From c7a2a91376075048431014411357f061791cd93d Mon Sep 17 00:00:00 2001 From: Rostyk <34774987+rostyk-kanafotskyy@users.noreply.github.com> Date: Fri, 5 May 2023 13:21:49 +0300 Subject: [PATCH] feat: subscriptions product (#801) --- src/endpoints/subscription-products.js | 29 ++++++++++++++++ src/moltin.d.ts | 3 ++ src/moltin.js | 2 ++ src/types/subscription-product.d.ts | 48 ++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 src/endpoints/subscription-products.js create mode 100644 src/types/subscription-product.d.ts diff --git a/src/endpoints/subscription-products.js b/src/endpoints/subscription-products.js new file mode 100644 index 000000000..f20f9d016 --- /dev/null +++ b/src/endpoints/subscription-products.js @@ -0,0 +1,29 @@ +import CRUDExtend from '../extends/crud' + +class SubscriptionProductsEndpoint extends CRUDExtend { + constructor(endpoint) { + super(endpoint) + + this.endpoint = 'subscriptions/products' + } + + Create(body) { + return this.request.send(this.endpoint, 'POST', { + ...body + }) + } + + Update(id, body, token = null) { + return this.request.send( + `${this.endpoint}/${id}`, + 'PUT', + { + ...body + }, + token + ) + } + +} + +export default SubscriptionProductsEndpoint diff --git a/src/moltin.d.ts b/src/moltin.d.ts index f86f27dea..7162a3d6e 100644 --- a/src/moltin.d.ts +++ b/src/moltin.d.ts @@ -54,6 +54,7 @@ import { ErasureRequestsEndpoint } from './types/erasure-requests' import { PriceBookPriceModifierEndpoint } from './types/price-book-price-modifiers' import { AccountMembershipSettingsEndpoint } from './types/account-membership-settings' import { ApplicationKeysEndpoint } from './types/application-keys' +import { SubscriptionProductsEndpoint } from './types/subscription-product' export * from './types/config' export * from './types/storage' @@ -118,6 +119,7 @@ export * from './types/user-authentication-password-profile' export * from './types/locales' export * from './types/extensions' export * from './types/application-keys' +export * from './types/subscription-product' // UMD export as namespace moltin @@ -174,6 +176,7 @@ export class Moltin { ErasureRequests: ErasureRequestsEndpoint PriceBookPriceModifier: PriceBookPriceModifierEndpoint ApplicationKeys: ApplicationKeysEndpoint + SubscriptionProducts: SubscriptionProductsEndpoint Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/ constructor(config: Config) diff --git a/src/moltin.js b/src/moltin.js index 4b9c97ff5..7da87b1d3 100644 --- a/src/moltin.js +++ b/src/moltin.js @@ -47,6 +47,7 @@ import DataEntriesEndpoint from './endpoints/data-entry' import AccountMembershipSettingsEndpoint from './endpoints/account-membership-settings' import ErasureRequestsEndpoint from './endpoints/erasure-requests' import ApplicationKeysEndpoint from './endpoints/application-keys' +import SubscriptionProductsEndpoint from './endpoints/subscription-products' import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers' import CatalogsEndpoint from './endpoints/catalogs' @@ -112,6 +113,7 @@ export default class Moltin { new UserAuthenticationPasswordProfileEndpoint(config) this.Metrics = new MetricsEndpoint(config) this.ApplicationKeys = new ApplicationKeysEndpoint(config) + this.SubscriptionProducts = new SubscriptionProductsEndpoint(config) } // Expose `Cart` class on Moltin class diff --git a/src/types/subscription-product.d.ts b/src/types/subscription-product.d.ts new file mode 100644 index 000000000..a2b5de12f --- /dev/null +++ b/src/types/subscription-product.d.ts @@ -0,0 +1,48 @@ +/** + * Subscription Products + * Description: Subscription Products. + * DOCS: TODO: add docs when ready + */ +import { + Identifiable, + CrudQueryableResource +} from './core' + +/** + * Core Subscription Product Base Interface + * For custom flows, extend this interface + * DOCS: TODO: add docs when ready + */ +export interface SubscriptionProductBase { + type: string + attributes: { + created_at: string + description: string + main_image: string + name: string + sku: string + updated_at: string + }, +} + +export interface SubscriptionProduct extends Identifiable, SubscriptionProductBase { + +} +export type SubscriptionProductCreate = Omit & {attributes: Partial} +export type SubscriptionProductUpdate = Omit & {attributes: Partial} + +/** + * Subscription Product Endpoints + * DOCS: TODO: add docs when ready + */ +export interface SubscriptionProductsEndpoint + extends CrudQueryableResource< + SubscriptionProduct, + SubscriptionProductCreate, + SubscriptionProductUpdate, + never, + never, + never + > { + endpoint: 'products' +}