@moonbase.sh/storefront-api 3.8.0 → 3.10.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 CHANGED
@@ -46,7 +46,9 @@ __export(index_exports, {
46
46
  NotFoundError: () => NotFoundError,
47
47
  OfferUtils: () => OfferUtils,
48
48
  OrderStatus: () => OrderStatus,
49
+ PasswordSetupRequiredError: () => PasswordSetupRequiredError,
49
50
  Platform: () => Platform,
51
+ ReleaseNotCoveredError: () => ReleaseNotCoveredError,
50
52
  StoreClosedError: () => StoreClosedError,
51
53
  SubscriptionCancellationReason: () => SubscriptionCancellationReason,
52
54
  SubscriptionStatus: () => SubscriptionStatus,
@@ -84,6 +86,7 @@ __export(schemas_exports2, {
84
86
  offerConditionSchema: () => offerConditionSchema,
85
87
  offerScopeSchema: () => offerScopeSchema,
86
88
  storefrontBundleSchema: () => storefrontBundleSchema,
89
+ storefrontLicenseUpgradeSchema: () => storefrontLicenseUpgradeSchema,
87
90
  storefrontOfferSchema: () => storefrontOfferSchema,
88
91
  storefrontOfferTargetSchema: () => storefrontOfferTargetSchema,
89
92
  storefrontProductSchema: () => storefrontProductSchema,
@@ -218,6 +221,7 @@ var schemas_exports = {};
218
221
  __export(schemas_exports, {
219
222
  downloadSchema: () => downloadSchema,
220
223
  manifestSchema: () => manifestSchema,
224
+ productReleaseAccessSchema: () => productReleaseAccessSchema,
221
225
  productReleaseSchema: () => productReleaseSchema,
222
226
  productSummarySchema: () => productSummarySchema
223
227
  });
@@ -260,6 +264,21 @@ var downloadSchema = import_zod2.z.object({
260
264
  path: import_zod2.z.string().nullable(),
261
265
  manifest: manifestSchema.optional()
262
266
  });
267
+ var productReleaseAccessSchema = import_zod2.z.object({
268
+ // Releases published until then are covered, and every version while it has not passed.
269
+ updatesUntil: import_zod2.z.coerce.date().nullish().catch(void 0),
270
+ // Every version whose major is at most this is covered.
271
+ upToMajor: import_zod2.z.number().nullish().catch(void 0),
272
+ // Once updates have ended, the last version published before they did.
273
+ upToVersion: import_zod2.z.string().nullish().catch(void 0),
274
+ // Whether the release this was resolved for (the one shown) is covered. Read as covered when
275
+ // unreadable, so a garbled answer never locks a download the API would hand out.
276
+ coversRelease: import_zod2.z.boolean().catch(true),
277
+ // The newest published version the customer may download, when the shown one is not covered.
278
+ latestCoveredVersion: import_zod2.z.string().nullish().catch(void 0),
279
+ // Where to buy the upgrade or renewal, while the product sells one.
280
+ upgradeUrl: import_zod2.z.string().nullish().catch(void 0)
281
+ });
263
282
  var productSummarySchema = import_zod2.z.object({
264
283
  id: import_zod2.z.string(),
265
284
  name: import_zod2.z.string(),
@@ -283,7 +302,10 @@ var productSummarySchema = import_zod2.z.object({
283
302
  // Whether this caller clears every requirement above, including the group membership the client
284
303
  // can't see for itself. False with none of them set means the merchant closed the release to everyone.
285
304
  downloadsAllowed: import_zod2.z.boolean(),
286
- downloads: import_zod2.z.array(downloadSchema).optional()
305
+ downloads: import_zod2.z.array(downloadSchema).optional(),
306
+ // Set only when the customer's licenses do not cover every release. `downloadsAllowed` already
307
+ // accounts for it; this says why a download is locked and where to upgrade.
308
+ releaseAccess: productReleaseAccessSchema.nullish().catch(void 0)
287
309
  });
288
310
  var productReleaseSchema = import_zod2.z.object({
289
311
  version: import_zod2.z.string(),
@@ -293,10 +315,33 @@ var productReleaseSchema = import_zod2.z.object({
293
315
  // merchant can keep past releases to owners while the current one is open to anyone.
294
316
  downloadsAllowed: import_zod2.z.boolean(),
295
317
  downloads: import_zod2.z.array(downloadSchema),
296
- properties: import_zod2.z.record(rawPropertyValueSchema).nullish()
318
+ properties: import_zod2.z.record(rawPropertyValueSchema).nullish(),
319
+ // True when the caller owns the product but none of their licenses covers this release, so it
320
+ // takes an upgrade rather than a sign-in to unlock. Absent otherwise.
321
+ releaseNotCovered: import_zod2.z.boolean().nullish().catch(void 0)
297
322
  });
298
323
 
299
324
  // src/storefront/schemas.ts
325
+ var storefrontLicenseUpgradeSchema = import_zod3.z.object({
326
+ // The customer's licenses this entry prices. An entry without them is no use and is left out.
327
+ licenseIds: import_zod3.z.string().array(),
328
+ // What those licenses cover now, which is how a cart tells the customer which of their licenses an
329
+ // upgrade is for. Read leniently, field by field: a backend that predates it leaves it out, and one
330
+ // this version cannot read reads as absent rather than costing the entry.
331
+ releaseAccess: import_zod3.z.object({
332
+ // Releases published until then are covered, and every version while it has not passed.
333
+ updatesUntil: import_zod3.z.coerce.date().nullish().catch(void 0),
334
+ // Every version whose major is at most this is covered.
335
+ upToMajor: import_zod3.z.number().nullish().catch(void 0),
336
+ // Once updates have ended, the last version published before they did.
337
+ upToVersion: import_zod3.z.string().nullish().catch(void 0)
338
+ }).nullish().catch(void 0),
339
+ variations: pricingVariationSchema.array()
340
+ });
341
+ var storefrontLicenseUpgradesSchema = import_zod3.z.array(import_zod3.z.unknown()).transform((upgrades) => upgrades.flatMap((upgrade) => {
342
+ const parsed = storefrontLicenseUpgradeSchema.safeParse(upgrade);
343
+ return parsed.success ? [parsed.data] : [];
344
+ }));
300
345
  var storefrontProductSchema = import_zod3.z.object({
301
346
  id: import_zod3.z.string(),
302
347
  name: import_zod3.z.string(),
@@ -310,7 +355,13 @@ var storefrontProductSchema = import_zod3.z.object({
310
355
  defaultVariation: pricingVariationSchema.optional(),
311
356
  variations: pricingVariationSchema.array().optional(),
312
357
  properties: import_zod3.z.record(rawPropertyValueSchema).nullish(),
313
- type: import_zod3.z.string().optional().default("Product").pipe(import_zod3.z.literal("Product"))
358
+ type: import_zod3.z.string().optional().default("Product").pipe(import_zod3.z.literal("Product")),
359
+ // What upgrading or renewing the signed-in customer's licenses of the product that cover only
360
+ // some releases costs, one entry per group of licenses that cover the same, furthest behind first.
361
+ // Capped, so a customer with a great many licenses may find one in none of them. Absent for anyone
362
+ // else, and from a backend that predates per-license prices. A cart line naming one of these
363
+ // licenses (`targetLicenseId`) is priced from here: see `CartUtils.licenseUpgrade`.
364
+ licenseUpgrades: storefrontLicenseUpgradesSchema.nullish().catch(void 0)
314
365
  });
315
366
  var storefrontBundleSchema = import_zod3.z.object({
316
367
  id: import_zod3.z.string(),
@@ -484,7 +535,17 @@ var activationRequestSchema = import_zod4.z.object({
484
535
  endless: import_zod4.z.boolean().default(false)
485
536
  }).optional(),
486
537
  licenseEligibility: import_zod4.z.object({
487
- eligible: import_zod4.z.boolean()
538
+ eligible: import_zod4.z.boolean(),
539
+ // Set when the customer's licenses would take the device but none of them covers the version
540
+ // the app runs (`eligible` is then false), so the app's version needs an upgrade. Absent from
541
+ // a backend that predates release access, and read leniently so it can never fail the request.
542
+ releaseNotCovered: import_zod4.z.object({
543
+ appVersion: import_zod4.z.string().nullish().catch(void 0),
544
+ updatesUntil: import_zod4.z.coerce.date().nullish().catch(void 0),
545
+ upToMajor: import_zod4.z.number().nullish().catch(void 0),
546
+ upToVersion: import_zod4.z.string().nullish().catch(void 0),
547
+ upgradeUrl: import_zod4.z.string().nullish().catch(void 0)
548
+ }).nullish().catch(void 0)
488
549
  }).optional()
489
550
  });
490
551
 
@@ -563,7 +624,8 @@ var CommunicationsEndpoints = class {
563
624
  newsletter: (_b = input.newsletter) != null ? _b : true,
564
625
  productUpdates: (_c = input.productUpdates) != null ? _c : true,
565
626
  groupIds: normalizeGroupIds(input.groupIds)
566
- }
627
+ },
628
+ headers: input.captchaToken ? { "X-MB-CAPTCHA": input.captchaToken } : void 0
567
629
  });
568
630
  return response.data;
569
631
  }
@@ -643,6 +705,15 @@ var NotAuthorizedError = class extends Error {
643
705
  this.message = "Not allowed";
644
706
  }
645
707
  };
708
+ var ReleaseNotCoveredError = class extends NotAuthorizedError {
709
+ constructor(releaseAccess, upgradeUrl, detail) {
710
+ super();
711
+ this.releaseAccess = releaseAccess;
712
+ this.upgradeUrl = upgradeUrl;
713
+ this.name = "ReleaseNotCoveredError";
714
+ this.message = detail != null ? detail : "Your license doesn't cover this version";
715
+ }
716
+ };
646
717
  var NotAuthenticatedError = class extends Error {
647
718
  constructor() {
648
719
  super();
@@ -685,6 +756,15 @@ var CaptchaRequiredError = class extends MoonbaseError {
685
756
  this.name = "CaptchaRequiredError";
686
757
  }
687
758
  };
759
+ var PasswordSetupRequiredError = class extends MoonbaseError {
760
+ constructor(detail, title, status) {
761
+ super(title != null ? title : "Password setup required", detail, status);
762
+ this.name = "PasswordSetupRequiredError";
763
+ }
764
+ };
765
+
766
+ // src/utils/problemHandler.ts
767
+ var import_zod8 = require("zod");
688
768
 
689
769
  // src/utils/problemDetails.ts
690
770
  var import_zod7 = require("zod");
@@ -699,6 +779,28 @@ var problemDetailsSchema = import_zod7.z.object({
699
779
  });
700
780
 
701
781
  // src/utils/problemHandler.ts
782
+ var releaseNotCoveredProblemSchema = import_zod8.z.object({
783
+ errorType: import_zod8.z.literal("ReleaseNotCovered"),
784
+ detail: import_zod8.z.string().nullish().catch(void 0),
785
+ releaseAccess: productReleaseAccessSchema.nullish().catch(void 0),
786
+ upgradeUrl: import_zod8.z.string().nullish().catch(void 0)
787
+ });
788
+ async function forbiddenError(response) {
789
+ var _a;
790
+ try {
791
+ const problem = releaseNotCoveredProblemSchema.safeParse(JSON.parse(await response.text()));
792
+ if (problem.success) {
793
+ const { releaseAccess, upgradeUrl, detail } = problem.data;
794
+ return new ReleaseNotCoveredError(
795
+ releaseAccess != null ? releaseAccess : void 0,
796
+ (_a = upgradeUrl != null ? upgradeUrl : releaseAccess == null ? void 0 : releaseAccess.upgradeUrl) != null ? _a : void 0,
797
+ detail != null ? detail : void 0
798
+ );
799
+ }
800
+ } catch (e) {
801
+ }
802
+ return new NotAuthorizedError();
803
+ }
702
804
  function camelCase(str) {
703
805
  return str.split(".").map((word, index) => {
704
806
  let [firstLetter, ...restOfLetters] = word;
@@ -708,13 +810,14 @@ function camelCase(str) {
708
810
  }).join("");
709
811
  }
710
812
  async function handleResponseProblem(response, logger) {
813
+ var _a;
711
814
  if (response.status === 404)
712
815
  throw new NotFoundError();
713
816
  if (response.status === 401) {
714
817
  throw new NotAuthenticatedError();
715
818
  }
716
819
  if (response.status === 403) {
717
- throw new NotAuthorizedError();
820
+ throw await forbiddenError(response);
718
821
  }
719
822
  let problemDetails;
720
823
  const body = await response.text();
@@ -729,6 +832,8 @@ async function handleResponseProblem(response, logger) {
729
832
  throw new StoreClosedError(problemDetails.detail);
730
833
  if (problemDetails.errorType === "CaptchaRequired")
731
834
  throw new CaptchaRequiredError(problemDetails.detail, problemDetails.title);
835
+ if (problemDetails.errorType === "PasswordSetupRequired")
836
+ throw new PasswordSetupRequiredError(problemDetails.detail, problemDetails.title, (_a = problemDetails.status) != null ? _a : response.status);
732
837
  throw new MoonbaseError(
733
838
  problemDetails.title,
734
839
  problemDetails.detail,
@@ -747,11 +852,12 @@ __export(schemas_exports5, {
747
852
  identitySchema: () => identitySchema,
748
853
  ilokConnectedAccountSchema: () => ilokConnectedAccountSchema,
749
854
  pendingActivationSchema: () => pendingActivationSchema,
855
+ pendingPasswordProblemSchema: () => pendingPasswordProblemSchema,
750
856
  userAccountConfirmedSchema: () => userAccountConfirmedSchema,
751
857
  userAccountConfirmedStatusSchema: () => userAccountConfirmedStatusSchema,
752
858
  userSchema: () => userSchema
753
859
  });
754
- var import_zod8 = require("zod");
860
+ var import_zod9 = require("zod");
755
861
 
756
862
  // src/identity/models.ts
757
863
  var ConnectableAccountProvider = /* @__PURE__ */ ((ConnectableAccountProvider2) => {
@@ -760,73 +866,78 @@ var ConnectableAccountProvider = /* @__PURE__ */ ((ConnectableAccountProvider2)
760
866
  })(ConnectableAccountProvider || {});
761
867
 
762
868
  // src/identity/schemas.ts
763
- var addressSchema = import_zod8.z.object({
764
- countryCode: import_zod8.z.string(),
765
- streetAddress1: import_zod8.z.string(),
766
- streetAddress2: import_zod8.z.string().nullable(),
767
- locality: import_zod8.z.string().nullable(),
768
- region: import_zod8.z.string().nullable(),
769
- postCode: import_zod8.z.string().nullable()
770
- });
771
- var communicationPreferencesSchema = import_zod8.z.object({
772
- newsletterOptIn: import_zod8.z.boolean(),
869
+ var addressSchema = import_zod9.z.object({
870
+ countryCode: import_zod9.z.string(),
871
+ streetAddress1: import_zod9.z.string(),
872
+ streetAddress2: import_zod9.z.string().nullable(),
873
+ locality: import_zod9.z.string().nullable(),
874
+ region: import_zod9.z.string().nullable(),
875
+ postCode: import_zod9.z.string().nullable()
876
+ });
877
+ var communicationPreferencesSchema = import_zod9.z.object({
878
+ newsletterOptIn: import_zod9.z.boolean(),
773
879
  // Default keeps older persisted identities (pre productUpdatesOptIn) parseable
774
880
  // during boot. The server-side value is hydrated by updateUser() right after.
775
- productUpdatesOptIn: import_zod8.z.boolean().default(false)
881
+ productUpdatesOptIn: import_zod9.z.boolean().default(false)
776
882
  });
777
- var ilokConnectedAccountSchema = import_zod8.z.object({
778
- provider: import_zod8.z.literal("iLok" /* iLok */),
779
- isConnected: import_zod8.z.boolean(),
780
- pendingLicenseFulfillments: import_zod8.z.boolean(),
781
- accountId: import_zod8.z.string().nullish()
883
+ var ilokConnectedAccountSchema = import_zod9.z.object({
884
+ provider: import_zod9.z.literal("iLok" /* iLok */),
885
+ isConnected: import_zod9.z.boolean(),
886
+ pendingLicenseFulfillments: import_zod9.z.boolean(),
887
+ accountId: import_zod9.z.string().nullish()
782
888
  });
783
- var connectedAccountSchema = import_zod8.z.discriminatedUnion("provider", [
889
+ var connectedAccountSchema = import_zod9.z.discriminatedUnion("provider", [
784
890
  ilokConnectedAccountSchema
785
891
  ]);
786
- var connectionUrlSchema = import_zod8.z.object({
787
- url: import_zod8.z.string()
892
+ var connectionUrlSchema = import_zod9.z.object({
893
+ url: import_zod9.z.string()
788
894
  });
789
- var userSchema = import_zod8.z.object({
790
- id: import_zod8.z.string(),
791
- email: import_zod8.z.string(),
895
+ var userSchema = import_zod9.z.object({
896
+ id: import_zod9.z.string(),
897
+ email: import_zod9.z.string(),
792
898
  // Nullable: customers created via import may have no name.
793
- name: import_zod8.z.string().nullable(),
794
- tenantId: import_zod8.z.string(),
899
+ name: import_zod9.z.string().nullable(),
900
+ tenantId: import_zod9.z.string(),
795
901
  address: addressSchema.optional(),
796
- phone: import_zod8.z.string().optional(),
902
+ phone: import_zod9.z.string().optional(),
797
903
  communicationPreferences: communicationPreferencesSchema,
798
- ownedProducts: import_zod8.z.string().array().optional(),
799
- subscribedProducts: import_zod8.z.string().array().optional(),
800
- confirmedAccount: import_zod8.z.boolean().optional(),
801
- hasProducts: import_zod8.z.boolean().nullish(),
802
- hasSubscriptions: import_zod8.z.boolean().nullish(),
803
- connectedAccounts: import_zod8.z.array(connectedAccountSchema).default([])
804
- });
805
- var identitySchema = userSchema.and(import_zod8.z.object({
806
- accessToken: import_zod8.z.string(),
807
- refreshToken: import_zod8.z.string()
904
+ ownedProducts: import_zod9.z.string().array().optional(),
905
+ subscribedProducts: import_zod9.z.string().array().optional(),
906
+ confirmedAccount: import_zod9.z.boolean().optional(),
907
+ hasProducts: import_zod9.z.boolean().nullish(),
908
+ hasSubscriptions: import_zod9.z.boolean().nullish(),
909
+ connectedAccounts: import_zod9.z.array(connectedAccountSchema).default([])
910
+ });
911
+ var identitySchema = userSchema.and(import_zod9.z.object({
912
+ accessToken: import_zod9.z.string(),
913
+ refreshToken: import_zod9.z.string()
808
914
  }));
809
- var userAccountConfirmedStatusSchema = import_zod8.z.enum([
915
+ var userAccountConfirmedStatusSchema = import_zod9.z.enum([
810
916
  "PasswordSetupRequired",
811
917
  "SignedIn"
812
918
  ]);
813
- var userAccountConfirmedSchema = userSchema.and(import_zod8.z.object({
919
+ var userAccountConfirmedSchema = userSchema.and(import_zod9.z.object({
814
920
  status: userAccountConfirmedStatusSchema,
815
- resetPasswordToken: import_zod8.z.string().nullish(),
816
- accessToken: import_zod8.z.string().nullish(),
817
- refreshToken: import_zod8.z.string().nullish()
921
+ resetPasswordToken: import_zod9.z.string().nullish(),
922
+ accessToken: import_zod9.z.string().nullish(),
923
+ refreshToken: import_zod9.z.string().nullish()
818
924
  }));
819
- var pendingActivationSchema = import_zod8.z.object({
820
- status: import_zod8.z.literal("activation_pending"),
821
- email: import_zod8.z.string()
925
+ var pendingActivationSchema = import_zod9.z.object({
926
+ status: import_zod9.z.literal("activation_pending"),
927
+ email: import_zod9.z.string()
928
+ });
929
+ var pendingPasswordProblemSchema = import_zod9.z.object({
930
+ errorType: import_zod9.z.literal("PasswordSetupRequired"),
931
+ pendingPasswordToken: import_zod9.z.string()
822
932
  });
823
933
 
824
934
  // src/identity/endpoints.ts
825
935
  var IdentityEndpoints = class {
826
- constructor(api, tokenStore, logger) {
936
+ constructor(api, tokenStore, logger, pendingPasswords) {
827
937
  this.api = api;
828
938
  this.tokenStore = tokenStore;
829
939
  this.logger = logger;
940
+ this.pendingPasswords = pendingPasswords;
830
941
  }
831
942
  async get() {
832
943
  const response = await this.api.authenticatedFetch("/api/customer/meta/user", userSchema);
@@ -882,8 +993,11 @@ var IdentityEndpoints = class {
882
993
  groupIds: normalizeGroupIds(options == null ? void 0 : options.groupIds)
883
994
  })
884
995
  });
885
- if (response.status >= 400)
996
+ if (response.status >= 400) {
997
+ if (response.status === 409)
998
+ await this.keepPendingPassword(email, response.clone());
886
999
  await handleResponseProblem(response, this.logger);
1000
+ }
887
1001
  const data = await response.json();
888
1002
  if (response.status === 202) {
889
1003
  const parsed = pendingActivationSchema.parse(data);
@@ -899,6 +1013,19 @@ var IdentityEndpoints = class {
899
1013
  this.tokenStore.setUser(identity);
900
1014
  return { status: "signed-in", user: userSchema.parse(identity) };
901
1015
  }
1016
+ /**
1017
+ * The address already has an account with no password, so the server emailed it a link and
1018
+ * handed back the password just typed, sealed, for that link to set once it is opened here.
1019
+ * Never thrown: the caller still gets the `PasswordSetupRequiredError` from the response.
1020
+ */
1021
+ async keepPendingPassword(email, response) {
1022
+ try {
1023
+ const problem = pendingPasswordProblemSchema.safeParse(await response.json());
1024
+ if (problem.success)
1025
+ this.pendingPasswords.set(email, problem.data.pendingPasswordToken);
1026
+ } catch (e) {
1027
+ }
1028
+ }
902
1029
  /**
903
1030
  * Signs the buyer out here at once, and ends the session on the server so its refresh
904
1031
  * token stops working too. Resolves once the server has answered, and never rejects:
@@ -950,7 +1077,13 @@ var IdentityEndpoints = class {
950
1077
  await handleResponseProblem(response, this.logger);
951
1078
  }
952
1079
  async confirmAccount(email, code) {
953
- const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}&scheme=JWT`, userAccountConfirmedSchema, { method: "POST" });
1080
+ const pendingPasswordToken = this.pendingPasswords.get(email);
1081
+ const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}&scheme=JWT`, userAccountConfirmedSchema, {
1082
+ method: "POST",
1083
+ body: pendingPasswordToken ? { pendingPasswordToken } : void 0
1084
+ });
1085
+ if (pendingPasswordToken)
1086
+ this.pendingPasswords.remove(email);
954
1087
  const result = response.data;
955
1088
  if (result.status === "SignedIn") {
956
1089
  if (!result.accessToken || !result.refreshToken) {
@@ -991,16 +1124,17 @@ var IdentityEndpoints = class {
991
1124
  };
992
1125
 
993
1126
  // src/inventory/activation/endpoints.ts
994
- var import_zod10 = require("zod");
1127
+ var import_zod11 = require("zod");
995
1128
 
996
1129
  // src/inventory/licenses/schemas.ts
997
1130
  var schemas_exports6 = {};
998
1131
  __export(schemas_exports6, {
999
1132
  activationSchema: () => activationSchema,
1000
1133
  externalLicenseContent: () => externalLicenseContent,
1134
+ licenseReleaseAccessSchema: () => licenseReleaseAccessSchema,
1001
1135
  licenseSchema: () => licenseSchema
1002
1136
  });
1003
- var import_zod9 = require("zod");
1137
+ var import_zod10 = require("zod");
1004
1138
 
1005
1139
  // src/inventory/licenses/models.ts
1006
1140
  var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
@@ -1021,43 +1155,57 @@ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
1021
1155
  })(ActivationMethod || {});
1022
1156
 
1023
1157
  // src/inventory/licenses/schemas.ts
1024
- var externalLicenseFileContent = import_zod9.z.object({
1025
- type: import_zod9.z.literal("file"),
1026
- fileName: import_zod9.z.string(),
1027
- contentType: import_zod9.z.string(),
1028
- data: import_zod9.z.string()
1029
- });
1030
- var externalLicenseILokContent = import_zod9.z.object({
1031
- type: import_zod9.z.literal("iLok")
1032
- });
1033
- var externalLicenseContent = import_zod9.z.union([
1034
- import_zod9.z.string(),
1035
- import_zod9.z.discriminatedUnion("type", [
1158
+ var externalLicenseFileContent = import_zod10.z.object({
1159
+ type: import_zod10.z.literal("file"),
1160
+ fileName: import_zod10.z.string(),
1161
+ contentType: import_zod10.z.string(),
1162
+ data: import_zod10.z.string()
1163
+ });
1164
+ var externalLicenseILokContent = import_zod10.z.object({
1165
+ type: import_zod10.z.literal("iLok")
1166
+ });
1167
+ var externalLicenseContent = import_zod10.z.union([
1168
+ import_zod10.z.string(),
1169
+ import_zod10.z.discriminatedUnion("type", [
1036
1170
  externalLicenseFileContent,
1037
1171
  externalLicenseILokContent
1038
1172
  ])
1039
1173
  ]);
1040
- var licenseSchema = import_zod9.z.object({
1041
- id: import_zod9.z.string(),
1042
- status: import_zod9.z.nativeEnum(LicenseStatus),
1174
+ var licenseReleaseAccessSchema = import_zod10.z.object({
1175
+ // Releases published until then are covered, and every version while it has not passed.
1176
+ updatesUntil: import_zod10.z.coerce.date().nullish().catch(void 0),
1177
+ // Every version whose major is at most this is covered.
1178
+ upToMajor: import_zod10.z.number().nullish().catch(void 0),
1179
+ // Once updates have ended, the last version published before they did.
1180
+ upToVersion: import_zod10.z.string().nullish().catch(void 0),
1181
+ // Whether the product's current release is covered, so whether to offer an upgrade. Read as
1182
+ // covered when unreadable, so a garbled answer never pushes an upgrade nobody needs.
1183
+ coversCurrentRelease: import_zod10.z.boolean().catch(true),
1184
+ // Where to buy the upgrade or renewal for this license, while the product sells one.
1185
+ upgradeUrl: import_zod10.z.string().nullish().catch(void 0)
1186
+ });
1187
+ var licenseSchema = import_zod10.z.object({
1188
+ id: import_zod10.z.string(),
1189
+ status: import_zod10.z.nativeEnum(LicenseStatus),
1043
1190
  product: productSummarySchema,
1044
- activeNumberOfActivations: import_zod9.z.number(),
1045
- maxNumberOfActivations: import_zod9.z.number(),
1191
+ activeNumberOfActivations: import_zod10.z.number(),
1192
+ maxNumberOfActivations: import_zod10.z.number(),
1046
1193
  externalFulfillment: externalLicenseContent.optional(),
1047
- requiredConnectedAccount: import_zod9.z.nativeEnum(ConnectableAccountProvider).nullish(),
1048
- fulfillmentMessage: import_zod9.z.string().optional(),
1049
- properties: import_zod9.z.record(rawPropertyValueSchema).nullish(),
1050
- expiresAt: import_zod9.z.coerce.date().optional(),
1051
- createdAt: import_zod9.z.coerce.date()
1052
- });
1053
- var activationSchema = import_zod9.z.object({
1054
- id: import_zod9.z.string(),
1055
- licenseId: import_zod9.z.string(),
1056
- name: import_zod9.z.string(),
1057
- status: import_zod9.z.nativeEnum(ActivationStatus),
1058
- activationMethod: import_zod9.z.nativeEnum(ActivationMethod),
1059
- firstValidatedAt: import_zod9.z.coerce.date(),
1060
- lastValidatedAt: import_zod9.z.coerce.date().nullable()
1194
+ requiredConnectedAccount: import_zod10.z.nativeEnum(ConnectableAccountProvider).nullish(),
1195
+ fulfillmentMessage: import_zod10.z.string().optional(),
1196
+ properties: import_zod10.z.record(rawPropertyValueSchema).nullish(),
1197
+ expiresAt: import_zod10.z.coerce.date().optional(),
1198
+ createdAt: import_zod10.z.coerce.date(),
1199
+ releaseAccess: licenseReleaseAccessSchema.nullish().catch(void 0)
1200
+ });
1201
+ var activationSchema = import_zod10.z.object({
1202
+ id: import_zod10.z.string(),
1203
+ licenseId: import_zod10.z.string(),
1204
+ name: import_zod10.z.string(),
1205
+ status: import_zod10.z.nativeEnum(ActivationStatus),
1206
+ activationMethod: import_zod10.z.nativeEnum(ActivationMethod),
1207
+ firstValidatedAt: import_zod10.z.coerce.date(),
1208
+ lastValidatedAt: import_zod10.z.coerce.date().nullable()
1061
1209
  });
1062
1210
 
1063
1211
  // src/inventory/activation/endpoints.ts
@@ -1074,7 +1222,7 @@ var ActivationEndpoints = class {
1074
1222
  });
1075
1223
  return {
1076
1224
  license: response.data,
1077
- url: import_zod10.z.string().parse(response.headers.location)
1225
+ url: import_zod11.z.string().parse(response.headers.location)
1078
1226
  };
1079
1227
  }
1080
1228
  };
@@ -1102,7 +1250,7 @@ var LicenseEndpoints = class {
1102
1250
  };
1103
1251
 
1104
1252
  // src/inventory/products/endpoints.ts
1105
- var import_zod11 = require("zod");
1253
+ var import_zod12 = require("zod");
1106
1254
  var ProductEndpoints = class {
1107
1255
  constructor(api, configuration) {
1108
1256
  this.api = api;
@@ -1136,18 +1284,18 @@ var ProductEndpoints = class {
1136
1284
  async getDownloadUrl(path) {
1137
1285
  const url = new URL(path);
1138
1286
  url.searchParams.append("redirect", "false");
1139
- const response = await this.api.fetch(url.pathname + url.search, import_zod11.z.object({
1140
- location: import_zod11.z.string()
1287
+ const response = await this.api.fetch(url.pathname + url.search, import_zod12.z.object({
1288
+ location: import_zod12.z.string()
1141
1289
  }));
1142
1290
  return response.data.location;
1143
1291
  }
1144
1292
  };
1145
1293
 
1146
1294
  // src/inventory/subscriptions/endpoints.ts
1147
- var import_zod14 = require("zod");
1295
+ var import_zod15 = require("zod");
1148
1296
 
1149
1297
  // package.json
1150
- var version = "3.8.0";
1298
+ var version = "3.10.0";
1151
1299
 
1152
1300
  // src/utils/client.ts
1153
1301
  function buildClientHeader(sdk) {
@@ -1155,6 +1303,11 @@ function buildClientHeader(sdk) {
1155
1303
  }
1156
1304
 
1157
1305
  // src/utils/api.ts
1306
+ function loggableBody(body) {
1307
+ if (!body || typeof body !== "object" || Array.isArray(body))
1308
+ return body;
1309
+ return Object.fromEntries(Object.entries(body).map(([key, value]) => [key, /password|token/i.test(key) && value != null ? "[redacted]" : value]));
1310
+ }
1158
1311
  function objectToQuery(obj) {
1159
1312
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
1160
1313
  }
@@ -1176,7 +1329,7 @@ var MoonbaseApi = class {
1176
1329
  const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
1177
1330
  this.logger.debug("Making request to Moonbase API...", {
1178
1331
  path,
1179
- body: options == null ? void 0 : options.body
1332
+ body: loggableBody(options == null ? void 0 : options.body)
1180
1333
  });
1181
1334
  const startedAt = /* @__PURE__ */ new Date();
1182
1335
  const request = {
@@ -1189,7 +1342,8 @@ var MoonbaseApi = class {
1189
1342
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
1190
1343
  // Force CORS on all calls
1191
1344
  "x-mb-cors": "1",
1192
- "x-mb-client": this.clientHeader
1345
+ "x-mb-client": this.clientHeader,
1346
+ ...options == null ? void 0 : options.headers
1193
1347
  },
1194
1348
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
1195
1349
  signal: options == null ? void 0 : options.abort,
@@ -1299,7 +1453,7 @@ __export(schemas_exports8, {
1299
1453
  milestoneProgressSchema: () => milestoneProgressSchema,
1300
1454
  subscriptionSchema: () => subscriptionSchema
1301
1455
  });
1302
- var import_zod13 = require("zod");
1456
+ var import_zod14 = require("zod");
1303
1457
 
1304
1458
  // src/orders/schemas.ts
1305
1459
  var schemas_exports7 = {};
@@ -1313,7 +1467,7 @@ __export(schemas_exports7, {
1313
1467
  orderSchema: () => orderSchema,
1314
1468
  orderTotalSchema: () => orderTotalSchema
1315
1469
  });
1316
- var import_zod12 = require("zod");
1470
+ var import_zod13 = require("zod");
1317
1471
 
1318
1472
  // src/orders/models.ts
1319
1473
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
@@ -1326,18 +1480,18 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
1326
1480
  })(OrderStatus || {});
1327
1481
 
1328
1482
  // src/orders/schemas.ts
1329
- var couponSchema = import_zod12.z.object({
1330
- code: import_zod12.z.string(),
1331
- name: import_zod12.z.string(),
1332
- description: import_zod12.z.string()
1333
- });
1334
- var lineItemProductSchema = import_zod12.z.object({
1335
- id: import_zod12.z.string(),
1336
- name: import_zod12.z.string(),
1337
- tagline: import_zod12.z.string().nullish(),
1338
- iconUrl: import_zod12.z.string().nullable()
1339
- });
1340
- var lineItemTotalSchema = import_zod12.z.object({
1483
+ var couponSchema = import_zod13.z.object({
1484
+ code: import_zod13.z.string(),
1485
+ name: import_zod13.z.string(),
1486
+ description: import_zod13.z.string()
1487
+ });
1488
+ var lineItemProductSchema = import_zod13.z.object({
1489
+ id: import_zod13.z.string(),
1490
+ name: import_zod13.z.string(),
1491
+ tagline: import_zod13.z.string().nullish(),
1492
+ iconUrl: import_zod13.z.string().nullable()
1493
+ });
1494
+ var lineItemTotalSchema = import_zod13.z.object({
1341
1495
  original: moneySchema,
1342
1496
  discount: moneySchema,
1343
1497
  subtotal: moneySchema,
@@ -1346,52 +1500,59 @@ var lineItemTotalSchema = import_zod12.z.object({
1346
1500
  // for this item. Both are part of `discount`. Absent on orders priced before cart offers existed.
1347
1501
  cartOfferDiscount: moneySchema.optional()
1348
1502
  });
1349
- var openProductLineItem = import_zod12.z.object({
1350
- id: import_zod12.z.string(),
1351
- type: import_zod12.z.literal("Product"),
1352
- productId: import_zod12.z.string(),
1353
- quantity: import_zod12.z.number(),
1354
- variationId: import_zod12.z.string(),
1355
- offerId: import_zod12.z.string().optional(),
1356
- isDefaultVariation: import_zod12.z.boolean().nullish(),
1357
- isSubcriptionPayment: import_zod12.z.boolean().nullish(),
1503
+ var openProductLineItem = import_zod13.z.object({
1504
+ id: import_zod13.z.string(),
1505
+ type: import_zod13.z.literal("Product"),
1506
+ productId: import_zod13.z.string(),
1507
+ quantity: import_zod13.z.number(),
1508
+ variationId: import_zod13.z.string(),
1509
+ offerId: import_zod13.z.string().optional(),
1510
+ isDefaultVariation: import_zod13.z.boolean().nullish(),
1511
+ isSubcriptionPayment: import_zod13.z.boolean().nullish(),
1358
1512
  price: priceCollectionSchema.optional(),
1359
1513
  variation: pricingVariationSchema.optional(),
1360
1514
  total: lineItemTotalSchema.nullish(),
1361
1515
  product: lineItemProductSchema.optional(),
1362
- appliedDiscount: discountSchema.optional()
1363
- });
1364
- var lineItemBundleSchema = import_zod12.z.object({
1365
- id: import_zod12.z.string(),
1366
- name: import_zod12.z.string(),
1367
- tagline: import_zod12.z.string().nullish(),
1368
- iconUrl: import_zod12.z.string().nullable(),
1369
- products: lineItemProductSchema.and(import_zod12.z.object({
1370
- included: import_zod12.z.boolean().optional()
1516
+ appliedDiscount: discountSchema.optional(),
1517
+ // The customer's license this line upgrades or renews, as the cart named it. Such a line is one
1518
+ // license, so its quantity is always 1, and the line's `id` names the license too
1519
+ // (`p/<productId>/<variationId>/<licenseId>`): upgrading two licenses takes two lines. A line
1520
+ // without one issues new licenses. Part of the cart payload like `offerId`, so a push that leaves
1521
+ // it out forgets it. Echoed on completed orders too. Absent from a backend that predates release
1522
+ // access.
1523
+ targetLicenseId: import_zod13.z.string().nullish().catch(void 0)
1524
+ });
1525
+ var lineItemBundleSchema = import_zod13.z.object({
1526
+ id: import_zod13.z.string(),
1527
+ name: import_zod13.z.string(),
1528
+ tagline: import_zod13.z.string().nullish(),
1529
+ iconUrl: import_zod13.z.string().nullable(),
1530
+ products: lineItemProductSchema.and(import_zod13.z.object({
1531
+ included: import_zod13.z.boolean().optional()
1371
1532
  })).array()
1372
1533
  });
1373
- var openBundleLineItem = import_zod12.z.object({
1374
- id: import_zod12.z.string(),
1375
- type: import_zod12.z.literal("Bundle"),
1376
- bundleId: import_zod12.z.string(),
1377
- quantity: import_zod12.z.number(),
1378
- variationId: import_zod12.z.string(),
1379
- offerId: import_zod12.z.string().optional(),
1380
- partial: import_zod12.z.boolean().optional(),
1381
- replaced: import_zod12.z.string().array().optional(),
1382
- isDefaultVariation: import_zod12.z.boolean().nullish(),
1383
- isSubcriptionPayment: import_zod12.z.boolean().nullish(),
1534
+ var openBundleLineItem = import_zod13.z.object({
1535
+ id: import_zod13.z.string(),
1536
+ type: import_zod13.z.literal("Bundle"),
1537
+ bundleId: import_zod13.z.string(),
1538
+ quantity: import_zod13.z.number(),
1539
+ variationId: import_zod13.z.string(),
1540
+ offerId: import_zod13.z.string().optional(),
1541
+ partial: import_zod13.z.boolean().optional(),
1542
+ replaced: import_zod13.z.string().array().optional(),
1543
+ isDefaultVariation: import_zod13.z.boolean().nullish(),
1544
+ isSubcriptionPayment: import_zod13.z.boolean().nullish(),
1384
1545
  price: priceCollectionSchema.optional(),
1385
1546
  variation: pricingVariationSchema.optional(),
1386
1547
  total: lineItemTotalSchema.nullish(),
1387
1548
  bundle: lineItemBundleSchema.optional(),
1388
1549
  appliedDiscount: discountSchema.optional()
1389
1550
  });
1390
- var openOrderLineItem = import_zod12.z.discriminatedUnion("type", [
1551
+ var openOrderLineItem = import_zod13.z.discriminatedUnion("type", [
1391
1552
  openProductLineItem,
1392
1553
  openBundleLineItem
1393
1554
  ]);
1394
- var orderTotalSchema = import_zod12.z.object({
1555
+ var orderTotalSchema = import_zod13.z.object({
1395
1556
  original: moneySchema,
1396
1557
  discount: moneySchema,
1397
1558
  subtotal: moneySchema,
@@ -1401,52 +1562,52 @@ var orderTotalSchema = import_zod12.z.object({
1401
1562
  // rather than a share on every line. Absent when no cart offer applied.
1402
1563
  cartOfferDiscount: moneySchema.optional()
1403
1564
  });
1404
- var openOrderSchema = import_zod12.z.object({
1405
- id: import_zod12.z.string(),
1406
- currency: import_zod12.z.string(),
1565
+ var openOrderSchema = import_zod13.z.object({
1566
+ id: import_zod13.z.string(),
1567
+ currency: import_zod13.z.string(),
1407
1568
  total: orderTotalSchema.nullish(),
1408
1569
  items: openOrderLineItem.array(),
1409
1570
  couponsApplied: couponSchema.array(),
1410
1571
  // The cart offer on the order as a whole: the buyer's intent. It is part of the cart payload, so
1411
1572
  // a content push that leaves it out clears it. The API echoes it back even while the cart sits
1412
1573
  // below the offer's threshold.
1413
- offerId: import_zod12.z.string().optional(),
1574
+ offerId: import_zod13.z.string().optional(),
1414
1575
  // The cart offer as actually applied: the result. Absent while the offer's condition doesn't hold.
1415
1576
  appliedOffer: discountSchema.optional(),
1416
- checkoutUrl: import_zod12.z.string().optional(),
1417
- hostedCheckoutUrl: import_zod12.z.string().optional(),
1418
- embeddedCheckoutUrl: import_zod12.z.string().optional()
1419
- });
1420
- var customerSnapshotSchema = import_zod12.z.object({
1421
- name: import_zod12.z.string().nullable(),
1422
- businessName: import_zod12.z.string().nullable(),
1423
- taxId: import_zod12.z.string().nullable(),
1424
- email: import_zod12.z.string().nullable(),
1425
- phone: import_zod12.z.string().nullable(),
1577
+ checkoutUrl: import_zod13.z.string().optional(),
1578
+ hostedCheckoutUrl: import_zod13.z.string().optional(),
1579
+ embeddedCheckoutUrl: import_zod13.z.string().optional()
1580
+ });
1581
+ var customerSnapshotSchema = import_zod13.z.object({
1582
+ name: import_zod13.z.string().nullable(),
1583
+ businessName: import_zod13.z.string().nullable(),
1584
+ taxId: import_zod13.z.string().nullable(),
1585
+ email: import_zod13.z.string().nullable(),
1586
+ phone: import_zod13.z.string().nullable(),
1426
1587
  address: addressSchema.nullable()
1427
1588
  });
1428
- var completedOrderSchema = import_zod12.z.object({
1429
- id: import_zod12.z.string(),
1430
- status: import_zod12.z.literal("Completed" /* Completed */),
1431
- currency: import_zod12.z.string(),
1589
+ var completedOrderSchema = import_zod13.z.object({
1590
+ id: import_zod13.z.string(),
1591
+ status: import_zod13.z.literal("Completed" /* Completed */),
1592
+ currency: import_zod13.z.string(),
1432
1593
  customer: customerSnapshotSchema,
1433
1594
  total: orderTotalSchema,
1434
1595
  items: openOrderLineItem.array(),
1435
1596
  couponsApplied: couponSchema.array(),
1436
1597
  appliedOffer: discountSchema.optional()
1437
1598
  });
1438
- var orderSchema = import_zod12.z.discriminatedUnion("status", [
1599
+ var orderSchema = import_zod13.z.discriminatedUnion("status", [
1439
1600
  openOrderSchema.extend({
1440
- status: import_zod12.z.literal("Open" /* Open */)
1601
+ status: import_zod13.z.literal("Open" /* Open */)
1441
1602
  }),
1442
1603
  openOrderSchema.extend({
1443
- status: import_zod12.z.literal("PaymentProcessing" /* PaymentProcessing */)
1604
+ status: import_zod13.z.literal("PaymentProcessing" /* PaymentProcessing */)
1444
1605
  }),
1445
1606
  openOrderSchema.extend({
1446
- status: import_zod12.z.literal("Paid" /* Paid */)
1607
+ status: import_zod13.z.literal("Paid" /* Paid */)
1447
1608
  }),
1448
1609
  openOrderSchema.extend({
1449
- status: import_zod12.z.literal("Failed" /* Failed */)
1610
+ status: import_zod13.z.literal("Failed" /* Failed */)
1450
1611
  }),
1451
1612
  completedOrderSchema
1452
1613
  ]);
@@ -1470,58 +1631,58 @@ var SubscriptionCancellationReason = /* @__PURE__ */ ((SubscriptionCancellationR
1470
1631
  })(SubscriptionCancellationReason || {});
1471
1632
 
1472
1633
  // src/inventory/subscriptions/schemas.ts
1473
- var baseMilestoneProgressEventSchema = import_zod13.z.object({
1474
- milestoneId: import_zod13.z.string(),
1475
- fulfilled: import_zod13.z.boolean(),
1476
- afterCycleNumber: import_zod13.z.number(),
1477
- afterNormalizedCycleNumber: import_zod13.z.number(),
1478
- message: import_zod13.z.string().optional()
1479
- });
1480
- var milestoneProgressEventSchema = import_zod13.z.discriminatedUnion("type", [
1634
+ var baseMilestoneProgressEventSchema = import_zod14.z.object({
1635
+ milestoneId: import_zod14.z.string(),
1636
+ fulfilled: import_zod14.z.boolean(),
1637
+ afterCycleNumber: import_zod14.z.number(),
1638
+ afterNormalizedCycleNumber: import_zod14.z.number(),
1639
+ message: import_zod14.z.string().optional()
1640
+ });
1641
+ var milestoneProgressEventSchema = import_zod14.z.discriminatedUnion("type", [
1481
1642
  baseMilestoneProgressEventSchema.extend({
1482
- type: import_zod13.z.literal("CouponCodeMilestone"),
1483
- code: import_zod13.z.string().optional(),
1484
- redeemed: import_zod13.z.boolean().optional()
1643
+ type: import_zod14.z.literal("CouponCodeMilestone"),
1644
+ code: import_zod14.z.string().optional(),
1645
+ redeemed: import_zod14.z.boolean().optional()
1485
1646
  }),
1486
1647
  baseMilestoneProgressEventSchema.extend({
1487
- type: import_zod13.z.literal("PerpetualLicenseConversionMilestone")
1648
+ type: import_zod14.z.literal("PerpetualLicenseConversionMilestone")
1488
1649
  })
1489
1650
  ]);
1490
- var milestoneProgressSchema = import_zod13.z.object({
1491
- title: import_zod13.z.string(),
1492
- description: import_zod13.z.string().nullish(),
1493
- currentCycleNumber: import_zod13.z.number(),
1494
- currentNormalizedCycleNumber: import_zod13.z.number(),
1495
- currentCycleIsCompleted: import_zod13.z.boolean(),
1496
- fromCycleNumber: import_zod13.z.number(),
1497
- fromNormalizedCycleNumber: import_zod13.z.number(),
1498
- toCycleNumber: import_zod13.z.number(),
1499
- toNormalizedCycleNumber: import_zod13.z.number(),
1500
- events: import_zod13.z.record(import_zod13.z.coerce.number(), milestoneProgressEventSchema.array())
1501
- });
1502
- var subscriptionSchema = import_zod13.z.object({
1503
- id: import_zod13.z.string(),
1504
- status: import_zod13.z.nativeEnum(SubscriptionStatus),
1505
- hasPaymentMethod: import_zod13.z.boolean(),
1506
- cancellable: import_zod13.z.boolean(),
1507
- expiresAt: import_zod13.z.coerce.date(),
1508
- renewedAt: import_zod13.z.coerce.date().nullable(),
1509
- nextPaymentScheduledAt: import_zod13.z.coerce.date().nullable(),
1510
- startedAt: import_zod13.z.coerce.date(),
1651
+ var milestoneProgressSchema = import_zod14.z.object({
1652
+ title: import_zod14.z.string(),
1653
+ description: import_zod14.z.string().nullish(),
1654
+ currentCycleNumber: import_zod14.z.number(),
1655
+ currentNormalizedCycleNumber: import_zod14.z.number(),
1656
+ currentCycleIsCompleted: import_zod14.z.boolean(),
1657
+ fromCycleNumber: import_zod14.z.number(),
1658
+ fromNormalizedCycleNumber: import_zod14.z.number(),
1659
+ toCycleNumber: import_zod14.z.number(),
1660
+ toNormalizedCycleNumber: import_zod14.z.number(),
1661
+ events: import_zod14.z.record(import_zod14.z.coerce.number(), milestoneProgressEventSchema.array())
1662
+ });
1663
+ var subscriptionSchema = import_zod14.z.object({
1664
+ id: import_zod14.z.string(),
1665
+ status: import_zod14.z.nativeEnum(SubscriptionStatus),
1666
+ hasPaymentMethod: import_zod14.z.boolean(),
1667
+ cancellable: import_zod14.z.boolean(),
1668
+ expiresAt: import_zod14.z.coerce.date(),
1669
+ renewedAt: import_zod14.z.coerce.date().nullable(),
1670
+ nextPaymentScheduledAt: import_zod14.z.coerce.date().nullable(),
1671
+ startedAt: import_zod14.z.coerce.date(),
1511
1672
  total: orderTotalSchema,
1512
- cycleLength: import_zod13.z.nativeEnum(CycleLength),
1513
- paymentMethod: import_zod13.z.string().optional(),
1673
+ cycleLength: import_zod14.z.nativeEnum(CycleLength),
1674
+ paymentMethod: import_zod14.z.string().optional(),
1514
1675
  milestoneProgress: milestoneProgressSchema.nullish(),
1515
- embeddedUpdatePaymentUrl: import_zod13.z.string().optional(),
1516
- content: import_zod13.z.discriminatedUnion("type", [
1517
- import_zod13.z.object({
1518
- type: import_zod13.z.literal("Product"),
1519
- quantity: import_zod13.z.number(),
1676
+ embeddedUpdatePaymentUrl: import_zod14.z.string().optional(),
1677
+ content: import_zod14.z.discriminatedUnion("type", [
1678
+ import_zod14.z.object({
1679
+ type: import_zod14.z.literal("Product"),
1680
+ quantity: import_zod14.z.number(),
1520
1681
  product: storefrontProductSchema
1521
1682
  }),
1522
- import_zod13.z.object({
1523
- type: import_zod13.z.literal("Bundle"),
1524
- quantity: import_zod13.z.number(),
1683
+ import_zod14.z.object({
1684
+ type: import_zod14.z.literal("Bundle"),
1685
+ quantity: import_zod14.z.number(),
1525
1686
  bundle: storefrontBundleSchema
1526
1687
  })
1527
1688
  ])
@@ -1557,8 +1718,8 @@ var SubscriptionEndpoints = class {
1557
1718
  return response.data;
1558
1719
  }
1559
1720
  async renew(subscriptionId, returnUrl, embedded) {
1560
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/renew?redirect=false&return=${returnUrl}&embedded=${embedded ? "true" : "false"}`, import_zod14.z.object({
1561
- location: import_zod14.z.string()
1721
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/renew?redirect=false&return=${returnUrl}&embedded=${embedded ? "true" : "false"}`, import_zod15.z.object({
1722
+ location: import_zod15.z.string()
1562
1723
  }), { method: "POST" });
1563
1724
  return response.data;
1564
1725
  }
@@ -1825,6 +1986,50 @@ var InMemoryStore = class {
1825
1986
  }
1826
1987
  };
1827
1988
 
1989
+ // src/utils/pendingPasswords.ts
1990
+ var lifetime = 24 * 60 * 60 * 1e3;
1991
+ function normalizeEmail(email) {
1992
+ return email.trim().toLowerCase();
1993
+ }
1994
+ var _PendingPasswordStore = class _PendingPasswordStore {
1995
+ constructor(store) {
1996
+ this.store = store != null ? store : isLocalStorageAvailable() ? new LocalStorageStore() : new InMemoryStore();
1997
+ }
1998
+ get(email) {
1999
+ var _a, _b;
2000
+ return (_b = (_a = this.read()[normalizeEmail(email)]) == null ? void 0 : _a.token) != null ? _b : null;
2001
+ }
2002
+ set(email, token) {
2003
+ this.write({ ...this.read(), [normalizeEmail(email)]: { token, storedAt: Date.now() } });
2004
+ }
2005
+ remove(email) {
2006
+ const entries = this.read();
2007
+ delete entries[normalizeEmail(email)];
2008
+ this.write(entries);
2009
+ }
2010
+ /** The entries still worth keeping. Drops the rest from storage as it goes. */
2011
+ read() {
2012
+ const stored = this.store.get(_PendingPasswordStore.storageKey);
2013
+ if (!stored || typeof stored !== "object")
2014
+ return {};
2015
+ const now = Date.now();
2016
+ const fresh = Object.fromEntries(Object.entries(stored).filter(
2017
+ ([, entry]) => typeof (entry == null ? void 0 : entry.token) === "string" && typeof entry.storedAt === "number" && now - entry.storedAt < lifetime
2018
+ ));
2019
+ if (Object.keys(fresh).length !== Object.keys(stored).length)
2020
+ this.write(fresh);
2021
+ return fresh;
2022
+ }
2023
+ write(entries) {
2024
+ if (Object.keys(entries).length > 0)
2025
+ this.store.set(_PendingPasswordStore.storageKey, entries);
2026
+ else
2027
+ this.store.remove(_PendingPasswordStore.storageKey);
2028
+ }
2029
+ };
2030
+ _PendingPasswordStore.storageKey = "moonbase_pending_passwords";
2031
+ var PendingPasswordStore = _PendingPasswordStore;
2032
+
1828
2033
  // src/utils/tokenStore.ts
1829
2034
  var defaultAccessTokenLifetime = 15 * 60 * 1e3;
1830
2035
  var renewBeforeExpiry = 5 * 60 * 1e3;
@@ -1834,9 +2039,9 @@ function accessTokenLifetime(accessToken) {
1834
2039
  try {
1835
2040
  const payload = accessToken.split(".")[1].replaceAll("-", "+").replaceAll("_", "/");
1836
2041
  const claims = JSON.parse(atob(payload.padEnd(Math.ceil(payload.length / 4) * 4, "=")));
1837
- const lifetime = (Number(claims.exp) - Number(claims.iat)) * 1e3;
1838
- if (Number.isFinite(lifetime) && lifetime > 0 && lifetime <= 24 * 60 * 60 * 1e3)
1839
- return lifetime;
2042
+ const lifetime2 = (Number(claims.exp) - Number(claims.iat)) * 1e3;
2043
+ if (Number.isFinite(lifetime2) && lifetime2 > 0 && lifetime2 <= 24 * 60 * 60 * 1e3)
2044
+ return lifetime2;
1840
2045
  } catch (e) {
1841
2046
  }
1842
2047
  return defaultAccessTokenLifetime;
@@ -2083,21 +2288,21 @@ __export(schemas_exports9, {
2083
2288
  vendorFeaturesSchema: () => vendorFeaturesSchema,
2084
2289
  vendorSchema: () => vendorSchema
2085
2290
  });
2086
- var import_zod15 = require("zod");
2087
- var vendorCaptchaSchema = import_zod15.z.object({
2088
- url: import_zod15.z.string()
2291
+ var import_zod16 = require("zod");
2292
+ var vendorCaptchaSchema = import_zod16.z.object({
2293
+ url: import_zod16.z.string()
2089
2294
  });
2090
- var vendorFeaturesSchema = import_zod15.z.object({
2091
- customerPortal: import_zod15.z.boolean().optional(),
2092
- phoneNumber: import_zod15.z.boolean().optional(),
2093
- marketingConsent: import_zod15.z.nativeEnum(MarketingConsentType).optional().catch(void 0),
2295
+ var vendorFeaturesSchema = import_zod16.z.object({
2296
+ customerPortal: import_zod16.z.boolean().optional(),
2297
+ phoneNumber: import_zod16.z.boolean().optional(),
2298
+ marketingConsent: import_zod16.z.nativeEnum(MarketingConsentType).optional().catch(void 0),
2094
2299
  // Absent on backends from before captchas, which never ask for one.
2095
2300
  captcha: vendorCaptchaSchema.nullish()
2096
2301
  });
2097
- var vendorSchema = import_zod15.z.object({
2098
- id: import_zod15.z.string(),
2099
- name: import_zod15.z.string(),
2100
- logoUrl: import_zod15.z.string().nullable(),
2302
+ var vendorSchema = import_zod16.z.object({
2303
+ id: import_zod16.z.string(),
2304
+ name: import_zod16.z.string(),
2305
+ logoUrl: import_zod16.z.string().nullable(),
2101
2306
  features: vendorFeaturesSchema.optional()
2102
2307
  });
2103
2308
 
@@ -2117,16 +2322,16 @@ var schemas_exports10 = {};
2117
2322
  __export(schemas_exports10, {
2118
2323
  voucherSchema: () => voucherSchema
2119
2324
  });
2120
- var import_zod16 = require("zod");
2121
- var voucherSchema = import_zod16.z.object({
2122
- id: import_zod16.z.string(),
2123
- name: import_zod16.z.string(),
2124
- description: import_zod16.z.string(),
2125
- code: import_zod16.z.string(),
2126
- redeemed: import_zod16.z.boolean(),
2325
+ var import_zod17 = require("zod");
2326
+ var voucherSchema = import_zod17.z.object({
2327
+ id: import_zod17.z.string(),
2328
+ name: import_zod17.z.string(),
2329
+ description: import_zod17.z.string(),
2330
+ code: import_zod17.z.string(),
2331
+ redeemed: import_zod17.z.boolean(),
2127
2332
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
2128
2333
  redeemsBundles: quantifiable(storefrontBundleSchema).array(),
2129
- properties: import_zod16.z.record(rawPropertyValueSchema).nullish()
2334
+ properties: import_zod17.z.record(rawPropertyValueSchema).nullish()
2130
2335
  });
2131
2336
 
2132
2337
  // src/vouchers/endpoints.ts
@@ -2327,11 +2532,48 @@ var OfferUtils = class _OfferUtils {
2327
2532
  // src/utils/cart.ts
2328
2533
  var _CartUtils = class _CartUtils {
2329
2534
  // The pricing variation a line item points at, falling back to the item's default variation when
2330
- // the variation id doesn't resolve, which is what the cart has always displayed.
2535
+ // the variation id doesn't resolve, which is what the cart has always displayed. A line upgrading
2536
+ // one of the customer's licenses is priced for that license, as the API prices it.
2331
2537
  static resolveVariation(catalog, item) {
2332
- var _a, _b;
2333
- const source = item.type === "Product" ? catalog.products.find((p) => p.id === item.productId) : catalog.bundles.find((b) => b.id === item.bundleId);
2334
- return (_b = (_a = source == null ? void 0 : source.variations) == null ? void 0 : _a.find((v) => v.id === item.variationId)) != null ? _b : source == null ? void 0 : source.defaultVariation;
2538
+ var _a, _b, _c;
2539
+ if (item.type === "Product") {
2540
+ const product = catalog.products.find((p) => p.id === item.productId);
2541
+ return (_a = _CartUtils.productLineVariation(product, item.variationId, item.targetLicenseId)) != null ? _a : product == null ? void 0 : product.defaultVariation;
2542
+ }
2543
+ const bundle = catalog.bundles.find((b) => b.id === item.bundleId);
2544
+ return (_c = (_b = bundle == null ? void 0 : bundle.variations) == null ? void 0 : _b.find((v) => v.id === item.variationId)) != null ? _c : bundle == null ? void 0 : bundle.defaultVariation;
2545
+ }
2546
+ /**
2547
+ * The storefront's entry for upgrading or renewing one of the signed-in customer's licenses of a
2548
+ * product: what it covers now, and the variations that would upgrade it, priced for it. Licenses
2549
+ * that cover the same share an entry. `undefined` when the storefront has none for it (the license
2550
+ * is not theirs, covers every release, is past the cap on entries, or the customer is not signed in).
2551
+ */
2552
+ static licenseUpgrade(product, licenseId) {
2553
+ var _a;
2554
+ if (!product || !licenseId)
2555
+ return void 0;
2556
+ const wanted = licenseId.toLowerCase();
2557
+ return (_a = product.licenseUpgrades) == null ? void 0 : _a.find((u) => u.licenseIds.some((id) => id.toLowerCase() === wanted));
2558
+ }
2559
+ /**
2560
+ * The variations that would upgrade or renew one of the signed-in customer's licenses of a
2561
+ * product, priced for that license, or `undefined` when the storefront has no price for it.
2562
+ */
2563
+ static licenseUpgradeVariations(product, licenseId) {
2564
+ var _a;
2565
+ return (_a = _CartUtils.licenseUpgrade(product, licenseId)) == null ? void 0 : _a.variations;
2566
+ }
2567
+ /**
2568
+ * The variation a product line is priced at. A line naming one of the customer's licenses
2569
+ * (`targetLicenseId`) upgrades that license, and an upgrade discount is judged per license, so its
2570
+ * price comes from the product's `licenseUpgrades` for that license. Every other line, and an
2571
+ * upgrade line the storefront has no price for, takes the product's own variation, which is what
2572
+ * a new license costs.
2573
+ */
2574
+ static productLineVariation(product, variationId, targetLicenseId) {
2575
+ var _a, _b, _c;
2576
+ return (_c = (_a = _CartUtils.licenseUpgradeVariations(product, targetLicenseId)) == null ? void 0 : _a.find((v) => v.id === variationId)) != null ? _c : (_b = product == null ? void 0 : product.variations) == null ? void 0 : _b.find((v) => v.id === variationId);
2335
2577
  }
2336
2578
  // A line's unit price after its product discount and any pricing tier, and *before* any offer.
2337
2579
  // This is the basis the API measures cart total conditions on, which is why it reads the catalog
@@ -2778,7 +3020,7 @@ var MoonbaseClient = class {
2778
3020
  this.tokenStore = new TokenStore(configuration);
2779
3021
  this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
2780
3022
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
2781
- this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
3023
+ this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger, new PendingPasswordStore(configuration.store));
2782
3024
  this.communications = new CommunicationsEndpoints(this.api);
2783
3025
  this.groups = new GroupEndpoints(this.api);
2784
3026
  this.vouchers = new VoucherEndpoints(this.api);
@@ -2816,7 +3058,9 @@ var MoonbaseClient = class {
2816
3058
  NotFoundError,
2817
3059
  OfferUtils,
2818
3060
  OrderStatus,
3061
+ PasswordSetupRequiredError,
2819
3062
  Platform,
3063
+ ReleaseNotCoveredError,
2820
3064
  StoreClosedError,
2821
3065
  SubscriptionCancellationReason,
2822
3066
  SubscriptionStatus,