@xylex-group/athena 3.6.0 → 3.6.1
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/dist/next/client.cjs +8379 -10061
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.cts +28 -0
- package/dist/next/client.d.ts +28 -0
- package/dist/next/client.js +8379 -10061
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +9662 -11378
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.d.cts +274 -0
- package/dist/next/server.d.ts +274 -0
- package/dist/next/server.js +9662 -11378
- package/dist/next/server.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { ad as AthenaAuthSessionResponse } from '../types-BVKpQmfY.cjs';
|
|
2
|
+
import { r as AthenaClientModelsInput } from '../types-D5dj1v5Z.cjs';
|
|
3
|
+
import { aA as AthenaRequestContext, ai as AthenaClientConfig, ag as AthenaClient } from '../v3-client-DP-qg82X.cjs';
|
|
4
|
+
import { OrganizationLike } from '../organization.cjs';
|
|
5
|
+
export { ActiveOrganizationSessionLike, EnsureActiveOrganizationOptions, EnsureActiveOrganizationResult, ensureActiveOrganization } from '../organization.cjs';
|
|
6
|
+
import { g as AthenaAuthSessionBridgeOptions, h as AthenaAuthSessionBridgePathOptions } from '../payload-DWI1rw-e.cjs';
|
|
7
|
+
export { A as ATHENA_AUTH_SESSION_BRIDGE_ROUTE, a as ATHENA_AUTH_SESSION_COOKIE_NAME, b as ATHENA_AUTH_SESSION_COOKIE_NAMES, c as AthenaAuthSessionBridgeClientOptions, d as AthenaAuthSessionBridgePayload, e as AthenaAuthSessionBridgeSource, f as clearAthenaAuthSessionOnAppHost, p as persistAthenaAuthSessionOnAppHost, r as resolveSessionBridgePayload } from '../payload-DWI1rw-e.cjs';
|
|
8
|
+
export { S as SESSION_COOKIE_PATTERNS, h as hasAuthSessionCookie } from '../session-cookie-detection-BqOp9mO6.cjs';
|
|
9
|
+
export { A as ATHENA_AUTH_DISABLE_COOKIE_CACHE_QUERY_PARAM, a as ATHENA_AUTH_DISABLE_COOKIE_CACHE_QUERY_VALUE, b as ATHENA_AUTH_GET_SESSION_ABSOLUTE_PATH, c as ATHENA_AUTH_GET_SESSION_PATH, d as ATHENA_AUTH_PATH, e as ATHENA_AUTH_UPSTREAM_ENV_KEYS, f as ATHENA_AUTH_UPSTREAM_URL_ENV_NAMES, g as ATHENA_AUTH_VERIFY_EMAIL_PATH, h as ATHENA_SESSION_DATA_HEADER, i as AUTH_SESSION_PATH, j as AthenaAuthClientBaseUrlOptions, k as AthenaAuthUpstreamEnv, l as AthenaAuthUpstreamEnvKey, D as DEFAULT_ATHENA_AUTH_ORIGIN, m as DEFAULT_ATHENA_AUTH_UPSTREAM_URL, n as DISABLE_COOKIE_CACHE_QUERY_PARAM, o as DISABLE_COOKIE_CACHE_QUERY_VALUE, E as EnvLike, L as LOCAL_DEV_ORIGIN, S as SESSION_DATA_HEADER, p as createFreshSessionLookupUrl, q as isAbsoluteUrl, r as normalizeAthenaAuthBaseUrl, s as readAthenaAuthUpstreamUrlFromEnv, t as resolveAthenaAuthClientBaseUrl, u as resolveAthenaAuthRequestUrl, v as resolveAthenaAuthUpstreamUrl, w as resolveEmailVerificationCallbackUrl } from '../athena-auth-url-C1FbVmN6.cjs';
|
|
10
|
+
export { A as ATHENA_AUTH_COOKIE_PREFIXES, a as AUTHENTICATED_REDIRECT_MODE_SET, b as AUTHENTICATED_REDIRECT_VIEW_SET, c as AUTH_DEFAULT_VIEW, d as AUTH_MODE_REDIRECTS, e as AUTH_MODE_SET, f as AUTH_ROUTES, g as AUTH_TWO_FACTOR_SEGMENT, h as AUTH_VIEW_BY_SEGMENT, i as AthenaRequestHeaderOverrideFields, j as AthenaRequestHeaderProfile, k as AuthMode, l as AuthModeRedirects, m as AuthRoutes, n as AuthView, B as BuildAthenaRequestHeadersInput, C as ClearAuthCookiesOptions, R as ResolvedRequestHeaderOverrides, E as applyAthenaApiKeyHeaders, F as applyAthenaAuthContextHeaders, G as applyAthenaPgUriHeaders, o as asNonEmptyString, p as asString, q as buildAthenaGatewayHeaders, r as buildAthenaRequestHeaders, H as buildServiceRequestHeaders, s as clearAuthCookies, t as createAuthModeRedirects, u as createAuthRoutes, I as hasHeaderIgnoreCase, v as isAuthMode, w as readTrimmedString, x as resolveAuthModeRedirect, y as resolveAuthViewFromSegment, J as resolveHeaderValue, K as resolveRequestHeaderOverrides, z as shouldRedirectAuthenticatedAuthMode, D as shouldRedirectAuthenticatedAuthView } from '../athena-request-headers-BnFN2mbd.cjs';
|
|
11
|
+
export { G as GetOriginFromHeadersOptions, g as getOriginFromHeaders, i as isDynamicServerUsageError, p as proxyRequestHeaders, r as readEnv, a as requireEnv } from '../proxy-request-headers-pIBSn1Fw.cjs';
|
|
12
|
+
export { A as ATHENA_TABLE_SCHEMA_ROUTE, a as AthenaTableCatalogColumn, b as AthenaTableCatalogQueryClient, c as AthenaTableCatalogRelation, d as AthenaTableCatalogResponse, e as AthenaTableCatalogTable, f as AthenaTableSchemaConfig, g as AthenaTableSchemaHandlerOptions, h as AthenaTableShowcaseConfig, F as FetchAthenaTableCatalogOptions, T as TableCatalogColumn, i as TableCatalogRelation, j as TableCatalogResponse, k as TableCatalogTable, l as buildAthenaTableCatalogQueries, m as createAthenaTableSchemaHandlers, n as fetchAthenaTableCatalog, o as fetchTableCatalog, p as handleAthenaTableSchemaPost, q as hasAthenaTableSchemaCredentials, r as isAthenaTableSchemaConfig, s as parseAthenaTableSchemaScope } from '../schema-handlers-Dr8h9Jg-.cjs';
|
|
13
|
+
import '../types-B2RZPivM.cjs';
|
|
14
|
+
import '../module-C_ab-MM1.cjs';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Handle bridge `POST` — set an httpOnly session cookie from JSON body.
|
|
18
|
+
*
|
|
19
|
+
* Expected body: `{ "token": string, "expiresAt"?: string }`.
|
|
20
|
+
*
|
|
21
|
+
* @param request - Incoming request (JSON body)
|
|
22
|
+
* @param options - Cookie / route configuration
|
|
23
|
+
* @returns `200` on success, `400` when token is missing
|
|
24
|
+
*/
|
|
25
|
+
declare function handleAthenaAuthSessionBridgePost(request: Request, options?: AthenaAuthSessionBridgeOptions): Promise<Response>;
|
|
26
|
+
/**
|
|
27
|
+
* Handle bridge `DELETE` — clear bridged session cookie name variants.
|
|
28
|
+
*
|
|
29
|
+
* @param request - Incoming request (used for Secure detection)
|
|
30
|
+
* @param options - Cookie / route configuration
|
|
31
|
+
* @returns `200` with clear `Set-Cookie` headers
|
|
32
|
+
*/
|
|
33
|
+
declare function handleAthenaAuthSessionBridgeDelete(request: Request, options?: AthenaAuthSessionBridgeOptions): Response;
|
|
34
|
+
/**
|
|
35
|
+
* Create dedicated App Router handlers for the session bridge.
|
|
36
|
+
*
|
|
37
|
+
* Drop into a route file with no additional wiring:
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // app/api/athena-auth/session/route.ts
|
|
42
|
+
* import { createAthenaAuthSessionBridgeHandlers } from '@xylex-group/athena/next/server'
|
|
43
|
+
*
|
|
44
|
+
* export const { POST, DELETE } = createAthenaAuthSessionBridgeHandlers()
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param options - Optional cookie name, path, SameSite, Secure overrides
|
|
48
|
+
* @returns Object with `POST` and `DELETE` route handlers
|
|
49
|
+
*/
|
|
50
|
+
declare function createAthenaAuthSessionBridgeHandlers(options?: AthenaAuthSessionBridgeOptions): {
|
|
51
|
+
POST: (request: Request) => Promise<Response>;
|
|
52
|
+
DELETE: (request: Request) => Response;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Whether this request should be handled as a session bridge call.
|
|
56
|
+
*
|
|
57
|
+
* Returns true when:
|
|
58
|
+
* - the pathname equals the configured `route`, or
|
|
59
|
+
* - the final path segment is listed in `matchPaths` (default `session`)
|
|
60
|
+
*
|
|
61
|
+
* @param request - Incoming request
|
|
62
|
+
* @param options - Route + matchPaths configuration
|
|
63
|
+
*/
|
|
64
|
+
declare function isAthenaAuthSessionBridgePath(request: Request, options?: AthenaAuthSessionBridgePathOptions): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Create catch-all / `[path]` handlers that only service session-bridge paths.
|
|
67
|
+
*
|
|
68
|
+
* Non-matching paths return `404` with `{ error: 'Not found' }` so you can
|
|
69
|
+
* mount under `/api/auth/[...path]` without implementing a full auth proxy.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* // app/api/auth/[...path]/route.ts
|
|
74
|
+
* import { createAthenaAuthSessionBridgePathHandlers } from '@xylex-group/athena/next/server'
|
|
75
|
+
*
|
|
76
|
+
* export const { POST, DELETE } = createAthenaAuthSessionBridgePathHandlers({
|
|
77
|
+
* route: '/api/auth/session',
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @param options - Bridge options plus `matchPaths`
|
|
82
|
+
* @returns Object with `POST` and `DELETE` route handlers
|
|
83
|
+
*/
|
|
84
|
+
declare function createAthenaAuthSessionBridgePathHandlers(options?: AthenaAuthSessionBridgePathOptions): {
|
|
85
|
+
POST: (request: Request) => Promise<Response>;
|
|
86
|
+
DELETE: (request: Request) => Response;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
interface AthenaRequestHeadersBag {
|
|
90
|
+
get(name: string): string | null;
|
|
91
|
+
}
|
|
92
|
+
interface AthenaRequestCookiesBag {
|
|
93
|
+
getAll(): Array<{
|
|
94
|
+
name: string;
|
|
95
|
+
value: string;
|
|
96
|
+
}>;
|
|
97
|
+
}
|
|
98
|
+
type AthenaRequestHeadersInput = AthenaRequestHeadersBag | Record<string, string | null | undefined>;
|
|
99
|
+
type AthenaRequestCookiesInput = AthenaRequestCookiesBag | string | null | undefined;
|
|
100
|
+
interface AthenaServerRequestOptions {
|
|
101
|
+
requestHeaders?: AthenaRequestHeadersInput;
|
|
102
|
+
requestCookies?: AthenaRequestCookiesInput;
|
|
103
|
+
forceNoCache?: boolean;
|
|
104
|
+
headers?: Record<string, string>;
|
|
105
|
+
}
|
|
106
|
+
declare function resolveNextRequestContext(options?: AthenaServerRequestOptions): Promise<AthenaRequestContext>;
|
|
107
|
+
|
|
108
|
+
interface ResolveActiveOrganizationIdArgs {
|
|
109
|
+
rawActiveOrganizationId: string | null;
|
|
110
|
+
session: AthenaAuthSessionResponse;
|
|
111
|
+
userId: string;
|
|
112
|
+
}
|
|
113
|
+
interface GetServerSessionEnsureActiveOptions<TOrganization extends OrganizationLike = OrganizationLike> {
|
|
114
|
+
listOrganizations: () => Promise<readonly TOrganization[]>;
|
|
115
|
+
onError?: (error: unknown) => void;
|
|
116
|
+
selectOrganizationId?: (organizations: readonly TOrganization[]) => string | null;
|
|
117
|
+
setActiveOrganization: (organizationId: string) => Promise<unknown>;
|
|
118
|
+
}
|
|
119
|
+
interface GetServerSessionOptions extends AthenaServerRequestOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Absolute get-session URL. When omitted, built from `appOrigin` via
|
|
122
|
+
* {@link createFreshSessionLookupUrl}.
|
|
123
|
+
*/
|
|
124
|
+
authSessionUrl?: string | URL;
|
|
125
|
+
/**
|
|
126
|
+
* App origin used to build `/api/auth/get-session?disableCookieCache=true`
|
|
127
|
+
* when `authSessionUrl` is not set.
|
|
128
|
+
*/
|
|
129
|
+
appOrigin?: string | URL;
|
|
130
|
+
/**
|
|
131
|
+
* Raw middleware-forwarded session JSON (or omit to read
|
|
132
|
+
* {@link ATHENA_SESSION_DATA_HEADER} from `requestHeaders`).
|
|
133
|
+
*/
|
|
134
|
+
sessionDataHeader?: string | null;
|
|
135
|
+
/** Custom fetch (tests / edge). Defaults to `globalThis.fetch`. */
|
|
136
|
+
fetchImpl?: typeof fetch;
|
|
137
|
+
/**
|
|
138
|
+
* When true (default), skip the network get-session call if cookies and
|
|
139
|
+
* bearer token are both absent.
|
|
140
|
+
*/
|
|
141
|
+
skipFetchWithoutCredentials?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Product org policy. Runs after the raw session is loaded and before
|
|
144
|
+
* optional ensure-active. Does not replace membership checks in the app.
|
|
145
|
+
*/
|
|
146
|
+
resolveActiveOrganizationId?: (args: ResolveActiveOrganizationIdArgs) => string | null | Promise<string | null>;
|
|
147
|
+
/**
|
|
148
|
+
* Optional bootstrap when the session has no active org. Inject list/set
|
|
149
|
+
* from your auth client; the package does not own org transport here.
|
|
150
|
+
*/
|
|
151
|
+
ensureActiveOrganization?: GetServerSessionEnsureActiveOptions;
|
|
152
|
+
}
|
|
153
|
+
interface GetServerSessionResult {
|
|
154
|
+
session: AthenaAuthSessionResponse | null;
|
|
155
|
+
userId: string | null;
|
|
156
|
+
/** Active org id from the auth session payload before product resolution. */
|
|
157
|
+
rawActiveOrganizationId: string | null;
|
|
158
|
+
/**
|
|
159
|
+
* Product-resolved organization id after `resolveActiveOrganizationId` and
|
|
160
|
+
* optional ensure-active. Prefer this for data client `scope.organizationId`.
|
|
161
|
+
*/
|
|
162
|
+
organizationId: string | null;
|
|
163
|
+
didEnsureActiveOrganization: boolean;
|
|
164
|
+
/** True when the session came from the middleware header without a fetch. */
|
|
165
|
+
fromSessionDataHeader: boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Parse a middleware-forwarded session JSON string into a session response.
|
|
169
|
+
* Returns null for missing, invalid, or incomplete payloads.
|
|
170
|
+
*/
|
|
171
|
+
declare function parseAthenaSessionDataHeader(raw: string | null | undefined): AthenaAuthSessionResponse | null;
|
|
172
|
+
/**
|
|
173
|
+
* Load the current Athena Auth session for Next.js RSC / route handlers.
|
|
174
|
+
*
|
|
175
|
+
* Composition (not a full product policy module):
|
|
176
|
+
* 1. Optional middleware header (`x-session-data` / {@link ATHENA_SESSION_DATA_HEADER})
|
|
177
|
+
* 2. Else fetch get-session with request cookies/bearer
|
|
178
|
+
* 3. Optional product `resolveActiveOrganizationId`
|
|
179
|
+
* 4. Optional `ensureActiveOrganization` injectables
|
|
180
|
+
*
|
|
181
|
+
* Wrap with React `cache()` in the app if you need per-request dedupe:
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { cache } from 'react'
|
|
185
|
+
* import { getServerSession } from '@xylex-group/athena/next/server'
|
|
186
|
+
*
|
|
187
|
+
* export const getSession = cache(() =>
|
|
188
|
+
* getServerSession({
|
|
189
|
+
* appOrigin: process.env.NEXT_PUBLIC_APP_URL!,
|
|
190
|
+
* resolveActiveOrganizationId: ({ userId, rawActiveOrganizationId }) =>
|
|
191
|
+
* resolveFormationsOrganizationId(userId, rawActiveOrganizationId),
|
|
192
|
+
* }),
|
|
193
|
+
* )
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function getServerSession(options?: GetServerSessionOptions): Promise<GetServerSessionResult>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Minimal session shape used to derive gateway identity headers.
|
|
200
|
+
* Accepts full {@link AthenaAuthSessionResponse} or a partial getSession payload.
|
|
201
|
+
*/
|
|
202
|
+
type AthenaServerSessionInput = {
|
|
203
|
+
user?: {
|
|
204
|
+
id?: string | null;
|
|
205
|
+
} | null;
|
|
206
|
+
session?: {
|
|
207
|
+
id?: string | null;
|
|
208
|
+
activeOrganizationId?: string | null;
|
|
209
|
+
} | null;
|
|
210
|
+
} | null;
|
|
211
|
+
/**
|
|
212
|
+
* Explicit gateway identity for request-scoped server clients.
|
|
213
|
+
*
|
|
214
|
+
* Maps to `X-User-Id` / `X-Organization-Id` via {@link AthenaRequestContext}.
|
|
215
|
+
* When both `session` and `scope` are provided, any field present on `scope`
|
|
216
|
+
* overrides the session-derived value (including explicit `null` to clear).
|
|
217
|
+
*/
|
|
218
|
+
interface AthenaServerScope {
|
|
219
|
+
userId?: string | null;
|
|
220
|
+
organizationId?: string | null;
|
|
221
|
+
}
|
|
222
|
+
interface AthenaServerContextOptions extends AthenaServerRequestOptions {
|
|
223
|
+
session?: AthenaAuthSessionResponse | AthenaServerSessionInput | null;
|
|
224
|
+
/**
|
|
225
|
+
* First-class identity scope. Prefer this over a second `withContext(...)`
|
|
226
|
+
* call when you already know user/org for the request.
|
|
227
|
+
*/
|
|
228
|
+
scope?: AthenaServerScope;
|
|
229
|
+
}
|
|
230
|
+
interface AthenaResolvedServerContext {
|
|
231
|
+
request: AthenaRequestContext;
|
|
232
|
+
session: AthenaAuthSessionResponse | AthenaServerSessionInput | null;
|
|
233
|
+
userId: string | null;
|
|
234
|
+
organizationId: string | null;
|
|
235
|
+
}
|
|
236
|
+
declare function resolveAthenaServerContext(options?: AthenaServerContextOptions): Promise<AthenaResolvedServerContext>;
|
|
237
|
+
type AthenaBaseServerOptions = AthenaServerRequestOptions & {
|
|
238
|
+
session?: AthenaAuthSessionResponse | AthenaServerSessionInput | null;
|
|
239
|
+
scope?: AthenaServerScope;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Explicit server config: require url + key at the call site.
|
|
243
|
+
*/
|
|
244
|
+
type AthenaExplicitServerConfig<TModels extends AthenaClientModelsInput | undefined = undefined> = AthenaBaseServerOptions & AthenaClientConfig<TModels> & {
|
|
245
|
+
url: string;
|
|
246
|
+
key: string;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Environment server config: require an explicit env object (no silent global process.env).
|
|
250
|
+
*/
|
|
251
|
+
type AthenaEnvironmentServerConfig<TModels extends AthenaClientModelsInput | undefined = undefined> = AthenaBaseServerOptions & Omit<AthenaClientConfig<TModels>, 'url' | 'key'> & {
|
|
252
|
+
env: Record<string, string | undefined>;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Flat Next server client options: client config fields + request context options.
|
|
256
|
+
* Requires either `{ url, key }` or `{ env }`.
|
|
257
|
+
*/
|
|
258
|
+
type AthenaServerClientConfig<TModels extends AthenaClientModelsInput | undefined = undefined> = AthenaExplicitServerConfig<TModels> | AthenaEnvironmentServerConfig<TModels>;
|
|
259
|
+
/**
|
|
260
|
+
* Request-scoped Next server façade over {@link createClient}.
|
|
261
|
+
*
|
|
262
|
+
* Resolves cookies, bearer tokens, optional session/`scope` identity, and cache
|
|
263
|
+
* policy on every invocation, merges with any application-level context, then
|
|
264
|
+
* materializes the client through the singular `createClient` primitive.
|
|
265
|
+
*
|
|
266
|
+
* Does not cache clients. Call once per Server Component / Server Action /
|
|
267
|
+
* Route Handler request (or pass explicit requestHeaders/requestCookies).
|
|
268
|
+
*
|
|
269
|
+
* Prefer `session` and/or `scope` for identity headers instead of a follow-up
|
|
270
|
+
* `withContext({})` that drops org/user fields.
|
|
271
|
+
*/
|
|
272
|
+
declare function createAthenaServerClient<const TModels extends AthenaClientModelsInput | undefined = undefined>(options: AthenaServerClientConfig<TModels>): Promise<AthenaClient<TModels>>;
|
|
273
|
+
|
|
274
|
+
export { AthenaAuthSessionBridgeOptions, AthenaAuthSessionBridgePathOptions, type AthenaEnvironmentServerConfig, type AthenaExplicitServerConfig, type AthenaRequestCookiesBag, type AthenaRequestCookiesInput, type AthenaRequestHeadersBag, type AthenaRequestHeadersInput, type AthenaResolvedServerContext, type AthenaServerClientConfig, type AthenaServerContextOptions, type AthenaServerRequestOptions, type AthenaServerScope, type AthenaServerSessionInput, type GetServerSessionEnsureActiveOptions, type GetServerSessionOptions, type GetServerSessionResult, OrganizationLike, type ResolveActiveOrganizationIdArgs, createAthenaAuthSessionBridgeHandlers, createAthenaAuthSessionBridgePathHandlers, createAthenaServerClient, getServerSession, handleAthenaAuthSessionBridgeDelete, handleAthenaAuthSessionBridgePost, isAthenaAuthSessionBridgePath, parseAthenaSessionDataHeader, resolveAthenaServerContext, resolveNextRequestContext };
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { ad as AthenaAuthSessionResponse } from '../types-BVKpQmfY.js';
|
|
2
|
+
import { r as AthenaClientModelsInput } from '../types-S-bTMPiM.js';
|
|
3
|
+
import { aA as AthenaRequestContext, ai as AthenaClientConfig, ag as AthenaClient } from '../v3-client-OAai_JNs.js';
|
|
4
|
+
import { OrganizationLike } from '../organization.js';
|
|
5
|
+
export { ActiveOrganizationSessionLike, EnsureActiveOrganizationOptions, EnsureActiveOrganizationResult, ensureActiveOrganization } from '../organization.js';
|
|
6
|
+
import { g as AthenaAuthSessionBridgeOptions, h as AthenaAuthSessionBridgePathOptions } from '../payload-DWI1rw-e.js';
|
|
7
|
+
export { A as ATHENA_AUTH_SESSION_BRIDGE_ROUTE, a as ATHENA_AUTH_SESSION_COOKIE_NAME, b as ATHENA_AUTH_SESSION_COOKIE_NAMES, c as AthenaAuthSessionBridgeClientOptions, d as AthenaAuthSessionBridgePayload, e as AthenaAuthSessionBridgeSource, f as clearAthenaAuthSessionOnAppHost, p as persistAthenaAuthSessionOnAppHost, r as resolveSessionBridgePayload } from '../payload-DWI1rw-e.js';
|
|
8
|
+
export { S as SESSION_COOKIE_PATTERNS, h as hasAuthSessionCookie } from '../session-cookie-detection-BqOp9mO6.js';
|
|
9
|
+
export { A as ATHENA_AUTH_DISABLE_COOKIE_CACHE_QUERY_PARAM, a as ATHENA_AUTH_DISABLE_COOKIE_CACHE_QUERY_VALUE, b as ATHENA_AUTH_GET_SESSION_ABSOLUTE_PATH, c as ATHENA_AUTH_GET_SESSION_PATH, d as ATHENA_AUTH_PATH, e as ATHENA_AUTH_UPSTREAM_ENV_KEYS, f as ATHENA_AUTH_UPSTREAM_URL_ENV_NAMES, g as ATHENA_AUTH_VERIFY_EMAIL_PATH, h as ATHENA_SESSION_DATA_HEADER, i as AUTH_SESSION_PATH, j as AthenaAuthClientBaseUrlOptions, k as AthenaAuthUpstreamEnv, l as AthenaAuthUpstreamEnvKey, D as DEFAULT_ATHENA_AUTH_ORIGIN, m as DEFAULT_ATHENA_AUTH_UPSTREAM_URL, n as DISABLE_COOKIE_CACHE_QUERY_PARAM, o as DISABLE_COOKIE_CACHE_QUERY_VALUE, E as EnvLike, L as LOCAL_DEV_ORIGIN, S as SESSION_DATA_HEADER, p as createFreshSessionLookupUrl, q as isAbsoluteUrl, r as normalizeAthenaAuthBaseUrl, s as readAthenaAuthUpstreamUrlFromEnv, t as resolveAthenaAuthClientBaseUrl, u as resolveAthenaAuthRequestUrl, v as resolveAthenaAuthUpstreamUrl, w as resolveEmailVerificationCallbackUrl } from '../athena-auth-url-C1FbVmN6.js';
|
|
10
|
+
export { A as ATHENA_AUTH_COOKIE_PREFIXES, a as AUTHENTICATED_REDIRECT_MODE_SET, b as AUTHENTICATED_REDIRECT_VIEW_SET, c as AUTH_DEFAULT_VIEW, d as AUTH_MODE_REDIRECTS, e as AUTH_MODE_SET, f as AUTH_ROUTES, g as AUTH_TWO_FACTOR_SEGMENT, h as AUTH_VIEW_BY_SEGMENT, i as AthenaRequestHeaderOverrideFields, j as AthenaRequestHeaderProfile, k as AuthMode, l as AuthModeRedirects, m as AuthRoutes, n as AuthView, B as BuildAthenaRequestHeadersInput, C as ClearAuthCookiesOptions, R as ResolvedRequestHeaderOverrides, E as applyAthenaApiKeyHeaders, F as applyAthenaAuthContextHeaders, G as applyAthenaPgUriHeaders, o as asNonEmptyString, p as asString, q as buildAthenaGatewayHeaders, r as buildAthenaRequestHeaders, H as buildServiceRequestHeaders, s as clearAuthCookies, t as createAuthModeRedirects, u as createAuthRoutes, I as hasHeaderIgnoreCase, v as isAuthMode, w as readTrimmedString, x as resolveAuthModeRedirect, y as resolveAuthViewFromSegment, J as resolveHeaderValue, K as resolveRequestHeaderOverrides, z as shouldRedirectAuthenticatedAuthMode, D as shouldRedirectAuthenticatedAuthView } from '../athena-request-headers-Dwdkq2WR.js';
|
|
11
|
+
export { G as GetOriginFromHeadersOptions, g as getOriginFromHeaders, i as isDynamicServerUsageError, p as proxyRequestHeaders, r as readEnv, a as requireEnv } from '../proxy-request-headers-CttlcuRb.js';
|
|
12
|
+
export { A as ATHENA_TABLE_SCHEMA_ROUTE, a as AthenaTableCatalogColumn, b as AthenaTableCatalogQueryClient, c as AthenaTableCatalogRelation, d as AthenaTableCatalogResponse, e as AthenaTableCatalogTable, f as AthenaTableSchemaConfig, g as AthenaTableSchemaHandlerOptions, h as AthenaTableShowcaseConfig, F as FetchAthenaTableCatalogOptions, T as TableCatalogColumn, i as TableCatalogRelation, j as TableCatalogResponse, k as TableCatalogTable, l as buildAthenaTableCatalogQueries, m as createAthenaTableSchemaHandlers, n as fetchAthenaTableCatalog, o as fetchTableCatalog, p as handleAthenaTableSchemaPost, q as hasAthenaTableSchemaCredentials, r as isAthenaTableSchemaConfig, s as parseAthenaTableSchemaScope } from '../schema-handlers-CvWqF-dW.js';
|
|
13
|
+
import '../types-B2RZPivM.js';
|
|
14
|
+
import '../module-C_ab-MM1.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Handle bridge `POST` — set an httpOnly session cookie from JSON body.
|
|
18
|
+
*
|
|
19
|
+
* Expected body: `{ "token": string, "expiresAt"?: string }`.
|
|
20
|
+
*
|
|
21
|
+
* @param request - Incoming request (JSON body)
|
|
22
|
+
* @param options - Cookie / route configuration
|
|
23
|
+
* @returns `200` on success, `400` when token is missing
|
|
24
|
+
*/
|
|
25
|
+
declare function handleAthenaAuthSessionBridgePost(request: Request, options?: AthenaAuthSessionBridgeOptions): Promise<Response>;
|
|
26
|
+
/**
|
|
27
|
+
* Handle bridge `DELETE` — clear bridged session cookie name variants.
|
|
28
|
+
*
|
|
29
|
+
* @param request - Incoming request (used for Secure detection)
|
|
30
|
+
* @param options - Cookie / route configuration
|
|
31
|
+
* @returns `200` with clear `Set-Cookie` headers
|
|
32
|
+
*/
|
|
33
|
+
declare function handleAthenaAuthSessionBridgeDelete(request: Request, options?: AthenaAuthSessionBridgeOptions): Response;
|
|
34
|
+
/**
|
|
35
|
+
* Create dedicated App Router handlers for the session bridge.
|
|
36
|
+
*
|
|
37
|
+
* Drop into a route file with no additional wiring:
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // app/api/athena-auth/session/route.ts
|
|
42
|
+
* import { createAthenaAuthSessionBridgeHandlers } from '@xylex-group/athena/next/server'
|
|
43
|
+
*
|
|
44
|
+
* export const { POST, DELETE } = createAthenaAuthSessionBridgeHandlers()
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param options - Optional cookie name, path, SameSite, Secure overrides
|
|
48
|
+
* @returns Object with `POST` and `DELETE` route handlers
|
|
49
|
+
*/
|
|
50
|
+
declare function createAthenaAuthSessionBridgeHandlers(options?: AthenaAuthSessionBridgeOptions): {
|
|
51
|
+
POST: (request: Request) => Promise<Response>;
|
|
52
|
+
DELETE: (request: Request) => Response;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Whether this request should be handled as a session bridge call.
|
|
56
|
+
*
|
|
57
|
+
* Returns true when:
|
|
58
|
+
* - the pathname equals the configured `route`, or
|
|
59
|
+
* - the final path segment is listed in `matchPaths` (default `session`)
|
|
60
|
+
*
|
|
61
|
+
* @param request - Incoming request
|
|
62
|
+
* @param options - Route + matchPaths configuration
|
|
63
|
+
*/
|
|
64
|
+
declare function isAthenaAuthSessionBridgePath(request: Request, options?: AthenaAuthSessionBridgePathOptions): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Create catch-all / `[path]` handlers that only service session-bridge paths.
|
|
67
|
+
*
|
|
68
|
+
* Non-matching paths return `404` with `{ error: 'Not found' }` so you can
|
|
69
|
+
* mount under `/api/auth/[...path]` without implementing a full auth proxy.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* // app/api/auth/[...path]/route.ts
|
|
74
|
+
* import { createAthenaAuthSessionBridgePathHandlers } from '@xylex-group/athena/next/server'
|
|
75
|
+
*
|
|
76
|
+
* export const { POST, DELETE } = createAthenaAuthSessionBridgePathHandlers({
|
|
77
|
+
* route: '/api/auth/session',
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @param options - Bridge options plus `matchPaths`
|
|
82
|
+
* @returns Object with `POST` and `DELETE` route handlers
|
|
83
|
+
*/
|
|
84
|
+
declare function createAthenaAuthSessionBridgePathHandlers(options?: AthenaAuthSessionBridgePathOptions): {
|
|
85
|
+
POST: (request: Request) => Promise<Response>;
|
|
86
|
+
DELETE: (request: Request) => Response;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
interface AthenaRequestHeadersBag {
|
|
90
|
+
get(name: string): string | null;
|
|
91
|
+
}
|
|
92
|
+
interface AthenaRequestCookiesBag {
|
|
93
|
+
getAll(): Array<{
|
|
94
|
+
name: string;
|
|
95
|
+
value: string;
|
|
96
|
+
}>;
|
|
97
|
+
}
|
|
98
|
+
type AthenaRequestHeadersInput = AthenaRequestHeadersBag | Record<string, string | null | undefined>;
|
|
99
|
+
type AthenaRequestCookiesInput = AthenaRequestCookiesBag | string | null | undefined;
|
|
100
|
+
interface AthenaServerRequestOptions {
|
|
101
|
+
requestHeaders?: AthenaRequestHeadersInput;
|
|
102
|
+
requestCookies?: AthenaRequestCookiesInput;
|
|
103
|
+
forceNoCache?: boolean;
|
|
104
|
+
headers?: Record<string, string>;
|
|
105
|
+
}
|
|
106
|
+
declare function resolveNextRequestContext(options?: AthenaServerRequestOptions): Promise<AthenaRequestContext>;
|
|
107
|
+
|
|
108
|
+
interface ResolveActiveOrganizationIdArgs {
|
|
109
|
+
rawActiveOrganizationId: string | null;
|
|
110
|
+
session: AthenaAuthSessionResponse;
|
|
111
|
+
userId: string;
|
|
112
|
+
}
|
|
113
|
+
interface GetServerSessionEnsureActiveOptions<TOrganization extends OrganizationLike = OrganizationLike> {
|
|
114
|
+
listOrganizations: () => Promise<readonly TOrganization[]>;
|
|
115
|
+
onError?: (error: unknown) => void;
|
|
116
|
+
selectOrganizationId?: (organizations: readonly TOrganization[]) => string | null;
|
|
117
|
+
setActiveOrganization: (organizationId: string) => Promise<unknown>;
|
|
118
|
+
}
|
|
119
|
+
interface GetServerSessionOptions extends AthenaServerRequestOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Absolute get-session URL. When omitted, built from `appOrigin` via
|
|
122
|
+
* {@link createFreshSessionLookupUrl}.
|
|
123
|
+
*/
|
|
124
|
+
authSessionUrl?: string | URL;
|
|
125
|
+
/**
|
|
126
|
+
* App origin used to build `/api/auth/get-session?disableCookieCache=true`
|
|
127
|
+
* when `authSessionUrl` is not set.
|
|
128
|
+
*/
|
|
129
|
+
appOrigin?: string | URL;
|
|
130
|
+
/**
|
|
131
|
+
* Raw middleware-forwarded session JSON (or omit to read
|
|
132
|
+
* {@link ATHENA_SESSION_DATA_HEADER} from `requestHeaders`).
|
|
133
|
+
*/
|
|
134
|
+
sessionDataHeader?: string | null;
|
|
135
|
+
/** Custom fetch (tests / edge). Defaults to `globalThis.fetch`. */
|
|
136
|
+
fetchImpl?: typeof fetch;
|
|
137
|
+
/**
|
|
138
|
+
* When true (default), skip the network get-session call if cookies and
|
|
139
|
+
* bearer token are both absent.
|
|
140
|
+
*/
|
|
141
|
+
skipFetchWithoutCredentials?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Product org policy. Runs after the raw session is loaded and before
|
|
144
|
+
* optional ensure-active. Does not replace membership checks in the app.
|
|
145
|
+
*/
|
|
146
|
+
resolveActiveOrganizationId?: (args: ResolveActiveOrganizationIdArgs) => string | null | Promise<string | null>;
|
|
147
|
+
/**
|
|
148
|
+
* Optional bootstrap when the session has no active org. Inject list/set
|
|
149
|
+
* from your auth client; the package does not own org transport here.
|
|
150
|
+
*/
|
|
151
|
+
ensureActiveOrganization?: GetServerSessionEnsureActiveOptions;
|
|
152
|
+
}
|
|
153
|
+
interface GetServerSessionResult {
|
|
154
|
+
session: AthenaAuthSessionResponse | null;
|
|
155
|
+
userId: string | null;
|
|
156
|
+
/** Active org id from the auth session payload before product resolution. */
|
|
157
|
+
rawActiveOrganizationId: string | null;
|
|
158
|
+
/**
|
|
159
|
+
* Product-resolved organization id after `resolveActiveOrganizationId` and
|
|
160
|
+
* optional ensure-active. Prefer this for data client `scope.organizationId`.
|
|
161
|
+
*/
|
|
162
|
+
organizationId: string | null;
|
|
163
|
+
didEnsureActiveOrganization: boolean;
|
|
164
|
+
/** True when the session came from the middleware header without a fetch. */
|
|
165
|
+
fromSessionDataHeader: boolean;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Parse a middleware-forwarded session JSON string into a session response.
|
|
169
|
+
* Returns null for missing, invalid, or incomplete payloads.
|
|
170
|
+
*/
|
|
171
|
+
declare function parseAthenaSessionDataHeader(raw: string | null | undefined): AthenaAuthSessionResponse | null;
|
|
172
|
+
/**
|
|
173
|
+
* Load the current Athena Auth session for Next.js RSC / route handlers.
|
|
174
|
+
*
|
|
175
|
+
* Composition (not a full product policy module):
|
|
176
|
+
* 1. Optional middleware header (`x-session-data` / {@link ATHENA_SESSION_DATA_HEADER})
|
|
177
|
+
* 2. Else fetch get-session with request cookies/bearer
|
|
178
|
+
* 3. Optional product `resolveActiveOrganizationId`
|
|
179
|
+
* 4. Optional `ensureActiveOrganization` injectables
|
|
180
|
+
*
|
|
181
|
+
* Wrap with React `cache()` in the app if you need per-request dedupe:
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { cache } from 'react'
|
|
185
|
+
* import { getServerSession } from '@xylex-group/athena/next/server'
|
|
186
|
+
*
|
|
187
|
+
* export const getSession = cache(() =>
|
|
188
|
+
* getServerSession({
|
|
189
|
+
* appOrigin: process.env.NEXT_PUBLIC_APP_URL!,
|
|
190
|
+
* resolveActiveOrganizationId: ({ userId, rawActiveOrganizationId }) =>
|
|
191
|
+
* resolveFormationsOrganizationId(userId, rawActiveOrganizationId),
|
|
192
|
+
* }),
|
|
193
|
+
* )
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
declare function getServerSession(options?: GetServerSessionOptions): Promise<GetServerSessionResult>;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Minimal session shape used to derive gateway identity headers.
|
|
200
|
+
* Accepts full {@link AthenaAuthSessionResponse} or a partial getSession payload.
|
|
201
|
+
*/
|
|
202
|
+
type AthenaServerSessionInput = {
|
|
203
|
+
user?: {
|
|
204
|
+
id?: string | null;
|
|
205
|
+
} | null;
|
|
206
|
+
session?: {
|
|
207
|
+
id?: string | null;
|
|
208
|
+
activeOrganizationId?: string | null;
|
|
209
|
+
} | null;
|
|
210
|
+
} | null;
|
|
211
|
+
/**
|
|
212
|
+
* Explicit gateway identity for request-scoped server clients.
|
|
213
|
+
*
|
|
214
|
+
* Maps to `X-User-Id` / `X-Organization-Id` via {@link AthenaRequestContext}.
|
|
215
|
+
* When both `session` and `scope` are provided, any field present on `scope`
|
|
216
|
+
* overrides the session-derived value (including explicit `null` to clear).
|
|
217
|
+
*/
|
|
218
|
+
interface AthenaServerScope {
|
|
219
|
+
userId?: string | null;
|
|
220
|
+
organizationId?: string | null;
|
|
221
|
+
}
|
|
222
|
+
interface AthenaServerContextOptions extends AthenaServerRequestOptions {
|
|
223
|
+
session?: AthenaAuthSessionResponse | AthenaServerSessionInput | null;
|
|
224
|
+
/**
|
|
225
|
+
* First-class identity scope. Prefer this over a second `withContext(...)`
|
|
226
|
+
* call when you already know user/org for the request.
|
|
227
|
+
*/
|
|
228
|
+
scope?: AthenaServerScope;
|
|
229
|
+
}
|
|
230
|
+
interface AthenaResolvedServerContext {
|
|
231
|
+
request: AthenaRequestContext;
|
|
232
|
+
session: AthenaAuthSessionResponse | AthenaServerSessionInput | null;
|
|
233
|
+
userId: string | null;
|
|
234
|
+
organizationId: string | null;
|
|
235
|
+
}
|
|
236
|
+
declare function resolveAthenaServerContext(options?: AthenaServerContextOptions): Promise<AthenaResolvedServerContext>;
|
|
237
|
+
type AthenaBaseServerOptions = AthenaServerRequestOptions & {
|
|
238
|
+
session?: AthenaAuthSessionResponse | AthenaServerSessionInput | null;
|
|
239
|
+
scope?: AthenaServerScope;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Explicit server config: require url + key at the call site.
|
|
243
|
+
*/
|
|
244
|
+
type AthenaExplicitServerConfig<TModels extends AthenaClientModelsInput | undefined = undefined> = AthenaBaseServerOptions & AthenaClientConfig<TModels> & {
|
|
245
|
+
url: string;
|
|
246
|
+
key: string;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Environment server config: require an explicit env object (no silent global process.env).
|
|
250
|
+
*/
|
|
251
|
+
type AthenaEnvironmentServerConfig<TModels extends AthenaClientModelsInput | undefined = undefined> = AthenaBaseServerOptions & Omit<AthenaClientConfig<TModels>, 'url' | 'key'> & {
|
|
252
|
+
env: Record<string, string | undefined>;
|
|
253
|
+
};
|
|
254
|
+
/**
|
|
255
|
+
* Flat Next server client options: client config fields + request context options.
|
|
256
|
+
* Requires either `{ url, key }` or `{ env }`.
|
|
257
|
+
*/
|
|
258
|
+
type AthenaServerClientConfig<TModels extends AthenaClientModelsInput | undefined = undefined> = AthenaExplicitServerConfig<TModels> | AthenaEnvironmentServerConfig<TModels>;
|
|
259
|
+
/**
|
|
260
|
+
* Request-scoped Next server façade over {@link createClient}.
|
|
261
|
+
*
|
|
262
|
+
* Resolves cookies, bearer tokens, optional session/`scope` identity, and cache
|
|
263
|
+
* policy on every invocation, merges with any application-level context, then
|
|
264
|
+
* materializes the client through the singular `createClient` primitive.
|
|
265
|
+
*
|
|
266
|
+
* Does not cache clients. Call once per Server Component / Server Action /
|
|
267
|
+
* Route Handler request (or pass explicit requestHeaders/requestCookies).
|
|
268
|
+
*
|
|
269
|
+
* Prefer `session` and/or `scope` for identity headers instead of a follow-up
|
|
270
|
+
* `withContext({})` that drops org/user fields.
|
|
271
|
+
*/
|
|
272
|
+
declare function createAthenaServerClient<const TModels extends AthenaClientModelsInput | undefined = undefined>(options: AthenaServerClientConfig<TModels>): Promise<AthenaClient<TModels>>;
|
|
273
|
+
|
|
274
|
+
export { AthenaAuthSessionBridgeOptions, AthenaAuthSessionBridgePathOptions, type AthenaEnvironmentServerConfig, type AthenaExplicitServerConfig, type AthenaRequestCookiesBag, type AthenaRequestCookiesInput, type AthenaRequestHeadersBag, type AthenaRequestHeadersInput, type AthenaResolvedServerContext, type AthenaServerClientConfig, type AthenaServerContextOptions, type AthenaServerRequestOptions, type AthenaServerScope, type AthenaServerSessionInput, type GetServerSessionEnsureActiveOptions, type GetServerSessionOptions, type GetServerSessionResult, OrganizationLike, type ResolveActiveOrganizationIdArgs, createAthenaAuthSessionBridgeHandlers, createAthenaAuthSessionBridgePathHandlers, createAthenaServerClient, getServerSession, handleAthenaAuthSessionBridgeDelete, handleAthenaAuthSessionBridgePost, isAthenaAuthSessionBridgePath, parseAthenaSessionDataHeader, resolveAthenaServerContext, resolveNextRequestContext };
|