@webiny/api-apw 0.0.0-unstable.d7f521b032 → 0.0.0-unstable.da99e0b846

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/package.json +31 -31
  2. package/plugins/graphql/changeRequest.gql.js +2 -2
  3. package/plugins/graphql/changeRequest.gql.js.map +1 -1
  4. package/plugins/graphql/comment.gql.js +2 -2
  5. package/plugins/graphql/comment.gql.js.map +1 -1
  6. package/plugins/graphql/contentReview.gql.js +5 -5
  7. package/plugins/graphql/contentReview.gql.js.map +1 -1
  8. package/plugins/graphql/reviewer.gql.js +2 -2
  9. package/plugins/graphql/reviewer.gql.js.map +1 -1
  10. package/plugins/graphql/workflow.gql.js +2 -2
  11. package/plugins/graphql/workflow.gql.js.map +1 -1
  12. package/plugins/graphql.js +1 -1
  13. package/plugins/graphql.js.map +1 -1
  14. package/plugins/hooks/notifications/changeRequestAfterCreate.js +3 -8
  15. package/plugins/hooks/notifications/changeRequestAfterCreate.js.map +1 -1
  16. package/plugins/hooks/notifications/commentAfterCreate.js +3 -8
  17. package/plugins/hooks/notifications/commentAfterCreate.js.map +1 -1
  18. package/plugins/hooks/notifications/contentReviewAfterCreate.js +3 -8
  19. package/plugins/hooks/notifications/contentReviewAfterCreate.js.map +1 -1
  20. package/plugins/hooks/notifications/reviewers.js +15 -14
  21. package/plugins/hooks/notifications/reviewers.js.map +1 -1
  22. package/scheduler/handlers/executeAction/index.d.ts +1 -1
  23. package/scheduler/handlers/executeAction/index.js +27 -6
  24. package/scheduler/handlers/executeAction/index.js.map +1 -1
  25. package/scheduler/handlers/scheduleAction/index.js +5 -1
  26. package/scheduler/handlers/scheduleAction/index.js.map +1 -1
  27. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js +2 -0
  28. package/scheduler/handlers/scheduleAction/scheduleAction.utils.js.map +1 -1
  29. package/scheduler/types.d.ts +2 -20
  30. package/scheduler/types.js +0 -5
  31. package/scheduler/types.js.map +1 -1
  32. package/storageOperations/changeRequestStorageOperations.js +20 -20
  33. package/storageOperations/changeRequestStorageOperations.js.map +1 -1
  34. package/storageOperations/commentStorageOperations.js +23 -23
  35. package/storageOperations/commentStorageOperations.js.map +1 -1
  36. package/storageOperations/contentReviewStorageOperations.js +20 -20
  37. package/storageOperations/contentReviewStorageOperations.js.map +1 -1
  38. package/storageOperations/models/contentModelPluginFactory.d.ts +3 -3
  39. package/storageOperations/models/contentModelPluginFactory.js +4 -3
  40. package/storageOperations/models/contentModelPluginFactory.js.map +1 -1
  41. package/storageOperations/models/index.js +0 -2
  42. package/storageOperations/models/index.js.map +1 -1
  43. package/storageOperations/reviewerStorageOperations.js +23 -28
  44. package/storageOperations/reviewerStorageOperations.js.map +1 -1
  45. package/storageOperations/workflowStorageOperations.js +20 -20
  46. package/storageOperations/workflowStorageOperations.js.map +1 -1
  47. package/types.d.ts +6 -5
  48. package/types.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":["attachContentReviewAfterCreate","context","apw","contentReview","onContentReviewAfterCreate","subscribe","execute","steps","length","step","id","settings","getAppUrl","contentReviewUrl","createContentReviewUrl","baseUrl","appUrl","contentReviewId","stepId","workflow","get","workflowId","WebinyError","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","sendContentReviewNotification","ex","error","message","code","data","stack","security","disableAuthorization","enableAuthorization"],"sources":["contentReviewAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { getAppUrl } from \"./appUrl\";\nimport { createContentReviewUrl } from \"./contentReviewUrl\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { sendContentReviewNotification } from \"./sendContentReviewNotification\";\n\nexport const attachContentReviewAfterCreate = (context: ApwContext): void => {\n context.apw.contentReview.onContentReviewAfterCreate.subscribe(async ({ contentReview }) => {\n const execute = async () => {\n if (contentReview.steps.length === 0) {\n return;\n }\n const [step] = contentReview.steps;\n if (!step?.id) {\n return;\n }\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n\n const contentReviewUrl = createContentReviewUrl({\n baseUrl: settings.appUrl,\n contentReviewId: contentReview.id,\n stepId: step.id\n });\n if (!contentReviewUrl) {\n return;\n }\n\n /**\n * We go and check the workflow.\n */\n const workflow = await context.apw.workflow.get(contentReview.workflowId);\n if (!workflow) {\n throw new WebinyError(\n `There is no workflow with Id \"${contentReview.workflowId}\".`,\n \"WORKFLOW_NOT_FOUND\",\n {\n workflowId: contentReview.workflowId\n }\n );\n }\n\n const contentUrl = createContentUrl({\n plugins: context.plugins,\n baseUrl: settings.appUrl,\n contentReview,\n workflow\n });\n if (!contentUrl) {\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [contentReview.createdBy.id]\n });\n if (reviewers.length === 0) {\n return;\n }\n\n try {\n await sendContentReviewNotification({\n context,\n reviewers,\n contentReview,\n workflow,\n contentReviewUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send content review notifications.`,\n \"CONTENT_REVIEW_NOTIFICATIONS_NOT_SENT\",\n {\n workflowId: workflow.id,\n contentReviewId: contentReview.id,\n contentReviewUrl,\n contentUrl,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n }\n );\n }\n };\n\n try {\n context.security.disableAuthorization();\n await execute();\n } catch (ex) {\n throw ex;\n } finally {\n context.security.enableAuthorization();\n }\n });\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AAEO,MAAMA,8BAA8B,GAAIC,OAAmB,IAAW;EACzEA,OAAO,CAACC,GAAG,CAACC,aAAa,CAACC,0BAA0B,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IACxF,MAAMG,OAAO,GAAG,YAAY;MACxB,IAAIH,aAAa,CAACI,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;QAClC;MACJ;MACA,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;UAChC7B,OAAO;UACPyB,SAAS;UACTvB,aAAa;UACbgB,QAAQ;UACRN,gBAAgB;UAChBU;QACJ,CAAC,CAAC;MACN,CAAC,CAAC,OAAOQ,EAAE,EAAE;QACT,MAAM,IAAIT,cAAW,CAChB,8CAA6C,EAC9C,uCAAuC,EACvC;UACID,UAAU,EAAEF,QAAQ,CAACT,EAAE;UACvBO,eAAe,EAAEd,aAAa,CAACO,EAAE;UACjCG,gBAAgB;UAChBU,UAAU;UACVS,KAAK,EAAE;YACHC,OAAO,EAAEF,EAAE,CAACE,OAAO;YACnBC,IAAI,EAAEH,EAAE,CAACG,IAAI;YACbC,IAAI,EAAEJ,EAAE,CAACI,IAAI;YACbC,KAAK,EAAEL,EAAE,CAACK;UACd;QACJ,CAAC,CACJ;MACL;IACJ,CAAC;IAED,IAAI;MACAnC,OAAO,CAACoC,QAAQ,CAACC,oBAAoB,EAAE;MACvC,MAAMhC,OAAO,EAAE;IACnB,CAAC,CAAC,OAAOyB,EAAE,EAAE;MACT,MAAMA,EAAE;IACZ,CAAC,SAAS;MACN9B,OAAO,CAACoC,QAAQ,CAACE,mBAAmB,EAAE;IAC1C;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["attachContentReviewAfterCreate","context","apw","contentReview","onContentReviewAfterCreate","subscribe","execute","steps","length","step","id","settings","getAppUrl","contentReviewUrl","createContentReviewUrl","baseUrl","appUrl","contentReviewId","stepId","workflow","get","workflowId","WebinyError","contentUrl","createContentUrl","plugins","reviewers","fetchReviewers","exclude","createdBy","sendContentReviewNotification","ex","error","message","code","data","stack","security","withoutAuthorization"],"sources":["contentReviewAfterCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { ApwContext } from \"~/types\";\nimport { getAppUrl } from \"./appUrl\";\nimport { createContentReviewUrl } from \"./contentReviewUrl\";\nimport { createContentUrl } from \"./contentUrl\";\nimport { fetchReviewers } from \"./reviewers\";\nimport { sendContentReviewNotification } from \"./sendContentReviewNotification\";\n\nexport const attachContentReviewAfterCreate = (context: ApwContext): void => {\n context.apw.contentReview.onContentReviewAfterCreate.subscribe(async ({ contentReview }) => {\n const execute = async () => {\n if (contentReview.steps.length === 0) {\n return;\n }\n const [step] = contentReview.steps;\n if (!step?.id) {\n return;\n }\n const settings = await getAppUrl(context);\n if (!settings) {\n return;\n }\n\n const contentReviewUrl = createContentReviewUrl({\n baseUrl: settings.appUrl,\n contentReviewId: contentReview.id,\n stepId: step.id\n });\n if (!contentReviewUrl) {\n return;\n }\n\n /**\n * We go and check the workflow.\n */\n const workflow = await context.apw.workflow.get(contentReview.workflowId);\n if (!workflow) {\n throw new WebinyError(\n `There is no workflow with Id \"${contentReview.workflowId}\".`,\n \"WORKFLOW_NOT_FOUND\",\n {\n workflowId: contentReview.workflowId\n }\n );\n }\n\n const contentUrl = createContentUrl({\n plugins: context.plugins,\n baseUrl: settings.appUrl,\n contentReview,\n workflow\n });\n if (!contentUrl) {\n return;\n }\n\n const reviewers = await fetchReviewers({\n context,\n workflow,\n exclude: [contentReview.createdBy.id]\n });\n if (reviewers.length === 0) {\n return;\n }\n\n try {\n await sendContentReviewNotification({\n context,\n reviewers,\n contentReview,\n workflow,\n contentReviewUrl,\n contentUrl\n });\n } catch (ex) {\n throw new WebinyError(\n `Could not send content review notifications.`,\n \"CONTENT_REVIEW_NOTIFICATIONS_NOT_SENT\",\n {\n workflowId: workflow.id,\n contentReviewId: contentReview.id,\n contentReviewUrl,\n contentUrl,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n }\n );\n }\n };\n\n await context.security.withoutAuthorization(async () => {\n return execute();\n });\n });\n};\n"],"mappings":";;;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AAEO,MAAMA,8BAA8B,GAAIC,OAAmB,IAAW;EACzEA,OAAO,CAACC,GAAG,CAACC,aAAa,CAACC,0BAA0B,CAACC,SAAS,CAAC,OAAO;IAAEF;EAAc,CAAC,KAAK;IACx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ACF,IAAIgB,SAAS,CAAClB,MAAM,KAAK,CAAC,EAAE;QACxB;MACJ;MAEA,IAAI;QACA,MAAM,IAAAsB,4DAA6B,EAAC;UAChC7B,OAAO;UACPyB,SAAS;UACTvB,aAAa;UACbgB,QAAQ;UACRN,gBAAgB;UAChBU;QACJ,CAAC,CAAC;MACN,CAAC,CAAC,OAAOQ,EAAE,EAAE;QACT,MAAM,IAAIT,cAAW,CAChB,8CAA6C,EAC9C,uCAAuC,EACvC;UACID,UAAU,EAAEF,QAAQ,CAACT,EAAE;UACvBO,eAAe,EAAEd,aAAa,CAACO,EAAE;UACjCG,gBAAgB;UAChBU,UAAU;UACVS,KAAK,EAAE;YACHC,OAAO,EAAEF,EAAE,CAACE,OAAO;YACnBC,IAAI,EAAEH,EAAE,CAACG,IAAI;YACbC,IAAI,EAAEJ,EAAE,CAACI,IAAI;YACbC,KAAK,EAAEL,EAAE,CAACK;UACd;QACJ,CAAC,CACJ;MACL;IACJ,CAAC;IAED,MAAMnC,OAAO,CAACoC,QAAQ,CAACC,oBAAoB,CAAC,YAAY;MACpD,OAAOhC,OAAO,EAAE;IACpB,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -25,20 +25,21 @@ const fetchReviewers = async params => {
25
25
  exclude
26
26
  } = params;
27
27
  const idList = getReviewerIdList(workflow);
28
- context.security.disableAuthorization();
29
- const [reviewers] = await context.apw.reviewer.list({
30
- where: {
31
- id_in: idList
32
- },
33
- limit: 10000
34
- });
35
- return reviewers.filter(item => {
36
- if (!item.email) {
37
- return false;
38
- } else if (exclude.includes(item.identityId)) {
39
- return false;
40
- }
41
- return true;
28
+ return context.security.withoutAuthorization(async () => {
29
+ const [reviewers] = await context.apw.reviewer.list({
30
+ where: {
31
+ id_in: idList
32
+ },
33
+ limit: 10000
34
+ });
35
+ return reviewers.filter(item => {
36
+ if (!item.email) {
37
+ return false;
38
+ } else if (exclude.includes(item.identityId)) {
39
+ return false;
40
+ }
41
+ return true;
42
+ });
42
43
  });
43
44
  };
44
45
  exports.fetchReviewers = fetchReviewers;
@@ -1 +1 @@
1
- {"version":3,"names":["getReviewerIdList","steps","reduce","collection","step","reviewer","reviewers","includes","id","push","fetchReviewers","params","context","workflow","exclude","idList","security","disableAuthorization","apw","list","where","id_in","limit","filter","item","email","identityId"],"sources":["reviewers.ts"],"sourcesContent":["import { ApwContext, ApwReviewerWithEmail, ApwWorkflow, ApwWorkflowStep } from \"~/types\";\n\ninterface GetReviewerIdListParams {\n steps: ApwWorkflowStep[];\n}\ninterface GetReviewerIdList {\n (params: GetReviewerIdListParams): string[];\n}\nexport const getReviewerIdList: GetReviewerIdList = ({ steps }) => {\n return steps.reduce<string[]>((collection, step) => {\n for (const reviewer of step.reviewers) {\n if (collection.includes(reviewer.id)) {\n return collection;\n }\n collection.push(reviewer.id);\n }\n\n return collection;\n }, []);\n};\n\ninterface FetchReviewersParams {\n context: ApwContext;\n workflow: ApwWorkflow;\n exclude: string[];\n}\nexport const fetchReviewers = async (\n params: FetchReviewersParams\n): Promise<ApwReviewerWithEmail[]> => {\n const { context, workflow, exclude } = params;\n\n const idList = getReviewerIdList(workflow);\n\n context.security.disableAuthorization();\n\n const [reviewers] = await context.apw.reviewer.list({\n where: {\n id_in: idList\n },\n limit: 10000\n });\n return reviewers.filter(item => {\n if (!item.email) {\n return false;\n } else if (exclude.includes(item.identityId)) {\n return false;\n }\n\n return true;\n }) as ApwReviewerWithEmail[];\n};\n"],"mappings":";;;;;;AAQO,MAAMA,iBAAoC,GAAG,CAAC;EAAEC;AAAM,CAAC,KAAK;EAC/D,OAAOA,KAAK,CAACC,MAAM,CAAW,CAACC,UAAU,EAAEC,IAAI,KAAK;IAChD,KAAK,MAAMC,QAAQ,IAAID,IAAI,CAACE,SAAS,EAAE;MACnC,IAAIH,UAAU,CAACI,QAAQ,CAACF,QAAQ,CAACG,EAAE,CAAC,EAAE;QAClC,OAAOL,UAAU;MACrB;MACAA,UAAU,CAACM,IAAI,CAACJ,QAAQ,CAACG,EAAE,CAAC;IAChC;IAEA,OAAOL,UAAU;EACrB,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AAAC;AAOK,MAAMO,cAAc,GAAG,MAC1BC,MAA4B,IACM;EAClC,MAAM;IAAEC,OAAO;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAE7C,MAAMI,MAAM,GAAGf,iBAAiB,CAACa,QAAQ,CAAC;EAE1CD,OAAO,CAACI,QAAQ,CAACC,oBAAoB,EAAE;EAEvC,MAAM,CAACX,SAAS,CAAC,GAAG,MAAMM,OAAO,CAACM,GAAG,CAACb,QAAQ,CAACc,IAAI,CAAC;IAChDC,KAAK,EAAE;MACHC,KAAK,EAAEN;IACX,CAAC;IACDO,KAAK,EAAE;EACX,CAAC,CAAC;EACF,OAAOhB,SAAS,CAACiB,MAAM,CAACC,IAAI,IAAI;IAC5B,IAAI,CAACA,IAAI,CAACC,KAAK,EAAE;MACb,OAAO,KAAK;IAChB,CAAC,MAAM,IAAIX,OAAO,CAACP,QAAQ,CAACiB,IAAI,CAACE,UAAU,CAAC,EAAE;MAC1C,OAAO,KAAK;IAChB;IAEA,OAAO,IAAI;EACf,CAAC,CAAC;AACN,CAAC;AAAC"}
1
+ {"version":3,"names":["getReviewerIdList","steps","reduce","collection","step","reviewer","reviewers","includes","id","push","fetchReviewers","params","context","workflow","exclude","idList","security","withoutAuthorization","apw","list","where","id_in","limit","filter","item","email","identityId"],"sources":["reviewers.ts"],"sourcesContent":["import { ApwContext, ApwReviewerWithEmail, ApwWorkflow, ApwWorkflowStep } from \"~/types\";\n\ninterface GetReviewerIdListParams {\n steps: ApwWorkflowStep[];\n}\n\ninterface GetReviewerIdList {\n (params: GetReviewerIdListParams): string[];\n}\n\nexport const getReviewerIdList: GetReviewerIdList = ({ steps }) => {\n return steps.reduce<string[]>((collection, step) => {\n for (const reviewer of step.reviewers) {\n if (collection.includes(reviewer.id)) {\n return collection;\n }\n collection.push(reviewer.id);\n }\n\n return collection;\n }, []);\n};\n\ninterface FetchReviewersParams {\n context: ApwContext;\n workflow: ApwWorkflow;\n exclude: string[];\n}\n\nexport const fetchReviewers = async (\n params: FetchReviewersParams\n): Promise<ApwReviewerWithEmail[]> => {\n const { context, workflow, exclude } = params;\n\n const idList = getReviewerIdList(workflow);\n\n return context.security.withoutAuthorization(async () => {\n const [reviewers] = await context.apw.reviewer.list({\n where: {\n id_in: idList\n },\n limit: 10000\n });\n return reviewers.filter((item): item is ApwReviewerWithEmail => {\n if (!item.email) {\n return false;\n } else if (exclude.includes(item.identityId)) {\n return false;\n }\n\n return true;\n });\n });\n};\n"],"mappings":";;;;;;AAUO,MAAMA,iBAAoC,GAAG,CAAC;EAAEC;AAAM,CAAC,KAAK;EAC/D,OAAOA,KAAK,CAACC,MAAM,CAAW,CAACC,UAAU,EAAEC,IAAI,KAAK;IAChD,KAAK,MAAMC,QAAQ,IAAID,IAAI,CAACE,SAAS,EAAE;MACnC,IAAIH,UAAU,CAACI,QAAQ,CAACF,QAAQ,CAACG,EAAE,CAAC,EAAE;QAClC,OAAOL,UAAU;MACrB;MACAA,UAAU,CAACM,IAAI,CAACJ,QAAQ,CAACG,EAAE,CAAC;IAChC;IAEA,OAAOL,UAAU;EACrB,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AAAC;AAQK,MAAMO,cAAc,GAAG,MAC1BC,MAA4B,IACM;EAClC,MAAM;IAAEC,OAAO;IAAEC,QAAQ;IAAEC;EAAQ,CAAC,GAAGH,MAAM;EAE7C,MAAMI,MAAM,GAAGf,iBAAiB,CAACa,QAAQ,CAAC;EAE1C,OAAOD,OAAO,CAACI,QAAQ,CAACC,oBAAoB,CAAC,YAAY;IACrD,MAAM,CAACX,SAAS,CAAC,GAAG,MAAMM,OAAO,CAACM,GAAG,CAACb,QAAQ,CAACc,IAAI,CAAC;MAChDC,KAAK,EAAE;QACHC,KAAK,EAAEN;MACX,CAAC;MACDO,KAAK,EAAE;IACX,CAAC,CAAC;IACF,OAAOhB,SAAS,CAACiB,MAAM,CAAEC,IAAI,IAAmC;MAC5D,IAAI,CAACA,IAAI,CAACC,KAAK,EAAE;QACb,OAAO,KAAK;MAChB,CAAC,MAAM,IAAIX,OAAO,CAACP,QAAQ,CAACiB,IAAI,CAACE,UAAU,CAAC,EAAE;QAC1C,OAAO,KAAK;MAChB;MAEA,OAAO,IAAI;IACf,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC;AAAC"}
@@ -9,5 +9,5 @@ export interface HandlerArgs {
9
9
  interface Configuration {
10
10
  storageOperations: ApwScheduleActionStorageOperations;
11
11
  }
12
- export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler").EventPlugin<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
12
+ export declare const executeActionHandlerPlugins: (config: Configuration) => ((import("@webiny/db-dynamodb/plugins/definitions/ValueFilterPlugin").ValueFilterPlugin[][] | import("@webiny/handler").HandlerResultPlugin<import("@webiny/handler/types").Context> | ContextPlugin<import("@webiny/handler-db/types").DbContext>[])[] | import("@webiny/handler-aws").RawEventHandler<HandlerArgs, import("@webiny/handler/types").Context, any> | ContextPlugin<import("@webiny/api/types").Context>)[];
13
13
  export {};
@@ -9,7 +9,7 @@ var _api = require("@webiny/api");
9
9
  var _PageBuilderGraphQL = require("./plugins/PageBuilderGraphQL");
10
10
  var _HeadlessCMSGraphQL = require("./plugins/HeadlessCMSGraphQL");
11
11
  var _ApplicationGraphQL = require("./plugins/ApplicationGraphQL");
12
- var _handler = require("@webiny/handler");
12
+ var _handlerAws = require("@webiny/handler-aws");
13
13
  /**
14
14
  * Handler that execute the provided action(s) for the schedule action workflow.
15
15
  */
@@ -17,7 +17,7 @@ const createExecuteActionLambda = params => {
17
17
  const {
18
18
  storageOperations
19
19
  } = params;
20
- return (0, _handler.createEvent)(async ({
20
+ return (0, _handlerAws.createRawEventHandler)(async ({
21
21
  payload,
22
22
  context
23
23
  }) => {
@@ -111,7 +111,7 @@ const createExecuteActionLambda = params => {
111
111
  console.log(JSON.stringify(item));
112
112
  continue;
113
113
  }
114
-
114
+ console.log(`Invoking Lambda "${name}" with url "${url}".`);
115
115
  // Perform the actual action call.
116
116
  const response = await context.handlerClient.invoke({
117
117
  name,
@@ -132,9 +132,26 @@ const createExecuteActionLambda = params => {
132
132
  },
133
133
  await: true
134
134
  });
135
+ /**
136
+ *
137
+ */
138
+ await storageOperations.delete({
139
+ locale,
140
+ tenant,
141
+ id: item.id
142
+ });
143
+ /**
144
+ * Check for the response and log the error if any.
145
+ */
135
146
  if (response !== null && response !== void 0 && response.body) {
147
+ var _response$body$data, _response$body$data$c;
148
+ const error = (_response$body$data = response.body.data) === null || _response$body$data === void 0 ? void 0 : (_response$body$data$c = _response$body$data.content) === null || _response$body$data$c === void 0 ? void 0 : _response$body$data$c.error;
149
+ if (!error) {
150
+ console.log("Invoke successful.");
151
+ continue;
152
+ }
136
153
  console.log(JSON.stringify({
137
- body: response.body
154
+ error
138
155
  }, null, 2));
139
156
  continue;
140
157
  }
@@ -144,8 +161,12 @@ const createExecuteActionLambda = params => {
144
161
 
145
162
  // TODO: Maybe update the status like error in original item in DB.
146
163
  }
147
- } catch (e) {
148
- log("[HANDLER_EXECUTE_ACTION] Error => ", e);
164
+ } catch (ex) {
165
+ console.error("[HANDLER_EXECUTE_ACTION] => ", JSON.stringify({
166
+ message: ex.message,
167
+ code: ex.code,
168
+ data: ex.data
169
+ }));
149
170
  // TODO: Maybe update the status like error in original item in DB.
150
171
  }
151
172
  });
@@ -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","url","getUrl","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 url = plugin.getUrl({\n locale,\n tenant\n });\n if (!url) {\n console.error(\n `There is no url defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\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: url,\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,GAA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I,CAACR;cACjB,CAAC,CAAC;cACF,CAAC,UAAU,GAAGA,MAAM;cACpB,CAAC,eAAe,GAAI,WAAUD,MAAO,YAAWA,MAAO;YAC3D,CAAC;YACDkB,IAAI,EAAEP,IAAI,CAACC,SAAS,CAACM,IAAI;UAC7B,CAAC;UACDW,KAAK,EAAE;QACX,CAAC,CAAC;QACF,IAAIT,QAAQ,aAARA,QAAQ,eAARA,QAAQ,CAAEF,IAAI,EAAE;UAChBnC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;YAAEM,IAAI,EAAEE,QAAQ,CAACF;UAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;UAC7D;QACJ;QACAnC,OAAO,CAACD,GAAG,CAAC6B,IAAI,CAACC,SAAS,CAAC;UAAEQ;QAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;;QAElD;MACJ;IACJ,CAAC,CAAC,OAAOU,CAAC,EAAE;MACRhD,GAAG,CAAC,oCAAoC,EAAEgD,CAAC,CAAC;MAC5C;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAMC,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMpD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAACiD,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,EAAE,EAAE,IAAIC,sCAAkB,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,GAAE,EACb7D,yBAAyB,CAACwD,MAAM,CAAC,CACpC;AAAC"}
1
+ {"version":3,"names":["createExecuteActionLambda","params","storageOperations","createRawEventHandler","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","url","getUrl","body","getGraphQLBody","response","handlerClient","invoke","httpMethod","path","headers","Authorization","encodeToken","id","await","delete","content","ex","message","code","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 { createRawEventHandler } from \"@webiny/handler-aws\";\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 createRawEventHandler<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 url = plugin.getUrl({\n locale,\n tenant\n });\n if (!url) {\n console.error(\n `There is no url defined, in the Plugin, for type \"${item.data.type}\".`\n );\n console.log(JSON.stringify(item));\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 console.log(`Invoking Lambda \"${name}\" with url \"${url}\".`);\n // Perform the actual action call.\n const response = await context.handlerClient.invoke({\n name,\n payload: {\n httpMethod: \"POST\",\n path: url,\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 /**\n *\n */\n await storageOperations.delete({\n locale,\n tenant,\n id: item.id\n });\n /**\n * Check for the response and log the error if any.\n */\n if (response?.body) {\n const error = response.body.data?.content?.error;\n if (!error) {\n console.log(\"Invoke successful.\");\n continue;\n }\n console.log(JSON.stringify({ error }, 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 (ex) {\n console.error(\n \"[HANDLER_EXECUTE_ACTION] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\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,iCAAqB,EAAc,OAAO;IAAEC,OAAO;IAAEC;EAAQ,CAAC,KAAK;IACtE,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,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AAE,CAACC,OAAO;QACnBC,IAAI,EAAEF,EAAE,CAACE,IAAI;QACbzC,IAAI,EAAEuC,EAAE,CAACvC;MACb,CAAC,CAAC,CACL;MACD;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;;AAEM,MAAM0C,2BAA2B,GAAIC,MAAqB,IAAK,CAClE,IAAIC,kBAAa,CAAC,MAAMxD,OAAO,IAAI;EAC/BA,OAAO,CAACI,OAAO,CAACqD,QAAQ,CAAC,CAAC,IAAIC,sCAAkB,EAAE,EAAE,IAAIC,sCAAkB,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC,EACF,IAAAC,kBAAW,GAAE,EACbjE,yBAAyB,CAAC4D,MAAM,CAAC,CACpC;AAAC"}
@@ -134,7 +134,11 @@ const createScheduleActionLambda = params => {
134
134
  item: nextItem
135
135
  });
136
136
  } catch (ex) {
137
- log("[HANDLER_CREATE_RULE] Error => ", ex);
137
+ console.error("[HANDLER_CREATE_RULE] => ", JSON.stringify({
138
+ message: ex.message,
139
+ code: ex.code,
140
+ data: ex.data
141
+ }));
138
142
  // TODO: Handler error. Maybe save it into DB.
139
143
  }
140
144
  });
@@ -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":";;;;;;;;AAIA;AAMA;AAMA;AAhBA;AACA;AACA;AAFA,IAkBYA,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe;AAoB3B,MAAMC,GAAG,GAAGC,OAAO,CAACD,GAAG;;AAEvB;AACA;AACA;AACA,MAAME,0BAA0B,GAAIC,MAAqB,IAAK;EAC1D,MAAM;IAAEC,QAAQ,EAAEC,qBAAqB;IAAEC,iBAAiB;IAAEC;EAAS,CAAC,GAAGJ,MAAM;EAE/E,OAAO,IAAAK,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC,OAAO;IAAEC,aAAa,EAAEC;EAAa,CAAC,KAAK;IACzD,IAAI;MACA,MAAM;QAAEC,MAAM;QAAEC,MAAM;QAAEC;MAAe,CAAC,GAA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CAAC+B,MAAM,CAAC;QAC3BC,IAAI,8DACGb,QAAQ;UACXK,IAAI,8DAAOL,QAAQ,CAACK,IAAI;YAAEC,QAAQ,EAAEI;UAAc;QAAE,EACvD;QACDI,KAAK,8DAAOd,QAAQ,CAACK,IAAI;UAAEC,QAAQ,EAAEI;QAAc;MACvD,CAAC,CAAC;MACF;AAChB;AACA;MACgB,IACIH,mBAAmB,IACnB,IAAAQ,4BAAqB,EAAC;QAClBzB,cAAc;QACdgB,QAAQ,EAAEC;MACd,CAAC,CAAC,EACJ;QACE,MAAM,IAAAS,+BAAe,EAAC;UAClB3B,MAAM;UACND,MAAM;UACN6B,IAAI,EAAEpB,WAAW;UACjBhB;QACJ,CAAC,CAAC;MACN;MACA;AAChB;AACA;MACgBN,GAAG,CAAE,8BAA6B,CAAC;MACnC,MAAM,IAAA2C,uCAAuB,EAAC;QAC1BtC,qBAAqB;QACrBuC,kBAAkB,EAAEhC,YAAY,CAACgC,kBAAkB;QACnDb,QAAQ,EAAEN,QAAQ,CAACK,IAAI,CAACC,QAAQ;QAChCI,cAAc,EAAEA,cAAc;QAC9BrB,MAAM;QACND;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
+ {"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","error","JSON","stringify","message","code","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 console.error(\n \"[HANDLER_CREATE_RULE] => \",\n JSON.stringify({\n message: ex.message,\n code: ex.code,\n data: ex.data\n })\n );\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":";;;;;;;;AAIA;AAMA;AAMA;AAhBA;AACA;AACA;AAFA,IAkBYA,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,e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;IACjE,CAAC,CAAC,OAAOqB,EAAE,EAAE;MACT7C,OAAO,CAAC8C,KAAK,CACT,2BAA2B,EAC3BC,IAAI,CAACC,SAAS,CAAC;QACXC,OAAO,EAAEJ,EAAE,CAACI,OAAO;QACnBC,IAAI,EAAEL,EAAE,CAACK,IAAI;QACbrB,IAAI,EAAEgB,EAAE,CAAChB;MACb,CAAC,CAAC,CACL;MACD;IACJ;EACJ,CAAC,CACJ;AACL,CAAC;;AAEM,MAAMsB,4BAA4B,GAAIC,MAAqB,IAAK,CACnE,IAAAC,kBAAW,GAAE,EACbpD,0BAA0B,CAACmD,MAAM,CAAC,CACrC;AAAC"}
@@ -134,6 +134,8 @@ const executeTask = async ({
134
134
  },
135
135
  await: false
136
136
  });
137
+ } else {
138
+ console.log(`context.handlerClient.invoke is not a function!`);
137
139
  }
138
140
 
139
141
  /**
@@ -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"],"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AChD,CAAC,CAAC;EACN;AACJ,CAAC;AAAC;AASK,MAAMK,WAAW,GAAG,OAAO;EAC9BC,IAAI;EACJC,UAAU;EACVC,aAAa;EACbb;AACe,CAAC,KAAoB;EACpC/C,GAAG,CAAE,qBAAoB,EAAE,IAAI6D,IAAI,EAAE,CAACC,WAAW,EAAE,CAAC;EAEpD,IAAI,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"}
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 } else {\n console.log(`context.handlerClient.invoke is not a function!`);\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,EAAE;EAC9B,MAAM;IAAEC,aAAa;IAAEC;EAAc,CAAC,GAAG,MAAM,IAAAC,qBAAc,GAAE;EAC/D;AACJ;AACA;EACI,MAAMC,oBAAoB,GAAG,IAAIC,4CAAoB,CAAC;IAClDC,IAAI,EAAEJ,aAAa;IACnBK,GAAG,EAAE,CAACN,aAAa;EACvB,CAAC,CAAC;EACF,MAAMO,qBAAqB,GAAG,MAAMb,qBAAqB,CAACc,IAAI,CAACL,oBAAoB,CAAC;EACpF;AACJ;AACA;EACI,IACI,OAAOI,qBAAqB,CAACE,gBAAgB,KAAK,QAAQ,IAC1DF,qBAAqB,CAACE,gBAAgB,KAAK,CAAC,EAC9C;IACEjB,OAAO,CAACkB,IAAI,CAAC,iCAAiC,CAAC;IAC/ClB,OAAO,CAACkB,IAAI,CAACH,qBAAqB,CAACI,aAAa,CAAC;EACrD;EACA;AACJ;AACA;EACI,MAAMC,iBAAiB,GAAG,IAAIC,yCAAiB,CAAC;IAC5CC,IAAI,EAAEb;EACV,CAAC,CAAC;EACF,MAAMP,qBAAqB,CAACc,IAAI,CAACI,iBA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}
@@ -3,6 +3,7 @@ import { SecurityIdentity, SecurityPermission } from "@webiny/api-security/types
3
3
  import { I18NLocale, I18NContext } from "@webiny/api-i18n/types";
4
4
  import { Tenant } from "@webiny/api-tenancy/types";
5
5
  import { TenancyContext } from "@webiny/api-tenancy/types";
6
+ import { ApwIdentity } from "../types";
6
7
  export interface ListWhere {
7
8
  /**
8
9
  * Fields.
@@ -29,25 +30,6 @@ export interface ListParams {
29
30
  limit?: number;
30
31
  after?: string;
31
32
  }
32
- /**
33
- * A interface describing the reference to a user that created some data in the database.
34
- *
35
- * @category General
36
- */
37
- export interface CreatedBy {
38
- /**
39
- * ID if the user.
40
- */
41
- id: string;
42
- /**
43
- * Full name of the user.
44
- */
45
- displayName: string | null;
46
- /**
47
- * Type of the user (admin, user)
48
- */
49
- type: string;
50
- }
51
33
  export interface ListMeta {
52
34
  /**
53
35
  * A cursor for pagination.
@@ -70,7 +52,7 @@ export interface BaseFields {
70
52
  id: string;
71
53
  createdOn: string;
72
54
  savedOn?: string;
73
- createdBy: CreatedBy;
55
+ createdBy: ApwIdentity;
74
56
  tenant: string;
75
57
  locale: string;
76
58
  }
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.InvocationTypes = exports.ApwScheduleActionTypes = exports.ApwContentTypes = void 0;
7
- /**
8
- * A interface describing the reference to a user that created some data in the database.
9
- *
10
- * @category General
11
- */
12
7
  let ApwContentTypes;
13
8
  exports.ApwContentTypes = ApwContentTypes;
14
9
  (function (ApwContentTypes) {
@@ -1 +1 @@
1
- {"version":3,"names":["ApwContentTypes","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\n/**\n * A interface describing the reference to a user that created some data in the database.\n *\n * @category General\n */\nexport interface CreatedBy {\n /**\n * ID if the user.\n */\n id: string;\n /**\n * Full name of the user.\n */\n displayName: string | null;\n /**\n * Type of the user (admin, user)\n */\n type: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: CreatedBy;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;AAkCA;AACA;AACA;AACA;AACA;AAJA,IAmCYA,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe;AAAA,IAkBfC,sBAAsB;AAAA;AAAA,WAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;AAAA,GAAtBA,sBAAsB,sCAAtBA,sBAAsB;AAAA,IAiBtBC,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe"}
1
+ {"version":3,"names":["ApwContentTypes","ApwScheduleActionTypes","InvocationTypes"],"sources":["types.ts"],"sourcesContent":["import { Context } from \"@webiny/api/types\";\nimport { SecurityIdentity, SecurityPermission } from \"@webiny/api-security/types\";\nimport { I18NLocale, I18NContext } from \"@webiny/api-i18n/types\";\nimport { Tenant } from \"@webiny/api-tenancy/types\";\nimport { TenancyContext } from \"@webiny/api-tenancy/types\";\nimport { ApwIdentity } from \"~/types\";\n\nexport interface ListWhere {\n /**\n * Fields.\n */\n id?: string;\n id_in?: string[];\n id_not?: string;\n id_not_in?: string[];\n /**\n * Who created the entry?\n */\n createdBy?: string;\n createdBy_not?: string;\n createdBy_in?: string[];\n createdBy_not_in?: string[];\n /**\n * By datetime field.\n */\n datetime_startsWith?: string;\n}\n\nexport interface ListParams {\n where: ListWhere;\n sort?: (\"datetime_ASC\" | \"datetime_DESC\")[];\n limit?: number;\n after?: string;\n}\n\nexport interface ListMeta {\n /**\n * A cursor for pagination.\n */\n cursor: string | null;\n /**\n * Is there more items to load?\n */\n hasMoreItems: boolean;\n /**\n * Total count of the items in the storage.\n */\n totalCount: number;\n}\n\nexport enum ApwContentTypes {\n PAGE = \"page\",\n CMS_ENTRY = \"cms_entry\"\n}\n\nexport interface BaseFields {\n id: string;\n createdOn: string;\n savedOn?: string;\n createdBy: ApwIdentity;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleAction extends BaseFields {\n data: ApwScheduleActionData;\n}\n\nexport enum ApwScheduleActionTypes {\n PUBLISH = \"publish\",\n UNPUBLISH = \"unpublish\"\n}\n\nexport interface ApwScheduleActionData {\n action: ApwScheduleActionTypes;\n type: ApwContentTypes;\n datetime: string;\n entryId: string;\n /**\n * We will add modelId to the data for now.\n * TODO extract in separate package?\n */\n modelId?: string;\n}\n\nexport enum InvocationTypes {\n SCHEDULED = \"scheduled\"\n}\n\ninterface BaseApwCrud<TEntry, TCreateEntryParams, TUpdateEntryParams> {\n get(id: string): Promise<TEntry | null>;\n\n create(data: TCreateEntryParams): Promise<TEntry>;\n\n update(id: string, data: TUpdateEntryParams): Promise<TEntry>;\n\n delete(id: string): Promise<Boolean>;\n}\n\nexport interface ApwScheduleActionCrud\n extends BaseApwCrud<ApwScheduleAction, ApwScheduleActionData, ApwScheduleActionData> {\n list(params: ListParams): Promise<[ApwScheduleAction[], ListMeta]>;\n\n getCurrentTask(): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(item: ApwScheduleAction): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(): Promise<Boolean>;\n}\n\nexport interface ScheduleActionContext extends Context, I18NContext, TenancyContext {\n scheduleAction: ApwScheduleActionCrud;\n}\n\nexport interface CreateScheduleActionParams {\n getLocale: () => I18NLocale;\n getIdentity: () => SecurityIdentity;\n getTenant: () => Tenant;\n getPermission: (name: string) => Promise<SecurityPermission | null>;\n storageOperations: ApwScheduleActionStorageOperations;\n}\n\ninterface CreateApwScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\ninterface StorageOperationsGetParams {\n where: {\n id: string;\n tenant: string;\n locale: string;\n };\n}\n\ninterface StorageOperationsDeleteParams {\n id: string;\n tenant: string;\n locale: string;\n}\n\nexport interface ApwScheduleActionListParams extends ListParams {\n where: ListWhere & {\n tenant: string;\n locale: string;\n };\n}\n\nexport type StorageOperationsGetScheduleActionParams = StorageOperationsGetParams;\n\nexport type StorageOperationsDeleteScheduleActionParams = StorageOperationsDeleteParams;\nexport type StorageOperationsListScheduleActionsParams = ApwScheduleActionListParams;\n\nexport type StorageOperationsCreateScheduleActionParams = CreateApwScheduleActionParams;\n\nexport interface StorageOperationsUpdateScheduleActionParams {\n item: ApwScheduleAction;\n input: ApwScheduleActionData;\n}\n\nexport type StorageOperationsListScheduleActionsResponse = [ApwScheduleAction[], ListMeta];\n\nexport interface StorageOperationsUpdateCurrentTaskParams {\n item: ApwScheduleAction;\n}\n\nexport interface StorageOperationsGetCurrentTaskParams {\n where: Pick<StorageOperationsGetParams[\"where\"], \"tenant\" | \"locale\">;\n}\n\nexport type StorageOperationsDeleteCurrentTaskParams = Pick<\n StorageOperationsDeleteParams,\n \"tenant\" | \"locale\"\n>;\n\nexport interface ApwScheduleActionStorageOperations {\n get(params: StorageOperationsGetScheduleActionParams): Promise<ApwScheduleAction | null>;\n\n list(\n params: StorageOperationsListScheduleActionsParams\n ): Promise<StorageOperationsListScheduleActionsResponse>;\n\n create(params: StorageOperationsCreateScheduleActionParams): Promise<ApwScheduleAction>;\n\n update(params: StorageOperationsUpdateScheduleActionParams): Promise<ApwScheduleAction>;\n\n delete(params: StorageOperationsDeleteScheduleActionParams): Promise<Boolean>;\n\n getCurrentTask(\n params: StorageOperationsGetCurrentTaskParams\n ): Promise<ApwScheduleAction | null>;\n\n updateCurrentTask(params: StorageOperationsUpdateCurrentTaskParams): Promise<ApwScheduleAction>;\n\n deleteCurrentTask(params: StorageOperationsDeleteCurrentTaskParams): Promise<Boolean>;\n}\n\nexport interface CreateApwContextParams {\n storageOperations: ApwScheduleActionStorageOperations;\n}\n"],"mappings":";;;;;;IAkDYA,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe;AAAA,IAkBfC,sBAAsB;AAAA;AAAA,WAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;AAAA,GAAtBA,sBAAsB,sCAAtBA,sBAAsB;AAAA,IAiBtBC,eAAe;AAAA;AAAA,WAAfA,eAAe;EAAfA,eAAe;AAAA,GAAfA,eAAe,+BAAfA,eAAe"}
@@ -16,9 +16,9 @@ const createChangeRequestStorageOperations = params => {
16
16
  security
17
17
  } = params;
18
18
  const getChangeRequestModel = async () => {
19
- security.disableAuthorization();
20
- const model = await cms.getModel("apwChangeRequestModelDefinition");
21
- security.enableAuthorization();
19
+ const model = await security.withoutAuthorization(async () => {
20
+ return cms.getModel("apwChangeRequestModelDefinition");
21
+ });
22
22
  if (!model) {
23
23
  throw new _error.default("Could not find `apwChangeRequestModelDefinition` model.", "MODEL_NOT_FOUND_ERROR");
24
24
  }
@@ -28,9 +28,9 @@ const createChangeRequestStorageOperations = params => {
28
28
  id
29
29
  }) => {
30
30
  const model = await getChangeRequestModel();
31
- security.disableAuthorization();
32
- const entry = await cms.getEntryById(model, id);
33
- security.enableAuthorization();
31
+ const entry = await security.withoutAuthorization(async () => {
32
+ return cms.getEntryById(model, id);
33
+ });
34
34
  return (0, _fieldResolver.getFieldValues)({
35
35
  entry,
36
36
  fields: _index.baseFields,
@@ -43,11 +43,11 @@ const createChangeRequestStorageOperations = params => {
43
43
  getChangeRequest,
44
44
  async listChangeRequests(params) {
45
45
  const model = await getChangeRequestModel();
46
- security.disableAuthorization();
47
- const [entries, meta] = await cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
48
- where: (0, _objectSpread2.default)({}, params.where)
49
- }));
50
- security.enableAuthorization();
46
+ const [entries, meta] = await security.withoutAuthorization(async () => {
47
+ return cms.listLatestEntries(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
48
+ where: (0, _objectSpread2.default)({}, params.where)
49
+ }));
50
+ });
51
51
  try {
52
52
  const all = await Promise.all(entries.map(entry => (0, _fieldResolver.getFieldValues)({
53
53
  entry,
@@ -62,9 +62,9 @@ const createChangeRequestStorageOperations = params => {
62
62
  },
63
63
  async createChangeRequest(params) {
64
64
  const model = await getChangeRequestModel();
65
- security.disableAuthorization();
66
- const entry = await cms.createEntry(model, params.data);
67
- security.enableAuthorization();
65
+ const entry = await security.withoutAuthorization(async () => {
66
+ return cms.createEntry(model, params.data);
67
+ });
68
68
  return (0, _fieldResolver.getFieldValues)({
69
69
  entry,
70
70
  fields: _index.baseFields,
@@ -81,9 +81,9 @@ const createChangeRequestStorageOperations = params => {
81
81
  const existingEntry = await getChangeRequest({
82
82
  id: params.id
83
83
  });
84
- security.disableAuthorization();
85
- const entry = await cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
86
- security.enableAuthorization();
84
+ const entry = await security.withoutAuthorization(async () => {
85
+ return cms.updateEntry(model, params.id, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, existingEntry), params.data));
86
+ });
87
87
  return (0, _fieldResolver.getFieldValues)({
88
88
  entry,
89
89
  fields: _index.baseFields,
@@ -93,9 +93,9 @@ const createChangeRequestStorageOperations = params => {
93
93
  },
94
94
  async deleteChangeRequest(params) {
95
95
  const model = await getChangeRequestModel();
96
- security.disableAuthorization();
97
- await cms.deleteEntry(model, params.id);
98
- security.enableAuthorization();
96
+ await security.withoutAuthorization(async () => {
97
+ return cms.deleteEntry(model, params.id);
98
+ });
99
99
  return true;
100
100
  }
101
101
  };
@@ -1 +1 @@
1
- {"version":3,"names":["createChangeRequestStorageOperations","params","cms","getCmsContext","security","getChangeRequestModel","disableAuthorization","model","getModel","enableAuthorization","WebinyError","getChangeRequest","id","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","listChangeRequests","entries","meta","listLatestEntries","where","all","Promise","map","ex","message","code","data","createChangeRequest","createEntry","updateChangeRequest","existingEntry","updateEntry","deleteChangeRequest","deleteEntry"],"sources":["changeRequestStorageOperations.ts"],"sourcesContent":["import { ApwChangeRequestStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwChangeRequest } from \"~/types\";\n\nexport const createChangeRequestStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwChangeRequestStorageOperations => {\n const { cms, getCmsContext, security } = params;\n const getChangeRequestModel = async () => {\n security.disableAuthorization();\n const model = await cms.getModel(\"apwChangeRequestModelDefinition\");\n security.enableAuthorization();\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwChangeRequestModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getChangeRequest: ApwChangeRequestStorageOperations[\"getChangeRequest\"] = async ({\n id\n }) => {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.getEntryById(model, id);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getChangeRequestModel,\n getChangeRequest,\n async listChangeRequests(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const [entries, meta] = await cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n security.enableAuthorization();\n try {\n const all = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwChangeRequest>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n return [all, meta];\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\n },\n async createChangeRequest(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n const entry = await cms.createEntry(model, params.data);\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async updateChangeRequest(params) {\n const model = await getChangeRequestModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getChangeRequest({ id: params.id });\n\n security.disableAuthorization();\n const entry = await cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n security.enableAuthorization();\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async deleteChangeRequest(params) {\n const model = await getChangeRequestModel();\n security.disableAuthorization();\n await cms.deleteEntry(model, params.id);\n security.enableAuthorization();\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AACA;AACA;AACA;AAGO,MAAMA,oCAAoC,GAC7CC,MAAwC,IACJ;EACpC,MAAM;IAAEC,GAAG;IAAEC,aAAa;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAC/C,MAAMI,qBAAqB,GAAG,YAAY;IACtCD,QAAQ,CAACE,oBAAoB,EAAE;IAC/B,MAAMC,KAAK,GAAG,MAAML,GAAG,CAACM,QAAQ,CAAC,iCAAiC,CAAC;IACnEJ,QAAQ,CAACK,mBAAmB,EAAE;IAC9B,IAAI,CAACF,KAAK,EAAE;MACR,MAAM,IAAIG,cAAW,CACjB,yDAAyD,EACzD,uBAAuB,CAC1B;IACL;IACA,OA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BAAmB,CAACrC,MAAM,EAAE;MAC9B,MAAMM,KAAK,GAAG,MAAMF,qBAAqB,EAAE;MAC3CD,QAAQ,CAACE,oBAAoB,EAAE;MAC/B,MAAMJ,GAAG,CAACqC,WAAW,CAAChC,KAAK,EAAEN,MAAM,CAACW,EAAE,CAAC;MACvCR,QAAQ,CAACK,mBAAmB,EAAE;MAC9B,OAAO,IAAI;IACf;EACJ,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["createChangeRequestStorageOperations","params","cms","getCmsContext","security","getChangeRequestModel","model","withoutAuthorization","getModel","WebinyError","getChangeRequest","id","entry","getEntryById","getFieldValues","fields","baseFields","context","transformers","getTransformer","listChangeRequests","entries","meta","listLatestEntries","where","all","Promise","map","ex","message","code","data","createChangeRequest","createEntry","updateChangeRequest","existingEntry","updateEntry","deleteChangeRequest","deleteEntry"],"sources":["changeRequestStorageOperations.ts"],"sourcesContent":["import { ApwChangeRequestStorageOperations } from \"./types\";\nimport { baseFields, CreateApwStorageOperationsParams } from \"~/storageOperations/index\";\nimport { getFieldValues, getTransformer } from \"~/utils/fieldResolver\";\nimport WebinyError from \"@webiny/error\";\nimport { ApwChangeRequest } from \"~/types\";\n\nexport const createChangeRequestStorageOperations = (\n params: CreateApwStorageOperationsParams\n): ApwChangeRequestStorageOperations => {\n const { cms, getCmsContext, security } = params;\n const getChangeRequestModel = async () => {\n const model = await security.withoutAuthorization(async () => {\n return cms.getModel(\"apwChangeRequestModelDefinition\");\n });\n if (!model) {\n throw new WebinyError(\n \"Could not find `apwChangeRequestModelDefinition` model.\",\n \"MODEL_NOT_FOUND_ERROR\"\n );\n }\n return model;\n };\n const getChangeRequest: ApwChangeRequestStorageOperations[\"getChangeRequest\"] = async ({\n id\n }) => {\n const model = await getChangeRequestModel();\n\n const entry = await security.withoutAuthorization(async () => {\n return cms.getEntryById(model, id);\n });\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n };\n return {\n getChangeRequestModel,\n getChangeRequest,\n async listChangeRequests(params) {\n const model = await getChangeRequestModel();\n\n const [entries, meta] = await security.withoutAuthorization(async () => {\n return cms.listLatestEntries(model, {\n ...params,\n where: {\n ...params.where\n }\n });\n });\n try {\n const all = await Promise.all(\n entries.map(entry =>\n getFieldValues<ApwChangeRequest>({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n })\n )\n );\n return [all, meta];\n } catch (ex) {\n throw new WebinyError(ex.message, ex.code, ex.data);\n }\n },\n async createChangeRequest(params) {\n const model = await getChangeRequestModel();\n\n const entry = await security.withoutAuthorization(async () => {\n return cms.createEntry(model, params.data);\n });\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async updateChangeRequest(params) {\n const model = await getChangeRequestModel();\n /**\n * We're fetching the existing entry here because we're not accepting \"app\" field as input,\n * but, we still need to retain its value after the \"update\" operation.\n */\n const existingEntry = await getChangeRequest({ id: params.id });\n\n const entry = await security.withoutAuthorization(async () => {\n return cms.updateEntry(model, params.id, {\n ...existingEntry,\n ...params.data\n });\n });\n return getFieldValues({\n entry,\n fields: baseFields,\n context: getCmsContext(),\n transformers: [getTransformer(model, \"body\")]\n });\n },\n async deleteChangeRequest(params) {\n const model = await getChangeRequestModel();\n\n await security.withoutAuthorization(async () => {\n return cms.deleteEntry(model, params.id);\n });\n return true;\n }\n };\n};\n"],"mappings":";;;;;;;;AACA;AACA;AACA;AAGO,MAAMA,oCAAoC,GAC7CC,MAAwC,IACJ;EACpC,MAAM;IAAEC,GAAG;IAAEC,aAAa;IAAEC;EAAS,CAAC,GAAGH,MAAM;EAC/C,MAAMI,qBAAqB,GAAG,YAAY;IACtC,MAAMC,KAAK,GAAG,MAAMF,QAAQ,CAACG,oBAAoB,CAAC,YAAY;MAC1D,OAAOL,GAAG,CAACM,QAAQ,CAAC,iCAAiC,CAAC;IAC1D,CAAC,CAAC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