@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
@@ -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", "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,207 @@ 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 (!hasHeaderIgnoreCase(headers, "x-api-key")) {
272
+ headers["x-api-key"] = apiKey;
273
+ }
274
+ }
275
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
276
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
277
+ headers["X-Athena-Key"] = resolvedAthenaKey;
278
+ }
279
+ }
280
+ function applyAthenaAuthContextHeaders(headers, input) {
281
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
282
+ const rules = PROFILE_RULES[input.profile];
283
+ const explicitCookie = normalizeHeaderValue(input.cookie);
284
+ if (explicitCookie) {
285
+ mergedExtraHeaders.Cookie = explicitCookie;
286
+ }
287
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
288
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
289
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
290
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
291
+ headers.Cookie = explicitCookie;
292
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
293
+ headers.Cookie = cookieFromHeaders;
294
+ }
295
+ const explicitBearerToken = (() => {
296
+ const configured = normalizeHeaderValue(input.bearerToken);
297
+ if (configured) {
298
+ return normalizeBearerToken(configured);
299
+ }
300
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
301
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
302
+ })();
303
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
304
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
305
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
306
+ }
307
+ if (rules.authMirror) {
308
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
309
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
310
+ }
311
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
312
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
313
+ }
314
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
315
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
316
+ }
317
+ }
318
+ function applyAthenaPgUriHeaders(headers, input) {
319
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
320
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
321
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
322
+ headers["x-pg-uri"] = pgUri;
323
+ }
324
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
325
+ if (jdbcUrl) {
326
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
327
+ headers["x-athena-jdbc-url"] = jdbcUrl;
328
+ }
329
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
330
+ headers["x-jdbc-url"] = jdbcUrl;
331
+ }
332
+ }
333
+ }
334
+ function buildAthenaRequestHeaders(input) {
335
+ const forceNoCache = Boolean(input.forceNoCache);
336
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
337
+ const rules = PROFILE_RULES[input.profile];
338
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
339
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
340
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
341
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
342
+ const headers = {
343
+ "X-Athena-Sdk": input.sdkHeaderValue
344
+ };
345
+ if (rules.contentType) {
346
+ headers["Content-Type"] = input.contentType ?? "application/json";
347
+ }
348
+ if (input.accept ?? rules.accept) {
349
+ headers.Accept = input.accept ?? "application/json";
350
+ }
351
+ if (rules.routing) {
352
+ if (normalizeHeaderValue(input.userId)) {
353
+ headers["X-User-Id"] = input.userId ?? "";
354
+ }
355
+ if (normalizeHeaderValue(input.organizationId)) {
356
+ headers["X-Organization-Id"] = input.organizationId ?? "";
357
+ }
358
+ if (finalClient) {
359
+ headers["X-Athena-Client"] = finalClient;
360
+ }
361
+ const backendType = resolveBackendType(input.backend);
362
+ if (backendType) {
363
+ headers["X-Backend-Type"] = backendType;
364
+ }
365
+ if (typeof input.stripNulls === "boolean") {
366
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
367
+ } else if (rules.stripNullsDefault) {
368
+ headers["X-Strip-Nulls"] = "true";
369
+ }
370
+ if (normalizeHeaderValue(input.publishEvent)) {
371
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
372
+ }
373
+ }
374
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
375
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
376
+ }
377
+ applyAthenaAuthContextHeaders(headers, input);
378
+ applyAthenaPgUriHeaders(headers, input);
379
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
380
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
381
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
382
+ return;
383
+ }
384
+ if (forceNoCache && isCacheControlHeaderName(key)) {
385
+ return;
386
+ }
387
+ const normalized = normalizeHeaderValue(value);
388
+ if (normalized) {
389
+ headers[key] = normalized;
390
+ }
391
+ });
392
+ if (forceNoCache) {
393
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
394
+ }
395
+ return headers;
396
+ }
397
+
398
+ // package.json
399
+ var package_default = {
400
+ version: "2.12.0"
401
+ };
402
+
403
+ // src/sdk-version.ts
404
+ var PACKAGE_VERSION = package_default.version;
405
+ function buildSdkHeaderValue(sdkName) {
406
+ return `${sdkName} ${PACKAGE_VERSION}`;
407
+ }
408
+
409
+ // src/gateway/client.ts
410
+ var DEFAULT_CLIENT = "railway_direct";
411
+ var SDK_NAME = "xylex-group/athena";
412
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
413
+ function parseResponseBody(rawText, contentType) {
414
+ if (!rawText) {
415
+ return { parsed: null, parseFailed: false };
416
+ }
417
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
418
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
419
+ if (!looksJson) {
420
+ return { parsed: rawText, parseFailed: false };
421
+ }
422
+ try {
423
+ return { parsed: JSON.parse(rawText), parseFailed: false };
424
+ } catch {
425
+ return { parsed: rawText, parseFailed: true };
426
+ }
427
+ }
231
428
  function isRecord(value) {
232
429
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
233
430
  }
@@ -354,71 +551,10 @@ function buildRpcGetEndpoint(payload) {
354
551
  return withQuery;
355
552
  }
356
553
  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
- }
554
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
555
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
556
+ stripNulls: options?.stripNulls ?? true
417
557
  });
418
- if (forceNoCache) {
419
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
420
- }
421
- return headers;
422
558
  }
423
559
  function toInvalidUrlResponse(error, endpoint, method) {
424
560
  const message = error instanceof Error ? error.message : String(error);
@@ -1075,19 +1211,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
1075
1211
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
1076
1212
  var SDK_NAME2 = "xylex-group/athena-auth";
1077
1213
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
1078
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
1079
1214
  function normalizeBaseUrl(baseUrl) {
1080
1215
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
1081
1216
  }
1082
1217
  function isRecord3(value) {
1083
1218
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1084
1219
  }
1085
- function normalizeHeaderValue2(value) {
1086
- return value ? value : void 0;
1087
- }
1088
- function isCacheControlHeaderName2(name) {
1089
- return name.toLowerCase() === "cache-control";
1090
- }
1091
1220
  function parseResponseBody2(rawText, contentType) {
1092
1221
  if (!rawText) {
1093
1222
  return { parsed: null, parseFailed: false };
@@ -1287,45 +1416,7 @@ function extractFetchOptions(input) {
1287
1416
  };
1288
1417
  }
1289
1418
  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;
1419
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
1329
1420
  }
1330
1421
  function appendQueryParam(searchParams, key, value) {
1331
1422
  if (value === void 0 || value === null) return;
@@ -4787,7 +4878,6 @@ function createStorageModule(gateway, runtimeOptions) {
4787
4878
  // src/chat/module.ts
4788
4879
  var SDK_NAME3 = "xylex-group/athena-chat";
4789
4880
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
4790
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
4791
4881
  var AthenaChatError = class extends Error {
4792
4882
  status;
4793
4883
  endpoint;
@@ -4833,9 +4923,6 @@ function normalizeWsUrl(value, label) {
4833
4923
  function isRecord7(value) {
4834
4924
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4835
4925
  }
4836
- function normalizeHeaderValue3(value) {
4837
- return value ? value : void 0;
4838
- }
4839
4926
  function parseResponseBody4(rawText, contentType) {
4840
4927
  if (!rawText) {
4841
4928
  return { parsed: null, parseFailed: false };
@@ -4907,39 +4994,7 @@ function createSocket(factory, url, protocols) {
4907
4994
  }
4908
4995
  }
4909
4996
  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;
4997
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
4943
4998
  }
4944
4999
  function withJsonBody(init, body) {
4945
5000
  return {
@@ -5318,6 +5373,9 @@ var AthenaClientBuilderImpl = class {
5318
5373
  defaultOrganizationId;
5319
5374
  forceNoCacheEnabled = false;
5320
5375
  defaultHeaders;
5376
+ pgUriValue;
5377
+ jdbcUrlValue;
5378
+ athenaKeyValue;
5321
5379
  authConfig;
5322
5380
  dbUrlOverride;
5323
5381
  gatewayUrlOverride;
@@ -5344,6 +5402,18 @@ var AthenaClientBuilderImpl = class {
5344
5402
  this.defaultHeaders = headers;
5345
5403
  return this;
5346
5404
  }
5405
+ pgUri(pgUri) {
5406
+ this.pgUriValue = pgUri;
5407
+ return this;
5408
+ }
5409
+ jdbcUrl(jdbcUrl) {
5410
+ this.jdbcUrlValue = jdbcUrl;
5411
+ return this;
5412
+ }
5413
+ athenaKey(athenaKey) {
5414
+ this.athenaKeyValue = athenaKey;
5415
+ return this;
5416
+ }
5347
5417
  auth(config) {
5348
5418
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
5349
5419
  return this;
@@ -5380,6 +5450,15 @@ var AthenaClientBuilderImpl = class {
5380
5450
  if (options.headers !== void 0) {
5381
5451
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
5382
5452
  }
5453
+ if (options.pgUri !== void 0) {
5454
+ this.pgUriValue = options.pgUri;
5455
+ }
5456
+ if (options.jdbcUrl !== void 0) {
5457
+ this.jdbcUrlValue = options.jdbcUrl;
5458
+ }
5459
+ if (options.athenaKey !== void 0) {
5460
+ this.athenaKeyValue = options.athenaKey;
5461
+ }
5383
5462
  if (options.auth !== void 0) {
5384
5463
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
5385
5464
  }
@@ -5431,6 +5510,9 @@ var AthenaClientBuilderImpl = class {
5431
5510
  userId: this.defaultUserId,
5432
5511
  organizationId: this.defaultOrganizationId,
5433
5512
  forceNoCache: this.forceNoCacheEnabled,
5513
+ pgUri: this.pgUriValue,
5514
+ jdbcUrl: this.jdbcUrlValue,
5515
+ athenaKey: this.athenaKeyValue,
5434
5516
  backend: this.backendConfig,
5435
5517
  headers: this.defaultHeaders,
5436
5518
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -8137,10 +8219,6 @@ function resolveRequiredClientApiKey(value) {
8137
8219
  }
8138
8220
  return normalizedValue;
8139
8221
  }
8140
- function hasHeaderIgnoreCase(headers, targetKey) {
8141
- const normalizedTargetKey = targetKey.toLowerCase();
8142
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
8143
- }
8144
8222
  function mergeClientHeaders(current, next) {
8145
8223
  if (!current && !next) {
8146
8224
  return void 0;
@@ -8271,6 +8349,9 @@ function resolveCreateClientConfig(config) {
8271
8349
  userId: config.userId,
8272
8350
  organizationId: config.organizationId,
8273
8351
  forceNoCache: config.forceNoCache,
8352
+ pgUri: config.pgUri,
8353
+ jdbcUrl: config.jdbcUrl,
8354
+ athenaKey: config.athenaKey,
8274
8355
  backend: toBackendConfig(config.backend),
8275
8356
  headers: config.headers,
8276
8357
  auth: config.auth,
@@ -8287,18 +8368,6 @@ function createClientFromInput(sourceConfig) {
8287
8368
  }
8288
8369
  function createClientFromConfig(config, sourceConfig) {
8289
8370
  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
8371
  const gateway = createAthenaGatewayClient({
8303
8372
  baseUrl: config.baseUrl,
8304
8373
  apiKey: config.apiKey,
@@ -8306,8 +8375,14 @@ function createClientFromConfig(config, sourceConfig) {
8306
8375
  userId: config.userId,
8307
8376
  organizationId: config.organizationId,
8308
8377
  forceNoCache: config.forceNoCache,
8378
+ pgUri: config.pgUri,
8379
+ jdbcUrl: config.jdbcUrl,
8380
+ athenaKey: config.athenaKey,
8309
8381
  backend: config.backend,
8310
- headers: gatewayHeaders
8382
+ bearerToken: normalizedAuthConfig?.bearerToken,
8383
+ cookie: normalizedAuthConfig?.cookie,
8384
+ sessionToken: normalizedAuthConfig?.sessionToken,
8385
+ headers: config.headers
8311
8386
  });
8312
8387
  const formatGatewayResult = createResultFormatter(config.experimental);
8313
8388
  const queryTracer = createQueryTracer(config.experimental);
@@ -8365,6 +8440,7 @@ function createClientFromConfig(config, sourceConfig) {
8365
8440
  const chat = createChatModule({
8366
8441
  baseUrl: config.chatUrl,
8367
8442
  apiKey: config.apiKey,
8443
+ athenaKey: config.athenaKey,
8368
8444
  client: config.client,
8369
8445
  headers: config.headers,
8370
8446
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -8401,48 +8477,28 @@ function createClientFromConfig(config, sourceConfig) {
8401
8477
  return path.startsWith("/") ? path : `/${path}`;
8402
8478
  })();
8403
8479
  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
- }
8480
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
8481
+ const headers = buildAthenaRequestHeaders({
8482
+ profile: requestProfile,
8483
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
8484
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
8485
+ athenaKey: options.athenaKey ?? config.athenaKey,
8486
+ client: config.client,
8487
+ userId: config.userId,
8488
+ organizationId: config.organizationId,
8489
+ backend: config.backend,
8490
+ pgUri: config.pgUri,
8491
+ jdbcUrl: config.jdbcUrl,
8492
+ bearerToken: normalizedAuthConfig?.bearerToken,
8493
+ cookie: normalizedAuthConfig?.cookie,
8494
+ sessionToken: normalizedAuthConfig?.sessionToken,
8495
+ forceNoCache: config.forceNoCache,
8496
+ configHeaders: config.headers,
8497
+ callHeaders: options.headers,
8498
+ accept: service === "chat" ? "application/json" : void 0,
8499
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
8500
+ stripNulls: service === "db" ? true : void 0
8501
+ });
8446
8502
  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
8503
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
8448
8504
  headers["Content-Type"] = "application/json";