@webiny/api-apw 5.31.0-beta.1 → 5.32.0

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.
Files changed (32) hide show
  1. package/package.json +28 -28
  2. package/plugins/context.js +2 -1
  3. package/plugins/context.js.map +1 -1
  4. package/plugins/hooks/validateComment.js +4 -2
  5. package/plugins/hooks/validateComment.js.map +1 -1
  6. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  7. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  8. package/scheduler/handlers/utils.d.ts +1 -1
  9. package/storageOperations/changeRequestStorageOperations.d.ts +1 -1
  10. package/storageOperations/changeRequestStorageOperations.js +20 -5
  11. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  12. package/storageOperations/commentStorageOperations.d.ts +1 -1
  13. package/storageOperations/commentStorageOperations.js +18 -3
  14. package/storageOperations/commentStorageOperations.js.map +1 -1
  15. package/storageOperations/contentReviewStorageOperations.d.ts +1 -1
  16. package/storageOperations/contentReviewStorageOperations.js +18 -3
  17. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  18. package/storageOperations/index.d.ts +3 -1
  19. package/storageOperations/index.js +3 -18
  20. package/storageOperations/index.js.map +1 -1
  21. package/storageOperations/models/contentModelPluginFactory.d.ts +5 -7
  22. package/storageOperations/models/contentModelPluginFactory.js +3 -4
  23. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  24. package/storageOperations/models/index.js +3 -3
  25. package/storageOperations/models/index.js.map +1 -1
  26. package/storageOperations/reviewerStorageOperations.d.ts +1 -1
  27. package/storageOperations/reviewerStorageOperations.js +12 -1
  28. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  29. package/storageOperations/workflowStorageOperations.d.ts +1 -1
  30. package/storageOperations/workflowStorageOperations.js +22 -5
  31. package/storageOperations/workflowStorageOperations.js.map +1 -1
  32. package/utils/resolve.d.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-apw",
3
- "version": "5.31.0-beta.1",
3
+ "version": "5.32.0",
4
4
  "keywords": [
5
5
  "apw:base"
6
6
  ],
@@ -17,24 +17,24 @@
17
17
  "@aws-sdk/client-cloudwatch-events": "3.142.0",
18
18
  "@babel/runtime": "7.18.9",
19
19
  "@commodo/fields": "1.1.2-beta.20",
20
- "@webiny/api": "5.31.0-beta.1",
21
- "@webiny/api-headless-cms": "5.31.0-beta.1",
22
- "@webiny/api-i18n": "5.31.0-beta.1",
23
- "@webiny/api-i18n-ddb": "5.31.0-beta.1",
24
- "@webiny/api-page-builder": "5.31.0-beta.1",
25
- "@webiny/api-security": "5.31.0-beta.1",
26
- "@webiny/api-tenancy": "5.31.0-beta.1",
27
- "@webiny/api-wcp": "5.31.0-beta.1",
28
- "@webiny/db-dynamodb": "5.31.0-beta.1",
29
- "@webiny/error": "5.31.0-beta.1",
30
- "@webiny/handler": "5.31.0-beta.1",
31
- "@webiny/handler-client": "5.31.0-beta.1",
32
- "@webiny/handler-db": "5.31.0-beta.1",
33
- "@webiny/handler-graphql": "5.31.0-beta.1",
34
- "@webiny/handler-logs": "5.31.0-beta.1",
35
- "@webiny/plugins": "5.31.0-beta.1",
36
- "@webiny/pubsub": "5.31.0-beta.1",
37
- "@webiny/validation": "5.31.0-beta.1",
20
+ "@webiny/api": "5.32.0",
21
+ "@webiny/api-headless-cms": "5.32.0",
22
+ "@webiny/api-i18n": "5.32.0",
23
+ "@webiny/api-i18n-ddb": "5.32.0",
24
+ "@webiny/api-page-builder": "5.32.0",
25
+ "@webiny/api-security": "5.32.0",
26
+ "@webiny/api-tenancy": "5.32.0",
27
+ "@webiny/api-wcp": "5.32.0",
28
+ "@webiny/db-dynamodb": "5.32.0",
29
+ "@webiny/error": "5.32.0",
30
+ "@webiny/handler": "5.32.0",
31
+ "@webiny/handler-client": "5.32.0",
32
+ "@webiny/handler-db": "5.32.0",
33
+ "@webiny/handler-graphql": "5.32.0",
34
+ "@webiny/handler-logs": "5.32.0",
35
+ "@webiny/plugins": "5.32.0",
36
+ "@webiny/pubsub": "5.32.0",
37
+ "@webiny/validation": "5.32.0",
38
38
  "dayjs": "1.11.4",
39
39
  "lodash": "4.17.21",
40
40
  "mdbid": "1.0.0",
@@ -45,14 +45,14 @@
45
45
  "@babel/core": "^7.5.5",
46
46
  "@babel/preset-env": "^7.5.5",
47
47
  "@babel/preset-flow": "^7.0.0",
48
- "@webiny/api-headless-cms-ddb": "^5.31.0-beta.1",
49
- "@webiny/api-page-builder-so-ddb": "^5.31.0-beta.1",
50
- "@webiny/api-security-so-ddb": "^5.31.0-beta.1",
51
- "@webiny/api-tenancy-so-ddb": "^5.31.0-beta.1",
52
- "@webiny/cli": "^5.31.0-beta.1",
53
- "@webiny/handler-aws": "^5.31.0-beta.1",
54
- "@webiny/project-utils": "^5.31.0-beta.1",
55
- "@webiny/wcp": "^5.31.0-beta.1",
48
+ "@webiny/api-headless-cms-ddb": "^5.32.0",
49
+ "@webiny/api-page-builder-so-ddb": "^5.32.0",
50
+ "@webiny/api-security-so-ddb": "^5.32.0",
51
+ "@webiny/api-tenancy-so-ddb": "^5.32.0",
52
+ "@webiny/cli": "^5.32.0",
53
+ "@webiny/handler-aws": "^5.32.0",
54
+ "@webiny/project-utils": "^5.32.0",
55
+ "@webiny/wcp": "^5.32.0",
56
56
  "get-yarn-workspaces": "^1.0.2",
57
57
  "graphql": "^15.7.2",
58
58
  "jest": "^28.1.0",
@@ -71,5 +71,5 @@
71
71
  "build": "yarn webiny run build",
72
72
  "watch": "yarn webiny run watch"
73
73
  },
74
- "gitHead": "b29a1cdd4c7cba5af3b9b993a78f4561525a9201"
74
+ "gitHead": "1227aa53c68afa4ccd518c8a4344195a2b8e354b"
75
75
  }
@@ -87,7 +87,8 @@ const setupApwContext = params => new _api.ContextPlugin(async context => {
87
87
  /**
88
88
  * TODO: This is required for "entryFieldFromStorageTransform" which access plugins from context.
89
89
  */
90
- getCmsContext: () => context
90
+ getCmsContext: () => context,
91
+ security
91
92
  }),
92
93
  scheduler,
93
94
  handlerClient,
@@ -1 +1 @@
1
- {"version":3,"names":["setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema","createApwHeadlessCmsContext"],"sources":["context.ts"],"sourcesContent":["import { attachApwHooks } from \"./hooks\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { createApw } from \"~/crud\";\nimport { apwPageBuilderHooks } from \"./pageBuilder\";\nimport { createStorageOperations } from \"~/storageOperations\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { createScheduler } from \"~/scheduler\";\nimport { createCustomAuth } from \"~/scheduler/handlers/executeAction/security\";\nimport { isInstallationPending } from \"./utils\";\nimport { extendPbPageSettingsSchema } from \"~/plugins/pageBuilder/extendPbPageSettingsSchema\";\nimport { apwContentPagePlugins } from \"~/plugins/pageBuilder/apwContentPagePlugins\";\nimport { apwCmsHooks } from \"~/plugins/cms\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst setupApwContext = (params: CreateApwContextParams) =>\n new ContextPlugin<ApwContext>(async context => {\n const { tenancy, security, i18n, handlerClient } = context;\n\n if (isInstallationPending({ tenancy, i18n })) {\n return;\n }\n\n const getLocale = (): I18NLocale => {\n const locale = i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/plugins/context.ts\",\n \"LOCALE_ERROR\"\n );\n }\n\n return locale;\n };\n\n const getTenant = (): Tenant => {\n return tenancy.getCurrentTenant();\n };\n\n const getPermission = async (name: string): Promise<SecurityPermission | null> => {\n return security.getPermission(name);\n };\n const getIdentity = () => security.getIdentity();\n\n const scheduler = createScheduler({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: params.storageOperations\n });\n\n context.apw = createApw({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: createStorageOperations({\n /**\n * TODO: We need to figure out a way to pass \"cms\" from outside (e.g. apps/api/graphql)\n */\n cms: context.cms,\n /**\n * TODO: This is required for \"entryFieldFromStorageTransform\" which access plugins from context.\n */\n getCmsContext: () => context\n }),\n scheduler,\n handlerClient,\n plugins: context.plugins\n });\n });\n\nconst setupApwPageBuilder = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwPageBuilderHooks(context);\n });\n};\n\nconst setupApwHeadlessCms = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwCmsHooks(context);\n });\n};\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwPageBuilder().apply(context);\n await setupApwHeadlessCms().apply(context);\n await apwContentPagePlugins().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n\n context.plugins.register(extendPbPageSettingsSchema());\n });\n};\n\nexport const createApwHeadlessCmsContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwHeadlessCms().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA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,2BAA2B,GAAIvC,MAAD,IAAoC;EAC3E,OAAO,IAAIC,kBAAJ,CAA8B,MAAMC,OAAN,IAAiB;IAClD,IAAI,CAACA,OAAO,CAAC6B,GAAR,CAAYC,aAAZ,CAA0B,4BAA1B,CAAL,EAA8D;MAC1D;IACH,CAFD,MAEO,IAAI,IAAAzB,4BAAA,EAAsBL,OAAtB,CAAJ,EAAoC;MACvC;IACH;;IAED,MAAMH,eAAe,CAACC,MAAD,CAAf,CAAwBiC,KAAxB,CAA8B/B,OAA9B,CAAN;IACA,MAAM0B,mBAAmB,GAAGK,KAAtB,CAA4B/B,OAA5B,CAAN;IACA,MAAM,IAAAiC,qBAAA,IAAiBF,KAAjB,CAAuB/B,OAAvB,CAAN;IACA,MAAM,IAAAkC,0BAAA,EAAiBpC,MAAjB,EAAyBiC,KAAzB,CAA+B/B,OAA/B,CAAN;EACH,CAXM,CAAP;AAYH,CAbM"}
1
+ {"version":3,"names":["setupApwContext","params","ContextPlugin","context","tenancy","security","i18n","handlerClient","isInstallationPending","getLocale","locale","getContentLocale","WebinyError","getTenant","getCurrentTenant","getPermission","name","getIdentity","scheduler","createScheduler","storageOperations","apw","createApw","createStorageOperations","cms","getCmsContext","plugins","setupApwPageBuilder","apwPageBuilderHooks","setupApwHeadlessCms","apwCmsHooks","createApwPageBuilderContext","wcp","canUseFeature","apply","apwContentPagePlugins","attachApwHooks","createCustomAuth","register","extendPbPageSettingsSchema","createApwHeadlessCmsContext"],"sources":["context.ts"],"sourcesContent":["import { attachApwHooks } from \"./hooks\";\nimport WebinyError from \"@webiny/error\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { ApwContext } from \"~/types\";\nimport { createApw } from \"~/crud\";\nimport { apwPageBuilderHooks } from \"./pageBuilder\";\nimport { createStorageOperations } from \"~/storageOperations\";\nimport { SecurityPermission } from \"@webiny/api-security/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { CreateApwContextParams } from \"~/scheduler/types\";\nimport { createScheduler } from \"~/scheduler\";\nimport { createCustomAuth } from \"~/scheduler/handlers/executeAction/security\";\nimport { isInstallationPending } from \"./utils\";\nimport { extendPbPageSettingsSchema } from \"~/plugins/pageBuilder/extendPbPageSettingsSchema\";\nimport { apwContentPagePlugins } from \"~/plugins/pageBuilder/apwContentPagePlugins\";\nimport { apwCmsHooks } from \"~/plugins/cms\";\nimport { I18NLocale } from \"@webiny/api-i18n/types\";\n\nconst setupApwContext = (params: CreateApwContextParams) =>\n new ContextPlugin<ApwContext>(async context => {\n const { tenancy, security, i18n, handlerClient } = context;\n\n if (isInstallationPending({ tenancy, i18n })) {\n return;\n }\n\n const getLocale = (): I18NLocale => {\n const locale = i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/plugins/context.ts\",\n \"LOCALE_ERROR\"\n );\n }\n\n return locale;\n };\n\n const getTenant = (): Tenant => {\n return tenancy.getCurrentTenant();\n };\n\n const getPermission = async (name: string): Promise<SecurityPermission | null> => {\n return security.getPermission(name);\n };\n const getIdentity = () => security.getIdentity();\n\n const scheduler = createScheduler({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: params.storageOperations\n });\n\n context.apw = createApw({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations: createStorageOperations({\n /**\n * TODO: We need to figure out a way to pass \"cms\" from outside (e.g. apps/api/graphql)\n */\n cms: context.cms,\n /**\n * TODO: This is required for \"entryFieldFromStorageTransform\" which access plugins from context.\n */\n getCmsContext: () => context,\n security\n }),\n scheduler,\n handlerClient,\n plugins: context.plugins\n });\n });\n\nconst setupApwPageBuilder = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwPageBuilderHooks(context);\n });\n};\n\nconst setupApwHeadlessCms = () => {\n return new ContextPlugin<ApwContext>(async context => {\n apwCmsHooks(context);\n });\n};\n\nexport const createApwPageBuilderContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwPageBuilder().apply(context);\n await setupApwHeadlessCms().apply(context);\n await apwContentPagePlugins().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n\n context.plugins.register(extendPbPageSettingsSchema());\n });\n};\n\nexport const createApwHeadlessCmsContext = (params: CreateApwContextParams) => {\n return new ContextPlugin<ApwContext>(async context => {\n if (!context.wcp.canUseFeature(\"advancedPublishingWorkflow\")) {\n return;\n } else if (isInstallationPending(context)) {\n return;\n }\n\n await setupApwContext(params).apply(context);\n await setupApwHeadlessCms().apply(context);\n await attachApwHooks().apply(context);\n await createCustomAuth(params).apply(context);\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAGA,MAAMA,eAAe,GAAIC,MAAD,IACpB,IAAIC,kBAAJ,CAA8B,MAAMC,OAAN,IAAiB;EAC3C,MAAM;IAAEC,OAAF;IAAWC,QAAX;IAAqBC,IAArB;IAA2BC;EAA3B,IAA6CJ,OAAnD;;EAEA,IAAI,IAAAK,4BAAA,EAAsB;IAAEJ,OAAF;IAAWE;EAAX,CAAtB,CAAJ,EAA8C;IAC1C;EACH;;EAED,MAAMG,SAAS,GAAG,MAAkB;IAChC,MAAMC,MAAM,GAAGJ,IAAI,CAACK,gBAAL,EAAf;;IACA,IAAI,CAACD,MAAL,EAAa;MACT,MAAM,IAAIE,cAAJ,CACF,sDADE,EAEF,cAFE,CAAN;IAIH;;IAED,OAAOF,MAAP;EACH,CAVD;;EAYA,MAAMG,SAAS,GAAG,MAAc;IAC5B,OAAOT,OAAO,CAACU,gBAAR,EAAP;EACH,CAFD;;EAIA,MAAMC,aAAa,GAAG,MAAOC,IAAP,IAA4D;IAC9E,OAAOX,QAAQ,CAACU,aAAT,CAAuBC,IAAvB,CAAP;EACH,CAFD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IACH;;IAED,MAAMH,eAAe,CAACC,MAAD,CAAf,CAAwBiC,KAAxB,CAA8B/B,OAA9B,CAAN;IACA,MAAMwB,mBAAmB,GAAGO,KAAtB,CAA4B/B,OAA5B,CAAN;IACA,MAAM0B,mBAAmB,GAAGK,KAAtB,CAA4B/B,OAA5B,CAAN;IACA,MAAM,IAAAgC,4CAAA,IAAwBD,KAAxB,CAA8B/B,OAA9B,CAAN;IACA,MAAM,IAAAiC,qBAAA,IAAiBF,KAAjB,CAAuB/B,OAAvB,CAAN;IACA,MAAM,IAAAkC,0BAAA,EAAiBpC,MAAjB,EAAyBiC,KAAzB,CAA+B/B,OAA/B,CAAN;IAEAA,OAAO,CAACuB,OAAR,CAAgBY,QAAhB,CAAyB,IAAAC,sDAAA,GAAzB;EACH,CAfM,CAAP;AAgBH,CAjBM;;;;AAmBA,MAAMC,2BAA2B,GAAIvC,MAAD,IAAoC;EAC3E,OAAO,IAAIC,kBAAJ,CAA8B,MAAMC,OAAN,IAAiB;IAClD,IAAI,CAACA,OAAO,CAAC6B,GAAR,CAAYC,aAAZ,CAA0B,4BAA1B,CAAL,EAA8D;MAC1D;IACH,CAFD,MAEO,IAAI,IAAAzB,4BAAA,EAAsBL,OAAtB,CAAJ,EAAoC;MACvC;IACH;;IAED,MAAMH,eAAe,CAACC,MAAD,CAAf,CAAwBiC,KAAxB,CAA8B/B,OAA9B,CAAN;IACA,MAAM0B,mBAAmB,GAAGK,KAAtB,CAA4B/B,OAA5B,CAAN;IACA,MAAM,IAAAiC,qBAAA,IAAiBF,KAAjB,CAAuB/B,OAAvB,CAAN;IACA,MAAM,IAAAkC,0BAAA,EAAiBpC,MAAjB,EAAyBiC,KAAzB,CAA+B/B,OAA/B,CAAN;EACH,CAXM,CAAP;AAYH,CAbM"}
@@ -36,9 +36,11 @@ const validateComment = ({
36
36
 
37
37
  const changeRequest = await apw.changeRequest.get(changeRequestId);
38
38
 
39
- if (changeRequest) {
40
- input.step = changeRequest.step;
39
+ if (!changeRequest) {
40
+ return;
41
41
  }
42
+
43
+ input.step = changeRequest.step;
42
44
  });
43
45
  };
44
46
 
@@ -1 +1 @@
1
- {"version":3,"names":["validateComment","apw","comment","onBeforeCommentCreate","subscribe","input","changeRequest","changeRequestId","entryId","version","split","WebinyError","get","step"],"sources":["validateComment.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateComment = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onBeforeCommentCreate.subscribe(async ({ input }) => {\n const { changeRequest: changeRequestId } = input;\n /**\n * We need changeRequest to be in a particular format i.e. \"contentReviewUniqueId#version\"\n */\n const [entryId, version] = changeRequestId.split(\"#\");\n if (!entryId || !version) {\n throw new WebinyError(\n `The\"changeRequest\" property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n input\n }\n );\n }\n\n /**\n * Assign value for \"step\" field from \"changeRequest\".\n */\n const changeRequest = await apw.changeRequest.get(changeRequestId);\n if (changeRequest) {\n input.step = changeRequest.step;\n }\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAGO,MAAMA,eAAe,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAClFA,GAAG,CAACC,OAAJ,CAAYC,qBAAZ,CAAkCC,SAAlC,CAA4C,OAAO;IAAEC;EAAF,CAAP,KAAqB;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAjB,IAAqCF,KAA3C;IACA;AACR;AACA;;IACQ,MAAM,CAACG,OAAD,EAAUC,OAAV,IAAqBF,eAAe,CAACG,KAAhB,CAAsB,GAAtB,CAA3B;;IACA,IAAI,CAACF,OAAD,IAAY,CAACC,OAAjB,EAA0B;MACtB,MAAM,IAAIE,cAAJ,CACD,iEADC,EAEF,6BAFE,EAGF;QACIN;MADJ,CAHE,CAAN;IAOH;IAED;AACR;AACA;;;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAJ,CAAkBM,GAAlB,CAAsBL,eAAtB,CAA5B;;IACA,IAAID,aAAJ,EAAmB;MACfD,KAAK,CAACQ,IAAN,GAAaP,aAAa,CAACO,IAA3B;IACH;EACJ,CAvBD;AAwBH,CAzBM"}
1
+ {"version":3,"names":["validateComment","apw","comment","onBeforeCommentCreate","subscribe","input","changeRequest","changeRequestId","entryId","version","split","WebinyError","get","step"],"sources":["validateComment.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { LifeCycleHookCallbackParams } from \"~/types\";\n\nexport const validateComment = ({ apw }: Pick<LifeCycleHookCallbackParams, \"apw\">) => {\n apw.comment.onBeforeCommentCreate.subscribe(async ({ input }) => {\n const { changeRequest: changeRequestId } = input;\n /**\n * We need changeRequest to be in a particular format i.e. \"contentReviewUniqueId#version\"\n */\n const [entryId, version] = changeRequestId.split(\"#\");\n if (!entryId || !version) {\n throw new WebinyError(\n `The\"changeRequest\" property in input is not properly formatted.`,\n \"MALFORMED_CHANGE_REQUEST_ID\",\n {\n input\n }\n );\n }\n\n /**\n * Assign value for \"step\" field from \"changeRequest\".\n */\n const changeRequest = await apw.changeRequest.get(changeRequestId);\n if (!changeRequest) {\n return;\n }\n input.step = changeRequest.step;\n });\n};\n"],"mappings":";;;;;;;;;AAAA;;AAGO,MAAMA,eAAe,GAAG,CAAC;EAAEC;AAAF,CAAD,KAAuD;EAClFA,GAAG,CAACC,OAAJ,CAAYC,qBAAZ,CAAkCC,SAAlC,CAA4C,OAAO;IAAEC;EAAF,CAAP,KAAqB;IAC7D,MAAM;MAAEC,aAAa,EAAEC;IAAjB,IAAqCF,KAA3C;IACA;AACR;AACA;;IACQ,MAAM,CAACG,OAAD,EAAUC,OAAV,IAAqBF,eAAe,CAACG,KAAhB,CAAsB,GAAtB,CAA3B;;IACA,IAAI,CAACF,OAAD,IAAY,CAACC,OAAjB,EAA0B;MACtB,MAAM,IAAIE,cAAJ,CACD,iEADC,EAEF,6BAFE,EAGF;QACIN;MADJ,CAHE,CAAN;IAOH;IAED;AACR;AACA;;;IACQ,MAAMC,aAAa,GAAG,MAAML,GAAG,CAACK,aAAJ,CAAkBM,GAAlB,CAAsBL,eAAtB,CAA5B;;IACA,IAAI,CAACD,aAAL,EAAoB;MAChB;IACH;;IACDD,KAAK,CAACQ,IAAN,GAAaP,aAAa,CAACO,IAA3B;EACH,CAxBD;AAyBH,CA1BM"}
@@ -9,5 +9,5 @@ export interface HandlerArgs {
9
9
  interface Configuration {
10
10
  storageOperations: ApwScheduleActionStorageOperations;
11
11
  }
12
- export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler").EventPlugin<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
12
+ export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler").EventPlugin<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
13
13
  export {};
@@ -19,4 +19,4 @@ export interface Configuration {
19
19
  executeAction: string;
20
20
  };
21
21
  }
22
- export declare const scheduleActionHandlerPlugins: (config: Configuration) => ((import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any>)[];
22
+ export declare const scheduleActionHandlerPlugins: (config: Configuration) => ((import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any>)[];
@@ -19,7 +19,7 @@ export declare const encodeToken: ({ id, tenant, locale }: EncodeTokenParams) =>
19
19
  export declare const TOKEN_PREFIX = "apw-";
20
20
  export declare const decodeToken: (token: string) => Partial<EncodeTokenParams>;
21
21
  export declare const documentClient: DocumentClient;
22
- export declare const basePlugins: () => (import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[];
22
+ export declare const basePlugins: () => (import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[];
23
23
  /**
24
24
  * Get APW settings record from DDB.
25
25
  */
@@ -1,3 +1,3 @@
1
1
  import { ApwChangeRequestStorageOperations } from "./types";
2
2
  import { CreateApwStorageOperationsParams } from "./index";
3
- export declare const createChangeRequestStorageOperations: ({ cms, getCmsContext }: CreateApwStorageOperationsParams) => ApwChangeRequestStorageOperations;
3
+ export declare const createChangeRequestStorageOperations: (params: CreateApwStorageOperationsParams) => ApwChangeRequestStorageOperations;
@@ -19,15 +19,20 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
19
19
 
20
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
21
 
22
- const createChangeRequestStorageOperations = ({
23
- cms,
24
- getCmsContext
25
- }) => {
22
+ const createChangeRequestStorageOperations = params => {
23
+ const {
24
+ cms,
25
+ getCmsContext,
26
+ security
27
+ } = params;
28
+
26
29
  const getChangeRequestModel = async () => {
30
+ security.disableAuthorization();
27
31
  const model = await cms.getModel("apwChangeRequestModelDefinition");
32
+ security.enableAuthorization();
28
33
 
29
34
  if (!model) {
30
- throw new _error.default("Could not find `apwWorkflowModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
35
+ throw new _error.default("Could not find `apwChangeRequestModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
31
36
  }
32
37
 
33
38
  return model;
@@ -37,7 +42,9 @@ const createChangeRequestStorageOperations = ({
37
42
  id
38
43
  }) => {
39
44
  const model = await getChangeRequestModel();
45
+ security.disableAuthorization();
40
46
  const entry = await cms.getEntryById(model, id);
47
+ security.enableAuthorization();
41
48
  return (0, _fieldResolver.getFieldValues)({
42
49
  entry,
43
50
  fields: _index.baseFields,
@@ -52,9 +59,11 @@ const createChangeRequestStorageOperations = ({
52
59
 
53
60
  async listChangeRequests(params) {
54
61
  const model = await getChangeRequestModel();
62
+ security.disableAuthorization();
55
63
  const [entries, meta] = await cms.listLatestEntries(model, _objectSpread(_objectSpread({}, params), {}, {
56
64
  where: _objectSpread({}, params.where)
57
65
  }));
66
+ security.enableAuthorization();
58
67
  const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
59
68
  entry,
60
69
  fields: _index.baseFields,
@@ -66,7 +75,9 @@ const createChangeRequestStorageOperations = ({
66
75
 
67
76
  async createChangeRequest(params) {
68
77
  const model = await getChangeRequestModel();
78
+ security.disableAuthorization();
69
79
  const entry = await cms.createEntry(model, params.data);
80
+ security.enableAuthorization();
70
81
  return (0, _fieldResolver.getFieldValues)({
71
82
  entry,
72
83
  fields: _index.baseFields,
@@ -85,7 +96,9 @@ const createChangeRequestStorageOperations = ({
85
96
  const existingEntry = await getChangeRequest({
86
97
  id: params.id
87
98
  });
99
+ security.disableAuthorization();
88
100
  const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
101
+ security.enableAuthorization();
89
102
  return (0, _fieldResolver.getFieldValues)({
90
103
  entry,
91
104
  fields: _index.baseFields,
@@ -96,7 +109,9 @@ const createChangeRequestStorageOperations = ({
96
109
 
97
110
  async deleteChangeRequest(params) {
98
111
  const model = await getChangeRequestModel();
112
+ security.disableAuthorization();
99
113
  await cms.deleteEntry(model, params.id);
114
+ security.enableAuthorization();
100
115
  return true;
101
116
  }
102
117
 
@@ -1 +1 @@
1
- {"version":3,"names":["createChangeRequestStorageOperations","cms","getCmsContext","getChangeRequestModel","model","getModel","WebinyError","getChangeRequest","id","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","listChangeRequests","params","entries","meta","listLatestEntries","where","all","Promise","map","createChangeRequest","createEntry","data","updateChangeRequest","existingEntry","updateEntry","deleteChangeRequest","deleteEntry"],"sources":["changeRequestStorageOperations.ts"],"sourcesContent":["import { ApwChangeRequestStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwChangeRequest } from \"~/types\";\n\nexport const createChangeRequestStorageOperations = ({\n cms,\n getCmsContext\n}: CreateApwStorageOperationsParams): ApwChangeRequestStorageOperations => {\n const getChangeRequestModel = async () => {\n const model = await cms.getModel(\"apwChangeRequestModelDefinition\");\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwWorkflowModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getChangeRequest: ApwChangeRequestStorageOperations[\"getChangeRequest\"] = async ({\n id\n }) => {\n const model = await getChangeRequestModel();\n const entry = await cms.getEntryById(model, id);\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getChangeRequestModel,\n getChangeRequest,\n async listChangeRequests(params) {\n const model = await getChangeRequestModel();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n const all = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwChangeRequest>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n return [all, meta];\n },\n async createChangeRequest(params) {\n const model = await getChangeRequestModel();\n const entry = await cms.createEntry(model, params.data);\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async updateChangeRequest(params) {\n const model = await getChangeRequestModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getChangeRequest({ id: params.id });\n\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async deleteChangeRequest(params) {\n const model = await getChangeRequestModel();\n await cms.deleteEntry(model, params.id);\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;;;;;AAGO,MAAMA,oCAAoC,GAAG,CAAC;EACjDC,GADiD;EAEjDC;AAFiD,CAAD,KAGuB;EACvE,MAAMC,qBAAqB,GAAG,YAAY;IACtC,MAAMC,KAAK,GAAG,MAAMH,GAAG,CAACI,QAAJ,CAAa,iCAAb,CAApB;;IACA,IAAI,CAACD,KAAL,EAAY;MACR,MAAM,IAAIE,cAAJ,CACF,oDADE,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOF,KAAP;EACH,CATD;;EAUA,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,MAAM,CAACU,IAA9B,CAApB;MACA,OAAO,IAAAjB,6BAAA,EAAe;QAClBF,KADkB;QAElBG,MAAM,EAAEC,iBAFU;QAGlBC,OAAO,EAAEZ,aAAa,EAHJ;QAIlBa,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeZ,KAAf,EAAsB,MAAtB,CAAD;MAJI,CAAf,CAAP;IAMH,CAhCE;;IAiCH,MAAMyB,mBAAN,CAA0BX,MAA1B,EAAkC;MAC9B,MAAMd,KAAK,GAAG,MAAMD,qBAAqB,EAAzC;MACA;AACZ;AACA;AACA;;MACY,MAAM2B,aAAa,GAAG,MAAMvB,gBAAgB,CAAC;QAAEC,EAAE,EAAEU,MAAM,CAACV;MAAb,CAAD,CAA5C;MAEA,MAAMC,KAAK,GAAG,MAAMR,GAAG,CAAC8B,WAAJ,CAAgB3B,KAAhB,EAAuBc,MAAM,CAACV,EAA9B,kCACbsB,aADa,GAEbZ,MAAM,CAACU,IAFM,EAApB;MAIA,OAAO,IAAAjB,6BAAA,EAAe;QAClBF,KADkB;QAElBG,MAAM,EAAEC,iBAFU;QAGlBC,OAAO,EAAEZ,aAAa,EAHJ;QAIlBa,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeZ,KAAf,EAAsB,MAAtB,CAAD;MAJI,CAAf,CAAP;IAMH,CAnDE;;IAoDH,MAAM4B,mBAAN,CAA0Bd,MAA1B,EAAkC;MAC9B,MAAMd,KAAK,GAAG,MAAMD,qBAAqB,EAAzC;MACA,MAAMF,GAAG,CAACgC,WAAJ,CAAgB7B,KAAhB,EAAuBc,MAAM,CAACV,EAA9B,CAAN;MACA,OAAO,IAAP;IACH;;EAxDE,CAAP;AA0DH,CApFM"}
1
+ {"version":3,"names":["createChangeRequestStorageOperations","params","cms","getCmsContext","security","getChangeRequestModel","disableAuthorization","model","getModel","enableAuthorization","WebinyError","getChangeRequest","id","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","listChangeRequests","entries","meta","listLatestEntries","where","all","Promise","map","createChangeRequest","createEntry","data","updateChangeRequest","existingEntry","updateEntry","deleteChangeRequest","deleteEntry"],"sources":["changeRequestStorageOperations.ts"],"sourcesContent":["import { ApwChangeRequestStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwChangeRequest } from \"~/types\";\n\nexport const createChangeRequestStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwChangeRequestStorageOperations => {\n const { cms, getCmsContext, security } = params;\n const getChangeRequestModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(\"apwChangeRequestModelDefinition\");\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwChangeRequestModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getChangeRequest: ApwChangeRequestStorageOperations[\"getChangeRequest\"] = async ({\n id\n }) => {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getChangeRequestModel,\n getChangeRequest,\n async listChangeRequests(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n security.enableAuthorization();\n const all = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwChangeRequest>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n return [all, meta];\n },\n async createChangeRequest(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.createEntry(model, params.data);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async updateChangeRequest(params) {\n const model = await getChangeRequestModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getChangeRequest({ id: params.id });\n\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async deleteChangeRequest(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AACA;;AACA;;;;;;AAGO,MAAMA,oCAAoC,GAC7CC,MADgD,IAEZ;EACpC,MAAM;IAAEC,GAAF;IAAOC,aAAP;IAAsBC;EAAtB,IAAmCH,MAAzC;;EACA,MAAMI,qBAAqB,GAAG,YAAY;IACtCD,QAAQ,CAACE,oBAAT;IACA,MAAMC,KAAK,GAAG,MAAML,GAAG,CAACM,QAAJ,CAAa,iCAAb,CAApB;IACAJ,QAAQ,CAACK,mBAAT;;IACA,IAAI,CAACF,KAAL,EAAY;MACR,MAAM,IAAIG,cAAJ,CACF,yDADE,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOH,KAAP;EACH,CAXD;;EAYA,MAAMI,gBAAuE,GAAG,OAAO;IACnFC;EADmF,CAAP,KAE1E;IACF,MAAML,KAAK,GAAG,MAAMF,qBAAqB,EAAzC;IACAD,QAAQ,CAACE,oBAAT;IACA,MAAMO,KAAK,GAAG,MAAMX,GAAG,CAACY,YAAJ,CAAiBP,KAAjB,EAAwBK,EAAxB,CAApB;IACAR,QAAQ,CAACK,mBAAT;IACA,OAAO,IAAAM,6BAAA,EAAe;MAClBF,KADkB;MAElBG,MAAM,EAAEC,iBAFU;MAGlBC,OAAO,EAAEf,aAAa,EAHJ;MAIlBgB,YAAY,EAAE,CAA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I,CAAf,CAAP;IAMH,CApCE;;IAqCH,MAAMyB,mBAAN,CAA0B/B,MAA1B,EAAkC;MAC9B,MAAMM,KAAK,GAAG,MAAMF,qBAAqB,EAAzC;MACA;AACZ;AACA;AACA;;MACY,MAAM4B,aAAa,GAAG,MAAMtB,gBAAgB,CAAC;QAAEC,EAAE,EAAEX,MAAM,CAACW;MAAb,CAAD,CAA5C;MAEAR,QAAQ,CAACE,oBAAT;MACA,MAAMO,KAAK,GAAG,MAAMX,GAAG,CAACgC,WAAJ,CAAgB3B,KAAhB,EAAuBN,MAAM,CAACW,EAA9B,kCACbqB,aADa,GAEbhC,MAAM,CAAC8B,IAFM,EAApB;MAIA3B,QAAQ,CAACK,mBAAT;MACA,OAAO,IAAAM,6BAAA,EAAe;QAClBF,KADkB;QAElBG,MAAM,EAAEC,iBAFU;QAGlBC,OAAO,EAAEf,aAAa,EAHJ;QAIlBgB,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeb,KAAf,EAAsB,MAAtB,CAAD;MAJI,CAAf,CAAP;IAMH,CAzDE;;IA0DH,MAAM4B,mBAAN,CAA0BlC,MAA1B,EAAkC;MAC9B,MAAMM,KAAK,GAAG,MAAMF,qBAAqB,EAAzC;MACAD,QAAQ,CAACE,oBAAT;MACA,MAAMJ,GAAG,CAACkC,WAAJ,CAAgB7B,KAAhB,EAAuBN,MAAM,CAACW,EAA9B,CAAN;MACAR,QAAQ,CAACK,mBAAT;MACA,OAAO,IAAP;IACH;;EAhEE,CAAP;AAkEH,CAhGM"}
@@ -1,3 +1,3 @@
1
1
  import { ApwCommentStorageOperations } from "./types";
2
2
  import { CreateApwStorageOperationsParams } from "./index";
3
- export declare const createCommentStorageOperations: ({ cms, getCmsContext }: CreateApwStorageOperationsParams) => ApwCommentStorageOperations;
3
+ export declare const createCommentStorageOperations: ({ cms, getCmsContext, security }: CreateApwStorageOperationsParams) => ApwCommentStorageOperations;
@@ -15,6 +15,8 @@ var _fieldResolver = require("../utils/fieldResolver");
15
15
 
16
16
  var _error = _interopRequireDefault(require("@webiny/error"));
17
17
 
18
+ var _comment = require("./models/comment.model");
19
+
18
20
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
21
 
20
22
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -32,13 +34,16 @@ const pickIdFromChangeRequest = obj => {
32
34
 
33
35
  const createCommentStorageOperations = ({
34
36
  cms,
35
- getCmsContext
37
+ getCmsContext,
38
+ security
36
39
  }) => {
37
40
  const getCommentModel = async () => {
38
- const model = await cms.getModel("apwCommentModelDefinition");
41
+ security.disableAuthorization();
42
+ const model = await cms.getModel(_comment.COMMENT_MODEL_ID);
43
+ security.enableAuthorization();
39
44
 
40
45
  if (!model) {
41
- throw new _error.default("Could not find `apwContentReviewModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
46
+ throw new _error.default(`Could not find "${_comment.COMMENT_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
42
47
  }
43
48
 
44
49
  return model;
@@ -48,7 +53,9 @@ const createCommentStorageOperations = ({
48
53
  id
49
54
  }) => {
50
55
  const model = await getCommentModel();
56
+ security.disableAuthorization();
51
57
  const entry = await cms.getEntryById(model, id);
58
+ security.enableAuthorization();
52
59
  return (0, _fieldResolver.getFieldValues)({
53
60
  entry,
54
61
  fields: _index.baseFields,
@@ -66,7 +73,9 @@ const createCommentStorageOperations = ({
66
73
 
67
74
  async listComments(params) {
68
75
  const model = await getCommentModel();
76
+ security.disableAuthorization();
69
77
  const [entries, meta] = await cms.listLatestEntries(model, params);
78
+ security.enableAuthorization();
70
79
  const values = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
71
80
  entry,
72
81
  fields: _index.baseFields,
@@ -80,12 +89,14 @@ const createCommentStorageOperations = ({
80
89
  async createComment(params) {
81
90
  const model = await getCommentModel();
82
91
  const refModel = await this.getChangeRequestModel();
92
+ security.disableAuthorization();
83
93
  const entry = await cms.createEntry(model, _objectSpread(_objectSpread({}, params.data), {}, {
84
94
  changeRequest: {
85
95
  id: params.data.changeRequest,
86
96
  modelId: refModel.modelId
87
97
  }
88
98
  }));
99
+ security.enableAuthorization();
89
100
  const values = await (0, _fieldResolver.getFieldValues)({
90
101
  entry,
91
102
  fields: _index.baseFields,
@@ -105,7 +116,9 @@ const createCommentStorageOperations = ({
105
116
  const existingEntry = await getComment({
106
117
  id: params.id
107
118
  });
119
+ security.disableAuthorization();
108
120
  const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
121
+ security.enableAuthorization();
109
122
  const values = await (0, _fieldResolver.getFieldValues)({
110
123
  entry,
111
124
  fields: _index.baseFields,
@@ -117,7 +130,9 @@ const createCommentStorageOperations = ({
117
130
 
118
131
  async deleteComment(params) {
119
132
  const model = await getCommentModel();
133
+ security.disableAuthorization();
120
134
  await cms.deleteEntry(model, params.id);
135
+ security.enableAuthorization();
121
136
  return true;
122
137
  }
123
138
 
@@ -1 +1 @@
1
- {"version":3,"names":["pickIdFromChangeRequest","obj","rawValue","id","createCommentStorageOperations","cms","getCmsContext","getCommentModel","model","getModel","WebinyError","getComment","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","params","values","listComments","entries","meta","listLatestEntries","Promise","all","map","value","createComment","refModel","getChangeRequestModel","createEntry","data","changeRequest","modelId","updateComment","existingEntry","updateEntry","deleteComment","deleteEntry"],"sources":["commentStorageOperations.ts"],"sourcesContent":["import { ApwStorageOperations } from \"./types\";\nimport { ApwCommentStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwComment } from \"~/types\";\nimport { CmsEntryListParams } from \"@webiny/api-headless-cms/types\";\n\nconst pickIdFromChangeRequest = (obj: Record<string, any>): ApwComment => {\n const rawValue = obj[\"changeRequest\"];\n if (!rawValue) {\n return obj as unknown as ApwComment;\n }\n obj[\"changeRequest\"] = rawValue.id;\n return obj as unknown as ApwComment;\n};\n\nexport const createCommentStorageOperations = ({\n cms,\n getCmsContext\n}: CreateApwStorageOperationsParams): ApwCommentStorageOperations => {\n const getCommentModel = async () => {\n const model = await cms.getModel(\"apwCommentModelDefinition\");\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwContentReviewModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getComment: ApwCommentStorageOperations[\"getComment\"] = async ({ id }) => {\n const model = await getCommentModel();\n const entry = await cms.getEntryById(model, id);\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getCommentModel,\n getComment: async params => {\n const values = await getComment(params);\n return pickIdFromChangeRequest(values);\n },\n async listComments(params) {\n const model = await getCommentModel();\n const [entries, meta] = await cms.listLatestEntries(\n model,\n params as CmsEntryListParams\n );\n const values = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwComment>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n const all = values.map(value => pickIdFromChangeRequest(value));\n return [all, meta];\n },\n async createComment(this: ApwStorageOperations, params) {\n const model = await getCommentModel();\n const refModel = await this.getChangeRequestModel();\n const entry = await cms.createEntry(model, {\n ...params.data,\n changeRequest: {\n id: params.data.changeRequest,\n modelId: refModel.modelId\n }\n });\n\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async updateComment(params) {\n const model = await getCommentModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getComment({ id: params.id });\n\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async deleteComment(params) {\n const model = await getCommentModel();\n await cms.deleteEntry(model, params.id);\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AACA;;AACA;;;;;;AAIA,MAAMA,uBAAuB,GAAIC,GAAD,IAA0C;EACtE,MAAMC,QAAQ,GAAGD,GAAG,CAAC,eAAD,CAApB;;EACA,IAAI,CAACC,QAAL,EAAe;IACX,OAAOD,GAAP;EACH;;EACDA,GAAG,CAAC,eAAD,CAAH,GAAuBC,QAAQ,CAACC,EAAhC;EACA,OAAOF,GAAP;AACH,CAPD;;AASO,MAAMG,8BAA8B,GAAG,CAAC;EAC3CC,GAD2C;EAE3CC;AAF2C,CAAD,KAGuB;EACjE,MAAMC,eAAe,GAAG,YAAY;IAChC,MAAMC,KAAK,GAAG,MAAMH,GAAG,CAACI,QAAJ,CAAa,2BAAb,CAApB;;IACA,IAAI,CAACD,KAAL,EAAY;MACR,MAAM,IAAIE,cAAJ,CACF,yDADE,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOF,KAAP;EACH,CATD;;EAUA,MAAMG,UAAqD,GAAG,OAAO;IAAER;EAAF,CAAP,KAAkB;IAC5E,MAAMK,KAAK,GAAG,MAAMD,eAAe,EAAnC;IACA,MAAMK,KAAK,GAAG,MAAMP,GAAG,CAACQ,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AAMF,GAAG,CAACoC,WAAJ,CAAgBjC,KAAhB,EAAuBY,MAAM,CAACjB,EAA9B,CAAN;MACA,OAAO,IAAP;IACH;;EApEE,CAAP;AAsEH,CA9FM"}
1
+ {"version":3,"names":["pickIdFromChangeRequest","obj","rawValue","id","createCommentStorageOperations","cms","getCmsContext","security","getCommentModel","disableAuthorization","model","getModel","COMMENT_MODEL_ID","enableAuthorization","WebinyError","getComment","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","params","values","listComments","entries","meta","listLatestEntries","Promise","all","map","value","createComment","refModel","getChangeRequestModel","createEntry","data","changeRequest","modelId","updateComment","existingEntry","updateEntry","deleteComment","deleteEntry"],"sources":["commentStorageOperations.ts"],"sourcesContent":["import { ApwStorageOperations } from \"./types\";\nimport { ApwCommentStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwComment } from \"~/types\";\nimport { CmsEntryListParams } from \"@webiny/api-headless-cms/types\";\nimport { COMMENT_MODEL_ID } from \"~/storageOperations/models/comment.model\";\n\nconst pickIdFromChangeRequest = (obj: Record<string, any>): ApwComment => {\n const rawValue = obj[\"changeRequest\"];\n if (!rawValue) {\n return obj as unknown as ApwComment;\n }\n obj[\"changeRequest\"] = rawValue.id;\n return obj as unknown as ApwComment;\n};\n\nexport const createCommentStorageOperations = ({\n cms,\n getCmsContext,\n security\n}: CreateApwStorageOperationsParams): ApwCommentStorageOperations => {\n const getCommentModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(COMMENT_MODEL_ID);\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n `Could not find \"${COMMENT_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getComment: ApwCommentStorageOperations[\"getComment\"] = async ({ id }) => {\n const model = await getCommentModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getCommentModel,\n getComment: async params => {\n const values = await getComment(params);\n return pickIdFromChangeRequest(values);\n },\n async listComments(params) {\n const model = await getCommentModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(\n model,\n params as CmsEntryListParams\n );\n security.enableAuthorization();\n const values = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwComment>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n const all = values.map(value => pickIdFromChangeRequest(value));\n return [all, meta];\n },\n async createComment(this: ApwStorageOperations, params) {\n const model = await getCommentModel();\n const refModel = await this.getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.createEntry(model, {\n ...params.data,\n changeRequest: {\n id: params.data.changeRequest,\n modelId: refModel.modelId\n }\n });\n security.enableAuthorization();\n\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async updateComment(params) {\n const model = await getCommentModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getComment({ id: params.id });\n\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n security.enableAuthorization();\n const values = await getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n return pickIdFromChangeRequest(values);\n },\n async deleteComment(params) {\n const model = await getCommentModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AACA;;AACA;;AAGA;;;;;;AAEA,MAAMA,uBAAuB,GAAIC,G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C,OAAO,EAAEf,aAAa,EAHU;QAIhCgB,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeb,KAAf,EAAsB,MAAtB,CAAD;MAJkB,CAAf,CAArB;MAMA,OAAOV,uBAAuB,CAACyB,MAAD,CAA9B;IACH,CA/CE;;IAgDH,MAAMgB,aAAN,CAAoBjB,MAApB,EAA4B;MACxB,MAAMd,KAAK,GAAG,MAAMF,eAAe,EAAnC;MACA;AACZ;AACA;AACA;;MACY,MAAMkC,aAAa,GAAG,MAAM3B,UAAU,CAAC;QAAEZ,EAAE,EAAEqB,MAAM,CAACrB;MAAb,CAAD,CAAtC;MAEAI,QAAQ,CAACE,oBAAT;MACA,MAAMO,KAAK,GAAG,MAAMX,GAAG,CAACsC,WAAJ,CAAgBjC,KAAhB,EAAuBc,MAAM,CAACrB,EAA9B,kCACbuC,aADa,GAEblB,MAAM,CAACc,IAFM,EAApB;MAIA/B,QAAQ,CAACM,mBAAT;MACA,MAAMY,MAAM,GAAG,MAAM,IAAAP,6BAAA,EAAe;QAChCF,KADgC;QAEhCG,MAAM,EAAEC,iBAFwB;QAGhCC,OAAO,EAAEf,aAAa,EAHU;QAIhCgB,YAAY,EAAE,CAAC,IAAAC,6BAAA,EAAeb,KAAf,EAAsB,MAAtB,CAAD;MAJkB,CAAf,CAArB;MAMA,OAAOV,uBAAuB,CAACyB,MAAD,CAA9B;IACH,CArEE;;IAsEH,MAAMmB,aAAN,CAAoBpB,MAApB,EAA4B;MACxB,MAAMd,KAAK,GAAG,MAAMF,eAAe,EAAnC;MACAD,QAAQ,CAACE,oBAAT;MACA,MAAMJ,GAAG,CAACwC,WAAJ,CAAgBnC,KAAhB,EAAuBc,MAAM,CAACrB,EAA9B,CAAN;MACAI,QAAQ,CAACM,mBAAT;MACA,OAAO,IAAP;IACH;;EA5EE,CAAP;AA8EH,CA3GM"}
@@ -1,3 +1,3 @@
1
1
  import { ApwContentReviewStorageOperations } from "./types";
2
2
  import { CreateApwStorageOperationsParams } from "./index";
3
- export declare const createContentReviewStorageOperations: ({ cms }: Pick<CreateApwStorageOperationsParams, "cms">) => ApwContentReviewStorageOperations;
3
+ export declare const createContentReviewStorageOperations: ({ cms, security }: CreateApwStorageOperationsParams) => ApwContentReviewStorageOperations;
@@ -13,18 +13,23 @@ var _index = require("./index");
13
13
 
14
14
  var _error = _interopRequireDefault(require("@webiny/error"));
15
15
 
16
+ var _contentReview = require("./models/contentReview.model");
17
+
16
18
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
19
 
18
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
21
 
20
22
  const createContentReviewStorageOperations = ({
21
- cms
23
+ cms,
24
+ security
22
25
  }) => {
23
26
  const getContentReviewModel = async () => {
24
- const model = await cms.getModel("apwContentReviewModelDefinition");
27
+ security.disableAuthorization();
28
+ const model = await cms.getModel(_contentReview.CONTENT_REVIEW_MODEL_ID);
29
+ security.enableAuthorization();
25
30
 
26
31
  if (!model) {
27
- throw new _error.default("Could not find `apwContentReviewModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
32
+ throw new _error.default(`Could not find "${_contentReview.CONTENT_REVIEW_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
28
33
  }
29
34
 
30
35
  return model;
@@ -34,7 +39,9 @@ const createContentReviewStorageOperations = ({
34
39
  id
35
40
  }) => {
36
41
  const model = await getContentReviewModel();
42
+ security.disableAuthorization();
37
43
  const entry = await cms.getEntryById(model, id);
44
+ security.enableAuthorization();
38
45
  return (0, _index.getFieldValues)(entry, _index.baseFields);
39
46
  };
40
47
 
@@ -44,15 +51,19 @@ const createContentReviewStorageOperations = ({
44
51
 
45
52
  async listContentReviews(params) {
46
53
  const model = await getContentReviewModel();
54
+ security.disableAuthorization();
47
55
  const [entries, meta] = await cms.listLatestEntries(model, _objectSpread(_objectSpread({}, params), {}, {
48
56
  where: _objectSpread({}, params.where)
49
57
  }));
58
+ security.enableAuthorization();
50
59
  return [entries.map(entry => (0, _index.getFieldValues)(entry, _index.baseFields)), meta];
51
60
  },
52
61
 
53
62
  async createContentReview(params) {
54
63
  const model = await getContentReviewModel();
64
+ security.disableAuthorization();
55
65
  const entry = await cms.createEntry(model, params.data);
66
+ security.enableAuthorization();
56
67
  return (0, _index.getFieldValues)(entry, _index.baseFields);
57
68
  },
58
69
 
@@ -66,13 +77,17 @@ const createContentReviewStorageOperations = ({
66
77
  const existingEntry = await getContentReview({
67
78
  id: params.id
68
79
  });
80
+ security.disableAuthorization();
69
81
  const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
82
+ security.enableAuthorization();
70
83
  return (0, _index.getFieldValues)(entry, _index.baseFields);
71
84
  },
72
85
 
73
86
  async deleteContentReview(params) {
74
87
  const model = await getContentReviewModel();
88
+ security.disableAuthorization();
75
89
  await cms.deleteEntry(model, params.id);
90
+ security.enableAuthorization();
76
91
  return true;
77
92
  }
78
93
 
@@ -1 +1 @@
1
- {"version":3,"names":["createContentReviewStorageOperations","cms","getContentReviewModel","model","getModel","WebinyError","getContentReview","id","entry","getEntryById","getFieldValues","baseFields","listContentReviews","params","entries","meta","listLatestEntries","where","map","createContentReview","createEntry","data","updateContentReview","existingEntry","updateEntry","deleteContentReview","deleteEntry"],"sources":["contentReviewStorageOperations.ts"],"sourcesContent":["import { ApwContentReviewStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\n\nexport const createContentReviewStorageOperations = ({\n cms\n}: Pick<CreateApwStorageOperationsParams, \"cms\">): ApwContentReviewStorageOperations => {\n const getContentReviewModel = async () => {\n const model = await cms.getModel(\"apwContentReviewModelDefinition\");\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwContentReviewModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getContentReview: ApwContentReviewStorageOperations[\"getContentReview\"] = async ({\n id\n }) => {\n const model = await getContentReviewModel();\n const entry = await cms.getEntryById(model, id);\n return getFieldValues(entry, baseFields);\n };\n return {\n getContentReviewModel,\n getContentReview,\n async listContentReviews(params) {\n const model = await getContentReviewModel();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createContentReview(params) {\n const model = await getContentReviewModel();\n const entry = await cms.createEntry(model, params.data);\n return getFieldValues(entry, baseFields);\n },\n async updateContentReview(params) {\n const model = await getContentReviewModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getContentReview({ id: params.id });\n\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n return getFieldValues(entry, baseFields);\n },\n async deleteContentReview(params) {\n const model = await getContentReviewModel();\n await cms.deleteEntry(model, params.id);\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAKA;;;;;;AAEO,MAAMA,oCAAoC,GAAG,CAAC;EACjDC;AADiD,CAAD,KAEoC;EACpF,MAAMC,qBAAqB,GAAG,YAAY;IACtC,MAAMC,KAAK,GAAG,MAAMF,GAAG,CAACG,QAAJ,CAAa,iCAAb,CAApB;;IACA,IAAI,CAACD,KAAL,EAAY;MACR,MAAM,IAAIE,cA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M,CAACN;MAAb,CAAD,CAA5C;MAEA,MAAMC,KAAK,GAAG,MAAMP,GAAG,CAACuB,WAAJ,CAAgBrB,KAAhB,EAAuBU,MAAM,CAACN,EAA9B,kCACbgB,aADa,GAEbV,MAAM,CAACQ,IAFM,EAApB;MAIA,OAAO,IAAAX,qBAAA,EAAeF,KAAf,EAAsBG,iBAAtB,CAAP;IACH,CA/BE;;IAgCH,MAAMc,mBAAN,CAA0BZ,MAA1B,EAAkC;MAC9B,MAAMV,KAAK,GAAG,MAAMD,qBAAqB,EAAzC;MACA,MAAMD,GAAG,CAACyB,WAAJ,CAAgBvB,KAAhB,EAAuBU,MAAM,CAACN,EAA9B,CAAN;MACA,OAAO,IAAP;IACH;;EApCE,CAAP;AAsCH,CA1DM"}
1
+ {"version":3,"names":["createContentReviewStorageOperations","cms","security","getContentReviewModel","disableAuthorization","model","getModel","CONTENT_REVIEW_MODEL_ID","enableAuthorization","WebinyError","getContentReview","id","entry","getEntryById","getFieldValues","baseFields","listContentReviews","params","entries","meta","listLatestEntries","where","map","createContentReview","createEntry","data","updateContentReview","existingEntry","updateEntry","deleteContentReview","deleteEntry"],"sources":["contentReviewStorageOperations.ts"],"sourcesContent":["import { ApwContentReviewStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\nimport { CONTENT_REVIEW_MODEL_ID } from \"~/storageOperations/models/contentReview.model\";\n\nexport const createContentReviewStorageOperations = ({\n cms,\n security\n}: CreateApwStorageOperationsParams): ApwContentReviewStorageOperations => {\n const getContentReviewModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(CONTENT_REVIEW_MODEL_ID);\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n `Could not find \"${CONTENT_REVIEW_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getContentReview: ApwContentReviewStorageOperations[\"getContentReview\"] = async ({\n id\n }) => {\n const model = await getContentReviewModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n };\n return {\n getContentReviewModel,\n getContentReview,\n async listContentReviews(params) {\n const model = await getContentReviewModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n security.enableAuthorization();\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createContentReview(params) {\n const model = await getContentReviewModel();\n security.disableAuthorization();\n const entry = await cms.createEntry(model, params.data);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async updateContentReview(params) {\n const model = await getContentReviewModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getContentReview({ id: params.id });\n\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async deleteContentReview(params) {\n const model = await getContentReviewModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAKA;;AACA;;;;;;AAEO,MAAMA,oCAAoC,GAAG,CAAC;EACjDC,GADiD;EAEjDC;AAFiD,CAAD,KAGuB;EACvE,MAAMC,qBAAqB,GAAG,YAAY;IACtCD,QAAQ,CAACE,oBAAT;IACA,MAAMC,KAAK,GAAG,MAAMJ,GAAG,CAACK,QAAJ,CAAaC,sCAAb,CAApB;IACAL,QAAQ,CAACM,mBAAT;;IACA,IAAI,CAACH,KAAL,EAAY;MACR,MAAM,IAAII,cAAJ,CACD,mBAAkBF,sCAAwB,UADzC,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOF,KAAP;EACH,CAXD;;EAYA,MAAMK,gBAAuE,GAAG,OAAO;IACnFC;EAD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AAG,MAAMjB,gBAAgB,CAAC;QAAEC,EAAE,EAAEM,MAAM,CAACN;MAAb,CAAD,CAA5C;MAEAT,QAAQ,CAACE,oBAAT;MACA,MAAMQ,KAAK,GAAG,MAAMX,GAAG,CAAC2B,WAAJ,CAAgBvB,KAAhB,EAAuBY,MAAM,CAACN,EAA9B,kCACbgB,aADa,GAEbV,MAAM,CAACQ,IAFM,EAApB;MAIAvB,QAAQ,CAACM,mBAAT;MACA,OAAO,IAAAM,qBAAA,EAAeF,KAAf,EAAsBG,iBAAtB,CAAP;IACH,CArCE;;IAsCH,MAAMc,mBAAN,CAA0BZ,MAA1B,EAAkC;MAC9B,MAAMZ,KAAK,GAAG,MAAMF,qBAAqB,EAAzC;MACAD,QAAQ,CAACE,oBAAT;MACA,MAAMH,GAAG,CAAC6B,WAAJ,CAAgBzB,KAAhB,EAAuBY,MAAM,CAACN,EAA9B,CAAN;MACAT,QAAQ,CAACM,mBAAT;MACA,OAAO,IAAP;IACH;;EA5CE,CAAP;AA8CH,CAvEM"}
@@ -1,7 +1,9 @@
1
1
  import { CmsContext, CmsEntry, HeadlessCms } from "@webiny/api-headless-cms/types";
2
2
  import { ApwStorageOperations } from "../types";
3
+ import { Security } from "@webiny/api-security/types";
3
4
  export interface CreateApwStorageOperationsParams {
4
5
  cms: HeadlessCms;
6
+ security: Security;
5
7
  getCmsContext: () => CmsContext;
6
8
  }
7
9
  /**
@@ -10,4 +12,4 @@ export interface CreateApwStorageOperationsParams {
10
12
  */
11
13
  export declare function getFieldValues(entry: CmsEntry, fields: string[]): any;
12
14
  export declare const baseFields: string[];
13
- export declare const createStorageOperations: ({ cms, getCmsContext }: CreateApwStorageOperationsParams) => ApwStorageOperations;
15
+ export declare const createStorageOperations: (params: CreateApwStorageOperationsParams) => ApwStorageOperations;
@@ -39,29 +39,14 @@ function getFieldValues(entry, fields) {
39
39
  const baseFields = ["id", "createdBy", "createdOn", "savedOn"];
40
40
  exports.baseFields = baseFields;
41
41
 
42
- const createStorageOperations = ({
43
- cms,
44
- getCmsContext
45
- }) => {
46
- const context = getCmsContext();
42
+ const createStorageOperations = params => {
43
+ const context = params.getCmsContext();
47
44
  /**
48
45
  * Register Apw models.
49
46
  */
50
47
 
51
48
  (0, _models.createApwModels)(context);
52
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, (0, _reviewerStorageOperations.createReviewerStorageOperations)({
53
- cms
54
- })), (0, _workflowStorageOperations.createWorkflowStorageOperations)({
55
- cms
56
- })), (0, _contentReviewStorageOperations.createContentReviewStorageOperations)({
57
- cms
58
- })), (0, _changeRequestStorageOperations.createChangeRequestStorageOperations)({
59
- cms,
60
- getCmsContext
61
- })), (0, _commentStorageOperations.createCommentStorageOperations)({
62
- cms,
63
- getCmsContext
64
- }));
49
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, (0, _reviewerStorageOperations.createReviewerStorageOperations)(params)), (0, _workflowStorageOperations.createWorkflowStorageOperations)(params)), (0, _contentReviewStorageOperations.createContentReviewStorageOperations)(params)), (0, _changeRequestStorageOperations.createChangeRequestStorageOperations)(params)), (0, _commentStorageOperations.createCommentStorageOperations)(params));
65
50
  };
66
51
 
67
52
  exports.createStorageOperations = createStorageOperations;
@@ -1 +1 @@
1
- {"version":3,"names":["getFieldValues","entry","fields","pick","values","baseFields","createStorageOperations","cms","getCmsContext","context","createApwModels","createReviewerStorageOperations","createWorkflowStorageOperations","createContentReviewStorageOperations","createChangeRequestStorageOperations","createCommentStorageOperations"],"sources":["index.ts"],"sourcesContent":["import pick from \"lodash/pick\";\nimport { CmsContext, CmsEntry, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { ApwStorageOperations } from \"~/types\";\nimport { createReviewerStorageOperations } from \"./reviewerStorageOperations\";\nimport { createWorkflowStorageOperations } from \"./workflowStorageOperations\";\nimport { createContentReviewStorageOperations } from \"./contentReviewStorageOperations\";\nimport { createChangeRequestStorageOperations } from \"./changeRequestStorageOperations\";\nimport { createCommentStorageOperations } from \"~/storageOperations/commentStorageOperations\";\nimport { createApwModels } from \"./models\";\n\nexport interface CreateApwStorageOperationsParams {\n cms: HeadlessCms;\n getCmsContext: () => CmsContext;\n}\n\n/**\n * Using any because value can be a lot of types.\n * TODO @ts-refactor figure out correct types.\n */\nexport function getFieldValues(entry: CmsEntry, fields: string[]): any {\n return { ...pick(entry, fields), ...entry.values };\n}\n\nexport const baseFields = [\"id\", \"createdBy\", \"createdOn\", \"savedOn\"];\n\nexport const createStorageOperations = ({\n cms,\n getCmsContext\n}: CreateApwStorageOperationsParams): ApwStorageOperations => {\n const context = getCmsContext();\n /**\n * Register Apw models.\n */\n createApwModels(context);\n\n return {\n ...createReviewerStorageOperations({ cms }),\n ...createWorkflowStorageOperations({ cms }),\n ...createContentReviewStorageOperations({ cms }),\n ...createChangeRequestStorageOperations({ cms, getCmsContext }),\n ...createCommentStorageOperations({\n cms,\n getCmsContext\n })\n };\n};\n"],"mappings":";;;;;;;;;;;;AAAA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAOA;AACA;AACA;AACA;AACO,SAASA,cAAT,CAAwBC,KAAxB,EAAyCC,MAAzC,EAAgE;EACnE,uCAAY,IAAAC,aAAA,EAAKF,KAAL,EAAYC,MAAZ,CAAZ,GAAoCD,KAAK,CAACG,MAA1C;AACH;;AAEM,MAAMC,UAAU,GAAG,CAAC,IAAD,EAAO,WAAP,EAAoB,WAApB,EAAiC,SAAjC,CAAnB;;;AAEA,MAAMC,uBAAuB,GAAG,CAAC;EACpCC,GADoC;EAEpCC;AAFoC,CAAD,KAGuB;EAC1D,MAAMC,OAAO,GAAGD,aAAa,EAA7B;EACA;AACJ;AACA;;EACI,IAAAE,uBAAA,EAAgBD,OAAhB;EAEA,iFACO,IAAAE,0DAAA,EAAgC;IAAEJ;EAAF,CAAhC,CADP,GAEO,IAAAK,0DAAA,EAAgC;IAAEL;EAAF,CAAhC,CAFP,GAGO,IAAAM,oEAAA,EAAqC;IAAEN;EAAF,CAArC,CAHP,GAIO,IAAAO,oEAAA,EAAqC;IAAEP,GAAF;IAAOC;EAAP,CAArC,CAJP,GAKO,IAAAO,wDAAA,EAA+B;IAC9BR,GAD8B;IAE9BC;EAF8B,CAA/B,CALP;AAUH,CApBM"}
1
+ {"version":3,"names":["getFieldValues","entry","fields","pick","values","baseFields","createStorageOperations","params","context","getCmsContext","createApwModels","createReviewerStorageOperations","createWorkflowStorageOperations","createContentReviewStorageOperations","createChangeRequestStorageOperations","createCommentStorageOperations"],"sources":["index.ts"],"sourcesContent":["import pick from \"lodash/pick\";\nimport { CmsContext, CmsEntry, HeadlessCms } from \"@webiny/api-headless-cms/types\";\nimport { ApwStorageOperations } from \"~/types\";\nimport { createReviewerStorageOperations } from \"./reviewerStorageOperations\";\nimport { createWorkflowStorageOperations } from \"./workflowStorageOperations\";\nimport { createContentReviewStorageOperations } from \"./contentReviewStorageOperations\";\nimport { createChangeRequestStorageOperations } from \"./changeRequestStorageOperations\";\nimport { createCommentStorageOperations } from \"~/storageOperations/commentStorageOperations\";\nimport { createApwModels } from \"./models\";\nimport { Security } from \"@webiny/api-security/types\";\n\nexport interface CreateApwStorageOperationsParams {\n cms: HeadlessCms;\n security: Security;\n getCmsContext: () => CmsContext;\n}\n\n/**\n * Using any because value can be a lot of types.\n * TODO @ts-refactor figure out correct types.\n */\nexport function getFieldValues(entry: CmsEntry, fields: string[]): any {\n return { ...pick(entry, fields), ...entry.values };\n}\n\nexport const baseFields = [\"id\", \"createdBy\", \"createdOn\", \"savedOn\"];\n\nexport const createStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwStorageOperations => {\n const context = params.getCmsContext();\n /**\n * Register Apw models.\n */\n createApwModels(context);\n\n return {\n ...createReviewerStorageOperations(params),\n ...createWorkflowStorageOperations(params),\n ...createContentReviewStorageOperations(params),\n ...createChangeRequestStorageOperations(params),\n ...createCommentStorageOperations(params)\n };\n};\n"],"mappings":";;;;;;;;;;;;AAAA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AASA;AACA;AACA;AACA;AACO,SAASA,cAAT,CAAwBC,KAAxB,EAAyCC,MAAzC,EAAgE;EACnE,uCAAY,IAAAC,aAAA,EAAKF,KAAL,EAAYC,MAAZ,CAAZ,GAAoCD,KAAK,CAACG,MAA1C;AACH;;AAEM,MAAMC,UAAU,GAAG,CAAC,IAAD,EAAO,WAAP,EAAoB,WAApB,EAAiC,SAAjC,CAAnB;;;AAEA,MAAMC,uBAAuB,GAChCC,MADmC,IAEZ;EACvB,MAAMC,OAAO,GAAGD,MAAM,CAACE,aAAP,EAAhB;EACA;AACJ;AACA;;EACI,IAAAC,uBAAA,EAAgBF,OAAhB;EAEA,iFACO,IAAAG,0DAAA,EAAgCJ,MAAhC,CADP,GAEO,IAAAK,0DAAA,EAAgCL,MAAhC,CAFP,GAGO,IAAAM,oEAAA,EAAqCN,MAArC,CAHP,GAIO,IAAAO,oEAAA,EAAqCP,MAArC,CAJP,GAKO,IAAAQ,wDAAA,EAA+BR,MAA/B,CALP;AAOH,CAhBM"}
@@ -1,9 +1,7 @@
1
- import { CmsGroup } from "@webiny/api-headless-cms";
2
1
  import { CmsModelPlugin } from "@webiny/api-headless-cms";
3
- import { CmsModel } from "@webiny/api-headless-cms/types";
4
- declare type ModelDefinition = Omit<CmsModel, "locale" | "tenant" | "webinyVersion" | "group">;
2
+ import { CmsModel, CmsGroup } from "@webiny/api-headless-cms/types";
5
3
  interface Params {
6
- group: CmsGroup;
4
+ group: Pick<CmsGroup, "id" | "name">;
7
5
  /**
8
6
  * Locale and tenant do not need to be defined.
9
7
  * In that case model is not bound to any locale or tenant.
@@ -11,7 +9,7 @@ interface Params {
11
9
  */
12
10
  locale?: string;
13
11
  tenant?: string;
14
- modelDefinition: ModelDefinition;
12
+ modelDefinition: Omit<CmsModel, "locale" | "tenant" | "webinyVersion" | "group">;
15
13
  }
16
- declare const contentModelPluginFactory: (params: Params) => CmsModelPlugin;
17
- export default contentModelPluginFactory;
14
+ export declare const contentModelPluginFactory: (params: Params) => CmsModelPlugin;
15
+ export {};
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = void 0;
8
+ exports.contentModelPluginFactory = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
 
@@ -22,12 +22,11 @@ const contentModelPluginFactory = params => {
22
22
  tenant,
23
23
  modelDefinition
24
24
  } = params;
25
- return new _apiHeadlessCms.CmsModelPlugin(_objectSpread({
25
+ return (0, _apiHeadlessCms.createCmsModel)(_objectSpread({
26
26
  group,
27
27
  locale,
28
28
  tenant
29
29
  }, modelDefinition));
30
30
  };
31
31
 
32
- var _default = contentModelPluginFactory;
33
- exports.default = _default;
32
+ exports.contentModelPluginFactory = contentModelPluginFactory;
@@ -1 +1 @@
1
- {"version":3,"names":["contentModelPluginFactory","params","group","locale","tenant","modelDefinition","CmsModelPlugin"],"sources":["contentModelPluginFactory.ts"],"sourcesContent":["import { CmsGroup } from \"@webiny/api-headless-cms\";\nimport { CmsModelPlugin } from \"@webiny/api-headless-cms\";\nimport { CmsModel } from \"@webiny/api-headless-cms/types\";\n\ntype ModelDefinition = Omit<CmsModel, \"locale\" | \"tenant\" | \"webinyVersion\" | \"group\">;\n\ninterface Params {\n group: CmsGroup;\n /**\n * Locale and tenant do not need to be defined.\n * In that case model is not bound to any locale or tenant.\n * You can bind it to locale, tenant, both or none.\n */\n locale?: string;\n tenant?: string;\n modelDefinition: ModelDefinition;\n}\n\nconst contentModelPluginFactory = (params: Params): CmsModelPlugin => {\n const { group, locale, tenant, modelDefinition } = params;\n\n return new CmsModelPlugin({\n group,\n locale,\n tenant,\n ...modelDefinition\n });\n};\n\nexport default contentModelPluginFactory;\n"],"mappings":";;;;;;;;;;;AACA;;;;;;AAiBA,MAAMA,yBAAyB,GAAIC,MAAD,IAAoC;EAClE,MAAM;IAAEC,KAAF;IAASC,MAAT;IAAiBC,MAAjB;IAAyBC;EAAzB,IAA6CJ,MAAnD;EAEA,OAAO,IAAIK,8BAAJ;IACHJ,KADG;IAEHC,MAFG;IAGHC;EAHG,GAIAC,eAJA,EAAP;AAMH,CATD;;eAWeL,yB"}
1
+ {"version":3,"names":["contentModelPluginFactory","params","group","locale","tenant","modelDefinition","createCmsModel"],"sources":["contentModelPluginFactory.ts"],"sourcesContent":["import { CmsModelPlugin, createCmsModel } from \"@webiny/api-headless-cms\";\nimport { CmsModel, CmsGroup } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n group: Pick<CmsGroup, \"id\" | \"name\">;\n /**\n * Locale and tenant do not need to be defined.\n * In that case model is not bound to any locale or tenant.\n * You can bind it to locale, tenant, both or none.\n */\n locale?: string;\n tenant?: string;\n modelDefinition: Omit<CmsModel, \"locale\" | \"tenant\" | \"webinyVersion\" | \"group\">;\n}\n\nexport const contentModelPluginFactory = (params: Params): CmsModelPlugin => {\n const { group, locale, tenant, modelDefinition } = params;\n\n return createCmsModel({\n group,\n locale,\n tenant,\n ...modelDefinition\n });\n};\n"],"mappings":";;;;;;;;;;;AAAA;;;;;;AAeO,MAAMA,yBAAyB,GAAIC,MAAD,IAAoC;EACzE,MAAM;IAAEC,KAAF;IAASC,MAAT;IAAiBC,MAAjB;IAAyBC;EAAzB,IAA6CJ,MAAnD;EAEA,OAAO,IAAAK,8BAAA;IACHJ,KADG;IAEHC,MAFG;IAGHC;EAHG,GAIAC,eAJA,EAAP;AAMH,CATM"}
@@ -7,12 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.createApwModels = void 0;
9
9
 
10
- var _contentModelPluginFactory = _interopRequireDefault(require("./contentModelPluginFactory"));
11
-
12
10
  var _error = _interopRequireDefault(require("@webiny/error"));
13
11
 
14
12
  var _apiHeadlessCms = require("@webiny/api-headless-cms");
15
13
 
14
+ var _contentModelPluginFactory = require("./contentModelPluginFactory");
15
+
16
16
  var _workflow = require("./workflow.model");
17
17
 
18
18
  var _contentReview = require("./contentReview.model");
@@ -86,7 +86,7 @@ const createApwModels = context => {
86
86
  const cmsModelPlugins = [];
87
87
 
88
88
  for (const modelDefinition of modelDefinitions) {
89
- const cmsModelPlugin = (0, _contentModelPluginFactory.default)({
89
+ const cmsModelPlugin = (0, _contentModelPluginFactory.contentModelPluginFactory)({
90
90
  group: cmsGroupPlugin.contentModelGroup,
91
91
  tenant: context.tenancy.getCurrentTenant().id,
92
92
  locale: locale.code,
@@ -1 +1 @@
1
- {"version":3,"names":["createApwModels","context","cms","console","warn","isInstallationPending","tenancy","i18n","security","disableAuthorization","locale","getContentLocale","WebinyError","groupId","cmsGroupPlugin","CmsGroupPlugin","id","slug","name","description","icon","isPrivate","changeRequestModelDefinition","createChangeRequestModelDefinition","reviewerModelDefinition","createReviewerModelDefinition","workflowModelDefinition","createWorkflowModelDefinition","reviewerModelId","modelId","commentModelDefinition","createCommentModelDefinition","contentReviewModelDefinition","createContentReviewModelDefinition","modelDefinitions","cmsModelPlugins","modelDefinition","cmsModelPlugin","contentModelPluginFactory","group","contentModelGroup","tenant","getCurrentTenant","code","contentModel","titleFieldId","push","plugins","register","enableAuthorization"],"sources":["index.ts"],"sourcesContent":["import contentModelPluginFactory from \"./contentModelPluginFactory\";\nimport WebinyError from \"@webiny/error\";\nimport { CmsGroupPlugin } from \"@webiny/api-headless-cms\";\nimport { createWorkflowModelDefinition } from \"./workflow.model\";\nimport { createContentReviewModelDefinition } from \"./contentReview.model\";\nimport { createReviewerModelDefinition } from \"./reviewer.model\";\nimport { createCommentModelDefinition } from \"./comment.model\";\nimport { createChangeRequestModelDefinition } from \"./changeRequest.model\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { isInstallationPending } from \"~/plugins/utils\";\n\nexport const createApwModels = (context: CmsContext) => {\n /**\n * This should never happen in the actual project.\n * It is to make sure that we load setup context before the CRUD init in our internal code.\n */\n if (!context.cms) {\n console.warn(\"Creating model before cms init.\");\n return;\n }\n\n if (isInstallationPending({ tenancy: context.tenancy, i18n: context.i18n })) {\n return;\n }\n\n context.security.disableAuthorization();\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/storageOperations/index.ts\",\n \"LOCALE_ERROR\"\n );\n }\n /**\n * TODO:@ashutosh\n * We need to move these plugin in an installation plugin\n */\n const groupId = \"contentModelGroup_apw\";\n /**\n * Create a CmsGroup.\n */\n const cmsGroupPlugin = new CmsGroupPlugin({\n id: groupId,\n slug: \"apw\",\n name: \"APW\",\n description: \"Group for Advanced Publishing Workflow\",\n icon: \"fas/star\",\n isPrivate: true\n });\n\n /**\n * Create CmsModel plugins.\n */\n const changeRequestModelDefinition = createChangeRequestModelDefinition();\n const reviewerModelDefinition = createReviewerModelDefinition();\n const workflowModelDefinition = createWorkflowModelDefinition({\n reviewerModelId: reviewerModelDefinition.modelId\n });\n const commentModelDefinition = createCommentModelDefinition({\n modelId: changeRequestModelDefinition.modelId\n });\n const contentReviewModelDefinition = createContentReviewModelDefinition({\n reviewerModelId: reviewerModelDefinition.modelId\n });\n\n const modelDefinitions = [\n workflowModelDefinition,\n contentReviewModelDefinition,\n reviewerModelDefinition,\n changeRequestModelDefinition,\n commentModelDefinition\n ];\n\n const cmsModelPlugins = [];\n for (const modelDefinition of modelDefinitions) {\n const cmsModelPlugin = contentModelPluginFactory({\n group: cmsGroupPlugin.contentModelGroup,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: locale.code,\n modelDefinition\n });\n /**\n * We want \"title\" field as the \"titleField\" for \"ContentReview\" model.\n * so that we can later search entries by title.\n */\n if (cmsModelPlugin.contentModel.modelId === \"apwContentReviewModelDefinition\") {\n cmsModelPlugin.contentModel.titleFieldId = \"title\";\n }\n cmsModelPlugins.push(cmsModelPlugin);\n }\n\n /**\n * Register them so that they are accessible in cms context\n */\n context.plugins.register([cmsGroupPlugin, cmsModelPlugins]);\n\n context.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AAG,IAAAC,iDAAA,EAAmC;IACpEL,eAAe,EAAEJ,uBAAuB,CAACK;EAD2B,CAAnC,CAArC;EAIA,MAAMK,gBAAgB,GAAG,CACrBR,uBADqB,EAErBM,4BAFqB,EAGrBR,uBAHqB,EAIrBF,4BAJqB,EAKrBQ,sBALqB,CAAzB;EAQA,MAAMK,eAAe,GAAG,EAAxB;;EACA,KAAK,MAAMC,eAAX,IAA8BF,gBAA9B,EAAgD;IAC5C,MAAMG,cAAc,GAAG,IAAAC,kCAAA,EAA0B;MAC7CC,KAAK,EAAEzB,cAAc,CAAC0B,iBADuB;MAE7CC,MAAM,EAAExC,OAAO,CAACK,OAAR,CAAgBoC,gBAAhB,GAAmC1B,EAFE;MAG7CN,MAAM,EAAEA,MAAM,CAACiC,IAH8B;MAI7CP;IAJ6C,CAA1B,CAAvB;IAMA;AACR;AACA;AACA;;IACQ,IAAIC,cAAc,CAACO,YAAf,CAA4Bf,OAA5B,KAAwC,iCAA5C,EAA+E;MAC3EQ,cAAc,CAACO,YAAf,CAA4BC,YAA5B,GAA2C,OAA3C;IACH;;IACDV,eAAe,CAACW,IAAhB,CAAqBT,cAArB;EACH;EAED;AACJ;AACA;;;EACIpC,OAAO,CAAC8C,OAAR,CAAgBC,QAAhB,CAAyB,CAAClC,cAAD,EAAiBqB,eAAjB,CAAzB;EAEAlC,OAAO,CAACO,QAAR,CAAiByC,mBAAjB;AACH,CAvFM"}
1
+ {"version":3,"names":["createApwModels","context","cms","console","warn","isInstallationPending","tenancy","i18n","security","disableAuthorization","locale","getContentLocale","WebinyError","groupId","cmsGroupPlugin","CmsGroupPlugin","id","slug","name","description","icon","isPrivate","changeRequestModelDefinition","createChangeRequestModelDefinition","reviewerModelDefinition","createReviewerModelDefinition","workflowModelDefinition","createWorkflowModelDefinition","reviewerModelId","modelId","commentModelDefinition","createCommentModelDefinition","contentReviewModelDefinition","createContentReviewModelDefinition","modelDefinitions","cmsModelPlugins","modelDefinition","cmsModelPlugin","contentModelPluginFactory","group","contentModelGroup","tenant","getCurrentTenant","code","contentModel","titleFieldId","push","plugins","register","enableAuthorization"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsGroupPlugin } from \"@webiny/api-headless-cms\";\nimport { contentModelPluginFactory } from \"./contentModelPluginFactory\";\nimport { createWorkflowModelDefinition } from \"./workflow.model\";\nimport { createContentReviewModelDefinition } from \"./contentReview.model\";\nimport { createReviewerModelDefinition } from \"./reviewer.model\";\nimport { createCommentModelDefinition } from \"./comment.model\";\nimport { createChangeRequestModelDefinition } from \"./changeRequest.model\";\nimport { CmsContext } from \"@webiny/api-headless-cms/types\";\nimport { isInstallationPending } from \"~/plugins/utils\";\n\nexport const createApwModels = (context: CmsContext) => {\n /**\n * This should never happen in the actual project.\n * It is to make sure that we load setup context before the CRUD init in our internal code.\n */\n if (!context.cms) {\n console.warn(\"Creating model before cms init.\");\n return;\n }\n\n if (isInstallationPending({ tenancy: context.tenancy, i18n: context.i18n })) {\n return;\n }\n\n context.security.disableAuthorization();\n\n const locale = context.i18n.getContentLocale();\n if (!locale) {\n throw new WebinyError(\n \"Missing content locale in api-apw/storageOperations/index.ts\",\n \"LOCALE_ERROR\"\n );\n }\n /**\n * TODO:@ashutosh\n * We need to move these plugin in an installation plugin\n */\n const groupId = \"contentModelGroup_apw\";\n /**\n * Create a CmsGroup.\n */\n const cmsGroupPlugin = new CmsGroupPlugin({\n id: groupId,\n slug: \"apw\",\n name: \"APW\",\n description: \"Group for Advanced Publishing Workflow\",\n icon: \"fas/star\",\n isPrivate: true\n });\n\n /**\n * Create CmsModel plugins.\n */\n const changeRequestModelDefinition = createChangeRequestModelDefinition();\n const reviewerModelDefinition = createReviewerModelDefinition();\n const workflowModelDefinition = createWorkflowModelDefinition({\n reviewerModelId: reviewerModelDefinition.modelId\n });\n const commentModelDefinition = createCommentModelDefinition({\n modelId: changeRequestModelDefinition.modelId\n });\n const contentReviewModelDefinition = createContentReviewModelDefinition({\n reviewerModelId: reviewerModelDefinition.modelId\n });\n\n const modelDefinitions = [\n workflowModelDefinition,\n contentReviewModelDefinition,\n reviewerModelDefinition,\n changeRequestModelDefinition,\n commentModelDefinition\n ];\n\n const cmsModelPlugins = [];\n for (const modelDefinition of modelDefinitions) {\n const cmsModelPlugin = contentModelPluginFactory({\n group: cmsGroupPlugin.contentModelGroup,\n tenant: context.tenancy.getCurrentTenant().id,\n locale: locale.code,\n modelDefinition\n });\n /**\n * We want \"title\" field as the \"titleField\" for \"ContentReview\" model.\n * so that we can later search entries by title.\n */\n if (cmsModelPlugin.contentModel.modelId === \"apwContentReviewModelDefinition\") {\n cmsModelPlugin.contentModel.titleFieldId = \"title\";\n }\n cmsModelPlugins.push(cmsModelPlugin);\n }\n\n /**\n * Register them so that they are accessible in cms context\n */\n context.plugins.register([cmsGroupPlugin, cmsModelPlugins]);\n\n context.security.enableAuthorization();\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEO,MAAMA,eAAe,GAAIC,OAAD,IAAyB;EACpD;AACJ;AACA;AACA;EACI,IAAI,CAACA,OAAO,CAACC,GAAb,EAAkB;IACdC,OAAO,CAACC,IAAR,CAAa,iCAAb;IACA;EACH;;EAED,IAAI,IAAAC,4BAAA,EAAsB;IAAEC,OAAO,EAAEL,OAAO,CAACK,OAAnB;IAA4BC,IAAI,EAAEN,OAAO,CAACM;EAA1C,CAAtB,CAAJ,EAA6E;IACzE;EACH;;EAEDN,OAAO,CAACO,QAAR,CAAiBC,oBAAjB;EAEA,MAAMC,MAAM,GAAGT,OAAO,CAACM,IAAR,CAAaI,gBAAb,EAAf;;EACA,IAAI,CAACD,MAAL,EAAa;IACT,MAAM,IAAIE,cAAJ,CACF,8DADE,EAEF,cAFE,CAAN;EAIH;EACD;AACJ;AACA;AACA;;;EACI,MAAMC,OAAO,GAAG,uBAAhB;EACA;AACJ;AACA;;EACI,MAAMC,cAAc,GAAG,IAAIC,8BAA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hB,CAAqBT,cAArB;EACH;EAED;AACJ;AACA;;;EACIpC,OAAO,CAAC8C,OAAR,CAAgBC,QAAhB,CAAyB,CAAClC,cAAD,EAAiBqB,eAAjB,CAAzB;EAEAlC,OAAO,CAACO,QAAR,CAAiByC,mBAAjB;AACH,CAvFM"}
@@ -1,3 +1,3 @@
1
1
  import { ApwReviewerStorageOperations } from "./types";
2
2
  import { CreateApwStorageOperationsParams } from "./index";
3
- export declare const createReviewerStorageOperations: ({ cms }: Pick<CreateApwStorageOperationsParams, "cms">) => ApwReviewerStorageOperations;
3
+ export declare const createReviewerStorageOperations: ({ cms, security }: CreateApwStorageOperationsParams) => ApwReviewerStorageOperations;
@@ -18,7 +18,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
18
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
19
 
20
20
  const createReviewerStorageOperations = ({
21
- cms
21
+ cms,
22
+ security
22
23
  }) => {
23
24
  const getReviewerModel = async () => {
24
25
  const model = await cms.getModel("apwReviewerModelDefinition");
@@ -34,7 +35,9 @@ const createReviewerStorageOperations = ({
34
35
  id
35
36
  }) => {
36
37
  const model = await getReviewerModel();
38
+ security.disableAuthorization();
37
39
  const entry = await cms.getEntryById(model, id);
40
+ security.enableAuthorization();
38
41
  return (0, _index.getFieldValues)(entry, _index.baseFields);
39
42
  };
40
43
 
@@ -44,15 +47,19 @@ const createReviewerStorageOperations = ({
44
47
 
45
48
  async listReviewers(params) {
46
49
  const model = await getReviewerModel();
50
+ security.disableAuthorization();
47
51
  const [entries, meta] = await cms.listLatestEntries(model, _objectSpread(_objectSpread({}, params), {}, {
48
52
  where: _objectSpread({}, params.where)
49
53
  }));
54
+ security.enableAuthorization();
50
55
  return [entries.map(entry => (0, _index.getFieldValues)(entry, _index.baseFields)), meta];
51
56
  },
52
57
 
53
58
  async createReviewer(params) {
54
59
  const model = await getReviewerModel();
60
+ security.disableAuthorization();
55
61
  const entry = await cms.createEntry(model, params.data);
62
+ security.enableAuthorization();
56
63
  return (0, _index.getFieldValues)(entry, _index.baseFields);
57
64
  },
58
65
 
@@ -66,13 +73,17 @@ const createReviewerStorageOperations = ({
66
73
  const existingEntry = await getReviewer({
67
74
  id: params.id
68
75
  });
76
+ security.disableAuthorization();
69
77
  const entry = await cms.updateEntry(model, params.id, _objectSpread(_objectSpread({}, existingEntry), params.data));
78
+ security.enableAuthorization();
70
79
  return (0, _index.getFieldValues)(entry, _index.baseFields);
71
80
  },
72
81
 
73
82
  async deleteReviewer(params) {
74
83
  const model = await getReviewerModel();
84
+ security.disableAuthorization();
75
85
  await cms.deleteEntry(model, params.id);
86
+ security.enableAuthorization();
76
87
  return true;
77
88
  }
78
89
 
@@ -1 +1 @@
1
- {"version":3,"names":["createReviewerStorageOperations","cms","getReviewerModel","model","getModel","WebinyError","getReviewer","id","entry","getEntryById","getFieldValues","baseFields","listReviewers","params","entries","meta","listLatestEntries","where","map","createReviewer","createEntry","data","updateReviewer","existingEntry","updateEntry","deleteReviewer","deleteEntry"],"sources":["reviewerStorageOperations.ts"],"sourcesContent":["import { ApwReviewerStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\n\nexport const createReviewerStorageOperations = ({\n cms\n}: Pick<CreateApwStorageOperationsParams, \"cms\">): ApwReviewerStorageOperations => {\n const getReviewerModel = async () => {\n const model = await cms.getModel(\"apwReviewerModelDefinition\");\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwReviewerModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getReviewer: ApwReviewerStorageOperations[\"getReviewer\"] = async ({ id }) => {\n const model = await getReviewerModel();\n const entry = await cms.getEntryById(model, id);\n return getFieldValues(entry, baseFields);\n };\n return {\n getReviewerModel,\n getReviewer,\n async listReviewers(params) {\n const model = await getReviewerModel();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createReviewer(params) {\n const model = await getReviewerModel();\n const entry = await cms.createEntry(model, params.data);\n return getFieldValues(entry, baseFields);\n },\n async updateReviewer(params) {\n const model = await getReviewerModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getReviewer({ id: params.id });\n\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n return getFieldValues(entry, baseFields);\n },\n async deleteReviewer(params) {\n const model = await getReviewerModel();\n await cms.deleteEntry(model, params.id);\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAKA;;;;;;AAEO,MAAMA,+BAA+B,GAAG,CAAC;EAC5CC;AAD4C,CAAD,KAEoC;EAC/E,MAAMC,gBAAgB,GAAG,YAAY;IACjC,MAAMC,KAAK,GAAG,MAAMF,GAAG,CAACG,QAAJ,CAAa,4BAAb,CAApB;;IACA,IAAI,CAACD,KAAL,EAAY;MACR,MAAM,IAAIE,cAAJ,CACF,oDADE,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOF,KAAP;EACH,CATD;;EAUA,MAAMG,WAAwD,GAAG,OAAO;IAAEC;EAAF,CAAP,KAAkB;IAC/E,MAAMJ,KAAK,GAAG,MAAMD,gBAAgB,EAApC;IACA,MAAMM,KAAK,GAAG,MAAMP,GAAG,CAACQ,YAAJ,CAAiBN,KAAjB,EAAwBI,EAAxB,CAApB;IACA,OAAO,IAAAG,qBAAA,EAAeF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AAMD,gBAAgB,EAApC;MACA,MAAMD,GAAG,CAACyB,WAAJ,CAAgBvB,KAAhB,EAAuBU,MAAM,CAACN,EAA9B,CAAN;MACA,OAAO,IAAP;IACH;;EApCE,CAAP;AAsCH,CAxDM"}
1
+ {"version":3,"names":["createReviewerStorageOperations","cms","security","getReviewerModel","model","getModel","WebinyError","getReviewer","id","disableAuthorization","entry","getEntryById","enableAuthorization","getFieldValues","baseFields","listReviewers","params","entries","meta","listLatestEntries","where","map","createReviewer","createEntry","data","updateReviewer","existingEntry","updateEntry","deleteReviewer","deleteEntry"],"sources":["reviewerStorageOperations.ts"],"sourcesContent":["import { ApwReviewerStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\n\nexport const createReviewerStorageOperations = ({\n cms,\n security\n}: CreateApwStorageOperationsParams): ApwReviewerStorageOperations => {\n const getReviewerModel = async () => {\n const model = await cms.getModel(\"apwReviewerModelDefinition\");\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwReviewerModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getReviewer: ApwReviewerStorageOperations[\"getReviewer\"] = async ({ id }) => {\n const model = await getReviewerModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n };\n return {\n getReviewerModel,\n getReviewer,\n async listReviewers(params) {\n const model = await getReviewerModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n security.enableAuthorization();\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createReviewer(params) {\n const model = await getReviewerModel();\n security.disableAuthorization();\n const entry = await cms.createEntry(model, params.data);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async updateReviewer(params) {\n const model = await getReviewerModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getReviewer({ id: params.id });\n\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async deleteReviewer(params) {\n const model = await getReviewerModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAKA;;;;;;AAEO,MAAMA,+BAA+B,GAAG,CAAC;EAC5CC,GAD4C;EAE5CC;AAF4C,CAAD,KAGuB;EAClE,MAAMC,gBAAgB,GAAG,YAAY;IACjC,MAAMC,KAAK,GAAG,MAAMH,GAAG,CAACI,QAAJ,CAAa,4BAAb,CAApB;;IACA,IAAI,CAACD,KAAL,EAAY;MACR,MAAM,IAAIE,cAAJ,CACF,oDADE,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOF,KAAP;EACH,CATD;;EAUA,MAAMG,WAAwD,GAAG,OAAO;IAAEC;EAAF,CAAP,KAAkB;IAC/E,MAAMJ,KAAK,GAAG,MAAMD,gBAAgB,EAApC;IACAD,QAAQ,CAACO,oBAAT;IACA,MAAMC,KAAK,GAAG,MAAMT,GAAG,CAACU,YAAJ,CAAiBP,KAAjB,EAAwBI,EAAxB,CAApB;IACAN,QAAQ,CAACU,mBAAT;IACA,OAAO,IAAAC,qBAAA,EAAeH,KAAf,EAAsBI,iBAAtB,CAAP;EACH,CAND;;EAOA,OAAO;IACHX,gBADG;IAEHI,WAFG;;IAGH,MAAMQ,aAAN,CAAoBC,MAApB,EAA4B;MACxB,MAAMZ,KAAK,GAAG,MAAMD,gBAAgB,EAApC;MACAD,QAAQ,CAACO,oBAAT;MACA,MAAM,CAACQ,OAAD,EAAUC,IAAV,IAAkB,MAAMjB,GAAG,CAACkB,iBAAJ,CAAsBf,KAAtB,kCACvBY,MADuB;QAE1BI,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AAQ,CAACU,mBAAT;MACA,OAAO,IAAP;IACH;;EA5CE,CAAP;AA8CH,CAnEM"}
@@ -1,3 +1,3 @@
1
1
  import { ApwWorkflowStorageOperations } from "./types";
2
2
  import { CreateApwStorageOperationsParams } from "./index";
3
- export declare const createWorkflowStorageOperations: ({ cms }: Pick<CreateApwStorageOperationsParams, "cms">) => ApwWorkflowStorageOperations;
3
+ export declare const createWorkflowStorageOperations: (params: CreateApwStorageOperationsParams) => ApwWorkflowStorageOperations;
@@ -13,6 +13,8 @@ var _index = require("./index");
13
13
 
14
14
  var _error = _interopRequireDefault(require("@webiny/error"));
15
15
 
16
+ var _workflow = require("./models/workflow.model");
17
+
16
18
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
19
 
18
20
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -28,14 +30,19 @@ const formatReviewersForRefInput = (data, modelId) => {
28
30
  });
29
31
  };
30
32
 
31
- const createWorkflowStorageOperations = ({
32
- cms
33
- }) => {
33
+ const createWorkflowStorageOperations = params => {
34
+ const {
35
+ cms,
36
+ security
37
+ } = params;
38
+
34
39
  const getWorkflowModel = async () => {
35
- const model = await cms.getModel("apwWorkflowModelDefinition");
40
+ security.disableAuthorization();
41
+ const model = await cms.getModel(_workflow.WORKFLOW_MODEL_ID);
42
+ security.enableAuthorization();
36
43
 
37
44
  if (!model) {
38
- throw new _error.default("Could not find `apwWorkflowModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
45
+ throw new _error.default(`Could not find "${_workflow.WORKFLOW_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
39
46
  }
40
47
 
41
48
  return model;
@@ -45,7 +52,9 @@ const createWorkflowStorageOperations = ({
45
52
  id
46
53
  }) => {
47
54
  const model = await getWorkflowModel();
55
+ security.disableAuthorization();
48
56
  const entry = await cms.getEntryById(model, id);
57
+ security.enableAuthorization();
49
58
  return (0, _index.getFieldValues)(entry, _index.baseFields);
50
59
  };
51
60
 
@@ -55,7 +64,9 @@ const createWorkflowStorageOperations = ({
55
64
 
56
65
  async listWorkflows(params) {
57
66
  const model = await getWorkflowModel();
67
+ security.disableAuthorization();
58
68
  const [entries, meta] = await cms.listLatestEntries(model, _objectSpread({}, params));
69
+ security.enableAuthorization();
59
70
  return [entries.map(entry => (0, _index.getFieldValues)(entry, _index.baseFields)), meta];
60
71
  },
61
72
 
@@ -63,7 +74,9 @@ const createWorkflowStorageOperations = ({
63
74
  const model = await getWorkflowModel();
64
75
  const reviewerModel = await this.getReviewerModel();
65
76
  const data = formatReviewersForRefInput(params.data, reviewerModel.modelId);
77
+ security.disableAuthorization();
66
78
  const entry = await cms.createEntry(model, data);
79
+ security.enableAuthorization();
67
80
  return (0, _index.getFieldValues)(entry, _index.baseFields);
68
81
  },
69
82
 
@@ -82,13 +95,17 @@ const createWorkflowStorageOperations = ({
82
95
  const input = _objectSpread(_objectSpread({}, existingEntry), params.data);
83
96
 
84
97
  const data = formatReviewersForRefInput(input, reviewerModel.modelId);
98
+ security.disableAuthorization();
85
99
  const entry = await cms.updateEntry(model, params.id, data);
100
+ security.enableAuthorization();
86
101
  return (0, _index.getFieldValues)(entry, _index.baseFields);
87
102
  },
88
103
 
89
104
  async deleteWorkflow(params) {
90
105
  const model = await getWorkflowModel();
106
+ security.disableAuthorization();
91
107
  await cms.deleteEntry(model, params.id);
108
+ security.enableAuthorization();
92
109
  return true;
93
110
  }
94
111
 
@@ -1 +1 @@
1
- {"version":3,"names":["formatReviewersForRefInput","data","modelId","steps","map","step","reviewers","id","createWorkflowStorageOperations","cms","getWorkflowModel","model","getModel","WebinyError","getWorkflow","entry","getEntryById","getFieldValues","baseFields","listWorkflows","params","entries","meta","listLatestEntries","createWorkflow","reviewerModel","getReviewerModel","createEntry","updateWorkflow","existingEntry","input","updateEntry","deleteWorkflow","deleteEntry"],"sources":["workflowStorageOperations.ts"],"sourcesContent":["import { CreateApwWorkflowParams } from \"~/types\";\nimport { ApwStorageOperations, ApwWorkflowStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\n\ntype ReviewersRefInput = CreateApwWorkflowParams<{ modelId: string; id: string }>;\n\nconst formatReviewersForRefInput = (\n data: CreateApwWorkflowParams,\n modelId: string\n): ReviewersRefInput => {\n return {\n ...data,\n steps: data.steps.map(step => ({\n ...step,\n reviewers: step.reviewers.map(id => ({\n id,\n modelId\n }))\n }))\n };\n};\n\nexport const createWorkflowStorageOperations = ({\n cms\n}: Pick<CreateApwStorageOperationsParams, \"cms\">): ApwWorkflowStorageOperations => {\n const getWorkflowModel = async () => {\n const model = await cms.getModel(\"apwWorkflowModelDefinition\");\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwWorkflowModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getWorkflow: ApwWorkflowStorageOperations[\"getWorkflow\"] = async ({ id }) => {\n const model = await getWorkflowModel();\n const entry = await cms.getEntryById(model, id);\n return getFieldValues(entry, baseFields);\n };\n return {\n getWorkflowModel,\n getWorkflow,\n async listWorkflows(params) {\n const model = await getWorkflowModel();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params\n });\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n\n const data = formatReviewersForRefInput(params.data, reviewerModel.modelId);\n const entry = await cms.createEntry(model, data);\n\n return getFieldValues(entry, baseFields);\n },\n async updateWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getWorkflow({ id: params.id });\n const input = {\n ...existingEntry,\n ...params.data\n };\n const data = formatReviewersForRefInput(\n input as CreateApwWorkflowParams,\n reviewerModel.modelId\n );\n const entry = await cms.updateEntry(model, params.id, data);\n return getFieldValues(entry, baseFields);\n },\n async deleteWorkflow(params) {\n const model = await getWorkflowModel();\n await cms.deleteEntry(model, params.id);\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AAKA;;;;;;AAIA,MAAMA,0BAA0B,GAAG,CAC/BC,IAD+B,EAE/BC,OAF+B,KAGX;EACpB,uCACOD,IADP;IAEIE,KAAK,EAAEF,IAAI,CAACE,KAAL,CAAWC,GAAX,CAAeC,IAAI,oCACnBA,IADmB;MAEtBC,SAAS,EAAED,IAAI,CAACC,SAAL,CAAeF,GAAf,CAAmBG,EAAE,KAAK;QACjCA,EADiC;QAEjCL;MAFiC,CAAL,CAArB;IAFW,EAAnB;EAFX;AAUH,CAdD;;AAgBO,MAAMM,+BAA+B,GAAG,CAAC;EAC5CC;AAD4C,CAAD,KAEoC;EAC/E,MAAMC,gBAAgB,GAAG,YAAY;IACjC,MAAMC,KAAK,GAAG,MAAMF,GAAG,CAACG,QAAJ,CAAa,4BAAb,CAApB;;IACA,IAAI,CAACD,KAAL,EAAY;MACR,MAAM,IAAIE,cAAJ,CACF,oDADE,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOF,KAAP;EACH,CATD;;EAUA,MAAMG,WAAwD,GAAG,OAAO;IAAEP;EAAF,CAAP,KAAkB;IAC/E,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AAb,CAAD,CAAvC;;MACA,MAAMuB,KAAK,mCACJD,aADI,GAEJT,MAAM,CAACnB,IAFH,CAAX;;MAIA,MAAMA,IAAI,GAAGD,0BAA0B,CACnC8B,KADmC,EAEnCL,aAAa,CAACvB,OAFqB,CAAvC;MAIA,MAAMa,KAAK,GAAG,MAAMN,GAAG,CAACsB,WAAJ,CAAgBpB,KAAhB,EAAuBS,MAAM,CAACb,EAA9B,EAAkCN,IAAlC,CAApB;MACA,OAAO,IAAAgB,qBAAA,EAAeF,KAAf,EAAsBG,iBAAtB,CAAP;IACH,CArCE;;IAsCH,MAAMc,cAAN,CAAqBZ,MAArB,EAA6B;MACzB,MAAMT,KAAK,GAAG,MAAMD,gBAAgB,EAApC;MACA,MAAMD,GAAG,CAACwB,WAAJ,CAAgBtB,KAAhB,EAAuBS,MAAM,CAACb,EAA9B,CAAN;MACA,OAAO,IAAP;IACH;;EA1CE,CAAP;AA4CH,CA9DM"}
1
+ {"version":3,"names":["formatReviewersForRefInput","data","modelId","steps","map","step","reviewers","id","createWorkflowStorageOperations","params","cms","security","getWorkflowModel","disableAuthorization","model","getModel","WORKFLOW_MODEL_ID","enableAuthorization","WebinyError","getWorkflow","entry","getEntryById","getFieldValues","baseFields","listWorkflows","entries","meta","listLatestEntries","createWorkflow","reviewerModel","getReviewerModel","createEntry","updateWorkflow","existingEntry","input","updateEntry","deleteWorkflow","deleteEntry"],"sources":["workflowStorageOperations.ts"],"sourcesContent":["import { CreateApwWorkflowParams } from \"~/types\";\nimport { ApwStorageOperations, ApwWorkflowStorageOperations } from \"./types\";\nimport {\n baseFields,\n CreateApwStorageOperationsParams,\n getFieldValues\n} from \"~/storageOperations/index\";\nimport WebinyError from \"@webiny/error\";\nimport { WORKFLOW_MODEL_ID } from \"~/storageOperations/models/workflow.model\";\n\ntype ReviewersRefInput = CreateApwWorkflowParams<{ modelId: string; id: string }>;\n\nconst formatReviewersForRefInput = (\n data: CreateApwWorkflowParams,\n modelId: string\n): ReviewersRefInput => {\n return {\n ...data,\n steps: data.steps.map(step => ({\n ...step,\n reviewers: step.reviewers.map(id => ({\n id,\n modelId\n }))\n }))\n };\n};\n\nexport const createWorkflowStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwWorkflowStorageOperations => {\n const { cms, security } = params;\n const getWorkflowModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(WORKFLOW_MODEL_ID);\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n `Could not find \"${WORKFLOW_MODEL_ID}\" model.`,\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getWorkflow: ApwWorkflowStorageOperations[\"getWorkflow\"] = async ({ id }) => {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n };\n return {\n getWorkflowModel,\n getWorkflow,\n async listWorkflows(params) {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params\n });\n security.enableAuthorization();\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n\n const data = formatReviewersForRefInput(params.data, reviewerModel.modelId);\n security.disableAuthorization();\n const entry = await cms.createEntry(model, data);\n security.enableAuthorization();\n\n return getFieldValues(entry, baseFields);\n },\n async updateWorkflow(this: ApwStorageOperations, params) {\n const model = await getWorkflowModel();\n const reviewerModel = await this.getReviewerModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getWorkflow({ id: params.id });\n const input = {\n ...existingEntry,\n ...params.data\n };\n const data = formatReviewersForRefInput(\n input as CreateApwWorkflowParams,\n reviewerModel.modelId\n );\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, data);\n security.enableAuthorization();\n return getFieldValues(entry, baseFields);\n },\n async deleteWorkflow(params) {\n const model = await getWorkflowModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AAKA;;AACA;;;;;;AAIA,MAAMA,0BAA0B,GAAG,CAC/BC,IAD+B,EAE/BC,OAF+B,KAGX;EACpB,uCACOD,IADP;IAEIE,KAAK,EAAEF,IAAI,CAACE,KAAL,CAAWC,GAAX,CAAeC,IAAI,oCACnBA,IADmB;MAEtBC,SAAS,EAAED,IAAI,CAACC,SAAL,CAAeF,GAAf,CAAmBG,EAAE,KAAK;QACjCA,EADiC;QAEjCL;MAFiC,CAAL,CAArB;IAFW,EAAnB;EAFX;AAUH,CAdD;;AAgBO,MAAMM,+BAA+B,GACxCC,MAD2C,IAEZ;EAC/B,MAAM;IAAEC,GAAF;IAAOC;EAAP,IAAoBF,MAA1B;;EACA,MAAMG,gBAAgB,GAAG,YAAY;IACjCD,QAAQ,CAACE,oBAAT;IACA,MAAMC,KAAK,GAAG,MAAMJ,GAAG,CAACK,QAAJ,CAAaC,2BAAb,CAApB;IACAL,QAAQ,CAACM,mBAAT;;IACA,IAAI,CAACH,KAAL,EAAY;MACR,MAAM,IAAII,cAAJ,CACD,mBAAkBF,2BAAkB,UADnC,EAEF,uBAFE,CAAN;IAIH;;IACD,OAAOF,KAAP;EACH,CAXD;;EAYA,MAAMK,WAAwD,GAAG,OAAO;IAAEZ;EAAF,CAAP,KAAkB;IAC/E,MAAMO,KAAK,GAAG,MAAMF,gBAAgB,EAApC;IACAD,QAAQ,CAACE,oBAAT;IACA,MAAMO,KAAK,GAAG,MAAMV,GAAG,CAACW,YAAJ,CAAiBP,KAAjB,EAAwBP,EAAxB,CAApB;IACAI,QAAQ,CAACM,mBAAT;IACA,OAAO,IAAAK,qBAAA,EAAeF,KAAf,EAAsBG,iBAAtB,CAAP;EACH,CAND;;EAOA,OAAO;IACHX,gBADG;IAEHO,WAFG;;IAGH,M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EnCL,aAAa,CAAC3B,OAFqB,CAAvC;MAIAS,QAAQ,CAACE,oBAAT;MACA,MAAMO,KAAK,GAAG,MAAMV,GAAG,CAACyB,WAAJ,CAAgBrB,KAAhB,EAAuBL,MAAM,CAACF,EAA9B,EAAkCN,IAAlC,CAApB;MACAU,QAAQ,CAACM,mBAAT;MACA,OAAO,IAAAK,qBAAA,EAAeF,KAAf,EAAsBG,iBAAtB,CAAP;IACH,CA3CE;;IA4CH,MAAMa,cAAN,CAAqB3B,MAArB,EAA6B;MACzB,MAAMK,KAAK,GAAG,MAAMF,gBAAgB,EAApC;MACAD,QAAQ,CAACE,oBAAT;MACA,MAAMH,GAAG,CAAC2B,WAAJ,CAAgBvB,KAAhB,EAAuBL,MAAM,CAACF,EAA9B,CAAN;MACAI,QAAQ,CAACM,mBAAT;MACA,OAAO,IAAP;IACH;;EAlDE,CAAP;AAoDH,CA3EM"}
@@ -1,3 +1,3 @@
1
1
  import { Response, ErrorResponse } from "@webiny/handler-graphql";
2
- declare const _default: (fn: () => Promise<any>) => Promise<Response<any> | ErrorResponse>;
2
+ declare const _default: (fn: () => Promise<any>) => Promise<ErrorResponse | Response<any>>;
3
3
  export default _default;