@crombolo/server 0.37.0 → 0.39.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/package.json +15 -14
- package/src/access.ts +29 -27
- package/src/adapters/audit.ts +1 -1
- package/src/adapters/blueprints.ts +22 -13
- package/src/adapters/content.ts +1 -1
- package/src/adapters/dictionary.ts +1 -1
- package/src/adapters/documents.ts +17 -10
- package/src/adapters/elements.ts +47 -37
- package/src/adapters/file-system.ts +1 -1
- package/src/adapters/health.ts +10 -5
- package/src/adapters/media.ts +12 -8
- package/src/adapters/member-groups.ts +8 -6
- package/src/adapters/members.ts +6 -4
- package/src/adapters/public-access.ts +7 -5
- package/src/adapters/redirects.ts +1 -1
- package/src/adapters/references.ts +1 -1
- package/src/adapters/relations.ts +1 -1
- package/src/adapters/schema-files.ts +33 -1
- package/src/adapters/search-index.ts +1 -1
- package/src/adapters/template-query.ts +1 -1
- package/src/adapters/users.ts +13 -13
- package/src/adapters/webhooks.ts +1 -1
- package/src/anonymise-rules.ts +83 -0
- package/src/approvals-api.ts +1 -1
- package/src/approvals.ts +75 -38
- package/src/back-office-url.ts +20 -0
- package/src/backup.ts +26 -2
- package/src/bundle-code.ts +1 -1
- package/src/bundle-grants.ts +250 -0
- package/src/bundle-install.ts +13 -2
- package/src/bundle-media.ts +12 -11
- package/src/bundles.ts +131 -43
- package/src/component-snippets.ts +1 -1
- package/src/components.ts +6 -1
- package/src/config.ts +61 -3
- package/src/content-notifications.ts +13 -9
- package/src/content-operations.ts +23 -65
- package/src/content-query.ts +1 -1
- package/src/core.ts +675 -0
- package/src/cron.ts +139 -0
- package/src/custom-tables.ts +274 -0
- package/src/database.ts +22 -14
- package/src/dictionary-transfer.ts +1 -1
- package/src/git-routes.ts +1 -1
- package/src/identity-provider-overrides.ts +18 -16
- package/src/imaging.ts +65 -15
- package/src/index.ts +10 -1
- package/src/job-wake.ts +23 -0
- package/src/live-reload.ts +195 -0
- package/src/log-viewer.ts +6 -1
- package/src/marketplace.ts +82 -10
- package/src/media-access.ts +12 -9
- package/src/member-auth.ts +6 -4
- package/src/models-builder.ts +1 -1
- package/src/node-operations.ts +122 -0
- package/src/owner-jobs.ts +428 -0
- package/src/ports.ts +36 -154
- package/src/preview-tokens.ts +6 -12
- package/src/remote.ts +3 -1
- package/src/routes.ts +18 -1
- package/src/schema.ts +8 -3
- package/src/seed/compile.ts +7 -5
- package/src/seed/export.ts +6 -4
- package/src/seo.ts +2 -2
- package/src/server.ts +328 -452
- package/src/settings.ts +18 -2
- package/src/site-data.ts +195 -0
- package/src/site-file.ts +30 -4
- package/src/site-queries.ts +140 -0
- package/src/site-replace.ts +25 -19
- package/src/site-sections.ts +1 -1
- package/src/site-services.ts +23 -6
- package/src/status-pages.ts +19 -5
- package/src/status.ts +11 -9
- package/src/url-settings.ts +1 -2
- package/src/webhook-files.ts +1 -1
- package/src/webhooks.ts +31 -23
- package/src/worker-watch.ts +73 -0
- package/src/worker.ts +138 -0
- package/src/bundle-tables.ts +0 -161
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
9
9
|
import { join, relative } from 'node:path'
|
|
10
|
-
import type { PortFailure } from '@crombolo/api-management'
|
|
10
|
+
import type { PortFailure } from '@crombolo/api-management/domain'
|
|
11
11
|
import type { ContentTypeAggregate, DataTypeModel, FormTypes } from '@crombolo/core'
|
|
12
12
|
import { currentSchemaState, type Db, updateSchemaStateHash } from '@crombolo/data'
|
|
13
13
|
import {
|
|
@@ -27,7 +27,11 @@ import {
|
|
|
27
27
|
writeSchemaFiles,
|
|
28
28
|
writeSchemaVersion,
|
|
29
29
|
} from '@crombolo/schema'
|
|
30
|
+
import type { CromboloConfig } from '../config.ts'
|
|
31
|
+
import { formTypesFor } from '../form-types.ts'
|
|
30
32
|
import { logger } from '../logging.ts'
|
|
33
|
+
import { componentAliasesIn } from '../schema.ts'
|
|
34
|
+
import { publishSchema } from '../schema-store.ts'
|
|
31
35
|
|
|
32
36
|
export interface SchemaFiles {
|
|
33
37
|
schemaDir: string
|
|
@@ -232,3 +236,31 @@ export function createSchemaFileWriter(
|
|
|
232
236
|
},
|
|
233
237
|
}
|
|
234
238
|
}
|
|
239
|
+
|
|
240
|
+
/** Where the backoffice writes schema files, and whether it may. */
|
|
241
|
+
export function schemaFiles(config: CromboloConfig): SchemaFiles {
|
|
242
|
+
const store = config.schemaStore
|
|
243
|
+
return {
|
|
244
|
+
schemaDir: config.schemaDir,
|
|
245
|
+
writable: config.schemaWritable,
|
|
246
|
+
componentAliases: () => componentAliasesIn(config.componentsDir),
|
|
247
|
+
formTypes: formTypesFor(config),
|
|
248
|
+
// Only when a store is configured: a schema directory in a repository is
|
|
249
|
+
// already where the files durably live.
|
|
250
|
+
onChanged: store
|
|
251
|
+
? async () => {
|
|
252
|
+
const report = await publishSchema(store, config.schemaDir)
|
|
253
|
+
if (report.written.length > 0 || report.removed.length > 0) {
|
|
254
|
+
logger('schema').info(
|
|
255
|
+
'Published schema to {store}: {written} written, {removed} removed',
|
|
256
|
+
{
|
|
257
|
+
store: store.description,
|
|
258
|
+
written: report.written.length,
|
|
259
|
+
removed: report.removed.length,
|
|
260
|
+
},
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
: undefined,
|
|
265
|
+
}
|
|
266
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The Examine dashboard's port over the search index. docs/search.md. */
|
|
2
|
-
import type { SearchIndexInfo, SearchIndexPort } from '@crombolo/api-management'
|
|
2
|
+
import type { SearchIndexInfo, SearchIndexPort } from '@crombolo/api-management/domain'
|
|
3
3
|
import { type Db, SEARCH_INDEXES, SearchIndex, type SearchIndexDefinition } from '@crombolo/data'
|
|
4
4
|
|
|
5
5
|
export function createSearchIndexPort(db: Db, onQueued?: () => void): SearchIndexPort {
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
TemplateQueryPort,
|
|
12
12
|
TemplateQueryRequest,
|
|
13
13
|
TemplateQuerySort,
|
|
14
|
-
} from '@crombolo/api-management'
|
|
14
|
+
} from '@crombolo/api-management/domain'
|
|
15
15
|
import type { ContentTypeRepository } from '@crombolo/data'
|
|
16
16
|
import type { PublishedCache, PublishedContent } from '@crombolo/render'
|
|
17
17
|
|
package/src/adapters/users.ts
CHANGED
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
UserPort,
|
|
17
17
|
UserResponse,
|
|
18
18
|
UserStatus,
|
|
19
|
-
} from '@crombolo/api-management'
|
|
19
|
+
} from '@crombolo/api-management/domain'
|
|
20
20
|
import {
|
|
21
21
|
generateToken,
|
|
22
22
|
hashPassword,
|
|
@@ -225,18 +225,18 @@ export function createUserPorts(
|
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
const setPassword = async (user: UserRecord, password: string) => {
|
|
228
|
-
await db.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
DbDate.toDb(new Date()),
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
228
|
+
await db.q
|
|
229
|
+
.updateTable('user_account')
|
|
230
|
+
.set({
|
|
231
|
+
password_hash: await hashPassword(password),
|
|
232
|
+
password_config: passwordConfigJson(),
|
|
233
|
+
security_stamp: crypto.randomUUID(),
|
|
234
|
+
last_password_change_date: DbDate.toDb(new Date()),
|
|
235
|
+
failed_login_attempts: 0,
|
|
236
|
+
update_date: DbDate.toDb(new Date()),
|
|
237
|
+
})
|
|
238
|
+
.where('id', '=', user.id)
|
|
239
|
+
.execute()
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
async function create(
|
package/src/adapters/webhooks.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Webhooks, shaped for the Management API: secrets masked, logs as Umbraco's client reads them. */
|
|
2
|
-
import type { WebhookPort, WebhookPortView } from '@crombolo/api-management'
|
|
2
|
+
import type { WebhookPort, WebhookPortView } from '@crombolo/api-management/domain'
|
|
3
3
|
import { nameBasedUuid, type WebhookLogEntry } from '@crombolo/data'
|
|
4
4
|
import { envReference } from '../webhook-files.ts'
|
|
5
5
|
import { MASKED, type WebhookService, type WebhookView } from '../webhooks.ts'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checking an owner's anonymise rules against its tables (story 189): the
|
|
3
|
+
* site's from `database.anonymise`, a bundle's from its package.json. A rule
|
|
4
|
+
* that names nothing, or that could not be written back, is refused up front
|
|
5
|
+
* rather than found at export or import.
|
|
6
|
+
*/
|
|
7
|
+
import type { ColumnSpec, ResolvedSchema } from '@crombolo/data'
|
|
8
|
+
import { ANONYMISE_COLUMNS, type AnonymiseColumn } from '@crombolo/transfer'
|
|
9
|
+
|
|
10
|
+
const TEXT = new Set<ColumnSpec['type']>(['varchar', 'text'])
|
|
11
|
+
const MEMBER = new Set<ColumnSpec['type']>(['uuid', 'varchar', 'text'])
|
|
12
|
+
|
|
13
|
+
/** What a scrubbed column holds: null where it may, otherwise its type's empty value. */
|
|
14
|
+
export function emptyValue(spec: ColumnSpec): unknown {
|
|
15
|
+
if (spec.nullable) return null
|
|
16
|
+
switch (spec.type) {
|
|
17
|
+
case 'varchar':
|
|
18
|
+
case 'text':
|
|
19
|
+
return ''
|
|
20
|
+
case 'integer':
|
|
21
|
+
case 'bigint':
|
|
22
|
+
return 0
|
|
23
|
+
case 'decimal':
|
|
24
|
+
return '0'
|
|
25
|
+
case 'boolean':
|
|
26
|
+
return false
|
|
27
|
+
case 'json':
|
|
28
|
+
return {}
|
|
29
|
+
default:
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function columnProblem(
|
|
35
|
+
table: string,
|
|
36
|
+
column: string,
|
|
37
|
+
how: AnonymiseColumn,
|
|
38
|
+
spec: ColumnSpec,
|
|
39
|
+
): string | undefined {
|
|
40
|
+
const at = `${table}.${column}`
|
|
41
|
+
if (how === 'email' && !TEXT.has(spec.type))
|
|
42
|
+
return `${at} is "email", and holds ${spec.type} rather than text`
|
|
43
|
+
if (how === 'member' && !MEMBER.has(spec.type))
|
|
44
|
+
return `${at} is "member", and holds ${spec.type} rather than a member's key`
|
|
45
|
+
if (how === 'member' && !spec.nullable)
|
|
46
|
+
return `${at} is "member", so it must be nullable: it is emptied when its member does not travel`
|
|
47
|
+
if (how === 'scrub' && emptyValue(spec) === null && !spec.nullable)
|
|
48
|
+
return `${at} is "scrub", and a ${spec.type} that is not nullable has no empty value`
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Every reason the rules cannot be used with these tables. */
|
|
53
|
+
export function anonymiseProblems(rules: unknown, schema: ResolvedSchema): string[] {
|
|
54
|
+
if (!rules || typeof rules !== 'object' || Array.isArray(rules))
|
|
55
|
+
return ['anonymise maps each table to "keep" or to its columns\' rules']
|
|
56
|
+
const problems: string[] = []
|
|
57
|
+
for (const [table, rule] of Object.entries(rules)) {
|
|
58
|
+
const declared = schema.tables.get(table)
|
|
59
|
+
if (!declared) {
|
|
60
|
+
problems.push(`anonymise names the table "${table}", which is not declared`)
|
|
61
|
+
continue
|
|
62
|
+
}
|
|
63
|
+
if (rule === 'keep') continue
|
|
64
|
+
if (!rule || typeof rule !== 'object' || Array.isArray(rule)) {
|
|
65
|
+
problems.push(`anonymise.${table} is "keep" or a map of its columns' rules`)
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
for (const [column, how] of Object.entries(rule as Record<string, unknown>)) {
|
|
69
|
+
const spec = declared.columns.get(column)?.spec
|
|
70
|
+
if (!spec) {
|
|
71
|
+
problems.push(`anonymise.${table} names the column "${column}", which is not declared`)
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
if (!ANONYMISE_COLUMNS.includes(how as AnonymiseColumn)) {
|
|
75
|
+
problems.push(`anonymise.${table}.${column} is "member", "email" or "scrub"`)
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
const problem = columnProblem(table, column, how as AnonymiseColumn, spec)
|
|
79
|
+
if (problem) problems.push(problem)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return problems
|
|
83
|
+
}
|
package/src/approvals-api.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
11
11
|
import { join } from 'node:path'
|
|
12
|
-
import type { Principal } from '@crombolo/api-management'
|
|
12
|
+
import type { Principal } from '@crombolo/api-management/domain'
|
|
13
13
|
import type { SchemaWorkflow } from '@crombolo/core'
|
|
14
14
|
import {
|
|
15
15
|
type ApprovalScheduleEntry,
|
package/src/approvals.ts
CHANGED
|
@@ -9,8 +9,13 @@
|
|
|
9
9
|
* request asked for (story 029), the schedule job doing the publishing.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type { Principal } from '@crombolo/api-management'
|
|
13
|
-
import {
|
|
12
|
+
import type { Principal } from '@crombolo/api-management/domain'
|
|
13
|
+
import {
|
|
14
|
+
type Actor,
|
|
15
|
+
type ApprovalsGate,
|
|
16
|
+
type ContentPrincipal,
|
|
17
|
+
systemActor,
|
|
18
|
+
} from '@crombolo/content'
|
|
14
19
|
import {
|
|
15
20
|
approvalsNeeded,
|
|
16
21
|
DocumentPermissions,
|
|
@@ -273,10 +278,12 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
273
278
|
.filter((id) => id > 0)
|
|
274
279
|
const rows = await nodes.byIds(ids)
|
|
275
280
|
const keyOf = new Map(rows.map((r) => [r.id, r.key]))
|
|
276
|
-
const type = await db.
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
281
|
+
const type = await db.q
|
|
282
|
+
.selectFrom('content as c')
|
|
283
|
+
.innerJoin('content_type as ct', 'ct.node_id', 'c.content_type_id')
|
|
284
|
+
.select(['ct.alias', 'ct.variations'])
|
|
285
|
+
.where('c.node_id', '=', node.id)
|
|
286
|
+
.execute()
|
|
280
287
|
return {
|
|
281
288
|
key: node.key,
|
|
282
289
|
name: node.text ?? node.key,
|
|
@@ -341,11 +348,12 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
341
348
|
|
|
342
349
|
const membersOf = async (aliases: readonly string[]): Promise<number> => {
|
|
343
350
|
if (aliases.length === 0) return 0
|
|
344
|
-
const rows = await db.
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
351
|
+
const rows = await db.q
|
|
352
|
+
.selectFrom('user_group_member as m')
|
|
353
|
+
.innerJoin('user_group as g', 'g.id', 'm.user_group_id')
|
|
354
|
+
.select((eb) => eb.fn.count('m.user_id').distinct().as('n'))
|
|
355
|
+
.where('g.alias', 'in', aliases)
|
|
356
|
+
.execute()
|
|
349
357
|
return Number(rows[0]?.n ?? 0)
|
|
350
358
|
}
|
|
351
359
|
|
|
@@ -376,20 +384,24 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
376
384
|
if (!options.email) return
|
|
377
385
|
let emails: string[] = []
|
|
378
386
|
if (to === 'editor') {
|
|
379
|
-
const rows = await db.
|
|
380
|
-
'
|
|
381
|
-
|
|
382
|
-
|
|
387
|
+
const rows = await db.q
|
|
388
|
+
.selectFrom('user_account')
|
|
389
|
+
.select('email')
|
|
390
|
+
.where('key', '=', request.requestedBy)
|
|
391
|
+
.execute()
|
|
383
392
|
emails = rows.map((r) => r.email)
|
|
384
393
|
} else {
|
|
385
394
|
const aliases = stages.flatMap((s) => stageOf(request.workflow, s)?.approvers ?? [])
|
|
386
395
|
if (aliases.length === 0) return
|
|
387
|
-
const rows = await db.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
396
|
+
const rows = await db.q
|
|
397
|
+
.selectFrom('user_account as u')
|
|
398
|
+
.innerJoin('user_group_member as m', 'm.user_id', 'u.id')
|
|
399
|
+
.innerJoin('user_group as g', 'g.id', 'm.user_group_id')
|
|
400
|
+
.select('u.email')
|
|
401
|
+
.distinct()
|
|
402
|
+
.where('g.alias', 'in', aliases)
|
|
403
|
+
.where('u.is_approved', '=', db.dialect.boolValue(true) as boolean)
|
|
404
|
+
.execute()
|
|
393
405
|
emails = rows.map((r) => r.email)
|
|
394
406
|
}
|
|
395
407
|
if (emails.length === 0) return
|
|
@@ -435,11 +447,14 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
435
447
|
const stepId = await repo.addStep(request.id, stage)
|
|
436
448
|
if (request.workflow.selfApproval !== 'automatic') continue
|
|
437
449
|
const approvers = stageOf(request.workflow, stage)?.approvers ?? []
|
|
438
|
-
const member = await db.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
450
|
+
const member = await db.q
|
|
451
|
+
.selectFrom('user_group_member as m')
|
|
452
|
+
.innerJoin('user_group as g', 'g.id', 'm.user_group_id')
|
|
453
|
+
.innerJoin('user_account as u', 'u.id', 'm.user_id')
|
|
454
|
+
.select((eb) => eb.fn.countAll().as('n'))
|
|
455
|
+
.where('u.key', '=', request.requestedBy)
|
|
456
|
+
.where('g.alias', 'in', approvers.length > 0 ? approvers : [''])
|
|
457
|
+
.execute()
|
|
443
458
|
if (Number(member[0]?.n ?? 0) > 0)
|
|
444
459
|
await repo.record(request.id, {
|
|
445
460
|
kind: 'approved',
|
|
@@ -684,10 +699,11 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
684
699
|
const ownChange = normaliseUuid(principal.id) === request.requestedBy
|
|
685
700
|
let variant = 'invariant'
|
|
686
701
|
if (facts?.variesByCulture) {
|
|
687
|
-
const fallback = await db.
|
|
688
|
-
'
|
|
689
|
-
|
|
690
|
-
|
|
702
|
+
const fallback = await db.q
|
|
703
|
+
.selectFrom('language')
|
|
704
|
+
.select('iso_code')
|
|
705
|
+
.where('is_default', '=', db.dialect.boolValue(true) as boolean)
|
|
706
|
+
.execute()
|
|
691
707
|
variant = request.cultures?.[0] ?? fallback[0]?.iso_code ?? 'invariant'
|
|
692
708
|
}
|
|
693
709
|
return {
|
|
@@ -766,10 +782,12 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
766
782
|
if (!root) return undefined
|
|
767
783
|
const workflows = (await readWorkflows(db)).map((s) => s.workflow)
|
|
768
784
|
if (workflows.length === 0) return undefined
|
|
769
|
-
const below = await db.
|
|
770
|
-
'
|
|
771
|
-
|
|
772
|
-
|
|
785
|
+
const below = await db.q
|
|
786
|
+
.selectFrom('node')
|
|
787
|
+
.select('unique_id')
|
|
788
|
+
.where((eb) => eb.or([eb('id', '=', root.id), eb('path', 'like', `${root.path},%`)]))
|
|
789
|
+
.orderBy('level')
|
|
790
|
+
.execute()
|
|
773
791
|
for (const row of below) {
|
|
774
792
|
const facts = await page(String(row.unique_id))
|
|
775
793
|
if (!facts) continue
|
|
@@ -781,10 +799,12 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
781
799
|
|
|
782
800
|
async newPageRefusal(principal, parentKey, contentTypeKey) {
|
|
783
801
|
const parent = parentKey ? await page(parentKey) : undefined
|
|
784
|
-
const type = await db.
|
|
785
|
-
'
|
|
786
|
-
|
|
787
|
-
|
|
802
|
+
const type = await db.q
|
|
803
|
+
.selectFrom('content_type as ct')
|
|
804
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
805
|
+
.select('ct.alias')
|
|
806
|
+
.where('n.unique_id', '=', normaliseUuid(contentTypeKey))
|
|
807
|
+
.execute()
|
|
788
808
|
const facts: PageFacts = {
|
|
789
809
|
key: '',
|
|
790
810
|
name: 'This page',
|
|
@@ -1149,3 +1169,20 @@ export function createApprovals(options: ApprovalsOptions): Approvals {
|
|
|
1149
1169
|
},
|
|
1150
1170
|
}
|
|
1151
1171
|
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* The approval workflows as the document operations meet them. A user's principal
|
|
1175
|
+
* is the backoffice's own, passed straight through; a local operator has none.
|
|
1176
|
+
*/
|
|
1177
|
+
export function approvalsGate(approvals: Approvals): ApprovalsGate {
|
|
1178
|
+
const as = (who: ContentPrincipal | undefined) => who as Principal | undefined
|
|
1179
|
+
return {
|
|
1180
|
+
publishRefusal: (who, key, action) => approvals.publishRefusal(as(who), key, action),
|
|
1181
|
+
branchRefusal: (who, key) => approvals.branchRefusal(as(who), key),
|
|
1182
|
+
newPageRefusal: (who, parentKey, typeKey) =>
|
|
1183
|
+
approvals.newPageRefusal(as(who), parentKey, typeKey),
|
|
1184
|
+
beforeSave: (who, key) => approvals.beforeSave(as(who), key),
|
|
1185
|
+
afterSave: (who, key) => approvals.afterSave(as(who), key),
|
|
1186
|
+
afterDirectPublish: (who, key, what) => approvals.afterDirectPublish(as(who), key, what),
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Addresses in the back office, for links in e-mails and messages. */
|
|
2
|
+
import type { CromboloConfig } from './config.ts'
|
|
3
|
+
|
|
4
|
+
/** The back office's address, e.g. `https://site.example/crombolo`; undefined when the site's own is not set. */
|
|
5
|
+
export function backOfficeUrl(
|
|
6
|
+
config: Pick<CromboloConfig, 'applicationUrl' | 'backOfficePath'>,
|
|
7
|
+
): string | undefined {
|
|
8
|
+
return config.applicationUrl
|
|
9
|
+
? `${config.applicationUrl.replace(/\/$/, '')}${config.backOfficePath}`
|
|
10
|
+
: undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A page's address in the back office, for a link in an e-mail. */
|
|
14
|
+
export function documentEditUrl(
|
|
15
|
+
config: Pick<CromboloConfig, 'applicationUrl' | 'backOfficePath'>,
|
|
16
|
+
key: string,
|
|
17
|
+
): string | undefined {
|
|
18
|
+
const base = backOfficeUrl(config)
|
|
19
|
+
return base ? `${base}/section/content/workspace/document/edit/${key}` : undefined
|
|
20
|
+
}
|
package/src/backup.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* beside the database; Postgres runs the operator's `CROMBOLO_PG_DUMP` command
|
|
4
4
|
* or refuses unless the caller vouches with `--backup-taken`.
|
|
5
5
|
*/
|
|
6
|
-
import { copyFileSync, existsSync } from 'node:fs'
|
|
6
|
+
import { copyFileSync, existsSync, readdirSync } from 'node:fs'
|
|
7
|
+
import { basename, dirname, join } from 'node:path'
|
|
8
|
+
import { ownerFile } from '@crombolo/data'
|
|
7
9
|
import type { CromboloConfig } from './config.ts'
|
|
8
10
|
|
|
9
11
|
export interface BackupOptions {
|
|
@@ -16,6 +18,23 @@ export interface BackupOptions {
|
|
|
16
18
|
export interface BackupResult {
|
|
17
19
|
kind: 'sqlite-copy' | 'pg-dump' | 'operator' | 'none'
|
|
18
20
|
path?: string
|
|
21
|
+
/** SQLite: the copies of the site's and bundles' own tables' files beside it (story 189). */
|
|
22
|
+
owners?: string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The site's and bundles' own SQLite files beside crombolo's, whatever is wired now. */
|
|
26
|
+
export function ownerFilesBeside(sqliteFile: string): string[] {
|
|
27
|
+
if (sqliteFile === ':memory:') return []
|
|
28
|
+
const site = ownerFile(sqliteFile, 'site')
|
|
29
|
+
const bundle = basename(ownerFile(sqliteFile, 'x')).replace(/x\.sqlite$/, '')
|
|
30
|
+
const dir = dirname(sqliteFile)
|
|
31
|
+
if (!existsSync(dir)) return []
|
|
32
|
+
return readdirSync(dir)
|
|
33
|
+
.filter(
|
|
34
|
+
(name) => name === basename(site) || (name.startsWith(bundle) && name.endsWith('.sqlite')),
|
|
35
|
+
)
|
|
36
|
+
.map((name) => join(dir, name))
|
|
37
|
+
.sort()
|
|
19
38
|
}
|
|
20
39
|
|
|
21
40
|
export class BackupRequiredError extends Error {
|
|
@@ -35,7 +54,12 @@ export async function backupBefore(
|
|
|
35
54
|
if (config.sqliteFile === ':memory:' || !existsSync(config.sqliteFile)) return { kind: 'none' }
|
|
36
55
|
const path = `${config.sqliteFile}.${stamp}.${options.reason}.bak`
|
|
37
56
|
copyFileSync(config.sqliteFile, path)
|
|
38
|
-
|
|
57
|
+
const owners = ownerFilesBeside(config.sqliteFile).map((file) => {
|
|
58
|
+
const copy = `${file}.${stamp}.${options.reason}.bak`
|
|
59
|
+
copyFileSync(file, copy)
|
|
60
|
+
return copy
|
|
61
|
+
})
|
|
62
|
+
return { kind: 'sqlite-copy', path, ...(owners.length > 0 ? { owners } : {}) }
|
|
39
63
|
}
|
|
40
64
|
if (config.pgDump) {
|
|
41
65
|
const proc = Bun.spawn(['sh', '-c', config.pgDump], {
|
package/src/bundle-code.ts
CHANGED