@webiny/webhooks 0.0.0-unstable.33e4fd9647 → 0.0.0-unstable.48a4e5b6c1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Webhooks.d.ts +6 -0
- package/Webhooks.js +11 -0
- package/Webhooks.js.map +1 -0
- package/admin/Extension.d.ts +1 -0
- package/admin/Extension.js +1 -0
- package/admin/WebhookRoutes.js +1 -1
- package/admin/WebhookRoutes.js.map +1 -1
- package/admin/Webhooks.js +1 -1
- package/admin/Webhooks.js.map +1 -1
- package/admin/presentation/WebhookDeliveriesPage/WebhookDeliveriesPagePresenter.d.ts +8 -0
- package/admin/presentation/WebhookDeliveriesPage/WebhookDeliveriesPagePresenter.js +64 -25
- package/admin/presentation/WebhookDeliveriesPage/WebhookDeliveriesPagePresenter.js.map +1 -1
- package/admin/presentation/WebhookDeliveriesPage/WebhookDeliveriesPagePresenter.test.d.ts +1 -0
- package/admin/presentation/WebhookDeliveriesPage/WebhookDeliveriesPagePresenter.test.js +119 -0
- package/admin/presentation/WebhookDeliveriesPage/WebhookDeliveriesPagePresenter.test.js.map +1 -0
- package/admin/presentation/WebhookDeliveriesPage/abstractions.d.ts +2 -0
- package/admin/presentation/WebhookDeliveriesPage/abstractions.js.map +1 -1
- package/admin/presentation/WebhookDeliveriesPage/components/DeliveryBottomInfoBar.js.map +1 -1
- package/admin/presentation/WebhookDeliveriesPage/components/WebhookDeliveriesPage.js +1 -0
- package/admin/presentation/WebhookDeliveriesPage/components/WebhookDeliveriesPage.js.map +1 -1
- package/admin/presentation/WebhookList/WebhookListPresenter.d.ts +1 -0
- package/admin/presentation/WebhookList/WebhookListPresenter.js +12 -1
- package/admin/presentation/WebhookList/WebhookListPresenter.js.map +1 -1
- package/admin/presentation/WebhookList/abstractions.d.ts +2 -0
- package/admin/presentation/WebhookList/abstractions.js.map +1 -1
- package/admin/presentation/WebhookList/components/WebhookListView.js +1 -0
- package/admin/presentation/WebhookList/components/WebhookListView.js.map +1 -1
- package/api/domain/errors.d.ts +12 -0
- package/api/domain/errors.js +12 -1
- package/api/domain/errors.js.map +1 -1
- package/api/features/CreateWebhook/schema.js +1 -1
- package/api/features/CreateWebhook/schema.js.map +1 -1
- package/api/features/GetWebhookSettings/GetWebhookSettingsUseCase.d.ts +14 -0
- package/api/features/GetWebhookSettings/GetWebhookSettingsUseCase.js +24 -0
- package/api/features/GetWebhookSettings/GetWebhookSettingsUseCase.js.map +1 -0
- package/api/features/GetWebhookSettings/abstractions.d.ts +14 -1
- package/api/features/GetWebhookSettings/abstractions.js +2 -1
- package/api/features/GetWebhookSettings/abstractions.js.map +1 -1
- package/api/features/GetWebhookSettings/feature.js +2 -0
- package/api/features/GetWebhookSettings/feature.js.map +1 -1
- package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.d.ts +3 -1
- package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js +18 -5
- package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js.map +1 -1
- package/api/features/ResendWebhookDelivery/abstractions.d.ts +2 -1
- package/api/features/ResendWebhookDelivery/abstractions.js.map +1 -1
- package/api/features/SendWebhookTask/SendWebhookTask.js +15 -1
- package/api/features/SendWebhookTask/SendWebhookTask.js.map +1 -1
- package/api/features/TriggerWebhook/TriggerWebhookUseCase.d.ts +3 -1
- package/api/features/TriggerWebhook/TriggerWebhookUseCase.js +18 -5
- package/api/features/TriggerWebhook/TriggerWebhookUseCase.js.map +1 -1
- package/api/features/TriggerWebhook/abstractions.d.ts +2 -1
- package/api/features/TriggerWebhook/abstractions.js.map +1 -1
- package/api/features/UpdateWebhook/schema.js +1 -1
- package/api/features/UpdateWebhook/schema.js.map +1 -1
- package/api/features/WebhookDeliver/WebhookDeliver.js +1 -0
- package/api/features/WebhookDeliver/WebhookDeliver.js.map +1 -1
- package/api/features/WebhookDispatcher/WebhookDispatcher.d.ts +5 -1
- package/api/features/WebhookDispatcher/WebhookDispatcher.js +25 -4
- package/api/features/WebhookDispatcher/WebhookDispatcher.js.map +1 -1
- package/api/graphql/WebhookCrudSchema.js +21 -6
- package/api/graphql/WebhookCrudSchema.js.map +1 -1
- package/api/graphql/WebhookSettingsSchema.js +2 -2
- package/api/graphql/WebhookSettingsSchema.js.map +1 -1
- package/api/utils/isValidEndpointUrl.js +29 -3
- package/api/utils/isValidEndpointUrl.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +28 -26
|
@@ -4,17 +4,19 @@ 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 { UpdateWebhookDeliveryRepository } from "../UpdateWebhookDelivery/abstractions.js";
|
|
7
8
|
import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.js";
|
|
8
9
|
import { WebhookPermissions } from "../WebhookPermissions/abstractions.js";
|
|
9
|
-
import { WebhookNotAuthorizedError, WebhookValidationError } from "../../domain/errors.js";
|
|
10
|
+
import { WebhookDeliveryNotQueuedError, WebhookNotAuthorizedError, WebhookValidationError } from "../../domain/errors.js";
|
|
10
11
|
import { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from "../../domain/constants.js";
|
|
11
12
|
class TriggerWebhookUseCaseImpl {
|
|
12
|
-
constructor(permissions, getWebhookRepository, createDeliveryRepository, taskService, getSettingsRepository){
|
|
13
|
+
constructor(permissions, getWebhookRepository, createDeliveryRepository, taskService, getSettingsRepository, updateDeliveryRepository){
|
|
13
14
|
this.permissions = permissions;
|
|
14
15
|
this.getWebhookRepository = getWebhookRepository;
|
|
15
16
|
this.createDeliveryRepository = createDeliveryRepository;
|
|
16
17
|
this.taskService = taskService;
|
|
17
18
|
this.getSettingsRepository = getSettingsRepository;
|
|
19
|
+
this.updateDeliveryRepository = updateDeliveryRepository;
|
|
18
20
|
}
|
|
19
21
|
async execute(webhookId, payload) {
|
|
20
22
|
if (!await this.permissions.canEdit("webhook")) return Result.fail(new WebhookNotAuthorizedError());
|
|
@@ -28,7 +30,7 @@ class TriggerWebhookUseCaseImpl {
|
|
|
28
30
|
const webhook = webhookResult.value;
|
|
29
31
|
const settingsResult = await this.getSettingsRepository.execute();
|
|
30
32
|
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 *
|
|
33
|
+
const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
|
|
32
34
|
const deliveryResult = await this.createDeliveryRepository.execute({
|
|
33
35
|
webhookId: webhook.id,
|
|
34
36
|
eventType: "webhook.test",
|
|
@@ -38,7 +40,7 @@ class TriggerWebhookUseCaseImpl {
|
|
|
38
40
|
});
|
|
39
41
|
if (deliveryResult.isFail()) return Result.fail(deliveryResult.error);
|
|
40
42
|
const delivery = deliveryResult.value;
|
|
41
|
-
await this.taskService.trigger({
|
|
43
|
+
const triggered = await this.taskService.trigger({
|
|
42
44
|
definition: SEND_WEBHOOK_TASK,
|
|
43
45
|
name: `Test webhook: ${webhook.slug}`,
|
|
44
46
|
input: {
|
|
@@ -47,6 +49,16 @@ class TriggerWebhookUseCaseImpl {
|
|
|
47
49
|
deliveryId: delivery.id
|
|
48
50
|
}
|
|
49
51
|
});
|
|
52
|
+
if (triggered.isFail()) {
|
|
53
|
+
const marked = await this.updateDeliveryRepository.execute(delivery.id, {
|
|
54
|
+
status: "failed"
|
|
55
|
+
});
|
|
56
|
+
return Result.fail(new WebhookDeliveryNotQueuedError({
|
|
57
|
+
message: triggered.error.message,
|
|
58
|
+
deliveryId: delivery.id,
|
|
59
|
+
markedFailed: marked.isOk()
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
50
62
|
return Result.ok(delivery);
|
|
51
63
|
}
|
|
52
64
|
}
|
|
@@ -57,7 +69,8 @@ const TriggerWebhookUseCase_TriggerWebhookUseCase = TriggerWebhookUseCase.create
|
|
|
57
69
|
GetWebhookRepository,
|
|
58
70
|
CreateWebhookDeliveryRepository,
|
|
59
71
|
TaskService,
|
|
60
|
-
GetWebhookSettingsRepository
|
|
72
|
+
GetWebhookSettingsRepository,
|
|
73
|
+
UpdateWebhookDeliveryRepository
|
|
61
74
|
]
|
|
62
75
|
});
|
|
63
76
|
export { TriggerWebhookUseCase_TriggerWebhookUseCase as TriggerWebhookUseCase };
|
|
@@ -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":"
|
|
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 { UpdateWebhookDeliveryRepository } from \"~/api/features/UpdateWebhookDelivery/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 { WebhookDeliveryNotQueuedError } 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 private readonly updateDeliveryRepository: UpdateWebhookDeliveryRepository.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 const triggered = 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 if (triggered.isFail()) {\n // Nothing will send this delivery, so it must not stay pending.\n const marked = await this.updateDeliveryRepository.execute(delivery.id, {\n status: \"failed\"\n });\n return Result.fail(\n new WebhookDeliveryNotQueuedError({\n message: triggered.error.message,\n deliveryId: delivery.id,\n markedFailed: marked.isOk()\n })\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 UpdateWebhookDeliveryRepository\n ]\n});\n"],"names":["TriggerWebhookUseCaseImpl","permissions","getWebhookRepository","createDeliveryRepository","taskService","getSettingsRepository","updateDeliveryRepository","webhookId","payload","Result","WebhookNotAuthorizedError","parsed","TriggerWebhookInputSchema","WebhookValidationError","webhookResult","webhook","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","deliveryResult","delivery","triggered","SEND_WEBHOOK_TASK","marked","WebhookDeliveryNotQueuedError","TriggerWebhookUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookRepository","CreateWebhookDeliveryRepository","TaskService","GetWebhookSettingsRepository","UpdateWebhookDeliveryRepository"],"mappings":";;;;;;;;;;;AAeA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,oBAAoD,EACpDC,wBAAmE,EACnEC,WAAkC,EAClCC,qBAA6D,EAC7DC,wBAAmE,CACtF;aANmBL,WAAW,GAAXA;aACAC,oBAAoB,GAApBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;aACAC,wBAAwB,GAAxBA;IAClB;IAEH,MAAM,QACFC,SAAiB,EACjBC,OAAgC,EAC0B;QAC1D,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,0BAA0B,SAAS,CAAC;YAAEL;YAAWC;QAAQ;QACxE,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAMG,gBAAgB,MAAM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E,gBAAgB5B;IAChB,cAAc;QACV6B;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type Result } from "@webiny/feature/api";
|
|
2
2
|
import type { WebhookDelivery } from "../../../api/domain/WebhookDelivery.js";
|
|
3
3
|
import type { WebhookNotFoundError, WebhookPersistenceError, WebhookModelNotFoundError, WebhookNotAuthorizedError, WebhookValidationError } from "../../../api/domain/errors.js";
|
|
4
|
-
type
|
|
4
|
+
import type { WebhookDeliveryNotQueuedError } from "../../../api/domain/errors.js";
|
|
5
|
+
type IError = WebhookNotFoundError | WebhookPersistenceError | WebhookModelNotFoundError | WebhookNotAuthorizedError | WebhookValidationError | WebhookDeliveryNotQueuedError;
|
|
5
6
|
export interface ITriggerWebhookUseCase {
|
|
6
7
|
execute(webhookId: string, payload: Record<string, unknown>): Promise<Result<WebhookDelivery, IError>>;
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/TriggerWebhook/abstractions.js","sources":["../../../../src/api/features/TriggerWebhook/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { WebhookDelivery } from \"~/api/domain/WebhookDelivery.js\";\nimport type {\n WebhookNotFoundError,\n WebhookPersistenceError,\n WebhookModelNotFoundError,\n WebhookNotAuthorizedError,\n WebhookValidationError\n} from \"~/api/domain/errors.js\";\n\ntype IError =\n | WebhookNotFoundError\n | WebhookPersistenceError\n | WebhookModelNotFoundError\n | WebhookNotAuthorizedError\n | WebhookValidationError;\n\nexport interface ITriggerWebhookUseCase {\n execute(\n webhookId: string,\n payload: Record<string, unknown>\n ): Promise<Result<WebhookDelivery, IError>>;\n}\n\nexport const TriggerWebhookUseCase = createAbstraction<ITriggerWebhookUseCase>(\n \"Webhooks/TriggerWebhookUseCase\"\n);\n\nexport namespace TriggerWebhookUseCase {\n export type Interface = ITriggerWebhookUseCase;\n export type Error = IError;\n}\n"],"names":["TriggerWebhookUseCase","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"api/features/TriggerWebhook/abstractions.js","sources":["../../../../src/api/features/TriggerWebhook/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { WebhookDelivery } from \"~/api/domain/WebhookDelivery.js\";\nimport type {\n WebhookNotFoundError,\n WebhookPersistenceError,\n WebhookModelNotFoundError,\n WebhookNotAuthorizedError,\n WebhookValidationError\n} from \"~/api/domain/errors.js\";\nimport type { WebhookDeliveryNotQueuedError } from \"~/api/domain/errors.js\";\n\ntype IError =\n | WebhookNotFoundError\n | WebhookPersistenceError\n | WebhookModelNotFoundError\n | WebhookNotAuthorizedError\n | WebhookValidationError\n | WebhookDeliveryNotQueuedError;\n\nexport interface ITriggerWebhookUseCase {\n execute(\n webhookId: string,\n payload: Record<string, unknown>\n ): Promise<Result<WebhookDelivery, IError>>;\n}\n\nexport const TriggerWebhookUseCase = createAbstraction<ITriggerWebhookUseCase>(\n \"Webhooks/TriggerWebhookUseCase\"\n);\n\nexport namespace TriggerWebhookUseCase {\n export type Interface = ITriggerWebhookUseCase;\n export type Error = IError;\n}\n"],"names":["TriggerWebhookUseCase","createAbstraction"],"mappings":";AA0BO,MAAMA,wBAAwBC,kBACjC"}
|
|
@@ -3,7 +3,7 @@ import { isValidEndpointUrl } from "../../utils/isValidEndpointUrl.js";
|
|
|
3
3
|
const UpdateWebhookInputSchema = z.object({
|
|
4
4
|
name: z.string().min(1, "Name must not be empty.").optional(),
|
|
5
5
|
endpointUrl: z.string().refine(isValidEndpointUrl, {
|
|
6
|
-
message: "Endpoint URL must use HTTPS
|
|
6
|
+
message: "Endpoint URL must use HTTPS and must not point to a local or link-local address."
|
|
7
7
|
}).optional(),
|
|
8
8
|
description: z.string().optional(),
|
|
9
9
|
enabled: z.boolean().optional(),
|
|
@@ -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
|
|
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:\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.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,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,EAAE,MAAM,GAAG,QAAQ;AACtC"}
|
|
@@ -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,WAAW,MAAMC,MAAMR,MAAM,GAAG,EAAE;gBACpC,QAAQ;gBACR,SAASA,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;
|
|
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,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,WAAW,MAAMC,MAAMR,MAAM,GAAG,EAAE;gBACpC,QAAQ;gBACR,SAASA,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;gBAKhB,UAAU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ACJ;AAEO,MAAMI,gCAAiBC,eAAAA,oBAAgC,CAAC;IAC3D,gBAAgB7B;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { WebhookDispatcher as WebhookDispatcherAbstraction, WebhookProvider } from "@webiny/api-core/features/webhooks/index.js";
|
|
2
2
|
import { TaskService } from "@webiny/api-core/exports/api/tasks.js";
|
|
3
|
+
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
3
4
|
import { ListWebhooksRepository } from "../../../api/features/ListWebhooks/abstractions.js";
|
|
4
5
|
import { CreateWebhookDeliveryRepository } from "../../../api/features/CreateWebhookDelivery/abstractions.js";
|
|
6
|
+
import { UpdateWebhookDeliveryRepository } from "../../../api/features/UpdateWebhookDelivery/abstractions.js";
|
|
5
7
|
import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions.js";
|
|
6
8
|
import type { IWebhookDispatcherData } from "@webiny/api-core/features/webhooks/WebhookDispatcher/abstractions.js";
|
|
7
9
|
declare class WebhookDispatcherImpl implements WebhookDispatcherAbstraction.Interface {
|
|
@@ -10,7 +12,9 @@ declare class WebhookDispatcherImpl implements WebhookDispatcherAbstraction.Inte
|
|
|
10
12
|
private readonly taskService;
|
|
11
13
|
private readonly provider;
|
|
12
14
|
private readonly getSettingsRepository;
|
|
13
|
-
|
|
15
|
+
private readonly updateDeliveryRepository;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
constructor(listWebhooksRepository: ListWebhooksRepository.Interface, createDeliveryRepository: CreateWebhookDeliveryRepository.Interface, taskService: TaskService.Interface, provider: WebhookProvider.Interface, getSettingsRepository: GetWebhookSettingsRepository.Interface, updateDeliveryRepository: UpdateWebhookDeliveryRepository.Interface, logger: Logger.Interface);
|
|
14
18
|
dispatch<T extends IWebhookDispatcherData = IWebhookDispatcherData>(eventName: string, payload: T): Promise<void>;
|
|
15
19
|
}
|
|
16
20
|
export declare const WebhookDispatcher: typeof WebhookDispatcherImpl & {
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { WebhookDispatcher, WebhookProvider } from "@webiny/api-core/features/webhooks/index.js";
|
|
2
2
|
import { TaskService } from "@webiny/api-core/exports/api/tasks.js";
|
|
3
|
+
import { Logger } from "@webiny/api-core/features/logger/index.js";
|
|
3
4
|
import { ListWebhooksRepository } from "../ListWebhooks/abstractions.js";
|
|
4
5
|
import { CreateWebhookDeliveryRepository } from "../CreateWebhookDelivery/abstractions.js";
|
|
6
|
+
import { UpdateWebhookDeliveryRepository } from "../UpdateWebhookDelivery/abstractions.js";
|
|
5
7
|
import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.js";
|
|
6
8
|
import { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from "../../domain/constants.js";
|
|
7
9
|
class WebhookDispatcherImpl {
|
|
8
|
-
constructor(listWebhooksRepository, createDeliveryRepository, taskService, provider, getSettingsRepository){
|
|
10
|
+
constructor(listWebhooksRepository, createDeliveryRepository, taskService, provider, getSettingsRepository, updateDeliveryRepository, logger){
|
|
9
11
|
this.listWebhooksRepository = listWebhooksRepository;
|
|
10
12
|
this.createDeliveryRepository = createDeliveryRepository;
|
|
11
13
|
this.taskService = taskService;
|
|
12
14
|
this.provider = provider;
|
|
13
15
|
this.getSettingsRepository = getSettingsRepository;
|
|
16
|
+
this.updateDeliveryRepository = updateDeliveryRepository;
|
|
17
|
+
this.logger = logger;
|
|
14
18
|
}
|
|
15
19
|
async dispatch(eventName, payload) {
|
|
16
20
|
const events = await this.provider.execute();
|
|
@@ -25,7 +29,7 @@ class WebhookDispatcherImpl {
|
|
|
25
29
|
if (result.isFail()) return;
|
|
26
30
|
const settingsResult = await this.getSettingsRepository.execute();
|
|
27
31
|
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 *
|
|
32
|
+
const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
|
|
29
33
|
for (const webhook of result.value.items){
|
|
30
34
|
const deliveryResult = await this.createDeliveryRepository.execute({
|
|
31
35
|
webhookId: webhook.id,
|
|
@@ -34,7 +38,8 @@ class WebhookDispatcherImpl {
|
|
|
34
38
|
expiresAt,
|
|
35
39
|
payload
|
|
36
40
|
});
|
|
37
|
-
if (
|
|
41
|
+
if (deliveryResult.isFail()) continue;
|
|
42
|
+
const triggered = await this.taskService.trigger({
|
|
38
43
|
definition: SEND_WEBHOOK_TASK,
|
|
39
44
|
name: `Webhook: ${webhook.slug} — ${event.eventName}`,
|
|
40
45
|
input: {
|
|
@@ -43,6 +48,20 @@ class WebhookDispatcherImpl {
|
|
|
43
48
|
deliveryId: deliveryResult.value.id
|
|
44
49
|
}
|
|
45
50
|
});
|
|
51
|
+
if (triggered.isFail()) {
|
|
52
|
+
this.logger.error({
|
|
53
|
+
error: triggered.error,
|
|
54
|
+
webhookId: webhook.id,
|
|
55
|
+
deliveryId: deliveryResult.value.id
|
|
56
|
+
}, "Could not queue the webhook delivery.");
|
|
57
|
+
const marked = await this.updateDeliveryRepository.execute(deliveryResult.value.id, {
|
|
58
|
+
status: "failed"
|
|
59
|
+
});
|
|
60
|
+
if (marked.isFail()) this.logger.error({
|
|
61
|
+
error: marked.error,
|
|
62
|
+
deliveryId: deliveryResult.value.id
|
|
63
|
+
}, "Could not mark the unqueued webhook delivery as failed.");
|
|
64
|
+
}
|
|
46
65
|
}
|
|
47
66
|
}
|
|
48
67
|
}
|
|
@@ -53,7 +72,9 @@ const WebhookDispatcher_WebhookDispatcher = WebhookDispatcher.createImplementati
|
|
|
53
72
|
CreateWebhookDeliveryRepository,
|
|
54
73
|
TaskService,
|
|
55
74
|
WebhookProvider,
|
|
56
|
-
GetWebhookSettingsRepository
|
|
75
|
+
GetWebhookSettingsRepository,
|
|
76
|
+
UpdateWebhookDeliveryRepository,
|
|
77
|
+
Logger
|
|
57
78
|
]
|
|
58
79
|
});
|
|
59
80
|
export { WebhookDispatcher_WebhookDispatcher as WebhookDispatcher };
|
|
@@ -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":"
|
|
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 { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { ListWebhooksRepository } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { UpdateWebhookDeliveryRepository } from \"~/api/features/UpdateWebhookDelivery/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 private readonly updateDeliveryRepository: UpdateWebhookDeliveryRepository.Interface,\n private readonly logger: Logger.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 // The event's own write has already succeeded, so a delivery that can't be queued is\n // logged and marked failed, and doesn't fail the write.\n const triggered = 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 if (triggered.isFail()) {\n this.logger.error(\n {\n error: triggered.error,\n webhookId: webhook.id,\n deliveryId: deliveryResult.value.id\n },\n \"Could not queue the webhook delivery.\"\n );\n const marked = await this.updateDeliveryRepository.execute(\n deliveryResult.value.id,\n { status: \"failed\" }\n );\n if (marked.isFail()) {\n this.logger.error(\n { error: marked.error, deliveryId: deliveryResult.value.id },\n \"Could not mark the unqueued webhook delivery as failed.\"\n );\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 UpdateWebhookDeliveryRepository,\n Logger\n ]\n});\n"],"names":["WebhookDispatcherImpl","listWebhooksRepository","createDeliveryRepository","taskService","provider","getSettingsRepository","updateDeliveryRepository","logger","eventName","payload","events","event","result","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","webhook","deliveryResult","triggered","SEND_WEBHOOK_TASK","marked","WebhookDispatcher","WebhookDispatcherAbstraction","ListWebhooksRepository","CreateWebhookDeliveryRepository","TaskService","WebhookProvider","GetWebhookSettingsRepository","UpdateWebhookDeliveryRepository","Logger"],"mappings":";;;;;;;;AAcA,MAAMA;IACF,YACqBC,sBAAwD,EACxDC,wBAAmE,EACnEC,WAAkC,EAClCC,QAAmC,EACnCC,qBAA6D,EAC7DC,wBAAmE,EACnEC,MAAwB,CAC3C;aAPmBN,sBAAsB,GAA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UAAU,MAAM,IAAI;gBACpB,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;oBACI,OAAOA,UAAU,KAAK;oBACtB,WAAWF,QAAQ,EAAE;oBACrB,YAAYC,eAAe,KAAK,CAAC,EAAE;gBACvC,GACA;gBAEJ,MAAMG,SAAS,MAAM,IAAI,CAAC,wBAAwB,CAAC,OAAO,CACtDH,eAAe,KAAK,CAAC,EAAE,EACvB;oBAAE,QAAQ;gBAAS;gBAEvB,IAAIG,OAAO,MAAM,IACb,IAAI,CAAC,MAAM,CAAC,KAAK,CACb;oBAAE,OAAOA,OAAO,KAAK;oBAAE,YAAYH,eAAe,KAAK,CAAC,EAAE;gBAAC,GAC3D;YAGZ;QACJ;IACJ;AACJ;AAEO,MAAMI,sCAAoBC,kBAAAA,oBAAiD,CAAC;IAC/E,gBAAgBxB;IAChB,cAAc;QACVyB;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -6,6 +6,17 @@ import { GetWebhookUseCase } from "../features/GetWebhook/abstractions.js";
|
|
|
6
6
|
import { CreateWebhookUseCase } from "../features/CreateWebhook/abstractions.js";
|
|
7
7
|
import { UpdateWebhookUseCase } from "../features/UpdateWebhook/abstractions.js";
|
|
8
8
|
import { DeleteWebhookUseCase } from "../features/DeleteWebhook/abstractions.js";
|
|
9
|
+
import { WebhookPermissions } from "../features/WebhookPermissions/abstractions.js";
|
|
10
|
+
const createSecretFilter = async (permissions)=>{
|
|
11
|
+
const canSeeSecret = await permissions.canEdit("webhook");
|
|
12
|
+
return (webhook)=>{
|
|
13
|
+
if (canSeeSecret) return webhook;
|
|
14
|
+
return {
|
|
15
|
+
...webhook,
|
|
16
|
+
signingSecret: null
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
9
20
|
class WebhookCrudSchema_ {
|
|
10
21
|
async execute(builder) {
|
|
11
22
|
builder.addTypeDefs(`
|
|
@@ -114,23 +125,27 @@ class WebhookCrudSchema_ {
|
|
|
114
125
|
builder.addResolver({
|
|
115
126
|
path: "WebhookQuery.listWebhooks",
|
|
116
127
|
dependencies: [
|
|
117
|
-
ListWebhooksUseCase
|
|
128
|
+
ListWebhooksUseCase,
|
|
129
|
+
WebhookPermissions
|
|
118
130
|
],
|
|
119
|
-
resolver: (listWebhooks)=>async ({ args })=>{
|
|
131
|
+
resolver: (listWebhooks, permissions)=>async ({ args })=>{
|
|
120
132
|
const result = await listWebhooks.execute(args);
|
|
121
133
|
if (result.isFail()) return new ListErrorResponse(result.error);
|
|
122
|
-
|
|
134
|
+
const filterSecret = await createSecretFilter(permissions);
|
|
135
|
+
return new ListResponse(result.value.items.map(filterSecret), result.value.meta);
|
|
123
136
|
}
|
|
124
137
|
});
|
|
125
138
|
builder.addResolver({
|
|
126
139
|
path: "WebhookQuery.getWebhook",
|
|
127
140
|
dependencies: [
|
|
128
|
-
GetWebhookUseCase
|
|
141
|
+
GetWebhookUseCase,
|
|
142
|
+
WebhookPermissions
|
|
129
143
|
],
|
|
130
|
-
resolver: (getWebhook)=>async ({ args })=>{
|
|
144
|
+
resolver: (getWebhook, permissions)=>async ({ args })=>{
|
|
131
145
|
const result = await getWebhook.execute(args.id);
|
|
132
146
|
if (result.isFail()) return new ErrorResponse(result.error);
|
|
133
|
-
|
|
147
|
+
const filterSecret = await createSecretFilter(permissions);
|
|
148
|
+
return new Response(filterSecret(result.value));
|
|
134
149
|
}
|
|
135
150
|
});
|
|
136
151
|
builder.addResolver({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/graphql/WebhookCrudSchema.js","sources":["../../../src/api/graphql/WebhookCrudSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { ErrorResponse } from \"@webiny/api-graphql\";\nimport { ListResponse } from \"@webiny/api-graphql\";\nimport { ListErrorResponse } from \"@webiny/api-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 public getSchemaKey = staticSchemaKey(\"webhooks/WebhookCrudSchema_\");\n\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 stack: String\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 enum ListWebhooksSort {\n createdOn_ASC\n createdOn_DESC\n modifiedOn_ASC\n modifiedOn_DESC\n name_ASC\n name_DESC\n }\n\n type WebhookQuery {\n listWebhooks(\n where: ListWebhooksWhereInput\n sort: [ListWebhooksSort!]\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","staticSchemaKey","WebhookCrudSchema","GraphQLSchemaFactory"],"mappings":";;;;;;;;AA0BA,MAAMA;IAGF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA4FnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc,EAAE;YAChB,UAAU,IAAM,IAAO,EAAC;QAC5B;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc,EAAE;YAChB,UAAU,IAAM,IAAO,EAAC;QAC5B;QAEAA,QAAQ,WAAW,CAAqB;YACpC,MAAM;YACN,cAAc;gBAACC;aAAoB;YACnC,UAAU,CAACC,eACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,aAAa,OAAO,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D,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAAS;gBACxB;QAER;QAEA,OAAOV;IACX;;aAtLO,YAAY,GAAGiB,gBAAgB;;AAuL1C;AAEO,MAAMC,oBAAoBC,qBAAqB,oBAAoB,CAAC;IACvE,gBAAgBpB;IAChB,cAAc,EAAE;AACpB"}
|
|
1
|
+
{"version":3,"file":"api/graphql/WebhookCrudSchema.js","sources":["../../../src/api/graphql/WebhookCrudSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { ErrorResponse } from \"@webiny/api-graphql\";\nimport { ListResponse } from \"@webiny/api-graphql\";\nimport { ListErrorResponse } from \"@webiny/api-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\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport type { Webhook } from \"~/api/domain/Webhook.js\";\n\n/**\n * Security: the signing secret is returned only to identities that can edit webhooks.\n */\nconst createSecretFilter = async (permissions: WebhookPermissions.Interface) => {\n const canSeeSecret = await permissions.canEdit(\"webhook\");\n return (webhook: Webhook) => {\n if (canSeeSecret) {\n return webhook;\n }\n return { ...webhook, signingSecret: null };\n };\n};\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 public getSchemaKey = staticSchemaKey(\"webhooks/WebhookCrudSchema_\");\n\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 stack: String\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 enum ListWebhooksSort {\n createdOn_ASC\n createdOn_DESC\n modifiedOn_ASC\n modifiedOn_DESC\n name_ASC\n name_DESC\n }\n\n type WebhookQuery {\n listWebhooks(\n where: ListWebhooksWhereInput\n sort: [ListWebhooksSort!]\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, WebhookPermissions],\n resolver: (\n listWebhooks: ListWebhooksUseCase.Interface,\n permissions: WebhookPermissions.Interface\n ) => {\n return async ({ args }) => {\n const result = await listWebhooks.execute(args);\n if (result.isFail()) {\n return new ListErrorResponse(result.error);\n }\n const filterSecret = await createSecretFilter(permissions);\n return new ListResponse(\n result.value.items.map(filterSecret),\n result.value.meta\n );\n };\n }\n });\n\n builder.addResolver<IIdArgs>({\n path: \"WebhookQuery.getWebhook\",\n dependencies: [GetWebhookUseCase, WebhookPermissions],\n resolver: (\n getWebhook: GetWebhookUseCase.Interface,\n permissions: WebhookPermissions.Interface\n ) => {\n return async ({ args }) => {\n const result = await getWebhook.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n const filterSecret = await createSecretFilter(permissions);\n return new Response(filterSecret(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":["createSecretFilter","permissions","canSeeSecret","webhook","WebhookCrudSchema_","builder","ListWebhooksUseCase","WebhookPermissions","listWebhooks","args","result","ListErrorResponse","filterSecret","ListResponse","GetWebhookUseCase","getWebhook","ErrorResponse","Response","CreateWebhookUseCase","createWebhook","UpdateWebhookUseCase","updateWebhook","DeleteWebhookUseCase","deleteWebhook","staticSchemaKey","WebhookCrudSchema","GraphQLSchemaFactory"],"mappings":";;;;;;;;;AAkBA,MAAMA,qBAAqB,OAAOC;IAC9B,MAAMC,eAAe,MAAMD,YAAY,OAAO,CAAC;IAC/C,OAAO,CAACE;QACJ,IAAID,cACA,OAAOC;QAEX,OAAO;YAAE,GAAGA,OAAO;YAAE,eAAe;QAAK;IAC7C;AACJ;AAeA,MAAMC;IAGF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA4FnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc,EAAE;YAChB,UAAU,IAAM,IAAO,EAAC;QAC5B;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc,EAAE;YAChB,UAAU,IAAM,IAAO,EAAC;QAC5B;QAEAA,QAAQ,WAAW,CAAqB;YACpC,MAAM;YACN,cAAc;gBAACC;gBAAqBC;aAAmB;YACvD,UAAU,CACNC,cACAP,cAEO,OAAO,EAAEQ,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,aAAa,OAAO,CAACC;o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B;YACpC,UAAU,CAACC,gBACA,OAAO,EAAEd,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMa,cAAc,OAAO,CAACd,KAAK,EAAE;oBAClD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIM,cAAcN,OAAO,KAAK;oBAEzC,OAAO,IAAIO,SAAS;gBACxB;QAER;QAEA,OAAOZ;IACX;;aAjMO,YAAY,GAAGmB,gBAAgB;;AAkM1C;AAEO,MAAMC,oBAAoBC,qBAAqB,oBAAoB,CAAC;IACvE,gBAAgBtB;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.js";
|
|
2
2
|
import { staticSchemaKey } from "@webiny/api-graphql/graphql/staticSchemaKey.js";
|
|
3
3
|
import { ErrorResponse, Response } from "@webiny/api-graphql";
|
|
4
|
-
import {
|
|
4
|
+
import { GetWebhookSettingsUseCase } from "../features/GetWebhookSettings/abstractions.js";
|
|
5
5
|
import { UpdateWebhookSettingsUseCase } from "../features/UpdateWebhookSettings/abstractions.js";
|
|
6
6
|
class WebhookSettingsSchema_ {
|
|
7
7
|
async execute(builder) {
|
|
@@ -32,7 +32,7 @@ class WebhookSettingsSchema_ {
|
|
|
32
32
|
builder.addResolver({
|
|
33
33
|
path: "WebhookQuery.getSettings",
|
|
34
34
|
dependencies: [
|
|
35
|
-
|
|
35
|
+
GetWebhookSettingsUseCase
|
|
36
36
|
],
|
|
37
37
|
resolver: (getSettings)=>async ()=>{
|
|
38
38
|
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/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { ErrorResponse } from \"@webiny/api-graphql\";\nimport {
|
|
1
|
+
{"version":3,"file":"api/graphql/WebhookSettingsSchema.js","sources":["../../../src/api/graphql/WebhookSettingsSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { Response } from \"@webiny/api-graphql\";\nimport { ErrorResponse } from \"@webiny/api-graphql\";\nimport { GetWebhookSettingsUseCase } 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 public getSchemaKey = staticSchemaKey(\"webhooks/WebhookSettingsSchema_\");\n\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","staticSchemaKey","WebhookSettingsSchema","GraphQLSchemaFactory"],"mappings":";;;;;AAYA,MAAMA;IAGF,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;;aA3DO,YAAY,GAAGS,gBAAgB;;AA4D1C;AAEO,MAAMC,wBAAwBC,qBAAqB,oBAAoB,CAAC;IAC3E,gBAAgBZ;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
|
-
|
|
5
|
-
if (
|
|
6
|
-
return
|
|
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":["
|
|
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,CAAC,YAAY,IACpB,OAAO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+
export { Webhooks } from "./Webhooks.js";
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Webhooks } from "./Webhooks.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/webhooks",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.48a4e5b6c1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -19,36 +19,38 @@
|
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@webiny/admin-ui": "0.0.0-unstable.
|
|
23
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
24
|
-
"@webiny/api-graphql": "0.0.0-unstable.
|
|
25
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
26
|
-
"@webiny/app": "0.0.0-unstable.
|
|
27
|
-
"@webiny/app-admin": "0.0.0-unstable.
|
|
28
|
-
"@webiny/background-tasks": "0.0.0-unstable.
|
|
29
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
30
|
-
"@webiny/icons": "0.0.0-unstable.
|
|
31
|
-
"@webiny/
|
|
32
|
-
"@webiny/
|
|
33
|
-
"
|
|
22
|
+
"@webiny/admin-ui": "0.0.0-unstable.48a4e5b6c1",
|
|
23
|
+
"@webiny/api-core": "0.0.0-unstable.48a4e5b6c1",
|
|
24
|
+
"@webiny/api-graphql": "0.0.0-unstable.48a4e5b6c1",
|
|
25
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.48a4e5b6c1",
|
|
26
|
+
"@webiny/app": "0.0.0-unstable.48a4e5b6c1",
|
|
27
|
+
"@webiny/app-admin": "0.0.0-unstable.48a4e5b6c1",
|
|
28
|
+
"@webiny/background-tasks": "0.0.0-unstable.48a4e5b6c1",
|
|
29
|
+
"@webiny/feature": "0.0.0-unstable.48a4e5b6c1",
|
|
30
|
+
"@webiny/icons": "0.0.0-unstable.48a4e5b6c1",
|
|
31
|
+
"@webiny/project": "0.0.0-unstable.48a4e5b6c1",
|
|
32
|
+
"@webiny/project-extensions": "0.0.0-unstable.48a4e5b6c1",
|
|
33
|
+
"@webiny/sdk": "0.0.0-unstable.48a4e5b6c1",
|
|
34
|
+
"@webiny/utils": "0.0.0-unstable.48a4e5b6c1",
|
|
35
|
+
"graphql": "16.15.0",
|
|
34
36
|
"lodash": "4.18.1",
|
|
35
|
-
"mobx": "7.
|
|
36
|
-
"mobx-react-lite": "5.
|
|
37
|
-
"react": "
|
|
38
|
-
"react-dom": "
|
|
39
|
-
"standardwebhooks": "1.
|
|
40
|
-
"zod": "4.
|
|
37
|
+
"mobx": "7.1.7",
|
|
38
|
+
"mobx-react-lite": "5.1.3",
|
|
39
|
+
"react": "19.3.1",
|
|
40
|
+
"react-dom": "19.3.1",
|
|
41
|
+
"standardwebhooks": "1.3.0",
|
|
42
|
+
"zod": "4.6.7"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@webiny/api": "0.0.0-unstable.
|
|
44
|
-
"@webiny/api-core-testing": "0.0.0-unstable.
|
|
45
|
-
"@webiny/
|
|
45
|
+
"@webiny/api": "0.0.0-unstable.48a4e5b6c1",
|
|
46
|
+
"@webiny/api-core-testing": "0.0.0-unstable.48a4e5b6c1",
|
|
47
|
+
"@webiny/api-kernel-core": "0.0.0-unstable.48a4e5b6c1",
|
|
48
|
+
"@webiny/build-tools": "0.0.0-unstable.48a4e5b6c1",
|
|
46
49
|
"@webiny/di": "2.0.0",
|
|
47
|
-
"@webiny/
|
|
48
|
-
"@webiny/
|
|
49
|
-
"@webiny/wcp": "0.0.0-unstable.33e4fd9647",
|
|
50
|
+
"@webiny/handler": "0.0.0-unstable.48a4e5b6c1",
|
|
51
|
+
"@webiny/wcp": "0.0.0-unstable.48a4e5b6c1",
|
|
50
52
|
"typescript": "7.0.2",
|
|
51
|
-
"vitest": "
|
|
53
|
+
"vitest": "5.1.1"
|
|
52
54
|
},
|
|
53
55
|
"publishConfig": {
|
|
54
56
|
"access": "public"
|