Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
feat: subscriptions product (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
rostyk-kanafotskyy authored May 5, 2023
1 parent 780ab41 commit c7a2a91
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/endpoints/subscription-products.js
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/moltin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/moltin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions src/types/subscription-product.d.ts
Original file line number Diff line number Diff line change
@@ -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<SubscriptionProductBase, 'attributes'> & {attributes: Partial<SubscriptionProductBase['attributes']>}
export type SubscriptionProductUpdate = Omit<SubscriptionProduct, 'attributes'> & {attributes: Partial<SubscriptionProductBase['attributes']>}

/**
* Subscription Product Endpoints
* DOCS: TODO: add docs when ready
*/
export interface SubscriptionProductsEndpoint
extends CrudQueryableResource<
SubscriptionProduct,
SubscriptionProductCreate,
SubscriptionProductUpdate,
never,
never,
never
> {
endpoint: 'products'
}

0 comments on commit c7a2a91

Please sign in to comment.