@authyon/server 0.2.0-beta.3 → 0.2.0-beta.31

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/bff.d.cts ADDED
@@ -0,0 +1,182 @@
1
+ import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.cjs';
2
+ import 'jose';
3
+
4
+ interface BffLoginInput {
5
+ email?: string;
6
+ username?: string;
7
+ password: string;
8
+ /** Tenant to scope the new session to. */
9
+ tenantSlug?: string;
10
+ /** @deprecated Use `tenantSlug`. */
11
+ organizationSlug?: string;
12
+ sessionPersistence?: BffSessionPersistence;
13
+ }
14
+ interface BffVerifyTwoFactorInput {
15
+ challengeToken: string;
16
+ method: string;
17
+ code?: string;
18
+ sessionPersistence?: BffSessionPersistence;
19
+ webAuthnAssertion?: {
20
+ ceremonyToken: string;
21
+ assertionJson: string;
22
+ };
23
+ }
24
+ type BffSessionPersistence = "standard" | "remembered";
25
+ interface BffSessionLifetime {
26
+ absoluteTimeoutMs: number;
27
+ idleTimeoutMs: number;
28
+ }
29
+ interface BffTokens {
30
+ accessToken: string;
31
+ refreshToken: string;
32
+ expiresAt: number;
33
+ }
34
+ /** Explicit public projection; upstream objects must never be spread into responses. */
35
+ interface BffUser {
36
+ id: string;
37
+ email: string;
38
+ /** The tenant the session is scoped to, or `null`. */
39
+ tenant: {
40
+ id: string;
41
+ slug: string;
42
+ } | null;
43
+ /**
44
+ * @deprecated Use `tenant`. Still read from custom providers and still sent
45
+ * to the browser as a mirror of `tenant`; removed in a later release.
46
+ */
47
+ organization?: {
48
+ id: string;
49
+ slug: string;
50
+ } | null;
51
+ }
52
+ interface BffChallenge {
53
+ twoFactorRequired: true;
54
+ challengeToken: string;
55
+ methods: string[];
56
+ }
57
+ interface BffAuthProvider {
58
+ login(input: BffLoginInput): Promise<BffTokens | BffChallenge>;
59
+ verifyTwoFactor(input: BffVerifyTwoFactorInput): Promise<BffTokens>;
60
+ /**
61
+ * Resends the e-mail code of an in-flight login challenge. Optional so existing
62
+ * custom providers keep compiling; without it the handler answers 501.
63
+ */
64
+ resendTwoFactorEmail?(challengeToken: string): Promise<void>;
65
+ refresh(refreshToken: string): Promise<BffTokens>;
66
+ logout(refreshToken: string): Promise<void>;
67
+ /**
68
+ * Issues tokens scoped to another tenant. Optional only so providers written
69
+ * against the old name keep working: one of `switchTenant` or the deprecated
70
+ * `switchOrganization` must exist, or switching answers 501.
71
+ */
72
+ switchTenant?(accessToken: string, slug: string): Promise<BffTokens>;
73
+ /** @deprecated Implement `switchTenant`. */
74
+ switchOrganization?(accessToken: string, slug: string): Promise<BffTokens>;
75
+ validate(accessToken: string): Promise<boolean>;
76
+ profile(accessToken: string): Promise<BffUser>;
77
+ }
78
+ interface BffSessionRecord {
79
+ revision: string;
80
+ tokens: BffTokens;
81
+ user: BffUser;
82
+ /** Missing on records created before persistent sessions; those retain the standard policy. */
83
+ sessionPersistence?: BffSessionPersistence;
84
+ expiresAt: number;
85
+ idleExpiresAt: number;
86
+ /** A crashed token rotation must invalidate the session, never replay its old token. */
87
+ busyUntil: number | null;
88
+ }
89
+ interface BffSessionStore {
90
+ read(key: string): Promise<BffSessionRecord | null>;
91
+ /** Atomic across all processes. null expectedRevision means insert only if absent. */
92
+ compareAndSwap(key: string, expectedRevision: string | null, next: BffSessionRecord | null): Promise<boolean>;
93
+ }
94
+ interface BffSessionOptions {
95
+ origin: string;
96
+ provider: BffAuthProvider;
97
+ store: BffSessionStore;
98
+ absoluteTimeoutMs?: number;
99
+ idleTimeoutMs?: number;
100
+ /** Server-controlled limits used only after an explicit remembered login. */
101
+ rememberedSession?: Partial<BffSessionLifetime>;
102
+ refreshAheadMs?: number;
103
+ /** Only permits HTTP on localhost/loopback. Never enables remote HTTP. */
104
+ allowInsecureLocalhost?: boolean;
105
+ }
106
+ declare class BffSessionError extends Error {
107
+ readonly code: string;
108
+ readonly status: number;
109
+ readonly clearCookie: boolean;
110
+ constructor(code: string, status: number, clearCookie?: boolean);
111
+ }
112
+
113
+ /** Mount each handler explicitly. Never expose a catch-all proxy for the provider. */
114
+ declare function createBffSession(options: BffSessionOptions): {
115
+ login: (request: Request) => Promise<Response>;
116
+ verifyTwoFactor: (request: Request) => Promise<Response>;
117
+ /** Same guards as `verifyTwoFactor`; never creates a session or sets a cookie. */
118
+ resendTwoFactorEmail: (request: Request) => Promise<Response>;
119
+ session: (request: Request) => Promise<Response>;
120
+ /** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
121
+ switchTenant: (request: Request) => Promise<Response>;
122
+ /** @deprecated Mount `switchTenant`; this is the same handler. */
123
+ switchOrganization: (request: Request) => Promise<Response>;
124
+ logout: (request: Request) => Promise<Response>;
125
+ /** Server-only credential for downstream calls. Never serialize this result to the browser. */
126
+ requireSession(request: Request): Promise<{
127
+ accessToken: string;
128
+ user: {
129
+ id: string;
130
+ email: string;
131
+ tenant: {
132
+ id: string;
133
+ slug: string;
134
+ } | null;
135
+ organization: {
136
+ id: string;
137
+ slug: string;
138
+ } | null;
139
+ };
140
+ expiresAt: number;
141
+ }>;
142
+ errorResponse: (error: unknown) => Response;
143
+ };
144
+
145
+ interface SharedTransportOptions {
146
+ baseUrl: string;
147
+ allowInsecureHttp?: boolean;
148
+ timeoutMs?: number;
149
+ httpAdapter?: HttpAdapter;
150
+ httpLogger?: HttpLoggerOptions;
151
+ /** @deprecated Prefer `httpAdapter`. */
152
+ fetch?: typeof fetch;
153
+ }
154
+
155
+ interface AuthyonBffProviderOptions extends Omit<SharedTransportOptions, "baseUrl"> {
156
+ baseUrl?: string;
157
+ envKey: string;
158
+ /** Reuses the server client's database-backed validation, not offline JWT verification. */
159
+ validator: Pick<AuthyonServerClient, "validate">;
160
+ }
161
+ declare function createAuthyonBffProvider(options: AuthyonBffProviderOptions): BffAuthProvider;
162
+
163
+ /** Single-process test/development store. Supply a shared store in production. */
164
+ declare function createMemoryBffSessionStore(): BffSessionStore;
165
+
166
+ interface BffRedisClient {
167
+ get(key: string): Promise<string | null>;
168
+ eval(script: string, options: {
169
+ keys: string[];
170
+ arguments: string[];
171
+ }): Promise<unknown>;
172
+ }
173
+ interface RedisBffSessionStoreOptions {
174
+ client: BffRedisClient;
175
+ /** 32 random bytes kept outside Redis; changing this key invalidates existing sessions. */
176
+ encryptionKey: Uint8Array;
177
+ prefix?: string;
178
+ }
179
+ /** node-redis-compatible adapter. Lua fences stale writers using the record revision. */
180
+ declare function createRedisBffSessionStore(options: RedisBffSessionStoreOptions): BffSessionStore;
181
+
182
+ export { type AuthyonBffProviderOptions, type BffAuthProvider, type BffChallenge, type BffLoginInput, type BffRedisClient, BffSessionError, type BffSessionLifetime, type BffSessionOptions, type BffSessionPersistence, type BffSessionRecord, type BffSessionStore, type BffTokens, type BffUser, type BffVerifyTwoFactorInput, type RedisBffSessionStoreOptions, createAuthyonBffProvider, createBffSession, createMemoryBffSessionStore, createRedisBffSessionStore };
package/dist/bff.d.ts ADDED
@@ -0,0 +1,182 @@
1
+ import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-mwY55kc9.js';
2
+ import 'jose';
3
+
4
+ interface BffLoginInput {
5
+ email?: string;
6
+ username?: string;
7
+ password: string;
8
+ /** Tenant to scope the new session to. */
9
+ tenantSlug?: string;
10
+ /** @deprecated Use `tenantSlug`. */
11
+ organizationSlug?: string;
12
+ sessionPersistence?: BffSessionPersistence;
13
+ }
14
+ interface BffVerifyTwoFactorInput {
15
+ challengeToken: string;
16
+ method: string;
17
+ code?: string;
18
+ sessionPersistence?: BffSessionPersistence;
19
+ webAuthnAssertion?: {
20
+ ceremonyToken: string;
21
+ assertionJson: string;
22
+ };
23
+ }
24
+ type BffSessionPersistence = "standard" | "remembered";
25
+ interface BffSessionLifetime {
26
+ absoluteTimeoutMs: number;
27
+ idleTimeoutMs: number;
28
+ }
29
+ interface BffTokens {
30
+ accessToken: string;
31
+ refreshToken: string;
32
+ expiresAt: number;
33
+ }
34
+ /** Explicit public projection; upstream objects must never be spread into responses. */
35
+ interface BffUser {
36
+ id: string;
37
+ email: string;
38
+ /** The tenant the session is scoped to, or `null`. */
39
+ tenant: {
40
+ id: string;
41
+ slug: string;
42
+ } | null;
43
+ /**
44
+ * @deprecated Use `tenant`. Still read from custom providers and still sent
45
+ * to the browser as a mirror of `tenant`; removed in a later release.
46
+ */
47
+ organization?: {
48
+ id: string;
49
+ slug: string;
50
+ } | null;
51
+ }
52
+ interface BffChallenge {
53
+ twoFactorRequired: true;
54
+ challengeToken: string;
55
+ methods: string[];
56
+ }
57
+ interface BffAuthProvider {
58
+ login(input: BffLoginInput): Promise<BffTokens | BffChallenge>;
59
+ verifyTwoFactor(input: BffVerifyTwoFactorInput): Promise<BffTokens>;
60
+ /**
61
+ * Resends the e-mail code of an in-flight login challenge. Optional so existing
62
+ * custom providers keep compiling; without it the handler answers 501.
63
+ */
64
+ resendTwoFactorEmail?(challengeToken: string): Promise<void>;
65
+ refresh(refreshToken: string): Promise<BffTokens>;
66
+ logout(refreshToken: string): Promise<void>;
67
+ /**
68
+ * Issues tokens scoped to another tenant. Optional only so providers written
69
+ * against the old name keep working: one of `switchTenant` or the deprecated
70
+ * `switchOrganization` must exist, or switching answers 501.
71
+ */
72
+ switchTenant?(accessToken: string, slug: string): Promise<BffTokens>;
73
+ /** @deprecated Implement `switchTenant`. */
74
+ switchOrganization?(accessToken: string, slug: string): Promise<BffTokens>;
75
+ validate(accessToken: string): Promise<boolean>;
76
+ profile(accessToken: string): Promise<BffUser>;
77
+ }
78
+ interface BffSessionRecord {
79
+ revision: string;
80
+ tokens: BffTokens;
81
+ user: BffUser;
82
+ /** Missing on records created before persistent sessions; those retain the standard policy. */
83
+ sessionPersistence?: BffSessionPersistence;
84
+ expiresAt: number;
85
+ idleExpiresAt: number;
86
+ /** A crashed token rotation must invalidate the session, never replay its old token. */
87
+ busyUntil: number | null;
88
+ }
89
+ interface BffSessionStore {
90
+ read(key: string): Promise<BffSessionRecord | null>;
91
+ /** Atomic across all processes. null expectedRevision means insert only if absent. */
92
+ compareAndSwap(key: string, expectedRevision: string | null, next: BffSessionRecord | null): Promise<boolean>;
93
+ }
94
+ interface BffSessionOptions {
95
+ origin: string;
96
+ provider: BffAuthProvider;
97
+ store: BffSessionStore;
98
+ absoluteTimeoutMs?: number;
99
+ idleTimeoutMs?: number;
100
+ /** Server-controlled limits used only after an explicit remembered login. */
101
+ rememberedSession?: Partial<BffSessionLifetime>;
102
+ refreshAheadMs?: number;
103
+ /** Only permits HTTP on localhost/loopback. Never enables remote HTTP. */
104
+ allowInsecureLocalhost?: boolean;
105
+ }
106
+ declare class BffSessionError extends Error {
107
+ readonly code: string;
108
+ readonly status: number;
109
+ readonly clearCookie: boolean;
110
+ constructor(code: string, status: number, clearCookie?: boolean);
111
+ }
112
+
113
+ /** Mount each handler explicitly. Never expose a catch-all proxy for the provider. */
114
+ declare function createBffSession(options: BffSessionOptions): {
115
+ login: (request: Request) => Promise<Response>;
116
+ verifyTwoFactor: (request: Request) => Promise<Response>;
117
+ /** Same guards as `verifyTwoFactor`; never creates a session or sets a cookie. */
118
+ resendTwoFactorEmail: (request: Request) => Promise<Response>;
119
+ session: (request: Request) => Promise<Response>;
120
+ /** Body `{ tenantSlug }` (the deprecated `{ organizationSlug }` is still read). */
121
+ switchTenant: (request: Request) => Promise<Response>;
122
+ /** @deprecated Mount `switchTenant`; this is the same handler. */
123
+ switchOrganization: (request: Request) => Promise<Response>;
124
+ logout: (request: Request) => Promise<Response>;
125
+ /** Server-only credential for downstream calls. Never serialize this result to the browser. */
126
+ requireSession(request: Request): Promise<{
127
+ accessToken: string;
128
+ user: {
129
+ id: string;
130
+ email: string;
131
+ tenant: {
132
+ id: string;
133
+ slug: string;
134
+ } | null;
135
+ organization: {
136
+ id: string;
137
+ slug: string;
138
+ } | null;
139
+ };
140
+ expiresAt: number;
141
+ }>;
142
+ errorResponse: (error: unknown) => Response;
143
+ };
144
+
145
+ interface SharedTransportOptions {
146
+ baseUrl: string;
147
+ allowInsecureHttp?: boolean;
148
+ timeoutMs?: number;
149
+ httpAdapter?: HttpAdapter;
150
+ httpLogger?: HttpLoggerOptions;
151
+ /** @deprecated Prefer `httpAdapter`. */
152
+ fetch?: typeof fetch;
153
+ }
154
+
155
+ interface AuthyonBffProviderOptions extends Omit<SharedTransportOptions, "baseUrl"> {
156
+ baseUrl?: string;
157
+ envKey: string;
158
+ /** Reuses the server client's database-backed validation, not offline JWT verification. */
159
+ validator: Pick<AuthyonServerClient, "validate">;
160
+ }
161
+ declare function createAuthyonBffProvider(options: AuthyonBffProviderOptions): BffAuthProvider;
162
+
163
+ /** Single-process test/development store. Supply a shared store in production. */
164
+ declare function createMemoryBffSessionStore(): BffSessionStore;
165
+
166
+ interface BffRedisClient {
167
+ get(key: string): Promise<string | null>;
168
+ eval(script: string, options: {
169
+ keys: string[];
170
+ arguments: string[];
171
+ }): Promise<unknown>;
172
+ }
173
+ interface RedisBffSessionStoreOptions {
174
+ client: BffRedisClient;
175
+ /** 32 random bytes kept outside Redis; changing this key invalidates existing sessions. */
176
+ encryptionKey: Uint8Array;
177
+ prefix?: string;
178
+ }
179
+ /** node-redis-compatible adapter. Lua fences stale writers using the record revision. */
180
+ declare function createRedisBffSessionStore(options: RedisBffSessionStoreOptions): BffSessionStore;
181
+
182
+ export { type AuthyonBffProviderOptions, type BffAuthProvider, type BffChallenge, type BffLoginInput, type BffRedisClient, BffSessionError, type BffSessionLifetime, type BffSessionOptions, type BffSessionPersistence, type BffSessionRecord, type BffSessionStore, type BffTokens, type BffUser, type BffVerifyTwoFactorInput, type RedisBffSessionStoreOptions, createAuthyonBffProvider, createBffSession, createMemoryBffSessionStore, createRedisBffSessionStore };