-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathidentifiers.ts
More file actions
125 lines (109 loc) · 3.62 KB
/
Copy pathidentifiers.ts
File metadata and controls
125 lines (109 loc) · 3.62 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import type { CloudRegion } from "@posthog/shared";
import type {
CancelFlowOutput,
RefreshTokenOutput,
StartFlowOutput,
} from "./oauth.schemas";
export interface AuthSessionRecord {
refreshTokenEncrypted: string;
cloudRegion: CloudRegion;
selectedProjectId: number | null;
scopeVersion: number;
}
export interface PersistAuthSessionRecord {
refreshTokenEncrypted: string;
cloudRegion: CloudRegion;
selectedProjectId: number | null;
scopeVersion: number;
}
export interface AuthPreferenceRecord {
accountKey: string;
cloudRegion: CloudRegion;
lastSelectedProjectId: number | null;
lastSelectedOrgId: string | null;
}
export interface AuthOrgProjectPreferenceRecord {
accountKey: string;
cloudRegion: CloudRegion;
orgId: string;
lastSelectedProjectId: number;
}
/**
* Persists the encrypted auth session. Desktop adapter wraps the
* workspace-server AuthSessionRepository (drizzle rows mapped to the domain
* record above so core never imports workspace-server).
*/
export interface IAuthSessionStore {
getCurrent(): AuthSessionRecord | null;
saveCurrent(input: PersistAuthSessionRecord): void;
clearCurrent(): void;
}
export const AUTH_SESSION_STORE = Symbol.for("posthog.core.auth.sessionStore");
/**
* Persists per-account project preference. Desktop adapter wraps the
* workspace-server AuthPreferenceRepository.
*/
export interface IAuthPreferenceStore {
get(
accountKey: string,
cloudRegion: CloudRegion,
): AuthPreferenceRecord | null;
save(input: AuthPreferenceRecord): void;
getOrgProject(
accountKey: string,
cloudRegion: CloudRegion,
orgId: string,
): AuthOrgProjectPreferenceRecord | null;
saveOrgProject(input: AuthOrgProjectPreferenceRecord): void;
}
export const AUTH_PREFERENCE_STORE = Symbol.for(
"posthog.core.auth.preferenceStore",
);
/**
* Drives the host OAuth login/refresh flow. Desktop adapter wraps the
* Electron-coupled OAuthService (loopback callback server, deep links,
* browser launch, window focus).
*/
export interface IAuthOAuthFlowService {
startFlow(region: CloudRegion): Promise<StartFlowOutput>;
startSignupFlow(region: CloudRegion): Promise<StartFlowOutput>;
refreshToken(
refreshToken: string,
region: CloudRegion,
): Promise<RefreshTokenOutput>;
cancelFlow(): CancelFlowOutput;
}
export const AUTH_OAUTH_FLOW_SERVICE = Symbol.for(
"posthog.core.auth.oauthFlow",
);
/**
* Machine-bound symmetric cipher for the refresh token at rest. Desktop adapter
* wraps the existing encryption util (node:crypto + machine id); the web adapter
* uses a non-extractable Web Crypto key (async), so the contract is async.
*/
export interface IAuthTokenCipher {
encrypt(plaintext: string): Promise<string>;
decrypt(encrypted: string): Promise<string | null>;
}
export const AUTH_TOKEN_CIPHER = Symbol.for("posthog.core.auth.tokenCipher");
export interface ConnectivityStatus {
isOnline: boolean;
}
/**
* Reports network connectivity so the session refresh can avoid pointless
* offline attempts and recover when the network returns. Desktop adapter wraps
* the ConnectivityService (workspace-server connectivity stream).
*/
export interface IAuthConnectivity {
getStatus(): ConnectivityStatus;
onStatusChange(handler: (status: ConnectivityStatus) => void): () => void;
}
export const AUTH_CONNECTIVITY = Symbol.for("posthog.core.auth.connectivity");
/**
* Optional dev/test access-token override (host build env, e.g. Vite
* VITE_POSTHOG_ACCESS_TOKEN_OVERRIDE). Injected as a value so core stays pure
* (no process.env). Bind to null when unset.
*/
export const AUTH_TOKEN_OVERRIDE = Symbol.for(
"posthog.core.auth.tokenOverride",
);