@moonbase.sh/storefront-api 3.11.0 → 3.13.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.js CHANGED
@@ -7,34 +7,6 @@ var __export = (target, all) => {
7
7
  // src/activationRequests/endpoints.ts
8
8
  import { z as z5 } from "zod";
9
9
 
10
- // src/activationRequests/schemas.ts
11
- var schemas_exports3 = {};
12
- __export(schemas_exports3, {
13
- activationRequestSchema: () => activationRequestSchema
14
- });
15
- import { z as z4 } from "zod";
16
-
17
- // src/storefront/schemas.ts
18
- var schemas_exports2 = {};
19
- __export(schemas_exports2, {
20
- offerConditionSchema: () => offerConditionSchema,
21
- offerScopeSchema: () => offerScopeSchema,
22
- storefrontBundleSchema: () => storefrontBundleSchema,
23
- storefrontLicenseUpgradeSchema: () => storefrontLicenseUpgradeSchema,
24
- storefrontOfferSchema: () => storefrontOfferSchema,
25
- storefrontOfferTargetSchema: () => storefrontOfferTargetSchema,
26
- storefrontProductSchema: () => storefrontProductSchema,
27
- storefrontPromotionCtaSchema: () => storefrontPromotionCtaSchema,
28
- storefrontPromotionSchema: () => storefrontPromotionSchema,
29
- storefrontPromotionTargetSchema: () => storefrontPromotionTargetSchema,
30
- storefrontSchema: () => storefrontSchema,
31
- taxEstimateSchema: () => taxEstimateSchema
32
- });
33
- import { z as z3 } from "zod";
34
-
35
- // src/globalSchemas.ts
36
- import { z } from "zod";
37
-
38
10
  // src/globalModels.ts
39
11
  var CycleLength = /* @__PURE__ */ ((CycleLength2) => {
40
12
  CycleLength2["Daily"] = "Daily";
@@ -51,6 +23,7 @@ var MarketingConsentType = /* @__PURE__ */ ((MarketingConsentType2) => {
51
23
  return MarketingConsentType2;
52
24
  })(MarketingConsentType || {});
53
25
  function utmToObject(utm) {
26
+ var _a;
54
27
  return Object.entries({
55
28
  utm_source: utm == null ? void 0 : utm.source,
56
29
  utm_medium: utm == null ? void 0 : utm.medium,
@@ -63,14 +36,41 @@ function utmToObject(utm) {
63
36
  wbraid: utm == null ? void 0 : utm.wbraid,
64
37
  fbclid: utm == null ? void 0 : utm.fbclid,
65
38
  msclkid: utm == null ? void 0 : utm.msclkid,
66
- ttclid: utm == null ? void 0 : utm.ttclid
39
+ ttclid: utm == null ? void 0 : utm.ttclid,
40
+ utm_ad_click: ((_a = utm == null ? void 0 : utm.adClicks) == null ? void 0 : _a.length) ? utm.adClicks.join(",") : void 0
67
41
  }).filter(([_, value]) => value !== void 0).reduce((obj, [key, value]) => ({
68
42
  ...obj,
69
43
  [key]: value
70
44
  }), {});
71
45
  }
72
46
 
47
+ // src/activationRequests/schemas.ts
48
+ var schemas_exports3 = {};
49
+ __export(schemas_exports3, {
50
+ activationRequestSchema: () => activationRequestSchema
51
+ });
52
+ import { z as z4 } from "zod";
53
+
54
+ // src/storefront/schemas.ts
55
+ var schemas_exports2 = {};
56
+ __export(schemas_exports2, {
57
+ offerConditionSchema: () => offerConditionSchema,
58
+ offerScopeSchema: () => offerScopeSchema,
59
+ storefrontBundleSchema: () => storefrontBundleSchema,
60
+ storefrontLicenseUpgradeSchema: () => storefrontLicenseUpgradeSchema,
61
+ storefrontOfferSchema: () => storefrontOfferSchema,
62
+ storefrontOfferTargetSchema: () => storefrontOfferTargetSchema,
63
+ storefrontProductSchema: () => storefrontProductSchema,
64
+ storefrontPromotionCtaSchema: () => storefrontPromotionCtaSchema,
65
+ storefrontPromotionSchema: () => storefrontPromotionSchema,
66
+ storefrontPromotionTargetSchema: () => storefrontPromotionTargetSchema,
67
+ storefrontSchema: () => storefrontSchema,
68
+ taxEstimateSchema: () => taxEstimateSchema
69
+ });
70
+ import { z as z3 } from "zod";
71
+
73
72
  // src/globalSchemas.ts
73
+ import { z } from "zod";
74
74
  var priceCollectionSchema = z.record(z.number());
75
75
  var discountPromotionFields = {
76
76
  promotionId: z.string().optional(),
@@ -434,7 +434,11 @@ var storefrontSchema = z3.object({
434
434
  // Promotions need to be optional since we may still have old, cached representations in browsers
435
435
  promotions: storefrontPromotionsSchema.optional(),
436
436
  // Depending on circumstances, we may have a tax estimate available
437
- estimatedTax: taxEstimateSchema.optional()
437
+ estimatedTax: taxEstimateSchema.optional(),
438
+ // Whether the storefront has to wait for this visitor's cookie consent before it keeps ad click
439
+ // IDs or remembers their visit: the store's setting, for the country the visit comes from.
440
+ // Optional for older backends and cached catalogs, which count as asking.
441
+ cookieConsentRequired: z3.boolean().optional()
438
442
  });
439
443
 
440
444
  // src/activationRequests/models.ts
@@ -500,8 +504,14 @@ var ActivationRequestEndpoints = class {
500
504
  const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, activationRequestSchema, { method: "POST" });
501
505
  return response.data;
502
506
  }
503
- async fulfillTrial(requestId) {
504
- const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, activationRequestSchema, { method: "POST" });
507
+ /**
508
+ * Starts the trial the request's app asked for. `utm` is the tracking the visitor arrived with, which the
509
+ * trial is put down to, as a sign-up or an order is, so trials can be told apart by the marketing that
510
+ * brought them.
511
+ */
512
+ async fulfillTrial(requestId, utm) {
513
+ const query = new URLSearchParams(utmToObject(utm)).toString();
514
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial${query ? `?${query}` : ""}`, activationRequestSchema, { method: "POST" });
505
515
  return response.data;
506
516
  }
507
517
  async cancel(requestId) {
@@ -984,6 +994,20 @@ var IdentityEndpoints = class {
984
994
  user: response.data
985
995
  };
986
996
  }
997
+ /**
998
+ * Saves the signed-in customer's address, which their next checkout starts from. A checkout
999
+ * they have already entered billing details in keeps those. Rejects with a `MoonbaseError` for
1000
+ * an address the store can't use: it needs a known country, a street address, a city or a
1001
+ * region, and in the US a postal code.
1002
+ */
1003
+ async updateAddress(address) {
1004
+ const response = await this.api.authenticatedFetch("/api/customer/identity", userSchema, {
1005
+ method: "PATCH",
1006
+ body: { address }
1007
+ });
1008
+ this.tokenStore.setUser(response.data);
1009
+ return response.data;
1010
+ }
987
1011
  async setPassword(currentPassword, newPassword) {
988
1012
  await this.api.authenticatedFetch(`/api/customer/identity/set-password`, null, {
989
1013
  method: "POST",
@@ -1229,7 +1253,7 @@ var ProductEndpoints = class {
1229
1253
  import { z as z15 } from "zod";
1230
1254
 
1231
1255
  // package.json
1232
- var version = "3.11.0";
1256
+ var version = "3.13.0";
1233
1257
 
1234
1258
  // src/utils/client.ts
1235
1259
  function buildClientHeader(sdk) {
@@ -2990,6 +3014,31 @@ var ImageUtils = class _ImageUtils {
2990
3014
  };
2991
3015
 
2992
3016
  // src/utils/utm.ts
3017
+ var clickIdPlatforms = [
3018
+ ["gclid", "google"],
3019
+ ["gbraid", "google"],
3020
+ ["wbraid", "google"],
3021
+ ["msclkid", "microsoft"],
3022
+ ["fbclid", "meta"],
3023
+ ["ttclid", "tiktok"]
3024
+ ];
3025
+ var adPlatformOrder = ["google", "microsoft", "meta", "tiktok"];
3026
+ function adClicksOf(utm) {
3027
+ var _a;
3028
+ if (!utm)
3029
+ return void 0;
3030
+ const platforms = new Set((_a = utm.adClicks) != null ? _a : []);
3031
+ for (const [key, platform] of clickIdPlatforms) {
3032
+ if (utm[key])
3033
+ platforms.add(platform);
3034
+ }
3035
+ const ordered = adPlatformOrder.filter((platform) => platforms.has(platform));
3036
+ return ordered.length > 0 ? ordered : void 0;
3037
+ }
3038
+ function withoutClickIds(utm) {
3039
+ const { gclid: _gclid, gbraid: _gbraid, wbraid: _wbraid, msclkid: _msclkid, fbclid: _fbclid, ttclid: _ttclid, ...rest } = utm;
3040
+ return { ...rest, adClicks: adClicksOf(utm) };
3041
+ }
2993
3042
  function parseOffSiteReferrer(rawReferrer, currentOrigin) {
2994
3043
  if (!rawReferrer)
2995
3044
  return void 0;
@@ -3004,7 +3053,7 @@ function parseOffSiteReferrer(rawReferrer, currentOrigin) {
3004
3053
  }
3005
3054
  function resolveUtm(cached, fresh) {
3006
3055
  const freshHasUtm = !!(fresh.source || fresh.medium || fresh.campaign || fresh.term || fresh.content);
3007
- const freshHasClickId = !!(fresh.gclid || fresh.gbraid || fresh.wbraid || fresh.fbclid || fresh.msclkid || fresh.ttclid);
3056
+ const freshHasClickId = !!adClicksOf(fresh);
3008
3057
  const freshIsExternalArrival = freshHasUtm || freshHasClickId || !!fresh.referrer;
3009
3058
  if (freshIsExternalArrival)
3010
3059
  return fresh;
@@ -3066,6 +3115,7 @@ export {
3066
3115
  SubscriptionStatus,
3067
3116
  TokenStore,
3068
3117
  accessTokenLifetime,
3118
+ adClicksOf,
3069
3119
  imageWidths,
3070
3120
  isLocalStorageAvailable,
3071
3121
  isPromotionDisplay,
@@ -3078,5 +3128,6 @@ export {
3078
3128
  promotionDisplays,
3079
3129
  resolveUtm,
3080
3130
  schemas_exports12 as schemas,
3081
- utmToObject
3131
+ utmToObject,
3132
+ withoutClickIds
3082
3133
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "3.11.0",
4
+ "version": "3.13.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",