@xylex-group/athena 2.11.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +296 -240
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.cts +9 -8
  5. package/dist/browser.d.ts +9 -8
  6. package/dist/browser.js +296 -240
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +269 -240
  9. package/dist/cli/index.cjs.map +1 -1
  10. package/dist/cli/index.d.cts +4 -3
  11. package/dist/cli/index.d.ts +4 -3
  12. package/dist/cli/index.js +269 -240
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/{client-DD_UeF3Q.d.ts → client-C3x75Zgn.d.cts} +20 -9
  15. package/dist/{client-WqBuu60O.d.cts → client-QUbAs7E8.d.ts} +20 -9
  16. package/dist/index.cjs +296 -240
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +9 -8
  19. package/dist/index.d.ts +9 -8
  20. package/dist/index.js +296 -240
  21. package/dist/index.js.map +1 -1
  22. package/dist/{model-form-DACdBLYG.d.cts → model-form-CD1uhWSh.d.cts} +2 -1
  23. package/dist/{model-form-ByvyyvxB.d.ts → model-form-Dm69I-oO.d.ts} +2 -1
  24. package/dist/{module-DRkIHtY-.d.ts → module-CW3tWJ10.d.ts} +5 -4
  25. package/dist/{module-BFMyVmwX.d.cts → module-Cxcurfes.d.cts} +5 -4
  26. package/dist/next/client.cjs +296 -240
  27. package/dist/next/client.cjs.map +1 -1
  28. package/dist/next/client.d.cts +4 -3
  29. package/dist/next/client.d.ts +4 -3
  30. package/dist/next/client.js +296 -240
  31. package/dist/next/client.js.map +1 -1
  32. package/dist/next/server.cjs +296 -240
  33. package/dist/next/server.cjs.map +1 -1
  34. package/dist/next/server.d.cts +4 -3
  35. package/dist/next/server.d.ts +4 -3
  36. package/dist/next/server.js +296 -240
  37. package/dist/next/server.js.map +1 -1
  38. package/dist/{pipeline-CmUZsXsi.d.cts → pipeline-B14jVK7J.d.cts} +1 -1
  39. package/dist/{pipeline-DZMsPxUg.d.ts → pipeline-BAwb6Vzm.d.ts} +1 -1
  40. package/dist/react.cjs +234 -98
  41. package/dist/react.cjs.map +1 -1
  42. package/dist/react.d.cts +5 -4
  43. package/dist/react.d.ts +5 -4
  44. package/dist/react.js +234 -98
  45. package/dist/react.js.map +1 -1
  46. package/dist/{shared-GPAprhBb.d.ts → shared-0Kdc74lu.d.ts} +2 -2
  47. package/dist/{shared-B1ueL-Ox.d.cts → shared-C0wVICRv.d.cts} +2 -2
  48. package/dist/{types-C-YvfgYh.d.cts → types-BcVmPBP-.d.ts} +2 -1
  49. package/dist/types-Cq4-NoB4.d.ts +204 -0
  50. package/dist/types-CwJCPpLD.d.cts +236 -0
  51. package/dist/types-CwJCPpLD.d.ts +236 -0
  52. package/dist/{types-CRjDwmtJ.d.ts → types-DMOoYnPS.d.cts} +2 -1
  53. package/dist/types-Dr849HD6.d.cts +204 -0
  54. package/dist/utils.cjs +276 -0
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +58 -1
  57. package/dist/utils.d.ts +58 -1
  58. package/dist/utils.js +269 -1
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +1 -1
  61. package/dist/types-BeZIHduP.d.cts +0 -428
  62. package/dist/types-BeZIHduP.d.ts +0 -428
package/dist/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", "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,207 @@ 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 (!hasHeaderIgnoreCase(headers, "x-api-key")) {
910
+ headers["x-api-key"] = apiKey;
911
+ }
912
+ }
913
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
914
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
915
+ headers["X-Athena-Key"] = resolvedAthenaKey;
916
+ }
917
+ }
918
+ function applyAthenaAuthContextHeaders(headers, input) {
919
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
920
+ const rules = PROFILE_RULES[input.profile];
921
+ const explicitCookie = normalizeHeaderValue(input.cookie);
922
+ if (explicitCookie) {
923
+ mergedExtraHeaders.Cookie = explicitCookie;
924
+ }
925
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
926
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
927
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
928
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
929
+ headers.Cookie = explicitCookie;
930
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
931
+ headers.Cookie = cookieFromHeaders;
932
+ }
933
+ const explicitBearerToken = (() => {
934
+ const configured = normalizeHeaderValue(input.bearerToken);
935
+ if (configured) {
936
+ return normalizeBearerToken(configured);
937
+ }
938
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
939
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
940
+ })();
941
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
942
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
943
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
944
+ }
945
+ if (rules.authMirror) {
946
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
947
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
948
+ }
949
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
950
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
951
+ }
952
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
953
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
954
+ }
955
+ }
956
+ function applyAthenaPgUriHeaders(headers, input) {
957
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
958
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
959
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
960
+ headers["x-pg-uri"] = pgUri;
961
+ }
962
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
963
+ if (jdbcUrl) {
964
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
965
+ headers["x-athena-jdbc-url"] = jdbcUrl;
966
+ }
967
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
968
+ headers["x-jdbc-url"] = jdbcUrl;
969
+ }
970
+ }
971
+ }
972
+ function buildAthenaRequestHeaders(input) {
973
+ const forceNoCache = Boolean(input.forceNoCache);
974
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
975
+ const rules = PROFILE_RULES[input.profile];
976
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
977
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
978
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
979
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
980
+ const headers = {
981
+ "X-Athena-Sdk": input.sdkHeaderValue
982
+ };
983
+ if (rules.contentType) {
984
+ headers["Content-Type"] = input.contentType ?? "application/json";
985
+ }
986
+ if (input.accept ?? rules.accept) {
987
+ headers.Accept = input.accept ?? "application/json";
988
+ }
989
+ if (rules.routing) {
990
+ if (normalizeHeaderValue(input.userId)) {
991
+ headers["X-User-Id"] = input.userId ?? "";
992
+ }
993
+ if (normalizeHeaderValue(input.organizationId)) {
994
+ headers["X-Organization-Id"] = input.organizationId ?? "";
995
+ }
996
+ if (finalClient) {
997
+ headers["X-Athena-Client"] = finalClient;
998
+ }
999
+ const backendType = resolveBackendType(input.backend);
1000
+ if (backendType) {
1001
+ headers["X-Backend-Type"] = backendType;
1002
+ }
1003
+ if (typeof input.stripNulls === "boolean") {
1004
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
1005
+ } else if (rules.stripNullsDefault) {
1006
+ headers["X-Strip-Nulls"] = "true";
1007
+ }
1008
+ if (normalizeHeaderValue(input.publishEvent)) {
1009
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
1010
+ }
1011
+ }
1012
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
1013
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
1014
+ }
1015
+ applyAthenaAuthContextHeaders(headers, input);
1016
+ applyAthenaPgUriHeaders(headers, input);
1017
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
1018
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1019
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
1020
+ return;
1021
+ }
1022
+ if (forceNoCache && isCacheControlHeaderName(key)) {
1023
+ return;
1024
+ }
1025
+ const normalized = normalizeHeaderValue(value);
1026
+ if (normalized) {
1027
+ headers[key] = normalized;
1028
+ }
1029
+ });
1030
+ if (forceNoCache) {
1031
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1032
+ }
1033
+ return headers;
1034
+ }
1035
+
1036
+ // package.json
1037
+ var package_default = {
1038
+ version: "2.12.0"
1039
+ };
1040
+
1041
+ // src/sdk-version.ts
1042
+ var PACKAGE_VERSION = package_default.version;
1043
+ function buildSdkHeaderValue(sdkName) {
1044
+ return `${sdkName} ${PACKAGE_VERSION}`;
1045
+ }
1046
+
1047
+ // src/gateway/client.ts
1048
+ var DEFAULT_CLIENT = "railway_direct";
1049
+ var SDK_NAME = "xylex-group/athena";
1050
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
1051
+ function parseResponseBody(rawText, contentType) {
1052
+ if (!rawText) {
1053
+ return { parsed: null, parseFailed: false };
1054
+ }
1055
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
1056
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
1057
+ if (!looksJson) {
1058
+ return { parsed: rawText, parseFailed: false };
1059
+ }
1060
+ try {
1061
+ return { parsed: JSON.parse(rawText), parseFailed: false };
1062
+ } catch {
1063
+ return { parsed: rawText, parseFailed: true };
1064
+ }
1065
+ }
869
1066
  function isRecord(value) {
870
1067
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
871
1068
  }
@@ -992,71 +1189,10 @@ function buildRpcGetEndpoint(payload) {
992
1189
  return withQuery;
993
1190
  }
994
1191
  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
- }
1192
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
1193
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
1194
+ stripNulls: options?.stripNulls ?? true
1055
1195
  });
1056
- if (forceNoCache) {
1057
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1058
- }
1059
- return headers;
1060
1196
  }
1061
1197
  function toInvalidUrlResponse(error, endpoint, method) {
1062
1198
  const message = error instanceof Error ? error.message : String(error);
@@ -1784,19 +1920,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
1784
1920
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
1785
1921
  var SDK_NAME2 = "xylex-group/athena-auth";
1786
1922
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
1787
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
1788
1923
  function normalizeBaseUrl(baseUrl) {
1789
1924
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
1790
1925
  }
1791
1926
  function isRecord3(value) {
1792
1927
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1793
1928
  }
1794
- function normalizeHeaderValue2(value) {
1795
- return value ? value : void 0;
1796
- }
1797
- function isCacheControlHeaderName2(name) {
1798
- return name.toLowerCase() === "cache-control";
1799
- }
1800
1929
  function parseResponseBody2(rawText, contentType) {
1801
1930
  if (!rawText) {
1802
1931
  return { parsed: null, parseFailed: false };
@@ -1996,45 +2125,7 @@ function extractFetchOptions(input) {
1996
2125
  };
1997
2126
  }
1998
2127
  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;
2128
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
2038
2129
  }
2039
2130
  function appendQueryParam(searchParams, key, value) {
2040
2131
  if (value === void 0 || value === null) return;
@@ -5713,7 +5804,6 @@ function createStorageModule(gateway, runtimeOptions) {
5713
5804
  // src/chat/module.ts
5714
5805
  var SDK_NAME3 = "xylex-group/athena-chat";
5715
5806
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
5716
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
5717
5807
  var AthenaChatError = class extends Error {
5718
5808
  status;
5719
5809
  endpoint;
@@ -5759,9 +5849,6 @@ function normalizeWsUrl(value, label) {
5759
5849
  function isRecord7(value) {
5760
5850
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5761
5851
  }
5762
- function normalizeHeaderValue3(value) {
5763
- return value ? value : void 0;
5764
- }
5765
5852
  function parseResponseBody4(rawText, contentType) {
5766
5853
  if (!rawText) {
5767
5854
  return { parsed: null, parseFailed: false };
@@ -5833,39 +5920,7 @@ function createSocket(factory, url, protocols) {
5833
5920
  }
5834
5921
  }
5835
5922
  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;
5923
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
5869
5924
  }
5870
5925
  function withJsonBody(init, body) {
5871
5926
  return {
@@ -6277,6 +6332,9 @@ var AthenaClientBuilderImpl = class {
6277
6332
  defaultOrganizationId;
6278
6333
  forceNoCacheEnabled = false;
6279
6334
  defaultHeaders;
6335
+ pgUriValue;
6336
+ jdbcUrlValue;
6337
+ athenaKeyValue;
6280
6338
  authConfig;
6281
6339
  dbUrlOverride;
6282
6340
  gatewayUrlOverride;
@@ -6303,6 +6361,18 @@ var AthenaClientBuilderImpl = class {
6303
6361
  this.defaultHeaders = headers;
6304
6362
  return this;
6305
6363
  }
6364
+ pgUri(pgUri) {
6365
+ this.pgUriValue = pgUri;
6366
+ return this;
6367
+ }
6368
+ jdbcUrl(jdbcUrl) {
6369
+ this.jdbcUrlValue = jdbcUrl;
6370
+ return this;
6371
+ }
6372
+ athenaKey(athenaKey) {
6373
+ this.athenaKeyValue = athenaKey;
6374
+ return this;
6375
+ }
6306
6376
  auth(config) {
6307
6377
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
6308
6378
  return this;
@@ -6339,6 +6409,15 @@ var AthenaClientBuilderImpl = class {
6339
6409
  if (options.headers !== void 0) {
6340
6410
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
6341
6411
  }
6412
+ if (options.pgUri !== void 0) {
6413
+ this.pgUriValue = options.pgUri;
6414
+ }
6415
+ if (options.jdbcUrl !== void 0) {
6416
+ this.jdbcUrlValue = options.jdbcUrl;
6417
+ }
6418
+ if (options.athenaKey !== void 0) {
6419
+ this.athenaKeyValue = options.athenaKey;
6420
+ }
6342
6421
  if (options.auth !== void 0) {
6343
6422
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
6344
6423
  }
@@ -6390,6 +6469,9 @@ var AthenaClientBuilderImpl = class {
6390
6469
  userId: this.defaultUserId,
6391
6470
  organizationId: this.defaultOrganizationId,
6392
6471
  forceNoCache: this.forceNoCacheEnabled,
6472
+ pgUri: this.pgUriValue,
6473
+ jdbcUrl: this.jdbcUrlValue,
6474
+ athenaKey: this.athenaKeyValue,
6393
6475
  backend: this.backendConfig,
6394
6476
  headers: this.defaultHeaders,
6395
6477
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -9102,10 +9184,6 @@ function resolveRequiredClientApiKey(value) {
9102
9184
  }
9103
9185
  return normalizedValue;
9104
9186
  }
9105
- function hasHeaderIgnoreCase(headers, targetKey) {
9106
- const normalizedTargetKey = targetKey.toLowerCase();
9107
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9108
- }
9109
9187
  function mergeClientHeaders(current, next) {
9110
9188
  if (!current && !next) {
9111
9189
  return void 0;
@@ -9236,6 +9314,9 @@ function resolveCreateClientConfig(config) {
9236
9314
  userId: config.userId,
9237
9315
  organizationId: config.organizationId,
9238
9316
  forceNoCache: config.forceNoCache,
9317
+ pgUri: config.pgUri,
9318
+ jdbcUrl: config.jdbcUrl,
9319
+ athenaKey: config.athenaKey,
9239
9320
  backend: toBackendConfig(config.backend),
9240
9321
  headers: config.headers,
9241
9322
  auth: config.auth,
@@ -9252,18 +9333,6 @@ function createClientFromInput(sourceConfig) {
9252
9333
  }
9253
9334
  function createClientFromConfig(config, sourceConfig) {
9254
9335
  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
9336
  const gateway = createAthenaGatewayClient({
9268
9337
  baseUrl: config.baseUrl,
9269
9338
  apiKey: config.apiKey,
@@ -9271,8 +9340,14 @@ function createClientFromConfig(config, sourceConfig) {
9271
9340
  userId: config.userId,
9272
9341
  organizationId: config.organizationId,
9273
9342
  forceNoCache: config.forceNoCache,
9343
+ pgUri: config.pgUri,
9344
+ jdbcUrl: config.jdbcUrl,
9345
+ athenaKey: config.athenaKey,
9274
9346
  backend: config.backend,
9275
- headers: gatewayHeaders
9347
+ bearerToken: normalizedAuthConfig?.bearerToken,
9348
+ cookie: normalizedAuthConfig?.cookie,
9349
+ sessionToken: normalizedAuthConfig?.sessionToken,
9350
+ headers: config.headers
9276
9351
  });
9277
9352
  const formatGatewayResult = createResultFormatter(config.experimental);
9278
9353
  const queryTracer = createQueryTracer(config.experimental);
@@ -9330,6 +9405,7 @@ function createClientFromConfig(config, sourceConfig) {
9330
9405
  const chat = createChatModule({
9331
9406
  baseUrl: config.chatUrl,
9332
9407
  apiKey: config.apiKey,
9408
+ athenaKey: config.athenaKey,
9333
9409
  client: config.client,
9334
9410
  headers: config.headers,
9335
9411
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9366,48 +9442,28 @@ function createClientFromConfig(config, sourceConfig) {
9366
9442
  return path.startsWith("/") ? path : `/${path}`;
9367
9443
  })();
9368
9444
  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
- }
9445
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
9446
+ const headers = buildAthenaRequestHeaders({
9447
+ profile: requestProfile,
9448
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
9449
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
9450
+ athenaKey: options.athenaKey ?? config.athenaKey,
9451
+ client: config.client,
9452
+ userId: config.userId,
9453
+ organizationId: config.organizationId,
9454
+ backend: config.backend,
9455
+ pgUri: config.pgUri,
9456
+ jdbcUrl: config.jdbcUrl,
9457
+ bearerToken: normalizedAuthConfig?.bearerToken,
9458
+ cookie: normalizedAuthConfig?.cookie,
9459
+ sessionToken: normalizedAuthConfig?.sessionToken,
9460
+ forceNoCache: config.forceNoCache,
9461
+ configHeaders: config.headers,
9462
+ callHeaders: options.headers,
9463
+ accept: service === "chat" ? "application/json" : void 0,
9464
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
9465
+ stripNulls: service === "db" ? true : void 0
9466
+ });
9411
9467
  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
9468
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9413
9469
  headers["Content-Type"] = "application/json";