@xylex-group/athena 2.1.2 → 2.4.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/README.md +306 -117
- package/dist/browser.cjs +2151 -194
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +14 -14
- package/dist/browser.d.ts +14 -14
- package/dist/browser.js +2146 -194
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +2035 -172
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +2036 -173
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +2166 -190
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +2162 -191
- package/dist/index.js.map +1 -1
- package/dist/{model-form-2hqmoOUX.d.ts → model-form-C0FAbOaf.d.ts} +97 -2
- package/dist/{model-form-Cy-zaO0u.d.cts → model-form-GzTqhEzM.d.cts} +97 -2
- package/dist/{pipeline-BOPszLsL.d.ts → pipeline-CR4V15jF.d.ts} +1 -1
- package/dist/{pipeline-E3FDbs4W.d.cts → pipeline-DZeExYMA.d.cts} +1 -1
- package/dist/{client-BX0NQqOn.d.ts → react-email-BuApZuyG.d.ts} +362 -174
- package/dist/{client-dpAp-NZK.d.cts → react-email-CQJq92zQ.d.cts} +362 -174
- package/dist/react.cjs +279 -21
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +279 -21
- package/dist/react.js.map +1 -1
- package/dist/{types-BaBzjwXr.d.cts → types-09Q4D86N.d.cts} +24 -2
- package/dist/{types-BaBzjwXr.d.ts → types-09Q4D86N.d.ts} +24 -2
- package/dist/{types-CpqL-pZx.d.cts → types-D1JvL21V.d.cts} +1 -1
- package/dist/{types-CeBPrnGj.d.ts → types-DU3gNdFv.d.ts} +1 -1
- package/dist/utils.cjs +153 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +23 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.js +146 -0
- package/dist/utils.js.map +1 -0
- package/package.json +74 -16
|
@@ -44,9 +44,12 @@ interface AthenaSortBy {
|
|
|
44
44
|
direction: AthenaSortDirection;
|
|
45
45
|
}
|
|
46
46
|
interface AthenaFetchPayload {
|
|
47
|
+
select?: string | AthenaJsonObject;
|
|
47
48
|
view_name?: string;
|
|
48
49
|
table_name?: string;
|
|
49
50
|
columns?: string[] | string;
|
|
51
|
+
where?: AthenaJsonObject;
|
|
52
|
+
orderBy?: AthenaJsonObject | AthenaJsonArray;
|
|
50
53
|
conditions?: AthenaGatewayCondition[];
|
|
51
54
|
limit?: number;
|
|
52
55
|
offset?: number;
|
|
@@ -54,6 +57,8 @@ interface AthenaFetchPayload {
|
|
|
54
57
|
page_size?: number;
|
|
55
58
|
total_pages?: number;
|
|
56
59
|
strip_nulls?: boolean;
|
|
60
|
+
count?: AthenaCountOption;
|
|
61
|
+
head?: boolean;
|
|
57
62
|
group_by?: string;
|
|
58
63
|
time_granularity?: 'day' | 'hour' | 'minute';
|
|
59
64
|
aggregation_column?: string;
|
|
@@ -158,13 +163,14 @@ interface AthenaRpcCallOptions extends AthenaGatewayCallOptions {
|
|
|
158
163
|
interface AthenaGatewayResponse<T = unknown> {
|
|
159
164
|
ok: boolean;
|
|
160
165
|
status: number;
|
|
166
|
+
statusText?: string | null;
|
|
161
167
|
data: T | null;
|
|
162
168
|
count?: number | null;
|
|
163
169
|
error?: string;
|
|
164
170
|
errorDetails?: AthenaGatewayErrorDetails | null;
|
|
165
171
|
raw: unknown;
|
|
166
172
|
}
|
|
167
|
-
type AthenaGatewayErrorCode = 'NETWORK_ERROR' | 'HTTP_ERROR' | 'INVALID_JSON' | 'UNKNOWN_ERROR';
|
|
173
|
+
type AthenaGatewayErrorCode = 'NETWORK_ERROR' | 'INVALID_URL' | 'HTTP_ERROR' | 'INVALID_JSON' | 'UNKNOWN_ERROR';
|
|
168
174
|
interface AthenaGatewayErrorDetails {
|
|
169
175
|
code: AthenaGatewayErrorCode;
|
|
170
176
|
message: string;
|
|
@@ -175,6 +181,22 @@ interface AthenaGatewayErrorDetails {
|
|
|
175
181
|
hint?: string;
|
|
176
182
|
cause?: string;
|
|
177
183
|
}
|
|
184
|
+
interface AthenaGatewayConnectionOptions {
|
|
185
|
+
path?: `/${string}`;
|
|
186
|
+
headers?: Record<string, string>;
|
|
187
|
+
signal?: AbortSignal;
|
|
188
|
+
}
|
|
189
|
+
interface AthenaGatewayConnectionResult {
|
|
190
|
+
ok: boolean;
|
|
191
|
+
reachable: boolean;
|
|
192
|
+
status: number;
|
|
193
|
+
statusText?: string | null;
|
|
194
|
+
baseUrl: string;
|
|
195
|
+
url: string;
|
|
196
|
+
error?: string;
|
|
197
|
+
errorDetails?: AthenaGatewayErrorDetails | null;
|
|
198
|
+
raw: unknown;
|
|
199
|
+
}
|
|
178
200
|
interface AthenaGatewayResponseLog extends AthenaGatewayResponse {
|
|
179
201
|
timestamp: string;
|
|
180
202
|
}
|
|
@@ -377,4 +399,4 @@ interface SchemaIntrospectionProvider {
|
|
|
377
399
|
inspect(options?: IntrospectionInspectOptions): Promise<IntrospectionSnapshot>;
|
|
378
400
|
}
|
|
379
401
|
|
|
380
|
-
export { type AthenaConditionCastType as A, Backend as B, type
|
|
402
|
+
export { type AthenaConditionCastType as A, Backend as B, type ModelRelationMetadata as C, type DatabaseDef as D, type RowOf as E, type SchemaDef as F, type TenantContextValue as G, type TenantKeyMap as H, type IntrospectionSnapshot as I, type AthenaConditionValue as J, type AthenaConditionArrayValue as K, type AnyModelDef as L, type ModelAt as M, type AthenaConditionOperator as N, type AthenaGatewayHookConfig as O, type AthenaGatewayHookResult as P, type AthenaDeletePayload as Q, type RegistryDef as R, type SchemaIntrospectionProvider as S, type TenantContext as T, type UpdateOf as U, type AthenaFetchPayload as V, type AthenaGatewayResponse as W, type AthenaInsertPayload as X, type AthenaUpdatePayload as Y, type AthenaGatewayEndpointPath as Z, type AthenaGatewayMethod as _, type AthenaGatewayCallOptions as a, type AthenaGatewayConnectionOptions as b, type AthenaGatewayConnectionResult as c, type AthenaGatewayErrorCode as d, type AthenaGatewayErrorDetails as e, type AthenaJsonArray as f, type AthenaJsonObject as g, type AthenaJsonPrimitive as h, type AthenaJsonValue as i, type AthenaRpcCallOptions as j, type AthenaRpcFilter as k, type AthenaRpcFilterOperator as l, type AthenaRpcOrder as m, type AthenaRpcPayload as n, type BackendConfig as o, type BackendType as p, type InsertOf as q, type IntrospectionColumn as r, type IntrospectionInspectOptions as s, type IntrospectionRelation as t, type IntrospectionSchema as u, type IntrospectionTable as v, type IntrospectionTypeKind as w, type ModelDef as x, type ModelMetadata as y, type ModelRelationKind as z };
|
|
@@ -44,9 +44,12 @@ interface AthenaSortBy {
|
|
|
44
44
|
direction: AthenaSortDirection;
|
|
45
45
|
}
|
|
46
46
|
interface AthenaFetchPayload {
|
|
47
|
+
select?: string | AthenaJsonObject;
|
|
47
48
|
view_name?: string;
|
|
48
49
|
table_name?: string;
|
|
49
50
|
columns?: string[] | string;
|
|
51
|
+
where?: AthenaJsonObject;
|
|
52
|
+
orderBy?: AthenaJsonObject | AthenaJsonArray;
|
|
50
53
|
conditions?: AthenaGatewayCondition[];
|
|
51
54
|
limit?: number;
|
|
52
55
|
offset?: number;
|
|
@@ -54,6 +57,8 @@ interface AthenaFetchPayload {
|
|
|
54
57
|
page_size?: number;
|
|
55
58
|
total_pages?: number;
|
|
56
59
|
strip_nulls?: boolean;
|
|
60
|
+
count?: AthenaCountOption;
|
|
61
|
+
head?: boolean;
|
|
57
62
|
group_by?: string;
|
|
58
63
|
time_granularity?: 'day' | 'hour' | 'minute';
|
|
59
64
|
aggregation_column?: string;
|
|
@@ -158,13 +163,14 @@ interface AthenaRpcCallOptions extends AthenaGatewayCallOptions {
|
|
|
158
163
|
interface AthenaGatewayResponse<T = unknown> {
|
|
159
164
|
ok: boolean;
|
|
160
165
|
status: number;
|
|
166
|
+
statusText?: string | null;
|
|
161
167
|
data: T | null;
|
|
162
168
|
count?: number | null;
|
|
163
169
|
error?: string;
|
|
164
170
|
errorDetails?: AthenaGatewayErrorDetails | null;
|
|
165
171
|
raw: unknown;
|
|
166
172
|
}
|
|
167
|
-
type AthenaGatewayErrorCode = 'NETWORK_ERROR' | 'HTTP_ERROR' | 'INVALID_JSON' | 'UNKNOWN_ERROR';
|
|
173
|
+
type AthenaGatewayErrorCode = 'NETWORK_ERROR' | 'INVALID_URL' | 'HTTP_ERROR' | 'INVALID_JSON' | 'UNKNOWN_ERROR';
|
|
168
174
|
interface AthenaGatewayErrorDetails {
|
|
169
175
|
code: AthenaGatewayErrorCode;
|
|
170
176
|
message: string;
|
|
@@ -175,6 +181,22 @@ interface AthenaGatewayErrorDetails {
|
|
|
175
181
|
hint?: string;
|
|
176
182
|
cause?: string;
|
|
177
183
|
}
|
|
184
|
+
interface AthenaGatewayConnectionOptions {
|
|
185
|
+
path?: `/${string}`;
|
|
186
|
+
headers?: Record<string, string>;
|
|
187
|
+
signal?: AbortSignal;
|
|
188
|
+
}
|
|
189
|
+
interface AthenaGatewayConnectionResult {
|
|
190
|
+
ok: boolean;
|
|
191
|
+
reachable: boolean;
|
|
192
|
+
status: number;
|
|
193
|
+
statusText?: string | null;
|
|
194
|
+
baseUrl: string;
|
|
195
|
+
url: string;
|
|
196
|
+
error?: string;
|
|
197
|
+
errorDetails?: AthenaGatewayErrorDetails | null;
|
|
198
|
+
raw: unknown;
|
|
199
|
+
}
|
|
178
200
|
interface AthenaGatewayResponseLog extends AthenaGatewayResponse {
|
|
179
201
|
timestamp: string;
|
|
180
202
|
}
|
|
@@ -377,4 +399,4 @@ interface SchemaIntrospectionProvider {
|
|
|
377
399
|
inspect(options?: IntrospectionInspectOptions): Promise<IntrospectionSnapshot>;
|
|
378
400
|
}
|
|
379
401
|
|
|
380
|
-
export { type AthenaConditionCastType as A, Backend as B, type
|
|
402
|
+
export { type AthenaConditionCastType as A, Backend as B, type ModelRelationMetadata as C, type DatabaseDef as D, type RowOf as E, type SchemaDef as F, type TenantContextValue as G, type TenantKeyMap as H, type IntrospectionSnapshot as I, type AthenaConditionValue as J, type AthenaConditionArrayValue as K, type AnyModelDef as L, type ModelAt as M, type AthenaConditionOperator as N, type AthenaGatewayHookConfig as O, type AthenaGatewayHookResult as P, type AthenaDeletePayload as Q, type RegistryDef as R, type SchemaIntrospectionProvider as S, type TenantContext as T, type UpdateOf as U, type AthenaFetchPayload as V, type AthenaGatewayResponse as W, type AthenaInsertPayload as X, type AthenaUpdatePayload as Y, type AthenaGatewayEndpointPath as Z, type AthenaGatewayMethod as _, type AthenaGatewayCallOptions as a, type AthenaGatewayConnectionOptions as b, type AthenaGatewayConnectionResult as c, type AthenaGatewayErrorCode as d, type AthenaGatewayErrorDetails as e, type AthenaJsonArray as f, type AthenaJsonObject as g, type AthenaJsonPrimitive as h, type AthenaJsonValue as i, type AthenaRpcCallOptions as j, type AthenaRpcFilter as k, type AthenaRpcFilterOperator as l, type AthenaRpcOrder as m, type AthenaRpcPayload as n, type BackendConfig as o, type BackendType as p, type InsertOf as q, type IntrospectionColumn as r, type IntrospectionInspectOptions as s, type IntrospectionRelation as t, type IntrospectionSchema as u, type IntrospectionTable as v, type IntrospectionTypeKind as w, type ModelDef as x, type ModelMetadata as y, type ModelRelationKind as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as BackendType, I as IntrospectionSnapshot, S as SchemaIntrospectionProvider } from './types-09Q4D86N.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Supported case transformations for generated symbols and path token variants.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as BackendType, I as IntrospectionSnapshot, S as SchemaIntrospectionProvider } from './types-09Q4D86N.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Supported case transformations for generated symbols and path token variants.
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/slugify.ts
|
|
4
|
+
function slugify(input) {
|
|
5
|
+
return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/utils/trim-trailing-slashes.ts
|
|
9
|
+
function trimTrailingSlashes(value) {
|
|
10
|
+
return value.replace(/\/+$/, "");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// src/utils/parse-boolean-flag.ts
|
|
14
|
+
function parseBooleanFlag(rawValue, fallback) {
|
|
15
|
+
if (!rawValue) return fallback;
|
|
16
|
+
const normalized = rawValue.trim().toLowerCase();
|
|
17
|
+
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return fallback;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/utils/hostname.ts
|
|
27
|
+
var LOCAL_IPV4_PATTERN = /^127(?:\.\d{1,3}){3}$/;
|
|
28
|
+
function isLocalHostname(hostname) {
|
|
29
|
+
const normalized = hostname.trim().replace(/\.$/, "").toLowerCase();
|
|
30
|
+
if (!normalized) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
if (normalized === "localhost" || normalized.endsWith(".localhost")) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (normalized === "127.0.0.1" || LOCAL_IPV4_PATTERN.test(normalized) || normalized === "::1" || normalized === "[::1]" || normalized === "0:0:0:0:0:0:0:1") {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/utils/auth-cookies.ts
|
|
43
|
+
var DEFAULT_AUTH_COOKIE_PREFIXES = [
|
|
44
|
+
"athena-auth",
|
|
45
|
+
"__Secure-athena-auth",
|
|
46
|
+
"better-auth",
|
|
47
|
+
"__Secure-better-auth"
|
|
48
|
+
];
|
|
49
|
+
function extractCookieNames(cookieHeader) {
|
|
50
|
+
const names = /* @__PURE__ */ new Set();
|
|
51
|
+
for (const rawCookie of cookieHeader.split(";")) {
|
|
52
|
+
const trimmed = rawCookie.trim();
|
|
53
|
+
if (!trimmed) continue;
|
|
54
|
+
const eqPos = trimmed.indexOf("=");
|
|
55
|
+
const name = (eqPos > -1 ? trimmed.slice(0, eqPos) : trimmed).trim();
|
|
56
|
+
if (name) {
|
|
57
|
+
names.add(name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return Array.from(names);
|
|
61
|
+
}
|
|
62
|
+
function buildCookieDomainCandidates(hostname) {
|
|
63
|
+
const normalized = hostname.trim().replace(/\.$/, "").toLowerCase();
|
|
64
|
+
if (!normalized || isLocalHostname(normalized)) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
const labels = normalized.split(".").filter(Boolean);
|
|
68
|
+
if (labels.length < 2) {
|
|
69
|
+
return [normalized, `.${normalized}`];
|
|
70
|
+
}
|
|
71
|
+
const domains = /* @__PURE__ */ new Set();
|
|
72
|
+
for (let index = 0; index <= labels.length - 2; index += 1) {
|
|
73
|
+
const domain = labels.slice(index).join(".");
|
|
74
|
+
domains.add(domain);
|
|
75
|
+
domains.add(`.${domain}`);
|
|
76
|
+
}
|
|
77
|
+
return Array.from(domains);
|
|
78
|
+
}
|
|
79
|
+
function getCookieStore() {
|
|
80
|
+
const candidate = globalThis.document;
|
|
81
|
+
if (!candidate || typeof candidate.cookie !== "string") {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return candidate;
|
|
85
|
+
}
|
|
86
|
+
function getRuntimeHostname() {
|
|
87
|
+
const fromWindow = globalThis.window?.location?.hostname;
|
|
88
|
+
if (typeof fromWindow === "string") {
|
|
89
|
+
return fromWindow;
|
|
90
|
+
}
|
|
91
|
+
const fromLocation = globalThis.location?.hostname;
|
|
92
|
+
if (typeof fromLocation === "string") {
|
|
93
|
+
return fromLocation;
|
|
94
|
+
}
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
function writeExpiredCookie(cookieStore, name, path, domain) {
|
|
98
|
+
const domainClause = domain ? ` domain=${domain};` : "";
|
|
99
|
+
cookieStore.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; path=${path};${domainClause}`;
|
|
100
|
+
}
|
|
101
|
+
function clearAuthCookies(options = {}) {
|
|
102
|
+
const cookieStore = getCookieStore();
|
|
103
|
+
if (!cookieStore) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
const cookieHeader = options.cookieHeader ?? cookieStore.cookie;
|
|
107
|
+
if (!cookieHeader?.trim()) {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
const prefixes = options.prefixes?.length ? options.prefixes : [...DEFAULT_AUTH_COOKIE_PREFIXES];
|
|
111
|
+
const cookieNames = extractCookieNames(cookieHeader);
|
|
112
|
+
const namesToClear = cookieNames.filter((name) => prefixes.some((prefix) => name.startsWith(prefix)));
|
|
113
|
+
if (namesToClear.length === 0) {
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
const path = options.path?.trim() || "/";
|
|
117
|
+
const hostname = options.hostname ?? getRuntimeHostname();
|
|
118
|
+
const domainCandidates = buildCookieDomainCandidates(hostname);
|
|
119
|
+
for (const name of namesToClear) {
|
|
120
|
+
writeExpiredCookie(cookieStore, name, path);
|
|
121
|
+
for (const domain of domainCandidates) {
|
|
122
|
+
writeExpiredCookie(cookieStore, name, path, domain);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return namesToClear;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/utils/proxy-request-headers.ts
|
|
129
|
+
function proxyRequestHeaders(request) {
|
|
130
|
+
const headers = new Headers(request.headers);
|
|
131
|
+
const requestUrl = new URL(request.url);
|
|
132
|
+
const proto = requestUrl.protocol.replace(/:$/u, "") || "https";
|
|
133
|
+
headers.delete("host");
|
|
134
|
+
headers.set("x-forwarded-host", requestUrl.host);
|
|
135
|
+
headers.set("x-forwarded-proto", proto);
|
|
136
|
+
headers.set("x-forwarded-origin", requestUrl.origin);
|
|
137
|
+
headers.set("x-forwarded-uri", `${requestUrl.pathname}${requestUrl.search}`);
|
|
138
|
+
if (requestUrl.port) {
|
|
139
|
+
headers.set("x-forwarded-port", requestUrl.port);
|
|
140
|
+
} else {
|
|
141
|
+
headers.delete("x-forwarded-port");
|
|
142
|
+
}
|
|
143
|
+
return headers;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
exports.clearAuthCookies = clearAuthCookies;
|
|
147
|
+
exports.isLocalHostname = isLocalHostname;
|
|
148
|
+
exports.parseBooleanFlag = parseBooleanFlag;
|
|
149
|
+
exports.proxyRequestHeaders = proxyRequestHeaders;
|
|
150
|
+
exports.slugify = slugify;
|
|
151
|
+
exports.trimTrailingSlashes = trimTrailingSlashes;
|
|
152
|
+
//# sourceMappingURL=utils.cjs.map
|
|
153
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/slugify.ts","../src/utils/trim-trailing-slashes.ts","../src/utils/parse-boolean-flag.ts","../src/utils/hostname.ts","../src/utils/auth-cookies.ts","../src/utils/proxy-request-headers.ts"],"names":[],"mappings":";;;AAAO,SAAS,QAAQ,KAAA,EAAuB;AAC7C,EAAA,OAAO,KAAA,CACJ,WAAA,EAAY,CACZ,OAAA,CAAQ,aAAA,EAAe,GAAG,CAAA,CAC1B,OAAA,CAAQ,UAAA,EAAY,EAAE,CAAA,CACtB,KAAA,CAAM,GAAG,EAAE,CAAA;AAChB;;;ACNO,SAAS,oBAAoB,KAAA,EA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,KAAA,EAAO,EAAE,CAAA,IAAK,OAAA;AAKxD,EAAA,OAAA,CAAQ,OAAO,MAAM,CAAA;AACrB,EAAA,OAAA,CAAQ,GAAA,CAAI,kBAAA,EAAoB,UAAA,CAAW,IAAI,CAAA;AAC/C,EAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,KAAK,CAAA;AACtC,EAAA,OAAA,CAAQ,GAAA,CAAI,oBAAA,EAAsB,UAAA,CAAW,MAAM,CAAA;AACnD,EAAA,OAAA,CAAQ,GAAA,CAAI,mBAAmB,CAAA,EAAG,UAAA,CAAW,QAAQ,CAAA,EAAG,UAAA,CAAW,MAAM,CAAA,CAAE,CAAA;AAE3E,EAAA,IAAI,WAAW,IAAA,EAAM;AACnB,IAAA,OAAA,CAAQ,GAAA,CAAI,kBAAA,EAAoB,UAAA,CAAW,IAAI,CAAA;AAAA,EACjD,CAAA,MAAO;AACL,IAAA,OAAA,CAAQ,OAAO,kBAAkB,CAAA;AAAA,EACnC;AAEA,EAAA,OAAO,OAAA;AACT","file":"utils.cjs","sourcesContent":["export function slugify(input: string): string {\n return input\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 64)\n}\n","export function trimTrailingSlashes(value: string): string {\n return value.replace(/\\/+$/, '')\n}\n","export function parseBooleanFlag(\n rawValue: string | undefined,\n fallback: boolean,\n): boolean {\n if (!rawValue) return fallback\n\n const normalized = rawValue.trim().toLowerCase()\n\n if (\n normalized === '1' ||\n normalized === 'true' ||\n normalized === 'yes' ||\n normalized === 'on'\n ) {\n return true\n }\n\n if (\n normalized === '0' ||\n normalized === 'false' ||\n normalized === 'no' ||\n normalized === 'off'\n ) {\n return false\n }\n\n return fallback\n}\n","const LOCAL_IPV4_PATTERN = /^127(?:\\.\\d{1,3}){3}$/\n\nexport function isLocalHostname(hostname: string): boolean {\n const normalized = hostname.trim().replace(/\\.$/, '').toLowerCase()\n if (!normalized) {\n return false\n }\n\n if (normalized === 'localhost' || normalized.endsWith('.localhost')) {\n return true\n }\n\n if (\n normalized === '127.0.0.1' ||\n LOCAL_IPV4_PATTERN.test(normalized) ||\n normalized === '::1' ||\n normalized === '[::1]' ||\n normalized === '0:0:0:0:0:0:0:1'\n ) {\n return true\n }\n\n return false\n}\n","import { isLocalHostname } from './hostname.ts'\n\nconst DEFAULT_AUTH_COOKIE_PREFIXES = [\n 'athena-auth',\n '__Secure-athena-auth',\n 'better-auth',\n '__Secure-better-auth',\n] as const\n\nexport interface ClearAuthCookiesOptions {\n prefixes?: string[]\n hostname?: string\n path?: string\n cookieHeader?: string\n}\n\ninterface BrowserCookieStore {\n cookie: string\n}\n\nfunction extractCookieNames(cookieHeader: string): string[] {\n const names = new Set<string>()\n for (const rawCookie of cookieHeader.split(';')) {\n const trimmed = rawCookie.trim()\n if (!trimmed) continue\n\n const eqPos = trimmed.indexOf('=')\n const name = (eqPos > -1 ? trimmed.slice(0, eqPos) : trimmed).trim()\n if (name) {\n names.add(name)\n }\n }\n return Array.from(names)\n}\n\nfunction buildCookieDomainCandidates(hostname: string): string[] {\n const normalized = hostname.trim().replace(/\\.$/, '').toLowerCase()\n if (!normalized || isLocalHostname(normalized)) {\n return []\n }\n\n const labels = normalized.split('.').filter(Boolean)\n if (labels.length < 2) {\n return [normalized, `.${normalized}`]\n }\n\n const domains = new Set<string>()\n for (let index = 0; index <= labels.length - 2; index += 1) {\n const domain = labels.slice(index).join('.')\n domains.add(domain)\n domains.add(`.${domain}`)\n }\n return Array.from(domains)\n}\n\nfunction getCookieStore(): BrowserCookieStore | null {\n const candidate = (globalThis as { document?: BrowserCookieStore }).document\n if (!candidate || typeof candidate.cookie !== 'string') {\n return null\n }\n return candidate\n}\n\nfunction getRuntimeHostname(): string {\n const fromWindow = (\n globalThis as { window?: { location?: { hostname?: string } } }\n ).window?.location?.hostname\n if (typeof fromWindow === 'string') {\n return fromWindow\n }\n\n const fromLocation = (\n globalThis as { location?: { hostname?: string } }\n ).location?.hostname\n if (typeof fromLocation === 'string') {\n return fromLocation\n }\n\n return ''\n}\n\nfunction writeExpiredCookie(\n cookieStore: BrowserCookieStore,\n name: string,\n path: string,\n domain?: string,\n) {\n const domainClause = domain ? ` domain=${domain};` : ''\n cookieStore.cookie =\n `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; path=${path};${domainClause}`\n}\n\n/**\n * Clears Athena/Better Auth browser cookies by prefix.\n * Returns the cookie names that matched and were targeted for deletion.\n */\nexport function clearAuthCookies(options: ClearAuthCookiesOptions = {}): string[] {\n const cookieStore = getCookieStore()\n if (!cookieStore) {\n return []\n }\n\n const cookieHeader = options.cookieHeader ?? cookieStore.cookie\n if (!cookieHeader?.trim()) {\n return []\n }\n\n const prefixes = options.prefixes?.length ? options.prefixes : [...DEFAULT_AUTH_COOKIE_PREFIXES]\n const cookieNames = extractCookieNames(cookieHeader)\n const namesToClear = cookieNames.filter(name => prefixes.some(prefix => name.startsWith(prefix)))\n if (namesToClear.length === 0) {\n return []\n }\n\n const path = options.path?.trim() || '/'\n const hostname = options.hostname ?? getRuntimeHostname()\n const domainCandidates = buildCookieDomainCandidates(hostname)\n\n for (const name of namesToClear) {\n writeExpiredCookie(cookieStore, name, path)\n for (const domain of domainCandidates) {\n writeExpiredCookie(cookieStore, name, path, domain)\n }\n }\n\n return namesToClear\n}\n","export function proxyRequestHeaders(request: Request): Headers {\n const headers = new Headers(request.headers)\n const requestUrl = new URL(request.url)\n const proto = requestUrl.protocol.replace(/:$/u, '') || 'https'\n\n // Let fetch set the upstream Host header, but keep the original public app\n // origin available for auth servers that need to validate or generate links\n // for Vercel preview domains behind this proxy.\n headers.delete('host')\n headers.set('x-forwarded-host', requestUrl.host)\n headers.set('x-forwarded-proto', proto)\n headers.set('x-forwarded-origin', requestUrl.origin)\n headers.set('x-forwarded-uri', `${requestUrl.pathname}${requestUrl.search}`)\n\n if (requestUrl.port) {\n headers.set('x-forwarded-port', requestUrl.port)\n } else {\n headers.delete('x-forwarded-port')\n }\n\n return headers\n}\n"]}
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare function slugify(input: string): string;
|
|
2
|
+
|
|
3
|
+
declare function trimTrailingSlashes(value: string): string;
|
|
4
|
+
|
|
5
|
+
declare function parseBooleanFlag(rawValue: string | undefined, fallback: boolean): boolean;
|
|
6
|
+
|
|
7
|
+
declare function isLocalHostname(hostname: string): boolean;
|
|
8
|
+
|
|
9
|
+
interface ClearAuthCookiesOptions {
|
|
10
|
+
prefixes?: string[];
|
|
11
|
+
hostname?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
cookieHeader?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Clears Athena/Better Auth browser cookies by prefix.
|
|
17
|
+
* Returns the cookie names that matched and were targeted for deletion.
|
|
18
|
+
*/
|
|
19
|
+
declare function clearAuthCookies(options?: ClearAuthCookiesOptions): string[];
|
|
20
|
+
|
|
21
|
+
declare function proxyRequestHeaders(request: Request): Headers;
|
|
22
|
+
|
|
23
|
+
export { type ClearAuthCookiesOptions, clearAuthCookies, isLocalHostname, parseBooleanFlag, proxyRequestHeaders, slugify, trimTrailingSlashes };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare function slugify(input: string): string;
|
|
2
|
+
|
|
3
|
+
declare function trimTrailingSlashes(value: string): string;
|
|
4
|
+
|
|
5
|
+
declare function parseBooleanFlag(rawValue: string | undefined, fallback: boolean): boolean;
|
|
6
|
+
|
|
7
|
+
declare function isLocalHostname(hostname: string): boolean;
|
|
8
|
+
|
|
9
|
+
interface ClearAuthCookiesOptions {
|
|
10
|
+
prefixes?: string[];
|
|
11
|
+
hostname?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
cookieHeader?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Clears Athena/Better Auth browser cookies by prefix.
|
|
17
|
+
* Returns the cookie names that matched and were targeted for deletion.
|
|
18
|
+
*/
|
|
19
|
+
declare function clearAuthCookies(options?: ClearAuthCookiesOptions): string[];
|
|
20
|
+
|
|
21
|
+
declare function proxyRequestHeaders(request: Request): Headers;
|
|
22
|
+
|
|
23
|
+
export { type ClearAuthCookiesOptions, clearAuthCookies, isLocalHostname, parseBooleanFlag, proxyRequestHeaders, slugify, trimTrailingSlashes };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// src/utils/slugify.ts
|
|
2
|
+
function slugify(input) {
|
|
3
|
+
return input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/utils/trim-trailing-slashes.ts
|
|
7
|
+
function trimTrailingSlashes(value) {
|
|
8
|
+
return value.replace(/\/+$/, "");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/utils/parse-boolean-flag.ts
|
|
12
|
+
function parseBooleanFlag(rawValue, fallback) {
|
|
13
|
+
if (!rawValue) return fallback;
|
|
14
|
+
const normalized = rawValue.trim().toLowerCase();
|
|
15
|
+
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return fallback;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/utils/hostname.ts
|
|
25
|
+
var LOCAL_IPV4_PATTERN = /^127(?:\.\d{1,3}){3}$/;
|
|
26
|
+
function isLocalHostname(hostname) {
|
|
27
|
+
const normalized = hostname.trim().replace(/\.$/, "").toLowerCase();
|
|
28
|
+
if (!normalized) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (normalized === "localhost" || normalized.endsWith(".localhost")) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (normalized === "127.0.0.1" || LOCAL_IPV4_PATTERN.test(normalized) || normalized === "::1" || normalized === "[::1]" || normalized === "0:0:0:0:0:0:0:1") {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/utils/auth-cookies.ts
|
|
41
|
+
var DEFAULT_AUTH_COOKIE_PREFIXES = [
|
|
42
|
+
"athena-auth",
|
|
43
|
+
"__Secure-athena-auth",
|
|
44
|
+
"better-auth",
|
|
45
|
+
"__Secure-better-auth"
|
|
46
|
+
];
|
|
47
|
+
function extractCookieNames(cookieHeader) {
|
|
48
|
+
const names = /* @__PURE__ */ new Set();
|
|
49
|
+
for (const rawCookie of cookieHeader.split(";")) {
|
|
50
|
+
const trimmed = rawCookie.trim();
|
|
51
|
+
if (!trimmed) continue;
|
|
52
|
+
const eqPos = trimmed.indexOf("=");
|
|
53
|
+
const name = (eqPos > -1 ? trimmed.slice(0, eqPos) : trimmed).trim();
|
|
54
|
+
if (name) {
|
|
55
|
+
names.add(name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return Array.from(names);
|
|
59
|
+
}
|
|
60
|
+
function buildCookieDomainCandidates(hostname) {
|
|
61
|
+
const normalized = hostname.trim().replace(/\.$/, "").toLowerCase();
|
|
62
|
+
if (!normalized || isLocalHostname(normalized)) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
const labels = normalized.split(".").filter(Boolean);
|
|
66
|
+
if (labels.length < 2) {
|
|
67
|
+
return [normalized, `.${normalized}`];
|
|
68
|
+
}
|
|
69
|
+
const domains = /* @__PURE__ */ new Set();
|
|
70
|
+
for (let index = 0; index <= labels.length - 2; index += 1) {
|
|
71
|
+
const domain = labels.slice(index).join(".");
|
|
72
|
+
domains.add(domain);
|
|
73
|
+
domains.add(`.${domain}`);
|
|
74
|
+
}
|
|
75
|
+
return Array.from(domains);
|
|
76
|
+
}
|
|
77
|
+
function getCookieStore() {
|
|
78
|
+
const candidate = globalThis.document;
|
|
79
|
+
if (!candidate || typeof candidate.cookie !== "string") {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return candidate;
|
|
83
|
+
}
|
|
84
|
+
function getRuntimeHostname() {
|
|
85
|
+
const fromWindow = globalThis.window?.location?.hostname;
|
|
86
|
+
if (typeof fromWindow === "string") {
|
|
87
|
+
return fromWindow;
|
|
88
|
+
}
|
|
89
|
+
const fromLocation = globalThis.location?.hostname;
|
|
90
|
+
if (typeof fromLocation === "string") {
|
|
91
|
+
return fromLocation;
|
|
92
|
+
}
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
function writeExpiredCookie(cookieStore, name, path, domain) {
|
|
96
|
+
const domainClause = domain ? ` domain=${domain};` : "";
|
|
97
|
+
cookieStore.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; path=${path};${domainClause}`;
|
|
98
|
+
}
|
|
99
|
+
function clearAuthCookies(options = {}) {
|
|
100
|
+
const cookieStore = getCookieStore();
|
|
101
|
+
if (!cookieStore) {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
const cookieHeader = options.cookieHeader ?? cookieStore.cookie;
|
|
105
|
+
if (!cookieHeader?.trim()) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const prefixes = options.prefixes?.length ? options.prefixes : [...DEFAULT_AUTH_COOKIE_PREFIXES];
|
|
109
|
+
const cookieNames = extractCookieNames(cookieHeader);
|
|
110
|
+
const namesToClear = cookieNames.filter((name) => prefixes.some((prefix) => name.startsWith(prefix)));
|
|
111
|
+
if (namesToClear.length === 0) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
const path = options.path?.trim() || "/";
|
|
115
|
+
const hostname = options.hostname ?? getRuntimeHostname();
|
|
116
|
+
const domainCandidates = buildCookieDomainCandidates(hostname);
|
|
117
|
+
for (const name of namesToClear) {
|
|
118
|
+
writeExpiredCookie(cookieStore, name, path);
|
|
119
|
+
for (const domain of domainCandidates) {
|
|
120
|
+
writeExpiredCookie(cookieStore, name, path, domain);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return namesToClear;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/utils/proxy-request-headers.ts
|
|
127
|
+
function proxyRequestHeaders(request) {
|
|
128
|
+
const headers = new Headers(request.headers);
|
|
129
|
+
const requestUrl = new URL(request.url);
|
|
130
|
+
const proto = requestUrl.protocol.replace(/:$/u, "") || "https";
|
|
131
|
+
headers.delete("host");
|
|
132
|
+
headers.set("x-forwarded-host", requestUrl.host);
|
|
133
|
+
headers.set("x-forwarded-proto", proto);
|
|
134
|
+
headers.set("x-forwarded-origin", requestUrl.origin);
|
|
135
|
+
headers.set("x-forwarded-uri", `${requestUrl.pathname}${requestUrl.search}`);
|
|
136
|
+
if (requestUrl.port) {
|
|
137
|
+
headers.set("x-forwarded-port", requestUrl.port);
|
|
138
|
+
} else {
|
|
139
|
+
headers.delete("x-forwarded-port");
|
|
140
|
+
}
|
|
141
|
+
return headers;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { clearAuthCookies, isLocalHostname, parseBooleanFlag, proxyRequestHeaders, slugify, trimTrailingSlashes };
|
|
145
|
+
//# sourceMappingURL=utils.js.map
|
|
146
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/slugify.ts","../src/utils/trim-trailing-slashes.ts","../src/utils/parse-boolean-flag.ts","../src/utils/hostname.ts","../src/utils/auth-cookies.ts","../src/utils/proxy-request-headers.ts"],"names":[],"mappings":";AAAO,SAAS,QAAQ,KAAA,EAAuB;AAC7C,EAAA,OAAO,KAAA,CACJ,WAAA,EAAY,CACZ,OAAA,CAAQ,aAAA,EAAe,GAAG,CAAA,CAC1B,OAAA,CAAQ,UAAA,EAAY,EAAE,CAAA,CACtB,KAAA,CAAM,GAAG,EAAE,CA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AAQ,UAAA,CAAW,QAAA,CAAS,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA,IAAK,OAAA;AAKxD,EAAA,OAAA,CAAQ,OAAO,MAAM,CAAA;AACrB,EAAA,OAAA,CAAQ,GAAA,CAAI,kBAAA,EAAoB,UAAA,CAAW,IAAI,CAAA;AAC/C,EAAA,OAAA,CAAQ,GAAA,CAAI,qBAAqB,KAAK,CAAA;AACtC,EAAA,OAAA,CAAQ,GAAA,CAAI,oBAAA,EAAsB,UAAA,CAAW,MAAM,CAAA;AACnD,EAAA,OAAA,CAAQ,GAAA,CAAI,mBAAmB,CAAA,EAAG,UAAA,CAAW,QAAQ,CAAA,EAAG,UAAA,CAAW,MAAM,CAAA,CAAE,CAAA;AAE3E,EAAA,IAAI,WAAW,IAAA,EAAM;AACnB,IAAA,OAAA,CAAQ,GAAA,CAAI,kBAAA,EAAoB,UAAA,CAAW,IAAI,CAAA;AAAA,EACjD,CAAA,MAAO;AACL,IAAA,OAAA,CAAQ,OAAO,kBAAkB,CAAA;AAAA,EACnC;AAEA,EAAA,OAAO,OAAA;AACT","file":"utils.js","sourcesContent":["export function slugify(input: string): string {\n return input\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, 64)\n}\n","export function trimTrailingSlashes(value: string): string {\n return value.replace(/\\/+$/, '')\n}\n","export function parseBooleanFlag(\n rawValue: string | undefined,\n fallback: boolean,\n): boolean {\n if (!rawValue) return fallback\n\n const normalized = rawValue.trim().toLowerCase()\n\n if (\n normalized === '1' ||\n normalized === 'true' ||\n normalized === 'yes' ||\n normalized === 'on'\n ) {\n return true\n }\n\n if (\n normalized === '0' ||\n normalized === 'false' ||\n normalized === 'no' ||\n normalized === 'off'\n ) {\n return false\n }\n\n return fallback\n}\n","const LOCAL_IPV4_PATTERN = /^127(?:\\.\\d{1,3}){3}$/\n\nexport function isLocalHostname(hostname: string): boolean {\n const normalized = hostname.trim().replace(/\\.$/, '').toLowerCase()\n if (!normalized) {\n return false\n }\n\n if (normalized === 'localhost' || normalized.endsWith('.localhost')) {\n return true\n }\n\n if (\n normalized === '127.0.0.1' ||\n LOCAL_IPV4_PATTERN.test(normalized) ||\n normalized === '::1' ||\n normalized === '[::1]' ||\n normalized === '0:0:0:0:0:0:0:1'\n ) {\n return true\n }\n\n return false\n}\n","import { isLocalHostname } from './hostname.ts'\n\nconst DEFAULT_AUTH_COOKIE_PREFIXES = [\n 'athena-auth',\n '__Secure-athena-auth',\n 'better-auth',\n '__Secure-better-auth',\n] as const\n\nexport interface ClearAuthCookiesOptions {\n prefixes?: string[]\n hostname?: string\n path?: string\n cookieHeader?: string\n}\n\ninterface BrowserCookieStore {\n cookie: string\n}\n\nfunction extractCookieNames(cookieHeader: string): string[] {\n const names = new Set<string>()\n for (const rawCookie of cookieHeader.split(';')) {\n const trimmed = rawCookie.trim()\n if (!trimmed) continue\n\n const eqPos = trimmed.indexOf('=')\n const name = (eqPos > -1 ? trimmed.slice(0, eqPos) : trimmed).trim()\n if (name) {\n names.add(name)\n }\n }\n return Array.from(names)\n}\n\nfunction buildCookieDomainCandidates(hostname: string): string[] {\n const normalized = hostname.trim().replace(/\\.$/, '').toLowerCase()\n if (!normalized || isLocalHostname(normalized)) {\n return []\n }\n\n const labels = normalized.split('.').filter(Boolean)\n if (labels.length < 2) {\n return [normalized, `.${normalized}`]\n }\n\n const domains = new Set<string>()\n for (let index = 0; index <= labels.length - 2; index += 1) {\n const domain = labels.slice(index).join('.')\n domains.add(domain)\n domains.add(`.${domain}`)\n }\n return Array.from(domains)\n}\n\nfunction getCookieStore(): BrowserCookieStore | null {\n const candidate = (globalThis as { document?: BrowserCookieStore }).document\n if (!candidate || typeof candidate.cookie !== 'string') {\n return null\n }\n return candidate\n}\n\nfunction getRuntimeHostname(): string {\n const fromWindow = (\n globalThis as { window?: { location?: { hostname?: string } } }\n ).window?.location?.hostname\n if (typeof fromWindow === 'string') {\n return fromWindow\n }\n\n const fromLocation = (\n globalThis as { location?: { hostname?: string } }\n ).location?.hostname\n if (typeof fromLocation === 'string') {\n return fromLocation\n }\n\n return ''\n}\n\nfunction writeExpiredCookie(\n cookieStore: BrowserCookieStore,\n name: string,\n path: string,\n domain?: string,\n) {\n const domainClause = domain ? ` domain=${domain};` : ''\n cookieStore.cookie =\n `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; path=${path};${domainClause}`\n}\n\n/**\n * Clears Athena/Better Auth browser cookies by prefix.\n * Returns the cookie names that matched and were targeted for deletion.\n */\nexport function clearAuthCookies(options: ClearAuthCookiesOptions = {}): string[] {\n const cookieStore = getCookieStore()\n if (!cookieStore) {\n return []\n }\n\n const cookieHeader = options.cookieHeader ?? cookieStore.cookie\n if (!cookieHeader?.trim()) {\n return []\n }\n\n const prefixes = options.prefixes?.length ? options.prefixes : [...DEFAULT_AUTH_COOKIE_PREFIXES]\n const cookieNames = extractCookieNames(cookieHeader)\n const namesToClear = cookieNames.filter(name => prefixes.some(prefix => name.startsWith(prefix)))\n if (namesToClear.length === 0) {\n return []\n }\n\n const path = options.path?.trim() || '/'\n const hostname = options.hostname ?? getRuntimeHostname()\n const domainCandidates = buildCookieDomainCandidates(hostname)\n\n for (const name of namesToClear) {\n writeExpiredCookie(cookieStore, name, path)\n for (const domain of domainCandidates) {\n writeExpiredCookie(cookieStore, name, path, domain)\n }\n }\n\n return namesToClear\n}\n","export function proxyRequestHeaders(request: Request): Headers {\n const headers = new Headers(request.headers)\n const requestUrl = new URL(request.url)\n const proto = requestUrl.protocol.replace(/:$/u, '') || 'https'\n\n // Let fetch set the upstream Host header, but keep the original public app\n // origin available for auth servers that need to validate or generate links\n // for Vercel preview domains behind this proxy.\n headers.delete('host')\n headers.set('x-forwarded-host', requestUrl.host)\n headers.set('x-forwarded-proto', proto)\n headers.set('x-forwarded-origin', requestUrl.origin)\n headers.set('x-forwarded-uri', `${requestUrl.pathname}${requestUrl.search}`)\n\n if (requestUrl.port) {\n headers.set('x-forwarded-port', requestUrl.port)\n } else {\n headers.delete('x-forwarded-port')\n }\n\n return headers\n}\n"]}
|