@xylex-group/athena 2.10.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 +112 -28
  2. package/dist/browser.cjs +333 -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 +333 -240
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +306 -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 +306 -240
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/{client-BYii6dU9.d.ts → client-C3x75Zgn.d.cts} +22 -9
  15. package/dist/{client-B7EQ_hPV.d.cts → client-QUbAs7E8.d.ts} +22 -9
  16. package/dist/index.cjs +333 -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 +333 -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-DbHlxpeR.d.ts → module-CW3tWJ10.d.ts} +5 -4
  25. package/dist/{module-DC96HJa3.d.cts → module-Cxcurfes.d.cts} +5 -4
  26. package/dist/next/client.cjs +333 -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 +333 -240
  31. package/dist/next/client.js.map +1 -1
  32. package/dist/next/server.cjs +333 -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 +333 -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-DRptGBWP.d.ts → shared-0Kdc74lu.d.ts} +2 -2
  47. package/dist/{shared-BMVGMnti.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 +2 -2
  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.10.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", "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,207 @@ 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 (!hasHeaderIgnoreCase(headers, "x-api-key")) {
912
+ headers["x-api-key"] = apiKey;
913
+ }
914
+ }
915
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
916
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
917
+ headers["X-Athena-Key"] = resolvedAthenaKey;
918
+ }
919
+ }
920
+ function applyAthenaAuthContextHeaders(headers, input) {
921
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
922
+ const rules = PROFILE_RULES[input.profile];
923
+ const explicitCookie = normalizeHeaderValue(input.cookie);
924
+ if (explicitCookie) {
925
+ mergedExtraHeaders.Cookie = explicitCookie;
926
+ }
927
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
928
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
929
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
930
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
931
+ headers.Cookie = explicitCookie;
932
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
933
+ headers.Cookie = cookieFromHeaders;
934
+ }
935
+ const explicitBearerToken = (() => {
936
+ const configured = normalizeHeaderValue(input.bearerToken);
937
+ if (configured) {
938
+ return normalizeBearerToken(configured);
939
+ }
940
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
941
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
942
+ })();
943
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
944
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
945
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
946
+ }
947
+ if (rules.authMirror) {
948
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
949
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
950
+ }
951
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
952
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
953
+ }
954
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
955
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
956
+ }
957
+ }
958
+ function applyAthenaPgUriHeaders(headers, input) {
959
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
960
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
961
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
962
+ headers["x-pg-uri"] = pgUri;
963
+ }
964
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
965
+ if (jdbcUrl) {
966
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
967
+ headers["x-athena-jdbc-url"] = jdbcUrl;
968
+ }
969
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
970
+ headers["x-jdbc-url"] = jdbcUrl;
971
+ }
972
+ }
973
+ }
974
+ function buildAthenaRequestHeaders(input) {
975
+ const forceNoCache = Boolean(input.forceNoCache);
976
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
977
+ const rules = PROFILE_RULES[input.profile];
978
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
979
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
980
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
981
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
982
+ const headers = {
983
+ "X-Athena-Sdk": input.sdkHeaderValue
984
+ };
985
+ if (rules.contentType) {
986
+ headers["Content-Type"] = input.contentType ?? "application/json";
987
+ }
988
+ if (input.accept ?? rules.accept) {
989
+ headers.Accept = input.accept ?? "application/json";
990
+ }
991
+ if (rules.routing) {
992
+ if (normalizeHeaderValue(input.userId)) {
993
+ headers["X-User-Id"] = input.userId ?? "";
994
+ }
995
+ if (normalizeHeaderValue(input.organizationId)) {
996
+ headers["X-Organization-Id"] = input.organizationId ?? "";
997
+ }
998
+ if (finalClient) {
999
+ headers["X-Athena-Client"] = finalClient;
1000
+ }
1001
+ const backendType = resolveBackendType(input.backend);
1002
+ if (backendType) {
1003
+ headers["X-Backend-Type"] = backendType;
1004
+ }
1005
+ if (typeof input.stripNulls === "boolean") {
1006
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
1007
+ } else if (rules.stripNullsDefault) {
1008
+ headers["X-Strip-Nulls"] = "true";
1009
+ }
1010
+ if (normalizeHeaderValue(input.publishEvent)) {
1011
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
1012
+ }
1013
+ }
1014
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
1015
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
1016
+ }
1017
+ applyAthenaAuthContextHeaders(headers, input);
1018
+ applyAthenaPgUriHeaders(headers, input);
1019
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
1020
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1021
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
1022
+ return;
1023
+ }
1024
+ if (forceNoCache && isCacheControlHeaderName(key)) {
1025
+ return;
1026
+ }
1027
+ const normalized = normalizeHeaderValue(value);
1028
+ if (normalized) {
1029
+ headers[key] = normalized;
1030
+ }
1031
+ });
1032
+ if (forceNoCache) {
1033
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1034
+ }
1035
+ return headers;
1036
+ }
1037
+
1038
+ // package.json
1039
+ var package_default = {
1040
+ version: "2.12.0"
1041
+ };
1042
+
1043
+ // src/sdk-version.ts
1044
+ var PACKAGE_VERSION = package_default.version;
1045
+ function buildSdkHeaderValue(sdkName) {
1046
+ return `${sdkName} ${PACKAGE_VERSION}`;
1047
+ }
1048
+
1049
+ // src/gateway/client.ts
1050
+ var DEFAULT_CLIENT = "railway_direct";
1051
+ var SDK_NAME = "xylex-group/athena";
1052
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
1053
+ function parseResponseBody(rawText, contentType) {
1054
+ if (!rawText) {
1055
+ return { parsed: null, parseFailed: false };
1056
+ }
1057
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
1058
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
1059
+ if (!looksJson) {
1060
+ return { parsed: rawText, parseFailed: false };
1061
+ }
1062
+ try {
1063
+ return { parsed: JSON.parse(rawText), parseFailed: false };
1064
+ } catch {
1065
+ return { parsed: rawText, parseFailed: true };
1066
+ }
1067
+ }
871
1068
  function isRecord(value) {
872
1069
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
873
1070
  }
@@ -994,71 +1191,10 @@ function buildRpcGetEndpoint(payload) {
994
1191
  return withQuery;
995
1192
  }
996
1193
  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
- }
1194
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
1195
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
1196
+ stripNulls: options?.stripNulls ?? true
1057
1197
  });
1058
- if (forceNoCache) {
1059
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1060
- }
1061
- return headers;
1062
1198
  }
1063
1199
  function toInvalidUrlResponse(error, endpoint, method) {
1064
1200
  const message = error instanceof Error ? error.message : String(error);
@@ -1786,19 +1922,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
1786
1922
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
1787
1923
  var SDK_NAME2 = "xylex-group/athena-auth";
1788
1924
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
1789
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
1790
1925
  function normalizeBaseUrl(baseUrl) {
1791
1926
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
1792
1927
  }
1793
1928
  function isRecord3(value) {
1794
1929
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1795
1930
  }
1796
- function normalizeHeaderValue2(value) {
1797
- return value ? value : void 0;
1798
- }
1799
- function isCacheControlHeaderName2(name) {
1800
- return name.toLowerCase() === "cache-control";
1801
- }
1802
1931
  function parseResponseBody2(rawText, contentType) {
1803
1932
  if (!rawText) {
1804
1933
  return { parsed: null, parseFailed: false };
@@ -1863,6 +1992,21 @@ function copyDefinedField(target, source, targetKey, sourceKey) {
1863
1992
  target[targetKey] = value;
1864
1993
  }
1865
1994
  }
1995
+ function normalizeEmailTemplateAttachmentsValue(value) {
1996
+ if (typeof value === "string" || value == null) {
1997
+ return value;
1998
+ }
1999
+ if (Array.isArray(value)) {
2000
+ return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
2001
+ }
2002
+ if (typeof value !== "object") {
2003
+ return value;
2004
+ }
2005
+ const attachment = { ...value };
2006
+ copyDefinedField(attachment, attachment, "file_url", "fileUrl");
2007
+ delete attachment.fileUrl;
2008
+ return attachment;
2009
+ }
1866
2010
  function normalizeAdminEmailTemplatePayload(payload) {
1867
2011
  const normalized = { ...payload };
1868
2012
  copyDefinedField(normalized, payload, "template_key", "templateKey");
@@ -1873,6 +2017,17 @@ function normalizeAdminEmailTemplatePayload(payload) {
1873
2017
  copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
1874
2018
  copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
1875
2019
  copyDefinedField(normalized, payload, "is_active", "isActive");
2020
+ if (Object.hasOwn(payload, "attachments")) {
2021
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
2022
+ }
2023
+ delete normalized.templateKey;
2024
+ delete normalized.eventType;
2025
+ delete normalized.subjectTemplate;
2026
+ delete normalized.textTemplate;
2027
+ delete normalized.htmlTemplate;
2028
+ delete normalized.variableBindings;
2029
+ delete normalized.attachmentFailureMode;
2030
+ delete normalized.isActive;
1876
2031
  return normalized;
1877
2032
  }
1878
2033
  function toReactEmailTemplateCompatibilityInput(input) {
@@ -1896,6 +2051,17 @@ function normalizeAdminEmailTemplateSendPayload(payload) {
1896
2051
  copyDefinedField(normalized, payload, "user_id", "userId");
1897
2052
  copyDefinedField(normalized, payload, "organization_id", "organizationId");
1898
2053
  copyDefinedField(normalized, payload, "session_token", "sessionToken");
2054
+ copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
2055
+ if (Object.hasOwn(payload, "attachments")) {
2056
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
2057
+ }
2058
+ delete normalized.templateId;
2059
+ delete normalized.recipientEmail;
2060
+ delete normalized.renderVariables;
2061
+ delete normalized.userId;
2062
+ delete normalized.organizationId;
2063
+ delete normalized.sessionToken;
2064
+ delete normalized.attachmentFailureMode;
1899
2065
  return normalized;
1900
2066
  }
1901
2067
  function toSessionGuardFailure(sessionResult) {
@@ -1961,45 +2127,7 @@ function extractFetchOptions(input) {
1961
2127
  };
1962
2128
  }
1963
2129
  function buildHeaders2(config, options) {
1964
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1965
- const headers = {
1966
- "Content-Type": "application/json",
1967
- "X-Athena-Sdk": SDK_HEADER_VALUE2
1968
- };
1969
- const apiKey = options?.apiKey ?? config.apiKey;
1970
- if (apiKey) {
1971
- headers.apikey = apiKey;
1972
- headers["x-api-key"] = apiKey;
1973
- }
1974
- const bearerToken = options?.bearerToken ?? config.bearerToken;
1975
- if (bearerToken) {
1976
- headers.Authorization = `Bearer ${bearerToken}`;
1977
- }
1978
- const cookie = options?.cookie ?? config.cookie;
1979
- if (cookie) {
1980
- headers.Cookie = cookie;
1981
- }
1982
- const sessionToken = options?.sessionToken ?? config.sessionToken;
1983
- if (sessionToken) {
1984
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
1985
- }
1986
- const mergedExtraHeaders = {
1987
- ...config.headers ?? {},
1988
- ...options?.headers ?? {}
1989
- };
1990
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1991
- if (forceNoCache && isCacheControlHeaderName2(key)) {
1992
- return;
1993
- }
1994
- const normalized = normalizeHeaderValue2(value);
1995
- if (normalized) {
1996
- headers[key] = normalized;
1997
- }
1998
- });
1999
- if (forceNoCache) {
2000
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
2001
- }
2002
- return headers;
2130
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
2003
2131
  }
2004
2132
  function appendQueryParam(searchParams, key, value) {
2005
2133
  if (value === void 0 || value === null) return;
@@ -5678,7 +5806,6 @@ function createStorageModule(gateway, runtimeOptions) {
5678
5806
  // src/chat/module.ts
5679
5807
  var SDK_NAME3 = "xylex-group/athena-chat";
5680
5808
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
5681
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
5682
5809
  var AthenaChatError = class extends Error {
5683
5810
  status;
5684
5811
  endpoint;
@@ -5724,9 +5851,6 @@ function normalizeWsUrl(value, label) {
5724
5851
  function isRecord7(value) {
5725
5852
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5726
5853
  }
5727
- function normalizeHeaderValue3(value) {
5728
- return value ? value : void 0;
5729
- }
5730
5854
  function parseResponseBody4(rawText, contentType) {
5731
5855
  if (!rawText) {
5732
5856
  return { parsed: null, parseFailed: false };
@@ -5798,39 +5922,7 @@ function createSocket(factory, url, protocols) {
5798
5922
  }
5799
5923
  }
5800
5924
  function buildHeaders3(config, options) {
5801
- const headers = {
5802
- Accept: "application/json",
5803
- apikey: config.apiKey,
5804
- "x-api-key": config.apiKey,
5805
- "X-Athena-Sdk": SDK_HEADER_VALUE3
5806
- };
5807
- if (config.client || options?.client) {
5808
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
5809
- }
5810
- const bearerToken = options?.bearerToken ?? config.bearerToken;
5811
- if (typeof bearerToken === "string" && bearerToken.trim()) {
5812
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
5813
- }
5814
- const cookie = options?.cookie ?? config.cookie;
5815
- if (typeof cookie === "string" && cookie.trim()) {
5816
- headers.Cookie = cookie;
5817
- }
5818
- const sessionToken = options?.sessionToken ?? config.sessionToken;
5819
- if (typeof sessionToken === "string" && sessionToken.trim()) {
5820
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
5821
- }
5822
- if (config.forceNoCache || options?.forceNoCache) {
5823
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
5824
- }
5825
- for (const source of [config.headers, options?.headers]) {
5826
- for (const [key, value] of Object.entries(source ?? {})) {
5827
- const normalized = normalizeHeaderValue3(value);
5828
- if (normalized) {
5829
- headers[key] = normalized;
5830
- }
5831
- }
5832
- }
5833
- return headers;
5925
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
5834
5926
  }
5835
5927
  function withJsonBody(init, body) {
5836
5928
  return {
@@ -6242,6 +6334,9 @@ var AthenaClientBuilderImpl = class {
6242
6334
  defaultOrganizationId;
6243
6335
  forceNoCacheEnabled = false;
6244
6336
  defaultHeaders;
6337
+ pgUriValue;
6338
+ jdbcUrlValue;
6339
+ athenaKeyValue;
6245
6340
  authConfig;
6246
6341
  dbUrlOverride;
6247
6342
  gatewayUrlOverride;
@@ -6268,6 +6363,18 @@ var AthenaClientBuilderImpl = class {
6268
6363
  this.defaultHeaders = headers;
6269
6364
  return this;
6270
6365
  }
6366
+ pgUri(pgUri) {
6367
+ this.pgUriValue = pgUri;
6368
+ return this;
6369
+ }
6370
+ jdbcUrl(jdbcUrl) {
6371
+ this.jdbcUrlValue = jdbcUrl;
6372
+ return this;
6373
+ }
6374
+ athenaKey(athenaKey) {
6375
+ this.athenaKeyValue = athenaKey;
6376
+ return this;
6377
+ }
6271
6378
  auth(config) {
6272
6379
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
6273
6380
  return this;
@@ -6304,6 +6411,15 @@ var AthenaClientBuilderImpl = class {
6304
6411
  if (options.headers !== void 0) {
6305
6412
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
6306
6413
  }
6414
+ if (options.pgUri !== void 0) {
6415
+ this.pgUriValue = options.pgUri;
6416
+ }
6417
+ if (options.jdbcUrl !== void 0) {
6418
+ this.jdbcUrlValue = options.jdbcUrl;
6419
+ }
6420
+ if (options.athenaKey !== void 0) {
6421
+ this.athenaKeyValue = options.athenaKey;
6422
+ }
6307
6423
  if (options.auth !== void 0) {
6308
6424
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
6309
6425
  }
@@ -6355,6 +6471,9 @@ var AthenaClientBuilderImpl = class {
6355
6471
  userId: this.defaultUserId,
6356
6472
  organizationId: this.defaultOrganizationId,
6357
6473
  forceNoCache: this.forceNoCacheEnabled,
6474
+ pgUri: this.pgUriValue,
6475
+ jdbcUrl: this.jdbcUrlValue,
6476
+ athenaKey: this.athenaKeyValue,
6358
6477
  backend: this.backendConfig,
6359
6478
  headers: this.defaultHeaders,
6360
6479
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -9067,10 +9186,6 @@ function resolveRequiredClientApiKey(value) {
9067
9186
  }
9068
9187
  return normalizedValue;
9069
9188
  }
9070
- function hasHeaderIgnoreCase(headers, targetKey) {
9071
- const normalizedTargetKey = targetKey.toLowerCase();
9072
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9073
- }
9074
9189
  function mergeClientHeaders(current, next) {
9075
9190
  if (!current && !next) {
9076
9191
  return void 0;
@@ -9201,6 +9316,9 @@ function resolveCreateClientConfig(config) {
9201
9316
  userId: config.userId,
9202
9317
  organizationId: config.organizationId,
9203
9318
  forceNoCache: config.forceNoCache,
9319
+ pgUri: config.pgUri,
9320
+ jdbcUrl: config.jdbcUrl,
9321
+ athenaKey: config.athenaKey,
9204
9322
  backend: toBackendConfig(config.backend),
9205
9323
  headers: config.headers,
9206
9324
  auth: config.auth,
@@ -9217,18 +9335,6 @@ function createClientFromInput(sourceConfig) {
9217
9335
  }
9218
9336
  function createClientFromConfig(config, sourceConfig) {
9219
9337
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
9220
- const gatewayHeaders = {
9221
- ...config.headers ?? {}
9222
- };
9223
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
9224
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9225
- }
9226
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
9227
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
9228
- }
9229
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
9230
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9231
- }
9232
9338
  const gateway = createAthenaGatewayClient({
9233
9339
  baseUrl: config.baseUrl,
9234
9340
  apiKey: config.apiKey,
@@ -9236,8 +9342,14 @@ function createClientFromConfig(config, sourceConfig) {
9236
9342
  userId: config.userId,
9237
9343
  organizationId: config.organizationId,
9238
9344
  forceNoCache: config.forceNoCache,
9345
+ pgUri: config.pgUri,
9346
+ jdbcUrl: config.jdbcUrl,
9347
+ athenaKey: config.athenaKey,
9239
9348
  backend: config.backend,
9240
- headers: gatewayHeaders
9349
+ bearerToken: normalizedAuthConfig?.bearerToken,
9350
+ cookie: normalizedAuthConfig?.cookie,
9351
+ sessionToken: normalizedAuthConfig?.sessionToken,
9352
+ headers: config.headers
9241
9353
  });
9242
9354
  const formatGatewayResult = createResultFormatter(config.experimental);
9243
9355
  const queryTracer = createQueryTracer(config.experimental);
@@ -9295,6 +9407,7 @@ function createClientFromConfig(config, sourceConfig) {
9295
9407
  const chat = createChatModule({
9296
9408
  baseUrl: config.chatUrl,
9297
9409
  apiKey: config.apiKey,
9410
+ athenaKey: config.athenaKey,
9298
9411
  client: config.client,
9299
9412
  headers: config.headers,
9300
9413
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9331,48 +9444,28 @@ function createClientFromConfig(config, sourceConfig) {
9331
9444
  return path.startsWith("/") ? path : `/${path}`;
9332
9445
  })();
9333
9446
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
9334
- const headers = {
9335
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
9336
- ...config.headers ?? {},
9337
- ...options.headers ?? {}
9338
- };
9339
- if (service !== "auth") {
9340
- headers.apikey = headers.apikey ?? config.apiKey;
9341
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
9342
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
9343
- headers["X-Athena-Client"] = config.client;
9344
- }
9345
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
9346
- headers["X-User-Id"] = config.userId;
9347
- }
9348
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
9349
- headers["X-Organization-Id"] = config.organizationId;
9350
- }
9351
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9352
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9353
- }
9354
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
9355
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9356
- }
9357
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9358
- headers.Cookie = normalizedAuthConfig.cookie;
9359
- }
9360
- } else {
9361
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
9362
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
9363
- headers.apikey = headers.apikey ?? authApiKey;
9364
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
9365
- }
9366
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
9367
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
9368
- }
9369
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9370
- headers.Cookie = normalizedAuthConfig.cookie;
9371
- }
9372
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9373
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9374
- }
9375
- }
9447
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
9448
+ const headers = buildAthenaRequestHeaders({
9449
+ profile: requestProfile,
9450
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
9451
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
9452
+ athenaKey: options.athenaKey ?? config.athenaKey,
9453
+ client: config.client,
9454
+ userId: config.userId,
9455
+ organizationId: config.organizationId,
9456
+ backend: config.backend,
9457
+ pgUri: config.pgUri,
9458
+ jdbcUrl: config.jdbcUrl,
9459
+ bearerToken: normalizedAuthConfig?.bearerToken,
9460
+ cookie: normalizedAuthConfig?.cookie,
9461
+ sessionToken: normalizedAuthConfig?.sessionToken,
9462
+ forceNoCache: config.forceNoCache,
9463
+ configHeaders: config.headers,
9464
+ callHeaders: options.headers,
9465
+ accept: service === "chat" ? "application/json" : void 0,
9466
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
9467
+ stripNulls: service === "db" ? true : void 0
9468
+ });
9376
9469
  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";
9377
9470
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9378
9471
  headers["Content-Type"] = "application/json";