@01.software/sdk 0.65.1 → 0.68.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +81 -0
- package/README.md +201 -8
- package/dist/client.cjs +490 -338
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +11 -6
- package/dist/client.d.ts +11 -6
- package/dist/client.js +490 -338
- package/dist/client.js.map +1 -1
- package/dist/{collection-client-C2sMvfme.d.ts → collection-client-IOaWsTMI.d.ts} +4 -4
- package/dist/{collection-client-B7rsTtVj.d.cts → collection-client-MbIJ5KzW.d.cts} +4 -4
- package/dist/{const-CRxPTDGt.d.ts → const-Do27Udj6.d.ts} +2 -2
- package/dist/{const-D6ZRQLxI.d.cts → const-Dw5ElJs_.d.cts} +2 -2
- package/dist/embedded-admin/server.cjs +16 -1
- package/dist/embedded-admin/server.cjs.map +1 -1
- package/dist/embedded-admin/server.d.cts +4 -2
- package/dist/embedded-admin/server.d.ts +4 -2
- package/dist/embedded-admin/server.js +16 -1
- package/dist/embedded-admin/server.js.map +1 -1
- package/dist/embedded-admin.cjs +19 -0
- package/dist/embedded-admin.cjs.map +1 -1
- package/dist/embedded-admin.d.cts +7 -1
- package/dist/embedded-admin.d.ts +7 -1
- package/dist/embedded-admin.js +19 -0
- package/dist/embedded-admin.js.map +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/errors.d.ts +2 -2
- package/dist/{index-1auUEYrl.d.ts → index-DcYsLOja.d.ts} +3 -3
- package/dist/{index-Bbpf5t-l.d.cts → index-gnVxTKXu.d.cts} +3 -3
- package/dist/index.cjs +521 -367
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +521 -367
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-BnIET0xU.d.cts → payload-types-BY1uZFRf.d.cts} +162 -50
- package/dist/{payload-types-BnIET0xU.d.ts → payload-types-BY1uZFRf.d.ts} +162 -50
- package/dist/query.cjs +22 -1
- package/dist/query.cjs.map +1 -1
- package/dist/query.d.cts +5 -5
- package/dist/query.d.ts +5 -5
- package/dist/query.js +22 -1
- package/dist/query.js.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/server.cjs +1251 -1046
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +10 -9
- package/dist/server.d.ts +10 -9
- package/dist/server.js +1251 -1046
- package/dist/server.js.map +1 -1
- package/dist/{types-D1y4TgQm.d.ts → types-AWSVpuPE.d.ts} +2 -2
- package/dist/{types-DnRC3nLG.d.ts → types-CLRw0aDa.d.ts} +214 -42
- package/dist/{types-Dp1oYpD3.d.cts → types-DnIuxgu2.d.cts} +2 -2
- package/dist/{types-Dzn0LD2N.d.cts → types-csjaig4G.d.cts} +214 -42
- package/dist/ui/canvas.cjs +5 -1
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.js +5 -1
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.cjs +9 -2
- package/dist/ui/video.cjs.map +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/ui/video.js +9 -2
- package/dist/ui/video.js.map +1 -1
- package/dist/webhook.d.cts +5 -5
- package/dist/webhook.d.ts +5 -5
- package/package.json +4 -4
package/dist/client.cjs
CHANGED
|
@@ -41,9 +41,6 @@ __export(client_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(client_exports);
|
|
43
43
|
|
|
44
|
-
// src/core/collection/http-client.ts
|
|
45
|
-
var import_qs_esm = require("qs-esm");
|
|
46
|
-
|
|
47
44
|
// src/core/errors.ts
|
|
48
45
|
var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
|
|
49
46
|
var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
|
|
@@ -1047,281 +1044,6 @@ function stockSnapshotSearchParams(params) {
|
|
|
1047
1044
|
return `variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
|
|
1048
1045
|
}
|
|
1049
1046
|
|
|
1050
|
-
// src/core/collection/http-client.ts
|
|
1051
|
-
function validateWhere(where) {
|
|
1052
|
-
if (where === void 0) return false;
|
|
1053
|
-
let hasNull = false;
|
|
1054
|
-
function visit(value, depth, key) {
|
|
1055
|
-
if (depth > 10) {
|
|
1056
|
-
throw createValidationError(
|
|
1057
|
-
"Collection where must not exceed nesting depth 10."
|
|
1058
|
-
);
|
|
1059
|
-
}
|
|
1060
|
-
if (value === null && (key === "equals" || key === "not_equals")) {
|
|
1061
|
-
hasNull = true;
|
|
1062
|
-
return;
|
|
1063
|
-
}
|
|
1064
|
-
if (value == null) {
|
|
1065
|
-
throw createValidationError(
|
|
1066
|
-
"Collection where must not contain null or undefined values."
|
|
1067
|
-
);
|
|
1068
|
-
}
|
|
1069
|
-
if (Array.isArray(value)) {
|
|
1070
|
-
if (value.length === 0) {
|
|
1071
|
-
throw createValidationError(
|
|
1072
|
-
"Collection where must not contain empty arrays, including and/or."
|
|
1073
|
-
);
|
|
1074
|
-
}
|
|
1075
|
-
if (value.length > 1e3) {
|
|
1076
|
-
throw createValidationError(
|
|
1077
|
-
"Collection where arrays must not contain more than 1000 elements."
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
for (const item of value) visit(item, depth + 1);
|
|
1081
|
-
} else if (typeof value === "object" && !(value instanceof Date)) {
|
|
1082
|
-
const values = Object.entries(value);
|
|
1083
|
-
if (values.length === 0) {
|
|
1084
|
-
throw createValidationError(
|
|
1085
|
-
"Collection where must not contain empty condition objects."
|
|
1086
|
-
);
|
|
1087
|
-
}
|
|
1088
|
-
for (const [key2, item] of values) visit(item, depth + 1, key2);
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
visit(where, 0);
|
|
1092
|
-
return hasNull;
|
|
1093
|
-
}
|
|
1094
|
-
var HttpClient = class {
|
|
1095
|
-
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
1096
|
-
this.publishableKey = requirePublishableKeyForSecret(
|
|
1097
|
-
"CollectionClient",
|
|
1098
|
-
publishableKey,
|
|
1099
|
-
secretKey
|
|
1100
|
-
);
|
|
1101
|
-
this.secretKey = secretKey;
|
|
1102
|
-
this.getCustomerToken = getCustomerToken;
|
|
1103
|
-
this.onUnauthorized = onUnauthorized;
|
|
1104
|
-
this.onRequestId = onRequestId;
|
|
1105
|
-
this.apiUrl = apiUrl;
|
|
1106
|
-
}
|
|
1107
|
-
get defaultOptions() {
|
|
1108
|
-
const opts = {
|
|
1109
|
-
apiUrl: this.apiUrl,
|
|
1110
|
-
publishableKey: this.publishableKey,
|
|
1111
|
-
secretKey: this.secretKey
|
|
1112
|
-
};
|
|
1113
|
-
const token = this.getCustomerToken?.();
|
|
1114
|
-
if (token) {
|
|
1115
|
-
opts.customerToken = token;
|
|
1116
|
-
if (this.onUnauthorized) {
|
|
1117
|
-
opts.onUnauthorized = this.onUnauthorized;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
return opts;
|
|
1121
|
-
}
|
|
1122
|
-
async fetchWithTracking(url, opts) {
|
|
1123
|
-
try {
|
|
1124
|
-
const response = await httpFetch(url, opts);
|
|
1125
|
-
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1126
|
-
return response;
|
|
1127
|
-
} catch (err) {
|
|
1128
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1129
|
-
this.onRequestId?.(id);
|
|
1130
|
-
throw err;
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
buildUrl(endpoint, options) {
|
|
1134
|
-
if (!options) return endpoint;
|
|
1135
|
-
const { fallbackLocale, ...rest } = options;
|
|
1136
|
-
const queryOptions = fallbackLocale === void 0 ? rest : {
|
|
1137
|
-
...rest,
|
|
1138
|
-
"fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
|
|
1139
|
-
};
|
|
1140
|
-
const encodedOptions = validateWhere(queryOptions.where) ? { ...queryOptions, where: JSON.stringify(queryOptions.where) } : queryOptions;
|
|
1141
|
-
const queryString = (0, import_qs_esm.stringify)(encodedOptions, { addQueryPrefix: true });
|
|
1142
|
-
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
1143
|
-
}
|
|
1144
|
-
assertJsonResponse(response) {
|
|
1145
|
-
const contentType = response.headers.get("content-type");
|
|
1146
|
-
if (!contentType?.includes("application/json")) {
|
|
1147
|
-
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1148
|
-
contentType
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* Parse Payload CMS find response (list query)
|
|
1154
|
-
* Returns native Payload response structure
|
|
1155
|
-
*/
|
|
1156
|
-
async parseFindResponse(response) {
|
|
1157
|
-
const contentType = response.headers.get("content-type");
|
|
1158
|
-
try {
|
|
1159
|
-
this.assertJsonResponse(response);
|
|
1160
|
-
const jsonData = await response.json();
|
|
1161
|
-
if (jsonData.docs === void 0) {
|
|
1162
|
-
throw createApiError("Invalid find response.", response.status, {
|
|
1163
|
-
jsonData
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
return {
|
|
1167
|
-
docs: jsonData.docs,
|
|
1168
|
-
totalDocs: jsonData.totalDocs ?? 0,
|
|
1169
|
-
limit: jsonData.limit || 20,
|
|
1170
|
-
totalPages: jsonData.totalPages ?? 0,
|
|
1171
|
-
page: jsonData.page || 1,
|
|
1172
|
-
pagingCounter: jsonData.pagingCounter || 1,
|
|
1173
|
-
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
1174
|
-
hasNextPage: jsonData.hasNextPage ?? false,
|
|
1175
|
-
prevPage: jsonData.prevPage ?? null,
|
|
1176
|
-
nextPage: jsonData.nextPage ?? null
|
|
1177
|
-
};
|
|
1178
|
-
} catch (error) {
|
|
1179
|
-
if (error instanceof SDKError) throw error;
|
|
1180
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1181
|
-
contentType,
|
|
1182
|
-
error: error instanceof Error ? error.message : error
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* Parse Payload CMS mutation response (create/update)
|
|
1188
|
-
* Returns native Payload response structure
|
|
1189
|
-
*/
|
|
1190
|
-
async parseMutationResponse(response) {
|
|
1191
|
-
const contentType = response.headers.get("content-type");
|
|
1192
|
-
try {
|
|
1193
|
-
this.assertJsonResponse(response);
|
|
1194
|
-
const jsonData = await response.json();
|
|
1195
|
-
if (jsonData.doc === void 0) {
|
|
1196
|
-
throw createApiError("Invalid mutation response.", response.status, {
|
|
1197
|
-
jsonData
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
return {
|
|
1201
|
-
message: jsonData.message || "",
|
|
1202
|
-
doc: jsonData.doc,
|
|
1203
|
-
errors: jsonData.errors
|
|
1204
|
-
};
|
|
1205
|
-
} catch (error) {
|
|
1206
|
-
if (error instanceof SDKError) throw error;
|
|
1207
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1208
|
-
contentType,
|
|
1209
|
-
error: error instanceof Error ? error.message : error
|
|
1210
|
-
});
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* Parse Payload CMS document response (findById/delete)
|
|
1215
|
-
* Returns document directly without wrapper
|
|
1216
|
-
*/
|
|
1217
|
-
async parseDocumentResponse(response) {
|
|
1218
|
-
const contentType = response.headers.get("content-type");
|
|
1219
|
-
try {
|
|
1220
|
-
this.assertJsonResponse(response);
|
|
1221
|
-
const jsonData = await response.json();
|
|
1222
|
-
return jsonData;
|
|
1223
|
-
} catch (error) {
|
|
1224
|
-
if (error instanceof SDKError) throw error;
|
|
1225
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1226
|
-
contentType,
|
|
1227
|
-
error: error instanceof Error ? error.message : error
|
|
1228
|
-
});
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
};
|
|
1232
|
-
|
|
1233
|
-
// src/core/collection/query-builder.ts
|
|
1234
|
-
var PUBLIC_READ_DEPTH_ERROR = "Publishable collection reads require depth: 0. Use a shaped commerce endpoint or server client for populated data.";
|
|
1235
|
-
var PUBLIC_READ_JOINS_ERROR = "Publishable collection reads require joins: false. Use a shaped commerce endpoint or server client for joined data.";
|
|
1236
|
-
var PUBLIC_READ_POPULATE_ERROR = "Publishable collection reads do not support populate. Use a shaped commerce endpoint or server client for populated data.";
|
|
1237
|
-
function withDefaultPublicReadOptions(options) {
|
|
1238
|
-
const rawOptions = options;
|
|
1239
|
-
if (rawOptions?.depth !== void 0 && rawOptions.depth !== 0) {
|
|
1240
|
-
throw createValidationError(PUBLIC_READ_DEPTH_ERROR);
|
|
1241
|
-
}
|
|
1242
|
-
if (rawOptions?.joins !== void 0 && rawOptions.joins !== false) {
|
|
1243
|
-
throw createValidationError(PUBLIC_READ_JOINS_ERROR);
|
|
1244
|
-
}
|
|
1245
|
-
if (rawOptions?.populate !== void 0) {
|
|
1246
|
-
throw createValidationError(PUBLIC_READ_POPULATE_ERROR);
|
|
1247
|
-
}
|
|
1248
|
-
return {
|
|
1249
|
-
...options,
|
|
1250
|
-
depth: options?.depth ?? 0,
|
|
1251
|
-
joins: options?.joins ?? false
|
|
1252
|
-
};
|
|
1253
|
-
}
|
|
1254
|
-
var ReadOnlyCollectionQueryBuilder = class {
|
|
1255
|
-
constructor(api, collection) {
|
|
1256
|
-
this.api = api;
|
|
1257
|
-
this.collection = collection;
|
|
1258
|
-
}
|
|
1259
|
-
async find(options) {
|
|
1260
|
-
return this.api.requestFind(
|
|
1261
|
-
`/api/${String(this.collection)}`,
|
|
1262
|
-
withDefaultPublicReadOptions(options)
|
|
1263
|
-
);
|
|
1264
|
-
}
|
|
1265
|
-
async findById(id, options) {
|
|
1266
|
-
return this.api.requestFindById(
|
|
1267
|
-
`/api/${String(this.collection)}/${String(id)}`,
|
|
1268
|
-
withDefaultPublicReadOptions(options)
|
|
1269
|
-
);
|
|
1270
|
-
}
|
|
1271
|
-
async count(options) {
|
|
1272
|
-
return this.api.requestCount(
|
|
1273
|
-
`/api/${String(this.collection)}/count`,
|
|
1274
|
-
withDefaultPublicReadOptions(options)
|
|
1275
|
-
);
|
|
1276
|
-
}
|
|
1277
|
-
};
|
|
1278
|
-
|
|
1279
|
-
// src/core/collection/collection-client.ts
|
|
1280
|
-
var ReadOnlyCollectionClient = class extends HttpClient {
|
|
1281
|
-
from(collection) {
|
|
1282
|
-
return new ReadOnlyCollectionQueryBuilder(this, collection);
|
|
1283
|
-
}
|
|
1284
|
-
async requestFind(endpoint, options) {
|
|
1285
|
-
const url = this.buildUrl(endpoint, options);
|
|
1286
|
-
const response = await this.fetchWithTracking(url, {
|
|
1287
|
-
...this.defaultOptions,
|
|
1288
|
-
method: "GET"
|
|
1289
|
-
});
|
|
1290
|
-
return this.parseFindResponse(response);
|
|
1291
|
-
}
|
|
1292
|
-
async requestFindEndpoint(endpoint, data) {
|
|
1293
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1294
|
-
...this.defaultOptions,
|
|
1295
|
-
method: "POST",
|
|
1296
|
-
body: data ? JSON.stringify(data) : void 0
|
|
1297
|
-
});
|
|
1298
|
-
return this.parseFindResponse(response);
|
|
1299
|
-
}
|
|
1300
|
-
async requestFindEndpointGet(endpoint) {
|
|
1301
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1302
|
-
...this.defaultOptions,
|
|
1303
|
-
method: "GET"
|
|
1304
|
-
});
|
|
1305
|
-
return this.parseFindResponse(response);
|
|
1306
|
-
}
|
|
1307
|
-
async requestFindById(endpoint, options) {
|
|
1308
|
-
const url = this.buildUrl(endpoint, options);
|
|
1309
|
-
const response = await this.fetchWithTracking(url, {
|
|
1310
|
-
...this.defaultOptions,
|
|
1311
|
-
method: "GET"
|
|
1312
|
-
});
|
|
1313
|
-
return this.parseDocumentResponse(response);
|
|
1314
|
-
}
|
|
1315
|
-
async requestCount(endpoint, options) {
|
|
1316
|
-
const url = this.buildUrl(endpoint, options);
|
|
1317
|
-
const response = await this.fetchWithTracking(url, {
|
|
1318
|
-
...this.defaultOptions,
|
|
1319
|
-
method: "GET"
|
|
1320
|
-
});
|
|
1321
|
-
return this.parseDocumentResponse(response);
|
|
1322
|
-
}
|
|
1323
|
-
};
|
|
1324
|
-
|
|
1325
1047
|
// src/core/api/parse-response.ts
|
|
1326
1048
|
async function parseApiResponse(response, endpoint, options = {}) {
|
|
1327
1049
|
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
@@ -1418,7 +1140,9 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1418
1140
|
),
|
|
1419
1141
|
stockCheck: operation("products", "post", "/stock-check"),
|
|
1420
1142
|
stockSnapshot: operation("products", "get", "/stock"),
|
|
1421
|
-
upsert: operation("products", "post", "/upsert")
|
|
1143
|
+
upsert: operation("products", "post", "/upsert"),
|
|
1144
|
+
graphRevision: operation("products", "get", "/:id/graph-revision"),
|
|
1145
|
+
variantsPatch: operation("products", "patch", "/:id/variants")
|
|
1422
1146
|
},
|
|
1423
1147
|
orders: {
|
|
1424
1148
|
create: operation("orders", "post", "/create"),
|
|
@@ -1581,12 +1305,28 @@ var EXTERNAL_CUSTOMER_LINK_ENDPOINT_OPERATIONS = {
|
|
|
1581
1305
|
"/external-links/clear-previous-state"
|
|
1582
1306
|
)
|
|
1583
1307
|
};
|
|
1308
|
+
var BENEFIT_VOUCHER_ENDPOINT_OPERATIONS = {
|
|
1309
|
+
issue: operation("customers", "post", "/benefit-vouchers/issue"),
|
|
1310
|
+
get: operation("customers", "post", "/benefit-vouchers/get"),
|
|
1311
|
+
list: operation("customers", "post", "/benefit-vouchers/list"),
|
|
1312
|
+
redeem: operation("customers", "post", "/benefit-vouchers/redeem"),
|
|
1313
|
+
void: operation("customers", "post", "/benefit-vouchers/void"),
|
|
1314
|
+
listMine: operation("customers", "get", "/me/benefit-vouchers")
|
|
1315
|
+
};
|
|
1584
1316
|
var CUSTOMER_GROUP_ENDPOINT_OPERATIONS = {
|
|
1585
1317
|
members: operation("customer-groups", "get", "/:id/members"),
|
|
1586
1318
|
grant: operation("customer-groups", "post", "/:id/members/grant"),
|
|
1587
1319
|
revoke: operation("customer-groups", "post", "/:id/members/revoke")
|
|
1588
1320
|
};
|
|
1589
1321
|
var CUSTOMER_AUTH_ENDPOINT_OPERATIONS = {
|
|
1322
|
+
register: operation("customers", "post", "/register"),
|
|
1323
|
+
login: operation("customers", "post", "/login"),
|
|
1324
|
+
refresh: operation("customers", "post", "/refresh"),
|
|
1325
|
+
me: operation("customers", "get", "/me"),
|
|
1326
|
+
updateProfile: operation("customers", "patch", "/me"),
|
|
1327
|
+
forgotPassword: operation("customers", "post", "/forgot-password"),
|
|
1328
|
+
resetPassword: operation("customers", "post", "/reset-password"),
|
|
1329
|
+
changePassword: operation("customers", "post", "/change-password"),
|
|
1590
1330
|
revokeRefresh: operation("customers", "post", "/revoke-refresh"),
|
|
1591
1331
|
withdraw: operation("customers", "post", "/withdraw")
|
|
1592
1332
|
};
|
|
@@ -1596,6 +1336,9 @@ var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
|
|
|
1596
1336
|
disable: operation("tenants", "delete", "/embedded-admin-app")
|
|
1597
1337
|
};
|
|
1598
1338
|
var EVENTS_ENDPOINT_OPERATIONS = {
|
|
1339
|
+
registrations: {
|
|
1340
|
+
listMine: operation("event-registrations", "get", "/my")
|
|
1341
|
+
},
|
|
1599
1342
|
events: {
|
|
1600
1343
|
convertSchedule: operation("events", "post", "/:id/schedule")
|
|
1601
1344
|
},
|
|
@@ -1817,52 +1560,412 @@ var CustomerScopedTransport = class {
|
|
|
1817
1560
|
this.onUnauthorized = options.onUnauthorized;
|
|
1818
1561
|
this.onRequestId = options.onRequestId;
|
|
1819
1562
|
}
|
|
1820
|
-
async request(endpoint, options) {
|
|
1821
|
-
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1563
|
+
async request(endpoint, options) {
|
|
1564
|
+
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1565
|
+
try {
|
|
1566
|
+
const response = await httpFetch(endpoint, {
|
|
1567
|
+
method: options.method,
|
|
1568
|
+
apiUrl: this.apiUrl,
|
|
1569
|
+
publishableKey: this.publishableKey,
|
|
1570
|
+
secretKey: this.secretKey,
|
|
1571
|
+
customerToken: token ?? void 0,
|
|
1572
|
+
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1573
|
+
...options.body !== void 0 && {
|
|
1574
|
+
body: JSON.stringify(options.body)
|
|
1575
|
+
},
|
|
1576
|
+
...options.headers && { headers: options.headers },
|
|
1577
|
+
...options.errorFamily && { errorFamily: options.errorFamily }
|
|
1578
|
+
});
|
|
1579
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1580
|
+
return parseApiResponse(response, endpoint, {
|
|
1581
|
+
errorFamily: options.errorFamily
|
|
1582
|
+
});
|
|
1583
|
+
} catch (err) {
|
|
1584
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1585
|
+
this.onRequestId?.(id);
|
|
1586
|
+
throw err;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
var CustomerScopedApi = class {
|
|
1591
|
+
constructor(apiName, options) {
|
|
1592
|
+
this.transport = new CustomerScopedTransport(apiName, options);
|
|
1593
|
+
}
|
|
1594
|
+
requestEndpoint(endpoint, body, options) {
|
|
1595
|
+
return this.transport.request(resolveOperationPath(endpoint, options), {
|
|
1596
|
+
method: resolveOperationMethod(endpoint),
|
|
1597
|
+
body,
|
|
1598
|
+
headers: options?.headers,
|
|
1599
|
+
errorFamily: resolveOperationErrorFamily(endpoint)
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
var RawCustomerScopedApi = class {
|
|
1604
|
+
constructor(apiName, options) {
|
|
1605
|
+
this.transport = new CustomerScopedTransport(apiName, options);
|
|
1606
|
+
}
|
|
1607
|
+
request(endpoint, options) {
|
|
1608
|
+
return this.transport.request(endpoint, options);
|
|
1609
|
+
}
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
// src/core/api/benefit-voucher-types.ts
|
|
1613
|
+
var BENEFIT_VOUCHER_VOID_REASONS = [
|
|
1614
|
+
"issued_in_error",
|
|
1615
|
+
"benefit_revoked",
|
|
1616
|
+
"customer_request",
|
|
1617
|
+
"other"
|
|
1618
|
+
];
|
|
1619
|
+
function invalidBenefitVoucherResponse() {
|
|
1620
|
+
throw createApiError("Invalid benefit voucher response", 200);
|
|
1621
|
+
}
|
|
1622
|
+
function object(value, keys) {
|
|
1623
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length !== keys.length || keys.some((key) => !(key in value)))
|
|
1624
|
+
invalidBenefitVoucherResponse();
|
|
1625
|
+
return value;
|
|
1626
|
+
}
|
|
1627
|
+
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(
|
|
1628
|
+
v
|
|
1629
|
+
) || v === "00000000-0000-0000-0000-000000000000" || v.toLowerCase() === "ffffffff-ffff-ffff-ffff-ffffffffffff");
|
|
1630
|
+
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;
|
|
1631
|
+
var actor = (v) => typeof v === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(v);
|
|
1632
|
+
function parseBenefitVoucher(value, mine = false) {
|
|
1633
|
+
const v = object(value, [
|
|
1634
|
+
"id",
|
|
1635
|
+
"name",
|
|
1636
|
+
"description",
|
|
1637
|
+
"state",
|
|
1638
|
+
"issuedAt",
|
|
1639
|
+
"expiresAt",
|
|
1640
|
+
...mine ? ["closedAt"] : ["customerId", "definitionId", "source", "closed"]
|
|
1641
|
+
]);
|
|
1642
|
+
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))
|
|
1643
|
+
invalidBenefitVoucherResponse();
|
|
1644
|
+
if (mine) {
|
|
1645
|
+
if (v.closedAt !== null && !time(v.closedAt))
|
|
1646
|
+
invalidBenefitVoucherResponse();
|
|
1647
|
+
} else {
|
|
1648
|
+
if (!uuid(v.customerId) || !uuid(v.definitionId))
|
|
1649
|
+
invalidBenefitVoucherResponse();
|
|
1650
|
+
const source = object(v.source, ["namespace", "ref"]);
|
|
1651
|
+
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)
|
|
1652
|
+
invalidBenefitVoucherResponse();
|
|
1653
|
+
if (v.closed !== null) {
|
|
1654
|
+
const closed = object(v.closed, [
|
|
1655
|
+
"at",
|
|
1656
|
+
"channel",
|
|
1657
|
+
"actor",
|
|
1658
|
+
"actorRef",
|
|
1659
|
+
"voidReason"
|
|
1660
|
+
]);
|
|
1661
|
+
const principal = object(closed.actor, ["type", "id"]);
|
|
1662
|
+
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))
|
|
1663
|
+
invalidBenefitVoucherResponse();
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
return value;
|
|
1667
|
+
}
|
|
1668
|
+
function parseBenefitVoucherList(value, mine = false) {
|
|
1669
|
+
const v = object(value, ["vouchers", "nextCursor", "evaluatedAt"]);
|
|
1670
|
+
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))
|
|
1671
|
+
invalidBenefitVoucherResponse();
|
|
1672
|
+
for (const row of v.vouchers) {
|
|
1673
|
+
if (mine) parseBenefitVoucher(row, true);
|
|
1674
|
+
else parseBenefitVoucher(row);
|
|
1675
|
+
}
|
|
1676
|
+
return value;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
// src/core/api/customer-benefit-vouchers-api.ts
|
|
1680
|
+
var CustomerBenefitVouchersApi = class extends CustomerScopedApi {
|
|
1681
|
+
async listMine(params = {}) {
|
|
1682
|
+
const query = new URLSearchParams();
|
|
1683
|
+
for (const [key, value] of Object.entries(params))
|
|
1684
|
+
if (value !== void 0) query.set(key, String(value));
|
|
1685
|
+
return parseBenefitVoucherList(
|
|
1686
|
+
await this.requestEndpoint(
|
|
1687
|
+
BENEFIT_VOUCHER_ENDPOINT_OPERATIONS.listMine,
|
|
1688
|
+
void 0,
|
|
1689
|
+
{ query }
|
|
1690
|
+
),
|
|
1691
|
+
true
|
|
1692
|
+
);
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
// src/core/collection/http-client.ts
|
|
1697
|
+
var import_qs_esm = require("qs-esm");
|
|
1698
|
+
function validateWhere(where) {
|
|
1699
|
+
if (where === void 0) return false;
|
|
1700
|
+
let hasNull = false;
|
|
1701
|
+
function visit(value, depth, key) {
|
|
1702
|
+
if (depth > 10) {
|
|
1703
|
+
throw createValidationError(
|
|
1704
|
+
"Collection where must not exceed nesting depth 10."
|
|
1705
|
+
);
|
|
1706
|
+
}
|
|
1707
|
+
if (value === null && (key === "equals" || key === "not_equals")) {
|
|
1708
|
+
hasNull = true;
|
|
1709
|
+
return;
|
|
1710
|
+
}
|
|
1711
|
+
if (value == null) {
|
|
1712
|
+
throw createValidationError(
|
|
1713
|
+
"Collection where must not contain null or undefined values."
|
|
1714
|
+
);
|
|
1715
|
+
}
|
|
1716
|
+
if (Array.isArray(value)) {
|
|
1717
|
+
if (value.length === 0) {
|
|
1718
|
+
throw createValidationError(
|
|
1719
|
+
"Collection where must not contain empty arrays, including and/or."
|
|
1720
|
+
);
|
|
1721
|
+
}
|
|
1722
|
+
if (value.length > 1e3) {
|
|
1723
|
+
throw createValidationError(
|
|
1724
|
+
"Collection where arrays must not contain more than 1000 elements."
|
|
1725
|
+
);
|
|
1726
|
+
}
|
|
1727
|
+
for (const item of value) visit(item, depth + 1);
|
|
1728
|
+
} else if (typeof value === "object" && !(value instanceof Date)) {
|
|
1729
|
+
const values = Object.entries(value);
|
|
1730
|
+
if (values.length === 0) {
|
|
1731
|
+
throw createValidationError(
|
|
1732
|
+
"Collection where must not contain empty condition objects."
|
|
1733
|
+
);
|
|
1734
|
+
}
|
|
1735
|
+
for (const [key2, item] of values) visit(item, depth + 1, key2);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
visit(where, 0);
|
|
1739
|
+
return hasNull;
|
|
1740
|
+
}
|
|
1741
|
+
var HttpClient = class {
|
|
1742
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
1743
|
+
this.publishableKey = requirePublishableKeyForSecret(
|
|
1744
|
+
"CollectionClient",
|
|
1745
|
+
publishableKey,
|
|
1746
|
+
secretKey
|
|
1747
|
+
);
|
|
1748
|
+
this.secretKey = secretKey;
|
|
1749
|
+
this.getCustomerToken = getCustomerToken;
|
|
1750
|
+
this.onUnauthorized = onUnauthorized;
|
|
1751
|
+
this.onRequestId = onRequestId;
|
|
1752
|
+
this.apiUrl = apiUrl;
|
|
1753
|
+
}
|
|
1754
|
+
get defaultOptions() {
|
|
1755
|
+
const opts = {
|
|
1756
|
+
apiUrl: this.apiUrl,
|
|
1757
|
+
publishableKey: this.publishableKey,
|
|
1758
|
+
secretKey: this.secretKey
|
|
1759
|
+
};
|
|
1760
|
+
const token = this.getCustomerToken?.();
|
|
1761
|
+
if (token) {
|
|
1762
|
+
opts.customerToken = token;
|
|
1763
|
+
if (this.onUnauthorized) {
|
|
1764
|
+
opts.onUnauthorized = this.onUnauthorized;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
return opts;
|
|
1768
|
+
}
|
|
1769
|
+
async fetchWithTracking(url, opts) {
|
|
1822
1770
|
try {
|
|
1823
|
-
const response = await httpFetch(
|
|
1824
|
-
method: options.method,
|
|
1825
|
-
apiUrl: this.apiUrl,
|
|
1826
|
-
publishableKey: this.publishableKey,
|
|
1827
|
-
secretKey: this.secretKey,
|
|
1828
|
-
customerToken: token ?? void 0,
|
|
1829
|
-
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1830
|
-
...options.body !== void 0 && {
|
|
1831
|
-
body: JSON.stringify(options.body)
|
|
1832
|
-
},
|
|
1833
|
-
...options.headers && { headers: options.headers },
|
|
1834
|
-
...options.errorFamily && { errorFamily: options.errorFamily }
|
|
1835
|
-
});
|
|
1771
|
+
const response = await httpFetch(url, opts);
|
|
1836
1772
|
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1837
|
-
return
|
|
1838
|
-
errorFamily: options.errorFamily
|
|
1839
|
-
});
|
|
1773
|
+
return response;
|
|
1840
1774
|
} catch (err) {
|
|
1841
1775
|
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1842
1776
|
this.onRequestId?.(id);
|
|
1843
1777
|
throw err;
|
|
1844
1778
|
}
|
|
1845
1779
|
}
|
|
1780
|
+
buildUrl(endpoint, options) {
|
|
1781
|
+
if (!options) return endpoint;
|
|
1782
|
+
const { fallbackLocale, ...rest } = options;
|
|
1783
|
+
const queryOptions = fallbackLocale === void 0 ? rest : {
|
|
1784
|
+
...rest,
|
|
1785
|
+
"fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
|
|
1786
|
+
};
|
|
1787
|
+
const encodedOptions = validateWhere(queryOptions.where) ? { ...queryOptions, where: JSON.stringify(queryOptions.where) } : queryOptions;
|
|
1788
|
+
const queryString = (0, import_qs_esm.stringify)(encodedOptions, { addQueryPrefix: true });
|
|
1789
|
+
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
1790
|
+
}
|
|
1791
|
+
assertJsonResponse(response) {
|
|
1792
|
+
const contentType = response.headers.get("content-type");
|
|
1793
|
+
if (!contentType?.includes("application/json")) {
|
|
1794
|
+
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1795
|
+
contentType
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
/**
|
|
1800
|
+
* Parse Payload CMS find response (list query)
|
|
1801
|
+
* Returns native Payload response structure
|
|
1802
|
+
*/
|
|
1803
|
+
async parseFindResponse(response) {
|
|
1804
|
+
const contentType = response.headers.get("content-type");
|
|
1805
|
+
try {
|
|
1806
|
+
this.assertJsonResponse(response);
|
|
1807
|
+
const jsonData = await response.json();
|
|
1808
|
+
if (jsonData.docs === void 0) {
|
|
1809
|
+
throw createApiError("Invalid find response.", response.status, {
|
|
1810
|
+
jsonData
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
return {
|
|
1814
|
+
docs: jsonData.docs,
|
|
1815
|
+
totalDocs: jsonData.totalDocs ?? 0,
|
|
1816
|
+
limit: jsonData.limit || 20,
|
|
1817
|
+
totalPages: jsonData.totalPages ?? 0,
|
|
1818
|
+
page: jsonData.page || 1,
|
|
1819
|
+
pagingCounter: jsonData.pagingCounter || 1,
|
|
1820
|
+
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
1821
|
+
hasNextPage: jsonData.hasNextPage ?? false,
|
|
1822
|
+
prevPage: jsonData.prevPage ?? null,
|
|
1823
|
+
nextPage: jsonData.nextPage ?? null
|
|
1824
|
+
};
|
|
1825
|
+
} catch (error) {
|
|
1826
|
+
if (error instanceof SDKError) throw error;
|
|
1827
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1828
|
+
contentType,
|
|
1829
|
+
error: error instanceof Error ? error.message : error
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
/**
|
|
1834
|
+
* Parse Payload CMS mutation response (create/update)
|
|
1835
|
+
* Returns native Payload response structure
|
|
1836
|
+
*/
|
|
1837
|
+
async parseMutationResponse(response) {
|
|
1838
|
+
const contentType = response.headers.get("content-type");
|
|
1839
|
+
try {
|
|
1840
|
+
this.assertJsonResponse(response);
|
|
1841
|
+
const jsonData = await response.json();
|
|
1842
|
+
if (jsonData.doc === void 0) {
|
|
1843
|
+
throw createApiError("Invalid mutation response.", response.status, {
|
|
1844
|
+
jsonData
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
return {
|
|
1848
|
+
message: jsonData.message || "",
|
|
1849
|
+
doc: jsonData.doc,
|
|
1850
|
+
errors: jsonData.errors
|
|
1851
|
+
};
|
|
1852
|
+
} catch (error) {
|
|
1853
|
+
if (error instanceof SDKError) throw error;
|
|
1854
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1855
|
+
contentType,
|
|
1856
|
+
error: error instanceof Error ? error.message : error
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Parse Payload CMS document response (findById/delete)
|
|
1862
|
+
* Returns document directly without wrapper
|
|
1863
|
+
*/
|
|
1864
|
+
async parseDocumentResponse(response) {
|
|
1865
|
+
const contentType = response.headers.get("content-type");
|
|
1866
|
+
try {
|
|
1867
|
+
this.assertJsonResponse(response);
|
|
1868
|
+
const jsonData = await response.json();
|
|
1869
|
+
return jsonData;
|
|
1870
|
+
} catch (error) {
|
|
1871
|
+
if (error instanceof SDKError) throw error;
|
|
1872
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1873
|
+
contentType,
|
|
1874
|
+
error: error instanceof Error ? error.message : error
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1846
1878
|
};
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1879
|
+
|
|
1880
|
+
// src/core/collection/query-builder.ts
|
|
1881
|
+
var PUBLIC_READ_DEPTH_ERROR = "Publishable collection reads require depth: 0. Use a shaped commerce endpoint or server client for populated data.";
|
|
1882
|
+
var PUBLIC_READ_JOINS_ERROR = "Publishable collection reads require joins: false. Use a shaped commerce endpoint or server client for joined data.";
|
|
1883
|
+
var PUBLIC_READ_POPULATE_ERROR = "Publishable collection reads do not support populate. Use a shaped commerce endpoint or server client for populated data.";
|
|
1884
|
+
function withDefaultPublicReadOptions(options) {
|
|
1885
|
+
const rawOptions = options;
|
|
1886
|
+
if (rawOptions?.depth !== void 0 && rawOptions.depth !== 0) {
|
|
1887
|
+
throw createValidationError(PUBLIC_READ_DEPTH_ERROR);
|
|
1850
1888
|
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1889
|
+
if (rawOptions?.joins !== void 0 && rawOptions.joins !== false) {
|
|
1890
|
+
throw createValidationError(PUBLIC_READ_JOINS_ERROR);
|
|
1891
|
+
}
|
|
1892
|
+
if (rawOptions?.populate !== void 0) {
|
|
1893
|
+
throw createValidationError(PUBLIC_READ_POPULATE_ERROR);
|
|
1894
|
+
}
|
|
1895
|
+
return {
|
|
1896
|
+
...options,
|
|
1897
|
+
depth: options?.depth ?? 0,
|
|
1898
|
+
joins: options?.joins ?? false
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
var ReadOnlyCollectionQueryBuilder = class {
|
|
1902
|
+
constructor(api, collection) {
|
|
1903
|
+
this.api = api;
|
|
1904
|
+
this.collection = collection;
|
|
1905
|
+
}
|
|
1906
|
+
async find(options) {
|
|
1907
|
+
return this.api.requestFind(
|
|
1908
|
+
`/api/${String(this.collection)}`,
|
|
1909
|
+
withDefaultPublicReadOptions(options)
|
|
1910
|
+
);
|
|
1911
|
+
}
|
|
1912
|
+
async findById(id, options) {
|
|
1913
|
+
return this.api.requestFindById(
|
|
1914
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
1915
|
+
withDefaultPublicReadOptions(options)
|
|
1916
|
+
);
|
|
1917
|
+
}
|
|
1918
|
+
async count(options) {
|
|
1919
|
+
return this.api.requestCount(
|
|
1920
|
+
`/api/${String(this.collection)}/count`,
|
|
1921
|
+
withDefaultPublicReadOptions(options)
|
|
1922
|
+
);
|
|
1858
1923
|
}
|
|
1859
1924
|
};
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1925
|
+
|
|
1926
|
+
// src/core/collection/collection-client.ts
|
|
1927
|
+
var ReadOnlyCollectionClient = class extends HttpClient {
|
|
1928
|
+
from(collection) {
|
|
1929
|
+
return new ReadOnlyCollectionQueryBuilder(this, collection);
|
|
1863
1930
|
}
|
|
1864
|
-
|
|
1865
|
-
|
|
1931
|
+
async requestFind(endpoint, options) {
|
|
1932
|
+
const url = this.buildUrl(endpoint, options);
|
|
1933
|
+
const response = await this.fetchWithTracking(url, {
|
|
1934
|
+
...this.defaultOptions,
|
|
1935
|
+
method: "GET"
|
|
1936
|
+
});
|
|
1937
|
+
return this.parseFindResponse(response);
|
|
1938
|
+
}
|
|
1939
|
+
async requestFindEndpoint(endpoint, data) {
|
|
1940
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1941
|
+
...this.defaultOptions,
|
|
1942
|
+
method: "POST",
|
|
1943
|
+
body: data ? JSON.stringify(data) : void 0
|
|
1944
|
+
});
|
|
1945
|
+
return this.parseFindResponse(response);
|
|
1946
|
+
}
|
|
1947
|
+
async requestFindEndpointGet(endpoint) {
|
|
1948
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1949
|
+
...this.defaultOptions,
|
|
1950
|
+
method: "GET"
|
|
1951
|
+
});
|
|
1952
|
+
return this.parseFindResponse(response);
|
|
1953
|
+
}
|
|
1954
|
+
async requestFindById(endpoint, options) {
|
|
1955
|
+
const url = this.buildUrl(endpoint, options);
|
|
1956
|
+
const response = await this.fetchWithTracking(url, {
|
|
1957
|
+
...this.defaultOptions,
|
|
1958
|
+
method: "GET"
|
|
1959
|
+
});
|
|
1960
|
+
return this.parseDocumentResponse(response);
|
|
1961
|
+
}
|
|
1962
|
+
async requestCount(endpoint, options) {
|
|
1963
|
+
const url = this.buildUrl(endpoint, options);
|
|
1964
|
+
const response = await this.fetchWithTracking(url, {
|
|
1965
|
+
...this.defaultOptions,
|
|
1966
|
+
method: "GET"
|
|
1967
|
+
});
|
|
1968
|
+
return this.parseDocumentResponse(response);
|
|
1866
1969
|
}
|
|
1867
1970
|
};
|
|
1868
1971
|
|
|
@@ -4021,19 +4124,24 @@ var CustomerAuth = class {
|
|
|
4021
4124
|
* Register a new customer account
|
|
4022
4125
|
*/
|
|
4023
4126
|
async register(data) {
|
|
4024
|
-
return this.requestJson(
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4127
|
+
return this.requestJson(
|
|
4128
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.register),
|
|
4129
|
+
{
|
|
4130
|
+
method: resolveOperationMethod(
|
|
4131
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.register
|
|
4132
|
+
),
|
|
4133
|
+
body: JSON.stringify(data)
|
|
4134
|
+
}
|
|
4135
|
+
);
|
|
4028
4136
|
}
|
|
4029
4137
|
/**
|
|
4030
4138
|
* Login with email and password. Stores the token internally.
|
|
4031
4139
|
*/
|
|
4032
4140
|
async login(data) {
|
|
4033
4141
|
const result = await this.requestJson(
|
|
4034
|
-
|
|
4142
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.login),
|
|
4035
4143
|
{
|
|
4036
|
-
method:
|
|
4144
|
+
method: resolveOperationMethod(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.login),
|
|
4037
4145
|
body: JSON.stringify(data)
|
|
4038
4146
|
}
|
|
4039
4147
|
);
|
|
@@ -4279,14 +4387,18 @@ var CustomerAuth = class {
|
|
|
4279
4387
|
}
|
|
4280
4388
|
async _doRefreshToken(intended) {
|
|
4281
4389
|
const init = intended.refreshToken ? {
|
|
4282
|
-
method:
|
|
4390
|
+
method: resolveOperationMethod(
|
|
4391
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.refresh
|
|
4392
|
+
),
|
|
4283
4393
|
body: JSON.stringify({ refreshToken: intended.refreshToken })
|
|
4284
4394
|
} : {
|
|
4285
|
-
method:
|
|
4395
|
+
method: resolveOperationMethod(
|
|
4396
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.refresh
|
|
4397
|
+
),
|
|
4286
4398
|
headers: { Authorization: `Bearer ${intended.token}` }
|
|
4287
4399
|
};
|
|
4288
4400
|
const result = await this.requestJson(
|
|
4289
|
-
|
|
4401
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.refresh),
|
|
4290
4402
|
init
|
|
4291
4403
|
);
|
|
4292
4404
|
const state = this.classifyCanonicalState(intended);
|
|
@@ -4355,9 +4467,9 @@ var CustomerAuth = class {
|
|
|
4355
4467
|
if (!token) return null;
|
|
4356
4468
|
try {
|
|
4357
4469
|
const data = await this.requestJson(
|
|
4358
|
-
|
|
4470
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.me),
|
|
4359
4471
|
{
|
|
4360
|
-
method:
|
|
4472
|
+
method: resolveOperationMethod(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.me),
|
|
4361
4473
|
headers: { Authorization: `Bearer ${token}` }
|
|
4362
4474
|
}
|
|
4363
4475
|
);
|
|
@@ -4374,19 +4486,29 @@ var CustomerAuth = class {
|
|
|
4374
4486
|
* Request a password reset email
|
|
4375
4487
|
*/
|
|
4376
4488
|
async forgotPassword(email) {
|
|
4377
|
-
await this.requestJson(
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4489
|
+
await this.requestJson(
|
|
4490
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.forgotPassword),
|
|
4491
|
+
{
|
|
4492
|
+
method: resolveOperationMethod(
|
|
4493
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.forgotPassword
|
|
4494
|
+
),
|
|
4495
|
+
body: JSON.stringify({ email })
|
|
4496
|
+
}
|
|
4497
|
+
);
|
|
4381
4498
|
}
|
|
4382
4499
|
/**
|
|
4383
4500
|
* Reset password using a token from the reset email
|
|
4384
4501
|
*/
|
|
4385
4502
|
async resetPassword(token, password) {
|
|
4386
|
-
await this.requestJson(
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4503
|
+
await this.requestJson(
|
|
4504
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.resetPassword),
|
|
4505
|
+
{
|
|
4506
|
+
method: resolveOperationMethod(
|
|
4507
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.resetPassword
|
|
4508
|
+
),
|
|
4509
|
+
body: JSON.stringify({ token, password })
|
|
4510
|
+
}
|
|
4511
|
+
);
|
|
4390
4512
|
}
|
|
4391
4513
|
/**
|
|
4392
4514
|
* Update the authenticated customer's profile (name, phone, marketingConsent)
|
|
@@ -4395,9 +4517,11 @@ var CustomerAuth = class {
|
|
|
4395
4517
|
const token = this.getToken();
|
|
4396
4518
|
if (!token) throw new ApiError("Not authenticated", 401);
|
|
4397
4519
|
const result = await this.requestJson(
|
|
4398
|
-
|
|
4520
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.updateProfile),
|
|
4399
4521
|
{
|
|
4400
|
-
method:
|
|
4522
|
+
method: resolveOperationMethod(
|
|
4523
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.updateProfile
|
|
4524
|
+
),
|
|
4401
4525
|
headers: { Authorization: `Bearer ${token}` },
|
|
4402
4526
|
body: JSON.stringify(data)
|
|
4403
4527
|
}
|
|
@@ -4410,11 +4534,16 @@ var CustomerAuth = class {
|
|
|
4410
4534
|
async changePassword(currentPassword, newPassword) {
|
|
4411
4535
|
const token = this.getToken();
|
|
4412
4536
|
if (!token) throw new ApiError("Not authenticated", 401);
|
|
4413
|
-
await this.requestJson(
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4537
|
+
await this.requestJson(
|
|
4538
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.changePassword),
|
|
4539
|
+
{
|
|
4540
|
+
method: resolveOperationMethod(
|
|
4541
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.changePassword
|
|
4542
|
+
),
|
|
4543
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
4544
|
+
body: JSON.stringify({ currentPassword, newPassword })
|
|
4545
|
+
}
|
|
4546
|
+
);
|
|
4418
4547
|
}
|
|
4419
4548
|
/**
|
|
4420
4549
|
* Get the authenticated customer's orders with pagination and optional status filter
|
|
@@ -6212,6 +6341,18 @@ var EventsClient = class {
|
|
|
6212
6341
|
{ useCustomerAuth: false }
|
|
6213
6342
|
);
|
|
6214
6343
|
}
|
|
6344
|
+
listMyRegistrations(params = {}) {
|
|
6345
|
+
const query = new URLSearchParams();
|
|
6346
|
+
if (params.page !== void 0) query.set("page", String(params.page));
|
|
6347
|
+
if (params.limit !== void 0) query.set("limit", String(params.limit));
|
|
6348
|
+
const operation2 = EVENTS_ENDPOINT_OPERATIONS.registrations.listMine;
|
|
6349
|
+
return this.execute(
|
|
6350
|
+
resolveOperationPath(operation2, { query }),
|
|
6351
|
+
resolveOperationMethod(operation2),
|
|
6352
|
+
void 0,
|
|
6353
|
+
{ useCustomerAuth: true, noStore: true }
|
|
6354
|
+
);
|
|
6355
|
+
}
|
|
6215
6356
|
register(params) {
|
|
6216
6357
|
return this.execute(
|
|
6217
6358
|
"/api/event-registrations/register",
|
|
@@ -6242,6 +6383,7 @@ var EventsClient = class {
|
|
|
6242
6383
|
try {
|
|
6243
6384
|
const response = await httpFetch(endpoint, {
|
|
6244
6385
|
method,
|
|
6386
|
+
...options.noStore && { cache: "no-store" },
|
|
6245
6387
|
apiUrl: this.apiUrl,
|
|
6246
6388
|
publishableKey: this.publishableKey,
|
|
6247
6389
|
...useCustomerAuth && token ? { customerToken: token } : {},
|
|
@@ -6434,6 +6576,16 @@ var Client = class _Client {
|
|
|
6434
6576
|
this.markets = new MarketDiscovery(
|
|
6435
6577
|
(options2) => this.collections.from("markets").find(options2)
|
|
6436
6578
|
);
|
|
6579
|
+
this.benefitVouchers = new CustomerBenefitVouchersApi(
|
|
6580
|
+
"CustomerBenefitVouchersApi",
|
|
6581
|
+
{
|
|
6582
|
+
publishableKey: this.config.publishableKey,
|
|
6583
|
+
apiUrl: this.config.apiUrl,
|
|
6584
|
+
customerToken: () => this.customer.auth.getToken(),
|
|
6585
|
+
onUnauthorized,
|
|
6586
|
+
onRequestId
|
|
6587
|
+
}
|
|
6588
|
+
);
|
|
6437
6589
|
const membershipApi = new BrowserMembershipApi("MembershipApi", {
|
|
6438
6590
|
publishableKey: this.config.publishableKey,
|
|
6439
6591
|
apiUrl: this.config.apiUrl,
|