@xylex-group/athena 2.9.0 → 2.11.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/README.md +112 -28
- package/dist/browser.cjs +865 -74
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +3 -3
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +862 -75
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +785 -40
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +785 -40
- package/dist/cli/index.js.map +1 -1
- package/dist/{client-D6EIJdQS.d.ts → client-DD_UeF3Q.d.ts} +508 -22
- package/dist/{client-CfAE_QOj.d.cts → client-WqBuu60O.d.cts} +508 -22
- package/dist/index.cjs +865 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +862 -75
- package/dist/index.js.map +1 -1
- package/dist/{react-email-BvJ3fj_F.d.cts → module-BFMyVmwX.d.cts} +97 -2
- package/dist/{react-email-PLAJuZuO.d.ts → module-DRkIHtY-.d.ts} +97 -2
- package/dist/next/client.cjs +793 -40
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.cts +3 -4
- package/dist/next/client.d.ts +3 -4
- package/dist/next/client.js +793 -40
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +793 -40
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.d.cts +2 -2
- package/dist/next/server.d.ts +2 -2
- package/dist/next/server.js +793 -40
- package/dist/next/server.js.map +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -3
- package/dist/react.d.ts +2 -3
- package/dist/react.js +1 -1
- package/dist/react.js.map +1 -1
- package/dist/{shared-BW6hoLBY.d.cts → shared-B1ueL-Ox.d.cts} +3 -1
- package/dist/{shared-BiJvoURI.d.ts → shared-GPAprhBb.d.ts} +3 -1
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -1978,8 +1978,8 @@ function parseCookies(cookieHeader) {
|
|
|
1978
1978
|
});
|
|
1979
1979
|
return cookieMap;
|
|
1980
1980
|
}
|
|
1981
|
-
var getSessionCookie = (
|
|
1982
|
-
const cookies = (
|
|
1981
|
+
var getSessionCookie = (request2, config) => {
|
|
1982
|
+
const cookies = (request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers).get("cookie");
|
|
1983
1983
|
if (!cookies) {
|
|
1984
1984
|
return null;
|
|
1985
1985
|
}
|
|
@@ -2002,7 +2002,7 @@ var getSessionCookie = (request, config) => {
|
|
|
2002
2002
|
|
|
2003
2003
|
// package.json
|
|
2004
2004
|
var package_default = {
|
|
2005
|
-
version: "2.
|
|
2005
|
+
version: "2.11.0"
|
|
2006
2006
|
};
|
|
2007
2007
|
|
|
2008
2008
|
// src/sdk-version.ts
|
|
@@ -2983,6 +2983,87 @@ function mergeCallOptions(base, override) {
|
|
|
2983
2983
|
}
|
|
2984
2984
|
};
|
|
2985
2985
|
}
|
|
2986
|
+
function copyDefinedField(target, source, targetKey, sourceKey) {
|
|
2987
|
+
if (!(sourceKey in source)) {
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
const value = source[sourceKey];
|
|
2991
|
+
if (value !== void 0) {
|
|
2992
|
+
target[targetKey] = value;
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
function normalizeEmailTemplateAttachmentsValue(value) {
|
|
2996
|
+
if (typeof value === "string" || value == null) {
|
|
2997
|
+
return value;
|
|
2998
|
+
}
|
|
2999
|
+
if (Array.isArray(value)) {
|
|
3000
|
+
return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
|
|
3001
|
+
}
|
|
3002
|
+
if (typeof value !== "object") {
|
|
3003
|
+
return value;
|
|
3004
|
+
}
|
|
3005
|
+
const attachment = { ...value };
|
|
3006
|
+
copyDefinedField(attachment, attachment, "file_url", "fileUrl");
|
|
3007
|
+
delete attachment.fileUrl;
|
|
3008
|
+
return attachment;
|
|
3009
|
+
}
|
|
3010
|
+
function normalizeAdminEmailTemplatePayload(payload) {
|
|
3011
|
+
const normalized = { ...payload };
|
|
3012
|
+
copyDefinedField(normalized, payload, "template_key", "templateKey");
|
|
3013
|
+
copyDefinedField(normalized, payload, "event_type", "eventType");
|
|
3014
|
+
copyDefinedField(normalized, payload, "subject_template", "subjectTemplate");
|
|
3015
|
+
copyDefinedField(normalized, payload, "text_template", "textTemplate");
|
|
3016
|
+
copyDefinedField(normalized, payload, "html_template", "htmlTemplate");
|
|
3017
|
+
copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
|
|
3018
|
+
copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
|
|
3019
|
+
copyDefinedField(normalized, payload, "is_active", "isActive");
|
|
3020
|
+
if (Object.hasOwn(payload, "attachments")) {
|
|
3021
|
+
normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
|
|
3022
|
+
}
|
|
3023
|
+
delete normalized.templateKey;
|
|
3024
|
+
delete normalized.eventType;
|
|
3025
|
+
delete normalized.subjectTemplate;
|
|
3026
|
+
delete normalized.textTemplate;
|
|
3027
|
+
delete normalized.htmlTemplate;
|
|
3028
|
+
delete normalized.variableBindings;
|
|
3029
|
+
delete normalized.attachmentFailureMode;
|
|
3030
|
+
delete normalized.isActive;
|
|
3031
|
+
return normalized;
|
|
3032
|
+
}
|
|
3033
|
+
function toReactEmailTemplateCompatibilityInput(input) {
|
|
3034
|
+
const payload = input;
|
|
3035
|
+
const compatibility = { ...payload };
|
|
3036
|
+
copyDefinedField(compatibility, payload, "templateKey", "template_key");
|
|
3037
|
+
copyDefinedField(compatibility, payload, "eventType", "event_type");
|
|
3038
|
+
copyDefinedField(compatibility, payload, "subjectTemplate", "subject_template");
|
|
3039
|
+
copyDefinedField(compatibility, payload, "textTemplate", "text_template");
|
|
3040
|
+
copyDefinedField(compatibility, payload, "htmlTemplate", "html_template");
|
|
3041
|
+
copyDefinedField(compatibility, payload, "variableBindings", "variable_bindings");
|
|
3042
|
+
copyDefinedField(compatibility, payload, "attachmentFailureMode", "attachment_failure_mode");
|
|
3043
|
+
copyDefinedField(compatibility, payload, "isActive", "is_active");
|
|
3044
|
+
return compatibility;
|
|
3045
|
+
}
|
|
3046
|
+
function normalizeAdminEmailTemplateSendPayload(payload) {
|
|
3047
|
+
const normalized = { ...payload };
|
|
3048
|
+
copyDefinedField(normalized, payload, "template_id", "templateId");
|
|
3049
|
+
copyDefinedField(normalized, payload, "recipient_email", "recipientEmail");
|
|
3050
|
+
copyDefinedField(normalized, payload, "render_variables", "renderVariables");
|
|
3051
|
+
copyDefinedField(normalized, payload, "user_id", "userId");
|
|
3052
|
+
copyDefinedField(normalized, payload, "organization_id", "organizationId");
|
|
3053
|
+
copyDefinedField(normalized, payload, "session_token", "sessionToken");
|
|
3054
|
+
copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
|
|
3055
|
+
if (Object.hasOwn(payload, "attachments")) {
|
|
3056
|
+
normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
|
|
3057
|
+
}
|
|
3058
|
+
delete normalized.templateId;
|
|
3059
|
+
delete normalized.recipientEmail;
|
|
3060
|
+
delete normalized.renderVariables;
|
|
3061
|
+
delete normalized.userId;
|
|
3062
|
+
delete normalized.organizationId;
|
|
3063
|
+
delete normalized.sessionToken;
|
|
3064
|
+
delete normalized.attachmentFailureMode;
|
|
3065
|
+
return normalized;
|
|
3066
|
+
}
|
|
2986
3067
|
function toSessionGuardFailure(sessionResult) {
|
|
2987
3068
|
if (sessionResult.status === 401 || sessionResult.data == null) {
|
|
2988
3069
|
return {
|
|
@@ -3289,7 +3370,7 @@ function createAuthClient(config = {}) {
|
|
|
3289
3370
|
...config,
|
|
3290
3371
|
baseUrl: normalizedBaseUrl
|
|
3291
3372
|
};
|
|
3292
|
-
const
|
|
3373
|
+
const request2 = (input, options) => {
|
|
3293
3374
|
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
3294
3375
|
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
3295
3376
|
return callAuthEndpoint(
|
|
@@ -3302,7 +3383,7 @@ function createAuthClient(config = {}) {
|
|
|
3302
3383
|
};
|
|
3303
3384
|
const postGeneric = (endpoint, input, options) => {
|
|
3304
3385
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3305
|
-
return
|
|
3386
|
+
return request2(
|
|
3306
3387
|
{
|
|
3307
3388
|
endpoint,
|
|
3308
3389
|
method: "POST",
|
|
@@ -3314,7 +3395,7 @@ function createAuthClient(config = {}) {
|
|
|
3314
3395
|
};
|
|
3315
3396
|
const getGeneric = (endpoint, input, options) => {
|
|
3316
3397
|
const { fetchOptions } = extractFetchOptions(input);
|
|
3317
|
-
return
|
|
3398
|
+
return request2(
|
|
3318
3399
|
{
|
|
3319
3400
|
endpoint,
|
|
3320
3401
|
method: "GET",
|
|
@@ -3326,7 +3407,7 @@ function createAuthClient(config = {}) {
|
|
|
3326
3407
|
const getWithQuery = (endpoint, input, options) => {
|
|
3327
3408
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3328
3409
|
const query = payload?.query;
|
|
3329
|
-
return
|
|
3410
|
+
return request2(
|
|
3330
3411
|
{
|
|
3331
3412
|
endpoint,
|
|
3332
3413
|
method: "GET",
|
|
@@ -3344,18 +3425,19 @@ function createAuthClient(config = {}) {
|
|
|
3344
3425
|
htmlField: "htmlBody",
|
|
3345
3426
|
textField: "textBody"
|
|
3346
3427
|
}, withReactEmailRoute(route));
|
|
3347
|
-
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(input, {
|
|
3428
|
+
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(toReactEmailTemplateCompatibilityInput(input), {
|
|
3348
3429
|
htmlField: "htmlTemplate",
|
|
3349
3430
|
textField: "textTemplate",
|
|
3350
3431
|
variablesField: "variables"
|
|
3351
3432
|
}, withReactEmailRoute(route)).then((payload) => {
|
|
3433
|
+
const normalizedPayload = normalizeAdminEmailTemplatePayload(payload);
|
|
3352
3434
|
if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
|
|
3353
3435
|
assertAthenaAuthTemplateVariables(
|
|
3354
3436
|
payload.variables,
|
|
3355
3437
|
`${route} variables`
|
|
3356
3438
|
);
|
|
3357
3439
|
}
|
|
3358
|
-
return
|
|
3440
|
+
return normalizedPayload;
|
|
3359
3441
|
});
|
|
3360
3442
|
const requireSession = async (input, options) => {
|
|
3361
3443
|
const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
|
|
@@ -3931,7 +4013,15 @@ function createAuthClient(config = {}) {
|
|
|
3931
4013
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
3932
4014
|
options
|
|
3933
4015
|
),
|
|
3934
|
-
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
|
|
4016
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
|
|
4017
|
+
send: (input, options) => postGeneric(
|
|
4018
|
+
"/admin/email-template/send",
|
|
4019
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
4020
|
+
options
|
|
4021
|
+
)
|
|
4022
|
+
},
|
|
4023
|
+
eventType: {
|
|
4024
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
3935
4025
|
}
|
|
3936
4026
|
},
|
|
3937
4027
|
emailTemplate: {
|
|
@@ -3947,7 +4037,15 @@ function createAuthClient(config = {}) {
|
|
|
3947
4037
|
"/admin/email-template/update",
|
|
3948
4038
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
3949
4039
|
options
|
|
4040
|
+
),
|
|
4041
|
+
send: (input, options) => postGeneric(
|
|
4042
|
+
"/admin/email-template/send",
|
|
4043
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
4044
|
+
options
|
|
3950
4045
|
)
|
|
4046
|
+
},
|
|
4047
|
+
emailEventType: {
|
|
4048
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
3951
4049
|
}
|
|
3952
4050
|
},
|
|
3953
4051
|
apiKey: {
|
|
@@ -3987,7 +4085,7 @@ function createAuthClient(config = {}) {
|
|
|
3987
4085
|
throw new Error("callback.provider requires non-empty code and state values");
|
|
3988
4086
|
}
|
|
3989
4087
|
const endpoint = `/callback/${encodeURIComponent(provider)}`;
|
|
3990
|
-
return
|
|
4088
|
+
return request2({
|
|
3991
4089
|
endpoint,
|
|
3992
4090
|
method: "GET",
|
|
3993
4091
|
query: {
|
|
@@ -4001,7 +4099,7 @@ function createAuthClient(config = {}) {
|
|
|
4001
4099
|
};
|
|
4002
4100
|
return {
|
|
4003
4101
|
baseUrl: normalizedBaseUrl,
|
|
4004
|
-
request,
|
|
4102
|
+
request: request2,
|
|
4005
4103
|
signIn: {
|
|
4006
4104
|
email: (input, options) => executePostWithCompatibleInput(
|
|
4007
4105
|
resolvedConfig,
|
|
@@ -4203,16 +4301,16 @@ function createStorageFileModule(base, config = {}) {
|
|
|
4203
4301
|
};
|
|
4204
4302
|
});
|
|
4205
4303
|
input.onProgress?.(createProgressSnapshot("preparing", sources, 0, 0, 0));
|
|
4206
|
-
const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((
|
|
4304
|
+
const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request2) => request2.uploadRequest) }, options)).files;
|
|
4207
4305
|
const aggregateLoaded = new Array(uploadRequests.length).fill(0);
|
|
4208
4306
|
const uploaded = [];
|
|
4209
4307
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
4210
|
-
const
|
|
4308
|
+
const request2 = uploadRequests[index];
|
|
4211
4309
|
const uploadUrl = uploadUrls[index];
|
|
4212
4310
|
const response = await putUploadBody(
|
|
4213
4311
|
uploadUrl.upload.url,
|
|
4214
4312
|
uploadUrl.upload.headers ?? {},
|
|
4215
|
-
|
|
4313
|
+
request2.source,
|
|
4216
4314
|
input,
|
|
4217
4315
|
options,
|
|
4218
4316
|
(progress) => {
|
|
@@ -4223,13 +4321,13 @@ function createStorageFileModule(base, config = {}) {
|
|
|
4223
4321
|
uploaded.push({
|
|
4224
4322
|
file: uploadUrl.file,
|
|
4225
4323
|
upload: uploadUrl.upload,
|
|
4226
|
-
source:
|
|
4227
|
-
fileName:
|
|
4228
|
-
storage_key:
|
|
4324
|
+
source: request2.source.source,
|
|
4325
|
+
fileName: request2.source.fileName,
|
|
4326
|
+
storage_key: request2.uploadRequest.storage_key,
|
|
4229
4327
|
response
|
|
4230
4328
|
});
|
|
4231
|
-
aggregateLoaded[index] =
|
|
4232
|
-
input.onProgress?.(createProgressSnapshot("complete", sources, index,
|
|
4329
|
+
aggregateLoaded[index] = request2.source.sizeBytes;
|
|
4330
|
+
input.onProgress?.(createProgressSnapshot("complete", sources, index, request2.source.sizeBytes, sum(aggregateLoaded)));
|
|
4233
4331
|
}
|
|
4234
4332
|
return {
|
|
4235
4333
|
files: uploaded,
|
|
@@ -6190,6 +6288,484 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6190
6288
|
};
|
|
6191
6289
|
}
|
|
6192
6290
|
|
|
6291
|
+
// src/chat/module.ts
|
|
6292
|
+
var SDK_NAME3 = "xylex-group/athena-chat";
|
|
6293
|
+
var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
|
|
6294
|
+
var NO_CACHE_HEADER_VALUE3 = "no-cache";
|
|
6295
|
+
var AthenaChatError = class extends Error {
|
|
6296
|
+
status;
|
|
6297
|
+
endpoint;
|
|
6298
|
+
method;
|
|
6299
|
+
requestId;
|
|
6300
|
+
body;
|
|
6301
|
+
constructor(input) {
|
|
6302
|
+
super(input.message);
|
|
6303
|
+
this.name = "AthenaChatError";
|
|
6304
|
+
this.status = input.status;
|
|
6305
|
+
this.endpoint = input.endpoint;
|
|
6306
|
+
this.method = input.method;
|
|
6307
|
+
this.requestId = input.requestId;
|
|
6308
|
+
this.body = input.body;
|
|
6309
|
+
}
|
|
6310
|
+
};
|
|
6311
|
+
function deriveRealtimeInfoUrl(wsUrl) {
|
|
6312
|
+
if (!wsUrl) {
|
|
6313
|
+
return void 0;
|
|
6314
|
+
}
|
|
6315
|
+
const parsed = new URL(normalizeWsUrl(wsUrl, "Athena chat WebSocket URL"));
|
|
6316
|
+
parsed.protocol = parsed.protocol === "wss:" ? "https:" : "http:";
|
|
6317
|
+
parsed.pathname = parsed.pathname.replace(/\/wss\/gateway$/, "/wss/info");
|
|
6318
|
+
return parsed.toString();
|
|
6319
|
+
}
|
|
6320
|
+
function normalizeWsUrl(value, label) {
|
|
6321
|
+
const normalized = value.trim();
|
|
6322
|
+
if (!normalized) {
|
|
6323
|
+
throw new Error(`${label} is required.`);
|
|
6324
|
+
}
|
|
6325
|
+
let parsed;
|
|
6326
|
+
try {
|
|
6327
|
+
parsed = new URL(normalized);
|
|
6328
|
+
} catch {
|
|
6329
|
+
throw new Error(`${label} must be a valid absolute ws(s) URL.`);
|
|
6330
|
+
}
|
|
6331
|
+
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
|
|
6332
|
+
throw new Error(`${label} must use ws or wss.`);
|
|
6333
|
+
}
|
|
6334
|
+
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
6335
|
+
return parsed.toString().replace(/\/$/, "");
|
|
6336
|
+
}
|
|
6337
|
+
function isRecord7(value) {
|
|
6338
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6339
|
+
}
|
|
6340
|
+
function normalizeHeaderValue3(value) {
|
|
6341
|
+
return value ? value : void 0;
|
|
6342
|
+
}
|
|
6343
|
+
function parseResponseBody4(rawText, contentType) {
|
|
6344
|
+
if (!rawText) {
|
|
6345
|
+
return { parsed: null, parseFailed: false };
|
|
6346
|
+
}
|
|
6347
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
6348
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
6349
|
+
if (!looksJson) {
|
|
6350
|
+
return { parsed: rawText, parseFailed: false };
|
|
6351
|
+
}
|
|
6352
|
+
try {
|
|
6353
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
6354
|
+
} catch {
|
|
6355
|
+
return { parsed: rawText, parseFailed: true };
|
|
6356
|
+
}
|
|
6357
|
+
}
|
|
6358
|
+
function resolveRequestId3(headers) {
|
|
6359
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
6360
|
+
}
|
|
6361
|
+
function resolveErrorMessage4(payload, fallback) {
|
|
6362
|
+
if (isRecord7(payload)) {
|
|
6363
|
+
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
6364
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
6365
|
+
return candidate.trim();
|
|
6366
|
+
}
|
|
6367
|
+
}
|
|
6368
|
+
}
|
|
6369
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
6370
|
+
return payload.trim();
|
|
6371
|
+
}
|
|
6372
|
+
return fallback;
|
|
6373
|
+
}
|
|
6374
|
+
function encodePathSegment(value, label) {
|
|
6375
|
+
const normalized = value.trim();
|
|
6376
|
+
if (!normalized) {
|
|
6377
|
+
throw new Error(`${label} is required.`);
|
|
6378
|
+
}
|
|
6379
|
+
return encodeURIComponent(normalized);
|
|
6380
|
+
}
|
|
6381
|
+
function encodeQuery(query) {
|
|
6382
|
+
if (!query) {
|
|
6383
|
+
return "";
|
|
6384
|
+
}
|
|
6385
|
+
const params = new URLSearchParams();
|
|
6386
|
+
for (const [key, value] of Object.entries(query)) {
|
|
6387
|
+
if (value === void 0 || value === null) {
|
|
6388
|
+
continue;
|
|
6389
|
+
}
|
|
6390
|
+
if (Array.isArray(value)) {
|
|
6391
|
+
for (const item of value) {
|
|
6392
|
+
if (item !== void 0 && item !== null) {
|
|
6393
|
+
params.append(key, String(item));
|
|
6394
|
+
}
|
|
6395
|
+
}
|
|
6396
|
+
continue;
|
|
6397
|
+
}
|
|
6398
|
+
params.set(key, String(value));
|
|
6399
|
+
}
|
|
6400
|
+
const encoded = params.toString();
|
|
6401
|
+
return encoded ? `?${encoded}` : "";
|
|
6402
|
+
}
|
|
6403
|
+
function createSocket(factory, url, protocols) {
|
|
6404
|
+
try {
|
|
6405
|
+
return new factory(url, protocols);
|
|
6406
|
+
} catch (error) {
|
|
6407
|
+
if (error instanceof TypeError) {
|
|
6408
|
+
return factory(url, protocols);
|
|
6409
|
+
}
|
|
6410
|
+
throw error;
|
|
6411
|
+
}
|
|
6412
|
+
}
|
|
6413
|
+
function buildHeaders3(config, options) {
|
|
6414
|
+
const headers = {
|
|
6415
|
+
Accept: "application/json",
|
|
6416
|
+
apikey: config.apiKey,
|
|
6417
|
+
"x-api-key": config.apiKey,
|
|
6418
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE3
|
|
6419
|
+
};
|
|
6420
|
+
if (config.client || options?.client) {
|
|
6421
|
+
headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
|
|
6422
|
+
}
|
|
6423
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
6424
|
+
if (typeof bearerToken === "string" && bearerToken.trim()) {
|
|
6425
|
+
headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
|
|
6426
|
+
}
|
|
6427
|
+
const cookie = options?.cookie ?? config.cookie;
|
|
6428
|
+
if (typeof cookie === "string" && cookie.trim()) {
|
|
6429
|
+
headers.Cookie = cookie;
|
|
6430
|
+
}
|
|
6431
|
+
const sessionToken = options?.sessionToken ?? config.sessionToken;
|
|
6432
|
+
if (typeof sessionToken === "string" && sessionToken.trim()) {
|
|
6433
|
+
headers["X-Athena-Auth-Session-Token"] = sessionToken;
|
|
6434
|
+
}
|
|
6435
|
+
if (config.forceNoCache || options?.forceNoCache) {
|
|
6436
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
|
|
6437
|
+
}
|
|
6438
|
+
for (const source of [config.headers, options?.headers]) {
|
|
6439
|
+
for (const [key, value] of Object.entries(source ?? {})) {
|
|
6440
|
+
const normalized = normalizeHeaderValue3(value);
|
|
6441
|
+
if (normalized) {
|
|
6442
|
+
headers[key] = normalized;
|
|
6443
|
+
}
|
|
6444
|
+
}
|
|
6445
|
+
}
|
|
6446
|
+
return headers;
|
|
6447
|
+
}
|
|
6448
|
+
function withJsonBody(init, body) {
|
|
6449
|
+
return {
|
|
6450
|
+
...init,
|
|
6451
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
6452
|
+
headers: {
|
|
6453
|
+
"Content-Type": "application/json",
|
|
6454
|
+
...init.headers
|
|
6455
|
+
}
|
|
6456
|
+
};
|
|
6457
|
+
}
|
|
6458
|
+
async function request(config, method, endpoint, options, body) {
|
|
6459
|
+
if (!config.baseUrl) {
|
|
6460
|
+
throw new Error(
|
|
6461
|
+
"Athena chat base URL is not configured. Pass createClient({ url }) for unified routing or set chat.url / chatUrl explicitly."
|
|
6462
|
+
);
|
|
6463
|
+
}
|
|
6464
|
+
const url = `${config.baseUrl}${endpoint}`;
|
|
6465
|
+
const init = {
|
|
6466
|
+
method,
|
|
6467
|
+
headers: buildHeaders3(config, options),
|
|
6468
|
+
signal: options?.signal
|
|
6469
|
+
};
|
|
6470
|
+
const finalInit = body === void 0 || method === "GET" ? init : withJsonBody(init, body);
|
|
6471
|
+
const response = await fetch(url, finalInit);
|
|
6472
|
+
const rawText = await response.text();
|
|
6473
|
+
const { parsed } = parseResponseBody4(rawText, response.headers.get("content-type"));
|
|
6474
|
+
if (!response.ok) {
|
|
6475
|
+
throw new AthenaChatError({
|
|
6476
|
+
message: resolveErrorMessage4(parsed, `Athena chat ${method} ${endpoint} failed with ${response.status}`),
|
|
6477
|
+
status: response.status,
|
|
6478
|
+
endpoint,
|
|
6479
|
+
method,
|
|
6480
|
+
requestId: resolveRequestId3(response.headers),
|
|
6481
|
+
body: parsed
|
|
6482
|
+
});
|
|
6483
|
+
}
|
|
6484
|
+
return parsed;
|
|
6485
|
+
}
|
|
6486
|
+
function createRealtimeConnection(config, options) {
|
|
6487
|
+
if (!config.wsUrl) {
|
|
6488
|
+
throw new Error(
|
|
6489
|
+
"Athena chat WebSocket URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
6490
|
+
);
|
|
6491
|
+
}
|
|
6492
|
+
const wsFactory = config.webSocketFactory ?? globalThis.WebSocket;
|
|
6493
|
+
if (!wsFactory) {
|
|
6494
|
+
throw new Error(
|
|
6495
|
+
"No WebSocket implementation is available. Provide chat.webSocketFactory in createClient(...) or run in a runtime with global WebSocket support."
|
|
6496
|
+
);
|
|
6497
|
+
}
|
|
6498
|
+
const socket = createSocket(wsFactory, config.wsUrl, options?.protocols);
|
|
6499
|
+
const send = (command) => {
|
|
6500
|
+
socket.send(JSON.stringify(command));
|
|
6501
|
+
};
|
|
6502
|
+
if (options?.onMessage) {
|
|
6503
|
+
const listener = (event) => {
|
|
6504
|
+
const messageEvent = event;
|
|
6505
|
+
const raw = messageEvent?.data;
|
|
6506
|
+
if (typeof raw !== "string") {
|
|
6507
|
+
return;
|
|
6508
|
+
}
|
|
6509
|
+
try {
|
|
6510
|
+
options.onMessage?.(JSON.parse(raw));
|
|
6511
|
+
} catch {
|
|
6512
|
+
options.onMessage?.({ type: "error", error: "Invalid JSON message from Athena chat realtime gateway." });
|
|
6513
|
+
}
|
|
6514
|
+
};
|
|
6515
|
+
if (typeof socket.addEventListener === "function") {
|
|
6516
|
+
socket.addEventListener("message", listener);
|
|
6517
|
+
} else {
|
|
6518
|
+
socket.onmessage = listener;
|
|
6519
|
+
}
|
|
6520
|
+
}
|
|
6521
|
+
const hello = (command) => {
|
|
6522
|
+
send({
|
|
6523
|
+
type: "auth.hello",
|
|
6524
|
+
token: command?.token,
|
|
6525
|
+
room_subscriptions: command?.room_subscriptions
|
|
6526
|
+
});
|
|
6527
|
+
};
|
|
6528
|
+
if (options?.hello) {
|
|
6529
|
+
const onOpen = () => hello({
|
|
6530
|
+
token: options.hello?.token ?? void 0,
|
|
6531
|
+
room_subscriptions: options.hello?.room_subscriptions ?? void 0
|
|
6532
|
+
});
|
|
6533
|
+
if (typeof socket.addEventListener === "function") {
|
|
6534
|
+
socket.addEventListener("open", onOpen);
|
|
6535
|
+
} else {
|
|
6536
|
+
socket.onopen = onOpen;
|
|
6537
|
+
}
|
|
6538
|
+
}
|
|
6539
|
+
return {
|
|
6540
|
+
socket,
|
|
6541
|
+
send,
|
|
6542
|
+
hello,
|
|
6543
|
+
subscribe(roomId, fromSeq) {
|
|
6544
|
+
send({
|
|
6545
|
+
type: "chat.subscribe",
|
|
6546
|
+
room_id: roomId,
|
|
6547
|
+
from_seq: fromSeq ?? void 0
|
|
6548
|
+
});
|
|
6549
|
+
},
|
|
6550
|
+
unsubscribe(roomId) {
|
|
6551
|
+
send({
|
|
6552
|
+
type: "chat.unsubscribe",
|
|
6553
|
+
room_id: roomId
|
|
6554
|
+
});
|
|
6555
|
+
},
|
|
6556
|
+
resume(rooms) {
|
|
6557
|
+
send({
|
|
6558
|
+
type: "chat.resume",
|
|
6559
|
+
rooms
|
|
6560
|
+
});
|
|
6561
|
+
},
|
|
6562
|
+
typingStart(roomId) {
|
|
6563
|
+
send({
|
|
6564
|
+
type: "chat.typing.start",
|
|
6565
|
+
room_id: roomId
|
|
6566
|
+
});
|
|
6567
|
+
},
|
|
6568
|
+
typingStop(roomId) {
|
|
6569
|
+
send({
|
|
6570
|
+
type: "chat.typing.stop",
|
|
6571
|
+
room_id: roomId
|
|
6572
|
+
});
|
|
6573
|
+
},
|
|
6574
|
+
presenceHeartbeat(activeRoomId) {
|
|
6575
|
+
send({
|
|
6576
|
+
type: "chat.presence.heartbeat",
|
|
6577
|
+
active_room_id: activeRoomId ?? void 0
|
|
6578
|
+
});
|
|
6579
|
+
},
|
|
6580
|
+
readUpTo(roomId, input) {
|
|
6581
|
+
send({
|
|
6582
|
+
type: "chat.read.up_to",
|
|
6583
|
+
room_id: roomId,
|
|
6584
|
+
message_id: input?.message_id ?? void 0,
|
|
6585
|
+
seq: input?.seq ?? void 0
|
|
6586
|
+
});
|
|
6587
|
+
},
|
|
6588
|
+
ping(at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
6589
|
+
send({
|
|
6590
|
+
type: "ping",
|
|
6591
|
+
at
|
|
6592
|
+
});
|
|
6593
|
+
},
|
|
6594
|
+
close(code, reason) {
|
|
6595
|
+
socket.close(code, reason);
|
|
6596
|
+
}
|
|
6597
|
+
};
|
|
6598
|
+
}
|
|
6599
|
+
function createChatModule(config) {
|
|
6600
|
+
const realtime = {
|
|
6601
|
+
info(options) {
|
|
6602
|
+
const realtimeInfoUrl = config.realtimeInfoUrl ?? deriveRealtimeInfoUrl(config.wsUrl);
|
|
6603
|
+
if (!realtimeInfoUrl) {
|
|
6604
|
+
throw new Error(
|
|
6605
|
+
"Athena chat realtime info URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
6606
|
+
);
|
|
6607
|
+
}
|
|
6608
|
+
return request(
|
|
6609
|
+
{
|
|
6610
|
+
...config,
|
|
6611
|
+
baseUrl: realtimeInfoUrl
|
|
6612
|
+
},
|
|
6613
|
+
"GET",
|
|
6614
|
+
"",
|
|
6615
|
+
options
|
|
6616
|
+
);
|
|
6617
|
+
},
|
|
6618
|
+
connect(options) {
|
|
6619
|
+
return createRealtimeConnection(config, options);
|
|
6620
|
+
}
|
|
6621
|
+
};
|
|
6622
|
+
return {
|
|
6623
|
+
room: {
|
|
6624
|
+
list(query, options) {
|
|
6625
|
+
return request(
|
|
6626
|
+
config,
|
|
6627
|
+
"GET",
|
|
6628
|
+
`/rooms${encodeQuery(query)}`,
|
|
6629
|
+
options
|
|
6630
|
+
);
|
|
6631
|
+
},
|
|
6632
|
+
create(input, options) {
|
|
6633
|
+
return request(config, "POST", "/rooms", options, input);
|
|
6634
|
+
},
|
|
6635
|
+
get(roomId, options) {
|
|
6636
|
+
return request(
|
|
6637
|
+
config,
|
|
6638
|
+
"GET",
|
|
6639
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6640
|
+
options
|
|
6641
|
+
);
|
|
6642
|
+
},
|
|
6643
|
+
update(roomId, input, options) {
|
|
6644
|
+
return request(
|
|
6645
|
+
config,
|
|
6646
|
+
"PATCH",
|
|
6647
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6648
|
+
options,
|
|
6649
|
+
input
|
|
6650
|
+
);
|
|
6651
|
+
},
|
|
6652
|
+
archive(roomId, options) {
|
|
6653
|
+
return request(
|
|
6654
|
+
config,
|
|
6655
|
+
"POST",
|
|
6656
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/archive`,
|
|
6657
|
+
options
|
|
6658
|
+
);
|
|
6659
|
+
},
|
|
6660
|
+
readCursor: {
|
|
6661
|
+
upTo(roomId, input, options) {
|
|
6662
|
+
return request(
|
|
6663
|
+
config,
|
|
6664
|
+
"POST",
|
|
6665
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/read-cursor`,
|
|
6666
|
+
options,
|
|
6667
|
+
input ?? {}
|
|
6668
|
+
);
|
|
6669
|
+
}
|
|
6670
|
+
},
|
|
6671
|
+
member: {
|
|
6672
|
+
list(roomId, options) {
|
|
6673
|
+
return request(
|
|
6674
|
+
config,
|
|
6675
|
+
"GET",
|
|
6676
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6677
|
+
options
|
|
6678
|
+
);
|
|
6679
|
+
},
|
|
6680
|
+
add(roomId, input, options) {
|
|
6681
|
+
return request(
|
|
6682
|
+
config,
|
|
6683
|
+
"POST",
|
|
6684
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6685
|
+
options,
|
|
6686
|
+
input
|
|
6687
|
+
);
|
|
6688
|
+
},
|
|
6689
|
+
remove(roomId, userId, options) {
|
|
6690
|
+
return request(
|
|
6691
|
+
config,
|
|
6692
|
+
"DELETE",
|
|
6693
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members/${encodePathSegment(userId, "chat user ID")}`,
|
|
6694
|
+
options
|
|
6695
|
+
);
|
|
6696
|
+
}
|
|
6697
|
+
},
|
|
6698
|
+
message: {
|
|
6699
|
+
list(roomId, query, options) {
|
|
6700
|
+
return request(
|
|
6701
|
+
config,
|
|
6702
|
+
"GET",
|
|
6703
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages${encodeQuery(query)}`,
|
|
6704
|
+
options
|
|
6705
|
+
);
|
|
6706
|
+
},
|
|
6707
|
+
send(roomId, input, options) {
|
|
6708
|
+
return request(
|
|
6709
|
+
config,
|
|
6710
|
+
"POST",
|
|
6711
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages`,
|
|
6712
|
+
options,
|
|
6713
|
+
input
|
|
6714
|
+
);
|
|
6715
|
+
},
|
|
6716
|
+
update(roomId, messageId, input, options) {
|
|
6717
|
+
return request(
|
|
6718
|
+
config,
|
|
6719
|
+
"PATCH",
|
|
6720
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6721
|
+
options,
|
|
6722
|
+
input
|
|
6723
|
+
);
|
|
6724
|
+
},
|
|
6725
|
+
delete(roomId, messageId, options) {
|
|
6726
|
+
return request(
|
|
6727
|
+
config,
|
|
6728
|
+
"DELETE",
|
|
6729
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6730
|
+
options
|
|
6731
|
+
);
|
|
6732
|
+
}
|
|
6733
|
+
}
|
|
6734
|
+
},
|
|
6735
|
+
message: {
|
|
6736
|
+
reaction: {
|
|
6737
|
+
add(messageId, input, options) {
|
|
6738
|
+
return request(
|
|
6739
|
+
config,
|
|
6740
|
+
"POST",
|
|
6741
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions`,
|
|
6742
|
+
options,
|
|
6743
|
+
input
|
|
6744
|
+
);
|
|
6745
|
+
},
|
|
6746
|
+
remove(messageId, emoji, options) {
|
|
6747
|
+
return request(
|
|
6748
|
+
config,
|
|
6749
|
+
"DELETE",
|
|
6750
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions/${encodePathSegment(emoji, "reaction emoji")}`,
|
|
6751
|
+
options
|
|
6752
|
+
);
|
|
6753
|
+
}
|
|
6754
|
+
},
|
|
6755
|
+
search(input, options) {
|
|
6756
|
+
return request(
|
|
6757
|
+
config,
|
|
6758
|
+
"POST",
|
|
6759
|
+
"/messages/search",
|
|
6760
|
+
options,
|
|
6761
|
+
input
|
|
6762
|
+
);
|
|
6763
|
+
}
|
|
6764
|
+
},
|
|
6765
|
+
realtime
|
|
6766
|
+
};
|
|
6767
|
+
}
|
|
6768
|
+
|
|
6193
6769
|
// src/client-builder.ts
|
|
6194
6770
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
6195
6771
|
function toBackendConfig(value) {
|
|
@@ -6224,7 +6800,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
6224
6800
|
"ilike",
|
|
6225
6801
|
"is"
|
|
6226
6802
|
]);
|
|
6227
|
-
function
|
|
6803
|
+
function isRecord8(value) {
|
|
6228
6804
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6229
6805
|
}
|
|
6230
6806
|
function isUuidString(value) {
|
|
@@ -6237,7 +6813,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
6237
6813
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
6238
6814
|
}
|
|
6239
6815
|
function isRelationSelectNode(value) {
|
|
6240
|
-
return
|
|
6816
|
+
return isRecord8(value) && isRecord8(value.select);
|
|
6241
6817
|
}
|
|
6242
6818
|
function normalizeIdentifier(value, label) {
|
|
6243
6819
|
const normalized = value.trim();
|
|
@@ -6293,7 +6869,7 @@ function compileRelationToken(key, node) {
|
|
|
6293
6869
|
return `${prefix}${relationToken}(${nested})`;
|
|
6294
6870
|
}
|
|
6295
6871
|
function compileSelectShape(select) {
|
|
6296
|
-
if (!
|
|
6872
|
+
if (!isRecord8(select)) {
|
|
6297
6873
|
throw new Error("findMany select must be an object");
|
|
6298
6874
|
}
|
|
6299
6875
|
const tokens = [];
|
|
@@ -6317,7 +6893,7 @@ function compileSelectShape(select) {
|
|
|
6317
6893
|
return tokens.join(",");
|
|
6318
6894
|
}
|
|
6319
6895
|
function selectShapeUsesRelationSchema(select) {
|
|
6320
|
-
if (!
|
|
6896
|
+
if (!isRecord8(select)) {
|
|
6321
6897
|
return false;
|
|
6322
6898
|
}
|
|
6323
6899
|
for (const rawValue of Object.values(select)) {
|
|
@@ -6335,7 +6911,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
6335
6911
|
}
|
|
6336
6912
|
function compileColumnWhere(column, input) {
|
|
6337
6913
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
6338
|
-
if (!
|
|
6914
|
+
if (!isRecord8(input)) {
|
|
6339
6915
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
6340
6916
|
}
|
|
6341
6917
|
const conditions = [];
|
|
@@ -6363,7 +6939,7 @@ function compileColumnWhere(column, input) {
|
|
|
6363
6939
|
return conditions;
|
|
6364
6940
|
}
|
|
6365
6941
|
function compileBooleanExpressionTerms(clause, label) {
|
|
6366
|
-
if (!
|
|
6942
|
+
if (!isRecord8(clause)) {
|
|
6367
6943
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
6368
6944
|
}
|
|
6369
6945
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -6372,7 +6948,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
6372
6948
|
}
|
|
6373
6949
|
const [rawColumn, rawValue] = entries[0];
|
|
6374
6950
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
6375
|
-
if (!
|
|
6951
|
+
if (!isRecord8(rawValue)) {
|
|
6376
6952
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
6377
6953
|
}
|
|
6378
6954
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -6396,7 +6972,7 @@ function compileWhere(where) {
|
|
|
6396
6972
|
if (where === void 0) {
|
|
6397
6973
|
return void 0;
|
|
6398
6974
|
}
|
|
6399
|
-
if (!
|
|
6975
|
+
if (!isRecord8(where)) {
|
|
6400
6976
|
throw new Error("findMany where must be an object");
|
|
6401
6977
|
}
|
|
6402
6978
|
const conditions = [];
|
|
@@ -6446,7 +7022,7 @@ function compileOrderBy(orderBy) {
|
|
|
6446
7022
|
if (orderBy === void 0) {
|
|
6447
7023
|
return void 0;
|
|
6448
7024
|
}
|
|
6449
|
-
if (!
|
|
7025
|
+
if (!isRecord8(orderBy)) {
|
|
6450
7026
|
throw new Error("findMany orderBy must be an object");
|
|
6451
7027
|
}
|
|
6452
7028
|
if ("column" in orderBy) {
|
|
@@ -6621,11 +7197,11 @@ function toFindManyAstOrder(order) {
|
|
|
6621
7197
|
ascending: order.direction !== "descending"
|
|
6622
7198
|
};
|
|
6623
7199
|
}
|
|
6624
|
-
function
|
|
7200
|
+
function isRecord9(value) {
|
|
6625
7201
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6626
7202
|
}
|
|
6627
7203
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
6628
|
-
if (!
|
|
7204
|
+
if (!isRecord9(value)) {
|
|
6629
7205
|
return {
|
|
6630
7206
|
eq: value
|
|
6631
7207
|
};
|
|
@@ -6649,7 +7225,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
6649
7225
|
return normalized;
|
|
6650
7226
|
}
|
|
6651
7227
|
function normalizeFindManyAstWhere(where) {
|
|
6652
|
-
if (!where || !
|
|
7228
|
+
if (!where || !isRecord9(where)) {
|
|
6653
7229
|
return where;
|
|
6654
7230
|
}
|
|
6655
7231
|
const normalized = {};
|
|
@@ -6663,7 +7239,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6663
7239
|
);
|
|
6664
7240
|
continue;
|
|
6665
7241
|
}
|
|
6666
|
-
if (key === "not" &&
|
|
7242
|
+
if (key === "not" && isRecord9(value)) {
|
|
6667
7243
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
6668
7244
|
value
|
|
6669
7245
|
);
|
|
@@ -6674,7 +7250,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6674
7250
|
return normalized;
|
|
6675
7251
|
}
|
|
6676
7252
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
6677
|
-
if (!
|
|
7253
|
+
if (!isRecord9(value)) {
|
|
6678
7254
|
return shouldUseUuidTextComparison(column, value);
|
|
6679
7255
|
}
|
|
6680
7256
|
const eqValue = value.eq;
|
|
@@ -6692,7 +7268,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
6692
7268
|
return false;
|
|
6693
7269
|
}
|
|
6694
7270
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
6695
|
-
if (!where || !
|
|
7271
|
+
if (!where || !isRecord9(where)) {
|
|
6696
7272
|
return false;
|
|
6697
7273
|
}
|
|
6698
7274
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -6707,7 +7283,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
6707
7283
|
}
|
|
6708
7284
|
continue;
|
|
6709
7285
|
}
|
|
6710
|
-
if (key === "not" &&
|
|
7286
|
+
if (key === "not" && isRecord9(value)) {
|
|
6711
7287
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
6712
7288
|
return true;
|
|
6713
7289
|
}
|
|
@@ -7250,6 +7826,7 @@ function resolveAthenaModelTargetTableName(target, options = {}) {
|
|
|
7250
7826
|
var DEFAULT_COLUMNS = "*";
|
|
7251
7827
|
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
7252
7828
|
var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
|
|
7829
|
+
var SDK_NAME4 = "xylex-group/athena";
|
|
7253
7830
|
function formatResult(response) {
|
|
7254
7831
|
const result = {
|
|
7255
7832
|
data: response.data ?? null,
|
|
@@ -7326,7 +7903,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
7326
7903
|
throw error;
|
|
7327
7904
|
}
|
|
7328
7905
|
}
|
|
7329
|
-
function
|
|
7906
|
+
function isRecord10(value) {
|
|
7330
7907
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7331
7908
|
}
|
|
7332
7909
|
function firstNonEmptyString2(...values) {
|
|
@@ -7338,8 +7915,8 @@ function firstNonEmptyString2(...values) {
|
|
|
7338
7915
|
return void 0;
|
|
7339
7916
|
}
|
|
7340
7917
|
function resolveStructuredErrorPayload2(raw) {
|
|
7341
|
-
if (!
|
|
7342
|
-
return
|
|
7918
|
+
if (!isRecord10(raw)) return null;
|
|
7919
|
+
return isRecord10(raw.error) ? raw.error : raw;
|
|
7343
7920
|
}
|
|
7344
7921
|
function resolveStructuredErrorDetails(payload, message) {
|
|
7345
7922
|
if (!payload || !("details" in payload)) {
|
|
@@ -7355,7 +7932,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
7355
7932
|
return details;
|
|
7356
7933
|
}
|
|
7357
7934
|
function createResultError(response, result, normalized) {
|
|
7358
|
-
const rawRecord =
|
|
7935
|
+
const rawRecord = isRecord10(response.raw) ? response.raw : null;
|
|
7359
7936
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
7360
7937
|
const message = firstNonEmptyString2(
|
|
7361
7938
|
response.error,
|
|
@@ -7418,6 +7995,43 @@ function asAthenaJsonObject(value) {
|
|
|
7418
7995
|
function asAthenaJsonObjectArray(values) {
|
|
7419
7996
|
return values;
|
|
7420
7997
|
}
|
|
7998
|
+
function parseArbitraryResponseBody(rawText, contentType) {
|
|
7999
|
+
if (!rawText) {
|
|
8000
|
+
return null;
|
|
8001
|
+
}
|
|
8002
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
8003
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
8004
|
+
if (!looksJson) {
|
|
8005
|
+
return rawText;
|
|
8006
|
+
}
|
|
8007
|
+
try {
|
|
8008
|
+
return JSON.parse(rawText);
|
|
8009
|
+
} catch {
|
|
8010
|
+
return rawText;
|
|
8011
|
+
}
|
|
8012
|
+
}
|
|
8013
|
+
function toRequestQueryString(query) {
|
|
8014
|
+
if (!query) {
|
|
8015
|
+
return "";
|
|
8016
|
+
}
|
|
8017
|
+
const params = new URLSearchParams();
|
|
8018
|
+
for (const [key, value] of Object.entries(query)) {
|
|
8019
|
+
if (value === void 0 || value === null) {
|
|
8020
|
+
continue;
|
|
8021
|
+
}
|
|
8022
|
+
if (Array.isArray(value)) {
|
|
8023
|
+
for (const item of value) {
|
|
8024
|
+
if (item !== void 0 && item !== null) {
|
|
8025
|
+
params.append(key, String(item));
|
|
8026
|
+
}
|
|
8027
|
+
}
|
|
8028
|
+
continue;
|
|
8029
|
+
}
|
|
8030
|
+
params.set(key, String(value));
|
|
8031
|
+
}
|
|
8032
|
+
const encoded = params.toString();
|
|
8033
|
+
return encoded ? `?${encoded}` : "";
|
|
8034
|
+
}
|
|
7421
8035
|
function normalizeSelectColumnsInput(columns) {
|
|
7422
8036
|
if (columns === void 0) {
|
|
7423
8037
|
return void 0;
|
|
@@ -8780,6 +9394,15 @@ function appendServicePath(baseUrl, segment) {
|
|
|
8780
9394
|
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
8781
9395
|
return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
|
|
8782
9396
|
}
|
|
9397
|
+
function appendRealtimeGatewayPath(baseUrl) {
|
|
9398
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
9399
|
+
const wsUrl = new URL(normalizedBaseUrl);
|
|
9400
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
9401
|
+
wsUrl.pathname = `${wsUrl.pathname.replace(/\/+$/, "")}/wss/gateway`;
|
|
9402
|
+
wsUrl.search = "";
|
|
9403
|
+
wsUrl.hash = "";
|
|
9404
|
+
return wsUrl.toString();
|
|
9405
|
+
}
|
|
8783
9406
|
function resolveServiceUrlOverride(value, label) {
|
|
8784
9407
|
return resolveClientServiceBaseUrl(value, label);
|
|
8785
9408
|
}
|
|
@@ -8788,6 +9411,8 @@ function resolveServiceUrls(config) {
|
|
|
8788
9411
|
return {
|
|
8789
9412
|
dbUrl: resolveServiceUrlOverride(config.db?.url, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gateway?.url, "Athena gateway base URL") ?? resolveServiceUrlOverride(config.dbUrl, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gatewayUrl, "Athena gateway base URL") ?? (baseUrl ? appendServicePath(baseUrl, "db") : void 0),
|
|
8790
9413
|
authUrl: resolveServiceUrlOverride(config.auth?.url, "Athena auth base URL") ?? resolveServiceUrlOverride(config.auth?.baseUrl, "Athena auth base URL") ?? resolveServiceUrlOverride(config.authUrl, "Athena auth base URL") ?? (baseUrl ? appendServicePath(baseUrl, "auth") : void 0),
|
|
9414
|
+
chatUrl: resolveServiceUrlOverride(config.chat?.url, "Athena chat base URL") ?? resolveServiceUrlOverride(config.chatUrl, "Athena chat base URL") ?? (baseUrl ? appendServicePath(baseUrl, "chat") : void 0),
|
|
9415
|
+
chatWsUrl: normalizeOptionalString2(config.chat?.wsUrl) ?? normalizeOptionalString2(config.chatWsUrl) ?? (baseUrl ? appendRealtimeGatewayPath(baseUrl) : void 0),
|
|
8791
9416
|
storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
|
|
8792
9417
|
};
|
|
8793
9418
|
}
|
|
@@ -8880,6 +9505,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8880
9505
|
} : void 0,
|
|
8881
9506
|
db: base.db ? { ...base.db } : void 0,
|
|
8882
9507
|
gateway: base.gateway ? { ...base.gateway } : void 0,
|
|
9508
|
+
chat: base.chat ? { ...base.chat } : void 0,
|
|
8883
9509
|
storage: base.storage ? { ...base.storage } : void 0
|
|
8884
9510
|
};
|
|
8885
9511
|
}
|
|
@@ -8890,6 +9516,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8890
9516
|
auth: mergeAuthClientOptions(base.auth, overrides.auth),
|
|
8891
9517
|
db: mergeServiceUrlOverrides(base.db, overrides.db),
|
|
8892
9518
|
gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
|
|
9519
|
+
chat: mergeServiceUrlOverrides(base.chat, overrides.chat),
|
|
8893
9520
|
storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
|
|
8894
9521
|
};
|
|
8895
9522
|
}
|
|
@@ -8948,6 +9575,9 @@ function resolveCreateClientConfig(config) {
|
|
|
8948
9575
|
headers: config.headers,
|
|
8949
9576
|
auth: config.auth,
|
|
8950
9577
|
authUrl: resolvedUrls.authUrl,
|
|
9578
|
+
chat: config.chat,
|
|
9579
|
+
chatUrl: resolvedUrls.chatUrl,
|
|
9580
|
+
chatWsUrl: resolvedUrls.chatWsUrl,
|
|
8951
9581
|
storageUrl: resolvedUrls.storageUrl,
|
|
8952
9582
|
experimental: config.experimental
|
|
8953
9583
|
};
|
|
@@ -9032,6 +9662,119 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9032
9662
|
queryTracer
|
|
9033
9663
|
);
|
|
9034
9664
|
const db = createDbModule({ from, rpc, query });
|
|
9665
|
+
const chat = createChatModule({
|
|
9666
|
+
baseUrl: config.chatUrl,
|
|
9667
|
+
apiKey: config.apiKey,
|
|
9668
|
+
client: config.client,
|
|
9669
|
+
headers: config.headers,
|
|
9670
|
+
bearerToken: normalizedAuthConfig?.bearerToken,
|
|
9671
|
+
cookie: normalizedAuthConfig?.cookie,
|
|
9672
|
+
sessionToken: normalizedAuthConfig?.sessionToken,
|
|
9673
|
+
forceNoCache: config.forceNoCache,
|
|
9674
|
+
wsUrl: config.chatWsUrl,
|
|
9675
|
+
webSocketFactory: config.chat?.webSocketFactory ?? void 0
|
|
9676
|
+
});
|
|
9677
|
+
const request2 = async (options) => {
|
|
9678
|
+
const method = options.method ?? "GET";
|
|
9679
|
+
const responseType = options.responseType ?? "json";
|
|
9680
|
+
const service = options.service ?? "db";
|
|
9681
|
+
const baseUrlByService = {
|
|
9682
|
+
db: config.baseUrl,
|
|
9683
|
+
auth: config.authUrl,
|
|
9684
|
+
chat: config.chatUrl,
|
|
9685
|
+
storage: config.storageUrl
|
|
9686
|
+
};
|
|
9687
|
+
const resolvedBaseUrl = options.url ?? baseUrlByService[service];
|
|
9688
|
+
if (!resolvedBaseUrl) {
|
|
9689
|
+
throw new Error(
|
|
9690
|
+
`Athena ${service} base URL is not configured. Pass createClient({ url }) for unified routing or set the service-specific URL first.`
|
|
9691
|
+
);
|
|
9692
|
+
}
|
|
9693
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(resolvedBaseUrl, {
|
|
9694
|
+
label: `Athena ${service} base URL`
|
|
9695
|
+
});
|
|
9696
|
+
const normalizedPath = options.url ? "" : (() => {
|
|
9697
|
+
const path = options.path?.trim();
|
|
9698
|
+
if (!path) {
|
|
9699
|
+
throw new Error("client.request(...) requires either an absolute url or a non-empty path.");
|
|
9700
|
+
}
|
|
9701
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
9702
|
+
})();
|
|
9703
|
+
const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
|
|
9704
|
+
const headers = {
|
|
9705
|
+
"X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
|
|
9706
|
+
...config.headers ?? {},
|
|
9707
|
+
...options.headers ?? {}
|
|
9708
|
+
};
|
|
9709
|
+
if (service !== "auth") {
|
|
9710
|
+
headers.apikey = headers.apikey ?? config.apiKey;
|
|
9711
|
+
headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
|
|
9712
|
+
if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
|
|
9713
|
+
headers["X-Athena-Client"] = config.client;
|
|
9714
|
+
}
|
|
9715
|
+
if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
|
|
9716
|
+
headers["X-User-Id"] = config.userId;
|
|
9717
|
+
}
|
|
9718
|
+
if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
|
|
9719
|
+
headers["X-Organization-Id"] = config.organizationId;
|
|
9720
|
+
}
|
|
9721
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9722
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9723
|
+
}
|
|
9724
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
|
|
9725
|
+
headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
|
|
9726
|
+
}
|
|
9727
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9728
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9729
|
+
}
|
|
9730
|
+
} else {
|
|
9731
|
+
const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
|
|
9732
|
+
if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
|
|
9733
|
+
headers.apikey = headers.apikey ?? authApiKey;
|
|
9734
|
+
headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
|
|
9735
|
+
}
|
|
9736
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
|
|
9737
|
+
headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
|
|
9738
|
+
}
|
|
9739
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9740
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9741
|
+
}
|
|
9742
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9743
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9744
|
+
}
|
|
9745
|
+
}
|
|
9746
|
+
const shouldSendJsonBody = options.body !== void 0 && options.body !== null && !(options.body instanceof FormData) && !(options.body instanceof Blob) && !(options.body instanceof URLSearchParams) && !(options.body instanceof ArrayBuffer) && !ArrayBuffer.isView(options.body) && typeof options.body !== "string";
|
|
9747
|
+
if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
|
|
9748
|
+
headers["Content-Type"] = "application/json";
|
|
9749
|
+
}
|
|
9750
|
+
const response = await fetch(targetUrl, {
|
|
9751
|
+
method,
|
|
9752
|
+
headers,
|
|
9753
|
+
body: options.body === void 0 || options.body === null ? void 0 : shouldSendJsonBody ? JSON.stringify(options.body) : options.body,
|
|
9754
|
+
signal: options.signal,
|
|
9755
|
+
credentials: options.credentials
|
|
9756
|
+
});
|
|
9757
|
+
if (responseType === "response") {
|
|
9758
|
+
return {
|
|
9759
|
+
ok: response.ok,
|
|
9760
|
+
status: response.status,
|
|
9761
|
+
statusText: response.statusText,
|
|
9762
|
+
headers: response.headers,
|
|
9763
|
+
data: null,
|
|
9764
|
+
raw: response
|
|
9765
|
+
};
|
|
9766
|
+
}
|
|
9767
|
+
const rawText = await response.text();
|
|
9768
|
+
const parsed = responseType === "text" ? rawText : parseArbitraryResponseBody(rawText, response.headers.get("content-type"));
|
|
9769
|
+
return {
|
|
9770
|
+
ok: response.ok,
|
|
9771
|
+
status: response.status,
|
|
9772
|
+
statusText: response.statusText,
|
|
9773
|
+
headers: response.headers,
|
|
9774
|
+
data: parsed,
|
|
9775
|
+
raw: response
|
|
9776
|
+
};
|
|
9777
|
+
};
|
|
9035
9778
|
const withContext = (context) => createClientFromInput(
|
|
9036
9779
|
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
9037
9780
|
);
|
|
@@ -9047,8 +9790,10 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9047
9790
|
db,
|
|
9048
9791
|
rpc,
|
|
9049
9792
|
query,
|
|
9793
|
+
request: request2,
|
|
9050
9794
|
verifyConnection: gateway.verifyConnection,
|
|
9051
9795
|
auth: auth.auth,
|
|
9796
|
+
chat,
|
|
9052
9797
|
withContext,
|
|
9053
9798
|
withSession,
|
|
9054
9799
|
withOptions: authWithOptions
|