@webiny/tasks 5.40.6 → 5.41.0-beta.1

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 (79) hide show
  1. package/context.d.ts +1 -2
  2. package/context.js +8 -16
  3. package/context.js.map +1 -1
  4. package/crud/model.js +2 -2
  5. package/crud/model.js.map +1 -1
  6. package/crud/service.tasks.d.ts +2 -0
  7. package/crud/{trigger.tasks.js → service.tasks.js} +30 -16
  8. package/crud/service.tasks.js.map +1 -0
  9. package/graphql/index.js +0 -4
  10. package/graphql/index.js.map +1 -1
  11. package/handler/index.d.ts +1 -3
  12. package/handler/index.js.map +1 -1
  13. package/handler/register.js +4 -2
  14. package/handler/register.js.map +1 -1
  15. package/handler/types.d.ts +2 -0
  16. package/handler/types.js.map +1 -1
  17. package/package.json +21 -20
  18. package/plugins/TaskServicePlugin.d.ts +21 -0
  19. package/plugins/TaskServicePlugin.js +17 -0
  20. package/plugins/TaskServicePlugin.js.map +1 -0
  21. package/plugins/index.d.ts +1 -1
  22. package/plugins/index.js +4 -4
  23. package/plugins/index.js.map +1 -1
  24. package/response/Response.js +48 -1
  25. package/response/Response.js.map +1 -1
  26. package/response/ResponseDoneResult.js +1 -1
  27. package/response/ResponseDoneResult.js.map +1 -1
  28. package/response/TaskResponse.js +4 -4
  29. package/response/TaskResponse.js.map +1 -1
  30. package/response/abstractions/Response.d.ts +2 -2
  31. package/response/abstractions/ResponseContinueResult.d.ts +1 -0
  32. package/response/abstractions/ResponseContinueResult.js.map +1 -1
  33. package/response/abstractions/ResponseErrorResult.d.ts +3 -2
  34. package/response/abstractions/ResponseErrorResult.js.map +1 -1
  35. package/response/abstractions/TaskResponse.d.ts +7 -10
  36. package/response/abstractions/TaskResponse.js.map +1 -1
  37. package/runner/TaskControl.js +44 -17
  38. package/runner/TaskControl.js.map +1 -1
  39. package/runner/TaskManager.js.map +1 -1
  40. package/runner/TaskManagerStore.d.ts +11 -2
  41. package/runner/TaskManagerStore.js +30 -6
  42. package/runner/TaskManagerStore.js.map +1 -1
  43. package/runner/abstractions/TaskEventValidation.d.ts +1 -1
  44. package/runner/abstractions/TaskManagerStore.d.ts +14 -8
  45. package/runner/abstractions/TaskManagerStore.js.map +1 -1
  46. package/runner/abstractions/TaskRunner.d.ts +4 -1
  47. package/runner/abstractions/TaskRunner.js.map +1 -1
  48. package/service/EventBridgeEventTransportPlugin.d.ts +18 -0
  49. package/{crud/transport → service}/EventBridgeEventTransportPlugin.js +9 -7
  50. package/service/EventBridgeEventTransportPlugin.js.map +1 -0
  51. package/service/StepFunctionServicePlugin.d.ts +26 -0
  52. package/service/StepFunctionServicePlugin.js +84 -0
  53. package/service/StepFunctionServicePlugin.js.map +1 -0
  54. package/service/createService.d.ts +6 -0
  55. package/service/createService.js +31 -0
  56. package/service/createService.js.map +1 -0
  57. package/service/index.d.ts +4 -0
  58. package/service/index.js +31 -0
  59. package/service/index.js.map +1 -0
  60. package/task/plugin.d.ts +3 -3
  61. package/types.d.ts +64 -65
  62. package/types.js +7 -16
  63. package/types.js.map +1 -1
  64. package/utils/getErrorProperties.d.ts +1 -1
  65. package/utils/getErrorProperties.js +3 -1
  66. package/utils/getErrorProperties.js.map +1 -1
  67. package/utils/index.d.ts +3 -0
  68. package/utils/index.js +40 -0
  69. package/utils/index.js.map +1 -0
  70. package/crud/transport/EventBridgeEventTransportPlugin.d.ts +0 -5
  71. package/crud/transport/EventBridgeEventTransportPlugin.js.map +0 -1
  72. package/crud/trigger.tasks.d.ts +0 -2
  73. package/crud/trigger.tasks.js.map +0 -1
  74. package/plugins/TaskTriggerTransportPlugin.d.ts +0 -17
  75. package/plugins/TaskTriggerTransportPlugin.js +0 -20
  76. package/plugins/TaskTriggerTransportPlugin.js.map +0 -1
  77. package/transport/createTransport.d.ts +0 -7
  78. package/transport/createTransport.js +0 -32
  79. package/transport/createTransport.js.map +0 -1
@@ -1,17 +1,26 @@
1
1
  import { ITask, ITaskDataInput, ITaskLog, ITaskManagerStoreInfoLog, ITaskManagerStorePrivate, ITaskManagerStoreSetOutputOptions, ITaskManagerStoreUpdateTaskInputOptions, ITaskManagerStoreUpdateTaskOptions, ITaskResponseDoneResultOutput, ITasksContextObject, TaskDataStatus } from "../types";
2
2
  import { ITaskManagerStoreAddLogOptions, ITaskManagerStoreErrorLog, ITaskManagerStoreUpdateTaskInputParam, ITaskManagerStoreUpdateTaskParams } from "./abstractions";
3
+ import { GenericRecord } from "@webiny/api/types";
3
4
  export interface TaskManagerStoreContext {
4
- tasks: Pick<ITasksContextObject, "updateTask" | "updateLog">;
5
+ tasks: Pick<ITasksContextObject, "updateTask" | "updateLog" | "listTasks">;
6
+ }
7
+ export interface ITaskManagerStoreParams {
8
+ context: TaskManagerStoreContext;
9
+ task: ITask;
10
+ log: ITaskLog;
11
+ disableDatabaseLogs?: boolean;
5
12
  }
6
13
  export declare class TaskManagerStore<T extends ITaskDataInput = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> implements ITaskManagerStorePrivate<T, O> {
7
14
  private readonly context;
8
15
  private task;
9
16
  private taskLog;
17
+ private readonly disableDatabaseLogs;
10
18
  private readonly taskUpdater;
11
19
  private readonly taskLogUpdater;
12
- constructor(context: TaskManagerStoreContext, task: ITask, log: ITaskLog);
20
+ constructor(params: ITaskManagerStoreParams);
13
21
  getStatus(): TaskDataStatus;
14
22
  getTask(): ITask<T, O>;
23
+ listChildTasks<I = GenericRecord, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput>(definitionId?: string): Promise<ITask<I, O>[]>;
15
24
  updateTask(param: ITaskManagerStoreUpdateTaskParams<T, O>, options?: ITaskManagerStoreUpdateTaskOptions): Promise<void>;
16
25
  updateInput(param: ITaskManagerStoreUpdateTaskInputParam<T>, options?: ITaskManagerStoreUpdateTaskInputOptions): Promise<void>;
17
26
  getInput(): T;
@@ -26,10 +26,11 @@ const getInput = (originalInput, input) => {
26
26
  class TaskManagerStore {
27
27
  taskUpdater = new _ObjectUpdater.ObjectUpdater();
28
28
  taskLogUpdater = new _ObjectUpdater.ObjectUpdater();
29
- constructor(context, task, log) {
30
- this.context = context;
31
- this.task = task;
32
- this.taskLog = log;
29
+ constructor(params) {
30
+ this.context = params.context;
31
+ this.task = params.task;
32
+ this.taskLog = params.log;
33
+ this.disableDatabaseLogs = !!params.disableDatabaseLogs;
33
34
  }
34
35
  getStatus() {
35
36
  return this.task.taskStatus;
@@ -37,6 +38,20 @@ class TaskManagerStore {
37
38
  getTask() {
38
39
  return this.task;
39
40
  }
41
+ async listChildTasks(definitionId) {
42
+ const where = {
43
+ parentId: this.task.id
44
+ };
45
+ if (definitionId) {
46
+ where.definitionId = definitionId;
47
+ }
48
+ const result = await this.context.tasks.listTasks({
49
+ where,
50
+ sort: ["createdOn_ASC"],
51
+ limit: 1000000
52
+ });
53
+ return result.items;
54
+ }
40
55
  async updateTask(param, options) {
41
56
  const data = typeof param === "function" ? param(this.task) : param;
42
57
 
@@ -89,11 +104,14 @@ class TaskManagerStore {
89
104
  * TODO: Maybe we should wrap it into try/catch and return error if any?
90
105
  */
91
106
  async addInfoLog(log, options) {
107
+ if (this.disableDatabaseLogs) {
108
+ return;
109
+ }
92
110
  this.taskLogUpdater.update({
93
111
  items: [{
94
112
  message: log.message,
95
113
  data: log.data,
96
- type: _types.ITaskLogItemType.INFO,
114
+ type: _types.TaskLogItemType.INFO,
97
115
  createdOn: new Date().toISOString()
98
116
  }]
99
117
  });
@@ -107,6 +125,9 @@ class TaskManagerStore {
107
125
  * TODO: Maybe we should wrap it into try/catch and return error if any?
108
126
  */
109
127
  async addErrorLog(log, options) {
128
+ if (this.disableDatabaseLogs) {
129
+ return;
130
+ }
110
131
  /**
111
132
  * Let's log the error to the console as well.
112
133
  */
@@ -118,7 +139,7 @@ class TaskManagerStore {
118
139
  items: [{
119
140
  message: log.message,
120
141
  error: log.error instanceof Error ? (0, _getObjectProperties.getObjectProperties)(log.error) : log.error,
121
- type: _types.ITaskLogItemType.ERROR,
142
+ type: _types.TaskLogItemType.ERROR,
122
143
  createdOn: new Date().toISOString()
123
144
  }]
124
145
  });
@@ -134,6 +155,9 @@ class TaskManagerStore {
134
155
  if (this.taskUpdater.isDirty()) {
135
156
  this.task = await this.context.tasks.updateTask(this.task.id, this.taskUpdater.fetch());
136
157
  }
158
+ if (this.disableDatabaseLogs) {
159
+ return;
160
+ }
137
161
  if (this.taskLogUpdater.isDirty()) {
138
162
  this.taskLog = await this.context.tasks.updateLog(this.taskLog.id, this.taskLogUpdater.fetch());
139
163
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_deepEqual","_interopRequireDefault","_getObjectProperties","_ObjectUpdater","getInput","originalInput","input","TaskManagerStore","taskUpdater","ObjectUpdater","taskLogUpdater","constructor","context","task","log","taskLog","getStatus","taskStatus","getTask","updateTask","param","options","data","deepEqual","update","save","updateInput","updateOutput","values","output","getOutput","addInfoLog","items","message","type","ITaskLogItemType","INFO","createdOn","Date","toISOString","addErrorLog","console","error","Error","getObjectProperties","ERROR","isDirty","tasks","id","fetch","updateLog","exports"],"sources":["TaskManagerStore.ts"],"sourcesContent":["import {\n ITask,\n ITaskDataInput,\n ITaskLog,\n ITaskLogItemType,\n ITaskManagerStoreInfoLog,\n ITaskManagerStorePrivate,\n ITaskManagerStoreSetOutputOptions,\n ITaskManagerStoreUpdateTaskInputOptions,\n ITaskManagerStoreUpdateTaskOptions,\n ITaskResponseDoneResultOutput,\n ITasksContextObject,\n TaskDataStatus\n} from \"~/types\";\nimport {\n ITaskManagerStoreAddLogOptions,\n ITaskManagerStoreErrorLog,\n ITaskManagerStoreUpdateTaskInputParam,\n ITaskManagerStoreUpdateTaskParams\n} from \"./abstractions\";\n/**\n * Package deep-equal does not have types.\n */\n// @ts-expect-error\nimport deepEqual from \"deep-equal\";\nimport { getObjectProperties } from \"~/utils/getObjectProperties\";\nimport { ObjectUpdater } from \"~/utils/ObjectUpdater\";\n\nconst getInput = <T extends ITaskDataInput = ITaskDataInput>(\n originalInput: T,\n input: ITaskManagerStoreUpdateTaskInputParam<T>\n): T => {\n if (typeof input === \"function\") {\n return input(originalInput);\n }\n return {\n ...originalInput,\n ...input\n };\n};\n\nexport interface TaskManagerStoreContext {\n tasks: Pick<ITasksContextObject, \"updateTask\" | \"updateLog\">;\n}\n\nexport class TaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> implements ITaskManagerStorePrivate<T, O>\n{\n private readonly context: TaskManagerStoreContext;\n private task: ITask<T, O>;\n private taskLog: ITaskLog;\n\n private readonly taskUpdater = new ObjectUpdater<ITask<T, O>>();\n private readonly taskLogUpdater = new ObjectUpdater<ITaskLog>();\n\n public constructor(context: TaskManagerStoreContext, task: ITask, log: ITaskLog) {\n this.context = context;\n this.task = task as ITask<T, O>;\n this.taskLog = log;\n }\n\n public getStatus(): TaskDataStatus {\n return this.task.taskStatus;\n }\n\n public getTask(): ITask<T, O> {\n return this.task as ITask<T, O>;\n }\n\n public async updateTask(\n param: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void> {\n const data = typeof param === \"function\" ? param(this.task) : param;\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(data, this.task)) {\n return;\n }\n\n this.taskUpdater.update(data);\n\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async updateInput(\n param: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ): Promise<void> {\n const input = getInput<T>(this.task.input, param);\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(input, this.task.input)) {\n return;\n }\n this.taskUpdater.update({\n input: input as T\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getInput(): T {\n return this.task.input as T;\n }\n\n public async updateOutput(\n values: Partial<O>,\n options: ITaskManagerStoreSetOutputOptions = {}\n ): Promise<void> {\n this.taskUpdater.update({\n output: values as O\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getOutput(): O {\n return this.task.output as O;\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addInfoLog(\n log: ITaskManagerStoreInfoLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n data: log.data,\n type: ITaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n\n await this.save();\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addErrorLog(\n log: ITaskManagerStoreErrorLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n /**\n * Let's log the error to the console as well.\n */\n console.error(log.error);\n /**\n * Then update the log object.\n */\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,\n type: ITaskLogItemType.ERROR,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async save(): Promise<void> {\n /**\n * Update both task and the log, if anything to update.\n */\n if (this.taskUpdater.isDirty()) {\n this.task = await this.context.tasks.updateTask<T, O>(\n this.task.id,\n this.taskUpdater.fetch()\n );\n }\n if (this.taskLogUpdater.isDirty()) {\n this.taskLog = await this.context.tasks.updateLog(\n this.taskLog.id,\n this.taskLogUpdater.fetch()\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAwBA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AANA;AACA;AACA;AACA;;AAKA,MAAMK,QAAQ,GAAGA,CACbC,aAAgB,EAChBC,KAA+C,KAC3C;EACJ,IAAI,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KAAK,CAAC5B,GAAG,CAAC4B,KAAK,CAAC;IACxB;AACR;AACA;IACQ,IAAI,CAAChC,cAAc,CAACc,MAAM,CAAC;MACvBQ,KAAK,EAAE,CACH;QACIC,OAAO,EAAEnB,GAAG,CAACmB,OAAO;QACpBS,KAAK,EAAE5B,GAAG,CAAC4B,KAAK,YAAYC,KAAK,GAAG,IAAAC,wCAAmB,EAAC9B,GAAG,CAAC4B,KAAK,CAAC,GAAG5B,GAAG,CAAC4B,KAAK;QAC9ER,IAAI,EAAEC,uBAAgB,CAACU,KAAK;QAC5BR,SAAS,EAAE,IAAIC,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC;MACtC,CAAC;IAET,CAAC,CAAC;IACF,IAAIlB,OAAO,EAAEI,IAAI,KAAK,KAAK,EAAE;MACzB;IACJ;IACA,MAAM,IAAI,CAACA,IAAI,CAAC,CAAC;EACrB;EAEA,MAAaA,IAAIA,CAAA,EAAkB;IAC/B;AACR;AACA;IACQ,IAAI,IAAI,CAACjB,WAAW,CAACsC,OAAO,CAAC,CAAC,EAAE;MAC5B,IAAI,CAACjC,IAAI,GAAG,MAAM,IAAI,CAACD,OAAO,CAACmC,KAAK,CAAC5B,UAAU,CAC3C,IAAI,CAACN,IAAI,CAACmC,EAAE,EACZ,IAAI,CAACxC,WAAW,CAACyC,KAAK,CAAC,CAC3B,CAAC;IACL;IACA,IAAI,IAAI,CAACvC,cAAc,CAACoC,OAAO,CAAC,CAAC,EAAE;MAC/B,IAAI,CAAC/B,OAAO,GAAG,MAAM,IAAI,CAACH,OAAO,CAACmC,KAAK,CAACG,SAAS,CAC7C,IAAI,CAACnC,OAAO,CAACiC,EAAE,EACf,IAAI,CAACtC,cAAc,CAACuC,KAAK,CAAC,CAC9B,CAAC;IACL;EACJ;AACJ;AAACE,OAAA,CAAA5C,gBAAA,GAAAA,gBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_types","require","_deepEqual","_interopRequireDefault","_getObjectProperties","_ObjectUpdater","getInput","originalInput","input","TaskManagerStore","taskUpdater","ObjectUpdater","taskLogUpdater","constructor","params","context","task","taskLog","log","disableDatabaseLogs","getStatus","taskStatus","getTask","listChildTasks","definitionId","where","parentId","id","result","tasks","listTasks","sort","limit","items","updateTask","param","options","data","deepEqual","update","save","updateInput","updateOutput","values","output","getOutput","addInfoLog","message","type","TaskLogItemType","INFO","createdOn","Date","toISOString","addErrorLog","console","error","Error","getObjectProperties","ERROR","isDirty","fetch","updateLog","exports"],"sources":["TaskManagerStore.ts"],"sourcesContent":["import {\n IListTaskParamsWhere,\n ITask,\n ITaskDataInput,\n ITaskLog,\n TaskLogItemType,\n ITaskManagerStoreInfoLog,\n ITaskManagerStorePrivate,\n ITaskManagerStoreSetOutputOptions,\n ITaskManagerStoreUpdateTaskInputOptions,\n ITaskManagerStoreUpdateTaskOptions,\n ITaskResponseDoneResultOutput,\n ITasksContextObject,\n TaskDataStatus\n} from \"~/types\";\nimport {\n ITaskManagerStoreAddLogOptions,\n ITaskManagerStoreErrorLog,\n ITaskManagerStoreUpdateTaskInputParam,\n ITaskManagerStoreUpdateTaskParams\n} from \"./abstractions\";\n/**\n * Package deep-equal does not have types.\n */\n// @ts-expect-error\nimport deepEqual from \"deep-equal\";\nimport { getObjectProperties } from \"~/utils/getObjectProperties\";\nimport { ObjectUpdater } from \"~/utils/ObjectUpdater\";\nimport { GenericRecord } from \"@webiny/api/types\";\n\nconst getInput = <T extends ITaskDataInput = ITaskDataInput>(\n originalInput: T,\n input: ITaskManagerStoreUpdateTaskInputParam<T>\n): T => {\n if (typeof input === \"function\") {\n return input(originalInput);\n }\n return {\n ...originalInput,\n ...input\n };\n};\n\nexport interface TaskManagerStoreContext {\n tasks: Pick<ITasksContextObject, \"updateTask\" | \"updateLog\" | \"listTasks\">;\n}\n\nexport interface ITaskManagerStoreParams {\n context: TaskManagerStoreContext;\n task: ITask;\n log: ITaskLog;\n disableDatabaseLogs?: boolean;\n}\n\nexport class TaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> implements ITaskManagerStorePrivate<T, O>\n{\n private readonly context: TaskManagerStoreContext;\n private task: ITask<T, O>;\n private taskLog: ITaskLog;\n private readonly disableDatabaseLogs: boolean;\n\n private readonly taskUpdater = new ObjectUpdater<ITask<T, O>>();\n private readonly taskLogUpdater = new ObjectUpdater<ITaskLog>();\n\n public constructor(params: ITaskManagerStoreParams) {\n this.context = params.context;\n this.task = params.task as ITask<T, O>;\n this.taskLog = params.log;\n this.disableDatabaseLogs = !!params.disableDatabaseLogs;\n }\n\n public getStatus(): TaskDataStatus {\n return this.task.taskStatus;\n }\n\n public getTask(): ITask<T, O> {\n return this.task as ITask<T, O>;\n }\n\n public async listChildTasks<\n I = GenericRecord,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(definitionId?: string): Promise<ITask<I, O>[]> {\n const where: IListTaskParamsWhere = {\n parentId: this.task.id\n };\n if (definitionId) {\n where.definitionId = definitionId;\n }\n const result = await this.context.tasks.listTasks<I, O>({\n where,\n sort: [\"createdOn_ASC\"],\n limit: 1000000\n });\n return result.items;\n }\n\n public async updateTask(\n param: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void> {\n const data = typeof param === \"function\" ? param(this.task) : param;\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(data, this.task)) {\n return;\n }\n\n this.taskUpdater.update(data);\n\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async updateInput(\n param: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ): Promise<void> {\n const input = getInput<T>(this.task.input, param);\n\n /**\n * No need to update if nothing changed.\n */\n if (deepEqual(input, this.task.input)) {\n return;\n }\n this.taskUpdater.update({\n input: input as T\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getInput(): T {\n return this.task.input as T;\n }\n\n public async updateOutput(\n values: Partial<O>,\n options: ITaskManagerStoreSetOutputOptions = {}\n ): Promise<void> {\n this.taskUpdater.update({\n output: values as O\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public getOutput(): O {\n return this.task.output as O;\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addInfoLog(\n log: ITaskManagerStoreInfoLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n data: log.data,\n type: TaskLogItemType.INFO,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n\n await this.save();\n }\n /**\n * Currently the methods throws an error if something goes wrong during the database update.\n * TODO: Maybe we should wrap it into try/catch and return error if any?\n */\n public async addErrorLog(\n log: ITaskManagerStoreErrorLog,\n options?: ITaskManagerStoreAddLogOptions\n ): Promise<void> {\n if (this.disableDatabaseLogs) {\n return;\n }\n /**\n * Let's log the error to the console as well.\n */\n console.error(log.error);\n /**\n * Then update the log object.\n */\n this.taskLogUpdater.update({\n items: [\n {\n message: log.message,\n error: log.error instanceof Error ? getObjectProperties(log.error) : log.error,\n type: TaskLogItemType.ERROR,\n createdOn: new Date().toISOString()\n }\n ]\n });\n if (options?.save === false) {\n return;\n }\n await this.save();\n }\n\n public async save(): Promise<void> {\n /**\n * Update both task and the log, if anything to update.\n */\n if (this.taskUpdater.isDirty()) {\n this.task = await this.context.tasks.updateTask<T, O>(\n this.task.id,\n this.taskUpdater.fetch()\n );\n }\n if (this.disableDatabaseLogs) {\n return;\n }\n if (this.taskLogUpdater.isDirty()) {\n this.taskLog = await this.context.tasks.updateLog(\n this.taskLog.id,\n this.taskLogUpdater.fetch()\n );\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAyBA,IAAAC,UAAA,GAAAC,sBA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AEI,IAAI,KAAK,KAAK,EAAE;MACzB;IACJ;IACA,MAAM,IAAI,CAACA,IAAI,CAAC,CAAC;EACrB;EAEA,MAAaA,IAAIA,CAAA,EAAkB;IAC/B;AACR;AACA;IACQ,IAAI,IAAI,CAAC9B,WAAW,CAACkD,OAAO,CAAC,CAAC,EAAE;MAC5B,IAAI,CAAC5C,IAAI,GAAG,MAAM,IAAI,CAACD,OAAO,CAACc,KAAK,CAACK,UAAU,CAC3C,IAAI,CAAClB,IAAI,CAACW,EAAE,EACZ,IAAI,CAACjB,WAAW,CAACmD,KAAK,CAAC,CAC3B,CAAC;IACL;IACA,IAAI,IAAI,CAAC1C,mBAAmB,EAAE;MAC1B;IACJ;IACA,IAAI,IAAI,CAACP,cAAc,CAACgD,OAAO,CAAC,CAAC,EAAE;MAC/B,IAAI,CAAC3C,OAAO,GAAG,MAAM,IAAI,CAACF,OAAO,CAACc,KAAK,CAACiC,SAAS,CAC7C,IAAI,CAAC7C,OAAO,CAACU,EAAE,EACf,IAAI,CAACf,cAAc,CAACiD,KAAK,CAAC,CAC9B,CAAC;IACL;EACJ;AACJ;AAACE,OAAA,CAAAtD,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { ITaskEvent } from "../../handler/types";
2
- export declare type ITaskEventValidationResult = ITaskEvent;
2
+ export type ITaskEventValidationResult = ITaskEvent;
3
3
  export interface ITaskEventValidation {
4
4
  validate: (event: Partial<ITaskEvent>) => ITaskEventValidationResult;
5
5
  }
@@ -1,17 +1,18 @@
1
1
  import { IResponseError, ITask, ITaskDataInput, ITaskLogItemData, ITaskResponseDoneResultOutput, ITaskUpdateData, TaskDataStatus } from "../../types";
2
- export declare type ITaskManagerStoreUpdateTaskValues<T extends ITaskDataInput = ITaskDataInput> = T;
3
- export interface ITaskManagerStoreUpdateTaskValuesCb<T extends ITaskDataInput = ITaskDataInput> {
2
+ import { GenericRecord } from "@webiny/api/types";
3
+ export type ITaskManagerStoreUpdateTaskValues<T = ITaskDataInput> = T;
4
+ export interface ITaskManagerStoreUpdateTaskValuesCb<T = ITaskDataInput> {
4
5
  (input: T): T;
5
6
  }
6
7
  export interface ITaskManagerStoreUpdateTaskInputOptions {
7
8
  save: boolean;
8
9
  }
9
- export declare type ITaskManagerStoreUpdateTaskInputParam<T extends ITaskDataInput = ITaskDataInput> = ITaskManagerStoreUpdateTaskValuesCb<T> | Partial<ITaskManagerStoreUpdateTaskValues<T>>;
10
- export interface ITaskManagerStoreUpdateTaskParamCb<T extends ITaskDataInput = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> {
10
+ export type ITaskManagerStoreUpdateTaskInputParam<T = ITaskDataInput> = ITaskManagerStoreUpdateTaskValuesCb<T> | Partial<ITaskManagerStoreUpdateTaskValues<T>>;
11
+ export interface ITaskManagerStoreUpdateTaskParamCb<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> {
11
12
  (task: ITask<T, O>): ITaskUpdateData<T, O>;
12
13
  }
13
- export declare type ITaskManagerStoreUpdateTask<T extends ITaskDataInput = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = ITaskUpdateData<T, O>;
14
- export declare type ITaskManagerStoreUpdateTaskParams<T extends ITaskDataInput = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;
14
+ export type ITaskManagerStoreUpdateTask<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = ITaskUpdateData<T, O>;
15
+ export type ITaskManagerStoreUpdateTaskParams<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;
15
16
  export interface ITaskManagerStoreInfoLog {
16
17
  message: string;
17
18
  data?: ITaskLogItemData;
@@ -42,13 +43,18 @@ export interface ITaskManagerStoreAddLogOptions {
42
43
  /**
43
44
  * Interface should not be used outside the @webiny/tasks package.
44
45
  */
45
- export interface ITaskManagerStorePrivate<T extends ITaskDataInput = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> {
46
+ export interface ITaskManagerStorePrivate<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> {
46
47
  getTask: () => ITask<T, O>;
47
48
  getStatus: () => TaskDataStatus;
48
49
  /**
49
50
  * @throws {Error} If task not found or something goes wrong during the database update.
50
51
  */
51
52
  updateTask(params: ITaskManagerStoreUpdateTaskParams<T, O>, options?: ITaskManagerStoreUpdateTaskOptions): Promise<void>;
53
+ /**
54
+ * List all child tasks of the current task.
55
+ * If definitionId is provided, filter by that parameter.
56
+ */
57
+ listChildTasks<T = GenericRecord, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput>(definitionId?: string): Promise<ITask<T, O>[]>;
52
58
  /**
53
59
  * Update the task input, which are used to store custom user data.
54
60
  * You can send partial input, and it will be merged with the existing input.
@@ -83,4 +89,4 @@ export interface ITaskManagerStorePrivate<T extends ITaskDataInput = ITaskDataIn
83
89
  */
84
90
  save(): Promise<void>;
85
91
  }
86
- export declare type ITaskManagerStore<T extends ITaskDataInput = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = Omit<ITaskManagerStorePrivate<T, O>, "save">;
92
+ export type ITaskManagerStore<T = ITaskDataInput, O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput> = Omit<ITaskManagerStorePrivate<T, O>, "save">;
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["TaskManagerStore.ts"],"sourcesContent":["import {\n IResponseError,\n ITask,\n ITaskDataInput,\n ITaskLogItemData,\n ITaskResponseDoneResultOutput,\n ITaskUpdateData,\n TaskDataStatus\n} from \"~/types\";\n\nexport type ITaskManagerStoreUpdateTaskValues<T extends ITaskDataInput = ITaskDataInput> = T;\n\nexport interface ITaskManagerStoreUpdateTaskValuesCb<T extends ITaskDataInput = ITaskDataInput> {\n (input: T): T;\n}\n\nexport interface ITaskManagerStoreUpdateTaskInputOptions {\n save: boolean;\n}\n\nexport type ITaskManagerStoreUpdateTaskInputParam<T extends ITaskDataInput = ITaskDataInput> =\n | ITaskManagerStoreUpdateTaskValuesCb<T>\n | Partial<ITaskManagerStoreUpdateTaskValues<T>>;\n\nexport interface ITaskManagerStoreUpdateTaskParamCb<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n (task: ITask<T, O>): ITaskUpdateData<T, O>;\n}\n\nexport type ITaskManagerStoreUpdateTask<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = ITaskUpdateData<T, O>;\n\nexport type ITaskManagerStoreUpdateTaskParams<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;\n\nexport interface ITaskManagerStoreInfoLog {\n message: string;\n data?: ITaskLogItemData;\n}\n\nexport interface ITaskManagerStoreErrorLog {\n message: string;\n data?: ITaskLogItemData;\n error: IResponseError | Error;\n}\n\nexport interface ITaskManagerStoreSetOutputOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreUpdateTaskOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreAddLogOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\n/**\n * Interface should not be used outside the @webiny/tasks package.\n */\nexport interface ITaskManagerStorePrivate<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n getTask: () => ITask<T, O>;\n getStatus: () => TaskDataStatus;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateTask(\n params: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void>;\n /**\n * Update the task input, which are used to store custom user data.\n * You can send partial input, and it will be merged with the existing input.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateInput: (\n params: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ) => Promise<void>;\n getInput: () => T;\n /**\n * Update the task output, which are used to store the output data.\n * You can send partial output, and it will be merged with the existing output.\n *\n * Second parameter is optional options, and it contains a possibility not to store the task immediately.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateOutput: (\n values: Partial<O>,\n options?: ITaskManagerStoreSetOutputOptions\n ) => Promise<void>;\n getOutput: () => O;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n addInfoLog: (log: ITaskManagerStoreInfoLog) => Promise<void>;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n *\n *\n */\n addErrorLog: (log: ITaskManagerStoreErrorLog) => Promise<void>;\n /**\n * Should store the task and logs into the database, if any.\n * If nothing to update, it should skip calling the internal store methods.\n */\n save(): Promise<void>;\n}\n\nexport type ITaskManagerStore<\n T extends ITaskDataInput = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = Omit<ITaskManagerStorePrivate<T, O>, \"save\">;\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["TaskManagerStore.ts"],"sourcesContent":["import {\n IResponseError,\n ITask,\n ITaskDataInput,\n ITaskLogItemData,\n ITaskResponseDoneResultOutput,\n ITaskUpdateData,\n TaskDataStatus\n} from \"~/types\";\nimport { GenericRecord } from \"@webiny/api/types\";\n\nexport type ITaskManagerStoreUpdateTaskValues<T = ITaskDataInput> = T;\n\nexport interface ITaskManagerStoreUpdateTaskValuesCb<T = ITaskDataInput> {\n (input: T): T;\n}\n\nexport interface ITaskManagerStoreUpdateTaskInputOptions {\n save: boolean;\n}\n\nexport type ITaskManagerStoreUpdateTaskInputParam<T = ITaskDataInput> =\n | ITaskManagerStoreUpdateTaskValuesCb<T>\n | Partial<ITaskManagerStoreUpdateTaskValues<T>>;\n\nexport interface ITaskManagerStoreUpdateTaskParamCb<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n (task: ITask<T, O>): ITaskUpdateData<T, O>;\n}\n\nexport type ITaskManagerStoreUpdateTask<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = ITaskUpdateData<T, O>;\n\nexport type ITaskManagerStoreUpdateTaskParams<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = ITaskManagerStoreUpdateTaskParamCb<T, O> | Partial<ITaskManagerStoreUpdateTask<T, O>>;\n\nexport interface ITaskManagerStoreInfoLog {\n message: string;\n data?: ITaskLogItemData;\n}\n\nexport interface ITaskManagerStoreErrorLog {\n message: string;\n data?: ITaskLogItemData;\n error: IResponseError | Error;\n}\n\nexport interface ITaskManagerStoreSetOutputOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreUpdateTaskOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\nexport interface ITaskManagerStoreAddLogOptions {\n /**\n * Default is true.\n */\n save?: boolean;\n}\n\n/**\n * Interface should not be used outside the @webiny/tasks package.\n */\nexport interface ITaskManagerStorePrivate<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> {\n getTask: () => ITask<T, O>;\n getStatus: () => TaskDataStatus;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateTask(\n params: ITaskManagerStoreUpdateTaskParams<T, O>,\n options?: ITaskManagerStoreUpdateTaskOptions\n ): Promise<void>;\n /**\n * List all child tasks of the current task.\n * If definitionId is provided, filter by that parameter.\n */\n listChildTasks<\n T = GenericRecord,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n >(\n definitionId?: string\n ): Promise<ITask<T, O>[]>;\n /**\n * Update the task input, which are used to store custom user data.\n * You can send partial input, and it will be merged with the existing input.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateInput: (\n params: ITaskManagerStoreUpdateTaskInputParam<T>,\n options?: ITaskManagerStoreUpdateTaskInputOptions\n ) => Promise<void>;\n getInput: () => T;\n /**\n * Update the task output, which are used to store the output data.\n * You can send partial output, and it will be merged with the existing output.\n *\n * Second parameter is optional options, and it contains a possibility not to store the task immediately.\n *\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n updateOutput: (\n values: Partial<O>,\n options?: ITaskManagerStoreSetOutputOptions\n ) => Promise<void>;\n getOutput: () => O;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n */\n addInfoLog: (log: ITaskManagerStoreInfoLog) => Promise<void>;\n /**\n * @throws {Error} If task not found or something goes wrong during the database update.\n *\n *\n */\n addErrorLog: (log: ITaskManagerStoreErrorLog) => Promise<void>;\n /**\n * Should store the task and logs into the database, if any.\n * If nothing to update, it should skip calling the internal store methods.\n */\n save(): Promise<void>;\n}\n\nexport type ITaskManagerStore<\n T = ITaskDataInput,\n O extends ITaskResponseDoneResultOutput = ITaskResponseDoneResultOutput\n> = Omit<ITaskManagerStorePrivate<T, O>, \"save\">;\n"],"mappings":"","ignoreList":[]}
@@ -1,8 +1,11 @@
1
1
  import { Context } from "../../types";
2
2
  import { ITaskEvent } from "../../handler/types";
3
3
  import { IResponseResult } from "../../response/abstractions";
4
+ export interface IIsCloseToTimeoutCallable {
5
+ (seconds?: number): boolean;
6
+ }
4
7
  export interface ITaskRunner<C extends Context = Context> {
5
8
  context: C;
6
- isCloseToTimeout(seconds?: number): boolean;
9
+ isCloseToTimeout: IIsCloseToTimeoutCallable;
7
10
  run(event: ITaskEvent): Promise<IResponseResult>;
8
11
  }
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["TaskRunner.ts"],"sourcesContent":["import { Context } from \"~/types\";\nimport { ITaskEvent } from \"~/handler/types\";\nimport { IResponseResult } from \"~/response/abstractions\";\n\nexport interface ITaskRunner<C extends Context = Context> {\n context: C;\n isCloseToTimeout(seconds?: number): boolean;\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["TaskRunner.ts"],"sourcesContent":["import { Context } from \"~/types\";\nimport { ITaskEvent } from \"~/handler/types\";\nimport { IResponseResult } from \"~/response/abstractions\";\n\nexport interface IIsCloseToTimeoutCallable {\n (seconds?: number): boolean;\n}\n\nexport interface ITaskRunner<C extends Context = Context> {\n context: C;\n isCloseToTimeout: IIsCloseToTimeoutCallable;\n run(event: ITaskEvent): Promise<IResponseResult>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ import { ITaskService, ITaskServiceCreatePluginParams, ITaskServiceTask, TaskServicePlugin } from "../plugins";
2
+ import { Context } from "../types";
3
+ import type { PutEventsCommandOutput } from "@webiny/aws-sdk/client-eventbridge";
4
+ import { GenericRecord } from "@webiny/api/types";
5
+ declare class EventBridgeService implements ITaskService {
6
+ protected readonly context: Context;
7
+ protected readonly getTenant: () => string;
8
+ protected readonly getLocale: () => string;
9
+ private readonly client;
10
+ constructor(params: ITaskServiceCreatePluginParams);
11
+ send(task: ITaskServiceTask, delay: number): Promise<PutEventsCommandOutput>;
12
+ fetch(): Promise<GenericRecord>;
13
+ }
14
+ export declare class EventBridgeEventTransportPlugin extends TaskServicePlugin {
15
+ name: string;
16
+ createService(params: ITaskServiceCreatePluginParams): EventBridgeService;
17
+ }
18
+ export {};
@@ -4,16 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.EventBridgeEventTransportPlugin = void 0;
7
- var _plugins = require("../../plugins");
7
+ var _plugins = require("../plugins");
8
8
  var _clientEventbridge = require("@webiny/aws-sdk/client-eventbridge");
9
9
  var _error = require("@webiny/error");
10
- class EventBridgeEventTransport {
10
+ class EventBridgeService {
11
11
  constructor(params) {
12
12
  this.client = new _clientEventbridge.EventBridgeClient({
13
13
  region: process.env.AWS_REGION
14
14
  });
15
15
  this.context = params.context;
16
- this.config = params.config;
17
16
  this.getTenant = params.getTenant;
18
17
  this.getLocale = params.getLocale;
19
18
  }
@@ -32,7 +31,7 @@ class EventBridgeEventTransport {
32
31
  const cmd = new _clientEventbridge.PutEventsCommand({
33
32
  Entries: [{
34
33
  Source: "webiny-api-tasks",
35
- EventBusName: this.config.eventBusName,
34
+ EventBusName: String(process.env.EVENT_BUS),
36
35
  DetailType: "WebinyBackgroundTask",
37
36
  Detail: JSON.stringify(event)
38
37
  }]
@@ -46,11 +45,14 @@ class EventBridgeEventTransport {
46
45
  });
47
46
  }
48
47
  }
48
+ async fetch() {
49
+ throw new _error.WebinyError("Not implemented!", "NOT_IMPLEMENTED");
50
+ }
49
51
  }
50
- class EventBridgeEventTransportPlugin extends _plugins.TaskTriggerTransportPlugin {
52
+ class EventBridgeEventTransportPlugin extends _plugins.TaskServicePlugin {
51
53
  name = "task.eventBridgeEventTransport";
52
- createTransport(params) {
53
- return new EventBridgeEventTransport(params);
54
+ createService(params) {
55
+ return new EventBridgeService(params);
54
56
  }
55
57
  }
56
58
  exports.EventBridgeEventTransportPlugin = EventBridgeEventTransportPlugin;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_plugins","require","_clientEventbridge","_error","EventBridgeService","constructor","params","client","EventBridgeClient","region","process","env","AWS_REGION","context","getTenant","getLocale","send","task","delay","event","webinyTaskId","id","webinyTaskDefinitionId","definitionId","tenant","locale","cmd","PutEventsCommand","Entries","Source","EventBusName","String","EVENT_BUS","DetailType","Detail","JSON","stringify","ex","WebinyError","message","code","data","fetch","EventBridgeEventTransportPlugin","TaskServicePlugin","name","createService","exports"],"sources":["EventBridgeEventTransportPlugin.ts"],"sourcesContent":["import {\n ITaskService,\n ITaskServiceCreatePluginParams,\n ITaskServiceTask,\n TaskServicePlugin\n} from \"~/plugins\";\nimport { Context, ITaskEventInput } from \"~/types\";\nimport type { PutEventsCommandOutput } from \"@webiny/aws-sdk/client-eventbridge\";\nimport { EventBridgeClient, PutEventsCommand } from \"@webiny/aws-sdk/client-eventbridge\";\nimport { WebinyError } from \"@webiny/error\";\nimport { GenericRecord } from \"@webiny/api/types\";\n\nclass EventBridgeService implements ITaskService {\n protected readonly context: Context;\n protected readonly getTenant: () => string;\n protected readonly getLocale: () => string;\n private readonly client: EventBridgeClient;\n\n public constructor(params: ITaskServiceCreatePluginParams) {\n this.client = new EventBridgeClient({\n region: process.env.AWS_REGION\n });\n this.context = params.context;\n this.getTenant = params.getTenant;\n this.getLocale = params.getLocale;\n }\n\n public async send(task: ITaskServiceTask, delay: number): Promise<PutEventsCommandOutput> {\n /**\n * The ITaskEvent is what our handler expect to get.\n * Endpoint and stateMachineId are added by the step function.\n */\n const event: ITaskEventInput = {\n webinyTaskId: task.id,\n webinyTaskDefinitionId: task.definitionId,\n tenant: this.getTenant(),\n locale: this.getLocale(),\n delay\n };\n\n const cmd = new PutEventsCommand({\n Entries: [\n {\n Source: \"webiny-api-tasks\",\n EventBusName: String(process.env.EVENT_BUS),\n DetailType: \"WebinyBackgroundTask\",\n Detail: JSON.stringify(event)\n }\n ]\n });\n try {\n return await this.client.send(cmd);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not trigger task via Event Bridge!\",\n ex.code || \"TRIGGER_TASK_ERROR\",\n {\n event,\n ...(ex.data || {})\n }\n );\n }\n }\n\n public async fetch(): Promise<GenericRecord> {\n throw new WebinyError(\"Not implemented!\", \"NOT_IMPLEMENTED\");\n }\n}\n\nexport class EventBridgeEventTransportPlugin extends TaskServicePlugin {\n public override name = \"task.eventBridgeEventTransport\";\n public createService(params: ITaskServiceCreatePlu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AA0C,EACxDF,EAAE,CAACG,IAAI,IAAI,oBAAoB,EAC/B;QACIrB,KAAK;QACL,IAAIkB,EAAE,CAACI,IAAI,IAAI,CAAC,CAAC;MACrB,CACJ,CAAC;IACL;EACJ;EAEA,MAAaC,KAAKA,CAAA,EAA2B;IACzC,MAAM,IAAIJ,kBAAW,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;EAChE;AACJ;AAEO,MAAMK,+BAA+B,SAASC,0BAAiB,CAAC;EACnDC,IAAI,GAAG,gCAAgC;EAChDC,aAAaA,CAACxC,MAAsC,EAAE;IACzD,OAAO,IAAIF,kBAAkB,CAACE,MAAM,CAAC;EACzC;AACJ;AAACyC,OAAA,CAAAJ,+BAAA,GAAAA,+BAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ import { ITaskService, ITaskServiceCreatePluginParams, ITaskServiceTask, TaskServicePlugin } from "../plugins";
2
+ import { DescribeExecutionCommandOutput } from "@webiny/aws-sdk/client-sfn";
3
+ import { ITask } from "../types";
4
+ export type IStepFunctionServiceFetchResult = DescribeExecutionCommandOutput;
5
+ export interface IDetailWrapper<T> {
6
+ detail: T;
7
+ }
8
+ declare class StepFunctionService implements ITaskService {
9
+ private readonly getTenant;
10
+ private readonly getLocale;
11
+ private readonly trigger;
12
+ private readonly get;
13
+ constructor(params: ITaskServiceCreatePluginParams);
14
+ send(task: ITaskServiceTask, delay: number): Promise<{
15
+ name: string;
16
+ executionArn: string | undefined;
17
+ startDate: Date | undefined;
18
+ $metadata: import("@smithy/types").ResponseMetadata;
19
+ } | null>;
20
+ fetch(task: ITask): Promise<IStepFunctionServiceFetchResult | null>;
21
+ }
22
+ export declare class StepFunctionServicePlugin extends TaskServicePlugin {
23
+ name: string;
24
+ createService(params: ITaskServiceCreatePluginParams): StepFunctionService;
25
+ }
26
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StepFunctionServicePlugin = void 0;
7
+ var _plugins = require("../plugins");
8
+ var _clientSfn = require("@webiny/aws-sdk/client-sfn");
9
+ var _utils = require("@webiny/utils");
10
+ var _api = require("@webiny/api");
11
+ class StepFunctionService {
12
+ constructor(params) {
13
+ this.getTenant = params.getTenant;
14
+ this.getLocale = params.getLocale;
15
+ const client = (0, _clientSfn.createStepFunctionClient)();
16
+ this.trigger = (0, _clientSfn.triggerStepFunctionFactory)(client);
17
+ this.get = (0, _clientSfn.describeExecutionFactory)(client);
18
+ }
19
+ async send(task, delay) {
20
+ const manifest = await _api.ServiceDiscovery.load();
21
+ if (!manifest) {
22
+ console.error("Service manifest not found.");
23
+ return null;
24
+ }
25
+ const {
26
+ bgTaskSfn
27
+ } = manifest.api || {};
28
+ if (!bgTaskSfn) {
29
+ console.error("Background task state machine not found.");
30
+ return null;
31
+ }
32
+ const input = {
33
+ webinyTaskId: task.id,
34
+ webinyTaskDefinitionId: task.definitionId,
35
+ tenant: this.getTenant(),
36
+ locale: this.getLocale(),
37
+ delay
38
+ };
39
+ const name = `${task.definitionId}_${task.id}_${(0, _utils.generateAlphaNumericId)(10)}`;
40
+ try {
41
+ const result = await this.trigger({
42
+ input: {
43
+ detail: input
44
+ },
45
+ stateMachineArn: bgTaskSfn,
46
+ name
47
+ });
48
+ return {
49
+ ...result,
50
+ name
51
+ };
52
+ } catch (ex) {
53
+ console.log("Could not trigger a step function.");
54
+ console.error(ex);
55
+ return null;
56
+ }
57
+ }
58
+ async fetch(task) {
59
+ const executionArn = task.eventResponse?.executionArn;
60
+ if (!executionArn) {
61
+ console.error(`Execution ARN not found in task "${task.id}".`);
62
+ return null;
63
+ }
64
+ try {
65
+ const result = await this.get({
66
+ executionArn
67
+ });
68
+ return result || null;
69
+ } catch (ex) {
70
+ console.log("Could not get the execution details.");
71
+ console.error(ex);
72
+ return null;
73
+ }
74
+ }
75
+ }
76
+ class StepFunctionServicePlugin extends _plugins.TaskServicePlugin {
77
+ name = "task.stepFunctionTriggerTransport";
78
+ createService(params) {
79
+ return new StepFunctionService(params);
80
+ }
81
+ }
82
+ exports.StepFunctionServicePlugin = StepFunctionServicePlugin;
83
+
84
+ //# sourceMappingURL=StepFunctionServicePlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_plugins","require","_clientSfn","_utils","_api","StepFunctionService","constructor","params","getTenant","getLocale","client","createStepFunctionClient","trigger","triggerStepFunctionFactory","get","describeExecutionFactory","send","task","delay","manifest","ServiceDiscovery","load","console","error","bgTaskSfn","api","input","webinyTaskId","id","webinyTaskDefinitionId","definitionId","tenant","locale","name","generateAlphaNumericId","result","detail","stateMachineArn","ex","log","fetch","executionArn","eventResponse","StepFunctionServicePlugin","TaskServicePlugin","createService","exports"],"sources":["StepFunctionServicePlugin.ts"],"sourcesContent":["import {\n ITaskService,\n ITaskServiceCreatePluginParams,\n ITaskServiceTask,\n TaskServicePlugin\n} from \"~/plugins\";\nimport {\n createStepFunctionClient,\n DescribeExecutionCommandOutput,\n describeExecutionFactory,\n triggerStepFunctionFactory\n} from \"@webiny/aws-sdk/client-sfn\";\nimport { ITaskEventInput } from \"~/handler/types\";\nimport { generateAlphaNumericId } from \"@webiny/utils\";\nimport { ServiceDiscovery } from \"@webiny/api\";\nimport { ITask } from \"~/types\";\n\nexport type IStepFunctionServiceFetchResult = DescribeExecutionCommandOutput;\n\nexport interface IDetailWrapper<T> {\n detail: T;\n}\n\nclass StepFunctionService implements ITaskService {\n private readonly getTenant: () => string;\n private readonly getLocale: () => string;\n private readonly trigger: ReturnType<typeof triggerStepFunctionFactory>;\n private readonly get: ReturnType<typeof describeExecutionFactory>;\n\n public constructor(params: ITaskServiceCreatePluginParams) {\n this.getTenant = params.getTenant;\n this.getLocale = params.getLocale;\n const client = createStepFunctionClient();\n this.trigger = triggerStepFunctionFactory(client);\n this.get = describeExecutionFactory(client);\n }\n public async send(task: ITaskServiceTask, delay: number) {\n const manifest = await ServiceDiscovery.load();\n if (!manifest) {\n console.error(\"Service manifest not found.\");\n return null;\n }\n const { bgTaskSfn } = manifest.api || {};\n if (!bgTaskSfn) {\n console.error(\"Background task state machine not found.\");\n return null;\n }\n\n const input: ITaskEventInput = {\n webinyTaskId: task.id,\n webinyTaskDefinitionId: task.definitionId,\n tenant: this.getTenant(),\n locale: this.getLocale(),\n delay\n };\n const name = `${task.definitionId}_${task.id}_${generateAlphaNumericId(10)}`;\n try {\n const result = await this.trigger<IDetailWrapper<ITaskEventInput>>({\n input: {\n detail: input\n },\n stateMachineArn: bgTaskSfn,\n name\n });\n return {\n ...result,\n name\n };\n } catch (ex) {\n console.log(\"Could not trigger a step function.\");\n console.error(ex);\n return null;\n }\n }\n\n public async fetch(task: ITask): Promise<IStepFunctionServiceFetchResult | null> {\n const executionArn = task.eventResponse?.executionArn;\n if (!executionArn) {\n console.error(`Execution ARN not found in task \"${task.id}\".`);\n return null;\n }\n try {\n const result = await this.get({\n executionArn\n });\n return result || null;\n } catch (ex) {\n console.log(\"Could not get the execution details.\");\n console.error(ex);\n return null;\n }\n }\n}\n\nexport class StepFunctionServicePlugin extends TaskServicePlugin {\n public override name = \"task.stepFunctionTriggerTransport\";\n\n public createService(params: ITaskServiceCreatePluginParams) {\n return new StepFunctionService(params);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,UAAA,GAAAD,OAAA;AAOA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AASA,MAAMI,mBAAmB,CAAyB;EAMvCC,WAAWA,CAACC,MAAsC,EAAE;IACvD,IAAI,CAACC,SAAS,GAAGD,MAAM,CAACC,SAAS;IACjC,IAAI,CAACC,SAAS,GAAGF,MAAM,CAACE,SAAS;IACjC,MAAMC,MAAM,GAAG,IAAAC,mCAAwB,EAAC,CAAC;IACzC,IAAI,CAACC,OAAO,GAAG,IAAAC,qCAA0B,EAACH,MAAM,CAAC;IACjD,IAAI,CAACI,GAAG,GAAG,IAAAC,mCAAwB,EAACL,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ED,YAAY;IACrD,IAAI,CAACA,YAAY,EAAE;MACfnB,OAAO,CAACC,KAAK,CAAE,oCAAmCN,IAAI,CAACW,EAAG,IAAG,CAAC;MAC9D,OAAO,IAAI;IACf;IACA,IAAI;MACA,MAAMO,MAAM,GAAG,MAAM,IAAI,CAACrB,GAAG,CAAC;QAC1B2B;MACJ,CAAC,CAAC;MACF,OAAON,MAAM,IAAI,IAAI;IACzB,CAAC,CAAC,OAAOG,EAAE,EAAE;MACThB,OAAO,CAACiB,GAAG,CAAC,sCAAsC,CAAC;MACnDjB,OAAO,CAACC,KAAK,CAACe,EAAE,CAAC;MACjB,OAAO,IAAI;IACf;EACJ;AACJ;AAEO,MAAMK,yBAAyB,SAASC,0BAAiB,CAAC;EAC7CX,IAAI,GAAG,mCAAmC;EAEnDY,aAAaA,CAACtC,MAAsC,EAAE;IACzD,OAAO,IAAIF,mBAAmB,CAACE,MAAM,CAAC;EAC1C;AACJ;AAACuC,OAAA,CAAAH,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import { Context } from "../types";
2
+ import { ITaskService } from "../plugins";
3
+ export interface ICreateTransport {
4
+ context: Context;
5
+ }
6
+ export declare const createService: (params: ICreateTransport) => ITaskService;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createService = void 0;
7
+ var _plugins = require("../plugins");
8
+ var _error = require("@webiny/error");
9
+ const createService = params => {
10
+ const plugins = params.context.plugins.byType(_plugins.TaskServicePlugin.type).reverse();
11
+ const plugin = plugins.find(plugin => plugin.default) || plugins[0];
12
+ if (!plugin) {
13
+ throw new _error.WebinyError("Missing TaskServicePlugin.", "PLUGIN_ERROR", {
14
+ type: _plugins.TaskServicePlugin.type
15
+ });
16
+ }
17
+ const getTenant = () => {
18
+ return params.context.tenancy.getCurrentTenant().id;
19
+ };
20
+ const getLocale = () => {
21
+ return params.context.cms.getLocale().code;
22
+ };
23
+ return plugin.createService({
24
+ context: params.context,
25
+ getTenant,
26
+ getLocale
27
+ });
28
+ };
29
+ exports.createService = createService;
30
+
31
+ //# sourceMappingURL=createService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_plugins","require","_error","createService","params","plugins","context","byType","TaskServicePlugin","type","reverse","plugin","find","default","WebinyError","getTenant","tenancy","getCurrentTenant","id","getLocale","cms","code","exports"],"sources":["createService.ts"],"sourcesContent":["import { Context } from \"~/types\";\nimport { ITaskService, TaskServicePlugin } from \"~/plugins\";\nimport { WebinyError } from \"@webiny/error\";\n\nexport interface ICreateTransport {\n context: Context;\n}\n\nexport const createService = (params: ICreateTransport): ITaskService => {\n const plugins = params.context.plugins\n .byType<TaskServicePlugin>(TaskServicePlugin.type)\n .reverse();\n\n const plugin = plugins.find(plugin => plugin.default) || plugins[0];\n if (!plugin) {\n throw new WebinyError(\"Missing TaskServicePlugin.\", \"PLUGIN_ERROR\", {\n type: TaskServicePlugin.type\n });\n }\n\n const getTenant = (): string => {\n return params.context.tenancy.getCurrentTenant().id;\n };\n const getLocale = (): string => {\n return params.context.cms.getLocale().code;\n };\n\n return plugin.createService({\n context: params.context,\n getTenant,\n getLocale\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAMO,MAAME,aAAa,GAAIC,MAAwB,IAAmB;EACrE,MAAMC,OAAO,GAAGD,MAAM,CAACE,OAAO,CAACD,OAAO,CACjCE,MAAM,CAAoBC,0BAAiB,CAACC,IAAI,CAAC,CACjDC,OAAO,CAAC,CAAC;EAEd,MAAMC,MAAM,GAAGN,OAAO,CAACO,IAAI,CAACD,MAAM,IAAIA,MAAM,CAACE,OAAO,CAAC,IAAIR,OAAO,CAAC,CAAC,CAAC;EACnE,IAAI,CAACM,MAAM,EAAE;IACT,MAAM,IAAIG,kBAAW,CAAC,4BAA4B,EAAE,cAAc,EAAE;MAChEL,IAAI,EAAED,0BAAiB,CAACC;IAC5B,CAAC,CAAC;EACN;EAEA,MAAMM,SAAS,GAAGA,CAAA,KAAc;IAC5B,OAAOX,MAAM,CAACE,OAAO,CAACU,OAAO,CAACC,gBAAgB,CAAC,CAAC,CAACC,EAAE;EACvD,CAAC;EACD,MAAMC,SAAS,GAAGA,CAAA,KAAc;IAC5B,OAAOf,MAAM,CAACE,OAAO,CAACc,GAAG,CAACD,SAAS,CAAC,CAAC,CAACE,IAAI;EAC9C,CAAC;EAED,OAAOV,MAAM,CAACR,aAAa,CAAC;IACxBG,OAAO,EAAEF,MAAM,CAACE,OAAO;IACvBS,SAAS;IACTI;EACJ,CAAC,CAAC;AACN,CAAC;AAACG,OAAA,CAAAnB,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import { EventBridgeEventTransportPlugin } from "./EventBridgeEventTransportPlugin";
2
+ import { StepFunctionServicePlugin } from "./StepFunctionServicePlugin";
3
+ export declare const createServicePlugins: () => (StepFunctionServicePlugin | EventBridgeEventTransportPlugin)[];
4
+ export * from "./createService";
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ createServicePlugins: true
8
+ };
9
+ exports.createServicePlugins = void 0;
10
+ var _EventBridgeEventTransportPlugin = require("./EventBridgeEventTransportPlugin");
11
+ var _StepFunctionServicePlugin = require("./StepFunctionServicePlugin");
12
+ var _createService = require("./createService");
13
+ Object.keys(_createService).forEach(function (key) {
14
+ if (key === "default" || key === "__esModule") return;
15
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
16
+ if (key in exports && exports[key] === _createService[key]) return;
17
+ Object.defineProperty(exports, key, {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _createService[key];
21
+ }
22
+ });
23
+ });
24
+ const createServicePlugins = () => {
25
+ return [new _StepFunctionServicePlugin.StepFunctionServicePlugin({
26
+ default: true
27
+ }), new _EventBridgeEventTransportPlugin.EventBridgeEventTransportPlugin()];
28
+ };
29
+ exports.createServicePlugins = createServicePlugins;
30
+
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_EventBridgeEventTransportPlugin","require","_StepFunctionServicePlugin","_createService","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","createServicePlugins","StepFunctionServicePlugin","default","EventBridgeEventTransportPlugin"],"sources":["index.ts"],"sourcesContent":["import { EventBridgeEventTransportPlugin } from \"./EventBridgeEventTransportPlugin\";\nimport { StepFunctionServicePlugin } from \"./StepFunctionServicePlugin\";\n\nexport const createServicePlugins = () => {\n return [\n new StepFunctionServicePlugin({ default: true }),\n new EventBridgeEventTransportPlugin()\n ];\n};\n\nexport * from \"./createService\";\n"],"mappings":";;;;;;;;;AAAA,IAAAA,gCAAA,GAAAC,OAAA;AACA,IAAAC,0BAAA,GAAAD,OAAA;AASA,IAAAE,cAAA,GAAAF,OAAA;AAAAG,MAAA,CAAAC,IAAA,CAAAF,cAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,cAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,cAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAPO,MAAMS,oBAAoB,GAAGA,CAAA,KAAM;EACtC,OAAO,CACH,IAAIC,oDAAyB,CAAC;IAAEC,OAAO,EAAE;EAAK,CAAC,CAAC,EAChD,IAAIC,gEAA+B,CAAC,CAAC,CACxC;AACL,CAAC;AAACP,OAAA,CAAAI,oBAAA,GAAAA,oBAAA","ignoreList":[]}
package/task/plugin.d.ts CHANGED
@@ -15,9 +15,9 @@ export declare class TaskDefinitionPlugin<C extends Context = Context, I = any,
15
15
  get title(): string;
16
16
  get fields(): ITaskDefinitionField[] | undefined;
17
17
  get run(): (params: import("../types").ITaskRunParams<C, I, O>) => Promise<import("../types").ITaskResponseResult<import("../types").ITaskDataInput, ITaskResponseDoneResultOutput>>;
18
- get onDone(): ((params: import("../types").ITaskOnSuccessParams<C, I>) => Promise<void>) | undefined;
19
- get onAbort(): ((params: import("../types").ITaskOnAbortParams<C>) => Promise<void>) | undefined;
20
- get onError(): ((params: import("../types").ITaskOnErrorParams<C, I>) => Promise<void>) | undefined;
18
+ get onDone(): ((params: import("../types").ITaskOnSuccessParams<C, I, O>) => Promise<void>) | undefined;
19
+ get onAbort(): ((params: import("../types").ITaskOnAbortParams<C, I, O>) => Promise<void>) | undefined;
20
+ get onError(): ((params: import("../types").ITaskOnErrorParams<C, I, ITaskResponseDoneResultOutput>) => Promise<void>) | undefined;
21
21
  get onMaxIterations(): ((params: import("../types").ITaskOnMaxIterationsParams<C>) => Promise<void>) | undefined;
22
22
  get maxIterations(): number;
23
23
  constructor(task: ITaskDefinitionParams<C, I, O>);