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

Commit 37577da

Browse files
feat: added subscription schedules and jobs endpoints (#919)
1 parent a2f736e commit 37577da

6 files changed

+200
-0
lines changed

src/endpoints/subscription-jobs.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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

src/moltin.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ import { OneTimePasswordTokenRequestEndpoint } from "./types/one-time-password-t
6262
import { SubscriptionsEndpoint } from './types/subscriptions'
6363
import { RulePromotionsEndpoint } from './types/rule-promotions'
6464
import { SubscriptionSubscribersEndpoint } from './types/subscription-subscribers'
65+
import { SubscriptionJobsEndpoint } from './types/subscription-jobs'
66+
import { SubscriptionSchedulesEndpoint } from './types/subscription-schedules'
6567

6668
export * from './types/config'
6769
export * from './types/storage'
@@ -134,6 +136,8 @@ export * from './types/one-time-password-token-request'
134136
export * from './types/subscriptions'
135137
export * from './types/rule-promotions'
136138
export * from './types/subscription-subscribers'
139+
export * from './types/subscription-jobs'
140+
export * from './types/subscription-schedules'
137141

138142
// UMD
139143
export as namespace moltin
@@ -197,6 +201,8 @@ export class Moltin {
197201
Subscriptions: SubscriptionsEndpoint
198202
RulePromotions : RulePromotionsEndpoint
199203
SubscriptionSubscribers : SubscriptionSubscribersEndpoint
204+
SubscriptionJobs : SubscriptionJobsEndpoint
205+
SubscriptionSchedules: SubscriptionSchedulesEndpoint
200206

201207
Cart(id?: string): CartEndpoint // This optional cart id is super worrying when using the SDK in a node server :/
202208
constructor(config: Config)

src/moltin.js

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import SubscriptionOfferingsEndpoint from './endpoints/subscription-offerings'
5454
import SubscriptionsEndpoint from './endpoints/subscriptions'
5555
import RulePromotionsEndpoint from './endpoints/rule-promotions'
5656
import SubscriptionSubscribersEndpoint from './endpoints/subscription-subscribers'
57+
import SubscriptionJobsEndpoint from './endpoints/subscription-jobs'
58+
import SubscriptionSchedulesEndpoint from './endpoints/subscription-schedules'
5759

5860
import {cartIdentifier, tokenInvalid, getCredentials, resolveCredentialsStorageKey} from './utils/helpers'
5961
import CatalogsEndpoint from './endpoints/catalogs'
@@ -126,6 +128,8 @@ export default class Moltin {
126128
this.Subscriptions = new SubscriptionsEndpoint(config)
127129
this.RulePromotions = new RulePromotionsEndpoint(config)
128130
this.SubscriptionSubscribers = new SubscriptionSubscribersEndpoint(config)
131+
this.SubscriptionJobs = new SubscriptionJobsEndpoint(config)
132+
this.SubscriptionSchedules = new SubscriptionSchedulesEndpoint(config)
129133
}
130134

131135
// Expose `Cart` class on Moltin class

src/types/subscription-jobs.d.ts

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
}

src/types/subscription-schedules.d.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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,
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+
attributes: SubscriptionScheduleBase['attributes'] & {
32+
updated_at: string
33+
created_at: string
34+
}
35+
meta: {
36+
scheduled_for: string,
37+
owner: 'store' | 'organization',
38+
timestamps: {
39+
updated_at: string,
40+
created_at: string,
41+
}
42+
}
43+
}
44+
45+
export type SubscriptionScheduleCreate = SubscriptionScheduleBase
46+
export type SubscriptionScheduleUpdate = Omit<SubscriptionSchedule, 'attributes'> & {attributes: Partial<SubscriptionSchedule['attributes']>}
47+
48+
/**
49+
* Subscription Schedule Endpoints
50+
* DOCS: TODO: add docs when ready
51+
*/
52+
export interface SubscriptionSchedulesEndpoint
53+
extends CrudQueryableResource<
54+
SubscriptionSchedule,
55+
SubscriptionScheduleCreate,
56+
SubscriptionScheduleUpdate,
57+
never,
58+
never,
59+
never
60+
> {
61+
endpoint: 'schedules'
62+
}

0 commit comments

Comments
 (0)