@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
package/dist/review.js ADDED
@@ -0,0 +1,160 @@
1
+ import { ContentNotFound as e, ReviewRequired as t, ReviewStepRefused as n, RevisionMismatch as r } from "./errors.js";
2
+ import { asTyped as i } from "./effectForm.js";
3
+ import { approvedByWorkflow as a } from "./workflow.js";
4
+ import { workspaceReviewTypes as o } from "./team.js";
5
+ import { and as s, eq as c, id as l, integer as u, table as d, text as f } from "@voltro/database";
6
+ import { tenant as p } from "@voltro/plugin-multitenancy/mixin";
7
+ //#region src/review.ts
8
+ var m = "cms_reviews", h = [
9
+ "requested",
10
+ "approved",
11
+ "changesRequested"
12
+ ], g = d(m, {
13
+ id: l({ prefix: "crvw" }),
14
+ contentType: f().maxLength(64),
15
+ variantId: f().maxLength(64),
16
+ documentId: f().maxLength(64),
17
+ site: f().maxLength(64),
18
+ environment: f().maxLength(64),
19
+ locale: f().maxLength(64),
20
+ revisionId: f(),
21
+ action: f().oneOf(h),
22
+ sequence: u().default(0),
23
+ actorId: f(),
24
+ note: f().nullable()
25
+ }).with(p()).index("cms_reviews_by_variant", ["contentType", "variantId"]), _ = (e) => [
26
+ c("site", e.site),
27
+ c("environment", e.environment),
28
+ c("locale", e.locale)
29
+ ], v = async (t, n, r, i, a = !1) => {
30
+ let [o] = await t.query({
31
+ table: `${n.name}_drafts`,
32
+ predicate: s(c("id", r), ..._(i)),
33
+ order: [],
34
+ take: 1,
35
+ skip: void 0,
36
+ projection: void 0,
37
+ ...a ? { lock: "update" } : {}
38
+ });
39
+ if (o === void 0) throw new e({
40
+ contentType: n.name,
41
+ id: r,
42
+ stage: "draft"
43
+ });
44
+ return o;
45
+ }, y = (e, t, n, r) => e.query({
46
+ table: m,
47
+ predicate: s(c("contentType", t.name), c("variantId", n), ..._(r)),
48
+ order: [{
49
+ column: "sequence",
50
+ direction: "desc"
51
+ }, {
52
+ column: "createdAt",
53
+ direction: "desc"
54
+ }],
55
+ take: void 0,
56
+ skip: void 0,
57
+ projection: void 0
58
+ }), b = async (e, t, n, r, i, a, o) => {
59
+ let [s] = await y(e, t, String(n.id), r), c = Number(s?.sequence ?? 0) + 1;
60
+ return e.insert(m, {
61
+ contentType: t.name,
62
+ variantId: n.id,
63
+ documentId: n.documentId,
64
+ site: r.site,
65
+ environment: r.environment,
66
+ locale: r.locale,
67
+ revisionId: n.revisionId,
68
+ action: i,
69
+ sequence: c,
70
+ actorId: a,
71
+ note: o ?? null
72
+ });
73
+ }, x = (e, t, r) => {
74
+ let [i, a] = e;
75
+ if (i !== void 0 && a !== void 0 && Number(i.sequence ?? 0) === 0 && new Date(i.createdAt).getTime() === new Date(a.createdAt).getTime()) throw new n({
76
+ contentType: t.name,
77
+ id: r,
78
+ reason: "ambiguousOrder"
79
+ });
80
+ return i;
81
+ }, S = async (e, t, n, r, i) => b(e, t, await v(e, t, n, r, !0), r, "requested", i.actorId, i.note), C = async (e, t, i, a, o) => {
82
+ let s = await v(e, t, i, a, !0);
83
+ if (s.revisionId !== o) throw new r({
84
+ contentType: t.name,
85
+ id: i,
86
+ expected: o,
87
+ actual: String(s.revisionId)
88
+ });
89
+ let c = x(await y(e, t, i, a), t, i);
90
+ if (c === void 0 || c.action !== "requested" || c.revisionId !== o) throw new n({
91
+ contentType: t.name,
92
+ id: i,
93
+ reason: "notInReview"
94
+ });
95
+ return {
96
+ draft: s,
97
+ request: c
98
+ };
99
+ }, w = async (e, t, r, i, a) => {
100
+ let { draft: o, request: s } = await C(e, t, r, i, a.revisionId);
101
+ if (a.allowSelfApproval !== !0 && s.actorId === a.actorId) throw new n({
102
+ contentType: t.name,
103
+ id: r,
104
+ reason: "selfApproval"
105
+ });
106
+ return b(e, t, o, i, "approved", a.actorId, a.note);
107
+ }, T = async (e, t, n, r, i) => {
108
+ let { draft: a } = await C(e, t, n, r, i.revisionId);
109
+ return b(e, t, a, r, "changesRequested", i.actorId, i.note);
110
+ }, E = async (e, t, n, r) => {
111
+ let i = await v(e, t, n, r), a = x(await y(e, t, n, r), t, n);
112
+ if (a === void 0) return {
113
+ state: "none",
114
+ revisionId: null,
115
+ stale: !1,
116
+ lastStep: null
117
+ };
118
+ let o = a.revisionId !== i.revisionId;
119
+ return {
120
+ state: o ? "none" : a.action === "requested" ? "inReview" : a.action === "approved" ? "approved" : "changesRequested",
121
+ revisionId: a.revisionId,
122
+ stale: o,
123
+ lastStep: a
124
+ };
125
+ }, D = async (e, t, n) => {
126
+ let r = t.review?.required;
127
+ if (r !== "workspace") return r === !0;
128
+ let [i] = n === void 0 ? [] : await e.query({
129
+ table: `${t.name}_drafts`,
130
+ predicate: c("id", n),
131
+ order: [],
132
+ take: 1,
133
+ skip: void 0,
134
+ projection: void 0
135
+ }), a = i?.tenantId;
136
+ return typeof a == "string" && (await o(e, a)).includes(t.name);
137
+ }, O = async (e, n, r, i, o) => {
138
+ if (await D(e, n, r)) {
139
+ if (n.review?.workflow !== void 0) {
140
+ if (!await a(e, n, r, o)) throw new t({
141
+ contentType: n.name,
142
+ id: r,
143
+ revisionId: o
144
+ });
145
+ } else if ((await e.query({
146
+ table: "cms_reviews",
147
+ predicate: s(c("contentType", n.name), c("variantId", r), c("revisionId", o), c("action", "approved"), ..._(i)),
148
+ order: [],
149
+ take: 1,
150
+ skip: void 0,
151
+ projection: void 0
152
+ })).length === 0) throw new t({
153
+ contentType: n.name,
154
+ id: r,
155
+ revisionId: o
156
+ });
157
+ }
158
+ }, k = (...e) => i(() => y(...e)), A = (...t) => i(() => S(...t), e), j = (...t) => i(() => w(...t), e, r, n), M = (...t) => i(() => T(...t), e, r, n), N = (...t) => i(() => E(...t), e, n), P = (...e) => i(() => D(...e)), F = (...e) => i(() => O(...e), t);
159
+ //#endregion
160
+ export { m as CMS_REVIEWS_TABLE, h as REVIEW_ACTIONS, w as approveReview, j as approveReviewEffect, O as assertApproved, F as assertApprovedEffect, g as cmsReviewsTable, T as requestChanges, M as requestChangesEffect, S as requestReview, A as requestReviewEffect, y as reviewLog, k as reviewLogEffect, D as reviewRequiredFor, P as reviewRequiredForEffect, E as reviewStatus, N as reviewStatusEffect };
@@ -0,0 +1,521 @@
1
+ //#region src/richDocument.ts
2
+ var e = 3, t = (e, t) => t === 0 ? e.ordered : (e.sublists?.[t - 1] ?? (e.ordered ? "ordered" : "unordered")) === "ordered", n = /* @__PURE__ */ new Set([
3
+ "bold",
4
+ "italic",
5
+ "underline"
6
+ ]), r = /* @__PURE__ */ new Set([
7
+ "paragraph",
8
+ "heading",
9
+ "list",
10
+ "table",
11
+ "image",
12
+ "file",
13
+ "component"
14
+ ]), i = (e) => typeof e == "object" && !!e && !Array.isArray(e), a = () => `rb_${crypto.randomUUID().replace(/-/g, "")}`, o = () => ({
15
+ type: "doc",
16
+ blocks: []
17
+ }), s = (e, t) => {
18
+ let n = t === void 0 ? {} : { profile: t.id };
19
+ return typeof e == "string" ? {
20
+ type: "doc",
21
+ blocks: e.split(/\n{2,}/).map((e) => e.trim()).filter((e) => e !== "").map((e) => ({
22
+ id: a(),
23
+ type: "paragraph",
24
+ content: [{
25
+ type: "text",
26
+ text: e
27
+ }]
28
+ })),
29
+ ...n
30
+ } : !i(e) || e.type !== "doc" || !Array.isArray(e.blocks) ? e : {
31
+ ...e,
32
+ blocks: e.blocks.map((e) => i(e) && (typeof e.id != "string" || e.id === "") ? {
33
+ ...e,
34
+ id: a()
35
+ } : e),
36
+ ...n
37
+ };
38
+ }, c = /^[^\s@<>()[\],;:"]+@[^\s@<>()[\],;:"]+\.[^\s@<>()[\],;:"]{2,}$/, l = /^\+?[0-9][0-9 ()/.-]*[0-9]$/, u = (e, t) => {
39
+ if (e === "email") return t.length <= 254 && c.test(t) ? null : "not an e-mail address";
40
+ let n = t.replace(/[^0-9]/g, "").length;
41
+ return l.test(t) && n >= 5 && n <= 15 ? null : "not a phone number (5 to 15 digits, an optional leading +)";
42
+ }, d = (e, t) => e === "email" ? `mailto:${t}` : `tel:${t.replace(/[^0-9+]/g, "")}`, f = (e, t, n) => {
43
+ t !== void 0 && (!i(t) || t.kind !== "insert" && t.kind !== "delete" || typeof t.id != "string" || t.id === "" || typeof t.by != "string" || t.by === "" || typeof t.at != "string" || Number.isNaN(Date.parse(t.at))) && n.push({
44
+ path: `${e}.change`,
45
+ rule: "type",
46
+ message: "a suggested change has an id, a kind (insert or delete), who made it and when"
47
+ });
48
+ }, p = (e, t, n, r) => {
49
+ if (t === void 0) return;
50
+ let i = n.profile?.styles;
51
+ if (i === void 0) return void r.push({
52
+ path: `${e}.style`,
53
+ rule: "profile",
54
+ message: "this field has no styles"
55
+ });
56
+ (typeof t != "string" || !(t in i.tokens)) && r.push({
57
+ path: `${e}.style`,
58
+ rule: "profile",
59
+ message: `a style is one of: ${Object.keys(i.tokens).join(", ")}`
60
+ });
61
+ }, m = (e, t, r, a) => {
62
+ if (!Array.isArray(t)) {
63
+ a.push({
64
+ path: e,
65
+ rule: "type",
66
+ message: "expected a list of inline nodes"
67
+ });
68
+ return;
69
+ }
70
+ let o = r.profile;
71
+ t.forEach((t, s) => {
72
+ let c = `${e}[${s}]`;
73
+ if (!i(t)) return void a.push({
74
+ path: c,
75
+ rule: "type",
76
+ message: "expected an inline node"
77
+ });
78
+ if (f(c, t.change, a), t.type === "text") {
79
+ typeof t.text != "string" && a.push({
80
+ path: c,
81
+ rule: "type",
82
+ message: "text must be a string"
83
+ });
84
+ let e = t.marks;
85
+ return e !== void 0 && (!Array.isArray(e) || e.some((e) => !n.has(String(e)))) ? a.push({
86
+ path: c,
87
+ rule: "unknown",
88
+ message: `marks must be ${[...n].join(" / ")}`
89
+ }) : o !== void 0 && Array.isArray(e) && e.some((e) => !o.marks.includes(e)) && a.push({
90
+ path: `${c}.marks`,
91
+ rule: "profile",
92
+ message: `this field allows the marks: ${o.marks.join(", ") || "none"}`
93
+ }), p(c, t.style, r, a);
94
+ }
95
+ if (t.type === "link") {
96
+ if (r.links === void 0) return void a.push({
97
+ path: c,
98
+ rule: "richText",
99
+ message: "links are not allowed in this field"
100
+ });
101
+ (typeof t.target != "string" || t.target === "") && a.push({
102
+ path: c,
103
+ rule: "required",
104
+ message: "a link needs a target document"
105
+ }), (typeof t.text != "string" || t.text === "") && a.push({
106
+ path: c,
107
+ rule: "required",
108
+ message: "a link needs text"
109
+ });
110
+ } else if (t.type === "contact") {
111
+ (typeof t.text != "string" || t.text === "") && a.push({
112
+ path: c,
113
+ rule: "required",
114
+ message: "a contact needs text"
115
+ });
116
+ let e = t.contact;
117
+ if (!i(e)) return void a.push({
118
+ path: `${c}.contact`,
119
+ rule: "type",
120
+ message: "expected a contact point or an address"
121
+ });
122
+ if ("target" in e) {
123
+ if (o?.contactPoints === void 0) return void a.push({
124
+ path: c,
125
+ rule: "profile",
126
+ message: "this field names no contact points"
127
+ });
128
+ (typeof e.target != "string" || e.target === "") && a.push({
129
+ path: `${c}.contact.target`,
130
+ rule: "required",
131
+ message: "a contact needs its contact point"
132
+ });
133
+ return;
134
+ }
135
+ if (o?.contactLiterals !== !0) return void a.push({
136
+ path: c,
137
+ rule: "profile",
138
+ message: "this field takes no one-off addresses or numbers"
139
+ });
140
+ let n = e.channel;
141
+ if (n !== "email" && n !== "phone") return void a.push({
142
+ path: `${c}.contact.channel`,
143
+ rule: "literal",
144
+ message: "a contact is an email or a phone"
145
+ });
146
+ let r = typeof e.value == "string" ? u(n, e.value) : "missing";
147
+ r !== null && a.push({
148
+ path: `${c}.contact.value`,
149
+ rule: "contact",
150
+ message: r
151
+ });
152
+ } else a.push({
153
+ path: c,
154
+ rule: "unknown",
155
+ message: `unknown inline node '${String(t.type)}'`
156
+ });
157
+ });
158
+ }, h = (e, t, n) => {
159
+ let a = [];
160
+ if (!i(t) || t.type !== "doc" || !Array.isArray(t.blocks)) return [{
161
+ path: e,
162
+ rule: "type",
163
+ message: "expected a rich document ({ type: 'doc', blocks })"
164
+ }];
165
+ let o = n.profile, s = /* @__PURE__ */ new Set();
166
+ return t.blocks.forEach((t, c) => {
167
+ let l = `${e}.blocks[${c}]`;
168
+ if (!i(t)) return void a.push({
169
+ path: l,
170
+ rule: "type",
171
+ message: "expected a block"
172
+ });
173
+ let u = t.id;
174
+ typeof u != "string" || u === "" ? a.push({
175
+ path: `${l}.id`,
176
+ rule: "required",
177
+ message: "every block needs an id"
178
+ }) : s.has(u) ? a.push({
179
+ path: `${l}.id`,
180
+ rule: "unique",
181
+ message: `block id '${u}' is used twice`
182
+ }) : s.add(u), f(l, t.change, a);
183
+ let d = t.type;
184
+ if (o !== void 0 && r.has(String(d)) && !o.blocks.includes(d)) a.push({
185
+ path: l,
186
+ rule: "profile",
187
+ message: `this field allows the blocks: ${o.blocks.join(", ")}`
188
+ });
189
+ else switch ((d === "paragraph" || d === "heading" || d === "list") && p(l, t.style, n, a), d) {
190
+ case "paragraph": return m(`${l}.content`, t.content, n, a);
191
+ case "heading": return t.level !== 2 && t.level !== 3 ? a.push({
192
+ path: `${l}.level`,
193
+ rule: "literal",
194
+ message: "a heading is level 2 or 3"
195
+ }) : o !== void 0 && !o.headings.includes(t.level) && a.push({
196
+ path: `${l}.level`,
197
+ rule: "profile",
198
+ message: `this field allows heading levels: ${o.headings.join(", ")}`
199
+ }), m(`${l}.content`, t.content, n, a);
200
+ case "list": {
201
+ let e = t.items;
202
+ if (typeof t.ordered != "boolean" && a.push({
203
+ path: `${l}.ordered`,
204
+ rule: "type",
205
+ message: "ordered must be true or false"
206
+ }), !Array.isArray(e)) return void a.push({
207
+ path: `${l}.items`,
208
+ rule: "type",
209
+ message: "expected list items"
210
+ });
211
+ let r = t.levels;
212
+ r !== void 0 && (!Array.isArray(r) || r.length !== e.length ? a.push({
213
+ path: `${l}.levels`,
214
+ rule: "type",
215
+ message: "one level per item"
216
+ }) : r.forEach((e, t) => {
217
+ let n = t === 0 ? -1 : Number(r[t - 1]);
218
+ (!Number.isInteger(e) || e < 0 || e > 3 || e > n + 1) && a.push({
219
+ path: `${l}.levels[${t}]`,
220
+ rule: "level",
221
+ message: "an item sits at most 3 deep, and at most one deeper than the item before it"
222
+ });
223
+ }));
224
+ let i = t.sublists;
225
+ return i !== void 0 && (!Array.isArray(i) || i.length > 3 || i.some((e) => e !== "ordered" && e !== "unordered")) && a.push({
226
+ path: `${l}.sublists`,
227
+ rule: "type",
228
+ message: "at most 3 kinds of nested lists, each ordered or unordered"
229
+ }), e.forEach((e, t) => m(`${l}.items[${t}]`, e, n, a));
230
+ }
231
+ case "table": {
232
+ let e = t.rows;
233
+ return typeof t.header != "boolean" && a.push({
234
+ path: `${l}.header`,
235
+ rule: "type",
236
+ message: "header must be true or false"
237
+ }), Array.isArray(e) ? e.forEach((e, t) => {
238
+ if (!Array.isArray(e)) return void a.push({
239
+ path: `${l}.rows[${t}]`,
240
+ rule: "type",
241
+ message: "expected a row of cells"
242
+ });
243
+ e.forEach((e, r) => m(`${l}.rows[${t}][${r}]`, e, n, a));
244
+ }) : void a.push({
245
+ path: `${l}.rows`,
246
+ rule: "type",
247
+ message: "expected table rows"
248
+ });
249
+ }
250
+ case "image":
251
+ if (n.images === void 0) return void a.push({
252
+ path: l,
253
+ rule: "richText",
254
+ message: "images are not allowed in this field"
255
+ });
256
+ (typeof t.asset != "string" || t.asset === "") && a.push({
257
+ path: `${l}.asset`,
258
+ rule: "required",
259
+ message: "an image needs an asset"
260
+ }), t.caption !== void 0 && typeof t.caption != "string" && a.push({
261
+ path: `${l}.caption`,
262
+ rule: "type",
263
+ message: "a caption is text"
264
+ });
265
+ return;
266
+ case "file":
267
+ if (n.files === void 0) return void a.push({
268
+ path: l,
269
+ rule: "richText",
270
+ message: "downloads are not allowed in this field"
271
+ });
272
+ (typeof t.asset != "string" || t.asset === "") && a.push({
273
+ path: `${l}.asset`,
274
+ rule: "required",
275
+ message: "a download needs a file"
276
+ }), (typeof t.label != "string" || t.label.trim() === "") && a.push({
277
+ path: `${l}.label`,
278
+ rule: "required",
279
+ message: "a download needs the text its link shows"
280
+ });
281
+ return;
282
+ case "component":
283
+ if (o === void 0 || o.components.length === 0) return void a.push({
284
+ path: l,
285
+ rule: "profile",
286
+ message: "components are not allowed in this field"
287
+ });
288
+ if (!o.components.some((e) => e.id === t.componentId)) {
289
+ a.push({
290
+ path: `${l}.componentId`,
291
+ rule: "unknown",
292
+ message: `'${String(t.componentId)}' is not a component this field allows`
293
+ });
294
+ return;
295
+ }
296
+ i(t.props) || a.push({
297
+ path: `${l}.props`,
298
+ rule: "type",
299
+ message: "expected an object"
300
+ });
301
+ return;
302
+ default: a.push({
303
+ path: l,
304
+ rule: "unknown",
305
+ message: `unknown block '${String(t.type)}'`
306
+ });
307
+ }
308
+ }), a;
309
+ }, g = (e, t, n) => {
310
+ let r = [], i = n.profile?.contactPoints, a = (e, t) => {
311
+ t.forEach((t, a) => {
312
+ t.type === "link" && n.links !== void 0 && t.target !== "" && r.push({
313
+ path: [...e, a],
314
+ targetType: n.links,
315
+ targetDocumentId: t.target
316
+ }), t.type === "contact" && i !== void 0 && "target" in t.contact && t.contact.target !== "" && r.push({
317
+ path: [...e, a],
318
+ targetType: i,
319
+ targetDocumentId: t.contact.target
320
+ });
321
+ });
322
+ };
323
+ return t.blocks.forEach((t, i) => {
324
+ let o = [
325
+ ...e,
326
+ "blocks",
327
+ i
328
+ ];
329
+ switch (t.type) {
330
+ case "paragraph":
331
+ case "heading": return a([...o, "content"], t.content);
332
+ case "list": return t.items.forEach((e, t) => a([
333
+ ...o,
334
+ "items",
335
+ t
336
+ ], e));
337
+ case "table": return t.rows.forEach((e, t) => e.forEach((e, n) => a([
338
+ ...o,
339
+ "rows",
340
+ t,
341
+ n
342
+ ], e)));
343
+ case "image":
344
+ n.images !== void 0 && t.asset !== "" && r.push({
345
+ path: o,
346
+ targetType: n.images,
347
+ targetDocumentId: t.asset
348
+ });
349
+ return;
350
+ case "file":
351
+ n.files !== void 0 && t.asset !== "" && r.push({
352
+ path: o,
353
+ targetType: n.files,
354
+ targetDocumentId: t.asset
355
+ });
356
+ return;
357
+ case "component": return;
358
+ }
359
+ }), r;
360
+ }, _ = (e, t, n) => g(e, t, n).map((n) => {
361
+ let r = t;
362
+ for (let t of n.path.slice(e.length)) {
363
+ if (typeof r != "object" || !r || !Object.hasOwn(r, t)) throw Error("Rich document reference unavailable");
364
+ r = r[t];
365
+ }
366
+ if (typeof r != "object" || !r) throw Error("Rich document reference unavailable");
367
+ let i = r.type, a = i === "contact" ? ["contact", "target"] : i === "link" ? ["target"] : i === "image" || i === "file" ? ["asset"] : null;
368
+ if (a === null) throw Error("Rich document reference unavailable");
369
+ return {
370
+ fieldPath: [...n.path, ...a],
371
+ targetType: n.targetType,
372
+ targetDocumentId: n.targetDocumentId
373
+ };
374
+ }), v = (e, t, n) => g([], t, n).map((t) => ({
375
+ ...t,
376
+ path: e + t.path.map((e) => typeof e == "number" ? `[${e}]` : `.${e}`).join("")
377
+ })), y = /[*_+[\]()\\{}|]/, b = (e, t = []) => {
378
+ let n = [], r = "", i = [], a, o = () => {
379
+ if (r === "") return;
380
+ let e = n[n.length - 1];
381
+ e?.type === "text" && (e.marks ?? []).join() === i.join() && e.style === a && e.type === "text" ? n[n.length - 1] = {
382
+ ...e,
383
+ text: e.text + r
384
+ } : n.push({
385
+ type: "text",
386
+ text: r,
387
+ ...i.length > 0 ? { marks: [...i] } : {},
388
+ ...a === void 0 ? {} : { style: a }
389
+ }), r = "";
390
+ }, s = (e, t) => {
391
+ o(), i = t ? i.filter((t) => t !== e) : [...i, e];
392
+ }, c = 0;
393
+ for (; c < e.length;) {
394
+ let l = e[c];
395
+ if (l === "\\" && c + 1 < e.length && y.test(e[c + 1])) r += e[c + 1], c += 2;
396
+ else {
397
+ if (e.startsWith("**", c)) {
398
+ let t = i.includes("bold");
399
+ if (t || e.indexOf("**", c + 2) !== -1) {
400
+ s("bold", t), c += 2;
401
+ continue;
402
+ }
403
+ }
404
+ if (e.startsWith("++", c)) {
405
+ let t = i.includes("underline");
406
+ if (t || e.indexOf("++", c + 2) !== -1) {
407
+ s("underline", t), c += 2;
408
+ continue;
409
+ }
410
+ }
411
+ if (l === "_") {
412
+ let t = i.includes("italic");
413
+ if (t || e.indexOf("_", c + 1) !== -1) {
414
+ s("italic", t), c += 1;
415
+ continue;
416
+ }
417
+ }
418
+ if (l === "[") {
419
+ let t = /^\[([^\]]+)\]\((doc|contact|mailto|tel):([^)\s]+)\)/.exec(e.slice(c));
420
+ if (t !== null) {
421
+ o();
422
+ let [, e = "", r, i = ""] = t;
423
+ n.push(r === "doc" ? {
424
+ type: "link",
425
+ text: e,
426
+ target: i
427
+ } : r === "contact" ? {
428
+ type: "contact",
429
+ text: e,
430
+ contact: { target: i }
431
+ } : {
432
+ type: "contact",
433
+ text: e,
434
+ contact: {
435
+ channel: r === "mailto" ? "email" : "phone",
436
+ value: i
437
+ }
438
+ }), c += t[0].length;
439
+ continue;
440
+ }
441
+ }
442
+ if (l === "{" && a === void 0) {
443
+ let n = /^\{([a-z][a-zA-Z0-9]*)\|/.exec(e.slice(c));
444
+ if (n !== null && t.includes(n[1]) && e.indexOf("}", c) !== -1) {
445
+ o(), a = n[1], c += n[0].length;
446
+ continue;
447
+ }
448
+ }
449
+ l === "}" && a !== void 0 ? (o(), a = void 0, c += 1) : (r += l, c += 1);
450
+ }
451
+ }
452
+ return o(), n;
453
+ }, x = (e) => e.replace(/[*_+[\]()\\{}|]/g, (e) => `\\${e}`), S = (e) => e.map((e) => {
454
+ if (e.type === "link") return `[${x(e.text)}](doc:${e.target})`;
455
+ if (e.type === "contact") {
456
+ let t = "target" in e.contact ? `contact:${e.contact.target}` : `${e.contact.channel === "email" ? "mailto" : "tel"}:${e.contact.value}`;
457
+ return `[${x(e.text)}](${t})`;
458
+ }
459
+ let t = e.marks ?? [], n = t.includes("bold") ? "**" : "", r = t.includes("italic") ? "_" : "", i = t.includes("underline") ? "++" : "", a = `${n}${r}${i}${x(e.text)}${i}${r}${n}`;
460
+ return e.style === void 0 ? a : `{${e.style}|${a}}`;
461
+ }).join(""), C = (e) => {
462
+ switch (e.type) {
463
+ case "paragraph":
464
+ case "heading": return S(e.content);
465
+ case "list": return e.items.map((t, n) => `${" ".repeat(e.levels?.[n] ?? 0)}${S(t)}`).join("\n");
466
+ case "table": return e.rows.map((e) => e.map(S).join(" | ")).join("\n");
467
+ case "image":
468
+ case "file":
469
+ case "component": return "";
470
+ }
471
+ }, w = (e, t) => {
472
+ let n = [], r = [];
473
+ for (let i of e.split("\n")) {
474
+ if (i.trim() === "") continue;
475
+ let e = /^[ \t]*/.exec(i)[0].replace(/\t/g, " ").length, a = Math.floor(e / 2), o = Math.min(a, 3, r.length === 0 ? 0 : r[r.length - 1] + 1);
476
+ n.push(b(i.trim(), t)), r.push(o);
477
+ }
478
+ return r.some((e) => e > 0) ? {
479
+ items: n,
480
+ levels: r
481
+ } : { items: n };
482
+ }, T = (e) => e.split("\n").map((e) => e.trim()).filter((e) => e !== ""), E = (e, t, n = []) => {
483
+ switch (e.type) {
484
+ case "paragraph":
485
+ case "heading": return {
486
+ ...e,
487
+ content: b(t, n)
488
+ };
489
+ case "list": return {
490
+ id: e.id,
491
+ type: "list",
492
+ ordered: e.ordered,
493
+ ...w(t, n),
494
+ ...e.change === void 0 ? {} : { change: e.change },
495
+ ...e.sublists === void 0 ? {} : { sublists: e.sublists },
496
+ ...e.style === void 0 ? {} : { style: e.style }
497
+ };
498
+ case "table": return {
499
+ ...e,
500
+ rows: T(t).map((e) => e.split("|").map((e) => b(e.trim())))
501
+ };
502
+ case "image":
503
+ case "file":
504
+ case "component": return e;
505
+ }
506
+ }, D = (e) => {
507
+ let t = (e) => e.map((e) => e.text).join("");
508
+ return e.blocks.map((e) => {
509
+ switch (e.type) {
510
+ case "paragraph":
511
+ case "heading": return t(e.content);
512
+ case "list": return e.items.map(t).join("\n");
513
+ case "table": return e.rows.map((e) => e.map(t).join(" ")).join("\n");
514
+ case "image": return e.caption ?? "";
515
+ case "file": return e.label;
516
+ case "component": return "";
517
+ }
518
+ }).filter((e) => e !== "").join("\n");
519
+ };
520
+ //#endregion
521
+ export { e as MAX_LIST_LEVEL, C as blockMarkup, d as contactLiteralHref, u as contactLiteralProblem, o as emptyRichDocument, S as inlineMarkupOf, t as listNumberedAt, a as newBlockId, s as normalizeRichDocument, b as parseInlineMarkup, D as plainTextOf, h as richDocumentProblems, _ as richDocumentReferenceFields, g as richDocumentReferencePaths, v as richDocumentReferences, E as withBlockMarkup };