@moonbase.sh/storefront-api 0.3.18 → 0.3.20

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
@@ -95,14 +95,16 @@ var percentageOffDiscountSchema = import_zod.z.object({
95
95
  description: import_zod.z.string().optional(),
96
96
  percentage: import_zod.z.number(),
97
97
  total: priceCollectionSchema.optional(),
98
- isExclusive: import_zod.z.boolean()
98
+ isExclusive: import_zod.z.boolean(),
99
+ recurringPaymentUseCount: import_zod.z.number().optional()
99
100
  });
100
101
  var flatAmountOffDiscountSchema = import_zod.z.object({
101
102
  type: import_zod.z.literal("FlatAmountOffDiscount"),
102
103
  name: import_zod.z.string(),
103
104
  description: import_zod.z.string().optional(),
104
105
  total: priceCollectionSchema.optional(),
105
- isExclusive: import_zod.z.boolean()
106
+ isExclusive: import_zod.z.boolean(),
107
+ recurringPaymentUseCount: import_zod.z.number().optional()
106
108
  });
107
109
  var moneySchema = import_zod.z.object({
108
110
  currency: import_zod.z.string(),
@@ -379,7 +381,7 @@ var schemas_exports = {};
379
381
  __export(schemas_exports, {
380
382
  addressSchema: () => addressSchema,
381
383
  communicationPreferencesSchema: () => communicationPreferencesSchema,
382
- identityUserSchema: () => identityUserSchema,
384
+ identitySchema: () => identitySchema,
383
385
  userAccountConfirmedSchema: () => userAccountConfirmedSchema,
384
386
  userSchema: () => userSchema
385
387
  });
@@ -408,7 +410,7 @@ var userSchema = import_zod7.z.object({
408
410
  hasProducts: import_zod7.z.boolean().nullish(),
409
411
  hasSubscriptions: import_zod7.z.boolean().nullish()
410
412
  });
411
- var identityUserSchema = userSchema.and(import_zod7.z.object({
413
+ var identitySchema = userSchema.and(import_zod7.z.object({
412
414
  accessToken: import_zod7.z.string(),
413
415
  refreshToken: import_zod7.z.string()
414
416
  }));
@@ -445,7 +447,7 @@ var IdentityEndpoints = class {
445
447
  await handleResponseProblem(response);
446
448
  try {
447
449
  const data = await response.json();
448
- const user = identityUserSchema.parse(data);
450
+ const user = identitySchema.parse(data);
449
451
  this.tokenStore.setUser(user);
450
452
  return userSchema.parse(user);
451
453
  } catch (err) {
@@ -454,7 +456,7 @@ var IdentityEndpoints = class {
454
456
  }
455
457
  }
456
458
  async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
457
- const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identityUserSchema, {
459
+ const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identitySchema, {
458
460
  method: "POST",
459
461
  body: {
460
462
  name,
@@ -900,7 +902,7 @@ var MoonbaseApi = class {
900
902
  this.tokenStore = tokenStore;
901
903
  }
902
904
  async authenticatedFetch(path, schema, options) {
903
- if (!this.tokenStore.hasAccessToken)
905
+ if (!this.tokenStore.user)
904
906
  throw new NotAuthenticatedError();
905
907
  return await this.fetch(path, schema, options);
906
908
  }
@@ -955,7 +957,7 @@ var MoonbaseApi = class {
955
957
  }
956
958
  async reportParsingProblem(path, err, body) {
957
959
  try {
958
- await (0, import_cross_fetch2.default)(this.baseUrl + "/api/customer/insights/error", {
960
+ await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/error`, {
959
961
  mode: "cors",
960
962
  method: "POST",
961
963
  headers: {
@@ -977,7 +979,7 @@ var MoonbaseApi = class {
977
979
  }
978
980
  async reportRequestProblem(path, request, response, err) {
979
981
  try {
980
- await (0, import_cross_fetch2.default)(this.baseUrl + "/api/customer/insights/warn", {
982
+ await (0, import_cross_fetch2.default)(`${this.baseUrl}/api/customer/insights/warn`, {
981
983
  mode: "cors",
982
984
  method: "POST",
983
985
  headers: {
@@ -1025,9 +1027,6 @@ var _TokenStore = class _TokenStore {
1025
1027
  return this.tokens;
1026
1028
  return null;
1027
1029
  }
1028
- get hasAccessToken() {
1029
- return !!this.tokens;
1030
- }
1031
1030
  async getAccessToken() {
1032
1031
  var _a, _b, _c;
1033
1032
  if (this.isExpired) {
@@ -1086,7 +1085,7 @@ var _TokenStore = class _TokenStore {
1086
1085
  }
1087
1086
  throw new MoonbaseError("Unexpected result", `Could not refresh access token, status code ${response.status}`, response.status);
1088
1087
  }
1089
- const result = identityUserSchema.parse(await response.json());
1088
+ const result = identitySchema.parse(await response.json());
1090
1089
  return this.setUser(result);
1091
1090
  }
1092
1091
  handleStorageUpdate(event) {
@@ -1167,9 +1166,10 @@ __export(schemas_exports3, {
1167
1166
  // src/index.ts
1168
1167
  var MoonbaseClient = class {
1169
1168
  constructor(configuration) {
1169
+ var _a;
1170
1170
  this.configuration = configuration;
1171
1171
  this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
1172
- this.tokenStore = new TokenStore(configuration);
1172
+ this.tokenStore = (_a = configuration.tokenStore) != null ? _a : new TokenStore(configuration);
1173
1173
  this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore);
1174
1174
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
1175
1175
  this.identity = new IdentityEndpoints(this.api, this.tokenStore);