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