@01.software/sdk 0.31.0 → 0.32.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 (52) hide show
  1. package/README.md +87 -29
  2. package/dist/analytics/react.cjs.map +1 -1
  3. package/dist/analytics/react.js.map +1 -1
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.js.map +1 -1
  6. package/dist/client.cjs +10 -46
  7. package/dist/client.cjs.map +1 -1
  8. package/dist/client.d.cts +6 -6
  9. package/dist/client.d.ts +6 -6
  10. package/dist/client.js +10 -46
  11. package/dist/client.js.map +1 -1
  12. package/dist/{collection-client-DFXXz0vk.d.cts → collection-client-CORhppPb.d.cts} +3 -3
  13. package/dist/{collection-client-ByzY3hWK.d.ts → collection-client-DPGXnhoF.d.ts} +3 -3
  14. package/dist/{const-AytzliEu.d.cts → const-Brk2Ff0q.d.cts} +1 -1
  15. package/dist/{const-BGCP-OJL.d.ts → const-DcY2_z9O.d.ts} +1 -1
  16. package/dist/index.cjs +58 -47
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +7 -7
  19. package/dist/index.d.ts +7 -7
  20. package/dist/index.js +58 -47
  21. package/dist/index.js.map +1 -1
  22. package/dist/{payload-types-Wa4-eC6x.d.cts → payload-types-DVK1QCeU.d.cts} +8 -2
  23. package/dist/{payload-types-Wa4-eC6x.d.ts → payload-types-DVK1QCeU.d.ts} +8 -2
  24. package/dist/query.cjs.map +1 -1
  25. package/dist/query.d.cts +16 -16
  26. package/dist/query.d.ts +16 -16
  27. package/dist/query.js.map +1 -1
  28. package/dist/realtime.cjs.map +1 -1
  29. package/dist/realtime.d.cts +2 -2
  30. package/dist/realtime.d.ts +2 -2
  31. package/dist/realtime.js.map +1 -1
  32. package/dist/server.cjs +34 -1
  33. package/dist/server.cjs.map +1 -1
  34. package/dist/server.d.cts +99 -7
  35. package/dist/server.d.ts +99 -7
  36. package/dist/server.js +34 -1
  37. package/dist/server.js.map +1 -1
  38. package/dist/{types-CmLG-7RL.d.cts → types-ByMrR_Z_.d.cts} +1 -1
  39. package/dist/{types-DChFjQGz.d.cts → types-CAkWqIr6.d.cts} +41 -8
  40. package/dist/{types-BX2mqDf6.d.ts → types-CYMSBkJC.d.ts} +41 -8
  41. package/dist/{types-CVA10VC-.d.ts → types-DUPC7Xn6.d.ts} +1 -1
  42. package/dist/ui/form.d.cts +1 -1
  43. package/dist/ui/form.d.ts +1 -1
  44. package/dist/ui/video.d.cts +1 -1
  45. package/dist/ui/video.d.ts +1 -1
  46. package/dist/webhook.cjs +48 -1
  47. package/dist/webhook.cjs.map +1 -1
  48. package/dist/webhook.d.cts +73 -4
  49. package/dist/webhook.d.ts +73 -4
  50. package/dist/webhook.js +48 -1
  51. package/dist/webhook.js.map +1 -1
  52. package/package.json +3 -3
@@ -1,7 +1,7 @@
1
- import { D as DebugConfig, R as RetryConfig, A as ApiQueryOptions, P as PayloadFindResponse, g as PayloadMutationResponse } from './types-DChFjQGz.cjs';
1
+ import { D as DebugConfig, R as RetryConfig, A as ApiQueryOptions, P as PayloadFindResponse, g as PayloadMutationResponse } from './types-CAkWqIr6.cjs';
2
2
  import { GenerateMetadataOptions, Metadata } from './metadata.cjs';
3
- import { c as ServerCollection, P as PublicCollection } from './const-AytzliEu.cjs';
4
- import { C as CollectionType } from './types-CmLG-7RL.cjs';
3
+ import { c as ServerCollection, P as PublicCollection } from './const-Brk2Ff0q.cjs';
4
+ import { C as CollectionType } from './types-ByMrR_Z_.cjs';
5
5
 
6
6
  interface FetchOptions extends RequestInit {
7
7
  apiUrl?: string;
@@ -1,7 +1,7 @@
1
- import { D as DebugConfig, R as RetryConfig, A as ApiQueryOptions, P as PayloadFindResponse, g as PayloadMutationResponse } from './types-BX2mqDf6.js';
1
+ import { D as DebugConfig, R as RetryConfig, A as ApiQueryOptions, P as PayloadFindResponse, g as PayloadMutationResponse } from './types-CYMSBkJC.js';
2
2
  import { GenerateMetadataOptions, Metadata } from './metadata.js';
3
- import { c as ServerCollection, P as PublicCollection } from './const-BGCP-OJL.js';
4
- import { C as CollectionType } from './types-CVA10VC-.js';
3
+ import { c as ServerCollection, P as PublicCollection } from './const-DcY2_z9O.js';
4
+ import { C as CollectionType } from './types-DUPC7Xn6.js';
5
5
 
6
6
  interface FetchOptions extends RequestInit {
7
7
  apiUrl?: string;
@@ -1,4 +1,4 @@
1
- import { e as Config } from './payload-types-Wa4-eC6x.cjs';
1
+ import { e as Config } from './payload-types-DVK1QCeU.cjs';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -1,4 +1,4 @@
1
- import { e as Config } from './payload-types-Wa4-eC6x.js';
1
+ import { e as Config } from './payload-types-DVK1QCeU.js';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
package/dist/index.cjs CHANGED
@@ -38,6 +38,7 @@ __export(src_exports, {
38
38
  INTERNAL_COLLECTIONS: () => INTERNAL_COLLECTIONS,
39
39
  NetworkError: () => NetworkError,
40
40
  NotFoundError: () => NotFoundError,
41
+ ORDER_CHANGED_EVENT_TYPE: () => ORDER_CHANGED_EVENT_TYPE,
41
42
  OrderApi: () => OrderApi,
42
43
  PermissionError: () => PermissionError,
43
44
  ProductApi: () => ProductApi,
@@ -92,6 +93,7 @@ __export(src_exports, {
92
93
  isGoneError: () => isGoneError,
93
94
  isNetworkError: () => isNetworkError,
94
95
  isNotFoundError: () => isNotFoundError,
96
+ isOrderChangedWebhookEvent: () => isOrderChangedWebhookEvent,
95
97
  isPermissionError: () => isPermissionError,
96
98
  isRateLimitError: () => isRateLimitError,
97
99
  isSDKError: () => isSDKError,
@@ -100,6 +102,8 @@ __export(src_exports, {
100
102
  isUsageLimitError: () => isUsageLimitError,
101
103
  isValidWebhookEvent: () => isValidWebhookEvent,
102
104
  isValidationError: () => isValidationError,
105
+ isWebhookCollection: () => isWebhookCollection,
106
+ isWebhookOperation: () => isWebhookOperation,
103
107
  normalizeProductSelection: () => normalizeProductSelection,
104
108
  normalizeProductSelectionFromMatrix: () => normalizeProductSelectionFromMatrix,
105
109
  normalizeSelectedValueIds: () => normalizeSelectedValueIds,
@@ -1340,7 +1344,7 @@ var CustomerAuth = class {
1340
1344
  );
1341
1345
  return data.customer ?? null;
1342
1346
  } catch (error) {
1343
- if (error instanceof ApiError && error.status === 401) {
1347
+ if (error instanceof SDKError && error.status === 401) {
1344
1348
  this.setToken(null);
1345
1349
  return null;
1346
1350
  }
@@ -1435,51 +1439,15 @@ var CustomerAuth = class {
1435
1439
  if (!headers.has("Content-Type") && init.body) {
1436
1440
  headers.set("Content-Type", "application/json");
1437
1441
  }
1438
- const controller = new AbortController();
1439
- const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT2);
1440
- let res;
1441
- try {
1442
- res = await fetch(`${this.baseUrl}${path}`, {
1443
- ...init,
1444
- headers,
1445
- signal: controller.signal
1446
- });
1447
- } catch (error) {
1448
- clearTimeout(timeoutId);
1449
- if (error instanceof Error && error.name === "AbortError") {
1450
- throw new TimeoutError(`Request timed out after ${DEFAULT_TIMEOUT2}ms`, {
1451
- url: path,
1452
- timeout: DEFAULT_TIMEOUT2
1453
- });
1454
- }
1455
- throw new NetworkError(
1456
- error instanceof Error ? error.message : "Network request failed",
1457
- void 0,
1458
- { url: path },
1459
- "Network connection failed.",
1460
- "Please check your internet connection and try again."
1461
- );
1462
- }
1463
- clearTimeout(timeoutId);
1464
- if (!res.ok) {
1465
- const body = await res.json().catch(() => ({}));
1466
- throw new ApiError(
1467
- body.error || `HTTP ${res.status}`,
1468
- res.status,
1469
- body.details,
1470
- body.error
1471
- );
1472
- }
1473
- try {
1474
- return await res.json();
1475
- } catch {
1476
- throw new ApiError(
1477
- "Invalid JSON response from server",
1478
- res.status,
1479
- void 0,
1480
- "INVALID_RESPONSE"
1481
- );
1482
- }
1442
+ const response = await httpFetch(path, {
1443
+ ...init,
1444
+ apiUrl: this.baseUrl,
1445
+ publishableKey: this.publishableKey,
1446
+ headers,
1447
+ timeout: DEFAULT_TIMEOUT2,
1448
+ retry: { maxRetries: 0 }
1449
+ });
1450
+ return parseApiResponse(response, path);
1483
1451
  }
1484
1452
  };
1485
1453
 
@@ -1816,7 +1784,7 @@ var ProductApi = class extends BaseApi {
1816
1784
  /**
1817
1785
  * Fetch full product detail by slug or id.
1818
1786
  * Returns `null` on 404 regardless of reason (`not_found` / `not_published` /
1819
- * `tenant_mismatch` / `feature_disabled`). For the reason behind a null,
1787
+ * `feature_disabled`). For the reason behind a null,
1820
1788
  * inspect `client.lastRequestId` against backend logs.
1821
1789
  */
1822
1790
  async detail(params) {
@@ -1839,11 +1807,54 @@ var ProductApi = class extends BaseApi {
1839
1807
  };
1840
1808
 
1841
1809
  // src/core/webhook/index.ts
1810
+ var ORDER_CHANGED_EVENT_TYPE = "collection.orderChanged";
1842
1811
  function isValidWebhookEvent(data) {
1843
1812
  if (typeof data !== "object" || data === null) return false;
1844
1813
  const obj = data;
1845
1814
  return typeof obj.collection === "string" && typeof obj.operation === "string" && obj.operation.length > 0 && typeof obj.data === "object" && obj.data !== null;
1846
1815
  }
1816
+ function isStringOrNumber(value) {
1817
+ return typeof value === "string" || typeof value === "number";
1818
+ }
1819
+ function isWebhookOrderScope(value) {
1820
+ if (!isRecord(value)) return false;
1821
+ if (value.kind === "collection") {
1822
+ return typeof value.collection === "string";
1823
+ }
1824
+ if (value.kind === "join") {
1825
+ return typeof value.collection === "string" && typeof value.field === "string" && isStringOrNumber(value.id);
1826
+ }
1827
+ return false;
1828
+ }
1829
+ function isWebhookOrderMoved(value) {
1830
+ if (!isRecord(value)) return false;
1831
+ return typeof value.collection === "string" && isStringOrNumber(value.id) && (value.relatedCollection === void 0 || typeof value.relatedCollection === "string") && (value.relatedId === void 0 || isStringOrNumber(value.relatedId));
1832
+ }
1833
+ function hasOptionalOrderValue(value, key) {
1834
+ return value[key] === void 0 || value[key] === null || typeof value[key] === "string";
1835
+ }
1836
+ function isWebhookOrderChange(value) {
1837
+ if (!isRecord(value)) return false;
1838
+ return value.type === "order" && value.source === "payload-orderable" && (value.orderableFieldName === void 0 || typeof value.orderableFieldName === "string") && hasOptionalOrderValue(value, "previousOrder") && hasOptionalOrderValue(value, "nextOrder") && isWebhookOrderScope(value.scope) && isWebhookOrderMoved(value.moved);
1839
+ }
1840
+ function isOrderChangedWebhookEvent(event) {
1841
+ if (!isValidWebhookEvent(event) || event.operation !== "update" || event.eventType !== ORDER_CHANGED_EVENT_TYPE || !isWebhookOrderChange(event.change)) {
1842
+ return false;
1843
+ }
1844
+ if (event.collection !== event.change.scope.collection) {
1845
+ return false;
1846
+ }
1847
+ if (event.change.scope.kind === "collection" && event.change.moved.collection !== event.change.scope.collection) {
1848
+ return false;
1849
+ }
1850
+ return true;
1851
+ }
1852
+ function isWebhookCollection(event, collection) {
1853
+ return isValidWebhookEvent(event) && event.collection === collection;
1854
+ }
1855
+ function isWebhookOperation(event, operation) {
1856
+ return isValidWebhookEvent(event) && event.operation === operation;
1857
+ }
1847
1858
  var CUSTOMER_PASSWORD_RESET_OPERATION = "password-reset";
1848
1859
  function isRecord(value) {
1849
1860
  return typeof value === "object" && value !== null;