@authyon/server 0.2.0-beta.1 → 0.2.0-beta.12
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 +201 -1
- package/dist/authorization-DWlLfYQJ.d.cts +129 -0
- package/dist/authorization-wrZ5ull7.d.ts +129 -0
- package/dist/authyonServerClient-t82mwTws.d.cts +900 -0
- package/dist/authyonServerClient-t82mwTws.d.ts +900 -0
- package/dist/bff.cjs +1126 -0
- package/dist/bff.d.cts +142 -0
- package/dist/bff.d.ts +142 -0
- package/dist/bff.js +791 -0
- package/dist/chunk-56H66KLG.js +323 -0
- package/dist/chunk-77J4NURK.js +13 -0
- package/dist/chunk-NKWQMYB3.js +485 -0
- package/dist/index.cjs +412 -30
- package/dist/index.d.cts +16 -746
- package/dist/index.d.ts +16 -746
- package/dist/index.js +392 -770
- package/dist/next.cjs +328 -0
- package/dist/next.d.cts +27 -0
- package/dist/next.d.ts +27 -0
- package/dist/next.js +48 -0
- package/package.json +28 -5
package/dist/bff.d.cts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-t82mwTws.cjs';
|
|
2
|
+
import 'jose';
|
|
3
|
+
|
|
4
|
+
interface BffLoginInput {
|
|
5
|
+
email?: string;
|
|
6
|
+
username?: string;
|
|
7
|
+
password: string;
|
|
8
|
+
organizationSlug?: string;
|
|
9
|
+
sessionPersistence?: BffSessionPersistence;
|
|
10
|
+
}
|
|
11
|
+
interface BffVerifyTwoFactorInput {
|
|
12
|
+
challengeToken: string;
|
|
13
|
+
method: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
sessionPersistence?: BffSessionPersistence;
|
|
16
|
+
webAuthnAssertion?: {
|
|
17
|
+
ceremonyToken: string;
|
|
18
|
+
assertionJson: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
type BffSessionPersistence = "standard" | "remembered";
|
|
22
|
+
interface BffSessionLifetime {
|
|
23
|
+
absoluteTimeoutMs: number;
|
|
24
|
+
idleTimeoutMs: number;
|
|
25
|
+
}
|
|
26
|
+
interface BffTokens {
|
|
27
|
+
accessToken: string;
|
|
28
|
+
refreshToken: string;
|
|
29
|
+
expiresAt: number;
|
|
30
|
+
}
|
|
31
|
+
/** Explicit public projection; upstream objects must never be spread into responses. */
|
|
32
|
+
interface BffUser {
|
|
33
|
+
id: string;
|
|
34
|
+
email: string;
|
|
35
|
+
organization: {
|
|
36
|
+
id: string;
|
|
37
|
+
slug: string;
|
|
38
|
+
} | null;
|
|
39
|
+
}
|
|
40
|
+
interface BffChallenge {
|
|
41
|
+
twoFactorRequired: true;
|
|
42
|
+
challengeToken: string;
|
|
43
|
+
methods: string[];
|
|
44
|
+
}
|
|
45
|
+
interface BffAuthProvider {
|
|
46
|
+
login(input: BffLoginInput): Promise<BffTokens | BffChallenge>;
|
|
47
|
+
verifyTwoFactor(input: BffVerifyTwoFactorInput): Promise<BffTokens>;
|
|
48
|
+
refresh(refreshToken: string): Promise<BffTokens>;
|
|
49
|
+
logout(refreshToken: string): Promise<void>;
|
|
50
|
+
switchOrganization(accessToken: string, slug: string): Promise<BffTokens>;
|
|
51
|
+
validate(accessToken: string): Promise<boolean>;
|
|
52
|
+
profile(accessToken: string): Promise<BffUser>;
|
|
53
|
+
}
|
|
54
|
+
interface BffSessionRecord {
|
|
55
|
+
revision: string;
|
|
56
|
+
tokens: BffTokens;
|
|
57
|
+
user: BffUser;
|
|
58
|
+
/** Missing on records created before persistent sessions; those retain the standard policy. */
|
|
59
|
+
sessionPersistence?: BffSessionPersistence;
|
|
60
|
+
expiresAt: number;
|
|
61
|
+
idleExpiresAt: number;
|
|
62
|
+
/** A crashed token rotation must invalidate the session, never replay its old token. */
|
|
63
|
+
busyUntil: number | null;
|
|
64
|
+
}
|
|
65
|
+
interface BffSessionStore {
|
|
66
|
+
read(key: string): Promise<BffSessionRecord | null>;
|
|
67
|
+
/** Atomic across all processes. null expectedRevision means insert only if absent. */
|
|
68
|
+
compareAndSwap(key: string, expectedRevision: string | null, next: BffSessionRecord | null): Promise<boolean>;
|
|
69
|
+
}
|
|
70
|
+
interface BffSessionOptions {
|
|
71
|
+
origin: string;
|
|
72
|
+
provider: BffAuthProvider;
|
|
73
|
+
store: BffSessionStore;
|
|
74
|
+
absoluteTimeoutMs?: number;
|
|
75
|
+
idleTimeoutMs?: number;
|
|
76
|
+
/** Server-controlled limits used only after an explicit remembered login. */
|
|
77
|
+
rememberedSession?: Partial<BffSessionLifetime>;
|
|
78
|
+
refreshAheadMs?: number;
|
|
79
|
+
/** Only permits HTTP on localhost/loopback. Never enables remote HTTP. */
|
|
80
|
+
allowInsecureLocalhost?: boolean;
|
|
81
|
+
}
|
|
82
|
+
declare class BffSessionError extends Error {
|
|
83
|
+
readonly code: string;
|
|
84
|
+
readonly status: number;
|
|
85
|
+
readonly clearCookie: boolean;
|
|
86
|
+
constructor(code: string, status: number, clearCookie?: boolean);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Mount each handler explicitly. Never expose a catch-all proxy for the provider. */
|
|
90
|
+
declare function createBffSession(options: BffSessionOptions): {
|
|
91
|
+
login: (request: Request) => Promise<Response>;
|
|
92
|
+
verifyTwoFactor: (request: Request) => Promise<Response>;
|
|
93
|
+
session: (request: Request) => Promise<Response>;
|
|
94
|
+
switchOrganization: (request: Request) => Promise<Response>;
|
|
95
|
+
logout: (request: Request) => Promise<Response>;
|
|
96
|
+
/** Server-only credential for downstream calls. Never serialize this result to the browser. */
|
|
97
|
+
requireSession(request: Request): Promise<{
|
|
98
|
+
accessToken: string;
|
|
99
|
+
user: BffUser;
|
|
100
|
+
expiresAt: number;
|
|
101
|
+
}>;
|
|
102
|
+
errorResponse: (error: unknown) => Response;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
interface SharedTransportOptions {
|
|
106
|
+
baseUrl: string;
|
|
107
|
+
allowInsecureHttp?: boolean;
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
httpAdapter?: HttpAdapter;
|
|
110
|
+
httpLogger?: HttpLoggerOptions;
|
|
111
|
+
/** @deprecated Prefer `httpAdapter`. */
|
|
112
|
+
fetch?: typeof fetch;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface AuthyonBffProviderOptions extends Omit<SharedTransportOptions, "baseUrl"> {
|
|
116
|
+
baseUrl?: string;
|
|
117
|
+
envKey: string;
|
|
118
|
+
/** Reuses the server client's database-backed validation, not offline JWT verification. */
|
|
119
|
+
validator: Pick<AuthyonServerClient, "validate">;
|
|
120
|
+
}
|
|
121
|
+
declare function createAuthyonBffProvider(options: AuthyonBffProviderOptions): BffAuthProvider;
|
|
122
|
+
|
|
123
|
+
/** Single-process test/development store. Supply a shared store in production. */
|
|
124
|
+
declare function createMemoryBffSessionStore(): BffSessionStore;
|
|
125
|
+
|
|
126
|
+
interface BffRedisClient {
|
|
127
|
+
get(key: string): Promise<string | null>;
|
|
128
|
+
eval(script: string, options: {
|
|
129
|
+
keys: string[];
|
|
130
|
+
arguments: string[];
|
|
131
|
+
}): Promise<unknown>;
|
|
132
|
+
}
|
|
133
|
+
interface RedisBffSessionStoreOptions {
|
|
134
|
+
client: BffRedisClient;
|
|
135
|
+
/** 32 random bytes kept outside Redis; changing this key invalidates existing sessions. */
|
|
136
|
+
encryptionKey: Uint8Array;
|
|
137
|
+
prefix?: string;
|
|
138
|
+
}
|
|
139
|
+
/** node-redis-compatible adapter. Lua fences stale writers using the record revision. */
|
|
140
|
+
declare function createRedisBffSessionStore(options: RedisBffSessionStoreOptions): BffSessionStore;
|
|
141
|
+
|
|
142
|
+
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,142 @@
|
|
|
1
|
+
import { H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonServerClient } from './authyonServerClient-t82mwTws.js';
|
|
2
|
+
import 'jose';
|
|
3
|
+
|
|
4
|
+
interface BffLoginInput {
|
|
5
|
+
email?: string;
|
|
6
|
+
username?: string;
|
|
7
|
+
password: string;
|
|
8
|
+
organizationSlug?: string;
|
|
9
|
+
sessionPersistence?: BffSessionPersistence;
|
|
10
|
+
}
|
|
11
|
+
interface BffVerifyTwoFactorInput {
|
|
12
|
+
challengeToken: string;
|
|
13
|
+
method: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
sessionPersistence?: BffSessionPersistence;
|
|
16
|
+
webAuthnAssertion?: {
|
|
17
|
+
ceremonyToken: string;
|
|
18
|
+
assertionJson: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
type BffSessionPersistence = "standard" | "remembered";
|
|
22
|
+
interface BffSessionLifetime {
|
|
23
|
+
absoluteTimeoutMs: number;
|
|
24
|
+
idleTimeoutMs: number;
|
|
25
|
+
}
|
|
26
|
+
interface BffTokens {
|
|
27
|
+
accessToken: string;
|
|
28
|
+
refreshToken: string;
|
|
29
|
+
expiresAt: number;
|
|
30
|
+
}
|
|
31
|
+
/** Explicit public projection; upstream objects must never be spread into responses. */
|
|
32
|
+
interface BffUser {
|
|
33
|
+
id: string;
|
|
34
|
+
email: string;
|
|
35
|
+
organization: {
|
|
36
|
+
id: string;
|
|
37
|
+
slug: string;
|
|
38
|
+
} | null;
|
|
39
|
+
}
|
|
40
|
+
interface BffChallenge {
|
|
41
|
+
twoFactorRequired: true;
|
|
42
|
+
challengeToken: string;
|
|
43
|
+
methods: string[];
|
|
44
|
+
}
|
|
45
|
+
interface BffAuthProvider {
|
|
46
|
+
login(input: BffLoginInput): Promise<BffTokens | BffChallenge>;
|
|
47
|
+
verifyTwoFactor(input: BffVerifyTwoFactorInput): Promise<BffTokens>;
|
|
48
|
+
refresh(refreshToken: string): Promise<BffTokens>;
|
|
49
|
+
logout(refreshToken: string): Promise<void>;
|
|
50
|
+
switchOrganization(accessToken: string, slug: string): Promise<BffTokens>;
|
|
51
|
+
validate(accessToken: string): Promise<boolean>;
|
|
52
|
+
profile(accessToken: string): Promise<BffUser>;
|
|
53
|
+
}
|
|
54
|
+
interface BffSessionRecord {
|
|
55
|
+
revision: string;
|
|
56
|
+
tokens: BffTokens;
|
|
57
|
+
user: BffUser;
|
|
58
|
+
/** Missing on records created before persistent sessions; those retain the standard policy. */
|
|
59
|
+
sessionPersistence?: BffSessionPersistence;
|
|
60
|
+
expiresAt: number;
|
|
61
|
+
idleExpiresAt: number;
|
|
62
|
+
/** A crashed token rotation must invalidate the session, never replay its old token. */
|
|
63
|
+
busyUntil: number | null;
|
|
64
|
+
}
|
|
65
|
+
interface BffSessionStore {
|
|
66
|
+
read(key: string): Promise<BffSessionRecord | null>;
|
|
67
|
+
/** Atomic across all processes. null expectedRevision means insert only if absent. */
|
|
68
|
+
compareAndSwap(key: string, expectedRevision: string | null, next: BffSessionRecord | null): Promise<boolean>;
|
|
69
|
+
}
|
|
70
|
+
interface BffSessionOptions {
|
|
71
|
+
origin: string;
|
|
72
|
+
provider: BffAuthProvider;
|
|
73
|
+
store: BffSessionStore;
|
|
74
|
+
absoluteTimeoutMs?: number;
|
|
75
|
+
idleTimeoutMs?: number;
|
|
76
|
+
/** Server-controlled limits used only after an explicit remembered login. */
|
|
77
|
+
rememberedSession?: Partial<BffSessionLifetime>;
|
|
78
|
+
refreshAheadMs?: number;
|
|
79
|
+
/** Only permits HTTP on localhost/loopback. Never enables remote HTTP. */
|
|
80
|
+
allowInsecureLocalhost?: boolean;
|
|
81
|
+
}
|
|
82
|
+
declare class BffSessionError extends Error {
|
|
83
|
+
readonly code: string;
|
|
84
|
+
readonly status: number;
|
|
85
|
+
readonly clearCookie: boolean;
|
|
86
|
+
constructor(code: string, status: number, clearCookie?: boolean);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Mount each handler explicitly. Never expose a catch-all proxy for the provider. */
|
|
90
|
+
declare function createBffSession(options: BffSessionOptions): {
|
|
91
|
+
login: (request: Request) => Promise<Response>;
|
|
92
|
+
verifyTwoFactor: (request: Request) => Promise<Response>;
|
|
93
|
+
session: (request: Request) => Promise<Response>;
|
|
94
|
+
switchOrganization: (request: Request) => Promise<Response>;
|
|
95
|
+
logout: (request: Request) => Promise<Response>;
|
|
96
|
+
/** Server-only credential for downstream calls. Never serialize this result to the browser. */
|
|
97
|
+
requireSession(request: Request): Promise<{
|
|
98
|
+
accessToken: string;
|
|
99
|
+
user: BffUser;
|
|
100
|
+
expiresAt: number;
|
|
101
|
+
}>;
|
|
102
|
+
errorResponse: (error: unknown) => Response;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
interface SharedTransportOptions {
|
|
106
|
+
baseUrl: string;
|
|
107
|
+
allowInsecureHttp?: boolean;
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
httpAdapter?: HttpAdapter;
|
|
110
|
+
httpLogger?: HttpLoggerOptions;
|
|
111
|
+
/** @deprecated Prefer `httpAdapter`. */
|
|
112
|
+
fetch?: typeof fetch;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface AuthyonBffProviderOptions extends Omit<SharedTransportOptions, "baseUrl"> {
|
|
116
|
+
baseUrl?: string;
|
|
117
|
+
envKey: string;
|
|
118
|
+
/** Reuses the server client's database-backed validation, not offline JWT verification. */
|
|
119
|
+
validator: Pick<AuthyonServerClient, "validate">;
|
|
120
|
+
}
|
|
121
|
+
declare function createAuthyonBffProvider(options: AuthyonBffProviderOptions): BffAuthProvider;
|
|
122
|
+
|
|
123
|
+
/** Single-process test/development store. Supply a shared store in production. */
|
|
124
|
+
declare function createMemoryBffSessionStore(): BffSessionStore;
|
|
125
|
+
|
|
126
|
+
interface BffRedisClient {
|
|
127
|
+
get(key: string): Promise<string | null>;
|
|
128
|
+
eval(script: string, options: {
|
|
129
|
+
keys: string[];
|
|
130
|
+
arguments: string[];
|
|
131
|
+
}): Promise<unknown>;
|
|
132
|
+
}
|
|
133
|
+
interface RedisBffSessionStoreOptions {
|
|
134
|
+
client: BffRedisClient;
|
|
135
|
+
/** 32 random bytes kept outside Redis; changing this key invalidates existing sessions. */
|
|
136
|
+
encryptionKey: Uint8Array;
|
|
137
|
+
prefix?: string;
|
|
138
|
+
}
|
|
139
|
+
/** node-redis-compatible adapter. Lua fences stale writers using the record revision. */
|
|
140
|
+
declare function createRedisBffSessionStore(options: RedisBffSessionStoreOptions): BffSessionStore;
|
|
141
|
+
|
|
142
|
+
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 };
|