@01.software/sdk 0.36.0 → 0.37.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 (80) hide show
  1. package/README.md +71 -6
  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 +94 -114
  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 +94 -114
  19. package/dist/client.js.map +1 -1
  20. package/dist/{collection-client-Bq5Zd7p7.d.ts → collection-client-DyELGUcL.d.ts} +3 -3
  21. package/dist/{collection-client-Cv0D2w1Q.d.cts → collection-client-zOmnxwdA.d.cts} +3 -3
  22. package/dist/{const-DVcM7Ac_.d.cts → const-CK_FPaIn.d.cts} +3 -3
  23. package/dist/{const-BDUKFP9w.d.ts → const-Dqz05oaG.d.ts} +3 -3
  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-DRJs7QIh.d.cts} +9 -6
  27. package/dist/{index-BHDKJ6B3.d.cts → index-DTqoUZk_.d.ts} +9 -6
  28. package/dist/index.cjs +172 -132
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +10 -9
  31. package/dist/index.d.ts +10 -9
  32. package/dist/index.js +172 -132
  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-CREOjFNT.d.cts} +281 -108
  39. package/dist/{payload-types-BCui2Oml.d.ts → payload-types-CREOjFNT.d.ts} +281 -108
  40. package/dist/query.cjs +5 -3
  41. package/dist/query.cjs.map +1 -1
  42. package/dist/query.d.cts +5 -5
  43. package/dist/query.d.ts +5 -5
  44. package/dist/query.js +5 -3
  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 +84 -69
  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 +84 -69
  53. package/dist/server.js.map +1 -1
  54. package/dist/{types-Dib-zdK6.d.cts → types-BWMUr3Zw.d.cts} +195 -71
  55. package/dist/{types-CEzLf3PX.d.cts → types-BkZNhuBh.d.cts} +1 -1
  56. package/dist/{types-3qV6sY7T.d.ts → types-CxzWHspI.d.ts} +1 -1
  57. package/dist/{types-DK9EnLwJ.d.ts → types-DMvVHdb1.d.ts} +195 -71
  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 +1 -1
package/dist/client.cjs CHANGED
@@ -772,13 +772,15 @@ var HttpClient = class {
772
772
  };
773
773
 
774
774
  // src/utils/types.ts
775
- var resolveRelation = (ref) => {
775
+ function resolveRelation(ref) {
776
776
  if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
777
777
  return null;
778
778
  return ref;
779
- };
779
+ }
780
780
 
781
781
  // src/core/metadata/index.ts
782
+ var OPEN_GRAPH_IMAGE_SIZE = "1200";
783
+ var LEGACY_OPEN_GRAPH_IMAGE_SIZE = "1536";
782
784
  function extractSeo(doc) {
783
785
  const seo = doc.seo ?? {};
784
786
  const og = seo.openGraph ?? {};
@@ -822,7 +824,7 @@ function generateMetadata(input, options) {
822
824
  function resolveMetaImage(ref) {
823
825
  const image = resolveRelation(ref);
824
826
  if (!image) return null;
825
- const sized = image.sizes?.["1536"];
827
+ const sized = image.sizes?.[OPEN_GRAPH_IMAGE_SIZE] ?? image.sizes?.[LEGACY_OPEN_GRAPH_IMAGE_SIZE];
826
828
  const url = sized?.url || image.url;
827
829
  if (!url) return null;
828
830
  const width = sized?.url ? sized.width : image.width;
@@ -954,13 +956,16 @@ async function parseApiResponse(response, endpoint) {
954
956
  return data;
955
957
  }
956
958
 
957
- // src/core/community/community-client.ts
958
- var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
959
- var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
960
- var CommunityClient = class {
961
- constructor(options) {
959
+ // src/core/api/customer-scoped-api.ts
960
+ var CustomerScopedApi = class {
961
+ constructor(apiName, options) {
962
+ if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
963
+ throw createConfigError(
964
+ `Either secretKey or customerToken is required for ${apiName}.`
965
+ );
966
+ }
962
967
  this.publishableKey = requirePublishableKeyForSecret(
963
- "CommunityClient",
968
+ apiName,
964
969
  options.publishableKey,
965
970
  options.secretKey
966
971
  );
@@ -970,6 +975,44 @@ var CommunityClient = class {
970
975
  this.onUnauthorized = options.onUnauthorized;
971
976
  this.onRequestId = options.onRequestId;
972
977
  }
978
+ async request(endpoint, options) {
979
+ const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
980
+ try {
981
+ const response = await httpFetch(endpoint, {
982
+ method: options.method,
983
+ apiUrl: this.apiUrl,
984
+ publishableKey: this.publishableKey,
985
+ secretKey: this.secretKey,
986
+ customerToken: token ?? void 0,
987
+ ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
988
+ ...options.body !== void 0 && {
989
+ body: JSON.stringify(options.body)
990
+ },
991
+ ...options.headers && { headers: options.headers }
992
+ });
993
+ this.onRequestId?.(response.headers.get("x-request-id") ?? null);
994
+ return parseApiResponse(response, endpoint);
995
+ } catch (err) {
996
+ const id = err instanceof SDKError ? err.requestId ?? null : null;
997
+ this.onRequestId?.(id);
998
+ throw err;
999
+ }
1000
+ }
1001
+ };
1002
+
1003
+ // src/core/community/community-client.ts
1004
+ var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
1005
+ var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
1006
+ function unwrapPayloadDoc(value) {
1007
+ if (value && typeof value === "object" && "doc" in value) {
1008
+ return value.doc;
1009
+ }
1010
+ return value;
1011
+ }
1012
+ var CommunityClient = class extends CustomerScopedApi {
1013
+ constructor(options) {
1014
+ super("CommunityClient", { ...options, requiresCredential: false });
1015
+ }
973
1016
  buildQuery(params) {
974
1017
  if (!params) return "";
975
1018
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
@@ -1010,27 +1053,14 @@ var CommunityClient = class {
1010
1053
  return `/api/comments?${urlParams.toString()}`;
1011
1054
  }
1012
1055
  async execute(endpoint, method, body) {
1013
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1014
- try {
1015
- const response = await httpFetch(endpoint, {
1016
- method,
1017
- apiUrl: this.apiUrl,
1018
- publishableKey: this.publishableKey,
1019
- secretKey: this.secretKey,
1020
- customerToken: token ?? void 0,
1021
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1022
- ...body !== void 0 && { body: JSON.stringify(body) }
1023
- });
1024
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1025
- return parseApiResponse(response, endpoint);
1026
- } catch (err) {
1027
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1028
- this.onRequestId?.(id);
1029
- throw err;
1030
- }
1056
+ return this.request(endpoint, { method, body });
1057
+ }
1058
+ async executeDoc(endpoint, method, body) {
1059
+ const response = await this.execute(endpoint, method, body);
1060
+ return unwrapPayloadDoc(response);
1031
1061
  }
1032
1062
  createPost(params) {
1033
- return this.execute("/api/posts", "POST", params);
1063
+ return this.executeDoc("/api/posts", "POST", params);
1034
1064
  }
1035
1065
  /**
1036
1066
  * Public post feed. Server applies the same visibility contract as
@@ -1087,7 +1117,7 @@ var CommunityClient = class {
1087
1117
  if (parentId !== void 0) {
1088
1118
  body.parent = parentId;
1089
1119
  }
1090
- return this.execute("/api/comments", "POST", body);
1120
+ return this.executeDoc("/api/comments", "POST", body);
1091
1121
  }
1092
1122
  /**
1093
1123
  * List comments for a post.
@@ -1125,7 +1155,7 @@ var CommunityClient = class {
1125
1155
  }
1126
1156
  updateComment(params) {
1127
1157
  const { commentId, body } = params;
1128
- return this.execute(
1158
+ return this.executeDoc(
1129
1159
  `/api/comments/${commentId}`,
1130
1160
  "PATCH",
1131
1161
  { body }
@@ -1156,7 +1186,7 @@ var CommunityClient = class {
1156
1186
  400
1157
1187
  );
1158
1188
  }
1159
- return this.execute("/api/reactions", "POST", {
1189
+ return this.executeDoc("/api/reactions", "POST", {
1160
1190
  post: postId,
1161
1191
  type: reactionType
1162
1192
  });
@@ -1178,7 +1208,7 @@ var CommunityClient = class {
1178
1208
  400
1179
1209
  );
1180
1210
  }
1181
- return this.execute("/api/reactions", "POST", {
1211
+ return this.executeDoc("/api/reactions", "POST", {
1182
1212
  comment: commentId,
1183
1213
  type: reactionType
1184
1214
  });
@@ -1210,7 +1240,7 @@ var CommunityClient = class {
1210
1240
  }
1211
1241
  // Bookmarks
1212
1242
  addBookmark(params) {
1213
- return this.execute("/api/bookmarks", "POST", {
1243
+ return this.executeDoc("/api/bookmarks", "POST", {
1214
1244
  post: params.postId
1215
1245
  });
1216
1246
  }
@@ -1461,43 +1491,12 @@ var CustomerNamespace = class {
1461
1491
  };
1462
1492
 
1463
1493
  // src/core/api/cart-api.ts
1464
- var CartApi = class {
1494
+ var CartApi = class extends CustomerScopedApi {
1465
1495
  constructor(options) {
1466
- if (!options.secretKey && !options.customerToken) {
1467
- throw createConfigError(
1468
- "Either secretKey or customerToken is required for CartApi."
1469
- );
1470
- }
1471
- this.publishableKey = requirePublishableKeyForSecret(
1472
- "CartApi",
1473
- options.publishableKey,
1474
- options.secretKey
1475
- );
1476
- this.secretKey = options.secretKey;
1477
- this.apiUrl = options.apiUrl;
1478
- this.customerToken = options.customerToken;
1479
- this.onUnauthorized = options.onUnauthorized;
1480
- this.onRequestId = options.onRequestId;
1496
+ super("CartApi", options);
1481
1497
  }
1482
1498
  async execute(endpoint, method, body) {
1483
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1484
- try {
1485
- const response = await httpFetch(endpoint, {
1486
- method,
1487
- apiUrl: this.apiUrl,
1488
- publishableKey: this.publishableKey,
1489
- secretKey: this.secretKey,
1490
- customerToken: token ?? void 0,
1491
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1492
- ...body !== void 0 && { body: JSON.stringify(body) }
1493
- });
1494
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1495
- return parseApiResponse(response, endpoint);
1496
- } catch (err) {
1497
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1498
- this.onRequestId?.(id);
1499
- throw err;
1500
- }
1499
+ return this.request(endpoint, { method, body });
1501
1500
  }
1502
1501
  getCart(cartId) {
1503
1502
  return this.execute(`/api/carts/${cartId}`, "GET");
@@ -1564,6 +1563,18 @@ function splitIdempotencyKey(params) {
1564
1563
  }
1565
1564
 
1566
1565
  // src/core/commerce/commerce-client.ts
1566
+ var BrowserCommerceApi = class extends CustomerScopedApi {
1567
+ post(endpoint, body, requestOptions) {
1568
+ return this.request(endpoint, {
1569
+ method: "POST",
1570
+ body,
1571
+ headers: requestOptions?.headers
1572
+ });
1573
+ }
1574
+ get(endpoint) {
1575
+ return this.request(endpoint, { method: "GET" });
1576
+ }
1577
+ };
1567
1578
  var CommerceClient = class {
1568
1579
  constructor(options) {
1569
1580
  const cartApi = new CartApi({
@@ -1573,52 +1584,21 @@ var CommerceClient = class {
1573
1584
  onUnauthorized: options.onUnauthorized,
1574
1585
  onRequestId: options.onRequestId
1575
1586
  });
1576
- const execute = async (endpoint, body, requestOptions) => {
1577
- const token = options.customerToken();
1578
- try {
1579
- const response = await httpFetch(endpoint, {
1580
- method: "POST",
1581
- apiUrl: options.apiUrl,
1582
- publishableKey: options.publishableKey,
1583
- customerToken: token ?? void 0,
1584
- ...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized },
1585
- body: JSON.stringify(body),
1586
- ...requestOptions?.headers && { headers: requestOptions.headers }
1587
- });
1588
- options.onRequestId?.(response.headers.get("x-request-id") ?? null);
1589
- return parseApiResponse(response, endpoint);
1590
- } catch (err) {
1591
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1592
- options.onRequestId?.(id);
1593
- throw err;
1594
- }
1595
- };
1596
- const executeGet = async (endpoint) => {
1597
- const token = options.customerToken();
1598
- try {
1599
- const response = await httpFetch(endpoint, {
1600
- method: "GET",
1601
- apiUrl: options.apiUrl,
1602
- publishableKey: options.publishableKey,
1603
- customerToken: token ?? void 0,
1604
- ...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized }
1605
- });
1606
- options.onRequestId?.(response.headers.get("x-request-id") ?? null);
1607
- return parseApiResponse(response, endpoint);
1608
- } catch (err) {
1609
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1610
- options.onRequestId?.(id);
1611
- throw err;
1612
- }
1613
- };
1587
+ const api = new BrowserCommerceApi("CommerceClient", {
1588
+ publishableKey: options.publishableKey,
1589
+ apiUrl: options.apiUrl,
1590
+ customerToken: options.customerToken,
1591
+ onUnauthorized: options.onUnauthorized,
1592
+ onRequestId: options.onRequestId
1593
+ });
1614
1594
  this.product = {
1615
- stockCheck: (params) => execute("/api/products/stock-check", params),
1616
- stockSnapshot: (params) => executeGet(stockSnapshotQuery(params)),
1617
- listingGroups: (params) => executeGet(listingGroupsQuery(params)),
1618
- listingGroupsCatalog: (params) => executeGet(listingGroupsCatalogQuery(params)),
1595
+ stockCheck: (params) => api.post("/api/products/stock-check", params),
1596
+ stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
1597
+ listingGroups: (params) => api.get(listingGroupsQuery(params)),
1598
+ listingGroupsCatalog: (params) => api.get(listingGroupsCatalogQuery(params)),
1619
1599
  detail: async (params) => {
1620
1600
  try {
1621
- const product = await executeGet(productDetailQuery(params));
1601
+ const product = await api.get(productDetailQuery(params));
1622
1602
  return { found: true, product };
1623
1603
  } catch (err) {
1624
1604
  const notFoundResult = productDetailResultFromError(err);
@@ -1628,7 +1608,7 @@ var CommerceClient = class {
1628
1608
  },
1629
1609
  detailCatalog: async (params) => {
1630
1610
  try {
1631
- const product = await executeGet(
1611
+ const product = await api.get(
1632
1612
  productDetailCatalogQuery(params)
1633
1613
  );
1634
1614
  return { found: true, product };
@@ -1651,7 +1631,7 @@ var CommerceClient = class {
1651
1631
  this.orders = {
1652
1632
  checkout: (params) => {
1653
1633
  const { body, idempotencyKey } = splitIdempotencyKey(params);
1654
- return execute(
1634
+ return api.post(
1655
1635
  "/api/orders/checkout",
1656
1636
  body,
1657
1637
  idempotencyRequestOptions(idempotencyKey)
@@ -1660,10 +1640,10 @@ var CommerceClient = class {
1660
1640
  listMine: (params) => options.customerAuth.getMyOrders(params)
1661
1641
  };
1662
1642
  this.discounts = {
1663
- validate: (params) => execute("/api/discounts/validate", params)
1643
+ validate: (params) => api.post("/api/discounts/validate", params)
1664
1644
  };
1665
1645
  this.shipping = {
1666
- calculate: (params) => execute("/api/shipping-policies/calculate", params)
1646
+ calculate: (params) => api.post("/api/shipping-policies/calculate", params)
1667
1647
  };
1668
1648
  }
1669
1649
  };