@hanzo/commerce 7.8.3 → 7.9.1
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 +1246 -402
- package/dist/client.js +955 -331
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/metering.d.ts +11 -2
- package/dist/metering.js +28 -9
- package/dist/metering.js.map +1 -1
- package/dist/metering.test.d.ts +0 -12
- package/dist/metering.test.js +107 -169
- package/dist/metering.test.js.map +1 -1
- package/package.json +6 -5
package/dist/client.js
CHANGED
|
@@ -1,392 +1,1016 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @hanzo/commerce/client
|
|
2
|
+
* @hanzo/commerce/client — the Commerce and Billing API, as the document
|
|
3
|
+
* describes it.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* GENERATED from `cloud/openapi.yaml`. Do not hand-edit: a method here exists
|
|
6
|
+
* because an operation exists, and it is named by that operation's own id. The
|
|
7
|
+
* previous client was written by hand and eleven of its twenty-six addresses had
|
|
8
|
+
* stopped existing, which nothing reported until a call 404'd.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Two surfaces, orthogonal and both here because a store needs both: `commerce`
|
|
11
|
+
* is the storefront — cart, catalog, product, variant, discount, store — and
|
|
12
|
+
* `billing` is the ledger — balance, credits, invoices, methods, subscriptions,
|
|
13
|
+
* usage. They share one noun, `plans`.
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
* // Create a checkout session
|
|
19
|
-
* const session = await commerce.createCheckoutSession({
|
|
20
|
-
* items: [{ id: 'plan_pro', quantity: 1 }],
|
|
21
|
-
* couponCode: 'LAUNCH50',
|
|
22
|
-
* referrerId: 'ref_abc123',
|
|
23
|
-
* successUrl: 'https://app.example.com/success',
|
|
24
|
-
* cancelUrl: 'https://app.example.com/cancel',
|
|
25
|
-
* })
|
|
26
|
-
* window.location.href = session.checkoutUrl
|
|
15
|
+
* const commerce = new Commerce({ baseUrl: 'https://api.hanzo.ai', token })
|
|
16
|
+
* const balance = await commerce.getBillingBalance()
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* A refusal, carrying what the service said about it.
|
|
27
20
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
21
|
+
* RFC 9457 problem documents are what this API answers with, so `detail` is the
|
|
22
|
+
* member to read; `status` is the code. The raw body is kept because a problem
|
|
23
|
+
* document may carry extension members this class does not name.
|
|
31
24
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
export class CommerceApiError extends Error {
|
|
26
|
+
constructor(status, detail, body) {
|
|
27
|
+
super(detail || `commerce: ${status}`);
|
|
28
|
+
this.status = status;
|
|
29
|
+
this.detail = detail;
|
|
30
|
+
this.body = body;
|
|
31
|
+
this.name = 'CommerceApiError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const DEFAULT_BASE_URL = 'https://api.hanzo.ai';
|
|
37
35
|
export class Commerce {
|
|
38
36
|
constructor(config = {}) {
|
|
39
|
-
this.baseUrl = (config.baseUrl ??
|
|
37
|
+
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, '');
|
|
40
38
|
this.token = config.token;
|
|
41
|
-
this.timeoutMs = config.timeoutMs ??
|
|
39
|
+
this.timeoutMs = config.timeoutMs ?? 30000;
|
|
42
40
|
}
|
|
43
|
-
/**
|
|
41
|
+
/** Use this token from now on — after a sign-in, or a refresh. */
|
|
44
42
|
setToken(token) {
|
|
45
43
|
this.token = token;
|
|
46
44
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (opts?.headers)
|
|
63
|
-
Object.assign(headers, opts.headers);
|
|
64
|
-
try {
|
|
65
|
-
const res = await fetch(url.toString(), {
|
|
66
|
-
method: opts?.method ?? 'GET',
|
|
67
|
-
headers,
|
|
68
|
-
body: opts?.body ? JSON.stringify(opts.body) : undefined,
|
|
69
|
-
signal: controller.signal,
|
|
70
|
-
});
|
|
71
|
-
if (!res.ok) {
|
|
72
|
-
const text = await res.text().catch(() => '');
|
|
73
|
-
throw new CommerceApiError(res.status, `${res.statusText}: ${text}`.trim());
|
|
74
|
-
}
|
|
75
|
-
return (await res.json());
|
|
45
|
+
/**
|
|
46
|
+
* One request, one place.
|
|
47
|
+
*
|
|
48
|
+
* A per-call token overrides the client's, which is what a server rendering
|
|
49
|
+
* for one user among many needs: the client is shared, the identity is not.
|
|
50
|
+
*
|
|
51
|
+
* Public because a few addresses this API serves are in neither document.
|
|
52
|
+
* Everything the documents DO describe has a method below; reach for this only
|
|
53
|
+
* when nothing there fits, and say why at the call site.
|
|
54
|
+
*/
|
|
55
|
+
async request(method, path, opts = {}) {
|
|
56
|
+
const url = new URL(this.baseUrl + path);
|
|
57
|
+
for (const [k, v] of Object.entries(opts.query ?? {})) {
|
|
58
|
+
if (v !== undefined)
|
|
59
|
+
url.searchParams.set(k, String(v));
|
|
76
60
|
}
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
const token = opts.token ?? this.token;
|
|
62
|
+
const timer = AbortSignal.timeout(this.timeoutMs);
|
|
63
|
+
const res = await fetch(url, {
|
|
64
|
+
method,
|
|
65
|
+
signal: timer,
|
|
66
|
+
headers: {
|
|
67
|
+
accept: 'application/json',
|
|
68
|
+
...(opts.body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
69
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
70
|
+
...opts.headers,
|
|
71
|
+
},
|
|
72
|
+
...(opts.body !== undefined ? { body: JSON.stringify(opts.body) } : {}),
|
|
73
|
+
});
|
|
74
|
+
if (res.status === 204)
|
|
75
|
+
return undefined;
|
|
76
|
+
const text = await res.text();
|
|
77
|
+
const body = text ? safeJson(text) : undefined;
|
|
78
|
+
if (!res.ok) {
|
|
79
|
+
const d = body;
|
|
80
|
+
throw new CommerceApiError(res.status, d?.detail ?? d?.title ?? d?.msg ?? text.slice(0, 200), body);
|
|
79
81
|
}
|
|
82
|
+
// The /v1 envelope carries the value under `data`; a typed body is itself.
|
|
83
|
+
const env = body;
|
|
84
|
+
return (env && typeof env === 'object' && 'data' in env ? env.data : body);
|
|
80
85
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
async getBalance(user, currency = 'usd', token, headers) {
|
|
85
|
-
return this.request('/v1/billing/balance', {
|
|
86
|
-
params: { user, currency }, token, headers,
|
|
87
|
-
});
|
|
86
|
+
/** Answers the caller's billing accounts: the org itself, its currency, when it was opened, and the caller's own standing in it. */
|
|
87
|
+
getBillingAccounts(opts = {}) {
|
|
88
|
+
return this.request('GET', `/v1/billing/accounts`, opts);
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
90
|
+
/** Answers one billing account's roster. */
|
|
91
|
+
getBillingAccountsByIdMembers(id, opts = {}) {
|
|
92
|
+
return this.request('GET', `/v1/billing/accounts/${encodeURIComponent(id)}/members`, opts);
|
|
93
93
|
}
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
* want included usage (e.g. free-tier daily credit) honored before prepaid
|
|
98
|
-
* funds are drawn down.
|
|
99
|
-
*/
|
|
100
|
-
async getTier(user, opts) {
|
|
101
|
-
return this.request('/v1/billing/tier', {
|
|
102
|
-
params: { user }, token: opts?.token, headers: opts?.headers,
|
|
103
|
-
});
|
|
94
|
+
/** Lists this org's spend caps: the ceiling, its scope, whether it enforces, and how much of it has been spent this period. */
|
|
95
|
+
getBillingAlerts(opts = {}) {
|
|
96
|
+
return this.request('GET', `/v1/billing/alerts`, opts);
|
|
104
97
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
async addUsageRecord(record, token, headers) {
|
|
109
|
-
return this.request('/v1/billing/usage', {
|
|
110
|
-
method: 'POST', body: record, token, headers,
|
|
111
|
-
});
|
|
98
|
+
/** Opens a spend cap on the caller's own org. */
|
|
99
|
+
postBillingAlerts(opts = {}) {
|
|
100
|
+
return this.request('POST', `/v1/billing/alerts`, opts);
|
|
112
101
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
102
|
+
/** Answers whether one proposed spend fits inside this org's caps. */
|
|
103
|
+
getBillingAlertsAuthorize(opts = {}) {
|
|
104
|
+
return this.request('GET', `/v1/billing/alerts/authorize`, opts);
|
|
117
105
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
async addDeposit(params, token) {
|
|
122
|
-
return this.request('/v1/billing/crypto/deposit', {
|
|
123
|
-
method: 'POST', body: params, token,
|
|
124
|
-
});
|
|
106
|
+
/** Removes one of the caller's spend caps and answers 204. */
|
|
107
|
+
deleteBillingAlertsById(id, opts = {}) {
|
|
108
|
+
return this.request('DELETE', `/v1/billing/alerts/${encodeURIComponent(id)}`, opts);
|
|
125
109
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
110
|
+
/** Changes one spend cap: raise or lower the ceiling, flip enforcement, retune the rate limit. */
|
|
111
|
+
patchBillingAlertsById(id, opts = {}) {
|
|
112
|
+
return this.request('PATCH', `/v1/billing/alerts/${encodeURIComponent(id)}`, opts);
|
|
130
113
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
async getPlans(token) {
|
|
135
|
-
return this.request('/v1/billing/plans', { token });
|
|
114
|
+
/** Prepaid credit the caller's org can still spend */
|
|
115
|
+
getBillingBalance(opts = {}) {
|
|
116
|
+
return this.request('GET', `/v1/billing/balance`, opts);
|
|
136
117
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
118
|
+
/** Answers what the caller can spend right now, one entry per currency. */
|
|
119
|
+
getBillingCreditBalance(opts = {}) {
|
|
120
|
+
return this.request('GET', `/v1/billing/credit-balance`, opts);
|
|
144
121
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
async subscribe(params, token) {
|
|
149
|
-
return this.request('/v1/billing/subscriptions', {
|
|
150
|
-
method: 'POST', body: params, token,
|
|
151
|
-
});
|
|
122
|
+
/** Answers that same spendable credit split by grant tag, with the earliest expiry under each and the total across all of them. */
|
|
123
|
+
getBillingCreditBalanceBreakdown(opts = {}) {
|
|
124
|
+
return this.request('GET', `/v1/billing/credit-balance/breakdown`, opts);
|
|
152
125
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
126
|
+
/** Lists the caller's credit grants — every one of them, spent and lapsed and voided included. */
|
|
127
|
+
getBillingCredits(opts = {}) {
|
|
128
|
+
return this.request('GET', `/v1/billing/credits`, opts);
|
|
160
129
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
130
|
+
/** Issues a deposit address the caller can send crypto to, on the asset they ask for. */
|
|
131
|
+
postBillingCryptoDeposit(opts = {}) {
|
|
132
|
+
return this.request('POST', `/v1/billing/crypto/deposit`, opts);
|
|
165
133
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
});
|
|
134
|
+
/** Reads one of the caller's own deposit intents back — pending, confirming, or succeeded. */
|
|
135
|
+
getBillingCryptoDepositById(id, opts = {}) {
|
|
136
|
+
return this.request('GET', `/v1/billing/crypto/deposit/${encodeURIComponent(id)}`, opts);
|
|
170
137
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
138
|
+
/** Answers which chains and tokens the crypto rail accepts — what an asset picker renders. */
|
|
139
|
+
getBillingCryptoOptions(opts = {}) {
|
|
140
|
+
return this.request('GET', `/v1/billing/crypto/options`, opts);
|
|
175
141
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
142
|
+
/** Lists the caller's invoices, newest first, with the count beside them. */
|
|
143
|
+
getBillingInvoices(opts = {}) {
|
|
144
|
+
return this.request('GET', `/v1/billing/invoices`, opts);
|
|
180
145
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Create a hosted checkout session.
|
|
186
|
-
* Returns a URL to redirect the customer to for payment.
|
|
187
|
-
* Supports coupons, referral tracking, and multiple currencies.
|
|
188
|
-
*/
|
|
189
|
-
async createCheckoutSession(params, token) {
|
|
190
|
-
return this.request('/v1/checkout/sessions', {
|
|
191
|
-
method: 'POST', body: params, token,
|
|
192
|
-
});
|
|
146
|
+
/** Raise a draft invoice against a customer */
|
|
147
|
+
raiseInvoice(opts = {}) {
|
|
148
|
+
return this.request('POST', `/v1/billing/invoices`, opts);
|
|
193
149
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
async addPaymentMethod(params, token) {
|
|
198
|
-
return this.request('/v1/billing/methods', {
|
|
199
|
-
method: 'POST', body: params, token,
|
|
200
|
-
});
|
|
150
|
+
/** Read one invoice */
|
|
151
|
+
getInvoice(id, opts = {}) {
|
|
152
|
+
return this.request('GET', `/v1/billing/invoices/${encodeURIComponent(id)}`, opts);
|
|
201
153
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
154
|
+
/** Collect an issued invoice from credits, balance, then card */
|
|
155
|
+
collectInvoice(id, opts = {}) {
|
|
156
|
+
return this.request('POST', `/v1/billing/invoices/${encodeURIComponent(id)}/collect`, opts);
|
|
206
157
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
158
|
+
/** Issue a draft invoice, making it collectible */
|
|
159
|
+
issueInvoice(id, opts = {}) {
|
|
160
|
+
return this.request('POST', `/v1/billing/invoices/${encodeURIComponent(id)}/issue`, opts);
|
|
211
161
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
});
|
|
162
|
+
/** Download one invoice as a PDF */
|
|
163
|
+
getBillingInvoicesByIdPdf(id, opts = {}) {
|
|
164
|
+
return this.request('GET', `/v1/billing/invoices/${encodeURIComponent(id)}/pdf`, opts);
|
|
216
165
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Validate a coupon code.
|
|
222
|
-
* Optionally pass a subtotalCents to get the calculated discount amount.
|
|
223
|
-
*/
|
|
224
|
-
async validateCoupon(code, subtotalCents, token) {
|
|
225
|
-
try {
|
|
226
|
-
const result = await this.request('/v1/coupon/validate', {
|
|
227
|
-
method: 'POST',
|
|
228
|
-
body: { code: code.toUpperCase().trim(), subtotalCents },
|
|
229
|
-
token,
|
|
230
|
-
});
|
|
231
|
-
return { valid: true, coupon: result };
|
|
232
|
-
}
|
|
233
|
-
catch (err) {
|
|
234
|
-
const msg = err instanceof CommerceApiError ? err.message : 'Invalid coupon';
|
|
235
|
-
return { valid: false, error: msg };
|
|
236
|
-
}
|
|
166
|
+
/** Void a draft or issued invoice */
|
|
167
|
+
voidInvoice(id, opts = {}) {
|
|
168
|
+
return this.request('POST', `/v1/billing/invoices/${encodeURIComponent(id)}/void`, opts);
|
|
237
169
|
}
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
async redeemCoupon(code, userId, token) {
|
|
242
|
-
return this.request('/v1/coupon/redeem', {
|
|
243
|
-
method: 'POST',
|
|
244
|
-
body: { code: code.toUpperCase().trim(), userId },
|
|
245
|
-
token,
|
|
246
|
-
});
|
|
170
|
+
/** Answers the org's own postings inside `range=`, each as a signed entry: a DEPOSIT CREDITS the wallet (positive, account `credits:<org>`) and every other posting DEBITS it (negative, account `usage:<org>`), described by its notes or its tags. */
|
|
171
|
+
getBillingLedger(opts = {}) {
|
|
172
|
+
return this.request('GET', `/v1/billing/ledger`, opts);
|
|
247
173
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Get or create a referrer record for a user.
|
|
253
|
-
* Returns the referral code/link the user can share.
|
|
254
|
-
*/
|
|
255
|
-
async getOrCreateReferrer(userId, token) {
|
|
256
|
-
return this.request('/v1/referral', {
|
|
257
|
-
method: 'POST', body: { userId }, token,
|
|
258
|
-
});
|
|
174
|
+
/** Cards and accounts on file for the caller */
|
|
175
|
+
getBillingMethods(opts = {}) {
|
|
176
|
+
return this.request('GET', `/v1/billing/methods`, opts);
|
|
259
177
|
}
|
|
260
|
-
|
|
261
|
-
|
|
178
|
+
/** Save a card or account for the caller */
|
|
179
|
+
postBillingMethods(opts = {}) {
|
|
180
|
+
return this.request('POST', `/v1/billing/methods`, opts);
|
|
262
181
|
}
|
|
263
|
-
|
|
264
|
-
|
|
182
|
+
/** Removes one card or account the caller has saved. */
|
|
183
|
+
deleteBillingMethodsById(id, opts = {}) {
|
|
184
|
+
return this.request('DELETE', `/v1/billing/methods/${encodeURIComponent(id)}`, opts);
|
|
265
185
|
}
|
|
266
|
-
/**
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
async getAffiliate(userId, token) {
|
|
270
|
-
try {
|
|
271
|
-
return await this.request(`/v1/user/${userId}/affiliate`, { token });
|
|
272
|
-
}
|
|
273
|
-
catch {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
186
|
+
/** Moves this org between sandbox money and real money. */
|
|
187
|
+
postBillingMode(opts = {}) {
|
|
188
|
+
return this.request('POST', `/v1/billing/mode`, opts);
|
|
276
189
|
}
|
|
277
|
-
/**
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
*/
|
|
281
|
-
async createAffiliate(userId, token) {
|
|
282
|
-
return this.request('/v1/affiliate', {
|
|
283
|
-
method: 'POST', body: { userId }, token,
|
|
284
|
-
});
|
|
190
|
+
/** Answers the org's outbound payouts, newest first — amount, destination, status, and the failure reason where one applies. */
|
|
191
|
+
getBillingPayouts(opts = {}) {
|
|
192
|
+
return this.request('GET', `/v1/billing/payouts`, opts);
|
|
285
193
|
}
|
|
286
|
-
|
|
287
|
-
|
|
194
|
+
/** The plan catalog, priced with whatever offer is in force */
|
|
195
|
+
getBillingPlans(opts = {}) {
|
|
196
|
+
return this.request('GET', `/v1/billing/plans`, opts);
|
|
288
197
|
}
|
|
289
|
-
|
|
290
|
-
|
|
198
|
+
/** Cards and accounts on file for the caller */
|
|
199
|
+
getBillingPortalMethods(opts = {}) {
|
|
200
|
+
return this.request('GET', `/v1/billing/portal/methods`, opts);
|
|
291
201
|
}
|
|
292
|
-
|
|
293
|
-
|
|
202
|
+
/** Save a card or account for the caller */
|
|
203
|
+
postBillingPortalMethods(opts = {}) {
|
|
204
|
+
return this.request('POST', `/v1/billing/portal/methods`, opts);
|
|
294
205
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
async authorize(orderId, token) {
|
|
299
|
-
return this.request(`/v1/authorize/${orderId}`, { method: 'POST', token });
|
|
206
|
+
/** DetachPortalMethod is DetachMethod at the address a hosted checkout addresses it by. */
|
|
207
|
+
deleteBillingPortalMethodsById(id, opts = {}) {
|
|
208
|
+
return this.request('DELETE', `/v1/billing/portal/methods/${encodeURIComponent(id)}`, opts);
|
|
300
209
|
}
|
|
301
|
-
|
|
302
|
-
|
|
210
|
+
/** Reads the caller's auto-reload rule: top the balance up by `amountCents` whenever it falls below `thresholdCents`, charging the card on file off-session. */
|
|
211
|
+
getBillingRecharge(opts = {}) {
|
|
212
|
+
return this.request('GET', `/v1/billing/recharge`, opts);
|
|
303
213
|
}
|
|
304
|
-
|
|
305
|
-
|
|
214
|
+
/** Sets the caller's auto-reload rule, and answers with the rule as stored. */
|
|
215
|
+
putBillingRecharge(opts = {}) {
|
|
216
|
+
return this.request('PUT', `/v1/billing/recharge`, opts);
|
|
306
217
|
}
|
|
307
|
-
|
|
308
|
-
|
|
218
|
+
/** Sweeps every org's auto-recharge and answers what it did. */
|
|
219
|
+
postBillingRechargeRunAll(opts = {}) {
|
|
220
|
+
return this.request('POST', `/v1/billing/recharge/run-all`, opts);
|
|
309
221
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
});
|
|
222
|
+
/** Answers the PUBLIC half of this org's processor configuration — the ids a browser needs to tokenize a card, and the environment it must tokenize against. */
|
|
223
|
+
getBillingSettings(opts = {}) {
|
|
224
|
+
return this.request('GET', `/v1/billing/settings`, opts);
|
|
314
225
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Get or create a deposit address for a given chain.
|
|
320
|
-
* Used for crypto top-up — user sends funds to this address.
|
|
321
|
-
*/
|
|
322
|
-
async getWalletAddress(params, token) {
|
|
323
|
-
return this.request('/api/wallet/account', {
|
|
324
|
-
method: 'POST',
|
|
325
|
-
body: { name: `${params.userId}-${params.chain}`, blockchainType: params.chain },
|
|
326
|
-
token,
|
|
327
|
-
});
|
|
226
|
+
/** Buy a plan with a card */
|
|
227
|
+
postBillingSubscribeCard(opts = {}) {
|
|
228
|
+
return this.request('POST', `/v1/billing/subscribe/card`, opts);
|
|
328
229
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Add a bank account payment method (ACH).
|
|
334
|
-
* plaidToken from Plaid Link or Square bank OAuth.
|
|
335
|
-
*/
|
|
336
|
-
async addBankAccount(params, token) {
|
|
337
|
-
return this.request('/v1/billing/methods', {
|
|
338
|
-
method: 'POST',
|
|
339
|
-
body: { customerId: params.customerId, type: 'bank_account', plaidToken: params.plaidToken, bankName: params.bankName, accountType: params.accountType },
|
|
340
|
-
token,
|
|
341
|
-
});
|
|
230
|
+
/** Lists the plans the caller holds, with the count beside them. */
|
|
231
|
+
getBillingSubscriptions(opts = {}) {
|
|
232
|
+
return this.request('GET', `/v1/billing/subscriptions`, opts);
|
|
342
233
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
body: { customerId: params.customerId, type: 'crypto', chain: params.chain, address: params.address, label: params.label },
|
|
347
|
-
token,
|
|
348
|
-
});
|
|
234
|
+
/** End a subscription */
|
|
235
|
+
cancelSubscription(id, opts = {}) {
|
|
236
|
+
return this.request('POST', `/v1/billing/subscriptions/${encodeURIComponent(id)}/cancel`, opts);
|
|
349
237
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
238
|
+
/** Put a canceled subscription back on its plan */
|
|
239
|
+
reactivateSubscription(id, opts = {}) {
|
|
240
|
+
return this.request('POST', `/v1/billing/subscriptions/${encodeURIComponent(id)}/reactivate`, opts);
|
|
241
|
+
}
|
|
242
|
+
/** Answers which tier the caller is on, what it allows, and what is left to spend. */
|
|
243
|
+
getBillingTier(opts = {}) {
|
|
244
|
+
return this.request('GET', `/v1/billing/tier`, opts);
|
|
245
|
+
}
|
|
246
|
+
/** Charges a card the caller already saved and credits the balance. */
|
|
247
|
+
postBillingTopup(opts = {}) {
|
|
248
|
+
return this.request('POST', `/v1/billing/topup`, opts);
|
|
249
|
+
}
|
|
250
|
+
/** Charges a single-use card token and credits the caller's balance. */
|
|
251
|
+
postBillingTopupToken(opts = {}) {
|
|
252
|
+
return this.request('POST', `/v1/billing/topup/token`, opts);
|
|
253
|
+
}
|
|
254
|
+
/** Answers one page of the caller's own ledger, newest first: what moved, how much, when, and what it was tagged with. */
|
|
255
|
+
getBillingTransactions(opts = {}) {
|
|
256
|
+
return this.request('GET', `/v1/billing/transactions`, opts);
|
|
257
|
+
}
|
|
258
|
+
/** Reads one ledger entry by its id. */
|
|
259
|
+
getBillingTransactionsById(id, opts = {}) {
|
|
260
|
+
return this.request('GET', `/v1/billing/transactions/${encodeURIComponent(id)}`, opts);
|
|
261
|
+
}
|
|
262
|
+
/** Every billed call the caller's org made, attributed to a product */
|
|
263
|
+
getBillingUsage(opts = {}) {
|
|
264
|
+
return this.request('GET', `/v1/billing/usage`, opts);
|
|
265
|
+
}
|
|
266
|
+
/** Answers per-account totals for the linked provider accounts the gateway ROUTED this caller's traffic through — requests, prompt and completion tokens, recorded cost — plus their honest sum. */
|
|
267
|
+
getBillingUsageAccounts(opts = {}) {
|
|
268
|
+
return this.request('GET', `/v1/billing/usage/accounts`, opts);
|
|
269
|
+
}
|
|
270
|
+
/** Answers the caller's month: what their plan includes, what has been consumed against it, and the wallet beside it. */
|
|
271
|
+
getBillingUsageRollup(opts = {}) {
|
|
272
|
+
return this.request('GET', `/v1/billing/usage/rollup`, opts);
|
|
273
|
+
}
|
|
274
|
+
/** Answers where to send a wire top-up: the receiving bank details, with the caller's own payment reference. */
|
|
275
|
+
getBillingWire(opts = {}) {
|
|
276
|
+
return this.request('GET', `/v1/billing/wire`, opts);
|
|
277
|
+
}
|
|
278
|
+
/** The catalog projection with cost and margin included */
|
|
279
|
+
getCommerceAdminCatalog(opts = {}) {
|
|
280
|
+
return this.request('GET', `/v1/commerce/admin/catalog`, opts);
|
|
281
|
+
}
|
|
282
|
+
/** Open a cart for a shopper to fill */
|
|
283
|
+
openCart(opts = {}) {
|
|
284
|
+
return this.request('POST', `/v1/commerce/cart`, opts);
|
|
285
|
+
}
|
|
286
|
+
/** Read one cart with its lines and totals */
|
|
287
|
+
getCart(id, opts = {}) {
|
|
288
|
+
return this.request('GET', `/v1/commerce/cart/${encodeURIComponent(id)}`, opts);
|
|
289
|
+
}
|
|
290
|
+
/** Discard a cart the shopper abandoned */
|
|
291
|
+
discardCart(id, opts = {}) {
|
|
292
|
+
return this.request('POST', `/v1/commerce/cart/${encodeURIComponent(id)}/discard`, opts);
|
|
293
|
+
}
|
|
294
|
+
/** Set one item's quantity in a cart; zero removes it */
|
|
295
|
+
setCartItem(id, opts = {}) {
|
|
296
|
+
return this.request('POST', `/v1/commerce/cart/${encodeURIComponent(id)}/item`, opts);
|
|
297
|
+
}
|
|
298
|
+
/** The public product catalog projection for a brand */
|
|
299
|
+
getCommerceCatalog(opts = {}) {
|
|
300
|
+
return this.request('GET', `/v1/commerce/catalog`, opts);
|
|
301
|
+
}
|
|
302
|
+
/** The raw catalog entries, including the unpublished ones */
|
|
303
|
+
getCommerceCatalogEntries(opts = {}) {
|
|
304
|
+
return this.request('GET', `/v1/commerce/catalog/entries`, opts);
|
|
305
|
+
}
|
|
306
|
+
/** Add a catalog entry */
|
|
307
|
+
postCommerceCatalogEntries(opts = {}) {
|
|
308
|
+
return this.request('POST', `/v1/commerce/catalog/entries`, opts);
|
|
309
|
+
}
|
|
310
|
+
/** Land a syncer's view of the model catalog: upstream costs and machine facts */
|
|
311
|
+
postCommerceCatalogModels(opts = {}) {
|
|
312
|
+
return this.request('POST', `/v1/commerce/catalog/models`, opts);
|
|
313
|
+
}
|
|
314
|
+
/** Refresh the model catalog by reading the upstream provider */
|
|
315
|
+
postCommerceCatalogModelsRefresh(opts = {}) {
|
|
316
|
+
return this.request('POST', `/v1/commerce/catalog/models/refresh`, opts);
|
|
317
|
+
}
|
|
318
|
+
/** Seed the embedded catalog, without disturbing edits already made */
|
|
319
|
+
postCommerceCatalogSeed(opts = {}) {
|
|
320
|
+
return this.request('POST', `/v1/commerce/catalog/seed`, opts);
|
|
321
|
+
}
|
|
322
|
+
/** List your org's collections, as a page */
|
|
323
|
+
getCommerceCollection(opts = {}) {
|
|
324
|
+
return this.request('GET', `/v1/commerce/collection/`, opts);
|
|
325
|
+
}
|
|
326
|
+
/** Create a collection */
|
|
327
|
+
postCommerceCollection(opts = {}) {
|
|
328
|
+
return this.request('POST', `/v1/commerce/collection/`, opts);
|
|
329
|
+
}
|
|
330
|
+
/** Delete a collection, keeping a recoverable copy */
|
|
331
|
+
deleteCommerceCollectionByCollectionid(collectionid, opts = {}) {
|
|
332
|
+
return this.request('DELETE', `/v1/commerce/collection/${encodeURIComponent(collectionid)}`, opts);
|
|
333
|
+
}
|
|
334
|
+
/** Fetch one collection */
|
|
335
|
+
getCommerceCollectionByCollectionid(collectionid, opts = {}) {
|
|
336
|
+
return this.request('GET', `/v1/commerce/collection/${encodeURIComponent(collectionid)}`, opts);
|
|
337
|
+
}
|
|
338
|
+
/** Change part of a collection */
|
|
339
|
+
patchCommerceCollectionByCollectionid(collectionid, opts = {}) {
|
|
340
|
+
return this.request('PATCH', `/v1/commerce/collection/${encodeURIComponent(collectionid)}`, opts);
|
|
341
|
+
}
|
|
342
|
+
/** Method-override tunnel for a collection — for clients that cannot send PUT, PATCH or DELETE */
|
|
343
|
+
postCommerceCollectionByCollectionid(collectionid, opts = {}) {
|
|
344
|
+
return this.request('POST', `/v1/commerce/collection/${encodeURIComponent(collectionid)}`, opts);
|
|
345
|
+
}
|
|
346
|
+
/** Replace a collection outright */
|
|
347
|
+
putCommerceCollectionByCollectionid(collectionid, opts = {}) {
|
|
348
|
+
return this.request('PUT', `/v1/commerce/collection/${encodeURIComponent(collectionid)}`, opts);
|
|
349
|
+
}
|
|
350
|
+
/** The reference currency list the price and settings pickers render */
|
|
351
|
+
getCommerceCurrencies(opts = {}) {
|
|
352
|
+
return this.request('GET', `/v1/commerce/currencies`, opts);
|
|
353
|
+
}
|
|
354
|
+
/** Read the crypto deposit watcher's runtime state, asset by asset */
|
|
355
|
+
getCommerceDeposits(opts = {}) {
|
|
356
|
+
return this.request('GET', `/v1/commerce/deposits`, opts);
|
|
357
|
+
}
|
|
358
|
+
/** List your org's disclosures, as a page */
|
|
359
|
+
getCommerceDisclosure(opts = {}) {
|
|
360
|
+
return this.request('GET', `/v1/commerce/disclosure/`, opts);
|
|
361
|
+
}
|
|
362
|
+
/** Create a disclosure */
|
|
363
|
+
postCommerceDisclosure(opts = {}) {
|
|
364
|
+
return this.request('POST', `/v1/commerce/disclosure/`, opts);
|
|
365
|
+
}
|
|
366
|
+
/** Delete a disclosure, keeping a recoverable copy */
|
|
367
|
+
deleteCommerceDisclosureByDisclosureid(disclosureid, opts = {}) {
|
|
368
|
+
return this.request('DELETE', `/v1/commerce/disclosure/${encodeURIComponent(disclosureid)}`, opts);
|
|
369
|
+
}
|
|
370
|
+
/** Fetch one disclosure */
|
|
371
|
+
getCommerceDisclosureByDisclosureid(disclosureid, opts = {}) {
|
|
372
|
+
return this.request('GET', `/v1/commerce/disclosure/${encodeURIComponent(disclosureid)}`, opts);
|
|
373
|
+
}
|
|
374
|
+
/** Change part of a disclosure */
|
|
375
|
+
patchCommerceDisclosureByDisclosureid(disclosureid, opts = {}) {
|
|
376
|
+
return this.request('PATCH', `/v1/commerce/disclosure/${encodeURIComponent(disclosureid)}`, opts);
|
|
377
|
+
}
|
|
378
|
+
/** Method-override tunnel for a disclosure — for clients that cannot send PUT, PATCH or DELETE */
|
|
379
|
+
postCommerceDisclosureByDisclosureid(disclosureid, opts = {}) {
|
|
380
|
+
return this.request('POST', `/v1/commerce/disclosure/${encodeURIComponent(disclosureid)}`, opts);
|
|
381
|
+
}
|
|
382
|
+
/** Replace a disclosure outright */
|
|
383
|
+
putCommerceDisclosureByDisclosureid(disclosureid, opts = {}) {
|
|
384
|
+
return this.request('PUT', `/v1/commerce/disclosure/${encodeURIComponent(disclosureid)}`, opts);
|
|
385
|
+
}
|
|
386
|
+
/** List your org's discounts, as a page */
|
|
387
|
+
getCommerceDiscount(opts = {}) {
|
|
388
|
+
return this.request('GET', `/v1/commerce/discount/`, opts);
|
|
389
|
+
}
|
|
390
|
+
/** Create a discount */
|
|
391
|
+
postCommerceDiscount(opts = {}) {
|
|
392
|
+
return this.request('POST', `/v1/commerce/discount/`, opts);
|
|
393
|
+
}
|
|
394
|
+
/** Delete a discount, keeping a recoverable copy */
|
|
395
|
+
deleteCommerceDiscountByDiscountid(discountid, opts = {}) {
|
|
396
|
+
return this.request('DELETE', `/v1/commerce/discount/${encodeURIComponent(discountid)}`, opts);
|
|
397
|
+
}
|
|
398
|
+
/** Fetch one discount */
|
|
399
|
+
getCommerceDiscountByDiscountid(discountid, opts = {}) {
|
|
400
|
+
return this.request('GET', `/v1/commerce/discount/${encodeURIComponent(discountid)}`, opts);
|
|
401
|
+
}
|
|
402
|
+
/** Change part of a discount */
|
|
403
|
+
patchCommerceDiscountByDiscountid(discountid, opts = {}) {
|
|
404
|
+
return this.request('PATCH', `/v1/commerce/discount/${encodeURIComponent(discountid)}`, opts);
|
|
405
|
+
}
|
|
406
|
+
/** Method-override tunnel for a discount — for clients that cannot send PUT, PATCH or DELETE */
|
|
407
|
+
postCommerceDiscountByDiscountid(discountid, opts = {}) {
|
|
408
|
+
return this.request('POST', `/v1/commerce/discount/${encodeURIComponent(discountid)}`, opts);
|
|
409
|
+
}
|
|
410
|
+
/** Replace a discount outright */
|
|
411
|
+
putCommerceDiscountByDiscountid(discountid, opts = {}) {
|
|
412
|
+
return this.request('PUT', `/v1/commerce/discount/${encodeURIComponent(discountid)}`, opts);
|
|
413
|
+
}
|
|
414
|
+
/** Answers ok whenever the commerce subsystem is mounted. */
|
|
415
|
+
getCommerceHealth(opts = {}) {
|
|
416
|
+
return this.request('GET', `/v1/commerce/health`, opts);
|
|
417
|
+
}
|
|
418
|
+
/** List your org's movies, as a page */
|
|
419
|
+
getCommerceMovie(opts = {}) {
|
|
420
|
+
return this.request('GET', `/v1/commerce/movie/`, opts);
|
|
421
|
+
}
|
|
422
|
+
/** Create a movie */
|
|
423
|
+
postCommerceMovie(opts = {}) {
|
|
424
|
+
return this.request('POST', `/v1/commerce/movie/`, opts);
|
|
425
|
+
}
|
|
426
|
+
/** Delete a movie, keeping a recoverable copy */
|
|
427
|
+
deleteCommerceMovieByMovieid(movieid, opts = {}) {
|
|
428
|
+
return this.request('DELETE', `/v1/commerce/movie/${encodeURIComponent(movieid)}`, opts);
|
|
429
|
+
}
|
|
430
|
+
/** Fetch one movie */
|
|
431
|
+
getCommerceMovieByMovieid(movieid, opts = {}) {
|
|
432
|
+
return this.request('GET', `/v1/commerce/movie/${encodeURIComponent(movieid)}`, opts);
|
|
433
|
+
}
|
|
434
|
+
/** Change part of a movie */
|
|
435
|
+
patchCommerceMovieByMovieid(movieid, opts = {}) {
|
|
436
|
+
return this.request('PATCH', `/v1/commerce/movie/${encodeURIComponent(movieid)}`, opts);
|
|
437
|
+
}
|
|
438
|
+
/** Method-override tunnel for a movie — for clients that cannot send PUT, PATCH or DELETE */
|
|
439
|
+
postCommerceMovieByMovieid(movieid, opts = {}) {
|
|
440
|
+
return this.request('POST', `/v1/commerce/movie/${encodeURIComponent(movieid)}`, opts);
|
|
441
|
+
}
|
|
442
|
+
/** Replace a movie outright */
|
|
443
|
+
putCommerceMovieByMovieid(movieid, opts = {}) {
|
|
444
|
+
return this.request('PUT', `/v1/commerce/movie/${encodeURIComponent(movieid)}`, opts);
|
|
445
|
+
}
|
|
446
|
+
/** List your org's notes, as a page */
|
|
447
|
+
getCommerceNote(opts = {}) {
|
|
448
|
+
return this.request('GET', `/v1/commerce/note/`, opts);
|
|
449
|
+
}
|
|
450
|
+
/** Create a note */
|
|
451
|
+
postCommerceNote(opts = {}) {
|
|
452
|
+
return this.request('POST', `/v1/commerce/note/`, opts);
|
|
453
|
+
}
|
|
454
|
+
/** Delete a note, keeping a recoverable copy */
|
|
455
|
+
deleteCommerceNoteByNoteid(noteid, opts = {}) {
|
|
456
|
+
return this.request('DELETE', `/v1/commerce/note/${encodeURIComponent(noteid)}`, opts);
|
|
457
|
+
}
|
|
458
|
+
/** Fetch one note */
|
|
459
|
+
getCommerceNoteByNoteid(noteid, opts = {}) {
|
|
460
|
+
return this.request('GET', `/v1/commerce/note/${encodeURIComponent(noteid)}`, opts);
|
|
461
|
+
}
|
|
462
|
+
/** Change part of a note */
|
|
463
|
+
patchCommerceNoteByNoteid(noteid, opts = {}) {
|
|
464
|
+
return this.request('PATCH', `/v1/commerce/note/${encodeURIComponent(noteid)}`, opts);
|
|
465
|
+
}
|
|
466
|
+
/** Method-override tunnel for a note — for clients that cannot send PUT, PATCH or DELETE */
|
|
467
|
+
postCommerceNoteByNoteid(noteid, opts = {}) {
|
|
468
|
+
return this.request('POST', `/v1/commerce/note/${encodeURIComponent(noteid)}`, opts);
|
|
469
|
+
}
|
|
470
|
+
/** Replace a note outright */
|
|
471
|
+
putCommerceNoteByNoteid(noteid, opts = {}) {
|
|
472
|
+
return this.request('PUT', `/v1/commerce/note/${encodeURIComponent(noteid)}`, opts);
|
|
473
|
+
}
|
|
474
|
+
/** The public org configuration a checkout page boots from */
|
|
475
|
+
getCommerceOrg(opts = {}) {
|
|
476
|
+
return this.request('GET', `/v1/commerce/org`, opts);
|
|
477
|
+
}
|
|
478
|
+
/** The raw plan authority rows */
|
|
479
|
+
getCommercePlansEntries(opts = {}) {
|
|
480
|
+
return this.request('GET', `/v1/commerce/plans/entries`, opts);
|
|
481
|
+
}
|
|
482
|
+
/** Add a subscription plan */
|
|
483
|
+
postCommercePlansEntries(opts = {}) {
|
|
484
|
+
return this.request('POST', `/v1/commerce/plans/entries`, opts);
|
|
485
|
+
}
|
|
486
|
+
/** Remove a plan from the authority */
|
|
487
|
+
deleteCommercePlansEntriesBySlug(slug, opts = {}) {
|
|
488
|
+
return this.request('DELETE', `/v1/commerce/plans/entries/${encodeURIComponent(slug)}`, opts);
|
|
489
|
+
}
|
|
490
|
+
/** Edit a plan, leaving the fields you omit alone */
|
|
491
|
+
putCommercePlansEntriesBySlug(slug, opts = {}) {
|
|
492
|
+
return this.request('PUT', `/v1/commerce/plans/entries/${encodeURIComponent(slug)}`, opts);
|
|
493
|
+
}
|
|
494
|
+
/** Seed the embedded plan catalog, without overwriting administrative edits */
|
|
495
|
+
postCommercePlansSeed(opts = {}) {
|
|
496
|
+
return this.request('POST', `/v1/commerce/plans/seed`, opts);
|
|
497
|
+
}
|
|
498
|
+
/** List your org's products, as a page */
|
|
499
|
+
getCommerceProduct(opts = {}) {
|
|
500
|
+
return this.request('GET', `/v1/commerce/product/`, opts);
|
|
501
|
+
}
|
|
502
|
+
/** Create a product */
|
|
503
|
+
postCommerceProduct(opts = {}) {
|
|
504
|
+
return this.request('POST', `/v1/commerce/product/`, opts);
|
|
505
|
+
}
|
|
506
|
+
/** Delete a product, keeping a recoverable copy */
|
|
507
|
+
deleteCommerceProductByProductid(productid, opts = {}) {
|
|
508
|
+
return this.request('DELETE', `/v1/commerce/product/${encodeURIComponent(productid)}`, opts);
|
|
509
|
+
}
|
|
510
|
+
/** Fetch one product */
|
|
511
|
+
getCommerceProductByProductid(productid, opts = {}) {
|
|
512
|
+
return this.request('GET', `/v1/commerce/product/${encodeURIComponent(productid)}`, opts);
|
|
513
|
+
}
|
|
514
|
+
/** Change part of a product */
|
|
515
|
+
patchCommerceProductByProductid(productid, opts = {}) {
|
|
516
|
+
return this.request('PATCH', `/v1/commerce/product/${encodeURIComponent(productid)}`, opts);
|
|
517
|
+
}
|
|
518
|
+
/** Method-override tunnel for a product — for clients that cannot send PUT, PATCH or DELETE */
|
|
519
|
+
postCommerceProductByProductid(productid, opts = {}) {
|
|
520
|
+
return this.request('POST', `/v1/commerce/product/${encodeURIComponent(productid)}`, opts);
|
|
521
|
+
}
|
|
522
|
+
/** Replace a product outright */
|
|
523
|
+
putCommerceProductByProductid(productid, opts = {}) {
|
|
524
|
+
return this.request('PUT', `/v1/commerce/product/${encodeURIComponent(productid)}`, opts);
|
|
525
|
+
}
|
|
526
|
+
/** List what one unit of each metered thing costs */
|
|
527
|
+
getCommerceRatesEntries(opts = {}) {
|
|
528
|
+
return this.request('GET', `/v1/commerce/rates/entries`, opts);
|
|
529
|
+
}
|
|
530
|
+
/** Add a rate */
|
|
531
|
+
postCommerceRatesEntries(opts = {}) {
|
|
532
|
+
return this.request('POST', `/v1/commerce/rates/entries`, opts);
|
|
533
|
+
}
|
|
534
|
+
/** Remove a rate outright */
|
|
535
|
+
deleteCommerceRatesEntriesByProductByMeter(product, meter, opts = {}) {
|
|
536
|
+
return this.request('DELETE', `/v1/commerce/rates/entries/${encodeURIComponent(product)}/${encodeURIComponent(meter)}`, opts);
|
|
537
|
+
}
|
|
538
|
+
/** Edit a rate, and mark it as operator-set */
|
|
539
|
+
putCommerceRatesEntriesByProductByMeter(product, meter, opts = {}) {
|
|
540
|
+
return this.request('PUT', `/v1/commerce/rates/entries/${encodeURIComponent(product)}/${encodeURIComponent(meter)}`, opts);
|
|
541
|
+
}
|
|
542
|
+
/** Load the published price document, reconciling rather than replacing */
|
|
543
|
+
postCommerceRatesImport(opts = {}) {
|
|
544
|
+
return this.request('POST', `/v1/commerce/rates/import`, opts);
|
|
545
|
+
}
|
|
546
|
+
/** List your org's returns, as a page */
|
|
547
|
+
getCommerceReturn(opts = {}) {
|
|
548
|
+
return this.request('GET', `/v1/commerce/return/`, opts);
|
|
549
|
+
}
|
|
550
|
+
/** Create a return */
|
|
551
|
+
postCommerceReturn(opts = {}) {
|
|
552
|
+
return this.request('POST', `/v1/commerce/return/`, opts);
|
|
553
|
+
}
|
|
554
|
+
/** Delete a return, keeping a recoverable copy */
|
|
555
|
+
deleteCommerceReturnByReturnid(returnid, opts = {}) {
|
|
556
|
+
return this.request('DELETE', `/v1/commerce/return/${encodeURIComponent(returnid)}`, opts);
|
|
557
|
+
}
|
|
558
|
+
/** Fetch one return */
|
|
559
|
+
getCommerceReturnByReturnid(returnid, opts = {}) {
|
|
560
|
+
return this.request('GET', `/v1/commerce/return/${encodeURIComponent(returnid)}`, opts);
|
|
561
|
+
}
|
|
562
|
+
/** Change part of a return */
|
|
563
|
+
patchCommerceReturnByReturnid(returnid, opts = {}) {
|
|
564
|
+
return this.request('PATCH', `/v1/commerce/return/${encodeURIComponent(returnid)}`, opts);
|
|
565
|
+
}
|
|
566
|
+
/** Method-override tunnel for a return — for clients that cannot send PUT, PATCH or DELETE */
|
|
567
|
+
postCommerceReturnByReturnid(returnid, opts = {}) {
|
|
568
|
+
return this.request('POST', `/v1/commerce/return/${encodeURIComponent(returnid)}`, opts);
|
|
569
|
+
}
|
|
570
|
+
/** Replace a return outright */
|
|
571
|
+
putCommerceReturnByReturnid(returnid, opts = {}) {
|
|
572
|
+
return this.request('PUT', `/v1/commerce/return/${encodeURIComponent(returnid)}`, opts);
|
|
573
|
+
}
|
|
574
|
+
/** List your org's sales channels, as a page */
|
|
575
|
+
getCommerceSaleschannel(opts = {}) {
|
|
576
|
+
return this.request('GET', `/v1/commerce/saleschannel/`, opts);
|
|
577
|
+
}
|
|
578
|
+
/** Create a sales channel */
|
|
579
|
+
postCommerceSaleschannel(opts = {}) {
|
|
580
|
+
return this.request('POST', `/v1/commerce/saleschannel/`, opts);
|
|
581
|
+
}
|
|
582
|
+
/** Delete a sales channel, keeping a recoverable copy */
|
|
583
|
+
deleteCommerceSaleschannelBySaleschannelid(saleschannelid, opts = {}) {
|
|
584
|
+
return this.request('DELETE', `/v1/commerce/saleschannel/${encodeURIComponent(saleschannelid)}`, opts);
|
|
585
|
+
}
|
|
586
|
+
/** Fetch one sales channel */
|
|
587
|
+
getCommerceSaleschannelBySaleschannelid(saleschannelid, opts = {}) {
|
|
588
|
+
return this.request('GET', `/v1/commerce/saleschannel/${encodeURIComponent(saleschannelid)}`, opts);
|
|
589
|
+
}
|
|
590
|
+
/** Change part of a sales channel */
|
|
591
|
+
patchCommerceSaleschannelBySaleschannelid(saleschannelid, opts = {}) {
|
|
592
|
+
return this.request('PATCH', `/v1/commerce/saleschannel/${encodeURIComponent(saleschannelid)}`, opts);
|
|
593
|
+
}
|
|
594
|
+
/** Method-override tunnel for a sales channel — for clients that cannot send PUT, PATCH or DELETE */
|
|
595
|
+
postCommerceSaleschannelBySaleschannelid(saleschannelid, opts = {}) {
|
|
596
|
+
return this.request('POST', `/v1/commerce/saleschannel/${encodeURIComponent(saleschannelid)}`, opts);
|
|
597
|
+
}
|
|
598
|
+
/** Replace a sales channel outright */
|
|
599
|
+
putCommerceSaleschannelBySaleschannelid(saleschannelid, opts = {}) {
|
|
600
|
+
return this.request('PUT', `/v1/commerce/saleschannel/${encodeURIComponent(saleschannelid)}`, opts);
|
|
601
|
+
}
|
|
602
|
+
/** List your org's stock locations, as a page */
|
|
603
|
+
getCommerceStocklocation(opts = {}) {
|
|
604
|
+
return this.request('GET', `/v1/commerce/stocklocation/`, opts);
|
|
605
|
+
}
|
|
606
|
+
/** Create a stock location */
|
|
607
|
+
postCommerceStocklocation(opts = {}) {
|
|
608
|
+
return this.request('POST', `/v1/commerce/stocklocation/`, opts);
|
|
609
|
+
}
|
|
610
|
+
/** Delete a stock location, keeping a recoverable copy */
|
|
611
|
+
deleteCommerceStocklocationByStocklocationid(stocklocationid, opts = {}) {
|
|
612
|
+
return this.request('DELETE', `/v1/commerce/stocklocation/${encodeURIComponent(stocklocationid)}`, opts);
|
|
613
|
+
}
|
|
614
|
+
/** Fetch one stock location */
|
|
615
|
+
getCommerceStocklocationByStocklocationid(stocklocationid, opts = {}) {
|
|
616
|
+
return this.request('GET', `/v1/commerce/stocklocation/${encodeURIComponent(stocklocationid)}`, opts);
|
|
617
|
+
}
|
|
618
|
+
/** Change part of a stock location */
|
|
619
|
+
patchCommerceStocklocationByStocklocationid(stocklocationid, opts = {}) {
|
|
620
|
+
return this.request('PATCH', `/v1/commerce/stocklocation/${encodeURIComponent(stocklocationid)}`, opts);
|
|
621
|
+
}
|
|
622
|
+
/** Method-override tunnel for a stock location — for clients that cannot send PUT, PATCH or DELETE */
|
|
623
|
+
postCommerceStocklocationByStocklocationid(stocklocationid, opts = {}) {
|
|
624
|
+
return this.request('POST', `/v1/commerce/stocklocation/${encodeURIComponent(stocklocationid)}`, opts);
|
|
625
|
+
}
|
|
626
|
+
/** Replace a stock location outright */
|
|
627
|
+
putCommerceStocklocationByStocklocationid(stocklocationid, opts = {}) {
|
|
628
|
+
return this.request('PUT', `/v1/commerce/stocklocation/${encodeURIComponent(stocklocationid)}`, opts);
|
|
629
|
+
}
|
|
630
|
+
/** List your org's storefronts as a page */
|
|
631
|
+
getCommerceStore(opts = {}) {
|
|
632
|
+
return this.request('GET', `/v1/commerce/store/`, opts);
|
|
633
|
+
}
|
|
634
|
+
/** Create a storefront */
|
|
635
|
+
postCommerceStore(opts = {}) {
|
|
636
|
+
return this.request('POST', `/v1/commerce/store/`, opts);
|
|
637
|
+
}
|
|
638
|
+
/** Whether a store is entitled to trade, and why */
|
|
639
|
+
getCommerceStoreAccess(opts = {}) {
|
|
640
|
+
return this.request('GET', `/v1/commerce/store/access`, opts);
|
|
641
|
+
}
|
|
642
|
+
/** Resolve your org's active storefront without naming an id */
|
|
643
|
+
getCommerceStoreCurrent(opts = {}) {
|
|
644
|
+
return this.request('GET', `/v1/commerce/store/current`, opts);
|
|
645
|
+
}
|
|
646
|
+
/** Mint your org's least-privilege storefront read key */
|
|
647
|
+
postCommerceStoreToken(opts = {}) {
|
|
648
|
+
return this.request('POST', `/v1/commerce/store/token`, opts);
|
|
649
|
+
}
|
|
650
|
+
/** Delete a storefront, keeping a recoverable copy */
|
|
651
|
+
deleteCommerceStoreByStoreid(storeid, opts = {}) {
|
|
652
|
+
return this.request('DELETE', `/v1/commerce/store/${encodeURIComponent(storeid)}`, opts);
|
|
653
|
+
}
|
|
654
|
+
/** Fetch one storefront */
|
|
655
|
+
getCommerceStoreByStoreid(storeid, opts = {}) {
|
|
656
|
+
return this.request('GET', `/v1/commerce/store/${encodeURIComponent(storeid)}`, opts);
|
|
657
|
+
}
|
|
658
|
+
/** Change part of a storefront */
|
|
659
|
+
patchCommerceStoreByStoreid(storeid, opts = {}) {
|
|
660
|
+
return this.request('PATCH', `/v1/commerce/store/${encodeURIComponent(storeid)}`, opts);
|
|
661
|
+
}
|
|
662
|
+
/** Method-override tunnel for clients that cannot send PUT, PATCH or DELETE */
|
|
663
|
+
postCommerceStoreByStoreid(storeid, opts = {}) {
|
|
664
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}`, opts);
|
|
665
|
+
}
|
|
666
|
+
/** Replace a storefront outright */
|
|
667
|
+
putCommerceStoreByStoreid(storeid, opts = {}) {
|
|
668
|
+
return this.request('PUT', `/v1/commerce/store/${encodeURIComponent(storeid)}`, opts);
|
|
669
|
+
}
|
|
670
|
+
/** Authorize a new order against a storefront, holding the funds without settling them */
|
|
671
|
+
postCommerceStoreByStoreidAuthorize(storeid, opts = {}) {
|
|
672
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/authorize`, opts);
|
|
673
|
+
}
|
|
674
|
+
/** Authorize an order that already exists, holding the funds without settling them */
|
|
675
|
+
postCommerceStoreByStoreidAuthorizeByOrderid(storeid, orderid, opts = {}) {
|
|
676
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/authorize/${encodeURIComponent(orderid)}`, opts);
|
|
677
|
+
}
|
|
678
|
+
/** Fetch a bundle as this storefront sells it */
|
|
679
|
+
getCommerceStoreByStoreidBundleByKey(storeid, key, opts = {}) {
|
|
680
|
+
return this.request('GET', `/v1/commerce/store/${encodeURIComponent(storeid)}/bundle/${encodeURIComponent(key)}`, opts);
|
|
681
|
+
}
|
|
682
|
+
/** Capture a previously authorized order and settle the payment */
|
|
683
|
+
postCommerceStoreByStoreidCaptureByOrderid(storeid, orderid, opts = {}) {
|
|
684
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/capture/${encodeURIComponent(orderid)}`, opts);
|
|
685
|
+
}
|
|
686
|
+
/** Authorize and capture a new order in one call */
|
|
687
|
+
postCommerceStoreByStoreidCharge(storeid, opts = {}) {
|
|
688
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/charge`, opts);
|
|
689
|
+
}
|
|
690
|
+
/** Authorize a new order against a storefront, holding the funds — the checkout spelling */
|
|
691
|
+
postCommerceStoreByStoreidCheckoutAuthorize(storeid, opts = {}) {
|
|
692
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/checkout/authorize`, opts);
|
|
693
|
+
}
|
|
694
|
+
/** Authorize an existing order, holding the funds — the checkout spelling */
|
|
695
|
+
postCommerceStoreByStoreidCheckoutAuthorizeByOrderid(storeid, orderid, opts = {}) {
|
|
696
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/checkout/authorize/${encodeURIComponent(orderid)}`, opts);
|
|
697
|
+
}
|
|
698
|
+
/** Capture a previously authorized order and settle it — the checkout spelling */
|
|
699
|
+
postCommerceStoreByStoreidCheckoutCaptureByOrderid(storeid, orderid, opts = {}) {
|
|
700
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/checkout/capture/${encodeURIComponent(orderid)}`, opts);
|
|
701
|
+
}
|
|
702
|
+
/** Authorize and capture a new order in one call — the checkout spelling */
|
|
703
|
+
postCommerceStoreByStoreidCheckoutCharge(storeid, opts = {}) {
|
|
704
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/checkout/charge`, opts);
|
|
705
|
+
}
|
|
706
|
+
/** PayPal cancel by pay key — refuses, exactly as the unprefixed address does */
|
|
707
|
+
postCommerceStoreByStoreidCheckoutPaypalCancelByPaykey(storeid, payKey, opts = {}) {
|
|
708
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/checkout/paypal/cancel/${encodeURIComponent(payKey)}`, opts);
|
|
709
|
+
}
|
|
710
|
+
/** PayPal confirm by pay key — refuses, exactly as the unprefixed address does */
|
|
711
|
+
postCommerceStoreByStoreidCheckoutPaypalConfirmByPaykey(storeid, payKey, opts = {}) {
|
|
712
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/checkout/paypal/confirm/${encodeURIComponent(payKey)}`, opts);
|
|
713
|
+
}
|
|
714
|
+
/** Start a PayPal authorization for a new order — the checkout spelling */
|
|
715
|
+
postCommerceStoreByStoreidCheckoutPaypalPay(storeid, opts = {}) {
|
|
716
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/checkout/paypal/pay`, opts);
|
|
717
|
+
}
|
|
718
|
+
/** The storefront's whole listing override map */
|
|
719
|
+
getCommerceStoreByStoreidListing(storeid, opts = {}) {
|
|
720
|
+
return this.request('GET', `/v1/commerce/store/${encodeURIComponent(storeid)}/listing`, opts);
|
|
721
|
+
}
|
|
722
|
+
/** Remove a listing override */
|
|
723
|
+
deleteCommerceStoreByStoreidListingByKey(storeid, key, opts = {}) {
|
|
724
|
+
return this.request('DELETE', `/v1/commerce/store/${encodeURIComponent(storeid)}/listing/${encodeURIComponent(key)}`, opts);
|
|
725
|
+
}
|
|
726
|
+
/** Fetch one listing override, by item id or by its slug or SKU */
|
|
727
|
+
getCommerceStoreByStoreidListingByKey(storeid, key, opts = {}) {
|
|
728
|
+
return this.request('GET', `/v1/commerce/store/${encodeURIComponent(storeid)}/listing/${encodeURIComponent(key)}`, opts);
|
|
729
|
+
}
|
|
730
|
+
/** Confirm a listing override exists and re-save the store */
|
|
731
|
+
patchCommerceStoreByStoreidListingByKey(storeid, key, opts = {}) {
|
|
732
|
+
return this.request('PATCH', `/v1/commerce/store/${encodeURIComponent(storeid)}/listing/${encodeURIComponent(key)}`, opts);
|
|
733
|
+
}
|
|
734
|
+
/** Add a listing override under a new key */
|
|
735
|
+
postCommerceStoreByStoreidListingByKey(storeid, key, opts = {}) {
|
|
736
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/listing/${encodeURIComponent(key)}`, opts);
|
|
737
|
+
}
|
|
738
|
+
/** Upsert a listing override */
|
|
739
|
+
putCommerceStoreByStoreidListingByKey(storeid, key, opts = {}) {
|
|
740
|
+
return this.request('PUT', `/v1/commerce/store/${encodeURIComponent(storeid)}/listing/${encodeURIComponent(key)}`, opts);
|
|
741
|
+
}
|
|
742
|
+
/** PayPal cancel by pay key — refuses, because a pay key alone does not identify the order */
|
|
743
|
+
postCommerceStoreByStoreidPaypalCancelByPaykey(storeid, payKey, opts = {}) {
|
|
744
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/paypal/cancel/${encodeURIComponent(payKey)}`, opts);
|
|
745
|
+
}
|
|
746
|
+
/** PayPal confirm by pay key — refuses, because a pay key alone does not identify the order */
|
|
747
|
+
postCommerceStoreByStoreidPaypalConfirmByPaykey(storeid, payKey, opts = {}) {
|
|
748
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/paypal/confirm/${encodeURIComponent(payKey)}`, opts);
|
|
749
|
+
}
|
|
750
|
+
/** Start a PayPal authorization for a new order */
|
|
751
|
+
postCommerceStoreByStoreidPaypalPay(storeid, opts = {}) {
|
|
752
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/paypal/pay`, opts);
|
|
753
|
+
}
|
|
754
|
+
/** Fetch a product as this storefront sells it */
|
|
755
|
+
getCommerceStoreByStoreidProductByKey(storeid, key, opts = {}) {
|
|
756
|
+
return this.request('GET', `/v1/commerce/store/${encodeURIComponent(storeid)}/product/${encodeURIComponent(key)}`, opts);
|
|
757
|
+
}
|
|
758
|
+
/** Start this store's no-card trial on the entry plan */
|
|
759
|
+
postCommerceStoreByStoreidTrial(storeid, opts = {}) {
|
|
760
|
+
return this.request('POST', `/v1/commerce/store/${encodeURIComponent(storeid)}/trial`, opts);
|
|
761
|
+
}
|
|
762
|
+
/** Fetch a variant as this storefront sells it */
|
|
763
|
+
getCommerceStoreByStoreidVariantByKey(storeid, key, opts = {}) {
|
|
764
|
+
return this.request('GET', `/v1/commerce/store/${encodeURIComponent(storeid)}/variant/${encodeURIComponent(key)}`, opts);
|
|
765
|
+
}
|
|
766
|
+
/** List your org's submissions, as a page */
|
|
767
|
+
getCommerceSubmission(opts = {}) {
|
|
768
|
+
return this.request('GET', `/v1/commerce/submission/`, opts);
|
|
769
|
+
}
|
|
770
|
+
/** Create a submission */
|
|
771
|
+
postCommerceSubmission(opts = {}) {
|
|
772
|
+
return this.request('POST', `/v1/commerce/submission/`, opts);
|
|
773
|
+
}
|
|
774
|
+
/** Delete a submission, keeping a recoverable copy */
|
|
775
|
+
deleteCommerceSubmissionBySubmissionid(submissionid, opts = {}) {
|
|
776
|
+
return this.request('DELETE', `/v1/commerce/submission/${encodeURIComponent(submissionid)}`, opts);
|
|
777
|
+
}
|
|
778
|
+
/** Fetch one submission */
|
|
779
|
+
getCommerceSubmissionBySubmissionid(submissionid, opts = {}) {
|
|
780
|
+
return this.request('GET', `/v1/commerce/submission/${encodeURIComponent(submissionid)}`, opts);
|
|
781
|
+
}
|
|
782
|
+
/** Change part of a submission */
|
|
783
|
+
patchCommerceSubmissionBySubmissionid(submissionid, opts = {}) {
|
|
784
|
+
return this.request('PATCH', `/v1/commerce/submission/${encodeURIComponent(submissionid)}`, opts);
|
|
785
|
+
}
|
|
786
|
+
/** Method-override tunnel for a submission — for clients that cannot send PUT, PATCH or DELETE */
|
|
787
|
+
postCommerceSubmissionBySubmissionid(submissionid, opts = {}) {
|
|
788
|
+
return this.request('POST', `/v1/commerce/submission/${encodeURIComponent(submissionid)}`, opts);
|
|
789
|
+
}
|
|
790
|
+
/** Replace a submission outright */
|
|
791
|
+
putCommerceSubmissionBySubmissionid(submissionid, opts = {}) {
|
|
792
|
+
return this.request('PUT', `/v1/commerce/submission/${encodeURIComponent(submissionid)}`, opts);
|
|
793
|
+
}
|
|
794
|
+
/** List your org's subscribers, as a page */
|
|
795
|
+
getCommerceSubscriber(opts = {}) {
|
|
796
|
+
return this.request('GET', `/v1/commerce/subscriber/`, opts);
|
|
797
|
+
}
|
|
798
|
+
/** Create a subscriber */
|
|
799
|
+
postCommerceSubscriber(opts = {}) {
|
|
800
|
+
return this.request('POST', `/v1/commerce/subscriber/`, opts);
|
|
801
|
+
}
|
|
802
|
+
/** Delete a subscriber, keeping a recoverable copy */
|
|
803
|
+
deleteCommerceSubscriberBySubscriberid(subscriberid, opts = {}) {
|
|
804
|
+
return this.request('DELETE', `/v1/commerce/subscriber/${encodeURIComponent(subscriberid)}`, opts);
|
|
805
|
+
}
|
|
806
|
+
/** Fetch one subscriber */
|
|
807
|
+
getCommerceSubscriberBySubscriberid(subscriberid, opts = {}) {
|
|
808
|
+
return this.request('GET', `/v1/commerce/subscriber/${encodeURIComponent(subscriberid)}`, opts);
|
|
809
|
+
}
|
|
810
|
+
/** Change part of a subscriber */
|
|
811
|
+
patchCommerceSubscriberBySubscriberid(subscriberid, opts = {}) {
|
|
812
|
+
return this.request('PATCH', `/v1/commerce/subscriber/${encodeURIComponent(subscriberid)}`, opts);
|
|
813
|
+
}
|
|
814
|
+
/** Method-override tunnel for a subscriber — for clients that cannot send PUT, PATCH or DELETE */
|
|
815
|
+
postCommerceSubscriberBySubscriberid(subscriberid, opts = {}) {
|
|
816
|
+
return this.request('POST', `/v1/commerce/subscriber/${encodeURIComponent(subscriberid)}`, opts);
|
|
817
|
+
}
|
|
818
|
+
/** Replace a subscriber outright */
|
|
819
|
+
putCommerceSubscriberBySubscriberid(subscriberid, opts = {}) {
|
|
820
|
+
return this.request('PUT', `/v1/commerce/subscriber/${encodeURIComponent(subscriberid)}`, opts);
|
|
821
|
+
}
|
|
822
|
+
/** List your org's token transactions, as a page */
|
|
823
|
+
getCommerceTokentransaction(opts = {}) {
|
|
824
|
+
return this.request('GET', `/v1/commerce/tokentransaction/`, opts);
|
|
825
|
+
}
|
|
826
|
+
/** Create a token transaction */
|
|
827
|
+
postCommerceTokentransaction(opts = {}) {
|
|
828
|
+
return this.request('POST', `/v1/commerce/tokentransaction/`, opts);
|
|
829
|
+
}
|
|
830
|
+
/** Delete a token transaction, keeping a recoverable copy */
|
|
831
|
+
deleteCommerceTokentransactionByTokentransactionid(tokentransactionid, opts = {}) {
|
|
832
|
+
return this.request('DELETE', `/v1/commerce/tokentransaction/${encodeURIComponent(tokentransactionid)}`, opts);
|
|
833
|
+
}
|
|
834
|
+
/** Fetch one token transaction */
|
|
835
|
+
getCommerceTokentransactionByTokentransactionid(tokentransactionid, opts = {}) {
|
|
836
|
+
return this.request('GET', `/v1/commerce/tokentransaction/${encodeURIComponent(tokentransactionid)}`, opts);
|
|
837
|
+
}
|
|
838
|
+
/** Change part of a token transaction */
|
|
839
|
+
patchCommerceTokentransactionByTokentransactionid(tokentransactionid, opts = {}) {
|
|
840
|
+
return this.request('PATCH', `/v1/commerce/tokentransaction/${encodeURIComponent(tokentransactionid)}`, opts);
|
|
841
|
+
}
|
|
842
|
+
/** Method-override tunnel for a token transaction — for clients that cannot send PUT, PATCH or DELETE */
|
|
843
|
+
postCommerceTokentransactionByTokentransactionid(tokentransactionid, opts = {}) {
|
|
844
|
+
return this.request('POST', `/v1/commerce/tokentransaction/${encodeURIComponent(tokentransactionid)}`, opts);
|
|
845
|
+
}
|
|
846
|
+
/** Replace a token transaction outright */
|
|
847
|
+
putCommerceTokentransactionByTokentransactionid(tokentransactionid, opts = {}) {
|
|
848
|
+
return this.request('PUT', `/v1/commerce/tokentransaction/${encodeURIComponent(tokentransactionid)}`, opts);
|
|
849
|
+
}
|
|
850
|
+
/** List your org's transfers, as a page */
|
|
851
|
+
getCommerceTransfer(opts = {}) {
|
|
852
|
+
return this.request('GET', `/v1/commerce/transfer/`, opts);
|
|
853
|
+
}
|
|
854
|
+
/** Create a transfer */
|
|
855
|
+
postCommerceTransfer(opts = {}) {
|
|
856
|
+
return this.request('POST', `/v1/commerce/transfer/`, opts);
|
|
857
|
+
}
|
|
858
|
+
/** Delete a transfer, keeping a recoverable copy */
|
|
859
|
+
deleteCommerceTransferByTransferid(transferid, opts = {}) {
|
|
860
|
+
return this.request('DELETE', `/v1/commerce/transfer/${encodeURIComponent(transferid)}`, opts);
|
|
861
|
+
}
|
|
862
|
+
/** Fetch one transfer */
|
|
863
|
+
getCommerceTransferByTransferid(transferid, opts = {}) {
|
|
864
|
+
return this.request('GET', `/v1/commerce/transfer/${encodeURIComponent(transferid)}`, opts);
|
|
865
|
+
}
|
|
866
|
+
/** Change part of a transfer */
|
|
867
|
+
patchCommerceTransferByTransferid(transferid, opts = {}) {
|
|
868
|
+
return this.request('PATCH', `/v1/commerce/transfer/${encodeURIComponent(transferid)}`, opts);
|
|
869
|
+
}
|
|
870
|
+
/** Method-override tunnel for a transfer — for clients that cannot send PUT, PATCH or DELETE */
|
|
871
|
+
postCommerceTransferByTransferid(transferid, opts = {}) {
|
|
872
|
+
return this.request('POST', `/v1/commerce/transfer/${encodeURIComponent(transferid)}`, opts);
|
|
873
|
+
}
|
|
874
|
+
/** Replace a transfer outright */
|
|
875
|
+
putCommerceTransferByTransferid(transferid, opts = {}) {
|
|
876
|
+
return this.request('PUT', `/v1/commerce/transfer/${encodeURIComponent(transferid)}`, opts);
|
|
877
|
+
}
|
|
878
|
+
/** List your org's variants, as a page */
|
|
879
|
+
getCommerceVariant(opts = {}) {
|
|
880
|
+
return this.request('GET', `/v1/commerce/variant/`, opts);
|
|
881
|
+
}
|
|
882
|
+
/** Create a variant */
|
|
883
|
+
postCommerceVariant(opts = {}) {
|
|
884
|
+
return this.request('POST', `/v1/commerce/variant/`, opts);
|
|
885
|
+
}
|
|
886
|
+
/** Delete a variant, keeping a recoverable copy */
|
|
887
|
+
deleteCommerceVariantByVariantid(variantid, opts = {}) {
|
|
888
|
+
return this.request('DELETE', `/v1/commerce/variant/${encodeURIComponent(variantid)}`, opts);
|
|
889
|
+
}
|
|
890
|
+
/** Fetch one variant */
|
|
891
|
+
getCommerceVariantByVariantid(variantid, opts = {}) {
|
|
892
|
+
return this.request('GET', `/v1/commerce/variant/${encodeURIComponent(variantid)}`, opts);
|
|
893
|
+
}
|
|
894
|
+
/** Change part of a variant */
|
|
895
|
+
patchCommerceVariantByVariantid(variantid, opts = {}) {
|
|
896
|
+
return this.request('PATCH', `/v1/commerce/variant/${encodeURIComponent(variantid)}`, opts);
|
|
897
|
+
}
|
|
898
|
+
/** Method-override tunnel for a variant — for clients that cannot send PUT, PATCH or DELETE */
|
|
899
|
+
postCommerceVariantByVariantid(variantid, opts = {}) {
|
|
900
|
+
return this.request('POST', `/v1/commerce/variant/${encodeURIComponent(variantid)}`, opts);
|
|
901
|
+
}
|
|
902
|
+
/** Replace a variant outright */
|
|
903
|
+
putCommerceVariantByVariantid(variantid, opts = {}) {
|
|
904
|
+
return this.request('PUT', `/v1/commerce/variant/${encodeURIComponent(variantid)}`, opts);
|
|
905
|
+
}
|
|
906
|
+
/** List your org's wallets, as a page */
|
|
907
|
+
getCommerceWallet(opts = {}) {
|
|
908
|
+
return this.request('GET', `/v1/commerce/wallet/`, opts);
|
|
909
|
+
}
|
|
910
|
+
/** Create a wallet */
|
|
911
|
+
postCommerceWallet(opts = {}) {
|
|
912
|
+
return this.request('POST', `/v1/commerce/wallet/`, opts);
|
|
913
|
+
}
|
|
914
|
+
/** Delete a wallet, keeping a recoverable copy */
|
|
915
|
+
deleteCommerceWalletByWalletid(walletid, opts = {}) {
|
|
916
|
+
return this.request('DELETE', `/v1/commerce/wallet/${encodeURIComponent(walletid)}`, opts);
|
|
917
|
+
}
|
|
918
|
+
/** Fetch one wallet */
|
|
919
|
+
getCommerceWalletByWalletid(walletid, opts = {}) {
|
|
920
|
+
return this.request('GET', `/v1/commerce/wallet/${encodeURIComponent(walletid)}`, opts);
|
|
921
|
+
}
|
|
922
|
+
/** Change part of a wallet */
|
|
923
|
+
patchCommerceWalletByWalletid(walletid, opts = {}) {
|
|
924
|
+
return this.request('PATCH', `/v1/commerce/wallet/${encodeURIComponent(walletid)}`, opts);
|
|
925
|
+
}
|
|
926
|
+
/** Method-override tunnel for a wallet — for clients that cannot send PUT, PATCH or DELETE */
|
|
927
|
+
postCommerceWalletByWalletid(walletid, opts = {}) {
|
|
928
|
+
return this.request('POST', `/v1/commerce/wallet/${encodeURIComponent(walletid)}`, opts);
|
|
929
|
+
}
|
|
930
|
+
/** Replace a wallet outright */
|
|
931
|
+
putCommerceWalletByWalletid(walletid, opts = {}) {
|
|
932
|
+
return this.request('PUT', `/v1/commerce/wallet/${encodeURIComponent(walletid)}`, opts);
|
|
933
|
+
}
|
|
934
|
+
/** List your org's watchlists, as a page */
|
|
935
|
+
getCommerceWatchlist(opts = {}) {
|
|
936
|
+
return this.request('GET', `/v1/commerce/watchlist/`, opts);
|
|
937
|
+
}
|
|
938
|
+
/** Create a watchlist */
|
|
939
|
+
postCommerceWatchlist(opts = {}) {
|
|
940
|
+
return this.request('POST', `/v1/commerce/watchlist/`, opts);
|
|
941
|
+
}
|
|
942
|
+
/** Delete a watchlist, keeping a recoverable copy */
|
|
943
|
+
deleteCommerceWatchlistByWatchlistid(watchlistid, opts = {}) {
|
|
944
|
+
return this.request('DELETE', `/v1/commerce/watchlist/${encodeURIComponent(watchlistid)}`, opts);
|
|
945
|
+
}
|
|
946
|
+
/** Fetch one watchlist */
|
|
947
|
+
getCommerceWatchlistByWatchlistid(watchlistid, opts = {}) {
|
|
948
|
+
return this.request('GET', `/v1/commerce/watchlist/${encodeURIComponent(watchlistid)}`, opts);
|
|
949
|
+
}
|
|
950
|
+
/** Change part of a watchlist */
|
|
951
|
+
patchCommerceWatchlistByWatchlistid(watchlistid, opts = {}) {
|
|
952
|
+
return this.request('PATCH', `/v1/commerce/watchlist/${encodeURIComponent(watchlistid)}`, opts);
|
|
953
|
+
}
|
|
954
|
+
/** Method-override tunnel for a watchlist — for clients that cannot send PUT, PATCH or DELETE */
|
|
955
|
+
postCommerceWatchlistByWatchlistid(watchlistid, opts = {}) {
|
|
956
|
+
return this.request('POST', `/v1/commerce/watchlist/${encodeURIComponent(watchlistid)}`, opts);
|
|
957
|
+
}
|
|
958
|
+
/** Replace a watchlist outright */
|
|
959
|
+
putCommerceWatchlistByWatchlistid(watchlistid, opts = {}) {
|
|
960
|
+
return this.request('PUT', `/v1/commerce/watchlist/${encodeURIComponent(watchlistid)}`, opts);
|
|
961
|
+
}
|
|
962
|
+
/** List your org's webhooks, as a page */
|
|
963
|
+
getCommerceWebhook(opts = {}) {
|
|
964
|
+
return this.request('GET', `/v1/commerce/webhook/`, opts);
|
|
965
|
+
}
|
|
966
|
+
/** Create a webhook */
|
|
967
|
+
postCommerceWebhook(opts = {}) {
|
|
968
|
+
return this.request('POST', `/v1/commerce/webhook/`, opts);
|
|
969
|
+
}
|
|
970
|
+
/** Delete a webhook, keeping a recoverable copy */
|
|
971
|
+
deleteCommerceWebhookByWebhookid(webhookid, opts = {}) {
|
|
972
|
+
return this.request('DELETE', `/v1/commerce/webhook/${encodeURIComponent(webhookid)}`, opts);
|
|
973
|
+
}
|
|
974
|
+
/** Fetch one webhook */
|
|
975
|
+
getCommerceWebhookByWebhookid(webhookid, opts = {}) {
|
|
976
|
+
return this.request('GET', `/v1/commerce/webhook/${encodeURIComponent(webhookid)}`, opts);
|
|
977
|
+
}
|
|
978
|
+
/** Change part of a webhook */
|
|
979
|
+
patchCommerceWebhookByWebhookid(webhookid, opts = {}) {
|
|
980
|
+
return this.request('PATCH', `/v1/commerce/webhook/${encodeURIComponent(webhookid)}`, opts);
|
|
981
|
+
}
|
|
982
|
+
/** Method-override tunnel for a webhook — for clients that cannot send PUT, PATCH or DELETE */
|
|
983
|
+
postCommerceWebhookByWebhookid(webhookid, opts = {}) {
|
|
984
|
+
return this.request('POST', `/v1/commerce/webhook/${encodeURIComponent(webhookid)}`, opts);
|
|
985
|
+
}
|
|
986
|
+
/** Replace a webhook outright */
|
|
987
|
+
putCommerceWebhookByWebhookid(webhookid, opts = {}) {
|
|
988
|
+
return this.request('PUT', `/v1/commerce/webhook/${encodeURIComponent(webhookid)}`, opts);
|
|
989
|
+
}
|
|
990
|
+
/** Payment-provider webhook intake for settlement and subscription lifecycle events */
|
|
991
|
+
postCommerceWebhooksByProvider(provider, opts = {}) {
|
|
992
|
+
return this.request('POST', `/v1/commerce/webhooks/${encodeURIComponent(provider)}`, opts);
|
|
363
993
|
}
|
|
364
994
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
995
|
+
/** A body that is not JSON is still evidence; keep it rather than throwing. */
|
|
996
|
+
function safeJson(text) {
|
|
997
|
+
try {
|
|
998
|
+
return JSON.parse(text);
|
|
999
|
+
}
|
|
1000
|
+
catch {
|
|
1001
|
+
return text;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
let shared;
|
|
368
1005
|
/**
|
|
369
|
-
*
|
|
370
|
-
* Pass your IAM access token (read from localStorage or cookie).
|
|
1006
|
+
* The process-wide client.
|
|
371
1007
|
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
* import { hanzoCommerce } from '@hanzo/commerce/client'
|
|
375
|
-
* const commerce = hanzoCommerce(localStorage.getItem('hanzo-auth-token') ?? undefined)
|
|
376
|
-
* const plans = await commerce.getPlans()
|
|
377
|
-
* ```
|
|
1008
|
+
* One instance because the base url and the timeout are properties of the
|
|
1009
|
+
* deployment, not of a call. Pass a token per call where the identity varies.
|
|
378
1010
|
*/
|
|
379
|
-
export function hanzoCommerce(
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
// Error
|
|
384
|
-
// ---------------------------------------------------------------------------
|
|
385
|
-
export class CommerceApiError extends Error {
|
|
386
|
-
constructor(status, message) {
|
|
387
|
-
super(message);
|
|
388
|
-
this.name = 'CommerceApiError';
|
|
389
|
-
this.status = status;
|
|
390
|
-
}
|
|
1011
|
+
export function hanzoCommerce(config = {}) {
|
|
1012
|
+
if (!shared)
|
|
1013
|
+
shared = new Commerce(config);
|
|
1014
|
+
return shared;
|
|
391
1015
|
}
|
|
392
1016
|
//# sourceMappingURL=client.js.map
|