@moonbase.sh/storefront-api 2.2.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
@@ -156,7 +156,13 @@ var pricingVariationSchema = import_zod.z.object({
156
156
  pricingTiers: import_zod.z.array(pricingTierSchema).nullish()
157
157
  });
158
158
  var rawPropertyValueSchema = import_zod.z.lazy(
159
- () => import_zod.z.union([import_zod.z.string(), import_zod.z.number(), import_zod.z.boolean(), import_zod.z.record(rawPropertyValueSchema)])
159
+ () => import_zod.z.union([
160
+ import_zod.z.string(),
161
+ import_zod.z.number(),
162
+ import_zod.z.boolean(),
163
+ import_zod.z.record(rawPropertyValueSchema),
164
+ import_zod.z.array(rawPropertyValueSchema)
165
+ ])
160
166
  );
161
167
  function paged(itemSchema) {
162
168
  return import_zod.z.object({
@@ -509,11 +515,11 @@ async function handleResponseProblem(response, logger) {
509
515
  throw new NotAuthorizedError();
510
516
  }
511
517
  let problemDetails;
518
+ const body = await response.text();
512
519
  try {
513
- const json = await response.json();
514
- problemDetails = problemDetailsSchema.parse(json);
520
+ problemDetails = problemDetailsSchema.parse(JSON.parse(body));
515
521
  } catch (err) {
516
- logger.warn("Could not handle response", { response, err, content: await response.text() });
522
+ logger.warn("Could not handle response", { response, err, content: body });
517
523
  throw new Error("An unknown problem occurred");
518
524
  }
519
525
  logger.debug("The response indicates a problem", problemDetails);
@@ -577,7 +583,8 @@ var connectionUrlSchema = import_zod8.z.object({
577
583
  var userSchema = import_zod8.z.object({
578
584
  id: import_zod8.z.string(),
579
585
  email: import_zod8.z.string(),
580
- name: import_zod8.z.string(),
586
+ // Nullable: customers created via import may have no name.
587
+ name: import_zod8.z.string().nullable(),
581
588
  tenantId: import_zod8.z.string(),
582
589
  address: addressSchema.optional(),
583
590
  phone: import_zod8.z.string().optional(),
@@ -906,6 +913,9 @@ var ProductEndpoints = class {
906
913
  }
907
914
  };
908
915
 
916
+ // src/inventory/subscriptions/endpoints.ts
917
+ var import_zod14 = require("zod");
918
+
909
919
  // src/utils/api.ts
910
920
  function objectToQuery(obj) {
911
921
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
@@ -1031,9 +1041,6 @@ var MoonbaseApi = class {
1031
1041
  }
1032
1042
  };
1033
1043
 
1034
- // src/inventory/subscriptions/endpoints.ts
1035
- var import_zod14 = require("zod");
1036
-
1037
1044
  // src/inventory/subscriptions/schemas.ts
1038
1045
  var schemas_exports8 = {};
1039
1046
  __export(schemas_exports8, {
@@ -1042,15 +1049,6 @@ __export(schemas_exports8, {
1042
1049
  });
1043
1050
  var import_zod13 = require("zod");
1044
1051
 
1045
- // src/inventory/subscriptions/models.ts
1046
- var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
1047
- SubscriptionStatus2["Active"] = "Active";
1048
- SubscriptionStatus2["Expired"] = "Expired";
1049
- SubscriptionStatus2["Cancelled"] = "Cancelled";
1050
- SubscriptionStatus2["Completed"] = "Completed";
1051
- return SubscriptionStatus2;
1052
- })(SubscriptionStatus || {});
1053
-
1054
1052
  // src/orders/schemas.ts
1055
1053
  var schemas_exports7 = {};
1056
1054
  __export(schemas_exports7, {
@@ -1187,6 +1185,15 @@ var orderSchema = import_zod12.z.discriminatedUnion("status", [
1187
1185
  completedOrderSchema
1188
1186
  ]);
1189
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
+
1190
1197
  // src/inventory/subscriptions/schemas.ts
1191
1198
  var baseMilestoneProgressEventSchema = import_zod13.z.object({
1192
1199
  milestoneId: import_zod13.z.string(),
@@ -1362,6 +1369,36 @@ var StorefrontEndpoints = class {
1362
1369
  }
1363
1370
  };
1364
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
+
1365
1402
  // src/utils/store.ts
1366
1403
  var LocalStorageStore = class {
1367
1404
  get(key) {
@@ -1409,7 +1446,8 @@ var InMemoryStore = class {
1409
1446
  }
1410
1447
  }
1411
1448
  listen(key, callback) {
1412
- if (!this.listeners[key]) this.listeners[key] = [];
1449
+ if (!this.listeners[key])
1450
+ this.listeners[key] = [];
1413
1451
  this.listeners[key].push(callback);
1414
1452
  }
1415
1453
  };
@@ -1453,7 +1491,8 @@ var _TokenStore = class _TokenStore {
1453
1491
  setUser(user) {
1454
1492
  const identity = user;
1455
1493
  if (!identity.accessToken || !identity.refreshToken) {
1456
- if (!this.tokens) return null;
1494
+ if (!this.tokens)
1495
+ return null;
1457
1496
  this.tokens = {
1458
1497
  ...user,
1459
1498
  accessToken: this.tokens.accessToken,
@@ -1583,32 +1622,6 @@ var VoucherEndpoints = class {
1583
1622
  }
1584
1623
  };
1585
1624
 
1586
- // src/utils/logger.ts
1587
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1588
- LogLevel2[LogLevel2["Debug"] = 0] = "Debug";
1589
- LogLevel2[LogLevel2["Information"] = 1] = "Information";
1590
- LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
1591
- LogLevel2[LogLevel2["Error"] = 3] = "Error";
1592
- return LogLevel2;
1593
- })(LogLevel || {});
1594
- var ConsoleLogger = class {
1595
- constructor(level = 2 /* Warn */) {
1596
- this.level = level;
1597
- }
1598
- debug(message, ...optionalParams) {
1599
- if (this.level <= 0 /* Debug */) console.debug(message, ...optionalParams);
1600
- }
1601
- log(message, ...optionalParams) {
1602
- if (this.level <= 1 /* Information */) console.log(message, ...optionalParams);
1603
- }
1604
- warn(message, ...optionalParams) {
1605
- if (this.level <= 2 /* Warn */) console.warn(message, ...optionalParams);
1606
- }
1607
- error(message, ...optionalParams) {
1608
- if (this.level <= 3 /* Error */) console.error(message, ...optionalParams);
1609
- }
1610
- };
1611
-
1612
1625
  // src/schemas.ts
1613
1626
  var schemas_exports12 = {};
1614
1627
  __export(schemas_exports12, {
@@ -1659,7 +1672,7 @@ var MoneyCollectionUtils = class {
1659
1672
  var OfferUtils = class _OfferUtils {
1660
1673
  static eligible(offer, order) {
1661
1674
  switch (offer.condition.type) {
1662
- case "CartContainsItems":
1675
+ case "CartContainsItems": {
1663
1676
  const relevantItems = order.items.filter(
1664
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)
1665
1678
  );
@@ -1671,6 +1684,7 @@ var OfferUtils = class _OfferUtils {
1671
1684
  return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
1672
1685
  });
1673
1686
  return relevantItems.length + relevantReplacedItems.length >= offer.condition.minimumItems;
1687
+ }
1674
1688
  }
1675
1689
  console.warn("Unsupported offer condition found:", offer.condition);
1676
1690
  return false;
@@ -1694,7 +1708,8 @@ var OfferUtils = class _OfferUtils {
1694
1708
  };
1695
1709
  }
1696
1710
  static targetContainsBundle(offer, bundleId) {
1697
- 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);
1698
1713
  }
1699
1714
  };
1700
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;
@@ -2129,7 +2150,8 @@ type SingleOrMultiple<T> = T | T[];
2129
2150
  interface RawPropertyObject {
2130
2151
  [key: string]: RawPropertyValue;
2131
2152
  }
2132
- type RawPropertyValue = string | number | boolean | RawPropertyObject;
2153
+ type RawPropertyArray = RawPropertyValue[];
2154
+ type RawPropertyValue = string | number | boolean | RawPropertyObject | RawPropertyArray;
2133
2155
  declare enum CycleLength {
2134
2156
  Daily = "Daily",
2135
2157
  Weekly = "Weekly",
@@ -23722,27 +23744,6 @@ declare class VoucherEndpoints {
23722
23744
  redeem(code: string): Promise<Voucher>;
23723
23745
  }
23724
23746
 
23725
- interface IStore {
23726
- get<TItem>(key: string): TItem | null;
23727
- set<TItem>(key: string, item: TItem): void;
23728
- remove(key: string): void;
23729
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23730
- }
23731
- declare class LocalStorageStore implements IStore {
23732
- get<TItem>(key: string): TItem | null;
23733
- set<TItem>(key: string, item: TItem): void;
23734
- remove(key: string): void;
23735
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23736
- }
23737
- declare class InMemoryStore implements IStore {
23738
- private readonly store;
23739
- private readonly listeners;
23740
- get<TItem>(key: string): TItem | null;
23741
- set<TItem>(key: string, item: TItem): void;
23742
- remove(key: string): void;
23743
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23744
- }
23745
-
23746
23747
  declare namespace schemas$2 {
23747
23748
  export { schemas$8 as licenses, schemas$7 as products, schemas$6 as subscriptions };
23748
23749
  }
@@ -38540,6 +38541,10 @@ type StorefrontOffer = z.infer<typeof storefrontOfferSchema>;
38540
38541
  type Storefront = z.infer<typeof storefrontSchema>;
38541
38542
  type TaxEstimate = z.infer<typeof taxEstimateSchema>;
38542
38543
 
38544
+ declare class DiscountUtils {
38545
+ static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38546
+ }
38547
+
38543
38548
  declare class NotAuthorizedError extends Error {
38544
38549
  constructor();
38545
38550
  }
@@ -38557,6 +38562,18 @@ declare class MoonbaseError extends Error {
38557
38562
  constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
38558
38563
  }
38559
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
+
38560
38577
  declare const problemDetailsSchema: z.ZodObject<{
38561
38578
  type: z.ZodOptional<z.ZodString>;
38562
38579
  title: z.ZodString;
@@ -38581,22 +38598,6 @@ declare const problemDetailsSchema: z.ZodObject<{
38581
38598
  }>;
38582
38599
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
38583
38600
 
38584
- declare class OfferUtils {
38585
- static eligible(offer: StorefrontOffer, order: Order): boolean;
38586
- static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): (StorefrontProduct | StorefrontBundle)[];
38587
- static applyToVariation(offer: StorefrontOffer, variation: PricingVariation): PricingVariation;
38588
- private static targetContainsBundle;
38589
- }
38590
-
38591
- declare class MoneyCollectionUtils {
38592
- static sum(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38593
- static subtract(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38594
- }
38595
-
38596
- declare class DiscountUtils {
38597
- static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38598
- }
38599
-
38600
38601
  /**
38601
38602
  * Returns the host of `rawReferrer` if it parses as a URL with a different
38602
38603
  * origin from `currentOrigin`. Returns `undefined` for same-origin (internal
@@ -38646,4 +38647,4 @@ declare class MoonbaseClient {
38646
38647
  orders: OrderEndpoints;
38647
38648
  }
38648
38649
 
38649
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, resolveUtm, schemas, utmToObject };
38650
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, resolveUtm, schemas, utmToObject };
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;
@@ -2129,7 +2150,8 @@ type SingleOrMultiple<T> = T | T[];
2129
2150
  interface RawPropertyObject {
2130
2151
  [key: string]: RawPropertyValue;
2131
2152
  }
2132
- type RawPropertyValue = string | number | boolean | RawPropertyObject;
2153
+ type RawPropertyArray = RawPropertyValue[];
2154
+ type RawPropertyValue = string | number | boolean | RawPropertyObject | RawPropertyArray;
2133
2155
  declare enum CycleLength {
2134
2156
  Daily = "Daily",
2135
2157
  Weekly = "Weekly",
@@ -23722,27 +23744,6 @@ declare class VoucherEndpoints {
23722
23744
  redeem(code: string): Promise<Voucher>;
23723
23745
  }
23724
23746
 
23725
- interface IStore {
23726
- get<TItem>(key: string): TItem | null;
23727
- set<TItem>(key: string, item: TItem): void;
23728
- remove(key: string): void;
23729
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23730
- }
23731
- declare class LocalStorageStore implements IStore {
23732
- get<TItem>(key: string): TItem | null;
23733
- set<TItem>(key: string, item: TItem): void;
23734
- remove(key: string): void;
23735
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23736
- }
23737
- declare class InMemoryStore implements IStore {
23738
- private readonly store;
23739
- private readonly listeners;
23740
- get<TItem>(key: string): TItem | null;
23741
- set<TItem>(key: string, item: TItem): void;
23742
- remove(key: string): void;
23743
- listen<TItem>(key: string, callback: (item: TItem | null) => void): void;
23744
- }
23745
-
23746
23747
  declare namespace schemas$2 {
23747
23748
  export { schemas$8 as licenses, schemas$7 as products, schemas$6 as subscriptions };
23748
23749
  }
@@ -38540,6 +38541,10 @@ type StorefrontOffer = z.infer<typeof storefrontOfferSchema>;
38540
38541
  type Storefront = z.infer<typeof storefrontSchema>;
38541
38542
  type TaxEstimate = z.infer<typeof taxEstimateSchema>;
38542
38543
 
38544
+ declare class DiscountUtils {
38545
+ static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38546
+ }
38547
+
38543
38548
  declare class NotAuthorizedError extends Error {
38544
38549
  constructor();
38545
38550
  }
@@ -38557,6 +38562,18 @@ declare class MoonbaseError extends Error {
38557
38562
  constructor(title: string, detail: string | undefined, status?: number | undefined, errors?: Record<string, string> | undefined);
38558
38563
  }
38559
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
+
38560
38577
  declare const problemDetailsSchema: z.ZodObject<{
38561
38578
  type: z.ZodOptional<z.ZodString>;
38562
38579
  title: z.ZodString;
@@ -38581,22 +38598,6 @@ declare const problemDetailsSchema: z.ZodObject<{
38581
38598
  }>;
38582
38599
  type ProblemDetails = z.infer<typeof problemDetailsSchema>;
38583
38600
 
38584
- declare class OfferUtils {
38585
- static eligible(offer: StorefrontOffer, order: Order): boolean;
38586
- static relevantTargets(offer: StorefrontOffer, cartItems: LineItem[]): (StorefrontProduct | StorefrontBundle)[];
38587
- static applyToVariation(offer: StorefrontOffer, variation: PricingVariation): PricingVariation;
38588
- private static targetContainsBundle;
38589
- }
38590
-
38591
- declare class MoneyCollectionUtils {
38592
- static sum(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38593
- static subtract(a: MoneyCollection, b: MoneyCollection): MoneyCollection;
38594
- }
38595
-
38596
- declare class DiscountUtils {
38597
- static apply(discount: Discount, price: MoneyCollection): MoneyCollection;
38598
- }
38599
-
38600
38601
  /**
38601
38602
  * Returns the host of `rawReferrer` if it parses as a URL with a different
38602
38603
  * origin from `currentOrigin`. Returns `undefined` for same-origin (internal
@@ -38646,4 +38647,4 @@ declare class MoonbaseClient {
38646
38647
  orders: OrderEndpoints;
38647
38648
  }
38648
38649
 
38649
- export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, resolveUtm, schemas, utmToObject };
38650
+ export { type Activation, ActivationMethod, type ActivationRequest, ActivationRequestFulfillmentType, ActivationRequestStatus, ActivationStatus, type Address, Architecture, type BundleLineItem, type CommunicationPreferences, type CommunicationPreferencesInput, type CommunicationPreferencesView, type CompletedOrder, ConnectableAccountProvider, type ConnectedAccount, ConsoleLogger, CycleLength, type Discount, DiscountUtils, type Download, type DownloadManifest, type ILogger, type IRecurrence, type IStore, type ITokenStore, type Identity, InMemoryStore, type License, LicenseStatus, type LineItem, LocalStorageStore, LogLevel, MarketingConsentType, type MilestoneProgress, type Money, type MoneyCollection, MoneyCollectionUtils, MoonbaseApi, MoonbaseClient, type MoonbaseConfiguration, MoonbaseError, NotAuthenticatedError, NotAuthorizedError, NotFoundError, type OfferCondition, OfferUtils, type OpenOrder, type Order, OrderStatus, type OwnedProduct, type Page, Platform, type PricingTier, type PricingVariation, type ProblemDetails, type ProductLineItem, type Quantifiable, type RawPropertyArray, type RawPropertyObject, type RawPropertyValue, type SignUpResult, type SingleOrMultiple, type Storefront, type StorefrontBundle, type StorefrontOffer, type StorefrontProduct, type SubscribeInput, type SubscribeResponse, type Subscription, SubscriptionStatus, type TaxEstimate, TokenStore, type UrchinTrackingModule, type User, type UserAccountConfirmed, type UserAccountConfirmedStatus, type Vendor, type Voucher, objectToQuery, parseOffSiteReferrer, problemDetailsSchema, resolveUtm, schemas, utmToObject };
package/dist/index.js CHANGED
@@ -105,7 +105,13 @@ var pricingVariationSchema = z.object({
105
105
  pricingTiers: z.array(pricingTierSchema).nullish()
106
106
  });
107
107
  var rawPropertyValueSchema = z.lazy(
108
- () => z.union([z.string(), z.number(), z.boolean(), z.record(rawPropertyValueSchema)])
108
+ () => z.union([
109
+ z.string(),
110
+ z.number(),
111
+ z.boolean(),
112
+ z.record(rawPropertyValueSchema),
113
+ z.array(rawPropertyValueSchema)
114
+ ])
109
115
  );
110
116
  function paged(itemSchema) {
111
117
  return z.object({
@@ -458,11 +464,11 @@ async function handleResponseProblem(response, logger) {
458
464
  throw new NotAuthorizedError();
459
465
  }
460
466
  let problemDetails;
467
+ const body = await response.text();
461
468
  try {
462
- const json = await response.json();
463
- problemDetails = problemDetailsSchema.parse(json);
469
+ problemDetails = problemDetailsSchema.parse(JSON.parse(body));
464
470
  } catch (err) {
465
- logger.warn("Could not handle response", { response, err, content: await response.text() });
471
+ logger.warn("Could not handle response", { response, err, content: body });
466
472
  throw new Error("An unknown problem occurred");
467
473
  }
468
474
  logger.debug("The response indicates a problem", problemDetails);
@@ -526,7 +532,8 @@ var connectionUrlSchema = z8.object({
526
532
  var userSchema = z8.object({
527
533
  id: z8.string(),
528
534
  email: z8.string(),
529
- name: z8.string(),
535
+ // Nullable: customers created via import may have no name.
536
+ name: z8.string().nullable(),
530
537
  tenantId: z8.string(),
531
538
  address: addressSchema.optional(),
532
539
  phone: z8.string().optional(),
@@ -855,6 +862,9 @@ var ProductEndpoints = class {
855
862
  }
856
863
  };
857
864
 
865
+ // src/inventory/subscriptions/endpoints.ts
866
+ import { z as z14 } from "zod";
867
+
858
868
  // src/utils/api.ts
859
869
  function objectToQuery(obj) {
860
870
  return Object.entries(obj != null ? obj : {}).filter(([_, value]) => value !== void 0).map(([key, value]) => `${key}=${encodeURIComponent(value instanceof Date ? value.toISOString() : value)}`).join("&");
@@ -980,9 +990,6 @@ var MoonbaseApi = class {
980
990
  }
981
991
  };
982
992
 
983
- // src/inventory/subscriptions/endpoints.ts
984
- import { z as z14 } from "zod";
985
-
986
993
  // src/inventory/subscriptions/schemas.ts
987
994
  var schemas_exports8 = {};
988
995
  __export(schemas_exports8, {
@@ -991,15 +998,6 @@ __export(schemas_exports8, {
991
998
  });
992
999
  import { z as z13 } from "zod";
993
1000
 
994
- // src/inventory/subscriptions/models.ts
995
- var SubscriptionStatus = /* @__PURE__ */ ((SubscriptionStatus2) => {
996
- SubscriptionStatus2["Active"] = "Active";
997
- SubscriptionStatus2["Expired"] = "Expired";
998
- SubscriptionStatus2["Cancelled"] = "Cancelled";
999
- SubscriptionStatus2["Completed"] = "Completed";
1000
- return SubscriptionStatus2;
1001
- })(SubscriptionStatus || {});
1002
-
1003
1001
  // src/orders/schemas.ts
1004
1002
  var schemas_exports7 = {};
1005
1003
  __export(schemas_exports7, {
@@ -1136,6 +1134,15 @@ var orderSchema = z12.discriminatedUnion("status", [
1136
1134
  completedOrderSchema
1137
1135
  ]);
1138
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
+
1139
1146
  // src/inventory/subscriptions/schemas.ts
1140
1147
  var baseMilestoneProgressEventSchema = z13.object({
1141
1148
  milestoneId: z13.string(),
@@ -1311,6 +1318,36 @@ var StorefrontEndpoints = class {
1311
1318
  }
1312
1319
  };
1313
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
+
1314
1351
  // src/utils/store.ts
1315
1352
  var LocalStorageStore = class {
1316
1353
  get(key) {
@@ -1358,7 +1395,8 @@ var InMemoryStore = class {
1358
1395
  }
1359
1396
  }
1360
1397
  listen(key, callback) {
1361
- if (!this.listeners[key]) this.listeners[key] = [];
1398
+ if (!this.listeners[key])
1399
+ this.listeners[key] = [];
1362
1400
  this.listeners[key].push(callback);
1363
1401
  }
1364
1402
  };
@@ -1402,7 +1440,8 @@ var _TokenStore = class _TokenStore {
1402
1440
  setUser(user) {
1403
1441
  const identity = user;
1404
1442
  if (!identity.accessToken || !identity.refreshToken) {
1405
- if (!this.tokens) return null;
1443
+ if (!this.tokens)
1444
+ return null;
1406
1445
  this.tokens = {
1407
1446
  ...user,
1408
1447
  accessToken: this.tokens.accessToken,
@@ -1532,32 +1571,6 @@ var VoucherEndpoints = class {
1532
1571
  }
1533
1572
  };
1534
1573
 
1535
- // src/utils/logger.ts
1536
- var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
1537
- LogLevel2[LogLevel2["Debug"] = 0] = "Debug";
1538
- LogLevel2[LogLevel2["Information"] = 1] = "Information";
1539
- LogLevel2[LogLevel2["Warn"] = 2] = "Warn";
1540
- LogLevel2[LogLevel2["Error"] = 3] = "Error";
1541
- return LogLevel2;
1542
- })(LogLevel || {});
1543
- var ConsoleLogger = class {
1544
- constructor(level = 2 /* Warn */) {
1545
- this.level = level;
1546
- }
1547
- debug(message, ...optionalParams) {
1548
- if (this.level <= 0 /* Debug */) console.debug(message, ...optionalParams);
1549
- }
1550
- log(message, ...optionalParams) {
1551
- if (this.level <= 1 /* Information */) console.log(message, ...optionalParams);
1552
- }
1553
- warn(message, ...optionalParams) {
1554
- if (this.level <= 2 /* Warn */) console.warn(message, ...optionalParams);
1555
- }
1556
- error(message, ...optionalParams) {
1557
- if (this.level <= 3 /* Error */) console.error(message, ...optionalParams);
1558
- }
1559
- };
1560
-
1561
1574
  // src/schemas.ts
1562
1575
  var schemas_exports12 = {};
1563
1576
  __export(schemas_exports12, {
@@ -1608,7 +1621,7 @@ var MoneyCollectionUtils = class {
1608
1621
  var OfferUtils = class _OfferUtils {
1609
1622
  static eligible(offer, order) {
1610
1623
  switch (offer.condition.type) {
1611
- case "CartContainsItems":
1624
+ case "CartContainsItems": {
1612
1625
  const relevantItems = order.items.filter(
1613
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)
1614
1627
  );
@@ -1620,6 +1633,7 @@ var OfferUtils = class _OfferUtils {
1620
1633
  return offer.condition.relevantItemVariations[`Product/${productId}`] && offer.condition.relevantItemVariations[`Product/${productId}`].includes(variationId);
1621
1634
  });
1622
1635
  return relevantItems.length + relevantReplacedItems.length >= offer.condition.minimumItems;
1636
+ }
1623
1637
  }
1624
1638
  console.warn("Unsupported offer condition found:", offer.condition);
1625
1639
  return false;
@@ -1643,7 +1657,8 @@ var OfferUtils = class _OfferUtils {
1643
1657
  };
1644
1658
  }
1645
1659
  static targetContainsBundle(offer, bundleId) {
1646
- 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);
1647
1662
  }
1648
1663
  };
1649
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.2.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
  }