@voltro/cms 0.85.0 → 0.86.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +666 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- package/dist/ContentForm.js +282 -0
- package/dist/RichDocumentEditor.js +550 -0
- package/dist/RichDocumentView.js +132 -0
- package/dist/RichTextSurface.js +135 -0
- package/dist/aiCandidates.js +199 -0
- package/dist/aiOperations.js +152 -0
- package/dist/audiences.js +31 -0
- package/dist/availability.js +121 -0
- package/dist/blueprint.js +166 -0
- package/dist/bulk.js +281 -0
- package/dist/cacheIdentity.js +152 -0
- package/dist/changes.js +90 -0
- package/dist/cmsContext.js +229 -0
- package/dist/collections.js +224 -0
- package/dist/consent.js +29 -0
- package/dist/contentType.js +191 -0
- package/dist/contentfulImport.js +162 -0
- package/dist/copies.js +89 -0
- package/dist/cutover.js +202 -0
- package/dist/deliveryChecks.js +138 -0
- package/dist/domains.js +145 -0
- package/dist/draftTexts.js +164 -0
- package/dist/duplicates.js +78 -0
- package/dist/edgePurge.js +69 -0
- package/dist/editHistory.js +113 -0
- package/dist/effectForm.js +11 -0
- package/dist/environments.js +109 -0
- package/dist/errors.js +67 -0
- package/dist/experiments.js +528 -0
- package/dist/exposure.js +28 -0
- package/dist/extensionManifest.js +81 -0
- package/dist/extensions.js +314 -0
- package/dist/fieldSchema.js +199 -0
- package/dist/formStrings.js +74 -0
- package/dist/glossary.js +73 -0
- package/dist/history.js +54 -0
- package/dist/htmlImport.js +297 -0
- package/dist/index.d.ts +11 -7
- package/dist/index.js +73 -6082
- package/dist/media.js +29 -0
- package/dist/metrics.js +46 -0
- package/dist/migration.js +193 -0
- package/dist/migrationStages.js +13 -0
- package/dist/presenceAnchors.js +68 -0
- package/dist/preview.js +31 -0
- package/dist/promotion.js +107 -0
- package/dist/quality.js +188 -0
- package/dist/recurrence.js +78 -0
- package/dist/redirects.js +99 -0
- package/dist/referenceGraph.js +223 -0
- package/dist/references.js +173 -0
- package/dist/release.js +205 -0
- package/dist/rest.js +52 -0
- package/dist/review.js +160 -0
- package/dist/richDocument.js +491 -0
- package/dist/richInline.js +100 -0
- package/dist/schedule.js +80 -0
- package/dist/search.js +148 -0
- package/dist/selectionIntent.js +164 -0
- package/dist/seo.js +31 -0
- package/dist/series.js +105 -0
- package/dist/share.js +112 -0
- package/dist/stewardship.js +146 -0
- package/dist/taxonomy.js +36 -0
- package/dist/team.js +103 -0
- package/dist/templates.js +106 -0
- package/dist/trackChanges.js +197 -0
- package/dist/translation.js +64 -0
- package/dist/tree.js +87 -0
- package/dist/usage.js +50 -0
- package/dist/validation.js +192 -0
- package/dist/visualEditing.js +60 -0
- package/dist/web.js +33 -2
- package/dist/workflow.js +322 -0
- package/dist/write.js +394 -0
- package/dist/xliff.js +325 -0
- package/package.json +5 -5
- package/dist/presenceAnchors-4iHAVQB3.js +0 -4367
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { buildTree as e } from "./tree.js";
|
|
2
|
+
import { hadAddress as t, redirectTarget as n } from "./redirects.js";
|
|
3
|
+
import { usedBy as r } from "./references.js";
|
|
4
|
+
import { verifyPreviewToken as i } from "./preview.js";
|
|
5
|
+
import { and as a, eq as o, gt as s, gte as c, lt as l, lte as u, neq as d } from "@voltro/database";
|
|
6
|
+
//#region src/cmsContext.ts
|
|
7
|
+
var f = (e, t, n) => {
|
|
8
|
+
switch (t) {
|
|
9
|
+
case "=": return o(e, n);
|
|
10
|
+
case "!=": return d(e, n);
|
|
11
|
+
case "<": return l(e, n);
|
|
12
|
+
case "<=": return u(e, n);
|
|
13
|
+
case ">": return s(e, n);
|
|
14
|
+
case ">=": return c(e, n);
|
|
15
|
+
}
|
|
16
|
+
}, p = (e) => {
|
|
17
|
+
let t = e.excludeArchived ? [...e.predicates, d("status", "archived")] : e.predicates, n = t.length === 0 ? void 0 : t.length === 1 ? t[0] : a(...t);
|
|
18
|
+
return {
|
|
19
|
+
table: e.table,
|
|
20
|
+
predicate: n,
|
|
21
|
+
order: e.order,
|
|
22
|
+
take: e.take,
|
|
23
|
+
skip: e.skip,
|
|
24
|
+
projection: void 0
|
|
25
|
+
};
|
|
26
|
+
}, m = (e, t) => ({
|
|
27
|
+
where(n, r, i) {
|
|
28
|
+
return m(e, {
|
|
29
|
+
...t,
|
|
30
|
+
predicates: [...t.predicates, f(n, r, i)]
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
orderBy(n, r = "asc") {
|
|
34
|
+
return m(e, {
|
|
35
|
+
...t,
|
|
36
|
+
order: [...t.order, {
|
|
37
|
+
column: n,
|
|
38
|
+
direction: r
|
|
39
|
+
}]
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
limit(n) {
|
|
43
|
+
return m(e, {
|
|
44
|
+
...t,
|
|
45
|
+
take: n
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
offset(n) {
|
|
49
|
+
return m(e, {
|
|
50
|
+
...t,
|
|
51
|
+
skip: n
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
async all() {
|
|
55
|
+
return e.query(p(t));
|
|
56
|
+
},
|
|
57
|
+
async one() {
|
|
58
|
+
return (await e.query(p({
|
|
59
|
+
...t,
|
|
60
|
+
take: 1
|
|
61
|
+
})))[0] ?? null;
|
|
62
|
+
},
|
|
63
|
+
async page(n, r) {
|
|
64
|
+
let i = Math.max(1, Math.floor(n)), a = r === void 0 ? t.predicates : [...t.predicates, s("id", r)], o = await e.query(p({
|
|
65
|
+
...t,
|
|
66
|
+
predicates: a,
|
|
67
|
+
order: [{
|
|
68
|
+
column: "id",
|
|
69
|
+
direction: "asc"
|
|
70
|
+
}],
|
|
71
|
+
take: i + 1,
|
|
72
|
+
skip: void 0
|
|
73
|
+
})), c = o.slice(0, i);
|
|
74
|
+
return {
|
|
75
|
+
items: c,
|
|
76
|
+
next: o.length > i ? String(c[c.length - 1]?.id) : null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}), h = (s, c, l, u) => {
|
|
80
|
+
let f = [
|
|
81
|
+
o("site", l.site),
|
|
82
|
+
o("environment", l.environment),
|
|
83
|
+
o("locale", l.locale)
|
|
84
|
+
], p = new Map(c.map((e) => [e.name, e])), h = (e) => {
|
|
85
|
+
let t = p.get(e);
|
|
86
|
+
if (!t) throw Error(`cms.contentType('${e}'): unknown content type. Register it via defineContentType and pass it to cmsContext / createCmsClient.`);
|
|
87
|
+
return t;
|
|
88
|
+
}, g = async (e, t, n) => (await s.query({
|
|
89
|
+
table: `${e}_published`,
|
|
90
|
+
predicate: a(o("site", l.site), o("environment", l.environment), o("locale", t), d("status", "archived"), ...Object.entries(n).map(([e, t]) => o(e, t))),
|
|
91
|
+
order: [],
|
|
92
|
+
take: 1,
|
|
93
|
+
skip: void 0,
|
|
94
|
+
projection: void 0
|
|
95
|
+
}))[0] ?? null, _ = (e, t, n) => s.query({
|
|
96
|
+
table: `${e}_published`,
|
|
97
|
+
predicate: a(o("site", l.site), o("environment", l.environment), o("locale", t), d("status", "archived"), ...Object.entries(n).map(([e, t]) => o(e, t))),
|
|
98
|
+
order: [],
|
|
99
|
+
take: void 0,
|
|
100
|
+
skip: void 0,
|
|
101
|
+
projection: void 0
|
|
102
|
+
}), v = async (t, n, r) => {
|
|
103
|
+
let i = h(t).tree;
|
|
104
|
+
if (i === void 0) throw Error(`cms.tree('${t}'): the content type declares no tree. Add tree: { parent, segment } to it.`);
|
|
105
|
+
let a = [];
|
|
106
|
+
for (let e of /* @__PURE__ */ new Set([n, ...r.fallback ?? []])) for (let i of await _(t, e, r.filter ?? {})) a.push({
|
|
107
|
+
row: i,
|
|
108
|
+
locale: e,
|
|
109
|
+
fallback: e !== n
|
|
110
|
+
});
|
|
111
|
+
return e(a, i);
|
|
112
|
+
}, y = {
|
|
113
|
+
async usedBy(e, t) {
|
|
114
|
+
return h(e), r(s, {
|
|
115
|
+
type: e,
|
|
116
|
+
documentId: t
|
|
117
|
+
}, l);
|
|
118
|
+
},
|
|
119
|
+
async tree(e, t = {}) {
|
|
120
|
+
return v(e, l.locale, t);
|
|
121
|
+
},
|
|
122
|
+
async route(e, t, r = {}) {
|
|
123
|
+
let i = await v(e, l.locale, r), a = i.nodes.find((e) => e.path === t);
|
|
124
|
+
if (a !== void 0) return {
|
|
125
|
+
node: a,
|
|
126
|
+
tree: i,
|
|
127
|
+
via: "path"
|
|
128
|
+
};
|
|
129
|
+
for (let n of r.fallback ?? []) {
|
|
130
|
+
if (n === l.locale) continue;
|
|
131
|
+
let a = (await v(e, n, {
|
|
132
|
+
...r,
|
|
133
|
+
fallback: []
|
|
134
|
+
})).nodes.find((e) => e.path === t);
|
|
135
|
+
if (a === void 0) continue;
|
|
136
|
+
let o = i.nodes.find((e) => e.documentId === a.documentId);
|
|
137
|
+
return o === void 0 ? null : {
|
|
138
|
+
node: o,
|
|
139
|
+
tree: i,
|
|
140
|
+
via: "fallback"
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
let o = r.filter?.tenantId;
|
|
144
|
+
for (let a of /* @__PURE__ */ new Set([l.locale, ...r.fallback ?? []])) {
|
|
145
|
+
let r = await n(s, e, t, {
|
|
146
|
+
...l,
|
|
147
|
+
locale: a
|
|
148
|
+
}, o), c = r === null ? void 0 : i.nodes.find((e) => e.documentId === r);
|
|
149
|
+
if (c !== void 0) return {
|
|
150
|
+
node: c,
|
|
151
|
+
tree: i,
|
|
152
|
+
via: "redirect"
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
},
|
|
157
|
+
async gone(e, n, r = {}) {
|
|
158
|
+
if (await y.route(e, n, r) !== null) return !1;
|
|
159
|
+
let i = r.filter?.tenantId;
|
|
160
|
+
for (let a of /* @__PURE__ */ new Set([l.locale, ...r.fallback ?? []])) if (await t(s, e, n, {
|
|
161
|
+
...l,
|
|
162
|
+
locale: a
|
|
163
|
+
}, i)) return !0;
|
|
164
|
+
return !1;
|
|
165
|
+
},
|
|
166
|
+
async resolve(e, t) {
|
|
167
|
+
h(e);
|
|
168
|
+
let n = t.filter ?? {}, r = {
|
|
169
|
+
...n,
|
|
170
|
+
[t.key.field]: t.key.value
|
|
171
|
+
}, i = l.locale, a = await g(e, i, r);
|
|
172
|
+
if (a !== null) return {
|
|
173
|
+
row: a,
|
|
174
|
+
locale: i,
|
|
175
|
+
requestedLocale: i,
|
|
176
|
+
fallback: !1
|
|
177
|
+
};
|
|
178
|
+
for (let a of t.fallback ?? []) {
|
|
179
|
+
if (a === i) continue;
|
|
180
|
+
let t = await g(e, a, r);
|
|
181
|
+
if (t === null) continue;
|
|
182
|
+
let o = await g(e, i, {
|
|
183
|
+
...n,
|
|
184
|
+
documentId: t.documentId
|
|
185
|
+
});
|
|
186
|
+
return o === null ? {
|
|
187
|
+
row: t,
|
|
188
|
+
locale: a,
|
|
189
|
+
requestedLocale: i,
|
|
190
|
+
fallback: !0
|
|
191
|
+
} : {
|
|
192
|
+
row: o,
|
|
193
|
+
locale: i,
|
|
194
|
+
requestedLocale: i,
|
|
195
|
+
fallback: !1
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
},
|
|
200
|
+
contentType(e) {
|
|
201
|
+
return h(e), m(s, {
|
|
202
|
+
table: `${e}_published`,
|
|
203
|
+
predicates: f,
|
|
204
|
+
order: [],
|
|
205
|
+
take: void 0,
|
|
206
|
+
skip: void 0,
|
|
207
|
+
excludeArchived: !0
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
async preview(e, t, n) {
|
|
211
|
+
h(e);
|
|
212
|
+
let r = n ? i(n, u ? { secret: u } : {}) : null, c = r !== null && r.type === e && r.id === t ? `${e}_drafts` : `${e}_published`;
|
|
213
|
+
return (await s.query({
|
|
214
|
+
table: c,
|
|
215
|
+
predicate: a(o("id", t), ...f),
|
|
216
|
+
order: [],
|
|
217
|
+
take: 1,
|
|
218
|
+
skip: void 0,
|
|
219
|
+
projection: void 0
|
|
220
|
+
}))[0] ?? null;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
return y;
|
|
224
|
+
}, g = (e, t, n) => h(e, t, n.scope, n.secret), _ = (e) => h(e.store, e.types, e.scope, e.secret), v = (e) => {
|
|
225
|
+
if (e.cms === void 0) throw Error("useCms: `ctx.cms` is not set. Build it with cmsContext(store, types, { scope }) and attach it to your AppContext (or use createCmsClient at build time).");
|
|
226
|
+
return e.cms;
|
|
227
|
+
};
|
|
228
|
+
//#endregion
|
|
229
|
+
export { g as cmsContext, _ as createCmsClient, v as useCms };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { and as t, eq as n, id as r, integer as i, table as a, text as o, timestamp as s } from "@voltro/database";
|
|
3
|
+
import { tenant as c } from "@voltro/plugin-multitenancy/mixin";
|
|
4
|
+
import { createHash as l, randomBytes as u } from "node:crypto";
|
|
5
|
+
//#region src/collections.ts
|
|
6
|
+
var d = "cms_collections", f = "cms_collection_items", p = "cms_collection_portals", m = 90, h = a(d, {
|
|
7
|
+
id: r({ prefix: "ccol" }),
|
|
8
|
+
site: o().maxLength(64),
|
|
9
|
+
environment: o().maxLength(64),
|
|
10
|
+
name: o(),
|
|
11
|
+
description: o().nullable()
|
|
12
|
+
}).with(c()), g = a(f, {
|
|
13
|
+
id: r({ prefix: "ccli" }),
|
|
14
|
+
collectionId: o().maxLength(64),
|
|
15
|
+
contentType: o().maxLength(64),
|
|
16
|
+
documentId: o().maxLength(64),
|
|
17
|
+
position: i()
|
|
18
|
+
}).with(c()).unique("cms_collection_items_once", ["collectionId", "documentId"]), _ = a(p, {
|
|
19
|
+
id: r({ prefix: "ccpt" }),
|
|
20
|
+
collectionId: o().maxLength(64),
|
|
21
|
+
tokenHash: o().unique(),
|
|
22
|
+
label: o().nullable(),
|
|
23
|
+
expiresAt: s(),
|
|
24
|
+
revokedAt: s().nullable(),
|
|
25
|
+
maxDownloads: i().nullable(),
|
|
26
|
+
downloads: i()
|
|
27
|
+
}).with(c()), v = (e) => l("sha256").update(e, "utf8").digest("hex"), y = (e) => e instanceof Date ? e : new Date(String(e)), b = async (e, t, n) => {
|
|
28
|
+
let r = n.name.trim().slice(0, 120), i = n.description?.trim() ? n.description.trim().slice(0, 500) : null, a = await e.insert(d, {
|
|
29
|
+
site: t.site,
|
|
30
|
+
environment: t.environment,
|
|
31
|
+
name: r,
|
|
32
|
+
description: i
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
id: String(a.id),
|
|
36
|
+
name: r,
|
|
37
|
+
description: i
|
|
38
|
+
};
|
|
39
|
+
}, x = async (e, r) => (await e.query({
|
|
40
|
+
table: d,
|
|
41
|
+
predicate: t(n("site", r.site), n("environment", r.environment)),
|
|
42
|
+
order: [{
|
|
43
|
+
column: "name",
|
|
44
|
+
direction: "asc"
|
|
45
|
+
}],
|
|
46
|
+
take: 500,
|
|
47
|
+
skip: void 0,
|
|
48
|
+
projection: void 0
|
|
49
|
+
})).map((e) => ({
|
|
50
|
+
id: String(e.id),
|
|
51
|
+
name: String(e.name),
|
|
52
|
+
description: typeof e.description == "string" ? e.description : null
|
|
53
|
+
})), S = async (e, t, r = !1) => (await e.query({
|
|
54
|
+
table: f,
|
|
55
|
+
predicate: n("collectionId", t),
|
|
56
|
+
order: [{
|
|
57
|
+
column: "position",
|
|
58
|
+
direction: "asc"
|
|
59
|
+
}],
|
|
60
|
+
take: 1e3,
|
|
61
|
+
skip: void 0,
|
|
62
|
+
projection: void 0,
|
|
63
|
+
...r ? { crossTenant: !0 } : {}
|
|
64
|
+
})).map((e) => ({
|
|
65
|
+
contentType: String(e.contentType),
|
|
66
|
+
documentId: String(e.documentId),
|
|
67
|
+
position: Number(e.position)
|
|
68
|
+
})), C = async (e, t) => (await e.query({
|
|
69
|
+
table: d,
|
|
70
|
+
predicate: n("id", t),
|
|
71
|
+
order: [],
|
|
72
|
+
take: 1,
|
|
73
|
+
skip: void 0,
|
|
74
|
+
projection: void 0
|
|
75
|
+
}))[0], w = async (e, t, n) => {
|
|
76
|
+
if (await C(e, t) === void 0) return !1;
|
|
77
|
+
let r = await S(e, t);
|
|
78
|
+
return r.some((e) => e.documentId === n.documentId) || await e.insert(f, {
|
|
79
|
+
collectionId: t,
|
|
80
|
+
contentType: n.contentType,
|
|
81
|
+
documentId: n.documentId,
|
|
82
|
+
position: r.length
|
|
83
|
+
}), !0;
|
|
84
|
+
}, T = async (e, r, i) => {
|
|
85
|
+
let [a] = await e.query({
|
|
86
|
+
table: f,
|
|
87
|
+
predicate: t(n("collectionId", r), n("documentId", i)),
|
|
88
|
+
order: [],
|
|
89
|
+
take: 1,
|
|
90
|
+
skip: void 0,
|
|
91
|
+
projection: void 0
|
|
92
|
+
});
|
|
93
|
+
return a !== void 0 && (await e.delete(f, String(a.id)), !0);
|
|
94
|
+
}, E = async (e, t, n, r = /* @__PURE__ */ new Date()) => {
|
|
95
|
+
if (await C(e, t) === void 0) return {
|
|
96
|
+
ok: !1,
|
|
97
|
+
reason: "notFound"
|
|
98
|
+
};
|
|
99
|
+
let i = (n.expiresAt.getTime() - r.getTime()) / 864e5;
|
|
100
|
+
if (!(i > 0) || i > 90) return {
|
|
101
|
+
ok: !1,
|
|
102
|
+
reason: "badExpiry"
|
|
103
|
+
};
|
|
104
|
+
let a = n.maxDownloads ?? null;
|
|
105
|
+
if (a !== null && (!Number.isInteger(a) || a < 1 || a > 1e5)) return {
|
|
106
|
+
ok: !1,
|
|
107
|
+
reason: "badLimit"
|
|
108
|
+
};
|
|
109
|
+
let o = u(32).toString("base64url"), s = await e.insert(p, {
|
|
110
|
+
collectionId: t,
|
|
111
|
+
tokenHash: v(o),
|
|
112
|
+
label: n.label?.trim() ? n.label.trim().slice(0, 120) : null,
|
|
113
|
+
expiresAt: n.expiresAt,
|
|
114
|
+
revokedAt: null,
|
|
115
|
+
maxDownloads: a,
|
|
116
|
+
downloads: 0
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
ok: !0,
|
|
120
|
+
id: String(s.id),
|
|
121
|
+
token: o
|
|
122
|
+
};
|
|
123
|
+
}, D = (e) => ({
|
|
124
|
+
id: String(e.id),
|
|
125
|
+
label: typeof e.label == "string" ? e.label : null,
|
|
126
|
+
expiresAt: y(e.expiresAt),
|
|
127
|
+
revoked: e.revokedAt !== null && e.revokedAt !== void 0,
|
|
128
|
+
maxDownloads: typeof e.maxDownloads == "number" ? e.maxDownloads : null,
|
|
129
|
+
downloads: Number(e.downloads ?? 0)
|
|
130
|
+
}), O = async (e, t) => (await e.query({
|
|
131
|
+
table: p,
|
|
132
|
+
predicate: n("collectionId", t),
|
|
133
|
+
order: [{
|
|
134
|
+
column: "createdAt",
|
|
135
|
+
direction: "desc"
|
|
136
|
+
}],
|
|
137
|
+
take: 100,
|
|
138
|
+
skip: void 0,
|
|
139
|
+
projection: void 0
|
|
140
|
+
})).map(D), k = async (e, t, r = /* @__PURE__ */ new Date()) => {
|
|
141
|
+
let [i] = await e.query({
|
|
142
|
+
table: p,
|
|
143
|
+
predicate: n("id", t),
|
|
144
|
+
order: [],
|
|
145
|
+
take: 1,
|
|
146
|
+
skip: void 0,
|
|
147
|
+
projection: void 0
|
|
148
|
+
});
|
|
149
|
+
return i === void 0 || i.revokedAt !== null && i.revokedAt !== void 0 ? !1 : (await e.update(p, t, { revokedAt: r }), !0);
|
|
150
|
+
}, A = async (e, r, i = /* @__PURE__ */ new Date()) => {
|
|
151
|
+
let [a] = await e.query({
|
|
152
|
+
table: p,
|
|
153
|
+
predicate: n("tokenHash", v(r)),
|
|
154
|
+
order: [],
|
|
155
|
+
take: 1,
|
|
156
|
+
skip: void 0,
|
|
157
|
+
projection: void 0,
|
|
158
|
+
crossTenant: !0
|
|
159
|
+
});
|
|
160
|
+
if (a === void 0) return {
|
|
161
|
+
ok: !1,
|
|
162
|
+
reason: "unknown"
|
|
163
|
+
};
|
|
164
|
+
let o = D(a);
|
|
165
|
+
if (o.revoked) return {
|
|
166
|
+
ok: !1,
|
|
167
|
+
reason: "revoked"
|
|
168
|
+
};
|
|
169
|
+
if (o.expiresAt.getTime() <= i.getTime()) return {
|
|
170
|
+
ok: !1,
|
|
171
|
+
reason: "expired"
|
|
172
|
+
};
|
|
173
|
+
let s = typeof a.tenantId == "string" ? a.tenantId : null, [c] = await e.query({
|
|
174
|
+
table: d,
|
|
175
|
+
predicate: t(n("id", String(a.collectionId)), n("tenantId", s)),
|
|
176
|
+
order: [],
|
|
177
|
+
take: 1,
|
|
178
|
+
skip: void 0,
|
|
179
|
+
projection: void 0,
|
|
180
|
+
crossTenant: !0
|
|
181
|
+
});
|
|
182
|
+
return c === void 0 ? {
|
|
183
|
+
ok: !1,
|
|
184
|
+
reason: "unknown"
|
|
185
|
+
} : {
|
|
186
|
+
ok: !0,
|
|
187
|
+
portal: o,
|
|
188
|
+
tenantId: s,
|
|
189
|
+
collection: {
|
|
190
|
+
id: String(c.id),
|
|
191
|
+
name: String(c.name),
|
|
192
|
+
description: typeof c.description == "string" ? c.description : null
|
|
193
|
+
},
|
|
194
|
+
items: await S(e, String(c.id), !0),
|
|
195
|
+
downloadsLeft: o.maxDownloads === null ? null : Math.max(0, o.maxDownloads - o.downloads)
|
|
196
|
+
};
|
|
197
|
+
}, j = async (e, r, i, a = /* @__PURE__ */ new Date()) => {
|
|
198
|
+
for (let o = 0; o < 5; o++) {
|
|
199
|
+
let o = await A(e, r, a);
|
|
200
|
+
if (!o.ok) return o;
|
|
201
|
+
let s = o.items.find((e) => e.documentId === i);
|
|
202
|
+
if (s === void 0) return {
|
|
203
|
+
ok: !1,
|
|
204
|
+
reason: "notInCollection"
|
|
205
|
+
};
|
|
206
|
+
let { portal: c } = o;
|
|
207
|
+
if (c.maxDownloads !== null && c.downloads >= c.maxDownloads) return {
|
|
208
|
+
ok: !1,
|
|
209
|
+
reason: "limitReached"
|
|
210
|
+
};
|
|
211
|
+
if (await e.updateMany("cms_collection_portals", { downloads: c.downloads + 1 }, { where: t(n("id", c.id), n("downloads", c.downloads)) }) === 1) return {
|
|
212
|
+
ok: !0,
|
|
213
|
+
contentType: s.contentType,
|
|
214
|
+
tenantId: o.tenantId,
|
|
215
|
+
downloadsLeft: c.maxDownloads === null ? null : c.maxDownloads - c.downloads - 1
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
ok: !1,
|
|
220
|
+
reason: "limitReached"
|
|
221
|
+
};
|
|
222
|
+
}, M = (...t) => e(() => b(...t)), N = (...t) => e(() => x(...t)), P = (...t) => e(() => S(...t)), F = (...t) => e(() => w(...t)), I = (...t) => e(() => T(...t)), L = (...t) => e(() => E(...t)), R = (...t) => e(() => O(...t)), z = (...t) => e(() => k(...t)), B = (...t) => e(() => A(...t)), V = (...t) => e(() => j(...t));
|
|
223
|
+
//#endregion
|
|
224
|
+
export { d as CMS_COLLECTIONS_TABLE, f as CMS_COLLECTION_ITEMS_TABLE, p as CMS_COLLECTION_PORTALS_TABLE, m as MAX_PORTAL_DAYS, w as addToCollection, F as addToCollectionEffect, g as cmsCollectionItemsTable, _ as cmsCollectionPortalsTable, h as cmsCollectionsTable, S as collectionItems, P as collectionItemsEffect, O as collectionPortals, R as collectionPortalsEffect, b as createCollection, M as createCollectionEffect, E as createPortal, L as createPortalEffect, x as listCollections, N as listCollectionsEffect, j as recordPortalDownload, V as recordPortalDownloadEffect, T as removeFromCollection, I as removeFromCollectionEffect, A as resolvePortal, B as resolvePortalEffect, k as revokePortal, z as revokePortalEffect };
|
package/dist/consent.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/consent.ts
|
|
2
|
+
var e = /^https:\/\/[a-z0-9.-]+(:\d+)?$/, t = (t) => {
|
|
3
|
+
for (let n of t) {
|
|
4
|
+
let t = /* @__PURE__ */ new Set();
|
|
5
|
+
for (let r of n.vendors ?? []) {
|
|
6
|
+
if (!/^[a-z][a-zA-Z0-9]*$/.test(r.id) || t.has(r.id)) throw Error(`consent purpose '${n.id}': vendor id '${r.id}' must be a unique camelCase id`);
|
|
7
|
+
t.add(r.id);
|
|
8
|
+
for (let t of r.origins) if (!e.test(t)) throw Error(`consent purpose '${n.id}': vendor '${r.name}' origin '${t}' must be exactly https://host`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}, n = (t, n) => {
|
|
12
|
+
let r = i(t, n);
|
|
13
|
+
return [...new Set(t.filter((e) => r.has(e.id)).flatMap((e) => (e.vendors ?? []).flatMap((e) => e.origins)).filter((t) => e.test(t)))].sort();
|
|
14
|
+
}, r = (e, t, r = "frame-ancestors 'none'; base-uri 'none'; object-src 'none'") => [r, `frame-src ${["'self'", ...n(e, t)].join(" ")}`].filter((e) => e !== "").join("; "), i = (e, t) => new Set(e.filter((e) => t[e.id] === e.version).map((e) => e.id)), a = (e, t, n) => Array.isArray(e) ? e.map((e) => {
|
|
15
|
+
if (typeof e != "object" || !e) return e;
|
|
16
|
+
let r = e, i = t.get(String(r.componentId))?.consent;
|
|
17
|
+
return i === void 0 || n.has(i) ? e : {
|
|
18
|
+
instanceId: String(r.instanceId ?? ""),
|
|
19
|
+
componentId: String(r.componentId),
|
|
20
|
+
consentRequired: i,
|
|
21
|
+
props: {}
|
|
22
|
+
};
|
|
23
|
+
}) : e, o = (e, t, n) => {
|
|
24
|
+
let r = { ...t };
|
|
25
|
+
for (let [i, o] of Object.entries(e.fields)) o.kind === "components" && o.components !== void 0 && (r[i] = a(t[i], new Map(o.components.map((e) => [e.id, e])), n));
|
|
26
|
+
return r;
|
|
27
|
+
}, s = (e) => new Set(Object.values(e.fields).flatMap((e) => (e.components ?? []).flatMap((e) => e.consent === void 0 ? [] : [e.consent])));
|
|
28
|
+
//#endregion
|
|
29
|
+
export { t as checkConsentPurposes, r as consentContentSecurityPolicy, n as consentedOrigins, o as gateConsent, i as grantedPurposes, s as purposesUsedBy };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { checkTemplates as e } from "./templates.js";
|
|
2
|
+
import { checkSearch as t } from "./search.js";
|
|
3
|
+
import { taxonomyProblem as n } from "./taxonomy.js";
|
|
4
|
+
import { componentExampleViolations as r } from "./validation.js";
|
|
5
|
+
import { boolean as i, date as a, id as o, integer as s, json as c, real as l, table as u, text as d, timestamp as f } from "@voltro/database";
|
|
6
|
+
import { tenant as p } from "@voltro/plugin-multitenancy/mixin";
|
|
7
|
+
//#region src/contentType.ts
|
|
8
|
+
var m = [
|
|
9
|
+
"site",
|
|
10
|
+
"environment",
|
|
11
|
+
"locale"
|
|
12
|
+
], h = [
|
|
13
|
+
"draft",
|
|
14
|
+
"published",
|
|
15
|
+
"archived"
|
|
16
|
+
], g = [
|
|
17
|
+
"id",
|
|
18
|
+
"status",
|
|
19
|
+
"publishAt",
|
|
20
|
+
"unpublishAt",
|
|
21
|
+
"revisionId",
|
|
22
|
+
"revision",
|
|
23
|
+
"documentId",
|
|
24
|
+
"site",
|
|
25
|
+
"environment",
|
|
26
|
+
"locale",
|
|
27
|
+
"tenantId",
|
|
28
|
+
"createdAt",
|
|
29
|
+
"updatedAt",
|
|
30
|
+
"createdBy",
|
|
31
|
+
"updatedBy"
|
|
32
|
+
], _ = (i) => {
|
|
33
|
+
let a = {}, o = [], s = [];
|
|
34
|
+
for (let [e, t] of Object.entries(i.fields)) {
|
|
35
|
+
if (g.includes(e)) throw Error(`defineContentType('${i.name}'): field '${e}' collides with a reserved lifecycle column (${g.join(", ")}). Rename it.`);
|
|
36
|
+
let n = t;
|
|
37
|
+
if (n.unique && n.kind !== "string") throw Error(`defineContentType('${i.name}'): field '${e}' is marked unique() but is a '${n.kind}' field — per-tenant uniqueness is only supported on string fields (a slug). Remove unique() or make it a Schema.String.`);
|
|
38
|
+
a[e] = n, n.derived && o.push(e), n.unique && s.push(e);
|
|
39
|
+
}
|
|
40
|
+
if (i.list) {
|
|
41
|
+
let e = /* @__PURE__ */ new Set([...Object.keys(a), ...g]);
|
|
42
|
+
for (let t of i.list.columns) if (!e.has(t)) throw Error(`defineContentType('${i.name}'): list.columns entry '${t}' is not a declared field (or lifecycle column) of this content type.`);
|
|
43
|
+
let t = i.list.defaultSort?.field;
|
|
44
|
+
if (t !== void 0 && !e.has(t)) throw Error(`defineContentType('${i.name}'): list.defaultSort.field '${t}' is not a declared field (or lifecycle column) of this content type.`);
|
|
45
|
+
}
|
|
46
|
+
if (i.tree && y(i.name, a, i.tree), i.address !== void 0) {
|
|
47
|
+
if (i.tree) throw Error(`defineContentType('${i.name}'): address is for a type outside a tree — a tree type is addressed by its tree.`);
|
|
48
|
+
if (a[i.address]?.kind !== "string") throw Error(`defineContentType('${i.name}'): address '${i.address}' must be a declared string field.`);
|
|
49
|
+
}
|
|
50
|
+
i.availability && b(i.name, a, i.availability), i.templates && e(i.name, a, i.templates), i.search && t(i.name, a, i.search), i.quality && v(i.name, a, i.quality);
|
|
51
|
+
for (let e of Object.values(a)) for (let t of e.components ?? []) {
|
|
52
|
+
let [e] = r(t);
|
|
53
|
+
if (e !== void 0) throw Error(`defineContentType('${i.name}'): component '${t.id}' ${e.field}: ${e.message}.`);
|
|
54
|
+
}
|
|
55
|
+
if (i.taxonomy) {
|
|
56
|
+
let e = a[i.taxonomy.field];
|
|
57
|
+
if (e?.kind !== "array" || e.element?.kind !== "string") throw Error(`defineContentType('${i.name}'): taxonomy field '${i.taxonomy.field}' must be a declared Schema.Array(Schema.String) field.`);
|
|
58
|
+
let t = n(i.taxonomy);
|
|
59
|
+
if (t !== null) throw Error(`defineContentType('${i.name}'): taxonomy ${t}.`);
|
|
60
|
+
}
|
|
61
|
+
if (i.lifecycle && !(Number.isInteger(i.lifecycle.reviewEveryDays) && i.lifecycle.reviewEveryDays > 0)) throw Error(`defineContentType('${i.name}'): lifecycle.reviewEveryDays must be a positive whole number of days.`);
|
|
62
|
+
return {
|
|
63
|
+
name: i.name,
|
|
64
|
+
displayName: i.displayName,
|
|
65
|
+
pluralName: i.pluralName,
|
|
66
|
+
fields: a,
|
|
67
|
+
...i.list ? { list: i.list } : {},
|
|
68
|
+
...i.idPrefix ? { idPrefix: i.idPrefix } : {},
|
|
69
|
+
...i.revalidate ? { revalidate: i.revalidate } : {},
|
|
70
|
+
...i.tree ? { tree: i.tree } : {},
|
|
71
|
+
...i.address === void 0 ? {} : { address: i.address },
|
|
72
|
+
...i.review ? { review: i.review } : {},
|
|
73
|
+
...i.availability ? { availability: i.availability } : {},
|
|
74
|
+
...i.lifecycle ? { lifecycle: i.lifecycle } : {},
|
|
75
|
+
...i.templates ? { templates: i.templates } : {},
|
|
76
|
+
...i.changeFeed === !0 ? { changeFeed: !0 } : {},
|
|
77
|
+
...i.search ? { search: i.search } : {},
|
|
78
|
+
...i.quality && i.quality.length > 0 ? { quality: i.quality } : {},
|
|
79
|
+
...i.taxonomy ? { taxonomy: i.taxonomy } : {},
|
|
80
|
+
derivedFields: o,
|
|
81
|
+
uniqueFields: s
|
|
82
|
+
};
|
|
83
|
+
}, v = (e, t, n) => {
|
|
84
|
+
let r = /* @__PURE__ */ new Set();
|
|
85
|
+
for (let i of n) {
|
|
86
|
+
if (!/^[A-Za-z][A-Za-z0-9.-]{0,63}$/.test(i.id)) throw Error(`defineContentType('${e}'): quality rule id '${i.id}' must be letters, digits, '.' or '-', at most 64.`);
|
|
87
|
+
if (r.has(i.id)) throw Error(`defineContentType('${e}'): quality rule '${i.id}' is declared twice.`);
|
|
88
|
+
if (r.add(i.id), t[i.field] === void 0) throw Error(`defineContentType('${e}'): quality rule '${i.id}' names '${i.field}', which is no field of this type.`);
|
|
89
|
+
if (i.sites?.length === 0 || i.locales?.length === 0) throw Error(`defineContentType('${e}'): quality rule '${i.id}' names an empty list of sites or locales — leave it out to apply everywhere.`);
|
|
90
|
+
}
|
|
91
|
+
}, y = (e, t, n) => {
|
|
92
|
+
let r = (t) => {
|
|
93
|
+
throw Error(`defineContentType('${e}'): tree ${t}`);
|
|
94
|
+
}, i = t[n.parent];
|
|
95
|
+
i === void 0 ? r(`parent '${n.parent}' is not a declared field.`) : (i.kind !== "reference" || i.referenceType !== e || !i.isOptional) && r(`parent '${n.parent}' must be Schema.Reference('${e}').optional() — roots have no parent.`);
|
|
96
|
+
let a = t[n.segment];
|
|
97
|
+
(a === void 0 || a.kind !== "string") && r(`segment '${n.segment}' must be a declared string field.`), n.order !== void 0 && t[n.order]?.kind !== "number" && r(`order '${n.order}' must be a declared number field.`);
|
|
98
|
+
for (let [e, i] of Object.entries(n.inherit ?? {})) if ((t[e] === void 0 || !t[e].isOptional) && r(`inherit '${e}' must be a declared optional field — a page that sets nothing inherits.`), i.mask !== void 0) {
|
|
99
|
+
let n = t[i.mask];
|
|
100
|
+
(n === void 0 || !n.isOptional || n.kind !== "boolean") && r(`inherit '${e}' mask '${i.mask}' must be a declared optional Boolean field.`), i.locked === !0 && r(`inherit '${e}' is locked, so it cannot be masked — drop 'mask' or 'locked'.`);
|
|
101
|
+
}
|
|
102
|
+
}, b = (e, t, n) => {
|
|
103
|
+
let r = n.until === void 0 ? void 0 : t[n.until];
|
|
104
|
+
if (n.until !== void 0 && (r === void 0 || r.kind !== "date" && r.kind !== "datetime")) throw Error(`defineContentType('${e}'): availability.until '${n.until}' must be a declared date or datetime field.`);
|
|
105
|
+
let i = n.blocked === void 0 ? void 0 : t[n.blocked];
|
|
106
|
+
if (n.blocked !== void 0 && (i === void 0 || i.kind !== "boolean")) throw Error(`defineContentType('${e}'): availability.blocked '${n.blocked}' must be a declared boolean field.`);
|
|
107
|
+
let a = n.from === void 0 ? void 0 : t[n.from];
|
|
108
|
+
if (n.from !== void 0 && (a === void 0 || a.kind !== "date" && a.kind !== "datetime")) throw Error(`defineContentType('${e}'): availability.from '${n.from}' must be a declared date or datetime field.`);
|
|
109
|
+
for (let r of [
|
|
110
|
+
"territories",
|
|
111
|
+
"channels",
|
|
112
|
+
"purposes"
|
|
113
|
+
]) {
|
|
114
|
+
let i = n[r] === void 0 ? void 0 : t[n[r]];
|
|
115
|
+
if (n[r] !== void 0 && (i?.kind !== "array" || i.element?.kind !== "string" && i.element?.kind !== "literal")) throw Error(`defineContentType('${e}'): availability.${r} '${n[r]}' must be a declared list of text or choices.`);
|
|
116
|
+
}
|
|
117
|
+
}, x = (e) => {
|
|
118
|
+
switch (e.kind) {
|
|
119
|
+
case "string": return e.isOptional ? d().nullable() : d();
|
|
120
|
+
case "number": return e.fraction === !0 ? e.isOptional ? l().nullable() : l() : e.isOptional ? s().nullable() : s();
|
|
121
|
+
case "boolean": return e.isOptional ? i().nullable() : i();
|
|
122
|
+
case "date": return e.isOptional ? a().nullable() : a();
|
|
123
|
+
case "datetime": return e.isOptional ? f().nullable() : f();
|
|
124
|
+
case "literal": {
|
|
125
|
+
let t = e.literals ?? [], n = t.length > 0 ? d().oneOf(t) : d();
|
|
126
|
+
return e.isOptional ? n.nullable() : n;
|
|
127
|
+
}
|
|
128
|
+
case "richText":
|
|
129
|
+
case "array":
|
|
130
|
+
case "struct":
|
|
131
|
+
case "components": {
|
|
132
|
+
let t = c();
|
|
133
|
+
return e.isOptional ? t.nullable() : t;
|
|
134
|
+
}
|
|
135
|
+
case "media":
|
|
136
|
+
case "reference": return e.isOptional ? d().nullable() : d();
|
|
137
|
+
}
|
|
138
|
+
}, S = (e) => {
|
|
139
|
+
let t = {};
|
|
140
|
+
for (let [n, r] of Object.entries(e.fields)) t[n] = x(r);
|
|
141
|
+
return t;
|
|
142
|
+
}, C = (e) => e.idPrefix, w = (e, t) => {
|
|
143
|
+
let n = C(e), r = n ? o({ prefix: n }) : o(), i = u(`${e.name}_${t}`, {
|
|
144
|
+
id: r,
|
|
145
|
+
status: d().oneOf(h),
|
|
146
|
+
...t === "drafts" ? {
|
|
147
|
+
publishAt: f().nullable(),
|
|
148
|
+
unpublishAt: f().nullable()
|
|
149
|
+
} : {},
|
|
150
|
+
revisionId: d().default(""),
|
|
151
|
+
revision: s().default(0),
|
|
152
|
+
documentId: d().maxLength(64).backfill((e) => String(e.id)),
|
|
153
|
+
site: d().maxLength(64).default(""),
|
|
154
|
+
environment: d().maxLength(64).default(""),
|
|
155
|
+
locale: d().maxLength(64).default(""),
|
|
156
|
+
...S(e)
|
|
157
|
+
}).with(p()).unique(D(e, `${e.name}_${t}_variant_key`, "the document variant key"), [
|
|
158
|
+
"tenantId",
|
|
159
|
+
...m,
|
|
160
|
+
"documentId"
|
|
161
|
+
]);
|
|
162
|
+
return e.uniqueFields.reduce((n, r) => n.unique(E(e, t, r), [
|
|
163
|
+
"tenantId",
|
|
164
|
+
...m,
|
|
165
|
+
r
|
|
166
|
+
]), i);
|
|
167
|
+
}, T = 63, E = (e, t, n) => D(e, `${e.name}_${t}_uq_${n}`, `the unique constraint for field '${n}'`), D = (e, t, n) => {
|
|
168
|
+
if (t.length > T) throw Error(`contentTypeToEntities('${e.name}'): ${n} would be named '${t}' (${t.length} chars), past the ${T}-byte identifier limit. Shorten the content type name or the field name.`);
|
|
169
|
+
return t;
|
|
170
|
+
}, O = "cms_revisions", k = u(O, {
|
|
171
|
+
id: o({ prefix: "crev" }),
|
|
172
|
+
contentType: d().maxLength(64),
|
|
173
|
+
documentId: d().maxLength(64),
|
|
174
|
+
number: s(),
|
|
175
|
+
site: d().maxLength(64).default(""),
|
|
176
|
+
environment: d().maxLength(64).default(""),
|
|
177
|
+
locale: d().maxLength(64).default(""),
|
|
178
|
+
values: c(),
|
|
179
|
+
basedOn: d().nullable()
|
|
180
|
+
}).with(p()).unique("cms_revisions_uq_variant_number", [
|
|
181
|
+
"tenantId",
|
|
182
|
+
"contentType",
|
|
183
|
+
"documentId",
|
|
184
|
+
...m,
|
|
185
|
+
"number"
|
|
186
|
+
]), A = (e) => ({
|
|
187
|
+
draft: w(e, "drafts"),
|
|
188
|
+
published: w(e, "published")
|
|
189
|
+
});
|
|
190
|
+
//#endregion
|
|
191
|
+
export { O as CMS_REVISIONS_TABLE, m as CMS_SCOPE_COLUMNS, h as CONTENT_STATUSES, g as RESERVED_FIELD_NAMES, k as cmsRevisionsTable, A as contentTypeToEntities, _ as defineContentType };
|