@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/server.cjs
CHANGED
|
@@ -138,6 +138,22 @@ function parseCookies(cookieHeader) {
|
|
|
138
138
|
});
|
|
139
139
|
return cookieMap;
|
|
140
140
|
}
|
|
141
|
+
|
|
142
|
+
// src/cookies/session-cookie-detection.ts
|
|
143
|
+
var SESSION_COOKIE_PATTERNS = [
|
|
144
|
+
/(?:^|;\s*)(?:__Secure-)?better-auth\.session_token=/,
|
|
145
|
+
/(?:^|;\s*)(?:__Secure-)?better-auth-session_token=/,
|
|
146
|
+
/(?:^|;\s*)(?:__Secure-)?athena-auth\.session-token=/,
|
|
147
|
+
/(?:^|;\s*)(?:__Secure-)?athena-auth-session-token=/,
|
|
148
|
+
/(?:^|;\s*)(?:__Secure-)?athena-auth\.session_token=/,
|
|
149
|
+
/(?:^|;\s*)(?:__Secure-)?athena-auth-session_token=/
|
|
150
|
+
];
|
|
151
|
+
function hasAuthSessionCookie(cookieHeader) {
|
|
152
|
+
if (!cookieHeader) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return SESSION_COOKIE_PATTERNS.some((pattern) => pattern.test(cookieHeader));
|
|
156
|
+
}
|
|
141
157
|
var getSessionCookie = (request2, config) => {
|
|
142
158
|
const cookies = (request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers).get("cookie");
|
|
143
159
|
if (!cookies) {
|
|
@@ -162,7 +178,7 @@ var getSessionCookie = (request2, config) => {
|
|
|
162
178
|
|
|
163
179
|
// src/utils/athena-request-headers.ts
|
|
164
180
|
var NO_CACHE_HEADER_VALUE = "no-cache";
|
|
165
|
-
var API_KEY_HEADER_CANDIDATES = ["X-Api-Key", "x-api-key", "apikey"];
|
|
181
|
+
var API_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key", "X-Api-Key", "x-api-key", "apikey"];
|
|
166
182
|
var ATHENA_KEY_HEADER_CANDIDATES = ["X-Athena-Key", "x-athena-key"];
|
|
167
183
|
var SESSION_TOKEN_HEADER_CANDIDATES = ["X-Athena-Auth-Session-Token"];
|
|
168
184
|
var BEARER_MIRROR_HEADER_CANDIDATES = ["X-Athena-Auth-Bearer-Token"];
|
|
@@ -264,17 +280,6 @@ function buildServiceRequestHeaders(profile, sdkHeaderValue, config, options, ex
|
|
|
264
280
|
});
|
|
265
281
|
}
|
|
266
282
|
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
283
|
const resolvedAthenaKey = normalizeHeaderValue(athenaKey) ?? normalizeHeaderValue(apiKey);
|
|
279
284
|
if (resolvedAthenaKey && !hasHeaderIgnoreCase(headers, "X-Athena-Key")) {
|
|
280
285
|
headers["X-Athena-Key"] = resolvedAthenaKey;
|
|
@@ -400,7 +405,7 @@ function buildAthenaRequestHeaders(input) {
|
|
|
400
405
|
|
|
401
406
|
// package.json
|
|
402
407
|
var package_default = {
|
|
403
|
-
version: "2.
|
|
408
|
+
version: "2.14.0"
|
|
404
409
|
};
|
|
405
410
|
|
|
406
411
|
// src/sdk-version.ts
|
|
@@ -2829,39 +2834,224 @@ async function withRetry(config, fn) {
|
|
|
2829
2834
|
throw new Error("withRetry reached an unexpected state");
|
|
2830
2835
|
}
|
|
2831
2836
|
|
|
2832
|
-
// src/
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2837
|
+
// src/storage/direct-upload.ts
|
|
2838
|
+
var SERVICE = "s3";
|
|
2839
|
+
var TERMINATOR = "aws4_request";
|
|
2840
|
+
async function putDirectStorageUploadBody(config, bucket, storageKey, body, uploadHeaders, signal, onProgress) {
|
|
2841
|
+
if (config.bucket && bucket && config.bucket !== bucket) {
|
|
2842
|
+
throw new Error(
|
|
2843
|
+
`athena.storage.file.upload direct mode bucket mismatch: configured ${config.bucket} but Athena returned ${bucket}`
|
|
2844
|
+
);
|
|
2845
|
+
}
|
|
2846
|
+
const target = createDirectUploadTarget(config, bucket, storageKey);
|
|
2847
|
+
const bytes = await bodyToArrayBuffer(body);
|
|
2848
|
+
const payloadHash = await sha256Hex(bytes);
|
|
2849
|
+
const headers = new Headers(uploadHeaders);
|
|
2850
|
+
if (isBlobBody(body) && body.type && !headers.has("Content-Type")) {
|
|
2851
|
+
headers.set("Content-Type", body.type);
|
|
2852
|
+
}
|
|
2853
|
+
const signed = await signDirectUploadRequest(config, target, headers, payloadHash);
|
|
2854
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
2855
|
+
return putWithXhr(target.toString(), signed, body, signal, onProgress);
|
|
2856
|
+
}
|
|
2857
|
+
onProgress({ loaded: 0 });
|
|
2858
|
+
const response = await fetch(target, {
|
|
2859
|
+
method: "PUT",
|
|
2860
|
+
headers: signed.requestHeaders,
|
|
2861
|
+
body,
|
|
2862
|
+
signal
|
|
2863
|
+
});
|
|
2864
|
+
if (!response.ok) {
|
|
2865
|
+
throw new Error(`athena.storage.file.upload failed with status ${response.status}`);
|
|
2866
|
+
}
|
|
2867
|
+
onProgress({ loaded: bytes.byteLength });
|
|
2868
|
+
return response;
|
|
2869
|
+
}
|
|
2870
|
+
function createDirectUploadTarget(config, bucket, storageKey) {
|
|
2871
|
+
const resolvedBucket = config.bucket ?? bucket;
|
|
2872
|
+
if (!resolvedBucket?.trim()) {
|
|
2873
|
+
throw new Error(
|
|
2874
|
+
"athena.storage.file.upload direct mode requires a bucket in experimental.directStorageUpload or the server upload response"
|
|
2875
|
+
);
|
|
2876
|
+
}
|
|
2877
|
+
if (!storageKey.trim()) {
|
|
2878
|
+
throw new Error("athena.storage.file.upload direct mode requires a storage key");
|
|
2879
|
+
}
|
|
2880
|
+
let endpoint;
|
|
2881
|
+
try {
|
|
2882
|
+
endpoint = new URL(config.endpoint);
|
|
2883
|
+
} catch (error) {
|
|
2884
|
+
throw new Error(
|
|
2885
|
+
`athena.storage.file.upload direct mode received an invalid endpoint: ${error instanceof Error ? error.message : String(error)}`
|
|
2886
|
+
);
|
|
2887
|
+
}
|
|
2888
|
+
if (endpoint.search || endpoint.hash) {
|
|
2889
|
+
throw new Error("athena.storage.file.upload direct mode endpoint must not contain a query or hash");
|
|
2890
|
+
}
|
|
2891
|
+
const endpointPath = endpoint.pathname.replace(/\/+$/, "");
|
|
2892
|
+
const pathParts = config.forcePathStyle === false ? [endpointPath, storageKey] : [endpointPath, resolvedBucket, storageKey];
|
|
2893
|
+
if (config.forcePathStyle === false) {
|
|
2894
|
+
endpoint.hostname = `${resolvedBucket}.${endpoint.hostname}`;
|
|
2895
|
+
}
|
|
2896
|
+
endpoint.pathname = pathParts.filter(Boolean).flatMap((part) => part.split("/")).map(awsEncode).join("/").replace(/^([^/])/, "/$1");
|
|
2897
|
+
return endpoint;
|
|
2898
|
+
}
|
|
2899
|
+
async function signDirectUploadRequest(config, target, inputHeaders, payloadHash) {
|
|
2900
|
+
const accessKeyId = config.accessKeyId.trim();
|
|
2901
|
+
const secretAccessKey = config.secretAccessKey.trim();
|
|
2902
|
+
if (!accessKeyId || !secretAccessKey) {
|
|
2903
|
+
throw new Error(
|
|
2904
|
+
"athena.storage.file.upload direct mode requires accessKeyId and secretAccessKey"
|
|
2905
|
+
);
|
|
2906
|
+
}
|
|
2907
|
+
const now = /* @__PURE__ */ new Date();
|
|
2908
|
+
const amzDate = formatAmzDate(now);
|
|
2909
|
+
const shortDate = amzDate.slice(0, 8);
|
|
2910
|
+
const region = config.region?.trim() || "auto";
|
|
2911
|
+
const headers = {};
|
|
2912
|
+
inputHeaders.forEach((value, key) => {
|
|
2913
|
+
if (key.toLowerCase() !== "authorization" && key.toLowerCase() !== "host") {
|
|
2914
|
+
headers[key.toLowerCase()] = value.trim().replace(/\s+/g, " ");
|
|
2915
|
+
}
|
|
2916
|
+
});
|
|
2917
|
+
headers["x-amz-content-sha256"] = payloadHash;
|
|
2918
|
+
headers["x-amz-date"] = amzDate;
|
|
2919
|
+
if (config.sessionToken?.trim()) {
|
|
2920
|
+
headers["x-amz-security-token"] = config.sessionToken.trim();
|
|
2921
|
+
}
|
|
2922
|
+
const canonicalHeaders = Object.keys(headers).sort().map((key) => `${key}:${headers[key]}
|
|
2923
|
+
`).join("");
|
|
2924
|
+
const signedHeaders = Object.keys(headers).sort().join(";");
|
|
2925
|
+
const canonicalRequest = [
|
|
2926
|
+
"PUT",
|
|
2927
|
+
target.pathname,
|
|
2928
|
+
"",
|
|
2929
|
+
`host:${target.host}
|
|
2930
|
+
${canonicalHeaders}`,
|
|
2931
|
+
`host;${signedHeaders}`,
|
|
2932
|
+
payloadHash
|
|
2933
|
+
].join("\n");
|
|
2934
|
+
const credentialScope = `${shortDate}/${region}/${SERVICE}/${TERMINATOR}`;
|
|
2935
|
+
const stringToSign = [
|
|
2936
|
+
"AWS4-HMAC-SHA256",
|
|
2937
|
+
amzDate,
|
|
2938
|
+
credentialScope,
|
|
2939
|
+
await sha256Hex(canonicalRequest)
|
|
2940
|
+
].join("\n");
|
|
2941
|
+
const dateKey = await hmac(`AWS4${secretAccessKey}`, shortDate);
|
|
2942
|
+
const regionKey = await hmac(dateKey, region);
|
|
2943
|
+
const serviceKey = await hmac(regionKey, SERVICE);
|
|
2944
|
+
const signingKey = await hmac(serviceKey, TERMINATOR);
|
|
2945
|
+
const signature = await hmacHex(signingKey, stringToSign);
|
|
2946
|
+
headers.authorization = `AWS4-HMAC-SHA256 Credential=${accessKeyId}/${credentialScope}, SignedHeaders=host;${signedHeaders}, Signature=${signature}`;
|
|
2947
|
+
return { requestHeaders: headers };
|
|
2948
|
+
}
|
|
2949
|
+
async function putWithXhr(url, signed, body, signal, onProgress) {
|
|
2950
|
+
const Xhr = XMLHttpRequest;
|
|
2951
|
+
if (Xhr === void 0) {
|
|
2952
|
+
return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
|
|
2953
|
+
}
|
|
2954
|
+
return new Promise((resolve, reject) => {
|
|
2955
|
+
const xhr = new Xhr();
|
|
2956
|
+
const abort = () => xhr.abort();
|
|
2957
|
+
xhr.open("PUT", url);
|
|
2958
|
+
Object.entries(signed.requestHeaders).forEach(([key, value]) => xhr.setRequestHeader(key, value));
|
|
2959
|
+
xhr.upload.onprogress = (event) => onProgress({ loaded: event.loaded });
|
|
2960
|
+
xhr.onload = () => {
|
|
2961
|
+
signal?.removeEventListener("abort", abort);
|
|
2962
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
2963
|
+
reject(new Error(`athena.storage.file.upload failed with status ${xhr.status}`));
|
|
2964
|
+
return;
|
|
2839
2965
|
}
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
}
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2966
|
+
onProgress({ loaded: bodySize(body) });
|
|
2967
|
+
resolve(new Response(xhr.response, {
|
|
2968
|
+
status: xhr.status,
|
|
2969
|
+
statusText: xhr.statusText,
|
|
2970
|
+
headers: parseXhrHeaders(xhr.getAllResponseHeaders())
|
|
2971
|
+
}));
|
|
2972
|
+
};
|
|
2973
|
+
xhr.onerror = () => {
|
|
2974
|
+
signal?.removeEventListener("abort", abort);
|
|
2975
|
+
reject(new Error("athena.storage.file.upload failed with a network error"));
|
|
2976
|
+
};
|
|
2977
|
+
xhr.onabort = () => {
|
|
2978
|
+
signal?.removeEventListener("abort", abort);
|
|
2979
|
+
reject(new DOMException("Upload aborted", "AbortError"));
|
|
2980
|
+
};
|
|
2981
|
+
if (signal) {
|
|
2982
|
+
if (signal.aborted) {
|
|
2983
|
+
abort();
|
|
2984
|
+
return;
|
|
2985
|
+
}
|
|
2986
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
2859
2987
|
}
|
|
2860
|
-
|
|
2861
|
-
|
|
2988
|
+
xhr.send(body);
|
|
2989
|
+
});
|
|
2990
|
+
}
|
|
2991
|
+
function isBlobBody(body) {
|
|
2992
|
+
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
2993
|
+
}
|
|
2994
|
+
async function bodyToArrayBuffer(body) {
|
|
2995
|
+
if (isBlobBody(body)) return body.arrayBuffer();
|
|
2996
|
+
if (body instanceof ArrayBuffer) return body;
|
|
2997
|
+
if (ArrayBuffer.isView(body)) {
|
|
2998
|
+
return body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength);
|
|
2999
|
+
}
|
|
3000
|
+
throw new Error("athena.storage.file.upload direct mode does not support ReadableStream bodies");
|
|
3001
|
+
}
|
|
3002
|
+
function bodySize(body) {
|
|
3003
|
+
if (isBlobBody(body)) return body.size;
|
|
3004
|
+
if (body instanceof ArrayBuffer) return body.byteLength;
|
|
3005
|
+
if (ArrayBuffer.isView(body)) return body.byteLength;
|
|
3006
|
+
return 0;
|
|
3007
|
+
}
|
|
3008
|
+
function awsEncode(value) {
|
|
3009
|
+
return encodeURIComponent(value).replace(/[!'()*]/g, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
3010
|
+
}
|
|
3011
|
+
function formatAmzDate(date) {
|
|
3012
|
+
return date.toISOString().replace(/[:-]|\.\d{3}/g, "");
|
|
3013
|
+
}
|
|
3014
|
+
async function sha256Hex(value) {
|
|
3015
|
+
const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
|
|
3016
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
3017
|
+
return toHex(new Uint8Array(digest));
|
|
3018
|
+
}
|
|
3019
|
+
async function hmac(key, value) {
|
|
3020
|
+
const keyBytes = typeof key === "string" ? new TextEncoder().encode(key) : key;
|
|
3021
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
3022
|
+
"raw",
|
|
3023
|
+
keyBytes,
|
|
3024
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
3025
|
+
false,
|
|
3026
|
+
["sign"]
|
|
3027
|
+
);
|
|
3028
|
+
return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
|
|
3029
|
+
}
|
|
3030
|
+
async function hmacHex(key, value) {
|
|
3031
|
+
return toHex(new Uint8Array(await hmac(key, value)));
|
|
3032
|
+
}
|
|
3033
|
+
function toHex(bytes) {
|
|
3034
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
3035
|
+
}
|
|
3036
|
+
function parseXhrHeaders(rawHeaders) {
|
|
3037
|
+
const headers = new Headers();
|
|
3038
|
+
rawHeaders.trim().split(/[\r\n]+/).forEach((line) => {
|
|
3039
|
+
const separator = line.indexOf(":");
|
|
3040
|
+
if (separator > 0) {
|
|
3041
|
+
headers.set(line.slice(0, separator).trim(), line.slice(separator + 1).trim());
|
|
3042
|
+
}
|
|
3043
|
+
});
|
|
3044
|
+
return headers;
|
|
2862
3045
|
}
|
|
2863
3046
|
|
|
2864
3047
|
// src/storage/file.ts
|
|
3048
|
+
function mergeUploadHeaders(serverHeaders, inputHeaders) {
|
|
3049
|
+
const headers = { ...serverHeaders };
|
|
3050
|
+
new Headers(inputHeaders).forEach((value, key) => {
|
|
3051
|
+
headers[key] = value;
|
|
3052
|
+
});
|
|
3053
|
+
return headers;
|
|
3054
|
+
}
|
|
2865
3055
|
function createStorageFileModule(base, config = {}) {
|
|
2866
3056
|
const upload = async (input, options) => {
|
|
2867
3057
|
const sources = normalizeUploadSources(input);
|
|
@@ -2897,16 +3087,25 @@ function createStorageFileModule(base, config = {}) {
|
|
|
2897
3087
|
for (let index = 0; index < uploadRequests.length; index += 1) {
|
|
2898
3088
|
const request2 = uploadRequests[index];
|
|
2899
3089
|
const uploadUrl = uploadUrls[index];
|
|
2900
|
-
const
|
|
3090
|
+
const aggregateProgress = (progress) => {
|
|
3091
|
+
aggregateLoaded[index] = progress.loaded;
|
|
3092
|
+
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
3093
|
+
};
|
|
3094
|
+
const response = config.directUpload ? await putDirectStorageUploadBody(
|
|
3095
|
+
config.directUpload,
|
|
3096
|
+
uploadUrl.upload.bucket,
|
|
3097
|
+
uploadUrl.upload.storage_key,
|
|
3098
|
+
request2.source.source,
|
|
3099
|
+
mergeUploadHeaders(uploadUrl.upload.headers ?? {}, input.uploadHeaders),
|
|
3100
|
+
options?.signal,
|
|
3101
|
+
aggregateProgress
|
|
3102
|
+
) : await putUploadBody(
|
|
2901
3103
|
uploadUrl.upload.url,
|
|
2902
3104
|
uploadUrl.upload.headers ?? {},
|
|
2903
3105
|
request2.source,
|
|
2904
3106
|
input,
|
|
2905
3107
|
options,
|
|
2906
|
-
|
|
2907
|
-
aggregateLoaded[index] = progress.loaded;
|
|
2908
|
-
input.onProgress?.(createProgressSnapshot("uploading", sources, index, progress.loaded, sum(aggregateLoaded)));
|
|
2909
|
-
}
|
|
3108
|
+
aggregateProgress
|
|
2910
3109
|
);
|
|
2911
3110
|
uploaded.push({
|
|
2912
3111
|
file: uploadUrl.file,
|
|
@@ -3057,7 +3256,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
|
|
|
3057
3256
|
resolve(new Response(xhr.response, {
|
|
3058
3257
|
status: xhr.status,
|
|
3059
3258
|
statusText: xhr.statusText,
|
|
3060
|
-
headers:
|
|
3259
|
+
headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
|
|
3061
3260
|
}));
|
|
3062
3261
|
};
|
|
3063
3262
|
xhr.onerror = () => {
|
|
@@ -3195,7 +3394,7 @@ function createProgressSnapshot(phase, sources, fileIndex, loaded, aggregateLoad
|
|
|
3195
3394
|
function sum(values) {
|
|
3196
3395
|
return values.reduce((total, value) => total + value, 0);
|
|
3197
3396
|
}
|
|
3198
|
-
function
|
|
3397
|
+
function parseXhrHeaders2(raw) {
|
|
3199
3398
|
const headers = new Headers();
|
|
3200
3399
|
for (const line of raw.trim().split(/[\r\n]+/)) {
|
|
3201
3400
|
const index = line.indexOf(":");
|
|
@@ -3212,6 +3411,230 @@ function isRecord5(value) {
|
|
|
3212
3411
|
return Boolean(value) && typeof value === "object";
|
|
3213
3412
|
}
|
|
3214
3413
|
|
|
3414
|
+
// src/storage/backup.ts
|
|
3415
|
+
function backupError(message, status, endpoint, method, cause, raw) {
|
|
3416
|
+
const error = new Error(message);
|
|
3417
|
+
error.name = "AthenaStorageError";
|
|
3418
|
+
error.code = status === 0 ? "NETWORK_ERROR" : "HTTP_ERROR";
|
|
3419
|
+
error.status = status;
|
|
3420
|
+
error.endpoint = endpoint;
|
|
3421
|
+
error.method = method;
|
|
3422
|
+
error.cause = cause;
|
|
3423
|
+
error.raw = raw;
|
|
3424
|
+
throw error;
|
|
3425
|
+
}
|
|
3426
|
+
function isRecord6(value) {
|
|
3427
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3428
|
+
}
|
|
3429
|
+
function asPath(path) {
|
|
3430
|
+
return path;
|
|
3431
|
+
}
|
|
3432
|
+
function appendQuery(path, query) {
|
|
3433
|
+
if (!query) return path;
|
|
3434
|
+
const params = new URLSearchParams();
|
|
3435
|
+
for (const [key, value] of Object.entries(query)) {
|
|
3436
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
3437
|
+
params.set(key, String(value));
|
|
3438
|
+
}
|
|
3439
|
+
const text = params.toString();
|
|
3440
|
+
return text ? `${path}?${text}` : path;
|
|
3441
|
+
}
|
|
3442
|
+
function unwrapAthenaData(payload) {
|
|
3443
|
+
if (isRecord6(payload) && "data" in payload) {
|
|
3444
|
+
return payload.data;
|
|
3445
|
+
}
|
|
3446
|
+
return payload;
|
|
3447
|
+
}
|
|
3448
|
+
function requireKey(key) {
|
|
3449
|
+
const trimmed = key.trim();
|
|
3450
|
+
if (!trimmed || trimmed === "undefined" || trimmed === "null") {
|
|
3451
|
+
backupError("Backup object key is required", 400, "/admin/backups/{key}", "DELETE");
|
|
3452
|
+
}
|
|
3453
|
+
return trimmed;
|
|
3454
|
+
}
|
|
3455
|
+
function resolveMessage(payload, fallback) {
|
|
3456
|
+
if (isRecord6(payload)) {
|
|
3457
|
+
const message = payload.message ?? payload.error ?? payload.details;
|
|
3458
|
+
if (typeof message === "string" && message.trim()) return message.trim();
|
|
3459
|
+
}
|
|
3460
|
+
if (typeof payload === "string" && payload.trim()) return payload.trim();
|
|
3461
|
+
return fallback;
|
|
3462
|
+
}
|
|
3463
|
+
async function callBackupEndpoint(gateway, path, method, payload, options, runtime) {
|
|
3464
|
+
const endpoint = asPath(path);
|
|
3465
|
+
const baseUrl = options?.baseUrl ? normalizeAthenaGatewayBaseUrl(options.baseUrl) : gateway.baseUrl;
|
|
3466
|
+
const url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
3467
|
+
const headers = gateway.buildHeaders(options);
|
|
3468
|
+
const init = {
|
|
3469
|
+
method,
|
|
3470
|
+
headers,
|
|
3471
|
+
signal: options?.signal
|
|
3472
|
+
};
|
|
3473
|
+
if (payload !== void 0 && method !== "GET") {
|
|
3474
|
+
init.body = JSON.stringify(payload);
|
|
3475
|
+
}
|
|
3476
|
+
let response;
|
|
3477
|
+
try {
|
|
3478
|
+
response = await fetch(url, init);
|
|
3479
|
+
} catch (error) {
|
|
3480
|
+
backupError(
|
|
3481
|
+
error instanceof Error ? error.message : "Backup network error",
|
|
3482
|
+
0,
|
|
3483
|
+
path,
|
|
3484
|
+
method,
|
|
3485
|
+
error
|
|
3486
|
+
);
|
|
3487
|
+
}
|
|
3488
|
+
const rawText = await response.text();
|
|
3489
|
+
let parsed = null;
|
|
3490
|
+
if (rawText) {
|
|
3491
|
+
try {
|
|
3492
|
+
parsed = JSON.parse(rawText);
|
|
3493
|
+
} catch {
|
|
3494
|
+
parsed = rawText;
|
|
3495
|
+
}
|
|
3496
|
+
}
|
|
3497
|
+
if (!response.ok) {
|
|
3498
|
+
backupError(
|
|
3499
|
+
resolveMessage(parsed, `Backup ${method} ${path} failed (${response.status})`),
|
|
3500
|
+
response.status,
|
|
3501
|
+
path,
|
|
3502
|
+
method,
|
|
3503
|
+
void 0,
|
|
3504
|
+
parsed
|
|
3505
|
+
);
|
|
3506
|
+
}
|
|
3507
|
+
return unwrapAthenaData(parsed);
|
|
3508
|
+
}
|
|
3509
|
+
function createStorageBackupModule(gateway, runtimeOptions) {
|
|
3510
|
+
const resolvedBaseUrl = () => String(gateway.baseUrl ?? "").replace(/\/+$/, "");
|
|
3511
|
+
return {
|
|
3512
|
+
async list(query, options) {
|
|
3513
|
+
const path = appendQuery("/admin/backups", {
|
|
3514
|
+
limit: query?.limit ?? 10,
|
|
3515
|
+
client_name: query?.client_name,
|
|
3516
|
+
cursor: query?.cursor ?? void 0
|
|
3517
|
+
});
|
|
3518
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
3519
|
+
const backups = (data?.backups ?? []).map((row) => ({
|
|
3520
|
+
...row,
|
|
3521
|
+
key: row.key ?? row.s3_key
|
|
3522
|
+
}));
|
|
3523
|
+
return {
|
|
3524
|
+
backups,
|
|
3525
|
+
next_cursor: data?.next_cursor ?? null
|
|
3526
|
+
};
|
|
3527
|
+
},
|
|
3528
|
+
async create(input, options) {
|
|
3529
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups", "POST", input, options);
|
|
3530
|
+
return {
|
|
3531
|
+
job_id: Number(data?.job_id ?? 0),
|
|
3532
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
3533
|
+
status: String(data?.status ?? "pending")
|
|
3534
|
+
};
|
|
3535
|
+
},
|
|
3536
|
+
async restore(key, input, options) {
|
|
3537
|
+
const backupKey = requireKey(key);
|
|
3538
|
+
const path = `/admin/backups/${encodeURIComponent(backupKey)}/restore`;
|
|
3539
|
+
const data = await callBackupEndpoint(gateway, path, "POST", input, options);
|
|
3540
|
+
return {
|
|
3541
|
+
job_id: Number(data?.job_id ?? 0),
|
|
3542
|
+
client_name: String(data?.client_name ?? input.client_name),
|
|
3543
|
+
status: String(data?.status ?? "pending"),
|
|
3544
|
+
key: String(data?.key ?? backupKey)
|
|
3545
|
+
};
|
|
3546
|
+
},
|
|
3547
|
+
async delete(key, options) {
|
|
3548
|
+
const backupKey = requireKey(key);
|
|
3549
|
+
await callBackupEndpoint(
|
|
3550
|
+
gateway,
|
|
3551
|
+
`/admin/backups/${encodeURIComponent(backupKey)}`,
|
|
3552
|
+
"DELETE",
|
|
3553
|
+
void 0,
|
|
3554
|
+
options);
|
|
3555
|
+
},
|
|
3556
|
+
downloadUrl(key, options) {
|
|
3557
|
+
const backupKey = requireKey(key);
|
|
3558
|
+
const base = `${resolvedBaseUrl()}/admin/backups/${encodeURIComponent(backupKey)}/download`;
|
|
3559
|
+
return options?.apiKey ? `${base}?api_key=${encodeURIComponent(options.apiKey)}` : base;
|
|
3560
|
+
},
|
|
3561
|
+
jobs: {
|
|
3562
|
+
async list(query, options) {
|
|
3563
|
+
const path = appendQuery("/admin/backups/jobs", query ?? {});
|
|
3564
|
+
const data = await callBackupEndpoint(gateway, path, "GET", void 0, options);
|
|
3565
|
+
if (Array.isArray(data)) return data;
|
|
3566
|
+
if (isRecord6(data) && Array.isArray(data.jobs)) return data.jobs;
|
|
3567
|
+
return [];
|
|
3568
|
+
},
|
|
3569
|
+
async get(jobId, options) {
|
|
3570
|
+
return callBackupEndpoint(
|
|
3571
|
+
gateway,
|
|
3572
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
3573
|
+
"GET",
|
|
3574
|
+
void 0,
|
|
3575
|
+
options);
|
|
3576
|
+
},
|
|
3577
|
+
async cancel(jobId, options) {
|
|
3578
|
+
return callBackupEndpoint(
|
|
3579
|
+
gateway,
|
|
3580
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/cancel`,
|
|
3581
|
+
"POST",
|
|
3582
|
+
{},
|
|
3583
|
+
options);
|
|
3584
|
+
},
|
|
3585
|
+
async delete(jobId, options) {
|
|
3586
|
+
await callBackupEndpoint(
|
|
3587
|
+
gateway,
|
|
3588
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}`,
|
|
3589
|
+
"DELETE",
|
|
3590
|
+
void 0,
|
|
3591
|
+
options);
|
|
3592
|
+
},
|
|
3593
|
+
async openObjectUrl(jobId, options) {
|
|
3594
|
+
const data = await callBackupEndpoint(
|
|
3595
|
+
gateway,
|
|
3596
|
+
`/admin/backups/jobs/${encodeURIComponent(String(jobId))}/s3-open`,
|
|
3597
|
+
"GET",
|
|
3598
|
+
void 0,
|
|
3599
|
+
options);
|
|
3600
|
+
return String(data?.url ?? "");
|
|
3601
|
+
}
|
|
3602
|
+
},
|
|
3603
|
+
schedules: {
|
|
3604
|
+
async list(options) {
|
|
3605
|
+
const data = await callBackupEndpoint(gateway, "/admin/backups/schedules", "GET", void 0, options);
|
|
3606
|
+
if (Array.isArray(data)) return data;
|
|
3607
|
+
if (isRecord6(data) && Array.isArray(data.schedules)) return data.schedules;
|
|
3608
|
+
return [];
|
|
3609
|
+
},
|
|
3610
|
+
async create(input, options) {
|
|
3611
|
+
return callBackupEndpoint(
|
|
3612
|
+
gateway,
|
|
3613
|
+
"/admin/backups/schedules",
|
|
3614
|
+
"POST",
|
|
3615
|
+
input,
|
|
3616
|
+
options);
|
|
3617
|
+
},
|
|
3618
|
+
async update(id, input, options) {
|
|
3619
|
+
return callBackupEndpoint(
|
|
3620
|
+
gateway,
|
|
3621
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
3622
|
+
"PATCH",
|
|
3623
|
+
input,
|
|
3624
|
+
options);
|
|
3625
|
+
},
|
|
3626
|
+
async delete(id, options) {
|
|
3627
|
+
await callBackupEndpoint(
|
|
3628
|
+
gateway,
|
|
3629
|
+
`/admin/backups/schedules/${encodeURIComponent(String(id))}`,
|
|
3630
|
+
"DELETE",
|
|
3631
|
+
void 0,
|
|
3632
|
+
options);
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3215
3638
|
// src/storage/module.ts
|
|
3216
3639
|
var storageSdkManifest = {
|
|
3217
3640
|
methods: [
|
|
@@ -3254,6 +3677,53 @@ var storageSdkManifest = {
|
|
|
3254
3677
|
responseEnvelope: "raw",
|
|
3255
3678
|
responseType: "{ data: S3CredentialListItem[] }"
|
|
3256
3679
|
},
|
|
3680
|
+
{
|
|
3681
|
+
name: "backup.list",
|
|
3682
|
+
method: "GET",
|
|
3683
|
+
path: "/admin/backups",
|
|
3684
|
+
responseEnvelope: "athena",
|
|
3685
|
+
responseType: "StorageBackupListPage",
|
|
3686
|
+
note: "Admin backup archives on server S3/R2 profile"
|
|
3687
|
+
},
|
|
3688
|
+
{
|
|
3689
|
+
name: "backup.create",
|
|
3690
|
+
method: "POST",
|
|
3691
|
+
path: "/admin/backups",
|
|
3692
|
+
requestType: "StorageBackupCreateRequest",
|
|
3693
|
+
responseEnvelope: "athena",
|
|
3694
|
+
responseType: "StorageBackupQueuedJob"
|
|
3695
|
+
},
|
|
3696
|
+
{
|
|
3697
|
+
name: "backup.restore",
|
|
3698
|
+
method: "POST",
|
|
3699
|
+
path: "/admin/backups/{key}/restore",
|
|
3700
|
+
pathParams: ["key"],
|
|
3701
|
+
requestType: "StorageBackupRestoreRequest",
|
|
3702
|
+
responseEnvelope: "athena",
|
|
3703
|
+
responseType: "StorageBackupQueuedJob"
|
|
3704
|
+
},
|
|
3705
|
+
{
|
|
3706
|
+
name: "backup.delete",
|
|
3707
|
+
method: "DELETE",
|
|
3708
|
+
path: "/admin/backups/{key}",
|
|
3709
|
+
pathParams: ["key"],
|
|
3710
|
+
responseEnvelope: "athena",
|
|
3711
|
+
responseType: "void"
|
|
3712
|
+
},
|
|
3713
|
+
{
|
|
3714
|
+
name: "backup.jobs.list",
|
|
3715
|
+
method: "GET",
|
|
3716
|
+
path: "/admin/backups/jobs",
|
|
3717
|
+
responseEnvelope: "athena",
|
|
3718
|
+
responseType: "StorageBackupJob[]"
|
|
3719
|
+
},
|
|
3720
|
+
{
|
|
3721
|
+
name: "backup.schedules.list",
|
|
3722
|
+
method: "GET",
|
|
3723
|
+
path: "/admin/backups/schedules",
|
|
3724
|
+
responseEnvelope: "athena",
|
|
3725
|
+
responseType: "StorageBackupSchedule[]"
|
|
3726
|
+
},
|
|
3257
3727
|
{
|
|
3258
3728
|
name: "createStorageUploadUrl",
|
|
3259
3729
|
method: "POST",
|
|
@@ -3901,7 +4371,7 @@ var AthenaStorageError = class extends Error {
|
|
|
3901
4371
|
};
|
|
3902
4372
|
}
|
|
3903
4373
|
};
|
|
3904
|
-
function
|
|
4374
|
+
function isRecord7(value) {
|
|
3905
4375
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3906
4376
|
}
|
|
3907
4377
|
function causeToString(cause) {
|
|
@@ -3999,7 +4469,7 @@ function parseResponseBody3(rawText, contentType) {
|
|
|
3999
4469
|
return { parsed: rawText, parseFailed: true };
|
|
4000
4470
|
}
|
|
4001
4471
|
}
|
|
4002
|
-
function
|
|
4472
|
+
function appendQuery2(path, query) {
|
|
4003
4473
|
if (!query) return path;
|
|
4004
4474
|
const params = new URLSearchParams();
|
|
4005
4475
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -4025,7 +4495,7 @@ function withPathParam(path, name, value) {
|
|
|
4025
4495
|
return path.replace(`{${name}}`, encodeURIComponent(value));
|
|
4026
4496
|
}
|
|
4027
4497
|
function resolveErrorMessage3(payload, fallback) {
|
|
4028
|
-
if (
|
|
4498
|
+
if (isRecord7(payload)) {
|
|
4029
4499
|
const message = payload.message ?? payload.error ?? payload.details;
|
|
4030
4500
|
if (typeof message === "string" && message.trim()) {
|
|
4031
4501
|
return message.trim();
|
|
@@ -4037,12 +4507,12 @@ function resolveErrorMessage3(payload, fallback) {
|
|
|
4037
4507
|
return fallback;
|
|
4038
4508
|
}
|
|
4039
4509
|
function resolveErrorHint2(payload) {
|
|
4040
|
-
if (!
|
|
4510
|
+
if (!isRecord7(payload)) return void 0;
|
|
4041
4511
|
const hint = payload.hint ?? payload.suggestion;
|
|
4042
4512
|
return typeof hint === "string" && hint.trim() ? hint.trim() : void 0;
|
|
4043
4513
|
}
|
|
4044
4514
|
function resolveErrorCause(payload) {
|
|
4045
|
-
if (!
|
|
4515
|
+
if (!isRecord7(payload)) return void 0;
|
|
4046
4516
|
const cause = payload.cause ?? payload.reason;
|
|
4047
4517
|
return typeof cause === "string" && cause.trim() ? cause.trim() : void 0;
|
|
4048
4518
|
}
|
|
@@ -4161,7 +4631,7 @@ async function callStorageEndpoint(gateway, endpoint, method, envelope, payload,
|
|
|
4161
4631
|
);
|
|
4162
4632
|
}
|
|
4163
4633
|
if (envelope === "athena") {
|
|
4164
|
-
if (!
|
|
4634
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
4165
4635
|
return rejectStorageError(
|
|
4166
4636
|
{
|
|
4167
4637
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -4269,7 +4739,7 @@ async function callStorageBinaryEndpoint(gateway, endpoint, method, options, run
|
|
|
4269
4739
|
runtimeOptions
|
|
4270
4740
|
);
|
|
4271
4741
|
}
|
|
4272
|
-
function
|
|
4742
|
+
function isBlobBody2(body) {
|
|
4273
4743
|
return typeof Blob !== "undefined" && body instanceof Blob;
|
|
4274
4744
|
}
|
|
4275
4745
|
function isReadableStreamBody(body) {
|
|
@@ -4278,7 +4748,7 @@ function isReadableStreamBody(body) {
|
|
|
4278
4748
|
async function putPresignedUploadBody(uploadUrl, uploadHeaders, body, options) {
|
|
4279
4749
|
const headers = new Headers(uploadHeaders);
|
|
4280
4750
|
Object.entries(options?.headers ?? {}).forEach(([key, value]) => headers.set(key, value));
|
|
4281
|
-
if (!headers.has("Content-Type") &&
|
|
4751
|
+
if (!headers.has("Content-Type") && isBlobBody2(body) && body.type) {
|
|
4282
4752
|
headers.set("Content-Type", body.type);
|
|
4283
4753
|
}
|
|
4284
4754
|
const init = {
|
|
@@ -4373,7 +4843,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
4373
4843
|
}
|
|
4374
4844
|
delete headers["Content-Type"];
|
|
4375
4845
|
delete headers["content-type"];
|
|
4376
|
-
if (
|
|
4846
|
+
if (isBlobBody2(body) && body.type) {
|
|
4377
4847
|
headers["Content-Type"] = body.type;
|
|
4378
4848
|
}
|
|
4379
4849
|
const requestInit = {
|
|
@@ -4458,7 +4928,7 @@ async function callStorageUploadBinaryEndpoint(gateway, endpoint, body, options,
|
|
|
4458
4928
|
runtimeOptions
|
|
4459
4929
|
);
|
|
4460
4930
|
}
|
|
4461
|
-
if (!
|
|
4931
|
+
if (!isRecord7(parsedBody.parsed) || !("data" in parsedBody.parsed)) {
|
|
4462
4932
|
return rejectStorageError(
|
|
4463
4933
|
{
|
|
4464
4934
|
code: "INVALID_ATHENA_ENVELOPE",
|
|
@@ -4530,14 +5000,14 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4530
5000
|
return callAthena2(withPathParam("/storage/files/{file_id}", "file_id", fileId), "GET", void 0, options);
|
|
4531
5001
|
},
|
|
4532
5002
|
getStorageFileUrl(fileId, query, options) {
|
|
4533
|
-
const path =
|
|
5003
|
+
const path = appendQuery2(
|
|
4534
5004
|
withPathParam("/storage/files/{file_id}/url", "file_id", fileId),
|
|
4535
5005
|
query
|
|
4536
5006
|
);
|
|
4537
5007
|
return callAthena2(path, "GET", void 0, options);
|
|
4538
5008
|
},
|
|
4539
5009
|
getStorageFileProxy(fileId, query, options) {
|
|
4540
|
-
const path =
|
|
5010
|
+
const path = appendQuery2(
|
|
4541
5011
|
withPathParam("/storage/files/{file_id}/proxy", "file_id", fileId),
|
|
4542
5012
|
query
|
|
4543
5013
|
);
|
|
@@ -4561,7 +5031,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4561
5031
|
};
|
|
4562
5032
|
const fileFacade = createStorageFileModule(base, runtimeOptions);
|
|
4563
5033
|
const fileUpload = ((input, options) => {
|
|
4564
|
-
if (
|
|
5034
|
+
if (isRecord7(input) && "files" in input) {
|
|
4565
5035
|
return fileFacade.upload(input, options);
|
|
4566
5036
|
}
|
|
4567
5037
|
return base.createStorageUploadUrl(
|
|
@@ -4623,7 +5093,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4623
5093
|
return callAthena2(withPathParam("/storage/files/{file_id}/public-url", "file_id", fileId), "GET", void 0, options);
|
|
4624
5094
|
},
|
|
4625
5095
|
proxyUrl(fileId, query, options) {
|
|
4626
|
-
const path =
|
|
5096
|
+
const path = appendQuery2(
|
|
4627
5097
|
withPathParam("/storage/files/{file_id}/proxy-url", "file_id", fileId),
|
|
4628
5098
|
query
|
|
4629
5099
|
);
|
|
@@ -4661,7 +5131,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4661
5131
|
},
|
|
4662
5132
|
retention: {
|
|
4663
5133
|
get(fileId, query, options) {
|
|
4664
|
-
const path =
|
|
5134
|
+
const path = appendQuery2(
|
|
4665
5135
|
withPathParam("/storage/files/{file_id}/retention", "file_id", fileId),
|
|
4666
5136
|
query
|
|
4667
5137
|
);
|
|
@@ -4863,6 +5333,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4863
5333
|
return callAthena2("/storage/audit/list", "POST", input, options);
|
|
4864
5334
|
}
|
|
4865
5335
|
};
|
|
5336
|
+
const backup = createStorageBackupModule(gateway);
|
|
4866
5337
|
return {
|
|
4867
5338
|
...base,
|
|
4868
5339
|
credentials,
|
|
@@ -4874,6 +5345,7 @@ function createStorageModule(gateway, runtimeOptions) {
|
|
|
4874
5345
|
bucket,
|
|
4875
5346
|
multipart,
|
|
4876
5347
|
audit,
|
|
5348
|
+
backup,
|
|
4877
5349
|
delete: file.delete
|
|
4878
5350
|
};
|
|
4879
5351
|
}
|
|
@@ -4923,7 +5395,7 @@ function normalizeWsUrl(value, label) {
|
|
|
4923
5395
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
4924
5396
|
return parsed.toString().replace(/\/$/, "");
|
|
4925
5397
|
}
|
|
4926
|
-
function
|
|
5398
|
+
function isRecord8(value) {
|
|
4927
5399
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4928
5400
|
}
|
|
4929
5401
|
function parseResponseBody4(rawText, contentType) {
|
|
@@ -4945,7 +5417,7 @@ function resolveRequestId3(headers) {
|
|
|
4945
5417
|
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
4946
5418
|
}
|
|
4947
5419
|
function resolveErrorMessage4(payload, fallback) {
|
|
4948
|
-
if (
|
|
5420
|
+
if (isRecord8(payload)) {
|
|
4949
5421
|
for (const candidate of [payload.error, payload.message, payload.details]) {
|
|
4950
5422
|
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
4951
5423
|
return candidate.trim();
|
|
@@ -5559,7 +6031,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
5559
6031
|
"ilike",
|
|
5560
6032
|
"is"
|
|
5561
6033
|
]);
|
|
5562
|
-
function
|
|
6034
|
+
function isRecord9(value) {
|
|
5563
6035
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5564
6036
|
}
|
|
5565
6037
|
function isUuidString(value) {
|
|
@@ -5572,7 +6044,7 @@ function shouldUseUuidTextComparison(column, value) {
|
|
|
5572
6044
|
return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
|
|
5573
6045
|
}
|
|
5574
6046
|
function isRelationSelectNode(value) {
|
|
5575
|
-
return
|
|
6047
|
+
return isRecord9(value) && isRecord9(value.select);
|
|
5576
6048
|
}
|
|
5577
6049
|
function normalizeIdentifier(value, label) {
|
|
5578
6050
|
const normalized = value.trim();
|
|
@@ -5628,7 +6100,7 @@ function compileRelationToken(key, node) {
|
|
|
5628
6100
|
return `${prefix}${relationToken}(${nested})`;
|
|
5629
6101
|
}
|
|
5630
6102
|
function compileSelectShape(select) {
|
|
5631
|
-
if (!
|
|
6103
|
+
if (!isRecord9(select)) {
|
|
5632
6104
|
throw new Error("findMany select must be an object");
|
|
5633
6105
|
}
|
|
5634
6106
|
const tokens = [];
|
|
@@ -5652,7 +6124,7 @@ function compileSelectShape(select) {
|
|
|
5652
6124
|
return tokens.join(",");
|
|
5653
6125
|
}
|
|
5654
6126
|
function selectShapeUsesRelationSchema(select) {
|
|
5655
|
-
if (!
|
|
6127
|
+
if (!isRecord9(select)) {
|
|
5656
6128
|
return false;
|
|
5657
6129
|
}
|
|
5658
6130
|
for (const rawValue of Object.values(select)) {
|
|
@@ -5670,7 +6142,7 @@ function selectShapeUsesRelationSchema(select) {
|
|
|
5670
6142
|
}
|
|
5671
6143
|
function compileColumnWhere(column, input) {
|
|
5672
6144
|
const normalizedColumn = normalizeIdentifier(column, "where column");
|
|
5673
|
-
if (!
|
|
6145
|
+
if (!isRecord9(input)) {
|
|
5674
6146
|
return [buildGatewayCondition("eq", normalizedColumn, input)];
|
|
5675
6147
|
}
|
|
5676
6148
|
const conditions = [];
|
|
@@ -5698,7 +6170,7 @@ function compileColumnWhere(column, input) {
|
|
|
5698
6170
|
return conditions;
|
|
5699
6171
|
}
|
|
5700
6172
|
function compileBooleanExpressionTerms(clause, label) {
|
|
5701
|
-
if (!
|
|
6173
|
+
if (!isRecord9(clause)) {
|
|
5702
6174
|
throw new Error(`findMany where.${label} clauses must be objects`);
|
|
5703
6175
|
}
|
|
5704
6176
|
const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
|
|
@@ -5707,7 +6179,7 @@ function compileBooleanExpressionTerms(clause, label) {
|
|
|
5707
6179
|
}
|
|
5708
6180
|
const [rawColumn, rawValue] = entries[0];
|
|
5709
6181
|
const column = normalizeIdentifier(rawColumn, `where.${label} column`);
|
|
5710
|
-
if (!
|
|
6182
|
+
if (!isRecord9(rawValue)) {
|
|
5711
6183
|
return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
|
|
5712
6184
|
}
|
|
5713
6185
|
const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
|
|
@@ -5731,7 +6203,7 @@ function compileWhere(where) {
|
|
|
5731
6203
|
if (where === void 0) {
|
|
5732
6204
|
return void 0;
|
|
5733
6205
|
}
|
|
5734
|
-
if (!
|
|
6206
|
+
if (!isRecord9(where)) {
|
|
5735
6207
|
throw new Error("findMany where must be an object");
|
|
5736
6208
|
}
|
|
5737
6209
|
const conditions = [];
|
|
@@ -5781,7 +6253,7 @@ function compileOrderBy(orderBy) {
|
|
|
5781
6253
|
if (orderBy === void 0) {
|
|
5782
6254
|
return void 0;
|
|
5783
6255
|
}
|
|
5784
|
-
if (!
|
|
6256
|
+
if (!isRecord9(orderBy)) {
|
|
5785
6257
|
throw new Error("findMany orderBy must be an object");
|
|
5786
6258
|
}
|
|
5787
6259
|
if ("column" in orderBy) {
|
|
@@ -5956,11 +6428,11 @@ function toFindManyAstOrder(order) {
|
|
|
5956
6428
|
ascending: order.direction !== "descending"
|
|
5957
6429
|
};
|
|
5958
6430
|
}
|
|
5959
|
-
function
|
|
6431
|
+
function isRecord10(value) {
|
|
5960
6432
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
5961
6433
|
}
|
|
5962
6434
|
function normalizeFindManyAstColumnPredicate(value) {
|
|
5963
|
-
if (!
|
|
6435
|
+
if (!isRecord10(value)) {
|
|
5964
6436
|
return {
|
|
5965
6437
|
eq: value
|
|
5966
6438
|
};
|
|
@@ -5984,7 +6456,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
|
|
|
5984
6456
|
return normalized;
|
|
5985
6457
|
}
|
|
5986
6458
|
function normalizeFindManyAstWhere(where) {
|
|
5987
|
-
if (!where || !
|
|
6459
|
+
if (!where || !isRecord10(where)) {
|
|
5988
6460
|
return where;
|
|
5989
6461
|
}
|
|
5990
6462
|
const normalized = {};
|
|
@@ -5998,7 +6470,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
5998
6470
|
);
|
|
5999
6471
|
continue;
|
|
6000
6472
|
}
|
|
6001
|
-
if (key === "not" &&
|
|
6473
|
+
if (key === "not" && isRecord10(value)) {
|
|
6002
6474
|
normalized.not = normalizeFindManyAstBooleanOperand(
|
|
6003
6475
|
value
|
|
6004
6476
|
);
|
|
@@ -6009,7 +6481,7 @@ function normalizeFindManyAstWhere(where) {
|
|
|
6009
6481
|
return normalized;
|
|
6010
6482
|
}
|
|
6011
6483
|
function predicateRequiresUuidQueryFallback(column, value) {
|
|
6012
|
-
if (!
|
|
6484
|
+
if (!isRecord10(value)) {
|
|
6013
6485
|
return shouldUseUuidTextComparison(column, value);
|
|
6014
6486
|
}
|
|
6015
6487
|
const eqValue = value.eq;
|
|
@@ -6027,7 +6499,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
|
|
|
6027
6499
|
return false;
|
|
6028
6500
|
}
|
|
6029
6501
|
function findManyAstWhereRequiresLegacyTransport(where) {
|
|
6030
|
-
if (!where || !
|
|
6502
|
+
if (!where || !isRecord10(where)) {
|
|
6031
6503
|
return false;
|
|
6032
6504
|
}
|
|
6033
6505
|
for (const [key, value] of Object.entries(where)) {
|
|
@@ -6042,7 +6514,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
|
|
|
6042
6514
|
}
|
|
6043
6515
|
continue;
|
|
6044
6516
|
}
|
|
6045
|
-
if (key === "not" &&
|
|
6517
|
+
if (key === "not" && isRecord10(value)) {
|
|
6046
6518
|
if (booleanOperandRequiresUuidQueryFallback(value)) {
|
|
6047
6519
|
return true;
|
|
6048
6520
|
}
|
|
@@ -6662,7 +7134,7 @@ async function executeExperimentalRead(experimental, runner) {
|
|
|
6662
7134
|
throw error;
|
|
6663
7135
|
}
|
|
6664
7136
|
}
|
|
6665
|
-
function
|
|
7137
|
+
function isRecord11(value) {
|
|
6666
7138
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6667
7139
|
}
|
|
6668
7140
|
function firstNonEmptyString2(...values) {
|
|
@@ -6674,8 +7146,8 @@ function firstNonEmptyString2(...values) {
|
|
|
6674
7146
|
return void 0;
|
|
6675
7147
|
}
|
|
6676
7148
|
function resolveStructuredErrorPayload2(raw) {
|
|
6677
|
-
if (!
|
|
6678
|
-
return
|
|
7149
|
+
if (!isRecord11(raw)) return null;
|
|
7150
|
+
return isRecord11(raw.error) ? raw.error : raw;
|
|
6679
7151
|
}
|
|
6680
7152
|
function resolveStructuredErrorDetails(payload, message) {
|
|
6681
7153
|
if (!payload || !("details" in payload)) {
|
|
@@ -6691,7 +7163,7 @@ function resolveStructuredErrorDetails(payload, message) {
|
|
|
6691
7163
|
return details;
|
|
6692
7164
|
}
|
|
6693
7165
|
function createResultError(response, result, normalized) {
|
|
6694
|
-
const rawRecord =
|
|
7166
|
+
const rawRecord = isRecord11(response.raw) ? response.raw : null;
|
|
6695
7167
|
const payload = resolveStructuredErrorPayload2(response.raw);
|
|
6696
7168
|
const message = firstNonEmptyString2(
|
|
6697
7169
|
response.error,
|
|
@@ -8439,7 +8911,30 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8439
8911
|
config.experimental,
|
|
8440
8912
|
queryTracer
|
|
8441
8913
|
);
|
|
8442
|
-
const
|
|
8914
|
+
const untypedDbFrom = from;
|
|
8915
|
+
const db = {
|
|
8916
|
+
from,
|
|
8917
|
+
select(table, first, second) {
|
|
8918
|
+
if (first && typeof first === "object" && !Array.isArray(first)) {
|
|
8919
|
+
return untypedDbFrom(table).select(void 0, first);
|
|
8920
|
+
}
|
|
8921
|
+
return untypedDbFrom(table).select(first, second);
|
|
8922
|
+
},
|
|
8923
|
+
insert(table, values, options) {
|
|
8924
|
+
return Array.isArray(values) ? untypedDbFrom(table).insert(values, options) : untypedDbFrom(table).insert(values, options);
|
|
8925
|
+
},
|
|
8926
|
+
upsert(table, values, options) {
|
|
8927
|
+
return Array.isArray(values) ? untypedDbFrom(table).upsert(values, options) : untypedDbFrom(table).upsert(values, options);
|
|
8928
|
+
},
|
|
8929
|
+
update(table, values, options) {
|
|
8930
|
+
return untypedDbFrom(table).update(values, options);
|
|
8931
|
+
},
|
|
8932
|
+
delete(table, options) {
|
|
8933
|
+
return untypedDbFrom(table).delete(options);
|
|
8934
|
+
},
|
|
8935
|
+
rpc,
|
|
8936
|
+
query
|
|
8937
|
+
};
|
|
8443
8938
|
const chat = createChatModule({
|
|
8444
8939
|
baseUrl: config.chatUrl,
|
|
8445
8940
|
apiKey: config.apiKey,
|
|
@@ -8577,6 +9072,7 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8577
9072
|
withOptions: storageWithOptions,
|
|
8578
9073
|
storage: createStorageModule(gateway, {
|
|
8579
9074
|
...config.experimental.storage,
|
|
9075
|
+
...config.experimental.directStorageUpload ? { directUpload: config.experimental.directStorageUpload } : {},
|
|
8580
9076
|
...config.storageUrl ? {
|
|
8581
9077
|
baseUrl: config.storageUrl,
|
|
8582
9078
|
stripBasePath: true
|
|
@@ -8590,7 +9086,9 @@ function createClientFromConfig(config, sourceConfig) {
|
|
|
8590
9086
|
var AthenaClient = class {
|
|
8591
9087
|
/** Create a fluent builder for a strongly-typed Athena SDK client. */
|
|
8592
9088
|
static builder() {
|
|
8593
|
-
return createAthenaClientBuilder(
|
|
9089
|
+
return createAthenaClientBuilder(
|
|
9090
|
+
(config) => createClientFromInput(config)
|
|
9091
|
+
);
|
|
8594
9092
|
}
|
|
8595
9093
|
static fromEnvironment(options = {}) {
|
|
8596
9094
|
const env = options.env ?? process.env;
|
|
@@ -8621,11 +9119,12 @@ var AthenaClient = class {
|
|
|
8621
9119
|
});
|
|
8622
9120
|
}
|
|
8623
9121
|
};
|
|
8624
|
-
function createClient(
|
|
9122
|
+
function createClient(...args) {
|
|
9123
|
+
const [configOrUrl, apiKey, options] = args;
|
|
8625
9124
|
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
8626
9125
|
return createClientFromInput({
|
|
8627
9126
|
url: configOrUrl,
|
|
8628
|
-
key: "",
|
|
9127
|
+
key: apiKey ?? "",
|
|
8629
9128
|
...options
|
|
8630
9129
|
});
|
|
8631
9130
|
}
|
|
@@ -8761,6 +9260,237 @@ function buildSessionClientOptions(context, options) {
|
|
|
8761
9260
|
};
|
|
8762
9261
|
}
|
|
8763
9262
|
|
|
9263
|
+
// src/next/session-bridge/constants.ts
|
|
9264
|
+
var ATHENA_AUTH_SESSION_BRIDGE_ROUTE = "/api/athena-auth/session";
|
|
9265
|
+
var ATHENA_AUTH_SESSION_COOKIE_NAME = "athena-auth.session-token";
|
|
9266
|
+
var ATHENA_AUTH_SESSION_COOKIE_NAMES = [
|
|
9267
|
+
ATHENA_AUTH_SESSION_COOKIE_NAME,
|
|
9268
|
+
"athena-auth.session_token"
|
|
9269
|
+
];
|
|
9270
|
+
|
|
9271
|
+
// src/next/session-bridge/client.ts
|
|
9272
|
+
var JSON_CONTENT_TYPE = "application/json";
|
|
9273
|
+
function isBrowserRuntime() {
|
|
9274
|
+
return typeof globalThis !== "undefined" && "window" in globalThis;
|
|
9275
|
+
}
|
|
9276
|
+
async function persistAthenaAuthSessionOnAppHost(payload, options) {
|
|
9277
|
+
if (!(payload && isBrowserRuntime())) {
|
|
9278
|
+
return;
|
|
9279
|
+
}
|
|
9280
|
+
const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
|
|
9281
|
+
const fetchImpl = options?.fetch ?? fetch;
|
|
9282
|
+
const response = await fetchImpl(route, {
|
|
9283
|
+
body: JSON.stringify(payload),
|
|
9284
|
+
credentials: "same-origin",
|
|
9285
|
+
headers: {
|
|
9286
|
+
"Content-Type": JSON_CONTENT_TYPE
|
|
9287
|
+
},
|
|
9288
|
+
method: "POST"
|
|
9289
|
+
});
|
|
9290
|
+
if (!response.ok) {
|
|
9291
|
+
throw new Error("Failed to persist the Athena Auth session on the app host");
|
|
9292
|
+
}
|
|
9293
|
+
}
|
|
9294
|
+
async function clearAthenaAuthSessionOnAppHost(options) {
|
|
9295
|
+
if (!isBrowserRuntime()) {
|
|
9296
|
+
return;
|
|
9297
|
+
}
|
|
9298
|
+
const route = options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
|
|
9299
|
+
const fetchImpl = options?.fetch ?? fetch;
|
|
9300
|
+
const response = await fetchImpl(route, {
|
|
9301
|
+
credentials: "same-origin",
|
|
9302
|
+
method: "DELETE"
|
|
9303
|
+
});
|
|
9304
|
+
if (!response.ok) {
|
|
9305
|
+
throw new Error("Failed to clear the Athena Auth session on the app host");
|
|
9306
|
+
}
|
|
9307
|
+
}
|
|
9308
|
+
|
|
9309
|
+
// src/next/session-bridge/payload.ts
|
|
9310
|
+
function resolveSessionBridgePayload(payload) {
|
|
9311
|
+
const token = payload?.session?.token ?? payload?.token;
|
|
9312
|
+
if (typeof token !== "string") {
|
|
9313
|
+
return null;
|
|
9314
|
+
}
|
|
9315
|
+
const normalizedToken = token.trim();
|
|
9316
|
+
if (!normalizedToken) {
|
|
9317
|
+
return null;
|
|
9318
|
+
}
|
|
9319
|
+
return {
|
|
9320
|
+
token: normalizedToken,
|
|
9321
|
+
expiresAt: typeof payload?.session?.expiresAt === "string" ? payload.session.expiresAt : void 0
|
|
9322
|
+
};
|
|
9323
|
+
}
|
|
9324
|
+
|
|
9325
|
+
// src/next/session-bridge/cookie.ts
|
|
9326
|
+
var EXPIRED_AT = /* @__PURE__ */ new Date(0);
|
|
9327
|
+
function resolveRequestIsSecure(request2) {
|
|
9328
|
+
const forwardedProto = request2.headers.get("x-forwarded-proto")?.trim();
|
|
9329
|
+
if (forwardedProto) {
|
|
9330
|
+
const first = forwardedProto.split(",")[0]?.trim().toLowerCase();
|
|
9331
|
+
if (first === "https") return true;
|
|
9332
|
+
if (first === "http") return false;
|
|
9333
|
+
}
|
|
9334
|
+
return new URL(request2.url).protocol === "https:";
|
|
9335
|
+
}
|
|
9336
|
+
function resolveSessionCookieExpiresAt(value) {
|
|
9337
|
+
if (typeof value !== "string") {
|
|
9338
|
+
return void 0;
|
|
9339
|
+
}
|
|
9340
|
+
const expiresAt = new Date(value);
|
|
9341
|
+
return Number.isNaN(expiresAt.getTime()) ? void 0 : expiresAt;
|
|
9342
|
+
}
|
|
9343
|
+
function serializeCookie(name, value, options) {
|
|
9344
|
+
const parts = [
|
|
9345
|
+
`${encodeURIComponent(name)}=${encodeURIComponent(value)}`,
|
|
9346
|
+
`Path=${options.path}`,
|
|
9347
|
+
"HttpOnly",
|
|
9348
|
+
`SameSite=${options.sameSite === "none" ? "None" : options.sameSite === "strict" ? "Strict" : "Lax"}`
|
|
9349
|
+
];
|
|
9350
|
+
if (options.secure) {
|
|
9351
|
+
parts.push("Secure");
|
|
9352
|
+
}
|
|
9353
|
+
if (options.expires) {
|
|
9354
|
+
parts.push(`Expires=${options.expires.toUTCString()}`);
|
|
9355
|
+
}
|
|
9356
|
+
return parts.join("; ");
|
|
9357
|
+
}
|
|
9358
|
+
function resolveBridgeCookieConfig(options) {
|
|
9359
|
+
return {
|
|
9360
|
+
cookieName: options?.cookieName ?? ATHENA_AUTH_SESSION_COOKIE_NAME,
|
|
9361
|
+
cookieNames: options?.cookieNames ?? ATHENA_AUTH_SESSION_COOKIE_NAMES,
|
|
9362
|
+
cookiePath: options?.cookiePath ?? "/",
|
|
9363
|
+
sameSite: options?.sameSite ?? "lax"
|
|
9364
|
+
};
|
|
9365
|
+
}
|
|
9366
|
+
function appendSessionCookie(headers, request2, token, expiresAt, options) {
|
|
9367
|
+
const config = resolveBridgeCookieConfig(options);
|
|
9368
|
+
const secure = options?.secure ?? resolveRequestIsSecure(request2);
|
|
9369
|
+
headers.append(
|
|
9370
|
+
"set-cookie",
|
|
9371
|
+
serializeCookie(config.cookieName, token, {
|
|
9372
|
+
path: config.cookiePath,
|
|
9373
|
+
sameSite: config.sameSite,
|
|
9374
|
+
secure,
|
|
9375
|
+
expires: expiresAt
|
|
9376
|
+
})
|
|
9377
|
+
);
|
|
9378
|
+
}
|
|
9379
|
+
function appendClearSessionCookies(headers, request2, options) {
|
|
9380
|
+
const config = resolveBridgeCookieConfig(options);
|
|
9381
|
+
const secure = options?.secure ?? resolveRequestIsSecure(request2);
|
|
9382
|
+
const names = /* @__PURE__ */ new Set([config.cookieName, ...config.cookieNames]);
|
|
9383
|
+
for (const name of names) {
|
|
9384
|
+
headers.append(
|
|
9385
|
+
"set-cookie",
|
|
9386
|
+
serializeCookie(name, "", {
|
|
9387
|
+
path: config.cookiePath,
|
|
9388
|
+
sameSite: config.sameSite,
|
|
9389
|
+
secure,
|
|
9390
|
+
expires: EXPIRED_AT
|
|
9391
|
+
})
|
|
9392
|
+
);
|
|
9393
|
+
}
|
|
9394
|
+
}
|
|
9395
|
+
|
|
9396
|
+
// src/next/session-bridge/handlers.ts
|
|
9397
|
+
function json(body, init) {
|
|
9398
|
+
const headers = init?.headers ?? new Headers();
|
|
9399
|
+
if (!headers.has("content-type")) {
|
|
9400
|
+
headers.set("content-type", "application/json; charset=utf-8");
|
|
9401
|
+
}
|
|
9402
|
+
return new Response(JSON.stringify(body), {
|
|
9403
|
+
status: init?.status ?? 200,
|
|
9404
|
+
headers
|
|
9405
|
+
});
|
|
9406
|
+
}
|
|
9407
|
+
function resolveRoute(options) {
|
|
9408
|
+
return options?.route ?? ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
|
|
9409
|
+
}
|
|
9410
|
+
async function handleAthenaAuthSessionBridgePost(request2, options) {
|
|
9411
|
+
const payload = await request2.json().catch(() => null);
|
|
9412
|
+
const token = typeof payload?.token === "string" ? payload.token.trim() : "";
|
|
9413
|
+
if (!token) {
|
|
9414
|
+
return json(
|
|
9415
|
+
{
|
|
9416
|
+
error: "Missing Athena Auth session token"
|
|
9417
|
+
},
|
|
9418
|
+
{ status: 400 }
|
|
9419
|
+
);
|
|
9420
|
+
}
|
|
9421
|
+
const headers = new Headers();
|
|
9422
|
+
appendSessionCookie(
|
|
9423
|
+
headers,
|
|
9424
|
+
request2,
|
|
9425
|
+
token,
|
|
9426
|
+
resolveSessionCookieExpiresAt(payload?.expiresAt),
|
|
9427
|
+
options
|
|
9428
|
+
);
|
|
9429
|
+
return json(
|
|
9430
|
+
{
|
|
9431
|
+
ok: true,
|
|
9432
|
+
route: resolveRoute(options)
|
|
9433
|
+
},
|
|
9434
|
+
{ headers }
|
|
9435
|
+
);
|
|
9436
|
+
}
|
|
9437
|
+
function handleAthenaAuthSessionBridgeDelete(request2, options) {
|
|
9438
|
+
const headers = new Headers();
|
|
9439
|
+
appendClearSessionCookies(headers, request2, options);
|
|
9440
|
+
return json(
|
|
9441
|
+
{
|
|
9442
|
+
ok: true,
|
|
9443
|
+
route: resolveRoute(options)
|
|
9444
|
+
},
|
|
9445
|
+
{ headers }
|
|
9446
|
+
);
|
|
9447
|
+
}
|
|
9448
|
+
function createAthenaAuthSessionBridgeHandlers(options) {
|
|
9449
|
+
return {
|
|
9450
|
+
POST: (request2) => handleAthenaAuthSessionBridgePost(request2, options),
|
|
9451
|
+
DELETE: (request2) => handleAthenaAuthSessionBridgeDelete(request2, options)
|
|
9452
|
+
};
|
|
9453
|
+
}
|
|
9454
|
+
function normalizePathname(pathname) {
|
|
9455
|
+
if (pathname.length > 1 && pathname.endsWith("/")) {
|
|
9456
|
+
return pathname.slice(0, -1);
|
|
9457
|
+
}
|
|
9458
|
+
return pathname || "/";
|
|
9459
|
+
}
|
|
9460
|
+
function isAthenaAuthSessionBridgePath(request2, options) {
|
|
9461
|
+
const pathname = normalizePathname(new URL(request2.url).pathname);
|
|
9462
|
+
const route = normalizePathname(resolveRoute(options));
|
|
9463
|
+
if (pathname === route) {
|
|
9464
|
+
return true;
|
|
9465
|
+
}
|
|
9466
|
+
const matchPaths = options?.matchPaths ?? ["session"];
|
|
9467
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
9468
|
+
const tail = segments[segments.length - 1];
|
|
9469
|
+
return typeof tail === "string" && matchPaths.includes(tail);
|
|
9470
|
+
}
|
|
9471
|
+
function createAthenaAuthSessionBridgePathHandlers(options) {
|
|
9472
|
+
const notFound = () => json(
|
|
9473
|
+
{
|
|
9474
|
+
error: "Not found"
|
|
9475
|
+
},
|
|
9476
|
+
{ status: 404 }
|
|
9477
|
+
);
|
|
9478
|
+
return {
|
|
9479
|
+
POST: async (request2) => {
|
|
9480
|
+
if (!isAthenaAuthSessionBridgePath(request2, options)) {
|
|
9481
|
+
return notFound();
|
|
9482
|
+
}
|
|
9483
|
+
return handleAthenaAuthSessionBridgePost(request2, options);
|
|
9484
|
+
},
|
|
9485
|
+
DELETE: (request2) => {
|
|
9486
|
+
if (!isAthenaAuthSessionBridgePath(request2, options)) {
|
|
9487
|
+
return notFound();
|
|
9488
|
+
}
|
|
9489
|
+
return handleAthenaAuthSessionBridgeDelete(request2, options);
|
|
9490
|
+
}
|
|
9491
|
+
};
|
|
9492
|
+
}
|
|
9493
|
+
|
|
8764
9494
|
// src/next/server.ts
|
|
8765
9495
|
function resolveUserId(session) {
|
|
8766
9496
|
return session?.user?.id ?? null;
|
|
@@ -8799,7 +9529,20 @@ async function resolveAthenaServerContext(options) {
|
|
|
8799
9529
|
};
|
|
8800
9530
|
}
|
|
8801
9531
|
|
|
9532
|
+
exports.ATHENA_AUTH_SESSION_BRIDGE_ROUTE = ATHENA_AUTH_SESSION_BRIDGE_ROUTE;
|
|
9533
|
+
exports.ATHENA_AUTH_SESSION_COOKIE_NAME = ATHENA_AUTH_SESSION_COOKIE_NAME;
|
|
9534
|
+
exports.ATHENA_AUTH_SESSION_COOKIE_NAMES = ATHENA_AUTH_SESSION_COOKIE_NAMES;
|
|
9535
|
+
exports.SESSION_COOKIE_PATTERNS = SESSION_COOKIE_PATTERNS;
|
|
9536
|
+
exports.clearAthenaAuthSessionOnAppHost = clearAthenaAuthSessionOnAppHost;
|
|
9537
|
+
exports.createAthenaAuthSessionBridgeHandlers = createAthenaAuthSessionBridgeHandlers;
|
|
9538
|
+
exports.createAthenaAuthSessionBridgePathHandlers = createAthenaAuthSessionBridgePathHandlers;
|
|
8802
9539
|
exports.createAthenaServerClient = createAthenaServerClient;
|
|
9540
|
+
exports.handleAthenaAuthSessionBridgeDelete = handleAthenaAuthSessionBridgeDelete;
|
|
9541
|
+
exports.handleAthenaAuthSessionBridgePost = handleAthenaAuthSessionBridgePost;
|
|
9542
|
+
exports.hasAuthSessionCookie = hasAuthSessionCookie;
|
|
9543
|
+
exports.isAthenaAuthSessionBridgePath = isAthenaAuthSessionBridgePath;
|
|
9544
|
+
exports.persistAthenaAuthSessionOnAppHost = persistAthenaAuthSessionOnAppHost;
|
|
8803
9545
|
exports.resolveAthenaServerContext = resolveAthenaServerContext;
|
|
9546
|
+
exports.resolveSessionBridgePayload = resolveSessionBridgePayload;
|
|
8804
9547
|
//# sourceMappingURL=server.cjs.map
|
|
8805
9548
|
//# sourceMappingURL=server.cjs.map
|