@blinkk/root-cms 1.0.7 → 1.0.9
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/cli.js +1 -1
- package/dist/client-17zSZX1E.d.ts +405 -0
- package/dist/client.d.ts +3 -272
- package/dist/client.js +49 -2
- package/dist/core.d.ts +2 -3
- package/dist/core.js +49 -2
- package/dist/functions.js +49 -2
- package/dist/plugin.d.ts +4 -98
- package/dist/plugin.js +80 -2
- package/dist/ui/ui.css +60 -19
- package/dist/ui/ui.js +435 -122
- package/package.json +3 -3
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
import { Request, Plugin, RootConfig } from '@blinkk/root';
|
|
2
|
+
import { Firestore, Timestamp, Query, WriteBatch } from 'firebase-admin/firestore';
|
|
3
|
+
import { App } from 'firebase-admin/app';
|
|
4
|
+
|
|
5
|
+
interface CMSUser {
|
|
6
|
+
email: string;
|
|
7
|
+
}
|
|
8
|
+
interface CMSSidebarTool {
|
|
9
|
+
/** URL for the sidebar icon image. */
|
|
10
|
+
icon?: string;
|
|
11
|
+
/** Label. */
|
|
12
|
+
label?: string;
|
|
13
|
+
/** Iframe URL to render for the tool. */
|
|
14
|
+
iframeUrl?: string;
|
|
15
|
+
}
|
|
16
|
+
type CMSPluginOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* The ID of the project. Data will be stored under the namespace
|
|
19
|
+
* `Projects/${id}` in firestore.
|
|
20
|
+
*/
|
|
21
|
+
id?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The name of the project. Used in the header of the CMS to help identify
|
|
24
|
+
* the project.
|
|
25
|
+
*/
|
|
26
|
+
name?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Firebase config object, which can be obtained in the Firebase Console by
|
|
29
|
+
* going to "Project Settings".
|
|
30
|
+
*/
|
|
31
|
+
firebaseConfig: {
|
|
32
|
+
[key: string]: string | undefined;
|
|
33
|
+
apiKey: string;
|
|
34
|
+
authDomain: string;
|
|
35
|
+
projectId: string;
|
|
36
|
+
storageBucket: string;
|
|
37
|
+
databaseId?: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* GAPI credentials. Include if using Google Drive and Google Sheets features.
|
|
41
|
+
* See: https://developers.google.com/sheets/api/quickstart/js
|
|
42
|
+
*/
|
|
43
|
+
gapi?: {
|
|
44
|
+
/** https://developers.google.com/sheets/api/quickstart/js#create_an_api_key */
|
|
45
|
+
apiKey: string;
|
|
46
|
+
/** https://developers.google.com/sheets/api/quickstart/js#authorize_credentials_for_a_web_application */
|
|
47
|
+
clientId: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Secret value(s) used for signing the user authentication cookie.
|
|
51
|
+
* @deprecated This is now handled directly by root's sessionMiddleware under
|
|
52
|
+
* `server.sessionCookieSecret` in root.config.ts.
|
|
53
|
+
*/
|
|
54
|
+
cookieSecret?: string | string[];
|
|
55
|
+
/** Function called to check if a user should have access to the CMS. */
|
|
56
|
+
isUserAuthorized?: (req: Request, user: CMSUser) => boolean | Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Function to call to check if login is required for a particular request.
|
|
59
|
+
*/
|
|
60
|
+
isLoginRequired?: (req: Request) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* URL to GCI service for transforming uploaded GCS images to a Google App
|
|
63
|
+
* Engine Images API serving URL.
|
|
64
|
+
*
|
|
65
|
+
* Setting this to `true` uses the default hosted service at
|
|
66
|
+
* https://gci.rootjs.dev.
|
|
67
|
+
*
|
|
68
|
+
* To set up GCI:
|
|
69
|
+
*
|
|
70
|
+
* - Create a GCS bucket with fine-grained permissions
|
|
71
|
+
* - Share owner access to the bucket with the service account returned in
|
|
72
|
+
* https://gci.rootjs.dev/_/service_account
|
|
73
|
+
*
|
|
74
|
+
* To disable GCI, leave this value empty or set to `false`, which which will
|
|
75
|
+
* serve images directly from GCS instead.
|
|
76
|
+
*/
|
|
77
|
+
gci?: string | boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Customization options for the CMS sidebar.
|
|
80
|
+
*/
|
|
81
|
+
sidebar?: {
|
|
82
|
+
/**
|
|
83
|
+
* Sidebar tools, a map of the sidebar id to config options. The sidebar
|
|
84
|
+
* tool is url-mapped to `/cms/tools/:id` and displays the tool in an
|
|
85
|
+
* iframe.
|
|
86
|
+
*/
|
|
87
|
+
tools?: Record<string, CMSSidebarTool>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Callback when an action occurs.
|
|
91
|
+
*/
|
|
92
|
+
onAction?: (action: Action) => any;
|
|
93
|
+
};
|
|
94
|
+
type CMSPlugin = Plugin & {
|
|
95
|
+
name: 'root-cms';
|
|
96
|
+
getConfig: () => CMSPluginOptions;
|
|
97
|
+
getFirebaseApp: () => App;
|
|
98
|
+
getFirestore: () => Firestore;
|
|
99
|
+
};
|
|
100
|
+
declare function cmsPlugin(options: CMSPluginOptions): CMSPlugin;
|
|
101
|
+
|
|
102
|
+
interface Doc<Fields = any> {
|
|
103
|
+
/** The id of the doc, e.g. "Pages/foo-bar". */
|
|
104
|
+
id: string;
|
|
105
|
+
/** The collection id of the doc, e.g. "Pages". */
|
|
106
|
+
collection: string;
|
|
107
|
+
/** The slug of the doc, e.g. "foo-bar". */
|
|
108
|
+
slug: string;
|
|
109
|
+
sys: {
|
|
110
|
+
createdAt: number;
|
|
111
|
+
createdBy: string;
|
|
112
|
+
modifiedAt: number;
|
|
113
|
+
modifiedBy: string;
|
|
114
|
+
firstPublishedAt?: number;
|
|
115
|
+
firstPublishedBy?: string;
|
|
116
|
+
publishedAt?: number;
|
|
117
|
+
publishedBy?: string;
|
|
118
|
+
locales?: string[];
|
|
119
|
+
};
|
|
120
|
+
fields: Fields;
|
|
121
|
+
}
|
|
122
|
+
type DocMode = 'draft' | 'published';
|
|
123
|
+
type HttpMethod = 'GET' | 'POST';
|
|
124
|
+
interface DataSource {
|
|
125
|
+
id: string;
|
|
126
|
+
description?: string;
|
|
127
|
+
type: 'http' | 'gsheet';
|
|
128
|
+
url: string;
|
|
129
|
+
/**
|
|
130
|
+
* Currently only used by gsheet. `array` returns the sheet as an array of
|
|
131
|
+
* arrays, `map` returns the sheet as an array of objects.
|
|
132
|
+
*/
|
|
133
|
+
dataFormat?: 'array' | 'map';
|
|
134
|
+
/**
|
|
135
|
+
* Options for HTTP requests.
|
|
136
|
+
*/
|
|
137
|
+
httpOptions?: {
|
|
138
|
+
method: HttpMethod;
|
|
139
|
+
headers?: Record<string, string>;
|
|
140
|
+
body?: string;
|
|
141
|
+
};
|
|
142
|
+
createdAt: Timestamp;
|
|
143
|
+
createdBy: string;
|
|
144
|
+
syncedAt?: Timestamp;
|
|
145
|
+
syncedBy?: string;
|
|
146
|
+
publishedAt?: Timestamp;
|
|
147
|
+
publishedBy?: string;
|
|
148
|
+
}
|
|
149
|
+
interface DataSourceData<T = any> {
|
|
150
|
+
dataSource: DataSource;
|
|
151
|
+
data: T;
|
|
152
|
+
}
|
|
153
|
+
type DataSourceMode = 'draft' | 'published';
|
|
154
|
+
interface GetDocOptions {
|
|
155
|
+
/** Mode, either "draft" or "published". */
|
|
156
|
+
mode: DocMode;
|
|
157
|
+
}
|
|
158
|
+
interface SetDocOptions {
|
|
159
|
+
/** Mode, either "draft" or "published". */
|
|
160
|
+
mode: DocMode;
|
|
161
|
+
/**
|
|
162
|
+
* Email of user modifying the doc. If blank, defaults to `root-cms-client`.
|
|
163
|
+
*/
|
|
164
|
+
modifiedBy?: string;
|
|
165
|
+
}
|
|
166
|
+
interface ListDocsOptions {
|
|
167
|
+
mode: DocMode;
|
|
168
|
+
offset?: number;
|
|
169
|
+
limit?: number;
|
|
170
|
+
orderBy?: string;
|
|
171
|
+
orderByDirection?: 'asc' | 'desc';
|
|
172
|
+
query?: (query: Query) => Query;
|
|
173
|
+
}
|
|
174
|
+
interface GetCountOptions {
|
|
175
|
+
mode: DocMode;
|
|
176
|
+
query?: (query: Query) => Query;
|
|
177
|
+
}
|
|
178
|
+
interface Translation {
|
|
179
|
+
[locale: string]: string;
|
|
180
|
+
source: string;
|
|
181
|
+
}
|
|
182
|
+
interface TranslationsMap {
|
|
183
|
+
[hash: string]: Translation;
|
|
184
|
+
}
|
|
185
|
+
interface LocaleTranslations {
|
|
186
|
+
[source: string]: string;
|
|
187
|
+
}
|
|
188
|
+
interface LoadTranslationsOptions {
|
|
189
|
+
tags?: string[];
|
|
190
|
+
}
|
|
191
|
+
interface Release {
|
|
192
|
+
id: string;
|
|
193
|
+
description?: string;
|
|
194
|
+
docIds?: string[];
|
|
195
|
+
createdAt?: Timestamp;
|
|
196
|
+
createdBy?: string;
|
|
197
|
+
scheduledAt?: Timestamp;
|
|
198
|
+
scheduledBy?: string;
|
|
199
|
+
publishedAt?: Timestamp;
|
|
200
|
+
publishedBy?: string;
|
|
201
|
+
}
|
|
202
|
+
interface Action<T = any> {
|
|
203
|
+
/**
|
|
204
|
+
* The name of the action.
|
|
205
|
+
*/
|
|
206
|
+
action: string;
|
|
207
|
+
/**
|
|
208
|
+
* The user's email that performed the action (or "system").
|
|
209
|
+
*/
|
|
210
|
+
by?: string;
|
|
211
|
+
/**
|
|
212
|
+
* Timestamp when the action occurred.
|
|
213
|
+
*/
|
|
214
|
+
timestamp: Timestamp;
|
|
215
|
+
/**
|
|
216
|
+
* Metadata for the action.
|
|
217
|
+
*/
|
|
218
|
+
metadata?: T;
|
|
219
|
+
}
|
|
220
|
+
interface ListActionsOptions {
|
|
221
|
+
/**
|
|
222
|
+
* Filter by a specific action. Defaults to all actions.
|
|
223
|
+
*/
|
|
224
|
+
action?: string;
|
|
225
|
+
/**
|
|
226
|
+
* Filter by a specific user. Defaults to all users.
|
|
227
|
+
*/
|
|
228
|
+
by?: string;
|
|
229
|
+
/**
|
|
230
|
+
* Max number of actions to return. Defaults to 100.
|
|
231
|
+
*/
|
|
232
|
+
limit?: number;
|
|
233
|
+
}
|
|
234
|
+
declare class RootCMSClient {
|
|
235
|
+
private readonly rootConfig;
|
|
236
|
+
private readonly cmsPlugin;
|
|
237
|
+
private readonly projectId;
|
|
238
|
+
private readonly app;
|
|
239
|
+
private readonly db;
|
|
240
|
+
constructor(rootConfig: RootConfig);
|
|
241
|
+
/**
|
|
242
|
+
* Retrieves doc data from Root.js CMS.
|
|
243
|
+
*/
|
|
244
|
+
getDoc<Fields = any>(collectionId: string, slug: string, options: GetDocOptions): Promise<Doc<Fields> | null>;
|
|
245
|
+
/**
|
|
246
|
+
* Retrieves raw doc data as stored in the database. Only use this if you know
|
|
247
|
+
* what you are doing.
|
|
248
|
+
*/
|
|
249
|
+
getRawDoc(collectionId: string, slug: string, options: GetDocOptions): Promise<any | null>;
|
|
250
|
+
setRawDoc(collectionId: string, slug: string, data: any, options: SetDocOptions): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Lists docs from a Root.js CMS collection.
|
|
253
|
+
*/
|
|
254
|
+
listDocs<T>(collectionId: string, options: ListDocsOptions): Promise<{
|
|
255
|
+
docs: T[];
|
|
256
|
+
}>;
|
|
257
|
+
/**
|
|
258
|
+
* Returns the number of docs in a Root.js CMS collection.
|
|
259
|
+
*/
|
|
260
|
+
getDocsCount(collectionId: string, options: GetCountOptions): Promise<number>;
|
|
261
|
+
/**
|
|
262
|
+
* Batch publishes a set of docs by id.
|
|
263
|
+
*/
|
|
264
|
+
publishDocs(docIds: string[], options?: {
|
|
265
|
+
publishedBy: string;
|
|
266
|
+
batch?: WriteBatch;
|
|
267
|
+
}): Promise<any[]>;
|
|
268
|
+
/**
|
|
269
|
+
* Publishes scheduled docs.
|
|
270
|
+
*/
|
|
271
|
+
publishScheduledDocs(): Promise<any[]>;
|
|
272
|
+
/**
|
|
273
|
+
* Publishes docs in scheduled releases.
|
|
274
|
+
*/
|
|
275
|
+
publishScheduledReleases(): Promise<void>;
|
|
276
|
+
/**
|
|
277
|
+
* Loads translations saved in the translations collection, optionally
|
|
278
|
+
* filtered by tag.
|
|
279
|
+
*
|
|
280
|
+
* Returns a map like:
|
|
281
|
+
* ```
|
|
282
|
+
* {
|
|
283
|
+
* "<hash>": {"source": "Hello", "es": "Hola", "fr": "Bonjour"},
|
|
284
|
+
* }
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
loadTranslations(options?: LoadTranslationsOptions): Promise<TranslationsMap>;
|
|
288
|
+
/**
|
|
289
|
+
* Saves a map of translations, e.g.:
|
|
290
|
+
* ```
|
|
291
|
+
* await client.saveTranslations({
|
|
292
|
+
* "Hello": {"es": "Hola", "fr": "Bonjour"},
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
saveTranslations(translations: {
|
|
297
|
+
[source: string]: {
|
|
298
|
+
[locale: string]: string;
|
|
299
|
+
};
|
|
300
|
+
}, tags?: string[]): Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* Returns the "key" used for a translation as stored in the db. Translations
|
|
303
|
+
* are stored under `Projects/<project id>/Translations/<sha1 hash>`.
|
|
304
|
+
*/
|
|
305
|
+
getTranslationKey(source: string): string;
|
|
306
|
+
/**
|
|
307
|
+
* Cleans a string that's used for translations. Performs the following:
|
|
308
|
+
* - Removes any leading/trailing whitespace
|
|
309
|
+
* - Removes spaces at the end of any line
|
|
310
|
+
*/
|
|
311
|
+
normalizeString(str: string): string;
|
|
312
|
+
/**
|
|
313
|
+
* Loads translations for a particular locale.
|
|
314
|
+
*
|
|
315
|
+
* Returns a map like:
|
|
316
|
+
* ```
|
|
317
|
+
* {
|
|
318
|
+
* "Hello": "Bonjour",
|
|
319
|
+
* }
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
loadTranslationsForLocale(locale: string, options?: LoadTranslationsOptions): Promise<LocaleTranslations>;
|
|
323
|
+
/**
|
|
324
|
+
* Returns a data source configuration object.
|
|
325
|
+
*/
|
|
326
|
+
getDataSource(dataSourceId: string): Promise<DataSource | null>;
|
|
327
|
+
/**
|
|
328
|
+
* Syncs a data source to draft state.
|
|
329
|
+
*/
|
|
330
|
+
syncDataSource(dataSourceId: string, options?: {
|
|
331
|
+
syncedBy?: string;
|
|
332
|
+
}): Promise<void>;
|
|
333
|
+
publishDataSource(dataSourceId: string, options?: {
|
|
334
|
+
publishedBy?: string;
|
|
335
|
+
}): Promise<void>;
|
|
336
|
+
private fetchData;
|
|
337
|
+
private fetchHttpData;
|
|
338
|
+
/**
|
|
339
|
+
* Fetches data from a data source.
|
|
340
|
+
*/
|
|
341
|
+
getFromDataSource<T = any>(dataSourceId: string, options?: {
|
|
342
|
+
mode?: 'draft' | 'published';
|
|
343
|
+
}): Promise<DataSourceData<T> | null>;
|
|
344
|
+
/**
|
|
345
|
+
* Verifies user exists in the ACL list.
|
|
346
|
+
*/
|
|
347
|
+
userExistsInAcl(email: string): Promise<boolean>;
|
|
348
|
+
logAction(action: string, options?: {
|
|
349
|
+
by?: string;
|
|
350
|
+
metadata?: any;
|
|
351
|
+
}): Promise<void>;
|
|
352
|
+
}
|
|
353
|
+
declare function getCmsPlugin(rootConfig: RootConfig): CMSPlugin;
|
|
354
|
+
/**
|
|
355
|
+
* Walks the data tree and converts any Timestamp objects to millis and any
|
|
356
|
+
* _array maps to normal arrays.
|
|
357
|
+
*
|
|
358
|
+
* E.g.:
|
|
359
|
+
*
|
|
360
|
+
* normalizeData({
|
|
361
|
+
* sys: {modifiedAt: Timestamp(123)},
|
|
362
|
+
* fields: {
|
|
363
|
+
* _array: ['asdf'],
|
|
364
|
+
* asdf: {title: 'hello'}
|
|
365
|
+
* }
|
|
366
|
+
* })
|
|
367
|
+
* // => {sys: {modifiedAt: 123}, fields: {foo: [{title: 'hello'}]}}
|
|
368
|
+
*/
|
|
369
|
+
declare function unmarshalData(data: any): any;
|
|
370
|
+
/** @deprecated Use `unmarshalData()` instead. */
|
|
371
|
+
declare function normalizeData(data: any): any;
|
|
372
|
+
interface ArrayObject {
|
|
373
|
+
[key: string]: any;
|
|
374
|
+
_array: string[];
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Serializes an array into an `ArrayObject`, e.g.:
|
|
378
|
+
*
|
|
379
|
+
* ```
|
|
380
|
+
* marshalArray([1, 2, 3])
|
|
381
|
+
* // => {a: 1, b: 2, c: 3, _array: ['a', 'b', 'c']}
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* This database storage method makes it easier to update a single field in a
|
|
385
|
+
* deeply nested array object.
|
|
386
|
+
*/
|
|
387
|
+
declare function marshalArray(arr: any[]): ArrayObject;
|
|
388
|
+
/**
|
|
389
|
+
* Converts an `ArrayObject` to a normal array.
|
|
390
|
+
*/
|
|
391
|
+
declare function unmarshalArray(arrObject: ArrayObject): any[];
|
|
392
|
+
/**
|
|
393
|
+
* Converts a translations map from `loadTranslations()` to a map of source to
|
|
394
|
+
* translated string for a particular locale.
|
|
395
|
+
*
|
|
396
|
+
* Returns a map like:
|
|
397
|
+
* ```
|
|
398
|
+
* {
|
|
399
|
+
* "Hello": "Bonjour",
|
|
400
|
+
* }
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
declare function translationsForLocale(translationsMap: TranslationsMap, locale: string): LocaleTranslations;
|
|
404
|
+
|
|
405
|
+
export { type Action as A, type CMSUser as C, type Doc as D, type GetDocOptions as G, type HttpMethod as H, type LoadTranslationsOptions as L, type Release as R, type SetDocOptions as S, type TranslationsMap as T, type LocaleTranslations as a, type DocMode as b, type DataSource as c, type DataSourceData as d, type DataSourceMode as e, type ListDocsOptions as f, type GetCountOptions as g, type Translation as h, type ListActionsOptions as i, RootCMSClient as j, getCmsPlugin as k, type ArrayObject as l, marshalArray as m, normalizeData as n, unmarshalArray as o, type CMSSidebarTool as p, type CMSPluginOptions as q, type CMSPlugin as r, cmsPlugin as s, translationsForLocale as t, unmarshalData as u };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,273 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import '@blinkk/root';
|
|
2
|
+
import 'firebase-admin/firestore';
|
|
3
|
+
export { A as Action, l as ArrayObject, c as DataSource, d as DataSourceData, e as DataSourceMode, D as Doc, b as DocMode, g as GetCountOptions, G as GetDocOptions, H as HttpMethod, i as ListActionsOptions, f as ListDocsOptions, L as LoadTranslationsOptions, a as LocaleTranslations, R as Release, j as RootCMSClient, S as SetDocOptions, h as Translation, T as TranslationsMap, k as getCmsPlugin, m as marshalArray, n as normalizeData, t as translationsForLocale, o as unmarshalArray, u as unmarshalData } from './client-17zSZX1E.js';
|
|
4
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 };
|