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