@xylex-group/athena 2.9.0 → 2.10.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 +1 -1
- package/dist/browser.cjs +828 -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 +825 -75
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +748 -40
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +748 -40
- package/dist/cli/index.js.map +1 -1
- package/dist/{client-CfAE_QOj.d.cts → client-B7EQ_hPV.d.cts} +506 -22
- package/dist/{client-D6EIJdQS.d.ts → client-BYii6dU9.d.ts} +506 -22
- package/dist/index.cjs +828 -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 +825 -75
- package/dist/index.js.map +1 -1
- package/dist/{react-email-BvJ3fj_F.d.cts → module-DC96HJa3.d.cts} +97 -2
- package/dist/{react-email-PLAJuZuO.d.ts → module-DbHlxpeR.d.ts} +97 -2
- package/dist/next/client.cjs +756 -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 +756 -40
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +756 -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 +756 -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-BMVGMnti.d.cts} +3 -1
- package/dist/{shared-BiJvoURI.d.ts → shared-DRptGBWP.d.ts} +3 -1
- package/package.json +1 -1
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.10.0"
|
|
2006
2006
|
};
|
|
2007
2007
|
|
|
2008
2008
|
// src/sdk-version.ts
|
|
@@ -2983,6 +2983,50 @@ 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 normalizeAdminEmailTemplatePayload(payload) {
|
|
2996
|
+
const normalized = { ...payload };
|
|
2997
|
+
copyDefinedField(normalized, payload, "template_key", "templateKey");
|
|
2998
|
+
copyDefinedField(normalized, payload, "event_type", "eventType");
|
|
2999
|
+
copyDefinedField(normalized, payload, "subject_template", "subjectTemplate");
|
|
3000
|
+
copyDefinedField(normalized, payload, "text_template", "textTemplate");
|
|
3001
|
+
copyDefinedField(normalized, payload, "html_template", "htmlTemplate");
|
|
3002
|
+
copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
|
|
3003
|
+
copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
|
|
3004
|
+
copyDefinedField(normalized, payload, "is_active", "isActive");
|
|
3005
|
+
return normalized;
|
|
3006
|
+
}
|
|
3007
|
+
function toReactEmailTemplateCompatibilityInput(input) {
|
|
3008
|
+
const payload = input;
|
|
3009
|
+
const compatibility = { ...payload };
|
|
3010
|
+
copyDefinedField(compatibility, payload, "templateKey", "template_key");
|
|
3011
|
+
copyDefinedField(compatibility, payload, "eventType", "event_type");
|
|
3012
|
+
copyDefinedField(compatibility, payload, "subjectTemplate", "subject_template");
|
|
3013
|
+
copyDefinedField(compatibility, payload, "textTemplate", "text_template");
|
|
3014
|
+
copyDefinedField(compatibility, payload, "htmlTemplate", "html_template");
|
|
3015
|
+
copyDefinedField(compatibility, payload, "variableBindings", "variable_bindings");
|
|
3016
|
+
copyDefinedField(compatibility, payload, "attachmentFailureMode", "attachment_failure_mode");
|
|
3017
|
+
copyDefinedField(compatibility, payload, "isActive", "is_active");
|
|
3018
|
+
return compatibility;
|
|
3019
|
+
}
|
|
3020
|
+
function normalizeAdminEmailTemplateSendPayload(payload) {
|
|
3021
|
+
const normalized = { ...payload };
|
|
3022
|
+
copyDefinedField(normalized, payload, "template_id", "templateId");
|
|
3023
|
+
copyDefinedField(normalized, payload, "recipient_email", "recipientEmail");
|
|
3024
|
+
copyDefinedField(normalized, payload, "render_variables", "renderVariables");
|
|
3025
|
+
copyDefinedField(normalized, payload, "user_id", "userId");
|
|
3026
|
+
copyDefinedField(normalized, payload, "organization_id", "organizationId");
|
|
3027
|
+
copyDefinedField(normalized, payload, "session_token", "sessionToken");
|
|
3028
|
+
return normalized;
|
|
3029
|
+
}
|
|
2986
3030
|
function toSessionGuardFailure(sessionResult) {
|
|
2987
3031
|
if (sessionResult.status === 401 || sessionResult.data == null) {
|
|
2988
3032
|
return {
|
|
@@ -3289,7 +3333,7 @@ function createAuthClient(config = {}) {
|
|
|
3289
3333
|
...config,
|
|
3290
3334
|
baseUrl: normalizedBaseUrl
|
|
3291
3335
|
};
|
|
3292
|
-
const
|
|
3336
|
+
const request2 = (input, options) => {
|
|
3293
3337
|
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
3294
3338
|
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
3295
3339
|
return callAuthEndpoint(
|
|
@@ -3302,7 +3346,7 @@ function createAuthClient(config = {}) {
|
|
|
3302
3346
|
};
|
|
3303
3347
|
const postGeneric = (endpoint, input, options) => {
|
|
3304
3348
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3305
|
-
return
|
|
3349
|
+
return request2(
|
|
3306
3350
|
{
|
|
3307
3351
|
endpoint,
|
|
3308
3352
|
method: "POST",
|
|
@@ -3314,7 +3358,7 @@ function createAuthClient(config = {}) {
|
|
|
3314
3358
|
};
|
|
3315
3359
|
const getGeneric = (endpoint, input, options) => {
|
|
3316
3360
|
const { fetchOptions } = extractFetchOptions(input);
|
|
3317
|
-
return
|
|
3361
|
+
return request2(
|
|
3318
3362
|
{
|
|
3319
3363
|
endpoint,
|
|
3320
3364
|
method: "GET",
|
|
@@ -3326,7 +3370,7 @@ function createAuthClient(config = {}) {
|
|
|
3326
3370
|
const getWithQuery = (endpoint, input, options) => {
|
|
3327
3371
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3328
3372
|
const query = payload?.query;
|
|
3329
|
-
return
|
|
3373
|
+
return request2(
|
|
3330
3374
|
{
|
|
3331
3375
|
endpoint,
|
|
3332
3376
|
method: "GET",
|
|
@@ -3344,18 +3388,19 @@ function createAuthClient(config = {}) {
|
|
|
3344
3388
|
htmlField: "htmlBody",
|
|
3345
3389
|
textField: "textBody"
|
|
3346
3390
|
}, withReactEmailRoute(route));
|
|
3347
|
-
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(input, {
|
|
3391
|
+
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(toReactEmailTemplateCompatibilityInput(input), {
|
|
3348
3392
|
htmlField: "htmlTemplate",
|
|
3349
3393
|
textField: "textTemplate",
|
|
3350
3394
|
variablesField: "variables"
|
|
3351
3395
|
}, withReactEmailRoute(route)).then((payload) => {
|
|
3396
|
+
const normalizedPayload = normalizeAdminEmailTemplatePayload(payload);
|
|
3352
3397
|
if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
|
|
3353
3398
|
assertAthenaAuthTemplateVariables(
|
|
3354
3399
|
payload.variables,
|
|
3355
3400
|
`${route} variables`
|
|
3356
3401
|
);
|
|
3357
3402
|
}
|
|
3358
|
-
return
|
|
3403
|
+
return normalizedPayload;
|
|
3359
3404
|
});
|
|
3360
3405
|
const requireSession = async (input, options) => {
|
|
3361
3406
|
const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
|
|
@@ -3931,7 +3976,15 @@ function createAuthClient(config = {}) {
|
|
|
3931
3976
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
3932
3977
|
options
|
|
3933
3978
|
),
|
|
3934
|
-
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
|
|
3979
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
|
|
3980
|
+
send: (input, options) => postGeneric(
|
|
3981
|
+
"/admin/email-template/send",
|
|
3982
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
3983
|
+
options
|
|
3984
|
+
)
|
|
3985
|
+
},
|
|
3986
|
+
eventType: {
|
|
3987
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
3935
3988
|
}
|
|
3936
3989
|
},
|
|
3937
3990
|
emailTemplate: {
|
|
@@ -3947,7 +4000,15 @@ function createAuthClient(config = {}) {
|
|
|
3947
4000
|
"/admin/email-template/update",
|
|
3948
4001
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
3949
4002
|
options
|
|
4003
|
+
),
|
|
4004
|
+
send: (input, options) => postGeneric(
|
|
4005
|
+
"/admin/email-template/send",
|
|
4006
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
4007
|
+
options
|
|
3950
4008
|
)
|
|
4009
|
+
},
|
|
4010
|
+
emailEventType: {
|
|
4011
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
3951
4012
|
}
|
|
3952
4013
|
},
|
|
3953
4014
|
apiKey: {
|
|
@@ -3987,7 +4048,7 @@ function createAuthClient(config = {}) {
|
|
|
3987
4048
|
throw new Error("callback.provider requires non-empty code and state values");
|
|
3988
4049
|
}
|
|
3989
4050
|
const endpoint = `/callback/${encodeURIComponent(provider)}`;
|
|
3990
|
-
return
|
|
4051
|
+
return request2({
|
|
3991
4052
|
endpoint,
|
|
3992
4053
|
method: "GET",
|
|
3993
4054
|
query: {
|
|
@@ -4001,7 +4062,7 @@ function createAuthClient(config = {}) {
|
|
|
4001
4062
|
};
|
|
4002
4063
|
return {
|
|
4003
4064
|
baseUrl: normalizedBaseUrl,
|
|
4004
|
-
request,
|
|
4065
|
+
request: request2,
|
|
4005
4066
|
signIn: {
|
|
4006
4067
|
email: (input, options) => executePostWithCompatibleInput(
|
|
4007
4068
|
resolvedConfig,
|
|
@@ -4203,16 +4264,16 @@ function createStorageFileModule(base, config = {}) {
|
|
|
4203
4264
|
};
|
|
4204
4265
|
});
|
|
4205
4266
|
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((
|
|
4267
|
+
const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request2) => request2.uploadRequest) }, options)).files;
|
|
4207
4268
|
const aggregateLoaded = new Array(uploadRequests.length).fill(0);
|
|
4208
4269
|
const uploaded = [];
|
|
4209
4270
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
4210
|
-
const
|
|
4271
|
+
const request2 = uploadRequests[index];
|
|
4211
4272
|
const uploadUrl = uploadUrls[index];
|
|
4212
4273
|
const response = await putUploadBody(
|
|
4213
4274
|
uploadUrl.upload.url,
|
|
4214
4275
|
uploadUrl.upload.headers ?? {},
|
|
4215
|
-
|
|
4276
|
+
request2.source,
|
|
4216
4277
|
input,
|
|
4217
4278
|
options,
|
|
4218
4279
|
(progress) => {
|
|
@@ -4223,13 +4284,13 @@ function createStorageFileModule(base, config = {}) {
|
|
|
4223
4284
|
uploaded.push({
|
|
4224
4285
|
file: uploadUrl.file,
|
|
4225
4286
|
upload: uploadUrl.upload,
|
|
4226
|
-
source:
|
|
4227
|
-
fileName:
|
|
4228
|
-
storage_key:
|
|
4287
|
+
source: request2.source.source,
|
|
4288
|
+
fileName: request2.source.fileName,
|
|
4289
|
+
storage_key: request2.uploadRequest.storage_key,
|
|
4229
4290
|
response
|
|
4230
4291
|
});
|
|
4231
|
-
aggregateLoaded[index] =
|
|
4232
|
-
input.onProgress?.(createProgressSnapshot("complete", sources, index,
|
|
4292
|
+
aggregateLoaded[index] = request2.source.sizeBytes;
|
|
4293
|
+
input.onProgress?.(createProgressSnapshot("complete", sources, index, request2.source.sizeBytes, sum(aggregateLoaded)));
|
|
4233
4294
|
}
|
|
4234
4295
|
return {
|
|
4235
4296
|
files: uploaded,
|
|
@@ -6190,6 +6251,484 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
6190
6251
|
};
|
|
6191
6252
|
}
|
|
6192
6253
|
|
|
6254
|
+
// src/chat/module.ts
|
|
6255
|
+
var SDK_NAME3 = "xylex-group/athena-chat";
|
|
6256
|
+
var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
|
|
6257
|
+
var NO_CACHE_HEADER_VALUE3 = "no-cache";
|
|
6258
|
+
var AthenaChatError = class extends Error {
|
|
6259
|
+
status;
|
|
6260
|
+
endpoint;
|
|
6261
|
+
method;
|
|
6262
|
+
requestId;
|
|
6263
|
+
body;
|
|
6264
|
+
constructor(input) {
|
|
6265
|
+
super(input.message);
|
|
6266
|
+
this.name = "AthenaChatError";
|
|
6267
|
+
this.status = input.status;
|
|
6268
|
+
this.endpoint = input.endpoint;
|
|
6269
|
+
this.method = input.method;
|
|
6270
|
+
this.requestId = input.requestId;
|
|
6271
|
+
this.body = input.body;
|
|
6272
|
+
}
|
|
6273
|
+
};
|
|
6274
|
+
function deriveRealtimeInfoUrl(wsUrl) {
|
|
6275
|
+
if (!wsUrl) {
|
|
6276
|
+
return void 0;
|
|
6277
|
+
}
|
|
6278
|
+
const parsed = new URL(normalizeWsUrl(wsUrl, "Athena chat WebSocket URL"));
|
|
6279
|
+
parsed.protocol = parsed.protocol === "wss:" ? "https:" : "http:";
|
|
6280
|
+
parsed.pathname = parsed.pathname.replace(/\/wss\/gateway$/, "/wss/info");
|
|
6281
|
+
return parsed.toString();
|
|
6282
|
+
}
|
|
6283
|
+
function normalizeWsUrl(value, label) {
|
|
6284
|
+
const normalized = value.trim();
|
|
6285
|
+
if (!normalized) {
|
|
6286
|
+
throw new Error(`${label} is required.`);
|
|
6287
|
+
}
|
|
6288
|
+
let parsed;
|
|
6289
|
+
try {
|
|
6290
|
+
parsed = new URL(normalized);
|
|
6291
|
+
} catch {
|
|
6292
|
+
throw new Error(`${label} must be a valid absolute ws(s) URL.`);
|
|
6293
|
+
}
|
|
6294
|
+
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
|
|
6295
|
+
throw new Error(`${label} must use ws or wss.`);
|
|
6296
|
+
}
|
|
6297
|
+
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
6298
|
+
return parsed.toString().replace(/\/$/, "");
|
|
6299
|
+
}
|
|
6300
|
+
function isRecord7(value) {
|
|
6301
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6302
|
+
}
|
|
6303
|
+
function normalizeHeaderValue3(value) {
|
|
6304
|
+
return value ? value : void 0;
|
|
6305
|
+
}
|
|
6306
|
+
function parseResponseBody4(rawText, contentType) {
|
|
6307
|
+
if (!rawText) {
|
|
6308
|
+
return { parsed: null, parseFailed: false };
|
|
6309
|
+
}
|
|
6310
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
6311
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
6312
|
+
if (!looksJson) {
|
|
6313
|
+
return { parsed: rawText, parseFailed: false };
|
|
6314
|
+
}
|
|
6315
|
+
try {
|
|
6316
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
6317
|
+
} catch {
|
|
6318
|
+
return { parsed: rawText, parseFailed: true };
|
|
6319
|
+
}
|
|
6320
|
+
}
|
|
6321
|
+
function resolveRequestId3(headers) {
|
|
6322
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
6323
|
+
}
|
|
6324
|
+
function resolveErrorMessage4(payload, fallback) {
|
|
6325
|
+
if (isRecord7(payload)) {
|
|
6326
|
+
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
6327
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
6328
|
+
return candidate.trim();
|
|
6329
|
+
}
|
|
6330
|
+
}
|
|
6331
|
+
}
|
|
6332
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
6333
|
+
return payload.trim();
|
|
6334
|
+
}
|
|
6335
|
+
return fallback;
|
|
6336
|
+
}
|
|
6337
|
+
function encodePathSegment(value, label) {
|
|
6338
|
+
const normalized = value.trim();
|
|
6339
|
+
if (!normalized) {
|
|
6340
|
+
throw new Error(`${label} is required.`);
|
|
6341
|
+
}
|
|
6342
|
+
return encodeURIComponent(normalized);
|
|
6343
|
+
}
|
|
6344
|
+
function encodeQuery(query) {
|
|
6345
|
+
if (!query) {
|
|
6346
|
+
return "";
|
|
6347
|
+
}
|
|
6348
|
+
const params = new URLSearchParams();
|
|
6349
|
+
for (const [key, value] of Object.entries(query)) {
|
|
6350
|
+
if (value === void 0 || value === null) {
|
|
6351
|
+
continue;
|
|
6352
|
+
}
|
|
6353
|
+
if (Array.isArray(value)) {
|
|
6354
|
+
for (const item of value) {
|
|
6355
|
+
if (item !== void 0 && item !== null) {
|
|
6356
|
+
params.append(key, String(item));
|
|
6357
|
+
}
|
|
6358
|
+
}
|
|
6359
|
+
continue;
|
|
6360
|
+
}
|
|
6361
|
+
params.set(key, String(value));
|
|
6362
|
+
}
|
|
6363
|
+
const encoded = params.toString();
|
|
6364
|
+
return encoded ? `?${encoded}` : "";
|
|
6365
|
+
}
|
|
6366
|
+
function createSocket(factory, url, protocols) {
|
|
6367
|
+
try {
|
|
6368
|
+
return new factory(url, protocols);
|
|
6369
|
+
} catch (error) {
|
|
6370
|
+
if (error instanceof TypeError) {
|
|
6371
|
+
return factory(url, protocols);
|
|
6372
|
+
}
|
|
6373
|
+
throw error;
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
function buildHeaders3(config, options) {
|
|
6377
|
+
const headers = {
|
|
6378
|
+
Accept: "application/json",
|
|
6379
|
+
apikey: config.apiKey,
|
|
6380
|
+
"x-api-key": config.apiKey,
|
|
6381
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE3
|
|
6382
|
+
};
|
|
6383
|
+
if (config.client || options?.client) {
|
|
6384
|
+
headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
|
|
6385
|
+
}
|
|
6386
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
6387
|
+
if (typeof bearerToken === "string" && bearerToken.trim()) {
|
|
6388
|
+
headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
|
|
6389
|
+
}
|
|
6390
|
+
const cookie = options?.cookie ?? config.cookie;
|
|
6391
|
+
if (typeof cookie === "string" && cookie.trim()) {
|
|
6392
|
+
headers.Cookie = cookie;
|
|
6393
|
+
}
|
|
6394
|
+
const sessionToken = options?.sessionToken ?? config.sessionToken;
|
|
6395
|
+
if (typeof sessionToken === "string" && sessionToken.trim()) {
|
|
6396
|
+
headers["X-Athena-Auth-Session-Token"] = sessionToken;
|
|
6397
|
+
}
|
|
6398
|
+
if (config.forceNoCache || options?.forceNoCache) {
|
|
6399
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
|
|
6400
|
+
}
|
|
6401
|
+
for (const source of [config.headers, options?.headers]) {
|
|
6402
|
+
for (const [key, value] of Object.entries(source ?? {})) {
|
|
6403
|
+
const normalized = normalizeHeaderValue3(value);
|
|
6404
|
+
if (normalized) {
|
|
6405
|
+
headers[key] = normalized;
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6408
|
+
}
|
|
6409
|
+
return headers;
|
|
6410
|
+
}
|
|
6411
|
+
function withJsonBody(init, body) {
|
|
6412
|
+
return {
|
|
6413
|
+
...init,
|
|
6414
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
6415
|
+
headers: {
|
|
6416
|
+
"Content-Type": "application/json",
|
|
6417
|
+
...init.headers
|
|
6418
|
+
}
|
|
6419
|
+
};
|
|
6420
|
+
}
|
|
6421
|
+
async function request(config, method, endpoint, options, body) {
|
|
6422
|
+
if (!config.baseUrl) {
|
|
6423
|
+
throw new Error(
|
|
6424
|
+
"Athena chat base URL is not configured. Pass createClient({ url }) for unified routing or set chat.url / chatUrl explicitly."
|
|
6425
|
+
);
|
|
6426
|
+
}
|
|
6427
|
+
const url = `${config.baseUrl}${endpoint}`;
|
|
6428
|
+
const init = {
|
|
6429
|
+
method,
|
|
6430
|
+
headers: buildHeaders3(config, options),
|
|
6431
|
+
signal: options?.signal
|
|
6432
|
+
};
|
|
6433
|
+
const finalInit = body === void 0 || method === "GET" ? init : withJsonBody(init, body);
|
|
6434
|
+
const response = await fetch(url, finalInit);
|
|
6435
|
+
const rawText = await response.text();
|
|
6436
|
+
const { parsed } = parseResponseBody4(rawText, response.headers.get("content-type"));
|
|
6437
|
+
if (!response.ok) {
|
|
6438
|
+
throw new AthenaChatError({
|
|
6439
|
+
message: resolveErrorMessage4(parsed, `Athena chat ${method} ${endpoint} failed with ${response.status}`),
|
|
6440
|
+
status: response.status,
|
|
6441
|
+
endpoint,
|
|
6442
|
+
method,
|
|
6443
|
+
requestId: resolveRequestId3(response.headers),
|
|
6444
|
+
body: parsed
|
|
6445
|
+
});
|
|
6446
|
+
}
|
|
6447
|
+
return parsed;
|
|
6448
|
+
}
|
|
6449
|
+
function createRealtimeConnection(config, options) {
|
|
6450
|
+
if (!config.wsUrl) {
|
|
6451
|
+
throw new Error(
|
|
6452
|
+
"Athena chat WebSocket URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
6453
|
+
);
|
|
6454
|
+
}
|
|
6455
|
+
const wsFactory = config.webSocketFactory ?? globalThis.WebSocket;
|
|
6456
|
+
if (!wsFactory) {
|
|
6457
|
+
throw new Error(
|
|
6458
|
+
"No WebSocket implementation is available. Provide chat.webSocketFactory in createClient(...) or run in a runtime with global WebSocket support."
|
|
6459
|
+
);
|
|
6460
|
+
}
|
|
6461
|
+
const socket = createSocket(wsFactory, config.wsUrl, options?.protocols);
|
|
6462
|
+
const send = (command) => {
|
|
6463
|
+
socket.send(JSON.stringify(command));
|
|
6464
|
+
};
|
|
6465
|
+
if (options?.onMessage) {
|
|
6466
|
+
const listener = (event) => {
|
|
6467
|
+
const messageEvent = event;
|
|
6468
|
+
const raw = messageEvent?.data;
|
|
6469
|
+
if (typeof raw !== "string") {
|
|
6470
|
+
return;
|
|
6471
|
+
}
|
|
6472
|
+
try {
|
|
6473
|
+
options.onMessage?.(JSON.parse(raw));
|
|
6474
|
+
} catch {
|
|
6475
|
+
options.onMessage?.({ type: "error", error: "Invalid JSON message from Athena chat realtime gateway." });
|
|
6476
|
+
}
|
|
6477
|
+
};
|
|
6478
|
+
if (typeof socket.addEventListener === "function") {
|
|
6479
|
+
socket.addEventListener("message", listener);
|
|
6480
|
+
} else {
|
|
6481
|
+
socket.onmessage = listener;
|
|
6482
|
+
}
|
|
6483
|
+
}
|
|
6484
|
+
const hello = (command) => {
|
|
6485
|
+
send({
|
|
6486
|
+
type: "auth.hello",
|
|
6487
|
+
token: command?.token,
|
|
6488
|
+
room_subscriptions: command?.room_subscriptions
|
|
6489
|
+
});
|
|
6490
|
+
};
|
|
6491
|
+
if (options?.hello) {
|
|
6492
|
+
const onOpen = () => hello({
|
|
6493
|
+
token: options.hello?.token ?? void 0,
|
|
6494
|
+
room_subscriptions: options.hello?.room_subscriptions ?? void 0
|
|
6495
|
+
});
|
|
6496
|
+
if (typeof socket.addEventListener === "function") {
|
|
6497
|
+
socket.addEventListener("open", onOpen);
|
|
6498
|
+
} else {
|
|
6499
|
+
socket.onopen = onOpen;
|
|
6500
|
+
}
|
|
6501
|
+
}
|
|
6502
|
+
return {
|
|
6503
|
+
socket,
|
|
6504
|
+
send,
|
|
6505
|
+
hello,
|
|
6506
|
+
subscribe(roomId, fromSeq) {
|
|
6507
|
+
send({
|
|
6508
|
+
type: "chat.subscribe",
|
|
6509
|
+
room_id: roomId,
|
|
6510
|
+
from_seq: fromSeq ?? void 0
|
|
6511
|
+
});
|
|
6512
|
+
},
|
|
6513
|
+
unsubscribe(roomId) {
|
|
6514
|
+
send({
|
|
6515
|
+
type: "chat.unsubscribe",
|
|
6516
|
+
room_id: roomId
|
|
6517
|
+
});
|
|
6518
|
+
},
|
|
6519
|
+
resume(rooms) {
|
|
6520
|
+
send({
|
|
6521
|
+
type: "chat.resume",
|
|
6522
|
+
rooms
|
|
6523
|
+
});
|
|
6524
|
+
},
|
|
6525
|
+
typingStart(roomId) {
|
|
6526
|
+
send({
|
|
6527
|
+
type: "chat.typing.start",
|
|
6528
|
+
room_id: roomId
|
|
6529
|
+
});
|
|
6530
|
+
},
|
|
6531
|
+
typingStop(roomId) {
|
|
6532
|
+
send({
|
|
6533
|
+
type: "chat.typing.stop",
|
|
6534
|
+
room_id: roomId
|
|
6535
|
+
});
|
|
6536
|
+
},
|
|
6537
|
+
presenceHeartbeat(activeRoomId) {
|
|
6538
|
+
send({
|
|
6539
|
+
type: "chat.presence.heartbeat",
|
|
6540
|
+
active_room_id: activeRoomId ?? void 0
|
|
6541
|
+
});
|
|
6542
|
+
},
|
|
6543
|
+
readUpTo(roomId, input) {
|
|
6544
|
+
send({
|
|
6545
|
+
type: "chat.read.up_to",
|
|
6546
|
+
room_id: roomId,
|
|
6547
|
+
message_id: input?.message_id ?? void 0,
|
|
6548
|
+
seq: input?.seq ?? void 0
|
|
6549
|
+
});
|
|
6550
|
+
},
|
|
6551
|
+
ping(at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
6552
|
+
send({
|
|
6553
|
+
type: "ping",
|
|
6554
|
+
at
|
|
6555
|
+
});
|
|
6556
|
+
},
|
|
6557
|
+
close(code, reason) {
|
|
6558
|
+
socket.close(code, reason);
|
|
6559
|
+
}
|
|
6560
|
+
};
|
|
6561
|
+
}
|
|
6562
|
+
function createChatModule(config) {
|
|
6563
|
+
const realtime = {
|
|
6564
|
+
info(options) {
|
|
6565
|
+
const realtimeInfoUrl = config.realtimeInfoUrl ?? deriveRealtimeInfoUrl(config.wsUrl);
|
|
6566
|
+
if (!realtimeInfoUrl) {
|
|
6567
|
+
throw new Error(
|
|
6568
|
+
"Athena chat realtime info URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
6569
|
+
);
|
|
6570
|
+
}
|
|
6571
|
+
return request(
|
|
6572
|
+
{
|
|
6573
|
+
...config,
|
|
6574
|
+
baseUrl: realtimeInfoUrl
|
|
6575
|
+
},
|
|
6576
|
+
"GET",
|
|
6577
|
+
"",
|
|
6578
|
+
options
|
|
6579
|
+
);
|
|
6580
|
+
},
|
|
6581
|
+
connect(options) {
|
|
6582
|
+
return createRealtimeConnection(config, options);
|
|
6583
|
+
}
|
|
6584
|
+
};
|
|
6585
|
+
return {
|
|
6586
|
+
room: {
|
|
6587
|
+
list(query, options) {
|
|
6588
|
+
return request(
|
|
6589
|
+
config,
|
|
6590
|
+
"GET",
|
|
6591
|
+
`/rooms${encodeQuery(query)}`,
|
|
6592
|
+
options
|
|
6593
|
+
);
|
|
6594
|
+
},
|
|
6595
|
+
create(input, options) {
|
|
6596
|
+
return request(config, "POST", "/rooms", options, input);
|
|
6597
|
+
},
|
|
6598
|
+
get(roomId, options) {
|
|
6599
|
+
return request(
|
|
6600
|
+
config,
|
|
6601
|
+
"GET",
|
|
6602
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6603
|
+
options
|
|
6604
|
+
);
|
|
6605
|
+
},
|
|
6606
|
+
update(roomId, input, options) {
|
|
6607
|
+
return request(
|
|
6608
|
+
config,
|
|
6609
|
+
"PATCH",
|
|
6610
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6611
|
+
options,
|
|
6612
|
+
input
|
|
6613
|
+
);
|
|
6614
|
+
},
|
|
6615
|
+
archive(roomId, options) {
|
|
6616
|
+
return request(
|
|
6617
|
+
config,
|
|
6618
|
+
"POST",
|
|
6619
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/archive`,
|
|
6620
|
+
options
|
|
6621
|
+
);
|
|
6622
|
+
},
|
|
6623
|
+
readCursor: {
|
|
6624
|
+
upTo(roomId, input, options) {
|
|
6625
|
+
return request(
|
|
6626
|
+
config,
|
|
6627
|
+
"POST",
|
|
6628
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/read-cursor`,
|
|
6629
|
+
options,
|
|
6630
|
+
input ?? {}
|
|
6631
|
+
);
|
|
6632
|
+
}
|
|
6633
|
+
},
|
|
6634
|
+
member: {
|
|
6635
|
+
list(roomId, options) {
|
|
6636
|
+
return request(
|
|
6637
|
+
config,
|
|
6638
|
+
"GET",
|
|
6639
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6640
|
+
options
|
|
6641
|
+
);
|
|
6642
|
+
},
|
|
6643
|
+
add(roomId, input, options) {
|
|
6644
|
+
return request(
|
|
6645
|
+
config,
|
|
6646
|
+
"POST",
|
|
6647
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6648
|
+
options,
|
|
6649
|
+
input
|
|
6650
|
+
);
|
|
6651
|
+
},
|
|
6652
|
+
remove(roomId, userId, options) {
|
|
6653
|
+
return request(
|
|
6654
|
+
config,
|
|
6655
|
+
"DELETE",
|
|
6656
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members/${encodePathSegment(userId, "chat user ID")}`,
|
|
6657
|
+
options
|
|
6658
|
+
);
|
|
6659
|
+
}
|
|
6660
|
+
},
|
|
6661
|
+
message: {
|
|
6662
|
+
list(roomId, query, options) {
|
|
6663
|
+
return request(
|
|
6664
|
+
config,
|
|
6665
|
+
"GET",
|
|
6666
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages${encodeQuery(query)}`,
|
|
6667
|
+
options
|
|
6668
|
+
);
|
|
6669
|
+
},
|
|
6670
|
+
send(roomId, input, options) {
|
|
6671
|
+
return request(
|
|
6672
|
+
config,
|
|
6673
|
+
"POST",
|
|
6674
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages`,
|
|
6675
|
+
options,
|
|
6676
|
+
input
|
|
6677
|
+
);
|
|
6678
|
+
},
|
|
6679
|
+
update(roomId, messageId, input, options) {
|
|
6680
|
+
return request(
|
|
6681
|
+
config,
|
|
6682
|
+
"PATCH",
|
|
6683
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6684
|
+
options,
|
|
6685
|
+
input
|
|
6686
|
+
);
|
|
6687
|
+
},
|
|
6688
|
+
delete(roomId, messageId, options) {
|
|
6689
|
+
return request(
|
|
6690
|
+
config,
|
|
6691
|
+
"DELETE",
|
|
6692
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6693
|
+
options
|
|
6694
|
+
);
|
|
6695
|
+
}
|
|
6696
|
+
}
|
|
6697
|
+
},
|
|
6698
|
+
message: {
|
|
6699
|
+
reaction: {
|
|
6700
|
+
add(messageId, input, options) {
|
|
6701
|
+
return request(
|
|
6702
|
+
config,
|
|
6703
|
+
"POST",
|
|
6704
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions`,
|
|
6705
|
+
options,
|
|
6706
|
+
input
|
|
6707
|
+
);
|
|
6708
|
+
},
|
|
6709
|
+
remove(messageId, emoji, options) {
|
|
6710
|
+
return request(
|
|
6711
|
+
config,
|
|
6712
|
+
"DELETE",
|
|
6713
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions/${encodePathSegment(emoji, "reaction emoji")}`,
|
|
6714
|
+
options
|
|
6715
|
+
);
|
|
6716
|
+
}
|
|
6717
|
+
},
|
|
6718
|
+
search(input, options) {
|
|
6719
|
+
return request(
|
|
6720
|
+
config,
|
|
6721
|
+
"POST",
|
|
6722
|
+
"/messages/search",
|
|
6723
|
+
options,
|
|
6724
|
+
input
|
|
6725
|
+
);
|
|
6726
|
+
}
|
|
6727
|
+
},
|
|
6728
|
+
realtime
|
|
6729
|
+
};
|
|
6730
|
+
}
|
|
6731
|
+
|
|
6193
6732
|
// src/client-builder.ts
|
|
6194
6733
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
6195
6734
|
function toBackendConfig(value) {
|
|
@@ -6224,7 +6763,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
6224
6763
|
"ilike",
|
|
6225
6764
|
"is"
|
|
6226
6765
|
]);
|
|
6227
|
-
function
|
|
6766
|
+
function isRecord8(value) {
|
|
6228
6767
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6229
6768
|
}
|
|
6230
6769
|
function isUuidString(value) {
|
|
@@ -6237,7 +6776,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
6237
6776
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
6238
6777
|
}
|
|
6239
6778
|
function isRelationSelectNode(value) {
|
|
6240
|
-
return
|
|
6779
|
+
return isRecord8(value) && isRecord8(value.select);
|
|
6241
6780
|
}
|
|
6242
6781
|
function normalizeIdentifier(value, label) {
|
|
6243
6782
|
const normalized = value.trim();
|
|
@@ -6293,7 +6832,7 @@ function compileRelationToken(key, node) {
|
|
|
6293
6832
|
return `${prefix}${relationToken}(${nested})`;
|
|
6294
6833
|
}
|
|
6295
6834
|
function compileSelectShape(select) {
|
|
6296
|
-
if (!
|
|
6835
|
+
if (!isRecord8(select)) {
|
|
6297
6836
|
throw new Error("findMany select must be an object");
|
|
6298
6837
|
}
|
|
6299
6838
|
const tokens = [];
|
|
@@ -6317,7 +6856,7 @@ function compileSelectShape(select) {
|
|
|
6317
6856
|
return tokens.join(",");
|
|
6318
6857
|
}
|
|
6319
6858
|
function selectShapeUsesRelationSchema(select) {
|
|
6320
|
-
if (!
|
|
6859
|
+
if (!isRecord8(select)) {
|
|
6321
6860
|
return false;
|
|
6322
6861
|
}
|
|
6323
6862
|
for (const rawValue of Object.values(select)) {
|
|
@@ -6335,7 +6874,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
6335
6874
|
}
|
|
6336
6875
|
function compileColumnWhere(column, input) {
|
|
6337
6876
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
6338
|
-
if (!
|
|
6877
|
+
if (!isRecord8(input)) {
|
|
6339
6878
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
6340
6879
|
}
|
|
6341
6880
|
const conditions = [];
|
|
@@ -6363,7 +6902,7 @@ function compileColumnWhere(column, input) {
|
|
|
6363
6902
|
return conditions;
|
|
6364
6903
|
}
|
|
6365
6904
|
function compileBooleanExpressionTerms(clause, label) {
|
|
6366
|
-
if (!
|
|
6905
|
+
if (!isRecord8(clause)) {
|
|
6367
6906
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
6368
6907
|
}
|
|
6369
6908
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -6372,7 +6911,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
6372
6911
|
}
|
|
6373
6912
|
const [rawColumn, rawValue] = entries[0];
|
|
6374
6913
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
6375
|
-
if (!
|
|
6914
|
+
if (!isRecord8(rawValue)) {
|
|
6376
6915
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
6377
6916
|
}
|
|
6378
6917
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -6396,7 +6935,7 @@ function compileWhere(where) {
|
|
|
6396
6935
|
if (where === void 0) {
|
|
6397
6936
|
return void 0;
|
|
6398
6937
|
}
|
|
6399
|
-
if (!
|
|
6938
|
+
if (!isRecord8(where)) {
|
|
6400
6939
|
throw new Error("findMany where must be an object");
|
|
6401
6940
|
}
|
|
6402
6941
|
const conditions = [];
|
|
@@ -6446,7 +6985,7 @@ function compileOrderBy(orderBy) {
|
|
|
6446
6985
|
if (orderBy === void 0) {
|
|
6447
6986
|
return void 0;
|
|
6448
6987
|
}
|
|
6449
|
-
if (!
|
|
6988
|
+
if (!isRecord8(orderBy)) {
|
|
6450
6989
|
throw new Error("findMany orderBy must be an object");
|
|
6451
6990
|
}
|
|
6452
6991
|
if ("column" in orderBy) {
|
|
@@ -6621,11 +7160,11 @@ function toFindManyAstOrder(order) {
|
|
|
6621
7160
|
ascending: order.direction !== "descending"
|
|
6622
7161
|
};
|
|
6623
7162
|
}
|
|
6624
|
-
function
|
|
7163
|
+
function isRecord9(value) {
|
|
6625
7164
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6626
7165
|
}
|
|
6627
7166
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
6628
|
-
if (!
|
|
7167
|
+
if (!isRecord9(value)) {
|
|
6629
7168
|
return {
|
|
6630
7169
|
eq: value
|
|
6631
7170
|
};
|
|
@@ -6649,7 +7188,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
6649
7188
|
return normalized;
|
|
6650
7189
|
}
|
|
6651
7190
|
function normalizeFindManyAstWhere(where) {
|
|
6652
|
-
if (!where || !
|
|
7191
|
+
if (!where || !isRecord9(where)) {
|
|
6653
7192
|
return where;
|
|
6654
7193
|
}
|
|
6655
7194
|
const normalized = {};
|
|
@@ -6663,7 +7202,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6663
7202
|
);
|
|
6664
7203
|
continue;
|
|
6665
7204
|
}
|
|
6666
|
-
if (key === "not" &&
|
|
7205
|
+
if (key === "not" && isRecord9(value)) {
|
|
6667
7206
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
6668
7207
|
value
|
|
6669
7208
|
);
|
|
@@ -6674,7 +7213,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6674
7213
|
return normalized;
|
|
6675
7214
|
}
|
|
6676
7215
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
6677
|
-
if (!
|
|
7216
|
+
if (!isRecord9(value)) {
|
|
6678
7217
|
return shouldUseUuidTextComparison(column, value);
|
|
6679
7218
|
}
|
|
6680
7219
|
const eqValue = value.eq;
|
|
@@ -6692,7 +7231,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
6692
7231
|
return false;
|
|
6693
7232
|
}
|
|
6694
7233
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
6695
|
-
if (!where || !
|
|
7234
|
+
if (!where || !isRecord9(where)) {
|
|
6696
7235
|
return false;
|
|
6697
7236
|
}
|
|
6698
7237
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -6707,7 +7246,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
6707
7246
|
}
|
|
6708
7247
|
continue;
|
|
6709
7248
|
}
|
|
6710
|
-
if (key === "not" &&
|
|
7249
|
+
if (key === "not" && isRecord9(value)) {
|
|
6711
7250
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
6712
7251
|
return true;
|
|
6713
7252
|
}
|
|
@@ -7250,6 +7789,7 @@ function resolveAthenaModelTargetTableName(target, options = {}) {
|
|
|
7250
7789
|
var DEFAULT_COLUMNS = "*";
|
|
7251
7790
|
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
7252
7791
|
var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
|
|
7792
|
+
var SDK_NAME4 = "xylex-group/athena";
|
|
7253
7793
|
function formatResult(response) {
|
|
7254
7794
|
const result = {
|
|
7255
7795
|
data: response.data ?? null,
|
|
@@ -7326,7 +7866,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
7326
7866
|
throw error;
|
|
7327
7867
|
}
|
|
7328
7868
|
}
|
|
7329
|
-
function
|
|
7869
|
+
function isRecord10(value) {
|
|
7330
7870
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7331
7871
|
}
|
|
7332
7872
|
function firstNonEmptyString2(...values) {
|
|
@@ -7338,8 +7878,8 @@ function firstNonEmptyString2(...values) {
|
|
|
7338
7878
|
return void 0;
|
|
7339
7879
|
}
|
|
7340
7880
|
function resolveStructuredErrorPayload2(raw) {
|
|
7341
|
-
if (!
|
|
7342
|
-
return
|
|
7881
|
+
if (!isRecord10(raw)) return null;
|
|
7882
|
+
return isRecord10(raw.error) ? raw.error : raw;
|
|
7343
7883
|
}
|
|
7344
7884
|
function resolveStructuredErrorDetails(payload, message) {
|
|
7345
7885
|
if (!payload || !("details" in payload)) {
|
|
@@ -7355,7 +7895,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
7355
7895
|
return details;
|
|
7356
7896
|
}
|
|
7357
7897
|
function createResultError(response, result, normalized) {
|
|
7358
|
-
const rawRecord =
|
|
7898
|
+
const rawRecord = isRecord10(response.raw) ? response.raw : null;
|
|
7359
7899
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
7360
7900
|
const message = firstNonEmptyString2(
|
|
7361
7901
|
response.error,
|
|
@@ -7418,6 +7958,43 @@ function asAthenaJsonObject(value) {
|
|
|
7418
7958
|
function asAthenaJsonObjectArray(values) {
|
|
7419
7959
|
return values;
|
|
7420
7960
|
}
|
|
7961
|
+
function parseArbitraryResponseBody(rawText, contentType) {
|
|
7962
|
+
if (!rawText) {
|
|
7963
|
+
return null;
|
|
7964
|
+
}
|
|
7965
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
7966
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
7967
|
+
if (!looksJson) {
|
|
7968
|
+
return rawText;
|
|
7969
|
+
}
|
|
7970
|
+
try {
|
|
7971
|
+
return JSON.parse(rawText);
|
|
7972
|
+
} catch {
|
|
7973
|
+
return rawText;
|
|
7974
|
+
}
|
|
7975
|
+
}
|
|
7976
|
+
function toRequestQueryString(query) {
|
|
7977
|
+
if (!query) {
|
|
7978
|
+
return "";
|
|
7979
|
+
}
|
|
7980
|
+
const params = new URLSearchParams();
|
|
7981
|
+
for (const [key, value] of Object.entries(query)) {
|
|
7982
|
+
if (value === void 0 || value === null) {
|
|
7983
|
+
continue;
|
|
7984
|
+
}
|
|
7985
|
+
if (Array.isArray(value)) {
|
|
7986
|
+
for (const item of value) {
|
|
7987
|
+
if (item !== void 0 && item !== null) {
|
|
7988
|
+
params.append(key, String(item));
|
|
7989
|
+
}
|
|
7990
|
+
}
|
|
7991
|
+
continue;
|
|
7992
|
+
}
|
|
7993
|
+
params.set(key, String(value));
|
|
7994
|
+
}
|
|
7995
|
+
const encoded = params.toString();
|
|
7996
|
+
return encoded ? `?${encoded}` : "";
|
|
7997
|
+
}
|
|
7421
7998
|
function normalizeSelectColumnsInput(columns) {
|
|
7422
7999
|
if (columns === void 0) {
|
|
7423
8000
|
return void 0;
|
|
@@ -8780,6 +9357,15 @@ function appendServicePath(baseUrl, segment) {
|
|
|
8780
9357
|
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
8781
9358
|
return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
|
|
8782
9359
|
}
|
|
9360
|
+
function appendRealtimeGatewayPath(baseUrl) {
|
|
9361
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
9362
|
+
const wsUrl = new URL(normalizedBaseUrl);
|
|
9363
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
9364
|
+
wsUrl.pathname = `${wsUrl.pathname.replace(/\/+$/, "")}/wss/gateway`;
|
|
9365
|
+
wsUrl.search = "";
|
|
9366
|
+
wsUrl.hash = "";
|
|
9367
|
+
return wsUrl.toString();
|
|
9368
|
+
}
|
|
8783
9369
|
function resolveServiceUrlOverride(value, label) {
|
|
8784
9370
|
return resolveClientServiceBaseUrl(value, label);
|
|
8785
9371
|
}
|
|
@@ -8788,6 +9374,8 @@ function resolveServiceUrls(config) {
|
|
|
8788
9374
|
return {
|
|
8789
9375
|
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
9376
|
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),
|
|
9377
|
+
chatUrl: resolveServiceUrlOverride(config.chat?.url, "Athena chat base URL") ?? resolveServiceUrlOverride(config.chatUrl, "Athena chat base URL") ?? (baseUrl ? appendServicePath(baseUrl, "chat") : void 0),
|
|
9378
|
+
chatWsUrl: normalizeOptionalString2(config.chat?.wsUrl) ?? normalizeOptionalString2(config.chatWsUrl) ?? (baseUrl ? appendRealtimeGatewayPath(baseUrl) : void 0),
|
|
8791
9379
|
storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
|
|
8792
9380
|
};
|
|
8793
9381
|
}
|
|
@@ -8880,6 +9468,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8880
9468
|
} : void 0,
|
|
8881
9469
|
db: base.db ? { ...base.db } : void 0,
|
|
8882
9470
|
gateway: base.gateway ? { ...base.gateway } : void 0,
|
|
9471
|
+
chat: base.chat ? { ...base.chat } : void 0,
|
|
8883
9472
|
storage: base.storage ? { ...base.storage } : void 0
|
|
8884
9473
|
};
|
|
8885
9474
|
}
|
|
@@ -8890,6 +9479,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8890
9479
|
auth: mergeAuthClientOptions(base.auth, overrides.auth),
|
|
8891
9480
|
db: mergeServiceUrlOverrides(base.db, overrides.db),
|
|
8892
9481
|
gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
|
|
9482
|
+
chat: mergeServiceUrlOverrides(base.chat, overrides.chat),
|
|
8893
9483
|
storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
|
|
8894
9484
|
};
|
|
8895
9485
|
}
|
|
@@ -8948,6 +9538,9 @@ function resolveCreateClientConfig(config) {
|
|
|
8948
9538
|
headers: config.headers,
|
|
8949
9539
|
auth: config.auth,
|
|
8950
9540
|
authUrl: resolvedUrls.authUrl,
|
|
9541
|
+
chat: config.chat,
|
|
9542
|
+
chatUrl: resolvedUrls.chatUrl,
|
|
9543
|
+
chatWsUrl: resolvedUrls.chatWsUrl,
|
|
8951
9544
|
storageUrl: resolvedUrls.storageUrl,
|
|
8952
9545
|
experimental: config.experimental
|
|
8953
9546
|
};
|
|
@@ -9032,6 +9625,119 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9032
9625
|
queryTracer
|
|
9033
9626
|
);
|
|
9034
9627
|
const db = createDbModule({ from, rpc, query });
|
|
9628
|
+
const chat = createChatModule({
|
|
9629
|
+
baseUrl: config.chatUrl,
|
|
9630
|
+
apiKey: config.apiKey,
|
|
9631
|
+
client: config.client,
|
|
9632
|
+
headers: config.headers,
|
|
9633
|
+
bearerToken: normalizedAuthConfig?.bearerToken,
|
|
9634
|
+
cookie: normalizedAuthConfig?.cookie,
|
|
9635
|
+
sessionToken: normalizedAuthConfig?.sessionToken,
|
|
9636
|
+
forceNoCache: config.forceNoCache,
|
|
9637
|
+
wsUrl: config.chatWsUrl,
|
|
9638
|
+
webSocketFactory: config.chat?.webSocketFactory ?? void 0
|
|
9639
|
+
});
|
|
9640
|
+
const request2 = async (options) => {
|
|
9641
|
+
const method = options.method ?? "GET";
|
|
9642
|
+
const responseType = options.responseType ?? "json";
|
|
9643
|
+
const service = options.service ?? "db";
|
|
9644
|
+
const baseUrlByService = {
|
|
9645
|
+
db: config.baseUrl,
|
|
9646
|
+
auth: config.authUrl,
|
|
9647
|
+
chat: config.chatUrl,
|
|
9648
|
+
storage: config.storageUrl
|
|
9649
|
+
};
|
|
9650
|
+
const resolvedBaseUrl = options.url ?? baseUrlByService[service];
|
|
9651
|
+
if (!resolvedBaseUrl) {
|
|
9652
|
+
throw new Error(
|
|
9653
|
+
`Athena ${service} base URL is not configured. Pass createClient({ url }) for unified routing or set the service-specific URL first.`
|
|
9654
|
+
);
|
|
9655
|
+
}
|
|
9656
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(resolvedBaseUrl, {
|
|
9657
|
+
label: `Athena ${service} base URL`
|
|
9658
|
+
});
|
|
9659
|
+
const normalizedPath = options.url ? "" : (() => {
|
|
9660
|
+
const path = options.path?.trim();
|
|
9661
|
+
if (!path) {
|
|
9662
|
+
throw new Error("client.request(...) requires either an absolute url or a non-empty path.");
|
|
9663
|
+
}
|
|
9664
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
9665
|
+
})();
|
|
9666
|
+
const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
|
|
9667
|
+
const headers = {
|
|
9668
|
+
"X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
|
|
9669
|
+
...config.headers ?? {},
|
|
9670
|
+
...options.headers ?? {}
|
|
9671
|
+
};
|
|
9672
|
+
if (service !== "auth") {
|
|
9673
|
+
headers.apikey = headers.apikey ?? config.apiKey;
|
|
9674
|
+
headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
|
|
9675
|
+
if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
|
|
9676
|
+
headers["X-Athena-Client"] = config.client;
|
|
9677
|
+
}
|
|
9678
|
+
if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
|
|
9679
|
+
headers["X-User-Id"] = config.userId;
|
|
9680
|
+
}
|
|
9681
|
+
if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
|
|
9682
|
+
headers["X-Organization-Id"] = config.organizationId;
|
|
9683
|
+
}
|
|
9684
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9685
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9686
|
+
}
|
|
9687
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
|
|
9688
|
+
headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
|
|
9689
|
+
}
|
|
9690
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9691
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9692
|
+
}
|
|
9693
|
+
} else {
|
|
9694
|
+
const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
|
|
9695
|
+
if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
|
|
9696
|
+
headers.apikey = headers.apikey ?? authApiKey;
|
|
9697
|
+
headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
|
|
9698
|
+
}
|
|
9699
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
|
|
9700
|
+
headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
|
|
9701
|
+
}
|
|
9702
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9703
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9704
|
+
}
|
|
9705
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9706
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9707
|
+
}
|
|
9708
|
+
}
|
|
9709
|
+
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";
|
|
9710
|
+
if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
|
|
9711
|
+
headers["Content-Type"] = "application/json";
|
|
9712
|
+
}
|
|
9713
|
+
const response = await fetch(targetUrl, {
|
|
9714
|
+
method,
|
|
9715
|
+
headers,
|
|
9716
|
+
body: options.body === void 0 || options.body === null ? void 0 : shouldSendJsonBody ? JSON.stringify(options.body) : options.body,
|
|
9717
|
+
signal: options.signal,
|
|
9718
|
+
credentials: options.credentials
|
|
9719
|
+
});
|
|
9720
|
+
if (responseType === "response") {
|
|
9721
|
+
return {
|
|
9722
|
+
ok: response.ok,
|
|
9723
|
+
status: response.status,
|
|
9724
|
+
statusText: response.statusText,
|
|
9725
|
+
headers: response.headers,
|
|
9726
|
+
data: null,
|
|
9727
|
+
raw: response
|
|
9728
|
+
};
|
|
9729
|
+
}
|
|
9730
|
+
const rawText = await response.text();
|
|
9731
|
+
const parsed = responseType === "text" ? rawText : parseArbitraryResponseBody(rawText, response.headers.get("content-type"));
|
|
9732
|
+
return {
|
|
9733
|
+
ok: response.ok,
|
|
9734
|
+
status: response.status,
|
|
9735
|
+
statusText: response.statusText,
|
|
9736
|
+
headers: response.headers,
|
|
9737
|
+
data: parsed,
|
|
9738
|
+
raw: response
|
|
9739
|
+
};
|
|
9740
|
+
};
|
|
9035
9741
|
const withContext = (context) => createClientFromInput(
|
|
9036
9742
|
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
9037
9743
|
);
|
|
@@ -9047,8 +9753,10 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
9047
9753
|
db,
|
|
9048
9754
|
rpc,
|
|
9049
9755
|
query,
|
|
9756
|
+
request: request2,
|
|
9050
9757
|
verifyConnection: gateway.verifyConnection,
|
|
9051
9758
|
auth: auth.auth,
|
|
9759
|
+
chat,
|
|
9052
9760
|
withContext,
|
|
9053
9761
|
withSession,
|
|
9054
9762
|
withOptions: authWithOptions
|