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

Commit

Permalink
feat: subscribers endpoint (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
rostyk-kanafotskyy committed Feb 14, 2024
1 parent 5f98d11 commit 406054e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/endpoints/subscription-subscribers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import CRUDExtend from '../extends/crud'

class SubscriptionSubscribersEndpoint extends CRUDExtend {
constructor(endpoint) {
super(endpoint)

this.endpoint = 'subscriptions/subscribers'
}

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 SubscriptionSubscribersEndpoint
3 changes: 3 additions & 0 deletions src/moltin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { SubscriptionOfferingsEndpoint } from './types/subscription-offerings'
import { OneTimePasswordTokenRequestEndpoint } from "./types/one-time-password-token-request";
import { SubscriptionsEndpoint } from './types/subscriptions'
import { RulePromotionsEndpoint } from './types/rule-promotions'
import { SubscriptionSubscribersEndpoint } from './types/subscription-subscribers'

export * from './types/config'
export * from './types/storage'
Expand Down Expand Up @@ -132,6 +133,7 @@ export * from './types/subscription-offerings'
export * from './types/one-time-password-token-request'
export * from './types/subscriptions'
export * from './types/rule-promotions'
export * from './types/subscription-subscribers'

// UMD
export as namespace moltin
Expand Down Expand Up @@ -194,6 +196,7 @@ export class Moltin {
OneTimePasswordTokenRequest: OneTimePasswordTokenRequestEndpoint
Subscriptions: SubscriptionsEndpoint
RulePromotions : RulePromotionsEndpoint
SubscriptionSubscribers : SubscriptionSubscribersEndpoint

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 @@ -53,6 +53,7 @@ import SubscriptionPlansEndpoint from './endpoints/subscription-plan'
import SubscriptionOfferingsEndpoint from './endpoints/subscription-offerings'
import SubscriptionsEndpoint from './endpoints/subscriptions'
import RulePromotionsEndpoint from './endpoints/rule-promotions'
import SubscriptionSubscribersEndpoint from './endpoints/subscription-subscribers'

import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
import CatalogsEndpoint from './endpoints/catalogs'
Expand Down Expand Up @@ -124,6 +125,7 @@ export default class Moltin {
this.OneTimePasswordTokenRequest = new OneTimePasswordTokenRequestEndpoint(config)
this.Subscriptions = new SubscriptionsEndpoint(config)
this.RulePromotions = new RulePromotionsEndpoint(config)
this.SubscriptionSubscribers = new SubscriptionSubscribersEndpoint(config)
}

// Expose `Cart` class on Moltin class
Expand Down
45 changes: 45 additions & 0 deletions src/types/subscription-subscribers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Subscription Subscribers
* Description: Subscription Subscribers.
* DOCS: TODO: add docs when ready
*/
import {
Identifiable,
CrudQueryableResource
} from './core'

/**
* Core Subscription Subscriber Base Interface
* For custom flows, extend this interface
* DOCS: TODO: add docs when ready
*/
export interface SubscriptionSubscriberBase {
type: "subscription_subscriber"
attributes: {
account_id: string
name: string
email: string
}
}

export interface SubscriptionSubscriber extends Identifiable, SubscriptionSubscriberBase {

}
export type SubscriptionSubscriberCreate = SubscriptionSubscriberBase
export type SubscriptionSubscriberUpdate = Omit<SubscriptionSubscriber, 'attributes'> & {attributes: Partial<SubscriptionSubscriberBase['attributes']> & Identifiable}

/**
* Subscription Subscriber Endpoints
* DOCS: TODO: add docs when ready
*/
export interface SubscriptionSubscribersEndpoint
extends CrudQueryableResource<
SubscriptionSubscriber,
SubscriptionSubscriberCreate,
SubscriptionSubscriberUpdate,
never,
never,
never
> {
endpoint: 'plans'
}

0 comments on commit 406054e

Please sign in to comment.