@qelos/sdk 3.11.7 → 3.11.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/administrator/index.d.ts +2 -0
- package/dist/administrator/index.js +3 -0
- package/dist/administrator/index.js.map +1 -1
- package/dist/administrator/payments.d.ts +34 -0
- package/dist/administrator/payments.js +78 -0
- package/dist/administrator/payments.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/payments.d.ts +33 -0
- package/dist/payments.js +42 -0
- package/dist/payments.js.map +1 -0
- package/package.json +2 -2
- package/src/administrator/index.ts +3 -0
- package/src/administrator/payments.ts +111 -0
- package/src/index.ts +3 -0
- package/src/payments.ts +78 -0
|
@@ -12,6 +12,7 @@ import QlManagePlugins from './manage-plugins';
|
|
|
12
12
|
import QlComponents from './components';
|
|
13
13
|
import QlIntegrations from './integrations';
|
|
14
14
|
import QlManageLambdas from './admin-lambdas';
|
|
15
|
+
import QlPaymentsAdmin from './payments';
|
|
15
16
|
export default class QelosAdministratorSDK<T = any> extends QelosSDK {
|
|
16
17
|
manageLambdas: QlManageLambdas;
|
|
17
18
|
users: QlUsers<T>;
|
|
@@ -25,6 +26,7 @@ export default class QelosAdministratorSDK<T = any> extends QelosSDK {
|
|
|
25
26
|
managePlugins: QlManagePlugins;
|
|
26
27
|
components: QlComponents;
|
|
27
28
|
integrations: QlIntegrations;
|
|
29
|
+
managePayments: QlPaymentsAdmin;
|
|
28
30
|
constructor(options: QelosSDKOptions);
|
|
29
31
|
impersonateUser(userId: string, workspaceId?: string): void;
|
|
30
32
|
clearImpersonation(): void;
|
|
@@ -11,6 +11,7 @@ import QlManagePlugins from './manage-plugins';
|
|
|
11
11
|
import QlComponents from './components';
|
|
12
12
|
import QlIntegrations from './integrations';
|
|
13
13
|
import QlManageLambdas from './admin-lambdas';
|
|
14
|
+
import QlPaymentsAdmin from './payments';
|
|
14
15
|
export default class QelosAdministratorSDK extends QelosSDK {
|
|
15
16
|
manageLambdas;
|
|
16
17
|
users;
|
|
@@ -24,6 +25,7 @@ export default class QelosAdministratorSDK extends QelosSDK {
|
|
|
24
25
|
managePlugins;
|
|
25
26
|
components;
|
|
26
27
|
integrations;
|
|
28
|
+
managePayments;
|
|
27
29
|
constructor(options) {
|
|
28
30
|
super(options);
|
|
29
31
|
this.manageLambdas = new QlManageLambdas(options);
|
|
@@ -38,6 +40,7 @@ export default class QelosAdministratorSDK extends QelosSDK {
|
|
|
38
40
|
this.managePlugins = new QlManagePlugins(options);
|
|
39
41
|
this.components = new QlComponents(options);
|
|
40
42
|
this.integrations = new QlIntegrations(options);
|
|
43
|
+
this.managePayments = new QlPaymentsAdmin(options);
|
|
41
44
|
if (!options.extraQueryParams) {
|
|
42
45
|
options.extraQueryParams = () => ({
|
|
43
46
|
bypassAdmin: 'true'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/administrator/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,sBAAsB,MAAM,yBAAyB,CAAC;AAC7D,OAAO,iBAAiB,MAAM,cAAc,CAAC;AAC7C,OAAO,kBAAkB,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,oBAAoB,MAAM,uBAAuB,CAAC;AACzD,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,cAAc,MAAM,gBAAgB,CAAC;AAC5C,OAAO,eAAe,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/administrator/index.ts"],"names":[],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AI,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;QAClC,IAAI,CAAC,kBAAkB,GAAG,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC5D,IAAI,CAAC,aAAa,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,YAAY,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QAEnD,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE;YAC7B,OAAO,CAAC,gBAAgB,GAAG,GAAG,EAAE,CAAC,CAAC;gBAChC,WAAW,EAAE,MAAM;aACpB,CAAC,CAAA;SACH;IACH,CAAC;IAED,eAAe,CAAC,MAAc,EAAE,WAAoB;QAClD,IAAI,CAAC,eAAe,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;QACnD,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,eAAe,CAAC,yBAAyB,EAAE,WAAW,CAAC,CAAC;SAC9D;IACH,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAC;QAC9C,IAAI,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { QelosSDKOptions } from '../types';
|
|
2
|
+
import BaseSDK from '../base-sdk';
|
|
3
|
+
import { IPlan, ISubscription, IInvoice, ICoupon, BillableEntityType, SubscriptionStatus, InvoiceStatus } from '@qelos/global-types';
|
|
4
|
+
export default class QlPaymentsAdmin extends BaseSDK {
|
|
5
|
+
private options;
|
|
6
|
+
constructor(options: QelosSDKOptions);
|
|
7
|
+
getPlans(query?: {
|
|
8
|
+
isActive?: boolean;
|
|
9
|
+
}): Promise<IPlan[]>;
|
|
10
|
+
getPlan(planId: string): Promise<IPlan>;
|
|
11
|
+
createPlan(data: Omit<IPlan, '_id' | 'tenant' | 'created'>): Promise<IPlan>;
|
|
12
|
+
updatePlan(planId: string, data: Partial<IPlan>): Promise<IPlan>;
|
|
13
|
+
deletePlan(planId: string): Promise<IPlan>;
|
|
14
|
+
getSubscriptions(query?: {
|
|
15
|
+
billableEntityType?: BillableEntityType;
|
|
16
|
+
billableEntityId?: string;
|
|
17
|
+
status?: SubscriptionStatus;
|
|
18
|
+
}): Promise<ISubscription[]>;
|
|
19
|
+
getSubscription(subscriptionId: string): Promise<ISubscription>;
|
|
20
|
+
cancelSubscription(subscriptionId: string): Promise<ISubscription>;
|
|
21
|
+
getInvoices(query?: {
|
|
22
|
+
billableEntityType?: BillableEntityType;
|
|
23
|
+
billableEntityId?: string;
|
|
24
|
+
status?: InvoiceStatus;
|
|
25
|
+
}): Promise<IInvoice[]>;
|
|
26
|
+
getInvoice(invoiceId: string): Promise<IInvoice>;
|
|
27
|
+
getCoupons(query?: {
|
|
28
|
+
isActive?: boolean;
|
|
29
|
+
}): Promise<ICoupon[]>;
|
|
30
|
+
getCoupon(couponId: string): Promise<ICoupon>;
|
|
31
|
+
createCoupon(data: Omit<ICoupon, '_id' | 'tenant' | 'created' | 'currentRedemptions'>): Promise<ICoupon>;
|
|
32
|
+
updateCoupon(couponId: string, data: Partial<ICoupon>): Promise<ICoupon>;
|
|
33
|
+
deleteCoupon(couponId: string): Promise<ICoupon>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import BaseSDK from '../base-sdk';
|
|
2
|
+
export default class QlPaymentsAdmin extends BaseSDK {
|
|
3
|
+
options;
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super(options);
|
|
6
|
+
this.options = options;
|
|
7
|
+
}
|
|
8
|
+
// --- Plans ---
|
|
9
|
+
getPlans(query) {
|
|
10
|
+
const qs = query ? `?${new URLSearchParams(query)}` : '';
|
|
11
|
+
return this.callJsonApi(`/api/plans${qs}`);
|
|
12
|
+
}
|
|
13
|
+
getPlan(planId) {
|
|
14
|
+
return this.callJsonApi(`/api/plans/${planId}`);
|
|
15
|
+
}
|
|
16
|
+
createPlan(data) {
|
|
17
|
+
return this.callJsonApi('/api/plans', {
|
|
18
|
+
method: 'post',
|
|
19
|
+
headers: { 'content-type': 'application/json' },
|
|
20
|
+
body: JSON.stringify(data),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
updatePlan(planId, data) {
|
|
24
|
+
return this.callJsonApi(`/api/plans/${planId}`, {
|
|
25
|
+
method: 'put',
|
|
26
|
+
headers: { 'content-type': 'application/json' },
|
|
27
|
+
body: JSON.stringify(data),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
deletePlan(planId) {
|
|
31
|
+
return this.callJsonApi(`/api/plans/${planId}`, { method: 'delete' });
|
|
32
|
+
}
|
|
33
|
+
// --- Subscriptions ---
|
|
34
|
+
getSubscriptions(query) {
|
|
35
|
+
const qs = query ? `?${new URLSearchParams(query)}` : '';
|
|
36
|
+
return this.callJsonApi(`/api/subscriptions${qs}`);
|
|
37
|
+
}
|
|
38
|
+
getSubscription(subscriptionId) {
|
|
39
|
+
return this.callJsonApi(`/api/subscriptions/${subscriptionId}`);
|
|
40
|
+
}
|
|
41
|
+
cancelSubscription(subscriptionId) {
|
|
42
|
+
return this.callJsonApi(`/api/subscriptions/${subscriptionId}/cancel`, { method: 'put' });
|
|
43
|
+
}
|
|
44
|
+
// --- Invoices ---
|
|
45
|
+
getInvoices(query) {
|
|
46
|
+
const qs = query ? `?${new URLSearchParams(query)}` : '';
|
|
47
|
+
return this.callJsonApi(`/api/invoices${qs}`);
|
|
48
|
+
}
|
|
49
|
+
getInvoice(invoiceId) {
|
|
50
|
+
return this.callJsonApi(`/api/invoices/${invoiceId}`);
|
|
51
|
+
}
|
|
52
|
+
// --- Coupons ---
|
|
53
|
+
getCoupons(query) {
|
|
54
|
+
const qs = query ? `?${new URLSearchParams(query)}` : '';
|
|
55
|
+
return this.callJsonApi(`/api/coupons${qs}`);
|
|
56
|
+
}
|
|
57
|
+
getCoupon(couponId) {
|
|
58
|
+
return this.callJsonApi(`/api/coupons/${couponId}`);
|
|
59
|
+
}
|
|
60
|
+
createCoupon(data) {
|
|
61
|
+
return this.callJsonApi('/api/coupons', {
|
|
62
|
+
method: 'post',
|
|
63
|
+
headers: { 'content-type': 'application/json' },
|
|
64
|
+
body: JSON.stringify(data),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
updateCoupon(couponId, data) {
|
|
68
|
+
return this.callJsonApi(`/api/coupons/${couponId}`, {
|
|
69
|
+
method: 'put',
|
|
70
|
+
headers: { 'content-type': 'application/json' },
|
|
71
|
+
body: JSON.stringify(data),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
deleteCoupon(couponId) {
|
|
75
|
+
return this.callJsonApi(`/api/coupons/${couponId}`, { method: 'delete' });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sourceRoot":"","sources":["../../src/administrator/payments.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,aAAa,CAAC;AAMlC,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAC9B;IAApB,YAAoB,OAAwB;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QADG,YAAO,GAAP,OAAO,CAAiB;IAE5C,CAAC;IAED,gBAAgB;IAEhB,QAAQ,CAAC,KAA8B;QACrC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,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E,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAC,QAAgB;QAC3B,OAAO,IAAI,CAAC,WAAW,CAAU,gBAAgB,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrF,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import QlInvites from './invites';
|
|
|
8
8
|
import QlBlueprints from './blueprints';
|
|
9
9
|
import QlAI from './ai';
|
|
10
10
|
import QlLambdas from './lambdas';
|
|
11
|
+
import QlPayments from './payments';
|
|
11
12
|
export default class QelosSDK extends BaseSDK {
|
|
12
13
|
#private;
|
|
13
14
|
private options;
|
|
@@ -19,6 +20,7 @@ export default class QelosSDK extends BaseSDK {
|
|
|
19
20
|
blueprints: QlBlueprints;
|
|
20
21
|
ai: QlAI;
|
|
21
22
|
lambdas: QlLambdas;
|
|
23
|
+
payments: QlPayments;
|
|
22
24
|
constructor(options: QelosSDKOptions);
|
|
23
25
|
setCustomHeader(key: string, value: string): void;
|
|
24
26
|
removeCustomHeader(key: string): void;
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import QlInvites from './invites';
|
|
|
7
7
|
import QlBlueprints from './blueprints';
|
|
8
8
|
import QlAI from './ai';
|
|
9
9
|
import QlLambdas from './lambdas';
|
|
10
|
+
import QlPayments from './payments';
|
|
10
11
|
const noExtraHeadersUrls = new Set(['/api/token/refresh', '/api/signin', '/api/signup']);
|
|
11
12
|
export default class QelosSDK extends BaseSDK {
|
|
12
13
|
options;
|
|
@@ -19,6 +20,7 @@ export default class QelosSDK extends BaseSDK {
|
|
|
19
20
|
blueprints;
|
|
20
21
|
ai;
|
|
21
22
|
lambdas;
|
|
23
|
+
payments;
|
|
22
24
|
constructor(options) {
|
|
23
25
|
super(options);
|
|
24
26
|
this.options = options;
|
|
@@ -30,6 +32,7 @@ export default class QelosSDK extends BaseSDK {
|
|
|
30
32
|
this.blueprints = new QlBlueprints(this.options);
|
|
31
33
|
this.ai = new QlAI(this.options);
|
|
32
34
|
this.lambdas = new QlLambdas(this.options);
|
|
35
|
+
this.payments = new QlPayments(this.options);
|
|
33
36
|
const isBrowser = globalThis.navigator && globalThis.window && globalThis.document;
|
|
34
37
|
if (!options.getAccessToken) {
|
|
35
38
|
options.getAccessToken = () => this.authentication.accessToken;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,mBAAmB,MAAM,kBAAkB,CAAC;AACnD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,SAAS,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,mBAAmB,MAAM,kBAAkB,CAAC;AACnD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,gBAAgB,MAAM,kBAAkB,CAAC;AAChD,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,oBAA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K from './base-sdk';
|
|
3
|
+
import { IPlan, ISubscription, IInvoice, ICoupon, BillingCycle } from '@qelos/global-types';
|
|
4
|
+
export interface CheckoutRequest {
|
|
5
|
+
planId: string;
|
|
6
|
+
billingCycle: BillingCycle;
|
|
7
|
+
couponCode?: string;
|
|
8
|
+
successUrl?: string;
|
|
9
|
+
cancelUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CheckoutResponse {
|
|
12
|
+
subscriptionId: string;
|
|
13
|
+
checkoutUrl?: string;
|
|
14
|
+
clientToken?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ValidateCouponResponse extends ICoupon {
|
|
17
|
+
}
|
|
18
|
+
export default class QlPayments extends BaseSDK {
|
|
19
|
+
private relativePath;
|
|
20
|
+
constructor(options: QelosSDKOptions);
|
|
21
|
+
getPlans(query?: {
|
|
22
|
+
isActive?: boolean;
|
|
23
|
+
}): Promise<IPlan[]>;
|
|
24
|
+
getPlan(planId: string): Promise<IPlan>;
|
|
25
|
+
checkout(params: CheckoutRequest): Promise<CheckoutResponse>;
|
|
26
|
+
getMySubscription(): Promise<ISubscription>;
|
|
27
|
+
cancelSubscription(subscriptionId: string): Promise<ISubscription>;
|
|
28
|
+
getInvoices(query?: {
|
|
29
|
+
status?: string;
|
|
30
|
+
}): Promise<IInvoice[]>;
|
|
31
|
+
getInvoice(invoiceId: string): Promise<IInvoice>;
|
|
32
|
+
validateCoupon(code: string, planId?: string): Promise<ValidateCouponResponse>;
|
|
33
|
+
}
|
package/dist/payments.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import BaseSDK from './base-sdk';
|
|
2
|
+
export default class QlPayments extends BaseSDK {
|
|
3
|
+
relativePath = '/api';
|
|
4
|
+
constructor(options) {
|
|
5
|
+
super(options);
|
|
6
|
+
}
|
|
7
|
+
getPlans(query) {
|
|
8
|
+
const qs = query ? `?${new URLSearchParams(query)}` : '';
|
|
9
|
+
return this.callJsonApi(`${this.relativePath}/plans/public${qs}`);
|
|
10
|
+
}
|
|
11
|
+
getPlan(planId) {
|
|
12
|
+
return this.callJsonApi(`${this.relativePath}/plans/${planId}`);
|
|
13
|
+
}
|
|
14
|
+
checkout(params) {
|
|
15
|
+
return this.callJsonApi(`${this.relativePath}/checkout`, {
|
|
16
|
+
method: 'post',
|
|
17
|
+
headers: { 'content-type': 'application/json' },
|
|
18
|
+
body: JSON.stringify(params),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
getMySubscription() {
|
|
22
|
+
return this.callJsonApi(`${this.relativePath}/subscriptions/me`);
|
|
23
|
+
}
|
|
24
|
+
cancelSubscription(subscriptionId) {
|
|
25
|
+
return this.callJsonApi(`${this.relativePath}/subscriptions/${subscriptionId}/cancel`, { method: 'put' });
|
|
26
|
+
}
|
|
27
|
+
getInvoices(query) {
|
|
28
|
+
const qs = query ? `?${new URLSearchParams(query)}` : '';
|
|
29
|
+
return this.callJsonApi(`${this.relativePath}/invoices${qs}`);
|
|
30
|
+
}
|
|
31
|
+
getInvoice(invoiceId) {
|
|
32
|
+
return this.callJsonApi(`${this.relativePath}/invoices/${invoiceId}`);
|
|
33
|
+
}
|
|
34
|
+
validateCoupon(code, planId) {
|
|
35
|
+
return this.callJsonApi(`${this.relativePath}/coupons/validate`, {
|
|
36
|
+
method: 'post',
|
|
37
|
+
headers: { 'content-type': 'application/json' },
|
|
38
|
+
body: JSON.stringify({ code, planId }),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,YAAY,CAAC;AAmBjC,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,OAAO;IACrC,YAAY,GAAG,MAAM,CAAC;IAE9B,YAAY,OAAwB;QAClC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IA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C,YAAY,aAAa,SAAS,EAAE,CAAC,CAAC;IAClF,CAAC;IAED,cAAc,CAAC,IAAY,EAAE,MAAe;QAC1C,OAAO,IAAI,CAAC,WAAW,CACrB,GAAG,IAAI,CAAC,YAAY,mBAAmB,EACvC;YACE,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;SACvC,CACF,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qelos/sdk",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.9",
|
|
4
4
|
"description": "SDK for Qelos API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"access": "public"
|
|
103
103
|
},
|
|
104
104
|
"dependencies": {
|
|
105
|
-
"@qelos/global-types": "^3.11.
|
|
105
|
+
"@qelos/global-types": "^3.11.9"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
108
108
|
"tsx": "^4.21.0",
|
|
@@ -12,6 +12,7 @@ import QlManagePlugins from './manage-plugins';
|
|
|
12
12
|
import QlComponents from './components';
|
|
13
13
|
import QlIntegrations from './integrations';
|
|
14
14
|
import QlManageLambdas from './admin-lambdas';
|
|
15
|
+
import QlPaymentsAdmin from './payments';
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
export default class QelosAdministratorSDK<T = any> extends QelosSDK {
|
|
@@ -27,6 +28,7 @@ export default class QelosAdministratorSDK<T = any> extends QelosSDK {
|
|
|
27
28
|
managePlugins: QlManagePlugins;
|
|
28
29
|
components: QlComponents;
|
|
29
30
|
integrations: QlIntegrations;
|
|
31
|
+
managePayments: QlPaymentsAdmin;
|
|
30
32
|
|
|
31
33
|
constructor(options: QelosSDKOptions) {
|
|
32
34
|
super(options);
|
|
@@ -42,6 +44,7 @@ export default class QelosAdministratorSDK<T = any> extends QelosSDK {
|
|
|
42
44
|
this.managePlugins = new QlManagePlugins(options);
|
|
43
45
|
this.components = new QlComponents(options);
|
|
44
46
|
this.integrations = new QlIntegrations(options);
|
|
47
|
+
this.managePayments = new QlPaymentsAdmin(options);
|
|
45
48
|
|
|
46
49
|
if (!options.extraQueryParams) {
|
|
47
50
|
options.extraQueryParams = () => ({
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { QelosSDKOptions } from '../types';
|
|
2
|
+
import BaseSDK from '../base-sdk';
|
|
3
|
+
import {
|
|
4
|
+
IPlan, ISubscription, IInvoice, ICoupon,
|
|
5
|
+
BillableEntityType, SubscriptionStatus, InvoiceStatus,
|
|
6
|
+
} from '@qelos/global-types';
|
|
7
|
+
|
|
8
|
+
export default class QlPaymentsAdmin extends BaseSDK {
|
|
9
|
+
constructor(private options: QelosSDKOptions) {
|
|
10
|
+
super(options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// --- Plans ---
|
|
14
|
+
|
|
15
|
+
getPlans(query?: { isActive?: boolean }) {
|
|
16
|
+
const qs = query ? `?${new URLSearchParams(query as any)}` : '';
|
|
17
|
+
return this.callJsonApi<IPlan[]>(`/api/plans${qs}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getPlan(planId: string) {
|
|
21
|
+
return this.callJsonApi<IPlan>(`/api/plans/${planId}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
createPlan(data: Omit<IPlan, '_id' | 'tenant' | 'created'>) {
|
|
25
|
+
return this.callJsonApi<IPlan>('/api/plans', {
|
|
26
|
+
method: 'post',
|
|
27
|
+
headers: { 'content-type': 'application/json' },
|
|
28
|
+
body: JSON.stringify(data),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
updatePlan(planId: string, data: Partial<IPlan>) {
|
|
33
|
+
return this.callJsonApi<IPlan>(`/api/plans/${planId}`, {
|
|
34
|
+
method: 'put',
|
|
35
|
+
headers: { 'content-type': 'application/json' },
|
|
36
|
+
body: JSON.stringify(data),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
deletePlan(planId: string) {
|
|
41
|
+
return this.callJsonApi<IPlan>(`/api/plans/${planId}`, { method: 'delete' });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// --- Subscriptions ---
|
|
45
|
+
|
|
46
|
+
getSubscriptions(query?: {
|
|
47
|
+
billableEntityType?: BillableEntityType;
|
|
48
|
+
billableEntityId?: string;
|
|
49
|
+
status?: SubscriptionStatus;
|
|
50
|
+
}) {
|
|
51
|
+
const qs = query ? `?${new URLSearchParams(query as any)}` : '';
|
|
52
|
+
return this.callJsonApi<ISubscription[]>(`/api/subscriptions${qs}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getSubscription(subscriptionId: string) {
|
|
56
|
+
return this.callJsonApi<ISubscription>(`/api/subscriptions/${subscriptionId}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
cancelSubscription(subscriptionId: string) {
|
|
60
|
+
return this.callJsonApi<ISubscription>(
|
|
61
|
+
`/api/subscriptions/${subscriptionId}/cancel`,
|
|
62
|
+
{ method: 'put' },
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// --- Invoices ---
|
|
67
|
+
|
|
68
|
+
getInvoices(query?: {
|
|
69
|
+
billableEntityType?: BillableEntityType;
|
|
70
|
+
billableEntityId?: string;
|
|
71
|
+
status?: InvoiceStatus;
|
|
72
|
+
}) {
|
|
73
|
+
const qs = query ? `?${new URLSearchParams(query as any)}` : '';
|
|
74
|
+
return this.callJsonApi<IInvoice[]>(`/api/invoices${qs}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getInvoice(invoiceId: string) {
|
|
78
|
+
return this.callJsonApi<IInvoice>(`/api/invoices/${invoiceId}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// --- Coupons ---
|
|
82
|
+
|
|
83
|
+
getCoupons(query?: { isActive?: boolean }) {
|
|
84
|
+
const qs = query ? `?${new URLSearchParams(query as any)}` : '';
|
|
85
|
+
return this.callJsonApi<ICoupon[]>(`/api/coupons${qs}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getCoupon(couponId: string) {
|
|
89
|
+
return this.callJsonApi<ICoupon>(`/api/coupons/${couponId}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
createCoupon(data: Omit<ICoupon, '_id' | 'tenant' | 'created' | 'currentRedemptions'>) {
|
|
93
|
+
return this.callJsonApi<ICoupon>('/api/coupons', {
|
|
94
|
+
method: 'post',
|
|
95
|
+
headers: { 'content-type': 'application/json' },
|
|
96
|
+
body: JSON.stringify(data),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
updateCoupon(couponId: string, data: Partial<ICoupon>) {
|
|
101
|
+
return this.callJsonApi<ICoupon>(`/api/coupons/${couponId}`, {
|
|
102
|
+
method: 'put',
|
|
103
|
+
headers: { 'content-type': 'application/json' },
|
|
104
|
+
body: JSON.stringify(data),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
deleteCoupon(couponId: string) {
|
|
109
|
+
return this.callJsonApi<ICoupon>(`/api/coupons/${couponId}`, { method: 'delete' });
|
|
110
|
+
}
|
|
111
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import QlInvites from './invites';
|
|
|
8
8
|
import QlBlueprints from './blueprints';
|
|
9
9
|
import QlAI from './ai';
|
|
10
10
|
import QlLambdas from './lambdas';
|
|
11
|
+
import QlPayments from './payments';
|
|
11
12
|
|
|
12
13
|
const noExtraHeadersUrls = new Set(['/api/token/refresh', '/api/signin', '/api/signup'])
|
|
13
14
|
|
|
@@ -22,6 +23,7 @@ export default class QelosSDK extends BaseSDK {
|
|
|
22
23
|
blueprints: QlBlueprints;
|
|
23
24
|
ai: QlAI;
|
|
24
25
|
lambdas: QlLambdas;
|
|
26
|
+
payments: QlPayments;
|
|
25
27
|
|
|
26
28
|
constructor(private options: QelosSDKOptions) {
|
|
27
29
|
super(options);
|
|
@@ -33,6 +35,7 @@ export default class QelosSDK extends BaseSDK {
|
|
|
33
35
|
this.blueprints = new QlBlueprints(this.options);
|
|
34
36
|
this.ai = new QlAI(this.options);
|
|
35
37
|
this.lambdas = new QlLambdas(this.options);
|
|
38
|
+
this.payments = new QlPayments(this.options);
|
|
36
39
|
|
|
37
40
|
const isBrowser = globalThis.navigator && globalThis.window && globalThis.document
|
|
38
41
|
|
package/src/payments.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { QelosSDKOptions } from './types';
|
|
2
|
+
import BaseSDK from './base-sdk';
|
|
3
|
+
import { IPlan, ISubscription, IInvoice, ICoupon, BillingCycle } from '@qelos/global-types';
|
|
4
|
+
|
|
5
|
+
export interface CheckoutRequest {
|
|
6
|
+
planId: string;
|
|
7
|
+
billingCycle: BillingCycle;
|
|
8
|
+
couponCode?: string;
|
|
9
|
+
successUrl?: string;
|
|
10
|
+
cancelUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface CheckoutResponse {
|
|
14
|
+
subscriptionId: string;
|
|
15
|
+
checkoutUrl?: string;
|
|
16
|
+
clientToken?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ValidateCouponResponse extends ICoupon {}
|
|
20
|
+
|
|
21
|
+
export default class QlPayments extends BaseSDK {
|
|
22
|
+
private relativePath = '/api';
|
|
23
|
+
|
|
24
|
+
constructor(options: QelosSDKOptions) {
|
|
25
|
+
super(options);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getPlans(query?: { isActive?: boolean }) {
|
|
29
|
+
const qs = query ? `?${new URLSearchParams(query as any)}` : '';
|
|
30
|
+
return this.callJsonApi<IPlan[]>(`${this.relativePath}/plans/public${qs}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getPlan(planId: string) {
|
|
34
|
+
return this.callJsonApi<IPlan>(`${this.relativePath}/plans/${planId}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
checkout(params: CheckoutRequest) {
|
|
38
|
+
return this.callJsonApi<CheckoutResponse>(
|
|
39
|
+
`${this.relativePath}/checkout`,
|
|
40
|
+
{
|
|
41
|
+
method: 'post',
|
|
42
|
+
headers: { 'content-type': 'application/json' },
|
|
43
|
+
body: JSON.stringify(params),
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getMySubscription() {
|
|
49
|
+
return this.callJsonApi<ISubscription>(`${this.relativePath}/subscriptions/me`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cancelSubscription(subscriptionId: string) {
|
|
53
|
+
return this.callJsonApi<ISubscription>(
|
|
54
|
+
`${this.relativePath}/subscriptions/${subscriptionId}/cancel`,
|
|
55
|
+
{ method: 'put' },
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getInvoices(query?: { status?: string }) {
|
|
60
|
+
const qs = query ? `?${new URLSearchParams(query as any)}` : '';
|
|
61
|
+
return this.callJsonApi<IInvoice[]>(`${this.relativePath}/invoices${qs}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getInvoice(invoiceId: string) {
|
|
65
|
+
return this.callJsonApi<IInvoice>(`${this.relativePath}/invoices/${invoiceId}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
validateCoupon(code: string, planId?: string) {
|
|
69
|
+
return this.callJsonApi<ValidateCouponResponse>(
|
|
70
|
+
`${this.relativePath}/coupons/validate`,
|
|
71
|
+
{
|
|
72
|
+
method: 'post',
|
|
73
|
+
headers: { 'content-type': 'application/json' },
|
|
74
|
+
body: JSON.stringify({ code, planId }),
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|