@xylex-group/athena 2.8.2 → 2.9.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 +154 -64
- package/dist/browser.cjs +636 -21
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +8 -7
- package/dist/browser.d.ts +8 -7
- package/dist/browser.js +630 -22
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +591 -29
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +591 -29
- package/dist/cli/index.js.map +1 -1
- package/dist/{model-form-Cx3wtvi8.d.ts → client-CfAE_QOj.d.cts} +101 -97
- package/dist/{model-form-_ugfOXao.d.cts → client-D6EIJdQS.d.ts} +101 -97
- package/dist/index.cjs +714 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +708 -42
- package/dist/index.js.map +1 -1
- package/dist/model-form-ByvyyvxB.d.ts +96 -0
- package/dist/model-form-DACdBLYG.d.cts +96 -0
- package/dist/next/client.cjs +7875 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.cts +25 -0
- package/dist/next/client.d.ts +25 -0
- package/dist/next/client.js +7873 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/server.cjs +7993 -0
- package/dist/next/server.cjs.map +1 -0
- package/dist/next/server.d.cts +52 -0
- package/dist/next/server.d.ts +52 -0
- package/dist/next/server.js +7990 -0
- package/dist/next/server.js.map +1 -0
- package/dist/{pipeline-BtD-Uo5X.d.cts → pipeline-CmUZsXsi.d.cts} +1 -1
- package/dist/{pipeline-yCIZNJHE.d.ts → pipeline-DZMsPxUg.d.ts} +1 -1
- package/dist/{react-email-CiiSVa9F.d.cts → react-email-BvJ3fj_F.d.cts} +35 -5
- package/dist/{react-email-WN8UU3AL.d.ts → react-email-PLAJuZuO.d.ts} +35 -5
- package/dist/react.cjs +30 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +39 -10
- package/dist/react.d.ts +39 -10
- package/dist/react.js +30 -2
- package/dist/react.js.map +1 -1
- package/dist/shared-BW6hoLBY.d.cts +33 -0
- package/dist/shared-BiJvoURI.d.ts +33 -0
- package/dist/{types-g8G6J0xE.d.cts → types-BeZIHduP.d.cts} +2 -1
- package/dist/{types-g8G6J0xE.d.ts → types-BeZIHduP.d.ts} +2 -1
- package/dist/{types-C2kiTt6-.d.ts → types-C-YvfgYh.d.cts} +26 -2
- package/dist/{types-89EfjLjV.d.cts → types-CRjDwmtJ.d.ts} +26 -2
- package/package.json +32 -14
package/dist/browser.js
CHANGED
|
@@ -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.9.0"
|
|
804
804
|
};
|
|
805
805
|
|
|
806
806
|
// src/sdk-version.ts
|
|
@@ -813,6 +813,7 @@ function buildSdkHeaderValue(sdkName) {
|
|
|
813
813
|
var DEFAULT_CLIENT = "railway_direct";
|
|
814
814
|
var SDK_NAME = "xylex-group/athena";
|
|
815
815
|
var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
|
|
816
|
+
var NO_CACHE_HEADER_VALUE = "no-cache";
|
|
816
817
|
function parseResponseBody(rawText, contentType) {
|
|
817
818
|
if (!rawText) {
|
|
818
819
|
return { parsed: null, parseFailed: false };
|
|
@@ -831,6 +832,9 @@ function parseResponseBody(rawText, contentType) {
|
|
|
831
832
|
function normalizeHeaderValue(value) {
|
|
832
833
|
return value ? value : void 0;
|
|
833
834
|
}
|
|
835
|
+
function isCacheControlHeaderName(name) {
|
|
836
|
+
return name.toLowerCase() === "cache-control";
|
|
837
|
+
}
|
|
834
838
|
function resolveHeaderValue(headers, candidates) {
|
|
835
839
|
for (const candidate of candidates) {
|
|
836
840
|
const direct = normalizeHeaderValue(headers[candidate]);
|
|
@@ -989,6 +993,7 @@ function buildRpcGetEndpoint(payload) {
|
|
|
989
993
|
}
|
|
990
994
|
function buildHeaders(config, options) {
|
|
991
995
|
const mergedStripNulls = options?.stripNulls ?? true;
|
|
996
|
+
const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
|
|
992
997
|
const extraHeaders = {
|
|
993
998
|
...config.headers ?? {},
|
|
994
999
|
...options?.headers ?? {}
|
|
@@ -1042,11 +1047,15 @@ function buildHeaders(config, options) {
|
|
|
1042
1047
|
const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
|
|
1043
1048
|
Object.entries(extraHeaders).forEach(([key, value]) => {
|
|
1044
1049
|
if (athenaClientKeys.includes(key)) return;
|
|
1050
|
+
if (forceNoCache && isCacheControlHeaderName(key)) return;
|
|
1045
1051
|
const normalized = normalizeHeaderValue(value);
|
|
1046
1052
|
if (normalized) {
|
|
1047
1053
|
headers[key] = normalized;
|
|
1048
1054
|
}
|
|
1049
1055
|
});
|
|
1056
|
+
if (forceNoCache) {
|
|
1057
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
|
|
1058
|
+
}
|
|
1050
1059
|
return headers;
|
|
1051
1060
|
}
|
|
1052
1061
|
function toInvalidUrlResponse(error, endpoint, method) {
|
|
@@ -1507,6 +1516,45 @@ function identifier(...segments) {
|
|
|
1507
1516
|
return new SqlIdentifierPath(expandedSegments);
|
|
1508
1517
|
}
|
|
1509
1518
|
|
|
1519
|
+
// src/auth/limits.ts
|
|
1520
|
+
var ATHENA_AUTH_MAX_ADMIN_JSON_BYTES = 32 * 1024;
|
|
1521
|
+
var ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH = 8;
|
|
1522
|
+
var ATHENA_AUTH_MAX_TEMPLATE_VARIABLES = 64;
|
|
1523
|
+
var ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH = 128;
|
|
1524
|
+
var ATHENA_AUTH_ADMIN_LIMITS = {
|
|
1525
|
+
maxAdminJsonBytes: ATHENA_AUTH_MAX_ADMIN_JSON_BYTES,
|
|
1526
|
+
maxAdminJsonDepth: ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH,
|
|
1527
|
+
maxTemplateVariables: ATHENA_AUTH_MAX_TEMPLATE_VARIABLES,
|
|
1528
|
+
maxTemplateVariableLength: ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH
|
|
1529
|
+
};
|
|
1530
|
+
function describeTemplateVariableTarget(target) {
|
|
1531
|
+
const normalized = target?.trim();
|
|
1532
|
+
return normalized && normalized.length > 0 ? normalized : "Athena auth admin email template variables";
|
|
1533
|
+
}
|
|
1534
|
+
function assertAthenaAuthTemplateVariables(variables, target) {
|
|
1535
|
+
const label = describeTemplateVariableTarget(target);
|
|
1536
|
+
if (!Array.isArray(variables)) {
|
|
1537
|
+
throw new Error(`${label} must be an array of strings.`);
|
|
1538
|
+
}
|
|
1539
|
+
if (variables.length > ATHENA_AUTH_MAX_TEMPLATE_VARIABLES) {
|
|
1540
|
+
throw new Error(
|
|
1541
|
+
`${label} cannot contain more than ${ATHENA_AUTH_MAX_TEMPLATE_VARIABLES} entries.`
|
|
1542
|
+
);
|
|
1543
|
+
}
|
|
1544
|
+
variables.forEach((variable, index) => {
|
|
1545
|
+
if (typeof variable !== "string") {
|
|
1546
|
+
throw new Error(
|
|
1547
|
+
`${label} must contain only strings. Received ${typeof variable} at index ${index}.`
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
if (variable.length > ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH) {
|
|
1551
|
+
throw new Error(
|
|
1552
|
+
`${label} cannot contain entries longer than ${ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH} characters. Received ${variable.length} characters at index ${index}.`
|
|
1553
|
+
);
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1510
1558
|
// src/auth/react-email.ts
|
|
1511
1559
|
var reactEmailRenderModulePromise;
|
|
1512
1560
|
function isRecord2(value) {
|
|
@@ -1736,6 +1784,7 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
|
|
|
1736
1784
|
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
1737
1785
|
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
1738
1786
|
var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
|
|
1787
|
+
var NO_CACHE_HEADER_VALUE2 = "no-cache";
|
|
1739
1788
|
function normalizeBaseUrl(baseUrl) {
|
|
1740
1789
|
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
1741
1790
|
}
|
|
@@ -1745,6 +1794,9 @@ function isRecord3(value) {
|
|
|
1745
1794
|
function normalizeHeaderValue2(value) {
|
|
1746
1795
|
return value ? value : void 0;
|
|
1747
1796
|
}
|
|
1797
|
+
function isCacheControlHeaderName2(name) {
|
|
1798
|
+
return name.toLowerCase() === "cache-control";
|
|
1799
|
+
}
|
|
1748
1800
|
function parseResponseBody2(rawText, contentType) {
|
|
1749
1801
|
if (!rawText) {
|
|
1750
1802
|
return { parsed: null, parseFailed: false };
|
|
@@ -1800,6 +1852,54 @@ function mergeCallOptions(base, override) {
|
|
|
1800
1852
|
}
|
|
1801
1853
|
};
|
|
1802
1854
|
}
|
|
1855
|
+
function toSessionGuardFailure(sessionResult) {
|
|
1856
|
+
if (sessionResult.status === 401 || sessionResult.data == null) {
|
|
1857
|
+
return {
|
|
1858
|
+
ok: false,
|
|
1859
|
+
reason: "unauthorized",
|
|
1860
|
+
status: 401,
|
|
1861
|
+
error: sessionResult.error ?? "Unauthorized",
|
|
1862
|
+
sessionResult
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
return {
|
|
1866
|
+
ok: false,
|
|
1867
|
+
reason: "upstream_error",
|
|
1868
|
+
status: sessionResult.status,
|
|
1869
|
+
error: sessionResult.error ?? "Failed to resolve current session",
|
|
1870
|
+
sessionResult
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
function toPermissionGuardFailure(permissionResult, sessionResult) {
|
|
1874
|
+
if (permissionResult.status === 401) {
|
|
1875
|
+
return {
|
|
1876
|
+
ok: false,
|
|
1877
|
+
reason: "unauthorized",
|
|
1878
|
+
status: 401,
|
|
1879
|
+
error: permissionResult.error ?? "Unauthorized",
|
|
1880
|
+
sessionResult,
|
|
1881
|
+
permissionResult
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
if (permissionResult.status === 403) {
|
|
1885
|
+
return {
|
|
1886
|
+
ok: false,
|
|
1887
|
+
reason: "forbidden",
|
|
1888
|
+
status: 403,
|
|
1889
|
+
error: permissionResult.error ?? "Forbidden",
|
|
1890
|
+
sessionResult,
|
|
1891
|
+
permissionResult
|
|
1892
|
+
};
|
|
1893
|
+
}
|
|
1894
|
+
return {
|
|
1895
|
+
ok: false,
|
|
1896
|
+
reason: "upstream_error",
|
|
1897
|
+
status: permissionResult.status,
|
|
1898
|
+
error: permissionResult.error ?? "Failed to resolve permission check",
|
|
1899
|
+
sessionResult,
|
|
1900
|
+
permissionResult
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1803
1903
|
function extractFetchOptions(input) {
|
|
1804
1904
|
if (!input) {
|
|
1805
1905
|
return {
|
|
@@ -1815,6 +1915,7 @@ function extractFetchOptions(input) {
|
|
|
1815
1915
|
};
|
|
1816
1916
|
}
|
|
1817
1917
|
function buildHeaders2(config, options) {
|
|
1918
|
+
const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
|
|
1818
1919
|
const headers = {
|
|
1819
1920
|
"Content-Type": "application/json",
|
|
1820
1921
|
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
@@ -1828,16 +1929,30 @@ function buildHeaders2(config, options) {
|
|
|
1828
1929
|
if (bearerToken) {
|
|
1829
1930
|
headers.Authorization = `Bearer ${bearerToken}`;
|
|
1830
1931
|
}
|
|
1932
|
+
const cookie = options?.cookie ?? config.cookie;
|
|
1933
|
+
if (cookie) {
|
|
1934
|
+
headers.Cookie = cookie;
|
|
1935
|
+
}
|
|
1936
|
+
const sessionToken = options?.sessionToken ?? config.sessionToken;
|
|
1937
|
+
if (sessionToken) {
|
|
1938
|
+
headers["X-Athena-Auth-Session-Token"] = sessionToken;
|
|
1939
|
+
}
|
|
1831
1940
|
const mergedExtraHeaders = {
|
|
1832
1941
|
...config.headers ?? {},
|
|
1833
1942
|
...options?.headers ?? {}
|
|
1834
1943
|
};
|
|
1835
1944
|
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
1945
|
+
if (forceNoCache && isCacheControlHeaderName2(key)) {
|
|
1946
|
+
return;
|
|
1947
|
+
}
|
|
1836
1948
|
const normalized = normalizeHeaderValue2(value);
|
|
1837
1949
|
if (normalized) {
|
|
1838
1950
|
headers[key] = normalized;
|
|
1839
1951
|
}
|
|
1840
1952
|
});
|
|
1953
|
+
if (forceNoCache) {
|
|
1954
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
|
|
1955
|
+
}
|
|
1841
1956
|
return headers;
|
|
1842
1957
|
}
|
|
1843
1958
|
function appendQueryParam(searchParams, key, value) {
|
|
@@ -2102,7 +2217,91 @@ function createAuthClient(config = {}) {
|
|
|
2102
2217
|
htmlField: "htmlTemplate",
|
|
2103
2218
|
textField: "textTemplate",
|
|
2104
2219
|
variablesField: "variables"
|
|
2105
|
-
}, withReactEmailRoute(route))
|
|
2220
|
+
}, withReactEmailRoute(route)).then((payload) => {
|
|
2221
|
+
if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
|
|
2222
|
+
assertAthenaAuthTemplateVariables(
|
|
2223
|
+
payload.variables,
|
|
2224
|
+
`${route} variables`
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2227
|
+
return payload;
|
|
2228
|
+
});
|
|
2229
|
+
const requireSession = async (input, options) => {
|
|
2230
|
+
const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
|
|
2231
|
+
const sessionResult = await getGeneric(
|
|
2232
|
+
"/get-session",
|
|
2233
|
+
sessionInput,
|
|
2234
|
+
options
|
|
2235
|
+
);
|
|
2236
|
+
if (!sessionResult.ok || sessionResult.data == null) {
|
|
2237
|
+
return toSessionGuardFailure(sessionResult);
|
|
2238
|
+
}
|
|
2239
|
+
return {
|
|
2240
|
+
ok: true,
|
|
2241
|
+
session: sessionResult.data
|
|
2242
|
+
};
|
|
2243
|
+
};
|
|
2244
|
+
const getUser = async (input, options) => {
|
|
2245
|
+
const sessionResult = await getGeneric(
|
|
2246
|
+
"/get-session",
|
|
2247
|
+
input,
|
|
2248
|
+
options
|
|
2249
|
+
);
|
|
2250
|
+
if (!sessionResult.ok) {
|
|
2251
|
+
return {
|
|
2252
|
+
...sessionResult,
|
|
2253
|
+
data: null
|
|
2254
|
+
};
|
|
2255
|
+
}
|
|
2256
|
+
return {
|
|
2257
|
+
...sessionResult,
|
|
2258
|
+
data: {
|
|
2259
|
+
user: sessionResult.data?.user ?? null
|
|
2260
|
+
}
|
|
2261
|
+
};
|
|
2262
|
+
};
|
|
2263
|
+
const requirePermission = async (endpoint, input, options) => {
|
|
2264
|
+
const sessionGuard = await requireSession(
|
|
2265
|
+
input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0,
|
|
2266
|
+
options
|
|
2267
|
+
);
|
|
2268
|
+
if (!sessionGuard.ok) {
|
|
2269
|
+
return sessionGuard;
|
|
2270
|
+
}
|
|
2271
|
+
const permissionResult = await postGeneric(
|
|
2272
|
+
endpoint,
|
|
2273
|
+
input,
|
|
2274
|
+
options
|
|
2275
|
+
);
|
|
2276
|
+
if (!permissionResult.ok) {
|
|
2277
|
+
return toPermissionGuardFailure(permissionResult, {
|
|
2278
|
+
ok: true,
|
|
2279
|
+
status: 200,
|
|
2280
|
+
data: sessionGuard.session,
|
|
2281
|
+
error: null,
|
|
2282
|
+
errorDetails: null,
|
|
2283
|
+
raw: sessionGuard.session
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
if (!permissionResult.data?.success) {
|
|
2287
|
+
return {
|
|
2288
|
+
ok: false,
|
|
2289
|
+
reason: "forbidden",
|
|
2290
|
+
status: 403,
|
|
2291
|
+
error: permissionResult.data?.error ?? "Forbidden",
|
|
2292
|
+
sessionResult: {
|
|
2293
|
+
ok: true,
|
|
2294
|
+
status: 200,
|
|
2295
|
+
data: sessionGuard.session,
|
|
2296
|
+
error: null,
|
|
2297
|
+
errorDetails: null,
|
|
2298
|
+
raw: sessionGuard.session
|
|
2299
|
+
},
|
|
2300
|
+
permissionResult
|
|
2301
|
+
};
|
|
2302
|
+
}
|
|
2303
|
+
return sessionGuard;
|
|
2304
|
+
};
|
|
2106
2305
|
const listUserEmailsWithFallback = async (input, options) => {
|
|
2107
2306
|
const primary = await getWithQuery(
|
|
2108
2307
|
"/email/list",
|
|
@@ -2264,6 +2463,7 @@ function createAuthClient(config = {}) {
|
|
|
2264
2463
|
input,
|
|
2265
2464
|
options
|
|
2266
2465
|
),
|
|
2466
|
+
requirePermission: (input, options) => requirePermission("/organization/has-permission", input, options),
|
|
2267
2467
|
invitation: {
|
|
2268
2468
|
cancel: (input, options) => executePostWithCompatibleInput(
|
|
2269
2469
|
resolvedConfig,
|
|
@@ -2459,6 +2659,8 @@ function createAuthClient(config = {}) {
|
|
|
2459
2659
|
};
|
|
2460
2660
|
const auth = {
|
|
2461
2661
|
getSession: (input, options) => getGeneric("/get-session", input, options),
|
|
2662
|
+
getUser,
|
|
2663
|
+
requireSession,
|
|
2462
2664
|
signOut,
|
|
2463
2665
|
forgetPassword: (input, options) => postGeneric("/forget-password", input, options),
|
|
2464
2666
|
resetPassword: authResetPassword,
|
|
@@ -2553,6 +2755,7 @@ function createAuthClient(config = {}) {
|
|
|
2553
2755
|
}
|
|
2554
2756
|
},
|
|
2555
2757
|
hasPermission: (input, options) => postGeneric("/admin/has-permission", input, options),
|
|
2758
|
+
requirePermission: (input, options) => requirePermission("/admin/has-permission", input, options),
|
|
2556
2759
|
apiKey: {
|
|
2557
2760
|
create: (input, options) => postGeneric("/admin/api-key/create", input, options)
|
|
2558
2761
|
},
|
|
@@ -2704,6 +2907,8 @@ function createAuthClient(config = {}) {
|
|
|
2704
2907
|
input,
|
|
2705
2908
|
options
|
|
2706
2909
|
),
|
|
2910
|
+
getUser,
|
|
2911
|
+
requireSession,
|
|
2707
2912
|
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
2708
2913
|
resolvedConfig,
|
|
2709
2914
|
{ endpoint: "/list-sessions", method: "GET" },
|
|
@@ -5459,6 +5664,9 @@ var AthenaClientBuilderImpl = class {
|
|
|
5459
5664
|
apiKey;
|
|
5460
5665
|
backendConfig = DEFAULT_BACKEND;
|
|
5461
5666
|
clientName;
|
|
5667
|
+
defaultUserId;
|
|
5668
|
+
defaultOrganizationId;
|
|
5669
|
+
forceNoCacheEnabled = false;
|
|
5462
5670
|
defaultHeaders;
|
|
5463
5671
|
authConfig;
|
|
5464
5672
|
dbUrlOverride;
|
|
@@ -5507,6 +5715,15 @@ var AthenaClientBuilderImpl = class {
|
|
|
5507
5715
|
if (options.client !== void 0) {
|
|
5508
5716
|
this.clientName = options.client;
|
|
5509
5717
|
}
|
|
5718
|
+
if (options.userId !== void 0) {
|
|
5719
|
+
this.defaultUserId = options.userId;
|
|
5720
|
+
}
|
|
5721
|
+
if (options.organizationId !== void 0) {
|
|
5722
|
+
this.defaultOrganizationId = options.organizationId;
|
|
5723
|
+
}
|
|
5724
|
+
if (options.forceNoCache !== void 0) {
|
|
5725
|
+
this.forceNoCacheEnabled = options.forceNoCache;
|
|
5726
|
+
}
|
|
5510
5727
|
if (options.backend !== void 0) {
|
|
5511
5728
|
this.backendConfig = toBackendConfig(options.backend);
|
|
5512
5729
|
}
|
|
@@ -5561,6 +5778,9 @@ var AthenaClientBuilderImpl = class {
|
|
|
5561
5778
|
url: this.rootUrl,
|
|
5562
5779
|
key: this.apiKey,
|
|
5563
5780
|
client: this.clientName,
|
|
5781
|
+
userId: this.defaultUserId,
|
|
5782
|
+
organizationId: this.defaultOrganizationId,
|
|
5783
|
+
forceNoCache: this.forceNoCacheEnabled,
|
|
5564
5784
|
backend: this.backendConfig,
|
|
5565
5785
|
headers: this.defaultHeaders,
|
|
5566
5786
|
db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
|
|
@@ -8103,6 +8323,83 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
|
8103
8323
|
);
|
|
8104
8324
|
};
|
|
8105
8325
|
}
|
|
8326
|
+
var ATHENA_ENV_URL_KEYS = ["ATHENA_URL", "NEXT_PUBLIC_ATHENA_URL"];
|
|
8327
|
+
var ATHENA_ENV_GATEWAY_URL_KEYS = [
|
|
8328
|
+
"ATHENA_DB_URL",
|
|
8329
|
+
"ATHENA_GATEWAY_URL",
|
|
8330
|
+
"NEXT_PUBLIC_ATHENA_DB_API_URL"
|
|
8331
|
+
];
|
|
8332
|
+
var ATHENA_ENV_AUTH_URL_KEYS = ["ATHENA_AUTH_URL", "NEXT_PUBLIC_ATHENA_AUTH_URL"];
|
|
8333
|
+
var ATHENA_ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
|
|
8334
|
+
var ATHENA_ENV_KEY_KEYS = [
|
|
8335
|
+
"ATHENA_API_KEY",
|
|
8336
|
+
"NEXT_PUBLIC_ATHENA_API_KEY",
|
|
8337
|
+
"ATHENA_GATEWAY_API_KEY",
|
|
8338
|
+
"X_API_KEY"
|
|
8339
|
+
];
|
|
8340
|
+
var ATHENA_ENV_CLIENT_KEYS = ["ATHENA_CLIENT", "NEXT_PUBLIC_ATHENA_CLIENT"];
|
|
8341
|
+
function normalizeOptionalString(value) {
|
|
8342
|
+
if (typeof value !== "string") {
|
|
8343
|
+
return void 0;
|
|
8344
|
+
}
|
|
8345
|
+
const normalizedValue = value.trim();
|
|
8346
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
8347
|
+
}
|
|
8348
|
+
function readFirstEnvValue(env, keys) {
|
|
8349
|
+
for (const key of keys) {
|
|
8350
|
+
const value = normalizeOptionalString(env[key]);
|
|
8351
|
+
if (value) {
|
|
8352
|
+
return value;
|
|
8353
|
+
}
|
|
8354
|
+
}
|
|
8355
|
+
return void 0;
|
|
8356
|
+
}
|
|
8357
|
+
function readHeaderBagValue(headers, targetKey) {
|
|
8358
|
+
if (!headers) {
|
|
8359
|
+
return void 0;
|
|
8360
|
+
}
|
|
8361
|
+
if (typeof headers.get === "function") {
|
|
8362
|
+
return normalizeOptionalString(headers.get(targetKey));
|
|
8363
|
+
}
|
|
8364
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
8365
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
8366
|
+
if (key.toLowerCase() !== normalizedTargetKey) {
|
|
8367
|
+
continue;
|
|
8368
|
+
}
|
|
8369
|
+
if (typeof value === "string") {
|
|
8370
|
+
return normalizeOptionalString(value);
|
|
8371
|
+
}
|
|
8372
|
+
return void 0;
|
|
8373
|
+
}
|
|
8374
|
+
return void 0;
|
|
8375
|
+
}
|
|
8376
|
+
function resolveSessionContextOptions(session, options) {
|
|
8377
|
+
const sessionToken = normalizeOptionalString(session?.session?.token);
|
|
8378
|
+
const requestCookie = readHeaderBagValue(options?.requestHeaders, "cookie") ?? readHeaderBagValue(options?.headers, "cookie");
|
|
8379
|
+
const authInput = options?.auth;
|
|
8380
|
+
const resolvedUserId = options?.userId !== void 0 ? options.userId : session?.user?.id;
|
|
8381
|
+
const resolvedOrganizationId = options?.organizationId !== void 0 ? options.organizationId : session?.session?.activeOrganizationId;
|
|
8382
|
+
const resolvedBearerToken = authInput?.bearerToken !== void 0 ? authInput.bearerToken : sessionToken;
|
|
8383
|
+
const resolvedSessionToken = authInput?.sessionToken !== void 0 ? authInput.sessionToken : sessionToken;
|
|
8384
|
+
const resolvedCookie = authInput?.cookie !== void 0 ? authInput.cookie : requestCookie;
|
|
8385
|
+
const auth = authInput !== void 0 || resolvedBearerToken !== void 0 || resolvedSessionToken !== void 0 || resolvedCookie !== void 0 ? {
|
|
8386
|
+
...authInput ?? {},
|
|
8387
|
+
...resolvedBearerToken !== void 0 ? { bearerToken: resolvedBearerToken } : {},
|
|
8388
|
+
...resolvedSessionToken !== void 0 ? { sessionToken: resolvedSessionToken } : {},
|
|
8389
|
+
...resolvedCookie !== void 0 ? { cookie: resolvedCookie } : {},
|
|
8390
|
+
headers: authInput?.headers ? { ...authInput.headers } : void 0
|
|
8391
|
+
} : void 0;
|
|
8392
|
+
if (resolvedUserId === void 0 && resolvedOrganizationId === void 0 && options?.forceNoCache === void 0 && !options?.headers && !auth) {
|
|
8393
|
+
return void 0;
|
|
8394
|
+
}
|
|
8395
|
+
return {
|
|
8396
|
+
userId: resolvedUserId,
|
|
8397
|
+
organizationId: resolvedOrganizationId,
|
|
8398
|
+
forceNoCache: options?.forceNoCache,
|
|
8399
|
+
headers: options?.headers ? { ...options.headers } : void 0,
|
|
8400
|
+
auth
|
|
8401
|
+
};
|
|
8402
|
+
}
|
|
8106
8403
|
function resolveClientServiceBaseUrl(value, label) {
|
|
8107
8404
|
if (value === void 0 || value === null) {
|
|
8108
8405
|
return void 0;
|
|
@@ -8145,6 +8442,87 @@ function resolveRequiredClientApiKey(value) {
|
|
|
8145
8442
|
}
|
|
8146
8443
|
return normalizedValue;
|
|
8147
8444
|
}
|
|
8445
|
+
function hasHeaderIgnoreCase(headers, targetKey) {
|
|
8446
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
8447
|
+
return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
|
|
8448
|
+
}
|
|
8449
|
+
function mergeClientHeaders(current, next) {
|
|
8450
|
+
if (!current && !next) {
|
|
8451
|
+
return void 0;
|
|
8452
|
+
}
|
|
8453
|
+
return {
|
|
8454
|
+
...current ?? {},
|
|
8455
|
+
...next ?? {}
|
|
8456
|
+
};
|
|
8457
|
+
}
|
|
8458
|
+
function mergeDefinedObject(current, next) {
|
|
8459
|
+
if (!current && !next) {
|
|
8460
|
+
return void 0;
|
|
8461
|
+
}
|
|
8462
|
+
const merged = {
|
|
8463
|
+
...current ?? {}
|
|
8464
|
+
};
|
|
8465
|
+
const mutableMerged = merged;
|
|
8466
|
+
for (const [key, value] of Object.entries(next ?? {})) {
|
|
8467
|
+
if (value !== void 0) {
|
|
8468
|
+
mutableMerged[key] = value;
|
|
8469
|
+
}
|
|
8470
|
+
}
|
|
8471
|
+
return merged;
|
|
8472
|
+
}
|
|
8473
|
+
function mergeAuthClientOptions(current, next) {
|
|
8474
|
+
const merged = mergeDefinedObject(current, next);
|
|
8475
|
+
if (!merged) {
|
|
8476
|
+
return void 0;
|
|
8477
|
+
}
|
|
8478
|
+
const mergedHeaders = mergeClientHeaders(current?.headers, next?.headers);
|
|
8479
|
+
if (mergedHeaders) {
|
|
8480
|
+
merged.headers = mergedHeaders;
|
|
8481
|
+
}
|
|
8482
|
+
return merged;
|
|
8483
|
+
}
|
|
8484
|
+
function mergeServiceUrlOverrides(current, next) {
|
|
8485
|
+
return mergeDefinedObject(current, next);
|
|
8486
|
+
}
|
|
8487
|
+
function toClientContextOverrides(context) {
|
|
8488
|
+
if (!context) {
|
|
8489
|
+
return void 0;
|
|
8490
|
+
}
|
|
8491
|
+
return {
|
|
8492
|
+
userId: context.userId,
|
|
8493
|
+
organizationId: context.organizationId,
|
|
8494
|
+
forceNoCache: context.forceNoCache,
|
|
8495
|
+
headers: context.headers,
|
|
8496
|
+
auth: context.auth ? {
|
|
8497
|
+
...context.auth,
|
|
8498
|
+
headers: context.auth.headers ? { ...context.auth.headers } : void 0
|
|
8499
|
+
} : void 0
|
|
8500
|
+
};
|
|
8501
|
+
}
|
|
8502
|
+
function mergeClientOverrideOptions(base, overrides) {
|
|
8503
|
+
if (!overrides) {
|
|
8504
|
+
return {
|
|
8505
|
+
...base,
|
|
8506
|
+
headers: base.headers ? { ...base.headers } : void 0,
|
|
8507
|
+
auth: base.auth ? {
|
|
8508
|
+
...base.auth,
|
|
8509
|
+
headers: base.auth.headers ? { ...base.auth.headers } : void 0
|
|
8510
|
+
} : void 0,
|
|
8511
|
+
db: base.db ? { ...base.db } : void 0,
|
|
8512
|
+
gateway: base.gateway ? { ...base.gateway } : void 0,
|
|
8513
|
+
storage: base.storage ? { ...base.storage } : void 0
|
|
8514
|
+
};
|
|
8515
|
+
}
|
|
8516
|
+
const merged = mergeDefinedObject(base, overrides) ?? { ...base };
|
|
8517
|
+
return {
|
|
8518
|
+
...merged,
|
|
8519
|
+
headers: mergeClientHeaders(base.headers, overrides.headers),
|
|
8520
|
+
auth: mergeAuthClientOptions(base.auth, overrides.auth),
|
|
8521
|
+
db: mergeServiceUrlOverrides(base.db, overrides.db),
|
|
8522
|
+
gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
|
|
8523
|
+
storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
|
|
8524
|
+
};
|
|
8525
|
+
}
|
|
8148
8526
|
function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
8149
8527
|
if (!auth && defaultBaseUrl === void 0) {
|
|
8150
8528
|
return void 0;
|
|
@@ -8154,6 +8532,8 @@ function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
|
8154
8532
|
baseUrl,
|
|
8155
8533
|
apiKey,
|
|
8156
8534
|
bearerToken,
|
|
8535
|
+
cookie,
|
|
8536
|
+
sessionToken,
|
|
8157
8537
|
...rest
|
|
8158
8538
|
} = auth ?? {};
|
|
8159
8539
|
const normalized = {
|
|
@@ -8172,6 +8552,12 @@ function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
|
8172
8552
|
if (typeof bearerToken === "string") {
|
|
8173
8553
|
normalized.bearerToken = bearerToken;
|
|
8174
8554
|
}
|
|
8555
|
+
if (typeof cookie === "string") {
|
|
8556
|
+
normalized.cookie = cookie;
|
|
8557
|
+
}
|
|
8558
|
+
if (typeof sessionToken === "string") {
|
|
8559
|
+
normalized.sessionToken = sessionToken;
|
|
8560
|
+
}
|
|
8175
8561
|
return normalized;
|
|
8176
8562
|
}
|
|
8177
8563
|
function resolveCreateClientConfig(config) {
|
|
@@ -8185,6 +8571,9 @@ function resolveCreateClientConfig(config) {
|
|
|
8185
8571
|
baseUrl: resolvedUrls.dbUrl,
|
|
8186
8572
|
apiKey: resolveRequiredClientApiKey(config.key),
|
|
8187
8573
|
client: resolveOptionalClientName(config.client),
|
|
8574
|
+
userId: config.userId,
|
|
8575
|
+
organizationId: config.organizationId,
|
|
8576
|
+
forceNoCache: config.forceNoCache,
|
|
8188
8577
|
backend: toBackendConfig(config.backend),
|
|
8189
8578
|
headers: config.headers,
|
|
8190
8579
|
auth: config.auth,
|
|
@@ -8193,23 +8582,39 @@ function resolveCreateClientConfig(config) {
|
|
|
8193
8582
|
experimental: config.experimental
|
|
8194
8583
|
};
|
|
8195
8584
|
}
|
|
8196
|
-
function
|
|
8585
|
+
function createClientFromInput(sourceConfig) {
|
|
8586
|
+
return createClientFromConfig(resolveCreateClientConfig(sourceConfig), sourceConfig);
|
|
8587
|
+
}
|
|
8588
|
+
function createClientFromConfig(config, sourceConfig) {
|
|
8589
|
+
const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
|
|
8197
8590
|
const gatewayHeaders = {
|
|
8198
8591
|
...config.headers ?? {}
|
|
8199
8592
|
};
|
|
8200
|
-
if (
|
|
8201
|
-
gatewayHeaders["X-Athena-Auth-Bearer-Token"] =
|
|
8593
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
|
|
8594
|
+
gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
|
|
8595
|
+
}
|
|
8596
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
|
|
8597
|
+
gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
|
|
8598
|
+
}
|
|
8599
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
|
|
8600
|
+
gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
8202
8601
|
}
|
|
8203
8602
|
const gateway = createAthenaGatewayClient({
|
|
8204
8603
|
baseUrl: config.baseUrl,
|
|
8205
8604
|
apiKey: config.apiKey,
|
|
8206
8605
|
client: config.client,
|
|
8606
|
+
userId: config.userId,
|
|
8607
|
+
organizationId: config.organizationId,
|
|
8608
|
+
forceNoCache: config.forceNoCache,
|
|
8207
8609
|
backend: config.backend,
|
|
8208
8610
|
headers: gatewayHeaders
|
|
8209
8611
|
});
|
|
8210
8612
|
const formatGatewayResult = createResultFormatter(config.experimental);
|
|
8211
8613
|
const queryTracer = createQueryTracer(config.experimental);
|
|
8212
|
-
const auth = createAuthClient(
|
|
8614
|
+
const auth = createAuthClient({
|
|
8615
|
+
...normalizedAuthConfig ?? {},
|
|
8616
|
+
...config.forceNoCache ? { forceNoCache: true } : {}
|
|
8617
|
+
});
|
|
8213
8618
|
function from(tableOrModel, options) {
|
|
8214
8619
|
if (isAthenaModelTarget(tableOrModel)) {
|
|
8215
8620
|
if (options?.schema !== void 0) {
|
|
@@ -8257,17 +8662,45 @@ function createClientFromConfig(config) {
|
|
|
8257
8662
|
queryTracer
|
|
8258
8663
|
);
|
|
8259
8664
|
const db = createDbModule({ from, rpc, query });
|
|
8665
|
+
const withContext = (context) => createClientFromInput(
|
|
8666
|
+
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8667
|
+
);
|
|
8668
|
+
const withSession = (session, options) => createClientFromInput(
|
|
8669
|
+
mergeClientOverrideOptions(
|
|
8670
|
+
sourceConfig,
|
|
8671
|
+
toClientContextOverrides(resolveSessionContextOptions(session, options))
|
|
8672
|
+
)
|
|
8673
|
+
);
|
|
8674
|
+
const authWithOptions = (options) => createClientFromInput(mergeClientOverrideOptions(sourceConfig, options));
|
|
8260
8675
|
const sdkClient = {
|
|
8261
8676
|
from,
|
|
8262
8677
|
db,
|
|
8263
8678
|
rpc,
|
|
8264
8679
|
query,
|
|
8265
8680
|
verifyConnection: gateway.verifyConnection,
|
|
8266
|
-
auth: auth.auth
|
|
8681
|
+
auth: auth.auth,
|
|
8682
|
+
withContext,
|
|
8683
|
+
withSession,
|
|
8684
|
+
withOptions: authWithOptions
|
|
8267
8685
|
};
|
|
8268
8686
|
if (config.experimental?.athenaStorageBackend) {
|
|
8687
|
+
const storageWithContext = (context) => createClientFromInput(
|
|
8688
|
+
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8689
|
+
);
|
|
8690
|
+
const storageWithSession = (session, options) => createClientFromInput(
|
|
8691
|
+
mergeClientOverrideOptions(
|
|
8692
|
+
sourceConfig,
|
|
8693
|
+
toClientContextOverrides(resolveSessionContextOptions(session, options))
|
|
8694
|
+
)
|
|
8695
|
+
);
|
|
8696
|
+
const storageWithOptions = (options) => createClientFromInput(
|
|
8697
|
+
mergeClientOverrideOptions(sourceConfig, options)
|
|
8698
|
+
);
|
|
8269
8699
|
const storageClient = {
|
|
8270
8700
|
...sdkClient,
|
|
8701
|
+
withContext: storageWithContext,
|
|
8702
|
+
withSession: storageWithSession,
|
|
8703
|
+
withOptions: storageWithOptions,
|
|
8271
8704
|
storage: createStorageModule(gateway, {
|
|
8272
8705
|
...config.experimental.storage,
|
|
8273
8706
|
...config.storageUrl ? {
|
|
@@ -8283,38 +8716,42 @@ function createClientFromConfig(config) {
|
|
|
8283
8716
|
var AthenaClient = class {
|
|
8284
8717
|
/** Create a fluent builder for a strongly-typed Athena SDK client. */
|
|
8285
8718
|
static builder() {
|
|
8286
|
-
return createAthenaClientBuilder((config) =>
|
|
8287
|
-
}
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
const url =
|
|
8291
|
-
const gatewayUrl =
|
|
8292
|
-
const authUrl =
|
|
8293
|
-
const storageUrl =
|
|
8294
|
-
const key =
|
|
8719
|
+
return createAthenaClientBuilder((config) => createClientFromInput(config));
|
|
8720
|
+
}
|
|
8721
|
+
static fromEnvironment(options = {}) {
|
|
8722
|
+
const env = options.env ?? process.env;
|
|
8723
|
+
const url = options.url ?? readFirstEnvValue(env, ATHENA_ENV_URL_KEYS);
|
|
8724
|
+
const gatewayUrl = options.gatewayUrl ?? readFirstEnvValue(env, ATHENA_ENV_GATEWAY_URL_KEYS);
|
|
8725
|
+
const authUrl = options.authUrl ?? readFirstEnvValue(env, ATHENA_ENV_AUTH_URL_KEYS);
|
|
8726
|
+
const storageUrl = options.storageUrl ?? readFirstEnvValue(env, ATHENA_ENV_STORAGE_URL_KEYS);
|
|
8727
|
+
const key = options.key ?? readFirstEnvValue(env, ATHENA_ENV_KEY_KEYS);
|
|
8728
|
+
const client = options.client ?? readFirstEnvValue(env, ATHENA_ENV_CLIENT_KEYS);
|
|
8295
8729
|
if (!url && !gatewayUrl || !key) {
|
|
8296
8730
|
throw new Error(
|
|
8297
|
-
"
|
|
8731
|
+
"AthenaClient.fromEnvironment() requires an API key plus a public or gateway URL. Supported aliases include ATHENA_API_KEY, NEXT_PUBLIC_ATHENA_API_KEY, ATHENA_GATEWAY_API_KEY, X_API_KEY, ATHENA_URL, NEXT_PUBLIC_ATHENA_URL, ATHENA_GATEWAY_URL, and ATHENA_DB_URL."
|
|
8298
8732
|
);
|
|
8299
8733
|
}
|
|
8734
|
+
const { env: _env, ...clientOptions } = options;
|
|
8300
8735
|
return createClient({
|
|
8736
|
+
...clientOptions,
|
|
8301
8737
|
url,
|
|
8302
8738
|
gatewayUrl,
|
|
8303
8739
|
authUrl,
|
|
8304
8740
|
storageUrl,
|
|
8305
|
-
key
|
|
8741
|
+
key,
|
|
8742
|
+
client
|
|
8306
8743
|
});
|
|
8307
8744
|
}
|
|
8308
8745
|
};
|
|
8309
8746
|
function createClient(configOrUrl, apiKey, options) {
|
|
8310
8747
|
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
8311
|
-
return
|
|
8748
|
+
return createClientFromInput({
|
|
8312
8749
|
url: configOrUrl,
|
|
8313
8750
|
key: apiKey ?? "",
|
|
8314
8751
|
...options
|
|
8315
|
-
})
|
|
8752
|
+
});
|
|
8316
8753
|
}
|
|
8317
|
-
return
|
|
8754
|
+
return createClientFromInput(configOrUrl);
|
|
8318
8755
|
}
|
|
8319
8756
|
|
|
8320
8757
|
// src/gateway/types.ts
|
|
@@ -8680,6 +9117,9 @@ function createColumnsBuilder(name, mappedName, schemaName, columns) {
|
|
|
8680
9117
|
resolveTableTarget(name, mappedName, normalizedSchemaName);
|
|
8681
9118
|
return createColumnsBuilder(name, mappedName, normalizedSchemaName, columns);
|
|
8682
9119
|
},
|
|
9120
|
+
withoutPrimaryKey() {
|
|
9121
|
+
return finalizeTable(name, mappedName, schemaName, columns, []);
|
|
9122
|
+
},
|
|
8683
9123
|
primaryKey(...keys) {
|
|
8684
9124
|
return finalizeTable(name, mappedName, schemaName, columns, keys);
|
|
8685
9125
|
}
|
|
@@ -8731,6 +9171,59 @@ var TenantHeaderMapper = class {
|
|
|
8731
9171
|
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
8732
9172
|
}
|
|
8733
9173
|
};
|
|
9174
|
+
function normalizeOptionalString2(value) {
|
|
9175
|
+
if (typeof value !== "string") {
|
|
9176
|
+
return void 0;
|
|
9177
|
+
}
|
|
9178
|
+
const normalizedValue = value.trim();
|
|
9179
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
9180
|
+
}
|
|
9181
|
+
function readHeaderBagValue2(headers, targetKey) {
|
|
9182
|
+
if (!headers) {
|
|
9183
|
+
return void 0;
|
|
9184
|
+
}
|
|
9185
|
+
if (typeof headers.get === "function") {
|
|
9186
|
+
return normalizeOptionalString2(headers.get(targetKey));
|
|
9187
|
+
}
|
|
9188
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
9189
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
9190
|
+
if (key.toLowerCase() !== normalizedTargetKey) {
|
|
9191
|
+
continue;
|
|
9192
|
+
}
|
|
9193
|
+
if (typeof value === "string") {
|
|
9194
|
+
return normalizeOptionalString2(value);
|
|
9195
|
+
}
|
|
9196
|
+
return void 0;
|
|
9197
|
+
}
|
|
9198
|
+
return void 0;
|
|
9199
|
+
}
|
|
9200
|
+
function resolveSessionContextOptions2(session, options) {
|
|
9201
|
+
const sessionToken = normalizeOptionalString2(session?.session?.token);
|
|
9202
|
+
const requestCookie = readHeaderBagValue2(options?.requestHeaders, "cookie") ?? readHeaderBagValue2(options?.headers, "cookie");
|
|
9203
|
+
const authInput = options?.auth;
|
|
9204
|
+
const resolvedUserId = options?.userId !== void 0 ? options.userId : session?.user?.id;
|
|
9205
|
+
const resolvedOrganizationId = options?.organizationId !== void 0 ? options.organizationId : session?.session?.activeOrganizationId;
|
|
9206
|
+
const resolvedBearerToken = authInput?.bearerToken !== void 0 ? authInput.bearerToken : sessionToken;
|
|
9207
|
+
const resolvedSessionToken = authInput?.sessionToken !== void 0 ? authInput.sessionToken : sessionToken;
|
|
9208
|
+
const resolvedCookie = authInput?.cookie !== void 0 ? authInput.cookie : requestCookie;
|
|
9209
|
+
const auth = authInput !== void 0 || resolvedBearerToken !== void 0 || resolvedSessionToken !== void 0 || resolvedCookie !== void 0 ? {
|
|
9210
|
+
...authInput ?? {},
|
|
9211
|
+
...resolvedBearerToken !== void 0 ? { bearerToken: resolvedBearerToken } : {},
|
|
9212
|
+
...resolvedSessionToken !== void 0 ? { sessionToken: resolvedSessionToken } : {},
|
|
9213
|
+
...resolvedCookie !== void 0 ? { cookie: resolvedCookie } : {},
|
|
9214
|
+
headers: authInput?.headers ? { ...authInput.headers } : void 0
|
|
9215
|
+
} : void 0;
|
|
9216
|
+
if (resolvedUserId === void 0 && resolvedOrganizationId === void 0 && options?.forceNoCache === void 0 && !options?.headers && !auth) {
|
|
9217
|
+
return void 0;
|
|
9218
|
+
}
|
|
9219
|
+
return {
|
|
9220
|
+
userId: resolvedUserId,
|
|
9221
|
+
organizationId: resolvedOrganizationId,
|
|
9222
|
+
forceNoCache: options?.forceNoCache,
|
|
9223
|
+
headers: options?.headers ? { ...options.headers } : void 0,
|
|
9224
|
+
auth
|
|
9225
|
+
};
|
|
9226
|
+
}
|
|
8734
9227
|
var RegistryNavigator = class {
|
|
8735
9228
|
constructor(registry) {
|
|
8736
9229
|
this.registry = registry;
|
|
@@ -8782,12 +9275,22 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
8782
9275
|
backend: input.options?.backend,
|
|
8783
9276
|
client: input.options?.client,
|
|
8784
9277
|
headers: input.options?.headers,
|
|
9278
|
+
forceNoCache: input.options?.forceNoCache,
|
|
9279
|
+
userId: input.options?.userId,
|
|
9280
|
+
organizationId: input.options?.organizationId,
|
|
9281
|
+
auth: input.options?.auth,
|
|
9282
|
+
tenantKeyMap,
|
|
9283
|
+
tenantContext,
|
|
8785
9284
|
experimental: input.options?.experimental
|
|
8786
9285
|
};
|
|
8787
9286
|
this.baseClient = createClient(this.url, this.apiKey, {
|
|
8788
9287
|
backend: this.clientOptions.backend,
|
|
8789
9288
|
client: this.clientOptions.client,
|
|
8790
9289
|
headers: this.tenantHeaderMapper.apply(this.clientOptions.headers, tenantContext),
|
|
9290
|
+
forceNoCache: this.clientOptions.forceNoCache,
|
|
9291
|
+
userId: this.clientOptions.userId,
|
|
9292
|
+
organizationId: this.clientOptions.organizationId,
|
|
9293
|
+
auth: this.clientOptions.auth,
|
|
8791
9294
|
experimental: this.clientOptions.experimental
|
|
8792
9295
|
});
|
|
8793
9296
|
this.db = this.baseClient.db;
|
|
@@ -8805,6 +9308,40 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
8805
9308
|
verifyConnection(options) {
|
|
8806
9309
|
return this.baseClient.verifyConnection(options);
|
|
8807
9310
|
}
|
|
9311
|
+
withContext(context) {
|
|
9312
|
+
const headers = {
|
|
9313
|
+
...this.clientOptions.headers ?? {},
|
|
9314
|
+
...context?.headers ?? {}
|
|
9315
|
+
};
|
|
9316
|
+
const auth = this.clientOptions.auth || context?.auth ? {
|
|
9317
|
+
...this.clientOptions.auth ?? {},
|
|
9318
|
+
...context?.auth ?? {},
|
|
9319
|
+
headers: this.clientOptions.auth?.headers || context?.auth?.headers ? {
|
|
9320
|
+
...this.clientOptions.auth?.headers ?? {},
|
|
9321
|
+
...context?.auth?.headers ?? {}
|
|
9322
|
+
} : void 0
|
|
9323
|
+
} : void 0;
|
|
9324
|
+
return new _TypedAthenaClientImpl({
|
|
9325
|
+
registry: this.registry,
|
|
9326
|
+
url: this.url,
|
|
9327
|
+
apiKey: this.apiKey,
|
|
9328
|
+
options: {
|
|
9329
|
+
...this.clientOptions,
|
|
9330
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
9331
|
+
auth,
|
|
9332
|
+
tenantKeyMap: this.tenantKeyMap,
|
|
9333
|
+
tenantContext: {
|
|
9334
|
+
...this.tenantContext
|
|
9335
|
+
},
|
|
9336
|
+
...context?.userId !== void 0 ? { userId: context.userId } : {},
|
|
9337
|
+
...context?.organizationId !== void 0 ? { organizationId: context.organizationId } : {},
|
|
9338
|
+
...context?.forceNoCache !== void 0 ? { forceNoCache: context.forceNoCache } : {}
|
|
9339
|
+
}
|
|
9340
|
+
});
|
|
9341
|
+
}
|
|
9342
|
+
withSession(session, options) {
|
|
9343
|
+
return this.withContext(resolveSessionContextOptions2(session, options));
|
|
9344
|
+
}
|
|
8808
9345
|
withTenantContext(context) {
|
|
8809
9346
|
return new _TypedAthenaClientImpl({
|
|
8810
9347
|
registry: this.registry,
|
|
@@ -8865,6 +9402,77 @@ function resolveProviderSchemas(providerConfig) {
|
|
|
8865
9402
|
return [...DEFAULT_POSTGRES_SCHEMAS];
|
|
8866
9403
|
}
|
|
8867
9404
|
|
|
9405
|
+
// src/generator/table-selection.ts
|
|
9406
|
+
function normalizeTableSelector(value) {
|
|
9407
|
+
const trimmed = value.trim();
|
|
9408
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
9409
|
+
}
|
|
9410
|
+
function normalizeTableSelection(value) {
|
|
9411
|
+
if (typeof value === "string") {
|
|
9412
|
+
return Array.from(
|
|
9413
|
+
new Set(
|
|
9414
|
+
value.split(",").map(normalizeTableSelector).filter((entry) => Boolean(entry))
|
|
9415
|
+
)
|
|
9416
|
+
);
|
|
9417
|
+
}
|
|
9418
|
+
if (Array.isArray(value)) {
|
|
9419
|
+
return Array.from(
|
|
9420
|
+
new Set(
|
|
9421
|
+
value.map((entry) => typeof entry === "string" ? normalizeTableSelector(entry) : void 0).filter((entry) => Boolean(entry))
|
|
9422
|
+
)
|
|
9423
|
+
);
|
|
9424
|
+
}
|
|
9425
|
+
return [];
|
|
9426
|
+
}
|
|
9427
|
+
function matchesTableSelector(schemaName, tableName, selector) {
|
|
9428
|
+
const separatorIndex = selector.indexOf(".");
|
|
9429
|
+
if (separatorIndex < 0) {
|
|
9430
|
+
return tableName === selector;
|
|
9431
|
+
}
|
|
9432
|
+
const selectorSchema = selector.slice(0, separatorIndex).trim();
|
|
9433
|
+
const selectorTable = selector.slice(separatorIndex + 1).trim();
|
|
9434
|
+
return selectorSchema === schemaName && selectorTable === tableName;
|
|
9435
|
+
}
|
|
9436
|
+
function shouldKeepTable(schemaName, tableName, filter) {
|
|
9437
|
+
const included = filter.includeTables.length === 0 || filter.includeTables.some((selector) => matchesTableSelector(schemaName, tableName, selector));
|
|
9438
|
+
if (!included) {
|
|
9439
|
+
return false;
|
|
9440
|
+
}
|
|
9441
|
+
return !filter.excludeTables.some((selector) => matchesTableSelector(schemaName, tableName, selector));
|
|
9442
|
+
}
|
|
9443
|
+
function hasTableFilters(filter) {
|
|
9444
|
+
return filter.includeTables.length > 0 || filter.excludeTables.length > 0;
|
|
9445
|
+
}
|
|
9446
|
+
function filterIntrospectionSnapshot(snapshot, filter) {
|
|
9447
|
+
if (!hasTableFilters(filter)) {
|
|
9448
|
+
return snapshot;
|
|
9449
|
+
}
|
|
9450
|
+
const schemas = {};
|
|
9451
|
+
for (const [schemaName, schema] of Object.entries(snapshot.schemas)) {
|
|
9452
|
+
const tables = Object.fromEntries(
|
|
9453
|
+
Object.entries(schema.tables).filter(([tableName]) => shouldKeepTable(schemaName, tableName, filter))
|
|
9454
|
+
);
|
|
9455
|
+
if (Object.keys(tables).length === 0) {
|
|
9456
|
+
continue;
|
|
9457
|
+
}
|
|
9458
|
+
schemas[schemaName] = {
|
|
9459
|
+
...schema,
|
|
9460
|
+
tables
|
|
9461
|
+
};
|
|
9462
|
+
}
|
|
9463
|
+
if (Object.keys(schemas).length === 0) {
|
|
9464
|
+
const includeLabel = filter.includeTables.length > 0 ? ` includeTables=${filter.includeTables.join(", ")}` : "";
|
|
9465
|
+
const excludeLabel = filter.excludeTables.length > 0 ? ` excludeTables=${filter.excludeTables.join(", ")}` : "";
|
|
9466
|
+
throw new Error(
|
|
9467
|
+
`Generator table filters matched no tables after schema selection.${includeLabel}${excludeLabel}`
|
|
9468
|
+
);
|
|
9469
|
+
}
|
|
9470
|
+
return {
|
|
9471
|
+
...snapshot,
|
|
9472
|
+
schemas
|
|
9473
|
+
};
|
|
9474
|
+
}
|
|
9475
|
+
|
|
8868
9476
|
// src/generator/env.ts
|
|
8869
9477
|
function readEnvStringValue(key) {
|
|
8870
9478
|
if (typeof process === "undefined" || !process.env) {
|
|
@@ -9523,6 +10131,6 @@ async function runSchemaGenerator(options = {}) {
|
|
|
9523
10131
|
return throwBrowserUnsupported("runSchemaGenerator");
|
|
9524
10132
|
}
|
|
9525
10133
|
|
|
9526
|
-
export { ATHENA_AUTH_BASE_ERROR_CODES, 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, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, identifier, isAthenaGatewayError, isOk, json, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, number, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
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 };
|
|
9527
10135
|
//# sourceMappingURL=browser.js.map
|
|
9528
10136
|
//# sourceMappingURL=browser.js.map
|