@webiny/api-headless-cms 5.19.0-beta.2 → 5.19.0-beta.3

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.
@@ -624,6 +624,83 @@ const createContentEntryCrud = params => {
624
624
  });
625
625
  }
626
626
  },
627
+ republishEntry: async (model, id) => {
628
+ await checkEntryPermissions({
629
+ rwd: "w"
630
+ });
631
+ await utils.checkModelAccess(context, model);
632
+ /**
633
+ * Fetch the entry from the storage.
634
+ */
635
+
636
+ const originalStorageEntry = await storageOperations.entries.getRevisionById(model, {
637
+ id
638
+ });
639
+
640
+ if (!originalStorageEntry) {
641
+ throw new _handlerGraphql.NotFoundError(`Entry "${id}" was not found!`);
642
+ }
643
+
644
+ const originalEntry = await (0, _entryStorage.entryFromStorageTransform)(context, model, originalStorageEntry);
645
+ /**
646
+ * We can only process published entries.
647
+ */
648
+
649
+ if (originalEntry.status !== "published") {
650
+ throw new _error.default("Entry with given ID is not published!", "NOT_PUBLISHED_ERROR", {
651
+ id,
652
+ original: originalEntry
653
+ });
654
+ }
655
+
656
+ const values = await (0, _referenceFieldsMapping.referenceFieldsMapping)({
657
+ context,
658
+ model,
659
+ input: originalEntry.values
660
+ });
661
+
662
+ const entry = _objectSpread(_objectSpread({}, originalEntry), {}, {
663
+ savedOn: new Date().toISOString(),
664
+ webinyVersion: context.WEBINY_VERSION,
665
+ values
666
+ });
667
+
668
+ const storageEntry = await (0, _entryStorage.entryToStorageTransform)(context, model, entry);
669
+ /**
670
+ * First we need to update existing entry.
671
+ */
672
+
673
+ try {
674
+ await storageOperations.entries.update(model, {
675
+ originalEntry,
676
+ originalStorageEntry,
677
+ entry,
678
+ storageEntry,
679
+ input: {}
680
+ });
681
+ } catch (ex) {
682
+ throw new _error.default("Could not update existing entry with new data while re-publishing.", "REPUBLISH_UPDATE_ERROR", {
683
+ entry
684
+ });
685
+ }
686
+ /**
687
+ * Then we move onto publishing it again.
688
+ */
689
+
690
+
691
+ try {
692
+ return await storageOperations.entries.publish(model, {
693
+ originalEntry,
694
+ originalStorageEntry,
695
+ entry,
696
+ storageEntry
697
+ });
698
+ } catch (ex) {
699
+ throw new _error.default("Could not publish existing entry while re-publishing.", "REPUBLISH_PUBLISH_ERROR", {
700
+ entry
701
+ });
702
+ }
703
+ },
627
704
  deleteEntryRevision: async (model, revisionId) => {
628
705
  const permission = await checkEntryPermissions({
629
706
  rwd: "d"
@@ -31,6 +31,8 @@ var _resolveDelete = require("./resolvers/manage/resolveDelete");
31
31
 
32
32
  var _resolvePublish = require("./resolvers/manage/resolvePublish");
33
33
 
34
+ var _resolveRepublish = require("./resolvers/manage/resolveRepublish");
35
+
34
36
  var _resolveUnpublish = require("./resolvers/manage/resolveUnpublish");
35
37
 
36
38
  var _resolveCreateFrom = require("./resolvers/manage/resolveCreateFrom");
@@ -88,6 +90,9 @@ const createManageResolvers = ({
88
90
  [`publish${typeName}`]: (0, _resolvePublish.resolvePublish)({
89
91
  model
90
92
  }),
93
+ [`republish${typeName}`]: (0, _resolveRepublish.resolveRepublish)({
94
+ model
95
+ }),
91
96
  [`unpublish${typeName}`]: (0, _resolveUnpublish.resolveUnpublish)({
92
97
  model
93
98
  }),
@@ -139,6 +139,8 @@ const createManageSDL = ({
139
139
  delete${typeName}(revision: ID!): CmsDeleteResponse
140
140
 
141
141
  publish${typeName}(revision: ID!): ${mTypeName}Response
142
+
143
+ republish${typeName}(revision: ID!): ${mTypeName}Response
142
144
 
143
145
  unpublish${typeName}(revision: ID!): ${mTypeName}Response
144
146
 
@@ -0,0 +1,2 @@
1
+ import { CmsEntryResolverFactory as ResolverFactory } from "../../../../../types";
2
+ export declare const resolveRepublish: ResolverFactory;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveRepublish = void 0;
7
+
8
+ var _responses = require("@webiny/handler-graphql/responses");
9
+
10
+ const resolveRepublish = ({
11
+ model
12
+ }) => async (_, args, context) => {
13
+ try {
14
+ const entry = await context.cms.republishEntry(model, args.revision);
15
+ return new _responses.Response(entry);
16
+ } catch (e) {
17
+ return new _responses.ErrorResponse(e);
18
+ }
19
+ };
20
+
21
+ exports.resolveRepublish = resolveRepublish;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms",
3
- "version": "5.19.0-beta.2",
3
+ "version": "5.19.0-beta.3",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "cms:base"
@@ -21,23 +21,23 @@
21
21
  "@babel/runtime": "7.16.3",
22
22
  "@commodo/fields": "1.1.2-beta.20",
23
23
  "@graphql-tools/schema": "7.1.5",
24
- "@webiny/api-file-manager": "5.19.0-beta.2",
25
- "@webiny/api-i18n": "5.19.0-beta.2",
26
- "@webiny/api-i18n-content": "5.19.0-beta.2",
27
- "@webiny/api-i18n-ddb": "5.19.0-beta.2",
28
- "@webiny/api-security": "5.19.0-beta.2",
29
- "@webiny/api-tenancy": "5.19.0-beta.2",
30
- "@webiny/api-upgrade": "5.19.0-beta.2",
31
- "@webiny/error": "5.19.0-beta.2",
32
- "@webiny/handler": "5.19.0-beta.2",
33
- "@webiny/handler-aws": "5.19.0-beta.2",
34
- "@webiny/handler-db": "5.19.0-beta.2",
35
- "@webiny/handler-graphql": "5.19.0-beta.2",
36
- "@webiny/handler-http": "5.19.0-beta.2",
37
- "@webiny/plugins": "5.19.0-beta.2",
38
- "@webiny/pubsub": "5.19.0-beta.2",
39
- "@webiny/utils": "5.19.0-beta.2",
40
- "@webiny/validation": "5.19.0-beta.2",
24
+ "@webiny/api-file-manager": "5.19.0-beta.3",
25
+ "@webiny/api-i18n": "5.19.0-beta.3",
26
+ "@webiny/api-i18n-content": "5.19.0-beta.3",
27
+ "@webiny/api-i18n-ddb": "5.19.0-beta.3",
28
+ "@webiny/api-security": "5.19.0-beta.3",
29
+ "@webiny/api-tenancy": "5.19.0-beta.3",
30
+ "@webiny/api-upgrade": "5.19.0-beta.3",
31
+ "@webiny/error": "5.19.0-beta.3",
32
+ "@webiny/handler": "5.19.0-beta.3",
33
+ "@webiny/handler-aws": "5.19.0-beta.3",
34
+ "@webiny/handler-db": "5.19.0-beta.3",
35
+ "@webiny/handler-graphql": "5.19.0-beta.3",
36
+ "@webiny/handler-http": "5.19.0-beta.3",
37
+ "@webiny/plugins": "5.19.0-beta.3",
38
+ "@webiny/pubsub": "5.19.0-beta.3",
39
+ "@webiny/utils": "5.19.0-beta.3",
40
+ "@webiny/validation": "5.19.0-beta.3",
41
41
  "boolean": "3.1.4",
42
42
  "commodo-fields-object": "1.0.6",
43
43
  "dataloader": "2.0.0",
@@ -54,10 +54,10 @@
54
54
  "@babel/core": "^7.5.5",
55
55
  "@babel/preset-env": "^7.5.5",
56
56
  "@babel/preset-flow": "^7.0.0",
57
- "@webiny/api-security-so-ddb": "^5.19.0-beta.2",
58
- "@webiny/api-tenancy-so-ddb": "^5.19.0-beta.2",
59
- "@webiny/cli": "^5.19.0-beta.2",
60
- "@webiny/project-utils": "^5.19.0-beta.2",
57
+ "@webiny/api-security-so-ddb": "^5.19.0-beta.3",
58
+ "@webiny/api-tenancy-so-ddb": "^5.19.0-beta.3",
59
+ "@webiny/cli": "^5.19.0-beta.3",
60
+ "@webiny/project-utils": "^5.19.0-beta.3",
61
61
  "apollo-graphql": "^0.4.1",
62
62
  "get-yarn-workspaces": "^1.0.2",
63
63
  "graphql": "^14.6.0",
@@ -77,5 +77,5 @@
77
77
  "build": "yarn webiny run build",
78
78
  "watch": "yarn webiny run watch"
79
79
  },
80
- "gitHead": "6817702cc537405b7288c1fc63ee5d40531b4122"
80
+ "gitHead": "a1cca819f83172183b907de16fd5746d07d13ad0"
81
81
  }
@@ -162,17 +162,34 @@ const createSystemCrud = params => {
162
162
 
163
163
  const upgradePlugins = context.plugins.byType("api-upgrade").filter(pl => pl.app === "headless-cms");
164
164
  const installedAppVersion = await this.getSystemVersion();
165
- const plugin = (0, _apiUpgrade.getApplicablePlugin)({
166
- deployedVersion: context.WEBINY_VERSION,
167
- installedAppVersion,
168
- upgradePlugins,
169
- upgradeToVersion: version
170
- });
171
- await plugin.apply(context);
165
+ let plugin;
166
+
167
+ try {
168
+ plugin = (0, _apiUpgrade.getApplicablePlugin)({
169
+ deployedVersion: context.WEBINY_VERSION,
170
+ installedAppVersion,
171
+ upgradePlugins,
172
+ upgradeToVersion: version
173
+ });
174
+ } catch (ex) {
175
+ /**
176
+ * We just let the error disappear if is UPGRADE_NOT_AVAILABLE code
177
+ * and rethrow if is not.
178
+ * This is because we want upgrade to pass if there is no plugin available.
179
+ */
180
+ if (ex.code !== _apiUpgrade.ErrorCode.UPGRADE_NOT_AVAILABLE) {
181
+ throw ex;
182
+ }
183
+ }
184
+
185
+ if (plugin) {
186
+ await plugin.apply(context);
187
+ }
172
188
  /**
173
189
  * Store new app version.
174
190
  */
175
191
 
192
+
176
193
  await setVersion(version);
177
194
  return true;
178
195
  }
package/types.d.ts CHANGED
@@ -1525,6 +1525,11 @@ export interface CmsEntryContext {
1525
1525
  * Update existing entry.
1526
1526
  */
1527
1527
  updateEntry: (model: CmsModel, id: string, data?: Record<string, any>) => Promise<CmsEntry>;
1528
+ /**
1529
+ * Method that republishes entry with given identifier.
1530
+ * @internal
1531
+ */
1532
+ republishEntry: (model: CmsModel, id: string) => Promise<CmsEntry>;
1528
1533
  /**
1529
1534
  * Delete only a certain revision of the entry.
1530
1535
  */