@treeseed/sdk 0.10.7 → 0.10.8
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/dist/api/auth/d1-provider.d.ts +5 -0
- package/dist/api/auth/d1-provider.js +3 -0
- package/dist/api/auth/d1-store.d.ts +5 -0
- package/dist/api/auth/d1-store.js +62 -0
- package/dist/api/auth/memory-provider.d.ts +5 -0
- package/dist/api/auth/memory-provider.js +41 -0
- package/dist/api/types.d.ts +5 -0
- package/dist/market-client.d.ts +119 -0
- package/dist/market-client.js +79 -0
- package/dist/operations/services/project-platform.js +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,11 @@ export declare class D1AuthProvider implements ApiAuthProvider {
|
|
|
10
10
|
startDeviceFlow(request: DeviceCodeStartRequest): Promise<DeviceCodeStartResponse>;
|
|
11
11
|
pollDeviceFlow(request: DeviceCodePollRequest): Promise<DeviceCodePollResponse>;
|
|
12
12
|
refreshAccessToken(request: TokenRefreshRequest): Promise<TokenRefreshResponse>;
|
|
13
|
+
issueUserSession(userId: string, options?: {
|
|
14
|
+
sessionType?: string;
|
|
15
|
+
scopes?: string[];
|
|
16
|
+
data?: Record<string, unknown>;
|
|
17
|
+
}): Promise<TokenRefreshResponse>;
|
|
13
18
|
approveDeviceFlow(request: DeviceCodeApproveRequest): Promise<{
|
|
14
19
|
ok: true;
|
|
15
20
|
}>;
|
|
@@ -34,6 +34,9 @@ class D1AuthProvider {
|
|
|
34
34
|
refreshAccessToken(request) {
|
|
35
35
|
return this.store.refreshAccessToken(request);
|
|
36
36
|
}
|
|
37
|
+
issueUserSession(userId, options = {}) {
|
|
38
|
+
return this.store.issueUserSession(userId, options);
|
|
39
|
+
}
|
|
37
40
|
approveDeviceFlow(request) {
|
|
38
41
|
return this.store.approveDeviceFlow(request);
|
|
39
42
|
}
|
|
@@ -58,6 +58,11 @@ export declare class D1AuthStore {
|
|
|
58
58
|
ok: true;
|
|
59
59
|
}>;
|
|
60
60
|
pollDeviceFlow(request: DeviceCodePollRequest): Promise<DeviceCodePollResponse>;
|
|
61
|
+
issueUserSession(userId: string, options?: {
|
|
62
|
+
sessionType?: string;
|
|
63
|
+
scopes?: string[];
|
|
64
|
+
data?: Record<string, unknown>;
|
|
65
|
+
}): Promise<TokenRefreshResponse>;
|
|
61
66
|
refreshAccessToken(request: TokenRefreshRequest): Promise<TokenRefreshResponse>;
|
|
62
67
|
createPersonalAccessToken(userId: string, input: {
|
|
63
68
|
name: string;
|
|
@@ -650,6 +650,68 @@ class D1AuthStore {
|
|
|
650
650
|
}
|
|
651
651
|
};
|
|
652
652
|
}
|
|
653
|
+
async issueUserSession(userId, options = {}) {
|
|
654
|
+
await this.ensureInitialized();
|
|
655
|
+
const principalRecord = await this.principalForUser(userId);
|
|
656
|
+
const refreshToken = nextOpaqueToken("refresh");
|
|
657
|
+
const sessionId = randomUUID();
|
|
658
|
+
const refreshTokenHash = stableHash(refreshToken, this.config.authSecret);
|
|
659
|
+
const expiresAt = addSeconds(now(), this.config.accessTokenTtlSeconds);
|
|
660
|
+
const refreshExpiresAt = addSeconds(now(), this.config.refreshTokenTtlSeconds);
|
|
661
|
+
const requestedScopes = options.scopes && options.scopes.length > 0 ? [...new Set(options.scopes)] : principalRecord.principal.scopes;
|
|
662
|
+
await this.run(
|
|
663
|
+
`INSERT INTO auth_sessions (id, user_id, session_type, refresh_token_hash, scopes_json, expires_at, revoked_at, data_json, created_at, updated_at)
|
|
664
|
+
VALUES (?, ?, ?, ?, ?, ?, NULL, ?, ?, ?)`,
|
|
665
|
+
[
|
|
666
|
+
sessionId,
|
|
667
|
+
userId,
|
|
668
|
+
options.sessionType?.trim() || "web",
|
|
669
|
+
refreshTokenHash,
|
|
670
|
+
JSON.stringify(requestedScopes),
|
|
671
|
+
refreshExpiresAt.toISOString(),
|
|
672
|
+
JSON.stringify(options.data ?? {}),
|
|
673
|
+
isoNow(),
|
|
674
|
+
isoNow()
|
|
675
|
+
]
|
|
676
|
+
);
|
|
677
|
+
const accessToken = createAccessToken({
|
|
678
|
+
sub: principalRecord.principal.id,
|
|
679
|
+
displayName: principalRecord.principal.displayName,
|
|
680
|
+
scopes: requestedScopes,
|
|
681
|
+
roles: principalRecord.principal.roles,
|
|
682
|
+
permissions: principalRecord.principal.permissions,
|
|
683
|
+
metadata: {
|
|
684
|
+
...principalRecord.principal.metadata,
|
|
685
|
+
sessionId
|
|
686
|
+
},
|
|
687
|
+
iat: Math.floor(Date.now() / 1e3),
|
|
688
|
+
exp: Math.floor(expiresAt.getTime() / 1e3),
|
|
689
|
+
iss: this.config.issuer,
|
|
690
|
+
jti: randomUUID(),
|
|
691
|
+
tokenType: "access"
|
|
692
|
+
}, this.config.authSecret);
|
|
693
|
+
await this.writeAuditEvent({
|
|
694
|
+
actorType: "user",
|
|
695
|
+
actorId: userId,
|
|
696
|
+
eventType: "auth.session_issued",
|
|
697
|
+
targetType: "auth_session",
|
|
698
|
+
targetId: sessionId,
|
|
699
|
+
data: { sessionType: options.sessionType ?? "web" }
|
|
700
|
+
});
|
|
701
|
+
return {
|
|
702
|
+
ok: true,
|
|
703
|
+
status: "approved",
|
|
704
|
+
accessToken,
|
|
705
|
+
refreshToken,
|
|
706
|
+
tokenType: "Bearer",
|
|
707
|
+
expiresAt: expiresAt.toISOString(),
|
|
708
|
+
expiresInSeconds: this.config.accessTokenTtlSeconds,
|
|
709
|
+
principal: {
|
|
710
|
+
...principalRecord.principal,
|
|
711
|
+
scopes: requestedScopes
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
}
|
|
653
715
|
async refreshAccessToken(request) {
|
|
654
716
|
await this.ensureInitialized();
|
|
655
717
|
const refreshHash = stableHash(request.refreshToken, this.config.authSecret);
|
|
@@ -11,6 +11,11 @@ export declare class MemoryDeviceCodeAuthProvider implements ApiAuthProvider {
|
|
|
11
11
|
}>;
|
|
12
12
|
pollDeviceFlow(request: DeviceCodePollRequest): Promise<DeviceCodePollResponse>;
|
|
13
13
|
refreshAccessToken(request: TokenRefreshRequest): Promise<TokenRefreshResponse>;
|
|
14
|
+
issueUserSession(userId: string, options?: {
|
|
15
|
+
sessionType?: string;
|
|
16
|
+
scopes?: string[];
|
|
17
|
+
data?: Record<string, unknown>;
|
|
18
|
+
}): Promise<TokenRefreshResponse>;
|
|
14
19
|
authenticateBearerToken(token: string): Promise<{
|
|
15
20
|
principal: ApiPrincipal;
|
|
16
21
|
credential: {
|
|
@@ -154,6 +154,47 @@ class MemoryDeviceCodeAuthProvider {
|
|
|
154
154
|
principal: session.principal
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
+
async issueUserSession(userId, options = {}) {
|
|
158
|
+
const principal = {
|
|
159
|
+
id: userId,
|
|
160
|
+
displayName: userId,
|
|
161
|
+
scopes: options.scopes ?? ["auth:me"],
|
|
162
|
+
roles: ["member"],
|
|
163
|
+
permissions: ["auth:read:self"],
|
|
164
|
+
metadata: {
|
|
165
|
+
...options.data ?? {},
|
|
166
|
+
sessionType: options.sessionType ?? "web"
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const refreshToken = nextOpaqueToken("refresh");
|
|
170
|
+
this.refreshSessions.set(refreshToken, {
|
|
171
|
+
principal,
|
|
172
|
+
expiresAt: nowSeconds() + this.config.refreshTokenTtlSeconds
|
|
173
|
+
});
|
|
174
|
+
const expiresAt = nowSeconds() + this.config.accessTokenTtlSeconds;
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
status: "approved",
|
|
178
|
+
accessToken: createAccessToken({
|
|
179
|
+
sub: principal.id,
|
|
180
|
+
displayName: principal.displayName,
|
|
181
|
+
scopes: principal.scopes,
|
|
182
|
+
roles: principal.roles,
|
|
183
|
+
permissions: principal.permissions,
|
|
184
|
+
metadata: principal.metadata,
|
|
185
|
+
iat: nowSeconds(),
|
|
186
|
+
exp: expiresAt,
|
|
187
|
+
iss: this.config.issuer,
|
|
188
|
+
jti: randomUUID(),
|
|
189
|
+
tokenType: "access"
|
|
190
|
+
}, this.config.authSecret),
|
|
191
|
+
refreshToken,
|
|
192
|
+
tokenType: "Bearer",
|
|
193
|
+
expiresAt: formatExpiry(expiresAt),
|
|
194
|
+
expiresInSeconds: this.config.accessTokenTtlSeconds,
|
|
195
|
+
principal
|
|
196
|
+
};
|
|
197
|
+
}
|
|
157
198
|
async authenticateBearerToken(token) {
|
|
158
199
|
const payload = verifyAccessToken(token, this.config.authSecret);
|
|
159
200
|
return payload ? {
|
package/dist/api/types.d.ts
CHANGED
|
@@ -83,6 +83,11 @@ export interface ApiAuthProvider {
|
|
|
83
83
|
expiresInSeconds: number;
|
|
84
84
|
principal: ApiPrincipal;
|
|
85
85
|
}>;
|
|
86
|
+
issueUserSession?(userId: string, options?: {
|
|
87
|
+
sessionType?: string;
|
|
88
|
+
scopes?: string[];
|
|
89
|
+
data?: Record<string, unknown>;
|
|
90
|
+
}): Promise<TokenRefreshResponse>;
|
|
86
91
|
}
|
|
87
92
|
export type ApiRuntimeProviderSelections = {
|
|
88
93
|
auth: string;
|
package/dist/market-client.d.ts
CHANGED
|
@@ -19,6 +19,13 @@ export interface MarketSession {
|
|
|
19
19
|
expiresAt?: string;
|
|
20
20
|
principal?: ApiPrincipal | null;
|
|
21
21
|
}
|
|
22
|
+
export interface MarketWebAuthSession {
|
|
23
|
+
accessToken: string;
|
|
24
|
+
refreshToken?: string | null;
|
|
25
|
+
expiresInSeconds?: number;
|
|
26
|
+
principal: ApiPrincipal;
|
|
27
|
+
session?: Record<string, unknown> | null;
|
|
28
|
+
}
|
|
22
29
|
export interface MarketRegistryState {
|
|
23
30
|
version: 1;
|
|
24
31
|
activeMarketId: string;
|
|
@@ -128,6 +135,118 @@ export declare class MarketClient {
|
|
|
128
135
|
logout(): Promise<{
|
|
129
136
|
ok: true;
|
|
130
137
|
}>;
|
|
138
|
+
webSignUp(body: {
|
|
139
|
+
email: string;
|
|
140
|
+
password: string;
|
|
141
|
+
username?: string | null;
|
|
142
|
+
name?: string | null;
|
|
143
|
+
firstName?: string | null;
|
|
144
|
+
lastName?: string | null;
|
|
145
|
+
}): Promise<{
|
|
146
|
+
ok: true;
|
|
147
|
+
payload: MarketWebAuthSession;
|
|
148
|
+
}>;
|
|
149
|
+
webSignIn(body: {
|
|
150
|
+
email?: string;
|
|
151
|
+
username?: string;
|
|
152
|
+
login?: string;
|
|
153
|
+
password: string;
|
|
154
|
+
}): Promise<{
|
|
155
|
+
ok: true;
|
|
156
|
+
payload: MarketWebAuthSession;
|
|
157
|
+
}>;
|
|
158
|
+
checkWebUsername(username: string): Promise<{
|
|
159
|
+
ok: true;
|
|
160
|
+
payload: {
|
|
161
|
+
username: string;
|
|
162
|
+
available: boolean;
|
|
163
|
+
status: string;
|
|
164
|
+
};
|
|
165
|
+
}>;
|
|
166
|
+
webSessions(): Promise<{
|
|
167
|
+
ok: true;
|
|
168
|
+
payload: unknown[];
|
|
169
|
+
}>;
|
|
170
|
+
revokeWebSession(sessionId: string): Promise<{
|
|
171
|
+
ok: true;
|
|
172
|
+
payload: {
|
|
173
|
+
sessionId: string;
|
|
174
|
+
};
|
|
175
|
+
}>;
|
|
176
|
+
updateWebProfile(body: {
|
|
177
|
+
name?: string | null;
|
|
178
|
+
image?: string | null;
|
|
179
|
+
}): Promise<{
|
|
180
|
+
ok: true;
|
|
181
|
+
payload: MarketWebAuthSession;
|
|
182
|
+
}>;
|
|
183
|
+
webAppearance(): Promise<{
|
|
184
|
+
ok: true;
|
|
185
|
+
payload: {
|
|
186
|
+
scheme: string;
|
|
187
|
+
mode: string;
|
|
188
|
+
};
|
|
189
|
+
}>;
|
|
190
|
+
updateWebAppearance(body: {
|
|
191
|
+
colorScheme?: string | null;
|
|
192
|
+
scheme?: string | null;
|
|
193
|
+
themeMode?: string | null;
|
|
194
|
+
mode?: string | null;
|
|
195
|
+
}): Promise<{
|
|
196
|
+
ok: true;
|
|
197
|
+
payload: {
|
|
198
|
+
scheme: string;
|
|
199
|
+
mode: string;
|
|
200
|
+
};
|
|
201
|
+
}>;
|
|
202
|
+
updateWebEmail(body: {
|
|
203
|
+
email: string;
|
|
204
|
+
}): Promise<{
|
|
205
|
+
ok: true;
|
|
206
|
+
payload: MarketWebAuthSession;
|
|
207
|
+
}>;
|
|
208
|
+
updateWebPassword(body: {
|
|
209
|
+
currentPassword?: string;
|
|
210
|
+
password: string;
|
|
211
|
+
}): Promise<{
|
|
212
|
+
ok: true;
|
|
213
|
+
payload: {
|
|
214
|
+
changed: true;
|
|
215
|
+
};
|
|
216
|
+
}>;
|
|
217
|
+
requestWebPasswordReset(body: {
|
|
218
|
+
email: string;
|
|
219
|
+
}): Promise<{
|
|
220
|
+
ok: true;
|
|
221
|
+
payload: {
|
|
222
|
+
sent: true;
|
|
223
|
+
resetToken?: string | null;
|
|
224
|
+
};
|
|
225
|
+
}>;
|
|
226
|
+
completeWebPasswordReset(body: {
|
|
227
|
+
token: string;
|
|
228
|
+
password: string;
|
|
229
|
+
}): Promise<{
|
|
230
|
+
ok: true;
|
|
231
|
+
payload: {
|
|
232
|
+
reset: true;
|
|
233
|
+
};
|
|
234
|
+
}>;
|
|
235
|
+
accountDeletionBlockers(): Promise<{
|
|
236
|
+
ok: true;
|
|
237
|
+
payload: {
|
|
238
|
+
blockers: unknown[];
|
|
239
|
+
canDelete: boolean;
|
|
240
|
+
};
|
|
241
|
+
}>;
|
|
242
|
+
deleteAccount(body?: {
|
|
243
|
+
confirmation?: string;
|
|
244
|
+
}): Promise<{
|
|
245
|
+
ok: true;
|
|
246
|
+
payload: {
|
|
247
|
+
deleted: true;
|
|
248
|
+
};
|
|
249
|
+
}>;
|
|
131
250
|
me(): Promise<{
|
|
132
251
|
ok: true;
|
|
133
252
|
payload: {
|
package/dist/market-client.js
CHANGED
|
@@ -319,6 +319,85 @@ class MarketClient {
|
|
|
319
319
|
requireAuth: true
|
|
320
320
|
});
|
|
321
321
|
}
|
|
322
|
+
webSignUp(body) {
|
|
323
|
+
return this.request("/v1/auth/web/sign-up", {
|
|
324
|
+
method: "POST",
|
|
325
|
+
body
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
webSignIn(body) {
|
|
329
|
+
return this.request("/v1/auth/web/sign-in", {
|
|
330
|
+
method: "POST",
|
|
331
|
+
body
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
checkWebUsername(username) {
|
|
335
|
+
return this.request(
|
|
336
|
+
`/v1/auth/web/username/check?username=${encodeURIComponent(username)}`
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
webSessions() {
|
|
340
|
+
return this.request("/v1/auth/web/sessions", { requireAuth: true });
|
|
341
|
+
}
|
|
342
|
+
revokeWebSession(sessionId) {
|
|
343
|
+
return this.request(
|
|
344
|
+
`/v1/auth/web/sessions/${encodeURIComponent(sessionId)}/revoke`,
|
|
345
|
+
{ method: "POST", requireAuth: true }
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
updateWebProfile(body) {
|
|
349
|
+
return this.request("/v1/auth/web/profile", {
|
|
350
|
+
method: "PATCH",
|
|
351
|
+
body,
|
|
352
|
+
requireAuth: true
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
webAppearance() {
|
|
356
|
+
return this.request("/v1/auth/web/appearance", { requireAuth: true });
|
|
357
|
+
}
|
|
358
|
+
updateWebAppearance(body) {
|
|
359
|
+
return this.request("/v1/auth/web/appearance", {
|
|
360
|
+
method: "PATCH",
|
|
361
|
+
body,
|
|
362
|
+
requireAuth: true
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
updateWebEmail(body) {
|
|
366
|
+
return this.request("/v1/auth/web/email", {
|
|
367
|
+
method: "PATCH",
|
|
368
|
+
body,
|
|
369
|
+
requireAuth: true
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
updateWebPassword(body) {
|
|
373
|
+
return this.request("/v1/auth/web/password", {
|
|
374
|
+
method: "PATCH",
|
|
375
|
+
body,
|
|
376
|
+
requireAuth: true
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
requestWebPasswordReset(body) {
|
|
380
|
+
return this.request("/v1/auth/web/password-reset/request", {
|
|
381
|
+
method: "POST",
|
|
382
|
+
body
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
completeWebPasswordReset(body) {
|
|
386
|
+
return this.request("/v1/auth/web/password-reset/complete", {
|
|
387
|
+
method: "POST",
|
|
388
|
+
body
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
accountDeletionBlockers() {
|
|
392
|
+
return this.request("/v1/auth/web/account/deletion-blockers", { requireAuth: true });
|
|
393
|
+
}
|
|
394
|
+
deleteAccount(body = {}) {
|
|
395
|
+
return this.request("/v1/auth/web/account", {
|
|
396
|
+
method: "DELETE",
|
|
397
|
+
body,
|
|
398
|
+
requireAuth: true
|
|
399
|
+
});
|
|
400
|
+
}
|
|
322
401
|
me() {
|
|
323
402
|
return this.request("/v1/me", { requireAuth: true });
|
|
324
403
|
}
|
|
@@ -45,7 +45,7 @@ import { CloudflareQueuePullClient, CloudflareQueuePushClient } from "../../remo
|
|
|
45
45
|
import { runPrefixedCommand, runTreeseedBootstrapDag, sleep, writeTreeseedBootstrapLine } from "./bootstrap-runner.js";
|
|
46
46
|
import { runTenantDeployPreflight } from "./save-deploy-preflight.js";
|
|
47
47
|
const PROJECT_PLATFORM_BOOTSTRAP_SYSTEMS = ["data", "web", "api", "agents"];
|
|
48
|
-
const WEB_PLATFORM_BOOTSTRAP_SYSTEMS =
|
|
48
|
+
const WEB_PLATFORM_BOOTSTRAP_SYSTEMS = PROJECT_PLATFORM_BOOTSTRAP_SYSTEMS;
|
|
49
49
|
const PROCESSING_PLATFORM_BOOTSTRAP_SYSTEMS = ["api", "agents"];
|
|
50
50
|
function stableHash(value) {
|
|
51
51
|
return createHash("sha256").update(value).digest("hex");
|