@open-pencil/cloud 0.0.0-stage → 0.16.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/LICENSE +202 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +7 -0
- package/README.md +37 -2
- package/dist/bin/ai-relay.d.mts +1 -0
- package/dist/bin/ai-relay.mjs +31 -0
- package/dist/bin/ai-relay.mjs.map +1 -0
- package/dist/bin/server.d.mts +1 -0
- package/dist/bin/server.mjs +29 -0
- package/dist/bin/server.mjs.map +1 -0
- package/dist/client.d.ts +1520 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1917 -0
- package/dist/client.js.map +1 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/contract2.js +1453 -0
- package/dist/contract2.js.map +1 -0
- package/dist/email.d.ts +169 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +670 -0
- package/dist/email.js.map +1 -0
- package/dist/index.d.ts +1755 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/listen.mjs +1881 -0
- package/dist/listen.mjs.map +1 -0
- package/dist/runtime-node.d.mts +10040 -0
- package/dist/runtime-node.d.mts.map +1 -0
- package/dist/runtime-node.mjs +32 -0
- package/dist/runtime-node.mjs.map +1 -0
- package/dist/server.d.ts +12792 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +8475 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +8324 -0
- package/dist/server.mjs.map +1 -0
- package/dist/server2.mjs +505 -0
- package/dist/server2.mjs.map +1 -0
- package/package.json +124 -4
- package/src/admin/api/routes.ts +223 -0
- package/src/admin/api/security.ts +12 -0
- package/src/admin/audit/service.ts +138 -0
- package/src/admin/email/service.ts +140 -0
- package/src/admin/enrollment/email.ts +77 -0
- package/src/admin/enrollment/service.ts +308 -0
- package/src/admin/errors.ts +20 -0
- package/src/admin/index.ts +19 -0
- package/src/admin/list.ts +61 -0
- package/src/admin/operations/service.ts +70 -0
- package/src/admin/schema.ts +28 -0
- package/src/admin/users/service.ts +369 -0
- package/src/ai-relay/app.ts +251 -0
- package/src/ai-relay/config.ts +120 -0
- package/src/ai-relay/db/index.ts +10 -0
- package/src/ai-relay/db/migrate.ts +32 -0
- package/src/ai-relay/db/migrations/001_usage.ts +26 -0
- package/src/ai-relay/db/schema.ts +20 -0
- package/src/ai-relay/index.ts +18 -0
- package/src/ai-relay/metering.ts +68 -0
- package/src/ai-relay/usage.ts +115 -0
- package/src/client/ai.ts +96 -0
- package/src/client/api.ts +528 -0
- package/src/client/auth/client.ts +188 -0
- package/src/client/auth/failure.ts +54 -0
- package/src/client/auth/navigation.ts +45 -0
- package/src/client/device-authorization.ts +134 -0
- package/src/client/discovery.ts +105 -0
- package/src/client/images.ts +81 -0
- package/src/client/index.ts +53 -0
- package/src/client/portal/account.ts +183 -0
- package/src/client/portal/administration.ts +130 -0
- package/src/client/portal/client.ts +18 -0
- package/src/client/portal/request.ts +115 -0
- package/src/client/response.ts +51 -0
- package/src/client/workspaces.ts +142 -0
- package/src/contract/account.ts +204 -0
- package/src/contract/admin/index.ts +187 -0
- package/src/contract/ai.ts +150 -0
- package/src/contract/collaboration.ts +45 -0
- package/src/contract/discovery.ts +81 -0
- package/src/contract/documents.ts +265 -0
- package/src/contract/entitlements.ts +28 -0
- package/src/contract/index.ts +204 -0
- package/src/contract/links.ts +87 -0
- package/src/contract/portal.ts +11 -0
- package/src/contract/relay.ts +368 -0
- package/src/contract/sharing.ts +191 -0
- package/src/contract/versions.ts +87 -0
- package/src/contract/workspaces.ts +100 -0
- package/src/email/index.ts +14 -0
- package/src/email/render.ts +276 -0
- package/src/email/schema.ts +144 -0
- package/src/email/templates/brand.ts +105 -0
- package/src/email/templates/document-invitation.ts +35 -0
- package/src/email/templates/enrollment.ts +27 -0
- package/src/email/templates/layout.ts +18 -0
- package/src/runtime/cloudflare/email.ts +70 -0
- package/src/runtime/cloudflare/environment.ts +57 -0
- package/src/runtime/cloudflare/index.ts +3 -0
- package/src/runtime/cloudflare/relay.ts +136 -0
- package/src/runtime/cloudflare/site.ts +13 -0
- package/src/runtime/cloudflare/tsconfig.json +21 -0
- package/src/runtime/cloudflare/worker.ts +160 -0
- package/src/runtime/node/admin.ts +59 -0
- package/src/runtime/node/ai-relay/main.ts +35 -0
- package/src/runtime/node/ai-relay/server.ts +63 -0
- package/src/runtime/node/application.ts +50 -0
- package/src/runtime/node/bootstrap.ts +22 -0
- package/src/runtime/node/cleanup.ts +24 -0
- package/src/runtime/node/command.ts +17 -0
- package/src/runtime/node/config.ts +16 -0
- package/src/runtime/node/email/runtime.ts +43 -0
- package/src/runtime/node/email/transport.ts +112 -0
- package/src/runtime/node/entitlements/main.ts +41 -0
- package/src/runtime/node/entitlements/refusal.ts +15 -0
- package/src/runtime/node/index.ts +25 -0
- package/src/runtime/node/listen.ts +35 -0
- package/src/runtime/node/main.ts +29 -0
- package/src/runtime/node/migrate.ts +13 -0
- package/src/runtime/node/quota-reconcile.ts +9 -0
- package/src/runtime/node/relay.ts +54 -0
- package/src/runtime/node/server.ts +121 -0
- package/src/runtime/node/site.ts +64 -0
- package/src/runtime/postgres/database.ts +19 -0
- package/src/runtime/s3/objects.ts +244 -0
- package/src/runtime/site/server.ts +82 -0
- package/src/server/account/actions.ts +66 -0
- package/src/server/account/routes.ts +300 -0
- package/src/server/ai/errors.ts +7 -0
- package/src/server/ai/index.ts +4 -0
- package/src/server/ai/keys.ts +43 -0
- package/src/server/ai/routes.ts +43 -0
- package/src/server/ai/service.ts +70 -0
- package/src/server/api/index.ts +8 -0
- package/src/server/api/router.ts +117 -0
- package/src/server/api/types.ts +7 -0
- package/src/server/app.ts +375 -0
- package/src/server/auth/account.ts +73 -0
- package/src/server/auth/activity.ts +213 -0
- package/src/server/auth/adapter.ts +79 -0
- package/src/server/auth/email.ts +125 -0
- package/src/server/auth/endpoints.ts +57 -0
- package/src/server/auth/factory.ts +583 -0
- package/src/server/auth/index.ts +17 -0
- package/src/server/auth/mfa-assurance.ts +55 -0
- package/src/server/auth/runtime.ts +26 -0
- package/src/server/auth/session.ts +19 -0
- package/src/server/auth/social-providers.ts +55 -0
- package/src/server/auth/user-agent.ts +16 -0
- package/src/server/auth/workspace-access.ts +23 -0
- package/src/server/cleanup/configured.ts +38 -0
- package/src/server/cleanup/documents.ts +231 -0
- package/src/server/cleanup/index.ts +29 -0
- package/src/server/cleanup/objects.ts +27 -0
- package/src/server/cleanup/revisions.ts +232 -0
- package/src/server/cleanup/uploads.ts +129 -0
- package/src/server/cleanup/worker.ts +79 -0
- package/src/server/collaboration/index.ts +28 -0
- package/src/server/collaboration/relay/authorize.ts +53 -0
- package/src/server/collaboration/relay/awareness.ts +104 -0
- package/src/server/collaboration/relay/documents.ts +39 -0
- package/src/server/collaboration/relay/hub.ts +524 -0
- package/src/server/collaboration/relay/index.ts +15 -0
- package/src/server/collaboration/relay/persistence.ts +48 -0
- package/src/server/collaboration/routes.ts +77 -0
- package/src/server/collaboration/service.ts +188 -0
- package/src/server/config/deployment.ts +178 -0
- package/src/server/config/index.ts +20 -0
- package/src/server/config/limits.ts +8 -0
- package/src/server/config/public.ts +66 -0
- package/src/server/config/schema.ts +512 -0
- package/src/server/db/database.ts +15 -0
- package/src/server/db/expressions.ts +13 -0
- package/src/server/db/index.ts +21 -0
- package/src/server/db/migrate.ts +177 -0
- package/src/server/db/migrations/001_foundation.ts +164 -0
- package/src/server/db/migrations/002_upload_cleanup_claims.ts +34 -0
- package/src/server/db/migrations/003_document_cleanup_claims.ts +23 -0
- package/src/server/db/migrations/004_document_sharing.ts +82 -0
- package/src/server/db/migrations/005_document_collaboration_epoch.ts +13 -0
- package/src/server/db/migrations/006_invitation_continuation.ts +27 -0
- package/src/server/db/migrations/007_collaboration_state.ts +25 -0
- package/src/server/db/migrations/008_storage_reservations.ts +37 -0
- package/src/server/db/migrations/009_workspace_entitlements.ts +22 -0
- package/src/server/db/migrations/010_upload_finalization.ts +22 -0
- package/src/server/db/migrations/011_upload_finalization_lease.ts +12 -0
- package/src/server/db/migrations/012_transactional_email.ts +48 -0
- package/src/server/db/migrations/013_admin_enrollment.ts +54 -0
- package/src/server/db/migrations/014_enrollment_email_kinds.ts +30 -0
- package/src/server/db/migrations/015_cloud_rate_limit.ts +22 -0
- package/src/server/db/migrations/016_auth_schema.ts +16 -0
- package/src/server/db/migrations/017_authentication_email_kinds.ts +32 -0
- package/src/server/db/migrations/018_authentication_mfa.ts +78 -0
- package/src/server/db/migrations/019_better_auth_account_issuer.ts +42 -0
- package/src/server/db/migrations/020_workspace_invitations.ts +57 -0
- package/src/server/db/migrations/021_document_versions.ts +66 -0
- package/src/server/db/migrations/022_entitlement_external_version.ts +17 -0
- package/src/server/db/migrations/023_document_images.ts +61 -0
- package/src/server/db/migrations/024_account_activity.ts +66 -0
- package/src/server/db/migrations/025_table_names.ts +58 -0
- package/src/server/db/migrations/026_user_picture.ts +30 -0
- package/src/server/db/migrations/027_document_kind.ts +19 -0
- package/src/server/db/migrations/helpers.ts +78 -0
- package/src/server/db/tables.ts +394 -0
- package/src/server/documents/access.ts +103 -0
- package/src/server/documents/errors.ts +16 -0
- package/src/server/documents/images.ts +407 -0
- package/src/server/documents/index.ts +14 -0
- package/src/server/documents/limits.ts +57 -0
- package/src/server/documents/repository.ts +141 -0
- package/src/server/documents/routes.ts +239 -0
- package/src/server/documents/service.ts +597 -0
- package/src/server/documents/summary.ts +37 -0
- package/src/server/documents/types.ts +14 -0
- package/src/server/documents/versions/checkpoint.ts +98 -0
- package/src/server/documents/versions/history.ts +25 -0
- package/src/server/documents/versions/index.ts +4 -0
- package/src/server/documents/versions/routes.ts +112 -0
- package/src/server/documents/versions/service.ts +397 -0
- package/src/server/email/crypto.ts +57 -0
- package/src/server/email/index.ts +18 -0
- package/src/server/email/invitations.ts +30 -0
- package/src/server/email/service.ts +245 -0
- package/src/server/email/types.ts +56 -0
- package/src/server/email/worker.ts +33 -0
- package/src/server/index.ts +279 -0
- package/src/server/internal/index.ts +8 -0
- package/src/server/internal/routes.ts +41 -0
- package/src/server/internal/schema.ts +10 -0
- package/src/server/internal/service.ts +44 -0
- package/src/server/invitations/index.ts +6 -0
- package/src/server/invitations/types.ts +30 -0
- package/src/server/objects/index.ts +16 -0
- package/src/server/objects/types.ts +81 -0
- package/src/server/pictures/index.ts +9 -0
- package/src/server/pictures/provider.ts +61 -0
- package/src/server/pictures/routes.ts +21 -0
- package/src/server/pictures/service.ts +235 -0
- package/src/server/policy/configured.ts +23 -0
- package/src/server/policy/database.ts +108 -0
- package/src/server/policy/entitlements.ts +29 -0
- package/src/server/policy/index.ts +17 -0
- package/src/server/policy/keys.ts +23 -0
- package/src/server/policy/policy.ts +117 -0
- package/src/server/policy/provider.ts +67 -0
- package/src/server/policy/schema.ts +69 -0
- package/src/server/policy/service.ts +85 -0
- package/src/server/policy/static.ts +62 -0
- package/src/server/quota/index.ts +7 -0
- package/src/server/quota/reconcile.ts +61 -0
- package/src/server/quota/storage.ts +165 -0
- package/src/server/rate-limit/cleanup.ts +16 -0
- package/src/server/rate-limit/index.ts +12 -0
- package/src/server/rate-limit/keys.ts +38 -0
- package/src/server/rate-limit/middleware.ts +137 -0
- package/src/server/rate-limit/postgres.ts +79 -0
- package/src/server/sharing/access.ts +29 -0
- package/src/server/sharing/actor.ts +12 -0
- package/src/server/sharing/capabilities/service.ts +262 -0
- package/src/server/sharing/continuation.ts +85 -0
- package/src/server/sharing/contracts.ts +80 -0
- package/src/server/sharing/crypto.ts +48 -0
- package/src/server/sharing/document-routes.ts +41 -0
- package/src/server/sharing/errors.ts +12 -0
- package/src/server/sharing/grants/service.ts +79 -0
- package/src/server/sharing/http.ts +41 -0
- package/src/server/sharing/index.ts +39 -0
- package/src/server/sharing/invitations/service.ts +315 -0
- package/src/server/sharing/policy.ts +44 -0
- package/src/server/sharing/routes.ts +251 -0
- package/src/server/sharing/service.ts +117 -0
- package/src/server/validation.ts +24 -0
- package/src/server/worker/interval.ts +23 -0
- package/src/server/worker/periodic.ts +42 -0
- package/src/server/workspaces/index.ts +16 -0
- package/src/server/workspaces/members.ts +502 -0
- package/src/server/workspaces/repository.ts +91 -0
- package/src/server/workspaces/routes.ts +198 -0
- package/src/server/workspaces/service.ts +84 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import type { EnrollmentService } from '#cloud/admin'
|
|
2
|
+
import {
|
|
3
|
+
parseCloudPasswordChange,
|
|
4
|
+
parseCloudMFAEnable,
|
|
5
|
+
parseCloudMFAVerify,
|
|
6
|
+
parseCloudPasskeyDelete,
|
|
7
|
+
parseCloudSocialLink,
|
|
8
|
+
parseCloudUnlinkAuthenticationMethod,
|
|
9
|
+
parseCloudEmailChange,
|
|
10
|
+
parseCloudProfileUpdate,
|
|
11
|
+
parseCloudPictureUpload,
|
|
12
|
+
CLOUD_PICTURE_MAX_BYTES,
|
|
13
|
+
parseCloudSessionRevoke
|
|
14
|
+
} from '#cloud/contract'
|
|
15
|
+
import type { CloudAPIEnvironment } from '#cloud/server/api'
|
|
16
|
+
import {
|
|
17
|
+
createAccountAuthenticationService,
|
|
18
|
+
type CloudAuthAdapter,
|
|
19
|
+
type CloudIdentityResolver,
|
|
20
|
+
type CloudSessionResolver
|
|
21
|
+
} from '#cloud/server/auth'
|
|
22
|
+
import type { CloudServerConfig } from '#cloud/server/config'
|
|
23
|
+
import { PictureInvalidError, type UserPictureService } from '#cloud/server/pictures'
|
|
24
|
+
import { validatedJSON } from '#cloud/server/validation'
|
|
25
|
+
import type { WorkspaceService } from '#cloud/server/workspaces'
|
|
26
|
+
import { Hono, type MiddlewareHandler } from 'hono'
|
|
27
|
+
import { bodyLimit } from 'hono/body-limit'
|
|
28
|
+
import { toUint8Array } from 'js-base64'
|
|
29
|
+
|
|
30
|
+
import { createAccountActions } from './actions'
|
|
31
|
+
|
|
32
|
+
/** Room for a Base64 picture and the JSON around it. */
|
|
33
|
+
const PICTURE_BODY_BYTES = Math.ceil(CLOUD_PICTURE_MAX_BYTES / 3) * 4 + 1024
|
|
34
|
+
|
|
35
|
+
export type AccountRouteDependencies = {
|
|
36
|
+
auth: CloudAuthAdapter
|
|
37
|
+
config: CloudServerConfig
|
|
38
|
+
pictures: UserPictureService
|
|
39
|
+
enrollment: EnrollmentService
|
|
40
|
+
workspaces: WorkspaceService
|
|
41
|
+
resolveIdentity: CloudIdentityResolver
|
|
42
|
+
resolveSession: CloudSessionResolver
|
|
43
|
+
requireActiveSession: MiddlewareHandler<CloudAPIEnvironment>
|
|
44
|
+
authenticatedMutationLimiter: MiddlewareHandler<CloudAPIEnvironment>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createAccountRoutes(services: AccountRouteDependencies) {
|
|
48
|
+
const {
|
|
49
|
+
enrollment,
|
|
50
|
+
workspaces,
|
|
51
|
+
resolveIdentity,
|
|
52
|
+
resolveSession,
|
|
53
|
+
requireActiveSession,
|
|
54
|
+
authenticatedMutationLimiter
|
|
55
|
+
} = services
|
|
56
|
+
const accountAuthentication = createAccountAuthenticationService(services.auth, services.config)
|
|
57
|
+
const { accountAction, activeAccountAction, verifiedMFAAction } =
|
|
58
|
+
createAccountActions(resolveSession)
|
|
59
|
+
return new Hono<CloudAPIEnvironment>()
|
|
60
|
+
.get('/api/account/status', async (context) => {
|
|
61
|
+
const identity = await resolveIdentity(context.req.raw)
|
|
62
|
+
if (!identity) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
63
|
+
let enrollmentStatus = await enrollment.statusForEmail(identity.email)
|
|
64
|
+
if (services.config.enrollmentMode === 'approval' && !enrollmentStatus) {
|
|
65
|
+
await enrollment.request({ email: identity.email, name: identity.name })
|
|
66
|
+
enrollmentStatus = 'pending'
|
|
67
|
+
}
|
|
68
|
+
const state =
|
|
69
|
+
services.config.enrollmentMode !== 'approval' || enrollmentStatus === 'approved'
|
|
70
|
+
? ('active' as const)
|
|
71
|
+
: (enrollmentStatus ?? 'pending')
|
|
72
|
+
if (state === 'active') await workspaces.ensurePersonal(identity)
|
|
73
|
+
return context.json({ user: identity, state })
|
|
74
|
+
})
|
|
75
|
+
.get('/api/account/mfa', async (context) => {
|
|
76
|
+
const actor = await resolveSession(context.req.raw)
|
|
77
|
+
if (!actor) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
78
|
+
const mfa = await services.auth.mfaStatus(context.req.raw.headers)
|
|
79
|
+
return mfa
|
|
80
|
+
? context.json({ mfa })
|
|
81
|
+
: context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
82
|
+
})
|
|
83
|
+
.post('/api/account/mfa/totp/enable', validatedJSON(parseCloudMFAEnable), async (context) => {
|
|
84
|
+
const result = await activeAccountAction(context, () =>
|
|
85
|
+
services.auth.enableTOTP(context.req.raw.headers, context.req.valid('json').password)
|
|
86
|
+
)
|
|
87
|
+
return result instanceof Response ? result : context.json(result)
|
|
88
|
+
})
|
|
89
|
+
.post('/api/account/mfa/totp/verify', validatedJSON(parseCloudMFAVerify), (context) =>
|
|
90
|
+
verifiedMFAAction(context, resolveSession, () =>
|
|
91
|
+
services.auth.verifyTOTP(context.req.raw.headers, context.req.valid('json').code)
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
.post('/api/account/mfa/recovery/verify', validatedJSON(parseCloudMFAVerify), (context) =>
|
|
95
|
+
verifiedMFAAction(context, resolveIdentity, () =>
|
|
96
|
+
services.auth.verifyRecoveryCode(context.req.raw.headers, context.req.valid('json').code)
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
.post(
|
|
100
|
+
'/api/account/mfa/recovery/regenerate',
|
|
101
|
+
validatedJSON(parseCloudMFAEnable),
|
|
102
|
+
async (context) => {
|
|
103
|
+
const result = await activeAccountAction(context, () =>
|
|
104
|
+
services.auth.generateRecoveryCodes(
|
|
105
|
+
context.req.raw.headers,
|
|
106
|
+
context.req.valid('json').password
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
return result instanceof Response ? result : context.json({ backupCodes: result })
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
.post('/api/account/mfa/totp/disable', validatedJSON(parseCloudMFAEnable), async (context) => {
|
|
113
|
+
const actor = await resolveSession(context.req.raw)
|
|
114
|
+
if (!actor) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
115
|
+
if (actor.deploymentRole === 'admin' && services.config.deploymentAdminMFARequired) {
|
|
116
|
+
const passkeys = await services.auth.listPasskeys(context.req.raw.headers)
|
|
117
|
+
if (passkeys.length === 0) {
|
|
118
|
+
return context.json({ error: { code: 'mfa_required' as const } }, 403)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const result = await accountAction(
|
|
122
|
+
() =>
|
|
123
|
+
services.auth.disableTOTP(context.req.raw.headers, context.req.valid('json').password),
|
|
124
|
+
context
|
|
125
|
+
)
|
|
126
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
127
|
+
})
|
|
128
|
+
.get('/api/account/mfa/passkeys', async (context) => {
|
|
129
|
+
const actor = await resolveSession(context.req.raw)
|
|
130
|
+
if (!actor) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
131
|
+
return context.json({ passkeys: await services.auth.listPasskeys(context.req.raw.headers) })
|
|
132
|
+
})
|
|
133
|
+
.post(
|
|
134
|
+
'/api/account/mfa/passkeys/delete',
|
|
135
|
+
validatedJSON(parseCloudPasskeyDelete),
|
|
136
|
+
async (context) => {
|
|
137
|
+
const actor = await resolveSession(context.req.raw)
|
|
138
|
+
if (!actor) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
139
|
+
const { id } = context.req.valid('json')
|
|
140
|
+
if (actor.deploymentRole === 'admin' && services.config.deploymentAdminMFARequired) {
|
|
141
|
+
// An administrator keeps at least one second factor: TOTP or another passkey.
|
|
142
|
+
const status = await services.auth.mfaStatus(context.req.raw.headers)
|
|
143
|
+
const passkeys = await services.auth.listPasskeys(context.req.raw.headers)
|
|
144
|
+
const otherPasskeys = passkeys.filter((passkey) => passkey.id !== id)
|
|
145
|
+
if (!status?.totpEnabled && otherPasskeys.length === 0) {
|
|
146
|
+
return context.json({ error: { code: 'mfa_required' as const } }, 403)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const result = await accountAction(
|
|
150
|
+
() => services.auth.deletePasskey(context.req.raw.headers, id),
|
|
151
|
+
context
|
|
152
|
+
)
|
|
153
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
.use('/api/account/authentication/*', requireActiveSession)
|
|
157
|
+
.use('/api/account/authentication/*', authenticatedMutationLimiter)
|
|
158
|
+
.post(
|
|
159
|
+
'/api/account/authentication/change-password',
|
|
160
|
+
validatedJSON(parseCloudPasswordChange),
|
|
161
|
+
async (context) => {
|
|
162
|
+
const result = await accountAction(
|
|
163
|
+
() =>
|
|
164
|
+
accountAuthentication.changePassword(
|
|
165
|
+
context.req.raw.headers,
|
|
166
|
+
context.req.valid('json')
|
|
167
|
+
),
|
|
168
|
+
context
|
|
169
|
+
)
|
|
170
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
.post(
|
|
174
|
+
'/api/account/authentication/link-social',
|
|
175
|
+
validatedJSON(parseCloudSocialLink),
|
|
176
|
+
async (context) => {
|
|
177
|
+
const result = await accountAction(
|
|
178
|
+
() =>
|
|
179
|
+
accountAuthentication.startSocialLink(
|
|
180
|
+
context.req.raw.headers,
|
|
181
|
+
context.req.valid('json')
|
|
182
|
+
),
|
|
183
|
+
context
|
|
184
|
+
)
|
|
185
|
+
return result instanceof Response ? result : context.json({ url: result })
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
.post(
|
|
189
|
+
'/api/account/authentication/unlink',
|
|
190
|
+
validatedJSON(parseCloudUnlinkAuthenticationMethod),
|
|
191
|
+
async (context) => {
|
|
192
|
+
const result = await accountAction(
|
|
193
|
+
() =>
|
|
194
|
+
accountAuthentication.unlink(
|
|
195
|
+
context.req.raw.headers,
|
|
196
|
+
context.req.valid('json').methodId
|
|
197
|
+
),
|
|
198
|
+
context
|
|
199
|
+
)
|
|
200
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
.use('/api/account/profile', requireActiveSession)
|
|
204
|
+
.use('/api/account/profile/*', requireActiveSession)
|
|
205
|
+
.use('/api/account/sessions', requireActiveSession)
|
|
206
|
+
.use('/api/account/sessions/*', requireActiveSession)
|
|
207
|
+
.use('/api/account/sign-ins', requireActiveSession)
|
|
208
|
+
.use('/api/account/profile', authenticatedMutationLimiter)
|
|
209
|
+
.use('/api/account/profile/*', authenticatedMutationLimiter)
|
|
210
|
+
.use('/api/account/sessions/*', authenticatedMutationLimiter)
|
|
211
|
+
.get('/api/account/profile', async (context) => {
|
|
212
|
+
const profile = await services.auth.profile(context.req.raw.headers)
|
|
213
|
+
if (!profile) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
214
|
+
return context.json({
|
|
215
|
+
profile: {
|
|
216
|
+
...profile,
|
|
217
|
+
createdAt: profile.createdAt.toISOString(),
|
|
218
|
+
emailChangeAvailable: services.auth.emailChangeAvailable
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
.post('/api/account/profile', validatedJSON(parseCloudProfileUpdate), async (context) => {
|
|
223
|
+
const result = await accountAction(
|
|
224
|
+
() => services.auth.updateProfile(context.req.raw.headers, context.req.valid('json')),
|
|
225
|
+
context
|
|
226
|
+
)
|
|
227
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
228
|
+
})
|
|
229
|
+
.put(
|
|
230
|
+
'/api/account/profile/picture',
|
|
231
|
+
bodyLimit({
|
|
232
|
+
maxSize: PICTURE_BODY_BYTES,
|
|
233
|
+
onError: (context) => context.json({ error: { code: 'picture_invalid' as const } }, 413)
|
|
234
|
+
}),
|
|
235
|
+
validatedJSON(parseCloudPictureUpload),
|
|
236
|
+
async (context) => {
|
|
237
|
+
const bytes = toUint8Array(context.req.valid('json').data)
|
|
238
|
+
try {
|
|
239
|
+
const image = await services.pictures.upload(context.get('actor').userId, bytes)
|
|
240
|
+
return context.json({ image })
|
|
241
|
+
} catch (error) {
|
|
242
|
+
if (!(error instanceof PictureInvalidError)) throw error
|
|
243
|
+
return context.json({ error: { code: 'picture_invalid' as const } }, 400)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
)
|
|
247
|
+
.delete('/api/account/profile/picture', async (context) => {
|
|
248
|
+
await services.pictures.remove(context.get('actor').userId)
|
|
249
|
+
return context.json({ ok: true as const })
|
|
250
|
+
})
|
|
251
|
+
.post('/api/account/profile/email', validatedJSON(parseCloudEmailChange), async (context) => {
|
|
252
|
+
const result = await accountAction(
|
|
253
|
+
() => accountAuthentication.changeEmail(context.req.raw.headers, context.req.valid('json')),
|
|
254
|
+
context
|
|
255
|
+
)
|
|
256
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
257
|
+
})
|
|
258
|
+
.get('/api/account/sessions', async (context) => {
|
|
259
|
+
const sessions = await services.auth.sessions(context.req.raw.headers)
|
|
260
|
+
if (!sessions) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
261
|
+
return context.json({ sessions })
|
|
262
|
+
})
|
|
263
|
+
.post(
|
|
264
|
+
'/api/account/sessions/revoke',
|
|
265
|
+
validatedJSON(parseCloudSessionRevoke),
|
|
266
|
+
async (context) => {
|
|
267
|
+
const result = await accountAction(
|
|
268
|
+
() =>
|
|
269
|
+
services.auth.revokeSession(
|
|
270
|
+
context.req.raw.headers,
|
|
271
|
+
context.req.valid('json').sessionId
|
|
272
|
+
),
|
|
273
|
+
context
|
|
274
|
+
)
|
|
275
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
276
|
+
}
|
|
277
|
+
)
|
|
278
|
+
.post('/api/account/sessions/revoke-others', async (context) => {
|
|
279
|
+
const result = await accountAction(
|
|
280
|
+
() => services.auth.revokeOtherSessions(context.req.raw.headers),
|
|
281
|
+
context
|
|
282
|
+
)
|
|
283
|
+
return result instanceof Response ? result : context.json({ ok: true as const })
|
|
284
|
+
})
|
|
285
|
+
.get('/api/account/sign-ins', async (context) => {
|
|
286
|
+
const signIns = await services.auth.signIns(context.req.raw.headers)
|
|
287
|
+
if (!signIns) return context.json({ error: { code: 'unauthorized' as const } }, 401)
|
|
288
|
+
return context.json({ signIns })
|
|
289
|
+
})
|
|
290
|
+
.get('/api/account/authentication', async (context) => {
|
|
291
|
+
const result = await accountAction(
|
|
292
|
+
() => accountAuthentication.methods(context.req.raw.headers),
|
|
293
|
+
context
|
|
294
|
+
)
|
|
295
|
+
return result instanceof Response ? result : context.json(result)
|
|
296
|
+
})
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** The account routes' types, for the portal's typed client. */
|
|
300
|
+
export type CloudAccountRoutes = ReturnType<typeof createAccountRoutes>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AINotEntitledError } from './errors'
|
|
2
|
+
export { importAISigningKey, loadAISigningKey, type AISigningKey } from './keys'
|
|
3
|
+
export { createAIRoutes, type AIRouteEnvironment } from './routes'
|
|
4
|
+
export { createAITokenService, type AITokenService, type AITokenServiceOptions } from './service'
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CloudConfigError, type CloudServerConfig } from '#cloud/server/config/schema'
|
|
2
|
+
import { calculateJwkThumbprint, exportJWK, importPKCS8, type JWK } from 'jose'
|
|
3
|
+
|
|
4
|
+
const ALGORITHM = 'ES256'
|
|
5
|
+
|
|
6
|
+
export type AISigningKey = {
|
|
7
|
+
privateKey: CryptoKey
|
|
8
|
+
/** The public half, as published in the JWKS. */
|
|
9
|
+
publicJWK: JWK & { kid: string }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Imports the P-256 key that signs AI service tokens. Its `kid` is the public key's thumbprint,
|
|
14
|
+
* so replacing the key changes the `kid`, and a service that caches the JWKS refetches it on the
|
|
15
|
+
* first token it cannot match. Tokens the old key signed fail once and are re-requested.
|
|
16
|
+
*/
|
|
17
|
+
export async function importAISigningKey(pem: string): Promise<AISigningKey> {
|
|
18
|
+
const privateKey = await importPKCS8(pem, ALGORITHM, { extractable: true })
|
|
19
|
+
const { kty, crv, x, y } = await exportJWK(privateKey)
|
|
20
|
+
const publicJWK = { kty, crv, x, y }
|
|
21
|
+
const kid = await calculateJwkThumbprint(publicJWK)
|
|
22
|
+
return {
|
|
23
|
+
privateKey: await importPKCS8(pem, ALGORITHM),
|
|
24
|
+
publicJWK: { ...publicJWK, kid, alg: ALGORITHM, use: 'sig' }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Imports the configured signing key at startup, so a key that cannot sign stops the runtime
|
|
30
|
+
* instead of failing every token request after discovery has advertised the AI service.
|
|
31
|
+
*/
|
|
32
|
+
export async function loadAISigningKey(
|
|
33
|
+
config: Pick<CloudServerConfig, 'aiSigningKey'>
|
|
34
|
+
): Promise<AISigningKey | undefined> {
|
|
35
|
+
if (!config.aiSigningKey) return undefined
|
|
36
|
+
try {
|
|
37
|
+
return await importAISigningKey(config.aiSigningKey)
|
|
38
|
+
} catch {
|
|
39
|
+
throw new CloudConfigError('AI signing key must be a PKCS #8 P-256 private key')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const AI_SIGNING_ALGORITHM = ALGORITHM
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { parseCreateAIToken } from '#cloud/contract'
|
|
2
|
+
import type { CloudActor } from '#cloud/server/auth'
|
|
3
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
4
|
+
import { DocumentNotFoundError } from '#cloud/server/documents'
|
|
5
|
+
import { CLOUD_RATE_LIMITS, createRouteRateLimiter } from '#cloud/server/rate-limit'
|
|
6
|
+
import { validatedJSON } from '#cloud/server/validation'
|
|
7
|
+
import { Hono } from 'hono'
|
|
8
|
+
import type { Kysely } from 'kysely'
|
|
9
|
+
|
|
10
|
+
import { AINotEntitledError } from './errors'
|
|
11
|
+
import type { AITokenService } from './service'
|
|
12
|
+
|
|
13
|
+
export type AIRouteEnvironment = { Variables: { actor: CloudActor } }
|
|
14
|
+
|
|
15
|
+
/** Without a service, the deployment has no AI service and the token route is not found. */
|
|
16
|
+
export function createAIRoutes(
|
|
17
|
+
service: AITokenService | undefined,
|
|
18
|
+
rateLimit?: { database: Kysely<CloudDatabase>; secret: string }
|
|
19
|
+
) {
|
|
20
|
+
const router = new Hono<AIRouteEnvironment>()
|
|
21
|
+
if (service && rateLimit) {
|
|
22
|
+
router.use(
|
|
23
|
+
'/ai/token',
|
|
24
|
+
createRouteRateLimiter(rateLimit.database, rateLimit.secret, CLOUD_RATE_LIMITS.aiToken)
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
return router.post('/ai/token', validatedJSON(parseCreateAIToken), async (context) => {
|
|
28
|
+
if (!service) return context.json({ error: { code: 'not_found' as const } }, 404)
|
|
29
|
+
try {
|
|
30
|
+
return context.json(
|
|
31
|
+
await service.issue(context.get('actor'), context.req.valid('json').workspaceId)
|
|
32
|
+
)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof DocumentNotFoundError) {
|
|
35
|
+
return context.json({ error: { code: 'not_found' as const } }, 404)
|
|
36
|
+
}
|
|
37
|
+
if (error instanceof AINotEntitledError) {
|
|
38
|
+
return context.json({ error: { code: 'forbidden' as const } }, 403)
|
|
39
|
+
}
|
|
40
|
+
throw error
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CLOUD_AI_TOKEN_AUDIENCE, type AIToken } from '#cloud/contract'
|
|
2
|
+
import type { CloudActor } from '#cloud/server/auth'
|
|
3
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
4
|
+
import { DocumentNotFoundError } from '#cloud/server/documents/errors'
|
|
5
|
+
import { workspaceRole } from '#cloud/server/documents/repository'
|
|
6
|
+
import { CLOUD_FEATURE_KEYS } from '#cloud/server/policy/keys'
|
|
7
|
+
import type { CloudPolicy } from '#cloud/server/policy/policy'
|
|
8
|
+
import { SignJWT } from 'jose'
|
|
9
|
+
import type { Kysely } from 'kysely'
|
|
10
|
+
|
|
11
|
+
import { AINotEntitledError } from './errors'
|
|
12
|
+
import { AI_SIGNING_ALGORITHM, type AISigningKey } from './keys'
|
|
13
|
+
|
|
14
|
+
export type AITokenServiceOptions = {
|
|
15
|
+
database: Kysely<CloudDatabase>
|
|
16
|
+
policy: CloudPolicy
|
|
17
|
+
deploymentMode: 'official' | 'self-hosted'
|
|
18
|
+
/** The Cloud public URL, which services check as the token's `iss`. */
|
|
19
|
+
issuer: string
|
|
20
|
+
signingKey: AISigningKey
|
|
21
|
+
lifetimeSeconds: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createAITokenService(options: AITokenServiceOptions) {
|
|
25
|
+
const { privateKey, publicJWK } = options.signingKey
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
/**
|
|
29
|
+
* Signs a token that lets a workspace member reach the AI service on the workspace's behalf.
|
|
30
|
+
* Entitlements are read for every token, so a plan change reaches the service within one
|
|
31
|
+
* token lifetime.
|
|
32
|
+
*/
|
|
33
|
+
async issue(actor: CloudActor, workspaceId: string): Promise<AIToken> {
|
|
34
|
+
if (!(await workspaceRole(options.database, actor.userId, workspaceId))) {
|
|
35
|
+
throw new DocumentNotFoundError()
|
|
36
|
+
}
|
|
37
|
+
const context = {
|
|
38
|
+
targetingKey: workspaceId,
|
|
39
|
+
actorId: actor.userId,
|
|
40
|
+
workspaceId,
|
|
41
|
+
deploymentMode: options.deploymentMode
|
|
42
|
+
}
|
|
43
|
+
const [enabled, allowance] = await Promise.all([
|
|
44
|
+
options.policy.boolean(CLOUD_FEATURE_KEYS.cloudAI, false, context),
|
|
45
|
+
options.policy.number(CLOUD_FEATURE_KEYS.monthlyCreditAllowance, -1, context)
|
|
46
|
+
])
|
|
47
|
+
if (!enabled) throw new AINotEntitledError()
|
|
48
|
+
const issuedAt = Math.floor(Date.now() / 1000)
|
|
49
|
+
const expiresAt = issuedAt + options.lifetimeSeconds
|
|
50
|
+
const token = await new SignJWT({
|
|
51
|
+
workspaceId,
|
|
52
|
+
monthlyCreditAllowance: allowance < 0 ? null : allowance
|
|
53
|
+
})
|
|
54
|
+
.setProtectedHeader({ alg: AI_SIGNING_ALGORITHM, kid: publicJWK.kid, typ: 'JWT' })
|
|
55
|
+
.setIssuer(options.issuer)
|
|
56
|
+
.setAudience(CLOUD_AI_TOKEN_AUDIENCE)
|
|
57
|
+
.setSubject(actor.userId)
|
|
58
|
+
.setIssuedAt(issuedAt)
|
|
59
|
+
.setExpirationTime(expiresAt)
|
|
60
|
+
.sign(privateKey)
|
|
61
|
+
return { token, expiresAt: new Date(expiresAt * 1000).toISOString() }
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
jwks() {
|
|
65
|
+
return { keys: [publicJWK] }
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type AITokenService = ReturnType<typeof createAITokenService>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createAIRoutes, type AITokenService } from '#cloud/server/ai'
|
|
2
|
+
import type { CloudAPIEnvironment } from '#cloud/server/api/types'
|
|
3
|
+
import type { CloudSessionResolver } from '#cloud/server/auth'
|
|
4
|
+
import type { CollaborationTicketService } from '#cloud/server/collaboration'
|
|
5
|
+
import {
|
|
6
|
+
createCollaborationRoutes,
|
|
7
|
+
createPublicCollaborationRoutes
|
|
8
|
+
} from '#cloud/server/collaboration'
|
|
9
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
10
|
+
import type { DocumentService } from '#cloud/server/documents'
|
|
11
|
+
import { createDocumentRoutes } from '#cloud/server/documents'
|
|
12
|
+
import {
|
|
13
|
+
createDocumentVersionRoutes,
|
|
14
|
+
type DocumentVersionService
|
|
15
|
+
} from '#cloud/server/documents/versions'
|
|
16
|
+
import type { EntitlementService } from '#cloud/server/policy'
|
|
17
|
+
import type { DocumentSharingService } from '#cloud/server/sharing'
|
|
18
|
+
import {
|
|
19
|
+
createDocumentSharingRoutes,
|
|
20
|
+
createPublicDocumentRoutes,
|
|
21
|
+
createPublicSharingRoutes
|
|
22
|
+
} from '#cloud/server/sharing'
|
|
23
|
+
import type { WorkspaceMemberService, WorkspaceService } from '#cloud/server/workspaces'
|
|
24
|
+
import { createWorkspaceRoutes } from '#cloud/server/workspaces'
|
|
25
|
+
import { Hono } from 'hono'
|
|
26
|
+
import type { Kysely } from 'kysely'
|
|
27
|
+
|
|
28
|
+
export type CloudAPIServices = {
|
|
29
|
+
database?: Kysely<CloudDatabase>
|
|
30
|
+
rateLimitSecret?: string
|
|
31
|
+
collaboration: CollaborationTicketService
|
|
32
|
+
documents: DocumentService
|
|
33
|
+
versions: DocumentVersionService
|
|
34
|
+
sharing: DocumentSharingService
|
|
35
|
+
resolveSession?: CloudSessionResolver
|
|
36
|
+
entitlements?: EntitlementService
|
|
37
|
+
/** Signs AI service tokens; without it the deployment has no AI service. */
|
|
38
|
+
aiTokens?: AITokenService
|
|
39
|
+
workspaces: WorkspaceService
|
|
40
|
+
workspaceMembers: WorkspaceMemberService
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createPublicCloudAPIRouter(services: CloudAPIServices) {
|
|
44
|
+
return new Hono<CloudAPIEnvironment>()
|
|
45
|
+
.route('/', createPublicSharingRoutes(services.sharing, services.resolveSession))
|
|
46
|
+
.route(
|
|
47
|
+
'/',
|
|
48
|
+
createPublicDocumentRoutes(services.sharing, services.documents, services.resolveSession)
|
|
49
|
+
)
|
|
50
|
+
.route('/', createPublicCollaborationRoutes(services.collaboration, services.resolveSession))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function createCloudAPIRouter(services: CloudAPIServices) {
|
|
54
|
+
return new Hono<CloudAPIEnvironment>()
|
|
55
|
+
.route('/public', createPublicCloudAPIRouter(services))
|
|
56
|
+
.get('/workspaces/:workspaceId/entitlements', async (context) => {
|
|
57
|
+
if (!services.entitlements)
|
|
58
|
+
return context.json({ error: { code: 'not_found' as const } }, 404)
|
|
59
|
+
return context.json({
|
|
60
|
+
entitlements: await services.entitlements.workspace(
|
|
61
|
+
context.get('actor').userId,
|
|
62
|
+
context.req.param('workspaceId')
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
.get('/session', (context) => context.json({ user: context.get('actor') }))
|
|
67
|
+
.route(
|
|
68
|
+
'/',
|
|
69
|
+
createAIRoutes(
|
|
70
|
+
services.aiTokens,
|
|
71
|
+
services.database && services.rateLimitSecret
|
|
72
|
+
? { database: services.database, secret: services.rateLimitSecret }
|
|
73
|
+
: undefined
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
.route(
|
|
77
|
+
'/',
|
|
78
|
+
createCollaborationRoutes(
|
|
79
|
+
services.collaboration,
|
|
80
|
+
services.database && services.rateLimitSecret
|
|
81
|
+
? { database: services.database, secret: services.rateLimitSecret }
|
|
82
|
+
: undefined
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
.route(
|
|
86
|
+
'/',
|
|
87
|
+
createDocumentRoutes(
|
|
88
|
+
services.documents,
|
|
89
|
+
services.database && services.rateLimitSecret
|
|
90
|
+
? { database: services.database, secret: services.rateLimitSecret }
|
|
91
|
+
: undefined
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
.route('/', createDocumentVersionRoutes(services.versions))
|
|
95
|
+
.route(
|
|
96
|
+
'/',
|
|
97
|
+
createDocumentSharingRoutes(
|
|
98
|
+
services.sharing,
|
|
99
|
+
services.database && services.rateLimitSecret
|
|
100
|
+
? { database: services.database, secret: services.rateLimitSecret }
|
|
101
|
+
: undefined
|
|
102
|
+
)
|
|
103
|
+
)
|
|
104
|
+
.route(
|
|
105
|
+
'/workspaces',
|
|
106
|
+
createWorkspaceRoutes(
|
|
107
|
+
services.workspaces,
|
|
108
|
+
services.workspaceMembers,
|
|
109
|
+
services.database && services.rateLimitSecret
|
|
110
|
+
? { database: services.database, secret: services.rateLimitSecret }
|
|
111
|
+
: undefined
|
|
112
|
+
)
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type CloudAPI = ReturnType<typeof createCloudAPIRouter>
|
|
117
|
+
export type PublicCloudAPI = ReturnType<typeof createPublicCloudAPIRouter>
|