@voltro/cms 0.85.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 (244) hide show
  1. package/CHANGELOG.md +5987 -0
  2. package/README.md +138 -0
  3. package/THIRD-PARTY-NOTICES.md +864 -253
  4. package/dist/ContentForm.js +282 -0
  5. package/dist/RichDocumentEditor.js +550 -0
  6. package/dist/RichDocumentView.js +177 -0
  7. package/dist/RichTextSurface.js +135 -0
  8. package/dist/aiCandidates.js +199 -0
  9. package/dist/aiOperations.js +152 -0
  10. package/dist/applicationBuildSnapshotService.js +101 -0
  11. package/dist/assetRenditions.js +102 -0
  12. package/dist/assetRevision.js +46 -0
  13. package/dist/assetUseRights.js +72 -0
  14. package/dist/audiences.js +31 -0
  15. package/dist/availability.js +124 -0
  16. package/dist/blueprint.js +166 -0
  17. package/dist/build.d.ts +3063 -0
  18. package/dist/build.js +37 -0
  19. package/dist/buildApplicationAdmission.js +16 -0
  20. package/dist/buildApplicationCatalog.js +136 -0
  21. package/dist/buildApplicationCatalogTable.js +24 -0
  22. package/dist/buildApplicationRest.js +99 -0
  23. package/dist/buildApplicationUpload.js +111 -0
  24. package/dist/buildSnapshot.js +401 -0
  25. package/dist/buildSnapshotApplicationPin.js +32 -0
  26. package/dist/buildSnapshotRest.js +210 -0
  27. package/dist/buildSnapshotService.js +265 -0
  28. package/dist/buildSnapshotTables.js +25 -0
  29. package/dist/bulk.js +282 -0
  30. package/dist/cacheIdentity.js +152 -0
  31. package/dist/changes.js +307 -0
  32. package/dist/cmsContext.js +229 -0
  33. package/dist/collections.js +224 -0
  34. package/dist/consent.js +29 -0
  35. package/dist/contentLocations.js +53 -0
  36. package/dist/contentProjection.js +83 -0
  37. package/dist/contentRouteIdentity.js +13 -0
  38. package/dist/contentRouteMaterializer.js +97 -0
  39. package/dist/contentRouteTypes.js +39 -0
  40. package/dist/contentSeo.js +189 -0
  41. package/dist/contentTreePath.js +60 -0
  42. package/dist/contentType.js +208 -0
  43. package/dist/contentValues.js +18 -0
  44. package/dist/contentfulImport.js +162 -0
  45. package/dist/copies.js +89 -0
  46. package/dist/cutover.js +202 -0
  47. package/dist/deliveryChecks.js +138 -0
  48. package/dist/domainHost.js +7 -0
  49. package/dist/domains.js +139 -0
  50. package/dist/draftTexts.js +164 -0
  51. package/dist/duplicates.js +78 -0
  52. package/dist/edgePurge.js +69 -0
  53. package/dist/editHistory.js +113 -0
  54. package/dist/effectForm.js +11 -0
  55. package/dist/environmentAliases.js +138 -0
  56. package/dist/environments.js +147 -0
  57. package/dist/errors.js +107 -0
  58. package/dist/experiments.js +528 -0
  59. package/dist/exposure.js +28 -0
  60. package/dist/extensionManifest.js +81 -0
  61. package/dist/extensions.js +314 -0
  62. package/dist/fieldSchema.js +199 -0
  63. package/dist/formStrings.js +74 -0
  64. package/dist/frontendBindings.js +99 -0
  65. package/dist/frontendMedia.js +18 -0
  66. package/dist/glossary.js +73 -0
  67. package/dist/history.js +54 -0
  68. package/dist/htmlImport.js +297 -0
  69. package/dist/index.d.ts +771 -54
  70. package/dist/index.js +89 -6082
  71. package/dist/initializePublicRoutes.js +28 -0
  72. package/dist/liveContentRouteView.js +76 -0
  73. package/dist/media.js +29 -0
  74. package/dist/metrics.js +46 -0
  75. package/dist/migration.js +193 -0
  76. package/dist/migrationStages.js +13 -0
  77. package/dist/nativeOutputDeploymentService.js +205 -0
  78. package/dist/outputActivation.js +234 -0
  79. package/dist/outputActivationOrigin.js +51 -0
  80. package/dist/outputActivationStore.js +411 -0
  81. package/dist/outputActivationTables.js +11 -0
  82. package/dist/outputActivationTarget.js +81 -0
  83. package/dist/outputActivationTargetTable.js +25 -0
  84. package/dist/outputDeployment.js +174 -0
  85. package/dist/outputDeploymentRest.js +168 -0
  86. package/dist/outputDeploymentService.js +241 -0
  87. package/dist/outputRouteGraph.js +177 -0
  88. package/dist/outputSafetyArtifact.js +147 -0
  89. package/dist/outputTargetRest.js +62 -0
  90. package/dist/pathSegmentEncoding.js +4 -0
  91. package/dist/presenceAnchors.js +68 -0
  92. package/dist/preview.js +31 -0
  93. package/dist/privateCmsTransport.js +76 -0
  94. package/dist/privateNativeRouteReservation.js +10 -0
  95. package/dist/promotion.js +116 -0
  96. package/dist/publicBuild.js +90 -0
  97. package/dist/publicBuildRest.js +98 -0
  98. package/dist/publicBuildService.js +63 -0
  99. package/dist/publicOutputHttp.js +129 -0
  100. package/dist/publicOutputService.js +287 -0
  101. package/dist/publicPresentation.js +17 -0
  102. package/dist/publicRouteDispositionAdmission.js +38 -0
  103. package/dist/publicRouteHistoryStore.js +12 -0
  104. package/dist/publicRouteHistoryView.js +34 -0
  105. package/dist/publicRouteIntegrity.js +5 -0
  106. package/dist/publicRouteMutation.js +6 -0
  107. package/dist/publicRouteNamespace.js +134 -0
  108. package/dist/publicRoutePublication.js +36 -0
  109. package/dist/publicRouteRegistry.js +17 -0
  110. package/dist/publicRouteRegistryBinding.js +194 -0
  111. package/dist/publicRouteRegistryDefinition.js +76 -0
  112. package/dist/publicRouteSitePublication.js +40 -0
  113. package/dist/publicRouteTables.js +13 -0
  114. package/dist/publicRouteUrl.js +18 -0
  115. package/dist/publicationSeo.js +52 -0
  116. package/dist/publicationState.js +296 -0
  117. package/dist/quality.js +188 -0
  118. package/dist/reconfigurePublicRoutes.js +41 -0
  119. package/dist/recurrence.js +78 -0
  120. package/dist/redirects.js +130 -0
  121. package/dist/referenceGraph.js +224 -0
  122. package/dist/references.js +173 -0
  123. package/dist/release.js +241 -0
  124. package/dist/renderReadAuthority.js +43 -0
  125. package/dist/renderReadGrant.js +137 -0
  126. package/dist/rest.js +52 -0
  127. package/dist/review.js +160 -0
  128. package/dist/richDocument.js +521 -0
  129. package/dist/richInline.js +100 -0
  130. package/dist/routeDispositionGraph.js +44 -0
  131. package/dist/routeDispositionRest.js +51 -0
  132. package/dist/routeDispositionService.js +73 -0
  133. package/dist/routeDispositionStore.js +289 -0
  134. package/dist/routeDispositionTables.js +5 -0
  135. package/dist/routeDispositions.js +91 -0
  136. package/dist/routeHistoryStorage.js +320 -0
  137. package/dist/routeHistoryStore.js +12 -0
  138. package/dist/schedule.js +80 -0
  139. package/dist/search.js +148 -0
  140. package/dist/selectionIntent.js +164 -0
  141. package/dist/seo.js +31 -0
  142. package/dist/series.js +105 -0
  143. package/dist/share.js +112 -0
  144. package/dist/siteBindings.js +159 -0
  145. package/dist/siteBuildCandidate.js +104 -0
  146. package/dist/siteDelivery.js +115 -0
  147. package/dist/siteState.js +47 -0
  148. package/dist/snapshotAddressGraph.js +55 -0
  149. package/dist/snapshotAddressRead.js +73 -0
  150. package/dist/snapshotAppConsumer.js +71 -0
  151. package/dist/snapshotAppExecution.js +102 -0
  152. package/dist/snapshotApplication.js +75 -0
  153. package/dist/snapshotApprovedRouteDispositions.js +44 -0
  154. package/dist/snapshotAssetAssembly.js +70 -0
  155. package/dist/snapshotAssetAssemblyRest.js +50 -0
  156. package/dist/snapshotBindingRead.js +61 -0
  157. package/dist/snapshotCodeSeo.js +29 -0
  158. package/dist/snapshotComponent.js +34 -0
  159. package/dist/snapshotComponentSource.js +24 -0
  160. package/dist/snapshotConsumer.js +87 -0
  161. package/dist/snapshotContentIdentity.js +10 -0
  162. package/dist/snapshotDefinitions.js +264 -0
  163. package/dist/snapshotDocumentAssembly.js +193 -0
  164. package/dist/snapshotDocumentAssemblyRest.js +84 -0
  165. package/dist/snapshotDocumentProjection.js +202 -0
  166. package/dist/snapshotDocumentTransfer.js +35 -0
  167. package/dist/snapshotDocumentTransferRest.js +80 -0
  168. package/dist/snapshotDomains.js +56 -0
  169. package/dist/snapshotEnvironment.js +31 -0
  170. package/dist/snapshotFieldPlan.js +85 -0
  171. package/dist/snapshotFrontend.js +103 -0
  172. package/dist/snapshotLink.js +8 -0
  173. package/dist/snapshotMedia.js +111 -0
  174. package/dist/snapshotMediaCapture.js +246 -0
  175. package/dist/snapshotMediaFields.js +225 -0
  176. package/dist/snapshotMediaRead.js +185 -0
  177. package/dist/snapshotMediaReader.js +13 -0
  178. package/dist/snapshotObservation.js +16 -0
  179. package/dist/snapshotObservedRouteHistory.js +34 -0
  180. package/dist/snapshotOutputTransfer.js +78 -0
  181. package/dist/snapshotPageLoader.js +7 -0
  182. package/dist/snapshotPageSeo.js +59 -0
  183. package/dist/snapshotPathLocale.js +15 -0
  184. package/dist/snapshotPresentation.js +86 -0
  185. package/dist/snapshotPresentationPolicy.js +12 -0
  186. package/dist/snapshotProjection.js +119 -0
  187. package/dist/snapshotPublicAccess.js +161 -0
  188. package/dist/snapshotPublicRouteHistory.js +40 -0
  189. package/dist/snapshotReadAdmission.js +38 -0
  190. package/dist/snapshotRedirectOutput.js +151 -0
  191. package/dist/snapshotRedirectTargets.js +24 -0
  192. package/dist/snapshotRedirects.js +132 -0
  193. package/dist/snapshotReference.js +8 -0
  194. package/dist/snapshotReferenceAddress.js +10 -0
  195. package/dist/snapshotReferenceGraph.js +79 -0
  196. package/dist/snapshotReferenceRead.js +65 -0
  197. package/dist/snapshotRelease.js +99 -0
  198. package/dist/snapshotRender.js +361 -0
  199. package/dist/snapshotRenderDependencies.js +178 -0
  200. package/dist/snapshotRenditions.js +88 -0
  201. package/dist/snapshotRichDocument.js +62 -0
  202. package/dist/snapshotRoleTransfer.js +106 -0
  203. package/dist/snapshotRoleTransferRest.js +99 -0
  204. package/dist/snapshotRouteAdmission.js +71 -0
  205. package/dist/snapshotRouteDispatch.js +111 -0
  206. package/dist/snapshotRouteDispositionPlan.js +73 -0
  207. package/dist/snapshotRouteRead.js +43 -0
  208. package/dist/snapshotRoutes.js +79 -0
  209. package/dist/snapshotRouting.js +113 -0
  210. package/dist/snapshotSeo.js +179 -0
  211. package/dist/snapshotSeoControls.js +101 -0
  212. package/dist/snapshotSeoDocumentInventory.js +115 -0
  213. package/dist/snapshotSeoDocuments.js +129 -0
  214. package/dist/snapshotSeoMerge.js +85 -0
  215. package/dist/snapshotSeoMetadata.js +137 -0
  216. package/dist/snapshotSeoOutput.js +173 -0
  217. package/dist/snapshotSeoPathSets.js +105 -0
  218. package/dist/snapshotSeoRead.js +88 -0
  219. package/dist/snapshotSite.js +128 -0
  220. package/dist/snapshotSitemapFiles.js +36 -0
  221. package/dist/snapshotTreeDependencies.js +58 -0
  222. package/dist/snapshotTreeLoader.js +10 -0
  223. package/dist/snapshotTreeRead.js +158 -0
  224. package/dist/staticPathSet.js +177 -0
  225. package/dist/staticPathSetRest.js +129 -0
  226. package/dist/staticPathSetService.js +249 -0
  227. package/dist/staticPathSetStore.js +338 -0
  228. package/dist/stewardship.js +146 -0
  229. package/dist/taxonomy.js +36 -0
  230. package/dist/team.js +103 -0
  231. package/dist/templates.js +106 -0
  232. package/dist/trackChanges.js +197 -0
  233. package/dist/translation.js +64 -0
  234. package/dist/tree.js +87 -0
  235. package/dist/usage.js +50 -0
  236. package/dist/validation.js +192 -0
  237. package/dist/visualEditing.js +60 -0
  238. package/dist/web.d.ts +709 -7
  239. package/dist/web.js +50 -2
  240. package/dist/workflow.js +322 -0
  241. package/dist/write.js +419 -0
  242. package/dist/xliff.js +325 -0
  243. package/package.json +20 -6
  244. package/dist/presenceAnchors-4iHAVQB3.js +0 -4367
@@ -0,0 +1,173 @@
1
+ import { richDocumentProblems as e, richDocumentReferences as t } from "./richDocument.js";
2
+ import { asTyped as n } from "./effectForm.js";
3
+ import { and as r, eq as i, gt as a, id as o, integer as s, table as c, text as l } from "@voltro/database";
4
+ import { tenant as u } from "@voltro/plugin-multitenancy/mixin";
5
+ //#region src/references.ts
6
+ var d = "cms_references", f = c(d, {
7
+ id: o({ prefix: "cref" }),
8
+ sourceType: l().maxLength(64),
9
+ sourceDocumentId: l().maxLength(64),
10
+ sourceVariantId: l().maxLength(64),
11
+ stage: l().maxLength(16).oneOf([
12
+ "published",
13
+ "draft",
14
+ "revision"
15
+ ]).default("published"),
16
+ revisionId: l().maxLength(64).nullable(),
17
+ revisionNumber: s().nullable(),
18
+ site: l().maxLength(64),
19
+ environment: l().maxLength(64),
20
+ locale: l().maxLength(64),
21
+ path: l(),
22
+ targetType: l().maxLength(64),
23
+ targetDocumentId: l().maxLength(64)
24
+ }).with(u()).index("cms_references_by_target", [
25
+ "tenantId",
26
+ "stage",
27
+ "site",
28
+ "environment",
29
+ "targetType",
30
+ "targetDocumentId"
31
+ ]).index("cms_references_by_source", [
32
+ "stage",
33
+ "sourceType",
34
+ "sourceVariantId",
35
+ "site",
36
+ "environment",
37
+ "locale"
38
+ ]), p = (n, r, i, a) => {
39
+ if (r != null) switch (n.kind) {
40
+ case "reference":
41
+ typeof r == "string" && r !== "" && n.referenceType !== void 0 && a.push({
42
+ path: i,
43
+ targetType: n.referenceType,
44
+ targetDocumentId: r
45
+ });
46
+ return;
47
+ case "array":
48
+ n.element !== void 0 && Array.isArray(r) && r.forEach((e, t) => p(n.element, e, `${i}[${t}]`, a));
49
+ return;
50
+ case "struct":
51
+ if (n.struct !== void 0 && typeof r == "object") for (let [e, t] of Object.entries(n.struct)) p(t, r[e], `${i}.${e}`, a);
52
+ return;
53
+ case "richText": {
54
+ let o = n.richText ?? {};
55
+ if (e(i, r, o).length > 0) return;
56
+ let s = r;
57
+ a.push(...t(i, s, o));
58
+ let c = new Map((o.profile?.components ?? []).map((e) => [e.id, e]));
59
+ s.blocks.forEach((e, t) => {
60
+ let n = e.type === "component" ? c.get(e.componentId) : void 0;
61
+ if (n !== void 0 && e.type === "component") for (let [r, o] of Object.entries(n.props)) p(o, e.props[r], `${i}.blocks[${t}].props.${r}`, a);
62
+ });
63
+ return;
64
+ }
65
+ case "components": {
66
+ if (!Array.isArray(r)) return;
67
+ let e = new Map((n.components ?? []).map((e) => [e.id, e]));
68
+ r.forEach((t, n) => {
69
+ let r = t, o = e.get(String(r.componentId));
70
+ if (o !== void 0 && typeof r.props == "object" && r.props !== null) for (let [e, t] of Object.entries(o.props)) p(t, r.props[e], `${i}[${n}].props.${e}`, a);
71
+ });
72
+ return;
73
+ }
74
+ default: return;
75
+ }
76
+ }, m = (e, t) => {
77
+ let n = [];
78
+ for (let [r, i] of Object.entries(e.fields)) p(i, t[r], r, n);
79
+ return n;
80
+ }, h = (e, t, n, a) => ({
81
+ table: d,
82
+ predicate: r(i("sourceType", e.name), i("stage", a), i("sourceVariantId", t), i("site", n.site), i("environment", n.environment), i("locale", n.locale)),
83
+ order: [],
84
+ take: void 0,
85
+ skip: void 0,
86
+ projection: void 0
87
+ }), g = async (e, t, n, r, i = "published") => {
88
+ await e.deleteMany(d, { where: h(t, n, r, i).predicate });
89
+ }, _ = async (e, t, n, r, i = "published") => {
90
+ let a = n.id;
91
+ await g(e, t, a, r, i), await v(e, t, n, r, i);
92
+ }, v = async (e, t, n, r, i) => {
93
+ let a = n.id, o = n.tenantId, s = m(t, n).map((e) => ({
94
+ sourceType: t.name,
95
+ sourceDocumentId: n.documentId,
96
+ sourceVariantId: a,
97
+ stage: i,
98
+ revisionId: typeof n.revisionId == "string" ? n.revisionId : null,
99
+ revisionNumber: typeof n.revision == "number" ? n.revision : null,
100
+ site: r.site,
101
+ environment: r.environment,
102
+ locale: r.locale,
103
+ path: e.path,
104
+ targetType: e.targetType,
105
+ targetDocumentId: e.targetDocumentId,
106
+ ...o == null ? {} : { tenantId: o }
107
+ }));
108
+ s.length > 0 && await e.insertMany(d, s, { returning: "none" });
109
+ }, y = (e) => {
110
+ let t = (e) => e.kind === "reference" || e.kind === "richText" || e.element !== void 0 && t(e.element) || Object.values(e.struct ?? {}).some(t) || (e.components ?? []).some((e) => Object.values(e.props).some(t));
111
+ return Object.values(e.fields).some(t);
112
+ }, b = async (e, t, n, r) => {
113
+ let i = n.values;
114
+ if (typeof i != "object" || !i) return;
115
+ let a = m(t, i).map((e) => ({
116
+ sourceType: t.name,
117
+ sourceDocumentId: n.documentId,
118
+ sourceVariantId: n.id,
119
+ stage: "revision",
120
+ revisionId: n.id,
121
+ revisionNumber: n.number,
122
+ ...r,
123
+ ...e,
124
+ ...n.tenantId !== void 0 && n.tenantId !== null ? { tenantId: n.tenantId } : {}
125
+ }));
126
+ a.length > 0 && await e.insertMany(d, a, { returning: "none" });
127
+ }, x = async (e, t, n) => {
128
+ async function* o(t, n) {
129
+ let i;
130
+ for (;;) {
131
+ let o = await e.query({
132
+ table: t,
133
+ predicate: i === void 0 ? n : r(n, a("id", i)),
134
+ order: [{
135
+ column: "id",
136
+ direction: "asc"
137
+ }],
138
+ take: 500,
139
+ skip: void 0,
140
+ projection: void 0
141
+ });
142
+ for (let e of o) yield e;
143
+ if (o.length < 500) return;
144
+ i = String(o.at(-1).id);
145
+ }
146
+ }
147
+ for (let a of t) {
148
+ for (let t of ["draft", "revision"]) await e.deleteMany(d, { where: r(i("stage", t), i("sourceType", a.name), i("site", n.site), i("environment", n.environment)) });
149
+ for await (let t of o(`${a.name}_drafts`, r(i("site", n.site), i("environment", n.environment)))) t.status !== "archived" && await v(e, a, t, {
150
+ ...n,
151
+ locale: String(t.locale)
152
+ }, "draft");
153
+ for await (let t of o("cms_revisions", r(i("contentType", a.name), i("site", n.site), i("environment", n.environment)))) await b(e, a, t, {
154
+ ...n,
155
+ locale: String(t.locale)
156
+ });
157
+ }
158
+ }, S = async (e, t, n) => (await e.query({
159
+ table: d,
160
+ predicate: r(i("targetType", t.type), i("stage", "published"), i("targetDocumentId", t.documentId), i("site", n.site), i("environment", n.environment)),
161
+ order: [],
162
+ take: void 0,
163
+ skip: void 0,
164
+ projection: void 0
165
+ })).map((e) => ({
166
+ sourceType: e.sourceType,
167
+ sourceDocumentId: e.sourceDocumentId,
168
+ sourceVariantId: e.sourceVariantId,
169
+ locale: e.locale,
170
+ path: e.path
171
+ })).sort((e, t) => e.sourceType.localeCompare(t.sourceType) || e.sourceDocumentId.localeCompare(t.sourceDocumentId) || e.locale.localeCompare(t.locale) || e.path.localeCompare(t.path)), C = (...e) => n(() => S(...e)), w = (...e) => n(() => x(...e));
172
+ //#endregion
173
+ export { d as CMS_REFERENCES_TABLE, g as clearReferences, f as cmsReferencesTable, y as hasReferenceFields, x as rebuildReferenceIndex, w as rebuildReferenceIndexEffect, m as referencesOf, S as usedBy, C as usedByEffect, _ as writeReferences, b as writeRevisionReferences };
@@ -0,0 +1,241 @@
1
+ import { PublicRouteRegistryUnavailable as e } from "./publicRouteRegistry.js";
2
+ import { ChangeFeedUnavailable as t, ContentNotFound as n, ReferenceUnavailable as r, ReleaseNotEditable as i, ReviewRequired as a } from "./errors.js";
3
+ import { asTyped as o } from "./effectForm.js";
4
+ import { activatePublicationRelease as s, lockPublicationStream as c } from "./changes.js";
5
+ import { withPublicRouteStateMutation as l } from "./publicRouteMutation.js";
6
+ import { withPublicRoutePublicationBatch as u } from "./publicRoutePublication.js";
7
+ import { publishRevision as d, unpublish as f } from "./write.js";
8
+ import { and as p, eq as m, generateId as h, id as g, integer as _, isNull as v, json as y, lte as b, table as x, text as S, timestamp as C } from "@voltro/database";
9
+ import { tenant as w } from "@voltro/plugin-multitenancy/mixin";
10
+ //#region src/release.ts
11
+ var T = "cms_releases", E = "cms_release_items", D = [
12
+ "draft",
13
+ "scheduled",
14
+ "published",
15
+ "failed"
16
+ ], O = x(T, {
17
+ id: g({ prefix: "crel" }),
18
+ name: S(),
19
+ site: S().maxLength(64),
20
+ environment: S().maxLength(64),
21
+ status: S().oneOf(D),
22
+ scheduledAt: C().nullable(),
23
+ publishedAt: C().nullable(),
24
+ publicationGeneration: S().maxLength(20).nullable(),
25
+ publicationCheckpoint: S().maxLength(64).nullable(),
26
+ rollbackOf: S().nullable(),
27
+ claimToken: S().nullable(),
28
+ failure: S().nullable()
29
+ }).with(w()), k = x(E, {
30
+ id: g({ prefix: "crit" }),
31
+ releaseId: S(),
32
+ contentType: S().maxLength(64),
33
+ variantId: S().maxLength(64),
34
+ locale: S().maxLength(64),
35
+ action: S().oneOf(["publish", "unpublish"]),
36
+ revisionId: S().nullable(),
37
+ previousRevisionId: S().nullable(),
38
+ position: _(),
39
+ inherited: y().nullable()
40
+ }).with(w()).unique("cms_release_items_uq_variant", [
41
+ "tenantId",
42
+ "releaseId",
43
+ "contentType",
44
+ "variantId"
45
+ ]), A = (e, t, n, r, i) => e.query({
46
+ table: t,
47
+ predicate: n,
48
+ ...i === void 0 ? {} : { lock: i },
49
+ order: r === void 0 ? [] : [r],
50
+ take: void 0,
51
+ skip: void 0,
52
+ projection: void 0
53
+ }), j = async (e, t, r) => {
54
+ let [i] = await A(e, T, m("id", t), void 0, r);
55
+ if (i === void 0) throw new n({
56
+ contentType: "release",
57
+ id: t,
58
+ stage: "draft"
59
+ });
60
+ return i;
61
+ }, M = async (e, n) => {
62
+ let r = await j(e, n);
63
+ if (typeof r.tenantId != "string" || r.tenantId === "") throw new t({ reason: "scope" });
64
+ return await c(e, {
65
+ tenantId: r.tenantId,
66
+ site: String(r.site),
67
+ environment: String(r.environment)
68
+ }), j(e, n, "update");
69
+ }, N = (e, t) => ({
70
+ site: String(e.site),
71
+ environment: String(e.environment),
72
+ locale: t
73
+ }), P = (e, t) => e.insert(T, {
74
+ ...t,
75
+ status: "draft"
76
+ }), F = async (e, t, r) => {
77
+ let a = await j(e, t, "update");
78
+ if (a.status !== "draft") throw new i({
79
+ id: t,
80
+ status: String(a.status)
81
+ });
82
+ let o = N(a, r.locale), [s] = await A(e, `${r.type.name}_drafts`, p(m("id", r.id), m("site", o.site), m("environment", o.environment), m("locale", o.locale)), void 0, "update");
83
+ if (s === void 0) throw new n({
84
+ contentType: r.type.name,
85
+ id: r.id,
86
+ stage: "draft"
87
+ });
88
+ let c = r.action ?? "publish", l = await A(e, E, p(m("releaseId", t), m("contentType", r.type.name), m("variantId", r.id)), void 0, "update"), u = {
89
+ action: c,
90
+ locale: r.locale,
91
+ revisionId: c === "publish" ? r.revisionId ?? String(s.revisionId) : null
92
+ }, [d] = l;
93
+ if (d !== void 0) return await e.update("cms_release_items", String(d.id), u) ?? d;
94
+ let f = (await A(e, E, m("releaseId", t), void 0, "update")).length;
95
+ return e.insert(E, {
96
+ releaseId: t,
97
+ contentType: r.type.name,
98
+ variantId: r.id,
99
+ position: f,
100
+ ...u
101
+ });
102
+ }, I = async (e, t) => {
103
+ let [n] = await A(e, T, m("id", t));
104
+ return n === void 0 ? null : String(n.status);
105
+ }, L = (e, t) => A(e, E, m("releaseId", t), {
106
+ column: "position",
107
+ direction: "asc"
108
+ }), R = (e, t) => A(e, T, p(m("site", t.site), m("environment", t.environment)), {
109
+ column: "createdAt",
110
+ direction: "desc"
111
+ }), z = async (e, t, n, r) => {
112
+ let [i] = await A(e, `${t}_published`, p(m("id", n), m("site", r.site), m("environment", r.environment), m("locale", r.locale)), void 0, "update");
113
+ return i === void 0 ? null : String(i.revisionId);
114
+ }, B = async (e, t, r, a = /* @__PURE__ */ new Date(), o = {}) => {
115
+ let c = await M(e, r);
116
+ if (c.status !== "draft" && c.status !== "scheduled") throw new i({
117
+ id: r,
118
+ status: String(c.status)
119
+ });
120
+ return u(e, {
121
+ tenantId: String(c.tenantId),
122
+ site: String(c.site),
123
+ environment: String(c.environment)
124
+ }, async () => {
125
+ let i = new Map(t.map((e) => [e.name, e]));
126
+ for (let t of await A(e, E, m("releaseId", r), {
127
+ column: "position",
128
+ direction: "asc"
129
+ }, "update")) {
130
+ let a = i.get(String(t.contentType));
131
+ if (a === void 0) throw new n({
132
+ contentType: String(t.contentType),
133
+ id: String(t.variantId),
134
+ stage: "draft"
135
+ });
136
+ let o = N(c, String(t.locale)), s = String(t.variantId), l = await z(e, a.name, s, o);
137
+ t.action === "publish" ? await d(e, a, s, o, String(t.revisionId), { releaseId: r }) : l !== null && await f(e, a, s, o, { releaseId: r }), await e.update(E, String(t.id), { previousRevisionId: l });
138
+ }
139
+ let l = await s(e, {
140
+ tenantId: String(c.tenantId),
141
+ site: String(c.site),
142
+ environment: String(c.environment)
143
+ }, r), u = await e.update("cms_releases", r, {
144
+ status: "published",
145
+ publishedAt: a,
146
+ publicationGeneration: l.generation,
147
+ publicationCheckpoint: l.checkpoint
148
+ }) ?? c;
149
+ for (let t of o.afterPublish ?? []) await t(e, u, a);
150
+ return u;
151
+ });
152
+ }, V = async (e, t, n) => {
153
+ let r = await j(e, t, "update");
154
+ if (r.status !== "draft") throw new i({
155
+ id: t,
156
+ status: String(r.status)
157
+ });
158
+ return await e.update("cms_releases", t, {
159
+ status: "scheduled",
160
+ scheduledAt: n
161
+ }) ?? r;
162
+ }, H = async (e, t, n = /* @__PURE__ */ new Date(), r = {}) => {
163
+ let i = await A(e, T, p(m("status", "scheduled"), b("scheduledAt", n))), a = [];
164
+ for (let o of i) {
165
+ let i = String(o.id), s = h({
166
+ kind: "typeid",
167
+ prefix: "claim"
168
+ }, "cms_releases") ?? `claim_${Date.now()}`;
169
+ try {
170
+ await e.transactional(async (e) => (await M(e, i), await e.updateMany("cms_releases", { claimToken: s }, { where: p(m("id", i), m("status", "scheduled")) }) === 1 && (await B(e, t, i, n, r), !0))) && a.push(i);
171
+ } catch (t) {
172
+ await e.updateMany(T, {
173
+ status: "failed",
174
+ failure: U(t)
175
+ }, { where: p(m("id", i), m("status", "scheduled"), o.claimToken === null || o.claimToken === void 0 ? v("claimToken") : m("claimToken", o.claimToken)) });
176
+ }
177
+ }
178
+ return a;
179
+ }, U = (e) => {
180
+ if (e instanceof r) return `ReferenceUnavailable: ${e.contentType} ${e.id} uses ${e.targets.map((e) => `${e.contentType} ${e.documentId} (${e.reason})`).join(", ")}`;
181
+ if (e instanceof a) return `ReviewRequired: ${e.contentType} ${e.id} revision ${e.revisionId} is not approved`;
182
+ if (e instanceof n) return `ContentNotFound: ${e.contentType} ${e.id} (${e.stage})`;
183
+ let t = e?._tag;
184
+ return typeof t == "string" ? t : e instanceof Error ? e.message : String(e);
185
+ }, W = async (e, t) => {
186
+ let n = await j(e, t, "update");
187
+ if (n.status !== "failed") throw new i({
188
+ id: t,
189
+ status: String(n.status)
190
+ });
191
+ return await e.update("cms_releases", t, {
192
+ status: "draft",
193
+ failure: null,
194
+ claimToken: null,
195
+ scheduledAt: null
196
+ }) ?? n;
197
+ }, G = async (e, t, n, r = /* @__PURE__ */ new Date(), a = {}) => {
198
+ let o = await M(e, n);
199
+ if (o.status !== "published") throw new i({
200
+ id: n,
201
+ status: String(o.status)
202
+ });
203
+ return l(e, async () => {
204
+ let i = await e.insert(T, {
205
+ name: `Rollback of ${String(o.name)}`,
206
+ site: o.site,
207
+ environment: o.environment,
208
+ status: "draft",
209
+ rollbackOf: n,
210
+ ...o.tenantId !== void 0 && o.tenantId !== null ? { tenantId: o.tenantId } : {}
211
+ }), s = String(i.id), c = 0;
212
+ for (let t of await L(e, n)) {
213
+ let n = t.previousRevisionId;
214
+ await e.insert(E, {
215
+ releaseId: s,
216
+ contentType: t.contentType,
217
+ variantId: t.variantId,
218
+ locale: t.locale,
219
+ action: n == null ? "unpublish" : "publish",
220
+ revisionId: n ?? null,
221
+ position: c++,
222
+ ...t.tenantId !== void 0 && t.tenantId !== null ? { tenantId: t.tenantId } : {}
223
+ });
224
+ }
225
+ return B(e, t, s, r, a);
226
+ });
227
+ }, K = [
228
+ n,
229
+ i,
230
+ a,
231
+ r
232
+ ], q = [
233
+ ...K,
234
+ t,
235
+ e
236
+ ], J = (...e) => o(() => P(...e)), Y = (...e) => o(() => F(...e), n, i), X = async (e, t, n, r) => {
237
+ let [i] = await A(e, E, p(m("releaseId", t), m("variantId", n)));
238
+ return i !== void 0 && (await e.update(E, String(i.id), { inherited: r }), !0);
239
+ }, Z = (...e) => o(() => X(...e)), Q = (...e) => o(() => L(...e)), $ = (...e) => o(() => I(...e)), ee = (...e) => o(() => R(...e)), te = (...e) => o(() => B(...e), ...q), ne = (...e) => o(() => V(...e), ...K), re = (...e) => o(() => H(...e)), ie = (...e) => o(() => G(...e), ...q), ae = (...e) => o(() => W(...e), ...K);
240
+ //#endregion
241
+ export { T as CMS_RELEASES_TABLE, E as CMS_RELEASE_ITEMS_TABLE, D as RELEASE_STATUSES, F as addToRelease, Y as addToReleaseEffect, k as cmsReleaseItemsTable, O as cmsReleasesTable, P as createRelease, J as createReleaseEffect, U as describeFailure, L as listReleaseItems, Q as listReleaseItemsEffect, R as listReleases, ee as listReleasesEffect, X as pinReleaseInheritance, Z as pinReleaseInheritanceEffect, H as publishDueReleases, re as publishDueReleasesEffect, B as publishRelease, te as publishReleaseEffect, I as releaseStatusOf, $ as releaseStatusOfEffect, W as retryRelease, ae as retryReleaseEffect, G as rollbackRelease, ie as rollbackReleaseEffect, V as scheduleRelease, ne as scheduleReleaseEffect };
@@ -0,0 +1,43 @@
1
+ import { dataStoreApiKeyStore as e, lockApiKeyById as t, sha256Hex as n } from "@voltro/runtime";
2
+ //#region src/renderReadAuthority.ts
3
+ var r = (e) => {
4
+ if (typeof e != "object" || !e || Array.isArray(e)) return null;
5
+ let t = e;
6
+ return Object.keys(t).length !== 3 || Object.keys(t).some((e) => ![
7
+ "kind",
8
+ "id",
9
+ "scope"
10
+ ].includes(e)) || t.kind !== "apiKey" || typeof t.id != "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(t.id) || typeof t.scope != "string" || !/^[A-Za-z][A-Za-z0-9:_.-]{0,127}$/.test(t.scope) ? null : {
11
+ kind: "apiKey",
12
+ id: t.id,
13
+ scope: t.scope
14
+ };
15
+ }, i = (e, t, n, r) => e === null || e.id !== n || e.tenantId !== t.tenantId || e.revokedAt !== null || e.onBehalfOf !== null && e.onBehalfOf !== void 0 || !Array.isArray(e.scopes) || !e.scopes.every((e) => typeof e == "string") || e.metadata === null || typeof e.metadata != "object" || Array.isArray(e.metadata) || e.metadata.site !== t.site || e.metadata.environment !== t.environment || e.expiresAt !== null && (!Number.isSafeInteger(e.expiresAt) || e.expiresAt <= r) ? null : {
16
+ expiresAt: e.expiresAt,
17
+ scopes: [...e.scopes]
18
+ }, a = async (t, n, r, a) => i(await e(t).findById(r), n, r, a), o = async (e, t, n, r) => {
19
+ let i = await a(e, t, n.id, r);
20
+ return i !== null && i.scopes.includes(n.scope) ? { expiresAt: i.expiresAt } : null;
21
+ }, s = async (t, r, i, o) => {
22
+ if (typeof i != "string" || i.length === 0 || i.length > 512 || !Number.isSafeInteger(o) || !Number.isFinite(new Date(o).getTime())) return null;
23
+ let s = await e(t).findByHash(n(i));
24
+ if (s === null) return null;
25
+ let c = await a(t, r, s.id, o);
26
+ return c === null ? null : {
27
+ id: s.id,
28
+ ...c
29
+ };
30
+ }, c = async (r, a, o, s) => {
31
+ if (typeof o != "string" || o.length === 0 || o.length > 512 || !Number.isSafeInteger(s) || !Number.isFinite(new Date(s).getTime())) return null;
32
+ let c = n(o), l = await e(r).findByHash(c);
33
+ if (l === null) return null;
34
+ let u = await t(r, l.id, a.tenantId);
35
+ if (u === null || u.hashedKey !== c) return null;
36
+ let d = i(u, a, l.id, s);
37
+ return d === null ? null : {
38
+ id: u.id,
39
+ ...d
40
+ };
41
+ };
42
+ //#endregion
43
+ export { r as copyRenderReadAuthority, c as lockRenderReadCredential, o as readRenderReadAuthority, s as readRenderReadCredential, a as readRenderReadOrganization };
@@ -0,0 +1,137 @@
1
+ import { copyRenderReadAuthority as e, readRenderReadAuthority as t } from "./renderReadAuthority.js";
2
+ import { Schema as n } from "effect";
3
+ import { and as r, eq as i, id as a, json as o, table as s, text as c, timestamp as l } from "@voltro/database";
4
+ import { tenant as u } from "@voltro/plugin-multitenancy/mixin";
5
+ import { createHmac as d, timingSafeEqual as f } from "node:crypto";
6
+ import { canonicalJson as p, generateApiKeyToken as m } from "@voltro/runtime";
7
+ //#region src/renderReadGrant.ts
8
+ var h = class extends n.TaggedError()("RenderReadGrantRejected", { reason: n.Literals([
9
+ "binding",
10
+ "key",
11
+ "expiry",
12
+ "token",
13
+ "revoked",
14
+ "expired",
15
+ "authority"
16
+ ]) }) {}, g = "_voltro_cms_render_read_grants", _ = s(g, {
17
+ id: a({ prefix: "crrg" }),
18
+ site: c().maxLength(64),
19
+ environment: c().maxLength(64),
20
+ binding: o(),
21
+ keyId: c().maxLength(64),
22
+ verifier: c().maxLength(64),
23
+ issuedAt: l(),
24
+ expiresAt: l(),
25
+ revokedAt: l().nullable()
26
+ }).with(u()), v = "crread1", y = [
27
+ "tenantId",
28
+ "site",
29
+ "environment",
30
+ "consumerId",
31
+ "snapshotId",
32
+ "snapshotDigest",
33
+ "releaseId",
34
+ "buildId",
35
+ "policyDigest",
36
+ "projectionDigest"
37
+ ], b = [
38
+ "tenantId",
39
+ "site",
40
+ "environment",
41
+ "consumerId",
42
+ "snapshotId",
43
+ "buildId"
44
+ ], x = [
45
+ "snapshotDigest",
46
+ "policyDigest",
47
+ "projectionDigest"
48
+ ], S = (e) => {
49
+ throw new h({ reason: e });
50
+ }, C = (e) => typeof e == "string" && e.length > 0 && e.length <= 64 && /^[a-zA-Z0-9_-]+$/.test(e), w = (e) => typeof e == "string" && /^[0-9a-f]{64}$/.test(e), T = (e) => e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : NaN, E = (e) => Number.isSafeInteger(e) && Number.isFinite(new Date(e).getTime()), D = (e) => {
51
+ if (typeof e != "object" || !e || Array.isArray(e)) return S("binding");
52
+ let t = e;
53
+ return Object.keys(t).length !== y.length || Object.keys(t).some((e) => !y.includes(e)) || !b.every((e) => C(t[e])) || !x.every((e) => w(t[e])) || !(t.releaseId === null || C(t.releaseId)) ? S("binding") : Object.fromEntries(y.map((e) => [e, t[e]]));
54
+ }, O = (e) => !C(e.id) || !(e.material instanceof Uint8Array) || e.material.length < 32 ? S("key") : e, k = (e) => [
55
+ e.tenantId,
56
+ e.site,
57
+ e.environment
58
+ ].every(C) ? r(i("tenantId", e.tenantId), i("site", e.site), i("environment", e.environment)) : S("binding"), A = (e, t, n) => d("sha256", e.material).update(p({
59
+ purpose: "voltro.cms.render-read/v1",
60
+ nonce: t,
61
+ id: n.id,
62
+ keyId: n.keyId,
63
+ binding: n.binding,
64
+ issuedAt: T(n.issuedAt),
65
+ expiresAt: T(n.expiresAt)
66
+ })).digest("hex"), j = async (n, r, i) => {
67
+ let a = D(r), o = O({
68
+ id: i.key.id,
69
+ material: new Uint8Array(i.key.material)
70
+ }), s = i.now ?? Date.now(), c = i.expiresAt, l = i.maxExpiresAt;
71
+ if (![
72
+ s,
73
+ c,
74
+ l
75
+ ].every(E) || c <= s || c > l) return S("expiry");
76
+ let u = i.authority === void 0 ? void 0 : e(i.authority);
77
+ if (u === null) return S("authority");
78
+ if (u !== void 0) {
79
+ let e = await t(n, a, u, s);
80
+ if (e === null || e.expiresAt !== null && c > e.expiresAt) return S("authority");
81
+ }
82
+ let d = m(""), f = await n.insert(g, {
83
+ tenantId: a.tenantId,
84
+ site: a.site,
85
+ environment: a.environment,
86
+ binding: u === void 0 ? a : {
87
+ ...a,
88
+ authority: u
89
+ },
90
+ keyId: o.id,
91
+ verifier: "",
92
+ issuedAt: new Date(s),
93
+ expiresAt: new Date(c),
94
+ revokedAt: null
95
+ });
96
+ return C(f.id) ? (await n.update(g, f.id, { verifier: A(o, d, f) }), {
97
+ id: f.id,
98
+ token: `${v}.${f.id}.${d}`,
99
+ expiresAt: c
100
+ }) : S("token");
101
+ }, M = async (n, a, o, s, c) => {
102
+ let l = D(o), u = s.now ?? Date.now();
103
+ if (!E(u)) return S("expiry");
104
+ if (s.keys.length === 0 || new Set(s.keys.map((e) => e.id)).size !== s.keys.length) return S("key");
105
+ for (let e of s.keys) O(e);
106
+ if (typeof a != "string" || a.length > 128) return S("token");
107
+ let d = a.split(".");
108
+ if (d.length !== 3 || d[0] !== v || !C(d[1]) || !/^[A-Za-z0-9_-]{40}$/.test(d[2])) return S("token");
109
+ let [m] = await n.query({
110
+ table: g,
111
+ predicate: r(k(l), i("id", d[1])),
112
+ order: [],
113
+ take: 1,
114
+ skip: void 0,
115
+ projection: void 0
116
+ });
117
+ if (m === void 0 || !w(m.verifier)) return S("token");
118
+ let h = s.keys.find((e) => e.id === m.keyId);
119
+ if (h === void 0) return S("token");
120
+ let _ = Buffer.from(A(h, d[2], m), "hex"), y = Buffer.from(m.verifier, "hex");
121
+ if (!f(_, y) || m.binding === null || typeof m.binding != "object" || Array.isArray(m.binding)) return S("token");
122
+ let b = m.binding, { authority: x, ...j } = b;
123
+ if (p(j) !== p(l)) return S("token");
124
+ if (m.revokedAt !== null) return S("revoked");
125
+ let M = T(m.issuedAt), N = T(m.expiresAt);
126
+ if (!E(M) || !E(N) || M > u || N <= M) return S("token");
127
+ if (c === void 0 && N <= u) return S("expired");
128
+ if (Object.hasOwn(b, "authority")) {
129
+ let r = e(x);
130
+ if (r === null || await t(n, l, r, u) === null || c !== void 0 && p(r) !== p(c)) return S("authority");
131
+ } else if (c !== void 0) return S("authority");
132
+ }, N = (e, t, n, r) => M(e, t, n, r), P = (t, n, r, i, a) => {
133
+ let o = e(i);
134
+ return o === null ? S("authority") : M(t, n, r, a, o);
135
+ };
136
+ //#endregion
137
+ export { g as RENDER_READ_GRANTS_TABLE, h as RenderReadGrantRejected, j as issueRenderReadGrant, _ as renderReadGrantsTable, N as verifyRenderReadGrant, P as verifyRenderReadRenewal };
package/dist/rest.js ADDED
@@ -0,0 +1,52 @@
1
+ //#region src/rest.ts
2
+ var e = (e) => {
3
+ let t = e.authorization;
4
+ return t && t.toLowerCase().startsWith("bearer ") ? t.slice(7).trim() : e["x-api-key"];
5
+ }, t = async (t, n) => {
6
+ if (t.method.toUpperCase() !== "GET") return {
7
+ status: 405,
8
+ body: { error: "method_not_allowed" }
9
+ };
10
+ if (!t.path.startsWith("/v1/cms/")) return {
11
+ status: 404,
12
+ body: { error: "not_found" }
13
+ };
14
+ let r = e(t.headers), i = r ? n.apiKeys.find((e) => e.key === r) : void 0;
15
+ if (!i) return {
16
+ status: 401,
17
+ body: { error: "unauthorized" }
18
+ };
19
+ let a = t.path.slice(8).split("/").filter((e) => e.length > 0), o = a[0];
20
+ if (!o || !n.types.some((e) => e.name === o)) return {
21
+ status: 404,
22
+ body: { error: "unknown_content_type" }
23
+ };
24
+ if (!(i.types === void 0 || i.types.includes("*") || i.types.includes(o))) return {
25
+ status: 403,
26
+ body: {
27
+ error: "forbidden",
28
+ type: o
29
+ }
30
+ };
31
+ if (a.length >= 2) {
32
+ let e = a.slice(1).join("/"), t = await n.cms.contentType(o).where("slug", "=", e).one();
33
+ return t ? {
34
+ status: 200,
35
+ body: t
36
+ } : {
37
+ status: 404,
38
+ body: {
39
+ error: "not_found",
40
+ type: o,
41
+ slug: e
42
+ }
43
+ };
44
+ }
45
+ let s = n.defaultLimit ?? 20, c = n.maxLimit ?? 100, l = Number(t.query?.limit), u = Number.isFinite(l) && l > 0 ? Math.min(l, c) : s;
46
+ return {
47
+ status: 200,
48
+ body: await n.cms.contentType(o).limit(u).all()
49
+ };
50
+ };
51
+ //#endregion
52
+ export { t as handleCmsRest };