@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.js CHANGED
@@ -20,6 +20,7 @@ __export(schemas_exports2, {
20
20
  offerConditionSchema: () => offerConditionSchema,
21
21
  offerScopeSchema: () => offerScopeSchema,
22
22
  storefrontBundleSchema: () => storefrontBundleSchema,
23
+ storefrontLicenseUpgradeSchema: () => storefrontLicenseUpgradeSchema,
23
24
  storefrontOfferSchema: () => storefrontOfferSchema,
24
25
  storefrontOfferTargetSchema: () => storefrontOfferTargetSchema,
25
26
  storefrontProductSchema: () => storefrontProductSchema,
@@ -154,6 +155,7 @@ var schemas_exports = {};
154
155
  __export(schemas_exports, {
155
156
  downloadSchema: () => downloadSchema,
156
157
  manifestSchema: () => manifestSchema,
158
+ productReleaseAccessSchema: () => productReleaseAccessSchema,
157
159
  productReleaseSchema: () => productReleaseSchema,
158
160
  productSummarySchema: () => productSummarySchema
159
161
  });
@@ -196,6 +198,21 @@ var downloadSchema = z2.object({
196
198
  path: z2.string().nullable(),
197
199
  manifest: manifestSchema.optional()
198
200
  });
201
+ var productReleaseAccessSchema = z2.object({
202
+ // Releases published until then are covered, and every version while it has not passed.
203
+ updatesUntil: z2.coerce.date().nullish().catch(void 0),
204
+ // Every version whose major is at most this is covered.
205
+ upToMajor: z2.number().nullish().catch(void 0),
206
+ // Once updates have ended, the last version published before they did.
207
+ upToVersion: z2.string().nullish().catch(void 0),
208
+ // Whether the release this was resolved for (the one shown) is covered. Read as covered when
209
+ // unreadable, so a garbled answer never locks a download the API would hand out.
210
+ coversRelease: z2.boolean().catch(true),
211
+ // The newest published version the customer may download, when the shown one is not covered.
212
+ latestCoveredVersion: z2.string().nullish().catch(void 0),
213
+ // Where to buy the upgrade or renewal, while the product sells one.
214
+ upgradeUrl: z2.string().nullish().catch(void 0)
215
+ });
199
216
  var productSummarySchema = z2.object({
200
217
  id: z2.string(),
201
218
  name: z2.string(),
@@ -219,7 +236,10 @@ var productSummarySchema = z2.object({
219
236
  // Whether this caller clears every requirement above, including the group membership the client
220
237
  // can't see for itself. False with none of them set means the merchant closed the release to everyone.
221
238
  downloadsAllowed: z2.boolean(),
222
- downloads: z2.array(downloadSchema).optional()
239
+ downloads: z2.array(downloadSchema).optional(),
240
+ // Set only when the customer's licenses do not cover every release. `downloadsAllowed` already
241
+ // accounts for it; this says why a download is locked and where to upgrade.
242
+ releaseAccess: productReleaseAccessSchema.nullish().catch(void 0)
223
243
  });
224
244
  var productReleaseSchema = z2.object({
225
245
  version: z2.string(),
@@ -229,10 +249,33 @@ var productReleaseSchema = z2.object({
229
249
  // merchant can keep past releases to owners while the current one is open to anyone.
230
250
  downloadsAllowed: z2.boolean(),
231
251
  downloads: z2.array(downloadSchema),
232
- properties: z2.record(rawPropertyValueSchema).nullish()
252
+ properties: z2.record(rawPropertyValueSchema).nullish(),
253
+ // True when the caller owns the product but none of their licenses covers this release, so it
254
+ // takes an upgrade rather than a sign-in to unlock. Absent otherwise.
255
+ releaseNotCovered: z2.boolean().nullish().catch(void 0)
233
256
  });
234
257
 
235
258
  // src/storefront/schemas.ts
259
+ var storefrontLicenseUpgradeSchema = z3.object({
260
+ // The customer's licenses this entry prices. An entry without them is no use and is left out.
261
+ licenseIds: z3.string().array(),
262
+ // What those licenses cover now, which is how a cart tells the customer which of their licenses an
263
+ // upgrade is for. Read leniently, field by field: a backend that predates it leaves it out, and one
264
+ // this version cannot read reads as absent rather than costing the entry.
265
+ releaseAccess: z3.object({
266
+ // Releases published until then are covered, and every version while it has not passed.
267
+ updatesUntil: z3.coerce.date().nullish().catch(void 0),
268
+ // Every version whose major is at most this is covered.
269
+ upToMajor: z3.number().nullish().catch(void 0),
270
+ // Once updates have ended, the last version published before they did.
271
+ upToVersion: z3.string().nullish().catch(void 0)
272
+ }).nullish().catch(void 0),
273
+ variations: pricingVariationSchema.array()
274
+ });
275
+ var storefrontLicenseUpgradesSchema = z3.array(z3.unknown()).transform((upgrades) => upgrades.flatMap((upgrade) => {
276
+ const parsed = storefrontLicenseUpgradeSchema.safeParse(upgrade);
277
+ return parsed.success ? [parsed.data] : [];
278
+ }));
236
279
  var storefrontProductSchema = z3.object({
237
280
  id: z3.string(),
238
281
  name: z3.string(),
@@ -246,7 +289,13 @@ var storefrontProductSchema = z3.object({
246
289
  defaultVariation: pricingVariationSchema.optional(),
247
290
  variations: pricingVariationSchema.array().optional(),
248
291
  properties: z3.record(rawPropertyValueSchema).nullish(),
249
- type: z3.string().optional().default("Product").pipe(z3.literal("Product"))
292
+ type: z3.string().optional().default("Product").pipe(z3.literal("Product")),
293
+ // What upgrading or renewing the signed-in customer's licenses of the product that cover only
294
+ // some releases costs, one entry per group of licenses that cover the same, furthest behind first.
295
+ // Capped, so a customer with a great many licenses may find one in none of them. Absent for anyone
296
+ // else, and from a backend that predates per-license prices. A cart line naming one of these
297
+ // licenses (`targetLicenseId`) is priced from here: see `CartUtils.licenseUpgrade`.
298
+ licenseUpgrades: storefrontLicenseUpgradesSchema.nullish().catch(void 0)
250
299
  });
251
300
  var storefrontBundleSchema = z3.object({
252
301
  id: z3.string(),
@@ -420,7 +469,17 @@ var activationRequestSchema = z4.object({
420
469
  endless: z4.boolean().default(false)
421
470
  }).optional(),
422
471
  licenseEligibility: z4.object({
423
- eligible: z4.boolean()
472
+ eligible: z4.boolean(),
473
+ // Set when the customer's licenses would take the device but none of them covers the version
474
+ // the app runs (`eligible` is then false), so the app's version needs an upgrade. Absent from
475
+ // a backend that predates release access, and read leniently so it can never fail the request.
476
+ releaseNotCovered: z4.object({
477
+ appVersion: z4.string().nullish().catch(void 0),
478
+ updatesUntil: z4.coerce.date().nullish().catch(void 0),
479
+ upToMajor: z4.number().nullish().catch(void 0),
480
+ upToVersion: z4.string().nullish().catch(void 0),
481
+ upgradeUrl: z4.string().nullish().catch(void 0)
482
+ }).nullish().catch(void 0)
424
483
  }).optional()
425
484
  });
426
485
 
@@ -499,7 +558,8 @@ var CommunicationsEndpoints = class {
499
558
  newsletter: (_b = input.newsletter) != null ? _b : true,
500
559
  productUpdates: (_c = input.productUpdates) != null ? _c : true,
501
560
  groupIds: normalizeGroupIds(input.groupIds)
502
- }
561
+ },
562
+ headers: input.captchaToken ? { "X-MB-CAPTCHA": input.captchaToken } : void 0
503
563
  });
504
564
  return response.data;
505
565
  }
@@ -579,6 +639,15 @@ var NotAuthorizedError = class extends Error {
579
639
  this.message = "Not allowed";
580
640
  }
581
641
  };
642
+ var ReleaseNotCoveredError = class extends NotAuthorizedError {
643
+ constructor(releaseAccess, upgradeUrl, detail) {
644
+ super();
645
+ this.releaseAccess = releaseAccess;
646
+ this.upgradeUrl = upgradeUrl;
647
+ this.name = "ReleaseNotCoveredError";
648
+ this.message = detail != null ? detail : "Your license doesn't cover this version";
649
+ }
650
+ };
582
651
  var NotAuthenticatedError = class extends Error {
583
652
  constructor() {
584
653
  super();
@@ -621,6 +690,15 @@ var CaptchaRequiredError = class extends MoonbaseError {
621
690
  this.name = "CaptchaRequiredError";
622
691
  }
623
692
  };
693
+ var PasswordSetupRequiredError = class extends MoonbaseError {
694
+ constructor(detail, title, status) {
695
+ super(title != null ? title : "Password setup required", detail, status);
696
+ this.name = "PasswordSetupRequiredError";
697
+ }
698
+ };
699
+
700
+ // src/utils/problemHandler.ts
701
+ import { z as z8 } from "zod";
624
702
 
625
703
  // src/utils/problemDetails.ts
626
704
  import { z as z7 } from "zod";
@@ -635,6 +713,28 @@ var problemDetailsSchema = z7.object({
635
713
  });
636
714
 
637
715
  // src/utils/problemHandler.ts
716
+ var releaseNotCoveredProblemSchema = z8.object({
717
+ errorType: z8.literal("ReleaseNotCovered"),
718
+ detail: z8.string().nullish().catch(void 0),
719
+ releaseAccess: productReleaseAccessSchema.nullish().catch(void 0),
720
+ upgradeUrl: z8.string().nullish().catch(void 0)
721
+ });
722
+ async function forbiddenError(response) {
723
+ var _a;
724
+ try {
725
+ const problem = releaseNotCoveredProblemSchema.safeParse(JSON.parse(await response.text()));
726
+ if (problem.success) {
727
+ const { releaseAccess, upgradeUrl, detail } = problem.data;
728
+ return new ReleaseNotCoveredError(
729
+ releaseAccess != null ? releaseAccess : void 0,
730
+ (_a = upgradeUrl != null ? upgradeUrl : releaseAccess == null ? void 0 : releaseAccess.upgradeUrl) != null ? _a : void 0,
731
+ detail != null ? detail : void 0
732
+ );
733
+ }
734
+ } catch (e) {
735
+ }
736
+ return new NotAuthorizedError();
737
+ }
638
738
  function camelCase(str) {
639
739
  return str.split(".").map((word, index) => {
640
740
  let [firstLetter, ...restOfLetters] = word;
@@ -644,13 +744,14 @@ function camelCase(str) {
644
744
  }).join("");
645
745
  }
646
746
  async function handleResponseProblem(response, logger) {
747
+ var _a;
647
748
  if (response.status === 404)
648
749
  throw new NotFoundError();
649
750
  if (response.status === 401) {
650
751
  throw new NotAuthenticatedError();
651
752
  }
652
753
  if (response.status === 403) {
653
- throw new NotAuthorizedError();
754
+ throw await forbiddenError(response);
654
755
  }
655
756
  let problemDetails;
656
757
  const body = await response.text();
@@ -665,6 +766,8 @@ async function handleResponseProblem(response, logger) {
665
766
  throw new StoreClosedError(problemDetails.detail);
666
767
  if (problemDetails.errorType === "CaptchaRequired")
667
768
  throw new CaptchaRequiredError(problemDetails.detail, problemDetails.title);
769
+ if (problemDetails.errorType === "PasswordSetupRequired")
770
+ throw new PasswordSetupRequiredError(problemDetails.detail, problemDetails.title, (_a = problemDetails.status) != null ? _a : response.status);
668
771
  throw new MoonbaseError(
669
772
  problemDetails.title,
670
773
  problemDetails.detail,
@@ -683,11 +786,12 @@ __export(schemas_exports5, {
683
786
  identitySchema: () => identitySchema,
684
787
  ilokConnectedAccountSchema: () => ilokConnectedAccountSchema,
685
788
  pendingActivationSchema: () => pendingActivationSchema,
789
+ pendingPasswordProblemSchema: () => pendingPasswordProblemSchema,
686
790
  userAccountConfirmedSchema: () => userAccountConfirmedSchema,
687
791
  userAccountConfirmedStatusSchema: () => userAccountConfirmedStatusSchema,
688
792
  userSchema: () => userSchema
689
793
  });
690
- import { z as z8 } from "zod";
794
+ import { z as z9 } from "zod";
691
795
 
692
796
  // src/identity/models.ts
693
797
  var ConnectableAccountProvider = /* @__PURE__ */ ((ConnectableAccountProvider2) => {
@@ -696,73 +800,78 @@ var ConnectableAccountProvider = /* @__PURE__ */ ((ConnectableAccountProvider2)
696
800
  })(ConnectableAccountProvider || {});
697
801
 
698
802
  // src/identity/schemas.ts
699
- var addressSchema = z8.object({
700
- countryCode: z8.string(),
701
- streetAddress1: z8.string(),
702
- streetAddress2: z8.string().nullable(),
703
- locality: z8.string().nullable(),
704
- region: z8.string().nullable(),
705
- postCode: z8.string().nullable()
706
- });
707
- var communicationPreferencesSchema = z8.object({
708
- newsletterOptIn: z8.boolean(),
803
+ var addressSchema = z9.object({
804
+ countryCode: z9.string(),
805
+ streetAddress1: z9.string(),
806
+ streetAddress2: z9.string().nullable(),
807
+ locality: z9.string().nullable(),
808
+ region: z9.string().nullable(),
809
+ postCode: z9.string().nullable()
810
+ });
811
+ var communicationPreferencesSchema = z9.object({
812
+ newsletterOptIn: z9.boolean(),
709
813
  // Default keeps older persisted identities (pre productUpdatesOptIn) parseable
710
814
  // during boot. The server-side value is hydrated by updateUser() right after.
711
- productUpdatesOptIn: z8.boolean().default(false)
815
+ productUpdatesOptIn: z9.boolean().default(false)
712
816
  });
713
- var ilokConnectedAccountSchema = z8.object({
714
- provider: z8.literal("iLok" /* iLok */),
715
- isConnected: z8.boolean(),
716
- pendingLicenseFulfillments: z8.boolean(),
717
- accountId: z8.string().nullish()
817
+ var ilokConnectedAccountSchema = z9.object({
818
+ provider: z9.literal("iLok" /* iLok */),
819
+ isConnected: z9.boolean(),
820
+ pendingLicenseFulfillments: z9.boolean(),
821
+ accountId: z9.string().nullish()
718
822
  });
719
- var connectedAccountSchema = z8.discriminatedUnion("provider", [
823
+ var connectedAccountSchema = z9.discriminatedUnion("provider", [
720
824
  ilokConnectedAccountSchema
721
825
  ]);
722
- var connectionUrlSchema = z8.object({
723
- url: z8.string()
826
+ var connectionUrlSchema = z9.object({
827
+ url: z9.string()
724
828
  });
725
- var userSchema = z8.object({
726
- id: z8.string(),
727
- email: z8.string(),
829
+ var userSchema = z9.object({
830
+ id: z9.string(),
831
+ email: z9.string(),
728
832
  // Nullable: customers created via import may have no name.
729
- name: z8.string().nullable(),
730
- tenantId: z8.string(),
833
+ name: z9.string().nullable(),
834
+ tenantId: z9.string(),
731
835
  address: addressSchema.optional(),
732
- phone: z8.string().optional(),
836
+ phone: z9.string().optional(),
733
837
  communicationPreferences: communicationPreferencesSchema,
734
- ownedProducts: z8.string().array().optional(),
735
- subscribedProducts: z8.string().array().optional(),
736
- confirmedAccount: z8.boolean().optional(),
737
- hasProducts: z8.boolean().nullish(),
738
- hasSubscriptions: z8.boolean().nullish(),
739
- connectedAccounts: z8.array(connectedAccountSchema).default([])
740
- });
741
- var identitySchema = userSchema.and(z8.object({
742
- accessToken: z8.string(),
743
- refreshToken: z8.string()
838
+ ownedProducts: z9.string().array().optional(),
839
+ subscribedProducts: z9.string().array().optional(),
840
+ confirmedAccount: z9.boolean().optional(),
841
+ hasProducts: z9.boolean().nullish(),
842
+ hasSubscriptions: z9.boolean().nullish(),
843
+ connectedAccounts: z9.array(connectedAccountSchema).default([])
844
+ });
845
+ var identitySchema = userSchema.and(z9.object({
846
+ accessToken: z9.string(),
847
+ refreshToken: z9.string()
744
848
  }));
745
- var userAccountConfirmedStatusSchema = z8.enum([
849
+ var userAccountConfirmedStatusSchema = z9.enum([
746
850
  "PasswordSetupRequired",
747
851
  "SignedIn"
748
852
  ]);
749
- var userAccountConfirmedSchema = userSchema.and(z8.object({
853
+ var userAccountConfirmedSchema = userSchema.and(z9.object({
750
854
  status: userAccountConfirmedStatusSchema,
751
- resetPasswordToken: z8.string().nullish(),
752
- accessToken: z8.string().nullish(),
753
- refreshToken: z8.string().nullish()
855
+ resetPasswordToken: z9.string().nullish(),
856
+ accessToken: z9.string().nullish(),
857
+ refreshToken: z9.string().nullish()
754
858
  }));
755
- var pendingActivationSchema = z8.object({
756
- status: z8.literal("activation_pending"),
757
- email: z8.string()
859
+ var pendingActivationSchema = z9.object({
860
+ status: z9.literal("activation_pending"),
861
+ email: z9.string()
862
+ });
863
+ var pendingPasswordProblemSchema = z9.object({
864
+ errorType: z9.literal("PasswordSetupRequired"),
865
+ pendingPasswordToken: z9.string()
758
866
  });
759
867
 
760
868
  // src/identity/endpoints.ts
761
869
  var IdentityEndpoints = class {
762
- constructor(api, tokenStore, logger) {
870
+ constructor(api, tokenStore, logger, pendingPasswords) {
763
871
  this.api = api;
764
872
  this.tokenStore = tokenStore;
765
873
  this.logger = logger;
874
+ this.pendingPasswords = pendingPasswords;
766
875
  }
767
876
  async get() {
768
877
  const response = await this.api.authenticatedFetch("/api/customer/meta/user", userSchema);
@@ -818,8 +927,11 @@ var IdentityEndpoints = class {
818
927
  groupIds: normalizeGroupIds(options == null ? void 0 : options.groupIds)
819
928
  })
820
929
  });
821
- if (response.status >= 400)
930
+ if (response.status >= 400) {
931
+ if (response.status === 409)
932
+ await this.keepPendingPassword(email, response.clone());
822
933
  await handleResponseProblem(response, this.logger);
934
+ }
823
935
  const data = await response.json();
824
936
  if (response.status === 202) {
825
937
  const parsed = pendingActivationSchema.parse(data);
@@ -835,6 +947,19 @@ var IdentityEndpoints = class {
835
947
  this.tokenStore.setUser(identity);
836
948
  return { status: "signed-in", user: userSchema.parse(identity) };
837
949
  }
950
+ /**
951
+ * The address already has an account with no password, so the server emailed it a link and
952
+ * handed back the password just typed, sealed, for that link to set once it is opened here.
953
+ * Never thrown: the caller still gets the `PasswordSetupRequiredError` from the response.
954
+ */
955
+ async keepPendingPassword(email, response) {
956
+ try {
957
+ const problem = pendingPasswordProblemSchema.safeParse(await response.json());
958
+ if (problem.success)
959
+ this.pendingPasswords.set(email, problem.data.pendingPasswordToken);
960
+ } catch (e) {
961
+ }
962
+ }
838
963
  /**
839
964
  * Signs the buyer out here at once, and ends the session on the server so its refresh
840
965
  * token stops working too. Resolves once the server has answered, and never rejects:
@@ -886,7 +1011,13 @@ var IdentityEndpoints = class {
886
1011
  await handleResponseProblem(response, this.logger);
887
1012
  }
888
1013
  async confirmAccount(email, code) {
889
- const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}&scheme=JWT`, userAccountConfirmedSchema, { method: "POST" });
1014
+ const pendingPasswordToken = this.pendingPasswords.get(email);
1015
+ const response = await this.api.fetch(`/api/customer/identity/confirm-account?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code.replaceAll(" ", "+"))}&scheme=JWT`, userAccountConfirmedSchema, {
1016
+ method: "POST",
1017
+ body: pendingPasswordToken ? { pendingPasswordToken } : void 0
1018
+ });
1019
+ if (pendingPasswordToken)
1020
+ this.pendingPasswords.remove(email);
890
1021
  const result = response.data;
891
1022
  if (result.status === "SignedIn") {
892
1023
  if (!result.accessToken || !result.refreshToken) {
@@ -927,16 +1058,17 @@ var IdentityEndpoints = class {
927
1058
  };
928
1059
 
929
1060
  // src/inventory/activation/endpoints.ts
930
- import { z as z10 } from "zod";
1061
+ import { z as z11 } from "zod";
931
1062
 
932
1063
  // src/inventory/licenses/schemas.ts
933
1064
  var schemas_exports6 = {};
934
1065
  __export(schemas_exports6, {
935
1066
  activationSchema: () => activationSchema,
936
1067
  externalLicenseContent: () => externalLicenseContent,
1068
+ licenseReleaseAccessSchema: () => licenseReleaseAccessSchema,
937
1069
  licenseSchema: () => licenseSchema
938
1070
  });
939
- import { z as z9 } from "zod";
1071
+ import { z as z10 } from "zod";
940
1072
 
941
1073
  // src/inventory/licenses/models.ts
942
1074
  var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
@@ -957,43 +1089,57 @@ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
957
1089
  })(ActivationMethod || {});
958
1090
 
959
1091
  // src/inventory/licenses/schemas.ts
960
- var externalLicenseFileContent = z9.object({
961
- type: z9.literal("file"),
962
- fileName: z9.string(),
963
- contentType: z9.string(),
964
- data: z9.string()
965
- });
966
- var externalLicenseILokContent = z9.object({
967
- type: z9.literal("iLok")
968
- });
969
- var externalLicenseContent = z9.union([
970
- z9.string(),
971
- z9.discriminatedUnion("type", [
1092
+ var externalLicenseFileContent = z10.object({
1093
+ type: z10.literal("file"),
1094
+ fileName: z10.string(),
1095
+ contentType: z10.string(),
1096
+ data: z10.string()
1097
+ });
1098
+ var externalLicenseILokContent = z10.object({
1099
+ type: z10.literal("iLok")
1100
+ });
1101
+ var externalLicenseContent = z10.union([
1102
+ z10.string(),
1103
+ z10.discriminatedUnion("type", [
972
1104
  externalLicenseFileContent,
973
1105
  externalLicenseILokContent
974
1106
  ])
975
1107
  ]);
976
- var licenseSchema = z9.object({
977
- id: z9.string(),
978
- status: z9.nativeEnum(LicenseStatus),
1108
+ var licenseReleaseAccessSchema = z10.object({
1109
+ // Releases published until then are covered, and every version while it has not passed.
1110
+ updatesUntil: z10.coerce.date().nullish().catch(void 0),
1111
+ // Every version whose major is at most this is covered.
1112
+ upToMajor: z10.number().nullish().catch(void 0),
1113
+ // Once updates have ended, the last version published before they did.
1114
+ upToVersion: z10.string().nullish().catch(void 0),
1115
+ // Whether the product's current release is covered, so whether to offer an upgrade. Read as
1116
+ // covered when unreadable, so a garbled answer never pushes an upgrade nobody needs.
1117
+ coversCurrentRelease: z10.boolean().catch(true),
1118
+ // Where to buy the upgrade or renewal for this license, while the product sells one.
1119
+ upgradeUrl: z10.string().nullish().catch(void 0)
1120
+ });
1121
+ var licenseSchema = z10.object({
1122
+ id: z10.string(),
1123
+ status: z10.nativeEnum(LicenseStatus),
979
1124
  product: productSummarySchema,
980
- activeNumberOfActivations: z9.number(),
981
- maxNumberOfActivations: z9.number(),
1125
+ activeNumberOfActivations: z10.number(),
1126
+ maxNumberOfActivations: z10.number(),
982
1127
  externalFulfillment: externalLicenseContent.optional(),
983
- requiredConnectedAccount: z9.nativeEnum(ConnectableAccountProvider).nullish(),
984
- fulfillmentMessage: z9.string().optional(),
985
- properties: z9.record(rawPropertyValueSchema).nullish(),
986
- expiresAt: z9.coerce.date().optional(),
987
- createdAt: z9.coerce.date()
1128
+ requiredConnectedAccount: z10.nativeEnum(ConnectableAccountProvider).nullish(),
1129
+ fulfillmentMessage: z10.string().optional(),
1130
+ properties: z10.record(rawPropertyValueSchema).nullish(),
1131
+ expiresAt: z10.coerce.date().optional(),
1132
+ createdAt: z10.coerce.date(),
1133
+ releaseAccess: licenseReleaseAccessSchema.nullish().catch(void 0)
988
1134
  });
989
- var activationSchema = z9.object({
990
- id: z9.string(),
991
- licenseId: z9.string(),
992
- name: z9.string(),
993
- status: z9.nativeEnum(ActivationStatus),
994
- activationMethod: z9.nativeEnum(ActivationMethod),
995
- firstValidatedAt: z9.coerce.date(),
996
- lastValidatedAt: z9.coerce.date().nullable()
1135
+ var activationSchema = z10.object({
1136
+ id: z10.string(),
1137
+ licenseId: z10.string(),
1138
+ name: z10.string(),
1139
+ status: z10.nativeEnum(ActivationStatus),
1140
+ activationMethod: z10.nativeEnum(ActivationMethod),
1141
+ firstValidatedAt: z10.coerce.date(),
1142
+ lastValidatedAt: z10.coerce.date().nullable()
997
1143
  });
998
1144
 
999
1145
  // src/inventory/activation/endpoints.ts
@@ -1010,7 +1156,7 @@ var ActivationEndpoints = class {
1010
1156
  });
1011
1157
  return {
1012
1158
  license: response.data,
1013
- url: z10.string().parse(response.headers.location)
1159
+ url: z11.string().parse(response.headers.location)
1014
1160
  };
1015
1161
  }
1016
1162
  };
@@ -1038,7 +1184,7 @@ var LicenseEndpoints = class {
1038
1184
  };
1039
1185
 
1040
1186
  // src/inventory/products/endpoints.ts
1041
- import { z as z11 } from "zod";
1187
+ import { z as z12 } from "zod";
1042
1188
  var ProductEndpoints = class {
1043
1189
  constructor(api, configuration) {
1044
1190
  this.api = api;
@@ -1072,18 +1218,18 @@ var ProductEndpoints = class {
1072
1218
  async getDownloadUrl(path) {
1073
1219
  const url = new URL(path);
1074
1220
  url.searchParams.append("redirect", "false");
1075
- const response = await this.api.fetch(url.pathname + url.search, z11.object({
1076
- location: z11.string()
1221
+ const response = await this.api.fetch(url.pathname + url.search, z12.object({
1222
+ location: z12.string()
1077
1223
  }));
1078
1224
  return response.data.location;
1079
1225
  }
1080
1226
  };
1081
1227
 
1082
1228
  // src/inventory/subscriptions/endpoints.ts
1083
- import { z as z14 } from "zod";
1229
+ import { z as z15 } from "zod";
1084
1230
 
1085
1231
  // package.json
1086
- var version = "3.8.0";
1232
+ var version = "3.10.0";
1087
1233
 
1088
1234
  // src/utils/client.ts
1089
1235
  function buildClientHeader(sdk) {
@@ -1091,6 +1237,11 @@ function buildClientHeader(sdk) {
1091
1237
  }
1092
1238
 
1093
1239
  // src/utils/api.ts
1240
+ function loggableBody(body) {
1241
+ if (!body || typeof body !== "object" || Array.isArray(body))
1242
+ return body;
1243
+ return Object.fromEntries(Object.entries(body).map(([key, value]) => [key, /password|token/i.test(key) && value != null ? "[redacted]" : value]));
1244
+ }
1094
1245
  function objectToQuery(obj) {
1095
1246
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
1096
1247
  }
@@ -1112,7 +1263,7 @@ var MoonbaseApi = class {
1112
1263
  const contentType = (_a = options == null ? void 0 : options.contentType) != null ? _a : "application/json";
1113
1264
  this.logger.debug("Making request to Moonbase API...", {
1114
1265
  path,
1115
- body: options == null ? void 0 : options.body
1266
+ body: loggableBody(options == null ? void 0 : options.body)
1116
1267
  });
1117
1268
  const startedAt = /* @__PURE__ */ new Date();
1118
1269
  const request = {
@@ -1125,7 +1276,8 @@ var MoonbaseApi = class {
1125
1276
  ...accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
1126
1277
  // Force CORS on all calls
1127
1278
  "x-mb-cors": "1",
1128
- "x-mb-client": this.clientHeader
1279
+ "x-mb-client": this.clientHeader,
1280
+ ...options == null ? void 0 : options.headers
1129
1281
  },
1130
1282
  body: (options == null ? void 0 : options.body) ? contentType !== "application/json" ? options.body : JSON.stringify(options.body) : void 0,
1131
1283
  signal: options == null ? void 0 : options.abort,
@@ -1235,7 +1387,7 @@ __export(schemas_exports8, {
1235
1387
  milestoneProgressSchema: () => milestoneProgressSchema,
1236
1388
  subscriptionSchema: () => subscriptionSchema
1237
1389
  });
1238
- import { z as z13 } from "zod";
1390
+ import { z as z14 } from "zod";
1239
1391
 
1240
1392
  // src/orders/schemas.ts
1241
1393
  var schemas_exports7 = {};
@@ -1249,7 +1401,7 @@ __export(schemas_exports7, {
1249
1401
  orderSchema: () => orderSchema,
1250
1402
  orderTotalSchema: () => orderTotalSchema
1251
1403
  });
1252
- import { z as z12 } from "zod";
1404
+ import { z as z13 } from "zod";
1253
1405
 
1254
1406
  // src/orders/models.ts
1255
1407
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
@@ -1262,18 +1414,18 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
1262
1414
  })(OrderStatus || {});
1263
1415
 
1264
1416
  // src/orders/schemas.ts
1265
- var couponSchema = z12.object({
1266
- code: z12.string(),
1267
- name: z12.string(),
1268
- description: z12.string()
1269
- });
1270
- var lineItemProductSchema = z12.object({
1271
- id: z12.string(),
1272
- name: z12.string(),
1273
- tagline: z12.string().nullish(),
1274
- iconUrl: z12.string().nullable()
1275
- });
1276
- var lineItemTotalSchema = z12.object({
1417
+ var couponSchema = z13.object({
1418
+ code: z13.string(),
1419
+ name: z13.string(),
1420
+ description: z13.string()
1421
+ });
1422
+ var lineItemProductSchema = z13.object({
1423
+ id: z13.string(),
1424
+ name: z13.string(),
1425
+ tagline: z13.string().nullish(),
1426
+ iconUrl: z13.string().nullable()
1427
+ });
1428
+ var lineItemTotalSchema = z13.object({
1277
1429
  original: moneySchema,
1278
1430
  discount: moneySchema,
1279
1431
  subtotal: moneySchema,
@@ -1282,52 +1434,59 @@ var lineItemTotalSchema = z12.object({
1282
1434
  // for this item. Both are part of `discount`. Absent on orders priced before cart offers existed.
1283
1435
  cartOfferDiscount: moneySchema.optional()
1284
1436
  });
1285
- var openProductLineItem = z12.object({
1286
- id: z12.string(),
1287
- type: z12.literal("Product"),
1288
- productId: z12.string(),
1289
- quantity: z12.number(),
1290
- variationId: z12.string(),
1291
- offerId: z12.string().optional(),
1292
- isDefaultVariation: z12.boolean().nullish(),
1293
- isSubcriptionPayment: z12.boolean().nullish(),
1437
+ var openProductLineItem = z13.object({
1438
+ id: z13.string(),
1439
+ type: z13.literal("Product"),
1440
+ productId: z13.string(),
1441
+ quantity: z13.number(),
1442
+ variationId: z13.string(),
1443
+ offerId: z13.string().optional(),
1444
+ isDefaultVariation: z13.boolean().nullish(),
1445
+ isSubcriptionPayment: z13.boolean().nullish(),
1294
1446
  price: priceCollectionSchema.optional(),
1295
1447
  variation: pricingVariationSchema.optional(),
1296
1448
  total: lineItemTotalSchema.nullish(),
1297
1449
  product: lineItemProductSchema.optional(),
1298
- appliedDiscount: discountSchema.optional()
1450
+ appliedDiscount: discountSchema.optional(),
1451
+ // The customer's license this line upgrades or renews, as the cart named it. Such a line is one
1452
+ // license, so its quantity is always 1, and the line's `id` names the license too
1453
+ // (`p/<productId>/<variationId>/<licenseId>`): upgrading two licenses takes two lines. A line
1454
+ // without one issues new licenses. Part of the cart payload like `offerId`, so a push that leaves
1455
+ // it out forgets it. Echoed on completed orders too. Absent from a backend that predates release
1456
+ // access.
1457
+ targetLicenseId: z13.string().nullish().catch(void 0)
1299
1458
  });
1300
- var lineItemBundleSchema = z12.object({
1301
- id: z12.string(),
1302
- name: z12.string(),
1303
- tagline: z12.string().nullish(),
1304
- iconUrl: z12.string().nullable(),
1305
- products: lineItemProductSchema.and(z12.object({
1306
- included: z12.boolean().optional()
1459
+ var lineItemBundleSchema = z13.object({
1460
+ id: z13.string(),
1461
+ name: z13.string(),
1462
+ tagline: z13.string().nullish(),
1463
+ iconUrl: z13.string().nullable(),
1464
+ products: lineItemProductSchema.and(z13.object({
1465
+ included: z13.boolean().optional()
1307
1466
  })).array()
1308
1467
  });
1309
- var openBundleLineItem = z12.object({
1310
- id: z12.string(),
1311
- type: z12.literal("Bundle"),
1312
- bundleId: z12.string(),
1313
- quantity: z12.number(),
1314
- variationId: z12.string(),
1315
- offerId: z12.string().optional(),
1316
- partial: z12.boolean().optional(),
1317
- replaced: z12.string().array().optional(),
1318
- isDefaultVariation: z12.boolean().nullish(),
1319
- isSubcriptionPayment: z12.boolean().nullish(),
1468
+ var openBundleLineItem = z13.object({
1469
+ id: z13.string(),
1470
+ type: z13.literal("Bundle"),
1471
+ bundleId: z13.string(),
1472
+ quantity: z13.number(),
1473
+ variationId: z13.string(),
1474
+ offerId: z13.string().optional(),
1475
+ partial: z13.boolean().optional(),
1476
+ replaced: z13.string().array().optional(),
1477
+ isDefaultVariation: z13.boolean().nullish(),
1478
+ isSubcriptionPayment: z13.boolean().nullish(),
1320
1479
  price: priceCollectionSchema.optional(),
1321
1480
  variation: pricingVariationSchema.optional(),
1322
1481
  total: lineItemTotalSchema.nullish(),
1323
1482
  bundle: lineItemBundleSchema.optional(),
1324
1483
  appliedDiscount: discountSchema.optional()
1325
1484
  });
1326
- var openOrderLineItem = z12.discriminatedUnion("type", [
1485
+ var openOrderLineItem = z13.discriminatedUnion("type", [
1327
1486
  openProductLineItem,
1328
1487
  openBundleLineItem
1329
1488
  ]);
1330
- var orderTotalSchema = z12.object({
1489
+ var orderTotalSchema = z13.object({
1331
1490
  original: moneySchema,
1332
1491
  discount: moneySchema,
1333
1492
  subtotal: moneySchema,
@@ -1337,52 +1496,52 @@ var orderTotalSchema = z12.object({
1337
1496
  // rather than a share on every line. Absent when no cart offer applied.
1338
1497
  cartOfferDiscount: moneySchema.optional()
1339
1498
  });
1340
- var openOrderSchema = z12.object({
1341
- id: z12.string(),
1342
- currency: z12.string(),
1499
+ var openOrderSchema = z13.object({
1500
+ id: z13.string(),
1501
+ currency: z13.string(),
1343
1502
  total: orderTotalSchema.nullish(),
1344
1503
  items: openOrderLineItem.array(),
1345
1504
  couponsApplied: couponSchema.array(),
1346
1505
  // The cart offer on the order as a whole: the buyer's intent. It is part of the cart payload, so
1347
1506
  // a content push that leaves it out clears it. The API echoes it back even while the cart sits
1348
1507
  // below the offer's threshold.
1349
- offerId: z12.string().optional(),
1508
+ offerId: z13.string().optional(),
1350
1509
  // The cart offer as actually applied: the result. Absent while the offer's condition doesn't hold.
1351
1510
  appliedOffer: discountSchema.optional(),
1352
- checkoutUrl: z12.string().optional(),
1353
- hostedCheckoutUrl: z12.string().optional(),
1354
- embeddedCheckoutUrl: z12.string().optional()
1355
- });
1356
- var customerSnapshotSchema = z12.object({
1357
- name: z12.string().nullable(),
1358
- businessName: z12.string().nullable(),
1359
- taxId: z12.string().nullable(),
1360
- email: z12.string().nullable(),
1361
- phone: z12.string().nullable(),
1511
+ checkoutUrl: z13.string().optional(),
1512
+ hostedCheckoutUrl: z13.string().optional(),
1513
+ embeddedCheckoutUrl: z13.string().optional()
1514
+ });
1515
+ var customerSnapshotSchema = z13.object({
1516
+ name: z13.string().nullable(),
1517
+ businessName: z13.string().nullable(),
1518
+ taxId: z13.string().nullable(),
1519
+ email: z13.string().nullable(),
1520
+ phone: z13.string().nullable(),
1362
1521
  address: addressSchema.nullable()
1363
1522
  });
1364
- var completedOrderSchema = z12.object({
1365
- id: z12.string(),
1366
- status: z12.literal("Completed" /* Completed */),
1367
- currency: z12.string(),
1523
+ var completedOrderSchema = z13.object({
1524
+ id: z13.string(),
1525
+ status: z13.literal("Completed" /* Completed */),
1526
+ currency: z13.string(),
1368
1527
  customer: customerSnapshotSchema,
1369
1528
  total: orderTotalSchema,
1370
1529
  items: openOrderLineItem.array(),
1371
1530
  couponsApplied: couponSchema.array(),
1372
1531
  appliedOffer: discountSchema.optional()
1373
1532
  });
1374
- var orderSchema = z12.discriminatedUnion("status", [
1533
+ var orderSchema = z13.discriminatedUnion("status", [
1375
1534
  openOrderSchema.extend({
1376
- status: z12.literal("Open" /* Open */)
1535
+ status: z13.literal("Open" /* Open */)
1377
1536
  }),
1378
1537
  openOrderSchema.extend({
1379
- status: z12.literal("PaymentProcessing" /* PaymentProcessing */)
1538
+ status: z13.literal("PaymentProcessing" /* PaymentProcessing */)
1380
1539
  }),
1381
1540
  openOrderSchema.extend({
1382
- status: z12.literal("Paid" /* Paid */)
1541
+ status: z13.literal("Paid" /* Paid */)
1383
1542
  }),
1384
1543
  openOrderSchema.extend({
1385
- status: z12.literal("Failed" /* Failed */)
1544
+ status: z13.literal("Failed" /* Failed */)
1386
1545
  }),
1387
1546
  completedOrderSchema
1388
1547
  ]);
@@ -1406,58 +1565,58 @@ var SubscriptionCancellationReason = /* @__PURE__ */ ((SubscriptionCancellationR
1406
1565
  })(SubscriptionCancellationReason || {});
1407
1566
 
1408
1567
  // src/inventory/subscriptions/schemas.ts
1409
- var baseMilestoneProgressEventSchema = z13.object({
1410
- milestoneId: z13.string(),
1411
- fulfilled: z13.boolean(),
1412
- afterCycleNumber: z13.number(),
1413
- afterNormalizedCycleNumber: z13.number(),
1414
- message: z13.string().optional()
1415
- });
1416
- var milestoneProgressEventSchema = z13.discriminatedUnion("type", [
1568
+ var baseMilestoneProgressEventSchema = z14.object({
1569
+ milestoneId: z14.string(),
1570
+ fulfilled: z14.boolean(),
1571
+ afterCycleNumber: z14.number(),
1572
+ afterNormalizedCycleNumber: z14.number(),
1573
+ message: z14.string().optional()
1574
+ });
1575
+ var milestoneProgressEventSchema = z14.discriminatedUnion("type", [
1417
1576
  baseMilestoneProgressEventSchema.extend({
1418
- type: z13.literal("CouponCodeMilestone"),
1419
- code: z13.string().optional(),
1420
- redeemed: z13.boolean().optional()
1577
+ type: z14.literal("CouponCodeMilestone"),
1578
+ code: z14.string().optional(),
1579
+ redeemed: z14.boolean().optional()
1421
1580
  }),
1422
1581
  baseMilestoneProgressEventSchema.extend({
1423
- type: z13.literal("PerpetualLicenseConversionMilestone")
1582
+ type: z14.literal("PerpetualLicenseConversionMilestone")
1424
1583
  })
1425
1584
  ]);
1426
- var milestoneProgressSchema = z13.object({
1427
- title: z13.string(),
1428
- description: z13.string().nullish(),
1429
- currentCycleNumber: z13.number(),
1430
- currentNormalizedCycleNumber: z13.number(),
1431
- currentCycleIsCompleted: z13.boolean(),
1432
- fromCycleNumber: z13.number(),
1433
- fromNormalizedCycleNumber: z13.number(),
1434
- toCycleNumber: z13.number(),
1435
- toNormalizedCycleNumber: z13.number(),
1436
- events: z13.record(z13.coerce.number(), milestoneProgressEventSchema.array())
1437
- });
1438
- var subscriptionSchema = z13.object({
1439
- id: z13.string(),
1440
- status: z13.nativeEnum(SubscriptionStatus),
1441
- hasPaymentMethod: z13.boolean(),
1442
- cancellable: z13.boolean(),
1443
- expiresAt: z13.coerce.date(),
1444
- renewedAt: z13.coerce.date().nullable(),
1445
- nextPaymentScheduledAt: z13.coerce.date().nullable(),
1446
- startedAt: z13.coerce.date(),
1585
+ var milestoneProgressSchema = z14.object({
1586
+ title: z14.string(),
1587
+ description: z14.string().nullish(),
1588
+ currentCycleNumber: z14.number(),
1589
+ currentNormalizedCycleNumber: z14.number(),
1590
+ currentCycleIsCompleted: z14.boolean(),
1591
+ fromCycleNumber: z14.number(),
1592
+ fromNormalizedCycleNumber: z14.number(),
1593
+ toCycleNumber: z14.number(),
1594
+ toNormalizedCycleNumber: z14.number(),
1595
+ events: z14.record(z14.coerce.number(), milestoneProgressEventSchema.array())
1596
+ });
1597
+ var subscriptionSchema = z14.object({
1598
+ id: z14.string(),
1599
+ status: z14.nativeEnum(SubscriptionStatus),
1600
+ hasPaymentMethod: z14.boolean(),
1601
+ cancellable: z14.boolean(),
1602
+ expiresAt: z14.coerce.date(),
1603
+ renewedAt: z14.coerce.date().nullable(),
1604
+ nextPaymentScheduledAt: z14.coerce.date().nullable(),
1605
+ startedAt: z14.coerce.date(),
1447
1606
  total: orderTotalSchema,
1448
- cycleLength: z13.nativeEnum(CycleLength),
1449
- paymentMethod: z13.string().optional(),
1607
+ cycleLength: z14.nativeEnum(CycleLength),
1608
+ paymentMethod: z14.string().optional(),
1450
1609
  milestoneProgress: milestoneProgressSchema.nullish(),
1451
- embeddedUpdatePaymentUrl: z13.string().optional(),
1452
- content: z13.discriminatedUnion("type", [
1453
- z13.object({
1454
- type: z13.literal("Product"),
1455
- quantity: z13.number(),
1610
+ embeddedUpdatePaymentUrl: z14.string().optional(),
1611
+ content: z14.discriminatedUnion("type", [
1612
+ z14.object({
1613
+ type: z14.literal("Product"),
1614
+ quantity: z14.number(),
1456
1615
  product: storefrontProductSchema
1457
1616
  }),
1458
- z13.object({
1459
- type: z13.literal("Bundle"),
1460
- quantity: z13.number(),
1617
+ z14.object({
1618
+ type: z14.literal("Bundle"),
1619
+ quantity: z14.number(),
1461
1620
  bundle: storefrontBundleSchema
1462
1621
  })
1463
1622
  ])
@@ -1493,8 +1652,8 @@ var SubscriptionEndpoints = class {
1493
1652
  return response.data;
1494
1653
  }
1495
1654
  async renew(subscriptionId, returnUrl, embedded) {
1496
- const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/renew?redirect=false&return=${returnUrl}&embedded=${embedded ? "true" : "false"}`, z14.object({
1497
- location: z14.string()
1655
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/subscriptions/${subscriptionId}/renew?redirect=false&return=${returnUrl}&embedded=${embedded ? "true" : "false"}`, z15.object({
1656
+ location: z15.string()
1498
1657
  }), { method: "POST" });
1499
1658
  return response.data;
1500
1659
  }
@@ -1761,6 +1920,50 @@ var InMemoryStore = class {
1761
1920
  }
1762
1921
  };
1763
1922
 
1923
+ // src/utils/pendingPasswords.ts
1924
+ var lifetime = 24 * 60 * 60 * 1e3;
1925
+ function normalizeEmail(email) {
1926
+ return email.trim().toLowerCase();
1927
+ }
1928
+ var _PendingPasswordStore = class _PendingPasswordStore {
1929
+ constructor(store) {
1930
+ this.store = store != null ? store : isLocalStorageAvailable() ? new LocalStorageStore() : new InMemoryStore();
1931
+ }
1932
+ get(email) {
1933
+ var _a, _b;
1934
+ return (_b = (_a = this.read()[normalizeEmail(email)]) == null ? void 0 : _a.token) != null ? _b : null;
1935
+ }
1936
+ set(email, token) {
1937
+ this.write({ ...this.read(), [normalizeEmail(email)]: { token, storedAt: Date.now() } });
1938
+ }
1939
+ remove(email) {
1940
+ const entries = this.read();
1941
+ delete entries[normalizeEmail(email)];
1942
+ this.write(entries);
1943
+ }
1944
+ /** The entries still worth keeping. Drops the rest from storage as it goes. */
1945
+ read() {
1946
+ const stored = this.store.get(_PendingPasswordStore.storageKey);
1947
+ if (!stored || typeof stored !== "object")
1948
+ return {};
1949
+ const now = Date.now();
1950
+ const fresh = Object.fromEntries(Object.entries(stored).filter(
1951
+ ([, entry]) => typeof (entry == null ? void 0 : entry.token) === "string" && typeof entry.storedAt === "number" && now - entry.storedAt < lifetime
1952
+ ));
1953
+ if (Object.keys(fresh).length !== Object.keys(stored).length)
1954
+ this.write(fresh);
1955
+ return fresh;
1956
+ }
1957
+ write(entries) {
1958
+ if (Object.keys(entries).length > 0)
1959
+ this.store.set(_PendingPasswordStore.storageKey, entries);
1960
+ else
1961
+ this.store.remove(_PendingPasswordStore.storageKey);
1962
+ }
1963
+ };
1964
+ _PendingPasswordStore.storageKey = "moonbase_pending_passwords";
1965
+ var PendingPasswordStore = _PendingPasswordStore;
1966
+
1764
1967
  // src/utils/tokenStore.ts
1765
1968
  var defaultAccessTokenLifetime = 15 * 60 * 1e3;
1766
1969
  var renewBeforeExpiry = 5 * 60 * 1e3;
@@ -1770,9 +1973,9 @@ function accessTokenLifetime(accessToken) {
1770
1973
  try {
1771
1974
  const payload = accessToken.split(".")[1].replaceAll("-", "+").replaceAll("_", "/");
1772
1975
  const claims = JSON.parse(atob(payload.padEnd(Math.ceil(payload.length / 4) * 4, "=")));
1773
- const lifetime = (Number(claims.exp) - Number(claims.iat)) * 1e3;
1774
- if (Number.isFinite(lifetime) && lifetime > 0 && lifetime <= 24 * 60 * 60 * 1e3)
1775
- return lifetime;
1976
+ const lifetime2 = (Number(claims.exp) - Number(claims.iat)) * 1e3;
1977
+ if (Number.isFinite(lifetime2) && lifetime2 > 0 && lifetime2 <= 24 * 60 * 60 * 1e3)
1978
+ return lifetime2;
1776
1979
  } catch (e) {
1777
1980
  }
1778
1981
  return defaultAccessTokenLifetime;
@@ -2019,21 +2222,21 @@ __export(schemas_exports9, {
2019
2222
  vendorFeaturesSchema: () => vendorFeaturesSchema,
2020
2223
  vendorSchema: () => vendorSchema
2021
2224
  });
2022
- import { z as z15 } from "zod";
2023
- var vendorCaptchaSchema = z15.object({
2024
- url: z15.string()
2225
+ import { z as z16 } from "zod";
2226
+ var vendorCaptchaSchema = z16.object({
2227
+ url: z16.string()
2025
2228
  });
2026
- var vendorFeaturesSchema = z15.object({
2027
- customerPortal: z15.boolean().optional(),
2028
- phoneNumber: z15.boolean().optional(),
2029
- marketingConsent: z15.nativeEnum(MarketingConsentType).optional().catch(void 0),
2229
+ var vendorFeaturesSchema = z16.object({
2230
+ customerPortal: z16.boolean().optional(),
2231
+ phoneNumber: z16.boolean().optional(),
2232
+ marketingConsent: z16.nativeEnum(MarketingConsentType).optional().catch(void 0),
2030
2233
  // Absent on backends from before captchas, which never ask for one.
2031
2234
  captcha: vendorCaptchaSchema.nullish()
2032
2235
  });
2033
- var vendorSchema = z15.object({
2034
- id: z15.string(),
2035
- name: z15.string(),
2036
- logoUrl: z15.string().nullable(),
2236
+ var vendorSchema = z16.object({
2237
+ id: z16.string(),
2238
+ name: z16.string(),
2239
+ logoUrl: z16.string().nullable(),
2037
2240
  features: vendorFeaturesSchema.optional()
2038
2241
  });
2039
2242
 
@@ -2053,16 +2256,16 @@ var schemas_exports10 = {};
2053
2256
  __export(schemas_exports10, {
2054
2257
  voucherSchema: () => voucherSchema
2055
2258
  });
2056
- import { z as z16 } from "zod";
2057
- var voucherSchema = z16.object({
2058
- id: z16.string(),
2059
- name: z16.string(),
2060
- description: z16.string(),
2061
- code: z16.string(),
2062
- redeemed: z16.boolean(),
2259
+ import { z as z17 } from "zod";
2260
+ var voucherSchema = z17.object({
2261
+ id: z17.string(),
2262
+ name: z17.string(),
2263
+ description: z17.string(),
2264
+ code: z17.string(),
2265
+ redeemed: z17.boolean(),
2063
2266
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
2064
2267
  redeemsBundles: quantifiable(storefrontBundleSchema).array(),
2065
- properties: z16.record(rawPropertyValueSchema).nullish()
2268
+ properties: z17.record(rawPropertyValueSchema).nullish()
2066
2269
  });
2067
2270
 
2068
2271
  // src/vouchers/endpoints.ts
@@ -2263,11 +2466,48 @@ var OfferUtils = class _OfferUtils {
2263
2466
  // src/utils/cart.ts
2264
2467
  var _CartUtils = class _CartUtils {
2265
2468
  // The pricing variation a line item points at, falling back to the item's default variation when
2266
- // the variation id doesn't resolve, which is what the cart has always displayed.
2469
+ // the variation id doesn't resolve, which is what the cart has always displayed. A line upgrading
2470
+ // one of the customer's licenses is priced for that license, as the API prices it.
2267
2471
  static resolveVariation(catalog, item) {
2268
- var _a, _b;
2269
- const source = item.type === "Product" ? catalog.products.find((p) => p.id === item.productId) : catalog.bundles.find((b) => b.id === item.bundleId);
2270
- 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;
2472
+ var _a, _b, _c;
2473
+ if (item.type === "Product") {
2474
+ const product = catalog.products.find((p) => p.id === item.productId);
2475
+ return (_a = _CartUtils.productLineVariation(product, item.variationId, item.targetLicenseId)) != null ? _a : product == null ? void 0 : product.defaultVariation;
2476
+ }
2477
+ const bundle = catalog.bundles.find((b) => b.id === item.bundleId);
2478
+ 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;
2479
+ }
2480
+ /**
2481
+ * The storefront's entry for upgrading or renewing one of the signed-in customer's licenses of a
2482
+ * product: what it covers now, and the variations that would upgrade it, priced for it. Licenses
2483
+ * that cover the same share an entry. `undefined` when the storefront has none for it (the license
2484
+ * is not theirs, covers every release, is past the cap on entries, or the customer is not signed in).
2485
+ */
2486
+ static licenseUpgrade(product, licenseId) {
2487
+ var _a;
2488
+ if (!product || !licenseId)
2489
+ return void 0;
2490
+ const wanted = licenseId.toLowerCase();
2491
+ return (_a = product.licenseUpgrades) == null ? void 0 : _a.find((u) => u.licenseIds.some((id) => id.toLowerCase() === wanted));
2492
+ }
2493
+ /**
2494
+ * The variations that would upgrade or renew one of the signed-in customer's licenses of a
2495
+ * product, priced for that license, or `undefined` when the storefront has no price for it.
2496
+ */
2497
+ static licenseUpgradeVariations(product, licenseId) {
2498
+ var _a;
2499
+ return (_a = _CartUtils.licenseUpgrade(product, licenseId)) == null ? void 0 : _a.variations;
2500
+ }
2501
+ /**
2502
+ * The variation a product line is priced at. A line naming one of the customer's licenses
2503
+ * (`targetLicenseId`) upgrades that license, and an upgrade discount is judged per license, so its
2504
+ * price comes from the product's `licenseUpgrades` for that license. Every other line, and an
2505
+ * upgrade line the storefront has no price for, takes the product's own variation, which is what
2506
+ * a new license costs.
2507
+ */
2508
+ static productLineVariation(product, variationId, targetLicenseId) {
2509
+ var _a, _b, _c;
2510
+ 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);
2271
2511
  }
2272
2512
  // A line's unit price after its product discount and any pricing tier, and *before* any offer.
2273
2513
  // This is the basis the API measures cart total conditions on, which is why it reads the catalog
@@ -2714,7 +2954,7 @@ var MoonbaseClient = class {
2714
2954
  this.tokenStore = new TokenStore(configuration);
2715
2955
  this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore, this.logger, this.configuration.sdk);
2716
2956
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
2717
- this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger);
2957
+ this.identity = new IdentityEndpoints(this.api, this.tokenStore, this.logger, new PendingPasswordStore(configuration.store));
2718
2958
  this.communications = new CommunicationsEndpoints(this.api);
2719
2959
  this.groups = new GroupEndpoints(this.api);
2720
2960
  this.vouchers = new VoucherEndpoints(this.api);
@@ -2751,7 +2991,9 @@ export {
2751
2991
  NotFoundError,
2752
2992
  OfferUtils,
2753
2993
  OrderStatus,
2994
+ PasswordSetupRequiredError,
2754
2995
  Platform,
2996
+ ReleaseNotCoveredError,
2755
2997
  StoreClosedError,
2756
2998
  SubscriptionCancellationReason,
2757
2999
  SubscriptionStatus,