@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/browser.cjs
CHANGED
|
@@ -662,8 +662,8 @@ function deleteSessionCookie(ctx, skipDontRememberMe) {
|
|
|
662
662
|
expireCookie(ctx, ctx.context.authCookies.dontRememberToken);
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
|
-
var getSessionCookie = (
|
|
666
|
-
const cookies = (
|
|
665
|
+
var getSessionCookie = (request2, config) => {
|
|
666
|
+
const cookies = (request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers).get("cookie");
|
|
667
667
|
if (!cookies) {
|
|
668
668
|
return null;
|
|
669
669
|
}
|
|
@@ -683,8 +683,8 @@ var getSessionCookie = (request, config) => {
|
|
|
683
683
|
}
|
|
684
684
|
return null;
|
|
685
685
|
};
|
|
686
|
-
var getCookieCache = async (
|
|
687
|
-
const headers =
|
|
686
|
+
var getCookieCache = async (request2, config) => {
|
|
687
|
+
const headers = request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers;
|
|
688
688
|
const cookieHeader = headers.get("cookie");
|
|
689
689
|
if (!cookieHeader) {
|
|
690
690
|
return null;
|
|
@@ -802,7 +802,7 @@ var getCookieCache = async (request, config) => {
|
|
|
802
802
|
|
|
803
803
|
// package.json
|
|
804
804
|
var package_default = {
|
|
805
|
-
version: "2.
|
|
805
|
+
version: "2.11.0"
|
|
806
806
|
};
|
|
807
807
|
|
|
808
808
|
// src/sdk-version.ts
|
|
@@ -1854,6 +1854,87 @@ function mergeCallOptions(base, override) {
|
|
|
1854
1854
|
}
|
|
1855
1855
|
};
|
|
1856
1856
|
}
|
|
1857
|
+
function copyDefinedField(target, source, targetKey, sourceKey) {
|
|
1858
|
+
if (!(sourceKey in source)) {
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
const value = source[sourceKey];
|
|
1862
|
+
if (value !== void 0) {
|
|
1863
|
+
target[targetKey] = value;
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
function normalizeEmailTemplateAttachmentsValue(value) {
|
|
1867
|
+
if (typeof value === "string" || value == null) {
|
|
1868
|
+
return value;
|
|
1869
|
+
}
|
|
1870
|
+
if (Array.isArray(value)) {
|
|
1871
|
+
return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
|
|
1872
|
+
}
|
|
1873
|
+
if (typeof value !== "object") {
|
|
1874
|
+
return value;
|
|
1875
|
+
}
|
|
1876
|
+
const attachment = { ...value };
|
|
1877
|
+
copyDefinedField(attachment, attachment, "file_url", "fileUrl");
|
|
1878
|
+
delete attachment.fileUrl;
|
|
1879
|
+
return attachment;
|
|
1880
|
+
}
|
|
1881
|
+
function normalizeAdminEmailTemplatePayload(payload) {
|
|
1882
|
+
const normalized = { ...payload };
|
|
1883
|
+
copyDefinedField(normalized, payload, "template_key", "templateKey");
|
|
1884
|
+
copyDefinedField(normalized, payload, "event_type", "eventType");
|
|
1885
|
+
copyDefinedField(normalized, payload, "subject_template", "subjectTemplate");
|
|
1886
|
+
copyDefinedField(normalized, payload, "text_template", "textTemplate");
|
|
1887
|
+
copyDefinedField(normalized, payload, "html_template", "htmlTemplate");
|
|
1888
|
+
copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
|
|
1889
|
+
copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
|
|
1890
|
+
copyDefinedField(normalized, payload, "is_active", "isActive");
|
|
1891
|
+
if (Object.hasOwn(payload, "attachments")) {
|
|
1892
|
+
normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
|
|
1893
|
+
}
|
|
1894
|
+
delete normalized.templateKey;
|
|
1895
|
+
delete normalized.eventType;
|
|
1896
|
+
delete normalized.subjectTemplate;
|
|
1897
|
+
delete normalized.textTemplate;
|
|
1898
|
+
delete normalized.htmlTemplate;
|
|
1899
|
+
delete normalized.variableBindings;
|
|
1900
|
+
delete normalized.attachmentFailureMode;
|
|
1901
|
+
delete normalized.isActive;
|
|
1902
|
+
return normalized;
|
|
1903
|
+
}
|
|
1904
|
+
function toReactEmailTemplateCompatibilityInput(input) {
|
|
1905
|
+
const payload = input;
|
|
1906
|
+
const compatibility = { ...payload };
|
|
1907
|
+
copyDefinedField(compatibility, payload, "templateKey", "template_key");
|
|
1908
|
+
copyDefinedField(compatibility, payload, "eventType", "event_type");
|
|
1909
|
+
copyDefinedField(compatibility, payload, "subjectTemplate", "subject_template");
|
|
1910
|
+
copyDefinedField(compatibility, payload, "textTemplate", "text_template");
|
|
1911
|
+
copyDefinedField(compatibility, payload, "htmlTemplate", "html_template");
|
|
1912
|
+
copyDefinedField(compatibility, payload, "variableBindings", "variable_bindings");
|
|
1913
|
+
copyDefinedField(compatibility, payload, "attachmentFailureMode", "attachment_failure_mode");
|
|
1914
|
+
copyDefinedField(compatibility, payload, "isActive", "is_active");
|
|
1915
|
+
return compatibility;
|
|
1916
|
+
}
|
|
1917
|
+
function normalizeAdminEmailTemplateSendPayload(payload) {
|
|
1918
|
+
const normalized = { ...payload };
|
|
1919
|
+
copyDefinedField(normalized, payload, "template_id", "templateId");
|
|
1920
|
+
copyDefinedField(normalized, payload, "recipient_email", "recipientEmail");
|
|
1921
|
+
copyDefinedField(normalized, payload, "render_variables", "renderVariables");
|
|
1922
|
+
copyDefinedField(normalized, payload, "user_id", "userId");
|
|
1923
|
+
copyDefinedField(normalized, payload, "organization_id", "organizationId");
|
|
1924
|
+
copyDefinedField(normalized, payload, "session_token", "sessionToken");
|
|
1925
|
+
copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
|
|
1926
|
+
if (Object.hasOwn(payload, "attachments")) {
|
|
1927
|
+
normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
|
|
1928
|
+
}
|
|
1929
|
+
delete normalized.templateId;
|
|
1930
|
+
delete normalized.recipientEmail;
|
|
1931
|
+
delete normalized.renderVariables;
|
|
1932
|
+
delete normalized.userId;
|
|
1933
|
+
delete normalized.organizationId;
|
|
1934
|
+
delete normalized.sessionToken;
|
|
1935
|
+
delete normalized.attachmentFailureMode;
|
|
1936
|
+
return normalized;
|
|
1937
|
+
}
|
|
1857
1938
|
function toSessionGuardFailure(sessionResult) {
|
|
1858
1939
|
if (sessionResult.status === 401 || sessionResult.data == null) {
|
|
1859
1940
|
return {
|
|
@@ -2160,7 +2241,7 @@ function createAuthClient(config = {}) {
|
|
|
2160
2241
|
...config,
|
|
2161
2242
|
baseUrl: normalizedBaseUrl
|
|
2162
2243
|
};
|
|
2163
|
-
const
|
|
2244
|
+
const request2 = (input, options) => {
|
|
2164
2245
|
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
2165
2246
|
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
2166
2247
|
return callAuthEndpoint(
|
|
@@ -2173,7 +2254,7 @@ function createAuthClient(config = {}) {
|
|
|
2173
2254
|
};
|
|
2174
2255
|
const postGeneric = (endpoint, input, options) => {
|
|
2175
2256
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
2176
|
-
return
|
|
2257
|
+
return request2(
|
|
2177
2258
|
{
|
|
2178
2259
|
endpoint,
|
|
2179
2260
|
method: "POST",
|
|
@@ -2185,7 +2266,7 @@ function createAuthClient(config = {}) {
|
|
|
2185
2266
|
};
|
|
2186
2267
|
const getGeneric = (endpoint, input, options) => {
|
|
2187
2268
|
const { fetchOptions } = extractFetchOptions(input);
|
|
2188
|
-
return
|
|
2269
|
+
return request2(
|
|
2189
2270
|
{
|
|
2190
2271
|
endpoint,
|
|
2191
2272
|
method: "GET",
|
|
@@ -2197,7 +2278,7 @@ function createAuthClient(config = {}) {
|
|
|
2197
2278
|
const getWithQuery = (endpoint, input, options) => {
|
|
2198
2279
|
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
2199
2280
|
const query = payload?.query;
|
|
2200
|
-
return
|
|
2281
|
+
return request2(
|
|
2201
2282
|
{
|
|
2202
2283
|
endpoint,
|
|
2203
2284
|
method: "GET",
|
|
@@ -2215,18 +2296,19 @@ function createAuthClient(config = {}) {
|
|
|
2215
2296
|
htmlField: "htmlBody",
|
|
2216
2297
|
textField: "textBody"
|
|
2217
2298
|
}, withReactEmailRoute(route));
|
|
2218
|
-
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(input, {
|
|
2299
|
+
const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(toReactEmailTemplateCompatibilityInput(input), {
|
|
2219
2300
|
htmlField: "htmlTemplate",
|
|
2220
2301
|
textField: "textTemplate",
|
|
2221
2302
|
variablesField: "variables"
|
|
2222
2303
|
}, withReactEmailRoute(route)).then((payload) => {
|
|
2304
|
+
const normalizedPayload = normalizeAdminEmailTemplatePayload(payload);
|
|
2223
2305
|
if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
|
|
2224
2306
|
assertAthenaAuthTemplateVariables(
|
|
2225
2307
|
payload.variables,
|
|
2226
2308
|
`${route} variables`
|
|
2227
2309
|
);
|
|
2228
2310
|
}
|
|
2229
|
-
return
|
|
2311
|
+
return normalizedPayload;
|
|
2230
2312
|
});
|
|
2231
2313
|
const requireSession = async (input, options) => {
|
|
2232
2314
|
const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
|
|
@@ -2802,7 +2884,15 @@ function createAuthClient(config = {}) {
|
|
|
2802
2884
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
2803
2885
|
options
|
|
2804
2886
|
),
|
|
2805
|
-
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
|
|
2887
|
+
delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
|
|
2888
|
+
send: (input, options) => postGeneric(
|
|
2889
|
+
"/admin/email-template/send",
|
|
2890
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
2891
|
+
options
|
|
2892
|
+
)
|
|
2893
|
+
},
|
|
2894
|
+
eventType: {
|
|
2895
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
2806
2896
|
}
|
|
2807
2897
|
},
|
|
2808
2898
|
emailTemplate: {
|
|
@@ -2818,7 +2908,15 @@ function createAuthClient(config = {}) {
|
|
|
2818
2908
|
"/admin/email-template/update",
|
|
2819
2909
|
await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
|
|
2820
2910
|
options
|
|
2911
|
+
),
|
|
2912
|
+
send: (input, options) => postGeneric(
|
|
2913
|
+
"/admin/email-template/send",
|
|
2914
|
+
normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
|
|
2915
|
+
options
|
|
2821
2916
|
)
|
|
2917
|
+
},
|
|
2918
|
+
emailEventType: {
|
|
2919
|
+
list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
|
|
2822
2920
|
}
|
|
2823
2921
|
},
|
|
2824
2922
|
apiKey: {
|
|
@@ -2858,7 +2956,7 @@ function createAuthClient(config = {}) {
|
|
|
2858
2956
|
throw new Error("callback.provider requires non-empty code and state values");
|
|
2859
2957
|
}
|
|
2860
2958
|
const endpoint = `/callback/${encodeURIComponent(provider)}`;
|
|
2861
|
-
return
|
|
2959
|
+
return request2({
|
|
2862
2960
|
endpoint,
|
|
2863
2961
|
method: "GET",
|
|
2864
2962
|
query: {
|
|
@@ -2872,7 +2970,7 @@ function createAuthClient(config = {}) {
|
|
|
2872
2970
|
};
|
|
2873
2971
|
return {
|
|
2874
2972
|
baseUrl: normalizedBaseUrl,
|
|
2875
|
-
request,
|
|
2973
|
+
request: request2,
|
|
2876
2974
|
signIn: {
|
|
2877
2975
|
email: (input, options) => executePostWithCompatibleInput(
|
|
2878
2976
|
resolvedConfig,
|
|
@@ -3613,16 +3711,16 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3613
3711
|
};
|
|
3614
3712
|
});
|
|
3615
3713
|
input.onProgress?.(createProgressSnapshot("preparing", sources, 0, 0, 0));
|
|
3616
|
-
const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((
|
|
3714
|
+
const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request2) => request2.uploadRequest) }, options)).files;
|
|
3617
3715
|
const aggregateLoaded = new Array(uploadRequests.length).fill(0);
|
|
3618
3716
|
const uploaded = [];
|
|
3619
3717
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
3620
|
-
const
|
|
3718
|
+
const request2 = uploadRequests[index];
|
|
3621
3719
|
const uploadUrl = uploadUrls[index];
|
|
3622
3720
|
const response = await putUploadBody(
|
|
3623
3721
|
uploadUrl.upload.url,
|
|
3624
3722
|
uploadUrl.upload.headers ?? {},
|
|
3625
|
-
|
|
3723
|
+
request2.source,
|
|
3626
3724
|
input,
|
|
3627
3725
|
options,
|
|
3628
3726
|
(progress) => {
|
|
@@ -3633,13 +3731,13 @@ function createStorageFileModule(base, config = {}) {
|
|
|
3633
3731
|
uploaded.push({
|
|
3634
3732
|
file: uploadUrl.file,
|
|
3635
3733
|
upload: uploadUrl.upload,
|
|
3636
|
-
source:
|
|
3637
|
-
fileName:
|
|
3638
|
-
storage_key:
|
|
3734
|
+
source: request2.source.source,
|
|
3735
|
+
fileName: request2.source.fileName,
|
|
3736
|
+
storage_key: request2.uploadRequest.storage_key,
|
|
3639
3737
|
response
|
|
3640
3738
|
});
|
|
3641
|
-
aggregateLoaded[index] =
|
|
3642
|
-
input.onProgress?.(createProgressSnapshot("complete", sources, index,
|
|
3739
|
+
aggregateLoaded[index] = request2.source.sizeBytes;
|
|
3740
|
+
input.onProgress?.(createProgressSnapshot("complete", sources, index, request2.source.sizeBytes, sum(aggregateLoaded)));
|
|
3643
3741
|
}
|
|
3644
3742
|
return {
|
|
3645
3743
|
files: uploaded,
|
|
@@ -5614,6 +5712,517 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
5614
5712
|
};
|
|
5615
5713
|
}
|
|
5616
5714
|
|
|
5715
|
+
// src/chat/module.ts
|
|
5716
|
+
var SDK_NAME3 = "xylex-group/athena-chat";
|
|
5717
|
+
var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
|
|
5718
|
+
var NO_CACHE_HEADER_VALUE3 = "no-cache";
|
|
5719
|
+
var AthenaChatError = class extends Error {
|
|
5720
|
+
status;
|
|
5721
|
+
endpoint;
|
|
5722
|
+
method;
|
|
5723
|
+
requestId;
|
|
5724
|
+
body;
|
|
5725
|
+
constructor(input) {
|
|
5726
|
+
super(input.message);
|
|
5727
|
+
this.name = "AthenaChatError";
|
|
5728
|
+
this.status = input.status;
|
|
5729
|
+
this.endpoint = input.endpoint;
|
|
5730
|
+
this.method = input.method;
|
|
5731
|
+
this.requestId = input.requestId;
|
|
5732
|
+
this.body = input.body;
|
|
5733
|
+
}
|
|
5734
|
+
};
|
|
5735
|
+
function deriveRealtimeInfoUrl(wsUrl) {
|
|
5736
|
+
if (!wsUrl) {
|
|
5737
|
+
return void 0;
|
|
5738
|
+
}
|
|
5739
|
+
const parsed = new URL(normalizeWsUrl(wsUrl, "Athena chat WebSocket URL"));
|
|
5740
|
+
parsed.protocol = parsed.protocol === "wss:" ? "https:" : "http:";
|
|
5741
|
+
parsed.pathname = parsed.pathname.replace(/\/wss\/gateway$/, "/wss/info");
|
|
5742
|
+
return parsed.toString();
|
|
5743
|
+
}
|
|
5744
|
+
function normalizeWsUrl(value, label) {
|
|
5745
|
+
const normalized = value.trim();
|
|
5746
|
+
if (!normalized) {
|
|
5747
|
+
throw new Error(`${label} is required.`);
|
|
5748
|
+
}
|
|
5749
|
+
let parsed;
|
|
5750
|
+
try {
|
|
5751
|
+
parsed = new URL(normalized);
|
|
5752
|
+
} catch {
|
|
5753
|
+
throw new Error(`${label} must be a valid absolute ws(s) URL.`);
|
|
5754
|
+
}
|
|
5755
|
+
if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
|
|
5756
|
+
throw new Error(`${label} must use ws or wss.`);
|
|
5757
|
+
}
|
|
5758
|
+
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
5759
|
+
return parsed.toString().replace(/\/$/, "");
|
|
5760
|
+
}
|
|
5761
|
+
function isRecord7(value) {
|
|
5762
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5763
|
+
}
|
|
5764
|
+
function normalizeHeaderValue3(value) {
|
|
5765
|
+
return value ? value : void 0;
|
|
5766
|
+
}
|
|
5767
|
+
function parseResponseBody4(rawText, contentType) {
|
|
5768
|
+
if (!rawText) {
|
|
5769
|
+
return { parsed: null, parseFailed: false };
|
|
5770
|
+
}
|
|
5771
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
5772
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
5773
|
+
if (!looksJson) {
|
|
5774
|
+
return { parsed: rawText, parseFailed: false };
|
|
5775
|
+
}
|
|
5776
|
+
try {
|
|
5777
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
5778
|
+
} catch {
|
|
5779
|
+
return { parsed: rawText, parseFailed: true };
|
|
5780
|
+
}
|
|
5781
|
+
}
|
|
5782
|
+
function resolveRequestId3(headers) {
|
|
5783
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
5784
|
+
}
|
|
5785
|
+
function resolveErrorMessage4(payload, fallback) {
|
|
5786
|
+
if (isRecord7(payload)) {
|
|
5787
|
+
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
5788
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
5789
|
+
return candidate.trim();
|
|
5790
|
+
}
|
|
5791
|
+
}
|
|
5792
|
+
}
|
|
5793
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
5794
|
+
return payload.trim();
|
|
5795
|
+
}
|
|
5796
|
+
return fallback;
|
|
5797
|
+
}
|
|
5798
|
+
function encodePathSegment(value, label) {
|
|
5799
|
+
const normalized = value.trim();
|
|
5800
|
+
if (!normalized) {
|
|
5801
|
+
throw new Error(`${label} is required.`);
|
|
5802
|
+
}
|
|
5803
|
+
return encodeURIComponent(normalized);
|
|
5804
|
+
}
|
|
5805
|
+
function encodeQuery(query) {
|
|
5806
|
+
if (!query) {
|
|
5807
|
+
return "";
|
|
5808
|
+
}
|
|
5809
|
+
const params = new URLSearchParams();
|
|
5810
|
+
for (const [key, value] of Object.entries(query)) {
|
|
5811
|
+
if (value === void 0 || value === null) {
|
|
5812
|
+
continue;
|
|
5813
|
+
}
|
|
5814
|
+
if (Array.isArray(value)) {
|
|
5815
|
+
for (const item of value) {
|
|
5816
|
+
if (item !== void 0 && item !== null) {
|
|
5817
|
+
params.append(key, String(item));
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
continue;
|
|
5821
|
+
}
|
|
5822
|
+
params.set(key, String(value));
|
|
5823
|
+
}
|
|
5824
|
+
const encoded = params.toString();
|
|
5825
|
+
return encoded ? `?${encoded}` : "";
|
|
5826
|
+
}
|
|
5827
|
+
function createSocket(factory, url, protocols) {
|
|
5828
|
+
try {
|
|
5829
|
+
return new factory(url, protocols);
|
|
5830
|
+
} catch (error) {
|
|
5831
|
+
if (error instanceof TypeError) {
|
|
5832
|
+
return factory(url, protocols);
|
|
5833
|
+
}
|
|
5834
|
+
throw error;
|
|
5835
|
+
}
|
|
5836
|
+
}
|
|
5837
|
+
function buildHeaders3(config, options) {
|
|
5838
|
+
const headers = {
|
|
5839
|
+
Accept: "application/json",
|
|
5840
|
+
apikey: config.apiKey,
|
|
5841
|
+
"x-api-key": config.apiKey,
|
|
5842
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE3
|
|
5843
|
+
};
|
|
5844
|
+
if (config.client || options?.client) {
|
|
5845
|
+
headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
|
|
5846
|
+
}
|
|
5847
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
5848
|
+
if (typeof bearerToken === "string" && bearerToken.trim()) {
|
|
5849
|
+
headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
|
|
5850
|
+
}
|
|
5851
|
+
const cookie = options?.cookie ?? config.cookie;
|
|
5852
|
+
if (typeof cookie === "string" && cookie.trim()) {
|
|
5853
|
+
headers.Cookie = cookie;
|
|
5854
|
+
}
|
|
5855
|
+
const sessionToken = options?.sessionToken ?? config.sessionToken;
|
|
5856
|
+
if (typeof sessionToken === "string" && sessionToken.trim()) {
|
|
5857
|
+
headers["X-Athena-Auth-Session-Token"] = sessionToken;
|
|
5858
|
+
}
|
|
5859
|
+
if (config.forceNoCache || options?.forceNoCache) {
|
|
5860
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
|
|
5861
|
+
}
|
|
5862
|
+
for (const source of [config.headers, options?.headers]) {
|
|
5863
|
+
for (const [key, value] of Object.entries(source ?? {})) {
|
|
5864
|
+
const normalized = normalizeHeaderValue3(value);
|
|
5865
|
+
if (normalized) {
|
|
5866
|
+
headers[key] = normalized;
|
|
5867
|
+
}
|
|
5868
|
+
}
|
|
5869
|
+
}
|
|
5870
|
+
return headers;
|
|
5871
|
+
}
|
|
5872
|
+
function withJsonBody(init, body) {
|
|
5873
|
+
return {
|
|
5874
|
+
...init,
|
|
5875
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
5876
|
+
headers: {
|
|
5877
|
+
"Content-Type": "application/json",
|
|
5878
|
+
...init.headers
|
|
5879
|
+
}
|
|
5880
|
+
};
|
|
5881
|
+
}
|
|
5882
|
+
async function request(config, method, endpoint, options, body) {
|
|
5883
|
+
if (!config.baseUrl) {
|
|
5884
|
+
throw new Error(
|
|
5885
|
+
"Athena chat base URL is not configured. Pass createClient({ url }) for unified routing or set chat.url / chatUrl explicitly."
|
|
5886
|
+
);
|
|
5887
|
+
}
|
|
5888
|
+
const url = `${config.baseUrl}${endpoint}`;
|
|
5889
|
+
const init = {
|
|
5890
|
+
method,
|
|
5891
|
+
headers: buildHeaders3(config, options),
|
|
5892
|
+
signal: options?.signal
|
|
5893
|
+
};
|
|
5894
|
+
const finalInit = body === void 0 || method === "GET" ? init : withJsonBody(init, body);
|
|
5895
|
+
const response = await fetch(url, finalInit);
|
|
5896
|
+
const rawText = await response.text();
|
|
5897
|
+
const { parsed } = parseResponseBody4(rawText, response.headers.get("content-type"));
|
|
5898
|
+
if (!response.ok) {
|
|
5899
|
+
throw new AthenaChatError({
|
|
5900
|
+
message: resolveErrorMessage4(parsed, `Athena chat ${method} ${endpoint} failed with ${response.status}`),
|
|
5901
|
+
status: response.status,
|
|
5902
|
+
endpoint,
|
|
5903
|
+
method,
|
|
5904
|
+
requestId: resolveRequestId3(response.headers),
|
|
5905
|
+
body: parsed
|
|
5906
|
+
});
|
|
5907
|
+
}
|
|
5908
|
+
return parsed;
|
|
5909
|
+
}
|
|
5910
|
+
function unwrapEnvelopeData(payload) {
|
|
5911
|
+
return payload.data;
|
|
5912
|
+
}
|
|
5913
|
+
function createRealtimeConnection(config, options) {
|
|
5914
|
+
if (!config.wsUrl) {
|
|
5915
|
+
throw new Error(
|
|
5916
|
+
"Athena chat WebSocket URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
5917
|
+
);
|
|
5918
|
+
}
|
|
5919
|
+
const wsFactory = config.webSocketFactory ?? globalThis.WebSocket;
|
|
5920
|
+
if (!wsFactory) {
|
|
5921
|
+
throw new Error(
|
|
5922
|
+
"No WebSocket implementation is available. Provide chat.webSocketFactory in createClient(...) or run in a runtime with global WebSocket support."
|
|
5923
|
+
);
|
|
5924
|
+
}
|
|
5925
|
+
const socket = createSocket(wsFactory, config.wsUrl, options?.protocols);
|
|
5926
|
+
const send = (command) => {
|
|
5927
|
+
socket.send(JSON.stringify(command));
|
|
5928
|
+
};
|
|
5929
|
+
if (options?.onMessage) {
|
|
5930
|
+
const listener = (event) => {
|
|
5931
|
+
const messageEvent = event;
|
|
5932
|
+
const raw = messageEvent?.data;
|
|
5933
|
+
if (typeof raw !== "string") {
|
|
5934
|
+
return;
|
|
5935
|
+
}
|
|
5936
|
+
try {
|
|
5937
|
+
options.onMessage?.(JSON.parse(raw));
|
|
5938
|
+
} catch {
|
|
5939
|
+
options.onMessage?.({ type: "error", error: "Invalid JSON message from Athena chat realtime gateway." });
|
|
5940
|
+
}
|
|
5941
|
+
};
|
|
5942
|
+
if (typeof socket.addEventListener === "function") {
|
|
5943
|
+
socket.addEventListener("message", listener);
|
|
5944
|
+
} else {
|
|
5945
|
+
socket.onmessage = listener;
|
|
5946
|
+
}
|
|
5947
|
+
}
|
|
5948
|
+
const hello = (command) => {
|
|
5949
|
+
send({
|
|
5950
|
+
type: "auth.hello",
|
|
5951
|
+
token: command?.token,
|
|
5952
|
+
room_subscriptions: command?.room_subscriptions
|
|
5953
|
+
});
|
|
5954
|
+
};
|
|
5955
|
+
if (options?.hello) {
|
|
5956
|
+
const onOpen = () => hello({
|
|
5957
|
+
token: options.hello?.token ?? void 0,
|
|
5958
|
+
room_subscriptions: options.hello?.room_subscriptions ?? void 0
|
|
5959
|
+
});
|
|
5960
|
+
if (typeof socket.addEventListener === "function") {
|
|
5961
|
+
socket.addEventListener("open", onOpen);
|
|
5962
|
+
} else {
|
|
5963
|
+
socket.onopen = onOpen;
|
|
5964
|
+
}
|
|
5965
|
+
}
|
|
5966
|
+
return {
|
|
5967
|
+
socket,
|
|
5968
|
+
send,
|
|
5969
|
+
hello,
|
|
5970
|
+
subscribe(roomId, fromSeq) {
|
|
5971
|
+
send({
|
|
5972
|
+
type: "chat.subscribe",
|
|
5973
|
+
room_id: roomId,
|
|
5974
|
+
from_seq: fromSeq ?? void 0
|
|
5975
|
+
});
|
|
5976
|
+
},
|
|
5977
|
+
unsubscribe(roomId) {
|
|
5978
|
+
send({
|
|
5979
|
+
type: "chat.unsubscribe",
|
|
5980
|
+
room_id: roomId
|
|
5981
|
+
});
|
|
5982
|
+
},
|
|
5983
|
+
resume(rooms) {
|
|
5984
|
+
send({
|
|
5985
|
+
type: "chat.resume",
|
|
5986
|
+
rooms
|
|
5987
|
+
});
|
|
5988
|
+
},
|
|
5989
|
+
typingStart(roomId) {
|
|
5990
|
+
send({
|
|
5991
|
+
type: "chat.typing.start",
|
|
5992
|
+
room_id: roomId
|
|
5993
|
+
});
|
|
5994
|
+
},
|
|
5995
|
+
typingStop(roomId) {
|
|
5996
|
+
send({
|
|
5997
|
+
type: "chat.typing.stop",
|
|
5998
|
+
room_id: roomId
|
|
5999
|
+
});
|
|
6000
|
+
},
|
|
6001
|
+
presenceHeartbeat(activeRoomId) {
|
|
6002
|
+
send({
|
|
6003
|
+
type: "chat.presence.heartbeat",
|
|
6004
|
+
active_room_id: activeRoomId ?? void 0
|
|
6005
|
+
});
|
|
6006
|
+
},
|
|
6007
|
+
readUpTo(roomId, input) {
|
|
6008
|
+
send({
|
|
6009
|
+
type: "chat.read.up_to",
|
|
6010
|
+
room_id: roomId,
|
|
6011
|
+
message_id: input?.message_id ?? void 0,
|
|
6012
|
+
seq: input?.seq ?? void 0
|
|
6013
|
+
});
|
|
6014
|
+
},
|
|
6015
|
+
ping(at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
6016
|
+
send({
|
|
6017
|
+
type: "ping",
|
|
6018
|
+
at
|
|
6019
|
+
});
|
|
6020
|
+
},
|
|
6021
|
+
close(code, reason) {
|
|
6022
|
+
socket.close(code, reason);
|
|
6023
|
+
}
|
|
6024
|
+
};
|
|
6025
|
+
}
|
|
6026
|
+
function createChatModule(config) {
|
|
6027
|
+
const realtime = {
|
|
6028
|
+
info(options) {
|
|
6029
|
+
const realtimeInfoUrl = config.realtimeInfoUrl ?? deriveRealtimeInfoUrl(config.wsUrl);
|
|
6030
|
+
if (!realtimeInfoUrl) {
|
|
6031
|
+
throw new Error(
|
|
6032
|
+
"Athena chat realtime info URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
|
|
6033
|
+
);
|
|
6034
|
+
}
|
|
6035
|
+
return request(
|
|
6036
|
+
{
|
|
6037
|
+
...config,
|
|
6038
|
+
baseUrl: realtimeInfoUrl
|
|
6039
|
+
},
|
|
6040
|
+
"GET",
|
|
6041
|
+
"",
|
|
6042
|
+
options
|
|
6043
|
+
);
|
|
6044
|
+
},
|
|
6045
|
+
connect(options) {
|
|
6046
|
+
return createRealtimeConnection(config, options);
|
|
6047
|
+
}
|
|
6048
|
+
};
|
|
6049
|
+
return {
|
|
6050
|
+
room: {
|
|
6051
|
+
list(query, options) {
|
|
6052
|
+
return request(
|
|
6053
|
+
config,
|
|
6054
|
+
"GET",
|
|
6055
|
+
`/rooms${encodeQuery(query)}`,
|
|
6056
|
+
options
|
|
6057
|
+
);
|
|
6058
|
+
},
|
|
6059
|
+
create(input, options) {
|
|
6060
|
+
return request(config, "POST", "/rooms", options, input);
|
|
6061
|
+
},
|
|
6062
|
+
get(roomId, options) {
|
|
6063
|
+
return request(
|
|
6064
|
+
config,
|
|
6065
|
+
"GET",
|
|
6066
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6067
|
+
options
|
|
6068
|
+
);
|
|
6069
|
+
},
|
|
6070
|
+
update(roomId, input, options) {
|
|
6071
|
+
return request(
|
|
6072
|
+
config,
|
|
6073
|
+
"PATCH",
|
|
6074
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}`,
|
|
6075
|
+
options,
|
|
6076
|
+
input
|
|
6077
|
+
);
|
|
6078
|
+
},
|
|
6079
|
+
archive(roomId, options) {
|
|
6080
|
+
return request(
|
|
6081
|
+
config,
|
|
6082
|
+
"POST",
|
|
6083
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/archive`,
|
|
6084
|
+
options
|
|
6085
|
+
);
|
|
6086
|
+
},
|
|
6087
|
+
readCursor: {
|
|
6088
|
+
upTo(roomId, input, options) {
|
|
6089
|
+
return request(
|
|
6090
|
+
config,
|
|
6091
|
+
"POST",
|
|
6092
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/read-cursor`,
|
|
6093
|
+
options,
|
|
6094
|
+
input ?? {}
|
|
6095
|
+
);
|
|
6096
|
+
}
|
|
6097
|
+
},
|
|
6098
|
+
member: {
|
|
6099
|
+
list(roomId, options) {
|
|
6100
|
+
return request(
|
|
6101
|
+
config,
|
|
6102
|
+
"GET",
|
|
6103
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6104
|
+
options
|
|
6105
|
+
);
|
|
6106
|
+
},
|
|
6107
|
+
add(roomId, input, options) {
|
|
6108
|
+
return request(
|
|
6109
|
+
config,
|
|
6110
|
+
"POST",
|
|
6111
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
|
|
6112
|
+
options,
|
|
6113
|
+
input
|
|
6114
|
+
);
|
|
6115
|
+
},
|
|
6116
|
+
remove(roomId, userId, options) {
|
|
6117
|
+
return request(
|
|
6118
|
+
config,
|
|
6119
|
+
"DELETE",
|
|
6120
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/members/${encodePathSegment(userId, "chat user ID")}`,
|
|
6121
|
+
options
|
|
6122
|
+
);
|
|
6123
|
+
}
|
|
6124
|
+
},
|
|
6125
|
+
message: {
|
|
6126
|
+
list(roomId, query, options) {
|
|
6127
|
+
return request(
|
|
6128
|
+
config,
|
|
6129
|
+
"GET",
|
|
6130
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages${encodeQuery(query)}`,
|
|
6131
|
+
options
|
|
6132
|
+
);
|
|
6133
|
+
},
|
|
6134
|
+
send(roomId, input, options) {
|
|
6135
|
+
return request(
|
|
6136
|
+
config,
|
|
6137
|
+
"POST",
|
|
6138
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages`,
|
|
6139
|
+
options,
|
|
6140
|
+
input
|
|
6141
|
+
);
|
|
6142
|
+
},
|
|
6143
|
+
update(roomId, messageId, input, options) {
|
|
6144
|
+
return request(
|
|
6145
|
+
config,
|
|
6146
|
+
"PATCH",
|
|
6147
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6148
|
+
options,
|
|
6149
|
+
input
|
|
6150
|
+
);
|
|
6151
|
+
},
|
|
6152
|
+
delete(roomId, messageId, options) {
|
|
6153
|
+
return request(
|
|
6154
|
+
config,
|
|
6155
|
+
"DELETE",
|
|
6156
|
+
`/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
|
|
6157
|
+
options
|
|
6158
|
+
);
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
},
|
|
6162
|
+
message: {
|
|
6163
|
+
reaction: {
|
|
6164
|
+
add(messageId, input, options) {
|
|
6165
|
+
return request(
|
|
6166
|
+
config,
|
|
6167
|
+
"POST",
|
|
6168
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions`,
|
|
6169
|
+
options,
|
|
6170
|
+
input
|
|
6171
|
+
);
|
|
6172
|
+
},
|
|
6173
|
+
remove(messageId, emoji, options) {
|
|
6174
|
+
return request(
|
|
6175
|
+
config,
|
|
6176
|
+
"DELETE",
|
|
6177
|
+
`/messages/${encodePathSegment(messageId, "chat message ID")}/reactions/${encodePathSegment(emoji, "reaction emoji")}`,
|
|
6178
|
+
options
|
|
6179
|
+
);
|
|
6180
|
+
}
|
|
6181
|
+
},
|
|
6182
|
+
search(input, options) {
|
|
6183
|
+
return request(
|
|
6184
|
+
config,
|
|
6185
|
+
"POST",
|
|
6186
|
+
"/messages/search",
|
|
6187
|
+
options,
|
|
6188
|
+
input
|
|
6189
|
+
);
|
|
6190
|
+
}
|
|
6191
|
+
},
|
|
6192
|
+
realtime
|
|
6193
|
+
};
|
|
6194
|
+
}
|
|
6195
|
+
var chatSdkManifest = {
|
|
6196
|
+
namespace: "chat",
|
|
6197
|
+
basePath: "/chat",
|
|
6198
|
+
methods: [
|
|
6199
|
+
{ name: "listRooms", method: "GET", path: "/chat/rooms" },
|
|
6200
|
+
{ name: "createRoom", method: "POST", path: "/chat/rooms" },
|
|
6201
|
+
{ name: "getRoom", method: "GET", path: "/chat/rooms/{room_id}" },
|
|
6202
|
+
{ name: "updateRoom", method: "PATCH", path: "/chat/rooms/{room_id}" },
|
|
6203
|
+
{ name: "archiveRoom", method: "POST", path: "/chat/rooms/{room_id}/archive" },
|
|
6204
|
+
{ name: "listRoomMessages", method: "GET", path: "/chat/rooms/{room_id}/messages" },
|
|
6205
|
+
{ name: "sendRoomMessage", method: "POST", path: "/chat/rooms/{room_id}/messages" },
|
|
6206
|
+
{ name: "updateRoomMessage", method: "PATCH", path: "/chat/rooms/{room_id}/messages/{message_id}" },
|
|
6207
|
+
{ name: "deleteRoomMessage", method: "DELETE", path: "/chat/rooms/{room_id}/messages/{message_id}" },
|
|
6208
|
+
{ name: "advanceReadCursor", method: "POST", path: "/chat/rooms/{room_id}/read-cursor" },
|
|
6209
|
+
{ name: "listRoomMembers", method: "GET", path: "/chat/rooms/{room_id}/members" },
|
|
6210
|
+
{ name: "addRoomMembers", method: "POST", path: "/chat/rooms/{room_id}/members" },
|
|
6211
|
+
{ name: "removeRoomMember", method: "DELETE", path: "/chat/rooms/{room_id}/members/{user_id}" },
|
|
6212
|
+
{ name: "addReaction", method: "POST", path: "/chat/messages/{message_id}/reactions" },
|
|
6213
|
+
{ name: "removeReaction", method: "DELETE", path: "/chat/messages/{message_id}/reactions/{emoji}" },
|
|
6214
|
+
{ name: "searchMessages", method: "POST", path: "/chat/messages/search" },
|
|
6215
|
+
{ name: "getRealtimeInfo", method: "GET", path: "/wss/info" },
|
|
6216
|
+
{ name: "connectRealtime", method: "GET", path: "/wss/gateway" }
|
|
6217
|
+
]
|
|
6218
|
+
};
|
|
6219
|
+
function unwrapChatRoom(payload) {
|
|
6220
|
+
return unwrapEnvelopeData(payload);
|
|
6221
|
+
}
|
|
6222
|
+
function unwrapChatMessage(payload) {
|
|
6223
|
+
return unwrapEnvelopeData(payload);
|
|
6224
|
+
}
|
|
6225
|
+
|
|
5617
6226
|
// src/client-builder.ts
|
|
5618
6227
|
var DEFAULT_BACKEND = { type: "athena" };
|
|
5619
6228
|
function toBackendConfig(value) {
|
|
@@ -5826,7 +6435,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
5826
6435
|
"ilike",
|
|
5827
6436
|
"is"
|
|
5828
6437
|
]);
|
|
5829
|
-
function
|
|
6438
|
+
function isRecord8(value) {
|
|
5830
6439
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5831
6440
|
}
|
|
5832
6441
|
function isUuidString(value) {
|
|
@@ -5839,7 +6448,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
5839
6448
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
5840
6449
|
}
|
|
5841
6450
|
function isRelationSelectNode(value) {
|
|
5842
|
-
return
|
|
6451
|
+
return isRecord8(value) && isRecord8(value.select);
|
|
5843
6452
|
}
|
|
5844
6453
|
function normalizeIdentifier(value, label) {
|
|
5845
6454
|
const normalized = value.trim();
|
|
@@ -5895,7 +6504,7 @@ function compileRelationToken(key, node) {
|
|
|
5895
6504
|
return `${prefix}${relationToken}(${nested})`;
|
|
5896
6505
|
}
|
|
5897
6506
|
function compileSelectShape(select) {
|
|
5898
|
-
if (!
|
|
6507
|
+
if (!isRecord8(select)) {
|
|
5899
6508
|
throw new Error("findMany select must be an object");
|
|
5900
6509
|
}
|
|
5901
6510
|
const tokens = [];
|
|
@@ -5919,7 +6528,7 @@ function compileSelectShape(select) {
|
|
|
5919
6528
|
return tokens.join(",");
|
|
5920
6529
|
}
|
|
5921
6530
|
function selectShapeUsesRelationSchema(select) {
|
|
5922
|
-
if (!
|
|
6531
|
+
if (!isRecord8(select)) {
|
|
5923
6532
|
return false;
|
|
5924
6533
|
}
|
|
5925
6534
|
for (const rawValue of Object.values(select)) {
|
|
@@ -5937,7 +6546,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
5937
6546
|
}
|
|
5938
6547
|
function compileColumnWhere(column, input) {
|
|
5939
6548
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
5940
|
-
if (!
|
|
6549
|
+
if (!isRecord8(input)) {
|
|
5941
6550
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
5942
6551
|
}
|
|
5943
6552
|
const conditions = [];
|
|
@@ -5965,7 +6574,7 @@ function compileColumnWhere(column, input) {
|
|
|
5965
6574
|
return conditions;
|
|
5966
6575
|
}
|
|
5967
6576
|
function compileBooleanExpressionTerms(clause, label) {
|
|
5968
|
-
if (!
|
|
6577
|
+
if (!isRecord8(clause)) {
|
|
5969
6578
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
5970
6579
|
}
|
|
5971
6580
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -5974,7 +6583,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
5974
6583
|
}
|
|
5975
6584
|
const [rawColumn, rawValue] = entries[0];
|
|
5976
6585
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
5977
|
-
if (!
|
|
6586
|
+
if (!isRecord8(rawValue)) {
|
|
5978
6587
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
5979
6588
|
}
|
|
5980
6589
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -5998,7 +6607,7 @@ function compileWhere(where) {
|
|
|
5998
6607
|
if (where === void 0) {
|
|
5999
6608
|
return void 0;
|
|
6000
6609
|
}
|
|
6001
|
-
if (!
|
|
6610
|
+
if (!isRecord8(where)) {
|
|
6002
6611
|
throw new Error("findMany where must be an object");
|
|
6003
6612
|
}
|
|
6004
6613
|
const conditions = [];
|
|
@@ -6048,7 +6657,7 @@ function compileOrderBy(orderBy) {
|
|
|
6048
6657
|
if (orderBy === void 0) {
|
|
6049
6658
|
return void 0;
|
|
6050
6659
|
}
|
|
6051
|
-
if (!
|
|
6660
|
+
if (!isRecord8(orderBy)) {
|
|
6052
6661
|
throw new Error("findMany orderBy must be an object");
|
|
6053
6662
|
}
|
|
6054
6663
|
if ("column" in orderBy) {
|
|
@@ -6223,11 +6832,11 @@ function toFindManyAstOrder(order) {
|
|
|
6223
6832
|
ascending: order.direction !== "descending"
|
|
6224
6833
|
};
|
|
6225
6834
|
}
|
|
6226
|
-
function
|
|
6835
|
+
function isRecord9(value) {
|
|
6227
6836
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6228
6837
|
}
|
|
6229
6838
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
6230
|
-
if (!
|
|
6839
|
+
if (!isRecord9(value)) {
|
|
6231
6840
|
return {
|
|
6232
6841
|
eq: value
|
|
6233
6842
|
};
|
|
@@ -6251,7 +6860,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
6251
6860
|
return normalized;
|
|
6252
6861
|
}
|
|
6253
6862
|
function normalizeFindManyAstWhere(where) {
|
|
6254
|
-
if (!where || !
|
|
6863
|
+
if (!where || !isRecord9(where)) {
|
|
6255
6864
|
return where;
|
|
6256
6865
|
}
|
|
6257
6866
|
const normalized = {};
|
|
@@ -6265,7 +6874,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6265
6874
|
);
|
|
6266
6875
|
continue;
|
|
6267
6876
|
}
|
|
6268
|
-
if (key === "not" &&
|
|
6877
|
+
if (key === "not" && isRecord9(value)) {
|
|
6269
6878
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
6270
6879
|
value
|
|
6271
6880
|
);
|
|
@@ -6276,7 +6885,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6276
6885
|
return normalized;
|
|
6277
6886
|
}
|
|
6278
6887
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
6279
|
-
if (!
|
|
6888
|
+
if (!isRecord9(value)) {
|
|
6280
6889
|
return shouldUseUuidTextComparison(column, value);
|
|
6281
6890
|
}
|
|
6282
6891
|
const eqValue = value.eq;
|
|
@@ -6294,7 +6903,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
6294
6903
|
return false;
|
|
6295
6904
|
}
|
|
6296
6905
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
6297
|
-
if (!where || !
|
|
6906
|
+
if (!where || !isRecord9(where)) {
|
|
6298
6907
|
return false;
|
|
6299
6908
|
}
|
|
6300
6909
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -6309,7 +6918,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
6309
6918
|
}
|
|
6310
6919
|
continue;
|
|
6311
6920
|
}
|
|
6312
|
-
if (key === "not" &&
|
|
6921
|
+
if (key === "not" && isRecord9(value)) {
|
|
6313
6922
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
6314
6923
|
return true;
|
|
6315
6924
|
}
|
|
@@ -6858,6 +7467,7 @@ function resolveAthenaModelTargetTableName(target, options = {}) {
|
|
|
6858
7467
|
var DEFAULT_COLUMNS = "*";
|
|
6859
7468
|
var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
|
|
6860
7469
|
var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
|
|
7470
|
+
var SDK_NAME4 = "xylex-group/athena";
|
|
6861
7471
|
function formatResult(response) {
|
|
6862
7472
|
const result = {
|
|
6863
7473
|
data: response.data ?? null,
|
|
@@ -6934,7 +7544,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
6934
7544
|
throw error;
|
|
6935
7545
|
}
|
|
6936
7546
|
}
|
|
6937
|
-
function
|
|
7547
|
+
function isRecord10(value) {
|
|
6938
7548
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6939
7549
|
}
|
|
6940
7550
|
function firstNonEmptyString2(...values) {
|
|
@@ -6946,8 +7556,8 @@ function firstNonEmptyString2(...values) {
|
|
|
6946
7556
|
return void 0;
|
|
6947
7557
|
}
|
|
6948
7558
|
function resolveStructuredErrorPayload2(raw) {
|
|
6949
|
-
if (!
|
|
6950
|
-
return
|
|
7559
|
+
if (!isRecord10(raw)) return null;
|
|
7560
|
+
return isRecord10(raw.error) ? raw.error : raw;
|
|
6951
7561
|
}
|
|
6952
7562
|
function resolveStructuredErrorDetails(payload, message) {
|
|
6953
7563
|
if (!payload || !("details" in payload)) {
|
|
@@ -6963,7 +7573,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
6963
7573
|
return details;
|
|
6964
7574
|
}
|
|
6965
7575
|
function createResultError(response, result, normalized) {
|
|
6966
|
-
const rawRecord =
|
|
7576
|
+
const rawRecord = isRecord10(response.raw) ? response.raw : null;
|
|
6967
7577
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
6968
7578
|
const message = firstNonEmptyString2(
|
|
6969
7579
|
response.error,
|
|
@@ -7026,6 +7636,43 @@ function asAthenaJsonObject(value) {
|
|
|
7026
7636
|
function asAthenaJsonObjectArray(values) {
|
|
7027
7637
|
return values;
|
|
7028
7638
|
}
|
|
7639
|
+
function parseArbitraryResponseBody(rawText, contentType) {
|
|
7640
|
+
if (!rawText) {
|
|
7641
|
+
return null;
|
|
7642
|
+
}
|
|
7643
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
7644
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
7645
|
+
if (!looksJson) {
|
|
7646
|
+
return rawText;
|
|
7647
|
+
}
|
|
7648
|
+
try {
|
|
7649
|
+
return JSON.parse(rawText);
|
|
7650
|
+
} catch {
|
|
7651
|
+
return rawText;
|
|
7652
|
+
}
|
|
7653
|
+
}
|
|
7654
|
+
function toRequestQueryString(query) {
|
|
7655
|
+
if (!query) {
|
|
7656
|
+
return "";
|
|
7657
|
+
}
|
|
7658
|
+
const params = new URLSearchParams();
|
|
7659
|
+
for (const [key, value] of Object.entries(query)) {
|
|
7660
|
+
if (value === void 0 || value === null) {
|
|
7661
|
+
continue;
|
|
7662
|
+
}
|
|
7663
|
+
if (Array.isArray(value)) {
|
|
7664
|
+
for (const item of value) {
|
|
7665
|
+
if (item !== void 0 && item !== null) {
|
|
7666
|
+
params.append(key, String(item));
|
|
7667
|
+
}
|
|
7668
|
+
}
|
|
7669
|
+
continue;
|
|
7670
|
+
}
|
|
7671
|
+
params.set(key, String(value));
|
|
7672
|
+
}
|
|
7673
|
+
const encoded = params.toString();
|
|
7674
|
+
return encoded ? `?${encoded}` : "";
|
|
7675
|
+
}
|
|
7029
7676
|
function normalizeSelectColumnsInput(columns) {
|
|
7030
7677
|
if (columns === void 0) {
|
|
7031
7678
|
return void 0;
|
|
@@ -8332,6 +8979,8 @@ var ATHENA_ENV_GATEWAY_URL_KEYS = [
|
|
|
8332
8979
|
"NEXT_PUBLIC_ATHENA_DB_API_URL"
|
|
8333
8980
|
];
|
|
8334
8981
|
var ATHENA_ENV_AUTH_URL_KEYS = ["ATHENA_AUTH_URL", "NEXT_PUBLIC_ATHENA_AUTH_URL"];
|
|
8982
|
+
var ATHENA_ENV_CHAT_URL_KEYS = ["ATHENA_CHAT_URL", "NEXT_PUBLIC_ATHENA_CHAT_URL"];
|
|
8983
|
+
var ATHENA_ENV_CHAT_WS_URL_KEYS = ["ATHENA_CHAT_WS_URL", "NEXT_PUBLIC_ATHENA_CHAT_WS_URL"];
|
|
8335
8984
|
var ATHENA_ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
|
|
8336
8985
|
var ATHENA_ENV_KEY_KEYS = [
|
|
8337
8986
|
"ATHENA_API_KEY",
|
|
@@ -8412,6 +9061,15 @@ function appendServicePath(baseUrl, segment) {
|
|
|
8412
9061
|
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
8413
9062
|
return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
|
|
8414
9063
|
}
|
|
9064
|
+
function appendRealtimeGatewayPath(baseUrl) {
|
|
9065
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
|
|
9066
|
+
const wsUrl = new URL(normalizedBaseUrl);
|
|
9067
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
9068
|
+
wsUrl.pathname = `${wsUrl.pathname.replace(/\/+$/, "")}/wss/gateway`;
|
|
9069
|
+
wsUrl.search = "";
|
|
9070
|
+
wsUrl.hash = "";
|
|
9071
|
+
return wsUrl.toString();
|
|
9072
|
+
}
|
|
8415
9073
|
function resolveServiceUrlOverride(value, label) {
|
|
8416
9074
|
return resolveClientServiceBaseUrl(value, label);
|
|
8417
9075
|
}
|
|
@@ -8420,6 +9078,8 @@ function resolveServiceUrls(config) {
|
|
|
8420
9078
|
return {
|
|
8421
9079
|
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),
|
|
8422
9080
|
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),
|
|
9081
|
+
chatUrl: resolveServiceUrlOverride(config.chat?.url, "Athena chat base URL") ?? resolveServiceUrlOverride(config.chatUrl, "Athena chat base URL") ?? (baseUrl ? appendServicePath(baseUrl, "chat") : void 0),
|
|
9082
|
+
chatWsUrl: normalizeOptionalString(config.chat?.wsUrl) ?? normalizeOptionalString(config.chatWsUrl) ?? (baseUrl ? appendRealtimeGatewayPath(baseUrl) : void 0),
|
|
8423
9083
|
storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
|
|
8424
9084
|
};
|
|
8425
9085
|
}
|
|
@@ -8512,6 +9172,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8512
9172
|
} : void 0,
|
|
8513
9173
|
db: base.db ? { ...base.db } : void 0,
|
|
8514
9174
|
gateway: base.gateway ? { ...base.gateway } : void 0,
|
|
9175
|
+
chat: base.chat ? { ...base.chat } : void 0,
|
|
8515
9176
|
storage: base.storage ? { ...base.storage } : void 0
|
|
8516
9177
|
};
|
|
8517
9178
|
}
|
|
@@ -8522,6 +9183,7 @@ function mergeClientOverrideOptions(base, overrides) {
|
|
|
8522
9183
|
auth: mergeAuthClientOptions(base.auth, overrides.auth),
|
|
8523
9184
|
db: mergeServiceUrlOverrides(base.db, overrides.db),
|
|
8524
9185
|
gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
|
|
9186
|
+
chat: mergeServiceUrlOverrides(base.chat, overrides.chat),
|
|
8525
9187
|
storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
|
|
8526
9188
|
};
|
|
8527
9189
|
}
|
|
@@ -8580,6 +9242,9 @@ function resolveCreateClientConfig(config) {
|
|
|
8580
9242
|
headers: config.headers,
|
|
8581
9243
|
auth: config.auth,
|
|
8582
9244
|
authUrl: resolvedUrls.authUrl,
|
|
9245
|
+
chat: config.chat,
|
|
9246
|
+
chatUrl: resolvedUrls.chatUrl,
|
|
9247
|
+
chatWsUrl: resolvedUrls.chatWsUrl,
|
|
8583
9248
|
storageUrl: resolvedUrls.storageUrl,
|
|
8584
9249
|
experimental: config.experimental
|
|
8585
9250
|
};
|
|
@@ -8664,6 +9329,119 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8664
9329
|
queryTracer
|
|
8665
9330
|
);
|
|
8666
9331
|
const db = createDbModule({ from, rpc, query });
|
|
9332
|
+
const chat = createChatModule({
|
|
9333
|
+
baseUrl: config.chatUrl,
|
|
9334
|
+
apiKey: config.apiKey,
|
|
9335
|
+
client: config.client,
|
|
9336
|
+
headers: config.headers,
|
|
9337
|
+
bearerToken: normalizedAuthConfig?.bearerToken,
|
|
9338
|
+
cookie: normalizedAuthConfig?.cookie,
|
|
9339
|
+
sessionToken: normalizedAuthConfig?.sessionToken,
|
|
9340
|
+
forceNoCache: config.forceNoCache,
|
|
9341
|
+
wsUrl: config.chatWsUrl,
|
|
9342
|
+
webSocketFactory: config.chat?.webSocketFactory ?? void 0
|
|
9343
|
+
});
|
|
9344
|
+
const request2 = async (options) => {
|
|
9345
|
+
const method = options.method ?? "GET";
|
|
9346
|
+
const responseType = options.responseType ?? "json";
|
|
9347
|
+
const service = options.service ?? "db";
|
|
9348
|
+
const baseUrlByService = {
|
|
9349
|
+
db: config.baseUrl,
|
|
9350
|
+
auth: config.authUrl,
|
|
9351
|
+
chat: config.chatUrl,
|
|
9352
|
+
storage: config.storageUrl
|
|
9353
|
+
};
|
|
9354
|
+
const resolvedBaseUrl = options.url ?? baseUrlByService[service];
|
|
9355
|
+
if (!resolvedBaseUrl) {
|
|
9356
|
+
throw new Error(
|
|
9357
|
+
`Athena ${service} base URL is not configured. Pass createClient({ url }) for unified routing or set the service-specific URL first.`
|
|
9358
|
+
);
|
|
9359
|
+
}
|
|
9360
|
+
const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(resolvedBaseUrl, {
|
|
9361
|
+
label: `Athena ${service} base URL`
|
|
9362
|
+
});
|
|
9363
|
+
const normalizedPath = options.url ? "" : (() => {
|
|
9364
|
+
const path = options.path?.trim();
|
|
9365
|
+
if (!path) {
|
|
9366
|
+
throw new Error("client.request(...) requires either an absolute url or a non-empty path.");
|
|
9367
|
+
}
|
|
9368
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
9369
|
+
})();
|
|
9370
|
+
const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
|
|
9371
|
+
const headers = {
|
|
9372
|
+
"X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
|
|
9373
|
+
...config.headers ?? {},
|
|
9374
|
+
...options.headers ?? {}
|
|
9375
|
+
};
|
|
9376
|
+
if (service !== "auth") {
|
|
9377
|
+
headers.apikey = headers.apikey ?? config.apiKey;
|
|
9378
|
+
headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
|
|
9379
|
+
if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
|
|
9380
|
+
headers["X-Athena-Client"] = config.client;
|
|
9381
|
+
}
|
|
9382
|
+
if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
|
|
9383
|
+
headers["X-User-Id"] = config.userId;
|
|
9384
|
+
}
|
|
9385
|
+
if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
|
|
9386
|
+
headers["X-Organization-Id"] = config.organizationId;
|
|
9387
|
+
}
|
|
9388
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9389
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9390
|
+
}
|
|
9391
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
|
|
9392
|
+
headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
|
|
9393
|
+
}
|
|
9394
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9395
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9396
|
+
}
|
|
9397
|
+
} else {
|
|
9398
|
+
const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
|
|
9399
|
+
if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
|
|
9400
|
+
headers.apikey = headers.apikey ?? authApiKey;
|
|
9401
|
+
headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
|
|
9402
|
+
}
|
|
9403
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
|
|
9404
|
+
headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
|
|
9405
|
+
}
|
|
9406
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
|
|
9407
|
+
headers.Cookie = normalizedAuthConfig.cookie;
|
|
9408
|
+
}
|
|
9409
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
|
|
9410
|
+
headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
9411
|
+
}
|
|
9412
|
+
}
|
|
9413
|
+
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";
|
|
9414
|
+
if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
|
|
9415
|
+
headers["Content-Type"] = "application/json";
|
|
9416
|
+
}
|
|
9417
|
+
const response = await fetch(targetUrl, {
|
|
9418
|
+
method,
|
|
9419
|
+
headers,
|
|
9420
|
+
body: options.body === void 0 || options.body === null ? void 0 : shouldSendJsonBody ? JSON.stringify(options.body) : options.body,
|
|
9421
|
+
signal: options.signal,
|
|
9422
|
+
credentials: options.credentials
|
|
9423
|
+
});
|
|
9424
|
+
if (responseType === "response") {
|
|
9425
|
+
return {
|
|
9426
|
+
ok: response.ok,
|
|
9427
|
+
status: response.status,
|
|
9428
|
+
statusText: response.statusText,
|
|
9429
|
+
headers: response.headers,
|
|
9430
|
+
data: null,
|
|
9431
|
+
raw: response
|
|
9432
|
+
};
|
|
9433
|
+
}
|
|
9434
|
+
const rawText = await response.text();
|
|
9435
|
+
const parsed = responseType === "text" ? rawText : parseArbitraryResponseBody(rawText, response.headers.get("content-type"));
|
|
9436
|
+
return {
|
|
9437
|
+
ok: response.ok,
|
|
9438
|
+
status: response.status,
|
|
9439
|
+
statusText: response.statusText,
|
|
9440
|
+
headers: response.headers,
|
|
9441
|
+
data: parsed,
|
|
9442
|
+
raw: response
|
|
9443
|
+
};
|
|
9444
|
+
};
|
|
8667
9445
|
const withContext = (context) => createClientFromInput(
|
|
8668
9446
|
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8669
9447
|
);
|
|
@@ -8679,8 +9457,10 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8679
9457
|
db,
|
|
8680
9458
|
rpc,
|
|
8681
9459
|
query,
|
|
9460
|
+
request: request2,
|
|
8682
9461
|
verifyConnection: gateway.verifyConnection,
|
|
8683
9462
|
auth: auth.auth,
|
|
9463
|
+
chat,
|
|
8684
9464
|
withContext,
|
|
8685
9465
|
withSession,
|
|
8686
9466
|
withOptions: authWithOptions
|
|
@@ -8725,6 +9505,8 @@ var AthenaClient = class {
|
|
|
8725
9505
|
const url = options.url ?? readFirstEnvValue(env, ATHENA_ENV_URL_KEYS);
|
|
8726
9506
|
const gatewayUrl = options.gatewayUrl ?? readFirstEnvValue(env, ATHENA_ENV_GATEWAY_URL_KEYS);
|
|
8727
9507
|
const authUrl = options.authUrl ?? readFirstEnvValue(env, ATHENA_ENV_AUTH_URL_KEYS);
|
|
9508
|
+
const chatUrl = options.chatUrl ?? readFirstEnvValue(env, ATHENA_ENV_CHAT_URL_KEYS);
|
|
9509
|
+
const chatWsUrl = options.chatWsUrl ?? readFirstEnvValue(env, ATHENA_ENV_CHAT_WS_URL_KEYS);
|
|
8728
9510
|
const storageUrl = options.storageUrl ?? readFirstEnvValue(env, ATHENA_ENV_STORAGE_URL_KEYS);
|
|
8729
9511
|
const key = options.key ?? readFirstEnvValue(env, ATHENA_ENV_KEY_KEYS);
|
|
8730
9512
|
const client = options.client ?? readFirstEnvValue(env, ATHENA_ENV_CLIENT_KEYS);
|
|
@@ -8739,6 +9521,8 @@ var AthenaClient = class {
|
|
|
8739
9521
|
url,
|
|
8740
9522
|
gatewayUrl,
|
|
8741
9523
|
authUrl,
|
|
9524
|
+
chatUrl,
|
|
9525
|
+
chatWsUrl,
|
|
8742
9526
|
storageUrl,
|
|
8743
9527
|
key,
|
|
8744
9528
|
client
|
|
@@ -8784,7 +9568,7 @@ function resolveNullishValue(mode) {
|
|
|
8784
9568
|
if (mode === "null") return null;
|
|
8785
9569
|
return "";
|
|
8786
9570
|
}
|
|
8787
|
-
function
|
|
9571
|
+
function isRecord11(value) {
|
|
8788
9572
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
8789
9573
|
}
|
|
8790
9574
|
function isNullableColumn(model, key) {
|
|
@@ -8793,7 +9577,7 @@ function isNullableColumn(model, key) {
|
|
|
8793
9577
|
}
|
|
8794
9578
|
function toModelFormDefaults(model, values, options) {
|
|
8795
9579
|
const source = values;
|
|
8796
|
-
if (!
|
|
9580
|
+
if (!isRecord11(source)) {
|
|
8797
9581
|
return {};
|
|
8798
9582
|
}
|
|
8799
9583
|
const mode = options?.nullishMode ?? "empty-string";
|
|
@@ -9307,6 +10091,9 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
9307
10091
|
query(query, options) {
|
|
9308
10092
|
return this.baseClient.query(query, options);
|
|
9309
10093
|
}
|
|
10094
|
+
request(options) {
|
|
10095
|
+
return this.baseClient.request(options);
|
|
10096
|
+
}
|
|
9310
10097
|
verifyConnection(options) {
|
|
9311
10098
|
return this.baseClient.verifyConnection(options);
|
|
9312
10099
|
}
|
|
@@ -9740,15 +10527,15 @@ function readCookieFromHeaders(headers, name) {
|
|
|
9740
10527
|
}
|
|
9741
10528
|
return parseCookies(cookieHeader).get(name);
|
|
9742
10529
|
}
|
|
9743
|
-
function
|
|
10530
|
+
function isRecord12(value) {
|
|
9744
10531
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
9745
10532
|
}
|
|
9746
10533
|
function resolveSessionCandidate(value) {
|
|
9747
|
-
if (!
|
|
10534
|
+
if (!isRecord12(value)) {
|
|
9748
10535
|
return null;
|
|
9749
10536
|
}
|
|
9750
|
-
const session =
|
|
9751
|
-
const user =
|
|
10537
|
+
const session = isRecord12(value.session) ? value.session : void 0;
|
|
10538
|
+
const user = isRecord12(value.user) ? value.user : void 0;
|
|
9752
10539
|
if (session && typeof session.token === "string" && session.token.length > 0 && user) {
|
|
9753
10540
|
return {
|
|
9754
10541
|
session,
|
|
@@ -9758,7 +10545,7 @@ function resolveSessionCandidate(value) {
|
|
|
9758
10545
|
return null;
|
|
9759
10546
|
}
|
|
9760
10547
|
function inferSessionPair(returned) {
|
|
9761
|
-
return resolveSessionCandidate(returned) ?? (
|
|
10548
|
+
return resolveSessionCandidate(returned) ?? (isRecord12(returned) ? resolveSessionCandidate(returned.data) : null) ?? (isRecord12(returned) ? resolveSessionCandidate(returned.session) : null);
|
|
9762
10549
|
}
|
|
9763
10550
|
function resolveResponseHeaders(ctx) {
|
|
9764
10551
|
if (ctx.context.responseHeaders instanceof Headers) {
|
|
@@ -9781,23 +10568,23 @@ function normalizeBasePath(basePath) {
|
|
|
9781
10568
|
function isDynamicBaseURLConfig2(baseURL) {
|
|
9782
10569
|
return typeof baseURL === "object" && baseURL !== null && "allowedHosts" in baseURL && Array.isArray(baseURL.allowedHosts);
|
|
9783
10570
|
}
|
|
9784
|
-
function getRequestUrl(
|
|
10571
|
+
function getRequestUrl(request2) {
|
|
9785
10572
|
try {
|
|
9786
|
-
return new URL(
|
|
10573
|
+
return new URL(request2.url);
|
|
9787
10574
|
} catch {
|
|
9788
10575
|
return new URL("http://localhost");
|
|
9789
10576
|
}
|
|
9790
10577
|
}
|
|
9791
|
-
function getRequestHost(
|
|
9792
|
-
const forwardedHost =
|
|
9793
|
-
const host = forwardedHost ||
|
|
10578
|
+
function getRequestHost(request2, url) {
|
|
10579
|
+
const forwardedHost = request2.headers.get("x-forwarded-host")?.split(",")[0]?.trim();
|
|
10580
|
+
const host = forwardedHost || request2.headers.get("host") || url.host;
|
|
9794
10581
|
return host || null;
|
|
9795
10582
|
}
|
|
9796
|
-
function getRequestProtocol(
|
|
10583
|
+
function getRequestProtocol(request2, configuredProtocol, url) {
|
|
9797
10584
|
if (configuredProtocol === "http" || configuredProtocol === "https") {
|
|
9798
10585
|
return configuredProtocol;
|
|
9799
10586
|
}
|
|
9800
|
-
const forwardedProto =
|
|
10587
|
+
const forwardedProto = request2.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
|
|
9801
10588
|
if (forwardedProto === "http" || forwardedProto === "https") {
|
|
9802
10589
|
return forwardedProto;
|
|
9803
10590
|
}
|
|
@@ -9806,12 +10593,12 @@ function getRequestProtocol(request, configuredProtocol, url) {
|
|
|
9806
10593
|
}
|
|
9807
10594
|
return "http";
|
|
9808
10595
|
}
|
|
9809
|
-
function resolveRequestBaseURL(baseURL,
|
|
10596
|
+
function resolveRequestBaseURL(baseURL, request2) {
|
|
9810
10597
|
if (typeof baseURL === "string") {
|
|
9811
10598
|
return normalizeBaseURL(baseURL);
|
|
9812
10599
|
}
|
|
9813
|
-
const requestUrl = getRequestUrl(
|
|
9814
|
-
const host = getRequestHost(
|
|
10600
|
+
const requestUrl = getRequestUrl(request2);
|
|
10601
|
+
const host = getRequestHost(request2, requestUrl);
|
|
9815
10602
|
if (!host) {
|
|
9816
10603
|
return null;
|
|
9817
10604
|
}
|
|
@@ -9821,7 +10608,7 @@ function resolveRequestBaseURL(baseURL, request) {
|
|
|
9821
10608
|
return null;
|
|
9822
10609
|
}
|
|
9823
10610
|
}
|
|
9824
|
-
const protocol = typeof baseURL === "object" && baseURL !== null ? getRequestProtocol(
|
|
10611
|
+
const protocol = typeof baseURL === "object" && baseURL !== null ? getRequestProtocol(request2, baseURL.protocol, requestUrl) : getRequestProtocol(request2, void 0, requestUrl);
|
|
9825
10612
|
return `${protocol}://${host}`;
|
|
9826
10613
|
}
|
|
9827
10614
|
function getOrigin(baseURL) {
|
|
@@ -9834,16 +10621,16 @@ function getOrigin(baseURL) {
|
|
|
9834
10621
|
return void 0;
|
|
9835
10622
|
}
|
|
9836
10623
|
}
|
|
9837
|
-
async function resolveTrustedOrigins(config, baseURL,
|
|
9838
|
-
const resolved = typeof config.trustedOrigins === "function" ? await config.trustedOrigins(
|
|
10624
|
+
async function resolveTrustedOrigins(config, baseURL, request2) {
|
|
10625
|
+
const resolved = typeof config.trustedOrigins === "function" ? await config.trustedOrigins(request2) : config.trustedOrigins ?? [];
|
|
9839
10626
|
const values = [
|
|
9840
10627
|
getOrigin(baseURL),
|
|
9841
10628
|
...resolved
|
|
9842
10629
|
];
|
|
9843
10630
|
return Array.from(new Set(values.filter((value) => typeof value === "string" && value.length > 0)));
|
|
9844
10631
|
}
|
|
9845
|
-
async function resolveTrustedProviders(config,
|
|
9846
|
-
const configured = typeof config.trustedProviders === "function" ? await config.trustedProviders(
|
|
10632
|
+
async function resolveTrustedProviders(config, request2) {
|
|
10633
|
+
const configured = typeof config.trustedProviders === "function" ? await config.trustedProviders(request2) : config.trustedProviders ?? [];
|
|
9847
10634
|
const values = [
|
|
9848
10635
|
...Object.keys(config.socialProviders ?? {}),
|
|
9849
10636
|
...configured
|
|
@@ -9968,9 +10755,9 @@ function athenaAuth(config) {
|
|
|
9968
10755
|
}
|
|
9969
10756
|
return ctx;
|
|
9970
10757
|
};
|
|
9971
|
-
const resolveRequestContext = async (
|
|
9972
|
-
const requestUrl = getRequestUrl(
|
|
9973
|
-
const resolvedBaseURL = resolveRequestBaseURL(config.baseURL,
|
|
10758
|
+
const resolveRequestContext = async (request2) => {
|
|
10759
|
+
const requestUrl = getRequestUrl(request2);
|
|
10760
|
+
const resolvedBaseURL = resolveRequestBaseURL(config.baseURL, request2);
|
|
9974
10761
|
if (!resolvedBaseURL) {
|
|
9975
10762
|
throw new Error(
|
|
9976
10763
|
isDynamicBaseURLConfig2(config.baseURL) ? "Could not resolve base URL from request. Check allowedHosts/baseURL." : "Could not resolve base URL from request."
|
|
@@ -9981,17 +10768,17 @@ function athenaAuth(config) {
|
|
|
9981
10768
|
session: config.session,
|
|
9982
10769
|
advanced: config.advanced
|
|
9983
10770
|
});
|
|
9984
|
-
const trustedOrigins = await resolveTrustedOrigins(config, resolvedBaseURL,
|
|
9985
|
-
const trustedProviders = await resolveTrustedProviders(config,
|
|
10771
|
+
const trustedOrigins = await resolveTrustedOrigins(config, resolvedBaseURL, request2);
|
|
10772
|
+
const trustedProviders = await resolveTrustedProviders(config, request2);
|
|
9986
10773
|
return {
|
|
9987
10774
|
auth,
|
|
9988
|
-
request,
|
|
10775
|
+
request: request2,
|
|
9989
10776
|
url: requestUrl,
|
|
9990
10777
|
path: requestUrl.pathname,
|
|
9991
10778
|
basePath: normalizedBasePath,
|
|
9992
10779
|
baseURL: resolvedBaseURL,
|
|
9993
10780
|
origin: getOrigin(resolvedBaseURL) ?? resolvedBaseURL,
|
|
9994
|
-
headers:
|
|
10781
|
+
headers: request2.headers,
|
|
9995
10782
|
cookies: requestCookies,
|
|
9996
10783
|
trustedOrigins,
|
|
9997
10784
|
trustedProviders,
|
|
@@ -10004,8 +10791,8 @@ function athenaAuth(config) {
|
|
|
10004
10791
|
socialProviders: auth.socialProviders
|
|
10005
10792
|
};
|
|
10006
10793
|
};
|
|
10007
|
-
const handler = async (
|
|
10008
|
-
const requestContext = await resolveRequestContext(
|
|
10794
|
+
const handler = async (request2) => {
|
|
10795
|
+
const requestContext = await resolveRequestContext(request2);
|
|
10009
10796
|
if (typeof config.handler !== "function") {
|
|
10010
10797
|
return createJsonResponse(
|
|
10011
10798
|
{
|
|
@@ -10026,7 +10813,7 @@ function athenaAuth(config) {
|
|
|
10026
10813
|
const responseHeaders = new Headers(response.headers);
|
|
10027
10814
|
await runAfterHooks({
|
|
10028
10815
|
path: requestContext.path,
|
|
10029
|
-
headers:
|
|
10816
|
+
headers: request2.headers,
|
|
10030
10817
|
context: {
|
|
10031
10818
|
responseHeaders,
|
|
10032
10819
|
returned: result.returned,
|
|
@@ -10139,6 +10926,7 @@ exports.ATHENA_AUTH_MAX_ADMIN_JSON_BYTES = ATHENA_AUTH_MAX_ADMIN_JSON_BYTES;
|
|
|
10139
10926
|
exports.ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH = ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH;
|
|
10140
10927
|
exports.ATHENA_AUTH_MAX_TEMPLATE_VARIABLES = ATHENA_AUTH_MAX_TEMPLATE_VARIABLES;
|
|
10141
10928
|
exports.ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH = ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH;
|
|
10929
|
+
exports.AthenaChatError = AthenaChatError;
|
|
10142
10930
|
exports.AthenaClient = AthenaClient;
|
|
10143
10931
|
exports.AthenaError = AthenaError;
|
|
10144
10932
|
exports.AthenaErrorCategory = AthenaErrorCategory;
|
|
@@ -10152,6 +10940,7 @@ exports.DEFAULT_POSTGRES_SCHEMAS = DEFAULT_POSTGRES_SCHEMAS;
|
|
|
10152
10940
|
exports.assertInt = assertInt;
|
|
10153
10941
|
exports.athenaAuth = athenaAuth;
|
|
10154
10942
|
exports.boolean = boolean;
|
|
10943
|
+
exports.chatSdkManifest = chatSdkManifest;
|
|
10155
10944
|
exports.coerceInt = coerceInt;
|
|
10156
10945
|
exports.createAthenaStorageError = createAthenaStorageError;
|
|
10157
10946
|
exports.createAuthClient = createAuthClient;
|
|
@@ -10198,6 +10987,8 @@ exports.table = table;
|
|
|
10198
10987
|
exports.toModelFormDefaults = toModelFormDefaults;
|
|
10199
10988
|
exports.toModelPayload = toModelPayload;
|
|
10200
10989
|
exports.unwrap = unwrap;
|
|
10990
|
+
exports.unwrapChatMessage = unwrapChatMessage;
|
|
10991
|
+
exports.unwrapChatRoom = unwrapChatRoom;
|
|
10201
10992
|
exports.unwrapOne = unwrapOne;
|
|
10202
10993
|
exports.unwrapRows = unwrapRows;
|
|
10203
10994
|
exports.verifyAthenaGatewayUrl = verifyAthenaGatewayUrl;
|