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