@webiny/api-apw 0.0.0-unstable.990c3ab1b6 → 0.0.0-unstable.99666aeb00

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 (74) hide show
  1. package/crud/createContentReviewMethods.js +20 -5
  2. package/crud/createContentReviewMethods.js.map +1 -1
  3. package/index.d.ts +1 -2
  4. package/index.js +1 -5
  5. package/index.js.map +1 -1
  6. package/package.json +40 -47
  7. package/plugins/context.d.ts +0 -1
  8. package/plugins/context.js +2 -16
  9. package/plugins/context.js.map +1 -1
  10. package/plugins/graphql/changeRequest.gql.js +2 -2
  11. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  12. package/plugins/graphql/comment.gql.js +2 -2
  13. package/plugins/graphql/comment.gql.js.map +1 -1
  14. package/plugins/graphql/contentReview.gql.js +5 -5
  15. package/plugins/graphql/contentReview.gql.js.map +1 -1
  16. package/plugins/graphql/reviewer.gql.js +2 -2
  17. package/plugins/graphql/reviewer.gql.js.map +1 -1
  18. package/plugins/graphql/workflow.gql.js +2 -2
  19. package/plugins/graphql/workflow.gql.js.map +1 -1
  20. package/plugins/graphql.js +2 -2
  21. package/plugins/graphql.js.map +1 -1
  22. package/plugins/hooks/initializeContentReviewSteps.js +8 -2
  23. package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
  24. package/plugins/hooks/notifications/changeRequestAfterCreate.js +3 -8
  25. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  26. package/plugins/hooks/notifications/commentAfterCreate.js +3 -8
  27. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  28. package/plugins/hooks/notifications/contentReviewAfterCreate.js +3 -8
  29. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  30. package/plugins/hooks/notifications/reviewers.js +15 -14
  31. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  32. package/scheduler/createScheduleActionMethods.js +2 -7
  33. package/scheduler/createScheduleActionMethods.js.map +1 -1
  34. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  35. package/scheduler/handlers/executeAction/index.js +37 -7
  36. package/scheduler/handlers/executeAction/index.js.map +1 -1
  37. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
  38. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +14 -0
  39. package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
  40. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
  41. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +7 -2
  42. package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
  43. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
  44. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +3 -59
  45. package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
  46. package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
  47. package/scheduler/handlers/scheduleAction/index.js +5 -1
  48. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  49. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -0
  50. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  51. package/scheduler/handlers/utils.d.ts +1 -2
  52. package/scheduler/handlers/utils.js +0 -1
  53. package/scheduler/handlers/utils.js.map +1 -1
  54. package/scheduler/types.d.ts +2 -20
  55. package/scheduler/types.js +0 -5
  56. package/scheduler/types.js.map +1 -1
  57. package/storageOperations/changeRequestStorageOperations.js +20 -20
  58. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  59. package/storageOperations/commentStorageOperations.js +23 -23
  60. package/storageOperations/commentStorageOperations.js.map +1 -1
  61. package/storageOperations/contentReviewStorageOperations.js +20 -20
  62. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  63. package/storageOperations/models/contentModelPluginFactory.d.ts +3 -10
  64. package/storageOperations/models/contentModelPluginFactory.js +3 -6
  65. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  66. package/storageOperations/models/index.js +0 -4
  67. package/storageOperations/models/index.js.map +1 -1
  68. package/storageOperations/reviewerStorageOperations.js +23 -28
  69. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  70. package/storageOperations/workflowStorageOperations.js +20 -18
  71. package/storageOperations/workflowStorageOperations.js.map +1 -1
  72. package/types.d.ts +6 -5
  73. package/types.js.map +1 -1
  74. package/utils/resolve.d.ts +1 -1
@@ -3,6 +3,7 @@ import { SecurityIdentity, SecurityPermission } from "@webiny/api-security/types
3
3
  import { I18NLocale, I18NContext } from "@webiny/api-i18n/types";
4
4
  import { Tenant } from "@webiny/api-tenancy/types";
5
5
  import { TenancyContext } from "@webiny/api-tenancy/types";
6
+ import { ApwIdentity } from "../types";
6
7
  export interface ListWhere {
7
8
  /**
8
9
  * Fields.
@@ -29,25 +30,6 @@ export interface ListParams {
29
30
  limit?: number;
30
31
  after?: string;
31
32
  }
32
- /**
33
- * A interface describing the reference to a user that created some data in the database.
34
- *
35
- * @category General
36
- */
37
- export interface CreatedBy {
38
- /**
39
- * ID if the user.
40
- */
41
- id: string;
42
- /**
43
- * Full name of the user.
44
- */
45
- displayName: string | null;
46
- /**
47
- * Type of the user (admin, user)
48
- */
49
- type: string;
50
- }
51
33
  export interface ListMeta {
52
34
  /**
53
35
  * A cursor for pagination.
@@ -70,7 +52,7 @@ export interface BaseFields {
70
52
  id: string;
71
53
  createdOn: string;
72
54
  savedOn?: string;
73
- createdBy: CreatedBy;
55
+ createdBy: ApwIdentity;
74
56
  tenant: string;
75
57
  locale: string;
76
58
  }
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.InvocationTypes = exports.ApwScheduleActionTypes = exports.ApwContentTypes = void 0;
7
- /**
8
- * A interface describing the reference to a user that created some data in the database.
9
- *
10
- * @category General
11
- */
12
7
  let ApwContentTypes;
13
8
  exports.ApwContentTypes = ApwContentTypes;
14
9
  (function (ApwContentTypes) {
@@ -1 +1 @@
1
- {"version":3,"names":["ApwContentTypes","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\n/**\n * A interface describing the reference to a user that created some data in the database.\n *\n * @category General\n */\nexport interface CreatedBy {\n /**\n * ID if the user.\n */\n id: string;\n /**\n * Full name of the user.\n */\n displayName: string | null;\n /**\n * Type of the user (admin, user)\n */\n type: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: CreatedBy;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;AAkCA;AACA;AACA;AACA;AACA;AAJA,IAmCYA,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe;AAAA,IAkBfC,sBAAsB;AAAA;AAAA,WAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;AAAA,GAAtBA,sBAAsB,sCAAtBA,sBAAsB;AAAA,IAiBtBC,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe"}
1
+ {"version":3,"names":["ApwContentTypes","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { ApwIdentity } from \"~/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: ApwIdentity;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;IAkDYA,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe;AAAA,IAkBfC,sBAAsB;AAAA;AAAA,WAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;AAAA,GAAtBA,sBAAsB,sCAAtBA,sBAAsB;AAAA,IAiBtBC,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe"}
@@ -16,9 +16,9 @@ const createChangeRequestStorageOperations = params => {
16
16
  security
17
17
  } = params;
18
18
  const getChangeRequestModel = async () => {
19
- security.disableAuthorization();
20
- const model = await cms.getModel("apwChangeRequestModelDefinition");
21
- security.enableAuthorization();
19
+ const model = await security.withoutAuthorization(async () => {
20
+ return cms.getModel("apwChangeRequestModelDefinition");
21
+ });
22
22
  if (!model) {
23
23
  throw new _error.default("Could not find `apwChangeRequestModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
24
24
  }
@@ -28,9 +28,9 @@ const createChangeRequestStorageOperations = params => {
28
28
  id
29
29
  }) => {
30
30
  const model = await getChangeRequestModel();
31
- security.disableAuthorization();
32
- const entry = await cms.getEntryById(model, id);
33
- security.enableAuthorization();
31
+ const entry = await security.withoutAuthorization(async () => {
32
+ return cms.getEntryById(model, id);
33
+ });
34
34
  return (0, _fieldResolver.getFieldValues)({
35
35
  entry,
36
36
  fields: _index.baseFields,
@@ -43,11 +43,11 @@ const createChangeRequestStorageOperations = params => {
43
43
  getChangeRequest,
44
44
  async listChangeRequests(params) {
45
45
  const model = await getChangeRequestModel();
46
- security.disableAuthorization();
47
- const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
48
- where: (0, _objectSpread2.default)({}, params.where)
49
- }));
50
- security.enableAuthorization();
46
+ const [entries, meta] = await security.withoutAuthorization(async () => {
47
+ return cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
48
+ where: (0, _objectSpread2.default)({}, params.where)
49
+ }));
50
+ });
51
51
  try {
52
52
  const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
53
53
  entry,
@@ -62,9 +62,9 @@ const createChangeRequestStorageOperations = params => {
62
62
  },
63
63
  async createChangeRequest(params) {
64
64
  const model = await getChangeRequestModel();
65
- security.disableAuthorization();
66
- const entry = await cms.createEntry(model, params.data);
67
- security.enableAuthorization();
65
+ const entry = await security.withoutAuthorization(async () => {
66
+ return cms.createEntry(model, params.data);
67
+ });
68
68
  return (0, _fieldResolver.getFieldValues)({
69
69
  entry,
70
70
  fields: _index.baseFields,
@@ -81,9 +81,9 @@ const createChangeRequestStorageOperations = params => {
81
81
  const existingEntry = await getChangeRequest({
82
82
  id: params.id
83
83
  });
84
- security.disableAuthorization();
85
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
86
- security.enableAuthorization();
84
+ const entry = await security.withoutAuthorization(async () => {
85
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
86
+ });
87
87
  return (0, _fieldResolver.getFieldValues)({
88
88
  entry,
89
89
  fields: _index.baseFields,
@@ -93,9 +93,9 @@ const createChangeRequestStorageOperations = params => {
93
93
  },
94
94
  async deleteChangeRequest(params) {
95
95
  const model = await getChangeRequestModel();
96
- security.disableAuthorization();
97
- await cms.deleteEntry(model, params.id);
98
- security.enableAuthorization();
96
+ await security.withoutAuthorization(async () => {
97
+ return cms.deleteEntry(model, params.id);
98
+ });
99
99
  return true;
100
100
  }
101
101
  };
@@ -1 +1 @@
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","ex","message","code","data","createChangeRequest","createEntry","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 try {\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 } catch (ex) {\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\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,MAAwC,IACJ;EACpC,MAAM;IAAEC,GAAG;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EN,MAAM,CAACW,EAAE,8DAC7CwB,aAAa,GACbnC,MAAM,CAAC+B,IAAI,EAChB;MACF5B,QAAQ,CAACK,mBAAmB,EAAE;MAC9B,OAAO,IAAAM,6BAAc,EAAC;QAClBF,KAAK;QACLG,MAAM,EAAEC,iBAAU;QAClBC,OAAO,EAAEf,aAAa,EAAE;QACxBgB,YAAY,EAAE,CAAC,IAAAC,6BAAc,EAACb,KAAK,EAAE,MAAM,CAAC;MAChD,CAAC,CAAC;IACN,CAAC;IACD,MAAM+B,mBAAmB,CAACrC,MAAM,EAAE;MAC9B,MAAMM,KAAK,GAAG,MAAMF,qBAAqB,EAAE;MAC3CD,QAAQ,CAACE,oBAAoB,EAAE;MAC/B,MAAMJ,GAAG,CAACqC,WAAW,CAAChC,KAAK,EAAEN,MAAM,CAACW,EAAE,CAAC;MACvCR,QAAQ,CAACK,mBAAmB,EAAE;MAC9B,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["createChangeRequestStorageOperations","params","cms","getCmsContext","security","getChangeRequestModel","model","withoutAuthorization","getModel","WebinyError","getChangeRequest","id","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","listChangeRequests","entries","meta","listLatestEntries","where","all","Promise","map","ex","message","code","data","createChangeRequest","createEntry","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 const model = await security.withoutAuthorization(async () => {\n return cms.getModel(\"apwChangeRequestModelDefinition\");\n });\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\n const entry = await security.withoutAuthorization(async () => {\n return cms.getEntryById(model, id);\n });\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\n const [entries, meta] = await security.withoutAuthorization(async () => {\n return cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n });\n try {\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 } catch (ex) {\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\n },\n async createChangeRequest(params) {\n const model = await getChangeRequestModel();\n\n const entry = await security.withoutAuthorization(async () => {\n return cms.createEntry(model, params.data);\n });\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 security.withoutAuthorization(async () => {\n return cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\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\n await security.withoutAuthorization(async () => {\n return cms.deleteEntry(model, params.id);\n });\n return true;\n }\n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AMR,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC1D,OAAOL,GAAG,CAACkC,WAAW,CAAC9B,KAAK,EAAEL,MAAM,CAACU,EAAE,8DAChCwB,aAAa,GACblC,MAAM,CAAC8B,IAAI,EAChB;MACN,CAAC,CAAC;MACF,OAAO,IAAAjB,6BAAc,EAAC;QAClBF,KAAK;QACLG,MAAM,EAAEC,iBAAU;QAClBC,OAAO,EAAEd,aAAa,EAAE;QACxBe,YAAY,EAAE,CAAC,IAAAC,6BAAc,EAACb,KAAK,EAAE,MAAM,CAAC;MAChD,CAAC,CAAC;IACN,CAAC;IACD,MAAM+B,mBAAmB,CAACpC,MAAM,EAAE;MAC9B,MAAMK,KAAK,GAAG,MAAMD,qBAAqB,EAAE;MAE3C,MAAMD,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC5C,OAAOL,GAAG,CAACoC,WAAW,CAAChC,KAAK,EAAEL,MAAM,CAACU,EAAE,CAAC;MAC5C,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -24,9 +24,9 @@ const createCommentStorageOperations = ({
24
24
  security
25
25
  }) => {
26
26
  const getCommentModel = async () => {
27
- security.disableAuthorization();
28
- const model = await cms.getModel(_comment.COMMENT_MODEL_ID);
29
- security.enableAuthorization();
27
+ const model = await security.withoutAuthorization(async () => {
28
+ return cms.getModel(_comment.COMMENT_MODEL_ID);
29
+ });
30
30
  if (!model) {
31
31
  throw new _error.default(`Could not find "${_comment.COMMENT_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
32
32
  }
@@ -36,9 +36,9 @@ const createCommentStorageOperations = ({
36
36
  id
37
37
  }) => {
38
38
  const model = await getCommentModel();
39
- security.disableAuthorization();
40
- const entry = await cms.getEntryById(model, id);
41
- security.enableAuthorization();
39
+ const entry = await security.withoutAuthorization(async () => {
40
+ return cms.getEntryById(model, id);
41
+ });
42
42
  return (0, _fieldResolver.getFieldValues)({
43
43
  entry,
44
44
  fields: _index.baseFields,
@@ -54,9 +54,9 @@ const createCommentStorageOperations = ({
54
54
  },
55
55
  async listComments(params) {
56
56
  const model = await getCommentModel();
57
- security.disableAuthorization();
58
- const [entries, meta] = await cms.listLatestEntries(model, params);
59
- security.enableAuthorization();
57
+ const [entries, meta] = await security.withoutAuthorization(async () => {
58
+ return cms.listLatestEntries(model, params);
59
+ });
60
60
  const values = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
61
61
  entry,
62
62
  fields: _index.baseFields,
@@ -69,14 +69,14 @@ const createCommentStorageOperations = ({
69
69
  async createComment(params) {
70
70
  const model = await getCommentModel();
71
71
  const refModel = await this.getChangeRequestModel();
72
- security.disableAuthorization();
73
- const entry = await cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.data), {}, {
74
- changeRequest: {
75
- id: params.data.changeRequest,
76
- modelId: refModel.modelId
77
- }
78
- }));
79
- security.enableAuthorization();
72
+ const entry = await security.withoutAuthorization(async () => {
73
+ return cms.createEntry(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.data), {}, {
74
+ changeRequest: {
75
+ id: params.data.changeRequest,
76
+ modelId: refModel.modelId
77
+ }
78
+ }));
79
+ });
80
80
  const values = await (0, _fieldResolver.getFieldValues)({
81
81
  entry,
82
82
  fields: _index.baseFields,
@@ -94,9 +94,9 @@ const createCommentStorageOperations = ({
94
94
  const existingEntry = await getComment({
95
95
  id: params.id
96
96
  });
97
- security.disableAuthorization();
98
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
99
- security.enableAuthorization();
97
+ const entry = await security.withoutAuthorization(async () => {
98
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
99
+ });
100
100
  const values = await (0, _fieldResolver.getFieldValues)({
101
101
  entry,
102
102
  fields: _index.baseFields,
@@ -107,9 +107,9 @@ const createCommentStorageOperations = ({
107
107
  },
108
108
  async deleteComment(params) {
109
109
  const model = await getCommentModel();
110
- security.disableAuthorization();
111
- await cms.deleteEntry(model, params.id);
112
- security.enableAuthorization();
110
+ await security.withoutAuthorization(async () => {
111
+ return cms.deleteEntry(model, params.id);
112
+ });
113
113
  return true;
114
114
  }
115
115
  };
@@ -1 +1 @@
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"],"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3,"names":["pickIdFromChangeRequest","obj","rawValue","id","createCommentStorageOperations","cms","getCmsContext","security","getCommentModel","model","withoutAuthorization","getModel","COMMENT_MODEL_ID","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 const model = await security.withoutAuthorization(async () => {\n return cms.getModel(COMMENT_MODEL_ID);\n });\n\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 const entry = await security.withoutAuthorization(async () => {\n return cms.getEntryById(model, id);\n });\n\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 security.withoutAuthorization(async () => {\n return cms.listLatestEntries(model, 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\n const entry = await security.withoutAuthorization(async () => {\n return cms.createEntry(model, {\n ...params.data,\n changeRequest: {\n id: params.data.changeRequest,\n modelId: refModel.modelId\n }\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 security.withoutAuthorization(async () => {\n return cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\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 deleteComment(params) {\n const model = await getCommentModel();\n await security.withoutAuthorization(async () => {\n return cms.deleteEntry(model, params.id);\n });\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AAEA;AACA;AACA;AAGA;AAEA,MAAMA,uBAAuB,GAAIC,GAAwB,IAAiB;EACtE,MAAMC,QAAQ,GAAGD,GAAG,CAAC,eAAe,CAAC;EACrC,IAAI,CAACC,QAAQ,EAAE;IACX,OAAOD,GAAG;EACd;EACAA,GAAG,CAAC,eAAe,CAAC,GAAGC,QAAQ,CAACC,EAAE;EAClC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B,MAAM,EAAE;MACxB,MAAMd,KAAK,GAAG,MAAMD,eAAe,EAAE;MACrC;AACZ;AACA;AACA;MACY,MAAMiC,aAAa,GAAG,MAAM3B,UAAU,CAAC;QAAEX,EAAE,EAAEoB,MAAM,CAACpB;MAAG,CAAC,CAAC;MAEzD,MAAMY,KAAK,GAAG,MAAMR,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC1D,OAAOL,GAAG,CAACqC,WAAW,CAACjC,KAAK,EAAEc,MAAM,CAACpB,EAAE,8DAChCsC,aAAa,GACblB,MAAM,CAACc,IAAI,EAChB;MACN,CAAC,CAAC;MAEF,MAAMb,MAAM,GAAG,MAAM,IAAAP,6BAAc,EAAC;QAChCF,KAAK;QACLG,MAAM,EAAEC,iBAAU;QAClBC,OAAO,EAAEd,aAAa,EAAE;QACxBe,YAAY,EAAE,CAAC,IAAAC,6BAAc,EAACb,KAAK,EAAE,MAAM,CAAC;MAChD,CAAC,CAAC;MACF,OAAOT,uBAAuB,CAACwB,MAAM,CAAC;IAC1C,CAAC;IACD,MAAMmB,aAAa,CAACpB,MAAM,EAAE;MACxB,MAAMd,KAAK,GAAG,MAAMD,eAAe,EAAE;MACrC,MAAMD,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC5C,OAAOL,GAAG,CAACuC,WAAW,CAACnC,KAAK,EAAEc,MAAM,CAACpB,EAAE,CAAC;MAC5C,CAAC,CAAC;MACF,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -14,9 +14,9 @@ const createContentReviewStorageOperations = ({
14
14
  security
15
15
  }) => {
16
16
  const getContentReviewModel = async () => {
17
- security.disableAuthorization();
18
- const model = await cms.getModel(_contentReview.CONTENT_REVIEW_MODEL_ID);
19
- security.enableAuthorization();
17
+ const model = await security.withoutAuthorization(async () => {
18
+ return cms.getModel(_contentReview.CONTENT_REVIEW_MODEL_ID);
19
+ });
20
20
  if (!model) {
21
21
  throw new _error.default(`Could not find "${_contentReview.CONTENT_REVIEW_MODEL_ID}" model.`, "MODEL_NOT_FOUND_ERROR");
22
22
  }
@@ -26,9 +26,9 @@ const createContentReviewStorageOperations = ({
26
26
  id
27
27
  }) => {
28
28
  const model = await getContentReviewModel();
29
- security.disableAuthorization();
30
- const entry = await cms.getEntryById(model, id);
31
- security.enableAuthorization();
29
+ const entry = await security.withoutAuthorization(async () => {
30
+ return cms.getEntryById(model, id);
31
+ });
32
32
  return (0, _index.getFieldValues)(entry, _index.baseFields);
33
33
  };
34
34
  return {
@@ -36,18 +36,18 @@ const createContentReviewStorageOperations = ({
36
36
  getContentReview,
37
37
  async listContentReviews(params) {
38
38
  const model = await getContentReviewModel();
39
- security.disableAuthorization();
40
- const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
41
- where: (0, _objectSpread2.default)({}, params.where)
42
- }));
43
- security.enableAuthorization();
39
+ const [entries, meta] = await security.withoutAuthorization(async () => {
40
+ return cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
41
+ where: (0, _objectSpread2.default)({}, params.where)
42
+ }));
43
+ });
44
44
  return [entries.map(entry => (0, _index.getFieldValues)(entry, _index.baseFields)), meta];
45
45
  },
46
46
  async createContentReview(params) {
47
47
  const model = await getContentReviewModel();
48
- security.disableAuthorization();
49
- const entry = await cms.createEntry(model, params.data);
50
- security.enableAuthorization();
48
+ const entry = await security.withoutAuthorization(async () => {
49
+ return cms.createEntry(model, params.data);
50
+ });
51
51
  return (0, _index.getFieldValues)(entry, _index.baseFields);
52
52
  },
53
53
  async updateContentReview(params) {
@@ -59,16 +59,16 @@ const createContentReviewStorageOperations = ({
59
59
  const existingEntry = await getContentReview({
60
60
  id: params.id
61
61
  });
62
- security.disableAuthorization();
63
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
64
- security.enableAuthorization();
62
+ const entry = await security.withoutAuthorization(async () => {
63
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
64
+ });
65
65
  return (0, _index.getFieldValues)(entry, _index.baseFields);
66
66
  },
67
67
  async deleteContentReview(params) {
68
68
  const model = await getContentReviewModel();
69
- security.disableAuthorization();
70
- await cms.deleteEntry(model, params.id);
71
- security.enableAuthorization();
69
+ await security.withoutAuthorization(async () => {
70
+ return cms.deleteEntry(model, params.id);
71
+ });
72
72
  return true;
73
73
  }
74
74
  };
@@ -1 +1 @@
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,GAAG;EACHC;AAC8B,CAAC,KAAwC;EACvE,MAAMC,qBAAqB,GAAG,YAAY;IACtCD,QAAQ,CAACE,oBAAoB,EAAE;IAC/B,MAAMC,KAAK,GAAG,MAAMJ,GAAG,CAACK,QAAQ,CAACC,sCAAuB,CAAC;IACzDL,QAAQ,CAACM,mBAAmB,EAAE;IAC9B,IAAI,CAACH,KAAK,EAAE;MACR,MAAM,IAAII,cAAW,CAChB,mBAAkBF,sCAAwB,UAAS,EACpD,uBAAuB,CAC1B;IACL;IACA,OAAOF,KAAK;EAChB,CAAC;EACD,MAAMK,gBAAuE,GAAG,OAAO;IACnFC;EACJ,CAAC,KAAK;IACF,MAAMN,KAAK,GAAG,MAAMF,qBAAqB,EAAE;IAC3CD,QAAQ,CAACE,oBAAoB,EAAE;IAC/B,MAAMQ,KAAK,GAAG,MAAMX,GAAG,CAACY,Y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AAMQ,KAAK,GAAG,MAAMX,GAAG,CAAC2B,WAAW,CAACvB,KAAK,EAAEY,MAAM,CAACN,EAAE,8DAC7CgB,aAAa,GACbV,MAAM,CAACQ,IAAI,EAChB;MACFvB,QAAQ,CAACM,mBAAmB,EAAE;MAC9B,OAAO,IAAAM,qBAAc,EAACF,KAAK,EAAEG,iBAAU,CAAC;IAC5C,CAAC;IACD,MAAMc,mBAAmB,CAACZ,MAAM,EAAE;MAC9B,MAAMZ,KAAK,GAAG,MAAMF,qBAAqB,EAAE;MAC3CD,QAAQ,CAACE,oBAAoB,EAAE;MAC/B,MAAMH,GAAG,CAAC6B,WAAW,CAACzB,KAAK,EAAEY,MAAM,CAACN,EAAE,CAAC;MACvCT,QAAQ,CAACM,mBAAmB,EAAE;MAC9B,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["createContentReviewStorageOperations","cms","security","getContentReviewModel","model","withoutAuthorization","getModel","CONTENT_REVIEW_MODEL_ID","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 const model = await security.withoutAuthorization(async () => {\n return cms.getModel(CONTENT_REVIEW_MODEL_ID);\n });\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 const entry = await security.withoutAuthorization(async () => {\n return cms.getEntryById(model, id);\n });\n return getFieldValues(entry, baseFields);\n };\n return {\n getContentReviewModel,\n getContentReview,\n async listContentReviews(params) {\n const model = await getContentReviewModel();\n\n const [entries, meta] = await security.withoutAuthorization(async () => {\n return cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n });\n\n return [entries.map(entry => getFieldValues(entry, baseFields)), meta];\n },\n async createContentReview(params) {\n const model = await getContentReviewModel();\n\n const entry = await security.withoutAuthorization(async () => {\n return cms.createEntry(model, params.data);\n });\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 security.withoutAuthorization(async () => {\n return cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n });\n return getFieldValues(entry, baseFields);\n },\n async deleteContentReview(params) {\n const model = await getContentReviewModel();\n\n await security.withoutAuthorization(async () => {\n return cms.deleteEntry(model, params.id);\n });\n\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AACA;AAKA;AACA;AAEO,MAAMA,oCAAoC,GAAG,CAAC;EACjDC,GAAG;EACHC;AAC8B,CAAC,KAAwC;EACvE,MAAMC,qBAAqB,GAAG,YAAY;IACtC,MAAMC,KAAK,GAAG,MAAMF,QAAQ,CAACG,oBAAoB,CAAC,YAAY;MAC1D,OAAOJ,GAAG,CAACK,QAAQ,CAACC,sCAAuB,CAAC;IAChD,CAAC,CAAC;IACF,IAAI,CAACH,KAAK,EAAE;MACR,MAAM,IAAII,cAAW,CAChB,mBAAkBD,sCAAwB,UAAS,EACpD,uBAAuB,CAC1B;IACL;IACA,OAAOH,KAAK;EAChB,CAAC;EACD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C3C;AACZ;AACA;AACA;MACY,MAAMuB,aAAa,GAAG,MAAMjB,gBAAgB,CAAC;QAAEC,EAAE,EAAEM,MAAM,CAACN;MAAG,CAAC,CAAC;MAE/D,MAAMC,KAAK,GAAG,MAAMT,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC1D,OAAOJ,GAAG,CAAC0B,WAAW,CAACvB,KAAK,EAAEY,MAAM,CAACN,EAAE,8DAChCgB,aAAa,GACbV,MAAM,CAACQ,IAAI,EAChB;MACN,CAAC,CAAC;MACF,OAAO,IAAAX,qBAAc,EAACF,KAAK,EAAEG,iBAAU,CAAC;IAC5C,CAAC;IACD,MAAMc,mBAAmB,CAACZ,MAAM,EAAE;MAC9B,MAAMZ,KAAK,GAAG,MAAMD,qBAAqB,EAAE;MAE3C,MAAMD,QAAQ,CAACG,oBAAoB,CAAC,YAAY;QAC5C,OAAOJ,GAAG,CAAC4B,WAAW,CAACzB,KAAK,EAAEY,MAAM,CAACN,EAAE,CAAC;MAC5C,CAAC,CAAC;MAEF,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1,15 +1,8 @@
1
- import { CmsModelPlugin } from "@webiny/api-headless-cms";
2
- import { CmsModel, CmsGroup } from "@webiny/api-headless-cms/types";
1
+ import { CmsModelPlugin, CmsPrivateModelFull } from "@webiny/api-headless-cms";
2
+ import { CmsGroup } from "@webiny/api-headless-cms/types";
3
3
  interface Params {
4
4
  group: Pick<CmsGroup, "id" | "name">;
5
- /**
6
- * Locale and tenant do not need to be defined.
7
- * In that case model is not bound to any locale or tenant.
8
- * You can bind it to locale, tenant, both or none.
9
- */
10
- locale?: string;
11
- tenant?: string;
12
- modelDefinition: Omit<CmsModel, "locale" | "tenant" | "webinyVersion" | "group">;
5
+ modelDefinition: Omit<CmsPrivateModelFull, "group" | "noValidate">;
13
6
  }
14
7
  export declare const contentModelPluginFactory: (params: Params) => CmsModelPlugin;
15
8
  export {};
@@ -10,14 +10,11 @@ var _apiHeadlessCms = require("@webiny/api-headless-cms");
10
10
  const contentModelPluginFactory = params => {
11
11
  const {
12
12
  group,
13
- locale,
14
- tenant,
15
13
  modelDefinition
16
14
  } = params;
17
- return (0, _apiHeadlessCms.createCmsModel)((0, _objectSpread2.default)({
15
+ return (0, _apiHeadlessCms.createCmsModel)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, modelDefinition), {}, {
18
16
  group,
19
- locale,
20
- tenant
21
- }, modelDefinition));
17
+ noValidate: true
18
+ }));
22
19
  };
23
20
  exports.contentModelPluginFactory = contentModelPluginFactory;
@@ -1 +1 @@
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,MAAc,IAAqB;EACzE,MAAM;IAAEC,KAAK;IAAEC,MAAM;IAAEC,MAAM;IAAEC;EAAgB,CAAC,GAAGJ,MAAM;EAEzD,OAAO,IAAAK,8BAAc;IACjBJ,KAAK;IACLC,MAAM;IACNC;EAAM,GACHC,eAAe,EACpB;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["contentModelPluginFactory","params","group","modelDefinition","createCmsModel","noValidate"],"sources":["contentModelPluginFactory.ts"],"sourcesContent":["import { CmsModelPlugin, CmsPrivateModelFull, createCmsModel } from \"@webiny/api-headless-cms\";\nimport { CmsGroup } from \"@webiny/api-headless-cms/types\";\n\ninterface Params {\n group: Pick<CmsGroup, \"id\" | \"name\">;\n modelDefinition: Omit<CmsPrivateModelFull, \"group\" | \"noValidate\">;\n}\n\nexport const contentModelPluginFactory = (params: Params): CmsModelPlugin => {\n const { group, modelDefinition } = params;\n\n return createCmsModel({\n ...modelDefinition,\n group,\n noValidate: true\n });\n};\n"],"mappings":";;;;;;;;AAAA;AAQO,MAAMA,yBAAyB,GAAIC,MAAc,IAAqB;EACzE,MAAM;IAAEC,KAAK;IAAEC;EAAgB,CAAC,GAAGF,MAAM;EAEzC,OAAO,IAAAG,8BAAc,8DACdD,eAAe;IAClBD,KAAK;IACLG,UAAU,EAAE;EAAI,GAClB;AACN,CAAC;AAAC"}
@@ -29,7 +29,6 @@ const createApwModels = context => {
29
29
  })) {
30
30
  return;
31
31
  }
32
- context.security.disableAuthorization();
33
32
  const locale = context.i18n.getContentLocale();
34
33
  if (!locale) {
35
34
  throw new _error.default("Missing content locale in api-apw/storageOperations/index.ts", "LOCALE_ERROR");
@@ -70,8 +69,6 @@ const createApwModels = context => {
70
69
  for (const modelDefinition of modelDefinitions) {
71
70
  const cmsModelPlugin = (0, _contentModelPluginFactory.contentModelPluginFactory)({
72
71
  group: cmsGroupPlugin.contentModelGroup,
73
- tenant: context.tenancy.getCurrentTenant().id,
74
- locale: locale.code,
75
72
  modelDefinition
76
73
  });
77
74
  /**
@@ -88,6 +85,5 @@ const createApwModels = context => {
88
85
  * Register them so that they are accessible in cms context
89
86
  */
90
87
  context.plugins.register([cmsGroupPlugin, cmsModelPlugins]);
91
- context.security.enableAuthorization();
92
88
  };
93
89
  exports.createApwModels = createApwModels;
@@ -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 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,OAAmB,IAAK;EACpD;AACJ;AACA;AACA;EACI,IAAI,CAACA,OAAO,CAACC,GAAG,EAAE;IACdC,OAAO,CAACC,IAAI,CAAC,iCAAiC,CAAC;IAC/C;EACJ;EAEA,IAAI,IAAAC,4BAAqB,EAAC;IAAEC,OAAO,EAAEL,OAAO,CAACK,OAAO;IAAEC,IAAI,EAAEN,OAAO,CAACM;EAAK,CAAC,CAAC,EAAE;IACzE;EACJ;EAEAN,OAAO,CAACO,QAAQ,CAACC,oBAAoB,EAAE;EAEvC,MAAMC,MAAM,GAAGT,OAAO,CA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MACnBP;IACJ,CAAC,CAAC;IACF;AACR;AACA;AACA;IACQ,IAAIC,cAAc,CAACO,YAAY,CAACf,OAAO,KAAK,iCAAiC,EAAE;MAC3EQ,cAAc,CAACO,YAAY,CAACC,YAAY,GAAG,OAAO;IACtD;IACAV,eAAe,CAACW,IAAI,CAACT,cAAc,CAAC;EACxC;;EAEA;AACJ;AACA;EACIpC,OAAO,CAAC8C,OAAO,CAACC,QAAQ,CAAC,CAAClC,cAAc,EAAEqB,eAAe,CAAC,CAAC;EAE3DlC,OAAO,CAACO,QAAQ,CAACyC,mBAAmB,EAAE;AAC1C,CAAC;AAAC"}
1
+ {"version":3,"names":["createApwModels","context","cms","console","warn","isInstallationPending","tenancy","i18n","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","contentModel","titleFieldId","push","plugins","register"],"sources":["index.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsGroupPlugin, CmsModelPlugin } 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 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: CmsModelPlugin[] = [];\n for (const modelDefinition of modelDefinitions) {\n const cmsModelPlugin = contentModelPluginFactory({\n group: cmsGroupPlugin.contentModelGroup,\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"],"mappings":";;;;;;;AAAA;AACA;AACA;A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