All Projects → moltin → Js Sdk

moltin / Js Sdk

Licence: mit
JavaScript & Node.js SDKs for the Elastic Path Commerce Cloud eCommerce API

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
es2015
71 projects

Labels

Projects that are alternatives of or similar to Js Sdk

Pymedium
Unofficial Medium Python Flask API and SDK
Stars: ✭ 153 (-9.47%)
Mutual labels:  sdk
React Rollup Boilerplate
Boilerplate for creating React component libraries, bundled with Rollup.js to ES6 Modules, React Styleguidist, Typescript
Stars: ✭ 157 (-7.1%)
Mutual labels:  rollup
Wordpress Sdk
Stars: ✭ 162 (-4.14%)
Mutual labels:  sdk
Smartopencv
🔥 🔥 🔥 SmartOpenCV是一个OpenCV在Android端的增强库,解决了OpenCV Android SDK在图像预览方面存在的诸多问题,且无需修改OpenCV SDK源码,与OpenCV的SDK解耦
Stars: ✭ 1,869 (+1005.92%)
Mutual labels:  sdk
Nacos Sdk Csharp
🌹 nacos csharp sdk
Stars: ✭ 157 (-7.1%)
Mutual labels:  sdk
Contentful Management.js
JavaScript library for Contentful's Management API (node & browser)
Stars: ✭ 160 (-5.33%)
Mutual labels:  sdk
Openweatherplus Android
An open source weather APP for Android. 天气普拉斯Android版,自带天气数据的开源天气APP。
Stars: ✭ 153 (-9.47%)
Mutual labels:  sdk
Telegram Bot Sdk
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+1208.88%)
Mutual labels:  sdk
P2p Cdn Sdk Javascript
Free p2p cdn github javascript sdk to reduce video streaming costs of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀
Stars: ✭ 158 (-6.51%)
Mutual labels:  sdk
Miband Android
Unofficial SDK for Xiaomi Mi Band
Stars: ✭ 162 (-4.14%)
Mutual labels:  sdk
Esp8266 Firmware
DeviceHive esp8266 firmware. Control hardware via clouds with DeviceHive!
Stars: ✭ 154 (-8.88%)
Mutual labels:  sdk
Arcgis Pro Sdk
ArcGIS Pro SDK for Microsoft .NET is the new .NET SDK for the ArcGIS Pro Application.
Stars: ✭ 156 (-7.69%)
Mutual labels:  sdk
Card.io Android Sdk
card.io provides fast, easy credit card scanning in mobile apps
Stars: ✭ 1,942 (+1049.11%)
Mutual labels:  sdk
Aws Sdk Perl
A community AWS SDK for Perl Programmers
Stars: ✭ 153 (-9.47%)
Mutual labels:  sdk
Kendryte Freertos Sdk
Kendryte K210 SDK with FreeRTOS
Stars: ✭ 164 (-2.96%)
Mutual labels:  sdk
Javascript Sdk
Javascript SDK to communicate with Binance Chain.
Stars: ✭ 151 (-10.65%)
Mutual labels:  sdk
Onesignal Unity Sdk
OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Unity app with OneSignal. https://onesignal.com
Stars: ✭ 161 (-4.73%)
Mutual labels:  sdk
Countly Sdk Web
Countly Product Analytics SDK for websites and web applications
Stars: ✭ 165 (-2.37%)
Mutual labels:  sdk
School Api
🌱 校园教务系统接口,正方教务系统 SDK for Python
Stars: ✭ 165 (-2.37%)
Mutual labels:  sdk
Tails Ui
🐒 Clean UI based on tailwindcss
Stars: ✭ 162 (-4.14%)
Mutual labels:  rollup

Elastic Path Commerce Cloud JavaScript SDK

npm version License: MIT contributions welcome follow on Twitter

A simple to use API interface to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud JavaScript apps.

📚 API reference — 📚 Elastic Path Commerce Cloud

🛠 Installation

Install the package from npm and import in your project.

npm install --save @moltin/sdk

⛽️ Usage

To get started, instantiate a new Moltin client with your store credentials.

Note: This requires an Elastic Path Commerce Cloud account.

// JavaScript
import { gateway as MoltinGateway } from '@moltin/sdk'

const Moltin = MoltinGateway({
  client_id: 'XXX'
})

// Node.js
const MoltinGateway = require('@moltin/sdk').gateway

const Moltin = MoltinGateway({
  client_id: 'XXX',
  client_secret: 'XXX'
})

Alternatively you can include the UMD bundle via UNPKG like so:

<script src="https://unpkg.com/@moltin/sdk"></script>

<script>
  const Moltin = moltin.gateway({
    client_id: 'XXX'
  });
</script>

Note: If you're using webpack, you'll need to add the following to your projects configuration file.

node: {
  fs: 'empty'
}

You can now authenticate with the Moltin service 🎉

Moltin.Authenticate().then(response => {
  console.log('authenticated', response)
})

Check out the API reference to learn more about authenticating and the available endpoints.

Custom Host

If you're an enterprise customer with your own infrastructure, you'll need to specify your API URL when instantiating:

const Moltin = MoltinGateway({
  client_id: 'XXX',
  host: 'api.yourdomain.com'
})

Custom Storage

By default the Elastic Path Commerce Cloud SDK persists data to window.localStorage in the browser and node-localstorage in Node. If this doesn't suit your needs you can override the default storage with a MemoryStorageFactory which will persist data for the life cycle of the JavaScript VM:

import { gateway as MoltinGateway, MemoryStorageFactory } from '@moltin/sdk'

const Moltin = MoltinGateway({
  client_id: 'XXX',
  storage: new MemoryStorageFactory()
});

Or alternatively, create your own storage factory by passing in an object which implements the following interface:

interface StorageFactory {
  set(key: string, value: string): void;
  get(key: string): string | null;
  delete(key: string): void;
}

Included Headers

There are currently several optional headers you can pass into the configuration, which include application, language and currency.

You can pass them into the config used by the gateway like this:

// JavaScript
import { gateway as MoltinGateway } from '@moltin/sdk'
// const MoltinGateway = require('@moltin/sdk').gateway -> for Node

const Moltin = MoltinGateway({
    client_id: 'XXX',
    client_secret: 'XXX'
    currency: 'YEN',
    language: 'en',
    application: 'my-app'
})

TypeScript Support

The Elastic Path Commerce Cloud JavaScript SDK is fully supported in Typescript.

Imported module will contain all interfaces needed to consume backend services. i.e:

import * as moltin from '@moltin/sdk';

const product: moltin.ProductBase = {...}

If you do not want to use the namespace, you can extend the interfaces and define them yourself, like so:

// You can name the interface anything you like
interface Product extends product.ProductBase {
}

const product: Product = {...}

Here is an example of a simple product creation:

import { Moltin, gateway, ProductBase, Resource } from '@moltin/sdk';

async function main() {
  const g: Moltin = gateway({client_id, client_secret});
  const auth = await g.Authenticate();
  
  const newProduct: ProductBase = {
    type: "product",
    name: "My Product",
    slug: "my-prod",
    sku: "my-prod",
    manage_stock: false,
    description: "Some description",
    status: "draft",
    commodity_type: "physical",
    price: [
      {
        amount: 5499,
        currency: "USD",
        includes_tax: true
      }
    ]
  };
  
  const nP: Resource<Product> = await g.Products.Create(newProduct);
}

You can also extend any base interface compatible with flows to create any custom interfaces that you might be using by re-declaring @moltin/sdk module. Following example adds several properties to ProductsBase interface that correspond to flows added to the backend.

In your project add a definition file (with a .d.ts extension) with a following code:

import * as moltin from '@moltin/sdk';

declare module '@moltin/sdk' {

  interface Weight {
    g: number;
    kg: number;
    lb: number;
    oz: number;
  }

  interface ProductBase {
    background_color: string;
    background_colour: string | null;
    bulb: string;
    bulb_qty: string;
    finish: string;
    material: string;
    max_watt: string;
    new: string | null;
    on_sale: string | null;
    weight: Weight;
  }

}

This will affect base interface and all other Product interfaces that inherit from base interface so added properties will be present when creating, updating, fetching products.

❤️ Contributing

We love community contributions. Here's a quick guide if you want to submit a pull request:

  1. Fork the repository
  2. Add a test for your change (it should fail)
  3. Make the tests pass
  4. Commit your changes (see note below)
  5. Submit your PR with a brief description explaining your changes

Note: Commits should adhere to the Angular commit conventions.

Make sure you have Prettier installed for your editor with ESLint integration enabled.

⚡️ Development

The SDK is built with ES6 modules that are bundled using Rollup.

If you want to roll your own bundle, or make changes to any of the modules in src, then you'll need to install the package dependencies and run rollup while watching for changes.

npm install
npm start

You can learn more about the Rollup API and configuration here.

Terms And Conditions

  • Any changes to this project must be reviewed and approved by the repository owner. For more information about contributing, see the Contribution Guide.
  • For more information about the license, see MIT License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].