@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
@@ -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-DVcM7Ac_.cjs';
4
- import './payload-types-BCui2Oml.cjs';
3
+ import { P as PublicCollection } from './const-B5KT72c7.cjs';
4
+ import './payload-types-m3jjhxk9.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-BDUKFP9w.js';
4
- import './payload-types-BCui2Oml.js';
3
+ import { P as PublicCollection } from './const-6XHz_jej.js';
4
+ import './payload-types-m3jjhxk9.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)]);
@@ -1213,7 +1256,8 @@ var CommunityClient = class {
1213
1256
  const urlParams = new URLSearchParams();
1214
1257
  const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
1215
1258
  urlParams.set("sort", sort);
1216
- if (params?.limit !== void 0) urlParams.set("limit", String(params.limit));
1259
+ if (params?.limit !== void 0)
1260
+ urlParams.set("limit", String(params.limit));
1217
1261
  if (params?.page !== void 0) urlParams.set("page", String(params.page));
1218
1262
  if (params?.categoryId !== void 0) {
1219
1263
  urlParams.set("where[categories][in]", params.categoryId);
@@ -1221,7 +1265,7 @@ var CommunityClient = class {
1221
1265
  if (params?.tagId !== void 0) {
1222
1266
  urlParams.set("where[tags][in]", params.tagId);
1223
1267
  }
1224
- return `/api/posts?${urlParams.toString()}`;
1268
+ return `/api/posts/public?${urlParams.toString()}`;
1225
1269
  }
1226
1270
  buildCommentsListQuery(params) {
1227
1271
  const urlParams = new URLSearchParams();
@@ -1241,30 +1285,21 @@ var CommunityClient = class {
1241
1285
  }
1242
1286
  if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
1243
1287
  if (params.page !== void 0) urlParams.set("page", String(params.page));
1244
- return `/api/comments?${urlParams.toString()}`;
1288
+ return `/api/comments/public?${urlParams.toString()}`;
1245
1289
  }
1246
1290
  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
- }
1291
+ return this.request(endpoint, { method, body });
1292
+ }
1293
+ async executeDoc(endpoint, method, body) {
1294
+ const response = await this.execute(endpoint, method, body);
1295
+ return unwrapPayloadDoc(response);
1265
1296
  }
1266
1297
  createPost(params) {
1267
- return this.execute("/api/posts", "POST", params);
1298
+ return this.executeDoc(
1299
+ "/api/posts",
1300
+ "POST",
1301
+ params
1302
+ );
1268
1303
  }
1269
1304
  /**
1270
1305
  * Public post feed. Server applies the same visibility contract as
@@ -1321,7 +1356,11 @@ var CommunityClient = class {
1321
1356
  if (parentId !== void 0) {
1322
1357
  body.parent = parentId;
1323
1358
  }
1324
- return this.execute("/api/comments", "POST", body);
1359
+ return this.executeDoc(
1360
+ "/api/comments",
1361
+ "POST",
1362
+ body
1363
+ );
1325
1364
  }
1326
1365
  /**
1327
1366
  * List comments for a post.
@@ -1359,7 +1398,7 @@ var CommunityClient = class {
1359
1398
  }
1360
1399
  updateComment(params) {
1361
1400
  const { commentId, body } = params;
1362
- return this.execute(
1401
+ return this.executeDoc(
1363
1402
  `/api/comments/${commentId}`,
1364
1403
  "PATCH",
1365
1404
  { body }
@@ -1390,10 +1429,14 @@ var CommunityClient = class {
1390
1429
  400
1391
1430
  );
1392
1431
  }
1393
- return this.execute("/api/reactions", "POST", {
1394
- post: postId,
1395
- type: reactionType
1396
- });
1432
+ return this.executeDoc(
1433
+ "/api/reactions",
1434
+ "POST",
1435
+ {
1436
+ post: postId,
1437
+ type: reactionType
1438
+ }
1439
+ );
1397
1440
  }
1398
1441
  removeReaction(params) {
1399
1442
  const { postId, type } = params;
@@ -1412,10 +1455,14 @@ var CommunityClient = class {
1412
1455
  400
1413
1456
  );
1414
1457
  }
1415
- return this.execute("/api/reactions", "POST", {
1416
- comment: commentId,
1417
- type: reactionType
1418
- });
1458
+ return this.executeDoc(
1459
+ "/api/reactions",
1460
+ "POST",
1461
+ {
1462
+ comment: commentId,
1463
+ type: reactionType
1464
+ }
1465
+ );
1419
1466
  }
1420
1467
  removeCommentReaction(params) {
1421
1468
  const { commentId, type } = params;
@@ -1444,9 +1491,13 @@ var CommunityClient = class {
1444
1491
  }
1445
1492
  // Bookmarks
1446
1493
  addBookmark(params) {
1447
- return this.execute("/api/bookmarks", "POST", {
1448
- post: params.postId
1449
- });
1494
+ return this.executeDoc(
1495
+ "/api/bookmarks",
1496
+ "POST",
1497
+ {
1498
+ post: params.postId
1499
+ }
1500
+ );
1450
1501
  }
1451
1502
  removeBookmark(params) {
1452
1503
  return this.execute(
@@ -1462,10 +1513,7 @@ var CommunityClient = class {
1462
1513
  }
1463
1514
  // Profiles
1464
1515
  listProfileLists(params) {
1465
- return this.execute(
1466
- `/api/customer-profile-lists${this.buildQuery(params)}`,
1467
- "GET"
1468
- );
1516
+ return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
1469
1517
  }
1470
1518
  async getProfileList(params) {
1471
1519
  const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
@@ -1539,46 +1587,18 @@ var ModerationApi = class extends BaseApi {
1539
1587
  };
1540
1588
 
1541
1589
  // src/core/api/cart-api.ts
1542
- var CartApi = class {
1590
+ var CartApi = class extends CustomerScopedApi {
1543
1591
  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;
1592
+ super("CartApi", options);
1559
1593
  }
1560
1594
  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
- }
1595
+ return this.request(endpoint, { method, body });
1579
1596
  }
1580
1597
  getCart(cartId) {
1581
- return this.execute(`/api/carts/${cartId}`, "GET");
1598
+ return this.execute(
1599
+ `/api/carts/${cartId}?depth=0&joins=false`,
1600
+ "GET"
1601
+ );
1582
1602
  }
1583
1603
  addItem(params) {
1584
1604
  return this.execute("/api/carts/add-item", "POST", params);
@@ -1775,15 +1795,24 @@ function splitIdempotencyKey(params) {
1775
1795
  const { idempotencyKey, ...body } = params;
1776
1796
  return { body, idempotencyKey };
1777
1797
  }
1798
+ function normalizeCreateOrderBody(params) {
1799
+ if (params.items !== void 0) {
1800
+ const { idempotencyKey: _idempotencyKey2, items, ...rest } = params;
1801
+ return { ...rest, orderItems: items };
1802
+ }
1803
+ const { idempotencyKey: _idempotencyKey, ...body } = params;
1804
+ return body;
1805
+ }
1778
1806
  var OrderApi = class extends BaseApi {
1779
1807
  constructor(options) {
1780
1808
  super("OrderApi", options);
1781
1809
  }
1782
1810
  createOrder(params) {
1783
- const { body, idempotencyKey } = splitIdempotencyKey(params);
1811
+ const { idempotencyKey } = params;
1812
+ const normalizedBody = normalizeCreateOrderBody(params);
1784
1813
  return this.request(
1785
1814
  "/api/orders/create",
1786
- body,
1815
+ normalizedBody,
1787
1816
  idempotencyRequestOptions(idempotencyKey)
1788
1817
  );
1789
1818
  }
@@ -1845,6 +1874,12 @@ var OrderApi = class extends BaseApi {
1845
1874
  idempotencyRequestOptions(idempotencyKey)
1846
1875
  );
1847
1876
  }
1877
+ prepareFulfillmentOrder(params) {
1878
+ return this.request(
1879
+ "/api/fulfillment-orders/prepare-fulfillment-order",
1880
+ params
1881
+ );
1882
+ }
1848
1883
  updateFulfillment(params) {
1849
1884
  return this.request("/api/orders/update-fulfillment", params);
1850
1885
  }
@@ -1973,6 +2008,7 @@ var ServerCommerceClient = class {
1973
2008
  cancelOrder: orderApi.cancelOrder.bind(orderApi),
1974
2009
  resolveCancelRefund: orderApi.resolveCancelRefund.bind(orderApi),
1975
2010
  createFulfillment: orderApi.createFulfillment.bind(orderApi),
2011
+ prepareFulfillmentOrder: orderApi.prepareFulfillmentOrder.bind(orderApi),
1976
2012
  updateFulfillment: orderApi.updateFulfillment.bind(orderApi),
1977
2013
  bulkImportFulfillments: orderApi.bulkImportFulfillments.bind(orderApi),
1978
2014
  createReturn: orderApi.createReturn.bind(orderApi),