@webiny/api-apw 0.0.0-unstable.d16f688daf → 0.0.0-unstable.d7f521b032
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 +0 -10
- package/ApwChangeRequestNotification.js.map +1 -1
- package/ApwCommentNotification.js +0 -10
- package/ApwCommentNotification.js.map +1 -1
- package/ApwContentReviewNotification.js +0 -10
- package/ApwContentReviewNotification.js.map +1 -1
- package/ApwContentUrlPlugin.js +0 -10
- package/ApwContentUrlPlugin.js.map +1 -1
- package/ContentApwSettingsPlugin.js +0 -5
- package/ContentApwSettingsPlugin.js.map +1 -1
- package/crud/createChangeRequestMethods.js +4 -11
- package/crud/createChangeRequestMethods.js.map +1 -1
- package/crud/createCommentMethods.js +4 -12
- package/crud/createCommentMethods.js.map +1 -1
- package/crud/createContentReviewMethods.js +20 -84
- package/crud/createContentReviewMethods.js.map +1 -1
- package/crud/createReviewerMethods.js +4 -12
- package/crud/createReviewerMethods.js.map +1 -1
- package/crud/createWorkflowMethods.js +4 -17
- package/crud/createWorkflowMethods.js.map +1 -1
- package/crud/index.js +0 -25
- package/crud/index.js.map +1 -1
- package/crud/utils.js +0 -28
- package/crud/utils.js.map +1 -1
- package/index.d.ts +1 -2
- package/index.js +1 -15
- package/index.js.map +1 -1
- package/package.json +34 -34
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js +0 -15
- package/plugins/cms/CmsEntryApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/cms/apwEntryPlugins.js +0 -8
- package/plugins/cms/apwEntryPlugins.js.map +1 -1
- package/plugins/cms/index.js +0 -13
- package/plugins/cms/index.js.map +1 -1
- package/plugins/cms/linkContentReviewToEntry.js +0 -17
- package/plugins/cms/linkContentReviewToEntry.js.map +1 -1
- package/plugins/cms/linkWorkflowToEntry.js +2 -31
- package/plugins/cms/linkWorkflowToEntry.js.map +1 -1
- package/plugins/cms/notifications/changeRequestNotification.js +0 -4
- package/plugins/cms/notifications/changeRequestNotification.js.map +1 -1
- package/plugins/cms/notifications/commentNotification.js +0 -4
- package/plugins/cms/notifications/commentNotification.js.map +1 -1
- package/plugins/cms/notifications/contentReviewNotification.js +0 -4
- package/plugins/cms/notifications/contentReviewNotification.js.map +1 -1
- package/plugins/cms/notifications/contentUrl.js +1 -8
- package/plugins/cms/notifications/contentUrl.js.map +1 -1
- package/plugins/cms/triggerContentReview.js +0 -14
- package/plugins/cms/triggerContentReview.js.map +1 -1
- package/plugins/cms/updateContentReviewStatus.js +0 -18
- package/plugins/cms/updateContentReviewStatus.js.map +1 -1
- package/plugins/cms/utils.js +2 -47
- package/plugins/cms/utils.js.map +1 -1
- package/plugins/context.d.ts +0 -1
- package/plugins/context.js +2 -47
- package/plugins/context.js.map +1 -1
- package/plugins/graphql/changeRequest.gql.js +1 -8
- package/plugins/graphql/changeRequest.gql.js.map +1 -1
- package/plugins/graphql/comment.gql.js +1 -8
- package/plugins/graphql/comment.gql.js.map +1 -1
- package/plugins/graphql/contentReview.gql.js +1 -20
- package/plugins/graphql/contentReview.gql.js.map +1 -1
- package/plugins/graphql/reviewer.gql.js +1 -8
- package/plugins/graphql/reviewer.gql.js.map +1 -1
- package/plugins/graphql/workflow.gql.js +1 -8
- package/plugins/graphql/workflow.gql.js.map +1 -1
- package/plugins/graphql.js +2 -17
- package/plugins/graphql.js.map +1 -1
- package/plugins/hooks/createReviewerFromIdentity.js +2 -11
- package/plugins/hooks/createReviewerFromIdentity.js.map +1 -1
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js +1 -9
- package/plugins/hooks/deleteChangeRequestsAfterContentReview.js.map +1 -1
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js +1 -8
- package/plugins/hooks/deleteCommentsAfterChangeRequest.js.map +1 -1
- package/plugins/hooks/index.js +0 -14
- package/plugins/hooks/index.js.map +1 -1
- package/plugins/hooks/initializeContentReviewSteps.js +10 -17
- package/plugins/hooks/initializeContentReviewSteps.js.map +1 -1
- package/plugins/hooks/initializeNotifications.js +0 -5
- package/plugins/hooks/initializeNotifications.js.map +1 -1
- package/plugins/hooks/listContentReviews.js +0 -12
- package/plugins/hooks/listContentReviews.js.map +1 -1
- package/plugins/hooks/notifications/appUrl.js +0 -4
- package/plugins/hooks/notifications/appUrl.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestAfterCreate.js +0 -28
- package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/changeRequestUrl.js +0 -4
- package/plugins/hooks/notifications/changeRequestUrl.js.map +1 -1
- package/plugins/hooks/notifications/commentAfterCreate.js +0 -30
- package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/commentUrl.js +0 -4
- package/plugins/hooks/notifications/commentUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewAfterCreate.js +1 -24
- package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
- package/plugins/hooks/notifications/contentReviewUrl.js +0 -4
- package/plugins/hooks/notifications/contentReviewUrl.js.map +1 -1
- package/plugins/hooks/notifications/contentUrl.js +0 -5
- package/plugins/hooks/notifications/contentUrl.js.map +1 -1
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js +0 -4
- package/plugins/hooks/notifications/lastChangeRequestNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js +0 -4
- package/plugins/hooks/notifications/lastCommentNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js +0 -4
- package/plugins/hooks/notifications/lastContentReviewNotificationPlugin.js.map +1 -1
- package/plugins/hooks/notifications/reviewers.js +0 -7
- package/plugins/hooks/notifications/reviewers.js.map +1 -1
- package/plugins/hooks/notifications/sendChangeRequestNotification.js +0 -11
- package/plugins/hooks/notifications/sendChangeRequestNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendCommentNotification.js +0 -11
- package/plugins/hooks/notifications/sendCommentNotification.js.map +1 -1
- package/plugins/hooks/notifications/sendContentReviewNotification.js +0 -11
- package/plugins/hooks/notifications/sendContentReviewNotification.js.map +1 -1
- package/plugins/hooks/updatePendingChangeRequests.js +0 -8
- package/plugins/hooks/updatePendingChangeRequests.js.map +1 -1
- package/plugins/hooks/updateTotalComments.js +0 -9
- package/plugins/hooks/updateTotalComments.js.map +1 -1
- package/plugins/hooks/validateChangeRequest.js +0 -16
- package/plugins/hooks/validateChangeRequest.js.map +1 -1
- package/plugins/hooks/validateComment.js +1 -12
- package/plugins/hooks/validateComment.js.map +1 -1
- package/plugins/hooks/validateContentReview.js +0 -6
- package/plugins/hooks/validateContentReview.js.map +1 -1
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js +0 -15
- package/plugins/pageBuilder/PageApwSettingsGetterPlugin.js.map +1 -1
- package/plugins/pageBuilder/apwContentPagePlugins.js +0 -4
- package/plugins/pageBuilder/apwContentPagePlugins.js.map +1 -1
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js +1 -6
- package/plugins/pageBuilder/extendPbPageSettingsSchema.js.map +1 -1
- package/plugins/pageBuilder/index.js +0 -11
- package/plugins/pageBuilder/index.js.map +1 -1
- package/plugins/pageBuilder/linkContentReviewToPage.js +0 -16
- package/plugins/pageBuilder/linkContentReviewToPage.js.map +1 -1
- package/plugins/pageBuilder/linkWorkflowToPage.js +1 -31
- package/plugins/pageBuilder/linkWorkflowToPage.js.map +1 -1
- package/plugins/pageBuilder/notifications/changeRequestNotification.js +0 -4
- package/plugins/pageBuilder/notifications/changeRequestNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/commentNotification.js +0 -4
- package/plugins/pageBuilder/notifications/commentNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/contentReviewNotification.js +0 -4
- package/plugins/pageBuilder/notifications/contentReviewNotification.js.map +1 -1
- package/plugins/pageBuilder/notifications/contentUrl.js +1 -7
- package/plugins/pageBuilder/notifications/contentUrl.js.map +1 -1
- package/plugins/pageBuilder/triggerContentReview.js +0 -11
- package/plugins/pageBuilder/triggerContentReview.js.map +1 -1
- package/plugins/pageBuilder/updateContentReviewStatus.js +0 -12
- package/plugins/pageBuilder/updateContentReviewStatus.js.map +1 -1
- package/plugins/pageBuilder/utils.js +1 -35
- package/plugins/pageBuilder/utils.js.map +1 -1
- package/plugins/utils.js +0 -43
- package/plugins/utils.js.map +1 -1
- package/scheduler/createScheduleActionMethods.js +1 -20
- package/scheduler/createScheduleActionMethods.js.map +1 -1
- package/scheduler/handlers/executeAction/index.d.ts +1 -1
- package/scheduler/handlers/executeAction/index.js +19 -34
- package/scheduler/handlers/executeAction/index.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.d.ts +6 -0
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js +14 -5
- package/scheduler/handlers/executeAction/plugins/ApplicationGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.d.ts +2 -3
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js +7 -23
- package/scheduler/handlers/executeAction/plugins/HeadlessCMSGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.d.ts +2 -2
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js +7 -86
- package/scheduler/handlers/executeAction/plugins/PageBuilderGraphQL.js.map +1 -1
- package/scheduler/handlers/executeAction/security.js +0 -11
- package/scheduler/handlers/executeAction/security.js.map +1 -1
- package/scheduler/handlers/scheduleAction/index.d.ts +1 -1
- package/scheduler/handlers/scheduleAction/index.js +5 -25
- package/scheduler/handlers/scheduleAction/index.js.map +1 -1
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -23
- package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
- package/scheduler/handlers/utils.d.ts +1 -2
- package/scheduler/handlers/utils.js +3 -41
- package/scheduler/handlers/utils.js.map +1 -1
- package/scheduler/index.js +0 -3
- package/scheduler/index.js.map +1 -1
- package/scheduler/types.js +0 -6
- package/scheduler/types.js.map +1 -1
- package/storageOperations/changeRequestStorageOperations.js +0 -19
- package/storageOperations/changeRequestStorageOperations.js.map +1 -1
- package/storageOperations/commentStorageOperations.js +0 -21
- package/storageOperations/commentStorageOperations.js.map +1 -1
- package/storageOperations/contentReviewStorageOperations.js +0 -17
- package/storageOperations/contentReviewStorageOperations.js.map +1 -1
- package/storageOperations/index.js +0 -14
- package/storageOperations/index.js.map +1 -1
- package/storageOperations/models/changeRequest.model.js +0 -9
- package/storageOperations/models/changeRequest.model.js.map +1 -1
- package/storageOperations/models/comment.model.js +0 -8
- package/storageOperations/models/comment.model.js.map +1 -1
- package/storageOperations/models/contentModelPluginFactory.d.ts +0 -7
- package/storageOperations/models/contentModelPluginFactory.js +1 -10
- package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
- package/storageOperations/models/contentReview.model.js +0 -26
- package/storageOperations/models/contentReview.model.js.map +1 -1
- package/storageOperations/models/index.js +2 -26
- package/storageOperations/models/index.js.map +1 -1
- package/storageOperations/models/reviewer.model.js +0 -8
- package/storageOperations/models/reviewer.model.js.map +1 -1
- package/storageOperations/models/utils.js +0 -4
- package/storageOperations/models/utils.js.map +1 -1
- package/storageOperations/models/workflow.model.js +0 -23
- package/storageOperations/models/workflow.model.js.map +1 -1
- package/storageOperations/reviewerStorageOperations.js +0 -17
- package/storageOperations/reviewerStorageOperations.js.map +1 -1
- package/storageOperations/workflowStorageOperations.js +0 -19
- package/storageOperations/workflowStorageOperations.js.map +1 -1
- package/types.js +0 -14
- package/types.js.map +1 -1
- package/utils/contentApwSettingsPlugin.js +0 -6
- package/utils/contentApwSettingsPlugin.js.map +1 -1
- package/utils/errors.js +0 -17
- package/utils/errors.js.map +1 -1
- package/utils/fieldResolver.js +2 -12
- package/utils/fieldResolver.js.map +1 -1
- package/utils/resolve.d.ts +1 -1
- package/utils/resolve.js +0 -3
- package/utils/resolve.js.map +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["InvocationTypes","log","console","createScheduleActionLambda","params","cwClient","cloudWatchEventClient","storageOperations","handlers","createRawEventHandler","payload","context","lambdaContext","eventContext","locale","tenant","invocationType","SCHEDULED","executeTask","args","lambdaName","executeAction","handlerClient","currentTask","getCurrentTask","where","nextItem","list","sort","limit","nextTaskDatetime","data","datetime","currentTaskDatetime","isDateTimeInNextCentury","shouldScheduleTask","futureDatetime","moveDateTimeToNextCentury","update","item","input","shouldRestoreDatetime","restoreDateTime","task","scheduleLambdaExecution","invokedFunctionArn","updateCurrentTask","ex","scheduleActionHandlerPlugins","config","basePlugins"],"sources":["index.ts"],"sourcesContent":["/**\n * This logic/file should be moved somewhere else as it is relying on AWS specific stuff.\n */\nimport { ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport {\n isDateTimeInNextCentury,\n moveDateTimeToNextCentury,\n shouldRestoreDatetime,\n basePlugins\n} from \"~/scheduler/handlers/utils\";\nimport {\n executeTask,\n shouldScheduleTask,\n restoreDateTime,\n scheduleLambdaExecution\n} from \"./scheduleAction.utils\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n invocationType?: InvocationTypes;\n futureDatetime?: string;\n}\n\nexport interface Configuration {\n cwClient: any;\n storageOperations: ApwScheduleActionStorageOperations;\n handlers: {\n executeAction: string;\n };\n}\n\nconst log = console.log;\n\n/**\n * Handler that creates a cloudwatch event rule for the schedule action workflow.\n */\nconst createScheduleActionLambda = (params: Configuration) => {\n const { cwClient: cloudWatchEventClient, storageOperations, handlers } = params;\n\n return createRawEventHandler<HandlerArgs>(\n async ({ payload, context, lambdaContext: eventContext }) => {\n try {\n const { locale, tenant, invocationType } = payload;\n /**\n * If invocationType is \"scheduled\", execute the action.\n */\n if (invocationType === InvocationTypes.SCHEDULED) {\n await executeTask({\n args: payload,\n lambdaName: handlers.executeAction,\n handlerClient: context.handlerClient,\n storageOperations\n });\n }\n\n /**\n * Get current scheduled task from the DB.\n */\n const currentTask = await storageOperations.getCurrentTask({\n where: {\n tenant,\n locale\n }\n });\n\n /**\n * Get next task from the DB.\n */\n const [[nextItem]] = await storageOperations.list({\n where: {\n tenant,\n locale\n },\n sort: [\"datetime_ASC\"],\n limit: 1\n });\n\n if (!nextItem) {\n log(`No item found.`);\n return;\n }\n\n const nextTaskDatetime = nextItem.data.datetime;\n const currentTaskDatetime = currentTask && currentTask.data.datetime;\n\n if (isDateTimeInNextCentury(nextTaskDatetime)) {\n log(`Already processed the task.`);\n return;\n }\n\n if (!shouldScheduleTask(nextTaskDatetime, currentTaskDatetime)) {\n log(`Already scheduled the task.`);\n return;\n }\n\n const futureDatetime = moveDateTimeToNextCentury(nextItem.data.datetime);\n /**\n * Update \"datetime\" to a future date to mark it as scheduled.\n */\n log(`Update task's datetime to `, futureDatetime);\n await storageOperations.update({\n item: {\n ...nextItem,\n data: { ...nextItem.data, datetime: futureDatetime }\n },\n input: { ...nextItem.data, datetime: futureDatetime }\n });\n /**\n * Restore \"datetime\" of current task so that it can be schedule in next cycle.\n */\n if (\n currentTaskDatetime &&\n shouldRestoreDatetime({\n invocationType,\n datetime: currentTaskDatetime\n })\n ) {\n await restoreDateTime({\n tenant,\n locale,\n task: currentTask,\n storageOperations\n });\n }\n /**\n * Schedule Lambda\n */\n log(`Schedule Lambda Execution...`);\n await scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn: eventContext.invokedFunctionArn,\n datetime: nextItem.data.datetime,\n futureDatetime: futureDatetime,\n tenant,\n locale\n });\n /**\n * Update current task.\n */\n await storageOperations.updateCurrentTask({ item: nextItem });\n } catch (ex) {\n log(\"[HANDLER_CREATE_RULE] Error => \", ex);\n // TODO: Handler error. Maybe save it into DB.\n }\n }\n );\n};\n\nexport const scheduleActionHandlerPlugins = (config: Configuration) => [\n basePlugins(),\n createScheduleActionLambda(config)\n];\n"],"mappings":"
|
1
|
+
{"version":3,"names":["InvocationTypes","log","console","createScheduleActionLambda","params","cwClient","cloudWatchEventClient","storageOperations","handlers","createRawEventHandler","payload","context","lambdaContext","eventContext","locale","tenant","invocationType","SCHEDULED","executeTask","args","lambdaName","executeAction","handlerClient","currentTask","getCurrentTask","where","nextItem","list","sort","limit","nextTaskDatetime","data","datetime","currentTaskDatetime","isDateTimeInNextCentury","shouldScheduleTask","futureDatetime","moveDateTimeToNextCentury","update","item","input","shouldRestoreDatetime","restoreDateTime","task","scheduleLambdaExecution","invokedFunctionArn","updateCurrentTask","ex","scheduleActionHandlerPlugins","config","basePlugins"],"sources":["index.ts"],"sourcesContent":["/**\n * This logic/file should be moved somewhere else as it is relying on AWS specific stuff.\n */\nimport { ApwScheduleActionStorageOperations } from \"~/scheduler/types\";\nimport {\n isDateTimeInNextCentury,\n moveDateTimeToNextCentury,\n shouldRestoreDatetime,\n basePlugins\n} from \"~/scheduler/handlers/utils\";\nimport {\n executeTask,\n shouldScheduleTask,\n restoreDateTime,\n scheduleLambdaExecution\n} from \"./scheduleAction.utils\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\nexport interface HandlerArgs {\n datetime: string;\n tenant: string;\n locale: string;\n invocationType?: InvocationTypes;\n futureDatetime?: string;\n}\n\nexport interface Configuration {\n cwClient: any;\n storageOperations: ApwScheduleActionStorageOperations;\n handlers: {\n executeAction: string;\n };\n}\n\nconst log = console.log;\n\n/**\n * Handler that creates a cloudwatch event rule for the schedule action workflow.\n */\nconst createScheduleActionLambda = (params: Configuration) => {\n const { cwClient: cloudWatchEventClient, storageOperations, handlers } = params;\n\n return createRawEventHandler<HandlerArgs>(\n async ({ payload, context, lambdaContext: eventContext }) => {\n try {\n const { locale, tenant, invocationType } = payload;\n /**\n * If invocationType is \"scheduled\", execute the action.\n */\n if (invocationType === InvocationTypes.SCHEDULED) {\n await executeTask({\n args: payload,\n lambdaName: handlers.executeAction,\n handlerClient: context.handlerClient,\n storageOperations\n });\n }\n\n /**\n * Get current scheduled task from the DB.\n */\n const currentTask = await storageOperations.getCurrentTask({\n where: {\n tenant,\n locale\n }\n });\n\n /**\n * Get next task from the DB.\n */\n const [[nextItem]] = await storageOperations.list({\n where: {\n tenant,\n locale\n },\n sort: [\"datetime_ASC\"],\n limit: 1\n });\n\n if (!nextItem) {\n log(`No item found.`);\n return;\n }\n\n const nextTaskDatetime = nextItem.data.datetime;\n const currentTaskDatetime = currentTask && currentTask.data.datetime;\n\n if (isDateTimeInNextCentury(nextTaskDatetime)) {\n log(`Already processed the task.`);\n return;\n }\n\n if (!shouldScheduleTask(nextTaskDatetime, currentTaskDatetime)) {\n log(`Already scheduled the task.`);\n return;\n }\n\n const futureDatetime = moveDateTimeToNextCentury(nextItem.data.datetime);\n /**\n * Update \"datetime\" to a future date to mark it as scheduled.\n */\n log(`Update task's datetime to `, futureDatetime);\n await storageOperations.update({\n item: {\n ...nextItem,\n data: { ...nextItem.data, datetime: futureDatetime }\n },\n input: { ...nextItem.data, datetime: futureDatetime }\n });\n /**\n * Restore \"datetime\" of current task so that it can be schedule in next cycle.\n */\n if (\n currentTaskDatetime &&\n shouldRestoreDatetime({\n invocationType,\n datetime: currentTaskDatetime\n })\n ) {\n await restoreDateTime({\n tenant,\n locale,\n task: currentTask,\n storageOperations\n });\n }\n /**\n * Schedule Lambda\n */\n log(`Schedule Lambda Execution...`);\n await scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn: eventContext.invokedFunctionArn,\n datetime: nextItem.data.datetime,\n futureDatetime: futureDatetime,\n tenant,\n locale\n });\n /**\n * Update current task.\n */\n await storageOperations.updateCurrentTask({ item: nextItem });\n } catch (ex) {\n log(\"[HANDLER_CREATE_RULE] Error => \", ex);\n // TODO: Handler error. Maybe save it into DB.\n }\n }\n );\n};\n\nexport const scheduleActionHandlerPlugins = (config: Configuration) => [\n basePlugins(),\n createScheduleActionLambda(config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MACJ,CAAC,CAAC;MACF;AAChB;AACA;MACgB,MAAMP,iBAAiB,CAACuC,iBAAiB,CAAC;QAAEP,IAAI,EAAEb;MAAS,CAAC,CAAC;IACjE,CAAC,CAAC,OAAOqB,EAAE,EAAE;MACT9C,GAAG,CAAC,iCAAiC,EAAE8C,EAAE,CAAC;MAC1C;IACJ;EACJ,CAAC,CACJ;AACL,CAAC;;AAEM,MAAMC,4BAA4B,GAAIC,MAAqB,IAAK,CACnE,IAAAC,kBAAW,GAAE,EACb/C,0BAA0B,CAAC8C,MAAM,CAAC,CACrC;AAAC"}
|
@@ -1,24 +1,17 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.restoreDateTime = exports.executeTask = void 0;
|
9
8
|
exports.scheduleLambdaExecution = scheduleLambdaExecution;
|
10
9
|
exports.shouldScheduleTask = void 0;
|
11
|
-
|
12
10
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
13
|
-
|
14
11
|
var _utils = require("../utils");
|
15
|
-
|
16
12
|
var _index = require("./index");
|
17
|
-
|
18
13
|
var _clientCloudwatchEvents = require("@aws-sdk/client-cloudwatch-events");
|
19
|
-
|
20
14
|
const log = console.log;
|
21
|
-
|
22
15
|
/**
|
23
16
|
* Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;
|
24
17
|
* in case of scheduling becoming the most frequently used feature.
|
@@ -39,7 +32,6 @@ async function scheduleLambdaExecution({
|
|
39
32
|
/**
|
40
33
|
* Remove the target
|
41
34
|
*/
|
42
|
-
|
43
35
|
const removeTargetsCommand = new _clientCloudwatchEvents.RemoveTargetsCommand({
|
44
36
|
Rule: eventRuleName,
|
45
37
|
Ids: [eventTargetId]
|
@@ -48,7 +40,6 @@ async function scheduleLambdaExecution({
|
|
48
40
|
/**
|
49
41
|
* Log error.
|
50
42
|
*/
|
51
|
-
|
52
43
|
if (typeof removeTargetsResponse.FailedEntryCount === "number" && removeTargetsResponse.FailedEntryCount !== 0) {
|
53
44
|
console.info("Failed in removing the targets!");
|
54
45
|
console.info(removeTargetsResponse.FailedEntries);
|
@@ -56,18 +47,16 @@ async function scheduleLambdaExecution({
|
|
56
47
|
/**
|
57
48
|
* Delete the Rule
|
58
49
|
*/
|
59
|
-
|
60
|
-
|
61
50
|
const deleteRuleCommand = new _clientCloudwatchEvents.DeleteRuleCommand({
|
62
51
|
Name: eventRuleName
|
63
52
|
});
|
64
53
|
await cloudWatchEventClient.send(deleteRuleCommand);
|
54
|
+
|
65
55
|
/**
|
66
56
|
* Create a new one.
|
67
57
|
* Min H D M DW Y
|
68
58
|
* 20 10 10 03 * 2022
|
69
59
|
*/
|
70
|
-
|
71
60
|
const cronExpression = (0, _utils.dateTimeToCronExpression)(datetime);
|
72
61
|
const ruleParams = {
|
73
62
|
Name: eventRuleName,
|
@@ -79,7 +68,6 @@ async function scheduleLambdaExecution({
|
|
79
68
|
/**
|
80
69
|
* Add lambda as target for the rule.
|
81
70
|
*/
|
82
|
-
|
83
71
|
await cloudWatchEventClient.send(new _clientCloudwatchEvents.PutTargetsCommand({
|
84
72
|
Rule: eventRuleName,
|
85
73
|
Targets: [{
|
@@ -95,13 +83,10 @@ async function scheduleLambdaExecution({
|
|
95
83
|
}]
|
96
84
|
}));
|
97
85
|
}
|
98
|
-
|
99
86
|
const shouldScheduleTask = (nextTaskDatetime, currentTaskDatetime) => {
|
100
87
|
return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;
|
101
88
|
};
|
102
|
-
|
103
89
|
exports.shouldScheduleTask = shouldScheduleTask;
|
104
|
-
|
105
90
|
const restoreDateTime = async ({
|
106
91
|
locale,
|
107
92
|
tenant,
|
@@ -116,7 +101,6 @@ const restoreDateTime = async ({
|
|
116
101
|
id: currentTask.id
|
117
102
|
}
|
118
103
|
});
|
119
|
-
|
120
104
|
if (item) {
|
121
105
|
const newDateTime = (0, _utils.moveDateTimeToCurrentCentury)(item.data.datetime);
|
122
106
|
await storageOperations.update({
|
@@ -131,9 +115,7 @@ const restoreDateTime = async ({
|
|
131
115
|
});
|
132
116
|
}
|
133
117
|
};
|
134
|
-
|
135
118
|
exports.restoreDateTime = restoreDateTime;
|
136
|
-
|
137
119
|
const executeTask = async ({
|
138
120
|
args,
|
139
121
|
lambdaName,
|
@@ -141,7 +123,6 @@ const executeTask = async ({
|
|
141
123
|
storageOperations
|
142
124
|
}) => {
|
143
125
|
log(`Executing task at: `, new Date().toISOString());
|
144
|
-
|
145
126
|
if (typeof handlerClient.invoke === "function") {
|
146
127
|
await handlerClient.invoke({
|
147
128
|
name: lambdaName,
|
@@ -154,11 +135,10 @@ const executeTask = async ({
|
|
154
135
|
await: false
|
155
136
|
});
|
156
137
|
}
|
138
|
+
|
157
139
|
/**
|
158
140
|
* Delete current schedule Task. So that, we can schedule a new one later.
|
159
141
|
*/
|
160
|
-
|
161
|
-
|
162
142
|
try {
|
163
143
|
await storageOperations.deleteCurrentTask({
|
164
144
|
tenant: args.tenant,
|
@@ -168,5 +148,4 @@ const executeTask = async ({
|
|
168
148
|
console.error(e);
|
169
149
|
}
|
170
150
|
};
|
171
|
-
|
172
151
|
exports.executeTask = executeTask;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["log","console","scheduleLambdaExecution","cloudWatchEventClient","invokedFunctionArn","datetime","futureDatetime","tenant","locale","eventTargetId","eventRuleName","getApwSettings","removeTargetsCommand","RemoveTargetsCommand","Rule","Ids","removeTargetsResponse","send","FailedEntryCount","info","FailedEntries","deleteRuleCommand","DeleteRuleCommand","Name","cronExpression","dateTimeToCronExpression","ruleParams","ScheduleExpression","State","Description","PutRuleCommand","PutTargetsCommand","Targets","Arn","Id","Input","JSON","stringify","invocationType","InvocationTypes","SCHEDULED","shouldScheduleTask","nextTaskDatetime","currentTaskDatetime","restoreDateTime","task","currentTask","storageOperations","id","item","get","where","newDateTime","moveDateTimeToCurrentCentury","data","update","input","executeTask","args","lambdaName","handlerClient","Date","toISOString","invoke","name","payload","await","deleteCurrentTask","e","error"],"sources":["scheduleAction.utils.ts"],"sourcesContent":["import { dateTimeToCronExpression, moveDateTimeToCurrentCentury } from \"~/scheduler/handlers/utils\";\nimport { ApwScheduleAction } from \"~/scheduler/types\";\nimport {\n HandlerArgs,\n InvocationTypes,\n Configuration\n} from \"~/scheduler/handlers/scheduleAction/index\";\nimport {\n DeleteRuleCommand,\n RemoveTargetsCommand,\n PutTargetsCommand,\n PutRuleCommand\n} from \"@aws-sdk/client-cloudwatch-events\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst log = console.log;\n\ninterface ScheduleLambdaExecutionParams extends Omit<HandlerArgs, \"invocationType\"> {\n cloudWatchEventClient: any;\n invokedFunctionArn: string;\n}\n\n/**\n * Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;\n * in case of scheduling becoming the most frequently used feature.\n * https://aws.amazon.com/about-aws/whats-new/2017/07/cloudwatch-events-increases-rules-and-api-requests-limits/\n */\nexport async function scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn,\n datetime,\n futureDatetime,\n tenant,\n locale\n}: ScheduleLambdaExecutionParams) {\n const { eventTargetId, eventRuleName } = await getApwSettings();\n /**\n * Remove the target\n */\n const removeTargetsCommand = new RemoveTargetsCommand({\n Rule: eventRuleName,\n Ids: [eventTargetId]\n });\n const removeTargetsResponse = await cloudWatchEventClient.send(removeTargetsCommand);\n /**\n * Log error.\n */\n if (\n typeof removeTargetsResponse.FailedEntryCount === \"number\" &&\n removeTargetsResponse.FailedEntryCount !== 0\n ) {\n console.info(\"Failed in removing the targets!\");\n console.info(removeTargetsResponse.FailedEntries);\n }\n /**\n * Delete the Rule\n */\n const deleteRuleCommand = new DeleteRuleCommand({\n Name: eventRuleName\n });\n await cloudWatchEventClient.send(deleteRuleCommand);\n\n /**\n * Create a new one.\n * Min H D M DW Y\n * 20 10 10 03 * 2022\n */\n const cronExpression = dateTimeToCronExpression(datetime);\n\n const ruleParams = {\n Name: eventRuleName,\n ScheduleExpression: `cron(${cronExpression})`,\n State: \"ENABLED\",\n Description: `Enable us to schedule an action in publishing workflow at a particular datetime`\n };\n\n await cloudWatchEventClient.send(new PutRuleCommand(ruleParams));\n /**\n * Add lambda as target for the rule.\n */\n await cloudWatchEventClient.send(\n new PutTargetsCommand({\n Rule: eventRuleName,\n Targets: [\n {\n Arn: invokedFunctionArn,\n Id: eventTargetId,\n Input: JSON.stringify({\n datetime: datetime,\n tenant: tenant,\n locale: locale,\n invocationType: InvocationTypes.SCHEDULED,\n futureDatetime: futureDatetime\n } as HandlerArgs)\n }\n ]\n })\n );\n}\n\nexport const shouldScheduleTask = (\n nextTaskDatetime: string,\n currentTaskDatetime: string | null\n): boolean => {\n return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;\n};\n\ninterface RestoreDateTimeParams\n extends Pick<Configuration, \"storageOperations\">,\n Pick<HandlerArgs, \"tenant\" | \"locale\"> {\n task: ApwScheduleAction;\n}\n\nexport const restoreDateTime = async ({\n locale,\n tenant,\n task: currentTask,\n storageOperations\n}: RestoreDateTimeParams): Promise<void> => {\n log(`Mark task \"${currentTask.id}\" as undone by restoring original \"datetime\".`);\n const item = await storageOperations.get({\n where: {\n tenant,\n locale,\n id: currentTask.id\n }\n });\n if (item) {\n const newDateTime = moveDateTimeToCurrentCentury(item.data.datetime);\n await storageOperations.update({\n item: {\n ...item,\n data: { ...item.data, datetime: newDateTime }\n },\n input: { ...item.data, datetime: newDateTime }\n });\n }\n};\n\ninterface ExecuteTaskParams\n extends Pick<ClientContext, \"handlerClient\">,\n Pick<Configuration, \"storageOperations\"> {\n args: HandlerArgs;\n lambdaName: string;\n}\n\nexport const executeTask = async ({\n args,\n lambdaName,\n handlerClient,\n storageOperations\n}: ExecuteTaskParams): Promise<void> => {\n log(`Executing task at: `, new Date().toISOString());\n\n if (typeof handlerClient.invoke === \"function\") {\n await handlerClient.invoke({\n name: lambdaName,\n payload: {\n futureDatetime: args.futureDatetime,\n datetime: args.datetime,\n tenant: args.tenant,\n locale: args.locale\n },\n await: false\n });\n }\n\n /**\n * Delete current schedule Task. So that, we can schedule a new one later.\n */\n try {\n await storageOperations.deleteCurrentTask({\n tenant: args.tenant,\n locale: args.locale\n });\n } catch (e) {\n console.error(e);\n }\n};\n"],"mappings":"
|
1
|
+
{"version":3,"names":["log","console","scheduleLambdaExecution","cloudWatchEventClient","invokedFunctionArn","datetime","futureDatetime","tenant","locale","eventTargetId","eventRuleName","getApwSettings","removeTargetsCommand","RemoveTargetsCommand","Rule","Ids","removeTargetsResponse","send","FailedEntryCount","info","FailedEntries","deleteRuleCommand","DeleteRuleCommand","Name","cronExpression","dateTimeToCronExpression","ruleParams","ScheduleExpression","State","Description","PutRuleCommand","PutTargetsCommand","Targets","Arn","Id","Input","JSON","stringify","invocationType","InvocationTypes","SCHEDULED","shouldScheduleTask","nextTaskDatetime","currentTaskDatetime","restoreDateTime","task","currentTask","storageOperations","id","item","get","where","newDateTime","moveDateTimeToCurrentCentury","data","update","input","executeTask","args","lambdaName","handlerClient","Date","toISOString","invoke","name","payload","await","deleteCurrentTask","e","error"],"sources":["scheduleAction.utils.ts"],"sourcesContent":["import { dateTimeToCronExpression, moveDateTimeToCurrentCentury } from \"~/scheduler/handlers/utils\";\nimport { ApwScheduleAction } from \"~/scheduler/types\";\nimport {\n HandlerArgs,\n InvocationTypes,\n Configuration\n} from \"~/scheduler/handlers/scheduleAction/index\";\nimport {\n DeleteRuleCommand,\n RemoveTargetsCommand,\n PutTargetsCommand,\n PutRuleCommand\n} from \"@aws-sdk/client-cloudwatch-events\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\nimport { getApwSettings } from \"~/scheduler/handlers/utils\";\n\nconst log = console.log;\n\ninterface ScheduleLambdaExecutionParams extends Omit<HandlerArgs, \"invocationType\"> {\n cloudWatchEventClient: any;\n invokedFunctionArn: string;\n}\n\n/**\n * Current API limit/quota for Cloudwatch events is sufficient for now. But, we should watch for it;\n * in case of scheduling becoming the most frequently used feature.\n * https://aws.amazon.com/about-aws/whats-new/2017/07/cloudwatch-events-increases-rules-and-api-requests-limits/\n */\nexport async function scheduleLambdaExecution({\n cloudWatchEventClient,\n invokedFunctionArn,\n datetime,\n futureDatetime,\n tenant,\n locale\n}: ScheduleLambdaExecutionParams) {\n const { eventTargetId, eventRuleName } = await getApwSettings();\n /**\n * Remove the target\n */\n const removeTargetsCommand = new RemoveTargetsCommand({\n Rule: eventRuleName,\n Ids: [eventTargetId]\n });\n const removeTargetsResponse = await cloudWatchEventClient.send(removeTargetsCommand);\n /**\n * Log error.\n */\n if (\n typeof removeTargetsResponse.FailedEntryCount === \"number\" &&\n removeTargetsResponse.FailedEntryCount !== 0\n ) {\n console.info(\"Failed in removing the targets!\");\n console.info(removeTargetsResponse.FailedEntries);\n }\n /**\n * Delete the Rule\n */\n const deleteRuleCommand = new DeleteRuleCommand({\n Name: eventRuleName\n });\n await cloudWatchEventClient.send(deleteRuleCommand);\n\n /**\n * Create a new one.\n * Min H D M DW Y\n * 20 10 10 03 * 2022\n */\n const cronExpression = dateTimeToCronExpression(datetime);\n\n const ruleParams = {\n Name: eventRuleName,\n ScheduleExpression: `cron(${cronExpression})`,\n State: \"ENABLED\",\n Description: `Enable us to schedule an action in publishing workflow at a particular datetime`\n };\n\n await cloudWatchEventClient.send(new PutRuleCommand(ruleParams));\n /**\n * Add lambda as target for the rule.\n */\n await cloudWatchEventClient.send(\n new PutTargetsCommand({\n Rule: eventRuleName,\n Targets: [\n {\n Arn: invokedFunctionArn,\n Id: eventTargetId,\n Input: JSON.stringify({\n datetime: datetime,\n tenant: tenant,\n locale: locale,\n invocationType: InvocationTypes.SCHEDULED,\n futureDatetime: futureDatetime\n } as HandlerArgs)\n }\n ]\n })\n );\n}\n\nexport const shouldScheduleTask = (\n nextTaskDatetime: string,\n currentTaskDatetime: string | null\n): boolean => {\n return !currentTaskDatetime || nextTaskDatetime < currentTaskDatetime;\n};\n\ninterface RestoreDateTimeParams\n extends Pick<Configuration, \"storageOperations\">,\n Pick<HandlerArgs, \"tenant\" | \"locale\"> {\n task: ApwScheduleAction;\n}\n\nexport const restoreDateTime = async ({\n locale,\n tenant,\n task: currentTask,\n storageOperations\n}: RestoreDateTimeParams): Promise<void> => {\n log(`Mark task \"${currentTask.id}\" as undone by restoring original \"datetime\".`);\n const item = await storageOperations.get({\n where: {\n tenant,\n locale,\n id: currentTask.id\n }\n });\n if (item) {\n const newDateTime = moveDateTimeToCurrentCentury(item.data.datetime);\n await storageOperations.update({\n item: {\n ...item,\n data: { ...item.data, datetime: newDateTime }\n },\n input: { ...item.data, datetime: newDateTime }\n });\n }\n};\n\ninterface ExecuteTaskParams\n extends Pick<ClientContext, \"handlerClient\">,\n Pick<Configuration, \"storageOperations\"> {\n args: HandlerArgs;\n lambdaName: string;\n}\n\nexport const executeTask = async ({\n args,\n lambdaName,\n handlerClient,\n storageOperations\n}: ExecuteTaskParams): Promise<void> => {\n log(`Executing task at: `, new Date().toISOString());\n\n if (typeof handlerClient.invoke === \"function\") {\n await handlerClient.invoke({\n name: lambdaName,\n payload: {\n futureDatetime: args.futureDatetime,\n datetime: args.datetime,\n tenant: args.tenant,\n locale: args.locale\n },\n await: false\n });\n }\n\n /**\n * Delete current schedule Task. So that, we can schedule a new one later.\n */\n try {\n await storageOperations.deleteCurrentTask({\n tenant: args.tenant,\n locale: args.locale\n });\n } catch (e) {\n console.error(e);\n }\n};\n"],"mappings":";;;;;;;;;;AAAA;AAEA;AAKA;AASA,MAAMA,GAAG,GAAGC,OAAO,CAACD,GAAG;AAOvB;AACA;AACA;AACA;AACA;AACO,eAAeE,uBAAuB,CAAC;EAC1CC,qBAAqB;EACrBC,kBAAkB;EAClBC,QAAQ;EACRC,cAAc;EACdC,MAAM;EACNC;AAC2B,CAAC,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AI,OAAOF,aAAa,CAACG,MAAM,KAAK,UAAU,EAAE;IAC5C,MAAMH,aAAa,CAACG,MAAM,CAAC;MACvBC,IAAI,EAAEL,UAAU;MAChBM,OAAO,EAAE;QACL3D,cAAc,EAAEoD,IAAI,CAACpD,cAAc;QACnCD,QAAQ,EAAEqD,IAAI,CAACrD,QAAQ;QACvBE,MAAM,EAAEmD,IAAI,CAACnD,MAAM;QACnBC,MAAM,EAAEkD,IAAI,CAAClD;MACjB,CAAC;MACD0D,KAAK,EAAE;IACX,CAAC,CAAC;EACN;;EAEA;AACJ;AACA;EACI,IAAI;IACA,MAAMnB,iBAAiB,CAACoB,iBAAiB,CAAC;MACtC5D,MAAM,EAAEmD,IAAI,CAACnD,MAAM;MACnBC,MAAM,EAAEkD,IAAI,CAAClD;IACjB,CAAC,CAAC;EACN,CAAC,CAAC,OAAO4D,CAAC,EAAE;IACRnE,OAAO,CAACoE,KAAK,CAACD,CAAC,CAAC;EACpB;AACJ,CAAC;AAAC"}
|
@@ -19,13 +19,12 @@ export declare const encodeToken: ({ id, tenant, locale }: EncodeTokenParams) =>
|
|
19
19
|
export declare const TOKEN_PREFIX = "apw-";
|
20
20
|
export declare const decodeToken: (token: string) => Partial<EncodeTokenParams>;
|
21
21
|
export declare const documentClient: DocumentClient;
|
22
|
-
export declare const basePlugins: () => (import("@webiny/
|
22
|
+
export declare const basePlugins: () => (import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | import("@webiny/api").ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[];
|
23
23
|
/**
|
24
24
|
* Get APW settings record from DDB.
|
25
25
|
*/
|
26
26
|
export interface ApwSettings {
|
27
27
|
mainGraphqlFunctionArn: string;
|
28
|
-
cmsGraphqlFunctionArn: string;
|
29
28
|
eventRuleName: string;
|
30
29
|
eventTargetId: string;
|
31
30
|
}
|
@@ -1,51 +1,36 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4
|
-
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.shouldRestoreDatetime = exports.moveDateTimeToNextCentury = exports.moveDateTimeToCurrentCentury = exports.isDateTimeInNextCentury = exports.getIsoStringTillMinutes = exports.getApwSettings = exports.encodeToken = exports.documentClient = exports.decodeToken = exports.dateTimeToCronExpression = exports.basePlugins = exports.TOKEN_PREFIX = void 0;
|
9
|
-
|
10
8
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
11
|
-
|
12
9
|
var _utc = _interopRequireDefault(require("dayjs/plugin/utc"));
|
13
|
-
|
14
10
|
var _dynamodb = require("aws-sdk/clients/dynamodb");
|
15
|
-
|
16
11
|
var _handlerDb = _interopRequireDefault(require("@webiny/handler-db"));
|
17
|
-
|
18
12
|
var _dbDynamodb = require("@webiny/db-dynamodb");
|
19
|
-
|
20
13
|
var _plugins = _interopRequireDefault(require("@webiny/db-dynamodb/plugins"));
|
21
|
-
|
22
14
|
var _handlerLogs = _interopRequireDefault(require("@webiny/handler-logs"));
|
23
|
-
|
24
15
|
var _types = require("../types");
|
25
|
-
|
26
16
|
/**
|
27
17
|
* https://day.js.org/docs/en/plugin/utc
|
28
18
|
*/
|
29
19
|
_dayjs.default.extend(_utc.default);
|
30
|
-
|
31
20
|
const TIME_SEPARATOR = ":";
|
32
21
|
const ELAPSED_CRON_EXPRESSION = "* * * * ? 2000";
|
33
|
-
|
34
22
|
const getIsoStringTillMinutes = datetime => {
|
35
23
|
/**
|
36
24
|
* Validate datetime.
|
37
25
|
*/
|
38
26
|
if (isNaN(Date.parse(datetime))) {
|
39
27
|
return datetime;
|
40
|
-
}
|
28
|
+
}
|
29
|
+
// input = "2022-03-08T05:41:13.230Z"
|
41
30
|
// output = "2022-03-08T05:41"
|
42
|
-
|
43
|
-
|
44
31
|
return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));
|
45
32
|
};
|
46
|
-
|
47
33
|
exports.getIsoStringTillMinutes = getIsoStringTillMinutes;
|
48
|
-
|
49
34
|
const dateTimeToCronExpression = datetime => {
|
50
35
|
if (!datetime) {
|
51
36
|
return ELAPSED_CRON_EXPRESSION;
|
@@ -56,32 +41,22 @@ const dateTimeToCronExpression = datetime => {
|
|
56
41
|
*
|
57
42
|
* https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
|
58
43
|
*/
|
59
|
-
|
60
|
-
|
61
44
|
const dayOfWeek = "?";
|
62
45
|
return _dayjs.default.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);
|
63
46
|
};
|
64
|
-
|
65
47
|
exports.dateTimeToCronExpression = dateTimeToCronExpression;
|
66
|
-
|
67
48
|
const moveDateTimeToNextCentury = datetime => {
|
68
49
|
return _dayjs.default.utc(datetime).add(100, "year").toISOString();
|
69
50
|
};
|
70
|
-
|
71
51
|
exports.moveDateTimeToNextCentury = moveDateTimeToNextCentury;
|
72
|
-
|
73
52
|
const moveDateTimeToCurrentCentury = datetime => {
|
74
53
|
return _dayjs.default.utc(datetime).subtract(100, "year").toISOString();
|
75
54
|
};
|
76
|
-
|
77
55
|
exports.moveDateTimeToCurrentCentury = moveDateTimeToCurrentCentury;
|
78
|
-
|
79
56
|
const isDateTimeInNextCentury = datetime => {
|
80
57
|
return _dayjs.default.utc(datetime).isAfter("2100-01-01", "year");
|
81
58
|
};
|
82
|
-
|
83
59
|
exports.isDateTimeInNextCentury = isDateTimeInNextCentury;
|
84
|
-
|
85
60
|
const shouldRestoreDatetime = ({
|
86
61
|
invocationType,
|
87
62
|
datetime
|
@@ -93,16 +68,11 @@ const shouldRestoreDatetime = ({
|
|
93
68
|
* scheduled action if it has not been executed already.
|
94
69
|
*/
|
95
70
|
const selfInvoked = invocationType === _types.InvocationTypes.SCHEDULED;
|
96
|
-
|
97
71
|
const today = _dayjs.default.utc();
|
98
|
-
|
99
72
|
const isExecutionPending = _dayjs.default.utc(datetime).isAfter(today);
|
100
|
-
|
101
73
|
return !selfInvoked && isExecutionPending;
|
102
74
|
};
|
103
|
-
|
104
75
|
exports.shouldRestoreDatetime = shouldRestoreDatetime;
|
105
|
-
|
106
76
|
const encodeToken = ({
|
107
77
|
id,
|
108
78
|
tenant,
|
@@ -110,11 +80,9 @@ const encodeToken = ({
|
|
110
80
|
}) => {
|
111
81
|
return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;
|
112
82
|
};
|
113
|
-
|
114
83
|
exports.encodeToken = encodeToken;
|
115
84
|
const TOKEN_PREFIX = "apw-";
|
116
85
|
exports.TOKEN_PREFIX = TOKEN_PREFIX;
|
117
|
-
|
118
86
|
const decodeToken = token => {
|
119
87
|
const auth = token.slice(TOKEN_PREFIX.length);
|
120
88
|
const [id, tenant, locale] = auth.split("__");
|
@@ -124,27 +92,23 @@ const decodeToken = token => {
|
|
124
92
|
locale
|
125
93
|
};
|
126
94
|
};
|
127
|
-
|
128
95
|
exports.decodeToken = decodeToken;
|
129
96
|
const documentClient = new _dynamodb.DocumentClient({
|
130
97
|
convertEmptyValues: true,
|
131
98
|
region: process.env.AWS_REGION
|
132
99
|
});
|
133
100
|
exports.documentClient = documentClient;
|
134
|
-
|
135
101
|
const basePlugins = () => [(0, _plugins.default)(), (0, _handlerLogs.default)(), (0, _handlerDb.default)({
|
136
102
|
table: process.env.DB_TABLE,
|
137
103
|
driver: new _dbDynamodb.DynamoDbDriver({
|
138
104
|
documentClient
|
139
105
|
})
|
140
106
|
})];
|
107
|
+
|
141
108
|
/**
|
142
109
|
* Get APW settings record from DDB.
|
143
110
|
*/
|
144
|
-
|
145
|
-
|
146
111
|
exports.basePlugins = basePlugins;
|
147
|
-
|
148
112
|
const getApwSettings = async () => {
|
149
113
|
const variant = process.env.STAGED_ROLLOUTS_VARIANT;
|
150
114
|
const params = {
|
@@ -159,10 +123,8 @@ const getApwSettings = async () => {
|
|
159
123
|
} = await documentClient.get(params).promise();
|
160
124
|
return {
|
161
125
|
mainGraphqlFunctionArn: Item ? Item["mainGraphqlFunctionArn"] : "mainGraphqlFunctionArn",
|
162
|
-
cmsGraphqlFunctionArn: Item ? Item["cmsGraphqlFunctionArn"] : "cmsGraphqlFunctionArn",
|
163
126
|
eventRuleName: Item ? Item["eventRuleName"] : "eventRuleName",
|
164
127
|
eventTargetId: Item ? Item["eventTargetId"] : "eventTargetId"
|
165
128
|
};
|
166
129
|
};
|
167
|
-
|
168
130
|
exports.getApwSettings = getApwSettings;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["dayjs","extend","utc","TIME_SEPARATOR","ELAPSED_CRON_EXPRESSION","getIsoStringTillMinutes","datetime","isNaN","Date","parse","slice","lastIndexOf","dateTimeToCronExpression","dayOfWeek","format","moveDateTimeToNextCentury","add","toISOString","moveDateTimeToCurrentCentury","subtract","isDateTimeInNextCentury","isAfter","shouldRestoreDatetime","invocationType","selfInvoked","InvocationTypes","SCHEDULED","today","isExecutionPending","encodeToken","id","tenant","locale","TOKEN_PREFIX","decodeToken","token","auth","length","split","documentClient","DocumentClient","convertEmptyValues","region","process","env","AWS_REGION","basePlugins","dynamoDbPlugins","logsPlugins","dbPlugins","table","DB_TABLE","driver","DynamoDbDriver","getApwSettings","variant","STAGED_ROLLOUTS_VARIANT","params","TableName","Key","PK","SK","Item","get","promise","mainGraphqlFunctionArn","
|
1
|
+
{"version":3,"names":["dayjs","extend","utc","TIME_SEPARATOR","ELAPSED_CRON_EXPRESSION","getIsoStringTillMinutes","datetime","isNaN","Date","parse","slice","lastIndexOf","dateTimeToCronExpression","dayOfWeek","format","moveDateTimeToNextCentury","add","toISOString","moveDateTimeToCurrentCentury","subtract","isDateTimeInNextCentury","isAfter","shouldRestoreDatetime","invocationType","selfInvoked","InvocationTypes","SCHEDULED","today","isExecutionPending","encodeToken","id","tenant","locale","TOKEN_PREFIX","decodeToken","token","auth","length","split","documentClient","DocumentClient","convertEmptyValues","region","process","env","AWS_REGION","basePlugins","dynamoDbPlugins","logsPlugins","dbPlugins","table","DB_TABLE","driver","DynamoDbDriver","getApwSettings","variant","STAGED_ROLLOUTS_VARIANT","params","TableName","Key","PK","SK","Item","get","promise","mainGraphqlFunctionArn","eventRuleName","eventTargetId"],"sources":["utils.ts"],"sourcesContent":["import dayjs from \"dayjs\";\nimport utc from \"dayjs/plugin/utc\";\nimport { DocumentClient } from \"aws-sdk/clients/dynamodb\";\nimport dbPlugins from \"@webiny/handler-db\";\nimport { DynamoDbDriver } from \"@webiny/db-dynamodb\";\nimport dynamoDbPlugins from \"@webiny/db-dynamodb/plugins\";\nimport logsPlugins from \"@webiny/handler-logs\";\nimport { InvocationTypes } from \"~/scheduler/types\";\n\n/**\n * https://day.js.org/docs/en/plugin/utc\n */\ndayjs.extend(utc);\n\nconst TIME_SEPARATOR = \":\";\nconst ELAPSED_CRON_EXPRESSION = \"* * * * ? 2000\";\n\nexport const getIsoStringTillMinutes = (datetime: string): string => {\n /**\n * Validate datetime.\n */\n if (isNaN(Date.parse(datetime))) {\n return datetime;\n }\n // input = \"2022-03-08T05:41:13.230Z\"\n // output = \"2022-03-08T05:41\"\n return datetime.slice(0, datetime.lastIndexOf(TIME_SEPARATOR));\n};\n\nexport const dateTimeToCronExpression = (datetime: string): string => {\n if (!datetime) {\n return ELAPSED_CRON_EXPRESSION;\n }\n /**\n * You can't specify the Day-of-month and Day-of-week fields in the same cron expression.\n * If you specify a value (or a *) in one of the fields, you must use a ? (question mark) in the other.\n *\n * https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html\n */\n const dayOfWeek = \"?\";\n\n return dayjs.utc(datetime).format(`mm H D M [${dayOfWeek}] YYYY`);\n};\n\nexport const moveDateTimeToNextCentury = (datetime: string): string => {\n return dayjs.utc(datetime).add(100, \"year\").toISOString();\n};\n\nexport const moveDateTimeToCurrentCentury = (datetime: string): string => {\n return dayjs.utc(datetime).subtract(100, \"year\").toISOString();\n};\n\nexport const isDateTimeInNextCentury = (datetime: string): boolean => {\n return dayjs.utc(datetime).isAfter(\"2100-01-01\", \"year\");\n};\n\ninterface ShouldRestoreDatetimeParams {\n invocationType?: InvocationTypes;\n datetime: string;\n}\n\nexport const shouldRestoreDatetime = ({\n invocationType,\n datetime\n}: ShouldRestoreDatetimeParams): boolean => {\n /**\n * \"invocationType\" will not be SCHEDULED when the lambda is called from Main GQL handler.\n *\n * Which means a new content is scheduled for \"publish\"/\"unpublish\" therefore, we need to restore the previously\n * scheduled action if it has not been executed already.\n */\n const selfInvoked = invocationType === InvocationTypes.SCHEDULED;\n\n const today = dayjs.utc();\n const isExecutionPending = dayjs.utc(datetime).isAfter(today);\n\n return !selfInvoked && isExecutionPending;\n};\n\ninterface EncodeTokenParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport const encodeToken = ({ id, tenant, locale }: EncodeTokenParams) => {\n return `${TOKEN_PREFIX}${id}__${tenant}__${locale}`;\n};\n\nexport const TOKEN_PREFIX = \"apw-\";\n\nexport const decodeToken = (token: string): Partial<EncodeTokenParams> => {\n const auth = token.slice(TOKEN_PREFIX.length);\n const [id, tenant, locale] = auth.split(\"__\");\n\n return {\n id,\n tenant,\n locale\n };\n};\n\nexport const documentClient = new DocumentClient({\n convertEmptyValues: true,\n region: process.env.AWS_REGION\n});\n\nexport const basePlugins = () => [\n dynamoDbPlugins(),\n logsPlugins(),\n dbPlugins({\n table: process.env.DB_TABLE,\n driver: new DynamoDbDriver({\n documentClient\n })\n })\n];\n\n/**\n * Get APW settings record from DDB.\n */\nexport interface ApwSettings {\n mainGraphqlFunctionArn: string;\n eventRuleName: string;\n eventTargetId: string;\n}\n\nexport const getApwSettings = async (): Promise<ApwSettings> => {\n const variant = process.env.STAGED_ROLLOUTS_VARIANT;\n\n const params = {\n TableName: process.env.DB_TABLE as string,\n Key: {\n PK: `APW#SETTINGS`,\n SK: variant || \"default\"\n }\n };\n\n const { Item } = await documentClient.get(params).promise();\n\n return {\n mainGraphqlFunctionArn: Item ? Item[\"mainGraphqlFunctionArn\"] : \"mainGraphqlFunctionArn\",\n eventRuleName: Item ? Item[\"eventRuleName\"] : \"eventRuleName\",\n eventTargetId: Item ? Item[\"eventTargetId\"] : \"eventTargetId\"\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACAA,cAAK,CAACC,MAAM,CAACC,YAAG,CAAC;AAEjB,MAAMC,cAAc,GAAG,GAAG;AAC1B,MAAMC,uBAAuB,GAAG,gBAAgB;AAEzC,MAAMC,uBAAuB,GAAIC,QAAgB,IAAa;EACjE;AACJ;AACA;EACI,IAAIC,KAAK,CAACC,IAAI,CAACC,KAAK,CAACH,QAAQ,CAAC,CAAC,EAAE;IAC7B,OAAOA,QAAQ;EACnB;EACA;EACA;EACA,OAAOA,QAAQ,CAACI,KAAK,CAAC,CAAC,EAAEJ,QAAQ,CAACK,WAAW,CAACR,cAAc,CAAC,CAAC;AAClE,CAAC;AAAC;AAEK,MAAMS,wBAAwB,GAAIN,QAAgB,IAAa;EAClE,IAAI,CAACA,QAAQ,EAAE;IACX,OAAOF,uBAAuB;EAClC;EACA;AACJ;AACA;AACA;AACA;AACA;EACI,MAAMS,SAAS,GAAG,GAAG;EAErB,OAAOb,cAAK,CAACE,GAAG,CAACI,QAAQ,CAAC,CAACQ,MAAM,CAAE,aAAYD,SAAU,QAAO,CAAC;AACrE,CAAC;AAAC;AAEK,MAAME,yBAAyB,GAAIT,QAAgB,IAAa;EACnE,OAAON,cAAK,CAACE,GAAG,CAACI,QAAQ,CAAC,CAACU,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAACC,WAAW,EAAE;AAC7D,CAAC;AAAC;AAEK,MAAMC,4BAA4B,GAAIZ,QAAgB,IAAa;EACtE,OAAON,cAAK,CAACE,GAAG,CAACI,QAAQ,CAAC,CAACa,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAACF,WAAW,EAAE;AACl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BAAe,GAAE,EACjB,IAAAC,oBAAW,GAAE,EACb,IAAAC,kBAAS,EAAC;EACNC,KAAK,EAAEP,OAAO,CAACC,GAAG,CAACO,QAAQ;EAC3BC,MAAM,EAAE,IAAIC,0BAAc,CAAC;IACvBd;EACJ,CAAC;AACL,CAAC,CAAC,CACL;;AAED;AACA;AACA;AAFA;AASO,MAAMe,cAAc,GAAG,YAAkC;EAC5D,MAAMC,OAAO,GAAGZ,OAAO,CAACC,GAAG,CAACY,uBAAuB;EAEnD,MAAMC,MAAM,GAAG;IACXC,SAAS,EAAEf,OAAO,CAACC,GAAG,CAACO,QAAkB;IACzCQ,GAAG,EAAE;MACDC,EAAE,EAAG,cAAa;MAClBC,EAAE,EAAEN,OAAO,IAAI;IACnB;EACJ,CAAC;EAED,MAAM;IAAEO;EAAK,CAAC,GAAG,MAAMvB,cAAc,CAACwB,GAAG,CAACN,MAAM,CAAC,CAACO,OAAO,EAAE;EAE3D,OAAO;IACHC,sBAAsB,EAAEH,IAAI,GAAGA,IAAI,CAAC,wBAAwB,CAAC,GAAG,wBAAwB;IACxFI,aAAa,EAAEJ,IAAI,GAAGA,IAAI,CAAC,eAAe,CAAC,GAAG,eAAe;IAC7DK,aAAa,EAAEL,IAAI,GAAGA,IAAI,CAAC,eAAe,CAAC,GAAG;EAClD,CAAC;AACL,CAAC;AAAC"}
|
package/scheduler/index.js
CHANGED
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.createScheduler = void 0;
|
7
|
-
|
8
7
|
var _createScheduleActionMethods = require("./createScheduleActionMethods");
|
9
|
-
|
10
8
|
const createScheduler = params => {
|
11
9
|
const {
|
12
10
|
getLocale,
|
@@ -23,5 +21,4 @@ const createScheduler = params => {
|
|
23
21
|
storageOperations
|
24
22
|
});
|
25
23
|
};
|
26
|
-
|
27
24
|
exports.createScheduler = createScheduler;
|
package/scheduler/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["createScheduler","params","getLocale","getIdentity","getTenant","getPermission","storageOperations","createScheduleActionMethods"],"sources":["index.ts"],"sourcesContent":["import { createScheduleActionMethods } from \"./createScheduleActionMethods\";\nimport { ApwScheduleActionCrud, CreateScheduleActionParams } from \"./types\";\n\nexport const createScheduler = (params: CreateScheduleActionParams): ApwScheduleActionCrud => {\n const { getLocale, getIdentity, getTenant, getPermission, storageOperations } = params;\n\n return createScheduleActionMethods({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations\n });\n};\n"],"mappings":"
|
1
|
+
{"version":3,"names":["createScheduler","params","getLocale","getIdentity","getTenant","getPermission","storageOperations","createScheduleActionMethods"],"sources":["index.ts"],"sourcesContent":["import { createScheduleActionMethods } from \"./createScheduleActionMethods\";\nimport { ApwScheduleActionCrud, CreateScheduleActionParams } from \"./types\";\n\nexport const createScheduler = (params: CreateScheduleActionParams): ApwScheduleActionCrud => {\n const { getLocale, getIdentity, getTenant, getPermission, storageOperations } = params;\n\n return createScheduleActionMethods({\n getLocale,\n getIdentity,\n getTenant,\n getPermission,\n storageOperations\n });\n};\n"],"mappings":";;;;;;AAAA;AAGO,MAAMA,eAAe,GAAIC,MAAkC,IAA4B;EAC1F,MAAM;IAAEC,SAAS;IAAEC,WAAW;IAAEC,SAAS;IAAEC,aAAa;IAAEC;EAAkB,CAAC,GAAGL,MAAM;EAEtF,OAAO,IAAAM,wDAA2B,EAAC;IAC/BL,SAAS;IACTC,WAAW;IACXC,SAAS;IACTC,aAAa;IACbC;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|
package/scheduler/types.js
CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.InvocationTypes = exports.ApwScheduleActionTypes = exports.ApwContentTypes = void 0;
|
7
|
-
|
8
7
|
/**
|
9
8
|
* A interface describing the reference to a user that created some data in the database.
|
10
9
|
*
|
@@ -12,23 +11,18 @@ exports.InvocationTypes = exports.ApwScheduleActionTypes = exports.ApwContentTyp
|
|
12
11
|
*/
|
13
12
|
let ApwContentTypes;
|
14
13
|
exports.ApwContentTypes = ApwContentTypes;
|
15
|
-
|
16
14
|
(function (ApwContentTypes) {
|
17
15
|
ApwContentTypes["PAGE"] = "page";
|
18
16
|
ApwContentTypes["CMS_ENTRY"] = "cms_entry";
|
19
17
|
})(ApwContentTypes || (exports.ApwContentTypes = ApwContentTypes = {}));
|
20
|
-
|
21
18
|
let ApwScheduleActionTypes;
|
22
19
|
exports.ApwScheduleActionTypes = ApwScheduleActionTypes;
|
23
|
-
|
24
20
|
(function (ApwScheduleActionTypes) {
|
25
21
|
ApwScheduleActionTypes["PUBLISH"] = "publish";
|
26
22
|
ApwScheduleActionTypes["UNPUBLISH"] = "unpublish";
|
27
23
|
})(ApwScheduleActionTypes || (exports.ApwScheduleActionTypes = ApwScheduleActionTypes = {}));
|
28
|
-
|
29
24
|
let InvocationTypes;
|
30
25
|
exports.InvocationTypes = InvocationTypes;
|
31
|
-
|
32
26
|
(function (InvocationTypes) {
|
33
27
|
InvocationTypes["SCHEDULED"] = "scheduled";
|
34
28
|
})(InvocationTypes || (exports.InvocationTypes = InvocationTypes = {}));
|
package/scheduler/types.js.map
CHANGED
@@ -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":"
|
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"}
|