@crombolo/server 0.69.0 → 0.70.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.
Files changed (46) hide show
  1. package/package.json +15 -14
  2. package/src/adapters/blueprints.ts +51 -5
  3. package/src/adapters/change-recording.ts +140 -0
  4. package/src/adapters/content.ts +132 -21
  5. package/src/adapters/documents.ts +26 -5
  6. package/src/adapters/elements.ts +3 -0
  7. package/src/adapters/media.ts +7 -1
  8. package/src/adapters/schema-files.ts +89 -1
  9. package/src/adapters/workspace-dictionary.ts +287 -0
  10. package/src/adapters/workspace-file-port.ts +160 -0
  11. package/src/adapters/workspace-languages.ts +94 -0
  12. package/src/approvals-api.ts +16 -7
  13. package/src/bundle-api.ts +19 -16
  14. package/src/bundle-install.ts +4 -0
  15. package/src/change-transfer.ts +676 -0
  16. package/src/changes-api.ts +258 -0
  17. package/src/component-templates-api.ts +2 -2
  18. package/src/config.ts +162 -22
  19. package/src/content-events.ts +65 -1
  20. package/src/content-operations.ts +22 -3
  21. package/src/core.ts +2 -0
  22. package/src/environment-values-api.ts +161 -0
  23. package/src/host-token.ts +30 -1
  24. package/src/node-operations.ts +150 -2
  25. package/src/ports.ts +174 -52
  26. package/src/remote-changes.ts +279 -0
  27. package/src/remote-schema.ts +126 -0
  28. package/src/remote-workspaces.ts +82 -0
  29. package/src/remote.ts +289 -192
  30. package/src/schema-transfer.ts +240 -41
  31. package/src/schema.ts +7 -2
  32. package/src/seed/compile.ts +13 -1
  33. package/src/seed/values.ts +3 -0
  34. package/src/server.ts +971 -364
  35. package/src/settings.ts +123 -5
  36. package/src/site-sections.ts +1 -1
  37. package/src/workspace-access.ts +152 -0
  38. package/src/workspace-checks.ts +299 -0
  39. package/src/workspace-losses.ts +95 -0
  40. package/src/workspace-processes.ts +306 -0
  41. package/src/workspace-render-child.ts +168 -0
  42. package/src/workspace-schema-dir.ts +100 -0
  43. package/src/workspace-schema.ts +598 -0
  44. package/src/workspace-sites.ts +179 -0
  45. package/src/workspace-views.ts +121 -0
  46. package/src/workspaces.ts +1031 -0
@@ -37,6 +37,8 @@ export interface ApprovalsApiContext {
37
37
  /** False on a deployed node with no schema store: a save would not last. */
38
38
  writable: boolean
39
39
  onChanged?: () => Promise<void>
40
+ /** Story 392: `schemaDir` is a workspace's copy, so nothing is synced from it. */
41
+ inWorkspace?: boolean
40
42
  }
41
43
 
42
44
  const json = (body: unknown, status = 200) => Response.json(body, { status })
@@ -50,10 +52,14 @@ export async function syncWorkflowFiles(db: Db, schemaDir: string) {
50
52
  )
51
53
  }
52
54
 
55
+ /** Shared's workflows synced from its files; a workspace's wait for its merge. */
56
+ const syncedFrom = (ctx: ApprovalsApiContext) =>
57
+ ctx.inWorkspace ? Promise.resolve(null) : syncWorkflowFiles(ctx.db, ctx.schemaDir)
58
+
53
59
  /** What saving a workflow would do to the requests in flight under it. */
54
- /** Setting up workflows, which Settings brings (story 322). Deciding on a page is separate. */
60
+ /** Setting up workflows, which Structure brings (story 385). Deciding on a page is separate. */
55
61
  const mayDesignWorkflows = (principal: Principal): boolean =>
56
- principal.isAdmin || hasSection(principal, 'settings')
62
+ principal.isAdmin || hasSection(principal, 'structure')
57
63
 
58
64
  async function changePreview(approvals: Approvals, principal: Principal, workflow: SchemaWorkflow) {
59
65
  const id = workflow.key ?? workflow.alias
@@ -182,9 +188,12 @@ export async function handleApprovalsApi(
182
188
  if (path === 'workflows' && request.method === 'GET') {
183
189
  const loaded = loadSchemaDirectory(ctx.schemaDir)
184
190
  return json({
185
- items: (await readWorkflows(ctx.db)).map((s) => ({
186
- ...s.workflow,
187
- folder: folderIn(loaded.files.get(`workflow:${s.workflow.alias}`)),
191
+ items: (ctx.inWorkspace
192
+ ? (loaded.set.workflows ?? [])
193
+ : (await readWorkflows(ctx.db)).map((s) => s.workflow)
194
+ ).map((workflow) => ({
195
+ ...workflow,
196
+ folder: folderIn(loaded.files.get(`workflow:${workflow.alias}`)),
188
197
  })),
189
198
  folders: foldersIn(ctx.schemaDir, 'workflows'),
190
199
  readOnlyBecause: ctx.writable
@@ -216,7 +225,7 @@ export async function handleApprovalsApi(
216
225
  return json({ ok: false, message: 'There is no such workflow.' }, 404)
217
226
  rmSync(file)
218
227
  await ctx.onChanged?.()
219
- return json({ ok: true, report: await syncWorkflowFiles(ctx.db, ctx.schemaDir) })
228
+ return json({ ok: true, report: await syncedFrom(ctx) })
220
229
  }
221
230
  if (request.method !== 'PUT' && request.method !== 'POST') return undefined
222
231
  const b = await body()
@@ -256,7 +265,7 @@ export async function handleApprovalsApi(
256
265
  if (alias !== workflow.alias && existsSync(file)) rmSync(file)
257
266
  writeFileSync(join(dir, fileNameFor(workflow.alias)), source, 'utf8')
258
267
  await ctx.onChanged?.()
259
- return json({ ok: true, affected, report: await syncWorkflowFiles(ctx.db, ctx.schemaDir) })
268
+ return json({ ok: true, affected, report: await syncedFrom(ctx) })
260
269
  }
261
270
  } catch (error) {
262
271
  if (error instanceof ApprovalRefused)
package/src/bundle-api.ts CHANGED
@@ -116,25 +116,29 @@ export function permissionsFor(method: string, path: string): string[] {
116
116
  .map(([permission]) => permission)
117
117
  }
118
118
 
119
- /** The sections a set of permissions needs, for the API's own section checks. */
120
- const SECTIONS: Readonly<Record<string, string>> = {
121
- content: SECTION_ALIASES.content,
122
- media: SECTION_ALIASES.media,
123
- members: SECTION_ALIASES.members,
124
- users: SECTION_ALIASES.users,
125
- forms: SECTION_ALIASES.forms,
126
- formEntries: SECTION_ALIASES.forms,
127
- dictionary: SECTION_ALIASES.translation,
128
- contentTypes: SECTION_ALIASES.settings,
129
- webhooks: SECTION_ALIASES.settings,
130
- workflows: SECTION_ALIASES.workflow,
131
- redirects: SECTION_ALIASES.content,
119
+ /**
120
+ * The sections a set of permissions needs, for the API's own section checks; the
121
+ * last is the place a person needs to hold it (story 385: pages are Pages', types
122
+ * Structure's).
123
+ */
124
+ const SECTIONS: Readonly<Record<string, readonly string[]>> = {
125
+ content: [SECTION_ALIASES.content, SECTION_ALIASES.pages],
126
+ media: [SECTION_ALIASES.media],
127
+ members: [SECTION_ALIASES.members],
128
+ users: [SECTION_ALIASES.users],
129
+ forms: [SECTION_ALIASES.forms],
130
+ formEntries: [SECTION_ALIASES.forms],
131
+ dictionary: [SECTION_ALIASES.translation],
132
+ contentTypes: [SECTION_ALIASES.structure],
133
+ webhooks: [SECTION_ALIASES.settings],
134
+ workflows: [SECTION_ALIASES.workflow],
135
+ redirects: [SECTION_ALIASES.content, SECTION_ALIASES.pages],
132
136
  }
133
137
 
134
138
  /** The section an area's permission needs, for acting as the person using it (story 325). */
135
139
  export const sectionOfPermission = (permission: string): string | undefined => {
136
140
  const area = permission.split('.')[0] as string
137
- return area === 'identityProviders' ? SECTION_ALIASES.settings : SECTIONS[area]
141
+ return area === 'identityProviders' ? SECTION_ALIASES.settings : SECTIONS[area]?.at(-1)
138
142
  }
139
143
 
140
144
  /** The verbs a set of permissions needs, for the API's own permission checks. */
@@ -169,8 +173,7 @@ export function extensionPrincipal(
169
173
  const set = new Set(granted)
170
174
  const sections = new Set<string>()
171
175
  for (const permission of set) {
172
- const section = SECTIONS[permission.split('.')[0] as string]
173
- if (section) sections.add(section)
176
+ for (const section of SECTIONS[permission.split('.')[0] as string] ?? []) sections.add(section)
174
177
  }
175
178
  const verbs = verbsOf(set)
176
179
  return {
@@ -27,6 +27,7 @@ import {
27
27
  import { ObjectTypes } from '@crombolo/core'
28
28
  import {
29
29
  answersByNode,
30
+ ChangeRepository,
30
31
  type Db,
31
32
  DictionaryRepository,
32
33
  describeRefFailure,
@@ -853,6 +854,8 @@ export async function installBundleContent(
853
854
  result = await db.locks.withLock(Locks.Schema, () =>
854
855
  db.locks.withLock(Locks.ContentTree, () =>
855
856
  db.transaction(async (tx) => {
857
+ // Story 383: replacing a site that holds pages is a change marked as replacing everything.
858
+ const replacing = replace ? await new ChangeRepository(tx).holdsPages() : false
856
859
  const pruned = replace ? await pruneSite(tx, set, replace, config.nodeId) : []
857
860
  if (replace === 'replace-all') await prunePeople(tx, set.people)
858
861
  if (staged?.next.schema) {
@@ -895,6 +898,7 @@ export async function installBundleContent(
895
898
  })
896
899
  if (!imported.runId) throw new InstallRefused([], imported)
897
900
  await recordPruned(tx, imported.runId, pruned)
901
+ if (replacing) await new ChangeRepository(tx).markReplacing(imported.runId)
898
902
  return imported
899
903
  }),
900
904
  ),