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