-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
106 lines (87 loc) · 2.41 KB
/
index.d.ts
File metadata and controls
106 lines (87 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
export type CookieOptions = {
readonly maxAge?: number;
readonly expires?: Date;
readonly domain?: string;
readonly path?: string;
readonly httpOnly?: boolean;
readonly secure?: boolean;
readonly sameSite?: "strict" | "lax" | "none";
};
export type Cookie = {
readonly value: string;
readonly options: CookieOptions;
};
export type Config = {
readonly nowEpochMs?: () => number;
readonly sessionExpiresInMs?: number;
readonly tokenExpiresInMs?: number;
};
type Credential = {
readonly id: string;
readonly idHash: string;
readonly token: string;
};
export type SessionData = {
readonly sessionExpEpochMs: number;
readonly tokenExpEpochMs: number;
readonly token1Hash: string;
readonly token2Hash: string | null;
};
export type DeleteSessionAction = {
readonly type: "DeleteSession";
readonly idHash: string;
};
export type SetSessionAction = {
readonly type: "SetSession";
readonly idHash: string;
readonly reason: "SessionCreated" | "TokenRotated" | "Token2Deleted";
readonly sessionData: SessionData;
};
export type Action = SetSessionAction | DeleteSessionAction;
export const logoutCookie: Cookie;
type LogoutArg = {
readonly credential: Credential;
};
type LogoutResult = {
readonly cookie: Cookie;
readonly action: DeleteSessionAction;
};
export const logout: (arg: LogoutArg) => Promise<LogoutResult>;
type LoginArg = {
readonly config?: Config;
};
type LoginResult = {
readonly cookie: Cookie;
readonly action: SetSessionAction;
};
export const login: (arg?: LoginArg) => Promise<LoginResult>;
export type ConsumeArg = {
readonly credential: Credential;
readonly sessionData: SessionData;
readonly config?: Config;
};
export type ConsumeResult =
| {
readonly state: "Forked";
readonly cookie: Cookie;
readonly action: DeleteSessionAction;
}
| {
readonly state: "Expired";
readonly cookie: Cookie;
readonly action: DeleteSessionAction;
}
| {
readonly state: "Active";
readonly cookie?: Cookie;
readonly action?: SetSessionAction;
};
export const consume: (arg: ConsumeArg) => Promise<ConsumeResult>;
export type CredentialFromCookieArg = {
readonly cookie: string;
};
export type CredentialFromCookieResult = Credential | undefined;
type credentialFromCookie = (arg: {
readonly cookie: string;
}) => Promise<CredentialFromCookieResult>;
export const credentialFromCookie: credentialFromCookie;