@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
@@ -387,7 +387,7 @@ function buildAthenaRequestHeaders(input) {
387
387
 
388
388
  // package.json
389
389
  var package_default = {
390
- version: "2.13.0"
390
+ version: "2.14.0"
391
391
  };
392
392
 
393
393
  // src/sdk-version.ts
@@ -2816,7 +2816,224 @@ async function withRetry(config, fn) {
2816
2816
  throw new Error("withRetry reached an unexpected state");
2817
2817
  }
2818
2818
 
2819
+ // src/storage/direct-upload.ts
2820
+ var SERVICE = "s3";
2821
+ var TERMINATOR = "aws4_request";
2822
+ async function putDirectStorageUploadBody(config, bucket, storageKey, body, uploadHeaders, signal, onProgress) {
2823
+ if (config.bucket && bucket && config.bucket !== bucket) {
2824
+ throw new Error(
2825
+ `athena.storage.file.upload direct mode bucket mismatch: configured ${config.bucket} but Athena returned ${bucket}`
2826
+ );
2827
+ }
2828
+ const target = createDirectUploadTarget(config, bucket, storageKey);
2829
+ const bytes = await bodyToArrayBuffer(body);
2830
+ const payloadHash = await sha256Hex(bytes);
2831
+ const headers = new Headers(uploadHeaders);
2832
+ if (isBlobBody(body) && body.type && !headers.has("Content-Type")) {
2833
+ headers.set("Content-Type", body.type);
2834
+ }
2835
+ const signed = await signDirectUploadRequest(config, target, headers, payloadHash);
2836
+ if (typeof XMLHttpRequest !== "undefined") {
2837
+ return putWithXhr(target.toString(), signed, body, signal, onProgress);
2838
+ }
2839
+ onProgress({ loaded: 0 });
2840
+ const response = await fetch(target, {
2841
+ method: "PUT",
2842
+ headers: signed.requestHeaders,
2843
+ body,
2844
+ signal
2845
+ });
2846
+ if (!response.ok) {
2847
+ throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
2848
+ }
2849
+ onProgress({ loaded: bytes.byteLength });
2850
+ return response;
2851
+ }
2852
+ function createDirectUploadTarget(config, bucket, storageKey) {
2853
+ const resolvedBucket = config.bucket ?? bucket;
2854
+ if (!resolvedBucket?.trim()) {
2855
+ throw new Error(
2856
+ "athena.storage.file.upload direct mode requires a bucket in experimental.directStorageUpload or the server upload response"
2857
+ );
2858
+ }
2859
+ if (!storageKey.trim()) {
2860
+ throw new Error("athena.storage.file.upload direct mode requires a storage key");
2861
+ }
2862
+ let endpoint;
2863
+ try {
2864
+ endpoint = new URL(config.endpoint);
2865
+ } catch (error) {
2866
+ throw new Error(
2867
+ `athena.storage.file.upload direct mode received an invalid endpoint: ${error instanceof Error ? error.message : String(error)}`
2868
+ );
2869
+ }
2870
+ if (endpoint.search || endpoint.hash) {
2871
+ throw new Error("athena.storage.file.upload direct mode endpoint must not contain a query or hash");
2872
+ }
2873
+ const endpointPath = endpoint.pathname.replace(/\/+$/, "");
2874
+ const pathParts = config.forcePathStyle === false ? [endpointPath, storageKey] : [endpointPath, resolvedBucket, storageKey];
2875
+ if (config.forcePathStyle === false) {
2876
+ endpoint.hostname = `${resolvedBucket}.${endpoint.hostname}`;
2877
+ }
2878
+ endpoint.pathname = pathParts.filter(Boolean).flatMap((part) => part.split("/")).map(awsEncode).join("/").replace(/^([^/])/, "/$1");
2879
+ return endpoint;
2880
+ }
2881
+ async function signDirectUploadRequest(config, target, inputHeaders, payloadHash) {
2882
+ const accessKeyId = config.accessKeyId.trim();
2883
+ const secretAccessKey = config.secretAccessKey.trim();
2884
+ if (!accessKeyId || !secretAccessKey) {
2885
+ throw new Error(
2886
+ "athena.storage.file.upload direct mode requires accessKeyId and secretAccessKey"
2887
+ );
2888
+ }
2889
+ const now = /* @__PURE__ */ new Date();
2890
+ const amzDate = formatAmzDate(now);
2891
+ const shortDate = amzDate.slice(0, 8);
2892
+ const region = config.region?.trim() || "auto";
2893
+ const headers = {};
2894
+ inputHeaders.forEach((value, key) => {
2895
+ if (key.toLowerCase() !== "authorization" && key.toLowerCase() !== "host") {
2896
+ headers[key.toLowerCase()] = value.trim().replace(/\s+/g, " ");
2897
+ }
2898
+ });
2899
+ headers["x-amz-content-sha256"] = payloadHash;
2900
+ headers["x-amz-date"] = amzDate;
2901
+ if (config.sessionToken?.trim()) {
2902
+ headers["x-amz-security-token"] = config.sessionToken.trim();
2903
+ }
2904
+ const canonicalHeaders = Object.keys(headers).sort().map((key) => `${key}:${headers[key]}
2905
+ `).join("");
2906
+ const signedHeaders = Object.keys(headers).sort().join(";");
2907
+ const canonicalRequest = [
2908
+ "PUT",
2909
+ target.pathname,
2910
+ "",
2911
+ `host:${target.host}
2912
+ ${canonicalHeaders}`,
2913
+ `host;${signedHeaders}`,
2914
+ payloadHash
2915
+ ].join("\n");
2916
+ const credentialScope = `${shortDate}/${region}/${SERVICE}/${TERMINATOR}`;
2917
+ const stringToSign = [
2918
+ "AWS4-HMAC-SHA256",
2919
+ amzDate,
2920
+ credentialScope,
2921
+ await sha256Hex(canonicalRequest)
2922
+ ].join("\n");
2923
+ const dateKey = await hmac(`AWS4${secretAccessKey}`, shortDate);
2924
+ const regionKey = await hmac(dateKey, region);
2925
+ const serviceKey = await hmac(regionKey, SERVICE);
2926
+ const signingKey = await hmac(serviceKey, TERMINATOR);
2927
+ const signature = await hmacHex(signingKey, stringToSign);
2928
+ headers.authorization = `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=host;${signedHeaders}, Signature=${signature}`;
2929
+ return { requestHeaders: headers };
2930
+ }
2931
+ async function putWithXhr(url, signed, body, signal, onProgress) {
2932
+ const Xhr = XMLHttpRequest;
2933
+ if (Xhr === void 0) {
2934
+ return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
2935
+ }
2936
+ return new Promise((resolve, reject) => {
2937
+ const xhr = new Xhr();
2938
+ const abort = () => xhr.abort();
2939
+ xhr.open("PUT", url);
2940
+ Object.entries(signed.requestHeaders).forEach(([key, value]) => xhr.setRequestHeader(key, value));
2941
+ xhr.upload.onprogress = (event) => onProgress({ loaded: event.loaded });
2942
+ xhr.onload = () => {
2943
+ signal?.removeEventListener("abort", abort);
2944
+ if (xhr.status < 200 || xhr.status >= 300) {
2945
+ reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
2946
+ return;
2947
+ }
2948
+ onProgress({ loaded: bodySize(body) });
2949
+ resolve(new Response(xhr.response, {
2950
+ status: xhr.status,
2951
+ statusText: xhr.statusText,
2952
+ headers: parseXhrHeaders(xhr.getAllResponseHeaders())
2953
+ }));
2954
+ };
2955
+ xhr.onerror = () => {
2956
+ signal?.removeEventListener("abort", abort);
2957
+ reject(new Error("athena.storage.file.upload failed with a network error"));
2958
+ };
2959
+ xhr.onabort = () => {
2960
+ signal?.removeEventListener("abort", abort);
2961
+ reject(new DOMException("Upload aborted", "AbortError"));
2962
+ };
2963
+ if (signal) {
2964
+ if (signal.aborted) {
2965
+ abort();
2966
+ return;
2967
+ }
2968
+ signal.addEventListener("abort", abort, { once: true });
2969
+ }
2970
+ xhr.send(body);
2971
+ });
2972
+ }
2973
+ function isBlobBody(body) {
2974
+ return typeof Blob !== "undefined" && body instanceof Blob;
2975
+ }
2976
+ async function bodyToArrayBuffer(body) {
2977
+ if (isBlobBody(body)) return body.arrayBuffer();
2978
+ if (body instanceof ArrayBuffer) return body;
2979
+ if (ArrayBuffer.isView(body)) {
2980
+ return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
2981
+ }
2982
+ throw new Error("athena.storage.file.upload direct mode does not support ReadableStream bodies");
2983
+ }
2984
+ function bodySize(body) {
2985
+ if (isBlobBody(body)) return body.size;
2986
+ if (body instanceof ArrayBuffer) return body.byteLength;
2987
+ if (ArrayBuffer.isView(body)) return body.byteLength;
2988
+ return 0;
2989
+ }
2990
+ function awsEncode(value) {
2991
+ return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
2992
+ }
2993
+ function formatAmzDate(date) {
2994
+ return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
2995
+ }
2996
+ async function sha256Hex(value) {
2997
+ const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
2998
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
2999
+ return toHex(new Uint8Array(digest));
3000
+ }
3001
+ async function hmac(key, value) {
3002
+ const keyBytes = typeof key === "string" ? new TextEncoder().encode(key) : key;
3003
+ const cryptoKey = await crypto.subtle.importKey(
3004
+ "raw",
3005
+ keyBytes,
3006
+ { name: "HMAC", hash: "SHA-256" },
3007
+ false,
3008
+ ["sign"]
3009
+ );
3010
+ return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
3011
+ }
3012
+ async function hmacHex(key, value) {
3013
+ return toHex(new Uint8Array(await hmac(key, value)));
3014
+ }
3015
+ function toHex(bytes) {
3016
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
3017
+ }
3018
+ function parseXhrHeaders(rawHeaders) {
3019
+ const headers = new Headers();
3020
+ rawHeaders.trim().split(/[\r\n]+/).forEach((line) => {
3021
+ const separator = line.indexOf(":");
3022
+ if (separator > 0) {
3023
+ headers.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
3024
+ }
3025
+ });
3026
+ return headers;
3027
+ }
3028
+
2819
3029
  // src/storage/file.ts
3030
+ function mergeUploadHeaders(serverHeaders, inputHeaders) {
3031
+ const headers = { ...serverHeaders };
3032
+ new Headers(inputHeaders).forEach((value, key) => {
3033
+ headers[key] = value;
3034
+ });
3035
+ return headers;
3036
+ }
2820
3037
  function createStorageFileModule(base, config = {}) {
2821
3038
  const upload = async (input, options) => {
2822
3039
  const sources = normalizeUploadSources(input);
@@ -2852,16 +3069,25 @@ function createStorageFileModule(base, config = {}) {
2852
3069
  for (let index = 0; index < uploadRequests.length; index += 1) {
2853
3070
  const request2 = uploadRequests[index];
2854
3071
  const uploadUrl = uploadUrls[index];
2855
- const response = await putUploadBody(
3072
+ const aggregateProgress = (progress) => {
3073
+ aggregateLoaded[index] = progress.loaded;
3074
+ input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
3075
+ };
3076
+ const response = config.directUpload ? await putDirectStorageUploadBody(
3077
+ config.directUpload,
3078
+ uploadUrl.upload.bucket,
3079
+ uploadUrl.upload.storage_key,
3080
+ request2.source.source,
3081
+ mergeUploadHeaders(uploadUrl.upload.headers ?? {}, input.uploadHeaders),
3082
+ options?.signal,
3083
+ aggregateProgress
3084
+ ) : await putUploadBody(
2856
3085
  uploadUrl.upload.url,
2857
3086
  uploadUrl.upload.headers ?? {},
2858
3087
  request2.source,
2859
3088
  input,
2860
3089
  options,
2861
- (progress) => {
2862
- aggregateLoaded[index] = progress.loaded;
2863
- input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
2864
- }
3090
+ aggregateProgress
2865
3091
  );
2866
3092
  uploaded.push({
2867
3093
  file: uploadUrl.file,
@@ -3012,7 +3238,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
3012
3238
  resolve(new Response(xhr.response, {
3013
3239
  status: xhr.status,
3014
3240
  statusText: xhr.statusText,
3015
- headers: parseXhrHeaders(xhr.getAllResponseHeaders())
3241
+ headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
3016
3242
  }));
3017
3243
  };
3018
3244
  xhr.onerror = () => {
@@ -3150,7 +3376,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
3150
3376
  function sum(values) {
3151
3377
  return values.reduce((total, value) => total + value, 0);
3152
3378
  }
3153
- function parseXhrHeaders(raw) {
3379
+ function parseXhrHeaders2(raw) {
3154
3380
  const headers = new Headers();
3155
3381
  for (const line of raw.trim().split(/[\r\n]+/)) {
3156
3382
  const index = line.indexOf(":");
@@ -3167,6 +3393,230 @@ function isRecord5(value) {
3167
3393
  return Boolean(value) && typeof value === "object";
3168
3394
  }
3169
3395
 
3396
+ // src/storage/backup.ts
3397
+ function backupError(message, status, endpoint, method, cause, raw) {
3398
+ const error = new Error(message);
3399
+ error.name = "AthenaStorageError";
3400
+ error.code = status === 0 ? "NETWORK_ERROR" : "HTTP_ERROR";
3401
+ error.status = status;
3402
+ error.endpoint = endpoint;
3403
+ error.method = method;
3404
+ error.cause = cause;
3405
+ error.raw = raw;
3406
+ throw error;
3407
+ }
3408
+ function isRecord6(value) {
3409
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3410
+ }
3411
+ function asPath(path) {
3412
+ return path;
3413
+ }
3414
+ function appendQuery(path, query) {
3415
+ if (!query) return path;
3416
+ const params = new URLSearchParams();
3417
+ for (const [key, value] of Object.entries(query)) {
3418
+ if (value === void 0 || value === null || value === "") continue;
3419
+ params.set(key, String(value));
3420
+ }
3421
+ const text = params.toString();
3422
+ return text ? `${path}?${text}` : path;
3423
+ }
3424
+ function unwrapAthenaData(payload) {
3425
+ if (isRecord6(payload) && "data" in payload) {
3426
+ return payload.data;
3427
+ }
3428
+ return payload;
3429
+ }
3430
+ function requireKey(key) {
3431
+ const trimmed = key.trim();
3432
+ if (!trimmed || trimmed === "undefined" || trimmed === "null") {
3433
+ backupError("Backup object key is required", 400, "/admin/backups/{key}", "DELETE");
3434
+ }
3435
+ return trimmed;
3436
+ }
3437
+ function resolveMessage(payload, fallback) {
3438
+ if (isRecord6(payload)) {
3439
+ const message = payload.message ?? payload.error ?? payload.details;
3440
+ if (typeof message === "string" && message.trim()) return message.trim();
3441
+ }
3442
+ if (typeof payload === "string" && payload.trim()) return payload.trim();
3443
+ return fallback;
3444
+ }
3445
+ async function callBackupEndpoint(gateway, path, method, payload, options, runtime) {
3446
+ const endpoint = asPath(path);
3447
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
3448
+ const url = buildAthenaGatewayUrl(baseUrl, endpoint);
3449
+ const headers = gateway.buildHeaders(options);
3450
+ const init = {
3451
+ method,
3452
+ headers,
3453
+ signal: options?.signal
3454
+ };
3455
+ if (payload !== void 0 && method !== "GET") {
3456
+ init.body = JSON.stringify(payload);
3457
+ }
3458
+ let response;
3459
+ try {
3460
+ response = await fetch(url, init);
3461
+ } catch (error) {
3462
+ backupError(
3463
+ error instanceof Error ? error.message : "Backup network error",
3464
+ 0,
3465
+ path,
3466
+ method,
3467
+ error
3468
+ );
3469
+ }
3470
+ const rawText = await response.text();
3471
+ let parsed = null;
3472
+ if (rawText) {
3473
+ try {
3474
+ parsed = JSON.parse(rawText);
3475
+ } catch {
3476
+ parsed = rawText;
3477
+ }
3478
+ }
3479
+ if (!response.ok) {
3480
+ backupError(
3481
+ resolveMessage(parsed, `Backup ${method} ${path} failed (${response.status})`),
3482
+ response.status,
3483
+ path,
3484
+ method,
3485
+ void 0,
3486
+ parsed
3487
+ );
3488
+ }
3489
+ return unwrapAthenaData(parsed);
3490
+ }
3491
+ function createStorageBackupModule(gateway, runtimeOptions) {
3492
+ const resolvedBaseUrl = () => String(gateway.baseUrl ?? "").replace(/\/+$/, "");
3493
+ return {
3494
+ async list(query, options) {
3495
+ const path = appendQuery("/admin/backups", {
3496
+ limit: query?.limit ?? 10,
3497
+ client_name: query?.client_name,
3498
+ cursor: query?.cursor ?? void 0
3499
+ });
3500
+ const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
3501
+ const backups = (data?.backups ?? []).map((row) => ({
3502
+ ...row,
3503
+ key: row.key ?? row.s3_key
3504
+ }));
3505
+ return {
3506
+ backups,
3507
+ next_cursor: data?.next_cursor ?? null
3508
+ };
3509
+ },
3510
+ async create(input, options) {
3511
+ const data = await callBackupEndpoint(gateway, "/admin/backups", "POST", input, options);
3512
+ return {
3513
+ job_id: Number(data?.job_id ?? 0),
3514
+ client_name: String(data?.client_name ?? input.client_name),
3515
+ status: String(data?.status ?? "pending")
3516
+ };
3517
+ },
3518
+ async restore(key, input, options) {
3519
+ const backupKey = requireKey(key);
3520
+ const path = `/admin/backups/${encodeURIComponent(backupKey)}/restore`;
3521
+ const data = await callBackupEndpoint(gateway, path, "POST", input, options);
3522
+ return {
3523
+ job_id: Number(data?.job_id ?? 0),
3524
+ client_name: String(data?.client_name ?? input.client_name),
3525
+ status: String(data?.status ?? "pending"),
3526
+ key: String(data?.key ?? backupKey)
3527
+ };
3528
+ },
3529
+ async delete(key, options) {
3530
+ const backupKey = requireKey(key);
3531
+ await callBackupEndpoint(
3532
+ gateway,
3533
+ `/admin/backups/${encodeURIComponent(backupKey)}`,
3534
+ "DELETE",
3535
+ void 0,
3536
+ options);
3537
+ },
3538
+ downloadUrl(key, options) {
3539
+ const backupKey = requireKey(key);
3540
+ const base = `${resolvedBaseUrl()}/admin/backups/${encodeURIComponent(backupKey)}/download`;
3541
+ return options?.apiKey ? `${base}?api_key=${encodeURIComponent(options.apiKey)}` : base;
3542
+ },
3543
+ jobs: {
3544
+ async list(query, options) {
3545
+ const path = appendQuery("/admin/backups/jobs", query ?? {});
3546
+ const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
3547
+ if (Array.isArray(data)) return data;
3548
+ if (isRecord6(data) && Array.isArray(data.jobs)) return data.jobs;
3549
+ return [];
3550
+ },
3551
+ async get(jobId, options) {
3552
+ return callBackupEndpoint(
3553
+ gateway,
3554
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
3555
+ "GET",
3556
+ void 0,
3557
+ options);
3558
+ },
3559
+ async cancel(jobId, options) {
3560
+ return callBackupEndpoint(
3561
+ gateway,
3562
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}/cancel`,
3563
+ "POST",
3564
+ {},
3565
+ options);
3566
+ },
3567
+ async delete(jobId, options) {
3568
+ await callBackupEndpoint(
3569
+ gateway,
3570
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
3571
+ "DELETE",
3572
+ void 0,
3573
+ options);
3574
+ },
3575
+ async openObjectUrl(jobId, options) {
3576
+ const data = await callBackupEndpoint(
3577
+ gateway,
3578
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}/s3-open`,
3579
+ "GET",
3580
+ void 0,
3581
+ options);
3582
+ return String(data?.url ?? "");
3583
+ }
3584
+ },
3585
+ schedules: {
3586
+ async list(options) {
3587
+ const data = await callBackupEndpoint(gateway, "/admin/backups/schedules", "GET", void 0, options);
3588
+ if (Array.isArray(data)) return data;
3589
+ if (isRecord6(data) && Array.isArray(data.schedules)) return data.schedules;
3590
+ return [];
3591
+ },
3592
+ async create(input, options) {
3593
+ return callBackupEndpoint(
3594
+ gateway,
3595
+ "/admin/backups/schedules",
3596
+ "POST",
3597
+ input,
3598
+ options);
3599
+ },
3600
+ async update(id, input, options) {
3601
+ return callBackupEndpoint(
3602
+ gateway,
3603
+ `/admin/backups/schedules/${encodeURIComponent(String(id))}`,
3604
+ "PATCH",
3605
+ input,
3606
+ options);
3607
+ },
3608
+ async delete(id, options) {
3609
+ await callBackupEndpoint(
3610
+ gateway,
3611
+ `/admin/backups/schedules/${encodeURIComponent(String(id))}`,
3612
+ "DELETE",
3613
+ void 0,
3614
+ options);
3615
+ }
3616
+ }
3617
+ };
3618
+ }
3619
+
3170
3620
  // src/storage/module.ts
3171
3621
  var storageSdkManifest = {
3172
3622
  methods: [
@@ -3209,6 +3659,53 @@ var storageSdkManifest = {
3209
3659
  responseEnvelope: "raw",
3210
3660
  responseType: "{ data: S3CredentialListItem[] }"
3211
3661
  },
3662
+ {
3663
+ name: "backup.list",
3664
+ method: "GET",
3665
+ path: "/admin/backups",
3666
+ responseEnvelope: "athena",
3667
+ responseType: "StorageBackupListPage",
3668
+ note: "Admin backup archives on server S3/R2 profile"
3669
+ },
3670
+ {
3671
+ name: "backup.create",
3672
+ method: "POST",
3673
+ path: "/admin/backups",
3674
+ requestType: "StorageBackupCreateRequest",
3675
+ responseEnvelope: "athena",
3676
+ responseType: "StorageBackupQueuedJob"
3677
+ },
3678
+ {
3679
+ name: "backup.restore",
3680
+ method: "POST",
3681
+ path: "/admin/backups/{key}/restore",
3682
+ pathParams: ["key"],
3683
+ requestType: "StorageBackupRestoreRequest",
3684
+ responseEnvelope: "athena",
3685
+ responseType: "StorageBackupQueuedJob"
3686
+ },
3687
+ {
3688
+ name: "backup.delete",
3689
+ method: "DELETE",
3690
+ path: "/admin/backups/{key}",
3691
+ pathParams: ["key"],
3692
+ responseEnvelope: "athena",
3693
+ responseType: "void"
3694
+ },
3695
+ {
3696
+ name: "backup.jobs.list",
3697
+ method: "GET",
3698
+ path: "/admin/backups/jobs",
3699
+ responseEnvelope: "athena",
3700
+ responseType: "StorageBackupJob[]"
3701
+ },
3702
+ {
3703
+ name: "backup.schedules.list",
3704
+ method: "GET",
3705
+ path: "/admin/backups/schedules",
3706
+ responseEnvelope: "athena",
3707
+ responseType: "StorageBackupSchedule[]"
3708
+ },
3212
3709
  {
3213
3710
  name: "createStorageUploadUrl",
3214
3711
  method: "POST",
@@ -3856,7 +4353,7 @@ var AthenaStorageError = class extends Error {
3856
4353
  };
3857
4354
  }
3858
4355
  };
3859
- function isRecord6(value) {
4356
+ function isRecord7(value) {
3860
4357
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3861
4358
  }
3862
4359
  function causeToString(cause) {
@@ -3954,7 +4451,7 @@ function parseResponseBody3(rawText, contentType) {
3954
4451
  return { parsed: rawText, parseFailed: true };
3955
4452
  }
3956
4453
  }
3957
- function appendQuery(path, query) {
4454
+ function appendQuery2(path, query) {
3958
4455
  if (!query) return path;
3959
4456
  const params = new URLSearchParams();
3960
4457
  for (const [key, value] of Object.entries(query)) {
@@ -3980,7 +4477,7 @@ function withPathParam(path, name, value) {
3980
4477
  return path.replace(`{${name}}`, encodeURIComponent(value));
3981
4478
  }
3982
4479
  function resolveErrorMessage3(payload, fallback) {
3983
- if (isRecord6(payload)) {
4480
+ if (isRecord7(payload)) {
3984
4481
  const message = payload.message ?? payload.error ?? payload.details;
3985
4482
  if (typeof message === "string" && message.trim()) {
3986
4483
  return message.trim();
@@ -3992,12 +4489,12 @@ function resolveErrorMessage3(payload, fallback) {
3992
4489
  return fallback;
3993
4490
  }
3994
4491
  function resolveErrorHint2(payload) {
3995
- if (!isRecord6(payload)) return void 0;
4492
+ if (!isRecord7(payload)) return void 0;
3996
4493
  const hint = payload.hint ?? payload.suggestion;
3997
4494
  return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
3998
4495
  }
3999
4496
  function resolveErrorCause(payload) {
4000
- if (!isRecord6(payload)) return void 0;
4497
+ if (!isRecord7(payload)) return void 0;
4001
4498
  const cause = payload.cause ?? payload.reason;
4002
4499
  return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
4003
4500
  }
@@ -4116,7 +4613,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
4116
4613
  );
4117
4614
  }
4118
4615
  if (envelope === "athena") {
4119
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4616
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4120
4617
  return rejectStorageError(
4121
4618
  {
4122
4619
  code: "INVALID_ATHENA_ENVELOPE",
@@ -4224,7 +4721,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
4224
4721
  runtimeOptions
4225
4722
  );
4226
4723
  }
4227
- function isBlobBody(body) {
4724
+ function isBlobBody2(body) {
4228
4725
  return typeof Blob !== "undefined" && body instanceof Blob;
4229
4726
  }
4230
4727
  function isReadableStreamBody(body) {
@@ -4233,7 +4730,7 @@ function isReadableStreamBody(body) {
4233
4730
  async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
4234
4731
  const headers = new Headers(uploadHeaders);
4235
4732
  Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
4236
- if (!headers.has("Content-Type") && isBlobBody(body) && body.type) {
4733
+ if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
4237
4734
  headers.set("Content-Type", body.type);
4238
4735
  }
4239
4736
  const init = {
@@ -4328,7 +4825,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
4328
4825
  }
4329
4826
  delete headers["Content-Type"];
4330
4827
  delete headers["content-type"];
4331
- if (isBlobBody(body) && body.type) {
4828
+ if (isBlobBody2(body) && body.type) {
4332
4829
  headers["Content-Type"] = body.type;
4333
4830
  }
4334
4831
  const requestInit = {
@@ -4413,7 +4910,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
4413
4910
  runtimeOptions
4414
4911
  );
4415
4912
  }
4416
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4913
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
4417
4914
  return rejectStorageError(
4418
4915
  {
4419
4916
  code: "INVALID_ATHENA_ENVELOPE",
@@ -4485,14 +4982,14 @@ function createStorageModule(gateway, runtimeOptions) {
4485
4982
  return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
4486
4983
  },
4487
4984
  getStorageFileUrl(fileId, query, options) {
4488
- const path = appendQuery(
4985
+ const path = appendQuery2(
4489
4986
  withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
4490
4987
  query
4491
4988
  );
4492
4989
  return callAthena2(path, "GET", void 0, options);
4493
4990
  },
4494
4991
  getStorageFileProxy(fileId, query, options) {
4495
- const path = appendQuery(
4992
+ const path = appendQuery2(
4496
4993
  withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
4497
4994
  query
4498
4995
  );
@@ -4516,7 +5013,7 @@ function createStorageModule(gateway, runtimeOptions) {
4516
5013
  };
4517
5014
  const fileFacade = createStorageFileModule(base, runtimeOptions);
4518
5015
  const fileUpload = ((input, options) => {
4519
- if (isRecord6(input) && "files" in input) {
5016
+ if (isRecord7(input) && "files" in input) {
4520
5017
  return fileFacade.upload(input, options);
4521
5018
  }
4522
5019
  return base.createStorageUploadUrl(
@@ -4578,7 +5075,7 @@ function createStorageModule(gateway, runtimeOptions) {
4578
5075
  return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
4579
5076
  },
4580
5077
  proxyUrl(fileId, query, options) {
4581
- const path = appendQuery(
5078
+ const path = appendQuery2(
4582
5079
  withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
4583
5080
  query
4584
5081
  );
@@ -4616,7 +5113,7 @@ function createStorageModule(gateway, runtimeOptions) {
4616
5113
  },
4617
5114
  retention: {
4618
5115
  get(fileId, query, options) {
4619
- const path = appendQuery(
5116
+ const path = appendQuery2(
4620
5117
  withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
4621
5118
  query
4622
5119
  );
@@ -4818,6 +5315,7 @@ function createStorageModule(gateway, runtimeOptions) {
4818
5315
  return callAthena2("/storage/audit/list", "POST", input, options);
4819
5316
  }
4820
5317
  };
5318
+ const backup = createStorageBackupModule(gateway);
4821
5319
  return {
4822
5320
  ...base,
4823
5321
  credentials,
@@ -4829,6 +5327,7 @@ function createStorageModule(gateway, runtimeOptions) {
4829
5327
  bucket,
4830
5328
  multipart,
4831
5329
  audit,
5330
+ backup,
4832
5331
  delete: file.delete
4833
5332
  };
4834
5333
  }
@@ -4878,7 +5377,7 @@ function normalizeWsUrl(value, label) {
4878
5377
  parsed.pathname = parsed.pathname.replace(/\/+$/, "");
4879
5378
  return parsed.toString().replace(/\/$/, "");
4880
5379
  }
4881
- function isRecord7(value) {
5380
+ function isRecord8(value) {
4882
5381
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4883
5382
  }
4884
5383
  function parseResponseBody4(rawText, contentType) {
@@ -4900,7 +5399,7 @@ function resolveRequestId3(headers) {
4900
5399
  return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
4901
5400
  }
4902
5401
  function resolveErrorMessage4(payload, fallback) {
4903
- if (isRecord7(payload)) {
5402
+ if (isRecord8(payload)) {
4904
5403
  for (const candidate of [payload.error, payload.message, payload.details]) {
4905
5404
  if (typeof candidate === "string" && candidate.trim().length > 0) {
4906
5405
  return candidate.trim();
@@ -5514,7 +6013,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
5514
6013
  "ilike",
5515
6014
  "is"
5516
6015
  ]);
5517
- function isRecord8(value) {
6016
+ function isRecord9(value) {
5518
6017
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5519
6018
  }
5520
6019
  function isUuidString(value) {
@@ -5527,7 +6026,7 @@ function shouldUseUuidTextComparison(column, value) {
5527
6026
  return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
5528
6027
  }
5529
6028
  function isRelationSelectNode(value) {
5530
- return isRecord8(value) && isRecord8(value.select);
6029
+ return isRecord9(value) && isRecord9(value.select);
5531
6030
  }
5532
6031
  function normalizeIdentifier(value, label) {
5533
6032
  const normalized = value.trim();
@@ -5583,7 +6082,7 @@ function compileRelationToken(key, node) {
5583
6082
  return `${prefix}${relationToken}(${nested})`;
5584
6083
  }
5585
6084
  function compileSelectShape(select) {
5586
- if (!isRecord8(select)) {
6085
+ if (!isRecord9(select)) {
5587
6086
  throw new Error("findMany select must be an object");
5588
6087
  }
5589
6088
  const tokens = [];
@@ -5607,7 +6106,7 @@ function compileSelectShape(select) {
5607
6106
  return tokens.join(",");
5608
6107
  }
5609
6108
  function selectShapeUsesRelationSchema(select) {
5610
- if (!isRecord8(select)) {
6109
+ if (!isRecord9(select)) {
5611
6110
  return false;
5612
6111
  }
5613
6112
  for (const rawValue of Object.values(select)) {
@@ -5625,7 +6124,7 @@ function selectShapeUsesRelationSchema(select) {
5625
6124
  }
5626
6125
  function compileColumnWhere(column, input) {
5627
6126
  const normalizedColumn = normalizeIdentifier(column, "where column");
5628
- if (!isRecord8(input)) {
6127
+ if (!isRecord9(input)) {
5629
6128
  return [buildGatewayCondition("eq", normalizedColumn, input)];
5630
6129
  }
5631
6130
  const conditions = [];
@@ -5653,7 +6152,7 @@ function compileColumnWhere(column, input) {
5653
6152
  return conditions;
5654
6153
  }
5655
6154
  function compileBooleanExpressionTerms(clause, label) {
5656
- if (!isRecord8(clause)) {
6155
+ if (!isRecord9(clause)) {
5657
6156
  throw new Error(`findMany where.${label} clauses must be objects`);
5658
6157
  }
5659
6158
  const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
@@ -5662,7 +6161,7 @@ function compileBooleanExpressionTerms(clause, label) {
5662
6161
  }
5663
6162
  const [rawColumn, rawValue] = entries[0];
5664
6163
  const column = normalizeIdentifier(rawColumn, `where.${label} column`);
5665
- if (!isRecord8(rawValue)) {
6164
+ if (!isRecord9(rawValue)) {
5666
6165
  return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
5667
6166
  }
5668
6167
  const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
@@ -5686,7 +6185,7 @@ function compileWhere(where) {
5686
6185
  if (where === void 0) {
5687
6186
  return void 0;
5688
6187
  }
5689
- if (!isRecord8(where)) {
6188
+ if (!isRecord9(where)) {
5690
6189
  throw new Error("findMany where must be an object");
5691
6190
  }
5692
6191
  const conditions = [];
@@ -5736,7 +6235,7 @@ function compileOrderBy(orderBy) {
5736
6235
  if (orderBy === void 0) {
5737
6236
  return void 0;
5738
6237
  }
5739
- if (!isRecord8(orderBy)) {
6238
+ if (!isRecord9(orderBy)) {
5740
6239
  throw new Error("findMany orderBy must be an object");
5741
6240
  }
5742
6241
  if ("column" in orderBy) {
@@ -5911,11 +6410,11 @@ function toFindManyAstOrder(order) {
5911
6410
  ascending: order.direction !== "descending"
5912
6411
  };
5913
6412
  }
5914
- function isRecord9(value) {
6413
+ function isRecord10(value) {
5915
6414
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5916
6415
  }
5917
6416
  function normalizeFindManyAstColumnPredicate(value) {
5918
- if (!isRecord9(value)) {
6417
+ if (!isRecord10(value)) {
5919
6418
  return {
5920
6419
  eq: value
5921
6420
  };
@@ -5939,7 +6438,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
5939
6438
  return normalized;
5940
6439
  }
5941
6440
  function normalizeFindManyAstWhere(where) {
5942
- if (!where || !isRecord9(where)) {
6441
+ if (!where || !isRecord10(where)) {
5943
6442
  return where;
5944
6443
  }
5945
6444
  const normalized = {};
@@ -5953,7 +6452,7 @@ function normalizeFindManyAstWhere(where) {
5953
6452
  );
5954
6453
  continue;
5955
6454
  }
5956
- if (key === "not" && isRecord9(value)) {
6455
+ if (key === "not" && isRecord10(value)) {
5957
6456
  normalized.not = normalizeFindManyAstBooleanOperand(
5958
6457
  value
5959
6458
  );
@@ -5964,7 +6463,7 @@ function normalizeFindManyAstWhere(where) {
5964
6463
  return normalized;
5965
6464
  }
5966
6465
  function predicateRequiresUuidQueryFallback(column, value) {
5967
- if (!isRecord9(value)) {
6466
+ if (!isRecord10(value)) {
5968
6467
  return shouldUseUuidTextComparison(column, value);
5969
6468
  }
5970
6469
  const eqValue = value.eq;
@@ -5982,7 +6481,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
5982
6481
  return false;
5983
6482
  }
5984
6483
  function findManyAstWhereRequiresLegacyTransport(where) {
5985
- if (!where || !isRecord9(where)) {
6484
+ if (!where || !isRecord10(where)) {
5986
6485
  return false;
5987
6486
  }
5988
6487
  for (const [key, value] of Object.entries(where)) {
@@ -5997,7 +6496,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
5997
6496
  }
5998
6497
  continue;
5999
6498
  }
6000
- if (key === "not" && isRecord9(value)) {
6499
+ if (key === "not" && isRecord10(value)) {
6001
6500
  if (booleanOperandRequiresUuidQueryFallback(value)) {
6002
6501
  return true;
6003
6502
  }
@@ -6617,7 +7116,7 @@ async function executeExperimentalRead(experimental, runner) {
6617
7116
  throw error;
6618
7117
  }
6619
7118
  }
6620
- function isRecord10(value) {
7119
+ function isRecord11(value) {
6621
7120
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6622
7121
  }
6623
7122
  function firstNonEmptyString2(...values) {
@@ -6629,8 +7128,8 @@ function firstNonEmptyString2(...values) {
6629
7128
  return void 0;
6630
7129
  }
6631
7130
  function resolveStructuredErrorPayload2(raw) {
6632
- if (!isRecord10(raw)) return null;
6633
- return isRecord10(raw.error) ? raw.error : raw;
7131
+ if (!isRecord11(raw)) return null;
7132
+ return isRecord11(raw.error) ? raw.error : raw;
6634
7133
  }
6635
7134
  function resolveStructuredErrorDetails(payload, message) {
6636
7135
  if (!payload || !("details" in payload)) {
@@ -6646,7 +7145,7 @@ function resolveStructuredErrorDetails(payload, message) {
6646
7145
  return details;
6647
7146
  }
6648
7147
  function createResultError(response, result, normalized) {
6649
- const rawRecord = isRecord10(response.raw) ? response.raw : null;
7148
+ const rawRecord = isRecord11(response.raw) ? response.raw : null;
6650
7149
  const payload = resolveStructuredErrorPayload2(response.raw);
6651
7150
  const message = firstNonEmptyString2(
6652
7151
  response.error,
@@ -8555,6 +9054,7 @@ function createClientFromConfig(config, sourceConfig) {
8555
9054
  withOptions: storageWithOptions,
8556
9055
  storage: createStorageModule(gateway, {
8557
9056
  ...config.experimental.storage,
9057
+ ...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
8558
9058
  ...config.storageUrl ? {
8559
9059
  baseUrl: config.storageUrl,
8560
9060
  stripBasePath: true