@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
package/dist/domains.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { and as t, boolean as n, eq as r, id 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 { randomBytes as l } from "node:crypto";
|
|
5
|
+
//#region src/domains.ts
|
|
6
|
+
var u = "cms_site_domains", d = a(u, {
|
|
7
|
+
id: i({ prefix: "cdom" }),
|
|
8
|
+
site: o().maxLength(64),
|
|
9
|
+
host: o().maxLength(253),
|
|
10
|
+
token: o().maxLength(64),
|
|
11
|
+
status: o().oneOf(["pending", "verified"]),
|
|
12
|
+
verifiedAt: s().nullable(),
|
|
13
|
+
isPrimary: n().default(!1)
|
|
14
|
+
}).with(c()).unique("cms_site_domains_host", ["host"]), f = /^(?=.{1,253}$)(?!-)[a-z0-9-]{1,63}(?<!-)(\.(?!-)[a-z0-9-]{1,63}(?<!-))+$/, p = (e) => {
|
|
15
|
+
let t = e.trim().toLowerCase().replace(/\.$/, "");
|
|
16
|
+
return f.test(t) && !/^\d+(\.\d+){3}$/.test(t) ? t : null;
|
|
17
|
+
}, m = (e) => ({
|
|
18
|
+
id: String(e.id),
|
|
19
|
+
site: String(e.site),
|
|
20
|
+
host: String(e.host),
|
|
21
|
+
status: e.status === "verified" ? "verified" : "pending",
|
|
22
|
+
primary: e.isPrimary === !0,
|
|
23
|
+
verifiedAt: e.verifiedAt instanceof Date ? e.verifiedAt : e.verifiedAt ? new Date(String(e.verifiedAt)) : null,
|
|
24
|
+
record: {
|
|
25
|
+
name: `_voltro-verify.${String(e.host)}`,
|
|
26
|
+
value: `voltro-verify=${String(e.token)}`
|
|
27
|
+
}
|
|
28
|
+
}), h = async (e, t) => (await e.query({
|
|
29
|
+
table: u,
|
|
30
|
+
predicate: r("site", t),
|
|
31
|
+
order: [{
|
|
32
|
+
column: "host",
|
|
33
|
+
direction: "asc"
|
|
34
|
+
}],
|
|
35
|
+
take: 100,
|
|
36
|
+
skip: void 0,
|
|
37
|
+
projection: void 0
|
|
38
|
+
})).map(m).sort((e, t) => Number(t.primary) - Number(e.primary)), g = async (e, t, n) => {
|
|
39
|
+
let i = p(n);
|
|
40
|
+
if (i === null) return {
|
|
41
|
+
ok: !1,
|
|
42
|
+
reason: "notAHost"
|
|
43
|
+
};
|
|
44
|
+
let [a] = await e.query({
|
|
45
|
+
table: u,
|
|
46
|
+
predicate: r("host", i),
|
|
47
|
+
order: [],
|
|
48
|
+
take: 1,
|
|
49
|
+
skip: void 0,
|
|
50
|
+
projection: void 0,
|
|
51
|
+
crossTenant: !0
|
|
52
|
+
});
|
|
53
|
+
return a === void 0 ? {
|
|
54
|
+
ok: !0,
|
|
55
|
+
domain: m(await e.insert(u, {
|
|
56
|
+
site: t,
|
|
57
|
+
host: i,
|
|
58
|
+
token: l(16).toString("hex"),
|
|
59
|
+
status: "pending",
|
|
60
|
+
verifiedAt: null,
|
|
61
|
+
isPrimary: !1
|
|
62
|
+
}))
|
|
63
|
+
} : {
|
|
64
|
+
ok: !1,
|
|
65
|
+
reason: "taken"
|
|
66
|
+
};
|
|
67
|
+
}, _ = async (e, t, n, i = /* @__PURE__ */ new Date()) => {
|
|
68
|
+
let [a] = await e.query({
|
|
69
|
+
table: u,
|
|
70
|
+
predicate: r("id", t),
|
|
71
|
+
order: [],
|
|
72
|
+
take: 1,
|
|
73
|
+
skip: void 0,
|
|
74
|
+
projection: void 0
|
|
75
|
+
});
|
|
76
|
+
if (a === void 0) return {
|
|
77
|
+
ok: !1,
|
|
78
|
+
reason: "notFound"
|
|
79
|
+
};
|
|
80
|
+
let o = m(a);
|
|
81
|
+
if (o.status === "verified") return {
|
|
82
|
+
ok: !0,
|
|
83
|
+
domain: o
|
|
84
|
+
};
|
|
85
|
+
let s = await n(o.record.name).catch(() => []);
|
|
86
|
+
return s.some((e) => e.trim() === o.record.value) ? {
|
|
87
|
+
ok: !0,
|
|
88
|
+
domain: m(await e.update(u, t, {
|
|
89
|
+
status: "verified",
|
|
90
|
+
verifiedAt: i
|
|
91
|
+
}) ?? {
|
|
92
|
+
...a,
|
|
93
|
+
status: "verified",
|
|
94
|
+
verifiedAt: i
|
|
95
|
+
})
|
|
96
|
+
} : {
|
|
97
|
+
ok: !1,
|
|
98
|
+
reason: "recordMissing",
|
|
99
|
+
found: s
|
|
100
|
+
};
|
|
101
|
+
}, v = async (e, n) => {
|
|
102
|
+
let [i] = await e.query({
|
|
103
|
+
table: u,
|
|
104
|
+
predicate: r("id", n),
|
|
105
|
+
order: [],
|
|
106
|
+
take: 1,
|
|
107
|
+
skip: void 0,
|
|
108
|
+
projection: void 0
|
|
109
|
+
});
|
|
110
|
+
return i === void 0 ? {
|
|
111
|
+
ok: !1,
|
|
112
|
+
reason: "notFound"
|
|
113
|
+
} : i.status === "verified" ? (await e.updateMany(u, { isPrimary: !1 }, { where: t(r("site", String(i.site)), r("isPrimary", !0)) }), await e.update(u, n, { isPrimary: !0 }), { ok: !0 }) : {
|
|
114
|
+
ok: !1,
|
|
115
|
+
reason: "notVerified"
|
|
116
|
+
};
|
|
117
|
+
}, y = async (e, t) => {
|
|
118
|
+
let [n] = await e.query({
|
|
119
|
+
table: u,
|
|
120
|
+
predicate: r("id", t),
|
|
121
|
+
order: [],
|
|
122
|
+
take: 1,
|
|
123
|
+
skip: void 0,
|
|
124
|
+
projection: void 0
|
|
125
|
+
});
|
|
126
|
+
return n === void 0 ? {
|
|
127
|
+
ok: !1,
|
|
128
|
+
reason: "notFound"
|
|
129
|
+
} : n.isPrimary === !0 ? {
|
|
130
|
+
ok: !1,
|
|
131
|
+
reason: "primary"
|
|
132
|
+
} : (await e.delete(u, t), { ok: !0 });
|
|
133
|
+
}, b = async (e, n) => {
|
|
134
|
+
let [i] = await e.query({
|
|
135
|
+
table: u,
|
|
136
|
+
predicate: t(r("site", n), r("isPrimary", !0)),
|
|
137
|
+
order: [],
|
|
138
|
+
take: 1,
|
|
139
|
+
skip: void 0,
|
|
140
|
+
projection: void 0
|
|
141
|
+
});
|
|
142
|
+
return i === void 0 ? null : String(i.host);
|
|
143
|
+
}, x = (...t) => e(() => h(...t)), S = (...t) => e(() => g(...t)), C = (...t) => e(() => _(...t)), w = (...t) => e(() => v(...t)), T = (...t) => e(() => y(...t)), E = (...t) => e(() => b(...t));
|
|
144
|
+
//#endregion
|
|
145
|
+
export { u as CMS_SITE_DOMAINS_TABLE, g as addDomain, S as addDomainEffect, d as cmsSiteDomainsTable, p as normalizeHost, b as primaryDomain, E as primaryDomainEffect, y as removeDomain, T as removeDomainEffect, v as setPrimaryDomain, w as setPrimaryDomainEffect, h as siteDomains, x as siteDomainsEffect, _ as verifyDomain, C as verifyDomainEffect };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { blockMarkup as e, normalizeRichDocument as t, withBlockMarkup as n } from "./richDocument.js";
|
|
2
|
+
import { asTyped as r } from "./effectForm.js";
|
|
3
|
+
import { ContentNotFound as i } from "./errors.js";
|
|
4
|
+
import { blockHasChanges as a } from "./trackChanges.js";
|
|
5
|
+
import { changedFields as o } from "./history.js";
|
|
6
|
+
import { crdtText as s, eq as c, id as l, table as u, text as d } from "@voltro/database";
|
|
7
|
+
import { tenant as f } from "@voltro/plugin-multitenancy/mixin";
|
|
8
|
+
import { crdtText as p, crdtTextEdit as m, decodeCrdtText as h, mergeCrdtStates as g } from "@voltro/local-first";
|
|
9
|
+
//#region src/draftTexts.ts
|
|
10
|
+
var _ = "cms_draft_texts", v = u(_, {
|
|
11
|
+
id: l({ prefix: "cdtx" }),
|
|
12
|
+
contentType: d().maxLength(64),
|
|
13
|
+
draftId: d(),
|
|
14
|
+
field: d(),
|
|
15
|
+
baseRevision: d(),
|
|
16
|
+
state: s()
|
|
17
|
+
}).with(f()).unique("cms_draft_texts_uq_field", [
|
|
18
|
+
"tenantId",
|
|
19
|
+
"draftId",
|
|
20
|
+
"field"
|
|
21
|
+
]), y = (e) => Object.entries(e.fields).filter(([t, n]) => t !== e.templates?.field && n.kind === "string" && (n.editorHint === "text" || n.editorHint === "textarea") && n.derived === void 0 && n.literals === void 0 && n.unique !== !0).map(([e]) => e), b = (e, t) => /* @__PURE__ */ new Set([...t, ...Object.entries(e.fields).filter(([, e]) => e.derived !== void 0 && t.has(e.derived.source)).map(([e]) => e)]), x = (e, t) => `${e}#${t}`, S = (e) => {
|
|
22
|
+
let t = e.indexOf("#");
|
|
23
|
+
return t <= 0 ? null : {
|
|
24
|
+
field: e.slice(0, t),
|
|
25
|
+
blockId: e.slice(t + 1)
|
|
26
|
+
};
|
|
27
|
+
}, C = /* @__PURE__ */ new Set([
|
|
28
|
+
"paragraph",
|
|
29
|
+
"heading",
|
|
30
|
+
"list",
|
|
31
|
+
"table"
|
|
32
|
+
]), w = (e) => {
|
|
33
|
+
let n = t(e ?? "");
|
|
34
|
+
return typeof n == "object" && n && Array.isArray(n.blocks) ? n : null;
|
|
35
|
+
}, T = (t, n) => Object.entries(t.fields).filter(([, e]) => e.kind === "richText").flatMap(([t]) => (w(n[t])?.blocks ?? []).filter((e) => C.has(e.type) && !a(e)).map((n) => ({
|
|
36
|
+
key: x(t, n.id),
|
|
37
|
+
field: t,
|
|
38
|
+
block: n,
|
|
39
|
+
markup: e(n)
|
|
40
|
+
}))), E = (t, r, i, o = {}) => {
|
|
41
|
+
let s = {}, c = [], l = (t, n) => {
|
|
42
|
+
let r = w(t)?.blocks.find((e) => e.id === n);
|
|
43
|
+
return r === void 0 ? void 0 : e(r);
|
|
44
|
+
};
|
|
45
|
+
for (let [u, d] of Object.entries(t.fields)) {
|
|
46
|
+
if (d.kind !== "richText" || r[u] === void 0 || r[u] === null) continue;
|
|
47
|
+
let t = w(r[u]);
|
|
48
|
+
if (t === null) continue;
|
|
49
|
+
let f = Object.keys(d.richText?.profile?.styles?.tokens ?? {}), p = !1, m = t.blocks.map((t) => {
|
|
50
|
+
let r = x(u, t.id), s = i.get(r);
|
|
51
|
+
if (s === void 0 || !C.has(t.type) || a(t)) return t;
|
|
52
|
+
let d = e(t), m = l(o.current?.[u], t.id), h = l(o.seen?.[u], t.id);
|
|
53
|
+
return o.seen !== void 0 && d !== h && s === m && m === h ? (c.push({
|
|
54
|
+
key: r,
|
|
55
|
+
markup: d
|
|
56
|
+
}), t) : s === d ? t : (p = !0, n(t, s, f));
|
|
57
|
+
});
|
|
58
|
+
p && (s[u] = {
|
|
59
|
+
...t,
|
|
60
|
+
blocks: m
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
values: s,
|
|
65
|
+
typedBefore: c
|
|
66
|
+
};
|
|
67
|
+
}, D = (e, t, n) => {
|
|
68
|
+
let r = (e) => {
|
|
69
|
+
let t = w(e);
|
|
70
|
+
return t === null ? e : t.blocks.map((e) => n.has(e.id) ? {
|
|
71
|
+
id: e.id,
|
|
72
|
+
type: e.type
|
|
73
|
+
} : e);
|
|
74
|
+
};
|
|
75
|
+
return JSON.stringify(r(e)) === JSON.stringify(r(t));
|
|
76
|
+
}, O = (e, t, n, r) => {
|
|
77
|
+
let i = [...r], a = b(e, new Set(i.filter((e) => S(e) === null))), s = /* @__PURE__ */ new Map();
|
|
78
|
+
for (let e of i) {
|
|
79
|
+
let t = S(e);
|
|
80
|
+
t !== null && s.set(t.field, /* @__PURE__ */ new Set([...s.get(t.field) ?? [], t.blockId]));
|
|
81
|
+
}
|
|
82
|
+
return o(e.fields, t, n).filter((e) => !a.has(e) && !(s.has(e) && D(t[e], n[e], s.get(e))));
|
|
83
|
+
}, k = (e, t, n) => e.query({
|
|
84
|
+
table: t,
|
|
85
|
+
predicate: n,
|
|
86
|
+
order: [],
|
|
87
|
+
take: void 0,
|
|
88
|
+
skip: void 0,
|
|
89
|
+
projection: void 0
|
|
90
|
+
}), A = async (e, t, n) => {
|
|
91
|
+
let [r] = await k(e, `${t.name}_drafts`, c("id", n));
|
|
92
|
+
if (r === void 0) throw new i({
|
|
93
|
+
contentType: t.name,
|
|
94
|
+
id: n,
|
|
95
|
+
stage: "draft"
|
|
96
|
+
});
|
|
97
|
+
return r;
|
|
98
|
+
}, j = (e, t) => k(e, _, c("draftId", t)), M = async (e, t, n) => {
|
|
99
|
+
let r = await A(e, t, n), i = String(r.revisionId), a = new Map((await j(e, n)).map((e) => [String(e.field), e])), o = r.tenantId !== void 0 && r.tenantId !== null ? { tenantId: r.tenantId } : {}, s = [...y(t).map((e) => ({
|
|
100
|
+
key: e,
|
|
101
|
+
value: typeof r[e] == "string" ? r[e] : ""
|
|
102
|
+
})), ...T(t, r).map((e) => ({
|
|
103
|
+
key: e.key,
|
|
104
|
+
value: e.markup
|
|
105
|
+
}))];
|
|
106
|
+
for (let { key: r, value: c } of s) {
|
|
107
|
+
let s = a.get(r);
|
|
108
|
+
s?.baseRevision !== i && (s !== void 0 && await e.delete(_, String(s.id)), await e.insertIgnore(_, {
|
|
109
|
+
contentType: t.name,
|
|
110
|
+
draftId: n,
|
|
111
|
+
field: r,
|
|
112
|
+
baseRevision: i,
|
|
113
|
+
state: p(c).encode(),
|
|
114
|
+
...o
|
|
115
|
+
}, { conflictColumns: [
|
|
116
|
+
"tenantId",
|
|
117
|
+
"draftId",
|
|
118
|
+
"field"
|
|
119
|
+
] }));
|
|
120
|
+
}
|
|
121
|
+
return j(e, n);
|
|
122
|
+
}, N = async (e, t, n) => {
|
|
123
|
+
let r = await j(e, n);
|
|
124
|
+
if (r.length === 0) return;
|
|
125
|
+
let i = new Set(r.map((e) => String(e.field))), a = await A(e, t, n), o = a.tenantId !== void 0 && a.tenantId !== null ? { tenantId: a.tenantId } : {};
|
|
126
|
+
for (let r of T(t, a)) i.has(r.key) || await e.insertIgnore(_, {
|
|
127
|
+
contentType: t.name,
|
|
128
|
+
draftId: n,
|
|
129
|
+
field: r.key,
|
|
130
|
+
baseRevision: String(a.revisionId),
|
|
131
|
+
state: p(r.markup).encode(),
|
|
132
|
+
...o
|
|
133
|
+
}, { conflictColumns: [
|
|
134
|
+
"tenantId",
|
|
135
|
+
"draftId",
|
|
136
|
+
"field"
|
|
137
|
+
] });
|
|
138
|
+
}, P = async (e, t, n) => {
|
|
139
|
+
let [r] = await k(e, _, c("id", t));
|
|
140
|
+
if (r === void 0) throw new i({
|
|
141
|
+
contentType: _,
|
|
142
|
+
id: t,
|
|
143
|
+
stage: "draft"
|
|
144
|
+
});
|
|
145
|
+
let a = r.state instanceof Uint8Array ? r.state : /* @__PURE__ */ new Uint8Array();
|
|
146
|
+
return await e.update("cms_draft_texts", t, { state: a.length === 0 ? n : g(a, n) }) ?? r;
|
|
147
|
+
}, F = async (e, t, n) => {
|
|
148
|
+
let [r] = await k(e, _, c("id", t));
|
|
149
|
+
if (r === void 0) return;
|
|
150
|
+
let i = p();
|
|
151
|
+
r.state instanceof Uint8Array && r.state.length > 0 && i.merge(r.state);
|
|
152
|
+
let a = m(i.toString(), n);
|
|
153
|
+
a !== null && (a.deleteLength > 0 && i.delete(a.index, a.deleteLength), a.insert !== "" && i.insert(a.index, a.insert), await P(e, t, i.encode()));
|
|
154
|
+
}, I = async (e, t) => {
|
|
155
|
+
let n = (await j(e, String(t.id))).filter((e) => e.baseRevision === t.revisionId);
|
|
156
|
+
return {
|
|
157
|
+
values: new Map(n.map((e) => [String(e.field), e.state instanceof Uint8Array && e.state.length > 0 ? h(e.state) : ""])),
|
|
158
|
+
rows: n
|
|
159
|
+
};
|
|
160
|
+
}, L = async (e, t, n) => {
|
|
161
|
+
for (let r of t) await e.update(_, String(r.id), { baseRevision: n });
|
|
162
|
+
}, R = [i], z = (...e) => r(() => I(...e), ...R), B = (...e) => r(() => M(...e), ...R), V = (...e) => r(() => j(...e), ...R), H = (...e) => r(() => L(...e), ...R), U = (...e) => r(() => P(...e), ...R);
|
|
163
|
+
//#endregion
|
|
164
|
+
export { _ as CMS_DRAFT_TEXTS_TABLE, O as changedApartFromShared, v as cmsDraftTextsTable, y as collaborativeFields, I as liveDraftTexts, z as liveDraftTextsEffect, b as movedTogether, M as openDraftTexts, B as openDraftTextsEffect, N as openNewBlockTexts, j as readDraftTexts, V as readDraftTextsEffect, L as rebaseDraftTexts, H as rebaseDraftTextsEffect, S as richBlockOfKey, x as richBlockTextKey, F as setDraftText, T as sharedRichBlocks, P as typeDraftText, U as typeDraftTextEffect, E as withSharedBlocks };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { ContentNotFound as t } from "./errors.js";
|
|
3
|
+
import { usedBy as n } from "./references.js";
|
|
4
|
+
import { archive as r } from "./write.js";
|
|
5
|
+
import { and as i, eq as a, neq as o } from "@voltro/database";
|
|
6
|
+
//#region src/duplicates.ts
|
|
7
|
+
var s = async (e, t, n, r) => {
|
|
8
|
+
let s = await e.query({
|
|
9
|
+
table: `${t.name}_drafts`,
|
|
10
|
+
predicate: i(a("site", n.site), a("environment", n.environment), a("locale", n.locale), o("status", "archived")),
|
|
11
|
+
order: [{
|
|
12
|
+
column: "createdAt",
|
|
13
|
+
direction: "asc"
|
|
14
|
+
}],
|
|
15
|
+
take: void 0,
|
|
16
|
+
skip: void 0,
|
|
17
|
+
projection: void 0
|
|
18
|
+
}), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
|
|
19
|
+
for (let e of s) {
|
|
20
|
+
let t = e[r.field];
|
|
21
|
+
if (typeof t != "string" || t === "") continue;
|
|
22
|
+
c.has(t) || c.set(t, r.fingerprint(t).catch(() => null));
|
|
23
|
+
let n = await c.get(t);
|
|
24
|
+
if (n === null) continue;
|
|
25
|
+
let i = l.get(n) ?? [];
|
|
26
|
+
i.push({
|
|
27
|
+
id: String(e.id),
|
|
28
|
+
documentId: String(e.documentId),
|
|
29
|
+
title: String(e[r.titleField ?? "title"] ?? ""),
|
|
30
|
+
status: String(e.status)
|
|
31
|
+
}), l.set(n, i);
|
|
32
|
+
}
|
|
33
|
+
return [...l].filter(([, e]) => e.length > 1).map(([e, t]) => ({
|
|
34
|
+
fingerprint: e,
|
|
35
|
+
documents: t
|
|
36
|
+
}));
|
|
37
|
+
}, c = async (e, o, s, c) => {
|
|
38
|
+
if (c.copyId === c.keepId) return {
|
|
39
|
+
ok: !1,
|
|
40
|
+
reason: "notDuplicate"
|
|
41
|
+
};
|
|
42
|
+
let l = async (n) => {
|
|
43
|
+
let [r] = await e.query({
|
|
44
|
+
table: `${o.name}_drafts`,
|
|
45
|
+
predicate: i(a("id", n), a("site", s.site), a("environment", s.environment), a("locale", s.locale)),
|
|
46
|
+
order: [],
|
|
47
|
+
take: 1,
|
|
48
|
+
skip: void 0,
|
|
49
|
+
projection: void 0
|
|
50
|
+
});
|
|
51
|
+
if (r === void 0) throw new t({
|
|
52
|
+
contentType: o.name,
|
|
53
|
+
id: n,
|
|
54
|
+
stage: "draft"
|
|
55
|
+
});
|
|
56
|
+
return r;
|
|
57
|
+
}, [u, d] = [await l(c.copyId), await l(c.keepId)], [f, p] = [u[c.field], d[c.field]];
|
|
58
|
+
if (typeof f != "string" || typeof p != "string") return {
|
|
59
|
+
ok: !1,
|
|
60
|
+
reason: "notDuplicate"
|
|
61
|
+
};
|
|
62
|
+
let [m, h] = [await c.fingerprint(f), await c.fingerprint(p)];
|
|
63
|
+
if (m === null || m !== h) return {
|
|
64
|
+
ok: !1,
|
|
65
|
+
reason: "notDuplicate"
|
|
66
|
+
};
|
|
67
|
+
let g = await n(e, {
|
|
68
|
+
type: o.name,
|
|
69
|
+
documentId: String(u.documentId)
|
|
70
|
+
}, s);
|
|
71
|
+
return g.length > 0 ? {
|
|
72
|
+
ok: !1,
|
|
73
|
+
reason: "inUse",
|
|
74
|
+
usedBy: g
|
|
75
|
+
} : (await r(e, o, c.copyId, s), { ok: !0 });
|
|
76
|
+
}, l = (...t) => e(() => s(...t)), u = (...n) => e(() => c(...n), t);
|
|
77
|
+
//#endregion
|
|
78
|
+
export { s as duplicateGroups, l as duplicateGroupsEffect, c as retireDuplicate, u as retireDuplicateEffect };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
//#region src/edgePurge.ts
|
|
2
|
+
var e = /^[\w:.\-/@]{1,256}$/, t = (e) => {
|
|
3
|
+
if (e.length > 2048 || /[\s]/.test(e)) return null;
|
|
4
|
+
try {
|
|
5
|
+
let t = new URL(e);
|
|
6
|
+
return t.protocol === "https:" || t.protocol === "http:" ? t.toString() : null;
|
|
7
|
+
} catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
}, n = (n, i, a, o = []) => {
|
|
11
|
+
let s = [...new Set(a.filter((t) => e.test(t)))], c = [...new Set(o.map(t).filter((e) => e !== null))];
|
|
12
|
+
if (i.target === "") return [];
|
|
13
|
+
let l = i.token === null || i.token === "" ? {} : { authorization: `Bearer ${i.token}` };
|
|
14
|
+
switch (n) {
|
|
15
|
+
case "cloudflare": {
|
|
16
|
+
let e = `https://api.cloudflare.com/client/v4/zones/${encodeURIComponent(i.target)}/purge_cache`, t = (t) => ({
|
|
17
|
+
url: e,
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
"content-type": "application/json",
|
|
21
|
+
...l
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify(t)
|
|
24
|
+
});
|
|
25
|
+
return [...r(s).map((e) => t({ tags: e })), ...r(c).map((e) => t({ files: e }))];
|
|
26
|
+
}
|
|
27
|
+
case "fastly": {
|
|
28
|
+
let e = i.token === null || i.token === "" ? {} : { "fastly-key": i.token };
|
|
29
|
+
return [...s.length === 0 ? [] : [{
|
|
30
|
+
url: `https://api.fastly.com/service/${encodeURIComponent(i.target)}/purge`,
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"surrogate-key": s.join(" "),
|
|
34
|
+
...e
|
|
35
|
+
}
|
|
36
|
+
}], ...c.map((t) => ({
|
|
37
|
+
url: `https://api.fastly.com/purge/${t.replace(/^https?:\/\//, "")}`,
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: { ...e }
|
|
40
|
+
}))];
|
|
41
|
+
}
|
|
42
|
+
case "webhook": {
|
|
43
|
+
let e;
|
|
44
|
+
try {
|
|
45
|
+
e = new URL(i.target);
|
|
46
|
+
} catch {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
return e.protocol !== "https:" && e.hostname !== "localhost" && e.hostname !== "127.0.0.1" || s.length === 0 && c.length === 0 ? [] : [{
|
|
50
|
+
url: e.toString(),
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: {
|
|
53
|
+
"content-type": "application/json",
|
|
54
|
+
...l
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(c.length === 0 ? { tags: s } : {
|
|
57
|
+
tags: s,
|
|
58
|
+
urls: c
|
|
59
|
+
})
|
|
60
|
+
}];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}, r = (e) => {
|
|
64
|
+
let t = [];
|
|
65
|
+
for (let n = 0; n < e.length; n += 30) t.push(e.slice(n, n + 30));
|
|
66
|
+
return t;
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { n as edgePurgeRequests };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { changedFields as e } from "./history.js";
|
|
2
|
+
//#region src/editHistory.ts
|
|
3
|
+
var t = (e, t, n) => (Array.isArray(e) ? e : []).flatMap((e) => {
|
|
4
|
+
let r = e;
|
|
5
|
+
return typeof r == "object" && r && typeof r[t] == "string" ? [{
|
|
6
|
+
id: r[t],
|
|
7
|
+
name: String(r[n] ?? ""),
|
|
8
|
+
raw: JSON.stringify(r)
|
|
9
|
+
}] : [];
|
|
10
|
+
}), n = (e, t, n, r, i) => {
|
|
11
|
+
let a = new Map(e.map((e, t) => [e.id, t])), o = new Map(t.map((e, t) => [e.id, t])), s = t.find((e) => !a.has(e.id));
|
|
12
|
+
if (s !== void 0) return {
|
|
13
|
+
label: i.add(r(s)),
|
|
14
|
+
key: `add:${n}:${s.id}`
|
|
15
|
+
};
|
|
16
|
+
let c = e.find((e) => !o.has(e.id));
|
|
17
|
+
if (c !== void 0) return {
|
|
18
|
+
label: i.remove(r(c)),
|
|
19
|
+
key: `remove:${n}:${c.id}`
|
|
20
|
+
};
|
|
21
|
+
let l = t.flatMap((t, n) => e[n]?.id === t.id ? [] : [n]);
|
|
22
|
+
if (l.length === 2 && l[1] === l[0] + 1 && t[l[0]]?.id === e[l[1]]?.id) {
|
|
23
|
+
let [t, a] = [e[l[0]], e[l[1]]];
|
|
24
|
+
return {
|
|
25
|
+
label: i.swap(r(t), r(a)),
|
|
26
|
+
key: `move:${n}:${t.id}:${a.id}:${l[0]}`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
let u = t.find((e, t) => (a.get(e.id) ?? t) > t);
|
|
30
|
+
if (u !== void 0) return {
|
|
31
|
+
label: i.moveUp(r(u)),
|
|
32
|
+
key: `move:${n}:${u.id}:${o.get(u.id)}`
|
|
33
|
+
};
|
|
34
|
+
let d = t.find((e, t) => (a.get(e.id) ?? t) < t);
|
|
35
|
+
if (d !== void 0) return {
|
|
36
|
+
label: i.moveDown(r(d)),
|
|
37
|
+
key: `move:${n}:${d.id}:${o.get(d.id)}`
|
|
38
|
+
};
|
|
39
|
+
let f = t.find((t) => t.raw !== e[a.get(t.id) ?? -1]?.raw);
|
|
40
|
+
return {
|
|
41
|
+
label: i.edit(f === void 0 ? i.fieldLabel(n) : r(f)),
|
|
42
|
+
key: `edit:${n}${f === void 0 ? "" : `:${f.id}`}`
|
|
43
|
+
};
|
|
44
|
+
}, r = (r, i, a, o) => {
|
|
45
|
+
let s = e(r, i, a);
|
|
46
|
+
if (s.length === 0) return null;
|
|
47
|
+
if (s.length > 1) return {
|
|
48
|
+
label: o.edit(s.map(o.fieldLabel).join(", ")),
|
|
49
|
+
key: `edit:${s.join(",")}`
|
|
50
|
+
};
|
|
51
|
+
let c = s[0], l = r[c];
|
|
52
|
+
if (l?.editorHint === "components") return n(t(i[c], "instanceId", "componentId"), t(a[c], "instanceId", "componentId"), c, (e) => o.componentLabel(e.name), o);
|
|
53
|
+
if (l?.editorHint === "richText") {
|
|
54
|
+
let e = (e) => t(e?.blocks, "id", "type"), r = n(e(i[c]), e(a[c]), c, (e) => o.blockLabel(e.name), o);
|
|
55
|
+
return r.key.startsWith("edit:") ? {
|
|
56
|
+
label: r.label,
|
|
57
|
+
key: `edit:${c}`
|
|
58
|
+
} : r;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
label: o.edit(o.fieldLabel(c)),
|
|
62
|
+
key: `edit:${c}`
|
|
63
|
+
};
|
|
64
|
+
}, i = {
|
|
65
|
+
past: [],
|
|
66
|
+
future: []
|
|
67
|
+
}, a = (e, t, n, r, i = {}) => {
|
|
68
|
+
let a = e.past[e.past.length - 1];
|
|
69
|
+
return a !== void 0 && a.key === n.key && r - a.at <= (i.mergeMs ?? 1500) ? {
|
|
70
|
+
past: [...e.past.slice(0, -1), {
|
|
71
|
+
...a,
|
|
72
|
+
label: n.label,
|
|
73
|
+
at: r
|
|
74
|
+
}],
|
|
75
|
+
future: []
|
|
76
|
+
} : {
|
|
77
|
+
past: [...e.past, {
|
|
78
|
+
values: t,
|
|
79
|
+
label: n.label,
|
|
80
|
+
key: n.key,
|
|
81
|
+
at: r
|
|
82
|
+
}].slice(-(i.limit ?? 100)),
|
|
83
|
+
future: []
|
|
84
|
+
};
|
|
85
|
+
}, o = (e, t) => {
|
|
86
|
+
let n = e.past[e.past.length - 1];
|
|
87
|
+
return n === void 0 ? null : {
|
|
88
|
+
values: n.values,
|
|
89
|
+
label: n.label,
|
|
90
|
+
history: {
|
|
91
|
+
past: e.past.slice(0, -1),
|
|
92
|
+
future: [{
|
|
93
|
+
...n,
|
|
94
|
+
values: t
|
|
95
|
+
}, ...e.future]
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}, s = (e, t) => {
|
|
99
|
+
let n = e.future[0];
|
|
100
|
+
return n === void 0 ? null : {
|
|
101
|
+
values: n.values,
|
|
102
|
+
label: n.label,
|
|
103
|
+
history: {
|
|
104
|
+
past: [...e.past, {
|
|
105
|
+
...n,
|
|
106
|
+
values: t
|
|
107
|
+
}],
|
|
108
|
+
future: e.future.slice(1)
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
//#endregion
|
|
113
|
+
export { i as EMPTY_EDIT_HISTORY, r as describeEdit, a as recordEdit, s as redoEdit, o as undoEdit };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Effect as e } from "effect";
|
|
2
|
+
//#region src/effectForm.ts
|
|
3
|
+
var t = (t, ...n) => {
|
|
4
|
+
let r = (e) => n.some((t) => e instanceof t);
|
|
5
|
+
return e.tryPromise({
|
|
6
|
+
try: t,
|
|
7
|
+
catch: (e) => e
|
|
8
|
+
}).pipe(e.catch((t) => r(t) ? e.fail(t) : e.die(t)));
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { t as asTyped };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { indexForSearch as t } from "./search.js";
|
|
3
|
+
import { recordPaths as n } from "./redirects.js";
|
|
4
|
+
import { hasReferenceFields as r, writeReferences as i } from "./references.js";
|
|
5
|
+
import { writeAvailability as a } from "./availability.js";
|
|
6
|
+
import { newVariantId as o, pickDeclared as s, scopeColumns as c, writeRevision as l } from "./write.js";
|
|
7
|
+
import { and as u, eq as d, neq as f } from "@voltro/database";
|
|
8
|
+
//#region src/environments.ts
|
|
9
|
+
var p = (e, t, n, r) => e.query({
|
|
10
|
+
table: t,
|
|
11
|
+
predicate: u(d("site", n), d("environment", r), f("status", "archived")),
|
|
12
|
+
order: [{
|
|
13
|
+
column: "id",
|
|
14
|
+
direction: "asc"
|
|
15
|
+
}],
|
|
16
|
+
take: void 0,
|
|
17
|
+
skip: void 0,
|
|
18
|
+
projection: void 0
|
|
19
|
+
}), m = async (e, u, d) => {
|
|
20
|
+
if (d.from === d.to) return {
|
|
21
|
+
ok: !1,
|
|
22
|
+
reason: "sameEnvironment",
|
|
23
|
+
variants: 0
|
|
24
|
+
};
|
|
25
|
+
let f = 0;
|
|
26
|
+
for (let t of u) f += (await p(e, `${t.name}_drafts`, d.site, d.to)).length;
|
|
27
|
+
if (f > 0) return {
|
|
28
|
+
ok: !1,
|
|
29
|
+
reason: "targetNotEmpty",
|
|
30
|
+
variants: f
|
|
31
|
+
};
|
|
32
|
+
let m = 0, h = 0;
|
|
33
|
+
for (let f of u) {
|
|
34
|
+
let u = await p(e, `${f.name}_drafts`, d.site, d.from), g = new Map((await p(e, `${f.name}_published`, d.site, d.from)).map((e) => [String(e.id), e])), _ = /* @__PURE__ */ new Set();
|
|
35
|
+
for (let n of u) {
|
|
36
|
+
let u = {
|
|
37
|
+
site: d.site,
|
|
38
|
+
environment: d.to,
|
|
39
|
+
locale: String(n.locale)
|
|
40
|
+
}, p = String(n.documentId), v = n.tenantId, y = o(f), b = g.get(String(n.id)), x = s(f, n), S = 0, C;
|
|
41
|
+
b !== void 0 && (C = await l(e, f, p, ++S, s(f, b), u, v));
|
|
42
|
+
let w = b !== void 0 && b.revisionId === n.revisionId && C !== void 0 ? C : await l(e, f, p, ++S, x, u, v), T = v == null ? {} : { tenantId: v }, E = await e.insert(`${f.name}_drafts`, {
|
|
43
|
+
...x,
|
|
44
|
+
id: y,
|
|
45
|
+
documentId: p,
|
|
46
|
+
...c(u),
|
|
47
|
+
status: n.status,
|
|
48
|
+
revisionId: w.id,
|
|
49
|
+
revision: w.number,
|
|
50
|
+
...T
|
|
51
|
+
});
|
|
52
|
+
if (await t(e, f, E, u, "draft"), r(f) && await i(e, f, E, u, "draft"), m++, b !== void 0 && C !== void 0) {
|
|
53
|
+
let n = await e.insert(`${f.name}_published`, {
|
|
54
|
+
...s(f, b),
|
|
55
|
+
id: y,
|
|
56
|
+
documentId: p,
|
|
57
|
+
...c(u),
|
|
58
|
+
status: "published",
|
|
59
|
+
revisionId: C.id,
|
|
60
|
+
revision: C.number,
|
|
61
|
+
...T
|
|
62
|
+
});
|
|
63
|
+
await i(e, f, n, u), await a(e, f, n, u), await t(e, f, n, u, "published"), _.add(`${u.locale}\u0000${String(v ?? "")}`), h++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (let t of _) {
|
|
67
|
+
let [r, i] = t.split("\0");
|
|
68
|
+
await n(e, f, {
|
|
69
|
+
site: d.site,
|
|
70
|
+
environment: d.to,
|
|
71
|
+
locale: r
|
|
72
|
+
}, i === "" ? void 0 : i);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
ok: !0,
|
|
77
|
+
variants: m,
|
|
78
|
+
published: h
|
|
79
|
+
};
|
|
80
|
+
}, h = (e) => JSON.stringify(e, (e, t) => typeof t == "object" && t && !Array.isArray(t) && !(t instanceof Date) ? Object.fromEntries(Object.entries(t).sort(([e], [t]) => e < t ? -1 : 1)) : t), g = (e) => {
|
|
81
|
+
for (let t of [
|
|
82
|
+
"title",
|
|
83
|
+
"name",
|
|
84
|
+
"slug"
|
|
85
|
+
]) if (typeof e[t] == "string" && e[t] !== "") return e[t];
|
|
86
|
+
return String(e.documentId);
|
|
87
|
+
}, _ = async (e, t, n) => {
|
|
88
|
+
let r = [];
|
|
89
|
+
for (let i of t) {
|
|
90
|
+
let t = async (t) => new Set((await p(e, `${i.name}_drafts`, n.site, t)).map((e) => String(e.documentId))), [a, o] = [await t(n.from), await t(n.to)], c = async (t) => new Map((await p(e, `${i.name}_published`, n.site, t)).map((e) => [`${String(e.documentId)}\u0000${String(e.locale)}`, e])), [l, u] = [await c(n.from), await c(n.to)], d = [];
|
|
91
|
+
for (let [e, t] of l) {
|
|
92
|
+
let n = u.get(e);
|
|
93
|
+
n !== void 0 && h(s(i, t)) !== h(s(i, n)) && d.push({
|
|
94
|
+
documentId: String(t.documentId),
|
|
95
|
+
locale: String(t.locale),
|
|
96
|
+
title: g(n)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
r.push({
|
|
100
|
+
contentType: i.name,
|
|
101
|
+
onlyInFrom: [...a].filter((e) => !o.has(e)).length,
|
|
102
|
+
onlyInTo: [...o].filter((e) => !a.has(e)).length,
|
|
103
|
+
differing: d
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return r;
|
|
107
|
+
}, v = (...t) => e(() => _(...t)), y = (...t) => e(() => m(...t));
|
|
108
|
+
//#endregion
|
|
109
|
+
export { _ as compareEnvironments, v as compareEnvironmentsEffect, m as copyEnvironment, y as copyEnvironmentEffect };
|