@xylex-group/athena 2.11.0 → 2.12.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.
Files changed (62) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +296 -240
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.cts +9 -8
  5. package/dist/browser.d.ts +9 -8
  6. package/dist/browser.js +296 -240
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +269 -240
  9. package/dist/cli/index.cjs.map +1 -1
  10. package/dist/cli/index.d.cts +4 -3
  11. package/dist/cli/index.d.ts +4 -3
  12. package/dist/cli/index.js +269 -240
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/{client-DD_UeF3Q.d.ts → client-C3x75Zgn.d.cts} +20 -9
  15. package/dist/{client-WqBuu60O.d.cts → client-QUbAs7E8.d.ts} +20 -9
  16. package/dist/index.cjs +296 -240
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +9 -8
  19. package/dist/index.d.ts +9 -8
  20. package/dist/index.js +296 -240
  21. package/dist/index.js.map +1 -1
  22. package/dist/{model-form-DACdBLYG.d.cts → model-form-CD1uhWSh.d.cts} +2 -1
  23. package/dist/{model-form-ByvyyvxB.d.ts → model-form-Dm69I-oO.d.ts} +2 -1
  24. package/dist/{module-DRkIHtY-.d.ts → module-CW3tWJ10.d.ts} +5 -4
  25. package/dist/{module-BFMyVmwX.d.cts → module-Cxcurfes.d.cts} +5 -4
  26. package/dist/next/client.cjs +296 -240
  27. package/dist/next/client.cjs.map +1 -1
  28. package/dist/next/client.d.cts +4 -3
  29. package/dist/next/client.d.ts +4 -3
  30. package/dist/next/client.js +296 -240
  31. package/dist/next/client.js.map +1 -1
  32. package/dist/next/server.cjs +296 -240
  33. package/dist/next/server.cjs.map +1 -1
  34. package/dist/next/server.d.cts +4 -3
  35. package/dist/next/server.d.ts +4 -3
  36. package/dist/next/server.js +296 -240
  37. package/dist/next/server.js.map +1 -1
  38. package/dist/{pipeline-CmUZsXsi.d.cts → pipeline-B14jVK7J.d.cts} +1 -1
  39. package/dist/{pipeline-DZMsPxUg.d.ts → pipeline-BAwb6Vzm.d.ts} +1 -1
  40. package/dist/react.cjs +234 -98
  41. package/dist/react.cjs.map +1 -1
  42. package/dist/react.d.cts +5 -4
  43. package/dist/react.d.ts +5 -4
  44. package/dist/react.js +234 -98
  45. package/dist/react.js.map +1 -1
  46. package/dist/{shared-GPAprhBb.d.ts → shared-0Kdc74lu.d.ts} +2 -2
  47. package/dist/{shared-B1ueL-Ox.d.cts → shared-C0wVICRv.d.cts} +2 -2
  48. package/dist/{types-C-YvfgYh.d.cts → types-BcVmPBP-.d.ts} +2 -1
  49. package/dist/types-Cq4-NoB4.d.ts +204 -0
  50. package/dist/types-CwJCPpLD.d.cts +236 -0
  51. package/dist/types-CwJCPpLD.d.ts +236 -0
  52. package/dist/{types-CRjDwmtJ.d.ts → types-DMOoYnPS.d.cts} +2 -1
  53. package/dist/types-Dr849HD6.d.cts +204 -0
  54. package/dist/utils.cjs +276 -0
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +58 -1
  57. package/dist/utils.d.ts +58 -1
  58. package/dist/utils.js +269 -1
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +1 -1
  61. package/dist/types-BeZIHduP.d.cts +0 -428
  62. package/dist/types-BeZIHduP.d.ts +0 -428
@@ -1,6 +1,7 @@
1
- import { r as runSchemaGenerator } from '../pipeline-CmUZsXsi.cjs';
2
- import '../types-C-YvfgYh.cjs';
3
- import '../types-BeZIHduP.cjs';
1
+ import { r as runSchemaGenerator } from '../pipeline-B14jVK7J.cjs';
2
+ import '../types-DMOoYnPS.cjs';
3
+ import '../types-CwJCPpLD.cjs';
4
+ import '../types-Dr849HD6.cjs';
4
5
 
5
6
  interface GenerateCommand {
6
7
  command: 'generate';
@@ -1,6 +1,7 @@
1
- import { r as runSchemaGenerator } from '../pipeline-DZMsPxUg.js';
2
- import '../types-CRjDwmtJ.js';
3
- import '../types-BeZIHduP.js';
1
+ import { r as runSchemaGenerator } from '../pipeline-BAwb6Vzm.js';
2
+ import '../types-BcVmPBP-.js';
3
+ import '../types-CwJCPpLD.js';
4
+ import '../types-Cq4-NoB4.js';
4
5
 
5
6
  interface GenerateCommand {
6
7
  command: 'generate';
package/dist/cli/index.js CHANGED
@@ -2000,42 +2000,31 @@ var getSessionCookie = (request2, config) => {
2000
2000
  return null;
2001
2001
  };
2002
2002
 
2003
- // package.json
2004
- var package_default = {
2005
- version: "2.11.0"
2006
- };
2007
-
2008
- // src/sdk-version.ts
2009
- var PACKAGE_VERSION = package_default.version;
2010
- function buildSdkHeaderValue(sdkName) {
2011
- return `${sdkName} ${PACKAGE_VERSION}`;
2012
- }
2013
-
2014
- // src/gateway/client.ts
2015
- var DEFAULT_CLIENT = "railway_direct";
2016
- var SDK_NAME = "xylex-group/athena";
2017
- var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
2003
+ // src/utils/athena-request-headers.ts
2018
2004
  var NO_CACHE_HEADER_VALUE = "no-cache";
2019
- function parseResponseBody(rawText, contentType) {
2020
- if (!rawText) {
2021
- return { parsed: null, parseFailed: false };
2022
- }
2023
- const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
2024
- const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
2025
- if (!looksJson) {
2026
- return { parsed: rawText, parseFailed: false };
2027
- }
2028
- try {
2029
- return { parsed: JSON.parse(rawText), parseFailed: false };
2030
- } catch {
2031
- return { parsed: rawText, parseFailed: true };
2032
- }
2033
- }
2005
+ var API_KEY_HEADER_CANDIDATES = ["x-api-key", "apikey"];
2006
+ var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
2007
+ var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
2008
+ var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
2009
+ var CLIENT_HEADER_CANDIDATES = ["X-Athena-Client", "x-athena-client"];
2010
+ var PG_URI_HEADER_CANDIDATES = ["x-pg-uri"];
2011
+ var JDBC_URI_HEADER_CANDIDATES = ["x-athena-jdbc-url", "x-jdbc-url"];
2012
+ var PROFILE_RULES = {
2013
+ gateway: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true, stripNullsDefault: true },
2014
+ chat: { apiKeys: true, routing: true, authMirror: true, authBearer: true, accept: true },
2015
+ storage: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true },
2016
+ auth: { apiKeys: true, routing: false, authMirror: false, authBearer: true, contentType: true },
2017
+ minimal: { apiKeys: false, routing: false, authMirror: false, authBearer: false }
2018
+ };
2034
2019
  function normalizeHeaderValue(value) {
2035
2020
  return value ? value : void 0;
2036
2021
  }
2037
- function isCacheControlHeaderName(name) {
2038
- return name.toLowerCase() === "cache-control";
2022
+ function mergeExtraHeaders(configHeaders, callHeaders) {
2023
+ return { ...configHeaders ?? {}, ...callHeaders ?? {} };
2024
+ }
2025
+ function hasHeaderIgnoreCase(headers, targetKey) {
2026
+ const normalizedTargetKey = targetKey.toLowerCase();
2027
+ return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
2039
2028
  }
2040
2029
  function resolveHeaderValue(headers, candidates) {
2041
2030
  for (const candidate of candidates) {
@@ -2052,13 +2041,20 @@ function resolveHeaderValue(headers, candidates) {
2052
2041
  }
2053
2042
  return void 0;
2054
2043
  }
2044
+ function isCacheControlHeaderName(name) {
2045
+ return name.toLowerCase() === "cache-control";
2046
+ }
2047
+ function normalizeBearerToken(value) {
2048
+ const trimmed = value.trim();
2049
+ const match = trimmed.match(/^Bearer\s+(.+)$/i);
2050
+ return match?.[1]?.trim() ?? trimmed;
2051
+ }
2055
2052
  function resolveBearerTokenFromAuthorizationHeader(headers) {
2056
2053
  const authorization = resolveHeaderValue(headers, ["Authorization"]);
2057
2054
  if (!authorization) {
2058
2055
  return void 0;
2059
2056
  }
2060
- const match = authorization.match(/^Bearer\s+(.+)$/i);
2061
- const token = match?.[1]?.trim();
2057
+ const token = normalizeBearerToken(authorization);
2062
2058
  return token ? token : void 0;
2063
2059
  }
2064
2060
  function resolveSessionTokenFromCookieHeader(headers) {
@@ -2068,6 +2064,207 @@ function resolveSessionTokenFromCookieHeader(headers) {
2068
2064
  }
2069
2065
  return getSessionCookie(new Headers({ cookie })) ?? void 0;
2070
2066
  }
2067
+ function resolveBackendType(backend) {
2068
+ if (!backend) {
2069
+ return void 0;
2070
+ }
2071
+ return typeof backend === "string" ? backend : backend.type;
2072
+ }
2073
+ function resolveRequestHeaderOverrides(config, options, defaults) {
2074
+ return {
2075
+ apiKey: options?.apiKey ?? config.apiKey,
2076
+ athenaKey: options?.athenaKey ?? config.athenaKey,
2077
+ client: options?.client ?? config.client ?? defaults?.client,
2078
+ userId: options?.userId ?? config.userId,
2079
+ organizationId: options?.organizationId ?? config.organizationId,
2080
+ backend: options?.backend ?? config.backend,
2081
+ publishEvent: options?.publishEvent ?? config.publishEvent,
2082
+ stripNulls: options?.stripNulls ?? config.stripNulls ?? defaults?.stripNulls,
2083
+ bearerToken: options?.bearerToken ?? config.bearerToken,
2084
+ cookie: options?.cookie ?? config.cookie,
2085
+ sessionToken: options?.sessionToken ?? config.sessionToken,
2086
+ pgUri: options?.pgUri ?? config.pgUri,
2087
+ jdbcUrl: options?.jdbcUrl ?? config.jdbcUrl,
2088
+ forceNoCache: Boolean(config.forceNoCache || options?.forceNoCache),
2089
+ configHeaders: config.headers,
2090
+ callHeaders: options?.headers
2091
+ };
2092
+ }
2093
+ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, extras) {
2094
+ const rules = PROFILE_RULES[profile];
2095
+ return buildAthenaRequestHeaders({
2096
+ profile,
2097
+ sdkHeaderValue,
2098
+ ...resolveRequestHeaderOverrides(config, options, {
2099
+ client: extras?.client ?? void 0,
2100
+ stripNulls: extras?.stripNulls ?? (rules.stripNullsDefault ? true : void 0)
2101
+ }),
2102
+ contentType: extras?.contentType ?? (rules.contentType ? "application/json" : void 0),
2103
+ accept: extras?.accept ?? (rules.accept ? "application/json" : void 0)
2104
+ });
2105
+ }
2106
+ function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
2107
+ if (apiKey) {
2108
+ if (!hasHeaderIgnoreCase(headers, "apikey")) {
2109
+ headers.apikey = apiKey;
2110
+ }
2111
+ if (!hasHeaderIgnoreCase(headers, "x-api-key")) {
2112
+ headers["x-api-key"] = apiKey;
2113
+ }
2114
+ }
2115
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
2116
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
2117
+ headers["X-Athena-Key"] = resolvedAthenaKey;
2118
+ }
2119
+ }
2120
+ function applyAthenaAuthContextHeaders(headers, input) {
2121
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
2122
+ const rules = PROFILE_RULES[input.profile];
2123
+ const explicitCookie = normalizeHeaderValue(input.cookie);
2124
+ if (explicitCookie) {
2125
+ mergedExtraHeaders.Cookie = explicitCookie;
2126
+ }
2127
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
2128
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
2129
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
2130
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
2131
+ headers.Cookie = explicitCookie;
2132
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
2133
+ headers.Cookie = cookieFromHeaders;
2134
+ }
2135
+ const explicitBearerToken = (() => {
2136
+ const configured = normalizeHeaderValue(input.bearerToken);
2137
+ if (configured) {
2138
+ return normalizeBearerToken(configured);
2139
+ }
2140
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
2141
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
2142
+ })();
2143
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
2144
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
2145
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
2146
+ }
2147
+ if (rules.authMirror) {
2148
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
2149
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
2150
+ }
2151
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
2152
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
2153
+ }
2154
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
2155
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
2156
+ }
2157
+ }
2158
+ function applyAthenaPgUriHeaders(headers, input) {
2159
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
2160
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
2161
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
2162
+ headers["x-pg-uri"] = pgUri;
2163
+ }
2164
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
2165
+ if (jdbcUrl) {
2166
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
2167
+ headers["x-athena-jdbc-url"] = jdbcUrl;
2168
+ }
2169
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
2170
+ headers["x-jdbc-url"] = jdbcUrl;
2171
+ }
2172
+ }
2173
+ }
2174
+ function buildAthenaRequestHeaders(input) {
2175
+ const forceNoCache = Boolean(input.forceNoCache);
2176
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
2177
+ const rules = PROFILE_RULES[input.profile];
2178
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
2179
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
2180
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
2181
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
2182
+ const headers = {
2183
+ "X-Athena-Sdk": input.sdkHeaderValue
2184
+ };
2185
+ if (rules.contentType) {
2186
+ headers["Content-Type"] = input.contentType ?? "application/json";
2187
+ }
2188
+ if (input.accept ?? rules.accept) {
2189
+ headers.Accept = input.accept ?? "application/json";
2190
+ }
2191
+ if (rules.routing) {
2192
+ if (normalizeHeaderValue(input.userId)) {
2193
+ headers["X-User-Id"] = input.userId ?? "";
2194
+ }
2195
+ if (normalizeHeaderValue(input.organizationId)) {
2196
+ headers["X-Organization-Id"] = input.organizationId ?? "";
2197
+ }
2198
+ if (finalClient) {
2199
+ headers["X-Athena-Client"] = finalClient;
2200
+ }
2201
+ const backendType = resolveBackendType(input.backend);
2202
+ if (backendType) {
2203
+ headers["X-Backend-Type"] = backendType;
2204
+ }
2205
+ if (typeof input.stripNulls === "boolean") {
2206
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
2207
+ } else if (rules.stripNullsDefault) {
2208
+ headers["X-Strip-Nulls"] = "true";
2209
+ }
2210
+ if (normalizeHeaderValue(input.publishEvent)) {
2211
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
2212
+ }
2213
+ }
2214
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
2215
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
2216
+ }
2217
+ applyAthenaAuthContextHeaders(headers, input);
2218
+ applyAthenaPgUriHeaders(headers, input);
2219
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
2220
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
2221
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
2222
+ return;
2223
+ }
2224
+ if (forceNoCache && isCacheControlHeaderName(key)) {
2225
+ return;
2226
+ }
2227
+ const normalized = normalizeHeaderValue(value);
2228
+ if (normalized) {
2229
+ headers[key] = normalized;
2230
+ }
2231
+ });
2232
+ if (forceNoCache) {
2233
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
2234
+ }
2235
+ return headers;
2236
+ }
2237
+
2238
+ // package.json
2239
+ var package_default = {
2240
+ version: "2.12.0"
2241
+ };
2242
+
2243
+ // src/sdk-version.ts
2244
+ var PACKAGE_VERSION = package_default.version;
2245
+ function buildSdkHeaderValue(sdkName) {
2246
+ return `${sdkName} ${PACKAGE_VERSION}`;
2247
+ }
2248
+
2249
+ // src/gateway/client.ts
2250
+ var DEFAULT_CLIENT = "railway_direct";
2251
+ var SDK_NAME = "xylex-group/athena";
2252
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
2253
+ function parseResponseBody(rawText, contentType) {
2254
+ if (!rawText) {
2255
+ return { parsed: null, parseFailed: false };
2256
+ }
2257
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
2258
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
2259
+ if (!looksJson) {
2260
+ return { parsed: rawText, parseFailed: false };
2261
+ }
2262
+ try {
2263
+ return { parsed: JSON.parse(rawText), parseFailed: false };
2264
+ } catch {
2265
+ return { parsed: rawText, parseFailed: true };
2266
+ }
2267
+ }
2071
2268
  function isRecord2(value) {
2072
2269
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2073
2270
  }
@@ -2194,71 +2391,10 @@ function buildRpcGetEndpoint(payload) {
2194
2391
  return withQuery;
2195
2392
  }
2196
2393
  function buildHeaders(config, options) {
2197
- const mergedStripNulls = options?.stripNulls ?? true;
2198
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
2199
- const extraHeaders = {
2200
- ...config.headers ?? {},
2201
- ...options?.headers ?? {}
2202
- };
2203
- const headerClient = extraHeaders["x-athena-client"] ?? extraHeaders["X-Athena-Client"];
2204
- const finalClient = options?.client ?? config.client ?? (typeof headerClient === "string" ? headerClient : void 0) ?? DEFAULT_CLIENT;
2205
- const finalApiKey = options?.apiKey ?? config.apiKey;
2206
- const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
2207
- const headers = {
2208
- "Content-Type": "application/json",
2209
- "X-Athena-Sdk": SDK_HEADER_VALUE
2210
- };
2211
- if (options?.userId ?? config.userId) {
2212
- headers["X-User-Id"] = options?.userId ?? config.userId ?? "";
2213
- }
2214
- if (options?.organizationId ?? config.organizationId) {
2215
- headers["X-Organization-Id"] = options?.organizationId ?? config.organizationId ?? "";
2216
- }
2217
- if (finalClient) {
2218
- headers["X-Athena-Client"] = finalClient;
2219
- }
2220
- const finalBackend = options?.backend ?? config.backend;
2221
- if (finalBackend) {
2222
- const type = typeof finalBackend === "string" ? finalBackend : finalBackend.type;
2223
- if (type) headers["X-Backend-Type"] = type;
2224
- }
2225
- if (typeof mergedStripNulls === "boolean") {
2226
- headers["X-Strip-Nulls"] = mergedStripNulls ? "true" : "false";
2227
- }
2228
- if (finalPublishEvent) {
2229
- headers["X-Publish-Event"] = finalPublishEvent;
2230
- }
2231
- if (finalApiKey) {
2232
- headers["apikey"] = finalApiKey;
2233
- headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
2234
- }
2235
- const explicitSessionToken = resolveHeaderValue(extraHeaders, [
2236
- "X-Athena-Auth-Session-Token"
2237
- ]);
2238
- const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(extraHeaders);
2239
- if (derivedSessionToken) {
2240
- headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
2241
- }
2242
- const explicitBearerToken = resolveHeaderValue(extraHeaders, [
2243
- "X-Athena-Auth-Bearer-Token"
2244
- ]);
2245
- const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(extraHeaders);
2246
- if (derivedBearerToken) {
2247
- headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
2248
- }
2249
- const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
2250
- Object.entries(extraHeaders).forEach(([key, value]) => {
2251
- if (athenaClientKeys.includes(key)) return;
2252
- if (forceNoCache && isCacheControlHeaderName(key)) return;
2253
- const normalized = normalizeHeaderValue(value);
2254
- if (normalized) {
2255
- headers[key] = normalized;
2256
- }
2394
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
2395
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
2396
+ stripNulls: options?.stripNulls ?? true
2257
2397
  });
2258
- if (forceNoCache) {
2259
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
2260
- }
2261
- return headers;
2262
2398
  }
2263
2399
  function toInvalidUrlResponse(error, endpoint, method) {
2264
2400
  const message = error instanceof Error ? error.message : String(error);
@@ -2915,19 +3051,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
2915
3051
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
2916
3052
  var SDK_NAME2 = "xylex-group/athena-auth";
2917
3053
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
2918
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
2919
3054
  function normalizeBaseUrl(baseUrl) {
2920
3055
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
2921
3056
  }
2922
3057
  function isRecord4(value) {
2923
3058
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2924
3059
  }
2925
- function normalizeHeaderValue2(value) {
2926
- return value ? value : void 0;
2927
- }
2928
- function isCacheControlHeaderName2(name) {
2929
- return name.toLowerCase() === "cache-control";
2930
- }
2931
3060
  function parseResponseBody2(rawText, contentType) {
2932
3061
  if (!rawText) {
2933
3062
  return { parsed: null, parseFailed: false };
@@ -3127,45 +3256,7 @@ function extractFetchOptions(input) {
3127
3256
  };
3128
3257
  }
3129
3258
  function buildHeaders2(config, options) {
3130
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
3131
- const headers = {
3132
- "Content-Type": "application/json",
3133
- "X-Athena-Sdk": SDK_HEADER_VALUE2
3134
- };
3135
- const apiKey = options?.apiKey ?? config.apiKey;
3136
- if (apiKey) {
3137
- headers.apikey = apiKey;
3138
- headers["x-api-key"] = apiKey;
3139
- }
3140
- const bearerToken = options?.bearerToken ?? config.bearerToken;
3141
- if (bearerToken) {
3142
- headers.Authorization = `Bearer ${bearerToken}`;
3143
- }
3144
- const cookie = options?.cookie ?? config.cookie;
3145
- if (cookie) {
3146
- headers.Cookie = cookie;
3147
- }
3148
- const sessionToken = options?.sessionToken ?? config.sessionToken;
3149
- if (sessionToken) {
3150
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
3151
- }
3152
- const mergedExtraHeaders = {
3153
- ...config.headers ?? {},
3154
- ...options?.headers ?? {}
3155
- };
3156
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
3157
- if (forceNoCache && isCacheControlHeaderName2(key)) {
3158
- return;
3159
- }
3160
- const normalized = normalizeHeaderValue2(value);
3161
- if (normalized) {
3162
- headers[key] = normalized;
3163
- }
3164
- });
3165
- if (forceNoCache) {
3166
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
3167
- }
3168
- return headers;
3259
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
3169
3260
  }
3170
3261
  function appendQueryParam(searchParams, key, value) {
3171
3262
  if (value === void 0 || value === null) return;
@@ -6291,7 +6382,6 @@ function createStorageModule(gateway, runtimeOptions) {
6291
6382
  // src/chat/module.ts
6292
6383
  var SDK_NAME3 = "xylex-group/athena-chat";
6293
6384
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
6294
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
6295
6385
  var AthenaChatError = class extends Error {
6296
6386
  status;
6297
6387
  endpoint;
@@ -6337,9 +6427,6 @@ function normalizeWsUrl(value, label) {
6337
6427
  function isRecord7(value) {
6338
6428
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6339
6429
  }
6340
- function normalizeHeaderValue3(value) {
6341
- return value ? value : void 0;
6342
- }
6343
6430
  function parseResponseBody4(rawText, contentType) {
6344
6431
  if (!rawText) {
6345
6432
  return { parsed: null, parseFailed: false };
@@ -6411,39 +6498,7 @@ function createSocket(factory, url, protocols) {
6411
6498
  }
6412
6499
  }
6413
6500
  function buildHeaders3(config, options) {
6414
- const headers = {
6415
- Accept: "application/json",
6416
- apikey: config.apiKey,
6417
- "x-api-key": config.apiKey,
6418
- "X-Athena-Sdk": SDK_HEADER_VALUE3
6419
- };
6420
- if (config.client || options?.client) {
6421
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
6422
- }
6423
- const bearerToken = options?.bearerToken ?? config.bearerToken;
6424
- if (typeof bearerToken === "string" && bearerToken.trim()) {
6425
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
6426
- }
6427
- const cookie = options?.cookie ?? config.cookie;
6428
- if (typeof cookie === "string" && cookie.trim()) {
6429
- headers.Cookie = cookie;
6430
- }
6431
- const sessionToken = options?.sessionToken ?? config.sessionToken;
6432
- if (typeof sessionToken === "string" && sessionToken.trim()) {
6433
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
6434
- }
6435
- if (config.forceNoCache || options?.forceNoCache) {
6436
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
6437
- }
6438
- for (const source of [config.headers, options?.headers]) {
6439
- for (const [key, value] of Object.entries(source ?? {})) {
6440
- const normalized = normalizeHeaderValue3(value);
6441
- if (normalized) {
6442
- headers[key] = normalized;
6443
- }
6444
- }
6445
- }
6446
- return headers;
6501
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
6447
6502
  }
6448
6503
  function withJsonBody(init, body) {
6449
6504
  return {
@@ -9437,10 +9492,6 @@ function resolveRequiredClientApiKey(value) {
9437
9492
  }
9438
9493
  return normalizedValue;
9439
9494
  }
9440
- function hasHeaderIgnoreCase(headers, targetKey) {
9441
- const normalizedTargetKey = targetKey.toLowerCase();
9442
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9443
- }
9444
9495
  function mergeClientHeaders(current, next) {
9445
9496
  if (!current && !next) {
9446
9497
  return void 0;
@@ -9571,6 +9622,9 @@ function resolveCreateClientConfig(config) {
9571
9622
  userId: config.userId,
9572
9623
  organizationId: config.organizationId,
9573
9624
  forceNoCache: config.forceNoCache,
9625
+ pgUri: config.pgUri,
9626
+ jdbcUrl: config.jdbcUrl,
9627
+ athenaKey: config.athenaKey,
9574
9628
  backend: toBackendConfig(config.backend),
9575
9629
  headers: config.headers,
9576
9630
  auth: config.auth,
@@ -9587,18 +9641,6 @@ function createClientFromInput(sourceConfig) {
9587
9641
  }
9588
9642
  function createClientFromConfig(config, sourceConfig) {
9589
9643
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
9590
- const gatewayHeaders = {
9591
- ...config.headers ?? {}
9592
- };
9593
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
9594
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9595
- }
9596
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
9597
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
9598
- }
9599
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
9600
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9601
- }
9602
9644
  const gateway = createAthenaGatewayClient({
9603
9645
  baseUrl: config.baseUrl,
9604
9646
  apiKey: config.apiKey,
@@ -9606,8 +9648,14 @@ function createClientFromConfig(config, sourceConfig) {
9606
9648
  userId: config.userId,
9607
9649
  organizationId: config.organizationId,
9608
9650
  forceNoCache: config.forceNoCache,
9651
+ pgUri: config.pgUri,
9652
+ jdbcUrl: config.jdbcUrl,
9653
+ athenaKey: config.athenaKey,
9609
9654
  backend: config.backend,
9610
- headers: gatewayHeaders
9655
+ bearerToken: normalizedAuthConfig?.bearerToken,
9656
+ cookie: normalizedAuthConfig?.cookie,
9657
+ sessionToken: normalizedAuthConfig?.sessionToken,
9658
+ headers: config.headers
9611
9659
  });
9612
9660
  const formatGatewayResult = createResultFormatter(config.experimental);
9613
9661
  const queryTracer = createQueryTracer(config.experimental);
@@ -9665,6 +9713,7 @@ function createClientFromConfig(config, sourceConfig) {
9665
9713
  const chat = createChatModule({
9666
9714
  baseUrl: config.chatUrl,
9667
9715
  apiKey: config.apiKey,
9716
+ athenaKey: config.athenaKey,
9668
9717
  client: config.client,
9669
9718
  headers: config.headers,
9670
9719
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9701,48 +9750,28 @@ function createClientFromConfig(config, sourceConfig) {
9701
9750
  return path.startsWith("/") ? path : `/${path}`;
9702
9751
  })();
9703
9752
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
9704
- const headers = {
9705
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
9706
- ...config.headers ?? {},
9707
- ...options.headers ?? {}
9708
- };
9709
- if (service !== "auth") {
9710
- headers.apikey = headers.apikey ?? config.apiKey;
9711
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
9712
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
9713
- headers["X-Athena-Client"] = config.client;
9714
- }
9715
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
9716
- headers["X-User-Id"] = config.userId;
9717
- }
9718
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
9719
- headers["X-Organization-Id"] = config.organizationId;
9720
- }
9721
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9722
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9723
- }
9724
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
9725
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9726
- }
9727
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9728
- headers.Cookie = normalizedAuthConfig.cookie;
9729
- }
9730
- } else {
9731
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
9732
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
9733
- headers.apikey = headers.apikey ?? authApiKey;
9734
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
9735
- }
9736
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
9737
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
9738
- }
9739
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9740
- headers.Cookie = normalizedAuthConfig.cookie;
9741
- }
9742
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9743
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9744
- }
9745
- }
9753
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
9754
+ const headers = buildAthenaRequestHeaders({
9755
+ profile: requestProfile,
9756
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
9757
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
9758
+ athenaKey: options.athenaKey ?? config.athenaKey,
9759
+ client: config.client,
9760
+ userId: config.userId,
9761
+ organizationId: config.organizationId,
9762
+ backend: config.backend,
9763
+ pgUri: config.pgUri,
9764
+ jdbcUrl: config.jdbcUrl,
9765
+ bearerToken: normalizedAuthConfig?.bearerToken,
9766
+ cookie: normalizedAuthConfig?.cookie,
9767
+ sessionToken: normalizedAuthConfig?.sessionToken,
9768
+ forceNoCache: config.forceNoCache,
9769
+ configHeaders: config.headers,
9770
+ callHeaders: options.headers,
9771
+ accept: service === "chat" ? "application/json" : void 0,
9772
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
9773
+ stripNulls: service === "db" ? true : void 0
9774
+ });
9746
9775
  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";
9747
9776
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9748
9777
  headers["Content-Type"] = "application/json";