@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/index.cjs CHANGED
@@ -804,42 +804,31 @@ var getCookieCache = async (request2, config) => {
804
804
  };
805
805
  };
806
806
 
807
- // package.json
808
- var package_default = {
809
- version: "2.10.0"
810
- };
811
-
812
- // src/sdk-version.ts
813
- var PACKAGE_VERSION = package_default.version;
814
- function buildSdkHeaderValue(sdkName) {
815
- return `${sdkName} ${PACKAGE_VERSION}`;
816
- }
817
-
818
- // src/gateway/client.ts
819
- var DEFAULT_CLIENT = "railway_direct";
820
- var SDK_NAME = "xylex-group/athena";
821
- var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
807
+ // src/utils/athena-request-headers.ts
822
808
  var NO_CACHE_HEADER_VALUE = "no-cache";
823
- function parseResponseBody(rawText, contentType) {
824
- if (!rawText) {
825
- return { parsed: null, parseFailed: false };
826
- }
827
- const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
828
- const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
829
- if (!looksJson) {
830
- return { parsed: rawText, parseFailed: false };
831
- }
832
- try {
833
- return { parsed: JSON.parse(rawText), parseFailed: false };
834
- } catch {
835
- return { parsed: rawText, parseFailed: true };
836
- }
837
- }
809
+ var API_KEY_HEADER_CANDIDATES = ["x-api-key", "apikey"];
810
+ var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
811
+ var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
812
+ var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
813
+ var CLIENT_HEADER_CANDIDATES = ["X-Athena-Client", "x-athena-client"];
814
+ var PG_URI_HEADER_CANDIDATES = ["x-pg-uri"];
815
+ var JDBC_URI_HEADER_CANDIDATES = ["x-athena-jdbc-url", "x-jdbc-url"];
816
+ var PROFILE_RULES = {
817
+ gateway: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true, stripNullsDefault: true },
818
+ chat: { apiKeys: true, routing: true, authMirror: true, authBearer: true, accept: true },
819
+ storage: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true },
820
+ auth: { apiKeys: true, routing: false, authMirror: false, authBearer: true, contentType: true },
821
+ minimal: { apiKeys: false, routing: false, authMirror: false, authBearer: false }
822
+ };
838
823
  function normalizeHeaderValue(value) {
839
824
  return value ? value : void 0;
840
825
  }
841
- function isCacheControlHeaderName(name) {
842
- return name.toLowerCase() === "cache-control";
826
+ function mergeExtraHeaders(configHeaders, callHeaders) {
827
+ return { ...configHeaders ?? {}, ...callHeaders ?? {} };
828
+ }
829
+ function hasHeaderIgnoreCase(headers, targetKey) {
830
+ const normalizedTargetKey = targetKey.toLowerCase();
831
+ return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
843
832
  }
844
833
  function resolveHeaderValue(headers, candidates) {
845
834
  for (const candidate of candidates) {
@@ -856,13 +845,20 @@ function resolveHeaderValue(headers, candidates) {
856
845
  }
857
846
  return void 0;
858
847
  }
848
+ function isCacheControlHeaderName(name) {
849
+ return name.toLowerCase() === "cache-control";
850
+ }
851
+ function normalizeBearerToken(value) {
852
+ const trimmed = value.trim();
853
+ const match = trimmed.match(/^Bearer\s+(.+)$/i);
854
+ return match?.[1]?.trim() ?? trimmed;
855
+ }
859
856
  function resolveBearerTokenFromAuthorizationHeader(headers) {
860
857
  const authorization = resolveHeaderValue(headers, ["Authorization"]);
861
858
  if (!authorization) {
862
859
  return void 0;
863
860
  }
864
- const match = authorization.match(/^Bearer\s+(.+)$/i);
865
- const token = match?.[1]?.trim();
861
+ const token = normalizeBearerToken(authorization);
866
862
  return token ? token : void 0;
867
863
  }
868
864
  function resolveSessionTokenFromCookieHeader(headers) {
@@ -872,6 +868,207 @@ function resolveSessionTokenFromCookieHeader(headers) {
872
868
  }
873
869
  return getSessionCookie(new Headers({ cookie })) ?? void 0;
874
870
  }
871
+ function resolveBackendType(backend) {
872
+ if (!backend) {
873
+ return void 0;
874
+ }
875
+ return typeof backend === "string" ? backend : backend.type;
876
+ }
877
+ function resolveRequestHeaderOverrides(config, options, defaults) {
878
+ return {
879
+ apiKey: options?.apiKey ?? config.apiKey,
880
+ athenaKey: options?.athenaKey ?? config.athenaKey,
881
+ client: options?.client ?? config.client ?? defaults?.client,
882
+ userId: options?.userId ?? config.userId,
883
+ organizationId: options?.organizationId ?? config.organizationId,
884
+ backend: options?.backend ?? config.backend,
885
+ publishEvent: options?.publishEvent ?? config.publishEvent,
886
+ stripNulls: options?.stripNulls ?? config.stripNulls ?? defaults?.stripNulls,
887
+ bearerToken: options?.bearerToken ?? config.bearerToken,
888
+ cookie: options?.cookie ?? config.cookie,
889
+ sessionToken: options?.sessionToken ?? config.sessionToken,
890
+ pgUri: options?.pgUri ?? config.pgUri,
891
+ jdbcUrl: options?.jdbcUrl ?? config.jdbcUrl,
892
+ forceNoCache: Boolean(config.forceNoCache || options?.forceNoCache),
893
+ configHeaders: config.headers,
894
+ callHeaders: options?.headers
895
+ };
896
+ }
897
+ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, extras) {
898
+ const rules = PROFILE_RULES[profile];
899
+ return buildAthenaRequestHeaders({
900
+ profile,
901
+ sdkHeaderValue,
902
+ ...resolveRequestHeaderOverrides(config, options, {
903
+ client: extras?.client ?? void 0,
904
+ stripNulls: extras?.stripNulls ?? (rules.stripNullsDefault ? true : void 0)
905
+ }),
906
+ contentType: extras?.contentType ?? (rules.contentType ? "application/json" : void 0),
907
+ accept: extras?.accept ?? (rules.accept ? "application/json" : void 0)
908
+ });
909
+ }
910
+ function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
911
+ if (apiKey) {
912
+ if (!hasHeaderIgnoreCase(headers, "apikey")) {
913
+ headers.apikey = apiKey;
914
+ }
915
+ if (!hasHeaderIgnoreCase(headers, "x-api-key")) {
916
+ headers["x-api-key"] = apiKey;
917
+ }
918
+ }
919
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
920
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
921
+ headers["X-Athena-Key"] = resolvedAthenaKey;
922
+ }
923
+ }
924
+ function applyAthenaAuthContextHeaders(headers, input) {
925
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
926
+ const rules = PROFILE_RULES[input.profile];
927
+ const explicitCookie = normalizeHeaderValue(input.cookie);
928
+ if (explicitCookie) {
929
+ mergedExtraHeaders.Cookie = explicitCookie;
930
+ }
931
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
932
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
933
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
934
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
935
+ headers.Cookie = explicitCookie;
936
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
937
+ headers.Cookie = cookieFromHeaders;
938
+ }
939
+ const explicitBearerToken = (() => {
940
+ const configured = normalizeHeaderValue(input.bearerToken);
941
+ if (configured) {
942
+ return normalizeBearerToken(configured);
943
+ }
944
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
945
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
946
+ })();
947
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
948
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
949
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
950
+ }
951
+ if (rules.authMirror) {
952
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
953
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
954
+ }
955
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
956
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
957
+ }
958
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
959
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
960
+ }
961
+ }
962
+ function applyAthenaPgUriHeaders(headers, input) {
963
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
964
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
965
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
966
+ headers["x-pg-uri"] = pgUri;
967
+ }
968
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
969
+ if (jdbcUrl) {
970
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
971
+ headers["x-athena-jdbc-url"] = jdbcUrl;
972
+ }
973
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
974
+ headers["x-jdbc-url"] = jdbcUrl;
975
+ }
976
+ }
977
+ }
978
+ function buildAthenaRequestHeaders(input) {
979
+ const forceNoCache = Boolean(input.forceNoCache);
980
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
981
+ const rules = PROFILE_RULES[input.profile];
982
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
983
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
984
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
985
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
986
+ const headers = {
987
+ "X-Athena-Sdk": input.sdkHeaderValue
988
+ };
989
+ if (rules.contentType) {
990
+ headers["Content-Type"] = input.contentType ?? "application/json";
991
+ }
992
+ if (input.accept ?? rules.accept) {
993
+ headers.Accept = input.accept ?? "application/json";
994
+ }
995
+ if (rules.routing) {
996
+ if (normalizeHeaderValue(input.userId)) {
997
+ headers["X-User-Id"] = input.userId ?? "";
998
+ }
999
+ if (normalizeHeaderValue(input.organizationId)) {
1000
+ headers["X-Organization-Id"] = input.organizationId ?? "";
1001
+ }
1002
+ if (finalClient) {
1003
+ headers["X-Athena-Client"] = finalClient;
1004
+ }
1005
+ const backendType = resolveBackendType(input.backend);
1006
+ if (backendType) {
1007
+ headers["X-Backend-Type"] = backendType;
1008
+ }
1009
+ if (typeof input.stripNulls === "boolean") {
1010
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
1011
+ } else if (rules.stripNullsDefault) {
1012
+ headers["X-Strip-Nulls"] = "true";
1013
+ }
1014
+ if (normalizeHeaderValue(input.publishEvent)) {
1015
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
1016
+ }
1017
+ }
1018
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
1019
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
1020
+ }
1021
+ applyAthenaAuthContextHeaders(headers, input);
1022
+ applyAthenaPgUriHeaders(headers, input);
1023
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
1024
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1025
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
1026
+ return;
1027
+ }
1028
+ if (forceNoCache && isCacheControlHeaderName(key)) {
1029
+ return;
1030
+ }
1031
+ const normalized = normalizeHeaderValue(value);
1032
+ if (normalized) {
1033
+ headers[key] = normalized;
1034
+ }
1035
+ });
1036
+ if (forceNoCache) {
1037
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1038
+ }
1039
+ return headers;
1040
+ }
1041
+
1042
+ // package.json
1043
+ var package_default = {
1044
+ version: "2.12.0"
1045
+ };
1046
+
1047
+ // src/sdk-version.ts
1048
+ var PACKAGE_VERSION = package_default.version;
1049
+ function buildSdkHeaderValue(sdkName) {
1050
+ return `${sdkName} ${PACKAGE_VERSION}`;
1051
+ }
1052
+
1053
+ // src/gateway/client.ts
1054
+ var DEFAULT_CLIENT = "railway_direct";
1055
+ var SDK_NAME = "xylex-group/athena";
1056
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
1057
+ function parseResponseBody(rawText, contentType) {
1058
+ if (!rawText) {
1059
+ return { parsed: null, parseFailed: false };
1060
+ }
1061
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
1062
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
1063
+ if (!looksJson) {
1064
+ return { parsed: rawText, parseFailed: false };
1065
+ }
1066
+ try {
1067
+ return { parsed: JSON.parse(rawText), parseFailed: false };
1068
+ } catch {
1069
+ return { parsed: rawText, parseFailed: true };
1070
+ }
1071
+ }
875
1072
  function isRecord(value) {
876
1073
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
877
1074
  }
@@ -998,71 +1195,10 @@ function buildRpcGetEndpoint(payload) {
998
1195
  return withQuery;
999
1196
  }
1000
1197
  function buildHeaders(config, options) {
1001
- const mergedStripNulls = options?.stripNulls ?? true;
1002
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1003
- const extraHeaders = {
1004
- ...config.headers ?? {},
1005
- ...options?.headers ?? {}
1006
- };
1007
- const headerClient = extraHeaders["x-athena-client"] ?? extraHeaders["X-Athena-Client"];
1008
- const finalClient = options?.client ?? config.client ?? (typeof headerClient === "string" ? headerClient : void 0) ?? DEFAULT_CLIENT;
1009
- const finalApiKey = options?.apiKey ?? config.apiKey;
1010
- const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
1011
- const headers = {
1012
- "Content-Type": "application/json",
1013
- "X-Athena-Sdk": SDK_HEADER_VALUE
1014
- };
1015
- if (options?.userId ?? config.userId) {
1016
- headers["X-User-Id"] = options?.userId ?? config.userId ?? "";
1017
- }
1018
- if (options?.organizationId ?? config.organizationId) {
1019
- headers["X-Organization-Id"] = options?.organizationId ?? config.organizationId ?? "";
1020
- }
1021
- if (finalClient) {
1022
- headers["X-Athena-Client"] = finalClient;
1023
- }
1024
- const finalBackend = options?.backend ?? config.backend;
1025
- if (finalBackend) {
1026
- const type = typeof finalBackend === "string" ? finalBackend : finalBackend.type;
1027
- if (type) headers["X-Backend-Type"] = type;
1028
- }
1029
- if (typeof mergedStripNulls === "boolean") {
1030
- headers["X-Strip-Nulls"] = mergedStripNulls ? "true" : "false";
1031
- }
1032
- if (finalPublishEvent) {
1033
- headers["X-Publish-Event"] = finalPublishEvent;
1034
- }
1035
- if (finalApiKey) {
1036
- headers["apikey"] = finalApiKey;
1037
- headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
1038
- }
1039
- const explicitSessionToken = resolveHeaderValue(extraHeaders, [
1040
- "X-Athena-Auth-Session-Token"
1041
- ]);
1042
- const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(extraHeaders);
1043
- if (derivedSessionToken) {
1044
- headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
1045
- }
1046
- const explicitBearerToken = resolveHeaderValue(extraHeaders, [
1047
- "X-Athena-Auth-Bearer-Token"
1048
- ]);
1049
- const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(extraHeaders);
1050
- if (derivedBearerToken) {
1051
- headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
1052
- }
1053
- const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
1054
- Object.entries(extraHeaders).forEach(([key, value]) => {
1055
- if (athenaClientKeys.includes(key)) return;
1056
- if (forceNoCache && isCacheControlHeaderName(key)) return;
1057
- const normalized = normalizeHeaderValue(value);
1058
- if (normalized) {
1059
- headers[key] = normalized;
1060
- }
1198
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
1199
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
1200
+ stripNulls: options?.stripNulls ?? true
1061
1201
  });
1062
- if (forceNoCache) {
1063
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
1064
- }
1065
- return headers;
1066
1202
  }
1067
1203
  function toInvalidUrlResponse(error, endpoint, method) {
1068
1204
  const message = error instanceof Error ? error.message : String(error);
@@ -1790,19 +1926,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
1790
1926
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
1791
1927
  var SDK_NAME2 = "xylex-group/athena-auth";
1792
1928
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
1793
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
1794
1929
  function normalizeBaseUrl(baseUrl) {
1795
1930
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
1796
1931
  }
1797
1932
  function isRecord3(value) {
1798
1933
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1799
1934
  }
1800
- function normalizeHeaderValue2(value) {
1801
- return value ? value : void 0;
1802
- }
1803
- function isCacheControlHeaderName2(name) {
1804
- return name.toLowerCase() === "cache-control";
1805
- }
1806
1935
  function parseResponseBody2(rawText, contentType) {
1807
1936
  if (!rawText) {
1808
1937
  return { parsed: null, parseFailed: false };
@@ -1867,6 +1996,21 @@ function copyDefinedField(target, source, targetKey, sourceKey) {
1867
1996
  target[targetKey] = value;
1868
1997
  }
1869
1998
  }
1999
+ function normalizeEmailTemplateAttachmentsValue(value) {
2000
+ if (typeof value === "string" || value == null) {
2001
+ return value;
2002
+ }
2003
+ if (Array.isArray(value)) {
2004
+ return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
2005
+ }
2006
+ if (typeof value !== "object") {
2007
+ return value;
2008
+ }
2009
+ const attachment = { ...value };
2010
+ copyDefinedField(attachment, attachment, "file_url", "fileUrl");
2011
+ delete attachment.fileUrl;
2012
+ return attachment;
2013
+ }
1870
2014
  function normalizeAdminEmailTemplatePayload(payload) {
1871
2015
  const normalized = { ...payload };
1872
2016
  copyDefinedField(normalized, payload, "template_key", "templateKey");
@@ -1877,6 +2021,17 @@ function normalizeAdminEmailTemplatePayload(payload) {
1877
2021
  copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
1878
2022
  copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
1879
2023
  copyDefinedField(normalized, payload, "is_active", "isActive");
2024
+ if (Object.hasOwn(payload, "attachments")) {
2025
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
2026
+ }
2027
+ delete normalized.templateKey;
2028
+ delete normalized.eventType;
2029
+ delete normalized.subjectTemplate;
2030
+ delete normalized.textTemplate;
2031
+ delete normalized.htmlTemplate;
2032
+ delete normalized.variableBindings;
2033
+ delete normalized.attachmentFailureMode;
2034
+ delete normalized.isActive;
1880
2035
  return normalized;
1881
2036
  }
1882
2037
  function toReactEmailTemplateCompatibilityInput(input) {
@@ -1900,6 +2055,17 @@ function normalizeAdminEmailTemplateSendPayload(payload) {
1900
2055
  copyDefinedField(normalized, payload, "user_id", "userId");
1901
2056
  copyDefinedField(normalized, payload, "organization_id", "organizationId");
1902
2057
  copyDefinedField(normalized, payload, "session_token", "sessionToken");
2058
+ copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
2059
+ if (Object.hasOwn(payload, "attachments")) {
2060
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
2061
+ }
2062
+ delete normalized.templateId;
2063
+ delete normalized.recipientEmail;
2064
+ delete normalized.renderVariables;
2065
+ delete normalized.userId;
2066
+ delete normalized.organizationId;
2067
+ delete normalized.sessionToken;
2068
+ delete normalized.attachmentFailureMode;
1903
2069
  return normalized;
1904
2070
  }
1905
2071
  function toSessionGuardFailure(sessionResult) {
@@ -1965,45 +2131,7 @@ function extractFetchOptions(input) {
1965
2131
  };
1966
2132
  }
1967
2133
  function buildHeaders2(config, options) {
1968
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
1969
- const headers = {
1970
- "Content-Type": "application/json",
1971
- "X-Athena-Sdk": SDK_HEADER_VALUE2
1972
- };
1973
- const apiKey = options?.apiKey ?? config.apiKey;
1974
- if (apiKey) {
1975
- headers.apikey = apiKey;
1976
- headers["x-api-key"] = apiKey;
1977
- }
1978
- const bearerToken = options?.bearerToken ?? config.bearerToken;
1979
- if (bearerToken) {
1980
- headers.Authorization = `Bearer ${bearerToken}`;
1981
- }
1982
- const cookie = options?.cookie ?? config.cookie;
1983
- if (cookie) {
1984
- headers.Cookie = cookie;
1985
- }
1986
- const sessionToken = options?.sessionToken ?? config.sessionToken;
1987
- if (sessionToken) {
1988
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
1989
- }
1990
- const mergedExtraHeaders = {
1991
- ...config.headers ?? {},
1992
- ...options?.headers ?? {}
1993
- };
1994
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
1995
- if (forceNoCache && isCacheControlHeaderName2(key)) {
1996
- return;
1997
- }
1998
- const normalized = normalizeHeaderValue2(value);
1999
- if (normalized) {
2000
- headers[key] = normalized;
2001
- }
2002
- });
2003
- if (forceNoCache) {
2004
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
2005
- }
2006
- return headers;
2134
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
2007
2135
  }
2008
2136
  function appendQueryParam(searchParams, key, value) {
2009
2137
  if (value === void 0 || value === null) return;
@@ -5682,7 +5810,6 @@ function createStorageModule(gateway, runtimeOptions) {
5682
5810
  // src/chat/module.ts
5683
5811
  var SDK_NAME3 = "xylex-group/athena-chat";
5684
5812
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
5685
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
5686
5813
  var AthenaChatError = class extends Error {
5687
5814
  status;
5688
5815
  endpoint;
@@ -5728,9 +5855,6 @@ function normalizeWsUrl(value, label) {
5728
5855
  function isRecord7(value) {
5729
5856
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5730
5857
  }
5731
- function normalizeHeaderValue3(value) {
5732
- return value ? value : void 0;
5733
- }
5734
5858
  function parseResponseBody4(rawText, contentType) {
5735
5859
  if (!rawText) {
5736
5860
  return { parsed: null, parseFailed: false };
@@ -5802,39 +5926,7 @@ function createSocket(factory, url, protocols) {
5802
5926
  }
5803
5927
  }
5804
5928
  function buildHeaders3(config, options) {
5805
- const headers = {
5806
- Accept: "application/json",
5807
- apikey: config.apiKey,
5808
- "x-api-key": config.apiKey,
5809
- "X-Athena-Sdk": SDK_HEADER_VALUE3
5810
- };
5811
- if (config.client || options?.client) {
5812
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
5813
- }
5814
- const bearerToken = options?.bearerToken ?? config.bearerToken;
5815
- if (typeof bearerToken === "string" && bearerToken.trim()) {
5816
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
5817
- }
5818
- const cookie = options?.cookie ?? config.cookie;
5819
- if (typeof cookie === "string" && cookie.trim()) {
5820
- headers.Cookie = cookie;
5821
- }
5822
- const sessionToken = options?.sessionToken ?? config.sessionToken;
5823
- if (typeof sessionToken === "string" && sessionToken.trim()) {
5824
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
5825
- }
5826
- if (config.forceNoCache || options?.forceNoCache) {
5827
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
5828
- }
5829
- for (const source of [config.headers, options?.headers]) {
5830
- for (const [key, value] of Object.entries(source ?? {})) {
5831
- const normalized = normalizeHeaderValue3(value);
5832
- if (normalized) {
5833
- headers[key] = normalized;
5834
- }
5835
- }
5836
- }
5837
- return headers;
5929
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
5838
5930
  }
5839
5931
  function withJsonBody(init, body) {
5840
5932
  return {
@@ -6246,6 +6338,9 @@ var AthenaClientBuilderImpl = class {
6246
6338
  defaultOrganizationId;
6247
6339
  forceNoCacheEnabled = false;
6248
6340
  defaultHeaders;
6341
+ pgUriValue;
6342
+ jdbcUrlValue;
6343
+ athenaKeyValue;
6249
6344
  authConfig;
6250
6345
  dbUrlOverride;
6251
6346
  gatewayUrlOverride;
@@ -6272,6 +6367,18 @@ var AthenaClientBuilderImpl = class {
6272
6367
  this.defaultHeaders = headers;
6273
6368
  return this;
6274
6369
  }
6370
+ pgUri(pgUri) {
6371
+ this.pgUriValue = pgUri;
6372
+ return this;
6373
+ }
6374
+ jdbcUrl(jdbcUrl) {
6375
+ this.jdbcUrlValue = jdbcUrl;
6376
+ return this;
6377
+ }
6378
+ athenaKey(athenaKey) {
6379
+ this.athenaKeyValue = athenaKey;
6380
+ return this;
6381
+ }
6275
6382
  auth(config) {
6276
6383
  this.authConfig = mergeAuthClientConfig(this.authConfig, config);
6277
6384
  return this;
@@ -6308,6 +6415,15 @@ var AthenaClientBuilderImpl = class {
6308
6415
  if (options.headers !== void 0) {
6309
6416
  this.defaultHeaders = mergeHeaders(this.defaultHeaders, options.headers);
6310
6417
  }
6418
+ if (options.pgUri !== void 0) {
6419
+ this.pgUriValue = options.pgUri;
6420
+ }
6421
+ if (options.jdbcUrl !== void 0) {
6422
+ this.jdbcUrlValue = options.jdbcUrl;
6423
+ }
6424
+ if (options.athenaKey !== void 0) {
6425
+ this.athenaKeyValue = options.athenaKey;
6426
+ }
6311
6427
  if (options.auth !== void 0) {
6312
6428
  this.authConfig = mergeAuthClientConfig(this.authConfig, options.auth);
6313
6429
  }
@@ -6359,6 +6475,9 @@ var AthenaClientBuilderImpl = class {
6359
6475
  userId: this.defaultUserId,
6360
6476
  organizationId: this.defaultOrganizationId,
6361
6477
  forceNoCache: this.forceNoCacheEnabled,
6478
+ pgUri: this.pgUriValue,
6479
+ jdbcUrl: this.jdbcUrlValue,
6480
+ athenaKey: this.athenaKeyValue,
6362
6481
  backend: this.backendConfig,
6363
6482
  headers: this.defaultHeaders,
6364
6483
  db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
@@ -9071,10 +9190,6 @@ function resolveRequiredClientApiKey(value) {
9071
9190
  }
9072
9191
  return normalizedValue;
9073
9192
  }
9074
- function hasHeaderIgnoreCase(headers, targetKey) {
9075
- const normalizedTargetKey = targetKey.toLowerCase();
9076
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9077
- }
9078
9193
  function mergeClientHeaders(current, next) {
9079
9194
  if (!current && !next) {
9080
9195
  return void 0;
@@ -9205,6 +9320,9 @@ function resolveCreateClientConfig(config) {
9205
9320
  userId: config.userId,
9206
9321
  organizationId: config.organizationId,
9207
9322
  forceNoCache: config.forceNoCache,
9323
+ pgUri: config.pgUri,
9324
+ jdbcUrl: config.jdbcUrl,
9325
+ athenaKey: config.athenaKey,
9208
9326
  backend: toBackendConfig(config.backend),
9209
9327
  headers: config.headers,
9210
9328
  auth: config.auth,
@@ -9221,18 +9339,6 @@ function createClientFromInput(sourceConfig) {
9221
9339
  }
9222
9340
  function createClientFromConfig(config, sourceConfig) {
9223
9341
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
9224
- const gatewayHeaders = {
9225
- ...config.headers ?? {}
9226
- };
9227
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
9228
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9229
- }
9230
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
9231
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
9232
- }
9233
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
9234
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9235
- }
9236
9342
  const gateway = createAthenaGatewayClient({
9237
9343
  baseUrl: config.baseUrl,
9238
9344
  apiKey: config.apiKey,
@@ -9240,8 +9346,14 @@ function createClientFromConfig(config, sourceConfig) {
9240
9346
  userId: config.userId,
9241
9347
  organizationId: config.organizationId,
9242
9348
  forceNoCache: config.forceNoCache,
9349
+ pgUri: config.pgUri,
9350
+ jdbcUrl: config.jdbcUrl,
9351
+ athenaKey: config.athenaKey,
9243
9352
  backend: config.backend,
9244
- headers: gatewayHeaders
9353
+ bearerToken: normalizedAuthConfig?.bearerToken,
9354
+ cookie: normalizedAuthConfig?.cookie,
9355
+ sessionToken: normalizedAuthConfig?.sessionToken,
9356
+ headers: config.headers
9245
9357
  });
9246
9358
  const formatGatewayResult = createResultFormatter(config.experimental);
9247
9359
  const queryTracer = createQueryTracer(config.experimental);
@@ -9299,6 +9411,7 @@ function createClientFromConfig(config, sourceConfig) {
9299
9411
  const chat = createChatModule({
9300
9412
  baseUrl: config.chatUrl,
9301
9413
  apiKey: config.apiKey,
9414
+ athenaKey: config.athenaKey,
9302
9415
  client: config.client,
9303
9416
  headers: config.headers,
9304
9417
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9335,48 +9448,28 @@ function createClientFromConfig(config, sourceConfig) {
9335
9448
  return path.startsWith("/") ? path : `/${path}`;
9336
9449
  })();
9337
9450
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
9338
- const headers = {
9339
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
9340
- ...config.headers ?? {},
9341
- ...options.headers ?? {}
9342
- };
9343
- if (service !== "auth") {
9344
- headers.apikey = headers.apikey ?? config.apiKey;
9345
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
9346
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
9347
- headers["X-Athena-Client"] = config.client;
9348
- }
9349
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
9350
- headers["X-User-Id"] = config.userId;
9351
- }
9352
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
9353
- headers["X-Organization-Id"] = config.organizationId;
9354
- }
9355
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9356
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9357
- }
9358
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
9359
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9360
- }
9361
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9362
- headers.Cookie = normalizedAuthConfig.cookie;
9363
- }
9364
- } else {
9365
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
9366
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
9367
- headers.apikey = headers.apikey ?? authApiKey;
9368
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
9369
- }
9370
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
9371
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
9372
- }
9373
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9374
- headers.Cookie = normalizedAuthConfig.cookie;
9375
- }
9376
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9377
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9378
- }
9379
- }
9451
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
9452
+ const headers = buildAthenaRequestHeaders({
9453
+ profile: requestProfile,
9454
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
9455
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
9456
+ athenaKey: options.athenaKey ?? config.athenaKey,
9457
+ client: config.client,
9458
+ userId: config.userId,
9459
+ organizationId: config.organizationId,
9460
+ backend: config.backend,
9461
+ pgUri: config.pgUri,
9462
+ jdbcUrl: config.jdbcUrl,
9463
+ bearerToken: normalizedAuthConfig?.bearerToken,
9464
+ cookie: normalizedAuthConfig?.cookie,
9465
+ sessionToken: normalizedAuthConfig?.sessionToken,
9466
+ forceNoCache: config.forceNoCache,
9467
+ configHeaders: config.headers,
9468
+ callHeaders: options.headers,
9469
+ accept: service === "chat" ? "application/json" : void 0,
9470
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
9471
+ stripNulls: service === "db" ? true : void 0
9472
+ });
9380
9473
  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";
9381
9474
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9382
9475
  headers["Content-Type"] = "application/json";