@crombolo/api-management 0.21.0 → 0.22.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 +3 -3
- package/src/authorization.ts +12 -3
- package/src/handlers/document.ts +13 -1
- package/src/ports.ts +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/api-management",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Umbraco-compatible Management API handlers for crombolo.",
|
|
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.
|
|
32
|
-
"@crombolo/contracts": "0.
|
|
31
|
+
"@crombolo/core": "0.22.0",
|
|
32
|
+
"@crombolo/contracts": "0.22.0"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/authorization.ts
CHANGED
|
@@ -523,10 +523,19 @@ export async function canReadDocument(
|
|
|
523
523
|
key: string,
|
|
524
524
|
nodes: NodeLookup,
|
|
525
525
|
): Promise<boolean> {
|
|
526
|
-
if (!hasSection(principal, 'content')) return false
|
|
527
526
|
const node = (await nodes.documents([key])).get(key.toLowerCase())
|
|
528
|
-
|
|
529
|
-
|
|
527
|
+
return node !== undefined && canReadDocumentAt(principal, node.chain, node.trashed)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** `canReadDocument` for a document whose place is known: its ancestors' keys then its own. Pure. */
|
|
531
|
+
export function canReadDocumentAt(
|
|
532
|
+
principal: Principal,
|
|
533
|
+
chain: readonly string[],
|
|
534
|
+
trashed = false,
|
|
535
|
+
): boolean {
|
|
536
|
+
if (!hasSection(principal, 'content')) return false
|
|
537
|
+
if (!hasPathAccess(principal.startNodes.document, chain, trashed)) return false
|
|
538
|
+
return permissionsForPath(principal.groups, chain).has(D.Read)
|
|
530
539
|
}
|
|
531
540
|
|
|
532
541
|
/** Evaluates the operation's section requirements, then its node rules. */
|
package/src/handlers/document.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
ROOT_ACCESS,
|
|
21
21
|
} from '@crombolo/core'
|
|
22
22
|
import { deniedChildren, deniedPropertyWrite } from '../authorization.ts'
|
|
23
|
-
import type
|
|
23
|
+
import { APP_PREVIEW_PROVIDER, type PreviewPort } from '../ports.ts'
|
|
24
24
|
import type { ApprovalGatePort, DocumentPort, PortFailure, SaveDocument } from '../ports-content.ts'
|
|
25
25
|
import type { ManagementApiRouter, RequestContext } from '../router.ts'
|
|
26
26
|
import { created, paging } from './content-type.ts'
|
|
@@ -918,6 +918,18 @@ export function registerDocumentHandlers(
|
|
|
918
918
|
)
|
|
919
919
|
const culture = ctx.url.searchParams.get('culture') || null
|
|
920
920
|
const segment = ctx.url.searchParams.get('segment') || null
|
|
921
|
+
const provider = ctx.url.searchParams.get('providerAlias')
|
|
922
|
+
// The app's own address: no preview cookie, since nothing here renders it.
|
|
923
|
+
if (provider === APP_PREVIEW_PROVIDER && preview.inApp && ctx.principal) {
|
|
924
|
+
const inApp = await preview.inApp(key, culture, ctx.principal)
|
|
925
|
+
return Response.json({
|
|
926
|
+
url: 'url' in inApp ? inApp.url : null,
|
|
927
|
+
provider,
|
|
928
|
+
isExternal: true,
|
|
929
|
+
culture,
|
|
930
|
+
message: 'message' in inApp ? inApp.message : null,
|
|
931
|
+
})
|
|
932
|
+
}
|
|
921
933
|
const query = new URLSearchParams({ id: key, culture: culture ?? '', segment: segment ?? '' })
|
|
922
934
|
const headers = new Headers({ 'content-type': 'application/json' })
|
|
923
935
|
for (const cookie of preview.enter()) headers.append('set-cookie', cookie)
|
package/src/ports.ts
CHANGED
|
@@ -185,11 +185,23 @@ export interface DynamicRootPort {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
/** Preview mode is a cookie; the server owns its name and attributes. */
|
|
188
|
+
/** The provider alias the Preview in app option asks for (story 053). */
|
|
189
|
+
export const APP_PREVIEW_PROVIDER = 'cromboloAppPreview'
|
|
190
|
+
|
|
188
191
|
export interface PreviewPort {
|
|
189
192
|
/** `Set-Cookie` values that enter preview for the signed-in editor. */
|
|
190
193
|
enter(): string[]
|
|
191
194
|
/** `Set-Cookie` values that leave it. */
|
|
192
195
|
exit(): string[]
|
|
196
|
+
/**
|
|
197
|
+
* Where a page previews in the site's app, with a preview token for the
|
|
198
|
+
* editor in it, or why it cannot; absent when the site has no app preview.
|
|
199
|
+
*/
|
|
200
|
+
inApp?(
|
|
201
|
+
key: string,
|
|
202
|
+
culture: string | null,
|
|
203
|
+
principal: Principal,
|
|
204
|
+
): Promise<{ url: string } | { message: string }>
|
|
193
205
|
}
|
|
194
206
|
|
|
195
207
|
export interface DictionaryItemModel {
|