fresh-squeezy 0.1.13 → 0.1.15
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/README.md +56 -12
- package/dist/cli.js +1496 -328
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +1136 -245
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +901 -73
- package/dist/index.d.ts +901 -73
- package/dist/index.js +1106 -245
- package/dist/index.js.map +1 -1
- package/package.json +7 -10
package/dist/index.js
CHANGED
|
@@ -20,7 +20,7 @@ var ENV_KEYS = {
|
|
|
20
20
|
storeId: "LEMON_SQUEEZY_STORE_ID",
|
|
21
21
|
mode: "LEMON_SQUEEZY_MODE"
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
var resolveConfig = (input = {}) => {
|
|
24
24
|
const apiKey = input.apiKey ?? process.env[ENV_KEYS.apiKey];
|
|
25
25
|
if (!apiKey) {
|
|
26
26
|
throw new FreshSqueezyError({
|
|
@@ -37,14 +37,14 @@ function resolveConfig(input = {}) {
|
|
|
37
37
|
baseUrl: input.baseUrl ?? DEFAULT_BASE_URL,
|
|
38
38
|
fetch: input.fetch ?? globalThis.fetch
|
|
39
39
|
};
|
|
40
|
-
}
|
|
41
|
-
|
|
40
|
+
};
|
|
41
|
+
var normalizeMode = (value) => {
|
|
42
42
|
if (value === "test" || value === "live") return value;
|
|
43
43
|
throw new FreshSqueezyError({
|
|
44
44
|
code: "INVALID_MODE",
|
|
45
45
|
message: `Mode must be "test" or "live", got "${value}".`
|
|
46
46
|
});
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
|
|
49
49
|
// src/core/http.ts
|
|
50
50
|
var HttpClient = class {
|
|
@@ -90,6 +90,37 @@ var HttpClient = class {
|
|
|
90
90
|
const doc = await this.request({ path });
|
|
91
91
|
return doc.data;
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* POST a JSON:API document and return the created `data` resource.
|
|
95
|
+
*
|
|
96
|
+
* @param path - API path starting with `/v1/...`.
|
|
97
|
+
* @param body - JSON:API create document.
|
|
98
|
+
* @returns The created resource.
|
|
99
|
+
*/
|
|
100
|
+
async postResource(path, body) {
|
|
101
|
+
const doc = await this.request({ method: "POST", path, body });
|
|
102
|
+
return doc.data;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* PATCH a JSON:API document and return the updated `data` resource.
|
|
106
|
+
*
|
|
107
|
+
* @param path - API path starting with `/v1/...`.
|
|
108
|
+
* @param body - JSON:API update document.
|
|
109
|
+
* @returns The updated resource.
|
|
110
|
+
*/
|
|
111
|
+
async patchResource(path, body) {
|
|
112
|
+
const doc = await this.request({ method: "PATCH", path, body });
|
|
113
|
+
return doc.data;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* DELETE a resource. Lemon Squeezy often returns an empty body on success.
|
|
117
|
+
*
|
|
118
|
+
* @param path - API path starting with `/v1/...`.
|
|
119
|
+
* @returns Nothing — single void return, not a multi-field bag.
|
|
120
|
+
*/
|
|
121
|
+
async deleteResource(path) {
|
|
122
|
+
await this.request({ method: "DELETE", path });
|
|
123
|
+
}
|
|
93
124
|
/**
|
|
94
125
|
* Fetch a single page of a JSON:API collection. Most callers want
|
|
95
126
|
* `paginate()` instead — this method is kept for one-shot lookups where
|
|
@@ -137,51 +168,922 @@ var HttpClient = class {
|
|
|
137
168
|
return url.toString();
|
|
138
169
|
}
|
|
139
170
|
};
|
|
140
|
-
|
|
171
|
+
var safeJsonParse = (text) => {
|
|
141
172
|
try {
|
|
142
173
|
return JSON.parse(text);
|
|
143
174
|
} catch {
|
|
144
175
|
return text;
|
|
145
176
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
177
|
+
};
|
|
178
|
+
var toApiError = (status, body) => {
|
|
148
179
|
const errors = extractJsonApiErrors(body);
|
|
149
180
|
const first = errors[0];
|
|
150
181
|
const code = status === 401 ? "UNAUTHORIZED" : status === 404 ? "NOT_FOUND" : status === 429 ? "RATE_LIMITED" : first?.code ?? `HTTP_${status}`;
|
|
151
182
|
const message = first?.detail ?? first?.title ?? `Lemon Squeezy request failed with status ${status}`;
|
|
152
183
|
return new FreshSqueezyError({ code, status, message, detail: body });
|
|
153
|
-
}
|
|
154
|
-
|
|
184
|
+
};
|
|
185
|
+
var extractJsonApiErrors = (body) => {
|
|
155
186
|
if (!body || typeof body !== "object") return [];
|
|
156
187
|
const errors = body.errors;
|
|
157
188
|
if (!Array.isArray(errors)) return [];
|
|
158
189
|
return errors.filter(
|
|
159
190
|
(entry) => typeof entry === "object" && entry !== null
|
|
160
191
|
);
|
|
161
|
-
}
|
|
192
|
+
};
|
|
162
193
|
|
|
163
|
-
// src/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
194
|
+
// src/resources/affiliates.ts
|
|
195
|
+
var getAffiliate = async (http, affiliateId) => {
|
|
196
|
+
return http.getResource(`/v1/affiliates/${affiliateId}`);
|
|
197
|
+
};
|
|
198
|
+
var listAffiliatesForStore = async (http, storeId) => {
|
|
199
|
+
return http.paginate("/v1/affiliates", {
|
|
200
|
+
"filter[store_id]": String(storeId)
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// src/resources/checkouts.ts
|
|
205
|
+
var getCheckout = async (http, checkoutId) => {
|
|
206
|
+
return http.getResource(`/v1/checkouts/${checkoutId}`);
|
|
207
|
+
};
|
|
208
|
+
var listCheckoutsForStore = async (http, storeId) => {
|
|
209
|
+
return http.paginate("/v1/checkouts", {
|
|
210
|
+
"filter[store_id]": String(storeId)
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
var createCheckout = async (http, body) => {
|
|
214
|
+
return http.postResource("/v1/checkouts", body);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/resources/customers.ts
|
|
218
|
+
var getCustomer = async (http, customerId) => {
|
|
219
|
+
return http.getResource(`/v1/customers/${customerId}`);
|
|
220
|
+
};
|
|
221
|
+
var listCustomersForStore = async (http, storeId) => {
|
|
222
|
+
return http.paginate("/v1/customers", {
|
|
223
|
+
"filter[store_id]": String(storeId)
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
var createCustomer = async (http, body) => {
|
|
227
|
+
return http.postResource("/v1/customers", body);
|
|
228
|
+
};
|
|
229
|
+
var updateCustomer = async (http, customerId, body) => {
|
|
230
|
+
return http.patchResource(`/v1/customers/${customerId}`, body);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/resources/discountRedemptions.ts
|
|
234
|
+
var getDiscountRedemption = async (http, discountRedemptionId) => {
|
|
235
|
+
return http.getResource(
|
|
236
|
+
`/v1/discount-redemptions/${discountRedemptionId}`
|
|
237
|
+
);
|
|
238
|
+
};
|
|
239
|
+
var listDiscountRedemptionsForDiscount = async (http, discountId) => {
|
|
240
|
+
return http.paginate("/v1/discount-redemptions", {
|
|
241
|
+
"filter[discount_id]": String(discountId)
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/resources/discounts.ts
|
|
246
|
+
var getDiscount = async (http, discountId) => {
|
|
247
|
+
return http.getResource(`/v1/discounts/${discountId}`);
|
|
248
|
+
};
|
|
249
|
+
var listDiscountsForStore = async (http, storeId) => {
|
|
250
|
+
return http.paginate("/v1/discounts", {
|
|
251
|
+
"filter[store_id]": String(storeId)
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
var createDiscount = async (http, body) => {
|
|
255
|
+
return http.postResource("/v1/discounts", body);
|
|
256
|
+
};
|
|
257
|
+
var deleteDiscount = async (http, discountId) => {
|
|
258
|
+
await http.deleteResource(`/v1/discounts/${discountId}`);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/resources/files.ts
|
|
262
|
+
var getFile = async (http, fileId) => {
|
|
263
|
+
return http.getResource(`/v1/files/${fileId}`);
|
|
264
|
+
};
|
|
265
|
+
var listFilesForVariant = async (http, variantId) => {
|
|
266
|
+
return http.paginate("/v1/files", {
|
|
267
|
+
"filter[variant_id]": String(variantId)
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// src/resources/licenseKeyInstances.ts
|
|
272
|
+
var getLicenseKeyInstance = async (http, licenseKeyInstanceId) => {
|
|
273
|
+
return http.getResource(
|
|
274
|
+
`/v1/license-key-instances/${licenseKeyInstanceId}`
|
|
275
|
+
);
|
|
276
|
+
};
|
|
277
|
+
var listLicenseKeyInstancesForLicenseKey = async (http, licenseKeyId) => {
|
|
278
|
+
return http.paginate("/v1/license-key-instances", {
|
|
279
|
+
"filter[license_key_id]": String(licenseKeyId)
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/resources/licenseKeys.ts
|
|
284
|
+
var getLicenseKey = async (http, licenseKeyId) => {
|
|
285
|
+
return http.getResource(`/v1/license-keys/${licenseKeyId}`);
|
|
286
|
+
};
|
|
287
|
+
var listLicenseKeysForStore = async (http, storeId) => {
|
|
288
|
+
return http.paginate("/v1/license-keys", {
|
|
289
|
+
"filter[store_id]": String(storeId)
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
var updateLicenseKey = async (http, licenseKeyId, body) => {
|
|
293
|
+
return http.patchResource(`/v1/license-keys/${licenseKeyId}`, body);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
// src/resources/orderItems.ts
|
|
297
|
+
var getOrderItem = async (http, orderItemId) => {
|
|
298
|
+
return http.getResource(`/v1/order-items/${orderItemId}`);
|
|
299
|
+
};
|
|
300
|
+
var listOrderItemsForOrder = async (http, orderId) => {
|
|
301
|
+
return http.paginate("/v1/order-items", {
|
|
302
|
+
"filter[order_id]": String(orderId)
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/resources/orders.ts
|
|
307
|
+
var getOrder = async (http, orderId) => {
|
|
308
|
+
return http.getResource(`/v1/orders/${orderId}`);
|
|
309
|
+
};
|
|
310
|
+
var listOrdersForStore = async (http, storeId) => {
|
|
311
|
+
return http.paginate("/v1/orders", {
|
|
312
|
+
"filter[store_id]": String(storeId)
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
var refundOrder = async (http, orderId, body) => {
|
|
316
|
+
return http.postResource(`/v1/orders/${orderId}/refund`, body ?? {});
|
|
317
|
+
};
|
|
318
|
+
var generateOrderInvoice = async (http, orderId, body) => {
|
|
319
|
+
return http.request({
|
|
320
|
+
method: "POST",
|
|
321
|
+
path: `/v1/orders/${orderId}/generate-invoice`,
|
|
322
|
+
body: body ?? {}
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// src/resources/prices.ts
|
|
327
|
+
var getPrice = async (http, priceId) => {
|
|
328
|
+
return http.getResource(`/v1/prices/${priceId}`);
|
|
329
|
+
};
|
|
330
|
+
var listPricesForVariant = async (http, variantId) => {
|
|
331
|
+
return http.paginate("/v1/prices", {
|
|
332
|
+
"filter[variant_id]": String(variantId)
|
|
333
|
+
});
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// src/resources/products.ts
|
|
337
|
+
var getProduct = async (http, productId) => {
|
|
338
|
+
return http.getResource(`/v1/products/${productId}`);
|
|
339
|
+
};
|
|
340
|
+
var listProducts = async (http, storeId) => {
|
|
341
|
+
return http.paginate("/v1/products", {
|
|
342
|
+
"filter[store_id]": String(storeId)
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// src/resources/registry.ts
|
|
347
|
+
var resourceRegistry = [
|
|
348
|
+
// users
|
|
349
|
+
{ resource: "user", verb: "get", docsPath: "users/retrieve-user", body: "none", idRole: "none" },
|
|
350
|
+
// stores (read-only)
|
|
351
|
+
{ resource: "store", verb: "get", docsPath: "stores/retrieve-store", body: "none", idRole: "id" },
|
|
352
|
+
{
|
|
353
|
+
resource: "store",
|
|
354
|
+
verb: "list",
|
|
355
|
+
docsPath: "stores/list-all-stores",
|
|
356
|
+
body: "none",
|
|
357
|
+
idRole: "none"
|
|
358
|
+
},
|
|
359
|
+
// products (read-only)
|
|
360
|
+
{
|
|
361
|
+
resource: "product",
|
|
362
|
+
verb: "get",
|
|
363
|
+
docsPath: "products/retrieve-product",
|
|
364
|
+
body: "none",
|
|
365
|
+
idRole: "id"
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
resource: "product",
|
|
369
|
+
verb: "list",
|
|
370
|
+
docsPath: "products/list-all-products",
|
|
371
|
+
body: "none",
|
|
372
|
+
idRole: "store"
|
|
373
|
+
},
|
|
374
|
+
// variants (read-only)
|
|
375
|
+
{
|
|
376
|
+
resource: "variant",
|
|
377
|
+
verb: "get",
|
|
378
|
+
docsPath: "variants/retrieve-variant",
|
|
379
|
+
body: "none",
|
|
380
|
+
idRole: "id"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
resource: "variant",
|
|
384
|
+
verb: "list",
|
|
385
|
+
docsPath: "variants/list-all-variants",
|
|
386
|
+
body: "none",
|
|
387
|
+
idRole: "parent"
|
|
388
|
+
},
|
|
389
|
+
// prices (read-only)
|
|
390
|
+
{ resource: "price", verb: "get", docsPath: "prices/retrieve-price", body: "none", idRole: "id" },
|
|
391
|
+
{
|
|
392
|
+
resource: "price",
|
|
393
|
+
verb: "list",
|
|
394
|
+
docsPath: "prices/list-all-prices",
|
|
395
|
+
body: "none",
|
|
396
|
+
idRole: "parent"
|
|
397
|
+
},
|
|
398
|
+
// files (read-only)
|
|
399
|
+
{ resource: "file", verb: "get", docsPath: "files/retrieve-file", body: "none", idRole: "id" },
|
|
400
|
+
{
|
|
401
|
+
resource: "file",
|
|
402
|
+
verb: "list",
|
|
403
|
+
docsPath: "files/list-all-files",
|
|
404
|
+
body: "none",
|
|
405
|
+
idRole: "parent"
|
|
406
|
+
},
|
|
407
|
+
// customers
|
|
408
|
+
{
|
|
409
|
+
resource: "customer",
|
|
410
|
+
verb: "get",
|
|
411
|
+
docsPath: "customers/retrieve-customer",
|
|
412
|
+
body: "none",
|
|
413
|
+
idRole: "id"
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
resource: "customer",
|
|
417
|
+
verb: "list",
|
|
418
|
+
docsPath: "customers/list-all-customers",
|
|
419
|
+
body: "none",
|
|
420
|
+
idRole: "store"
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
resource: "customer",
|
|
424
|
+
verb: "create",
|
|
425
|
+
docsPath: "customers/create-customer",
|
|
426
|
+
body: "required",
|
|
427
|
+
idRole: "none"
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
resource: "customer",
|
|
431
|
+
verb: "update",
|
|
432
|
+
docsPath: "customers/update-customer",
|
|
433
|
+
body: "required",
|
|
434
|
+
idRole: "id"
|
|
435
|
+
},
|
|
436
|
+
// orders
|
|
437
|
+
{ resource: "order", verb: "get", docsPath: "orders/retrieve-order", body: "none", idRole: "id" },
|
|
438
|
+
{
|
|
439
|
+
resource: "order",
|
|
440
|
+
verb: "list",
|
|
441
|
+
docsPath: "orders/list-all-orders",
|
|
442
|
+
body: "none",
|
|
443
|
+
idRole: "store"
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
resource: "order",
|
|
447
|
+
verb: "refund",
|
|
448
|
+
docsPath: "orders/issue-refund",
|
|
449
|
+
body: "optional",
|
|
450
|
+
destructive: true,
|
|
451
|
+
idRole: "id"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
resource: "order",
|
|
455
|
+
verb: "generate-invoice",
|
|
456
|
+
docsPath: "orders/generate-order-invoice",
|
|
457
|
+
body: "optional",
|
|
458
|
+
idRole: "id"
|
|
459
|
+
},
|
|
460
|
+
// order-items (read-only)
|
|
461
|
+
{
|
|
462
|
+
resource: "order-item",
|
|
463
|
+
verb: "get",
|
|
464
|
+
docsPath: "order-items/retrieve-order-item",
|
|
465
|
+
body: "none",
|
|
466
|
+
idRole: "id"
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
resource: "order-item",
|
|
470
|
+
verb: "list",
|
|
471
|
+
docsPath: "order-items/list-all-order-items",
|
|
472
|
+
body: "none",
|
|
473
|
+
idRole: "parent"
|
|
474
|
+
},
|
|
475
|
+
// subscriptions
|
|
476
|
+
{
|
|
477
|
+
resource: "subscription",
|
|
478
|
+
verb: "get",
|
|
479
|
+
docsPath: "subscriptions/retrieve-subscription",
|
|
480
|
+
body: "none",
|
|
481
|
+
idRole: "id"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
resource: "subscription",
|
|
485
|
+
verb: "list",
|
|
486
|
+
docsPath: "subscriptions/list-all-subscriptions",
|
|
487
|
+
body: "none",
|
|
488
|
+
idRole: "store"
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
resource: "subscription",
|
|
492
|
+
verb: "update",
|
|
493
|
+
docsPath: "subscriptions/update-subscription",
|
|
494
|
+
body: "required",
|
|
495
|
+
idRole: "id"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
resource: "subscription",
|
|
499
|
+
verb: "cancel",
|
|
500
|
+
docsPath: "subscriptions/cancel-subscription",
|
|
501
|
+
body: "none",
|
|
502
|
+
destructive: true,
|
|
503
|
+
idRole: "id"
|
|
504
|
+
},
|
|
505
|
+
// subscription-items
|
|
506
|
+
{
|
|
507
|
+
resource: "subscription-item",
|
|
508
|
+
verb: "get",
|
|
509
|
+
docsPath: "subscription-items/retrieve-subscription-item",
|
|
510
|
+
body: "none",
|
|
511
|
+
idRole: "id"
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
resource: "subscription-item",
|
|
515
|
+
verb: "list",
|
|
516
|
+
docsPath: "subscription-items/list-all-subscription-items",
|
|
517
|
+
body: "none",
|
|
518
|
+
idRole: "parent"
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
resource: "subscription-item",
|
|
522
|
+
verb: "update",
|
|
523
|
+
docsPath: "subscription-items/update-subscription-item",
|
|
524
|
+
body: "required",
|
|
525
|
+
idRole: "id"
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
resource: "subscription-item",
|
|
529
|
+
verb: "current-usage",
|
|
530
|
+
docsPath: "subscription-items/retrieve-subscription-item-current-usage",
|
|
531
|
+
body: "none",
|
|
532
|
+
idRole: "id"
|
|
533
|
+
},
|
|
534
|
+
// subscription-invoices
|
|
535
|
+
{
|
|
536
|
+
resource: "subscription-invoice",
|
|
537
|
+
verb: "get",
|
|
538
|
+
docsPath: "subscription-invoices/retrieve-subscription-invoice",
|
|
539
|
+
body: "none",
|
|
540
|
+
idRole: "id"
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
resource: "subscription-invoice",
|
|
544
|
+
verb: "list",
|
|
545
|
+
docsPath: "subscription-invoices/list-all-subscription-invoices",
|
|
546
|
+
body: "none",
|
|
547
|
+
idRole: "parent"
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
resource: "subscription-invoice",
|
|
551
|
+
verb: "refund",
|
|
552
|
+
docsPath: "subscription-invoices/issue-refund",
|
|
553
|
+
body: "optional",
|
|
554
|
+
destructive: true,
|
|
555
|
+
idRole: "id"
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
resource: "subscription-invoice",
|
|
559
|
+
verb: "generate-invoice",
|
|
560
|
+
docsPath: "subscription-invoices/generate-subscription-invoice",
|
|
561
|
+
body: "optional",
|
|
562
|
+
idRole: "id"
|
|
563
|
+
},
|
|
564
|
+
// usage-records
|
|
565
|
+
{
|
|
566
|
+
resource: "usage-record",
|
|
567
|
+
verb: "get",
|
|
568
|
+
docsPath: "usage-records/retrieve-usage-record",
|
|
569
|
+
body: "none",
|
|
570
|
+
idRole: "id"
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
resource: "usage-record",
|
|
574
|
+
verb: "list",
|
|
575
|
+
docsPath: "usage-records/list-all-usage-records",
|
|
576
|
+
body: "none",
|
|
577
|
+
idRole: "parent"
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
resource: "usage-record",
|
|
581
|
+
verb: "create",
|
|
582
|
+
docsPath: "usage-records/create-usage-record",
|
|
583
|
+
body: "required",
|
|
584
|
+
idRole: "none"
|
|
585
|
+
},
|
|
586
|
+
// discounts
|
|
587
|
+
{
|
|
588
|
+
resource: "discount",
|
|
589
|
+
verb: "get",
|
|
590
|
+
docsPath: "discounts/retrieve-discount",
|
|
591
|
+
body: "none",
|
|
592
|
+
idRole: "id"
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
resource: "discount",
|
|
596
|
+
verb: "list",
|
|
597
|
+
docsPath: "discounts/list-all-discounts",
|
|
598
|
+
body: "none",
|
|
599
|
+
idRole: "store"
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
resource: "discount",
|
|
603
|
+
verb: "create",
|
|
604
|
+
docsPath: "discounts/create-discount",
|
|
605
|
+
body: "required",
|
|
606
|
+
idRole: "none"
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
resource: "discount",
|
|
610
|
+
verb: "delete",
|
|
611
|
+
docsPath: "discounts/delete-discount",
|
|
612
|
+
body: "none",
|
|
613
|
+
destructive: true,
|
|
614
|
+
idRole: "id"
|
|
615
|
+
},
|
|
616
|
+
// discount-redemptions (read-only)
|
|
617
|
+
{
|
|
618
|
+
resource: "discount-redemption",
|
|
619
|
+
verb: "get",
|
|
620
|
+
docsPath: "discount-redemptions/retrieve-discount-redemption",
|
|
621
|
+
body: "none",
|
|
622
|
+
idRole: "id"
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
resource: "discount-redemption",
|
|
626
|
+
verb: "list",
|
|
627
|
+
docsPath: "discount-redemptions/list-all-discount-redemptions",
|
|
628
|
+
body: "none",
|
|
629
|
+
idRole: "parent"
|
|
630
|
+
},
|
|
631
|
+
// license-keys
|
|
632
|
+
{
|
|
633
|
+
resource: "license-key",
|
|
634
|
+
verb: "get",
|
|
635
|
+
docsPath: "license-keys/retrieve-license-key",
|
|
636
|
+
body: "none",
|
|
637
|
+
idRole: "id"
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
resource: "license-key",
|
|
641
|
+
verb: "list",
|
|
642
|
+
docsPath: "license-keys/list-all-license-keys",
|
|
643
|
+
body: "none",
|
|
644
|
+
idRole: "store"
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
resource: "license-key",
|
|
648
|
+
verb: "update",
|
|
649
|
+
docsPath: "license-keys/update-license-key",
|
|
650
|
+
body: "required",
|
|
651
|
+
idRole: "id"
|
|
652
|
+
},
|
|
653
|
+
// license-key-instances (read-only)
|
|
654
|
+
{
|
|
655
|
+
resource: "license-key-instance",
|
|
656
|
+
verb: "get",
|
|
657
|
+
docsPath: "license-key-instances/retrieve-license-key-instance",
|
|
658
|
+
body: "none",
|
|
659
|
+
idRole: "id"
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
resource: "license-key-instance",
|
|
663
|
+
verb: "list",
|
|
664
|
+
docsPath: "license-key-instances/list-all-license-key-instances",
|
|
665
|
+
body: "none",
|
|
666
|
+
idRole: "parent"
|
|
667
|
+
},
|
|
668
|
+
// checkouts
|
|
669
|
+
{
|
|
670
|
+
resource: "checkout",
|
|
671
|
+
verb: "get",
|
|
672
|
+
docsPath: "checkouts/retrieve-checkout",
|
|
673
|
+
body: "none",
|
|
674
|
+
idRole: "id"
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
resource: "checkout",
|
|
678
|
+
verb: "list",
|
|
679
|
+
docsPath: "checkouts/list-all-checkouts",
|
|
680
|
+
body: "none",
|
|
681
|
+
idRole: "store"
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
resource: "checkout",
|
|
685
|
+
verb: "create",
|
|
686
|
+
docsPath: "checkouts/create-checkout",
|
|
687
|
+
body: "required",
|
|
688
|
+
idRole: "none"
|
|
689
|
+
},
|
|
690
|
+
// webhooks
|
|
691
|
+
{
|
|
692
|
+
resource: "webhook",
|
|
693
|
+
verb: "get",
|
|
694
|
+
docsPath: "webhooks/retrieve-webhook",
|
|
695
|
+
body: "none",
|
|
696
|
+
idRole: "id"
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
resource: "webhook",
|
|
700
|
+
verb: "list",
|
|
701
|
+
docsPath: "webhooks/list-all-webhooks",
|
|
702
|
+
body: "none",
|
|
703
|
+
idRole: "store"
|
|
704
|
+
},
|
|
705
|
+
{
|
|
706
|
+
resource: "webhook",
|
|
707
|
+
verb: "create",
|
|
708
|
+
docsPath: "webhooks/create-webhook",
|
|
709
|
+
body: "required",
|
|
710
|
+
idRole: "none"
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
resource: "webhook",
|
|
714
|
+
verb: "update",
|
|
715
|
+
docsPath: "webhooks/update-webhook",
|
|
716
|
+
body: "required",
|
|
717
|
+
idRole: "id"
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
resource: "webhook",
|
|
721
|
+
verb: "delete",
|
|
722
|
+
docsPath: "webhooks/delete-webhook",
|
|
723
|
+
body: "none",
|
|
724
|
+
destructive: true,
|
|
725
|
+
idRole: "id"
|
|
726
|
+
},
|
|
727
|
+
// affiliates (read-only)
|
|
728
|
+
{
|
|
729
|
+
resource: "affiliate",
|
|
730
|
+
verb: "get",
|
|
731
|
+
docsPath: "affiliates/retrieve-affiliate",
|
|
732
|
+
body: "none",
|
|
733
|
+
idRole: "id"
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
resource: "affiliate",
|
|
737
|
+
verb: "list",
|
|
738
|
+
docsPath: "affiliates/list-all-affiliates",
|
|
739
|
+
body: "none",
|
|
740
|
+
idRole: "store"
|
|
741
|
+
}
|
|
742
|
+
];
|
|
743
|
+
var findResourceVerb = (resource, verb) => {
|
|
744
|
+
const normalized = resource.replace(/_/g, "-").toLowerCase();
|
|
745
|
+
const singular = normalized.endsWith("s") && normalized !== "status" ? normalized.slice(0, -1) : normalized;
|
|
746
|
+
const aliases = {
|
|
747
|
+
products: "product",
|
|
748
|
+
stores: "store",
|
|
749
|
+
customers: "customer",
|
|
750
|
+
orders: "order",
|
|
751
|
+
"order-items": "order-item",
|
|
752
|
+
subscriptions: "subscription",
|
|
753
|
+
"subscription-items": "subscription-item",
|
|
754
|
+
"subscription-invoices": "subscription-invoice",
|
|
755
|
+
"usage-records": "usage-record",
|
|
756
|
+
discounts: "discount",
|
|
757
|
+
"discount-redemptions": "discount-redemption",
|
|
758
|
+
"license-keys": "license-key",
|
|
759
|
+
"license-key-instances": "license-key-instance",
|
|
760
|
+
checkouts: "checkout",
|
|
761
|
+
webhooks: "webhook",
|
|
762
|
+
affiliates: "affiliate",
|
|
763
|
+
variants: "variant",
|
|
764
|
+
prices: "price",
|
|
765
|
+
files: "file",
|
|
766
|
+
users: "user"
|
|
767
|
+
};
|
|
768
|
+
const key = aliases[normalized] ?? singular;
|
|
769
|
+
return resourceRegistry.find((entry) => entry.resource === key && entry.verb === verb);
|
|
770
|
+
};
|
|
771
|
+
var listRegisteredResources = () => {
|
|
772
|
+
return [...new Set(resourceRegistry.map((entry) => entry.resource))].sort();
|
|
773
|
+
};
|
|
169
774
|
|
|
170
775
|
// src/resources/stores.ts
|
|
171
|
-
async
|
|
776
|
+
var getStore = async (http, storeId) => {
|
|
172
777
|
return http.getResource(`/v1/stores/${storeId}`);
|
|
173
|
-
}
|
|
174
|
-
async
|
|
778
|
+
};
|
|
779
|
+
var listStores = async (http) => {
|
|
175
780
|
return http.paginate("/v1/stores");
|
|
176
|
-
}
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
// src/resources/subscriptionInvoices.ts
|
|
784
|
+
var getSubscriptionInvoice = async (http, subscriptionInvoiceId) => {
|
|
785
|
+
return http.getResource(
|
|
786
|
+
`/v1/subscription-invoices/${subscriptionInvoiceId}`
|
|
787
|
+
);
|
|
788
|
+
};
|
|
789
|
+
var listSubscriptionInvoicesForSubscription = async (http, subscriptionId) => {
|
|
790
|
+
return http.paginate("/v1/subscription-invoices", {
|
|
791
|
+
"filter[subscription_id]": String(subscriptionId)
|
|
792
|
+
});
|
|
793
|
+
};
|
|
794
|
+
var refundSubscriptionInvoice = async (http, subscriptionInvoiceId, body) => {
|
|
795
|
+
return http.postResource(
|
|
796
|
+
`/v1/subscription-invoices/${subscriptionInvoiceId}/refund`,
|
|
797
|
+
body ?? {}
|
|
798
|
+
);
|
|
799
|
+
};
|
|
800
|
+
var generateSubscriptionInvoice = async (http, subscriptionInvoiceId, body) => {
|
|
801
|
+
return http.request({
|
|
802
|
+
method: "POST",
|
|
803
|
+
path: `/v1/subscription-invoices/${subscriptionInvoiceId}/generate-invoice`,
|
|
804
|
+
body: body ?? {}
|
|
805
|
+
});
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// src/resources/subscriptionItems.ts
|
|
809
|
+
var getSubscriptionItem = async (http, subscriptionItemId) => {
|
|
810
|
+
return http.getResource(
|
|
811
|
+
`/v1/subscription-items/${subscriptionItemId}`
|
|
812
|
+
);
|
|
813
|
+
};
|
|
814
|
+
var listSubscriptionItemsForSubscription = async (http, subscriptionId) => {
|
|
815
|
+
return http.paginate("/v1/subscription-items", {
|
|
816
|
+
"filter[subscription_id]": String(subscriptionId)
|
|
817
|
+
});
|
|
818
|
+
};
|
|
819
|
+
var buildSubscriptionItemUpdateBody = (subscriptionItemId, attributes) => {
|
|
820
|
+
return {
|
|
821
|
+
data: {
|
|
822
|
+
type: "subscription-items",
|
|
823
|
+
id: String(subscriptionItemId),
|
|
824
|
+
attributes
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
};
|
|
828
|
+
var updateSubscriptionItem = async (http, subscriptionItemId, body) => {
|
|
829
|
+
return http.patchResource(
|
|
830
|
+
`/v1/subscription-items/${subscriptionItemId}`,
|
|
831
|
+
body
|
|
832
|
+
);
|
|
833
|
+
};
|
|
834
|
+
var getSubscriptionItemCurrentUsage = async (http, subscriptionItemId) => {
|
|
835
|
+
return http.request({
|
|
836
|
+
path: `/v1/subscription-items/${subscriptionItemId}/current-usage`
|
|
837
|
+
});
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
// src/resources/subscriptions.ts
|
|
841
|
+
var getSubscription = async (http, subscriptionId) => {
|
|
842
|
+
return http.getResource(`/v1/subscriptions/${subscriptionId}`);
|
|
843
|
+
};
|
|
844
|
+
var listSubscriptionsForStore = async (http, storeId) => {
|
|
845
|
+
return http.paginate("/v1/subscriptions", {
|
|
846
|
+
"filter[store_id]": String(storeId)
|
|
847
|
+
});
|
|
848
|
+
};
|
|
849
|
+
var updateSubscription = async (http, subscriptionId, body) => {
|
|
850
|
+
return http.patchResource(`/v1/subscriptions/${subscriptionId}`, body);
|
|
851
|
+
};
|
|
852
|
+
var cancelSubscription = async (http, subscriptionId) => {
|
|
853
|
+
const doc = await http.request({
|
|
854
|
+
method: "DELETE",
|
|
855
|
+
path: `/v1/subscriptions/${subscriptionId}`
|
|
856
|
+
});
|
|
857
|
+
return doc?.data;
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
// src/resources/usageRecords.ts
|
|
861
|
+
var getUsageRecord = async (http, usageRecordId) => {
|
|
862
|
+
return http.getResource(`/v1/usage-records/${usageRecordId}`);
|
|
863
|
+
};
|
|
864
|
+
var listUsageRecordsForSubscriptionItem = async (http, subscriptionItemId) => {
|
|
865
|
+
return http.paginate("/v1/usage-records", {
|
|
866
|
+
"filter[subscription_item_id]": String(subscriptionItemId)
|
|
867
|
+
});
|
|
868
|
+
};
|
|
869
|
+
var createUsageRecord = async (http, body) => {
|
|
870
|
+
return http.postResource("/v1/usage-records", body);
|
|
871
|
+
};
|
|
177
872
|
|
|
178
873
|
// src/resources/users.ts
|
|
179
|
-
async
|
|
874
|
+
var getAuthenticatedUser = async (http) => {
|
|
180
875
|
return http.request({ path: "/v1/users/me" });
|
|
181
|
-
}
|
|
182
|
-
|
|
876
|
+
};
|
|
877
|
+
var userResource = (doc) => {
|
|
183
878
|
return doc.data;
|
|
184
|
-
}
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
// src/resources/variants.ts
|
|
882
|
+
var getVariant = async (http, variantId) => {
|
|
883
|
+
return http.getResource(`/v1/variants/${variantId}`);
|
|
884
|
+
};
|
|
885
|
+
var listVariantsForProduct = async (http, productId) => {
|
|
886
|
+
return http.paginate("/v1/variants", {
|
|
887
|
+
"filter[product_id]": String(productId)
|
|
888
|
+
});
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
// src/resources/webhooks.ts
|
|
892
|
+
var getWebhook = async (http, webhookId) => {
|
|
893
|
+
return http.getResource(`/v1/webhooks/${webhookId}`);
|
|
894
|
+
};
|
|
895
|
+
var listWebhooksForStore = async (http, storeId) => {
|
|
896
|
+
return http.paginate("/v1/webhooks", {
|
|
897
|
+
"filter[store_id]": String(storeId)
|
|
898
|
+
});
|
|
899
|
+
};
|
|
900
|
+
var createWebhook = async (http, body) => {
|
|
901
|
+
return http.postResource("/v1/webhooks", body);
|
|
902
|
+
};
|
|
903
|
+
var updateWebhook = async (http, webhookId, body) => {
|
|
904
|
+
return http.patchResource(`/v1/webhooks/${webhookId}`, body);
|
|
905
|
+
};
|
|
906
|
+
var deleteWebhook = async (http, webhookId) => {
|
|
907
|
+
await http.deleteResource(`/v1/webhooks/${webhookId}`);
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
// src/resources/invokeOp.ts
|
|
911
|
+
var invokeOp = async (http, resource, verb, args = {}) => {
|
|
912
|
+
const spec = findResourceVerb(resource, verb);
|
|
913
|
+
if (!spec) {
|
|
914
|
+
throw new FreshSqueezyError({
|
|
915
|
+
code: "UNKNOWN_OP",
|
|
916
|
+
message: `Unknown or unsupported op: ${verb} ${resource}. Run \`fresh-squeezy ops --list\`.`
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
const key = `${spec.resource}:${spec.verb}`;
|
|
920
|
+
switch (key) {
|
|
921
|
+
case "user:get":
|
|
922
|
+
return userResource(await getAuthenticatedUser(http));
|
|
923
|
+
case "store:get":
|
|
924
|
+
return getStore(http, requireId(args, "store"));
|
|
925
|
+
case "store:list":
|
|
926
|
+
return listStores(http);
|
|
927
|
+
case "product:get":
|
|
928
|
+
return getProduct(http, requireId(args, "product"));
|
|
929
|
+
case "product:list":
|
|
930
|
+
return listProducts(http, requireStore(args));
|
|
931
|
+
case "variant:get":
|
|
932
|
+
return getVariant(http, requireId(args, "variant"));
|
|
933
|
+
case "variant:list":
|
|
934
|
+
return listVariantsForProduct(http, requireParent(args, "product"));
|
|
935
|
+
case "price:get":
|
|
936
|
+
return getPrice(http, requireId(args, "price"));
|
|
937
|
+
case "price:list":
|
|
938
|
+
return listPricesForVariant(http, requireParent(args, "variant"));
|
|
939
|
+
case "file:get":
|
|
940
|
+
return getFile(http, requireId(args, "file"));
|
|
941
|
+
case "file:list":
|
|
942
|
+
return listFilesForVariant(http, requireParent(args, "variant"));
|
|
943
|
+
case "customer:get":
|
|
944
|
+
return getCustomer(http, requireId(args, "customer"));
|
|
945
|
+
case "customer:list":
|
|
946
|
+
return listCustomersForStore(http, requireStore(args));
|
|
947
|
+
case "customer:create":
|
|
948
|
+
return createCustomer(http, requireBody(args));
|
|
949
|
+
case "customer:update":
|
|
950
|
+
return updateCustomer(http, requireId(args, "customer"), requireBody(args));
|
|
951
|
+
case "order:get":
|
|
952
|
+
return getOrder(http, requireId(args, "order"));
|
|
953
|
+
case "order:list":
|
|
954
|
+
return listOrdersForStore(http, requireStore(args));
|
|
955
|
+
case "order:refund":
|
|
956
|
+
return refundOrder(http, requireId(args, "order"), args.body);
|
|
957
|
+
case "order:generate-invoice":
|
|
958
|
+
return generateOrderInvoice(http, requireId(args, "order"), args.body);
|
|
959
|
+
case "order-item:get":
|
|
960
|
+
return getOrderItem(http, requireId(args, "order-item"));
|
|
961
|
+
case "order-item:list":
|
|
962
|
+
return listOrderItemsForOrder(http, requireParent(args, "order"));
|
|
963
|
+
case "subscription:get":
|
|
964
|
+
return getSubscription(http, requireId(args, "subscription"));
|
|
965
|
+
case "subscription:list":
|
|
966
|
+
return listSubscriptionsForStore(http, requireStore(args));
|
|
967
|
+
case "subscription:update":
|
|
968
|
+
return updateSubscription(http, requireId(args, "subscription"), requireBody(args));
|
|
969
|
+
case "subscription:cancel":
|
|
970
|
+
return cancelSubscription(http, requireId(args, "subscription"));
|
|
971
|
+
case "subscription-item:get":
|
|
972
|
+
return getSubscriptionItem(http, requireId(args, "subscription-item"));
|
|
973
|
+
case "subscription-item:list":
|
|
974
|
+
return listSubscriptionItemsForSubscription(http, requireParent(args, "subscription"));
|
|
975
|
+
case "subscription-item:update":
|
|
976
|
+
return updateSubscriptionItem(http, requireId(args, "subscription-item"), requireBody(args));
|
|
977
|
+
case "subscription-item:current-usage":
|
|
978
|
+
return getSubscriptionItemCurrentUsage(http, requireId(args, "subscription-item"));
|
|
979
|
+
case "subscription-invoice:get":
|
|
980
|
+
return getSubscriptionInvoice(http, requireId(args, "subscription-invoice"));
|
|
981
|
+
case "subscription-invoice:list":
|
|
982
|
+
return listSubscriptionInvoicesForSubscription(http, requireParent(args, "subscription"));
|
|
983
|
+
case "subscription-invoice:refund":
|
|
984
|
+
return refundSubscriptionInvoice(http, requireId(args, "subscription-invoice"), args.body);
|
|
985
|
+
case "subscription-invoice:generate-invoice":
|
|
986
|
+
return generateSubscriptionInvoice(http, requireId(args, "subscription-invoice"), args.body);
|
|
987
|
+
case "usage-record:get":
|
|
988
|
+
return getUsageRecord(http, requireId(args, "usage-record"));
|
|
989
|
+
case "usage-record:list":
|
|
990
|
+
return listUsageRecordsForSubscriptionItem(http, requireParent(args, "subscription-item"));
|
|
991
|
+
case "usage-record:create":
|
|
992
|
+
return createUsageRecord(http, requireBody(args));
|
|
993
|
+
case "discount:get":
|
|
994
|
+
return getDiscount(http, requireId(args, "discount"));
|
|
995
|
+
case "discount:list":
|
|
996
|
+
return listDiscountsForStore(http, requireStore(args));
|
|
997
|
+
case "discount:create":
|
|
998
|
+
return createDiscount(http, requireBody(args));
|
|
999
|
+
case "discount:delete":
|
|
1000
|
+
await deleteDiscount(http, requireId(args, "discount"));
|
|
1001
|
+
return void 0;
|
|
1002
|
+
case "discount-redemption:get":
|
|
1003
|
+
return getDiscountRedemption(http, requireId(args, "discount-redemption"));
|
|
1004
|
+
case "discount-redemption:list":
|
|
1005
|
+
return listDiscountRedemptionsForDiscount(http, requireParent(args, "discount"));
|
|
1006
|
+
case "license-key:get":
|
|
1007
|
+
return getLicenseKey(http, requireId(args, "license-key"));
|
|
1008
|
+
case "license-key:list":
|
|
1009
|
+
return listLicenseKeysForStore(http, requireStore(args));
|
|
1010
|
+
case "license-key:update":
|
|
1011
|
+
return updateLicenseKey(http, requireId(args, "license-key"), requireBody(args));
|
|
1012
|
+
case "license-key-instance:get":
|
|
1013
|
+
return getLicenseKeyInstance(http, requireId(args, "license-key-instance"));
|
|
1014
|
+
case "license-key-instance:list":
|
|
1015
|
+
return listLicenseKeyInstancesForLicenseKey(http, requireParent(args, "license-key"));
|
|
1016
|
+
case "checkout:get":
|
|
1017
|
+
return getCheckout(http, requireId(args, "checkout"));
|
|
1018
|
+
case "checkout:list":
|
|
1019
|
+
return listCheckoutsForStore(http, requireStore(args));
|
|
1020
|
+
case "checkout:create":
|
|
1021
|
+
return createCheckout(http, requireBody(args));
|
|
1022
|
+
case "webhook:get":
|
|
1023
|
+
return getWebhook(http, requireId(args, "webhook"));
|
|
1024
|
+
case "webhook:list":
|
|
1025
|
+
return listWebhooksForStore(http, requireStore(args));
|
|
1026
|
+
case "webhook:create":
|
|
1027
|
+
return createWebhook(http, requireBody(args));
|
|
1028
|
+
case "webhook:update":
|
|
1029
|
+
return updateWebhook(http, requireId(args, "webhook"), requireBody(args));
|
|
1030
|
+
case "webhook:delete":
|
|
1031
|
+
await deleteWebhook(http, requireId(args, "webhook"));
|
|
1032
|
+
return void 0;
|
|
1033
|
+
case "affiliate:get":
|
|
1034
|
+
return getAffiliate(http, requireId(args, "affiliate"));
|
|
1035
|
+
case "affiliate:list":
|
|
1036
|
+
return listAffiliatesForStore(http, requireStore(args));
|
|
1037
|
+
default:
|
|
1038
|
+
throw new FreshSqueezyError({
|
|
1039
|
+
code: "UNKNOWN_OP",
|
|
1040
|
+
message: `Op registered but not wired: ${key}`
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
var requireId = (args, label) => {
|
|
1045
|
+
if (args.id === void 0 || args.id === "") {
|
|
1046
|
+
throw new FreshSqueezyError({
|
|
1047
|
+
code: "MISSING_ARG",
|
|
1048
|
+
message: `--id is required for this ${label} operation.`
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
return args.id;
|
|
1052
|
+
};
|
|
1053
|
+
var requireStore = (args) => {
|
|
1054
|
+
if (args.storeId === void 0 || args.storeId === "") {
|
|
1055
|
+
throw new FreshSqueezyError({
|
|
1056
|
+
code: "MISSING_ARG",
|
|
1057
|
+
message: "--store-ids (or store id) is required for this list operation."
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
return args.storeId;
|
|
1061
|
+
};
|
|
1062
|
+
var requireParent = (args, label) => {
|
|
1063
|
+
if (args.parentId === void 0 || args.parentId === "") {
|
|
1064
|
+
throw new FreshSqueezyError({
|
|
1065
|
+
code: "MISSING_ARG",
|
|
1066
|
+
message: `--parent-id (${label} id) is required for this list operation.`
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
return args.parentId;
|
|
1070
|
+
};
|
|
1071
|
+
var requireBody = (args) => {
|
|
1072
|
+
if (args.body === void 0) {
|
|
1073
|
+
throw new FreshSqueezyError({
|
|
1074
|
+
code: "MISSING_ARG",
|
|
1075
|
+
message: "A JSON body is required (--body, --body-file, or stdin)."
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
return args.body;
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1081
|
+
// src/core/mode.ts
|
|
1082
|
+
var resolveActualMode = (testMode) => {
|
|
1083
|
+
if (testMode === true) return "test";
|
|
1084
|
+
if (testMode === false) return "live";
|
|
1085
|
+
return void 0;
|
|
1086
|
+
};
|
|
185
1087
|
|
|
186
1088
|
// src/validate/rules.ts
|
|
187
1089
|
var ISSUE_CODES = {
|
|
@@ -220,16 +1122,16 @@ var ISSUE_CODES = {
|
|
|
220
1122
|
NETWORK_ERROR: "NETWORK_ERROR",
|
|
221
1123
|
UNKNOWN: "UNKNOWN"
|
|
222
1124
|
};
|
|
223
|
-
|
|
1125
|
+
var issue = (code, severity, message, extras = {}) => {
|
|
224
1126
|
const base = { code, severity, message };
|
|
225
1127
|
if (extras.suggestedFix !== void 0) base.suggestedFix = extras.suggestedFix;
|
|
226
1128
|
if (extras.context !== void 0) base.context = extras.context;
|
|
227
1129
|
return base;
|
|
228
|
-
}
|
|
229
|
-
|
|
1130
|
+
};
|
|
1131
|
+
var isOk = (issues) => {
|
|
230
1132
|
return !issues.some((entry) => entry.severity === "error");
|
|
231
|
-
}
|
|
232
|
-
|
|
1133
|
+
};
|
|
1134
|
+
var buildResult = (name, mode, issues, resource, target) => {
|
|
233
1135
|
const result = {
|
|
234
1136
|
name,
|
|
235
1137
|
ok: isOk(issues),
|
|
@@ -239,10 +1141,10 @@ function buildResult(name, mode, issues, resource, target) {
|
|
|
239
1141
|
if (resource !== void 0) result.resource = resource;
|
|
240
1142
|
if (target !== void 0) result.target = target;
|
|
241
1143
|
return result;
|
|
242
|
-
}
|
|
1144
|
+
};
|
|
243
1145
|
|
|
244
1146
|
// src/validate/probe.ts
|
|
245
|
-
|
|
1147
|
+
var mapErrorToIssue = (err, mapping = {}) => {
|
|
246
1148
|
if (err instanceof FreshSqueezyError) {
|
|
247
1149
|
if (mapping.unauthorized && (err.status === 401 || err.code === "UNAUTHORIZED")) {
|
|
248
1150
|
return issue(mapping.unauthorized.code, "error", mapping.unauthorized.message, {
|
|
@@ -269,8 +1171,8 @@ function mapErrorToIssue(err, mapping = {}) {
|
|
|
269
1171
|
}
|
|
270
1172
|
const message = err instanceof Error ? err.message : "Unknown error";
|
|
271
1173
|
return issue(ISSUE_CODES.UNKNOWN, "error", message);
|
|
272
|
-
}
|
|
273
|
-
async
|
|
1174
|
+
};
|
|
1175
|
+
var probeFetch = async (fetcher, options) => {
|
|
274
1176
|
return probeCollection(fetcher, {
|
|
275
1177
|
notFound: {
|
|
276
1178
|
code: options.notFoundCode,
|
|
@@ -279,15 +1181,15 @@ async function probeFetch(fetcher, options) {
|
|
|
279
1181
|
...options.notFoundContext !== void 0 ? { context: options.notFoundContext } : {}
|
|
280
1182
|
}
|
|
281
1183
|
});
|
|
282
|
-
}
|
|
283
|
-
async
|
|
1184
|
+
};
|
|
1185
|
+
var probeCollection = async (fetcher, mapping = {}) => {
|
|
284
1186
|
try {
|
|
285
1187
|
return { ok: true, resource: await fetcher() };
|
|
286
1188
|
} catch (err) {
|
|
287
1189
|
return { ok: false, issue: mapErrorToIssue(err, mapping) };
|
|
288
1190
|
}
|
|
289
|
-
}
|
|
290
|
-
|
|
1191
|
+
};
|
|
1192
|
+
var checkStoreOwnership = (check) => {
|
|
291
1193
|
const expected = String(check.expectedStoreId);
|
|
292
1194
|
const actual = String(check.actualStoreId);
|
|
293
1195
|
if (expected === actual) return null;
|
|
@@ -305,10 +1207,10 @@ function checkStoreOwnership(check) {
|
|
|
305
1207
|
context
|
|
306
1208
|
}
|
|
307
1209
|
);
|
|
308
|
-
}
|
|
1210
|
+
};
|
|
309
1211
|
|
|
310
1212
|
// src/validate/connection.ts
|
|
311
|
-
async
|
|
1213
|
+
var validateConnection = async (http, mode) => {
|
|
312
1214
|
const issues = [];
|
|
313
1215
|
const fetched = await probeCollection(
|
|
314
1216
|
async () => {
|
|
@@ -361,19 +1263,14 @@ async function validateConnection(http, mode) {
|
|
|
361
1263
|
);
|
|
362
1264
|
}
|
|
363
1265
|
return buildResult("connection", mode, issues, summary);
|
|
364
|
-
}
|
|
365
|
-
async
|
|
1266
|
+
};
|
|
1267
|
+
var fetchActualMode = async (http) => {
|
|
366
1268
|
const doc = await getAuthenticatedUser(http);
|
|
367
1269
|
return resolveActualMode(doc.meta?.test_mode);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// src/resources/discounts.ts
|
|
371
|
-
async function getDiscount(http, discountId) {
|
|
372
|
-
return http.getResource(`/v1/discounts/${discountId}`);
|
|
373
|
-
}
|
|
1270
|
+
};
|
|
374
1271
|
|
|
375
1272
|
// src/validate/discount.ts
|
|
376
|
-
async
|
|
1273
|
+
var validateDiscount = async (http, mode, options) => {
|
|
377
1274
|
const issues = [];
|
|
378
1275
|
const fetched = await probeFetch(() => getDiscount(http, options.discountId), {
|
|
379
1276
|
notFoundCode: ISSUE_CODES.DISCOUNT_NOT_FOUND,
|
|
@@ -394,8 +1291,8 @@ async function validateDiscount(http, mode, options) {
|
|
|
394
1291
|
label: `${attrs.name} (${attrs.code})`,
|
|
395
1292
|
id: String(options.discountId)
|
|
396
1293
|
});
|
|
397
|
-
}
|
|
398
|
-
|
|
1294
|
+
};
|
|
1295
|
+
var checkDiscount = (attrs, options) => {
|
|
399
1296
|
const issues = [];
|
|
400
1297
|
const mismatch = checkStoreOwnership({
|
|
401
1298
|
expectedStoreId: options.storeId,
|
|
@@ -484,15 +1381,10 @@ function checkDiscount(attrs, options) {
|
|
|
484
1381
|
);
|
|
485
1382
|
}
|
|
486
1383
|
return issues;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
// src/resources/licenseKeys.ts
|
|
490
|
-
async function getLicenseKey(http, licenseKeyId) {
|
|
491
|
-
return http.getResource(`/v1/license-keys/${licenseKeyId}`);
|
|
492
|
-
}
|
|
1384
|
+
};
|
|
493
1385
|
|
|
494
1386
|
// src/validate/licenseKey.ts
|
|
495
|
-
async
|
|
1387
|
+
var validateLicenseKey = async (http, mode, options) => {
|
|
496
1388
|
const issues = [];
|
|
497
1389
|
const fetched = await probeFetch(() => getLicenseKey(http, options.licenseKeyId), {
|
|
498
1390
|
notFoundCode: ISSUE_CODES.LICENSE_KEY_NOT_FOUND,
|
|
@@ -513,8 +1405,8 @@ async function validateLicenseKey(http, mode, options) {
|
|
|
513
1405
|
label: attrs.key_short,
|
|
514
1406
|
id: String(options.licenseKeyId)
|
|
515
1407
|
});
|
|
516
|
-
}
|
|
517
|
-
|
|
1408
|
+
};
|
|
1409
|
+
var checkLicenseKey = (attrs, options) => {
|
|
518
1410
|
const issues = [];
|
|
519
1411
|
const mismatch = checkStoreOwnership({
|
|
520
1412
|
expectedStoreId: options.storeId,
|
|
@@ -568,30 +1460,10 @@ function checkLicenseKey(attrs, options) {
|
|
|
568
1460
|
);
|
|
569
1461
|
}
|
|
570
1462
|
return issues;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// src/resources/products.ts
|
|
574
|
-
async function getProduct(http, productId) {
|
|
575
|
-
return http.getResource(`/v1/products/${productId}`);
|
|
576
|
-
}
|
|
577
|
-
async function listProducts(http, storeId) {
|
|
578
|
-
return http.paginate("/v1/products", {
|
|
579
|
-
"filter[store_id]": String(storeId)
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// src/resources/variants.ts
|
|
584
|
-
async function getVariant(http, variantId) {
|
|
585
|
-
return http.getResource(`/v1/variants/${variantId}`);
|
|
586
|
-
}
|
|
587
|
-
async function listVariantsForProduct(http, productId) {
|
|
588
|
-
return http.paginate("/v1/variants", {
|
|
589
|
-
"filter[product_id]": String(productId)
|
|
590
|
-
});
|
|
591
|
-
}
|
|
1463
|
+
};
|
|
592
1464
|
|
|
593
1465
|
// src/validate/product.ts
|
|
594
|
-
async
|
|
1466
|
+
var validateProduct = async (http, mode, options) => {
|
|
595
1467
|
const issues = [];
|
|
596
1468
|
const fetched = await probeFetch(() => getProduct(http, options.productId), {
|
|
597
1469
|
notFoundCode: ISSUE_CODES.PRODUCT_NOT_FOUND,
|
|
@@ -637,8 +1509,8 @@ async function validateProduct(http, mode, options) {
|
|
|
637
1509
|
label: attrs.name,
|
|
638
1510
|
id: String(options.productId)
|
|
639
1511
|
});
|
|
640
|
-
}
|
|
641
|
-
|
|
1512
|
+
};
|
|
1513
|
+
var checkProduct = (attrs, options = {}) => {
|
|
642
1514
|
const issues = [];
|
|
643
1515
|
if (options.expectedStoreId !== void 0) {
|
|
644
1516
|
const mismatch = checkStoreOwnership({
|
|
@@ -674,10 +1546,10 @@ function checkProduct(attrs, options = {}) {
|
|
|
674
1546
|
);
|
|
675
1547
|
}
|
|
676
1548
|
return issues;
|
|
677
|
-
}
|
|
1549
|
+
};
|
|
678
1550
|
|
|
679
1551
|
// src/validate/store.ts
|
|
680
|
-
async
|
|
1552
|
+
var validateStore = async (http, mode, storeId) => {
|
|
681
1553
|
const issues = [];
|
|
682
1554
|
const fetched = await probeFetch(() => getStore(http, storeId), {
|
|
683
1555
|
notFoundCode: ISSUE_CODES.STORE_NOT_FOUND,
|
|
@@ -696,11 +1568,11 @@ async function validateStore(http, mode, storeId) {
|
|
|
696
1568
|
label: fetched.resource.attributes.name,
|
|
697
1569
|
id: String(storeId)
|
|
698
1570
|
});
|
|
699
|
-
}
|
|
1571
|
+
};
|
|
700
1572
|
|
|
701
1573
|
// src/validate/subscriptionPlan.ts
|
|
702
1574
|
var VALID_INTERVALS = /* @__PURE__ */ new Set(["day", "week", "month", "year"]);
|
|
703
|
-
async
|
|
1575
|
+
var validateSubscriptionPlan = async (http, mode, options) => {
|
|
704
1576
|
const issues = [];
|
|
705
1577
|
const fetched = await probeFetch(
|
|
706
1578
|
() => getVariant(http, options.variantId),
|
|
@@ -746,8 +1618,8 @@ async function validateSubscriptionPlan(http, mode, options) {
|
|
|
746
1618
|
label: attrs.name,
|
|
747
1619
|
id: String(options.variantId)
|
|
748
1620
|
});
|
|
749
|
-
}
|
|
750
|
-
|
|
1621
|
+
};
|
|
1622
|
+
var checkSubscriptionPlan = (attrs, options) => {
|
|
751
1623
|
const issues = [];
|
|
752
1624
|
if (!attrs.is_subscription) {
|
|
753
1625
|
issues.push(
|
|
@@ -831,22 +1703,15 @@ function checkSubscriptionPlan(attrs, options) {
|
|
|
831
1703
|
);
|
|
832
1704
|
}
|
|
833
1705
|
return issues;
|
|
834
|
-
}
|
|
1706
|
+
};
|
|
835
1707
|
|
|
836
1708
|
// src/core/equality.ts
|
|
837
|
-
|
|
1709
|
+
var sameWebhookUrl = (a, b) => {
|
|
838
1710
|
return normalizeWebhookUrl(a) === normalizeWebhookUrl(b);
|
|
839
|
-
}
|
|
840
|
-
|
|
1711
|
+
};
|
|
1712
|
+
var normalizeWebhookUrl = (raw) => {
|
|
841
1713
|
return raw.replace(/\/+$/, "").toLowerCase();
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
// src/resources/webhooks.ts
|
|
845
|
-
async function listWebhooksForStore(http, storeId) {
|
|
846
|
-
return http.paginate("/v1/webhooks", {
|
|
847
|
-
"filter[store_id]": String(storeId)
|
|
848
|
-
});
|
|
849
|
-
}
|
|
1714
|
+
};
|
|
850
1715
|
|
|
851
1716
|
// src/generated/lemonSqueezyApiTypes.ts
|
|
852
1717
|
var GENERATED_LEMON_SQUEEZY_RESOURCES = [
|
|
@@ -1022,7 +1887,7 @@ var ACKNOWLEDGED_CHANGELOG_ENTRIES = [
|
|
|
1022
1887
|
];
|
|
1023
1888
|
|
|
1024
1889
|
// src/validate/webhook.ts
|
|
1025
|
-
async
|
|
1890
|
+
var validateWebhook = async (http, mode, options) => {
|
|
1026
1891
|
const issues = [];
|
|
1027
1892
|
const fetched = await probeCollection(() => listWebhooksForStore(http, options.storeId));
|
|
1028
1893
|
if (!fetched.ok) {
|
|
@@ -1082,7 +1947,7 @@ async function validateWebhook(http, mode, options) {
|
|
|
1082
1947
|
id: match.id,
|
|
1083
1948
|
url: match.attributes.url
|
|
1084
1949
|
});
|
|
1085
|
-
}
|
|
1950
|
+
};
|
|
1086
1951
|
|
|
1087
1952
|
// src/validate/doctor.ts
|
|
1088
1953
|
var DEFAULT_VALIDATORS = {
|
|
@@ -1094,7 +1959,7 @@ var DEFAULT_VALIDATORS = {
|
|
|
1094
1959
|
licenseKey: validateLicenseKey,
|
|
1095
1960
|
subscriptionPlan: validateSubscriptionPlan
|
|
1096
1961
|
};
|
|
1097
|
-
async
|
|
1962
|
+
var doctor = async (http, mode, options = {}, validators = DEFAULT_VALIDATORS) => {
|
|
1098
1963
|
assertOptionsCoherent(options);
|
|
1099
1964
|
const results = [];
|
|
1100
1965
|
const productIds = collectValues(options.productId, options.productIds);
|
|
@@ -1160,8 +2025,8 @@ async function doctor(http, mode, options = {}, validators = DEFAULT_VALIDATORS)
|
|
|
1160
2025
|
}
|
|
1161
2026
|
const ok = results.every((result) => result.ok);
|
|
1162
2027
|
return { ok, mode, results };
|
|
1163
|
-
}
|
|
1164
|
-
|
|
2028
|
+
};
|
|
2029
|
+
var assertOptionsCoherent = (options) => {
|
|
1165
2030
|
if (options.storeId !== void 0) return;
|
|
1166
2031
|
const dependent = [];
|
|
1167
2032
|
if (hasAny(options.webhookUrl, options.webhookUrls)) dependent.push("webhookUrl");
|
|
@@ -1173,23 +2038,24 @@ function assertOptionsCoherent(options) {
|
|
|
1173
2038
|
code: "DOCTOR_OPTIONS_INVALID",
|
|
1174
2039
|
message: `doctor() received ${dependent.join(", ")} without storeId. These validators cannot run without a store; pass \`storeId\` or remove the dependent options.`
|
|
1175
2040
|
});
|
|
1176
|
-
}
|
|
1177
|
-
|
|
2041
|
+
};
|
|
2042
|
+
var collectValues = (single, many) => {
|
|
1178
2043
|
const values = /* @__PURE__ */ new Set();
|
|
1179
2044
|
if (single !== void 0) values.add(single);
|
|
1180
2045
|
for (const value of many ?? []) {
|
|
1181
2046
|
if (value !== void 0) values.add(value);
|
|
1182
2047
|
}
|
|
1183
2048
|
return Array.from(values);
|
|
1184
|
-
}
|
|
1185
|
-
|
|
2049
|
+
};
|
|
2050
|
+
var hasAny = (single, many) => {
|
|
1186
2051
|
return single !== void 0 || (many?.length ?? 0) > 0;
|
|
1187
|
-
}
|
|
2052
|
+
};
|
|
1188
2053
|
|
|
1189
2054
|
// src/createFreshSqueezy.ts
|
|
1190
|
-
|
|
2055
|
+
var createFreshSqueezy = (config = {}) => {
|
|
1191
2056
|
const resolved = resolveConfig(config);
|
|
1192
2057
|
const http = new HttpClient(resolved);
|
|
2058
|
+
const op = (resource, verb, args = {}) => invokeOp(http, resource, verb, args);
|
|
1193
2059
|
return {
|
|
1194
2060
|
mode: resolved.mode,
|
|
1195
2061
|
request: (options) => http.request(options),
|
|
@@ -1212,141 +2078,106 @@ function createFreshSqueezy(config = {}) {
|
|
|
1212
2078
|
licenseKeyIds: options?.licenseKeyIds,
|
|
1213
2079
|
variantId: options?.variantId,
|
|
1214
2080
|
variantIds: options?.variantIds
|
|
1215
|
-
})
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
);
|
|
1313
|
-
}
|
|
1314
|
-
async function listSubscriptionInvoicesForSubscription(http, subscriptionId) {
|
|
1315
|
-
return http.paginate("/v1/subscription-invoices", {
|
|
1316
|
-
"filter[subscription_id]": String(subscriptionId)
|
|
1317
|
-
});
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
// src/resources/subscriptionItems.ts
|
|
1321
|
-
async function getSubscriptionItem(http, subscriptionItemId) {
|
|
1322
|
-
return http.getResource(
|
|
1323
|
-
`/v1/subscription-items/${subscriptionItemId}`
|
|
1324
|
-
);
|
|
1325
|
-
}
|
|
1326
|
-
async function listSubscriptionItemsForSubscription(http, subscriptionId) {
|
|
1327
|
-
return http.paginate("/v1/subscription-items", {
|
|
1328
|
-
"filter[subscription_id]": String(subscriptionId)
|
|
1329
|
-
});
|
|
1330
|
-
}
|
|
1331
|
-
function buildSubscriptionItemUpdateBody(subscriptionItemId, attributes) {
|
|
1332
|
-
return {
|
|
1333
|
-
data: {
|
|
1334
|
-
type: "subscription-items",
|
|
1335
|
-
id: String(subscriptionItemId),
|
|
1336
|
-
attributes
|
|
2081
|
+
}),
|
|
2082
|
+
users: {
|
|
2083
|
+
me: () => op("user", "get")
|
|
2084
|
+
},
|
|
2085
|
+
stores: {
|
|
2086
|
+
get: (id) => op("store", "get", { id }),
|
|
2087
|
+
list: () => op("store", "list")
|
|
2088
|
+
},
|
|
2089
|
+
products: {
|
|
2090
|
+
get: (id) => op("product", "get", { id }),
|
|
2091
|
+
list: (storeId) => op("product", "list", { storeId })
|
|
2092
|
+
},
|
|
2093
|
+
variants: {
|
|
2094
|
+
get: (id) => op("variant", "get", { id }),
|
|
2095
|
+
list: (productId) => op("variant", "list", { parentId: productId })
|
|
2096
|
+
},
|
|
2097
|
+
prices: {
|
|
2098
|
+
get: (id) => op("price", "get", { id }),
|
|
2099
|
+
list: (variantId) => op("price", "list", { parentId: variantId })
|
|
2100
|
+
},
|
|
2101
|
+
files: {
|
|
2102
|
+
get: (id) => op("file", "get", { id }),
|
|
2103
|
+
list: (variantId) => op("file", "list", { parentId: variantId })
|
|
2104
|
+
},
|
|
2105
|
+
customers: {
|
|
2106
|
+
get: (id) => op("customer", "get", { id }),
|
|
2107
|
+
list: (storeId) => op("customer", "list", { storeId }),
|
|
2108
|
+
create: (body) => op("customer", "create", { body }),
|
|
2109
|
+
update: (id, body) => op("customer", "update", { id, body })
|
|
2110
|
+
},
|
|
2111
|
+
orders: {
|
|
2112
|
+
get: (id) => op("order", "get", { id }),
|
|
2113
|
+
list: (storeId) => op("order", "list", { storeId }),
|
|
2114
|
+
refund: (id, body) => op("order", "refund", { id, body }),
|
|
2115
|
+
generateInvoice: (id, body) => op("order", "generate-invoice", { id, body })
|
|
2116
|
+
},
|
|
2117
|
+
orderItems: {
|
|
2118
|
+
get: (id) => op("order-item", "get", { id }),
|
|
2119
|
+
list: (orderId) => op("order-item", "list", { parentId: orderId })
|
|
2120
|
+
},
|
|
2121
|
+
subscriptions: {
|
|
2122
|
+
get: (id) => op("subscription", "get", { id }),
|
|
2123
|
+
list: (storeId) => op("subscription", "list", { storeId }),
|
|
2124
|
+
update: (id, body) => op("subscription", "update", { id, body }),
|
|
2125
|
+
cancel: (id) => op("subscription", "cancel", { id })
|
|
2126
|
+
},
|
|
2127
|
+
subscriptionItems: {
|
|
2128
|
+
get: (id) => op("subscription-item", "get", { id }),
|
|
2129
|
+
list: (subscriptionId) => op("subscription-item", "list", { parentId: subscriptionId }),
|
|
2130
|
+
update: (id, body) => op("subscription-item", "update", { id, body }),
|
|
2131
|
+
currentUsage: (id) => op("subscription-item", "current-usage", { id })
|
|
2132
|
+
},
|
|
2133
|
+
subscriptionInvoices: {
|
|
2134
|
+
get: (id) => op("subscription-invoice", "get", { id }),
|
|
2135
|
+
list: (subscriptionId) => op("subscription-invoice", "list", { parentId: subscriptionId }),
|
|
2136
|
+
refund: (id, body) => op("subscription-invoice", "refund", { id, body }),
|
|
2137
|
+
generateInvoice: (id, body) => op("subscription-invoice", "generate-invoice", { id, body })
|
|
2138
|
+
},
|
|
2139
|
+
usageRecords: {
|
|
2140
|
+
get: (id) => op("usage-record", "get", { id }),
|
|
2141
|
+
list: (subscriptionItemId) => op("usage-record", "list", { parentId: subscriptionItemId }),
|
|
2142
|
+
create: (body) => op("usage-record", "create", { body })
|
|
2143
|
+
},
|
|
2144
|
+
discounts: {
|
|
2145
|
+
get: (id) => op("discount", "get", { id }),
|
|
2146
|
+
list: (storeId) => op("discount", "list", { storeId }),
|
|
2147
|
+
create: (body) => op("discount", "create", { body }),
|
|
2148
|
+
delete: (id) => op("discount", "delete", { id })
|
|
2149
|
+
},
|
|
2150
|
+
discountRedemptions: {
|
|
2151
|
+
get: (id) => op("discount-redemption", "get", { id }),
|
|
2152
|
+
list: (discountId) => op("discount-redemption", "list", { parentId: discountId })
|
|
2153
|
+
},
|
|
2154
|
+
licenseKeys: {
|
|
2155
|
+
get: (id) => op("license-key", "get", { id }),
|
|
2156
|
+
list: (storeId) => op("license-key", "list", { storeId }),
|
|
2157
|
+
update: (id, body) => op("license-key", "update", { id, body })
|
|
2158
|
+
},
|
|
2159
|
+
licenseKeyInstances: {
|
|
2160
|
+
get: (id) => op("license-key-instance", "get", { id }),
|
|
2161
|
+
list: (licenseKeyId) => op("license-key-instance", "list", { parentId: licenseKeyId })
|
|
2162
|
+
},
|
|
2163
|
+
checkouts: {
|
|
2164
|
+
get: (id) => op("checkout", "get", { id }),
|
|
2165
|
+
list: (storeId) => op("checkout", "list", { storeId }),
|
|
2166
|
+
create: (body) => op("checkout", "create", { body })
|
|
2167
|
+
},
|
|
2168
|
+
webhooks: {
|
|
2169
|
+
get: (id) => op("webhook", "get", { id }),
|
|
2170
|
+
list: (storeId) => op("webhook", "list", { storeId }),
|
|
2171
|
+
create: (body) => op("webhook", "create", { body }),
|
|
2172
|
+
update: (id, body) => op("webhook", "update", { id, body }),
|
|
2173
|
+
delete: (id) => op("webhook", "delete", { id })
|
|
2174
|
+
},
|
|
2175
|
+
affiliates: {
|
|
2176
|
+
get: (id) => op("affiliate", "get", { id }),
|
|
2177
|
+
list: (storeId) => op("affiliate", "list", { storeId })
|
|
1337
2178
|
}
|
|
1338
2179
|
};
|
|
1339
|
-
}
|
|
1340
|
-
|
|
1341
|
-
// src/resources/usageRecords.ts
|
|
1342
|
-
async function getUsageRecord(http, usageRecordId) {
|
|
1343
|
-
return http.getResource(`/v1/usage-records/${usageRecordId}`);
|
|
1344
|
-
}
|
|
1345
|
-
async function listUsageRecordsForSubscriptionItem(http, subscriptionItemId) {
|
|
1346
|
-
return http.paginate("/v1/usage-records", {
|
|
1347
|
-
"filter[subscription_item_id]": String(subscriptionItemId)
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
2180
|
+
};
|
|
1350
2181
|
export {
|
|
1351
2182
|
ACKNOWLEDGED_CHANGELOG_ENTRIES,
|
|
1352
2183
|
DEFAULT_VALIDATORS,
|
|
@@ -1360,19 +2191,32 @@ export {
|
|
|
1360
2191
|
SUPPORTED_RESOURCES,
|
|
1361
2192
|
buildResult,
|
|
1362
2193
|
buildSubscriptionItemUpdateBody,
|
|
2194
|
+
cancelSubscription,
|
|
1363
2195
|
checkDiscount,
|
|
1364
2196
|
checkLicenseKey,
|
|
1365
2197
|
checkProduct,
|
|
1366
2198
|
checkSubscriptionPlan,
|
|
2199
|
+
createCheckout,
|
|
2200
|
+
createCustomer,
|
|
2201
|
+
createDiscount,
|
|
1367
2202
|
createFreshSqueezy,
|
|
2203
|
+
createUsageRecord,
|
|
2204
|
+
createWebhook,
|
|
2205
|
+
deleteDiscount,
|
|
2206
|
+
deleteWebhook,
|
|
1368
2207
|
doctor,
|
|
1369
2208
|
fetchActualMode,
|
|
2209
|
+
findResourceVerb,
|
|
2210
|
+
generateOrderInvoice,
|
|
2211
|
+
generateSubscriptionInvoice,
|
|
1370
2212
|
getAffiliate,
|
|
1371
2213
|
getAuthenticatedUser,
|
|
1372
2214
|
getCheckout,
|
|
1373
2215
|
getCustomer,
|
|
2216
|
+
getDiscount,
|
|
1374
2217
|
getDiscountRedemption,
|
|
1375
2218
|
getFile,
|
|
2219
|
+
getLicenseKey,
|
|
1376
2220
|
getLicenseKeyInstance,
|
|
1377
2221
|
getOrder,
|
|
1378
2222
|
getOrderItem,
|
|
@@ -1382,27 +2226,44 @@ export {
|
|
|
1382
2226
|
getSubscription,
|
|
1383
2227
|
getSubscriptionInvoice,
|
|
1384
2228
|
getSubscriptionItem,
|
|
2229
|
+
getSubscriptionItemCurrentUsage,
|
|
1385
2230
|
getUsageRecord,
|
|
1386
2231
|
getVariant,
|
|
2232
|
+
getWebhook,
|
|
2233
|
+
invokeOp,
|
|
1387
2234
|
isOk,
|
|
1388
2235
|
issue,
|
|
1389
2236
|
listAffiliatesForStore,
|
|
1390
2237
|
listCheckoutsForStore,
|
|
1391
2238
|
listCustomersForStore,
|
|
1392
2239
|
listDiscountRedemptionsForDiscount,
|
|
2240
|
+
listDiscountsForStore,
|
|
1393
2241
|
listFilesForVariant,
|
|
1394
2242
|
listLicenseKeyInstancesForLicenseKey,
|
|
2243
|
+
listLicenseKeysForStore,
|
|
1395
2244
|
listOrderItemsForOrder,
|
|
2245
|
+
listOrdersForStore,
|
|
2246
|
+
listPricesForVariant,
|
|
1396
2247
|
listProducts,
|
|
2248
|
+
listRegisteredResources,
|
|
1397
2249
|
listStores,
|
|
1398
2250
|
listSubscriptionInvoicesForSubscription,
|
|
1399
2251
|
listSubscriptionItemsForSubscription,
|
|
2252
|
+
listSubscriptionsForStore,
|
|
1400
2253
|
listUsageRecordsForSubscriptionItem,
|
|
1401
2254
|
listVariantsForProduct,
|
|
1402
2255
|
listWebhooksForStore,
|
|
2256
|
+
refundOrder,
|
|
2257
|
+
refundSubscriptionInvoice,
|
|
1403
2258
|
resolveActualMode,
|
|
1404
2259
|
resolveConfig,
|
|
2260
|
+
resourceRegistry,
|
|
1405
2261
|
sameWebhookUrl,
|
|
2262
|
+
updateCustomer,
|
|
2263
|
+
updateLicenseKey,
|
|
2264
|
+
updateSubscription,
|
|
2265
|
+
updateSubscriptionItem,
|
|
2266
|
+
updateWebhook,
|
|
1406
2267
|
userResource,
|
|
1407
2268
|
validateConnection,
|
|
1408
2269
|
validateDiscount,
|