@01.software/sdk 0.36.0 → 0.38.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 (82) hide show
  1. package/README.md +142 -55
  2. package/dist/analytics/react.cjs +33 -9
  3. package/dist/analytics/react.cjs.map +1 -1
  4. package/dist/analytics/react.d.cts +1 -1
  5. package/dist/analytics/react.d.ts +1 -1
  6. package/dist/analytics/react.js +33 -9
  7. package/dist/analytics/react.js.map +1 -1
  8. package/dist/analytics.cjs +30 -8
  9. package/dist/analytics.cjs.map +1 -1
  10. package/dist/analytics.d.cts +6 -0
  11. package/dist/analytics.d.ts +6 -0
  12. package/dist/analytics.js +30 -8
  13. package/dist/analytics.js.map +1 -1
  14. package/dist/client.cjs +150 -207
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.d.cts +6 -6
  17. package/dist/client.d.ts +6 -6
  18. package/dist/client.js +150 -207
  19. package/dist/client.js.map +1 -1
  20. package/dist/{collection-client-Cv0D2w1Q.d.cts → collection-client-B0J9wMNE.d.cts} +5 -5
  21. package/dist/{collection-client-Bq5Zd7p7.d.ts → collection-client-BroIWHY1.d.ts} +5 -5
  22. package/dist/const-6XHz_jej.d.ts +32 -0
  23. package/dist/const-B5KT72c7.d.cts +32 -0
  24. package/dist/{image-BDz2-AaO.d.cts → image-BDjHp03R.d.cts} +13 -9
  25. package/dist/{image-BDz2-AaO.d.ts → image-BDjHp03R.d.ts} +13 -9
  26. package/dist/{index-DTSXUYkr.d.ts → index-BOLQxveo.d.cts} +9 -6
  27. package/dist/{index-BHDKJ6B3.d.cts → index-CSwR2HSg.d.ts} +9 -6
  28. package/dist/index.cjs +256 -244
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +12 -11
  31. package/dist/index.d.ts +12 -11
  32. package/dist/index.js +256 -244
  33. package/dist/index.js.map +1 -1
  34. package/dist/metadata.cjs +5 -3
  35. package/dist/metadata.cjs.map +1 -1
  36. package/dist/metadata.js +5 -3
  37. package/dist/metadata.js.map +1 -1
  38. package/dist/{payload-types-BCui2Oml.d.cts → payload-types-m3jjhxk9.d.cts} +669 -184
  39. package/dist/{payload-types-BCui2Oml.d.ts → payload-types-m3jjhxk9.d.ts} +669 -184
  40. package/dist/query.cjs +3 -1033
  41. package/dist/query.cjs.map +1 -1
  42. package/dist/query.d.cts +13 -13
  43. package/dist/query.d.ts +13 -13
  44. package/dist/query.js +3 -1033
  45. package/dist/query.js.map +1 -1
  46. package/dist/realtime.d.cts +2 -2
  47. package/dist/realtime.d.ts +2 -2
  48. package/dist/server.cjs +121 -85
  49. package/dist/server.cjs.map +1 -1
  50. package/dist/server.d.cts +7 -7
  51. package/dist/server.d.ts +7 -7
  52. package/dist/server.js +121 -85
  53. package/dist/server.js.map +1 -1
  54. package/dist/{types-Dib-zdK6.d.cts → types-CIGscmus.d.cts} +1471 -1100
  55. package/dist/{types-3qV6sY7T.d.ts → types-Cmrd1ezc.d.ts} +1 -15
  56. package/dist/{types-CEzLf3PX.d.cts → types-D0ubzQw0.d.cts} +1 -15
  57. package/dist/{types-DK9EnLwJ.d.ts → types-D2xYdz4P.d.ts} +1471 -1100
  58. package/dist/ui/canvas.cjs +15 -5
  59. package/dist/ui/canvas.cjs.map +1 -1
  60. package/dist/ui/canvas.d.cts +1 -1
  61. package/dist/ui/canvas.d.ts +1 -1
  62. package/dist/ui/canvas.js +15 -5
  63. package/dist/ui/canvas.js.map +1 -1
  64. package/dist/ui/form.d.cts +1 -1
  65. package/dist/ui/form.d.ts +1 -1
  66. package/dist/ui/image.cjs +15 -5
  67. package/dist/ui/image.cjs.map +1 -1
  68. package/dist/ui/image.d.cts +1 -1
  69. package/dist/ui/image.d.ts +1 -1
  70. package/dist/ui/image.js +15 -5
  71. package/dist/ui/image.js.map +1 -1
  72. package/dist/ui/video.d.cts +1 -1
  73. package/dist/ui/video.d.ts +1 -1
  74. package/dist/webhook.cjs +5 -1
  75. package/dist/webhook.cjs.map +1 -1
  76. package/dist/webhook.d.cts +4 -4
  77. package/dist/webhook.d.ts +4 -4
  78. package/dist/webhook.js +5 -1
  79. package/dist/webhook.js.map +1 -1
  80. package/package.json +3 -3
  81. package/dist/const-BDUKFP9w.d.ts +0 -32
  82. package/dist/const-DVcM7Ac_.d.cts +0 -32
package/dist/index.js CHANGED
@@ -807,70 +807,20 @@ var HttpClient = class {
807
807
  };
808
808
 
809
809
  // src/utils/types.ts
810
- var resolveRelation = (ref) => {
810
+ function resolveRelation(ref) {
811
811
  if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
812
812
  return null;
813
813
  return ref;
814
- };
815
-
816
- // src/core/metadata/index.ts
817
- function extractSeo(doc) {
818
- const seo = doc.seo ?? {};
819
- const og = seo.openGraph ?? {};
820
- return {
821
- title: seo.title ?? doc.title ?? null,
822
- description: seo.description ?? null,
823
- noIndex: seo.noIndex ?? null,
824
- canonical: seo.canonical ?? null,
825
- openGraph: {
826
- title: og.title ?? null,
827
- description: og.description ?? null,
828
- image: og.image ?? null
829
- }
830
- };
831
- }
832
- function generateMetadata(input, options) {
833
- const title = input.title ?? void 0;
834
- const description = input.description ?? void 0;
835
- const ogTitle = input.openGraph?.title ?? title;
836
- const ogDescription = input.openGraph?.description ?? description;
837
- const image = resolveMetaImage(input.openGraph?.image);
838
- return {
839
- title,
840
- description,
841
- ...input.noIndex && { robots: { index: false, follow: false } },
842
- ...input.canonical && { alternates: { canonical: input.canonical } },
843
- openGraph: {
844
- ...ogTitle && { title: ogTitle },
845
- ...ogDescription && { description: ogDescription },
846
- ...options?.siteName && { siteName: options.siteName },
847
- ...image && { images: [image] }
848
- },
849
- twitter: {
850
- card: image ? "summary_large_image" : "summary",
851
- ...ogTitle && { title: ogTitle },
852
- ...ogDescription && { description: ogDescription },
853
- ...image && { images: [image.url] }
854
- }
855
- };
856
814
  }
857
- function resolveMetaImage(ref) {
858
- const image = resolveRelation(ref);
859
- if (!image) return null;
860
- const sized = image.sizes?.["1536"];
861
- const url = sized?.url || image.url;
862
- if (!url) return null;
863
- const width = sized?.url ? sized.width : image.width;
864
- const height = sized?.url ? sized.height : image.height;
815
+
816
+ // src/core/collection/query-builder.ts
817
+ function withDefaultPublicReadOptions(options) {
865
818
  return {
866
- url,
867
- ...width && { width },
868
- ...height && { height },
869
- ...image.alt && { alt: image.alt }
819
+ ...options,
820
+ depth: options?.depth ?? 0,
821
+ joins: options?.joins ?? false
870
822
  };
871
823
  }
872
-
873
- // src/core/collection/query-builder.ts
874
824
  var ReadOnlyCollectionQueryBuilder = class {
875
825
  constructor(api, collection) {
876
826
  this.api = api;
@@ -879,13 +829,13 @@ var ReadOnlyCollectionQueryBuilder = class {
879
829
  async find(options) {
880
830
  return this.api.requestFind(
881
831
  `/api/${String(this.collection)}`,
882
- options
832
+ withDefaultPublicReadOptions(options)
883
833
  );
884
834
  }
885
835
  async findById(id, options) {
886
836
  return this.api.requestFindById(
887
837
  `/api/${String(this.collection)}/${String(id)}`,
888
- options
838
+ withDefaultPublicReadOptions(options)
889
839
  );
890
840
  }
891
841
  async count(options) {
@@ -894,22 +844,6 @@ var ReadOnlyCollectionQueryBuilder = class {
894
844
  options
895
845
  );
896
846
  }
897
- async findMetadata(options, metadataOptions) {
898
- const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
899
- const doc = docs[0];
900
- if (!doc) return null;
901
- return generateMetadata(
902
- extractSeo(doc),
903
- metadataOptions
904
- );
905
- }
906
- async findMetadataById(id, metadataOptions) {
907
- const doc = await this.findById(id, { depth: 1 });
908
- return generateMetadata(
909
- extractSeo(doc),
910
- metadataOptions
911
- );
912
- }
913
847
  };
914
848
 
915
849
  // src/core/collection/collection-client.ts
@@ -925,6 +859,21 @@ var ReadOnlyCollectionClient = class extends HttpClient {
925
859
  });
926
860
  return this.parseFindResponse(response);
927
861
  }
862
+ async requestFindEndpoint(endpoint, data) {
863
+ const response = await this.fetchWithTracking(endpoint, {
864
+ ...this.defaultOptions,
865
+ method: "POST",
866
+ body: data ? JSON.stringify(data) : void 0
867
+ });
868
+ return this.parseFindResponse(response);
869
+ }
870
+ async requestFindEndpointGet(endpoint) {
871
+ const response = await this.fetchWithTracking(endpoint, {
872
+ ...this.defaultOptions,
873
+ method: "GET"
874
+ });
875
+ return this.parseFindResponse(response);
876
+ }
928
877
  async requestFindById(endpoint, options) {
929
878
  const url = this.buildUrl(endpoint, options);
930
879
  const response = await this.fetchWithTracking(url, {
@@ -989,13 +938,16 @@ async function parseApiResponse(response, endpoint) {
989
938
  return data;
990
939
  }
991
940
 
992
- // src/core/community/community-client.ts
993
- var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
994
- var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
995
- var CommunityClient = class {
996
- constructor(options) {
941
+ // src/core/api/customer-scoped-api.ts
942
+ var CustomerScopedApi = class {
943
+ constructor(apiName, options) {
944
+ if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
945
+ throw createConfigError(
946
+ `Either secretKey or customerToken is required for ${apiName}.`
947
+ );
948
+ }
997
949
  this.publishableKey = requirePublishableKeyForSecret(
998
- "CommunityClient",
950
+ apiName,
999
951
  options.publishableKey,
1000
952
  options.secretKey
1001
953
  );
@@ -1005,6 +957,44 @@ var CommunityClient = class {
1005
957
  this.onUnauthorized = options.onUnauthorized;
1006
958
  this.onRequestId = options.onRequestId;
1007
959
  }
960
+ async request(endpoint, options) {
961
+ const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
962
+ try {
963
+ const response = await httpFetch(endpoint, {
964
+ method: options.method,
965
+ apiUrl: this.apiUrl,
966
+ publishableKey: this.publishableKey,
967
+ secretKey: this.secretKey,
968
+ customerToken: token ?? void 0,
969
+ ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
970
+ ...options.body !== void 0 && {
971
+ body: JSON.stringify(options.body)
972
+ },
973
+ ...options.headers && { headers: options.headers }
974
+ });
975
+ this.onRequestId?.(response.headers.get("x-request-id") ?? null);
976
+ return parseApiResponse(response, endpoint);
977
+ } catch (err) {
978
+ const id = err instanceof SDKError ? err.requestId ?? null : null;
979
+ this.onRequestId?.(id);
980
+ throw err;
981
+ }
982
+ }
983
+ };
984
+
985
+ // src/core/community/community-client.ts
986
+ var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
987
+ var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
988
+ function unwrapPayloadDoc(value) {
989
+ if (value && typeof value === "object" && "doc" in value) {
990
+ return value.doc;
991
+ }
992
+ return value;
993
+ }
994
+ var CommunityClient = class extends CustomerScopedApi {
995
+ constructor(options) {
996
+ super("CommunityClient", { ...options, requiresCredential: false });
997
+ }
1008
998
  buildQuery(params) {
1009
999
  if (!params) return "";
1010
1000
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
@@ -1014,7 +1004,8 @@ var CommunityClient = class {
1014
1004
  const urlParams = new URLSearchParams();
1015
1005
  const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
1016
1006
  urlParams.set("sort", sort);
1017
- if (params?.limit !== void 0) urlParams.set("limit", String(params.limit));
1007
+ if (params?.limit !== void 0)
1008
+ urlParams.set("limit", String(params.limit));
1018
1009
  if (params?.page !== void 0) urlParams.set("page", String(params.page));
1019
1010
  if (params?.categoryId !== void 0) {
1020
1011
  urlParams.set("where[categories][in]", params.categoryId);
@@ -1022,7 +1013,7 @@ var CommunityClient = class {
1022
1013
  if (params?.tagId !== void 0) {
1023
1014
  urlParams.set("where[tags][in]", params.tagId);
1024
1015
  }
1025
- return `/api/posts?${urlParams.toString()}`;
1016
+ return `/api/posts/public?${urlParams.toString()}`;
1026
1017
  }
1027
1018
  buildCommentsListQuery(params) {
1028
1019
  const urlParams = new URLSearchParams();
@@ -1042,30 +1033,21 @@ var CommunityClient = class {
1042
1033
  }
1043
1034
  if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
1044
1035
  if (params.page !== void 0) urlParams.set("page", String(params.page));
1045
- return `/api/comments?${urlParams.toString()}`;
1036
+ return `/api/comments/public?${urlParams.toString()}`;
1046
1037
  }
1047
1038
  async execute(endpoint, method, body) {
1048
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1049
- try {
1050
- const response = await httpFetch(endpoint, {
1051
- method,
1052
- apiUrl: this.apiUrl,
1053
- publishableKey: this.publishableKey,
1054
- secretKey: this.secretKey,
1055
- customerToken: token ?? void 0,
1056
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1057
- ...body !== void 0 && { body: JSON.stringify(body) }
1058
- });
1059
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1060
- return parseApiResponse(response, endpoint);
1061
- } catch (err) {
1062
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1063
- this.onRequestId?.(id);
1064
- throw err;
1065
- }
1039
+ return this.request(endpoint, { method, body });
1040
+ }
1041
+ async executeDoc(endpoint, method, body) {
1042
+ const response = await this.execute(endpoint, method, body);
1043
+ return unwrapPayloadDoc(response);
1066
1044
  }
1067
1045
  createPost(params) {
1068
- return this.execute("/api/posts", "POST", params);
1046
+ return this.executeDoc(
1047
+ "/api/posts",
1048
+ "POST",
1049
+ params
1050
+ );
1069
1051
  }
1070
1052
  /**
1071
1053
  * Public post feed. Server applies the same visibility contract as
@@ -1122,7 +1104,11 @@ var CommunityClient = class {
1122
1104
  if (parentId !== void 0) {
1123
1105
  body.parent = parentId;
1124
1106
  }
1125
- return this.execute("/api/comments", "POST", body);
1107
+ return this.executeDoc(
1108
+ "/api/comments",
1109
+ "POST",
1110
+ body
1111
+ );
1126
1112
  }
1127
1113
  /**
1128
1114
  * List comments for a post.
@@ -1160,7 +1146,7 @@ var CommunityClient = class {
1160
1146
  }
1161
1147
  updateComment(params) {
1162
1148
  const { commentId, body } = params;
1163
- return this.execute(
1149
+ return this.executeDoc(
1164
1150
  `/api/comments/${commentId}`,
1165
1151
  "PATCH",
1166
1152
  { body }
@@ -1191,10 +1177,14 @@ var CommunityClient = class {
1191
1177
  400
1192
1178
  );
1193
1179
  }
1194
- return this.execute("/api/reactions", "POST", {
1195
- post: postId,
1196
- type: reactionType
1197
- });
1180
+ return this.executeDoc(
1181
+ "/api/reactions",
1182
+ "POST",
1183
+ {
1184
+ post: postId,
1185
+ type: reactionType
1186
+ }
1187
+ );
1198
1188
  }
1199
1189
  removeReaction(params) {
1200
1190
  const { postId, type } = params;
@@ -1213,10 +1203,14 @@ var CommunityClient = class {
1213
1203
  400
1214
1204
  );
1215
1205
  }
1216
- return this.execute("/api/reactions", "POST", {
1217
- comment: commentId,
1218
- type: reactionType
1219
- });
1206
+ return this.executeDoc(
1207
+ "/api/reactions",
1208
+ "POST",
1209
+ {
1210
+ comment: commentId,
1211
+ type: reactionType
1212
+ }
1213
+ );
1220
1214
  }
1221
1215
  removeCommentReaction(params) {
1222
1216
  const { commentId, type } = params;
@@ -1245,9 +1239,13 @@ var CommunityClient = class {
1245
1239
  }
1246
1240
  // Bookmarks
1247
1241
  addBookmark(params) {
1248
- return this.execute("/api/bookmarks", "POST", {
1249
- post: params.postId
1250
- });
1242
+ return this.executeDoc(
1243
+ "/api/bookmarks",
1244
+ "POST",
1245
+ {
1246
+ post: params.postId
1247
+ }
1248
+ );
1251
1249
  }
1252
1250
  removeBookmark(params) {
1253
1251
  return this.execute(
@@ -1263,10 +1261,7 @@ var CommunityClient = class {
1263
1261
  }
1264
1262
  // Profiles
1265
1263
  listProfileLists(params) {
1266
- return this.execute(
1267
- `/api/customer-profile-lists${this.buildQuery(params)}`,
1268
- "GET"
1269
- );
1264
+ return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
1270
1265
  }
1271
1266
  async getProfileList(params) {
1272
1267
  const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
@@ -1496,46 +1491,18 @@ var CustomerNamespace = class {
1496
1491
  };
1497
1492
 
1498
1493
  // src/core/api/cart-api.ts
1499
- var CartApi = class {
1494
+ var CartApi = class extends CustomerScopedApi {
1500
1495
  constructor(options) {
1501
- if (!options.secretKey && !options.customerToken) {
1502
- throw createConfigError(
1503
- "Either secretKey or customerToken is required for CartApi."
1504
- );
1505
- }
1506
- this.publishableKey = requirePublishableKeyForSecret(
1507
- "CartApi",
1508
- options.publishableKey,
1509
- options.secretKey
1510
- );
1511
- this.secretKey = options.secretKey;
1512
- this.apiUrl = options.apiUrl;
1513
- this.customerToken = options.customerToken;
1514
- this.onUnauthorized = options.onUnauthorized;
1515
- this.onRequestId = options.onRequestId;
1496
+ super("CartApi", options);
1516
1497
  }
1517
1498
  async execute(endpoint, method, body) {
1518
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1519
- try {
1520
- const response = await httpFetch(endpoint, {
1521
- method,
1522
- apiUrl: this.apiUrl,
1523
- publishableKey: this.publishableKey,
1524
- secretKey: this.secretKey,
1525
- customerToken: token ?? void 0,
1526
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1527
- ...body !== void 0 && { body: JSON.stringify(body) }
1528
- });
1529
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1530
- return parseApiResponse(response, endpoint);
1531
- } catch (err) {
1532
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1533
- this.onRequestId?.(id);
1534
- throw err;
1535
- }
1499
+ return this.request(endpoint, { method, body });
1536
1500
  }
1537
1501
  getCart(cartId) {
1538
- return this.execute(`/api/carts/${cartId}`, "GET");
1502
+ return this.execute(
1503
+ `/api/carts/${cartId}?depth=0&joins=false`,
1504
+ "GET"
1505
+ );
1539
1506
  }
1540
1507
  addItem(params) {
1541
1508
  return this.execute("/api/carts/add-item", "POST", params);
@@ -1756,15 +1723,24 @@ function splitIdempotencyKey(params) {
1756
1723
  const { idempotencyKey, ...body } = params;
1757
1724
  return { body, idempotencyKey };
1758
1725
  }
1726
+ function normalizeCreateOrderBody(params) {
1727
+ if (params.items !== void 0) {
1728
+ const { idempotencyKey: _idempotencyKey2, items, ...rest } = params;
1729
+ return { ...rest, orderItems: items };
1730
+ }
1731
+ const { idempotencyKey: _idempotencyKey, ...body } = params;
1732
+ return body;
1733
+ }
1759
1734
  var OrderApi = class extends BaseApi {
1760
1735
  constructor(options) {
1761
1736
  super("OrderApi", options);
1762
1737
  }
1763
1738
  createOrder(params) {
1764
- const { body, idempotencyKey } = splitIdempotencyKey(params);
1739
+ const { idempotencyKey } = params;
1740
+ const normalizedBody = normalizeCreateOrderBody(params);
1765
1741
  return this.request(
1766
1742
  "/api/orders/create",
1767
- body,
1743
+ normalizedBody,
1768
1744
  idempotencyRequestOptions(idempotencyKey)
1769
1745
  );
1770
1746
  }
@@ -1826,6 +1802,12 @@ var OrderApi = class extends BaseApi {
1826
1802
  idempotencyRequestOptions(idempotencyKey)
1827
1803
  );
1828
1804
  }
1805
+ prepareFulfillmentOrder(params) {
1806
+ return this.request(
1807
+ "/api/fulfillment-orders/prepare-fulfillment-order",
1808
+ params
1809
+ );
1810
+ }
1829
1811
  updateFulfillment(params) {
1830
1812
  return this.request("/api/orders/update-fulfillment", params);
1831
1813
  }
@@ -1857,6 +1839,18 @@ var OrderApi = class extends BaseApi {
1857
1839
  };
1858
1840
 
1859
1841
  // src/core/commerce/commerce-client.ts
1842
+ var BrowserCommerceApi = class extends CustomerScopedApi {
1843
+ post(endpoint, body, requestOptions) {
1844
+ return this.request(endpoint, {
1845
+ method: "POST",
1846
+ body,
1847
+ headers: requestOptions?.headers
1848
+ });
1849
+ }
1850
+ get(endpoint) {
1851
+ return this.request(endpoint, { method: "GET" });
1852
+ }
1853
+ };
1860
1854
  var CommerceClient = class {
1861
1855
  constructor(options) {
1862
1856
  const cartApi = new CartApi({
@@ -1866,52 +1860,23 @@ var CommerceClient = class {
1866
1860
  onUnauthorized: options.onUnauthorized,
1867
1861
  onRequestId: options.onRequestId
1868
1862
  });
1869
- const execute = async (endpoint, body, requestOptions) => {
1870
- const token = options.customerToken();
1871
- try {
1872
- const response = await httpFetch(endpoint, {
1873
- method: "POST",
1874
- apiUrl: options.apiUrl,
1875
- publishableKey: options.publishableKey,
1876
- customerToken: token ?? void 0,
1877
- ...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized },
1878
- body: JSON.stringify(body),
1879
- ...requestOptions?.headers && { headers: requestOptions.headers }
1880
- });
1881
- options.onRequestId?.(response.headers.get("x-request-id") ?? null);
1882
- return parseApiResponse(response, endpoint);
1883
- } catch (err) {
1884
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1885
- options.onRequestId?.(id);
1886
- throw err;
1887
- }
1888
- };
1889
- const executeGet = async (endpoint) => {
1890
- const token = options.customerToken();
1891
- try {
1892
- const response = await httpFetch(endpoint, {
1893
- method: "GET",
1894
- apiUrl: options.apiUrl,
1895
- publishableKey: options.publishableKey,
1896
- customerToken: token ?? void 0,
1897
- ...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized }
1898
- });
1899
- options.onRequestId?.(response.headers.get("x-request-id") ?? null);
1900
- return parseApiResponse(response, endpoint);
1901
- } catch (err) {
1902
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1903
- options.onRequestId?.(id);
1904
- throw err;
1905
- }
1906
- };
1863
+ const api = new BrowserCommerceApi("CommerceClient", {
1864
+ publishableKey: options.publishableKey,
1865
+ apiUrl: options.apiUrl,
1866
+ customerToken: options.customerToken,
1867
+ onUnauthorized: options.onUnauthorized,
1868
+ onRequestId: options.onRequestId
1869
+ });
1907
1870
  this.product = {
1908
- stockCheck: (params) => execute("/api/products/stock-check", params),
1909
- stockSnapshot: (params) => executeGet(stockSnapshotQuery(params)),
1910
- listingGroups: (params) => executeGet(listingGroupsQuery(params)),
1911
- listingGroupsCatalog: (params) => executeGet(listingGroupsCatalogQuery(params)),
1871
+ stockCheck: (params) => api.post("/api/products/stock-check", params),
1872
+ stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
1873
+ listingGroups: (params) => api.get(listingGroupsQuery(params)),
1874
+ listingGroupsCatalog: (params) => api.get(
1875
+ listingGroupsCatalogQuery(params)
1876
+ ),
1912
1877
  detail: async (params) => {
1913
1878
  try {
1914
- const product = await executeGet(productDetailQuery(params));
1879
+ const product = await api.get(productDetailQuery(params));
1915
1880
  return { found: true, product };
1916
1881
  } catch (err) {
1917
1882
  const notFoundResult = productDetailResultFromError(err);
@@ -1921,7 +1886,7 @@ var CommerceClient = class {
1921
1886
  },
1922
1887
  detailCatalog: async (params) => {
1923
1888
  try {
1924
- const product = await executeGet(
1889
+ const product = await api.get(
1925
1890
  productDetailCatalogQuery(params)
1926
1891
  );
1927
1892
  return { found: true, product };
@@ -1944,7 +1909,7 @@ var CommerceClient = class {
1944
1909
  this.orders = {
1945
1910
  checkout: (params) => {
1946
1911
  const { body, idempotencyKey } = splitIdempotencyKey(params);
1947
- return execute(
1912
+ return api.post(
1948
1913
  "/api/orders/checkout",
1949
1914
  body,
1950
1915
  idempotencyRequestOptions(idempotencyKey)
@@ -1953,10 +1918,10 @@ var CommerceClient = class {
1953
1918
  listMine: (params) => options.customerAuth.getMyOrders(params)
1954
1919
  };
1955
1920
  this.discounts = {
1956
- validate: (params) => execute("/api/discounts/validate", params)
1921
+ validate: (params) => api.post("/api/discounts/validate", params)
1957
1922
  };
1958
1923
  this.shipping = {
1959
- calculate: (params) => execute("/api/shipping-policies/calculate", params)
1924
+ calculate: (params) => api.post("/api/shipping-policies/calculate", params)
1960
1925
  };
1961
1926
  }
1962
1927
  };
@@ -2312,7 +2277,7 @@ function getCommerceNotificationIdempotencyKey(event) {
2312
2277
  function defineCommerceEmailConfig(config) {
2313
2278
  return config;
2314
2279
  }
2315
- function createCommerceEmailWebhookHandler(handlers) {
2280
+ function createCommerceNotificationWebhookHandler(handlers) {
2316
2281
  return async (event) => {
2317
2282
  if (!isCommerceNotificationWebhookEvent(event)) {
2318
2283
  await handlers.unhandled?.(event);
@@ -2329,6 +2294,9 @@ function createCommerceEmailWebhookHandler(handlers) {
2329
2294
  });
2330
2295
  };
2331
2296
  }
2297
+ function createCommerceEmailWebhookHandler(handlers) {
2298
+ return createCommerceNotificationWebhookHandler(handlers);
2299
+ }
2332
2300
  function isWebhookCollection(event, collection) {
2333
2301
  return isValidWebhookEvent(event) && event.collection === collection;
2334
2302
  }
@@ -2466,6 +2434,7 @@ var INTERNAL_COLLECTIONS = [
2466
2434
  "subscriptions",
2467
2435
  "billing-history",
2468
2436
  "inventory-reservations",
2437
+ "inventory-adjustments",
2469
2438
  "commerce-notification-intents",
2470
2439
  "product-collection-items",
2471
2440
  "order-status-logs",
@@ -2484,7 +2453,6 @@ var INTERNAL_COLLECTIONS = [
2484
2453
  var COLLECTIONS = [
2485
2454
  "tenants",
2486
2455
  "tenant-metadata",
2487
- "tenant-logos",
2488
2456
  "products",
2489
2457
  "product-variants",
2490
2458
  "product-options",
@@ -2493,19 +2461,7 @@ var COLLECTIONS = [
2493
2461
  "product-tags",
2494
2462
  "product-collections",
2495
2463
  "brands",
2496
- "brand-logos",
2497
- "orders",
2498
- "order-items",
2499
- "returns",
2500
- "return-items",
2501
- "fulfillments",
2502
- "fulfillment-items",
2503
- "transactions",
2504
- "customers",
2505
2464
  "customer-profiles",
2506
- "customer-addresses",
2507
- "carts",
2508
- "cart-items",
2509
2465
  "discounts",
2510
2466
  "shipping-policies",
2511
2467
  "shipping-zones",
@@ -2536,19 +2492,11 @@ var COLLECTIONS = [
2536
2492
  "canvas-tags",
2537
2493
  "canvas-nodes",
2538
2494
  "canvas-edges",
2539
- "videos",
2540
2495
  "video-categories",
2541
2496
  "video-tags",
2542
- "live-streams",
2543
- "images",
2544
2497
  "forms",
2545
- "form-submissions",
2546
2498
  // Community
2547
- "posts",
2548
- "comments",
2549
- "reactions",
2550
2499
  "reaction-types",
2551
- "bookmarks",
2552
2500
  "post-categories",
2553
2501
  "post-tags",
2554
2502
  "customer-profile-lists",
@@ -2560,9 +2508,33 @@ var COLLECTIONS = [
2560
2508
  "event-tags"
2561
2509
  ];
2562
2510
  var SERVER_ONLY_COLLECTIONS = [
2511
+ "tenant-logos",
2512
+ "brand-logos",
2513
+ "images",
2514
+ "videos",
2515
+ "orders",
2516
+ "order-items",
2517
+ "returns",
2518
+ "return-items",
2519
+ "fulfillment-orders",
2520
+ "fulfillment-order-items",
2521
+ "fulfillments",
2522
+ "fulfillment-items",
2523
+ "transactions",
2524
+ "customers",
2525
+ "customer-addresses",
2526
+ "form-submissions",
2527
+ "carts",
2528
+ "cart-items",
2529
+ "posts",
2530
+ "comments",
2531
+ "reactions",
2532
+ "bookmarks",
2533
+ "live-streams",
2563
2534
  "customer-groups",
2564
2535
  "reports",
2565
- "community-bans"
2536
+ "community-bans",
2537
+ "order-export-profiles"
2566
2538
  ];
2567
2539
  var SERVER_COLLECTIONS = [
2568
2540
  ...COLLECTIONS,
@@ -4416,6 +4388,12 @@ function maxOfNullable(values) {
4416
4388
  const numbers = values.filter((v) => v !== null);
4417
4389
  return numbers.length === 0 ? null : Math.max(...numbers);
4418
4390
  }
4391
+ var PRODUCT_PLP_FIND_OPTIONS = {
4392
+ joins: {
4393
+ variants: { limit: 200, sort: "_order" },
4394
+ options: { limit: 50, sort: "_order" }
4395
+ }
4396
+ };
4419
4397
  function buildProductListingGroupsByOption(args) {
4420
4398
  const primaryOptionId = args.primaryOptionId ?? void 0;
4421
4399
  if (!primaryOptionId) return [];
@@ -4609,8 +4587,6 @@ function resolveLegacyMediaSet(input) {
4609
4587
  };
4610
4588
  }
4611
4589
  function resolveProductGallery(input) {
4612
- const legacyResolved = resolveLegacyMediaSet(input);
4613
- if (legacyResolved && legacyResolved.source !== "none") return legacyResolved;
4614
4590
  const selectedVariantId = mediaId(input.selectedVariantId);
4615
4591
  const selectedOptionValueIds = relationshipIds(input.selectedOptionValueIds);
4616
4592
  const selection = resolveProductSelectionMedia({
@@ -4622,6 +4598,8 @@ function resolveProductGallery(input) {
4622
4598
  if (selection.source !== "none") {
4623
4599
  return selection;
4624
4600
  }
4601
+ const legacyResolved = resolveLegacyMediaSet(input);
4602
+ if (legacyResolved && legacyResolved.source !== "none") return legacyResolved;
4625
4603
  return resolveProductDisplayMedia({
4626
4604
  productMediaPool: input.productMediaPool ?? input.pool ?? null,
4627
4605
  productPrimaryMediaItemId: input.productPrimaryMediaItemId,
@@ -4630,14 +4608,22 @@ function resolveProductGallery(input) {
4630
4608
  }
4631
4609
 
4632
4610
  // src/utils/image.ts
4633
- var IMAGE_SIZES = [384, 768, 1536];
4611
+ var IMAGE_SIZES = [200, 400, 800, 1200, 1600];
4612
+ function imageSizeCandidates(sizes) {
4613
+ const keys = new Set(IMAGE_SIZES);
4614
+ for (const key of Object.keys(sizes)) {
4615
+ const value = Number(key);
4616
+ if (Number.isFinite(value) && value > 0) keys.add(value);
4617
+ }
4618
+ return [...keys].sort((a, b) => a - b);
4619
+ }
4634
4620
  function getImageUrl(image, displayWidth, dpr = 1) {
4635
4621
  const target = displayWidth * dpr;
4636
4622
  const sizes = image.sizes;
4637
4623
  if (sizes) {
4638
- for (const size of IMAGE_SIZES) {
4624
+ for (const size of imageSizeCandidates(sizes)) {
4639
4625
  if (size >= target) {
4640
- const entry = sizes[String(size)];
4626
+ const entry = sizes[`${size}`];
4641
4627
  if (entry?.url) return entry.url;
4642
4628
  }
4643
4629
  }
@@ -4646,16 +4632,18 @@ function getImageUrl(image, displayWidth, dpr = 1) {
4646
4632
  }
4647
4633
  function getImageSrcSet(image) {
4648
4634
  const parts = [];
4635
+ const emittedWidths = /* @__PURE__ */ new Set();
4649
4636
  const sizes = image.sizes;
4650
4637
  if (sizes) {
4651
- for (const size of IMAGE_SIZES) {
4652
- const entry = sizes[String(size)];
4653
- if (entry?.url && entry.width) {
4638
+ for (const size of imageSizeCandidates(sizes)) {
4639
+ const entry = sizes[`${size}`];
4640
+ if (entry?.url && entry.width && !emittedWidths.has(entry.width)) {
4641
+ emittedWidths.add(entry.width);
4654
4642
  parts.push(`${entry.url} ${entry.width}w`);
4655
4643
  }
4656
4644
  }
4657
4645
  }
4658
- if (image.url && image.width) {
4646
+ if (image.url && image.width && !emittedWidths.has(image.width)) {
4659
4647
  parts.push(`${image.url} ${image.width}w`);
4660
4648
  }
4661
4649
  return parts.join(", ");
@@ -4757,6 +4745,27 @@ function createAnalytics(config) {
4757
4745
  const nav = navigator;
4758
4746
  return nav.doNotTrack === "1" || nav.globalPrivacyControl === true;
4759
4747
  }
4748
+ const isLocalHost = (() => {
4749
+ try {
4750
+ const h = location.hostname;
4751
+ return h === "localhost" || h === "127.0.0.1" || h.endsWith(".local");
4752
+ } catch {
4753
+ return false;
4754
+ }
4755
+ })();
4756
+ const mode = config.mode ?? "auto";
4757
+ const sendSuppressed = mode === "development" || mode === "auto" && isLocalHost;
4758
+ let suppressNoticeShown = false;
4759
+ function devSuppressNotice() {
4760
+ if (suppressNoticeShown) return;
4761
+ suppressNoticeShown = true;
4762
+ try {
4763
+ console.info(
4764
+ `[01 analytics] events disabled on local host (mode: '${mode}'). Pass mode: 'production' to send while developing.`
4765
+ );
4766
+ } catch {
4767
+ }
4768
+ }
4760
4769
  let lastPath = null;
4761
4770
  let lastAt = 0;
4762
4771
  const autoTrack = config.autoTrack !== false;
@@ -4787,6 +4796,10 @@ function createAnalytics(config) {
4787
4796
  if (isDntActive()) return;
4788
4797
  const doc = document;
4789
4798
  if (doc.prerendering === true || document.visibilityState === "prerender") return;
4799
+ if (sendSuppressed) {
4800
+ devSuppressNotice();
4801
+ return;
4802
+ }
4790
4803
  const now = Date.now();
4791
4804
  if (pathname === lastPath && now - lastAt < 500) return;
4792
4805
  lastPath = pathname;
@@ -4822,14 +4835,7 @@ function createAnalytics(config) {
4822
4835
  window.addEventListener("load", trackCurrentPath, { once: true });
4823
4836
  }
4824
4837
  }
4825
- const isProduction = (() => {
4826
- try {
4827
- const hostname = location.hostname;
4828
- return hostname !== "localhost" && hostname !== "127.0.0.1" && !hostname.endsWith(".local");
4829
- } catch {
4830
- return true;
4831
- }
4832
- })();
4838
+ const isProduction = !isLocalHost;
4833
4839
  const warnedReasons = /* @__PURE__ */ new Set();
4834
4840
  function devWarn(name, reason) {
4835
4841
  if (isProduction) return;
@@ -4889,6 +4895,10 @@ function createAnalytics(config) {
4889
4895
  return;
4890
4896
  }
4891
4897
  }
4898
+ if (sendSuppressed) {
4899
+ devSuppressNotice();
4900
+ return;
4901
+ }
4892
4902
  const body = JSON.stringify({
4893
4903
  publishableKey: config.publishableKey,
4894
4904
  pathname: location.pathname,
@@ -4943,6 +4953,7 @@ export {
4943
4953
  NotFoundError,
4944
4954
  ORDER_CHANGED_EVENT_TYPE,
4945
4955
  OrderApi,
4956
+ PRODUCT_PLP_FIND_OPTIONS,
4946
4957
  PRODUCT_UPSERT_READONLY_FIELD_REASON,
4947
4958
  PRODUCT_UPSERT_UNKNOWN_FIELD_REASON,
4948
4959
  PermissionError,
@@ -4968,6 +4979,7 @@ export {
4968
4979
  createAuthError,
4969
4980
  createClient2 as createClient,
4970
4981
  createCommerceEmailWebhookHandler,
4982
+ createCommerceNotificationWebhookHandler,
4971
4983
  createConflictError,
4972
4984
  createCustomerAuthWebhookHandler,
4973
4985
  createNotFoundError,