@crombolo/data 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 +2 -2
- package/src/audit.ts +1 -1
- package/src/index.ts +1 -0
- package/src/repositories/bundle-grants.ts +54 -23
- package/src/schema/bundles-disabled.ts +29 -0
- package/src/schema/plan.ts +2 -0
- package/src/tables.gen.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
31
|
+
"@crombolo/core": "0.39.1",
|
|
32
32
|
"kysely": "0.29.6"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/audit.ts
CHANGED
|
@@ -35,7 +35,7 @@ export const AUDIT_CATEGORIES: readonly AuditCategory[] = [
|
|
|
35
35
|
]
|
|
36
36
|
|
|
37
37
|
/** Where an entry came from: a request (with its address), the command line, or a background job. */
|
|
38
|
-
export type AuditSource = 'request' | 'cli' | 'job'
|
|
38
|
+
export type AuditSource = 'request' | 'cli' | 'job' | 'boot'
|
|
39
39
|
|
|
40
40
|
export interface AuditEntryInput {
|
|
41
41
|
category: AuditCategory
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ export * from './schema/built-in-media-types.ts'
|
|
|
60
60
|
export * from './schema/built-in-member-types.ts'
|
|
61
61
|
export * from './schema/bundle-grants.ts'
|
|
62
62
|
export * from './schema/bundle-package.ts'
|
|
63
|
+
export * from './schema/bundles-disabled.ts'
|
|
63
64
|
export * from './schema/bundles-rename.ts'
|
|
64
65
|
export * from './schema/change-report.ts'
|
|
65
66
|
export * from './schema/client-id-prefix.ts'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What
|
|
3
|
-
* replaced
|
|
4
|
-
* "Permissions".
|
|
2
|
+
* What each bundle was approved for (stories 222 and 225): one row per bundle,
|
|
3
|
+
* its approval replaced as it changes, and whether an administrator disabled
|
|
4
|
+
* it. docs/bundles.md, "Permissions".
|
|
5
5
|
*/
|
|
6
6
|
import type { Db } from '../database.ts'
|
|
7
7
|
import { DbDate } from '../dialect.ts'
|
|
@@ -13,6 +13,9 @@ export interface BundleGrant {
|
|
|
13
13
|
permissions: string[]
|
|
14
14
|
grantedBy: string | null
|
|
15
15
|
grantedAt: Date
|
|
16
|
+
/** Who disabled the bundle, and when; null while it may run. */
|
|
17
|
+
disabledBy: string | null
|
|
18
|
+
disabledAt: Date | null
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
const permissionsOf = (value: unknown): string[] => {
|
|
@@ -40,6 +43,8 @@ export class BundleGrantRepository {
|
|
|
40
43
|
permissions: permissionsOf(row.permissions),
|
|
41
44
|
grantedBy: row.granted_by ?? null,
|
|
42
45
|
grantedAt: DbDate.fromDb(row.granted_at) ?? new Date(0),
|
|
46
|
+
disabledBy: row.disabled_by ?? null,
|
|
47
|
+
disabledAt: row.disabled_at ? (DbDate.fromDb(row.disabled_at) ?? null) : null,
|
|
43
48
|
}))
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -47,28 +52,54 @@ export class BundleGrantRepository {
|
|
|
47
52
|
return (await this.all()).find((grant) => grant.bundleId === bundleId)
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
/**
|
|
51
|
-
async grant(grant: Omit<BundleGrant, 'grantedAt'>): Promise<void> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.execute()
|
|
65
|
-
})
|
|
55
|
+
/** Records what a bundle is approved for, keeping whether it is disabled. */
|
|
56
|
+
async grant(grant: Omit<BundleGrant, 'grantedAt' | 'disabledBy' | 'disabledAt'>): Promise<void> {
|
|
57
|
+
const values = {
|
|
58
|
+
package_name: grant.packageName,
|
|
59
|
+
version: grant.version,
|
|
60
|
+
permissions: JSON.stringify(grant.permissions),
|
|
61
|
+
granted_by: grant.grantedBy,
|
|
62
|
+
granted_at: DbDate.toDb(new Date()),
|
|
63
|
+
}
|
|
64
|
+
await this.db.q
|
|
65
|
+
.insertInto('bundle_grant')
|
|
66
|
+
.values({ bundle_id: grant.bundleId, ...values })
|
|
67
|
+
.onConflict((conflict) => conflict.column('bundle_id').doUpdateSet(values))
|
|
68
|
+
.execute()
|
|
66
69
|
}
|
|
67
70
|
|
|
68
|
-
/**
|
|
69
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Disables a bundle, recording its package as it stands when it has no row
|
|
73
|
+
* yet; it stays disabled until `enable`.
|
|
74
|
+
*/
|
|
75
|
+
async disable(
|
|
76
|
+
bundle: Pick<BundleGrant, 'bundleId' | 'packageName' | 'version'>,
|
|
77
|
+
by: string | null,
|
|
78
|
+
): Promise<void> {
|
|
79
|
+
const disabled = { disabled_by: by, disabled_at: DbDate.toDb(new Date()) }
|
|
80
|
+
await this.db.q
|
|
81
|
+
.insertInto('bundle_grant')
|
|
82
|
+
.values({
|
|
83
|
+
bundle_id: bundle.bundleId,
|
|
84
|
+
package_name: bundle.packageName,
|
|
85
|
+
version: bundle.version,
|
|
86
|
+
permissions: JSON.stringify([]),
|
|
87
|
+
granted_by: null,
|
|
88
|
+
granted_at: DbDate.toDb(new Date()),
|
|
89
|
+
...disabled,
|
|
90
|
+
})
|
|
91
|
+
.onConflict((conflict) => conflict.column('bundle_id').doUpdateSet(disabled))
|
|
92
|
+
.execute()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Lets a disabled bundle run again; true when it was disabled. */
|
|
96
|
+
async enable(bundleId: string): Promise<boolean> {
|
|
70
97
|
const before = await this.get(bundleId)
|
|
71
|
-
await this.db.q
|
|
72
|
-
|
|
98
|
+
await this.db.q
|
|
99
|
+
.updateTable('bundle_grant')
|
|
100
|
+
.set({ disabled_by: null, disabled_at: null })
|
|
101
|
+
.where('bundle_id', '=', bundleId)
|
|
102
|
+
.execute()
|
|
103
|
+
return before?.disabledAt != null
|
|
73
104
|
}
|
|
74
105
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 056: an administrator can disable a bundle (story 225). Its row in
|
|
3
|
+
* `bundle_grant` says who disabled it and when; a bundle with neither runs.
|
|
4
|
+
*/
|
|
5
|
+
import { sql } from 'kysely'
|
|
6
|
+
import type { Db } from '../database.ts'
|
|
7
|
+
import type { Migration } from '../migrations.ts'
|
|
8
|
+
import { STATE_JOBS } from './jobs.ts'
|
|
9
|
+
|
|
10
|
+
export const STATE_BUNDLES_DISABLED = '{4b198f00-0056-4ca8-bc39-97d92fca0056}'
|
|
11
|
+
|
|
12
|
+
export const bundlesDisabledMigration: Migration = {
|
|
13
|
+
from: STATE_JOBS,
|
|
14
|
+
to: STATE_BUNDLES_DISABLED,
|
|
15
|
+
name: 'DisableBundles',
|
|
16
|
+
kind: 'expand',
|
|
17
|
+
release: '0.39.0',
|
|
18
|
+
async up(db: Db) {
|
|
19
|
+
const t = db.dialect.types
|
|
20
|
+
await db.q.schema
|
|
21
|
+
.alterTable('bundle_grant')
|
|
22
|
+
.addColumn('disabled_by', sql.raw(t.varchar(255)))
|
|
23
|
+
.execute()
|
|
24
|
+
await db.q.schema
|
|
25
|
+
.alterTable('bundle_grant')
|
|
26
|
+
.addColumn('disabled_at', sql.raw(t.timestamp))
|
|
27
|
+
.execute()
|
|
28
|
+
},
|
|
29
|
+
}
|
package/src/schema/plan.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { auditLogMigration } from './audit-log.ts'
|
|
|
20
20
|
import { bundleComponentsMigration } from './bundle-components.ts'
|
|
21
21
|
import { bundleGrantsMigration } from './bundle-grants.ts'
|
|
22
22
|
import { bundlePackageMigration } from './bundle-package.ts'
|
|
23
|
+
import { bundlesDisabledMigration } from './bundles-disabled.ts'
|
|
23
24
|
import { bundlesRenameMigration } from './bundles-rename.ts'
|
|
24
25
|
import { changeReportMigration } from './change-report.ts'
|
|
25
26
|
import { clientIdPrefixMigration } from './client-id-prefix.ts'
|
|
@@ -125,4 +126,5 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
125
126
|
mediaMemberGrantsMigration,
|
|
126
127
|
bundleGrantsMigration,
|
|
127
128
|
jobsMigration,
|
|
129
|
+
bundlesDisabledMigration,
|
|
128
130
|
])
|
package/src/tables.gen.ts
CHANGED