@01.software/sdk 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +214 -22
  2. package/dist/analytics/react.cjs.map +1 -1
  3. package/dist/analytics/react.js.map +1 -1
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.js.map +1 -1
  6. package/dist/client.cjs +341 -26
  7. package/dist/client.cjs.map +1 -1
  8. package/dist/client.d.cts +7 -6
  9. package/dist/client.d.ts +7 -6
  10. package/dist/client.js +341 -26
  11. package/dist/client.js.map +1 -1
  12. package/dist/{collection-client-De6eKW1J.d.cts → collection-client-CR2B8c1v.d.cts} +7 -3
  13. package/dist/{collection-client-B6SlhzIP.d.ts → collection-client-DkREjhQ9.d.ts} +7 -3
  14. package/dist/{const-sPR2IkCe.d.cts → const-BTvdrXtY.d.cts} +4 -4
  15. package/dist/{const-DwmSDeWq.d.ts → const-CdqCauHQ.d.ts} +4 -4
  16. package/dist/index-CjA3U6X3.d.cts +186 -0
  17. package/dist/index-DK8_NXkh.d.ts +186 -0
  18. package/dist/index.cjs +1401 -176
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +74 -9
  21. package/dist/index.d.ts +74 -9
  22. package/dist/index.js +1401 -176
  23. package/dist/index.js.map +1 -1
  24. package/dist/{payload-types-dkeQyrDC.d.cts → payload-types-C7tb7Xbs.d.cts} +208 -52
  25. package/dist/{payload-types-dkeQyrDC.d.ts → payload-types-C7tb7Xbs.d.ts} +208 -52
  26. package/dist/query.cjs +194 -35
  27. package/dist/query.cjs.map +1 -1
  28. package/dist/query.d.cts +44 -17
  29. package/dist/query.d.ts +44 -17
  30. package/dist/query.js +194 -35
  31. package/dist/query.js.map +1 -1
  32. package/dist/realtime.cjs.map +1 -1
  33. package/dist/realtime.d.cts +2 -2
  34. package/dist/realtime.d.ts +2 -2
  35. package/dist/realtime.js.map +1 -1
  36. package/dist/{server-CrsPyqEc.d.cts → server-nXOezi4b.d.cts} +22 -6
  37. package/dist/{server-CrsPyqEc.d.ts → server-nXOezi4b.d.ts} +22 -6
  38. package/dist/server.cjs +439 -32
  39. package/dist/server.cjs.map +1 -1
  40. package/dist/server.d.cts +11 -179
  41. package/dist/server.d.ts +11 -179
  42. package/dist/server.js +439 -32
  43. package/dist/server.js.map +1 -1
  44. package/dist/{types-Cel_4L9t.d.ts → types-1ylMrCuW.d.ts} +1 -1
  45. package/dist/{types-B3YT092I.d.cts → types-Bx558PU6.d.cts} +1 -1
  46. package/dist/{types-BHh0YLmq.d.ts → types-Byo_Rty4.d.ts} +705 -69
  47. package/dist/{types-BZKxss8Y.d.cts → types-DDhtZI6E.d.cts} +705 -69
  48. package/dist/ui/canvas/server.cjs +231 -38
  49. package/dist/ui/canvas/server.cjs.map +1 -1
  50. package/dist/ui/canvas/server.d.cts +1 -1
  51. package/dist/ui/canvas/server.d.ts +1 -1
  52. package/dist/ui/canvas/server.js +221 -38
  53. package/dist/ui/canvas/server.js.map +1 -1
  54. package/dist/ui/canvas.cjs +320 -257
  55. package/dist/ui/canvas.cjs.map +1 -1
  56. package/dist/ui/canvas.d.cts +5 -19
  57. package/dist/ui/canvas.d.ts +5 -19
  58. package/dist/ui/canvas.js +323 -260
  59. package/dist/ui/canvas.js.map +1 -1
  60. package/dist/ui/form.d.cts +1 -1
  61. package/dist/ui/form.d.ts +1 -1
  62. package/dist/ui/video.d.cts +1 -1
  63. package/dist/ui/video.d.ts +1 -1
  64. package/dist/webhook.cjs +2 -1
  65. package/dist/webhook.cjs.map +1 -1
  66. package/dist/webhook.d.cts +20 -179
  67. package/dist/webhook.d.ts +20 -179
  68. package/dist/webhook.js +2 -1
  69. package/dist/webhook.js.map +1 -1
  70. package/package.json +4 -5
package/dist/client.d.cts CHANGED
@@ -1,14 +1,15 @@
1
- import { R as ReadOnlyCollectionClient } from './collection-client-De6eKW1J.cjs';
2
- import { C as CommerceClient, a as CommunityClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-BZKxss8Y.cjs';
3
- export { A as ApiQueryOptions, e as ClientMetadata, D as DebugConfig, f as DeepPartial, E as ExtractArrayType, P as PayloadFindResponse, g as PayloadMutationResponse, R as RetryConfig, h as RootClient, h as RootClientType, i as RootCollectionClient, j as RootReadOnlyQueryBuilder, S as Sort, W as Where } from './types-BZKxss8Y.cjs';
4
- export { C as Collection, P as PublicCollection } from './const-sPR2IkCe.cjs';
1
+ import { R as ReadOnlyCollectionClient } from './collection-client-CR2B8c1v.cjs';
2
+ import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-DDhtZI6E.cjs';
3
+ export { A as ApiQueryOptions, e as ClientMetadata, D as DebugConfig, f as DeepPartial, g as ExtractArrayType, P as PayloadFindResponse, h as PayloadMutationResponse, R as RetryConfig, i as RootClient, i as RootClientType, j as RootCollectionClient, k as RootReadOnlyQueryBuilder, S as Sort, W as Where } from './types-DDhtZI6E.cjs';
4
+ export { C as Collection, P as PublicCollection } from './const-BTvdrXtY.cjs';
5
5
  import './metadata.cjs';
6
- import './types-B3YT092I.cjs';
7
- import './payload-types-dkeQyrDC.cjs';
6
+ import './types-Bx558PU6.cjs';
7
+ import './payload-types-C7tb7Xbs.cjs';
8
8
 
9
9
  declare class Client {
10
10
  commerce: CommerceClient;
11
11
  community: CommunityClient;
12
+ events: EventsClient;
12
13
  customer: CustomerNamespace;
13
14
  collections: ReadOnlyCollectionClient;
14
15
  lastRequestId: string | null;
package/dist/client.d.ts CHANGED
@@ -1,14 +1,15 @@
1
- import { R as ReadOnlyCollectionClient } from './collection-client-B6SlhzIP.js';
2
- import { C as CommerceClient, a as CommunityClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-BHh0YLmq.js';
3
- export { A as ApiQueryOptions, e as ClientMetadata, D as DebugConfig, f as DeepPartial, E as ExtractArrayType, P as PayloadFindResponse, g as PayloadMutationResponse, R as RetryConfig, h as RootClient, h as RootClientType, i as RootCollectionClient, j as RootReadOnlyQueryBuilder, S as Sort, W as Where } from './types-BHh0YLmq.js';
4
- export { C as Collection, P as PublicCollection } from './const-DwmSDeWq.js';
1
+ import { R as ReadOnlyCollectionClient } from './collection-client-DkREjhQ9.js';
2
+ import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-Byo_Rty4.js';
3
+ export { A as ApiQueryOptions, e as ClientMetadata, D as DebugConfig, f as DeepPartial, g as ExtractArrayType, P as PayloadFindResponse, h as PayloadMutationResponse, R as RetryConfig, i as RootClient, i as RootClientType, j as RootCollectionClient, k as RootReadOnlyQueryBuilder, S as Sort, W as Where } from './types-Byo_Rty4.js';
4
+ export { C as Collection, P as PublicCollection } from './const-CdqCauHQ.js';
5
5
  import './metadata.js';
6
- import './types-Cel_4L9t.js';
7
- import './payload-types-dkeQyrDC.js';
6
+ import './types-1ylMrCuW.js';
7
+ import './payload-types-C7tb7Xbs.js';
8
8
 
9
9
  declare class Client {
10
10
  commerce: CommerceClient;
11
11
  community: CommunityClient;
12
+ events: EventsClient;
12
13
  customer: CustomerNamespace;
13
14
  collections: ReadOnlyCollectionClient;
14
15
  lastRequestId: string | null;
package/dist/client.js CHANGED
@@ -191,9 +191,12 @@ function resolveApiUrl(apiUrl) {
191
191
 
192
192
  // src/core/internal/utils/http.ts
193
193
  var DEFAULT_TIMEOUT = 3e4;
194
+ var STOREFRONT_BROWSER_TIMEOUT = 15e3;
194
195
  var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
195
196
  var NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
196
197
  var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
198
+ var DEFAULT_MAX_RETRIES = 3;
199
+ var STOREFRONT_BROWSER_MAX_RETRIES = 1;
197
200
  function debugLog(debug, type, message, data) {
198
201
  if (!debug) return;
199
202
  const shouldLog = debug === true || type === "request" && debug.logRequests || type === "response" && debug.logResponses || type === "error" && debug.logErrors;
@@ -386,15 +389,18 @@ async function httpFetch(url, options) {
386
389
  publishableKey,
387
390
  secretKey,
388
391
  customerToken,
389
- timeout = DEFAULT_TIMEOUT,
392
+ timeout: timeoutOption = DEFAULT_TIMEOUT,
390
393
  debug,
391
394
  retry,
392
395
  onUnauthorized,
393
396
  ...requestInit
394
397
  } = options || {};
395
398
  const baseUrl = resolveApiUrl(apiUrl);
399
+ const method = (requestInit.method || "GET").toUpperCase();
400
+ const isPublishableKeyBrowserGet = typeof window !== "undefined" && !secretKey && !customerToken && Boolean(publishableKey) && SAFE_METHODS.includes(method);
401
+ const timeout = timeoutOption === DEFAULT_TIMEOUT && isPublishableKeyBrowserGet ? STOREFRONT_BROWSER_TIMEOUT : timeoutOption;
396
402
  const retryConfig = {
397
- maxRetries: retry?.maxRetries ?? 3,
403
+ maxRetries: retry?.maxRetries ?? (isPublishableKeyBrowserGet ? STOREFRONT_BROWSER_MAX_RETRIES : DEFAULT_MAX_RETRIES),
398
404
  retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
399
405
  retryDelay: retry?.retryDelay ?? ((attempt) => Math.min(1e3 * 2 ** attempt, 1e4))
400
406
  };
@@ -502,8 +508,8 @@ async function httpFetch(url, options) {
502
508
  ),
503
509
  requestId
504
510
  );
505
- const method = (requestInit.method || "GET").toUpperCase();
506
- if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method) && retryConfig.retryableStatuses.includes(response.status)) {
511
+ const method2 = (requestInit.method || "GET").toUpperCase();
512
+ if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && retryConfig.retryableStatuses.includes(response.status)) {
507
513
  lastError = error;
508
514
  const retryDelay = retryConfig.retryDelay(attempt);
509
515
  debugLog(debug, "error", `Retrying in ${retryDelay}ms...`, error);
@@ -515,8 +521,8 @@ async function httpFetch(url, options) {
515
521
  return response;
516
522
  } catch (error) {
517
523
  debugLog(debug, "error", url, error);
518
- const method = (requestInit.method || "GET").toUpperCase();
519
- const isSafe = SAFE_METHODS.includes(method);
524
+ const method2 = (requestInit.method || "GET").toUpperCase();
525
+ const isSafe = SAFE_METHODS.includes(method2);
520
526
  if (error instanceof Error && error.name === "AbortError") {
521
527
  const timeoutError = createTimeoutError(
522
528
  `Request timed out after ${timeout}ms.`,
@@ -575,6 +581,35 @@ async function httpFetch(url, options) {
575
581
  throw lastError ?? new NetworkError("Request failed after retries");
576
582
  }
577
583
 
584
+ // src/core/internal/utils/query-string.ts
585
+ function productDetailQuery(params) {
586
+ const search = new URLSearchParams();
587
+ if ("slug" in params) {
588
+ search.set("slug", params.slug);
589
+ } else {
590
+ search.set("id", params.id);
591
+ }
592
+ return `/api/products/detail?${search}`;
593
+ }
594
+ function productDetailCatalogQuery(params) {
595
+ const search = new URLSearchParams();
596
+ if ("slug" in params) {
597
+ search.set("slug", params.slug);
598
+ } else {
599
+ search.set("id", params.id);
600
+ }
601
+ return `/api/products/detail/catalog?${search}`;
602
+ }
603
+ function listingGroupsQuery(params) {
604
+ return `/api/products/listing-groups?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
605
+ }
606
+ function listingGroupsCatalogQuery(params) {
607
+ return `/api/products/listing-groups/catalog?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
608
+ }
609
+ function stockSnapshotQuery(params) {
610
+ return `/api/products/stock?variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
611
+ }
612
+
578
613
  // src/core/collection/http-client.ts
579
614
  var HttpClient = class {
580
615
  constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
@@ -893,6 +928,8 @@ async function parseApiResponse(response, endpoint) {
893
928
  }
894
929
 
895
930
  // src/core/community/community-client.ts
931
+ var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
932
+ var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
896
933
  var CommunityClient = class {
897
934
  constructor(options) {
898
935
  this.publishableKey = requirePublishableKeyForSecret(
@@ -911,6 +948,40 @@ var CommunityClient = class {
911
948
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
912
949
  return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
913
950
  }
951
+ buildPostsListQuery(params) {
952
+ const urlParams = new URLSearchParams();
953
+ const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
954
+ urlParams.set("sort", sort);
955
+ if (params?.limit !== void 0) urlParams.set("limit", String(params.limit));
956
+ if (params?.page !== void 0) urlParams.set("page", String(params.page));
957
+ if (params?.categoryId !== void 0) {
958
+ urlParams.set("where[categories][in]", params.categoryId);
959
+ }
960
+ if (params?.tagId !== void 0) {
961
+ urlParams.set("where[tags][in]", params.tagId);
962
+ }
963
+ return `/api/posts?${urlParams.toString()}`;
964
+ }
965
+ buildCommentsListQuery(params) {
966
+ const urlParams = new URLSearchParams();
967
+ const sort = params.sort ?? DEFAULT_COMMENT_LIST_SORT;
968
+ urlParams.set("sort", sort);
969
+ if (params.postId !== void 0) {
970
+ urlParams.set("where[post][equals]", params.postId);
971
+ }
972
+ if (params.parentId !== void 0) {
973
+ urlParams.set("where[parent][equals]", params.parentId);
974
+ }
975
+ if (params.rootComment !== void 0) {
976
+ urlParams.set("where[rootComment][equals]", params.rootComment);
977
+ }
978
+ if (params.topLevelOnly) {
979
+ urlParams.set("where[parent][exists]", "false");
980
+ }
981
+ if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
982
+ if (params.page !== void 0) urlParams.set("page", String(params.page));
983
+ return `/api/comments?${urlParams.toString()}`;
984
+ }
914
985
  async execute(endpoint, method, body) {
915
986
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
916
987
  try {
@@ -934,6 +1005,28 @@ var CommunityClient = class {
934
1005
  createPost(params) {
935
1006
  return this.execute("/api/posts", "POST", params);
936
1007
  }
1008
+ /**
1009
+ * Public post feed. Server applies the same visibility contract as
1010
+ * `communityPostRead` (published + visible + moderation-safe).
1011
+ */
1012
+ listPosts(params) {
1013
+ return this.execute(
1014
+ this.buildPostsListQuery(params),
1015
+ "GET"
1016
+ );
1017
+ }
1018
+ listPostCategories(params) {
1019
+ return this.execute(
1020
+ `/api/post-categories${this.buildQuery(params)}`,
1021
+ "GET"
1022
+ );
1023
+ }
1024
+ listPostTags(params) {
1025
+ return this.execute(
1026
+ `/api/post-tags${this.buildQuery(params)}`,
1027
+ "GET"
1028
+ );
1029
+ }
937
1030
  getMyPosts(params) {
938
1031
  return this.execute(
939
1032
  `/api/posts/my${this.buildQuery(params)}`,
@@ -969,16 +1062,37 @@ var CommunityClient = class {
969
1062
  }
970
1063
  return this.execute("/api/comments", "POST", body);
971
1064
  }
1065
+ /**
1066
+ * List comments for a post.
1067
+ *
1068
+ * - Default: all visible comments on the post (any depth).
1069
+ * - `topLevelOnly: true`: only root comments (`parent` unset).
1070
+ * - `rootComment`: comments belonging to a thread rooted at that comment.
1071
+ */
972
1072
  listComments(params) {
973
- const { postId, page, limit, rootComment } = params;
974
- const urlParams = new URLSearchParams();
975
- urlParams.set("where[post][equals]", postId);
976
- urlParams.set("sort", "-createdAt");
977
- if (limit !== void 0) urlParams.set("limit", String(limit));
978
- if (page !== void 0) urlParams.set("page", String(page));
979
- if (rootComment !== void 0) urlParams.set("where[rootComment][equals]", rootComment);
1073
+ const { postId, page, limit, rootComment, topLevelOnly, sort } = params;
1074
+ return this.execute(
1075
+ this.buildCommentsListQuery({
1076
+ postId,
1077
+ page,
1078
+ limit,
1079
+ rootComment,
1080
+ topLevelOnly,
1081
+ sort
1082
+ }),
1083
+ "GET"
1084
+ );
1085
+ }
1086
+ /** Direct replies to a comment (`where[parent][equals]`). */
1087
+ listReplies(params) {
1088
+ const { commentId, page, limit, sort } = params;
980
1089
  return this.execute(
981
- `/api/comments?${urlParams.toString()}`,
1090
+ this.buildCommentsListQuery({
1091
+ parentId: commentId,
1092
+ page,
1093
+ limit,
1094
+ sort
1095
+ }),
982
1096
  "GET"
983
1097
  );
984
1098
  }
@@ -1006,10 +1120,18 @@ var CommunityClient = class {
1006
1120
  }
1007
1121
  // Reactions
1008
1122
  addReaction(params) {
1009
- const { postId, type } = params;
1123
+ const { postId, typeSlug, type } = params;
1124
+ const reactionType = typeSlug ?? type;
1125
+ if (!reactionType) {
1126
+ throw new SDKError(
1127
+ "validation_failed",
1128
+ "addReaction requires typeSlug (or deprecated type)",
1129
+ 400
1130
+ );
1131
+ }
1010
1132
  return this.execute("/api/reactions", "POST", {
1011
1133
  post: postId,
1012
- type
1134
+ type: reactionType
1013
1135
  });
1014
1136
  }
1015
1137
  removeReaction(params) {
@@ -1020,10 +1142,18 @@ var CommunityClient = class {
1020
1142
  );
1021
1143
  }
1022
1144
  addCommentReaction(params) {
1023
- const { commentId, type } = params;
1145
+ const { commentId, typeSlug, type } = params;
1146
+ const reactionType = typeSlug ?? type;
1147
+ if (!reactionType) {
1148
+ throw new SDKError(
1149
+ "validation_failed",
1150
+ "addCommentReaction requires typeSlug (or deprecated type)",
1151
+ 400
1152
+ );
1153
+ }
1024
1154
  return this.execute("/api/reactions", "POST", {
1025
1155
  comment: commentId,
1026
- type
1156
+ type: reactionType
1027
1157
  });
1028
1158
  }
1029
1159
  removeCommentReaction(params) {
@@ -1039,6 +1169,12 @@ var CommunityClient = class {
1039
1169
  "GET"
1040
1170
  );
1041
1171
  }
1172
+ getCommentReactionSummary(params) {
1173
+ return this.execute(
1174
+ `/api/comments/${params.commentId}/reactions`,
1175
+ "GET"
1176
+ );
1177
+ }
1042
1178
  getReactionTypes() {
1043
1179
  return this.execute(
1044
1180
  "/api/reaction-types?limit=100",
@@ -1063,6 +1199,25 @@ var CommunityClient = class {
1063
1199
  "GET"
1064
1200
  );
1065
1201
  }
1202
+ // Profiles
1203
+ listProfileLists(params) {
1204
+ return this.execute(
1205
+ `/api/customer-profile-lists${this.buildQuery(params)}`,
1206
+ "GET"
1207
+ );
1208
+ }
1209
+ async getProfileList(params) {
1210
+ const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
1211
+ const res = await this.execute(`/api/customer-profile-lists${query}`, "GET");
1212
+ return res.docs[0] ?? null;
1213
+ }
1214
+ updatePublicProfile(body) {
1215
+ return this.execute(
1216
+ "/api/customers/me/profile",
1217
+ "PATCH",
1218
+ body
1219
+ );
1220
+ }
1066
1221
  };
1067
1222
 
1068
1223
  // src/core/customer/customer-auth.ts
@@ -1372,6 +1527,15 @@ function productDetailResultFromError(error) {
1372
1527
  return { found: false, reason };
1373
1528
  }
1374
1529
 
1530
+ // src/core/api/order-api.ts
1531
+ function idempotencyRequestOptions(idempotencyKey) {
1532
+ return idempotencyKey ? { headers: { "X-Idempotency-Key": idempotencyKey } } : void 0;
1533
+ }
1534
+ function splitIdempotencyKey(params) {
1535
+ const { idempotencyKey, ...body } = params;
1536
+ return { body, idempotencyKey };
1537
+ }
1538
+
1375
1539
  // src/core/commerce/commerce-client.ts
1376
1540
  var CommerceClient = class {
1377
1541
  constructor(options) {
@@ -1382,7 +1546,7 @@ var CommerceClient = class {
1382
1546
  onUnauthorized: options.onUnauthorized,
1383
1547
  onRequestId: options.onRequestId
1384
1548
  });
1385
- const execute = async (endpoint, body) => {
1549
+ const execute = async (endpoint, body, requestOptions) => {
1386
1550
  const token = options.customerToken();
1387
1551
  try {
1388
1552
  const response = await httpFetch(endpoint, {
@@ -1391,7 +1555,26 @@ var CommerceClient = class {
1391
1555
  publishableKey: options.publishableKey,
1392
1556
  customerToken: token ?? void 0,
1393
1557
  ...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized },
1394
- body: JSON.stringify(body)
1558
+ body: JSON.stringify(body),
1559
+ ...requestOptions?.headers && { headers: requestOptions.headers }
1560
+ });
1561
+ options.onRequestId?.(response.headers.get("x-request-id") ?? null);
1562
+ return parseApiResponse(response, endpoint);
1563
+ } catch (err) {
1564
+ const id = err instanceof SDKError ? err.requestId ?? null : null;
1565
+ options.onRequestId?.(id);
1566
+ throw err;
1567
+ }
1568
+ };
1569
+ const executeGet = async (endpoint) => {
1570
+ const token = options.customerToken();
1571
+ try {
1572
+ const response = await httpFetch(endpoint, {
1573
+ method: "GET",
1574
+ apiUrl: options.apiUrl,
1575
+ publishableKey: options.publishableKey,
1576
+ customerToken: token ?? void 0,
1577
+ ...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized }
1395
1578
  });
1396
1579
  options.onRequestId?.(response.headers.get("x-request-id") ?? null);
1397
1580
  return parseApiResponse(response, endpoint);
@@ -1403,19 +1586,30 @@ var CommerceClient = class {
1403
1586
  };
1404
1587
  this.product = {
1405
1588
  stockCheck: (params) => execute("/api/products/stock-check", params),
1406
- listingGroups: (params) => execute("/api/products/listing-groups", params),
1589
+ stockSnapshot: (params) => executeGet(stockSnapshotQuery(params)),
1590
+ listingGroups: (params) => executeGet(listingGroupsQuery(params)),
1591
+ listingGroupsCatalog: (params) => executeGet(listingGroupsCatalogQuery(params)),
1407
1592
  detail: async (params) => {
1408
1593
  try {
1409
- const product = await execute(
1410
- "/api/products/detail",
1411
- params
1412
- );
1594
+ const product = await executeGet(productDetailQuery(params));
1413
1595
  return { found: true, product };
1414
1596
  } catch (err) {
1415
1597
  const notFoundResult = productDetailResultFromError(err);
1416
1598
  if (notFoundResult) return notFoundResult;
1417
1599
  throw err;
1418
1600
  }
1601
+ },
1602
+ detailCatalog: async (params) => {
1603
+ try {
1604
+ const product = await executeGet(
1605
+ productDetailCatalogQuery(params)
1606
+ );
1607
+ return { found: true, product };
1608
+ } catch (err) {
1609
+ const notFoundResult = productDetailResultFromError(err);
1610
+ if (notFoundResult?.found === false) return notFoundResult;
1611
+ throw err;
1612
+ }
1419
1613
  }
1420
1614
  };
1421
1615
  this.cart = {
@@ -1428,7 +1622,14 @@ var CommerceClient = class {
1428
1622
  clear: cartApi.clearCart.bind(cartApi)
1429
1623
  };
1430
1624
  this.orders = {
1431
- checkout: (params) => execute("/api/orders/checkout", params),
1625
+ checkout: (params) => {
1626
+ const { body, idempotencyKey } = splitIdempotencyKey(params);
1627
+ return execute(
1628
+ "/api/orders/checkout",
1629
+ body,
1630
+ idempotencyRequestOptions(idempotencyKey)
1631
+ );
1632
+ },
1432
1633
  listMine: (params) => options.customerAuth.getMyOrders(params)
1433
1634
  };
1434
1635
  this.discounts = {
@@ -1440,6 +1641,113 @@ var CommerceClient = class {
1440
1641
  }
1441
1642
  };
1442
1643
 
1644
+ // src/core/events/events-client.ts
1645
+ var EventsClient = class {
1646
+ constructor(options) {
1647
+ const secretKey = options.secretKey;
1648
+ this.publishableKey = requirePublishableKeyForSecret(
1649
+ "EventsClient",
1650
+ options.publishableKey,
1651
+ secretKey
1652
+ );
1653
+ this.apiUrl = options.apiUrl;
1654
+ this.customerToken = options.customerToken;
1655
+ this.onUnauthorized = options.onUnauthorized;
1656
+ this.onRequestId = options.onRequestId;
1657
+ }
1658
+ getRange(params) {
1659
+ return this.execute(
1660
+ buildRangeEndpoint(params),
1661
+ "GET",
1662
+ void 0,
1663
+ { useCustomerAuth: false }
1664
+ );
1665
+ }
1666
+ register(params) {
1667
+ return this.execute(
1668
+ "/api/event-registrations/register",
1669
+ "POST",
1670
+ buildRegistrationRequestBody(params),
1671
+ { useCustomerAuth: true }
1672
+ );
1673
+ }
1674
+ getGuestRegistration(token) {
1675
+ return this.execute(
1676
+ "/api/event-registrations/guest/lookup",
1677
+ "POST",
1678
+ { token },
1679
+ { useCustomerAuth: false }
1680
+ );
1681
+ }
1682
+ cancelGuestRegistration(token, params = {}) {
1683
+ return this.execute(
1684
+ "/api/event-registrations/guest/cancel",
1685
+ "POST",
1686
+ buildGuestCancelRequestBody(token, params),
1687
+ { useCustomerAuth: false }
1688
+ );
1689
+ }
1690
+ async execute(endpoint, method, body, options = {}) {
1691
+ const useCustomerAuth = options.useCustomerAuth === true;
1692
+ const token = useCustomerAuth ? typeof this.customerToken === "function" ? this.customerToken() : this.customerToken : void 0;
1693
+ try {
1694
+ const response = await httpFetch(endpoint, {
1695
+ method,
1696
+ apiUrl: this.apiUrl,
1697
+ publishableKey: this.publishableKey,
1698
+ ...useCustomerAuth && token ? { customerToken: token } : {},
1699
+ ...useCustomerAuth && token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1700
+ ...body !== void 0 && { body: JSON.stringify(body) }
1701
+ });
1702
+ this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1703
+ return parseApiResponse(response, endpoint);
1704
+ } catch (err) {
1705
+ const id = err instanceof SDKError ? err.requestId ?? null : null;
1706
+ this.onRequestId?.(id);
1707
+ throw err;
1708
+ }
1709
+ }
1710
+ };
1711
+ function buildRegistrationRequestBody(params) {
1712
+ return {
1713
+ event: params.event,
1714
+ occurrence: params.occurrence,
1715
+ ...params.quantity !== void 0 && { quantity: params.quantity },
1716
+ ...params.attendee !== void 0 && { attendee: params.attendee },
1717
+ ...params.answers !== void 0 && { answers: params.answers }
1718
+ };
1719
+ }
1720
+ function buildGuestCancelRequestBody(token, params) {
1721
+ return {
1722
+ token,
1723
+ ...params.reason !== void 0 && { reason: params.reason }
1724
+ };
1725
+ }
1726
+ function buildRangeEndpoint(params) {
1727
+ const urlParams = new URLSearchParams();
1728
+ urlParams.set("start", formatDateParam(params.start));
1729
+ urlParams.set("end", formatDateParam(params.end));
1730
+ if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
1731
+ if (params.page !== void 0) urlParams.set("page", String(params.page));
1732
+ appendValues(urlParams, "calendar", params.calendar);
1733
+ appendValues(urlParams, "calendarSlug", params.calendarSlug);
1734
+ appendValues(urlParams, "category", params.category);
1735
+ appendValues(urlParams, "categorySlug", params.categorySlug);
1736
+ appendValues(urlParams, "tag", params.tag);
1737
+ appendValues(urlParams, "tagSlug", params.tagSlug);
1738
+ return `/api/event-occurrences/range?${urlParams.toString()}`;
1739
+ }
1740
+ function formatDateParam(value) {
1741
+ return value instanceof Date ? value.toISOString() : value;
1742
+ }
1743
+ function appendValues(params, key, value) {
1744
+ if (value === void 0) return;
1745
+ const values = Array.isArray(value) ? value : [value];
1746
+ for (const entry of values) {
1747
+ if (entry) params.append(key, entry);
1748
+ }
1749
+ }
1750
+
1443
1751
  // src/core/client/client.ts
1444
1752
  var Client = class {
1445
1753
  constructor(options) {
@@ -1485,6 +1793,13 @@ var Client = class {
1485
1793
  onUnauthorized,
1486
1794
  onRequestId
1487
1795
  });
1796
+ this.events = new EventsClient({
1797
+ publishableKey: this.config.publishableKey,
1798
+ apiUrl: this.config.apiUrl,
1799
+ customerToken: () => this.customer.auth.getToken(),
1800
+ onUnauthorized,
1801
+ onRequestId
1802
+ });
1488
1803
  this.collections = new ReadOnlyCollectionClient(
1489
1804
  this.config.publishableKey,
1490
1805
  void 0,