@moonbase.sh/storefront-api 3.10.0 → 3.12.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/README.md +7 -1
- package/dist/index.cjs +108 -6
- package/dist/index.d.cts +1042 -5
- package/dist/index.d.ts +1042 -5
- package/dist/index.js +105 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ var MarketingConsentType = /* @__PURE__ */ ((MarketingConsentType2) => {
|
|
|
51
51
|
return MarketingConsentType2;
|
|
52
52
|
})(MarketingConsentType || {});
|
|
53
53
|
function utmToObject(utm) {
|
|
54
|
+
var _a;
|
|
54
55
|
return Object.entries({
|
|
55
56
|
utm_source: utm == null ? void 0 : utm.source,
|
|
56
57
|
utm_medium: utm == null ? void 0 : utm.medium,
|
|
@@ -63,7 +64,8 @@ function utmToObject(utm) {
|
|
|
63
64
|
wbraid: utm == null ? void 0 : utm.wbraid,
|
|
64
65
|
fbclid: utm == null ? void 0 : utm.fbclid,
|
|
65
66
|
msclkid: utm == null ? void 0 : utm.msclkid,
|
|
66
|
-
ttclid: utm == null ? void 0 : utm.ttclid
|
|
67
|
+
ttclid: utm == null ? void 0 : utm.ttclid,
|
|
68
|
+
utm_ad_click: ((_a = utm == null ? void 0 : utm.adClicks) == null ? void 0 : _a.length) ? utm.adClicks.join(",") : void 0
|
|
67
69
|
}).filter(([_, value]) => value !== void 0).reduce((obj, [key, value]) => ({
|
|
68
70
|
...obj,
|
|
69
71
|
[key]: value
|
|
@@ -434,7 +436,11 @@ var storefrontSchema = z3.object({
|
|
|
434
436
|
// Promotions need to be optional since we may still have old, cached representations in browsers
|
|
435
437
|
promotions: storefrontPromotionsSchema.optional(),
|
|
436
438
|
// Depending on circumstances, we may have a tax estimate available
|
|
437
|
-
estimatedTax: taxEstimateSchema.optional()
|
|
439
|
+
estimatedTax: taxEstimateSchema.optional(),
|
|
440
|
+
// Whether the storefront has to wait for this visitor's cookie consent before it keeps ad click
|
|
441
|
+
// IDs or remembers their visit: the store's setting, for the country the visit comes from.
|
|
442
|
+
// Optional for older backends and cached catalogs, which count as asking.
|
|
443
|
+
cookieConsentRequired: z3.boolean().optional()
|
|
438
444
|
});
|
|
439
445
|
|
|
440
446
|
// src/activationRequests/models.ts
|
|
@@ -1229,7 +1235,7 @@ var ProductEndpoints = class {
|
|
|
1229
1235
|
import { z as z15 } from "zod";
|
|
1230
1236
|
|
|
1231
1237
|
// package.json
|
|
1232
|
-
var version = "3.
|
|
1238
|
+
var version = "3.12.0";
|
|
1233
1239
|
|
|
1234
1240
|
// src/utils/client.ts
|
|
1235
1241
|
function buildClientHeader(sdk) {
|
|
@@ -1385,6 +1391,10 @@ var MoonbaseApi = class {
|
|
|
1385
1391
|
var schemas_exports8 = {};
|
|
1386
1392
|
__export(schemas_exports8, {
|
|
1387
1393
|
milestoneProgressSchema: () => milestoneProgressSchema,
|
|
1394
|
+
pendingPlanChangeSchema: () => pendingPlanChangeSchema,
|
|
1395
|
+
pricingOptionSchema: () => pricingOptionSchema,
|
|
1396
|
+
subscriptionPlanOptionSchema: () => subscriptionPlanOptionSchema,
|
|
1397
|
+
subscriptionPlanOptionsSchema: () => subscriptionPlanOptionsSchema,
|
|
1388
1398
|
subscriptionSchema: () => subscriptionSchema
|
|
1389
1399
|
});
|
|
1390
1400
|
import { z as z14 } from "zod";
|
|
@@ -1594,6 +1604,33 @@ var milestoneProgressSchema = z14.object({
|
|
|
1594
1604
|
toNormalizedCycleNumber: z14.number(),
|
|
1595
1605
|
events: z14.record(z14.coerce.number(), milestoneProgressEventSchema.array())
|
|
1596
1606
|
});
|
|
1607
|
+
var pricingOptionSchema = z14.object({
|
|
1608
|
+
id: z14.string(),
|
|
1609
|
+
name: z14.string(),
|
|
1610
|
+
cycleLength: z14.nativeEnum(CycleLength)
|
|
1611
|
+
});
|
|
1612
|
+
var pendingPlanChangeSchema = z14.object({
|
|
1613
|
+
option: pricingOptionSchema,
|
|
1614
|
+
// The renewal that starts the new plan and charges `nextTotal`.
|
|
1615
|
+
takesEffectAt: z14.coerce.date(),
|
|
1616
|
+
nextTotal: orderTotalSchema,
|
|
1617
|
+
// Whether everything the subscription gets off now (discount, offer, coupons) still applies on the new plan.
|
|
1618
|
+
keepsDiscount: z14.boolean(),
|
|
1619
|
+
scheduledAt: z14.coerce.date()
|
|
1620
|
+
});
|
|
1621
|
+
var subscriptionPlanOptionSchema = z14.object({
|
|
1622
|
+
option: pricingOptionSchema,
|
|
1623
|
+
// What the next renewal charges on this plan. For the plan it is on, its normal renewal.
|
|
1624
|
+
nextTotal: orderTotalSchema,
|
|
1625
|
+
takesEffectAt: z14.coerce.date(),
|
|
1626
|
+
keepsDiscount: z14.boolean(),
|
|
1627
|
+
current: z14.boolean(),
|
|
1628
|
+
scheduled: z14.boolean()
|
|
1629
|
+
});
|
|
1630
|
+
var subscriptionPlanOptionsSchema = z14.object({
|
|
1631
|
+
unavailable: z14.string().nullish(),
|
|
1632
|
+
plans: subscriptionPlanOptionSchema.array()
|
|
1633
|
+
});
|
|
1597
1634
|
var subscriptionSchema = z14.object({
|
|
1598
1635
|
id: z14.string(),
|
|
1599
1636
|
status: z14.nativeEnum(SubscriptionStatus),
|
|
@@ -1608,6 +1645,10 @@ var subscriptionSchema = z14.object({
|
|
|
1608
1645
|
paymentMethod: z14.string().optional(),
|
|
1609
1646
|
milestoneProgress: milestoneProgressSchema.nullish(),
|
|
1610
1647
|
embeddedUpdatePaymentUrl: z14.string().optional(),
|
|
1648
|
+
// Older backends send neither, and one this version can't read is dropped rather than failing
|
|
1649
|
+
// the whole subscription.
|
|
1650
|
+
pricingOption: pricingOptionSchema.nullish().catch(void 0),
|
|
1651
|
+
pendingChange: pendingPlanChangeSchema.nullish().catch(void 0),
|
|
1611
1652
|
content: z14.discriminatedUnion("type", [
|
|
1612
1653
|
z14.object({
|
|
1613
1654
|
type: z14.literal("Product"),
|
|
@@ -1651,6 +1692,38 @@ var SubscriptionEndpoints = class {
|
|
|
1651
1692
|
});
|
|
1652
1693
|
return response.data;
|
|
1653
1694
|
}
|
|
1695
|
+
/**
|
|
1696
|
+
* The plans the subscription can switch to when its current period ends, each with what the
|
|
1697
|
+
* next renewal would charge on it. The plan it is on comes first. When it can't switch,
|
|
1698
|
+
* `unavailable` says why, ready to show to the customer.
|
|
1699
|
+
*/
|
|
1700
|
+
async getPlanOptions(subscriptionId) {
|
|
1701
|
+
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/plan-options`, subscriptionPlanOptionsSchema);
|
|
1702
|
+
return response.data;
|
|
1703
|
+
}
|
|
1704
|
+
/**
|
|
1705
|
+
* Switches the subscription to another plan when its current period ends. Nothing is charged
|
|
1706
|
+
* now: the next renewal charges the new plan and starts its cycle. Until then the customer can
|
|
1707
|
+
* switch again, and passing the plan it is on keeps that plan. Returns the updated subscription,
|
|
1708
|
+
* with the switch in `pendingChange`.
|
|
1709
|
+
*/
|
|
1710
|
+
async changePlan(subscriptionId, variationId) {
|
|
1711
|
+
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/plan-change`, subscriptionSchema, {
|
|
1712
|
+
method: "POST",
|
|
1713
|
+
body: { variationId }
|
|
1714
|
+
});
|
|
1715
|
+
return response.data;
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* Keeps the subscription on its current plan, dropping a switch scheduled with `changePlan`.
|
|
1719
|
+
* Returns the updated subscription.
|
|
1720
|
+
*/
|
|
1721
|
+
async cancelPlanChange(subscriptionId) {
|
|
1722
|
+
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/plan-change`, subscriptionSchema, {
|
|
1723
|
+
method: "DELETE"
|
|
1724
|
+
});
|
|
1725
|
+
return response.data;
|
|
1726
|
+
}
|
|
1654
1727
|
async renew(subscriptionId, returnUrl, embedded) {
|
|
1655
1728
|
const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/renew?redirect=false&return=${returnUrl}&embedded=${embedded ? "true" : "false"}`, z15.object({
|
|
1656
1729
|
location: z15.string()
|
|
@@ -2923,6 +2996,31 @@ var ImageUtils = class _ImageUtils {
|
|
|
2923
2996
|
};
|
|
2924
2997
|
|
|
2925
2998
|
// src/utils/utm.ts
|
|
2999
|
+
var clickIdPlatforms = [
|
|
3000
|
+
["gclid", "google"],
|
|
3001
|
+
["gbraid", "google"],
|
|
3002
|
+
["wbraid", "google"],
|
|
3003
|
+
["msclkid", "microsoft"],
|
|
3004
|
+
["fbclid", "meta"],
|
|
3005
|
+
["ttclid", "tiktok"]
|
|
3006
|
+
];
|
|
3007
|
+
var adPlatformOrder = ["google", "microsoft", "meta", "tiktok"];
|
|
3008
|
+
function adClicksOf(utm) {
|
|
3009
|
+
var _a;
|
|
3010
|
+
if (!utm)
|
|
3011
|
+
return void 0;
|
|
3012
|
+
const platforms = new Set((_a = utm.adClicks) != null ? _a : []);
|
|
3013
|
+
for (const [key, platform] of clickIdPlatforms) {
|
|
3014
|
+
if (utm[key])
|
|
3015
|
+
platforms.add(platform);
|
|
3016
|
+
}
|
|
3017
|
+
const ordered = adPlatformOrder.filter((platform) => platforms.has(platform));
|
|
3018
|
+
return ordered.length > 0 ? ordered : void 0;
|
|
3019
|
+
}
|
|
3020
|
+
function withoutClickIds(utm) {
|
|
3021
|
+
const { gclid: _gclid, gbraid: _gbraid, wbraid: _wbraid, msclkid: _msclkid, fbclid: _fbclid, ttclid: _ttclid, ...rest } = utm;
|
|
3022
|
+
return { ...rest, adClicks: adClicksOf(utm) };
|
|
3023
|
+
}
|
|
2926
3024
|
function parseOffSiteReferrer(rawReferrer, currentOrigin) {
|
|
2927
3025
|
if (!rawReferrer)
|
|
2928
3026
|
return void 0;
|
|
@@ -2937,7 +3035,7 @@ function parseOffSiteReferrer(rawReferrer, currentOrigin) {
|
|
|
2937
3035
|
}
|
|
2938
3036
|
function resolveUtm(cached, fresh) {
|
|
2939
3037
|
const freshHasUtm = !!(fresh.source || fresh.medium || fresh.campaign || fresh.term || fresh.content);
|
|
2940
|
-
const freshHasClickId = !!(fresh
|
|
3038
|
+
const freshHasClickId = !!adClicksOf(fresh);
|
|
2941
3039
|
const freshIsExternalArrival = freshHasUtm || freshHasClickId || !!fresh.referrer;
|
|
2942
3040
|
if (freshIsExternalArrival)
|
|
2943
3041
|
return fresh;
|
|
@@ -2999,6 +3097,7 @@ export {
|
|
|
2999
3097
|
SubscriptionStatus,
|
|
3000
3098
|
TokenStore,
|
|
3001
3099
|
accessTokenLifetime,
|
|
3100
|
+
adClicksOf,
|
|
3002
3101
|
imageWidths,
|
|
3003
3102
|
isLocalStorageAvailable,
|
|
3004
3103
|
isPromotionDisplay,
|
|
@@ -3011,5 +3110,6 @@ export {
|
|
|
3011
3110
|
promotionDisplays,
|
|
3012
3111
|
resolveUtm,
|
|
3013
3112
|
schemas_exports12 as schemas,
|
|
3014
|
-
utmToObject
|
|
3113
|
+
utmToObject,
|
|
3114
|
+
withoutClickIds
|
|
3015
3115
|
};
|
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.12.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",
|