@blinkk/root-cms 1.3.12 → 2.0.0-rc.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.
@@ -127,6 +127,7 @@ type CMSPlugin = Plugin & {
127
127
  getFirestore: () => Firestore;
128
128
  };
129
129
  declare function cmsPlugin(options: CMSPluginOptions): CMSPlugin;
130
+ declare function getCmsPlugin(rootConfig: RootConfig): CMSPlugin;
130
131
 
131
132
  interface Doc<Fields = any> {
132
133
  /** The id of the doc, e.g. "Pages/foo-bar". */
@@ -154,6 +155,23 @@ interface Doc<Fields = any> {
154
155
  };
155
156
  fields: Fields;
156
157
  }
158
+ interface TranslationsDoc {
159
+ id: string;
160
+ sys: {
161
+ modifiedAt: Timestamp;
162
+ modifiedBy: string;
163
+ publishedAt?: Timestamp;
164
+ publishedBy?: string;
165
+ linkedSheet?: {
166
+ spreadsheetId: string;
167
+ gid: number;
168
+ linkedAt: Timestamp;
169
+ linkedBy: string;
170
+ };
171
+ tags?: string[];
172
+ };
173
+ strings: TranslationsMap;
174
+ }
157
175
  type DocMode = 'draft' | 'published';
158
176
  type UserRole = 'ADMIN' | 'EDITOR' | 'VIEWER';
159
177
  type HttpMethod = 'GET' | 'POST';
@@ -294,6 +312,15 @@ declare class RootCMSClient {
294
312
  * what you are doing.
295
313
  */
296
314
  getRawDoc(collectionId: string, slug: string, options: GetDocOptions): Promise<any | null>;
315
+ dbCollectionDocsPath(collectionId: string, options: {
316
+ mode: 'draft' | 'published';
317
+ }): string;
318
+ dbDocPath(collectionId: string, slug: string, options: {
319
+ mode: 'draft' | 'published';
320
+ }): string;
321
+ dbDocRef(collectionId: string, slug: string, options: {
322
+ mode: 'draft' | 'published';
323
+ }): FirebaseFirestore.DocumentReference<FirebaseFirestore.DocumentData>;
297
324
  /**
298
325
  * Saves draft data to a doc.
299
326
  *
@@ -331,35 +358,33 @@ declare class RootCMSClient {
331
358
  * Publishes docs in scheduled releases.
332
359
  */
333
360
  publishScheduledReleases(): Promise<void>;
361
+ publishTranslationsDoc(translationsId: string, options?: {
362
+ batch?: WriteBatch;
363
+ publishedBy?: string;
364
+ }): Promise<void>;
334
365
  /**
335
366
  * Checks if a doc is currently "locked" for publishing.
336
367
  */
337
368
  testPublishingLocked(doc: Doc): boolean;
338
369
  /**
339
- * Loads translations saved in the translations collection, optionally
340
- * filtered by tag.
370
+ * Loads all published strings in the db.
341
371
  *
342
- * Returns a map like:
343
372
  * ```
344
373
  * {
345
374
  * "<hash>": {"source": "Hello", "es": "Hola", "fr": "Bonjour"},
346
375
  * }
347
376
  * ```
377
+ *
378
+ * @deprecated Use `createBatchRequest()` to fetch draft/published translations.
348
379
  */
349
380
  loadTranslations(options?: LoadTranslationsOptions): Promise<TranslationsMap>;
350
- /**
351
- * Saves a map of translations, e.g.:
352
- * ```
353
- * await client.saveTranslations({
354
- * "Hello": {"es": "Hola", "fr": "Bonjour"},
355
- * });
356
- * ```
357
- */
358
- saveTranslations(translations: {
381
+ saveDraftTranslations(translationsId: string, translations: {
359
382
  [source: string]: {
360
383
  [locale: string]: string;
361
384
  };
362
- }, tags?: string[]): Promise<void>;
385
+ }, options?: {
386
+ modifiedby?: string;
387
+ }): Promise<void>;
363
388
  /**
364
389
  * Returns the "key" used for a translation as stored in the db. Translations
365
390
  * are stored under `Projects/<project id>/Translations/<sha1 hash>`.
@@ -403,6 +428,18 @@ declare class RootCMSClient {
403
428
  getFromDataSource<T = any>(dataSourceId: string, options?: {
404
429
  mode?: 'draft' | 'published';
405
430
  }): Promise<DataSourceData<T> | null>;
431
+ dbDataSourceDataPath(dataSourceId: string, options: {
432
+ mode: 'draft' | 'published';
433
+ }): string;
434
+ dbDataSourceDataRef(dataSourceId: string, options: {
435
+ mode: 'draft' | 'published';
436
+ }): FirebaseFirestore.DocumentReference<FirebaseFirestore.DocumentData>;
437
+ dbTranslationsPath(translationsId: string, options: {
438
+ mode: 'draft' | 'published';
439
+ }): string;
440
+ dbTranslationsRef(translationsId: string, options: {
441
+ mode: 'draft' | 'published';
442
+ }): FirebaseFirestore.DocumentReference<FirebaseFirestore.DocumentData>;
406
443
  /**
407
444
  * Gets the user's role from the project's ACL.
408
445
  */
@@ -415,12 +452,90 @@ declare class RootCMSClient {
415
452
  by?: string;
416
453
  metadata?: any;
417
454
  }): Promise<void>;
455
+ createBatchRequest(options: BatchRequestOptions): BatchRequest;
456
+ }
457
+ interface BatchRequestOptions {
458
+ mode: 'draft' | 'published';
459
+ /**
460
+ * Whether to automatically fetch translations for the docs retrieved in the
461
+ * request.
462
+ */
463
+ translate?: boolean;
464
+ }
465
+ interface BatchRequestQuery {
466
+ queryId: string;
467
+ collectionId: string;
468
+ queryOptions?: BatchRequestQueryOptions;
469
+ }
470
+ interface BatchRequestQueryOptions {
471
+ offset?: number;
472
+ limit?: number;
473
+ orderBy?: string;
474
+ orderByDirection?: 'asc' | 'desc';
475
+ query?: (query: Query) => Query;
476
+ }
477
+ declare class BatchRequest {
478
+ cmsClient: RootCMSClient;
479
+ private options;
480
+ private db;
481
+ private docIds;
482
+ private dataSourceIds;
483
+ private queries;
484
+ private translationsIds;
485
+ constructor(cmsClient: RootCMSClient, options: BatchRequestOptions);
486
+ /**
487
+ * Adds a doc to the batch request.
488
+ */
489
+ addDoc(docId: string): void;
490
+ /**
491
+ * Adds a data source to the batch request.
492
+ */
493
+ addDataSource(dataSourceId: string): void;
494
+ /**
495
+ * Adds a collection-based query to the batch request.
496
+ */
497
+ addQuery(queryId: string, collectionId: string, queryOptions?: BatchRequestQueryOptions): void;
498
+ /**
499
+ * Adds a translation file to the request.
500
+ */
501
+ addTranslations(translationsId: string): void;
502
+ /**
503
+ * Fetches data from the DB.
504
+ */
505
+ fetch(): Promise<BatchResponse>;
506
+ private fetchDocs;
507
+ private fetchQueries;
508
+ private fetchDataSources;
509
+ private fetchTranslations;
510
+ }
511
+ declare class BatchResponse {
512
+ docs: Record<string, Doc>;
513
+ queries: Record<string, Doc[]>;
514
+ dataSources: Record<string, DataSourceData>;
515
+ translations: Record<string, TranslationsDoc>;
516
+ /**
517
+ * Returns a map of translations for a given locale or locale fallbacks.
518
+ *
519
+ * The input is either a single locale (e.g. "de") or an array of locales
520
+ * representing the fallback tree, e.g. ["en-CA", "en-GB", "en"].
521
+ *
522
+ * The returned value is a flat map of source string to translated string,
523
+ * e.g.:
524
+ * {"<source>": "<translation>"}
525
+ */
526
+ getTranslations(locale: string | string[]): LocaleTranslations;
527
+ /**
528
+ * Merges the strings from all translations files retrieved in the request.
529
+ * The returned value is a map of string to translations, e.g.:
530
+ *
531
+ * {"<hash>": {"source": "<source>", "<locale>": "<translation>"}}
532
+ */
533
+ private getTranslationsMap;
418
534
  }
419
535
  /**
420
536
  * Returns true if the `data` is a rich text data object.
421
537
  */
422
538
  declare function isRichTextData(data: any): boolean;
423
- declare function getCmsPlugin(rootConfig: RootConfig): CMSPlugin;
424
539
  /**
425
540
  * Walks the data tree and converts any array of objects into "array objects"
426
541
  * for storage in firestore.
@@ -476,7 +591,7 @@ declare function unmarshalArray(arrObject: ArrayObject): any[];
476
591
  * }
477
592
  * ```
478
593
  */
479
- declare function translationsForLocale(translationsMap: TranslationsMap, locale: string): LocaleTranslations;
594
+ declare function translationsForLocale(translationsMap: TranslationsMap, locale: string | string[]): LocaleTranslations;
480
595
  /**
481
596
  * Parses a docId (e.g. `Pages/foo`) and returns the `collection` and `slug`.
482
597
  */
@@ -485,4 +600,4 @@ declare function parseDocId(docId: string): {
485
600
  slug: string;
486
601
  };
487
602
 
488
- export { type Action as A, cmsPlugin as B, 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 UserRole as U, type LocaleTranslations as a, type DocMode as b, type DataSource as c, type DataSourceData as d, type DataSourceMode as e, type SaveDraftOptions as f, type ListDocsOptions as g, type GetCountOptions as h, type Translation as i, type ListActionsOptions as j, RootCMSClient as k, isRichTextData as l, getCmsPlugin as m, marshalData as n, normalizeData as o, type ArrayObject as p, marshalArray as q, unmarshalArray as r, translationsForLocale as s, toArrayObject as t, unmarshalData as u, parseDocId as v, type CMSAIConfig as w, type CMSSidebarTool as x, type CMSPluginOptions as y, type CMSPlugin as z };
603
+ export { type Action as A, BatchRequest as B, parseDocId as C, type Doc as D, type CMSUser as E, type CMSAIConfig as F, type GetDocOptions as G, type HttpMethod as H, type CMSSidebarTool as I, type CMSPluginOptions as J, type CMSPlugin as K, type LoadTranslationsOptions as L, cmsPlugin as M, RootCMSClient as R, type SetDocOptions as S, type TranslationsMap as T, type UserRole as U, type LocaleTranslations as a, type TranslationsDoc as b, type DocMode as c, type DataSource as d, type DataSourceData as e, type DataSourceMode as f, getCmsPlugin as g, type SaveDraftOptions as h, type ListDocsOptions as i, type GetCountOptions as j, type Translation as k, type Release as l, type ListActionsOptions as m, type BatchRequestOptions as n, type BatchRequestQuery as o, type BatchRequestQueryOptions as p, BatchResponse as q, isRichTextData as r, marshalData as s, normalizeData as t, unmarshalData as u, type ArrayObject as v, toArrayObject as w, marshalArray as x, unmarshalArray as y, translationsForLocale as z };
package/dist/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import '@blinkk/root';
2
2
  import 'firebase-admin/app';
3
3
  import 'firebase-admin/firestore';
4
- export { A as Action, p as ArrayObject, c as DataSource, d as DataSourceData, e as DataSourceMode, D as Doc, b as DocMode, h as GetCountOptions, G as GetDocOptions, H as HttpMethod, j as ListActionsOptions, g as ListDocsOptions, L as LoadTranslationsOptions, a as LocaleTranslations, R as Release, k as RootCMSClient, f as SaveDraftOptions, S as SetDocOptions, i as Translation, T as TranslationsMap, U as UserRole, m as getCmsPlugin, l as isRichTextData, q as marshalArray, n as marshalData, o as normalizeData, v as parseDocId, t as toArrayObject, s as translationsForLocale, r as unmarshalArray, u as unmarshalData } from './client-98Le1XxF.js';
4
+ export { A as Action, v as ArrayObject, B as BatchRequest, n as BatchRequestOptions, o as BatchRequestQuery, p as BatchRequestQueryOptions, q as BatchResponse, d as DataSource, e as DataSourceData, f as DataSourceMode, D as Doc, c as DocMode, j as GetCountOptions, G as GetDocOptions, H as HttpMethod, m as ListActionsOptions, i as ListDocsOptions, L as LoadTranslationsOptions, a as LocaleTranslations, l as Release, R as RootCMSClient, h as SaveDraftOptions, S as SetDocOptions, k as Translation, b as TranslationsDoc, T as TranslationsMap, U as UserRole, g as getCmsPlugin, r as isRichTextData, x as marshalArray, s as marshalData, t as normalizeData, C as parseDocId, w as toArrayObject, z as translationsForLocale, y as unmarshalArray, u as unmarshalData } from './client-AKOLkEwt.js';