@moonbase.sh/storefront-api 3.10.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +68 -1
- package/dist/index.d.cts +994 -2
- package/dist/index.d.ts +994 -2
- package/dist/index.js +68 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1229,7 +1229,7 @@ var ProductEndpoints = class {
|
|
|
1229
1229
|
import { z as z15 } from "zod";
|
|
1230
1230
|
|
|
1231
1231
|
// package.json
|
|
1232
|
-
var version = "3.
|
|
1232
|
+
var version = "3.11.0";
|
|
1233
1233
|
|
|
1234
1234
|
// src/utils/client.ts
|
|
1235
1235
|
function buildClientHeader(sdk) {
|
|
@@ -1385,6 +1385,10 @@ var MoonbaseApi = class {
|
|
|
1385
1385
|
var schemas_exports8 = {};
|
|
1386
1386
|
__export(schemas_exports8, {
|
|
1387
1387
|
milestoneProgressSchema: () => milestoneProgressSchema,
|
|
1388
|
+
pendingPlanChangeSchema: () => pendingPlanChangeSchema,
|
|
1389
|
+
pricingOptionSchema: () => pricingOptionSchema,
|
|
1390
|
+
subscriptionPlanOptionSchema: () => subscriptionPlanOptionSchema,
|
|
1391
|
+
subscriptionPlanOptionsSchema: () => subscriptionPlanOptionsSchema,
|
|
1388
1392
|
subscriptionSchema: () => subscriptionSchema
|
|
1389
1393
|
});
|
|
1390
1394
|
import { z as z14 } from "zod";
|
|
@@ -1594,6 +1598,33 @@ var milestoneProgressSchema = z14.object({
|
|
|
1594
1598
|
toNormalizedCycleNumber: z14.number(),
|
|
1595
1599
|
events: z14.record(z14.coerce.number(), milestoneProgressEventSchema.array())
|
|
1596
1600
|
});
|
|
1601
|
+
var pricingOptionSchema = z14.object({
|
|
1602
|
+
id: z14.string(),
|
|
1603
|
+
name: z14.string(),
|
|
1604
|
+
cycleLength: z14.nativeEnum(CycleLength)
|
|
1605
|
+
});
|
|
1606
|
+
var pendingPlanChangeSchema = z14.object({
|
|
1607
|
+
option: pricingOptionSchema,
|
|
1608
|
+
// The renewal that starts the new plan and charges `nextTotal`.
|
|
1609
|
+
takesEffectAt: z14.coerce.date(),
|
|
1610
|
+
nextTotal: orderTotalSchema,
|
|
1611
|
+
// Whether everything the subscription gets off now (discount, offer, coupons) still applies on the new plan.
|
|
1612
|
+
keepsDiscount: z14.boolean(),
|
|
1613
|
+
scheduledAt: z14.coerce.date()
|
|
1614
|
+
});
|
|
1615
|
+
var subscriptionPlanOptionSchema = z14.object({
|
|
1616
|
+
option: pricingOptionSchema,
|
|
1617
|
+
// What the next renewal charges on this plan. For the plan it is on, its normal renewal.
|
|
1618
|
+
nextTotal: orderTotalSchema,
|
|
1619
|
+
takesEffectAt: z14.coerce.date(),
|
|
1620
|
+
keepsDiscount: z14.boolean(),
|
|
1621
|
+
current: z14.boolean(),
|
|
1622
|
+
scheduled: z14.boolean()
|
|
1623
|
+
});
|
|
1624
|
+
var subscriptionPlanOptionsSchema = z14.object({
|
|
1625
|
+
unavailable: z14.string().nullish(),
|
|
1626
|
+
plans: subscriptionPlanOptionSchema.array()
|
|
1627
|
+
});
|
|
1597
1628
|
var subscriptionSchema = z14.object({
|
|
1598
1629
|
id: z14.string(),
|
|
1599
1630
|
status: z14.nativeEnum(SubscriptionStatus),
|
|
@@ -1608,6 +1639,10 @@ var subscriptionSchema = z14.object({
|
|
|
1608
1639
|
paymentMethod: z14.string().optional(),
|
|
1609
1640
|
milestoneProgress: milestoneProgressSchema.nullish(),
|
|
1610
1641
|
embeddedUpdatePaymentUrl: z14.string().optional(),
|
|
1642
|
+
// Older backends send neither, and one this version can't read is dropped rather than failing
|
|
1643
|
+
// the whole subscription.
|
|
1644
|
+
pricingOption: pricingOptionSchema.nullish().catch(void 0),
|
|
1645
|
+
pendingChange: pendingPlanChangeSchema.nullish().catch(void 0),
|
|
1611
1646
|
content: z14.discriminatedUnion("type", [
|
|
1612
1647
|
z14.object({
|
|
1613
1648
|
type: z14.literal("Product"),
|
|
@@ -1651,6 +1686,38 @@ var SubscriptionEndpoints = class {
|
|
|
1651
1686
|
});
|
|
1652
1687
|
return response.data;
|
|
1653
1688
|
}
|
|
1689
|
+
/**
|
|
1690
|
+
* The plans the subscription can switch to when its current period ends, each with what the
|
|
1691
|
+
* next renewal would charge on it. The plan it is on comes first. When it can't switch,
|
|
1692
|
+
* `unavailable` says why, ready to show to the customer.
|
|
1693
|
+
*/
|
|
1694
|
+
async getPlanOptions(subscriptionId) {
|
|
1695
|
+
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/plan-options`, subscriptionPlanOptionsSchema);
|
|
1696
|
+
return response.data;
|
|
1697
|
+
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Switches the subscription to another plan when its current period ends. Nothing is charged
|
|
1700
|
+
* now: the next renewal charges the new plan and starts its cycle. Until then the customer can
|
|
1701
|
+
* switch again, and passing the plan it is on keeps that plan. Returns the updated subscription,
|
|
1702
|
+
* with the switch in `pendingChange`.
|
|
1703
|
+
*/
|
|
1704
|
+
async changePlan(subscriptionId, variationId) {
|
|
1705
|
+
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/plan-change`, subscriptionSchema, {
|
|
1706
|
+
method: "POST",
|
|
1707
|
+
body: { variationId }
|
|
1708
|
+
});
|
|
1709
|
+
return response.data;
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Keeps the subscription on its current plan, dropping a switch scheduled with `changePlan`.
|
|
1713
|
+
* Returns the updated subscription.
|
|
1714
|
+
*/
|
|
1715
|
+
async cancelPlanChange(subscriptionId) {
|
|
1716
|
+
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/plan-change`, subscriptionSchema, {
|
|
1717
|
+
method: "DELETE"
|
|
1718
|
+
});
|
|
1719
|
+
return response.data;
|
|
1720
|
+
}
|
|
1654
1721
|
async renew(subscriptionId, returnUrl, embedded) {
|
|
1655
1722
|
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/renew?redirect=false&return=${returnUrl}&embedded=${embedded ? "true" : "false"}`, z15.object({
|
|
1656
1723
|
location: z15.string()
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/storefront-api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.11.0",
|
|
5
5
|
"description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|