@01.software/sdk 0.33.0 → 0.34.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.
- package/README.md +214 -22
- package/dist/analytics/react.cjs.map +1 -1
- package/dist/analytics/react.js.map +1 -1
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.js.map +1 -1
- package/dist/client.cjs +341 -26
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +7 -6
- package/dist/client.d.ts +7 -6
- package/dist/client.js +341 -26
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-De6eKW1J.d.cts → collection-client-CR2B8c1v.d.cts} +7 -3
- package/dist/{collection-client-B6SlhzIP.d.ts → collection-client-DkREjhQ9.d.ts} +7 -3
- package/dist/{const-sPR2IkCe.d.cts → const-BTvdrXtY.d.cts} +4 -4
- package/dist/{const-DwmSDeWq.d.ts → const-CdqCauHQ.d.ts} +4 -4
- package/dist/index-CjA3U6X3.d.cts +186 -0
- package/dist/index-DK8_NXkh.d.ts +186 -0
- package/dist/index.cjs +1401 -176
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -9
- package/dist/index.d.ts +74 -9
- package/dist/index.js +1401 -176
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-dkeQyrDC.d.cts → payload-types-C7tb7Xbs.d.cts} +208 -52
- package/dist/{payload-types-dkeQyrDC.d.ts → payload-types-C7tb7Xbs.d.ts} +208 -52
- package/dist/query.cjs +194 -35
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +44 -17
- package/dist/query.d.ts +44 -17
- package/dist/query.js +194 -35
- package/dist/query.js.map +1 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js.map +1 -1
- package/dist/{server-CrsPyqEc.d.cts → server-nXOezi4b.d.cts} +22 -6
- package/dist/{server-CrsPyqEc.d.ts → server-nXOezi4b.d.ts} +22 -6
- package/dist/server.cjs +439 -32
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +11 -179
- package/dist/server.d.ts +11 -179
- package/dist/server.js +439 -32
- package/dist/server.js.map +1 -1
- package/dist/{types-Cel_4L9t.d.ts → types-1ylMrCuW.d.ts} +1 -1
- package/dist/{types-B3YT092I.d.cts → types-Bx558PU6.d.cts} +1 -1
- package/dist/{types-BHh0YLmq.d.ts → types-Byo_Rty4.d.ts} +705 -69
- package/dist/{types-BZKxss8Y.d.cts → types-DDhtZI6E.d.cts} +705 -69
- package/dist/ui/canvas/server.cjs +231 -38
- package/dist/ui/canvas/server.cjs.map +1 -1
- package/dist/ui/canvas/server.d.cts +1 -1
- package/dist/ui/canvas/server.d.ts +1 -1
- package/dist/ui/canvas/server.js +221 -38
- package/dist/ui/canvas/server.js.map +1 -1
- package/dist/ui/canvas.cjs +320 -257
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.d.cts +5 -19
- package/dist/ui/canvas.d.ts +5 -19
- package/dist/ui/canvas.js +323 -260
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/webhook.cjs +2 -1
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +20 -179
- package/dist/webhook.d.ts +20 -179
- package/dist/webhook.js +2 -1
- package/dist/webhook.js.map +1 -1
- package/package.json +4 -5
package/dist/client.cjs
CHANGED
|
@@ -218,9 +218,12 @@ function resolveApiUrl(apiUrl) {
|
|
|
218
218
|
|
|
219
219
|
// src/core/internal/utils/http.ts
|
|
220
220
|
var DEFAULT_TIMEOUT = 3e4;
|
|
221
|
+
var STOREFRONT_BROWSER_TIMEOUT = 15e3;
|
|
221
222
|
var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
|
|
222
223
|
var NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
|
|
223
224
|
var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
|
|
225
|
+
var DEFAULT_MAX_RETRIES = 3;
|
|
226
|
+
var STOREFRONT_BROWSER_MAX_RETRIES = 1;
|
|
224
227
|
function debugLog(debug, type, message, data) {
|
|
225
228
|
if (!debug) return;
|
|
226
229
|
const shouldLog = debug === true || type === "request" && debug.logRequests || type === "response" && debug.logResponses || type === "error" && debug.logErrors;
|
|
@@ -413,15 +416,18 @@ async function httpFetch(url, options) {
|
|
|
413
416
|
publishableKey,
|
|
414
417
|
secretKey,
|
|
415
418
|
customerToken,
|
|
416
|
-
timeout = DEFAULT_TIMEOUT,
|
|
419
|
+
timeout: timeoutOption = DEFAULT_TIMEOUT,
|
|
417
420
|
debug,
|
|
418
421
|
retry,
|
|
419
422
|
onUnauthorized,
|
|
420
423
|
...requestInit
|
|
421
424
|
} = options || {};
|
|
422
425
|
const baseUrl = resolveApiUrl(apiUrl);
|
|
426
|
+
const method = (requestInit.method || "GET").toUpperCase();
|
|
427
|
+
const isPublishableKeyBrowserGet = typeof window !== "undefined" && !secretKey && !customerToken && Boolean(publishableKey) && SAFE_METHODS.includes(method);
|
|
428
|
+
const timeout = timeoutOption === DEFAULT_TIMEOUT && isPublishableKeyBrowserGet ? STOREFRONT_BROWSER_TIMEOUT : timeoutOption;
|
|
423
429
|
const retryConfig = {
|
|
424
|
-
maxRetries: retry?.maxRetries ??
|
|
430
|
+
maxRetries: retry?.maxRetries ?? (isPublishableKeyBrowserGet ? STOREFRONT_BROWSER_MAX_RETRIES : DEFAULT_MAX_RETRIES),
|
|
425
431
|
retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
|
|
426
432
|
retryDelay: retry?.retryDelay ?? ((attempt) => Math.min(1e3 * 2 ** attempt, 1e4))
|
|
427
433
|
};
|
|
@@ -529,8 +535,8 @@ async function httpFetch(url, options) {
|
|
|
529
535
|
),
|
|
530
536
|
requestId
|
|
531
537
|
);
|
|
532
|
-
const
|
|
533
|
-
if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(
|
|
538
|
+
const method2 = (requestInit.method || "GET").toUpperCase();
|
|
539
|
+
if (attempt < retryConfig.maxRetries && SAFE_METHODS.includes(method2) && retryConfig.retryableStatuses.includes(response.status)) {
|
|
534
540
|
lastError = error;
|
|
535
541
|
const retryDelay = retryConfig.retryDelay(attempt);
|
|
536
542
|
debugLog(debug, "error", `Retrying in ${retryDelay}ms...`, error);
|
|
@@ -542,8 +548,8 @@ async function httpFetch(url, options) {
|
|
|
542
548
|
return response;
|
|
543
549
|
} catch (error) {
|
|
544
550
|
debugLog(debug, "error", url, error);
|
|
545
|
-
const
|
|
546
|
-
const isSafe = SAFE_METHODS.includes(
|
|
551
|
+
const method2 = (requestInit.method || "GET").toUpperCase();
|
|
552
|
+
const isSafe = SAFE_METHODS.includes(method2);
|
|
547
553
|
if (error instanceof Error && error.name === "AbortError") {
|
|
548
554
|
const timeoutError = createTimeoutError(
|
|
549
555
|
`Request timed out after ${timeout}ms.`,
|
|
@@ -602,6 +608,35 @@ async function httpFetch(url, options) {
|
|
|
602
608
|
throw lastError ?? new NetworkError("Request failed after retries");
|
|
603
609
|
}
|
|
604
610
|
|
|
611
|
+
// src/core/internal/utils/query-string.ts
|
|
612
|
+
function productDetailQuery(params) {
|
|
613
|
+
const search = new URLSearchParams();
|
|
614
|
+
if ("slug" in params) {
|
|
615
|
+
search.set("slug", params.slug);
|
|
616
|
+
} else {
|
|
617
|
+
search.set("id", params.id);
|
|
618
|
+
}
|
|
619
|
+
return `/api/products/detail?${search}`;
|
|
620
|
+
}
|
|
621
|
+
function productDetailCatalogQuery(params) {
|
|
622
|
+
const search = new URLSearchParams();
|
|
623
|
+
if ("slug" in params) {
|
|
624
|
+
search.set("slug", params.slug);
|
|
625
|
+
} else {
|
|
626
|
+
search.set("id", params.id);
|
|
627
|
+
}
|
|
628
|
+
return `/api/products/detail/catalog?${search}`;
|
|
629
|
+
}
|
|
630
|
+
function listingGroupsQuery(params) {
|
|
631
|
+
return `/api/products/listing-groups?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
|
|
632
|
+
}
|
|
633
|
+
function listingGroupsCatalogQuery(params) {
|
|
634
|
+
return `/api/products/listing-groups/catalog?ids=${params.productIds.map(encodeURIComponent).join(",")}`;
|
|
635
|
+
}
|
|
636
|
+
function stockSnapshotQuery(params) {
|
|
637
|
+
return `/api/products/stock?variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
|
|
638
|
+
}
|
|
639
|
+
|
|
605
640
|
// src/core/collection/http-client.ts
|
|
606
641
|
var HttpClient = class {
|
|
607
642
|
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
@@ -920,6 +955,8 @@ async function parseApiResponse(response, endpoint) {
|
|
|
920
955
|
}
|
|
921
956
|
|
|
922
957
|
// src/core/community/community-client.ts
|
|
958
|
+
var DEFAULT_POST_LIST_SORT = "-lastActivityAt";
|
|
959
|
+
var DEFAULT_COMMENT_LIST_SORT = "-createdAt";
|
|
923
960
|
var CommunityClient = class {
|
|
924
961
|
constructor(options) {
|
|
925
962
|
this.publishableKey = requirePublishableKeyForSecret(
|
|
@@ -938,6 +975,40 @@ var CommunityClient = class {
|
|
|
938
975
|
const entries = Object.entries(params).filter((e) => e[1] !== void 0).map(([k, v]) => [k, String(v)]);
|
|
939
976
|
return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
|
|
940
977
|
}
|
|
978
|
+
buildPostsListQuery(params) {
|
|
979
|
+
const urlParams = new URLSearchParams();
|
|
980
|
+
const sort = params?.sort ?? DEFAULT_POST_LIST_SORT;
|
|
981
|
+
urlParams.set("sort", sort);
|
|
982
|
+
if (params?.limit !== void 0) urlParams.set("limit", String(params.limit));
|
|
983
|
+
if (params?.page !== void 0) urlParams.set("page", String(params.page));
|
|
984
|
+
if (params?.categoryId !== void 0) {
|
|
985
|
+
urlParams.set("where[categories][in]", params.categoryId);
|
|
986
|
+
}
|
|
987
|
+
if (params?.tagId !== void 0) {
|
|
988
|
+
urlParams.set("where[tags][in]", params.tagId);
|
|
989
|
+
}
|
|
990
|
+
return `/api/posts?${urlParams.toString()}`;
|
|
991
|
+
}
|
|
992
|
+
buildCommentsListQuery(params) {
|
|
993
|
+
const urlParams = new URLSearchParams();
|
|
994
|
+
const sort = params.sort ?? DEFAULT_COMMENT_LIST_SORT;
|
|
995
|
+
urlParams.set("sort", sort);
|
|
996
|
+
if (params.postId !== void 0) {
|
|
997
|
+
urlParams.set("where[post][equals]", params.postId);
|
|
998
|
+
}
|
|
999
|
+
if (params.parentId !== void 0) {
|
|
1000
|
+
urlParams.set("where[parent][equals]", params.parentId);
|
|
1001
|
+
}
|
|
1002
|
+
if (params.rootComment !== void 0) {
|
|
1003
|
+
urlParams.set("where[rootComment][equals]", params.rootComment);
|
|
1004
|
+
}
|
|
1005
|
+
if (params.topLevelOnly) {
|
|
1006
|
+
urlParams.set("where[parent][exists]", "false");
|
|
1007
|
+
}
|
|
1008
|
+
if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
|
|
1009
|
+
if (params.page !== void 0) urlParams.set("page", String(params.page));
|
|
1010
|
+
return `/api/comments?${urlParams.toString()}`;
|
|
1011
|
+
}
|
|
941
1012
|
async execute(endpoint, method, body) {
|
|
942
1013
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
943
1014
|
try {
|
|
@@ -961,6 +1032,28 @@ var CommunityClient = class {
|
|
|
961
1032
|
createPost(params) {
|
|
962
1033
|
return this.execute("/api/posts", "POST", params);
|
|
963
1034
|
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Public post feed. Server applies the same visibility contract as
|
|
1037
|
+
* `communityPostRead` (published + visible + moderation-safe).
|
|
1038
|
+
*/
|
|
1039
|
+
listPosts(params) {
|
|
1040
|
+
return this.execute(
|
|
1041
|
+
this.buildPostsListQuery(params),
|
|
1042
|
+
"GET"
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1045
|
+
listPostCategories(params) {
|
|
1046
|
+
return this.execute(
|
|
1047
|
+
`/api/post-categories${this.buildQuery(params)}`,
|
|
1048
|
+
"GET"
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
listPostTags(params) {
|
|
1052
|
+
return this.execute(
|
|
1053
|
+
`/api/post-tags${this.buildQuery(params)}`,
|
|
1054
|
+
"GET"
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
964
1057
|
getMyPosts(params) {
|
|
965
1058
|
return this.execute(
|
|
966
1059
|
`/api/posts/my${this.buildQuery(params)}`,
|
|
@@ -996,16 +1089,37 @@ var CommunityClient = class {
|
|
|
996
1089
|
}
|
|
997
1090
|
return this.execute("/api/comments", "POST", body);
|
|
998
1091
|
}
|
|
1092
|
+
/**
|
|
1093
|
+
* List comments for a post.
|
|
1094
|
+
*
|
|
1095
|
+
* - Default: all visible comments on the post (any depth).
|
|
1096
|
+
* - `topLevelOnly: true`: only root comments (`parent` unset).
|
|
1097
|
+
* - `rootComment`: comments belonging to a thread rooted at that comment.
|
|
1098
|
+
*/
|
|
999
1099
|
listComments(params) {
|
|
1000
|
-
const { postId, page, limit, rootComment } = params;
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1100
|
+
const { postId, page, limit, rootComment, topLevelOnly, sort } = params;
|
|
1101
|
+
return this.execute(
|
|
1102
|
+
this.buildCommentsListQuery({
|
|
1103
|
+
postId,
|
|
1104
|
+
page,
|
|
1105
|
+
limit,
|
|
1106
|
+
rootComment,
|
|
1107
|
+
topLevelOnly,
|
|
1108
|
+
sort
|
|
1109
|
+
}),
|
|
1110
|
+
"GET"
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
/** Direct replies to a comment (`where[parent][equals]`). */
|
|
1114
|
+
listReplies(params) {
|
|
1115
|
+
const { commentId, page, limit, sort } = params;
|
|
1007
1116
|
return this.execute(
|
|
1008
|
-
|
|
1117
|
+
this.buildCommentsListQuery({
|
|
1118
|
+
parentId: commentId,
|
|
1119
|
+
page,
|
|
1120
|
+
limit,
|
|
1121
|
+
sort
|
|
1122
|
+
}),
|
|
1009
1123
|
"GET"
|
|
1010
1124
|
);
|
|
1011
1125
|
}
|
|
@@ -1033,10 +1147,18 @@ var CommunityClient = class {
|
|
|
1033
1147
|
}
|
|
1034
1148
|
// Reactions
|
|
1035
1149
|
addReaction(params) {
|
|
1036
|
-
const { postId, type } = params;
|
|
1150
|
+
const { postId, typeSlug, type } = params;
|
|
1151
|
+
const reactionType = typeSlug ?? type;
|
|
1152
|
+
if (!reactionType) {
|
|
1153
|
+
throw new SDKError(
|
|
1154
|
+
"validation_failed",
|
|
1155
|
+
"addReaction requires typeSlug (or deprecated type)",
|
|
1156
|
+
400
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1037
1159
|
return this.execute("/api/reactions", "POST", {
|
|
1038
1160
|
post: postId,
|
|
1039
|
-
type
|
|
1161
|
+
type: reactionType
|
|
1040
1162
|
});
|
|
1041
1163
|
}
|
|
1042
1164
|
removeReaction(params) {
|
|
@@ -1047,10 +1169,18 @@ var CommunityClient = class {
|
|
|
1047
1169
|
);
|
|
1048
1170
|
}
|
|
1049
1171
|
addCommentReaction(params) {
|
|
1050
|
-
const { commentId, type } = params;
|
|
1172
|
+
const { commentId, typeSlug, type } = params;
|
|
1173
|
+
const reactionType = typeSlug ?? type;
|
|
1174
|
+
if (!reactionType) {
|
|
1175
|
+
throw new SDKError(
|
|
1176
|
+
"validation_failed",
|
|
1177
|
+
"addCommentReaction requires typeSlug (or deprecated type)",
|
|
1178
|
+
400
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1051
1181
|
return this.execute("/api/reactions", "POST", {
|
|
1052
1182
|
comment: commentId,
|
|
1053
|
-
type
|
|
1183
|
+
type: reactionType
|
|
1054
1184
|
});
|
|
1055
1185
|
}
|
|
1056
1186
|
removeCommentReaction(params) {
|
|
@@ -1066,6 +1196,12 @@ var CommunityClient = class {
|
|
|
1066
1196
|
"GET"
|
|
1067
1197
|
);
|
|
1068
1198
|
}
|
|
1199
|
+
getCommentReactionSummary(params) {
|
|
1200
|
+
return this.execute(
|
|
1201
|
+
`/api/comments/${params.commentId}/reactions`,
|
|
1202
|
+
"GET"
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1069
1205
|
getReactionTypes() {
|
|
1070
1206
|
return this.execute(
|
|
1071
1207
|
"/api/reaction-types?limit=100",
|
|
@@ -1090,6 +1226,25 @@ var CommunityClient = class {
|
|
|
1090
1226
|
"GET"
|
|
1091
1227
|
);
|
|
1092
1228
|
}
|
|
1229
|
+
// Profiles
|
|
1230
|
+
listProfileLists(params) {
|
|
1231
|
+
return this.execute(
|
|
1232
|
+
`/api/customer-profile-lists${this.buildQuery(params)}`,
|
|
1233
|
+
"GET"
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
async getProfileList(params) {
|
|
1237
|
+
const query = "slug" in params ? `?where[slug][equals]=${encodeURIComponent(params.slug)}&limit=1` : `?where[id][equals]=${encodeURIComponent(params.id)}&limit=1`;
|
|
1238
|
+
const res = await this.execute(`/api/customer-profile-lists${query}`, "GET");
|
|
1239
|
+
return res.docs[0] ?? null;
|
|
1240
|
+
}
|
|
1241
|
+
updatePublicProfile(body) {
|
|
1242
|
+
return this.execute(
|
|
1243
|
+
"/api/customers/me/profile",
|
|
1244
|
+
"PATCH",
|
|
1245
|
+
body
|
|
1246
|
+
);
|
|
1247
|
+
}
|
|
1093
1248
|
};
|
|
1094
1249
|
|
|
1095
1250
|
// src/core/customer/customer-auth.ts
|
|
@@ -1399,6 +1554,15 @@ function productDetailResultFromError(error) {
|
|
|
1399
1554
|
return { found: false, reason };
|
|
1400
1555
|
}
|
|
1401
1556
|
|
|
1557
|
+
// src/core/api/order-api.ts
|
|
1558
|
+
function idempotencyRequestOptions(idempotencyKey) {
|
|
1559
|
+
return idempotencyKey ? { headers: { "X-Idempotency-Key": idempotencyKey } } : void 0;
|
|
1560
|
+
}
|
|
1561
|
+
function splitIdempotencyKey(params) {
|
|
1562
|
+
const { idempotencyKey, ...body } = params;
|
|
1563
|
+
return { body, idempotencyKey };
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1402
1566
|
// src/core/commerce/commerce-client.ts
|
|
1403
1567
|
var CommerceClient = class {
|
|
1404
1568
|
constructor(options) {
|
|
@@ -1409,7 +1573,7 @@ var CommerceClient = class {
|
|
|
1409
1573
|
onUnauthorized: options.onUnauthorized,
|
|
1410
1574
|
onRequestId: options.onRequestId
|
|
1411
1575
|
});
|
|
1412
|
-
const execute = async (endpoint, body) => {
|
|
1576
|
+
const execute = async (endpoint, body, requestOptions) => {
|
|
1413
1577
|
const token = options.customerToken();
|
|
1414
1578
|
try {
|
|
1415
1579
|
const response = await httpFetch(endpoint, {
|
|
@@ -1418,7 +1582,26 @@ var CommerceClient = class {
|
|
|
1418
1582
|
publishableKey: options.publishableKey,
|
|
1419
1583
|
customerToken: token ?? void 0,
|
|
1420
1584
|
...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized },
|
|
1421
|
-
body: JSON.stringify(body)
|
|
1585
|
+
body: JSON.stringify(body),
|
|
1586
|
+
...requestOptions?.headers && { headers: requestOptions.headers }
|
|
1587
|
+
});
|
|
1588
|
+
options.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1589
|
+
return parseApiResponse(response, endpoint);
|
|
1590
|
+
} catch (err) {
|
|
1591
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1592
|
+
options.onRequestId?.(id);
|
|
1593
|
+
throw err;
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
const executeGet = async (endpoint) => {
|
|
1597
|
+
const token = options.customerToken();
|
|
1598
|
+
try {
|
|
1599
|
+
const response = await httpFetch(endpoint, {
|
|
1600
|
+
method: "GET",
|
|
1601
|
+
apiUrl: options.apiUrl,
|
|
1602
|
+
publishableKey: options.publishableKey,
|
|
1603
|
+
customerToken: token ?? void 0,
|
|
1604
|
+
...token && options.onUnauthorized && { onUnauthorized: options.onUnauthorized }
|
|
1422
1605
|
});
|
|
1423
1606
|
options.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1424
1607
|
return parseApiResponse(response, endpoint);
|
|
@@ -1430,19 +1613,30 @@ var CommerceClient = class {
|
|
|
1430
1613
|
};
|
|
1431
1614
|
this.product = {
|
|
1432
1615
|
stockCheck: (params) => execute("/api/products/stock-check", params),
|
|
1433
|
-
|
|
1616
|
+
stockSnapshot: (params) => executeGet(stockSnapshotQuery(params)),
|
|
1617
|
+
listingGroups: (params) => executeGet(listingGroupsQuery(params)),
|
|
1618
|
+
listingGroupsCatalog: (params) => executeGet(listingGroupsCatalogQuery(params)),
|
|
1434
1619
|
detail: async (params) => {
|
|
1435
1620
|
try {
|
|
1436
|
-
const product = await
|
|
1437
|
-
"/api/products/detail",
|
|
1438
|
-
params
|
|
1439
|
-
);
|
|
1621
|
+
const product = await executeGet(productDetailQuery(params));
|
|
1440
1622
|
return { found: true, product };
|
|
1441
1623
|
} catch (err) {
|
|
1442
1624
|
const notFoundResult = productDetailResultFromError(err);
|
|
1443
1625
|
if (notFoundResult) return notFoundResult;
|
|
1444
1626
|
throw err;
|
|
1445
1627
|
}
|
|
1628
|
+
},
|
|
1629
|
+
detailCatalog: async (params) => {
|
|
1630
|
+
try {
|
|
1631
|
+
const product = await executeGet(
|
|
1632
|
+
productDetailCatalogQuery(params)
|
|
1633
|
+
);
|
|
1634
|
+
return { found: true, product };
|
|
1635
|
+
} catch (err) {
|
|
1636
|
+
const notFoundResult = productDetailResultFromError(err);
|
|
1637
|
+
if (notFoundResult?.found === false) return notFoundResult;
|
|
1638
|
+
throw err;
|
|
1639
|
+
}
|
|
1446
1640
|
}
|
|
1447
1641
|
};
|
|
1448
1642
|
this.cart = {
|
|
@@ -1455,7 +1649,14 @@ var CommerceClient = class {
|
|
|
1455
1649
|
clear: cartApi.clearCart.bind(cartApi)
|
|
1456
1650
|
};
|
|
1457
1651
|
this.orders = {
|
|
1458
|
-
checkout: (params) =>
|
|
1652
|
+
checkout: (params) => {
|
|
1653
|
+
const { body, idempotencyKey } = splitIdempotencyKey(params);
|
|
1654
|
+
return execute(
|
|
1655
|
+
"/api/orders/checkout",
|
|
1656
|
+
body,
|
|
1657
|
+
idempotencyRequestOptions(idempotencyKey)
|
|
1658
|
+
);
|
|
1659
|
+
},
|
|
1459
1660
|
listMine: (params) => options.customerAuth.getMyOrders(params)
|
|
1460
1661
|
};
|
|
1461
1662
|
this.discounts = {
|
|
@@ -1467,6 +1668,113 @@ var CommerceClient = class {
|
|
|
1467
1668
|
}
|
|
1468
1669
|
};
|
|
1469
1670
|
|
|
1671
|
+
// src/core/events/events-client.ts
|
|
1672
|
+
var EventsClient = class {
|
|
1673
|
+
constructor(options) {
|
|
1674
|
+
const secretKey = options.secretKey;
|
|
1675
|
+
this.publishableKey = requirePublishableKeyForSecret(
|
|
1676
|
+
"EventsClient",
|
|
1677
|
+
options.publishableKey,
|
|
1678
|
+
secretKey
|
|
1679
|
+
);
|
|
1680
|
+
this.apiUrl = options.apiUrl;
|
|
1681
|
+
this.customerToken = options.customerToken;
|
|
1682
|
+
this.onUnauthorized = options.onUnauthorized;
|
|
1683
|
+
this.onRequestId = options.onRequestId;
|
|
1684
|
+
}
|
|
1685
|
+
getRange(params) {
|
|
1686
|
+
return this.execute(
|
|
1687
|
+
buildRangeEndpoint(params),
|
|
1688
|
+
"GET",
|
|
1689
|
+
void 0,
|
|
1690
|
+
{ useCustomerAuth: false }
|
|
1691
|
+
);
|
|
1692
|
+
}
|
|
1693
|
+
register(params) {
|
|
1694
|
+
return this.execute(
|
|
1695
|
+
"/api/event-registrations/register",
|
|
1696
|
+
"POST",
|
|
1697
|
+
buildRegistrationRequestBody(params),
|
|
1698
|
+
{ useCustomerAuth: true }
|
|
1699
|
+
);
|
|
1700
|
+
}
|
|
1701
|
+
getGuestRegistration(token) {
|
|
1702
|
+
return this.execute(
|
|
1703
|
+
"/api/event-registrations/guest/lookup",
|
|
1704
|
+
"POST",
|
|
1705
|
+
{ token },
|
|
1706
|
+
{ useCustomerAuth: false }
|
|
1707
|
+
);
|
|
1708
|
+
}
|
|
1709
|
+
cancelGuestRegistration(token, params = {}) {
|
|
1710
|
+
return this.execute(
|
|
1711
|
+
"/api/event-registrations/guest/cancel",
|
|
1712
|
+
"POST",
|
|
1713
|
+
buildGuestCancelRequestBody(token, params),
|
|
1714
|
+
{ useCustomerAuth: false }
|
|
1715
|
+
);
|
|
1716
|
+
}
|
|
1717
|
+
async execute(endpoint, method, body, options = {}) {
|
|
1718
|
+
const useCustomerAuth = options.useCustomerAuth === true;
|
|
1719
|
+
const token = useCustomerAuth ? typeof this.customerToken === "function" ? this.customerToken() : this.customerToken : void 0;
|
|
1720
|
+
try {
|
|
1721
|
+
const response = await httpFetch(endpoint, {
|
|
1722
|
+
method,
|
|
1723
|
+
apiUrl: this.apiUrl,
|
|
1724
|
+
publishableKey: this.publishableKey,
|
|
1725
|
+
...useCustomerAuth && token ? { customerToken: token } : {},
|
|
1726
|
+
...useCustomerAuth && token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1727
|
+
...body !== void 0 && { body: JSON.stringify(body) }
|
|
1728
|
+
});
|
|
1729
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1730
|
+
return parseApiResponse(response, endpoint);
|
|
1731
|
+
} catch (err) {
|
|
1732
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1733
|
+
this.onRequestId?.(id);
|
|
1734
|
+
throw err;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
};
|
|
1738
|
+
function buildRegistrationRequestBody(params) {
|
|
1739
|
+
return {
|
|
1740
|
+
event: params.event,
|
|
1741
|
+
occurrence: params.occurrence,
|
|
1742
|
+
...params.quantity !== void 0 && { quantity: params.quantity },
|
|
1743
|
+
...params.attendee !== void 0 && { attendee: params.attendee },
|
|
1744
|
+
...params.answers !== void 0 && { answers: params.answers }
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
function buildGuestCancelRequestBody(token, params) {
|
|
1748
|
+
return {
|
|
1749
|
+
token,
|
|
1750
|
+
...params.reason !== void 0 && { reason: params.reason }
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
function buildRangeEndpoint(params) {
|
|
1754
|
+
const urlParams = new URLSearchParams();
|
|
1755
|
+
urlParams.set("start", formatDateParam(params.start));
|
|
1756
|
+
urlParams.set("end", formatDateParam(params.end));
|
|
1757
|
+
if (params.limit !== void 0) urlParams.set("limit", String(params.limit));
|
|
1758
|
+
if (params.page !== void 0) urlParams.set("page", String(params.page));
|
|
1759
|
+
appendValues(urlParams, "calendar", params.calendar);
|
|
1760
|
+
appendValues(urlParams, "calendarSlug", params.calendarSlug);
|
|
1761
|
+
appendValues(urlParams, "category", params.category);
|
|
1762
|
+
appendValues(urlParams, "categorySlug", params.categorySlug);
|
|
1763
|
+
appendValues(urlParams, "tag", params.tag);
|
|
1764
|
+
appendValues(urlParams, "tagSlug", params.tagSlug);
|
|
1765
|
+
return `/api/event-occurrences/range?${urlParams.toString()}`;
|
|
1766
|
+
}
|
|
1767
|
+
function formatDateParam(value) {
|
|
1768
|
+
return value instanceof Date ? value.toISOString() : value;
|
|
1769
|
+
}
|
|
1770
|
+
function appendValues(params, key, value) {
|
|
1771
|
+
if (value === void 0) return;
|
|
1772
|
+
const values = Array.isArray(value) ? value : [value];
|
|
1773
|
+
for (const entry of values) {
|
|
1774
|
+
if (entry) params.append(key, entry);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
|
|
1470
1778
|
// src/core/client/client.ts
|
|
1471
1779
|
var Client = class {
|
|
1472
1780
|
constructor(options) {
|
|
@@ -1512,6 +1820,13 @@ var Client = class {
|
|
|
1512
1820
|
onUnauthorized,
|
|
1513
1821
|
onRequestId
|
|
1514
1822
|
});
|
|
1823
|
+
this.events = new EventsClient({
|
|
1824
|
+
publishableKey: this.config.publishableKey,
|
|
1825
|
+
apiUrl: this.config.apiUrl,
|
|
1826
|
+
customerToken: () => this.customer.auth.getToken(),
|
|
1827
|
+
onUnauthorized,
|
|
1828
|
+
onRequestId
|
|
1829
|
+
});
|
|
1515
1830
|
this.collections = new ReadOnlyCollectionClient(
|
|
1516
1831
|
this.config.publishableKey,
|
|
1517
1832
|
void 0,
|