@crombolo/core 0.25.0 → 0.27.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 +1 -1
- package/src/api-paths.ts +59 -11
- package/src/documents.ts +8 -0
package/package.json
CHANGED
package/src/api-paths.ts
CHANGED
|
@@ -1,28 +1,76 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Where the APIs are served.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* The Management API and the back office's two live-update hubs live under the
|
|
5
|
+
* back office's own path (`backOfficePath`, `/crombolo` unless a site moves
|
|
6
|
+
* it), so the editor and everything it talks to move together. The Delivery
|
|
7
|
+
* API is public and serves apps, so it stays at one fixed path however the
|
|
8
|
+
* back office is mounted: a site that locks its back office down must not cut
|
|
9
|
+
* its apps off with it.
|
|
10
|
+
*
|
|
11
|
+
* Umbraco's own paths — the ones the vendored contract and client declare —
|
|
12
|
+
* keep answering as aliases, so an Umbraco client, an older command line or an
|
|
13
|
+
* older installed client still reach the same API. A request on the new paths
|
|
14
|
+
* is mapped onto these on the way in (`contractPathFor`).
|
|
10
15
|
*/
|
|
11
16
|
export const MANAGEMENT_API_PREFIX = '/umbraco/management/api/'
|
|
12
17
|
|
|
13
18
|
export const MANAGEMENT_API_PATH = `${MANAGEMENT_API_PREFIX}v1`
|
|
14
19
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
/** The Management API under the back office: `<backOfficePath>/management/api/`. */
|
|
21
|
+
export const managementApiPrefix = (backOfficePath: string): string =>
|
|
22
|
+
`${backOfficePath}/management/api/`
|
|
23
|
+
|
|
24
|
+
/** `<backOfficePath>/management/api/v1`. */
|
|
25
|
+
export const managementApiPath = (backOfficePath: string): string =>
|
|
26
|
+
`${managementApiPrefix(backOfficePath)}v1`
|
|
27
|
+
|
|
28
|
+
/** Umbraco's Delivery API at the path its contract and Umbraco's headless clients use. */
|
|
19
29
|
export const DELIVERY_API_PREFIX = '/umbraco/delivery/api'
|
|
20
30
|
|
|
31
|
+
/** The Delivery API at crombolo's own fixed path, wherever the back office is. */
|
|
32
|
+
export const FIXED_DELIVERY_API_PREFIX = '/crombolo/delivery/api'
|
|
33
|
+
|
|
21
34
|
/** `server-event.context.js`: `${serverURL}/umbraco/serverEventHub`. */
|
|
22
35
|
export const SERVER_EVENT_HUB_PATH = '/umbraco/serverEventHub'
|
|
23
36
|
|
|
24
37
|
/** `preview.context.js`: `${serverUrl}/umbraco/PreviewHub`. */
|
|
25
38
|
export const PREVIEW_HUB_PATH = '/umbraco/PreviewHub'
|
|
26
39
|
|
|
40
|
+
export const serverEventHubPath = (backOfficePath: string): string =>
|
|
41
|
+
`${backOfficePath}/serverEventHub`
|
|
42
|
+
|
|
43
|
+
export const previewHubPath = (backOfficePath: string): string => `${backOfficePath}/PreviewHub`
|
|
44
|
+
|
|
27
45
|
/** Where the editor is mounted unless a site overrides `backOfficePath`. */
|
|
28
46
|
export const DEFAULT_BACKOFFICE_PATH = '/crombolo'
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The contract's path for a request on one of the new paths, or undefined when
|
|
50
|
+
* it is not one. The rest of the path and the query are kept.
|
|
51
|
+
*/
|
|
52
|
+
export function contractPathFor(backOfficePath: string, pathname: string): string | undefined {
|
|
53
|
+
const management = managementApiPrefix(backOfficePath)
|
|
54
|
+
if (pathname.startsWith(management))
|
|
55
|
+
return `${MANAGEMENT_API_PREFIX}${pathname.slice(management.length)}`
|
|
56
|
+
if (
|
|
57
|
+
pathname === FIXED_DELIVERY_API_PREFIX ||
|
|
58
|
+
pathname.startsWith(`${FIXED_DELIVERY_API_PREFIX}/`)
|
|
59
|
+
)
|
|
60
|
+
return `${DELIVERY_API_PREFIX}${pathname.slice(FIXED_DELIVERY_API_PREFIX.length)}`
|
|
61
|
+
if (pathname === serverEventHubPath(backOfficePath)) return SERVER_EVENT_HUB_PATH
|
|
62
|
+
if (pathname === previewHubPath(backOfficePath)) return PREVIEW_HUB_PATH
|
|
63
|
+
return undefined
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The vendored client's own requests, moved to the paths above (a pure text
|
|
68
|
+
* rewrite of its modules as they are served). The contract's prefixes appear in
|
|
69
|
+
* the client only as request addresses.
|
|
70
|
+
*/
|
|
71
|
+
export function rehomeClientModule(source: string, backOfficePath: string): string {
|
|
72
|
+
return source
|
|
73
|
+
.replaceAll(MANAGEMENT_API_PREFIX, managementApiPrefix(backOfficePath))
|
|
74
|
+
.replaceAll(SERVER_EVENT_HUB_PATH, serverEventHubPath(backOfficePath))
|
|
75
|
+
.replaceAll(PREVIEW_HUB_PATH, previewHubPath(backOfficePath))
|
|
76
|
+
}
|
package/src/documents.ts
CHANGED
|
@@ -127,3 +127,11 @@ export function normaliseValueCulture(
|
|
|
127
127
|
): string | null {
|
|
128
128
|
return propertyVariesByCulture ? culture : null
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
/** The file path a media item's `umbracoFile` holds, whether an upload or a cropper value. */
|
|
132
|
+
export function mediaFileOf(media: Pick<DocumentAggregate, 'values'>): string | null {
|
|
133
|
+
const value = media.values.find((v) => v.alias === 'umbracoFile')?.value
|
|
134
|
+
if (typeof value === 'string') return value || null
|
|
135
|
+
const src = (value as { src?: unknown } | null | undefined)?.src
|
|
136
|
+
return typeof src === 'string' && src ? src : null
|
|
137
|
+
}
|