@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
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-B0J9wMNE.cjs';
2
+ import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-CIGscmus.cjs';
3
+ export { A as AddItemParams, e as ApiQueryOptions, f as ApplyDiscountParams, g as CheckoutParams, h as ClearCartParams, i as ClientMetadata, D as DebugConfig, j as DeepPartial, k as ExtractArrayType, P as PayloadFindResponse, l as PayloadMutationResponse, m as PublicCart, n as PublicCartItem, o as PublicCartReference, p as PublicMediaAsset, q as PublicMediaSize, r as PublicOrder, s as PublicOrderItem, t as PublicOrderReference, R as RemoveDiscountParams, u as RemoveItemParams, v as RetryConfig, w as RootClient, w as RootClientType, x as RootCollectionClient, y as RootReadOnlyQueryBuilder, S as Sort, U as UpdateItemParams, W as Where } from './types-CIGscmus.cjs';
4
+ import './payload-types-m3jjhxk9.cjs';
5
+ export { C as Collection, P as PublicCollection } from './const-B5KT72c7.cjs';
5
6
  import './metadata.cjs';
6
- import './types-CEzLf3PX.cjs';
7
- import './payload-types-BCui2Oml.cjs';
7
+ import './types-D0ubzQw0.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-BroIWHY1.js';
2
+ import { C as CommerceClient, a as CommunityClient, E as EventsClient, b as CustomerNamespace, c as ClientState, d as ClientConfig } from './types-D2xYdz4P.js';
3
+ export { A as AddItemParams, e as ApiQueryOptions, f as ApplyDiscountParams, g as CheckoutParams, h as ClearCartParams, i as ClientMetadata, D as DebugConfig, j as DeepPartial, k as ExtractArrayType, P as PayloadFindResponse, l as PayloadMutationResponse, m as PublicCart, n as PublicCartItem, o as PublicCartReference, p as PublicMediaAsset, q as PublicMediaSize, r as PublicOrder, s as PublicOrderItem, t as PublicOrderReference, R as RemoveDiscountParams, u as RemoveItemParams, v as RetryConfig, w as RootClient, w as RootClientType, x as RootCollectionClient, y as RootReadOnlyQueryBuilder, S as Sort, U as UpdateItemParams, W as Where } from './types-D2xYdz4P.js';
4
+ import './payload-types-m3jjhxk9.js';
5
+ export { C as Collection, P as PublicCollection } from './const-6XHz_jej.js';
5
6
  import './metadata.js';
6
- import './types-3qV6sY7T.js';
7
- import './payload-types-BCui2Oml.js';
7
+ import './types-Cmrd1ezc.js';
8
8
 
9
9
  declare class Client {
10
10
  commerce: CommerceClient;
package/dist/client.js CHANGED
@@ -744,71 +744,14 @@ var HttpClient = class {
744
744
  }
745
745
  };
746
746
 
747
- // src/utils/types.ts
748
- var resolveRelation = (ref) => {
749
- if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
750
- return null;
751
- return ref;
752
- };
753
-
754
- // src/core/metadata/index.ts
755
- function extractSeo(doc) {
756
- const seo = doc.seo ?? {};
757
- const og = seo.openGraph ?? {};
758
- return {
759
- title: seo.title ?? doc.title ?? null,
760
- description: seo.description ?? null,
761
- noIndex: seo.noIndex ?? null,
762
- canonical: seo.canonical ?? null,
763
- openGraph: {
764
- title: og.title ?? null,
765
- description: og.description ?? null,
766
- image: og.image ?? null
767
- }
768
- };
769
- }
770
- function generateMetadata(input, options) {
771
- const title = input.title ?? void 0;
772
- const description = input.description ?? void 0;
773
- const ogTitle = input.openGraph?.title ?? title;
774
- const ogDescription = input.openGraph?.description ?? description;
775
- const image = resolveMetaImage(input.openGraph?.image);
776
- return {
777
- title,
778
- description,
779
- ...input.noIndex && { robots: { index: false, follow: false } },
780
- ...input.canonical && { alternates: { canonical: input.canonical } },
781
- openGraph: {
782
- ...ogTitle && { title: ogTitle },
783
- ...ogDescription && { description: ogDescription },
784
- ...options?.siteName && { siteName: options.siteName },
785
- ...image && { images: [image] }
786
- },
787
- twitter: {
788
- card: image ? "summary_large_image" : "summary",
789
- ...ogTitle && { title: ogTitle },
790
- ...ogDescription && { description: ogDescription },
791
- ...image && { images: [image.url] }
792
- }
793
- };
794
- }
795
- function resolveMetaImage(ref) {
796
- const image = resolveRelation(ref);
797
- if (!image) return null;
798
- const sized = image.sizes?.["1536"];
799
- const url = sized?.url || image.url;
800
- if (!url) return null;
801
- const width = sized?.url ? sized.width : image.width;
802
- const height = sized?.url ? sized.height : image.height;
747
+ // src/core/collection/query-builder.ts
748
+ function withDefaultPublicReadOptions(options) {
803
749
  return {
804
- url,
805
- ...width && { width },
806
- ...height && { height },
807
- ...image.alt && { alt: image.alt }
750
+ ...options,
751
+ depth: options?.depth ?? 0,
752
+ joins: options?.joins ?? false
808
753
  };
809
754
  }
810
-
811
- // src/core/collection/query-builder.ts
812
755
  var ReadOnlyCollectionQueryBuilder = class {
813
756
  constructor(api, collection) {
814
757
  this.api = api;
@@ -817,13 +760,13 @@ var ReadOnlyCollectionQueryBuilder = class {
817
760
  async find(options) {
818
761
  return this.api.requestFind(
819
762
  `/api/${String(this.collection)}`,
820
- options
763
+ withDefaultPublicReadOptions(options)
821
764
  );
822
765
  }
823
766
  async findById(id, options) {
824
767
  return this.api.requestFindById(
825
768
  `/api/${String(this.collection)}/${String(id)}`,
826
- options
769
+ withDefaultPublicReadOptions(options)
827
770
  );
828
771
  }
829
772
  async count(options) {
@@ -832,22 +775,6 @@ var ReadOnlyCollectionQueryBuilder = class {
832
775
  options
833
776
  );
834
777
  }
835
- async findMetadata(options, metadataOptions) {
836
- const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
837
- const doc = docs[0];
838
- if (!doc) return null;
839
- return generateMetadata(
840
- extractSeo(doc),
841
- metadataOptions
842
- );
843
- }
844
- async findMetadataById(id, metadataOptions) {
845
- const doc = await this.findById(id, { depth: 1 });
846
- return generateMetadata(
847
- extractSeo(doc),
848
- metadataOptions
849
- );
850
- }
851
778
  };
852
779
 
853
780
  // src/core/collection/collection-client.ts
@@ -863,6 +790,21 @@ var ReadOnlyCollectionClient = class extends HttpClient {
863
790
  });
864
791
  return this.parseFindResponse(response);
865
792
  }
793
+ async requestFindEndpoint(endpoint, data) {
794
+ const response = await this.fetchWithTracking(endpoint, {
795
+ ...this.defaultOptions,
796
+ method: "POST",
797
+ body: data ? JSON.stringify(data) : void 0
798
+ });
799
+ return this.parseFindResponse(response);
800
+ }
801
+ async requestFindEndpointGet(endpoint) {
802
+ const response = await this.fetchWithTracking(endpoint, {
803
+ ...this.defaultOptions,
804
+ method: "GET"
805
+ });
806
+ return this.parseFindResponse(response);
807
+ }
866
808
  async requestFindById(endpoint, options) {
867
809
  const url = this.buildUrl(endpoint, options);
868
810
  const response = await this.fetchWithTracking(url, {
@@ -927,13 +869,16 @@ async function parseApiResponse(response, endpoint) {
927
869
  return data;
928
870
  }
929
871
 
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) {
872
+ // src/core/api/customer-scoped-api.ts
873
+ var CustomerScopedApi = class {
874
+ constructor(apiName, options) {
875
+ if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
876
+ throw createConfigError(
877
+ `Either secretKey or customerToken is required for ${apiName}.`
878
+ );
879
+ }
935
880
  this.publishableKey = requirePublishableKeyForSecret(
936
- "CommunityClient",
881
+ apiName,
937
882
  options.publishableKey,
938
883
  options.secretKey
939
884
  );
@@ -943,6 +888,44 @@ var CommunityClient = class {
943
888
  this.onUnauthorized = options.onUnauthorized;
944
889
  this.onRequestId = options.onRequestId;
945
890
  }
891
+ async request(endpoint, options) {
892
+ const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
893
+ try {
894
+ const response = await httpFetch(endpoint, {
895
+ method: options.method,
896
+ apiUrl: this.apiUrl,
897
+ publishableKey: this.publishableKey,
898
+ secretKey: this.secretKey,
899
+ customerToken: token ?? void 0,
900
+ ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
901
+ ...options.body !== void 0 && {
902
+ body: JSON.stringify(options.body)
903
+ },
904
+ ...options.headers && { headers: options.headers }
905
+ });
906
+ this.onRequestId?.(response.headers.get("x-request-id") ?? null);
907
+ return parseApiResponse(response, endpoint);
908
+ } catch (err) {
909
+ const id = err instanceof SDKError ? err.requestId ?? null : null;
910
+ this.onRequestId?.(id);
911
+ throw err;
912
+ }
913
+ }
914
+ };
915
+
916
+ // src/core/community/community-client.ts
917
+ var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
918
+ var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
919
+ function unwrapPayloadDoc(value) {
920
+ if (value && typeof value === "object" && "doc" in value) {
921
+ return value.doc;
922
+ }
923
+ return value;
924
+ }
925
+ var CommunityClient = class extends CustomerScopedApi {
926
+ constructor(options) {
927
+ super("CommunityClient", { ...options, requiresCredential: false });
928
+ }
946
929
  buildQuery(params) {
947
930
  if (!params) return "";
948
931
  const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
@@ -952,7 +935,8 @@ var CommunityClient = class {
952
935
  const urlParams = new URLSearchParams();
953
936
  const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
954
937
  urlParams.set("sort", sort);
955
- if (params?.limit !== void 0) urlParams.set("limit", String(params.limit));
938
+ if (params?.limit !== void 0)
939
+ urlParams.set("limit", String(params.limit));
956
940
  if (params?.page !== void 0) urlParams.set("page", String(params.page));
957
941
  if (params?.categoryId !== void 0) {
958
942
  urlParams.set("where[categories][in]", params.categoryId);
@@ -960,7 +944,7 @@ var CommunityClient = class {
960
944
  if (params?.tagId !== void 0) {
961
945
  urlParams.set("where[tags][in]", params.tagId);
962
946
  }
963
- return `/api/posts?${urlParams.toString()}`;
947
+ return `/api/posts/public?${urlParams.toString()}`;
964
948
  }
965
949
  buildCommentsListQuery(params) {
966
950
  const urlParams = new URLSearchParams();
@@ -980,30 +964,21 @@ var CommunityClient = class {
980
964
  }
981
965
  if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
982
966
  if (params.page !== void 0) urlParams.set("page", String(params.page));
983
- return `/api/comments?${urlParams.toString()}`;
967
+ return `/api/comments/public?${urlParams.toString()}`;
984
968
  }
985
969
  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
- }
970
+ return this.request(endpoint, { method, body });
971
+ }
972
+ async executeDoc(endpoint, method, body) {
973
+ const response = await this.execute(endpoint, method, body);
974
+ return unwrapPayloadDoc(response);
1004
975
  }
1005
976
  createPost(params) {
1006
- return this.execute("/api/posts", "POST", params);
977
+ return this.executeDoc(
978
+ "/api/posts",
979
+ "POST",
980
+ params
981
+ );
1007
982
  }
1008
983
  /**
1009
984
  * Public post feed. Server applies the same visibility contract as
@@ -1060,7 +1035,11 @@ var CommunityClient = class {
1060
1035
  if (parentId !== void 0) {
1061
1036
  body.parent = parentId;
1062
1037
  }
1063
- return this.execute("/api/comments", "POST", body);
1038
+ return this.executeDoc(
1039
+ "/api/comments",
1040
+ "POST",
1041
+ body
1042
+ );
1064
1043
  }
1065
1044
  /**
1066
1045
  * List comments for a post.
@@ -1098,7 +1077,7 @@ var CommunityClient = class {
1098
1077
  }
1099
1078
  updateComment(params) {
1100
1079
  const { commentId, body } = params;
1101
- return this.execute(
1080
+ return this.executeDoc(
1102
1081
  `/api/comments/${commentId}`,
1103
1082
  "PATCH",
1104
1083
  { body }
@@ -1129,10 +1108,14 @@ var CommunityClient = class {
1129
1108
  400
1130
1109
  );
1131
1110
  }
1132
- return this.execute("/api/reactions", "POST", {
1133
- post: postId,
1134
- type: reactionType
1135
- });
1111
+ return this.executeDoc(
1112
+ "/api/reactions",
1113
+ "POST",
1114
+ {
1115
+ post: postId,
1116
+ type: reactionType
1117
+ }
1118
+ );
1136
1119
  }
1137
1120
  removeReaction(params) {
1138
1121
  const { postId, type } = params;
@@ -1151,10 +1134,14 @@ var CommunityClient = class {
1151
1134
  400
1152
1135
  );
1153
1136
  }
1154
- return this.execute("/api/reactions", "POST", {
1155
- comment: commentId,
1156
- type: reactionType
1157
- });
1137
+ return this.executeDoc(
1138
+ "/api/reactions",
1139
+ "POST",
1140
+ {
1141
+ comment: commentId,
1142
+ type: reactionType
1143
+ }
1144
+ );
1158
1145
  }
1159
1146
  removeCommentReaction(params) {
1160
1147
  const { commentId, type } = params;
@@ -1183,9 +1170,13 @@ var CommunityClient = class {
1183
1170
  }
1184
1171
  // Bookmarks
1185
1172
  addBookmark(params) {
1186
- return this.execute("/api/bookmarks", "POST", {
1187
- post: params.postId
1188
- });
1173
+ return this.executeDoc(
1174
+ "/api/bookmarks",
1175
+ "POST",
1176
+ {
1177
+ post: params.postId
1178
+ }
1179
+ );
1189
1180
  }
1190
1181
  removeBookmark(params) {
1191
1182
  return this.execute(
@@ -1201,10 +1192,7 @@ var CommunityClient = class {
1201
1192
  }
1202
1193
  // Profiles
1203
1194
  listProfileLists(params) {
1204
- return this.execute(
1205
- `/api/customer-profile-lists${this.buildQuery(params)}`,
1206
- "GET"
1207
- );
1195
+ return this.execute(`/api/customer-profile-lists${this.buildQuery(params)}`, "GET");
1208
1196
  }
1209
1197
  async getProfileList(params) {
1210
1198
  const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
@@ -1434,46 +1422,18 @@ var CustomerNamespace = class {
1434
1422
  };
1435
1423
 
1436
1424
  // src/core/api/cart-api.ts
1437
- var CartApi = class {
1425
+ var CartApi = class extends CustomerScopedApi {
1438
1426
  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;
1427
+ super("CartApi", options);
1454
1428
  }
1455
1429
  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
- }
1430
+ return this.request(endpoint, { method, body });
1474
1431
  }
1475
1432
  getCart(cartId) {
1476
- return this.execute(`/api/carts/${cartId}`, "GET");
1433
+ return this.execute(
1434
+ `/api/carts/${cartId}?depth=0&joins=false`,
1435
+ "GET"
1436
+ );
1477
1437
  }
1478
1438
  addItem(params) {
1479
1439
  return this.execute("/api/carts/add-item", "POST", params);
@@ -1537,6 +1497,18 @@ function splitIdempotencyKey(params) {
1537
1497
  }
1538
1498
 
1539
1499
  // src/core/commerce/commerce-client.ts
1500
+ var BrowserCommerceApi = class extends CustomerScopedApi {
1501
+ post(endpoint, body, requestOptions) {
1502
+ return this.request(endpoint, {
1503
+ method: "POST",
1504
+ body,
1505
+ headers: requestOptions?.headers
1506
+ });
1507
+ }
1508
+ get(endpoint) {
1509
+ return this.request(endpoint, { method: "GET" });
1510
+ }
1511
+ };
1540
1512
  var CommerceClient = class {
1541
1513
  constructor(options) {
1542
1514
  const cartApi = new CartApi({
@@ -1546,52 +1518,23 @@ var CommerceClient = class {
1546
1518
  onUnauthorized: options.onUnauthorized,
1547
1519
  onRequestId: options.onRequestId
1548
1520
  });
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
- };
1521
+ const api = new BrowserCommerceApi("CommerceClient", {
1522
+ publishableKey: options.publishableKey,
1523
+ apiUrl: options.apiUrl,
1524
+ customerToken: options.customerToken,
1525
+ onUnauthorized: options.onUnauthorized,
1526
+ onRequestId: options.onRequestId
1527
+ });
1587
1528
  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)),
1529
+ stockCheck: (params) => api.post("/api/products/stock-check", params),
1530
+ stockSnapshot: (params) => api.get(stockSnapshotQuery(params)),
1531
+ listingGroups: (params) => api.get(listingGroupsQuery(params)),
1532
+ listingGroupsCatalog: (params) => api.get(
1533
+ listingGroupsCatalogQuery(params)
1534
+ ),
1592
1535
  detail: async (params) => {
1593
1536
  try {
1594
- const product = await executeGet(productDetailQuery(params));
1537
+ const product = await api.get(productDetailQuery(params));
1595
1538
  return { found: true, product };
1596
1539
  } catch (err) {
1597
1540
  const notFoundResult = productDetailResultFromError(err);
@@ -1601,7 +1544,7 @@ var CommerceClient = class {
1601
1544
  },
1602
1545
  detailCatalog: async (params) => {
1603
1546
  try {
1604
- const product = await executeGet(
1547
+ const product = await api.get(
1605
1548
  productDetailCatalogQuery(params)
1606
1549
  );
1607
1550
  return { found: true, product };
@@ -1624,7 +1567,7 @@ var CommerceClient = class {
1624
1567
  this.orders = {
1625
1568
  checkout: (params) => {
1626
1569
  const { body, idempotencyKey } = splitIdempotencyKey(params);
1627
- return execute(
1570
+ return api.post(
1628
1571
  "/api/orders/checkout",
1629
1572
  body,
1630
1573
  idempotencyRequestOptions(idempotencyKey)
@@ -1633,10 +1576,10 @@ var CommerceClient = class {
1633
1576
  listMine: (params) => options.customerAuth.getMyOrders(params)
1634
1577
  };
1635
1578
  this.discounts = {
1636
- validate: (params) => execute("/api/discounts/validate", params)
1579
+ validate: (params) => api.post("/api/discounts/validate", params)
1637
1580
  };
1638
1581
  this.shipping = {
1639
- calculate: (params) => execute("/api/shipping-policies/calculate", params)
1582
+ calculate: (params) => api.post("/api/shipping-policies/calculate", params)
1640
1583
  };
1641
1584
  }
1642
1585
  };