@crombolo/api-management 0.63.0 → 0.65.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/api-management",
3
- "version": "0.63.0",
3
+ "version": "0.65.1",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Umbraco-compatible Management API handlers for crombolo.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -29,8 +29,8 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@crombolo/content": "0.63.0",
33
- "@crombolo/contracts": "0.63.0",
34
- "@crombolo/core": "0.63.0"
32
+ "@crombolo/content": "0.65.1",
33
+ "@crombolo/contracts": "0.65.1",
34
+ "@crombolo/core": "0.65.1"
35
35
  }
36
36
  }
@@ -2,7 +2,7 @@
2
2
  import type { ResponseOf } from '@crombolo/contracts'
3
3
  import type { DataTypeModel, TreeItem } from '@crombolo/core'
4
4
  import { invalidSkipTake, notFound, problemDetails, problemResponse } from '@crombolo/core'
5
- import type { DataTypePort } from '../ports-content.ts'
5
+ import type { DataTypePort, PortFailure } from '../ports-content.ts'
6
6
  import type { ManagementApiRouter, RequestContext } from '../router.ts'
7
7
  import {
8
8
  created,
@@ -94,7 +94,11 @@ export function registerDataTypeHandlers(router: ManagementApiRouter, port: Data
94
94
  router.handle('PostDataType', async (ctx) => {
95
95
  const body = (await ctx.request.json()) as Record<string, unknown>
96
96
  const key = typeof body.id === 'string' && body.id ? body.id : crypto.randomUUID()
97
- await port.save(fromRequest(key, body), ctx.principal as NonNullable<typeof ctx.principal>)
97
+ const refused = await port.save(
98
+ fromRequest(key, body),
99
+ ctx.principal as NonNullable<typeof ctx.principal>,
100
+ )
101
+ if (refused) return refusedSave(refused)
98
102
  ctx.notifications.push({ message: 'Data type created', category: 'Data Type', type: 'Success' })
99
103
  return created(`${ctx.url.origin}/umbraco/management/api/v1/data-type/${key}`, key)
100
104
  })
@@ -105,10 +109,11 @@ export function registerDataTypeHandlers(router: ManagementApiRouter, port: Data
105
109
  if (!existing) return problemResponse(notFound('The data type could not be found'))
106
110
  const body = (await ctx.request.json()) as Record<string, unknown>
107
111
  // Keep the storage type the editor was created with.
108
- await port.save(
112
+ const refused = await port.save(
109
113
  { ...fromRequest(key, body), dbType: existing.dbType },
110
114
  ctx.principal as NonNullable<typeof ctx.principal>,
111
115
  )
116
+ if (refused) return refusedSave(refused)
112
117
  ctx.notifications.push({ message: 'Data type saved', category: 'Data Type', type: 'Success' })
113
118
  return new Response(null, { status: 200 })
114
119
  })
@@ -300,3 +305,13 @@ export function registerDataTypeHandlers(router: ManagementApiRouter, port: Data
300
305
  )
301
306
  })
302
307
  }
308
+
309
+ /** A save the server refused, such as one that would leave the schema files invalid. */
310
+ const refusedSave = (failure: PortFailure) =>
311
+ problemResponse(
312
+ problemDetails({
313
+ title: 'The data type was not saved',
314
+ status: failure.status ?? 400,
315
+ detail: failure.reason,
316
+ }),
317
+ )
@@ -55,7 +55,7 @@ const USER_PROBLEMS: Partial<Record<UserStatus, [number, string, string]>> = {
55
55
  CannotInvite: [
56
56
  500,
57
57
  'Cannot send user invitation',
58
- 'This site cannot send e-mail, so users cannot be invited. Configure an e-mail provider — CROMBOLO_EMAIL_PROVIDER, or `email` in crombolo.config.ts — or create the user and give them a password instead.',
58
+ 'This site cannot send e-mail, so users cannot be invited. Set up e-mail in Settings, under E-mail, or create the user and give them a password instead.',
59
59
  ],
60
60
  InvalidPassword: [
61
61
  400,
@@ -238,7 +238,8 @@ export interface DataTypePort extends TreePort {
238
238
  ): Promise<{ valueTypeName: string; jsonSchema: Record<string, unknown> } | undefined>
239
239
  byKey(key: string): Promise<DataTypeModel | undefined>
240
240
  byKeys(keys: readonly string[]): Promise<DataTypeModel[]>
241
- save(model: DataTypeModel, principal: Principal): Promise<void>
241
+ /** A failure when the save would leave the schema files invalid (story 344). */
242
+ save(model: DataTypeModel, principal: Principal): Promise<PortFailure | undefined>
242
243
  /** 'in-use' when a property type still uses it. */
243
244
  remove(key: string): Promise<boolean | 'in-use'>
244
245
  filter(
package/src/router.ts CHANGED
@@ -66,6 +66,11 @@ export interface Principal {
66
66
  * the remote protocol's routes.
67
67
  */
68
68
  ci?: { rule: string; claims: Record<string, string> }
69
+ /**
70
+ * Set while an administrator's session views as user groups (story 314):
71
+ * everything above is the groups', and they are who this really is.
72
+ */
73
+ viewingAs?: { groups: Array<{ key: string; name: string }>; until: Date }
69
74
  }
70
75
 
71
76
  export interface RequestContext {