@xylex-group/athena 2.11.0 → 2.12.1

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 +299 -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 +299 -240
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +272 -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 +272 -240
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/{client-DD_UeF3Q.d.ts → client-CMtx5P4D.d.cts} +20 -9
  15. package/dist/{client-WqBuu60O.d.cts → client-Dre8H24u.d.ts} +20 -9
  16. package/dist/index.cjs +299 -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 +299 -240
  21. package/dist/index.js.map +1 -1
  22. package/dist/{model-form-ByvyyvxB.d.ts → model-form-CU0mWrF9.d.ts} +2 -1
  23. package/dist/{model-form-DACdBLYG.d.cts → model-form-DfTi8-D1.d.cts} +2 -1
  24. package/dist/{module-DRkIHtY-.d.ts → module-DBGmbIuh.d.ts} +5 -4
  25. package/dist/{module-BFMyVmwX.d.cts → module-GoijrBXV.d.cts} +5 -4
  26. package/dist/next/client.cjs +299 -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 +299 -240
  31. package/dist/next/client.js.map +1 -1
  32. package/dist/next/server.cjs +299 -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 +299 -240
  37. package/dist/next/server.js.map +1 -1
  38. package/dist/{pipeline-DZMsPxUg.d.ts → pipeline-DrjU2vNA.d.ts} +1 -1
  39. package/dist/{pipeline-CmUZsXsi.d.cts → pipeline-c7Gdm0qv.d.cts} +1 -1
  40. package/dist/react.cjs +237 -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 +237 -98
  45. package/dist/react.js.map +1 -1
  46. package/dist/{shared-B1ueL-Ox.d.cts → shared-DZSGAmXs.d.cts} +2 -2
  47. package/dist/{shared-GPAprhBb.d.ts → shared-MMnVBBfy.d.ts} +2 -2
  48. package/dist/{types-CRjDwmtJ.d.ts → types-BLizCLd1.d.cts} +2 -1
  49. package/dist/types-BRUHGXo2.d.cts +236 -0
  50. package/dist/types-BRUHGXo2.d.ts +236 -0
  51. package/dist/types-Bez4HSbI.d.cts +204 -0
  52. package/dist/{types-C-YvfgYh.d.cts → types-DRRb0Fd0.d.ts} +2 -1
  53. package/dist/types-kPaHUqUa.d.ts +204 -0
  54. package/dist/utils.cjs +279 -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 +272 -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
@@ -158,42 +158,31 @@ var getSessionCookie = (request2, config) => {
158
158
  return null;
159
159
  };
160
160
 
161
- // package.json
162
- var package_default = {
163
- version: "2.11.0"
164
- };
165
-
166
- // src/sdk-version.ts
167
- var PACKAGE_VERSION = package_default.version;
168
- function buildSdkHeaderValue(sdkName) {
169
- return `${sdkName} ${PACKAGE_VERSION}`;
170
- }
171
-
172
- // src/gateway/client.ts
173
- var DEFAULT_CLIENT = "railway_direct";
174
- var SDK_NAME = "xylex-group/athena";
175
- var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
161
+ // src/utils/athena-request-headers.ts
176
162
  var NO_CACHE_HEADER_VALUE = "no-cache";
177
- function parseResponseBody(rawText, contentType) {
178
- if (!rawText) {
179
- return { parsed: null, parseFailed: false };
180
- }
181
- const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
182
- const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
183
- if (!looksJson) {
184
- return { parsed: rawText, parseFailed: false };
185
- }
186
- try {
187
- return { parsed: JSON.parse(rawText), parseFailed: false };
188
- } catch {
189
- return { parsed: rawText, parseFailed: true };
190
- }
191
- }
163
+ var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
164
+ var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
165
+ var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
166
+ var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
167
+ var CLIENT_HEADER_CANDIDATES = ["X-Athena-Client", "x-athena-client"];
168
+ var PG_URI_HEADER_CANDIDATES = ["x-pg-uri"];
169
+ var JDBC_URI_HEADER_CANDIDATES = ["x-athena-jdbc-url", "x-jdbc-url"];
170
+ var PROFILE_RULES = {
171
+ gateway: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true, stripNullsDefault: true },
172
+ chat: { apiKeys: true, routing: true, authMirror: true, authBearer: true, accept: true },
173
+ storage: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true },
174
+ auth: { apiKeys: true, routing: false, authMirror: false, authBearer: true, contentType: true },
175
+ minimal: { apiKeys: false, routing: false, authMirror: false, authBearer: false }
176
+ };
192
177
  function normalizeHeaderValue(value) {
193
178
  return value ? value : void 0;
194
179
  }
195
- function isCacheControlHeaderName(name) {
196
- return name.toLowerCase() === "cache-control";
180
+ function mergeExtraHeaders(configHeaders, callHeaders) {
181
+ return { ...configHeaders ?? {}, ...callHeaders ?? {} };
182
+ }
183
+ function hasHeaderIgnoreCase(headers, targetKey) {
184
+ const normalizedTargetKey = targetKey.toLowerCase();
185
+ return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
197
186
  }
198
187
  function resolveHeaderValue(headers, candidates) {
199
188
  for (const candidate of candidates) {
@@ -210,13 +199,20 @@ function resolveHeaderValue(headers, candidates) {
210
199
  }
211
200
  return void 0;
212
201
  }
202
+ function isCacheControlHeaderName(name) {
203
+ return name.toLowerCase() === "cache-control";
204
+ }
205
+ function normalizeBearerToken(value) {
206
+ const trimmed = value.trim();
207
+ const match = trimmed.match(/^Bearer\s+(.+)$/i);
208
+ return match?.[1]?.trim() ?? trimmed;
209
+ }
213
210
  function resolveBearerTokenFromAuthorizationHeader(headers) {
214
211
  const authorization = resolveHeaderValue(headers, ["Authorization"]);
215
212
  if (!authorization) {
216
213
  return void 0;
217
214
  }
218
- const match = authorization.match(/^Bearer\s+(.+)$/i);
219
- const token = match?.[1]?.trim();
215
+ const token = normalizeBearerToken(authorization);
220
216
  return token ? token : void 0;
221
217
  }
222
218
  function resolveSessionTokenFromCookieHeader(headers) {
@@ -226,6 +222,210 @@ function resolveSessionTokenFromCookieHeader(headers) {
226
222
  }
227
223
  return getSessionCookie(new Headers({ cookie })) ?? void 0;
228
224
  }
225
+ function resolveBackendType(backend) {
226
+ if (!backend) {
227
+ return void 0;
228
+ }
229
+ return typeof backend === "string" ? backend : backend.type;
230
+ }
231
+ function resolveRequestHeaderOverrides(config, options, defaults) {
232
+ return {
233
+ apiKey: options?.apiKey ?? config.apiKey,
234
+ athenaKey: options?.athenaKey ?? config.athenaKey,
235
+ client: options?.client ?? config.client ?? defaults?.client,
236
+ userId: options?.userId ?? config.userId,
237
+ organizationId: options?.organizationId ?? config.organizationId,
238
+ backend: options?.backend ?? config.backend,
239
+ publishEvent: options?.publishEvent ?? config.publishEvent,
240
+ stripNulls: options?.stripNulls ?? config.stripNulls ?? defaults?.stripNulls,
241
+ bearerToken: options?.bearerToken ?? config.bearerToken,
242
+ cookie: options?.cookie ?? config.cookie,
243
+ sessionToken: options?.sessionToken ?? config.sessionToken,
244
+ pgUri: options?.pgUri ?? config.pgUri,
245
+ jdbcUrl: options?.jdbcUrl ?? config.jdbcUrl,
246
+ forceNoCache: Boolean(config.forceNoCache || options?.forceNoCache),
247
+ configHeaders: config.headers,
248
+ callHeaders: options?.headers
249
+ };
250
+ }
251
+ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, extras) {
252
+ const rules = PROFILE_RULES[profile];
253
+ return buildAthenaRequestHeaders({
254
+ profile,
255
+ sdkHeaderValue,
256
+ ...resolveRequestHeaderOverrides(config, options, {
257
+ client: extras?.client ?? void 0,
258
+ stripNulls: extras?.stripNulls ?? (rules.stripNullsDefault ? true : void 0)
259
+ }),
260
+ contentType: extras?.contentType ?? (rules.contentType ? "application/json" : void 0),
261
+ accept: extras?.accept ?? (rules.accept ? "application/json" : void 0)
262
+ });
263
+ }
264
+ function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
265
+ if (apiKey) {
266
+ if (!hasHeaderIgnoreCase(headers, "apikey")) {
267
+ headers.apikey = apiKey;
268
+ }
269
+ if (!Object.hasOwn(headers, "x-api-key")) {
270
+ headers["x-api-key"] = apiKey;
271
+ }
272
+ if (!Object.hasOwn(headers, "X-Api-Key")) {
273
+ headers["X-Api-Key"] = apiKey;
274
+ }
275
+ }
276
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
277
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
278
+ headers["X-Athena-Key"] = resolvedAthenaKey;
279
+ }
280
+ }
281
+ function applyAthenaAuthContextHeaders(headers, input) {
282
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
283
+ const rules = PROFILE_RULES[input.profile];
284
+ const explicitCookie = normalizeHeaderValue(input.cookie);
285
+ if (explicitCookie) {
286
+ mergedExtraHeaders.Cookie = explicitCookie;
287
+ }
288
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
289
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
290
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
291
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
292
+ headers.Cookie = explicitCookie;
293
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
294
+ headers.Cookie = cookieFromHeaders;
295
+ }
296
+ const explicitBearerToken = (() => {
297
+ const configured = normalizeHeaderValue(input.bearerToken);
298
+ if (configured) {
299
+ return normalizeBearerToken(configured);
300
+ }
301
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
302
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
303
+ })();
304
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
305
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
306
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
307
+ }
308
+ if (rules.authMirror) {
309
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
310
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
311
+ }
312
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
313
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
314
+ }
315
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
316
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
317
+ }
318
+ }
319
+ function applyAthenaPgUriHeaders(headers, input) {
320
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
321
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
322
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
323
+ headers["x-pg-uri"] = pgUri;
324
+ }
325
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
326
+ if (jdbcUrl) {
327
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
328
+ headers["x-athena-jdbc-url"] = jdbcUrl;
329
+ }
330
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
331
+ headers["x-jdbc-url"] = jdbcUrl;
332
+ }
333
+ }
334
+ }
335
+ function buildAthenaRequestHeaders(input) {
336
+ const forceNoCache = Boolean(input.forceNoCache);
337
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
338
+ const rules = PROFILE_RULES[input.profile];
339
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
340
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
341
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
342
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
343
+ const headers = {
344
+ "X-Athena-Sdk": input.sdkHeaderValue
345
+ };
346
+ if (rules.contentType) {
347
+ headers["Content-Type"] = input.contentType ?? "application/json";
348
+ }
349
+ if (input.accept ?? rules.accept) {
350
+ headers.Accept = input.accept ?? "application/json";
351
+ }
352
+ if (rules.routing) {
353
+ if (normalizeHeaderValue(input.userId)) {
354
+ headers["X-User-Id"] = input.userId ?? "";
355
+ }
356
+ if (normalizeHeaderValue(input.organizationId)) {
357
+ headers["X-Organization-Id"] = input.organizationId ?? "";
358
+ }
359
+ if (finalClient) {
360
+ headers["X-Athena-Client"] = finalClient;
361
+ }
362
+ const backendType = resolveBackendType(input.backend);
363
+ if (backendType) {
364
+ headers["X-Backend-Type"] = backendType;
365
+ }
366
+ if (typeof input.stripNulls === "boolean") {
367
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
368
+ } else if (rules.stripNullsDefault) {
369
+ headers["X-Strip-Nulls"] = "true";
370
+ }
371
+ if (normalizeHeaderValue(input.publishEvent)) {
372
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
373
+ }
374
+ }
375
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
376
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
377
+ }
378
+ applyAthenaAuthContextHeaders(headers, input);
379
+ applyAthenaPgUriHeaders(headers, input);
380
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
381
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
382
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
383
+ return;
384
+ }
385
+ if (forceNoCache && isCacheControlHeaderName(key)) {
386
+ return;
387
+ }
388
+ const normalized = normalizeHeaderValue(value);
389
+ if (normalized) {
390
+ headers[key] = normalized;
391
+ }
392
+ });
393
+ if (forceNoCache) {
394
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
395
+ }
396
+ return headers;
397
+ }
398
+
399
+ // package.json
400
+ var package_default = {
401
+ version: "2.12.1"
402
+ };
403
+
404
+ // src/sdk-version.ts
405
+ var PACKAGE_VERSION = package_default.version;
406
+ function buildSdkHeaderValue(sdkName) {
407
+ return `${sdkName} ${PACKAGE_VERSION}`;
408
+ }
409
+
410
+ // src/gateway/client.ts
411
+ var DEFAULT_CLIENT = "railway_direct";
412
+ var SDK_NAME = "xylex-group/athena";
413
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
414
+ function parseResponseBody(rawText, contentType) {
415
+ if (!rawText) {
416
+ return { parsed: null, parseFailed: false };
417
+ }
418
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
419
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
420
+ if (!looksJson) {
421
+ return { parsed: rawText, parseFailed: false };
422
+ }
423
+ try {
424
+ return { parsed: JSON.parse(rawText), parseFailed: false };
425
+ } catch {
426
+ return { parsed: rawText, parseFailed: true };
427
+ }
428
+ }
229
429
  function isRecord(value) {
230
430
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
231
431
  }
@@ -352,71 +552,10 @@ function buildRpcGetEndpoint(payload) {
352
552
  return withQuery;
353
553
  }
354
554
  function buildHeaders(config, options) {
355
- const mergedStripNulls = options?.stripNulls ?? true;
356
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
357
- const extraHeaders = {
358
- ...config.headers ?? {},
359
- ...options?.headers ?? {}
360
- };
361
- const headerClient = extraHeaders["x-athena-client"] ?? extraHeaders["X-Athena-Client"];
362
- const finalClient = options?.client ?? config.client ?? (typeof headerClient === "string" ? headerClient : void 0) ?? DEFAULT_CLIENT;
363
- const finalApiKey = options?.apiKey ?? config.apiKey;
364
- const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
365
- const headers = {
366
- "Content-Type": "application/json",
367
- "X-Athena-Sdk": SDK_HEADER_VALUE
368
- };
369
- if (options?.userId ?? config.userId) {
370
- headers["X-User-Id"] = options?.userId ?? config.userId ?? "";
371
- }
372
- if (options?.organizationId ?? config.organizationId) {
373
- headers["X-Organization-Id"] = options?.organizationId ?? config.organizationId ?? "";
374
- }
375
- if (finalClient) {
376
- headers["X-Athena-Client"] = finalClient;
377
- }
378
- const finalBackend = options?.backend ?? config.backend;
379
- if (finalBackend) {
380
- const type = typeof finalBackend === "string" ? finalBackend : finalBackend.type;
381
- if (type) headers["X-Backend-Type"] = type;
382
- }
383
- if (typeof mergedStripNulls === "boolean") {
384
- headers["X-Strip-Nulls"] = mergedStripNulls ? "true" : "false";
385
- }
386
- if (finalPublishEvent) {
387
- headers["X-Publish-Event"] = finalPublishEvent;
388
- }
389
- if (finalApiKey) {
390
- headers["apikey"] = finalApiKey;
391
- headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
392
- }
393
- const explicitSessionToken = resolveHeaderValue(extraHeaders, [
394
- "X-Athena-Auth-Session-Token"
395
- ]);
396
- const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(extraHeaders);
397
- if (derivedSessionToken) {
398
- headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
399
- }
400
- const explicitBearerToken = resolveHeaderValue(extraHeaders, [
401
- "X-Athena-Auth-Bearer-Token"
402
- ]);
403
- const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(extraHeaders);
404
- if (derivedBearerToken) {
405
- headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
406
- }
407
- const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
408
- Object.entries(extraHeaders).forEach(([key, value]) => {
409
- if (athenaClientKeys.includes(key)) return;
410
- if (forceNoCache && isCacheControlHeaderName(key)) return;
411
- const normalized = normalizeHeaderValue(value);
412
- if (normalized) {
413
- headers[key] = normalized;
414
- }
555
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
556
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
557
+ stripNulls: options?.stripNulls ?? true
415
558
  });
416
- if (forceNoCache) {
417
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
418
- }
419
- return headers;
420
559
  }
421
560
  function toInvalidUrlResponse(error, endpoint, method) {
422
561
  const message = error instanceof Error ? error.message : String(error);
@@ -1073,19 +1212,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
1073
1212
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
1074
1213
  var SDK_NAME2 = "xylex-group/athena-auth";
1075
1214
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
1076
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
1077
1215
  function normalizeBaseUrl(baseUrl) {
1078
1216
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
1079
1217
  }
1080
1218
  function isRecord3(value) {
1081
1219
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1082
1220
  }
1083
- function normalizeHeaderValue2(value) {
1084
- return value ? value : void 0;
1085
- }
1086
- function isCacheControlHeaderName2(name) {
1087
- return name.toLowerCase() === "cache-control";
1088
- }
1089
1221
  function parseResponseBody2(rawText, contentType) {
1090
1222
  if (!rawText) {
1091
1223
  return { parsed: null, parseFailed: false };
@@ -1285,45 +1417,7 @@ function extractFetchOptions(input) {
1285
1417
  };
1286
1418
  }
1287
1419
  function buildHeaders2(config, options) {
1288
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1289
- const headers = {
1290
- "Content-Type": "application/json",
1291
- "X-Athena-Sdk": SDK_HEADER_VALUE2
1292
- };
1293
- const apiKey = options?.apiKey ?? config.apiKey;
1294
- if (apiKey) {
1295
- headers.apikey = apiKey;
1296
- headers["x-api-key"] = apiKey;
1297
- }
1298
- const bearerToken = options?.bearerToken ?? config.bearerToken;
1299
- if (bearerToken) {
1300
- headers.Authorization = `Bearer ${bearerToken}`;
1301
- }
1302
- const cookie = options?.cookie ?? config.cookie;
1303
- if (cookie) {
1304
- headers.Cookie = cookie;
1305
- }
1306
- const sessionToken = options?.sessionToken ?? config.sessionToken;
1307
- if (sessionToken) {
1308
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
1309
- }
1310
- const mergedExtraHeaders = {
1311
- ...config.headers ?? {},
1312
- ...options?.headers ?? {}
1313
- };
1314
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1315
- if (forceNoCache && isCacheControlHeaderName2(key)) {
1316
- return;
1317
- }
1318
- const normalized = normalizeHeaderValue2(value);
1319
- if (normalized) {
1320
- headers[key] = normalized;
1321
- }
1322
- });
1323
- if (forceNoCache) {
1324
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
1325
- }
1326
- return headers;
1420
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
1327
1421
  }
1328
1422
  function appendQueryParam(searchParams, key, value) {
1329
1423
  if (value === void 0 || value === null) return;
@@ -4785,7 +4879,6 @@ function createStorageModule(gateway, runtimeOptions) {
4785
4879
  // src/chat/module.ts
4786
4880
  var SDK_NAME3 = "xylex-group/athena-chat";
4787
4881
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
4788
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
4789
4882
  var AthenaChatError = class extends Error {
4790
4883
  status;
4791
4884
  endpoint;
@@ -4831,9 +4924,6 @@ function normalizeWsUrl(value, label) {
4831
4924
  function isRecord7(value) {
4832
4925
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4833
4926
  }
4834
- function normalizeHeaderValue3(value) {
4835
- return value ? value : void 0;
4836
- }
4837
4927
  function parseResponseBody4(rawText, contentType) {
4838
4928
  if (!rawText) {
4839
4929
  return { parsed: null, parseFailed: false };
@@ -4905,39 +4995,7 @@ function createSocket(factory, url, protocols) {
4905
4995
  }
4906
4996
  }
4907
4997
  function buildHeaders3(config, options) {
4908
- const headers = {
4909
- Accept: "application/json",
4910
- apikey: config.apiKey,
4911
- "x-api-key": config.apiKey,
4912
- "X-Athena-Sdk": SDK_HEADER_VALUE3
4913
- };
4914
- if (config.client || options?.client) {
4915
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
4916
- }
4917
- const bearerToken = options?.bearerToken ?? config.bearerToken;
4918
- if (typeof bearerToken === "string" && bearerToken.trim()) {
4919
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
4920
- }
4921
- const cookie = options?.cookie ?? config.cookie;
4922
- if (typeof cookie === "string" && cookie.trim()) {
4923
- headers.Cookie = cookie;
4924
- }
4925
- const sessionToken = options?.sessionToken ?? config.sessionToken;
4926
- if (typeof sessionToken === "string" && sessionToken.trim()) {
4927
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
4928
- }
4929
- if (config.forceNoCache || options?.forceNoCache) {
4930
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
4931
- }
4932
- for (const source of [config.headers, options?.headers]) {
4933
- for (const [key, value] of Object.entries(source ?? {})) {
4934
- const normalized = normalizeHeaderValue3(value);
4935
- if (normalized) {
4936
- headers[key] = normalized;
4937
- }
4938
- }
4939
- }
4940
- return headers;
4998
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
4941
4999
  }
4942
5000
  function withJsonBody(init, body) {
4943
5001
  return {
@@ -5316,6 +5374,9 @@ var AthenaClientBuilderImpl = class {
5316
5374
  defaultOrganizationId;
5317
5375
  forceNoCacheEnabled = false;
5318
5376
  defaultHeaders;
5377
+ pgUriValue;
5378
+ jdbcUrlValue;
5379
+ athenaKeyValue;
5319
5380
  authConfig;
5320
5381
  dbUrlOverride;
5321
5382
  gatewayUrlOverride;
@@ -5342,6 +5403,18 @@ var AthenaClientBuilderImpl = class {
5342
5403
  this.defaultHeaders = headers;
5343
5404
  return this;
5344
5405
  }
5406
+ pgUri(pgUri) {
5407
+ this.pgUriValue = pgUri;
5408
+ return this;
5409
+ }
5410
+ jdbcUrl(jdbcUrl) {
5411
+ this.jdbcUrlValue = jdbcUrl;
5412
+ return this;
5413
+ }
5414
+ athenaKey(athenaKey) {
5415
+ this.athenaKeyValue = athenaKey;
5416
+ return this;
5417
+ }
5345
5418
  auth(config) {
5346
5419
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
5347
5420
  return this;
@@ -5378,6 +5451,15 @@ var AthenaClientBuilderImpl = class {
5378
5451
  if (options.headers !== void 0) {
5379
5452
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
5380
5453
  }
5454
+ if (options.pgUri !== void 0) {
5455
+ this.pgUriValue = options.pgUri;
5456
+ }
5457
+ if (options.jdbcUrl !== void 0) {
5458
+ this.jdbcUrlValue = options.jdbcUrl;
5459
+ }
5460
+ if (options.athenaKey !== void 0) {
5461
+ this.athenaKeyValue = options.athenaKey;
5462
+ }
5381
5463
  if (options.auth !== void 0) {
5382
5464
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
5383
5465
  }
@@ -5429,6 +5511,9 @@ var AthenaClientBuilderImpl = class {
5429
5511
  userId: this.defaultUserId,
5430
5512
  organizationId: this.defaultOrganizationId,
5431
5513
  forceNoCache: this.forceNoCacheEnabled,
5514
+ pgUri: this.pgUriValue,
5515
+ jdbcUrl: this.jdbcUrlValue,
5516
+ athenaKey: this.athenaKeyValue,
5432
5517
  backend: this.backendConfig,
5433
5518
  headers: this.defaultHeaders,
5434
5519
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -8135,10 +8220,6 @@ function resolveRequiredClientApiKey(value) {
8135
8220
  }
8136
8221
  return normalizedValue;
8137
8222
  }
8138
- function hasHeaderIgnoreCase(headers, targetKey) {
8139
- const normalizedTargetKey = targetKey.toLowerCase();
8140
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
8141
- }
8142
8223
  function mergeClientHeaders(current, next) {
8143
8224
  if (!current && !next) {
8144
8225
  return void 0;
@@ -8269,6 +8350,9 @@ function resolveCreateClientConfig(config) {
8269
8350
  userId: config.userId,
8270
8351
  organizationId: config.organizationId,
8271
8352
  forceNoCache: config.forceNoCache,
8353
+ pgUri: config.pgUri,
8354
+ jdbcUrl: config.jdbcUrl,
8355
+ athenaKey: config.athenaKey,
8272
8356
  backend: toBackendConfig(config.backend),
8273
8357
  headers: config.headers,
8274
8358
  auth: config.auth,
@@ -8285,18 +8369,6 @@ function createClientFromInput(sourceConfig) {
8285
8369
  }
8286
8370
  function createClientFromConfig(config, sourceConfig) {
8287
8371
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
8288
- const gatewayHeaders = {
8289
- ...config.headers ?? {}
8290
- };
8291
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
8292
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
8293
- }
8294
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
8295
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
8296
- }
8297
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
8298
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8299
- }
8300
8372
  const gateway = createAthenaGatewayClient({
8301
8373
  baseUrl: config.baseUrl,
8302
8374
  apiKey: config.apiKey,
@@ -8304,8 +8376,14 @@ function createClientFromConfig(config, sourceConfig) {
8304
8376
  userId: config.userId,
8305
8377
  organizationId: config.organizationId,
8306
8378
  forceNoCache: config.forceNoCache,
8379
+ pgUri: config.pgUri,
8380
+ jdbcUrl: config.jdbcUrl,
8381
+ athenaKey: config.athenaKey,
8307
8382
  backend: config.backend,
8308
- headers: gatewayHeaders
8383
+ bearerToken: normalizedAuthConfig?.bearerToken,
8384
+ cookie: normalizedAuthConfig?.cookie,
8385
+ sessionToken: normalizedAuthConfig?.sessionToken,
8386
+ headers: config.headers
8309
8387
  });
8310
8388
  const formatGatewayResult = createResultFormatter(config.experimental);
8311
8389
  const queryTracer = createQueryTracer(config.experimental);
@@ -8363,6 +8441,7 @@ function createClientFromConfig(config, sourceConfig) {
8363
8441
  const chat = createChatModule({
8364
8442
  baseUrl: config.chatUrl,
8365
8443
  apiKey: config.apiKey,
8444
+ athenaKey: config.athenaKey,
8366
8445
  client: config.client,
8367
8446
  headers: config.headers,
8368
8447
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -8399,48 +8478,28 @@ function createClientFromConfig(config, sourceConfig) {
8399
8478
  return path.startsWith("/") ? path : `/${path}`;
8400
8479
  })();
8401
8480
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
8402
- const headers = {
8403
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
8404
- ...config.headers ?? {},
8405
- ...options.headers ?? {}
8406
- };
8407
- if (service !== "auth") {
8408
- headers.apikey = headers.apikey ?? config.apiKey;
8409
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
8410
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
8411
- headers["X-Athena-Client"] = config.client;
8412
- }
8413
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
8414
- headers["X-User-Id"] = config.userId;
8415
- }
8416
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
8417
- headers["X-Organization-Id"] = config.organizationId;
8418
- }
8419
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
8420
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8421
- }
8422
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
8423
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
8424
- }
8425
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
8426
- headers.Cookie = normalizedAuthConfig.cookie;
8427
- }
8428
- } else {
8429
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
8430
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
8431
- headers.apikey = headers.apikey ?? authApiKey;
8432
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
8433
- }
8434
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
8435
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
8436
- }
8437
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
8438
- headers.Cookie = normalizedAuthConfig.cookie;
8439
- }
8440
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
8441
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8442
- }
8443
- }
8481
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
8482
+ const headers = buildAthenaRequestHeaders({
8483
+ profile: requestProfile,
8484
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
8485
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
8486
+ athenaKey: options.athenaKey ?? config.athenaKey,
8487
+ client: config.client,
8488
+ userId: config.userId,
8489
+ organizationId: config.organizationId,
8490
+ backend: config.backend,
8491
+ pgUri: config.pgUri,
8492
+ jdbcUrl: config.jdbcUrl,
8493
+ bearerToken: normalizedAuthConfig?.bearerToken,
8494
+ cookie: normalizedAuthConfig?.cookie,
8495
+ sessionToken: normalizedAuthConfig?.sessionToken,
8496
+ forceNoCache: config.forceNoCache,
8497
+ configHeaders: config.headers,
8498
+ callHeaders: options.headers,
8499
+ accept: service === "chat" ? "application/json" : void 0,
8500
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
8501
+ stripNulls: service === "db" ? true : void 0
8502
+ });
8444
8503
  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";
8445
8504
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
8446
8505
  headers["Content-Type"] = "application/json";