@01.software/sdk 0.35.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-DkREjhQ9.d.ts → collection-client-DyELGUcL.d.ts} +3 -3
  21. package/dist/{collection-client-CR2B8c1v.d.cts → collection-client-zOmnxwdA.d.cts} +3 -3
  22. package/dist/{const-CdqCauHQ.d.ts → const-CK_FPaIn.d.cts} +3 -3
  23. package/dist/{const-BTvdrXtY.d.cts → 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-DK8_NXkh.d.ts → index-DRJs7QIh.d.cts} +9 -6
  27. package/dist/{index-CjA3U6X3.d.cts → index-DTqoUZk_.d.ts} +9 -6
  28. package/dist/index.cjs +229 -136
  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 +229 -136
  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-C7tb7Xbs.d.cts → payload-types-CREOjFNT.d.cts} +281 -128
  39. package/dist/{payload-types-C7tb7Xbs.d.ts → payload-types-CREOjFNT.d.ts} +281 -128
  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 +99 -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 +99 -69
  53. package/dist/server.js.map +1 -1
  54. package/dist/{types-DDhtZI6E.d.cts → types-BWMUr3Zw.d.cts} +274 -84
  55. package/dist/{types-Bx558PU6.d.cts → types-BkZNhuBh.d.cts} +1 -1
  56. package/dist/{types-1ylMrCuW.d.ts → types-CxzWHspI.d.ts} +1 -1
  57. package/dist/{types-Byo_Rty4.d.ts → types-DMvVHdb1.d.ts} +274 -84
  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
@@ -1,7 +1,7 @@
1
1
  import { R as RealtimeEvent } from './realtime-D7HtUpqt.cjs';
2
2
  export { a as RealtimeConnection, b as RealtimeListener } from './realtime-D7HtUpqt.cjs';
3
- import { P as PublicCollection } from './const-BTvdrXtY.cjs';
4
- import './payload-types-C7tb7Xbs.cjs';
3
+ import { P as PublicCollection } from './const-CK_FPaIn.cjs';
4
+ import './payload-types-CREOjFNT.cjs';
5
5
 
6
6
  interface UseRealtimeQueryOptions {
7
7
  /** Filter events to specific collections. Empty/undefined = all collections. */
@@ -1,7 +1,7 @@
1
1
  import { R as RealtimeEvent } from './realtime-D7HtUpqt.js';
2
2
  export { a as RealtimeConnection, b as RealtimeListener } from './realtime-D7HtUpqt.js';
3
- import { P as PublicCollection } from './const-CdqCauHQ.js';
4
- import './payload-types-C7tb7Xbs.js';
3
+ import { P as PublicCollection } from './const-Dqz05oaG.js';
4
+ import './payload-types-CREOjFNT.js';
5
5
 
6
6
  interface UseRealtimeQueryOptions {
7
7
  /** Filter events to specific collections. Empty/undefined = all collections. */
package/dist/server.cjs CHANGED
@@ -780,13 +780,15 @@ var HttpClient = class {
780
780
  };
781
781
 
782
782
  // src/utils/types.ts
783
- var resolveRelation = (ref) => {
783
+ function resolveRelation(ref) {
784
784
  if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
785
785
  return null;
786
786
  return ref;
787
- };
787
+ }
788
788
 
789
789
  // src/core/metadata/index.ts
790
+ var OPEN_GRAPH_IMAGE_SIZE = "1200";
791
+ var LEGACY_OPEN_GRAPH_IMAGE_SIZE = "1536";
790
792
  function extractSeo(doc) {
791
793
  const seo = doc.seo ?? {};
792
794
  const og = seo.openGraph ?? {};
@@ -830,7 +832,7 @@ function generateMetadata(input, options) {
830
832
  function resolveMetaImage(ref) {
831
833
  const image = resolveRelation(ref);
832
834
  if (!image) return null;
833
- const sized = image.sizes?.["1536"];
835
+ const sized = image.sizes?.[OPEN_GRAPH_IMAGE_SIZE] ?? image.sizes?.[LEGACY_OPEN_GRAPH_IMAGE_SIZE];
834
836
  const url = sized?.url || image.url;
835
837
  if (!url) return null;
836
838
  const width = sized?.url ? sized.width : image.width;
@@ -1188,13 +1190,16 @@ async function parseApiResponse(response, endpoint) {
1188
1190
  return data;
1189
1191
  }
1190
1192
 
1191
- // src/core/community/community-client.ts
1192
- var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
1193
- var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
1194
- var CommunityClient = class {
1195
- constructor(options) {
1193
+ // src/core/api/customer-scoped-api.ts
1194
+ var CustomerScopedApi = class {
1195
+ constructor(apiName, options) {
1196
+ if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
1197
+ throw createConfigError(
1198
+ `Either secretKey or customerToken is required for ${apiName}.`
1199
+ );
1200
+ }
1196
1201
  this.publishableKey = requirePublishableKeyForSecret(
1197
- "CommunityClient",
1202
+ apiName,
1198
1203
  options.publishableKey,
1199
1204
  options.secretKey
1200
1205
  );
@@ -1204,6 +1209,44 @@ var CommunityClient = class {
1204
1209
  this.onUnauthorized = options.onUnauthorized;
1205
1210
  this.onRequestId = options.onRequestId;
1206
1211
  }
1212
+ async request(endpoint, options) {
1213
+ const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1214
+ try {
1215
+ const response = await httpFetch(endpoint, {
1216
+ method: options.method,
1217
+ apiUrl: this.apiUrl,
1218
+ publishableKey: this.publishableKey,
1219
+ secretKey: this.secretKey,
1220
+ customerToken: token ?? void 0,
1221
+ ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1222
+ ...options.body !== void 0 && {
1223
+ body: JSON.stringify(options.body)
1224
+ },
1225
+ ...options.headers && { headers: options.headers }
1226
+ });
1227
+ this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1228
+ return parseApiResponse(response, endpoint);
1229
+ } catch (err) {
1230
+ const id = err instanceof SDKError ? err.requestId ?? null : null;
1231
+ this.onRequestId?.(id);
1232
+ throw err;
1233
+ }
1234
+ }
1235
+ };
1236
+
1237
+ // src/core/community/community-client.ts
1238
+ var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
1239
+ var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
1240
+ function unwrapPayloadDoc(value) {
1241
+ if (value && typeof value === "object" && "doc" in value) {
1242
+ return value.doc;
1243
+ }
1244
+ return value;
1245
+ }
1246
+ var CommunityClient = class extends CustomerScopedApi {
1247
+ constructor(options) {
1248
+ super("CommunityClient", { ...options, requiresCredential: false });
1249
+ }
1207
1250
  buildQuery(params) {
1208
1251
  if (!params) return "";
1209
1252
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
@@ -1244,27 +1287,14 @@ var CommunityClient = class {
1244
1287
  return `/api/comments?${urlParams.toString()}`;
1245
1288
  }
1246
1289
  async execute(endpoint, method, body) {
1247
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1248
- try {
1249
- const response = await httpFetch(endpoint, {
1250
- method,
1251
- apiUrl: this.apiUrl,
1252
- publishableKey: this.publishableKey,
1253
- secretKey: this.secretKey,
1254
- customerToken: token ?? void 0,
1255
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1256
- ...body !== void 0 && { body: JSON.stringify(body) }
1257
- });
1258
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1259
- return parseApiResponse(response, endpoint);
1260
- } catch (err) {
1261
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1262
- this.onRequestId?.(id);
1263
- throw err;
1264
- }
1290
+ return this.request(endpoint, { method, body });
1291
+ }
1292
+ async executeDoc(endpoint, method, body) {
1293
+ const response = await this.execute(endpoint, method, body);
1294
+ return unwrapPayloadDoc(response);
1265
1295
  }
1266
1296
  createPost(params) {
1267
- return this.execute("/api/posts", "POST", params);
1297
+ return this.executeDoc("/api/posts", "POST", params);
1268
1298
  }
1269
1299
  /**
1270
1300
  * Public post feed. Server applies the same visibility contract as
@@ -1321,7 +1351,7 @@ var CommunityClient = class {
1321
1351
  if (parentId !== void 0) {
1322
1352
  body.parent = parentId;
1323
1353
  }
1324
- return this.execute("/api/comments", "POST", body);
1354
+ return this.executeDoc("/api/comments", "POST", body);
1325
1355
  }
1326
1356
  /**
1327
1357
  * List comments for a post.
@@ -1359,7 +1389,7 @@ var CommunityClient = class {
1359
1389
  }
1360
1390
  updateComment(params) {
1361
1391
  const { commentId, body } = params;
1362
- return this.execute(
1392
+ return this.executeDoc(
1363
1393
  `/api/comments/${commentId}`,
1364
1394
  "PATCH",
1365
1395
  { body }
@@ -1390,7 +1420,7 @@ var CommunityClient = class {
1390
1420
  400
1391
1421
  );
1392
1422
  }
1393
- return this.execute("/api/reactions", "POST", {
1423
+ return this.executeDoc("/api/reactions", "POST", {
1394
1424
  post: postId,
1395
1425
  type: reactionType
1396
1426
  });
@@ -1412,7 +1442,7 @@ var CommunityClient = class {
1412
1442
  400
1413
1443
  );
1414
1444
  }
1415
- return this.execute("/api/reactions", "POST", {
1445
+ return this.executeDoc("/api/reactions", "POST", {
1416
1446
  comment: commentId,
1417
1447
  type: reactionType
1418
1448
  });
@@ -1444,7 +1474,7 @@ var CommunityClient = class {
1444
1474
  }
1445
1475
  // Bookmarks
1446
1476
  addBookmark(params) {
1447
- return this.execute("/api/bookmarks", "POST", {
1477
+ return this.executeDoc("/api/bookmarks", "POST", {
1448
1478
  post: params.postId
1449
1479
  });
1450
1480
  }
@@ -1539,43 +1569,12 @@ var ModerationApi = class extends BaseApi {
1539
1569
  };
1540
1570
 
1541
1571
  // src/core/api/cart-api.ts
1542
- var CartApi = class {
1572
+ var CartApi = class extends CustomerScopedApi {
1543
1573
  constructor(options) {
1544
- if (!options.secretKey && !options.customerToken) {
1545
- throw createConfigError(
1546
- "Either secretKey or customerToken is required for CartApi."
1547
- );
1548
- }
1549
- this.publishableKey = requirePublishableKeyForSecret(
1550
- "CartApi",
1551
- options.publishableKey,
1552
- options.secretKey
1553
- );
1554
- this.secretKey = options.secretKey;
1555
- this.apiUrl = options.apiUrl;
1556
- this.customerToken = options.customerToken;
1557
- this.onUnauthorized = options.onUnauthorized;
1558
- this.onRequestId = options.onRequestId;
1574
+ super("CartApi", options);
1559
1575
  }
1560
1576
  async execute(endpoint, method, body) {
1561
- const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1562
- try {
1563
- const response = await httpFetch(endpoint, {
1564
- method,
1565
- apiUrl: this.apiUrl,
1566
- publishableKey: this.publishableKey,
1567
- secretKey: this.secretKey,
1568
- customerToken: token ?? void 0,
1569
- ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1570
- ...body !== void 0 && { body: JSON.stringify(body) }
1571
- });
1572
- this.onRequestId?.(response.headers.get("x-request-id") ?? null);
1573
- return parseApiResponse(response, endpoint);
1574
- } catch (err) {
1575
- const id = err instanceof SDKError ? err.requestId ?? null : null;
1576
- this.onRequestId?.(id);
1577
- throw err;
1578
- }
1577
+ return this.request(endpoint, { method, body });
1579
1578
  }
1580
1579
  getCart(cartId) {
1581
1580
  return this.execute(`/api/carts/${cartId}`, "GET");
@@ -1775,15 +1774,24 @@ function splitIdempotencyKey(params) {
1775
1774
  const { idempotencyKey, ...body } = params;
1776
1775
  return { body, idempotencyKey };
1777
1776
  }
1777
+ function normalizeCreateOrderBody(params) {
1778
+ if (params.items !== void 0) {
1779
+ const { idempotencyKey: _idempotencyKey2, items, ...rest } = params;
1780
+ return { ...rest, orderItems: items };
1781
+ }
1782
+ const { idempotencyKey: _idempotencyKey, ...body } = params;
1783
+ return body;
1784
+ }
1778
1785
  var OrderApi = class extends BaseApi {
1779
1786
  constructor(options) {
1780
1787
  super("OrderApi", options);
1781
1788
  }
1782
1789
  createOrder(params) {
1783
- const { body, idempotencyKey } = splitIdempotencyKey(params);
1790
+ const { idempotencyKey } = params;
1791
+ const normalizedBody = normalizeCreateOrderBody(params);
1784
1792
  return this.request(
1785
1793
  "/api/orders/create",
1786
- body,
1794
+ normalizedBody,
1787
1795
  idempotencyRequestOptions(idempotencyKey)
1788
1796
  );
1789
1797
  }
@@ -1815,6 +1823,20 @@ var OrderApi = class extends BaseApi {
1815
1823
  idempotencyKey ? { headers: { "X-Idempotency-Key": idempotencyKey } } : void 0
1816
1824
  );
1817
1825
  }
1826
+ resolveCancelRefund(params) {
1827
+ return this.request(
1828
+ "/api/orders/resolve-cancel-refund",
1829
+ {
1830
+ orderNumber: params.orderNumber,
1831
+ idempotencyKey: params.idempotencyKey,
1832
+ outcome: params.outcome,
1833
+ refundedAmount: params.refundedAmount,
1834
+ pgProvider: params.pgProvider,
1835
+ ...params.pgRefundId ? { pgRefundId: params.pgRefundId } : {}
1836
+ },
1837
+ idempotencyRequestOptions(params.idempotencyKey)
1838
+ );
1839
+ }
1818
1840
  checkout(params) {
1819
1841
  const { body, idempotencyKey } = splitIdempotencyKey(params);
1820
1842
  return this.request(
@@ -1831,6 +1853,12 @@ var OrderApi = class extends BaseApi {
1831
1853
  idempotencyRequestOptions(idempotencyKey)
1832
1854
  );
1833
1855
  }
1856
+ prepareFulfillmentOrder(params) {
1857
+ return this.request(
1858
+ "/api/fulfillment-orders/prepare-fulfillment-order",
1859
+ params
1860
+ );
1861
+ }
1834
1862
  updateFulfillment(params) {
1835
1863
  return this.request("/api/orders/update-fulfillment", params);
1836
1864
  }
@@ -1957,7 +1985,9 @@ var ServerCommerceClient = class {
1957
1985
  updateTransaction: orderApi.updateTransaction.bind(orderApi),
1958
1986
  confirmPayment: orderApi.confirmPayment.bind(orderApi),
1959
1987
  cancelOrder: orderApi.cancelOrder.bind(orderApi),
1988
+ resolveCancelRefund: orderApi.resolveCancelRefund.bind(orderApi),
1960
1989
  createFulfillment: orderApi.createFulfillment.bind(orderApi),
1990
+ prepareFulfillmentOrder: orderApi.prepareFulfillmentOrder.bind(orderApi),
1961
1991
  updateFulfillment: orderApi.updateFulfillment.bind(orderApi),
1962
1992
  bulkImportFulfillments: orderApi.bulkImportFulfillments.bind(orderApi),
1963
1993
  createReturn: orderApi.createReturn.bind(orderApi),