@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.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.10.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 };
@@ -1861,6 +1990,21 @@ function copyDefinedField(target, source, targetKey, sourceKey) {
1861
1990
  target[targetKey] = value;
1862
1991
  }
1863
1992
  }
1993
+ function normalizeEmailTemplateAttachmentsValue(value) {
1994
+ if (typeof value === "string" || value == null) {
1995
+ return value;
1996
+ }
1997
+ if (Array.isArray(value)) {
1998
+ return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
1999
+ }
2000
+ if (typeof value !== "object") {
2001
+ return value;
2002
+ }
2003
+ const attachment = { ...value };
2004
+ copyDefinedField(attachment, attachment, "file_url", "fileUrl");
2005
+ delete attachment.fileUrl;
2006
+ return attachment;
2007
+ }
1864
2008
  function normalizeAdminEmailTemplatePayload(payload) {
1865
2009
  const normalized = { ...payload };
1866
2010
  copyDefinedField(normalized, payload, "template_key", "templateKey");
@@ -1871,6 +2015,17 @@ function normalizeAdminEmailTemplatePayload(payload) {
1871
2015
  copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
1872
2016
  copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
1873
2017
  copyDefinedField(normalized, payload, "is_active", "isActive");
2018
+ if (Object.hasOwn(payload, "attachments")) {
2019
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
2020
+ }
2021
+ delete normalized.templateKey;
2022
+ delete normalized.eventType;
2023
+ delete normalized.subjectTemplate;
2024
+ delete normalized.textTemplate;
2025
+ delete normalized.htmlTemplate;
2026
+ delete normalized.variableBindings;
2027
+ delete normalized.attachmentFailureMode;
2028
+ delete normalized.isActive;
1874
2029
  return normalized;
1875
2030
  }
1876
2031
  function toReactEmailTemplateCompatibilityInput(input) {
@@ -1894,6 +2049,17 @@ function normalizeAdminEmailTemplateSendPayload(payload) {
1894
2049
  copyDefinedField(normalized, payload, "user_id", "userId");
1895
2050
  copyDefinedField(normalized, payload, "organization_id", "organizationId");
1896
2051
  copyDefinedField(normalized, payload, "session_token", "sessionToken");
2052
+ copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
2053
+ if (Object.hasOwn(payload, "attachments")) {
2054
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
2055
+ }
2056
+ delete normalized.templateId;
2057
+ delete normalized.recipientEmail;
2058
+ delete normalized.renderVariables;
2059
+ delete normalized.userId;
2060
+ delete normalized.organizationId;
2061
+ delete normalized.sessionToken;
2062
+ delete normalized.attachmentFailureMode;
1897
2063
  return normalized;
1898
2064
  }
1899
2065
  function toSessionGuardFailure(sessionResult) {
@@ -1959,45 +2125,7 @@ function extractFetchOptions(input) {
1959
2125
  };
1960
2126
  }
1961
2127
  function buildHeaders2(config, options) {
1962
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1963
- const headers = {
1964
- "Content-Type": "application/json",
1965
- "X-Athena-Sdk": SDK_HEADER_VALUE2
1966
- };
1967
- const apiKey = options?.apiKey ?? config.apiKey;
1968
- if (apiKey) {
1969
- headers.apikey = apiKey;
1970
- headers["x-api-key"] = apiKey;
1971
- }
1972
- const bearerToken = options?.bearerToken ?? config.bearerToken;
1973
- if (bearerToken) {
1974
- headers.Authorization = `Bearer ${bearerToken}`;
1975
- }
1976
- const cookie = options?.cookie ?? config.cookie;
1977
- if (cookie) {
1978
- headers.Cookie = cookie;
1979
- }
1980
- const sessionToken = options?.sessionToken ?? config.sessionToken;
1981
- if (sessionToken) {
1982
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
1983
- }
1984
- const mergedExtraHeaders = {
1985
- ...config.headers ?? {},
1986
- ...options?.headers ?? {}
1987
- };
1988
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1989
- if (forceNoCache && isCacheControlHeaderName2(key)) {
1990
- return;
1991
- }
1992
- const normalized = normalizeHeaderValue2(value);
1993
- if (normalized) {
1994
- headers[key] = normalized;
1995
- }
1996
- });
1997
- if (forceNoCache) {
1998
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
1999
- }
2000
- return headers;
2128
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
2001
2129
  }
2002
2130
  function appendQueryParam(searchParams, key, value) {
2003
2131
  if (value === void 0 || value === null) return;
@@ -5676,7 +5804,6 @@ function createStorageModule(gateway, runtimeOptions) {
5676
5804
  // src/chat/module.ts
5677
5805
  var SDK_NAME3 = "xylex-group/athena-chat";
5678
5806
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
5679
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
5680
5807
  var AthenaChatError = class extends Error {
5681
5808
  status;
5682
5809
  endpoint;
@@ -5722,9 +5849,6 @@ function normalizeWsUrl(value, label) {
5722
5849
  function isRecord7(value) {
5723
5850
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5724
5851
  }
5725
- function normalizeHeaderValue3(value) {
5726
- return value ? value : void 0;
5727
- }
5728
5852
  function parseResponseBody4(rawText, contentType) {
5729
5853
  if (!rawText) {
5730
5854
  return { parsed: null, parseFailed: false };
@@ -5796,39 +5920,7 @@ function createSocket(factory, url, protocols) {
5796
5920
  }
5797
5921
  }
5798
5922
  function buildHeaders3(config, options) {
5799
- const headers = {
5800
- Accept: "application/json",
5801
- apikey: config.apiKey,
5802
- "x-api-key": config.apiKey,
5803
- "X-Athena-Sdk": SDK_HEADER_VALUE3
5804
- };
5805
- if (config.client || options?.client) {
5806
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
5807
- }
5808
- const bearerToken = options?.bearerToken ?? config.bearerToken;
5809
- if (typeof bearerToken === "string" && bearerToken.trim()) {
5810
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
5811
- }
5812
- const cookie = options?.cookie ?? config.cookie;
5813
- if (typeof cookie === "string" && cookie.trim()) {
5814
- headers.Cookie = cookie;
5815
- }
5816
- const sessionToken = options?.sessionToken ?? config.sessionToken;
5817
- if (typeof sessionToken === "string" && sessionToken.trim()) {
5818
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
5819
- }
5820
- if (config.forceNoCache || options?.forceNoCache) {
5821
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
5822
- }
5823
- for (const source of [config.headers, options?.headers]) {
5824
- for (const [key, value] of Object.entries(source ?? {})) {
5825
- const normalized = normalizeHeaderValue3(value);
5826
- if (normalized) {
5827
- headers[key] = normalized;
5828
- }
5829
- }
5830
- }
5831
- return headers;
5923
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
5832
5924
  }
5833
5925
  function withJsonBody(init, body) {
5834
5926
  return {
@@ -6240,6 +6332,9 @@ var AthenaClientBuilderImpl = class {
6240
6332
  defaultOrganizationId;
6241
6333
  forceNoCacheEnabled = false;
6242
6334
  defaultHeaders;
6335
+ pgUriValue;
6336
+ jdbcUrlValue;
6337
+ athenaKeyValue;
6243
6338
  authConfig;
6244
6339
  dbUrlOverride;
6245
6340
  gatewayUrlOverride;
@@ -6266,6 +6361,18 @@ var AthenaClientBuilderImpl = class {
6266
6361
  this.defaultHeaders = headers;
6267
6362
  return this;
6268
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
+ }
6269
6376
  auth(config) {
6270
6377
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
6271
6378
  return this;
@@ -6302,6 +6409,15 @@ var AthenaClientBuilderImpl = class {
6302
6409
  if (options.headers !== void 0) {
6303
6410
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
6304
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
+ }
6305
6421
  if (options.auth !== void 0) {
6306
6422
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
6307
6423
  }
@@ -6353,6 +6469,9 @@ var AthenaClientBuilderImpl = class {
6353
6469
  userId: this.defaultUserId,
6354
6470
  organizationId: this.defaultOrganizationId,
6355
6471
  forceNoCache: this.forceNoCacheEnabled,
6472
+ pgUri: this.pgUriValue,
6473
+ jdbcUrl: this.jdbcUrlValue,
6474
+ athenaKey: this.athenaKeyValue,
6356
6475
  backend: this.backendConfig,
6357
6476
  headers: this.defaultHeaders,
6358
6477
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -9065,10 +9184,6 @@ function resolveRequiredClientApiKey(value) {
9065
9184
  }
9066
9185
  return normalizedValue;
9067
9186
  }
9068
- function hasHeaderIgnoreCase(headers, targetKey) {
9069
- const normalizedTargetKey = targetKey.toLowerCase();
9070
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9071
- }
9072
9187
  function mergeClientHeaders(current, next) {
9073
9188
  if (!current && !next) {
9074
9189
  return void 0;
@@ -9199,6 +9314,9 @@ function resolveCreateClientConfig(config) {
9199
9314
  userId: config.userId,
9200
9315
  organizationId: config.organizationId,
9201
9316
  forceNoCache: config.forceNoCache,
9317
+ pgUri: config.pgUri,
9318
+ jdbcUrl: config.jdbcUrl,
9319
+ athenaKey: config.athenaKey,
9202
9320
  backend: toBackendConfig(config.backend),
9203
9321
  headers: config.headers,
9204
9322
  auth: config.auth,
@@ -9215,18 +9333,6 @@ function createClientFromInput(sourceConfig) {
9215
9333
  }
9216
9334
  function createClientFromConfig(config, sourceConfig) {
9217
9335
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
9218
- const gatewayHeaders = {
9219
- ...config.headers ?? {}
9220
- };
9221
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
9222
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9223
- }
9224
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
9225
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
9226
- }
9227
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
9228
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9229
- }
9230
9336
  const gateway = createAthenaGatewayClient({
9231
9337
  baseUrl: config.baseUrl,
9232
9338
  apiKey: config.apiKey,
@@ -9234,8 +9340,14 @@ function createClientFromConfig(config, sourceConfig) {
9234
9340
  userId: config.userId,
9235
9341
  organizationId: config.organizationId,
9236
9342
  forceNoCache: config.forceNoCache,
9343
+ pgUri: config.pgUri,
9344
+ jdbcUrl: config.jdbcUrl,
9345
+ athenaKey: config.athenaKey,
9237
9346
  backend: config.backend,
9238
- headers: gatewayHeaders
9347
+ bearerToken: normalizedAuthConfig?.bearerToken,
9348
+ cookie: normalizedAuthConfig?.cookie,
9349
+ sessionToken: normalizedAuthConfig?.sessionToken,
9350
+ headers: config.headers
9239
9351
  });
9240
9352
  const formatGatewayResult = createResultFormatter(config.experimental);
9241
9353
  const queryTracer = createQueryTracer(config.experimental);
@@ -9293,6 +9405,7 @@ function createClientFromConfig(config, sourceConfig) {
9293
9405
  const chat = createChatModule({
9294
9406
  baseUrl: config.chatUrl,
9295
9407
  apiKey: config.apiKey,
9408
+ athenaKey: config.athenaKey,
9296
9409
  client: config.client,
9297
9410
  headers: config.headers,
9298
9411
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9329,48 +9442,28 @@ function createClientFromConfig(config, sourceConfig) {
9329
9442
  return path.startsWith("/") ? path : `/${path}`;
9330
9443
  })();
9331
9444
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
9332
- const headers = {
9333
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
9334
- ...config.headers ?? {},
9335
- ...options.headers ?? {}
9336
- };
9337
- if (service !== "auth") {
9338
- headers.apikey = headers.apikey ?? config.apiKey;
9339
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
9340
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
9341
- headers["X-Athena-Client"] = config.client;
9342
- }
9343
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
9344
- headers["X-User-Id"] = config.userId;
9345
- }
9346
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
9347
- headers["X-Organization-Id"] = config.organizationId;
9348
- }
9349
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9350
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9351
- }
9352
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
9353
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9354
- }
9355
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9356
- headers.Cookie = normalizedAuthConfig.cookie;
9357
- }
9358
- } else {
9359
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
9360
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
9361
- headers.apikey = headers.apikey ?? authApiKey;
9362
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
9363
- }
9364
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
9365
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
9366
- }
9367
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9368
- headers.Cookie = normalizedAuthConfig.cookie;
9369
- }
9370
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9371
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9372
- }
9373
- }
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
+ });
9374
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";
9375
9468
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9376
9469
  headers["Content-Type"] = "application/json";