@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.
- package/LICENSE +21 -21
- package/README.md +1190 -1184
- package/bin/athena-js.js +104 -76
- package/dist/admin.cjs +45 -0
- package/dist/admin.cjs.map +1 -0
- package/dist/admin.d.cts +64 -0
- package/dist/admin.d.ts +64 -0
- package/dist/admin.js +41 -0
- package/dist/admin.js.map +1 -0
- package/dist/athena-auth-url-oLux_57a.d.cts +377 -0
- package/dist/athena-auth-url-oLux_57a.d.ts +377 -0
- package/dist/browser.cjs +580 -96
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +12 -10
- package/dist/browser.d.ts +12 -10
- package/dist/browser.js +580 -96
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +690 -91
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +14 -5
- package/dist/cli/index.d.ts +14 -5
- package/dist/cli/index.js +690 -92
- package/dist/cli/index.js.map +1 -1
- package/dist/{client-CMtx5P4D.d.cts → client-uthENhaf.d.ts} +346 -1488
- package/dist/{client-Dre8H24u.d.ts → client-wU2J9yqb.d.cts} +346 -1488
- package/dist/cookies.cjs +18 -0
- package/dist/cookies.cjs.map +1 -1
- package/dist/cookies.d.cts +2 -1
- package/dist/cookies.d.ts +2 -1
- package/dist/cookies.js +17 -1
- package/dist/cookies.js.map +1 -1
- package/dist/{index-CVcQCGyG.d.ts → index-CFL9xbFR.d.cts} +2 -0
- package/dist/{index-CVcQCGyG.d.cts → index-UKJpunc6.d.ts} +2 -0
- package/dist/index.cjs +648 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.js +648 -97
- package/dist/index.js.map +1 -1
- package/dist/{model-form-DfTi8-D1.d.cts → model-form-BE1_Bmdd.d.cts} +2 -2
- package/dist/{model-form-CU0mWrF9.d.ts → model-form-DcH3R7WD.d.ts} +2 -2
- package/dist/{module-DBGmbIuh.d.ts → module-Ca3_OQqR.d.ts} +12 -9
- package/dist/{module-GoijrBXV.d.cts → module-DFGZXCtt.d.cts} +12 -9
- package/dist/next/client.cjs +992 -89
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.cts +7 -4
- package/dist/next/client.d.ts +7 -4
- package/dist/next/client.js +970 -90
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +832 -89
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.d.cts +81 -5
- package/dist/next/server.d.ts +81 -5
- package/dist/next/server.js +820 -90
- package/dist/next/server.js.map +1 -1
- package/dist/organization.cjs +72 -0
- package/dist/organization.cjs.map +1 -0
- package/dist/organization.d.cts +43 -0
- package/dist/organization.d.ts +43 -0
- package/dist/organization.js +70 -0
- package/dist/organization.js.map +1 -0
- package/dist/payload-BbSCmILD.d.ts +219 -0
- package/dist/payload-zXIwKTQf.d.cts +219 -0
- package/dist/{pipeline-c7Gdm0qv.d.cts → pipeline-CwQoD5G9.d.cts} +1 -1
- package/dist/{pipeline-DrjU2vNA.d.ts → pipeline-DqwehoQV.d.ts} +1 -1
- package/dist/react.cjs +2 -13
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +26 -7
- package/dist/react.d.ts +26 -7
- package/dist/react.js +2 -13
- package/dist/react.js.map +1 -1
- package/dist/session-cookie-detection-BqOp9mO6.d.cts +46 -0
- package/dist/session-cookie-detection-BqOp9mO6.d.ts +46 -0
- package/dist/social-providers.cjs +4198 -0
- package/dist/social-providers.cjs.map +1 -0
- package/dist/social-providers.d.cts +4948 -0
- package/dist/social-providers.d.ts +4948 -0
- package/dist/social-providers.js +4126 -0
- package/dist/social-providers.js.map +1 -0
- package/dist/{types-kPaHUqUa.d.ts → types-6H575ITc.d.cts} +50 -2
- package/dist/{types-DRRb0Fd0.d.ts → types-C1swabT5.d.ts} +3 -3
- package/dist/{types-Bez4HSbI.d.cts → types-CD6K05JQ.d.ts} +50 -2
- package/dist/{types-BRUHGXo2.d.ts → types-YQUR7wu0.d.cts} +3 -3
- package/dist/{types-BRUHGXo2.d.cts → types-YQUR7wu0.d.ts} +3 -3
- package/dist/{types-BLizCLd1.d.cts → types-dHnjluBC.d.cts} +3 -3
- package/dist/types-eAKAh71s.d.cts +1476 -0
- package/dist/types-eAKAh71s.d.ts +1476 -0
- package/dist/utils.cjs +438 -15
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +76 -11
- package/dist/utils.d.ts +76 -11
- package/dist/utils.js +390 -16
- package/dist/utils.js.map +1 -1
- package/package.json +29 -1
- package/dist/shared-DZSGAmXs.d.cts +0 -35
- package/dist/shared-MMnVBBfy.d.ts +0 -35
package/dist/next/client.cjs
CHANGED
|
@@ -162,7 +162,7 @@ var getSessionCookie = (request2, config) => {
|
|
|
162
162
|
|
|
163
163
|
// src/utils/athena-request-headers.ts
|
|
164
164
|
var NO_CACHE_HEADER_VALUE = "no-cache";
|
|
165
|
-
var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
|
|
165
|
+
var API_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key", "X-Api-Key", "x-api-key", "apikey"];
|
|
166
166
|
var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
|
|
167
167
|
var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
|
|
168
168
|
var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
|
|
@@ -264,17 +264,6 @@ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, ex
|
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
266
|
function applyAthenaApiKeyHeaders(headers, apiKey, athenaKey) {
|
|
267
|
-
if (apiKey) {
|
|
268
|
-
if (!hasHeaderIgnoreCase(headers, "apikey")) {
|
|
269
|
-
headers.apikey = apiKey;
|
|
270
|
-
}
|
|
271
|
-
if (!Object.hasOwn(headers, "x-api-key")) {
|
|
272
|
-
headers["x-api-key"] = apiKey;
|
|
273
|
-
}
|
|
274
|
-
if (!Object.hasOwn(headers, "X-Api-Key")) {
|
|
275
|
-
headers["X-Api-Key"] = apiKey;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
267
|
const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
|
|
279
268
|
if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
|
|
280
269
|
headers["X-Athena-Key"] = resolvedAthenaKey;
|
|
@@ -400,7 +389,7 @@ function buildAthenaRequestHeaders(input) {
|
|
|
400
389
|
|
|
401
390
|
// package.json
|
|
402
391
|
var package_default = {
|
|
403
|
-
version: "2.
|
|
392
|
+
version: "2.14.0"
|
|
404
393
|
};
|
|
405
394
|
|
|
406
395
|
// src/sdk-version.ts
|
|
@@ -2829,39 +2818,224 @@ async function withRetry(config, fn) {
|
|
|
2829
2818
|
throw new Error("withRetry reached an unexpected state");
|
|
2830
2819
|
}
|
|
2831
2820
|
|
|
2832
|
-
// src/
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2821
|
+
// src/storage/direct-upload.ts
|
|
2822
|
+
var SERVICE = "s3";
|
|
2823
|
+
var TERMINATOR = "aws4_request";
|
|
2824
|
+
async function putDirectStorageUploadBody(config, bucket, storageKey, body, uploadHeaders, signal, onProgress) {
|
|
2825
|
+
if (config.bucket && bucket && config.bucket !== bucket) {
|
|
2826
|
+
throw new Error(
|
|
2827
|
+
`athena.storage.file.upload direct mode bucket mismatch: configured ${config.bucket} but Athena returned ${bucket}`
|
|
2828
|
+
);
|
|
2829
|
+
}
|
|
2830
|
+
const target = createDirectUploadTarget(config, bucket, storageKey);
|
|
2831
|
+
const bytes = await bodyToArrayBuffer(body);
|
|
2832
|
+
const payloadHash = await sha256Hex(bytes);
|
|
2833
|
+
const headers = new Headers(uploadHeaders);
|
|
2834
|
+
if (isBlobBody(body) && body.type && !headers.has("Content-Type")) {
|
|
2835
|
+
headers.set("Content-Type", body.type);
|
|
2836
|
+
}
|
|
2837
|
+
const signed = await signDirectUploadRequest(config, target, headers, payloadHash);
|
|
2838
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
2839
|
+
return putWithXhr(target.toString(), signed, body, signal, onProgress);
|
|
2840
|
+
}
|
|
2841
|
+
onProgress({ loaded: 0 });
|
|
2842
|
+
const response = await fetch(target, {
|
|
2843
|
+
method: "PUT",
|
|
2844
|
+
headers: signed.requestHeaders,
|
|
2845
|
+
body,
|
|
2846
|
+
signal
|
|
2847
|
+
});
|
|
2848
|
+
if (!response.ok) {
|
|
2849
|
+
throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
|
|
2850
|
+
}
|
|
2851
|
+
onProgress({ loaded: bytes.byteLength });
|
|
2852
|
+
return response;
|
|
2853
|
+
}
|
|
2854
|
+
function createDirectUploadTarget(config, bucket, storageKey) {
|
|
2855
|
+
const resolvedBucket = config.bucket ?? bucket;
|
|
2856
|
+
if (!resolvedBucket?.trim()) {
|
|
2857
|
+
throw new Error(
|
|
2858
|
+
"athena.storage.file.upload direct mode requires a bucket in experimental.directStorageUpload or the server upload response"
|
|
2859
|
+
);
|
|
2860
|
+
}
|
|
2861
|
+
if (!storageKey.trim()) {
|
|
2862
|
+
throw new Error("athena.storage.file.upload direct mode requires a storage key");
|
|
2863
|
+
}
|
|
2864
|
+
let endpoint;
|
|
2865
|
+
try {
|
|
2866
|
+
endpoint = new URL(config.endpoint);
|
|
2867
|
+
} catch (error) {
|
|
2868
|
+
throw new Error(
|
|
2869
|
+
`athena.storage.file.upload direct mode received an invalid endpoint: ${error instanceof Error ? error.message : String(error)}`
|
|
2870
|
+
);
|
|
2871
|
+
}
|
|
2872
|
+
if (endpoint.search || endpoint.hash) {
|
|
2873
|
+
throw new Error("athena.storage.file.upload direct mode endpoint must not contain a query or hash");
|
|
2874
|
+
}
|
|
2875
|
+
const endpointPath = endpoint.pathname.replace(/\/+$/, "");
|
|
2876
|
+
const pathParts = config.forcePathStyle === false ? [endpointPath, storageKey] : [endpointPath, resolvedBucket, storageKey];
|
|
2877
|
+
if (config.forcePathStyle === false) {
|
|
2878
|
+
endpoint.hostname = `${resolvedBucket}.${endpoint.hostname}`;
|
|
2879
|
+
}
|
|
2880
|
+
endpoint.pathname = pathParts.filter(Boolean).flatMap((part) => part.split("/")).map(awsEncode).join("/").replace(/^([^/])/, "/$1");
|
|
2881
|
+
return endpoint;
|
|
2882
|
+
}
|
|
2883
|
+
async function signDirectUploadRequest(config, target, inputHeaders, payloadHash) {
|
|
2884
|
+
const accessKeyId = config.accessKeyId.trim();
|
|
2885
|
+
const secretAccessKey = config.secretAccessKey.trim();
|
|
2886
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
2887
|
+
throw new Error(
|
|
2888
|
+
"athena.storage.file.upload direct mode requires accessKeyId and secretAccessKey"
|
|
2889
|
+
);
|
|
2890
|
+
}
|
|
2891
|
+
const now = /* @__PURE__ */ new Date();
|
|
2892
|
+
const amzDate = formatAmzDate(now);
|
|
2893
|
+
const shortDate = amzDate.slice(0, 8);
|
|
2894
|
+
const region = config.region?.trim() || "auto";
|
|
2895
|
+
const headers = {};
|
|
2896
|
+
inputHeaders.forEach((value, key) => {
|
|
2897
|
+
if (key.toLowerCase() !== "authorization" && key.toLowerCase() !== "host") {
|
|
2898
|
+
headers[key.toLowerCase()] = value.trim().replace(/\s+/g, " ");
|
|
2899
|
+
}
|
|
2900
|
+
});
|
|
2901
|
+
headers["x-amz-content-sha256"] = payloadHash;
|
|
2902
|
+
headers["x-amz-date"] = amzDate;
|
|
2903
|
+
if (config.sessionToken?.trim()) {
|
|
2904
|
+
headers["x-amz-security-token"] = config.sessionToken.trim();
|
|
2905
|
+
}
|
|
2906
|
+
const canonicalHeaders = Object.keys(headers).sort().map((key) => `${key}:${headers[key]}
|
|
2907
|
+
`).join("");
|
|
2908
|
+
const signedHeaders = Object.keys(headers).sort().join(";");
|
|
2909
|
+
const canonicalRequest = [
|
|
2910
|
+
"PUT",
|
|
2911
|
+
target.pathname,
|
|
2912
|
+
"",
|
|
2913
|
+
`host:${target.host}
|
|
2914
|
+
${canonicalHeaders}`,
|
|
2915
|
+
`host;${signedHeaders}`,
|
|
2916
|
+
payloadHash
|
|
2917
|
+
].join("\n");
|
|
2918
|
+
const credentialScope = `${shortDate}/${region}/${SERVICE}/${TERMINATOR}`;
|
|
2919
|
+
const stringToSign = [
|
|
2920
|
+
"AWS4-HMAC-SHA256",
|
|
2921
|
+
amzDate,
|
|
2922
|
+
credentialScope,
|
|
2923
|
+
await sha256Hex(canonicalRequest)
|
|
2924
|
+
].join("\n");
|
|
2925
|
+
const dateKey = await hmac(`AWS4${secretAccessKey}`, shortDate);
|
|
2926
|
+
const regionKey = await hmac(dateKey, region);
|
|
2927
|
+
const serviceKey = await hmac(regionKey, SERVICE);
|
|
2928
|
+
const signingKey = await hmac(serviceKey, TERMINATOR);
|
|
2929
|
+
const signature = await hmacHex(signingKey, stringToSign);
|
|
2930
|
+
headers.authorization = `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=host;${signedHeaders}, Signature=${signature}`;
|
|
2931
|
+
return { requestHeaders: headers };
|
|
2932
|
+
}
|
|
2933
|
+
async function putWithXhr(url, signed, body, signal, onProgress) {
|
|
2934
|
+
const Xhr = XMLHttpRequest;
|
|
2935
|
+
if (Xhr === void 0) {
|
|
2936
|
+
return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
|
|
2937
|
+
}
|
|
2938
|
+
return new Promise((resolve, reject) => {
|
|
2939
|
+
const xhr = new Xhr();
|
|
2940
|
+
const abort = () => xhr.abort();
|
|
2941
|
+
xhr.open("PUT", url);
|
|
2942
|
+
Object.entries(signed.requestHeaders).forEach(([key, value]) => xhr.setRequestHeader(key, value));
|
|
2943
|
+
xhr.upload.onprogress = (event) => onProgress({ loaded: event.loaded });
|
|
2944
|
+
xhr.onload = () => {
|
|
2945
|
+
signal?.removeEventListener("abort", abort);
|
|
2946
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
2947
|
+
reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
|
|
2948
|
+
return;
|
|
2839
2949
|
}
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2950
|
+
onProgress({ loaded: bodySize(body) });
|
|
2951
|
+
resolve(new Response(xhr.response, {
|
|
2952
|
+
status: xhr.status,
|
|
2953
|
+
statusText: xhr.statusText,
|
|
2954
|
+
headers: parseXhrHeaders(xhr.getAllResponseHeaders())
|
|
2955
|
+
}));
|
|
2956
|
+
};
|
|
2957
|
+
xhr.onerror = () => {
|
|
2958
|
+
signal?.removeEventListener("abort", abort);
|
|
2959
|
+
reject(new Error("athena.storage.file.upload failed with a network error"));
|
|
2960
|
+
};
|
|
2961
|
+
xhr.onabort = () => {
|
|
2962
|
+
signal?.removeEventListener("abort", abort);
|
|
2963
|
+
reject(new DOMException("Upload aborted", "AbortError"));
|
|
2964
|
+
};
|
|
2965
|
+
if (signal) {
|
|
2966
|
+
if (signal.aborted) {
|
|
2967
|
+
abort();
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
2859
2971
|
}
|
|
2860
|
-
|
|
2861
|
-
|
|
2972
|
+
xhr.send(body);
|
|
2973
|
+
});
|
|
2974
|
+
}
|
|
2975
|
+
function isBlobBody(body) {
|
|
2976
|
+
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
2977
|
+
}
|
|
2978
|
+
async function bodyToArrayBuffer(body) {
|
|
2979
|
+
if (isBlobBody(body)) return body.arrayBuffer();
|
|
2980
|
+
if (body instanceof ArrayBuffer) return body;
|
|
2981
|
+
if (ArrayBuffer.isView(body)) {
|
|
2982
|
+
return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
|
|
2983
|
+
}
|
|
2984
|
+
throw new Error("athena.storage.file.upload direct mode does not support ReadableStream bodies");
|
|
2985
|
+
}
|
|
2986
|
+
function bodySize(body) {
|
|
2987
|
+
if (isBlobBody(body)) return body.size;
|
|
2988
|
+
if (body instanceof ArrayBuffer) return body.byteLength;
|
|
2989
|
+
if (ArrayBuffer.isView(body)) return body.byteLength;
|
|
2990
|
+
return 0;
|
|
2991
|
+
}
|
|
2992
|
+
function awsEncode(value) {
|
|
2993
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
2994
|
+
}
|
|
2995
|
+
function formatAmzDate(date) {
|
|
2996
|
+
return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
2997
|
+
}
|
|
2998
|
+
async function sha256Hex(value) {
|
|
2999
|
+
const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
|
|
3000
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
3001
|
+
return toHex(new Uint8Array(digest));
|
|
3002
|
+
}
|
|
3003
|
+
async function hmac(key, value) {
|
|
3004
|
+
const keyBytes = typeof key === "string" ? new TextEncoder().encode(key) : key;
|
|
3005
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
3006
|
+
"raw",
|
|
3007
|
+
keyBytes,
|
|
3008
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
3009
|
+
false,
|
|
3010
|
+
["sign"]
|
|
3011
|
+
);
|
|
3012
|
+
return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
|
|
3013
|
+
}
|
|
3014
|
+
async function hmacHex(key, value) {
|
|
3015
|
+
return toHex(new Uint8Array(await hmac(key, value)));
|
|
3016
|
+
}
|
|
3017
|
+
function toHex(bytes) {
|
|
3018
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
3019
|
+
}
|
|
3020
|
+
function parseXhrHeaders(rawHeaders) {
|
|
3021
|
+
const headers = new Headers();
|
|
3022
|
+
rawHeaders.trim().split(/[\r\n]+/).forEach((line) => {
|
|
3023
|
+
const separator = line.indexOf(":");
|
|
3024
|
+
if (separator > 0) {
|
|
3025
|
+
headers.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
3026
|
+
}
|
|
3027
|
+
});
|
|
3028
|
+
return headers;
|
|
2862
3029
|
}
|
|
2863
3030
|
|
|
2864
3031
|
// src/storage/file.ts
|
|
3032
|
+
function mergeUploadHeaders(serverHeaders, inputHeaders) {
|
|
3033
|
+
const headers = { ...serverHeaders };
|
|
3034
|
+
new Headers(inputHeaders).forEach((value, key) => {
|
|
3035
|
+
headers[key] = value;
|
|
3036
|
+
});
|
|
3037
|
+
return headers;
|
|
3038
|
+
}
|
|
2865
3039
|
function createStorageFileModule(base, config = {}) {
|
|
2866
3040
|
const upload = async (input, options) => {
|
|
2867
3041
|
const sources = normalizeUploadSources(input);
|
|
@@ -2897,16 +3071,25 @@ function createStorageFileModule(base, config = {}) {
|
|
|
2897
3071
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
2898
3072
|
const request2 = uploadRequests[index];
|
|
2899
3073
|
const uploadUrl = uploadUrls[index];
|
|
2900
|
-
const
|
|
3074
|
+
const aggregateProgress = (progress) => {
|
|
3075
|
+
aggregateLoaded[index] = progress.loaded;
|
|
3076
|
+
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
3077
|
+
};
|
|
3078
|
+
const response = config.directUpload ? await putDirectStorageUploadBody(
|
|
3079
|
+
config.directUpload,
|
|
3080
|
+
uploadUrl.upload.bucket,
|
|
3081
|
+
uploadUrl.upload.storage_key,
|
|
3082
|
+
request2.source.source,
|
|
3083
|
+
mergeUploadHeaders(uploadUrl.upload.headers ?? {}, input.uploadHeaders),
|
|
3084
|
+
options?.signal,
|
|
3085
|
+
aggregateProgress
|
|
3086
|
+
) : await putUploadBody(
|
|
2901
3087
|
uploadUrl.upload.url,
|
|
2902
3088
|
uploadUrl.upload.headers ?? {},
|
|
2903
3089
|
request2.source,
|
|
2904
3090
|
input,
|
|
2905
3091
|
options,
|
|
2906
|
-
|
|
2907
|
-
aggregateLoaded[index] = progress.loaded;
|
|
2908
|
-
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
2909
|
-
}
|
|
3092
|
+
aggregateProgress
|
|
2910
3093
|
);
|
|
2911
3094
|
uploaded.push({
|
|
2912
3095
|
file: uploadUrl.file,
|
|
@@ -3057,7 +3240,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
|
|
|
3057
3240
|
resolve(new Response(xhr.response, {
|
|
3058
3241
|
status: xhr.status,
|
|
3059
3242
|
statusText: xhr.statusText,
|
|
3060
|
-
headers:
|
|
3243
|
+
headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
|
|
3061
3244
|
}));
|
|
3062
3245
|
};
|
|
3063
3246
|
xhr.onerror = () => {
|
|
@@ -3195,7 +3378,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
|
|
|
3195
3378
|
function sum(values) {
|
|
3196
3379
|
return values.reduce((total, value) => total + value, 0);
|
|
3197
3380
|
}
|
|
3198
|
-
function
|
|
3381
|
+
function parseXhrHeaders2(raw) {
|
|
3199
3382
|
const headers = new Headers();
|
|
3200
3383
|
for (const line of raw.trim().split(/[\r\n]+/)) {
|
|
3201
3384
|
const index = line.indexOf(":");
|
|
@@ -3212,6 +3395,230 @@ function isRecord5(value) {
|
|
|
3212
3395
|
return Boolean(value) && typeof value === "object";
|
|
3213
3396
|
}
|
|
3214
3397
|
|
|
3398
|
+
// src/storage/backup.ts
|
|
3399
|
+
function backupError(message, status, endpoint, method, cause, raw) {
|
|
3400
|
+
const error = new Error(message);
|
|
3401
|
+
error.name = "AthenaStorageError";
|
|
3402
|
+
error.code = status === 0 ? "NETWORK_ERROR" : "HTTP_ERROR";
|
|
3403
|
+
error.status = status;
|
|
3404
|
+
error.endpoint = endpoint;
|
|
3405
|
+
error.method = method;
|
|
3406
|
+
error.cause = cause;
|
|
3407
|
+
error.raw = raw;
|
|
3408
|
+
throw error;
|
|
3409
|
+
}
|
|
3410
|
+
function isRecord6(value) {
|
|
3411
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3412
|
+
}
|
|
3413
|
+
function asPath(path) {
|
|
3414
|
+
return path;
|
|
3415
|
+
}
|
|
3416
|
+
function appendQuery(path, query) {
|
|
3417
|
+
if (!query) return path;
|
|
3418
|
+
const params = new URLSearchParams();
|
|
3419
|
+
for (const [key, value] of Object.entries(query)) {
|
|
3420
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
3421
|
+
params.set(key, String(value));
|
|
3422
|
+
}
|
|
3423
|
+
const text = params.toString();
|
|
3424
|
+
return text ? `${path}?${text}` : path;
|
|
3425
|
+
}
|
|
3426
|
+
function unwrapAthenaData(payload) {
|
|
3427
|
+
if (isRecord6(payload) && "data" in payload) {
|
|
3428
|
+
return payload.data;
|
|
3429
|
+
}
|
|
3430
|
+
return payload;
|
|
3431
|
+
}
|
|
3432
|
+
function requireKey(key) {
|
|
3433
|
+
const trimmed = key.trim();
|
|
3434
|
+
if (!trimmed || trimmed === "undefined" || trimmed === "null") {
|
|
3435
|
+
backupError("Backup object key is required", 400, "/admin/backups/{key}", "DELETE");
|
|
3436
|
+
}
|
|
3437
|
+
return trimmed;
|
|
3438
|
+
}
|
|
3439
|
+
function resolveMessage(payload, fallback) {
|
|
3440
|
+
if (isRecord6(payload)) {
|
|
3441
|
+
const message = payload.message ?? payload.error ?? payload.details;
|
|
3442
|
+
if (typeof message === "string" && message.trim()) return message.trim();
|
|
3443
|
+
}
|
|
3444
|
+
if (typeof payload === "string" && payload.trim()) return payload.trim();
|
|
3445
|
+
return fallback;
|
|
3446
|
+
}
|
|
3447
|
+
async function callBackupEndpoint(gateway, path, method, payload, options, runtime) {
|
|
3448
|
+
const endpoint = asPath(path);
|
|
3449
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
3450
|
+
const url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
3451
|
+
const headers = gateway.buildHeaders(options);
|
|
3452
|
+
const init = {
|
|
3453
|
+
method,
|
|
3454
|
+
headers,
|
|
3455
|
+
signal: options?.signal
|
|
3456
|
+
};
|
|
3457
|
+
if (payload !== void 0 && method !== "GET") {
|
|
3458
|
+
init.body = JSON.stringify(payload);
|
|
3459
|
+
}
|
|
3460
|
+
let response;
|
|
3461
|
+
try {
|
|
3462
|
+
response = await fetch(url, init);
|
|
3463
|
+
} catch (error) {
|
|
3464
|
+
backupError(
|
|
3465
|
+
error instanceof Error ? error.message : "Backup network error",
|
|
3466
|
+
0,
|
|
3467
|
+
path,
|
|
3468
|
+
method,
|
|
3469
|
+
error
|
|
3470
|
+
);
|
|
3471
|
+
}
|
|
3472
|
+
const rawText = await response.text();
|
|
3473
|
+
let parsed = null;
|
|
3474
|
+
if (rawText) {
|
|
3475
|
+
try {
|
|
3476
|
+
parsed = JSON.parse(rawText);
|
|
3477
|
+
} catch {
|
|
3478
|
+
parsed = rawText;
|
|
3479
|
+
}
|
|
3480
|
+
}
|
|
3481
|
+
if (!response.ok) {
|
|
3482
|
+
backupError(
|
|
3483
|
+
resolveMessage(parsed, `Backup ${method} ${path} failed (${response.status})`),
|
|
3484
|
+
response.status,
|
|
3485
|
+
path,
|
|
3486
|
+
method,
|
|
3487
|
+
void 0,
|
|
3488
|
+
parsed
|
|
3489
|
+
);
|
|
3490
|
+
}
|
|
3491
|
+
return unwrapAthenaData(parsed);
|
|
3492
|
+
}
|
|
3493
|
+
function createStorageBackupModule(gateway, runtimeOptions) {
|
|
3494
|
+
const resolvedBaseUrl = () => String(gateway.baseUrl ?? "").replace(/\/+$/, "");
|
|
3495
|
+
return {
|
|
3496
|
+
async list(query, options) {
|
|
3497
|
+
const path = appendQuery("/admin/backups", {
|
|
3498
|
+
limit: query?.limit ?? 10,
|
|
3499
|
+
client_name: query?.client_name,
|
|
3500
|
+
cursor: query?.cursor ?? void 0
|
|
3501
|
+
});
|
|
3502
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
3503
|
+
const backups = (data?.backups ?? []).map((row) => ({
|
|
3504
|
+
...row,
|
|
3505
|
+
key: row.key ?? row.s3_key
|
|
3506
|
+
}));
|
|
3507
|
+
return {
|
|
3508
|
+
backups,
|
|
3509
|
+
next_cursor: data?.next_cursor ?? null
|
|
3510
|
+
};
|
|
3511
|
+
},
|
|
3512
|
+
async create(input, options) {
|
|
3513
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups", "POST", input, options);
|
|
3514
|
+
return {
|
|
3515
|
+
job_id: Number(data?.job_id ?? 0),
|
|
3516
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
3517
|
+
status: String(data?.status ?? "pending")
|
|
3518
|
+
};
|
|
3519
|
+
},
|
|
3520
|
+
async restore(key, input, options) {
|
|
3521
|
+
const backupKey = requireKey(key);
|
|
3522
|
+
const path = `/admin/backups/${encodeURIComponent(backupKey)}/restore`;
|
|
3523
|
+
const data = await callBackupEndpoint(gateway, path, "POST", input, options);
|
|
3524
|
+
return {
|
|
3525
|
+
job_id: Number(data?.job_id ?? 0),
|
|
3526
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
3527
|
+
status: String(data?.status ?? "pending"),
|
|
3528
|
+
key: String(data?.key ?? backupKey)
|
|
3529
|
+
};
|
|
3530
|
+
},
|
|
3531
|
+
async delete(key, options) {
|
|
3532
|
+
const backupKey = requireKey(key);
|
|
3533
|
+
await callBackupEndpoint(
|
|
3534
|
+
gateway,
|
|
3535
|
+
`/admin/backups/${encodeURIComponent(backupKey)}`,
|
|
3536
|
+
"DELETE",
|
|
3537
|
+
void 0,
|
|
3538
|
+
options);
|
|
3539
|
+
},
|
|
3540
|
+
downloadUrl(key, options) {
|
|
3541
|
+
const backupKey = requireKey(key);
|
|
3542
|
+
const base = `${resolvedBaseUrl()}/admin/backups/${encodeURIComponent(backupKey)}/download`;
|
|
3543
|
+
return options?.apiKey ? `${base}?api_key=${encodeURIComponent(options.apiKey)}` : base;
|
|
3544
|
+
},
|
|
3545
|
+
jobs: {
|
|
3546
|
+
async list(query, options) {
|
|
3547
|
+
const path = appendQuery("/admin/backups/jobs", query ?? {});
|
|
3548
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
3549
|
+
if (Array.isArray(data)) return data;
|
|
3550
|
+
if (isRecord6(data) && Array.isArray(data.jobs)) return data.jobs;
|
|
3551
|
+
return [];
|
|
3552
|
+
},
|
|
3553
|
+
async get(jobId, options) {
|
|
3554
|
+
return callBackupEndpoint(
|
|
3555
|
+
gateway,
|
|
3556
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
3557
|
+
"GET",
|
|
3558
|
+
void 0,
|
|
3559
|
+
options);
|
|
3560
|
+
},
|
|
3561
|
+
async cancel(jobId, options) {
|
|
3562
|
+
return callBackupEndpoint(
|
|
3563
|
+
gateway,
|
|
3564
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/cancel`,
|
|
3565
|
+
"POST",
|
|
3566
|
+
{},
|
|
3567
|
+
options);
|
|
3568
|
+
},
|
|
3569
|
+
async delete(jobId, options) {
|
|
3570
|
+
await callBackupEndpoint(
|
|
3571
|
+
gateway,
|
|
3572
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
3573
|
+
"DELETE",
|
|
3574
|
+
void 0,
|
|
3575
|
+
options);
|
|
3576
|
+
},
|
|
3577
|
+
async openObjectUrl(jobId, options) {
|
|
3578
|
+
const data = await callBackupEndpoint(
|
|
3579
|
+
gateway,
|
|
3580
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/s3-open`,
|
|
3581
|
+
"GET",
|
|
3582
|
+
void 0,
|
|
3583
|
+
options);
|
|
3584
|
+
return String(data?.url ?? "");
|
|
3585
|
+
}
|
|
3586
|
+
},
|
|
3587
|
+
schedules: {
|
|
3588
|
+
async list(options) {
|
|
3589
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups/schedules", "GET", void 0, options);
|
|
3590
|
+
if (Array.isArray(data)) return data;
|
|
3591
|
+
if (isRecord6(data) && Array.isArray(data.schedules)) return data.schedules;
|
|
3592
|
+
return [];
|
|
3593
|
+
},
|
|
3594
|
+
async create(input, options) {
|
|
3595
|
+
return callBackupEndpoint(
|
|
3596
|
+
gateway,
|
|
3597
|
+
"/admin/backups/schedules",
|
|
3598
|
+
"POST",
|
|
3599
|
+
input,
|
|
3600
|
+
options);
|
|
3601
|
+
},
|
|
3602
|
+
async update(id, input, options) {
|
|
3603
|
+
return callBackupEndpoint(
|
|
3604
|
+
gateway,
|
|
3605
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
3606
|
+
"PATCH",
|
|
3607
|
+
input,
|
|
3608
|
+
options);
|
|
3609
|
+
},
|
|
3610
|
+
async delete(id, options) {
|
|
3611
|
+
await callBackupEndpoint(
|
|
3612
|
+
gateway,
|
|
3613
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
3614
|
+
"DELETE",
|
|
3615
|
+
void 0,
|
|
3616
|
+
options);
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
3621
|
+
|
|
3215
3622
|
// src/storage/module.ts
|
|
3216
3623
|
var storageSdkManifest = {
|
|
3217
3624
|
methods: [
|
|
@@ -3254,6 +3661,53 @@ var storageSdkManifest = {
|
|
|
3254
3661
|
responseEnvelope: "raw",
|
|
3255
3662
|
responseType: "{ data: S3CredentialListItem[] }"
|
|
3256
3663
|
},
|
|
3664
|
+
{
|
|
3665
|
+
name: "backup.list",
|
|
3666
|
+
method: "GET",
|
|
3667
|
+
path: "/admin/backups",
|
|
3668
|
+
responseEnvelope: "athena",
|
|
3669
|
+
responseType: "StorageBackupListPage",
|
|
3670
|
+
note: "Admin backup archives on server S3/R2 profile"
|
|
3671
|
+
},
|
|
3672
|
+
{
|
|
3673
|
+
name: "backup.create",
|
|
3674
|
+
method: "POST",
|
|
3675
|
+
path: "/admin/backups",
|
|
3676
|
+
requestType: "StorageBackupCreateRequest",
|
|
3677
|
+
responseEnvelope: "athena",
|
|
3678
|
+
responseType: "StorageBackupQueuedJob"
|
|
3679
|
+
},
|
|
3680
|
+
{
|
|
3681
|
+
name: "backup.restore",
|
|
3682
|
+
method: "POST",
|
|
3683
|
+
path: "/admin/backups/{key}/restore",
|
|
3684
|
+
pathParams: ["key"],
|
|
3685
|
+
requestType: "StorageBackupRestoreRequest",
|
|
3686
|
+
responseEnvelope: "athena",
|
|
3687
|
+
responseType: "StorageBackupQueuedJob"
|
|
3688
|
+
},
|
|
3689
|
+
{
|
|
3690
|
+
name: "backup.delete",
|
|
3691
|
+
method: "DELETE",
|
|
3692
|
+
path: "/admin/backups/{key}",
|
|
3693
|
+
pathParams: ["key"],
|
|
3694
|
+
responseEnvelope: "athena",
|
|
3695
|
+
responseType: "void"
|
|
3696
|
+
},
|
|
3697
|
+
{
|
|
3698
|
+
name: "backup.jobs.list",
|
|
3699
|
+
method: "GET",
|
|
3700
|
+
path: "/admin/backups/jobs",
|
|
3701
|
+
responseEnvelope: "athena",
|
|
3702
|
+
responseType: "StorageBackupJob[]"
|
|
3703
|
+
},
|
|
3704
|
+
{
|
|
3705
|
+
name: "backup.schedules.list",
|
|
3706
|
+
method: "GET",
|
|
3707
|
+
path: "/admin/backups/schedules",
|
|
3708
|
+
responseEnvelope: "athena",
|
|
3709
|
+
responseType: "StorageBackupSchedule[]"
|
|
3710
|
+
},
|
|
3257
3711
|
{
|
|
3258
3712
|
name: "createStorageUploadUrl",
|
|
3259
3713
|
method: "POST",
|
|
@@ -3901,7 +4355,7 @@ var AthenaStorageError = class extends Error {
|
|
|
3901
4355
|
};
|
|
3902
4356
|
}
|
|
3903
4357
|
};
|
|
3904
|
-
function
|
|
4358
|
+
function isRecord7(value) {
|
|
3905
4359
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3906
4360
|
}
|
|
3907
4361
|
function causeToString(cause) {
|
|
@@ -3999,7 +4453,7 @@ function parseResponseBody3(rawText, contentType) {
|
|
|
3999
4453
|
return { parsed: rawText, parseFailed: true };
|
|
4000
4454
|
}
|
|
4001
4455
|
}
|
|
4002
|
-
function
|
|
4456
|
+
function appendQuery2(path, query) {
|
|
4003
4457
|
if (!query) return path;
|
|
4004
4458
|
const params = new URLSearchParams();
|
|
4005
4459
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -4025,7 +4479,7 @@ function withPathParam(path, name, value) {
|
|
|
4025
4479
|
return path.replace(`{${name}}`, encodeURIComponent(value));
|
|
4026
4480
|
}
|
|
4027
4481
|
function resolveErrorMessage3(payload, fallback) {
|
|
4028
|
-
if (
|
|
4482
|
+
if (isRecord7(payload)) {
|
|
4029
4483
|
const message = payload.message ?? payload.error ?? payload.details;
|
|
4030
4484
|
if (typeof message === "string" && message.trim()) {
|
|
4031
4485
|
return message.trim();
|
|
@@ -4037,12 +4491,12 @@ function resolveErrorMessage3(payload, fallback) {
|
|
|
4037
4491
|
return fallback;
|
|
4038
4492
|
}
|
|
4039
4493
|
function resolveErrorHint2(payload) {
|
|
4040
|
-
if (!
|
|
4494
|
+
if (!isRecord7(payload)) return void 0;
|
|
4041
4495
|
const hint = payload.hint ?? payload.suggestion;
|
|
4042
4496
|
return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
|
|
4043
4497
|
}
|
|
4044
4498
|
function resolveErrorCause(payload) {
|
|
4045
|
-
if (!
|
|
4499
|
+
if (!isRecord7(payload)) return void 0;
|
|
4046
4500
|
const cause = payload.cause ?? payload.reason;
|
|
4047
4501
|
return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
|
|
4048
4502
|
}
|
|
@@ -4161,7 +4615,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
|
|
|
4161
4615
|
);
|
|
4162
4616
|
}
|
|
4163
4617
|
if (envelope === "athena") {
|
|
4164
|
-
if (!
|
|
4618
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
4165
4619
|
return rejectStorageError(
|
|
4166
4620
|
{
|
|
4167
4621
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -4269,7 +4723,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
|
|
|
4269
4723
|
runtimeOptions
|
|
4270
4724
|
);
|
|
4271
4725
|
}
|
|
4272
|
-
function
|
|
4726
|
+
function isBlobBody2(body) {
|
|
4273
4727
|
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
4274
4728
|
}
|
|
4275
4729
|
function isReadableStreamBody(body) {
|
|
@@ -4278,7 +4732,7 @@ function isReadableStreamBody(body) {
|
|
|
4278
4732
|
async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
|
|
4279
4733
|
const headers = new Headers(uploadHeaders);
|
|
4280
4734
|
Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
|
|
4281
|
-
if (!headers.has("Content-Type") &&
|
|
4735
|
+
if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
|
|
4282
4736
|
headers.set("Content-Type", body.type);
|
|
4283
4737
|
}
|
|
4284
4738
|
const init = {
|
|
@@ -4373,7 +4827,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
4373
4827
|
}
|
|
4374
4828
|
delete headers["Content-Type"];
|
|
4375
4829
|
delete headers["content-type"];
|
|
4376
|
-
if (
|
|
4830
|
+
if (isBlobBody2(body) && body.type) {
|
|
4377
4831
|
headers["Content-Type"] = body.type;
|
|
4378
4832
|
}
|
|
4379
4833
|
const requestInit = {
|
|
@@ -4458,7 +4912,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
4458
4912
|
runtimeOptions
|
|
4459
4913
|
);
|
|
4460
4914
|
}
|
|
4461
|
-
if (!
|
|
4915
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
4462
4916
|
return rejectStorageError(
|
|
4463
4917
|
{
|
|
4464
4918
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -4530,14 +4984,14 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4530
4984
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
|
|
4531
4985
|
},
|
|
4532
4986
|
getStorageFileUrl(fileId, query, options) {
|
|
4533
|
-
const path =
|
|
4987
|
+
const path = appendQuery2(
|
|
4534
4988
|
withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
|
|
4535
4989
|
query
|
|
4536
4990
|
);
|
|
4537
4991
|
return callAthena2(path, "GET", void 0, options);
|
|
4538
4992
|
},
|
|
4539
4993
|
getStorageFileProxy(fileId, query, options) {
|
|
4540
|
-
const path =
|
|
4994
|
+
const path = appendQuery2(
|
|
4541
4995
|
withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
|
|
4542
4996
|
query
|
|
4543
4997
|
);
|
|
@@ -4561,7 +5015,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4561
5015
|
};
|
|
4562
5016
|
const fileFacade = createStorageFileModule(base, runtimeOptions);
|
|
4563
5017
|
const fileUpload = ((input, options) => {
|
|
4564
|
-
if (
|
|
5018
|
+
if (isRecord7(input) && "files" in input) {
|
|
4565
5019
|
return fileFacade.upload(input, options);
|
|
4566
5020
|
}
|
|
4567
5021
|
return base.createStorageUploadUrl(
|
|
@@ -4623,7 +5077,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4623
5077
|
return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
|
|
4624
5078
|
},
|
|
4625
5079
|
proxyUrl(fileId, query, options) {
|
|
4626
|
-
const path =
|
|
5080
|
+
const path = appendQuery2(
|
|
4627
5081
|
withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
|
|
4628
5082
|
query
|
|
4629
5083
|
);
|
|
@@ -4661,7 +5115,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4661
5115
|
},
|
|
4662
5116
|
retention: {
|
|
4663
5117
|
get(fileId, query, options) {
|
|
4664
|
-
const path =
|
|
5118
|
+
const path = appendQuery2(
|
|
4665
5119
|
withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
|
|
4666
5120
|
query
|
|
4667
5121
|
);
|
|
@@ -4863,6 +5317,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4863
5317
|
return callAthena2("/storage/audit/list", "POST", input, options);
|
|
4864
5318
|
}
|
|
4865
5319
|
};
|
|
5320
|
+
const backup = createStorageBackupModule(gateway);
|
|
4866
5321
|
return {
|
|
4867
5322
|
...base,
|
|
4868
5323
|
credentials,
|
|
@@ -4874,6 +5329,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4874
5329
|
bucket,
|
|
4875
5330
|
multipart,
|
|
4876
5331
|
audit,
|
|
5332
|
+
backup,
|
|
4877
5333
|
delete: file.delete
|
|
4878
5334
|
};
|
|
4879
5335
|
}
|
|
@@ -4923,7 +5379,7 @@ function normalizeWsUrl(value, label) {
|
|
|
4923
5379
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
4924
5380
|
return parsed.toString().replace(/\/$/, "");
|
|
4925
5381
|
}
|
|
4926
|
-
function
|
|
5382
|
+
function isRecord8(value) {
|
|
4927
5383
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4928
5384
|
}
|
|
4929
5385
|
function parseResponseBody4(rawText, contentType) {
|
|
@@ -4945,7 +5401,7 @@ function resolveRequestId3(headers) {
|
|
|
4945
5401
|
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
4946
5402
|
}
|
|
4947
5403
|
function resolveErrorMessage4(payload, fallback) {
|
|
4948
|
-
if (
|
|
5404
|
+
if (isRecord8(payload)) {
|
|
4949
5405
|
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
4950
5406
|
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
4951
5407
|
return candidate.trim();
|
|
@@ -5559,7 +6015,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
5559
6015
|
"ilike",
|
|
5560
6016
|
"is"
|
|
5561
6017
|
]);
|
|
5562
|
-
function
|
|
6018
|
+
function isRecord9(value) {
|
|
5563
6019
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5564
6020
|
}
|
|
5565
6021
|
function isUuidString(value) {
|
|
@@ -5572,7 +6028,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
5572
6028
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
5573
6029
|
}
|
|
5574
6030
|
function isRelationSelectNode(value) {
|
|
5575
|
-
return
|
|
6031
|
+
return isRecord9(value) && isRecord9(value.select);
|
|
5576
6032
|
}
|
|
5577
6033
|
function normalizeIdentifier(value, label) {
|
|
5578
6034
|
const normalized = value.trim();
|
|
@@ -5628,7 +6084,7 @@ function compileRelationToken(key, node) {
|
|
|
5628
6084
|
return `${prefix}${relationToken}(${nested})`;
|
|
5629
6085
|
}
|
|
5630
6086
|
function compileSelectShape(select) {
|
|
5631
|
-
if (!
|
|
6087
|
+
if (!isRecord9(select)) {
|
|
5632
6088
|
throw new Error("findMany select must be an object");
|
|
5633
6089
|
}
|
|
5634
6090
|
const tokens = [];
|
|
@@ -5652,7 +6108,7 @@ function compileSelectShape(select) {
|
|
|
5652
6108
|
return tokens.join(",");
|
|
5653
6109
|
}
|
|
5654
6110
|
function selectShapeUsesRelationSchema(select) {
|
|
5655
|
-
if (!
|
|
6111
|
+
if (!isRecord9(select)) {
|
|
5656
6112
|
return false;
|
|
5657
6113
|
}
|
|
5658
6114
|
for (const rawValue of Object.values(select)) {
|
|
@@ -5670,7 +6126,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
5670
6126
|
}
|
|
5671
6127
|
function compileColumnWhere(column, input) {
|
|
5672
6128
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
5673
|
-
if (!
|
|
6129
|
+
if (!isRecord9(input)) {
|
|
5674
6130
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
5675
6131
|
}
|
|
5676
6132
|
const conditions = [];
|
|
@@ -5698,7 +6154,7 @@ function compileColumnWhere(column, input) {
|
|
|
5698
6154
|
return conditions;
|
|
5699
6155
|
}
|
|
5700
6156
|
function compileBooleanExpressionTerms(clause, label) {
|
|
5701
|
-
if (!
|
|
6157
|
+
if (!isRecord9(clause)) {
|
|
5702
6158
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
5703
6159
|
}
|
|
5704
6160
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -5707,7 +6163,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
5707
6163
|
}
|
|
5708
6164
|
const [rawColumn, rawValue] = entries[0];
|
|
5709
6165
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
5710
|
-
if (!
|
|
6166
|
+
if (!isRecord9(rawValue)) {
|
|
5711
6167
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
5712
6168
|
}
|
|
5713
6169
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -5731,7 +6187,7 @@ function compileWhere(where) {
|
|
|
5731
6187
|
if (where === void 0) {
|
|
5732
6188
|
return void 0;
|
|
5733
6189
|
}
|
|
5734
|
-
if (!
|
|
6190
|
+
if (!isRecord9(where)) {
|
|
5735
6191
|
throw new Error("findMany where must be an object");
|
|
5736
6192
|
}
|
|
5737
6193
|
const conditions = [];
|
|
@@ -5781,7 +6237,7 @@ function compileOrderBy(orderBy) {
|
|
|
5781
6237
|
if (orderBy === void 0) {
|
|
5782
6238
|
return void 0;
|
|
5783
6239
|
}
|
|
5784
|
-
if (!
|
|
6240
|
+
if (!isRecord9(orderBy)) {
|
|
5785
6241
|
throw new Error("findMany orderBy must be an object");
|
|
5786
6242
|
}
|
|
5787
6243
|
if ("column" in orderBy) {
|
|
@@ -5956,11 +6412,11 @@ function toFindManyAstOrder(order) {
|
|
|
5956
6412
|
ascending: order.direction !== "descending"
|
|
5957
6413
|
};
|
|
5958
6414
|
}
|
|
5959
|
-
function
|
|
6415
|
+
function isRecord10(value) {
|
|
5960
6416
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5961
6417
|
}
|
|
5962
6418
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
5963
|
-
if (!
|
|
6419
|
+
if (!isRecord10(value)) {
|
|
5964
6420
|
return {
|
|
5965
6421
|
eq: value
|
|
5966
6422
|
};
|
|
@@ -5984,7 +6440,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
5984
6440
|
return normalized;
|
|
5985
6441
|
}
|
|
5986
6442
|
function normalizeFindManyAstWhere(where) {
|
|
5987
|
-
if (!where || !
|
|
6443
|
+
if (!where || !isRecord10(where)) {
|
|
5988
6444
|
return where;
|
|
5989
6445
|
}
|
|
5990
6446
|
const normalized = {};
|
|
@@ -5998,7 +6454,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
5998
6454
|
);
|
|
5999
6455
|
continue;
|
|
6000
6456
|
}
|
|
6001
|
-
if (key === "not" &&
|
|
6457
|
+
if (key === "not" && isRecord10(value)) {
|
|
6002
6458
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
6003
6459
|
value
|
|
6004
6460
|
);
|
|
@@ -6009,7 +6465,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6009
6465
|
return normalized;
|
|
6010
6466
|
}
|
|
6011
6467
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
6012
|
-
if (!
|
|
6468
|
+
if (!isRecord10(value)) {
|
|
6013
6469
|
return shouldUseUuidTextComparison(column, value);
|
|
6014
6470
|
}
|
|
6015
6471
|
const eqValue = value.eq;
|
|
@@ -6027,7 +6483,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
6027
6483
|
return false;
|
|
6028
6484
|
}
|
|
6029
6485
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
6030
|
-
if (!where || !
|
|
6486
|
+
if (!where || !isRecord10(where)) {
|
|
6031
6487
|
return false;
|
|
6032
6488
|
}
|
|
6033
6489
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -6042,7 +6498,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
6042
6498
|
}
|
|
6043
6499
|
continue;
|
|
6044
6500
|
}
|
|
6045
|
-
if (key === "not" &&
|
|
6501
|
+
if (key === "not" && isRecord10(value)) {
|
|
6046
6502
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
6047
6503
|
return true;
|
|
6048
6504
|
}
|
|
@@ -6662,7 +7118,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
6662
7118
|
throw error;
|
|
6663
7119
|
}
|
|
6664
7120
|
}
|
|
6665
|
-
function
|
|
7121
|
+
function isRecord11(value) {
|
|
6666
7122
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6667
7123
|
}
|
|
6668
7124
|
function firstNonEmptyString2(...values) {
|
|
@@ -6674,8 +7130,8 @@ function firstNonEmptyString2(...values) {
|
|
|
6674
7130
|
return void 0;
|
|
6675
7131
|
}
|
|
6676
7132
|
function resolveStructuredErrorPayload2(raw) {
|
|
6677
|
-
if (!
|
|
6678
|
-
return
|
|
7133
|
+
if (!isRecord11(raw)) return null;
|
|
7134
|
+
return isRecord11(raw.error) ? raw.error : raw;
|
|
6679
7135
|
}
|
|
6680
7136
|
function resolveStructuredErrorDetails(payload, message) {
|
|
6681
7137
|
if (!payload || !("details" in payload)) {
|
|
@@ -6691,7 +7147,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
6691
7147
|
return details;
|
|
6692
7148
|
}
|
|
6693
7149
|
function createResultError(response, result, normalized) {
|
|
6694
|
-
const rawRecord =
|
|
7150
|
+
const rawRecord = isRecord11(response.raw) ? response.raw : null;
|
|
6695
7151
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
6696
7152
|
const message = firstNonEmptyString2(
|
|
6697
7153
|
response.error,
|
|
@@ -8439,7 +8895,30 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8439
8895
|
config.experimental,
|
|
8440
8896
|
queryTracer
|
|
8441
8897
|
);
|
|
8442
|
-
const
|
|
8898
|
+
const untypedDbFrom = from;
|
|
8899
|
+
const db = {
|
|
8900
|
+
from,
|
|
8901
|
+
select(table, first, second) {
|
|
8902
|
+
if (first && typeof first === "object" && !Array.isArray(first)) {
|
|
8903
|
+
return untypedDbFrom(table).select(void 0, first);
|
|
8904
|
+
}
|
|
8905
|
+
return untypedDbFrom(table).select(first, second);
|
|
8906
|
+
},
|
|
8907
|
+
insert(table, values, options) {
|
|
8908
|
+
return Array.isArray(values) ? untypedDbFrom(table).insert(values, options) : untypedDbFrom(table).insert(values, options);
|
|
8909
|
+
},
|
|
8910
|
+
upsert(table, values, options) {
|
|
8911
|
+
return Array.isArray(values) ? untypedDbFrom(table).upsert(values, options) : untypedDbFrom(table).upsert(values, options);
|
|
8912
|
+
},
|
|
8913
|
+
update(table, values, options) {
|
|
8914
|
+
return untypedDbFrom(table).update(values, options);
|
|
8915
|
+
},
|
|
8916
|
+
delete(table, options) {
|
|
8917
|
+
return untypedDbFrom(table).delete(options);
|
|
8918
|
+
},
|
|
8919
|
+
rpc,
|
|
8920
|
+
query
|
|
8921
|
+
};
|
|
8443
8922
|
const chat = createChatModule({
|
|
8444
8923
|
baseUrl: config.chatUrl,
|
|
8445
8924
|
apiKey: config.apiKey,
|
|
@@ -8577,6 +9056,7 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8577
9056
|
withOptions: storageWithOptions,
|
|
8578
9057
|
storage: createStorageModule(gateway, {
|
|
8579
9058
|
...config.experimental.storage,
|
|
9059
|
+
...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
|
|
8580
9060
|
...config.storageUrl ? {
|
|
8581
9061
|
baseUrl: config.storageUrl,
|
|
8582
9062
|
stripBasePath: true
|
|
@@ -8590,7 +9070,9 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8590
9070
|
var AthenaClient = class {
|
|
8591
9071
|
/** Create a fluent builder for a strongly-typed Athena SDK client. */
|
|
8592
9072
|
static builder() {
|
|
8593
|
-
return createAthenaClientBuilder(
|
|
9073
|
+
return createAthenaClientBuilder(
|
|
9074
|
+
(config) => createClientFromInput(config)
|
|
9075
|
+
);
|
|
8594
9076
|
}
|
|
8595
9077
|
static fromEnvironment(options = {}) {
|
|
8596
9078
|
const env = options.env ?? process.env;
|
|
@@ -8621,11 +9103,12 @@ var AthenaClient = class {
|
|
|
8621
9103
|
});
|
|
8622
9104
|
}
|
|
8623
9105
|
};
|
|
8624
|
-
function createClient(
|
|
9106
|
+
function createClient(...args) {
|
|
9107
|
+
const [configOrUrl, apiKey, options] = args;
|
|
8625
9108
|
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
8626
9109
|
return createClientFromInput({
|
|
8627
9110
|
url: configOrUrl,
|
|
8628
|
-
key: "",
|
|
9111
|
+
key: apiKey ?? "",
|
|
8629
9112
|
...options
|
|
8630
9113
|
});
|
|
8631
9114
|
}
|
|
@@ -8669,6 +9152,403 @@ function createAdapterClient(options, context) {
|
|
|
8669
9152
|
return client;
|
|
8670
9153
|
}
|
|
8671
9154
|
|
|
9155
|
+
// src/next/session-bridge/constants.ts
|
|
9156
|
+
var ATHENA_AUTH_SESSION_BRIDGE_ROUTE = "/api/athena-auth/session";
|
|
9157
|
+
var ATHENA_AUTH_SESSION_COOKIE_NAME = "athena-auth.session-token";
|
|
9158
|
+
var ATHENA_AUTH_SESSION_COOKIE_NAMES = [
|
|
9159
|
+
ATHENA_AUTH_SESSION_COOKIE_NAME,
|
|
9160
|
+
"athena-auth.session_token"
|
|
9161
|
+
];
|
|
9162
|
+
|
|
9163
|
+
// src/next/session-bridge/client.ts
|
|
9164
|
+
var JSON_CONTENT_TYPE = "application/json";
|
|
9165
|
+
function isBrowserRuntime() {
|
|
9166
|
+
return typeof globalThis !== "undefined" && "window" in globalThis;
|
|
9167
|
+
}
|
|
9168
|
+
async function persistAthenaAuthSessionOnAppHost(payload, options) {
|
|
9169
|
+
if (!(payload && isBrowserRuntime())) {
|
|
9170
|
+
return;
|
|
9171
|
+
}
|
|
9172
|
+
const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
|
|
9173
|
+
const fetchImpl = options?.fetch ?? fetch;
|
|
9174
|
+
const response = await fetchImpl(route, {
|
|
9175
|
+
body: JSON.stringify(payload),
|
|
9176
|
+
credentials: "same-origin",
|
|
9177
|
+
headers: {
|
|
9178
|
+
"Content-Type": JSON_CONTENT_TYPE
|
|
9179
|
+
},
|
|
9180
|
+
method: "POST"
|
|
9181
|
+
});
|
|
9182
|
+
if (!response.ok) {
|
|
9183
|
+
throw new Error("Failed to persist the Athena Auth session on the app host");
|
|
9184
|
+
}
|
|
9185
|
+
}
|
|
9186
|
+
async function clearAthenaAuthSessionOnAppHost(options) {
|
|
9187
|
+
if (!isBrowserRuntime()) {
|
|
9188
|
+
return;
|
|
9189
|
+
}
|
|
9190
|
+
const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
|
|
9191
|
+
const fetchImpl = options?.fetch ?? fetch;
|
|
9192
|
+
const response = await fetchImpl(route, {
|
|
9193
|
+
credentials: "same-origin",
|
|
9194
|
+
method: "DELETE"
|
|
9195
|
+
});
|
|
9196
|
+
if (!response.ok) {
|
|
9197
|
+
throw new Error("Failed to clear the Athena Auth session on the app host");
|
|
9198
|
+
}
|
|
9199
|
+
}
|
|
9200
|
+
|
|
9201
|
+
// src/next/session-bridge/payload.ts
|
|
9202
|
+
function resolveSessionBridgePayload(payload) {
|
|
9203
|
+
const token = payload?.session?.token ?? payload?.token;
|
|
9204
|
+
if (typeof token !== "string") {
|
|
9205
|
+
return null;
|
|
9206
|
+
}
|
|
9207
|
+
const normalizedToken = token.trim();
|
|
9208
|
+
if (!normalizedToken) {
|
|
9209
|
+
return null;
|
|
9210
|
+
}
|
|
9211
|
+
return {
|
|
9212
|
+
token: normalizedToken,
|
|
9213
|
+
expiresAt: typeof payload?.session?.expiresAt === "string" ? payload.session.expiresAt : void 0
|
|
9214
|
+
};
|
|
9215
|
+
}
|
|
9216
|
+
|
|
9217
|
+
// src/utils/hostname.ts
|
|
9218
|
+
var LOCAL_IPV4_PATTERN = /^127(?:\.\d{1,3}){3}$/;
|
|
9219
|
+
function isLocalHostname(hostname) {
|
|
9220
|
+
const normalized = hostname.trim().replace(/\.$/, "").toLowerCase();
|
|
9221
|
+
if (!normalized) {
|
|
9222
|
+
return false;
|
|
9223
|
+
}
|
|
9224
|
+
if (normalized === "localhost" || normalized.endsWith(".localhost")) {
|
|
9225
|
+
return true;
|
|
9226
|
+
}
|
|
9227
|
+
if (normalized === "127.0.0.1" || LOCAL_IPV4_PATTERN.test(normalized) || normalized === "::1" || normalized === "[::1]" || normalized === "0:0:0:0:0:0:0:1") {
|
|
9228
|
+
return true;
|
|
9229
|
+
}
|
|
9230
|
+
return false;
|
|
9231
|
+
}
|
|
9232
|
+
|
|
9233
|
+
// src/utils/auth-cookies.ts
|
|
9234
|
+
var ATHENA_AUTH_COOKIE_PREFIXES = [
|
|
9235
|
+
"athena-auth",
|
|
9236
|
+
"__Secure-athena-auth",
|
|
9237
|
+
"better-auth",
|
|
9238
|
+
"__Secure-better-auth"
|
|
9239
|
+
];
|
|
9240
|
+
function extractCookieNames(cookieHeader) {
|
|
9241
|
+
const names = /* @__PURE__ */ new Set();
|
|
9242
|
+
for (const rawCookie of cookieHeader.split(";")) {
|
|
9243
|
+
const trimmed = rawCookie.trim();
|
|
9244
|
+
if (!trimmed) continue;
|
|
9245
|
+
const eqPos = trimmed.indexOf("=");
|
|
9246
|
+
const name = (eqPos > -1 ? trimmed.slice(0, eqPos) : trimmed).trim();
|
|
9247
|
+
if (name) {
|
|
9248
|
+
names.add(name);
|
|
9249
|
+
}
|
|
9250
|
+
}
|
|
9251
|
+
return Array.from(names);
|
|
9252
|
+
}
|
|
9253
|
+
function buildCookieDomainCandidates(hostname) {
|
|
9254
|
+
const normalized = hostname.trim().replace(/\.$/, "").toLowerCase();
|
|
9255
|
+
if (!normalized || isLocalHostname(normalized)) {
|
|
9256
|
+
return [];
|
|
9257
|
+
}
|
|
9258
|
+
const labels = normalized.split(".").filter(Boolean);
|
|
9259
|
+
if (labels.length < 2) {
|
|
9260
|
+
return [normalized, `.${normalized}`];
|
|
9261
|
+
}
|
|
9262
|
+
const domains = /* @__PURE__ */ new Set();
|
|
9263
|
+
for (let index = 0; index <= labels.length - 2; index += 1) {
|
|
9264
|
+
const domain = labels.slice(index).join(".");
|
|
9265
|
+
domains.add(domain);
|
|
9266
|
+
domains.add(`.${domain}`);
|
|
9267
|
+
}
|
|
9268
|
+
return Array.from(domains);
|
|
9269
|
+
}
|
|
9270
|
+
function getCookieStore() {
|
|
9271
|
+
const candidate = globalThis.document;
|
|
9272
|
+
if (!candidate || typeof candidate.cookie !== "string") {
|
|
9273
|
+
return null;
|
|
9274
|
+
}
|
|
9275
|
+
return candidate;
|
|
9276
|
+
}
|
|
9277
|
+
function getRuntimeHostname() {
|
|
9278
|
+
const fromWindow = globalThis.window?.location?.hostname;
|
|
9279
|
+
if (typeof fromWindow === "string") {
|
|
9280
|
+
return fromWindow;
|
|
9281
|
+
}
|
|
9282
|
+
const fromLocation = globalThis.location?.hostname;
|
|
9283
|
+
if (typeof fromLocation === "string") {
|
|
9284
|
+
return fromLocation;
|
|
9285
|
+
}
|
|
9286
|
+
return "";
|
|
9287
|
+
}
|
|
9288
|
+
function writeExpiredCookie(cookieStore, name, path, domain) {
|
|
9289
|
+
const domainClause = domain ? ` domain=${domain};` : "";
|
|
9290
|
+
cookieStore.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; path=${path};${domainClause}`;
|
|
9291
|
+
}
|
|
9292
|
+
function clearAuthCookies(options = {}) {
|
|
9293
|
+
const cookieStore = getCookieStore();
|
|
9294
|
+
if (!cookieStore) {
|
|
9295
|
+
return [];
|
|
9296
|
+
}
|
|
9297
|
+
const cookieHeader = options.cookieHeader ?? cookieStore.cookie;
|
|
9298
|
+
if (!cookieHeader?.trim()) {
|
|
9299
|
+
return [];
|
|
9300
|
+
}
|
|
9301
|
+
const prefixes = options.prefixes?.length ? options.prefixes : [...ATHENA_AUTH_COOKIE_PREFIXES];
|
|
9302
|
+
const cookieNames = extractCookieNames(cookieHeader);
|
|
9303
|
+
const namesToClear = cookieNames.filter(
|
|
9304
|
+
(name) => prefixes.some((prefix) => name.startsWith(prefix))
|
|
9305
|
+
);
|
|
9306
|
+
if (namesToClear.length === 0) {
|
|
9307
|
+
return [];
|
|
9308
|
+
}
|
|
9309
|
+
const path = options.path?.trim() || "/";
|
|
9310
|
+
const hostname = options.hostname ?? getRuntimeHostname();
|
|
9311
|
+
const domainCandidates = buildCookieDomainCandidates(hostname);
|
|
9312
|
+
for (const name of namesToClear) {
|
|
9313
|
+
writeExpiredCookie(cookieStore, name, path);
|
|
9314
|
+
for (const domain of domainCandidates) {
|
|
9315
|
+
writeExpiredCookie(cookieStore, name, path, domain);
|
|
9316
|
+
}
|
|
9317
|
+
}
|
|
9318
|
+
return namesToClear;
|
|
9319
|
+
}
|
|
9320
|
+
|
|
9321
|
+
// src/utils/auth-routes.ts
|
|
9322
|
+
var AUTH_DEFAULT_VIEW = "sign-in";
|
|
9323
|
+
var AUTH_VIEW_BY_SEGMENT = {
|
|
9324
|
+
"accept-invitation": "accept-invitation",
|
|
9325
|
+
"check-email": "check-email",
|
|
9326
|
+
"forget-password": "forgot-password",
|
|
9327
|
+
"forgot-password": "forgot-password",
|
|
9328
|
+
logout: "logout",
|
|
9329
|
+
"reset-email-sent": "reset-email-sent",
|
|
9330
|
+
"reset-password": "reset-password",
|
|
9331
|
+
"sign-in": "sign-in",
|
|
9332
|
+
"sign-up": "sign-up"
|
|
9333
|
+
};
|
|
9334
|
+
var AUTHENTICATED_REDIRECT_VIEW_SET = /* @__PURE__ */ new Set([
|
|
9335
|
+
"sign-in",
|
|
9336
|
+
"sign-up",
|
|
9337
|
+
"forgot-password"
|
|
9338
|
+
]);
|
|
9339
|
+
function resolveAuthViewFromSegment(segment) {
|
|
9340
|
+
if (!segment) {
|
|
9341
|
+
return AUTH_DEFAULT_VIEW;
|
|
9342
|
+
}
|
|
9343
|
+
return AUTH_VIEW_BY_SEGMENT[segment] ?? null;
|
|
9344
|
+
}
|
|
9345
|
+
function shouldRedirectAuthenticatedAuthView(view) {
|
|
9346
|
+
return AUTHENTICATED_REDIRECT_VIEW_SET.has(view);
|
|
9347
|
+
}
|
|
9348
|
+
var AUTH_ROUTES = {
|
|
9349
|
+
acceptInvitation: "/auth/accept-invitation",
|
|
9350
|
+
appHome: "/",
|
|
9351
|
+
checkEmail: "/auth/check-email",
|
|
9352
|
+
forgotPassword: "/auth/forgot-password",
|
|
9353
|
+
logout: "/auth/logout",
|
|
9354
|
+
resetEmailSent: "/auth/reset-email-sent",
|
|
9355
|
+
resetPassword: "/auth/reset-password",
|
|
9356
|
+
signIn: "/auth/sign-in",
|
|
9357
|
+
signUp: "/auth/sign-up",
|
|
9358
|
+
socialCallback: "/auth/social-callback"
|
|
9359
|
+
};
|
|
9360
|
+
function createAuthModeRedirects(routes = AUTH_ROUTES) {
|
|
9361
|
+
return {
|
|
9362
|
+
"forgot-password": routes.forgotPassword,
|
|
9363
|
+
login: routes.signIn,
|
|
9364
|
+
logout: routes.logout,
|
|
9365
|
+
"reset-password": routes.resetPassword,
|
|
9366
|
+
signup: routes.signUp
|
|
9367
|
+
};
|
|
9368
|
+
}
|
|
9369
|
+
var AUTH_MODE_REDIRECTS = createAuthModeRedirects();
|
|
9370
|
+
new Set(Object.keys(AUTH_MODE_REDIRECTS));
|
|
9371
|
+
|
|
9372
|
+
// src/utils/athena-auth-url.ts
|
|
9373
|
+
var ATHENA_AUTH_PATH = "/api/auth";
|
|
9374
|
+
var LOCAL_DEV_ORIGIN = "http://localhost:3000";
|
|
9375
|
+
var DEFAULT_ATHENA_AUTH_ORIGIN = "https://auth.athena-auth.com";
|
|
9376
|
+
var ATHENA_AUTH_UPSTREAM_ENV_KEYS = [
|
|
9377
|
+
"ATHENA_AUTH_UPSTREAM_URL",
|
|
9378
|
+
"ATHENA_AUTH_URL",
|
|
9379
|
+
"NEXT_PUBLIC_ATHENA_AUTH_UPSTREAM_URL",
|
|
9380
|
+
"NEXT_PUBLIC_ATHENA_AUTH_URL"
|
|
9381
|
+
];
|
|
9382
|
+
var ATHENA_AUTH_UPSTREAM_URL_ENV_NAMES = ATHENA_AUTH_UPSTREAM_ENV_KEYS;
|
|
9383
|
+
var LEADING_SLASHES_REGEX = /^\/+/;
|
|
9384
|
+
function stripTrailingSlashes(value) {
|
|
9385
|
+
return value.replace(/\/+$/g, "");
|
|
9386
|
+
}
|
|
9387
|
+
function ensureLeadingSlash(value) {
|
|
9388
|
+
return value.startsWith("/") ? value : `/${value}`;
|
|
9389
|
+
}
|
|
9390
|
+
function ensureAthenaAuthPath(pathname) {
|
|
9391
|
+
const normalizedPath = stripTrailingSlashes(
|
|
9392
|
+
ensureLeadingSlash(pathname.trim())
|
|
9393
|
+
);
|
|
9394
|
+
if (!normalizedPath || normalizedPath === "/") {
|
|
9395
|
+
return ATHENA_AUTH_PATH;
|
|
9396
|
+
}
|
|
9397
|
+
if (normalizedPath.endsWith(ATHENA_AUTH_PATH)) {
|
|
9398
|
+
return normalizedPath;
|
|
9399
|
+
}
|
|
9400
|
+
return `${normalizedPath}${ATHENA_AUTH_PATH}`;
|
|
9401
|
+
}
|
|
9402
|
+
function stripAthenaAuthPath(pathname) {
|
|
9403
|
+
const normalizedPath = stripTrailingSlashes(
|
|
9404
|
+
ensureLeadingSlash(pathname.trim())
|
|
9405
|
+
);
|
|
9406
|
+
if (!normalizedPath || normalizedPath === "/") {
|
|
9407
|
+
return "/";
|
|
9408
|
+
}
|
|
9409
|
+
if (normalizedPath === ATHENA_AUTH_PATH) {
|
|
9410
|
+
return "/";
|
|
9411
|
+
}
|
|
9412
|
+
if (normalizedPath.endsWith(ATHENA_AUTH_PATH)) {
|
|
9413
|
+
const withoutAuthPath = normalizedPath.slice(0, -ATHENA_AUTH_PATH.length);
|
|
9414
|
+
return withoutAuthPath ? ensureLeadingSlash(withoutAuthPath) : "/";
|
|
9415
|
+
}
|
|
9416
|
+
return normalizedPath;
|
|
9417
|
+
}
|
|
9418
|
+
function readProcessEnv2() {
|
|
9419
|
+
try {
|
|
9420
|
+
const maybeProcess = globalThis.process;
|
|
9421
|
+
return maybeProcess?.env;
|
|
9422
|
+
} catch {
|
|
9423
|
+
return void 0;
|
|
9424
|
+
}
|
|
9425
|
+
}
|
|
9426
|
+
function getBrowserOrigin() {
|
|
9427
|
+
try {
|
|
9428
|
+
const origin = globalThis.window?.location?.origin;
|
|
9429
|
+
return typeof origin === "string" && origin.length > 0 ? origin : void 0;
|
|
9430
|
+
} catch {
|
|
9431
|
+
return void 0;
|
|
9432
|
+
}
|
|
9433
|
+
}
|
|
9434
|
+
function isAbsoluteUrl(value) {
|
|
9435
|
+
const trimmed = value.trim();
|
|
9436
|
+
return trimmed.startsWith("http://") || trimmed.startsWith("https://");
|
|
9437
|
+
}
|
|
9438
|
+
function readAthenaAuthUpstreamUrlFromEnv(env) {
|
|
9439
|
+
for (const key of ATHENA_AUTH_UPSTREAM_ENV_KEYS) {
|
|
9440
|
+
const value = env[key]?.trim();
|
|
9441
|
+
if (value) {
|
|
9442
|
+
return value;
|
|
9443
|
+
}
|
|
9444
|
+
}
|
|
9445
|
+
return void 0;
|
|
9446
|
+
}
|
|
9447
|
+
function resolveConfiguredAthenaAuthUpstreamUrl(rawUpstreamUrl) {
|
|
9448
|
+
if (typeof rawUpstreamUrl === "string") {
|
|
9449
|
+
const trimmed = rawUpstreamUrl.trim();
|
|
9450
|
+
return trimmed || void 0;
|
|
9451
|
+
}
|
|
9452
|
+
if (rawUpstreamUrl) {
|
|
9453
|
+
return readAthenaAuthUpstreamUrlFromEnv(rawUpstreamUrl);
|
|
9454
|
+
}
|
|
9455
|
+
const processEnv = readProcessEnv2();
|
|
9456
|
+
return processEnv ? readAthenaAuthUpstreamUrlFromEnv(processEnv) : void 0;
|
|
9457
|
+
}
|
|
9458
|
+
function normalizeAthenaAuthBaseUrl(urlOrPath) {
|
|
9459
|
+
const trimmed = urlOrPath.trim();
|
|
9460
|
+
if (!trimmed) {
|
|
9461
|
+
return ATHENA_AUTH_PATH;
|
|
9462
|
+
}
|
|
9463
|
+
if (isAbsoluteUrl(trimmed)) {
|
|
9464
|
+
const url = new URL(trimmed);
|
|
9465
|
+
url.pathname = ensureAthenaAuthPath(url.pathname);
|
|
9466
|
+
url.search = "";
|
|
9467
|
+
url.hash = "";
|
|
9468
|
+
return stripTrailingSlashes(url.toString());
|
|
9469
|
+
}
|
|
9470
|
+
return ensureAthenaAuthPath(trimmed);
|
|
9471
|
+
}
|
|
9472
|
+
function resolveAthenaAuthUpstreamUrl(rawUpstreamUrl) {
|
|
9473
|
+
const configuredUpstream = resolveConfiguredAthenaAuthUpstreamUrl(rawUpstreamUrl) || DEFAULT_ATHENA_AUTH_ORIGIN;
|
|
9474
|
+
if (isAbsoluteUrl(configuredUpstream)) {
|
|
9475
|
+
const upstreamUrl = new URL(configuredUpstream);
|
|
9476
|
+
upstreamUrl.pathname = stripAthenaAuthPath(upstreamUrl.pathname);
|
|
9477
|
+
upstreamUrl.search = "";
|
|
9478
|
+
upstreamUrl.hash = "";
|
|
9479
|
+
return stripTrailingSlashes(upstreamUrl.toString());
|
|
9480
|
+
}
|
|
9481
|
+
const normalizedPath = stripAthenaAuthPath(configuredUpstream);
|
|
9482
|
+
return stripTrailingSlashes(
|
|
9483
|
+
new URL(normalizedPath, LOCAL_DEV_ORIGIN).toString()
|
|
9484
|
+
);
|
|
9485
|
+
}
|
|
9486
|
+
function resolveBrowserFacingOrigin(rawUpstreamUrl) {
|
|
9487
|
+
if (resolveConfiguredAthenaAuthUpstreamUrl(rawUpstreamUrl)) {
|
|
9488
|
+
return `${resolveAthenaAuthUpstreamUrl(rawUpstreamUrl)}/`;
|
|
9489
|
+
}
|
|
9490
|
+
const browserOrigin = getBrowserOrigin();
|
|
9491
|
+
if (browserOrigin) {
|
|
9492
|
+
return `${browserOrigin}/`;
|
|
9493
|
+
}
|
|
9494
|
+
return `${LOCAL_DEV_ORIGIN}/`;
|
|
9495
|
+
}
|
|
9496
|
+
function resolvePreservedAthenaAuthBaseUrl(configuredAuthBaseUrl, rawUpstreamUrl) {
|
|
9497
|
+
const trimmed = configuredAuthBaseUrl.trim();
|
|
9498
|
+
const preservedConfiguredBaseUrl = trimmed || ATHENA_AUTH_PATH;
|
|
9499
|
+
if (isAbsoluteUrl(preservedConfiguredBaseUrl)) {
|
|
9500
|
+
return stripTrailingSlashes(preservedConfiguredBaseUrl);
|
|
9501
|
+
}
|
|
9502
|
+
return stripTrailingSlashes(
|
|
9503
|
+
new URL(
|
|
9504
|
+
ensureLeadingSlash(preservedConfiguredBaseUrl),
|
|
9505
|
+
resolveBrowserFacingOrigin(rawUpstreamUrl)
|
|
9506
|
+
).toString()
|
|
9507
|
+
);
|
|
9508
|
+
}
|
|
9509
|
+
function resolveAthenaAuthClientBaseUrl(configuredAuthBaseUrl, rawUpstreamUrl, options = {}) {
|
|
9510
|
+
let baseInput;
|
|
9511
|
+
if (typeof configuredAuthBaseUrl === "string") {
|
|
9512
|
+
baseInput = configuredAuthBaseUrl;
|
|
9513
|
+
} else if (configuredAuthBaseUrl) {
|
|
9514
|
+
baseInput = readAthenaAuthUpstreamUrlFromEnv(configuredAuthBaseUrl) ?? ATHENA_AUTH_PATH;
|
|
9515
|
+
} else {
|
|
9516
|
+
const fromEnv = resolveConfiguredAthenaAuthUpstreamUrl(rawUpstreamUrl);
|
|
9517
|
+
baseInput = fromEnv ?? ATHENA_AUTH_PATH;
|
|
9518
|
+
}
|
|
9519
|
+
if (options.appendAuthPath === false) {
|
|
9520
|
+
return resolvePreservedAthenaAuthBaseUrl(baseInput, rawUpstreamUrl);
|
|
9521
|
+
}
|
|
9522
|
+
const normalizedConfiguredBaseUrl = normalizeAthenaAuthBaseUrl(baseInput);
|
|
9523
|
+
if (isAbsoluteUrl(normalizedConfiguredBaseUrl)) {
|
|
9524
|
+
return normalizedConfiguredBaseUrl;
|
|
9525
|
+
}
|
|
9526
|
+
const browserOrigin = getBrowserOrigin();
|
|
9527
|
+
if (browserOrigin) {
|
|
9528
|
+
return stripTrailingSlashes(
|
|
9529
|
+
new URL(normalizedConfiguredBaseUrl, browserOrigin).toString()
|
|
9530
|
+
);
|
|
9531
|
+
}
|
|
9532
|
+
if (resolveConfiguredAthenaAuthUpstreamUrl(rawUpstreamUrl)) {
|
|
9533
|
+
const upstream = resolveAthenaAuthUpstreamUrl(rawUpstreamUrl);
|
|
9534
|
+
return stripTrailingSlashes(
|
|
9535
|
+
new URL(ATHENA_AUTH_PATH, `${upstream}/`).toString()
|
|
9536
|
+
);
|
|
9537
|
+
}
|
|
9538
|
+
return stripTrailingSlashes(
|
|
9539
|
+
new URL(normalizedConfiguredBaseUrl, LOCAL_DEV_ORIGIN).toString()
|
|
9540
|
+
);
|
|
9541
|
+
}
|
|
9542
|
+
function resolveAthenaAuthRequestUrl(path, rawBaseUrl) {
|
|
9543
|
+
const normalizedPath = path.replace(LEADING_SLASHES_REGEX, "");
|
|
9544
|
+
const base = resolveAthenaAuthClientBaseUrl(rawBaseUrl);
|
|
9545
|
+
return new URL(normalizedPath, `${base}/`).toString();
|
|
9546
|
+
}
|
|
9547
|
+
var ATHENA_AUTH_VERIFY_EMAIL_PATH = "verify-email";
|
|
9548
|
+
function resolveEmailVerificationCallbackUrl(rawBaseUrl) {
|
|
9549
|
+
return resolveAthenaAuthRequestUrl(ATHENA_AUTH_VERIFY_EMAIL_PATH, rawBaseUrl);
|
|
9550
|
+
}
|
|
9551
|
+
|
|
8672
9552
|
// src/next/client.ts
|
|
8673
9553
|
var cachedBrowserClient = null;
|
|
8674
9554
|
function createAthenaBrowserClient(options) {
|
|
@@ -8682,6 +9562,29 @@ function createAthenaBrowserClient(options) {
|
|
|
8682
9562
|
return createAdapterClient(options);
|
|
8683
9563
|
}
|
|
8684
9564
|
|
|
9565
|
+
exports.ATHENA_AUTH_COOKIE_PREFIXES = ATHENA_AUTH_COOKIE_PREFIXES;
|
|
9566
|
+
exports.ATHENA_AUTH_PATH = ATHENA_AUTH_PATH;
|
|
9567
|
+
exports.ATHENA_AUTH_SESSION_BRIDGE_ROUTE = ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
|
|
9568
|
+
exports.ATHENA_AUTH_SESSION_COOKIE_NAME = ATHENA_AUTH_SESSION_COOKIE_NAME;
|
|
9569
|
+
exports.ATHENA_AUTH_SESSION_COOKIE_NAMES = ATHENA_AUTH_SESSION_COOKIE_NAMES;
|
|
9570
|
+
exports.ATHENA_AUTH_UPSTREAM_ENV_KEYS = ATHENA_AUTH_UPSTREAM_ENV_KEYS;
|
|
9571
|
+
exports.ATHENA_AUTH_UPSTREAM_URL_ENV_NAMES = ATHENA_AUTH_UPSTREAM_URL_ENV_NAMES;
|
|
9572
|
+
exports.AUTH_DEFAULT_VIEW = AUTH_DEFAULT_VIEW;
|
|
9573
|
+
exports.AUTH_ROUTES = AUTH_ROUTES;
|
|
9574
|
+
exports.AUTH_VIEW_BY_SEGMENT = AUTH_VIEW_BY_SEGMENT;
|
|
9575
|
+
exports.DEFAULT_ATHENA_AUTH_ORIGIN = DEFAULT_ATHENA_AUTH_ORIGIN;
|
|
9576
|
+
exports.clearAthenaAuthSessionOnAppHost = clearAthenaAuthSessionOnAppHost;
|
|
9577
|
+
exports.clearAuthCookies = clearAuthCookies;
|
|
8685
9578
|
exports.createAthenaBrowserClient = createAthenaBrowserClient;
|
|
9579
|
+
exports.isAbsoluteUrl = isAbsoluteUrl;
|
|
9580
|
+
exports.normalizeAthenaAuthBaseUrl = normalizeAthenaAuthBaseUrl;
|
|
9581
|
+
exports.persistAthenaAuthSessionOnAppHost = persistAthenaAuthSessionOnAppHost;
|
|
9582
|
+
exports.resolveAthenaAuthClientBaseUrl = resolveAthenaAuthClientBaseUrl;
|
|
9583
|
+
exports.resolveAthenaAuthRequestUrl = resolveAthenaAuthRequestUrl;
|
|
9584
|
+
exports.resolveAthenaAuthUpstreamUrl = resolveAthenaAuthUpstreamUrl;
|
|
9585
|
+
exports.resolveAuthViewFromSegment = resolveAuthViewFromSegment;
|
|
9586
|
+
exports.resolveEmailVerificationCallbackUrl = resolveEmailVerificationCallbackUrl;
|
|
9587
|
+
exports.resolveSessionBridgePayload = resolveSessionBridgePayload;
|
|
9588
|
+
exports.shouldRedirectAuthenticatedAuthView = shouldRedirectAuthenticatedAuthView;
|
|
8686
9589
|
//# sourceMappingURL=client.cjs.map
|
|
8687
9590
|
//# sourceMappingURL=client.cjs.map
|