@webiny/webhooks 6.4.12-beta.7 → 6.4.12-beta.8

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.
@@ -33,7 +33,7 @@ class ResendWebhookDeliveryUseCaseImpl {
33
33
  const data = originalPayload?.data ?? {};
34
34
  const settingsResult = await this.getSettingsRepository.execute();
35
35
  const retentionDays = settingsResult.isOk() ? settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;
36
- const expiresAt = new Date(Date.now() + 24 * retentionDays * 3600000);
36
+ const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
37
37
  const newDeliveryResult = await this.createDeliveryRepository.execute({
38
38
  webhookId: delivery.webhookId,
39
39
  eventType: delivery.eventType,
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js","sources":["../../../../src/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ResendWebhookDeliveryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { ResendWebhookDeliveryInputSchema } from \"./schema.js\";\nimport { GetWebhookDeliveryRepository } from \"~/api/features/GetWebhookDelivery/abstractions.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\nimport { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { IWebhookPayload } from \"~/api/features/SendWebhookTask/types.js\";\n\nclass ResendWebhookDeliveryUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly getDeliveryRepository: GetWebhookDeliveryRepository.Interface,\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface\n ) {}\n\n async execute(deliveryId: string): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = ResendWebhookDeliveryInputSchema.safeParse({ deliveryId });\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const deliveryResult = await this.getDeliveryRepository.execute(parsed.data.deliveryId);\n if (deliveryResult.isFail()) {\n return Result.fail(deliveryResult.error);\n }\n\n const delivery = deliveryResult.value;\n\n const webhookResult = await this.getWebhookRepository.execute(delivery.webhookId);\n if (webhookResult.isFail()) {\n return Result.fail(webhookResult.error);\n }\n\n const originalPayload = delivery.payload as IWebhookPayload | null;\n const data = originalPayload?.data ?? {};\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n const newDeliveryResult = await this.createDeliveryRepository.execute({\n webhookId: delivery.webhookId,\n eventType: delivery.eventType,\n status: \"pending\",\n payload: data as Record<string, unknown>,\n expiresAt\n });\n\n if (newDeliveryResult.isFail()) {\n return Result.fail(newDeliveryResult.error);\n }\n\n await this.taskService.trigger({\n definition: SEND_WEBHOOK_TASK,\n name: `Resend webhook: ${delivery.eventType}`,\n input: {\n webhookId: delivery.webhookId,\n eventName: delivery.eventType,\n deliveryId: newDeliveryResult.value.id\n }\n });\n\n return Result.ok(true);\n }\n}\n\nexport const ResendWebhookDeliveryUseCase = UseCaseAbstraction.createImplementation({\n implementation: ResendWebhookDeliveryUseCaseImpl,\n dependencies: [\n WebhookPermissions,\n GetWebhookDeliveryRepository,\n GetWebhookRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n GetWebhookSettingsRepository\n ]\n});\n"],"names":["ResendWebhookDeliveryUseCaseImpl","permissions","getDeliveryRepository","getWebhookRepository","createDeliveryRepository","taskService","getSettingsRepository","deliveryId","Result","WebhookNotAuthorizedError","parsed","ResendWebhookDeliveryInputSchema","WebhookValidationError","deliveryResult","delivery","webhookResult","originalPayload","data","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","newDeliveryResult","SEND_WEBHOOK_TASK","ResendWebhookDeliveryUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookDeliveryRepository","GetWebhookRepository","CreateWebhookDeliveryRepository","TaskService","GetWebhookSettingsRepository"],"mappings":";;;;;;;;;;;AAaA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,qBAA6D,EAC7DC,oBAAoD,EACpDC,wBAAmE,EACnEC,WAAkC,EAClCC,qBAA6D,CAChF;aANmBL,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;aACAC,oBAAoB,GAApBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;IAClB;IAEH,MAAM,QAAQC,UAAkB,EAAsD;QAClF,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,iCAAiC,SAAS,CAAC;YAAEJ;QAAW;QACvE,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IA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C;IAChF,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js","sources":["../../../../src/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ResendWebhookDeliveryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { ResendWebhookDeliveryInputSchema } from \"./schema.js\";\nimport { GetWebhookDeliveryRepository } from \"~/api/features/GetWebhookDelivery/abstractions.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\nimport { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { IWebhookPayload } from \"~/api/features/SendWebhookTask/types.js\";\n\nclass ResendWebhookDeliveryUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly getDeliveryRepository: GetWebhookDeliveryRepository.Interface,\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface\n ) {}\n\n async execute(deliveryId: string): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = ResendWebhookDeliveryInputSchema.safeParse({ deliveryId });\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const deliveryResult = await this.getDeliveryRepository.execute(parsed.data.deliveryId);\n if (deliveryResult.isFail()) {\n return Result.fail(deliveryResult.error);\n }\n\n const delivery = deliveryResult.value;\n\n const webhookResult = await this.getWebhookRepository.execute(delivery.webhookId);\n if (webhookResult.isFail()) {\n return Result.fail(webhookResult.error);\n }\n\n const originalPayload = delivery.payload as IWebhookPayload | null;\n const data = originalPayload?.data ?? {};\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n const newDeliveryResult = await this.createDeliveryRepository.execute({\n webhookId: delivery.webhookId,\n eventType: delivery.eventType,\n status: \"pending\",\n payload: data as Record<string, unknown>,\n expiresAt\n });\n\n if (newDeliveryResult.isFail()) {\n return Result.fail(newDeliveryResult.error);\n }\n\n await this.taskService.trigger({\n definition: SEND_WEBHOOK_TASK,\n name: `Resend webhook: ${delivery.eventType}`,\n input: {\n webhookId: delivery.webhookId,\n eventName: delivery.eventType,\n deliveryId: newDeliveryResult.value.id\n }\n });\n\n return Result.ok(true);\n }\n}\n\nexport const ResendWebhookDeliveryUseCase = UseCaseAbstraction.createImplementation({\n implementation: ResendWebhookDeliveryUseCaseImpl,\n dependencies: [\n WebhookPermissions,\n GetWebhookDeliveryRepository,\n GetWebhookRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n GetWebhookSettingsRepository\n ]\n});\n"],"names":["ResendWebhookDeliveryUseCaseImpl","permissions","getDeliveryRepository","getWebhookRepository","createDeliveryRepository","taskService","getSettingsRepository","deliveryId","Result","WebhookNotAuthorizedError","parsed","ResendWebhookDeliveryInputSchema","WebhookValidationError","deliveryResult","delivery","webhookResult","originalPayload","data","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","newDeliveryResult","SEND_WEBHOOK_TASK","ResendWebhookDeliveryUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookDeliveryRepository","GetWebhookRepository","CreateWebhookDeliveryRepository","TaskService","GetWebhookSettingsRepository"],"mappings":";;;;;;;;;;;AAaA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,qBAA6D,EAC7DC,oBAAoD,EACpDC,wBAAmE,EACnEC,WAAkC,EAClCC,qBAA6D,CAChF;aANmBL,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;aACAC,oBAAoB,GAApBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;IAClB;IAEH,MAAM,QAAQC,UAAkB,EAAsD;QAClF,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,iCAAiC,SAAS,CAAC;YAAEJ;QAAW;QACvE,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAMG,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACH,OAAO,IAAI,CAAC,UAAU;QACtF,IAAIG,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,WAAWD,eAAe,KAAK;QAErC,MAAME,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACD,SAAS,SAAS;QAChF,IAAIC,cAAc,MAAM,IACpB,OAAOP,OAAO,IAAI,CAACO,cAAc,KAAK;QAG1C,MAAMC,kBAAkBF,SAAS,OAAO;QACxC,MAAMG,OAAOD,iBAAiB,QAAQ,CAAC;QAEvC,MAAME,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO;QAC/D,MAAMC,gBAAgBD,eAAe,IAAI,KAClCA,eAAe,KAAK,CAAC,qBAAqB,IAAIE,sCAC/CA;QAEN,MAAMC,YAAY,IAAIC,KAAKA,KAAK,GAAG,KAAKH,AAAgB,KAAhBA,gBAAqB,KAAK,KAAK;QAEvE,MAAMI,oBAAoB,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAClE,WAAWT,SAAS,SAAS;YAC7B,WAAWA,SAAS,SAAS;YAC7B,QAAQ;YACR,SAASG;YACTI;QACJ;QAEA,IAAIE,kBAAkB,MAAM,IACxB,OAAOf,OAAO,IAAI,CAACe,kBAAkB,KAAK;QAG9C,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;YAC3B,YAAYC;YACZ,MAAM,CAAC,gBAAgB,EAAEV,SAAS,SAAS,EAAE;YAC7C,OAAO;gBACH,WAAWA,SAAS,SAAS;gBAC7B,WAAWA,SAAS,SAAS;gBAC7B,YAAYS,kBAAkB,KAAK,CAAC,EAAE;YAC1C;QACJ;QAEA,OAAOf,OAAO,EAAE,CAAC;IACrB;AACJ;AAEO,MAAMiB,4DAA+BC,6BAAAA,oBAAuC,CAAC;IAChF,gBAAgB1B;IAChB,cAAc;QACV2B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -28,7 +28,7 @@ class TriggerWebhookUseCaseImpl {
28
28
  const webhook = webhookResult.value;
29
29
  const settingsResult = await this.getSettingsRepository.execute();
30
30
  const retentionDays = settingsResult.isOk() ? settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;
31
- const expiresAt = new Date(Date.now() + 24 * retentionDays * 3600000);
31
+ const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
32
32
  const deliveryResult = await this.createDeliveryRepository.execute({
33
33
  webhookId: webhook.id,
34
34
  eventType: "webhook.test",
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/TriggerWebhook/TriggerWebhookUseCase.js","sources":["../../../../src/api/features/TriggerWebhook/TriggerWebhookUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { TriggerWebhookUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TriggerWebhookInputSchema } from \"./schema.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { ISendWebhookTaskInput } from \"~/api/features/SendWebhookTask/types.js\";\nimport type { WebhookDelivery } from \"~/api/domain/WebhookDelivery.js\";\n\nclass TriggerWebhookUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface\n ) {}\n\n async execute(\n webhookId: string,\n payload: Record<string, unknown>\n ): Promise<Result<WebhookDelivery, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = TriggerWebhookInputSchema.safeParse({ webhookId, payload });\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const webhookResult = await this.getWebhookRepository.execute(parsed.data.webhookId);\n if (webhookResult.isFail()) {\n return Result.fail(webhookResult.error);\n }\n\n const webhook = webhookResult.value;\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n const deliveryResult = await this.createDeliveryRepository.execute({\n webhookId: webhook.id,\n eventType: \"webhook.test\",\n status: \"pending\",\n payload,\n expiresAt\n });\n\n if (deliveryResult.isFail()) {\n return Result.fail(deliveryResult.error);\n }\n\n const delivery = deliveryResult.value;\n\n await this.taskService.trigger<ISendWebhookTaskInput>({\n definition: SEND_WEBHOOK_TASK,\n name: `Test webhook: ${webhook.slug}`,\n input: {\n webhookId: webhook.id,\n eventName: \"webhook.test\",\n deliveryId: delivery.id\n }\n });\n\n return Result.ok(delivery);\n }\n}\n\nexport const TriggerWebhookUseCase = UseCaseAbstraction.createImplementation({\n implementation: TriggerWebhookUseCaseImpl,\n dependencies: [\n WebhookPermissions,\n GetWebhookRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n GetWebhookSettingsRepository\n ]\n});\n"],"names":["TriggerWebhookUseCaseImpl","permissions","getWebhookRepository","createDeliveryRepository","taskService","getSettingsRepository","webhookId","payload","Result","WebhookNotAuthorizedError","parsed","TriggerWebhookInputSchema","WebhookValidationError","webhookResult","webhook","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","deliveryResult","delivery","SEND_WEBHOOK_TASK","TriggerWebhookUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookRepository","CreateWebhookDeliveryRepository","TaskService","GetWebhookSettingsRepository"],"mappings":";;;;;;;;;;AAaA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,oBAAoD,EACpDC,wBAAmE,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,WAAWA,QAAQ,EAAE;gBACrB,WAAW;gBACX,YAAYO,SAAS,EAAE;YAC3B;QACJ;QAEA,OAAOb,OAAO,EAAE,CAACa;IACrB;AACJ;AAEO,MAAME,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/TriggerWebhook/TriggerWebhookUseCase.js","sources":["../../../../src/api/features/TriggerWebhook/TriggerWebhookUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { TriggerWebhookUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { TriggerWebhookInputSchema } from \"./schema.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { ISendWebhookTaskInput } from \"~/api/features/SendWebhookTask/types.js\";\nimport type { WebhookDelivery } from \"~/api/domain/WebhookDelivery.js\";\n\nclass TriggerWebhookUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface\n ) {}\n\n async execute(\n webhookId: string,\n payload: Record<string, unknown>\n ): Promise<Result<WebhookDelivery, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = TriggerWebhookInputSchema.safeParse({ webhookId, payload });\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const webhookResult = await this.getWebhookRepository.execute(parsed.data.webhookId);\n if (webhookResult.isFail()) {\n return Result.fail(webhookResult.error);\n }\n\n const webhook = webhookResult.value;\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n const deliveryResult = await this.createDeliveryRepository.execute({\n webhookId: webhook.id,\n eventType: \"webhook.test\",\n status: \"pending\",\n payload,\n expiresAt\n });\n\n if (deliveryResult.isFail()) {\n return Result.fail(deliveryResult.error);\n }\n\n const delivery = deliveryResult.value;\n\n await this.taskService.trigger<ISendWebhookTaskInput>({\n definition: SEND_WEBHOOK_TASK,\n name: `Test webhook: ${webhook.slug}`,\n input: {\n webhookId: webhook.id,\n eventName: \"webhook.test\",\n deliveryId: delivery.id\n }\n });\n\n return Result.ok(delivery);\n }\n}\n\nexport const TriggerWebhookUseCase = UseCaseAbstraction.createImplementation({\n implementation: TriggerWebhookUseCaseImpl,\n dependencies: [\n WebhookPermissions,\n GetWebhookRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n GetWebhookSettingsRepository\n ]\n});\n"],"names":["TriggerWebhookUseCaseImpl","permissions","getWebhookRepository","createDeliveryRepository","taskService","getSettingsRepository","webhookId","payload","Result","WebhookNotAuthorizedError","parsed","TriggerWebhookInputSchema","WebhookValidationError","webhookResult","webhook","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","deliveryResult","delivery","SEND_WEBHOOK_TASK","TriggerWebhookUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookRepository","CreateWebhookDeliveryRepository","TaskService","GetWebhookSettingsRepository"],"mappings":";;;;;;;;;;AAaA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,oBAAoD,EACpDC,wBAAmE,EACnEC,WAAkC,EAClCC,qBAA6D,CAChF;aALmBJ,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;IAClB;IAEH,MAAM,QACFC,SAAiB,EACjBC,OAAgC,EAC0B;QAC1D,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,0BAA0B,SAAS,CAAC;YAAEL;YAAWC;QAAQ;QACxE,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAMG,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACH,OAAO,IAAI,CAAC,SAAS;QACnF,IAAIG,cAAc,MAAM,IACpB,OAAOL,OAAO,IAAI,CAACK,cAAc,KAAK;QAG1C,MAAMC,UAAUD,cAAc,KAAK;QAEnC,MAAME,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO;QAC/D,MAAMC,gBAAgBD,eAAe,IAAI,KAClCA,eAAe,KAAK,CAAC,qBAAqB,IAAIE,sCAC/CA;QAEN,MAAMC,YAAY,IAAIC,KAAKA,KAAK,GAAG,KAAKH,AAAgB,KAAhBA,gBAAqB,KAAK,KAAK;QAEvE,MAAMI,iBAAiB,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC;YAC/D,WAAWN,QAAQ,EAAE;YACrB,WAAW;YACX,QAAQ;YACRP;YACAW;QACJ;QAEA,IAAIE,eAAe,MAAM,IACrB,OAAOZ,OAAO,IAAI,CAACY,eAAe,KAAK;QAG3C,MAAMC,WAAWD,eAAe,KAAK;QAErC,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAwB;YAClD,YAAYE;YACZ,MAAM,CAAC,cAAc,EAAER,QAAQ,IAAI,EAAE;YACrC,OAAO;gBACH,WAAWA,QAAQ,EAAE;gBACrB,WAAW;gBACX,YAAYO,SAAS,EAAE;YAC3B;QACJ;QAEA,OAAOb,OAAO,EAAE,CAACa;IACrB;AACJ;AAEO,MAAME,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -30,6 +30,7 @@ class WebhookDeliverImpl {
30
30
  method: "POST",
31
31
  headers: input.headers,
32
32
  body: input.body,
33
+ redirect: "manual",
33
34
  signal: AbortSignal.timeout(input.timeout)
34
35
  });
35
36
  const body = await response.text();
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/WebhookDeliver/WebhookDeliver.js","sources":["../../../../src/api/features/WebhookDeliver/WebhookDeliver.ts"],"sourcesContent":["import {\n WebhookDeliver as Abstraction,\n type IWebhookDeliverInput,\n type IWebhookDeliverResult\n} from \"./abstractions.js\";\n\ninterface IAttemptResult {\n status: number;\n body: string;\n retryAfter: string | null;\n}\n\nclass WebhookDeliverImpl implements Abstraction.Interface {\n public async execute(input: IWebhookDeliverInput): Promise<IWebhookDeliverResult> {\n const startTime = Date.now();\n let attempts = 0;\n let lastResult: IAttemptResult = { status: 0, body: \"\", retryAfter: null };\n\n for (let i = 0; i <= input.maxRetries; i++) {\n if (i > 0) {\n const delay = this.computeDelay(i - 1, input, lastResult);\n await this.sleep(delay);\n }\n\n attempts++;\n lastResult = await this.attempt(input);\n\n if (!this.isRetryable(lastResult.status)) {\n break;\n }\n }\n\n return {\n status: lastResult.status,\n body: lastResult.body,\n responseTime: Date.now() - startTime,\n attempts\n };\n }\n\n private async attempt(input: IWebhookDeliverInput): Promise<IAttemptResult> {\n try {\n const response = await fetch(input.url, {\n method: \"POST\",\n headers: input.headers,\n body: input.body,\n signal: AbortSignal.timeout(input.timeout)\n });\n\n const body = await response.text();\n const retryAfter = response.headers.get(\"retry-after\");\n\n return { status: response.status, body, retryAfter };\n } catch (error) {\n return {\n status: 0,\n body: error instanceof Error ? error.message : \"Unknown fetch error\",\n retryAfter: null\n };\n }\n }\n\n private isRetryable(status: number): boolean {\n if (status === 0 || status === 429) {\n return true;\n }\n return status >= 500 && status <= 599;\n }\n\n private computeDelay(\n retryIndex: number,\n input: IWebhookDeliverInput,\n lastResult: IAttemptResult\n ): number {\n const exponential = Math.min(input.initialDelay * Math.pow(2, retryIndex), input.maxDelay);\n\n if (lastResult.status === 429 && lastResult.retryAfter) {\n const parsed = this.parseRetryAfter(lastResult.retryAfter);\n if (parsed !== null) {\n return Math.max(parsed, exponential);\n }\n }\n\n return exponential;\n }\n\n private parseRetryAfter(value: string): number | null {\n const seconds = Number(value);\n if (!Number.isNaN(seconds) && Number.isFinite(seconds) && seconds >= 0) {\n return seconds * 1000;\n }\n\n const dateMs = Date.parse(value);\n if (!Number.isNaN(dateMs)) {\n return Math.max(0, dateMs - Date.now());\n }\n\n return null;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n\nexport const WebhookDeliver = Abstraction.createImplementation({\n implementation: WebhookDeliverImpl,\n dependencies: []\n});\n"],"names":["WebhookDeliverImpl","input","startTime","Date","attempts","lastResult","i","delay","response","fetch","AbortSignal","body","retryAfter","error","Error","status","retryIndex","exponential","Math","parsed","value","seconds","Number","dateMs","ms","Promise","resolve","setTimeout","WebhookDeliver","Abstraction"],"mappings":";AAYA,MAAMA;IACF,MAAa,QAAQC,KAA2B,EAAkC;QAC9E,MAAMC,YAAYC,KAAK,GAAG;QAC1B,IAAIC,WAAW;QACf,IAAIC,aAA6B;YAAE,QAAQ;YAAG,MAAM;YAAI,YA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AAII,AAAsB,QAAtBA,WAAW,MAAM,IAAYA,WAAW,UAAU,EAAE;YACpD,MAAMc,SAAS,IAAI,CAAC,eAAe,CAACd,WAAW,UAAU;YACzD,IAAIc,AAAW,SAAXA,QACA,OAAOD,KAAK,GAAG,CAACC,QAAQF;QAEhC;QAEA,OAAOA;IACX;IAEQ,gBAAgBG,KAAa,EAAiB;QAClD,MAAMC,UAAUC,OAAOF;QACvB,IAAI,CAACE,OAAO,KAAK,CAACD,YAAYC,OAAO,QAAQ,CAACD,YAAYA,WAAW,GACjE,OAAOA,AAAU,OAAVA;QAGX,MAAME,SAASpB,KAAK,KAAK,CAACiB;QAC1B,IAAI,CAACE,OAAO,KAAK,CAACC,SACd,OAAOL,KAAK,GAAG,CAAC,GAAGK,SAASpB,KAAK,GAAG;QAGxC,OAAO;IACX;IAEQ,MAAMqB,EAAU,EAAiB;QACrC,OAAO,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;IACtD;AACJ;AAEO,MAAMI,gCAAiBC,eAAAA,oBAAgC,CAAC;IAC3D,gBAAgB7B;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"api/features/WebhookDeliver/WebhookDeliver.js","sources":["../../../../src/api/features/WebhookDeliver/WebhookDeliver.ts"],"sourcesContent":["import {\n WebhookDeliver as Abstraction,\n type IWebhookDeliverInput,\n type IWebhookDeliverResult\n} from \"./abstractions.js\";\n\ninterface IAttemptResult {\n status: number;\n body: string;\n retryAfter: string | null;\n}\n\nclass WebhookDeliverImpl implements Abstraction.Interface {\n public async execute(input: IWebhookDeliverInput): Promise<IWebhookDeliverResult> {\n const startTime = Date.now();\n let attempts = 0;\n let lastResult: IAttemptResult = { status: 0, body: \"\", retryAfter: null };\n\n for (let i = 0; i <= input.maxRetries; i++) {\n if (i > 0) {\n const delay = this.computeDelay(i - 1, input, lastResult);\n await this.sleep(delay);\n }\n\n attempts++;\n lastResult = await this.attempt(input);\n\n if (!this.isRetryable(lastResult.status)) {\n break;\n }\n }\n\n return {\n status: lastResult.status,\n body: lastResult.body,\n responseTime: Date.now() - startTime,\n attempts\n };\n }\n\n private async attempt(input: IWebhookDeliverInput): Promise<IAttemptResult> {\n try {\n const response = await fetch(input.url, {\n method: \"POST\",\n headers: input.headers,\n body: input.body,\n /* Never follow redirects: the endpoint URL is validated when it's stored, a\n redirect could point anywhere (e.g. the Lambda Runtime API or other internal\n addresses), and the response body ends up in the delivery log. A 3xx is\n recorded as the delivery result. */\n redirect: \"manual\",\n signal: AbortSignal.timeout(input.timeout)\n });\n\n const body = await response.text();\n const retryAfter = response.headers.get(\"retry-after\");\n\n return { status: response.status, body, retryAfter };\n } catch (error) {\n return {\n status: 0,\n body: error instanceof Error ? error.message : \"Unknown fetch error\",\n retryAfter: null\n };\n }\n }\n\n private isRetryable(status: number): boolean {\n if (status === 0 || status === 429) {\n return true;\n }\n return status >= 500 && status <= 599;\n }\n\n private computeDelay(\n retryIndex: number,\n input: IWebhookDeliverInput,\n lastResult: IAttemptResult\n ): number {\n const exponential = Math.min(input.initialDelay * Math.pow(2, retryIndex), input.maxDelay);\n\n if (lastResult.status === 429 && lastResult.retryAfter) {\n const parsed = this.parseRetryAfter(lastResult.retryAfter);\n if (parsed !== null) {\n return Math.max(parsed, exponential);\n }\n }\n\n return exponential;\n }\n\n private parseRetryAfter(value: string): number | null {\n const seconds = Number(value);\n if (!Number.isNaN(seconds) && Number.isFinite(seconds) && seconds >= 0) {\n return seconds * 1000;\n }\n\n const dateMs = Date.parse(value);\n if (!Number.isNaN(dateMs)) {\n return Math.max(0, dateMs - Date.now());\n }\n\n return null;\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n}\n\nexport const WebhookDeliver = Abstraction.createImplementation({\n implementation: WebhookDeliverImpl,\n dependencies: []\n});\n"],"names":["WebhookDeliverImpl","input","startTime","Date","attempts","lastResult","i","delay","response","fetch","AbortSignal","body","retryAfter","error","Error","status","retryIndex","exponential","Math","parsed","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W,QAAXA,QAChB,OAAO;QAEX,OAAOA,UAAU,OAAOA,UAAU;IACtC;IAEQ,aACJC,UAAkB,EAClBf,KAA2B,EAC3BI,UAA0B,EACpB;QACN,MAAMY,cAAcC,KAAK,GAAG,CAACjB,MAAM,YAAY,GAAGiB,KAAK,GAAG,CAAC,GAAGF,aAAaf,MAAM,QAAQ;QAEzF,IAAII,AAAsB,QAAtBA,WAAW,MAAM,IAAYA,WAAW,UAAU,EAAE;YACpD,MAAMc,SAAS,IAAI,CAAC,eAAe,CAACd,WAAW,UAAU;YACzD,IAAIc,AAAW,SAAXA,QACA,OAAOD,KAAK,GAAG,CAACC,QAAQF;QAEhC;QAEA,OAAOA;IACX;IAEQ,gBAAgBG,KAAa,EAAiB;QAClD,MAAMC,UAAUC,OAAOF;QACvB,IAAI,CAACE,OAAO,KAAK,CAACD,YAAYC,OAAO,QAAQ,CAACD,YAAYA,WAAW,GACjE,OAAOA,AAAU,OAAVA;QAGX,MAAME,SAASpB,KAAK,KAAK,CAACiB;QAC1B,IAAI,CAACE,OAAO,KAAK,CAACC,SACd,OAAOL,KAAK,GAAG,CAAC,GAAGK,SAASpB,KAAK,GAAG;QAGxC,OAAO;IACX;IAEQ,MAAMqB,EAAU,EAAiB;QACrC,OAAO,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;IACtD;AACJ;AAEO,MAAMI,gCAAiBC,eAAAA,oBAAgC,CAAC;IAC3D,gBAAgB7B;IAChB,cAAc,EAAE;AACpB"}
@@ -25,7 +25,7 @@ class WebhookDispatcherImpl {
25
25
  if (result.isFail()) return;
26
26
  const settingsResult = await this.getSettingsRepository.execute();
27
27
  const retentionDays = settingsResult.isOk() ? settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;
28
- const expiresAt = new Date(Date.now() + 24 * retentionDays * 3600000);
28
+ const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
29
29
  for (const webhook of result.value.items){
30
30
  const deliveryResult = await this.createDeliveryRepository.execute({
31
31
  webhookId: webhook.id,
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/WebhookDispatcher/WebhookDispatcher.js","sources":["../../../../src/api/features/WebhookDispatcher/WebhookDispatcher.ts"],"sourcesContent":["import {\n WebhookDispatcher as WebhookDispatcherAbstraction,\n WebhookProvider\n} from \"@webiny/api-core/features/webhooks/index.js\";\nimport { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { ListWebhooksRepository } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { IWebhookDispatcherData } from \"@webiny/api-core/features/webhooks/WebhookDispatcher/abstractions.js\";\nimport type { ISendWebhookTaskInput } from \"~/api/features/SendWebhookTask/types.js\";\n\nclass WebhookDispatcherImpl implements WebhookDispatcherAbstraction.Interface {\n constructor(\n private readonly listWebhooksRepository: ListWebhooksRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly provider: WebhookProvider.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface\n ) {}\n\n async dispatch<T extends IWebhookDispatcherData = IWebhookDispatcherData>(\n eventName: string,\n payload: T\n ): Promise<void> {\n const events = await this.provider.execute();\n const event = events.find(event => {\n return event.eventName === eventName;\n });\n if (!event) {\n return;\n }\n\n const result = await this.listWebhooksRepository.execute({\n where: {\n enabled: true,\n events_contains: eventName\n }\n });\n\n if (result.isFail()) {\n return;\n }\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n for (const webhook of result.value.items) {\n const deliveryResult = await this.createDeliveryRepository.execute({\n webhookId: webhook.id,\n eventType: event.eventName,\n status: \"pending\",\n expiresAt,\n payload\n });\n\n if (deliveryResult.isFail()) {\n continue;\n }\n\n await this.taskService.trigger<ISendWebhookTaskInput>({\n definition: SEND_WEBHOOK_TASK,\n name: `Webhook: ${webhook.slug} — ${event.eventName}`,\n input: {\n webhookId: webhook.id,\n eventName,\n deliveryId: deliveryResult.value.id\n }\n });\n }\n }\n}\n\nexport const WebhookDispatcher = WebhookDispatcherAbstraction.createImplementation({\n implementation: WebhookDispatcherImpl,\n dependencies: [\n ListWebhooksRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n WebhookProvider,\n GetWebhookSettingsRepository\n ]\n});\n"],"names":["WebhookDispatcherImpl","listWebhooksRepository","createDeliveryRepository","taskService","provider","getSettingsRepository","eventName","payload","events","event","result","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","webhook","deliveryResult","SEND_WEBHOOK_TASK","WebhookDispatcher","WebhookDispatcherAbstraction","ListWebhooksRepository","CreateWebhookDeliveryRepository","TaskService","WebhookProvider","GetWebhookSettingsRepository"],"mappings":";;;;;;AAYA,MAAMA;IACF,YACqBC,sBAAwD,EACxDC,wBAAmE,EACnEC,WAAkC,EAClCC,QAAmC,EACnCC,qBAA6D,CAChF;aALmBJ,sBAAsB,GAAtBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,QAAQ,GAARA;aACAC,qBAAqB,GAArBA;IAClB;IAEH,MAAM,SACFC,SAAiB,EACjBC,OAAU,EACG;QACb,MAAMC,SAAS,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO;QAC1C,MAAMC,QAAQD,OAAO,IAAI,CAACC,CAAAA,QACfA,MAAM,SAAS,KAAKH;QAE/B,IAAI,CAACG,OACD;QAGJ,MAAMC,SAAS,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACrD,OAAO;gBACH,SAAS;gBACT,iBAAiBJ;YACrB;QACJ;QAEA,IAAII,OAAO,MAAM,IACb;QAGJ,MAAMC,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO;QAC/D,MAAMC,gBAAgBD,eAAe,IAAI,KAClCA,eAAe,KAAK,CAAC,qBAAqB,IAAIE,sCAC/CA;QAEN,MAAMC,YAAY,IAAIC,KAAKA,KAAK,GAAG,KAAKH,AAAgB,KAAhBA,gBAAAA;QAExC,KAAK,MAAMI,WAAWN,OAAO,KAAK,CAAC,KAAK,CAAE;YACtC,MAAMO,iBAAiB,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC;gBAC/D,WAAWD,QAAQ,EAAE;gBACrB,WAAWP,MAAM,SAAS;gBAC1B,QAAQ;gBACRK;gBACAP;YACJ;YAEA,KAAIU,eAAe,MAAM,IAIzB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAwB;gBAClD,YAAYC;gBACZ,MAAM,CAAC,SAAS,EAAEF,QAAQ,IAAI,CAAC,GAAG,EAAEP,MAAM,SAAS,EAAE;gBACrD,OAAO;oBACH,WAAWO,QAAQ,EAAE;oBACrBV;oBACA,YAAYW,eAAe,KAAK,CAAC,EAAE;gBACvC;YACJ;QACJ;IACJ;AACJ;AAEO,MAAME,sCAAoBC,kBAAAA,oBAAiD,CAAC;IAC/E,gBAAgBpB;IAChB,cAAc;QACVqB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/WebhookDispatcher/WebhookDispatcher.js","sources":["../../../../src/api/features/WebhookDispatcher/WebhookDispatcher.ts"],"sourcesContent":["import {\n WebhookDispatcher as WebhookDispatcherAbstraction,\n WebhookProvider\n} from \"@webiny/api-core/features/webhooks/index.js\";\nimport { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { ListWebhooksRepository } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { IWebhookDispatcherData } from \"@webiny/api-core/features/webhooks/WebhookDispatcher/abstractions.js\";\nimport type { ISendWebhookTaskInput } from \"~/api/features/SendWebhookTask/types.js\";\n\nclass WebhookDispatcherImpl implements WebhookDispatcherAbstraction.Interface {\n constructor(\n private readonly listWebhooksRepository: ListWebhooksRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly provider: WebhookProvider.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface\n ) {}\n\n async dispatch<T extends IWebhookDispatcherData = IWebhookDispatcherData>(\n eventName: string,\n payload: T\n ): Promise<void> {\n const events = await this.provider.execute();\n const event = events.find(event => {\n return event.eventName === eventName;\n });\n if (!event) {\n return;\n }\n\n const result = await this.listWebhooksRepository.execute({\n where: {\n enabled: true,\n events_contains: eventName\n }\n });\n\n if (result.isFail()) {\n return;\n }\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n for (const webhook of result.value.items) {\n const deliveryResult = await this.createDeliveryRepository.execute({\n webhookId: webhook.id,\n eventType: event.eventName,\n status: \"pending\",\n expiresAt,\n payload\n });\n\n if (deliveryResult.isFail()) {\n continue;\n }\n\n await this.taskService.trigger<ISendWebhookTaskInput>({\n definition: SEND_WEBHOOK_TASK,\n name: `Webhook: ${webhook.slug} — ${event.eventName}`,\n input: {\n webhookId: webhook.id,\n eventName,\n deliveryId: deliveryResult.value.id\n }\n });\n }\n }\n}\n\nexport const WebhookDispatcher = WebhookDispatcherAbstraction.createImplementation({\n implementation: WebhookDispatcherImpl,\n dependencies: [\n ListWebhooksRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n WebhookProvider,\n GetWebhookSettingsRepository\n ]\n});\n"],"names":["WebhookDispatcherImpl","listWebhooksRepository","createDeliveryRepository","taskService","provider","getSettingsRepository","eventName","payload","events","event","result","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","webhook","deliveryResult","SEND_WEBHOOK_TASK","WebhookDispatcher","WebhookDispatcherAbstraction","ListWebhooksRepository","CreateWebhookDeliveryRepository","TaskService","WebhookProvider","GetWebhookSettingsRepository"],"mappings":";;;;;;AAYA,MAAMA;IACF,YACqBC,sBAAwD,EACxDC,wBAAmE,EACnEC,WAAkC,EAClCC,QAAmC,EACnCC,qBAA6D,CAChF;aALmBJ,sBAAsB,GAAtBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,QAAQ,GAARA;aACAC,qBAAqB,GAArBA;IAClB;IAEH,MAAM,SACFC,SAAiB,EACjBC,OAAU,EACG;QACb,MAAMC,SAAS,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO;QAC1C,MAAMC,QAAQD,OAAO,IAAI,CAACC,CAAAA,QACfA,MAAM,SAAS,KAAKH;QAE/B,IAAI,CAACG,OACD;QAGJ,MAAMC,SAAS,MAAM,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC;YACrD,OAAO;gBACH,SAAS;gBACT,iBAAiBJ;YACrB;QACJ;QAEA,IAAII,OAAO,MAAM,IACb;QAGJ,MAAMC,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO;QAC/D,MAAMC,gBAAgBD,eAAe,IAAI,KAClCA,eAAe,KAAK,CAAC,qBAAqB,IAAIE,sCAC/CA;QAEN,MAAMC,YAAY,IAAIC,KAAKA,KAAK,GAAG,KAAKH,AAAgB,KAAhBA,gBAAqB,KAAK,KAAK;QAEvE,KAAK,MAAMI,WAAWN,OAAO,KAAK,CAAC,KAAK,CAAE;YACtC,MAAMO,iBAAiB,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC;gBAC/D,WAAWD,QAAQ,EAAE;gBACrB,WAAWP,MAAM,SAAS;gBAC1B,QAAQ;gBACRK;gBACAP;YACJ;YAEA,KAAIU,eAAe,MAAM,IAIzB,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAwB;gBAClD,YAAYC;gBACZ,MAAM,CAAC,SAAS,EAAEF,QAAQ,IAAI,CAAC,GAAG,EAAEP,MAAM,SAAS,EAAE;gBACrD,OAAO;oBACH,WAAWO,QAAQ,EAAE;oBACrBV;oBACA,YAAYW,eAAe,KAAK,CAAC,EAAE;gBACvC;YACJ;QACJ;IACJ;AACJ;AAEO,MAAME,sCAAoBC,kBAAAA,oBAAiD,CAAC;IAC/E,gBAAgBpB;IAChB,cAAc;QACVqB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -1,14 +1,14 @@
1
1
  const isLocalDevelopment = ()=>"1" === process.env.WEBINY_WATCH_LOCAL_INVOCATION;
2
2
  const isLocalhostName = (hostname)=>"localhost" === hostname || hostname.endsWith(".localhost");
3
3
  const isLoopbackOrLinkLocal = (hostname)=>{
4
- const host = hostname.replace(/^\[|\]$/g, "").toLowerCase();
4
+ const host = hostname.replace(/^\[|\]$/g, "").replace(/\.+$/, "").toLowerCase();
5
5
  if (isLocalhostName(host)) return true;
6
6
  if (host.includes(":")) {
7
7
  if ("::1" === host || "::" === host) return true;
8
8
  if (/^fe[89ab][0-9a-f]:/.test(host)) return true;
9
- const dotted = host.match(/^::ffff:(?:0:)?(\d+\.\d+\.\d+\.\d+)$/);
9
+ const dotted = host.match(/^::(?:ffff:(?:0:)?)?(\d+\.\d+\.\d+\.\d+)$/);
10
10
  if (dotted) return isLoopbackOrLinkLocal(dotted[1]);
11
- const hex = host.match(/^::ffff:(?:0:)?([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
11
+ const hex = host.match(/^::(?:ffff:(?:0:)?)?([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
12
12
  if (hex) {
13
13
  const high = parseInt(hex[1], 16);
14
14
  const low = parseInt(hex[2], 16);
@@ -1 +1 @@
1
- {"version":3,"file":"api/utils/isValidEndpointUrl.js","sources":["../../../src/api/utils/isValidEndpointUrl.ts"],"sourcesContent":["/**\n * Webhook endpoints are called from the API (Lambda). Loopback and link-local addresses point\n * at the Lambda environment itself (e.g. the Lambda Runtime API on 127.0.0.1:9001), never at a\n * real receiver, and the delivery log stores the response body: refuse them.\n *\n * During local development (`webiny watch` runs invocations on the developer's machine) a local\n * receiver is a valid target, so localhost over HTTP is allowed there.\n *\n * TODO: private ranges (10/8, 172.16/12, 192.168/16, 100.64/10, fc00::/7) are still allowed,\n * because projects deployed in a VPC may call internal receivers. Refuse them by default with\n * an allowlist setting for VPC receivers. Also resolve DNS at delivery time (a public hostname\n * can point to a private address) and don't follow redirects to private addresses.\n */\nconst isLocalDevelopment = () => process.env.WEBINY_WATCH_LOCAL_INVOCATION === \"1\";\n\nconst isLocalhostName = (hostname: string) => {\n return hostname === \"localhost\" || hostname.endsWith(\".localhost\");\n};\n\nconst isLoopbackOrLinkLocal = (hostname: string): boolean => {\n const host = hostname.replace(/^\\[|\\]$/g, \"\").toLowerCase();\n\n if (isLocalhostName(host)) {\n return true;\n }\n\n // IPv6: loopback, unspecified, link-local, IPv4-mapped.\n if (host.includes(\":\")) {\n if (host === \"::1\" || host === \"::\") {\n return true;\n }\n if (/^fe[89ab][0-9a-f]:/.test(host)) {\n return true;\n }\n // IPv4-mapped / IPv4-translated addresses. `new URL()` normalizes them to hex\n // (e.g. \"::ffff:127.0.0.1\" becomes \"::ffff:7f00:1\"), so handle both forms.\n const dotted = host.match(/^::ffff:(?:0:)?(\\d+\\.\\d+\\.\\d+\\.\\d+)$/);\n if (dotted) {\n return isLoopbackOrLinkLocal(dotted[1]);\n }\n const hex = host.match(/^::ffff:(?:0:)?([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);\n if (hex) {\n const high = parseInt(hex[1], 16);\n const low = parseInt(hex[2], 16);\n return isLoopbackOrLinkLocal(`${high >> 8}.${high & 255}.${low >> 8}.${low & 255}`);\n }\n return false;\n }\n\n // IPv4: 0.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16.\n const ipv4 = host.match(/^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$/);\n if (!ipv4) {\n return false;\n }\n const [a, b] = [Number(ipv4[1]), Number(ipv4[2])];\n return a === 0 || a === 127 || (a === 169 && b === 254);\n};\n\nexport const isValidEndpointUrl = (url: string): boolean => {\n try {\n const parsed = new URL(url);\n const isLocalTarget = isLoopbackOrLinkLocal(parsed.hostname);\n\n if (isLocalTarget) {\n // Only a local receiver during local development, never link-local addresses.\n return (\n isLocalDevelopment() &&\n (isLocalhostName(parsed.hostname) || parsed.hostname === \"127.0.0.1\")\n );\n }\n\n return parsed.protocol === \"https:\";\n } catch {\n return false;\n }\n};\n"],"names":["isLocalDevelopment","process","isLocalhostName","hostname","isLoopbackOrLinkLocal","host","dotted","hex","high","parseInt","low","ipv4","a","b","Number","isValidEndpointUrl","url","parsed","URL","isLocalTarget"],"mappings":"AAaA,MAAMA,qBAAqB,IAAMC,AAA8C,QAA9CA,QAAQ,GAAG,CAAC,6BAA6B;AAE1E,MAAMC,kBAAkB,CAACC,WACdA,AAAa,gBAAbA,YAA4BA,SAAS,QAAQ,CAAC;AAGzD,MAAMC,wBAAwB,CAACD;IAC3B,MAAME,OAAOF,SAAS,OAAO,CAAC,YAAY,IAAI,WAAW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ourcesContent":["/**\n * Webhook endpoints are called from the API (Lambda). Loopback and link-local addresses point\n * at the Lambda environment itself (e.g. the Lambda Runtime API on 127.0.0.1:9001), never at a\n * real receiver, and the delivery log stores the response body: refuse them.\n *\n * During local development (`webiny watch` runs invocations on the developer's machine) a local\n * receiver is a valid target, so localhost over HTTP is allowed there.\n *\n * TODO: private ranges (10/8, 172.16/12, 192.168/16, 100.64/10, fc00::/7) are still allowed,\n * because projects deployed in a VPC may call internal receivers. Refuse them by default with\n * an allowlist setting for VPC receivers. Also resolve DNS at delivery time (a public hostname\n * can point to a private address). Redirects are never followed (see WebhookDeliver).\n */\nconst isLocalDevelopment = () => process.env.WEBINY_WATCH_LOCAL_INVOCATION === \"1\";\n\nconst isLocalhostName = (hostname: string) => {\n return hostname === \"localhost\" || hostname.endsWith(\".localhost\");\n};\n\nconst isLoopbackOrLinkLocal = (hostname: string): boolean => {\n // A trailing dot (\"localhost.\", \"127.0.0.1.\") names the same host.\n const host = hostname\n .replace(/^\\[|\\]$/g, \"\")\n .replace(/\\.+$/, \"\")\n .toLowerCase();\n\n if (isLocalhostName(host)) {\n return true;\n }\n\n // IPv6: loopback, unspecified, link-local, IPv4-mapped.\n if (host.includes(\":\")) {\n if (host === \"::1\" || host === \"::\") {\n return true;\n }\n if (/^fe[89ab][0-9a-f]:/.test(host)) {\n return true;\n }\n // IPv4-mapped / IPv4-translated / IPv4-compatible addresses. `new URL()` normalizes them\n // to hex (e.g. \"::ffff:127.0.0.1\" becomes \"::ffff:7f00:1\"), so handle both forms.\n const dotted = host.match(/^::(?:ffff:(?:0:)?)?(\\d+\\.\\d+\\.\\d+\\.\\d+)$/);\n if (dotted) {\n return isLoopbackOrLinkLocal(dotted[1]);\n }\n const hex = host.match(/^::(?:ffff:(?:0:)?)?([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);\n if (hex) {\n const high = parseInt(hex[1], 16);\n const low = parseInt(hex[2], 16);\n return isLoopbackOrLinkLocal(`${high >> 8}.${high & 255}.${low >> 8}.${low & 255}`);\n }\n return false;\n }\n\n // IPv4: 0.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16.\n const ipv4 = host.match(/^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$/);\n if (!ipv4) {\n return false;\n }\n const [a, b] = [Number(ipv4[1]), Number(ipv4[2])];\n return a === 0 || a === 127 || (a === 169 && b === 254);\n};\n\nexport const isValidEndpointUrl = (url: string): boolean => {\n try {\n const parsed = new URL(url);\n const isLocalTarget = isLoopbackOrLinkLocal(parsed.hostname);\n\n if (isLocalTarget) {\n // Only a local receiver during local development, never link-local addresses.\n return (\n isLocalDevelopment() &&\n (isLocalhostName(parsed.hostname) || parsed.hostname === \"127.0.0.1\")\n );\n }\n\n return parsed.protocol === \"https:\";\n } catch {\n return false;\n }\n};\n"],"names":["isLocalDevelopment","process","isLocalhostName","hostname","isLoopbackOrLinkLocal","host","dotted","hex","high","parseInt","low","ipv4","a","b","Number","isValidEndpointUrl","url","parsed","URL","isLocalTarget"],"mappings":"AAaA,MAAMA,qBAAqB,IAAMC,AAA8C,QAA9CA,QAAQ,GAAG,CAAC,6BAA6B;AAE1E,MAAMC,kBAAkB,CAACC,WACdA,AAAa,gBAAbA,YAA4BA,SAAS,QAAQ,CAAC;AAGzD,MAAMC,wBAAwB,CAACD;IAE3B,MAAME,OAAOF,SACR,OAAO,CAAC,YAAY,IACpB,OAAO,CAAC,QAAQ,IAChB,WAAW;IAEhB,IAAID,gBAAgBG,OAChB,OAAO;IAIX,IAAIA,KAAK,QAAQ,CAAC,MAAM;QACpB,IAAIA,AAAS,UAATA,QAAkBA,AAAS,SAATA,MAClB,OAAO;QAEX,IAAI,qBAAqB,IAAI,CAACA,OAC1B,OAAO;QAIX,MAAMC,SAASD,KAAK,KAAK,CAAC;QAC1B,IAAIC,QACA,OAAOF,sBAAsBE,MAAM,CAAC,EAAE;QAE1C,MAAMC,MAAMF,KAAK,KAAK,CAAC;QACvB,IAAIE,KAAK;YACL,MAAMC,OAAOC,SAASF,GAAG,CAAC,EAAE,EAAE;YAC9B,MAAMG,MAAMD,SAASF,GAAG,CAAC,EAAE,EAAE;YAC7B,OAAOH,sBAAsB,GAAGI,QAAQ,EAAE,CAAC,EAAEA,AAAO,MAAPA,KAAW,CAAC,EAAEE,OAAO,EAAE,CAAC,EAAEA,AAAM,MAANA,KAAW;QACtF;QACA,OAAO;IACX;IAGA,MAAMC,OAAON,KAAK,KAAK,CAAC;IACxB,IAAI,CAACM,MACD,OAAO;IAEX,MAAM,CAACC,GAAGC,EAAE,GAAG;QAACC,OAAOH,IAAI,CAAC,EAAE;QAAGG,OAAOH,IAAI,CAAC,EAAE;KAAE;IACjD,OAAOC,AAAM,MAANA,KAAWA,AAAM,QAANA,KAAcA,AAAM,QAANA,KAAaC,AAAM,QAANA;AACjD;AAEO,MAAME,qBAAqB,CAACC;IAC/B,IAAI;QACA,MAAMC,SAAS,IAAIC,IAAIF;QACvB,MAAMG,gBAAgBf,sBAAsBa,OAAO,QAAQ;QAE3D,IAAIE,eAEA,OACInB,wBACCE,CAAAA,gBAAgBe,OAAO,QAAQ,KAAKA,AAAoB,gBAApBA,OAAO,QAAQ,AAAe;QAI3E,OAAOA,AAAoB,aAApBA,OAAO,QAAQ;IAC1B,EAAE,OAAM;QACJ,OAAO;IACX;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/webhooks",
3
- "version": "6.4.12-beta.7",
3
+ "version": "6.4.12-beta.8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -19,17 +19,17 @@
19
19
  },
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@webiny/admin-ui": "6.4.12-beta.7",
23
- "@webiny/api-core": "6.4.12-beta.7",
24
- "@webiny/api-headless-cms": "6.4.12-beta.7",
25
- "@webiny/app": "6.4.12-beta.7",
26
- "@webiny/app-admin": "6.4.12-beta.7",
27
- "@webiny/background-tasks": "6.4.12-beta.7",
28
- "@webiny/feature": "6.4.12-beta.7",
29
- "@webiny/handler-graphql": "6.4.12-beta.7",
30
- "@webiny/icons": "6.4.12-beta.7",
31
- "@webiny/sdk": "6.4.12-beta.7",
32
- "@webiny/utils": "6.4.12-beta.7",
22
+ "@webiny/admin-ui": "6.4.12-beta.8",
23
+ "@webiny/api-core": "6.4.12-beta.8",
24
+ "@webiny/api-headless-cms": "6.4.12-beta.8",
25
+ "@webiny/app": "6.4.12-beta.8",
26
+ "@webiny/app-admin": "6.4.12-beta.8",
27
+ "@webiny/background-tasks": "6.4.12-beta.8",
28
+ "@webiny/feature": "6.4.12-beta.8",
29
+ "@webiny/handler-graphql": "6.4.12-beta.8",
30
+ "@webiny/icons": "6.4.12-beta.8",
31
+ "@webiny/sdk": "6.4.12-beta.8",
32
+ "@webiny/utils": "6.4.12-beta.8",
33
33
  "lodash": "4.18.1",
34
34
  "mobx": "7.1.5",
35
35
  "mobx-react-lite": "5.1.2",
@@ -39,13 +39,13 @@
39
39
  "zod": "4.6.7"
40
40
  },
41
41
  "devDependencies": {
42
- "@webiny/api": "6.4.12-beta.7",
43
- "@webiny/build-tools": "6.4.12-beta.7",
42
+ "@webiny/api": "6.4.12-beta.8",
43
+ "@webiny/build-tools": "6.4.12-beta.8",
44
44
  "@webiny/di": "1.1.0",
45
- "@webiny/handler": "6.4.12-beta.7",
46
- "@webiny/handler-aws": "6.4.12-beta.7",
47
- "@webiny/plugins": "6.4.12-beta.7",
48
- "@webiny/project-utils": "6.4.12-beta.7",
45
+ "@webiny/handler": "6.4.12-beta.8",
46
+ "@webiny/handler-aws": "6.4.12-beta.8",
47
+ "@webiny/plugins": "6.4.12-beta.8",
48
+ "@webiny/project-utils": "6.4.12-beta.8",
49
49
  "typescript": "6.0.3",
50
50
  "vitest": "5.1.0"
51
51
  },