@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
package/dist/index.cjs CHANGED
@@ -806,7 +806,7 @@ var getCookieCache = async (request2, config) => {
806
806
 
807
807
  // src/utils/athena-request-headers.ts
808
808
  var NO_CACHE_HEADER_VALUE = "no-cache";
809
- var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
809
+ var API_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key", "X-Api-Key", "x-api-key", "apikey"];
810
810
  var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
811
811
  var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
812
812
  var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
@@ -908,17 +908,6 @@ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, ex
908
908
  });
909
909
  }
910
910
  function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
911
- if (apiKey) {
912
- if (!hasHeaderIgnoreCase(headers, "apikey")) {
913
- headers.apikey = apiKey;
914
- }
915
- if (!Object.hasOwn(headers, "x-api-key")) {
916
- headers["x-api-key"] = apiKey;
917
- }
918
- if (!Object.hasOwn(headers, "X-Api-Key")) {
919
- headers["X-Api-Key"] = apiKey;
920
- }
921
- }
922
911
  const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
923
912
  if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
924
913
  headers["X-Athena-Key"] = resolvedAthenaKey;
@@ -1044,7 +1033,7 @@ function buildAthenaRequestHeaders(input) {
1044
1033
 
1045
1034
  // package.json
1046
1035
  var package_default = {
1047
- version: "2.12.1"
1036
+ version: "2.14.0"
1048
1037
  };
1049
1038
 
1050
1039
  // src/sdk-version.ts
@@ -3747,39 +3736,224 @@ async function withRetry(config, fn) {
3747
3736
  throw new Error("withRetry reached an unexpected state");
3748
3737
  }
3749
3738
 
3750
- // src/db/module.ts
3751
- function createDbModule(input) {
3752
- const db = {
3753
- from: input.from,
3754
- select(table2, first, second) {
3755
- if (first && typeof first === "object" && !Array.isArray(first)) {
3756
- return input.from(table2).select(void 0, first);
3739
+ // src/storage/direct-upload.ts
3740
+ var SERVICE = "s3";
3741
+ var TERMINATOR = "aws4_request";
3742
+ async function putDirectStorageUploadBody(config, bucket, storageKey, body, uploadHeaders, signal, onProgress) {
3743
+ if (config.bucket && bucket && config.bucket !== bucket) {
3744
+ throw new Error(
3745
+ `athena.storage.file.upload direct mode bucket mismatch: configured ${config.bucket} but Athena returned ${bucket}`
3746
+ );
3747
+ }
3748
+ const target = createDirectUploadTarget(config, bucket, storageKey);
3749
+ const bytes = await bodyToArrayBuffer(body);
3750
+ const payloadHash = await sha256Hex(bytes);
3751
+ const headers = new Headers(uploadHeaders);
3752
+ if (isBlobBody(body) && body.type && !headers.has("Content-Type")) {
3753
+ headers.set("Content-Type", body.type);
3754
+ }
3755
+ const signed = await signDirectUploadRequest(config, target, headers, payloadHash);
3756
+ if (typeof XMLHttpRequest !== "undefined") {
3757
+ return putWithXhr(target.toString(), signed, body, signal, onProgress);
3758
+ }
3759
+ onProgress({ loaded: 0 });
3760
+ const response = await fetch(target, {
3761
+ method: "PUT",
3762
+ headers: signed.requestHeaders,
3763
+ body,
3764
+ signal
3765
+ });
3766
+ if (!response.ok) {
3767
+ throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
3768
+ }
3769
+ onProgress({ loaded: bytes.byteLength });
3770
+ return response;
3771
+ }
3772
+ function createDirectUploadTarget(config, bucket, storageKey) {
3773
+ const resolvedBucket = config.bucket ?? bucket;
3774
+ if (!resolvedBucket?.trim()) {
3775
+ throw new Error(
3776
+ "athena.storage.file.upload direct mode requires a bucket in experimental.directStorageUpload or the server upload response"
3777
+ );
3778
+ }
3779
+ if (!storageKey.trim()) {
3780
+ throw new Error("athena.storage.file.upload direct mode requires a storage key");
3781
+ }
3782
+ let endpoint;
3783
+ try {
3784
+ endpoint = new URL(config.endpoint);
3785
+ } catch (error) {
3786
+ throw new Error(
3787
+ `athena.storage.file.upload direct mode received an invalid endpoint: ${error instanceof Error ? error.message : String(error)}`
3788
+ );
3789
+ }
3790
+ if (endpoint.search || endpoint.hash) {
3791
+ throw new Error("athena.storage.file.upload direct mode endpoint must not contain a query or hash");
3792
+ }
3793
+ const endpointPath = endpoint.pathname.replace(/\/+$/, "");
3794
+ const pathParts = config.forcePathStyle === false ? [endpointPath, storageKey] : [endpointPath, resolvedBucket, storageKey];
3795
+ if (config.forcePathStyle === false) {
3796
+ endpoint.hostname = `${resolvedBucket}.${endpoint.hostname}`;
3797
+ }
3798
+ endpoint.pathname = pathParts.filter(Boolean).flatMap((part) => part.split("/")).map(awsEncode).join("/").replace(/^([^/])/, "/$1");
3799
+ return endpoint;
3800
+ }
3801
+ async function signDirectUploadRequest(config, target, inputHeaders, payloadHash) {
3802
+ const accessKeyId = config.accessKeyId.trim();
3803
+ const secretAccessKey = config.secretAccessKey.trim();
3804
+ if (!accessKeyId || !secretAccessKey) {
3805
+ throw new Error(
3806
+ "athena.storage.file.upload direct mode requires accessKeyId and secretAccessKey"
3807
+ );
3808
+ }
3809
+ const now = /* @__PURE__ */ new Date();
3810
+ const amzDate = formatAmzDate(now);
3811
+ const shortDate = amzDate.slice(0, 8);
3812
+ const region = config.region?.trim() || "auto";
3813
+ const headers = {};
3814
+ inputHeaders.forEach((value, key) => {
3815
+ if (key.toLowerCase() !== "authorization" && key.toLowerCase() !== "host") {
3816
+ headers[key.toLowerCase()] = value.trim().replace(/\s+/g, " ");
3817
+ }
3818
+ });
3819
+ headers["x-amz-content-sha256"] = payloadHash;
3820
+ headers["x-amz-date"] = amzDate;
3821
+ if (config.sessionToken?.trim()) {
3822
+ headers["x-amz-security-token"] = config.sessionToken.trim();
3823
+ }
3824
+ const canonicalHeaders = Object.keys(headers).sort().map((key) => `${key}:${headers[key]}
3825
+ `).join("");
3826
+ const signedHeaders = Object.keys(headers).sort().join(";");
3827
+ const canonicalRequest = [
3828
+ "PUT",
3829
+ target.pathname,
3830
+ "",
3831
+ `host:${target.host}
3832
+ ${canonicalHeaders}`,
3833
+ `host;${signedHeaders}`,
3834
+ payloadHash
3835
+ ].join("\n");
3836
+ const credentialScope = `${shortDate}/${region}/${SERVICE}/${TERMINATOR}`;
3837
+ const stringToSign = [
3838
+ "AWS4-HMAC-SHA256",
3839
+ amzDate,
3840
+ credentialScope,
3841
+ await sha256Hex(canonicalRequest)
3842
+ ].join("\n");
3843
+ const dateKey = await hmac(`AWS4${secretAccessKey}`, shortDate);
3844
+ const regionKey = await hmac(dateKey, region);
3845
+ const serviceKey = await hmac(regionKey, SERVICE);
3846
+ const signingKey = await hmac(serviceKey, TERMINATOR);
3847
+ const signature = await hmacHex(signingKey, stringToSign);
3848
+ headers.authorization = `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=host;${signedHeaders}, Signature=${signature}`;
3849
+ return { requestHeaders: headers };
3850
+ }
3851
+ async function putWithXhr(url, signed, body, signal, onProgress) {
3852
+ const Xhr = XMLHttpRequest;
3853
+ if (Xhr === void 0) {
3854
+ return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
3855
+ }
3856
+ return new Promise((resolve3, reject) => {
3857
+ const xhr = new Xhr();
3858
+ const abort = () => xhr.abort();
3859
+ xhr.open("PUT", url);
3860
+ Object.entries(signed.requestHeaders).forEach(([key, value]) => xhr.setRequestHeader(key, value));
3861
+ xhr.upload.onprogress = (event) => onProgress({ loaded: event.loaded });
3862
+ xhr.onload = () => {
3863
+ signal?.removeEventListener("abort", abort);
3864
+ if (xhr.status < 200 || xhr.status >= 300) {
3865
+ reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
3866
+ return;
3757
3867
  }
3758
- return input.from(table2).select(first, second);
3759
- },
3760
- insert(table2, values, options) {
3761
- return Array.isArray(values) ? input.from(table2).insert(values, options) : input.from(table2).insert(values, options);
3762
- },
3763
- upsert(table2, values, options) {
3764
- return Array.isArray(values) ? input.from(table2).upsert(values, options) : input.from(table2).upsert(values, options);
3765
- },
3766
- update(table2, values, options) {
3767
- return input.from(table2).update(values, options);
3768
- },
3769
- delete(table2, options) {
3770
- return input.from(table2).delete(options);
3771
- },
3772
- rpc(fn, args, options) {
3773
- return input.rpc(fn, args, options);
3774
- },
3775
- query(query, options) {
3776
- return input.query(query, options);
3868
+ onProgress({ loaded: bodySize(body) });
3869
+ resolve3(new Response(xhr.response, {
3870
+ status: xhr.status,
3871
+ statusText: xhr.statusText,
3872
+ headers: parseXhrHeaders(xhr.getAllResponseHeaders())
3873
+ }));
3874
+ };
3875
+ xhr.onerror = () => {
3876
+ signal?.removeEventListener("abort", abort);
3877
+ reject(new Error("athena.storage.file.upload failed with a network error"));
3878
+ };
3879
+ xhr.onabort = () => {
3880
+ signal?.removeEventListener("abort", abort);
3881
+ reject(new DOMException("Upload aborted", "AbortError"));
3882
+ };
3883
+ if (signal) {
3884
+ if (signal.aborted) {
3885
+ abort();
3886
+ return;
3887
+ }
3888
+ signal.addEventListener("abort", abort, { once: true });
3777
3889
  }
3778
- };
3779
- return db;
3890
+ xhr.send(body);
3891
+ });
3892
+ }
3893
+ function isBlobBody(body) {
3894
+ return typeof Blob !== "undefined" && body instanceof Blob;
3895
+ }
3896
+ async function bodyToArrayBuffer(body) {
3897
+ if (isBlobBody(body)) return body.arrayBuffer();
3898
+ if (body instanceof ArrayBuffer) return body;
3899
+ if (ArrayBuffer.isView(body)) {
3900
+ return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
3901
+ }
3902
+ throw new Error("athena.storage.file.upload direct mode does not support ReadableStream bodies");
3903
+ }
3904
+ function bodySize(body) {
3905
+ if (isBlobBody(body)) return body.size;
3906
+ if (body instanceof ArrayBuffer) return body.byteLength;
3907
+ if (ArrayBuffer.isView(body)) return body.byteLength;
3908
+ return 0;
3909
+ }
3910
+ function awsEncode(value) {
3911
+ return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
3912
+ }
3913
+ function formatAmzDate(date) {
3914
+ return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
3915
+ }
3916
+ async function sha256Hex(value) {
3917
+ const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
3918
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
3919
+ return toHex(new Uint8Array(digest));
3920
+ }
3921
+ async function hmac(key, value) {
3922
+ const keyBytes = typeof key === "string" ? new TextEncoder().encode(key) : key;
3923
+ const cryptoKey = await crypto.subtle.importKey(
3924
+ "raw",
3925
+ keyBytes,
3926
+ { name: "HMAC", hash: "SHA-256" },
3927
+ false,
3928
+ ["sign"]
3929
+ );
3930
+ return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
3931
+ }
3932
+ async function hmacHex(key, value) {
3933
+ return toHex(new Uint8Array(await hmac(key, value)));
3934
+ }
3935
+ function toHex(bytes) {
3936
+ return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
3937
+ }
3938
+ function parseXhrHeaders(rawHeaders) {
3939
+ const headers = new Headers();
3940
+ rawHeaders.trim().split(/[\r\n]+/).forEach((line) => {
3941
+ const separator = line.indexOf(":");
3942
+ if (separator > 0) {
3943
+ headers.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
3944
+ }
3945
+ });
3946
+ return headers;
3780
3947
  }
3781
3948
 
3782
3949
  // src/storage/file.ts
3950
+ function mergeUploadHeaders(serverHeaders, inputHeaders) {
3951
+ const headers = { ...serverHeaders };
3952
+ new Headers(inputHeaders).forEach((value, key) => {
3953
+ headers[key] = value;
3954
+ });
3955
+ return headers;
3956
+ }
3783
3957
  function createStorageFileModule(base, config = {}) {
3784
3958
  const upload = async (input, options) => {
3785
3959
  const sources = normalizeUploadSources(input);
@@ -3815,16 +3989,25 @@ function createStorageFileModule(base, config = {}) {
3815
3989
  for (let index = 0; index < uploadRequests.length; index += 1) {
3816
3990
  const request2 = uploadRequests[index];
3817
3991
  const uploadUrl = uploadUrls[index];
3818
- const response = await putUploadBody(
3992
+ const aggregateProgress = (progress) => {
3993
+ aggregateLoaded[index] = progress.loaded;
3994
+ input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
3995
+ };
3996
+ const response = config.directUpload ? await putDirectStorageUploadBody(
3997
+ config.directUpload,
3998
+ uploadUrl.upload.bucket,
3999
+ uploadUrl.upload.storage_key,
4000
+ request2.source.source,
4001
+ mergeUploadHeaders(uploadUrl.upload.headers ?? {}, input.uploadHeaders),
4002
+ options?.signal,
4003
+ aggregateProgress
4004
+ ) : await putUploadBody(
3819
4005
  uploadUrl.upload.url,
3820
4006
  uploadUrl.upload.headers ?? {},
3821
4007
  request2.source,
3822
4008
  input,
3823
4009
  options,
3824
- (progress) => {
3825
- aggregateLoaded[index] = progress.loaded;
3826
- input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
3827
- }
4010
+ aggregateProgress
3828
4011
  );
3829
4012
  uploaded.push({
3830
4013
  file: uploadUrl.file,
@@ -3975,7 +4158,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
3975
4158
  resolve3(new Response(xhr.response, {
3976
4159
  status: xhr.status,
3977
4160
  statusText: xhr.statusText,
3978
- headers: parseXhrHeaders(xhr.getAllResponseHeaders())
4161
+ headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
3979
4162
  }));
3980
4163
  };
3981
4164
  xhr.onerror = () => {
@@ -4113,7 +4296,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
4113
4296
  function sum(values) {
4114
4297
  return values.reduce((total, value) => total + value, 0);
4115
4298
  }
4116
- function parseXhrHeaders(raw) {
4299
+ function parseXhrHeaders2(raw) {
4117
4300
  const headers = new Headers();
4118
4301
  for (const line of raw.trim().split(/[\r\n]+/)) {
4119
4302
  const index = line.indexOf(":");
@@ -4130,6 +4313,230 @@ function isRecord5(value) {
4130
4313
  return Boolean(value) && typeof value === "object";
4131
4314
  }
4132
4315
 
4316
+ // src/storage/backup.ts
4317
+ function backupError(message, status, endpoint, method, cause, raw) {
4318
+ const error = new Error(message);
4319
+ error.name = "AthenaStorageError";
4320
+ error.code = status === 0 ? "NETWORK_ERROR" : "HTTP_ERROR";
4321
+ error.status = status;
4322
+ error.endpoint = endpoint;
4323
+ error.method = method;
4324
+ error.cause = cause;
4325
+ error.raw = raw;
4326
+ throw error;
4327
+ }
4328
+ function isRecord6(value) {
4329
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4330
+ }
4331
+ function asPath(path) {
4332
+ return path;
4333
+ }
4334
+ function appendQuery(path, query) {
4335
+ if (!query) return path;
4336
+ const params = new URLSearchParams();
4337
+ for (const [key, value] of Object.entries(query)) {
4338
+ if (value === void 0 || value === null || value === "") continue;
4339
+ params.set(key, String(value));
4340
+ }
4341
+ const text = params.toString();
4342
+ return text ? `${path}?${text}` : path;
4343
+ }
4344
+ function unwrapAthenaData(payload) {
4345
+ if (isRecord6(payload) && "data" in payload) {
4346
+ return payload.data;
4347
+ }
4348
+ return payload;
4349
+ }
4350
+ function requireKey(key) {
4351
+ const trimmed = key.trim();
4352
+ if (!trimmed || trimmed === "undefined" || trimmed === "null") {
4353
+ backupError("Backup object key is required", 400, "/admin/backups/{key}", "DELETE");
4354
+ }
4355
+ return trimmed;
4356
+ }
4357
+ function resolveMessage(payload, fallback) {
4358
+ if (isRecord6(payload)) {
4359
+ const message = payload.message ?? payload.error ?? payload.details;
4360
+ if (typeof message === "string" && message.trim()) return message.trim();
4361
+ }
4362
+ if (typeof payload === "string" && payload.trim()) return payload.trim();
4363
+ return fallback;
4364
+ }
4365
+ async function callBackupEndpoint(gateway, path, method, payload, options, runtime) {
4366
+ const endpoint = asPath(path);
4367
+ const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
4368
+ const url = buildAthenaGatewayUrl(baseUrl, endpoint);
4369
+ const headers = gateway.buildHeaders(options);
4370
+ const init = {
4371
+ method,
4372
+ headers,
4373
+ signal: options?.signal
4374
+ };
4375
+ if (payload !== void 0 && method !== "GET") {
4376
+ init.body = JSON.stringify(payload);
4377
+ }
4378
+ let response;
4379
+ try {
4380
+ response = await fetch(url, init);
4381
+ } catch (error) {
4382
+ backupError(
4383
+ error instanceof Error ? error.message : "Backup network error",
4384
+ 0,
4385
+ path,
4386
+ method,
4387
+ error
4388
+ );
4389
+ }
4390
+ const rawText = await response.text();
4391
+ let parsed = null;
4392
+ if (rawText) {
4393
+ try {
4394
+ parsed = JSON.parse(rawText);
4395
+ } catch {
4396
+ parsed = rawText;
4397
+ }
4398
+ }
4399
+ if (!response.ok) {
4400
+ backupError(
4401
+ resolveMessage(parsed, `Backup ${method} ${path} failed (${response.status})`),
4402
+ response.status,
4403
+ path,
4404
+ method,
4405
+ void 0,
4406
+ parsed
4407
+ );
4408
+ }
4409
+ return unwrapAthenaData(parsed);
4410
+ }
4411
+ function createStorageBackupModule(gateway, runtimeOptions) {
4412
+ const resolvedBaseUrl = () => String(gateway.baseUrl ?? "").replace(/\/+$/, "");
4413
+ return {
4414
+ async list(query, options) {
4415
+ const path = appendQuery("/admin/backups", {
4416
+ limit: query?.limit ?? 10,
4417
+ client_name: query?.client_name,
4418
+ cursor: query?.cursor ?? void 0
4419
+ });
4420
+ const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
4421
+ const backups = (data?.backups ?? []).map((row) => ({
4422
+ ...row,
4423
+ key: row.key ?? row.s3_key
4424
+ }));
4425
+ return {
4426
+ backups,
4427
+ next_cursor: data?.next_cursor ?? null
4428
+ };
4429
+ },
4430
+ async create(input, options) {
4431
+ const data = await callBackupEndpoint(gateway, "/admin/backups", "POST", input, options);
4432
+ return {
4433
+ job_id: Number(data?.job_id ?? 0),
4434
+ client_name: String(data?.client_name ?? input.client_name),
4435
+ status: String(data?.status ?? "pending")
4436
+ };
4437
+ },
4438
+ async restore(key, input, options) {
4439
+ const backupKey = requireKey(key);
4440
+ const path = `/admin/backups/${encodeURIComponent(backupKey)}/restore`;
4441
+ const data = await callBackupEndpoint(gateway, path, "POST", input, options);
4442
+ return {
4443
+ job_id: Number(data?.job_id ?? 0),
4444
+ client_name: String(data?.client_name ?? input.client_name),
4445
+ status: String(data?.status ?? "pending"),
4446
+ key: String(data?.key ?? backupKey)
4447
+ };
4448
+ },
4449
+ async delete(key, options) {
4450
+ const backupKey = requireKey(key);
4451
+ await callBackupEndpoint(
4452
+ gateway,
4453
+ `/admin/backups/${encodeURIComponent(backupKey)}`,
4454
+ "DELETE",
4455
+ void 0,
4456
+ options);
4457
+ },
4458
+ downloadUrl(key, options) {
4459
+ const backupKey = requireKey(key);
4460
+ const base = `${resolvedBaseUrl()}/admin/backups/${encodeURIComponent(backupKey)}/download`;
4461
+ return options?.apiKey ? `${base}?api_key=${encodeURIComponent(options.apiKey)}` : base;
4462
+ },
4463
+ jobs: {
4464
+ async list(query, options) {
4465
+ const path = appendQuery("/admin/backups/jobs", query ?? {});
4466
+ const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
4467
+ if (Array.isArray(data)) return data;
4468
+ if (isRecord6(data) && Array.isArray(data.jobs)) return data.jobs;
4469
+ return [];
4470
+ },
4471
+ async get(jobId, options) {
4472
+ return callBackupEndpoint(
4473
+ gateway,
4474
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
4475
+ "GET",
4476
+ void 0,
4477
+ options);
4478
+ },
4479
+ async cancel(jobId, options) {
4480
+ return callBackupEndpoint(
4481
+ gateway,
4482
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}/cancel`,
4483
+ "POST",
4484
+ {},
4485
+ options);
4486
+ },
4487
+ async delete(jobId, options) {
4488
+ await callBackupEndpoint(
4489
+ gateway,
4490
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
4491
+ "DELETE",
4492
+ void 0,
4493
+ options);
4494
+ },
4495
+ async openObjectUrl(jobId, options) {
4496
+ const data = await callBackupEndpoint(
4497
+ gateway,
4498
+ `/admin/backups/jobs/${encodeURIComponent(String(jobId))}/s3-open`,
4499
+ "GET",
4500
+ void 0,
4501
+ options);
4502
+ return String(data?.url ?? "");
4503
+ }
4504
+ },
4505
+ schedules: {
4506
+ async list(options) {
4507
+ const data = await callBackupEndpoint(gateway, "/admin/backups/schedules", "GET", void 0, options);
4508
+ if (Array.isArray(data)) return data;
4509
+ if (isRecord6(data) && Array.isArray(data.schedules)) return data.schedules;
4510
+ return [];
4511
+ },
4512
+ async create(input, options) {
4513
+ return callBackupEndpoint(
4514
+ gateway,
4515
+ "/admin/backups/schedules",
4516
+ "POST",
4517
+ input,
4518
+ options);
4519
+ },
4520
+ async update(id, input, options) {
4521
+ return callBackupEndpoint(
4522
+ gateway,
4523
+ `/admin/backups/schedules/${encodeURIComponent(String(id))}`,
4524
+ "PATCH",
4525
+ input,
4526
+ options);
4527
+ },
4528
+ async delete(id, options) {
4529
+ await callBackupEndpoint(
4530
+ gateway,
4531
+ `/admin/backups/schedules/${encodeURIComponent(String(id))}`,
4532
+ "DELETE",
4533
+ void 0,
4534
+ options);
4535
+ }
4536
+ }
4537
+ };
4538
+ }
4539
+
4133
4540
  // src/storage/module.ts
4134
4541
  var storageSdkManifest = {
4135
4542
  namespace: "storage",
@@ -4178,6 +4585,53 @@ var storageSdkManifest = {
4178
4585
  responseEnvelope: "raw",
4179
4586
  responseType: "{ data: S3CredentialListItem[] }"
4180
4587
  },
4588
+ {
4589
+ name: "backup.list",
4590
+ method: "GET",
4591
+ path: "/admin/backups",
4592
+ responseEnvelope: "athena",
4593
+ responseType: "StorageBackupListPage",
4594
+ note: "Admin backup archives on server S3/R2 profile"
4595
+ },
4596
+ {
4597
+ name: "backup.create",
4598
+ method: "POST",
4599
+ path: "/admin/backups",
4600
+ requestType: "StorageBackupCreateRequest",
4601
+ responseEnvelope: "athena",
4602
+ responseType: "StorageBackupQueuedJob"
4603
+ },
4604
+ {
4605
+ name: "backup.restore",
4606
+ method: "POST",
4607
+ path: "/admin/backups/{key}/restore",
4608
+ pathParams: ["key"],
4609
+ requestType: "StorageBackupRestoreRequest",
4610
+ responseEnvelope: "athena",
4611
+ responseType: "StorageBackupQueuedJob"
4612
+ },
4613
+ {
4614
+ name: "backup.delete",
4615
+ method: "DELETE",
4616
+ path: "/admin/backups/{key}",
4617
+ pathParams: ["key"],
4618
+ responseEnvelope: "athena",
4619
+ responseType: "void"
4620
+ },
4621
+ {
4622
+ name: "backup.jobs.list",
4623
+ method: "GET",
4624
+ path: "/admin/backups/jobs",
4625
+ responseEnvelope: "athena",
4626
+ responseType: "StorageBackupJob[]"
4627
+ },
4628
+ {
4629
+ name: "backup.schedules.list",
4630
+ method: "GET",
4631
+ path: "/admin/backups/schedules",
4632
+ responseEnvelope: "athena",
4633
+ responseType: "StorageBackupSchedule[]"
4634
+ },
4181
4635
  {
4182
4636
  name: "createStorageUploadUrl",
4183
4637
  method: "POST",
@@ -4833,7 +5287,7 @@ var AthenaStorageError = class extends Error {
4833
5287
  };
4834
5288
  }
4835
5289
  };
4836
- function isRecord6(value) {
5290
+ function isRecord7(value) {
4837
5291
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4838
5292
  }
4839
5293
  function causeToString(cause) {
@@ -4931,7 +5385,7 @@ function parseResponseBody3(rawText, contentType) {
4931
5385
  return { parsed: rawText, parseFailed: true };
4932
5386
  }
4933
5387
  }
4934
- function appendQuery(path, query) {
5388
+ function appendQuery2(path, query) {
4935
5389
  if (!query) return path;
4936
5390
  const params = new URLSearchParams();
4937
5391
  for (const [key, value] of Object.entries(query)) {
@@ -4957,7 +5411,7 @@ function withPathParam(path, name, value) {
4957
5411
  return path.replace(`{${name}}`, encodeURIComponent(value));
4958
5412
  }
4959
5413
  function resolveErrorMessage3(payload, fallback) {
4960
- if (isRecord6(payload)) {
5414
+ if (isRecord7(payload)) {
4961
5415
  const message = payload.message ?? payload.error ?? payload.details;
4962
5416
  if (typeof message === "string" && message.trim()) {
4963
5417
  return message.trim();
@@ -4969,12 +5423,12 @@ function resolveErrorMessage3(payload, fallback) {
4969
5423
  return fallback;
4970
5424
  }
4971
5425
  function resolveErrorHint2(payload) {
4972
- if (!isRecord6(payload)) return void 0;
5426
+ if (!isRecord7(payload)) return void 0;
4973
5427
  const hint = payload.hint ?? payload.suggestion;
4974
5428
  return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
4975
5429
  }
4976
5430
  function resolveErrorCause(payload) {
4977
- if (!isRecord6(payload)) return void 0;
5431
+ if (!isRecord7(payload)) return void 0;
4978
5432
  const cause = payload.cause ?? payload.reason;
4979
5433
  return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
4980
5434
  }
@@ -5093,7 +5547,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
5093
5547
  );
5094
5548
  }
5095
5549
  if (envelope === "athena") {
5096
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
5550
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
5097
5551
  return rejectStorageError(
5098
5552
  {
5099
5553
  code: "INVALID_ATHENA_ENVELOPE",
@@ -5201,7 +5655,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
5201
5655
  runtimeOptions
5202
5656
  );
5203
5657
  }
5204
- function isBlobBody(body) {
5658
+ function isBlobBody2(body) {
5205
5659
  return typeof Blob !== "undefined" && body instanceof Blob;
5206
5660
  }
5207
5661
  function isReadableStreamBody(body) {
@@ -5210,7 +5664,7 @@ function isReadableStreamBody(body) {
5210
5664
  async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
5211
5665
  const headers = new Headers(uploadHeaders);
5212
5666
  Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
5213
- if (!headers.has("Content-Type") && isBlobBody(body) && body.type) {
5667
+ if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
5214
5668
  headers.set("Content-Type", body.type);
5215
5669
  }
5216
5670
  const init = {
@@ -5305,7 +5759,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
5305
5759
  }
5306
5760
  delete headers["Content-Type"];
5307
5761
  delete headers["content-type"];
5308
- if (isBlobBody(body) && body.type) {
5762
+ if (isBlobBody2(body) && body.type) {
5309
5763
  headers["Content-Type"] = body.type;
5310
5764
  }
5311
5765
  const requestInit = {
@@ -5390,7 +5844,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
5390
5844
  runtimeOptions
5391
5845
  );
5392
5846
  }
5393
- if (!isRecord6(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
5847
+ if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
5394
5848
  return rejectStorageError(
5395
5849
  {
5396
5850
  code: "INVALID_ATHENA_ENVELOPE",
@@ -5462,14 +5916,14 @@ function createStorageModule(gateway, runtimeOptions) {
5462
5916
  return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
5463
5917
  },
5464
5918
  getStorageFileUrl(fileId, query, options) {
5465
- const path = appendQuery(
5919
+ const path = appendQuery2(
5466
5920
  withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
5467
5921
  query
5468
5922
  );
5469
5923
  return callAthena2(path, "GET", void 0, options);
5470
5924
  },
5471
5925
  getStorageFileProxy(fileId, query, options) {
5472
- const path = appendQuery(
5926
+ const path = appendQuery2(
5473
5927
  withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
5474
5928
  query
5475
5929
  );
@@ -5493,7 +5947,7 @@ function createStorageModule(gateway, runtimeOptions) {
5493
5947
  };
5494
5948
  const fileFacade = createStorageFileModule(base, runtimeOptions);
5495
5949
  const fileUpload = ((input, options) => {
5496
- if (isRecord6(input) && "files" in input) {
5950
+ if (isRecord7(input) && "files" in input) {
5497
5951
  return fileFacade.upload(input, options);
5498
5952
  }
5499
5953
  return base.createStorageUploadUrl(
@@ -5555,7 +6009,7 @@ function createStorageModule(gateway, runtimeOptions) {
5555
6009
  return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
5556
6010
  },
5557
6011
  proxyUrl(fileId, query, options) {
5558
- const path = appendQuery(
6012
+ const path = appendQuery2(
5559
6013
  withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
5560
6014
  query
5561
6015
  );
@@ -5593,7 +6047,7 @@ function createStorageModule(gateway, runtimeOptions) {
5593
6047
  },
5594
6048
  retention: {
5595
6049
  get(fileId, query, options) {
5596
- const path = appendQuery(
6050
+ const path = appendQuery2(
5597
6051
  withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
5598
6052
  query
5599
6053
  );
@@ -5795,6 +6249,7 @@ function createStorageModule(gateway, runtimeOptions) {
5795
6249
  return callAthena2("/storage/audit/list", "POST", input, options);
5796
6250
  }
5797
6251
  };
6252
+ const backup = createStorageBackupModule(gateway);
5798
6253
  return {
5799
6254
  ...base,
5800
6255
  credentials,
@@ -5806,6 +6261,7 @@ function createStorageModule(gateway, runtimeOptions) {
5806
6261
  bucket,
5807
6262
  multipart,
5808
6263
  audit,
6264
+ backup,
5809
6265
  delete: file.delete
5810
6266
  };
5811
6267
  }
@@ -5855,7 +6311,7 @@ function normalizeWsUrl(value, label) {
5855
6311
  parsed.pathname = parsed.pathname.replace(/\/+$/, "");
5856
6312
  return parsed.toString().replace(/\/$/, "");
5857
6313
  }
5858
- function isRecord7(value) {
6314
+ function isRecord8(value) {
5859
6315
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5860
6316
  }
5861
6317
  function parseResponseBody4(rawText, contentType) {
@@ -5877,7 +6333,7 @@ function resolveRequestId3(headers) {
5877
6333
  return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
5878
6334
  }
5879
6335
  function resolveErrorMessage4(payload, fallback) {
5880
- if (isRecord7(payload)) {
6336
+ if (isRecord8(payload)) {
5881
6337
  for (const candidate of [payload.error, payload.message, payload.details]) {
5882
6338
  if (typeof candidate === "string" && candidate.trim().length > 0) {
5883
6339
  return candidate.trim();
@@ -6524,7 +6980,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
6524
6980
  "ilike",
6525
6981
  "is"
6526
6982
  ]);
6527
- function isRecord8(value) {
6983
+ function isRecord9(value) {
6528
6984
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6529
6985
  }
6530
6986
  function isUuidString(value) {
@@ -6537,7 +6993,7 @@ function shouldUseUuidTextComparison(column, value) {
6537
6993
  return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
6538
6994
  }
6539
6995
  function isRelationSelectNode(value) {
6540
- return isRecord8(value) && isRecord8(value.select);
6996
+ return isRecord9(value) && isRecord9(value.select);
6541
6997
  }
6542
6998
  function normalizeIdentifier(value, label) {
6543
6999
  const normalized = value.trim();
@@ -6593,7 +7049,7 @@ function compileRelationToken(key, node) {
6593
7049
  return `${prefix}${relationToken}(${nested})`;
6594
7050
  }
6595
7051
  function compileSelectShape(select) {
6596
- if (!isRecord8(select)) {
7052
+ if (!isRecord9(select)) {
6597
7053
  throw new Error("findMany select must be an object");
6598
7054
  }
6599
7055
  const tokens = [];
@@ -6617,7 +7073,7 @@ function compileSelectShape(select) {
6617
7073
  return tokens.join(",");
6618
7074
  }
6619
7075
  function selectShapeUsesRelationSchema(select) {
6620
- if (!isRecord8(select)) {
7076
+ if (!isRecord9(select)) {
6621
7077
  return false;
6622
7078
  }
6623
7079
  for (const rawValue of Object.values(select)) {
@@ -6635,7 +7091,7 @@ function selectShapeUsesRelationSchema(select) {
6635
7091
  }
6636
7092
  function compileColumnWhere(column, input) {
6637
7093
  const normalizedColumn = normalizeIdentifier(column, "where column");
6638
- if (!isRecord8(input)) {
7094
+ if (!isRecord9(input)) {
6639
7095
  return [buildGatewayCondition("eq", normalizedColumn, input)];
6640
7096
  }
6641
7097
  const conditions = [];
@@ -6663,7 +7119,7 @@ function compileColumnWhere(column, input) {
6663
7119
  return conditions;
6664
7120
  }
6665
7121
  function compileBooleanExpressionTerms(clause, label) {
6666
- if (!isRecord8(clause)) {
7122
+ if (!isRecord9(clause)) {
6667
7123
  throw new Error(`findMany where.${label} clauses must be objects`);
6668
7124
  }
6669
7125
  const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
@@ -6672,7 +7128,7 @@ function compileBooleanExpressionTerms(clause, label) {
6672
7128
  }
6673
7129
  const [rawColumn, rawValue] = entries[0];
6674
7130
  const column = normalizeIdentifier(rawColumn, `where.${label} column`);
6675
- if (!isRecord8(rawValue)) {
7131
+ if (!isRecord9(rawValue)) {
6676
7132
  return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
6677
7133
  }
6678
7134
  const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
@@ -6696,7 +7152,7 @@ function compileWhere(where) {
6696
7152
  if (where === void 0) {
6697
7153
  return void 0;
6698
7154
  }
6699
- if (!isRecord8(where)) {
7155
+ if (!isRecord9(where)) {
6700
7156
  throw new Error("findMany where must be an object");
6701
7157
  }
6702
7158
  const conditions = [];
@@ -6746,7 +7202,7 @@ function compileOrderBy(orderBy) {
6746
7202
  if (orderBy === void 0) {
6747
7203
  return void 0;
6748
7204
  }
6749
- if (!isRecord8(orderBy)) {
7205
+ if (!isRecord9(orderBy)) {
6750
7206
  throw new Error("findMany orderBy must be an object");
6751
7207
  }
6752
7208
  if ("column" in orderBy) {
@@ -6921,11 +7377,11 @@ function toFindManyAstOrder(order) {
6921
7377
  ascending: order.direction !== "descending"
6922
7378
  };
6923
7379
  }
6924
- function isRecord9(value) {
7380
+ function isRecord10(value) {
6925
7381
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6926
7382
  }
6927
7383
  function normalizeFindManyAstColumnPredicate(value) {
6928
- if (!isRecord9(value)) {
7384
+ if (!isRecord10(value)) {
6929
7385
  return {
6930
7386
  eq: value
6931
7387
  };
@@ -6949,7 +7405,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
6949
7405
  return normalized;
6950
7406
  }
6951
7407
  function normalizeFindManyAstWhere(where) {
6952
- if (!where || !isRecord9(where)) {
7408
+ if (!where || !isRecord10(where)) {
6953
7409
  return where;
6954
7410
  }
6955
7411
  const normalized = {};
@@ -6963,7 +7419,7 @@ function normalizeFindManyAstWhere(where) {
6963
7419
  );
6964
7420
  continue;
6965
7421
  }
6966
- if (key === "not" && isRecord9(value)) {
7422
+ if (key === "not" && isRecord10(value)) {
6967
7423
  normalized.not = normalizeFindManyAstBooleanOperand(
6968
7424
  value
6969
7425
  );
@@ -6974,7 +7430,7 @@ function normalizeFindManyAstWhere(where) {
6974
7430
  return normalized;
6975
7431
  }
6976
7432
  function predicateRequiresUuidQueryFallback(column, value) {
6977
- if (!isRecord9(value)) {
7433
+ if (!isRecord10(value)) {
6978
7434
  return shouldUseUuidTextComparison(column, value);
6979
7435
  }
6980
7436
  const eqValue = value.eq;
@@ -6992,7 +7448,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
6992
7448
  return false;
6993
7449
  }
6994
7450
  function findManyAstWhereRequiresLegacyTransport(where) {
6995
- if (!where || !isRecord9(where)) {
7451
+ if (!where || !isRecord10(where)) {
6996
7452
  return false;
6997
7453
  }
6998
7454
  for (const [key, value] of Object.entries(where)) {
@@ -7007,7 +7463,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
7007
7463
  }
7008
7464
  continue;
7009
7465
  }
7010
- if (key === "not" && isRecord9(value)) {
7466
+ if (key === "not" && isRecord10(value)) {
7011
7467
  if (booleanOperandRequiresUuidQueryFallback(value)) {
7012
7468
  return true;
7013
7469
  }
@@ -7633,7 +8089,7 @@ async function executeExperimentalRead(experimental, runner) {
7633
8089
  throw error;
7634
8090
  }
7635
8091
  }
7636
- function isRecord10(value) {
8092
+ function isRecord11(value) {
7637
8093
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
7638
8094
  }
7639
8095
  function firstNonEmptyString2(...values) {
@@ -7645,8 +8101,8 @@ function firstNonEmptyString2(...values) {
7645
8101
  return void 0;
7646
8102
  }
7647
8103
  function resolveStructuredErrorPayload2(raw) {
7648
- if (!isRecord10(raw)) return null;
7649
- return isRecord10(raw.error) ? raw.error : raw;
8104
+ if (!isRecord11(raw)) return null;
8105
+ return isRecord11(raw.error) ? raw.error : raw;
7650
8106
  }
7651
8107
  function resolveStructuredErrorDetails(payload, message) {
7652
8108
  if (!payload || !("details" in payload)) {
@@ -7662,7 +8118,7 @@ function resolveStructuredErrorDetails(payload, message) {
7662
8118
  return details;
7663
8119
  }
7664
8120
  function createResultError(response, result, normalized) {
7665
- const rawRecord = isRecord10(response.raw) ? response.raw : null;
8121
+ const rawRecord = isRecord11(response.raw) ? response.raw : null;
7666
8122
  const payload = resolveStructuredErrorPayload2(response.raw);
7667
8123
  const message = firstNonEmptyString2(
7668
8124
  response.error,
@@ -9410,7 +9866,30 @@ function createClientFromConfig(config, sourceConfig) {
9410
9866
  config.experimental,
9411
9867
  queryTracer
9412
9868
  );
9413
- const db = createDbModule({ from, rpc, query });
9869
+ const untypedDbFrom = from;
9870
+ const db = {
9871
+ from,
9872
+ select(table2, first, second) {
9873
+ if (first && typeof first === "object" && !Array.isArray(first)) {
9874
+ return untypedDbFrom(table2).select(void 0, first);
9875
+ }
9876
+ return untypedDbFrom(table2).select(first, second);
9877
+ },
9878
+ insert(table2, values, options) {
9879
+ return Array.isArray(values) ? untypedDbFrom(table2).insert(values, options) : untypedDbFrom(table2).insert(values, options);
9880
+ },
9881
+ upsert(table2, values, options) {
9882
+ return Array.isArray(values) ? untypedDbFrom(table2).upsert(values, options) : untypedDbFrom(table2).upsert(values, options);
9883
+ },
9884
+ update(table2, values, options) {
9885
+ return untypedDbFrom(table2).update(values, options);
9886
+ },
9887
+ delete(table2, options) {
9888
+ return untypedDbFrom(table2).delete(options);
9889
+ },
9890
+ rpc,
9891
+ query
9892
+ };
9414
9893
  const chat = createChatModule({
9415
9894
  baseUrl: config.chatUrl,
9416
9895
  apiKey: config.apiKey,
@@ -9548,6 +10027,7 @@ function createClientFromConfig(config, sourceConfig) {
9548
10027
  withOptions: storageWithOptions,
9549
10028
  storage: createStorageModule(gateway, {
9550
10029
  ...config.experimental.storage,
10030
+ ...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
9551
10031
  ...config.storageUrl ? {
9552
10032
  baseUrl: config.storageUrl,
9553
10033
  stripBasePath: true
@@ -9561,7 +10041,9 @@ function createClientFromConfig(config, sourceConfig) {
9561
10041
  var AthenaClient = class {
9562
10042
  /** Create a fluent builder for a strongly-typed Athena SDK client. */
9563
10043
  static builder() {
9564
- return createAthenaClientBuilder((config) => createClientFromInput(config));
10044
+ return createAthenaClientBuilder(
10045
+ (config) => createClientFromInput(config)
10046
+ );
9565
10047
  }
9566
10048
  static fromEnvironment(options = {}) {
9567
10049
  const env = options.env ?? process.env;
@@ -9592,7 +10074,8 @@ var AthenaClient = class {
9592
10074
  });
9593
10075
  }
9594
10076
  };
9595
- function createClient(configOrUrl, apiKey, options) {
10077
+ function createClient(...args) {
10078
+ const [configOrUrl, apiKey, options] = args;
9596
10079
  if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
9597
10080
  return createClientFromInput({
9598
10081
  url: configOrUrl,
@@ -9631,7 +10114,7 @@ function resolveNullishValue(mode) {
9631
10114
  if (mode === "null") return null;
9632
10115
  return "";
9633
10116
  }
9634
- function isRecord11(value) {
10117
+ function isRecord12(value) {
9635
10118
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
9636
10119
  }
9637
10120
  function isNullableColumn(model, key) {
@@ -9640,7 +10123,7 @@ function isNullableColumn(model, key) {
9640
10123
  }
9641
10124
  function toModelFormDefaults(model, values, options) {
9642
10125
  const source = values;
9643
- if (!isRecord11(source)) {
10126
+ if (!isRecord12(source)) {
9644
10127
  return {};
9645
10128
  }
9646
10129
  const mode = options?.nullishMode ?? "empty-string";
@@ -10213,7 +10696,8 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
10213
10696
  fromModel(database, schema, model) {
10214
10697
  const modelDef = this.registryNavigator.resolveModel(database, schema, model);
10215
10698
  const tableName = this.registryNavigator.resolveTableName(schema, model, modelDef);
10216
- return this.baseClient.from(tableName);
10699
+ const from = this.baseClient.from;
10700
+ return from(tableName);
10217
10701
  }
10218
10702
  };
10219
10703
  function createTypedClient(registry, url, apiKey, options) {
@@ -12453,15 +12937,15 @@ function readCookieFromHeaders(headers, name) {
12453
12937
  }
12454
12938
  return parseCookies(cookieHeader).get(name);
12455
12939
  }
12456
- function isRecord12(value) {
12940
+ function isRecord13(value) {
12457
12941
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
12458
12942
  }
12459
12943
  function resolveSessionCandidate(value) {
12460
- if (!isRecord12(value)) {
12944
+ if (!isRecord13(value)) {
12461
12945
  return null;
12462
12946
  }
12463
- const session = isRecord12(value.session) ? value.session : void 0;
12464
- const user = isRecord12(value.user) ? value.user : void 0;
12947
+ const session = isRecord13(value.session) ? value.session : void 0;
12948
+ const user = isRecord13(value.user) ? value.user : void 0;
12465
12949
  if (session && typeof session.token === "string" && session.token.length > 0 && user) {
12466
12950
  return {
12467
12951
  session,
@@ -12471,7 +12955,7 @@ function resolveSessionCandidate(value) {
12471
12955
  return null;
12472
12956
  }
12473
12957
  function inferSessionPair(returned) {
12474
- return resolveSessionCandidate(returned) ?? (isRecord12(returned) ? resolveSessionCandidate(returned.data) : null) ?? (isRecord12(returned) ? resolveSessionCandidate(returned.session) : null);
12958
+ return resolveSessionCandidate(returned) ?? (isRecord13(returned) ? resolveSessionCandidate(returned.data) : null) ?? (isRecord13(returned) ? resolveSessionCandidate(returned.session) : null);
12475
12959
  }
12476
12960
  function resolveResponseHeaders(ctx) {
12477
12961
  if (ctx.context.responseHeaders instanceof Headers) {
@@ -12815,6 +13299,73 @@ function athenaAuth(config) {
12815
13299
  return auth;
12816
13300
  }
12817
13301
 
13302
+ // src/organization/ensure-active-organization.ts
13303
+ function normalizeOrganizationId(value) {
13304
+ if (typeof value !== "string") {
13305
+ return null;
13306
+ }
13307
+ const normalized = value.trim();
13308
+ return normalized.length > 0 ? normalized : null;
13309
+ }
13310
+ function defaultSelectOrganizationId(organizations) {
13311
+ for (const organization of organizations) {
13312
+ const id = normalizeOrganizationId(organization.id);
13313
+ if (id) {
13314
+ return id;
13315
+ }
13316
+ }
13317
+ return null;
13318
+ }
13319
+ async function ensureActiveOrganization(options) {
13320
+ const currentActiveOrganizationId = normalizeOrganizationId(
13321
+ options.session?.session?.activeOrganizationId
13322
+ );
13323
+ if (currentActiveOrganizationId) {
13324
+ return {
13325
+ activeOrganizationId: currentActiveOrganizationId,
13326
+ didSetActiveOrganization: false
13327
+ };
13328
+ }
13329
+ let organizations;
13330
+ try {
13331
+ organizations = await options.listOrganizations();
13332
+ } catch (error) {
13333
+ options.onError?.(error);
13334
+ return {
13335
+ activeOrganizationId: null,
13336
+ didSetActiveOrganization: false
13337
+ };
13338
+ }
13339
+ if (organizations.length === 0) {
13340
+ return {
13341
+ activeOrganizationId: null,
13342
+ didSetActiveOrganization: false
13343
+ };
13344
+ }
13345
+ const selectedOrganizationId = normalizeOrganizationId(
13346
+ (options.selectOrganizationId ?? defaultSelectOrganizationId)(organizations)
13347
+ );
13348
+ if (!selectedOrganizationId) {
13349
+ return {
13350
+ activeOrganizationId: null,
13351
+ didSetActiveOrganization: false
13352
+ };
13353
+ }
13354
+ try {
13355
+ await options.setActiveOrganization(selectedOrganizationId);
13356
+ return {
13357
+ activeOrganizationId: selectedOrganizationId,
13358
+ didSetActiveOrganization: true
13359
+ };
13360
+ } catch (error) {
13361
+ options.onError?.(error);
13362
+ return {
13363
+ activeOrganizationId: null,
13364
+ didSetActiveOrganization: false
13365
+ };
13366
+ }
13367
+ }
13368
+
12818
13369
  exports.ATHENA_AUTH_ADMIN_LIMITS = ATHENA_AUTH_ADMIN_LIMITS;
12819
13370
  exports.ATHENA_AUTH_BASE_ERROR_CODES = ATHENA_AUTH_BASE_ERROR_CODES;
12820
13371
  exports.ATHENA_AUTH_MAX_ADMIN_JSON_BYTES = ATHENA_AUTH_MAX_ADMIN_JSON_BYTES;
@@ -12851,6 +13402,7 @@ exports.defineGeneratorConfig = defineGeneratorConfig;
12851
13402
  exports.defineModel = defineModel;
12852
13403
  exports.defineRegistry = defineRegistry;
12853
13404
  exports.defineSchema = defineSchema;
13405
+ exports.ensureActiveOrganization = ensureActiveOrganization;
12854
13406
  exports.enumeration = enumeration;
12855
13407
  exports.filterIntrospectionSnapshot = filterIntrospectionSnapshot;
12856
13408
  exports.findGeneratorConfigPath = findGeneratorConfigPath;