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