@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.js CHANGED
@@ -47,14 +47,16 @@ var percentageOffDiscountSchema = z.object({
47
47
  description: z.string().optional(),
48
48
  percentage: z.number(),
49
49
  total: priceCollectionSchema.optional(),
50
- isExclusive: z.boolean()
50
+ isExclusive: z.boolean(),
51
+ recurringPaymentUseCount: z.number().optional()
51
52
  });
52
53
  var flatAmountOffDiscountSchema = z.object({
53
54
  type: z.literal("FlatAmountOffDiscount"),
54
55
  name: z.string(),
55
56
  description: z.string().optional(),
56
57
  total: priceCollectionSchema.optional(),
57
- isExclusive: z.boolean()
58
+ isExclusive: z.boolean(),
59
+ recurringPaymentUseCount: z.number().optional()
58
60
  });
59
61
  var moneySchema = z.object({
60
62
  currency: z.string(),
@@ -331,7 +333,7 @@ var schemas_exports = {};
331
333
  __export(schemas_exports, {
332
334
  addressSchema: () => addressSchema,
333
335
  communicationPreferencesSchema: () => communicationPreferencesSchema,
334
- identityUserSchema: () => identityUserSchema,
336
+ identitySchema: () => identitySchema,
335
337
  userAccountConfirmedSchema: () => userAccountConfirmedSchema,
336
338
  userSchema: () => userSchema
337
339
  });
@@ -360,7 +362,7 @@ var userSchema = z7.object({
360
362
  hasProducts: z7.boolean().nullish(),
361
363
  hasSubscriptions: z7.boolean().nullish()
362
364
  });
363
- var identityUserSchema = userSchema.and(z7.object({
365
+ var identitySchema = userSchema.and(z7.object({
364
366
  accessToken: z7.string(),
365
367
  refreshToken: z7.string()
366
368
  }));
@@ -397,7 +399,7 @@ var IdentityEndpoints = class {
397
399
  await handleResponseProblem(response);
398
400
  try {
399
401
  const data = await response.json();
400
- const user = identityUserSchema.parse(data);
402
+ const user = identitySchema.parse(data);
401
403
  this.tokenStore.setUser(user);
402
404
  return userSchema.parse(user);
403
405
  } catch (err) {
@@ -406,7 +408,7 @@ var IdentityEndpoints = class {
406
408
  }
407
409
  }
408
410
  async signUp(name, email, password, address, acceptedPrivacyPolicy, acceptedTermsAndConditions, communicationOptIn) {
409
- const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identityUserSchema, {
411
+ const response = await this.api.fetch(`/api/customer/identity/sign-up?scheme=JWT&communicationOptIn=${communicationOptIn ? "true" : "false"}`, identitySchema, {
410
412
  method: "POST",
411
413
  body: {
412
414
  name,
@@ -852,7 +854,7 @@ var MoonbaseApi = class {
852
854
  this.tokenStore = tokenStore;
853
855
  }
854
856
  async authenticatedFetch(path, schema, options) {
855
- if (!this.tokenStore.hasAccessToken)
857
+ if (!this.tokenStore.user)
856
858
  throw new NotAuthenticatedError();
857
859
  return await this.fetch(path, schema, options);
858
860
  }
@@ -907,7 +909,7 @@ var MoonbaseApi = class {
907
909
  }
908
910
  async reportParsingProblem(path, err, body) {
909
911
  try {
910
- await fetch2(this.baseUrl + "/api/customer/insights/error", {
912
+ await fetch2(`${this.baseUrl}/api/customer/insights/error`, {
911
913
  mode: "cors",
912
914
  method: "POST",
913
915
  headers: {
@@ -929,7 +931,7 @@ var MoonbaseApi = class {
929
931
  }
930
932
  async reportRequestProblem(path, request, response, err) {
931
933
  try {
932
- await fetch2(this.baseUrl + "/api/customer/insights/warn", {
934
+ await fetch2(`${this.baseUrl}/api/customer/insights/warn`, {
933
935
  mode: "cors",
934
936
  method: "POST",
935
937
  headers: {
@@ -977,9 +979,6 @@ var _TokenStore = class _TokenStore {
977
979
  return this.tokens;
978
980
  return null;
979
981
  }
980
- get hasAccessToken() {
981
- return !!this.tokens;
982
- }
983
982
  async getAccessToken() {
984
983
  var _a, _b, _c;
985
984
  if (this.isExpired) {
@@ -1038,7 +1037,7 @@ var _TokenStore = class _TokenStore {
1038
1037
  }
1039
1038
  throw new MoonbaseError("Unexpected result", `Could not refresh access token, status code ${response.status}`, response.status);
1040
1039
  }
1041
- const result = identityUserSchema.parse(await response.json());
1040
+ const result = identitySchema.parse(await response.json());
1042
1041
  return this.setUser(result);
1043
1042
  }
1044
1043
  handleStorageUpdate(event) {
@@ -1119,9 +1118,10 @@ __export(schemas_exports3, {
1119
1118
  // src/index.ts
1120
1119
  var MoonbaseClient = class {
1121
1120
  constructor(configuration) {
1121
+ var _a;
1122
1122
  this.configuration = configuration;
1123
1123
  this.configuration.endpoint = this.configuration.endpoint.replace(/\/$/, "");
1124
- this.tokenStore = new TokenStore(configuration);
1124
+ this.tokenStore = (_a = configuration.tokenStore) != null ? _a : new TokenStore(configuration);
1125
1125
  this.api = new MoonbaseApi(this.configuration.endpoint, this.tokenStore);
1126
1126
  this.storefront = new StorefrontEndpoints(this.api, this.configuration);
1127
1127
  this.identity = new IdentityEndpoints(this.api, this.tokenStore);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "0.3.18",
4
+ "version": "0.3.20",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",