@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/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/core/collection/http-client.ts
|
|
2
|
-
import { stringify } from "qs-esm";
|
|
3
|
-
|
|
4
1
|
// src/core/errors.ts
|
|
5
2
|
var SDK_ERROR_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError");
|
|
6
3
|
var SDK_ERROR_TYPE_BRAND = /* @__PURE__ */ Symbol.for("@01.software/sdk/SDKError.type");
|
|
@@ -1004,288 +1001,6 @@ function stockSnapshotSearchParams(params) {
|
|
|
1004
1001
|
return `variantIds=${params.variantIds.map(encodeURIComponent).join(",")}`;
|
|
1005
1002
|
}
|
|
1006
1003
|
|
|
1007
|
-
// src/core/collection/http-client.ts
|
|
1008
|
-
function validateWhere(where) {
|
|
1009
|
-
if (where === void 0) return false;
|
|
1010
|
-
let hasNull = false;
|
|
1011
|
-
function visit(value, depth, key) {
|
|
1012
|
-
if (depth > 10) {
|
|
1013
|
-
throw createValidationError(
|
|
1014
|
-
"Collection where must not exceed nesting depth 10."
|
|
1015
|
-
);
|
|
1016
|
-
}
|
|
1017
|
-
if (value === null && (key === "equals" || key === "not_equals")) {
|
|
1018
|
-
hasNull = true;
|
|
1019
|
-
return;
|
|
1020
|
-
}
|
|
1021
|
-
if (value == null) {
|
|
1022
|
-
throw createValidationError(
|
|
1023
|
-
"Collection where must not contain null or undefined values."
|
|
1024
|
-
);
|
|
1025
|
-
}
|
|
1026
|
-
if (Array.isArray(value)) {
|
|
1027
|
-
if (value.length === 0) {
|
|
1028
|
-
throw createValidationError(
|
|
1029
|
-
"Collection where must not contain empty arrays, including and/or."
|
|
1030
|
-
);
|
|
1031
|
-
}
|
|
1032
|
-
if (value.length > 1e3) {
|
|
1033
|
-
throw createValidationError(
|
|
1034
|
-
"Collection where arrays must not contain more than 1000 elements."
|
|
1035
|
-
);
|
|
1036
|
-
}
|
|
1037
|
-
for (const item of value) visit(item, depth + 1);
|
|
1038
|
-
} else if (typeof value === "object" && !(value instanceof Date)) {
|
|
1039
|
-
const values = Object.entries(value);
|
|
1040
|
-
if (values.length === 0) {
|
|
1041
|
-
throw createValidationError(
|
|
1042
|
-
"Collection where must not contain empty condition objects."
|
|
1043
|
-
);
|
|
1044
|
-
}
|
|
1045
|
-
for (const [key2, item] of values) visit(item, depth + 1, key2);
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
visit(where, 0);
|
|
1049
|
-
return hasNull;
|
|
1050
|
-
}
|
|
1051
|
-
var HttpClient = class {
|
|
1052
|
-
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
1053
|
-
this.publishableKey = requirePublishableKeyForSecret(
|
|
1054
|
-
"CollectionClient",
|
|
1055
|
-
publishableKey,
|
|
1056
|
-
secretKey
|
|
1057
|
-
);
|
|
1058
|
-
this.secretKey = secretKey;
|
|
1059
|
-
this.getCustomerToken = getCustomerToken;
|
|
1060
|
-
this.onUnauthorized = onUnauthorized;
|
|
1061
|
-
this.onRequestId = onRequestId;
|
|
1062
|
-
this.apiUrl = apiUrl;
|
|
1063
|
-
}
|
|
1064
|
-
get defaultOptions() {
|
|
1065
|
-
const opts = {
|
|
1066
|
-
apiUrl: this.apiUrl,
|
|
1067
|
-
publishableKey: this.publishableKey,
|
|
1068
|
-
secretKey: this.secretKey
|
|
1069
|
-
};
|
|
1070
|
-
const token = this.getCustomerToken?.();
|
|
1071
|
-
if (token) {
|
|
1072
|
-
opts.customerToken = token;
|
|
1073
|
-
if (this.onUnauthorized) {
|
|
1074
|
-
opts.onUnauthorized = this.onUnauthorized;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
return opts;
|
|
1078
|
-
}
|
|
1079
|
-
async fetchWithTracking(url, opts) {
|
|
1080
|
-
try {
|
|
1081
|
-
const response = await httpFetch(url, opts);
|
|
1082
|
-
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1083
|
-
return response;
|
|
1084
|
-
} catch (err) {
|
|
1085
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1086
|
-
this.onRequestId?.(id);
|
|
1087
|
-
throw err;
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
buildUrl(endpoint, options) {
|
|
1091
|
-
if (!options) return endpoint;
|
|
1092
|
-
const { fallbackLocale, ...rest } = options;
|
|
1093
|
-
const queryOptions = fallbackLocale === void 0 ? rest : {
|
|
1094
|
-
...rest,
|
|
1095
|
-
"fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
|
|
1096
|
-
};
|
|
1097
|
-
const encodedOptions = validateWhere(queryOptions.where) ? { ...queryOptions, where: JSON.stringify(queryOptions.where) } : queryOptions;
|
|
1098
|
-
const queryString = stringify(encodedOptions, { addQueryPrefix: true });
|
|
1099
|
-
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
1100
|
-
}
|
|
1101
|
-
assertJsonResponse(response) {
|
|
1102
|
-
const contentType = response.headers.get("content-type");
|
|
1103
|
-
if (!contentType?.includes("application/json")) {
|
|
1104
|
-
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1105
|
-
contentType
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Parse Payload CMS find response (list query)
|
|
1111
|
-
* Returns native Payload response structure
|
|
1112
|
-
*/
|
|
1113
|
-
async parseFindResponse(response) {
|
|
1114
|
-
const contentType = response.headers.get("content-type");
|
|
1115
|
-
try {
|
|
1116
|
-
this.assertJsonResponse(response);
|
|
1117
|
-
const jsonData = await response.json();
|
|
1118
|
-
if (jsonData.docs === void 0) {
|
|
1119
|
-
throw createApiError("Invalid find response.", response.status, {
|
|
1120
|
-
jsonData
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
|
-
return {
|
|
1124
|
-
docs: jsonData.docs,
|
|
1125
|
-
totalDocs: jsonData.totalDocs ?? 0,
|
|
1126
|
-
limit: jsonData.limit || 20,
|
|
1127
|
-
totalPages: jsonData.totalPages ?? 0,
|
|
1128
|
-
page: jsonData.page || 1,
|
|
1129
|
-
pagingCounter: jsonData.pagingCounter || 1,
|
|
1130
|
-
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
1131
|
-
hasNextPage: jsonData.hasNextPage ?? false,
|
|
1132
|
-
prevPage: jsonData.prevPage ?? null,
|
|
1133
|
-
nextPage: jsonData.nextPage ?? null
|
|
1134
|
-
};
|
|
1135
|
-
} catch (error) {
|
|
1136
|
-
if (error instanceof SDKError) throw error;
|
|
1137
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1138
|
-
contentType,
|
|
1139
|
-
error: error instanceof Error ? error.message : error
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Parse Payload CMS mutation response (create/update)
|
|
1145
|
-
* Returns native Payload response structure
|
|
1146
|
-
*/
|
|
1147
|
-
async parseMutationResponse(response) {
|
|
1148
|
-
const contentType = response.headers.get("content-type");
|
|
1149
|
-
try {
|
|
1150
|
-
this.assertJsonResponse(response);
|
|
1151
|
-
const jsonData = await response.json();
|
|
1152
|
-
if (jsonData.doc === void 0) {
|
|
1153
|
-
throw createApiError("Invalid mutation response.", response.status, {
|
|
1154
|
-
jsonData
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
return {
|
|
1158
|
-
message: jsonData.message || "",
|
|
1159
|
-
doc: jsonData.doc,
|
|
1160
|
-
errors: jsonData.errors
|
|
1161
|
-
};
|
|
1162
|
-
} catch (error) {
|
|
1163
|
-
if (error instanceof SDKError) throw error;
|
|
1164
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1165
|
-
contentType,
|
|
1166
|
-
error: error instanceof Error ? error.message : error
|
|
1167
|
-
});
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
/**
|
|
1171
|
-
* Parse Payload CMS document response (findById/delete)
|
|
1172
|
-
* Returns document directly without wrapper
|
|
1173
|
-
*/
|
|
1174
|
-
async parseDocumentResponse(response) {
|
|
1175
|
-
const contentType = response.headers.get("content-type");
|
|
1176
|
-
try {
|
|
1177
|
-
this.assertJsonResponse(response);
|
|
1178
|
-
const jsonData = await response.json();
|
|
1179
|
-
return jsonData;
|
|
1180
|
-
} catch (error) {
|
|
1181
|
-
if (error instanceof SDKError) throw error;
|
|
1182
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
1183
|
-
contentType,
|
|
1184
|
-
error: error instanceof Error ? error.message : error
|
|
1185
|
-
});
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
};
|
|
1189
|
-
|
|
1190
|
-
// src/utils/types.ts
|
|
1191
|
-
function resolveRelation(ref) {
|
|
1192
|
-
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
1193
|
-
return null;
|
|
1194
|
-
return ref;
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
// src/core/collection/query-builder.ts
|
|
1198
|
-
var PUBLIC_READ_DEPTH_ERROR = "Publishable collection reads require depth: 0. Use a shaped commerce endpoint or server client for populated data.";
|
|
1199
|
-
var PUBLIC_READ_JOINS_ERROR = "Publishable collection reads require joins: false. Use a shaped commerce endpoint or server client for joined data.";
|
|
1200
|
-
var PUBLIC_READ_POPULATE_ERROR = "Publishable collection reads do not support populate. Use a shaped commerce endpoint or server client for populated data.";
|
|
1201
|
-
function withDefaultPublicReadOptions(options) {
|
|
1202
|
-
const rawOptions = options;
|
|
1203
|
-
if (rawOptions?.depth !== void 0 && rawOptions.depth !== 0) {
|
|
1204
|
-
throw createValidationError(PUBLIC_READ_DEPTH_ERROR);
|
|
1205
|
-
}
|
|
1206
|
-
if (rawOptions?.joins !== void 0 && rawOptions.joins !== false) {
|
|
1207
|
-
throw createValidationError(PUBLIC_READ_JOINS_ERROR);
|
|
1208
|
-
}
|
|
1209
|
-
if (rawOptions?.populate !== void 0) {
|
|
1210
|
-
throw createValidationError(PUBLIC_READ_POPULATE_ERROR);
|
|
1211
|
-
}
|
|
1212
|
-
return {
|
|
1213
|
-
...options,
|
|
1214
|
-
depth: options?.depth ?? 0,
|
|
1215
|
-
joins: options?.joins ?? false
|
|
1216
|
-
};
|
|
1217
|
-
}
|
|
1218
|
-
var ReadOnlyCollectionQueryBuilder = class {
|
|
1219
|
-
constructor(api, collection) {
|
|
1220
|
-
this.api = api;
|
|
1221
|
-
this.collection = collection;
|
|
1222
|
-
}
|
|
1223
|
-
async find(options) {
|
|
1224
|
-
return this.api.requestFind(
|
|
1225
|
-
`/api/${String(this.collection)}`,
|
|
1226
|
-
withDefaultPublicReadOptions(options)
|
|
1227
|
-
);
|
|
1228
|
-
}
|
|
1229
|
-
async findById(id, options) {
|
|
1230
|
-
return this.api.requestFindById(
|
|
1231
|
-
`/api/${String(this.collection)}/${String(id)}`,
|
|
1232
|
-
withDefaultPublicReadOptions(options)
|
|
1233
|
-
);
|
|
1234
|
-
}
|
|
1235
|
-
async count(options) {
|
|
1236
|
-
return this.api.requestCount(
|
|
1237
|
-
`/api/${String(this.collection)}/count`,
|
|
1238
|
-
withDefaultPublicReadOptions(options)
|
|
1239
|
-
);
|
|
1240
|
-
}
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
// src/core/collection/collection-client.ts
|
|
1244
|
-
var ReadOnlyCollectionClient = class extends HttpClient {
|
|
1245
|
-
from(collection) {
|
|
1246
|
-
return new ReadOnlyCollectionQueryBuilder(this, collection);
|
|
1247
|
-
}
|
|
1248
|
-
async requestFind(endpoint, options) {
|
|
1249
|
-
const url = this.buildUrl(endpoint, options);
|
|
1250
|
-
const response = await this.fetchWithTracking(url, {
|
|
1251
|
-
...this.defaultOptions,
|
|
1252
|
-
method: "GET"
|
|
1253
|
-
});
|
|
1254
|
-
return this.parseFindResponse(response);
|
|
1255
|
-
}
|
|
1256
|
-
async requestFindEndpoint(endpoint, data) {
|
|
1257
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1258
|
-
...this.defaultOptions,
|
|
1259
|
-
method: "POST",
|
|
1260
|
-
body: data ? JSON.stringify(data) : void 0
|
|
1261
|
-
});
|
|
1262
|
-
return this.parseFindResponse(response);
|
|
1263
|
-
}
|
|
1264
|
-
async requestFindEndpointGet(endpoint) {
|
|
1265
|
-
const response = await this.fetchWithTracking(endpoint, {
|
|
1266
|
-
...this.defaultOptions,
|
|
1267
|
-
method: "GET"
|
|
1268
|
-
});
|
|
1269
|
-
return this.parseFindResponse(response);
|
|
1270
|
-
}
|
|
1271
|
-
async requestFindById(endpoint, options) {
|
|
1272
|
-
const url = this.buildUrl(endpoint, options);
|
|
1273
|
-
const response = await this.fetchWithTracking(url, {
|
|
1274
|
-
...this.defaultOptions,
|
|
1275
|
-
method: "GET"
|
|
1276
|
-
});
|
|
1277
|
-
return this.parseDocumentResponse(response);
|
|
1278
|
-
}
|
|
1279
|
-
async requestCount(endpoint, options) {
|
|
1280
|
-
const url = this.buildUrl(endpoint, options);
|
|
1281
|
-
const response = await this.fetchWithTracking(url, {
|
|
1282
|
-
...this.defaultOptions,
|
|
1283
|
-
method: "GET"
|
|
1284
|
-
});
|
|
1285
|
-
return this.parseDocumentResponse(response);
|
|
1286
|
-
}
|
|
1287
|
-
};
|
|
1288
|
-
|
|
1289
1004
|
// src/core/api/parse-response.ts
|
|
1290
1005
|
async function parseApiResponse(response, endpoint, options = {}) {
|
|
1291
1006
|
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
@@ -1382,7 +1097,9 @@ var COMMERCE_ENDPOINT_OPERATIONS = {
|
|
|
1382
1097
|
),
|
|
1383
1098
|
stockCheck: operation("products", "post", "/stock-check"),
|
|
1384
1099
|
stockSnapshot: operation("products", "get", "/stock"),
|
|
1385
|
-
upsert: operation("products", "post", "/upsert")
|
|
1100
|
+
upsert: operation("products", "post", "/upsert"),
|
|
1101
|
+
graphRevision: operation("products", "get", "/:id/graph-revision"),
|
|
1102
|
+
variantsPatch: operation("products", "patch", "/:id/variants")
|
|
1386
1103
|
},
|
|
1387
1104
|
orders: {
|
|
1388
1105
|
create: operation("orders", "post", "/create"),
|
|
@@ -1545,12 +1262,28 @@ var EXTERNAL_CUSTOMER_LINK_ENDPOINT_OPERATIONS = {
|
|
|
1545
1262
|
"/external-links/clear-previous-state"
|
|
1546
1263
|
)
|
|
1547
1264
|
};
|
|
1265
|
+
var BENEFIT_VOUCHER_ENDPOINT_OPERATIONS = {
|
|
1266
|
+
issue: operation("customers", "post", "/benefit-vouchers/issue"),
|
|
1267
|
+
get: operation("customers", "post", "/benefit-vouchers/get"),
|
|
1268
|
+
list: operation("customers", "post", "/benefit-vouchers/list"),
|
|
1269
|
+
redeem: operation("customers", "post", "/benefit-vouchers/redeem"),
|
|
1270
|
+
void: operation("customers", "post", "/benefit-vouchers/void"),
|
|
1271
|
+
listMine: operation("customers", "get", "/me/benefit-vouchers")
|
|
1272
|
+
};
|
|
1548
1273
|
var CUSTOMER_GROUP_ENDPOINT_OPERATIONS = {
|
|
1549
1274
|
members: operation("customer-groups", "get", "/:id/members"),
|
|
1550
1275
|
grant: operation("customer-groups", "post", "/:id/members/grant"),
|
|
1551
1276
|
revoke: operation("customer-groups", "post", "/:id/members/revoke")
|
|
1552
1277
|
};
|
|
1553
1278
|
var CUSTOMER_AUTH_ENDPOINT_OPERATIONS = {
|
|
1279
|
+
register: operation("customers", "post", "/register"),
|
|
1280
|
+
login: operation("customers", "post", "/login"),
|
|
1281
|
+
refresh: operation("customers", "post", "/refresh"),
|
|
1282
|
+
me: operation("customers", "get", "/me"),
|
|
1283
|
+
updateProfile: operation("customers", "patch", "/me"),
|
|
1284
|
+
forgotPassword: operation("customers", "post", "/forgot-password"),
|
|
1285
|
+
resetPassword: operation("customers", "post", "/reset-password"),
|
|
1286
|
+
changePassword: operation("customers", "post", "/change-password"),
|
|
1554
1287
|
revokeRefresh: operation("customers", "post", "/revoke-refresh"),
|
|
1555
1288
|
withdraw: operation("customers", "post", "/withdraw")
|
|
1556
1289
|
};
|
|
@@ -1560,6 +1293,9 @@ var EMBEDDED_ADMIN_ENDPOINT_OPERATIONS = {
|
|
|
1560
1293
|
disable: operation("tenants", "delete", "/embedded-admin-app")
|
|
1561
1294
|
};
|
|
1562
1295
|
var EVENTS_ENDPOINT_OPERATIONS = {
|
|
1296
|
+
registrations: {
|
|
1297
|
+
listMine: operation("event-registrations", "get", "/my")
|
|
1298
|
+
},
|
|
1563
1299
|
events: {
|
|
1564
1300
|
convertSchedule: operation("events", "post", "/:id/schedule")
|
|
1565
1301
|
},
|
|
@@ -1760,73 +1496,440 @@ var COMMERCE_ENDPOINTS = {
|
|
|
1760
1496
|
COMMERCE_ENDPOINT_OPERATIONS.shippingPolicies.calculate
|
|
1761
1497
|
)
|
|
1762
1498
|
}
|
|
1763
|
-
};
|
|
1764
|
-
|
|
1765
|
-
// src/core/api/customer-scoped-api.ts
|
|
1766
|
-
var CustomerScopedTransport = class {
|
|
1767
|
-
constructor(apiName, options) {
|
|
1768
|
-
if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
|
|
1769
|
-
throw createConfigError(
|
|
1770
|
-
`Either secretKey or customerToken is required for ${apiName}.`
|
|
1771
|
-
);
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
// src/core/api/customer-scoped-api.ts
|
|
1502
|
+
var CustomerScopedTransport = class {
|
|
1503
|
+
constructor(apiName, options) {
|
|
1504
|
+
if (options.requiresCredential !== false && !options.secretKey && !options.customerToken) {
|
|
1505
|
+
throw createConfigError(
|
|
1506
|
+
`Either secretKey or customerToken is required for ${apiName}.`
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
this.publishableKey = requirePublishableKeyForSecret(
|
|
1510
|
+
apiName,
|
|
1511
|
+
options.publishableKey,
|
|
1512
|
+
options.secretKey
|
|
1513
|
+
);
|
|
1514
|
+
this.secretKey = options.secretKey;
|
|
1515
|
+
this.apiUrl = options.apiUrl;
|
|
1516
|
+
this.customerToken = options.customerToken;
|
|
1517
|
+
this.onUnauthorized = options.onUnauthorized;
|
|
1518
|
+
this.onRequestId = options.onRequestId;
|
|
1519
|
+
}
|
|
1520
|
+
async request(endpoint, options) {
|
|
1521
|
+
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1522
|
+
try {
|
|
1523
|
+
const response = await httpFetch(endpoint, {
|
|
1524
|
+
method: options.method,
|
|
1525
|
+
apiUrl: this.apiUrl,
|
|
1526
|
+
publishableKey: this.publishableKey,
|
|
1527
|
+
secretKey: this.secretKey,
|
|
1528
|
+
customerToken: token ?? void 0,
|
|
1529
|
+
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1530
|
+
...options.body !== void 0 && {
|
|
1531
|
+
body: JSON.stringify(options.body)
|
|
1532
|
+
},
|
|
1533
|
+
...options.headers && { headers: options.headers },
|
|
1534
|
+
...options.errorFamily && { errorFamily: options.errorFamily }
|
|
1535
|
+
});
|
|
1536
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1537
|
+
return parseApiResponse(response, endpoint, {
|
|
1538
|
+
errorFamily: options.errorFamily
|
|
1539
|
+
});
|
|
1540
|
+
} catch (err) {
|
|
1541
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1542
|
+
this.onRequestId?.(id);
|
|
1543
|
+
throw err;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
var CustomerScopedApi = class {
|
|
1548
|
+
constructor(apiName, options) {
|
|
1549
|
+
this.transport = new CustomerScopedTransport(apiName, options);
|
|
1550
|
+
}
|
|
1551
|
+
requestEndpoint(endpoint, body, options) {
|
|
1552
|
+
return this.transport.request(resolveOperationPath(endpoint, options), {
|
|
1553
|
+
method: resolveOperationMethod(endpoint),
|
|
1554
|
+
body,
|
|
1555
|
+
headers: options?.headers,
|
|
1556
|
+
errorFamily: resolveOperationErrorFamily(endpoint)
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
var RawCustomerScopedApi = class {
|
|
1561
|
+
constructor(apiName, options) {
|
|
1562
|
+
this.transport = new CustomerScopedTransport(apiName, options);
|
|
1563
|
+
}
|
|
1564
|
+
request(endpoint, options) {
|
|
1565
|
+
return this.transport.request(endpoint, options);
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
|
|
1569
|
+
// src/core/api/benefit-voucher-types.ts
|
|
1570
|
+
var BENEFIT_VOUCHER_VOID_REASONS = [
|
|
1571
|
+
"issued_in_error",
|
|
1572
|
+
"benefit_revoked",
|
|
1573
|
+
"customer_request",
|
|
1574
|
+
"other"
|
|
1575
|
+
];
|
|
1576
|
+
function invalidBenefitVoucherResponse() {
|
|
1577
|
+
throw createApiError("Invalid benefit voucher response", 200);
|
|
1578
|
+
}
|
|
1579
|
+
function object(value, keys) {
|
|
1580
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).length !== keys.length || keys.some((key) => !(key in value)))
|
|
1581
|
+
invalidBenefitVoucherResponse();
|
|
1582
|
+
return value;
|
|
1583
|
+
}
|
|
1584
|
+
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(
|
|
1585
|
+
v
|
|
1586
|
+
) || v === "00000000-0000-0000-0000-000000000000" || v.toLowerCase() === "ffffffff-ffff-ffff-ffff-ffffffffffff");
|
|
1587
|
+
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;
|
|
1588
|
+
var actor = (v) => typeof v === "string" && /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(v);
|
|
1589
|
+
function parseBenefitVoucher(value, mine = false) {
|
|
1590
|
+
const v = object(value, [
|
|
1591
|
+
"id",
|
|
1592
|
+
"name",
|
|
1593
|
+
"description",
|
|
1594
|
+
"state",
|
|
1595
|
+
"issuedAt",
|
|
1596
|
+
"expiresAt",
|
|
1597
|
+
...mine ? ["closedAt"] : ["customerId", "definitionId", "source", "closed"]
|
|
1598
|
+
]);
|
|
1599
|
+
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))
|
|
1600
|
+
invalidBenefitVoucherResponse();
|
|
1601
|
+
if (mine) {
|
|
1602
|
+
if (v.closedAt !== null && !time(v.closedAt))
|
|
1603
|
+
invalidBenefitVoucherResponse();
|
|
1604
|
+
} else {
|
|
1605
|
+
if (!uuid(v.customerId) || !uuid(v.definitionId))
|
|
1606
|
+
invalidBenefitVoucherResponse();
|
|
1607
|
+
const source = object(v.source, ["namespace", "ref"]);
|
|
1608
|
+
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)
|
|
1609
|
+
invalidBenefitVoucherResponse();
|
|
1610
|
+
if (v.closed !== null) {
|
|
1611
|
+
const closed = object(v.closed, [
|
|
1612
|
+
"at",
|
|
1613
|
+
"channel",
|
|
1614
|
+
"actor",
|
|
1615
|
+
"actorRef",
|
|
1616
|
+
"voidReason"
|
|
1617
|
+
]);
|
|
1618
|
+
const principal = object(closed.actor, ["type", "id"]);
|
|
1619
|
+
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))
|
|
1620
|
+
invalidBenefitVoucherResponse();
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
return value;
|
|
1624
|
+
}
|
|
1625
|
+
function parseBenefitVoucherList(value, mine = false) {
|
|
1626
|
+
const v = object(value, ["vouchers", "nextCursor", "evaluatedAt"]);
|
|
1627
|
+
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))
|
|
1628
|
+
invalidBenefitVoucherResponse();
|
|
1629
|
+
for (const row of v.vouchers) {
|
|
1630
|
+
if (mine) parseBenefitVoucher(row, true);
|
|
1631
|
+
else parseBenefitVoucher(row);
|
|
1632
|
+
}
|
|
1633
|
+
return value;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
// src/core/api/customer-benefit-vouchers-api.ts
|
|
1637
|
+
var CustomerBenefitVouchersApi = class extends CustomerScopedApi {
|
|
1638
|
+
async listMine(params = {}) {
|
|
1639
|
+
const query = new URLSearchParams();
|
|
1640
|
+
for (const [key, value] of Object.entries(params))
|
|
1641
|
+
if (value !== void 0) query.set(key, String(value));
|
|
1642
|
+
return parseBenefitVoucherList(
|
|
1643
|
+
await this.requestEndpoint(
|
|
1644
|
+
BENEFIT_VOUCHER_ENDPOINT_OPERATIONS.listMine,
|
|
1645
|
+
void 0,
|
|
1646
|
+
{ query }
|
|
1647
|
+
),
|
|
1648
|
+
true
|
|
1649
|
+
);
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1653
|
+
// src/core/collection/http-client.ts
|
|
1654
|
+
import { stringify } from "qs-esm";
|
|
1655
|
+
function validateWhere(where) {
|
|
1656
|
+
if (where === void 0) return false;
|
|
1657
|
+
let hasNull = false;
|
|
1658
|
+
function visit(value, depth, key) {
|
|
1659
|
+
if (depth > 10) {
|
|
1660
|
+
throw createValidationError(
|
|
1661
|
+
"Collection where must not exceed nesting depth 10."
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
if (value === null && (key === "equals" || key === "not_equals")) {
|
|
1665
|
+
hasNull = true;
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
if (value == null) {
|
|
1669
|
+
throw createValidationError(
|
|
1670
|
+
"Collection where must not contain null or undefined values."
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1673
|
+
if (Array.isArray(value)) {
|
|
1674
|
+
if (value.length === 0) {
|
|
1675
|
+
throw createValidationError(
|
|
1676
|
+
"Collection where must not contain empty arrays, including and/or."
|
|
1677
|
+
);
|
|
1678
|
+
}
|
|
1679
|
+
if (value.length > 1e3) {
|
|
1680
|
+
throw createValidationError(
|
|
1681
|
+
"Collection where arrays must not contain more than 1000 elements."
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1684
|
+
for (const item of value) visit(item, depth + 1);
|
|
1685
|
+
} else if (typeof value === "object" && !(value instanceof Date)) {
|
|
1686
|
+
const values = Object.entries(value);
|
|
1687
|
+
if (values.length === 0) {
|
|
1688
|
+
throw createValidationError(
|
|
1689
|
+
"Collection where must not contain empty condition objects."
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
for (const [key2, item] of values) visit(item, depth + 1, key2);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
visit(where, 0);
|
|
1696
|
+
return hasNull;
|
|
1697
|
+
}
|
|
1698
|
+
var HttpClient = class {
|
|
1699
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
1700
|
+
this.publishableKey = requirePublishableKeyForSecret(
|
|
1701
|
+
"CollectionClient",
|
|
1702
|
+
publishableKey,
|
|
1703
|
+
secretKey
|
|
1704
|
+
);
|
|
1705
|
+
this.secretKey = secretKey;
|
|
1706
|
+
this.getCustomerToken = getCustomerToken;
|
|
1707
|
+
this.onUnauthorized = onUnauthorized;
|
|
1708
|
+
this.onRequestId = onRequestId;
|
|
1709
|
+
this.apiUrl = apiUrl;
|
|
1710
|
+
}
|
|
1711
|
+
get defaultOptions() {
|
|
1712
|
+
const opts = {
|
|
1713
|
+
apiUrl: this.apiUrl,
|
|
1714
|
+
publishableKey: this.publishableKey,
|
|
1715
|
+
secretKey: this.secretKey
|
|
1716
|
+
};
|
|
1717
|
+
const token = this.getCustomerToken?.();
|
|
1718
|
+
if (token) {
|
|
1719
|
+
opts.customerToken = token;
|
|
1720
|
+
if (this.onUnauthorized) {
|
|
1721
|
+
opts.onUnauthorized = this.onUnauthorized;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
return opts;
|
|
1725
|
+
}
|
|
1726
|
+
async fetchWithTracking(url, opts) {
|
|
1727
|
+
try {
|
|
1728
|
+
const response = await httpFetch(url, opts);
|
|
1729
|
+
this.onRequestId?.(response.headers.get("x-request-id") ?? null);
|
|
1730
|
+
return response;
|
|
1731
|
+
} catch (err) {
|
|
1732
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1733
|
+
this.onRequestId?.(id);
|
|
1734
|
+
throw err;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
buildUrl(endpoint, options) {
|
|
1738
|
+
if (!options) return endpoint;
|
|
1739
|
+
const { fallbackLocale, ...rest } = options;
|
|
1740
|
+
const queryOptions = fallbackLocale === void 0 ? rest : {
|
|
1741
|
+
...rest,
|
|
1742
|
+
"fallback-locale": fallbackLocale === false ? "none" : fallbackLocale
|
|
1743
|
+
};
|
|
1744
|
+
const encodedOptions = validateWhere(queryOptions.where) ? { ...queryOptions, where: JSON.stringify(queryOptions.where) } : queryOptions;
|
|
1745
|
+
const queryString = stringify(encodedOptions, { addQueryPrefix: true });
|
|
1746
|
+
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
1747
|
+
}
|
|
1748
|
+
assertJsonResponse(response) {
|
|
1749
|
+
const contentType = response.headers.get("content-type");
|
|
1750
|
+
if (!contentType?.includes("application/json")) {
|
|
1751
|
+
throw createApiError("Response is not in JSON format.", response.status, {
|
|
1752
|
+
contentType
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Parse Payload CMS find response (list query)
|
|
1758
|
+
* Returns native Payload response structure
|
|
1759
|
+
*/
|
|
1760
|
+
async parseFindResponse(response) {
|
|
1761
|
+
const contentType = response.headers.get("content-type");
|
|
1762
|
+
try {
|
|
1763
|
+
this.assertJsonResponse(response);
|
|
1764
|
+
const jsonData = await response.json();
|
|
1765
|
+
if (jsonData.docs === void 0) {
|
|
1766
|
+
throw createApiError("Invalid find response.", response.status, {
|
|
1767
|
+
jsonData
|
|
1768
|
+
});
|
|
1769
|
+
}
|
|
1770
|
+
return {
|
|
1771
|
+
docs: jsonData.docs,
|
|
1772
|
+
totalDocs: jsonData.totalDocs ?? 0,
|
|
1773
|
+
limit: jsonData.limit || 20,
|
|
1774
|
+
totalPages: jsonData.totalPages ?? 0,
|
|
1775
|
+
page: jsonData.page || 1,
|
|
1776
|
+
pagingCounter: jsonData.pagingCounter || 1,
|
|
1777
|
+
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
1778
|
+
hasNextPage: jsonData.hasNextPage ?? false,
|
|
1779
|
+
prevPage: jsonData.prevPage ?? null,
|
|
1780
|
+
nextPage: jsonData.nextPage ?? null
|
|
1781
|
+
};
|
|
1782
|
+
} catch (error) {
|
|
1783
|
+
if (error instanceof SDKError) throw error;
|
|
1784
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1785
|
+
contentType,
|
|
1786
|
+
error: error instanceof Error ? error.message : error
|
|
1787
|
+
});
|
|
1772
1788
|
}
|
|
1773
|
-
this.publishableKey = requirePublishableKeyForSecret(
|
|
1774
|
-
apiName,
|
|
1775
|
-
options.publishableKey,
|
|
1776
|
-
options.secretKey
|
|
1777
|
-
);
|
|
1778
|
-
this.secretKey = options.secretKey;
|
|
1779
|
-
this.apiUrl = options.apiUrl;
|
|
1780
|
-
this.customerToken = options.customerToken;
|
|
1781
|
-
this.onUnauthorized = options.onUnauthorized;
|
|
1782
|
-
this.onRequestId = options.onRequestId;
|
|
1783
1789
|
}
|
|
1784
|
-
|
|
1785
|
-
|
|
1790
|
+
/**
|
|
1791
|
+
* Parse Payload CMS mutation response (create/update)
|
|
1792
|
+
* Returns native Payload response structure
|
|
1793
|
+
*/
|
|
1794
|
+
async parseMutationResponse(response) {
|
|
1795
|
+
const contentType = response.headers.get("content-type");
|
|
1786
1796
|
try {
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1797
|
+
this.assertJsonResponse(response);
|
|
1798
|
+
const jsonData = await response.json();
|
|
1799
|
+
if (jsonData.doc === void 0) {
|
|
1800
|
+
throw createApiError("Invalid mutation response.", response.status, {
|
|
1801
|
+
jsonData
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
return {
|
|
1805
|
+
message: jsonData.message || "",
|
|
1806
|
+
doc: jsonData.doc,
|
|
1807
|
+
errors: jsonData.errors
|
|
1808
|
+
};
|
|
1809
|
+
} catch (error) {
|
|
1810
|
+
if (error instanceof SDKError) throw error;
|
|
1811
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1812
|
+
contentType,
|
|
1813
|
+
error: error instanceof Error ? error.message : error
|
|
1799
1814
|
});
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* Parse Payload CMS document response (findById/delete)
|
|
1819
|
+
* Returns document directly without wrapper
|
|
1820
|
+
*/
|
|
1821
|
+
async parseDocumentResponse(response) {
|
|
1822
|
+
const contentType = response.headers.get("content-type");
|
|
1823
|
+
try {
|
|
1824
|
+
this.assertJsonResponse(response);
|
|
1825
|
+
const jsonData = await response.json();
|
|
1826
|
+
return jsonData;
|
|
1827
|
+
} catch (error) {
|
|
1828
|
+
if (error instanceof SDKError) throw error;
|
|
1829
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
1830
|
+
contentType,
|
|
1831
|
+
error: error instanceof Error ? error.message : error
|
|
1803
1832
|
});
|
|
1804
|
-
} catch (err) {
|
|
1805
|
-
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1806
|
-
this.onRequestId?.(id);
|
|
1807
|
-
throw err;
|
|
1808
1833
|
}
|
|
1809
1834
|
}
|
|
1810
1835
|
};
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1836
|
+
|
|
1837
|
+
// src/utils/types.ts
|
|
1838
|
+
function resolveRelation(ref) {
|
|
1839
|
+
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
1840
|
+
return null;
|
|
1841
|
+
return ref;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
// src/core/collection/query-builder.ts
|
|
1845
|
+
var PUBLIC_READ_DEPTH_ERROR = "Publishable collection reads require depth: 0. Use a shaped commerce endpoint or server client for populated data.";
|
|
1846
|
+
var PUBLIC_READ_JOINS_ERROR = "Publishable collection reads require joins: false. Use a shaped commerce endpoint or server client for joined data.";
|
|
1847
|
+
var PUBLIC_READ_POPULATE_ERROR = "Publishable collection reads do not support populate. Use a shaped commerce endpoint or server client for populated data.";
|
|
1848
|
+
function withDefaultPublicReadOptions(options) {
|
|
1849
|
+
const rawOptions = options;
|
|
1850
|
+
if (rawOptions?.depth !== void 0 && rawOptions.depth !== 0) {
|
|
1851
|
+
throw createValidationError(PUBLIC_READ_DEPTH_ERROR);
|
|
1814
1852
|
}
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1853
|
+
if (rawOptions?.joins !== void 0 && rawOptions.joins !== false) {
|
|
1854
|
+
throw createValidationError(PUBLIC_READ_JOINS_ERROR);
|
|
1855
|
+
}
|
|
1856
|
+
if (rawOptions?.populate !== void 0) {
|
|
1857
|
+
throw createValidationError(PUBLIC_READ_POPULATE_ERROR);
|
|
1858
|
+
}
|
|
1859
|
+
return {
|
|
1860
|
+
...options,
|
|
1861
|
+
depth: options?.depth ?? 0,
|
|
1862
|
+
joins: options?.joins ?? false
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
var ReadOnlyCollectionQueryBuilder = class {
|
|
1866
|
+
constructor(api, collection) {
|
|
1867
|
+
this.api = api;
|
|
1868
|
+
this.collection = collection;
|
|
1869
|
+
}
|
|
1870
|
+
async find(options) {
|
|
1871
|
+
return this.api.requestFind(
|
|
1872
|
+
`/api/${String(this.collection)}`,
|
|
1873
|
+
withDefaultPublicReadOptions(options)
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
async findById(id, options) {
|
|
1877
|
+
return this.api.requestFindById(
|
|
1878
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
1879
|
+
withDefaultPublicReadOptions(options)
|
|
1880
|
+
);
|
|
1881
|
+
}
|
|
1882
|
+
async count(options) {
|
|
1883
|
+
return this.api.requestCount(
|
|
1884
|
+
`/api/${String(this.collection)}/count`,
|
|
1885
|
+
withDefaultPublicReadOptions(options)
|
|
1886
|
+
);
|
|
1822
1887
|
}
|
|
1823
1888
|
};
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1889
|
+
|
|
1890
|
+
// src/core/collection/collection-client.ts
|
|
1891
|
+
var ReadOnlyCollectionClient = class extends HttpClient {
|
|
1892
|
+
from(collection) {
|
|
1893
|
+
return new ReadOnlyCollectionQueryBuilder(this, collection);
|
|
1827
1894
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1895
|
+
async requestFind(endpoint, options) {
|
|
1896
|
+
const url = this.buildUrl(endpoint, options);
|
|
1897
|
+
const response = await this.fetchWithTracking(url, {
|
|
1898
|
+
...this.defaultOptions,
|
|
1899
|
+
method: "GET"
|
|
1900
|
+
});
|
|
1901
|
+
return this.parseFindResponse(response);
|
|
1902
|
+
}
|
|
1903
|
+
async requestFindEndpoint(endpoint, data) {
|
|
1904
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1905
|
+
...this.defaultOptions,
|
|
1906
|
+
method: "POST",
|
|
1907
|
+
body: data ? JSON.stringify(data) : void 0
|
|
1908
|
+
});
|
|
1909
|
+
return this.parseFindResponse(response);
|
|
1910
|
+
}
|
|
1911
|
+
async requestFindEndpointGet(endpoint) {
|
|
1912
|
+
const response = await this.fetchWithTracking(endpoint, {
|
|
1913
|
+
...this.defaultOptions,
|
|
1914
|
+
method: "GET"
|
|
1915
|
+
});
|
|
1916
|
+
return this.parseFindResponse(response);
|
|
1917
|
+
}
|
|
1918
|
+
async requestFindById(endpoint, options) {
|
|
1919
|
+
const url = this.buildUrl(endpoint, options);
|
|
1920
|
+
const response = await this.fetchWithTracking(url, {
|
|
1921
|
+
...this.defaultOptions,
|
|
1922
|
+
method: "GET"
|
|
1923
|
+
});
|
|
1924
|
+
return this.parseDocumentResponse(response);
|
|
1925
|
+
}
|
|
1926
|
+
async requestCount(endpoint, options) {
|
|
1927
|
+
const url = this.buildUrl(endpoint, options);
|
|
1928
|
+
const response = await this.fetchWithTracking(url, {
|
|
1929
|
+
...this.defaultOptions,
|
|
1930
|
+
method: "GET"
|
|
1931
|
+
});
|
|
1932
|
+
return this.parseDocumentResponse(response);
|
|
1830
1933
|
}
|
|
1831
1934
|
};
|
|
1832
1935
|
|
|
@@ -3985,19 +4088,24 @@ var CustomerAuth = class {
|
|
|
3985
4088
|
* Register a new customer account
|
|
3986
4089
|
*/
|
|
3987
4090
|
async register(data) {
|
|
3988
|
-
return this.requestJson(
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
4091
|
+
return this.requestJson(
|
|
4092
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.register),
|
|
4093
|
+
{
|
|
4094
|
+
method: resolveOperationMethod(
|
|
4095
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.register
|
|
4096
|
+
),
|
|
4097
|
+
body: JSON.stringify(data)
|
|
4098
|
+
}
|
|
4099
|
+
);
|
|
3992
4100
|
}
|
|
3993
4101
|
/**
|
|
3994
4102
|
* Login with email and password. Stores the token internally.
|
|
3995
4103
|
*/
|
|
3996
4104
|
async login(data) {
|
|
3997
4105
|
const result = await this.requestJson(
|
|
3998
|
-
|
|
4106
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.login),
|
|
3999
4107
|
{
|
|
4000
|
-
method:
|
|
4108
|
+
method: resolveOperationMethod(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.login),
|
|
4001
4109
|
body: JSON.stringify(data)
|
|
4002
4110
|
}
|
|
4003
4111
|
);
|
|
@@ -4243,14 +4351,18 @@ var CustomerAuth = class {
|
|
|
4243
4351
|
}
|
|
4244
4352
|
async _doRefreshToken(intended) {
|
|
4245
4353
|
const init = intended.refreshToken ? {
|
|
4246
|
-
method:
|
|
4354
|
+
method: resolveOperationMethod(
|
|
4355
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.refresh
|
|
4356
|
+
),
|
|
4247
4357
|
body: JSON.stringify({ refreshToken: intended.refreshToken })
|
|
4248
4358
|
} : {
|
|
4249
|
-
method:
|
|
4359
|
+
method: resolveOperationMethod(
|
|
4360
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.refresh
|
|
4361
|
+
),
|
|
4250
4362
|
headers: { Authorization: `Bearer ${intended.token}` }
|
|
4251
4363
|
};
|
|
4252
4364
|
const result = await this.requestJson(
|
|
4253
|
-
|
|
4365
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.refresh),
|
|
4254
4366
|
init
|
|
4255
4367
|
);
|
|
4256
4368
|
const state = this.classifyCanonicalState(intended);
|
|
@@ -4319,9 +4431,9 @@ var CustomerAuth = class {
|
|
|
4319
4431
|
if (!token) return null;
|
|
4320
4432
|
try {
|
|
4321
4433
|
const data = await this.requestJson(
|
|
4322
|
-
|
|
4434
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.me),
|
|
4323
4435
|
{
|
|
4324
|
-
method:
|
|
4436
|
+
method: resolveOperationMethod(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.me),
|
|
4325
4437
|
headers: { Authorization: `Bearer ${token}` }
|
|
4326
4438
|
}
|
|
4327
4439
|
);
|
|
@@ -4338,19 +4450,29 @@ var CustomerAuth = class {
|
|
|
4338
4450
|
* Request a password reset email
|
|
4339
4451
|
*/
|
|
4340
4452
|
async forgotPassword(email) {
|
|
4341
|
-
await this.requestJson(
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4453
|
+
await this.requestJson(
|
|
4454
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.forgotPassword),
|
|
4455
|
+
{
|
|
4456
|
+
method: resolveOperationMethod(
|
|
4457
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.forgotPassword
|
|
4458
|
+
),
|
|
4459
|
+
body: JSON.stringify({ email })
|
|
4460
|
+
}
|
|
4461
|
+
);
|
|
4345
4462
|
}
|
|
4346
4463
|
/**
|
|
4347
4464
|
* Reset password using a token from the reset email
|
|
4348
4465
|
*/
|
|
4349
4466
|
async resetPassword(token, password) {
|
|
4350
|
-
await this.requestJson(
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4467
|
+
await this.requestJson(
|
|
4468
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.resetPassword),
|
|
4469
|
+
{
|
|
4470
|
+
method: resolveOperationMethod(
|
|
4471
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.resetPassword
|
|
4472
|
+
),
|
|
4473
|
+
body: JSON.stringify({ token, password })
|
|
4474
|
+
}
|
|
4475
|
+
);
|
|
4354
4476
|
}
|
|
4355
4477
|
/**
|
|
4356
4478
|
* Update the authenticated customer's profile (name, phone, marketingConsent)
|
|
@@ -4359,9 +4481,11 @@ var CustomerAuth = class {
|
|
|
4359
4481
|
const token = this.getToken();
|
|
4360
4482
|
if (!token) throw new ApiError("Not authenticated", 401);
|
|
4361
4483
|
const result = await this.requestJson(
|
|
4362
|
-
|
|
4484
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.updateProfile),
|
|
4363
4485
|
{
|
|
4364
|
-
method:
|
|
4486
|
+
method: resolveOperationMethod(
|
|
4487
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.updateProfile
|
|
4488
|
+
),
|
|
4365
4489
|
headers: { Authorization: `Bearer ${token}` },
|
|
4366
4490
|
body: JSON.stringify(data)
|
|
4367
4491
|
}
|
|
@@ -4374,11 +4498,16 @@ var CustomerAuth = class {
|
|
|
4374
4498
|
async changePassword(currentPassword, newPassword) {
|
|
4375
4499
|
const token = this.getToken();
|
|
4376
4500
|
if (!token) throw new ApiError("Not authenticated", 401);
|
|
4377
|
-
await this.requestJson(
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4501
|
+
await this.requestJson(
|
|
4502
|
+
resolveOperationPath(CUSTOMER_AUTH_ENDPOINT_OPERATIONS.changePassword),
|
|
4503
|
+
{
|
|
4504
|
+
method: resolveOperationMethod(
|
|
4505
|
+
CUSTOMER_AUTH_ENDPOINT_OPERATIONS.changePassword
|
|
4506
|
+
),
|
|
4507
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
4508
|
+
body: JSON.stringify({ currentPassword, newPassword })
|
|
4509
|
+
}
|
|
4510
|
+
);
|
|
4382
4511
|
}
|
|
4383
4512
|
/**
|
|
4384
4513
|
* Get the authenticated customer's orders with pagination and optional status filter
|
|
@@ -6896,6 +7025,18 @@ var EventsClient = class {
|
|
|
6896
7025
|
{ useCustomerAuth: false }
|
|
6897
7026
|
);
|
|
6898
7027
|
}
|
|
7028
|
+
listMyRegistrations(params = {}) {
|
|
7029
|
+
const query = new URLSearchParams();
|
|
7030
|
+
if (params.page !== void 0) query.set("page", String(params.page));
|
|
7031
|
+
if (params.limit !== void 0) query.set("limit", String(params.limit));
|
|
7032
|
+
const operation2 = EVENTS_ENDPOINT_OPERATIONS.registrations.listMine;
|
|
7033
|
+
return this.execute(
|
|
7034
|
+
resolveOperationPath(operation2, { query }),
|
|
7035
|
+
resolveOperationMethod(operation2),
|
|
7036
|
+
void 0,
|
|
7037
|
+
{ useCustomerAuth: true, noStore: true }
|
|
7038
|
+
);
|
|
7039
|
+
}
|
|
6899
7040
|
register(params) {
|
|
6900
7041
|
return this.execute(
|
|
6901
7042
|
"/api/event-registrations/register",
|
|
@@ -6926,6 +7067,7 @@ var EventsClient = class {
|
|
|
6926
7067
|
try {
|
|
6927
7068
|
const response = await httpFetch(endpoint, {
|
|
6928
7069
|
method,
|
|
7070
|
+
...options.noStore && { cache: "no-store" },
|
|
6929
7071
|
apiUrl: this.apiUrl,
|
|
6930
7072
|
publishableKey: this.publishableKey,
|
|
6931
7073
|
...useCustomerAuth && token ? { customerToken: token } : {},
|
|
@@ -7118,6 +7260,16 @@ var Client = class _Client {
|
|
|
7118
7260
|
this.markets = new MarketDiscovery(
|
|
7119
7261
|
(options2) => this.collections.from("markets").find(options2)
|
|
7120
7262
|
);
|
|
7263
|
+
this.benefitVouchers = new CustomerBenefitVouchersApi(
|
|
7264
|
+
"CustomerBenefitVouchersApi",
|
|
7265
|
+
{
|
|
7266
|
+
publishableKey: this.config.publishableKey,
|
|
7267
|
+
apiUrl: this.config.apiUrl,
|
|
7268
|
+
customerToken: () => this.customer.auth.getToken(),
|
|
7269
|
+
onUnauthorized,
|
|
7270
|
+
onRequestId
|
|
7271
|
+
}
|
|
7272
|
+
);
|
|
7121
7273
|
const membershipApi = new BrowserMembershipApi("MembershipApi", {
|
|
7122
7274
|
publishableKey: this.config.publishableKey,
|
|
7123
7275
|
apiUrl: this.config.apiUrl,
|
|
@@ -7497,6 +7649,7 @@ function createTypedWebhookHandler(collection, handler) {
|
|
|
7497
7649
|
|
|
7498
7650
|
// src/core/collection/const.ts
|
|
7499
7651
|
var INTERNAL_COLLECTIONS = [
|
|
7652
|
+
"benefit-voucher-definitions",
|
|
7500
7653
|
"users",
|
|
7501
7654
|
"payload-kv",
|
|
7502
7655
|
"payload-locked-documents",
|
|
@@ -7512,6 +7665,7 @@ var INTERNAL_COLLECTIONS = [
|
|
|
7512
7665
|
"tenant-mcp-usage-daily",
|
|
7513
7666
|
"subscriptions",
|
|
7514
7667
|
"billing-history",
|
|
7668
|
+
"billing-consent-receipts",
|
|
7515
7669
|
"usage-rate-cards",
|
|
7516
7670
|
"usage-invoices",
|
|
7517
7671
|
"inventory-reservations",
|