@webiny/webhooks 6.4.12-beta.1 → 6.4.12-beta.10

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 (85) hide show
  1. package/admin/WebhookRoutes.js +14 -11
  2. package/admin/WebhookRoutes.js.map +1 -1
  3. package/admin/Webhooks.js +1 -1
  4. package/admin/Webhooks.js.map +1 -1
  5. package/admin/features/createWebhook/abstractions.d.ts +1 -0
  6. package/admin/features/createWebhook/abstractions.js.map +1 -1
  7. package/admin/features/updateWebhook/abstractions.d.ts +1 -0
  8. package/admin/features/updateWebhook/abstractions.js.map +1 -1
  9. package/admin/presentation/SigningSecret/SigningSecretActions.d.ts +11 -0
  10. package/admin/presentation/SigningSecret/SigningSecretActions.js +35 -0
  11. package/admin/presentation/SigningSecret/SigningSecretActions.js.map +1 -0
  12. package/admin/presentation/WebhookDeliveriesPage/components/DeliveryBottomInfoBar.js.map +1 -1
  13. package/admin/presentation/WebhookDeliveriesPage/components/WebhookDeliveriesPage.js.map +1 -1
  14. package/admin/presentation/WebhookForm/WebhookFormPresenter.d.ts +3 -0
  15. package/admin/presentation/WebhookForm/WebhookFormPresenter.js +31 -16
  16. package/admin/presentation/WebhookForm/WebhookFormPresenter.js.map +1 -1
  17. package/admin/presentation/WebhookForm/abstractions.d.ts +2 -0
  18. package/admin/presentation/WebhookForm/abstractions.js.map +1 -1
  19. package/admin/presentation/WebhookForm/components/WebhookFormView.js +11 -4
  20. package/admin/presentation/WebhookForm/components/WebhookFormView.js.map +1 -1
  21. package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.d.ts +3 -0
  22. package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.js +17 -2
  23. package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.js.map +1 -1
  24. package/admin/presentation/WebhookSettings/abstractions.d.ts +3 -0
  25. package/admin/presentation/WebhookSettings/abstractions.js.map +1 -1
  26. package/admin/presentation/WebhookSettings/components/WebhookSettingsView.js +22 -3
  27. package/admin/presentation/WebhookSettings/components/WebhookSettingsView.js.map +1 -1
  28. package/admin/shared/signingSecret.d.ts +2 -0
  29. package/admin/shared/signingSecret.js +8 -0
  30. package/admin/shared/signingSecret.js.map +1 -0
  31. package/api/features/CreateWebhook/schema.js +5 -2
  32. package/api/features/CreateWebhook/schema.js.map +1 -1
  33. package/api/features/GetWebhook/GetWebhookUseCase.js +7 -1
  34. package/api/features/GetWebhook/GetWebhookUseCase.js.map +1 -1
  35. package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.d.ts +2 -2
  36. package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.js +1 -1
  37. package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.js.map +1 -1
  38. package/api/features/GetWebhookSettings/GetWebhookSettingsUseCase.d.ts +15 -0
  39. package/api/features/GetWebhookSettings/GetWebhookSettingsUseCase.js +25 -0
  40. package/api/features/GetWebhookSettings/GetWebhookSettingsUseCase.js.map +1 -0
  41. package/api/features/GetWebhookSettings/{abstractions.d.ts → abstractions/GetWebhookSettingsRepository.d.ts} +2 -2
  42. package/api/features/GetWebhookSettings/{abstractions.js → abstractions/GetWebhookSettingsRepository.js} +1 -1
  43. package/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js.map +1 -0
  44. package/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsUseCase.d.ts +17 -0
  45. package/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsUseCase.js +5 -0
  46. package/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsUseCase.js.map +1 -0
  47. package/api/features/GetWebhookSettings/feature.js +2 -0
  48. package/api/features/GetWebhookSettings/feature.js.map +1 -1
  49. package/api/features/ListWebhooks/ListWebhooksUseCase.js +10 -1
  50. package/api/features/ListWebhooks/ListWebhooksUseCase.js.map +1 -1
  51. package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.d.ts +1 -1
  52. package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js +2 -2
  53. package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js.map +1 -1
  54. package/api/features/SendWebhookTask/SendWebhookTask.d.ts +1 -1
  55. package/api/features/SendWebhookTask/SendWebhookTask.js +16 -2
  56. package/api/features/SendWebhookTask/SendWebhookTask.js.map +1 -1
  57. package/api/features/TriggerWebhook/TriggerWebhookUseCase.d.ts +1 -1
  58. package/api/features/TriggerWebhook/TriggerWebhookUseCase.js +2 -2
  59. package/api/features/TriggerWebhook/TriggerWebhookUseCase.js.map +1 -1
  60. package/api/features/UpdateWebhook/schema.js +5 -2
  61. package/api/features/UpdateWebhook/schema.js.map +1 -1
  62. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.d.ts +1 -1
  63. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js +1 -1
  64. package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js.map +1 -1
  65. package/api/features/UpdateWebhookSettings/schema.js +4 -1
  66. package/api/features/UpdateWebhookSettings/schema.js.map +1 -1
  67. package/api/features/WebhookDeliver/WebhookDeliver.js +1 -0
  68. package/api/features/WebhookDeliver/WebhookDeliver.js.map +1 -1
  69. package/api/features/WebhookDispatcher/WebhookDispatcher.d.ts +1 -1
  70. package/api/features/WebhookDispatcher/WebhookDispatcher.js +2 -2
  71. package/api/features/WebhookDispatcher/WebhookDispatcher.js.map +1 -1
  72. package/api/graphql/WebhookCrudSchema.js +1 -0
  73. package/api/graphql/WebhookCrudSchema.js.map +1 -1
  74. package/api/graphql/WebhookSettingsSchema.js +2 -2
  75. package/api/graphql/WebhookSettingsSchema.js.map +1 -1
  76. package/api/utils/isValidEndpointUrl.js +29 -3
  77. package/api/utils/isValidEndpointUrl.js.map +1 -1
  78. package/api/utils/isValidSigningSecret.d.ts +8 -0
  79. package/api/utils/isValidSigningSecret.js +11 -0
  80. package/api/utils/isValidSigningSecret.js.map +1 -0
  81. package/package.json +22 -22
  82. package/admin/presentation/WebhookForm/components/SigningSecret.d.ts +0 -9
  83. package/admin/presentation/WebhookForm/components/SigningSecret.js +0 -47
  84. package/admin/presentation/WebhookForm/components/SigningSecret.js.map +0 -1
  85. package/api/features/GetWebhookSettings/abstractions.js.map +0 -1
@@ -5,7 +5,7 @@ import { WebhookSignPayload } from "@webiny/api-core/features/webhooks/index.js"
5
5
  import { GetWebhookRepository } from "../../../api/features/GetWebhook/abstractions.js";
6
6
  import { GetWebhookDeliveryRepository } from "../../../api/features/GetWebhookDelivery/abstractions.js";
7
7
  import { UpdateWebhookDeliveryRepository } from "../../../api/features/UpdateWebhookDelivery/abstractions.js";
8
- import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions.js";
8
+ import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
9
9
  import { WebhookDeliver } from "../../../api/features/WebhookDeliver/abstractions.js";
10
10
  import type { ISendWebhookTaskInput, ISendWebhookTaskOutput } from "./types.js";
11
11
  type IRunParams = TaskDefinition.RunParams<ISendWebhookTaskInput, ISendWebhookTaskOutput>;
@@ -1,13 +1,19 @@
1
1
  import "@webiny/background-tasks/api/types.js";
2
+ import { isValidEndpointUrl } from "../../utils/isValidEndpointUrl.js";
2
3
  import { TaskDefinition } from "@webiny/api-core/exports/api/tasks.js";
3
4
  import { TenantContext } from "@webiny/api-core/exports/api/tenancy.js";
4
5
  import { WebhookSignPayload } from "@webiny/api-core/features/webhooks/index.js";
5
6
  import { GetWebhookRepository } from "../GetWebhook/abstractions.js";
6
7
  import { GetWebhookDeliveryRepository } from "../GetWebhookDelivery/abstractions.js";
7
8
  import { UpdateWebhookDeliveryRepository } from "../UpdateWebhookDelivery/abstractions.js";
8
- import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.js";
9
+ import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
9
10
  import { WebhookDeliver } from "../WebhookDeliver/abstractions.js";
10
11
  import { SEND_WEBHOOK_TASK } from "../../domain/constants.js";
12
+ const MAX_STORED_RESPONSE_BODY_LENGTH = 4096;
13
+ const truncateResponseBody = (body)=>{
14
+ if (!body || body.length <= MAX_STORED_RESPONSE_BODY_LENGTH) return body;
15
+ return `${body.slice(0, MAX_STORED_RESPONSE_BODY_LENGTH)}… (truncated)`;
16
+ };
11
17
  class SendWebhookTaskDefinition {
12
18
  constructor(getWebhookRepository, getWebhookDeliveryRepository, updateDeliveryRepository, signPayload, tenantContext, getWebhookSettingsRepository, deliver){
13
19
  this.getWebhookRepository = getWebhookRepository;
@@ -74,6 +80,14 @@ class SendWebhookTaskDefinition {
74
80
  "Content-Type": "application/json",
75
81
  ...signHeaders
76
82
  };
83
+ if (!isValidEndpointUrl(webhook.endpointUrl)) {
84
+ await this.updateDeliveryRepository.execute(input.deliveryId, {
85
+ status: "failed"
86
+ });
87
+ return controller.response.error({
88
+ message: `Webhook endpoint URL is not allowed: ${webhook.endpointUrl}`
89
+ });
90
+ }
77
91
  const result = await this.deliver.execute({
78
92
  url: webhook.endpointUrl,
79
93
  headers: requestHeaders,
@@ -88,7 +102,7 @@ class SendWebhookTaskDefinition {
88
102
  requestHeaders,
89
103
  responseTime: result.responseTime,
90
104
  responseStatus: result.status,
91
- responseBody: result.body,
105
+ responseBody: truncateResponseBody(result.body),
92
106
  status: result.status > 0 ? "delivered" : "failed"
93
107
  });
94
108
  return controller.response.done();
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/SendWebhookTask/SendWebhookTask.js","sources":["../../../../src/api/features/SendWebhookTask/SendWebhookTask.ts"],"sourcesContent":["import \"@webiny/background-tasks/api/types.js\";\nimport { TaskDefinition } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { TenantContext } from \"@webiny/api-core/exports/api/tenancy.js\";\nimport { WebhookSignPayload } from \"@webiny/api-core/features/webhooks/index.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { GetWebhookDeliveryRepository } from \"~/api/features/GetWebhookDelivery/abstractions.js\";\nimport { UpdateWebhookDeliveryRepository } from \"~/api/features/UpdateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions.js\";\nimport { WebhookDeliver } from \"~/api/features/WebhookDeliver/abstractions.js\";\nimport { SEND_WEBHOOK_TASK } from \"~/api/domain/constants.js\";\nimport type { ISendWebhookTaskInput, ISendWebhookTaskOutput, IWebhookPayload } from \"./types.js\";\nimport type { IWebhookSignPayloadHeaders } from \"@webiny/api-core/features/webhooks/WebhookSignPayload/abstractions.js\";\n\ntype IRunParams = TaskDefinition.RunParams<ISendWebhookTaskInput, ISendWebhookTaskOutput>;\n\nclass SendWebhookTaskDefinition implements TaskDefinition.Interface<\n ISendWebhookTaskInput,\n ISendWebhookTaskOutput\n> {\n public readonly id = SEND_WEBHOOK_TASK;\n public readonly title = \"Send Webhook\";\n public readonly maxIterations = 1;\n public readonly isPrivate = true;\n public readonly databaseLogs = false;\n public readonly description =\n \"POST a signed event payload to a webhook endpoint and log the delivery.\";\n public readonly selfCleanup = \"always\";\n\n public constructor(\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly getWebhookDeliveryRepository: GetWebhookDeliveryRepository.Interface,\n private readonly updateDeliveryRepository: UpdateWebhookDeliveryRepository.Interface,\n private readonly signPayload: WebhookSignPayload.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly getWebhookSettingsRepository: GetWebhookSettingsRepository.Interface,\n private readonly deliver: WebhookDeliver.Interface\n ) {}\n\n public async run(params: IRunParams) {\n const { input, controller } = params;\n const taskId = controller.state.getTask().id;\n\n const delivery = await this.getWebhookDeliveryRepository.execute(input.deliveryId);\n if (delivery.isFail()) {\n return controller.response.error(delivery.error);\n }\n\n await this.updateDeliveryRepository.execute(input.deliveryId, {\n backgroundTaskId: taskId,\n status: \"delivering\"\n });\n\n const webhookResult = await this.getWebhookRepository.execute(input.webhookId);\n if (webhookResult.isFail()) {\n await this.updateDeliveryRepository.execute(input.deliveryId, { status: \"failed\" });\n return controller.response.error(webhookResult.error);\n }\n const webhook = webhookResult.value;\n\n const now = new Date();\n const payload: IWebhookPayload = {\n id: taskId,\n event: input.eventName,\n timestamp: now.toISOString(),\n webhookId: input.webhookId,\n deliveryId: input.deliveryId,\n tenant: this.tenantContext.getTenant().id,\n data: delivery.value.payload\n };\n const rawBody = JSON.stringify(payload);\n let signHeaders: IWebhookSignPayloadHeaders;\n\n const settingsResult = await this.getWebhookSettingsRepository.execute();\n if (settingsResult.isFail()) {\n await this.updateDeliveryRepository.execute(input.deliveryId, { status: \"failed\" });\n return controller.response.error(settingsResult.error);\n }\n const signingSecret = webhook.signingSecret || settingsResult.value.signingSecret || \"\";\n\n try {\n signHeaders = await this.signPayload.sign(taskId, now, rawBody, signingSecret);\n } catch (ex) {\n await this.updateDeliveryRepository.execute(input.deliveryId, { status: \"failed\" });\n return controller.response.error(ex);\n }\n\n const requestHeaders: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n ...signHeaders\n };\n\n const result = await this.deliver.execute({\n url: webhook.endpointUrl,\n headers: requestHeaders,\n body: rawBody,\n timeout: 600_000,\n maxRetries: 3,\n initialDelay: 1000,\n maxDelay: 30_000\n });\n\n await this.updateDeliveryRepository.execute(input.deliveryId, {\n payload,\n requestHeaders,\n responseTime: result.responseTime,\n responseStatus: result.status,\n responseBody: result.body,\n status: result.status > 0 ? \"delivered\" : \"failed\"\n });\n\n return controller.response.done();\n }\n}\n\nexport const SendWebhookTask = TaskDefinition.createImplementation({\n implementation: SendWebhookTaskDefinition,\n dependencies: [\n GetWebhookRepository,\n GetWebhookDeliveryRepository,\n UpdateWebhookDeliveryRepository,\n WebhookSignPayload,\n TenantContext,\n GetWebhookSettingsRepository,\n WebhookDeliver\n ]\n});\n"],"names":["SendWebhookTaskDefinition","getWebhookRepository","getWebhookDeliveryRepository","updateDeliveryRepository","signPayload","tenantContext","getWebhookSettingsRepository","deliver","SEND_WEBHOOK_TASK","params","input","controller","taskId","delivery","webhookResult","webhook","now","Date","payload","rawBody","JSON","signHeaders","settingsResult","signingSecret","ex","requestHeaders","result","SendWebhookTask","TaskDefinition","GetWebhookRepository","GetWebhookDeliveryRepository","UpdateWebhookDeliveryRepository","WebhookSignPayload","TenantContext","GetWebhookSettingsRepository","WebhookDeliver"],"mappings":";;;;;;;;;;AAeA,MAAMA;IAaF,YACqBC,oBAAoD,EACpDC,4BAAoE,EACpEC,wBAAmE,EACnEC,WAAyC,EACzCC,aAAsC,EACtCC,4BAAoE,EACpEC,OAAiC,CACpD;aAPmBN,oBAAoB,GAApBA;aACAC,4BAA4B,GAA5BA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,4BAA4B,GAA5BA;aACAC,OAAO,GAAPA;aAhBL,EAAE,GAAGC;aACL,KAAK,GAAG;aACR,aAAa,GAAG;aAChB,SAAS,GAAG;aACZ,YAAY,GAAG;aACf,WAAW,GACvB;aACY,WAAW,GAAG;IAU3B;IAEH,MAAa,IAAIC,MAAkB,EAAE;QACjC,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAC9B,MAAMG,SAASD,WAAW,KAAK,CAAC,OAAO,GAAG,EAAE;QAE5C,MAAME,WAAW,MAAM,IAAI,CAAC,4BAA4B,CAAC,OAAO,CAACH,MAAM,UAAU;QACjF,IAAIG,SAAS,MAAM,IACf,OAAOF,WAAW,QAAQ,CAAC,KAAK,CAACE,SAAS,KAAK;QAGnD,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAACH,MAAM,UAAU,EAAE;YAC1D,kBAAkBE;YAClB,QAAQ;QACZ;QAEA,MAAME,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACJ,MAAM,SAAS;QAC7E,IAAII,cAAc,MAAM,IAAI;YACxB,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAACJ,MAAM,UAAU,EAAE;gBAAE,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I,CAAC,wBAAwB,CAAC,OAAO,CAACT,MAAM,UAAU,EAAE;YAC1DQ;YACAO;YACA,cAAcC,OAAO,YAAY;YACjC,gBAAgBA,OAAO,MAAM;YAC7B,cAAcA,OAAO,IAAI;YACzB,QAAQA,OAAO,MAAM,GAAG,IAAI,cAAc;QAC9C;QAEA,OAAOf,WAAW,QAAQ,CAAC,IAAI;IACnC;AACJ;AAEO,MAAMgB,kBAAkBC,eAAe,oBAAoB,CAAC;IAC/D,gBAAgB5B;IAChB,cAAc;QACV6B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/SendWebhookTask/SendWebhookTask.js","sources":["../../../../src/api/features/SendWebhookTask/SendWebhookTask.ts"],"sourcesContent":["import \"@webiny/background-tasks/api/types.js\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.js\";\nimport { TaskDefinition } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { TenantContext } from \"@webiny/api-core/exports/api/tenancy.js\";\nimport { WebhookSignPayload } from \"@webiny/api-core/features/webhooks/index.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { GetWebhookDeliveryRepository } from \"~/api/features/GetWebhookDelivery/abstractions.js\";\nimport { UpdateWebhookDeliveryRepository } from \"~/api/features/UpdateWebhookDelivery/abstractions.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport { WebhookDeliver } from \"~/api/features/WebhookDeliver/abstractions.js\";\nimport { SEND_WEBHOOK_TASK } from \"~/api/domain/constants.js\";\nimport type { ISendWebhookTaskInput, ISendWebhookTaskOutput, IWebhookPayload } from \"./types.js\";\nimport type { IWebhookSignPayloadHeaders } from \"@webiny/api-core/features/webhooks/WebhookSignPayload/abstractions.js\";\n\ntype IRunParams = TaskDefinition.RunParams<ISendWebhookTaskInput, ISendWebhookTaskOutput>;\n\n/* The delivery log only needs enough of the response to debug the receiver. */\nconst MAX_STORED_RESPONSE_BODY_LENGTH = 4096;\nconst truncateResponseBody = (body: string | undefined) => {\n if (!body || body.length <= MAX_STORED_RESPONSE_BODY_LENGTH) {\n return body;\n }\n return `${body.slice(0, MAX_STORED_RESPONSE_BODY_LENGTH)}… (truncated)`;\n};\n\nclass SendWebhookTaskDefinition implements TaskDefinition.Interface<\n ISendWebhookTaskInput,\n ISendWebhookTaskOutput\n> {\n public readonly id = SEND_WEBHOOK_TASK;\n public readonly title = \"Send Webhook\";\n public readonly maxIterations = 1;\n public readonly isPrivate = true;\n public readonly databaseLogs = false;\n public readonly description =\n \"POST a signed event payload to a webhook endpoint and log the delivery.\";\n public readonly selfCleanup = \"always\";\n\n public constructor(\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly getWebhookDeliveryRepository: GetWebhookDeliveryRepository.Interface,\n private readonly updateDeliveryRepository: UpdateWebhookDeliveryRepository.Interface,\n private readonly signPayload: WebhookSignPayload.Interface,\n private readonly tenantContext: TenantContext.Interface,\n private readonly getWebhookSettingsRepository: GetWebhookSettingsRepository.Interface,\n private readonly deliver: WebhookDeliver.Interface\n ) {}\n\n public async run(params: IRunParams) {\n const { input, controller } = params;\n const taskId = controller.state.getTask().id;\n\n const delivery = await this.getWebhookDeliveryRepository.execute(input.deliveryId);\n if (delivery.isFail()) {\n return controller.response.error(delivery.error);\n }\n\n await this.updateDeliveryRepository.execute(input.deliveryId, {\n backgroundTaskId: taskId,\n status: \"delivering\"\n });\n\n const webhookResult = await this.getWebhookRepository.execute(input.webhookId);\n if (webhookResult.isFail()) {\n await this.updateDeliveryRepository.execute(input.deliveryId, { status: \"failed\" });\n return controller.response.error(webhookResult.error);\n }\n const webhook = webhookResult.value;\n\n const now = new Date();\n const payload: IWebhookPayload = {\n id: taskId,\n event: input.eventName,\n timestamp: now.toISOString(),\n webhookId: input.webhookId,\n deliveryId: input.deliveryId,\n tenant: this.tenantContext.getTenant().id,\n data: delivery.value.payload\n };\n const rawBody = JSON.stringify(payload);\n let signHeaders: IWebhookSignPayloadHeaders;\n\n const settingsResult = await this.getWebhookSettingsRepository.execute();\n if (settingsResult.isFail()) {\n await this.updateDeliveryRepository.execute(input.deliveryId, { status: \"failed\" });\n return controller.response.error(settingsResult.error);\n }\n const signingSecret = webhook.signingSecret || settingsResult.value.signingSecret || \"\";\n\n try {\n signHeaders = await this.signPayload.sign(taskId, now, rawBody, signingSecret);\n } catch (ex) {\n await this.updateDeliveryRepository.execute(input.deliveryId, { status: \"failed\" });\n return controller.response.error(ex);\n }\n\n const requestHeaders: Record<string, string> = {\n \"Content-Type\": \"application/json\",\n ...signHeaders\n };\n\n // Webhooks stored before the endpoint rules were tightened may still point to a local address.\n if (!isValidEndpointUrl(webhook.endpointUrl)) {\n await this.updateDeliveryRepository.execute(input.deliveryId, { status: \"failed\" });\n return controller.response.error({\n message: `Webhook endpoint URL is not allowed: ${webhook.endpointUrl}`\n });\n }\n\n const result = await this.deliver.execute({\n url: webhook.endpointUrl,\n headers: requestHeaders,\n body: rawBody,\n timeout: 600_000,\n maxRetries: 3,\n initialDelay: 1000,\n maxDelay: 30_000\n });\n\n await this.updateDeliveryRepository.execute(input.deliveryId, {\n payload,\n requestHeaders,\n responseTime: result.responseTime,\n responseStatus: result.status,\n responseBody: truncateResponseBody(result.body),\n status: result.status > 0 ? \"delivered\" : \"failed\"\n });\n\n return controller.response.done();\n }\n}\n\nexport const SendWebhookTask = TaskDefinition.createImplementation({\n implementation: SendWebhookTaskDefinition,\n dependencies: [\n GetWebhookRepository,\n GetWebhookDeliveryRepository,\n UpdateWebhookDeliveryRepository,\n WebhookSignPayload,\n TenantContext,\n GetWebhookSettingsRepository,\n WebhookDeliver\n ]\n});\n"],"names":["MAX_STORED_RESPONSE_BODY_LENGTH","truncateResponseBody","body","SendWebhookTaskDefinition","getWebhookRepository","getWebhookDeliveryRepository","updateDeliveryRepository","signPayload","tenantContext","getWebhookSettingsRepository","deliver","SEND_WEBHOOK_TASK","params","input","controller","taskId","delivery","webhookResult","webhook","now","Date","payload","rawBody","JSON","signHeaders","settingsResult","signingSecret","ex","requestHeaders","isValidEndpointUrl","result","SendWebhookTask","TaskDefinition","GetWebhookRepository","GetWebhookDeliveryRepository","UpdateWebhookDeliveryRepository","WebhookSignPayload","TenantContext","GetWebhookSettingsRepository","WebhookDeliver"],"mappings":";;;;;;;;;;;AAiBA,MAAMA,kCAAkC;AACxC,MAAMC,uBAAuB,CAACC;IAC1B,IAAI,CAACA,QAAQA,KAAK,MAAM,IAAIF,iCACxB,OAAOE;IAEX,OAAO,GAAGA,KAAK,KAAK,CAAC,GAAGF,iCAAiC,aAAa,CAAC;AAC3E;AAEA,MAAMG;IAaF,YACqBC,oBAAoD,EACpDC,4BAAoE,EACpEC,wBAAmE,EACnEC,WAAyC,EACzCC,aAAsC,EACtCC,4BAAoE,EACpEC,OAAiC,CACpD;aAPmBN,oBAAoB,GAApBA;aACAC,4BAA4B,GAA5BA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,aAAa,GAAbA;aACAC,4BAA4B,GAA5BA;aACAC,OAAO,GAAPA;aAhBL,EAAE,GAAGC;aACL,KAAK,GAAG;aACR,aAAa,GAAG;aAChB,SAAS,GAAG;aACZ,YAAY,GAAG;aACf,WAAW,GACvB;aACY,WAAW,GAAG;IAU3B;IAEH,MAAa,IAAIC,MAAkB,EAAE;QACjC,MAAM,EAAEC,KAAK,EAAEC,UAAU,EAAE,GAAGF;QAC9B,MAAMG,SAASD,WAAW,KAAK,CAAC,OAAO,GAAG,EAAE;QAE5C,MAAME,WAAW,MAAM,IAAI,CAAC,4BAA4B,CAAC,OAAO,CAACH,MAAM,UAAU;QACjF,IAAIG,SAAS,MAAM,IACf,OAAOF,WAAW,QAAQ,CAAC,KAAK,CAACE,SAAS,KAAK;QAGnD,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAACH,MAAM,UAAU,EAAE;YAC1D,kBAAkBE;YAClB,QAAQ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GJ,WAAW;QAClB;QAGA,IAAI,CAACK,mBAAmBX,QAAQ,WAAW,GAAG;YAC1C,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAACL,MAAM,UAAU,EAAE;gBAAE,QAAQ;YAAS;YACjF,OAAOC,WAAW,QAAQ,CAAC,KAAK,CAAC;gBAC7B,SAAS,CAAC,qCAAqC,EAAEI,QAAQ,WAAW,EAAE;YAC1E;QACJ;QAEA,MAAMY,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;YACtC,KAAKZ,QAAQ,WAAW;YACxB,SAASU;YACT,MAAMN;YACN,SAAS;YACT,YAAY;YACZ,cAAc;YACd,UAAU;QACd;QAEA,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAACT,MAAM,UAAU,EAAE;YAC1DQ;YACAO;YACA,cAAcE,OAAO,YAAY;YACjC,gBAAgBA,OAAO,MAAM;YAC7B,cAAc7B,qBAAqB6B,OAAO,IAAI;YAC9C,QAAQA,OAAO,MAAM,GAAG,IAAI,cAAc;QAC9C;QAEA,OAAOhB,WAAW,QAAQ,CAAC,IAAI;IACnC;AACJ;AAEO,MAAMiB,kBAAkBC,eAAe,oBAAoB,CAAC;IAC/D,gBAAgB7B;IAChB,cAAc;QACV8B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -3,7 +3,7 @@ import { TaskService } from "@webiny/api-core/exports/api/tasks.js";
3
3
  import { TriggerWebhookUseCase as UseCaseAbstraction } from "./abstractions.js";
4
4
  import { GetWebhookRepository } from "../../../api/features/GetWebhook/abstractions.js";
5
5
  import { CreateWebhookDeliveryRepository } from "../../../api/features/CreateWebhookDelivery/abstractions.js";
6
- import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions.js";
6
+ import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
7
7
  import { WebhookPermissions } from "../../../api/features/WebhookPermissions/abstractions.js";
8
8
  import type { WebhookDelivery } from "../../../api/domain/WebhookDelivery.js";
9
9
  declare class TriggerWebhookUseCaseImpl implements UseCaseAbstraction.Interface {
@@ -4,7 +4,7 @@ import { TriggerWebhookUseCase } from "./abstractions.js";
4
4
  import { TriggerWebhookInputSchema } from "./schema.js";
5
5
  import { GetWebhookRepository } from "../GetWebhook/abstractions.js";
6
6
  import { CreateWebhookDeliveryRepository } from "../CreateWebhookDelivery/abstractions.js";
7
- import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.js";
7
+ import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
8
8
  import { WebhookPermissions } from "../WebhookPermissions/abstractions.js";
9
9
  import { WebhookNotAuthorizedError, WebhookValidationError } from "../../domain/errors.js";
10
10
  import { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from "../../domain/constants.js";
@@ -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.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;QA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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,GAAxB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OAAO,EAAE,CAACa;IACrB;AACJ;AAEO,MAAME,8CAAwBC,sBAAAA,oBAAuC,CAAC;IACzE,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -1,14 +1,17 @@
1
1
  import { z } from "zod";
2
+ import { INVALID_SIGNING_SECRET_MESSAGE, isValidSigningSecret } from "../../utils/isValidSigningSecret.js";
2
3
  import { isValidEndpointUrl } from "../../utils/isValidEndpointUrl.js";
3
4
  const UpdateWebhookInputSchema = z.object({
4
5
  name: z.string().min(1, "Name must not be empty.").optional(),
5
6
  endpointUrl: z.string().refine(isValidEndpointUrl, {
6
- message: "Endpoint URL must use HTTPS. HTTP is only allowed for localhost."
7
+ message: "Endpoint URL must use HTTPS and must not point to a local or link-local address."
7
8
  }).optional(),
8
9
  description: z.string().optional(),
9
10
  enabled: z.boolean().optional(),
10
11
  events: z.array(z.string()).min(1, "At least one event must be selected.").optional(),
11
- signingSecret: z.string().optional()
12
+ signingSecret: z.string().refine(isValidSigningSecret, {
13
+ message: INVALID_SIGNING_SECRET_MESSAGE
14
+ }).optional()
12
15
  });
13
16
  export { UpdateWebhookInputSchema };
14
17
 
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/UpdateWebhook/schema.js","sources":["../../../../src/api/features/UpdateWebhook/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.js\";\n\nexport const UpdateWebhookInputSchema = z.object({\n name: z.string().min(1, \"Name must not be empty.\").optional(),\n endpointUrl: z\n .string()\n .refine(isValidEndpointUrl, {\n message: \"Endpoint URL must use HTTPS. HTTP is only allowed for localhost.\"\n })\n .optional(),\n description: z.string().optional(),\n enabled: z.boolean().optional(),\n events: z.array(z.string()).min(1, \"At least one event must be selected.\").optional(),\n signingSecret: z.string().optional()\n});\n"],"names":["UpdateWebhookInputSchema","z","isValidEndpointUrl"],"mappings":";;AAGO,MAAMA,2BAA2BC,EAAE,MAAM,CAAC;IAC7C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,2BAA2B,QAAQ;IAC3D,aAAaA,EAAAA,MACF,GACN,MAAM,CAACC,oBAAoB;QACxB,SAAS;IACb,GACC,QAAQ;IACb,aAAaD,EAAE,MAAM,GAAG,QAAQ;IAChC,SAASA,EAAE,OAAO,GAAG,QAAQ;IAC7B,QAAQA,EAAE,KAAK,CAACA,EAAE,MAAM,IAAI,GAAG,CAAC,GAAG,wCAAwC,QAAQ;IACnF,eAAeA,EAAE,MAAM,GAAG,QAAQ;AACtC"}
1
+ {"version":3,"file":"api/features/UpdateWebhook/schema.js","sources":["../../../../src/api/features/UpdateWebhook/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n INVALID_SIGNING_SECRET_MESSAGE,\n isValidSigningSecret\n} from \"~/api/utils/isValidSigningSecret.js\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.js\";\n\nexport const UpdateWebhookInputSchema = z.object({\n name: z.string().min(1, \"Name must not be empty.\").optional(),\n endpointUrl: z\n .string()\n .refine(isValidEndpointUrl, {\n message:\n \"Endpoint URL must use HTTPS and must not point to a local or link-local address.\"\n })\n .optional(),\n description: z.string().optional(),\n enabled: z.boolean().optional(),\n events: z.array(z.string()).min(1, \"At least one event must be selected.\").optional(),\n signingSecret: z\n .string()\n .refine(isValidSigningSecret, { message: INVALID_SIGNING_SECRET_MESSAGE })\n .optional()\n});\n"],"names":["UpdateWebhookInputSchema","z","isValidEndpointUrl","isValidSigningSecret","INVALID_SIGNING_SECRET_MESSAGE"],"mappings":";;;AAOO,MAAMA,2BAA2BC,EAAE,MAAM,CAAC;IAC7C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,2BAA2B,QAAQ;IAC3D,aAAaA,EAAAA,MACF,GACN,MAAM,CAACC,oBAAoB;QACxB,SACI;IACR,GACC,QAAQ;IACb,aAAaD,EAAE,MAAM,GAAG,QAAQ;IAChC,SAASA,EAAE,OAAO,GAAG,QAAQ;IAC7B,QAAQA,EAAE,KAAK,CAACA,EAAE,MAAM,IAAI,GAAG,CAAC,GAAG,wCAAwC,QAAQ;IACnF,eAAeA,EAAAA,MACJ,GACN,MAAM,CAACE,sBAAsB;QAAE,SAASC;IAA+B,GACvE,QAAQ;AACjB"}
@@ -3,7 +3,7 @@ import { GetModelRepository } from "@webiny/api-headless-cms/features/contentMod
3
3
  import { GetLatestRevisionByEntryIdRepository } from "@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js";
4
4
  import { UpdateEntryRepository } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
5
5
  import { UpdateEntryDataFactory } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
6
- import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions.js";
6
+ import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
7
7
  import { UpdateWebhookSettingsRepository as RepositoryAbstraction, type IUpdateWebhookSettingsInput } from "./abstractions.js";
8
8
  import type { IWebhookSettings } from "../../../api/domain/WebhookSettings.js";
9
9
  declare class UpdateWebhookSettingsRepositoryImpl implements RepositoryAbstraction.Interface {
@@ -4,7 +4,7 @@ import { GetModelRepository } from "@webiny/api-headless-cms/features/contentMod
4
4
  import { GetLatestRevisionByEntryIdRepository } from "@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js";
5
5
  import { UpdateEntryRepository } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
6
6
  import { UpdateEntryDataFactory } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
7
- import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.js";
7
+ import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
8
8
  import { UpdateWebhookSettingsRepository } from "./abstractions.js";
9
9
  import { WebhookModelNotFoundError, WebhookPersistenceError } from "../../domain/errors.js";
10
10
  import { WEBHOOK_SETTINGS_MODEL_ID } from "../../domain/constants.js";
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js","sources":["../../../../src/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createCacheKey } from \"@webiny/utils\";\nimport { GetModelRepository } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { UpdateEntryRepository } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { UpdateEntryDataFactory } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions.js\";\nimport {\n UpdateWebhookSettingsRepository as RepositoryAbstraction,\n type IUpdateWebhookSettingsInput\n} from \"./abstractions.js\";\nimport { WebhookModelNotFoundError, WebhookPersistenceError } from \"~/api/domain/errors.js\";\nimport { WEBHOOK_SETTINGS_MODEL_ID } from \"~/api/domain/constants.js\";\nimport type { IWebhookSettings } from \"~/api/domain/WebhookSettings.js\";\n\ninterface WebhookSettingsValues {\n signingSecret?: string;\n deliveryRetentionDays?: number;\n}\n\nclass UpdateWebhookSettingsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private readonly getModelRepository: GetModelRepository.Interface,\n private readonly getWebhookSettingsRepository: GetWebhookSettingsRepository.Interface,\n private readonly getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface,\n private readonly updateEntryRepository: UpdateEntryRepository.Interface,\n private readonly updateEntryDataFactory: UpdateEntryDataFactory.Interface\n ) {}\n\n async execute(\n input: IUpdateWebhookSettingsInput\n ): Promise<Result<IWebhookSettings, RepositoryAbstraction.Error>> {\n try {\n /* Ensure the singleton entry exists (creates if missing). */\n const getResult = await this.getWebhookSettingsRepository.execute();\n if (getResult.isFail()) {\n return getResult;\n }\n\n const modelResult = await this.getModelRepository.execute(WEBHOOK_SETTINGS_MODEL_ID);\n if (modelResult.isFail()) {\n return Result.fail(new WebhookModelNotFoundError(WEBHOOK_SETTINGS_MODEL_ID));\n }\n\n const model = modelResult.value;\n const singletonId = createCacheKey(model.modelId);\n const entryId = `${singletonId}#0001`;\n\n const entryResult =\n await this.getLatestRevisionRepository.execute<WebhookSettingsValues>(model, {\n id: entryId\n });\n\n if (entryResult.isFail()) {\n return Result.fail(WebhookPersistenceError.from(entryResult.error));\n }\n\n const { entry } = await this.updateEntryDataFactory.create<WebhookSettingsValues>(\n model,\n {\n values: {\n signingSecret: input.signingSecret,\n deliveryRetentionDays: input.deliveryRetentionDays\n }\n },\n entryResult.value\n );\n\n const updateResult = await this.updateEntryRepository.execute(model, entry);\n if (updateResult.isFail()) {\n return Result.fail(WebhookPersistenceError.from(updateResult.error));\n }\n\n const settings: IWebhookSettings = {\n signingSecret: entry.values.signingSecret,\n deliveryRetentionDays: entry.values.deliveryRetentionDays\n };\n\n return Result.ok(settings);\n } catch (error) {\n return Result.fail(WebhookPersistenceError.from(error));\n }\n }\n}\n\nexport const UpdateWebhookSettingsRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateWebhookSettingsRepositoryImpl,\n dependencies: [\n GetModelRepository,\n GetWebhookSettingsRepository,\n GetLatestRevisionByEntryIdRepository,\n UpdateEntryRepository,\n UpdateEntryDataFactory\n ]\n});\n"],"names":["UpdateWebhookSettingsRepositoryImpl","getModelRepository","getWebhookSettingsRepository","getLatestRevisionRepository","updateEntryRepository","updateEntryDataFactory","input","getResult","modelResult","WEBHOOK_SETTINGS_MODEL_ID","Result","WebhookModelNotFoundError","model","singletonId","createCacheKey","entryId","entryResult","WebhookPersistenceError","entry","updateResult","settings","error","UpdateWebhookSettingsRepository","RepositoryAbstraction","GetModelRepository","GetWebhookSettingsRepository","GetLatestRevisionByEnt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AA6B;gBAC/B,eAAeF,MAAM,MAAM,CAAC,aAAa;gBACzC,uBAAuBA,MAAM,MAAM,CAAC,qBAAqB;YAC7D;YAEA,OAAOR,OAAO,EAAE,CAACU;QACrB,EAAE,OAAOC,OAAO;YACZ,OAAOX,OAAO,IAAI,CAACO,wBAAwB,IAAI,CAACI;QACpD;IACJ;AACJ;AAEO,MAAMC,kEAAkCC,gCAAAA,oBAA0C,CAAC;IACtF,gBAAgBvB;IAChB,cAAc;QACVwB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
1
+ {"version":3,"file":"api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js","sources":["../../../../src/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createCacheKey } from \"@webiny/utils\";\nimport { GetModelRepository } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { UpdateEntryRepository } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { UpdateEntryDataFactory } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js\";\nimport {\n UpdateWebhookSettingsRepository as RepositoryAbstraction,\n type IUpdateWebhookSettingsInput\n} from \"./abstractions.js\";\nimport { WebhookModelNotFoundError, WebhookPersistenceError } from \"~/api/domain/errors.js\";\nimport { WEBHOOK_SETTINGS_MODEL_ID } from \"~/api/domain/constants.js\";\nimport type { IWebhookSettings } from \"~/api/domain/WebhookSettings.js\";\n\ninterface WebhookSettingsValues {\n signingSecret?: string;\n deliveryRetentionDays?: number;\n}\n\nclass UpdateWebhookSettingsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private readonly getModelRepository: GetModelRepository.Interface,\n private readonly getWebhookSettingsRepository: GetWebhookSettingsRepository.Interface,\n private readonly getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface,\n private readonly updateEntryRepository: UpdateEntryRepository.Interface,\n private readonly updateEntryDataFactory: UpdateEntryDataFactory.Interface\n ) {}\n\n async execute(\n input: IUpdateWebhookSettingsInput\n ): Promise<Result<IWebhookSettings, RepositoryAbstraction.Error>> {\n try {\n /* Ensure the singleton entry exists (creates if missing). */\n const getResult = await this.getWebhookSettingsRepository.execute();\n if (getResult.isFail()) {\n return getResult;\n }\n\n const modelResult = await this.getModelRepository.execute(WEBHOOK_SETTINGS_MODEL_ID);\n if (modelResult.isFail()) {\n return Result.fail(new WebhookModelNotFoundError(WEBHOOK_SETTINGS_MODEL_ID));\n }\n\n const model = modelResult.value;\n const singletonId = createCacheKey(model.modelId);\n const entryId = `${singletonId}#0001`;\n\n const entryResult =\n await this.getLatestRevisionRepository.execute<WebhookSettingsValues>(model, {\n id: entryId\n });\n\n if (entryResult.isFail()) {\n return Result.fail(WebhookPersistenceError.from(entryResult.error));\n }\n\n const { entry } = await this.updateEntryDataFactory.create<WebhookSettingsValues>(\n model,\n {\n values: {\n signingSecret: input.signingSecret,\n deliveryRetentionDays: input.deliveryRetentionDays\n }\n },\n entryResult.value\n );\n\n const updateResult = await this.updateEntryRepository.execute(model, entry);\n if (updateResult.isFail()) {\n return Result.fail(WebhookPersistenceError.from(updateResult.error));\n }\n\n const settings: IWebhookSettings = {\n signingSecret: entry.values.signingSecret,\n deliveryRetentionDays: entry.values.deliveryRetentionDays\n };\n\n return Result.ok(settings);\n } catch (error) {\n return Result.fail(WebhookPersistenceError.from(error));\n }\n }\n}\n\nexport const UpdateWebhookSettingsRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateWebhookSettingsRepositoryImpl,\n dependencies: [\n GetModelRepository,\n GetWebhookSettingsRepository,\n GetLatestRevisionByEntryIdRepository,\n UpdateEntryRepository,\n UpdateEntryDataFactory\n ]\n});\n"],"names":["UpdateWebhookSettingsRepositoryImpl","getModelRepository","getWebhookSettingsRepository","getLatestRevisionRepository","updateEntryRepository","updateEntryDataFactory","input","getResult","modelResult","WEBHOOK_SETTINGS_MODEL_ID","Result","WebhookModelNotFoundError","model","singletonId","createCacheKey","entryId","entryResult","WebhookPersistenceError","entry","updateResult","settings","error","UpdateWebhookSettingsRepository","RepositoryAbstraction","GetModelRepository","GetWebhookSettingsRepository","GetLatestRevisionByEntryIdRepository","UpdateEntryRepository","UpdateEntryDataFactory"],"mappings":";;;;;;;;;;AAoBA,MAAMA;IACF,YACqBC,kBAAgD,EAChDC,4BAAoE,EACpEC,2BAA2E,EAC3EC,qBAAsD,EACtDC,sBAAwD,CAC3E;aALmBJ,kBAAkB,GAAlBA;aACAC,4BAA4B,GAA5BA;aACAC,2BAA2B,GAA3BA;aACAC,qBAAqB,GAArBA;aACAC,sBAAsB,GAAtBA;IAClB;IAEH,MAAM,QACFC,KAAkC,EAC4B;QAC9D,IAAI;YAEA,MAAMC,YAAY,MAAM,IAAI,CAAC,4BAA4B,CAAC,OAAO;YACjE,IAAIA,UAAU,MAAM,IAChB,OAAOA;YAGX,MAAMC,cAAc,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACC;YAC1D,IAAID,YAAY,MAAM,IAClB,OAAOE,OAAO,IAAI,CAAC,IAAIC,0BAA0BF;YAGrD,MAAMG,QAAQJ,YAAY,KAAK;YAC/B,MAAMK,cAAcC,eAAeF,MAAM,OAAO;YAChD,MAAMG,UAAU,GAAGF,YAAY,KAAK,CAAC;YAErC,MAAMG,cACF,MAAM,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAwBJ,OAAO;gBACzE,IAAIG;YACR;YAEJ,IAAIC,YAAY,MAAM,IAClB,OAAON,OAAO,IAAI,CAACO,wBAAwB,IAAI,CAACD,YAAY,KAAK;YAGrE,MAAM,EAAEE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CACtDN,OACA;gBACI,QAAQ;oBACJ,eAAeN,MAAM,aAAa;oBAClC,uBAAuBA,MAAM,qBAAqB;gBACtD;YACJ,GACAU,YAAY,KAAK;YAGrB,MAAMG,eAAe,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACP,OAAOM;YACrE,IAAIC,aAAa,MAAM,IACnB,OAAOT,OAAO,IAAI,CAACO,wBAAwB,IAAI,CAACE,aAAa,KAAK;YAGtE,MAAMC,WAA6B;gBAC/B,eAAeF,MAAM,MAAM,CAAC,aAAa;gBACzC,uBAAuBA,MAAM,MAAM,CAAC,qBAAqB;YAC7D;YAEA,OAAOR,OAAO,EAAE,CAACU;QACrB,EAAE,OAAOC,OAAO;YACZ,OAAOX,OAAO,IAAI,CAACO,wBAAwB,IAAI,CAACI;QACpD;IACJ;AACJ;AAEO,MAAMC,kEAAkCC,gCAAAA,oBAA0C,CAAC;IACtF,gBAAgBvB;IAChB,cAAc;QACVwB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -1,7 +1,10 @@
1
1
  import { z } from "zod";
2
+ import { INVALID_SIGNING_SECRET_MESSAGE, isValidSigningSecret } from "../../utils/isValidSigningSecret.js";
2
3
  import { WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from "../../domain/constants.js";
3
4
  const UpdateWebhookSettingsInputSchema = z.object({
4
- signingSecret: z.string().optional(),
5
+ signingSecret: z.string().refine(isValidSigningSecret, {
6
+ message: INVALID_SIGNING_SECRET_MESSAGE
7
+ }).optional(),
5
8
  deliveryRetentionDays: z.number().int().min(0).max(WEBHOOK_DELIVERY_MAX_RETENTION_DAYS).optional()
6
9
  });
7
10
  export { UpdateWebhookSettingsInputSchema };
@@ -1 +1 @@
1
- {"version":3,"file":"api/features/UpdateWebhookSettings/schema.js","sources":["../../../../src/api/features/UpdateWebhookSettings/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\n\nexport const UpdateWebhookSettingsInputSchema = z.object({\n signingSecret: z.string().optional(),\n deliveryRetentionDays: z\n .number()\n .int()\n .min(0)\n .max(WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n .optional()\n});\n"],"names":["UpdateWebhookSettingsInputSchema","z","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS"],"mappings":";;AAGO,MAAMA,mCAAmCC,EAAE,MAAM,CAAC;IACrD,eAAeA,EAAE,MAAM,GAAG,QAAQ;IAClC,uBAAuBA,EAAAA,MACZ,GACN,GAAG,GACH,GAAG,CAAC,GACJ,GAAG,CAACC,qCACJ,QAAQ;AACjB"}
1
+ {"version":3,"file":"api/features/UpdateWebhookSettings/schema.js","sources":["../../../../src/api/features/UpdateWebhookSettings/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport {\n INVALID_SIGNING_SECRET_MESSAGE,\n isValidSigningSecret\n} from \"~/api/utils/isValidSigningSecret.js\";\nimport { WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\n\nexport const UpdateWebhookSettingsInputSchema = z.object({\n signingSecret: z\n .string()\n .refine(isValidSigningSecret, { message: INVALID_SIGNING_SECRET_MESSAGE })\n .optional(),\n deliveryRetentionDays: z\n .number()\n .int()\n .min(0)\n .max(WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n .optional()\n});\n"],"names":["UpdateWebhookSettingsInputSchema","z","isValidSigningSecret","INVALID_SIGNING_SECRET_MESSAGE","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS"],"mappings":";;;AAOO,MAAMA,mCAAmCC,EAAE,MAAM,CAAC;IACrD,eAAeA,EAAAA,MACJ,GACN,MAAM,CAACC,sBAAsB;QAAE,SAASC;IAA+B,GACvE,QAAQ;IACb,uBAAuBF,EAAAA,MACZ,GACN,GAAG,GACH,GAAG,CAAC,GACJ,GAAG,CAACG,qCACJ,QAAQ;AACjB"}
@@ -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,YAAY;QAAK;QAEzE,IAAK,IAAIC,IAAI,GAAGA,KAAKL,MAAM,UAAU,EAAEK,IAAK;YACxC,IAAIA,IAAI,GAAG;gBACP,MAAMC,QAAQ,IAAI,CAAC,YAAY,CAACD,IAAI,GAAGL,OAAOI;gBAC9C,MAAM,IAAI,CAAC,KAAK,CAACE;YACrB;YAEAH;YACAC,aAAa,MAAM,IAAI,CAAC,OAAO,CAACJ;YAEhC,IAAI,CAAC,IAAI,CAAC,WAAW,CAACI,WAAW,MAAM,GACnC;QAER;QAEA,OAAO;YACH,QAAQA,WAAW,MAAM;YACzB,MAAMA,WAAW,IAAI;YACrB,cAAcF,KAAK,GAAG,KAAKD;YAC3BE;QACJ;IACJ;IAEA,MAAc,QAAQH,KAA2B,EAA2B;QACxE,IAAI;YACA,MAAMO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xC,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","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,YAAY;QAAK;QAEzE,IAAK,IAAIC,IAAI,GAAGA,KAAKL,MAAM,UAAU,EAAEK,IAAK;YACxC,IAAIA,IAAI,GAAG;gBACP,MAAMC,QAAQ,IAAI,CAAC,YAAY,CAACD,IAAI,GAAGL,OAAOI;gBAC9C,MAAM,IAAI,CAAC,KAAK,CAACE;YACrB;YAEAH;YACAC,aAAa,MAAM,IAAI,CAAC,OAAO,CAACJ;YAEhC,IAAI,CAAC,I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AI,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"}
@@ -2,7 +2,7 @@ import { WebhookDispatcher as WebhookDispatcherAbstraction, WebhookProvider } fr
2
2
  import { TaskService } from "@webiny/api-core/exports/api/tasks.js";
3
3
  import { ListWebhooksRepository } from "../../../api/features/ListWebhooks/abstractions.js";
4
4
  import { CreateWebhookDeliveryRepository } from "../../../api/features/CreateWebhookDelivery/abstractions.js";
5
- import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions.js";
5
+ import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
6
6
  import type { IWebhookDispatcherData } from "@webiny/api-core/features/webhooks/WebhookDispatcher/abstractions.js";
7
7
  declare class WebhookDispatcherImpl implements WebhookDispatcherAbstraction.Interface {
8
8
  private readonly listWebhooksRepository;
@@ -2,7 +2,7 @@ import { WebhookDispatcher, WebhookProvider } from "@webiny/api-core/features/we
2
2
  import { TaskService } from "@webiny/api-core/exports/api/tasks.js";
3
3
  import { ListWebhooksRepository } from "../ListWebhooks/abstractions.js";
4
4
  import { CreateWebhookDeliveryRepository } from "../CreateWebhookDelivery/abstractions.js";
5
- import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.js";
5
+ import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions/GetWebhookSettingsRepository.js";
6
6
  import { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from "../../domain/constants.js";
7
7
  class WebhookDispatcherImpl {
8
8
  constructor(listWebhooksRepository, createDeliveryRepository, taskService, provider, getSettingsRepository){
@@ -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.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;aAC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;IAChB,cAAc;QACVqB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
@@ -60,6 +60,7 @@ class WebhookCrudSchema_ {
60
60
  description: String
61
61
  enabled: Boolean
62
62
  events: [String!]
63
+ signingSecret: String
63
64
  }
64
65
 
65
66
  input ListWebhooksWhereInput {
@@ -1 +1 @@
1
- {"version":3,"file":"api/graphql/WebhookCrudSchema.js","sources":["../../../src/api/graphql/WebhookCrudSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListResponse } from \"@webiny/handler-graphql\";\nimport { ListErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListWebhooksUseCase } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport type { IListWebhooksInput } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { GetWebhookUseCase } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookUseCase } from \"~/api/features/CreateWebhook/abstractions.js\";\nimport { UpdateWebhookUseCase } from \"~/api/features/UpdateWebhook/abstractions.js\";\nimport { DeleteWebhookUseCase } from \"~/api/features/DeleteWebhook/abstractions.js\";\n\ninterface IIdArgs {\n id: string;\n}\n\ninterface ICreateWebhookArgs {\n input: CreateWebhookUseCase.Input;\n}\n\ninterface IUpdateWebhookArgs {\n id: string;\n input: UpdateWebhookUseCase.Input;\n}\n\nclass WebhookCrudSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookError {\n code: String\n message: String\n data: JSON\n }\n\n type WebhookListMeta {\n cursor: String\n hasMoreItems: Boolean!\n totalCount: Int!\n }\n\n type Webhook {\n id: ID!\n name: String!\n slug: String!\n endpointUrl: String!\n description: String\n enabled: Boolean!\n events: [String!]!\n signingSecret: String\n createdOn: DateTime\n modifiedOn: DateTime\n }\n\n type WebhookResponse {\n data: Webhook\n error: WebhookError\n }\n\n type WebhookListResponse {\n data: [Webhook!]\n meta: WebhookListMeta\n error: WebhookError\n }\n\n input CreateWebhookInput {\n name: String!\n slug: String\n endpointUrl: String!\n description: String\n enabled: Boolean\n events: [String!]!\n signingSecret: String\n }\n\n input UpdateWebhookInput {\n name: String\n endpointUrl: String\n description: String\n enabled: Boolean\n events: [String!]\n }\n\n input ListWebhooksWhereInput {\n enabled: Boolean\n }\n\n type WebhookQuery {\n listWebhooks(\n where: ListWebhooksWhereInput\n limit: Int\n after: String\n ): WebhookListResponse!\n getWebhook(id: ID!): WebhookResponse!\n }\n\n type WebhookMutation {\n createWebhook(input: CreateWebhookInput!): WebhookResponse!\n updateWebhook(id: ID!, input: UpdateWebhookInput!): WebhookResponse!\n deleteWebhook(id: ID!): BooleanResponse!\n }\n\n extend type Query {\n webhooks: WebhookQuery!\n }\n\n extend type Mutation {\n webhooks: WebhookMutation!\n }\n `);\n\n builder.addResolver({\n path: \"Query.webhooks\",\n dependencies: [],\n resolver: () => () => ({})\n });\n\n builder.addResolver({\n path: \"Mutation.webhooks\",\n dependencies: [],\n resolver: () => () => ({})\n });\n\n builder.addResolver<IListWebhooksInput>({\n path: \"WebhookQuery.listWebhooks\",\n dependencies: [ListWebhooksUseCase],\n resolver: (listWebhooks: ListWebhooksUseCase.Interface) => {\n return async ({ args }) => {\n const result = await listWebhooks.execute(args);\n if (result.isFail()) {\n return new ListErrorResponse(result.error);\n }\n return new ListResponse(result.value.items, result.value.meta);\n };\n }\n });\n\n builder.addResolver<IIdArgs>({\n path: \"WebhookQuery.getWebhook\",\n dependencies: [GetWebhookUseCase],\n resolver: (getWebhook: GetWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await getWebhook.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<ICreateWebhookArgs>({\n path: \"WebhookMutation.createWebhook\",\n dependencies: [CreateWebhookUseCase],\n resolver: (createWebhook: CreateWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await createWebhook.execute(args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IUpdateWebhookArgs>({\n path: \"WebhookMutation.updateWebhook\",\n dependencies: [UpdateWebhookUseCase],\n resolver: (updateWebhook: UpdateWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await updateWebhook.execute(args.id, args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IIdArgs>({\n path: \"WebhookMutation.deleteWebhook\",\n dependencies: [DeleteWebhookUseCase],\n resolver: (deleteWebhook: DeleteWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await deleteWebhook.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(true);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebhookCrudSchema = GraphQLSchemaFactory.createImplementation({\n implementation: WebhookCrudSchema_,\n dependencies: []\n});\n"],"names":["WebhookCrudSchema_","builder","ListWebhooksUseCase","listWebhooks","args","result","ListErrorResponse","ListResponse","GetWebhookUseCase","getWebhook","ErrorResponse","Response","CreateWebhookUseCase","createWebhook","UpdateWebhookUseCase","updateWebhook","DeleteWebhookUseCase","deleteWebhook","WebhookCrudSchema","GraphQLSchemaFactory"],"mappings":";;;;;;;AAyBA,MAAMA;IACF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAiFnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc,EAAE;YAChB,UAAU,IAAM,IAAO,EAAC;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AIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAASN,OAAO,KAAK;gBACpC;QAER;QAEAJ,QAAQ,WAAW,CAAU;YACzB,MAAM;YACN,cAAc;gBAACe;aAAqB;YACpC,UAAU,CAACC,gBACA,OAAO,EAAEb,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMY,cAAc,OAAO,CAACb,KAAK,EAAE;oBAClD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAAS;gBACxB;QAER;QAEA,OAAOV;IACX;AACJ;AAEO,MAAMiB,oBAAoBC,qBAAqB,oBAAoB,CAAC;IACvE,gBAAgBnB;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"api/graphql/WebhookCrudSchema.js","sources":["../../../src/api/graphql/WebhookCrudSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListResponse } from \"@webiny/handler-graphql\";\nimport { ListErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListWebhooksUseCase } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport type { IListWebhooksInput } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { GetWebhookUseCase } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookUseCase } from \"~/api/features/CreateWebhook/abstractions.js\";\nimport { UpdateWebhookUseCase } from \"~/api/features/UpdateWebhook/abstractions.js\";\nimport { DeleteWebhookUseCase } from \"~/api/features/DeleteWebhook/abstractions.js\";\n\ninterface IIdArgs {\n id: string;\n}\n\ninterface ICreateWebhookArgs {\n input: CreateWebhookUseCase.Input;\n}\n\ninterface IUpdateWebhookArgs {\n id: string;\n input: UpdateWebhookUseCase.Input;\n}\n\nclass WebhookCrudSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookError {\n code: String\n message: String\n data: JSON\n }\n\n type WebhookListMeta {\n cursor: String\n hasMoreItems: Boolean!\n totalCount: Int!\n }\n\n type Webhook {\n id: ID!\n name: String!\n slug: String!\n endpointUrl: String!\n description: String\n enabled: Boolean!\n events: [String!]!\n signingSecret: String\n createdOn: DateTime\n modifiedOn: DateTime\n }\n\n type WebhookResponse {\n data: Webhook\n error: WebhookError\n }\n\n type WebhookListResponse {\n data: [Webhook!]\n meta: WebhookListMeta\n error: WebhookError\n }\n\n input CreateWebhookInput {\n name: String!\n slug: String\n endpointUrl: String!\n description: String\n enabled: Boolean\n events: [String!]!\n signingSecret: String\n }\n\n input UpdateWebhookInput {\n name: String\n endpointUrl: String\n description: String\n enabled: Boolean\n events: [String!]\n signingSecret: String\n }\n\n input ListWebhooksWhereInput {\n enabled: Boolean\n }\n\n type WebhookQuery {\n listWebhooks(\n where: ListWebhooksWhereInput\n limit: Int\n after: String\n ): WebhookListResponse!\n getWebhook(id: ID!): WebhookResponse!\n }\n\n type WebhookMutation {\n createWebhook(input: CreateWebhookInput!): WebhookResponse!\n updateWebhook(id: ID!, input: UpdateWebhookInput!): WebhookResponse!\n deleteWebhook(id: ID!): BooleanResponse!\n }\n\n extend type Query {\n webhooks: WebhookQuery!\n }\n\n extend type Mutation {\n webhooks: WebhookMutation!\n }\n `);\n\n builder.addResolver({\n path: \"Query.webhooks\",\n dependencies: [],\n resolver: () => () => ({})\n });\n\n builder.addResolver({\n path: \"Mutation.webhooks\",\n dependencies: [],\n resolver: () => () => ({})\n });\n\n builder.addResolver<IListWebhooksInput>({\n path: \"WebhookQuery.listWebhooks\",\n dependencies: [ListWebhooksUseCase],\n resolver: (listWebhooks: ListWebhooksUseCase.Interface) => {\n return async ({ args }) => {\n const result = await listWebhooks.execute(args);\n if (result.isFail()) {\n return new ListErrorResponse(result.error);\n }\n return new ListResponse(result.value.items, result.value.meta);\n };\n }\n });\n\n builder.addResolver<IIdArgs>({\n path: \"WebhookQuery.getWebhook\",\n dependencies: [GetWebhookUseCase],\n resolver: (getWebhook: GetWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await getWebhook.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<ICreateWebhookArgs>({\n path: \"WebhookMutation.createWebhook\",\n dependencies: [CreateWebhookUseCase],\n resolver: (createWebhook: CreateWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await createWebhook.execute(args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IUpdateWebhookArgs>({\n path: \"WebhookMutation.updateWebhook\",\n dependencies: [UpdateWebhookUseCase],\n resolver: (updateWebhook: UpdateWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await updateWebhook.execute(args.id, args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IIdArgs>({\n path: \"WebhookMutation.deleteWebhook\",\n dependencies: [DeleteWebhookUseCase],\n resolver: (deleteWebhook: DeleteWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await deleteWebhook.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(true);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebhookCrudSchema = GraphQLSchemaFactory.createImplementation({\n implementation: WebhookCrudSchema_,\n dependencies: []\n});\n"],"names":["WebhookCrudSchema_","builder","ListWebhooksUseCase","listWebhooks","args","result","ListErrorResponse","ListResponse","GetWebhookUseCase","getWebhook","ErrorResponse","Response","CreateWebhookUseCase","createWebhook","UpdateWebhookUseCase","updateWebhook","DeleteWebhookUseCase","deleteWebhook","WebhookCrudSchema","GraphQLSchemaFactory"],"mappings":";;;;;;;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AO,IAAIM,SAASN,OAAO,KAAK;gBACpC;QAER;QAEAJ,QAAQ,WAAW,CAAqB;YACpC,MAAM;YACN,cAAc;gBAACa;aAAqB;YACpC,UAAU,CAACC,gBACA,OAAO,EAAEX,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMU,cAAc,OAAO,CAACX,KAAK,EAAE,EAAEA,KAAK,KAAK;oBAC9D,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAASN,OAAO,KAAK;gBACpC;QAER;QAEAJ,QAAQ,WAAW,CAAU;YACzB,MAAM;YACN,cAAc;gBAACe;aAAqB;YACpC,UAAU,CAACC,gBACA,OAAO,EAAEb,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMY,cAAc,OAAO,CAACb,KAAK,EAAE;oBAClD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAAS;gBACxB;QAER;QAEA,OAAOV;IACX;AACJ;AAEO,MAAMiB,oBAAoBC,qBAAqB,oBAAoB,CAAC;IACvE,gBAAgBnB;IAChB,cAAc,EAAE;AACpB"}
@@ -1,6 +1,6 @@
1
1
  import { GraphQLSchemaFactory } from "@webiny/handler-graphql/graphql/abstractions.js";
2
2
  import { ErrorResponse, Response } from "@webiny/handler-graphql";
3
- import { GetWebhookSettingsRepository } from "../features/GetWebhookSettings/abstractions.js";
3
+ import { GetWebhookSettingsUseCase } from "../features/GetWebhookSettings/abstractions/GetWebhookSettingsUseCase.js";
4
4
  import { UpdateWebhookSettingsUseCase } from "../features/UpdateWebhookSettings/abstractions.js";
5
5
  class WebhookSettingsSchema_ {
6
6
  async execute(builder) {
@@ -31,7 +31,7 @@ class WebhookSettingsSchema_ {
31
31
  builder.addResolver({
32
32
  path: "WebhookQuery.getSettings",
33
33
  dependencies: [
34
- GetWebhookSettingsRepository
34
+ GetWebhookSettingsUseCase
35
35
  ],
36
36
  resolver: (getSettings)=>async ()=>{
37
37
  const result = await getSettings.execute();
@@ -1 +1 @@
1
- {"version":3,"file":"api/graphql/WebhookSettingsSchema.js","sources":["../../../src/api/graphql/WebhookSettingsSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions.js\";\nimport { UpdateWebhookSettingsUseCase } from \"~/api/features/UpdateWebhookSettings/abstractions.js\";\nimport type { IUpdateWebhookSettingsInput } from \"~/api/features/UpdateWebhookSettings/abstractions.js\";\n\ninterface IUpdateWebhookSettingsArgs {\n input: IUpdateWebhookSettingsInput;\n}\n\nclass WebhookSettingsSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookSettings {\n signingSecret: String\n deliveryRetentionDays: Int\n }\n\n type WebhookSettingsResponse {\n data: WebhookSettings\n error: WebhookError\n }\n\n input UpdateWebhookSettingsInput {\n signingSecret: String\n deliveryRetentionDays: Int\n }\n\n extend type WebhookQuery {\n getSettings: WebhookSettingsResponse\n }\n\n extend type WebhookMutation {\n updateSettings(input: UpdateWebhookSettingsInput!): WebhookSettingsResponse\n }\n `);\n\n builder.addResolver({\n path: \"WebhookQuery.getSettings\",\n dependencies: [GetWebhookSettingsRepository],\n resolver: (getSettings: GetWebhookSettingsRepository.Interface) => {\n return async () => {\n const result = await getSettings.execute();\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IUpdateWebhookSettingsArgs>({\n path: \"WebhookMutation.updateSettings\",\n dependencies: [UpdateWebhookSettingsUseCase],\n resolver: (updateSettings: UpdateWebhookSettingsUseCase.Interface) => {\n return async ({ args }) => {\n const result = await updateSettings.execute(args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebhookSettingsSchema = GraphQLSchemaFactory.createImplementation({\n implementation: WebhookSettingsSchema_,\n dependencies: []\n});\n"],"names":["WebhookSettingsSchema_","builder","GetWebhookSettingsRepository","getSettings","result","ErrorResponse","Response","UpdateWebhookSettingsUseCase","updateSettings","args","WebhookSettingsSchema","GraphQLSchemaFactory"],"mappings":";;;;AAWA,MAAMA;IACF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;QAuBnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc;gBAACC;aAA6B;YAC5C,UAAU,CAACC,cACA;oBACH,MAAMC,SAAS,MAAMD,YAAY,OAAO;oBACxC,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;oBAEzC,OAAO,IAAIE,SAASF,OAAO,KAAK;gBACpC;QAER;QAEAH,QAAQ,WAAW,CAA6B;YAC5C,MAAM;YACN,cAAc;gBAACM;aAA6B;YAC5C,UAAU,CAACC,iBACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAML,SAAS,MAAMI,eAAe,OAAO,CAACC,KAAK,KAAK;oBACtD,IAAIL,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;oBAEzC,OAAO,IAAIE,SAASF,OAAO,KAAK;gBACpC;QAER;QAEA,OAAOH;IACX;AACJ;AAEO,MAAMS,wBAAwBC,qBAAqB,oBAAoB,CAAC;IAC3E,gBAAgBX;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"api/graphql/WebhookSettingsSchema.js","sources":["../../../src/api/graphql/WebhookSettingsSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { GetWebhookSettingsUseCase } from \"~/api/features/GetWebhookSettings/abstractions/GetWebhookSettingsUseCase.js\";\nimport { UpdateWebhookSettingsUseCase } from \"~/api/features/UpdateWebhookSettings/abstractions.js\";\nimport type { IUpdateWebhookSettingsInput } from \"~/api/features/UpdateWebhookSettings/abstractions.js\";\n\ninterface IUpdateWebhookSettingsArgs {\n input: IUpdateWebhookSettingsInput;\n}\n\nclass WebhookSettingsSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookSettings {\n signingSecret: String\n deliveryRetentionDays: Int\n }\n\n type WebhookSettingsResponse {\n data: WebhookSettings\n error: WebhookError\n }\n\n input UpdateWebhookSettingsInput {\n signingSecret: String\n deliveryRetentionDays: Int\n }\n\n extend type WebhookQuery {\n getSettings: WebhookSettingsResponse\n }\n\n extend type WebhookMutation {\n updateSettings(input: UpdateWebhookSettingsInput!): WebhookSettingsResponse\n }\n `);\n\n builder.addResolver({\n path: \"WebhookQuery.getSettings\",\n dependencies: [GetWebhookSettingsUseCase],\n resolver: (getSettings: GetWebhookSettingsUseCase.Interface) => {\n return async () => {\n const result = await getSettings.execute();\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IUpdateWebhookSettingsArgs>({\n path: \"WebhookMutation.updateSettings\",\n dependencies: [UpdateWebhookSettingsUseCase],\n resolver: (updateSettings: UpdateWebhookSettingsUseCase.Interface) => {\n return async ({ args }) => {\n const result = await updateSettings.execute(args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebhookSettingsSchema = GraphQLSchemaFactory.createImplementation({\n implementation: WebhookSettingsSchema_,\n dependencies: []\n});\n"],"names":["WebhookSettingsSchema_","builder","GetWebhookSettingsUseCase","getSettings","result","ErrorResponse","Response","UpdateWebhookSettingsUseCase","updateSettings","args","WebhookSettingsSchema","GraphQLSchemaFactory"],"mappings":";;;;AAWA,MAAMA;IACF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;QAuBnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc;gBAACC;aAA0B;YACzC,UAAU,CAACC,cACA;oBACH,MAAMC,SAAS,MAAMD,YAAY,OAAO;oBACxC,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;oBAEzC,OAAO,IAAIE,SAASF,OAAO,KAAK;gBACpC;QAER;QAEAH,QAAQ,WAAW,CAA6B;YAC5C,MAAM;YACN,cAAc;gBAACM;aAA6B;YAC5C,UAAU,CAACC,iBACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAML,SAAS,MAAMI,eAAe,OAAO,CAACC,KAAK,KAAK;oBACtD,IAAIL,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;oBAEzC,OAAO,IAAIE,SAASF,OAAO,KAAK;gBACpC;QAER;QAEA,OAAOH;IACX;AACJ;AAEO,MAAMS,wBAAwBC,qBAAqB,oBAAoB,CAAC;IAC3E,gBAAgBX;IAChB,cAAc,EAAE;AACpB"}
@@ -1,9 +1,35 @@
1
+ const isLocalDevelopment = ()=>"1" === process.env.WEBINY_WATCH_LOCAL_INVOCATION;
2
+ const isLocalhostName = (hostname)=>"localhost" === hostname || hostname.endsWith(".localhost");
3
+ const isLoopbackOrLinkLocal = (hostname)=>{
4
+ const host = hostname.replace(/^\[|\]$/g, "").replace(/\.+$/, "").toLowerCase();
5
+ if (isLocalhostName(host)) return true;
6
+ if (host.includes(":")) {
7
+ if ("::1" === host || "::" === host) return true;
8
+ if (/^fe[89ab][0-9a-f]:/.test(host)) return true;
9
+ const dotted = host.match(/^::(?:ffff:(?:0:)?)?(\d+\.\d+\.\d+\.\d+)$/);
10
+ if (dotted) return isLoopbackOrLinkLocal(dotted[1]);
11
+ const hex = host.match(/^::(?:ffff:(?:0:)?)?([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);
12
+ if (hex) {
13
+ const high = parseInt(hex[1], 16);
14
+ const low = parseInt(hex[2], 16);
15
+ return isLoopbackOrLinkLocal(`${high >> 8}.${255 & high}.${low >> 8}.${255 & low}`);
16
+ }
17
+ return false;
18
+ }
19
+ const ipv4 = host.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
20
+ if (!ipv4) return false;
21
+ const [a, b] = [
22
+ Number(ipv4[1]),
23
+ Number(ipv4[2])
24
+ ];
25
+ return 0 === a || 127 === a || 169 === a && 254 === b;
26
+ };
1
27
  const isValidEndpointUrl = (url)=>{
2
28
  try {
3
29
  const parsed = new URL(url);
4
- if ("https:" === parsed.protocol) return true;
5
- else if ("http:" === parsed.protocol && ("localhost" === parsed.hostname || "127.0.0.1" === parsed.hostname)) return true;
6
- return false;
30
+ const isLocalTarget = isLoopbackOrLinkLocal(parsed.hostname);
31
+ if (isLocalTarget) return isLocalDevelopment() && (isLocalhostName(parsed.hostname) || "127.0.0.1" === parsed.hostname);
32
+ return "https:" === parsed.protocol;
7
33
  } catch {
8
34
  return false;
9
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api/utils/isValidEndpointUrl.js","sources":["../../../src/api/utils/isValidEndpointUrl.ts"],"sourcesContent":["export const isValidEndpointUrl = (url: string): boolean => {\n try {\n const parsed = new URL(url);\n if (parsed.protocol === \"https:\") {\n return true;\n } else if (\n parsed.protocol === \"http:\" &&\n (parsed.hostname === \"localhost\" || parsed.hostname === \"127.0.0.1\")\n ) {\n return true;\n }\n return false;\n } catch {\n return false;\n }\n};\n"],"names":["isValidEndpointUrl","url","parsed","URL"],"mappings":"AAAO,MAAMA,qBAAqB,CAACC;IAC/B,IAAI;QACA,MAAMC,SAAS,IAAIC,IAAIF;QACvB,IAAIC,AAAoB,aAApBA,OAAO,QAAQ,EACf,OAAO;aACJ,IACHA,AAAoB,YAApBA,OAAO,QAAQ,IACdA,CAAAA,AAAoB,gBAApBA,OAAO,QAAQ,IAAoBA,AAAoB,gBAApBA,OAAO,QAAQ,AAAe,GAElE,OAAO;QAEX,OAAO;IACX,EAAE,OAAM;QACJ,OAAO;IACX;AACJ"}
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). 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,C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SIGNING_SECRET_PREFIX = "whsec_";
2
+ export declare const INVALID_SIGNING_SECRET_MESSAGE = "A signing secret starting with \"whsec_\" must be followed by base64-encoded data.";
3
+ /**
4
+ * Plain-text secrets are base64-encoded before signing, so any value is valid. A "whsec_" secret is
5
+ * passed to standardwebhooks as is, so the rest must be valid base64. An empty value is valid: it
6
+ * means "no secret".
7
+ */
8
+ export declare const isValidSigningSecret: (secret: string | undefined | null) => boolean;
@@ -0,0 +1,11 @@
1
+ const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
2
+ const SIGNING_SECRET_PREFIX = "whsec_";
3
+ const INVALID_SIGNING_SECRET_MESSAGE = `A signing secret starting with "${SIGNING_SECRET_PREFIX}" must be followed by base64-encoded data.`;
4
+ const isValidSigningSecret = (secret)=>{
5
+ if (!secret || !secret.startsWith(SIGNING_SECRET_PREFIX)) return true;
6
+ const encoded = secret.slice(SIGNING_SECRET_PREFIX.length);
7
+ return encoded.length > 0 && encoded.length % 4 === 0 && BASE64.test(encoded);
8
+ };
9
+ export { INVALID_SIGNING_SECRET_MESSAGE, SIGNING_SECRET_PREFIX, isValidSigningSecret };
10
+
11
+ //# sourceMappingURL=isValidSigningSecret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api/utils/isValidSigningSecret.js","sources":["../../../src/api/utils/isValidSigningSecret.ts"],"sourcesContent":["const BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;\n\nexport const SIGNING_SECRET_PREFIX = \"whsec_\";\n\nexport const INVALID_SIGNING_SECRET_MESSAGE = `A signing secret starting with \"${SIGNING_SECRET_PREFIX}\" must be followed by base64-encoded data.`;\n\n/**\n * Plain-text secrets are base64-encoded before signing, so any value is valid. A \"whsec_\" secret is\n * passed to standardwebhooks as is, so the rest must be valid base64. An empty value is valid: it\n * means \"no secret\".\n */\nexport const isValidSigningSecret = (secret: string | undefined | null): boolean => {\n if (!secret || !secret.startsWith(SIGNING_SECRET_PREFIX)) {\n return true;\n }\n const encoded = secret.slice(SIGNING_SECRET_PREFIX.length);\n return encoded.length > 0 && encoded.length % 4 === 0 && BASE64.test(encoded);\n};\n"],"names":["BASE64","SIGNING_SECRET_PREFIX","INVALID_SIGNING_SECRET_MESSAGE","isValidSigningSecret","secret","encoded"],"mappings":"AAAA,MAAMA,SAAS;AAER,MAAMC,wBAAwB;AAE9B,MAAMC,iCAAiC,CAAC,gCAAgC,EAAED,sBAAsB,0CAA0C,CAAC;AAO3I,MAAME,uBAAuB,CAACC;IACjC,IAAI,CAACA,UAAU,CAACA,OAAO,UAAU,CAACH,wBAC9B,OAAO;IAEX,MAAMI,UAAUD,OAAO,KAAK,CAACH,sBAAsB,MAAM;IACzD,OAAOI,QAAQ,MAAM,GAAG,KAAKA,QAAQ,MAAM,GAAG,MAAM,KAAKL,OAAO,IAAI,CAACK;AACzE"}