@xylex-group/athena 2.12.1 → 2.14.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 (96) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +1190 -1184
  3. package/bin/athena-js.js +104 -76
  4. package/dist/admin.cjs +45 -0
  5. package/dist/admin.cjs.map +1 -0
  6. package/dist/admin.d.cts +64 -0
  7. package/dist/admin.d.ts +64 -0
  8. package/dist/admin.js +41 -0
  9. package/dist/admin.js.map +1 -0
  10. package/dist/athena-auth-url-oLux_57a.d.cts +377 -0
  11. package/dist/athena-auth-url-oLux_57a.d.ts +377 -0
  12. package/dist/browser.cjs +580 -96
  13. package/dist/browser.cjs.map +1 -1
  14. package/dist/browser.d.cts +12 -10
  15. package/dist/browser.d.ts +12 -10
  16. package/dist/browser.js +580 -96
  17. package/dist/browser.js.map +1 -1
  18. package/dist/cli/index.cjs +690 -91
  19. package/dist/cli/index.cjs.map +1 -1
  20. package/dist/cli/index.d.cts +14 -5
  21. package/dist/cli/index.d.ts +14 -5
  22. package/dist/cli/index.js +690 -92
  23. package/dist/cli/index.js.map +1 -1
  24. package/dist/{client-CMtx5P4D.d.cts → client-uthENhaf.d.ts} +346 -1488
  25. package/dist/{client-Dre8H24u.d.ts → client-wU2J9yqb.d.cts} +346 -1488
  26. package/dist/cookies.cjs +18 -0
  27. package/dist/cookies.cjs.map +1 -1
  28. package/dist/cookies.d.cts +2 -1
  29. package/dist/cookies.d.ts +2 -1
  30. package/dist/cookies.js +17 -1
  31. package/dist/cookies.js.map +1 -1
  32. package/dist/{index-CVcQCGyG.d.ts → index-CFL9xbFR.d.cts} +2 -0
  33. package/dist/{index-CVcQCGyG.d.cts → index-UKJpunc6.d.ts} +2 -0
  34. package/dist/index.cjs +648 -96
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +13 -10
  37. package/dist/index.d.ts +13 -10
  38. package/dist/index.js +648 -97
  39. package/dist/index.js.map +1 -1
  40. package/dist/{model-form-DfTi8-D1.d.cts → model-form-BE1_Bmdd.d.cts} +2 -2
  41. package/dist/{model-form-CU0mWrF9.d.ts → model-form-DcH3R7WD.d.ts} +2 -2
  42. package/dist/{module-DBGmbIuh.d.ts → module-Ca3_OQqR.d.ts} +12 -9
  43. package/dist/{module-GoijrBXV.d.cts → module-DFGZXCtt.d.cts} +12 -9
  44. package/dist/next/client.cjs +992 -89
  45. package/dist/next/client.cjs.map +1 -1
  46. package/dist/next/client.d.cts +7 -4
  47. package/dist/next/client.d.ts +7 -4
  48. package/dist/next/client.js +970 -90
  49. package/dist/next/client.js.map +1 -1
  50. package/dist/next/server.cjs +832 -89
  51. package/dist/next/server.cjs.map +1 -1
  52. package/dist/next/server.d.cts +81 -5
  53. package/dist/next/server.d.ts +81 -5
  54. package/dist/next/server.js +820 -90
  55. package/dist/next/server.js.map +1 -1
  56. package/dist/organization.cjs +72 -0
  57. package/dist/organization.cjs.map +1 -0
  58. package/dist/organization.d.cts +43 -0
  59. package/dist/organization.d.ts +43 -0
  60. package/dist/organization.js +70 -0
  61. package/dist/organization.js.map +1 -0
  62. package/dist/payload-BbSCmILD.d.ts +219 -0
  63. package/dist/payload-zXIwKTQf.d.cts +219 -0
  64. package/dist/{pipeline-c7Gdm0qv.d.cts → pipeline-CwQoD5G9.d.cts} +1 -1
  65. package/dist/{pipeline-DrjU2vNA.d.ts → pipeline-DqwehoQV.d.ts} +1 -1
  66. package/dist/react.cjs +2 -13
  67. package/dist/react.cjs.map +1 -1
  68. package/dist/react.d.cts +26 -7
  69. package/dist/react.d.ts +26 -7
  70. package/dist/react.js +2 -13
  71. package/dist/react.js.map +1 -1
  72. package/dist/session-cookie-detection-BqOp9mO6.d.cts +46 -0
  73. package/dist/session-cookie-detection-BqOp9mO6.d.ts +46 -0
  74. package/dist/social-providers.cjs +4198 -0
  75. package/dist/social-providers.cjs.map +1 -0
  76. package/dist/social-providers.d.cts +4948 -0
  77. package/dist/social-providers.d.ts +4948 -0
  78. package/dist/social-providers.js +4126 -0
  79. package/dist/social-providers.js.map +1 -0
  80. package/dist/{types-kPaHUqUa.d.ts → types-6H575ITc.d.cts} +50 -2
  81. package/dist/{types-DRRb0Fd0.d.ts → types-C1swabT5.d.ts} +3 -3
  82. package/dist/{types-Bez4HSbI.d.cts → types-CD6K05JQ.d.ts} +50 -2
  83. package/dist/{types-BRUHGXo2.d.ts → types-YQUR7wu0.d.cts} +3 -3
  84. package/dist/{types-BRUHGXo2.d.cts → types-YQUR7wu0.d.ts} +3 -3
  85. package/dist/{types-BLizCLd1.d.cts → types-dHnjluBC.d.cts} +3 -3
  86. package/dist/types-eAKAh71s.d.cts +1476 -0
  87. package/dist/types-eAKAh71s.d.ts +1476 -0
  88. package/dist/utils.cjs +438 -15
  89. package/dist/utils.cjs.map +1 -1
  90. package/dist/utils.d.cts +76 -11
  91. package/dist/utils.d.ts +76 -11
  92. package/dist/utils.js +390 -16
  93. package/dist/utils.js.map +1 -1
  94. package/package.json +29 -1
  95. package/dist/shared-DZSGAmXs.d.cts +0 -35
  96. package/dist/shared-MMnVBBfy.d.ts +0 -35
@@ -136,6 +136,22 @@ function parseCookies(cookieHeader) {
136
136
  });
137
137
  return cookieMap;
138
138
  }
139
+
140
+ // src/cookies/session-cookie-detection.ts
141
+ var SESSION_COOKIE_PATTERNS = [
142
+ /(?:^|;\s*)(?:__Secure-)?better-auth\.session_token=/,
143
+ /(?:^|;\s*)(?:__Secure-)?better-auth-session_token=/,
144
+ /(?:^|;\s*)(?:__Secure-)?athena-auth\.session-token=/,
145
+ /(?:^|;\s*)(?:__Secure-)?athena-auth-session-token=/,
146
+ /(?:^|;\s*)(?:__Secure-)?athena-auth\.session_token=/,
147
+ /(?:^|;\s*)(?:__Secure-)?athena-auth-session_token=/
148
+ ];
149
+ function hasAuthSessionCookie(cookieHeader) {
150
+ if (!cookieHeader) {
151
+ return false;
152
+ }
153
+ return SESSION_COOKIE_PATTERNS.some((pattern) => pattern.test(cookieHeader));
154
+ }
139
155
  var getSessionCookie = (request2, config) => {
140
156
  const cookies = (request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers).get("cookie");
141
157
  if (!cookies) {
@@ -160,7 +176,7 @@ var getSessionCookie = (request2, config) => {
160
176
 
161
177
  // src/utils/athena-request-headers.ts
162
178
  var NO_CACHE_HEADER_VALUE = "no-cache";
163
- var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
179
+ var API_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key", "X-Api-Key", "x-api-key", "apikey"];
164
180
  var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
165
181
  var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
166
182
  var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
@@ -262,17 +278,6 @@ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, ex
262
278
  });
263
279
  }
264
280
  function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
265
- if (apiKey) {
266
- if (!hasHeaderIgnoreCase(headers, "apikey")) {
267
- headers.apikey = apiKey;
268
- }
269
- if (!Object.hasOwn(headers, "x-api-key")) {
270
- headers["x-api-key"] = apiKey;
271
- }
272
- if (!Object.hasOwn(headers, "X-Api-Key")) {
273
- headers["X-Api-Key"] = apiKey;
274
- }
275
- }
276
281
  const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
277
282
  if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
278
283
  headers["X-Athena-Key"] = resolvedAthenaKey;
@@ -398,7 +403,7 @@ function buildAthenaRequestHeaders(input) {
398
403
 
399
404
  // package.json
400
405
  var package_default = {
401
- version: "2.12.1"
406
+ version: "2.14.0"
402
407
  };
403
408
 
404
409
  // src/sdk-version.ts
@@ -2827,39 +2832,224 @@ async function withRetry(config, fn) {
2827
2832
  throw new Error("withRetry reached an unexpected state");
2828
2833
  }
2829
2834
 
2830
- // src/db/module.ts
2831
- function createDbModule(input) {
2832
- const db = {
2833
- from: input.from,
2834
- select(table, first, second) {
2835
- if (first && typeof first === "object" && !Array.isArray(first)) {
2836
- return input.from(table).select(void 0, first);
2835
+ // src/storage/direct-upload.ts
2836
+ var SERVICE = "s3";
2837
+ var TERMINATOR = "aws4_request";
2838
+ async function putDirectStorageUploadBody(config, bucket, storageKey, body, uploadHeaders, signal, onProgress) {
2839
+ if (config.bucket && bucket && config.bucket !== bucket) {
2840
+ throw new Error(
2841
+ `athena.storage.file.upload direct mode bucket mismatch: configured ${config.bucket} but Athena returned ${bucket}`
2842
+ );
2843
+ }
2844
+ const target = createDirectUploadTarget(config, bucket, storageKey);
2845
+ const bytes = await bodyToArrayBuffer(body);
2846
+ const payloadHash = await sha256Hex(bytes);
2847
+ const headers = new Headers(uploadHeaders);
2848
+ if (isBlobBody(body) && body.type && !headers.has("Content-Type")) {
2849
+ headers.set("Content-Type", body.type);
2850
+ }
2851
+ const signed = await signDirectUploadRequest(config, target, headers, payloadHash);
2852
+ if (typeof XMLHttpRequest !== "undefined") {
2853
+ return putWithXhr(target.toString(), signed, body, signal, onProgress);
2854
+ }
2855
+ onProgress({ loaded: 0 });
2856
+ const response = await fetch(target, {
2857
+ method: "PUT",
2858
+ headers: signed.requestHeaders,
2859
+ body,
2860
+ signal
2861
+ });
2862
+ if (!response.ok) {
2863
+ throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
2864
+ }
2865
+ onProgress({ loaded: bytes.byteLength });
2866
+ return response;
2867
+ }
2868
+ function createDirectUploadTarget(config, bucket, storageKey) {
2869
+ const resolvedBucket = config.bucket ?? bucket;
2870
+ if (!resolvedBucket?.trim()) {
2871
+ throw new Error(
2872
+ "athena.storage.file.upload direct mode requires a bucket in experimental.directStorageUpload or the server upload response"
2873
+ );
2874
+ }
2875
+ if (!storageKey.trim()) {
2876
+ throw new Error("athena.storage.file.upload direct mode requires a storage key");
2877
+ }
2878
+ let endpoint;
2879
+ try {
2880
+ endpoint = new URL(config.endpoint);
2881
+ } catch (error) {
2882
+ throw new Error(
2883
+ `athena.storage.file.upload direct mode received an invalid endpoint: ${error instanceof Error ? error.message : String(error)}`
2884
+ );
2885
+ }
2886
+ if (endpoint.search || endpoint.hash) {
2887
+ throw new Error("athena.storage.file.upload direct mode endpoint must not contain a query or hash");
2888
+ }
2889
+ const endpointPath = endpoint.pathname.replace(/\/+$/, "");
2890
+ const pathParts = config.forcePathStyle === false ? [endpointPath, storageKey] : [endpointPath, resolvedBucket, storageKey];
2891
+ if (config.forcePathStyle === false) {
2892
+ endpoint.hostname = `${resolvedBucket}.${endpoint.hostname}`;
2893
+ }
2894
+ endpoint.pathname = pathParts.filter(Boolean).flatMap((part) => part.split("/")).map(awsEncode).join("/").replace(/^([^/])/, "/$1");
2895
+ return endpoint;
2896
+ }
2897
+ async function signDirectUploadRequest(config, target, inputHeaders, payloadHash) {
2898
+ const accessKeyId = config.accessKeyId.trim();
2899
+ const secretAccessKey = config.secretAccessKey.trim();
2900
+ if (!accessKeyId || !secretAccessKey) {
2901
+ throw new Error(
2902
+ "athena.storage.file.upload direct mode requires accessKeyId and secretAccessKey"
2903
+ );
2904
+ }
2905
+ const now = /* @__PURE__ */ new Date();
2906
+ const amzDate = formatAmzDate(now);
2907
+ const shortDate = amzDate.slice(0, 8);
2908
+ const region = config.region?.trim() || "auto";
2909
+ const headers = {};
2910
+ inputHeaders.forEach((value, key) => {
2911
+ if (key.toLowerCase() !== "authorization" && key.toLowerCase() !== "host") {
2912
+ headers[key.toLowerCase()] = value.trim().replace(/\s+/g, " ");
2913
+ }
2914
+ });
2915
+ headers["x-amz-content-sha256"] = payloadHash;
2916
+ headers["x-amz-date"] = amzDate;
2917
+ if (config.sessionToken?.trim()) {
2918
+ headers["x-amz-security-token"] = config.sessionToken.trim();
2919
+ }
2920
+ const canonicalHeaders = Object.keys(headers).sort().map((key) => `${key}:${headers[key]}
2921
+ `).join("");
2922
+ const signedHeaders = Object.keys(headers).sort().join(";");
2923
+ const canonicalRequest = [
2924
+ "PUT",
2925
+ target.pathname,
2926
+ "",
2927
+ `host:${target.host}
2928
+ ${canonicalHeaders}`,
2929
+ `host;${signedHeaders}`,
2930
+ payloadHash
2931
+ ].join("\n");
2932
+ const credentialScope = `${shortDate}/${region}/${SERVICE}/${TERMINATOR}`;
2933
+ const stringToSign = [
2934
+ "AWS4-HMAC-SHA256",
2935
+ amzDate,
2936
+ credentialScope,
2937
+ await sha256Hex(canonicalRequest)
2938
+ ].join("\n");
2939
+ const dateKey = await hmac(`AWS4${secretAccessKey}`, shortDate);
2940
+ const regionKey = await hmac(dateKey, region);
2941
+ const serviceKey = await hmac(regionKey, SERVICE);
2942
+ const signingKey = await hmac(serviceKey, TERMINATOR);
2943
+ const signature = await hmacHex(signingKey, stringToSign);
2944
+ headers.authorization = `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=host;${signedHeaders}, Signature=${signature}`;
2945
+ return { requestHeaders: headers };
2946
+ }
2947
+ async function putWithXhr(url, signed, body, signal, onProgress) {
2948
+ const Xhr = XMLHttpRequest;
2949
+ if (Xhr === void 0) {
2950
+ return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
2951
+ }
2952
+ return new Promise((resolve, reject) => {
2953
+ const xhr = new Xhr();
2954
+ const abort = () => xhr.abort();
2955
+ xhr.open("PUT", url);
2956
+ Object.entries(signed.requestHeaders).forEach(([key, value]) => xhr.setRequestHeader(key, value));
2957
+ xhr.upload.onprogress = (event) => onProgress({ loaded: event.loaded });
2958
+ xhr.onload = () => {
2959
+ signal?.removeEventListener("abort", abort);
2960
+ if (xhr.status < 200 || xhr.status >= 300) {
2961
+ reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
2962
+ return;
2837
2963
  }
2838
- return input.from(table).select(first, second);
2839
- },
2840
- insert(table, values, options) {
2841
- return Array.isArray(values) ? input.from(table).insert(values, options) : input.from(table).insert(values, options);
2842
- },
2843
- upsert(table, values, options) {
2844
- return Array.isArray(values) ? input.from(table).upsert(values, options) : input.from(table).upsert(values, options);
2845
- },
2846
- update(table, values, options) {
2847
- return input.from(table).update(values, options);
2848
- },
2849
- delete(table, options) {
2850
- return input.from(table).delete(options);
2851
- },
2852
- rpc(fn, args, options) {
2853
- return input.rpc(fn, args, options);
2854
- },
2855
- query(query, options) {
2856
- return input.query(query, options);
2964
+ onProgress({ loaded: bodySize(body) });
2965
+ resolve(new Response(xhr.response, {
2966
+ status: xhr.status,
2967
+ statusText: xhr.statusText,
2968
+ headers: parseXhrHeaders(xhr.getAllResponseHeaders())
2969
+ }));
2970
+ };
2971
+ xhr.onerror = () => {
2972
+ signal?.removeEventListener("abort", abort);
2973
+ reject(new Error("athena.storage.file.upload failed with a network error"));
2974
+ };
2975
+ xhr.onabort = () => {
2976
+ signal?.removeEventListener("abort", abort);
2977
+ reject(new DOMException("Upload aborted", "AbortError"));
2978
+ };
2979
+ if (signal) {
2980
+ if (signal.aborted) {
2981
+ abort();
2982
+ return;
2983
+ }
2984
+ signal.addEventListener("abort", abort, { once: true });
2857
2985
  }
2858
- };
2859
- return db;
2986
+ xhr.send(body);
2987
+ });
2988
+ }
2989
+ function isBlobBody(body) {
2990
+ return typeof Blob !== "undefined" && body instanceof Blob;
2991
+ }
2992
+ async function bodyToArrayBuffer(body) {
2993
+ if (isBlobBody(body)) return body.arrayBuffer();
2994
+ if (body instanceof ArrayBuffer) return body;
2995
+ if (ArrayBuffer.isView(body)) {
2996
+ return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
2997
+ }
2998
+ throw new Error("athena.storage.file.upload direct mode does not support ReadableStream bodies");
2999
+ }
3000
+ function bodySize(body) {
3001
+ if (isBlobBody(body)) return body.size;
3002
+ if (body instanceof ArrayBuffer) return body.byteLength;
3003
+ if (ArrayBuffer.isView(body)) return body.byteLength;
3004
+ return 0;
3005
+ }
3006
+ function awsEncode(value) {
3007
+ return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
3008
+ }
3009
+ function formatAmzDate(date) {
3010
+ return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
3011
+ }
3012
+ async function sha256Hex(value) {
3013
+ const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
3014
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
3015
+ return toHex(new Uint8Array(digest));
3016
+ }
3017
+ async function hmac(key, value) {
3018
+ const keyBytes = typeof key === "string" ? new TextEncoder().encode(key) : key;
3019
+ const cryptoKey = await crypto.subtle.importKey(
3020
+ "raw",
3021
+ keyBytes,
3022
+ { name: "HMAC", hash: "SHA-256" },
3023
+ false,
3024
+ ["sign"]
3025
+ );
3026
+ return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
3027
+ }
3028
+ async function hmacHex(key, value) {
3029
+ return toHex(new Uint8Array(await hmac(key, value)));
3030
+ }
3031
+ function toHex(bytes) {
3032
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
3033
+ }
3034
+ function parseXhrHeaders(rawHeaders) {
3035
+ const headers = new Headers();
3036
+ rawHeaders.trim().split(/[\r\n]+/).forEach((line) => {
3037
+ const separator = line.indexOf(":");
3038
+ if (separator > 0) {
3039
+ headers.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
3040
+ }
3041
+ });
3042
+ return headers;
2860
3043
  }
2861
3044
 
2862
3045
  // src/storage/file.ts
3046
+ function mergeUploadHeaders(serverHeaders, inputHeaders) {
3047
+ const headers = { ...serverHeaders };
3048
+ new Headers(inputHeaders).forEach((value, key) => {
3049
+ headers[key] = value;
3050
+ });
3051
+ return headers;
3052
+ }
2863
3053
  function createStorageFileModule(base, config = {}) {
2864
3054
  const upload = async (input, options) => {
2865
3055
  const sources = normalizeUploadSources(input);
@@ -2895,16 +3085,25 @@ function createStorageFileModule(base, config = {}) {
2895
3085
  for (let index = 0; index < uploadRequests.length; index += 1) {
2896
3086
  const request2 = uploadRequests[index];
2897
3087
  const uploadUrl = uploadUrls[index];
2898
- const response = await putUploadBody(
3088
+ const aggregateProgress = (progress) => {
3089
+ aggregateLoaded[index] = progress.loaded;
3090
+ input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
3091
+ };
3092
+ const response = config.directUpload ? await putDirectStorageUploadBody(
3093
+ config.directUpload,
3094
+ uploadUrl.upload.bucket,
3095
+ uploadUrl.upload.storage_key,
3096
+ request2.source.source,
3097
+ mergeUploadHeaders(uploadUrl.upload.headers ?? {}, input.uploadHeaders),
3098
+ options?.signal,
3099
+ aggregateProgress
3100
+ ) : await putUploadBody(
2899
3101
  uploadUrl.upload.url,
2900
3102
  uploadUrl.upload.headers ?? {},
2901
3103
  request2.source,
2902
3104
  input,
2903
3105
  options,
2904
- (progress) => {
2905
- aggregateLoaded[index] = progress.loaded;
2906
- input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
2907
- }
3106
+ aggregateProgress
2908
3107
  );
2909
3108
  uploaded.push({
2910
3109
  file: uploadUrl.file,
@@ -3055,7 +3254,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
3055
3254
  resolve(new Response(xhr.response, {
3056
3255
  status: xhr.status,
3057
3256
  statusText: xhr.statusText,
3058
- headers: parseXhrHeaders(xhr.getAllResponseHeaders())
3257
+ headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
3059
3258
  }));
3060
3259
  };
3061
3260
  xhr.onerror = () => {
@@ -3193,7 +3392,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
3193
3392
  function sum(values) {
3194
3393
  return values.reduce((total, value) => total + value, 0);
3195
3394
  }
3196
- function parseXhrHeaders(raw) {
3395
+ function parseXhrHeaders2(raw) {
3197
3396
  const headers = new Headers();
3198
3397
  for (const line of raw.trim().split(/[\r\n]+/)) {
3199
3398
  const index = line.indexOf(":");
@@ -3210,6 +3409,230 @@ function isRecord5(value) {
3210
3409
  return Boolean(value) && typeof value === "object";
3211
3410
  }
3212
3411
 
3412
+ // src/storage/backup.ts
3413
+ function backupError(message, status, endpoint, method, cause, raw) {
3414
+ const error = new Error(message);
3415
+ error.name = "AthenaStorageError";
3416
+ error.code = status === 0 ? "NETWORK_ERROR" : "HTTP_ERROR";
3417
+ error.status = status;
3418
+ error.endpoint = endpoint;
3419
+ error.method = method;
3420
+ error.cause = cause;
3421
+ error.raw = raw;
3422
+ throw error;
3423
+ }
3424
+ function isRecord6(value) {
3425
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3426
+ }
3427
+ function asPath(path) {
3428
+ return path;
3429
+ }
3430
+ function appendQuery(path, query) {
3431
+ if (!query) return path;
3432
+ const params = new URLSearchParams();
3433
+ for (const [key, value] of Object.entries(query)) {
3434
+ if (value === void 0 || value === null || value === "") continue;
3435
+ params.set(key, String(value));
3436
+ }
3437
+ const text = params.toString();
3438
+ return text ? `${path}?${text}` : path;
3439
+ }
3440
+ function unwrapAthenaData(payload) {
3441
+ if (isRecord6(payload) && "data" in payload) {
3442
+ return payload.data;
3443
+ }
3444
+ return payload;
3445
+ }
3446
+ function requireKey(key) {
3447
+ const trimmed = key.trim();
3448
+ if (!trimmed || trimmed === "undefined" || trimmed === "null") {
3449
+ backupError("Backup object key is required", 400, "/admin/backups/{key}", "DELETE");
3450
+ }
3451
+ return trimmed;
3452
+ }
3453
+ function resolveMessage(payload, fallback) {
3454
+ if (isRecord6(payload)) {
3455
+ const message = payload.message ?? payload.error ?? payload.details;
3456
+ if (typeof message === "string" && message.trim()) return message.trim();
3457
+ }
3458
+ if (typeof payload === "string" && payload.trim()) return payload.trim();
3459
+ return fallback;
3460
+ }
3461
+ async function callBackupEndpoint(gateway, path, method, payload, options, runtime) {
3462
+ const endpoint = asPath(path);
3463
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
3464
+ const url = buildAthenaGatewayUrl(baseUrl, endpoint);
3465
+ const headers = gateway.buildHeaders(options);
3466
+ const init = {
3467
+ method,
3468
+ headers,
3469
+ signal: options?.signal
3470
+ };
3471
+ if (payload !== void 0 && method !== "GET") {
3472
+ init.body = JSON.stringify(payload);
3473
+ }
3474
+ let response;
3475
+ try {
3476
+ response = await fetch(url, init);
3477
+ } catch (error) {
3478
+ backupError(
3479
+ error instanceof Error ? error.message : "Backup network error",
3480
+ 0,
3481
+ path,
3482
+ method,
3483
+ error
3484
+ );
3485
+ }
3486
+ const rawText = await response.text();
3487
+ let parsed = null;
3488
+ if (rawText) {
3489
+ try {
3490
+ parsed = JSON.parse(rawText);
3491
+ } catch {
3492
+ parsed = rawText;
3493
+ }
3494
+ }
3495
+ if (!response.ok) {
3496
+ backupError(
3497
+ resolveMessage(parsed, `Backup ${method} ${path} failed (${response.status})`),
3498
+ response.status,
3499
+ path,
3500
+ method,
3501
+ void 0,
3502
+ parsed
3503
+ );
3504
+ }
3505
+ return unwrapAthenaData(parsed);
3506
+ }
3507
+ function createStorageBackupModule(gateway, runtimeOptions) {
3508
+ const resolvedBaseUrl = () => String(gateway.baseUrl ?? "").replace(/\/+$/, "");
3509
+ return {
3510
+ async list(query, options) {
3511
+ const path = appendQuery("/admin/backups", {
3512
+ limit: query?.limit ?? 10,
3513
+ client_name: query?.client_name,
3514
+ cursor: query?.cursor ?? void 0
3515
+ });
3516
+ const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
3517
+ const backups = (data?.backups ?? []).map((row) => ({
3518
+ ...row,
3519
+ key: row.key ?? row.s3_key
3520
+ }));
3521
+ return {
3522
+ backups,
3523
+ next_cursor: data?.next_cursor ?? null
3524
+ };
3525
+ },
3526
+ async create(input, options) {
3527
+ const data = await callBackupEndpoint(gateway, "/admin/backups", "POST", input, options);
3528
+ return {
3529
+ job_id: Number(data?.job_id ?? 0),
3530
+ client_name: String(data?.client_name ?? input.client_name),
3531
+ status: String(data?.status ?? "pending")
3532
+ };
3533
+ },
3534
+ async restore(key, input, options) {
3535
+ const backupKey = requireKey(key);
3536
+ const path = `/admin/backups/${encodeURIComponent(backupKey)}/restore`;
3537
+ const data = await callBackupEndpoint(gateway, path, "POST", input, options);
3538
+ return {
3539
+ job_id: Number(data?.job_id ?? 0),
3540
+ client_name: String(data?.client_name ?? input.client_name),
3541
+ status: String(data?.status ?? "pending"),
3542
+ key: String(data?.key ?? backupKey)
3543
+ };
3544
+ },
3545
+ async delete(key, options) {
3546
+ const backupKey = requireKey(key);
3547
+ await callBackupEndpoint(
3548
+ gateway,
3549
+ `/admin/backups/${encodeURIComponent(backupKey)}`,
3550
+ "DELETE",
3551
+ void 0,
3552
+ options);
3553
+ },
3554
+ downloadUrl(key, options) {
3555
+ const backupKey = requireKey(key);
3556
+ const base = `${resolvedBaseUrl()}/admin/backups/${encodeURIComponent(backupKey)}/download`;
3557
+ return options?.apiKey ? `${base}?api_key=${encodeURIComponent(options.apiKey)}` : base;
3558
+ },
3559
+ jobs: {
3560
+ async list(query, options) {
3561
+ const path = appendQuery("/admin/backups/jobs", query ?? {});
3562
+ const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
3563
+ if (Array.isArray(data)) return data;
3564
+ if (isRecord6(data) && Array.isArray(data.jobs)) return data.jobs;
3565
+ return [];
3566
+ },
3567
+ async get(jobId, options) {
3568
+ return callBackupEndpoint(
3569
+ gateway,
3570
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
3571
+ "GET",
3572
+ void 0,
3573
+ options);
3574
+ },
3575
+ async cancel(jobId, options) {
3576
+ return callBackupEndpoint(
3577
+ gateway,
3578
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}/cancel`,
3579
+ "POST",
3580
+ {},
3581
+ options);
3582
+ },
3583
+ async delete(jobId, options) {
3584
+ await callBackupEndpoint(
3585
+ gateway,
3586
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
3587
+ "DELETE",
3588
+ void 0,
3589
+ options);
3590
+ },
3591
+ async openObjectUrl(jobId, options) {
3592
+ const data = await callBackupEndpoint(
3593
+ gateway,
3594
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}/s3-open`,
3595
+ "GET",
3596
+ void 0,
3597
+ options);
3598
+ return String(data?.url ?? "");
3599
+ }
3600
+ },
3601
+ schedules: {
3602
+ async list(options) {
3603
+ const data = await callBackupEndpoint(gateway, "/admin/backups/schedules", "GET", void 0, options);
3604
+ if (Array.isArray(data)) return data;
3605
+ if (isRecord6(data) && Array.isArray(data.schedules)) return data.schedules;
3606
+ return [];
3607
+ },
3608
+ async create(input, options) {
3609
+ return callBackupEndpoint(
3610
+ gateway,
3611
+ "/admin/backups/schedules",
3612
+ "POST",
3613
+ input,
3614
+ options);
3615
+ },
3616
+ async update(id, input, options) {
3617
+ return callBackupEndpoint(
3618
+ gateway,
3619
+ `/admin/backups/schedules/${encodeURIComponent(String(id))}`,
3620
+ "PATCH",
3621
+ input,
3622
+ options);
3623
+ },
3624
+ async delete(id, options) {
3625
+ await callBackupEndpoint(
3626
+ gateway,
3627
+ `/admin/backups/schedules/${encodeURIComponent(String(id))}`,
3628
+ "DELETE",
3629
+ void 0,
3630
+ options);
3631
+ }
3632
+ }
3633
+ };
3634
+ }
3635
+
3213
3636
  // src/storage/module.ts
3214
3637
  var storageSdkManifest = {
3215
3638
  methods: [
@@ -3252,6 +3675,53 @@ var storageSdkManifest = {
3252
3675
  responseEnvelope: "raw",
3253
3676
  responseType: "{ data: S3CredentialListItem[] }"
3254
3677
  },
3678
+ {
3679
+ name: "backup.list",
3680
+ method: "GET",
3681
+ path: "/admin/backups",
3682
+ responseEnvelope: "athena",
3683
+ responseType: "StorageBackupListPage",
3684
+ note: "Admin backup archives on server S3/R2 profile"
3685
+ },
3686
+ {
3687
+ name: "backup.create",
3688
+ method: "POST",
3689
+ path: "/admin/backups",
3690
+ requestType: "StorageBackupCreateRequest",
3691
+ responseEnvelope: "athena",
3692
+ responseType: "StorageBackupQueuedJob"
3693
+ },
3694
+ {
3695
+ name: "backup.restore",
3696
+ method: "POST",
3697
+ path: "/admin/backups/{key}/restore",
3698
+ pathParams: ["key"],
3699
+ requestType: "StorageBackupRestoreRequest",
3700
+ responseEnvelope: "athena",
3701
+ responseType: "StorageBackupQueuedJob"
3702
+ },
3703
+ {
3704
+ name: "backup.delete",
3705
+ method: "DELETE",
3706
+ path: "/admin/backups/{key}",
3707
+ pathParams: ["key"],
3708
+ responseEnvelope: "athena",
3709
+ responseType: "void"
3710
+ },
3711
+ {
3712
+ name: "backup.jobs.list",
3713
+ method: "GET",
3714
+ path: "/admin/backups/jobs",
3715
+ responseEnvelope: "athena",
3716
+ responseType: "StorageBackupJob[]"
3717
+ },
3718
+ {
3719
+ name: "backup.schedules.list",
3720
+ method: "GET",
3721
+ path: "/admin/backups/schedules",
3722
+ responseEnvelope: "athena",
3723
+ responseType: "StorageBackupSchedule[]"
3724
+ },
3255
3725
  {
3256
3726
  name: "createStorageUploadUrl",
3257
3727
  method: "POST",
@@ -3899,7 +4369,7 @@ var AthenaStorageError = class extends Error {
3899
4369
  };
3900
4370
  }
3901
4371
  };
3902
- function isRecord6(value) {
4372
+ function isRecord7(value) {
3903
4373
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3904
4374
  }
3905
4375
  function causeToString(cause) {
@@ -3997,7 +4467,7 @@ function parseResponseBody3(rawText, contentType) {
3997
4467
  return { parsed: rawText, parseFailed: true };
3998
4468
  }
3999
4469
  }
4000
- function appendQuery(path, query) {
4470
+ function appendQuery2(path, query) {
4001
4471
  if (!query) return path;
4002
4472
  const params = new URLSearchParams();
4003
4473
  for (const [key, value] of Object.entries(query)) {
@@ -4023,7 +4493,7 @@ function withPathParam(path, name, value) {
4023
4493
  return path.replace(`{${name}}`, encodeURIComponent(value));
4024
4494
  }
4025
4495
  function resolveErrorMessage3(payload, fallback) {
4026
- if (isRecord6(payload)) {
4496
+ if (isRecord7(payload)) {
4027
4497
  const message = payload.message ?? payload.error ?? payload.details;
4028
4498
  if (typeof message === "string" && message.trim()) {
4029
4499
  return message.trim();
@@ -4035,12 +4505,12 @@ function resolveErrorMessage3(payload, fallback) {
4035
4505
  return fallback;
4036
4506
  }
4037
4507
  function resolveErrorHint2(payload) {
4038
- if (!isRecord6(payload)) return void 0;
4508
+ if (!isRecord7(payload)) return void 0;
4039
4509
  const hint = payload.hint ?? payload.suggestion;
4040
4510
  return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
4041
4511
  }
4042
4512
  function resolveErrorCause(payload) {
4043
- if (!isRecord6(payload)) return void 0;
4513
+ if (!isRecord7(payload)) return void 0;
4044
4514
  const cause = payload.cause ?? payload.reason;
4045
4515
  return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
4046
4516
  }
@@ -4159,7 +4629,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
4159
4629
  );
4160
4630
  }
4161
4631
  if (envelope === "athena") {
4162
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4632
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4163
4633
  return rejectStorageError(
4164
4634
  {
4165
4635
  code: "INVALID_ATHENA_ENVELOPE",
@@ -4267,7 +4737,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
4267
4737
  runtimeOptions
4268
4738
  );
4269
4739
  }
4270
- function isBlobBody(body) {
4740
+ function isBlobBody2(body) {
4271
4741
  return typeof Blob !== "undefined" && body instanceof Blob;
4272
4742
  }
4273
4743
  function isReadableStreamBody(body) {
@@ -4276,7 +4746,7 @@ function isReadableStreamBody(body) {
4276
4746
  async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
4277
4747
  const headers = new Headers(uploadHeaders);
4278
4748
  Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
4279
- if (!headers.has("Content-Type") && isBlobBody(body) && body.type) {
4749
+ if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
4280
4750
  headers.set("Content-Type", body.type);
4281
4751
  }
4282
4752
  const init = {
@@ -4371,7 +4841,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
4371
4841
  }
4372
4842
  delete headers["Content-Type"];
4373
4843
  delete headers["content-type"];
4374
- if (isBlobBody(body) && body.type) {
4844
+ if (isBlobBody2(body) && body.type) {
4375
4845
  headers["Content-Type"] = body.type;
4376
4846
  }
4377
4847
  const requestInit = {
@@ -4456,7 +4926,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
4456
4926
  runtimeOptions
4457
4927
  );
4458
4928
  }
4459
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4929
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4460
4930
  return rejectStorageError(
4461
4931
  {
4462
4932
  code: "INVALID_ATHENA_ENVELOPE",
@@ -4528,14 +4998,14 @@ function createStorageModule(gateway, runtimeOptions) {
4528
4998
  return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
4529
4999
  },
4530
5000
  getStorageFileUrl(fileId, query, options) {
4531
- const path = appendQuery(
5001
+ const path = appendQuery2(
4532
5002
  withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
4533
5003
  query
4534
5004
  );
4535
5005
  return callAthena2(path, "GET", void 0, options);
4536
5006
  },
4537
5007
  getStorageFileProxy(fileId, query, options) {
4538
- const path = appendQuery(
5008
+ const path = appendQuery2(
4539
5009
  withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
4540
5010
  query
4541
5011
  );
@@ -4559,7 +5029,7 @@ function createStorageModule(gateway, runtimeOptions) {
4559
5029
  };
4560
5030
  const fileFacade = createStorageFileModule(base, runtimeOptions);
4561
5031
  const fileUpload = ((input, options) => {
4562
- if (isRecord6(input) && "files" in input) {
5032
+ if (isRecord7(input) && "files" in input) {
4563
5033
  return fileFacade.upload(input, options);
4564
5034
  }
4565
5035
  return base.createStorageUploadUrl(
@@ -4621,7 +5091,7 @@ function createStorageModule(gateway, runtimeOptions) {
4621
5091
  return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
4622
5092
  },
4623
5093
  proxyUrl(fileId, query, options) {
4624
- const path = appendQuery(
5094
+ const path = appendQuery2(
4625
5095
  withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
4626
5096
  query
4627
5097
  );
@@ -4659,7 +5129,7 @@ function createStorageModule(gateway, runtimeOptions) {
4659
5129
  },
4660
5130
  retention: {
4661
5131
  get(fileId, query, options) {
4662
- const path = appendQuery(
5132
+ const path = appendQuery2(
4663
5133
  withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
4664
5134
  query
4665
5135
  );
@@ -4861,6 +5331,7 @@ function createStorageModule(gateway, runtimeOptions) {
4861
5331
  return callAthena2("/storage/audit/list", "POST", input, options);
4862
5332
  }
4863
5333
  };
5334
+ const backup = createStorageBackupModule(gateway);
4864
5335
  return {
4865
5336
  ...base,
4866
5337
  credentials,
@@ -4872,6 +5343,7 @@ function createStorageModule(gateway, runtimeOptions) {
4872
5343
  bucket,
4873
5344
  multipart,
4874
5345
  audit,
5346
+ backup,
4875
5347
  delete: file.delete
4876
5348
  };
4877
5349
  }
@@ -4921,7 +5393,7 @@ function normalizeWsUrl(value, label) {
4921
5393
  parsed.pathname = parsed.pathname.replace(/\/+$/, "");
4922
5394
  return parsed.toString().replace(/\/$/, "");
4923
5395
  }
4924
- function isRecord7(value) {
5396
+ function isRecord8(value) {
4925
5397
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4926
5398
  }
4927
5399
  function parseResponseBody4(rawText, contentType) {
@@ -4943,7 +5415,7 @@ function resolveRequestId3(headers) {
4943
5415
  return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
4944
5416
  }
4945
5417
  function resolveErrorMessage4(payload, fallback) {
4946
- if (isRecord7(payload)) {
5418
+ if (isRecord8(payload)) {
4947
5419
  for (const candidate of [payload.error, payload.message, payload.details]) {
4948
5420
  if (typeof candidate === "string" && candidate.trim().length > 0) {
4949
5421
  return candidate.trim();
@@ -5557,7 +6029,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
5557
6029
  "ilike",
5558
6030
  "is"
5559
6031
  ]);
5560
- function isRecord8(value) {
6032
+ function isRecord9(value) {
5561
6033
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5562
6034
  }
5563
6035
  function isUuidString(value) {
@@ -5570,7 +6042,7 @@ function shouldUseUuidTextComparison(column, value) {
5570
6042
  return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
5571
6043
  }
5572
6044
  function isRelationSelectNode(value) {
5573
- return isRecord8(value) && isRecord8(value.select);
6045
+ return isRecord9(value) && isRecord9(value.select);
5574
6046
  }
5575
6047
  function normalizeIdentifier(value, label) {
5576
6048
  const normalized = value.trim();
@@ -5626,7 +6098,7 @@ function compileRelationToken(key, node) {
5626
6098
  return `${prefix}${relationToken}(${nested})`;
5627
6099
  }
5628
6100
  function compileSelectShape(select) {
5629
- if (!isRecord8(select)) {
6101
+ if (!isRecord9(select)) {
5630
6102
  throw new Error("findMany select must be an object");
5631
6103
  }
5632
6104
  const tokens = [];
@@ -5650,7 +6122,7 @@ function compileSelectShape(select) {
5650
6122
  return tokens.join(",");
5651
6123
  }
5652
6124
  function selectShapeUsesRelationSchema(select) {
5653
- if (!isRecord8(select)) {
6125
+ if (!isRecord9(select)) {
5654
6126
  return false;
5655
6127
  }
5656
6128
  for (const rawValue of Object.values(select)) {
@@ -5668,7 +6140,7 @@ function selectShapeUsesRelationSchema(select) {
5668
6140
  }
5669
6141
  function compileColumnWhere(column, input) {
5670
6142
  const normalizedColumn = normalizeIdentifier(column, "where column");
5671
- if (!isRecord8(input)) {
6143
+ if (!isRecord9(input)) {
5672
6144
  return [buildGatewayCondition("eq", normalizedColumn, input)];
5673
6145
  }
5674
6146
  const conditions = [];
@@ -5696,7 +6168,7 @@ function compileColumnWhere(column, input) {
5696
6168
  return conditions;
5697
6169
  }
5698
6170
  function compileBooleanExpressionTerms(clause, label) {
5699
- if (!isRecord8(clause)) {
6171
+ if (!isRecord9(clause)) {
5700
6172
  throw new Error(`findMany where.${label} clauses must be objects`);
5701
6173
  }
5702
6174
  const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
@@ -5705,7 +6177,7 @@ function compileBooleanExpressionTerms(clause, label) {
5705
6177
  }
5706
6178
  const [rawColumn, rawValue] = entries[0];
5707
6179
  const column = normalizeIdentifier(rawColumn, `where.${label} column`);
5708
- if (!isRecord8(rawValue)) {
6180
+ if (!isRecord9(rawValue)) {
5709
6181
  return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
5710
6182
  }
5711
6183
  const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
@@ -5729,7 +6201,7 @@ function compileWhere(where) {
5729
6201
  if (where === void 0) {
5730
6202
  return void 0;
5731
6203
  }
5732
- if (!isRecord8(where)) {
6204
+ if (!isRecord9(where)) {
5733
6205
  throw new Error("findMany where must be an object");
5734
6206
  }
5735
6207
  const conditions = [];
@@ -5779,7 +6251,7 @@ function compileOrderBy(orderBy) {
5779
6251
  if (orderBy === void 0) {
5780
6252
  return void 0;
5781
6253
  }
5782
- if (!isRecord8(orderBy)) {
6254
+ if (!isRecord9(orderBy)) {
5783
6255
  throw new Error("findMany orderBy must be an object");
5784
6256
  }
5785
6257
  if ("column" in orderBy) {
@@ -5954,11 +6426,11 @@ function toFindManyAstOrder(order) {
5954
6426
  ascending: order.direction !== "descending"
5955
6427
  };
5956
6428
  }
5957
- function isRecord9(value) {
6429
+ function isRecord10(value) {
5958
6430
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5959
6431
  }
5960
6432
  function normalizeFindManyAstColumnPredicate(value) {
5961
- if (!isRecord9(value)) {
6433
+ if (!isRecord10(value)) {
5962
6434
  return {
5963
6435
  eq: value
5964
6436
  };
@@ -5982,7 +6454,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
5982
6454
  return normalized;
5983
6455
  }
5984
6456
  function normalizeFindManyAstWhere(where) {
5985
- if (!where || !isRecord9(where)) {
6457
+ if (!where || !isRecord10(where)) {
5986
6458
  return where;
5987
6459
  }
5988
6460
  const normalized = {};
@@ -5996,7 +6468,7 @@ function normalizeFindManyAstWhere(where) {
5996
6468
  );
5997
6469
  continue;
5998
6470
  }
5999
- if (key === "not" && isRecord9(value)) {
6471
+ if (key === "not" && isRecord10(value)) {
6000
6472
  normalized.not = normalizeFindManyAstBooleanOperand(
6001
6473
  value
6002
6474
  );
@@ -6007,7 +6479,7 @@ function normalizeFindManyAstWhere(where) {
6007
6479
  return normalized;
6008
6480
  }
6009
6481
  function predicateRequiresUuidQueryFallback(column, value) {
6010
- if (!isRecord9(value)) {
6482
+ if (!isRecord10(value)) {
6011
6483
  return shouldUseUuidTextComparison(column, value);
6012
6484
  }
6013
6485
  const eqValue = value.eq;
@@ -6025,7 +6497,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
6025
6497
  return false;
6026
6498
  }
6027
6499
  function findManyAstWhereRequiresLegacyTransport(where) {
6028
- if (!where || !isRecord9(where)) {
6500
+ if (!where || !isRecord10(where)) {
6029
6501
  return false;
6030
6502
  }
6031
6503
  for (const [key, value] of Object.entries(where)) {
@@ -6040,7 +6512,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
6040
6512
  }
6041
6513
  continue;
6042
6514
  }
6043
- if (key === "not" && isRecord9(value)) {
6515
+ if (key === "not" && isRecord10(value)) {
6044
6516
  if (booleanOperandRequiresUuidQueryFallback(value)) {
6045
6517
  return true;
6046
6518
  }
@@ -6660,7 +7132,7 @@ async function executeExperimentalRead(experimental, runner) {
6660
7132
  throw error;
6661
7133
  }
6662
7134
  }
6663
- function isRecord10(value) {
7135
+ function isRecord11(value) {
6664
7136
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6665
7137
  }
6666
7138
  function firstNonEmptyString2(...values) {
@@ -6672,8 +7144,8 @@ function firstNonEmptyString2(...values) {
6672
7144
  return void 0;
6673
7145
  }
6674
7146
  function resolveStructuredErrorPayload2(raw) {
6675
- if (!isRecord10(raw)) return null;
6676
- return isRecord10(raw.error) ? raw.error : raw;
7147
+ if (!isRecord11(raw)) return null;
7148
+ return isRecord11(raw.error) ? raw.error : raw;
6677
7149
  }
6678
7150
  function resolveStructuredErrorDetails(payload, message) {
6679
7151
  if (!payload || !("details" in payload)) {
@@ -6689,7 +7161,7 @@ function resolveStructuredErrorDetails(payload, message) {
6689
7161
  return details;
6690
7162
  }
6691
7163
  function createResultError(response, result, normalized) {
6692
- const rawRecord = isRecord10(response.raw) ? response.raw : null;
7164
+ const rawRecord = isRecord11(response.raw) ? response.raw : null;
6693
7165
  const payload = resolveStructuredErrorPayload2(response.raw);
6694
7166
  const message = firstNonEmptyString2(
6695
7167
  response.error,
@@ -8437,7 +8909,30 @@ function createClientFromConfig(config, sourceConfig) {
8437
8909
  config.experimental,
8438
8910
  queryTracer
8439
8911
  );
8440
- const db = createDbModule({ from, rpc, query });
8912
+ const untypedDbFrom = from;
8913
+ const db = {
8914
+ from,
8915
+ select(table, first, second) {
8916
+ if (first && typeof first === "object" && !Array.isArray(first)) {
8917
+ return untypedDbFrom(table).select(void 0, first);
8918
+ }
8919
+ return untypedDbFrom(table).select(first, second);
8920
+ },
8921
+ insert(table, values, options) {
8922
+ return Array.isArray(values) ? untypedDbFrom(table).insert(values, options) : untypedDbFrom(table).insert(values, options);
8923
+ },
8924
+ upsert(table, values, options) {
8925
+ return Array.isArray(values) ? untypedDbFrom(table).upsert(values, options) : untypedDbFrom(table).upsert(values, options);
8926
+ },
8927
+ update(table, values, options) {
8928
+ return untypedDbFrom(table).update(values, options);
8929
+ },
8930
+ delete(table, options) {
8931
+ return untypedDbFrom(table).delete(options);
8932
+ },
8933
+ rpc,
8934
+ query
8935
+ };
8441
8936
  const chat = createChatModule({
8442
8937
  baseUrl: config.chatUrl,
8443
8938
  apiKey: config.apiKey,
@@ -8575,6 +9070,7 @@ function createClientFromConfig(config, sourceConfig) {
8575
9070
  withOptions: storageWithOptions,
8576
9071
  storage: createStorageModule(gateway, {
8577
9072
  ...config.experimental.storage,
9073
+ ...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
8578
9074
  ...config.storageUrl ? {
8579
9075
  baseUrl: config.storageUrl,
8580
9076
  stripBasePath: true
@@ -8588,7 +9084,9 @@ function createClientFromConfig(config, sourceConfig) {
8588
9084
  var AthenaClient = class {
8589
9085
  /** Create a fluent builder for a strongly-typed Athena SDK client. */
8590
9086
  static builder() {
8591
- return createAthenaClientBuilder((config) => createClientFromInput(config));
9087
+ return createAthenaClientBuilder(
9088
+ (config) => createClientFromInput(config)
9089
+ );
8592
9090
  }
8593
9091
  static fromEnvironment(options = {}) {
8594
9092
  const env = options.env ?? process.env;
@@ -8619,11 +9117,12 @@ var AthenaClient = class {
8619
9117
  });
8620
9118
  }
8621
9119
  };
8622
- function createClient(configOrUrl, apiKey, options) {
9120
+ function createClient(...args) {
9121
+ const [configOrUrl, apiKey, options] = args;
8623
9122
  if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
8624
9123
  return createClientFromInput({
8625
9124
  url: configOrUrl,
8626
- key: "",
9125
+ key: apiKey ?? "",
8627
9126
  ...options
8628
9127
  });
8629
9128
  }
@@ -8759,6 +9258,237 @@ function buildSessionClientOptions(context, options) {
8759
9258
  };
8760
9259
  }
8761
9260
 
9261
+ // src/next/session-bridge/constants.ts
9262
+ var ATHENA_AUTH_SESSION_BRIDGE_ROUTE = "/api/athena-auth/session";
9263
+ var ATHENA_AUTH_SESSION_COOKIE_NAME = "athena-auth.session-token";
9264
+ var ATHENA_AUTH_SESSION_COOKIE_NAMES = [
9265
+ ATHENA_AUTH_SESSION_COOKIE_NAME,
9266
+ "athena-auth.session_token"
9267
+ ];
9268
+
9269
+ // src/next/session-bridge/client.ts
9270
+ var JSON_CONTENT_TYPE = "application/json";
9271
+ function isBrowserRuntime() {
9272
+ return typeof globalThis !== "undefined" && "window" in globalThis;
9273
+ }
9274
+ async function persistAthenaAuthSessionOnAppHost(payload, options) {
9275
+ if (!(payload && isBrowserRuntime())) {
9276
+ return;
9277
+ }
9278
+ const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
9279
+ const fetchImpl = options?.fetch ?? fetch;
9280
+ const response = await fetchImpl(route, {
9281
+ body: JSON.stringify(payload),
9282
+ credentials: "same-origin",
9283
+ headers: {
9284
+ "Content-Type": JSON_CONTENT_TYPE
9285
+ },
9286
+ method: "POST"
9287
+ });
9288
+ if (!response.ok) {
9289
+ throw new Error("Failed to persist the Athena Auth session on the app host");
9290
+ }
9291
+ }
9292
+ async function clearAthenaAuthSessionOnAppHost(options) {
9293
+ if (!isBrowserRuntime()) {
9294
+ return;
9295
+ }
9296
+ const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
9297
+ const fetchImpl = options?.fetch ?? fetch;
9298
+ const response = await fetchImpl(route, {
9299
+ credentials: "same-origin",
9300
+ method: "DELETE"
9301
+ });
9302
+ if (!response.ok) {
9303
+ throw new Error("Failed to clear the Athena Auth session on the app host");
9304
+ }
9305
+ }
9306
+
9307
+ // src/next/session-bridge/payload.ts
9308
+ function resolveSessionBridgePayload(payload) {
9309
+ const token = payload?.session?.token ?? payload?.token;
9310
+ if (typeof token !== "string") {
9311
+ return null;
9312
+ }
9313
+ const normalizedToken = token.trim();
9314
+ if (!normalizedToken) {
9315
+ return null;
9316
+ }
9317
+ return {
9318
+ token: normalizedToken,
9319
+ expiresAt: typeof payload?.session?.expiresAt === "string" ? payload.session.expiresAt : void 0
9320
+ };
9321
+ }
9322
+
9323
+ // src/next/session-bridge/cookie.ts
9324
+ var EXPIRED_AT = /* @__PURE__ */ new Date(0);
9325
+ function resolveRequestIsSecure(request2) {
9326
+ const forwardedProto = request2.headers.get("x-forwarded-proto")?.trim();
9327
+ if (forwardedProto) {
9328
+ const first = forwardedProto.split(",")[0]?.trim().toLowerCase();
9329
+ if (first === "https") return true;
9330
+ if (first === "http") return false;
9331
+ }
9332
+ return new URL(request2.url).protocol === "https:";
9333
+ }
9334
+ function resolveSessionCookieExpiresAt(value) {
9335
+ if (typeof value !== "string") {
9336
+ return void 0;
9337
+ }
9338
+ const expiresAt = new Date(value);
9339
+ return Number.isNaN(expiresAt.getTime()) ? void 0 : expiresAt;
9340
+ }
9341
+ function serializeCookie(name, value, options) {
9342
+ const parts = [
9343
+ `${encodeURIComponent(name)}=${encodeURIComponent(value)}`,
9344
+ `Path=${options.path}`,
9345
+ "HttpOnly",
9346
+ `SameSite=${options.sameSite === "none" ? "None" : options.sameSite === "strict" ? "Strict" : "Lax"}`
9347
+ ];
9348
+ if (options.secure) {
9349
+ parts.push("Secure");
9350
+ }
9351
+ if (options.expires) {
9352
+ parts.push(`Expires=${options.expires.toUTCString()}`);
9353
+ }
9354
+ return parts.join("; ");
9355
+ }
9356
+ function resolveBridgeCookieConfig(options) {
9357
+ return {
9358
+ cookieName: options?.cookieName ?? ATHENA_AUTH_SESSION_COOKIE_NAME,
9359
+ cookieNames: options?.cookieNames ?? ATHENA_AUTH_SESSION_COOKIE_NAMES,
9360
+ cookiePath: options?.cookiePath ?? "/",
9361
+ sameSite: options?.sameSite ?? "lax"
9362
+ };
9363
+ }
9364
+ function appendSessionCookie(headers, request2, token, expiresAt, options) {
9365
+ const config = resolveBridgeCookieConfig(options);
9366
+ const secure = options?.secure ?? resolveRequestIsSecure(request2);
9367
+ headers.append(
9368
+ "set-cookie",
9369
+ serializeCookie(config.cookieName, token, {
9370
+ path: config.cookiePath,
9371
+ sameSite: config.sameSite,
9372
+ secure,
9373
+ expires: expiresAt
9374
+ })
9375
+ );
9376
+ }
9377
+ function appendClearSessionCookies(headers, request2, options) {
9378
+ const config = resolveBridgeCookieConfig(options);
9379
+ const secure = options?.secure ?? resolveRequestIsSecure(request2);
9380
+ const names = /* @__PURE__ */ new Set([config.cookieName, ...config.cookieNames]);
9381
+ for (const name of names) {
9382
+ headers.append(
9383
+ "set-cookie",
9384
+ serializeCookie(name, "", {
9385
+ path: config.cookiePath,
9386
+ sameSite: config.sameSite,
9387
+ secure,
9388
+ expires: EXPIRED_AT
9389
+ })
9390
+ );
9391
+ }
9392
+ }
9393
+
9394
+ // src/next/session-bridge/handlers.ts
9395
+ function json(body, init) {
9396
+ const headers = init?.headers ?? new Headers();
9397
+ if (!headers.has("content-type")) {
9398
+ headers.set("content-type", "application/json; charset=utf-8");
9399
+ }
9400
+ return new Response(JSON.stringify(body), {
9401
+ status: init?.status ?? 200,
9402
+ headers
9403
+ });
9404
+ }
9405
+ function resolveRoute(options) {
9406
+ return options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
9407
+ }
9408
+ async function handleAthenaAuthSessionBridgePost(request2, options) {
9409
+ const payload = await request2.json().catch(() => null);
9410
+ const token = typeof payload?.token === "string" ? payload.token.trim() : "";
9411
+ if (!token) {
9412
+ return json(
9413
+ {
9414
+ error: "Missing Athena Auth session token"
9415
+ },
9416
+ { status: 400 }
9417
+ );
9418
+ }
9419
+ const headers = new Headers();
9420
+ appendSessionCookie(
9421
+ headers,
9422
+ request2,
9423
+ token,
9424
+ resolveSessionCookieExpiresAt(payload?.expiresAt),
9425
+ options
9426
+ );
9427
+ return json(
9428
+ {
9429
+ ok: true,
9430
+ route: resolveRoute(options)
9431
+ },
9432
+ { headers }
9433
+ );
9434
+ }
9435
+ function handleAthenaAuthSessionBridgeDelete(request2, options) {
9436
+ const headers = new Headers();
9437
+ appendClearSessionCookies(headers, request2, options);
9438
+ return json(
9439
+ {
9440
+ ok: true,
9441
+ route: resolveRoute(options)
9442
+ },
9443
+ { headers }
9444
+ );
9445
+ }
9446
+ function createAthenaAuthSessionBridgeHandlers(options) {
9447
+ return {
9448
+ POST: (request2) => handleAthenaAuthSessionBridgePost(request2, options),
9449
+ DELETE: (request2) => handleAthenaAuthSessionBridgeDelete(request2, options)
9450
+ };
9451
+ }
9452
+ function normalizePathname(pathname) {
9453
+ if (pathname.length > 1 && pathname.endsWith("/")) {
9454
+ return pathname.slice(0, -1);
9455
+ }
9456
+ return pathname || "/";
9457
+ }
9458
+ function isAthenaAuthSessionBridgePath(request2, options) {
9459
+ const pathname = normalizePathname(new URL(request2.url).pathname);
9460
+ const route = normalizePathname(resolveRoute(options));
9461
+ if (pathname === route) {
9462
+ return true;
9463
+ }
9464
+ const matchPaths = options?.matchPaths ?? ["session"];
9465
+ const segments = pathname.split("/").filter(Boolean);
9466
+ const tail = segments[segments.length - 1];
9467
+ return typeof tail === "string" && matchPaths.includes(tail);
9468
+ }
9469
+ function createAthenaAuthSessionBridgePathHandlers(options) {
9470
+ const notFound = () => json(
9471
+ {
9472
+ error: "Not found"
9473
+ },
9474
+ { status: 404 }
9475
+ );
9476
+ return {
9477
+ POST: async (request2) => {
9478
+ if (!isAthenaAuthSessionBridgePath(request2, options)) {
9479
+ return notFound();
9480
+ }
9481
+ return handleAthenaAuthSessionBridgePost(request2, options);
9482
+ },
9483
+ DELETE: (request2) => {
9484
+ if (!isAthenaAuthSessionBridgePath(request2, options)) {
9485
+ return notFound();
9486
+ }
9487
+ return handleAthenaAuthSessionBridgeDelete(request2, options);
9488
+ }
9489
+ };
9490
+ }
9491
+
8762
9492
  // src/next/server.ts
8763
9493
  function resolveUserId(session) {
8764
9494
  return session?.user?.id ?? null;
@@ -8797,6 +9527,6 @@ async function resolveAthenaServerContext(options) {
8797
9527
  };
8798
9528
  }
8799
9529
 
8800
- export { createAthenaServerClient, resolveAthenaServerContext };
9530
+ export { ATHENA_AUTH_SESSION_BRIDGE_ROUTE, ATHENA_AUTH_SESSION_COOKIE_NAME, ATHENA_AUTH_SESSION_COOKIE_NAMES, SESSION_COOKIE_PATTERNS, clearAthenaAuthSessionOnAppHost, createAthenaAuthSessionBridgeHandlers, createAthenaAuthSessionBridgePathHandlers, createAthenaServerClient, handleAthenaAuthSessionBridgeDelete, handleAthenaAuthSessionBridgePost, hasAuthSessionCookie, isAthenaAuthSessionBridgePath, persistAthenaAuthSessionOnAppHost, resolveAthenaServerContext, resolveSessionBridgePayload };
8801
9531
  //# sourceMappingURL=server.js.map
8802
9532
  //# sourceMappingURL=server.js.map