@onelyid/client 0.2.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.
@@ -0,0 +1,62 @@
1
+ import { Environment } from '@onelyid/common';
2
+ import { OAuthClient } from '@atproto/oauth-client-node';
3
+ import { RequestHandler } from 'express';
4
+
5
+ type Logger = {
6
+ info: Function;
7
+ warn: Function;
8
+ error: Function;
9
+ }
10
+
11
+ type RequestMode = `${Environment}`
12
+ type AuthMiddlewareConfig = {
13
+ dbPath?: string;
14
+ cookieSecret?: string;
15
+ stateSecret?: string;
16
+ publicUrl?: string;
17
+ loginRedirect?: string;
18
+ logger?: Logger;
19
+ mode?: RequestMode;
20
+ }
21
+
22
+ // request-specific context
23
+ type RequestContext = {
24
+ oauthClient: OAuthClient | null;
25
+ }
26
+
27
+ type UserInfo = {
28
+ did: string;
29
+ handle: string;
30
+ email: string;
31
+ emailTrusted: boolean;
32
+ displayName?: string;
33
+ avatar?: string;
34
+ }
35
+
36
+ type LoginPageProps = {
37
+ redirectUrl: string;
38
+ authActioUrl: string;
39
+ requestMode?: string;
40
+ }
41
+
42
+ // Express request augmentation
43
+ declare global {
44
+ namespace Express {
45
+ interface Request {
46
+ ctx: RequestContext
47
+ auth: UserInfo | null
48
+ authFlow: () => Promise<LoginPageProps | void>
49
+ getAuth: () => Promise<UserInfo | null>
50
+ mode: Environment
51
+ }
52
+ interface Response {
53
+ clearAuth: () => Promise<void>
54
+ }
55
+ }
56
+ }
57
+
58
+ declare const authMiddleware: (config?: AuthMiddlewareConfig) => RequestHandler;
59
+ declare const setAuth: RequestHandler;
60
+ declare const redirect: (path: string) => RequestHandler;
61
+
62
+ export { type AuthMiddlewareConfig, type LoginPageProps, type UserInfo, authMiddleware, redirect, setAuth };