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