@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
package/dist/index.js CHANGED
@@ -802,42 +802,31 @@ var getCookieCache = async (request2, config) => {
802
802
  };
803
803
  };
804
804
 
805
- // package.json
806
- var package_default = {
807
- version: "2.11.0"
808
- };
809
-
810
- // src/sdk-version.ts
811
- var PACKAGE_VERSION = package_default.version;
812
- function buildSdkHeaderValue(sdkName) {
813
- return `${sdkName} ${PACKAGE_VERSION}`;
814
- }
815
-
816
- // src/gateway/client.ts
817
- var DEFAULT_CLIENT = "railway_direct";
818
- var SDK_NAME = "xylex-group/athena";
819
- var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
805
+ // src/utils/athena-request-headers.ts
820
806
  var NO_CACHE_HEADER_VALUE = "no-cache";
821
- function parseResponseBody(rawText, contentType) {
822
- if (!rawText) {
823
- return { parsed: null, parseFailed: false };
824
- }
825
- const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
826
- const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
827
- if (!looksJson) {
828
- return { parsed: rawText, parseFailed: false };
829
- }
830
- try {
831
- return { parsed: JSON.parse(rawText), parseFailed: false };
832
- } catch {
833
- return { parsed: rawText, parseFailed: true };
834
- }
835
- }
807
+ var API_KEY_HEADER_CANDIDATES = ["x-api-key", "apikey"];
808
+ var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
809
+ var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
810
+ var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
811
+ var CLIENT_HEADER_CANDIDATES = ["X-Athena-Client", "x-athena-client"];
812
+ var PG_URI_HEADER_CANDIDATES = ["x-pg-uri"];
813
+ var JDBC_URI_HEADER_CANDIDATES = ["x-athena-jdbc-url", "x-jdbc-url"];
814
+ var PROFILE_RULES = {
815
+ gateway: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true, stripNullsDefault: true },
816
+ chat: { apiKeys: true, routing: true, authMirror: true, authBearer: true, accept: true },
817
+ storage: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true },
818
+ auth: { apiKeys: true, routing: false, authMirror: false, authBearer: true, contentType: true },
819
+ minimal: { apiKeys: false, routing: false, authMirror: false, authBearer: false }
820
+ };
836
821
  function normalizeHeaderValue(value) {
837
822
  return value ? value : void 0;
838
823
  }
839
- function isCacheControlHeaderName(name) {
840
- return name.toLowerCase() === "cache-control";
824
+ function mergeExtraHeaders(configHeaders, callHeaders) {
825
+ return { ...configHeaders ?? {}, ...callHeaders ?? {} };
826
+ }
827
+ function hasHeaderIgnoreCase(headers, targetKey) {
828
+ const normalizedTargetKey = targetKey.toLowerCase();
829
+ return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
841
830
  }
842
831
  function resolveHeaderValue(headers, candidates) {
843
832
  for (const candidate of candidates) {
@@ -854,13 +843,20 @@ function resolveHeaderValue(headers, candidates) {
854
843
  }
855
844
  return void 0;
856
845
  }
846
+ function isCacheControlHeaderName(name) {
847
+ return name.toLowerCase() === "cache-control";
848
+ }
849
+ function normalizeBearerToken(value) {
850
+ const trimmed = value.trim();
851
+ const match = trimmed.match(/^Bearer\s+(.+)$/i);
852
+ return match?.[1]?.trim() ?? trimmed;
853
+ }
857
854
  function resolveBearerTokenFromAuthorizationHeader(headers) {
858
855
  const authorization = resolveHeaderValue(headers, ["Authorization"]);
859
856
  if (!authorization) {
860
857
  return void 0;
861
858
  }
862
- const match = authorization.match(/^Bearer\s+(.+)$/i);
863
- const token = match?.[1]?.trim();
859
+ const token = normalizeBearerToken(authorization);
864
860
  return token ? token : void 0;
865
861
  }
866
862
  function resolveSessionTokenFromCookieHeader(headers) {
@@ -870,6 +866,207 @@ function resolveSessionTokenFromCookieHeader(headers) {
870
866
  }
871
867
  return getSessionCookie(new Headers({ cookie })) ?? void 0;
872
868
  }
869
+ function resolveBackendType(backend) {
870
+ if (!backend) {
871
+ return void 0;
872
+ }
873
+ return typeof backend === "string" ? backend : backend.type;
874
+ }
875
+ function resolveRequestHeaderOverrides(config, options, defaults) {
876
+ return {
877
+ apiKey: options?.apiKey ?? config.apiKey,
878
+ athenaKey: options?.athenaKey ?? config.athenaKey,
879
+ client: options?.client ?? config.client ?? defaults?.client,
880
+ userId: options?.userId ?? config.userId,
881
+ organizationId: options?.organizationId ?? config.organizationId,
882
+ backend: options?.backend ?? config.backend,
883
+ publishEvent: options?.publishEvent ?? config.publishEvent,
884
+ stripNulls: options?.stripNulls ?? config.stripNulls ?? defaults?.stripNulls,
885
+ bearerToken: options?.bearerToken ?? config.bearerToken,
886
+ cookie: options?.cookie ?? config.cookie,
887
+ sessionToken: options?.sessionToken ?? config.sessionToken,
888
+ pgUri: options?.pgUri ?? config.pgUri,
889
+ jdbcUrl: options?.jdbcUrl ?? config.jdbcUrl,
890
+ forceNoCache: Boolean(config.forceNoCache || options?.forceNoCache),
891
+ configHeaders: config.headers,
892
+ callHeaders: options?.headers
893
+ };
894
+ }
895
+ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, extras) {
896
+ const rules = PROFILE_RULES[profile];
897
+ return buildAthenaRequestHeaders({
898
+ profile,
899
+ sdkHeaderValue,
900
+ ...resolveRequestHeaderOverrides(config, options, {
901
+ client: extras?.client ?? void 0,
902
+ stripNulls: extras?.stripNulls ?? (rules.stripNullsDefault ? true : void 0)
903
+ }),
904
+ contentType: extras?.contentType ?? (rules.contentType ? "application/json" : void 0),
905
+ accept: extras?.accept ?? (rules.accept ? "application/json" : void 0)
906
+ });
907
+ }
908
+ function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
909
+ if (apiKey) {
910
+ if (!hasHeaderIgnoreCase(headers, "apikey")) {
911
+ headers.apikey = apiKey;
912
+ }
913
+ if (!hasHeaderIgnoreCase(headers, "x-api-key")) {
914
+ headers["x-api-key"] = apiKey;
915
+ }
916
+ }
917
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
918
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
919
+ headers["X-Athena-Key"] = resolvedAthenaKey;
920
+ }
921
+ }
922
+ function applyAthenaAuthContextHeaders(headers, input) {
923
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
924
+ const rules = PROFILE_RULES[input.profile];
925
+ const explicitCookie = normalizeHeaderValue(input.cookie);
926
+ if (explicitCookie) {
927
+ mergedExtraHeaders.Cookie = explicitCookie;
928
+ }
929
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
930
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
931
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
932
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
933
+ headers.Cookie = explicitCookie;
934
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
935
+ headers.Cookie = cookieFromHeaders;
936
+ }
937
+ const explicitBearerToken = (() => {
938
+ const configured = normalizeHeaderValue(input.bearerToken);
939
+ if (configured) {
940
+ return normalizeBearerToken(configured);
941
+ }
942
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
943
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
944
+ })();
945
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
946
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
947
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
948
+ }
949
+ if (rules.authMirror) {
950
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
951
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
952
+ }
953
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
954
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
955
+ }
956
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
957
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
958
+ }
959
+ }
960
+ function applyAthenaPgUriHeaders(headers, input) {
961
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
962
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
963
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
964
+ headers["x-pg-uri"] = pgUri;
965
+ }
966
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
967
+ if (jdbcUrl) {
968
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
969
+ headers["x-athena-jdbc-url"] = jdbcUrl;
970
+ }
971
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
972
+ headers["x-jdbc-url"] = jdbcUrl;
973
+ }
974
+ }
975
+ }
976
+ function buildAthenaRequestHeaders(input) {
977
+ const forceNoCache = Boolean(input.forceNoCache);
978
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
979
+ const rules = PROFILE_RULES[input.profile];
980
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
981
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
982
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
983
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
984
+ const headers = {
985
+ "X-Athena-Sdk": input.sdkHeaderValue
986
+ };
987
+ if (rules.contentType) {
988
+ headers["Content-Type"] = input.contentType ?? "application/json";
989
+ }
990
+ if (input.accept ?? rules.accept) {
991
+ headers.Accept = input.accept ?? "application/json";
992
+ }
993
+ if (rules.routing) {
994
+ if (normalizeHeaderValue(input.userId)) {
995
+ headers["X-User-Id"] = input.userId ?? "";
996
+ }
997
+ if (normalizeHeaderValue(input.organizationId)) {
998
+ headers["X-Organization-Id"] = input.organizationId ?? "";
999
+ }
1000
+ if (finalClient) {
1001
+ headers["X-Athena-Client"] = finalClient;
1002
+ }
1003
+ const backendType = resolveBackendType(input.backend);
1004
+ if (backendType) {
1005
+ headers["X-Backend-Type"] = backendType;
1006
+ }
1007
+ if (typeof input.stripNulls === "boolean") {
1008
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
1009
+ } else if (rules.stripNullsDefault) {
1010
+ headers["X-Strip-Nulls"] = "true";
1011
+ }
1012
+ if (normalizeHeaderValue(input.publishEvent)) {
1013
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
1014
+ }
1015
+ }
1016
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
1017
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
1018
+ }
1019
+ applyAthenaAuthContextHeaders(headers, input);
1020
+ applyAthenaPgUriHeaders(headers, input);
1021
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
1022
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1023
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
1024
+ return;
1025
+ }
1026
+ if (forceNoCache && isCacheControlHeaderName(key)) {
1027
+ return;
1028
+ }
1029
+ const normalized = normalizeHeaderValue(value);
1030
+ if (normalized) {
1031
+ headers[key] = normalized;
1032
+ }
1033
+ });
1034
+ if (forceNoCache) {
1035
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1036
+ }
1037
+ return headers;
1038
+ }
1039
+
1040
+ // package.json
1041
+ var package_default = {
1042
+ version: "2.12.0"
1043
+ };
1044
+
1045
+ // src/sdk-version.ts
1046
+ var PACKAGE_VERSION = package_default.version;
1047
+ function buildSdkHeaderValue(sdkName) {
1048
+ return `${sdkName} ${PACKAGE_VERSION}`;
1049
+ }
1050
+
1051
+ // src/gateway/client.ts
1052
+ var DEFAULT_CLIENT = "railway_direct";
1053
+ var SDK_NAME = "xylex-group/athena";
1054
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
1055
+ function parseResponseBody(rawText, contentType) {
1056
+ if (!rawText) {
1057
+ return { parsed: null, parseFailed: false };
1058
+ }
1059
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
1060
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
1061
+ if (!looksJson) {
1062
+ return { parsed: rawText, parseFailed: false };
1063
+ }
1064
+ try {
1065
+ return { parsed: JSON.parse(rawText), parseFailed: false };
1066
+ } catch {
1067
+ return { parsed: rawText, parseFailed: true };
1068
+ }
1069
+ }
873
1070
  function isRecord(value) {
874
1071
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
875
1072
  }
@@ -996,71 +1193,10 @@ function buildRpcGetEndpoint(payload) {
996
1193
  return withQuery;
997
1194
  }
998
1195
  function buildHeaders(config, options) {
999
- const mergedStripNulls = options?.stripNulls ?? true;
1000
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1001
- const extraHeaders = {
1002
- ...config.headers ?? {},
1003
- ...options?.headers ?? {}
1004
- };
1005
- const headerClient = extraHeaders["x-athena-client"] ?? extraHeaders["X-Athena-Client"];
1006
- const finalClient = options?.client ?? config.client ?? (typeof headerClient === "string" ? headerClient : void 0) ?? DEFAULT_CLIENT;
1007
- const finalApiKey = options?.apiKey ?? config.apiKey;
1008
- const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
1009
- const headers = {
1010
- "Content-Type": "application/json",
1011
- "X-Athena-Sdk": SDK_HEADER_VALUE
1012
- };
1013
- if (options?.userId ?? config.userId) {
1014
- headers["X-User-Id"] = options?.userId ?? config.userId ?? "";
1015
- }
1016
- if (options?.organizationId ?? config.organizationId) {
1017
- headers["X-Organization-Id"] = options?.organizationId ?? config.organizationId ?? "";
1018
- }
1019
- if (finalClient) {
1020
- headers["X-Athena-Client"] = finalClient;
1021
- }
1022
- const finalBackend = options?.backend ?? config.backend;
1023
- if (finalBackend) {
1024
- const type = typeof finalBackend === "string" ? finalBackend : finalBackend.type;
1025
- if (type) headers["X-Backend-Type"] = type;
1026
- }
1027
- if (typeof mergedStripNulls === "boolean") {
1028
- headers["X-Strip-Nulls"] = mergedStripNulls ? "true" : "false";
1029
- }
1030
- if (finalPublishEvent) {
1031
- headers["X-Publish-Event"] = finalPublishEvent;
1032
- }
1033
- if (finalApiKey) {
1034
- headers["apikey"] = finalApiKey;
1035
- headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
1036
- }
1037
- const explicitSessionToken = resolveHeaderValue(extraHeaders, [
1038
- "X-Athena-Auth-Session-Token"
1039
- ]);
1040
- const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(extraHeaders);
1041
- if (derivedSessionToken) {
1042
- headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
1043
- }
1044
- const explicitBearerToken = resolveHeaderValue(extraHeaders, [
1045
- "X-Athena-Auth-Bearer-Token"
1046
- ]);
1047
- const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(extraHeaders);
1048
- if (derivedBearerToken) {
1049
- headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
1050
- }
1051
- const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
1052
- Object.entries(extraHeaders).forEach(([key, value]) => {
1053
- if (athenaClientKeys.includes(key)) return;
1054
- if (forceNoCache && isCacheControlHeaderName(key)) return;
1055
- const normalized = normalizeHeaderValue(value);
1056
- if (normalized) {
1057
- headers[key] = normalized;
1058
- }
1196
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
1197
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
1198
+ stripNulls: options?.stripNulls ?? true
1059
1199
  });
1060
- if (forceNoCache) {
1061
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1062
- }
1063
- return headers;
1064
1200
  }
1065
1201
  function toInvalidUrlResponse(error, endpoint, method) {
1066
1202
  const message = error instanceof Error ? error.message : String(error);
@@ -1788,19 +1924,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
1788
1924
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
1789
1925
  var SDK_NAME2 = "xylex-group/athena-auth";
1790
1926
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
1791
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
1792
1927
  function normalizeBaseUrl(baseUrl) {
1793
1928
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
1794
1929
  }
1795
1930
  function isRecord3(value) {
1796
1931
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1797
1932
  }
1798
- function normalizeHeaderValue2(value) {
1799
- return value ? value : void 0;
1800
- }
1801
- function isCacheControlHeaderName2(name) {
1802
- return name.toLowerCase() === "cache-control";
1803
- }
1804
1933
  function parseResponseBody2(rawText, contentType) {
1805
1934
  if (!rawText) {
1806
1935
  return { parsed: null, parseFailed: false };
@@ -2000,45 +2129,7 @@ function extractFetchOptions(input) {
2000
2129
  };
2001
2130
  }
2002
2131
  function buildHeaders2(config, options) {
2003
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
2004
- const headers = {
2005
- "Content-Type": "application/json",
2006
- "X-Athena-Sdk": SDK_HEADER_VALUE2
2007
- };
2008
- const apiKey = options?.apiKey ?? config.apiKey;
2009
- if (apiKey) {
2010
- headers.apikey = apiKey;
2011
- headers["x-api-key"] = apiKey;
2012
- }
2013
- const bearerToken = options?.bearerToken ?? config.bearerToken;
2014
- if (bearerToken) {
2015
- headers.Authorization = `Bearer ${bearerToken}`;
2016
- }
2017
- const cookie = options?.cookie ?? config.cookie;
2018
- if (cookie) {
2019
- headers.Cookie = cookie;
2020
- }
2021
- const sessionToken = options?.sessionToken ?? config.sessionToken;
2022
- if (sessionToken) {
2023
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
2024
- }
2025
- const mergedExtraHeaders = {
2026
- ...config.headers ?? {},
2027
- ...options?.headers ?? {}
2028
- };
2029
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
2030
- if (forceNoCache && isCacheControlHeaderName2(key)) {
2031
- return;
2032
- }
2033
- const normalized = normalizeHeaderValue2(value);
2034
- if (normalized) {
2035
- headers[key] = normalized;
2036
- }
2037
- });
2038
- if (forceNoCache) {
2039
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
2040
- }
2041
- return headers;
2132
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
2042
2133
  }
2043
2134
  function appendQueryParam(searchParams, key, value) {
2044
2135
  if (value === void 0 || value === null) return;
@@ -5717,7 +5808,6 @@ function createStorageModule(gateway, runtimeOptions) {
5717
5808
  // src/chat/module.ts
5718
5809
  var SDK_NAME3 = "xylex-group/athena-chat";
5719
5810
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
5720
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
5721
5811
  var AthenaChatError = class extends Error {
5722
5812
  status;
5723
5813
  endpoint;
@@ -5763,9 +5853,6 @@ function normalizeWsUrl(value, label) {
5763
5853
  function isRecord7(value) {
5764
5854
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5765
5855
  }
5766
- function normalizeHeaderValue3(value) {
5767
- return value ? value : void 0;
5768
- }
5769
5856
  function parseResponseBody4(rawText, contentType) {
5770
5857
  if (!rawText) {
5771
5858
  return { parsed: null, parseFailed: false };
@@ -5837,39 +5924,7 @@ function createSocket(factory, url, protocols) {
5837
5924
  }
5838
5925
  }
5839
5926
  function buildHeaders3(config, options) {
5840
- const headers = {
5841
- Accept: "application/json",
5842
- apikey: config.apiKey,
5843
- "x-api-key": config.apiKey,
5844
- "X-Athena-Sdk": SDK_HEADER_VALUE3
5845
- };
5846
- if (config.client || options?.client) {
5847
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
5848
- }
5849
- const bearerToken = options?.bearerToken ?? config.bearerToken;
5850
- if (typeof bearerToken === "string" && bearerToken.trim()) {
5851
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
5852
- }
5853
- const cookie = options?.cookie ?? config.cookie;
5854
- if (typeof cookie === "string" && cookie.trim()) {
5855
- headers.Cookie = cookie;
5856
- }
5857
- const sessionToken = options?.sessionToken ?? config.sessionToken;
5858
- if (typeof sessionToken === "string" && sessionToken.trim()) {
5859
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
5860
- }
5861
- if (config.forceNoCache || options?.forceNoCache) {
5862
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
5863
- }
5864
- for (const source of [config.headers, options?.headers]) {
5865
- for (const [key, value] of Object.entries(source ?? {})) {
5866
- const normalized = normalizeHeaderValue3(value);
5867
- if (normalized) {
5868
- headers[key] = normalized;
5869
- }
5870
- }
5871
- }
5872
- return headers;
5927
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
5873
5928
  }
5874
5929
  function withJsonBody(init, body) {
5875
5930
  return {
@@ -6281,6 +6336,9 @@ var AthenaClientBuilderImpl = class {
6281
6336
  defaultOrganizationId;
6282
6337
  forceNoCacheEnabled = false;
6283
6338
  defaultHeaders;
6339
+ pgUriValue;
6340
+ jdbcUrlValue;
6341
+ athenaKeyValue;
6284
6342
  authConfig;
6285
6343
  dbUrlOverride;
6286
6344
  gatewayUrlOverride;
@@ -6307,6 +6365,18 @@ var AthenaClientBuilderImpl = class {
6307
6365
  this.defaultHeaders = headers;
6308
6366
  return this;
6309
6367
  }
6368
+ pgUri(pgUri) {
6369
+ this.pgUriValue = pgUri;
6370
+ return this;
6371
+ }
6372
+ jdbcUrl(jdbcUrl) {
6373
+ this.jdbcUrlValue = jdbcUrl;
6374
+ return this;
6375
+ }
6376
+ athenaKey(athenaKey) {
6377
+ this.athenaKeyValue = athenaKey;
6378
+ return this;
6379
+ }
6310
6380
  auth(config) {
6311
6381
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
6312
6382
  return this;
@@ -6343,6 +6413,15 @@ var AthenaClientBuilderImpl = class {
6343
6413
  if (options.headers !== void 0) {
6344
6414
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
6345
6415
  }
6416
+ if (options.pgUri !== void 0) {
6417
+ this.pgUriValue = options.pgUri;
6418
+ }
6419
+ if (options.jdbcUrl !== void 0) {
6420
+ this.jdbcUrlValue = options.jdbcUrl;
6421
+ }
6422
+ if (options.athenaKey !== void 0) {
6423
+ this.athenaKeyValue = options.athenaKey;
6424
+ }
6346
6425
  if (options.auth !== void 0) {
6347
6426
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
6348
6427
  }
@@ -6394,6 +6473,9 @@ var AthenaClientBuilderImpl = class {
6394
6473
  userId: this.defaultUserId,
6395
6474
  organizationId: this.defaultOrganizationId,
6396
6475
  forceNoCache: this.forceNoCacheEnabled,
6476
+ pgUri: this.pgUriValue,
6477
+ jdbcUrl: this.jdbcUrlValue,
6478
+ athenaKey: this.athenaKeyValue,
6397
6479
  backend: this.backendConfig,
6398
6480
  headers: this.defaultHeaders,
6399
6481
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -9106,10 +9188,6 @@ function resolveRequiredClientApiKey(value) {
9106
9188
  }
9107
9189
  return normalizedValue;
9108
9190
  }
9109
- function hasHeaderIgnoreCase(headers, targetKey) {
9110
- const normalizedTargetKey = targetKey.toLowerCase();
9111
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9112
- }
9113
9191
  function mergeClientHeaders(current, next) {
9114
9192
  if (!current && !next) {
9115
9193
  return void 0;
@@ -9240,6 +9318,9 @@ function resolveCreateClientConfig(config) {
9240
9318
  userId: config.userId,
9241
9319
  organizationId: config.organizationId,
9242
9320
  forceNoCache: config.forceNoCache,
9321
+ pgUri: config.pgUri,
9322
+ jdbcUrl: config.jdbcUrl,
9323
+ athenaKey: config.athenaKey,
9243
9324
  backend: toBackendConfig(config.backend),
9244
9325
  headers: config.headers,
9245
9326
  auth: config.auth,
@@ -9256,18 +9337,6 @@ function createClientFromInput(sourceConfig) {
9256
9337
  }
9257
9338
  function createClientFromConfig(config, sourceConfig) {
9258
9339
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
9259
- const gatewayHeaders = {
9260
- ...config.headers ?? {}
9261
- };
9262
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
9263
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9264
- }
9265
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
9266
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
9267
- }
9268
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
9269
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9270
- }
9271
9340
  const gateway = createAthenaGatewayClient({
9272
9341
  baseUrl: config.baseUrl,
9273
9342
  apiKey: config.apiKey,
@@ -9275,8 +9344,14 @@ function createClientFromConfig(config, sourceConfig) {
9275
9344
  userId: config.userId,
9276
9345
  organizationId: config.organizationId,
9277
9346
  forceNoCache: config.forceNoCache,
9347
+ pgUri: config.pgUri,
9348
+ jdbcUrl: config.jdbcUrl,
9349
+ athenaKey: config.athenaKey,
9278
9350
  backend: config.backend,
9279
- headers: gatewayHeaders
9351
+ bearerToken: normalizedAuthConfig?.bearerToken,
9352
+ cookie: normalizedAuthConfig?.cookie,
9353
+ sessionToken: normalizedAuthConfig?.sessionToken,
9354
+ headers: config.headers
9280
9355
  });
9281
9356
  const formatGatewayResult = createResultFormatter(config.experimental);
9282
9357
  const queryTracer = createQueryTracer(config.experimental);
@@ -9334,6 +9409,7 @@ function createClientFromConfig(config, sourceConfig) {
9334
9409
  const chat = createChatModule({
9335
9410
  baseUrl: config.chatUrl,
9336
9411
  apiKey: config.apiKey,
9412
+ athenaKey: config.athenaKey,
9337
9413
  client: config.client,
9338
9414
  headers: config.headers,
9339
9415
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9370,48 +9446,28 @@ function createClientFromConfig(config, sourceConfig) {
9370
9446
  return path.startsWith("/") ? path : `/${path}`;
9371
9447
  })();
9372
9448
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
9373
- const headers = {
9374
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
9375
- ...config.headers ?? {},
9376
- ...options.headers ?? {}
9377
- };
9378
- if (service !== "auth") {
9379
- headers.apikey = headers.apikey ?? config.apiKey;
9380
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
9381
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
9382
- headers["X-Athena-Client"] = config.client;
9383
- }
9384
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
9385
- headers["X-User-Id"] = config.userId;
9386
- }
9387
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
9388
- headers["X-Organization-Id"] = config.organizationId;
9389
- }
9390
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9391
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9392
- }
9393
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
9394
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9395
- }
9396
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9397
- headers.Cookie = normalizedAuthConfig.cookie;
9398
- }
9399
- } else {
9400
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
9401
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
9402
- headers.apikey = headers.apikey ?? authApiKey;
9403
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
9404
- }
9405
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
9406
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
9407
- }
9408
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9409
- headers.Cookie = normalizedAuthConfig.cookie;
9410
- }
9411
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9412
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9413
- }
9414
- }
9449
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
9450
+ const headers = buildAthenaRequestHeaders({
9451
+ profile: requestProfile,
9452
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
9453
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
9454
+ athenaKey: options.athenaKey ?? config.athenaKey,
9455
+ client: config.client,
9456
+ userId: config.userId,
9457
+ organizationId: config.organizationId,
9458
+ backend: config.backend,
9459
+ pgUri: config.pgUri,
9460
+ jdbcUrl: config.jdbcUrl,
9461
+ bearerToken: normalizedAuthConfig?.bearerToken,
9462
+ cookie: normalizedAuthConfig?.cookie,
9463
+ sessionToken: normalizedAuthConfig?.sessionToken,
9464
+ forceNoCache: config.forceNoCache,
9465
+ configHeaders: config.headers,
9466
+ callHeaders: options.headers,
9467
+ accept: service === "chat" ? "application/json" : void 0,
9468
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
9469
+ stripNulls: service === "db" ? true : void 0
9470
+ });
9415
9471
  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";
9416
9472
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9417
9473
  headers["Content-Type"] = "application/json";