@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
@@ -2002,42 +2002,31 @@ var getSessionCookie = (request2, config) => {
2002
2002
  return null;
2003
2003
  };
2004
2004
 
2005
- // package.json
2006
- var package_default = {
2007
- version: "2.10.0"
2008
- };
2009
-
2010
- // src/sdk-version.ts
2011
- var PACKAGE_VERSION = package_default.version;
2012
- function buildSdkHeaderValue(sdkName) {
2013
- return `${sdkName} ${PACKAGE_VERSION}`;
2014
- }
2015
-
2016
- // src/gateway/client.ts
2017
- var DEFAULT_CLIENT = "railway_direct";
2018
- var SDK_NAME = "xylex-group/athena";
2019
- var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
2005
+ // src/utils/athena-request-headers.ts
2020
2006
  var NO_CACHE_HEADER_VALUE = "no-cache";
2021
- function parseResponseBody(rawText, contentType) {
2022
- if (!rawText) {
2023
- return { parsed: null, parseFailed: false };
2024
- }
2025
- const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
2026
- const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
2027
- if (!looksJson) {
2028
- return { parsed: rawText, parseFailed: false };
2029
- }
2030
- try {
2031
- return { parsed: JSON.parse(rawText), parseFailed: false };
2032
- } catch {
2033
- return { parsed: rawText, parseFailed: true };
2034
- }
2035
- }
2007
+ var API_KEY_HEADER_CANDIDATES = ["x-api-key", "apikey"];
2008
+ var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
2009
+ var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
2010
+ var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
2011
+ var CLIENT_HEADER_CANDIDATES = ["X-Athena-Client", "x-athena-client"];
2012
+ var PG_URI_HEADER_CANDIDATES = ["x-pg-uri"];
2013
+ var JDBC_URI_HEADER_CANDIDATES = ["x-athena-jdbc-url", "x-jdbc-url"];
2014
+ var PROFILE_RULES = {
2015
+ gateway: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true, stripNullsDefault: true },
2016
+ chat: { apiKeys: true, routing: true, authMirror: true, authBearer: true, accept: true },
2017
+ storage: { apiKeys: true, routing: true, authMirror: true, authBearer: false, contentType: true },
2018
+ auth: { apiKeys: true, routing: false, authMirror: false, authBearer: true, contentType: true },
2019
+ minimal: { apiKeys: false, routing: false, authMirror: false, authBearer: false }
2020
+ };
2036
2021
  function normalizeHeaderValue(value) {
2037
2022
  return value ? value : void 0;
2038
2023
  }
2039
- function isCacheControlHeaderName(name) {
2040
- return name.toLowerCase() === "cache-control";
2024
+ function mergeExtraHeaders(configHeaders, callHeaders) {
2025
+ return { ...configHeaders ?? {}, ...callHeaders ?? {} };
2026
+ }
2027
+ function hasHeaderIgnoreCase(headers, targetKey) {
2028
+ const normalizedTargetKey = targetKey.toLowerCase();
2029
+ return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
2041
2030
  }
2042
2031
  function resolveHeaderValue(headers, candidates) {
2043
2032
  for (const candidate of candidates) {
@@ -2054,13 +2043,20 @@ function resolveHeaderValue(headers, candidates) {
2054
2043
  }
2055
2044
  return void 0;
2056
2045
  }
2046
+ function isCacheControlHeaderName(name) {
2047
+ return name.toLowerCase() === "cache-control";
2048
+ }
2049
+ function normalizeBearerToken(value) {
2050
+ const trimmed = value.trim();
2051
+ const match = trimmed.match(/^Bearer\s+(.+)$/i);
2052
+ return match?.[1]?.trim() ?? trimmed;
2053
+ }
2057
2054
  function resolveBearerTokenFromAuthorizationHeader(headers) {
2058
2055
  const authorization = resolveHeaderValue(headers, ["Authorization"]);
2059
2056
  if (!authorization) {
2060
2057
  return void 0;
2061
2058
  }
2062
- const match = authorization.match(/^Bearer\s+(.+)$/i);
2063
- const token = match?.[1]?.trim();
2059
+ const token = normalizeBearerToken(authorization);
2064
2060
  return token ? token : void 0;
2065
2061
  }
2066
2062
  function resolveSessionTokenFromCookieHeader(headers) {
@@ -2070,6 +2066,207 @@ function resolveSessionTokenFromCookieHeader(headers) {
2070
2066
  }
2071
2067
  return getSessionCookie(new Headers({ cookie })) ?? void 0;
2072
2068
  }
2069
+ function resolveBackendType(backend) {
2070
+ if (!backend) {
2071
+ return void 0;
2072
+ }
2073
+ return typeof backend === "string" ? backend : backend.type;
2074
+ }
2075
+ function resolveRequestHeaderOverrides(config, options, defaults) {
2076
+ return {
2077
+ apiKey: options?.apiKey ?? config.apiKey,
2078
+ athenaKey: options?.athenaKey ?? config.athenaKey,
2079
+ client: options?.client ?? config.client ?? defaults?.client,
2080
+ userId: options?.userId ?? config.userId,
2081
+ organizationId: options?.organizationId ?? config.organizationId,
2082
+ backend: options?.backend ?? config.backend,
2083
+ publishEvent: options?.publishEvent ?? config.publishEvent,
2084
+ stripNulls: options?.stripNulls ?? config.stripNulls ?? defaults?.stripNulls,
2085
+ bearerToken: options?.bearerToken ?? config.bearerToken,
2086
+ cookie: options?.cookie ?? config.cookie,
2087
+ sessionToken: options?.sessionToken ?? config.sessionToken,
2088
+ pgUri: options?.pgUri ?? config.pgUri,
2089
+ jdbcUrl: options?.jdbcUrl ?? config.jdbcUrl,
2090
+ forceNoCache: Boolean(config.forceNoCache || options?.forceNoCache),
2091
+ configHeaders: config.headers,
2092
+ callHeaders: options?.headers
2093
+ };
2094
+ }
2095
+ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, extras) {
2096
+ const rules = PROFILE_RULES[profile];
2097
+ return buildAthenaRequestHeaders({
2098
+ profile,
2099
+ sdkHeaderValue,
2100
+ ...resolveRequestHeaderOverrides(config, options, {
2101
+ client: extras?.client ?? void 0,
2102
+ stripNulls: extras?.stripNulls ?? (rules.stripNullsDefault ? true : void 0)
2103
+ }),
2104
+ contentType: extras?.contentType ?? (rules.contentType ? "application/json" : void 0),
2105
+ accept: extras?.accept ?? (rules.accept ? "application/json" : void 0)
2106
+ });
2107
+ }
2108
+ function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
2109
+ if (apiKey) {
2110
+ if (!hasHeaderIgnoreCase(headers, "apikey")) {
2111
+ headers.apikey = apiKey;
2112
+ }
2113
+ if (!hasHeaderIgnoreCase(headers, "x-api-key")) {
2114
+ headers["x-api-key"] = apiKey;
2115
+ }
2116
+ }
2117
+ const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
2118
+ if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
2119
+ headers["X-Athena-Key"] = resolvedAthenaKey;
2120
+ }
2121
+ }
2122
+ function applyAthenaAuthContextHeaders(headers, input) {
2123
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
2124
+ const rules = PROFILE_RULES[input.profile];
2125
+ const explicitCookie = normalizeHeaderValue(input.cookie);
2126
+ if (explicitCookie) {
2127
+ mergedExtraHeaders.Cookie = explicitCookie;
2128
+ }
2129
+ const explicitSessionToken = normalizeHeaderValue(input.sessionToken) ?? resolveHeaderValue(mergedExtraHeaders, SESSION_TOKEN_HEADER_CANDIDATES);
2130
+ const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(mergedExtraHeaders);
2131
+ const cookieFromHeaders = resolveHeaderValue(mergedExtraHeaders, ["Cookie"]);
2132
+ if (explicitCookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
2133
+ headers.Cookie = explicitCookie;
2134
+ } else if (cookieFromHeaders && !hasHeaderIgnoreCase(headers, "Cookie")) {
2135
+ headers.Cookie = cookieFromHeaders;
2136
+ }
2137
+ const explicitBearerToken = (() => {
2138
+ const configured = normalizeHeaderValue(input.bearerToken);
2139
+ if (configured) {
2140
+ return normalizeBearerToken(configured);
2141
+ }
2142
+ const mirrored = resolveHeaderValue(mergedExtraHeaders, BEARER_MIRROR_HEADER_CANDIDATES);
2143
+ return mirrored ? normalizeBearerToken(mirrored) : void 0;
2144
+ })();
2145
+ const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(mergedExtraHeaders);
2146
+ if (rules.authBearer && derivedBearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
2147
+ headers.Authorization = `Bearer ${derivedBearerToken}`;
2148
+ }
2149
+ if (rules.authMirror) {
2150
+ if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
2151
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
2152
+ }
2153
+ if (derivedBearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
2154
+ headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
2155
+ }
2156
+ } else if (derivedSessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
2157
+ headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
2158
+ }
2159
+ }
2160
+ function applyAthenaPgUriHeaders(headers, input) {
2161
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
2162
+ const pgUri = normalizeHeaderValue(input.pgUri) ?? resolveHeaderValue(mergedExtraHeaders, PG_URI_HEADER_CANDIDATES);
2163
+ if (pgUri && !hasHeaderIgnoreCase(headers, "x-pg-uri")) {
2164
+ headers["x-pg-uri"] = pgUri;
2165
+ }
2166
+ const jdbcUrl = normalizeHeaderValue(input.jdbcUrl) ?? resolveHeaderValue(mergedExtraHeaders, JDBC_URI_HEADER_CANDIDATES);
2167
+ if (jdbcUrl) {
2168
+ if (!hasHeaderIgnoreCase(headers, "x-athena-jdbc-url")) {
2169
+ headers["x-athena-jdbc-url"] = jdbcUrl;
2170
+ }
2171
+ if (!hasHeaderIgnoreCase(headers, "x-jdbc-url")) {
2172
+ headers["x-jdbc-url"] = jdbcUrl;
2173
+ }
2174
+ }
2175
+ }
2176
+ function buildAthenaRequestHeaders(input) {
2177
+ const forceNoCache = Boolean(input.forceNoCache);
2178
+ const mergedExtraHeaders = mergeExtraHeaders(input.configHeaders, input.callHeaders);
2179
+ const rules = PROFILE_RULES[input.profile];
2180
+ const headerClient = resolveHeaderValue(mergedExtraHeaders, CLIENT_HEADER_CANDIDATES);
2181
+ const finalClient = normalizeHeaderValue(input.client) ?? headerClient;
2182
+ const finalApiKey = normalizeHeaderValue(input.apiKey) ?? resolveHeaderValue(mergedExtraHeaders, API_KEY_HEADER_CANDIDATES);
2183
+ const finalAthenaKey = normalizeHeaderValue(input.athenaKey) ?? resolveHeaderValue(mergedExtraHeaders, ATHENA_KEY_HEADER_CANDIDATES) ?? finalApiKey;
2184
+ const headers = {
2185
+ "X-Athena-Sdk": input.sdkHeaderValue
2186
+ };
2187
+ if (rules.contentType) {
2188
+ headers["Content-Type"] = input.contentType ?? "application/json";
2189
+ }
2190
+ if (input.accept ?? rules.accept) {
2191
+ headers.Accept = input.accept ?? "application/json";
2192
+ }
2193
+ if (rules.routing) {
2194
+ if (normalizeHeaderValue(input.userId)) {
2195
+ headers["X-User-Id"] = input.userId ?? "";
2196
+ }
2197
+ if (normalizeHeaderValue(input.organizationId)) {
2198
+ headers["X-Organization-Id"] = input.organizationId ?? "";
2199
+ }
2200
+ if (finalClient) {
2201
+ headers["X-Athena-Client"] = finalClient;
2202
+ }
2203
+ const backendType = resolveBackendType(input.backend);
2204
+ if (backendType) {
2205
+ headers["X-Backend-Type"] = backendType;
2206
+ }
2207
+ if (typeof input.stripNulls === "boolean") {
2208
+ headers["X-Strip-Nulls"] = input.stripNulls ? "true" : "false";
2209
+ } else if (rules.stripNullsDefault) {
2210
+ headers["X-Strip-Nulls"] = "true";
2211
+ }
2212
+ if (normalizeHeaderValue(input.publishEvent)) {
2213
+ headers["X-Publish-Event"] = input.publishEvent ?? "";
2214
+ }
2215
+ }
2216
+ if (rules.apiKeys && (finalApiKey || finalAthenaKey)) {
2217
+ applyAthenaApiKeyHeaders(headers, finalApiKey, finalAthenaKey);
2218
+ }
2219
+ applyAthenaAuthContextHeaders(headers, input);
2220
+ applyAthenaPgUriHeaders(headers, input);
2221
+ const reservedClientHeaderKeys = new Set(CLIENT_HEADER_CANDIDATES.map((key) => key.toLowerCase()));
2222
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
2223
+ if (reservedClientHeaderKeys.has(key.toLowerCase())) {
2224
+ return;
2225
+ }
2226
+ if (forceNoCache && isCacheControlHeaderName(key)) {
2227
+ return;
2228
+ }
2229
+ const normalized = normalizeHeaderValue(value);
2230
+ if (normalized) {
2231
+ headers[key] = normalized;
2232
+ }
2233
+ });
2234
+ if (forceNoCache) {
2235
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
2236
+ }
2237
+ return headers;
2238
+ }
2239
+
2240
+ // package.json
2241
+ var package_default = {
2242
+ version: "2.12.0"
2243
+ };
2244
+
2245
+ // src/sdk-version.ts
2246
+ var PACKAGE_VERSION = package_default.version;
2247
+ function buildSdkHeaderValue(sdkName) {
2248
+ return `${sdkName} ${PACKAGE_VERSION}`;
2249
+ }
2250
+
2251
+ // src/gateway/client.ts
2252
+ var DEFAULT_CLIENT = "railway_direct";
2253
+ var SDK_NAME = "xylex-group/athena";
2254
+ var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
2255
+ function parseResponseBody(rawText, contentType) {
2256
+ if (!rawText) {
2257
+ return { parsed: null, parseFailed: false };
2258
+ }
2259
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
2260
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
2261
+ if (!looksJson) {
2262
+ return { parsed: rawText, parseFailed: false };
2263
+ }
2264
+ try {
2265
+ return { parsed: JSON.parse(rawText), parseFailed: false };
2266
+ } catch {
2267
+ return { parsed: rawText, parseFailed: true };
2268
+ }
2269
+ }
2073
2270
  function isRecord2(value) {
2074
2271
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2075
2272
  }
@@ -2196,71 +2393,10 @@ function buildRpcGetEndpoint(payload) {
2196
2393
  return withQuery;
2197
2394
  }
2198
2395
  function buildHeaders(config, options) {
2199
- const mergedStripNulls = options?.stripNulls ?? true;
2200
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
2201
- const extraHeaders = {
2202
- ...config.headers ?? {},
2203
- ...options?.headers ?? {}
2204
- };
2205
- const headerClient = extraHeaders["x-athena-client"] ?? extraHeaders["X-Athena-Client"];
2206
- const finalClient = options?.client ?? config.client ?? (typeof headerClient === "string" ? headerClient : void 0) ?? DEFAULT_CLIENT;
2207
- const finalApiKey = options?.apiKey ?? config.apiKey;
2208
- const finalPublishEvent = options?.publishEvent ?? config.publishEvent;
2209
- const headers = {
2210
- "Content-Type": "application/json",
2211
- "X-Athena-Sdk": SDK_HEADER_VALUE
2212
- };
2213
- if (options?.userId ?? config.userId) {
2214
- headers["X-User-Id"] = options?.userId ?? config.userId ?? "";
2215
- }
2216
- if (options?.organizationId ?? config.organizationId) {
2217
- headers["X-Organization-Id"] = options?.organizationId ?? config.organizationId ?? "";
2218
- }
2219
- if (finalClient) {
2220
- headers["X-Athena-Client"] = finalClient;
2221
- }
2222
- const finalBackend = options?.backend ?? config.backend;
2223
- if (finalBackend) {
2224
- const type = typeof finalBackend === "string" ? finalBackend : finalBackend.type;
2225
- if (type) headers["X-Backend-Type"] = type;
2226
- }
2227
- if (typeof mergedStripNulls === "boolean") {
2228
- headers["X-Strip-Nulls"] = mergedStripNulls ? "true" : "false";
2229
- }
2230
- if (finalPublishEvent) {
2231
- headers["X-Publish-Event"] = finalPublishEvent;
2232
- }
2233
- if (finalApiKey) {
2234
- headers["apikey"] = finalApiKey;
2235
- headers["x-api-key"] = headers["x-api-key"] ?? finalApiKey;
2236
- }
2237
- const explicitSessionToken = resolveHeaderValue(extraHeaders, [
2238
- "X-Athena-Auth-Session-Token"
2239
- ]);
2240
- const derivedSessionToken = explicitSessionToken ?? resolveSessionTokenFromCookieHeader(extraHeaders);
2241
- if (derivedSessionToken) {
2242
- headers["X-Athena-Auth-Session-Token"] = derivedSessionToken;
2243
- }
2244
- const explicitBearerToken = resolveHeaderValue(extraHeaders, [
2245
- "X-Athena-Auth-Bearer-Token"
2246
- ]);
2247
- const derivedBearerToken = explicitBearerToken ?? resolveBearerTokenFromAuthorizationHeader(extraHeaders);
2248
- if (derivedBearerToken) {
2249
- headers["X-Athena-Auth-Bearer-Token"] = derivedBearerToken;
2250
- }
2251
- const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
2252
- Object.entries(extraHeaders).forEach(([key, value]) => {
2253
- if (athenaClientKeys.includes(key)) return;
2254
- if (forceNoCache && isCacheControlHeaderName(key)) return;
2255
- const normalized = normalizeHeaderValue(value);
2256
- if (normalized) {
2257
- headers[key] = normalized;
2258
- }
2396
+ return buildServiceRequestHeaders("gateway", SDK_HEADER_VALUE, config, options, {
2397
+ client: options?.client ?? config.client ?? DEFAULT_CLIENT,
2398
+ stripNulls: options?.stripNulls ?? true
2259
2399
  });
2260
- if (forceNoCache) {
2261
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
2262
- }
2263
- return headers;
2264
2400
  }
2265
2401
  function toInvalidUrlResponse(error, endpoint, method) {
2266
2402
  const message = error instanceof Error ? error.message : String(error);
@@ -2917,19 +3053,12 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
2917
3053
  var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
2918
3054
  var SDK_NAME2 = "xylex-group/athena-auth";
2919
3055
  var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
2920
- var NO_CACHE_HEADER_VALUE2 = "no-cache";
2921
3056
  function normalizeBaseUrl(baseUrl) {
2922
3057
  return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
2923
3058
  }
2924
3059
  function isRecord4(value) {
2925
3060
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2926
3061
  }
2927
- function normalizeHeaderValue2(value) {
2928
- return value ? value : void 0;
2929
- }
2930
- function isCacheControlHeaderName2(name) {
2931
- return name.toLowerCase() === "cache-control";
2932
- }
2933
3062
  function parseResponseBody2(rawText, contentType) {
2934
3063
  if (!rawText) {
2935
3064
  return { parsed: null, parseFailed: false };
@@ -2994,6 +3123,21 @@ function copyDefinedField(target, source, targetKey, sourceKey) {
2994
3123
  target[targetKey] = value;
2995
3124
  }
2996
3125
  }
3126
+ function normalizeEmailTemplateAttachmentsValue(value) {
3127
+ if (typeof value === "string" || value == null) {
3128
+ return value;
3129
+ }
3130
+ if (Array.isArray(value)) {
3131
+ return value.map((item) => normalizeEmailTemplateAttachmentsValue(item));
3132
+ }
3133
+ if (typeof value !== "object") {
3134
+ return value;
3135
+ }
3136
+ const attachment = { ...value };
3137
+ copyDefinedField(attachment, attachment, "file_url", "fileUrl");
3138
+ delete attachment.fileUrl;
3139
+ return attachment;
3140
+ }
2997
3141
  function normalizeAdminEmailTemplatePayload(payload) {
2998
3142
  const normalized = { ...payload };
2999
3143
  copyDefinedField(normalized, payload, "template_key", "templateKey");
@@ -3004,6 +3148,17 @@ function normalizeAdminEmailTemplatePayload(payload) {
3004
3148
  copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
3005
3149
  copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
3006
3150
  copyDefinedField(normalized, payload, "is_active", "isActive");
3151
+ if (Object.hasOwn(payload, "attachments")) {
3152
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
3153
+ }
3154
+ delete normalized.templateKey;
3155
+ delete normalized.eventType;
3156
+ delete normalized.subjectTemplate;
3157
+ delete normalized.textTemplate;
3158
+ delete normalized.htmlTemplate;
3159
+ delete normalized.variableBindings;
3160
+ delete normalized.attachmentFailureMode;
3161
+ delete normalized.isActive;
3007
3162
  return normalized;
3008
3163
  }
3009
3164
  function toReactEmailTemplateCompatibilityInput(input) {
@@ -3027,6 +3182,17 @@ function normalizeAdminEmailTemplateSendPayload(payload) {
3027
3182
  copyDefinedField(normalized, payload, "user_id", "userId");
3028
3183
  copyDefinedField(normalized, payload, "organization_id", "organizationId");
3029
3184
  copyDefinedField(normalized, payload, "session_token", "sessionToken");
3185
+ copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
3186
+ if (Object.hasOwn(payload, "attachments")) {
3187
+ normalized.attachments = normalizeEmailTemplateAttachmentsValue(payload.attachments);
3188
+ }
3189
+ delete normalized.templateId;
3190
+ delete normalized.recipientEmail;
3191
+ delete normalized.renderVariables;
3192
+ delete normalized.userId;
3193
+ delete normalized.organizationId;
3194
+ delete normalized.sessionToken;
3195
+ delete normalized.attachmentFailureMode;
3030
3196
  return normalized;
3031
3197
  }
3032
3198
  function toSessionGuardFailure(sessionResult) {
@@ -3092,45 +3258,7 @@ function extractFetchOptions(input) {
3092
3258
  };
3093
3259
  }
3094
3260
  function buildHeaders2(config, options) {
3095
- const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
3096
- const headers = {
3097
- "Content-Type": "application/json",
3098
- "X-Athena-Sdk": SDK_HEADER_VALUE2
3099
- };
3100
- const apiKey = options?.apiKey ?? config.apiKey;
3101
- if (apiKey) {
3102
- headers.apikey = apiKey;
3103
- headers["x-api-key"] = apiKey;
3104
- }
3105
- const bearerToken = options?.bearerToken ?? config.bearerToken;
3106
- if (bearerToken) {
3107
- headers.Authorization = `Bearer ${bearerToken}`;
3108
- }
3109
- const cookie = options?.cookie ?? config.cookie;
3110
- if (cookie) {
3111
- headers.Cookie = cookie;
3112
- }
3113
- const sessionToken = options?.sessionToken ?? config.sessionToken;
3114
- if (sessionToken) {
3115
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
3116
- }
3117
- const mergedExtraHeaders = {
3118
- ...config.headers ?? {},
3119
- ...options?.headers ?? {}
3120
- };
3121
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
3122
- if (forceNoCache && isCacheControlHeaderName2(key)) {
3123
- return;
3124
- }
3125
- const normalized = normalizeHeaderValue2(value);
3126
- if (normalized) {
3127
- headers[key] = normalized;
3128
- }
3129
- });
3130
- if (forceNoCache) {
3131
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
3132
- }
3133
- return headers;
3261
+ return buildServiceRequestHeaders("auth", SDK_HEADER_VALUE2, config, options);
3134
3262
  }
3135
3263
  function appendQueryParam(searchParams, key, value) {
3136
3264
  if (value === void 0 || value === null) return;
@@ -6256,7 +6384,6 @@ function createStorageModule(gateway, runtimeOptions) {
6256
6384
  // src/chat/module.ts
6257
6385
  var SDK_NAME3 = "xylex-group/athena-chat";
6258
6386
  var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
6259
- var NO_CACHE_HEADER_VALUE3 = "no-cache";
6260
6387
  var AthenaChatError = class extends Error {
6261
6388
  status;
6262
6389
  endpoint;
@@ -6302,9 +6429,6 @@ function normalizeWsUrl(value, label) {
6302
6429
  function isRecord7(value) {
6303
6430
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6304
6431
  }
6305
- function normalizeHeaderValue3(value) {
6306
- return value ? value : void 0;
6307
- }
6308
6432
  function parseResponseBody4(rawText, contentType) {
6309
6433
  if (!rawText) {
6310
6434
  return { parsed: null, parseFailed: false };
@@ -6376,39 +6500,7 @@ function createSocket(factory, url, protocols) {
6376
6500
  }
6377
6501
  }
6378
6502
  function buildHeaders3(config, options) {
6379
- const headers = {
6380
- Accept: "application/json",
6381
- apikey: config.apiKey,
6382
- "x-api-key": config.apiKey,
6383
- "X-Athena-Sdk": SDK_HEADER_VALUE3
6384
- };
6385
- if (config.client || options?.client) {
6386
- headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
6387
- }
6388
- const bearerToken = options?.bearerToken ?? config.bearerToken;
6389
- if (typeof bearerToken === "string" && bearerToken.trim()) {
6390
- headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
6391
- }
6392
- const cookie = options?.cookie ?? config.cookie;
6393
- if (typeof cookie === "string" && cookie.trim()) {
6394
- headers.Cookie = cookie;
6395
- }
6396
- const sessionToken = options?.sessionToken ?? config.sessionToken;
6397
- if (typeof sessionToken === "string" && sessionToken.trim()) {
6398
- headers["X-Athena-Auth-Session-Token"] = sessionToken;
6399
- }
6400
- if (config.forceNoCache || options?.forceNoCache) {
6401
- headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
6402
- }
6403
- for (const source of [config.headers, options?.headers]) {
6404
- for (const [key, value] of Object.entries(source ?? {})) {
6405
- const normalized = normalizeHeaderValue3(value);
6406
- if (normalized) {
6407
- headers[key] = normalized;
6408
- }
6409
- }
6410
- }
6411
- return headers;
6503
+ return buildServiceRequestHeaders("chat", SDK_HEADER_VALUE3, config, options);
6412
6504
  }
6413
6505
  function withJsonBody(init, body) {
6414
6506
  return {
@@ -9402,10 +9494,6 @@ function resolveRequiredClientApiKey(value) {
9402
9494
  }
9403
9495
  return normalizedValue;
9404
9496
  }
9405
- function hasHeaderIgnoreCase(headers, targetKey) {
9406
- const normalizedTargetKey = targetKey.toLowerCase();
9407
- return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
9408
- }
9409
9497
  function mergeClientHeaders(current, next) {
9410
9498
  if (!current && !next) {
9411
9499
  return void 0;
@@ -9536,6 +9624,9 @@ function resolveCreateClientConfig(config) {
9536
9624
  userId: config.userId,
9537
9625
  organizationId: config.organizationId,
9538
9626
  forceNoCache: config.forceNoCache,
9627
+ pgUri: config.pgUri,
9628
+ jdbcUrl: config.jdbcUrl,
9629
+ athenaKey: config.athenaKey,
9539
9630
  backend: toBackendConfig(config.backend),
9540
9631
  headers: config.headers,
9541
9632
  auth: config.auth,
@@ -9552,18 +9643,6 @@ function createClientFromInput(sourceConfig) {
9552
9643
  }
9553
9644
  function createClientFromConfig(config, sourceConfig) {
9554
9645
  const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
9555
- const gatewayHeaders = {
9556
- ...config.headers ?? {}
9557
- };
9558
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
9559
- gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9560
- }
9561
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
9562
- gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
9563
- }
9564
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
9565
- gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9566
- }
9567
9646
  const gateway = createAthenaGatewayClient({
9568
9647
  baseUrl: config.baseUrl,
9569
9648
  apiKey: config.apiKey,
@@ -9571,8 +9650,14 @@ function createClientFromConfig(config, sourceConfig) {
9571
9650
  userId: config.userId,
9572
9651
  organizationId: config.organizationId,
9573
9652
  forceNoCache: config.forceNoCache,
9653
+ pgUri: config.pgUri,
9654
+ jdbcUrl: config.jdbcUrl,
9655
+ athenaKey: config.athenaKey,
9574
9656
  backend: config.backend,
9575
- headers: gatewayHeaders
9657
+ bearerToken: normalizedAuthConfig?.bearerToken,
9658
+ cookie: normalizedAuthConfig?.cookie,
9659
+ sessionToken: normalizedAuthConfig?.sessionToken,
9660
+ headers: config.headers
9576
9661
  });
9577
9662
  const formatGatewayResult = createResultFormatter(config.experimental);
9578
9663
  const queryTracer = createQueryTracer(config.experimental);
@@ -9630,6 +9715,7 @@ function createClientFromConfig(config, sourceConfig) {
9630
9715
  const chat = createChatModule({
9631
9716
  baseUrl: config.chatUrl,
9632
9717
  apiKey: config.apiKey,
9718
+ athenaKey: config.athenaKey,
9633
9719
  client: config.client,
9634
9720
  headers: config.headers,
9635
9721
  bearerToken: normalizedAuthConfig?.bearerToken,
@@ -9666,48 +9752,28 @@ function createClientFromConfig(config, sourceConfig) {
9666
9752
  return path.startsWith("/") ? path : `/${path}`;
9667
9753
  })();
9668
9754
  const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
9669
- const headers = {
9670
- "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
9671
- ...config.headers ?? {},
9672
- ...options.headers ?? {}
9673
- };
9674
- if (service !== "auth") {
9675
- headers.apikey = headers.apikey ?? config.apiKey;
9676
- headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
9677
- if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
9678
- headers["X-Athena-Client"] = config.client;
9679
- }
9680
- if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
9681
- headers["X-User-Id"] = config.userId;
9682
- }
9683
- if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
9684
- headers["X-Organization-Id"] = config.organizationId;
9685
- }
9686
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9687
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9688
- }
9689
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
9690
- headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
9691
- }
9692
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9693
- headers.Cookie = normalizedAuthConfig.cookie;
9694
- }
9695
- } else {
9696
- const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
9697
- if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
9698
- headers.apikey = headers.apikey ?? authApiKey;
9699
- headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
9700
- }
9701
- if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
9702
- headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
9703
- }
9704
- if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
9705
- headers.Cookie = normalizedAuthConfig.cookie;
9706
- }
9707
- if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
9708
- headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
9709
- }
9710
- }
9755
+ const requestProfile = service === "auth" ? "auth" : service === "chat" ? "chat" : service === "storage" ? "storage" : "gateway";
9756
+ const headers = buildAthenaRequestHeaders({
9757
+ profile: requestProfile,
9758
+ sdkHeaderValue: buildSdkHeaderValue(SDK_NAME4),
9759
+ apiKey: options.apiKey ?? (service === "auth" ? normalizedAuthConfig?.apiKey ?? config.apiKey : config.apiKey),
9760
+ athenaKey: options.athenaKey ?? config.athenaKey,
9761
+ client: config.client,
9762
+ userId: config.userId,
9763
+ organizationId: config.organizationId,
9764
+ backend: config.backend,
9765
+ pgUri: config.pgUri,
9766
+ jdbcUrl: config.jdbcUrl,
9767
+ bearerToken: normalizedAuthConfig?.bearerToken,
9768
+ cookie: normalizedAuthConfig?.cookie,
9769
+ sessionToken: normalizedAuthConfig?.sessionToken,
9770
+ forceNoCache: config.forceNoCache,
9771
+ configHeaders: config.headers,
9772
+ callHeaders: options.headers,
9773
+ accept: service === "chat" ? "application/json" : void 0,
9774
+ contentType: service === "auth" || service === "db" || service === "storage" ? "application/json" : void 0,
9775
+ stripNulls: service === "db" ? true : void 0
9776
+ });
9711
9777
  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";
9712
9778
  if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
9713
9779
  headers["Content-Type"] = "application/json";