@xylex-group/athena 2.10.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 +112 -28
  2. package/dist/browser.cjs +333 -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 +333 -240
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +306 -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 +306 -240
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/{client-BYii6dU9.d.ts → client-C3x75Zgn.d.cts} +22 -9
  15. package/dist/{client-B7EQ_hPV.d.cts → client-QUbAs7E8.d.ts} +22 -9
  16. package/dist/index.cjs +333 -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 +333 -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-DbHlxpeR.d.ts → module-CW3tWJ10.d.ts} +5 -4
  25. package/dist/{module-DC96HJa3.d.cts → module-Cxcurfes.d.cts} +5 -4
  26. package/dist/next/client.cjs +333 -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 +333 -240
  31. package/dist/next/client.js.map +1 -1
  32. package/dist/next/server.cjs +333 -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 +333 -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-DRptGBWP.d.ts → shared-0Kdc74lu.d.ts} +2 -2
  47. package/dist/{shared-BMVGMnti.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 +2 -2
  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.10.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 };
@@ -1150,6 +1279,21 @@ function copyDefinedField(target, source, targetKey, sourceKey) {
1150
1279
  target[targetKey] = value;
1151
1280
  }
1152
1281
  }
1282
+ function normalizeEmailTemplateAttachmentsValue(value) {
1283
+ if (typeof value === "string" || value == null) {
1284
+ return value;
1285
+ }
1286
+ if (Array.isArray(value)) {
1287
+ return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
1288
+ }
1289
+ if (typeof value !== "object") {
1290
+ return value;
1291
+ }
1292
+ const attachment = { ...value };
1293
+ copyDefinedField(attachment, attachment, "file_url", "fileUrl");
1294
+ delete attachment.fileUrl;
1295
+ return attachment;
1296
+ }
1153
1297
  function normalizeAdminEmailTemplatePayload(payload) {
1154
1298
  const normalized = { ...payload };
1155
1299
  copyDefinedField(normalized, payload, "template_key", "templateKey");
@@ -1160,6 +1304,17 @@ function normalizeAdminEmailTemplatePayload(payload) {
1160
1304
  copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
1161
1305
  copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
1162
1306
  copyDefinedField(normalized, payload, "is_active", "isActive");
1307
+ if (Object.hasOwn(payload, "attachments")) {
1308
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
1309
+ }
1310
+ delete normalized.templateKey;
1311
+ delete normalized.eventType;
1312
+ delete normalized.subjectTemplate;
1313
+ delete normalized.textTemplate;
1314
+ delete normalized.htmlTemplate;
1315
+ delete normalized.variableBindings;
1316
+ delete normalized.attachmentFailureMode;
1317
+ delete normalized.isActive;
1163
1318
  return normalized;
1164
1319
  }
1165
1320
  function toReactEmailTemplateCompatibilityInput(input) {
@@ -1183,6 +1338,17 @@ function normalizeAdminEmailTemplateSendPayload(payload) {
1183
1338
  copyDefinedField(normalized, payload, "user_id", "userId");
1184
1339
  copyDefinedField(normalized, payload, "organization_id", "organizationId");
1185
1340
  copyDefinedField(normalized, payload, "session_token", "sessionToken");
1341
+ copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
1342
+ if (Object.hasOwn(payload, "attachments")) {
1343
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
1344
+ }
1345
+ delete normalized.templateId;
1346
+ delete normalized.recipientEmail;
1347
+ delete normalized.renderVariables;
1348
+ delete normalized.userId;
1349
+ delete normalized.organizationId;
1350
+ delete normalized.sessionToken;
1351
+ delete normalized.attachmentFailureMode;
1186
1352
  return normalized;
1187
1353
  }
1188
1354
  function toSessionGuardFailure(sessionResult) {
@@ -1248,45 +1414,7 @@ function extractFetchOptions(input) {
1248
1414
  };
1249
1415
  }
1250
1416
  function buildHeaders2(config, options) {
1251
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1252
- const headers = {
1253
- "Content-Type": "application/json",
1254
- "X-Athena-Sdk": SDK_HEADER_VALUE2
1255
- };
1256
- const apiKey = options?.apiKey ?? config.apiKey;
1257
- if (apiKey) {
1258
- headers.apikey = apiKey;
1259
- headers["x-api-key"] = apiKey;
1260
- }
1261
- const bearerToken = options?.bearerToken ?? config.bearerToken;
1262
- if (bearerToken) {
1263
- headers.Authorization = `Bearer ${bearerToken}`;
1264
- }
1265
- const cookie = options?.cookie ?? config.cookie;
1266
- if (cookie) {
1267
- headers.Cookie = cookie;
1268
- }
1269
- const sessionToken = options?.sessionToken ?? config.sessionToken;
1270
- if (sessionToken) {
1271
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
1272
- }
1273
- const mergedExtraHeaders = {
1274
- ...config.headers ?? {},
1275
- ...options?.headers ?? {}
1276
- };
1277
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1278
- if (forceNoCache && isCacheControlHeaderName2(key)) {
1279
- return;
1280
- }
1281
- const normalized = normalizeHeaderValue2(value);
1282
- if (normalized) {
1283
- headers[key] = normalized;
1284
- }
1285
- });
1286
- if (forceNoCache) {
1287
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
1288
- }
1289
- return headers;
1417
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
1290
1418
  }
1291
1419
  function appendQueryParam(searchParams, key, value) {
1292
1420
  if (value === void 0 || value === null) return;
@@ -4748,7 +4876,6 @@ function createStorageModule(gateway, runtimeOptions) {
4748
4876
  // src/chat/module.ts
4749
4877
  var SDK_NAME3 = "xylex-group/athena-chat";
4750
4878
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
4751
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
4752
4879
  var AthenaChatError = class extends Error {
4753
4880
  status;
4754
4881
  endpoint;
@@ -4794,9 +4921,6 @@ function normalizeWsUrl(value, label) {
4794
4921
  function isRecord7(value) {
4795
4922
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4796
4923
  }
4797
- function normalizeHeaderValue3(value) {
4798
- return value ? value : void 0;
4799
- }
4800
4924
  function parseResponseBody4(rawText, contentType) {
4801
4925
  if (!rawText) {
4802
4926
  return { parsed: null, parseFailed: false };
@@ -4868,39 +4992,7 @@ function createSocket(factory, url, protocols) {
4868
4992
  }
4869
4993
  }
4870
4994
  function buildHeaders3(config, options) {
4871
- const headers = {
4872
- Accept: "application/json",
4873
- apikey: config.apiKey,
4874
- "x-api-key": config.apiKey,
4875
- "X-Athena-Sdk": SDK_HEADER_VALUE3
4876
- };
4877
- if (config.client || options?.client) {
4878
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
4879
- }
4880
- const bearerToken = options?.bearerToken ?? config.bearerToken;
4881
- if (typeof bearerToken === "string" && bearerToken.trim()) {
4882
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
4883
- }
4884
- const cookie = options?.cookie ?? config.cookie;
4885
- if (typeof cookie === "string" && cookie.trim()) {
4886
- headers.Cookie = cookie;
4887
- }
4888
- const sessionToken = options?.sessionToken ?? config.sessionToken;
4889
- if (typeof sessionToken === "string" && sessionToken.trim()) {
4890
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
4891
- }
4892
- if (config.forceNoCache || options?.forceNoCache) {
4893
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
4894
- }
4895
- for (const source of [config.headers, options?.headers]) {
4896
- for (const [key, value] of Object.entries(source ?? {})) {
4897
- const normalized = normalizeHeaderValue3(value);
4898
- if (normalized) {
4899
- headers[key] = normalized;
4900
- }
4901
- }
4902
- }
4903
- return headers;
4995
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
4904
4996
  }
4905
4997
  function withJsonBody(init, body) {
4906
4998
  return {
@@ -5279,6 +5371,9 @@ var AthenaClientBuilderImpl = class {
5279
5371
  defaultOrganizationId;
5280
5372
  forceNoCacheEnabled = false;
5281
5373
  defaultHeaders;
5374
+ pgUriValue;
5375
+ jdbcUrlValue;
5376
+ athenaKeyValue;
5282
5377
  authConfig;
5283
5378
  dbUrlOverride;
5284
5379
  gatewayUrlOverride;
@@ -5305,6 +5400,18 @@ var AthenaClientBuilderImpl = class {
5305
5400
  this.defaultHeaders = headers;
5306
5401
  return this;
5307
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
+ }
5308
5415
  auth(config) {
5309
5416
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
5310
5417
  return this;
@@ -5341,6 +5448,15 @@ var AthenaClientBuilderImpl = class {
5341
5448
  if (options.headers !== void 0) {
5342
5449
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
5343
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
+ }
5344
5460
  if (options.auth !== void 0) {
5345
5461
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
5346
5462
  }
@@ -5392,6 +5508,9 @@ var AthenaClientBuilderImpl = class {
5392
5508
  userId: this.defaultUserId,
5393
5509
  organizationId: this.defaultOrganizationId,
5394
5510
  forceNoCache: this.forceNoCacheEnabled,
5511
+ pgUri: this.pgUriValue,
5512
+ jdbcUrl: this.jdbcUrlValue,
5513
+ athenaKey: this.athenaKeyValue,
5395
5514
  backend: this.backendConfig,
5396
5515
  headers: this.defaultHeaders,
5397
5516
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -8098,10 +8217,6 @@ function resolveRequiredClientApiKey(value) {
8098
8217
  }
8099
8218
  return normalizedValue;
8100
8219
  }
8101
- function hasHeaderIgnoreCase(headers, targetKey) {
8102
- const normalizedTargetKey = targetKey.toLowerCase();
8103
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
8104
- }
8105
8220
  function mergeClientHeaders(current, next) {
8106
8221
  if (!current && !next) {
8107
8222
  return void 0;
@@ -8232,6 +8347,9 @@ function resolveCreateClientConfig(config) {
8232
8347
  userId: config.userId,
8233
8348
  organizationId: config.organizationId,
8234
8349
  forceNoCache: config.forceNoCache,
8350
+ pgUri: config.pgUri,
8351
+ jdbcUrl: config.jdbcUrl,
8352
+ athenaKey: config.athenaKey,
8235
8353
  backend: toBackendConfig(config.backend),
8236
8354
  headers: config.headers,
8237
8355
  auth: config.auth,
@@ -8248,18 +8366,6 @@ function createClientFromInput(sourceConfig) {
8248
8366
  }
8249
8367
  function createClientFromConfig(config, sourceConfig) {
8250
8368
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
8251
- const gatewayHeaders = {
8252
- ...config.headers ?? {}
8253
- };
8254
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
8255
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
8256
- }
8257
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
8258
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
8259
- }
8260
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
8261
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8262
- }
8263
8369
  const gateway = createAthenaGatewayClient({
8264
8370
  baseUrl: config.baseUrl,
8265
8371
  apiKey: config.apiKey,
@@ -8267,8 +8373,14 @@ function createClientFromConfig(config, sourceConfig) {
8267
8373
  userId: config.userId,
8268
8374
  organizationId: config.organizationId,
8269
8375
  forceNoCache: config.forceNoCache,
8376
+ pgUri: config.pgUri,
8377
+ jdbcUrl: config.jdbcUrl,
8378
+ athenaKey: config.athenaKey,
8270
8379
  backend: config.backend,
8271
- headers: gatewayHeaders
8380
+ bearerToken: normalizedAuthConfig?.bearerToken,
8381
+ cookie: normalizedAuthConfig?.cookie,
8382
+ sessionToken: normalizedAuthConfig?.sessionToken,
8383
+ headers: config.headers
8272
8384
  });
8273
8385
  const formatGatewayResult = createResultFormatter(config.experimental);
8274
8386
  const queryTracer = createQueryTracer(config.experimental);
@@ -8326,6 +8438,7 @@ function createClientFromConfig(config, sourceConfig) {
8326
8438
  const chat = createChatModule({
8327
8439
  baseUrl: config.chatUrl,
8328
8440
  apiKey: config.apiKey,
8441
+ athenaKey: config.athenaKey,
8329
8442
  client: config.client,
8330
8443
  headers: config.headers,
8331
8444
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -8362,48 +8475,28 @@ function createClientFromConfig(config, sourceConfig) {
8362
8475
  return path.startsWith("/") ? path : `/${path}`;
8363
8476
  })();
8364
8477
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
8365
- const headers = {
8366
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
8367
- ...config.headers ?? {},
8368
- ...options.headers ?? {}
8369
- };
8370
- if (service !== "auth") {
8371
- headers.apikey = headers.apikey ?? config.apiKey;
8372
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
8373
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
8374
- headers["X-Athena-Client"] = config.client;
8375
- }
8376
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
8377
- headers["X-User-Id"] = config.userId;
8378
- }
8379
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
8380
- headers["X-Organization-Id"] = config.organizationId;
8381
- }
8382
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
8383
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8384
- }
8385
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
8386
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
8387
- }
8388
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
8389
- headers.Cookie = normalizedAuthConfig.cookie;
8390
- }
8391
- } else {
8392
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
8393
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
8394
- headers.apikey = headers.apikey ?? authApiKey;
8395
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
8396
- }
8397
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
8398
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
8399
- }
8400
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
8401
- headers.Cookie = normalizedAuthConfig.cookie;
8402
- }
8403
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
8404
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8405
- }
8406
- }
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
+ });
8407
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";
8408
8501
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
8409
8502
  headers["Content-Type"] = "application/json";