├── .babelrc ├── .eslintrc.json ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── main.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc ├── LICENSE ├── README.md ├── examples ├── express-app │ ├── index.js │ ├── package.json │ └── yarn.lock └── index.html ├── package.json ├── playground └── index.ts ├── preRelease.sh ├── renovate.json ├── rollup.config.js ├── src ├── config.js ├── endpoints │ ├── account-addresses.js │ ├── account-authentication-settings.js │ ├── account-members.js │ ├── account-membership-settings.js │ ├── account-memberships.js │ ├── accounts.js │ ├── application-keys.js │ ├── authentication-realm.js │ ├── authentication-settings.js │ ├── brands.js │ ├── cart.js │ ├── catalog.js │ ├── catalogs.js │ ├── categories.js │ ├── collections.js │ ├── currencies.js │ ├── custom-apis.js │ ├── customer-addresses.js │ ├── customers.js │ ├── data-entry.js │ ├── erasure-requests.js │ ├── fields.js │ ├── files.js │ ├── flows.js │ ├── gateways.js │ ├── hierarchies.js │ ├── integrations.js │ ├── inventories.js │ ├── jobs.js │ ├── merchant-realm-mappings.js │ ├── metrics.js │ ├── node-relationships.js │ ├── nodes.js │ ├── oidc-profile.js │ ├── one-time-password-token-request.js │ ├── orders.js │ ├── password-profile.js │ ├── pcm-file-relationship.js │ ├── pcm-jobs.js │ ├── pcm-main-image-relationship.js │ ├── pcm-template-relationship.js │ ├── pcm-variations-relationships.js │ ├── pcm-variations.js │ ├── pcm.js │ ├── personal-data.js │ ├── price-book-price-modifiers.js │ ├── price-book-prices.js │ ├── price-books.js │ ├── products.js │ ├── promotions.js │ ├── rule-promotions.js │ ├── settings.js │ ├── subscription-dunning-rules.js │ ├── subscription-jobs.js │ ├── subscription-offerings.js │ ├── subscription-plan.js │ ├── subscription-products.js │ ├── subscription-proration-policies.js │ ├── subscription-schedules.js │ ├── subscription-subscribers.js │ ├── subscriptions.js │ ├── transactions.js │ ├── user-authentication-info.js │ ├── user-authentication-password-profile.js │ └── variations.js ├── extends │ ├── base.js │ └── crud.js ├── factories │ ├── local-storage.js │ ├── memory-storage.js │ ├── request.js │ └── secure-cookies-storage.js ├── moltin.d.ts ├── moltin.js ├── types │ ├── account-address.d.ts │ ├── account-authentication-settings.d.ts │ ├── account-members.d.ts │ ├── account-membership-settings.d.ts │ ├── account-memberships.d.ts │ ├── accounts.d.ts │ ├── address.d.ts │ ├── application-keys.d.ts │ ├── authentication-realm.d.ts │ ├── authentication-settings.d.ts │ ├── brand.d.ts │ ├── cart.d.ts │ ├── catalog.d.ts │ ├── catalogs-nodes.d.ts │ ├── catalogs-products.d.ts │ ├── catalogs-releases.d.ts │ ├── catalogs-rules.d.ts │ ├── catalogs.d.ts │ ├── category.d.ts │ ├── collection.d.ts │ ├── config.d.ts │ ├── core.d.ts │ ├── currency.d.ts │ ├── custom-apis.ts │ ├── customer-address.d.ts │ ├── customer.d.ts │ ├── data-entries.d.ts │ ├── erasure-requests.d.ts │ ├── extensions.d.ts │ ├── field.d.ts │ ├── file.d.ts │ ├── flow.d.ts │ ├── gateway.d.ts │ ├── hierarchies.d.ts │ ├── integrations.d.ts │ ├── inventory.d.ts │ ├── job.d.ts │ ├── locales.ts │ ├── merchant-realm-mappings.d.ts │ ├── metrics.d.ts │ ├── node-relationships.d.ts │ ├── nodes.d.ts │ ├── oidc-profile.d.ts │ ├── one-time-password-token-request.d.ts │ ├── order.d.ts │ ├── password-profile.d.ts │ ├── pcm-file-relationship.ts │ ├── pcm-jobs.d.ts │ ├── pcm-main-image-relationship.ts │ ├── pcm-template-relationship.ts │ ├── pcm-variations-relationships.ts │ ├── pcm-variations.ts │ ├── pcm.d.ts │ ├── personal-data.d.ts │ ├── price-book-price-modifiers.d.ts │ ├── price-book-prices.d.ts │ ├── price-books.d.ts │ ├── price.d.ts │ ├── product.d.ts │ ├── promotions.d.ts │ ├── rule-promotions.ts │ ├── settings.d.ts │ ├── storage.d.ts │ ├── subscription-dunning-rules.d.ts │ ├── subscription-jobs.d.ts │ ├── subscription-offerings.d.ts │ ├── subscription-plans.d.ts │ ├── subscription-products.d.ts │ ├── subscription-proration-policies.d.ts │ ├── subscription-schedules.d.ts │ ├── subscription-subscribers.d.ts │ ├── subscriptions.d.ts │ ├── transaction.d.ts │ ├── user-authentication-info.d.ts │ ├── user-authentication-password-profile.d.ts │ ├── util.d.ts │ └── variations.d.ts └── utils │ ├── configFetch.js │ ├── constants.js │ ├── fetch-polyfill.js │ ├── helpers.js │ └── throttle.js ├── test ├── factories.ts ├── factories │ └── request.ts ├── tests.ts ├── unit │ ├── account-addresses.ts │ ├── account-authentication-settings.ts │ ├── account-members.ts │ ├── account-membership-settings.ts │ ├── account-memberships.ts │ ├── accounts.ts │ ├── application-keys.ts │ ├── authentication-realm.ts │ ├── authentication-settings.ts │ ├── authentication.ts │ ├── brands.ts │ ├── cart.ts │ ├── categories.ts │ ├── collections.ts │ ├── config.ts │ ├── currencies.ts │ ├── customer-addresses.ts │ ├── customers.ts │ ├── error.ts │ ├── fields.ts │ ├── files.ts │ ├── flows.ts │ ├── gateways.ts │ ├── integrations.ts │ ├── inventories.ts │ ├── jobs.ts │ ├── oidc-profile.ts │ ├── one-time-password-token-request.ts │ ├── orders.ts │ ├── password-profile.ts │ ├── products.ts │ ├── promotions.ts │ ├── settings.ts │ ├── transactions.ts │ ├── user-authentication-info.ts │ ├── user-authentication-password-profile.ts │ └── variations.ts └── utils │ ├── configFetch.ts │ ├── helpers.ts │ └── throttle.ts ├── tsconfig.json ├── yarn-error.log └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | "corejs": "3.8", 7 | "useBuiltIns": "entry" 8 | } 9 | ] 10 | ], 11 | "env": { 12 | "test": { 13 | "plugins": ["rewire"] 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true 4 | }, 5 | "extends": ["airbnb-base", "prettier"], 6 | "parser": "@babel/eslint-parser", 7 | "rules": { 8 | "class-methods-use-this": 0, 9 | "import/no-named-as-default": 0, 10 | "camelcase": 0, 11 | "prefer-rest-params": 0, 12 | "import/no-extraneous-dependencies": 0, 13 | "no-unused-expressions": 0, 14 | "no-undef": 0, 15 | "global-require": 0, 16 | "no-bitwise": 0, 17 | "max-classes-per-file": 0, 18 | "import/prefer-default-export": "off" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Type 2 | 3 | * ### Feature 4 | Implements a new feature 5 | * ### Fix 6 | Fixes a bug 7 | * ### Docs 8 | Documentation only changes 9 | * ### Style 10 | Changes that **do not** affect the meaning of the code (white-space, formatting, missing semi-colons, etc) 11 | * ### Refactor 12 | A code change that neither fixes a bug nor adds a feature 13 | * ### Performance 14 | A code change that improves performance 15 | * ### Test 16 | Adding missing or correcting existing tests 17 | * ### Chore 18 | Changes to the build process or auxiliary tools and libraries such as documentation generation 19 | 20 | ## Description 21 | 22 | *A brief description of the goals of the pull request.* 23 | 24 | ## Dependencies 25 | 26 | *Other PRs or builds that this PR depends on.* 27 | 28 | ## Issues 29 | 30 | *A list of issues closed by this PR.* 31 | 32 | * Fixes # 33 | 34 | ## Notes 35 | 36 | *Any additional notes.* 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | localStorage/ 3 | npm-debug.log 4 | .npmrc 5 | .idea/ 6 | dist/ 7 | test-results.xml 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | localStorage/ 3 | npm-debug.log 4 | .npmrc 5 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | package-lock.json 3 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | singleQuote: true 2 | semi: false 3 | jsxBracketSameLine: true 4 | trailingComma: none 5 | arrowParens: avoid -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Moltin Ltd 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/express-app/index.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const MoltinGateway = require('@moltin/sdk').gateway 3 | 4 | const app = express() 5 | 6 | const Moltin = MoltinGateway({ 7 | client_id: 8 | process.env.MOLTIN_CLIENT_ID || 'j6hSilXRQfxKohTndUuVrErLcSJWP15P347L6Im0M4' 9 | }) 10 | 11 | app.get('/', async (req, res) => { 12 | const { data } = await Moltin.Products.All() 13 | 14 | res.json({ 15 | data 16 | }) 17 | }) 18 | 19 | app.listen(4000, () => console.log('Listening on localhost:4000')) 20 | -------------------------------------------------------------------------------- /examples/express-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-app", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@moltin/sdk": "../..", 14 | "express": "^4.16.3" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Moltin Example 8 | 9 | 10 | 11 |
12 | 13 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /playground/index.ts: -------------------------------------------------------------------------------- 1 | import * as moltin from './../' 2 | 3 | async function main() { 4 | const gateway = moltin.gateway({ 5 | host: 'epcc-integration.global.ssl.fastly.net', 6 | client_id: 'client_id', 7 | client_secret: 'client_secret', 8 | headers: { 9 | 'EP-Beta-Features': 'account-management' 10 | } 11 | }) 12 | 13 | // const accounts = await gateway.Accounts.All(); 14 | // console.log(accounts); 15 | } 16 | 17 | main().catch(console.error) 18 | -------------------------------------------------------------------------------- /preRelease.sh: -------------------------------------------------------------------------------- 1 | cd dist || exit 2 | sed -i "s/0.0.0-semantic-release/$1/g" * 3 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["config:base", ":skipStatusChecks", "docker:disable", "schedule:weekly"], 3 | "automerge": true, 4 | "major": { 5 | "automerge": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import { babel } from '@rollup/plugin-babel' 2 | import { uglify } from 'rollup-plugin-uglify' 3 | import resolve from '@rollup/plugin-node-resolve' 4 | import commonjs from '@rollup/plugin-commonjs' 5 | import json from '@rollup/plugin-json' 6 | import serve from 'rollup-plugin-serve' 7 | import livereload from 'rollup-plugin-livereload' 8 | import filesize from 'rollup-plugin-filesize' 9 | import dts from 'rollup-plugin-dts' 10 | 11 | import pkg from './package.json' 12 | 13 | const { NODE_ENV = 'development' } = process.env 14 | const isProd = NODE_ENV === 'production' 15 | const isDev = NODE_ENV === 'development' && process.env.SERVE === 'true' 16 | 17 | const baseConfig = { 18 | input: 'src/moltin.js', 19 | watch: { 20 | include: 'src/**' 21 | }, 22 | external: ['es6-promise', 'fetch-everywhere'], 23 | plugins: [json(), filesize()] 24 | } 25 | 26 | const babelRollupPlugin = babel({ 27 | babelHelpers: 'bundled', 28 | exclude: ['package.json', 'node_modules/**'] 29 | }) 30 | 31 | export default [ 32 | { 33 | ...baseConfig, 34 | output: { 35 | name: 'moltin', 36 | exports: 'named', 37 | file: pkg.browser, 38 | format: 'umd' 39 | }, 40 | plugins: [ 41 | ...baseConfig.plugins, 42 | resolve({ browser: true }), 43 | commonjs(), 44 | /* 45 | babel plugin should be placed after commonjs 46 | https://github.com/rollup/plugins/tree/master/packages/babel#using-with-rollupplugin-commonjs 47 | */ 48 | babelRollupPlugin, 49 | isProd && 50 | uglify({ 51 | compress: { 52 | warnings: false 53 | } 54 | }), 55 | isDev && serve({ contentBase: ['dist', 'examples'], open: true }), 56 | isDev && livereload() 57 | ].filter(Boolean) 58 | }, 59 | { 60 | ...baseConfig, 61 | plugins: [...baseConfig.plugins, babelRollupPlugin], 62 | output: { 63 | file: pkg['cjs:main'], 64 | format: 'cjs', 65 | exports: 'named' 66 | }, 67 | external: [...baseConfig.external, ...Object.keys(pkg.dependencies || {})] 68 | }, 69 | { 70 | ...baseConfig, 71 | plugins: [...baseConfig.plugins, babelRollupPlugin], 72 | output: { 73 | file: pkg.module, 74 | format: 'es' 75 | }, 76 | external: [...baseConfig.external, ...Object.keys(pkg.dependencies || {})] 77 | }, 78 | { 79 | input: 'src/moltin.d.ts', 80 | output: [{ file: 'dist/moltin.d.ts', format: 'es' }], 81 | plugins: [dts()] 82 | } 83 | ] 84 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | import { version } from '../package.json' 2 | import LocalStorageFactory from './factories/local-storage' 3 | import SecureCookiesStorageFactory from './factories/secure-cookies-storage' 4 | import { resolveFetchMethod } from './utils/configFetch' 5 | 6 | class Config { 7 | constructor(options) { 8 | const { 9 | name, 10 | application, 11 | client_id, 12 | client_secret, 13 | currency, 14 | language, 15 | host, 16 | storage, 17 | storage_type, 18 | custom_authenticator, 19 | headers, 20 | disableCart, 21 | reauth, 22 | protocol, 23 | store_id, 24 | retryDelay, 25 | retryJitter, 26 | fetchMaxAttempts, 27 | custom_fetch, 28 | throttleEnabled = false, 29 | throttleLimit = 3, 30 | throttleInterval = 125 31 | } = options 32 | 33 | this.name = name 34 | this.application = application 35 | this.client_id = client_id 36 | this.client_secret = client_secret 37 | this.store_id = store_id 38 | this.host = host || 'euwest.api.elasticpath.com' 39 | this.protocol = protocol || 'https' 40 | this.version = 'v2' 41 | this.currency = currency 42 | this.language = language 43 | 44 | this.auth = { 45 | expires: 3600, 46 | uri: 'oauth/access_token', 47 | fetch: resolveFetchMethod({ 48 | custom_fetch, 49 | throttleEnabled, 50 | throttleLimit, 51 | throttleInterval 52 | }) 53 | } 54 | this.sdk = { 55 | version, 56 | language: 'JS' 57 | } 58 | 59 | this.storage = 60 | storage || 61 | (storage_type === 'cookies' 62 | ? new SecureCookiesStorageFactory() 63 | : new LocalStorageFactory()) 64 | this.custom_authenticator = custom_authenticator 65 | this.headers = headers || {} 66 | this.disableCart = disableCart || false 67 | this.reauth = reauth || true 68 | this.retryDelay = retryDelay || 1000 69 | this.retryJitter = retryJitter || 500 70 | this.fetchMaxAttempts = 71 | fetchMaxAttempts !== undefined && fetchMaxAttempts !== null 72 | ? fetchMaxAttempts 73 | : 4 74 | this.throttleConfig = { 75 | throttleEnabled, 76 | throttleLimit, 77 | throttleInterval 78 | } 79 | } 80 | } 81 | 82 | export default Config 83 | -------------------------------------------------------------------------------- /src/endpoints/account-addresses.js: -------------------------------------------------------------------------------- 1 | import { singularize } from 'inflected' 2 | 3 | import BaseExtend from '../extends/base' 4 | import { buildURL } from '../utils/helpers' 5 | 6 | class AccountAddressesEndpoint extends BaseExtend { 7 | constructor(endpoint) { 8 | super(endpoint) 9 | 10 | this.endpoint = 'addresses' 11 | } 12 | 13 | All({ account, token = null }) { 14 | const { includes, sort, limit, offset, filter } = this 15 | return this.request.send( 16 | buildURL(`accounts/${account}/${this.endpoint}`, { 17 | includes, 18 | sort, 19 | limit, 20 | offset, 21 | filter 22 | }), 23 | 'GET', 24 | undefined, 25 | undefined, 26 | this, 27 | true, 28 | null, 29 | token 30 | ? { 'EP-ACCOUNT-MANAGEMENT-AUTHENTICATION-TOKEN': token } 31 | : undefined 32 | ) 33 | } 34 | 35 | Get({ account, address, token = null }) { 36 | return this.request.send( 37 | `accounts/${account}/${this.endpoint}/${address}`, 38 | 'GET', 39 | undefined, 40 | undefined, 41 | this, 42 | true, 43 | null, 44 | token 45 | ? { 'EP-ACCOUNT-MANAGEMENT-AUTHENTICATION-TOKEN': token } 46 | : undefined 47 | ) 48 | } 49 | 50 | Create({ account, body, token = null }) { 51 | return this.request.send( 52 | `accounts/${account}/${this.endpoint}`, 53 | 'POST', 54 | { ...body, type: singularize(this.endpoint) }, 55 | undefined, 56 | this, 57 | true, 58 | null, 59 | token 60 | ? { 'EP-ACCOUNT-MANAGEMENT-AUTHENTICATION-TOKEN': token } 61 | : undefined 62 | ) 63 | } 64 | 65 | Delete({ account, address, token = null }) { 66 | return this.request.send( 67 | `accounts/${account}/${this.endpoint}/${address}`, 68 | 'DELETE', 69 | undefined, 70 | undefined, 71 | this, 72 | true, 73 | null, 74 | token 75 | ? { 'EP-ACCOUNT-MANAGEMENT-AUTHENTICATION-TOKEN': token } 76 | : undefined 77 | ) 78 | } 79 | 80 | Update({ account, address, body, token = null }) { 81 | return this.request.send( 82 | `accounts/${account}/${this.endpoint}/${address}`, 83 | 'PUT', 84 | { ...body, type: singularize(this.endpoint) }, 85 | undefined, 86 | this, 87 | true, 88 | null, 89 | token 90 | ? { 'EP-ACCOUNT-MANAGEMENT-AUTHENTICATION-TOKEN': token } 91 | : undefined 92 | ) 93 | } 94 | } 95 | 96 | export default AccountAddressesEndpoint 97 | -------------------------------------------------------------------------------- /src/endpoints/account-authentication-settings.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | 3 | class AccountAuthenticationSettingsEndpoint { 4 | constructor(config) { 5 | this.request = new RequestFactory(config) 6 | this.endpoint = 'settings/account-authentication' 7 | } 8 | 9 | Get() { 10 | return this.request.send(`${this.endpoint}`, 'GET', undefined) 11 | } 12 | 13 | Update(body) { 14 | return this.request.send(this.endpoint, 'PUT', { 15 | type: 'account_authentication_settings', 16 | ...body 17 | }) 18 | } 19 | } 20 | 21 | export default AccountAuthenticationSettingsEndpoint 22 | -------------------------------------------------------------------------------- /src/endpoints/account-members.js: -------------------------------------------------------------------------------- 1 | import { buildURL } from '../utils/helpers' 2 | import BaseExtend from '../extends/base' 3 | 4 | class AccountMembersEndpoint extends BaseExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'account-members' 8 | } 9 | 10 | Get(accountMemberId, token = null) { 11 | return this.request.send( 12 | `${this.endpoint}/${accountMemberId}`, 13 | 'GET', 14 | undefined, 15 | token 16 | ) 17 | } 18 | 19 | All(token = null, headers = {}) { 20 | const { limit, offset, filter } = this 21 | 22 | this.call = this.request.send( 23 | buildURL(this.endpoint, { 24 | limit, 25 | offset, 26 | filter 27 | }), 28 | 'GET', 29 | undefined, 30 | token, 31 | this, 32 | headers 33 | ) 34 | 35 | return this.call 36 | } 37 | 38 | UnassignedAccountMembers(accountId, token = null) { 39 | const { limit, offset, filter } = this 40 | 41 | this.call = this.request.send( 42 | buildURL( 43 | `accounts/${accountId}/account-memberships/unassigned-account-members`, 44 | { 45 | limit, 46 | offset, 47 | filter 48 | } 49 | ), 50 | 'GET', 51 | undefined, 52 | token, 53 | this 54 | ) 55 | 56 | return this.call 57 | } 58 | 59 | 60 | GenerateAccountToken(body, token = null) { 61 | return this.request.send( 62 | `${this.endpoint}/tokens`, 63 | 'POST', 64 | body, 65 | token 66 | ) 67 | } 68 | } 69 | 70 | export default AccountMembersEndpoint 71 | -------------------------------------------------------------------------------- /src/endpoints/account-membership-settings.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | 3 | class AccountMembershipSettingsEndpoint { 4 | constructor(config) { 5 | this.request = new RequestFactory(config) 6 | this.endpoint = 'settings/account-membership' 7 | } 8 | 9 | Get() { 10 | return this.request.send(`${this.endpoint}`, 'GET', undefined) 11 | } 12 | 13 | Update(body) { 14 | return this.request.send(`${this.endpoint}`, 'PUT', body) 15 | } 16 | } 17 | 18 | export default AccountMembershipSettingsEndpoint 19 | -------------------------------------------------------------------------------- /src/endpoints/account-memberships.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class AccountMembershipsEndpoint extends BaseExtend { 5 | Create(accountId, body, token = null) { 6 | return this.request.send( 7 | `accounts/${accountId}/account-memberships`, 8 | 'POST', 9 | body, 10 | token, 11 | this 12 | ) 13 | } 14 | 15 | All(accountId, token = null) { 16 | const { limit, offset, filter, includes } = this 17 | 18 | this.call = this.request.send( 19 | buildURL(`accounts/${accountId}/account-memberships`, { 20 | limit, 21 | offset, 22 | filter, 23 | includes 24 | }), 25 | 'GET', 26 | undefined, 27 | token, 28 | this 29 | ) 30 | 31 | return this.call 32 | } 33 | 34 | Get(accountId, accountMembershipId, token = null) { 35 | return this.request.send( 36 | `accounts/${accountId}/account-memberships/${accountMembershipId}`, 37 | 'GET', 38 | undefined, 39 | token 40 | ) 41 | } 42 | 43 | Delete(accountId, accountMembershipId, token = null) { 44 | return this.request.send( 45 | `accounts/${accountId}/account-memberships/${accountMembershipId}`, 46 | 'DELETE', 47 | undefined, 48 | token 49 | ) 50 | } 51 | 52 | AllOnAccountMember(accountMemberId, token = null) { 53 | const { limit, offset, filter, includes } = this 54 | 55 | this.call = this.request.send( 56 | buildURL(`account-members/${accountMemberId}/account-memberships`, { 57 | limit, 58 | offset, 59 | filter, 60 | includes 61 | }), 62 | 'GET', 63 | undefined, 64 | token, 65 | this 66 | ) 67 | 68 | return this.call 69 | } 70 | } 71 | 72 | export default AccountMembershipsEndpoint 73 | -------------------------------------------------------------------------------- /src/endpoints/accounts.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class AccountsEndpoint extends CRUDExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'accounts' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', body) 12 | } 13 | 14 | All(token = null, headers = {}) { 15 | const { limit, offset, filter } = this 16 | 17 | this.call = this.request.send( 18 | buildURL(this.endpoint, { 19 | limit, 20 | offset, 21 | filter 22 | }), 23 | 'GET', 24 | undefined, 25 | token, 26 | this, 27 | headers 28 | ) 29 | 30 | return this.call 31 | } 32 | } 33 | 34 | export default AccountsEndpoint 35 | -------------------------------------------------------------------------------- /src/endpoints/application-keys.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class ApplicationKeysEndpoint extends CRUDExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'application-keys' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', body) 12 | } 13 | 14 | Update(applicationKeyId, body, token = null) { 15 | return this.request.send( 16 | `${this.endpoint}/${applicationKeyId}`, 17 | `PUT`, 18 | body, 19 | token 20 | ) 21 | } 22 | 23 | All(token = null, headers = {}) { 24 | const { limit, offset, filter } = this 25 | 26 | this.call = this.request.send( 27 | buildURL(this.endpoint, { 28 | limit, 29 | offset, 30 | filter 31 | }), 32 | 'GET', 33 | undefined, 34 | token, 35 | this, 36 | headers 37 | ) 38 | 39 | return this.call 40 | } 41 | 42 | Delete(id) { 43 | return this.request.send(`${this.endpoint}/${id}`, 'DELETE') 44 | } 45 | } 46 | 47 | export default ApplicationKeysEndpoint 48 | -------------------------------------------------------------------------------- /src/endpoints/authentication-realm.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class AuthenticationRealmsEndpoint extends CRUDExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'authentication-realms' 8 | } 9 | 10 | All(token = null, headers = {}) { 11 | const { includes, sort, limit, offset, filter } = this 12 | 13 | this.call = this.request.send( 14 | buildURL(this.endpoint, { 15 | includes, 16 | sort, 17 | limit, 18 | offset, 19 | filter 20 | }), 21 | 'GET', 22 | undefined, 23 | token, 24 | this, 25 | headers 26 | ) 27 | 28 | return this.call 29 | } 30 | 31 | Create(body) { 32 | return this.request.send(this.endpoint, 'POST', body.data) 33 | } 34 | 35 | Get({ realmId, token = null }) { 36 | return this.request.send( 37 | `${this.endpoint}/${realmId}`, 38 | 'GET', 39 | undefined, 40 | token 41 | ) 42 | } 43 | } 44 | 45 | export default AuthenticationRealmsEndpoint 46 | -------------------------------------------------------------------------------- /src/endpoints/authentication-settings.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class AuthenticationSettingsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | this.endpoint = 'settings/customer-authentication' 7 | } 8 | 9 | Get() { 10 | return this.request.send(`${this.endpoint}`, 'GET', undefined) 11 | } 12 | } 13 | 14 | export default AuthenticationSettingsEndpoint 15 | -------------------------------------------------------------------------------- /src/endpoints/brands.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class BrandsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'brands' 8 | } 9 | } 10 | 11 | export default BrandsEndpoint 12 | -------------------------------------------------------------------------------- /src/endpoints/categories.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class CategoriesEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'categories' 8 | } 9 | 10 | Tree() { 11 | return this.request.send(`${this.endpoint}/tree`, 'GET') 12 | } 13 | } 14 | 15 | export default CategoriesEndpoint 16 | -------------------------------------------------------------------------------- /src/endpoints/collections.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class CollectionsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'collections' 8 | } 9 | } 10 | 11 | export default CollectionsEndpoint 12 | -------------------------------------------------------------------------------- /src/endpoints/currencies.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | import {resolveCurrencyStorageKey} from "../utils/helpers"; 3 | 4 | class CurrenciesEndpoint extends BaseExtend { 5 | constructor(config) { 6 | super(config) 7 | 8 | this.endpoint = 'currencies' 9 | this.storage = config.storage 10 | } 11 | 12 | Create(body) { 13 | return this.request.send(`${this.endpoint}`, 'POST', body) 14 | } 15 | 16 | Delete(id) { 17 | return this.request.send(`${this.endpoint}/${id}`, 'DELETE') 18 | } 19 | 20 | Update(id, body) { 21 | return this.request.send(`${this.endpoint}/${id}`, 'PUT', body) 22 | } 23 | 24 | Set(currency) { 25 | const { config, storage } = this 26 | const currencyStorageKey = resolveCurrencyStorageKey(config.name) 27 | storage.set(currencyStorageKey, currency) 28 | config.currency = currency 29 | 30 | const promise = new Promise((resolve, reject) => { 31 | const request = storage.get(currencyStorageKey) 32 | 33 | try { 34 | resolve(request) 35 | } catch (err) { 36 | reject(new Error(err)) 37 | } 38 | }) 39 | 40 | return promise 41 | } 42 | 43 | Active() { 44 | const { storage, config } = this 45 | 46 | const promise = new Promise((resolve, reject) => { 47 | const request = storage.get(resolveCurrencyStorageKey(config.name)) 48 | 49 | try { 50 | resolve(request) 51 | } catch (err) { 52 | reject(new Error(err)) 53 | } 54 | }) 55 | 56 | return promise 57 | } 58 | } 59 | 60 | export default CurrenciesEndpoint 61 | -------------------------------------------------------------------------------- /src/endpoints/custom-apis.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | import { buildURL } from '../utils/helpers' 4 | 5 | class CustomApisEndpoint extends CRUDExtend { 6 | constructor(endpoint) { 7 | super(endpoint) 8 | 9 | this.endpoint = 'settings/extensions/custom-apis' 10 | } 11 | 12 | Create(body) { 13 | return this.request.send( 14 | this.endpoint, 15 | 'POST', 16 | body 17 | ) 18 | } 19 | 20 | Update(id, body) { 21 | return this.request.send( 22 | `${this.endpoint}/${id}`, 23 | 'PUT', 24 | body 25 | ) 26 | } 27 | 28 | GetFields(customApiId) { 29 | const { limit, offset, sort } = this 30 | 31 | return this.request.send( 32 | buildURL(`${this.endpoint}/${customApiId}/fields`, { 33 | limit, 34 | offset, 35 | sort 36 | }), 37 | 'GET' 38 | ) 39 | } 40 | 41 | GetField(customApiId, customApiFieldId) { 42 | return this.request.send( 43 | `${this.endpoint}/${customApiId}/fields/${customApiFieldId}`, 44 | 'GET' 45 | ) 46 | } 47 | 48 | CreateField(customApiId, body) { 49 | return this.request.send( 50 | `${this.endpoint}/${customApiId}/fields`, 51 | 'POST', 52 | body 53 | ) 54 | } 55 | 56 | UpdateField(customApiId, customApiFieldId, body) { 57 | return this.request.send( 58 | `${this.endpoint}/${customApiId}/fields/${customApiFieldId}`, 59 | 'PUT', 60 | body 61 | ) 62 | } 63 | 64 | DeleteField(customApiId, customApiFieldId) { 65 | return this.request.send( 66 | `${this.endpoint}/${customApiId}/fields/${customApiFieldId}`, 67 | 'DELETE' 68 | ) 69 | } 70 | 71 | GetEntries(customApiId) { 72 | const { limit, offset, sort, filter } = this 73 | 74 | return this.request.send( 75 | buildURL(`${this.endpoint}/${customApiId}/entries`, { 76 | limit, 77 | offset, 78 | sort, 79 | filter 80 | }), 81 | 'GET' 82 | ) 83 | } 84 | 85 | GetEntry(customApiId, customApiEntryId) { 86 | return this.request.send( 87 | `${this.endpoint}/${customApiId}/entries/${customApiEntryId}`, 88 | 'GET' 89 | ) 90 | } 91 | 92 | CreateEntry(customApiId, body) { 93 | return this.request.send( 94 | `${this.endpoint}/${customApiId}/entries`, 95 | 'POST', 96 | body 97 | ) 98 | } 99 | 100 | UpdateEntry(customApiId, customApiEntryId, body) { 101 | return this.request.send( 102 | `${this.endpoint}/${customApiId}/entries/${customApiEntryId}`, 103 | 'PUT', 104 | body 105 | ) 106 | } 107 | 108 | DeleteEntry(customApiId, customApiEntryId) { 109 | return this.request.send( 110 | `${this.endpoint}/${customApiId}/entries/${customApiEntryId}`, 111 | 'DELETE' 112 | ) 113 | } 114 | } 115 | 116 | export default CustomApisEndpoint 117 | -------------------------------------------------------------------------------- /src/endpoints/customer-addresses.js: -------------------------------------------------------------------------------- 1 | import { singularize } from 'inflected' 2 | 3 | import BaseExtend from '../extends/base' 4 | 5 | class CustomerAddressesEndpoint extends BaseExtend { 6 | constructor(endpoint) { 7 | super(endpoint) 8 | 9 | this.endpoint = 'addresses' 10 | } 11 | 12 | All({ customer, token = null }) { 13 | return this.request.send( 14 | `customers/${customer}/${this.endpoint}`, 15 | 'GET', 16 | undefined, 17 | token 18 | ) 19 | } 20 | 21 | Get({ customer, address, token = null }) { 22 | return this.request.send( 23 | `customers/${customer}/${this.endpoint}/${address}`, 24 | 'GET', 25 | undefined, 26 | token 27 | ) 28 | } 29 | 30 | Create({ customer, body, token = null }) { 31 | return this.request.send( 32 | `customers/${customer}/${this.endpoint}`, 33 | 'POST', 34 | { ...body, type: singularize(this.endpoint) }, 35 | token 36 | ) 37 | } 38 | 39 | Delete({ customer, address, token = null }) { 40 | return this.request.send( 41 | `customers/${customer}/${this.endpoint}/${address}`, 42 | 'DELETE', 43 | undefined, 44 | token 45 | ) 46 | } 47 | 48 | Update({ customer, address, body, token = null }) { 49 | return this.request.send( 50 | `customers/${customer}/${this.endpoint}/${address}`, 51 | 'PUT', 52 | { ...body, type: singularize(this.endpoint) }, 53 | token 54 | ) 55 | } 56 | } 57 | 58 | export default CustomerAddressesEndpoint 59 | -------------------------------------------------------------------------------- /src/endpoints/customers.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class CustomersEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'customers' 8 | 9 | this.sendToken = (tokenRequestBody, headers = {}) => 10 | this.request.send( 11 | `${this.endpoint}/tokens`, 12 | 'POST', 13 | tokenRequestBody, 14 | null, 15 | { 16 | ...headers 17 | } 18 | ) 19 | } 20 | 21 | TokenViaPassword(email, password, headers) { 22 | const body = { 23 | type: 'token', 24 | authentication_mechanism: 'password', 25 | email, 26 | password 27 | } 28 | 29 | return this.sendToken(body, headers) 30 | } 31 | 32 | TokenViaOIDC(code, redirectUri, codeVerifier, headers) { 33 | const body = { 34 | type: 'token', 35 | authentication_mechanism: 'oidc', 36 | oauth_authorization_code: code, 37 | oauth_redirect_uri: redirectUri, 38 | oauth_code_verifier: codeVerifier 39 | } 40 | 41 | return this.sendToken(body, headers) 42 | } 43 | 44 | Token(email, password) { 45 | return this.TokenViaPassword(email, password) 46 | } 47 | } 48 | export default CustomersEndpoint 49 | -------------------------------------------------------------------------------- /src/endpoints/data-entry.js: -------------------------------------------------------------------------------- 1 | import { buildURL } from '../utils/helpers' 2 | import BaseExtend from '../extends/base' 3 | 4 | class DataEntriesEndpoint extends BaseExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'personal-data/related-data-entries' 8 | } 9 | 10 | All(token = null) { 11 | const { limit, offset, filter } = this 12 | 13 | const url = buildURL(this.endpoint, { 14 | limit, 15 | offset, 16 | filter 17 | }) 18 | 19 | return this.request.send(url, 'GET', undefined, token, this) 20 | } 21 | 22 | Filter(resourceType, resourceId) { 23 | this.filter = { 24 | eq: { 25 | resource_type: resourceType, 26 | resource_id: resourceId 27 | } 28 | } 29 | 30 | return this 31 | } 32 | } 33 | 34 | export default DataEntriesEndpoint 35 | -------------------------------------------------------------------------------- /src/endpoints/erasure-requests.js: -------------------------------------------------------------------------------- 1 | import { buildURL } from '../utils/helpers' 2 | import BaseExtend from '../extends/base' 3 | 4 | class ErasureRequestsEndpoint extends BaseExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'personal-data/erasure-requests' 8 | } 9 | 10 | All(token = null) { 11 | const { limit, offset, filter } = this 12 | 13 | const url = buildURL(this.endpoint, { 14 | limit, 15 | offset, 16 | filter 17 | }) 18 | 19 | return this.request.send(url, 'GET', undefined, token, this) 20 | } 21 | 22 | Filter(resourceType, resourceId) { 23 | this.filter = { 24 | eq: { 25 | resource_type: resourceType, 26 | resource_id: resourceId 27 | } 28 | } 29 | 30 | return this 31 | } 32 | 33 | Create(resourceType, resourceId) { 34 | const body = { 35 | resource_type: resourceType, 36 | resource_id: resourceId, 37 | type: 'erasure_request' 38 | } 39 | 40 | return this.request.send( 41 | this.endpoint, 42 | 'POST', 43 | body, 44 | ) 45 | } 46 | } 47 | 48 | export default ErasureRequestsEndpoint 49 | -------------------------------------------------------------------------------- /src/endpoints/fields.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class FieldsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'fields' 8 | } 9 | } 10 | 11 | export default FieldsEndpoint 12 | -------------------------------------------------------------------------------- /src/endpoints/files.js: -------------------------------------------------------------------------------- 1 | import FormData from 'form-data' 2 | import BaseExtend from '../extends/base' 3 | import { isNode } from '../utils/helpers' 4 | 5 | class Files extends BaseExtend { 6 | constructor(endpoint) { 7 | super(endpoint) 8 | 9 | this.endpoint = 'files' 10 | } 11 | 12 | Create(body, contentType = null) { 13 | const additionalHeaders = {} 14 | 15 | // Allows users to specify content type, useful if using Node and an 16 | // implementation of FormData 17 | if (isNode()) { 18 | if (contentType === null) 19 | throw new Error('You must provide a content type header') 20 | 21 | additionalHeaders['Content-Type'] = contentType 22 | } 23 | 24 | return this.request.send( 25 | `${this.endpoint}`, 26 | 'POST', 27 | body, 28 | undefined, 29 | undefined, 30 | false, 31 | undefined, 32 | additionalHeaders 33 | ) 34 | } 35 | 36 | Link(url) { 37 | const form = new FormData() 38 | form.append('file_location', url) 39 | 40 | // Headers only need to be explicitly passed in a node environment. 41 | // Browsers will handle FormData headers natively 42 | const contentType = isNode() ? form.getHeaders()['content-type'] : null 43 | 44 | return this.Create(form, contentType) 45 | } 46 | 47 | Delete(id) { 48 | return this.request.send(`${this.endpoint}/${id}`, 'DELETE') 49 | } 50 | } 51 | 52 | export default Files 53 | -------------------------------------------------------------------------------- /src/endpoints/flows.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | import { buildURL } from '../utils/helpers' 4 | 5 | class FlowsEndpoint extends CRUDExtend { 6 | constructor(endpoint) { 7 | super(endpoint) 8 | 9 | this.endpoint = 'flows' 10 | } 11 | 12 | AllTemplates(template, token = null) { 13 | const { includes, sort, limit, offset, filter } = this 14 | 15 | return this.request.send( 16 | buildURL(`${this.endpoint}?template=${template}`, { 17 | includes, 18 | sort, 19 | limit, 20 | offset, 21 | filter 22 | }), 23 | 'GET', 24 | undefined, 25 | token, 26 | this 27 | ) 28 | } 29 | 30 | GetEntries(slug) { 31 | const { limit, offset } = this 32 | 33 | return this.request.send( 34 | buildURL(`${this.endpoint}/${slug}/entries`, { 35 | limit, 36 | offset 37 | }), 38 | 'GET' 39 | ) 40 | } 41 | 42 | GetEntry(slug, entryId) { 43 | return this.request.send( 44 | `${this.endpoint}/${slug}/entries/${entryId}`, 45 | 'GET' 46 | ) 47 | } 48 | 49 | GetFields(slug) { 50 | return this.request.send(`${this.endpoint}/${slug}/fields`, 'GET') 51 | } 52 | 53 | CreateEntry(slug, body) { 54 | return this.request.send(`${this.endpoint}/${slug}/entries`, 'POST', { 55 | ...body, 56 | type: 'entry' 57 | }) 58 | } 59 | 60 | UpdateEntry(slug, entryId, body) { 61 | return this.request.send( 62 | `${this.endpoint}/${slug}/entries/${entryId}`, 63 | 'PUT', 64 | { ...body, type: 'entry' } 65 | ) 66 | } 67 | 68 | DeleteEntry(slug, entryId) { 69 | return this.request.send( 70 | `${this.endpoint}/${slug}/entries/${entryId}`, 71 | 'DELETE' 72 | ) 73 | } 74 | 75 | CreateEntryRelationship(flowSlug, entryId, fieldSlug, body = {}) { 76 | let actualBody = body 77 | if (Array.isArray(body) === false) { 78 | actualBody = { 79 | ...body 80 | } 81 | } 82 | return this.request.send( 83 | `${ 84 | this.endpoint 85 | }/${flowSlug}/entries/${entryId}/relationships/${fieldSlug}`, 86 | 'POST', 87 | actualBody 88 | ) 89 | } 90 | 91 | UpdateEntryRelationship(flowSlug, entryId, fieldSlug, body = {}) { 92 | let actualBody = body 93 | if (Array.isArray(body) === false) { 94 | actualBody = { 95 | ...body 96 | } 97 | } 98 | return this.request.send( 99 | `${ 100 | this.endpoint 101 | }/${flowSlug}/entries/${entryId}/relationships/${fieldSlug}`, 102 | 'PUT', 103 | actualBody 104 | ) 105 | } 106 | 107 | DeleteEntryRelationship(flowSlug, entryId, fieldSlug) { 108 | return this.request.send( 109 | `${ 110 | this.endpoint 111 | }/${flowSlug}/entries/${entryId}/relationships/${fieldSlug}`, 112 | 'DELETE' 113 | ) 114 | } 115 | 116 | GetFlowTypeAttributes(flowType, token = null) { 117 | return this.request.send( 118 | `${this.endpoint}/${flowType}/attributes`, 119 | 'GET', 120 | undefined, 121 | token 122 | ) 123 | } 124 | } 125 | 126 | export default FlowsEndpoint 127 | -------------------------------------------------------------------------------- /src/endpoints/gateways.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | 3 | class GatewaysEndpoint extends BaseExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'gateways' 8 | } 9 | 10 | Update(slug, body) { 11 | return this.request.send(`${this.endpoint}/${slug}`, 'PUT', body) 12 | } 13 | 14 | Enabled(slug, enabled) { 15 | return this.request.send(`${this.endpoint}/${slug}`, 'PUT', { 16 | type: 'gateway', 17 | enabled 18 | }) 19 | } 20 | 21 | GetSlugAttributes(slug, token = null) { 22 | return this.request.send( 23 | `${this.endpoint}/${slug}/attributes`, 24 | 'GET', 25 | undefined, 26 | token 27 | ) 28 | } 29 | 30 | OnboardingLinks(slug, returnUrl, test = false) { 31 | return this.request.send( 32 | `${this.endpoint}/${slug}/onboarding-links`, 33 | 'POST', 34 | { 35 | test, 36 | return_url: returnUrl 37 | } 38 | ) 39 | } 40 | 41 | StripeCustomers(slug, stripe_account) { 42 | return this.request.send( 43 | `${this.endpoint}/${slug}/stripe_customers`, 44 | 'POST', 45 | { 46 | data: { 47 | options: { 48 | stripe_account 49 | } 50 | } 51 | }, 52 | undefined, 53 | this, 54 | false, 55 | ) 56 | } 57 | 58 | StripeInvoices(slug, stripe_account, customer_id) { 59 | return this.request.send( 60 | `${this.endpoint}/${slug}/stripe_invoices`, 61 | 'POST', 62 | { 63 | data: { 64 | customer_id, 65 | options: { 66 | stripe_account, 67 | } 68 | } 69 | }, 70 | undefined, 71 | this, 72 | false, 73 | ) 74 | } 75 | } 76 | 77 | export default GatewaysEndpoint 78 | -------------------------------------------------------------------------------- /src/endpoints/hierarchies.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import NodesEndpoint from './nodes' 3 | import NodeRelationships from './node-relationships' 4 | import { buildURL } from '../utils/helpers' 5 | 6 | class HierarchiesEndpoint extends CRUDExtend { 7 | constructor(endpoint) { 8 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 9 | config.version = 'pcm' 10 | super(config) 11 | this.Nodes = new NodesEndpoint(config) 12 | this.Relationships = new NodeRelationships(config) 13 | this.endpoint = 'hierarchies' 14 | } 15 | 16 | Children(id, token = null) { 17 | const { limit, offset } = this 18 | 19 | this.call = this.request.send( 20 | buildURL(`${this.endpoint}/${id}/children`, { 21 | limit, 22 | offset 23 | }), 24 | 'GET', 25 | null, 26 | token 27 | ) 28 | 29 | return this.call 30 | } 31 | 32 | Duplicate(hierarchyId, body, token = null) { 33 | return this.request.send( 34 | `${this.endpoint}/${hierarchyId}/duplicate_job`, 35 | 'POST', 36 | body, 37 | token 38 | ) 39 | } 40 | } 41 | 42 | export default HierarchiesEndpoint 43 | -------------------------------------------------------------------------------- /src/endpoints/integrations.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class IntegrationsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | const config = { ...endpoint, version: 'v2' } 6 | super(config) 7 | 8 | this.endpoint = 'integrations' 9 | } 10 | 11 | GetAllLogs() { 12 | return this.request.send(`${this.endpoint}/logs`, 'GET') 13 | } 14 | 15 | GetLogs(id) { 16 | return this.request.send(`${this.endpoint}/${id}/logs`, 'GET') 17 | } 18 | 19 | GetJobs(id) { 20 | return this.request.send(`${this.endpoint}/${id}/jobs`, 'GET') 21 | } 22 | 23 | GetAllLogsForJob(integrationId, integrationJobId) { 24 | return this.request.send( 25 | `${this.endpoint}/${integrationId}/jobs/${integrationJobId}/logs`, 26 | 'GET' 27 | ) 28 | } 29 | } 30 | 31 | export default IntegrationsEndpoint 32 | -------------------------------------------------------------------------------- /src/endpoints/inventories.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | 3 | class InventoriesEndpoint extends BaseExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'inventories' 8 | } 9 | 10 | Create(productId, quantity) { 11 | return this.request.send(`${this.endpoint}/${productId}`, 'POST', { 12 | quantity 13 | }) 14 | } 15 | 16 | Delete(productId) { 17 | return this.request.send(`${this.endpoint}/${productId}`, 'DELETE') 18 | } 19 | 20 | IncrementStock(productId, quantity) { 21 | return this.request.send( 22 | `${this.endpoint}/${productId}/transactions`, 23 | 'POST', 24 | { action: 'increment', quantity, type: 'stock-transaction' } 25 | ) 26 | } 27 | 28 | DecrementStock(productId, quantity) { 29 | return this.request.send( 30 | `${this.endpoint}/${productId}/transactions`, 31 | 'POST', 32 | { action: 'decrement', quantity, type: 'stock-transaction' } 33 | ) 34 | } 35 | 36 | AllocateStock(productId, quantity) { 37 | return this.request.send( 38 | `${this.endpoint}/${productId}/transactions`, 39 | 'POST', 40 | { action: 'allocate', quantity, type: 'stock-transaction' } 41 | ) 42 | } 43 | 44 | DeallocateStock(productId, quantity) { 45 | return this.request.send( 46 | `${this.endpoint}/${productId}/transactions`, 47 | 'POST', 48 | { action: 'deallocate', quantity, type: 'stock-transaction' } 49 | ) 50 | } 51 | 52 | GetTransactions(productId) { 53 | return this.request.send( 54 | `${this.endpoint}/${productId}/transactions`, 55 | 'GET' 56 | ) 57 | } 58 | 59 | GetTransaction(productId, transactionId) { 60 | return this.request.send( 61 | `${this.endpoint}/${productId}/transactions/${transactionId}`, 62 | 'GET' 63 | ) 64 | } 65 | 66 | GetMultipleStock(productIds) { 67 | const body = productIds.map(id => ({ id })) 68 | return this.request.send(`${this.endpoint}/multiple`, 'POST', body) 69 | } 70 | } 71 | 72 | export default InventoriesEndpoint 73 | -------------------------------------------------------------------------------- /src/endpoints/jobs.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | 3 | class Jobs extends BaseExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'jobs' 8 | } 9 | 10 | All() { 11 | return this.request.send(`${this.endpoint}`, 'GET') 12 | } 13 | 14 | Create(body) { 15 | return this.request.send(`${this.endpoint}`, 'POST', body) 16 | } 17 | 18 | GetFile(fileId) { 19 | return this.request.send(`${this.endpoint}/${fileId}/file`, 'Get') 20 | } 21 | 22 | Get(fileId) { 23 | return this.request.send(`${this.endpoint}/${fileId}`, 'Get') 24 | } 25 | } 26 | 27 | export default Jobs 28 | -------------------------------------------------------------------------------- /src/endpoints/merchant-realm-mappings.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | 3 | class MerchantRealmMappings { 4 | constructor(config) { 5 | this.request = new RequestFactory(config) 6 | 7 | this.endpoint = 'merchant-realm-mappings' 8 | } 9 | 10 | All(token = null) { 11 | this.call = this.request.send(this.endpoint, 'GET', undefined, token, this) 12 | 13 | return this.call 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body, 22 | type: this.endpoint 23 | }, 24 | token 25 | ) 26 | } 27 | 28 | Get(id) { 29 | return this.request.send(`${this.endpoint}/${id}`, 'GET') 30 | } 31 | } 32 | 33 | export default MerchantRealmMappings 34 | -------------------------------------------------------------------------------- /src/endpoints/metrics.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | import { formatQueryParams } from '../utils/helpers' 3 | 4 | class MetricsEndpoint extends BaseExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | 8 | this.endpoint = 'metrics' 9 | } 10 | 11 | TotalOrders(query) { 12 | const formattedString = formatQueryParams(query) 13 | return this.request.send( 14 | `${this.endpoint}/orders/total?${formattedString}`, 15 | 'GET' 16 | ) 17 | } 18 | 19 | TotalValue(query) { 20 | const formattedString = formatQueryParams(query) 21 | return this.request.send( 22 | `${this.endpoint}/orders/value?${formattedString}`, 23 | 'GET' 24 | ) 25 | } 26 | } 27 | 28 | export default MetricsEndpoint 29 | -------------------------------------------------------------------------------- /src/endpoints/node-relationships.js: -------------------------------------------------------------------------------- 1 | import { singularize } from 'inflected' 2 | import RequestFactory from '../factories/request' 3 | import { buildURL } from '../utils/helpers' 4 | 5 | class NodeRelationshipsEndpoint { 6 | constructor(endpoint) { 7 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 8 | this.request = new RequestFactory(config) 9 | config.version = 'pcm' 10 | this.endpoint = 'relationships/products' 11 | } 12 | 13 | Create({ hierarchyId, nodeId, body, token = null }) { 14 | return this.request.send( 15 | `hierarchies/${hierarchyId}/nodes/${nodeId}/${this.endpoint}`, 16 | 'POST', 17 | body, 18 | token 19 | ) 20 | } 21 | 22 | Delete({ hierarchyId, nodeId, body, token = null }) { 23 | return this.request.send( 24 | `hierarchies/${hierarchyId}/nodes/${nodeId}/${this.endpoint}`, 25 | 'DELETE', 26 | body, 27 | token 28 | ) 29 | } 30 | 31 | Update({ hierarchyId, nodeId, body, token = null }) { 32 | return this.request.send( 33 | `hierarchies/${hierarchyId}/nodes/${nodeId}/relationships/parent`, 34 | 'PUT', 35 | { ...body, type: singularize(this.endpoint) }, 36 | token 37 | ) 38 | } 39 | 40 | Products({ hierarchyId, nodeId, token = null }) { 41 | const { limit, offset } = this 42 | return this.request.send( 43 | buildURL(`hierarchies/${hierarchyId}/nodes/${nodeId}/products`, { 44 | limit, 45 | offset 46 | }), 47 | 'GET', 48 | null, 49 | token 50 | ) 51 | } 52 | 53 | ChangeParent({ hierarchyId, nodeId, body, token = null }) { 54 | return this.request.send( 55 | `hierarchies/${hierarchyId}/nodes/${nodeId}/relationships/parent`, 56 | 'PUT', 57 | body, 58 | token 59 | ) 60 | } 61 | 62 | DeleteParent({ hierarchyId, nodeId, token = null }) { 63 | return this.request.send( 64 | `hierarchies/${hierarchyId}/nodes/${nodeId}/relationships/parent`, 65 | 'DELETE', 66 | undefined, 67 | token 68 | ) 69 | } 70 | 71 | CreateChildrenSortOrder({ hierarchyId, nodeId, body, token = null }) { 72 | return this.request.send( 73 | `hierarchies/${hierarchyId}/nodes/${nodeId}/relationships/children`, 74 | 'POST', 75 | body, 76 | token 77 | ) 78 | } 79 | 80 | Limit(value) { 81 | this.limit = value 82 | return this 83 | } 84 | 85 | Offset(value) { 86 | this.offset = value 87 | 88 | return this 89 | } 90 | } 91 | 92 | export default NodeRelationshipsEndpoint 93 | -------------------------------------------------------------------------------- /src/endpoints/nodes.js: -------------------------------------------------------------------------------- 1 | import { singularize } from 'inflected' 2 | import RequestFactory from '../factories/request' 3 | import { buildURL } from '../utils/helpers' 4 | 5 | class NodesEndpoint { 6 | constructor(endpoint) { 7 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 8 | this.request = new RequestFactory(config) 9 | config.version = 'pcm' 10 | this.endpoint = 'nodes' 11 | } 12 | 13 | // TODO: API - currently not working! (can get from hierarchy relationships) 14 | All({ hierarchyId, token = null }) { 15 | return this.request.send( 16 | `hierarchies/${hierarchyId}/${this.endpoint}`, 17 | 'GET', 18 | undefined, 19 | token 20 | ) 21 | } 22 | 23 | Get({ hierarchyId, nodeId, token = null }) { 24 | return this.request.send( 25 | `hierarchies/${hierarchyId}/${this.endpoint}/${nodeId}`, 26 | 'GET', 27 | undefined, 28 | token 29 | ) 30 | } 31 | 32 | Create({ hierarchyId, body, token = null }) { 33 | return this.request.send( 34 | `hierarchies/${hierarchyId}/${this.endpoint}`, 35 | 'POST', 36 | { ...body, type: singularize(this.endpoint) }, 37 | token 38 | ) 39 | } 40 | 41 | Delete({ hierarchyId, nodeId, token = null }) { 42 | return this.request.send( 43 | `hierarchies/${hierarchyId}/${this.endpoint}/${nodeId}`, 44 | 'DELETE', 45 | undefined, 46 | token 47 | ) 48 | } 49 | 50 | Update({ hierarchyId, nodeId, body, token = null }) { 51 | return this.request.send( 52 | `hierarchies/${hierarchyId}/${this.endpoint}/${nodeId}`, 53 | 'PUT', 54 | { ...body, type: singularize(this.endpoint) }, 55 | token 56 | ) 57 | } 58 | 59 | GetNodeChildren({ hierarchyId, nodeId, token = null }) { 60 | const { limit, offset } = this 61 | return this.request.send( 62 | buildURL( 63 | `hierarchies/${hierarchyId}/${this.endpoint}/${nodeId}/children`, 64 | { 65 | limit, 66 | offset 67 | } 68 | ), 69 | 'GET', 70 | undefined, 71 | token 72 | ) 73 | } 74 | 75 | Limit(value) { 76 | this.limit = value 77 | return this 78 | } 79 | 80 | Offset(value) { 81 | this.offset = value 82 | return this 83 | } 84 | } 85 | 86 | export default NodesEndpoint 87 | -------------------------------------------------------------------------------- /src/endpoints/oidc-profile.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class OidcProfileEndpoint extends CRUDExtend { 5 | constructor(config) { 6 | super(config) 7 | this.endpoint = 'authentication-realms/{{realmId}}/oidc-profiles' 8 | } 9 | 10 | All(realmId, token = null, headers = {}) { 11 | const { includes, sort, limit, offset, filter } = this 12 | 13 | this.call = this.request.send( 14 | buildURL(this.endpoint.replace('{{realmId}}', realmId), { 15 | includes, 16 | sort, 17 | limit, 18 | offset, 19 | filter 20 | }), 21 | 'GET', 22 | undefined, 23 | token, 24 | this, 25 | headers 26 | ) 27 | 28 | return this.call 29 | } 30 | 31 | Create(realmId, body) { 32 | return this.request.send( 33 | this.endpoint.replace('{{realmId}}', realmId), 34 | 'POST', 35 | body.data 36 | ) 37 | } 38 | 39 | Get({ realmId, profileId, token = null, headers = {} }) { 40 | return this.request.send( 41 | `${this.endpoint.replace('{{realmId}}', realmId)}/${profileId}`, 42 | 'GET', 43 | undefined, 44 | token, 45 | this, 46 | headers 47 | ) 48 | } 49 | 50 | Update(realmId, profileId, body, token = null) { 51 | return this.request.send( 52 | `${this.endpoint.replace('{{realmId}}', realmId)}/${profileId}`, 53 | 'PUT', 54 | body.data, 55 | token 56 | ) 57 | } 58 | 59 | Delete(realmId, profileId) { 60 | return this.request.send( 61 | `${this.endpoint.replace('{{realmId}}', realmId)}/${profileId}`, 62 | 'DELETE' 63 | ) 64 | } 65 | } 66 | 67 | export default OidcProfileEndpoint 68 | -------------------------------------------------------------------------------- /src/endpoints/one-time-password-token-request.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class OneTimePasswordTokenRequestEndpoint extends CRUDExtend { 4 | constructor(config) { 5 | super(config) 6 | this.endpoint = 7 | 'authentication-realms/{{realmId}}/password-profiles/{{passwordProfileId}}/one-time-password-token-request' 8 | } 9 | 10 | Create(realmId, passwordProfileId, body, token = null) { 11 | return this.request.send( 12 | this.endpoint 13 | .replace('{{realmId}}', realmId) 14 | .replace('{{passwordProfileId}}', passwordProfileId), 15 | 'POST', 16 | body, 17 | token 18 | ) 19 | } 20 | } 21 | 22 | export default OneTimePasswordTokenRequestEndpoint 23 | -------------------------------------------------------------------------------- /src/endpoints/orders.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | 3 | import { 4 | buildURL 5 | } from '../utils/helpers' 6 | 7 | class OrdersEndpoint extends BaseExtend { 8 | constructor(endpoint) { 9 | super(endpoint) 10 | 11 | this.endpoint = 'orders' 12 | } 13 | 14 | Items(orderId) { 15 | return this.request.send(`${this.endpoint}/${orderId}/items`, 'GET') 16 | } 17 | 18 | AllShippingGroups(orderId) { 19 | return this.request.send(`${this.endpoint}/${orderId}/shipping-groups`, 'GET') 20 | } 21 | 22 | GetShippingGroup(orderId, shippingGroupId) { 23 | const { includes } = this 24 | return this.request.send( 25 | buildURL(`${this.endpoint}/${orderId}/shipping-groups/${shippingGroupId}`, { 26 | includes 27 | }), 28 | 'GET' 29 | ) 30 | } 31 | 32 | Payment(orderId, body) { 33 | return this.request.send(`${this.endpoint}/${orderId}/payments`, 'POST', { 34 | data: body, 35 | }, null, null, false) 36 | } 37 | 38 | Confirm(orderId, transactionId, body) { 39 | return this.request.send( 40 | `${this.endpoint}/${orderId}/transactions/${transactionId}/confirm`, 41 | 'POST', 42 | body 43 | ) 44 | } 45 | 46 | Transactions(orderId) { 47 | /* eslint-disable no-console */ 48 | console.warn( 49 | `DeprecationWarning: 'Order.Transactions(id)' will soon be deprecated. It's recommended you use Transactions class directly to get all, capture and refund transactions.` 50 | ) 51 | return this.request.send(`${this.endpoint}/${orderId}/transactions`, 'GET') 52 | } 53 | 54 | Update(orderId, body) { 55 | return this.request.send(`${this.endpoint}/${orderId}`, 'PUT', { 56 | ...body, 57 | type: 'order' 58 | }) 59 | } 60 | 61 | anonymize(ids) { 62 | return this.request.send(`${this.endpoint}/anonymize`, 'POST', ids) 63 | } 64 | } 65 | 66 | export default OrdersEndpoint 67 | -------------------------------------------------------------------------------- /src/endpoints/password-profile.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class PasswordProfileEndpoint extends CRUDExtend { 5 | constructor(config) { 6 | super(config) 7 | this.endpoint = 'authentication-realms/{{realmId}}/password-profiles' 8 | } 9 | 10 | Create(realmId, body) { 11 | return this.request.send( 12 | this.endpoint.replace('{{realmId}}', realmId), 13 | 'POST', 14 | body.data 15 | ) 16 | } 17 | 18 | All(realmId, token = null, headers = {}) { 19 | const { limit, offset } = this 20 | return this.request.send( 21 | buildURL(`${this.endpoint.replace('{{realmId}}', realmId)}`, { 22 | limit, 23 | offset 24 | }), 25 | 'GET', 26 | undefined, 27 | token, 28 | this, 29 | headers 30 | ) 31 | } 32 | 33 | Get({ realmId, profileId }) { 34 | return this.request.send( 35 | `${this.endpoint.replace('{{realmId}}', realmId)}/${profileId}`, 36 | 'GET' 37 | ) 38 | } 39 | 40 | Update(realmId, profileId, body, token = null) { 41 | return this.request.send( 42 | `${this.endpoint.replace('{{realmId}}', realmId)}/${profileId}`, 43 | 'PUT', 44 | body.data, 45 | token 46 | ) 47 | } 48 | 49 | Delete(realmId, profileId) { 50 | return this.request.send( 51 | `${this.endpoint.replace('{{realmId}}', realmId)}/${profileId}`, 52 | 'DELETE' 53 | ) 54 | } 55 | } 56 | 57 | export default PasswordProfileEndpoint 58 | -------------------------------------------------------------------------------- /src/endpoints/pcm-file-relationship.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | import { buildRelationshipData } from '../utils/helpers' 3 | 4 | class PCMFileRelationshipEndpoint { 5 | constructor(endpoint) { 6 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 7 | this.request = new RequestFactory(config) 8 | config.version = 'pcm' 9 | this.endpoint = 'relationships/files' 10 | } 11 | 12 | All(productId) { 13 | return this.request.send(`products/${productId}/${this.endpoint}`, 'GET') 14 | } 15 | 16 | Create(productId, resources) { 17 | const body = buildRelationshipData('file', resources) 18 | return this.request.send( 19 | `products/${productId}/${this.endpoint}`, 20 | 'POST', 21 | body 22 | ) 23 | } 24 | 25 | Delete(productId, resources) { 26 | const body = buildRelationshipData('file', resources) 27 | return this.request.send( 28 | `products/${productId}/${this.endpoint}`, 29 | 'DELETE', 30 | body 31 | ) 32 | } 33 | 34 | Update(productId, resources) { 35 | const body = buildRelationshipData('file', resources) 36 | return this.request.send( 37 | `products/${productId}/${this.endpoint}`, 38 | 'PUT', 39 | body 40 | ) 41 | } 42 | } 43 | 44 | export default PCMFileRelationshipEndpoint 45 | -------------------------------------------------------------------------------- /src/endpoints/pcm-jobs.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | import CRUDExtend from "../extends/crud"; 3 | import { buildURL } from "../utils/helpers"; 4 | 5 | class PCMJobs extends CRUDExtend { 6 | constructor(endpoint) { 7 | super(endpoint) 8 | const config = { ...endpoint, version: 'pcm' } 9 | this.request = new RequestFactory(config) 10 | this.endpoint = 'jobs' 11 | } 12 | 13 | GetJobErrors(jobId) { 14 | const { limit, offset } = this 15 | return this.request.send( 16 | buildURL(`${this.endpoint}/${jobId}/errors`, { 17 | limit, 18 | offset 19 | }),'GET' 20 | ) 21 | } 22 | } 23 | 24 | export default PCMJobs 25 | -------------------------------------------------------------------------------- /src/endpoints/pcm-main-image-relationship.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | 3 | class PCMMainImageRelationshipEndpoint { 4 | constructor(endpoint) { 5 | const config = { ...endpoint } 6 | this.request = new RequestFactory(config) 7 | config.version = 'pcm' 8 | this.endpoint = 'relationships/main_image' 9 | } 10 | 11 | Get(productId) { 12 | return this.request.send(`products/${productId}/${this.endpoint}`, 'GET') 13 | } 14 | 15 | Create(productId, fileId) { 16 | return this.request.send(`products/${productId}/${this.endpoint}`, 'POST', { 17 | type: 'file', 18 | id: fileId 19 | }) 20 | } 21 | 22 | Delete(productId, fileId) { 23 | return this.request.send( 24 | `products/${productId}/${this.endpoint}`, 25 | 'DELETE', 26 | { 27 | type: 'file', 28 | id: fileId 29 | } 30 | ) 31 | } 32 | 33 | Update(productId, fileId) { 34 | return this.request.send(`products/${productId}/${this.endpoint}`, 'PUT', { 35 | type: 'file', 36 | id: fileId 37 | }) 38 | } 39 | } 40 | 41 | export default PCMMainImageRelationshipEndpoint 42 | -------------------------------------------------------------------------------- /src/endpoints/pcm-template-relationship.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | import { buildRelationshipData } from '../utils/helpers' 3 | 4 | class PCMTemplateRelationshipEndpoint { 5 | constructor(endpoint) { 6 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 7 | this.request = new RequestFactory(config) 8 | config.version = 'pcm' 9 | this.endpoint = 'relationships/templates' 10 | } 11 | 12 | All(productId) { 13 | return this.request.send(`products/${productId}/${this.endpoint}`, 'GET') 14 | } 15 | 16 | Create(productId, resources) { 17 | const body = buildRelationshipData('template', resources) 18 | return this.request.send( 19 | `products/${productId}/${this.endpoint}`, 20 | 'POST', 21 | body 22 | ) 23 | } 24 | 25 | Delete(productId, resources) { 26 | const body = buildRelationshipData('template', resources) 27 | return this.request.send( 28 | `products/${productId}/${this.endpoint}`, 29 | 'DELETE', 30 | body 31 | ) 32 | } 33 | } 34 | 35 | export default PCMTemplateRelationshipEndpoint 36 | -------------------------------------------------------------------------------- /src/endpoints/pcm-variations-relationships.js: -------------------------------------------------------------------------------- 1 | import { dasherize } from 'inflected' 2 | import RequestFactory from '../factories/request' 3 | import { buildRelationshipData } from '../utils/helpers' 4 | 5 | class PCMVariationsRelationshipsEndpoint { 6 | constructor(endpoint) { 7 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 8 | this.request = new RequestFactory(config) 9 | config.version = 'pcm' 10 | this.endpoint = 'relationships/variations' 11 | } 12 | 13 | All(productId) { 14 | return this.request.send(`products/${productId}/${this.endpoint}`, 'GET') 15 | } 16 | 17 | Create(productId, resources) { 18 | const body = buildRelationshipData( 19 | 'product-variation', 20 | resources, 21 | dasherize 22 | ) 23 | return this.request.send( 24 | `products/${productId}/${this.endpoint}`, 25 | 'POST', 26 | body 27 | ) 28 | } 29 | 30 | Delete(productId, resources) { 31 | const body = buildRelationshipData( 32 | 'product-variation', 33 | resources, 34 | dasherize 35 | ) 36 | return this.request.send( 37 | `products/${productId}/${this.endpoint}`, 38 | 'DELETE', 39 | body 40 | ) 41 | } 42 | 43 | Update(productId, resources) { 44 | const body = buildRelationshipData( 45 | 'product-variation', 46 | resources, 47 | dasherize 48 | ) 49 | return this.request.send( 50 | `products/${productId}/${this.endpoint}`, 51 | 'PUT', 52 | body 53 | ) 54 | } 55 | } 56 | 57 | export default PCMVariationsRelationshipsEndpoint 58 | -------------------------------------------------------------------------------- /src/endpoints/pcm.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import PCMFileRelationshipEndpoint from './pcm-file-relationship' 3 | import PCMVariationsRelationshipEndpoint from './pcm-variations-relationships' 4 | import PCMTemplateRelationshipEndpoint from './pcm-template-relationship' 5 | import PCMMainImageRelationshipEndpoint from './pcm-main-image-relationship' 6 | import { buildURL } from '../utils/helpers' 7 | import PCMJobs from './pcm-jobs' 8 | 9 | class PCMEndpoint extends CRUDExtend { 10 | constructor(endpoint) { 11 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 12 | config.version = 'pcm' 13 | super(config) 14 | 15 | this.FileRelationships = new PCMFileRelationshipEndpoint(config) 16 | this.VariationsRelationships = new PCMVariationsRelationshipEndpoint(config) 17 | this.TemplateRelationships = new PCMTemplateRelationshipEndpoint(config) 18 | this.MainImageRelationships = new PCMMainImageRelationshipEndpoint(config) 19 | this.Jobs = new PCMJobs(config) 20 | 21 | this.endpoint = 'products' 22 | } 23 | 24 | BuildChildProducts(productId) { 25 | return this.request.send(`${this.endpoint}/${productId}/build`, 'POST') 26 | } 27 | 28 | GetChildProducts(productId) { 29 | const { includes, sort, limit, offset, filter } = this 30 | return this.request.send( 31 | buildURL(`${this.endpoint}/${productId}/children`, { 32 | includes, 33 | sort, 34 | limit, 35 | offset, 36 | filter 37 | }), 38 | 'GET' 39 | ) 40 | } 41 | 42 | GetProductNodes(productId) { 43 | const { limit, offset } = this 44 | return this.request.send( 45 | buildURL(`${this.endpoint}/${productId}/nodes`, { 46 | limit, 47 | offset 48 | }), 49 | 'GET' 50 | ) 51 | } 52 | 53 | ImportProducts(file) { 54 | return this.request.send(`${this.endpoint}/import`, 'POST', file) 55 | } 56 | 57 | AttachNodes(body) { 58 | return this.request.send(`${this.endpoint}/attach_nodes`, 'POST', body) 59 | } 60 | 61 | DetachNodes(body) { 62 | return this.request.send(`${this.endpoint}/detach_nodes`, 'POST', body) 63 | } 64 | 65 | ExportProducts(filter, useTemplateSlugs) { 66 | return this.request.send( 67 | buildURL(`${this.endpoint}/export`, { 68 | filter, 69 | useTemplateSlugs 70 | }), 71 | 'POST' 72 | ) 73 | } 74 | } 75 | 76 | export default PCMEndpoint 77 | -------------------------------------------------------------------------------- /src/endpoints/personal-data.js: -------------------------------------------------------------------------------- 1 | import { buildURL } from '../utils/helpers' 2 | import BaseExtend from '../extends/base' 3 | 4 | class PersonalDataEndpoint extends BaseExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'personal-data/logs' 8 | } 9 | 10 | All(token = null) { 11 | const { limit, offset, filter } = this 12 | 13 | const url = buildURL(this.endpoint, { 14 | limit, 15 | offset, 16 | filter 17 | }) 18 | 19 | return this.request.send(url, 'GET', undefined, token, this) 20 | } 21 | 22 | Filter(resourceType, resourceId) { 23 | this.filter = { 24 | eq: { 25 | resource_type: resourceType, 26 | resource_id: resourceId 27 | } 28 | } 29 | 30 | return this 31 | } 32 | } 33 | 34 | export default PersonalDataEndpoint 35 | -------------------------------------------------------------------------------- /src/endpoints/price-book-price-modifiers.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class PriceBookPriceModifiersEndpoint { 5 | constructor(endpoint) { 6 | const config = { ...endpoint } 7 | this.request = new RequestFactory(config) 8 | config.version = 'pcm' 9 | this.endpoint = 'modifiers' 10 | } 11 | 12 | All({ pricebookId, token = null }) { 13 | const { limit, offset, filter } = this 14 | 15 | return this.request.send( 16 | buildURL(`pricebooks/${pricebookId}/${this.endpoint}`, { 17 | limit, 18 | offset, 19 | filter 20 | }), 21 | 'GET', 22 | undefined, 23 | token, 24 | this 25 | ) 26 | } 27 | 28 | Limit(value) { 29 | this.limit = value 30 | return this 31 | } 32 | 33 | Offset(value) { 34 | this.offset = value 35 | return this 36 | } 37 | 38 | Get({ pricebookId, priceModifierId, token = null }) { 39 | return this.request.send( 40 | `pricebooks/${pricebookId}/${this.endpoint}/${priceModifierId}`, 41 | 'GET', 42 | undefined, 43 | token 44 | ) 45 | } 46 | 47 | Create({ pricebookId, body, token = null }) { 48 | return this.request.send( 49 | `pricebooks/${pricebookId}/${this.endpoint}`, 50 | 'POST', 51 | { ...body, type: 'price-modifier' }, 52 | token 53 | ) 54 | } 55 | 56 | Update({ pricebookId, priceModifierId, body, token = null }) { 57 | return this.request.send( 58 | `pricebooks/${pricebookId}/${this.endpoint}/${priceModifierId}`, 59 | 'PUT', 60 | { ...body, type: 'price-modifier' }, 61 | token 62 | ) 63 | } 64 | 65 | Delete({ pricebookId, priceModifierId, token = null }) { 66 | return this.request.send( 67 | `pricebooks/${pricebookId}/${this.endpoint}/${priceModifierId}`, 68 | 'DELETE', 69 | undefined, 70 | token 71 | ) 72 | } 73 | } 74 | 75 | export default PriceBookPriceModifiersEndpoint 76 | -------------------------------------------------------------------------------- /src/endpoints/price-book-prices.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class PriceBookPricesEndpoint { 5 | constructor(endpoint) { 6 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 7 | this.request = new RequestFactory(config) 8 | config.version = 'pcm' 9 | this.endpoint = 'prices' 10 | } 11 | 12 | // TODO: API - currently not working! (can get from pricebook relationships) 13 | All({ pricebookId, token = null }) { 14 | const { limit, offset, filter } = this 15 | 16 | return this.request.send( 17 | buildURL(`pricebooks/${pricebookId}/${this.endpoint}`, { 18 | limit, 19 | offset, 20 | filter 21 | }), 22 | 'GET', 23 | undefined, 24 | token, 25 | this 26 | ) 27 | } 28 | 29 | Filter(filter) { 30 | this.filter = filter 31 | return this 32 | } 33 | 34 | Limit(value) { 35 | this.limit = value 36 | return this 37 | } 38 | 39 | Offset(value) { 40 | this.offset = value 41 | return this 42 | } 43 | 44 | Get({ pricebookId, priceId, token = null }) { 45 | return this.request.send( 46 | `pricebooks/${pricebookId}/${this.endpoint}/${priceId}`, 47 | 'GET', 48 | undefined, 49 | token 50 | ) 51 | } 52 | 53 | Create({ pricebookId, body, token = null }) { 54 | return this.request.send( 55 | `pricebooks/${pricebookId}/${this.endpoint}`, 56 | 'POST', 57 | { ...body, type: 'product-price' }, 58 | token 59 | ) 60 | } 61 | 62 | Delete({ pricebookId, priceId, token = null }) { 63 | return this.request.send( 64 | `pricebooks/${pricebookId}/${this.endpoint}/${priceId}`, 65 | 'DELETE', 66 | undefined, 67 | token 68 | ) 69 | } 70 | 71 | Update({ pricebookId, priceId, body, token = null }) { 72 | return this.request.send( 73 | `pricebooks/${pricebookId}/${this.endpoint}/${priceId}`, 74 | 'PUT', 75 | { ...body, type: 'product-price' }, 76 | token 77 | ) 78 | } 79 | } 80 | 81 | export default PriceBookPricesEndpoint 82 | -------------------------------------------------------------------------------- /src/endpoints/price-books.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import PriceBookPricesEndpoint from './price-book-prices' 3 | import PriceBookPriceModifiersEndpoint from './price-book-price-modifiers' 4 | 5 | class PriceBooksEndpoint extends CRUDExtend { 6 | constructor(endpoint) { 7 | const config = { ...endpoint } // Need to clone config so it is only updated in PCM 8 | config.version = 'pcm' 9 | super(config) 10 | this.Prices = new PriceBookPricesEndpoint(config) 11 | this.PriceModifiers = new PriceBookPriceModifiersEndpoint(config) 12 | 13 | this.endpoint = 'pricebooks' 14 | } 15 | 16 | ImportProductPrices(file) { 17 | return this.request.send(`${this.endpoint}/import`, 'POST', file) 18 | } 19 | 20 | } 21 | 22 | export default PriceBooksEndpoint 23 | -------------------------------------------------------------------------------- /src/endpoints/products.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildRelationshipData, formatUrlResource } from '../utils/helpers' 3 | 4 | class ProductsEndpoint extends CRUDExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | 8 | this.endpoint = 'products' 9 | } 10 | 11 | CreateRelationships(id, type, resources) { 12 | const body = buildRelationshipData(type, resources) 13 | const parsedType = formatUrlResource(type) 14 | 15 | return this.request.send( 16 | `${this.endpoint}/${id}/relationships/${parsedType}`, 17 | 'POST', 18 | type === 'main-image' ? body[0] : body 19 | ) 20 | } 21 | 22 | DeleteRelationships(id, type, resources) { 23 | const body = buildRelationshipData(type, resources) 24 | const parsedType = formatUrlResource(type) 25 | 26 | return this.request.send( 27 | `${this.endpoint}/${id}/relationships/${parsedType}`, 28 | 'DELETE', 29 | type === 'main-image' ? body[0] : body 30 | ) 31 | } 32 | 33 | UpdateRelationships(id, type, resources = null) { 34 | const body = buildRelationshipData(type, resources) 35 | const parsedType = formatUrlResource(type) 36 | 37 | return this.request.send( 38 | `${this.endpoint}/${id}/relationships/${parsedType}`, 39 | 'PUT', 40 | type === 'main-image' ? body[0] : body 41 | ) 42 | } 43 | 44 | BuildChildProducts(id) { 45 | return this.request.send(`${this.endpoint}/${id}/build`, 'POST') 46 | } 47 | } 48 | 49 | export default ProductsEndpoint 50 | -------------------------------------------------------------------------------- /src/endpoints/promotions.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class PromotionsEndpoint extends CRUDExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | 8 | this.endpoint = 'promotions' 9 | } 10 | 11 | Attributes() { 12 | return this.request.send(`${this.endpoint}/attributes`, 'GET') 13 | } 14 | 15 | Codes(promotionId, token = null) { 16 | const { limit, offset, filter } = this 17 | return this.request.send( 18 | buildURL(`${this.endpoint}/${promotionId}/codes`, { 19 | limit, 20 | offset, 21 | filter 22 | }), 23 | 'GET', 24 | undefined, 25 | token, 26 | this 27 | ) 28 | } 29 | 30 | PromotionJobs(promotionId) { 31 | const { limit, offset, filter } = this 32 | return this.request.send( 33 | buildURL(`${this.endpoint}/${promotionId}/jobs`, { 34 | limit, 35 | offset, 36 | filter 37 | }), 38 | 'GET' 39 | ) 40 | } 41 | 42 | AddCodes(promotionId, codes) { 43 | return this.request.send(`${this.endpoint}/${promotionId}/codes`, 'POST', { 44 | type: 'promotion_codes', 45 | codes 46 | }) 47 | } 48 | 49 | AddCodesJob(promotionId, body) { 50 | return this.request.send(`${this.endpoint}/${promotionId}/jobs`, 'POST', body) 51 | } 52 | 53 | DeleteCode(promotionId, codeId) { 54 | return this.request.send( 55 | `${this.endpoint}/${promotionId}/codes/${codeId}`, 56 | 'DELETE' 57 | ) 58 | } 59 | 60 | DeleteCodes(promotionId, codes) { 61 | return this.request.send( 62 | `${this.endpoint}/${promotionId}/codes`, 63 | 'DELETE', 64 | { 65 | type: 'promotion_codes', 66 | codes 67 | } 68 | ) 69 | } 70 | 71 | History(promotionId) { 72 | const { limit, offset } = this 73 | 74 | return this.request.send( 75 | buildURL(`${this.endpoint}/${promotionId}/history`, { 76 | limit, 77 | offset 78 | }), 79 | 'GET' 80 | ) 81 | } 82 | 83 | GetCodeExportFile(promotionId, jobId) { 84 | return this.request.send(`${this.endpoint}/${promotionId}/jobs/${jobId}/file`, 'Get') 85 | } 86 | } 87 | 88 | export default PromotionsEndpoint 89 | -------------------------------------------------------------------------------- /src/endpoints/rule-promotions.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class RulePromotionsEndpoint extends CRUDExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | 8 | this.endpoint = 'rule-promotions' 9 | } 10 | 11 | Create(body) { 12 | return this.request.send(this.endpoint, 'POST', { 13 | ...body, 14 | type: 'rule_promotion' 15 | }) 16 | } 17 | 18 | Update(id, body, token = null) { 19 | return this.request.send( 20 | `${this.endpoint}/${id}`, 21 | 'PUT', 22 | { 23 | ...body, 24 | type: 'rule_promotion' 25 | }, 26 | token 27 | ) 28 | } 29 | 30 | Codes(promotionId, token = null) { 31 | const { limit, offset, filter } = this 32 | return this.request.send( 33 | buildURL(`${this.endpoint}/${promotionId}/codes`, { 34 | limit, 35 | offset, 36 | filter 37 | }), 38 | 'GET', 39 | undefined, 40 | token, 41 | this 42 | ) 43 | } 44 | 45 | AddCodes(promotionId, codes) { 46 | return this.request.send(`${this.endpoint}/${promotionId}/codes`, 'POST', { 47 | type: 'promotion_codes', 48 | codes 49 | }) 50 | } 51 | 52 | DeleteCode(promotionId, codeId) { 53 | return this.request.send( 54 | `${this.endpoint}/${promotionId}/codes/${codeId}`, 55 | 'DELETE' 56 | ) 57 | } 58 | 59 | 60 | DeleteCodes(promotionId, codes) { 61 | return this.request.send( 62 | `${this.endpoint}/${promotionId}/codes`, 63 | 'DELETE', 64 | { 65 | type: 'promotion_codes', 66 | codes 67 | } 68 | ) 69 | } 70 | } 71 | export default RulePromotionsEndpoint 72 | -------------------------------------------------------------------------------- /src/endpoints/settings.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | 3 | class Settings { 4 | constructor(config) { 5 | this.request = new RequestFactory(config) 6 | 7 | this.endpoint = 'settings' 8 | } 9 | 10 | All() { 11 | return this.request.send(this.endpoint, 'GET') 12 | } 13 | 14 | Update(body) { 15 | return this.request.send(this.endpoint, 'PUT', { 16 | type: 'settings', 17 | ...body 18 | }) 19 | } 20 | 21 | Delete() { 22 | return this.request.send(this.endpoint, 'DELETE') 23 | } 24 | 25 | GetLogsTtl() { 26 | return this.request.send(`${this.endpoint}/logs-ttl`, 'GET') 27 | } 28 | 29 | UpdateLogsTtl(days) { 30 | return this.request.send(`${this.endpoint}/logs-ttl`, 'PUT', { days, type: 'time_to_live' }); 31 | } 32 | 33 | Cart() { 34 | return this.request.send(`${this.endpoint}/cart`, 'GET') 35 | } 36 | 37 | UpdateCart(body) { 38 | return this.request.send(`${this.endpoint}/cart`, 'PUT', { 39 | type: 'settings', 40 | ...body 41 | }) 42 | } 43 | 44 | Subscriptions() { 45 | return this.request.send(`${this.endpoint}/subscriptions`, 'GET') 46 | } 47 | 48 | UpdateSubscriptions(body) { 49 | return this.request.send(`${this.endpoint}/subscriptions`, 'PUT', body) 50 | } 51 | 52 | Promotions() { 53 | return this.request.send(`${this.endpoint}/promotions`, 'GET') 54 | } 55 | } 56 | 57 | export default Settings 58 | -------------------------------------------------------------------------------- /src/endpoints/subscription-dunning-rules.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionDunningRulesEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/dunning-rules' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body 22 | }, 23 | token 24 | ) 25 | } 26 | 27 | } 28 | 29 | export default SubscriptionDunningRulesEndpoint 30 | -------------------------------------------------------------------------------- /src/endpoints/subscription-jobs.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionJobsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/jobs' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | } 17 | 18 | export default SubscriptionJobsEndpoint 19 | -------------------------------------------------------------------------------- /src/endpoints/subscription-offerings.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionOfferingsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/offerings' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body 22 | }, 23 | token 24 | ) 25 | } 26 | 27 | Build(body) { 28 | return this.request.send(`${this.endpoint}/build`, 'POST', { 29 | ...body 30 | }) 31 | } 32 | 33 | AttachProducts(offeringId, body) { 34 | return this.request.send(`${this.endpoint}/${offeringId}/products/attach`, 'POST', { 35 | ...body 36 | }) 37 | } 38 | 39 | RemoveProduct(offeringId, productId) { 40 | return this.request.send(`${this.endpoint}/${offeringId}/products/${productId}`, 'DELETE') 41 | } 42 | 43 | AttachPlans(offeringId, body) { 44 | return this.request.send(`${this.endpoint}/${offeringId}/plans/attach`, 'POST', { 45 | ...body 46 | }) 47 | } 48 | 49 | RemovePlan(offeringId, planId) { 50 | return this.request.send(`${this.endpoint}/${offeringId}/plans/${planId}`, 'DELETE') 51 | } 52 | 53 | GetAttachedProducts(id) { 54 | return this.request.send(`${this.endpoint}/${id}/products`, 'GET') 55 | } 56 | 57 | GetAttachedPlans(id) { 58 | return this.request.send(`${this.endpoint}/${id}/plans`, 'GET') 59 | } 60 | 61 | AttachProrationPolicy(offeringId, body) { 62 | return this.request.send(`${this.endpoint}/${offeringId}/relationships/proration-policies`, 'PUT', { 63 | data: body 64 | }, undefined, undefined, false) 65 | } 66 | 67 | ReplaceProducts(offeringId, productIds) { 68 | return this.request.send(`${this.endpoint}/${offeringId}/products/replace`, 'PUT', { 69 | products: productIds 70 | }) 71 | } 72 | } 73 | 74 | export default SubscriptionOfferingsEndpoint 75 | -------------------------------------------------------------------------------- /src/endpoints/subscription-plan.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionPlansEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/plans' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body 22 | }, 23 | token 24 | ) 25 | } 26 | 27 | } 28 | 29 | export default SubscriptionPlansEndpoint 30 | -------------------------------------------------------------------------------- /src/endpoints/subscription-products.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionProductsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/products' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body 22 | }, 23 | token 24 | ) 25 | } 26 | 27 | } 28 | 29 | export default SubscriptionProductsEndpoint 30 | -------------------------------------------------------------------------------- /src/endpoints/subscription-proration-policies.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionProrationPoliciesEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/proration-policies' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body 22 | }, 23 | token 24 | ) 25 | } 26 | 27 | } 28 | 29 | export default SubscriptionProrationPoliciesEndpoint 30 | -------------------------------------------------------------------------------- /src/endpoints/subscription-schedules.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionSchedulesEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/schedules' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body 22 | }, 23 | token 24 | ) 25 | } 26 | 27 | } 28 | 29 | export default SubscriptionSchedulesEndpoint 30 | -------------------------------------------------------------------------------- /src/endpoints/subscription-subscribers.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionSubscribersEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/subscribers' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body 22 | }, 23 | token 24 | ) 25 | } 26 | 27 | } 28 | 29 | export default SubscriptionSubscribersEndpoint 30 | -------------------------------------------------------------------------------- /src/endpoints/subscriptions.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class SubscriptionsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'subscriptions/subscriptions' 8 | } 9 | 10 | Create(body) { 11 | return this.request.send(this.endpoint, 'POST', { 12 | ...body 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | body, 21 | token 22 | ) 23 | } 24 | 25 | GetInvoices(id) { 26 | return this.request.send(`${this.endpoint}/${id}/invoices`, 'GET') 27 | } 28 | 29 | GetAttachedProducts(id) { 30 | return this.request.send(`${this.endpoint}/${id}/products`, 'GET') 31 | } 32 | 33 | GetAttachedPlans(id) { 34 | return this.request.send(`${this.endpoint}/${id}/plans`, 'GET') 35 | } 36 | 37 | CreateState(id, action) { 38 | return this.request.send(`${this.endpoint}/${id}/states`, 'POST', { 39 | type: 'subscription_state', 40 | attributes: { 41 | action 42 | } 43 | }) 44 | } 45 | } 46 | 47 | export default SubscriptionsEndpoint 48 | -------------------------------------------------------------------------------- /src/endpoints/transactions.js: -------------------------------------------------------------------------------- 1 | import BaseExtend from '../extends/base' 2 | 3 | class TransactionsEndpoint extends BaseExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | 7 | this.endpoint = 'transactions' 8 | } 9 | 10 | All({ order }) { 11 | return this.request.send(`orders/${order}/${this.endpoint}`, 'GET') 12 | } 13 | 14 | Get({ order, transaction }, token = null) { 15 | return this.request.send( 16 | `orders/${order}/${this.endpoint}/${transaction}`, 17 | 'GET', 18 | undefined, 19 | token 20 | ) 21 | } 22 | 23 | Capture({ order, transaction }) { 24 | return this.request.send( 25 | `orders/${order}/${this.endpoint}/${transaction}/capture`, 26 | 'POST' 27 | ) 28 | } 29 | 30 | Refund({ order, transaction }, body = {}) { 31 | return this.request.send( 32 | `orders/${order}/${this.endpoint}/${transaction}/refund`, 33 | 'POST', 34 | body 35 | ) 36 | } 37 | 38 | Cancel({ order, transaction }, body = {}) { 39 | return this.request.send( 40 | `orders/${order}/${this.endpoint}/${transaction}/cancel`, 41 | 'POST', 42 | body 43 | ) 44 | } 45 | } 46 | 47 | export default TransactionsEndpoint 48 | -------------------------------------------------------------------------------- /src/endpoints/user-authentication-info.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class UserAuthenticationInfoEndpoint extends CRUDExtend { 5 | constructor(endpoint) { 6 | super(endpoint) 7 | this.endpoint = 'authentication-realms/{{realmId}}/user-authentication-info' 8 | } 9 | 10 | Create(realmId, body, token = null) { 11 | return this.request.send( 12 | this.endpoint.replace('{{realmId}}', realmId), 13 | 'POST', 14 | body.data, 15 | token 16 | ) 17 | } 18 | 19 | All(realmId, token = null, headers = {}) { 20 | const { limit, offset, filter } = this 21 | return this.request.send( 22 | buildURL(`${this.endpoint.replace('{{realmId}}', realmId)}`, { 23 | limit, 24 | offset, 25 | filter 26 | }), 27 | 'GET', 28 | undefined, 29 | token, 30 | this, 31 | headers 32 | ) 33 | } 34 | 35 | Get(realmId, userAuthenticationInfoId, token = null) { 36 | return this.request.send( 37 | `${this.endpoint.replace( 38 | '{{realmId}}', 39 | realmId 40 | )}/${userAuthenticationInfoId}`, 41 | 'GET', 42 | undefined, 43 | token 44 | ) 45 | } 46 | 47 | Update(realmId, userAuthenticationInfoId, body, token = null) { 48 | return this.request.send( 49 | `${this.endpoint.replace( 50 | '{{realmId}}', 51 | realmId 52 | )}/${userAuthenticationInfoId}`, 53 | 'PUT', 54 | body.data, 55 | token 56 | ) 57 | } 58 | 59 | Delete(realmId, userAuthenticationInfoId, token = null) { 60 | return this.request.send( 61 | `${this.endpoint.replace( 62 | '{{realmId}}', 63 | realmId 64 | )}/${userAuthenticationInfoId}`, 65 | 'DELETE', 66 | undefined, 67 | token 68 | ) 69 | } 70 | } 71 | 72 | export default UserAuthenticationInfoEndpoint 73 | -------------------------------------------------------------------------------- /src/endpoints/user-authentication-password-profile.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class UserAuthenticationPasswordProfileEndpoint extends CRUDExtend { 5 | constructor(config) { 6 | super(config) 7 | this.endpoint = 8 | 'authentication-realms/{{realmId}}/user-authentication-info/{{userAuthenticationInfoId}}/user-authentication-password-profile-info' 9 | } 10 | 11 | Create(realmId, userAuthenticationInfoId, body, token = null) { 12 | return this.request.send( 13 | this.endpoint 14 | .replace('{{realmId}}', realmId) 15 | .replace('{{userAuthenticationInfoId}}', userAuthenticationInfoId), 16 | 'POST', 17 | body.data, 18 | token 19 | ) 20 | } 21 | 22 | All(realmId, userAuthenticationInfoId, token = null, headers = {}) { 23 | const { limit, offset } = this 24 | return this.request.send( 25 | buildURL( 26 | `${this.endpoint 27 | .replace('{{realmId}}', realmId) 28 | .replace('{{userAuthenticationInfoId}}', userAuthenticationInfoId)}`, 29 | { 30 | limit, 31 | offset 32 | } 33 | ), 34 | 'GET', 35 | undefined, 36 | token, 37 | this, 38 | headers 39 | ) 40 | } 41 | 42 | Get( 43 | realmId, 44 | userAuthenticationInfoId, 45 | userAuthenticationPasswordProfileId, 46 | token = null 47 | ) { 48 | return this.request.send( 49 | `${this.endpoint 50 | .replace('{{realmId}}', realmId) 51 | .replace( 52 | '{{userAuthenticationInfoId}}', 53 | userAuthenticationInfoId 54 | )}/${userAuthenticationPasswordProfileId}`, 55 | 'GET', 56 | undefined, 57 | token 58 | ) 59 | } 60 | 61 | Update( 62 | realmId, 63 | userAuthenticationInfoId, 64 | userAuthenticationPasswordProfileId, 65 | body, 66 | token = null 67 | ) { 68 | return this.request.send( 69 | `${this.endpoint 70 | .replace('{{realmId}}', realmId) 71 | .replace( 72 | '{{userAuthenticationInfoId}}', 73 | userAuthenticationInfoId 74 | )}/${userAuthenticationPasswordProfileId}`, 75 | 'PUT', 76 | body.data, 77 | token 78 | ) 79 | } 80 | 81 | Delete( 82 | realmId, 83 | userAuthenticationInfoId, 84 | userAuthenticationPasswordProfileId, 85 | token = null 86 | ) { 87 | return this.request.send( 88 | `${this.endpoint 89 | .replace('{{realmId}}', realmId) 90 | .replace( 91 | '{{userAuthenticationInfoId}}', 92 | userAuthenticationInfoId 93 | )}/${userAuthenticationPasswordProfileId}`, 94 | 'DELETE', 95 | undefined, 96 | token 97 | ) 98 | } 99 | } 100 | 101 | export default UserAuthenticationPasswordProfileEndpoint 102 | -------------------------------------------------------------------------------- /src/endpoints/variations.js: -------------------------------------------------------------------------------- 1 | import CRUDExtend from '../extends/crud' 2 | 3 | class VariationsEndpoint extends CRUDExtend { 4 | constructor(endpoint) { 5 | super(endpoint) 6 | this.endpoint = 'variations' 7 | } 8 | 9 | Create(body) { 10 | return this.request.send(this.endpoint, 'POST', { 11 | ...body, 12 | type: 'product-variation' 13 | }) 14 | } 15 | 16 | Update(id, body, token = null) { 17 | return this.request.send( 18 | `${this.endpoint}/${id}`, 19 | 'PUT', 20 | { 21 | ...body, 22 | type: 'product-variation' 23 | }, 24 | token 25 | ) 26 | } 27 | 28 | Option(variationId, optionId) { 29 | return this.request.send( 30 | `${this.endpoint}/${variationId}/options/${optionId}`, 31 | 'GET' 32 | ) 33 | } 34 | 35 | Options(variationId) { 36 | return this.request.send(`${this.endpoint}/${variationId}/options`, 'GET') 37 | } 38 | 39 | CreateOption(variationId, body) { 40 | return this.request.send( 41 | `${this.endpoint}/${variationId}/options`, 42 | 'post', 43 | body 44 | ) 45 | } 46 | 47 | UpdateOption(variationId, optionId, body) { 48 | return this.request.send( 49 | `${this.endpoint}/${variationId}/options/${optionId}`, 50 | 'PUT', 51 | body 52 | ) 53 | } 54 | 55 | DeleteOption(variationId, optionId) { 56 | return this.request.send( 57 | `${this.endpoint}/${variationId}/options/${optionId}`, 58 | 'DELETE' 59 | ) 60 | } 61 | 62 | Modifier(variationId, optionId, modifierId) { 63 | return this.request.send( 64 | `${ 65 | this.endpoint 66 | }/${variationId}/options/${optionId}/modifiers/${modifierId}`, 67 | 'GET' 68 | ) 69 | } 70 | 71 | Modifiers(variationId, optionId) { 72 | return this.request.send( 73 | `${this.endpoint}/${variationId}/options/${optionId}/modifiers`, 74 | 'GET' 75 | ) 76 | } 77 | 78 | CreateModifier(variationId, optionId, body) { 79 | return this.request.send( 80 | `${this.endpoint}/${variationId}/options/${optionId}/modifiers`, 81 | 'post', 82 | body 83 | ) 84 | } 85 | 86 | UpdateModifier(variationId, optionId, modifierId, body) { 87 | return this.request.send( 88 | `${ 89 | this.endpoint 90 | }/${variationId}/options/${optionId}/modifiers/${modifierId}`, 91 | 'PUT', 92 | body 93 | ) 94 | } 95 | 96 | DeleteModifier(variationId, optionId, modifierId) { 97 | return this.request.send( 98 | `${ 99 | this.endpoint 100 | }/${variationId}/options/${optionId}/modifiers/${modifierId}`, 101 | 'DELETE' 102 | ) 103 | } 104 | } 105 | 106 | export default VariationsEndpoint 107 | -------------------------------------------------------------------------------- /src/extends/base.js: -------------------------------------------------------------------------------- 1 | import RequestFactory from '../factories/request' 2 | import { buildURL } from '../utils/helpers' 3 | 4 | class BaseExtend { 5 | constructor(config) { 6 | this.request = new RequestFactory(config) 7 | this.config = config 8 | } 9 | 10 | All(token = null) { 11 | const { includes, sort, limit, offset, filter } = this 12 | 13 | this.call = this.request.send( 14 | buildURL(this.endpoint, { 15 | includes, 16 | sort, 17 | limit, 18 | offset, 19 | filter 20 | }), 21 | 'GET', 22 | undefined, 23 | token, 24 | this 25 | ) 26 | 27 | return this.call 28 | } 29 | 30 | Get(id, token = null) { 31 | this.call = this.request.send( 32 | buildURL(`${this.endpoint}/${id}`, { 33 | includes: this.includes 34 | }), 35 | 'GET', 36 | undefined, 37 | token, 38 | this 39 | ) 40 | 41 | return this.call 42 | } 43 | 44 | Filter(filter) { 45 | this.filter = filter 46 | 47 | return this 48 | } 49 | 50 | Limit(value) { 51 | this.limit = value 52 | 53 | return this 54 | } 55 | 56 | Offset(value) { 57 | this.offset = value 58 | 59 | return this 60 | } 61 | 62 | Sort(value) { 63 | this.sort = value 64 | 65 | return this 66 | } 67 | 68 | With(includes) { 69 | if (includes) this.includes = includes.toString().toLowerCase() 70 | 71 | return this 72 | } 73 | 74 | Attributes(token = null) { 75 | return this.request.send( 76 | `${this.endpoint}/attributes`, 77 | 'GET', 78 | undefined, 79 | token 80 | ) 81 | } 82 | } 83 | 84 | export default BaseExtend 85 | -------------------------------------------------------------------------------- /src/extends/crud.js: -------------------------------------------------------------------------------- 1 | import { singularize } from 'inflected' 2 | 3 | import BaseExtend from './base' 4 | 5 | class CRUDExtend extends BaseExtend { 6 | Create(body) { 7 | return this.request.send(this.endpoint, 'POST', { 8 | ...body, 9 | type: singularize(this.endpoint) 10 | }) 11 | } 12 | 13 | Delete(id) { 14 | return this.request.send(`${this.endpoint}/${id}`, 'DELETE') 15 | } 16 | 17 | Update(id, body, token = null) { 18 | return this.request.send( 19 | `${this.endpoint}/${id}`, 20 | 'PUT', 21 | { 22 | ...body, 23 | type: singularize(this.endpoint) 24 | }, 25 | token 26 | ) 27 | } 28 | } 29 | 30 | export default CRUDExtend 31 | -------------------------------------------------------------------------------- /src/factories/local-storage.js: -------------------------------------------------------------------------------- 1 | class LocalStorageFactory { 2 | constructor() { 3 | if (typeof localStorage === 'undefined' || localStorage === null) { 4 | const { LocalStorage } = require('node-localstorage') 5 | 6 | this.localStorage = new LocalStorage('./localStorage') 7 | } else { 8 | this.localStorage = window.localStorage 9 | } 10 | } 11 | 12 | set(key, value) { 13 | return this.localStorage.setItem(key, value) 14 | } 15 | 16 | get(key) { 17 | return this.localStorage.getItem(key) 18 | } 19 | 20 | delete(key) { 21 | return this.localStorage.removeItem(key) 22 | } 23 | } 24 | 25 | export default LocalStorageFactory 26 | -------------------------------------------------------------------------------- /src/factories/memory-storage.js: -------------------------------------------------------------------------------- 1 | class MemoryStorageFactory { 2 | constructor() { 3 | this.state = new Map() 4 | } 5 | 6 | set(key, value) { 7 | this.state.set(key, value) 8 | } 9 | 10 | get(key) { 11 | return this.state.get(key) || null 12 | } 13 | 14 | delete(key) { 15 | this.state.delete(key) 16 | } 17 | } 18 | 19 | export default MemoryStorageFactory 20 | -------------------------------------------------------------------------------- /src/factories/secure-cookies-storage.js: -------------------------------------------------------------------------------- 1 | import Cookies from 'js-cookie' 2 | 3 | class SecureCookiesStorageFactory { 4 | constructor() { 5 | this.cookies = Cookies 6 | } 7 | 8 | set(key, value) { 9 | return this.cookies.set(key, value, { secure: true, sameSite: 'strict' }) 10 | } 11 | 12 | get(key) { 13 | return this.cookies.get(key) 14 | } 15 | 16 | delete(key) { 17 | return this.cookies.remove(key) 18 | } 19 | } 20 | 21 | export default SecureCookiesStorageFactory 22 | -------------------------------------------------------------------------------- /src/types/account-authentication-settings.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Account Authentication Settings 3 | * Description: You can use the Account Authentication Settings endpoint to retrieve 4 | * settings controlling Account authentication. 5 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-authentication-settings/index.html 6 | */ 7 | import { Resource, RelationshipToOne, Identifiable } from './core' 8 | 9 | /** 10 | * The Account Authentication Settings Interface 11 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-authentication-settings/index.html#the-account-authentication-settings-object 12 | */ 13 | export interface AccountAuthenticationSettingsBase { 14 | type: string 15 | enable_self_signup: boolean, 16 | auto_create_account_for_account_members: boolean, 17 | account_management_authentication_token_timeout_secs?: number, 18 | account_member_self_management: string 19 | meta: object 20 | relationships: { 21 | 'authentication_realm': RelationshipToOne<'authentication_realm'> 22 | } 23 | } 24 | 25 | export interface AccountAuthenticationSettings extends AccountAuthenticationSettingsBase, Identifiable {} 26 | 27 | /** 28 | * AuthenticationRealm Endpoints 29 | */ 30 | export interface AccountAuthenticationSettingsEndpoint { 31 | /** 32 | * Get Account Authentication Settings 33 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-authentication-settings/get-account-authentication-settings.html 34 | */ 35 | Get(): Promise> 36 | 37 | Update(body: Partial): Promise> 38 | } 39 | -------------------------------------------------------------------------------- /src/types/account-membership-settings.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Account Membership Settings 3 | * Description: You can use the Account Membership Settings endpoint to retrieve 4 | * settings controlling Account Membership. 5 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-membership-settings/index.html 6 | */ 7 | import { Resource, Identifiable } from './core' 8 | 9 | /** 10 | * The Account Membership Settings Interface 11 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-membership-settings/index.html#the-account-membership-settings-object 12 | */ 13 | export interface AccountMembershipSettingsBase { 14 | type: string 15 | membership_limit: number 16 | } 17 | 18 | export interface AccountMembershipSettings extends AccountMembershipSettingsBase, Identifiable {} 19 | 20 | /** 21 | * AccountMembershipSettings Endpoints 22 | */ 23 | export interface AccountMembershipSettingsEndpoint { 24 | /** 25 | * Get an Account Membership Settings 26 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/account-membership-settings/get-account-membership-settings.html 27 | */ 28 | Get(): Promise> 29 | 30 | /** 31 | * Update an Account Membership Settings 32 | */ 33 | Update(body: Partial): Promise> 34 | } 35 | -------------------------------------------------------------------------------- /src/types/accounts.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Accounts 3 | */ 4 | import { 5 | CrudQueryableResource, 6 | Identifiable, 7 | Resource, 8 | ResourceList, 9 | } from './core' 10 | 11 | /** 12 | * The Account object Interface 13 | */ 14 | export interface Account extends AccountBase, Identifiable { 15 | meta: { 16 | timestamps: { 17 | created_at: string 18 | updated_at: string 19 | } 20 | } 21 | links: {} 22 | relationships: { 23 | parent: { 24 | data: { 25 | id: string 26 | type: string 27 | } 28 | } 29 | ancestors: [ 30 | { 31 | data: { 32 | id: string 33 | type: string 34 | } 35 | } 36 | ] 37 | } 38 | } 39 | 40 | export interface AccountBase { 41 | type: string 42 | name: string 43 | legal_name: string 44 | registration_id?: string 45 | parent_id?: string 46 | external_ref?: string 47 | } 48 | 49 | 50 | /** 51 | * filter for accounts 52 | */ 53 | export interface AccountFilter { 54 | eq?: { 55 | name?: string 56 | legal_name?: string 57 | registration_id?: string 58 | external_ref?: string 59 | } 60 | like?: { 61 | name?: string 62 | legal_name?: string 63 | registration_id?: string 64 | external_ref?: string 65 | } 66 | } 67 | export interface AccountUpdateBody extends Partial {} 68 | 69 | /** 70 | * Accounts Endpoints 71 | */ 72 | export interface AccountEndpoint 73 | extends Omit< 74 | CrudQueryableResource< 75 | Account, 76 | AccountBase, 77 | AccountUpdateBody, 78 | AccountFilter, 79 | never, 80 | never 81 | >, 82 | 'All' | 'Create' | 'Get' | 'Update' 83 | > { 84 | endpoint: 'account' 85 | storage: Storage 86 | 87 | /** 88 | * Get all Accounts 89 | * @param token - The Bearer token to grant access to the API. 90 | * @param headers 91 | */ 92 | All(token?: string, headers?): Promise> 93 | 94 | /** 95 | * Get an Account by reference 96 | * @param data.accountId - The ID for the requested account, 97 | * @param data.token - The Bearer token to grant access to the API. 98 | */ 99 | Get(accountId: string, token?: string): Promise> 100 | 101 | /** 102 | * Create an Account 103 | */ 104 | Create(body: AccountBase): Promise> 105 | 106 | /** 107 | * Update an Account 108 | */ 109 | Update(accountId: string, body: Partial): Promise> 110 | } 111 | -------------------------------------------------------------------------------- /src/types/address.d.ts: -------------------------------------------------------------------------------- 1 | import { AccountAddress, AccountAddressBase } from './account-address'; 2 | import { CustomerAddress, CustomerAddressBase } from './customer-address'; 3 | 4 | export type Address = AccountAddress | CustomerAddress; 5 | export type AddressBase = AccountAddressBase | CustomerAddressBase; 6 | -------------------------------------------------------------------------------- /src/types/application-keys.d.ts: -------------------------------------------------------------------------------- 1 | import { Identifiable, Resource, ResourcePage, CrudQueryableResource } from './core' 2 | 3 | export interface ApplicationKeyBase { 4 | name: string 5 | type: 'application_key' 6 | reserved_rate_limit?: number 7 | } 8 | 9 | export interface ApplicationKey extends ApplicationKeyBase, Identifiable { 10 | id: string 11 | client_id: string 12 | client_secret?: string 13 | meta: { 14 | timestamps: { 15 | created_at: string 16 | updated_at: string 17 | last_used_at: string | null 18 | } 19 | } 20 | } 21 | 22 | interface MetaReservedRps { 23 | meta: { 24 | total_reserved_rate_limit: number 25 | } 26 | } 27 | 28 | export interface ApplicationKeyResponse extends Resource { 29 | links: { 30 | self: string 31 | } 32 | } 33 | 34 | export interface ApplicationKeysEndpoint extends CrudQueryableResource< 35 | ApplicationKey, 36 | ApplicationKeyBase, 37 | Partial, 38 | never, 39 | never, 40 | never 41 | > { 42 | All(): Promise & MetaReservedRps> 43 | Create(body: ApplicationKeyBase): Promise 44 | Delete(id: string): Promise<{}> 45 | } 46 | -------------------------------------------------------------------------------- /src/types/authentication-settings.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Customer Authentication Settings 3 | * Description: You can use the Customer Authentication Settings endpoint to retrieve 4 | * settings controlling customer authentication. 5 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/customer-authentication-settings/index.html 6 | */ 7 | import { Resource, RelationshipToOne, Identifiable } from './core' 8 | 9 | /** 10 | * The Customer Authentication Settings Interface 11 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/customer-authentication-settings/index.html#the-customer-authentication-settings-object 12 | */ 13 | 14 | export interface AuthenticationSettingsBase { 15 | type: string 16 | meta: object 17 | relationships: { 18 | 'authentication-realm': RelationshipToOne<'authentication-realm'> 19 | } 20 | } 21 | 22 | export interface AuthenticationSettings 23 | extends AuthenticationSettingsBase, 24 | Identifiable {} 25 | 26 | /** 27 | * AuthenticationRealm Endpoints 28 | */ 29 | export interface AuthenticationSettingsEndpoint { 30 | /** 31 | * Get Customer Authentication Settings 32 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/settings/customer-authentication-settings/get-customer-authentication-settings.html 33 | */ 34 | Get(): Promise> 35 | } 36 | -------------------------------------------------------------------------------- /src/types/brand.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Brands 3 | * Description: The Brands API allows you to organize products into hierarchical groups. Where a shoe product might be 4 | * in the category Shoes, the individual product might also be in the brand Nike. 5 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/index.html 6 | */ 7 | import { Identifiable, CrudQueryableResource, RelationshipToMany } from './core' 8 | 9 | /** 10 | * Core Brand Base Interface 11 | * For custom flows, extend this interface 12 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/index.html 13 | */ 14 | export interface BrandBase { 15 | type: 'brand' 16 | name: string 17 | slug: string 18 | description: string 19 | status: 'live' | 'draft' 20 | } 21 | 22 | export interface Brand extends Identifiable, BrandBase { 23 | meta: { 24 | timestamps: { 25 | created_at: string 26 | updated_at: string 27 | } 28 | } 29 | relationships: { 30 | products: RelationshipToMany<'product'> 31 | } 32 | } 33 | 34 | /** 35 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/filtering.html 36 | */ 37 | export interface BrandFilter { 38 | eq?: { 39 | name?: string 40 | slug?: string 41 | status?: string 42 | } 43 | like?: { 44 | name?: string 45 | slug?: string 46 | } 47 | } 48 | 49 | /** 50 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/basics/sorting.html 51 | */ 52 | type BrandSort = 53 | | 'created_at' 54 | | 'description' 55 | | 'name' 56 | | 'slug' 57 | | 'status' 58 | | 'updated_at' 59 | 60 | type BrandInclude = 'products' 61 | 62 | /** 63 | * Brand Endpoints 64 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/get-all-brands.html 65 | * Get DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/get-a-brand.html 66 | * Get All DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/get-all-brands.html 67 | * Create DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/create-a-brand.html 68 | * Update DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/update-a-brand.html 69 | * Delete DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/brands/delete-a-brand.html 70 | */ 71 | export interface BrandEndpoint 72 | extends CrudQueryableResource< 73 | Brand, 74 | BrandBase, 75 | Identifiable & Partial, 76 | BrandFilter, 77 | BrandSort, 78 | BrandInclude 79 | > { 80 | endpoint: 'brand' 81 | } 82 | -------------------------------------------------------------------------------- /src/types/catalogs-nodes.d.ts: -------------------------------------------------------------------------------- 1 | import { Identifiable, Resource, ResourceList } from './core' 2 | 3 | export interface NodeBaseResponse extends Identifiable { 4 | type: 'node' 5 | attributes: { 6 | created_at: string 7 | published_at?: string 8 | description: string 9 | label: string 10 | name: string 11 | slug: string 12 | status: string 13 | updated_at: string 14 | curated_products?: string[] 15 | } 16 | relationships: { 17 | children: { 18 | id: string 19 | label: string 20 | name: string 21 | }[] 22 | products: { 23 | id: string 24 | type: string 25 | }[] 26 | parent: { 27 | data: { 28 | id: string 29 | type: 'node' 30 | } 31 | links: { 32 | related: string 33 | } 34 | } 35 | } 36 | } 37 | 38 | export interface NodesResponse extends NodeBaseResponse { 39 | links: { 40 | self: string 41 | } 42 | } 43 | 44 | export interface CatalogsNodesEndpoint { 45 | endpoint: 'nodes' 46 | 47 | Limit(value: number): CatalogsNodesEndpoint 48 | 49 | Offset(value: number): CatalogsNodesEndpoint 50 | 51 | All(options: { token?: string }): Promise> 52 | 53 | Get(options: { 54 | nodeId: string 55 | token?: string 56 | }): Promise> 57 | 58 | GetNodeChildren(options: { 59 | nodeId: string 60 | token?: string 61 | }): Promise> 62 | 63 | GetNodeChildrenFromCatalogReleases(options: { 64 | catalogId: string 65 | releaseId: string 66 | nodeId: string 67 | token?: string 68 | }): Promise> 69 | 70 | GetAllCatalogNodes(options: { 71 | catalogId: string 72 | releaseId: string 73 | token?: string 74 | }): Promise> 75 | 76 | GetNodeInCatalogRelease(options: { 77 | catalogId: string 78 | releaseId: string 79 | nodeId: string 80 | token?: string 81 | }): Promise> 82 | } 83 | -------------------------------------------------------------------------------- /src/types/catalogs-releases.d.ts: -------------------------------------------------------------------------------- 1 | import { Identifiable, Resource, ResourceList, ResourcePage } from './core' 2 | import { Hierarchy } from './hierarchies' 3 | import { ShopperCatalogReleaseBase } from "./catalog"; 4 | 5 | export interface ReleaseBase extends Identifiable { 6 | name: string 7 | published_at: string 8 | } 9 | 10 | export interface ReleaseResponse extends Identifiable { 11 | type: 'catalog' 12 | attributes: { 13 | hierarchies: { 14 | id: string 15 | label: string 16 | name: string 17 | } 18 | } 19 | } 20 | 21 | export interface ReleaseBodyBase { 22 | export_full_delta?: boolean 23 | } 24 | 25 | export interface CatalogsReleasesEndpoint { 26 | endpoint: 'releases' 27 | 28 | All(options: { 29 | catalogId: string 30 | token?: string 31 | }): Promise> 32 | 33 | Get(options: { 34 | catalogId: string 35 | releaseId: string 36 | token?: string 37 | }): Promise> 38 | 39 | GetAllHierarchies(options: { 40 | catalogId: string 41 | releaseId: string 42 | token?: string 43 | }): Promise> 44 | 45 | Create(options: { 46 | catalogId: string 47 | body?: ReleaseBodyBase 48 | token?: string 49 | }): Promise> 50 | 51 | Limit(value: number): CatalogsReleasesEndpoint 52 | 53 | Offset(value: number): CatalogsReleasesEndpoint 54 | } 55 | -------------------------------------------------------------------------------- /src/types/catalogs-rules.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products 3 | * Description: Products are the core resource to any Commerce Cloud project. They can be associated by category, collection, brands, and more. 4 | */ 5 | import { 6 | Identifiable, 7 | CrudQueryableResource 8 | } from './core' 9 | 10 | /** 11 | * Core PCM Product Base Interface 12 | * For custom flows, extend this interface 13 | */ 14 | export interface RuleBase { 15 | type: 'catalog_rule' 16 | attributes: { 17 | name: string 18 | description?: string 19 | catalog_id: string 20 | account_ids?: string[] 21 | customer_ids?: string[] 22 | channels?: string[] 23 | tags?: string[] 24 | schedules?: {valid_from: string, valid_to: string}[] 25 | } 26 | } 27 | 28 | export interface Rule extends Identifiable, RuleBase { 29 | links: { 30 | self: string 31 | } 32 | } 33 | 34 | // Do Not have any relationships yet //TODO 35 | 36 | export interface RuleFilter { 37 | // TODO 38 | } 39 | 40 | type RuleSort = // TODO 41 | | '' 42 | 43 | type RuleInclude = // TODO 44 | | '' 45 | 46 | export interface RuleUpdateBody extends RuleBase { 47 | id: string 48 | } 49 | 50 | export interface CatalogsRulesEndpoint 51 | extends CrudQueryableResource { 52 | endpoint: 'rules' 53 | id: string 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/types/catalogs.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products 3 | * Description: Products are the core resource to any Commerce Cloud project. They can be associated by category, collection, brands, and more. 4 | */ 5 | import { Identifiable, CrudQueryableResource, ResourceList } from './core' 6 | import { CatalogsNodesEndpoint } from './catalogs-nodes' 7 | import { CatalogsProductsEndpoint } from './catalogs-products' 8 | import { CatalogsReleasesEndpoint } from './catalogs-releases' 9 | import { CatalogsRulesEndpoint } from './catalogs-rules' 10 | import { ShopperCatalogReleaseBase } from './catalog' 11 | 12 | /** 13 | * Catalog Base interface 14 | * pricebook_id OR pricebook_ids must be present, but never both or neither 15 | */ 16 | export interface CatalogBase { 17 | type: 'catalog' 18 | attributes: { 19 | name: string 20 | description?: string 21 | hierarchy_ids: string[] 22 | pricebook_id?: string 23 | pricebook_ids?: { priority: number; id: string }[] 24 | created_at?: string 25 | updated_at?: string 26 | owner?: 'organization' | 'store' 27 | } 28 | } 29 | 30 | export interface Catalog extends Identifiable, CatalogBase { 31 | relationships?: { 32 | releases?: { 33 | links: { 34 | related: string 35 | } 36 | meta: { 37 | count?: number 38 | } 39 | } 40 | children?: { 41 | data: { 42 | type: 'node' 43 | id: string 44 | }[] 45 | } 46 | } 47 | } 48 | 49 | export interface CatalogFilter { 50 | // TODO 51 | } 52 | 53 | type CatalogSort = '' // TODO 54 | 55 | type CatalogInclude = '' // TODO 56 | 57 | /** 58 | * PCM Product Endpoints 59 | */ 60 | 61 | export type CatalogUpdateBody = Partial & Identifiable 62 | 63 | export interface CatalogsEndpoint 64 | extends CrudQueryableResource< 65 | Catalog, 66 | CatalogBase, 67 | CatalogUpdateBody, 68 | CatalogFilter, 69 | CatalogSort, 70 | CatalogInclude 71 | > { 72 | endpoint: 'catalogs' 73 | Nodes: CatalogsNodesEndpoint 74 | Products: CatalogsProductsEndpoint 75 | Releases: CatalogsReleasesEndpoint 76 | Rules: CatalogsRulesEndpoint 77 | GetCatalogReleases( 78 | catalogId: string, 79 | token?: string 80 | ): Promise> 81 | DeleteCatalogRelease( 82 | catalogId: string, 83 | releaseId: string, 84 | token?: string 85 | ): Promise 86 | DeleteAllCatalogReleases(catalogId: string, token?: string): Promise 87 | } 88 | -------------------------------------------------------------------------------- /src/types/category.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Categories 3 | * Description: Categories allow you to organize your Products into hierarchical groups. That means these groups can 4 | * also contain other Categories, which can then be viewed in a tree structure. 5 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/categories/index.html 6 | */ 7 | import { 8 | Identifiable, 9 | ResourceList, 10 | RelationshipToMany, 11 | CrudQueryableResource 12 | } from './core' 13 | 14 | /** 15 | * Core Category Base Interface 16 | * For custom flows, extend this interface 17 | * DOCS: 18 | */ 19 | export interface CategoryBase { 20 | type: string 21 | name: string 22 | slug: string 23 | description: string 24 | status: string 25 | } 26 | 27 | export interface Category extends Identifiable, CategoryBase { 28 | children?: Category[] 29 | meta?: { 30 | timestamps: { 31 | created_at: string 32 | updated_at: string 33 | } 34 | } 35 | relationships: { 36 | products: RelationshipToMany<'product'> 37 | } 38 | } 39 | 40 | /** 41 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/categories/filtering.html 42 | */ 43 | export interface CategoryFilter { 44 | eq?: { 45 | name?: string 46 | slug?: string 47 | status?: string 48 | } 49 | like?: { 50 | name?: string 51 | slug?: string 52 | } 53 | } 54 | 55 | type CategorySort = 56 | | 'created_at' 57 | | 'description' 58 | | 'name' 59 | | 'slug' 60 | | 'status' 61 | | 'updated_at' 62 | 63 | type CategoryInclude = 'products' 64 | 65 | /** 66 | * Category Endpoints 67 | */ 68 | export interface CategoryEndpoint 69 | extends CrudQueryableResource< 70 | Category, 71 | CategoryBase, 72 | Partial, 73 | CategoryFilter, 74 | CategorySort, 75 | CategoryInclude 76 | > { 77 | endpoint: 'category' 78 | 79 | /** 80 | * Title: Tree (Relationships) 81 | * Description: You can use the Categories API to associate categories with each other in a hierarchical tree 82 | * structure. The relationship between Categories is known as parents and children. You can create relationships 83 | * between categories by attaching parent and child category IDs to the category of interest. A category can have 1 84 | * parent but many children. The Category Relationship endpoint allows you to specify the parent and children of a 85 | * category in one request. 86 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/categories/relationships/index.html 87 | */ 88 | Tree(): Promise> 89 | } 90 | -------------------------------------------------------------------------------- /src/types/collection.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Collections 3 | * Description: Collections allow you to organize your products into hierarchical groups. Where a dress product might be in the category Clothing, the individual product might also be in the collection Summer. 4 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/index.html 5 | */ 6 | import { Identifiable, RelationshipToMany, CrudQueryableResource } from './core' 7 | 8 | /** 9 | * Core Collection Base Interface 10 | * For custom flows, extend this interface 11 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/index.html 12 | */ 13 | export interface CollectionBase { 14 | type: string 15 | name: string 16 | slug: string 17 | description: string 18 | status: string 19 | } 20 | 21 | export interface Collection extends Identifiable, CollectionBase { 22 | meta?: { 23 | timestamps: { 24 | created_at: string 25 | updated_at: string 26 | } 27 | } 28 | relationships?: { 29 | products: RelationshipToMany<'product'> 30 | } 31 | } 32 | 33 | /** 34 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/filtering.html 35 | */ 36 | export interface CollectionFilter { 37 | eq?: { 38 | name?: string 39 | slug?: string 40 | status?: string 41 | } 42 | like?: { 43 | name?: string 44 | slug?: string 45 | } 46 | } 47 | 48 | /** 49 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/basics/sorting.html 50 | */ 51 | type CollectionSort = 52 | | 'created_at' 53 | | 'description' 54 | | 'name' 55 | | 'slug' 56 | | 'status' 57 | | 'updated_at' 58 | type CollectionInclude = 'products' 59 | 60 | /** 61 | * Collection Endpoints 62 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/index.html 63 | * Get DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/get-a-collection.html 64 | * Get All DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/categories/get-all-categories.html 65 | * Create DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/create-a-collection.html 66 | * Update DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/update-a-collection.html 67 | * Delete DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/collections/delete-a-collection.html 68 | */ 69 | export interface CollectionEndpoint 70 | extends CrudQueryableResource< 71 | Collection, 72 | CollectionBase, 73 | Partial, 74 | CollectionFilter, 75 | CollectionSort, 76 | CollectionInclude 77 | > { 78 | endpoint: 'collection' 79 | } 80 | -------------------------------------------------------------------------------- /src/types/config.d.ts: -------------------------------------------------------------------------------- 1 | import { StorageFactory } from './storage' 2 | import { Moltin } from '../moltin' 3 | 4 | export interface RequestFactory { 5 | config: Config 6 | storage: StorageFactory 7 | 8 | authenticate(): Promise 9 | 10 | send( 11 | uri: string, 12 | method: HttpVerbs, 13 | body?: any, 14 | token?: string, 15 | instance?: Moltin, 16 | wrapBody?: Boolean, 17 | version?: 'v1' | 'v2' | 'v3' | 'pcm', 18 | additionalHeaders?: { [key: string]: string } 19 | ): Promise 20 | 21 | constructor(config: Config): void 22 | } 23 | 24 | export interface ConfigOptions { 25 | name?: string 26 | application?: string 27 | client_id?: string 28 | client_secret?: string 29 | language?: string 30 | currency?: string 31 | host?: string 32 | custom_fetch?: Function 33 | custom_authenticator?: () => Promise 34 | storage?: StorageFactory 35 | storage_type?: 'cookies' | 'localStorage' 36 | headers?: { [key: string]: string } 37 | disableCart?: boolean 38 | reauth?: boolean 39 | retryDelay?: number 40 | retryJitter?: number 41 | fetchMaxAttempts?: number 42 | throttleEnabled?: boolean 43 | throttleLimit?: number 44 | throttleInterval?: number 45 | } 46 | 47 | export interface Config { 48 | name?: string 49 | application?: string 50 | client_id: string 51 | client_secret?: string 52 | host: string 53 | protocol: 'https' 54 | version: 'v1' | 'v2' | 'v3' | 'pcm' 55 | currency?: string 56 | language?: string 57 | custom_fetch?: Function 58 | custom_authenticator?: () => Promise 59 | auth: { 60 | expires: 3600 61 | uri: 'oauth/access_token' 62 | fetch: Function 63 | } 64 | sdk: { 65 | version: string 66 | language: 'JS' 67 | } 68 | storage?: StorageFactory 69 | storage_type?: 'cookies' | 'localStorage' 70 | retryDelay?: number 71 | retryJitter?: number 72 | fetchMaxAttempts?: number 73 | throttleConfig?: { 74 | throttleEnabled?: boolean 75 | throttleLimit?: number 76 | throttleInterval?: number 77 | } 78 | constructor(options: ConfigOptions): void 79 | } 80 | 81 | export type HttpVerbs = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' 82 | 83 | export const enum GrantType { 84 | ClientCredentials = 'client_credentials', 85 | Implicit = 'implicit' 86 | } 87 | 88 | export interface AuthenticateResponseBody { 89 | expires: number 90 | identifier: GrantType 91 | expires_in: number 92 | access_token: string 93 | token_type: 'Bearer' 94 | } 95 | 96 | export interface CustomAuthenticatorResponseBody { 97 | expires: number 98 | access_token: string 99 | } 100 | -------------------------------------------------------------------------------- /src/types/core.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Supporting nested Partial properties 3 | * https://grrr.tech/posts/2021/typescript-partial/ 4 | */ 5 | export type Subset = { 6 | [attr in keyof K]?: K[attr] extends object ? Subset : K[attr] 7 | } 8 | 9 | export interface Identifiable { 10 | id: string 11 | } 12 | 13 | export interface Resource { 14 | data: R 15 | } 16 | 17 | export interface ResourceList { 18 | data: R[] 19 | } 20 | 21 | export interface ResourceIncluded extends Resource { 22 | included?: I 23 | } 24 | 25 | export interface Attribute { 26 | label: string 27 | value: string 28 | type: string 29 | required: boolean 30 | options?: string[] 31 | description?: string 32 | validation_rules?: Validation[] 33 | validation?: { 34 | regex: string 35 | } 36 | } 37 | 38 | export interface Validation { 39 | type: string 40 | to?: string 41 | options?: any 42 | } 43 | 44 | export interface AttributesMeta { 45 | entity: string 46 | version: string 47 | } 48 | 49 | export interface Attributes extends ResourceList { 50 | meta: AttributesMeta 51 | } 52 | 53 | export interface ResourcePage extends ResourceList { 54 | links: { [key: string]: string | null } 55 | meta: { 56 | page: { 57 | current: number 58 | limit: number 59 | offset: number 60 | total: number 61 | } 62 | results: { 63 | total: number 64 | } 65 | } 66 | included?: I 67 | } 68 | 69 | export interface Relationship { 70 | data: { 71 | id: string 72 | type: T 73 | } 74 | } 75 | 76 | export interface RelationshipToMany { 77 | data: { 78 | id: string 79 | type: T 80 | }[] 81 | } 82 | 83 | export interface RelationshipToOne { 84 | data: { 85 | id: string 86 | type: T 87 | } 88 | } 89 | 90 | export interface QueryableResource { 91 | All(token?: string): Promise> 92 | 93 | Get(id: string, token?: string): Promise> 94 | 95 | Filter(filter: F): QueryableResource 96 | 97 | Limit(value: number): QueryableResource 98 | 99 | Offset(value: number): QueryableResource 100 | 101 | Sort(value: S): QueryableResource 102 | 103 | With(includes: I | I[]): QueryableResource 104 | 105 | Attributes(token?: string): Promise 106 | } 107 | 108 | export interface CrudQueryableResource 109 | extends QueryableResource { 110 | Create(body: C, contentType?: string): Promise> 111 | 112 | Delete(id: string): Promise<{}> 113 | 114 | Update(id: string, body: U, token?: string): Promise> 115 | 116 | Link(url: string): Promise> 117 | } 118 | -------------------------------------------------------------------------------- /src/types/currency.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Currencies 3 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/index.html 4 | */ 5 | import { Identifiable, CrudQueryableResource } from './core' 6 | 7 | /** 8 | * Core Currency Base Interface 9 | * For custom flows, extend this interface 10 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/index.html 11 | */ 12 | export interface CurrencyBase { 13 | type: string 14 | default: boolean 15 | code: string 16 | exchange_rate: number 17 | enabled: boolean 18 | format: string 19 | decimal_point: string 20 | thousand_separator: string 21 | decimal_places: number 22 | } 23 | 24 | export interface Currency extends Identifiable, CurrencyBase { 25 | links: { 26 | self: string 27 | } 28 | meta: { 29 | timestamps: { 30 | created_at: string 31 | updated_at: string 32 | } 33 | owner?: 'organization' | 'store' 34 | } 35 | } 36 | 37 | /** 38 | * Currency Endpoints 39 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/index.html 40 | * Get DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/get-a-currency.html 41 | * Get All DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/get-all-currencies.html 42 | * Create DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/create-a-currency.html 43 | * Update DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/update-a-currency.html 44 | * Delete DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/currencies/delete-a-currency.html 45 | */ 46 | export interface CurrencyEndpoint 47 | extends CrudQueryableResource< 48 | Currency, 49 | CurrencyBase, 50 | Partial, 51 | never, 52 | never, 53 | never 54 | > { 55 | endpoint: 'currency' 56 | storage: Storage 57 | 58 | Set(id: string): Promise 59 | Active(): Promise 60 | } 61 | -------------------------------------------------------------------------------- /src/types/data-entries.d.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Identifiable, ResourcePage } from './core' 3 | 4 | export interface DataEntryRecord extends Identifiable { 5 | type: 'related_data_entry'; 6 | resource_id: string; 7 | resource_type: string; 8 | } 9 | 10 | export interface DataEntriesEndpoint { 11 | All(): Promise> 12 | 13 | Filter(resourceType: string, resourceId: string): DataEntriesEndpoint 14 | 15 | Limit(value: number): DataEntriesEndpoint 16 | 17 | Offset(value: number): DataEntriesEndpoint 18 | } 19 | -------------------------------------------------------------------------------- /src/types/erasure-requests.d.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Identifiable, ResourcePage } from './core' 3 | 4 | export interface ErasureRequestRecord extends Identifiable { 5 | type: 'erasure_request'; 6 | id: string; 7 | resource_id: string; 8 | resource_type: string; 9 | initiator: Record; 10 | status: string; 11 | status_description: string; 12 | created_at: string; 13 | updated_at: string; 14 | } 15 | 16 | export interface ErasureRequestsEndpoint { 17 | All(): Promise> 18 | 19 | Filter(resourceType: string, resourceId: string): ErasureRequestsEndpoint 20 | 21 | Limit(value: number): ErasureRequestsEndpoint 22 | 23 | Offset(value: number): ErasureRequestsEndpoint 24 | 25 | Create(resourceType: string, resourceId: string): Promise 26 | } 27 | -------------------------------------------------------------------------------- /src/types/extensions.d.ts: -------------------------------------------------------------------------------- 1 | export type Extensions = Record> -------------------------------------------------------------------------------- /src/types/field.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Fields 3 | * Description: A Field represents a single Field of data (for example a Product Rating) to be applied to an entity. All 4 | * Fields have a field_type (string, integer, boolean, date or relationship), a default value and an optional set of 5 | * validation rules. 6 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/fields.html 7 | */ 8 | import { Identifiable, Relationship, CrudQueryableResource } from './core' 9 | 10 | /** 11 | * Core Field Base Interface 12 | * For custom flows, extend this interface 13 | * DOCS: 14 | */ 15 | export interface FieldBase { 16 | type: string 17 | name: string 18 | slug: string 19 | field_type: string 20 | validation_rules: any[] 21 | description: string 22 | required: boolean 23 | default: any 24 | enabled: boolean 25 | order: number 26 | omit_null: boolean 27 | } 28 | 29 | export interface Field extends Identifiable, FieldBase { 30 | relationships: { 31 | addresses?: Relationship<'addresses'> 32 | products?: Relationship<'products'> 33 | brands?: Relationship<'brands'> 34 | collections?: Relationship<'collections'> 35 | categories?: Relationship<'categories'> 36 | customers?: Relationship<'customers'> 37 | cart_items?: Relationship<'cart_items'> 38 | orders?: Relationship<'orders'> 39 | order_items?: Relationship<'order_items'> 40 | promotions?: Relationship<'promotions'> 41 | flow?: Relationship<'flow'> 42 | } 43 | } 44 | 45 | export interface FieldsEndpoint 46 | extends CrudQueryableResource< 47 | Field, 48 | FieldBase, 49 | Partial, 50 | never, 51 | never, 52 | never 53 | > { 54 | endpoint: 'fields' 55 | } 56 | -------------------------------------------------------------------------------- /src/types/file.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Files 3 | * Description: The immutable files API is available via the multipart/form-data Content-Type for image uploads. 4 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/index.html 5 | */ 6 | import { Identifiable, CrudQueryableResource } from './core' 7 | 8 | /** 9 | * Core File Base Interface 10 | * For custom flows, extend this interface 11 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/index.html 12 | */ 13 | export interface FileBase { 14 | file_name?: string 15 | file?: string 16 | public?: boolean 17 | file_location?: string 18 | } 19 | 20 | export interface File extends Identifiable, FileBase { 21 | type: string 22 | mime_type: string 23 | file_size: number 24 | public: boolean 25 | link: { 26 | href: string 27 | } 28 | links: { 29 | self: string 30 | } 31 | meta?: { 32 | timestamps: { 33 | created_at: string 34 | } 35 | dimensions: { 36 | width: number 37 | height: number 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/filtering.html 44 | */ 45 | export interface FileFilter { 46 | eq?: { 47 | file_name?: string 48 | public?: boolean 49 | } 50 | like?: { 51 | file_name?: string 52 | } 53 | gt?: { 54 | width?: number 55 | height?: number 56 | file_size?: number 57 | } 58 | lt?: { 59 | width?: number 60 | height?: number 61 | file_size?: number 62 | } 63 | le?: { 64 | width?: number 65 | height?: number 66 | file_size?: number 67 | } 68 | ge?: { 69 | width?: number 70 | height?: number 71 | file_size?: number 72 | } 73 | in?: { 74 | id?: string[] 75 | } 76 | } 77 | 78 | /** 79 | * File Endpoints 80 | * Get DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/get-a-file.html 81 | * Get All DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/get-all-files.html 82 | * Create DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/create-a-file.html 83 | * Delete DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/files/delete-a-file.html 84 | */ 85 | export interface FileEndpoint 86 | extends CrudQueryableResource< 87 | File, 88 | FileBase, 89 | never, 90 | FileFilter, 91 | never, 92 | never 93 | > { 94 | endpoint: 'file' 95 | } 96 | -------------------------------------------------------------------------------- /src/types/flow.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Flows 3 | * Description: A Flow describes a collection of Fields. It is named after the internal entity type you wish to 4 | * associate it with. For example a Flow with a slug of products will be applied to all Product responses in your store. 5 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/custom-data/flows.html 6 | */ 7 | 8 | import { Identifiable, Resource, ResourcePage, Attributes } from './core'; 9 | 10 | /** 11 | * Core Flow Base Interface 12 | */ 13 | export interface FlowBase { 14 | slug: string 15 | type: string 16 | name: string 17 | description: string 18 | enabled: boolean 19 | } 20 | 21 | export interface Flow extends Identifiable, FlowBase { 22 | links: { 23 | self: string 24 | } 25 | meta: { 26 | timestamps: { 27 | created_at: string 28 | updated_at: string 29 | } 30 | owner?: 'organization' | 'store' 31 | } 32 | } 33 | 34 | export interface FlowFilter { 35 | eq?: { 36 | template?: string 37 | } 38 | } 39 | 40 | /** 41 | * Flow Endpoints 42 | */ 43 | export interface FlowEndpoint { 44 | endpoint: 'flow' 45 | 46 | All(token?: string): Promise> 47 | 48 | AllTemplates(template: string, token?: string): Promise> 49 | 50 | Get(id: string, token?: string): Promise> 51 | 52 | Filter(filter: FlowFilter): FlowEndpoint 53 | 54 | Limit(value: number): FlowEndpoint 55 | 56 | Offset(value: number): FlowEndpoint 57 | 58 | Create(body: FlowBase): Promise> 59 | 60 | Delete(id: string): Promise<{}> 61 | 62 | Update( 63 | id: string, 64 | body: Partial, 65 | token?: string 66 | ): Promise> 67 | 68 | GetEntries(slug: string): Promise 69 | 70 | GetEntry(slug: string, entryId: string): Promise 71 | 72 | GetFields(slug: string): Promise 73 | 74 | DeleteFlow(id: string): Promise<{}> 75 | 76 | CreateEntry( 77 | slug: string, 78 | body: RequestBody 79 | ): Promise 80 | 81 | UpdateEntry( 82 | slug: string, 83 | entryId: string, 84 | body: RequestBody 85 | ): Promise 86 | 87 | DeleteEntry(slug: string, entryId: string): Promise 88 | 89 | CreateEntryRelationship( 90 | flowSlug: string, 91 | entryId: string, 92 | fieldSlug: string, 93 | body?: RequestBody 94 | ): Promise 95 | 96 | UpdateEntryRelationship( 97 | flowSlug: string, 98 | entryId: string, 99 | fieldSlug: string, 100 | body?: RequestBody 101 | ): Promise 102 | 103 | DeleteEntryRelationship( 104 | flowSlug: string, 105 | entryId: string, 106 | fieldSlug: string 107 | ): Promise 108 | 109 | Attributes(token?: string): Promise 110 | 111 | GetFlowTypeAttributes(flowType: string, token?: string): Promise 112 | } 113 | -------------------------------------------------------------------------------- /src/types/hierarchies.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products 3 | * Description: Products are the core resource to any Commerce Cloud project. They can be associated by category, collection, brands, and more. 4 | */ 5 | import { Identifiable, CrudQueryableResource, ResourcePage } from './core' 6 | import { NodesEndpoint, Node } from './nodes' 7 | import { NodeRelationshipsEndpoint } from './node-relationships' 8 | import { Resource } from './core' 9 | import { PcmJobBase } from './pcm-jobs' 10 | 11 | /** 12 | * Core PCM Product Base Interface 13 | * For custom flows, extend this interface 14 | */ 15 | export interface HierarchyBase { 16 | type: 'hierarchy' 17 | attributes: { 18 | name: string 19 | description?: string 20 | slug?: string 21 | created_at?: string 22 | updated_at?: string 23 | published_at?: string 24 | } 25 | meta?: { 26 | owner?: 'organization' | 'store' 27 | } 28 | } 29 | 30 | export interface Hierarchy extends Identifiable, HierarchyBase { 31 | relationships?: { 32 | children?: { 33 | data: { 34 | type: 'node' 35 | id: string 36 | }[] 37 | } 38 | } 39 | } 40 | 41 | export interface DuplicateHierarchyBody { 42 | type: 'hierarchy' 43 | attributes: { 44 | name?: string 45 | description?: string 46 | include_products?: boolean 47 | } 48 | } 49 | 50 | export type DuplicateHierarchyJob = Identifiable & PcmJobBase 51 | 52 | export interface HierarchyFilter { 53 | // TODO 54 | } 55 | 56 | type HierarchySort = // TODO 57 | '' 58 | 59 | type HierarchyInclude = // TODO 60 | '' 61 | 62 | /** 63 | * PCM Product Endpoints 64 | */ 65 | export interface HierarchiesEndpoint 66 | extends CrudQueryableResource< 67 | Hierarchy, 68 | HierarchyBase, 69 | Partial, 70 | HierarchyFilter, 71 | HierarchySort, 72 | HierarchyInclude 73 | > { 74 | endpoint: 'hierarchies' 75 | Nodes: NodesEndpoint 76 | Relationships: NodeRelationshipsEndpoint 77 | Children(id: string, token?: string): Promise> 78 | Duplicate( 79 | hierarchyId: string, 80 | body: DuplicateHierarchyBody, 81 | token?: string 82 | ): Promise> 83 | Limit(value: number): HierarchiesEndpoint 84 | Offset(value: number): HierarchiesEndpoint 85 | } 86 | -------------------------------------------------------------------------------- /src/types/job.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Jobs 3 | * Description:The jobs endpoint provides a programmatic way of running long running background tasks. An example job 4 | * would be exporting all orders from your store. 5 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/jobs/index.html 6 | */ 7 | import { Identifiable, Resource, ResourcePage } from './core' 8 | 9 | /** 10 | * Core Job Base Interface 11 | * For custom flows, extend this interface 12 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/inventory/stock-transactions.html 13 | */ 14 | export interface JobBase { 15 | type: string 16 | job_type: string 17 | link: { 18 | href: string 19 | } 20 | status: 'pending' | 'processing' | 'complete' | 'failed' 21 | } 22 | 23 | export interface Job extends Identifiable, JobBase { 24 | timestamps: { 25 | created_at: string 26 | updated_at: string 27 | } 28 | } 29 | 30 | export interface FileHref { 31 | href: string 32 | } 33 | 34 | export interface createJob { 35 | filter: string 36 | job_type: string 37 | type?: string 38 | } 39 | 40 | /** 41 | * Job Endpoints 42 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/catalog/inventory/stock-transactions.html 43 | */ 44 | export interface JobEndpoint { 45 | endpoint: 'job' 46 | 47 | /** 48 | * Title: Create 49 | * Description: Currently, you can invoke the jobs service to export orders 50 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/jobs/get-a-job.html 51 | * @param body 52 | * @constructor 53 | */ 54 | Create(body: createJob): Promise> 55 | 56 | /** 57 | * Title: Get All 58 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/jobs/get-all-jobs.html 59 | */ 60 | All(): Promise> 61 | 62 | /** 63 | * Title: Get 64 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/advanced/jobs/get-a-job.html 65 | */ 66 | Get(id: string): Promise> 67 | 68 | GetFile(id: string): Promise 69 | } 70 | -------------------------------------------------------------------------------- /src/types/locales.ts: -------------------------------------------------------------------------------- 1 | export type Locales = 2 | | 'ab' 3 | | 'af' 4 | | 'sq' 5 | | 'hy' 6 | | 'av' 7 | | 'ae' 8 | | 'ay' 9 | | 'az' 10 | | 'eu' 11 | | 'be' 12 | | 'bs' 13 | | 'bg' 14 | | 'ca' 15 | | 'co' 16 | | 'cs' 17 | | 'da' 18 | | 'nl' 19 | | 'en' 20 | | 'et' 21 | | 'fj' 22 | | 'fi' 23 | | 'fr' 24 | | 'de' 25 | | 'gd' 26 | | 'ga' 27 | | 'el' 28 | | 'ht' 29 | | 'hr' 30 | | 'hu' 31 | | 'is' 32 | | 'it' 33 | | 'lv' 34 | | 'lt' 35 | | 'lb' 36 | | 'no' 37 | | 'fa' 38 | | 'pl' 39 | | 'pt' 40 | | 'ro' 41 | | 'ru' 42 | | 'sk' 43 | | 'sl' 44 | | 'sm' 45 | | 'es' 46 | | 'sc' 47 | | 'sr' 48 | | 'sv' 49 | | 'uk' 50 | | 'cy' 51 | -------------------------------------------------------------------------------- /src/types/merchant-realm-mappings.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Merchant Realm Mappings 3 | */ 4 | import { Resource } from './core' 5 | 6 | export interface MerchantRealmMappings { 7 | type: 'merchant-realm-mappings' 8 | id: string 9 | realm_id: string 10 | store_id: string 11 | prefix: string 12 | } 13 | 14 | /** 15 | * Merchant Realm Mappings Endpoints 16 | */ 17 | export interface MerchantRealmMappingsEndpoint { 18 | endpoint: 'settings' 19 | 20 | /** 21 | * Get Merchant Realm Mappings 22 | */ 23 | All(token?: string): Promise> 24 | 25 | /** 26 | * Update Merchant Realm Mappings 27 | */ 28 | Update( 29 | id: string, 30 | body: Partial, 31 | token?: string 32 | ): Promise> 33 | 34 | /** 35 | * Get Merchant Realm Mappings by id 36 | */ 37 | Get(id: string): Promise> 38 | } 39 | -------------------------------------------------------------------------------- /src/types/metrics.d.ts: -------------------------------------------------------------------------------- 1 | import { ResourcePage } from './core' 2 | 3 | export interface MetricsBase { 4 | value: number 5 | time: string 6 | } 7 | 8 | export interface MetricsQuery { 9 | currency?: string 10 | from: string 11 | to: string 12 | interval: string 13 | } 14 | 15 | export interface MetricsEndpoint { 16 | TotalOrders(query: MetricsQuery): Promise> 17 | 18 | TotalValue(query: MetricsQuery): Promise> 19 | } 20 | -------------------------------------------------------------------------------- /src/types/node-relationships.d.ts: -------------------------------------------------------------------------------- 1 | import { ResourcePage, Resource, Identifiable } from './core' 2 | import { PcmProduct } from './pcm' 3 | 4 | export interface NodeRelationshipBase { 5 | type: 'product' 6 | id: string 7 | } 8 | 9 | export interface NodeRelationship extends NodeRelationshipBase { 10 | relationships: {} 11 | } 12 | 13 | export interface NodeRelationshipParent { 14 | type: 'node' 15 | id: string 16 | } 17 | 18 | export interface CreateChildrenSortOrderBody extends Identifiable { 19 | type: 'node' 20 | meta: { 21 | sort_order: number 22 | } 23 | } 24 | 25 | export interface NodeProduct extends PcmProduct { 26 | attributes: PcmProduct['attributes'] & { 27 | curated_product?: boolean 28 | } 29 | } 30 | 31 | export interface NodeRelationshipsEndpoint { 32 | endpoint: 'relationships/products' 33 | 34 | Create(options: { 35 | hierarchyId: string 36 | nodeId: string 37 | body: NodeRelationshipBase[] 38 | token?: string 39 | }): Promise> 40 | 41 | Update(options: { 42 | hierarchyId: string 43 | nodeId: string 44 | body: NodeRelationshipBase[] 45 | token?: string 46 | }): Promise> 47 | 48 | Delete(options: { 49 | hierarchyId: string 50 | nodeId: string 51 | body: NodeRelationshipBase[] 52 | token?: string 53 | }): Promise<{}> 54 | 55 | Products(options: { 56 | hierarchyId: string 57 | nodeId: string 58 | token?: string 59 | }): Promise> 60 | 61 | ChangeParent(options: { 62 | hierarchyId: string 63 | nodeId: string 64 | body: NodeRelationshipParent 65 | token?: string 66 | }): Promise 67 | 68 | DeleteParent(options: { 69 | hierarchyId: string 70 | nodeId: string 71 | token?: string 72 | }): Promise 73 | 74 | CreateChildrenSortOrder(options: { 75 | hierarchyId: string 76 | nodeId: string 77 | body: CreateChildrenSortOrderBody[] 78 | token?: string 79 | }): Promise 80 | 81 | Limit(value: number): NodeRelationshipsEndpoint 82 | 83 | Offset(value: number): NodeRelationshipsEndpoint 84 | } 85 | -------------------------------------------------------------------------------- /src/types/nodes.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products 3 | * Description: Products are the core resource to any Commerce Cloud project. They can be associated by category, collection, brands, and more. 4 | */ 5 | 6 | import { Identifiable, Resource, ResourceList, ResourcePage } from './core' 7 | import { Locales } from './locales' 8 | 9 | /** 10 | * Core PCM Product Base Interface 11 | * For custom flows, extend this interface 12 | */ 13 | export interface NodeBase { 14 | type: 'node' 15 | attributes: { 16 | name: string 17 | description?: string 18 | slug?: string 19 | curated_products?: string[] 20 | locales?: { [key in Locales]?: { name?: string; description?: string } } 21 | } 22 | relationships?: { 23 | parent: { 24 | data: { 25 | type: string 26 | id: string 27 | } 28 | } 29 | }, 30 | meta?: { 31 | sort_order: number 32 | } 33 | } 34 | 35 | export interface Node extends Identifiable, NodeBase { 36 | relationships: { 37 | children: { 38 | data: [] 39 | links: { 40 | related: string 41 | } 42 | } 43 | products: { 44 | data: { 45 | type: 'product' 46 | id: string 47 | }[] 48 | } 49 | parent: { 50 | data: { 51 | type: string 52 | id: string 53 | } 54 | } 55 | } 56 | } 57 | 58 | export type UpdateNodeBody = Omit & 59 | Identifiable & { 60 | attributes: Partial 61 | } 62 | 63 | export interface NodeFilter { 64 | // TODO 65 | } 66 | 67 | type NodeSort = // TODO 68 | '' 69 | 70 | type NodeInclude = // TODO 71 | '' 72 | 73 | /** 74 | * PCM Product Endpoints 75 | */ 76 | export interface NodesEndpoint { 77 | endpoint: 'nodes' 78 | 79 | Get(options: { 80 | hierarchyId: string 81 | nodeId: string 82 | token?: string 83 | }): Promise> 84 | 85 | // TODO: API - currently not working! (can get from hierarchy relationships) 86 | All(options: { 87 | hierarchyId: string 88 | token?: string 89 | }): Promise> 90 | 91 | Create(options: { 92 | hierarchyId: string 93 | body: NodeBase 94 | token?: string 95 | }): Promise> 96 | 97 | Update(options: { 98 | hierarchyId: string 99 | nodeId: string 100 | body: UpdateNodeBody 101 | token?: string 102 | }): Promise> 103 | 104 | Delete(options: { 105 | hierarchyId: string 106 | nodeId: string 107 | token?: string 108 | }): Promise<{}> 109 | 110 | GetNodeChildren(options: { 111 | hierarchyId: string 112 | nodeId: string 113 | token?: string 114 | }): Promise> 115 | 116 | Limit(value: number): NodesEndpoint 117 | 118 | Offset(value: number): NodesEndpoint 119 | } 120 | -------------------------------------------------------------------------------- /src/types/one-time-password-token-request.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * One Time Password Token Request 3 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-password-profiles/index.html 4 | */ 5 | 6 | /** 7 | * The One Time Password Token Request object 8 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-password-profiles/index.html#The-User-Authentication-Password-Profile-Object 9 | */ 10 | 11 | export interface OneTimePasswordTokenRequestBody { 12 | type: string 13 | username: string 14 | purpose : string 15 | } 16 | 17 | export interface OneTimePasswordTokenRequestEndpoint { 18 | /** 19 | * Create a Onetime Password Token Request 20 | * DOCS: https://documentation.elasticpath.com/commerce-cloud/docs/api/single-sign-on/user-authentication-password-profiles/create-a-user-authentication-password-profile.html 21 | * @param realmId - The ID for the authentication-realm. 22 | * @param passwordProfileId - The ID for the password profile. 23 | * @param body - The Onetime Password Token Request object 24 | */ 25 | Create(realmId: string, passwordProfileId: string, body: OneTimePasswordTokenRequestBody, token?: string) 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/types/pcm-file-relationship.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products file relationship 3 | */ 4 | import { Identifiable, ResourceList } from './core' 5 | 6 | export interface PcmFileRelationship extends Identifiable { 7 | meta?: { 8 | created_at: string 9 | tags?: string[] 10 | } 11 | type: string 12 | } 13 | 14 | export type ProductFileRelationshipResource = string | { id: string; meta?: { tags: string[] } } 15 | 16 | export interface PcmFileRelationshipEndpoint { 17 | endpoint: 'relationships/files' 18 | 19 | /** 20 | * Get all product file relationships 21 | * Description: 22 | * @param productId 23 | * @constructor 24 | */ 25 | All(productId: string): Promise> 26 | 27 | /** 28 | * Create a product file relationship 29 | * Description: 30 | * @param productId 31 | * @param resources 32 | * @constructor 33 | */ 34 | Create( 35 | productId: string, 36 | resources?: string | ProductFileRelationshipResource[] 37 | ): Promise 38 | 39 | /** 40 | * Delete a product file relationship 41 | * Description: 42 | * @param productId 43 | * @param resources 44 | * @constructor 45 | */ 46 | Delete( 47 | productId: string, 48 | resources?: string | string[] 49 | ): Promise 50 | /** 51 | * Update a product file relationship 52 | * Description: 53 | * @param productId 54 | * @param resources 55 | * @constructor 56 | */ 57 | 58 | Update( 59 | productId: string, 60 | resources?: string | ProductFileRelationshipResource[] 61 | ): Promise 62 | } 63 | -------------------------------------------------------------------------------- /src/types/pcm-jobs.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * PCM Jobs 3 | */ 4 | import { Identifiable, CrudQueryableResource } from './core' 5 | import { PcmJob } from './pcm'; 6 | import { ResourcePage } from './core' 7 | 8 | /** 9 | * PCM Job Base Interface 10 | */ 11 | export interface PcmJobBase { 12 | type: 'pim-job', 13 | attributes: { 14 | completed_at: string 15 | created_at: string 16 | started_at: string 17 | status: string 18 | type: string 19 | updated_at: string 20 | } 21 | } 22 | 23 | export interface PcmJobError extends Identifiable { 24 | type: 'pim-job-error' 25 | attributes: { 26 | message: string 27 | } 28 | } 29 | 30 | export interface PcmJobsEndpoint 31 | extends CrudQueryableResource< 32 | PcmJob, 33 | PcmJobBase, 34 | Partial, 35 | undefined, 36 | undefined, 37 | undefined 38 | > { 39 | endpoint: 'jobs' 40 | 41 | /** 42 | * Gets all job errors for a PCM Job 43 | */ 44 | GetJobErrors(jobId: string): Promise> 45 | } 46 | -------------------------------------------------------------------------------- /src/types/pcm-main-image-relationship.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products main image relationship 3 | */ 4 | import { Identifiable, Resource } from './core' 5 | 6 | export interface PcmMainImageRelationship extends Identifiable { 7 | type: string 8 | } 9 | 10 | export interface PcmMainImageRelationshipEndpoint { 11 | endpoint: 'relationships/main_image' 12 | 13 | /** 14 | * Get product main image relationships 15 | * Description: 16 | * @param productId 17 | * @constructor 18 | */ 19 | Get(productId: string): Promise> 20 | 21 | /** 22 | * Create a product main image relationship 23 | * Description: 24 | * @param productId 25 | * @param fileId 26 | * @constructor 27 | */ 28 | Create( 29 | productId: string, 30 | fileId: string 31 | ): Promise 32 | 33 | /** 34 | * Delete a product main image relationship 35 | * Description: 36 | * @param productId 37 | * @param fileId 38 | * @constructor 39 | */ 40 | Delete( 41 | productId: string, 42 | fileId: string 43 | ): Promise 44 | 45 | /** 46 | * Update a product main image relationship 47 | * Description: 48 | * @param productId 49 | * @param fileId 50 | * @constructor 51 | */ 52 | Update( 53 | productId: string, 54 | fileId: string 55 | ): Promise 56 | } 57 | -------------------------------------------------------------------------------- /src/types/pcm-template-relationship.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products templates relationship 3 | */ 4 | import { Identifiable, ResourceList } from './core' 5 | 6 | export interface PcmTemplateRelationship extends Identifiable { 7 | meta: { 8 | created_at: string 9 | tags?: string[] 10 | } 11 | type: string 12 | } 13 | 14 | export type ProductTemplateRelationshipResource = string | { id: string; meta: { tags: string[] } } 15 | 16 | export interface PcmTemplateRelationshipEndpoint { 17 | endpoint: 'relationships/templates' 18 | 19 | /** 20 | * Get all product template relationships 21 | * Description: 22 | * @param productId 23 | * @constructor 24 | */ 25 | All(productId: string): Promise> 26 | 27 | /** 28 | * Create a product template relationship 29 | * Description: 30 | * @param productId 31 | * @param resources 32 | * @constructor 33 | */ 34 | Create( 35 | productId: string, 36 | resources?: string | ProductTemplateRelationshipResource[] 37 | ): Promise 38 | 39 | /** 40 | * Delete a product template relationship 41 | * Description: 42 | * @param productId 43 | * @param resources 44 | * @constructor 45 | */ 46 | Delete( 47 | productId: string, 48 | resources?: string | string[] 49 | ): Promise 50 | } 51 | -------------------------------------------------------------------------------- /src/types/pcm-variations-relationships.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products variation relationship 3 | */ 4 | import { Identifiable, ResourceList } from './core' 5 | 6 | export interface PcmVariationsRelationships extends Identifiable { 7 | meta: { 8 | created_at: string 9 | tags?: string[] 10 | } 11 | type: string 12 | } 13 | 14 | export type PcmVariationsRelationshipResource = string | { id: string; meta: { tags: string[] } } 15 | 16 | export interface PcmVariationsRelationshipsEndpoint { 17 | endpoint: 'relationships/variations' 18 | 19 | /** 20 | * Get all product variation relationships 21 | * Description: 22 | * @param productId 23 | * @constructor 24 | */ 25 | All(productId: string): Promise> 26 | 27 | /** 28 | * Create a product variation relationship 29 | * Description: 30 | * @param productId 31 | * @param resources 32 | * @constructor 33 | */ 34 | Create( 35 | productId: string, 36 | resources?: string | PcmVariationsRelationshipResource[] 37 | ): Promise 38 | 39 | /** 40 | * Delete a product variation relationship 41 | * Description: 42 | * @param productId 43 | * @param resources 44 | * @constructor 45 | */ 46 | Delete( 47 | productId: string, 48 | resources?: string | string[] 49 | ): Promise 50 | /** 51 | * Update a product variation relationship 52 | * Description: 53 | * @param productId 54 | * @param resources 55 | * @constructor 56 | */ 57 | 58 | Update( 59 | productId: string, 60 | resources?: string | PcmVariationsRelationshipResource[] 61 | ): Promise 62 | } 63 | -------------------------------------------------------------------------------- /src/types/personal-data.d.ts: -------------------------------------------------------------------------------- 1 | 2 | import { Identifiable, ResourcePage } from './core' 3 | 4 | export interface PersonalDataRecord extends Identifiable { 5 | store_id: string; 6 | type: string; 7 | initiator: { 8 | "access-token-email": string; 9 | "access-token-id": string; 10 | "access-token-name": string; 11 | "access-token-store-id": string; 12 | "access-token-type": string; 13 | } 14 | time: string; 15 | event_type: string; 16 | delta: Record; 17 | resource_type: string; 18 | relationships: Record; 19 | links: Record; 20 | } 21 | 22 | export interface PersonalDataEndpoint { 23 | All(): Promise> 24 | 25 | Filter(resourceType: string, resourceId: string): PersonalDataEndpoint 26 | 27 | Limit(value: number): PersonalDataEndpoint 28 | 29 | Offset(value: number): PersonalDataEndpoint 30 | } 31 | -------------------------------------------------------------------------------- /src/types/price-book-price-modifiers.d.ts: -------------------------------------------------------------------------------- 1 | import {Identifiable, Resource, ResourceList, ResourcePage} from './core' 2 | 3 | export interface PriceBookPriceModifierBase { 4 | type: 'product-price' 5 | attributes: { 6 | modifier_type: string 7 | name: string 8 | external_ref?: string | null 9 | currencies: { 10 | [key: string]: { 11 | includes_tax: boolean 12 | amount: number 13 | } 14 | } 15 | } 16 | } 17 | 18 | export interface PriceBookPriceModifier 19 | extends Identifiable, 20 | PriceBookPriceModifierBase { 21 | relationships: {} 22 | } 23 | 24 | export interface PriceBookPriceModifierEndpoint { 25 | endpoint: 'prices' 26 | 27 | All(options: { 28 | pricebookId: string 29 | token?: string 30 | }): Promise> 31 | 32 | Get(options: { 33 | pricebookId: string 34 | priceModifierId: string 35 | token?: string 36 | }): Promise> 37 | 38 | Create(options: { 39 | pricebookId: string 40 | body: PriceBookPriceModifier 41 | token?: string 42 | }): Promise> 43 | 44 | Update(options: { 45 | pricebookId: string 46 | priceModifierId: string 47 | body: PriceBookPriceModifier 48 | token?: string 49 | }): Promise> 50 | 51 | Delete(options: { 52 | pricebookId: string 53 | priceModifierId: string 54 | token?: string 55 | }): Promise<{}> 56 | 57 | Limit(value: number): PriceBookPriceModifierEndpoint 58 | 59 | Offset(value: number): PriceBookPriceModifierEndpoint 60 | } 61 | -------------------------------------------------------------------------------- /src/types/price-book-prices.d.ts: -------------------------------------------------------------------------------- 1 | import { 2 | CrudQueryableResource, 3 | Identifiable, 4 | Resource, ResourcePage 5 | } from './core' 6 | 7 | export interface PriceBookPriceBase { 8 | type: 'product-price' 9 | attributes: { 10 | currencies: { 11 | [key: string]: { 12 | includes_tax: boolean 13 | amount: number 14 | tiers?: { 15 | [key: string]: { 16 | minimum_quantity: number 17 | amount: number 18 | } 19 | } 20 | } 21 | } 22 | sales?: { 23 | [key: string]: { 24 | bundle_ids?: string[] 25 | schedule?: { 26 | valid_from: string 27 | valid_to: string 28 | } 29 | currencies: { 30 | [key: string]: { 31 | includes_tax: boolean 32 | amount: number 33 | tiers?: { 34 | [key: string]: { 35 | minimum_quantity: number 36 | amount: number 37 | } 38 | } 39 | } 40 | } 41 | } 42 | } 43 | external_ref?: string | null 44 | sku: string 45 | } 46 | } 47 | 48 | export interface PriceBookPricesCreateBody { 49 | options: { 50 | pricebookId: string 51 | body: PriceBookPriceBase 52 | token?: string 53 | } 54 | } 55 | 56 | export interface PriceBookPricesUpdateBody { 57 | options: { 58 | pricebookId: string 59 | priceId: string 60 | body: Identifiable & PriceBookPrice 61 | token?: string 62 | } 63 | } 64 | 65 | export interface PriceBookPrice extends Identifiable, PriceBookPriceBase { 66 | relationships: {} 67 | } 68 | 69 | export interface PricesFilter {} 70 | 71 | export interface PriceBookPricesEndpoint 72 | extends Omit, 'Get' | 'All' | 'Filter' | 'Create' | 'Update' | 'Delete'> { 80 | endpoint: 'prices' 81 | 82 | Get(options: { 83 | pricebookId: string 84 | priceId: string 85 | token?: string 86 | }): Promise> 87 | 88 | // TODO: API - currently not working! (can get from pricebook relationships) 89 | All(options: { 90 | pricebookId: string 91 | token?: string 92 | }): Promise> 93 | 94 | Filter(filter: PricesFilter): PriceBookPricesEndpoint 95 | 96 | Create(PriceBookPricesCreateBody): Promise> 97 | 98 | Update(PriceBookPricesUpdateBody): Promise> 99 | 100 | Delete(options: { 101 | pricebookId: string 102 | priceId: string 103 | token?: string 104 | }): Promise<{}> 105 | } 106 | -------------------------------------------------------------------------------- /src/types/price-books.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Products 3 | * Description: Products are the core resource to any Commerce Cloud project. They can be associated by category, collection, brands, and more. 4 | */ 5 | import { Identifiable, CrudQueryableResource, Resource } from './core' 6 | import { PriceBookPricesEndpoint } from './price-book-prices' 7 | import { PriceBookPriceModifierEndpoint } from './price-book-price-modifiers' 8 | import { PcmJob } from "./pcm"; 9 | 10 | /** 11 | * Core PCM Product Base Interface 12 | * For custom flows, extend this interface 13 | */ 14 | export interface PriceBookBase { 15 | type: string 16 | attributes: { 17 | name: string 18 | description?: string 19 | created_at?: string 20 | updated_at?: string 21 | external_ref?: string | null 22 | meta?: { 23 | // TODO 24 | } 25 | } 26 | } 27 | 28 | export interface PriceBook extends Identifiable, PriceBookBase { 29 | meta?: { 30 | owner?: 'organization' | 'store' 31 | // TODO 32 | } 33 | } 34 | 35 | export interface PriceBookFilter { 36 | // TODO 37 | } 38 | 39 | type PriceBookSort = 'name' | '-name' // TODO 40 | 41 | type PriceBookInclude = 'price' // TODO 42 | 43 | export type PriceBooksUpdateBody = PriceBookBase & Identifiable 44 | 45 | /** 46 | * PCM Product Endpoints 47 | */ 48 | export interface PriceBooksEndpoint 49 | extends CrudQueryableResource< 50 | PriceBook, 51 | PriceBookBase, 52 | PriceBooksUpdateBody, 53 | PriceBookFilter, 54 | PriceBookSort, 55 | PriceBookInclude 56 | > { 57 | endpoint: 'pricebooks' 58 | Prices: PriceBookPricesEndpoint 59 | PriceModifiers: PriceBookPriceModifierEndpoint 60 | 61 | /** 62 | * Import price books 63 | * @param file - The file you want to upload. The file type is `.jsonl`. 64 | * @constructor 65 | */ 66 | ImportProductPrices(file: FormData): Promise> 67 | } 68 | -------------------------------------------------------------------------------- /src/types/price.d.ts: -------------------------------------------------------------------------------- 1 | export interface Price { 2 | amount: number 3 | currency: string 4 | includes_tax: boolean 5 | } 6 | 7 | export interface FormattedPrice { 8 | amount: number 9 | currency: string 10 | formatted: string 11 | } 12 | -------------------------------------------------------------------------------- /src/types/rule-promotions.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Promotions Builder 3 | * Description:Promotions allow you to provide discounts to customers. 4 | * A Promotion can be automatic which is applied provided any criteria are satisfied, 5 | * or require codes, which are then used by the end user to get a discount. 6 | */ 7 | import { 8 | CrudQueryableResource, 9 | Identifiable, 10 | ResourceList, 11 | ResourcePage, 12 | Resource 13 | } from './core' 14 | 15 | export interface ActionLimitation { 16 | max_discount?: number 17 | max_quantity?: number 18 | items?: { 19 | max_items?: number 20 | price_strategy?: string 21 | } 22 | } 23 | 24 | export interface ActionCondition { 25 | strategy: string 26 | operator?: string 27 | args?: any[] 28 | children?: { 29 | strategy?: string 30 | operator?: string 31 | args?: any[] 32 | }[] 33 | } 34 | 35 | export interface Action { 36 | strategy: string 37 | args: any[] 38 | limitations?: ActionLimitation 39 | condition?: ActionCondition 40 | } 41 | 42 | export interface Condition { 43 | strategy: string 44 | operator?: string 45 | args?: any[] 46 | children?: Condition[] 47 | } 48 | 49 | /** 50 | * Promotions Builder 51 | * Description:Base Promotion Type 52 | */ 53 | export interface RulePromotionBase { 54 | type: 'rule_promotion' 55 | name: string 56 | description: string 57 | enabled: boolean 58 | automatic?: boolean 59 | start: string 60 | end: string 61 | rule_set: { 62 | currencies: string[] 63 | catalog_ids: string[] 64 | rules: Condition 65 | actions: Action[] 66 | } 67 | } 68 | 69 | export interface RulePromotionMeta { 70 | timestamps: { 71 | created_at: string 72 | updated_at: string 73 | } 74 | } 75 | 76 | export interface RulePromotion extends Identifiable, RulePromotionBase { 77 | meta: RulePromotionMeta 78 | } 79 | 80 | export interface RulePromotionCode { 81 | code: string 82 | uses?: number 83 | user?: string 84 | created_by?: string 85 | max_uses?: number 86 | meta?: RulePromotionMeta 87 | consume_unit?: 'per_application' | 'per_checkout' 88 | } 89 | 90 | export interface DeleteRulePromotionCodes extends ResourceList { 91 | code: string 92 | } 93 | 94 | export interface RulePromotionsEndpoint 95 | extends CrudQueryableResource< 96 | RulePromotion, 97 | RulePromotionBase, 98 | Partial, 99 | never, 100 | never, 101 | never 102 | > { 103 | endpoint: 'rule-promotions' 104 | 105 | Codes(promotionId: string): Promise> 106 | 107 | AddCodes( 108 | promotionId: string, 109 | codes: RulePromotionCode[] 110 | ): Promise> 111 | 112 | DeleteCode(promotionId: string, codeId: string): Promise<{}> 113 | 114 | DeleteCodes( 115 | promotionId: string, 116 | codes: DeleteRulePromotionCodes[] 117 | ): Promise<{}> 118 | } 119 | -------------------------------------------------------------------------------- /src/types/storage.d.ts: -------------------------------------------------------------------------------- 1 | export interface StorageFactory { 2 | set(key: string, value: any): void 3 | get(key: string): any 4 | delete(key: string): void 5 | } 6 | 7 | export class MemoryStorageFactory implements StorageFactory { 8 | set(key: string, value: any): void 9 | get(key: string): any 10 | delete(key: string): void 11 | } 12 | 13 | export class LocalStorageFactory implements StorageFactory { 14 | set(key: string, value: any): void 15 | get(key: string): any 16 | delete(key: string): void 17 | } 18 | -------------------------------------------------------------------------------- /src/types/subscription-dunning-rules.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Subscription Dunning Rules 3 | * Description: Subscription Dunning Rules. 4 | * DOCS: TODO: add docs when ready 5 | */ 6 | import { 7 | Identifiable, 8 | CrudQueryableResource 9 | } from './core' 10 | 11 | /** 12 | * Core Subscription Dunning Rules Base Interface 13 | * For custom flows, extend this interface 14 | * DOCS: TODO: add docs when ready 15 | */ 16 | export interface SubscriptionDunningRulesBase { 17 | type: 'subscription_dunning_rule' 18 | attributes: { 19 | payment_retry_type: 'fixed' | 'backoff' | 'tiered' 20 | payment_retry_interval?: number 21 | payment_retry_unit?: 'day' | 'week' 22 | payment_retry_multiplier?: number 23 | payment_retries_limit: number 24 | action: 'none' | 'pause' | 'close' 25 | default?: boolean 26 | } 27 | } 28 | 29 | export interface SubscriptionDunningRules extends Identifiable, SubscriptionDunningRulesBase { 30 | meta: { 31 | owner: 'store' | 'organization' 32 | timestamps: { 33 | updated_at: string 34 | created_at: string 35 | } 36 | } 37 | } 38 | 39 | export type SubscriptionDunningRulesCreate = SubscriptionDunningRulesBase 40 | export type SubscriptionDunningRulesUpdate = Identifiable & Omit & {attributes: Partial} 41 | 42 | /** 43 | * Subscription Dunning Rules Endpoints 44 | * DOCS: TODO: add docs when ready 45 | */ 46 | export interface SubscriptionDunningRulesEndpoint 47 | extends CrudQueryableResource< 48 | SubscriptionDunningRules, 49 | SubscriptionDunningRulesCreate, 50 | SubscriptionDunningRulesUpdate, 51 | never, 52 | never, 53 | never 54 | > { 55 | endpoint: 'dunning-rules' 56 | } 57 | -------------------------------------------------------------------------------- /src/types/subscription-jobs.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Subscription Jobs 3 | * Description: Subscription Jobs. 4 | * DOCS: TODO: add docs when ready 5 | */ 6 | import { 7 | Identifiable, 8 | CrudQueryableResource 9 | } from './core' 10 | 11 | /** 12 | * Core Subscription Job Base Interface 13 | * For custom flows, extend this interface 14 | * DOCS: TODO: add docs when ready 15 | */ 16 | export interface SubscriptionJobBase { 17 | type: "subscription_job", 18 | attributes: { 19 | external_ref: string, 20 | job_type: "billing-run" | "payment-run" | "tax-run" 21 | taxes?: { 22 | invoice_id: string, 23 | tax_items: [ 24 | { 25 | type: "tax_item", 26 | name?: string, 27 | code?: string, 28 | rate: number, 29 | jurisdiction?: string 30 | } 31 | ] 32 | }[] 33 | } 34 | } 35 | 36 | export interface SubscriptionJob extends Identifiable, SubscriptionJobBase { 37 | attributes: SubscriptionJobBase['attributes'] & { 38 | status: 'pending' | 'started' | 'success' | 'failed' 39 | updated_at: string 40 | created_at: string 41 | } 42 | relationships: { 43 | [key: string]: { 44 | links: { 45 | related: string, 46 | self: string 47 | }, 48 | data: { 49 | type: string, 50 | id: string 51 | } 52 | } 53 | }, 54 | meta: { 55 | owner: 'store' | 'organization', 56 | timestamps: { 57 | updated_at: string, 58 | created_at: string, 59 | started_at?: string, 60 | finished_at?: string 61 | } 62 | } 63 | } 64 | 65 | export type SubscriptionJobCreate = SubscriptionJobBase 66 | 67 | /** 68 | * Subscription Job Endpoints 69 | * DOCS: TODO: add docs when ready 70 | */ 71 | export interface SubscriptionJobsEndpoint 72 | extends CrudQueryableResource< 73 | SubscriptionJob, 74 | SubscriptionJobCreate, 75 | never, 76 | never, 77 | never, 78 | never 79 | > { 80 | endpoint: 'jobs' 81 | } 82 | -------------------------------------------------------------------------------- /src/types/subscription-plans.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Subscription Plans 3 | * Description: Subscription Plans. 4 | * DOCS: TODO: add docs when ready 5 | */ 6 | import { 7 | Identifiable, 8 | CrudQueryableResource 9 | } from './core' 10 | 11 | /** 12 | * Core Subscription Plan Base Interface 13 | * For custom flows, extend this interface 14 | * DOCS: TODO: add docs when ready 15 | */ 16 | export interface SubscriptionPlanBase { 17 | type: string 18 | attributes: { 19 | name: string 20 | description?: string 21 | billing_interval_type: string 22 | billing_frequency: number 23 | trial_period?: number 24 | plan_length: number 25 | end_behavior: string 26 | can_pause: boolean 27 | can_resume: boolean 28 | can_cancel: boolean 29 | base_price_percentage: number | null | undefined 30 | fixed_price: { 31 | [key: string]: { 32 | amount: number 33 | includes_tax?: boolean 34 | } 35 | } | null | undefined 36 | }, 37 | } 38 | 39 | export interface SubscriptionPlan extends Identifiable, SubscriptionPlanBase { 40 | meta: { 41 | owner: string 42 | timestamps: { 43 | created_at: string 44 | updated_at: string 45 | } 46 | } 47 | } 48 | export type SubscriptionPlanCreate = Omit & {attributes: Partial} 49 | export type SubscriptionPlanUpdate = Identifiable & Omit & {attributes: Partial} 50 | 51 | /** 52 | * Subscription Plan Endpoints 53 | * DOCS: TODO: add docs when ready 54 | */ 55 | export interface SubscriptionPlansEndpoint 56 | extends CrudQueryableResource< 57 | SubscriptionPlan, 58 | SubscriptionPlanCreate, 59 | SubscriptionPlanUpdate, 60 | never, 61 | never, 62 | never 63 | > { 64 | endpoint: 'plans' 65 | } 66 | -------------------------------------------------------------------------------- /src/types/subscription-products.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Subscription Products 3 | * Description: Subscription Products. 4 | * DOCS: TODO: add docs when ready 5 | */ 6 | import { 7 | Identifiable, 8 | CrudQueryableResource 9 | } from './core' 10 | 11 | /** 12 | * Core Subscription Product Base Interface 13 | * For custom flows, extend this interface 14 | * DOCS: TODO: add docs when ready 15 | */ 16 | export interface SubscriptionProductBase { 17 | type: string 18 | attributes: { 19 | description: string 20 | main_image?: string | null 21 | name: string 22 | sku: string 23 | price: { 24 | [key: string]: { 25 | amount: number 26 | includes_tax?: boolean 27 | } 28 | } 29 | price_units?: { 30 | unit: 'day' | 'month' 31 | amount: number 32 | } | null 33 | }, 34 | } 35 | 36 | export interface SubscriptionProduct extends Identifiable, SubscriptionProductBase { 37 | meta: { 38 | display_price: { 39 | without_tax: { 40 | amount: number 41 | currency: string 42 | formatted: string 43 | } 44 | }, 45 | owner: string 46 | timestamps: { 47 | created_at: string 48 | updated_at: string 49 | } 50 | } 51 | } 52 | export type SubscriptionProductCreate = Omit & {attributes: Partial} 53 | export type SubscriptionProductUpdate = Identifiable & Omit & {attributes: Partial} 54 | 55 | /** 56 | * Subscription Product Endpoints 57 | * DOCS: TODO: add docs when ready 58 | */ 59 | export interface SubscriptionProductsEndpoint 60 | extends CrudQueryableResource< 61 | SubscriptionProduct, 62 | SubscriptionProductCreate, 63 | SubscriptionProductUpdate, 64 | never, 65 | never, 66 | never 67 | > { 68 | endpoint: 'products' 69 | } 70 | -------------------------------------------------------------------------------- /src/types/subscription-proration-policies.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Subscription Proration Policies 3 | * Description: Subscription Proration Policies. 4 | * DOCS: TODO: add docs when ready 5 | */ 6 | import { 7 | Identifiable, 8 | CrudQueryableResource 9 | } from './core' 10 | 11 | /** 12 | * Core Subscription Proration Policies Base Interface 13 | * For custom flows, extend this interface 14 | * DOCS: TODO: add docs when ready 15 | */ 16 | export interface SubscriptionProrationPolicyBase { 17 | type: 'subscription_proration_policy' 18 | attributes: { 19 | name: string 20 | rounding: 'up' | 'down' | 'nearest' 21 | external_ref?: string 22 | } 23 | } 24 | 25 | export interface SubscriptionProrationPolicy extends Identifiable, SubscriptionProrationPolicyBase { 26 | meta: { 27 | owner: 'store' | 'organization' 28 | timestamps: { 29 | updated_at: string 30 | created_at: string 31 | } 32 | } 33 | } 34 | 35 | export type SubscriptionProrationPolicyCreate = SubscriptionProrationPolicyBase 36 | export type SubscriptionProrationPolicyUpdate = Identifiable & Omit & {attributes: Partial} 37 | 38 | /** 39 | * Subscription Proration Policies Endpoints 40 | * DOCS: TODO: add docs when ready 41 | */ 42 | export interface SubscriptionProrationPoliciesEndpoint 43 | extends CrudQueryableResource< 44 | SubscriptionProrationPolicy, 45 | SubscriptionProrationPolicyCreate, 46 | SubscriptionProrationPolicyUpdate, 47 | never, 48 | never, 49 | never 50 | > { 51 | endpoint: 'proration-policies' 52 | } 53 | -------------------------------------------------------------------------------- /src/types/subscription-schedules.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Subscription Schedules 3 | * Description: Subscription Schedules. 4 | * DOCS: TODO: add docs when ready 5 | */ 6 | import { 7 | Identifiable, 8 | CrudQueryableResource 9 | } from './core' 10 | import { SubscriptionJob } from './subscription-jobs' 11 | 12 | /** 13 | * Core Subscription Schedule Base Interface 14 | * For custom flows, extend this interface 15 | * DOCS: TODO: add docs when ready 16 | */ 17 | export interface SubscriptionScheduleBase { 18 | type: 'subscription_schedule' 19 | attributes: { 20 | external_ref?: string | null 21 | name?: string 22 | specification: string 23 | location: string 24 | job: { 25 | job_type: SubscriptionJob['attributes']['job_type'] 26 | } 27 | } 28 | } 29 | 30 | export interface SubscriptionSchedule extends Identifiable, SubscriptionScheduleBase { 31 | meta: { 32 | scheduled_for: string 33 | owner: 'store' | 'organization' 34 | timestamps: { 35 | updated_at: string 36 | created_at: string 37 | } 38 | } 39 | } 40 | 41 | export type SubscriptionScheduleCreate = SubscriptionScheduleBase 42 | export type SubscriptionScheduleUpdate = Identifiable & Omit & {attributes: Partial} 43 | 44 | /** 45 | * Subscription Schedule Endpoints 46 | * DOCS: TODO: add docs when ready 47 | */ 48 | export interface SubscriptionSchedulesEndpoint 49 | extends CrudQueryableResource< 50 | SubscriptionSchedule, 51 | SubscriptionScheduleCreate, 52 | SubscriptionScheduleUpdate, 53 | never, 54 | never, 55 | never 56 | > { 57 | endpoint: 'schedules' 58 | } 59 | -------------------------------------------------------------------------------- /src/types/subscription-subscribers.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Subscription Subscribers 3 | * Description: Subscription Subscribers. 4 | * DOCS: TODO: add docs when ready 5 | */ 6 | import { 7 | Identifiable, 8 | CrudQueryableResource 9 | } from './core' 10 | 11 | /** 12 | * Core Subscription Subscriber Base Interface 13 | * For custom flows, extend this interface 14 | * DOCS: TODO: add docs when ready 15 | */ 16 | export interface SubscriptionSubscriberBase { 17 | type: "subscription_subscriber" 18 | attributes: { 19 | account_id: string 20 | name: string 21 | email: string 22 | } 23 | } 24 | export interface SubscriptionSubscriber extends Identifiable, SubscriptionSubscriberBase { 25 | meta: { 26 | owner: string 27 | timestamps: { 28 | created_at: string 29 | updated_at: string 30 | } 31 | } 32 | } 33 | export type SubscriptionSubscriberCreate = SubscriptionSubscriberBase 34 | export type SubscriptionSubscriberUpdate = Identifiable & Omit & {attributes: Partial} 35 | 36 | /** 37 | * Subscription Subscriber Endpoints 38 | * DOCS: TODO: add docs when ready 39 | */ 40 | export interface SubscriptionSubscribersEndpoint 41 | extends CrudQueryableResource< 42 | SubscriptionSubscriber, 43 | SubscriptionSubscriberCreate, 44 | SubscriptionSubscriberUpdate, 45 | never, 46 | never, 47 | never 48 | > { 49 | endpoint: 'plans' 50 | } 51 | -------------------------------------------------------------------------------- /src/types/util.d.ts: -------------------------------------------------------------------------------- 1 | export type WithOptional = Omit & 2 | Partial> 3 | 4 | export type WithRequired = Pick & 5 | Partial> 6 | 7 | /** 8 | * XOR using conditional types 9 | * https://github.com/Microsoft/TypeScript/issues/14094#issuecomment-373782604 10 | */ 11 | export type Without = { [P in Exclude]?: never } 12 | export type XOR = T | U extends object 13 | ? (Without & U) | (Without & T) 14 | : T | U 15 | -------------------------------------------------------------------------------- /src/utils/configFetch.js: -------------------------------------------------------------------------------- 1 | import { throttleFetch } from './throttle' 2 | 3 | export const resolveFetchMethod = options => { 4 | const { custom_fetch, throttleEnabled, throttleLimit, throttleInterval } = 5 | options 6 | 7 | /** 8 | * Use custom fetch function if provided 9 | */ 10 | const resolvedFetch = custom_fetch ?? fetch 11 | 12 | /** 13 | * Throttle the decided on fetch function if throttleEnabled option is true 14 | */ 15 | return throttleEnabled 16 | ? throttleFetch(resolvedFetch, throttleLimit, throttleInterval) 17 | : resolvedFetch 18 | } 19 | -------------------------------------------------------------------------------- /src/utils/constants.js: -------------------------------------------------------------------------------- 1 | export const DEFAULT_CREDENTIALS_KEY = 'moltinCredentials' 2 | export const DEFAULT_CART_KEY = 'mcart' 3 | export const DEFAULT_CURRENCY_KEY = 'mcurrency' -------------------------------------------------------------------------------- /src/utils/fetch-polyfill.js: -------------------------------------------------------------------------------- 1 | import fetch, { Headers, Request, Response } from 'cross-fetch' 2 | 3 | if (!globalThis.fetch) { 4 | globalThis.fetch = fetch 5 | globalThis.Headers = Headers 6 | globalThis.Request = Request 7 | globalThis.Response = Response 8 | } 9 | -------------------------------------------------------------------------------- /src/utils/throttle.js: -------------------------------------------------------------------------------- 1 | import throttledQueue from 'throttled-queue' 2 | 3 | /** 4 | * Cached throttle queue 5 | */ 6 | let throttleQueue 7 | 8 | export const throttleFetch = 9 | (resolveFetch, throttleLimit, throttleInterval) => async (url, options) => { 10 | if (throttleQueue === undefined) { 11 | throttleQueue = throttledQueue(throttleLimit, throttleInterval) 12 | } 13 | return throttleQueue(() => resolveFetch(url, options)) 14 | } 15 | -------------------------------------------------------------------------------- /test/factories/request.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import fakeTimers from '@sinonjs/fake-timers' 4 | import { gateway as MoltinGateway } from '../../src/moltin' 5 | import { shopperCatalogProductResponse } from '../factories' 6 | 7 | const apiUrl = 'https://euwest.api.elasticpath.com' 8 | 9 | describe('Moltin request', () => { 10 | const Moltin = MoltinGateway({ 11 | client_id: 'XXX' 12 | }) 13 | 14 | let clock: fakeTimers.InstalledClock | undefined 15 | 16 | beforeEach(() => { 17 | clock = fakeTimers.install({ 18 | shouldAdvanceTime: true, 19 | advanceTimeDelta: 1 20 | }) 21 | }) 22 | 23 | afterEach(() => { 24 | clock?.uninstall() 25 | }) 26 | 27 | it('Moltin request when 401 response should attempt to re-authenticate', () => { 28 | // Intercept the API request 29 | nock(apiUrl, { 30 | reqheaders: { 31 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 32 | } 33 | }) 34 | .post('/oauth/access_token') 35 | .reply(200, { 36 | token_type: 'Bearer', 37 | expires_in: 9999999999, 38 | expires: 9999999999, 39 | identifier: 'implicit', 40 | access_token: 'a550d8cbd4a4627013452359ab69694cd446615a' 41 | }) 42 | 43 | nock(apiUrl, { 44 | reqheaders: { 45 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 46 | } 47 | }) 48 | .get('/catalog/products/1') 49 | .reply(401, { 50 | errors: { 51 | title: 'Unauthorized', 52 | status: 401 53 | } 54 | }) 55 | .get('/catalog/products/1') 56 | .reply(200, shopperCatalogProductResponse) 57 | 58 | return Moltin.ShopperCatalog.Products.Get({ productId: '1' }).then( 59 | response => { 60 | assert.equal(response.data.attributes.name, 'Playstation 5 Controller') 61 | } 62 | ) 63 | }) 64 | }) 65 | -------------------------------------------------------------------------------- /test/tests.ts: -------------------------------------------------------------------------------- 1 | require('./unit/config') 2 | require('./unit/authentication') 3 | 4 | // Classes 5 | require('./unit/customer-addresses') 6 | require('./unit/account-addresses') 7 | require('./unit/brands') 8 | require('./unit/cart') 9 | require('./unit/categories') 10 | require('./unit/collections') 11 | require('./unit/currencies') 12 | require('./unit/customers') 13 | require('./unit/fields') 14 | require('./unit/files') 15 | require('./unit/flows') 16 | require('./unit/gateways') 17 | require('./unit/integrations') 18 | require('./unit/inventories') 19 | require('./unit/jobs') 20 | require('./unit/oidc-profile') 21 | require('./unit/orders') 22 | require('./unit/products') 23 | require('./unit/user-authentication-info') 24 | require('./unit/password-profile') 25 | require('./unit/user-authentication-password-profile') 26 | require('./unit/transactions') 27 | require('./unit/error') 28 | require('./unit/settings') 29 | require('./unit/promotions') 30 | require('./unit/variations') 31 | // require('./unit/authentication-realm') 32 | // require('./unit/authentication-settings') 33 | require('./unit/accounts') 34 | require('./unit/account-members') 35 | require('./unit/account-authentication-settings') 36 | require('./unit/account-membership-settings') 37 | require('./unit/account-memberships') 38 | require('./unit/application-keys') 39 | require('./unit/one-time-password-token-request') 40 | 41 | // Utilities 42 | require('./utils/helpers') 43 | require('./utils/throttle') 44 | require('./utils/configFetch') 45 | 46 | require('./factories/request') 47 | -------------------------------------------------------------------------------- /test/unit/account-authentication-settings.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 6 | 7 | describe('Moltin Account Authentication Settings', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | it('Get all Account Settings', () => { 13 | nock(apiUrl, {}) 14 | .get('/settings/account-authentication') 15 | .reply(200, {}) 16 | 17 | return Moltin.AccountAuthenticationSettings.Get().then(res => { 18 | assert.isObject(res) 19 | }) 20 | }) 21 | 22 | it('should update account authentication settings', () => { 23 | nock(apiUrl, { 24 | reqheaders: { 25 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 26 | } 27 | }) 28 | .put('/settings/account-authentication', { 29 | data: { 30 | type: 'account_authentication_settings', 31 | enable_self_signup: true, 32 | auto_create_account_for_account_members: true, 33 | account_management_authentication_token_timeout_secs: 200, 34 | account_member_self_management: 'update_only' 35 | } 36 | }) 37 | .reply(200, { 38 | data: { 39 | id: '775c934a-b54b-4846-9a7e-21844f4700a4', 40 | type: 'account_authentication_settings', 41 | enable_self_signup: true, 42 | auto_create_account_for_account_members: true, 43 | account_member_self_management: 'update_only', 44 | account_management_authentication_token_timeout_secs: 200, 45 | relationships: { 46 | authentication_realm: { 47 | data: { 48 | id: "775c934a-b54b-4846-9a7e-21844f4700a5", 49 | type: "authentication_realm" 50 | } 51 | } 52 | }, 53 | meta: { 54 | client_id: "account-management" 55 | } 56 | } 57 | }) 58 | const body = { 59 | type: 'account_authentication_settings', 60 | enable_self_signup: true, 61 | auto_create_account_for_account_members: true, 62 | account_management_authentication_token_timeout_secs: 200, 63 | account_member_self_management: 'update_only' 64 | } 65 | 66 | return Moltin.AccountAuthenticationSettings.Update(body).then(response => { 67 | assert.deepEqual(response, { 68 | data: { 69 | id: '775c934a-b54b-4846-9a7e-21844f4700a4', 70 | type: 'account_authentication_settings', 71 | enable_self_signup: true, 72 | auto_create_account_for_account_members: true, 73 | account_management_authentication_token_timeout_secs: 200, 74 | account_member_self_management: 'update_only', 75 | relationships: { 76 | authentication_realm: { 77 | data: { 78 | id: "775c934a-b54b-4846-9a7e-21844f4700a5", 79 | type: "authentication_realm" 80 | } 81 | } 82 | }, 83 | meta: { 84 | client_id: "account-management" 85 | } 86 | } 87 | }) 88 | }) 89 | }) 90 | }) 91 | -------------------------------------------------------------------------------- /test/unit/account-members.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com' 6 | 7 | describe('Moltin Account Members', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | it('Get a single account member', () => { 13 | nock(apiUrl, {}) 14 | .post('/oauth/access_token') 15 | .reply(200, { 16 | access_token: 'a550d8cbd4a4627013452359ab69694cd446615a' 17 | }) 18 | .get(/account-members\/*/) 19 | .reply(200, {}) 20 | const accountMemberId = '64f35045-2a76-4bcf-b6ba-02bb12090d38' 21 | 22 | return Moltin.AccountMembers.Get(accountMemberId).then(res => { 23 | assert.isObject(res) 24 | }) 25 | }) 26 | 27 | it('Get all Account Members', () => { 28 | nock(apiUrl, {}) 29 | .get(/account-members\/*/) 30 | .reply(200, {}) 31 | 32 | return Moltin.AccountMembers.All().then(res => { 33 | assert.isObject(res) 34 | }) 35 | }) 36 | 37 | it('Get all Account Members with filter', () => { 38 | nock(apiUrl, {}) 39 | .get(/account-members\/*/) 40 | .query({ 41 | filter: 'eq(name,John)' 42 | }) 43 | .reply(200, {}) 44 | 45 | return Moltin.AccountMembers.Filter({ eq: { name: 'John' } }) 46 | .All() 47 | .then(res => { 48 | assert.isObject(res) 49 | }) 50 | }) 51 | }) 52 | -------------------------------------------------------------------------------- /test/unit/account-membership-settings.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 6 | 7 | describe('Moltin Account Membership Settings', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | it('Get Account Membership Settings', () => { 13 | nock(apiUrl, {}) 14 | .get('/settings/account-membership') 15 | .reply(200, {}) 16 | 17 | return Moltin.AccountMembershipSettings.Get().then(res => { 18 | assert.isObject(res) 19 | }) 20 | }) 21 | 22 | it('Update Account Membership Settings', () => { 23 | nock(apiUrl, {}) 24 | .post('/oauth/access_token') 25 | .reply(200, { 26 | access_token: 'a550d8cbd4a4627013452359ab69694cd446615a' 27 | }) 28 | .put('/settings/account-membership') 29 | .reply(200, {}) 30 | 31 | const body = { 32 | type: 'account_membership_setting', 33 | membership_limit: 2 34 | } 35 | 36 | return Moltin.AccountMembershipSettings.Update(body).then(res => { 37 | assert.isObject(res) 38 | }) 39 | }) 40 | }) 41 | -------------------------------------------------------------------------------- /test/unit/authentication-realm.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 6 | 7 | describe('Moltin Authentication Realms', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | it('Get all Realms', () => { 13 | nock(apiUrl, {}) 14 | .get('/authentication-realms') 15 | .reply(200, {}) 16 | 17 | return Moltin.AuthenticationRealm.All().then(res => { 18 | assert.isObject(res) 19 | }) 20 | }) 21 | 22 | it('Get a single Realm', () => { 23 | nock(apiUrl, {}) 24 | .get(/authentication-realms\/*/) 25 | .reply(200, {}) 26 | const realmId = '64f35045-2a76-4bcf-b6ba-02bb12090d38' 27 | 28 | return Moltin.AuthenticationRealm.Get({ realmId }).then(res => { 29 | assert.isObject(res) 30 | }) 31 | }) 32 | 33 | it('Create a single Realm', () => { 34 | nock(apiUrl, {}) 35 | .post(/authentication-realms\/*/) 36 | .reply(201, {}) 37 | 38 | const data = { 39 | type: 'authentication-realm' as const, 40 | name: 'Boo Authentication Realm' 41 | } 42 | 43 | return Moltin.AuthenticationRealm.Create({ data }).then(res => { 44 | assert.isObject(res) 45 | }) 46 | }) 47 | 48 | it('Update a single Realm', () => { 49 | nock(apiUrl, {}) 50 | .put(/authentication-realms\/*/) 51 | .reply(201, {}) 52 | 53 | const body = { 54 | type: 'authentication-realm' as const, 55 | name: 'Boo Authentication Realm' 56 | } 57 | 58 | const realmId = '64f35045-2a76-4bcf-b6ba-02bb12090d38' 59 | 60 | return Moltin.AuthenticationRealm.Update(realmId, body).then(res => { 61 | assert.isObject(res) 62 | }) 63 | }) 64 | 65 | it('Delete a single Realm', () => { 66 | nock(apiUrl, {}) 67 | .delete(/authentication-realms\/*/) 68 | .reply(204, {}) 69 | 70 | const realmId = '64f35045-2a76-4bcf-b6ba-02bb12090d38' 71 | 72 | return Moltin.AuthenticationRealm.Delete(realmId).then(res => { 73 | assert.isObject(res) 74 | }) 75 | }) 76 | }) 77 | -------------------------------------------------------------------------------- /test/unit/authentication-settings.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 6 | 7 | describe('Moltin Authentication Settings', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | it('Get all Settings', () => { 13 | nock(apiUrl, {}) 14 | .get('/settings/customer-authentication') 15 | .reply(200, {}) 16 | 17 | return Moltin.AuthenticationSettings.Get().then(res => { 18 | assert.isObject(res) 19 | }) 20 | }) 21 | }) 22 | -------------------------------------------------------------------------------- /test/unit/error.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | import { 5 | notFoundError, 6 | rateLimitError, 7 | productsArray as products 8 | } from '../factories' 9 | 10 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 11 | 12 | describe('Moltin error handling', () => { 13 | const Moltin = MoltinGateway({ 14 | client_id: 'XXX', 15 | retryDelay: 10, // Reduce retryDelay/retryJitter/fetchMaxAttempts for retries during testing 16 | retryJitter: 1, 17 | fetchMaxAttempts: 2 // Minimum amount of fetch attempts we need for these tests. 18 | }) 19 | 20 | it('should handle a 429 correctly', () => { 21 | // Intercept the API request 22 | nock(apiUrl, { 23 | reqheaders: { 24 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 25 | } 26 | }) 27 | .get('/products') 28 | .times(2) 29 | .reply(429, rateLimitError) 30 | 31 | return Moltin.Products.All().catch(error => { 32 | assert.deepEqual(error, { errors: [{ status: 429 }] }) 33 | }) 34 | }) 35 | 36 | it('should handle a 404 correctly', () => { 37 | // Intercept the API request 38 | nock(apiUrl, { 39 | reqheaders: { 40 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 41 | } 42 | }) 43 | .get('/products') 44 | .reply(404, notFoundError) 45 | 46 | return Moltin.Products.All().catch(error => { 47 | assert.deepEqual(error, { 48 | errors: [ 49 | { 50 | status: 404, 51 | detail: 'The requested product could not be found', 52 | title: 'Product not found' 53 | } 54 | ] 55 | }) 56 | }) 57 | }) 58 | 59 | it('should handle retry then success correctly', () => { 60 | // Intercept the API request 61 | nock(apiUrl, { 62 | reqheaders: { 63 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 64 | } 65 | }) 66 | .get('/products') 67 | .reply(429, rateLimitError) 68 | .get('/products') 69 | .reply(200, { data: products }) 70 | return Moltin.Products.All().then(response => { 71 | assert.lengthOf(response.data, 4) 72 | }) 73 | }) 74 | }) 75 | -------------------------------------------------------------------------------- /test/unit/gateways.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | import { gatewaysArray as gateways, attributeResponse } from '../factories' 5 | 6 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 7 | 8 | describe('Moltin gateways', () => { 9 | const Moltin = MoltinGateway({ 10 | client_id: 'XXX' 11 | }) 12 | 13 | it('should return an array of gateways', () => { 14 | // Intercept the API request 15 | nock(apiUrl, { 16 | reqheaders: { 17 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 18 | } 19 | }) 20 | .get('/gateways') 21 | .reply(200, { data: gateways }) 22 | 23 | return Moltin.Gateways.All().then(response => { 24 | assert.lengthOf(response.data, 2) 25 | }) 26 | }) 27 | 28 | it('should return a single gateway', () => { 29 | // Intercept the API request 30 | nock(apiUrl, { 31 | reqheaders: { 32 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 33 | } 34 | }) 35 | .get('/gateways/braintree') 36 | .reply(200, gateways[0]) 37 | 38 | return Moltin.Gateways.Get(gateways[0].slug).then(response => { 39 | assert.propertyVal(response, 'slug', 'braintree') 40 | }) 41 | }) 42 | 43 | it('should enable a gateway', () => { 44 | // Intercept the API request 45 | nock(apiUrl, { 46 | reqheaders: { 47 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 48 | } 49 | }) 50 | .put('/gateways/braintree', { 51 | data: { 52 | type: 'gateway', 53 | enabled: true 54 | } 55 | }) 56 | .reply(200, { 57 | enabled: true 58 | }) 59 | 60 | return Moltin.Gateways.Enabled(gateways[0].slug, true).then(response => { 61 | assert.propertyVal(response, 'enabled', true) 62 | }) 63 | }) 64 | 65 | it('should update a gateway', () => { 66 | // Intercept the API request 67 | nock(apiUrl, { 68 | reqheaders: { 69 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 70 | } 71 | }) 72 | .put('/gateways/braintree', { 73 | data: { 74 | name: 'Braintree (updated)' 75 | } 76 | }) 77 | .reply(200, { 78 | name: 'Braintree (updated)' 79 | }) 80 | 81 | return Moltin.Gateways.Update(gateways[0].slug, { 82 | name: 'Braintree (updated)' 83 | }).then(response => { 84 | assert.propertyVal(response, 'name', 'Braintree (updated)') 85 | }) 86 | }) 87 | 88 | it('should get slug attributes', () => { 89 | // Intercept the API request 90 | nock(apiUrl, { 91 | reqheaders: { 92 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 93 | } 94 | }) 95 | .get('/gateways/braintree/attributes') 96 | .reply(200, attributeResponse) 97 | 98 | return Moltin.Gateways.GetSlugAttributes(gateways[0].slug).then( 99 | response => { 100 | assert.lengthOf(response.data, 3) 101 | } 102 | ) 103 | }) 104 | }) 105 | -------------------------------------------------------------------------------- /test/unit/jobs.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | import { jobsArray as jobs } from '../factories' 5 | 6 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 7 | 8 | describe('Moltin jobs', () => { 9 | const Moltin = MoltinGateway({ 10 | client_id: 'XXX' 11 | }) 12 | 13 | it('should return an array of jobs', () => { 14 | // Intercept the API request 15 | nock(apiUrl, { 16 | reqheaders: { 17 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 18 | } 19 | }) 20 | .get('/jobs') 21 | .reply(200, { data: jobs }) 22 | 23 | return Moltin.Jobs.All().then(response => { 24 | assert.lengthOf(response.data, 3) 25 | }) 26 | }) 27 | 28 | it('should return a single job', () => { 29 | // Intercept the API request 30 | nock(apiUrl, { 31 | reqheaders: { 32 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 33 | } 34 | }) 35 | .get('/jobs/1') 36 | .reply(200, jobs[0]) 37 | 38 | return Moltin.Jobs.Get('1').then(response => { 39 | assert.propertyVal(response, 'id', 'job-1') 40 | }) 41 | }) 42 | 43 | it('should return a file', () => { 44 | // Intercept the API request 45 | nock(apiUrl, { 46 | reqheaders: { 47 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 48 | } 49 | }) 50 | .get('/jobs/1/file') 51 | .reply(200, jobs[0]) 52 | 53 | return Moltin.Jobs.GetFile('1').then(response => { 54 | assert.propertyVal(response, 'id', 'job-1') 55 | }) 56 | }) 57 | 58 | it('should create a new job', () => { 59 | const newJobs = { 60 | filter: "", 61 | job_type: "order_export" 62 | } 63 | 64 | // Intercept the API request 65 | nock(apiUrl, { 66 | reqheaders: { 67 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 68 | } 69 | }) 70 | .post('/jobs', { data: newJobs }) 71 | .reply(201, jobs[0]) 72 | 73 | return Moltin.Jobs.Create(newJobs).then(response => { 74 | assert.propertyVal(response, 'id', 'job-1') 75 | }) 76 | }) 77 | }) 78 | -------------------------------------------------------------------------------- /test/unit/oidc-profile.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 6 | 7 | describe('Oidc Profiles', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | const realmId = '96764ca9-af12-4355-acce-37fa2ef4728a' 13 | 14 | it('Get all Oidc Profiles', () => { 15 | nock(apiUrl, {}) 16 | .get(/\/authentication-realms\/(.*)\/oidc-profiles/) 17 | .reply(200, {}) 18 | 19 | return Moltin.OidcProfile.All(realmId).then(res => { 20 | assert.isObject(res) 21 | }) 22 | }) 23 | 24 | it('Get a single Oidc Profile', () => { 25 | nock(apiUrl, {}) 26 | .get(/\/authentication-realms\/(.*)\/oidc-profiles\/(.*)/) 27 | .reply(200, {}) 28 | 29 | return Moltin.OidcProfile.Get({ 30 | realmId, 31 | profileId: '4da65e78-7f9b-4248-b498-823d43120da9' 32 | }).then(res => { 33 | assert.isObject(res) 34 | }) 35 | }) 36 | 37 | it('Create a single Oidc Profile', () => { 38 | nock(apiUrl, {}) 39 | .post(/\/authentication-realms\/(.*)\/oidc-profiles/) 40 | .reply(201, {}) 41 | 42 | const body = { 43 | name: 'Keycloak', 44 | type: 'oidc-profile', 45 | discovery_url: 'https://localhost:3000/discovery_url', 46 | client_id: 'test-client', 47 | client_secret: 'XXXXXX' 48 | } 49 | 50 | return Moltin.OidcProfile.Create(realmId, {data:body}).then(res => { 51 | assert.isObject(res) 52 | }) 53 | }) 54 | 55 | it('Update a single Oidc Profile', () => { 56 | nock(apiUrl, {}) 57 | .put(/\/authentication-realms\/(.*)\/oidc-profiles\/(.*)/) 58 | .reply(201, {}) 59 | 60 | const body = { 61 | name: 'Keycloak 2', 62 | type: 'oidc-profile', 63 | discovery_url: 64 | 'http://localhost:24074/auth/realms/Sample/.well-known/openid-configuration', 65 | client_id: 'openid-client', 66 | client_secret: 'ba5eba11-affec7ed-c0ff1e' 67 | } 68 | 69 | const profileId = 'e1b5c7fa-f2b6-48d2-b659-3d82f20968a9' 70 | 71 | return Moltin.OidcProfile.Update(realmId, profileId, {data:body}).then(res => { 72 | assert.isObject(res) 73 | }) 74 | }) 75 | 76 | it('Delete a single Oidc Profile', () => { 77 | nock(apiUrl, {}) 78 | .delete(/\/authentication-realms\/(.*)\/oidc-profiles\/(.*)/) 79 | .reply(204) 80 | 81 | const profileId = '7e6645ef-0084-4928-b9b4-d2fe5577f70e' 82 | 83 | return Moltin.OidcProfile.Delete(realmId, profileId).then(res => { 84 | assert.equal(res, '{}') 85 | }) 86 | }) 87 | }) 88 | -------------------------------------------------------------------------------- /test/unit/one-time-password-token-request.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 6 | 7 | describe('One Time Password Token Request', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | const realmId = '96764ca9-af12-4355-acce-37fa2ef4728a' 13 | const passwordProfileId = '4da65e78-7f9b-4248-b498-823d43120da9' 14 | 15 | it('Create a One Time Password Token Info', () => { 16 | nock(apiUrl, {}) 17 | .post(/\/authentication-realms\/(.*)\/password-profiles\/(.*)\/one-time-password-token-request/) 18 | .reply(202, {}) 19 | 20 | const body = { 21 | type: "one_time_password_token_request", 22 | username: "john.doe", 23 | purpose : "reset_password" 24 | } 25 | 26 | return Moltin.OneTimePasswordTokenRequest.Create(realmId,passwordProfileId, body).then(res => { 27 | assert.isObject(res) 28 | }) 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /test/unit/password-profile.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | 5 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 6 | 7 | describe('Password Profiles', () => { 8 | const Moltin = MoltinGateway({ 9 | client_id: 'XXX' 10 | }) 11 | 12 | const realmId = '96764ca9-af12-4355-acce-37fa2ef4728a' 13 | 14 | it('Read All User Authentication Password Profile Info', () => { 15 | nock(apiUrl, {}) 16 | .get(/\/authentication-realms\/(.*)\/password-profiles/) 17 | .reply(200, {}) 18 | 19 | return Moltin.PasswordProfile.All(realmId).then(res => { 20 | assert.isObject(res) 21 | }) 22 | }) 23 | 24 | it('Get a single Password Profile', () => { 25 | nock(apiUrl, {}) 26 | .get(/\/authentication-realms\/(.*)\/password-profiles\/(.*)/) 27 | .reply(200, {}) 28 | 29 | return Moltin.PasswordProfile.Get({ 30 | realmId, 31 | profileId: '4da65e78-7f9b-4248-b498-823d43120da9' 32 | }).then(res => { 33 | assert.isObject(res) 34 | }) 35 | }) 36 | 37 | it('Create a single Password Profile', () => { 38 | nock(apiUrl, {}) 39 | .post(/\/authentication-realms\/(.*)\/password-profiles/) 40 | .reply(201, {}) 41 | 42 | const body = { 43 | username_format: 'email', 44 | name: 'password profile', 45 | type: 'password_profile' 46 | } 47 | 48 | return Moltin.PasswordProfile.Create(realmId, { data: body }).then(res => { 49 | assert.isObject(res) 50 | }) 51 | }) 52 | 53 | it('Update a single Password Profile', () => { 54 | nock(apiUrl, {}) 55 | .put(/\/authentication-realms\/(.*)\/password-profiles\/(.*)/) 56 | .reply(201, {}) 57 | 58 | const body = { 59 | username_format: 'any', 60 | type: 'password_profile', 61 | name: 'updated password profile' 62 | } 63 | 64 | const profileId = 'e1b5c7fa-f2b6-48d2-b659-3d82f20968a9' 65 | 66 | return Moltin.PasswordProfile.Update(realmId, profileId, { 67 | data: body 68 | }).then(res => { 69 | assert.isObject(res) 70 | }) 71 | }) 72 | 73 | it('Delete a single Password Profile', () => { 74 | nock(apiUrl, {}) 75 | .delete(/\/authentication-realms\/(.*)\/password-profiles\/(.*)/) 76 | .reply(204) 77 | 78 | const profileId = '7e6645ef-0084-4928-b9b4-d2fe5577f70e' 79 | 80 | return Moltin.PasswordProfile.Delete(realmId, profileId).then(res => { 81 | assert.equal(res, '{}') 82 | }) 83 | }) 84 | }) 85 | -------------------------------------------------------------------------------- /test/unit/transactions.ts: -------------------------------------------------------------------------------- 1 | import { assert } from 'chai' 2 | import nock from 'nock' 3 | import { gateway as MoltinGateway } from '../../src/moltin' 4 | import { orderTransactionsArray as transactions } from '../factories' 5 | 6 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 7 | 8 | describe('Moltin order transactions', () => { 9 | const Moltin = MoltinGateway({ 10 | client_id: 'XXX' 11 | }) 12 | 13 | it('should return an array of order transactions', () => { 14 | // Intercept the API request 15 | nock(apiUrl, { 16 | reqheaders: { 17 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 18 | } 19 | }) 20 | .get('/orders/order-1/transactions') 21 | .reply(200, { data: transactions }) 22 | 23 | return Moltin.Transactions.All({ order: 'order-1' }).then(response => { 24 | assert.lengthOf(response.data, 2) 25 | assert.propertyVal(response.data[0], 'id', 'transaction-1') 26 | assert.propertyVal(response.data[1], 'id', 'transaction-2') 27 | }) 28 | }) 29 | 30 | it('should return a single order transaction', () => { 31 | // Intercept the API request 32 | nock(apiUrl, { 33 | reqheaders: { 34 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 35 | } 36 | }) 37 | .get('/orders/order-1/transactions/transaction-1') 38 | .reply(200, { data: transactions[0] }) 39 | 40 | return Moltin.Transactions.Get({ 41 | order: 'order-1', 42 | transaction: 'transaction-1' 43 | }).then(response => { 44 | assert.isOk(response) 45 | }) 46 | }) 47 | 48 | it('should capture an order transaction', () => { 49 | // Intercept the API request 50 | nock(apiUrl, { 51 | reqheaders: { 52 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 53 | } 54 | }) 55 | .post('/orders/order-1/transactions/transaction-1/capture') 56 | .reply(200, {}) 57 | 58 | return Moltin.Transactions.Capture({ 59 | order: 'order-1', 60 | transaction: 'transaction-1' 61 | }).then(response => { 62 | assert.isOk(response) 63 | }) 64 | }) 65 | 66 | it('should refund an order transaction', () => { 67 | // Intercept the API request 68 | nock(apiUrl, { 69 | reqheaders: { 70 | Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' 71 | } 72 | }) 73 | .post('/orders/order-1/transactions/transaction-1/refund') 74 | .reply(200, {}) 75 | 76 | return Moltin.Transactions.Refund({ 77 | order: 'order-1', 78 | transaction: 'transaction-1' 79 | }).then(response => { 80 | assert.isOk(response) 81 | }) 82 | }) 83 | }) 84 | -------------------------------------------------------------------------------- /test/utils/configFetch.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai' 2 | import '../../src/utils/fetch-polyfill' 3 | import resolveFetchMethod from '../../src/utils/configFetch' 4 | import { gateway as MoltinGateway } from '../../src/moltin' 5 | 6 | describe('Config fetch parameters', () => { 7 | // minimal test function 8 | const testCustomFetch = (url: string, options: object) => url 9 | 10 | const Moltin = MoltinGateway({ 11 | client_id: 'xxx', 12 | client_secret: 'xxx', 13 | custom_fetch: testCustomFetch, 14 | throttleEnabled: true, 15 | throttleLimit: 3, 16 | throttleInterval: 125 17 | }) 18 | const mockOptions = { 19 | custom_fetch: Moltin.config.custom_fetch, 20 | throttleEnabled: Moltin.config.throttleConfig?.throttleEnabled, 21 | throttleLimit: Moltin.config.throttleConfig?.throttleLimit, 22 | throttleInterval: Moltin.config.throttleConfig?.throttleInterval 23 | } 24 | const throttleMock = async function (fn: () => any) { 25 | return fn() 26 | } 27 | 28 | it('should have correct config options for resolveFetchMethod', () => { 29 | const resolveFetchMethodMock = function (options: any) { 30 | const isCustomFetch = options.custom_fetch ?? fetch 31 | expect(options.custom_fetch).to.equal(Moltin.config.custom_fetch) 32 | expect(options.throttleEnabled).to.equal( 33 | Moltin.config.throttleConfig?.throttleEnabled 34 | ) 35 | return options.throttleEnabled ? throttleMock : isCustomFetch 36 | } 37 | resolveFetchMethodMock(mockOptions) 38 | resolveFetchMethod.__Rewire__('resolveFetchMethod', resolveFetchMethodMock) 39 | }) 40 | 41 | it('should access throttleFetch if custom_fetch and throttle request is given', () => { 42 | expect(throttleMock).to.not.be.undefined 43 | const resolveFetchMethodMock = function (options: any) { 44 | const isCustomFetch = options.custom_fetch ?? fetch 45 | return options.throttleEnabled ? throttleMock : isCustomFetch 46 | } 47 | 48 | const response = resolveFetchMethodMock(mockOptions) 49 | resolveFetchMethod.__Rewire__('resolveFetchMethod', resolveFetchMethodMock) 50 | expect(response).to.equal(throttleMock) 51 | }) 52 | }) 53 | -------------------------------------------------------------------------------- /test/utils/throttle.ts: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai' 2 | import '../../src/utils/fetch-polyfill' 3 | import throttleMod from '../../src/utils/throttle.js' 4 | import { gateway as MoltinGateway } from '../../src/moltin' 5 | 6 | const apiUrl = 'https://euwest.api.elasticpath.com/v2' 7 | 8 | describe('Build throttle mechanism', () => { 9 | const Moltin = MoltinGateway({ 10 | client_id: 'xxx', 11 | client_secret: 'xxx', 12 | throttleEnabled: true, 13 | throttleLimit: 3, 14 | throttleInterval: 125 15 | }) 16 | 17 | it('should have correct config options for throttle', () => { 18 | const throttledQueueMock = function (limit: number, interval: number) { 19 | expect(limit).to.equal(Moltin.config.throttleConfig?.throttleLimit) 20 | expect(interval).to.equal(Moltin.config.throttleConfig?.throttleInterval) 21 | } 22 | throttleMod.__Rewire__('throttledQueue', throttledQueueMock) 23 | }) 24 | 25 | it('should not be undefined', async () => { 26 | const throttleMock = async function (fn: () => any) { 27 | return fn() 28 | } 29 | expect(throttleMock).to.not.be.undefined 30 | throttleMod.__Rewire__('throttle', throttleMock) 31 | }) 32 | }) 33 | --------------------------------------------------------------------------------