@moonbase.sh/api 0.2.112 → 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.cjs
CHANGED
|
@@ -40,6 +40,7 @@ __export(src_exports, {
|
|
|
40
40
|
NotAuthenticatedError: () => NotAuthenticatedError,
|
|
41
41
|
NotAuthorizedError: () => NotAuthorizedError,
|
|
42
42
|
NotFoundError: () => NotFoundError,
|
|
43
|
+
OrderStatus: () => OrderStatus,
|
|
43
44
|
ProductStatus: () => ProductStatus,
|
|
44
45
|
TrialStatus: () => TrialStatus
|
|
45
46
|
});
|
|
@@ -251,38 +252,61 @@ var CustomerEndpoints = class {
|
|
|
251
252
|
|
|
252
253
|
// src/globalSchemas.ts
|
|
253
254
|
var import_zod6 = require("zod");
|
|
255
|
+
var userSchema = import_zod6.z.object({
|
|
256
|
+
id: import_zod6.z.string(),
|
|
257
|
+
name: import_zod6.z.string(),
|
|
258
|
+
email: import_zod6.z.string()
|
|
259
|
+
});
|
|
260
|
+
var entityChangeSchema = import_zod6.z.object({
|
|
261
|
+
at: import_zod6.z.coerce.date(),
|
|
262
|
+
by: userSchema
|
|
263
|
+
});
|
|
264
|
+
var moneySchema = import_zod6.z.object({
|
|
265
|
+
currency: import_zod6.z.string(),
|
|
266
|
+
amount: import_zod6.z.number()
|
|
267
|
+
});
|
|
254
268
|
var priceCollectionSchema = import_zod6.z.record(import_zod6.z.number());
|
|
255
269
|
var percentageOffDiscountSchema = import_zod6.z.object({
|
|
256
270
|
type: import_zod6.z.literal("PercentageOffDiscount"),
|
|
257
|
-
|
|
258
|
-
description: import_zod6.z.string().optional(),
|
|
259
|
-
percentage: import_zod6.z.number(),
|
|
260
|
-
total: priceCollectionSchema
|
|
271
|
+
percentage: import_zod6.z.number()
|
|
261
272
|
});
|
|
262
273
|
var flatAmountOffDiscountSchema = import_zod6.z.object({
|
|
263
274
|
type: import_zod6.z.literal("FlatAmountOffDiscount"),
|
|
264
|
-
name: import_zod6.z.string(),
|
|
265
|
-
description: import_zod6.z.string().optional(),
|
|
266
275
|
total: priceCollectionSchema
|
|
267
276
|
});
|
|
268
277
|
var discountSchema = import_zod6.z.discriminatedUnion("type", [
|
|
269
278
|
percentageOffDiscountSchema,
|
|
270
279
|
flatAmountOffDiscountSchema
|
|
271
280
|
]);
|
|
281
|
+
var dateTimeSpanSchema = import_zod6.z.object({
|
|
282
|
+
from: import_zod6.z.coerce.date().nullable(),
|
|
283
|
+
to: import_zod6.z.coerce.date().nullable()
|
|
284
|
+
});
|
|
285
|
+
var pricingDiscountSchema = import_zod6.z.object({
|
|
286
|
+
name: import_zod6.z.string(),
|
|
287
|
+
description: import_zod6.z.string().nullable(),
|
|
288
|
+
discount: discountSchema,
|
|
289
|
+
applicableVariationIds: import_zod6.z.string().array().nullable(),
|
|
290
|
+
validity: dateTimeSpanSchema.nullable()
|
|
291
|
+
});
|
|
272
292
|
var pricingVariationSchema = import_zod6.z.object({
|
|
273
293
|
id: import_zod6.z.string(),
|
|
274
294
|
name: import_zod6.z.string(),
|
|
275
|
-
|
|
276
|
-
price: priceCollectionSchema,
|
|
277
|
-
hasDiscount: import_zod6.z.boolean(),
|
|
278
|
-
discount: discountSchema.optional()
|
|
295
|
+
price: priceCollectionSchema
|
|
279
296
|
});
|
|
280
|
-
function paged(itemSchema) {
|
|
297
|
+
function paged(itemSchema, api) {
|
|
281
298
|
return import_zod6.z.object({
|
|
282
299
|
items: import_zod6.z.array(itemSchema),
|
|
283
300
|
hasMore: import_zod6.z.boolean(),
|
|
284
301
|
next: import_zod6.z.string().nullable()
|
|
285
|
-
})
|
|
302
|
+
}).transform((page) => ({
|
|
303
|
+
...page,
|
|
304
|
+
getNext: () => {
|
|
305
|
+
if (!page.hasMore || !page.next)
|
|
306
|
+
throw new Error("Response indicates no more results");
|
|
307
|
+
return api.fetch(page.next).then((response) => paged(itemSchema, api).parse(response.data));
|
|
308
|
+
}
|
|
309
|
+
}));
|
|
286
310
|
}
|
|
287
311
|
function quantifiable(itemSchema) {
|
|
288
312
|
return import_zod6.z.object({
|
|
@@ -294,9 +318,6 @@ function quantifiable(itemSchema) {
|
|
|
294
318
|
// src/utils/api.ts
|
|
295
319
|
var import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
296
320
|
|
|
297
|
-
// src/utils/problemHandler.ts
|
|
298
|
-
var import_zod7 = require("zod");
|
|
299
|
-
|
|
300
321
|
// src/utils/errors.ts
|
|
301
322
|
var MoonbaseError = class extends Error {
|
|
302
323
|
constructor(problemDetails) {
|
|
@@ -337,6 +358,7 @@ var ConflictError = class extends MoonbaseError {
|
|
|
337
358
|
};
|
|
338
359
|
|
|
339
360
|
// src/utils/problemHandler.ts
|
|
361
|
+
var import_zod7 = require("zod");
|
|
340
362
|
var problemDetailsSchema = import_zod7.z.object({
|
|
341
363
|
type: import_zod7.z.string(),
|
|
342
364
|
title: import_zod7.z.string(),
|
|
@@ -386,6 +408,14 @@ var MoonbaseApi = class {
|
|
|
386
408
|
},
|
|
387
409
|
body: body ? contentType !== "application/json" ? body : JSON.stringify(body) : void 0
|
|
388
410
|
});
|
|
411
|
+
if (response.status === 500) {
|
|
412
|
+
throw new MoonbaseError({
|
|
413
|
+
status: 500,
|
|
414
|
+
title: "Unknown error",
|
|
415
|
+
detail: "An unknown error occurred",
|
|
416
|
+
type: "InternalServerError"
|
|
417
|
+
});
|
|
418
|
+
}
|
|
389
419
|
if (response.status >= 400)
|
|
390
420
|
await handleResponseProblem(response);
|
|
391
421
|
const contentLength = Number(response.headers.get("Content-Length")) || 0;
|
|
@@ -404,7 +434,7 @@ var LicenseEndpoints = class {
|
|
|
404
434
|
}
|
|
405
435
|
async query(opts) {
|
|
406
436
|
const response = await this.api.fetch(`/api/licenses?${objectToQuery(opts)}`);
|
|
407
|
-
return paged(licenseSchema).parse(response.data);
|
|
437
|
+
return paged(licenseSchema, this.api).parse(response.data);
|
|
408
438
|
}
|
|
409
439
|
async get(licenseId) {
|
|
410
440
|
const response = await this.api.fetch(`/api/licenses/${licenseId}`);
|
|
@@ -421,7 +451,7 @@ var LicenseEndpoints = class {
|
|
|
421
451
|
}
|
|
422
452
|
async queryActivations(licenseId, opts) {
|
|
423
453
|
const response = await this.api.fetch(`/api/licenses/${licenseId}/activations?${objectToQuery(opts)}`);
|
|
424
|
-
return paged(licenseActivationSchema).parse(response.data);
|
|
454
|
+
return paged(licenseActivationSchema, this.api).parse(response.data);
|
|
425
455
|
}
|
|
426
456
|
async getActivation(licenseId, activationId) {
|
|
427
457
|
const response = await this.api.fetch(`/api/licenses/${licenseId}/activations/${activationId}`);
|
|
@@ -437,6 +467,150 @@ var LicenseEndpoints = class {
|
|
|
437
467
|
}
|
|
438
468
|
};
|
|
439
469
|
|
|
470
|
+
// src/orders/schemas.ts
|
|
471
|
+
var import_zod8 = require("zod");
|
|
472
|
+
|
|
473
|
+
// src/orders/models.ts
|
|
474
|
+
var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
|
|
475
|
+
OrderStatus2["Open"] = "Open";
|
|
476
|
+
OrderStatus2["PaymentProcessing"] = "PaymentProcessing";
|
|
477
|
+
OrderStatus2["Completed"] = "Completed";
|
|
478
|
+
OrderStatus2["Failed"] = "Failed";
|
|
479
|
+
return OrderStatus2;
|
|
480
|
+
})(OrderStatus || {});
|
|
481
|
+
|
|
482
|
+
// src/orders/schemas.ts
|
|
483
|
+
var couponSchema = import_zod8.z.object({
|
|
484
|
+
code: import_zod8.z.string(),
|
|
485
|
+
name: import_zod8.z.string(),
|
|
486
|
+
description: import_zod8.z.string()
|
|
487
|
+
});
|
|
488
|
+
var licenseLineItemFulfillmentSchema = import_zod8.z.object({
|
|
489
|
+
type: import_zod8.z.literal("License"),
|
|
490
|
+
licenseIds: import_zod8.z.string().array()
|
|
491
|
+
});
|
|
492
|
+
var bundleLineItemFulfillmentSchema = import_zod8.z.object({
|
|
493
|
+
type: import_zod8.z.literal("Bundle"),
|
|
494
|
+
productLicenses: import_zod8.z.record(import_zod8.z.string(), import_zod8.z.object({
|
|
495
|
+
licenseIds: import_zod8.z.string().array()
|
|
496
|
+
}))
|
|
497
|
+
});
|
|
498
|
+
var lineItemFulfillmentSchema = import_zod8.z.discriminatedUnion("type", [
|
|
499
|
+
licenseLineItemFulfillmentSchema,
|
|
500
|
+
bundleLineItemFulfillmentSchema
|
|
501
|
+
]);
|
|
502
|
+
var lineItemTotalSchema = import_zod8.z.object({
|
|
503
|
+
original: moneySchema,
|
|
504
|
+
discount: moneySchema,
|
|
505
|
+
subtotal: moneySchema,
|
|
506
|
+
due: moneySchema
|
|
507
|
+
});
|
|
508
|
+
var lineItemPayoutSchema = import_zod8.z.object({
|
|
509
|
+
subtotal: moneySchema,
|
|
510
|
+
taxes: moneySchema,
|
|
511
|
+
platformFees: moneySchema,
|
|
512
|
+
due: moneySchema
|
|
513
|
+
});
|
|
514
|
+
var affiliatePayoutSchema = import_zod8.z.object({
|
|
515
|
+
payout: moneySchema,
|
|
516
|
+
affiliateId: import_zod8.z.string(),
|
|
517
|
+
contractId: import_zod8.z.string()
|
|
518
|
+
});
|
|
519
|
+
var productLineItemSchema = import_zod8.z.object({
|
|
520
|
+
type: import_zod8.z.literal("Product"),
|
|
521
|
+
productId: import_zod8.z.string(),
|
|
522
|
+
quantity: import_zod8.z.number(),
|
|
523
|
+
variationId: import_zod8.z.string(),
|
|
524
|
+
price: priceCollectionSchema.optional(),
|
|
525
|
+
total: lineItemTotalSchema.optional(),
|
|
526
|
+
payout: lineItemPayoutSchema.optional(),
|
|
527
|
+
affiliatePayouts: affiliatePayoutSchema.array().optional(),
|
|
528
|
+
variation: pricingVariationSchema.optional(),
|
|
529
|
+
appliedDiscount: pricingDiscountSchema.optional(),
|
|
530
|
+
fulfillment: lineItemFulfillmentSchema.optional()
|
|
531
|
+
});
|
|
532
|
+
var bundleLineItemSchema = import_zod8.z.object({
|
|
533
|
+
type: import_zod8.z.literal("Bundle"),
|
|
534
|
+
bundleId: import_zod8.z.string(),
|
|
535
|
+
quantity: import_zod8.z.number(),
|
|
536
|
+
variationId: import_zod8.z.string(),
|
|
537
|
+
price: priceCollectionSchema.optional(),
|
|
538
|
+
total: lineItemTotalSchema.optional(),
|
|
539
|
+
payout: lineItemPayoutSchema.optional(),
|
|
540
|
+
affiliatePayouts: affiliatePayoutSchema.array().optional(),
|
|
541
|
+
variation: pricingVariationSchema.optional(),
|
|
542
|
+
appliedDiscount: pricingDiscountSchema.optional(),
|
|
543
|
+
fulfillment: lineItemFulfillmentSchema.optional()
|
|
544
|
+
});
|
|
545
|
+
var orderLineItemSchema = import_zod8.z.discriminatedUnion("type", [
|
|
546
|
+
productLineItemSchema,
|
|
547
|
+
bundleLineItemSchema
|
|
548
|
+
]);
|
|
549
|
+
var orderTotalSchema = import_zod8.z.object({
|
|
550
|
+
original: moneySchema,
|
|
551
|
+
discount: moneySchema,
|
|
552
|
+
subtotal: moneySchema,
|
|
553
|
+
taxes: moneySchema,
|
|
554
|
+
due: moneySchema
|
|
555
|
+
});
|
|
556
|
+
var orderPayoutSchema = import_zod8.z.object({
|
|
557
|
+
subtotal: moneySchema,
|
|
558
|
+
taxes: moneySchema,
|
|
559
|
+
platformFees: moneySchema,
|
|
560
|
+
due: moneySchema,
|
|
561
|
+
feeBreakdown: import_zod8.z.string().array()
|
|
562
|
+
});
|
|
563
|
+
var customerSnapshotSchema = import_zod8.z.object({
|
|
564
|
+
name: import_zod8.z.string().nullable(),
|
|
565
|
+
businessName: import_zod8.z.string().nullable(),
|
|
566
|
+
taxId: import_zod8.z.string().nullable(),
|
|
567
|
+
email: import_zod8.z.string().nullable(),
|
|
568
|
+
address: addressSchema.nullable()
|
|
569
|
+
});
|
|
570
|
+
var utmSchema = import_zod8.z.object({
|
|
571
|
+
referrer: import_zod8.z.string().optional(),
|
|
572
|
+
source: import_zod8.z.string().optional(),
|
|
573
|
+
medium: import_zod8.z.string().optional(),
|
|
574
|
+
campaign: import_zod8.z.string().optional(),
|
|
575
|
+
term: import_zod8.z.string().optional(),
|
|
576
|
+
content: import_zod8.z.string().optional()
|
|
577
|
+
});
|
|
578
|
+
var orderSchema = import_zod8.z.object({
|
|
579
|
+
id: import_zod8.z.string(),
|
|
580
|
+
status: import_zod8.z.nativeEnum(OrderStatus),
|
|
581
|
+
currency: import_zod8.z.string(),
|
|
582
|
+
completedAt: import_zod8.z.coerce.date().optional(),
|
|
583
|
+
isRefunded: import_zod8.z.boolean(),
|
|
584
|
+
refundedAt: import_zod8.z.coerce.date().optional(),
|
|
585
|
+
isDisputed: import_zod8.z.boolean(),
|
|
586
|
+
total: orderTotalSchema.optional(),
|
|
587
|
+
payout: orderPayoutSchema.optional(),
|
|
588
|
+
merchantPayout: moneySchema.optional(),
|
|
589
|
+
affiliatePayouts: affiliatePayoutSchema.array().optional(),
|
|
590
|
+
initialUTM: utmSchema.optional(),
|
|
591
|
+
currentUTM: utmSchema.optional(),
|
|
592
|
+
customer: customerSnapshotSchema.optional(),
|
|
593
|
+
couponsApplied: couponSchema.array(),
|
|
594
|
+
items: orderLineItemSchema.array(),
|
|
595
|
+
lastUpdated: entityChangeSchema,
|
|
596
|
+
created: entityChangeSchema
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
// src/orders/endpoints.ts
|
|
600
|
+
var OrderEndpoints = class {
|
|
601
|
+
constructor(api) {
|
|
602
|
+
this.api = api;
|
|
603
|
+
}
|
|
604
|
+
async query(opts) {
|
|
605
|
+
const response = await this.api.fetch(`/api/orders?${objectToQuery(opts)}`);
|
|
606
|
+
return paged(orderSchema, this.api).parse(response.data);
|
|
607
|
+
}
|
|
608
|
+
async get(id) {
|
|
609
|
+
const response = await this.api.fetch(`/api/orders/${id}`);
|
|
610
|
+
return orderSchema.parse(response.data);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
440
614
|
// src/products/endpoints.ts
|
|
441
615
|
var ProductEndpoints = class {
|
|
442
616
|
constructor(api) {
|
|
@@ -444,7 +618,7 @@ var ProductEndpoints = class {
|
|
|
444
618
|
}
|
|
445
619
|
async query(opts) {
|
|
446
620
|
const response = await this.api.fetch(`/api/products?${objectToQuery(opts)}`);
|
|
447
|
-
return paged(productSchema).parse(response.data);
|
|
621
|
+
return paged(productSchema, this.api).parse(response.data);
|
|
448
622
|
}
|
|
449
623
|
async get(id) {
|
|
450
624
|
const response = await this.api.fetch(`/api/products/${id}`);
|
|
@@ -469,34 +643,34 @@ var TrialEndpoints = class {
|
|
|
469
643
|
};
|
|
470
644
|
|
|
471
645
|
// src/vouchers/schemas.ts
|
|
472
|
-
var
|
|
646
|
+
var import_zod10 = require("zod");
|
|
473
647
|
|
|
474
648
|
// src/bundles/schemas.ts
|
|
475
|
-
var
|
|
476
|
-
var bundleSchema =
|
|
477
|
-
id:
|
|
478
|
-
name:
|
|
479
|
-
tagline:
|
|
480
|
-
description:
|
|
481
|
-
iconUrl:
|
|
482
|
-
purchasable:
|
|
483
|
-
partialPurchaseEnabled:
|
|
649
|
+
var import_zod9 = require("zod");
|
|
650
|
+
var bundleSchema = import_zod9.z.object({
|
|
651
|
+
id: import_zod9.z.string(),
|
|
652
|
+
name: import_zod9.z.string(),
|
|
653
|
+
tagline: import_zod9.z.string(),
|
|
654
|
+
description: import_zod9.z.string(),
|
|
655
|
+
iconUrl: import_zod9.z.string().nullable(),
|
|
656
|
+
purchasable: import_zod9.z.boolean(),
|
|
657
|
+
partialPurchaseEnabled: import_zod9.z.boolean()
|
|
484
658
|
});
|
|
485
659
|
|
|
486
660
|
// src/vouchers/schemas.ts
|
|
487
|
-
var voucherSchema =
|
|
488
|
-
id:
|
|
489
|
-
description:
|
|
490
|
-
numberOfCodes:
|
|
491
|
-
numberOfRedemptions:
|
|
661
|
+
var voucherSchema = import_zod10.z.object({
|
|
662
|
+
id: import_zod10.z.string(),
|
|
663
|
+
description: import_zod10.z.string(),
|
|
664
|
+
numberOfCodes: import_zod10.z.number(),
|
|
665
|
+
numberOfRedemptions: import_zod10.z.number(),
|
|
492
666
|
redeemsProducts: quantifiable(productSchema).array(),
|
|
493
667
|
redeemsBundles: quantifiable(bundleSchema).array()
|
|
494
668
|
});
|
|
495
|
-
var createVoucherRequestSchema =
|
|
496
|
-
name:
|
|
497
|
-
description:
|
|
498
|
-
productEntitlements:
|
|
499
|
-
bundleEntitlements:
|
|
669
|
+
var createVoucherRequestSchema = import_zod10.z.object({
|
|
670
|
+
name: import_zod10.z.string(),
|
|
671
|
+
description: import_zod10.z.string(),
|
|
672
|
+
productEntitlements: import_zod10.z.record(import_zod10.z.string(), import_zod10.z.number()).optional(),
|
|
673
|
+
bundleEntitlements: import_zod10.z.record(import_zod10.z.string(), import_zod10.z.number()).optional()
|
|
500
674
|
});
|
|
501
675
|
|
|
502
676
|
// src/vouchers/endpoints.ts
|
|
@@ -529,6 +703,7 @@ var MoonbaseClient = class {
|
|
|
529
703
|
this.products = new ProductEndpoints(api);
|
|
530
704
|
this.trials = new TrialEndpoints(api);
|
|
531
705
|
this.vouchers = new VoucherEndpoints(api);
|
|
706
|
+
this.orders = new OrderEndpoints(api);
|
|
532
707
|
}
|
|
533
708
|
};
|
|
534
709
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -543,6 +718,7 @@ var MoonbaseClient = class {
|
|
|
543
718
|
NotAuthenticatedError,
|
|
544
719
|
NotAuthorizedError,
|
|
545
720
|
NotFoundError,
|
|
721
|
+
OrderStatus,
|
|
546
722
|
ProductStatus,
|
|
547
723
|
TrialStatus
|
|
548
724
|
});
|