@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/index.js
CHANGED
|
@@ -664,8 +664,8 @@ function deleteSessionCookie(ctx, skipDontRememberMe) {
|
|
|
664
664
|
expireCookie(ctx, ctx.context.authCookies.dontRememberToken);
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
|
-
var getSessionCookie = (
|
|
668
|
-
const cookies = (
|
|
667
|
+
var getSessionCookie = (request2, config) => {
|
|
668
|
+
const cookies = (request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers).get("cookie");
|
|
669
669
|
if (!cookies) {
|
|
670
670
|
return null;
|
|
671
671
|
}
|
|
@@ -685,8 +685,8 @@ var getSessionCookie = (request, config) => {
|
|
|
685
685
|
}
|
|
686
686
|
return null;
|
|
687
687
|
};
|
|
688
|
-
var getCookieCache = async (
|
|
689
|
-
const headers =
|
|
688
|
+
var getCookieCache = async (request2, config) => {
|
|
689
|
+
const headers = request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers;
|
|
690
690
|
const cookieHeader = headers.get("cookie");
|
|
691
691
|
if (!cookieHeader) {
|
|
692
692
|
return null;
|
|
@@ -804,7 +804,7 @@ var getCookieCache = async (request, config) => {
|
|
|
804
804
|
|
|
805
805
|
// package.json
|
|
806
806
|
var package_default = {
|
|
807
|
-
version: "2.
|
|
807
|
+
version: "2.11.0"
|
|
808
808
|
};
|
|
809
809
|
|
|
810
810
|
// src/sdk-version.ts
|
|
@@ -1856,6 +1856,87 @@ function mergeCallOptions(base, override) {
|
|
|
1856
1856
|
}
|
|
1857
1857
|
};
|
|
1858
1858
|
}
|
|
1859
|
+
function copyDefinedField(target, source, targetKey, sourceKey) {
|
|
1860
|
+
if (!(sourceKey in source)) {
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
const value = source[sourceKey];
|
|
1864
|
+
if (value !== void 0) {
|
|
1865
|
+
target[targetKey] = value;
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
function normalizeEmailTemplateAttachmentsValue(value) {
|
|
1869
|
+
if (typeof value === "string" || value == null) {
|
|
1870
|
+
return value;
|
|
1871
|
+
}
|
|
1872
|
+
if (Array.isArray(value)) {
|
|
1873
|
+
return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
|
|
1874
|
+
}
|
|
1875
|
+
if (typeof value !== "object") {
|
|
1876
|
+
return value;
|
|
1877
|
+
}
|
|
1878
|
+
const attachment = { ...value };
|
|
1879
|
+
copyDefinedField(attachment, attachment, "file_url", "fileUrl");
|
|
1880
|
+
delete attachment.fileUrl;
|
|
1881
|
+
return attachment;
|
|
1882
|
+
}
|
|
1883
|
+
function normalizeAdminEmailTemplatePayload(payload) {
|
|
1884
|
+
const normalized = { ...payload };
|
|
1885
|
+
copyDefinedField(normalized, payload, "template_key", "templateKey");
|
|
1886
|
+
copyDefinedField(normalized, payload, "event_type", "eventType");
|
|
1887
|
+
copyDefinedField(normalized, payload, "subject_template", "subjectTemplate");
|
|
1888
|
+
copyDefinedField(normalized, payload, "text_template", "textTemplate");
|
|
1889
|
+
copyDefinedField(normalized, payload, "html_template", "htmlTemplate");
|
|
1890
|
+
copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
|
|
1891
|
+
copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
|
|
1892
|
+
copyDefinedField(normalized, payload, "is_active", "isActive");
|
|
1893
|
+
if (Object.hasOwn(payload, "attachments")) {
|
|
1894
|
+
normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
|
|
1895
|
+
}
|
|
1896
|
+
delete normalized.templateKey;
|
|
1897
|
+
delete normalized.eventType;
|
|
1898
|
+
delete normalized.subjectTemplate;
|
|
1899
|
+
delete normalized.textTemplate;
|
|
1900
|
+
delete normalized.htmlTemplate;
|
|
1901
|
+
delete normalized.variableBindings;
|
|
1902
|
+
delete normalized.attachmentFailureMode;
|
|
1903
|
+
delete normalized.isActive;
|
|
1904
|
+
return normalized;
|
|
1905
|
+
}
|
|
1906
|
+
function toReactEmailTemplateCompatibilityInput(input) {
|
|
1907
|
+
const payload = input;
|
|
1908
|
+
const compatibility = { ...payload };
|
|
1909
|
+
copyDefinedField(compatibility, payload, "templateKey", "template_key");
|
|
1910
|
+
copyDefinedField(compatibility, payload, "eventType", "event_type");
|
|
1911
|
+
copyDefinedField(compatibility, payload, "subjectTemplate", "subject_template");
|
|
1912
|
+
copyDefinedField(compatibility, payload, "textTemplate", "text_template");
|
|
1913
|
+
copyDefinedField(compatibility, payload, "htmlTemplate", "html_template");
|
|
1914
|
+
copyDefinedField(compatibility, payload, "variableBindings", "variable_bindings");
|
|
1915
|
+
copyDefinedField(compatibility, payload, "attachmentFailureMode", "attachment_failure_mode");
|
|
1916
|
+
copyDefinedField(compatibility, payload, "isActive", "is_active");
|
|
1917
|
+
return compatibility;
|
|
1918
|
+
}
|
|
1919
|
+
function normalizeAdminEmailTemplateSendPayload(payload) {
|
|
1920
|
+
const normalized = { ...payload };
|
|
1921
|
+
copyDefinedField(normalized, payload, "template_id", "templateId");
|
|
1922
|
+
copyDefinedField(normalized, payload, "recipient_email", "recipientEmail");
|
|
1923
|
+
copyDefinedField(normalized, payload, "render_variables", "renderVariables");
|
|
1924
|
+
copyDefinedField(normalized, payload, "user_id", "userId");
|
|
1925
|
+
copyDefinedField(normalized, payload, "organization_id", "organizationId");
|
|
1926
|
+
copyDefinedField(normalized, payload, "session_token", "sessionToken");
|
|
1927
|
+
copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
|
|
1928
|
+
if (Object.hasOwn(payload, "attachments")) {
|
|
1929
|
+
normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
|
|
1930
|
+
}
|
|
1931
|
+
delete normalized.templateId;
|
|
1932
|
+
delete normalized.recipientEmail;
|
|
1933
|
+
delete normalized.renderVariables;
|
|
1934
|
+
delete normalized.userId;
|
|
1935
|
+
delete normalized.organizationId;
|
|
1936
|
+
delete normalized.sessionToken;
|
|
1937
|
+
delete normalized.attachmentFailureMode;
|
|
1938
|
+
return normalized;
|
|
1939
|
+
}
|
|
1859
1940
|
function toSessionGuardFailure(sessionResult) {
|
|
1860
1941
|
if (sessionResult.status === 401 || sessionResult.data == null) {
|
|
1861
1942
|
return {
|
|
@@ -2162,7 +2243,7 @@ function createAuthClient(config = {}) {
|
|
|
2162
2243
|
...config,
|
|
2163
2244
|
baseUrl: normalizedBaseUrl
|
|
2164
2245
|
};
|
|
2165
|
-
const
|
|
2246
|
+
const request2 = (input, options) => {
|
|
2166
2247
|
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
2167
2248
|
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
2168
2249
|
return callAuthEndpoint(
|
|
@@ -2175,7 +2256,7 @@ function createAuthClient(config = {}) {
|
|
|
2175
2256
|
};
|
|
2176
2257
|
const postGeneric = (endpoint, input, options) => {
|
|
2177
2258
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
2178
|
-
return
|
|
2259
|
+
return request2(
|
|
2179
2260
|
{
|
|
2180
2261
|
endpoint,
|
|
2181
2262
|
method: "POST",
|
|
@@ -2187,7 +2268,7 @@ function createAuthClient(config = {}) {
|
|
|
2187
2268
|
};
|
|
2188
2269
|
const getGeneric = (endpoint, input, options) => {
|
|
2189
2270
|
const { fetchOptions } = extractFetchOptions(input);
|
|
2190
|
-
return
|
|
2271
|
+
return request2(
|
|
2191
2272
|
{
|
|
2192
2273
|
endpoint,
|
|
2193
2274
|
method: "GET",
|
|
@@ -2199,7 +2280,7 @@ function createAuthClient(config = {}) {
|
|
|
2199
2280
|
const getWithQuery = (endpoint, input, options) => {
|
|
2200
2281
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
2201
2282
|
const query = payload?.query;
|
|
2202
|
-
return
|
|
2283
|
+
return request2(
|
|
2203
2284
|
{
|
|
2204
2285
|
endpoint,
|
|
2205
2286
|
method: "GET",
|
|
@@ -2217,18 +2298,19 @@ function createAuthClient(config = {}) {
|
|
|
2217
2298
|
htmlField: "htmlBody",
|
|
2218
2299
|
textField: "textBody"
|
|
2219
2300
|
}, withReactEmailRoute(route));
|
|
2220
|
-
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(input, {
|
|
2301
|
+
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(toReactEmailTemplateCompatibilityInput(input), {
|
|
2221
2302
|
htmlField: "htmlTemplate",
|
|
2222
2303
|
textField: "textTemplate",
|
|
2223
2304
|
variablesField: "variables"
|
|
2224
2305
|
}, withReactEmailRoute(route)).then((payload) => {
|
|
2306
|
+
const normalizedPayload = normalizeAdminEmailTemplatePayload(payload);
|
|
2225
2307
|
if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
|
|
2226
2308
|
assertAthenaAuthTemplateVariables(
|
|
2227
2309
|
payload.variables,
|
|
2228
2310
|
`${route} variables`
|
|
2229
2311
|
);
|
|
2230
2312
|
}
|
|
2231
|
-
return
|
|
2313
|
+
return normalizedPayload;
|
|
2232
2314
|
});
|
|
2233
2315
|
const requireSession = async (input, options) => {
|
|
2234
2316
|
const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
|
|
@@ -2804,7 +2886,15 @@ function createAuthClient(config = {}) {
|
|
|
2804
2886
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
2805
2887
|
options
|
|
2806
2888
|
),
|
|
2807
|
-
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
|
|
2889
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
|
|
2890
|
+
send: (input, options) => postGeneric(
|
|
2891
|
+
"/admin/email-template/send",
|
|
2892
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
2893
|
+
options
|
|
2894
|
+
)
|
|
2895
|
+
},
|
|
2896
|
+
eventType: {
|
|
2897
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
2808
2898
|
}
|
|
2809
2899
|
},
|
|
2810
2900
|
emailTemplate: {
|
|
@@ -2820,7 +2910,15 @@ function createAuthClient(config = {}) {
|
|
|
2820
2910
|
"/admin/email-template/update",
|
|
2821
2911
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
2822
2912
|
options
|
|
2913
|
+
),
|
|
2914
|
+
send: (input, options) => postGeneric(
|
|
2915
|
+
"/admin/email-template/send",
|
|
2916
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
2917
|
+
options
|
|
2823
2918
|
)
|
|
2919
|
+
},
|
|
2920
|
+
emailEventType: {
|
|
2921
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
2824
2922
|
}
|
|
2825
2923
|
},
|
|
2826
2924
|
apiKey: {
|
|
@@ -2860,7 +2958,7 @@ function createAuthClient(config = {}) {
|
|
|
2860
2958
|
throw new Error("callback.provider requires non-empty code and state values");
|
|
2861
2959
|
}
|
|
2862
2960
|
const endpoint = `/callback/${encodeURIComponent(provider)}`;
|
|
2863
|
-
return
|
|
2961
|
+
return request2({
|
|
2864
2962
|
endpoint,
|
|
2865
2963
|
method: "GET",
|
|
2866
2964
|
query: {
|
|
@@ -2874,7 +2972,7 @@ function createAuthClient(config = {}) {
|
|
|
2874
2972
|
};
|
|
2875
2973
|
return {
|
|
2876
2974
|
baseUrl: normalizedBaseUrl,
|
|
2877
|
-
request,
|
|
2975
|
+
request: request2,
|
|
2878
2976
|
signIn: {
|
|
2879
2977
|
email: (input, options) => executePostWithCompatibleInput(
|
|
2880
2978
|
resolvedConfig,
|
|
@@ -3615,16 +3713,16 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3615
3713
|
};
|
|
3616
3714
|
});
|
|
3617
3715
|
input.onProgress?.(createProgressSnapshot("preparing", sources, 0, 0, 0));
|
|
3618
|
-
const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((
|
|
3716
|
+
const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request2) => request2.uploadRequest) }, options)).files;
|
|
3619
3717
|
const aggregateLoaded = new Array(uploadRequests.length).fill(0);
|
|
3620
3718
|
const uploaded = [];
|
|
3621
3719
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
3622
|
-
const
|
|
3720
|
+
const request2 = uploadRequests[index];
|
|
3623
3721
|
const uploadUrl = uploadUrls[index];
|
|
3624
3722
|
const response = await putUploadBody(
|
|
3625
3723
|
uploadUrl.upload.url,
|
|
3626
3724
|
uploadUrl.upload.headers ?? {},
|
|
3627
|
-
|
|
3725
|
+
request2.source,
|
|
3628
3726
|
input,
|
|
3629
3727
|
options,
|
|
3630
3728
|
(progress) => {
|
|
@@ -3635,13 +3733,13 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3635
3733
|
uploaded.push({
|
|
3636
3734
|
file: uploadUrl.file,
|
|
3637
3735
|
upload: uploadUrl.upload,
|
|
3638
|
-
source:
|
|
3639
|
-
fileName:
|
|
3640
|
-
storage_key:
|
|
3736
|
+
source: request2.source.source,
|
|
3737
|
+
fileName: request2.source.fileName,
|
|
3738
|
+
storage_key: request2.uploadRequest.storage_key,
|
|
3641
3739
|
response
|
|
3642
3740
|
});
|
|
3643
|
-
aggregateLoaded[index] =
|
|
3644
|
-
input.onProgress?.(createProgressSnapshot("complete", sources, index,
|
|
3741
|
+
aggregateLoaded[index] = request2.source.sizeBytes;
|
|
3742
|
+
input.onProgress?.(createProgressSnapshot("complete", sources, index, request2.source.sizeBytes, sum(aggregateLoaded)));
|
|
3645
3743
|
}
|
|
3646
3744
|
return {
|
|
3647
3745
|
files: uploaded,
|
|
@@ -5616,6 +5714,517 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
5616
5714
|
};
|
|
5617
5715
|
}
|
|
5618
5716
|
|
|
5717
|
+
// src/chat/module.ts
|
|
5718
|
+
var SDK_NAME3 = "xylex-group/athena-chat";
|
|
5719
|
+
var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
|
|
5720
|
+
var NO_CACHE_HEADER_VALUE3 = "no-cache";
|
|
5721
|
+
var AthenaChatError = class extends Error {
|
|
5722
|
+
status;
|
|
5723
|
+
endpoint;
|
|
5724
|
+
method;
|
|
5725
|
+
requestId;
|
|
5726
|
+
body;
|
|
5727
|
+
constructor(input) {
|
|
5728
|
+
super(input.message);
|
|
5729
|
+
this.name = "AthenaChatError";
|
|
5730
|
+
this.status = input.status;
|
|
5731
|
+
this.endpoint = input.endpoint;
|
|
5732
|
+
this.method = input.method;
|
|
5733
|
+
this.requestId = input.requestId;
|
|
5734
|
+
this.body = input.body;
|
|
5735
|
+
}
|
|
5736
|
+
};
|
|
5737
|
+
function deriveRealtimeInfoUrl(wsUrl) {
|
|
5738
|
+
if (!wsUrl) {
|
|
5739
|
+
return void 0;
|
|
5740
|
+
}
|
|
5741
|
+
const parsed = new URL(normalizeWsUrl(wsUrl, "Athena chat WebSocket URL"));
|
|
5742
|
+
parsed.protocol = parsed.protocol === "wss:" ? "https:" : "http:";
|
|
5743
|
+
parsed.pathname = parsed.pathname.replace(/\/wss\/gateway$/, "/wss/info");
|
|
5744
|
+
return parsed.toString();
|
|
5745
|
+
}
|
|
5746
|
+
function normalizeWsUrl(value, label) {
|
|
5747
|
+
const normalized = value.trim();
|
|
5748
|
+
if (!normalized) {
|
|
5749
|
+
throw new Error(`${label} is required.`);
|
|
5750
|
+
}
|
|
5751
|
+
let parsed;
|
|
5752
|
+
try {
|
|
5753
|
+
parsed = new URL(normalized);
|
|
5754
|
+
} catch {
|
|
5755
|
+
throw new Error(`${label} must be a valid absolute ws(s) URL.`);
|
|
5756
|
+
}
|
|
5757
|
+
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
|
|
5758
|
+
throw new Error(`${label} must use ws or wss.`);
|
|
5759
|
+
}
|
|
5760
|
+
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
5761
|
+
return parsed.toString().replace(/\/$/, "");
|
|
5762
|
+
}
|
|
5763
|
+
function isRecord7(value) {
|
|
5764
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5765
|
+
}
|
|
5766
|
+
function normalizeHeaderValue3(value) {
|
|
5767
|
+
return value ? value : void 0;
|
|
5768
|
+
}
|
|
5769
|
+
function parseResponseBody4(rawText, contentType) {
|
|
5770
|
+
if (!rawText) {
|
|
5771
|
+
return { parsed: null, parseFailed: false };
|
|
5772
|
+
}
|
|
5773
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
5774
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
5775
|
+
if (!looksJson) {
|
|
5776
|
+
return { parsed: rawText, parseFailed: false };
|
|
5777
|
+
}
|
|
5778
|
+
try {
|
|
5779
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
5780
|
+
} catch {
|
|
5781
|
+
return { parsed: rawText, parseFailed: true };
|
|
5782
|
+
}
|
|
5783
|
+
}
|
|
5784
|
+
function resolveRequestId3(headers) {
|
|
5785
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
5786
|
+
}
|
|
5787
|
+
function resolveErrorMessage4(payload, fallback) {
|
|
5788
|
+
if (isRecord7(payload)) {
|
|
5789
|
+
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
5790
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
5791
|
+
return candidate.trim();
|
|
5792
|
+
}
|
|
5793
|
+
}
|
|
5794
|
+
}
|
|
5795
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
5796
|
+
return payload.trim();
|
|
5797
|
+
}
|
|
5798
|
+
return fallback;
|
|
5799
|
+
}
|
|
5800
|
+
function encodePathSegment(value, label) {
|
|
5801
|
+
const normalized = value.trim();
|
|
5802
|
+
if (!normalized) {
|
|
5803
|
+
throw new Error(`${label} is required.`);
|
|
5804
|
+
}
|
|
5805
|
+
return encodeURIComponent(normalized);
|
|
5806
|
+
}
|
|
5807
|
+
function encodeQuery(query) {
|
|
5808
|
+
if (!query) {
|
|
5809
|
+
return "";
|
|
5810
|
+
}
|
|
5811
|
+
const params = new URLSearchParams();
|
|
5812
|
+
for (const [key, value] of Object.entries(query)) {
|
|
5813
|
+
if (value === void 0 || value === null) {
|
|
5814
|
+
continue;
|
|
5815
|
+
}
|
|
5816
|
+
if (Array.isArray(value)) {
|
|
5817
|
+
for (const item of value) {
|
|
5818
|
+
if (item !== void 0 && item !== null) {
|
|
5819
|
+
params.append(key, String(item));
|
|
5820
|
+
}
|
|
5821
|
+
}
|
|
5822
|
+
continue;
|
|
5823
|
+
}
|
|
5824
|
+
params.set(key, String(value));
|
|
5825
|
+
}
|
|
5826
|
+
const encoded = params.toString();
|
|
5827
|
+
return encoded ? `?${encoded}` : "";
|
|
5828
|
+
}
|
|
5829
|
+
function createSocket(factory, url, protocols) {
|
|
5830
|
+
try {
|
|
5831
|
+
return new factory(url, protocols);
|
|
5832
|
+
} catch (error) {
|
|
5833
|
+
if (error instanceof TypeError) {
|
|
5834
|
+
return factory(url, protocols);
|
|
5835
|
+
}
|
|
5836
|
+
throw error;
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
function buildHeaders3(config, options) {
|
|
5840
|
+
const headers = {
|
|
5841
|
+
Accept: "application/json",
|
|
5842
|
+
apikey: config.apiKey,
|
|
5843
|
+
"x-api-key": config.apiKey,
|
|
5844
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE3
|
|
5845
|
+
};
|
|
5846
|
+
if (config.client || options?.client) {
|
|
5847
|
+
headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
|
|
5848
|
+
}
|
|
5849
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
5850
|
+
if (typeof bearerToken === "string" && bearerToken.trim()) {
|
|
5851
|
+
headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
|
|
5852
|
+
}
|
|
5853
|
+
const cookie = options?.cookie ?? config.cookie;
|
|
5854
|
+
if (typeof cookie === "string" && cookie.trim()) {
|
|
5855
|
+
headers.Cookie = cookie;
|
|
5856
|
+
}
|
|
5857
|
+
const sessionToken = options?.sessionToken ?? config.sessionToken;
|
|
5858
|
+
if (typeof sessionToken === "string" && sessionToken.trim()) {
|
|
5859
|
+
headers["X-Athena-Auth-Session-Token"] = sessionToken;
|
|
5860
|
+
}
|
|
5861
|
+
if (config.forceNoCache || options?.forceNoCache) {
|
|
5862
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
|
|
5863
|
+
}
|
|
5864
|
+
for (const source of [config.headers, options?.headers]) {
|
|
5865
|
+
for (const [key, value] of Object.entries(source ?? {})) {
|
|
5866
|
+
const normalized = normalizeHeaderValue3(value);
|
|
5867
|
+
if (normalized) {
|
|
5868
|
+
headers[key] = normalized;
|
|
5869
|
+
}
|
|
5870
|
+
}
|
|
5871
|
+
}
|
|
5872
|
+
return headers;
|
|
5873
|
+
}
|
|
5874
|
+
function withJsonBody(init, body) {
|
|
5875
|
+
return {
|
|
5876
|
+
...init,
|
|
5877
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
5878
|
+
headers: {
|
|
5879
|
+
"Content-Type": "application/json",
|
|
5880
|
+
...init.headers
|
|
5881
|
+
}
|
|
5882
|
+
};
|
|
5883
|
+
}
|
|
5884
|
+
async function request(config, method, endpoint, options, body) {
|
|
5885
|
+
if (!config.baseUrl) {
|
|
5886
|
+
throw new Error(
|
|
5887
|
+
"Athena chat base URL is not configured. Pass createClient({ url }) for unified routing or set chat.url / chatUrl explicitly."
|
|
5888
|
+
);
|
|
5889
|
+
}
|
|
5890
|
+
const url = `${config.baseUrl}${endpoint}`;
|
|
5891
|
+
const init = {
|
|
5892
|
+
method,
|
|
5893
|
+
headers: buildHeaders3(config, options),
|
|
5894
|
+
signal: options?.signal
|
|
5895
|
+
};
|
|
5896
|
+
const finalInit = body === void 0 || method === "GET" ? init : withJsonBody(init, body);
|
|
5897
|
+
const response = await fetch(url, finalInit);
|
|
5898
|
+
const rawText = await response.text();
|
|
5899
|
+
const { parsed } = parseResponseBody4(rawText, response.headers.get("content-type"));
|
|
5900
|
+
if (!response.ok) {
|
|
5901
|
+
throw new AthenaChatError({
|
|
5902
|
+
message: resolveErrorMessage4(parsed, `Athena chat ${method} ${endpoint} failed with ${response.status}`),
|
|
5903
|
+
status: response.status,
|
|
5904
|
+
endpoint,
|
|
5905
|
+
method,
|
|
5906
|
+
requestId: resolveRequestId3(response.headers),
|
|
5907
|
+
body: parsed
|
|
5908
|
+
});
|
|
5909
|
+
}
|
|
5910
|
+
return parsed;
|
|
5911
|
+
}
|
|
5912
|
+
function unwrapEnvelopeData(payload) {
|
|
5913
|
+
return payload.data;
|
|
5914
|
+
}
|
|
5915
|
+
function createRealtimeConnection(config, options) {
|
|
5916
|
+
if (!config.wsUrl) {
|
|
5917
|
+
throw new Error(
|
|
5918
|
+
"Athena chat WebSocket URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
5919
|
+
);
|
|
5920
|
+
}
|
|
5921
|
+
const wsFactory = config.webSocketFactory ?? globalThis.WebSocket;
|
|
5922
|
+
if (!wsFactory) {
|
|
5923
|
+
throw new Error(
|
|
5924
|
+
"No WebSocket implementation is available. Provide chat.webSocketFactory in createClient(...) or run in a runtime with global WebSocket support."
|
|
5925
|
+
);
|
|
5926
|
+
}
|
|
5927
|
+
const socket = createSocket(wsFactory, config.wsUrl, options?.protocols);
|
|
5928
|
+
const send = (command) => {
|
|
5929
|
+
socket.send(JSON.stringify(command));
|
|
5930
|
+
};
|
|
5931
|
+
if (options?.onMessage) {
|
|
5932
|
+
const listener = (event) => {
|
|
5933
|
+
const messageEvent = event;
|
|
5934
|
+
const raw = messageEvent?.data;
|
|
5935
|
+
if (typeof raw !== "string") {
|
|
5936
|
+
return;
|
|
5937
|
+
}
|
|
5938
|
+
try {
|
|
5939
|
+
options.onMessage?.(JSON.parse(raw));
|
|
5940
|
+
} catch {
|
|
5941
|
+
options.onMessage?.({ type: "error", error: "Invalid JSON message from Athena chat realtime gateway." });
|
|
5942
|
+
}
|
|
5943
|
+
};
|
|
5944
|
+
if (typeof socket.addEventListener === "function") {
|
|
5945
|
+
socket.addEventListener("message", listener);
|
|
5946
|
+
} else {
|
|
5947
|
+
socket.onmessage = listener;
|
|
5948
|
+
}
|
|
5949
|
+
}
|
|
5950
|
+
const hello = (command) => {
|
|
5951
|
+
send({
|
|
5952
|
+
type: "auth.hello",
|
|
5953
|
+
token: command?.token,
|
|
5954
|
+
room_subscriptions: command?.room_subscriptions
|
|
5955
|
+
});
|
|
5956
|
+
};
|
|
5957
|
+
if (options?.hello) {
|
|
5958
|
+
const onOpen = () => hello({
|
|
5959
|
+
token: options.hello?.token ?? void 0,
|
|
5960
|
+
room_subscriptions: options.hello?.room_subscriptions ?? void 0
|
|
5961
|
+
});
|
|
5962
|
+
if (typeof socket.addEventListener === "function") {
|
|
5963
|
+
socket.addEventListener("open", onOpen);
|
|
5964
|
+
} else {
|
|
5965
|
+
socket.onopen = onOpen;
|
|
5966
|
+
}
|
|
5967
|
+
}
|
|
5968
|
+
return {
|
|
5969
|
+
socket,
|
|
5970
|
+
send,
|
|
5971
|
+
hello,
|
|
5972
|
+
subscribe(roomId, fromSeq) {
|
|
5973
|
+
send({
|
|
5974
|
+
type: "chat.subscribe",
|
|
5975
|
+
room_id: roomId,
|
|
5976
|
+
from_seq: fromSeq ?? void 0
|
|
5977
|
+
});
|
|
5978
|
+
},
|
|
5979
|
+
unsubscribe(roomId) {
|
|
5980
|
+
send({
|
|
5981
|
+
type: "chat.unsubscribe",
|
|
5982
|
+
room_id: roomId
|
|
5983
|
+
});
|
|
5984
|
+
},
|
|
5985
|
+
resume(rooms) {
|
|
5986
|
+
send({
|
|
5987
|
+
type: "chat.resume",
|
|
5988
|
+
rooms
|
|
5989
|
+
});
|
|
5990
|
+
},
|
|
5991
|
+
typingStart(roomId) {
|
|
5992
|
+
send({
|
|
5993
|
+
type: "chat.typing.start",
|
|
5994
|
+
room_id: roomId
|
|
5995
|
+
});
|
|
5996
|
+
},
|
|
5997
|
+
typingStop(roomId) {
|
|
5998
|
+
send({
|
|
5999
|
+
type: "chat.typing.stop",
|
|
6000
|
+
room_id: roomId
|
|
6001
|
+
});
|
|
6002
|
+
},
|
|
6003
|
+
presenceHeartbeat(activeRoomId) {
|
|
6004
|
+
send({
|
|
6005
|
+
type: "chat.presence.heartbeat",
|
|
6006
|
+
active_room_id: activeRoomId ?? void 0
|
|
6007
|
+
});
|
|
6008
|
+
},
|
|
6009
|
+
readUpTo(roomId, input) {
|
|
6010
|
+
send({
|
|
6011
|
+
type: "chat.read.up_to",
|
|
6012
|
+
room_id: roomId,
|
|
6013
|
+
message_id: input?.message_id ?? void 0,
|
|
6014
|
+
seq: input?.seq ?? void 0
|
|
6015
|
+
});
|
|
6016
|
+
},
|
|
6017
|
+
ping(at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
6018
|
+
send({
|
|
6019
|
+
type: "ping",
|
|
6020
|
+
at
|
|
6021
|
+
});
|
|
6022
|
+
},
|
|
6023
|
+
close(code, reason) {
|
|
6024
|
+
socket.close(code, reason);
|
|
6025
|
+
}
|
|
6026
|
+
};
|
|
6027
|
+
}
|
|
6028
|
+
function createChatModule(config) {
|
|
6029
|
+
const realtime = {
|
|
6030
|
+
info(options) {
|
|
6031
|
+
const realtimeInfoUrl = config.realtimeInfoUrl ?? deriveRealtimeInfoUrl(config.wsUrl);
|
|
6032
|
+
if (!realtimeInfoUrl) {
|
|
6033
|
+
throw new Error(
|
|
6034
|
+
"Athena chat realtime info URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
6035
|
+
);
|
|
6036
|
+
}
|
|
6037
|
+
return request(
|
|
6038
|
+
{
|
|
6039
|
+
...config,
|
|
6040
|
+
baseUrl: realtimeInfoUrl
|
|
6041
|
+
},
|
|
6042
|
+
"GET",
|
|
6043
|
+
"",
|
|
6044
|
+
options
|
|
6045
|
+
);
|
|
6046
|
+
},
|
|
6047
|
+
connect(options) {
|
|
6048
|
+
return createRealtimeConnection(config, options);
|
|
6049
|
+
}
|
|
6050
|
+
};
|
|
6051
|
+
return {
|
|
6052
|
+
room: {
|
|
6053
|
+
list(query, options) {
|
|
6054
|
+
return request(
|
|
6055
|
+
config,
|
|
6056
|
+
"GET",
|
|
6057
|
+
`/rooms${encodeQuery(query)}`,
|
|
6058
|
+
options
|
|
6059
|
+
);
|
|
6060
|
+
},
|
|
6061
|
+
create(input, options) {
|
|
6062
|
+
return request(config, "POST", "/rooms", options, input);
|
|
6063
|
+
},
|
|
6064
|
+
get(roomId, options) {
|
|
6065
|
+
return request(
|
|
6066
|
+
config,
|
|
6067
|
+
"GET",
|
|
6068
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6069
|
+
options
|
|
6070
|
+
);
|
|
6071
|
+
},
|
|
6072
|
+
update(roomId, input, options) {
|
|
6073
|
+
return request(
|
|
6074
|
+
config,
|
|
6075
|
+
"PATCH",
|
|
6076
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6077
|
+
options,
|
|
6078
|
+
input
|
|
6079
|
+
);
|
|
6080
|
+
},
|
|
6081
|
+
archive(roomId, options) {
|
|
6082
|
+
return request(
|
|
6083
|
+
config,
|
|
6084
|
+
"POST",
|
|
6085
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/archive`,
|
|
6086
|
+
options
|
|
6087
|
+
);
|
|
6088
|
+
},
|
|
6089
|
+
readCursor: {
|
|
6090
|
+
upTo(roomId, input, options) {
|
|
6091
|
+
return request(
|
|
6092
|
+
config,
|
|
6093
|
+
"POST",
|
|
6094
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/read-cursor`,
|
|
6095
|
+
options,
|
|
6096
|
+
input ?? {}
|
|
6097
|
+
);
|
|
6098
|
+
}
|
|
6099
|
+
},
|
|
6100
|
+
member: {
|
|
6101
|
+
list(roomId, options) {
|
|
6102
|
+
return request(
|
|
6103
|
+
config,
|
|
6104
|
+
"GET",
|
|
6105
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6106
|
+
options
|
|
6107
|
+
);
|
|
6108
|
+
},
|
|
6109
|
+
add(roomId, input, options) {
|
|
6110
|
+
return request(
|
|
6111
|
+
config,
|
|
6112
|
+
"POST",
|
|
6113
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6114
|
+
options,
|
|
6115
|
+
input
|
|
6116
|
+
);
|
|
6117
|
+
},
|
|
6118
|
+
remove(roomId, userId, options) {
|
|
6119
|
+
return request(
|
|
6120
|
+
config,
|
|
6121
|
+
"DELETE",
|
|
6122
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members/${encodePathSegment(userId, "chat user ID")}`,
|
|
6123
|
+
options
|
|
6124
|
+
);
|
|
6125
|
+
}
|
|
6126
|
+
},
|
|
6127
|
+
message: {
|
|
6128
|
+
list(roomId, query, options) {
|
|
6129
|
+
return request(
|
|
6130
|
+
config,
|
|
6131
|
+
"GET",
|
|
6132
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages${encodeQuery(query)}`,
|
|
6133
|
+
options
|
|
6134
|
+
);
|
|
6135
|
+
},
|
|
6136
|
+
send(roomId, input, options) {
|
|
6137
|
+
return request(
|
|
6138
|
+
config,
|
|
6139
|
+
"POST",
|
|
6140
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages`,
|
|
6141
|
+
options,
|
|
6142
|
+
input
|
|
6143
|
+
);
|
|
6144
|
+
},
|
|
6145
|
+
update(roomId, messageId, input, options) {
|
|
6146
|
+
return request(
|
|
6147
|
+
config,
|
|
6148
|
+
"PATCH",
|
|
6149
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6150
|
+
options,
|
|
6151
|
+
input
|
|
6152
|
+
);
|
|
6153
|
+
},
|
|
6154
|
+
delete(roomId, messageId, options) {
|
|
6155
|
+
return request(
|
|
6156
|
+
config,
|
|
6157
|
+
"DELETE",
|
|
6158
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6159
|
+
options
|
|
6160
|
+
);
|
|
6161
|
+
}
|
|
6162
|
+
}
|
|
6163
|
+
},
|
|
6164
|
+
message: {
|
|
6165
|
+
reaction: {
|
|
6166
|
+
add(messageId, input, options) {
|
|
6167
|
+
return request(
|
|
6168
|
+
config,
|
|
6169
|
+
"POST",
|
|
6170
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions`,
|
|
6171
|
+
options,
|
|
6172
|
+
input
|
|
6173
|
+
);
|
|
6174
|
+
},
|
|
6175
|
+
remove(messageId, emoji, options) {
|
|
6176
|
+
return request(
|
|
6177
|
+
config,
|
|
6178
|
+
"DELETE",
|
|
6179
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions/${encodePathSegment(emoji, "reaction emoji")}`,
|
|
6180
|
+
options
|
|
6181
|
+
);
|
|
6182
|
+
}
|
|
6183
|
+
},
|
|
6184
|
+
search(input, options) {
|
|
6185
|
+
return request(
|
|
6186
|
+
config,
|
|
6187
|
+
"POST",
|
|
6188
|
+
"/messages/search",
|
|
6189
|
+
options,
|
|
6190
|
+
input
|
|
6191
|
+
);
|
|
6192
|
+
}
|
|
6193
|
+
},
|
|
6194
|
+
realtime
|
|
6195
|
+
};
|
|
6196
|
+
}
|
|
6197
|
+
var chatSdkManifest = {
|
|
6198
|
+
namespace: "chat",
|
|
6199
|
+
basePath: "/chat",
|
|
6200
|
+
methods: [
|
|
6201
|
+
{ name: "listRooms", method: "GET", path: "/chat/rooms" },
|
|
6202
|
+
{ name: "createRoom", method: "POST", path: "/chat/rooms" },
|
|
6203
|
+
{ name: "getRoom", method: "GET", path: "/chat/rooms/{room_id}" },
|
|
6204
|
+
{ name: "updateRoom", method: "PATCH", path: "/chat/rooms/{room_id}" },
|
|
6205
|
+
{ name: "archiveRoom", method: "POST", path: "/chat/rooms/{room_id}/archive" },
|
|
6206
|
+
{ name: "listRoomMessages", method: "GET", path: "/chat/rooms/{room_id}/messages" },
|
|
6207
|
+
{ name: "sendRoomMessage", method: "POST", path: "/chat/rooms/{room_id}/messages" },
|
|
6208
|
+
{ name: "updateRoomMessage", method: "PATCH", path: "/chat/rooms/{room_id}/messages/{message_id}" },
|
|
6209
|
+
{ name: "deleteRoomMessage", method: "DELETE", path: "/chat/rooms/{room_id}/messages/{message_id}" },
|
|
6210
|
+
{ name: "advanceReadCursor", method: "POST", path: "/chat/rooms/{room_id}/read-cursor" },
|
|
6211
|
+
{ name: "listRoomMembers", method: "GET", path: "/chat/rooms/{room_id}/members" },
|
|
6212
|
+
{ name: "addRoomMembers", method: "POST", path: "/chat/rooms/{room_id}/members" },
|
|
6213
|
+
{ name: "removeRoomMember", method: "DELETE", path: "/chat/rooms/{room_id}/members/{user_id}" },
|
|
6214
|
+
{ name: "addReaction", method: "POST", path: "/chat/messages/{message_id}/reactions" },
|
|
6215
|
+
{ name: "removeReaction", method: "DELETE", path: "/chat/messages/{message_id}/reactions/{emoji}" },
|
|
6216
|
+
{ name: "searchMessages", method: "POST", path: "/chat/messages/search" },
|
|
6217
|
+
{ name: "getRealtimeInfo", method: "GET", path: "/wss/info" },
|
|
6218
|
+
{ name: "connectRealtime", method: "GET", path: "/wss/gateway" }
|
|
6219
|
+
]
|
|
6220
|
+
};
|
|
6221
|
+
function unwrapChatRoom(payload) {
|
|
6222
|
+
return unwrapEnvelopeData(payload);
|
|
6223
|
+
}
|
|
6224
|
+
function unwrapChatMessage(payload) {
|
|
6225
|
+
return unwrapEnvelopeData(payload);
|
|
6226
|
+
}
|
|
6227
|
+
|
|
5619
6228
|
// src/client-builder.ts
|
|
5620
6229
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
5621
6230
|
function toBackendConfig(value) {
|
|
@@ -5828,7 +6437,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
5828
6437
|
"ilike",
|
|
5829
6438
|
"is"
|
|
5830
6439
|
]);
|
|
5831
|
-
function
|
|
6440
|
+
function isRecord8(value) {
|
|
5832
6441
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5833
6442
|
}
|
|
5834
6443
|
function isUuidString(value) {
|
|
@@ -5841,7 +6450,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
5841
6450
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
5842
6451
|
}
|
|
5843
6452
|
function isRelationSelectNode(value) {
|
|
5844
|
-
return
|
|
6453
|
+
return isRecord8(value) && isRecord8(value.select);
|
|
5845
6454
|
}
|
|
5846
6455
|
function normalizeIdentifier(value, label) {
|
|
5847
6456
|
const normalized = value.trim();
|
|
@@ -5897,7 +6506,7 @@ function compileRelationToken(key, node) {
|
|
|
5897
6506
|
return `${prefix}${relationToken}(${nested})`;
|
|
5898
6507
|
}
|
|
5899
6508
|
function compileSelectShape(select) {
|
|
5900
|
-
if (!
|
|
6509
|
+
if (!isRecord8(select)) {
|
|
5901
6510
|
throw new Error("findMany select must be an object");
|
|
5902
6511
|
}
|
|
5903
6512
|
const tokens = [];
|
|
@@ -5921,7 +6530,7 @@ function compileSelectShape(select) {
|
|
|
5921
6530
|
return tokens.join(",");
|
|
5922
6531
|
}
|
|
5923
6532
|
function selectShapeUsesRelationSchema(select) {
|
|
5924
|
-
if (!
|
|
6533
|
+
if (!isRecord8(select)) {
|
|
5925
6534
|
return false;
|
|
5926
6535
|
}
|
|
5927
6536
|
for (const rawValue of Object.values(select)) {
|
|
@@ -5939,7 +6548,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
5939
6548
|
}
|
|
5940
6549
|
function compileColumnWhere(column, input) {
|
|
5941
6550
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
5942
|
-
if (!
|
|
6551
|
+
if (!isRecord8(input)) {
|
|
5943
6552
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
5944
6553
|
}
|
|
5945
6554
|
const conditions = [];
|
|
@@ -5967,7 +6576,7 @@ function compileColumnWhere(column, input) {
|
|
|
5967
6576
|
return conditions;
|
|
5968
6577
|
}
|
|
5969
6578
|
function compileBooleanExpressionTerms(clause, label) {
|
|
5970
|
-
if (!
|
|
6579
|
+
if (!isRecord8(clause)) {
|
|
5971
6580
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
5972
6581
|
}
|
|
5973
6582
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -5976,7 +6585,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
5976
6585
|
}
|
|
5977
6586
|
const [rawColumn, rawValue] = entries[0];
|
|
5978
6587
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
5979
|
-
if (!
|
|
6588
|
+
if (!isRecord8(rawValue)) {
|
|
5980
6589
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
5981
6590
|
}
|
|
5982
6591
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -6000,7 +6609,7 @@ function compileWhere(where) {
|
|
|
6000
6609
|
if (where === void 0) {
|
|
6001
6610
|
return void 0;
|
|
6002
6611
|
}
|
|
6003
|
-
if (!
|
|
6612
|
+
if (!isRecord8(where)) {
|
|
6004
6613
|
throw new Error("findMany where must be an object");
|
|
6005
6614
|
}
|
|
6006
6615
|
const conditions = [];
|
|
@@ -6050,7 +6659,7 @@ function compileOrderBy(orderBy) {
|
|
|
6050
6659
|
if (orderBy === void 0) {
|
|
6051
6660
|
return void 0;
|
|
6052
6661
|
}
|
|
6053
|
-
if (!
|
|
6662
|
+
if (!isRecord8(orderBy)) {
|
|
6054
6663
|
throw new Error("findMany orderBy must be an object");
|
|
6055
6664
|
}
|
|
6056
6665
|
if ("column" in orderBy) {
|
|
@@ -6225,11 +6834,11 @@ function toFindManyAstOrder(order) {
|
|
|
6225
6834
|
ascending: order.direction !== "descending"
|
|
6226
6835
|
};
|
|
6227
6836
|
}
|
|
6228
|
-
function
|
|
6837
|
+
function isRecord9(value) {
|
|
6229
6838
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6230
6839
|
}
|
|
6231
6840
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
6232
|
-
if (!
|
|
6841
|
+
if (!isRecord9(value)) {
|
|
6233
6842
|
return {
|
|
6234
6843
|
eq: value
|
|
6235
6844
|
};
|
|
@@ -6253,7 +6862,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
6253
6862
|
return normalized;
|
|
6254
6863
|
}
|
|
6255
6864
|
function normalizeFindManyAstWhere(where) {
|
|
6256
|
-
if (!where || !
|
|
6865
|
+
if (!where || !isRecord9(where)) {
|
|
6257
6866
|
return where;
|
|
6258
6867
|
}
|
|
6259
6868
|
const normalized = {};
|
|
@@ -6267,7 +6876,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6267
6876
|
);
|
|
6268
6877
|
continue;
|
|
6269
6878
|
}
|
|
6270
|
-
if (key === "not" &&
|
|
6879
|
+
if (key === "not" && isRecord9(value)) {
|
|
6271
6880
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
6272
6881
|
value
|
|
6273
6882
|
);
|
|
@@ -6278,7 +6887,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6278
6887
|
return normalized;
|
|
6279
6888
|
}
|
|
6280
6889
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
6281
|
-
if (!
|
|
6890
|
+
if (!isRecord9(value)) {
|
|
6282
6891
|
return shouldUseUuidTextComparison(column, value);
|
|
6283
6892
|
}
|
|
6284
6893
|
const eqValue = value.eq;
|
|
@@ -6296,7 +6905,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
6296
6905
|
return false;
|
|
6297
6906
|
}
|
|
6298
6907
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
6299
|
-
if (!where || !
|
|
6908
|
+
if (!where || !isRecord9(where)) {
|
|
6300
6909
|
return false;
|
|
6301
6910
|
}
|
|
6302
6911
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -6311,7 +6920,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
6311
6920
|
}
|
|
6312
6921
|
continue;
|
|
6313
6922
|
}
|
|
6314
|
-
if (key === "not" &&
|
|
6923
|
+
if (key === "not" && isRecord9(value)) {
|
|
6315
6924
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
6316
6925
|
return true;
|
|
6317
6926
|
}
|
|
@@ -6860,6 +7469,7 @@ function resolveAthenaModelTargetTableName(target, options = {}) {
|
|
|
6860
7469
|
var DEFAULT_COLUMNS = "*";
|
|
6861
7470
|
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
6862
7471
|
var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
|
|
7472
|
+
var SDK_NAME4 = "xylex-group/athena";
|
|
6863
7473
|
function formatResult(response) {
|
|
6864
7474
|
const result = {
|
|
6865
7475
|
data: response.data ?? null,
|
|
@@ -6936,7 +7546,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
6936
7546
|
throw error;
|
|
6937
7547
|
}
|
|
6938
7548
|
}
|
|
6939
|
-
function
|
|
7549
|
+
function isRecord10(value) {
|
|
6940
7550
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6941
7551
|
}
|
|
6942
7552
|
function firstNonEmptyString2(...values) {
|
|
@@ -6948,8 +7558,8 @@ function firstNonEmptyString2(...values) {
|
|
|
6948
7558
|
return void 0;
|
|
6949
7559
|
}
|
|
6950
7560
|
function resolveStructuredErrorPayload2(raw) {
|
|
6951
|
-
if (!
|
|
6952
|
-
return
|
|
7561
|
+
if (!isRecord10(raw)) return null;
|
|
7562
|
+
return isRecord10(raw.error) ? raw.error : raw;
|
|
6953
7563
|
}
|
|
6954
7564
|
function resolveStructuredErrorDetails(payload, message) {
|
|
6955
7565
|
if (!payload || !("details" in payload)) {
|
|
@@ -6965,7 +7575,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
6965
7575
|
return details;
|
|
6966
7576
|
}
|
|
6967
7577
|
function createResultError(response, result, normalized) {
|
|
6968
|
-
const rawRecord =
|
|
7578
|
+
const rawRecord = isRecord10(response.raw) ? response.raw : null;
|
|
6969
7579
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
6970
7580
|
const message = firstNonEmptyString2(
|
|
6971
7581
|
response.error,
|
|
@@ -7028,6 +7638,43 @@ function asAthenaJsonObject(value) {
|
|
|
7028
7638
|
function asAthenaJsonObjectArray(values) {
|
|
7029
7639
|
return values;
|
|
7030
7640
|
}
|
|
7641
|
+
function parseArbitraryResponseBody(rawText, contentType) {
|
|
7642
|
+
if (!rawText) {
|
|
7643
|
+
return null;
|
|
7644
|
+
}
|
|
7645
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
7646
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
7647
|
+
if (!looksJson) {
|
|
7648
|
+
return rawText;
|
|
7649
|
+
}
|
|
7650
|
+
try {
|
|
7651
|
+
return JSON.parse(rawText);
|
|
7652
|
+
} catch {
|
|
7653
|
+
return rawText;
|
|
7654
|
+
}
|
|
7655
|
+
}
|
|
7656
|
+
function toRequestQueryString(query) {
|
|
7657
|
+
if (!query) {
|
|
7658
|
+
return "";
|
|
7659
|
+
}
|
|
7660
|
+
const params = new URLSearchParams();
|
|
7661
|
+
for (const [key, value] of Object.entries(query)) {
|
|
7662
|
+
if (value === void 0 || value === null) {
|
|
7663
|
+
continue;
|
|
7664
|
+
}
|
|
7665
|
+
if (Array.isArray(value)) {
|
|
7666
|
+
for (const item of value) {
|
|
7667
|
+
if (item !== void 0 && item !== null) {
|
|
7668
|
+
params.append(key, String(item));
|
|
7669
|
+
}
|
|
7670
|
+
}
|
|
7671
|
+
continue;
|
|
7672
|
+
}
|
|
7673
|
+
params.set(key, String(value));
|
|
7674
|
+
}
|
|
7675
|
+
const encoded = params.toString();
|
|
7676
|
+
return encoded ? `?${encoded}` : "";
|
|
7677
|
+
}
|
|
7031
7678
|
function normalizeSelectColumnsInput(columns) {
|
|
7032
7679
|
if (columns === void 0) {
|
|
7033
7680
|
return void 0;
|
|
@@ -8334,6 +8981,8 @@ var ATHENA_ENV_GATEWAY_URL_KEYS = [
|
|
|
8334
8981
|
"NEXT_PUBLIC_ATHENA_DB_API_URL"
|
|
8335
8982
|
];
|
|
8336
8983
|
var ATHENA_ENV_AUTH_URL_KEYS = ["ATHENA_AUTH_URL", "NEXT_PUBLIC_ATHENA_AUTH_URL"];
|
|
8984
|
+
var ATHENA_ENV_CHAT_URL_KEYS = ["ATHENA_CHAT_URL", "NEXT_PUBLIC_ATHENA_CHAT_URL"];
|
|
8985
|
+
var ATHENA_ENV_CHAT_WS_URL_KEYS = ["ATHENA_CHAT_WS_URL", "NEXT_PUBLIC_ATHENA_CHAT_WS_URL"];
|
|
8337
8986
|
var ATHENA_ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
|
|
8338
8987
|
var ATHENA_ENV_KEY_KEYS = [
|
|
8339
8988
|
"ATHENA_API_KEY",
|
|
@@ -8414,6 +9063,15 @@ function appendServicePath(baseUrl, segment) {
|
|
|
8414
9063
|
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
8415
9064
|
return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
|
|
8416
9065
|
}
|
|
9066
|
+
function appendRealtimeGatewayPath(baseUrl) {
|
|
9067
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
9068
|
+
const wsUrl = new URL(normalizedBaseUrl);
|
|
9069
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
9070
|
+
wsUrl.pathname = `${wsUrl.pathname.replace(/\/+$/, "")}/wss/gateway`;
|
|
9071
|
+
wsUrl.search = "";
|
|
9072
|
+
wsUrl.hash = "";
|
|
9073
|
+
return wsUrl.toString();
|
|
9074
|
+
}
|
|
8417
9075
|
function resolveServiceUrlOverride(value, label) {
|
|
8418
9076
|
return resolveClientServiceBaseUrl(value, label);
|
|
8419
9077
|
}
|
|
@@ -8422,6 +9080,8 @@ function resolveServiceUrls(config) {
|
|
|
8422
9080
|
return {
|
|
8423
9081
|
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),
|
|
8424
9082
|
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),
|
|
9083
|
+
chatUrl: resolveServiceUrlOverride(config.chat?.url, "Athena chat base URL") ?? resolveServiceUrlOverride(config.chatUrl, "Athena chat base URL") ?? (baseUrl ? appendServicePath(baseUrl, "chat") : void 0),
|
|
9084
|
+
chatWsUrl: normalizeOptionalString(config.chat?.wsUrl) ?? normalizeOptionalString(config.chatWsUrl) ?? (baseUrl ? appendRealtimeGatewayPath(baseUrl) : void 0),
|
|
8425
9085
|
storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
|
|
8426
9086
|
};
|
|
8427
9087
|
}
|
|
@@ -8514,6 +9174,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8514
9174
|
} : void 0,
|
|
8515
9175
|
db: base.db ? { ...base.db } : void 0,
|
|
8516
9176
|
gateway: base.gateway ? { ...base.gateway } : void 0,
|
|
9177
|
+
chat: base.chat ? { ...base.chat } : void 0,
|
|
8517
9178
|
storage: base.storage ? { ...base.storage } : void 0
|
|
8518
9179
|
};
|
|
8519
9180
|
}
|
|
@@ -8524,6 +9185,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8524
9185
|
auth: mergeAuthClientOptions(base.auth, overrides.auth),
|
|
8525
9186
|
db: mergeServiceUrlOverrides(base.db, overrides.db),
|
|
8526
9187
|
gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
|
|
9188
|
+
chat: mergeServiceUrlOverrides(base.chat, overrides.chat),
|
|
8527
9189
|
storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
|
|
8528
9190
|
};
|
|
8529
9191
|
}
|
|
@@ -8582,6 +9244,9 @@ function resolveCreateClientConfig(config) {
|
|
|
8582
9244
|
headers: config.headers,
|
|
8583
9245
|
auth: config.auth,
|
|
8584
9246
|
authUrl: resolvedUrls.authUrl,
|
|
9247
|
+
chat: config.chat,
|
|
9248
|
+
chatUrl: resolvedUrls.chatUrl,
|
|
9249
|
+
chatWsUrl: resolvedUrls.chatWsUrl,
|
|
8585
9250
|
storageUrl: resolvedUrls.storageUrl,
|
|
8586
9251
|
experimental: config.experimental
|
|
8587
9252
|
};
|
|
@@ -8666,6 +9331,119 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8666
9331
|
queryTracer
|
|
8667
9332
|
);
|
|
8668
9333
|
const db = createDbModule({ from, rpc, query });
|
|
9334
|
+
const chat = createChatModule({
|
|
9335
|
+
baseUrl: config.chatUrl,
|
|
9336
|
+
apiKey: config.apiKey,
|
|
9337
|
+
client: config.client,
|
|
9338
|
+
headers: config.headers,
|
|
9339
|
+
bearerToken: normalizedAuthConfig?.bearerToken,
|
|
9340
|
+
cookie: normalizedAuthConfig?.cookie,
|
|
9341
|
+
sessionToken: normalizedAuthConfig?.sessionToken,
|
|
9342
|
+
forceNoCache: config.forceNoCache,
|
|
9343
|
+
wsUrl: config.chatWsUrl,
|
|
9344
|
+
webSocketFactory: config.chat?.webSocketFactory ?? void 0
|
|
9345
|
+
});
|
|
9346
|
+
const request2 = async (options) => {
|
|
9347
|
+
const method = options.method ?? "GET";
|
|
9348
|
+
const responseType = options.responseType ?? "json";
|
|
9349
|
+
const service = options.service ?? "db";
|
|
9350
|
+
const baseUrlByService = {
|
|
9351
|
+
db: config.baseUrl,
|
|
9352
|
+
auth: config.authUrl,
|
|
9353
|
+
chat: config.chatUrl,
|
|
9354
|
+
storage: config.storageUrl
|
|
9355
|
+
};
|
|
9356
|
+
const resolvedBaseUrl = options.url ?? baseUrlByService[service];
|
|
9357
|
+
if (!resolvedBaseUrl) {
|
|
9358
|
+
throw new Error(
|
|
9359
|
+
`Athena ${service} base URL is not configured. Pass createClient({ url }) for unified routing or set the service-specific URL first.`
|
|
9360
|
+
);
|
|
9361
|
+
}
|
|
9362
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(resolvedBaseUrl, {
|
|
9363
|
+
label: `Athena ${service} base URL`
|
|
9364
|
+
});
|
|
9365
|
+
const normalizedPath = options.url ? "" : (() => {
|
|
9366
|
+
const path = options.path?.trim();
|
|
9367
|
+
if (!path) {
|
|
9368
|
+
throw new Error("client.request(...) requires either an absolute url or a non-empty path.");
|
|
9369
|
+
}
|
|
9370
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
9371
|
+
})();
|
|
9372
|
+
const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
|
|
9373
|
+
const headers = {
|
|
9374
|
+
"X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
|
|
9375
|
+
...config.headers ?? {},
|
|
9376
|
+
...options.headers ?? {}
|
|
9377
|
+
};
|
|
9378
|
+
if (service !== "auth") {
|
|
9379
|
+
headers.apikey = headers.apikey ?? config.apiKey;
|
|
9380
|
+
headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
|
|
9381
|
+
if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
|
|
9382
|
+
headers["X-Athena-Client"] = config.client;
|
|
9383
|
+
}
|
|
9384
|
+
if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
|
|
9385
|
+
headers["X-User-Id"] = config.userId;
|
|
9386
|
+
}
|
|
9387
|
+
if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
|
|
9388
|
+
headers["X-Organization-Id"] = config.organizationId;
|
|
9389
|
+
}
|
|
9390
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9391
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9392
|
+
}
|
|
9393
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
|
|
9394
|
+
headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
|
|
9395
|
+
}
|
|
9396
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9397
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9398
|
+
}
|
|
9399
|
+
} else {
|
|
9400
|
+
const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
|
|
9401
|
+
if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
|
|
9402
|
+
headers.apikey = headers.apikey ?? authApiKey;
|
|
9403
|
+
headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
|
|
9404
|
+
}
|
|
9405
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
|
|
9406
|
+
headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
|
|
9407
|
+
}
|
|
9408
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9409
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9410
|
+
}
|
|
9411
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9412
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9415
|
+
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";
|
|
9416
|
+
if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
|
|
9417
|
+
headers["Content-Type"] = "application/json";
|
|
9418
|
+
}
|
|
9419
|
+
const response = await fetch(targetUrl, {
|
|
9420
|
+
method,
|
|
9421
|
+
headers,
|
|
9422
|
+
body: options.body === void 0 || options.body === null ? void 0 : shouldSendJsonBody ? JSON.stringify(options.body) : options.body,
|
|
9423
|
+
signal: options.signal,
|
|
9424
|
+
credentials: options.credentials
|
|
9425
|
+
});
|
|
9426
|
+
if (responseType === "response") {
|
|
9427
|
+
return {
|
|
9428
|
+
ok: response.ok,
|
|
9429
|
+
status: response.status,
|
|
9430
|
+
statusText: response.statusText,
|
|
9431
|
+
headers: response.headers,
|
|
9432
|
+
data: null,
|
|
9433
|
+
raw: response
|
|
9434
|
+
};
|
|
9435
|
+
}
|
|
9436
|
+
const rawText = await response.text();
|
|
9437
|
+
const parsed = responseType === "text" ? rawText : parseArbitraryResponseBody(rawText, response.headers.get("content-type"));
|
|
9438
|
+
return {
|
|
9439
|
+
ok: response.ok,
|
|
9440
|
+
status: response.status,
|
|
9441
|
+
statusText: response.statusText,
|
|
9442
|
+
headers: response.headers,
|
|
9443
|
+
data: parsed,
|
|
9444
|
+
raw: response
|
|
9445
|
+
};
|
|
9446
|
+
};
|
|
8669
9447
|
const withContext = (context) => createClientFromInput(
|
|
8670
9448
|
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8671
9449
|
);
|
|
@@ -8681,8 +9459,10 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8681
9459
|
db,
|
|
8682
9460
|
rpc,
|
|
8683
9461
|
query,
|
|
9462
|
+
request: request2,
|
|
8684
9463
|
verifyConnection: gateway.verifyConnection,
|
|
8685
9464
|
auth: auth.auth,
|
|
9465
|
+
chat,
|
|
8686
9466
|
withContext,
|
|
8687
9467
|
withSession,
|
|
8688
9468
|
withOptions: authWithOptions
|
|
@@ -8727,6 +9507,8 @@ var AthenaClient = class {
|
|
|
8727
9507
|
const url = options.url ?? readFirstEnvValue(env, ATHENA_ENV_URL_KEYS);
|
|
8728
9508
|
const gatewayUrl = options.gatewayUrl ?? readFirstEnvValue(env, ATHENA_ENV_GATEWAY_URL_KEYS);
|
|
8729
9509
|
const authUrl = options.authUrl ?? readFirstEnvValue(env, ATHENA_ENV_AUTH_URL_KEYS);
|
|
9510
|
+
const chatUrl = options.chatUrl ?? readFirstEnvValue(env, ATHENA_ENV_CHAT_URL_KEYS);
|
|
9511
|
+
const chatWsUrl = options.chatWsUrl ?? readFirstEnvValue(env, ATHENA_ENV_CHAT_WS_URL_KEYS);
|
|
8730
9512
|
const storageUrl = options.storageUrl ?? readFirstEnvValue(env, ATHENA_ENV_STORAGE_URL_KEYS);
|
|
8731
9513
|
const key = options.key ?? readFirstEnvValue(env, ATHENA_ENV_KEY_KEYS);
|
|
8732
9514
|
const client = options.client ?? readFirstEnvValue(env, ATHENA_ENV_CLIENT_KEYS);
|
|
@@ -8741,6 +9523,8 @@ var AthenaClient = class {
|
|
|
8741
9523
|
url,
|
|
8742
9524
|
gatewayUrl,
|
|
8743
9525
|
authUrl,
|
|
9526
|
+
chatUrl,
|
|
9527
|
+
chatWsUrl,
|
|
8744
9528
|
storageUrl,
|
|
8745
9529
|
key,
|
|
8746
9530
|
client
|
|
@@ -8786,7 +9570,7 @@ function resolveNullishValue(mode) {
|
|
|
8786
9570
|
if (mode === "null") return null;
|
|
8787
9571
|
return "";
|
|
8788
9572
|
}
|
|
8789
|
-
function
|
|
9573
|
+
function isRecord11(value) {
|
|
8790
9574
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
8791
9575
|
}
|
|
8792
9576
|
function isNullableColumn(model, key) {
|
|
@@ -8795,7 +9579,7 @@ function isNullableColumn(model, key) {
|
|
|
8795
9579
|
}
|
|
8796
9580
|
function toModelFormDefaults(model, values, options) {
|
|
8797
9581
|
const source = values;
|
|
8798
|
-
if (!
|
|
9582
|
+
if (!isRecord11(source)) {
|
|
8799
9583
|
return {};
|
|
8800
9584
|
}
|
|
8801
9585
|
const mode = options?.nullishMode ?? "empty-string";
|
|
@@ -9309,6 +10093,9 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
9309
10093
|
query(query, options) {
|
|
9310
10094
|
return this.baseClient.query(query, options);
|
|
9311
10095
|
}
|
|
10096
|
+
request(options) {
|
|
10097
|
+
return this.baseClient.request(options);
|
|
10098
|
+
}
|
|
9312
10099
|
verifyConnection(options) {
|
|
9313
10100
|
return this.baseClient.verifyConnection(options);
|
|
9314
10101
|
}
|
|
@@ -11605,15 +12392,15 @@ function readCookieFromHeaders(headers, name) {
|
|
|
11605
12392
|
}
|
|
11606
12393
|
return parseCookies(cookieHeader).get(name);
|
|
11607
12394
|
}
|
|
11608
|
-
function
|
|
12395
|
+
function isRecord12(value) {
|
|
11609
12396
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
11610
12397
|
}
|
|
11611
12398
|
function resolveSessionCandidate(value) {
|
|
11612
|
-
if (!
|
|
12399
|
+
if (!isRecord12(value)) {
|
|
11613
12400
|
return null;
|
|
11614
12401
|
}
|
|
11615
|
-
const session =
|
|
11616
|
-
const user =
|
|
12402
|
+
const session = isRecord12(value.session) ? value.session : void 0;
|
|
12403
|
+
const user = isRecord12(value.user) ? value.user : void 0;
|
|
11617
12404
|
if (session && typeof session.token === "string" && session.token.length > 0 && user) {
|
|
11618
12405
|
return {
|
|
11619
12406
|
session,
|
|
@@ -11623,7 +12410,7 @@ function resolveSessionCandidate(value) {
|
|
|
11623
12410
|
return null;
|
|
11624
12411
|
}
|
|
11625
12412
|
function inferSessionPair(returned) {
|
|
11626
|
-
return resolveSessionCandidate(returned) ?? (
|
|
12413
|
+
return resolveSessionCandidate(returned) ?? (isRecord12(returned) ? resolveSessionCandidate(returned.data) : null) ?? (isRecord12(returned) ? resolveSessionCandidate(returned.session) : null);
|
|
11627
12414
|
}
|
|
11628
12415
|
function resolveResponseHeaders(ctx) {
|
|
11629
12416
|
if (ctx.context.responseHeaders instanceof Headers) {
|
|
@@ -11646,23 +12433,23 @@ function normalizeBasePath(basePath) {
|
|
|
11646
12433
|
function isDynamicBaseURLConfig2(baseURL) {
|
|
11647
12434
|
return typeof baseURL === "object" && baseURL !== null && "allowedHosts" in baseURL && Array.isArray(baseURL.allowedHosts);
|
|
11648
12435
|
}
|
|
11649
|
-
function getRequestUrl(
|
|
12436
|
+
function getRequestUrl(request2) {
|
|
11650
12437
|
try {
|
|
11651
|
-
return new URL(
|
|
12438
|
+
return new URL(request2.url);
|
|
11652
12439
|
} catch {
|
|
11653
12440
|
return new URL("http://localhost");
|
|
11654
12441
|
}
|
|
11655
12442
|
}
|
|
11656
|
-
function getRequestHost(
|
|
11657
|
-
const forwardedHost =
|
|
11658
|
-
const host = forwardedHost ||
|
|
12443
|
+
function getRequestHost(request2, url) {
|
|
12444
|
+
const forwardedHost = request2.headers.get("x-forwarded-host")?.split(",")[0]?.trim();
|
|
12445
|
+
const host = forwardedHost || request2.headers.get("host") || url.host;
|
|
11659
12446
|
return host || null;
|
|
11660
12447
|
}
|
|
11661
|
-
function getRequestProtocol(
|
|
12448
|
+
function getRequestProtocol(request2, configuredProtocol, url) {
|
|
11662
12449
|
if (configuredProtocol === "http" || configuredProtocol === "https") {
|
|
11663
12450
|
return configuredProtocol;
|
|
11664
12451
|
}
|
|
11665
|
-
const forwardedProto =
|
|
12452
|
+
const forwardedProto = request2.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
|
|
11666
12453
|
if (forwardedProto === "http" || forwardedProto === "https") {
|
|
11667
12454
|
return forwardedProto;
|
|
11668
12455
|
}
|
|
@@ -11671,12 +12458,12 @@ function getRequestProtocol(request, configuredProtocol, url) {
|
|
|
11671
12458
|
}
|
|
11672
12459
|
return "http";
|
|
11673
12460
|
}
|
|
11674
|
-
function resolveRequestBaseURL(baseURL,
|
|
12461
|
+
function resolveRequestBaseURL(baseURL, request2) {
|
|
11675
12462
|
if (typeof baseURL === "string") {
|
|
11676
12463
|
return normalizeBaseURL(baseURL);
|
|
11677
12464
|
}
|
|
11678
|
-
const requestUrl = getRequestUrl(
|
|
11679
|
-
const host = getRequestHost(
|
|
12465
|
+
const requestUrl = getRequestUrl(request2);
|
|
12466
|
+
const host = getRequestHost(request2, requestUrl);
|
|
11680
12467
|
if (!host) {
|
|
11681
12468
|
return null;
|
|
11682
12469
|
}
|
|
@@ -11686,7 +12473,7 @@ function resolveRequestBaseURL(baseURL, request) {
|
|
|
11686
12473
|
return null;
|
|
11687
12474
|
}
|
|
11688
12475
|
}
|
|
11689
|
-
const protocol = typeof baseURL === "object" && baseURL !== null ? getRequestProtocol(
|
|
12476
|
+
const protocol = typeof baseURL === "object" && baseURL !== null ? getRequestProtocol(request2, baseURL.protocol, requestUrl) : getRequestProtocol(request2, void 0, requestUrl);
|
|
11690
12477
|
return `${protocol}://${host}`;
|
|
11691
12478
|
}
|
|
11692
12479
|
function getOrigin(baseURL) {
|
|
@@ -11699,16 +12486,16 @@ function getOrigin(baseURL) {
|
|
|
11699
12486
|
return void 0;
|
|
11700
12487
|
}
|
|
11701
12488
|
}
|
|
11702
|
-
async function resolveTrustedOrigins(config, baseURL,
|
|
11703
|
-
const resolved = typeof config.trustedOrigins === "function" ? await config.trustedOrigins(
|
|
12489
|
+
async function resolveTrustedOrigins(config, baseURL, request2) {
|
|
12490
|
+
const resolved = typeof config.trustedOrigins === "function" ? await config.trustedOrigins(request2) : config.trustedOrigins ?? [];
|
|
11704
12491
|
const values = [
|
|
11705
12492
|
getOrigin(baseURL),
|
|
11706
12493
|
...resolved
|
|
11707
12494
|
];
|
|
11708
12495
|
return Array.from(new Set(values.filter((value) => typeof value === "string" && value.length > 0)));
|
|
11709
12496
|
}
|
|
11710
|
-
async function resolveTrustedProviders(config,
|
|
11711
|
-
const configured = typeof config.trustedProviders === "function" ? await config.trustedProviders(
|
|
12497
|
+
async function resolveTrustedProviders(config, request2) {
|
|
12498
|
+
const configured = typeof config.trustedProviders === "function" ? await config.trustedProviders(request2) : config.trustedProviders ?? [];
|
|
11712
12499
|
const values = [
|
|
11713
12500
|
...Object.keys(config.socialProviders ?? {}),
|
|
11714
12501
|
...configured
|
|
@@ -11833,9 +12620,9 @@ function athenaAuth(config) {
|
|
|
11833
12620
|
}
|
|
11834
12621
|
return ctx;
|
|
11835
12622
|
};
|
|
11836
|
-
const resolveRequestContext = async (
|
|
11837
|
-
const requestUrl = getRequestUrl(
|
|
11838
|
-
const resolvedBaseURL = resolveRequestBaseURL(config.baseURL,
|
|
12623
|
+
const resolveRequestContext = async (request2) => {
|
|
12624
|
+
const requestUrl = getRequestUrl(request2);
|
|
12625
|
+
const resolvedBaseURL = resolveRequestBaseURL(config.baseURL, request2);
|
|
11839
12626
|
if (!resolvedBaseURL) {
|
|
11840
12627
|
throw new Error(
|
|
11841
12628
|
isDynamicBaseURLConfig2(config.baseURL) ? "Could not resolve base URL from request. Check allowedHosts/baseURL." : "Could not resolve base URL from request."
|
|
@@ -11846,17 +12633,17 @@ function athenaAuth(config) {
|
|
|
11846
12633
|
session: config.session,
|
|
11847
12634
|
advanced: config.advanced
|
|
11848
12635
|
});
|
|
11849
|
-
const trustedOrigins = await resolveTrustedOrigins(config, resolvedBaseURL,
|
|
11850
|
-
const trustedProviders = await resolveTrustedProviders(config,
|
|
12636
|
+
const trustedOrigins = await resolveTrustedOrigins(config, resolvedBaseURL, request2);
|
|
12637
|
+
const trustedProviders = await resolveTrustedProviders(config, request2);
|
|
11851
12638
|
return {
|
|
11852
12639
|
auth,
|
|
11853
|
-
request,
|
|
12640
|
+
request: request2,
|
|
11854
12641
|
url: requestUrl,
|
|
11855
12642
|
path: requestUrl.pathname,
|
|
11856
12643
|
basePath: normalizedBasePath,
|
|
11857
12644
|
baseURL: resolvedBaseURL,
|
|
11858
12645
|
origin: getOrigin(resolvedBaseURL) ?? resolvedBaseURL,
|
|
11859
|
-
headers:
|
|
12646
|
+
headers: request2.headers,
|
|
11860
12647
|
cookies: requestCookies,
|
|
11861
12648
|
trustedOrigins,
|
|
11862
12649
|
trustedProviders,
|
|
@@ -11869,8 +12656,8 @@ function athenaAuth(config) {
|
|
|
11869
12656
|
socialProviders: auth.socialProviders
|
|
11870
12657
|
};
|
|
11871
12658
|
};
|
|
11872
|
-
const handler = async (
|
|
11873
|
-
const requestContext = await resolveRequestContext(
|
|
12659
|
+
const handler = async (request2) => {
|
|
12660
|
+
const requestContext = await resolveRequestContext(request2);
|
|
11874
12661
|
if (typeof config.handler !== "function") {
|
|
11875
12662
|
return createJsonResponse(
|
|
11876
12663
|
{
|
|
@@ -11891,7 +12678,7 @@ function athenaAuth(config) {
|
|
|
11891
12678
|
const responseHeaders = new Headers(response.headers);
|
|
11892
12679
|
await runAfterHooks({
|
|
11893
12680
|
path: requestContext.path,
|
|
11894
|
-
headers:
|
|
12681
|
+
headers: request2.headers,
|
|
11895
12682
|
context: {
|
|
11896
12683
|
responseHeaders,
|
|
11897
12684
|
returned: result.returned,
|
|
@@ -11967,6 +12754,6 @@ function athenaAuth(config) {
|
|
|
11967
12754
|
return auth;
|
|
11968
12755
|
}
|
|
11969
12756
|
|
|
11970
|
-
export { ATHENA_AUTH_ADMIN_LIMITS, ATHENA_AUTH_BASE_ERROR_CODES, ATHENA_AUTH_MAX_ADMIN_JSON_BYTES, ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH, ATHENA_AUTH_MAX_TEMPLATE_VARIABLES, ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, boolean, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, enumeration, filterIntrospectionSnapshot, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, identifier, isAthenaGatewayError, isOk, json, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, normalizeTableSelection, number, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
12757
|
+
export { ATHENA_AUTH_ADMIN_LIMITS, ATHENA_AUTH_BASE_ERROR_CODES, ATHENA_AUTH_MAX_ADMIN_JSON_BYTES, ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH, ATHENA_AUTH_MAX_TEMPLATE_VARIABLES, ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH, AthenaChatError, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, boolean, chatSdkManifest, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, enumeration, filterIntrospectionSnapshot, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, identifier, isAthenaGatewayError, isOk, json, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, normalizeTableSelection, number, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapChatMessage, unwrapChatRoom, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
11971
12758
|
//# sourceMappingURL=index.js.map
|
|
11972
12759
|
//# sourceMappingURL=index.js.map
|