@blinkk/root-cms 1.4.11 → 1.4.13

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 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: "1.4.11",
10
+ version: "1.4.13",
11
11
  author: "s@blinkk.com",
12
12
  license: "MIT",
13
13
  engines: {
@@ -140,7 +140,7 @@ var package_default = {
140
140
  vitest: "0.34.6"
141
141
  },
142
142
  peerDependencies: {
143
- "@blinkk/root": "1.4.11",
143
+ "@blinkk/root": "1.4.13",
144
144
  "firebase-admin": ">=11",
145
145
  "firebase-functions": ">=4",
146
146
  preact: ">=10",
@@ -433,6 +433,7 @@ interface Release {
433
433
  id: string;
434
434
  description?: string;
435
435
  docIds?: string[];
436
+ dataSourceIds?: string[];
436
437
  createdAt?: Timestamp;
437
438
  createdBy?: string;
438
439
  scheduledAt?: Timestamp;
@@ -534,6 +535,7 @@ declare class RootCMSClient {
534
535
  publishDocs(docIds: string[], options?: {
535
536
  publishedBy: string;
536
537
  batch?: WriteBatch;
538
+ releaseId?: string;
537
539
  }): Promise<any[]>;
538
540
  /**
539
541
  * Publishes scheduled docs.
@@ -634,6 +636,11 @@ declare class RootCMSClient {
634
636
  publishDataSource(dataSourceId: string, options?: {
635
637
  publishedBy?: string;
636
638
  }): Promise<void>;
639
+ publishDataSources(dataSourceIds: string[], options?: {
640
+ publishedBy: string;
641
+ batch?: WriteBatch;
642
+ commitBatch?: boolean;
643
+ }): Promise<void>;
637
644
  private fetchData;
638
645
  private fetchHttpData;
639
646
  /**
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, z as BatchRequest, B as BatchRequestOptions, w as BatchRequestQuery, x as BatchRequestQueryOptions, C as BatchResponse, 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, y as TranslationsDoc, 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-AE0BYn69.js';
4
+ export { A as Action, p as ArrayObject, z as BatchRequest, B as BatchRequestOptions, w as BatchRequestQuery, x as BatchRequestQueryOptions, C as BatchResponse, 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, y as TranslationsDoc, 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-X1tujeDI.js';
package/dist/client.js CHANGED
@@ -535,6 +535,10 @@ var RootCMSClient = class {
535
535
  }
536
536
  let batchCount = 0;
537
537
  const batch = (options == null ? void 0 : options.batch) || this.db.batch();
538
+ const versionTags = ["published"];
539
+ if (options == null ? void 0 : options.releaseId) {
540
+ versionTags.push(`release:${options.releaseId}`);
541
+ }
538
542
  const publishedDocs = [];
539
543
  for (const doc of docs) {
540
544
  const { id, collection, slug, sys, fields } = doc;
@@ -563,6 +567,27 @@ var RootCMSClient = class {
563
567
  }
564
568
  });
565
569
  batchCount += 1;
570
+ const versionRef = this.db.doc(
571
+ `${projectCollectionsPath}/${collection}/Drafts/${slug}/Versions/${Date.now()}`
572
+ );
573
+ const versionData = {
574
+ id,
575
+ collection,
576
+ slug,
577
+ fields: fields || {},
578
+ sys: {
579
+ ...sys,
580
+ firstPublishedAt,
581
+ firstPublishedBy,
582
+ publishedAt: FieldValue2.serverTimestamp(),
583
+ publishedBy
584
+ }
585
+ };
586
+ if (versionTags.length) {
587
+ versionData.tags = versionTags;
588
+ }
589
+ batch.set(versionRef, versionData);
590
+ batchCount += 1;
566
591
  batch.delete(scheduledRef);
567
592
  batchCount += 1;
568
593
  batch.update(draftRef, {
@@ -620,6 +645,7 @@ var RootCMSClient = class {
620
645
  }
621
646
  let batchCount = 0;
622
647
  const batch = this.db.batch();
648
+ const versionTags = ["published"];
623
649
  const publishedDocs = [];
624
650
  for (const doc of docs) {
625
651
  const { id, collection, slug, data } = doc;
@@ -649,6 +675,25 @@ var RootCMSClient = class {
649
675
  }
650
676
  });
651
677
  batchCount += 1;
678
+ const versionRef = this.db.doc(
679
+ `${projectCollectionsPath}/${collection}/Drafts/${slug}/Versions/${Date.now()}`
680
+ );
681
+ const versionData = {
682
+ id,
683
+ collection,
684
+ slug,
685
+ fields: data.fields || {},
686
+ sys: {
687
+ ...sys,
688
+ firstPublishedAt,
689
+ firstPublishedBy,
690
+ publishedAt: FieldValue2.serverTimestamp(),
691
+ publishedBy: scheduledBy || ""
692
+ },
693
+ tags: versionTags
694
+ };
695
+ batch.set(versionRef, versionData);
696
+ batchCount += 1;
652
697
  batch.delete(scheduledRef);
653
698
  batchCount += 1;
654
699
  batch.update(draftRef, {
@@ -691,7 +736,19 @@ var RootCMSClient = class {
691
736
  scheduledAt: FieldValue2.delete(),
692
737
  scheduledBy: FieldValue2.delete()
693
738
  });
694
- await this.publishDocs(release.docIds || [], { publishedBy, batch });
739
+ const dataSourceIds = release.dataSourceIds || [];
740
+ if (dataSourceIds.length > 0) {
741
+ await this.publishDataSources(dataSourceIds, {
742
+ publishedBy,
743
+ batch,
744
+ commitBatch: false
745
+ });
746
+ }
747
+ await this.publishDocs(release.docIds || [], {
748
+ publishedBy,
749
+ batch,
750
+ releaseId: release.id
751
+ });
695
752
  }
696
753
  }
697
754
  /**
@@ -922,6 +979,44 @@ var RootCMSClient = class {
922
979
  console.log(`published data ${dataSourceId}`);
923
980
  console.log(`published by: ${publishedBy}`);
924
981
  }
982
+ async publishDataSources(dataSourceIds, options) {
983
+ const publishedBy = (options == null ? void 0 : options.publishedBy) || "root-cms-client";
984
+ const batch = (options == null ? void 0 : options.batch) || this.db.batch();
985
+ for (const id of dataSourceIds) {
986
+ const dataSource = await this.getDataSource(id);
987
+ if (!dataSource) {
988
+ throw new Error(`data source not found: ${id}`);
989
+ }
990
+ const dataSourceDocRef = this.db.doc(
991
+ `Projects/${this.projectId}/DataSources/${id}`
992
+ );
993
+ const dataDocRefDraft = this.db.doc(
994
+ `Projects/${this.projectId}/DataSources/${id}/draft`
995
+ );
996
+ const dataDocRefPublished = this.db.doc(
997
+ `Projects/${this.projectId}/DataSources/${id}/published`
998
+ );
999
+ const dataRes = await this.getFromDataSource(id, { mode: "draft" });
1000
+ const updatedDataSource = {
1001
+ ...dataSource,
1002
+ publishedAt: FieldValue2.serverTimestamp(),
1003
+ publishedBy
1004
+ };
1005
+ batch.set(dataDocRefPublished, {
1006
+ dataSource: updatedDataSource,
1007
+ data: (dataRes == null ? void 0 : dataRes.data) || null,
1008
+ ...(dataRes == null ? void 0 : dataRes.headers) ? { headers: dataRes.headers } : {}
1009
+ });
1010
+ batch.update(dataDocRefDraft, { dataSource: updatedDataSource });
1011
+ batch.update(dataSourceDocRef, {
1012
+ publishedAt: FieldValue2.serverTimestamp(),
1013
+ publishedBy
1014
+ });
1015
+ }
1016
+ if (!(options == null ? void 0 : options.batch) || (options == null ? void 0 : options.commitBatch)) {
1017
+ await batch.commit();
1018
+ }
1019
+ }
925
1020
  async fetchData(dataSource) {
926
1021
  if (dataSource.type === "http") {
927
1022
  return await this.fetchHttpData(dataSource);
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as LoadTranslationsOptions, T as TranslationsMap, a as LocaleTranslations } from './client-AE0BYn69.js';
2
- export { A as Action, p as ArrayObject, z as BatchRequest, B as BatchRequestOptions, w as BatchRequestQuery, x as BatchRequestQueryOptions, C as BatchResponse, 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, E as Locale, N as MultiLocaleTranslationsMap, R as Release, k as RootCMSClient, f as SaveDraftOptions, S as SetDocOptions, O as SingleLocaleTranslationsMap, F as SourceString, I as TranslatedString, i as Translation, y as TranslationsDoc, J as TranslationsDocMode, M as TranslationsLocaleDocEntry, K as TranslationsLocaleDocHashMap, P as TranslationsManager, U as UserRole, Q as buildTranslationsDbPath, V as buildTranslationsLocaleDocDbPath, 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-AE0BYn69.js';
1
+ import { L as LoadTranslationsOptions, T as TranslationsMap, a as LocaleTranslations } from './client-X1tujeDI.js';
2
+ export { A as Action, p as ArrayObject, z as BatchRequest, B as BatchRequestOptions, w as BatchRequestQuery, x as BatchRequestQueryOptions, C as BatchResponse, 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, E as Locale, N as MultiLocaleTranslationsMap, R as Release, k as RootCMSClient, f as SaveDraftOptions, S as SetDocOptions, O as SingleLocaleTranslationsMap, F as SourceString, I as TranslatedString, i as Translation, y as TranslationsDoc, J as TranslationsDocMode, M as TranslationsLocaleDocEntry, K as TranslationsLocaleDocHashMap, P as TranslationsManager, U as UserRole, Q as buildTranslationsDbPath, V as buildTranslationsLocaleDocDbPath, 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-X1tujeDI.js';
3
3
  import { RootConfig } from '@blinkk/root';
4
4
  import { Query } from 'firebase-admin/firestore';
5
5
  export { s as schema } from './schema-tTvlPgCa.js';
package/dist/core.js CHANGED
@@ -541,6 +541,10 @@ var RootCMSClient = class {
541
541
  }
542
542
  let batchCount = 0;
543
543
  const batch = (options == null ? void 0 : options.batch) || this.db.batch();
544
+ const versionTags = ["published"];
545
+ if (options == null ? void 0 : options.releaseId) {
546
+ versionTags.push(`release:${options.releaseId}`);
547
+ }
544
548
  const publishedDocs = [];
545
549
  for (const doc of docs) {
546
550
  const { id, collection: collection2, slug, sys, fields } = doc;
@@ -569,6 +573,27 @@ var RootCMSClient = class {
569
573
  }
570
574
  });
571
575
  batchCount += 1;
576
+ const versionRef = this.db.doc(
577
+ `${projectCollectionsPath}/${collection2}/Drafts/${slug}/Versions/${Date.now()}`
578
+ );
579
+ const versionData = {
580
+ id,
581
+ collection: collection2,
582
+ slug,
583
+ fields: fields || {},
584
+ sys: {
585
+ ...sys,
586
+ firstPublishedAt,
587
+ firstPublishedBy,
588
+ publishedAt: FieldValue2.serverTimestamp(),
589
+ publishedBy
590
+ }
591
+ };
592
+ if (versionTags.length) {
593
+ versionData.tags = versionTags;
594
+ }
595
+ batch.set(versionRef, versionData);
596
+ batchCount += 1;
572
597
  batch.delete(scheduledRef);
573
598
  batchCount += 1;
574
599
  batch.update(draftRef, {
@@ -626,6 +651,7 @@ var RootCMSClient = class {
626
651
  }
627
652
  let batchCount = 0;
628
653
  const batch = this.db.batch();
654
+ const versionTags = ["published"];
629
655
  const publishedDocs = [];
630
656
  for (const doc of docs) {
631
657
  const { id, collection: collection2, slug, data } = doc;
@@ -655,6 +681,25 @@ var RootCMSClient = class {
655
681
  }
656
682
  });
657
683
  batchCount += 1;
684
+ const versionRef = this.db.doc(
685
+ `${projectCollectionsPath}/${collection2}/Drafts/${slug}/Versions/${Date.now()}`
686
+ );
687
+ const versionData = {
688
+ id,
689
+ collection: collection2,
690
+ slug,
691
+ fields: data.fields || {},
692
+ sys: {
693
+ ...sys,
694
+ firstPublishedAt,
695
+ firstPublishedBy,
696
+ publishedAt: FieldValue2.serverTimestamp(),
697
+ publishedBy: scheduledBy || ""
698
+ },
699
+ tags: versionTags
700
+ };
701
+ batch.set(versionRef, versionData);
702
+ batchCount += 1;
658
703
  batch.delete(scheduledRef);
659
704
  batchCount += 1;
660
705
  batch.update(draftRef, {
@@ -697,7 +742,19 @@ var RootCMSClient = class {
697
742
  scheduledAt: FieldValue2.delete(),
698
743
  scheduledBy: FieldValue2.delete()
699
744
  });
700
- await this.publishDocs(release.docIds || [], { publishedBy, batch });
745
+ const dataSourceIds = release.dataSourceIds || [];
746
+ if (dataSourceIds.length > 0) {
747
+ await this.publishDataSources(dataSourceIds, {
748
+ publishedBy,
749
+ batch,
750
+ commitBatch: false
751
+ });
752
+ }
753
+ await this.publishDocs(release.docIds || [], {
754
+ publishedBy,
755
+ batch,
756
+ releaseId: release.id
757
+ });
701
758
  }
702
759
  }
703
760
  /**
@@ -928,6 +985,44 @@ var RootCMSClient = class {
928
985
  console.log(`published data ${dataSourceId}`);
929
986
  console.log(`published by: ${publishedBy}`);
930
987
  }
988
+ async publishDataSources(dataSourceIds, options) {
989
+ const publishedBy = (options == null ? void 0 : options.publishedBy) || "root-cms-client";
990
+ const batch = (options == null ? void 0 : options.batch) || this.db.batch();
991
+ for (const id of dataSourceIds) {
992
+ const dataSource = await this.getDataSource(id);
993
+ if (!dataSource) {
994
+ throw new Error(`data source not found: ${id}`);
995
+ }
996
+ const dataSourceDocRef = this.db.doc(
997
+ `Projects/${this.projectId}/DataSources/${id}`
998
+ );
999
+ const dataDocRefDraft = this.db.doc(
1000
+ `Projects/${this.projectId}/DataSources/${id}/draft`
1001
+ );
1002
+ const dataDocRefPublished = this.db.doc(
1003
+ `Projects/${this.projectId}/DataSources/${id}/published`
1004
+ );
1005
+ const dataRes = await this.getFromDataSource(id, { mode: "draft" });
1006
+ const updatedDataSource = {
1007
+ ...dataSource,
1008
+ publishedAt: FieldValue2.serverTimestamp(),
1009
+ publishedBy
1010
+ };
1011
+ batch.set(dataDocRefPublished, {
1012
+ dataSource: updatedDataSource,
1013
+ data: (dataRes == null ? void 0 : dataRes.data) || null,
1014
+ ...(dataRes == null ? void 0 : dataRes.headers) ? { headers: dataRes.headers } : {}
1015
+ });
1016
+ batch.update(dataDocRefDraft, { dataSource: updatedDataSource });
1017
+ batch.update(dataSourceDocRef, {
1018
+ publishedAt: FieldValue2.serverTimestamp(),
1019
+ publishedBy
1020
+ });
1021
+ }
1022
+ if (!(options == null ? void 0 : options.batch) || (options == null ? void 0 : options.commitBatch)) {
1023
+ await batch.commit();
1024
+ }
1025
+ }
931
1026
  async fetchData(dataSource) {
932
1027
  if (dataSource.type === "http") {
933
1028
  return await this.fetchHttpData(dataSource);
package/dist/functions.js CHANGED
@@ -540,6 +540,10 @@ var RootCMSClient = class {
540
540
  }
541
541
  let batchCount = 0;
542
542
  const batch = (options == null ? void 0 : options.batch) || this.db.batch();
543
+ const versionTags = ["published"];
544
+ if (options == null ? void 0 : options.releaseId) {
545
+ versionTags.push(`release:${options.releaseId}`);
546
+ }
543
547
  const publishedDocs = [];
544
548
  for (const doc of docs) {
545
549
  const { id, collection, slug, sys, fields } = doc;
@@ -568,6 +572,27 @@ var RootCMSClient = class {
568
572
  }
569
573
  });
570
574
  batchCount += 1;
575
+ const versionRef = this.db.doc(
576
+ `${projectCollectionsPath}/${collection}/Drafts/${slug}/Versions/${Date.now()}`
577
+ );
578
+ const versionData = {
579
+ id,
580
+ collection,
581
+ slug,
582
+ fields: fields || {},
583
+ sys: {
584
+ ...sys,
585
+ firstPublishedAt,
586
+ firstPublishedBy,
587
+ publishedAt: FieldValue2.serverTimestamp(),
588
+ publishedBy
589
+ }
590
+ };
591
+ if (versionTags.length) {
592
+ versionData.tags = versionTags;
593
+ }
594
+ batch.set(versionRef, versionData);
595
+ batchCount += 1;
571
596
  batch.delete(scheduledRef);
572
597
  batchCount += 1;
573
598
  batch.update(draftRef, {
@@ -625,6 +650,7 @@ var RootCMSClient = class {
625
650
  }
626
651
  let batchCount = 0;
627
652
  const batch = this.db.batch();
653
+ const versionTags = ["published"];
628
654
  const publishedDocs = [];
629
655
  for (const doc of docs) {
630
656
  const { id, collection, slug, data } = doc;
@@ -654,6 +680,25 @@ var RootCMSClient = class {
654
680
  }
655
681
  });
656
682
  batchCount += 1;
683
+ const versionRef = this.db.doc(
684
+ `${projectCollectionsPath}/${collection}/Drafts/${slug}/Versions/${Date.now()}`
685
+ );
686
+ const versionData = {
687
+ id,
688
+ collection,
689
+ slug,
690
+ fields: data.fields || {},
691
+ sys: {
692
+ ...sys,
693
+ firstPublishedAt,
694
+ firstPublishedBy,
695
+ publishedAt: FieldValue2.serverTimestamp(),
696
+ publishedBy: scheduledBy || ""
697
+ },
698
+ tags: versionTags
699
+ };
700
+ batch.set(versionRef, versionData);
701
+ batchCount += 1;
657
702
  batch.delete(scheduledRef);
658
703
  batchCount += 1;
659
704
  batch.update(draftRef, {
@@ -696,7 +741,19 @@ var RootCMSClient = class {
696
741
  scheduledAt: FieldValue2.delete(),
697
742
  scheduledBy: FieldValue2.delete()
698
743
  });
699
- await this.publishDocs(release.docIds || [], { publishedBy, batch });
744
+ const dataSourceIds = release.dataSourceIds || [];
745
+ if (dataSourceIds.length > 0) {
746
+ await this.publishDataSources(dataSourceIds, {
747
+ publishedBy,
748
+ batch,
749
+ commitBatch: false
750
+ });
751
+ }
752
+ await this.publishDocs(release.docIds || [], {
753
+ publishedBy,
754
+ batch,
755
+ releaseId: release.id
756
+ });
700
757
  }
701
758
  }
702
759
  /**
@@ -927,6 +984,44 @@ var RootCMSClient = class {
927
984
  console.log(`published data ${dataSourceId}`);
928
985
  console.log(`published by: ${publishedBy}`);
929
986
  }
987
+ async publishDataSources(dataSourceIds, options) {
988
+ const publishedBy = (options == null ? void 0 : options.publishedBy) || "root-cms-client";
989
+ const batch = (options == null ? void 0 : options.batch) || this.db.batch();
990
+ for (const id of dataSourceIds) {
991
+ const dataSource = await this.getDataSource(id);
992
+ if (!dataSource) {
993
+ throw new Error(`data source not found: ${id}`);
994
+ }
995
+ const dataSourceDocRef = this.db.doc(
996
+ `Projects/${this.projectId}/DataSources/${id}`
997
+ );
998
+ const dataDocRefDraft = this.db.doc(
999
+ `Projects/${this.projectId}/DataSources/${id}/draft`
1000
+ );
1001
+ const dataDocRefPublished = this.db.doc(
1002
+ `Projects/${this.projectId}/DataSources/${id}/published`
1003
+ );
1004
+ const dataRes = await this.getFromDataSource(id, { mode: "draft" });
1005
+ const updatedDataSource = {
1006
+ ...dataSource,
1007
+ publishedAt: FieldValue2.serverTimestamp(),
1008
+ publishedBy
1009
+ };
1010
+ batch.set(dataDocRefPublished, {
1011
+ dataSource: updatedDataSource,
1012
+ data: (dataRes == null ? void 0 : dataRes.data) || null,
1013
+ ...(dataRes == null ? void 0 : dataRes.headers) ? { headers: dataRes.headers } : {}
1014
+ });
1015
+ batch.update(dataDocRefDraft, { dataSource: updatedDataSource });
1016
+ batch.update(dataSourceDocRef, {
1017
+ publishedAt: FieldValue2.serverTimestamp(),
1018
+ publishedBy
1019
+ });
1020
+ }
1021
+ if (!(options == null ? void 0 : options.batch) || (options == null ? void 0 : options.commitBatch)) {
1022
+ await batch.commit();
1023
+ }
1024
+ }
930
1025
  async fetchData(dataSource) {
931
1026
  if (dataSource.type === "http") {
932
1027
  return await this.fetchHttpData(dataSource);
package/dist/plugin.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 { X as CMSAIConfig, _ as CMSPlugin, Z as CMSPluginOptions, Y as CMSSidebarTool, W as CMSUser, $ as cmsPlugin } from './client-AE0BYn69.js';
4
+ export { X as CMSAIConfig, _ as CMSPlugin, Z as CMSPluginOptions, Y as CMSSidebarTool, W as CMSUser, $ as cmsPlugin } from './client-X1tujeDI.js';
package/dist/plugin.js CHANGED
@@ -982,6 +982,10 @@ var RootCMSClient = class {
982
982
  }
983
983
  let batchCount = 0;
984
984
  const batch = (options == null ? void 0 : options.batch) || this.db.batch();
985
+ const versionTags = ["published"];
986
+ if (options == null ? void 0 : options.releaseId) {
987
+ versionTags.push(`release:${options.releaseId}`);
988
+ }
985
989
  const publishedDocs = [];
986
990
  for (const doc of docs) {
987
991
  const { id, collection, slug, sys, fields } = doc;
@@ -1010,6 +1014,27 @@ var RootCMSClient = class {
1010
1014
  }
1011
1015
  });
1012
1016
  batchCount += 1;
1017
+ const versionRef = this.db.doc(
1018
+ `${projectCollectionsPath}/${collection}/Drafts/${slug}/Versions/${Date.now()}`
1019
+ );
1020
+ const versionData = {
1021
+ id,
1022
+ collection,
1023
+ slug,
1024
+ fields: fields || {},
1025
+ sys: {
1026
+ ...sys,
1027
+ firstPublishedAt,
1028
+ firstPublishedBy,
1029
+ publishedAt: FieldValue2.serverTimestamp(),
1030
+ publishedBy
1031
+ }
1032
+ };
1033
+ if (versionTags.length) {
1034
+ versionData.tags = versionTags;
1035
+ }
1036
+ batch.set(versionRef, versionData);
1037
+ batchCount += 1;
1013
1038
  batch.delete(scheduledRef);
1014
1039
  batchCount += 1;
1015
1040
  batch.update(draftRef, {
@@ -1067,6 +1092,7 @@ var RootCMSClient = class {
1067
1092
  }
1068
1093
  let batchCount = 0;
1069
1094
  const batch = this.db.batch();
1095
+ const versionTags = ["published"];
1070
1096
  const publishedDocs = [];
1071
1097
  for (const doc of docs) {
1072
1098
  const { id, collection, slug, data } = doc;
@@ -1096,6 +1122,25 @@ var RootCMSClient = class {
1096
1122
  }
1097
1123
  });
1098
1124
  batchCount += 1;
1125
+ const versionRef = this.db.doc(
1126
+ `${projectCollectionsPath}/${collection}/Drafts/${slug}/Versions/${Date.now()}`
1127
+ );
1128
+ const versionData = {
1129
+ id,
1130
+ collection,
1131
+ slug,
1132
+ fields: data.fields || {},
1133
+ sys: {
1134
+ ...sys,
1135
+ firstPublishedAt,
1136
+ firstPublishedBy,
1137
+ publishedAt: FieldValue2.serverTimestamp(),
1138
+ publishedBy: scheduledBy || ""
1139
+ },
1140
+ tags: versionTags
1141
+ };
1142
+ batch.set(versionRef, versionData);
1143
+ batchCount += 1;
1099
1144
  batch.delete(scheduledRef);
1100
1145
  batchCount += 1;
1101
1146
  batch.update(draftRef, {
@@ -1138,7 +1183,19 @@ var RootCMSClient = class {
1138
1183
  scheduledAt: FieldValue2.delete(),
1139
1184
  scheduledBy: FieldValue2.delete()
1140
1185
  });
1141
- await this.publishDocs(release.docIds || [], { publishedBy, batch });
1186
+ const dataSourceIds = release.dataSourceIds || [];
1187
+ if (dataSourceIds.length > 0) {
1188
+ await this.publishDataSources(dataSourceIds, {
1189
+ publishedBy,
1190
+ batch,
1191
+ commitBatch: false
1192
+ });
1193
+ }
1194
+ await this.publishDocs(release.docIds || [], {
1195
+ publishedBy,
1196
+ batch,
1197
+ releaseId: release.id
1198
+ });
1142
1199
  }
1143
1200
  }
1144
1201
  /**
@@ -1369,6 +1426,44 @@ var RootCMSClient = class {
1369
1426
  console.log(`published data ${dataSourceId}`);
1370
1427
  console.log(`published by: ${publishedBy}`);
1371
1428
  }
1429
+ async publishDataSources(dataSourceIds, options) {
1430
+ const publishedBy = (options == null ? void 0 : options.publishedBy) || "root-cms-client";
1431
+ const batch = (options == null ? void 0 : options.batch) || this.db.batch();
1432
+ for (const id of dataSourceIds) {
1433
+ const dataSource = await this.getDataSource(id);
1434
+ if (!dataSource) {
1435
+ throw new Error(`data source not found: ${id}`);
1436
+ }
1437
+ const dataSourceDocRef = this.db.doc(
1438
+ `Projects/${this.projectId}/DataSources/${id}`
1439
+ );
1440
+ const dataDocRefDraft = this.db.doc(
1441
+ `Projects/${this.projectId}/DataSources/${id}/draft`
1442
+ );
1443
+ const dataDocRefPublished = this.db.doc(
1444
+ `Projects/${this.projectId}/DataSources/${id}/published`
1445
+ );
1446
+ const dataRes = await this.getFromDataSource(id, { mode: "draft" });
1447
+ const updatedDataSource = {
1448
+ ...dataSource,
1449
+ publishedAt: FieldValue2.serverTimestamp(),
1450
+ publishedBy
1451
+ };
1452
+ batch.set(dataDocRefPublished, {
1453
+ dataSource: updatedDataSource,
1454
+ data: (dataRes == null ? void 0 : dataRes.data) || null,
1455
+ ...(dataRes == null ? void 0 : dataRes.headers) ? { headers: dataRes.headers } : {}
1456
+ });
1457
+ batch.update(dataDocRefDraft, { dataSource: updatedDataSource });
1458
+ batch.update(dataSourceDocRef, {
1459
+ publishedAt: FieldValue2.serverTimestamp(),
1460
+ publishedBy
1461
+ });
1462
+ }
1463
+ if (!(options == null ? void 0 : options.batch) || (options == null ? void 0 : options.commitBatch)) {
1464
+ await batch.commit();
1465
+ }
1466
+ }
1372
1467
  async fetchData(dataSource) {
1373
1468
  if (dataSource.type === "http") {
1374
1469
  return await this.fetchHttpData(dataSource);