@poppykit/client 0.0.0-stage → 0.1.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.
- package/API.md +25 -0
- package/AUTH.md +51 -0
- package/CHANGELOG.md +22 -0
- package/CONTRIBUTING.md +50 -0
- package/DELIVERY.md +113 -0
- package/INTEGRATIONS.md +87 -0
- package/LICENSE +21 -0
- package/PROVIDER.md +99 -0
- package/README.md +123 -2
- package/RELEASING.md +193 -0
- package/SECURITY.md +13 -0
- package/STORAGE.md +99 -0
- package/dist/auth/challenge.d.ts +19 -0
- package/dist/auth/challenge.js +68 -0
- package/dist/auth/client-auth.d.ts +297 -0
- package/dist/auth/client-auth.js +1583 -0
- package/dist/auth/ownership.d.ts +9 -0
- package/dist/auth/ownership.js +23 -0
- package/dist/auth/sqlite-store.d.ts +14 -0
- package/dist/auth/sqlite-store.js +123 -0
- package/dist/auth/store.d.ts +19 -0
- package/dist/auth/store.js +1 -0
- package/dist/conversation-store.d.ts +15 -0
- package/dist/conversation-store.js +1 -0
- package/dist/conversation.d.ts +118 -0
- package/dist/conversation.js +404 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +7 -0
- package/dist/integrations.d.ts +30 -0
- package/dist/integrations.js +58 -0
- package/dist/memory.d.ts +15 -0
- package/dist/memory.js +32 -0
- package/dist/network/discovery.d.ts +101 -0
- package/dist/network/discovery.js +276 -0
- package/dist/network/transport.d.ts +31 -0
- package/dist/network/transport.js +305 -0
- package/dist/protocol/sse.d.ts +15 -0
- package/dist/protocol/sse.js +90 -0
- package/dist/protocol/wire.d.ts +128 -0
- package/dist/protocol/wire.js +278 -0
- package/dist/provider-sqlite.d.ts +8 -0
- package/dist/provider-sqlite.js +30 -0
- package/dist/provider.d.ts +121 -0
- package/dist/provider.js +342 -0
- package/dist/sqlite-init.d.ts +2 -0
- package/dist/sqlite-init.js +17 -0
- package/dist/sqlite.d.ts +20 -0
- package/dist/sqlite.js +80 -0
- package/examples/quickstart.mjs +19 -0
- package/package.json +72 -4
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import type { AuthSelection, AuthStore } from './store.js';
|
|
2
|
+
import type { OperationOwner } from './ownership.js';
|
|
3
|
+
import type { JsonObject } from '../protocol/wire.js';
|
|
4
|
+
import type { CompanyMetadata, MetadataResolver } from '../network/discovery.js';
|
|
5
|
+
import type { HttpTransport } from '../network/transport.js';
|
|
6
|
+
import type { ApiTarget, AgentBrowserController, FeedbackReport } from '../integrations.js';
|
|
7
|
+
export type { AuthStore, AuthSelection };
|
|
8
|
+
export interface SecretStore {
|
|
9
|
+
stage(secret: string): Promise<string>;
|
|
10
|
+
read(reference: string): Promise<string | null>;
|
|
11
|
+
remove(reference: string): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface IdentitySigner {
|
|
14
|
+
readonly kid: string;
|
|
15
|
+
publicJwk(): Promise<JsonObject>;
|
|
16
|
+
sign(input: Uint8Array): Promise<Uint8Array>;
|
|
17
|
+
}
|
|
18
|
+
export type AssertionRequest = {
|
|
19
|
+
operationId: string;
|
|
20
|
+
issuer: string;
|
|
21
|
+
} & ({
|
|
22
|
+
purpose: 'client-authentication';
|
|
23
|
+
} | {
|
|
24
|
+
purpose: 'session';
|
|
25
|
+
} | {
|
|
26
|
+
purpose: 'browser';
|
|
27
|
+
sessionId: string;
|
|
28
|
+
returnTo: string;
|
|
29
|
+
});
|
|
30
|
+
export interface AssertionProvider {
|
|
31
|
+
assert(request: AssertionRequest): Promise<{
|
|
32
|
+
assertion: string;
|
|
33
|
+
expiresAt: number;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
export interface ProviderIdentity {
|
|
37
|
+
identity(issuer: string): Promise<{
|
|
38
|
+
clientId: string;
|
|
39
|
+
userId: string;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
export type SignInMethod = 'direct' | 'device' | 'mediated';
|
|
43
|
+
export interface AuthorizationRequirement {
|
|
44
|
+
requiredScopes: string[];
|
|
45
|
+
grantedScopes: string[];
|
|
46
|
+
missingScopes: string[];
|
|
47
|
+
sufficient: boolean;
|
|
48
|
+
methods: {
|
|
49
|
+
method: SignInMethod;
|
|
50
|
+
scopes: string[];
|
|
51
|
+
}[];
|
|
52
|
+
organization: {
|
|
53
|
+
name: string;
|
|
54
|
+
domain: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface TrustedInput {
|
|
58
|
+
collect(request: {
|
|
59
|
+
operationId: string;
|
|
60
|
+
issuer: string;
|
|
61
|
+
organization: {
|
|
62
|
+
name: string;
|
|
63
|
+
domain: string;
|
|
64
|
+
};
|
|
65
|
+
fields: {
|
|
66
|
+
name: string;
|
|
67
|
+
label: string;
|
|
68
|
+
secret: boolean;
|
|
69
|
+
}[];
|
|
70
|
+
challenge?: {
|
|
71
|
+
id: string;
|
|
72
|
+
sentTo: string;
|
|
73
|
+
expiresAt: number;
|
|
74
|
+
};
|
|
75
|
+
}): Promise<Record<string, string> | null>;
|
|
76
|
+
}
|
|
77
|
+
export interface SignInInput {
|
|
78
|
+
method?: SignInMethod;
|
|
79
|
+
scopes: string[];
|
|
80
|
+
redirectUri?: string;
|
|
81
|
+
browserBinding?: string;
|
|
82
|
+
force?: boolean;
|
|
83
|
+
requiredExistingScopes?: string[];
|
|
84
|
+
}
|
|
85
|
+
export interface SignInStart {
|
|
86
|
+
outcome: AuthOutcome;
|
|
87
|
+
authorizationUrl?: string;
|
|
88
|
+
device?: {
|
|
89
|
+
verificationUri: string;
|
|
90
|
+
verificationUriComplete?: string;
|
|
91
|
+
userCode: string;
|
|
92
|
+
organization: {
|
|
93
|
+
name: string;
|
|
94
|
+
domain: string;
|
|
95
|
+
};
|
|
96
|
+
nextPollAt: number;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export interface ClientAuthOptions {
|
|
100
|
+
namespace: string;
|
|
101
|
+
localUserId: string;
|
|
102
|
+
clientId: string;
|
|
103
|
+
redirectUris: readonly string[];
|
|
104
|
+
identity?: IdentitySigner;
|
|
105
|
+
assertions?: AssertionProvider;
|
|
106
|
+
providerIdentity?: ProviderIdentity;
|
|
107
|
+
trustedInput?: TrustedInput;
|
|
108
|
+
store: AuthStore;
|
|
109
|
+
secrets: SecretStore;
|
|
110
|
+
transport: HttpTransport;
|
|
111
|
+
metadata: MetadataResolver;
|
|
112
|
+
now?: () => number;
|
|
113
|
+
ownerAlive?: (owner: OperationOwner) => boolean;
|
|
114
|
+
}
|
|
115
|
+
export type ConnectionStatus = 'signed_out' | 'signed_in' | 'disconnected' | 'uncertain';
|
|
116
|
+
export interface Connection {
|
|
117
|
+
id: string;
|
|
118
|
+
domain: string;
|
|
119
|
+
issuer: string;
|
|
120
|
+
organization: {
|
|
121
|
+
name: string;
|
|
122
|
+
domain: string;
|
|
123
|
+
};
|
|
124
|
+
sessionId: string | null;
|
|
125
|
+
generation: number;
|
|
126
|
+
status: ConnectionStatus;
|
|
127
|
+
scopes: string[];
|
|
128
|
+
}
|
|
129
|
+
export type OperationStatus = 'pending' | 'completed' | 'denied' | 'expired' | 'cancelled' | 'failed' | 'uncertain';
|
|
130
|
+
export interface AuthOutcome {
|
|
131
|
+
operationId: string;
|
|
132
|
+
status: OperationStatus;
|
|
133
|
+
connection: Connection;
|
|
134
|
+
error?: string;
|
|
135
|
+
grantedScopes?: string[];
|
|
136
|
+
missingScopes?: string[];
|
|
137
|
+
retryAfterMs?: number;
|
|
138
|
+
nextAction?: 'wait' | 'sign_in' | 'retry_cleanup';
|
|
139
|
+
}
|
|
140
|
+
export interface SignOutOutcome {
|
|
141
|
+
connection: Connection;
|
|
142
|
+
cleanup: 'complete' | 'pending' | 'uncertain';
|
|
143
|
+
}
|
|
144
|
+
export interface ConversationTarget {
|
|
145
|
+
issuer: string;
|
|
146
|
+
endpoint: string;
|
|
147
|
+
resource?: string;
|
|
148
|
+
}
|
|
149
|
+
export interface ClientAuth {
|
|
150
|
+
start(domain: string, input?: {
|
|
151
|
+
anonymous?: boolean;
|
|
152
|
+
}): Promise<AuthOutcome>;
|
|
153
|
+
get(connectionId: string): Promise<Connection | null>;
|
|
154
|
+
list(): Promise<Connection[]>;
|
|
155
|
+
target(connectionId: string): Promise<ConversationTarget>;
|
|
156
|
+
authorization(connectionId: string, requiredScopes: readonly string[]): Promise<AuthorizationRequirement>;
|
|
157
|
+
beginSignIn(connectionId: string, input: SignInInput): Promise<SignInStart>;
|
|
158
|
+
continueSignIn(operationId: string): Promise<AuthOutcome>;
|
|
159
|
+
completeSignIn(input: {
|
|
160
|
+
callbackUrl: string;
|
|
161
|
+
browserBinding: string;
|
|
162
|
+
}): Promise<AuthOutcome>;
|
|
163
|
+
cancelSignIn(operationId: string): Promise<AuthOutcome>;
|
|
164
|
+
operation(operationId: string): Promise<AuthOutcome | null>;
|
|
165
|
+
renew(connectionId: string, input?: {
|
|
166
|
+
resource?: string;
|
|
167
|
+
scopes?: string[];
|
|
168
|
+
}): Promise<AuthOutcome>;
|
|
169
|
+
signOut(connectionId: string): Promise<SignOutOutcome>;
|
|
170
|
+
retryCleanup(connectionId: string): Promise<SignOutOutcome>;
|
|
171
|
+
recover(): Promise<AuthOutcome[]>;
|
|
172
|
+
authorizedFetch(connectionId: string, request: Request, target: ConversationTarget, requiredScopes?: readonly string[]): Promise<Response>;
|
|
173
|
+
apiTarget(connectionId: string, apiUrl: string, destination?: string): Promise<ApiTarget>;
|
|
174
|
+
apiFetch(connectionId: string, request: Request, target: ApiTarget, requiredScopes?: readonly string[]): Promise<Response>;
|
|
175
|
+
joinBrowser(connectionId: string, returnTo: string, controller: AgentBrowserController): Promise<void>;
|
|
176
|
+
feedback(connectionId: string, report: FeedbackReport): Promise<void>;
|
|
177
|
+
}
|
|
178
|
+
export interface CredentialRecord {
|
|
179
|
+
secretRef: string;
|
|
180
|
+
tokenType: 'DPoP' | 'Bearer';
|
|
181
|
+
dpopKeyRef: string;
|
|
182
|
+
scopes: string[];
|
|
183
|
+
expiresAt: number;
|
|
184
|
+
generation: number;
|
|
185
|
+
}
|
|
186
|
+
export interface ConnectionRecord {
|
|
187
|
+
id: string;
|
|
188
|
+
domain: string;
|
|
189
|
+
issuer: string;
|
|
190
|
+
metadata: CompanyMetadata;
|
|
191
|
+
userId: string;
|
|
192
|
+
dpopKeyRef: string;
|
|
193
|
+
sessionId: string | null;
|
|
194
|
+
generation: number;
|
|
195
|
+
status: ConnectionStatus;
|
|
196
|
+
grantId: string | null;
|
|
197
|
+
slots: Record<string, CredentialRecord>;
|
|
198
|
+
anonymous?: boolean;
|
|
199
|
+
notBefore?: string;
|
|
200
|
+
}
|
|
201
|
+
export interface GrantRecord {
|
|
202
|
+
id: string;
|
|
203
|
+
issuer: string;
|
|
204
|
+
userId: string;
|
|
205
|
+
secretRef: string;
|
|
206
|
+
scopes: string[];
|
|
207
|
+
expiresAt: number | null;
|
|
208
|
+
generation: number;
|
|
209
|
+
status: 'active' | 'uncertain' | 'revoking' | 'revoked';
|
|
210
|
+
operationId: string | null;
|
|
211
|
+
}
|
|
212
|
+
export interface DirectRecord {
|
|
213
|
+
stateHash: string;
|
|
214
|
+
verifierRef: string;
|
|
215
|
+
browserHash: string;
|
|
216
|
+
redirectUri: string;
|
|
217
|
+
issuer: string;
|
|
218
|
+
clientId: string;
|
|
219
|
+
sessionId: string;
|
|
220
|
+
}
|
|
221
|
+
export interface OperationRecord {
|
|
222
|
+
owner?: OperationOwner;
|
|
223
|
+
epoch: string;
|
|
224
|
+
id: string;
|
|
225
|
+
kind: 'start' | 'renew' | 'sign_in';
|
|
226
|
+
connectionId: string;
|
|
227
|
+
connectionGeneration: number;
|
|
228
|
+
grantId: string | null;
|
|
229
|
+
grantGeneration: number | null;
|
|
230
|
+
phase: 'prepared' | 'dispatched' | 'staged' | 'terminal';
|
|
231
|
+
status: OperationStatus;
|
|
232
|
+
createdAt: number;
|
|
233
|
+
expiresAt: number;
|
|
234
|
+
resource: string | null;
|
|
235
|
+
scopes: string[];
|
|
236
|
+
direct: DirectRecord | null;
|
|
237
|
+
staged: StagedRefresh | null;
|
|
238
|
+
result: AuthOutcome | null;
|
|
239
|
+
method?: SignInMethod;
|
|
240
|
+
requiredExistingScopes?: string[];
|
|
241
|
+
signInSessionId?: string;
|
|
242
|
+
device?: {
|
|
243
|
+
codeRef: string;
|
|
244
|
+
intervalMs: number;
|
|
245
|
+
nextPollAt: number;
|
|
246
|
+
};
|
|
247
|
+
mediated?: {
|
|
248
|
+
challengeId: string;
|
|
249
|
+
sentTo: string;
|
|
250
|
+
};
|
|
251
|
+
cancelRequested?: boolean;
|
|
252
|
+
}
|
|
253
|
+
export interface StagedRefresh {
|
|
254
|
+
tokenType?: 'DPoP' | 'Bearer';
|
|
255
|
+
accessRef: string;
|
|
256
|
+
refreshRef: string | null;
|
|
257
|
+
sessionId: string;
|
|
258
|
+
scopes: string[];
|
|
259
|
+
signedIn: boolean;
|
|
260
|
+
expiresAt: number;
|
|
261
|
+
refreshExpiresAt: number | null;
|
|
262
|
+
}
|
|
263
|
+
export interface CleanupRecord {
|
|
264
|
+
id: string;
|
|
265
|
+
connectionId: string;
|
|
266
|
+
issuer: string;
|
|
267
|
+
revocationEndpoint: string;
|
|
268
|
+
secretRef: string;
|
|
269
|
+
status: 'pending' | 'uncertain';
|
|
270
|
+
notBefore?: string;
|
|
271
|
+
}
|
|
272
|
+
export interface ClientAuthState {
|
|
273
|
+
version: 1;
|
|
274
|
+
epoch: string;
|
|
275
|
+
owner: {
|
|
276
|
+
namespace: string;
|
|
277
|
+
clientId: string;
|
|
278
|
+
localUserId: string;
|
|
279
|
+
} | null;
|
|
280
|
+
identities: Record<string, {
|
|
281
|
+
userId: string;
|
|
282
|
+
dpopKeyRef: string;
|
|
283
|
+
}>;
|
|
284
|
+
connections: Record<string, ConnectionRecord>;
|
|
285
|
+
grants: Record<string, GrantRecord>;
|
|
286
|
+
operations: Record<string, OperationRecord>;
|
|
287
|
+
cleanup: Record<string, CleanupRecord>;
|
|
288
|
+
}
|
|
289
|
+
export declare class AuthFailure extends Error {
|
|
290
|
+
readonly code: string;
|
|
291
|
+
readonly connectionId?: string | undefined;
|
|
292
|
+
readonly retryAfterMs?: number | undefined;
|
|
293
|
+
readonly retryAt?: string | undefined;
|
|
294
|
+
constructor(code: string, connectionId?: string | undefined, retryAfterMs?: number | undefined, retryAt?: string | undefined);
|
|
295
|
+
}
|
|
296
|
+
export declare function initialClientAuthState(): ClientAuthState;
|
|
297
|
+
export declare function createClientAuth(options: ClientAuthOptions): ClientAuth;
|