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