@blinkk/root-cms 1.0.1-alpha.0 → 1.0.1
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/LICENSE +22 -0
- package/README.md +66 -0
- package/bin/root-cms.js +17 -0
- package/dist/app.js +212 -0
- package/dist/cli.js +346 -0
- package/dist/client.d.ts +273 -0
- package/dist/client.js +600 -0
- package/dist/core.d.ts +55 -0
- package/dist/core.js +865 -0
- package/dist/functions.d.ts +13 -0
- package/dist/functions.js +714 -0
- package/dist/plugin.d.ts +76 -0
- package/dist/plugin.js +1091 -0
- package/dist/project.d.ts +16 -0
- package/dist/project.js +21 -0
- package/dist/richtext.d.ts +73 -0
- package/dist/richtext.js +129 -0
- package/dist/schema--v3Ho5Lj.d.ts +211 -0
- package/dist/ui/signin.css +173 -0
- package/dist/ui/signin.js +9167 -0
- package/dist/ui/ui.css +2352 -0
- package/dist/ui/ui.js +67731 -0
- package/package.json +118 -13
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { RootConfig } from '@blinkk/root';
|
|
2
|
+
import { Timestamp, Query, WriteBatch } from 'firebase-admin/firestore';
|
|
3
|
+
import { CMSPlugin } from './plugin.js';
|
|
4
|
+
import 'firebase-admin/app';
|
|
5
|
+
|
|
6
|
+
interface Doc<Fields = any> {
|
|
7
|
+
/** The id of the doc, e.g. "Pages/foo-bar". */
|
|
8
|
+
id: string;
|
|
9
|
+
/** The collection id of the doc, e.g. "Pages". */
|
|
10
|
+
collection: string;
|
|
11
|
+
/** The slug of the doc, e.g. "foo-bar". */
|
|
12
|
+
slug: string;
|
|
13
|
+
sys: {
|
|
14
|
+
createdAt: number;
|
|
15
|
+
createdBy: string;
|
|
16
|
+
modifiedAt: number;
|
|
17
|
+
modifiedBy: string;
|
|
18
|
+
firstPublishedAt?: number;
|
|
19
|
+
firstPublishedBy?: string;
|
|
20
|
+
publishedAt?: number;
|
|
21
|
+
publishedBy?: string;
|
|
22
|
+
locales?: string[];
|
|
23
|
+
};
|
|
24
|
+
fields: Fields;
|
|
25
|
+
}
|
|
26
|
+
type DocMode = 'draft' | 'published';
|
|
27
|
+
type HttpMethod = 'GET' | 'POST';
|
|
28
|
+
interface DataSource {
|
|
29
|
+
id: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
type: 'http' | 'gsheet';
|
|
32
|
+
url: string;
|
|
33
|
+
/**
|
|
34
|
+
* Currently only used by gsheet. `array` returns the sheet as an array of
|
|
35
|
+
* arrays, `map` returns the sheet as an array of objects.
|
|
36
|
+
*/
|
|
37
|
+
dataFormat?: 'array' | 'map';
|
|
38
|
+
/**
|
|
39
|
+
* Options for HTTP requests.
|
|
40
|
+
*/
|
|
41
|
+
httpOptions?: {
|
|
42
|
+
method: HttpMethod;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
body?: string;
|
|
45
|
+
};
|
|
46
|
+
createdAt: Timestamp;
|
|
47
|
+
createdBy: string;
|
|
48
|
+
syncedAt?: Timestamp;
|
|
49
|
+
syncedBy?: string;
|
|
50
|
+
publishedAt?: Timestamp;
|
|
51
|
+
publishedBy?: string;
|
|
52
|
+
}
|
|
53
|
+
interface DataSourceData<T = any> {
|
|
54
|
+
dataSource: DataSource;
|
|
55
|
+
data: T;
|
|
56
|
+
}
|
|
57
|
+
type DataSourceMode = 'draft' | 'published';
|
|
58
|
+
interface GetDocOptions {
|
|
59
|
+
/** Mode, either "draft" or "published". */
|
|
60
|
+
mode: DocMode;
|
|
61
|
+
}
|
|
62
|
+
interface SetDocOptions {
|
|
63
|
+
/** Mode, either "draft" or "published". */
|
|
64
|
+
mode: DocMode;
|
|
65
|
+
/**
|
|
66
|
+
* Email of user modifying the doc. If blank, defaults to `root-cms-client`.
|
|
67
|
+
*/
|
|
68
|
+
modifiedBy?: string;
|
|
69
|
+
}
|
|
70
|
+
interface ListDocsOptions {
|
|
71
|
+
mode: DocMode;
|
|
72
|
+
offset?: number;
|
|
73
|
+
limit?: number;
|
|
74
|
+
orderBy?: string;
|
|
75
|
+
orderByDirection?: 'asc' | 'desc';
|
|
76
|
+
query?: (query: Query) => Query;
|
|
77
|
+
}
|
|
78
|
+
interface GetCountOptions {
|
|
79
|
+
mode: DocMode;
|
|
80
|
+
query?: (query: Query) => Query;
|
|
81
|
+
}
|
|
82
|
+
interface Translation {
|
|
83
|
+
[locale: string]: string;
|
|
84
|
+
source: string;
|
|
85
|
+
}
|
|
86
|
+
interface TranslationsMap {
|
|
87
|
+
[hash: string]: Translation;
|
|
88
|
+
}
|
|
89
|
+
interface LocaleTranslations {
|
|
90
|
+
[source: string]: string;
|
|
91
|
+
}
|
|
92
|
+
interface LoadTranslationsOptions {
|
|
93
|
+
tags?: string[];
|
|
94
|
+
}
|
|
95
|
+
interface Release {
|
|
96
|
+
id: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
docIds?: string[];
|
|
99
|
+
createdAt?: Timestamp;
|
|
100
|
+
createdBy?: string;
|
|
101
|
+
scheduledAt?: Timestamp;
|
|
102
|
+
scheduledBy?: string;
|
|
103
|
+
publishedAt?: Timestamp;
|
|
104
|
+
publishedBy?: string;
|
|
105
|
+
}
|
|
106
|
+
declare class RootCMSClient {
|
|
107
|
+
private readonly rootConfig;
|
|
108
|
+
private readonly cmsPlugin;
|
|
109
|
+
private readonly projectId;
|
|
110
|
+
private readonly app;
|
|
111
|
+
private readonly db;
|
|
112
|
+
constructor(rootConfig: RootConfig);
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves doc data from Root.js CMS.
|
|
115
|
+
*/
|
|
116
|
+
getDoc<Fields = any>(collectionId: string, slug: string, options: GetDocOptions): Promise<Doc<Fields> | null>;
|
|
117
|
+
/**
|
|
118
|
+
* Retrieves raw doc data as stored in the database. Only use this if you know
|
|
119
|
+
* what you are doing.
|
|
120
|
+
*/
|
|
121
|
+
getRawDoc(collectionId: string, slug: string, options: GetDocOptions): Promise<any | null>;
|
|
122
|
+
setRawDoc(collectionId: string, slug: string, data: any, options: SetDocOptions): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Lists docs from a Root.js CMS collection.
|
|
125
|
+
*/
|
|
126
|
+
listDocs<T>(collectionId: string, options: ListDocsOptions): Promise<{
|
|
127
|
+
docs: T[];
|
|
128
|
+
}>;
|
|
129
|
+
/**
|
|
130
|
+
* Returns the number of docs in a Root.js CMS collection.
|
|
131
|
+
*/
|
|
132
|
+
getDocsCount(collectionId: string, options: GetCountOptions): Promise<number>;
|
|
133
|
+
/**
|
|
134
|
+
* Batch publishes a set of docs by id.
|
|
135
|
+
*/
|
|
136
|
+
publishDocs(docIds: string[], options?: {
|
|
137
|
+
publishedBy: string;
|
|
138
|
+
batch?: WriteBatch;
|
|
139
|
+
}): Promise<any[]>;
|
|
140
|
+
/**
|
|
141
|
+
* Publishes scheduled docs.
|
|
142
|
+
*/
|
|
143
|
+
publishScheduledDocs(): Promise<any[]>;
|
|
144
|
+
/**
|
|
145
|
+
* Publishes docs in scheduled releases.
|
|
146
|
+
*/
|
|
147
|
+
publishScheduledReleases(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Loads translations saved in the translations collection, optionally
|
|
150
|
+
* filtered by tag.
|
|
151
|
+
*
|
|
152
|
+
* Returns a map like:
|
|
153
|
+
* ```
|
|
154
|
+
* {
|
|
155
|
+
* "<hash>": {"source": "Hello", "es": "Hola", "fr": "Bonjour"},
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
loadTranslations(options?: LoadTranslationsOptions): Promise<TranslationsMap>;
|
|
160
|
+
/**
|
|
161
|
+
* Saves a map of translations, e.g.:
|
|
162
|
+
* ```
|
|
163
|
+
* await client.saveTranslations({
|
|
164
|
+
* "Hello": {"es": "Hola", "fr": "Bonjour"},
|
|
165
|
+
* });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
saveTranslations(translations: {
|
|
169
|
+
[source: string]: {
|
|
170
|
+
[locale: string]: string;
|
|
171
|
+
};
|
|
172
|
+
}, tags?: string[]): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Returns the "key" used for a translation as stored in the db. Translations
|
|
175
|
+
* are stored under `Projects/<project id>/Translations/<sha1 hash>`.
|
|
176
|
+
*/
|
|
177
|
+
getTranslationKey(source: string): string;
|
|
178
|
+
/**
|
|
179
|
+
* Cleans a string that's used for translations. Performs the following:
|
|
180
|
+
* - Removes any leading/trailing whitespace
|
|
181
|
+
* - Removes spaces at the end of any line
|
|
182
|
+
*/
|
|
183
|
+
normalizeString(str: string): string;
|
|
184
|
+
/**
|
|
185
|
+
* Loads translations for a particular locale.
|
|
186
|
+
*
|
|
187
|
+
* Returns a map like:
|
|
188
|
+
* ```
|
|
189
|
+
* {
|
|
190
|
+
* "Hello": "Bonjour",
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
loadTranslationsForLocale(locale: string, options?: LoadTranslationsOptions): Promise<LocaleTranslations>;
|
|
195
|
+
/**
|
|
196
|
+
* Returns a data source configuration object.
|
|
197
|
+
*/
|
|
198
|
+
getDataSource(dataSourceId: string): Promise<DataSource | null>;
|
|
199
|
+
/**
|
|
200
|
+
* Syncs a data source to draft state.
|
|
201
|
+
*/
|
|
202
|
+
syncDataSource(dataSourceId: string, options?: {
|
|
203
|
+
syncedBy?: string;
|
|
204
|
+
}): Promise<void>;
|
|
205
|
+
publishDataSource(dataSourceId: string, options?: {
|
|
206
|
+
publishedBy?: string;
|
|
207
|
+
}): Promise<void>;
|
|
208
|
+
private fetchData;
|
|
209
|
+
private fetchHttpData;
|
|
210
|
+
/**
|
|
211
|
+
* Fetches data from a data source.
|
|
212
|
+
*/
|
|
213
|
+
getFromDataSource<T = any>(dataSourceId: string, options?: {
|
|
214
|
+
mode?: 'draft' | 'published';
|
|
215
|
+
}): Promise<DataSourceData<T> | null>;
|
|
216
|
+
/**
|
|
217
|
+
* Verifies user exists in the ACL list.
|
|
218
|
+
*/
|
|
219
|
+
userExistsInAcl(email: string): Promise<boolean>;
|
|
220
|
+
}
|
|
221
|
+
declare function getCmsPlugin(rootConfig: RootConfig): CMSPlugin;
|
|
222
|
+
/**
|
|
223
|
+
* Walks the data tree and converts any Timestamp objects to millis and any
|
|
224
|
+
* _array maps to normal arrays.
|
|
225
|
+
*
|
|
226
|
+
* E.g.:
|
|
227
|
+
*
|
|
228
|
+
* normalizeData({
|
|
229
|
+
* sys: {modifiedAt: Timestamp(123)},
|
|
230
|
+
* fields: {
|
|
231
|
+
* _array: ['asdf'],
|
|
232
|
+
* asdf: {title: 'hello'}
|
|
233
|
+
* }
|
|
234
|
+
* })
|
|
235
|
+
* // => {sys: {modifiedAt: 123}, fields: {foo: [{title: 'hello'}]}}
|
|
236
|
+
*/
|
|
237
|
+
declare function unmarshalData(data: any): any;
|
|
238
|
+
/** @deprecated Use `unmarshalData()` instead. */
|
|
239
|
+
declare function normalizeData(data: any): any;
|
|
240
|
+
interface ArrayObject {
|
|
241
|
+
[key: string]: any;
|
|
242
|
+
_array: string[];
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Serializes an array into an `ArrayObject`, e.g.:
|
|
246
|
+
*
|
|
247
|
+
* ```
|
|
248
|
+
* marshalArray([1, 2, 3])
|
|
249
|
+
* // => {a: 1, b: 2, c: 3, _array: ['a', 'b', 'c']}
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* This database storage method makes it easier to update a single field in a
|
|
253
|
+
* deeply nested array object.
|
|
254
|
+
*/
|
|
255
|
+
declare function marshalArray(arr: any[]): ArrayObject;
|
|
256
|
+
/**
|
|
257
|
+
* Converts an `ArrayObject` to a normal array.
|
|
258
|
+
*/
|
|
259
|
+
declare function unmarshalArray(arrObject: ArrayObject): any[];
|
|
260
|
+
/**
|
|
261
|
+
* Converts a translations map from `loadTranslations()` to a map of source to
|
|
262
|
+
* translated string for a particular locale.
|
|
263
|
+
*
|
|
264
|
+
* Returns a map like:
|
|
265
|
+
* ```
|
|
266
|
+
* {
|
|
267
|
+
* "Hello": "Bonjour",
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
declare function translationsForLocale(translationsMap: TranslationsMap, locale: string): LocaleTranslations;
|
|
272
|
+
|
|
273
|
+
export { type ArrayObject, type DataSource, type DataSourceData, type DataSourceMode, type Doc, type DocMode, type GetCountOptions, type GetDocOptions, type HttpMethod, type ListDocsOptions, type LoadTranslationsOptions, type LocaleTranslations, type Release, RootCMSClient, type SetDocOptions, type Translation, type TranslationsMap, getCmsPlugin, marshalArray, normalizeData, translationsForLocale, unmarshalArray, unmarshalData };
|