@webiny/api-apw 0.0.0-unstable.6e5425ee89 → 0.0.0-unstable.78f581c1d2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ApwChangeRequestNotification.js +10 -0
- package/ApwChangeRequestNotification.js.map +1 -1
- package/ApwCommentNotification.js +10 -0
- package/ApwCommentNotification.js.map +1 -1
- package/ApwContentReviewNotification.js +10 -0
- package/ApwContentReviewNotification.js.map +1 -1
- package/ApwContentUrlPlugin.js +10 -0
- package/ApwContentUrlPlugin.js.map +1 -1
- package/ContentApwSettingsPlugin.js +5 -0
- package/ContentApwSettingsPlugin.js.map +1 -1
- package/crud/createChangeRequestMethods.js +11 -4
- package/crud/createChangeRequestMethods.js.map +1 -1
- package/crud/createCommentMethods.js +12 -4
- package/crud/createCommentMethods.js.map +1 -1
- package/crud/createContentReviewMethods.js +84 -20
- package/crud/createContentReviewMethods.js.map +1 -1
- package/crud/createReviewerMethods.js +12 -4
- package/crud/createReviewerMethods.js.map +1 -1
- package/crud/createWorkflowMethods.js +17 -4
- package/crud/createWorkflowMethods.js.map +1 -1
- package/crud/index.js +25 -0
- package/crud/index.js.map +1 -1
- package/crud/utils.js +28 -0
- package/crud/utils.js.map +1 -1
- package/index.js +11 -1
- package/index.js.map +1 -1
- package/package.json +34 -34
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +15 -0
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/cms/apwEntryPlugins.js +8 -0
- package/plugins/cms/apwEntryPlugins.js.map +1 -1
- package/plugins/cms/index.js +13 -0
- package/plugins/cms/index.js.map +1 -1
- package/plugins/cms/linkContentReviewToEntry.js +17 -0
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
- package/plugins/cms/linkWorkflowToEntry.js +31 -2
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
- package/plugins/cms/notifications/changeRequestNotification.js +4 -0
- package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
- package/plugins/cms/notifications/commentNotification.js +4 -0
- package/plugins/cms/notifications/commentNotification.js.map +1 -1
- package/plugins/cms/notifications/contentReviewNotification.js +4 -0
- package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
- package/plugins/cms/notifications/contentUrl.js +8 -1
- package/plugins/cms/notifications/contentUrl.js.map +1 -1
- package/plugins/cms/triggerContentReview.js +14 -0
- package/plugins/cms/triggerContentReview.js.map +1 -1
- package/plugins/cms/updateContentReviewStatus.js +18 -0
- package/plugins/cms/updateContentReviewStatus.js.map +1 -1
- package/plugins/cms/utils.js +47 -2
- package/plugins/cms/utils.js.map +1 -1
- package/plugins/context.js +31 -0
- package/plugins/context.js.map +1 -1
- package/plugins/graphql/changeRequest.gql.js +8 -1
- package/plugins/graphql/changeRequest.gql.js.map +1 -1
- package/plugins/graphql/comment.gql.js +8 -1
- package/plugins/graphql/comment.gql.js.map +1 -1
- package/plugins/graphql/contentReview.gql.js +20 -1
- package/plugins/graphql/contentReview.gql.js.map +1 -1
- package/plugins/graphql/reviewer.gql.js +8 -1
- package/plugins/graphql/reviewer.gql.js.map +1 -1
- package/plugins/graphql/workflow.gql.js +8 -1
- package/plugins/graphql/workflow.gql.js.map +1 -1
- package/plugins/graphql.js +16 -1
- package/plugins/graphql.js.map +1 -1
- package/plugins/hooks/createReviewerFromIdentity.js +11 -2
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +9 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +8 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
- package/plugins/hooks/index.js +14 -0
- package/plugins/hooks/index.js.map +1 -1
- package/plugins/hooks/initializeContentReviewSteps.js +15 -2
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
- package/plugins/hooks/initializeNotifications.js +5 -0
- package/plugins/hooks/initializeNotifications.js.map +1 -1
- package/plugins/hooks/listContentReviews.js +12 -0
- package/plugins/hooks/listContentReviews.js.map +1 -1
- package/plugins/hooks/notifications/appUrl.js +4 -0
- package/plugins/hooks/notifications/appUrl.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestAfterCreate.js +28 -0
- package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestUrl.js +4 -0
- package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
- package/plugins/hooks/notifications/commentAfterCreate.js +30 -0
- package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/commentUrl.js +4 -0
- package/plugins/hooks/notifications/commentUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewAfterCreate.js +24 -1
- package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewUrl.js +4 -0
- package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentUrl.js +5 -0
- package/plugins/hooks/notifications/contentUrl.js.map +1 -1
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +4 -0
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +4 -0
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +4 -0
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/reviewers.js +7 -0
- package/plugins/hooks/notifications/reviewers.js.map +1 -1
- package/plugins/hooks/notifications/sendChangeRequestNotification.js +11 -0
- package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendCommentNotification.js +11 -0
- package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendContentReviewNotification.js +11 -0
- package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
- package/plugins/hooks/updatePendingChangeRequests.js +8 -0
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
- package/plugins/hooks/updateTotalComments.js +9 -0
- package/plugins/hooks/updateTotalComments.js.map +1 -1
- package/plugins/hooks/validateChangeRequest.js +16 -0
- package/plugins/hooks/validateChangeRequest.js.map +1 -1
- package/plugins/hooks/validateComment.js +12 -1
- package/plugins/hooks/validateComment.js.map +1 -1
- package/plugins/hooks/validateContentReview.js +6 -0
- package/plugins/hooks/validateContentReview.js.map +1 -1
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +15 -0
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/pageBuilder/apwContentPagePlugins.js +4 -0
- package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js +6 -1
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
- package/plugins/pageBuilder/index.js +11 -0
- package/plugins/pageBuilder/index.js.map +1 -1
- package/plugins/pageBuilder/linkContentReviewToPage.js +16 -0
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
- package/plugins/pageBuilder/linkWorkflowToPage.js +31 -1
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
- package/plugins/pageBuilder/notifications/changeRequestNotification.js +4 -0
- package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/commentNotification.js +4 -0
- package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/contentReviewNotification.js +4 -0
- package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/contentUrl.js +7 -1
- package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -1
- package/plugins/pageBuilder/triggerContentReview.js +11 -0
- package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
- package/plugins/pageBuilder/updateContentReviewStatus.js +12 -0
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
- package/plugins/pageBuilder/utils.js +35 -1
- package/plugins/pageBuilder/utils.js.map +1 -1
- package/plugins/utils.js +43 -0
- package/plugins/utils.js.map +1 -1
- package/scheduler/createScheduleActionMethods.js +20 -1
- package/scheduler/createScheduleActionMethods.js.map +1 -1
- package/scheduler/handlers/executeAction/index.js +33 -9
- package/scheduler/handlers/executeAction/index.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +5 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +21 -0
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +27 -4
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/security.js +11 -0
- package/scheduler/handlers/executeAction/security.js.map +1 -1
- package/scheduler/handlers/scheduleAction/index.js +25 -5
- package/scheduler/handlers/scheduleAction/index.js.map +1 -1
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +23 -2
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
- package/scheduler/handlers/utils.js +40 -3
- package/scheduler/handlers/utils.js.map +1 -1
- package/scheduler/index.js +3 -0
- package/scheduler/index.js.map +1 -1
- package/scheduler/types.js +6 -0
- package/scheduler/types.js.map +1 -1
- package/storageOperations/changeRequestStorageOperations.js +19 -0
- package/storageOperations/changeRequestStorageOperations.js.map +1 -1
- package/storageOperations/commentStorageOperations.js +21 -0
- package/storageOperations/commentStorageOperations.js.map +1 -1
- package/storageOperations/contentReviewStorageOperations.js +17 -0
- package/storageOperations/contentReviewStorageOperations.js.map +1 -1
- package/storageOperations/index.js +14 -0
- package/storageOperations/index.js.map +1 -1
- package/storageOperations/models/changeRequest.model.js +9 -0
- package/storageOperations/models/changeRequest.model.js.map +1 -1
- package/storageOperations/models/comment.model.js +8 -0
- package/storageOperations/models/comment.model.js.map +1 -1
- package/storageOperations/models/contentModelPluginFactory.js +5 -0
- package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
- package/storageOperations/models/contentReview.model.js +26 -0
- package/storageOperations/models/contentReview.model.js.map +1 -1
- package/storageOperations/models/index.js +24 -2
- package/storageOperations/models/index.js.map +1 -1
- package/storageOperations/models/reviewer.model.js +8 -0
- package/storageOperations/models/reviewer.model.js.map +1 -1
- package/storageOperations/models/utils.js +4 -0
- package/storageOperations/models/utils.js.map +1 -1
- package/storageOperations/models/workflow.model.js +23 -0
- package/storageOperations/models/workflow.model.js.map +1 -1
- package/storageOperations/reviewerStorageOperations.js +17 -0
- package/storageOperations/reviewerStorageOperations.js.map +1 -1
- package/storageOperations/workflowStorageOperations.js +19 -0
- package/storageOperations/workflowStorageOperations.js.map +1 -1
- package/types.js +14 -0
- package/types.js.map +1 -1
- package/utils/contentApwSettingsPlugin.js +6 -0
- package/utils/contentApwSettingsPlugin.js.map +1 -1
- package/utils/errors.js +17 -0
- package/utils/errors.js.map +1 -1
- package/utils/fieldResolver.js +12 -2
- package/utils/fieldResolver.js.map +1 -1
- package/utils/resolve.js +3 -0
- package/utils/resolve.js.map +1 -1
package/plugins/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","getValue","object","key","get","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","e","message","code","updateContentReview","getNewContentReviewData","newContentReviewData","update","updateContentReviewStep","steps","updater","map","isInstallationPending","tenancy","i18n","tenant","getCurrentTenant","getContentLocale","WORKFLOW_PRECEDENCE","WorkflowScopeTypes","DEFAULT","CUSTOM","workflowByPrecedenceDesc","a","b","scoreA","scope","scoreB","workflowByCreatedOnDesc","createdOnA","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep,\n ApwWorkflowStepTypes,\n WorkflowScopeTypes\n} from \"~/types\";\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n fieldId?: string;\n parent: string;\n}\n\nexport interface HasReviewersParams {\n identity: SecurityIdentity;\n step: ApwContentReviewStep;\n getReviewer: ApwReviewerCrud[\"get\"];\n}\n\nexport const hasReviewer = async (params: HasReviewersParams): Promise<Boolean> => {\n const { getReviewer, identity, step } = params;\n for (const stepReviewer of step.reviewers) {\n const entry = await getReviewer(stepReviewer.id);\n\n if (entry.identityId === identity.id) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getValue = (object: Record<string, any>, key: string) => {\n return get(object, `values.${key}`);\n};\n\nexport const getContentReviewStepInitialStatus = (\n workflowSteps: ApwWorkflowStep[],\n index: number,\n previousStepStatus?: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n /**\n * Always set first step 'active' by default.\n */\n if (index === 0) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n const previousStep = workflowSteps[index - 1];\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStep.type !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport const getNextStepStatus = (\n previousStepType: ApwWorkflowStepTypes,\n previousStepStatus: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n if (previousStepStatus === ApwContentReviewStepStatus.DONE) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStepType !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport interface ExtractContentReviewIdAndStepResult {\n id: string;\n stepId: string;\n}\n\nexport const extractContentReviewIdAndStep = (\n step: ApwChangeRequest[\"step\"]\n): ExtractContentReviewIdAndStepResult => {\n /*\n * Get associated content review entry.\n */\n const [entryId, version, stepId] = step.split(\"#\");\n const revisionId = `${entryId}#${version}`;\n\n return {\n id: revisionId,\n stepId\n };\n};\n\ntype SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, \"id\" | \"contentReviewMethods\">;\n\nexport const safelyGetContentReview = async ({\n id,\n contentReviewMethods\n}: SafelyGetContentReviewParams): Promise<ApwContentReview | null> => {\n let contentReviewEntry = null;\n try {\n contentReviewEntry = await contentReviewMethods.get(id);\n } catch (e) {\n if (e.message !== \"index_not_found_exception\" && e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n return contentReviewEntry;\n};\n\nexport interface UpdateContentReviewParams {\n id: string;\n contentReviewMethods: ApwContentReviewCrud;\n getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;\n}\n\nexport const updateContentReview = async ({\n contentReviewMethods,\n id,\n getNewContentReviewData\n}: UpdateContentReviewParams): Promise<void> => {\n const contentReviewEntry = await safelyGetContentReview({ id, contentReviewMethods });\n if (contentReviewEntry) {\n const newContentReviewData = getNewContentReviewData(contentReviewEntry);\n /**\n * Update content review entry.\n */\n await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);\n }\n};\n\nexport const updateContentReviewStep = (\n steps: ApwContentReviewStep[],\n stepId: string,\n updater: (step: ApwContentReviewStep) => ApwContentReviewStep\n): ApwContentReviewStep[] => {\n return steps.map(step => {\n if (step.id === stepId) {\n return {\n ...updater(step)\n };\n }\n return step;\n });\n};\n\ntype CheckInstallationParams = Pick<ApwContext, \"tenancy\" | \"i18n\">;\n\nexport const isInstallationPending = ({ tenancy, i18n }: CheckInstallationParams): boolean => {\n /**\n * In case of a fresh webiny project \"tenant\" and \"locale\" won't be there until\n * installation is completed. So, we need to skip \"APW\" creation till then.\n */\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n return true;\n }\n\n return !i18n.getContentLocale();\n};\n\nconst WORKFLOW_PRECEDENCE = {\n [WorkflowScopeTypes.DEFAULT]: 0,\n [WorkflowScopeTypes.CUSTOM]: 1\n};\n\nexport const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];\n const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];\n /**\n * In descending order of workflow precedence.\n */\n return scoreB - scoreA;\n};\n\nexport const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const createdOnA = get(a, \"createdOn\");\n const createdOnB = get(b, \"createdOn\");\n /**\n * In descending order of workflow createdOn i.e. the most recent one first.\n */\n return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();\n};\n"],"mappings":";;;;;;;;AAAA;AAGA;AA0BO,MAAMA,WAAW,GAAG,MAAOC,MAA0B,IAAuB;EAC/E,MAAM;IAAEC,WAAW;IAAEC,QAAQ;IAAEC;EAAK,CAAC,GAAGH,MAAM;EAC9C,KAAK,MAAMI,YAAY,IAAID,IAAI,CAACE,SAAS,EAAE;IACvC,MAAMC,KAAK,GAAG,MAAML,WAAW,CAACG,YAAY,CAACG,EAAE,CAAC;IAEhD,IAAID,KAAK,CAACE,UAAU,KAAKN,QAAQ,CAACK,EAAE,E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EACI,MAAMC,MAAM,GAAGF,OAAO,CAACG,gBAAgB,EAAE;EACzC,IAAI,CAACD,MAAM,EAAE;IACT,OAAO,IAAI;EACf;EAEA,OAAO,CAACD,IAAI,CAACG,gBAAgB,EAAE;AACnC,CAAC;AAAC;AAEF,MAAMC,mBAAmB,GAAG;EACxB,CAACC,yBAAkB,CAACC,OAAO,GAAG,CAAC;EAC/B,CAACD,yBAAkB,CAACE,MAAM,GAAG;AACjC,CAAC;AAEM,MAAMC,wBAAwB,GAAG,CAACC,CAAc,EAAEC,CAAc,KAAK;EACxE,MAAMC,MAAM,GAAGP,mBAAmB,CAACK,CAAC,CAACG,KAAK,CAACzC,IAAI,CAAC;EAChD,MAAM0C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAK,CAACzC,IAAI,CAAC;EAChD;AACJ;AACA;EACI,OAAO0C,MAAM,GAAGF,MAAM;AAC1B,CAAC;AAAC;AAEK,MAAMG,uBAAuB,GAAG,CAACL,CAAc,EAAEC,CAAc,KAAK;EACvE,MAAMK,UAAU,GAAG,IAAApD,YAAG,EAAC8C,CAAC,EAAE,WAAW,CAAC;EACtC,MAAMO,UAAU,GAAG,IAAArD,YAAG,EAAC+C,CAAC,EAAE,WAAW,CAAC;EACtC;AACJ;AACA;EACI,OAAO,IAAIO,IAAI,CAACD,UAAU,CAAC,CAACE,OAAO,EAAE,GAAG,IAAID,IAAI,CAACF,UAAU,CAAC,CAACG,OAAO,EAAE;AAC1E,CAAC;AAAC"}
|
1
|
+
{"version":3,"names":["hasReviewer","params","getReviewer","identity","step","stepReviewer","reviewers","entry","id","identityId","getValue","object","key","get","getContentReviewStepInitialStatus","workflowSteps","index","previousStepStatus","ApwContentReviewStepStatus","ACTIVE","previousStep","type","ApwWorkflowStepTypes","MANDATORY_BLOCKING","INACTIVE","getNextStepStatus","previousStepType","DONE","extractContentReviewIdAndStep","entryId","version","stepId","split","revisionId","safelyGetContentReview","contentReviewMethods","contentReviewEntry","e","message","code","updateContentReview","getNewContentReviewData","newContentReviewData","update","updateContentReviewStep","steps","updater","map","isInstallationPending","tenancy","i18n","tenant","getCurrentTenant","getContentLocale","WORKFLOW_PRECEDENCE","WorkflowScopeTypes","DEFAULT","CUSTOM","workflowByPrecedenceDesc","a","b","scoreA","scope","scoreB","workflowByCreatedOnDesc","createdOnA","createdOnB","Date","getTime"],"sources":["utils.ts"],"sourcesContent":["import get from \"lodash/get\";\nimport { CmsModelField } from \"@webiny/api-headless-cms/types\";\nimport { SecurityIdentity } from \"@webiny/api-security/types\";\nimport {\n ApwChangeRequest,\n ApwContentReview,\n ApwContentReviewCrud,\n ApwContentReviewStep,\n ApwContentReviewStepStatus,\n ApwContext,\n ApwReviewerCrud,\n ApwWorkflow,\n ApwWorkflowStep,\n ApwWorkflowStepTypes,\n WorkflowScopeTypes\n} from \"~/types\";\n\nexport interface CreateModelFieldParams\n extends Omit<CmsModelField, \"id\" | \"storageId\" | \"fieldId\"> {\n fieldId?: string;\n parent: string;\n}\n\nexport interface HasReviewersParams {\n identity: SecurityIdentity;\n step: ApwContentReviewStep;\n getReviewer: ApwReviewerCrud[\"get\"];\n}\n\nexport const hasReviewer = async (params: HasReviewersParams): Promise<Boolean> => {\n const { getReviewer, identity, step } = params;\n for (const stepReviewer of step.reviewers) {\n const entry = await getReviewer(stepReviewer.id);\n\n if (entry.identityId === identity.id) {\n return true;\n }\n }\n\n return false;\n};\n\nexport const getValue = (object: Record<string, any>, key: string) => {\n return get(object, `values.${key}`);\n};\n\nexport const getContentReviewStepInitialStatus = (\n workflowSteps: ApwWorkflowStep[],\n index: number,\n previousStepStatus?: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n /**\n * Always set first step 'active' by default.\n */\n if (index === 0) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n const previousStep = workflowSteps[index - 1];\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStep.type !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport const getNextStepStatus = (\n previousStepType: ApwWorkflowStepTypes,\n previousStepStatus: ApwContentReviewStepStatus\n): ApwContentReviewStepStatus => {\n if (previousStepStatus === ApwContentReviewStepStatus.DONE) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n if (\n previousStepStatus === ApwContentReviewStepStatus.ACTIVE &&\n previousStepType !== ApwWorkflowStepTypes.MANDATORY_BLOCKING\n ) {\n return ApwContentReviewStepStatus.ACTIVE;\n }\n\n return ApwContentReviewStepStatus.INACTIVE;\n};\n\nexport interface ExtractContentReviewIdAndStepResult {\n id: string;\n stepId: string;\n}\n\nexport const extractContentReviewIdAndStep = (\n step: ApwChangeRequest[\"step\"]\n): ExtractContentReviewIdAndStepResult => {\n /*\n * Get associated content review entry.\n */\n const [entryId, version, stepId] = step.split(\"#\");\n const revisionId = `${entryId}#${version}`;\n\n return {\n id: revisionId,\n stepId\n };\n};\n\ntype SafelyGetContentReviewParams = Pick<UpdateContentReviewParams, \"id\" | \"contentReviewMethods\">;\n\nexport const safelyGetContentReview = async ({\n id,\n contentReviewMethods\n}: SafelyGetContentReviewParams): Promise<ApwContentReview | null> => {\n let contentReviewEntry = null;\n try {\n contentReviewEntry = await contentReviewMethods.get(id);\n } catch (e) {\n if (e.message !== \"index_not_found_exception\" && e.code !== \"NOT_FOUND\") {\n throw e;\n }\n }\n\n return contentReviewEntry;\n};\n\nexport interface UpdateContentReviewParams {\n id: string;\n contentReviewMethods: ApwContentReviewCrud;\n getNewContentReviewData: (entry: ApwContentReview) => ApwContentReview;\n}\n\nexport const updateContentReview = async ({\n contentReviewMethods,\n id,\n getNewContentReviewData\n}: UpdateContentReviewParams): Promise<void> => {\n const contentReviewEntry = await safelyGetContentReview({ id, contentReviewMethods });\n if (contentReviewEntry) {\n const newContentReviewData = getNewContentReviewData(contentReviewEntry);\n /**\n * Update content review entry.\n */\n await contentReviewMethods.update(contentReviewEntry.id, newContentReviewData);\n }\n};\n\nexport const updateContentReviewStep = (\n steps: ApwContentReviewStep[],\n stepId: string,\n updater: (step: ApwContentReviewStep) => ApwContentReviewStep\n): ApwContentReviewStep[] => {\n return steps.map(step => {\n if (step.id === stepId) {\n return {\n ...updater(step)\n };\n }\n return step;\n });\n};\n\ntype CheckInstallationParams = Pick<ApwContext, \"tenancy\" | \"i18n\">;\n\nexport const isInstallationPending = ({ tenancy, i18n }: CheckInstallationParams): boolean => {\n /**\n * In case of a fresh webiny project \"tenant\" and \"locale\" won't be there until\n * installation is completed. So, we need to skip \"APW\" creation till then.\n */\n const tenant = tenancy.getCurrentTenant();\n if (!tenant) {\n return true;\n }\n\n return !i18n.getContentLocale();\n};\n\nconst WORKFLOW_PRECEDENCE = {\n [WorkflowScopeTypes.DEFAULT]: 0,\n [WorkflowScopeTypes.CUSTOM]: 1\n};\n\nexport const workflowByPrecedenceDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const scoreA = WORKFLOW_PRECEDENCE[a.scope.type];\n const scoreB = WORKFLOW_PRECEDENCE[b.scope.type];\n /**\n * In descending order of workflow precedence.\n */\n return scoreB - scoreA;\n};\n\nexport const workflowByCreatedOnDesc = (a: ApwWorkflow, b: ApwWorkflow) => {\n const createdOnA = get(a, \"createdOn\");\n const createdOnB = get(b, \"createdOn\");\n /**\n * In descending order of workflow createdOn i.e. the most recent one first.\n */\n return new Date(createdOnB).getTime() - new Date(createdOnA).getTime();\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAGA;;AA0BO,MAAMA,WAAW,GAAG,MAAOC,MAAP,IAAwD;EAC/E,MAAM;IAAEC,WAAF;IAAeC,QAAf;IAAyBC;EAAzB,IAAkCH,MAAxC;;EACA,KAAK,MAAMI,YAAX,IAA2BD,IAAI,CAACE,SAAhC,EAA2C;IACvC,MAAMC,KAAK,GAAG,MAAML,WAAW,CAACG,YAAY,CAACG,EAAd,CAA/B;;IAEA,IAAID,KAAK,CAACE,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C,OAAF;EAAWC;AAAX,CAAD,KAAyD;EAC1F;AACJ;AACA;AACA;EACI,MAAMC,MAAM,GAAGF,OAAO,CAACG,gBAAR,EAAf;;EACA,IAAI,CAACD,MAAL,EAAa;IACT,OAAO,IAAP;EACH;;EAED,OAAO,CAACD,IAAI,CAACG,gBAAL,EAAR;AACH,CAXM;;;AAaP,MAAMC,mBAAmB,GAAG;EACxB,CAACC,yBAAA,CAAmBC,OAApB,GAA8B,CADN;EAExB,CAACD,yBAAA,CAAmBE,MAApB,GAA6B;AAFL,CAA5B;;AAKO,MAAMC,wBAAwB,GAAG,CAACC,CAAD,EAAiBC,CAAjB,KAAoC;EACxE,MAAMC,MAAM,GAAGP,mBAAmB,CAACK,CAAC,CAACG,KAAF,CAAQzC,IAAT,CAAlC;EACA,MAAM0C,MAAM,GAAGT,mBAAmB,CAACM,CAAC,CAACE,KAAF,CAAQzC,IAAT,CAAlC;EACA;AACJ;AACA;;EACI,OAAO0C,MAAM,GAAGF,MAAhB;AACH,CAPM;;;;AASA,MAAMG,uBAAuB,GAAG,CAACL,CAAD,EAAiBC,CAAjB,KAAoC;EACvE,MAAMK,UAAU,GAAG,IAAApD,YAAA,EAAI8C,CAAJ,EAAO,WAAP,CAAnB;EACA,MAAMO,UAAU,GAAG,IAAArD,YAAA,EAAI+C,CAAJ,EAAO,WAAP,CAAnB;EACA;AACJ;AACA;;EACI,OAAO,IAAIO,IAAJ,CAASD,UAAT,EAAqBE,OAArB,KAAiC,IAAID,IAAJ,CAASF,UAAT,EAAqBG,OAArB,EAAxC;AACH,CAPM"}
|
@@ -1,15 +1,22 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
5
6
|
value: true
|
6
7
|
});
|
7
8
|
exports.createScheduleActionMethods = createScheduleActionMethods;
|
9
|
+
|
8
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
11
|
+
|
9
12
|
var _mdbid = _interopRequireDefault(require("mdbid"));
|
13
|
+
|
10
14
|
var _fields = require("@commodo/fields");
|
15
|
+
|
11
16
|
var _validation = require("@webiny/validation");
|
17
|
+
|
12
18
|
var _types = require("./types");
|
19
|
+
|
13
20
|
/**
|
14
21
|
* Package mdbid does not have types.
|
15
22
|
*/
|
@@ -19,7 +26,6 @@ var _types = require("./types");
|
|
19
26
|
* Package @commodo/fields does not have types.
|
20
27
|
*/
|
21
28
|
// @ts-ignore
|
22
|
-
|
23
29
|
const CreateDataModel = (0, _fields.withFields)(instance => {
|
24
30
|
return {
|
25
31
|
datetime: (0, _fields.string)({
|
@@ -41,11 +47,13 @@ const CreateDataModel = (0, _fields.withFields)(instance => {
|
|
41
47
|
} else if (!!value) {
|
42
48
|
return true;
|
43
49
|
}
|
50
|
+
|
44
51
|
throw new Error(`There is no modelId defined when type is "${_types.ApwContentTypes.CMS_ENTRY}"`);
|
45
52
|
}
|
46
53
|
})
|
47
54
|
};
|
48
55
|
})();
|
56
|
+
|
49
57
|
function createScheduleActionMethods({
|
50
58
|
storageOperations,
|
51
59
|
getIdentity,
|
@@ -60,6 +68,7 @@ function createScheduleActionMethods({
|
|
60
68
|
locale
|
61
69
|
};
|
62
70
|
};
|
71
|
+
|
63
72
|
return {
|
64
73
|
async get(id) {
|
65
74
|
return storageOperations.get({
|
@@ -68,11 +77,13 @@ function createScheduleActionMethods({
|
|
68
77
|
}, getTenantAndLocale())
|
69
78
|
});
|
70
79
|
},
|
80
|
+
|
71
81
|
async list(params) {
|
72
82
|
return storageOperations.list((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
73
83
|
where: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params.where), getTenantAndLocale())
|
74
84
|
}));
|
75
85
|
},
|
86
|
+
|
76
87
|
async create(input) {
|
77
88
|
const createDataModel = new CreateDataModel().populate(input);
|
78
89
|
await createDataModel.validate();
|
@@ -95,36 +106,44 @@ function createScheduleActionMethods({
|
|
95
106
|
input
|
96
107
|
});
|
97
108
|
},
|
109
|
+
|
98
110
|
async update(id, data) {
|
99
111
|
const updateDataModel = new CreateDataModel().populate(data);
|
100
112
|
await updateDataModel.validate();
|
101
113
|
const original = await this.get(id);
|
114
|
+
|
102
115
|
if (!original) {
|
103
116
|
throw new Error("Not found!");
|
104
117
|
}
|
118
|
+
|
105
119
|
return await storageOperations.update({
|
106
120
|
item: original,
|
107
121
|
input: data
|
108
122
|
});
|
109
123
|
},
|
124
|
+
|
110
125
|
async delete(id) {
|
111
126
|
await storageOperations.delete((0, _objectSpread2.default)({
|
112
127
|
id
|
113
128
|
}, getTenantAndLocale()));
|
114
129
|
return true;
|
115
130
|
},
|
131
|
+
|
116
132
|
async getCurrentTask() {
|
117
133
|
return await storageOperations.getCurrentTask({
|
118
134
|
where: (0, _objectSpread2.default)({}, getTenantAndLocale())
|
119
135
|
});
|
120
136
|
},
|
137
|
+
|
121
138
|
async updateCurrentTask(item) {
|
122
139
|
return await storageOperations.updateCurrentTask({
|
123
140
|
item
|
124
141
|
});
|
125
142
|
},
|
143
|
+
|
126
144
|
async deleteCurrentTask() {
|
127
145
|
return await storageOperations.deleteCurrentTask((0, _objectSpread2.default)({}, getTenantAndLocale()));
|
128
146
|
}
|
147
|
+
|
129
148
|
};
|
130
149
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["CreateDataModel","withFields","instance","datetime","string","validation","create","type","ApwContentTypes","PAGE","CMS_ENTRY","action","ApwScheduleActionTypes","PUBLISH","UNPUBLISH","entryId","modelId","value","Error","createScheduleActionMethods","storageOperations","getIdentity","getTenant","getLocale","getTenantAndLocale","tenant","id","locale","code","get","where","list","params","input","createDataModel","populate","validate","mdbid","identity","data","toJSON","scheduleAction","createdOn","Date","toISOString","savedOn","createdBy","displayName","item","update","updateDataModel","original","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\n/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { string, withFields } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport {\n ApwContentTypes,\n ApwScheduleAction,\n ApwScheduleActionCrud,\n ApwScheduleActionData,\n ApwScheduleActionTypes,\n CreateScheduleActionParams\n} from \"~/scheduler/types\";\n\nconst CreateDataModel = withFields((instance: any) => {\n return {\n datetime: string({\n validation: validation.create(`required`)\n }),\n type: string({\n validation: validation.create(\n `required,in:${ApwContentTypes.PAGE}:${ApwContentTypes.CMS_ENTRY}`\n )\n }),\n action: string({\n validation: validation.create(\n `required,in:${ApwScheduleActionTypes.PUBLISH}:${ApwScheduleActionTypes.UNPUBLISH}`\n )\n }),\n entryId: string({\n validation: validation.create(`required`)\n }),\n modelId: string({\n validation: (value: string) => {\n if (instance.type !== ApwContentTypes.CMS_ENTRY) {\n return true;\n } else if (!!value) {\n return true;\n }\n throw new Error(\n `There is no modelId defined when type is \"${ApwContentTypes.CMS_ENTRY}\"`\n );\n }\n })\n };\n})();\n\ninterface GetTenantAndLocaleResult {\n tenant: string;\n locale: string;\n}\n\nexport function createScheduleActionMethods({\n storageOperations,\n getIdentity,\n getTenant,\n getLocale\n}: CreateScheduleActionParams): ApwScheduleActionCrud {\n const getTenantAndLocale = (): GetTenantAndLocaleResult => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n return {\n tenant,\n locale\n };\n };\n return {\n async get(id) {\n return storageOperations.get({\n where: {\n id,\n ...getTenantAndLocale()\n }\n });\n },\n async list(params) {\n return storageOperations.list({\n ...params,\n where: {\n ...params.where,\n ...getTenantAndLocale()\n }\n });\n },\n async create(input) {\n const createDataModel = new CreateDataModel().populate(input);\n\n await createDataModel.validate();\n\n const id: string = mdbid();\n const identity = getIdentity();\n\n const data: ApwScheduleActionData = await createDataModel.toJSON();\n\n const scheduleAction: ApwScheduleAction = {\n ...getTenantAndLocale(),\n data,\n id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n return await storageOperations.create({\n item: scheduleAction,\n input\n });\n },\n async update(id, data) {\n const updateDataModel = new CreateDataModel().populate(data);\n\n await updateDataModel.validate();\n\n const original = await this.get(id);\n\n if (!original) {\n throw new Error(\"Not found!\");\n }\n\n return await storageOperations.update({ item: original, input: data });\n },\n async delete(id: string) {\n await storageOperations.delete({ id, ...getTenantAndLocale() });\n\n return true;\n },\n async getCurrentTask() {\n return await storageOperations.getCurrentTask({ where: { ...getTenantAndLocale() } });\n },\n async updateCurrentTask(item) {\n return await storageOperations.updateCurrentTask({ item });\n },\n async deleteCurrentTask() {\n return await storageOperations.deleteCurrentTask({ ...getTenantAndLocale() });\n }\n };\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["CreateDataModel","withFields","instance","datetime","string","validation","create","type","ApwContentTypes","PAGE","CMS_ENTRY","action","ApwScheduleActionTypes","PUBLISH","UNPUBLISH","entryId","modelId","value","Error","createScheduleActionMethods","storageOperations","getIdentity","getTenant","getLocale","getTenantAndLocale","tenant","id","locale","code","get","where","list","params","input","createDataModel","populate","validate","mdbid","identity","data","toJSON","scheduleAction","createdOn","Date","toISOString","savedOn","createdBy","displayName","item","update","updateDataModel","original","delete","getCurrentTask","updateCurrentTask","deleteCurrentTask"],"sources":["createScheduleActionMethods.ts"],"sourcesContent":["/**\n * Package mdbid does not have types.\n */\n// @ts-ignore\nimport mdbid from \"mdbid\";\n/**\n * Package @commodo/fields does not have types.\n */\n// @ts-ignore\nimport { string, withFields } from \"@commodo/fields\";\nimport { validation } from \"@webiny/validation\";\nimport {\n ApwContentTypes,\n ApwScheduleAction,\n ApwScheduleActionCrud,\n ApwScheduleActionData,\n ApwScheduleActionTypes,\n CreateScheduleActionParams\n} from \"~/scheduler/types\";\n\nconst CreateDataModel = withFields((instance: any) => {\n return {\n datetime: string({\n validation: validation.create(`required`)\n }),\n type: string({\n validation: validation.create(\n `required,in:${ApwContentTypes.PAGE}:${ApwContentTypes.CMS_ENTRY}`\n )\n }),\n action: string({\n validation: validation.create(\n `required,in:${ApwScheduleActionTypes.PUBLISH}:${ApwScheduleActionTypes.UNPUBLISH}`\n )\n }),\n entryId: string({\n validation: validation.create(`required`)\n }),\n modelId: string({\n validation: (value: string) => {\n if (instance.type !== ApwContentTypes.CMS_ENTRY) {\n return true;\n } else if (!!value) {\n return true;\n }\n throw new Error(\n `There is no modelId defined when type is \"${ApwContentTypes.CMS_ENTRY}\"`\n );\n }\n })\n };\n})();\n\ninterface GetTenantAndLocaleResult {\n tenant: string;\n locale: string;\n}\n\nexport function createScheduleActionMethods({\n storageOperations,\n getIdentity,\n getTenant,\n getLocale\n}: CreateScheduleActionParams): ApwScheduleActionCrud {\n const getTenantAndLocale = (): GetTenantAndLocaleResult => {\n const tenant = getTenant().id;\n const locale = getLocale().code;\n return {\n tenant,\n locale\n };\n };\n return {\n async get(id) {\n return storageOperations.get({\n where: {\n id,\n ...getTenantAndLocale()\n }\n });\n },\n async list(params) {\n return storageOperations.list({\n ...params,\n where: {\n ...params.where,\n ...getTenantAndLocale()\n }\n });\n },\n async create(input) {\n const createDataModel = new CreateDataModel().populate(input);\n\n await createDataModel.validate();\n\n const id: string = mdbid();\n const identity = getIdentity();\n\n const data: ApwScheduleActionData = await createDataModel.toJSON();\n\n const scheduleAction: ApwScheduleAction = {\n ...getTenantAndLocale(),\n data,\n id,\n createdOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdBy: {\n id: identity.id,\n type: identity.type,\n displayName: identity.displayName\n }\n };\n\n return await storageOperations.create({\n item: scheduleAction,\n input\n });\n },\n async update(id, data) {\n const updateDataModel = new CreateDataModel().populate(data);\n\n await updateDataModel.validate();\n\n const original = await this.get(id);\n\n if (!original) {\n throw new Error(\"Not found!\");\n }\n\n return await storageOperations.update({ item: original, input: data });\n },\n async delete(id: string) {\n await storageOperations.delete({ id, ...getTenantAndLocale() });\n\n return true;\n },\n async getCurrentTask() {\n return await storageOperations.getCurrentTask({ where: { ...getTenantAndLocale() } });\n },\n async updateCurrentTask(item) {\n return await storageOperations.updateCurrentTask({ item });\n },\n async deleteCurrentTask() {\n return await storageOperations.deleteCurrentTask({ ...getTenantAndLocale() });\n }\n };\n}\n"],"mappings":";;;;;;;;;;;AAIA;;AAKA;;AACA;;AACA;;AAXA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAYA,MAAMA,eAAe,GAAG,IAAAC,kBAAA,EAAYC,QAAD,IAAmB;EAClD,OAAO;IACHC,QAAQ,EAAE,IAAAC,cAAA,EAAO;MACbC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAmB,UAAnB;IADC,CAAP,CADP;IAIHC,IAAI,EAAE,IAAAH,cAAA,EAAO;MACTC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CACP,eAAcE,sBAAA,CAAgBC,IAAK,IAAGD,sBAAA,CAAgBE,SAAU,EADzD;IADH,CAAP,CAJH;IASHC,MAAM,EAAE,IAAAP,cAAA,EAAO;MACXC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CACP,eAAcM,6BAAA,CAAuBC,OAAQ,IAAGD,6BAAA,CAAuBE,SAAU,EAD1E;IADD,CAAP,CATL;IAcHC,OAAO,EAAE,IAAAX,cAAA,EAAO;MACZC,UAAU,EAAEA,sBAAA,CAAWC,MAAX,CAAmB,UAAnB;IADA,CAAP,CAdN;IAiBHU,OAAO,EAAE,IAAAZ,cAAA,EAAO;MACZC,UAAU,EAAGY,KAAD,IAAmB;QAC3B,IAAIf,QAAQ,CAACK,IAAT,KAAkBC,sBAAA,CAAgBE,SAAtC,EAAiD;UAC7C,OAAO,IAAP;QACH,CAFD,MAEO,IAAI,CAAC,CAACO,KAAN,EAAa;UAChB,OAAO,IAAP;QACH;;QACD,MAAM,IAAIC,KAAJ,CACD,6CAA4CV,sBAAA,C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,EAA3D,EAAb;IACH;;EAxEE,CAAP;AA0EH"}
|
@@ -4,12 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.executeActionHandlerPlugins = void 0;
|
7
|
+
|
7
8
|
var _utils = require("../utils");
|
9
|
+
|
8
10
|
var _api = require("@webiny/api");
|
11
|
+
|
9
12
|
var _PageBuilderGraphQL = require("./plugins/PageBuilderGraphQL");
|
13
|
+
|
10
14
|
var _HeadlessCMSGraphQL = require("./plugins/HeadlessCMSGraphQL");
|
15
|
+
|
11
16
|
var _ApplicationGraphQL = require("./plugins/ApplicationGraphQL");
|
17
|
+
|
12
18
|
var _handler = require("@webiny/handler");
|
19
|
+
|
13
20
|
/**
|
14
21
|
* Handler that execute the provided action(s) for the schedule action workflow.
|
15
22
|
*/
|
@@ -23,27 +30,35 @@ const createExecuteActionLambda = params => {
|
|
23
30
|
}) => {
|
24
31
|
const log = console.log;
|
25
32
|
const applicationGraphQLPlugins = context.plugins.byType(_ApplicationGraphQL.ApplicationGraphQL.type);
|
33
|
+
|
26
34
|
if (applicationGraphQLPlugins.length === 0) {
|
27
35
|
console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);
|
28
36
|
return;
|
29
37
|
}
|
38
|
+
|
30
39
|
const applicationGraphQLPluginCache = {};
|
40
|
+
|
31
41
|
const getApplicationGraphQLPlugin = data => {
|
32
42
|
const {
|
33
43
|
type
|
34
44
|
} = data;
|
45
|
+
|
35
46
|
if (applicationGraphQLPluginCache[type]) {
|
36
47
|
return applicationGraphQLPluginCache[type];
|
37
48
|
}
|
49
|
+
|
38
50
|
for (const plugin of applicationGraphQLPlugins) {
|
39
51
|
if (!plugin.canUse(data)) {
|
40
52
|
continue;
|
41
53
|
}
|
54
|
+
|
42
55
|
applicationGraphQLPluginCache[type] = plugin;
|
43
56
|
return plugin;
|
44
57
|
}
|
58
|
+
|
45
59
|
return null;
|
46
60
|
};
|
61
|
+
|
47
62
|
try {
|
48
63
|
const apwSettings = await (0, _utils.getApwSettings)();
|
49
64
|
const {
|
@@ -54,14 +69,16 @@ const createExecuteActionLambda = params => {
|
|
54
69
|
/**
|
55
70
|
* If there is no datetime we bail out early.
|
56
71
|
*/
|
72
|
+
|
57
73
|
if (!datetime || typeof datetime !== "string") {
|
58
74
|
log(`Bailing out!!`);
|
59
75
|
return;
|
60
76
|
}
|
61
|
-
|
62
77
|
/**
|
63
78
|
* Get tasks from the DB by datetime.
|
64
79
|
*/
|
80
|
+
|
81
|
+
|
65
82
|
const [items] = await storageOperations.list({
|
66
83
|
where: {
|
67
84
|
tenant,
|
@@ -71,23 +88,28 @@ const createExecuteActionLambda = params => {
|
|
71
88
|
sort: ["datetime_ASC"],
|
72
89
|
limit: 1000
|
73
90
|
});
|
74
|
-
|
75
91
|
/**
|
76
92
|
* Execute all actions.
|
77
93
|
*/
|
94
|
+
|
78
95
|
if (!items || items.length === 0) {
|
79
96
|
return;
|
80
97
|
}
|
98
|
+
|
81
99
|
log(`Found ${items.length} actions.`);
|
100
|
+
|
82
101
|
for (const item of items) {
|
83
102
|
log(`Performing mutation "${item.data.action}" on "${item.data.type}" at "${item.data.datetime}"`);
|
84
103
|
const plugin = getApplicationGraphQLPlugin(item.data);
|
104
|
+
|
85
105
|
if (!plugin) {
|
86
106
|
console.error(`There is no plugin to determine GraphQL endpoint and mutations for type "${item.data.type}".`);
|
87
107
|
console.log(JSON.stringify(item));
|
88
108
|
continue;
|
89
109
|
}
|
110
|
+
|
90
111
|
const name = plugin.getArn(apwSettings);
|
112
|
+
|
91
113
|
if (!name) {
|
92
114
|
console.error(`There is no FunctionName found for type "${item.data.type}".`);
|
93
115
|
console.log(JSON.stringify({
|
@@ -96,14 +118,16 @@ const createExecuteActionLambda = params => {
|
|
96
118
|
}));
|
97
119
|
continue;
|
98
120
|
}
|
121
|
+
|
99
122
|
const body = plugin.getGraphQLBody(item.data);
|
123
|
+
|
100
124
|
if (!body) {
|
101
125
|
console.error(`There is no GraphQL body defined, in the Plugin, for type "${item.data.type}".`);
|
102
126
|
console.log(JSON.stringify(item));
|
103
127
|
continue;
|
104
|
-
}
|
128
|
+
} // Perform the actual action call.
|
129
|
+
|
105
130
|
|
106
|
-
// Perform the actual action call.
|
107
131
|
const response = await context.handlerClient.invoke({
|
108
132
|
name,
|
109
133
|
payload: {
|
@@ -123,21 +147,20 @@ const createExecuteActionLambda = params => {
|
|
123
147
|
},
|
124
148
|
await: true
|
125
149
|
});
|
150
|
+
|
126
151
|
if (response !== null && response !== void 0 && response.body) {
|
127
152
|
console.log(JSON.stringify({
|
128
153
|
body: response.body
|
129
154
|
}, null, 2));
|
130
155
|
continue;
|
131
156
|
}
|
157
|
+
|
132
158
|
console.log(JSON.stringify({
|
133
159
|
response
|
134
|
-
}, null, 2));
|
135
|
-
|
136
|
-
// TODO: Maybe update the status like error in original item in DB.
|
160
|
+
}, null, 2)); // TODO: Maybe update the status like error in original item in DB.
|
137
161
|
}
|
138
162
|
} catch (e) {
|
139
|
-
log("[HANDLER_EXECUTE_ACTION] Error => ", e);
|
140
|
-
// TODO: Maybe update the status like error in original item in DB.
|
163
|
+
log("[HANDLER_EXECUTE_ACTION] Error => ", e); // TODO: Maybe update the status like error in original item in DB.
|
141
164
|
}
|
142
165
|
});
|
143
166
|
};
|
@@ -145,4 +168,5 @@ const createExecuteActionLambda = params => {
|
|
145
168
|
const executeActionHandlerPlugins = config => [new _api.ContextPlugin(async context => {
|
146
169
|
context.plugins.register([new _PageBuilderGraphQL.PageBuilderGraphQL(), new _HeadlessCMSGraphQL.HeadlessCMSGraphQL()]);
|
147
170
|
}), (0, _utils.basePlugins)(), createExecuteActionLambda(config)];
|
171
|
+
|
148
172
|
exports.executeActionHandlerPlugins = executeActionHandlerPlugins;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createExecuteActionLambda","params","storageOperations","createEvent","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","e","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createEvent<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: `/cms/manage/${locale}`,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n if (response?.body) {\n console.log(JSON.stringify({ body: response.body }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (e) {\n log(\"[HANDLER_EXECUTE_ACTION] Error => \", e);\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAqB,IAAK;EACzD,MAAM;IAAEC;EAAkB,CAAC,GAAGD,MAAM;EAEpC,OAAO,IAAAE,oBAAW,EAAc,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IAC5D,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;IAEvB,MAAME,yBAAyB,GAAGH,OAAO,CAACI,OAAO,CAACC,MAAM,CACpDC,sCAAkB,CAACC,IAAI,CAC1B;IAED,IAAIJ,yBAAyB,CAACK,MAAM,KAAK,CAAC,EAAE;MACxCN,OAAO,CAACO,KAAK,CAAE,mEAAkE,CAAC;MAClF;IACJ;IAEA,MAAMC,6BAAiE,GAAG,CAAC,CAAC;IAE5E,MAAMC,2BAA2B,GAC7BC,IAA2B,IACC;MAC5B,MAAM;QAAEL;MAAK,CAAC,GAAGK,IAAI;MACrB,IAAIF,6BAA6B,CAACH,IAAI,CAAC,EAAE;QACrC,OAAOG,6BAA6B,CAACH,IAAI,CAAC;MAC9C;MACA,KAAK,MAAMM,MAAM,IAAIV,yBAAyB,EAAE;QAC5C,IAAI,CAACU,MAAM,CAACC,MAAM,CAACF,IAAI,CAAC,EAAE;UACtB;QACJ;QACAF,6BAA6B,CAACH,IAAI,CAAC,GAAGM,MAAM;QAC5C,OAAOA,MAAM;MACjB;MACA,OAAO,IAAI;IACf,CAAC;IAED,IAAI;MACA,MAAME,WAAW,GAAG,MAAM,IAAAC,qBA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AE,IAAI,EAAE,CAAC,CAAC,CAAC;UAC7D;QACJ;QACAjC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;UAAEM;QAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;;QAElD;MACJ;IACJ,CAAC,CAAC,OAAOU,CAAC,EAAE;MACR9C,GAAG,CAAC,oCAAoC,EAAE8C,CAAC,CAAC;MAC5C;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAMC,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMlD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAAC+C,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,EAAE,EAAE,IAAIC,sCAAkB,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,GAAE,EACb3D,yBAAyB,CAACsD,MAAM,CAAC,CACpC;AAAC"}
|
1
|
+
{"version":3,"names":["createExecuteActionLambda","params","storageOperations","createEvent","payload","context","log","console","applicationGraphQLPlugins","plugins","byType","ApplicationGraphQL","type","length","error","applicationGraphQLPluginCache","getApplicationGraphQLPlugin","data","plugin","canUse","apwSettings","getApwSettings","futureDatetime","datetime","locale","tenant","items","list","where","datetime_startsWith","getIsoStringTillMinutes","sort","limit","item","action","JSON","stringify","name","getArn","settings","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","e","executeActionHandlerPlugins","config","ContextPlugin","register","PageBuilderGraphQL","HeadlessCMSGraphQL","basePlugins"],"sources":["index.ts"],"sourcesContent":["import { ApwScheduleActionData, ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport { getIsoStringTillMinutes, encodeToken, basePlugins } from \"~/scheduler/handlers/utils\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { PageBuilderGraphQL } from \"./plugins/PageBuilderGraphQL\";\nimport { HeadlessCMSGraphQL } from \"./plugins/HeadlessCMSGraphQL\";\nimport { ApplicationGraphQL } from \"./plugins/ApplicationGraphQL\";\nimport { createEvent } from \"@webiny/handler\";\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n futureDatetime?: string;\n}\n\ninterface Configuration {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\n/**\n * Handler that execute the provided action(s) for the schedule action workflow.\n */\nconst createExecuteActionLambda = (params: Configuration) => {\n const { storageOperations } = params;\n\n return createEvent<HandlerArgs>(async ({ payload, context }) => {\n const log = console.log;\n\n const applicationGraphQLPlugins = context.plugins.byType<ApplicationGraphQL>(\n ApplicationGraphQL.type\n );\n\n if (applicationGraphQLPlugins.length === 0) {\n console.error(`There are no plugins to determine GraphQL endpoints or mutations.`);\n return;\n }\n\n const applicationGraphQLPluginCache: Record<string, ApplicationGraphQL> = {};\n\n const getApplicationGraphQLPlugin = (\n data: ApwScheduleActionData\n ): ApplicationGraphQL | null => {\n const { type } = data;\n if (applicationGraphQLPluginCache[type]) {\n return applicationGraphQLPluginCache[type];\n }\n for (const plugin of applicationGraphQLPlugins) {\n if (!plugin.canUse(data)) {\n continue;\n }\n applicationGraphQLPluginCache[type] = plugin;\n return plugin;\n }\n return null;\n };\n\n try {\n const apwSettings = await getApwSettings();\n\n const { futureDatetime: datetime, locale, tenant } = payload;\n /**\n * If there is no datetime we bail out early.\n */\n if (!datetime || typeof datetime !== \"string\") {\n log(`Bailing out!!`);\n return;\n }\n\n /**\n * Get tasks from the DB by datetime.\n */\n const [items] = await storageOperations.list({\n where: {\n tenant,\n locale,\n datetime_startsWith: getIsoStringTillMinutes(datetime)\n },\n sort: [\"datetime_ASC\"],\n limit: 1000\n });\n\n /**\n * Execute all actions.\n */\n if (!items || items.length === 0) {\n return;\n }\n log(`Found ${items.length} actions.`);\n for (const item of items) {\n log(\n `Performing mutation \"${item.data.action}\" on \"${item.data.type}\" at \"${item.data.datetime}\"`\n );\n\n const plugin = getApplicationGraphQLPlugin(item.data);\n if (!plugin) {\n console.error(\n `There is no plugin to determine GraphQL endpoint and mutations for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n const name = plugin.getArn(apwSettings);\n if (!name) {\n console.error(`There is no FunctionName found for type \"${item.data.type}\".`);\n console.log(\n JSON.stringify({\n item,\n settings: apwSettings\n })\n );\n continue;\n }\n\n const body = plugin.getGraphQLBody(item.data);\n\n if (!body) {\n console.error(\n `There is no GraphQL body defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\n continue;\n }\n\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: `/cms/manage/${locale}`,\n headers: {\n [\"content-type\"]: \"application/json\",\n Authorization: encodeToken({\n id: item.id,\n locale: item.locale,\n tenant: item.tenant\n }),\n [\"x-tenant\"]: tenant,\n [\"x-i18n-locale\"]: `default:${locale};content:${locale};`\n },\n body: JSON.stringify(body)\n },\n await: true\n });\n if (response?.body) {\n console.log(JSON.stringify({ body: response.body }, null, 2));\n continue;\n }\n console.log(JSON.stringify({ response }, null, 2));\n\n // TODO: Maybe update the status like error in original item in DB.\n }\n } catch (e) {\n log(\"[HANDLER_EXECUTE_ACTION] Error => \", e);\n // TODO: Maybe update the status like error in original item in DB.\n }\n });\n};\n\nexport const executeActionHandlerPlugins = (config: Configuration) => [\n new ContextPlugin(async context => {\n context.plugins.register([new PageBuilderGraphQL(), new HeadlessCMSGraphQL()]);\n }),\n basePlugins(),\n createExecuteActionLambda(config)\n];\n"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAaA;AACA;AACA;AACA,MAAMA,yBAAyB,GAAIC,MAAD,IAA2B;EACzD,MAAM;IAAEC;EAAF,IAAwBD,MAA9B;EAEA,OAAO,IAAAE,oBAAA,EAAyB,OAAO;IAAEC,OAAF;IAAWC;EAAX,CAAP,KAAgC;IAC5D,MAAMC,G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AIC,sCAAJ,EAAD,EAA2B,IAAIC,sCAAJ,EAA3B,CAAzB;AACH,CAFD,CADkE,EAIlE,IAAAC,kBAAA,GAJkE,EAKlE3D,yBAAyB,CAACsD,MAAD,CALyC,CAA/D"}
|
@@ -1,12 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
5
6
|
value: true
|
6
7
|
});
|
7
8
|
exports.ApplicationGraphQL = void 0;
|
9
|
+
|
8
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
9
12
|
var _Plugin = require("@webiny/plugins/Plugin");
|
13
|
+
|
10
14
|
class ApplicationGraphQL extends _Plugin.Plugin {}
|
15
|
+
|
11
16
|
exports.ApplicationGraphQL = ApplicationGraphQL;
|
12
17
|
(0, _defineProperty2.default)(ApplicationGraphQL, "type", "apw.scheduler.applicationGraphQL");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["ApplicationGraphQL","Plugin"],"sources":["ApplicationGraphQL.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { ApwScheduleActionData } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\n\nexport interface ApplicationGraphQLBody<T = Record<string, any>> {\n query: string;\n variables: T;\n}\n\nexport abstract class ApplicationGraphQL extends Plugin {\n public static override readonly type: string = \"apw.scheduler.applicationGraphQL\";\n\n public abstract canUse(data: ApwScheduleActionData): boolean;\n\n public abstract getArn(settings: ApwSettings): string;\n\n public abstract getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AASO,MAAeA,kBAAf,SAA0CC,cAA1C,CAAiD;;;8BAAlCD,kB,UAC6B,kC"}
|
@@ -1,15 +1,22 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
+
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
5
6
|
value: true
|
6
7
|
});
|
7
8
|
exports.HeadlessCMSGraphQL = void 0;
|
9
|
+
|
8
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11
|
+
|
9
12
|
var _ApplicationGraphQL = require("./ApplicationGraphQL");
|
13
|
+
|
10
14
|
var _types = require("../../../types");
|
15
|
+
|
11
16
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
17
|
+
|
12
18
|
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
19
|
+
|
13
20
|
const META_FIELDS = `
|
14
21
|
title
|
15
22
|
publishedOn
|
@@ -24,6 +31,7 @@ const ERROR_FIELD = `
|
|
24
31
|
message
|
25
32
|
}
|
26
33
|
`;
|
34
|
+
|
27
35
|
const createPublishMutation = modelId => {
|
28
36
|
const ucFirstModelId = (0, _upperFirst.default)(modelId);
|
29
37
|
return `
|
@@ -39,6 +47,7 @@ const createPublishMutation = modelId => {
|
|
39
47
|
}
|
40
48
|
}`;
|
41
49
|
};
|
50
|
+
|
42
51
|
const createUnpublishMutation = modelId => {
|
43
52
|
const ucFirstModelId = (0, _upperFirst.default)(modelId);
|
44
53
|
return `
|
@@ -54,33 +63,41 @@ const createUnpublishMutation = modelId => {
|
|
54
63
|
}
|
55
64
|
}`;
|
56
65
|
};
|
66
|
+
|
57
67
|
class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
58
68
|
constructor(...args) {
|
59
69
|
super(...args);
|
60
70
|
(0, _defineProperty2.default)(this, "name", "apw.scheduler.applicationGraphQL.pageBuilder");
|
61
71
|
}
|
72
|
+
|
62
73
|
canUse(data) {
|
63
74
|
return data.type === _types.ApwContentTypes.CMS_ENTRY;
|
64
75
|
}
|
76
|
+
|
65
77
|
getArn(settings) {
|
66
78
|
return settings.cmsGraphqlFunctionArn;
|
67
79
|
}
|
80
|
+
|
68
81
|
getGraphQLBody(data) {
|
69
82
|
switch (data.action) {
|
70
83
|
case _types.ApwScheduleActionTypes.PUBLISH:
|
71
84
|
return this.getPublishBody(data);
|
85
|
+
|
72
86
|
case _types.ApwScheduleActionTypes.UNPUBLISH:
|
73
87
|
return this.getUnpublishBody(data);
|
88
|
+
|
74
89
|
default:
|
75
90
|
return null;
|
76
91
|
}
|
77
92
|
}
|
93
|
+
|
78
94
|
getPublishBody(data) {
|
79
95
|
if (!data.modelId) {
|
80
96
|
throw new _error.default("Missing model ID in the schedule action data.", "SCHEDULE_ACTION_ERROR", {
|
81
97
|
data
|
82
98
|
});
|
83
99
|
}
|
100
|
+
|
84
101
|
return {
|
85
102
|
query: createPublishMutation(data.modelId),
|
86
103
|
variables: {
|
@@ -88,12 +105,14 @@ class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
|
88
105
|
}
|
89
106
|
};
|
90
107
|
}
|
108
|
+
|
91
109
|
getUnpublishBody(data) {
|
92
110
|
if (!data.modelId) {
|
93
111
|
throw new _error.default("Missing model ID in the schedule action data.", "SCHEDULE_ACTION_ERROR", {
|
94
112
|
data
|
95
113
|
});
|
96
114
|
}
|
115
|
+
|
97
116
|
return {
|
98
117
|
query: createUnpublishMutation(data.modelId),
|
99
118
|
variables: {
|
@@ -101,5 +120,7 @@ class HeadlessCMSGraphQL extends _ApplicationGraphQL.ApplicationGraphQL {
|
|
101
120
|
}
|
102
121
|
};
|
103
122
|
}
|
123
|
+
|
104
124
|
}
|
125
|
+
|
105
126
|
exports.HeadlessCMSGraphQL = HeadlessCMSGraphQL;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","CMS_ENTRY","getArn","settings","cmsGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import { ApplicationGraphQL, ApplicationGraphQLBody } from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionData, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n publishedOn\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.pageBuilder\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.cmsGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":"
|
1
|
+
{"version":3,"names":["META_FIELDS","ERROR_FIELD","createPublishMutation","modelId","ucFirstModelId","upperFirst","createUnpublishMutation","HeadlessCMSGraphQL","ApplicationGraphQL","canUse","data","type","ApwContentTypes","CMS_ENTRY","getArn","settings","cmsGraphqlFunctionArn","getGraphQLBody","action","ApwScheduleActionTypes","PUBLISH","getPublishBody","UNPUBLISH","getUnpublishBody","WebinyError","query","variables","revision","entryId"],"sources":["HeadlessCMSGraphQL.ts"],"sourcesContent":["import { ApplicationGraphQL, ApplicationGraphQLBody } from \"./ApplicationGraphQL\";\nimport { ApwContentTypes, ApwScheduleActionData, ApwScheduleActionTypes } from \"~/scheduler/types\";\nimport { ApwSettings } from \"~/scheduler/handlers/utils\";\nimport WebinyError from \"@webiny/error\";\nimport upperFirst from \"lodash/upperFirst\";\n\nconst META_FIELDS = `\n title\n publishedOn\n version\n locked\n status\n`;\n\nconst ERROR_FIELD = `\n {\n code\n data\n message\n }\n`;\n\nconst createPublishMutation = (modelId: string): string => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsPublish${ucFirstModelId}($revision: ID!) {\n content: publish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\nconst createUnpublishMutation = (modelId: string) => {\n const ucFirstModelId = upperFirst(modelId);\n\n return `\n mutation CmsUnpublish${ucFirstModelId}($revision: ID!) {\n content: unpublish${ucFirstModelId}(revision: $revision) {\n data {\n id\n meta {\n ${META_FIELDS}\n }\n }\n error ${ERROR_FIELD}\n }\n }`;\n};\n\ninterface ApplicationGraphQLBodyVariables {\n revision: string;\n}\n\nexport class HeadlessCMSGraphQL extends ApplicationGraphQL {\n public override name = \"apw.scheduler.applicationGraphQL.pageBuilder\";\n\n public override canUse(data: ApwScheduleActionData): boolean {\n return data.type === ApwContentTypes.CMS_ENTRY;\n }\n\n public override getArn(settings: ApwSettings): string {\n return settings.cmsGraphqlFunctionArn;\n }\n\n public override getGraphQLBody(data: ApwScheduleActionData): ApplicationGraphQLBody | null {\n switch (data.action) {\n case ApwScheduleActionTypes.PUBLISH:\n return this.getPublishBody(data);\n case ApwScheduleActionTypes.UNPUBLISH:\n return this.getUnpublishBody(data);\n default:\n return null;\n }\n }\n\n private getPublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createPublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n\n private getUnpublishBody(\n data: ApwScheduleActionData\n ): ApplicationGraphQLBody<ApplicationGraphQLBodyVariables> {\n if (!data.modelId) {\n throw new WebinyError(\n \"Missing model ID in the schedule action data.\",\n \"SCHEDULE_ACTION_ERROR\",\n {\n data\n }\n );\n }\n return {\n query: createUnpublishMutation(data.modelId),\n variables: {\n revision: data.entryId\n }\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AAEA,MAAMA,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CANA;AAQA,MAAMC,WAAW,GAAI;AACrB;AACA;AACA;AACA;AACA;AACA,CANA;;AAQA,MAAMC,qBAAqB,GAAIC,OAAD,IAA6B;EACvD,MAAMC,cAAc,GAAG,IAAAC,mBAAA,EAAWF,OAAX,CAAvB;EAEA,OAAQ;AACZ,6BAA6BC,cAAe;AAC5C,8BAA8BA,cAAe;AAC7C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAXI;AAYH,CAfD;;AAiBA,MAAMK,uBAAuB,GAAIH,OAAD,IAAqB;EACjD,MAAMC,cAAc,GAAG,IAAAC,mBAAA,EAAWF,OAAX,CAAvB;EAEA,OAAQ;AACZ,+BAA+BC,cAAe;AAC9C,gCAAgCA,cAAe;AAC/C;AACA;AACA;AACA,0BAA0BJ,WAAY;AACtC;AACA;AACA,wBAAwBC,WAAY;AACpC;AACA,UAXI;AAYH,CAfD;;AAqBO,MAAMM,kBAAN,SAAiCC,sCAAjC,CAAoD;EAAA;IAAA;IAAA,4CAChC,8CADgC;EAAA;;EAGvCC,MAAM,CAACC,IAAD,EAAuC;IACzD,OAAOA,IAAI,CAACC,IAAL,KAAcC,sBAAA,CAAgBC,SAArC;EACH;;EAEeC,MAAM,CA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