@blinkk/root-cms 2.0.1 → 2.0.3
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/dist/app.js +15 -5
- package/dist/client.js +38 -43
- package/dist/core.js +40 -46
- package/dist/functions.js +40 -46
- package/dist/plugin.js +163 -85
- package/dist/richtext.js +12 -19
- package/dist/ui/ui.css +1 -1
- package/dist/ui/ui.js +142 -95
- package/package.json +14 -3
package/dist/app.js
CHANGED
|
@@ -7,7 +7,7 @@ import { render as renderToString } from "preact-render-to-string";
|
|
|
7
7
|
// package.json
|
|
8
8
|
var package_default = {
|
|
9
9
|
name: "@blinkk/root-cms",
|
|
10
|
-
version: "2.0.
|
|
10
|
+
version: "2.0.3",
|
|
11
11
|
author: "s@blinkk.com",
|
|
12
12
|
license: "MIT",
|
|
13
13
|
engines: {
|
|
@@ -103,6 +103,15 @@ var package_default = {
|
|
|
103
103
|
"@firebase/app-compat": "0.2.19",
|
|
104
104
|
"@firebase/app-types": "0.9.0",
|
|
105
105
|
"@firebase/rules-unit-testing": "3.0.1",
|
|
106
|
+
"@lexical/code": "0.33.1",
|
|
107
|
+
"@lexical/html": "0.33.1",
|
|
108
|
+
"@lexical/link": "0.33.1",
|
|
109
|
+
"@lexical/list": "0.33.1",
|
|
110
|
+
"@lexical/markdown": "0.33.1",
|
|
111
|
+
"@lexical/react": "0.33.1",
|
|
112
|
+
"@lexical/rich-text": "0.33.1",
|
|
113
|
+
"@lexical/selection": "0.33.1",
|
|
114
|
+
"@lexical/utils": "0.33.1",
|
|
106
115
|
"@mantine/core": "4.2.12",
|
|
107
116
|
"@mantine/hooks": "4.2.12",
|
|
108
117
|
"@mantine/modals": "4.2.12",
|
|
@@ -126,6 +135,7 @@ var package_default = {
|
|
|
126
135
|
"firebase-tools": "12.9.1",
|
|
127
136
|
"highlight.js": "11.6.0",
|
|
128
137
|
"json-diff-kit": "1.0.29",
|
|
138
|
+
lexical: "0.33.1",
|
|
129
139
|
marked: "9.1.1",
|
|
130
140
|
"mdast-util-from-markdown": "2.0.1",
|
|
131
141
|
"mdast-util-gfm": "3.0.0",
|
|
@@ -139,10 +149,11 @@ var package_default = {
|
|
|
139
149
|
tsup: "8.0.1",
|
|
140
150
|
typescript: "5.2.2",
|
|
141
151
|
vite: "5.0.8",
|
|
142
|
-
vitest: "0.34.6"
|
|
152
|
+
vitest: "0.34.6",
|
|
153
|
+
yjs: "13.6.27"
|
|
143
154
|
},
|
|
144
155
|
peerDependencies: {
|
|
145
|
-
"@blinkk/root": "2.0.
|
|
156
|
+
"@blinkk/root": "2.0.3",
|
|
146
157
|
"firebase-admin": ">=11",
|
|
147
158
|
"firebase-functions": ">=4",
|
|
148
159
|
preact: ">=10",
|
|
@@ -246,7 +257,6 @@ function App(props) {
|
|
|
246
257
|
] });
|
|
247
258
|
}
|
|
248
259
|
async function renderApp(req, res, options) {
|
|
249
|
-
var _a;
|
|
250
260
|
const collections = {};
|
|
251
261
|
Object.entries(getCollections()).forEach(([collectionId, collection]) => {
|
|
252
262
|
collections[collectionId] = serializeCollection(collection);
|
|
@@ -266,7 +276,7 @@ async function renderApp(req, res, options) {
|
|
|
266
276
|
gci,
|
|
267
277
|
i18n: rootConfig.i18n,
|
|
268
278
|
server: {
|
|
269
|
-
trailingSlash:
|
|
279
|
+
trailingSlash: rootConfig.server?.trailingSlash
|
|
270
280
|
}
|
|
271
281
|
},
|
|
272
282
|
firebaseConfig: cmsConfig.firebaseConfig,
|
package/dist/client.js
CHANGED
|
@@ -64,11 +64,11 @@ var TranslationsManager = class {
|
|
|
64
64
|
locale,
|
|
65
65
|
sys: {
|
|
66
66
|
modifiedAt: Timestamp.now(),
|
|
67
|
-
modifiedBy:
|
|
67
|
+
modifiedBy: options?.modifiedBy || "root-cms-client"
|
|
68
68
|
},
|
|
69
69
|
strings: {}
|
|
70
70
|
};
|
|
71
|
-
if (
|
|
71
|
+
if (options?.tags && options.tags.length > 0) {
|
|
72
72
|
updates.tags = FieldValue.arrayUnion(...options.tags);
|
|
73
73
|
}
|
|
74
74
|
let numUpdates = 0;
|
|
@@ -108,13 +108,13 @@ var TranslationsManager = class {
|
|
|
108
108
|
console.warn(`no translations to publish for ${id}`);
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
const batch =
|
|
111
|
+
const batch = options?.batch || db.batch();
|
|
112
112
|
res.docs.forEach((doc) => {
|
|
113
113
|
const translationsLocaleDoc = doc.data();
|
|
114
114
|
const sys = {
|
|
115
115
|
...translationsLocaleDoc.sys,
|
|
116
116
|
publishedAt: Timestamp.now(),
|
|
117
|
-
publishedBy:
|
|
117
|
+
publishedBy: options?.publishedBy || "root-cms-client"
|
|
118
118
|
};
|
|
119
119
|
batch.update(doc.ref, { sys });
|
|
120
120
|
const publishedDocPath = buildTranslationsLocaleDocDbPath({
|
|
@@ -126,7 +126,7 @@ var TranslationsManager = class {
|
|
|
126
126
|
const publishedDocRef = db.doc(publishedDocPath);
|
|
127
127
|
batch.set(publishedDocRef, { ...translationsLocaleDoc, sys });
|
|
128
128
|
});
|
|
129
|
-
const shouldCommitBatch = !
|
|
129
|
+
const shouldCommitBatch = !options?.batch;
|
|
130
130
|
if (shouldCommitBatch) {
|
|
131
131
|
await batch.commit();
|
|
132
132
|
}
|
|
@@ -167,19 +167,19 @@ var TranslationsManager = class {
|
|
|
167
167
|
* ```
|
|
168
168
|
*/
|
|
169
169
|
async loadTranslations(options) {
|
|
170
|
-
const mode =
|
|
170
|
+
const mode = options?.mode || "published";
|
|
171
171
|
const dbPath = buildTranslationsDbPath({
|
|
172
172
|
project: this.cmsClient.projectId,
|
|
173
173
|
mode
|
|
174
174
|
});
|
|
175
175
|
let query = this.cmsClient.db.collection(dbPath);
|
|
176
|
-
if (
|
|
176
|
+
if (options?.ids && options.ids.length > 0) {
|
|
177
177
|
query = query.where("id", "in", options.ids);
|
|
178
178
|
}
|
|
179
|
-
if (
|
|
179
|
+
if (options?.tags && options.tags.length > 0) {
|
|
180
180
|
query = query.where("tags", "array-contains", options.tags);
|
|
181
181
|
}
|
|
182
|
-
if (
|
|
182
|
+
if (options?.locales && options.locales.length > 0) {
|
|
183
183
|
query = query.where("locale", "in", options.locales);
|
|
184
184
|
}
|
|
185
185
|
const results = await query.get();
|
|
@@ -210,11 +210,11 @@ var TranslationsManager = class {
|
|
|
210
210
|
async loadTranslationsForLocale(locale, options) {
|
|
211
211
|
const localeSet = /* @__PURE__ */ new Set([
|
|
212
212
|
locale,
|
|
213
|
-
...
|
|
213
|
+
...options?.fallbackLocales || []
|
|
214
214
|
]);
|
|
215
215
|
const fallbackLocales = Array.from(localeSet);
|
|
216
216
|
const multiLocaleStrings = await this.loadTranslations({
|
|
217
|
-
mode: options
|
|
217
|
+
mode: options?.mode,
|
|
218
218
|
locales: fallbackLocales
|
|
219
219
|
});
|
|
220
220
|
return this.toSingleLocaleMap(multiLocaleStrings, fallbackLocales);
|
|
@@ -285,7 +285,6 @@ var TranslationsManager = class {
|
|
|
285
285
|
* Import translations from the v1 system to the TranslationsManager.
|
|
286
286
|
*/
|
|
287
287
|
async importTranslationsFromV1() {
|
|
288
|
-
var _a;
|
|
289
288
|
const projectId = this.cmsClient.projectId;
|
|
290
289
|
const db = this.cmsClient.db;
|
|
291
290
|
const dbPath = `Projects/${projectId}/Translations`;
|
|
@@ -326,7 +325,7 @@ var TranslationsManager = class {
|
|
|
326
325
|
const doc = await this.cmsClient.getDoc(collection, slug, {
|
|
327
326
|
mode: "draft"
|
|
328
327
|
});
|
|
329
|
-
const linkedSheet =
|
|
328
|
+
const linkedSheet = doc?.sys?.l10nSheet;
|
|
330
329
|
if (linkedSheet) {
|
|
331
330
|
translationsDocs[docId].sys.linkedSheet = linkedSheet;
|
|
332
331
|
}
|
|
@@ -429,7 +428,7 @@ var RootCMSClient = class {
|
|
|
429
428
|
const { collection, slug } = parseDocId(docId);
|
|
430
429
|
const draftDoc = await this.getRawDoc(collection, slug, { mode: "draft" }) || {};
|
|
431
430
|
const draftSys = draftDoc.sys || {};
|
|
432
|
-
const modifiedBy =
|
|
431
|
+
const modifiedBy = options?.modifiedBy || "root-cms-client";
|
|
433
432
|
const fields = marshalData(fieldsData || {});
|
|
434
433
|
const data = {
|
|
435
434
|
id: docId,
|
|
@@ -441,7 +440,7 @@ var RootCMSClient = class {
|
|
|
441
440
|
createdBy: draftSys.createdBy ?? modifiedBy,
|
|
442
441
|
modifiedAt: Timestamp2.now(),
|
|
443
442
|
modifiedBy,
|
|
444
|
-
locales:
|
|
443
|
+
locales: options?.locales ?? draftSys.locales ?? ["en"]
|
|
445
444
|
},
|
|
446
445
|
fields
|
|
447
446
|
};
|
|
@@ -511,7 +510,7 @@ var RootCMSClient = class {
|
|
|
511
510
|
*/
|
|
512
511
|
async publishDocs(docIds, options) {
|
|
513
512
|
const projectCollectionsPath = `Projects/${this.projectId}/Collections`;
|
|
514
|
-
const publishedBy =
|
|
513
|
+
const publishedBy = options?.publishedBy || "root-cms-client";
|
|
515
514
|
const docRefs = docIds.map((docId) => {
|
|
516
515
|
const [collection, slug] = docId.split("/");
|
|
517
516
|
if (!collection || !slug) {
|
|
@@ -534,9 +533,9 @@ var RootCMSClient = class {
|
|
|
534
533
|
}
|
|
535
534
|
}
|
|
536
535
|
let batchCount = 0;
|
|
537
|
-
const batch =
|
|
536
|
+
const batch = options?.batch || this.db.batch();
|
|
538
537
|
const versionTags = ["published"];
|
|
539
|
-
if (options
|
|
538
|
+
if (options?.releaseId) {
|
|
540
539
|
versionTags.push(`release:${options.releaseId}`);
|
|
541
540
|
}
|
|
542
541
|
const publishedDocs = [];
|
|
@@ -619,12 +618,11 @@ var RootCMSClient = class {
|
|
|
619
618
|
const now = Math.ceil((/* @__PURE__ */ new Date()).getTime());
|
|
620
619
|
const snapshot = await this.db.collectionGroup("Scheduled").get();
|
|
621
620
|
const docs = snapshot.docs.filter((d) => {
|
|
622
|
-
var _a;
|
|
623
621
|
if (!d.ref.path.startsWith(projectCollectionsPath)) {
|
|
624
622
|
return false;
|
|
625
623
|
}
|
|
626
624
|
const data = d.data() || {};
|
|
627
|
-
const scheduledAt =
|
|
625
|
+
const scheduledAt = data.sys?.scheduledAt;
|
|
628
626
|
return scheduledAt && scheduledAt.toMillis && scheduledAt.toMillis() <= now;
|
|
629
627
|
}).map((d) => {
|
|
630
628
|
const dbPath = d.ref.path;
|
|
@@ -755,8 +753,7 @@ var RootCMSClient = class {
|
|
|
755
753
|
* Checks if a doc is currently "locked" for publishing.
|
|
756
754
|
*/
|
|
757
755
|
testPublishingLocked(doc) {
|
|
758
|
-
|
|
759
|
-
if ((_a = doc.sys) == null ? void 0 : _a.publishingLocked) {
|
|
756
|
+
if (doc.sys?.publishingLocked) {
|
|
760
757
|
if (doc.sys.publishingLocked.until) {
|
|
761
758
|
const now = Timestamp2.now().toMillis();
|
|
762
759
|
const until = doc.sys.publishingLocked.until.toMillis();
|
|
@@ -781,9 +778,8 @@ var RootCMSClient = class {
|
|
|
781
778
|
* replace the v1 translations system.
|
|
782
779
|
*/
|
|
783
780
|
getTranslationsManager() {
|
|
784
|
-
var _a;
|
|
785
781
|
const cmsPluginOptions = this.cmsPlugin.getConfig();
|
|
786
|
-
if (
|
|
782
|
+
if (cmsPluginOptions.experiments?.v2TranslationsManager) {
|
|
787
783
|
throw new Error(
|
|
788
784
|
"`v2TranslationsManager` is not enabled. update root.config.ts and add: `{experiments: {v2TranslationsManager: true}}`"
|
|
789
785
|
);
|
|
@@ -804,7 +800,7 @@ var RootCMSClient = class {
|
|
|
804
800
|
async loadTranslations(options) {
|
|
805
801
|
const dbPath = `Projects/${this.projectId}/Translations`;
|
|
806
802
|
let query = this.db.collection(dbPath);
|
|
807
|
-
if (options
|
|
803
|
+
if (options?.tags) {
|
|
808
804
|
query = query.where("tags", "array-contains-any", options.tags);
|
|
809
805
|
}
|
|
810
806
|
const querySnapshot = await query.get();
|
|
@@ -922,7 +918,7 @@ var RootCMSClient = class {
|
|
|
922
918
|
const dataDocRef = this.db.doc(
|
|
923
919
|
`Projects/${this.projectId}/DataSources/${dataSourceId}/Data/draft`
|
|
924
920
|
);
|
|
925
|
-
const syncedBy =
|
|
921
|
+
const syncedBy = options?.syncedBy || "root-cms-client";
|
|
926
922
|
const updatedDataSource = {
|
|
927
923
|
...dataSource,
|
|
928
924
|
syncedAt: Timestamp2.now(),
|
|
@@ -956,7 +952,7 @@ var RootCMSClient = class {
|
|
|
956
952
|
`Projects/${this.projectId}/DataSources/${dataSourceId}/published`
|
|
957
953
|
);
|
|
958
954
|
const dataRes = await this.getFromDataSource(dataSourceId, { mode: "draft" });
|
|
959
|
-
const publishedBy =
|
|
955
|
+
const publishedBy = options?.publishedBy || "root-cms-client";
|
|
960
956
|
const updatedDataSource = {
|
|
961
957
|
...dataSource,
|
|
962
958
|
publishedAt: Timestamp2.now(),
|
|
@@ -965,8 +961,8 @@ var RootCMSClient = class {
|
|
|
965
961
|
const batch = this.db.batch();
|
|
966
962
|
batch.set(dataDocRefPublished, {
|
|
967
963
|
dataSource: updatedDataSource,
|
|
968
|
-
data:
|
|
969
|
-
...
|
|
964
|
+
data: dataRes?.data || null,
|
|
965
|
+
...dataRes?.headers ? { headers: dataRes.headers } : {}
|
|
970
966
|
});
|
|
971
967
|
batch.update(dataDocRefDraft, {
|
|
972
968
|
dataSource: updatedDataSource
|
|
@@ -980,8 +976,8 @@ var RootCMSClient = class {
|
|
|
980
976
|
console.log(`published by: ${publishedBy}`);
|
|
981
977
|
}
|
|
982
978
|
async publishDataSources(dataSourceIds, options) {
|
|
983
|
-
const publishedBy =
|
|
984
|
-
const batch =
|
|
979
|
+
const publishedBy = options?.publishedBy || "root-cms-client";
|
|
980
|
+
const batch = options?.batch || this.db.batch();
|
|
985
981
|
for (const id of dataSourceIds) {
|
|
986
982
|
const dataSource = await this.getDataSource(id);
|
|
987
983
|
if (!dataSource) {
|
|
@@ -1004,8 +1000,8 @@ var RootCMSClient = class {
|
|
|
1004
1000
|
};
|
|
1005
1001
|
batch.set(dataDocRefPublished, {
|
|
1006
1002
|
dataSource: updatedDataSource,
|
|
1007
|
-
data:
|
|
1008
|
-
...
|
|
1003
|
+
data: dataRes?.data || null,
|
|
1004
|
+
...dataRes?.headers ? { headers: dataRes.headers } : {}
|
|
1009
1005
|
});
|
|
1010
1006
|
batch.update(dataDocRefDraft, { dataSource: updatedDataSource });
|
|
1011
1007
|
batch.update(dataSourceDocRef, {
|
|
@@ -1013,7 +1009,7 @@ var RootCMSClient = class {
|
|
|
1013
1009
|
publishedBy
|
|
1014
1010
|
});
|
|
1015
1011
|
}
|
|
1016
|
-
if (!
|
|
1012
|
+
if (!options?.batch || options?.commitBatch) {
|
|
1017
1013
|
await batch.commit();
|
|
1018
1014
|
}
|
|
1019
1015
|
}
|
|
@@ -1024,15 +1020,14 @@ var RootCMSClient = class {
|
|
|
1024
1020
|
throw new Error(`unsupported data source: ${dataSource.type}`);
|
|
1025
1021
|
}
|
|
1026
1022
|
async fetchHttpData(dataSource) {
|
|
1027
|
-
var _a, _b, _c;
|
|
1028
1023
|
const url = dataSource.url || "";
|
|
1029
1024
|
if (!url.startsWith("https://")) {
|
|
1030
1025
|
throw new Error(`url not supported: ${url}`);
|
|
1031
1026
|
}
|
|
1032
1027
|
const res = await fetch(url, {
|
|
1033
|
-
method:
|
|
1034
|
-
headers:
|
|
1035
|
-
body:
|
|
1028
|
+
method: dataSource.httpOptions?.method || "GET",
|
|
1029
|
+
headers: dataSource.httpOptions?.headers || [],
|
|
1030
|
+
body: dataSource.httpOptions?.body || void 0
|
|
1036
1031
|
});
|
|
1037
1032
|
if (res.status !== 200) {
|
|
1038
1033
|
const err = await res.text();
|
|
@@ -1048,7 +1043,7 @@ var RootCMSClient = class {
|
|
|
1048
1043
|
* Fetches data from a data source.
|
|
1049
1044
|
*/
|
|
1050
1045
|
async getFromDataSource(dataSourceId, options) {
|
|
1051
|
-
const mode =
|
|
1046
|
+
const mode = options?.mode || "published";
|
|
1052
1047
|
if (!(mode === "draft" || mode === "published")) {
|
|
1053
1048
|
throw new Error(`invalid mode: ${mode}`);
|
|
1054
1049
|
}
|
|
@@ -1138,12 +1133,12 @@ var RootCMSClient = class {
|
|
|
1138
1133
|
const data = {
|
|
1139
1134
|
action,
|
|
1140
1135
|
timestamp: Timestamp2.now(),
|
|
1141
|
-
by:
|
|
1142
|
-
metadata:
|
|
1136
|
+
by: options?.by || "system",
|
|
1137
|
+
metadata: options?.metadata || {}
|
|
1143
1138
|
};
|
|
1144
1139
|
const colRef = this.db.collection(`Projects/${this.projectId}/ActionLogs`);
|
|
1145
1140
|
await colRef.add(data);
|
|
1146
|
-
const metaStr =
|
|
1141
|
+
const metaStr = options?.metadata ? stringifyObj(options.metadata) : "";
|
|
1147
1142
|
console.log(`[${data.timestamp.toMillis()}] action: ${action} ${metaStr}`);
|
|
1148
1143
|
const cmsPluginConfig = this.cmsPlugin.getConfig();
|
|
1149
1144
|
if (cmsPluginConfig.onAction) {
|
|
@@ -1243,7 +1238,7 @@ function toArrayObject(arr) {
|
|
|
1243
1238
|
}
|
|
1244
1239
|
var marshalArray = toArrayObject;
|
|
1245
1240
|
function unmarshalArray(arrObject) {
|
|
1246
|
-
if (!Array.isArray(arrObject
|
|
1241
|
+
if (!Array.isArray(arrObject?._array)) {
|
|
1247
1242
|
return [];
|
|
1248
1243
|
}
|
|
1249
1244
|
const arr = arrObject._array.map((k) => arrObject[k]);
|
package/dist/core.js
CHANGED
|
@@ -70,11 +70,11 @@ var TranslationsManager = class {
|
|
|
70
70
|
locale,
|
|
71
71
|
sys: {
|
|
72
72
|
modifiedAt: Timestamp.now(),
|
|
73
|
-
modifiedBy:
|
|
73
|
+
modifiedBy: options?.modifiedBy || "root-cms-client"
|
|
74
74
|
},
|
|
75
75
|
strings: {}
|
|
76
76
|
};
|
|
77
|
-
if (
|
|
77
|
+
if (options?.tags && options.tags.length > 0) {
|
|
78
78
|
updates.tags = FieldValue.arrayUnion(...options.tags);
|
|
79
79
|
}
|
|
80
80
|
let numUpdates = 0;
|
|
@@ -114,13 +114,13 @@ var TranslationsManager = class {
|
|
|
114
114
|
console.warn(`no translations to publish for ${id}`);
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
|
-
const batch =
|
|
117
|
+
const batch = options?.batch || db.batch();
|
|
118
118
|
res.docs.forEach((doc) => {
|
|
119
119
|
const translationsLocaleDoc = doc.data();
|
|
120
120
|
const sys = {
|
|
121
121
|
...translationsLocaleDoc.sys,
|
|
122
122
|
publishedAt: Timestamp.now(),
|
|
123
|
-
publishedBy:
|
|
123
|
+
publishedBy: options?.publishedBy || "root-cms-client"
|
|
124
124
|
};
|
|
125
125
|
batch.update(doc.ref, { sys });
|
|
126
126
|
const publishedDocPath = buildTranslationsLocaleDocDbPath({
|
|
@@ -132,7 +132,7 @@ var TranslationsManager = class {
|
|
|
132
132
|
const publishedDocRef = db.doc(publishedDocPath);
|
|
133
133
|
batch.set(publishedDocRef, { ...translationsLocaleDoc, sys });
|
|
134
134
|
});
|
|
135
|
-
const shouldCommitBatch = !
|
|
135
|
+
const shouldCommitBatch = !options?.batch;
|
|
136
136
|
if (shouldCommitBatch) {
|
|
137
137
|
await batch.commit();
|
|
138
138
|
}
|
|
@@ -173,19 +173,19 @@ var TranslationsManager = class {
|
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
175
|
async loadTranslations(options) {
|
|
176
|
-
const mode =
|
|
176
|
+
const mode = options?.mode || "published";
|
|
177
177
|
const dbPath = buildTranslationsDbPath({
|
|
178
178
|
project: this.cmsClient.projectId,
|
|
179
179
|
mode
|
|
180
180
|
});
|
|
181
181
|
let query = this.cmsClient.db.collection(dbPath);
|
|
182
|
-
if (
|
|
182
|
+
if (options?.ids && options.ids.length > 0) {
|
|
183
183
|
query = query.where("id", "in", options.ids);
|
|
184
184
|
}
|
|
185
|
-
if (
|
|
185
|
+
if (options?.tags && options.tags.length > 0) {
|
|
186
186
|
query = query.where("tags", "array-contains", options.tags);
|
|
187
187
|
}
|
|
188
|
-
if (
|
|
188
|
+
if (options?.locales && options.locales.length > 0) {
|
|
189
189
|
query = query.where("locale", "in", options.locales);
|
|
190
190
|
}
|
|
191
191
|
const results = await query.get();
|
|
@@ -216,11 +216,11 @@ var TranslationsManager = class {
|
|
|
216
216
|
async loadTranslationsForLocale(locale, options) {
|
|
217
217
|
const localeSet = /* @__PURE__ */ new Set([
|
|
218
218
|
locale,
|
|
219
|
-
...
|
|
219
|
+
...options?.fallbackLocales || []
|
|
220
220
|
]);
|
|
221
221
|
const fallbackLocales = Array.from(localeSet);
|
|
222
222
|
const multiLocaleStrings = await this.loadTranslations({
|
|
223
|
-
mode: options
|
|
223
|
+
mode: options?.mode,
|
|
224
224
|
locales: fallbackLocales
|
|
225
225
|
});
|
|
226
226
|
return this.toSingleLocaleMap(multiLocaleStrings, fallbackLocales);
|
|
@@ -291,7 +291,6 @@ var TranslationsManager = class {
|
|
|
291
291
|
* Import translations from the v1 system to the TranslationsManager.
|
|
292
292
|
*/
|
|
293
293
|
async importTranslationsFromV1() {
|
|
294
|
-
var _a;
|
|
295
294
|
const projectId = this.cmsClient.projectId;
|
|
296
295
|
const db = this.cmsClient.db;
|
|
297
296
|
const dbPath = `Projects/${projectId}/Translations`;
|
|
@@ -332,7 +331,7 @@ var TranslationsManager = class {
|
|
|
332
331
|
const doc = await this.cmsClient.getDoc(collection2, slug, {
|
|
333
332
|
mode: "draft"
|
|
334
333
|
});
|
|
335
|
-
const linkedSheet =
|
|
334
|
+
const linkedSheet = doc?.sys?.l10nSheet;
|
|
336
335
|
if (linkedSheet) {
|
|
337
336
|
translationsDocs[docId].sys.linkedSheet = linkedSheet;
|
|
338
337
|
}
|
|
@@ -435,7 +434,7 @@ var RootCMSClient = class {
|
|
|
435
434
|
const { collection: collection2, slug } = parseDocId(docId);
|
|
436
435
|
const draftDoc = await this.getRawDoc(collection2, slug, { mode: "draft" }) || {};
|
|
437
436
|
const draftSys = draftDoc.sys || {};
|
|
438
|
-
const modifiedBy =
|
|
437
|
+
const modifiedBy = options?.modifiedBy || "root-cms-client";
|
|
439
438
|
const fields = marshalData(fieldsData || {});
|
|
440
439
|
const data = {
|
|
441
440
|
id: docId,
|
|
@@ -447,7 +446,7 @@ var RootCMSClient = class {
|
|
|
447
446
|
createdBy: draftSys.createdBy ?? modifiedBy,
|
|
448
447
|
modifiedAt: Timestamp2.now(),
|
|
449
448
|
modifiedBy,
|
|
450
|
-
locales:
|
|
449
|
+
locales: options?.locales ?? draftSys.locales ?? ["en"]
|
|
451
450
|
},
|
|
452
451
|
fields
|
|
453
452
|
};
|
|
@@ -517,7 +516,7 @@ var RootCMSClient = class {
|
|
|
517
516
|
*/
|
|
518
517
|
async publishDocs(docIds, options) {
|
|
519
518
|
const projectCollectionsPath = `Projects/${this.projectId}/Collections`;
|
|
520
|
-
const publishedBy =
|
|
519
|
+
const publishedBy = options?.publishedBy || "root-cms-client";
|
|
521
520
|
const docRefs = docIds.map((docId) => {
|
|
522
521
|
const [collection2, slug] = docId.split("/");
|
|
523
522
|
if (!collection2 || !slug) {
|
|
@@ -540,9 +539,9 @@ var RootCMSClient = class {
|
|
|
540
539
|
}
|
|
541
540
|
}
|
|
542
541
|
let batchCount = 0;
|
|
543
|
-
const batch =
|
|
542
|
+
const batch = options?.batch || this.db.batch();
|
|
544
543
|
const versionTags = ["published"];
|
|
545
|
-
if (options
|
|
544
|
+
if (options?.releaseId) {
|
|
546
545
|
versionTags.push(`release:${options.releaseId}`);
|
|
547
546
|
}
|
|
548
547
|
const publishedDocs = [];
|
|
@@ -625,12 +624,11 @@ var RootCMSClient = class {
|
|
|
625
624
|
const now = Math.ceil((/* @__PURE__ */ new Date()).getTime());
|
|
626
625
|
const snapshot = await this.db.collectionGroup("Scheduled").get();
|
|
627
626
|
const docs = snapshot.docs.filter((d) => {
|
|
628
|
-
var _a;
|
|
629
627
|
if (!d.ref.path.startsWith(projectCollectionsPath)) {
|
|
630
628
|
return false;
|
|
631
629
|
}
|
|
632
630
|
const data = d.data() || {};
|
|
633
|
-
const scheduledAt =
|
|
631
|
+
const scheduledAt = data.sys?.scheduledAt;
|
|
634
632
|
return scheduledAt && scheduledAt.toMillis && scheduledAt.toMillis() <= now;
|
|
635
633
|
}).map((d) => {
|
|
636
634
|
const dbPath = d.ref.path;
|
|
@@ -761,8 +759,7 @@ var RootCMSClient = class {
|
|
|
761
759
|
* Checks if a doc is currently "locked" for publishing.
|
|
762
760
|
*/
|
|
763
761
|
testPublishingLocked(doc) {
|
|
764
|
-
|
|
765
|
-
if ((_a = doc.sys) == null ? void 0 : _a.publishingLocked) {
|
|
762
|
+
if (doc.sys?.publishingLocked) {
|
|
766
763
|
if (doc.sys.publishingLocked.until) {
|
|
767
764
|
const now = Timestamp2.now().toMillis();
|
|
768
765
|
const until = doc.sys.publishingLocked.until.toMillis();
|
|
@@ -787,9 +784,8 @@ var RootCMSClient = class {
|
|
|
787
784
|
* replace the v1 translations system.
|
|
788
785
|
*/
|
|
789
786
|
getTranslationsManager() {
|
|
790
|
-
var _a;
|
|
791
787
|
const cmsPluginOptions = this.cmsPlugin.getConfig();
|
|
792
|
-
if (
|
|
788
|
+
if (cmsPluginOptions.experiments?.v2TranslationsManager) {
|
|
793
789
|
throw new Error(
|
|
794
790
|
"`v2TranslationsManager` is not enabled. update root.config.ts and add: `{experiments: {v2TranslationsManager: true}}`"
|
|
795
791
|
);
|
|
@@ -810,7 +806,7 @@ var RootCMSClient = class {
|
|
|
810
806
|
async loadTranslations(options) {
|
|
811
807
|
const dbPath = `Projects/${this.projectId}/Translations`;
|
|
812
808
|
let query = this.db.collection(dbPath);
|
|
813
|
-
if (options
|
|
809
|
+
if (options?.tags) {
|
|
814
810
|
query = query.where("tags", "array-contains-any", options.tags);
|
|
815
811
|
}
|
|
816
812
|
const querySnapshot = await query.get();
|
|
@@ -928,7 +924,7 @@ var RootCMSClient = class {
|
|
|
928
924
|
const dataDocRef = this.db.doc(
|
|
929
925
|
`Projects/${this.projectId}/DataSources/${dataSourceId}/Data/draft`
|
|
930
926
|
);
|
|
931
|
-
const syncedBy =
|
|
927
|
+
const syncedBy = options?.syncedBy || "root-cms-client";
|
|
932
928
|
const updatedDataSource = {
|
|
933
929
|
...dataSource,
|
|
934
930
|
syncedAt: Timestamp2.now(),
|
|
@@ -962,7 +958,7 @@ var RootCMSClient = class {
|
|
|
962
958
|
`Projects/${this.projectId}/DataSources/${dataSourceId}/published`
|
|
963
959
|
);
|
|
964
960
|
const dataRes = await this.getFromDataSource(dataSourceId, { mode: "draft" });
|
|
965
|
-
const publishedBy =
|
|
961
|
+
const publishedBy = options?.publishedBy || "root-cms-client";
|
|
966
962
|
const updatedDataSource = {
|
|
967
963
|
...dataSource,
|
|
968
964
|
publishedAt: Timestamp2.now(),
|
|
@@ -971,8 +967,8 @@ var RootCMSClient = class {
|
|
|
971
967
|
const batch = this.db.batch();
|
|
972
968
|
batch.set(dataDocRefPublished, {
|
|
973
969
|
dataSource: updatedDataSource,
|
|
974
|
-
data:
|
|
975
|
-
...
|
|
970
|
+
data: dataRes?.data || null,
|
|
971
|
+
...dataRes?.headers ? { headers: dataRes.headers } : {}
|
|
976
972
|
});
|
|
977
973
|
batch.update(dataDocRefDraft, {
|
|
978
974
|
dataSource: updatedDataSource
|
|
@@ -986,8 +982,8 @@ var RootCMSClient = class {
|
|
|
986
982
|
console.log(`published by: ${publishedBy}`);
|
|
987
983
|
}
|
|
988
984
|
async publishDataSources(dataSourceIds, options) {
|
|
989
|
-
const publishedBy =
|
|
990
|
-
const batch =
|
|
985
|
+
const publishedBy = options?.publishedBy || "root-cms-client";
|
|
986
|
+
const batch = options?.batch || this.db.batch();
|
|
991
987
|
for (const id of dataSourceIds) {
|
|
992
988
|
const dataSource = await this.getDataSource(id);
|
|
993
989
|
if (!dataSource) {
|
|
@@ -1010,8 +1006,8 @@ var RootCMSClient = class {
|
|
|
1010
1006
|
};
|
|
1011
1007
|
batch.set(dataDocRefPublished, {
|
|
1012
1008
|
dataSource: updatedDataSource,
|
|
1013
|
-
data:
|
|
1014
|
-
...
|
|
1009
|
+
data: dataRes?.data || null,
|
|
1010
|
+
...dataRes?.headers ? { headers: dataRes.headers } : {}
|
|
1015
1011
|
});
|
|
1016
1012
|
batch.update(dataDocRefDraft, { dataSource: updatedDataSource });
|
|
1017
1013
|
batch.update(dataSourceDocRef, {
|
|
@@ -1019,7 +1015,7 @@ var RootCMSClient = class {
|
|
|
1019
1015
|
publishedBy
|
|
1020
1016
|
});
|
|
1021
1017
|
}
|
|
1022
|
-
if (!
|
|
1018
|
+
if (!options?.batch || options?.commitBatch) {
|
|
1023
1019
|
await batch.commit();
|
|
1024
1020
|
}
|
|
1025
1021
|
}
|
|
@@ -1030,15 +1026,14 @@ var RootCMSClient = class {
|
|
|
1030
1026
|
throw new Error(`unsupported data source: ${dataSource.type}`);
|
|
1031
1027
|
}
|
|
1032
1028
|
async fetchHttpData(dataSource) {
|
|
1033
|
-
var _a, _b, _c;
|
|
1034
1029
|
const url = dataSource.url || "";
|
|
1035
1030
|
if (!url.startsWith("https://")) {
|
|
1036
1031
|
throw new Error(`url not supported: ${url}`);
|
|
1037
1032
|
}
|
|
1038
1033
|
const res = await fetch(url, {
|
|
1039
|
-
method:
|
|
1040
|
-
headers:
|
|
1041
|
-
body:
|
|
1034
|
+
method: dataSource.httpOptions?.method || "GET",
|
|
1035
|
+
headers: dataSource.httpOptions?.headers || [],
|
|
1036
|
+
body: dataSource.httpOptions?.body || void 0
|
|
1042
1037
|
});
|
|
1043
1038
|
if (res.status !== 200) {
|
|
1044
1039
|
const err = await res.text();
|
|
@@ -1054,7 +1049,7 @@ var RootCMSClient = class {
|
|
|
1054
1049
|
* Fetches data from a data source.
|
|
1055
1050
|
*/
|
|
1056
1051
|
async getFromDataSource(dataSourceId, options) {
|
|
1057
|
-
const mode =
|
|
1052
|
+
const mode = options?.mode || "published";
|
|
1058
1053
|
if (!(mode === "draft" || mode === "published")) {
|
|
1059
1054
|
throw new Error(`invalid mode: ${mode}`);
|
|
1060
1055
|
}
|
|
@@ -1144,12 +1139,12 @@ var RootCMSClient = class {
|
|
|
1144
1139
|
const data = {
|
|
1145
1140
|
action,
|
|
1146
1141
|
timestamp: Timestamp2.now(),
|
|
1147
|
-
by:
|
|
1148
|
-
metadata:
|
|
1142
|
+
by: options?.by || "system",
|
|
1143
|
+
metadata: options?.metadata || {}
|
|
1149
1144
|
};
|
|
1150
1145
|
const colRef = this.db.collection(`Projects/${this.projectId}/ActionLogs`);
|
|
1151
1146
|
await colRef.add(data);
|
|
1152
|
-
const metaStr =
|
|
1147
|
+
const metaStr = options?.metadata ? stringifyObj(options.metadata) : "";
|
|
1153
1148
|
console.log(`[${data.timestamp.toMillis()}] action: ${action} ${metaStr}`);
|
|
1154
1149
|
const cmsPluginConfig = this.cmsPlugin.getConfig();
|
|
1155
1150
|
if (cmsPluginConfig.onAction) {
|
|
@@ -1249,7 +1244,7 @@ function toArrayObject(arr) {
|
|
|
1249
1244
|
}
|
|
1250
1245
|
var marshalArray = toArrayObject;
|
|
1251
1246
|
function unmarshalArray(arrObject) {
|
|
1252
|
-
if (!Array.isArray(arrObject
|
|
1247
|
+
if (!Array.isArray(arrObject?._array)) {
|
|
1253
1248
|
return [];
|
|
1254
1249
|
}
|
|
1255
1250
|
const arr = arrObject._array.map((k) => arrObject[k]);
|
|
@@ -1591,12 +1586,11 @@ async function publishScheduledDocs(rootConfig) {
|
|
|
1591
1586
|
const now = Math.ceil((/* @__PURE__ */ new Date()).getTime());
|
|
1592
1587
|
const snapshot = await db.collectionGroup("Scheduled").get();
|
|
1593
1588
|
const docs = snapshot.docs.filter((d) => {
|
|
1594
|
-
var _a;
|
|
1595
1589
|
if (!d.ref.path.startsWith(projectCollectionsPath)) {
|
|
1596
1590
|
return false;
|
|
1597
1591
|
}
|
|
1598
1592
|
const data = d.data() || {};
|
|
1599
|
-
const scheduledAt =
|
|
1593
|
+
const scheduledAt = data.sys?.scheduledAt;
|
|
1600
1594
|
return scheduledAt && scheduledAt.toMillis && scheduledAt.toMillis() <= now;
|
|
1601
1595
|
}).map((d) => {
|
|
1602
1596
|
const dbPath = d.ref.path;
|
|
@@ -1672,7 +1666,7 @@ async function loadTranslations(rootConfig, options) {
|
|
|
1672
1666
|
const db = cmsPlugin.getFirestore();
|
|
1673
1667
|
const dbPath = `Projects/${projectId}/Translations`;
|
|
1674
1668
|
let query = db.collection(dbPath);
|
|
1675
|
-
if (options
|
|
1669
|
+
if (options?.tags) {
|
|
1676
1670
|
query = query.where("tags", "array-contains-any", options.tags);
|
|
1677
1671
|
}
|
|
1678
1672
|
const querySnapshot = await query.get();
|