@moonbase.sh/api 0.2.114 → 0.2.115
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/index.cjs +214 -38
- package/dist/index.d.cts +1865 -65
- package/dist/index.d.ts +1865 -65
- package/dist/index.js +213 -38
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -204,38 +204,61 @@ var CustomerEndpoints = class {
|
|
|
204
204
|
|
|
205
205
|
// src/globalSchemas.ts
|
|
206
206
|
import { z as z6 } from "zod";
|
|
207
|
+
var userSchema = z6.object({
|
|
208
|
+
id: z6.string(),
|
|
209
|
+
name: z6.string(),
|
|
210
|
+
email: z6.string()
|
|
211
|
+
});
|
|
212
|
+
var entityChangeSchema = z6.object({
|
|
213
|
+
at: z6.coerce.date(),
|
|
214
|
+
by: userSchema
|
|
215
|
+
});
|
|
216
|
+
var moneySchema = z6.object({
|
|
217
|
+
currency: z6.string(),
|
|
218
|
+
amount: z6.number()
|
|
219
|
+
});
|
|
207
220
|
var priceCollectionSchema = z6.record(z6.number());
|
|
208
221
|
var percentageOffDiscountSchema = z6.object({
|
|
209
222
|
type: z6.literal("PercentageOffDiscount"),
|
|
210
|
-
|
|
211
|
-
description: z6.string().optional(),
|
|
212
|
-
percentage: z6.number(),
|
|
213
|
-
total: priceCollectionSchema
|
|
223
|
+
percentage: z6.number()
|
|
214
224
|
});
|
|
215
225
|
var flatAmountOffDiscountSchema = z6.object({
|
|
216
226
|
type: z6.literal("FlatAmountOffDiscount"),
|
|
217
|
-
name: z6.string(),
|
|
218
|
-
description: z6.string().optional(),
|
|
219
227
|
total: priceCollectionSchema
|
|
220
228
|
});
|
|
221
229
|
var discountSchema = z6.discriminatedUnion("type", [
|
|
222
230
|
percentageOffDiscountSchema,
|
|
223
231
|
flatAmountOffDiscountSchema
|
|
224
232
|
]);
|
|
233
|
+
var dateTimeSpanSchema = z6.object({
|
|
234
|
+
from: z6.coerce.date().nullable(),
|
|
235
|
+
to: z6.coerce.date().nullable()
|
|
236
|
+
});
|
|
237
|
+
var pricingDiscountSchema = z6.object({
|
|
238
|
+
name: z6.string(),
|
|
239
|
+
description: z6.string().nullable(),
|
|
240
|
+
discount: discountSchema,
|
|
241
|
+
applicableVariationIds: z6.string().array().nullable(),
|
|
242
|
+
validity: dateTimeSpanSchema.nullable()
|
|
243
|
+
});
|
|
225
244
|
var pricingVariationSchema = z6.object({
|
|
226
245
|
id: z6.string(),
|
|
227
246
|
name: z6.string(),
|
|
228
|
-
|
|
229
|
-
price: priceCollectionSchema,
|
|
230
|
-
hasDiscount: z6.boolean(),
|
|
231
|
-
discount: discountSchema.optional()
|
|
247
|
+
price: priceCollectionSchema
|
|
232
248
|
});
|
|
233
|
-
function paged(itemSchema) {
|
|
249
|
+
function paged(itemSchema, api) {
|
|
234
250
|
return z6.object({
|
|
235
251
|
items: z6.array(itemSchema),
|
|
236
252
|
hasMore: z6.boolean(),
|
|
237
253
|
next: z6.string().nullable()
|
|
238
|
-
})
|
|
254
|
+
}).transform((page) => ({
|
|
255
|
+
...page,
|
|
256
|
+
getNext: () => {
|
|
257
|
+
if (!page.hasMore || !page.next)
|
|
258
|
+
throw new Error("Response indicates no more results");
|
|
259
|
+
return api.fetch(page.next).then((response) => paged(itemSchema, api).parse(response.data));
|
|
260
|
+
}
|
|
261
|
+
}));
|
|
239
262
|
}
|
|
240
263
|
function quantifiable(itemSchema) {
|
|
241
264
|
return z6.object({
|
|
@@ -247,9 +270,6 @@ function quantifiable(itemSchema) {
|
|
|
247
270
|
// src/utils/api.ts
|
|
248
271
|
import fetch from "cross-fetch";
|
|
249
272
|
|
|
250
|
-
// src/utils/problemHandler.ts
|
|
251
|
-
import { z as z7 } from "zod";
|
|
252
|
-
|
|
253
273
|
// src/utils/errors.ts
|
|
254
274
|
var MoonbaseError = class extends Error {
|
|
255
275
|
constructor(problemDetails) {
|
|
@@ -290,6 +310,7 @@ var ConflictError = class extends MoonbaseError {
|
|
|
290
310
|
};
|
|
291
311
|
|
|
292
312
|
// src/utils/problemHandler.ts
|
|
313
|
+
import { z as z7 } from "zod";
|
|
293
314
|
var problemDetailsSchema = z7.object({
|
|
294
315
|
type: z7.string(),
|
|
295
316
|
title: z7.string(),
|
|
@@ -339,6 +360,14 @@ var MoonbaseApi = class {
|
|
|
339
360
|
},
|
|
340
361
|
body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
|
|
341
362
|
});
|
|
363
|
+
if (response.status === 500) {
|
|
364
|
+
throw new MoonbaseError({
|
|
365
|
+
status: 500,
|
|
366
|
+
title: "Unknown error",
|
|
367
|
+
detail: "An unknown error occurred",
|
|
368
|
+
type: "InternalServerError"
|
|
369
|
+
});
|
|
370
|
+
}
|
|
342
371
|
if (response.status >= 400)
|
|
343
372
|
await handleResponseProblem(response);
|
|
344
373
|
const contentLength = Number(response.headers.get("Content-Length")) || 0;
|
|
@@ -357,7 +386,7 @@ var LicenseEndpoints = class {
|
|
|
357
386
|
}
|
|
358
387
|
async query(opts) {
|
|
359
388
|
const response = await this.api.fetch(`/api/licenses?${objectToQuery(opts)}`);
|
|
360
|
-
return paged(licenseSchema).parse(response.data);
|
|
389
|
+
return paged(licenseSchema, this.api).parse(response.data);
|
|
361
390
|
}
|
|
362
391
|
async get(licenseId) {
|
|
363
392
|
const response = await this.api.fetch(`/api/licenses/${licenseId}`);
|
|
@@ -374,7 +403,7 @@ var LicenseEndpoints = class {
|
|
|
374
403
|
}
|
|
375
404
|
async queryActivations(licenseId, opts) {
|
|
376
405
|
const response = await this.api.fetch(`/api/licenses/${licenseId}/activations?${objectToQuery(opts)}`);
|
|
377
|
-
return paged(licenseActivationSchema).parse(response.data);
|
|
406
|
+
return paged(licenseActivationSchema, this.api).parse(response.data);
|
|
378
407
|
}
|
|
379
408
|
async getActivation(licenseId, activationId) {
|
|
380
409
|
const response = await this.api.fetch(`/api/licenses/${licenseId}/activations/${activationId}`);
|
|
@@ -390,6 +419,150 @@ var LicenseEndpoints = class {
|
|
|
390
419
|
}
|
|
391
420
|
};
|
|
392
421
|
|
|
422
|
+
// src/orders/schemas.ts
|
|
423
|
+
import { z as z8 } from "zod";
|
|
424
|
+
|
|
425
|
+
// src/orders/models.ts
|
|
426
|
+
var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
|
|
427
|
+
OrderStatus2["Open"] = "Open";
|
|
428
|
+
OrderStatus2["PaymentProcessing"] = "PaymentProcessing";
|
|
429
|
+
OrderStatus2["Completed"] = "Completed";
|
|
430
|
+
OrderStatus2["Failed"] = "Failed";
|
|
431
|
+
return OrderStatus2;
|
|
432
|
+
})(OrderStatus || {});
|
|
433
|
+
|
|
434
|
+
// src/orders/schemas.ts
|
|
435
|
+
var couponSchema = z8.object({
|
|
436
|
+
code: z8.string(),
|
|
437
|
+
name: z8.string(),
|
|
438
|
+
description: z8.string()
|
|
439
|
+
});
|
|
440
|
+
var licenseLineItemFulfillmentSchema = z8.object({
|
|
441
|
+
type: z8.literal("License"),
|
|
442
|
+
licenseIds: z8.string().array()
|
|
443
|
+
});
|
|
444
|
+
var bundleLineItemFulfillmentSchema = z8.object({
|
|
445
|
+
type: z8.literal("Bundle"),
|
|
446
|
+
productLicenses: z8.record(z8.string(), z8.object({
|
|
447
|
+
licenseIds: z8.string().array()
|
|
448
|
+
}))
|
|
449
|
+
});
|
|
450
|
+
var lineItemFulfillmentSchema = z8.discriminatedUnion("type", [
|
|
451
|
+
licenseLineItemFulfillmentSchema,
|
|
452
|
+
bundleLineItemFulfillmentSchema
|
|
453
|
+
]);
|
|
454
|
+
var lineItemTotalSchema = z8.object({
|
|
455
|
+
original: moneySchema,
|
|
456
|
+
discount: moneySchema,
|
|
457
|
+
subtotal: moneySchema,
|
|
458
|
+
due: moneySchema
|
|
459
|
+
});
|
|
460
|
+
var lineItemPayoutSchema = z8.object({
|
|
461
|
+
subtotal: moneySchema,
|
|
462
|
+
taxes: moneySchema,
|
|
463
|
+
platformFees: moneySchema,
|
|
464
|
+
due: moneySchema
|
|
465
|
+
});
|
|
466
|
+
var affiliatePayoutSchema = z8.object({
|
|
467
|
+
payout: moneySchema,
|
|
468
|
+
affiliateId: z8.string(),
|
|
469
|
+
contractId: z8.string()
|
|
470
|
+
});
|
|
471
|
+
var productLineItemSchema = z8.object({
|
|
472
|
+
type: z8.literal("Product"),
|
|
473
|
+
productId: z8.string(),
|
|
474
|
+
quantity: z8.number(),
|
|
475
|
+
variationId: z8.string(),
|
|
476
|
+
price: priceCollectionSchema.optional(),
|
|
477
|
+
total: lineItemTotalSchema.optional(),
|
|
478
|
+
payout: lineItemPayoutSchema.optional(),
|
|
479
|
+
affiliatePayouts: affiliatePayoutSchema.array().optional(),
|
|
480
|
+
variation: pricingVariationSchema.optional(),
|
|
481
|
+
appliedDiscount: pricingDiscountSchema.optional(),
|
|
482
|
+
fulfillment: lineItemFulfillmentSchema.optional()
|
|
483
|
+
});
|
|
484
|
+
var bundleLineItemSchema = z8.object({
|
|
485
|
+
type: z8.literal("Bundle"),
|
|
486
|
+
bundleId: z8.string(),
|
|
487
|
+
quantity: z8.number(),
|
|
488
|
+
variationId: z8.string(),
|
|
489
|
+
price: priceCollectionSchema.optional(),
|
|
490
|
+
total: lineItemTotalSchema.optional(),
|
|
491
|
+
payout: lineItemPayoutSchema.optional(),
|
|
492
|
+
affiliatePayouts: affiliatePayoutSchema.array().optional(),
|
|
493
|
+
variation: pricingVariationSchema.optional(),
|
|
494
|
+
appliedDiscount: pricingDiscountSchema.optional(),
|
|
495
|
+
fulfillment: lineItemFulfillmentSchema.optional()
|
|
496
|
+
});
|
|
497
|
+
var orderLineItemSchema = z8.discriminatedUnion("type", [
|
|
498
|
+
productLineItemSchema,
|
|
499
|
+
bundleLineItemSchema
|
|
500
|
+
]);
|
|
501
|
+
var orderTotalSchema = z8.object({
|
|
502
|
+
original: moneySchema,
|
|
503
|
+
discount: moneySchema,
|
|
504
|
+
subtotal: moneySchema,
|
|
505
|
+
taxes: moneySchema,
|
|
506
|
+
due: moneySchema
|
|
507
|
+
});
|
|
508
|
+
var orderPayoutSchema = z8.object({
|
|
509
|
+
subtotal: moneySchema,
|
|
510
|
+
taxes: moneySchema,
|
|
511
|
+
platformFees: moneySchema,
|
|
512
|
+
due: moneySchema,
|
|
513
|
+
feeBreakdown: z8.string().array()
|
|
514
|
+
});
|
|
515
|
+
var customerSnapshotSchema = z8.object({
|
|
516
|
+
name: z8.string().nullable(),
|
|
517
|
+
businessName: z8.string().nullable(),
|
|
518
|
+
taxId: z8.string().nullable(),
|
|
519
|
+
email: z8.string().nullable(),
|
|
520
|
+
address: addressSchema.nullable()
|
|
521
|
+
});
|
|
522
|
+
var utmSchema = z8.object({
|
|
523
|
+
referrer: z8.string().optional(),
|
|
524
|
+
source: z8.string().optional(),
|
|
525
|
+
medium: z8.string().optional(),
|
|
526
|
+
campaign: z8.string().optional(),
|
|
527
|
+
term: z8.string().optional(),
|
|
528
|
+
content: z8.string().optional()
|
|
529
|
+
});
|
|
530
|
+
var orderSchema = z8.object({
|
|
531
|
+
id: z8.string(),
|
|
532
|
+
status: z8.nativeEnum(OrderStatus),
|
|
533
|
+
currency: z8.string(),
|
|
534
|
+
completedAt: z8.coerce.date().optional(),
|
|
535
|
+
isRefunded: z8.boolean(),
|
|
536
|
+
refundedAt: z8.coerce.date().optional(),
|
|
537
|
+
isDisputed: z8.boolean(),
|
|
538
|
+
total: orderTotalSchema.optional(),
|
|
539
|
+
payout: orderPayoutSchema.optional(),
|
|
540
|
+
merchantPayout: moneySchema.optional(),
|
|
541
|
+
affiliatePayouts: affiliatePayoutSchema.array().optional(),
|
|
542
|
+
initialUTM: utmSchema.optional(),
|
|
543
|
+
currentUTM: utmSchema.optional(),
|
|
544
|
+
customer: customerSnapshotSchema.optional(),
|
|
545
|
+
couponsApplied: couponSchema.array(),
|
|
546
|
+
items: orderLineItemSchema.array(),
|
|
547
|
+
lastUpdated: entityChangeSchema,
|
|
548
|
+
created: entityChangeSchema
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
// src/orders/endpoints.ts
|
|
552
|
+
var OrderEndpoints = class {
|
|
553
|
+
constructor(api) {
|
|
554
|
+
this.api = api;
|
|
555
|
+
}
|
|
556
|
+
async query(opts) {
|
|
557
|
+
const response = await this.api.fetch(`/api/orders?${objectToQuery(opts)}`);
|
|
558
|
+
return paged(orderSchema, this.api).parse(response.data);
|
|
559
|
+
}
|
|
560
|
+
async get(id) {
|
|
561
|
+
const response = await this.api.fetch(`/api/orders/${id}`);
|
|
562
|
+
return orderSchema.parse(response.data);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
|
|
393
566
|
// src/products/endpoints.ts
|
|
394
567
|
var ProductEndpoints = class {
|
|
395
568
|
constructor(api) {
|
|
@@ -397,7 +570,7 @@ var ProductEndpoints = class {
|
|
|
397
570
|
}
|
|
398
571
|
async query(opts) {
|
|
399
572
|
const response = await this.api.fetch(`/api/products?${objectToQuery(opts)}`);
|
|
400
|
-
return paged(productSchema).parse(response.data);
|
|
573
|
+
return paged(productSchema, this.api).parse(response.data);
|
|
401
574
|
}
|
|
402
575
|
async get(id) {
|
|
403
576
|
const response = await this.api.fetch(`/api/products/${id}`);
|
|
@@ -422,34 +595,34 @@ var TrialEndpoints = class {
|
|
|
422
595
|
};
|
|
423
596
|
|
|
424
597
|
// src/vouchers/schemas.ts
|
|
425
|
-
import { z as
|
|
598
|
+
import { z as z10 } from "zod";
|
|
426
599
|
|
|
427
600
|
// src/bundles/schemas.ts
|
|
428
|
-
import { z as
|
|
429
|
-
var bundleSchema =
|
|
430
|
-
id:
|
|
431
|
-
name:
|
|
432
|
-
tagline:
|
|
433
|
-
description:
|
|
434
|
-
iconUrl:
|
|
435
|
-
purchasable:
|
|
436
|
-
partialPurchaseEnabled:
|
|
601
|
+
import { z as z9 } from "zod";
|
|
602
|
+
var bundleSchema = z9.object({
|
|
603
|
+
id: z9.string(),
|
|
604
|
+
name: z9.string(),
|
|
605
|
+
tagline: z9.string(),
|
|
606
|
+
description: z9.string(),
|
|
607
|
+
iconUrl: z9.string().nullable(),
|
|
608
|
+
purchasable: z9.boolean(),
|
|
609
|
+
partialPurchaseEnabled: z9.boolean()
|
|
437
610
|
});
|
|
438
611
|
|
|
439
612
|
// src/vouchers/schemas.ts
|
|
440
|
-
var voucherSchema =
|
|
441
|
-
id:
|
|
442
|
-
description:
|
|
443
|
-
numberOfCodes:
|
|
444
|
-
numberOfRedemptions:
|
|
613
|
+
var voucherSchema = z10.object({
|
|
614
|
+
id: z10.string(),
|
|
615
|
+
description: z10.string(),
|
|
616
|
+
numberOfCodes: z10.number(),
|
|
617
|
+
numberOfRedemptions: z10.number(),
|
|
445
618
|
redeemsProducts: quantifiable(productSchema).array(),
|
|
446
619
|
redeemsBundles: quantifiable(bundleSchema).array()
|
|
447
620
|
});
|
|
448
|
-
var createVoucherRequestSchema =
|
|
449
|
-
name:
|
|
450
|
-
description:
|
|
451
|
-
productEntitlements:
|
|
452
|
-
bundleEntitlements:
|
|
621
|
+
var createVoucherRequestSchema = z10.object({
|
|
622
|
+
name: z10.string(),
|
|
623
|
+
description: z10.string(),
|
|
624
|
+
productEntitlements: z10.record(z10.string(), z10.number()).optional(),
|
|
625
|
+
bundleEntitlements: z10.record(z10.string(), z10.number()).optional()
|
|
453
626
|
});
|
|
454
627
|
|
|
455
628
|
// src/vouchers/endpoints.ts
|
|
@@ -482,6 +655,7 @@ var MoonbaseClient = class {
|
|
|
482
655
|
this.products = new ProductEndpoints(api);
|
|
483
656
|
this.trials = new TrialEndpoints(api);
|
|
484
657
|
this.vouchers = new VoucherEndpoints(api);
|
|
658
|
+
this.orders = new OrderEndpoints(api);
|
|
485
659
|
}
|
|
486
660
|
};
|
|
487
661
|
export {
|
|
@@ -495,6 +669,7 @@ export {
|
|
|
495
669
|
NotAuthenticatedError,
|
|
496
670
|
NotAuthorizedError,
|
|
497
671
|
NotFoundError,
|
|
672
|
+
OrderStatus,
|
|
498
673
|
ProductStatus,
|
|
499
674
|
TrialStatus
|
|
500
675
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.115",
|
|
5
5
|
"description": "Package to let you integrate backends with Moonbase.sh as payment and delivery provider",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
"@types/node": "^18.19.50",
|
|
21
21
|
"rimraf": "^5.0.10",
|
|
22
22
|
"tsup": "^7.1.0",
|
|
23
|
-
"typescript": "~5.1.6"
|
|
23
|
+
"typescript": "~5.1.6",
|
|
24
|
+
"vitest": "^2.1.4"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
27
28
|
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
28
|
-
"version": "npm version"
|
|
29
|
+
"version": "npm version",
|
|
30
|
+
"test": "vitest"
|
|
29
31
|
}
|
|
30
32
|
}
|