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