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