ppussh 0.1.1 → 0.2.0
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/client.d.ts +6 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +6 -2
- package/dist/client.js.map +1 -1
- package/dist/payments/namespace.d.ts +37 -15
- package/dist/payments/namespace.d.ts.map +1 -1
- package/dist/payments/namespace.js +92 -26
- package/dist/payments/namespace.js.map +1 -1
- package/dist/payments/types.d.ts +28 -0
- package/dist/payments/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -35,10 +35,11 @@ export interface PpusshClientOptions {
|
|
|
35
35
|
/** Your product's client_secret. Server-side only — never expose in browser code. */
|
|
36
36
|
clientSecret: string;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* Product API key for Payments service.
|
|
39
|
+
* Used for customer and subscription operations.
|
|
40
|
+
* Get this from the Payments section in the Accounts admin console.
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
paymentsProductKey?: string;
|
|
42
43
|
/**
|
|
43
44
|
* Accounts service base URL. Falls back to the PPUSSH_ACCOUNTS_URL env var.
|
|
44
45
|
* Required — one of the two must be set.
|
|
@@ -66,6 +67,8 @@ export declare class PpusshClient {
|
|
|
66
67
|
constructor(options: PpusshClientOptions);
|
|
67
68
|
/** Resolved Accounts service base URL. */
|
|
68
69
|
get accountsUrl(): string;
|
|
70
|
+
/** Resolved Accounts frontend service base URL. */
|
|
71
|
+
get accountsFrontendUrl(): string;
|
|
69
72
|
/** Resolved Payments service base URL. */
|
|
70
73
|
get paymentsUrl(): string;
|
|
71
74
|
toString(): string;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;A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,mBAAmB,IAAI,MAAM,CAEhC;IAED,0CAA0C;IAC1C,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,QAAQ,IAAI,MAAM;CAGnB"}
|
package/dist/client.js
CHANGED
|
@@ -65,19 +65,23 @@ class PpusshClient {
|
|
|
65
65
|
accountsFrontendUrl: this._accountsFrontendUrl
|
|
66
66
|
});
|
|
67
67
|
this.payments = new namespace_2.PaymentsNamespace(this._paymentsTransport, {
|
|
68
|
-
|
|
68
|
+
productKey: options.paymentsProductKey,
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
/** Resolved Accounts service base URL. */
|
|
72
72
|
get accountsUrl() {
|
|
73
73
|
return this._accountsUrl;
|
|
74
74
|
}
|
|
75
|
+
/** Resolved Accounts frontend service base URL. */
|
|
76
|
+
get accountsFrontendUrl() {
|
|
77
|
+
return this._accountsFrontendUrl;
|
|
78
|
+
}
|
|
75
79
|
/** Resolved Payments service base URL. */
|
|
76
80
|
get paymentsUrl() {
|
|
77
81
|
return this._paymentsUrl;
|
|
78
82
|
}
|
|
79
83
|
toString() {
|
|
80
|
-
return `PpusshClient(accountsUrl=${this._accountsUrl}, paymentsUrl=${this._paymentsUrl})`;
|
|
84
|
+
return `PpusshClient(accountsUrl=${this._accountsUrl}, accountsFrontendUrl=${this._accountsFrontendUrl}, paymentsUrl=${this._paymentsUrl})`;
|
|
81
85
|
}
|
|
82
86
|
}
|
|
83
87
|
exports.PpusshClient = PpusshClient;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA,uBAAuB;AACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAEH,oDAAyD;AACzD,iCAAuC;AACvC,oDAAyD;AAEzD,gFAAgF;AAChF,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAC/C,MAAM,yBAAyB,GAAG,8BAA8B,CAAC;AACjE,MAAM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mBAAmB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAED,0CAA0C;IAC1C,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,4BAA4B,IAAI,CAAC,YAAY,yBAAyB,IAAI,CAAC,oBAAoB,iBAAiB,IAAI,CAAC,YAAY,GAAG,CAAC;IAC9I,CAAC;CACF;AAlDD,oCAkDC"}
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
* PaymentsNamespace — customer, subscription, and plan operations.
|
|
3
3
|
*
|
|
4
4
|
* Auth model:
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - Admin endpoints (listPlans, getMrr) require the payments ADMIN_API_KEY
|
|
9
|
-
* sent as the `X-Admin-Key` header. Set once at PpusshClient construction
|
|
10
|
-
* time via `paymentsAdminKey`.
|
|
5
|
+
* - All endpoints accept either X-Admin-Key or X-Product-Key header.
|
|
6
|
+
* - Product API key is scoped to a specific product.
|
|
7
|
+
* - Get the product key from the Payments section in the Accounts admin console.
|
|
11
8
|
*
|
|
12
9
|
* Idempotency:
|
|
13
10
|
* - createSubscription() requires a caller-supplied idempotencyKey.
|
|
@@ -15,12 +12,12 @@
|
|
|
15
12
|
* - createCustomer() is idempotent on (owner_user_id, workspace_id) — no key needed.
|
|
16
13
|
*/
|
|
17
14
|
import { HttpTransport } from "../http";
|
|
18
|
-
import { CustomerResponse, MRRResponse, PaymentProductResponse, PlanResponse, SubscriptionListResponse, SubscriptionResponse } from "./types";
|
|
15
|
+
import { AccessResult, CustomerResponse, MRRResponse, PaymentProductResponse, PlanResponse, SubscriptionListResponse, SubscriptionResponse } from "./types";
|
|
19
16
|
export declare class PaymentsNamespace {
|
|
20
17
|
private readonly _http;
|
|
21
|
-
private readonly
|
|
18
|
+
private readonly _productKey;
|
|
22
19
|
constructor(transport: HttpTransport, options?: {
|
|
23
|
-
|
|
20
|
+
productKey?: string | null;
|
|
24
21
|
});
|
|
25
22
|
/**
|
|
26
23
|
* Create (or retrieve) a Payments customer for a PPUSSH user.
|
|
@@ -56,6 +53,7 @@ export declare class PaymentsNamespace {
|
|
|
56
53
|
* @param planKey Plan identifier, e.g. "pro" or "enterprise".
|
|
57
54
|
* @param idempotencyKey Unique string per subscription attempt (use UUID v4).
|
|
58
55
|
* @param provider "paddle" | "dodo" | null (uses plan default).
|
|
56
|
+
* @param returnUrl URL to redirect after checkout completes (provider redirects here).
|
|
59
57
|
* @param metadata Arbitrary key/value pairs.
|
|
60
58
|
* @throws PpusshPaymentError Various codes; see error.code for specifics.
|
|
61
59
|
*/
|
|
@@ -65,6 +63,7 @@ export declare class PaymentsNamespace {
|
|
|
65
63
|
planKey: string;
|
|
66
64
|
idempotencyKey: string;
|
|
67
65
|
provider?: string | null;
|
|
66
|
+
returnUrl?: string | null;
|
|
68
67
|
metadata?: Record<string, unknown> | null;
|
|
69
68
|
}): Promise<SubscriptionResponse>;
|
|
70
69
|
/**
|
|
@@ -99,15 +98,22 @@ export declare class PaymentsNamespace {
|
|
|
99
98
|
cancelSubscription(subscriptionId: string, options?: {
|
|
100
99
|
cancelImmediately?: boolean;
|
|
101
100
|
}): Promise<SubscriptionResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* Check if a customer has an active subscription.
|
|
103
|
+
*
|
|
104
|
+
* @param customerId UUID string of the customer.
|
|
105
|
+
* @returns true if customer has an active subscription, false otherwise.
|
|
106
|
+
*/
|
|
107
|
+
hasActiveSubscription(customerId: string): Promise<boolean>;
|
|
102
108
|
/**
|
|
103
109
|
* List all billing plans for a Payments product.
|
|
104
110
|
*
|
|
105
|
-
* Requires the
|
|
106
|
-
*
|
|
111
|
+
* Requires the product key to be set on PpusshClient construction.
|
|
112
|
+
* The key must be authorized for the product.
|
|
107
113
|
*
|
|
108
114
|
* @param paymentProductId UUID string of the PaymentProduct.
|
|
109
115
|
* @throws PpusshPaymentError code="product_not_found" on 404.
|
|
110
|
-
* @throws Error If no
|
|
116
|
+
* @throws Error If no productKey was provided at construction.
|
|
111
117
|
*/
|
|
112
118
|
listPlans(paymentProductId: string): Promise<PlanResponse[]>;
|
|
113
119
|
/**
|
|
@@ -116,13 +122,28 @@ export declare class PaymentsNamespace {
|
|
|
116
122
|
* Returns null if the product has not yet been registered in Payments
|
|
117
123
|
* (HTTP 404 is treated as a non-exceptional "not registered yet" state).
|
|
118
124
|
*
|
|
119
|
-
* @throws Error If no
|
|
125
|
+
* @throws Error If no productKey was provided at construction.
|
|
120
126
|
*/
|
|
121
127
|
getProductByAccountsId(accountsProductId: string): Promise<PaymentProductResponse | null>;
|
|
128
|
+
/**
|
|
129
|
+
* Check whether a user has access to a specific feature based on their
|
|
130
|
+
* active subscription's plan.
|
|
131
|
+
*
|
|
132
|
+
* Requires the product key to be set on PpusshClient construction.
|
|
133
|
+
*
|
|
134
|
+
* @param userId UUID string of the Accounts user.
|
|
135
|
+
* @param featureCode Feature code defined on the plan, e.g. "premium_nodes".
|
|
136
|
+
* @param workspaceId Optional workspace UUID — required for workspace-scoped billing.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* const access = await ppussh.payments.checkAccess(user.id, "premium_nodes");
|
|
140
|
+
* if (!access.hasAccess) throw new Error("Upgrade required");
|
|
141
|
+
*/
|
|
142
|
+
checkAccess(userId: string, featureCode: string, workspaceId?: string): Promise<AccessResult>;
|
|
122
143
|
/**
|
|
123
144
|
* Fetch Monthly Recurring Revenue breakdown.
|
|
124
145
|
*
|
|
125
|
-
* Requires
|
|
146
|
+
* Requires admin key.
|
|
126
147
|
*
|
|
127
148
|
* @param productId Filter to a specific product UUID (optional).
|
|
128
149
|
* @param startDate ISO date string e.g. "2025-01-01" (optional).
|
|
@@ -141,6 +162,7 @@ export declare class PaymentsNamespace {
|
|
|
141
162
|
getBillingPortal(_customerId: string, _options?: {
|
|
142
163
|
returnUrl?: string;
|
|
143
164
|
}): Promise<string>;
|
|
144
|
-
private
|
|
165
|
+
private _getAuthHeaders;
|
|
166
|
+
private _requireProductKey;
|
|
145
167
|
}
|
|
146
168
|
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/payments/namespace.ts"],"names":[],"mappings":"AACA
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../src/payments/namespace.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EACL,YAAY,EAEZ,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,YAAY,EACZ,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAEjB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAgB;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;gBAEhC,SAAS,EAAE,aAAa,EAAE,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAO;IAOlF;;;;;;;;;;;OAWG;IACG,cAAc,CAClB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;QACP,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;KACtC,GACL,OAAO,CAAC,gBAAgB,CAAC;IAe5B;;;;OAIG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUhE;;;;;;;;;;;;;;OAcG;IACG,kBAAkB,CAAC,OAAO,EAAE;QAChC,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,EAAE,MAAM,CAAC;QACzB,OAAO,EAAE,MAAM,CAA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nB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KACb,GAAG,OAAO,CAAC,WAAW,CAAC;IAiB7B;;;;OAIG;IACG,gBAAgB,CACpB,WAAW,EAAE,MAAM,EACnB,QAAQ,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACpC,OAAO,CAAC,MAAM,CAAC;IASlB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,kBAAkB;CAQ3B"}
|
|
@@ -4,12 +4,9 @@
|
|
|
4
4
|
* PaymentsNamespace — customer, subscription, and plan operations.
|
|
5
5
|
*
|
|
6
6
|
* Auth model:
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* - Admin endpoints (listPlans, getMrr) require the payments ADMIN_API_KEY
|
|
11
|
-
* sent as the `X-Admin-Key` header. Set once at PpusshClient construction
|
|
12
|
-
* time via `paymentsAdminKey`.
|
|
7
|
+
* - All endpoints accept either X-Admin-Key or X-Product-Key header.
|
|
8
|
+
* - Product API key is scoped to a specific product.
|
|
9
|
+
* - Get the product key from the Payments section in the Accounts admin console.
|
|
13
10
|
*
|
|
14
11
|
* Idempotency:
|
|
15
12
|
* - createSubscription() requires a caller-supplied idempotencyKey.
|
|
@@ -22,7 +19,7 @@ const errors_1 = require("../errors");
|
|
|
22
19
|
class PaymentsNamespace {
|
|
23
20
|
constructor(transport, options = {}) {
|
|
24
21
|
this._http = transport;
|
|
25
|
-
this.
|
|
22
|
+
this._productKey = options.productKey ?? null;
|
|
26
23
|
}
|
|
27
24
|
// ── Customers ──────────────────────────────────────────────────────────────
|
|
28
25
|
/**
|
|
@@ -46,6 +43,7 @@ class PaymentsNamespace {
|
|
|
46
43
|
};
|
|
47
44
|
const response = await this._http.request("POST", "/customers", {
|
|
48
45
|
json: body,
|
|
46
|
+
headers: this._getAuthHeaders(),
|
|
49
47
|
isPayments: true,
|
|
50
48
|
});
|
|
51
49
|
return response.data;
|
|
@@ -57,6 +55,7 @@ class PaymentsNamespace {
|
|
|
57
55
|
*/
|
|
58
56
|
async getCustomer(customerId) {
|
|
59
57
|
const response = await this._http.request("GET", `/customers/${customerId}`, {
|
|
58
|
+
headers: this._getAuthHeaders(),
|
|
60
59
|
isPayments: true,
|
|
61
60
|
});
|
|
62
61
|
return response.data;
|
|
@@ -73,6 +72,7 @@ class PaymentsNamespace {
|
|
|
73
72
|
* @param planKey Plan identifier, e.g. "pro" or "enterprise".
|
|
74
73
|
* @param idempotencyKey Unique string per subscription attempt (use UUID v4).
|
|
75
74
|
* @param provider "paddle" | "dodo" | null (uses plan default).
|
|
75
|
+
* @param returnUrl URL to redirect after checkout completes (provider redirects here).
|
|
76
76
|
* @param metadata Arbitrary key/value pairs.
|
|
77
77
|
* @throws PpusshPaymentError Various codes; see error.code for specifics.
|
|
78
78
|
*/
|
|
@@ -84,8 +84,10 @@ class PaymentsNamespace {
|
|
|
84
84
|
plan_key: options.planKey,
|
|
85
85
|
idempotency_key: options.idempotencyKey,
|
|
86
86
|
...(options.provider != null && { provider: options.provider }),
|
|
87
|
+
...(options.returnUrl != null && { return_url: options.returnUrl }),
|
|
87
88
|
...(options.metadata != null && { metadata: options.metadata }),
|
|
88
89
|
},
|
|
90
|
+
headers: this._getAuthHeaders(),
|
|
89
91
|
isPayments: true,
|
|
90
92
|
});
|
|
91
93
|
return response.data;
|
|
@@ -108,6 +110,7 @@ class PaymentsNamespace {
|
|
|
108
110
|
params["status"] = options.status;
|
|
109
111
|
const response = await this._http.request("GET", "/subscriptions", {
|
|
110
112
|
params,
|
|
113
|
+
headers: this._getAuthHeaders(),
|
|
111
114
|
isPayments: true,
|
|
112
115
|
});
|
|
113
116
|
return response.data;
|
|
@@ -118,7 +121,10 @@ class PaymentsNamespace {
|
|
|
118
121
|
* @throws PpusshPaymentError code="subscription_not_found" on 404.
|
|
119
122
|
*/
|
|
120
123
|
async getSubscription(subscriptionId) {
|
|
121
|
-
const response = await this._http.request("GET", `/subscriptions/${subscriptionId}`, {
|
|
124
|
+
const response = await this._http.request("GET", `/subscriptions/${subscriptionId}`, {
|
|
125
|
+
headers: this._getAuthHeaders(),
|
|
126
|
+
isPayments: true,
|
|
127
|
+
});
|
|
122
128
|
return response.data;
|
|
123
129
|
}
|
|
124
130
|
/**
|
|
@@ -134,25 +140,51 @@ class PaymentsNamespace {
|
|
|
134
140
|
async cancelSubscription(subscriptionId, options = {}) {
|
|
135
141
|
const response = await this._http.request("DELETE", `/subscriptions/${subscriptionId}`, {
|
|
136
142
|
json: { cancel_immediately: options.cancelImmediately ?? false },
|
|
143
|
+
headers: this._getAuthHeaders(),
|
|
137
144
|
isPayments: true,
|
|
138
145
|
});
|
|
139
146
|
return response.data;
|
|
140
147
|
}
|
|
141
|
-
// ──
|
|
148
|
+
// ── Helpers ─────────────────────────────────────────────────────────────
|
|
149
|
+
/**
|
|
150
|
+
* Check if a customer has an active subscription.
|
|
151
|
+
*
|
|
152
|
+
* @param customerId UUID string of the customer.
|
|
153
|
+
* @returns true if customer has an active subscription, false otherwise.
|
|
154
|
+
*/
|
|
155
|
+
async hasActiveSubscription(customerId) {
|
|
156
|
+
try {
|
|
157
|
+
const response = await this._http.request("GET", "/subscriptions", {
|
|
158
|
+
params: {
|
|
159
|
+
customer_id: customerId,
|
|
160
|
+
status: "active",
|
|
161
|
+
page_size: 1,
|
|
162
|
+
},
|
|
163
|
+
headers: this._getAuthHeaders(),
|
|
164
|
+
isPayments: true,
|
|
165
|
+
});
|
|
166
|
+
const data = response.data;
|
|
167
|
+
return data.total > 0;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// ── Plans (product-scoped) ────────────────────────────────────────────────
|
|
142
174
|
/**
|
|
143
175
|
* List all billing plans for a Payments product.
|
|
144
176
|
*
|
|
145
|
-
* Requires the
|
|
146
|
-
*
|
|
177
|
+
* Requires the product key to be set on PpusshClient construction.
|
|
178
|
+
* The key must be authorized for the product.
|
|
147
179
|
*
|
|
148
180
|
* @param paymentProductId UUID string of the PaymentProduct.
|
|
149
181
|
* @throws PpusshPaymentError code="product_not_found" on 404.
|
|
150
|
-
* @throws Error If no
|
|
182
|
+
* @throws Error If no productKey was provided at construction.
|
|
151
183
|
*/
|
|
152
184
|
async listPlans(paymentProductId) {
|
|
153
|
-
this.
|
|
154
|
-
const response = await this._http.request("GET", `/
|
|
155
|
-
headers: { "X-
|
|
185
|
+
this._requireProductKey("listPlans");
|
|
186
|
+
const response = await this._http.request("GET", `/products/${paymentProductId}/plans`, {
|
|
187
|
+
headers: { "X-Product-Key": this._productKey },
|
|
156
188
|
isPayments: true,
|
|
157
189
|
});
|
|
158
190
|
return response.data;
|
|
@@ -163,13 +195,13 @@ class PaymentsNamespace {
|
|
|
163
195
|
* Returns null if the product has not yet been registered in Payments
|
|
164
196
|
* (HTTP 404 is treated as a non-exceptional "not registered yet" state).
|
|
165
197
|
*
|
|
166
|
-
* @throws Error If no
|
|
198
|
+
* @throws Error If no productKey was provided at construction.
|
|
167
199
|
*/
|
|
168
200
|
async getProductByAccountsId(accountsProductId) {
|
|
169
|
-
this.
|
|
201
|
+
this._requireProductKey("getProductByAccountsId");
|
|
170
202
|
try {
|
|
171
203
|
const response = await this._http.request("GET", `/admin/products/by-accounts-id/${accountsProductId}`, {
|
|
172
|
-
headers: { "X-
|
|
204
|
+
headers: { "X-Product-Key": this._productKey },
|
|
173
205
|
isPayments: true,
|
|
174
206
|
});
|
|
175
207
|
return response.data;
|
|
@@ -181,18 +213,46 @@ class PaymentsNamespace {
|
|
|
181
213
|
throw err;
|
|
182
214
|
}
|
|
183
215
|
}
|
|
184
|
-
// ──
|
|
216
|
+
// ── Access check ───────────────────────────────────────────────────────────
|
|
217
|
+
/**
|
|
218
|
+
* Check whether a user has access to a specific feature based on their
|
|
219
|
+
* active subscription's plan.
|
|
220
|
+
*
|
|
221
|
+
* Requires the product key to be set on PpusshClient construction.
|
|
222
|
+
*
|
|
223
|
+
* @param userId UUID string of the Accounts user.
|
|
224
|
+
* @param featureCode Feature code defined on the plan, e.g. "premium_nodes".
|
|
225
|
+
* @param workspaceId Optional workspace UUID — required for workspace-scoped billing.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* const access = await ppussh.payments.checkAccess(user.id, "premium_nodes");
|
|
229
|
+
* if (!access.hasAccess) throw new Error("Upgrade required");
|
|
230
|
+
*/
|
|
231
|
+
async checkAccess(userId, featureCode, workspaceId) {
|
|
232
|
+
this._requireProductKey("checkAccess");
|
|
233
|
+
const response = await this._http.request("POST", "/access/check", {
|
|
234
|
+
json: {
|
|
235
|
+
user_id: userId,
|
|
236
|
+
feature_code: featureCode,
|
|
237
|
+
workspace_id: workspaceId ?? null,
|
|
238
|
+
},
|
|
239
|
+
headers: { "X-Product-Key": this._productKey },
|
|
240
|
+
isPayments: true,
|
|
241
|
+
});
|
|
242
|
+
return response.data;
|
|
243
|
+
}
|
|
244
|
+
// ── Analytics (admin) ─────────────────────────────────────────────────────
|
|
185
245
|
/**
|
|
186
246
|
* Fetch Monthly Recurring Revenue breakdown.
|
|
187
247
|
*
|
|
188
|
-
* Requires
|
|
248
|
+
* Requires admin key.
|
|
189
249
|
*
|
|
190
250
|
* @param productId Filter to a specific product UUID (optional).
|
|
191
251
|
* @param startDate ISO date string e.g. "2025-01-01" (optional).
|
|
192
252
|
* @param endDate ISO date string e.g. "2025-12-31" (optional).
|
|
193
253
|
*/
|
|
194
254
|
async getMrr(options = {}) {
|
|
195
|
-
this.
|
|
255
|
+
this._requireProductKey("getMrr");
|
|
196
256
|
const params = {};
|
|
197
257
|
if (options.productId)
|
|
198
258
|
params["product_id"] = options.productId;
|
|
@@ -201,7 +261,7 @@ class PaymentsNamespace {
|
|
|
201
261
|
if (options.endDate)
|
|
202
262
|
params["end_date"] = options.endDate;
|
|
203
263
|
const response = await this._http.request("GET", "/admin/analytics/mrr", {
|
|
204
|
-
headers: { "X-
|
|
264
|
+
headers: { "X-Product-Key": this._productKey },
|
|
205
265
|
params,
|
|
206
266
|
isPayments: true,
|
|
207
267
|
});
|
|
@@ -218,10 +278,16 @@ class PaymentsNamespace {
|
|
|
218
278
|
"The Payments backend endpoint has not been implemented.");
|
|
219
279
|
}
|
|
220
280
|
// ── Internal helpers ───────────────────────────────────────────────────────
|
|
221
|
-
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
281
|
+
_getAuthHeaders() {
|
|
282
|
+
if (this._productKey) {
|
|
283
|
+
return { "X-Product-Key": this._productKey };
|
|
284
|
+
}
|
|
285
|
+
return {};
|
|
286
|
+
}
|
|
287
|
+
_requireProductKey(method) {
|
|
288
|
+
if (!this._productKey) {
|
|
289
|
+
throw new Error(`payments.${method}() requires a paymentsProductKey. ` +
|
|
290
|
+
"Pass paymentsProductKey: '...' to PpusshClient().");
|
|
225
291
|
}
|
|
226
292
|
}
|
|
227
293
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/payments/namespace.ts"],"names":[],"mappings":";AAAA,mCAAmC;AACnC
|
|
1
|
+
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../../src/payments/namespace.ts"],"names":[],"mappings":";AAAA,mCAAmC;AACnC;;;;;;;;;;;;GAYG;;;AAEH,sCAA+C;AAa/C,MAAa,iBAAiB;IAI5B,YAAY,SAAwB,EAAE,UAA0C,EAAE;QAChF,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC;IAChD,CAAC;IAED,8EAA8E;IAE9E;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,cAAc,CAClB,WAAmB,EACnB,UAII,EAAE;QAEN,MAAM,IAAI,GAA0B;YAClC,aAAa,EAAE,WAAW;YAC1B,YAAY,EAAE,OAAO,CAAC,WAAW,IAAI,SAAS;YAC9C,aAAa,EAAE,OAAO,C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AAS,CAAC;QAChE,IAAI,OAAO,CAAC,SAAS;YAAE,MAAM,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;QAChE,IAAI,OAAO,CAAC,OAAO;YAAE,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;QAE1D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,sBAAsB,EAAE;YACvE,OAAO,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,WAAY,EAAE;YAC/C,MAAM;YACN,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAmB,CAAC;IACtC,CAAC;IAED,8EAA8E;IAE9E;;;;OAIG;IACH,KAAK,CAAC,gBAAgB,CACpB,WAAmB,EACnB,WAAmC,EAAE;QAErC,MAAM,IAAI,KAAK,CACb,2CAA2C;YACzC,yDAAyD,CAC5D,CAAC;IACJ,CAAC;IAED,8EAA8E;IAEtE,eAAe;QACrB,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,EAAE,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAEO,kBAAkB,CAAC,MAAc;QACvC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CACb,YAAY,MAAM,oCAAoC;gBACpD,mDAAmD,CACtD,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAzWD,8CAyWC"}
|
package/dist/payments/types.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export interface PlanResponse {
|
|
|
30
30
|
currency: string;
|
|
31
31
|
billing_cycle: "monthly" | "yearly";
|
|
32
32
|
status: "active" | "archived";
|
|
33
|
+
features: Record<string, unknown>[] | null;
|
|
33
34
|
created_at: string;
|
|
34
35
|
}
|
|
35
36
|
export type SubscriptionStatus = "trialing" | "active" | "past_due" | "paused" | "cancelled" | "unpaid";
|
|
@@ -62,12 +63,33 @@ export interface SubscriptionCreateRequest {
|
|
|
62
63
|
plan_key: string;
|
|
63
64
|
idempotency_key: string;
|
|
64
65
|
provider?: string | null;
|
|
66
|
+
return_url?: string | null;
|
|
65
67
|
metadata?: Record<string, unknown> | null;
|
|
66
68
|
}
|
|
67
69
|
/** Request body for DELETE /subscriptions/{id}. */
|
|
68
70
|
export interface SubscriptionCancelRequest {
|
|
69
71
|
cancel_immediately?: boolean;
|
|
70
72
|
}
|
|
73
|
+
/** Extended response includes checkout URL from provider */
|
|
74
|
+
export interface SubscriptionResponse {
|
|
75
|
+
id: string;
|
|
76
|
+
customer_id: string;
|
|
77
|
+
plan_id: string;
|
|
78
|
+
provider: string;
|
|
79
|
+
provider_subscription_ids: Record<string, string>;
|
|
80
|
+
status: SubscriptionStatus;
|
|
81
|
+
current_period_start: string | null;
|
|
82
|
+
current_period_end: string | null;
|
|
83
|
+
cancelled_at: string | null;
|
|
84
|
+
trial_ends_at: string | null;
|
|
85
|
+
created_at: string;
|
|
86
|
+
updated_at: string;
|
|
87
|
+
checkout_url: string | null;
|
|
88
|
+
}
|
|
89
|
+
/** Request body for DELETE /subscriptions/{id}. */
|
|
90
|
+
export interface SubscriptionCancelRequest {
|
|
91
|
+
cancel_immediately?: boolean;
|
|
92
|
+
}
|
|
71
93
|
/** Response from GET /admin/products/by-accounts-id/{id}. */
|
|
72
94
|
export interface PaymentProductResponse {
|
|
73
95
|
id: string;
|
|
@@ -95,4 +117,10 @@ export interface MRRResponse {
|
|
|
95
117
|
by_product: MRRByProduct[];
|
|
96
118
|
by_plan: MRRByPlan[];
|
|
97
119
|
}
|
|
120
|
+
/** Response from POST /access/check. */
|
|
121
|
+
export interface AccessResult {
|
|
122
|
+
hasAccess: boolean;
|
|
123
|
+
featureName: string | null;
|
|
124
|
+
limit: number | boolean | null;
|
|
125
|
+
}
|
|
98
126
|
//# sourceMappingURL=types.d.ts.map
|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