@crombolo/contracts 0.24.1 → 0.26.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/spec.ts +15 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/contracts",
3
- "version": "0.24.1",
3
+ "version": "0.26.0",
4
4
  "description": "The Umbraco Management and Delivery API OpenAPI documents and the TypeScript types generated from them.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
package/src/spec.ts CHANGED
@@ -55,11 +55,24 @@ export function loadSpec(): OpenApiSpec {
55
55
  }
56
56
 
57
57
  /** The contract as `GET …/openapi.json` serves it. */
58
- export function servedContract(): string {
58
+ /**
59
+ * The contract as a site serves it. With `prefix`, its paths are moved from
60
+ * Umbraco's `/umbraco/management/api/` to where this site serves the API.
61
+ */
62
+ export function servedContract(prefix?: string): string {
59
63
  if (!served) served = JSON.stringify(loadSpec())
60
- return served
64
+ if (!prefix || prefix === UMBRACO_PREFIX) return served
65
+ let moved = servedAt.get(prefix)
66
+ if (!moved) {
67
+ moved = served.replaceAll(`"${UMBRACO_PREFIX}`, `"${prefix}`)
68
+ servedAt.set(prefix, moved)
69
+ }
70
+ return moved
61
71
  }
62
72
 
73
+ const UMBRACO_PREFIX = '/umbraco/management/api/'
74
+ const servedAt = new Map<string, string>()
75
+
63
76
  let deliveryCached: OpenApiSpec | undefined
64
77
 
65
78
  export function loadDeliverySpec(): OpenApiSpec {