@xylex-group/athena 2.13.0 → 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 (61) hide show
  1. package/README.md +1 -1
  2. package/bin/athena-js.js +0 -0
  3. package/dist/browser.cjs +552 -52
  4. package/dist/browser.cjs.map +1 -1
  5. package/dist/browser.d.cts +9 -9
  6. package/dist/browser.d.ts +9 -9
  7. package/dist/browser.js +552 -52
  8. package/dist/browser.js.map +1 -1
  9. package/dist/cli/index.cjs +545 -45
  10. package/dist/cli/index.cjs.map +1 -1
  11. package/dist/cli/index.d.cts +4 -4
  12. package/dist/cli/index.d.ts +4 -4
  13. package/dist/cli/index.js +545 -45
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/{client-DVOKSYDI.d.ts → client-uthENhaf.d.ts} +289 -92
  16. package/dist/{client-BJjUwDSg.d.cts → client-wU2J9yqb.d.cts} +289 -92
  17. package/dist/index.cjs +552 -52
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +9 -9
  20. package/dist/index.d.ts +9 -9
  21. package/dist/index.js +552 -52
  22. package/dist/index.js.map +1 -1
  23. package/dist/{model-form-Dw4zEL5a.d.cts → model-form-BE1_Bmdd.d.cts} +2 -2
  24. package/dist/{model-form-yRg71q3H.d.ts → model-form-DcH3R7WD.d.ts} +2 -2
  25. package/dist/{module-DBteUIob.d.ts → module-Ca3_OQqR.d.ts} +5 -5
  26. package/dist/{module-yoX49uQC.d.cts → module-DFGZXCtt.d.cts} +5 -5
  27. package/dist/next/client.cjs +545 -45
  28. package/dist/next/client.cjs.map +1 -1
  29. package/dist/next/client.d.cts +5 -5
  30. package/dist/next/client.d.ts +5 -5
  31. package/dist/next/client.js +545 -45
  32. package/dist/next/client.js.map +1 -1
  33. package/dist/next/server.cjs +545 -45
  34. package/dist/next/server.cjs.map +1 -1
  35. package/dist/next/server.d.cts +5 -5
  36. package/dist/next/server.d.ts +5 -5
  37. package/dist/next/server.js +545 -45
  38. package/dist/next/server.js.map +1 -1
  39. package/dist/{payload-DEOWN_oo.d.ts → payload-BbSCmILD.d.ts} +2 -2
  40. package/dist/{payload-BzVbUgY_.d.cts → payload-zXIwKTQf.d.cts} +2 -2
  41. package/dist/{pipeline-Dwck-wZO.d.cts → pipeline-CwQoD5G9.d.cts} +1 -1
  42. package/dist/{pipeline-Bj6RWt1A.d.ts → pipeline-DqwehoQV.d.ts} +1 -1
  43. package/dist/react.cjs +1 -1
  44. package/dist/react.cjs.map +1 -1
  45. package/dist/react.d.cts +5 -5
  46. package/dist/react.d.ts +5 -5
  47. package/dist/react.js +1 -1
  48. package/dist/react.js.map +1 -1
  49. package/dist/social-providers.cjs +24 -15
  50. package/dist/social-providers.cjs.map +1 -1
  51. package/dist/social-providers.js +24 -15
  52. package/dist/social-providers.js.map +1 -1
  53. package/dist/{types-BU8uJH_b.d.cts → types-6H575ITc.d.cts} +1 -1
  54. package/dist/{types-DPgejxYC.d.ts → types-C1swabT5.d.ts} +2 -2
  55. package/dist/{types-BRP7sfSF.d.ts → types-CD6K05JQ.d.ts} +1 -1
  56. package/dist/{types-CH78O90i.d.cts → types-YQUR7wu0.d.cts} +1 -1
  57. package/dist/{types-CH78O90i.d.ts → types-YQUR7wu0.d.ts} +1 -1
  58. package/dist/{types-CjC9_5ZQ.d.cts → types-dHnjluBC.d.cts} +2 -2
  59. package/dist/utils.d.cts +1 -1
  60. package/dist/utils.d.ts +1 -1
  61. package/package.json +22 -21
@@ -403,7 +403,7 @@ function buildAthenaRequestHeaders(input) {
403
403
 
404
404
  // package.json
405
405
  var package_default = {
406
- version: "2.13.0"
406
+ version: "2.14.0"
407
407
  };
408
408
 
409
409
  // src/sdk-version.ts
@@ -2832,7 +2832,224 @@ async function withRetry(config, fn) {
2832
2832
  throw new Error("withRetry reached an unexpected state");
2833
2833
  }
2834
2834
 
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;
2963
+ }
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 });
2985
+ }
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;
3043
+ }
3044
+
2835
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
+ }
2836
3053
  function createStorageFileModule(base, config = {}) {
2837
3054
  const upload = async (input, options) => {
2838
3055
  const sources = normalizeUploadSources(input);
@@ -2868,16 +3085,25 @@ function createStorageFileModule(base, config = {}) {
2868
3085
  for (let index = 0; index < uploadRequests.length; index += 1) {
2869
3086
  const request2 = uploadRequests[index];
2870
3087
  const uploadUrl = uploadUrls[index];
2871
- 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(
2872
3101
  uploadUrl.upload.url,
2873
3102
  uploadUrl.upload.headers ?? {},
2874
3103
  request2.source,
2875
3104
  input,
2876
3105
  options,
2877
- (progress) => {
2878
- aggregateLoaded[index] = progress.loaded;
2879
- input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
2880
- }
3106
+ aggregateProgress
2881
3107
  );
2882
3108
  uploaded.push({
2883
3109
  file: uploadUrl.file,
@@ -3028,7 +3254,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
3028
3254
  resolve(new Response(xhr.response, {
3029
3255
  status: xhr.status,
3030
3256
  statusText: xhr.statusText,
3031
- headers: parseXhrHeaders(xhr.getAllResponseHeaders())
3257
+ headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
3032
3258
  }));
3033
3259
  };
3034
3260
  xhr.onerror = () => {
@@ -3166,7 +3392,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
3166
3392
  function sum(values) {
3167
3393
  return values.reduce((total, value) => total + value, 0);
3168
3394
  }
3169
- function parseXhrHeaders(raw) {
3395
+ function parseXhrHeaders2(raw) {
3170
3396
  const headers = new Headers();
3171
3397
  for (const line of raw.trim().split(/[\r\n]+/)) {
3172
3398
  const index = line.indexOf(":");
@@ -3183,6 +3409,230 @@ function isRecord5(value) {
3183
3409
  return Boolean(value) && typeof value === "object";
3184
3410
  }
3185
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
+
3186
3636
  // src/storage/module.ts
3187
3637
  var storageSdkManifest = {
3188
3638
  methods: [
@@ -3225,6 +3675,53 @@ var storageSdkManifest = {
3225
3675
  responseEnvelope: "raw",
3226
3676
  responseType: "{ data: S3CredentialListItem[] }"
3227
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
+ },
3228
3725
  {
3229
3726
  name: "createStorageUploadUrl",
3230
3727
  method: "POST",
@@ -3872,7 +4369,7 @@ var AthenaStorageError = class extends Error {
3872
4369
  };
3873
4370
  }
3874
4371
  };
3875
- function isRecord6(value) {
4372
+ function isRecord7(value) {
3876
4373
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3877
4374
  }
3878
4375
  function causeToString(cause) {
@@ -3970,7 +4467,7 @@ function parseResponseBody3(rawText, contentType) {
3970
4467
  return { parsed: rawText, parseFailed: true };
3971
4468
  }
3972
4469
  }
3973
- function appendQuery(path, query) {
4470
+ function appendQuery2(path, query) {
3974
4471
  if (!query) return path;
3975
4472
  const params = new URLSearchParams();
3976
4473
  for (const [key, value] of Object.entries(query)) {
@@ -3996,7 +4493,7 @@ function withPathParam(path, name, value) {
3996
4493
  return path.replace(`{${name}}`, encodeURIComponent(value));
3997
4494
  }
3998
4495
  function resolveErrorMessage3(payload, fallback) {
3999
- if (isRecord6(payload)) {
4496
+ if (isRecord7(payload)) {
4000
4497
  const message = payload.message ?? payload.error ?? payload.details;
4001
4498
  if (typeof message === "string" && message.trim()) {
4002
4499
  return message.trim();
@@ -4008,12 +4505,12 @@ function resolveErrorMessage3(payload, fallback) {
4008
4505
  return fallback;
4009
4506
  }
4010
4507
  function resolveErrorHint2(payload) {
4011
- if (!isRecord6(payload)) return void 0;
4508
+ if (!isRecord7(payload)) return void 0;
4012
4509
  const hint = payload.hint ?? payload.suggestion;
4013
4510
  return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
4014
4511
  }
4015
4512
  function resolveErrorCause(payload) {
4016
- if (!isRecord6(payload)) return void 0;
4513
+ if (!isRecord7(payload)) return void 0;
4017
4514
  const cause = payload.cause ?? payload.reason;
4018
4515
  return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
4019
4516
  }
@@ -4132,7 +4629,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
4132
4629
  );
4133
4630
  }
4134
4631
  if (envelope === "athena") {
4135
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4632
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4136
4633
  return rejectStorageError(
4137
4634
  {
4138
4635
  code: "INVALID_ATHENA_ENVELOPE",
@@ -4240,7 +4737,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
4240
4737
  runtimeOptions
4241
4738
  );
4242
4739
  }
4243
- function isBlobBody(body) {
4740
+ function isBlobBody2(body) {
4244
4741
  return typeof Blob !== "undefined" && body instanceof Blob;
4245
4742
  }
4246
4743
  function isReadableStreamBody(body) {
@@ -4249,7 +4746,7 @@ function isReadableStreamBody(body) {
4249
4746
  async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
4250
4747
  const headers = new Headers(uploadHeaders);
4251
4748
  Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
4252
- if (!headers.has("Content-Type") && isBlobBody(body) && body.type) {
4749
+ if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
4253
4750
  headers.set("Content-Type", body.type);
4254
4751
  }
4255
4752
  const init = {
@@ -4344,7 +4841,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
4344
4841
  }
4345
4842
  delete headers["Content-Type"];
4346
4843
  delete headers["content-type"];
4347
- if (isBlobBody(body) && body.type) {
4844
+ if (isBlobBody2(body) && body.type) {
4348
4845
  headers["Content-Type"] = body.type;
4349
4846
  }
4350
4847
  const requestInit = {
@@ -4429,7 +4926,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
4429
4926
  runtimeOptions
4430
4927
  );
4431
4928
  }
4432
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4929
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4433
4930
  return rejectStorageError(
4434
4931
  {
4435
4932
  code: "INVALID_ATHENA_ENVELOPE",
@@ -4501,14 +4998,14 @@ function createStorageModule(gateway, runtimeOptions) {
4501
4998
  return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
4502
4999
  },
4503
5000
  getStorageFileUrl(fileId, query, options) {
4504
- const path = appendQuery(
5001
+ const path = appendQuery2(
4505
5002
  withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
4506
5003
  query
4507
5004
  );
4508
5005
  return callAthena2(path, "GET", void 0, options);
4509
5006
  },
4510
5007
  getStorageFileProxy(fileId, query, options) {
4511
- const path = appendQuery(
5008
+ const path = appendQuery2(
4512
5009
  withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
4513
5010
  query
4514
5011
  );
@@ -4532,7 +5029,7 @@ function createStorageModule(gateway, runtimeOptions) {
4532
5029
  };
4533
5030
  const fileFacade = createStorageFileModule(base, runtimeOptions);
4534
5031
  const fileUpload = ((input, options) => {
4535
- if (isRecord6(input) && "files" in input) {
5032
+ if (isRecord7(input) && "files" in input) {
4536
5033
  return fileFacade.upload(input, options);
4537
5034
  }
4538
5035
  return base.createStorageUploadUrl(
@@ -4594,7 +5091,7 @@ function createStorageModule(gateway, runtimeOptions) {
4594
5091
  return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
4595
5092
  },
4596
5093
  proxyUrl(fileId, query, options) {
4597
- const path = appendQuery(
5094
+ const path = appendQuery2(
4598
5095
  withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
4599
5096
  query
4600
5097
  );
@@ -4632,7 +5129,7 @@ function createStorageModule(gateway, runtimeOptions) {
4632
5129
  },
4633
5130
  retention: {
4634
5131
  get(fileId, query, options) {
4635
- const path = appendQuery(
5132
+ const path = appendQuery2(
4636
5133
  withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
4637
5134
  query
4638
5135
  );
@@ -4834,6 +5331,7 @@ function createStorageModule(gateway, runtimeOptions) {
4834
5331
  return callAthena2("/storage/audit/list", "POST", input, options);
4835
5332
  }
4836
5333
  };
5334
+ const backup = createStorageBackupModule(gateway);
4837
5335
  return {
4838
5336
  ...base,
4839
5337
  credentials,
@@ -4845,6 +5343,7 @@ function createStorageModule(gateway, runtimeOptions) {
4845
5343
  bucket,
4846
5344
  multipart,
4847
5345
  audit,
5346
+ backup,
4848
5347
  delete: file.delete
4849
5348
  };
4850
5349
  }
@@ -4894,7 +5393,7 @@ function normalizeWsUrl(value, label) {
4894
5393
  parsed.pathname = parsed.pathname.replace(/\/+$/, "");
4895
5394
  return parsed.toString().replace(/\/$/, "");
4896
5395
  }
4897
- function isRecord7(value) {
5396
+ function isRecord8(value) {
4898
5397
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4899
5398
  }
4900
5399
  function parseResponseBody4(rawText, contentType) {
@@ -4916,7 +5415,7 @@ function resolveRequestId3(headers) {
4916
5415
  return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
4917
5416
  }
4918
5417
  function resolveErrorMessage4(payload, fallback) {
4919
- if (isRecord7(payload)) {
5418
+ if (isRecord8(payload)) {
4920
5419
  for (const candidate of [payload.error, payload.message, payload.details]) {
4921
5420
  if (typeof candidate === "string" && candidate.trim().length > 0) {
4922
5421
  return candidate.trim();
@@ -5530,7 +6029,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
5530
6029
  "ilike",
5531
6030
  "is"
5532
6031
  ]);
5533
- function isRecord8(value) {
6032
+ function isRecord9(value) {
5534
6033
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5535
6034
  }
5536
6035
  function isUuidString(value) {
@@ -5543,7 +6042,7 @@ function shouldUseUuidTextComparison(column, value) {
5543
6042
  return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
5544
6043
  }
5545
6044
  function isRelationSelectNode(value) {
5546
- return isRecord8(value) && isRecord8(value.select);
6045
+ return isRecord9(value) && isRecord9(value.select);
5547
6046
  }
5548
6047
  function normalizeIdentifier(value, label) {
5549
6048
  const normalized = value.trim();
@@ -5599,7 +6098,7 @@ function compileRelationToken(key, node) {
5599
6098
  return `${prefix}${relationToken}(${nested})`;
5600
6099
  }
5601
6100
  function compileSelectShape(select) {
5602
- if (!isRecord8(select)) {
6101
+ if (!isRecord9(select)) {
5603
6102
  throw new Error("findMany select must be an object");
5604
6103
  }
5605
6104
  const tokens = [];
@@ -5623,7 +6122,7 @@ function compileSelectShape(select) {
5623
6122
  return tokens.join(",");
5624
6123
  }
5625
6124
  function selectShapeUsesRelationSchema(select) {
5626
- if (!isRecord8(select)) {
6125
+ if (!isRecord9(select)) {
5627
6126
  return false;
5628
6127
  }
5629
6128
  for (const rawValue of Object.values(select)) {
@@ -5641,7 +6140,7 @@ function selectShapeUsesRelationSchema(select) {
5641
6140
  }
5642
6141
  function compileColumnWhere(column, input) {
5643
6142
  const normalizedColumn = normalizeIdentifier(column, "where column");
5644
- if (!isRecord8(input)) {
6143
+ if (!isRecord9(input)) {
5645
6144
  return [buildGatewayCondition("eq", normalizedColumn, input)];
5646
6145
  }
5647
6146
  const conditions = [];
@@ -5669,7 +6168,7 @@ function compileColumnWhere(column, input) {
5669
6168
  return conditions;
5670
6169
  }
5671
6170
  function compileBooleanExpressionTerms(clause, label) {
5672
- if (!isRecord8(clause)) {
6171
+ if (!isRecord9(clause)) {
5673
6172
  throw new Error(`findMany where.${label} clauses must be objects`);
5674
6173
  }
5675
6174
  const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
@@ -5678,7 +6177,7 @@ function compileBooleanExpressionTerms(clause, label) {
5678
6177
  }
5679
6178
  const [rawColumn, rawValue] = entries[0];
5680
6179
  const column = normalizeIdentifier(rawColumn, `where.${label} column`);
5681
- if (!isRecord8(rawValue)) {
6180
+ if (!isRecord9(rawValue)) {
5682
6181
  return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
5683
6182
  }
5684
6183
  const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
@@ -5702,7 +6201,7 @@ function compileWhere(where) {
5702
6201
  if (where === void 0) {
5703
6202
  return void 0;
5704
6203
  }
5705
- if (!isRecord8(where)) {
6204
+ if (!isRecord9(where)) {
5706
6205
  throw new Error("findMany where must be an object");
5707
6206
  }
5708
6207
  const conditions = [];
@@ -5752,7 +6251,7 @@ function compileOrderBy(orderBy) {
5752
6251
  if (orderBy === void 0) {
5753
6252
  return void 0;
5754
6253
  }
5755
- if (!isRecord8(orderBy)) {
6254
+ if (!isRecord9(orderBy)) {
5756
6255
  throw new Error("findMany orderBy must be an object");
5757
6256
  }
5758
6257
  if ("column" in orderBy) {
@@ -5927,11 +6426,11 @@ function toFindManyAstOrder(order) {
5927
6426
  ascending: order.direction !== "descending"
5928
6427
  };
5929
6428
  }
5930
- function isRecord9(value) {
6429
+ function isRecord10(value) {
5931
6430
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5932
6431
  }
5933
6432
  function normalizeFindManyAstColumnPredicate(value) {
5934
- if (!isRecord9(value)) {
6433
+ if (!isRecord10(value)) {
5935
6434
  return {
5936
6435
  eq: value
5937
6436
  };
@@ -5955,7 +6454,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
5955
6454
  return normalized;
5956
6455
  }
5957
6456
  function normalizeFindManyAstWhere(where) {
5958
- if (!where || !isRecord9(where)) {
6457
+ if (!where || !isRecord10(where)) {
5959
6458
  return where;
5960
6459
  }
5961
6460
  const normalized = {};
@@ -5969,7 +6468,7 @@ function normalizeFindManyAstWhere(where) {
5969
6468
  );
5970
6469
  continue;
5971
6470
  }
5972
- if (key === "not" && isRecord9(value)) {
6471
+ if (key === "not" && isRecord10(value)) {
5973
6472
  normalized.not = normalizeFindManyAstBooleanOperand(
5974
6473
  value
5975
6474
  );
@@ -5980,7 +6479,7 @@ function normalizeFindManyAstWhere(where) {
5980
6479
  return normalized;
5981
6480
  }
5982
6481
  function predicateRequiresUuidQueryFallback(column, value) {
5983
- if (!isRecord9(value)) {
6482
+ if (!isRecord10(value)) {
5984
6483
  return shouldUseUuidTextComparison(column, value);
5985
6484
  }
5986
6485
  const eqValue = value.eq;
@@ -5998,7 +6497,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
5998
6497
  return false;
5999
6498
  }
6000
6499
  function findManyAstWhereRequiresLegacyTransport(where) {
6001
- if (!where || !isRecord9(where)) {
6500
+ if (!where || !isRecord10(where)) {
6002
6501
  return false;
6003
6502
  }
6004
6503
  for (const [key, value] of Object.entries(where)) {
@@ -6013,7 +6512,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
6013
6512
  }
6014
6513
  continue;
6015
6514
  }
6016
- if (key === "not" && isRecord9(value)) {
6515
+ if (key === "not" && isRecord10(value)) {
6017
6516
  if (booleanOperandRequiresUuidQueryFallback(value)) {
6018
6517
  return true;
6019
6518
  }
@@ -6633,7 +7132,7 @@ async function executeExperimentalRead(experimental, runner) {
6633
7132
  throw error;
6634
7133
  }
6635
7134
  }
6636
- function isRecord10(value) {
7135
+ function isRecord11(value) {
6637
7136
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6638
7137
  }
6639
7138
  function firstNonEmptyString2(...values) {
@@ -6645,8 +7144,8 @@ function firstNonEmptyString2(...values) {
6645
7144
  return void 0;
6646
7145
  }
6647
7146
  function resolveStructuredErrorPayload2(raw) {
6648
- if (!isRecord10(raw)) return null;
6649
- return isRecord10(raw.error) ? raw.error : raw;
7147
+ if (!isRecord11(raw)) return null;
7148
+ return isRecord11(raw.error) ? raw.error : raw;
6650
7149
  }
6651
7150
  function resolveStructuredErrorDetails(payload, message) {
6652
7151
  if (!payload || !("details" in payload)) {
@@ -6662,7 +7161,7 @@ function resolveStructuredErrorDetails(payload, message) {
6662
7161
  return details;
6663
7162
  }
6664
7163
  function createResultError(response, result, normalized) {
6665
- const rawRecord = isRecord10(response.raw) ? response.raw : null;
7164
+ const rawRecord = isRecord11(response.raw) ? response.raw : null;
6666
7165
  const payload = resolveStructuredErrorPayload2(response.raw);
6667
7166
  const message = firstNonEmptyString2(
6668
7167
  response.error,
@@ -8571,6 +9070,7 @@ function createClientFromConfig(config, sourceConfig) {
8571
9070
  withOptions: storageWithOptions,
8572
9071
  storage: createStorageModule(gateway, {
8573
9072
  ...config.experimental.storage,
9073
+ ...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
8574
9074
  ...config.storageUrl ? {
8575
9075
  baseUrl: config.storageUrl,
8576
9076
  stripBasePath: true