@webiny/webhooks 6.6.0-alpha.11 → 6.6.0-alpha.13
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/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/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.js +1 -1
- package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.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.js +1 -1
- package/api/features/TriggerWebhook/TriggerWebhookUseCase.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.js +1 -1
- 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/package.json +25 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin/presentation/WebhookList/abstractions.js","sources":["../../../../src/admin/presentation/WebhookList/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { Webhook } from \"~/admin/shared/types.js\";\nimport type { IListViewModel } from \"@webiny/app-admin/presentation/listPresenter/abstractions.js\";\n\nexport interface IWebhookListViewModel {\n list: IListViewModel<Webhook>;\n permissions: {\n canRead: boolean;\n canCreate: boolean;\n canEdit: boolean;\n canDelete: boolean;\n };\n}\n\nexport interface IWebhookListPresenter {\n vm: IWebhookListViewModel;\n init(): void;\n search: { set(query: string): void; clear(): void };\n sort: { set(field: string, direction: \"ASC\" | \"DESC\"): void; toggle(field: string): void };\n filter: { set(key: string, value: unknown): void; clear(key: string): void; clearAll(): void };\n selection: {\n toggle(id: string): void;\n selectRangeTo(id: string): void;\n selectAll(): void;\n deselectAll(): void;\n selectRows(ids: string[]): void;\n isSelected(id: string): boolean;\n };\n loadMore(): Promise<void>;\n refresh(): Promise<void>;\n deleteWebhook(id: string): Promise<void>;\n triggerWebhook(id: string): Promise<void>;\n}\n\nexport const WebhookListPresenter =\n createAbstraction<IWebhookListPresenter>(\"WebhookListPresenter\");\n\nexport namespace WebhookListPresenter {\n export type Interface = IWebhookListPresenter;\n export type ViewModel = IWebhookListViewModel;\n}\n"],"names":["WebhookListPresenter","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"admin/presentation/WebhookList/abstractions.js","sources":["../../../../src/admin/presentation/WebhookList/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { Webhook } from \"~/admin/shared/types.js\";\nimport type { IListViewModel } from \"@webiny/app-admin/presentation/listPresenter/abstractions.js\";\n\nexport interface IWebhookListViewModel {\n list: IListViewModel<Webhook>;\n permissions: {\n canRead: boolean;\n canCreate: boolean;\n canEdit: boolean;\n canDelete: boolean;\n };\n}\n\nexport interface IWebhookListPresenter {\n vm: IWebhookListViewModel;\n init(): void;\n /** Stops telling the assistant about the webhooks list. */\n dispose(): void;\n search: { set(query: string): void; clear(): void };\n sort: { set(field: string, direction: \"ASC\" | \"DESC\"): void; toggle(field: string): void };\n filter: { set(key: string, value: unknown): void; clear(key: string): void; clearAll(): void };\n selection: {\n toggle(id: string): void;\n selectRangeTo(id: string): void;\n selectAll(): void;\n deselectAll(): void;\n selectRows(ids: string[]): void;\n isSelected(id: string): boolean;\n };\n loadMore(): Promise<void>;\n refresh(): Promise<void>;\n deleteWebhook(id: string): Promise<void>;\n triggerWebhook(id: string): Promise<void>;\n}\n\nexport const WebhookListPresenter =\n createAbstraction<IWebhookListPresenter>(\"WebhookListPresenter\");\n\nexport namespace WebhookListPresenter {\n export type Interface = IWebhookListPresenter;\n export type ViewModel = IWebhookListViewModel;\n}\n"],"names":["WebhookListPresenter","createAbstraction"],"mappings":";AAoCO,MAAMA,uBACTC,kBAAyC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin/presentation/WebhookList/components/WebhookListView.js","sources":["../../../../../src/admin/presentation/WebhookList/components/WebhookListView.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { DiContainerProvider, useContainer, useFeature } from \"@webiny/app\";\nimport { Heading, Separator } from \"@webiny/admin-ui\";\nimport { WebhookListPresenterFeature } from \"../feature.js\";\nimport { ListWebhooksFeature } from \"~/admin/features/ListWebhooks/feature.js\";\nimport { DeleteWebhookFeature } from \"~/admin/features/deleteWebhook/feature.js\";\nimport { TriggerWebhookFeature } from \"~/admin/features/triggerWebhook/feature.js\";\nimport { WebhookPermissionsFeature } from \"~/admin/features/permissions/feature.js\";\nimport { CreateWebhookButton } from \"./CreateWebhookButton.js\";\nimport { WebhookListContent } from \"./WebhookListContent.js\";\nimport { WebhookDeliveriesButton } from \"~/admin/presentation/WebhookList/components/WebhookDeliveriesButton.js\";\n\nconst WebhookListViewInner = observer(function WebhookListViewInner() {\n const { presenter } = useFeature(WebhookListPresenterFeature);\n\n useEffect(() => {\n presenter.init();\n }, [presenter]);\n\n return (\n <div className=\"flex flex-col h-main-content\">\n <div className=\"flex items-center justify-between py-sm px-md\">\n <Heading level={5}>Webhooks</Heading>\n <div className={\"flex gap-sm\"}>\n <WebhookDeliveriesButton />\n <CreateWebhookButton />\n </div>\n </div>\n <Separator />\n <WebhookListContent presenter={presenter} />\n </div>\n );\n});\n\nexport const WebhookListView = () => {\n const container = useContainer();\n\n const scopedContainer = useMemo(() => {\n const child = container.createChildContainer();\n ListWebhooksFeature.register(child);\n DeleteWebhookFeature.register(child);\n TriggerWebhookFeature.register(child);\n WebhookPermissionsFeature.register(child);\n WebhookListPresenterFeature.register(child);\n return child;\n }, []);\n\n return (\n <DiContainerProvider container={scopedContainer}>\n <WebhookListViewInner />\n </DiContainerProvider>\n );\n};\n"],"names":["WebhookListViewInner","observer","presenter","useFeature","WebhookListPresenterFeature","useEffect","Heading","WebhookDeliveriesButton","CreateWebhookButton","Separator","WebhookListContent","WebhookListView","container","useContainer","scopedContainer","useMemo","child","ListWebhooksFeature","DeleteWebhookFeature","TriggerWebhookFeature","WebhookPermissionsFeature","DiContainerProvider"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,uCAAuBC,SAAS;IAClC,MAAM,EAAEC,SAAS,EAAE,GAAGC,WAAWC;IAEjCC,UAAU;QACNH,UAAU,IAAI;
|
|
1
|
+
{"version":3,"file":"admin/presentation/WebhookList/components/WebhookListView.js","sources":["../../../../../src/admin/presentation/WebhookList/components/WebhookListView.tsx"],"sourcesContent":["import React, { useEffect, useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { DiContainerProvider, useContainer, useFeature } from \"@webiny/app\";\nimport { Heading, Separator } from \"@webiny/admin-ui\";\nimport { WebhookListPresenterFeature } from \"../feature.js\";\nimport { ListWebhooksFeature } from \"~/admin/features/ListWebhooks/feature.js\";\nimport { DeleteWebhookFeature } from \"~/admin/features/deleteWebhook/feature.js\";\nimport { TriggerWebhookFeature } from \"~/admin/features/triggerWebhook/feature.js\";\nimport { WebhookPermissionsFeature } from \"~/admin/features/permissions/feature.js\";\nimport { CreateWebhookButton } from \"./CreateWebhookButton.js\";\nimport { WebhookListContent } from \"./WebhookListContent.js\";\nimport { WebhookDeliveriesButton } from \"~/admin/presentation/WebhookList/components/WebhookDeliveriesButton.js\";\n\nconst WebhookListViewInner = observer(function WebhookListViewInner() {\n const { presenter } = useFeature(WebhookListPresenterFeature);\n\n useEffect(() => {\n presenter.init();\n return () => presenter.dispose();\n }, [presenter]);\n\n return (\n <div className=\"flex flex-col h-main-content\">\n <div className=\"flex items-center justify-between py-sm px-md\">\n <Heading level={5}>Webhooks</Heading>\n <div className={\"flex gap-sm\"}>\n <WebhookDeliveriesButton />\n <CreateWebhookButton />\n </div>\n </div>\n <Separator />\n <WebhookListContent presenter={presenter} />\n </div>\n );\n});\n\nexport const WebhookListView = () => {\n const container = useContainer();\n\n const scopedContainer = useMemo(() => {\n const child = container.createChildContainer();\n ListWebhooksFeature.register(child);\n DeleteWebhookFeature.register(child);\n TriggerWebhookFeature.register(child);\n WebhookPermissionsFeature.register(child);\n WebhookListPresenterFeature.register(child);\n return child;\n }, []);\n\n return (\n <DiContainerProvider container={scopedContainer}>\n <WebhookListViewInner />\n </DiContainerProvider>\n );\n};\n"],"names":["WebhookListViewInner","observer","presenter","useFeature","WebhookListPresenterFeature","useEffect","Heading","WebhookDeliveriesButton","CreateWebhookButton","Separator","WebhookListContent","WebhookListView","container","useContainer","scopedContainer","useMemo","child","ListWebhooksFeature","DeleteWebhookFeature","TriggerWebhookFeature","WebhookPermissionsFeature","DiContainerProvider"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,uCAAuBC,SAAS;IAClC,MAAM,EAAEC,SAAS,EAAE,GAAGC,WAAWC;IAEjCC,UAAU;QACNH,UAAU,IAAI;QACd,OAAO,IAAMA,UAAU,OAAO;IAClC,GAAG;QAACA;KAAU;IAEd,OAAO,WAAP,GACI,oBAAC;QAAI,WAAU;qBACX,oBAAC;QAAI,WAAU;qBACX,oBAACI,SAAOA;QAAC,OAAO;OAAG,2BACnB,oBAAC;QAAI,WAAW;qBACZ,oBAACC,yBAAuBA,OAAAA,WAAAA,GACxB,oBAACC,qBAAmBA,SAAAA,WAAAA,GAG5B,oBAACC,WAASA,OAAAA,WAAAA,GACV,oBAACC,oBAAkBA;QAAC,WAAWR;;AAG3C;AAEO,MAAMS,kBAAkB;IAC3B,MAAMC,YAAYC;IAElB,MAAMC,kBAAkBC,QAAQ;QAC5B,MAAMC,QAAQJ,UAAU,oBAAoB;QAC5CK,oBAAoB,QAAQ,CAACD;QAC7BE,qBAAqB,QAAQ,CAACF;QAC9BG,sBAAsB,QAAQ,CAACH;QAC/BI,0BAA0B,QAAQ,CAACJ;QACnCZ,4BAA4B,QAAQ,CAACY;QACrC,OAAOA;IACX,GAAG,EAAE;IAEL,OAAO,WAAP,GACI,oBAACK,qBAAmBA;QAAC,WAAWP;qBAC5B,oBAACd,sCAAoBA;AAGjC"}
|
|
@@ -4,7 +4,7 @@ const CreateWebhookInputSchema = z.object({
|
|
|
4
4
|
name: z.string().min(1, "Name is required."),
|
|
5
5
|
slug: z.string().optional(),
|
|
6
6
|
endpointUrl: z.string().refine(isValidEndpointUrl, {
|
|
7
|
-
message: "Endpoint URL must use HTTPS
|
|
7
|
+
message: "Endpoint URL must use HTTPS and must not point to a local or link-local address."
|
|
8
8
|
}),
|
|
9
9
|
description: z.string().optional(),
|
|
10
10
|
enabled: z.boolean().optional(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/CreateWebhook/schema.js","sources":["../../../../src/api/features/CreateWebhook/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.js\";\n\nexport const CreateWebhookInputSchema = z.object({\n name: z.string().min(1, \"Name is required.\"),\n slug: z.string().optional(),\n endpointUrl: z.string().refine(isValidEndpointUrl, {\n message: \"Endpoint URL must use HTTPS
|
|
1
|
+
{"version":3,"file":"api/features/CreateWebhook/schema.js","sources":["../../../../src/api/features/CreateWebhook/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.js\";\n\nexport const CreateWebhookInputSchema = z.object({\n name: z.string().min(1, \"Name is required.\"),\n slug: z.string().optional(),\n endpointUrl: z.string().refine(isValidEndpointUrl, {\n message: \"Endpoint URL must use HTTPS and must not point to a local or link-local address.\"\n }),\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.\"),\n signingSecret: z.string().optional()\n});\n"],"names":["CreateWebhookInputSchema","z","isValidEndpointUrl"],"mappings":";;AAGO,MAAMA,2BAA2BC,EAAE,MAAM,CAAC;IAC7C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG;IACxB,MAAMA,EAAE,MAAM,GAAG,QAAQ;IACzB,aAAaA,EAAE,MAAM,GAAG,MAAM,CAACC,oBAAoB;QAC/C,SAAS;IACb;IACA,aAAaD,EAAE,MAAM,GAAG,QAAQ;IAChC,SAASA,EAAE,OAAO,GAAG,QAAQ;IAC7B,QAAQA,EAAE,KAAK,CAACA,EAAE,MAAM,IAAI,GAAG,CAAC,GAAG;IACnC,eAAeA,EAAE,MAAM,GAAG,QAAQ;AACtC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { GetWebhookSettingsRepository, GetWebhookSettingsUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
3
|
+
import { WebhookPermissions } from "../../../api/features/WebhookPermissions/abstractions.js";
|
|
4
|
+
import type { IWebhookSettings } from "../../../api/domain/WebhookSettings.js";
|
|
5
|
+
declare class GetWebhookSettingsUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
+
private readonly permissions;
|
|
7
|
+
private readonly repository;
|
|
8
|
+
constructor(permissions: WebhookPermissions.Interface, repository: GetWebhookSettingsRepository.Interface);
|
|
9
|
+
execute(): Promise<Result<IWebhookSettings, UseCaseAbstraction.Error>>;
|
|
10
|
+
}
|
|
11
|
+
export declare const GetWebhookSettingsUseCase: typeof GetWebhookSettingsUseCaseImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IGetWebhookSettingsUseCase>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { GetWebhookSettingsRepository, GetWebhookSettingsUseCase } from "./abstractions.js";
|
|
3
|
+
import { WebhookPermissions } from "../WebhookPermissions/abstractions.js";
|
|
4
|
+
import { WebhookNotAuthorizedError } from "../../domain/errors.js";
|
|
5
|
+
class GetWebhookSettingsUseCaseImpl {
|
|
6
|
+
constructor(permissions, repository){
|
|
7
|
+
this.permissions = permissions;
|
|
8
|
+
this.repository = repository;
|
|
9
|
+
}
|
|
10
|
+
async execute() {
|
|
11
|
+
if (!await this.permissions.canEdit("webhook")) return Result.fail(new WebhookNotAuthorizedError());
|
|
12
|
+
return this.repository.execute();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const GetWebhookSettingsUseCase_GetWebhookSettingsUseCase = GetWebhookSettingsUseCase.createImplementation({
|
|
16
|
+
implementation: GetWebhookSettingsUseCaseImpl,
|
|
17
|
+
dependencies: [
|
|
18
|
+
WebhookPermissions,
|
|
19
|
+
GetWebhookSettingsRepository
|
|
20
|
+
]
|
|
21
|
+
});
|
|
22
|
+
export { GetWebhookSettingsUseCase_GetWebhookSettingsUseCase as GetWebhookSettingsUseCase };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=GetWebhookSettingsUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/GetWebhookSettings/GetWebhookSettingsUseCase.js","sources":["../../../../src/api/features/GetWebhookSettings/GetWebhookSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n GetWebhookSettingsRepository,\n GetWebhookSettingsUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError } from \"~/api/domain/errors.js\";\nimport type { IWebhookSettings } from \"~/api/domain/WebhookSettings.js\";\n\nclass GetWebhookSettingsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly repository: GetWebhookSettingsRepository.Interface\n ) {}\n\n async execute(): Promise<Result<IWebhookSettings, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n return this.repository.execute();\n }\n}\n\nexport const GetWebhookSettingsUseCase = UseCaseAbstraction.createImplementation({\n implementation: GetWebhookSettingsUseCaseImpl,\n dependencies: [WebhookPermissions, GetWebhookSettingsRepository]\n});\n"],"names":["GetWebhookSettingsUseCaseImpl","permissions","repository","Result","WebhookNotAuthorizedError","GetWebhookSettingsUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookSettingsRepository"],"mappings":";;;;AASA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,UAAkD,CACrE;aAFmBD,WAAW,GAAXA;aACAC,UAAU,GAAVA;IAClB;IAEH,MAAM,UAAuE;QACzE,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO;IAClC;AACJ;AAEO,MAAMC,sDAA4BC,0BAAAA,oBAAuC,CAAC;IAC7E,gBAAgBN;IAChB,cAAc;QAACO;QAAoBC;KAA6B;AACpE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Result } from "@webiny/feature/api";
|
|
2
2
|
import type { IWebhookSettings } from "../../../api/domain/WebhookSettings.js";
|
|
3
|
-
import type { WebhookModelNotFoundError, WebhookPersistenceError } from "../../../api/domain/errors.js";
|
|
3
|
+
import type { WebhookModelNotFoundError, WebhookNotAuthorizedError, WebhookPersistenceError } from "../../../api/domain/errors.js";
|
|
4
4
|
type IError = WebhookModelNotFoundError | WebhookPersistenceError;
|
|
5
5
|
export interface IGetWebhookSettingsRepository {
|
|
6
6
|
execute(): Promise<Result<IWebhookSettings, IError>>;
|
|
@@ -10,4 +10,17 @@ export declare namespace GetWebhookSettingsRepository {
|
|
|
10
10
|
type Interface = IGetWebhookSettingsRepository;
|
|
11
11
|
type Error = IError;
|
|
12
12
|
}
|
|
13
|
+
type IUseCaseError = IError | WebhookNotAuthorizedError;
|
|
14
|
+
/**
|
|
15
|
+
* Settings hold the global signing secret, so reading them needs the same permission as
|
|
16
|
+
* changing them. Internal code that signs deliveries uses the repository directly.
|
|
17
|
+
*/
|
|
18
|
+
export interface IGetWebhookSettingsUseCase {
|
|
19
|
+
execute(): Promise<Result<IWebhookSettings, IUseCaseError>>;
|
|
20
|
+
}
|
|
21
|
+
export declare const GetWebhookSettingsUseCase: import("@webiny/di").Abstraction<IGetWebhookSettingsUseCase>;
|
|
22
|
+
export declare namespace GetWebhookSettingsUseCase {
|
|
23
|
+
type Interface = IGetWebhookSettingsUseCase;
|
|
24
|
+
type Error = IUseCaseError;
|
|
25
|
+
}
|
|
13
26
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
const GetWebhookSettingsRepository = createAbstraction("Webhooks/GetWebhookSettingsRepository");
|
|
3
|
-
|
|
3
|
+
const GetWebhookSettingsUseCase = createAbstraction("Webhooks/GetWebhookSettingsUseCase");
|
|
4
|
+
export { GetWebhookSettingsRepository, GetWebhookSettingsUseCase };
|
|
4
5
|
|
|
5
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/GetWebhookSettings/abstractions.js","sources":["../../../../src/api/features/GetWebhookSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { IWebhookSettings } from \"~/api/domain/WebhookSettings.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"api/features/GetWebhookSettings/abstractions.js","sources":["../../../../src/api/features/GetWebhookSettings/abstractions.ts"],"sourcesContent":["import { createAbstraction, type Result } from \"@webiny/feature/api\";\nimport type { IWebhookSettings } from \"~/api/domain/WebhookSettings.js\";\nimport type {\n WebhookModelNotFoundError,\n WebhookNotAuthorizedError,\n WebhookPersistenceError\n} from \"~/api/domain/errors.js\";\n\ntype IError = WebhookModelNotFoundError | WebhookPersistenceError;\n\nexport interface IGetWebhookSettingsRepository {\n execute(): Promise<Result<IWebhookSettings, IError>>;\n}\n\nexport const GetWebhookSettingsRepository = createAbstraction<IGetWebhookSettingsRepository>(\n \"Webhooks/GetWebhookSettingsRepository\"\n);\n\nexport namespace GetWebhookSettingsRepository {\n export type Interface = IGetWebhookSettingsRepository;\n export type Error = IError;\n}\n\ntype IUseCaseError = IError | WebhookNotAuthorizedError;\n\n/**\n * Settings hold the global signing secret, so reading them needs the same permission as\n * changing them. Internal code that signs deliveries uses the repository directly.\n */\nexport interface IGetWebhookSettingsUseCase {\n execute(): Promise<Result<IWebhookSettings, IUseCaseError>>;\n}\n\nexport const GetWebhookSettingsUseCase = createAbstraction<IGetWebhookSettingsUseCase>(\n \"Webhooks/GetWebhookSettingsUseCase\"\n);\n\nexport namespace GetWebhookSettingsUseCase {\n export type Interface = IGetWebhookSettingsUseCase;\n export type Error = IUseCaseError;\n}\n"],"names":["GetWebhookSettingsRepository","createAbstraction","GetWebhookSettingsUseCase"],"mappings":";AAcO,MAAMA,+BAA+BC,kBACxC;AAkBG,MAAMC,4BAA4BD,kBACrC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { GetWebhookSettingsRepository } from "./GetWebhookSettingsRepository.js";
|
|
3
|
+
import { GetWebhookSettingsUseCase } from "./GetWebhookSettingsUseCase.js";
|
|
3
4
|
const GetWebhookSettingsFeature = createFeature({
|
|
4
5
|
name: "GetWebhookSettings",
|
|
5
6
|
register (container) {
|
|
7
|
+
container.register(GetWebhookSettingsUseCase);
|
|
6
8
|
container.register(GetWebhookSettingsRepository).inSingletonScope();
|
|
7
9
|
}
|
|
8
10
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/GetWebhookSettings/feature.js","sources":["../../../../src/api/features/GetWebhookSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetWebhookSettingsRepository } from \"./GetWebhookSettingsRepository.js\";\n\nexport const GetWebhookSettingsFeature = createFeature({\n name: \"GetWebhookSettings\",\n register(container) {\n container.register(GetWebhookSettingsRepository).inSingletonScope();\n }\n});\n"],"names":["GetWebhookSettingsFeature","createFeature","container","GetWebhookSettingsRepository"],"mappings":"
|
|
1
|
+
{"version":3,"file":"api/features/GetWebhookSettings/feature.js","sources":["../../../../src/api/features/GetWebhookSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GetWebhookSettingsRepository } from \"./GetWebhookSettingsRepository.js\";\nimport { GetWebhookSettingsUseCase } from \"./GetWebhookSettingsUseCase.js\";\n\nexport const GetWebhookSettingsFeature = createFeature({\n name: \"GetWebhookSettings\",\n register(container) {\n container.register(GetWebhookSettingsUseCase);\n container.register(GetWebhookSettingsRepository).inSingletonScope();\n }\n});\n"],"names":["GetWebhookSettingsFeature","createFeature","container","GetWebhookSettingsUseCase","GetWebhookSettingsRepository"],"mappings":";;;AAIO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,8BAA8B,gBAAgB;IACrE;AACJ"}
|
|
@@ -35,7 +35,7 @@ class ResendWebhookDeliveryUseCaseImpl {
|
|
|
35
35
|
const data = originalPayload?.data ?? {};
|
|
36
36
|
const settingsResult = await this.getSettingsRepository.execute();
|
|
37
37
|
const retentionDays = settingsResult.isOk() ? settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;
|
|
38
|
-
const expiresAt = new Date(Date.now() + 24 * retentionDays *
|
|
38
|
+
const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
|
|
39
39
|
const newDeliveryResult = await this.createDeliveryRepository.execute({
|
|
40
40
|
webhookId: delivery.webhookId,
|
|
41
41
|
eventType: delivery.eventType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js","sources":["../../../../src/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ResendWebhookDeliveryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { ResendWebhookDeliveryInputSchema } from \"./schema.js\";\nimport { GetWebhookDeliveryRepository } from \"~/api/features/GetWebhookDelivery/abstractions.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { 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 { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { IWebhookPayload } from \"~/api/features/SendWebhookTask/types.js\";\n\nclass ResendWebhookDeliveryUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly getDeliveryRepository: GetWebhookDeliveryRepository.Interface,\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface,\n private readonly updateDeliveryRepository: UpdateWebhookDeliveryRepository.Interface\n ) {}\n\n async execute(deliveryId: string): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = ResendWebhookDeliveryInputSchema.safeParse({ deliveryId });\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const deliveryResult = await this.getDeliveryRepository.execute(parsed.data.deliveryId);\n if (deliveryResult.isFail()) {\n return Result.fail(deliveryResult.error);\n }\n\n const delivery = deliveryResult.value;\n\n const webhookResult = await this.getWebhookRepository.execute(delivery.webhookId);\n if (webhookResult.isFail()) {\n return Result.fail(webhookResult.error);\n }\n\n const originalPayload = delivery.payload as IWebhookPayload | null;\n const data = originalPayload?.data ?? {};\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n const newDeliveryResult = await this.createDeliveryRepository.execute({\n webhookId: delivery.webhookId,\n eventType: delivery.eventType,\n status: \"pending\",\n payload: data as Record<string, unknown>,\n expiresAt\n });\n\n if (newDeliveryResult.isFail()) {\n return Result.fail(newDeliveryResult.error);\n }\n\n const triggered = await this.taskService.trigger({\n definition: SEND_WEBHOOK_TASK,\n name: `Resend webhook: ${delivery.eventType}`,\n input: {\n webhookId: delivery.webhookId,\n eventName: delivery.eventType,\n deliveryId: newDeliveryResult.value.id\n }\n });\n if (triggered.isFail()) {\n // Nothing will send this delivery, so it must not stay pending.\n const marked = await this.updateDeliveryRepository.execute(newDeliveryResult.value.id, {\n status: \"failed\"\n });\n return Result.fail(\n new WebhookDeliveryNotQueuedError({\n message: triggered.error.message,\n deliveryId: newDeliveryResult.value.id,\n markedFailed: marked.isOk()\n })\n );\n }\n\n return Result.ok(true);\n }\n}\n\nexport const ResendWebhookDeliveryUseCase = UseCaseAbstraction.createImplementation({\n implementation: ResendWebhookDeliveryUseCaseImpl,\n dependencies: [\n WebhookPermissions,\n GetWebhookDeliveryRepository,\n GetWebhookRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n GetWebhookSettingsRepository,\n UpdateWebhookDeliveryRepository\n ]\n});\n"],"names":["ResendWebhookDeliveryUseCaseImpl","permissions","getDeliveryRepository","getWebhookRepository","createDeliveryRepository","taskService","getSettingsRepository","updateDeliveryRepository","deliveryId","Result","WebhookNotAuthorizedError","parsed","ResendWebhookDeliveryInputSchema","WebhookValidationError","deliveryResult","delivery","webhookResult","originalPayload","data","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","newDeliveryResult","triggered","SEND_WEBHOOK_TASK","marked","WebhookDeliveryNotQueuedError","ResendWebhookDeliveryUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookDeliveryRepository","GetWebhookRepository","CreateWebhookDeliveryRepository","TaskService","GetWebhookSettingsRepository","UpdateWebhookDeliveryRepository"],"mappings":";;;;;;;;;;;;AAeA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,qBAA6D,EAC7DC,oBAAoD,EACpDC,wBAAmE,EACnEC,WAAkC,EAClCC,qBAA6D,EAC7DC,wBAAmE,CACtF;aAPmBN,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;aACAC,oBAAoB,GAApBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;aACAC,wBAAwB,GAAxBA;IAClB;IAEH,MAAM,QAAQC,UAAkB,EAAsD;QAClF,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,iCAAiC,SAAS,CAAC;YAAEJ;QAAW;QACvE,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAMG,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACH,OAAO,IAAI,CAAC,UAAU;QACtF,IAAIG,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,WAAWD,eAAe,KAAK;QAErC,MAAME,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACD,SAAS,SAAS;QAChF,IAAIC,cAAc,MAAM,IACpB,OAAOP,OAAO,IAAI,CAACO,cAAc,KAAK;QAG1C,MAAMC,kBAAkBF,SAAS,OAAO;QACxC,MAAMG,OAAOD,iBAAiB,QAAQ,CAAC;QAEvC,MAAME,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO;QAC/D,MAAMC,gBAAgBD,eAAe,IAAI,KAClCA,eAAe,KAAK,CAAC,qBAAqB,IAAIE,sCAC/CA;QAEN,MAAMC,YAAY,IAAIC,KAAKA,KAAK,GAAG,KAAKH,AAAgB,KAAhBA,
|
|
1
|
+
{"version":3,"file":"api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js","sources":["../../../../src/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { ResendWebhookDeliveryUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { ResendWebhookDeliveryInputSchema } from \"./schema.js\";\nimport { GetWebhookDeliveryRepository } from \"~/api/features/GetWebhookDelivery/abstractions.js\";\nimport { GetWebhookRepository } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookDeliveryRepository } from \"~/api/features/CreateWebhookDelivery/abstractions.js\";\nimport { 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 { TaskService } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { SEND_WEBHOOK_TASK, WEBHOOK_DELIVERY_MAX_RETENTION_DAYS } from \"~/api/domain/constants.js\";\nimport type { IWebhookPayload } from \"~/api/features/SendWebhookTask/types.js\";\n\nclass ResendWebhookDeliveryUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly getDeliveryRepository: GetWebhookDeliveryRepository.Interface,\n private readonly getWebhookRepository: GetWebhookRepository.Interface,\n private readonly createDeliveryRepository: CreateWebhookDeliveryRepository.Interface,\n private readonly taskService: TaskService.Interface,\n private readonly getSettingsRepository: GetWebhookSettingsRepository.Interface,\n private readonly updateDeliveryRepository: UpdateWebhookDeliveryRepository.Interface\n ) {}\n\n async execute(deliveryId: string): Promise<Result<boolean, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = ResendWebhookDeliveryInputSchema.safeParse({ deliveryId });\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n const deliveryResult = await this.getDeliveryRepository.execute(parsed.data.deliveryId);\n if (deliveryResult.isFail()) {\n return Result.fail(deliveryResult.error);\n }\n\n const delivery = deliveryResult.value;\n\n const webhookResult = await this.getWebhookRepository.execute(delivery.webhookId);\n if (webhookResult.isFail()) {\n return Result.fail(webhookResult.error);\n }\n\n const originalPayload = delivery.payload as IWebhookPayload | null;\n const data = originalPayload?.data ?? {};\n\n const settingsResult = await this.getSettingsRepository.execute();\n const retentionDays = settingsResult.isOk()\n ? (settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS)\n : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;\n\n const expiresAt = new Date(Date.now() + retentionDays * 24 * 60 * 60 * 1000);\n\n const newDeliveryResult = await this.createDeliveryRepository.execute({\n webhookId: delivery.webhookId,\n eventType: delivery.eventType,\n status: \"pending\",\n payload: data as Record<string, unknown>,\n expiresAt\n });\n\n if (newDeliveryResult.isFail()) {\n return Result.fail(newDeliveryResult.error);\n }\n\n const triggered = await this.taskService.trigger({\n definition: SEND_WEBHOOK_TASK,\n name: `Resend webhook: ${delivery.eventType}`,\n input: {\n webhookId: delivery.webhookId,\n eventName: delivery.eventType,\n deliveryId: newDeliveryResult.value.id\n }\n });\n if (triggered.isFail()) {\n // Nothing will send this delivery, so it must not stay pending.\n const marked = await this.updateDeliveryRepository.execute(newDeliveryResult.value.id, {\n status: \"failed\"\n });\n return Result.fail(\n new WebhookDeliveryNotQueuedError({\n message: triggered.error.message,\n deliveryId: newDeliveryResult.value.id,\n markedFailed: marked.isOk()\n })\n );\n }\n\n return Result.ok(true);\n }\n}\n\nexport const ResendWebhookDeliveryUseCase = UseCaseAbstraction.createImplementation({\n implementation: ResendWebhookDeliveryUseCaseImpl,\n dependencies: [\n WebhookPermissions,\n GetWebhookDeliveryRepository,\n GetWebhookRepository,\n CreateWebhookDeliveryRepository,\n TaskService,\n GetWebhookSettingsRepository,\n UpdateWebhookDeliveryRepository\n ]\n});\n"],"names":["ResendWebhookDeliveryUseCaseImpl","permissions","getDeliveryRepository","getWebhookRepository","createDeliveryRepository","taskService","getSettingsRepository","updateDeliveryRepository","deliveryId","Result","WebhookNotAuthorizedError","parsed","ResendWebhookDeliveryInputSchema","WebhookValidationError","deliveryResult","delivery","webhookResult","originalPayload","data","settingsResult","retentionDays","WEBHOOK_DELIVERY_MAX_RETENTION_DAYS","expiresAt","Date","newDeliveryResult","triggered","SEND_WEBHOOK_TASK","marked","WebhookDeliveryNotQueuedError","ResendWebhookDeliveryUseCase","UseCaseAbstraction","WebhookPermissions","GetWebhookDeliveryRepository","GetWebhookRepository","CreateWebhookDeliveryRepository","TaskService","GetWebhookSettingsRepository","UpdateWebhookDeliveryRepository"],"mappings":";;;;;;;;;;;;AAeA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,qBAA6D,EAC7DC,oBAAoD,EACpDC,wBAAmE,EACnEC,WAAkC,EAClCC,qBAA6D,EAC7DC,wBAAmE,CACtF;aAPmBN,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;aACAC,oBAAoB,GAApBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,qBAAqB,GAArBA;aACAC,wBAAwB,GAAxBA;IAClB;IAEH,MAAM,QAAQC,UAAkB,EAAsD;QAClF,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,iCAAiC,SAAS,CAAC;YAAEJ;QAAW;QACvE,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,MAAMG,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACH,OAAO,IAAI,CAAC,UAAU;QACtF,IAAIG,eAAe,MAAM,IACrB,OAAOL,OAAO,IAAI,CAACK,eAAe,KAAK;QAG3C,MAAMC,WAAWD,eAAe,KAAK;QAErC,MAAME,gBAAgB,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACD,SAAS,SAAS;QAChF,IAAIC,cAAc,MAAM,IACpB,OAAOP,OAAO,IAAI,CAACO,cAAc,KAAK;QAG1C,MAAMC,kBAAkBF,SAAS,OAAO;QACxC,MAAMG,OAA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@ -1,5 +1,6 @@
|
|
|
1
1
|
import "@webiny/background-tasks/api/types.js";
|
|
2
2
|
import { TaskDefinition, TaskHandler } from "@webiny/api-core/exports/api/tasks.js";
|
|
3
|
+
import { isValidEndpointUrl } from "../../utils/isValidEndpointUrl.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";
|
|
@@ -8,6 +9,11 @@ import { UpdateWebhookDeliveryRepository } from "../UpdateWebhookDelivery/abstra
|
|
|
8
9
|
import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.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 SendWebhookTaskHandlerImpl {
|
|
12
18
|
constructor(getWebhookRepository, getWebhookDeliveryRepository, updateDeliveryRepository, signPayload, tenantContext, getWebhookSettingsRepository, deliver){
|
|
13
19
|
this.getWebhookRepository = getWebhookRepository;
|
|
@@ -67,6 +73,14 @@ class SendWebhookTaskHandlerImpl {
|
|
|
67
73
|
"Content-Type": "application/json",
|
|
68
74
|
...signHeaders
|
|
69
75
|
};
|
|
76
|
+
if (!isValidEndpointUrl(webhook.endpointUrl)) {
|
|
77
|
+
await this.updateDeliveryRepository.execute(input.deliveryId, {
|
|
78
|
+
status: "failed"
|
|
79
|
+
});
|
|
80
|
+
return controller.response.error({
|
|
81
|
+
message: `Webhook endpoint URL is not allowed: ${webhook.endpointUrl}`
|
|
82
|
+
});
|
|
83
|
+
}
|
|
70
84
|
const result = await this.deliver.execute({
|
|
71
85
|
url: webhook.endpointUrl,
|
|
72
86
|
headers: requestHeaders,
|
|
@@ -81,7 +95,7 @@ class SendWebhookTaskHandlerImpl {
|
|
|
81
95
|
requestHeaders,
|
|
82
96
|
responseTime: result.responseTime,
|
|
83
97
|
responseStatus: result.status,
|
|
84
|
-
responseBody: result.body,
|
|
98
|
+
responseBody: truncateResponseBody(result.body),
|
|
85
99
|
status: result.status > 0 ? "delivered" : "failed"
|
|
86
100
|
});
|
|
87
101
|
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, TaskHandler } 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 = TaskHandler.RunParams<ISendWebhookTaskInput, ISendWebhookTaskOutput>;\n\nclass SendWebhookTaskHandlerImpl implements TaskHandler.Interface<\n ISendWebhookTaskInput,\n ISendWebhookTaskOutput\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\nconst SendWebhookTaskHandler = TaskHandler.createImplementation({\n implementation: SendWebhookTaskHandlerImpl,\n dependencies: [\n GetWebhookRepository,\n GetWebhookDeliveryRepository,\n UpdateWebhookDeliveryRepository,\n WebhookSignPayload,\n TenantContext,\n GetWebhookSettingsRepository,\n WebhookDeliver\n ]\n});\n\nclass SendWebhookTaskDefinition implements TaskDefinition.Interface {\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 handler = SendWebhookTaskHandler;\n}\n\nexport const SendWebhookTask = TaskDefinition.createImplementation({\n implementation: SendWebhookTaskDefinition,\n dependencies: []\n});\n"],"names":["SendWebhookTaskHandlerImpl","getWebhookRepository","getWebhookDeliveryRepository","updateDeliveryRepository","signPayload","tenantContext","getWebhookSettingsRepository","deliver","params","input","controller","taskId","delivery","webhookResult","webhook","now","Date","payload","rawBody","JSON","signHeaders","settingsResult","signingSecret","ex","requestHeaders","result","SendWebhookTaskHandler","TaskHandler","GetWebhookRepository","GetWebhookDeliveryRepository","UpdateWebhookDeliveryRepository","WebhookSignPayload","TenantContext","GetWebhookSettingsRepository","WebhookDeliver","SendWebhookTaskDefinition","SEND_WEBHOOK_TASK","SendWebhookTask","TaskDefinition"],"mappings":";;;;;;;;;;AAeA,MAAMA;IAIF,YACqBC,oBAAoD,EACpDC,4BAAoE,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C;aACL,KAAK,GAAG;aACR,aAAa,GAAG;aAChB,SAAS,GAAG;aACZ,YAAY,GAAG;aACf,WAAW,GACvB;aACY,WAAW,GAAG;aAE9B,OAAO,GAAGV;;AACd;AAEO,MAAMW,kBAAkBC,eAAe,oBAAoB,CAAC;IAC/D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
|
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, TaskHandler } from \"@webiny/api-core/exports/api/tasks.js\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.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 = TaskHandler.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 SendWebhookTaskHandlerImpl implements TaskHandler.Interface<\n ISendWebhookTaskInput,\n ISendWebhookTaskOutput\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\nconst SendWebhookTaskHandler = TaskHandler.createImplementation({\n implementation: SendWebhookTaskHandlerImpl,\n dependencies: [\n GetWebhookRepository,\n GetWebhookDeliveryRepository,\n UpdateWebhookDeliveryRepository,\n WebhookSignPayload,\n TenantContext,\n GetWebhookSettingsRepository,\n WebhookDeliver\n ]\n});\n\nclass SendWebhookTaskDefinition implements TaskDefinition.Interface {\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 handler = SendWebhookTaskHandler;\n}\n\nexport const SendWebhookTask = TaskDefinition.createImplementation({\n implementation: SendWebhookTaskDefinition,\n dependencies: []\n});\n"],"names":["MAX_STORED_RESPONSE_BODY_LENGTH","truncateResponseBody","body","SendWebhookTaskHandlerImpl","getWebhookRepository","getWebhookDeliveryRepository","updateDeliveryRepository","signPayload","tenantContext","getWebhookSettingsRepository","deliver","params","input","controller","taskId","delivery","webhookResult","webhook","now","Date","payload","rawBody","JSON","signHeaders","settingsResult","signingSecret","ex","requestHeaders","isValidEndpointUrl","result","SendWebhookTaskHandler","TaskHandler","GetWebhookRepository","GetWebhookDeliveryRepository","UpdateWebhookDeliveryRepository","WebhookSignPayload","TenantContext","GetWebhookSettingsRepository","WebhookDeliver","SendWebhookTaskDefinition","SEND_WEBHOOK_TASK","SendWebhookTask","TaskDefinition"],"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;IAIF,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;IAClB;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,IA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B,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,cAAc5B,qBAAqB4B,OAAO,IAAI;YAC9C,QAAQA,OAAO,MAAM,GAAG,IAAI,cAAc;QAC9C;QAEA,OAAOhB,WAAW,QAAQ,CAAC,IAAI;IACnC;AACJ;AAEA,MAAMiB,yBAAyBC,YAAY,oBAAoB,CAAC;IAC5D,gBAAgB5B;IAChB,cAAc;QACV6B;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;KACH;AACL;AAEA,MAAMC;;aACc,EAAE,GAAGC;aACL,KAAK,GAAG;aACR,aAAa,GAAG;aAChB,SAAS,GAAG;aACZ,YAAY,GAAG;aACf,WAAW,GACvB;aACY,WAAW,GAAG;aAE9B,OAAO,GAAGV;;AACd;AAEO,MAAMW,kBAAkBC,eAAe,oBAAoB,CAAC;IAC/D,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -30,7 +30,7 @@ class TriggerWebhookUseCaseImpl {
|
|
|
30
30
|
const webhook = webhookResult.value;
|
|
31
31
|
const settingsResult = await this.getSettingsRepository.execute();
|
|
32
32
|
const retentionDays = settingsResult.isOk() ? settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;
|
|
33
|
-
const expiresAt = new Date(Date.now() + 24 * retentionDays *
|
|
33
|
+
const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
|
|
34
34
|
const deliveryResult = await this.createDeliveryRepository.execute({
|
|
35
35
|
webhookId: webhook.id,
|
|
36
36
|
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 { 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,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACH,OAAO,IAAI,CAAC,SAAS;QACnF,IAAIG,cAAc,MAAM,IACpB,OAAOL,OAAO,IAAI,CAACK,cAAc,KAAK;QAG1C,MAAMC,UAAUD,cAAc,KAAK;QAEnC,MAAME,iBAAiB,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO;QAC/D,MAAMC,gBAAgBD,eAAe,IAAI,KAClCA,eAAe,KAAK,CAAC,qBAAqB,IAAIE,sCAC/CA;QAEN,MAAMC,YAAY,IAAIC,KAAKA,KAAK,GAAG,KAAKH,AAAgB,KAAhBA,
|
|
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,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAACH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QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -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,OA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OD,KAAK,GAAG,CAACC,QAAQF;QAEhC;QAEA,OAAOA;IACX;IAEQ,gBAAgBG,KAAa,EAAiB;QAClD,MAAMC,UAAUC,OAAOF;QACvB,IAAI,CAACE,OAAO,KAAK,CAACD,YAAYC,OAAO,QAAQ,CAACD,YAAYA,WAAW,GACjE,OAAOA,AAAU,OAAVA;QAGX,MAAME,SAASpB,KAAK,KAAK,CAACiB;QAC1B,IAAI,CAACE,OAAO,KAAK,CAACC,SACd,OAAOL,KAAK,GAAG,CAAC,GAAGK,SAASpB,KAAK,GAAG;QAGxC,OAAO;IACX;IAEQ,MAAMqB,EAAU,EAAiB;QACrC,OAAO,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;IACtD;AACJ;AAEO,MAAMI,gCAAiBC,eAAAA,oBAAgC,CAAC;IAC3D,gBAAgB7B;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -29,7 +29,7 @@ class WebhookDispatcherImpl {
|
|
|
29
29
|
if (result.isFail()) return;
|
|
30
30
|
const settingsResult = await this.getSettingsRepository.execute();
|
|
31
31
|
const retentionDays = settingsResult.isOk() ? settingsResult.value.deliveryRetentionDays ?? WEBHOOK_DELIVERY_MAX_RETENTION_DAYS : WEBHOOK_DELIVERY_MAX_RETENTION_DAYS;
|
|
32
|
-
const expiresAt = new Date(Date.now() + 24 * retentionDays *
|
|
32
|
+
const expiresAt = new Date(Date.now() + 24 * retentionDays * 60 * 60 * 1000);
|
|
33
33
|
for (const webhook of result.value.items){
|
|
34
34
|
const deliveryResult = await this.createDeliveryRepository.execute({
|
|
35
35
|
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 { 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,GAAtBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,QAAQ,GAARA;aACAC,qBAAqB,GAArBA;aACAC,wBAAwB,GAAxBA;aACAC,MAAM,GAANA;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,
|
|
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,GAAtBA;aACAC,wBAAwB,GAAxBA;aACAC,WAAW,GAAXA;aACAC,QAAQ,GAARA;aACAC,qBAAqB,GAArBA;aACAC,wBAAwB,GAAxBA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAM,S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AE;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({
|