@crombolo/server 0.38.1 → 0.39.1
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/package.json +13 -13
- package/src/bundle-grants.ts +47 -62
- package/src/bundles.ts +8 -3
- package/src/config.ts +1 -1
- package/src/core.ts +19 -7
- package/src/marketplace.ts +8 -8
- package/src/routes.ts +18 -1
- package/src/server.ts +16 -21
- package/src/worker.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@crombolo/api-delivery": "0.
|
|
35
|
-
"@crombolo/api-management": "0.
|
|
36
|
-
"@crombolo/auth": "0.
|
|
37
|
-
"@crombolo/backoffice-host": "0.
|
|
38
|
-
"@crombolo/common": "0.
|
|
39
|
-
"@crombolo/content": "0.
|
|
40
|
-
"@crombolo/contracts": "0.
|
|
41
|
-
"@crombolo/core": "0.
|
|
42
|
-
"@crombolo/data": "0.
|
|
43
|
-
"@crombolo/render": "0.
|
|
44
|
-
"@crombolo/schema": "0.
|
|
45
|
-
"@crombolo/transfer": "0.
|
|
34
|
+
"@crombolo/api-delivery": "0.39.1",
|
|
35
|
+
"@crombolo/api-management": "0.39.1",
|
|
36
|
+
"@crombolo/auth": "0.39.1",
|
|
37
|
+
"@crombolo/backoffice-host": "0.39.1",
|
|
38
|
+
"@crombolo/common": "0.39.1",
|
|
39
|
+
"@crombolo/content": "0.39.1",
|
|
40
|
+
"@crombolo/contracts": "0.39.1",
|
|
41
|
+
"@crombolo/core": "0.39.1",
|
|
42
|
+
"@crombolo/data": "0.39.1",
|
|
43
|
+
"@crombolo/render": "0.39.1",
|
|
44
|
+
"@crombolo/schema": "0.39.1",
|
|
45
|
+
"@crombolo/transfer": "0.39.1",
|
|
46
46
|
"@logtape/logtape": "^2.3.8",
|
|
47
47
|
"jose": "^6.2.12"
|
|
48
48
|
}
|
package/src/bundle-grants.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bundles ask for permissions (story 222). A bundle's package declares what it
|
|
3
|
-
* may do with the site
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* may do with the site, and each capability serves only those. Wiring it in the
|
|
4
|
+
* config approves it, recorded at boot (story 225); an administrator can
|
|
5
|
+
* disable it.
|
|
6
6
|
* docs/bundles.md, "Permissions".
|
|
7
7
|
*/
|
|
8
8
|
import {
|
|
9
9
|
type BundlePackage,
|
|
10
10
|
type BundlePermission,
|
|
11
11
|
describePermissions,
|
|
12
|
-
discoverBundles,
|
|
13
12
|
} from '@crombolo/backoffice-host/registry'
|
|
14
13
|
import { type BundleGrant, BundleGrantRepository, type Db } from '@crombolo/data'
|
|
15
14
|
|
|
@@ -126,41 +125,45 @@ export function gated<T extends object>(
|
|
|
126
125
|
return Object.freeze(out) as T
|
|
127
126
|
}
|
|
128
127
|
|
|
129
|
-
/** Where a bundle stands:
|
|
128
|
+
/** Where a bundle stands: what it may do, who approved it, and whether it is disabled. */
|
|
130
129
|
export interface BundleGrantState {
|
|
131
130
|
bundleId: string
|
|
132
131
|
packageName: string
|
|
133
132
|
version: string
|
|
134
133
|
declared: { permission: string; allows: string }[]
|
|
135
|
-
/** On
|
|
134
|
+
/** On unless an administrator disabled it: the site's code is its approval. */
|
|
136
135
|
on: boolean
|
|
137
136
|
grant: BundleGrant | undefined
|
|
138
|
-
/**
|
|
139
|
-
|
|
137
|
+
/** Who disabled it, when it is off. */
|
|
138
|
+
disabledBy: string | null
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
/**
|
|
141
|
+
/** Whether a bundle may run, what it was approved for, and the switch to stop one. */
|
|
143
142
|
export interface BundleGrants {
|
|
144
|
-
/** Reads the
|
|
143
|
+
/** Reads the rows again, as a node elsewhere may have changed them. */
|
|
145
144
|
refresh(): Promise<void>
|
|
146
145
|
isOn(bundleId: string): boolean
|
|
147
146
|
state(pkg: BundlePackage): BundleGrantState
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
/** Records what a bundle is approved for, and by whom; true when that changed. */
|
|
148
|
+
grant(pkg: BundlePackage, by: string | null): Promise<boolean>
|
|
149
|
+
disable(pkg: BundlePackage, by: string | null): Promise<BundleGrantState>
|
|
150
|
+
enable(pkg: BundlePackage): Promise<BundleGrantState>
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
/**
|
|
153
|
-
export function
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
153
|
+
/** Whether a recorded approval already holds this version and list. */
|
|
154
|
+
export function approvalHolds(pkg: BundlePackage, grant: BundleGrant | undefined): boolean {
|
|
155
|
+
if (!grant || grant.version !== pkg.version) return false
|
|
156
|
+
const declared = declaredPermissions(pkg)
|
|
157
|
+
return (
|
|
158
|
+
grant.permissions.length === declared.length &&
|
|
159
|
+
declared.every((permission) => grant.permissions.includes(permission))
|
|
160
|
+
)
|
|
158
161
|
}
|
|
159
162
|
|
|
160
163
|
/**
|
|
161
|
-
*
|
|
162
|
-
* `refreshMs` (a
|
|
163
|
-
*
|
|
164
|
+
* Bundles as this node sees them (stories 222 and 225): read at boot, read
|
|
165
|
+
* again at most every `refreshMs` (a node elsewhere disabling one), and at once
|
|
166
|
+
* after a change made here.
|
|
164
167
|
*/
|
|
165
168
|
export function createBundleGrants(options: {
|
|
166
169
|
db: Db
|
|
@@ -181,17 +184,15 @@ export function createBundleGrants(options: {
|
|
|
181
184
|
if (Date.now() - readAt > refreshMs) void read().catch(() => {})
|
|
182
185
|
}
|
|
183
186
|
const stateOf = (pkg: BundlePackage): BundleGrantState => {
|
|
184
|
-
const declared = declaredPermissions(pkg)
|
|
185
187
|
const grant = grants.get(pkg.id)
|
|
186
|
-
const granted = new Set(grant?.permissions ?? [])
|
|
187
188
|
return {
|
|
188
189
|
bundleId: pkg.id,
|
|
189
190
|
packageName: pkg.packageName,
|
|
190
191
|
version: pkg.version,
|
|
191
|
-
declared: describePermissions(
|
|
192
|
-
on:
|
|
192
|
+
declared: describePermissions(declaredPermissions(pkg)),
|
|
193
|
+
on: !grant?.disabledAt,
|
|
193
194
|
grant,
|
|
194
|
-
|
|
195
|
+
disabledBy: grant?.disabledAt ? grant.disabledBy : null,
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
198
|
|
|
@@ -199,14 +200,14 @@ export function createBundleGrants(options: {
|
|
|
199
200
|
refresh: read,
|
|
200
201
|
isOn(bundleId) {
|
|
201
202
|
stale()
|
|
202
|
-
|
|
203
|
-
return pkg ? grantCovers(declaredPermissions(pkg), grants.get(bundleId)) : false
|
|
203
|
+
return options.packages().has(bundleId) && !grants.get(bundleId)?.disabledAt
|
|
204
204
|
},
|
|
205
205
|
state(pkg) {
|
|
206
206
|
stale()
|
|
207
207
|
return stateOf(pkg)
|
|
208
208
|
},
|
|
209
209
|
async grant(pkg, by) {
|
|
210
|
+
if (approvalHolds(pkg, grants.get(pkg.id))) return false
|
|
210
211
|
await repository.grant({
|
|
211
212
|
bundleId: pkg.id,
|
|
212
213
|
packageName: pkg.packageName,
|
|
@@ -215,51 +216,35 @@ export function createBundleGrants(options: {
|
|
|
215
216
|
grantedBy: by,
|
|
216
217
|
})
|
|
217
218
|
await read()
|
|
219
|
+
return true
|
|
220
|
+
},
|
|
221
|
+
async disable(pkg, by) {
|
|
222
|
+
await repository.disable(
|
|
223
|
+
{ bundleId: pkg.id, packageName: pkg.packageName, version: pkg.version },
|
|
224
|
+
by,
|
|
225
|
+
)
|
|
226
|
+
await read()
|
|
218
227
|
return stateOf(pkg)
|
|
219
228
|
},
|
|
220
|
-
async
|
|
221
|
-
|
|
229
|
+
async enable(pkg) {
|
|
230
|
+
await repository.enable(pkg.id)
|
|
222
231
|
await read()
|
|
223
|
-
return
|
|
232
|
+
return stateOf(pkg)
|
|
224
233
|
},
|
|
225
234
|
}
|
|
226
235
|
}
|
|
227
236
|
|
|
237
|
+
/** Who a bundle's approval names when it came from being wired in the config. */
|
|
238
|
+
export const APPROVED_BY_CODE = "the site's code"
|
|
239
|
+
|
|
228
240
|
/** What a route of a bundle that is off answers. */
|
|
229
|
-
export function
|
|
241
|
+
export function disabledResponse(bundleId: string): Response {
|
|
230
242
|
return Response.json(
|
|
231
243
|
{
|
|
232
|
-
title: '
|
|
233
|
-
detail: `The bundle "${bundleId}"
|
|
244
|
+
title: 'Turned off',
|
|
245
|
+
detail: `The bundle "${bundleId}" has been disabled by an administrator, in Packages → Installed.`,
|
|
234
246
|
status: 503,
|
|
235
247
|
},
|
|
236
|
-
{ status: 503, headers: { 'content-type': 'application/problem+json'
|
|
248
|
+
{ status: 503, headers: { 'content-type': 'application/problem+json' } },
|
|
237
249
|
)
|
|
238
250
|
}
|
|
239
|
-
|
|
240
|
-
/** The bundle a site depends on, by id, when it has a server half to grant. */
|
|
241
|
-
export function grantableBundle(siteDir: string, id: string): BundlePackage | string {
|
|
242
|
-
const pkg = discoverBundles(siteDir).bundles.find((candidate) => candidate.id === id)
|
|
243
|
-
if (!pkg)
|
|
244
|
-
return `No package this site depends on declares the bundle "${id}". Add it to package.json first.`
|
|
245
|
-
if (!pkg.carries.server)
|
|
246
|
-
return `The bundle "${id}" has no server half, so there is nothing to grant.`
|
|
247
|
-
return pkg
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/** Grants a bundle the whole of what it declares, outside a running server. */
|
|
251
|
-
export async function grantBundle(
|
|
252
|
-
db: Db,
|
|
253
|
-
pkg: BundlePackage,
|
|
254
|
-
by: string | null,
|
|
255
|
-
): Promise<string[]> {
|
|
256
|
-
const permissions = declaredPermissions(pkg)
|
|
257
|
-
await new BundleGrantRepository(db).grant({
|
|
258
|
-
bundleId: pkg.id,
|
|
259
|
-
packageName: pkg.packageName,
|
|
260
|
-
version: pkg.version,
|
|
261
|
-
permissions,
|
|
262
|
-
grantedBy: by,
|
|
263
|
-
})
|
|
264
|
-
return permissions
|
|
265
|
-
}
|
package/src/bundles.ts
CHANGED
|
@@ -82,7 +82,12 @@ import {
|
|
|
82
82
|
type SiteServices,
|
|
83
83
|
} from '@crombolo/render'
|
|
84
84
|
import { anonymiseProblems } from './anonymise-rules.ts'
|
|
85
|
-
import {
|
|
85
|
+
import {
|
|
86
|
+
declaredPermissions,
|
|
87
|
+
disabledResponse,
|
|
88
|
+
gated,
|
|
89
|
+
permissionProblems,
|
|
90
|
+
} from './bundle-grants.ts'
|
|
86
91
|
import type { BundleMedia, BundleMediaDeclaration } from './bundle-media.ts'
|
|
87
92
|
import type { BundleForms } from './form-types.ts'
|
|
88
93
|
import type { BundleIdentityProviders } from './identity-provider-overrides.ts'
|
|
@@ -827,7 +832,7 @@ export function createServerBundles(options: ServerBundlesOptions): ServerBundle
|
|
|
827
832
|
const handlers: SiteRoute['handlers'] = {}
|
|
828
833
|
for (const [method, handler] of Object.entries(route.handlers))
|
|
829
834
|
handlers[method as RouteMethod] = (request, context) =>
|
|
830
|
-
isOn(bundleId) ? handler(request, context) :
|
|
835
|
+
isOn(bundleId) ? handler(request, context) : disabledResponse(bundleId)
|
|
831
836
|
return { ...route, handlers }
|
|
832
837
|
}
|
|
833
838
|
|
|
@@ -874,7 +879,7 @@ export function createServerBundles(options: ServerBundlesOptions): ServerBundle
|
|
|
874
879
|
for (const route of (bundle.routes ?? []).filter((candidate) => !onSite(candidate))) {
|
|
875
880
|
const params = matchRoute(route.path, requested)
|
|
876
881
|
if (!params) continue
|
|
877
|
-
if (options.isOn && !options.isOn(bundle.id)) return
|
|
882
|
+
if (options.isOn && !options.isOn(bundle.id)) return disabledResponse(bundle.id)
|
|
878
883
|
const caller: BundleCaller = Object.freeze({ kind: 'backoffice', principal })
|
|
879
884
|
return invoke(
|
|
880
885
|
{ route: route as SiteRoute, owner: `the bundle ${bundle.id}` },
|
package/src/config.ts
CHANGED
|
@@ -976,7 +976,7 @@ export function describeDatabase(
|
|
|
976
976
|
}
|
|
977
977
|
}
|
|
978
978
|
|
|
979
|
-
export const VERSION = '0.
|
|
979
|
+
export const VERSION = '0.39.1'
|
|
980
980
|
|
|
981
981
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
982
982
|
/** A positive number from a setting, else the default. */
|
package/src/core.ts
CHANGED
|
@@ -30,10 +30,11 @@ import {
|
|
|
30
30
|
ViewSnapshots,
|
|
31
31
|
} from '@crombolo/render'
|
|
32
32
|
import type { SyncReport } from '@crombolo/schema'
|
|
33
|
+
import { recordAudit } from './adapters/audit.ts'
|
|
33
34
|
import { createMediaSource, createPublishedContentSource } from './adapters/documents.ts'
|
|
34
35
|
import { backOfficeUrl, documentEditUrl } from './back-office-url.ts'
|
|
35
36
|
import { BACKOFFICE_EXTERNAL_PATH } from './backoffice-external.ts'
|
|
36
|
-
import { createBundleGrants } from './bundle-grants.ts'
|
|
37
|
+
import { APPROVED_BY_CODE, createBundleGrants, declaredPermissions } from './bundle-grants.ts'
|
|
37
38
|
import {
|
|
38
39
|
type BundleMediaFactory,
|
|
39
40
|
createBundleMedia,
|
|
@@ -162,7 +163,7 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
162
163
|
? await bootstrapDatabase(config, chains)
|
|
163
164
|
: await attachDatabase(config, opened)
|
|
164
165
|
await openTables(db, config, opened, { provision: owns })
|
|
165
|
-
//
|
|
166
|
+
// Stories 222 and 225: wiring a bundle approves it; an administrator can disable it.
|
|
166
167
|
const bundleGrants = createBundleGrants({
|
|
167
168
|
db,
|
|
168
169
|
packages: () => new Map(extensions.bundles().bundles.map((pkg) => [pkg.id, pkg])),
|
|
@@ -181,11 +182,22 @@ export async function createCore(config: CromboloConfig, hooks: CoreHooks) {
|
|
|
181
182
|
})
|
|
182
183
|
for (const bundle of config.bundles) {
|
|
183
184
|
const pkg = bundlePackages.find((candidate) => candidate.id === bundle.id)
|
|
184
|
-
if (pkg
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
if (!pkg) continue
|
|
186
|
+
// Recorded where the database is written, and audited when it changes.
|
|
187
|
+
if (owns && (await bundleGrants.grant(pkg, APPROVED_BY_CODE)))
|
|
188
|
+
await recordAudit(db, {
|
|
189
|
+
category: 'system',
|
|
190
|
+
action: 'Grant',
|
|
191
|
+
entityType: 'Bundle',
|
|
192
|
+
entityName: `${pkg.packageName}@${pkg.version}`,
|
|
193
|
+
detail: `approved by the site's code: ${declaredPermissions(pkg).join(', ') || 'nothing'}`,
|
|
194
|
+
source: 'boot',
|
|
195
|
+
})
|
|
196
|
+
if (!bundleGrants.isOn(bundle.id))
|
|
197
|
+
log.warning('The bundle {bundle} is disabled by {by}; enable it in Packages → Installed.', {
|
|
198
|
+
bundle: bundle.id,
|
|
199
|
+
by: bundleGrants.state(pkg).disabledBy ?? 'an administrator',
|
|
200
|
+
})
|
|
189
201
|
}
|
|
190
202
|
// A configured schema store is copied down before anything reads `schema/`, and
|
|
191
203
|
// becomes the schema directory for this boot. Everything after here — loading,
|
package/src/marketplace.ts
CHANGED
|
@@ -66,11 +66,11 @@ export interface InstalledListing {
|
|
|
66
66
|
peerRange: string
|
|
67
67
|
/** What its server half may do with the site, each with what it allows (story 222). */
|
|
68
68
|
permissions: { permission: string; allows: string }[]
|
|
69
|
-
/** Whether it is turned on:
|
|
69
|
+
/** Whether it is turned on: unless an administrator has disabled it. */
|
|
70
70
|
on: boolean
|
|
71
|
-
/**
|
|
72
|
-
|
|
73
|
-
/** Who
|
|
71
|
+
/** Who disabled it, while it is off. */
|
|
72
|
+
disabledBy: string | null
|
|
73
|
+
/** Who approved it, and when: an administrator at install, or the site's code. */
|
|
74
74
|
granted?: { by: string | null; at: string; version: string }
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -307,17 +307,17 @@ export function createMarketplace(options: MarketplaceOptions): Marketplace {
|
|
|
307
307
|
return carries
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
/** A bundle's permissions and
|
|
310
|
+
/** A bundle's permissions, who approved them, and whether it is disabled, for the listing. */
|
|
311
311
|
const grantOf = (bundle: BundlePackage) => {
|
|
312
312
|
const declared = describePermissions(declaredPermissions(bundle))
|
|
313
313
|
if (!bundle.carries.server || !options.grants)
|
|
314
|
-
return { permissions: declared, on: true,
|
|
314
|
+
return { permissions: declared, on: true, disabledBy: null }
|
|
315
315
|
const state = options.grants.state(bundle)
|
|
316
316
|
return {
|
|
317
317
|
permissions: state.declared,
|
|
318
318
|
on: state.on,
|
|
319
|
-
|
|
320
|
-
...(state.grant
|
|
319
|
+
disabledBy: state.disabledBy,
|
|
320
|
+
...(state.grant?.grantedBy
|
|
321
321
|
? {
|
|
322
322
|
granted: {
|
|
323
323
|
by: state.grant.grantedBy,
|
package/src/routes.ts
CHANGED
|
@@ -118,6 +118,9 @@ const prefersHtml = (request: Request) => {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/** Builds the site's route pipeline over its routes and its bundles'. */
|
|
121
|
+
/** Why a route's signal is aborted once its answer has been sent. */
|
|
122
|
+
const ANSWERED = new Error('The answer has been sent.')
|
|
123
|
+
|
|
121
124
|
export function createRoutes<Member extends RouteMember>(
|
|
122
125
|
declared: readonly DeclaredRoute[],
|
|
123
126
|
deps: RouteDeps<Member>,
|
|
@@ -382,7 +385,21 @@ export function createRoutes<Member extends RouteMember>(
|
|
|
382
385
|
if (!headers.has('cache-control') || (method !== 'GET' && method !== 'HEAD'))
|
|
383
386
|
headers.set('cache-control', 'private, no-store')
|
|
384
387
|
const body = method === 'HEAD' ? null : response.body
|
|
385
|
-
|
|
388
|
+
// Story 224: the signal ends once the answer has been sent, its body read
|
|
389
|
+
// to the end, failed or cancelled, so nothing still listening is kept alive.
|
|
390
|
+
const answered = () => deadline.abort(ANSWERED)
|
|
391
|
+
if (!body) answered()
|
|
392
|
+
const sent = body?.pipeThrough(
|
|
393
|
+
new TransformStream({ flush: answered, cancel: answered } as Transformer<
|
|
394
|
+
Uint8Array,
|
|
395
|
+
Uint8Array
|
|
396
|
+
>),
|
|
397
|
+
)
|
|
398
|
+
return new Response(sent ?? null, {
|
|
399
|
+
status: response.status,
|
|
400
|
+
statusText: response.statusText,
|
|
401
|
+
headers,
|
|
402
|
+
})
|
|
386
403
|
}
|
|
387
404
|
|
|
388
405
|
/** The route a site path matches, with its params. */
|
package/src/server.ts
CHANGED
|
@@ -267,8 +267,8 @@ export interface ServerHandle {
|
|
|
267
267
|
bundleGrants: BundleGrants
|
|
268
268
|
/** The site's and bundles' background jobs (story 187); started on a node that owns writes. */
|
|
269
269
|
backgroundJobs: JobRunner
|
|
270
|
-
/** The wired bundles
|
|
271
|
-
|
|
270
|
+
/** The wired bundles an administrator has disabled, and who did. */
|
|
271
|
+
disabledBundles(): { id: string; by: string | null }[]
|
|
272
272
|
schema: SchemaBoot
|
|
273
273
|
/** Applies cache instructions other nodes appended; the interval calls this too. */
|
|
274
274
|
poll(): Promise<number>
|
|
@@ -1161,7 +1161,7 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
1161
1161
|
const hostTokenPath = `${paths.pluginPath}/api/host-token`
|
|
1162
1162
|
const contentQueryPath = `${paths.pluginPath}/api/content-query`
|
|
1163
1163
|
const bundleInstallPaths = new Set(
|
|
1164
|
-
['install', 'uninstall', '
|
|
1164
|
+
['install', 'uninstall', 'disable', 'enable'].map(
|
|
1165
1165
|
(action) => `${paths.pluginPath}/api/bundles/${action}`,
|
|
1166
1166
|
),
|
|
1167
1167
|
)
|
|
@@ -1770,9 +1770,9 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
1770
1770
|
return Response.json(outcome, { status: outcome.ok ? 200 : 400 })
|
|
1771
1771
|
}
|
|
1772
1772
|
|
|
1773
|
-
// Story
|
|
1774
|
-
//
|
|
1775
|
-
if ((action === '
|
|
1773
|
+
// Story 225: a bundle wired in the config is approved by it; an
|
|
1774
|
+
// administrator can disable one, and enable it again.
|
|
1775
|
+
if ((action === 'disable' || action === 'enable') && request.method === 'POST') {
|
|
1776
1776
|
const body = (await request.json().catch(() => ({}))) as { id?: unknown }
|
|
1777
1777
|
const id = typeof body.id === 'string' ? body.id : ''
|
|
1778
1778
|
const pkg = extensions.bundles().bundles.find((candidate) => candidate.id === id)
|
|
@@ -1781,20 +1781,16 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
1781
1781
|
{ ok: false, message: `No installed bundle with a server half is called "${id}".` },
|
|
1782
1782
|
{ status: 404 },
|
|
1783
1783
|
)
|
|
1784
|
-
if (action === 'withdraw') await bundleGrants.withdraw(id)
|
|
1785
1784
|
const state =
|
|
1786
|
-
action === '
|
|
1787
|
-
? await bundleGrants.
|
|
1788
|
-
: bundleGrants.
|
|
1785
|
+
action === 'disable'
|
|
1786
|
+
? await bundleGrants.disable(pkg, principal.email)
|
|
1787
|
+
: await bundleGrants.enable(pkg)
|
|
1789
1788
|
await recordAudit(db, {
|
|
1790
1789
|
category: 'system',
|
|
1791
|
-
action: action === '
|
|
1790
|
+
action: action === 'disable' ? 'Disable' : 'Enable',
|
|
1792
1791
|
entityType: 'Bundle',
|
|
1793
1792
|
entityName: `${pkg.packageName}@${pkg.version}`,
|
|
1794
|
-
detail:
|
|
1795
|
-
action === 'grant'
|
|
1796
|
-
? `granted ${state.declared.map((d) => d.permission).join(', ') || 'nothing'}`
|
|
1797
|
-
: 'withdrew its permissions; it is off',
|
|
1793
|
+
detail: action === 'disable' ? 'disabled; it is off' : 'enabled; it runs again',
|
|
1798
1794
|
source: 'request',
|
|
1799
1795
|
userKey: principal.id,
|
|
1800
1796
|
userName: principal.name,
|
|
@@ -1803,11 +1799,10 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
1803
1799
|
return Response.json({
|
|
1804
1800
|
ok: true,
|
|
1805
1801
|
on: state.on,
|
|
1806
|
-
missing: state.missing,
|
|
1807
1802
|
message:
|
|
1808
|
-
action === '
|
|
1809
|
-
? `${pkg.name} is turned
|
|
1810
|
-
: `${pkg.name} is turned
|
|
1803
|
+
action === 'disable'
|
|
1804
|
+
? `${pkg.name} is turned off until it is enabled again.`
|
|
1805
|
+
: `${pkg.name} is turned on.`,
|
|
1811
1806
|
})
|
|
1812
1807
|
}
|
|
1813
1808
|
|
|
@@ -3174,11 +3169,11 @@ export async function createServer(config: CromboloConfig = loadConfig()): Promi
|
|
|
3174
3169
|
seededAdminPassword,
|
|
3175
3170
|
bundleGrants,
|
|
3176
3171
|
backgroundJobs: jobRunner,
|
|
3177
|
-
|
|
3172
|
+
disabledBundles: () =>
|
|
3178
3173
|
config.bundles.flatMap((bundle) => {
|
|
3179
3174
|
const pkg = bundlePackages.find((candidate) => candidate.id === bundle.id)
|
|
3180
3175
|
if (!pkg || bundleGrants.isOn(bundle.id)) return []
|
|
3181
|
-
return [{ id: bundle.id,
|
|
3176
|
+
return [{ id: bundle.id, by: bundleGrants.state(pkg).disabledBy }]
|
|
3182
3177
|
}),
|
|
3183
3178
|
schema,
|
|
3184
3179
|
poll: () => poller.poll(),
|
package/src/worker.ts
CHANGED
|
@@ -44,8 +44,8 @@ export interface WorkerHandle {
|
|
|
44
44
|
fetch(request: Request, server: Server<unknown>): Promise<Response>
|
|
45
45
|
websocket: { message(): void }
|
|
46
46
|
}
|
|
47
|
-
/** The wired bundles
|
|
48
|
-
|
|
47
|
+
/** The wired bundles an administrator has disabled, and who did. */
|
|
48
|
+
disabledBundles(): { id: string; by: string | null }[]
|
|
49
49
|
/** Core's jobs; each run can be called directly. */
|
|
50
50
|
jobs: BackgroundJobs
|
|
51
51
|
/** The site's and bundles' jobs (story 187). */
|
|
@@ -116,11 +116,11 @@ export async function createWorker(config: CromboloConfig): Promise<WorkerHandle
|
|
|
116
116
|
fetch: (request) => fetch(request),
|
|
117
117
|
websocket: { message() {} },
|
|
118
118
|
},
|
|
119
|
-
|
|
119
|
+
disabledBundles: () =>
|
|
120
120
|
config.bundles.flatMap((bundle) => {
|
|
121
121
|
const pkg = bundlePackages.find((candidate) => candidate.id === bundle.id)
|
|
122
122
|
if (!pkg || bundleGrants.isOn(bundle.id)) return []
|
|
123
|
-
return [{ id: bundle.id,
|
|
123
|
+
return [{ id: bundle.id, by: bundleGrants.state(pkg).disabledBy }]
|
|
124
124
|
}),
|
|
125
125
|
jobs,
|
|
126
126
|
backgroundJobs: jobRunner,
|