@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.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import { R as ReadOnlyCollectionClient } from './collection-client-Cv0D2w1Q.cjs';
2
- import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-Dib-zdK6.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-Dib-zdK6.cjs';
4
- export { C as Collection, P as PublicCollection } from './const-DVcM7Ac_.cjs';
1
+ import { R as ReadOnlyCollectionClient } from './collection-client-zOmnxwdA.cjs';
2
+ import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-BWMUr3Zw.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-BWMUr3Zw.cjs';
4
+ export { C as Collection, P as PublicCollection } from './const-CK_FPaIn.cjs';
5
5
  import './metadata.cjs';
6
- import './types-CEzLf3PX.cjs';
7
- import './payload-types-BCui2Oml.cjs';
6
+ import './types-BkZNhuBh.cjs';
7
+ import './payload-types-CREOjFNT.cjs';
8
8
 
9
9
  declare class Client {
10
10
  commerce: CommerceClient;
package/dist/client.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { R as ReadOnlyCollectionClient } from './collection-client-Bq5Zd7p7.js';
2
- import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-DK9EnLwJ.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-DK9EnLwJ.js';
4
- export { C as Collection, P as PublicCollection } from './const-BDUKFP9w.js';
1
+ import { R as ReadOnlyCollectionClient } from './collection-client-DyELGUcL.js';
2
+ import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-DMvVHdb1.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-DMvVHdb1.js';
4
+ export { C as Collection, P as PublicCollection } from './const-Dqz05oaG.js';
5
5
  import './metadata.js';
6
- import './types-3qV6sY7T.js';
7
- import './payload-types-BCui2Oml.js';
6
+ import './types-CxzWHspI.js';
7
+ import './payload-types-CREOjFNT.js';
8
8
 
9
9
  declare class Client {
10
10
  commerce: CommerceClient;
package/dist/client.js CHANGED
@@ -745,13 +745,15 @@ var HttpClient = class {
745
745
  };
746
746
 
747
747
  // src/utils/types.ts
748
- var resolveRelation = (ref) => {
748
+ function resolveRelation(ref) {
749
749
  if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
750
750
  return null;
751
751
  return ref;
752
- };
752
+ }
753
753
 
754
754
  // src/core/metadata/index.ts
755
+ var OPEN_GRAPH_IMAGE_SIZE = "1200";
756
+ var LEGACY_OPEN_GRAPH_IMAGE_SIZE = "1536";
755
757
  function extractSeo(doc) {
756
758
  const seo = doc.seo ?? {};
757
759
  const og = seo.openGraph ?? {};
@@ -795,7 +797,7 @@ function generateMetadata(input, options) {
795
797
  function resolveMetaImage(ref) {
796
798
  const image = resolveRelation(ref);
797
799
  if (!image) return null;
798
- const sized = image.sizes?.["1536"];
800
+ const sized = image.sizes?.[OPEN_GRAPH_IMAGE_SIZE] ?? image.sizes?.[LEGACY_OPEN_GRAPH_IMAGE_SIZE];
799
801
  const url = sized?.url || image.url;
800
802
  if (!url) return null;
801
803
  const width = sized?.url ? sized.width : image.width;
@@ -927,13 +929,16 @@ async function parseApiResponse(response, endpoint) {
927
929
  return data;
928
930
  }
929
931
 
930
- // src/core/community/community-client.ts
931
- var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
932
- var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
933
- var CommunityClient = class {
934
- constructor(options) {
932
+ // src/core/api/customer-scoped-api.ts
933
+ var CustomerScopedApi = class {
934
+ constructor(apiName, options) {
935
+ if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
936
+ throw createConfigError(
937
+ `Either secretKey or customerToken is required for ${apiName}.`
938
+ );
939
+ }
935
940
  this.publishableKey = requirePublishableKeyForSecret(
936
- "CommunityClient",
941
+ apiName,
937
942
  options.publishableKey,
938
943
  options.secretKey
939
944
  );
@@ -943,6 +948,44 @@ var CommunityClient = class {
943
948
  this.onUnauthorized = options.onUnauthorized;
944
949
  this.onRequestId = options.onRequestId;
945
950
  }
951
+ async request(endpoint, options) {
952
+ const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
953
+ try {
954
+ const response = await httpFetch(endpoint, {
955
+ method: options.method,
956
+ apiUrl: this.apiUrl,
957
+ publishableKey: this.publishableKey,
958
+ secretKey: this.secretKey,
959
+ customerToken: token ?? void 0,
960
+ ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
961
+ ...options.body !== void 0 && {
962
+ body: JSON.stringify(options.body)
963
+ },
964
+ ...options.headers && { headers: options.headers }
965
+ });
966
+ this.onRequestId?.(response.headers.get("x-request-id") ?? null);
967
+ return parseApiResponse(response, endpoint);
968
+ } catch (err) {
969
+ const id = err instanceof SDKError ? err.requestId ?? null : null;
970
+ this.onRequestId?.(id);
971
+ throw err;
972
+ }
973
+ }
974
+ };
975
+
976
+ // src/core/community/community-client.ts
977
+ var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
978
+ var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
979
+ function unwrapPayloadDoc(value) {
980
+ if (value && typeof value === "object" && "doc" in value) {
981
+ return value.doc;
982
+ }
983
+ return value;
984
+ }
985
+ var CommunityClient = class extends CustomerScopedApi {
986
+ constructor(options) {
987
+ super("CommunityClient", { ...options, requiresCredential: false });
988
+ }
946
989
  buildQuery(params) {
947
990
  if (!params) return "";
948
991
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
@@ -983,27 +1026,14 @@ var CommunityClient = class {
983
1026
  return `/api/comments?${urlParams.toString()}`;
984
1027
  }
985
1028
  async execute(endpoint, method, body) {
986
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
987
- try {
988
- const response = await httpFetch(endpoint, {
989
- method,
990
- apiUrl: this.apiUrl,
991
- publishableKey: this.publishableKey,
992
- secretKey: this.secretKey,
993
- customerToken: token ?? void 0,
994
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
995
- ...body !== void 0 && { body: JSON.stringify(body) }
996
- });
997
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
998
- return parseApiResponse(response, endpoint);
999
- } catch (err) {
1000
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1001
- this.onRequestId?.(id);
1002
- throw err;
1003
- }
1029
+ return this.request(endpoint, { method, body });
1030
+ }
1031
+ async executeDoc(endpoint, method, body) {
1032
+ const response = await this.execute(endpoint, method, body);
1033
+ return unwrapPayloadDoc(response);
1004
1034
  }
1005
1035
  createPost(params) {
1006
- return this.execute("/api/posts", "POST", params);
1036
+ return this.executeDoc("/api/posts", "POST", params);
1007
1037
  }
1008
1038
  /**
1009
1039
  * Public post feed. Server applies the same visibility contract as
@@ -1060,7 +1090,7 @@ var CommunityClient = class {
1060
1090
  if (parentId !== void 0) {
1061
1091
  body.parent = parentId;
1062
1092
  }
1063
- return this.execute("/api/comments", "POST", body);
1093
+ return this.executeDoc("/api/comments", "POST", body);
1064
1094
  }
1065
1095
  /**
1066
1096
  * List comments for a post.
@@ -1098,7 +1128,7 @@ var CommunityClient = class {
1098
1128
  }
1099
1129
  updateComment(params) {
1100
1130
  const { commentId, body } = params;
1101
- return this.execute(
1131
+ return this.executeDoc(
1102
1132
  `/api/comments/${commentId}`,
1103
1133
  "PATCH",
1104
1134
  { body }
@@ -1129,7 +1159,7 @@ var CommunityClient = class {
1129
1159
  400
1130
1160
  );
1131
1161
  }
1132
- return this.execute("/api/reactions", "POST", {
1162
+ return this.executeDoc("/api/reactions", "POST", {
1133
1163
  post: postId,
1134
1164
  type: reactionType
1135
1165
  });
@@ -1151,7 +1181,7 @@ var CommunityClient = class {
1151
1181
  400
1152
1182
  );
1153
1183
  }
1154
- return this.execute("/api/reactions", "POST", {
1184
+ return this.executeDoc("/api/reactions", "POST", {
1155
1185
  comment: commentId,
1156
1186
  type: reactionType
1157
1187
  });
@@ -1183,7 +1213,7 @@ var CommunityClient = class {
1183
1213
  }
1184
1214
  // Bookmarks
1185
1215
  addBookmark(params) {
1186
- return this.execute("/api/bookmarks", "POST", {
1216
+ return this.executeDoc("/api/bookmarks", "POST", {
1187
1217
  post: params.postId
1188
1218
  });
1189
1219
  }
@@ -1434,43 +1464,12 @@ var CustomerNamespace = class {
1434
1464
  };
1435
1465
 
1436
1466
  // src/core/api/cart-api.ts
1437
- var CartApi = class {
1467
+ var CartApi = class extends CustomerScopedApi {
1438
1468
  constructor(options) {
1439
- if (!options.secretKey && !options.customerToken) {
1440
- throw createConfigError(
1441
- "Either secretKey or customerToken is required for CartApi."
1442
- );
1443
- }
1444
- this.publishableKey = requirePublishableKeyForSecret(
1445
- "CartApi",
1446
- options.publishableKey,
1447
- options.secretKey
1448
- );
1449
- this.secretKey = options.secretKey;
1450
- this.apiUrl = options.apiUrl;
1451
- this.customerToken = options.customerToken;
1452
- this.onUnauthorized = options.onUnauthorized;
1453
- this.onRequestId = options.onRequestId;
1469
+ super("CartApi", options);
1454
1470
  }
1455
1471
  async execute(endpoint, method, body) {
1456
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1457
- try {
1458
- const response = await httpFetch(endpoint, {
1459
- method,
1460
- apiUrl: this.apiUrl,
1461
- publishableKey: this.publishableKey,
1462
- secretKey: this.secretKey,
1463
- customerToken: token ?? void 0,
1464
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1465
- ...body !== void 0 && { body: JSON.stringify(body) }
1466
- });
1467
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1468
- return parseApiResponse(response, endpoint);
1469
- } catch (err) {
1470
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1471
- this.onRequestId?.(id);
1472
- throw err;
1473
- }
1472
+ return this.request(endpoint, { method, body });
1474
1473
  }
1475
1474
  getCart(cartId) {
1476
1475
  return this.execute(`/api/carts/${cartId}`, "GET");
@@ -1537,6 +1536,18 @@ function splitIdempotencyKey(params) {
1537
1536
  }
1538
1537
 
1539
1538
  // src/core/commerce/commerce-client.ts
1539
+ var BrowserCommerceApi = class extends CustomerScopedApi {
1540
+ post(endpoint, body, requestOptions) {
1541
+ return this.request(endpoint, {
1542
+ method: "POST",
1543
+ body,
1544
+ headers: requestOptions?.headers
1545
+ });
1546
+ }
1547
+ get(endpoint) {
1548
+ return this.request(endpoint, { method: "GET" });
1549
+ }
1550
+ };
1540
1551
  var CommerceClient = class {
1541
1552
  constructor(options) {
1542
1553
  const cartApi = new CartApi({
@@ -1546,52 +1557,21 @@ var CommerceClient = class {
1546
1557
  onUnauthorized: options.onUnauthorized,
1547
1558
  onRequestId: options.onRequestId
1548
1559
  });
1549
- const execute = async (endpoint, body, requestOptions) => {
1550
- const token = options.customerToken();
1551
- try {
1552
- const response = await httpFetch(endpoint, {
1553
- method: "POST",
1554
- apiUrl: options.apiUrl,
1555
- publishableKey: options.publishableKey,
1556
- customerToken: token ?? void 0,
1557
- ...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized },
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 }
1578
- });
1579
- options.onRequestId?.(response.headers.get("x-request-id") ?? null);
1580
- return parseApiResponse(response, endpoint);
1581
- } catch (err) {
1582
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1583
- options.onRequestId?.(id);
1584
- throw err;
1585
- }
1586
- };
1560
+ const api = new BrowserCommerceApi("CommerceClient", {
1561
+ publishableKey: options.publishableKey,
1562
+ apiUrl: options.apiUrl,
1563
+ customerToken: options.customerToken,
1564
+ onUnauthorized: options.onUnauthorized,
1565
+ onRequestId: options.onRequestId
1566
+ });
1587
1567
  this.product = {
1588
- stockCheck: (params) => execute("/api/products/stock-check", params),
1589
- stockSnapshot: (params) => executeGet(stockSnapshotQuery(params)),
1590
- listingGroups: (params) => executeGet(listingGroupsQuery(params)),
1591
- listingGroupsCatalog: (params) => executeGet(listingGroupsCatalogQuery(params)),
1568
+ stockCheck: (params) => api.post("/api/products/stock-check", params),
1569
+ stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
1570
+ listingGroups: (params) => api.get(listingGroupsQuery(params)),
1571
+ listingGroupsCatalog: (params) => api.get(listingGroupsCatalogQuery(params)),
1592
1572
  detail: async (params) => {
1593
1573
  try {
1594
- const product = await executeGet(productDetailQuery(params));
1574
+ const product = await api.get(productDetailQuery(params));
1595
1575
  return { found: true, product };
1596
1576
  } catch (err) {
1597
1577
  const notFoundResult = productDetailResultFromError(err);
@@ -1601,7 +1581,7 @@ var CommerceClient = class {
1601
1581
  },
1602
1582
  detailCatalog: async (params) => {
1603
1583
  try {
1604
- const product = await executeGet(
1584
+ const product = await api.get(
1605
1585
  productDetailCatalogQuery(params)
1606
1586
  );
1607
1587
  return { found: true, product };
@@ -1624,7 +1604,7 @@ var CommerceClient = class {
1624
1604
  this.orders = {
1625
1605
  checkout: (params) => {
1626
1606
  const { body, idempotencyKey } = splitIdempotencyKey(params);
1627
- return execute(
1607
+ return api.post(
1628
1608
  "/api/orders/checkout",
1629
1609
  body,
1630
1610
  idempotencyRequestOptions(idempotencyKey)
@@ -1633,10 +1613,10 @@ var CommerceClient = class {
1633
1613
  listMine: (params) => options.customerAuth.getMyOrders(params)
1634
1614
  };
1635
1615
  this.discounts = {
1636
- validate: (params) => execute("/api/discounts/validate", params)
1616
+ validate: (params) => api.post("/api/discounts/validate", params)
1637
1617
  };
1638
1618
  this.shipping = {
1639
- calculate: (params) => execute("/api/shipping-policies/calculate", params)
1619
+ calculate: (params) => api.post("/api/shipping-policies/calculate", params)
1640
1620
  };
1641
1621
  }
1642
1622
  };