@moonbase.sh/storefront-api 2.3.0 → 2.3.1

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
@@ -515,11 +515,11 @@ async function handleResponseProblem(response, logger) {
515
515
  throw new NotAuthorizedError();
516
516
  }
517
517
  let problemDetails;
518
+ const body = await response.text();
518
519
  try {
519
- const json = await response.json();
520
- problemDetails = problemDetailsSchema.parse(json);
520
+ problemDetails = problemDetailsSchema.parse(JSON.parse(body));
521
521
  } catch (err) {
522
- logger.warn("Could not handle response", { response, err, content: await response.text() });
522
+ logger.warn("Could not handle response", { response, err, content: body });
523
523
  throw new Error("An unknown problem occurred");
524
524
  }
525
525
  logger.debug("The response indicates a problem", problemDetails);
@@ -583,7 +583,8 @@ var connectionUrlSchema = import_zod8.z.object({
583
583
  var userSchema = import_zod8.z.object({
584
584
  id: import_zod8.z.string(),
585
585
  email: import_zod8.z.string(),
586
- name: import_zod8.z.string(),
586
+ // Nullable: customers created via import may have no name.
587
+ name: import_zod8.z.string().nullable(),
587
588
  tenantId: import_zod8.z.string(),
588
589
  address: addressSchema.optional(),
589
590
  phone: import_zod8.z.string().optional(),
@@ -912,6 +913,9 @@ var ProductEndpoints = class {
912
913
  }
913
914
  };
914
915
 
916
+ // src/inventory/subscriptions/endpoints.ts
917
+ var import_zod14 = require("zod");
918
+
915
919
  // src/utils/api.ts
916
920
  function objectToQuery(obj) {
917
921
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
@@ -1037,9 +1041,6 @@ var MoonbaseApi = class {
1037
1041
  }
1038
1042
  };
1039
1043
 
1040
- // src/inventory/subscriptions/endpoints.ts
1041
- var import_zod14 = require("zod");
1042
-
1043
1044
  // src/inventory/subscriptions/schemas.ts
1044
1045
  var schemas_exports8 = {};
1045
1046
  __export(schemas_exports8, {
@@ -1048,15 +1049,6 @@ __export(schemas_exports8, {
1048
1049
  });
1049
1050
  var import_zod13 = require("zod");
1050
1051
 
1051
- // src/inventory/subscriptions/models.ts
1052
- var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
1053
- SubscriptionStatus2["Active"] = "Active";
1054
- SubscriptionStatus2["Expired"] = "Expired";
1055
- SubscriptionStatus2["Cancelled"] = "Cancelled";
1056
- SubscriptionStatus2["Completed"] = "Completed";
1057
- return SubscriptionStatus2;
1058
- })(SubscriptionStatus || {});
1059
-
1060
1052
  // src/orders/schemas.ts
1061
1053
  var schemas_exports7 = {};
1062
1054
  __export(schemas_exports7, {
@@ -1193,6 +1185,15 @@ var orderSchema = import_zod12.z.discriminatedUnion("status", [
1193
1185
  completedOrderSchema
1194
1186
  ]);
1195
1187
 
1188
+ // src/inventory/subscriptions/models.ts
1189
+ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
1190
+ SubscriptionStatus2["Active"] = "Active";
1191
+ SubscriptionStatus2["Expired"] = "Expired";
1192
+ SubscriptionStatus2["Cancelled"] = "Cancelled";
1193
+ SubscriptionStatus2["Completed"] = "Completed";
1194
+ return SubscriptionStatus2;
1195
+ })(SubscriptionStatus || {});
1196
+
1196
1197
  // src/inventory/subscriptions/schemas.ts
1197
1198
  var baseMilestoneProgressEventSchema = import_zod13.z.object({
1198
1199
  milestoneId: import_zod13.z.string(),
@@ -1368,6 +1369,36 @@ var StorefrontEndpoints = class {
1368
1369
  }
1369
1370
  };
1370
1371
 
1372
+ // src/utils/logger.ts
1373
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1374
+ LogLevel2[LogLevel2["Debug"] = 0] = "Debug";
1375
+ LogLevel2[LogLevel2["Information"] = 1] = "Information";
1376
+ LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
1377
+ LogLevel2[LogLevel2["Error"] = 3] = "Error";
1378
+ return LogLevel2;
1379
+ })(LogLevel || {});
1380
+ var ConsoleLogger = class {
1381
+ constructor(level = 2 /* Warn */) {
1382
+ this.level = level;
1383
+ }
1384
+ debug(message, ...optionalParams) {
1385
+ if (this.level <= 0 /* Debug */)
1386
+ console.debug(message, ...optionalParams);
1387
+ }
1388
+ log(message, ...optionalParams) {
1389
+ if (this.level <= 1 /* Information */)
1390
+ console.log(message, ...optionalParams);
1391
+ }
1392
+ warn(message, ...optionalParams) {
1393
+ if (this.level <= 2 /* Warn */)
1394
+ console.warn(message, ...optionalParams);
1395
+ }
1396
+ error(message, ...optionalParams) {
1397
+ if (this.level <= 3 /* Error */)
1398
+ console.error(message, ...optionalParams);
1399
+ }
1400
+ };
1401
+
1371
1402
  // src/utils/store.ts
1372
1403
  var LocalStorageStore = class {
1373
1404
  get(key) {
@@ -1415,7 +1446,8 @@ var InMemoryStore = class {
1415
1446
  }
1416
1447
  }
1417
1448
  listen(key, callback) {
1418
- if (!this.listeners[key]) this.listeners[key] = [];
1449
+ if (!this.listeners[key])
1450
+ this.listeners[key] = [];
1419
1451
  this.listeners[key].push(callback);
1420
1452
  }
1421
1453
  };
@@ -1459,7 +1491,8 @@ var _TokenStore = class _TokenStore {
1459
1491
  setUser(user) {
1460
1492
  const identity = user;
1461
1493
  if (!identity.accessToken || !identity.refreshToken) {
1462
- if (!this.tokens) return null;
1494
+ if (!this.tokens)
1495
+ return null;
1463
1496
  this.tokens = {
1464
1497
  ...user,
1465
1498
  accessToken: this.tokens.accessToken,
@@ -1589,32 +1622,6 @@ var VoucherEndpoints = class {
1589
1622
  }
1590
1623
  };
1591
1624
 
1592
- // src/utils/logger.ts
1593
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1594
- LogLevel2[LogLevel2["Debug"] = 0] = "Debug";
1595
- LogLevel2[LogLevel2["Information"] = 1] = "Information";
1596
- LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
1597
- LogLevel2[LogLevel2["Error"] = 3] = "Error";
1598
- return LogLevel2;
1599
- })(LogLevel || {});
1600
- var ConsoleLogger = class {
1601
- constructor(level = 2 /* Warn */) {
1602
- this.level = level;
1603
- }
1604
- debug(message, ...optionalParams) {
1605
- if (this.level <= 0 /* Debug */) console.debug(message, ...optionalParams);
1606
- }
1607
- log(message, ...optionalParams) {
1608
- if (this.level <= 1 /* Information */) console.log(message, ...optionalParams);
1609
- }
1610
- warn(message, ...optionalParams) {
1611
- if (this.level <= 2 /* Warn */) console.warn(message, ...optionalParams);
1612
- }
1613
- error(message, ...optionalParams) {
1614
- if (this.level <= 3 /* Error */) console.error(message, ...optionalParams);
1615
- }
1616
- };
1617
-
1618
1625
  // src/schemas.ts
1619
1626
  var schemas_exports12 = {};
1620
1627
  __export(schemas_exports12, {
@@ -1665,7 +1672,7 @@ var MoneyCollectionUtils = class {
1665
1672
  var OfferUtils = class _OfferUtils {
1666
1673
  static eligible(offer, order) {
1667
1674
  switch (offer.condition.type) {
1668
- case "CartContainsItems":
1675
+ case "CartContainsItems": {
1669
1676
  const relevantItems = order.items.filter(
1670
1677
  (i) => i.type === "Product" && offer.condition.relevantItemVariations[`Product/${i.productId}`] && offer.condition.relevantItemVariations[`Product/${i.productId}`].includes(i.variationId) || i.type === "Bundle" && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`] && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].includes(i.variationId)
1671
1678
  );
@@ -1677,6 +1684,7 @@ var OfferUtils = class _OfferUtils {
1677
1684
  return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
1678
1685
  });
1679
1686
  return relevantItems.length + relevantReplacedItems.length >= offer.condition.minimumItems;
1687
+ }
1680
1688
  }
1681
1689
  console.warn("Unsupported offer condition found:", offer.condition);
1682
1690
  return false;
@@ -1700,7 +1708,8 @@ var OfferUtils = class _OfferUtils {
1700
1708
  };
1701
1709
  }
1702
1710
  static targetContainsBundle(offer, bundleId) {
1703
- if (Array.isArray(offer.target)) return offer.target.some((i) => i.type === "Bundle" && i.id === bundleId);
1711
+ if (Array.isArray(offer.target))
1712
+ return offer.target.some((i) => i.type === "Bundle" && i.id === bundleId);
1704
1713
  }
1705
1714
  };
1706
1715
 
package/dist/index.d.cts CHANGED
@@ -1,5 +1,47 @@
1
1
  import { ZodTypeAny, z } from 'zod';
2
2
 
3
+ interface ILogger {
4
+ debug: (message?: any, ...optionalParams: any[]) => void;
5
+ log: (message?: any, ...optionalParams: any[]) => void;
6
+ warn: (message?: any, ...optionalParams: any[]) => void;
7
+ error: (message?: any, ...optionalParams: any[]) => void;
8
+ }
9
+ declare enum LogLevel {
10
+ Debug = 0,
11
+ Information = 1,
12
+ Warn = 2,
13
+ Error = 3
14
+ }
15
+ declare class ConsoleLogger implements ILogger {
16
+ private readonly level;
17
+ constructor(level?: LogLevel);
18
+ debug(message?: any, ...optionalParams: any[]): void;
19
+ log(message?: any, ...optionalParams: any[]): void;
20
+ warn(message?: any, ...optionalParams: any[]): void;
21
+ error(message?: any, ...optionalParams: any[]): void;
22
+ }
23
+
24
+ interface IStore {
25
+ get: <TItem>(key: string) => TItem | null;
26
+ set: <TItem>(key: string, item: TItem) => void;
27
+ remove: (key: string) => void;
28
+ listen: <TItem>(key: string, callback: (item: TItem | null) => void) => void;
29
+ }
30
+ declare class LocalStorageStore implements IStore {
31
+ get<TItem>(key: string): TItem | null;
32
+ set<TItem>(key: string, item: TItem): void;
33
+ remove(key: string): void;
34
+ listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
35
+ }
36
+ declare class InMemoryStore implements IStore {
37
+ private readonly store;
38
+ private readonly listeners;
39
+ get<TItem>(key: string): TItem | null;
40
+ set<TItem>(key: string, item: TItem): void;
41
+ remove(key: string): void;
42
+ listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
43
+ }
44
+
3
45
  type IdentityWithExpiry = Identity & {
4
46
  expiresAt: Date;
5
47
  };
@@ -26,27 +68,6 @@ declare class TokenStore implements ITokenStore {
26
68
  private handleStorageUpdate;
27
69
  }
28
70
 
29
- interface ILogger {
30
- debug: (message?: any, ...optionalParams: any[]) => void;
31
- log: (message?: any, ...optionalParams: any[]) => void;
32
- warn: (message?: any, ...optionalParams: any[]) => void;
33
- error: (message?: any, ...optionalParams: any[]) => void;
34
- }
35
- declare enum LogLevel {
36
- Debug = 0,
37
- Information = 1,
38
- Warn = 2,
39
- Error = 3
40
- }
41
- declare class ConsoleLogger implements ILogger {
42
- private readonly level;
43
- constructor(level?: LogLevel);
44
- debug(message?: any, ...optionalParams: any[]): void;
45
- log(message?: any, ...optionalParams: any[]): void;
46
- warn(message?: any, ...optionalParams: any[]): void;
47
- error(message?: any, ...optionalParams: any[]): void;
48
- }
49
-
50
71
  type HttpMethods = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
51
72
  interface Response<T> {
52
73
  data: T;
@@ -1037,7 +1058,7 @@ declare const connectionUrlSchema: z.ZodObject<{
1037
1058
  declare const userSchema: z.ZodObject<{
1038
1059
  id: z.ZodString;
1039
1060
  email: z.ZodString;
1040
- name: z.ZodString;
1061
+ name: z.ZodNullable<z.ZodString>;
1041
1062
  tenantId: z.ZodString;
1042
1063
  address: z.ZodOptional<z.ZodObject<{
1043
1064
  countryCode: z.ZodString;
@@ -1096,7 +1117,7 @@ declare const userSchema: z.ZodObject<{
1096
1117
  }, "strip", z.ZodTypeAny, {
1097
1118
  id: string;
1098
1119
  email: string;
1099
- name: string;
1120
+ name: string | null;
1100
1121
  tenantId: string;
1101
1122
  communicationPreferences: {
1102
1123
  newsletterOptIn: boolean;
@@ -1125,7 +1146,7 @@ declare const userSchema: z.ZodObject<{
1125
1146
  }, {
1126
1147
  id: string;
1127
1148
  email: string;
1128
- name: string;
1149
+ name: string | null;
1129
1150
  tenantId: string;
1130
1151
  communicationPreferences: {
1131
1152
  newsletterOptIn: boolean;
@@ -1155,7 +1176,7 @@ declare const userSchema: z.ZodObject<{
1155
1176
  declare const identitySchema: z.ZodIntersection<z.ZodObject<{
1156
1177
  id: z.ZodString;
1157
1178
  email: z.ZodString;
1158
- name: z.ZodString;
1179
+ name: z.ZodNullable<z.ZodString>;
1159
1180
  tenantId: z.ZodString;
1160
1181
  address: z.ZodOptional<z.ZodObject<{
1161
1182
  countryCode: z.ZodString;
@@ -1214,7 +1235,7 @@ declare const identitySchema: z.ZodIntersection<z.ZodObject<{
1214
1235
  }, "strip", z.ZodTypeAny, {
1215
1236
  id: string;
1216
1237
  email: string;
1217
- name: string;
1238
+ name: string | null;
1218
1239
  tenantId: string;
1219
1240
  communicationPreferences: {
1220
1241
  newsletterOptIn: boolean;
@@ -1243,7 +1264,7 @@ declare const identitySchema: z.ZodIntersection<z.ZodObject<{
1243
1264
  }, {
1244
1265
  id: string;
1245
1266
  email: string;
1246
- name: string;
1267
+ name: string | null;
1247
1268
  tenantId: string;
1248
1269
  communicationPreferences: {
1249
1270
  newsletterOptIn: boolean;
@@ -1283,7 +1304,7 @@ declare const userAccountConfirmedStatusSchema: z.ZodEnum<["PasswordSetupRequire
1283
1304
  declare const userAccountConfirmedSchema: z.ZodIntersection<z.ZodObject<{
1284
1305
  id: z.ZodString;
1285
1306
  email: z.ZodString;
1286
- name: z.ZodString;
1307
+ name: z.ZodNullable<z.ZodString>;
1287
1308
  tenantId: z.ZodString;
1288
1309
  address: z.ZodOptional<z.ZodObject<{
1289
1310
  countryCode: z.ZodString;
@@ -1342,7 +1363,7 @@ declare const userAccountConfirmedSchema: z.ZodIntersection<z.ZodObject<{
1342
1363
  }, "strip", z.ZodTypeAny, {
1343
1364
  id: string;
1344
1365
  email: string;
1345
- name: string;
1366
+ name: string | null;
1346
1367
  tenantId: string;
1347
1368
  communicationPreferences: {
1348
1369
  newsletterOptIn: boolean;
@@ -1371,7 +1392,7 @@ declare const userAccountConfirmedSchema: z.ZodIntersection<z.ZodObject<{
1371
1392
  }, {
1372
1393
  id: string;
1373
1394
  email: string;
1374
- name: string;
1395
+ name: string | null;
1375
1396
  tenantId: string;
1376
1397
  communicationPreferences: {
1377
1398
  newsletterOptIn: boolean;
@@ -1465,12 +1486,12 @@ declare class IdentityEndpoints {
1465
1486
  signIn(email: string, password: string): Promise<User>;
1466
1487
  signUp(name: string, email: string, password: string, address: Address | null | undefined, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean, communicationOptIn?: boolean): Promise<SignUpResult>;
1467
1488
  signOut(): Promise<void>;
1468
- update(name: string, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences): Promise<{
1489
+ update(name: string | null, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences): Promise<{
1469
1490
  needsEmailConfirmationToken: boolean;
1470
1491
  user: {
1471
1492
  id: string;
1472
1493
  email: string;
1473
- name: string;
1494
+ name: string | null;
1474
1495
  tenantId: string;
1475
1496
  communicationPreferences: {
1476
1497
  newsletterOptIn: boolean;
@@ -23723,27 +23744,6 @@ declare class VoucherEndpoints {
23723
23744
  redeem(code: string): Promise<Voucher>;
23724
23745
  }
23725
23746
 
23726
- interface IStore {
23727
- get<TItem>(key: string): TItem | null;
23728
- set<TItem>(key: string, item: TItem): void;
23729
- remove(key: string): void;
23730
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23731
- }
23732
- declare class LocalStorageStore implements IStore {
23733
- get<TItem>(key: string): TItem | null;
23734
- set<TItem>(key: string, item: TItem): void;
23735
- remove(key: string): void;
23736
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23737
- }
23738
- declare class InMemoryStore implements IStore {
23739
- private readonly store;
23740
- private readonly listeners;
23741
- get<TItem>(key: string): TItem | null;
23742
- set<TItem>(key: string, item: TItem): void;
23743
- remove(key: string): void;
23744
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23745
- }
23746
-
23747
23747
  declare namespace schemas$2 {
23748
23748
  export { schemas$8 as licenses, schemas$7 as products, schemas$6 as subscriptions };
23749
23749
  }
@@ -38541,6 +38541,10 @@ type StorefrontOffer = z.infer<typeof storefrontOfferSchema>;
38541
38541
  type Storefront = z.infer<typeof storefrontSchema>;
38542
38542
  type TaxEstimate = z.infer<typeof taxEstimateSchema>;
38543
38543
 
38544
+ declare class DiscountUtils {
38545
+ static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38546
+ }
38547
+
38544
38548
  declare class NotAuthorizedError extends Error {
38545
38549
  constructor();
38546
38550
  }
@@ -38558,6 +38562,18 @@ declare class MoonbaseError extends Error {
38558
38562
  constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
38559
38563
  }
38560
38564
 
38565
+ declare class MoneyCollectionUtils {
38566
+ static sum(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38567
+ static subtract(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38568
+ }
38569
+
38570
+ declare class OfferUtils {
38571
+ static eligible(offer: StorefrontOffer, order: Order): boolean;
38572
+ static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): (StorefrontProduct | StorefrontBundle)[];
38573
+ static applyToVariation(offer: StorefrontOffer, variation: PricingVariation): PricingVariation;
38574
+ private static targetContainsBundle;
38575
+ }
38576
+
38561
38577
  declare const problemDetailsSchema: z.ZodObject<{
38562
38578
  type: z.ZodOptional<z.ZodString>;
38563
38579
  title: z.ZodString;
@@ -38582,22 +38598,6 @@ declare const problemDetailsSchema: z.ZodObject<{
38582
38598
  }>;
38583
38599
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
38584
38600
 
38585
- declare class OfferUtils {
38586
- static eligible(offer: StorefrontOffer, order: Order): boolean;
38587
- static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): (StorefrontProduct | StorefrontBundle)[];
38588
- static applyToVariation(offer: StorefrontOffer, variation: PricingVariation): PricingVariation;
38589
- private static targetContainsBundle;
38590
- }
38591
-
38592
- declare class MoneyCollectionUtils {
38593
- static sum(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38594
- static subtract(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38595
- }
38596
-
38597
- declare class DiscountUtils {
38598
- static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38599
- }
38600
-
38601
38601
  /**
38602
38602
  * Returns the host of `rawReferrer` if it parses as a URL with a different
38603
38603
  * origin from `currentOrigin`. Returns `undefined` for same-origin (internal
package/dist/index.d.ts CHANGED
@@ -1,5 +1,47 @@
1
1
  import { ZodTypeAny, z } from 'zod';
2
2
 
3
+ interface ILogger {
4
+ debug: (message?: any, ...optionalParams: any[]) => void;
5
+ log: (message?: any, ...optionalParams: any[]) => void;
6
+ warn: (message?: any, ...optionalParams: any[]) => void;
7
+ error: (message?: any, ...optionalParams: any[]) => void;
8
+ }
9
+ declare enum LogLevel {
10
+ Debug = 0,
11
+ Information = 1,
12
+ Warn = 2,
13
+ Error = 3
14
+ }
15
+ declare class ConsoleLogger implements ILogger {
16
+ private readonly level;
17
+ constructor(level?: LogLevel);
18
+ debug(message?: any, ...optionalParams: any[]): void;
19
+ log(message?: any, ...optionalParams: any[]): void;
20
+ warn(message?: any, ...optionalParams: any[]): void;
21
+ error(message?: any, ...optionalParams: any[]): void;
22
+ }
23
+
24
+ interface IStore {
25
+ get: <TItem>(key: string) => TItem | null;
26
+ set: <TItem>(key: string, item: TItem) => void;
27
+ remove: (key: string) => void;
28
+ listen: <TItem>(key: string, callback: (item: TItem | null) => void) => void;
29
+ }
30
+ declare class LocalStorageStore implements IStore {
31
+ get<TItem>(key: string): TItem | null;
32
+ set<TItem>(key: string, item: TItem): void;
33
+ remove(key: string): void;
34
+ listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
35
+ }
36
+ declare class InMemoryStore implements IStore {
37
+ private readonly store;
38
+ private readonly listeners;
39
+ get<TItem>(key: string): TItem | null;
40
+ set<TItem>(key: string, item: TItem): void;
41
+ remove(key: string): void;
42
+ listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
43
+ }
44
+
3
45
  type IdentityWithExpiry = Identity & {
4
46
  expiresAt: Date;
5
47
  };
@@ -26,27 +68,6 @@ declare class TokenStore implements ITokenStore {
26
68
  private handleStorageUpdate;
27
69
  }
28
70
 
29
- interface ILogger {
30
- debug: (message?: any, ...optionalParams: any[]) => void;
31
- log: (message?: any, ...optionalParams: any[]) => void;
32
- warn: (message?: any, ...optionalParams: any[]) => void;
33
- error: (message?: any, ...optionalParams: any[]) => void;
34
- }
35
- declare enum LogLevel {
36
- Debug = 0,
37
- Information = 1,
38
- Warn = 2,
39
- Error = 3
40
- }
41
- declare class ConsoleLogger implements ILogger {
42
- private readonly level;
43
- constructor(level?: LogLevel);
44
- debug(message?: any, ...optionalParams: any[]): void;
45
- log(message?: any, ...optionalParams: any[]): void;
46
- warn(message?: any, ...optionalParams: any[]): void;
47
- error(message?: any, ...optionalParams: any[]): void;
48
- }
49
-
50
71
  type HttpMethods = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
51
72
  interface Response<T> {
52
73
  data: T;
@@ -1037,7 +1058,7 @@ declare const connectionUrlSchema: z.ZodObject<{
1037
1058
  declare const userSchema: z.ZodObject<{
1038
1059
  id: z.ZodString;
1039
1060
  email: z.ZodString;
1040
- name: z.ZodString;
1061
+ name: z.ZodNullable<z.ZodString>;
1041
1062
  tenantId: z.ZodString;
1042
1063
  address: z.ZodOptional<z.ZodObject<{
1043
1064
  countryCode: z.ZodString;
@@ -1096,7 +1117,7 @@ declare const userSchema: z.ZodObject<{
1096
1117
  }, "strip", z.ZodTypeAny, {
1097
1118
  id: string;
1098
1119
  email: string;
1099
- name: string;
1120
+ name: string | null;
1100
1121
  tenantId: string;
1101
1122
  communicationPreferences: {
1102
1123
  newsletterOptIn: boolean;
@@ -1125,7 +1146,7 @@ declare const userSchema: z.ZodObject<{
1125
1146
  }, {
1126
1147
  id: string;
1127
1148
  email: string;
1128
- name: string;
1149
+ name: string | null;
1129
1150
  tenantId: string;
1130
1151
  communicationPreferences: {
1131
1152
  newsletterOptIn: boolean;
@@ -1155,7 +1176,7 @@ declare const userSchema: z.ZodObject<{
1155
1176
  declare const identitySchema: z.ZodIntersection<z.ZodObject<{
1156
1177
  id: z.ZodString;
1157
1178
  email: z.ZodString;
1158
- name: z.ZodString;
1179
+ name: z.ZodNullable<z.ZodString>;
1159
1180
  tenantId: z.ZodString;
1160
1181
  address: z.ZodOptional<z.ZodObject<{
1161
1182
  countryCode: z.ZodString;
@@ -1214,7 +1235,7 @@ declare const identitySchema: z.ZodIntersection<z.ZodObject<{
1214
1235
  }, "strip", z.ZodTypeAny, {
1215
1236
  id: string;
1216
1237
  email: string;
1217
- name: string;
1238
+ name: string | null;
1218
1239
  tenantId: string;
1219
1240
  communicationPreferences: {
1220
1241
  newsletterOptIn: boolean;
@@ -1243,7 +1264,7 @@ declare const identitySchema: z.ZodIntersection<z.ZodObject<{
1243
1264
  }, {
1244
1265
  id: string;
1245
1266
  email: string;
1246
- name: string;
1267
+ name: string | null;
1247
1268
  tenantId: string;
1248
1269
  communicationPreferences: {
1249
1270
  newsletterOptIn: boolean;
@@ -1283,7 +1304,7 @@ declare const userAccountConfirmedStatusSchema: z.ZodEnum<["PasswordSetupRequire
1283
1304
  declare const userAccountConfirmedSchema: z.ZodIntersection<z.ZodObject<{
1284
1305
  id: z.ZodString;
1285
1306
  email: z.ZodString;
1286
- name: z.ZodString;
1307
+ name: z.ZodNullable<z.ZodString>;
1287
1308
  tenantId: z.ZodString;
1288
1309
  address: z.ZodOptional<z.ZodObject<{
1289
1310
  countryCode: z.ZodString;
@@ -1342,7 +1363,7 @@ declare const userAccountConfirmedSchema: z.ZodIntersection<z.ZodObject<{
1342
1363
  }, "strip", z.ZodTypeAny, {
1343
1364
  id: string;
1344
1365
  email: string;
1345
- name: string;
1366
+ name: string | null;
1346
1367
  tenantId: string;
1347
1368
  communicationPreferences: {
1348
1369
  newsletterOptIn: boolean;
@@ -1371,7 +1392,7 @@ declare const userAccountConfirmedSchema: z.ZodIntersection<z.ZodObject<{
1371
1392
  }, {
1372
1393
  id: string;
1373
1394
  email: string;
1374
- name: string;
1395
+ name: string | null;
1375
1396
  tenantId: string;
1376
1397
  communicationPreferences: {
1377
1398
  newsletterOptIn: boolean;
@@ -1465,12 +1486,12 @@ declare class IdentityEndpoints {
1465
1486
  signIn(email: string, password: string): Promise<User>;
1466
1487
  signUp(name: string, email: string, password: string, address: Address | null | undefined, acceptedPrivacyPolicy: boolean, acceptedTermsAndConditions: boolean, communicationOptIn?: boolean): Promise<SignUpResult>;
1467
1488
  signOut(): Promise<void>;
1468
- update(name: string, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences): Promise<{
1489
+ update(name: string | null, email: string, emailConfirmationToken?: string, communicationPreferences?: CommunicationPreferences): Promise<{
1469
1490
  needsEmailConfirmationToken: boolean;
1470
1491
  user: {
1471
1492
  id: string;
1472
1493
  email: string;
1473
- name: string;
1494
+ name: string | null;
1474
1495
  tenantId: string;
1475
1496
  communicationPreferences: {
1476
1497
  newsletterOptIn: boolean;
@@ -23723,27 +23744,6 @@ declare class VoucherEndpoints {
23723
23744
  redeem(code: string): Promise<Voucher>;
23724
23745
  }
23725
23746
 
23726
- interface IStore {
23727
- get<TItem>(key: string): TItem | null;
23728
- set<TItem>(key: string, item: TItem): void;
23729
- remove(key: string): void;
23730
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23731
- }
23732
- declare class LocalStorageStore implements IStore {
23733
- get<TItem>(key: string): TItem | null;
23734
- set<TItem>(key: string, item: TItem): void;
23735
- remove(key: string): void;
23736
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23737
- }
23738
- declare class InMemoryStore implements IStore {
23739
- private readonly store;
23740
- private readonly listeners;
23741
- get<TItem>(key: string): TItem | null;
23742
- set<TItem>(key: string, item: TItem): void;
23743
- remove(key: string): void;
23744
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23745
- }
23746
-
23747
23747
  declare namespace schemas$2 {
23748
23748
  export { schemas$8 as licenses, schemas$7 as products, schemas$6 as subscriptions };
23749
23749
  }
@@ -38541,6 +38541,10 @@ type StorefrontOffer = z.infer<typeof storefrontOfferSchema>;
38541
38541
  type Storefront = z.infer<typeof storefrontSchema>;
38542
38542
  type TaxEstimate = z.infer<typeof taxEstimateSchema>;
38543
38543
 
38544
+ declare class DiscountUtils {
38545
+ static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38546
+ }
38547
+
38544
38548
  declare class NotAuthorizedError extends Error {
38545
38549
  constructor();
38546
38550
  }
@@ -38558,6 +38562,18 @@ declare class MoonbaseError extends Error {
38558
38562
  constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
38559
38563
  }
38560
38564
 
38565
+ declare class MoneyCollectionUtils {
38566
+ static sum(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38567
+ static subtract(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38568
+ }
38569
+
38570
+ declare class OfferUtils {
38571
+ static eligible(offer: StorefrontOffer, order: Order): boolean;
38572
+ static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): (StorefrontProduct | StorefrontBundle)[];
38573
+ static applyToVariation(offer: StorefrontOffer, variation: PricingVariation): PricingVariation;
38574
+ private static targetContainsBundle;
38575
+ }
38576
+
38561
38577
  declare const problemDetailsSchema: z.ZodObject<{
38562
38578
  type: z.ZodOptional<z.ZodString>;
38563
38579
  title: z.ZodString;
@@ -38582,22 +38598,6 @@ declare const problemDetailsSchema: z.ZodObject<{
38582
38598
  }>;
38583
38599
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
38584
38600
 
38585
- declare class OfferUtils {
38586
- static eligible(offer: StorefrontOffer, order: Order): boolean;
38587
- static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): (StorefrontProduct | StorefrontBundle)[];
38588
- static applyToVariation(offer: StorefrontOffer, variation: PricingVariation): PricingVariation;
38589
- private static targetContainsBundle;
38590
- }
38591
-
38592
- declare class MoneyCollectionUtils {
38593
- static sum(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38594
- static subtract(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38595
- }
38596
-
38597
- declare class DiscountUtils {
38598
- static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38599
- }
38600
-
38601
38601
  /**
38602
38602
  * Returns the host of `rawReferrer` if it parses as a URL with a different
38603
38603
  * origin from `currentOrigin`. Returns `undefined` for same-origin (internal
package/dist/index.js CHANGED
@@ -464,11 +464,11 @@ async function handleResponseProblem(response, logger) {
464
464
  throw new NotAuthorizedError();
465
465
  }
466
466
  let problemDetails;
467
+ const body = await response.text();
467
468
  try {
468
- const json = await response.json();
469
- problemDetails = problemDetailsSchema.parse(json);
469
+ problemDetails = problemDetailsSchema.parse(JSON.parse(body));
470
470
  } catch (err) {
471
- logger.warn("Could not handle response", { response, err, content: await response.text() });
471
+ logger.warn("Could not handle response", { response, err, content: body });
472
472
  throw new Error("An unknown problem occurred");
473
473
  }
474
474
  logger.debug("The response indicates a problem", problemDetails);
@@ -532,7 +532,8 @@ var connectionUrlSchema = z8.object({
532
532
  var userSchema = z8.object({
533
533
  id: z8.string(),
534
534
  email: z8.string(),
535
- name: z8.string(),
535
+ // Nullable: customers created via import may have no name.
536
+ name: z8.string().nullable(),
536
537
  tenantId: z8.string(),
537
538
  address: addressSchema.optional(),
538
539
  phone: z8.string().optional(),
@@ -861,6 +862,9 @@ var ProductEndpoints = class {
861
862
  }
862
863
  };
863
864
 
865
+ // src/inventory/subscriptions/endpoints.ts
866
+ import { z as z14 } from "zod";
867
+
864
868
  // src/utils/api.ts
865
869
  function objectToQuery(obj) {
866
870
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
@@ -986,9 +990,6 @@ var MoonbaseApi = class {
986
990
  }
987
991
  };
988
992
 
989
- // src/inventory/subscriptions/endpoints.ts
990
- import { z as z14 } from "zod";
991
-
992
993
  // src/inventory/subscriptions/schemas.ts
993
994
  var schemas_exports8 = {};
994
995
  __export(schemas_exports8, {
@@ -997,15 +998,6 @@ __export(schemas_exports8, {
997
998
  });
998
999
  import { z as z13 } from "zod";
999
1000
 
1000
- // src/inventory/subscriptions/models.ts
1001
- var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
1002
- SubscriptionStatus2["Active"] = "Active";
1003
- SubscriptionStatus2["Expired"] = "Expired";
1004
- SubscriptionStatus2["Cancelled"] = "Cancelled";
1005
- SubscriptionStatus2["Completed"] = "Completed";
1006
- return SubscriptionStatus2;
1007
- })(SubscriptionStatus || {});
1008
-
1009
1001
  // src/orders/schemas.ts
1010
1002
  var schemas_exports7 = {};
1011
1003
  __export(schemas_exports7, {
@@ -1142,6 +1134,15 @@ var orderSchema = z12.discriminatedUnion("status", [
1142
1134
  completedOrderSchema
1143
1135
  ]);
1144
1136
 
1137
+ // src/inventory/subscriptions/models.ts
1138
+ var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
1139
+ SubscriptionStatus2["Active"] = "Active";
1140
+ SubscriptionStatus2["Expired"] = "Expired";
1141
+ SubscriptionStatus2["Cancelled"] = "Cancelled";
1142
+ SubscriptionStatus2["Completed"] = "Completed";
1143
+ return SubscriptionStatus2;
1144
+ })(SubscriptionStatus || {});
1145
+
1145
1146
  // src/inventory/subscriptions/schemas.ts
1146
1147
  var baseMilestoneProgressEventSchema = z13.object({
1147
1148
  milestoneId: z13.string(),
@@ -1317,6 +1318,36 @@ var StorefrontEndpoints = class {
1317
1318
  }
1318
1319
  };
1319
1320
 
1321
+ // src/utils/logger.ts
1322
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1323
+ LogLevel2[LogLevel2["Debug"] = 0] = "Debug";
1324
+ LogLevel2[LogLevel2["Information"] = 1] = "Information";
1325
+ LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
1326
+ LogLevel2[LogLevel2["Error"] = 3] = "Error";
1327
+ return LogLevel2;
1328
+ })(LogLevel || {});
1329
+ var ConsoleLogger = class {
1330
+ constructor(level = 2 /* Warn */) {
1331
+ this.level = level;
1332
+ }
1333
+ debug(message, ...optionalParams) {
1334
+ if (this.level <= 0 /* Debug */)
1335
+ console.debug(message, ...optionalParams);
1336
+ }
1337
+ log(message, ...optionalParams) {
1338
+ if (this.level <= 1 /* Information */)
1339
+ console.log(message, ...optionalParams);
1340
+ }
1341
+ warn(message, ...optionalParams) {
1342
+ if (this.level <= 2 /* Warn */)
1343
+ console.warn(message, ...optionalParams);
1344
+ }
1345
+ error(message, ...optionalParams) {
1346
+ if (this.level <= 3 /* Error */)
1347
+ console.error(message, ...optionalParams);
1348
+ }
1349
+ };
1350
+
1320
1351
  // src/utils/store.ts
1321
1352
  var LocalStorageStore = class {
1322
1353
  get(key) {
@@ -1364,7 +1395,8 @@ var InMemoryStore = class {
1364
1395
  }
1365
1396
  }
1366
1397
  listen(key, callback) {
1367
- if (!this.listeners[key]) this.listeners[key] = [];
1398
+ if (!this.listeners[key])
1399
+ this.listeners[key] = [];
1368
1400
  this.listeners[key].push(callback);
1369
1401
  }
1370
1402
  };
@@ -1408,7 +1440,8 @@ var _TokenStore = class _TokenStore {
1408
1440
  setUser(user) {
1409
1441
  const identity = user;
1410
1442
  if (!identity.accessToken || !identity.refreshToken) {
1411
- if (!this.tokens) return null;
1443
+ if (!this.tokens)
1444
+ return null;
1412
1445
  this.tokens = {
1413
1446
  ...user,
1414
1447
  accessToken: this.tokens.accessToken,
@@ -1538,32 +1571,6 @@ var VoucherEndpoints = class {
1538
1571
  }
1539
1572
  };
1540
1573
 
1541
- // src/utils/logger.ts
1542
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1543
- LogLevel2[LogLevel2["Debug"] = 0] = "Debug";
1544
- LogLevel2[LogLevel2["Information"] = 1] = "Information";
1545
- LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
1546
- LogLevel2[LogLevel2["Error"] = 3] = "Error";
1547
- return LogLevel2;
1548
- })(LogLevel || {});
1549
- var ConsoleLogger = class {
1550
- constructor(level = 2 /* Warn */) {
1551
- this.level = level;
1552
- }
1553
- debug(message, ...optionalParams) {
1554
- if (this.level <= 0 /* Debug */) console.debug(message, ...optionalParams);
1555
- }
1556
- log(message, ...optionalParams) {
1557
- if (this.level <= 1 /* Information */) console.log(message, ...optionalParams);
1558
- }
1559
- warn(message, ...optionalParams) {
1560
- if (this.level <= 2 /* Warn */) console.warn(message, ...optionalParams);
1561
- }
1562
- error(message, ...optionalParams) {
1563
- if (this.level <= 3 /* Error */) console.error(message, ...optionalParams);
1564
- }
1565
- };
1566
-
1567
1574
  // src/schemas.ts
1568
1575
  var schemas_exports12 = {};
1569
1576
  __export(schemas_exports12, {
@@ -1614,7 +1621,7 @@ var MoneyCollectionUtils = class {
1614
1621
  var OfferUtils = class _OfferUtils {
1615
1622
  static eligible(offer, order) {
1616
1623
  switch (offer.condition.type) {
1617
- case "CartContainsItems":
1624
+ case "CartContainsItems": {
1618
1625
  const relevantItems = order.items.filter(
1619
1626
  (i) => i.type === "Product" && offer.condition.relevantItemVariations[`Product/${i.productId}`] && offer.condition.relevantItemVariations[`Product/${i.productId}`].includes(i.variationId) || i.type === "Bundle" && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`] && offer.condition.relevantItemVariations[`Bundle/${i.bundleId}`].includes(i.variationId)
1620
1627
  );
@@ -1626,6 +1633,7 @@ var OfferUtils = class _OfferUtils {
1626
1633
  return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
1627
1634
  });
1628
1635
  return relevantItems.length + relevantReplacedItems.length >= offer.condition.minimumItems;
1636
+ }
1629
1637
  }
1630
1638
  console.warn("Unsupported offer condition found:", offer.condition);
1631
1639
  return false;
@@ -1649,7 +1657,8 @@ var OfferUtils = class _OfferUtils {
1649
1657
  };
1650
1658
  }
1651
1659
  static targetContainsBundle(offer, bundleId) {
1652
- if (Array.isArray(offer.target)) return offer.target.some((i) => i.type === "Bundle" && i.id === bundleId);
1660
+ if (Array.isArray(offer.target))
1661
+ return offer.target.some((i) => i.type === "Bundle" && i.id === bundleId);
1653
1662
  }
1654
1663
  };
1655
1664
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "2.3.0",
4
+ "version": "2.3.1",
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",
@@ -26,6 +26,9 @@
26
26
  "build": "tsup src/index.ts --format esm,cjs --dts",
27
27
  "dev": "tsup src/index.ts --format esm,cjs --watch --dts",
28
28
  "version": "npm version",
29
- "test": "vitest"
29
+ "type-check": "tsc --noEmit -p tsconfig.typecheck.json",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "test:integration": "TEST_INTEGRATION=true vitest run"
30
33
  }
31
34
  }