@voltro/cms 0.84.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 +1215 -0
- package/THIRD-PARTY-NOTICES.md +118 -600
- 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 +2266 -170
- package/dist/index.js +73 -3947
- 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.d.ts +927 -131
- 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 +6 -6
- package/dist/extensionManifest-BK3ZcL2P.js +0 -2782
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { hasMark as e, inlineFromDom as t, inlineHtml as n, replaceText as r, toggleMark as i } from "./richInline.js";
|
|
2
|
+
import { createElement as a, useEffect as o, useRef as s } from "react";
|
|
3
|
+
//#region src/RichTextSurface.tsx
|
|
4
|
+
var c = (e, t, n) => {
|
|
5
|
+
let r = 0, i = null, a = (e) => {
|
|
6
|
+
if (i === null) {
|
|
7
|
+
if (e === t && e.nodeType !== 3) {
|
|
8
|
+
for (let t = 0; t < n && t < e.childNodes.length; t++) r += l(e.childNodes[t]);
|
|
9
|
+
i = r;
|
|
10
|
+
} else if (e.nodeType === 3) {
|
|
11
|
+
if (e === t) {
|
|
12
|
+
i = r + n;
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
r += (e.textContent ?? "").length;
|
|
16
|
+
} else if (e.nodeName === "BR") r += 1;
|
|
17
|
+
else for (let t of Array.from(e.childNodes)) a(t);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return a(e), i ?? r;
|
|
21
|
+
}, l = (e) => e.nodeType === 3 ? (e.textContent ?? "").length : e.nodeName === "BR" ? 1 : Array.from(e.childNodes).reduce((e, t) => e + l(t), 0), u = (e, t) => {
|
|
22
|
+
let n = 0, r = null, i = (e) => {
|
|
23
|
+
if (r === null) {
|
|
24
|
+
if (e.nodeType === 3) {
|
|
25
|
+
let i = (e.textContent ?? "").length;
|
|
26
|
+
if (t <= n + i) {
|
|
27
|
+
r = [e, t - n];
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
n += i;
|
|
31
|
+
} else if (e.nodeName === "BR") {
|
|
32
|
+
if (t <= n) {
|
|
33
|
+
r = [e.parentNode, Array.from(e.parentNode.childNodes).indexOf(e)];
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
n += 1;
|
|
37
|
+
} else for (let t of Array.from(e.childNodes)) i(t);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return i(e), r ?? [e, e.childNodes.length];
|
|
41
|
+
}, d = (e) => {
|
|
42
|
+
let t = e.ownerDocument.getSelection();
|
|
43
|
+
if (t === null || t.rangeCount === 0) return null;
|
|
44
|
+
let n = t.getRangeAt(0);
|
|
45
|
+
return !e.contains(n.startContainer) || !e.contains(n.endContainer) ? null : [c(e, n.startContainer, n.startOffset), c(e, n.endContainer, n.endOffset)];
|
|
46
|
+
}, f = (e, t, n) => {
|
|
47
|
+
let r = e.ownerDocument.getSelection();
|
|
48
|
+
if (r === null) return;
|
|
49
|
+
let i = e.ownerDocument.createRange(), [a, o] = u(e, t), [s, c] = u(e, n);
|
|
50
|
+
i.setStart(a, o), i.setEnd(s, c), r.removeAllRanges(), r.addRange(i);
|
|
51
|
+
}, p = (c) => {
|
|
52
|
+
let { id: l, labelledBy: u, content: p, onChange: m, words: h } = c, g = s(null), _ = s("");
|
|
53
|
+
o(() => {
|
|
54
|
+
let e = g.current;
|
|
55
|
+
if (e === null) return;
|
|
56
|
+
let t = JSON.stringify(p);
|
|
57
|
+
if (t === _.current) return;
|
|
58
|
+
_.current = t;
|
|
59
|
+
let r = e.ownerDocument.activeElement === e ? d(e) : null, i = e.textContent ?? "";
|
|
60
|
+
if (e.innerHTML = n(p), r === null) return;
|
|
61
|
+
let a = e.textContent ?? "", o = 0;
|
|
62
|
+
for (; o < i.length && o < a.length && i[o] === a[o];) o += 1;
|
|
63
|
+
let s = (e) => Math.min(a.length, e <= o ? e : e + a.length - i.length);
|
|
64
|
+
f(e, s(r[0]), s(r[1]));
|
|
65
|
+
}, [p]);
|
|
66
|
+
let v = (e, t) => {
|
|
67
|
+
let r = g.current;
|
|
68
|
+
r !== null && (_.current = JSON.stringify(e), r.innerHTML = n(e), t !== void 0 && f(r, t[0], t[1]), m(e));
|
|
69
|
+
}, y = () => {
|
|
70
|
+
let e = g.current;
|
|
71
|
+
if (e === null) return;
|
|
72
|
+
let n = t(e);
|
|
73
|
+
_.current = JSON.stringify(n), m(n);
|
|
74
|
+
}, b = (e) => {
|
|
75
|
+
let n = g.current, r = n === null ? null : d(n);
|
|
76
|
+
r !== null && r[0] !== r[1] && v(i(t(n), r[0], r[1], e), r);
|
|
77
|
+
}, x = (e) => {
|
|
78
|
+
let n = {
|
|
79
|
+
b: "bold",
|
|
80
|
+
i: "italic",
|
|
81
|
+
u: "underline"
|
|
82
|
+
}[e.key.toLowerCase()];
|
|
83
|
+
if ((e.ctrlKey || e.metaKey) && n !== void 0) e.preventDefault(), b(n);
|
|
84
|
+
else if (e.key === "Enter") {
|
|
85
|
+
if (e.preventDefault(), !e.shiftKey || g.current === null) return;
|
|
86
|
+
let n = d(g.current);
|
|
87
|
+
n !== null && v(r(t(g.current), n[0], n[1], "\n"), [n[0] + 1, n[0] + 1]);
|
|
88
|
+
}
|
|
89
|
+
}, S = (e) => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
let n = g.current, i = e.clipboardData?.getData("text/plain") ?? "", a = n === null ? null : d(n);
|
|
92
|
+
a !== null && i !== "" && v(r(t(n), a[0], a[1], i), [a[0] + i.length, a[0] + i.length]);
|
|
93
|
+
}, C = (t) => {
|
|
94
|
+
let n = g.current, r = n === null ? null : d(n);
|
|
95
|
+
return r !== null && e(p, r[0], r[1], t);
|
|
96
|
+
}, w = (e) => e.preventDefault();
|
|
97
|
+
return a("div", { "data-cms-rich-surface": !0 }, a("div", {
|
|
98
|
+
role: "toolbar",
|
|
99
|
+
"aria-controls": l,
|
|
100
|
+
"data-cms-rich-marks": !0
|
|
101
|
+
}, a("button", {
|
|
102
|
+
type: "button",
|
|
103
|
+
onMouseDown: w,
|
|
104
|
+
onClick: () => b("bold"),
|
|
105
|
+
"aria-pressed": C("bold"),
|
|
106
|
+
"aria-label": h.bold
|
|
107
|
+
}, a("strong", null, "B")), a("button", {
|
|
108
|
+
type: "button",
|
|
109
|
+
onMouseDown: w,
|
|
110
|
+
onClick: () => b("italic"),
|
|
111
|
+
"aria-pressed": C("italic"),
|
|
112
|
+
"aria-label": h.italic
|
|
113
|
+
}, a("em", null, "I")), a("button", {
|
|
114
|
+
type: "button",
|
|
115
|
+
onMouseDown: w,
|
|
116
|
+
onClick: () => b("underline"),
|
|
117
|
+
"aria-pressed": C("underline"),
|
|
118
|
+
"aria-label": h.underline
|
|
119
|
+
}, a("u", null, "U"))), a("div", {
|
|
120
|
+
id: l,
|
|
121
|
+
ref: g,
|
|
122
|
+
role: "textbox",
|
|
123
|
+
"aria-multiline": !0,
|
|
124
|
+
"aria-labelledby": u,
|
|
125
|
+
contentEditable: !0,
|
|
126
|
+
suppressContentEditableWarning: !0,
|
|
127
|
+
tabIndex: 0,
|
|
128
|
+
onInput: y,
|
|
129
|
+
onKeyDown: x,
|
|
130
|
+
onPaste: S,
|
|
131
|
+
"data-cms-rich-text": !0
|
|
132
|
+
}));
|
|
133
|
+
};
|
|
134
|
+
//#endregion
|
|
135
|
+
export { p as RichTextSurface, d as selectionIn };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { ContentIdConflict as t, ContentNotFound as n, ContentValidationFailed as r, RevisionMismatch as i } from "./errors.js";
|
|
3
|
+
import { saveDraft as a } from "./write.js";
|
|
4
|
+
import { settleAiOperation as o } from "./aiOperations.js";
|
|
5
|
+
import { and as s, eq as c, id as l, json as u, table as d, text as f, timestamp as p } from "@voltro/database";
|
|
6
|
+
import { tenant as m } from "@voltro/plugin-multitenancy/mixin";
|
|
7
|
+
//#region src/aiCandidates.ts
|
|
8
|
+
var h = "cms_ai_candidates", g = d(h, {
|
|
9
|
+
id: l({ prefix: "caic" }),
|
|
10
|
+
contentType: f().maxLength(64),
|
|
11
|
+
variantId: f().maxLength(64),
|
|
12
|
+
baseRevisionId: f().maxLength(64).nullable(),
|
|
13
|
+
operationId: f().maxLength(64).nullable(),
|
|
14
|
+
suggestedBy: f().maxLength(64).nullable(),
|
|
15
|
+
values: u(),
|
|
16
|
+
status: f().oneOf([
|
|
17
|
+
"open",
|
|
18
|
+
"adopted",
|
|
19
|
+
"partial",
|
|
20
|
+
"discarded"
|
|
21
|
+
]),
|
|
22
|
+
adoptedUnits: u().nullable(),
|
|
23
|
+
adoptedRevisionId: f().maxLength(64).nullable(),
|
|
24
|
+
decidedBy: f().maxLength(64).nullable(),
|
|
25
|
+
decidedAt: p().nullable()
|
|
26
|
+
}).with(m()).index("cms_ai_candidates_by_variant", ["contentType", "variantId"]), _ = (e, t) => JSON.stringify(e ?? null) === JSON.stringify(t ?? null), v = (e, t, n) => {
|
|
27
|
+
let r = [];
|
|
28
|
+
for (let [i, a] of Object.entries(e.fields)) {
|
|
29
|
+
if (!(i in n)) continue;
|
|
30
|
+
if (a.kind !== "components") {
|
|
31
|
+
_(t[i], n[i]) || r.push({
|
|
32
|
+
key: i,
|
|
33
|
+
kind: "field",
|
|
34
|
+
field: i,
|
|
35
|
+
before: t[i] ?? null,
|
|
36
|
+
after: n[i]
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
let e = Array.isArray(t[i]) ? t[i] : [], o = Array.isArray(n[i]) ? n[i] : [], s = 0;
|
|
41
|
+
for (let t of o) {
|
|
42
|
+
let n = typeof t.instanceId == "string" ? e.find((e) => e.instanceId === t.instanceId) : void 0;
|
|
43
|
+
n === void 0 ? r.push({
|
|
44
|
+
key: `${i}+${s++}`,
|
|
45
|
+
kind: "addedSection",
|
|
46
|
+
field: i,
|
|
47
|
+
before: null,
|
|
48
|
+
after: t
|
|
49
|
+
}) : _(n.props, t.props) || r.push({
|
|
50
|
+
key: `${i}[${String(t.instanceId)}]`,
|
|
51
|
+
kind: "section",
|
|
52
|
+
field: i,
|
|
53
|
+
before: n,
|
|
54
|
+
after: t
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return r;
|
|
59
|
+
}, y = (e) => e instanceof Date ? e : new Date(String(e)), b = (e) => typeof e == "string" && e !== "" ? e : null, x = (e) => ({
|
|
60
|
+
id: String(e.id),
|
|
61
|
+
contentType: String(e.contentType),
|
|
62
|
+
variantId: String(e.variantId),
|
|
63
|
+
baseRevisionId: b(e.baseRevisionId),
|
|
64
|
+
operationId: b(e.operationId),
|
|
65
|
+
suggestedBy: b(e.suggestedBy),
|
|
66
|
+
values: e.values ?? {},
|
|
67
|
+
status: [
|
|
68
|
+
"open",
|
|
69
|
+
"adopted",
|
|
70
|
+
"partial",
|
|
71
|
+
"discarded"
|
|
72
|
+
].find((t) => t === e.status) ?? "open",
|
|
73
|
+
adoptedUnits: e.adoptedUnits ?? [],
|
|
74
|
+
adoptedRevisionId: b(e.adoptedRevisionId),
|
|
75
|
+
decidedBy: b(e.decidedBy),
|
|
76
|
+
createdAt: y(e.createdAt ?? 0)
|
|
77
|
+
}), S = async (e, t, n, r) => (await e.query({
|
|
78
|
+
table: `${t.name}_drafts`,
|
|
79
|
+
predicate: s(c("id", n), c("site", r.site), c("environment", r.environment), c("locale", r.locale)),
|
|
80
|
+
order: [],
|
|
81
|
+
take: 1,
|
|
82
|
+
skip: void 0,
|
|
83
|
+
projection: void 0
|
|
84
|
+
}))[0], C = async (e, t, n, r, i) => {
|
|
85
|
+
let a = await S(e, t, n, r);
|
|
86
|
+
if (a === void 0) return {
|
|
87
|
+
ok: !1,
|
|
88
|
+
reason: "notFound"
|
|
89
|
+
};
|
|
90
|
+
let o = Object.fromEntries(Object.entries(i.values).filter(([e]) => e in t.fields && !t.derivedFields.includes(e)));
|
|
91
|
+
if (v(t, a, o).length === 0) return {
|
|
92
|
+
ok: !1,
|
|
93
|
+
reason: "empty"
|
|
94
|
+
};
|
|
95
|
+
let s = await e.insert(h, {
|
|
96
|
+
contentType: t.name,
|
|
97
|
+
variantId: n,
|
|
98
|
+
baseRevisionId: b(a.revisionId),
|
|
99
|
+
operationId: i.operationId ?? null,
|
|
100
|
+
suggestedBy: i.suggestedBy ?? null,
|
|
101
|
+
values: o,
|
|
102
|
+
status: "open",
|
|
103
|
+
adoptedUnits: null,
|
|
104
|
+
adoptedRevisionId: null,
|
|
105
|
+
decidedBy: null,
|
|
106
|
+
decidedAt: null,
|
|
107
|
+
...a.tenantId !== void 0 && a.tenantId !== null ? { tenantId: a.tenantId } : {}
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
ok: !0,
|
|
111
|
+
id: String(s.id)
|
|
112
|
+
};
|
|
113
|
+
}, w = async (e, t, n, r, i, s = /* @__PURE__ */ new Date()) => {
|
|
114
|
+
let [l] = await e.query({
|
|
115
|
+
table: h,
|
|
116
|
+
predicate: c("id", n),
|
|
117
|
+
order: [],
|
|
118
|
+
take: 1,
|
|
119
|
+
skip: void 0,
|
|
120
|
+
projection: void 0
|
|
121
|
+
});
|
|
122
|
+
if (l === void 0 || l.contentType !== t.name) return {
|
|
123
|
+
ok: !1,
|
|
124
|
+
reason: "notFound"
|
|
125
|
+
};
|
|
126
|
+
let u = x(l);
|
|
127
|
+
if (u.status !== "open") return {
|
|
128
|
+
ok: !1,
|
|
129
|
+
reason: "closed"
|
|
130
|
+
};
|
|
131
|
+
if (i.units.length === 0) return {
|
|
132
|
+
ok: !1,
|
|
133
|
+
reason: "noUnits"
|
|
134
|
+
};
|
|
135
|
+
let d = await S(e, t, u.variantId, r);
|
|
136
|
+
if (d === void 0) return {
|
|
137
|
+
ok: !1,
|
|
138
|
+
reason: "notFound"
|
|
139
|
+
};
|
|
140
|
+
let f = v(t, d, u.values), p = i.units.filter((e) => !f.some((t) => t.key === e));
|
|
141
|
+
if (p.length > 0) return {
|
|
142
|
+
ok: !1,
|
|
143
|
+
reason: "unknownUnit",
|
|
144
|
+
units: p
|
|
145
|
+
};
|
|
146
|
+
let m = { ...d };
|
|
147
|
+
for (let e of f.filter((e) => i.units.includes(e.key))) {
|
|
148
|
+
if (e.kind === "field") {
|
|
149
|
+
m[e.field] = e.after;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
let t = [...Array.isArray(m[e.field]) ? m[e.field] : []], n = e.after;
|
|
153
|
+
m[e.field] = e.kind === "addedSection" ? [...t, {
|
|
154
|
+
componentId: n.componentId,
|
|
155
|
+
props: n.props
|
|
156
|
+
}] : t.map((e) => e.instanceId === n.instanceId ? {
|
|
157
|
+
...e,
|
|
158
|
+
props: n.props
|
|
159
|
+
} : e);
|
|
160
|
+
}
|
|
161
|
+
let g = await a(e, t, m, r, { expectedRevision: String(d.revisionId) }), _ = i.units.length === f.length ? "adopted" : "partial";
|
|
162
|
+
return await e.update(h, n, {
|
|
163
|
+
status: _,
|
|
164
|
+
adoptedUnits: [...i.units],
|
|
165
|
+
adoptedRevisionId: String(g.revisionId),
|
|
166
|
+
decidedBy: i.actorId,
|
|
167
|
+
decidedAt: s
|
|
168
|
+
}), u.operationId !== null && await o(e, u.operationId, "applied"), {
|
|
169
|
+
ok: !0,
|
|
170
|
+
revisionId: String(g.revisionId),
|
|
171
|
+
status: _
|
|
172
|
+
};
|
|
173
|
+
}, T = async (e, t, n, r = /* @__PURE__ */ new Date()) => {
|
|
174
|
+
let [i] = await e.query({
|
|
175
|
+
table: h,
|
|
176
|
+
predicate: c("id", t),
|
|
177
|
+
order: [],
|
|
178
|
+
take: 1,
|
|
179
|
+
skip: void 0,
|
|
180
|
+
projection: void 0
|
|
181
|
+
});
|
|
182
|
+
return i === void 0 || i.status !== "open" ? !1 : (await e.update(h, t, {
|
|
183
|
+
status: "discarded",
|
|
184
|
+
decidedBy: n,
|
|
185
|
+
decidedAt: r
|
|
186
|
+
}), typeof i.operationId == "string" && await o(e, i.operationId, "discarded"), !0);
|
|
187
|
+
}, E = async (e, t, n) => (await e.query({
|
|
188
|
+
table: h,
|
|
189
|
+
predicate: s(c("contentType", t.name), c("variantId", n)),
|
|
190
|
+
order: [{
|
|
191
|
+
column: "createdAt",
|
|
192
|
+
direction: "desc"
|
|
193
|
+
}],
|
|
194
|
+
take: 20,
|
|
195
|
+
skip: void 0,
|
|
196
|
+
projection: void 0
|
|
197
|
+
})).map(x), D = (...t) => e(() => C(...t)), O = (...a) => e(() => w(...a), r, n, t, i), k = (...t) => e(() => T(...t)), A = (...t) => e(() => E(...t));
|
|
198
|
+
//#endregion
|
|
199
|
+
export { h as CMS_AI_CANDIDATES_TABLE, w as adoptCandidate, O as adoptCandidateEffect, v as candidateUnits, E as candidatesFor, A as candidatesForEffect, g as cmsAiCandidatesTable, T as discardCandidate, k as discardCandidateEffect, C as proposeCandidate, D as proposeCandidateEffect };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { and as t, eq as n, gte as r, id as i, integer as a, table as o, text as s } from "@voltro/database";
|
|
3
|
+
import { tenant as c } from "@voltro/plugin-multitenancy/mixin";
|
|
4
|
+
import { createHash as l } from "node:crypto";
|
|
5
|
+
//#region src/aiOperations.ts
|
|
6
|
+
var u = "cms_ai_operations", d = "cms_ai_settings", f = [
|
|
7
|
+
"suggested",
|
|
8
|
+
"failed",
|
|
9
|
+
"applied",
|
|
10
|
+
"discarded"
|
|
11
|
+
], p = o(u, {
|
|
12
|
+
id: i({ prefix: "caio" }),
|
|
13
|
+
operation: s(),
|
|
14
|
+
version: s(),
|
|
15
|
+
provider: s(),
|
|
16
|
+
model: s(),
|
|
17
|
+
contentType: s().maxLength(64),
|
|
18
|
+
variantId: s().maxLength(64),
|
|
19
|
+
revisionId: s().nullable(),
|
|
20
|
+
field: s().nullable(),
|
|
21
|
+
promptHash: s(),
|
|
22
|
+
inputTokens: a().nullable(),
|
|
23
|
+
outputTokens: a().nullable(),
|
|
24
|
+
outcome: s().oneOf([...f]),
|
|
25
|
+
error: s().nullable(),
|
|
26
|
+
actor: s().nullable()
|
|
27
|
+
}).with(c()), m = o(d, {
|
|
28
|
+
id: i({ prefix: "cais" }),
|
|
29
|
+
provider: s(),
|
|
30
|
+
model: s(),
|
|
31
|
+
apiKey: s().encrypted().serverOnly().nullable(),
|
|
32
|
+
monthlyTokens: a().nullable()
|
|
33
|
+
}).with(c()).unique("cms_ai_settings_uq_tenant", ["tenantId"]), h = (e) => l("sha256").update(e).digest("hex"), g = async (e, t) => {
|
|
34
|
+
let n = await e.insert(u, {
|
|
35
|
+
operation: t.operation,
|
|
36
|
+
version: t.version,
|
|
37
|
+
provider: t.provider,
|
|
38
|
+
model: t.model,
|
|
39
|
+
contentType: t.contentType,
|
|
40
|
+
variantId: t.variantId,
|
|
41
|
+
revisionId: t.revisionId ?? null,
|
|
42
|
+
field: t.field ?? null,
|
|
43
|
+
promptHash: h(t.prompt),
|
|
44
|
+
inputTokens: t.usage?.inputTokens ?? null,
|
|
45
|
+
outputTokens: t.usage?.outputTokens ?? null,
|
|
46
|
+
outcome: t.outcome,
|
|
47
|
+
error: t.error ?? null,
|
|
48
|
+
actor: t.actor ?? null
|
|
49
|
+
});
|
|
50
|
+
return String(n.id);
|
|
51
|
+
}, _ = async (e, t, r) => {
|
|
52
|
+
let [i] = await e.query({
|
|
53
|
+
table: u,
|
|
54
|
+
predicate: n("id", t),
|
|
55
|
+
order: [],
|
|
56
|
+
take: 1,
|
|
57
|
+
skip: void 0,
|
|
58
|
+
projection: void 0
|
|
59
|
+
});
|
|
60
|
+
return i === void 0 || i.outcome !== "suggested" ? !1 : (await e.update(u, t, { outcome: r }), !0);
|
|
61
|
+
}, v = (e) => ({
|
|
62
|
+
id: String(e.id),
|
|
63
|
+
operation: String(e.operation),
|
|
64
|
+
version: String(e.version),
|
|
65
|
+
provider: String(e.provider),
|
|
66
|
+
model: String(e.model),
|
|
67
|
+
field: typeof e.field == "string" ? e.field : null,
|
|
68
|
+
revisionId: typeof e.revisionId == "string" ? e.revisionId : null,
|
|
69
|
+
outcome: e.outcome,
|
|
70
|
+
inputTokens: typeof e.inputTokens == "number" ? e.inputTokens : null,
|
|
71
|
+
outputTokens: typeof e.outputTokens == "number" ? e.outputTokens : null,
|
|
72
|
+
at: e.createdAt instanceof Date ? e.createdAt.getTime() : new Date(String(e.createdAt ?? 0)).getTime()
|
|
73
|
+
}), y = async (e, r, i) => (await e.query({
|
|
74
|
+
table: u,
|
|
75
|
+
predicate: t(n("contentType", r), n("variantId", i)),
|
|
76
|
+
order: [{
|
|
77
|
+
column: "createdAt",
|
|
78
|
+
direction: "desc"
|
|
79
|
+
}, {
|
|
80
|
+
column: "id",
|
|
81
|
+
direction: "desc"
|
|
82
|
+
}],
|
|
83
|
+
take: 200,
|
|
84
|
+
skip: void 0,
|
|
85
|
+
projection: void 0
|
|
86
|
+
})).map(v), b = async (e, t) => {
|
|
87
|
+
let [r] = await e.query({
|
|
88
|
+
table: d,
|
|
89
|
+
predicate: n("tenantId", t),
|
|
90
|
+
order: [],
|
|
91
|
+
take: 1,
|
|
92
|
+
skip: void 0,
|
|
93
|
+
projection: void 0
|
|
94
|
+
});
|
|
95
|
+
return r === void 0 ? null : {
|
|
96
|
+
provider: typeof r.provider == "string" && r.provider !== "" ? r.provider : null,
|
|
97
|
+
model: typeof r.model == "string" && r.model !== "" ? r.model : null,
|
|
98
|
+
apiKey: typeof r.apiKey == "string" && r.apiKey !== "" ? r.apiKey : null,
|
|
99
|
+
monthlyTokens: typeof r.monthlyTokens == "number" ? r.monthlyTokens : null
|
|
100
|
+
};
|
|
101
|
+
}, x = (e = /* @__PURE__ */ new Date()) => new Date(Date.UTC(e.getUTCFullYear(), e.getUTCMonth(), 1)), S = async (e, i, a = x()) => (await e.query({
|
|
102
|
+
table: u,
|
|
103
|
+
predicate: t(n("tenantId", i), r("createdAt", a)),
|
|
104
|
+
order: [],
|
|
105
|
+
take: void 0,
|
|
106
|
+
skip: void 0,
|
|
107
|
+
projection: ["inputTokens", "outputTokens"]
|
|
108
|
+
})).reduce((e, t) => e + (Number(t.inputTokens) || 0) + (Number(t.outputTokens) || 0), 0), C = async (e, t, n = /* @__PURE__ */ new Date()) => {
|
|
109
|
+
let r = (await b(e, t))?.monthlyTokens ?? null;
|
|
110
|
+
return r === null ? null : Math.max(0, r - await S(e, t, x(n)));
|
|
111
|
+
}, w = async (e, t, r) => {
|
|
112
|
+
let [i] = await e.query({
|
|
113
|
+
table: d,
|
|
114
|
+
predicate: n("tenantId", t),
|
|
115
|
+
order: [],
|
|
116
|
+
take: 1,
|
|
117
|
+
skip: void 0,
|
|
118
|
+
projection: void 0
|
|
119
|
+
}), a = r === null ? {
|
|
120
|
+
provider: "",
|
|
121
|
+
model: "",
|
|
122
|
+
apiKey: null
|
|
123
|
+
} : {
|
|
124
|
+
provider: r.provider,
|
|
125
|
+
model: r.model,
|
|
126
|
+
...r.apiKey === void 0 ? {} : { apiKey: r.apiKey }
|
|
127
|
+
};
|
|
128
|
+
i === void 0 ? r !== null && await e.insert(d, {
|
|
129
|
+
apiKey: null,
|
|
130
|
+
monthlyTokens: null,
|
|
131
|
+
...a,
|
|
132
|
+
tenantId: t
|
|
133
|
+
}) : r === null && typeof i.monthlyTokens != "number" ? await e.delete(d, String(i.id)) : await e.update(d, String(i.id), a);
|
|
134
|
+
}, T = async (e, t, r) => {
|
|
135
|
+
let [i] = await e.query({
|
|
136
|
+
table: d,
|
|
137
|
+
predicate: n("tenantId", t),
|
|
138
|
+
order: [],
|
|
139
|
+
take: 1,
|
|
140
|
+
skip: void 0,
|
|
141
|
+
projection: void 0
|
|
142
|
+
});
|
|
143
|
+
i === void 0 ? r !== null && await e.insert(d, {
|
|
144
|
+
provider: "",
|
|
145
|
+
model: "",
|
|
146
|
+
apiKey: null,
|
|
147
|
+
monthlyTokens: r,
|
|
148
|
+
tenantId: t
|
|
149
|
+
}) : r === null && i.provider === "" ? await e.delete(d, String(i.id)) : await e.update(d, String(i.id), { monthlyTokens: r });
|
|
150
|
+
}, E = (...t) => e(() => C(...t)), D = (...t) => e(() => y(...t)), O = (...t) => e(() => b(...t)), k = (...t) => e(() => S(...t)), A = (...t) => e(() => T(...t)), j = (...t) => e(() => g(...t)), M = (...t) => e(() => w(...t)), N = (...t) => e(() => _(...t));
|
|
151
|
+
//#endregion
|
|
152
|
+
export { f as AI_OUTCOMES, u as CMS_AI_OPERATIONS_TABLE, d as CMS_AI_SETTINGS_TABLE, C as aiBudgetLeft, E as aiBudgetLeftEffect, y as aiOperationsFor, D as aiOperationsForEffect, b as aiSettings, O as aiSettingsEffect, S as aiTokensUsed, k as aiTokensUsedEffect, p as cmsAiOperationsTable, m as cmsAiSettingsTable, x as monthStart, h as promptHash, g as recordAiOperation, j as recordAiOperationEffect, T as setAiBudget, A as setAiBudgetEffect, w as setAiSettings, M as setAiSettingsEffect, _ as settleAiOperation, N as settleAiOperationEffect };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/audiences.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let { languages: t, countries: n, returning: r } = e.rule;
|
|
4
|
+
if ((t?.length ?? 0) === 0 && (n?.length ?? 0) === 0 && r === void 0) throw Error(`defineAudience('${e.id}'): the rule has no condition, so it would match every reader.`);
|
|
5
|
+
return e;
|
|
6
|
+
}, t = (e, t) => {
|
|
7
|
+
if (e.languages !== void 0 && e.languages.length > 0) {
|
|
8
|
+
let n = (t.languages ?? [])[0]?.toLowerCase();
|
|
9
|
+
if (n === void 0 || !e.languages.some((e) => n === e.toLowerCase() || n.startsWith(`${e.toLowerCase()}-`))) return !1;
|
|
10
|
+
}
|
|
11
|
+
if (e.countries !== void 0 && e.countries.length > 0) {
|
|
12
|
+
let n = t.country?.toUpperCase();
|
|
13
|
+
if (n === void 0 || !e.countries.some((e) => e.toUpperCase() === n)) return !1;
|
|
14
|
+
}
|
|
15
|
+
return e.returning === void 0 || (t.returning ?? !1) === e.returning;
|
|
16
|
+
}, n = (e, n, r) => {
|
|
17
|
+
let i = new Map(n.map((e) => [e.id, e]));
|
|
18
|
+
return e.find((e) => {
|
|
19
|
+
let n = i.get(e.audience);
|
|
20
|
+
return n !== void 0 && t(n.rule, r);
|
|
21
|
+
}) ?? null;
|
|
22
|
+
}, r = (e) => (e ?? "").split(",").map((e, t) => {
|
|
23
|
+
let [n, ...r] = e.trim().split(";"), i = Number(r.find((e) => e.trim().startsWith("q="))?.trim().slice(2) ?? "1");
|
|
24
|
+
return {
|
|
25
|
+
tag: (n ?? "").trim(),
|
|
26
|
+
q: Number.isFinite(i) ? i : 0,
|
|
27
|
+
i: t
|
|
28
|
+
};
|
|
29
|
+
}).filter((e) => e.tag !== "" && e.tag !== "*" && e.q > 0).sort((e, t) => t.q - e.q || e.i - t.i).map((e) => e.tag);
|
|
30
|
+
//#endregion
|
|
31
|
+
export { e as defineAudience, r as languagesOf, t as matchesAudience, n as pickVariant };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { asTyped as e } from "./effectForm.js";
|
|
2
|
+
import { ReferenceUnavailable as t } from "./errors.js";
|
|
3
|
+
import { referencesOf as n } from "./references.js";
|
|
4
|
+
import { and as r, boolean as i, eq as a, gt as o, id as s, inSet as c, json as l, lte as u, table as d, text as f, timestamp as p } from "@voltro/database";
|
|
5
|
+
import { tenant as m } from "@voltro/plugin-multitenancy/mixin";
|
|
6
|
+
//#region src/availability.ts
|
|
7
|
+
var h = "cms_availability", g = d(h, {
|
|
8
|
+
id: s({ prefix: "cavl" }),
|
|
9
|
+
contentType: f().maxLength(64),
|
|
10
|
+
documentId: f().maxLength(64),
|
|
11
|
+
site: f().maxLength(64),
|
|
12
|
+
environment: f().maxLength(64),
|
|
13
|
+
availableUntil: p().nullable(),
|
|
14
|
+
blocked: i().default(!1),
|
|
15
|
+
availableFrom: p().nullable(),
|
|
16
|
+
territories: l().nullable(),
|
|
17
|
+
channels: l().nullable(),
|
|
18
|
+
purposes: l().nullable()
|
|
19
|
+
}).with(m()).index("cms_availability_by_document", [
|
|
20
|
+
"documentId",
|
|
21
|
+
"site",
|
|
22
|
+
"environment"
|
|
23
|
+
]), _ = (e) => {
|
|
24
|
+
if (!Array.isArray(e)) return null;
|
|
25
|
+
let t = e.filter((e) => typeof e == "string" && e.trim() !== "").map((e) => e.trim());
|
|
26
|
+
return t.length === 0 ? null : t;
|
|
27
|
+
}, v = (e) => {
|
|
28
|
+
if (e instanceof Date) return e;
|
|
29
|
+
if (typeof e == "string" && e !== "") {
|
|
30
|
+
let t = new Date(e);
|
|
31
|
+
return Number.isNaN(t.getTime()) ? null : t;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}, y = async (e, t, n, i) => {
|
|
35
|
+
let o = t.availability;
|
|
36
|
+
if (o === void 0) return;
|
|
37
|
+
let s = {
|
|
38
|
+
availableUntil: o.until === void 0 ? null : v(n[o.until]),
|
|
39
|
+
blocked: o.blocked !== void 0 && n[o.blocked] === !0,
|
|
40
|
+
availableFrom: o.from === void 0 ? null : v(n[o.from]),
|
|
41
|
+
territories: o.territories === void 0 ? null : _(n[o.territories])?.map((e) => e.toUpperCase()) ?? null,
|
|
42
|
+
channels: o.channels === void 0 ? null : _(n[o.channels]),
|
|
43
|
+
purposes: o.purposes === void 0 ? null : _(n[o.purposes])
|
|
44
|
+
}, [c] = await e.query({
|
|
45
|
+
table: h,
|
|
46
|
+
predicate: r(a("contentType", t.name), a("documentId", n.documentId), a("site", i.site), a("environment", i.environment)),
|
|
47
|
+
order: [],
|
|
48
|
+
take: 1,
|
|
49
|
+
skip: void 0,
|
|
50
|
+
projection: void 0
|
|
51
|
+
});
|
|
52
|
+
if (c !== void 0) {
|
|
53
|
+
await e.update(h, c.id, s);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let l = n.tenantId;
|
|
57
|
+
await e.insert(h, {
|
|
58
|
+
contentType: t.name,
|
|
59
|
+
documentId: n.documentId,
|
|
60
|
+
site: i.site,
|
|
61
|
+
environment: i.environment,
|
|
62
|
+
...s,
|
|
63
|
+
...l == null ? {} : { tenantId: l }
|
|
64
|
+
});
|
|
65
|
+
}, b = async (e, t, n, i = /* @__PURE__ */ new Date(), o = {}) => {
|
|
66
|
+
let s = /* @__PURE__ */ new Map(), l = [...new Set(t)];
|
|
67
|
+
if (l.length === 0) return s;
|
|
68
|
+
let u = await e.query({
|
|
69
|
+
table: h,
|
|
70
|
+
predicate: r(c("documentId", l), a("site", n.site), a("environment", n.environment)),
|
|
71
|
+
order: [],
|
|
72
|
+
take: void 0,
|
|
73
|
+
skip: void 0,
|
|
74
|
+
projection: void 0
|
|
75
|
+
}), d = (e, t, n = !1) => {
|
|
76
|
+
let r = _(e);
|
|
77
|
+
return r === null || t == null || t === "" ? !1 : !r.includes(n ? t.toUpperCase() : t);
|
|
78
|
+
};
|
|
79
|
+
for (let e of u) {
|
|
80
|
+
let t = e.documentId, n = v(e.availableUntil), r = v(e.availableFrom);
|
|
81
|
+
e.blocked === !0 ? s.set(t, "blocked") : n !== null && n.getTime() <= i.getTime() ? s.set(t, "expired") : r !== null && r.getTime() > i.getTime() ? s.set(t, "notYet") : d(e.territories, o.territory, !0) ? s.set(t, "territory") : d(e.channels, o.channel) ? s.set(t, "channel") : d(e.purposes, o.purpose) && s.set(t, "purpose");
|
|
82
|
+
}
|
|
83
|
+
return s;
|
|
84
|
+
}, x = async (e, t, n, i = /* @__PURE__ */ new Date()) => {
|
|
85
|
+
let s = new Date(i.getTime() + n * 864e5);
|
|
86
|
+
return (await e.query({
|
|
87
|
+
table: h,
|
|
88
|
+
predicate: r(a("site", t.site), a("environment", t.environment), a("blocked", !1), o("availableUntil", i), u("availableUntil", s)),
|
|
89
|
+
order: [{
|
|
90
|
+
column: "availableUntil",
|
|
91
|
+
direction: "asc"
|
|
92
|
+
}],
|
|
93
|
+
take: 500,
|
|
94
|
+
skip: void 0,
|
|
95
|
+
projection: void 0
|
|
96
|
+
})).flatMap((e) => {
|
|
97
|
+
let t = v(e.availableUntil);
|
|
98
|
+
return t === null ? [] : [{
|
|
99
|
+
contentType: String(e.contentType),
|
|
100
|
+
documentId: String(e.documentId),
|
|
101
|
+
until: t,
|
|
102
|
+
days: Math.ceil((t.getTime() - i.getTime()) / 864e5)
|
|
103
|
+
}];
|
|
104
|
+
});
|
|
105
|
+
}, S = async (e, r, i, a, o, s = /* @__PURE__ */ new Date()) => {
|
|
106
|
+
let c = n(r, a);
|
|
107
|
+
if (c.length === 0) return;
|
|
108
|
+
let l = await b(e, c.map((e) => e.targetDocumentId), o, s);
|
|
109
|
+
if (l.size !== 0) throw new t({
|
|
110
|
+
contentType: r.name,
|
|
111
|
+
id: i,
|
|
112
|
+
targets: c.filter((e) => l.has(e.targetDocumentId)).map((e) => ({
|
|
113
|
+
path: e.path,
|
|
114
|
+
contentType: e.targetType,
|
|
115
|
+
documentId: e.targetDocumentId,
|
|
116
|
+
reason: l.get(e.targetDocumentId)
|
|
117
|
+
}))
|
|
118
|
+
});
|
|
119
|
+
}, C = [t], w = (...t) => e(() => x(...t)), T = (...t) => e(() => S(...t), ...C), E = (...t) => e(() => b(...t), ...C), D = (...t) => e(() => y(...t), ...C);
|
|
120
|
+
//#endregion
|
|
121
|
+
export { h as CMS_AVAILABILITY_TABLE, S as assertReferencesAvailable, T as assertReferencesAvailableEffect, g as cmsAvailabilityTable, x as expiringAmong, w as expiringAmongEffect, b as unavailableAmong, E as unavailableAmongEffect, y as writeAvailability, D as writeAvailabilityEffect };
|