@treeseed/sdk 0.10.7 → 0.10.9
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 -9
- 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;
|
|
@@ -198,15 +198,6 @@ class D1AuthStore {
|
|
|
198
198
|
}
|
|
199
199
|
async seedCatalog() {
|
|
200
200
|
const createdAt = isoNow();
|
|
201
|
-
const seeded = await this.first(
|
|
202
|
-
`SELECT key FROM permissions WHERE key = '*:*:*' LIMIT 1`
|
|
203
|
-
);
|
|
204
|
-
const adminRole = await this.first(
|
|
205
|
-
`SELECT key FROM roles WHERE key = 'platform_admin' LIMIT 1`
|
|
206
|
-
);
|
|
207
|
-
if (seeded?.key && adminRole?.key) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
201
|
for (const permission of DEFAULT_PERMISSIONS) {
|
|
211
202
|
await this.run(
|
|
212
203
|
`INSERT OR IGNORE INTO permissions (id, key, resource, action, scope, description, created_at)
|
|
@@ -650,6 +641,68 @@ class D1AuthStore {
|
|
|
650
641
|
}
|
|
651
642
|
};
|
|
652
643
|
}
|
|
644
|
+
async issueUserSession(userId, options = {}) {
|
|
645
|
+
await this.ensureInitialized();
|
|
646
|
+
const principalRecord = await this.principalForUser(userId);
|
|
647
|
+
const refreshToken = nextOpaqueToken("refresh");
|
|
648
|
+
const sessionId = randomUUID();
|
|
649
|
+
const refreshTokenHash = stableHash(refreshToken, this.config.authSecret);
|
|
650
|
+
const expiresAt = addSeconds(now(), this.config.accessTokenTtlSeconds);
|
|
651
|
+
const refreshExpiresAt = addSeconds(now(), this.config.refreshTokenTtlSeconds);
|
|
652
|
+
const requestedScopes = options.scopes && options.scopes.length > 0 ? [...new Set(options.scopes)] : principalRecord.principal.scopes;
|
|
653
|
+
await this.run(
|
|
654
|
+
`INSERT INTO auth_sessions (id, user_id, session_type, refresh_token_hash, scopes_json, expires_at, revoked_at, data_json, created_at, updated_at)
|
|
655
|
+
VALUES (?, ?, ?, ?, ?, ?, NULL, ?, ?, ?)`,
|
|
656
|
+
[
|
|
657
|
+
sessionId,
|
|
658
|
+
userId,
|
|
659
|
+
options.sessionType?.trim() || "web",
|
|
660
|
+
refreshTokenHash,
|
|
661
|
+
JSON.stringify(requestedScopes),
|
|
662
|
+
refreshExpiresAt.toISOString(),
|
|
663
|
+
JSON.stringify(options.data ?? {}),
|
|
664
|
+
isoNow(),
|
|
665
|
+
isoNow()
|
|
666
|
+
]
|
|
667
|
+
);
|
|
668
|
+
const accessToken = createAccessToken({
|
|
669
|
+
sub: principalRecord.principal.id,
|
|
670
|
+
displayName: principalRecord.principal.displayName,
|
|
671
|
+
scopes: requestedScopes,
|
|
672
|
+
roles: principalRecord.principal.roles,
|
|
673
|
+
permissions: principalRecord.principal.permissions,
|
|
674
|
+
metadata: {
|
|
675
|
+
...principalRecord.principal.metadata,
|
|
676
|
+
sessionId
|
|
677
|
+
},
|
|
678
|
+
iat: Math.floor(Date.now() / 1e3),
|
|
679
|
+
exp: Math.floor(expiresAt.getTime() / 1e3),
|
|
680
|
+
iss: this.config.issuer,
|
|
681
|
+
jti: randomUUID(),
|
|
682
|
+
tokenType: "access"
|
|
683
|
+
}, this.config.authSecret);
|
|
684
|
+
await this.writeAuditEvent({
|
|
685
|
+
actorType: "user",
|
|
686
|
+
actorId: userId,
|
|
687
|
+
eventType: "auth.session_issued",
|
|
688
|
+
targetType: "auth_session",
|
|
689
|
+
targetId: sessionId,
|
|
690
|
+
data: { sessionType: options.sessionType ?? "web" }
|
|
691
|
+
});
|
|
692
|
+
return {
|
|
693
|
+
ok: true,
|
|
694
|
+
status: "approved",
|
|
695
|
+
accessToken,
|
|
696
|
+
refreshToken,
|
|
697
|
+
tokenType: "Bearer",
|
|
698
|
+
expiresAt: expiresAt.toISOString(),
|
|
699
|
+
expiresInSeconds: this.config.accessTokenTtlSeconds,
|
|
700
|
+
principal: {
|
|
701
|
+
...principalRecord.principal,
|
|
702
|
+
scopes: requestedScopes
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
653
706
|
async refreshAccessToken(request) {
|
|
654
707
|
await this.ensureInitialized();
|
|
655
708
|
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");
|