@xylex-group/athena 2.11.0 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +299 -240
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.cts +9 -8
  5. package/dist/browser.d.ts +9 -8
  6. package/dist/browser.js +299 -240
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +272 -240
  9. package/dist/cli/index.cjs.map +1 -1
  10. package/dist/cli/index.d.cts +4 -3
  11. package/dist/cli/index.d.ts +4 -3
  12. package/dist/cli/index.js +272 -240
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/{client-DD_UeF3Q.d.ts → client-CMtx5P4D.d.cts} +20 -9
  15. package/dist/{client-WqBuu60O.d.cts → client-Dre8H24u.d.ts} +20 -9
  16. package/dist/index.cjs +299 -240
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +9 -8
  19. package/dist/index.d.ts +9 -8
  20. package/dist/index.js +299 -240
  21. package/dist/index.js.map +1 -1
  22. package/dist/{model-form-ByvyyvxB.d.ts → model-form-CU0mWrF9.d.ts} +2 -1
  23. package/dist/{model-form-DACdBLYG.d.cts → model-form-DfTi8-D1.d.cts} +2 -1
  24. package/dist/{module-DRkIHtY-.d.ts → module-DBGmbIuh.d.ts} +5 -4
  25. package/dist/{module-BFMyVmwX.d.cts → module-GoijrBXV.d.cts} +5 -4
  26. package/dist/next/client.cjs +299 -240
  27. package/dist/next/client.cjs.map +1 -1
  28. package/dist/next/client.d.cts +4 -3
  29. package/dist/next/client.d.ts +4 -3
  30. package/dist/next/client.js +299 -240
  31. package/dist/next/client.js.map +1 -1
  32. package/dist/next/server.cjs +299 -240
  33. package/dist/next/server.cjs.map +1 -1
  34. package/dist/next/server.d.cts +4 -3
  35. package/dist/next/server.d.ts +4 -3
  36. package/dist/next/server.js +299 -240
  37. package/dist/next/server.js.map +1 -1
  38. package/dist/{pipeline-DZMsPxUg.d.ts → pipeline-DrjU2vNA.d.ts} +1 -1
  39. package/dist/{pipeline-CmUZsXsi.d.cts → pipeline-c7Gdm0qv.d.cts} +1 -1
  40. package/dist/react.cjs +237 -98
  41. package/dist/react.cjs.map +1 -1
  42. package/dist/react.d.cts +5 -4
  43. package/dist/react.d.ts +5 -4
  44. package/dist/react.js +237 -98
  45. package/dist/react.js.map +1 -1
  46. package/dist/{shared-B1ueL-Ox.d.cts → shared-DZSGAmXs.d.cts} +2 -2
  47. package/dist/{shared-GPAprhBb.d.ts → shared-MMnVBBfy.d.ts} +2 -2
  48. package/dist/{types-CRjDwmtJ.d.ts → types-BLizCLd1.d.cts} +2 -1
  49. package/dist/types-BRUHGXo2.d.cts +236 -0
  50. package/dist/types-BRUHGXo2.d.ts +236 -0
  51. package/dist/types-Bez4HSbI.d.cts +204 -0
  52. package/dist/{types-C-YvfgYh.d.cts → types-DRRb0Fd0.d.ts} +2 -1
  53. package/dist/types-kPaHUqUa.d.ts +204 -0
  54. package/dist/utils.cjs +279 -0
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +58 -1
  57. package/dist/utils.d.ts +58 -1
  58. package/dist/utils.js +272 -1
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +1 -1
  61. package/dist/types-BeZIHduP.d.cts +0 -428
  62. package/dist/types-BeZIHduP.d.ts +0 -428
package/dist/index.cjs CHANGED
@@ -804,42 +804,31 @@ var getCookieCache = async (request2, config) => {
804
804
  };
805
805
  };
806
806
 
807
- // package.json
808
- var package_default = {
809
- version: "2.11.0"
810
- };
811
-
812
- // src/sdk-version.ts
813
- var PACKAGE_VERSION = package_default.version;
814
- function buildSdkHeaderValue(sdkName) {
815
- return `${sdkName} ${PACKAGE_VERSION}`;
816
- }
817
-
818
- // src/gateway/client.ts
819
- var DEFAULT_CLIENT = "railway_direct";
820
- var SDK_NAME = "xylex-group/athena";
821
- var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
807
+ // src/utils/athena-request-headers.ts
822
808
  var NO_CACHE_HEADER_VALUE = "no-cache";
823
- function parseResponseBody(rawText, contentType) {
824
- if (!rawText) {
825
- return { parsed: null, parseFailed: false };
826
- }
827
- const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
828
- const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
829
- if (!looksJson) {
830
- return { parsed: rawText, parseFailed: false };
831
- }
832
- try {
833
- return { parsed: JSON.parse(rawText), parseFailed: false };
834
- } catch {
835
- return { parsed: rawText, parseFailed: true };
836
- }
837
- }
809
+ var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
810
+ var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
811
+ var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
812
+ var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
813
+ var CLIENT_HEADER_CANDIDATES = ["X-Athena-Client", "x-athena-client"];
814
+ var PG_URI_HEADER_CANDIDATES = ["x-pg-uri"];
815
+ var JDBC_URI_HEADER_CANDIDATES = ["x-athena-jdbc-url", "x-jdbc-url"];
816
+ var PROFILE_RULES = {
817
+ gateway: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true, stripNullsDefault: true },
818
+ chat: { apiKeys: true, routing: true, authMirror: true, authBearer: true, accept: true },
819
+ storage: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true },
820
+ auth: { apiKeys: true, routing: false, authMirror: false, authBearer: true, contentType: true },
821
+ minimal: { apiKeys: false, routing: false, authMirror: false, authBearer: false }
822
+ };
838
823
  function normalizeHeaderValue(value) {
839
824
  return value ? value : void 0;
840
825
  }
841
- function isCacheControlHeaderName(name) {
842
- return name.toLowerCase() === "cache-control";
826
+ function mergeExtraHeaders(configHeaders, callHeaders) {
827
+ return { ...configHeaders ?? {}, ...callHeaders ?? {} };
828
+ }
829
+ function hasHeaderIgnoreCase(headers, targetKey) {
830
+ const normalizedTargetKey = targetKey.toLowerCase();
831
+ return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
843
832
  }
844
833
  function resolveHeaderValue(headers, candidates) {
845
834
  for (const candidate of candidates) {
@@ -856,13 +845,20 @@ function resolveHeaderValue(headers, candidates) {
856
845
  }
857
846
  return void 0;
858
847
  }
848
+ function isCacheControlHeaderName(name) {
849
+ return name.toLowerCase() === "cache-control";
850
+ }
851
+ function normalizeBearerToken(value) {
852
+ const trimmed = value.trim();
853
+ const match = trimmed.match(/^Bearer\s+(.+)$/i);
854
+ return match?.[1]?.trim() ?? trimmed;
855
+ }
859
856
  function resolveBearerTokenFromAuthorizationHeader(headers) {
860
857
  const authorization = resolveHeaderValue(headers, ["Authorization"]);
861
858
  if (!authorization) {
862
859
  return void 0;
863
860
  }
864
- const match = authorization.match(/^Bearer\s+(.+)$/i);
865
- const token = match?.[1]?.trim();
861
+ const token = normalizeBearerToken(authorization);
866
862
  return token ? token : void 0;
867
863
  }
868
864
  function resolveSessionTokenFromCookieHeader(headers) {
@@ -872,6 +868,210 @@ function resolveSessionTokenFromCookieHeader(headers) {
872
868
  }
873
869
  return getSessionCookie(new Headers({ cookie })) ?? void 0;
874
870
  }
871
+ function resolveBackendType(backend) {
872
+ if (!backend) {
873
+ return void 0;
874
+ }
875
+ return typeof backend === "string" ? backend : backend.type;
876
+ }
877
+ function resolveRequestHeaderOverrides(config, options, defaults) {
878
+ return {
879
+ apiKey: options?.apiKey ?? config.apiKey,
880
+ athenaKey: options?.athenaKey ?? config.athenaKey,
881
+ client: options?.client ?? config.client ?? defaults?.client,
882
+ userId: options?.userId ?? config.userId,
883
+ organizationId: options?.organizationId ?? config.organizationId,
884
+ backend: options?.backend ?? config.backend,
885
+ publishEvent: options?.publishEvent ?? config.publishEvent,
886
+ stripNulls: options?.stripNulls ?? config.stripNulls ?? defaults?.stripNulls,
887
+ bearerToken: options?.bearerToken ?? config.bearerToken,
888
+ cookie: options?.cookie ?? config.cookie,
889
+ sessionToken: options?.sessionToken ?? config.sessionToken,
890
+ pgUri: options?.pgUri ?? config.pgUri,
891
+ jdbcUrl: options?.jdbcUrl ?? config.jdbcUrl,
892
+ forceNoCache: Boolean(config.forceNoCache || options?.forceNoCache),
893
+ configHeaders: config.headers,
894
+ callHeaders: options?.headers
895
+ };
896
+ }
897
+ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, extras) {
898
+ const rules = PROFILE_RULES[profile];
899
+ return buildAthenaRequestHeaders({
900
+ profile,
901
+ sdkHeaderValue,
902
+ ...resolveRequestHeaderOverrides(config, options, {
903
+ client: extras?.client ?? void 0,
904
+ stripNulls: extras?.stripNulls ?? (rules.stripNullsDefault ? true : void 0)
905
+ }),
906
+ contentType: extras?.contentType ?? (rules.contentType ? "application/json" : void 0),
907
+ accept: extras?.accept ?? (rules.accept ? "application/json" : void 0)
908
+ });
909
+ }
910
+ function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
911
+ if (apiKey) {
912
+ if (!hasHeaderIgnoreCase(headers, "apikey")) {
913
+ headers.apikey = apiKey;
914
+ }
915
+ if (!Object.hasOwn(headers, "x-api-key")) {
916
+ headers["x-api-key"] = apiKey;
917
+ }
918
+ if (!Object.hasOwn(headers, "X-Api-Key")) {
919
+ headers["X-Api-Key"] = apiKey;
920
+ }
921
+ }
922
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
923
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
924
+ headers["X-Athena-Key"] = resolvedAthenaKey;
925
+ }
926
+ }
927
+ function applyAthenaAuthContextHeaders(headers, input) {
928
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
929
+ const rules = PROFILE_RULES[input.profile];
930
+ const explicitCookie = normalizeHeaderValue(input.cookie);
931
+ if (explicitCookie) {
932
+ mergedExtraHeaders.Cookie = explicitCookie;
933
+ }
934
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
935
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
936
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
937
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
938
+ headers.Cookie = explicitCookie;
939
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
940
+ headers.Cookie = cookieFromHeaders;
941
+ }
942
+ const explicitBearerToken = (() => {
943
+ const configured = normalizeHeaderValue(input.bearerToken);
944
+ if (configured) {
945
+ return normalizeBearerToken(configured);
946
+ }
947
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
948
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
949
+ })();
950
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
951
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
952
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
953
+ }
954
+ if (rules.authMirror) {
955
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
956
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
957
+ }
958
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
959
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
960
+ }
961
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
962
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
963
+ }
964
+ }
965
+ function applyAthenaPgUriHeaders(headers, input) {
966
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
967
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
968
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
969
+ headers["x-pg-uri"] = pgUri;
970
+ }
971
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
972
+ if (jdbcUrl) {
973
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
974
+ headers["x-athena-jdbc-url"] = jdbcUrl;
975
+ }
976
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
977
+ headers["x-jdbc-url"] = jdbcUrl;
978
+ }
979
+ }
980
+ }
981
+ function buildAthenaRequestHeaders(input) {
982
+ const forceNoCache = Boolean(input.forceNoCache);
983
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
984
+ const rules = PROFILE_RULES[input.profile];
985
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
986
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
987
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
988
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
989
+ const headers = {
990
+ "X-Athena-Sdk": input.sdkHeaderValue
991
+ };
992
+ if (rules.contentType) {
993
+ headers["Content-Type"] = input.contentType ?? "application/json";
994
+ }
995
+ if (input.accept ?? rules.accept) {
996
+ headers.Accept = input.accept ?? "application/json";
997
+ }
998
+ if (rules.routing) {
999
+ if (normalizeHeaderValue(input.userId)) {
1000
+ headers["X-User-Id"] = input.userId ?? "";
1001
+ }
1002
+ if (normalizeHeaderValue(input.organizationId)) {
1003
+ headers["X-Organization-Id"] = input.organizationId ?? "";
1004
+ }
1005
+ if (finalClient) {
1006
+ headers["X-Athena-Client"] = finalClient;
1007
+ }
1008
+ const backendType = resolveBackendType(input.backend);
1009
+ if (backendType) {
1010
+ headers["X-Backend-Type"] = backendType;
1011
+ }
1012
+ if (typeof input.stripNulls === "boolean") {
1013
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
1014
+ } else if (rules.stripNullsDefault) {
1015
+ headers["X-Strip-Nulls"] = "true";
1016
+ }
1017
+ if (normalizeHeaderValue(input.publishEvent)) {
1018
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
1019
+ }
1020
+ }
1021
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
1022
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
1023
+ }
1024
+ applyAthenaAuthContextHeaders(headers, input);
1025
+ applyAthenaPgUriHeaders(headers, input);
1026
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
1027
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1028
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
1029
+ return;
1030
+ }
1031
+ if (forceNoCache && isCacheControlHeaderName(key)) {
1032
+ return;
1033
+ }
1034
+ const normalized = normalizeHeaderValue(value);
1035
+ if (normalized) {
1036
+ headers[key] = normalized;
1037
+ }
1038
+ });
1039
+ if (forceNoCache) {
1040
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1041
+ }
1042
+ return headers;
1043
+ }
1044
+
1045
+ // package.json
1046
+ var package_default = {
1047
+ version: "2.12.1"
1048
+ };
1049
+
1050
+ // src/sdk-version.ts
1051
+ var PACKAGE_VERSION = package_default.version;
1052
+ function buildSdkHeaderValue(sdkName) {
1053
+ return `${sdkName} ${PACKAGE_VERSION}`;
1054
+ }
1055
+
1056
+ // src/gateway/client.ts
1057
+ var DEFAULT_CLIENT = "railway_direct";
1058
+ var SDK_NAME = "xylex-group/athena";
1059
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
1060
+ function parseResponseBody(rawText, contentType) {
1061
+ if (!rawText) {
1062
+ return { parsed: null, parseFailed: false };
1063
+ }
1064
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
1065
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
1066
+ if (!looksJson) {
1067
+ return { parsed: rawText, parseFailed: false };
1068
+ }
1069
+ try {
1070
+ return { parsed: JSON.parse(rawText), parseFailed: false };
1071
+ } catch {
1072
+ return { parsed: rawText, parseFailed: true };
1073
+ }
1074
+ }
875
1075
  function isRecord(value) {
876
1076
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
877
1077
  }
@@ -998,71 +1198,10 @@ function buildRpcGetEndpoint(payload) {
998
1198
  return withQuery;
999
1199
  }
1000
1200
  function buildHeaders(config, options) {
1001
- const mergedStripNulls = options?.stripNulls ?? true;
1002
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1003
- const extraHeaders = {
1004
- ...config.headers ?? {},
1005
- ...options?.headers ?? {}
1006
- };
1007
- const headerClient = extraHeaders["x-athena-client"] ?? extraHeaders["X-Athena-Client"];
1008
- const finalClient = options?.client ?? config.client ?? (typeof headerClient === "string" ? headerClient : void 0) ?? DEFAULT_CLIENT;
1009
- const finalApiKey = options?.apiKey ?? config.apiKey;
1010
- const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
1011
- const headers = {
1012
- "Content-Type": "application/json",
1013
- "X-Athena-Sdk": SDK_HEADER_VALUE
1014
- };
1015
- if (options?.userId ?? config.userId) {
1016
- headers["X-User-Id"] = options?.userId ?? config.userId ?? "";
1017
- }
1018
- if (options?.organizationId ?? config.organizationId) {
1019
- headers["X-Organization-Id"] = options?.organizationId ?? config.organizationId ?? "";
1020
- }
1021
- if (finalClient) {
1022
- headers["X-Athena-Client"] = finalClient;
1023
- }
1024
- const finalBackend = options?.backend ?? config.backend;
1025
- if (finalBackend) {
1026
- const type = typeof finalBackend === "string" ? finalBackend : finalBackend.type;
1027
- if (type) headers["X-Backend-Type"] = type;
1028
- }
1029
- if (typeof mergedStripNulls === "boolean") {
1030
- headers["X-Strip-Nulls"] = mergedStripNulls ? "true" : "false";
1031
- }
1032
- if (finalPublishEvent) {
1033
- headers["X-Publish-Event"] = finalPublishEvent;
1034
- }
1035
- if (finalApiKey) {
1036
- headers["apikey"] = finalApiKey;
1037
- headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
1038
- }
1039
- const explicitSessionToken = resolveHeaderValue(extraHeaders, [
1040
- "X-Athena-Auth-Session-Token"
1041
- ]);
1042
- const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(extraHeaders);
1043
- if (derivedSessionToken) {
1044
- headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
1045
- }
1046
- const explicitBearerToken = resolveHeaderValue(extraHeaders, [
1047
- "X-Athena-Auth-Bearer-Token"
1048
- ]);
1049
- const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(extraHeaders);
1050
- if (derivedBearerToken) {
1051
- headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
1052
- }
1053
- const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
1054
- Object.entries(extraHeaders).forEach(([key, value]) => {
1055
- if (athenaClientKeys.includes(key)) return;
1056
- if (forceNoCache && isCacheControlHeaderName(key)) return;
1057
- const normalized = normalizeHeaderValue(value);
1058
- if (normalized) {
1059
- headers[key] = normalized;
1060
- }
1201
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
1202
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
1203
+ stripNulls: options?.stripNulls ?? true
1061
1204
  });
1062
- if (forceNoCache) {
1063
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1064
- }
1065
- return headers;
1066
1205
  }
1067
1206
  function toInvalidUrlResponse(error, endpoint, method) {
1068
1207
  const message = error instanceof Error ? error.message : String(error);
@@ -1790,19 +1929,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
1790
1929
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
1791
1930
  var SDK_NAME2 = "xylex-group/athena-auth";
1792
1931
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
1793
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
1794
1932
  function normalizeBaseUrl(baseUrl) {
1795
1933
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
1796
1934
  }
1797
1935
  function isRecord3(value) {
1798
1936
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1799
1937
  }
1800
- function normalizeHeaderValue2(value) {
1801
- return value ? value : void 0;
1802
- }
1803
- function isCacheControlHeaderName2(name) {
1804
- return name.toLowerCase() === "cache-control";
1805
- }
1806
1938
  function parseResponseBody2(rawText, contentType) {
1807
1939
  if (!rawText) {
1808
1940
  return { parsed: null, parseFailed: false };
@@ -2002,45 +2134,7 @@ function extractFetchOptions(input) {
2002
2134
  };
2003
2135
  }
2004
2136
  function buildHeaders2(config, options) {
2005
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
2006
- const headers = {
2007
- "Content-Type": "application/json",
2008
- "X-Athena-Sdk": SDK_HEADER_VALUE2
2009
- };
2010
- const apiKey = options?.apiKey ?? config.apiKey;
2011
- if (apiKey) {
2012
- headers.apikey = apiKey;
2013
- headers["x-api-key"] = apiKey;
2014
- }
2015
- const bearerToken = options?.bearerToken ?? config.bearerToken;
2016
- if (bearerToken) {
2017
- headers.Authorization = `Bearer ${bearerToken}`;
2018
- }
2019
- const cookie = options?.cookie ?? config.cookie;
2020
- if (cookie) {
2021
- headers.Cookie = cookie;
2022
- }
2023
- const sessionToken = options?.sessionToken ?? config.sessionToken;
2024
- if (sessionToken) {
2025
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
2026
- }
2027
- const mergedExtraHeaders = {
2028
- ...config.headers ?? {},
2029
- ...options?.headers ?? {}
2030
- };
2031
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
2032
- if (forceNoCache && isCacheControlHeaderName2(key)) {
2033
- return;
2034
- }
2035
- const normalized = normalizeHeaderValue2(value);
2036
- if (normalized) {
2037
- headers[key] = normalized;
2038
- }
2039
- });
2040
- if (forceNoCache) {
2041
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
2042
- }
2043
- return headers;
2137
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
2044
2138
  }
2045
2139
  function appendQueryParam(searchParams, key, value) {
2046
2140
  if (value === void 0 || value === null) return;
@@ -5719,7 +5813,6 @@ function createStorageModule(gateway, runtimeOptions) {
5719
5813
  // src/chat/module.ts
5720
5814
  var SDK_NAME3 = "xylex-group/athena-chat";
5721
5815
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
5722
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
5723
5816
  var AthenaChatError = class extends Error {
5724
5817
  status;
5725
5818
  endpoint;
@@ -5765,9 +5858,6 @@ function normalizeWsUrl(value, label) {
5765
5858
  function isRecord7(value) {
5766
5859
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5767
5860
  }
5768
- function normalizeHeaderValue3(value) {
5769
- return value ? value : void 0;
5770
- }
5771
5861
  function parseResponseBody4(rawText, contentType) {
5772
5862
  if (!rawText) {
5773
5863
  return { parsed: null, parseFailed: false };
@@ -5839,39 +5929,7 @@ function createSocket(factory, url, protocols) {
5839
5929
  }
5840
5930
  }
5841
5931
  function buildHeaders3(config, options) {
5842
- const headers = {
5843
- Accept: "application/json",
5844
- apikey: config.apiKey,
5845
- "x-api-key": config.apiKey,
5846
- "X-Athena-Sdk": SDK_HEADER_VALUE3
5847
- };
5848
- if (config.client || options?.client) {
5849
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
5850
- }
5851
- const bearerToken = options?.bearerToken ?? config.bearerToken;
5852
- if (typeof bearerToken === "string" && bearerToken.trim()) {
5853
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
5854
- }
5855
- const cookie = options?.cookie ?? config.cookie;
5856
- if (typeof cookie === "string" && cookie.trim()) {
5857
- headers.Cookie = cookie;
5858
- }
5859
- const sessionToken = options?.sessionToken ?? config.sessionToken;
5860
- if (typeof sessionToken === "string" && sessionToken.trim()) {
5861
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
5862
- }
5863
- if (config.forceNoCache || options?.forceNoCache) {
5864
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
5865
- }
5866
- for (const source of [config.headers, options?.headers]) {
5867
- for (const [key, value] of Object.entries(source ?? {})) {
5868
- const normalized = normalizeHeaderValue3(value);
5869
- if (normalized) {
5870
- headers[key] = normalized;
5871
- }
5872
- }
5873
- }
5874
- return headers;
5932
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
5875
5933
  }
5876
5934
  function withJsonBody(init, body) {
5877
5935
  return {
@@ -6283,6 +6341,9 @@ var AthenaClientBuilderImpl = class {
6283
6341
  defaultOrganizationId;
6284
6342
  forceNoCacheEnabled = false;
6285
6343
  defaultHeaders;
6344
+ pgUriValue;
6345
+ jdbcUrlValue;
6346
+ athenaKeyValue;
6286
6347
  authConfig;
6287
6348
  dbUrlOverride;
6288
6349
  gatewayUrlOverride;
@@ -6309,6 +6370,18 @@ var AthenaClientBuilderImpl = class {
6309
6370
  this.defaultHeaders = headers;
6310
6371
  return this;
6311
6372
  }
6373
+ pgUri(pgUri) {
6374
+ this.pgUriValue = pgUri;
6375
+ return this;
6376
+ }
6377
+ jdbcUrl(jdbcUrl) {
6378
+ this.jdbcUrlValue = jdbcUrl;
6379
+ return this;
6380
+ }
6381
+ athenaKey(athenaKey) {
6382
+ this.athenaKeyValue = athenaKey;
6383
+ return this;
6384
+ }
6312
6385
  auth(config) {
6313
6386
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
6314
6387
  return this;
@@ -6345,6 +6418,15 @@ var AthenaClientBuilderImpl = class {
6345
6418
  if (options.headers !== void 0) {
6346
6419
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
6347
6420
  }
6421
+ if (options.pgUri !== void 0) {
6422
+ this.pgUriValue = options.pgUri;
6423
+ }
6424
+ if (options.jdbcUrl !== void 0) {
6425
+ this.jdbcUrlValue = options.jdbcUrl;
6426
+ }
6427
+ if (options.athenaKey !== void 0) {
6428
+ this.athenaKeyValue = options.athenaKey;
6429
+ }
6348
6430
  if (options.auth !== void 0) {
6349
6431
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
6350
6432
  }
@@ -6396,6 +6478,9 @@ var AthenaClientBuilderImpl = class {
6396
6478
  userId: this.defaultUserId,
6397
6479
  organizationId: this.defaultOrganizationId,
6398
6480
  forceNoCache: this.forceNoCacheEnabled,
6481
+ pgUri: this.pgUriValue,
6482
+ jdbcUrl: this.jdbcUrlValue,
6483
+ athenaKey: this.athenaKeyValue,
6399
6484
  backend: this.backendConfig,
6400
6485
  headers: this.defaultHeaders,
6401
6486
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -9108,10 +9193,6 @@ function resolveRequiredClientApiKey(value) {
9108
9193
  }
9109
9194
  return normalizedValue;
9110
9195
  }
9111
- function hasHeaderIgnoreCase(headers, targetKey) {
9112
- const normalizedTargetKey = targetKey.toLowerCase();
9113
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9114
- }
9115
9196
  function mergeClientHeaders(current, next) {
9116
9197
  if (!current && !next) {
9117
9198
  return void 0;
@@ -9242,6 +9323,9 @@ function resolveCreateClientConfig(config) {
9242
9323
  userId: config.userId,
9243
9324
  organizationId: config.organizationId,
9244
9325
  forceNoCache: config.forceNoCache,
9326
+ pgUri: config.pgUri,
9327
+ jdbcUrl: config.jdbcUrl,
9328
+ athenaKey: config.athenaKey,
9245
9329
  backend: toBackendConfig(config.backend),
9246
9330
  headers: config.headers,
9247
9331
  auth: config.auth,
@@ -9258,18 +9342,6 @@ function createClientFromInput(sourceConfig) {
9258
9342
  }
9259
9343
  function createClientFromConfig(config, sourceConfig) {
9260
9344
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
9261
- const gatewayHeaders = {
9262
- ...config.headers ?? {}
9263
- };
9264
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
9265
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9266
- }
9267
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
9268
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
9269
- }
9270
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
9271
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9272
- }
9273
9345
  const gateway = createAthenaGatewayClient({
9274
9346
  baseUrl: config.baseUrl,
9275
9347
  apiKey: config.apiKey,
@@ -9277,8 +9349,14 @@ function createClientFromConfig(config, sourceConfig) {
9277
9349
  userId: config.userId,
9278
9350
  organizationId: config.organizationId,
9279
9351
  forceNoCache: config.forceNoCache,
9352
+ pgUri: config.pgUri,
9353
+ jdbcUrl: config.jdbcUrl,
9354
+ athenaKey: config.athenaKey,
9280
9355
  backend: config.backend,
9281
- headers: gatewayHeaders
9356
+ bearerToken: normalizedAuthConfig?.bearerToken,
9357
+ cookie: normalizedAuthConfig?.cookie,
9358
+ sessionToken: normalizedAuthConfig?.sessionToken,
9359
+ headers: config.headers
9282
9360
  });
9283
9361
  const formatGatewayResult = createResultFormatter(config.experimental);
9284
9362
  const queryTracer = createQueryTracer(config.experimental);
@@ -9336,6 +9414,7 @@ function createClientFromConfig(config, sourceConfig) {
9336
9414
  const chat = createChatModule({
9337
9415
  baseUrl: config.chatUrl,
9338
9416
  apiKey: config.apiKey,
9417
+ athenaKey: config.athenaKey,
9339
9418
  client: config.client,
9340
9419
  headers: config.headers,
9341
9420
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9372,48 +9451,28 @@ function createClientFromConfig(config, sourceConfig) {
9372
9451
  return path.startsWith("/") ? path : `/${path}`;
9373
9452
  })();
9374
9453
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
9375
- const headers = {
9376
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
9377
- ...config.headers ?? {},
9378
- ...options.headers ?? {}
9379
- };
9380
- if (service !== "auth") {
9381
- headers.apikey = headers.apikey ?? config.apiKey;
9382
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
9383
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
9384
- headers["X-Athena-Client"] = config.client;
9385
- }
9386
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
9387
- headers["X-User-Id"] = config.userId;
9388
- }
9389
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
9390
- headers["X-Organization-Id"] = config.organizationId;
9391
- }
9392
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9393
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9394
- }
9395
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
9396
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9397
- }
9398
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9399
- headers.Cookie = normalizedAuthConfig.cookie;
9400
- }
9401
- } else {
9402
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
9403
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
9404
- headers.apikey = headers.apikey ?? authApiKey;
9405
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
9406
- }
9407
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
9408
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
9409
- }
9410
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9411
- headers.Cookie = normalizedAuthConfig.cookie;
9412
- }
9413
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9414
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9415
- }
9416
- }
9454
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
9455
+ const headers = buildAthenaRequestHeaders({
9456
+ profile: requestProfile,
9457
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
9458
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
9459
+ athenaKey: options.athenaKey ?? config.athenaKey,
9460
+ client: config.client,
9461
+ userId: config.userId,
9462
+ organizationId: config.organizationId,
9463
+ backend: config.backend,
9464
+ pgUri: config.pgUri,
9465
+ jdbcUrl: config.jdbcUrl,
9466
+ bearerToken: normalizedAuthConfig?.bearerToken,
9467
+ cookie: normalizedAuthConfig?.cookie,
9468
+ sessionToken: normalizedAuthConfig?.sessionToken,
9469
+ forceNoCache: config.forceNoCache,
9470
+ configHeaders: config.headers,
9471
+ callHeaders: options.headers,
9472
+ accept: service === "chat" ? "application/json" : void 0,
9473
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
9474
+ stripNulls: service === "db" ? true : void 0
9475
+ });
9417
9476
  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";
9418
9477
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9419
9478
  headers["Content-Type"] = "application/json";