@voltro/cms 0.86.0 → 0.87.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 (201) hide show
  1. package/CHANGELOG.md +5321 -0
  2. package/README.md +138 -0
  3. package/THIRD-PARTY-NOTICES.md +860 -221
  4. package/dist/RichDocumentView.js +81 -36
  5. package/dist/aiCandidates.js +3 -3
  6. package/dist/applicationBuildSnapshotService.js +101 -0
  7. package/dist/assetRenditions.js +102 -0
  8. package/dist/assetRevision.js +46 -0
  9. package/dist/assetUseRights.js +72 -0
  10. package/dist/availability.js +19 -16
  11. package/dist/blueprint.js +75 -75
  12. package/dist/build.d.ts +3063 -0
  13. package/dist/build.js +37 -0
  14. package/dist/buildApplicationAdmission.js +16 -0
  15. package/dist/buildApplicationCatalog.js +136 -0
  16. package/dist/buildApplicationCatalogTable.js +24 -0
  17. package/dist/buildApplicationRest.js +99 -0
  18. package/dist/buildApplicationUpload.js +111 -0
  19. package/dist/buildSnapshot.js +401 -0
  20. package/dist/buildSnapshotApplicationPin.js +32 -0
  21. package/dist/buildSnapshotRest.js +210 -0
  22. package/dist/buildSnapshotService.js +265 -0
  23. package/dist/buildSnapshotTables.js +25 -0
  24. package/dist/bulk.js +71 -70
  25. package/dist/changes.js +279 -62
  26. package/dist/consent.js +5 -5
  27. package/dist/contentLocations.js +53 -0
  28. package/dist/contentProjection.js +83 -0
  29. package/dist/contentRouteIdentity.js +13 -0
  30. package/dist/contentRouteMaterializer.js +97 -0
  31. package/dist/contentRouteTypes.js +39 -0
  32. package/dist/contentSeo.js +189 -0
  33. package/dist/contentTreePath.js +60 -0
  34. package/dist/contentType.js +117 -100
  35. package/dist/contentValues.js +18 -0
  36. package/dist/copies.js +3 -3
  37. package/dist/domainHost.js +7 -0
  38. package/dist/domains.js +81 -87
  39. package/dist/draftTexts.js +37 -37
  40. package/dist/duplicates.js +23 -23
  41. package/dist/environmentAliases.js +138 -0
  42. package/dist/environments.js +107 -69
  43. package/dist/errors.js +54 -14
  44. package/dist/experiments.js +7 -7
  45. package/dist/frontendBindings.js +99 -0
  46. package/dist/frontendMedia.js +18 -0
  47. package/dist/index.d.ts +760 -47
  48. package/dist/index.js +89 -73
  49. package/dist/initializePublicRoutes.js +28 -0
  50. package/dist/liveContentRouteView.js +76 -0
  51. package/dist/nativeOutputDeploymentService.js +205 -0
  52. package/dist/outputActivation.js +234 -0
  53. package/dist/outputActivationOrigin.js +51 -0
  54. package/dist/outputActivationStore.js +411 -0
  55. package/dist/outputActivationTables.js +11 -0
  56. package/dist/outputActivationTarget.js +81 -0
  57. package/dist/outputActivationTargetTable.js +25 -0
  58. package/dist/outputDeployment.js +174 -0
  59. package/dist/outputDeploymentRest.js +168 -0
  60. package/dist/outputDeploymentService.js +241 -0
  61. package/dist/outputRouteGraph.js +177 -0
  62. package/dist/outputSafetyArtifact.js +147 -0
  63. package/dist/outputTargetRest.js +62 -0
  64. package/dist/pathSegmentEncoding.js +4 -0
  65. package/dist/privateCmsTransport.js +76 -0
  66. package/dist/privateNativeRouteReservation.js +10 -0
  67. package/dist/promotion.js +68 -59
  68. package/dist/publicBuild.js +90 -0
  69. package/dist/publicBuildRest.js +98 -0
  70. package/dist/publicBuildService.js +63 -0
  71. package/dist/publicOutputHttp.js +129 -0
  72. package/dist/publicOutputService.js +287 -0
  73. package/dist/publicPresentation.js +17 -0
  74. package/dist/publicRouteDispositionAdmission.js +38 -0
  75. package/dist/publicRouteHistoryStore.js +12 -0
  76. package/dist/publicRouteHistoryView.js +34 -0
  77. package/dist/publicRouteIntegrity.js +5 -0
  78. package/dist/publicRouteMutation.js +6 -0
  79. package/dist/publicRouteNamespace.js +134 -0
  80. package/dist/publicRoutePublication.js +36 -0
  81. package/dist/publicRouteRegistry.js +17 -0
  82. package/dist/publicRouteRegistryBinding.js +194 -0
  83. package/dist/publicRouteRegistryDefinition.js +76 -0
  84. package/dist/publicRouteSitePublication.js +40 -0
  85. package/dist/publicRouteTables.js +13 -0
  86. package/dist/publicRouteUrl.js +18 -0
  87. package/dist/publicationSeo.js +52 -0
  88. package/dist/publicationState.js +296 -0
  89. package/dist/quality.js +8 -8
  90. package/dist/reconfigurePublicRoutes.js +41 -0
  91. package/dist/redirects.js +104 -73
  92. package/dist/referenceGraph.js +15 -14
  93. package/dist/references.js +2 -2
  94. package/dist/release.js +177 -141
  95. package/dist/renderReadAuthority.js +43 -0
  96. package/dist/renderReadGrant.js +137 -0
  97. package/dist/review.js +28 -28
  98. package/dist/richDocument.js +54 -24
  99. package/dist/routeDispositionGraph.js +44 -0
  100. package/dist/routeDispositionRest.js +51 -0
  101. package/dist/routeDispositionService.js +73 -0
  102. package/dist/routeDispositionStore.js +289 -0
  103. package/dist/routeDispositionTables.js +5 -0
  104. package/dist/routeDispositions.js +91 -0
  105. package/dist/routeHistoryStorage.js +320 -0
  106. package/dist/routeHistoryStore.js +12 -0
  107. package/dist/schedule.js +36 -36
  108. package/dist/seo.js +1 -1
  109. package/dist/series.js +11 -11
  110. package/dist/share.js +13 -13
  111. package/dist/siteBindings.js +159 -0
  112. package/dist/siteBuildCandidate.js +104 -0
  113. package/dist/siteDelivery.js +115 -0
  114. package/dist/siteState.js +47 -0
  115. package/dist/snapshotAddressGraph.js +55 -0
  116. package/dist/snapshotAddressRead.js +73 -0
  117. package/dist/snapshotAppConsumer.js +71 -0
  118. package/dist/snapshotAppExecution.js +102 -0
  119. package/dist/snapshotApplication.js +75 -0
  120. package/dist/snapshotApprovedRouteDispositions.js +44 -0
  121. package/dist/snapshotAssetAssembly.js +70 -0
  122. package/dist/snapshotAssetAssemblyRest.js +50 -0
  123. package/dist/snapshotBindingRead.js +61 -0
  124. package/dist/snapshotCodeSeo.js +29 -0
  125. package/dist/snapshotComponent.js +34 -0
  126. package/dist/snapshotComponentSource.js +24 -0
  127. package/dist/snapshotConsumer.js +87 -0
  128. package/dist/snapshotContentIdentity.js +10 -0
  129. package/dist/snapshotDefinitions.js +264 -0
  130. package/dist/snapshotDocumentAssembly.js +193 -0
  131. package/dist/snapshotDocumentAssemblyRest.js +84 -0
  132. package/dist/snapshotDocumentProjection.js +202 -0
  133. package/dist/snapshotDocumentTransfer.js +35 -0
  134. package/dist/snapshotDocumentTransferRest.js +80 -0
  135. package/dist/snapshotDomains.js +56 -0
  136. package/dist/snapshotEnvironment.js +31 -0
  137. package/dist/snapshotFieldPlan.js +85 -0
  138. package/dist/snapshotFrontend.js +103 -0
  139. package/dist/snapshotLink.js +8 -0
  140. package/dist/snapshotMedia.js +111 -0
  141. package/dist/snapshotMediaCapture.js +246 -0
  142. package/dist/snapshotMediaFields.js +225 -0
  143. package/dist/snapshotMediaRead.js +185 -0
  144. package/dist/snapshotMediaReader.js +13 -0
  145. package/dist/snapshotObservation.js +16 -0
  146. package/dist/snapshotObservedRouteHistory.js +34 -0
  147. package/dist/snapshotOutputTransfer.js +78 -0
  148. package/dist/snapshotPageLoader.js +7 -0
  149. package/dist/snapshotPageSeo.js +59 -0
  150. package/dist/snapshotPathLocale.js +15 -0
  151. package/dist/snapshotPresentation.js +86 -0
  152. package/dist/snapshotPresentationPolicy.js +12 -0
  153. package/dist/snapshotProjection.js +119 -0
  154. package/dist/snapshotPublicAccess.js +161 -0
  155. package/dist/snapshotPublicRouteHistory.js +40 -0
  156. package/dist/snapshotReadAdmission.js +38 -0
  157. package/dist/snapshotRedirectOutput.js +151 -0
  158. package/dist/snapshotRedirectTargets.js +24 -0
  159. package/dist/snapshotRedirects.js +132 -0
  160. package/dist/snapshotReference.js +8 -0
  161. package/dist/snapshotReferenceAddress.js +10 -0
  162. package/dist/snapshotReferenceGraph.js +79 -0
  163. package/dist/snapshotReferenceRead.js +65 -0
  164. package/dist/snapshotRelease.js +99 -0
  165. package/dist/snapshotRender.js +361 -0
  166. package/dist/snapshotRenderDependencies.js +178 -0
  167. package/dist/snapshotRenditions.js +88 -0
  168. package/dist/snapshotRichDocument.js +62 -0
  169. package/dist/snapshotRoleTransfer.js +106 -0
  170. package/dist/snapshotRoleTransferRest.js +99 -0
  171. package/dist/snapshotRouteAdmission.js +71 -0
  172. package/dist/snapshotRouteDispatch.js +111 -0
  173. package/dist/snapshotRouteDispositionPlan.js +73 -0
  174. package/dist/snapshotRouteRead.js +43 -0
  175. package/dist/snapshotRoutes.js +79 -0
  176. package/dist/snapshotRouting.js +113 -0
  177. package/dist/snapshotSeo.js +179 -0
  178. package/dist/snapshotSeoControls.js +101 -0
  179. package/dist/snapshotSeoDocumentInventory.js +115 -0
  180. package/dist/snapshotSeoDocuments.js +129 -0
  181. package/dist/snapshotSeoMerge.js +85 -0
  182. package/dist/snapshotSeoMetadata.js +137 -0
  183. package/dist/snapshotSeoOutput.js +173 -0
  184. package/dist/snapshotSeoPathSets.js +105 -0
  185. package/dist/snapshotSeoRead.js +88 -0
  186. package/dist/snapshotSite.js +128 -0
  187. package/dist/snapshotSitemapFiles.js +36 -0
  188. package/dist/snapshotTreeDependencies.js +58 -0
  189. package/dist/snapshotTreeLoader.js +10 -0
  190. package/dist/snapshotTreeRead.js +158 -0
  191. package/dist/staticPathSet.js +177 -0
  192. package/dist/staticPathSetRest.js +129 -0
  193. package/dist/staticPathSetService.js +249 -0
  194. package/dist/staticPathSetStore.js +338 -0
  195. package/dist/tree.js +9 -9
  196. package/dist/validation.js +53 -53
  197. package/dist/web.d.ts +709 -7
  198. package/dist/web.js +50 -33
  199. package/dist/workflow.js +8 -8
  200. package/dist/write.js +250 -225
  201. package/package.json +20 -6
@@ -0,0 +1,249 @@
1
+ import { defineSiteDelivery as e } from "./siteDelivery.js";
2
+ import { normalizeHost as t } from "./domainHost.js";
3
+ import { verifyPublicationState as n } from "./publicationState.js";
4
+ import { findVerifiedSnapshotResources as r, pageSnapshotResources as i } from "./buildSnapshot.js";
5
+ import { nativeSnapshotRouteId as a, readSnapshotRouting as o, snapshotCmsPage as s, snapshotRouteDispatch as c, verifySnapshotRouteOwnership as l } from "./snapshotRouting.js";
6
+ import { StaticPathSetConflict as u, StaticPathSetUnavailable as d, copyStaticPathContext as f, copyStaticPathOwners as p, staticPathHash as m, staticPathUrl as h } from "./staticPathSet.js";
7
+ import { readSnapshotAppExecution as g, verifySnapshotAppExecution as _ } from "./snapshotAppExecution.js";
8
+ import { readSnapshotRouteAdmission as v, verifySnapshotContentRoute as y } from "./snapshotRouteAdmission.js";
9
+ import { readAdmittedSnapshotContentRoute as b } from "./snapshotRouteRead.js";
10
+ import { snapshotPathLocale as x } from "./snapshotPathLocale.js";
11
+ import { appendStaticPathStage as S, beginStaticPathSet as C, pageStaticPathSet as w, readStaticPathSet as T, sealStaticPathSet as E } from "./staticPathSetStore.js";
12
+ import { Effect as D } from "effect";
13
+ import { canonicalJson as O } from "@voltro/runtime";
14
+ //#region src/staticPathSetService.ts
15
+ var k = (e) => {
16
+ throw new d({ reason: e });
17
+ }, A = (e) => typeof e != "object" || !e || Array.isArray(e) ? k("integrity") : e, j = (e) => D.tryPromise({
18
+ try: e,
19
+ catch: (e) => e instanceof d || e instanceof u ? e : new d({ reason: "state" })
20
+ }), M = (e) => ({
21
+ id: e.id,
22
+ revision: e.progress.revision,
23
+ phase: e.progress.phase,
24
+ enumerated: e.progress.inputCount,
25
+ set: e.sealed
26
+ }), N = (e) => ({
27
+ snapshot: {
28
+ id: e.snapshot.id,
29
+ digest: e.snapshot.digest
30
+ },
31
+ token: e.token,
32
+ consumerId: e.consumerId,
33
+ buildId: e.buildId,
34
+ host: e.host,
35
+ ...e.localeIds === void 0 ? {} : { localeIds: [...e.localeIds] },
36
+ ...e.owners === void 0 ? {} : { owners: [...e.owners] }
37
+ }), P = async (r, i, a, s) => {
38
+ let c = await v(r, i, a.snapshot, {
39
+ ...a,
40
+ path: "/"
41
+ }, {
42
+ keys: s.keys,
43
+ now: s.now
44
+ }), l = await n(r, i, c.snapshot.manifest.publication, c.now), u = await g(r, i, c.snapshot), d = o(c.configuration), m = e(c.configuration.site), h = m.locales.filter((e) => e.enabled).map((e) => e.id).sort(), _ = a.localeIds === void 0 ? h : [...a.localeIds].sort();
45
+ if (_.length === 0 || _.some((e, t) => !h.includes(e) || t > 0 && _[t - 1] === e)) return k("input");
46
+ let y = p(a.owners ?? ["cms", "code"]), b = t(a.host);
47
+ if (b === null) return k("input");
48
+ let x = (e) => c.snapshot.manifest.parts.find((t) => t.part === e)?.digest ?? k("integrity"), S = f({
49
+ ...i,
50
+ snapshotId: c.snapshot.id,
51
+ snapshotDigest: c.snapshot.digest,
52
+ releaseId: c.snapshot.manifest.publication.releaseId,
53
+ consumerId: a.consumerId,
54
+ buildId: a.buildId,
55
+ inputsId: u.inputsId,
56
+ executionId: u.executionId,
57
+ routesDigest: x("routes"),
58
+ domainsDigest: x("domains"),
59
+ localesDigest: x("locales"),
60
+ policyDigest: x("policies"),
61
+ projectionDigest: x("projection"),
62
+ host: b,
63
+ localeIds: _,
64
+ owners: y
65
+ }), C = d.discovery === null ? [] : d.discovery.pages;
66
+ if (!Array.isArray(C)) return k("integrity");
67
+ let w = C.map(A).sort((e, t) => String(e.file) < String(t.file) ? -1 : +(String(e.file) > String(t.file)));
68
+ return {
69
+ admission: c,
70
+ partitions: l,
71
+ app: u,
72
+ routing: d,
73
+ site: m,
74
+ context: S,
75
+ nativePages: w,
76
+ codePages: y.includes("code") ? w.filter((e) => {
77
+ let t = d.definition?.claims[String(e.file)];
78
+ return t?.kind !== "cms" && (u.web === void 0 || t?.kind === "code" && t.public === !0);
79
+ }) : []
80
+ };
81
+ }, F = (e) => {
82
+ let { store: t, execution: n } = e, o = {
83
+ tenantId: e.scope.tenantId,
84
+ site: e.scope.site,
85
+ environment: e.scope.environment
86
+ }, u = e.now ?? Date.now, d = {
87
+ id: e.key.id,
88
+ material: new Uint8Array(e.key.material)
89
+ }, f = [d, ...(e.verificationKeys ?? []).map((e) => ({
90
+ id: e.id,
91
+ material: new Uint8Array(e.material)
92
+ }))], p = (e, t) => P(e, o, t, {
93
+ keys: f,
94
+ now: u()
95
+ }), g = (e, t, n) => {
96
+ if (t === null) return {};
97
+ let r = e.nativePages.find((e) => e.file === t);
98
+ if (r === void 0) return k("integrity");
99
+ let i = A(r.matcher), a = i.paramNames;
100
+ if (typeof i.source != "string" || i.flags !== "" || !Array.isArray(a) || a.some((e) => typeof e != "string") || new Set(a).size !== a.length) return k("integrity");
101
+ let o = new RegExp(i.source, "").exec(n);
102
+ if (o === null) return k("integrity");
103
+ try {
104
+ return Object.fromEntries(a.map((e, t) => [e, decodeURIComponent(o[t + 1] ?? "")]));
105
+ } catch {
106
+ return k("integrity");
107
+ }
108
+ }, v = (e, t) => {
109
+ if (O(e) !== O(t)) return k("changed");
110
+ };
111
+ return {
112
+ begin: (e) => j(async () => {
113
+ let n = N(e);
114
+ return t.transactional(async (e) => {
115
+ let t = await p(e, n), r = await C(e, t.context, f);
116
+ return await p(e, n), M(r);
117
+ });
118
+ }),
119
+ advance: (e) => j(async () => {
120
+ let u = N(e), C = e.id, w = e.revision;
121
+ if (!Number.isSafeInteger(w) || w < 0) return k("input");
122
+ let D = await t.transactional(async (e) => {
123
+ let t = await p(e, u), n = await T(e, t.context, C, f);
124
+ return {
125
+ ...t,
126
+ set: n
127
+ };
128
+ });
129
+ if (w > D.set.progress.revision) return k("changed");
130
+ if (w < D.set.progress.revision || D.set.sealed !== null) return M(D.set);
131
+ if (D.set.progress.phase === "cms") return t.transactional(async (e) => {
132
+ let t = await p(e, u);
133
+ v(t.context, D.context);
134
+ let n = await i(e, o, t.admission.snapshot.id, "routes", {
135
+ now: t.admission.now,
136
+ limit: 200,
137
+ ...D.set.progress.after === null ? {} : { after: D.set.progress.after }
138
+ }), r = [];
139
+ for (let i of n.items) {
140
+ if (!i.key.startsWith("path:")) continue;
141
+ let n = i.value, a = n.path;
142
+ if (typeof a != "string" || i.key !== "path:" + m(a)) return k("integrity");
143
+ if (y(o, a, n), l(t.admission.configuration, n).owner !== "cms" || !t.context.owners.includes("cms") || !t.context.localeIds.includes(String(n.localeId))) continue;
144
+ let c = await b(e, {
145
+ ...t.admission,
146
+ input: {
147
+ ...t.admission.input,
148
+ path: a
149
+ },
150
+ route: n
151
+ }, t.partitions);
152
+ if (c === null) continue;
153
+ if (x(t.site, a).id !== c.output.localeId) return k("integrity");
154
+ let u = t.app.nativePages ? s(t.routing, a) : null;
155
+ r.push({
156
+ host: t.context.host,
157
+ path: a,
158
+ localeId: c.output.localeId,
159
+ routeId: c.output.routeId,
160
+ owner: "cms",
161
+ file: u?.file ?? null,
162
+ sourceDigest: u?.sourceDigest ?? null,
163
+ parameters: g(t, u?.file ?? null, a)
164
+ });
165
+ }
166
+ let a = await S(e, D.set, {
167
+ source: "cms:" + D.set.progress.revision,
168
+ receiptDigest: m({
169
+ routesDigest: t.context.routesDigest,
170
+ items: n.items
171
+ }),
172
+ entries: r,
173
+ next: {
174
+ phase: n.next === null ? t.codePages.length === 0 ? "seal" : "code" : "cms",
175
+ after: n.next,
176
+ codeIndex: 0
177
+ }
178
+ }, d, f);
179
+ return await p(e, u), M(a);
180
+ });
181
+ if (D.set.progress.phase === "code") {
182
+ let e = D.codePages[D.set.progress.codeIndex];
183
+ if (e === void 0 || typeof e.file != "string" || typeof e.pattern != "string" || !D.app.nativePages) return k("state");
184
+ let i = {
185
+ version: 1,
186
+ file: e.file
187
+ }, s = await n.run({
188
+ inputsId: D.app.inputsId,
189
+ executionId: D.app.executionId,
190
+ exportName: "__voltro_staticPaths",
191
+ inputJson: O(i)
192
+ });
193
+ _(D.app, "__voltro_staticPaths", i, s);
194
+ let b = A(s.value);
195
+ return Object.keys(b).sort().join(",") !== "file,paths,pattern,version" || b.version !== 1 || b.file !== e.file || b.pattern !== e.pattern || !Array.isArray(b.paths) || b.paths.length > 1e4 ? k("integrity") : t.transactional(async (t) => {
196
+ let n = await p(t, u);
197
+ v(n.context, D.context);
198
+ let i = [], _ = b.paths.map((e) => typeof e == "string" ? (h(n.context.host, e), e) : k("integrity"));
199
+ for (let s = 0; s < _.length; s += 200) {
200
+ let u = _.slice(s, s + 200), d = await r(t, o, n.admission.snapshot, "routes", u.map((e) => "path:" + m(e)));
201
+ for (let t of u) {
202
+ let r = d.get("path:" + m(t))?.value;
203
+ r !== void 0 && y(o, t, r);
204
+ let s = r === void 0 ? c(n.routing, t, !1) : l(n.admission.configuration, r);
205
+ if (s?.owner !== "code" || s.code === null || s.code.file !== e.file) continue;
206
+ let u = x(n.site, t);
207
+ n.context.localeIds.includes(u.id) && i.push({
208
+ host: n.context.host,
209
+ path: t,
210
+ localeId: u.id,
211
+ routeId: a(o, u.id, s.code.file, t),
212
+ owner: "code",
213
+ file: s.code.file,
214
+ sourceDigest: s.code.sourceDigest,
215
+ parameters: g(n, s.code.file, t)
216
+ });
217
+ }
218
+ }
219
+ let C = D.set.progress.codeIndex + 1, w = await S(t, D.set, {
220
+ source: "code:" + e.file,
221
+ receiptDigest: m(s),
222
+ entries: i,
223
+ next: {
224
+ phase: C === n.codePages.length ? "seal" : "code",
225
+ after: null,
226
+ codeIndex: C
227
+ }
228
+ }, d, f);
229
+ return await p(t, u), M(w);
230
+ });
231
+ }
232
+ return t.transactional(async (e) => {
233
+ let t = await p(e, u);
234
+ v(t.context, D.context);
235
+ let n = await E(e, D.set, d, f);
236
+ return await p(e, u), M(n);
237
+ });
238
+ }),
239
+ page: (e) => j(async () => {
240
+ let n = N(e), r = e.id, i = e.index, a = e.digest;
241
+ return t.transactional(async (e) => {
242
+ let t = await p(e, n), o = await w(e, t.context, r, i, f);
243
+ return o.set.id === a ? (await p(e, n), o) : k("changed");
244
+ });
245
+ })
246
+ };
247
+ };
248
+ //#endregion
249
+ export { F as createCmsStaticPathSets, P as readSnapshotStaticPathAdmission };
@@ -0,0 +1,338 @@
1
+ import { StaticPathSetConflict as e, StaticPathSetUnavailable as t, copyStaticPathContext as n, copyStaticPathEntry as r, signStaticPathSet as i, staticPathHash as a, staticPathUrl as o, verifyStaticPathPage as s, verifyStaticPathSet as c } from "./staticPathSet.js";
2
+ import { and as l, eq as u, generateId as d, id as f, integer as p, json as m, table as h, text as g } from "@voltro/database";
3
+ import { tenant as _ } from "@voltro/plugin-multitenancy/mixin";
4
+ import { createHash as v, createHmac as y, timingSafeEqual as b } from "node:crypto";
5
+ import { canonicalJson as x } from "@voltro/runtime";
6
+ //#region src/staticPathSetStore.ts
7
+ var S = "_voltro_cms_static_path_sets", C = "_voltro_cms_static_path_pages", w = h(S, {
8
+ id: f({ prefix: "cpaths" }),
9
+ site: g().maxLength(64),
10
+ environment: g().maxLength(64),
11
+ contextDigest: g().maxLength(64),
12
+ context: m(),
13
+ progress: m(),
14
+ sealed: m().nullable()
15
+ }).with(_()).unique("cms_static_path_set_context", [
16
+ "tenantId",
17
+ "site",
18
+ "environment",
19
+ "contextDigest"
20
+ ]), T = h(C, {
21
+ id: f({ prefix: "cpathpg" }),
22
+ site: g().maxLength(64),
23
+ environment: g().maxLength(64),
24
+ setId: g().maxLength(64),
25
+ kind: g().oneOf([
26
+ "input",
27
+ "stage",
28
+ "output"
29
+ ]),
30
+ ordinal: p(),
31
+ value: m(),
32
+ digest: g().maxLength(64)
33
+ }).with(_()).unique("cms_static_path_page", [
34
+ "tenantId",
35
+ "setId",
36
+ "kind",
37
+ "ordinal"
38
+ ]), E = Object.freeze([w, T]), D = (e) => {
39
+ throw new t({ reason: e });
40
+ }, O = (e) => typeof e == "string" && /^[A-Za-z0-9_-]{1,64}$/.test(e), k = (e) => typeof e == "string" && /^[a-f0-9]{64}$/.test(e), A = (e) => typeof e != "object" || !e || Array.isArray(e) ? D("state") : e, j = (e) => l(u("tenantId", e.tenantId), u("site", e.site), u("environment", e.environment)), M = (e) => {
41
+ let t = A(e);
42
+ return Object.keys(t).sort().join(",") !== "after,chain,codeIndex,inputBytes,inputCount,inputPages,phase,revision,version" || t.version !== 1 || ![
43
+ "cms",
44
+ "code",
45
+ "seal",
46
+ "ready"
47
+ ].includes(String(t.phase)) || !(t.after === null || O(t.after)) || !k(t.chain) || ![
48
+ "codeIndex",
49
+ "inputBytes",
50
+ "inputCount",
51
+ "inputPages",
52
+ "revision"
53
+ ].every((e) => Number.isSafeInteger(t[e]) && Number(t[e]) >= 0) || Number(t.codeIndex) > 4096 || Number(t.inputCount) > 1e5 || Number(t.inputPages) > 1e5 || Number(t.inputBytes) > 67108864 || Number(t.revision) > 1e5 ? D("state") : { ...t };
54
+ }, N = (e, t, n) => {
55
+ if (!O(e.id) || e.contextDigest !== a(t) || x(e.context) !== x(t)) return D("changed");
56
+ let r = M(e.progress), i = e.sealed === null ? null : c(e.sealed, n);
57
+ return i !== null != (r.phase === "ready") || i !== null && x(i.manifest.context) !== x(t) ? D("state") : {
58
+ id: e.id,
59
+ context: t,
60
+ progress: r,
61
+ sealed: i
62
+ };
63
+ }, P = async (e, t, r, i, a = !1) => {
64
+ let o = n(t);
65
+ if (!O(r)) return D("input");
66
+ let [s] = await e.query({
67
+ table: S,
68
+ predicate: l(j(o), u("id", r)),
69
+ ...a ? { lock: "update" } : {},
70
+ order: [],
71
+ take: 1,
72
+ skip: void 0,
73
+ projection: void 0
74
+ });
75
+ if (s === void 0) return D("state");
76
+ let c = N(s, o, i);
77
+ return await L(e, c, i), c;
78
+ }, F = async (e, t, r) => {
79
+ let i = n(t), o = a(i), s = d({
80
+ kind: "typeid",
81
+ prefix: "cpaths"
82
+ }, S);
83
+ if (s === null) return D("state");
84
+ let c = {
85
+ version: 1,
86
+ phase: "cms",
87
+ after: null,
88
+ codeIndex: 0,
89
+ revision: 0,
90
+ inputPages: 0,
91
+ inputCount: 0,
92
+ inputBytes: 0,
93
+ chain: a({ context: i })
94
+ };
95
+ await e.insertIgnore(S, {
96
+ id: s,
97
+ tenantId: i.tenantId,
98
+ site: i.site,
99
+ environment: i.environment,
100
+ contextDigest: o,
101
+ context: i,
102
+ progress: c,
103
+ sealed: null
104
+ }, { conflictColumns: [
105
+ "tenantId",
106
+ "site",
107
+ "environment",
108
+ "contextDigest"
109
+ ] });
110
+ let [f] = await e.query({
111
+ table: S,
112
+ predicate: l(j(i), u("contextDigest", o)),
113
+ lock: "update",
114
+ order: [],
115
+ take: 1,
116
+ skip: void 0,
117
+ projection: void 0
118
+ });
119
+ if (f === void 0) return D("state");
120
+ let p = N(f, i, r);
121
+ return await L(e, p, r), p;
122
+ }, I = (e, t) => !O(t.id) || !(t.material instanceof Uint8Array) || t.material.byteLength < 32 ? D("key") : y("sha256", t.material).update(x({
123
+ purpose: "voltro.cms.static-path-stage/v1",
124
+ value: e,
125
+ keyId: t.id
126
+ })).digest("hex"), L = async (e, t, n) => {
127
+ if (t.progress.revision === 0) {
128
+ let e = {
129
+ version: 1,
130
+ phase: "cms",
131
+ after: null,
132
+ codeIndex: 0,
133
+ revision: 0,
134
+ inputPages: 0,
135
+ inputCount: 0,
136
+ inputBytes: 0,
137
+ chain: a({ context: t.context })
138
+ };
139
+ return x(t.progress) !== x(e) || t.sealed !== null ? D("integrity") : void 0;
140
+ }
141
+ let r = A(await R(e, t, "stage", t.progress.revision)), i = A(r.body), o = n.find((e) => e.id === r.keyId), s = {
142
+ ...t.progress,
143
+ chain: "",
144
+ ...t.sealed === null ? {} : { phase: "seal" }
145
+ };
146
+ if (o === void 0 || !k(r.signature) || i.setId !== t.id || i.contextDigest !== a(t.context) || a(i) !== t.progress.chain || x(i.next) !== x(s) || !b(Buffer.from(I(i, o), "hex"), Buffer.from(r.signature, "hex"))) return D("integrity");
147
+ }, R = async (e, t, n, r) => {
148
+ let [i] = await e.query({
149
+ table: C,
150
+ predicate: l(j(t.context), u("setId", t.id), u("kind", n), u("ordinal", r)),
151
+ order: [],
152
+ take: 1,
153
+ skip: void 0,
154
+ projection: void 0
155
+ });
156
+ return i === void 0 || i.digest !== a(i.value) ? D("integrity") : i.value;
157
+ }, z = (e, t, n, r, i) => e.insert(C, {
158
+ tenantId: t.context.tenantId,
159
+ site: t.context.site,
160
+ environment: t.context.environment,
161
+ setId: t.id,
162
+ kind: n,
163
+ ordinal: r,
164
+ value: i,
165
+ digest: a(i)
166
+ }), B = async (e, t, n, i, o) => {
167
+ if (t.sealed !== null || !k(n.receiptDigest) || n.source.length === 0 || n.source.length > 2048 || n.entries.length > 1e4) return D("input");
168
+ if (t.progress.phase === "seal" || t.progress.phase === "ready" || n.next.phase === "ready" || t.progress.phase === "cms" && (n.next.codeIndex !== 0 || n.next.phase === "cms" && (n.next.after === null || n.next.after === t.progress.after) || n.next.phase !== "cms" && n.next.after !== null) || t.progress.phase === "code" && (n.next.phase === "cms" || n.next.after !== null || n.next.codeIndex !== t.progress.codeIndex + 1)) return D("state");
169
+ let s = n.entries.map(r), c = t.progress.revision + 1;
170
+ if (s.some((e) => e.host !== t.context.host || !t.context.localeIds.includes(e.localeId) || !t.context.owners.includes(e.owner))) return D("input");
171
+ let l = Buffer.byteLength(x(s)), u = M({
172
+ ...t.progress,
173
+ ...n.next,
174
+ revision: c,
175
+ inputPages: t.progress.inputPages + Math.ceil(s.length / 200),
176
+ inputCount: t.progress.inputCount + s.length,
177
+ inputBytes: t.progress.inputBytes + l
178
+ }), d = {
179
+ contextDigest: a(t.context),
180
+ setId: t.id,
181
+ revision: c,
182
+ source: n.source,
183
+ receiptDigest: n.receiptDigest,
184
+ previous: t.progress.chain,
185
+ pages: Array.from({ length: Math.ceil(s.length / 200) }, (e, t) => a(s.slice(t * 200, (t + 1) * 200))),
186
+ next: {
187
+ ...u,
188
+ chain: ""
189
+ }
190
+ }, f = a(d), p = {
191
+ ...u,
192
+ chain: f
193
+ }, m = await P(e, t.context, t.id, o, !0);
194
+ if (m.progress.revision >= c) {
195
+ let t = A(await R(e, m, "stage", c));
196
+ return a(t.body) === f ? m : D("changed");
197
+ }
198
+ if (x(m.progress) !== x(t.progress)) return D("changed");
199
+ for (let n = 0; n < d.pages.length; n++) await z(e, m, "input", t.progress.inputPages + n + 1, s.slice(n * 200, (n + 1) * 200));
200
+ return await z(e, m, "stage", c, {
201
+ body: d,
202
+ keyId: i.id,
203
+ signature: I(d, i)
204
+ }), await e.update(S, t.id, { progress: p }), {
205
+ ...m,
206
+ progress: p
207
+ };
208
+ }, V = async (t, n, s, c) => {
209
+ let l = await P(t, n.context, n.id, c, !0);
210
+ if (l.sealed !== null) return l;
211
+ if (l.progress.phase !== "seal" || x(l.progress) !== x(n.progress)) return D("changed");
212
+ let u = [], d = v("sha256"), f = a({ context: l.context }), p = 0, m = 0;
213
+ for (let e = 1; e <= l.progress.revision; e++) {
214
+ let n = A(await R(t, l, "stage", e)), i = A(n.body), o = c.find((e) => e.id === n.keyId);
215
+ if (o === void 0 || !k(n.signature) || !b(Buffer.from(I(i, o), "hex"), Buffer.from(n.signature, "hex")) || i.contextDigest !== a(l.context) || i.setId !== l.id || i.revision !== e || i.previous !== f || !Array.isArray(i.pages) || i.pages.length > 50 || i.pages.some((e) => !k(e))) return D("integrity");
216
+ f = a(i), d.update(x({
217
+ source: i.source,
218
+ receiptDigest: i.receiptDigest,
219
+ pages: i.pages
220
+ }) + "\n");
221
+ let s = [];
222
+ for (let e of i.pages) {
223
+ let n = await R(t, l, "input", ++p);
224
+ if (!Array.isArray(n) || n.length < 1 || n.length > 200 || a(n) !== e) return D("integrity");
225
+ s.push(...n.map(r));
226
+ }
227
+ if (m += Buffer.byteLength(x(s)), u.length + s.length > 1e5 || m > 67108864) return D("bounds");
228
+ u.push(...s);
229
+ }
230
+ if (f !== l.progress.chain || p !== l.progress.inputPages || u.length !== l.progress.inputCount || m !== l.progress.inputBytes) return D("integrity");
231
+ let h = u.map((e) => ({
232
+ entry: e,
233
+ url: o(e.host, e.path)
234
+ })).sort((e, t) => e.url < t.url ? -1 : +(e.url > t.url));
235
+ for (let t = 0; t < h.length; t++) {
236
+ let n = h[t];
237
+ if (n.entry.host !== l.context.host || !l.context.localeIds.includes(n.entry.localeId) || !l.context.owners.includes(n.entry.owner)) return D("integrity");
238
+ if (t > 0 && h[t - 1].url === n.url) throw new e({
239
+ url: n.url,
240
+ owners: [h[t - 1].entry, n.entry].map((e) => `${e.owner}:${e.file ?? e.routeId}`),
241
+ repair: "Change the captured location or native path enumeration and capture a new build snapshot."
242
+ });
243
+ }
244
+ let g = [];
245
+ for (let e = 0; e < h.length; e += 200) {
246
+ let n = h.slice(e, e + 200), r = n.map((e) => e.entry);
247
+ g.push({
248
+ count: r.length,
249
+ digest: a(r),
250
+ first: n[0].url,
251
+ last: n[n.length - 1].url
252
+ }), await z(t, l, "output", g.length, r);
253
+ }
254
+ let _ = i({
255
+ version: 1,
256
+ context: l.context,
257
+ sort: "host-nfc-path/v1",
258
+ pageSize: 200,
259
+ count: h.length,
260
+ sources: {
261
+ count: l.progress.revision,
262
+ digest: d.digest("hex")
263
+ },
264
+ pages: g
265
+ }, s), y = {
266
+ ...l.progress,
267
+ phase: "ready"
268
+ };
269
+ return await t.update(S, l.id, {
270
+ progress: y,
271
+ sealed: _
272
+ }), {
273
+ ...l,
274
+ progress: y,
275
+ sealed: _
276
+ };
277
+ }, H = async (e, t, n, r, i) => {
278
+ let a = await P(e, t, n, i);
279
+ if (a.sealed === null || !Number.isSafeInteger(r) || r < 0 || r > a.sealed.manifest.pages.length) return D("state");
280
+ if (a.sealed.manifest.count > 0 && r >= a.sealed.manifest.pages.length) return D("bounds");
281
+ if (a.sealed.manifest.count === 0 && r === 0) return {
282
+ set: a.sealed,
283
+ index: r,
284
+ entries: [],
285
+ next: null
286
+ };
287
+ let o = s(a.sealed, r, await R(e, a, "output", r + 1));
288
+ return {
289
+ set: a.sealed,
290
+ index: r,
291
+ entries: o,
292
+ next: r + 1 < a.sealed.manifest.pages.length ? r + 1 : null
293
+ };
294
+ }, U = async (e, t, r, i) => {
295
+ if (typeof t != "object" || !t || Array.isArray(t) || !O(t.tenantId) || !O(t.site) || !O(t.environment) || !O(r?.id) || !k(r?.digest)) return D("input");
296
+ let a = {
297
+ tenantId: t.tenantId,
298
+ site: t.site,
299
+ environment: t.environment
300
+ }, [o] = await e.query({
301
+ table: S,
302
+ predicate: l(j(a), u("id", r.id)),
303
+ order: [],
304
+ take: 1,
305
+ skip: void 0,
306
+ projection: void 0
307
+ });
308
+ if (o === void 0) return D("state");
309
+ let c = n(o.context);
310
+ if (c.tenantId !== a.tenantId || c.site !== a.site || c.environment !== a.environment) return D("changed");
311
+ let d = await P(e, c, r.id, i), f = d.sealed;
312
+ if (f === null) return D("state");
313
+ if (f.id !== r.digest) return D("changed");
314
+ let p = await e.query({
315
+ table: C,
316
+ predicate: l(j(a), u("setId", r.id), u("kind", "output")),
317
+ order: [{
318
+ column: "ordinal",
319
+ direction: "asc"
320
+ }],
321
+ take: f.manifest.pages.length + 1,
322
+ skip: void 0,
323
+ projection: ["ordinal"]
324
+ });
325
+ if (p.length !== f.manifest.pages.length || p.some((e, t) => e.ordinal !== t + 1)) return D("integrity");
326
+ let m = [], h = 0, g = Buffer.byteLength(x(f));
327
+ for (let t = 0; t < f.manifest.pages.length; t++) {
328
+ let n = s(f, t, await R(e, d, "output", t + 1));
329
+ if (g += Buffer.byteLength(x(n)), h += n.length, g > 67108864 || h > 1e5) return D("bounds");
330
+ m.push([...n]);
331
+ }
332
+ return h === f.manifest.count ? {
333
+ set: f,
334
+ pages: m
335
+ } : D("integrity");
336
+ };
337
+ //#endregion
338
+ export { C as STATIC_PATH_PAGES_TABLE, S as STATIC_PATH_SETS_TABLE, B as appendStaticPathStage, F as beginStaticPathSet, H as pageStaticPathSet, P as readStaticPathSet, U as readStaticPathSetEvidence, V as sealStaticPathSet, T as staticPathPagesTable, E as staticPathSetTables, w as staticPathSetsTable };
package/dist/tree.js CHANGED
@@ -19,13 +19,13 @@ var e = (e, t) => {
19
19
  let n = e(t.row, i), r = o.get(n) ?? [];
20
20
  r.push(t), o.set(n, r);
21
21
  }
22
- let s = (e, r) => t(e.row, i) - t(r.row, i) || n(e.row, i).localeCompare(n(r.row, i)) || String(e.row.documentId).localeCompare(String(r.row.documentId)), c = [], l = /* @__PURE__ */ new Set(), u = (e, t) => {
23
- for (let r of [...o.get(e) ?? []].sort(s)) {
22
+ let s = (e, t) => e < t ? -1 : +(e > t), c = (e, r) => t(e.row, i) - t(r.row, i) || s(n(e.row, i), n(r.row, i)) || s(String(e.row.documentId), String(r.row.documentId)), l = [], u = /* @__PURE__ */ new Set(), d = (e, t) => {
23
+ for (let r of [...o.get(e) ?? []].sort(c)) {
24
24
  let a = r.row.documentId, o = n(r.row, i);
25
- if (o === "" || l.has(a)) continue;
26
- l.add(a);
25
+ if (o === "" || u.has(a)) continue;
26
+ u.add(a);
27
27
  let s = [...t, o];
28
- c.push({
28
+ l.push({
29
29
  documentId: a,
30
30
  parent: e,
31
31
  depth: t.length,
@@ -34,12 +34,12 @@ var e = (e, t) => {
34
34
  row: r.row,
35
35
  locale: r.locale,
36
36
  fallback: r.fallback
37
- }), u(a, s);
37
+ }), d(a, s);
38
38
  }
39
39
  };
40
- return u(null, []), {
41
- nodes: c,
42
- orphans: [...a.keys()].filter((e) => !l.has(e)).sort()
40
+ return d(null, []), {
41
+ nodes: l,
42
+ orphans: [...a.keys()].filter((e) => !u.has(e)).sort()
43
43
  };
44
44
  }, i = (e) => e != null && e !== "", a = (e, t, n, r = {}) => {
45
45
  let a = new Map(e.nodes.map((e) => [e.documentId, e])), o = r.ancestorsOnly === !0 ? t.parent === null ? void 0 : a.get(t.parent) : t, s = /* @__PURE__ */ new Set();