@nascentdigital/funnel-cms 4.4.10 → 4.4.14

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.
@@ -121,14 +121,6 @@ export declare namespace PageClient {
121
121
  }
122
122
  export {};
123
123
  }
124
- type Update = {
125
- id: Schema.Page.Id;
126
- slug?: string;
127
- publication?: number | null;
128
- errors: boolean;
129
- updatedOn: number;
130
- updates: ReadonlyArray<Schema.Page.Update>;
131
- };
132
124
  namespace GetOverview {
133
125
  type Args = Query.ByBrandAndRegion;
134
126
  type Result = {
@@ -207,8 +199,19 @@ export declare namespace PageClient {
207
199
  type Result = Schema.Page.Data.AsLink;
208
200
  }
209
201
  namespace Update {
210
- type Args = Update;
211
- type Result = Schema.Page.Data;
202
+ type Args = {
203
+ id: Schema.Page.Id;
204
+ slug?: string;
205
+ publication?: number | null;
206
+ errors: boolean;
207
+ updatedOn: number;
208
+ updates: ReadonlyArray<Schema.Page.Update>;
209
+ };
210
+ type Result = {
211
+ updatedOn: number;
212
+ changeSetId: Schema.ChangeSet.Id;
213
+ page?: Schema.Page.Data;
214
+ };
212
215
  }
213
216
  namespace Replace {
214
217
  type Args = {
@@ -617,92 +617,11 @@ class StrapiPageClient {
617
617
  return serialization_1.PageData.deserializeRef(updatedData);
618
618
  }
619
619
  async update(args) {
620
- // TODO: migrating towards this as the new method for ALL updates in the future
621
- if (args.updates.length === 1 && args.updates[0].type === 'section.blockName') {
622
- // publish changeset (transactional)
623
- const data = await this.provider.customRequest({
624
- command: 'page/update',
625
- method: 'POST',
626
- data: JSON.stringify(args)
627
- });
628
- console.debug('[StrapiPageClient/update] custom update result: ', data);
629
- }
630
- // resolve current user (or throw)
631
- const { id: pageId, slug: pageSlug, publication: pagePublication, errors, updates } = args;
632
- const { client, users } = this.provider;
633
- const strapiUrl = client.baseURL;
634
- const user = await users.me();
635
- if (!user) {
636
- throw new funnel_core_1.NotAuthenticatedError();
637
- }
638
- // get latest version of page
639
- const collection = client.collection('pages');
640
- const resultProps = funnel_core_1.Schema.Page.Data.Props.all;
641
- const { data: currentData } = await collection.findOne(pageId, {
642
- status: 'draft',
643
- populate: serialization_1.PageData.Populate.full
644
- });
645
- // TODO: validate page is able to be updated (e.g. not archived, etc.)
646
- // throw if page doesn't exist
647
- if (!currentData) {
648
- throw new funnel_core_1.NotFoundError();
649
- }
650
- // deserialize page (we'll be updating this version)
651
- let page = serialization_1.PageData.deserialize(currentData, strapiUrl, resultProps);
652
- // update slug
653
- if (pageSlug && page.slug) {
654
- console.debug(`[StrapiPageClient/update] updating page slug from "${page.slug}" to ${pageSlug}`);
655
- // validate slug before updating
656
- const validateSlugResult = await this.validateSlug({
657
- brand: page.brand,
658
- type: page.type,
659
- region: page.region,
660
- groupId: page.groupId,
661
- slug: pageSlug
662
- });
663
- if (validateSlugResult.status !== 'available') {
664
- throw new errors_1.SlugValidationError({ slug: pageSlug, reason: validateSlugResult });
665
- }
666
- page.slug = pageSlug;
667
- }
668
- // update publication
669
- if (pagePublication !== undefined) {
670
- page.publication = pagePublication !== null && pagePublication !== void 0 ? pagePublication : -1;
671
- }
672
- // set errors
673
- page.errors = errors;
674
- console.debug(`[StrapiPageClient/update] applying ${updates.length} page updates`);
675
- // merge changes (the original page will have changed)
676
- const model = funnel_core_1.Schema.PageModel.from(page);
677
- model.update(updates);
678
- console.debug(`[StrapiPageClient/update] saving updated page`);
679
- // resolve change set (rebind)
680
- const { provider } = this;
681
- const changeSet = await provider.changeSets.resolve({ id: page.changeSetId, fallbackToGlobal: true });
682
- page.changeSetId = changeSet.id;
683
- // save page
684
- const update = serialization_1.PageData.serialize(page);
685
- const { data: updatedData } = await collection.update(page.id, Object.assign(Object.assign({}, update), { state: 'draft' }), {
686
- status: 'draft',
687
- populate: serialization_1.PageData.Populate.full
688
- });
689
- page = serialization_1.PageData.deserialize(updatedData, strapiUrl, resultProps);
690
- // update changeset
691
- changeSet.addPageChange(user.id, {
692
- __type: 'page',
693
- id: page.id,
694
- name: page.name,
695
- schema: page.type,
696
- region: page.region,
697
- language: page.language,
698
- slug: page.slug,
699
- type: page.publishedOn ? 'update' : 'create',
700
- errors: page.errors
620
+ return this.provider.customRequest({
621
+ command: 'page/update',
622
+ method: 'POST',
623
+ data: JSON.stringify(args)
701
624
  });
702
- provider.changeSets.update(changeSet.toData())
703
- .catch(console.error);
704
- // return page
705
- return page;
706
625
  }
707
626
  async replace({ page, version, skipSync = false }) {
708
627
  console.debug(`[StrapiPageClient/replace] replacing page`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nascentdigital/funnel-cms",
3
- "version": "4.4.10",
3
+ "version": "4.4.14",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/nascentdigital/funnel.git",
6
6
  "directory": "libs/cms"
@@ -41,5 +41,5 @@
41
41
  "ts-jest": "^29",
42
42
  "type-fest": "^4"
43
43
  },
44
- "gitHead": "3aa36fa46c32ad625f569ea4b9e43aab80937ff4"
44
+ "gitHead": "242a9e0979c03d4037eb2462c5b01b2a095e8e8f"
45
45
  }