@01.software/sdk 0.65.1 → 0.68.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/CHANGELOG.md +81 -0
- package/README.md +201 -8
- package/dist/client.cjs +490 -338
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +11 -6
- package/dist/client.d.ts +11 -6
- package/dist/client.js +490 -338
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-C2sMvfme.d.ts → collection-client-IOaWsTMI.d.ts} +4 -4
- package/dist/{collection-client-B7rsTtVj.d.cts → collection-client-MbIJ5KzW.d.cts} +4 -4
- package/dist/{const-CRxPTDGt.d.ts → const-Do27Udj6.d.ts} +2 -2
- package/dist/{const-D6ZRQLxI.d.cts → const-Dw5ElJs_.d.cts} +2 -2
- package/dist/embedded-admin/server.cjs +16 -1
- package/dist/embedded-admin/server.cjs.map +1 -1
- package/dist/embedded-admin/server.d.cts +4 -2
- package/dist/embedded-admin/server.d.ts +4 -2
- package/dist/embedded-admin/server.js +16 -1
- package/dist/embedded-admin/server.js.map +1 -1
- package/dist/embedded-admin.cjs +19 -0
- package/dist/embedded-admin.cjs.map +1 -1
- package/dist/embedded-admin.d.cts +7 -1
- package/dist/embedded-admin.d.ts +7 -1
- package/dist/embedded-admin.js +19 -0
- package/dist/embedded-admin.js.map +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/{index-1auUEYrl.d.ts → index-DcYsLOja.d.ts} +3 -3
- package/dist/{index-Bbpf5t-l.d.cts → index-gnVxTKXu.d.cts} +3 -3
- package/dist/index.cjs +521 -367
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +521 -367
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-BnIET0xU.d.cts → payload-types-BY1uZFRf.d.cts} +162 -50
- package/dist/{payload-types-BnIET0xU.d.ts → payload-types-BY1uZFRf.d.ts} +162 -50
- package/dist/query.cjs +22 -1
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +5 -5
- package/dist/query.d.ts +5 -5
- package/dist/query.js +22 -1
- package/dist/query.js.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/server.cjs +1251 -1046
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +10 -9
- package/dist/server.d.ts +10 -9
- package/dist/server.js +1251 -1046
- package/dist/server.js.map +1 -1
- package/dist/{types-D1y4TgQm.d.ts → types-AWSVpuPE.d.ts} +2 -2
- package/dist/{types-DnRC3nLG.d.ts → types-CLRw0aDa.d.ts} +214 -42
- package/dist/{types-Dp1oYpD3.d.cts → types-DnIuxgu2.d.cts} +2 -2
- package/dist/{types-Dzn0LD2N.d.cts → types-csjaig4G.d.cts} +214 -42
- package/dist/ui/canvas.cjs +5 -1
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.js +5 -1
- 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.cjs +9 -2
- package/dist/ui/video.cjs.map +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/ui/video.js +9 -2
- package/dist/ui/video.js.map +1 -1
- package/dist/webhook.d.cts +5 -5
- package/dist/webhook.d.ts +5 -5
- package/package.json +4 -4
package/dist/server.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/server.ts
|
|
21
21
|
var server_exports = {};
|
|
22
22
|
__export(server_exports, {
|
|
23
|
+
BenefitVouchersApi: () => BenefitVouchersApi,
|
|
23
24
|
CollectionClient: () => CollectionClient,
|
|
24
25
|
CommunityClient: () => CommunityClient,
|
|
25
26
|
CustomerGroupApi: () => CustomerGroupApi,
|
|
@@ -54,9 +55,6 @@ __export(server_exports, {
|
|
|
54
55
|
});
|
|
55
56
|
module.exports = __toCommonJS(server_exports);
|
|
56
57
|
|
|
57
|
-
// src/core/collection/http-client.ts
|
|
58
|
-
var import_qs_esm = require("qs-esm");
|
|
59
|
-
|
|
60
58
|
// src/core/errors.ts
|
|
61
59
|
var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
|
|
62
60
|
var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
|
|
@@ -1060,1033 +1058,1234 @@ function stockSnapshotSearchParams(params) {
|
|
|
1060
1058
|
return `variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
|
|
1061
1059
|
}
|
|
1062
1060
|
|
|
1063
|
-
// src/core/
|
|
1064
|
-
function
|
|
1065
|
-
if (
|
|
1066
|
-
|
|
1067
|
-
function visit(value, depth, key) {
|
|
1068
|
-
if (depth > 10) {
|
|
1069
|
-
throw createValidationError(
|
|
1070
|
-
"Collection where must not exceed nesting depth 10."
|
|
1071
|
-
);
|
|
1072
|
-
}
|
|
1073
|
-
if (value === null && (key === "equals" || key === "not_equals")) {
|
|
1074
|
-
hasNull = true;
|
|
1075
|
-
return;
|
|
1076
|
-
}
|
|
1077
|
-
if (value == null) {
|
|
1078
|
-
throw createValidationError(
|
|
1079
|
-
"Collection where must not contain null or undefined values."
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1082
|
-
if (Array.isArray(value)) {
|
|
1083
|
-
if (value.length === 0) {
|
|
1084
|
-
throw createValidationError(
|
|
1085
|
-
"Collection where must not contain empty arrays, including and/or."
|
|
1086
|
-
);
|
|
1087
|
-
}
|
|
1088
|
-
if (value.length > 1e3) {
|
|
1089
|
-
throw createValidationError(
|
|
1090
|
-
"Collection where arrays must not contain more than 1000 elements."
|
|
1091
|
-
);
|
|
1092
|
-
}
|
|
1093
|
-
for (const item of value) visit(item, depth + 1);
|
|
1094
|
-
} else if (typeof value === "object" && !(value instanceof Date)) {
|
|
1095
|
-
const values = Object.entries(value);
|
|
1096
|
-
if (values.length === 0) {
|
|
1097
|
-
throw createValidationError(
|
|
1098
|
-
"Collection where must not contain empty condition objects."
|
|
1099
|
-
);
|
|
1100
|
-
}
|
|
1101
|
-
for (const [key2, item] of values) visit(item, depth + 1, key2);
|
|
1102
|
-
}
|
|
1061
|
+
// src/core/api/parse-response.ts
|
|
1062
|
+
async function parseApiResponse(response, endpoint, options = {}) {
|
|
1063
|
+
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
1064
|
+
return void 0;
|
|
1103
1065
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1066
|
+
let parsed;
|
|
1067
|
+
try {
|
|
1068
|
+
parsed = await response.json();
|
|
1069
|
+
} catch {
|
|
1070
|
+
throw createApiError(
|
|
1071
|
+
`Invalid JSON response from ${endpoint}`,
|
|
1072
|
+
response.status,
|
|
1073
|
+
void 0,
|
|
1074
|
+
"Server returned an invalid response.",
|
|
1075
|
+
"Check if the API endpoint is available."
|
|
1113
1076
|
);
|
|
1114
|
-
this.secretKey = secretKey;
|
|
1115
|
-
this.getCustomerToken = getCustomerToken;
|
|
1116
|
-
this.onUnauthorized = onUnauthorized;
|
|
1117
|
-
this.onRequestId = onRequestId;
|
|
1118
|
-
this.apiUrl = apiUrl;
|
|
1119
|
-
}
|
|
1120
|
-
get defaultOptions() {
|
|
1121
|
-
const opts = {
|
|
1122
|
-
apiUrl: this.apiUrl,
|
|
1123
|
-
publishableKey: this.publishableKey,
|
|
1124
|
-
secretKey: this.secretKey
|
|
1125
|
-
};
|
|
1126
|
-
const token = this.getCustomerToken?.();
|
|
1127
|
-
if (token) {
|
|
1128
|
-
opts.customerToken = token;
|
|
1129
|
-
if (this.onUnauthorized) {
|
|
1130
|
-
opts.onUnauthorized = this.onUnauthorized;
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
return opts;
|
|
1134
|
-
}
|
|
1135
|
-
async fetchWithTracking(url, opts) {
|
|
1136
|
-
try {
|
|
1137
|
-
const response = await httpFetch(url, opts);
|
|
1138
|
-
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1139
|
-
return response;
|
|
1140
|
-
} catch (err) {
|
|
1141
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1142
|
-
this.onRequestId?.(id);
|
|
1143
|
-
throw err;
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
buildUrl(endpoint, options) {
|
|
1147
|
-
if (!options) return endpoint;
|
|
1148
|
-
const { fallbackLocale, ...rest } = options;
|
|
1149
|
-
const queryOptions = fallbackLocale === void 0 ? rest : {
|
|
1150
|
-
...rest,
|
|
1151
|
-
"fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
|
|
1152
|
-
};
|
|
1153
|
-
const encodedOptions = validateWhere(queryOptions.where) ? { ...queryOptions, where: JSON.stringify(queryOptions.where) } : queryOptions;
|
|
1154
|
-
const queryString = (0, import_qs_esm.stringify)(encodedOptions, { addQueryPrefix: true });
|
|
1155
|
-
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
1156
|
-
}
|
|
1157
|
-
assertJsonResponse(response) {
|
|
1158
|
-
const contentType = response.headers.get("content-type");
|
|
1159
|
-
if (!contentType?.includes("application/json")) {
|
|
1160
|
-
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1161
|
-
contentType
|
|
1162
|
-
});
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* Parse Payload CMS find response (list query)
|
|
1167
|
-
* Returns native Payload response structure
|
|
1168
|
-
*/
|
|
1169
|
-
async parseFindResponse(response) {
|
|
1170
|
-
const contentType = response.headers.get("content-type");
|
|
1171
|
-
try {
|
|
1172
|
-
this.assertJsonResponse(response);
|
|
1173
|
-
const jsonData = await response.json();
|
|
1174
|
-
if (jsonData.docs === void 0) {
|
|
1175
|
-
throw createApiError("Invalid find response.", response.status, {
|
|
1176
|
-
jsonData
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
return {
|
|
1180
|
-
docs: jsonData.docs,
|
|
1181
|
-
totalDocs: jsonData.totalDocs ?? 0,
|
|
1182
|
-
limit: jsonData.limit || 20,
|
|
1183
|
-
totalPages: jsonData.totalPages ?? 0,
|
|
1184
|
-
page: jsonData.page || 1,
|
|
1185
|
-
pagingCounter: jsonData.pagingCounter || 1,
|
|
1186
|
-
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
1187
|
-
hasNextPage: jsonData.hasNextPage ?? false,
|
|
1188
|
-
prevPage: jsonData.prevPage ?? null,
|
|
1189
|
-
nextPage: jsonData.nextPage ?? null
|
|
1190
|
-
};
|
|
1191
|
-
} catch (error) {
|
|
1192
|
-
if (error instanceof SDKError) throw error;
|
|
1193
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1194
|
-
contentType,
|
|
1195
|
-
error: error instanceof Error ? error.message : error
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
1077
|
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
* Returns native Payload response structure
|
|
1202
|
-
*/
|
|
1203
|
-
async parseMutationResponse(response) {
|
|
1204
|
-
const contentType = response.headers.get("content-type");
|
|
1205
|
-
try {
|
|
1206
|
-
this.assertJsonResponse(response);
|
|
1207
|
-
const jsonData = await response.json();
|
|
1208
|
-
if (jsonData.doc === void 0) {
|
|
1209
|
-
throw createApiError("Invalid mutation response.", response.status, {
|
|
1210
|
-
jsonData
|
|
1211
|
-
});
|
|
1212
|
-
}
|
|
1213
|
-
return {
|
|
1214
|
-
message: jsonData.message || "",
|
|
1215
|
-
doc: jsonData.doc,
|
|
1216
|
-
errors: jsonData.errors
|
|
1217
|
-
};
|
|
1218
|
-
} catch (error) {
|
|
1219
|
-
if (error instanceof SDKError) throw error;
|
|
1220
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1221
|
-
contentType,
|
|
1222
|
-
error: error instanceof Error ? error.message : error
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1078
|
+
if (parsed === null || typeof parsed !== "object") {
|
|
1079
|
+
return parsed;
|
|
1225
1080
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1081
|
+
const data = parsed;
|
|
1082
|
+
const hasCommerceEnvelopeSignal = options.errorFamily === "commerce" && ["error", "reason", "requestId", "retryable", "details"].some(
|
|
1083
|
+
(key) => Object.prototype.hasOwnProperty.call(data, key)
|
|
1084
|
+
);
|
|
1085
|
+
if (data.error || hasCommerceEnvelopeSignal) {
|
|
1086
|
+
const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
|
|
1087
|
+
const reason = typeof data.reason === "string" ? data.reason : void 0;
|
|
1088
|
+
const requestId = response.headers.get("x-request-id") ?? void 0;
|
|
1089
|
+
const retryAfter = parseRetryAfter(response).seconds;
|
|
1090
|
+
let error;
|
|
1091
|
+
if (reason === "validation_failed") {
|
|
1092
|
+
error = createValidationError(errorMessage, data, errorMessage);
|
|
1093
|
+
} else if (reason === "token_expired" || reason === "token_invalid" || reason === "preview_token_invalid" || reason === "preview_token_required" || reason === "key_invalid" || reason === "key_revoked") {
|
|
1094
|
+
error = createAuthError(errorMessage, data, errorMessage);
|
|
1095
|
+
} else if (reason === "forbidden") {
|
|
1096
|
+
error = createPermissionError(errorMessage, data, errorMessage);
|
|
1097
|
+
} else if (reason === "rate_limit_exceeded") {
|
|
1098
|
+
error = createRateLimitError(errorMessage, retryAfter, data, errorMessage);
|
|
1099
|
+
} else if (reason === "not_found") {
|
|
1100
|
+
error = createNotFoundError(errorMessage, data, errorMessage);
|
|
1101
|
+
} else if (reason === "conflict") {
|
|
1102
|
+
error = createConflictError(errorMessage, data, errorMessage);
|
|
1103
|
+
} else {
|
|
1104
|
+
error = createApiError(
|
|
1105
|
+
errorMessage,
|
|
1106
|
+
response.status,
|
|
1107
|
+
data,
|
|
1108
|
+
errorMessage,
|
|
1109
|
+
"An error occurred while processing the request."
|
|
1110
|
+
);
|
|
1242
1111
|
}
|
|
1112
|
+
const withRequestId = attachRequestId(error, requestId);
|
|
1113
|
+
if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
|
|
1114
|
+
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
|
|
1243
1115
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
// src/utils/types.ts
|
|
1247
|
-
function resolveRelation(ref) {
|
|
1248
|
-
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
1249
|
-
return null;
|
|
1250
|
-
return ref;
|
|
1116
|
+
return data;
|
|
1251
1117
|
}
|
|
1252
1118
|
|
|
1253
|
-
//
|
|
1254
|
-
var
|
|
1255
|
-
var
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1119
|
+
// ../../internal/http-contracts/src/index.ts
|
|
1120
|
+
var operationBrand = /* @__PURE__ */ Symbol("sdk-http-operation");
|
|
1121
|
+
var PORTONE_STANDARD_ACTION_CAPABILITIES_MEDIA_TYPE = "application/vnd.01software.portone-action-capabilities.v1+json";
|
|
1122
|
+
var operation = (collection, method, path, errorFamily) => Object.freeze({
|
|
1123
|
+
[operationBrand]: true,
|
|
1124
|
+
collection,
|
|
1125
|
+
method,
|
|
1126
|
+
path,
|
|
1127
|
+
...errorFamily && { errorFamily }
|
|
1128
|
+
});
|
|
1129
|
+
var strictCommerceOperation = (collection, method, path) => operation(collection, method, path, "commerce");
|
|
1130
|
+
var selectiveCommerceOperation = (collection, method, path, typedCommerceErrorReasons) => Object.freeze({
|
|
1131
|
+
...operation(collection, method, path),
|
|
1132
|
+
typedCommerceErrorReasons: Object.freeze([...typedCommerceErrorReasons])
|
|
1133
|
+
});
|
|
1134
|
+
var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
1135
|
+
products: {
|
|
1136
|
+
detail: operation("products", "get", "/detail"),
|
|
1137
|
+
detailCatalog: operation("products", "get", "/detail/catalog"),
|
|
1138
|
+
listingGroups: operation("products", "get", "/listing-groups"),
|
|
1139
|
+
listingGroupsCatalog: operation(
|
|
1140
|
+
"products",
|
|
1141
|
+
"get",
|
|
1142
|
+
"/listing-groups/catalog"
|
|
1143
|
+
),
|
|
1144
|
+
listingGroupsQuery: operation("products", "post", "/listing-groups/query"),
|
|
1145
|
+
listingGroupsQueryGet: operation(
|
|
1146
|
+
"products",
|
|
1147
|
+
"get",
|
|
1148
|
+
"/listing-groups/query"
|
|
1149
|
+
),
|
|
1150
|
+
listingGroupsQueryCatalog: operation(
|
|
1151
|
+
"products",
|
|
1152
|
+
"get",
|
|
1153
|
+
"/listing-groups/query/catalog"
|
|
1154
|
+
),
|
|
1155
|
+
stockCheck: operation("products", "post", "/stock-check"),
|
|
1156
|
+
stockSnapshot: operation("products", "get", "/stock"),
|
|
1157
|
+
upsert: operation("products", "post", "/upsert"),
|
|
1158
|
+
graphRevision: operation("products", "get", "/:id/graph-revision"),
|
|
1159
|
+
variantsPatch: operation("products", "patch", "/:id/variants")
|
|
1160
|
+
},
|
|
1161
|
+
orders: {
|
|
1162
|
+
create: operation("orders", "post", "/create"),
|
|
1163
|
+
update: operation("orders", "post", "/update"),
|
|
1164
|
+
confirmPayment: operation("orders", "post", "/confirm-payment"),
|
|
1165
|
+
byPayment: operation("orders", "get", "/by-payment"),
|
|
1166
|
+
cancel: operation("orders", "post", "/cancel"),
|
|
1167
|
+
resolveCancelRefund: selectiveCommerceOperation(
|
|
1168
|
+
"orders",
|
|
1169
|
+
"post",
|
|
1170
|
+
"/resolve-cancel-refund",
|
|
1171
|
+
["managed_refund_attestation_forbidden"]
|
|
1172
|
+
),
|
|
1173
|
+
checkout: strictCommerceOperation("orders", "post", "/checkout"),
|
|
1174
|
+
createFulfillment: operation("orders", "post", "/create-fulfillment"),
|
|
1175
|
+
updateFulfillment: operation("orders", "post", "/update-fulfillment")
|
|
1176
|
+
},
|
|
1177
|
+
checkouts: {
|
|
1178
|
+
detail: strictCommerceOperation("checkouts", "post", "/detail"),
|
|
1179
|
+
query: strictCommerceOperation("checkouts", "post", "/query")
|
|
1180
|
+
},
|
|
1181
|
+
draftOrders: {
|
|
1182
|
+
calculate: operation("draft-orders", "post", "/:id/calculate"),
|
|
1183
|
+
complete: operation("draft-orders", "post", "/:id/complete"),
|
|
1184
|
+
finalize: operation("draft-orders", "post", "/:id/finalize")
|
|
1185
|
+
},
|
|
1186
|
+
transactions: {
|
|
1187
|
+
update: operation("transactions", "post", "/update")
|
|
1188
|
+
},
|
|
1189
|
+
returns: {
|
|
1190
|
+
create: operation("returns", "post", "/create"),
|
|
1191
|
+
update: operation("returns", "post", "/update"),
|
|
1192
|
+
returnRefund: operation("returns", "post", "/return-refund")
|
|
1193
|
+
},
|
|
1194
|
+
fulfillmentOrders: {
|
|
1195
|
+
prepare: operation(
|
|
1196
|
+
"fulfillment-orders",
|
|
1197
|
+
"post",
|
|
1198
|
+
"/prepare-fulfillment-order"
|
|
1199
|
+
)
|
|
1200
|
+
},
|
|
1201
|
+
fulfillments: {
|
|
1202
|
+
bulkImport: operation("fulfillments", "post", "/bulk-import")
|
|
1203
|
+
},
|
|
1204
|
+
carts: {
|
|
1205
|
+
create: strictCommerceOperation("carts", "post", "/create"),
|
|
1206
|
+
retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
|
|
1207
|
+
mine: strictCommerceOperation("carts", "post", "/mine"),
|
|
1208
|
+
merge: strictCommerceOperation("carts", "post", "/merge"),
|
|
1209
|
+
addItem: strictCommerceOperation("carts", "post", "/add-item"),
|
|
1210
|
+
updateItem: strictCommerceOperation("carts", "post", "/update-item"),
|
|
1211
|
+
removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
|
|
1212
|
+
updateDiscountCodes: strictCommerceOperation(
|
|
1213
|
+
"carts",
|
|
1214
|
+
"post",
|
|
1215
|
+
"/update-discount-codes"
|
|
1216
|
+
),
|
|
1217
|
+
updateAttributes: strictCommerceOperation(
|
|
1218
|
+
"carts",
|
|
1219
|
+
"post",
|
|
1220
|
+
"/update-attributes"
|
|
1221
|
+
),
|
|
1222
|
+
clear: strictCommerceOperation("carts", "post", "/clear")
|
|
1223
|
+
},
|
|
1224
|
+
paymentSessions: {
|
|
1225
|
+
create: strictCommerceOperation("payment-sessions", "post", "/create"),
|
|
1226
|
+
retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
|
|
1227
|
+
cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
|
|
1228
|
+
server: {
|
|
1229
|
+
create: strictCommerceOperation(
|
|
1230
|
+
"payment-sessions",
|
|
1231
|
+
"post",
|
|
1232
|
+
"/server/create"
|
|
1233
|
+
),
|
|
1234
|
+
retrieve: strictCommerceOperation(
|
|
1235
|
+
"payment-sessions",
|
|
1236
|
+
"post",
|
|
1237
|
+
"/server/retrieve"
|
|
1238
|
+
),
|
|
1239
|
+
cancel: strictCommerceOperation(
|
|
1240
|
+
"payment-sessions",
|
|
1241
|
+
"post",
|
|
1242
|
+
"/server/cancel"
|
|
1243
|
+
),
|
|
1244
|
+
confirm: strictCommerceOperation(
|
|
1245
|
+
"payment-sessions",
|
|
1246
|
+
"post",
|
|
1247
|
+
"/server/confirm"
|
|
1248
|
+
),
|
|
1249
|
+
findPortOne: strictCommerceOperation(
|
|
1250
|
+
"payment-sessions",
|
|
1251
|
+
"post",
|
|
1252
|
+
"/server/portone/find"
|
|
1253
|
+
),
|
|
1254
|
+
reconcilePortOne: strictCommerceOperation(
|
|
1255
|
+
"payment-sessions",
|
|
1256
|
+
"post",
|
|
1257
|
+
"/server/portone/reconcile"
|
|
1258
|
+
)
|
|
1259
|
+
},
|
|
1260
|
+
custom: {
|
|
1261
|
+
create: operation("orders", "post", "/custom-payment-sessions"),
|
|
1262
|
+
retrieve: operation(
|
|
1263
|
+
"orders",
|
|
1264
|
+
"post",
|
|
1265
|
+
"/custom-payment-sessions/retrieve"
|
|
1266
|
+
),
|
|
1267
|
+
confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
|
|
1268
|
+
}
|
|
1269
|
+
},
|
|
1270
|
+
shippingPolicies: {
|
|
1271
|
+
calculate: operation("shipping-policies", "post", "/calculate")
|
|
1272
|
+
},
|
|
1273
|
+
discounts: {
|
|
1274
|
+
validate: operation("discounts", "post", "/validate")
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
var portOneStandardActionCapabilityOperations = /* @__PURE__ */ new Set([
|
|
1278
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create,
|
|
1279
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve,
|
|
1280
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create,
|
|
1281
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
|
|
1282
|
+
]);
|
|
1283
|
+
var MEMBERSHIP_ENDPOINT_OPERATIONS = {
|
|
1284
|
+
subscribe: operation(null, "post", "/memberships/subscribe"),
|
|
1285
|
+
billingCustody: operation(null, "post", "/memberships/billing-custody"),
|
|
1286
|
+
cancel: operation(null, "post", "/memberships/:id/cancel"),
|
|
1287
|
+
me: operation(null, "get", "/memberships/me"),
|
|
1288
|
+
chargeResult: operation(null, "post", "/memberships/:id/charge-result"),
|
|
1289
|
+
refundResult: operation(null, "post", "/memberships/:id/refund-result"),
|
|
1290
|
+
revoke: operation(null, "post", "/memberships/:id/revoke")
|
|
1291
|
+
};
|
|
1292
|
+
var EXTERNAL_EFFECT_CLAIM_ENDPOINT_OPERATIONS = {
|
|
1293
|
+
claim: operation(null, "post", "/external-effect-claims/claim"),
|
|
1294
|
+
get: operation(null, "post", "/external-effect-claims/get"),
|
|
1295
|
+
arm: operation(null, "post", "/external-effect-claims/arm"),
|
|
1296
|
+
release: operation(null, "post", "/external-effect-claims/release"),
|
|
1297
|
+
report: operation(null, "post", "/external-effect-claims/report"),
|
|
1298
|
+
recovery: operation(null, "post", "/external-effect-claims/recovery")
|
|
1299
|
+
};
|
|
1300
|
+
var INSTALLATION_CREDENTIAL_ENDPOINT_OPERATIONS = {
|
|
1301
|
+
create: operation(null, "post", "/installation-credentials/create"),
|
|
1302
|
+
get: operation(null, "post", "/installation-credentials/get"),
|
|
1303
|
+
replace: operation(null, "post", "/installation-credentials/replace"),
|
|
1304
|
+
dispose: operation(null, "post", "/installation-credentials/dispose")
|
|
1305
|
+
};
|
|
1306
|
+
var EXTERNAL_CUSTOMER_LINK_ENDPOINT_OPERATIONS = {
|
|
1307
|
+
connect: operation("customers", "post", "/external-links/connect"),
|
|
1308
|
+
get: operation("customers", "post", "/external-links/get"),
|
|
1309
|
+
list: operation("customers", "post", "/external-links/list"),
|
|
1310
|
+
unlink: operation("customers", "post", "/external-links/unlink"),
|
|
1311
|
+
capturePreviousState: operation(
|
|
1312
|
+
"customers",
|
|
1313
|
+
"post",
|
|
1314
|
+
"/external-links/capture-previous-state"
|
|
1315
|
+
),
|
|
1316
|
+
clearPreviousState: operation(
|
|
1317
|
+
"customers",
|
|
1318
|
+
"post",
|
|
1319
|
+
"/external-links/clear-previous-state"
|
|
1320
|
+
)
|
|
1321
|
+
};
|
|
1322
|
+
var BENEFIT_VOUCHER_ENDPOINT_OPERATIONS = {
|
|
1323
|
+
issue: operation("customers", "post", "/benefit-vouchers/issue"),
|
|
1324
|
+
get: operation("customers", "post", "/benefit-vouchers/get"),
|
|
1325
|
+
list: operation("customers", "post", "/benefit-vouchers/list"),
|
|
1326
|
+
redeem: operation("customers", "post", "/benefit-vouchers/redeem"),
|
|
1327
|
+
void: operation("customers", "post", "/benefit-vouchers/void"),
|
|
1328
|
+
listMine: operation("customers", "get", "/me/benefit-vouchers")
|
|
1329
|
+
};
|
|
1330
|
+
var CUSTOMER_GROUP_ENDPOINT_OPERATIONS = {
|
|
1331
|
+
members: operation("customer-groups", "get", "/:id/members"),
|
|
1332
|
+
grant: operation("customer-groups", "post", "/:id/members/grant"),
|
|
1333
|
+
revoke: operation("customer-groups", "post", "/:id/members/revoke")
|
|
1334
|
+
};
|
|
1335
|
+
var CUSTOMER_AUTH_ENDPOINT_OPERATIONS = {
|
|
1336
|
+
register: operation("customers", "post", "/register"),
|
|
1337
|
+
login: operation("customers", "post", "/login"),
|
|
1338
|
+
refresh: operation("customers", "post", "/refresh"),
|
|
1339
|
+
me: operation("customers", "get", "/me"),
|
|
1340
|
+
updateProfile: operation("customers", "patch", "/me"),
|
|
1341
|
+
forgotPassword: operation("customers", "post", "/forgot-password"),
|
|
1342
|
+
resetPassword: operation("customers", "post", "/reset-password"),
|
|
1343
|
+
changePassword: operation("customers", "post", "/change-password"),
|
|
1344
|
+
revokeRefresh: operation("customers", "post", "/revoke-refresh"),
|
|
1345
|
+
withdraw: operation("customers", "post", "/withdraw")
|
|
1346
|
+
};
|
|
1347
|
+
var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
|
|
1348
|
+
show: operation("tenants", "get", "/embedded-admin-app"),
|
|
1349
|
+
configure: operation("tenants", "patch", "/embedded-admin-app"),
|
|
1350
|
+
disable: operation("tenants", "delete", "/embedded-admin-app")
|
|
1351
|
+
};
|
|
1352
|
+
var EVENTS_ENDPOINT_OPERATIONS = {
|
|
1353
|
+
registrations: {
|
|
1354
|
+
listMine: operation("event-registrations", "get", "/my")
|
|
1355
|
+
},
|
|
1356
|
+
events: {
|
|
1357
|
+
convertSchedule: operation("events", "post", "/:id/schedule")
|
|
1358
|
+
},
|
|
1359
|
+
occurrences: {
|
|
1360
|
+
range: operation("event-occurrences", "get", "/range"),
|
|
1361
|
+
admissionAvailability: operation(
|
|
1362
|
+
"event-occurrences",
|
|
1363
|
+
"get",
|
|
1364
|
+
"/admission-availability"
|
|
1365
|
+
)
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
var COMMUNITY_ENDPOINT_OPERATIONS = {
|
|
1369
|
+
posts: {
|
|
1370
|
+
detail: operation("posts", "get", "/detail")
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
var GALLERY_ENDPOINT_OPERATIONS = {
|
|
1374
|
+
items: {
|
|
1375
|
+
storefront: operation("gallery-items", "get", "/storefront")
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
var VIDEO_ENDPOINT_OPERATIONS = {
|
|
1379
|
+
playback: operation("videos", "post", "/:id/playback")
|
|
1380
|
+
};
|
|
1381
|
+
function resolveOperationTemplate(descriptor) {
|
|
1382
|
+
return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
|
|
1383
|
+
}
|
|
1384
|
+
function resolveOperationPath(descriptor, options) {
|
|
1385
|
+
const path = resolveOperationTemplate(descriptor).replace(
|
|
1386
|
+
/:([A-Za-z][A-Za-z0-9_]*)/g,
|
|
1387
|
+
(_, key) => {
|
|
1388
|
+
const value = options?.pathParams?.[key];
|
|
1389
|
+
if (value === void 0) {
|
|
1390
|
+
throw new TypeError(`Missing path parameter: ${key}`);
|
|
1391
|
+
}
|
|
1392
|
+
return encodeURIComponent(value);
|
|
1393
|
+
}
|
|
1394
|
+
);
|
|
1395
|
+
const unresolved = path.match(/:([A-Za-z][A-Za-z0-9_]*)/);
|
|
1396
|
+
if (unresolved) {
|
|
1397
|
+
throw new TypeError(`Missing path parameter: ${unresolved[1]}`);
|
|
1398
|
+
}
|
|
1399
|
+
const query = options?.query?.toString().replace(/^\?/, "");
|
|
1400
|
+
return query ? `${path}?${query}` : path;
|
|
1401
|
+
}
|
|
1402
|
+
function resolveOperationMethod(descriptor) {
|
|
1403
|
+
return descriptor.method.toUpperCase();
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
// src/core/api/endpoints.ts
|
|
1407
|
+
var sharedEndpoint = (descriptor) => descriptor;
|
|
1408
|
+
function resolveOperationErrorFamily(descriptor) {
|
|
1409
|
+
return descriptor.errorFamily;
|
|
1410
|
+
}
|
|
1411
|
+
function resolveOperationTypedCommerceErrorReasons(descriptor) {
|
|
1412
|
+
return descriptor.typedCommerceErrorReasons;
|
|
1413
|
+
}
|
|
1414
|
+
var COMMERCE_ENDPOINTS = {
|
|
1415
|
+
products: {
|
|
1416
|
+
detail: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.detail),
|
|
1417
|
+
detailCatalog: sharedEndpoint(
|
|
1418
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.detailCatalog
|
|
1419
|
+
),
|
|
1420
|
+
listingGroups: sharedEndpoint(
|
|
1421
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroups
|
|
1422
|
+
),
|
|
1423
|
+
listingGroupsCatalog: sharedEndpoint(
|
|
1424
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsCatalog
|
|
1425
|
+
),
|
|
1426
|
+
// The manifest keeps the GET read and the POST body-query apart; this
|
|
1427
|
+
// semantic name has always resolved to the GET one.
|
|
1428
|
+
listingGroupsQuery: sharedEndpoint(
|
|
1429
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryGet
|
|
1430
|
+
),
|
|
1431
|
+
listingGroupsQueryCatalog: sharedEndpoint(
|
|
1432
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.listingGroupsQueryCatalog
|
|
1433
|
+
),
|
|
1434
|
+
stockCheck: sharedEndpoint(
|
|
1435
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.stockCheck
|
|
1436
|
+
),
|
|
1437
|
+
stockSnapshot: sharedEndpoint(
|
|
1438
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.stockSnapshot
|
|
1439
|
+
),
|
|
1440
|
+
upsert: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.products.upsert)
|
|
1441
|
+
},
|
|
1442
|
+
orders: {
|
|
1443
|
+
update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.update),
|
|
1444
|
+
byPayment: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.byPayment),
|
|
1445
|
+
cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.cancel),
|
|
1446
|
+
resolveCancelRefund: sharedEndpoint(
|
|
1447
|
+
COMMERCE_ENDPOINT_OPERATIONS.orders.resolveCancelRefund
|
|
1448
|
+
),
|
|
1449
|
+
createFulfillment: sharedEndpoint(
|
|
1450
|
+
COMMERCE_ENDPOINT_OPERATIONS.orders.createFulfillment
|
|
1451
|
+
),
|
|
1452
|
+
updateFulfillment: sharedEndpoint(
|
|
1453
|
+
COMMERCE_ENDPOINT_OPERATIONS.orders.updateFulfillment
|
|
1454
|
+
)
|
|
1455
|
+
},
|
|
1456
|
+
checkouts: {
|
|
1457
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1458
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1459
|
+
server: {
|
|
1460
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.orders.checkout),
|
|
1461
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.detail),
|
|
1462
|
+
query: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.checkouts.query)
|
|
1463
|
+
}
|
|
1464
|
+
},
|
|
1465
|
+
returns: {
|
|
1466
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.create),
|
|
1467
|
+
update: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.returns.update),
|
|
1468
|
+
returnRefund: sharedEndpoint(
|
|
1469
|
+
COMMERCE_ENDPOINT_OPERATIONS.returns.returnRefund
|
|
1470
|
+
)
|
|
1471
|
+
},
|
|
1472
|
+
fulfillmentOrders: {
|
|
1473
|
+
prepare: sharedEndpoint(
|
|
1474
|
+
COMMERCE_ENDPOINT_OPERATIONS.fulfillmentOrders.prepare
|
|
1475
|
+
)
|
|
1476
|
+
},
|
|
1477
|
+
fulfillments: {
|
|
1478
|
+
bulkImport: sharedEndpoint(
|
|
1479
|
+
COMMERCE_ENDPOINT_OPERATIONS.fulfillments.bulkImport
|
|
1480
|
+
)
|
|
1481
|
+
},
|
|
1482
|
+
carts: {
|
|
1483
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
|
|
1484
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
|
|
1485
|
+
mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
|
|
1486
|
+
merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
|
|
1487
|
+
server: {
|
|
1488
|
+
// Server credentials are an authorization lane, not a second Cart
|
|
1489
|
+
// transport. These must stay bound to the registered shared operations.
|
|
1490
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.create),
|
|
1491
|
+
retrieve: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.retrieve),
|
|
1492
|
+
mine: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.mine),
|
|
1493
|
+
merge: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.merge),
|
|
1494
|
+
addItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.addItem),
|
|
1495
|
+
updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
|
|
1496
|
+
removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
|
|
1497
|
+
updateDiscountCodes: sharedEndpoint(
|
|
1498
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
|
|
1499
|
+
),
|
|
1500
|
+
updateAttributes: sharedEndpoint(
|
|
1501
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
|
|
1502
|
+
),
|
|
1503
|
+
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1287
1504
|
},
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
return this.api.requestFindById(
|
|
1336
|
-
`/api/${String(this.collection)}/${String(id)}`,
|
|
1337
|
-
options
|
|
1338
|
-
);
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Create a new document
|
|
1342
|
-
* POST /api/{collection}
|
|
1343
|
-
* @returns Payload CMS mutation response with doc and message
|
|
1344
|
-
*/
|
|
1345
|
-
async create(data, options) {
|
|
1346
|
-
const endpoint = `/api/${String(this.collection)}`;
|
|
1347
|
-
if (options?.file) {
|
|
1348
|
-
return this.api.requestCreateWithFile(
|
|
1349
|
-
endpoint,
|
|
1350
|
-
data,
|
|
1351
|
-
options.file,
|
|
1352
|
-
options.filename
|
|
1353
|
-
);
|
|
1505
|
+
addItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.addItem),
|
|
1506
|
+
updateItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.updateItem),
|
|
1507
|
+
removeItem: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.removeItem),
|
|
1508
|
+
updateDiscountCodes: sharedEndpoint(
|
|
1509
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateDiscountCodes
|
|
1510
|
+
),
|
|
1511
|
+
updateAttributes: sharedEndpoint(
|
|
1512
|
+
COMMERCE_ENDPOINT_OPERATIONS.carts.updateAttributes
|
|
1513
|
+
),
|
|
1514
|
+
clear: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.carts.clear)
|
|
1515
|
+
},
|
|
1516
|
+
paymentSessions: {
|
|
1517
|
+
create: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.create),
|
|
1518
|
+
retrieve: sharedEndpoint(
|
|
1519
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.retrieve
|
|
1520
|
+
),
|
|
1521
|
+
cancel: sharedEndpoint(COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.cancel),
|
|
1522
|
+
custom: {
|
|
1523
|
+
create: sharedEndpoint(
|
|
1524
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.create
|
|
1525
|
+
),
|
|
1526
|
+
retrieve: sharedEndpoint(
|
|
1527
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.retrieve
|
|
1528
|
+
),
|
|
1529
|
+
confirm: sharedEndpoint(
|
|
1530
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.custom.confirm
|
|
1531
|
+
)
|
|
1532
|
+
},
|
|
1533
|
+
server: {
|
|
1534
|
+
create: sharedEndpoint(
|
|
1535
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.create
|
|
1536
|
+
),
|
|
1537
|
+
retrieve: sharedEndpoint(
|
|
1538
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.retrieve
|
|
1539
|
+
),
|
|
1540
|
+
cancel: sharedEndpoint(
|
|
1541
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.cancel
|
|
1542
|
+
),
|
|
1543
|
+
confirm: sharedEndpoint(
|
|
1544
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.confirm
|
|
1545
|
+
),
|
|
1546
|
+
findPortOne: sharedEndpoint(
|
|
1547
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.findPortOne
|
|
1548
|
+
),
|
|
1549
|
+
reconcilePortOne: sharedEndpoint(
|
|
1550
|
+
COMMERCE_ENDPOINT_OPERATIONS.paymentSessions.server.reconcilePortOne
|
|
1551
|
+
)
|
|
1354
1552
|
}
|
|
1355
|
-
|
|
1553
|
+
},
|
|
1554
|
+
shippingPolicies: {
|
|
1555
|
+
calculate: sharedEndpoint(
|
|
1556
|
+
COMMERCE_ENDPOINT_OPERATIONS.shippingPolicies.calculate
|
|
1557
|
+
)
|
|
1356
1558
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
if (options?.file) {
|
|
1365
|
-
return this.api.requestUpdateWithFile(
|
|
1366
|
-
endpoint,
|
|
1367
|
-
data,
|
|
1368
|
-
options.file,
|
|
1369
|
-
options.filename
|
|
1370
|
-
);
|
|
1559
|
+
};
|
|
1560
|
+
|
|
1561
|
+
// src/core/api/base-api.ts
|
|
1562
|
+
var ServerApiTransport = class {
|
|
1563
|
+
constructor(apiName, options) {
|
|
1564
|
+
if (!options.secretKey) {
|
|
1565
|
+
throw createConfigError(`secretKey is required for ${apiName}.`);
|
|
1371
1566
|
}
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
* GET /api/{collection}/count
|
|
1377
|
-
* @returns Count response with totalDocs
|
|
1378
|
-
*/
|
|
1379
|
-
async count(options) {
|
|
1380
|
-
return this.api.requestCount(
|
|
1381
|
-
`/api/${String(this.collection)}/count`,
|
|
1382
|
-
options
|
|
1567
|
+
this.publishableKey = requirePublishableKeyForSecret(
|
|
1568
|
+
apiName,
|
|
1569
|
+
options.publishableKey,
|
|
1570
|
+
options.secretKey
|
|
1383
1571
|
);
|
|
1572
|
+
this.secretKey = options.secretKey;
|
|
1573
|
+
this.apiUrl = options.apiUrl;
|
|
1574
|
+
this.onRequestId = options.onRequestId;
|
|
1384
1575
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1576
|
+
async request(endpoint, body, options) {
|
|
1577
|
+
const method = options?.method ?? "POST";
|
|
1578
|
+
try {
|
|
1579
|
+
const response = await httpFetch(endpoint, {
|
|
1580
|
+
method,
|
|
1581
|
+
apiUrl: this.apiUrl,
|
|
1582
|
+
publishableKey: this.publishableKey,
|
|
1583
|
+
secretKey: this.secretKey,
|
|
1584
|
+
...body !== void 0 && { body: JSON.stringify(body) },
|
|
1585
|
+
...options?.headers && { headers: options.headers },
|
|
1586
|
+
...options?.errorFamily && { errorFamily: options.errorFamily },
|
|
1587
|
+
...options?.typedCommerceErrorReasons && {
|
|
1588
|
+
typedCommerceErrorReasons: options.typedCommerceErrorReasons
|
|
1589
|
+
}
|
|
1590
|
+
});
|
|
1591
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1592
|
+
return parseApiResponse(response, endpoint, {
|
|
1593
|
+
errorFamily: options?.errorFamily
|
|
1594
|
+
});
|
|
1595
|
+
} catch (err) {
|
|
1596
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1597
|
+
this.onRequestId?.(id);
|
|
1598
|
+
throw err;
|
|
1599
|
+
}
|
|
1398
1600
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
*/
|
|
1404
|
-
async findMetadataById(id, metadataOptions) {
|
|
1405
|
-
const doc = await this.findById(id, { depth: 1 });
|
|
1406
|
-
return generateMetadata(
|
|
1407
|
-
extractSeo(doc),
|
|
1408
|
-
metadataOptions
|
|
1409
|
-
);
|
|
1601
|
+
};
|
|
1602
|
+
var BaseApi = class {
|
|
1603
|
+
constructor(apiName, options) {
|
|
1604
|
+
this.transport = new ServerApiTransport(apiName, options);
|
|
1410
1605
|
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1606
|
+
requestEndpoint(endpoint, body, options) {
|
|
1607
|
+
return this.transport.request(
|
|
1608
|
+
resolveOperationPath(endpoint, options),
|
|
1609
|
+
body,
|
|
1610
|
+
{
|
|
1611
|
+
method: resolveOperationMethod(endpoint),
|
|
1612
|
+
headers: options?.headers,
|
|
1613
|
+
errorFamily: resolveOperationErrorFamily(endpoint),
|
|
1614
|
+
typedCommerceErrorReasons: resolveOperationTypedCommerceErrorReasons(endpoint)
|
|
1615
|
+
}
|
|
1420
1616
|
);
|
|
1421
1617
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
options
|
|
1618
|
+
};
|
|
1619
|
+
var RawBaseApi = class {
|
|
1620
|
+
constructor(apiName, options) {
|
|
1621
|
+
this.transport = new ServerApiTransport(apiName, options);
|
|
1622
|
+
this.publishableKey = requirePublishableKeyForSecret(
|
|
1623
|
+
apiName,
|
|
1624
|
+
options.publishableKey,
|
|
1625
|
+
options.secretKey
|
|
1431
1626
|
);
|
|
1627
|
+
this.secretKey = options.secretKey;
|
|
1628
|
+
this.apiUrl = options.apiUrl;
|
|
1629
|
+
this.onRequestId = options.onRequestId;
|
|
1432
1630
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
* DELETE /api/{collection}
|
|
1436
|
-
* @returns Payload CMS find response with deleted docs
|
|
1437
|
-
*/
|
|
1438
|
-
async removeMany(where) {
|
|
1439
|
-
return this.api.requestDeleteMany(
|
|
1440
|
-
`/api/${String(this.collection)}`,
|
|
1441
|
-
{ where }
|
|
1442
|
-
);
|
|
1631
|
+
request(endpoint, body, options) {
|
|
1632
|
+
return this.transport.request(endpoint, body, options);
|
|
1443
1633
|
}
|
|
1444
1634
|
};
|
|
1445
|
-
var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
|
|
1446
|
-
};
|
|
1447
1635
|
|
|
1448
|
-
// src/core/
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1636
|
+
// src/core/api/benefit-voucher-types.ts
|
|
1637
|
+
var BENEFIT_VOUCHER_VOID_REASONS = [
|
|
1638
|
+
"issued_in_error",
|
|
1639
|
+
"benefit_revoked",
|
|
1640
|
+
"customer_request",
|
|
1641
|
+
"other"
|
|
1642
|
+
];
|
|
1643
|
+
function invalidBenefitVoucherResponse() {
|
|
1644
|
+
throw createApiError("Invalid benefit voucher response", 200);
|
|
1645
|
+
}
|
|
1646
|
+
function object(value, keys) {
|
|
1647
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length !== keys.length || keys.some((key) => !(key in value)))
|
|
1648
|
+
invalidBenefitVoucherResponse();
|
|
1649
|
+
return value;
|
|
1650
|
+
}
|
|
1651
|
+
var uuid = (v) => typeof v === "string" && (/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
|
|
1652
|
+
v
|
|
1653
|
+
) || v === "00000000-0000-0000-0000-000000000000" || v.toLowerCase() === "ffffffff-ffff-ffff-ffff-ffffffffffff");
|
|
1654
|
+
var time = (v) => typeof v === "string" && /^\d{4}-\d{2}-\d{2}T/.test(v) && Number.isFinite(Date.parse(v)) && new Date(Date.parse(v)).toISOString() === v;
|
|
1655
|
+
var actor = (v) => typeof v === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(v);
|
|
1656
|
+
function parseBenefitVoucher(value, mine = false) {
|
|
1657
|
+
const v = object(value, [
|
|
1658
|
+
"id",
|
|
1659
|
+
"name",
|
|
1660
|
+
"description",
|
|
1661
|
+
"state",
|
|
1662
|
+
"issuedAt",
|
|
1663
|
+
"expiresAt",
|
|
1664
|
+
...mine ? ["closedAt"] : ["customerId", "definitionId", "source", "closed"]
|
|
1665
|
+
]);
|
|
1666
|
+
if (!uuid(v.id) || typeof v.name !== "string" || !v.name.length || v.name.length > 120 || v.description !== null && (typeof v.description !== "string" || v.description.length > 1e3) || !["issued", "redeemed", "expired", "voided"].includes(v.state) || !time(v.issuedAt) || !time(v.expiresAt))
|
|
1667
|
+
invalidBenefitVoucherResponse();
|
|
1668
|
+
if (mine) {
|
|
1669
|
+
if (v.closedAt !== null && !time(v.closedAt))
|
|
1670
|
+
invalidBenefitVoucherResponse();
|
|
1671
|
+
} else {
|
|
1672
|
+
if (!uuid(v.customerId) || !uuid(v.definitionId))
|
|
1673
|
+
invalidBenefitVoucherResponse();
|
|
1674
|
+
const source = object(v.source, ["namespace", "ref"]);
|
|
1675
|
+
if (typeof source.namespace !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(source.namespace) || typeof source.ref !== "string" || !source.ref.length || source.ref.length > 256)
|
|
1676
|
+
invalidBenefitVoucherResponse();
|
|
1677
|
+
if (v.closed !== null) {
|
|
1678
|
+
const closed = object(v.closed, [
|
|
1679
|
+
"at",
|
|
1680
|
+
"channel",
|
|
1681
|
+
"actor",
|
|
1682
|
+
"actorRef",
|
|
1683
|
+
"voidReason"
|
|
1684
|
+
]);
|
|
1685
|
+
const principal = object(closed.actor, ["type", "id"]);
|
|
1686
|
+
if (!time(closed.at) || !uuid(principal.id) || !["server", "console"].includes(closed.channel) || !["server_credential", "operator"].includes(principal.type) || closed.actorRef !== null && !actor(closed.actorRef) || closed.voidReason !== null && !BENEFIT_VOUCHER_VOID_REASONS.includes(closed.voidReason))
|
|
1687
|
+
invalidBenefitVoucherResponse();
|
|
1688
|
+
}
|
|
1454
1689
|
}
|
|
1455
|
-
return
|
|
1690
|
+
return value;
|
|
1456
1691
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1692
|
+
function parseBenefitVoucherList(value, mine = false) {
|
|
1693
|
+
const v = object(value, ["vouchers", "nextCursor", "evaluatedAt"]);
|
|
1694
|
+
if (!Array.isArray(v.vouchers) || v.vouchers.length > 100 || !time(v.evaluatedAt) || v.nextCursor !== null && (typeof v.nextCursor !== "string" || !v.nextCursor.length || v.nextCursor.length > 2048))
|
|
1695
|
+
invalidBenefitVoucherResponse();
|
|
1696
|
+
for (const row of v.vouchers) {
|
|
1697
|
+
if (mine) parseBenefitVoucher(row, true);
|
|
1698
|
+
else parseBenefitVoucher(row);
|
|
1460
1699
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1700
|
+
return value;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// src/core/api/benefit-vouchers-api.ts
|
|
1704
|
+
var BenefitVouchersApi = class extends BaseApi {
|
|
1705
|
+
constructor(options) {
|
|
1706
|
+
super("BenefitVouchersApi", options);
|
|
1707
|
+
}
|
|
1708
|
+
async command(name, input) {
|
|
1709
|
+
const result = await this.requestEndpoint(BENEFIT_VOUCHER_ENDPOINT_OPERATIONS[name], input);
|
|
1710
|
+
if (!result || typeof result !== "object" || !("voucher" in result))
|
|
1711
|
+
invalidBenefitVoucherResponse();
|
|
1712
|
+
const voucher = parseBenefitVoucher(result.voucher);
|
|
1713
|
+
const key = name === "issue" ? "created" : name === "get" ? null : "replayed";
|
|
1714
|
+
if (Object.keys(result).length !== (key ? 2 : 1) || key && typeof result[key] !== "boolean")
|
|
1715
|
+
invalidBenefitVoucherResponse();
|
|
1716
|
+
return {
|
|
1717
|
+
voucher,
|
|
1718
|
+
...key ? { [key]: result[key] } : {}
|
|
1719
|
+
};
|
|
1475
1720
|
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
* POST /api/...custom-endpoint
|
|
1479
|
-
*/
|
|
1480
|
-
async requestFindEndpoint(endpoint, data) {
|
|
1481
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1482
|
-
...this.defaultOptions,
|
|
1483
|
-
method: "POST",
|
|
1484
|
-
body: data ? JSON.stringify(data) : void 0
|
|
1485
|
-
});
|
|
1486
|
-
return this.parseFindResponse(response);
|
|
1721
|
+
async issue(input) {
|
|
1722
|
+
return await this.command("issue", input);
|
|
1487
1723
|
}
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
*/
|
|
1491
|
-
async requestFindEndpointGet(endpoint) {
|
|
1492
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1493
|
-
...this.defaultOptions,
|
|
1494
|
-
method: "GET"
|
|
1495
|
-
});
|
|
1496
|
-
return this.parseFindResponse(response);
|
|
1724
|
+
async get(input) {
|
|
1725
|
+
return this.command("get", input);
|
|
1497
1726
|
}
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
async requestFindById(endpoint, options) {
|
|
1503
|
-
const url = this.buildUrl(endpoint, options);
|
|
1504
|
-
const response = await this.fetchWithTracking(url, {
|
|
1505
|
-
...this.defaultOptions,
|
|
1506
|
-
method: "GET"
|
|
1507
|
-
});
|
|
1508
|
-
return this.parseDocumentResponse(response);
|
|
1727
|
+
async list(input) {
|
|
1728
|
+
return parseBenefitVoucherList(
|
|
1729
|
+
await this.requestEndpoint(BENEFIT_VOUCHER_ENDPOINT_OPERATIONS.list, input)
|
|
1730
|
+
);
|
|
1509
1731
|
}
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
* POST /api/{collection}
|
|
1513
|
-
*/
|
|
1514
|
-
async requestCreate(endpoint, data) {
|
|
1515
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1516
|
-
...this.defaultOptions,
|
|
1517
|
-
method: "POST",
|
|
1518
|
-
body: data ? JSON.stringify(data) : void 0
|
|
1519
|
-
});
|
|
1520
|
-
return this.parseMutationResponse(response);
|
|
1732
|
+
async redeem(input) {
|
|
1733
|
+
return await this.command("redeem", input);
|
|
1521
1734
|
}
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
* PATCH /api/{collection}/{id}
|
|
1525
|
-
*/
|
|
1526
|
-
async requestUpdate(endpoint, data) {
|
|
1527
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1528
|
-
...this.defaultOptions,
|
|
1529
|
-
method: "PATCH",
|
|
1530
|
-
body: data ? JSON.stringify(data) : void 0
|
|
1531
|
-
});
|
|
1532
|
-
return this.parseMutationResponse(response);
|
|
1735
|
+
async voidVoucher(input) {
|
|
1736
|
+
return await this.command("void", input);
|
|
1533
1737
|
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1738
|
+
};
|
|
1739
|
+
|
|
1740
|
+
// src/core/collection/http-client.ts
|
|
1741
|
+
var import_qs_esm = require("qs-esm");
|
|
1742
|
+
function validateWhere(where) {
|
|
1743
|
+
if (where === void 0) return false;
|
|
1744
|
+
let hasNull = false;
|
|
1745
|
+
function visit(value, depth, key) {
|
|
1746
|
+
if (depth > 10) {
|
|
1747
|
+
throw createValidationError(
|
|
1748
|
+
"Collection where must not exceed nesting depth 10."
|
|
1749
|
+
);
|
|
1750
|
+
}
|
|
1751
|
+
if (value === null && (key === "equals" || key === "not_equals")) {
|
|
1752
|
+
hasNull = true;
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1755
|
+
if (value == null) {
|
|
1756
|
+
throw createValidationError(
|
|
1757
|
+
"Collection where must not contain null or undefined values."
|
|
1758
|
+
);
|
|
1759
|
+
}
|
|
1760
|
+
if (Array.isArray(value)) {
|
|
1761
|
+
if (value.length === 0) {
|
|
1762
|
+
throw createValidationError(
|
|
1763
|
+
"Collection where must not contain empty arrays, including and/or."
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1766
|
+
if (value.length > 1e3) {
|
|
1767
|
+
throw createValidationError(
|
|
1768
|
+
"Collection where arrays must not contain more than 1000 elements."
|
|
1769
|
+
);
|
|
1770
|
+
}
|
|
1771
|
+
for (const item of value) visit(item, depth + 1);
|
|
1772
|
+
} else if (typeof value === "object" && !(value instanceof Date)) {
|
|
1773
|
+
const values = Object.entries(value);
|
|
1774
|
+
if (values.length === 0) {
|
|
1775
|
+
throw createValidationError(
|
|
1776
|
+
"Collection where must not contain empty condition objects."
|
|
1777
|
+
);
|
|
1778
|
+
}
|
|
1779
|
+
for (const [key2, item] of values) visit(item, depth + 1, key2);
|
|
1780
|
+
}
|
|
1545
1781
|
}
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1782
|
+
visit(where, 0);
|
|
1783
|
+
return hasNull;
|
|
1784
|
+
}
|
|
1785
|
+
var HttpClient = class {
|
|
1786
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
1787
|
+
this.publishableKey = requirePublishableKeyForSecret(
|
|
1788
|
+
"CollectionClient",
|
|
1789
|
+
publishableKey,
|
|
1790
|
+
secretKey
|
|
1791
|
+
);
|
|
1792
|
+
this.secretKey = secretKey;
|
|
1793
|
+
this.getCustomerToken = getCustomerToken;
|
|
1794
|
+
this.onUnauthorized = onUnauthorized;
|
|
1795
|
+
this.onRequestId = onRequestId;
|
|
1796
|
+
this.apiUrl = apiUrl;
|
|
1558
1797
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
const
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1798
|
+
get defaultOptions() {
|
|
1799
|
+
const opts = {
|
|
1800
|
+
apiUrl: this.apiUrl,
|
|
1801
|
+
publishableKey: this.publishableKey,
|
|
1802
|
+
secretKey: this.secretKey
|
|
1803
|
+
};
|
|
1804
|
+
const token = this.getCustomerToken?.();
|
|
1805
|
+
if (token) {
|
|
1806
|
+
opts.customerToken = token;
|
|
1807
|
+
if (this.onUnauthorized) {
|
|
1808
|
+
opts.onUnauthorized = this.onUnauthorized;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
return opts;
|
|
1812
|
+
}
|
|
1813
|
+
async fetchWithTracking(url, opts) {
|
|
1814
|
+
try {
|
|
1815
|
+
const response = await httpFetch(url, opts);
|
|
1816
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1817
|
+
return response;
|
|
1818
|
+
} catch (err) {
|
|
1819
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1820
|
+
this.onRequestId?.(id);
|
|
1821
|
+
throw err;
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
buildUrl(endpoint, options) {
|
|
1825
|
+
if (!options) return endpoint;
|
|
1826
|
+
const { fallbackLocale, ...rest } = options;
|
|
1827
|
+
const queryOptions = fallbackLocale === void 0 ? rest : {
|
|
1828
|
+
...rest,
|
|
1829
|
+
"fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
|
|
1830
|
+
};
|
|
1831
|
+
const encodedOptions = validateWhere(queryOptions.where) ? { ...queryOptions, where: JSON.stringify(queryOptions.where) } : queryOptions;
|
|
1832
|
+
const queryString = (0, import_qs_esm.stringify)(encodedOptions, { addQueryPrefix: true });
|
|
1833
|
+
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
1834
|
+
}
|
|
1835
|
+
assertJsonResponse(response) {
|
|
1836
|
+
const contentType = response.headers.get("content-type");
|
|
1837
|
+
if (!contentType?.includes("application/json")) {
|
|
1838
|
+
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1839
|
+
contentType
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1570
1842
|
}
|
|
1571
1843
|
/**
|
|
1572
|
-
*
|
|
1573
|
-
*
|
|
1844
|
+
* Parse Payload CMS find response (list query)
|
|
1845
|
+
* Returns native Payload response structure
|
|
1574
1846
|
*/
|
|
1575
|
-
async
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1847
|
+
async parseFindResponse(response) {
|
|
1848
|
+
const contentType = response.headers.get("content-type");
|
|
1849
|
+
try {
|
|
1850
|
+
this.assertJsonResponse(response);
|
|
1851
|
+
const jsonData = await response.json();
|
|
1852
|
+
if (jsonData.docs === void 0) {
|
|
1853
|
+
throw createApiError("Invalid find response.", response.status, {
|
|
1854
|
+
jsonData
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
return {
|
|
1858
|
+
docs: jsonData.docs,
|
|
1859
|
+
totalDocs: jsonData.totalDocs ?? 0,
|
|
1860
|
+
limit: jsonData.limit || 20,
|
|
1861
|
+
totalPages: jsonData.totalPages ?? 0,
|
|
1862
|
+
page: jsonData.page || 1,
|
|
1863
|
+
pagingCounter: jsonData.pagingCounter || 1,
|
|
1864
|
+
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
1865
|
+
hasNextPage: jsonData.hasNextPage ?? false,
|
|
1866
|
+
prevPage: jsonData.prevPage ?? null,
|
|
1867
|
+
nextPage: jsonData.nextPage ?? null
|
|
1868
|
+
};
|
|
1869
|
+
} catch (error) {
|
|
1870
|
+
if (error instanceof SDKError) throw error;
|
|
1871
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1872
|
+
contentType,
|
|
1873
|
+
error: error instanceof Error ? error.message : error
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1582
1876
|
}
|
|
1583
1877
|
/**
|
|
1584
|
-
*
|
|
1585
|
-
*
|
|
1878
|
+
* Parse Payload CMS mutation response (create/update)
|
|
1879
|
+
* Returns native Payload response structure
|
|
1586
1880
|
*/
|
|
1587
|
-
async
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1881
|
+
async parseMutationResponse(response) {
|
|
1882
|
+
const contentType = response.headers.get("content-type");
|
|
1883
|
+
try {
|
|
1884
|
+
this.assertJsonResponse(response);
|
|
1885
|
+
const jsonData = await response.json();
|
|
1886
|
+
if (jsonData.doc === void 0) {
|
|
1887
|
+
throw createApiError("Invalid mutation response.", response.status, {
|
|
1888
|
+
jsonData
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
return {
|
|
1892
|
+
message: jsonData.message || "",
|
|
1893
|
+
doc: jsonData.doc,
|
|
1894
|
+
errors: jsonData.errors
|
|
1895
|
+
};
|
|
1896
|
+
} catch (error) {
|
|
1897
|
+
if (error instanceof SDKError) throw error;
|
|
1898
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1899
|
+
contentType,
|
|
1900
|
+
error: error instanceof Error ? error.message : error
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1594
1903
|
}
|
|
1595
1904
|
/**
|
|
1596
|
-
*
|
|
1597
|
-
*
|
|
1905
|
+
* Parse Payload CMS document response (findById/delete)
|
|
1906
|
+
* Returns document directly without wrapper
|
|
1598
1907
|
*/
|
|
1599
|
-
async
|
|
1600
|
-
const
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1908
|
+
async parseDocumentResponse(response) {
|
|
1909
|
+
const contentType = response.headers.get("content-type");
|
|
1910
|
+
try {
|
|
1911
|
+
this.assertJsonResponse(response);
|
|
1912
|
+
const jsonData = await response.json();
|
|
1913
|
+
return jsonData;
|
|
1914
|
+
} catch (error) {
|
|
1915
|
+
if (error instanceof SDKError) throw error;
|
|
1916
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1917
|
+
contentType,
|
|
1918
|
+
error: error instanceof Error ? error.message : error
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1611
1921
|
}
|
|
1612
1922
|
};
|
|
1613
1923
|
|
|
1614
|
-
// src/
|
|
1615
|
-
|
|
1616
|
-
if (
|
|
1617
|
-
return
|
|
1924
|
+
// src/utils/types.ts
|
|
1925
|
+
function resolveRelation(ref) {
|
|
1926
|
+
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
1927
|
+
return null;
|
|
1928
|
+
return ref;
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
// src/core/metadata/index.ts
|
|
1932
|
+
var OPEN_GRAPH_IMAGE_SIZE = "1200";
|
|
1933
|
+
var LEGACY_OPEN_GRAPH_IMAGE_SIZE = "1536";
|
|
1934
|
+
function extractSeo(doc) {
|
|
1935
|
+
const seo = doc.seo ?? {};
|
|
1936
|
+
const og = seo.openGraph ?? {};
|
|
1937
|
+
return {
|
|
1938
|
+
title: seo.title ?? doc.title ?? null,
|
|
1939
|
+
description: seo.description ?? null,
|
|
1940
|
+
noIndex: seo.noIndex ?? null,
|
|
1941
|
+
canonical: seo.canonical ?? null,
|
|
1942
|
+
openGraph: {
|
|
1943
|
+
title: og.title ?? null,
|
|
1944
|
+
description: og.description ?? null,
|
|
1945
|
+
image: og.image ?? null
|
|
1946
|
+
}
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
function generateMetadata(input, options) {
|
|
1950
|
+
const title = input.title ?? void 0;
|
|
1951
|
+
const description = input.description ?? void 0;
|
|
1952
|
+
const ogTitle = input.openGraph?.title ?? title;
|
|
1953
|
+
const ogDescription = input.openGraph?.description ?? description;
|
|
1954
|
+
const image = resolveMetaImage(input.openGraph?.image);
|
|
1955
|
+
return {
|
|
1956
|
+
title,
|
|
1957
|
+
description,
|
|
1958
|
+
...input.noIndex && { robots: { index: false, follow: false } },
|
|
1959
|
+
...input.canonical && { alternates: { canonical: input.canonical } },
|
|
1960
|
+
openGraph: {
|
|
1961
|
+
...ogTitle && { title: ogTitle },
|
|
1962
|
+
...ogDescription && { description: ogDescription },
|
|
1963
|
+
...options?.siteName && { siteName: options.siteName },
|
|
1964
|
+
...image && { images: [image] }
|
|
1965
|
+
},
|
|
1966
|
+
twitter: {
|
|
1967
|
+
card: image ? "summary_large_image" : "summary",
|
|
1968
|
+
...ogTitle && { title: ogTitle },
|
|
1969
|
+
...ogDescription && { description: ogDescription },
|
|
1970
|
+
...image && { images: [image.url] }
|
|
1971
|
+
}
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
function resolveMetaImage(ref) {
|
|
1975
|
+
const image = resolveRelation(ref);
|
|
1976
|
+
if (!image) return null;
|
|
1977
|
+
const sized = image.sizes?.[OPEN_GRAPH_IMAGE_SIZE] ?? image.sizes?.[LEGACY_OPEN_GRAPH_IMAGE_SIZE];
|
|
1978
|
+
const url = sized?.url || image.url;
|
|
1979
|
+
if (!url) return null;
|
|
1980
|
+
const width = sized?.url ? sized.width : image.width;
|
|
1981
|
+
const height = sized?.url ? sized.height : image.height;
|
|
1982
|
+
return {
|
|
1983
|
+
url,
|
|
1984
|
+
...width && { width },
|
|
1985
|
+
...height && { height },
|
|
1986
|
+
...image.alt && { alt: image.alt }
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
// src/core/collection/query-builder.ts
|
|
1991
|
+
var CollectionQueryBuilder = class {
|
|
1992
|
+
constructor(api, collection) {
|
|
1993
|
+
this.api = api;
|
|
1994
|
+
this.collection = collection;
|
|
1618
1995
|
}
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
"Check if the API endpoint is available."
|
|
1996
|
+
/**
|
|
1997
|
+
* Find documents (list query)
|
|
1998
|
+
* GET /api/{collection}
|
|
1999
|
+
* @returns Payload CMS find response with docs array and pagination
|
|
2000
|
+
*/
|
|
2001
|
+
async find(options) {
|
|
2002
|
+
return this.api.requestFind(
|
|
2003
|
+
`/api/${String(this.collection)}`,
|
|
2004
|
+
options
|
|
1629
2005
|
);
|
|
1630
2006
|
}
|
|
1631
|
-
|
|
1632
|
-
|
|
2007
|
+
/**
|
|
2008
|
+
* Find document by ID
|
|
2009
|
+
* GET /api/{collection}/{id}
|
|
2010
|
+
* @returns Document object directly (no wrapper)
|
|
2011
|
+
*/
|
|
2012
|
+
async findById(id, options) {
|
|
2013
|
+
return this.api.requestFindById(
|
|
2014
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
2015
|
+
options
|
|
2016
|
+
);
|
|
1633
2017
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
const
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
if (reason === "validation_failed") {
|
|
1645
|
-
error = createValidationError(errorMessage, data, errorMessage);
|
|
1646
|
-
} else if (reason === "token_expired" || reason === "token_invalid" || reason === "preview_token_invalid" || reason === "preview_token_required" || reason === "key_invalid" || reason === "key_revoked") {
|
|
1647
|
-
error = createAuthError(errorMessage, data, errorMessage);
|
|
1648
|
-
} else if (reason === "forbidden") {
|
|
1649
|
-
error = createPermissionError(errorMessage, data, errorMessage);
|
|
1650
|
-
} else if (reason === "rate_limit_exceeded") {
|
|
1651
|
-
error = createRateLimitError(errorMessage, retryAfter, data, errorMessage);
|
|
1652
|
-
} else if (reason === "not_found") {
|
|
1653
|
-
error = createNotFoundError(errorMessage, data, errorMessage);
|
|
1654
|
-
} else if (reason === "conflict") {
|
|
1655
|
-
error = createConflictError(errorMessage, data, errorMessage);
|
|
1656
|
-
} else {
|
|
1657
|
-
error = createApiError(
|
|
1658
|
-
errorMessage,
|
|
1659
|
-
response.status,
|
|
2018
|
+
/**
|
|
2019
|
+
* Create a new document
|
|
2020
|
+
* POST /api/{collection}
|
|
2021
|
+
* @returns Payload CMS mutation response with doc and message
|
|
2022
|
+
*/
|
|
2023
|
+
async create(data, options) {
|
|
2024
|
+
const endpoint = `/api/${String(this.collection)}`;
|
|
2025
|
+
if (options?.file) {
|
|
2026
|
+
return this.api.requestCreateWithFile(
|
|
2027
|
+
endpoint,
|
|
1660
2028
|
data,
|
|
1661
|
-
|
|
1662
|
-
|
|
2029
|
+
options.file,
|
|
2030
|
+
options.filename
|
|
1663
2031
|
);
|
|
1664
2032
|
}
|
|
1665
|
-
|
|
1666
|
-
if (retryAfter !== void 0) Object.assign(withRequestId, { retryAfter });
|
|
1667
|
-
throw options.errorFamily === "commerce" ? enhanceCommerceError(withRequestId, data, requestId) : enhanceNonCommerceError(withRequestId, reason);
|
|
2033
|
+
return this.api.requestCreate(endpoint, data);
|
|
1668
2034
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
var selectiveCommerceOperation = (collection, method, path, typedCommerceErrorReasons) => Object.freeze({
|
|
1684
|
-
...operation(collection, method, path),
|
|
1685
|
-
typedCommerceErrorReasons: Object.freeze([...typedCommerceErrorReasons])
|
|
1686
|
-
});
|
|
1687
|
-
var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
1688
|
-
products: {
|
|
1689
|
-
detail: operation("products", "get", "/detail"),
|
|
1690
|
-
detailCatalog: operation("products", "get", "/detail/catalog"),
|
|
1691
|
-
listingGroups: operation("products", "get", "/listing-groups"),
|
|
1692
|
-
listingGroupsCatalog: operation(
|
|
1693
|
-
"products",
|
|
1694
|
-
"get",
|
|
1695
|
-
"/listing-groups/catalog"
|
|
1696
|
-
),
|
|
1697
|
-
listingGroupsQuery: operation("products", "post", "/listing-groups/query"),
|
|
1698
|
-
listingGroupsQueryGet: operation(
|
|
1699
|
-
"products",
|
|
1700
|
-
"get",
|
|
1701
|
-
"/listing-groups/query"
|
|
1702
|
-
),
|
|
1703
|
-
listingGroupsQueryCatalog: operation(
|
|
1704
|
-
"products",
|
|
1705
|
-
"get",
|
|
1706
|
-
"/listing-groups/query/catalog"
|
|
1707
|
-
),
|
|
1708
|
-
stockCheck: operation("products", "post", "/stock-check"),
|
|
1709
|
-
stockSnapshot: operation("products", "get", "/stock"),
|
|
1710
|
-
upsert: operation("products", "post", "/upsert")
|
|
1711
|
-
},
|
|
1712
|
-
orders: {
|
|
1713
|
-
create: operation("orders", "post", "/create"),
|
|
1714
|
-
update: operation("orders", "post", "/update"),
|
|
1715
|
-
confirmPayment: operation("orders", "post", "/confirm-payment"),
|
|
1716
|
-
byPayment: operation("orders", "get", "/by-payment"),
|
|
1717
|
-
cancel: operation("orders", "post", "/cancel"),
|
|
1718
|
-
resolveCancelRefund: selectiveCommerceOperation(
|
|
1719
|
-
"orders",
|
|
1720
|
-
"post",
|
|
1721
|
-
"/resolve-cancel-refund",
|
|
1722
|
-
["managed_refund_attestation_forbidden"]
|
|
1723
|
-
),
|
|
1724
|
-
checkout: strictCommerceOperation("orders", "post", "/checkout"),
|
|
1725
|
-
createFulfillment: operation("orders", "post", "/create-fulfillment"),
|
|
1726
|
-
updateFulfillment: operation("orders", "post", "/update-fulfillment")
|
|
1727
|
-
},
|
|
1728
|
-
checkouts: {
|
|
1729
|
-
detail: strictCommerceOperation("checkouts", "post", "/detail"),
|
|
1730
|
-
query: strictCommerceOperation("checkouts", "post", "/query")
|
|
1731
|
-
},
|
|
1732
|
-
draftOrders: {
|
|
1733
|
-
calculate: operation("draft-orders", "post", "/:id/calculate"),
|
|
1734
|
-
complete: operation("draft-orders", "post", "/:id/complete"),
|
|
1735
|
-
finalize: operation("draft-orders", "post", "/:id/finalize")
|
|
1736
|
-
},
|
|
1737
|
-
transactions: {
|
|
1738
|
-
update: operation("transactions", "post", "/update")
|
|
1739
|
-
},
|
|
1740
|
-
returns: {
|
|
1741
|
-
create: operation("returns", "post", "/create"),
|
|
1742
|
-
update: operation("returns", "post", "/update"),
|
|
1743
|
-
returnRefund: operation("returns", "post", "/return-refund")
|
|
1744
|
-
},
|
|
1745
|
-
fulfillmentOrders: {
|
|
1746
|
-
prepare: operation(
|
|
1747
|
-
"fulfillment-orders",
|
|
1748
|
-
"post",
|
|
1749
|
-
"/prepare-fulfillment-order"
|
|
1750
|
-
)
|
|
1751
|
-
},
|
|
1752
|
-
fulfillments: {
|
|
1753
|
-
bulkImport: operation("fulfillments", "post", "/bulk-import")
|
|
1754
|
-
},
|
|
1755
|
-
carts: {
|
|
1756
|
-
create: strictCommerceOperation("carts", "post", "/create"),
|
|
1757
|
-
retrieve: strictCommerceOperation("carts", "post", "/retrieve"),
|
|
1758
|
-
mine: strictCommerceOperation("carts", "post", "/mine"),
|
|
1759
|
-
merge: strictCommerceOperation("carts", "post", "/merge"),
|
|
1760
|
-
addItem: strictCommerceOperation("carts", "post", "/add-item"),
|
|
1761
|
-
updateItem: strictCommerceOperation("carts", "post", "/update-item"),
|
|
1762
|
-
removeItem: strictCommerceOperation("carts", "post", "/remove-item"),
|
|
1763
|
-
updateDiscountCodes: strictCommerceOperation(
|
|
1764
|
-
"carts",
|
|
1765
|
-
"post",
|
|
1766
|
-
"/update-discount-codes"
|
|
1767
|
-
),
|
|
1768
|
-
updateAttributes: strictCommerceOperation(
|
|
1769
|
-
"carts",
|
|
1770
|
-
"post",
|
|
1771
|
-
"/update-attributes"
|
|
1772
|
-
),
|
|
1773
|
-
clear: strictCommerceOperation("carts", "post", "/clear")
|
|
1774
|
-
},
|
|
1775
|
-
paymentSessions: {
|
|
1776
|
-
create: strictCommerceOperation("payment-sessions", "post", "/create"),
|
|
1777
|
-
retrieve: strictCommerceOperation("payment-sessions", "post", "/retrieve"),
|
|
1778
|
-
cancel: strictCommerceOperation("payment-sessions", "post", "/cancel"),
|
|
1779
|
-
server: {
|
|
1780
|
-
create: strictCommerceOperation(
|
|
1781
|
-
"payment-sessions",
|
|
1782
|
-
"post",
|
|
1783
|
-
"/server/create"
|
|
1784
|
-
),
|
|
1785
|
-
retrieve: strictCommerceOperation(
|
|
1786
|
-
"payment-sessions",
|
|
1787
|
-
"post",
|
|
1788
|
-
"/server/retrieve"
|
|
1789
|
-
),
|
|
1790
|
-
cancel: strictCommerceOperation(
|
|
1791
|
-
"payment-sessions",
|
|
1792
|
-
"post",
|
|
1793
|
-
"/server/cancel"
|
|
1794
|
-
),
|
|
1795
|
-
confirm: strictCommerceOperation(
|
|
1796
|
-
"payment-sessions",
|
|
1797
|
-
"post",
|
|
1798
|
-
"/server/confirm"
|
|
1799
|
-
),
|
|
1800
|
-
findPortOne: strictCommerceOperation(
|
|
1801
|
-
"payment-sessions",
|
|
1802
|
-
"post",
|
|
1803
|
-
"/server/portone/find"
|
|
1804
|
-
),
|
|
1805
|
-
reconcilePortOne: strictCommerceOperation(
|
|
1806
|
-
"payment-sessions",
|
|
1807
|
-
"post",
|
|
1808
|
-
"/server/portone/reconcile"
|
|
1809
|
-
)
|
|
1810
|
-
},
|
|
1811
|
-
custom: {
|
|
1812
|
-
create: operation("orders", "post", "/custom-payment-sessions"),
|
|
1813
|
-
retrieve: operation(
|
|
1814
|
-
"orders",
|
|
1815
|
-
"post",
|
|
1816
|
-
"/custom-payment-sessions/retrieve"
|
|
1817
|
-
),
|
|
1818
|
-
confirm: operation("orders", "post", "/custom-payment-sessions/confirm")
|
|
2035
|
+
/**
|
|
2036
|
+
* Update a document by ID
|
|
2037
|
+
* PATCH /api/{collection}/{id}
|
|
2038
|
+
* @returns Payload CMS mutation response with doc and message
|
|
2039
|
+
*/
|
|
2040
|
+
async update(id, data, options) {
|
|
2041
|
+
const endpoint = `/api/${String(this.collection)}/${String(id)}`;
|
|
2042
|
+
if (options?.file) {
|
|
2043
|
+
return this.api.requestUpdateWithFile(
|
|
2044
|
+
endpoint,
|
|
2045
|
+
data,
|
|
2046
|
+
options.file,
|
|
2047
|
+
options.filename
|
|
2048
|
+
);
|
|
1819
2049
|
}
|
|
1820
|
-
|
|
1821
|
-
shippingPolicies: {
|
|
1822
|
-
calculate: operation("shipping-policies", "post", "/calculate")
|
|
1823
|
-
},
|
|
1824
|
-
discounts: {
|
|
1825
|
-
validate: operation("discounts", "post", "/validate")
|
|
2050
|
+
return this.api.requestUpdate(endpoint, data);
|
|
1826
2051
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
cancel: operation(null, "post", "/memberships/:id/cancel"),
|
|
1838
|
-
me: operation(null, "get", "/memberships/me"),
|
|
1839
|
-
chargeResult: operation(null, "post", "/memberships/:id/charge-result"),
|
|
1840
|
-
refundResult: operation(null, "post", "/memberships/:id/refund-result"),
|
|
1841
|
-
revoke: operation(null, "post", "/memberships/:id/revoke")
|
|
1842
|
-
};
|
|
1843
|
-
var EXTERNAL_EFFECT_CLAIM_ENDPOINT_OPERATIONS = {
|
|
1844
|
-
claim: operation(null, "post", "/external-effect-claims/claim"),
|
|
1845
|
-
get: operation(null, "post", "/external-effect-claims/get"),
|
|
1846
|
-
arm: operation(null, "post", "/external-effect-claims/arm"),
|
|
1847
|
-
release: operation(null, "post", "/external-effect-claims/release"),
|
|
1848
|
-
report: operation(null, "post", "/external-effect-claims/report"),
|
|
1849
|
-
recovery: operation(null, "post", "/external-effect-claims/recovery")
|
|
1850
|
-
};
|
|
1851
|
-
var INSTALLATION_CREDENTIAL_ENDPOINT_OPERATIONS = {
|
|
1852
|
-
create: operation(null, "post", "/installation-credentials/create"),
|
|
1853
|
-
get: operation(null, "post", "/installation-credentials/get"),
|
|
1854
|
-
replace: operation(null, "post", "/installation-credentials/replace"),
|
|
1855
|
-
dispose: operation(null, "post", "/installation-credentials/dispose")
|
|
1856
|
-
};
|
|
1857
|
-
var EXTERNAL_CUSTOMER_LINK_ENDPOINT_OPERATIONS = {
|
|
1858
|
-
connect: operation("customers", "post", "/external-links/connect"),
|
|
1859
|
-
get: operation("customers", "post", "/external-links/get"),
|
|
1860
|
-
list: operation("customers", "post", "/external-links/list"),
|
|
1861
|
-
unlink: operation("customers", "post", "/external-links/unlink"),
|
|
1862
|
-
capturePreviousState: operation(
|
|
1863
|
-
"customers",
|
|
1864
|
-
"post",
|
|
1865
|
-
"/external-links/capture-previous-state"
|
|
1866
|
-
),
|
|
1867
|
-
clearPreviousState: operation(
|
|
1868
|
-
"customers",
|
|
1869
|
-
"post",
|
|
1870
|
-
"/external-links/clear-previous-state"
|
|
1871
|
-
)
|
|
1872
|
-
};
|
|
1873
|
-
var CUSTOMER_GROUP_ENDPOINT_OPERATIONS = {
|
|
1874
|
-
members: operation("customer-groups", "get", "/:id/members"),
|
|
1875
|
-
grant: operation("customer-groups", "post", "/:id/members/grant"),
|
|
1876
|
-
revoke: operation("customer-groups", "post", "/:id/members/revoke")
|
|
1877
|
-
};
|
|
1878
|
-
var CUSTOMER_AUTH_ENDPOINT_OPERATIONS = {
|
|
1879
|
-
revokeRefresh: operation("customers", "post", "/revoke-refresh"),
|
|
1880
|
-
withdraw: operation("customers", "post", "/withdraw")
|
|
1881
|
-
};
|
|
1882
|
-
var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
|
|
1883
|
-
show: operation("tenants", "get", "/embedded-admin-app"),
|
|
1884
|
-
configure: operation("tenants", "patch", "/embedded-admin-app"),
|
|
1885
|
-
disable: operation("tenants", "delete", "/embedded-admin-app")
|
|
1886
|
-
};
|
|
1887
|
-
var EVENTS_ENDPOINT_OPERATIONS = {
|
|
1888
|
-
events: {
|
|
1889
|
-
convertSchedule: operation("events", "post", "/:id/schedule")
|
|
1890
|
-
},
|
|
1891
|
-
occurrences: {
|
|
1892
|
-
range: operation("event-occurrences", "get", "/range"),
|
|
1893
|
-
admissionAvailability: operation(
|
|
1894
|
-
"event-occurrences",
|
|
1895
|
-
"get",
|
|
1896
|
-
"/admission-availability"
|
|
1897
|
-
)
|
|
2052
|
+
/**
|
|
2053
|
+
* Count documents
|
|
2054
|
+
* GET /api/{collection}/count
|
|
2055
|
+
* @returns Count response with totalDocs
|
|
2056
|
+
*/
|
|
2057
|
+
async count(options) {
|
|
2058
|
+
return this.api.requestCount(
|
|
2059
|
+
`/api/${String(this.collection)}/count`,
|
|
2060
|
+
options
|
|
2061
|
+
);
|
|
1898
2062
|
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
2063
|
+
/**
|
|
2064
|
+
* Find first matching document and return its Next.js Metadata.
|
|
2065
|
+
* Applies depth: 1 (SEO image populate) and limit: 1 automatically.
|
|
2066
|
+
* @returns Metadata or null if no document matches
|
|
2067
|
+
*/
|
|
2068
|
+
async findMetadata(options, metadataOptions) {
|
|
2069
|
+
const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
|
|
2070
|
+
const doc = docs[0];
|
|
2071
|
+
if (!doc) return null;
|
|
2072
|
+
return generateMetadata(
|
|
2073
|
+
extractSeo(doc),
|
|
2074
|
+
metadataOptions
|
|
2075
|
+
);
|
|
1903
2076
|
}
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
2077
|
+
/**
|
|
2078
|
+
* Find document by ID and return its Next.js Metadata.
|
|
2079
|
+
* Applies depth: 1 (SEO image populate) automatically.
|
|
2080
|
+
* @returns Metadata (throws on 404)
|
|
2081
|
+
*/
|
|
2082
|
+
async findMetadataById(id, metadataOptions) {
|
|
2083
|
+
const doc = await this.findById(id, { depth: 1 });
|
|
2084
|
+
return generateMetadata(
|
|
2085
|
+
extractSeo(doc),
|
|
2086
|
+
metadataOptions
|
|
2087
|
+
);
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Update multiple documents (bulk update)
|
|
2091
|
+
* PATCH /api/{collection}
|
|
2092
|
+
* @returns Payload CMS find response with updated docs
|
|
2093
|
+
*/
|
|
2094
|
+
async updateMany(where, data) {
|
|
2095
|
+
return this.api.requestUpdateMany(
|
|
2096
|
+
`/api/${String(this.collection)}`,
|
|
2097
|
+
{ where, data }
|
|
2098
|
+
);
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
2101
|
+
* Delete a document by ID
|
|
2102
|
+
* DELETE /api/{collection}/{id}
|
|
2103
|
+
* @returns Deleted document object directly (no wrapper)
|
|
2104
|
+
*/
|
|
2105
|
+
async remove(id, options) {
|
|
2106
|
+
return this.api.requestDelete(
|
|
2107
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
2108
|
+
options
|
|
2109
|
+
);
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Delete multiple documents (bulk delete)
|
|
2113
|
+
* DELETE /api/{collection}
|
|
2114
|
+
* @returns Payload CMS find response with deleted docs
|
|
2115
|
+
*/
|
|
2116
|
+
async removeMany(where) {
|
|
2117
|
+
return this.api.requestDeleteMany(
|
|
2118
|
+
`/api/${String(this.collection)}`,
|
|
2119
|
+
{ where }
|
|
2120
|
+
);
|
|
1908
2121
|
}
|
|
1909
2122
|
};
|
|
1910
|
-
var
|
|
1911
|
-
playback: operation("videos", "post", "/:id/playback")
|
|
2123
|
+
var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
|
|
1912
2124
|
};
|
|
1913
|
-
function resolveOperationTemplate(descriptor) {
|
|
1914
|
-
return descriptor.collection ? `/api/${descriptor.collection}${descriptor.path}` : `/api${descriptor.path}`;
|
|
1915
|
-
}
|
|
1916
|
-
function resolveOperationPath(descriptor, options) {
|
|
1917
|
-
const path = resolveOperationTemplate(descriptor).replace(
|
|
1918
|
-
/:([A-Za-z][A-Za-z0-9_]*)/g,
|
|
1919
|
-
(_, key) => {
|
|
1920
|
-
const value = options?.pathParams?.[key];
|
|
1921
|
-
if (value === void 0) {
|
|
1922
|
-
throw new TypeError(`Missing path parameter: ${key}`);
|
|
1923
|
-
}
|
|
1924
|
-
return encodeURIComponent(value);
|
|
1925
|
-
}
|
|
1926
|
-
);
|
|
1927
|
-
const unresolved = path.match(/:([A-Za-z][A-Za-z0-9_]*)/);
|
|
1928
|
-
if (unresolved) {
|
|
1929
|
-
throw new TypeError(`Missing path parameter: ${unresolved[1]}`);
|
|
1930
|
-
}
|
|
1931
|
-
const query = options?.query?.toString().replace(/^\?/, "");
|
|
1932
|
-
return query ? `${path}?${query}` : path;
|
|
1933
|
-
}
|
|
1934
|
-
function resolveOperationMethod(descriptor) {
|
|
1935
|
-
return descriptor.method.toUpperCase();
|
|
1936
|
-
}
|
|
1937
2125
|
|
|
1938
|
-
// src/core/
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2126
|
+
// src/core/collection/collection-client.ts
|
|
2127
|
+
function buildPayloadFormData(data, file, filename) {
|
|
2128
|
+
const formData = new FormData();
|
|
2129
|
+
formData.append("file", file, filename);
|
|
2130
|
+
if (data != null) {
|
|
2131
|
+
formData.append("_payload", JSON.stringify(data));
|
|
2132
|
+
}
|
|
2133
|
+
return formData;
|
|
1945
2134
|
}
|
|
1946
|
-
var
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
)
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
)
|
|
2046
|
-
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
)
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2135
|
+
var CollectionClient = class extends HttpClient {
|
|
2136
|
+
from(collection) {
|
|
2137
|
+
return new CollectionQueryBuilder(this, collection);
|
|
2138
|
+
}
|
|
2139
|
+
// ============================================================================
|
|
2140
|
+
// Payload-native methods
|
|
2141
|
+
// ============================================================================
|
|
2142
|
+
/**
|
|
2143
|
+
* Find documents (list query)
|
|
2144
|
+
* GET /api/{collection}
|
|
2145
|
+
*/
|
|
2146
|
+
async requestFind(endpoint, options) {
|
|
2147
|
+
const url = this.buildUrl(endpoint, options);
|
|
2148
|
+
const response = await this.fetchWithTracking(url, {
|
|
2149
|
+
...this.defaultOptions,
|
|
2150
|
+
method: "GET"
|
|
2151
|
+
});
|
|
2152
|
+
return this.parseFindResponse(response);
|
|
2153
|
+
}
|
|
2154
|
+
/**
|
|
2155
|
+
* Find-like response from a custom endpoint
|
|
2156
|
+
* POST /api/...custom-endpoint
|
|
2157
|
+
*/
|
|
2158
|
+
async requestFindEndpoint(endpoint, data) {
|
|
2159
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
2160
|
+
...this.defaultOptions,
|
|
2161
|
+
method: "POST",
|
|
2162
|
+
body: data ? JSON.stringify(data) : void 0
|
|
2163
|
+
});
|
|
2164
|
+
return this.parseFindResponse(response);
|
|
2165
|
+
}
|
|
2166
|
+
/**
|
|
2167
|
+
* Find-like response from a cacheable GET custom endpoint.
|
|
2168
|
+
*/
|
|
2169
|
+
async requestFindEndpointGet(endpoint) {
|
|
2170
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
2171
|
+
...this.defaultOptions,
|
|
2172
|
+
method: "GET"
|
|
2173
|
+
});
|
|
2174
|
+
return this.parseFindResponse(response);
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Find document by ID
|
|
2178
|
+
* GET /api/{collection}/{id}
|
|
2179
|
+
*/
|
|
2180
|
+
async requestFindById(endpoint, options) {
|
|
2181
|
+
const url = this.buildUrl(endpoint, options);
|
|
2182
|
+
const response = await this.fetchWithTracking(url, {
|
|
2183
|
+
...this.defaultOptions,
|
|
2184
|
+
method: "GET"
|
|
2185
|
+
});
|
|
2186
|
+
return this.parseDocumentResponse(response);
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Create document
|
|
2190
|
+
* POST /api/{collection}
|
|
2191
|
+
*/
|
|
2192
|
+
async requestCreate(endpoint, data) {
|
|
2193
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
2194
|
+
...this.defaultOptions,
|
|
2195
|
+
method: "POST",
|
|
2196
|
+
body: data ? JSON.stringify(data) : void 0
|
|
2197
|
+
});
|
|
2198
|
+
return this.parseMutationResponse(response);
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Update document
|
|
2202
|
+
* PATCH /api/{collection}/{id}
|
|
2203
|
+
*/
|
|
2204
|
+
async requestUpdate(endpoint, data) {
|
|
2205
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
2206
|
+
...this.defaultOptions,
|
|
2207
|
+
method: "PATCH",
|
|
2208
|
+
body: data ? JSON.stringify(data) : void 0
|
|
2209
|
+
});
|
|
2210
|
+
return this.parseMutationResponse(response);
|
|
2211
|
+
}
|
|
2212
|
+
/**
|
|
2213
|
+
* Count documents
|
|
2214
|
+
* GET /api/{collection}/count
|
|
2215
|
+
*/
|
|
2216
|
+
async requestCount(endpoint, options) {
|
|
2217
|
+
const url = this.buildUrl(endpoint, options);
|
|
2218
|
+
const response = await this.fetchWithTracking(url, {
|
|
2219
|
+
...this.defaultOptions,
|
|
2220
|
+
method: "GET"
|
|
2221
|
+
});
|
|
2222
|
+
return this.parseDocumentResponse(response);
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* Update multiple documents (bulk update)
|
|
2226
|
+
* PATCH /api/{collection}
|
|
2227
|
+
*/
|
|
2228
|
+
async requestUpdateMany(endpoint, data) {
|
|
2229
|
+
const url = this.buildUrl(endpoint, { where: data.where });
|
|
2230
|
+
const response = await this.fetchWithTracking(url, {
|
|
2231
|
+
...this.defaultOptions,
|
|
2232
|
+
method: "PATCH",
|
|
2233
|
+
body: JSON.stringify(data.data)
|
|
2234
|
+
});
|
|
2235
|
+
return this.parseFindResponse(response);
|
|
2236
|
+
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Delete document
|
|
2239
|
+
* DELETE /api/{collection}/{id}
|
|
2240
|
+
*/
|
|
2241
|
+
async requestDelete(endpoint, options) {
|
|
2242
|
+
const url = this.buildUrl(endpoint, options);
|
|
2243
|
+
const response = await this.fetchWithTracking(url, {
|
|
2244
|
+
...this.defaultOptions,
|
|
2245
|
+
method: "DELETE"
|
|
2246
|
+
});
|
|
2247
|
+
return this.parseDocumentResponse(response);
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Delete multiple documents (bulk delete)
|
|
2251
|
+
* DELETE /api/{collection}
|
|
2252
|
+
*/
|
|
2253
|
+
async requestDeleteMany(endpoint, data) {
|
|
2254
|
+
const url = this.buildUrl(endpoint, { where: data.where });
|
|
2255
|
+
const response = await this.fetchWithTracking(url, {
|
|
2256
|
+
...this.defaultOptions,
|
|
2257
|
+
method: "DELETE"
|
|
2258
|
+
});
|
|
2259
|
+
return this.parseFindResponse(response);
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Create document with file upload
|
|
2263
|
+
* POST /api/{collection} (multipart/form-data)
|
|
2264
|
+
*/
|
|
2265
|
+
async requestCreateWithFile(endpoint, data, file, filename) {
|
|
2266
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
2267
|
+
...this.defaultOptions,
|
|
2268
|
+
method: "POST",
|
|
2269
|
+
body: buildPayloadFormData(data, file, filename)
|
|
2270
|
+
});
|
|
2271
|
+
return this.parseMutationResponse(response);
|
|
2272
|
+
}
|
|
2273
|
+
/**
|
|
2274
|
+
* Update document with file upload
|
|
2275
|
+
* PATCH /api/{collection}/{id} (multipart/form-data)
|
|
2276
|
+
*/
|
|
2277
|
+
async requestUpdateWithFile(endpoint, data, file, filename) {
|
|
2278
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
2279
|
+
...this.defaultOptions,
|
|
2280
|
+
method: "PATCH",
|
|
2281
|
+
body: buildPayloadFormData(data, file, filename)
|
|
2282
|
+
});
|
|
2283
|
+
return this.parseMutationResponse(response);
|
|
2284
|
+
}
|
|
2285
|
+
};
|
|
2286
|
+
var ServerCollectionClient = class extends CollectionClient {
|
|
2287
|
+
from(collection) {
|
|
2288
|
+
return new ServerCollectionQueryBuilder(this, collection);
|
|
2090
2289
|
}
|
|
2091
2290
|
};
|
|
2092
2291
|
|
|
@@ -2497,81 +2696,6 @@ var CommunityClient = class extends RawCustomerScopedApi {
|
|
|
2497
2696
|
}
|
|
2498
2697
|
};
|
|
2499
2698
|
|
|
2500
|
-
// src/core/api/base-api.ts
|
|
2501
|
-
var ServerApiTransport = class {
|
|
2502
|
-
constructor(apiName, options) {
|
|
2503
|
-
if (!options.secretKey) {
|
|
2504
|
-
throw createConfigError(`secretKey is required for ${apiName}.`);
|
|
2505
|
-
}
|
|
2506
|
-
this.publishableKey = requirePublishableKeyForSecret(
|
|
2507
|
-
apiName,
|
|
2508
|
-
options.publishableKey,
|
|
2509
|
-
options.secretKey
|
|
2510
|
-
);
|
|
2511
|
-
this.secretKey = options.secretKey;
|
|
2512
|
-
this.apiUrl = options.apiUrl;
|
|
2513
|
-
this.onRequestId = options.onRequestId;
|
|
2514
|
-
}
|
|
2515
|
-
async request(endpoint, body, options) {
|
|
2516
|
-
const method = options?.method ?? "POST";
|
|
2517
|
-
try {
|
|
2518
|
-
const response = await httpFetch(endpoint, {
|
|
2519
|
-
method,
|
|
2520
|
-
apiUrl: this.apiUrl,
|
|
2521
|
-
publishableKey: this.publishableKey,
|
|
2522
|
-
secretKey: this.secretKey,
|
|
2523
|
-
...body !== void 0 && { body: JSON.stringify(body) },
|
|
2524
|
-
...options?.headers && { headers: options.headers },
|
|
2525
|
-
...options?.errorFamily && { errorFamily: options.errorFamily },
|
|
2526
|
-
...options?.typedCommerceErrorReasons && {
|
|
2527
|
-
typedCommerceErrorReasons: options.typedCommerceErrorReasons
|
|
2528
|
-
}
|
|
2529
|
-
});
|
|
2530
|
-
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
2531
|
-
return parseApiResponse(response, endpoint, {
|
|
2532
|
-
errorFamily: options?.errorFamily
|
|
2533
|
-
});
|
|
2534
|
-
} catch (err) {
|
|
2535
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
2536
|
-
this.onRequestId?.(id);
|
|
2537
|
-
throw err;
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
};
|
|
2541
|
-
var BaseApi = class {
|
|
2542
|
-
constructor(apiName, options) {
|
|
2543
|
-
this.transport = new ServerApiTransport(apiName, options);
|
|
2544
|
-
}
|
|
2545
|
-
requestEndpoint(endpoint, body, options) {
|
|
2546
|
-
return this.transport.request(
|
|
2547
|
-
resolveOperationPath(endpoint, options),
|
|
2548
|
-
body,
|
|
2549
|
-
{
|
|
2550
|
-
method: resolveOperationMethod(endpoint),
|
|
2551
|
-
headers: options?.headers,
|
|
2552
|
-
errorFamily: resolveOperationErrorFamily(endpoint),
|
|
2553
|
-
typedCommerceErrorReasons: resolveOperationTypedCommerceErrorReasons(endpoint)
|
|
2554
|
-
}
|
|
2555
|
-
);
|
|
2556
|
-
}
|
|
2557
|
-
};
|
|
2558
|
-
var RawBaseApi = class {
|
|
2559
|
-
constructor(apiName, options) {
|
|
2560
|
-
this.transport = new ServerApiTransport(apiName, options);
|
|
2561
|
-
this.publishableKey = requirePublishableKeyForSecret(
|
|
2562
|
-
apiName,
|
|
2563
|
-
options.publishableKey,
|
|
2564
|
-
options.secretKey
|
|
2565
|
-
);
|
|
2566
|
-
this.secretKey = options.secretKey;
|
|
2567
|
-
this.apiUrl = options.apiUrl;
|
|
2568
|
-
this.onRequestId = options.onRequestId;
|
|
2569
|
-
}
|
|
2570
|
-
request(endpoint, body, options) {
|
|
2571
|
-
return this.transport.request(endpoint, body, options);
|
|
2572
|
-
}
|
|
2573
|
-
};
|
|
2574
|
-
|
|
2575
2699
|
// src/core/community/moderation-api.ts
|
|
2576
2700
|
var ModerationApi = class extends RawBaseApi {
|
|
2577
2701
|
constructor(options) {
|
|
@@ -5423,10 +5547,68 @@ function normalizeProductUpsertParams(params) {
|
|
|
5423
5547
|
variants
|
|
5424
5548
|
};
|
|
5425
5549
|
}
|
|
5550
|
+
function assertPriceOperationObject(value, allowed) {
|
|
5551
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).some((key) => !allowed.includes(key))) {
|
|
5552
|
+
throw createValidationError(
|
|
5553
|
+
"Product price operations accept only their declared fields."
|
|
5554
|
+
);
|
|
5555
|
+
}
|
|
5556
|
+
}
|
|
5557
|
+
function productGraphQuery(params) {
|
|
5558
|
+
if (typeof params.productId !== "string" || !params.productId.trim() || params.locale !== void 0 && params.locale !== "ko" && params.locale !== "en") {
|
|
5559
|
+
throw createValidationError(
|
|
5560
|
+
"Provide a productId and, when specified, a ko or en content locale."
|
|
5561
|
+
);
|
|
5562
|
+
}
|
|
5563
|
+
return new URLSearchParams(
|
|
5564
|
+
params.locale ? { locale: params.locale } : void 0
|
|
5565
|
+
);
|
|
5566
|
+
}
|
|
5426
5567
|
var ProductApi = class extends BaseApi {
|
|
5427
5568
|
constructor(options) {
|
|
5428
5569
|
super("ProductApi", options);
|
|
5429
5570
|
}
|
|
5571
|
+
/** Read a baseline before reviewing values in the same content locale. */
|
|
5572
|
+
async graphRevision(params) {
|
|
5573
|
+
assertPriceOperationObject(params, ["productId", "locale"]);
|
|
5574
|
+
return this.requestEndpoint(
|
|
5575
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.graphRevision,
|
|
5576
|
+
void 0,
|
|
5577
|
+
{
|
|
5578
|
+
pathParams: { id: params.productId },
|
|
5579
|
+
query: productGraphQuery(params)
|
|
5580
|
+
}
|
|
5581
|
+
);
|
|
5582
|
+
}
|
|
5583
|
+
/** Update existing base prices only; conflicts never trigger a rebase or full upsert. */
|
|
5584
|
+
async updateVariantPrices(params) {
|
|
5585
|
+
assertPriceOperationObject(params, [
|
|
5586
|
+
"productId",
|
|
5587
|
+
"locale",
|
|
5588
|
+
"graphRevision",
|
|
5589
|
+
"updates"
|
|
5590
|
+
]);
|
|
5591
|
+
const query = productGraphQuery(params);
|
|
5592
|
+
if (typeof params.graphRevision !== "string" || !params.graphRevision.length || !Array.isArray(params.updates) || params.updates.length < 1 || params.updates.length > 250) {
|
|
5593
|
+
throw createValidationError(
|
|
5594
|
+
"Provide graphRevision and between 1 and 250 price updates."
|
|
5595
|
+
);
|
|
5596
|
+
}
|
|
5597
|
+
const updates = params.updates.map((row) => {
|
|
5598
|
+
assertPriceOperationObject(row, ["id", "price"]);
|
|
5599
|
+
if (typeof row.id !== "string" || !row.id.trim() || typeof row.price !== "number" || !Number.isFinite(row.price)) {
|
|
5600
|
+
throw createValidationError(
|
|
5601
|
+
"Each price update requires an existing variant id and numeric price."
|
|
5602
|
+
);
|
|
5603
|
+
}
|
|
5604
|
+
return { id: row.id, price: row.price };
|
|
5605
|
+
});
|
|
5606
|
+
return this.requestEndpoint(
|
|
5607
|
+
COMMERCE_ENDPOINT_OPERATIONS.products.variantsPatch,
|
|
5608
|
+
{ graphRevision: params.graphRevision, updates },
|
|
5609
|
+
{ pathParams: { id: params.productId }, query }
|
|
5610
|
+
);
|
|
5611
|
+
}
|
|
5430
5612
|
/**
|
|
5431
5613
|
* Check point-in-time stock availability for one or more product variants.
|
|
5432
5614
|
* Results reflect available stock at the moment of the call and are not guaranteed
|
|
@@ -5988,7 +6170,9 @@ var ServerCommerceClient = class {
|
|
|
5988
6170
|
detail: (params) => productApi.detail(this.withMarket(params)),
|
|
5989
6171
|
detailCatalog: (params) => productApi.detailCatalog(this.withMarket(params)),
|
|
5990
6172
|
previewDetail: productApi.previewDetail.bind(productApi),
|
|
5991
|
-
upsert: productApi.upsert.bind(productApi)
|
|
6173
|
+
upsert: productApi.upsert.bind(productApi),
|
|
6174
|
+
graphRevision: productApi.graphRevision.bind(productApi),
|
|
6175
|
+
updateVariantPrices: productApi.updateVariantPrices.bind(productApi)
|
|
5992
6176
|
};
|
|
5993
6177
|
this.carts = {
|
|
5994
6178
|
create: (params) => cartApi.create(this.withMarket(params ?? {})),
|
|
@@ -6089,6 +6273,18 @@ var EventsClient = class {
|
|
|
6089
6273
|
{ useCustomerAuth: false }
|
|
6090
6274
|
);
|
|
6091
6275
|
}
|
|
6276
|
+
listMyRegistrations(params = {}) {
|
|
6277
|
+
const query = new URLSearchParams();
|
|
6278
|
+
if (params.page !== void 0) query.set("page", String(params.page));
|
|
6279
|
+
if (params.limit !== void 0) query.set("limit", String(params.limit));
|
|
6280
|
+
const operation2 = EVENTS_ENDPOINT_OPERATIONS.registrations.listMine;
|
|
6281
|
+
return this.execute(
|
|
6282
|
+
resolveOperationPath(operation2, { query }),
|
|
6283
|
+
resolveOperationMethod(operation2),
|
|
6284
|
+
void 0,
|
|
6285
|
+
{ useCustomerAuth: true, noStore: true }
|
|
6286
|
+
);
|
|
6287
|
+
}
|
|
6092
6288
|
register(params) {
|
|
6093
6289
|
return this.execute(
|
|
6094
6290
|
"/api/event-registrations/register",
|
|
@@ -6119,6 +6315,7 @@ var EventsClient = class {
|
|
|
6119
6315
|
try {
|
|
6120
6316
|
const response = await httpFetch(endpoint, {
|
|
6121
6317
|
method,
|
|
6318
|
+
...options.noStore && { cache: "no-store" },
|
|
6122
6319
|
apiUrl: this.apiUrl,
|
|
6123
6320
|
publishableKey: this.publishableKey,
|
|
6124
6321
|
...useCustomerAuth && token ? { customerToken: token } : {},
|
|
@@ -6579,8 +6776,8 @@ var InstallationCredentialsApi = class extends BaseApi {
|
|
|
6579
6776
|
function invalidResponse3() {
|
|
6580
6777
|
throw createApiError("Invalid external-customer link response", 200);
|
|
6581
6778
|
}
|
|
6582
|
-
var
|
|
6583
|
-
var isUuid = (value) => typeof value === "string" && (
|
|
6779
|
+
var uuid2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
6780
|
+
var isUuid = (value) => typeof value === "string" && (uuid2.test(value) || value === "00000000-0000-0000-0000-000000000000" || value.toLowerCase() === "ffffffff-ffff-ffff-ffff-ffffffffffff");
|
|
6584
6781
|
var isIdentity = (value) => typeof value === "string" && value.length > 0 && value.length <= 256 && value === value.trim() && // eslint-disable-next-line no-control-regex -- Normalized identity forbids C0 controls.
|
|
6585
6782
|
!/[\u0000-\u001f]/.test(value) && !/[\uD800-\uDFFF]/u.test(value);
|
|
6586
6783
|
var isDateTime = (value) => {
|
|
@@ -6727,6 +6924,7 @@ var ServerClient = class _ServerClient {
|
|
|
6727
6924
|
this.customerGroups = new CustomerGroupApi(serverOptions);
|
|
6728
6925
|
this.externalEffectClaims = new ExternalEffectClaimsApi(serverOptions);
|
|
6729
6926
|
this.installationCredentials = new InstallationCredentialsApi(serverOptions);
|
|
6927
|
+
this.benefitVouchers = new BenefitVouchersApi(serverOptions);
|
|
6730
6928
|
this.externalCustomerLinks = new ExternalCustomerLinksApi(serverOptions);
|
|
6731
6929
|
const tenantIntrospectionApi = new TenantIntrospectionApi(serverOptions);
|
|
6732
6930
|
this.tenant = {
|
|
@@ -6769,13 +6967,20 @@ var ServerClient = class _ServerClient {
|
|
|
6769
6967
|
"publishableKey is required for server.events. It is sent as X-Publishable-Key for rate limiting and quota enforcement. Get it from Console > Settings > API Keys."
|
|
6770
6968
|
);
|
|
6771
6969
|
}
|
|
6772
|
-
|
|
6970
|
+
const events = new EventsClient({
|
|
6773
6971
|
publishableKey: this.config.publishableKey,
|
|
6774
6972
|
apiUrl: this.config.apiUrl,
|
|
6775
6973
|
onRequestId: (id) => {
|
|
6776
6974
|
this.lastRequestId = id;
|
|
6777
6975
|
}
|
|
6778
6976
|
});
|
|
6977
|
+
this._events = {
|
|
6978
|
+
getRange: events.getRange.bind(events),
|
|
6979
|
+
getAdmissionAvailability: events.getAdmissionAvailability.bind(events),
|
|
6980
|
+
register: events.register.bind(events),
|
|
6981
|
+
getGuestRegistration: events.getGuestRegistration.bind(events),
|
|
6982
|
+
cancelGuestRegistration: events.cancelGuestRegistration.bind(events)
|
|
6983
|
+
};
|
|
6779
6984
|
}
|
|
6780
6985
|
return this._events;
|
|
6781
6986
|
}
|