@webiny/webhooks 6.4.0-beta.1 → 6.4.0-beta.3
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 +21 -3
- package/admin/WebhookRoutes.js.map +1 -1
- package/admin/Webhooks.js +11 -0
- package/admin/Webhooks.js.map +1 -1
- package/admin/features/getWebhookSettings/GetWebhookSettingsGateway.d.ts +12 -0
- package/admin/features/getWebhookSettings/GetWebhookSettingsGateway.js +40 -0
- package/admin/features/getWebhookSettings/GetWebhookSettingsGateway.js.map +1 -0
- package/admin/features/getWebhookSettings/GetWebhookSettingsUseCase.d.ts +11 -0
- package/admin/features/getWebhookSettings/GetWebhookSettingsUseCase.js +18 -0
- package/admin/features/getWebhookSettings/GetWebhookSettingsUseCase.js.map +1 -0
- package/admin/features/getWebhookSettings/abstractions.d.ts +15 -0
- package/admin/features/getWebhookSettings/abstractions.js +6 -0
- package/admin/features/getWebhookSettings/abstractions.js.map +1 -0
- package/admin/features/getWebhookSettings/feature.d.ts +3 -0
- package/admin/features/getWebhookSettings/feature.js +19 -0
- package/admin/features/getWebhookSettings/feature.js.map +1 -0
- package/admin/features/getWebhookSettings/index.d.ts +2 -0
- package/admin/features/getWebhookSettings/index.js +2 -0
- package/admin/features/updateWebhookSettings/UpdateWebhookSettingsGateway.d.ts +12 -0
- package/admin/features/updateWebhookSettings/UpdateWebhookSettingsGateway.js +43 -0
- package/admin/features/updateWebhookSettings/UpdateWebhookSettingsGateway.js.map +1 -0
- package/admin/features/updateWebhookSettings/UpdateWebhookSettingsUseCase.d.ts +11 -0
- package/admin/features/updateWebhookSettings/UpdateWebhookSettingsUseCase.js +18 -0
- package/admin/features/updateWebhookSettings/UpdateWebhookSettingsUseCase.js.map +1 -0
- package/admin/features/updateWebhookSettings/abstractions.d.ts +18 -0
- package/admin/features/updateWebhookSettings/abstractions.js +6 -0
- package/admin/features/updateWebhookSettings/abstractions.js.map +1 -0
- package/admin/features/updateWebhookSettings/feature.d.ts +3 -0
- package/admin/features/updateWebhookSettings/feature.js +19 -0
- package/admin/features/updateWebhookSettings/feature.js.map +1 -0
- package/admin/features/updateWebhookSettings/index.d.ts +2 -0
- package/admin/features/updateWebhookSettings/index.js +2 -0
- package/admin/presentation/WebhookForm/WebhookFormPresenter.d.ts +6 -2
- package/admin/presentation/WebhookForm/WebhookFormPresenter.js +87 -14
- package/admin/presentation/WebhookForm/WebhookFormPresenter.js.map +1 -1
- package/admin/presentation/WebhookForm/abstractions.d.ts +0 -4
- package/admin/presentation/WebhookForm/abstractions.js.map +1 -1
- package/admin/presentation/WebhookForm/components/WebhookFormView.js +5 -11
- package/admin/presentation/WebhookForm/components/WebhookFormView.js.map +1 -1
- package/admin/presentation/WebhookList/components/WebhookListView.js +28 -21
- package/admin/presentation/WebhookList/components/WebhookListView.js.map +1 -1
- package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.d.ts +21 -0
- package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.js +83 -0
- package/admin/presentation/WebhookSettings/WebhookSettingsPresenter.js.map +1 -0
- package/admin/presentation/WebhookSettings/abstractions.d.ts +16 -0
- package/admin/presentation/WebhookSettings/abstractions.js +5 -0
- package/admin/presentation/WebhookSettings/abstractions.js.map +1 -0
- package/admin/presentation/WebhookSettings/components/WebhookSettingsView.d.ts +2 -0
- package/admin/presentation/WebhookSettings/components/WebhookSettingsView.js +56 -0
- package/admin/presentation/WebhookSettings/components/WebhookSettingsView.js.map +1 -0
- package/admin/presentation/WebhookSettings/feature.d.ts +3 -0
- package/admin/presentation/WebhookSettings/feature.js +17 -0
- package/admin/presentation/WebhookSettings/feature.js.map +1 -0
- package/admin/presentation/WebhookSettings/index.d.ts +2 -0
- package/admin/presentation/WebhookSettings/index.js +2 -0
- package/admin/routes.d.ts +1 -0
- package/admin/routes.js +4 -0
- package/admin/routes.js.map +1 -1
- package/admin/shared/types.d.ts +3 -0
- package/api/WebhooksFeature.js +10 -0
- package/api/WebhooksFeature.js.map +1 -1
- package/api/domain/WebhookSettings.d.ts +3 -0
- package/api/domain/WebhookSettings.js +0 -0
- package/api/domain/constants.d.ts +1 -0
- package/api/domain/constants.js +2 -1
- package/api/domain/constants.js.map +1 -1
- package/api/domain/errors.d.ts +7 -2
- package/api/domain/errors.js +16 -3
- package/api/domain/errors.js.map +1 -1
- package/api/features/CreateWebhook/CreateWebhookUseCase.d.ts +3 -3
- package/api/features/CreateWebhook/CreateWebhookUseCase.js +10 -19
- package/api/features/CreateWebhook/CreateWebhookUseCase.js.map +1 -1
- package/api/features/CreateWebhook/abstractions.d.ts +1 -1
- package/api/features/CreateWebhook/abstractions.js.map +1 -1
- package/api/features/CreateWebhook/schema.d.ts +10 -0
- package/api/features/CreateWebhook/schema.js +16 -0
- package/api/features/CreateWebhook/schema.js.map +1 -0
- package/api/features/DeleteWebhook/DeleteWebhookUseCase.d.ts +3 -3
- package/api/features/DeleteWebhook/DeleteWebhookUseCase.js +8 -3
- package/api/features/DeleteWebhook/DeleteWebhookUseCase.js.map +1 -1
- package/api/features/DeleteWebhook/abstractions.d.ts +2 -2
- package/api/features/DeleteWebhook/abstractions.js.map +1 -1
- package/api/features/DeleteWebhook/schema.d.ts +4 -0
- package/api/features/DeleteWebhook/schema.js +7 -0
- package/api/features/DeleteWebhook/schema.js.map +1 -0
- package/api/features/GetWebhook/GetWebhookUseCase.d.ts +2 -2
- package/api/features/GetWebhook/GetWebhookUseCase.js +7 -2
- package/api/features/GetWebhook/GetWebhookUseCase.js.map +1 -1
- package/api/features/GetWebhook/abstractions.d.ts +2 -2
- package/api/features/GetWebhook/abstractions.js.map +1 -1
- package/api/features/GetWebhook/schema.d.ts +4 -0
- package/api/features/GetWebhook/schema.js +7 -0
- package/api/features/GetWebhook/schema.js.map +1 -0
- package/api/features/GetWebhookDelivery/GetWebhookDeliveryUseCase.d.ts +2 -2
- package/api/features/GetWebhookDelivery/GetWebhookDeliveryUseCase.js +7 -2
- package/api/features/GetWebhookDelivery/GetWebhookDeliveryUseCase.js.map +1 -1
- package/api/features/GetWebhookDelivery/abstractions.d.ts +2 -2
- package/api/features/GetWebhookDelivery/abstractions.js.map +1 -1
- package/api/features/GetWebhookDelivery/schema.d.ts +4 -0
- package/api/features/GetWebhookDelivery/schema.js +7 -0
- package/api/features/GetWebhookDelivery/schema.js.map +1 -0
- package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.d.ts +19 -0
- package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.js +55 -0
- package/api/features/GetWebhookSettings/GetWebhookSettingsRepository.js.map +1 -0
- package/api/features/GetWebhookSettings/abstractions.d.ts +13 -0
- package/api/features/GetWebhookSettings/abstractions.js +5 -0
- package/api/features/GetWebhookSettings/abstractions.js.map +1 -0
- package/api/features/GetWebhookSettings/feature.d.ts +4 -0
- package/api/features/GetWebhookSettings/feature.js +11 -0
- package/api/features/GetWebhookSettings/feature.js.map +1 -0
- package/api/features/ListWebhookDeliveries/ListWebhookDeliveriesUseCase.d.ts +2 -2
- package/api/features/ListWebhookDeliveries/ListWebhookDeliveriesUseCase.js +4 -1
- package/api/features/ListWebhookDeliveries/ListWebhookDeliveriesUseCase.js.map +1 -1
- package/api/features/ListWebhookDeliveries/abstractions.d.ts +2 -2
- package/api/features/ListWebhookDeliveries/abstractions.js.map +1 -1
- package/api/features/ListWebhookDeliveries/schema.d.ts +7 -0
- package/api/features/ListWebhookDeliveries/schema.js +10 -0
- package/api/features/ListWebhookDeliveries/schema.js.map +1 -0
- package/api/features/ListWebhooks/ListWebhooksUseCase.d.ts +2 -2
- package/api/features/ListWebhooks/ListWebhooksUseCase.js +4 -1
- package/api/features/ListWebhooks/ListWebhooksUseCase.js.map +1 -1
- package/api/features/ListWebhooks/abstractions.d.ts +2 -2
- package/api/features/ListWebhooks/abstractions.js.map +1 -1
- package/api/features/ListWebhooks/schema.d.ts +7 -0
- package/api/features/ListWebhooks/schema.js +10 -0
- package/api/features/ListWebhooks/schema.js.map +1 -0
- package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.d.ts +5 -5
- package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js +7 -2
- package/api/features/ResendWebhookDelivery/ResendWebhookDeliveryUseCase.js.map +1 -1
- package/api/features/ResendWebhookDelivery/abstractions.d.ts +2 -2
- package/api/features/ResendWebhookDelivery/abstractions.js.map +1 -1
- package/api/features/ResendWebhookDelivery/schema.d.ts +4 -0
- package/api/features/ResendWebhookDelivery/schema.js +7 -0
- package/api/features/ResendWebhookDelivery/schema.js.map +1 -0
- package/api/features/SendWebhookTask/SendWebhookTask.d.ts +6 -2
- package/api/features/SendWebhookTask/SendWebhookTask.js +45 -33
- package/api/features/SendWebhookTask/SendWebhookTask.js.map +1 -1
- package/api/features/SendWebhookTask/types.d.ts +1 -0
- package/api/features/TriggerWebhook/TriggerWebhookUseCase.js +8 -2
- package/api/features/TriggerWebhook/TriggerWebhookUseCase.js.map +1 -1
- package/api/features/TriggerWebhook/abstractions.d.ts +2 -2
- package/api/features/TriggerWebhook/abstractions.js.map +1 -1
- package/api/features/TriggerWebhook/schema.d.ts +5 -0
- package/api/features/TriggerWebhook/schema.js +8 -0
- package/api/features/TriggerWebhook/schema.js.map +1 -0
- package/api/features/UpdateWebhook/UpdateWebhookUseCase.d.ts +4 -4
- package/api/features/UpdateWebhook/UpdateWebhookUseCase.js +9 -33
- package/api/features/UpdateWebhook/UpdateWebhookUseCase.js.map +1 -1
- package/api/features/UpdateWebhook/abstractions.d.ts +0 -1
- package/api/features/UpdateWebhook/abstractions.js.map +1 -1
- package/api/features/UpdateWebhook/schema.d.ts +9 -0
- package/api/features/UpdateWebhook/schema.js +15 -0
- package/api/features/UpdateWebhook/schema.js.map +1 -0
- package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.d.ts +21 -0
- package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js +60 -0
- package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js.map +1 -0
- package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.d.ts +14 -0
- package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.js +27 -0
- package/api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.js.map +1 -0
- package/api/features/UpdateWebhookSettings/abstractions.d.ts +26 -0
- package/api/features/UpdateWebhookSettings/abstractions.js +6 -0
- package/api/features/UpdateWebhookSettings/abstractions.js.map +1 -0
- package/api/features/UpdateWebhookSettings/feature.d.ts +4 -0
- package/api/features/UpdateWebhookSettings/feature.js +13 -0
- package/api/features/UpdateWebhookSettings/feature.js.map +1 -0
- package/api/features/UpdateWebhookSettings/schema.d.ts +4 -0
- package/api/features/UpdateWebhookSettings/schema.js +7 -0
- package/api/features/UpdateWebhookSettings/schema.js.map +1 -0
- package/api/features/WebhookDeliver/WebhookDeliver.d.ts +13 -0
- package/api/features/WebhookDeliver/WebhookDeliver.js +79 -0
- package/api/features/WebhookDeliver/WebhookDeliver.js.map +1 -0
- package/api/features/WebhookDeliver/abstractions.d.ts +24 -0
- package/api/features/WebhookDeliver/abstractions.js +5 -0
- package/api/features/WebhookDeliver/abstractions.js.map +1 -0
- package/api/features/WebhookDeliver/feature.d.ts +4 -0
- package/api/features/WebhookDeliver/feature.js +11 -0
- package/api/features/WebhookDeliver/feature.js.map +1 -0
- package/api/features/WebhookDeliver/index.d.ts +2 -0
- package/api/features/WebhookDeliver/index.js +2 -0
- package/api/features/WebhookSignPayload/WebhookSignPayload.d.ts +1 -0
- package/api/features/WebhookSignPayload/WebhookSignPayload.js +7 -1
- package/api/features/WebhookSignPayload/WebhookSignPayload.js.map +1 -1
- package/api/graphql/WebhookCrudSchema.js +1 -2
- package/api/graphql/WebhookCrudSchema.js.map +1 -1
- package/api/graphql/WebhookEventSchema.js +1 -0
- package/api/graphql/WebhookEventSchema.js.map +1 -1
- package/api/graphql/WebhookSettingsSchema.d.ts +8 -0
- package/api/graphql/WebhookSettingsSchema.js +60 -0
- package/api/graphql/WebhookSettingsSchema.js.map +1 -0
- package/api/models/WebhookDeliveryModel.js +4 -4
- package/api/models/WebhookDeliveryModel.js.map +1 -1
- package/api/models/WebhookModel.js +1 -1
- package/api/models/WebhookModel.js.map +1 -1
- package/api/models/WebhookSettingsModel.d.ts +8 -0
- package/api/models/WebhookSettingsModel.js +27 -0
- package/api/models/WebhookSettingsModel.js.map +1 -0
- package/api/utils/isValidEndpointUrl.d.ts +1 -0
- package/api/utils/isValidEndpointUrl.js +13 -0
- package/api/utils/isValidEndpointUrl.js.map +1 -0
- package/exports/api/webhooks.d.ts +0 -1
- package/exports/api/webhooks.js +0 -1
- package/package.json +22 -20
- package/admin/SecurityPermission.d.ts +0 -2
- package/admin/SecurityPermission.js +0 -15
- package/admin/SecurityPermission.js.map +0 -1
- package/admin/presentation/WebhookForm/components/EventsSelector.d.ts +0 -12
- package/admin/presentation/WebhookForm/components/EventsSelector.js +0 -44
- package/admin/presentation/WebhookForm/components/EventsSelector.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/UpdateWebhook/schema.js","sources":["../../../../src/api/features/UpdateWebhook/schema.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { isValidEndpointUrl } from \"~/api/utils/isValidEndpointUrl.js\";\n\nexport const UpdateWebhookInputSchema = z.object({\n name: z.string().min(1, \"Name must not be empty.\").optional(),\n endpointUrl: z\n .string()\n .refine(isValidEndpointUrl, {\n message: \"Endpoint URL must use HTTPS. HTTP is only allowed for localhost.\"\n })\n .optional(),\n description: z.string().optional(),\n enabled: z.boolean().optional(),\n events: z.array(z.string()).min(1, \"At least one event must be selected.\").optional(),\n signingSecret: z.string().optional()\n});\n"],"names":["UpdateWebhookInputSchema","z","isValidEndpointUrl"],"mappings":";;AAGO,MAAMA,2BAA2BC,EAAE,MAAM,CAAC;IAC7C,MAAMA,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,2BAA2B,QAAQ;IAC3D,aAAaA,EAAAA,MACF,GACN,MAAM,CAACC,oBAAoB;QACxB,SAAS;IACb,GACC,QAAQ;IACb,aAAaD,EAAE,MAAM,GAAG,QAAQ;IAChC,SAASA,EAAE,OAAO,GAAG,QAAQ;IAC7B,QAAQA,EAAE,KAAK,CAACA,EAAE,MAAM,IAAI,GAAG,CAAC,GAAG,wCAAwC,QAAQ;IACnF,eAAeA,EAAE,MAAM,GAAG,QAAQ;AACtC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { GetModelRepository } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
3
|
+
import { GetLatestRevisionByEntryIdRepository } from "@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
4
|
+
import { UpdateEntryRepository } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
|
|
5
|
+
import { UpdateEntryDataFactory } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
|
|
6
|
+
import { GetWebhookSettingsRepository } from "../../../api/features/GetWebhookSettings/abstractions.js";
|
|
7
|
+
import { UpdateWebhookSettingsRepository as RepositoryAbstraction, type IUpdateWebhookSettingsInput } from "./abstractions.js";
|
|
8
|
+
import type { IWebhookSettings } from "../../../api/domain/WebhookSettings.js";
|
|
9
|
+
declare class UpdateWebhookSettingsRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
10
|
+
private readonly getModelRepository;
|
|
11
|
+
private readonly getWebhookSettingsRepository;
|
|
12
|
+
private readonly getLatestRevisionRepository;
|
|
13
|
+
private readonly updateEntryRepository;
|
|
14
|
+
private readonly updateEntryDataFactory;
|
|
15
|
+
constructor(getModelRepository: GetModelRepository.Interface, getWebhookSettingsRepository: GetWebhookSettingsRepository.Interface, getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface, updateEntryRepository: UpdateEntryRepository.Interface, updateEntryDataFactory: UpdateEntryDataFactory.Interface);
|
|
16
|
+
execute(input: IUpdateWebhookSettingsInput): Promise<Result<IWebhookSettings, RepositoryAbstraction.Error>>;
|
|
17
|
+
}
|
|
18
|
+
export declare const UpdateWebhookSettingsRepository: typeof UpdateWebhookSettingsRepositoryImpl & {
|
|
19
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateWebhookSettingsRepository>;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { createCacheKey } from "@webiny/utils";
|
|
3
|
+
import { GetModelRepository } from "@webiny/api-headless-cms/features/contentModel/GetModel/index.js";
|
|
4
|
+
import { GetLatestRevisionByEntryIdRepository } from "@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js";
|
|
5
|
+
import { UpdateEntryRepository } from "@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js";
|
|
6
|
+
import { UpdateEntryDataFactory } from "@webiny/api-headless-cms/exports/api/cms/entry.js";
|
|
7
|
+
import { GetWebhookSettingsRepository } from "../GetWebhookSettings/abstractions.js";
|
|
8
|
+
import { UpdateWebhookSettingsRepository } from "./abstractions.js";
|
|
9
|
+
import { WebhookModelNotFoundError, WebhookPersistenceError } from "../../domain/errors.js";
|
|
10
|
+
import { WEBHOOK_SETTINGS_MODEL_ID } from "../../domain/constants.js";
|
|
11
|
+
class UpdateWebhookSettingsRepositoryImpl {
|
|
12
|
+
constructor(getModelRepository, getWebhookSettingsRepository, getLatestRevisionRepository, updateEntryRepository, updateEntryDataFactory){
|
|
13
|
+
this.getModelRepository = getModelRepository;
|
|
14
|
+
this.getWebhookSettingsRepository = getWebhookSettingsRepository;
|
|
15
|
+
this.getLatestRevisionRepository = getLatestRevisionRepository;
|
|
16
|
+
this.updateEntryRepository = updateEntryRepository;
|
|
17
|
+
this.updateEntryDataFactory = updateEntryDataFactory;
|
|
18
|
+
}
|
|
19
|
+
async execute(input) {
|
|
20
|
+
try {
|
|
21
|
+
const getResult = await this.getWebhookSettingsRepository.execute();
|
|
22
|
+
if (getResult.isFail()) return getResult;
|
|
23
|
+
const modelResult = await this.getModelRepository.execute(WEBHOOK_SETTINGS_MODEL_ID);
|
|
24
|
+
if (modelResult.isFail()) return Result.fail(new WebhookModelNotFoundError(WEBHOOK_SETTINGS_MODEL_ID));
|
|
25
|
+
const model = modelResult.value;
|
|
26
|
+
const singletonId = createCacheKey(model.modelId);
|
|
27
|
+
const entryId = `${singletonId}#0001`;
|
|
28
|
+
const entryResult = await this.getLatestRevisionRepository.execute(model, {
|
|
29
|
+
id: entryId
|
|
30
|
+
});
|
|
31
|
+
if (entryResult.isFail()) return Result.fail(WebhookPersistenceError.from(entryResult.error));
|
|
32
|
+
const { entry } = await this.updateEntryDataFactory.create(model, {
|
|
33
|
+
values: {
|
|
34
|
+
signingSecret: input.signingSecret
|
|
35
|
+
}
|
|
36
|
+
}, entryResult.value);
|
|
37
|
+
const updateResult = await this.updateEntryRepository.execute(model, entry);
|
|
38
|
+
if (updateResult.isFail()) return Result.fail(WebhookPersistenceError.from(updateResult.error));
|
|
39
|
+
const settings = {
|
|
40
|
+
signingSecret: entry.values.signingSecret
|
|
41
|
+
};
|
|
42
|
+
return Result.ok(settings);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
return Result.fail(WebhookPersistenceError.from(error));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const UpdateWebhookSettingsRepository_UpdateWebhookSettingsRepository = UpdateWebhookSettingsRepository.createImplementation({
|
|
49
|
+
implementation: UpdateWebhookSettingsRepositoryImpl,
|
|
50
|
+
dependencies: [
|
|
51
|
+
GetModelRepository,
|
|
52
|
+
GetWebhookSettingsRepository,
|
|
53
|
+
GetLatestRevisionByEntryIdRepository,
|
|
54
|
+
UpdateEntryRepository,
|
|
55
|
+
UpdateEntryDataFactory
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
export { UpdateWebhookSettingsRepository_UpdateWebhookSettingsRepository as UpdateWebhookSettingsRepository };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=UpdateWebhookSettingsRepository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.js","sources":["../../../../src/api/features/UpdateWebhookSettings/UpdateWebhookSettingsRepository.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { createCacheKey } from \"@webiny/utils\";\nimport { GetModelRepository } from \"@webiny/api-headless-cms/features/contentModel/GetModel/index.js\";\nimport { GetLatestRevisionByEntryIdRepository } from \"@webiny/api-headless-cms/features/contentEntry/GetLatestRevisionByEntryId/index.js\";\nimport { UpdateEntryRepository } from \"@webiny/api-headless-cms/features/contentEntry/UpdateEntry/index.js\";\nimport { UpdateEntryDataFactory } from \"@webiny/api-headless-cms/exports/api/cms/entry.js\";\nimport { GetWebhookSettingsRepository } from \"~/api/features/GetWebhookSettings/abstractions.js\";\nimport {\n UpdateWebhookSettingsRepository as RepositoryAbstraction,\n type IUpdateWebhookSettingsInput\n} from \"./abstractions.js\";\nimport { WebhookModelNotFoundError, WebhookPersistenceError } from \"~/api/domain/errors.js\";\nimport { WEBHOOK_SETTINGS_MODEL_ID } from \"~/api/domain/constants.js\";\nimport type { IWebhookSettings } from \"~/api/domain/WebhookSettings.js\";\n\ninterface WebhookSettingsValues {\n signingSecret?: string;\n}\n\nclass UpdateWebhookSettingsRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private readonly getModelRepository: GetModelRepository.Interface,\n private readonly getWebhookSettingsRepository: GetWebhookSettingsRepository.Interface,\n private readonly getLatestRevisionRepository: GetLatestRevisionByEntryIdRepository.Interface,\n private readonly updateEntryRepository: UpdateEntryRepository.Interface,\n private readonly updateEntryDataFactory: UpdateEntryDataFactory.Interface\n ) {}\n\n async execute(\n input: IUpdateWebhookSettingsInput\n ): Promise<Result<IWebhookSettings, RepositoryAbstraction.Error>> {\n try {\n /* Ensure the singleton entry exists (creates if missing). */\n const getResult = await this.getWebhookSettingsRepository.execute();\n if (getResult.isFail()) {\n return getResult;\n }\n\n const modelResult = await this.getModelRepository.execute(WEBHOOK_SETTINGS_MODEL_ID);\n if (modelResult.isFail()) {\n return Result.fail(new WebhookModelNotFoundError(WEBHOOK_SETTINGS_MODEL_ID));\n }\n\n const model = modelResult.value;\n const singletonId = createCacheKey(model.modelId);\n const entryId = `${singletonId}#0001`;\n\n const entryResult =\n await this.getLatestRevisionRepository.execute<WebhookSettingsValues>(model, {\n id: entryId\n });\n\n if (entryResult.isFail()) {\n return Result.fail(WebhookPersistenceError.from(entryResult.error));\n }\n\n const { entry } = await this.updateEntryDataFactory.create<WebhookSettingsValues>(\n model,\n { values: { signingSecret: input.signingSecret } },\n entryResult.value\n );\n\n const updateResult = await this.updateEntryRepository.execute(model, entry);\n if (updateResult.isFail()) {\n return Result.fail(WebhookPersistenceError.from(updateResult.error));\n }\n\n const settings: IWebhookSettings = {\n signingSecret: entry.values.signingSecret\n };\n\n return Result.ok(settings);\n } catch (error) {\n return Result.fail(WebhookPersistenceError.from(error));\n }\n }\n}\n\nexport const UpdateWebhookSettingsRepository = RepositoryAbstraction.createImplementation({\n implementation: UpdateWebhookSettingsRepositoryImpl,\n dependencies: [\n GetModelRepository,\n GetWebhookSettingsRepository,\n GetLatestRevisionByEntryIdRepository,\n UpdateEntryRepository,\n UpdateEntryDataFactory\n ]\n});\n"],"names":["UpdateWebhookSettingsRepositoryImpl","getModelRepository","getWebhookSettingsRepository","getLatestRevisionRepository","updateEntryRepository","updateEntryDataFactory","input","getResult","modelResult","WEBHOOK_SETTINGS_MODEL_ID","Result","WebhookModelNotFoundError","model","singletonId","createCacheKey","entryId","entryResult","WebhookPersistenceError","entry","updateResult","settings","error","UpdateWebhookSettingsRepository","RepositoryAbstraction","GetModelRepository","GetWebhookSettingsRepository","GetLatestRevisionByEntryIdRepository","UpdateEntryRepository","UpdateEntryDataFactory"],"mappings":";;;;;;;;;;AAmBA,MAAMA;IACF,YACqBC,kBAAgD,EAChDC,4BAAoE,EACpEC,2BAA2E,EAC3EC,qBAAsD,EACtDC,sBAAwD,CAC3E;aALmBJ,kBAAkB,GAAlBA;aACAC,4BAA4B,GAA5BA;aACAC,2BAA2B,GAA3BA;aACAC,qBAAqB,GAArBA;aACAC,sBAAsB,GAAtBA;IAClB;IAEH,MAAM,QACFC,KAAkC,EAC4B;QAC9D,IAAI;YAEA,MAAMC,YAAY,MAAM,IAAI,CAAC,4BAA4B,CAAC,OAAO;YACjE,IAAIA,UAAU,MAAM,IAChB,OAAOA;YAGX,MAAMC,cAAc,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAACC;YAC1D,IAAID,YAAY,MAAM,IAClB,OAAOE,OAAO,IAAI,CAAC,IAAIC,0BAA0BF;YAGrD,MAAMG,QAAQJ,YAAY,KAAK;YAC/B,MAAMK,cAAcC,eAAeF,MAAM,OAAO;YAChD,MAAMG,UAAU,GAAGF,YAAY,KAAK,CAAC;YAErC,MAAMG,cACF,MAAM,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAwBJ,OAAO;gBACzE,IAAIG;YACR;YAEJ,IAAIC,YAAY,MAAM,IAClB,OAAON,OAAO,IAAI,CAACO,wBAAwB,IAAI,CAACD,YAAY,KAAK;YAGrE,MAAM,EAAEE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CACtDN,OACA;gBAAE,QAAQ;oBAAE,eAAeN,MAAM,aAAa;gBAAC;YAAE,GACjDU,YAAY,KAAK;YAGrB,MAAMG,eAAe,MAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAACP,OAAOM;YACrE,IAAIC,aAAa,MAAM,IACnB,OAAOT,OAAO,IAAI,CAACO,wBAAwB,IAAI,CAACE,aAAa,KAAK;YAGtE,MAAMC,WAA6B;gBAC/B,eAAeF,MAAM,MAAM,CAAC,aAAa;YAC7C;YAEA,OAAOR,OAAO,EAAE,CAACU;QACrB,EAAE,OAAOC,OAAO;YACZ,OAAOX,OAAO,IAAI,CAACO,wBAAwB,IAAI,CAACI;QACpD;IACJ;AACJ;AAEO,MAAMC,kEAAkCC,gCAAAA,oBAA0C,CAAC;IACtF,gBAAgBvB;IAChB,cAAc;QACVwB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateWebhookSettingsRepository, UpdateWebhookSettingsUseCase 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 UpdateWebhookSettingsUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
6
|
+
private readonly permissions;
|
|
7
|
+
private readonly repository;
|
|
8
|
+
constructor(permissions: WebhookPermissions.Interface, repository: UpdateWebhookSettingsRepository.Interface);
|
|
9
|
+
execute(input: UseCaseAbstraction.Input): Promise<Result<IWebhookSettings, UseCaseAbstraction.Error>>;
|
|
10
|
+
}
|
|
11
|
+
export declare const UpdateWebhookSettingsUseCase: typeof UpdateWebhookSettingsUseCaseImpl & {
|
|
12
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IUpdateWebhookSettingsUseCase>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateWebhookSettingsRepository, UpdateWebhookSettingsUseCase } from "./abstractions.js";
|
|
3
|
+
import { UpdateWebhookSettingsInputSchema } from "./schema.js";
|
|
4
|
+
import { WebhookPermissions } from "../WebhookPermissions/abstractions.js";
|
|
5
|
+
import { WebhookNotAuthorizedError, WebhookValidationError } from "../../domain/errors.js";
|
|
6
|
+
class UpdateWebhookSettingsUseCaseImpl {
|
|
7
|
+
constructor(permissions, repository){
|
|
8
|
+
this.permissions = permissions;
|
|
9
|
+
this.repository = repository;
|
|
10
|
+
}
|
|
11
|
+
async execute(input) {
|
|
12
|
+
if (!await this.permissions.canEdit("webhook")) return Result.fail(new WebhookNotAuthorizedError());
|
|
13
|
+
const parsed = UpdateWebhookSettingsInputSchema.safeParse(input);
|
|
14
|
+
if (!parsed.success) return Result.fail(new WebhookValidationError(parsed.error));
|
|
15
|
+
return this.repository.execute(parsed.data);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const UpdateWebhookSettingsUseCase_UpdateWebhookSettingsUseCase = UpdateWebhookSettingsUseCase.createImplementation({
|
|
19
|
+
implementation: UpdateWebhookSettingsUseCaseImpl,
|
|
20
|
+
dependencies: [
|
|
21
|
+
WebhookPermissions,
|
|
22
|
+
UpdateWebhookSettingsRepository
|
|
23
|
+
]
|
|
24
|
+
});
|
|
25
|
+
export { UpdateWebhookSettingsUseCase_UpdateWebhookSettingsUseCase as UpdateWebhookSettingsUseCase };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=UpdateWebhookSettingsUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.js","sources":["../../../../src/api/features/UpdateWebhookSettings/UpdateWebhookSettingsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport {\n UpdateWebhookSettingsRepository,\n UpdateWebhookSettingsUseCase as UseCaseAbstraction\n} from \"./abstractions.js\";\nimport { UpdateWebhookSettingsInputSchema } from \"./schema.js\";\nimport { WebhookPermissions } from \"~/api/features/WebhookPermissions/abstractions.js\";\nimport { WebhookNotAuthorizedError, WebhookValidationError } from \"~/api/domain/errors.js\";\nimport type { IWebhookSettings } from \"~/api/domain/WebhookSettings.js\";\n\nclass UpdateWebhookSettingsUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private readonly permissions: WebhookPermissions.Interface,\n private readonly repository: UpdateWebhookSettingsRepository.Interface\n ) {}\n\n async execute(\n input: UseCaseAbstraction.Input\n ): Promise<Result<IWebhookSettings, UseCaseAbstraction.Error>> {\n if (!(await this.permissions.canEdit(\"webhook\"))) {\n return Result.fail(new WebhookNotAuthorizedError());\n }\n\n const parsed = UpdateWebhookSettingsInputSchema.safeParse(input);\n if (!parsed.success) {\n return Result.fail(new WebhookValidationError(parsed.error));\n }\n\n return this.repository.execute(parsed.data);\n }\n}\n\nexport const UpdateWebhookSettingsUseCase = UseCaseAbstraction.createImplementation({\n implementation: UpdateWebhookSettingsUseCaseImpl,\n dependencies: [WebhookPermissions, UpdateWebhookSettingsRepository]\n});\n"],"names":["UpdateWebhookSettingsUseCaseImpl","permissions","repository","input","Result","WebhookNotAuthorizedError","parsed","UpdateWebhookSettingsInputSchema","WebhookValidationError","UpdateWebhookSettingsUseCase","UseCaseAbstraction","WebhookPermissions","UpdateWebhookSettingsRepository"],"mappings":";;;;;AAUA,MAAMA;IACF,YACqBC,WAAyC,EACzCC,UAAqD,CACxE;aAFmBD,WAAW,GAAXA;aACAC,UAAU,GAAVA;IAClB;IAEH,MAAM,QACFC,KAA+B,EAC4B;QAC3D,IAAI,CAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,YACjC,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAG3B,MAAMC,SAASC,iCAAiC,SAAS,CAACJ;QAC1D,IAAI,CAACG,OAAO,OAAO,EACf,OAAOF,OAAO,IAAI,CAAC,IAAII,uBAAuBF,OAAO,KAAK;QAG9D,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAACA,OAAO,IAAI;IAC9C;AACJ;AAEO,MAAMG,4DAA+BC,6BAAAA,oBAAuC,CAAC;IAChF,gBAAgBV;IAChB,cAAc;QAACW;QAAoBC;KAAgC;AACvE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Result } from "@webiny/feature/api";
|
|
2
|
+
import type { IWebhookSettings } from "../../../api/domain/WebhookSettings.js";
|
|
3
|
+
import type { WebhookModelNotFoundError, WebhookNotAuthorizedError, WebhookPersistenceError, WebhookValidationError } from "../../../api/domain/errors.js";
|
|
4
|
+
export interface IUpdateWebhookSettingsInput {
|
|
5
|
+
signingSecret?: string;
|
|
6
|
+
}
|
|
7
|
+
type IError = WebhookModelNotFoundError | WebhookPersistenceError | WebhookNotAuthorizedError | WebhookValidationError;
|
|
8
|
+
export interface IUpdateWebhookSettingsUseCase {
|
|
9
|
+
execute(input: IUpdateWebhookSettingsInput): Promise<Result<IWebhookSettings, IError>>;
|
|
10
|
+
}
|
|
11
|
+
export declare const UpdateWebhookSettingsUseCase: import("@webiny/di").Abstraction<IUpdateWebhookSettingsUseCase>;
|
|
12
|
+
export declare namespace UpdateWebhookSettingsUseCase {
|
|
13
|
+
type Interface = IUpdateWebhookSettingsUseCase;
|
|
14
|
+
type Input = IUpdateWebhookSettingsInput;
|
|
15
|
+
type Error = IError;
|
|
16
|
+
}
|
|
17
|
+
type IRepositoryError = WebhookModelNotFoundError | WebhookPersistenceError;
|
|
18
|
+
export interface IUpdateWebhookSettingsRepository {
|
|
19
|
+
execute(input: IUpdateWebhookSettingsInput): Promise<Result<IWebhookSettings, IRepositoryError>>;
|
|
20
|
+
}
|
|
21
|
+
export declare const UpdateWebhookSettingsRepository: import("@webiny/di").Abstraction<IUpdateWebhookSettingsRepository>;
|
|
22
|
+
export declare namespace UpdateWebhookSettingsRepository {
|
|
23
|
+
type Interface = IUpdateWebhookSettingsRepository;
|
|
24
|
+
type Error = IRepositoryError;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
const UpdateWebhookSettingsUseCase = createAbstraction("Webhooks/UpdateWebhookSettingsUseCase");
|
|
3
|
+
const UpdateWebhookSettingsRepository = createAbstraction("Webhooks/UpdateWebhookSettingsRepository");
|
|
4
|
+
export { UpdateWebhookSettingsRepository, UpdateWebhookSettingsUseCase };
|
|
5
|
+
|
|
6
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/UpdateWebhookSettings/abstractions.js","sources":["../../../../src/api/features/UpdateWebhookSettings/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 WebhookValidationError\n} from \"~/api/domain/errors.js\";\n\nexport interface IUpdateWebhookSettingsInput {\n signingSecret?: string;\n}\n\ntype IError =\n | WebhookModelNotFoundError\n | WebhookPersistenceError\n | WebhookNotAuthorizedError\n | WebhookValidationError;\n\nexport interface IUpdateWebhookSettingsUseCase {\n execute(input: IUpdateWebhookSettingsInput): Promise<Result<IWebhookSettings, IError>>;\n}\n\nexport const UpdateWebhookSettingsUseCase = createAbstraction<IUpdateWebhookSettingsUseCase>(\n \"Webhooks/UpdateWebhookSettingsUseCase\"\n);\n\nexport namespace UpdateWebhookSettingsUseCase {\n export type Interface = IUpdateWebhookSettingsUseCase;\n export type Input = IUpdateWebhookSettingsInput;\n export type Error = IError;\n}\n\ntype IRepositoryError = WebhookModelNotFoundError | WebhookPersistenceError;\n\nexport interface IUpdateWebhookSettingsRepository {\n execute(\n input: IUpdateWebhookSettingsInput\n ): Promise<Result<IWebhookSettings, IRepositoryError>>;\n}\n\nexport const UpdateWebhookSettingsRepository = createAbstraction<IUpdateWebhookSettingsRepository>(\n \"Webhooks/UpdateWebhookSettingsRepository\"\n);\n\nexport namespace UpdateWebhookSettingsRepository {\n export type Interface = IUpdateWebhookSettingsRepository;\n export type Error = IRepositoryError;\n}\n"],"names":["UpdateWebhookSettingsUseCase","createAbstraction","UpdateWebhookSettingsRepository"],"mappings":";AAuBO,MAAMA,+BAA+BC,kBACxC;AAiBG,MAAMC,kCAAkCD,kBAC3C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { UpdateWebhookSettingsUseCase } from "./UpdateWebhookSettingsUseCase.js";
|
|
3
|
+
import { UpdateWebhookSettingsRepository } from "./UpdateWebhookSettingsRepository.js";
|
|
4
|
+
const UpdateWebhookSettingsFeature = createFeature({
|
|
5
|
+
name: "UpdateWebhookSettings",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(UpdateWebhookSettingsUseCase);
|
|
8
|
+
container.register(UpdateWebhookSettingsRepository).inSingletonScope();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { UpdateWebhookSettingsFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/UpdateWebhookSettings/feature.js","sources":["../../../../src/api/features/UpdateWebhookSettings/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { UpdateWebhookSettingsUseCase } from \"./UpdateWebhookSettingsUseCase.js\";\nimport { UpdateWebhookSettingsRepository } from \"./UpdateWebhookSettingsRepository.js\";\n\nexport const UpdateWebhookSettingsFeature = createFeature({\n name: \"UpdateWebhookSettings\",\n register(container) {\n container.register(UpdateWebhookSettingsUseCase);\n container.register(UpdateWebhookSettingsRepository).inSingletonScope();\n }\n});\n"],"names":["UpdateWebhookSettingsFeature","createFeature","container","UpdateWebhookSettingsUseCase","UpdateWebhookSettingsRepository"],"mappings":";;;AAIO,MAAMA,+BAA+BC,cAAc;IACtD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,iCAAiC,gBAAgB;IACxE;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/UpdateWebhookSettings/schema.js","sources":["../../../../src/api/features/UpdateWebhookSettings/schema.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const UpdateWebhookSettingsInputSchema = z.object({\n signingSecret: z.string().optional()\n});\n"],"names":["UpdateWebhookSettingsInputSchema","z"],"mappings":";AAEO,MAAMA,mCAAmCC,EAAE,MAAM,CAAC;IACrD,eAAeA,EAAE,MAAM,GAAG,QAAQ;AACtC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebhookDeliver as Abstraction, type IWebhookDeliverInput, type IWebhookDeliverResult } from "./abstractions.js";
|
|
2
|
+
declare class WebhookDeliverImpl implements Abstraction.Interface {
|
|
3
|
+
execute(input: IWebhookDeliverInput): Promise<IWebhookDeliverResult>;
|
|
4
|
+
private attempt;
|
|
5
|
+
private isRetryable;
|
|
6
|
+
private computeDelay;
|
|
7
|
+
private parseRetryAfter;
|
|
8
|
+
private sleep;
|
|
9
|
+
}
|
|
10
|
+
export declare const WebhookDeliver: typeof WebhookDeliverImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IWebhookDeliver>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { WebhookDeliver } from "./abstractions.js";
|
|
2
|
+
class WebhookDeliverImpl {
|
|
3
|
+
async execute(input) {
|
|
4
|
+
const startTime = Date.now();
|
|
5
|
+
let attempts = 0;
|
|
6
|
+
let lastResult = {
|
|
7
|
+
status: 0,
|
|
8
|
+
body: "",
|
|
9
|
+
retryAfter: null
|
|
10
|
+
};
|
|
11
|
+
for(let i = 0; i <= input.maxRetries; i++){
|
|
12
|
+
if (i > 0) {
|
|
13
|
+
const delay = this.computeDelay(i - 1, input, lastResult);
|
|
14
|
+
await this.sleep(delay);
|
|
15
|
+
}
|
|
16
|
+
attempts++;
|
|
17
|
+
lastResult = await this.attempt(input);
|
|
18
|
+
if (!this.isRetryable(lastResult.status)) break;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
status: lastResult.status,
|
|
22
|
+
body: lastResult.body,
|
|
23
|
+
responseTime: Date.now() - startTime,
|
|
24
|
+
attempts
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async attempt(input) {
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(input.url, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: input.headers,
|
|
32
|
+
body: input.body,
|
|
33
|
+
signal: AbortSignal.timeout(input.timeout)
|
|
34
|
+
});
|
|
35
|
+
const body = await response.text();
|
|
36
|
+
const retryAfter = response.headers.get("retry-after");
|
|
37
|
+
return {
|
|
38
|
+
status: response.status,
|
|
39
|
+
body,
|
|
40
|
+
retryAfter
|
|
41
|
+
};
|
|
42
|
+
} catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
status: 0,
|
|
45
|
+
body: error instanceof Error ? error.message : "Unknown fetch error",
|
|
46
|
+
retryAfter: null
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
isRetryable(status) {
|
|
51
|
+
if (0 === status || 429 === status) return true;
|
|
52
|
+
return status >= 500 && status <= 599;
|
|
53
|
+
}
|
|
54
|
+
computeDelay(retryIndex, input, lastResult) {
|
|
55
|
+
const exponential = Math.min(input.initialDelay * Math.pow(2, retryIndex), input.maxDelay);
|
|
56
|
+
if (429 === lastResult.status && lastResult.retryAfter) {
|
|
57
|
+
const parsed = this.parseRetryAfter(lastResult.retryAfter);
|
|
58
|
+
if (null !== parsed) return Math.max(parsed, exponential);
|
|
59
|
+
}
|
|
60
|
+
return exponential;
|
|
61
|
+
}
|
|
62
|
+
parseRetryAfter(value) {
|
|
63
|
+
const seconds = Number(value);
|
|
64
|
+
if (!Number.isNaN(seconds) && Number.isFinite(seconds) && seconds >= 0) return 1000 * seconds;
|
|
65
|
+
const dateMs = Date.parse(value);
|
|
66
|
+
if (!Number.isNaN(dateMs)) return Math.max(0, dateMs - Date.now());
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
sleep(ms) {
|
|
70
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const WebhookDeliver_WebhookDeliver = WebhookDeliver.createImplementation({
|
|
74
|
+
implementation: WebhookDeliverImpl,
|
|
75
|
+
dependencies: []
|
|
76
|
+
});
|
|
77
|
+
export { WebhookDeliver_WebhookDeliver as WebhookDeliver };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=WebhookDeliver.js.map
|
|
@@ -0,0 +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;gBAChB,QAAQS,YAAY,OAAO,CAACT,MAAM,OAAO;YAC7C;YAEA,MAAMU,OAAO,MAAMH,SAAS,IAAI;YAChC,MAAMI,aAAaJ,SAAS,OAAO,CAAC,GAAG,CAAC;YAExC,OAAO;gBAAE,QAAQA,SAAS,MAAM;gBAAEG;gBAAMC;YAAW;QACvD,EAAE,OAAOC,OAAO;YACZ,OAAO;gBACH,QAAQ;gBACR,MAAMA,iBAAiBC,QAAQD,MAAM,OAAO,GAAG;gBAC/C,YAAY;YAChB;QACJ;IACJ;IAEQ,YAAYE,MAAc,EAAW;QACzC,IAAIA,AAAW,MAAXA,UAAgBA,AAAW,QAAXA,QAChB,OAAO;QAEX,OAAOA,UAAU,OAAOA,UAAU;IACtC;IAEQ,aACJC,UAAkB,EAClBf,KAA2B,EAC3BI,UAA0B,EACpB;QACN,MAAMY,cAAcC,KAAK,GAAG,CAACjB,MAAM,YAAY,GAAGiB,KAAK,GAAG,CAAC,GAAGF,aAAaf,MAAM,QAAQ;QAEzF,IAAII,AAAsB,QAAtBA,WAAW,MAAM,IAAYA,WAAW,UAAU,EAAE;YACpD,MAAMc,SAAS,IAAI,CAAC,eAAe,CAACd,WAAW,UAAU;YACzD,IAAIc,AAAW,SAAXA,QACA,OAAOD,KAAK,GAAG,CAACC,QAAQF;QAEhC;QAEA,OAAOA;IACX;IAEQ,gBAAgBG,KAAa,EAAiB;QAClD,MAAMC,UAAUC,OAAOF;QACvB,IAAI,CAACE,OAAO,KAAK,CAACD,YAAYC,OAAO,QAAQ,CAACD,YAAYA,WAAW,GACjE,OAAOA,AAAU,OAAVA;QAGX,MAAME,SAASpB,KAAK,KAAK,CAACiB;QAC1B,IAAI,CAACE,OAAO,KAAK,CAACC,SACd,OAAOL,KAAK,GAAG,CAAC,GAAGK,SAASpB,KAAK,GAAG;QAGxC,OAAO;IACX;IAEQ,MAAMqB,EAAU,EAAiB;QACrC,OAAO,IAAIC,QAAQC,CAAAA,UAAWC,WAAWD,SAASF;IACtD;AACJ;AAEO,MAAMI,gCAAiBC,eAAAA,oBAAgC,CAAC;IAC3D,gBAAgB7B;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface IWebhookDeliverInput {
|
|
2
|
+
url: string;
|
|
3
|
+
headers: Record<string, string>;
|
|
4
|
+
body: string;
|
|
5
|
+
timeout: number;
|
|
6
|
+
maxRetries: number;
|
|
7
|
+
initialDelay: number;
|
|
8
|
+
maxDelay: number;
|
|
9
|
+
}
|
|
10
|
+
export interface IWebhookDeliverResult {
|
|
11
|
+
status: number;
|
|
12
|
+
body: string;
|
|
13
|
+
responseTime: number;
|
|
14
|
+
attempts: number;
|
|
15
|
+
}
|
|
16
|
+
export interface IWebhookDeliver {
|
|
17
|
+
execute(input: IWebhookDeliverInput): Promise<IWebhookDeliverResult>;
|
|
18
|
+
}
|
|
19
|
+
export declare const WebhookDeliver: import("@webiny/di").Abstraction<IWebhookDeliver>;
|
|
20
|
+
export declare namespace WebhookDeliver {
|
|
21
|
+
type Interface = IWebhookDeliver;
|
|
22
|
+
type Input = IWebhookDeliverInput;
|
|
23
|
+
type Result = IWebhookDeliverResult;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/WebhookDeliver/abstractions.js","sources":["../../../../src/api/features/WebhookDeliver/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IWebhookDeliverInput {\n url: string;\n headers: Record<string, string>;\n body: string;\n timeout: number;\n maxRetries: number;\n initialDelay: number;\n maxDelay: number;\n}\n\nexport interface IWebhookDeliverResult {\n status: number;\n body: string;\n responseTime: number;\n attempts: number;\n}\n\nexport interface IWebhookDeliver {\n execute(input: IWebhookDeliverInput): Promise<IWebhookDeliverResult>;\n}\n\nexport const WebhookDeliver = createAbstraction<IWebhookDeliver>(\"Webhooks/WebhookDeliver\");\n\nexport namespace WebhookDeliver {\n export type Interface = IWebhookDeliver;\n export type Input = IWebhookDeliverInput;\n export type Result = IWebhookDeliverResult;\n}\n"],"names":["WebhookDeliver","createAbstraction"],"mappings":";AAuBO,MAAMA,iBAAiBC,kBAAmC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { WebhookDeliver } from "./WebhookDeliver.js";
|
|
3
|
+
const WebhookDeliverFeature = createFeature({
|
|
4
|
+
name: "Webhooks/WebhookDeliver",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(WebhookDeliver).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { WebhookDeliverFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api/features/WebhookDeliver/feature.js","sources":["../../../../src/api/features/WebhookDeliver/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { WebhookDeliver } from \"./WebhookDeliver.js\";\n\nexport const WebhookDeliverFeature = createFeature({\n name: \"Webhooks/WebhookDeliver\",\n register(container) {\n container.register(WebhookDeliver).inSingletonScope();\n }\n});\n"],"names":["WebhookDeliverFeature","createFeature","container","WebhookDeliver"],"mappings":";;AAGO,MAAMA,wBAAwBC,cAAc;IAC/C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,gBAAgB,gBAAgB;IACvD;AACJ"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WebhookSignPayload as WebhookSignPayloadAbstraction } from "@webiny/api-core/features/webhooks/index.js";
|
|
2
2
|
declare class WebhookSignPayloadImpl implements WebhookSignPayloadAbstraction.Interface {
|
|
3
3
|
sign(msgId: string, timestamp: Date, rawBody: string | Buffer, secret: string): Promise<WebhookSignPayloadAbstraction.Headers>;
|
|
4
|
+
private ensureBase64;
|
|
4
5
|
}
|
|
5
6
|
export declare const WebhookSignPayload: typeof WebhookSignPayloadImpl & {
|
|
6
7
|
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/webhooks/WebhookSignPayload/abstractions").IWebhookSignPayload>;
|
|
@@ -2,7 +2,8 @@ import { Webhook } from "standardwebhooks";
|
|
|
2
2
|
import { WebhookSignPayload } from "@webiny/api-core/features/webhooks/index.js";
|
|
3
3
|
class WebhookSignPayloadImpl {
|
|
4
4
|
async sign(msgId, timestamp, rawBody, secret) {
|
|
5
|
-
const
|
|
5
|
+
const encodedSecret = this.ensureBase64(secret);
|
|
6
|
+
const wh = new Webhook(encodedSecret);
|
|
6
7
|
const signature = wh.sign(msgId, timestamp, rawBody);
|
|
7
8
|
return {
|
|
8
9
|
"webhook-id": msgId,
|
|
@@ -10,6 +11,11 @@ class WebhookSignPayloadImpl {
|
|
|
10
11
|
"webhook-signature": signature
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
ensureBase64(secret) {
|
|
15
|
+
if (secret.startsWith("whsec_")) return secret;
|
|
16
|
+
const encoded = Buffer.from(secret).toString("base64");
|
|
17
|
+
return `whsec_${encoded}`;
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
const WebhookSignPayload_WebhookSignPayload = WebhookSignPayload.createImplementation({
|
|
15
21
|
implementation: WebhookSignPayloadImpl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/features/WebhookSignPayload/WebhookSignPayload.js","sources":["../../../../src/api/features/WebhookSignPayload/WebhookSignPayload.ts"],"sourcesContent":["import { Webhook } from \"standardwebhooks\";\nimport { WebhookSignPayload as WebhookSignPayloadAbstraction } from \"@webiny/api-core/features/webhooks/index.js\";\n\nclass WebhookSignPayloadImpl implements WebhookSignPayloadAbstraction.Interface {\n async sign(\n msgId: string,\n timestamp: Date,\n rawBody: string | Buffer,\n secret: string\n ): Promise<WebhookSignPayloadAbstraction.Headers> {\n const wh = new Webhook(
|
|
1
|
+
{"version":3,"file":"api/features/WebhookSignPayload/WebhookSignPayload.js","sources":["../../../../src/api/features/WebhookSignPayload/WebhookSignPayload.ts"],"sourcesContent":["import { Webhook } from \"standardwebhooks\";\nimport { WebhookSignPayload as WebhookSignPayloadAbstraction } from \"@webiny/api-core/features/webhooks/index.js\";\n\nclass WebhookSignPayloadImpl implements WebhookSignPayloadAbstraction.Interface {\n async sign(\n msgId: string,\n timestamp: Date,\n rawBody: string | Buffer,\n secret: string\n ): Promise<WebhookSignPayloadAbstraction.Headers> {\n /* The standardwebhooks library expects the secret to be base64-encoded\n (optionally prefixed with \"whsec_\"). User-provided secrets are plain\n text, so we base64-encode them before passing to the library. */\n const encodedSecret = this.ensureBase64(secret);\n const wh = new Webhook(encodedSecret);\n const signature = wh.sign(msgId, timestamp, rawBody);\n return {\n \"webhook-id\": msgId,\n \"webhook-timestamp\": String(Math.floor(timestamp.getTime() / 1000)),\n \"webhook-signature\": signature\n };\n }\n\n private ensureBase64(secret: string): string {\n if (secret.startsWith(\"whsec_\")) {\n return secret;\n }\n\n const encoded = Buffer.from(secret).toString(\"base64\");\n return `whsec_${encoded}`;\n }\n}\n\nexport const WebhookSignPayload = WebhookSignPayloadAbstraction.createImplementation({\n implementation: WebhookSignPayloadImpl,\n dependencies: []\n});\n"],"names":["WebhookSignPayloadImpl","msgId","timestamp","rawBody","secret","encodedSecret","wh","Webhook","signature","String","Math","encoded","Buffer","WebhookSignPayload","WebhookSignPayloadAbstraction"],"mappings":";;AAGA,MAAMA;IACF,MAAM,KACFC,KAAa,EACbC,SAAe,EACfC,OAAwB,EACxBC,MAAc,EACgC;QAI9C,MAAMC,gBAAgB,IAAI,CAAC,YAAY,CAACD;QACxC,MAAME,KAAK,IAAIC,QAAQF;QACvB,MAAMG,YAAYF,GAAG,IAAI,CAACL,OAAOC,WAAWC;QAC5C,OAAO;YACH,cAAcF;YACd,qBAAqBQ,OAAOC,KAAK,KAAK,CAACR,UAAU,OAAO,KAAK;YAC7D,qBAAqBM;QACzB;IACJ;IAEQ,aAAaJ,MAAc,EAAU;QACzC,IAAIA,OAAO,UAAU,CAAC,WAClB,OAAOA;QAGX,MAAMO,UAAUC,OAAO,IAAI,CAACR,QAAQ,QAAQ,CAAC;QAC7C,OAAO,CAAC,MAAM,EAAEO,SAAS;IAC7B;AACJ;AAEO,MAAME,wCAAqBC,mBAAAA,oBAAkD,CAAC;IACjF,gBAAgBd;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -28,7 +28,7 @@ class WebhookCrudSchema_ {
|
|
|
28
28
|
description: String
|
|
29
29
|
enabled: Boolean!
|
|
30
30
|
events: [String!]!
|
|
31
|
-
signingSecret: String
|
|
31
|
+
signingSecret: String
|
|
32
32
|
createdOn: DateTime
|
|
33
33
|
modifiedOn: DateTime
|
|
34
34
|
}
|
|
@@ -56,7 +56,6 @@ class WebhookCrudSchema_ {
|
|
|
56
56
|
|
|
57
57
|
input UpdateWebhookInput {
|
|
58
58
|
name: String
|
|
59
|
-
slug: String
|
|
60
59
|
endpointUrl: String
|
|
61
60
|
description: String
|
|
62
61
|
enabled: Boolean
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/graphql/WebhookCrudSchema.js","sources":["../../../src/api/graphql/WebhookCrudSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListResponse } from \"@webiny/handler-graphql\";\nimport { ListErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListWebhooksUseCase } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport type { IListWebhooksInput } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { GetWebhookUseCase } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookUseCase } from \"~/api/features/CreateWebhook/abstractions.js\";\nimport { UpdateWebhookUseCase } from \"~/api/features/UpdateWebhook/abstractions.js\";\nimport { DeleteWebhookUseCase } from \"~/api/features/DeleteWebhook/abstractions.js\";\n\ninterface IIdArgs {\n id: string;\n}\n\ninterface ICreateWebhookArgs {\n input: CreateWebhookUseCase.Input;\n}\n\ninterface IUpdateWebhookArgs {\n id: string;\n input: UpdateWebhookUseCase.Input;\n}\n\nclass WebhookCrudSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookError {\n code: String\n message: String\n data: JSON\n }\n\n type WebhookListMeta {\n cursor: String\n hasMoreItems: Boolean!\n totalCount: Int!\n }\n\n type Webhook {\n id: ID!\n name: String!\n slug: String!\n endpointUrl: String!\n description: String\n enabled: Boolean!\n events: [String!]!\n signingSecret: String
|
|
1
|
+
{"version":3,"file":"api/graphql/WebhookCrudSchema.js","sources":["../../../src/api/graphql/WebhookCrudSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListResponse } from \"@webiny/handler-graphql\";\nimport { ListErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListWebhooksUseCase } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport type { IListWebhooksInput } from \"~/api/features/ListWebhooks/abstractions.js\";\nimport { GetWebhookUseCase } from \"~/api/features/GetWebhook/abstractions.js\";\nimport { CreateWebhookUseCase } from \"~/api/features/CreateWebhook/abstractions.js\";\nimport { UpdateWebhookUseCase } from \"~/api/features/UpdateWebhook/abstractions.js\";\nimport { DeleteWebhookUseCase } from \"~/api/features/DeleteWebhook/abstractions.js\";\n\ninterface IIdArgs {\n id: string;\n}\n\ninterface ICreateWebhookArgs {\n input: CreateWebhookUseCase.Input;\n}\n\ninterface IUpdateWebhookArgs {\n id: string;\n input: UpdateWebhookUseCase.Input;\n}\n\nclass WebhookCrudSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookError {\n code: String\n message: String\n data: JSON\n }\n\n type WebhookListMeta {\n cursor: String\n hasMoreItems: Boolean!\n totalCount: Int!\n }\n\n type Webhook {\n id: ID!\n name: String!\n slug: String!\n endpointUrl: String!\n description: String\n enabled: Boolean!\n events: [String!]!\n signingSecret: String\n createdOn: DateTime\n modifiedOn: DateTime\n }\n\n type WebhookResponse {\n data: Webhook\n error: WebhookError\n }\n\n type WebhookListResponse {\n data: [Webhook!]\n meta: WebhookListMeta\n error: WebhookError\n }\n\n input CreateWebhookInput {\n name: String!\n slug: String\n endpointUrl: String!\n description: String\n enabled: Boolean\n events: [String!]!\n signingSecret: String\n }\n\n input UpdateWebhookInput {\n name: String\n endpointUrl: String\n description: String\n enabled: Boolean\n events: [String!]\n }\n\n input ListWebhooksWhereInput {\n enabled: Boolean\n }\n\n type WebhookQuery {\n listWebhooks(\n where: ListWebhooksWhereInput\n limit: Int\n after: String\n ): WebhookListResponse!\n getWebhook(id: ID!): WebhookResponse!\n }\n\n type WebhookMutation {\n createWebhook(input: CreateWebhookInput!): WebhookResponse!\n updateWebhook(id: ID!, input: UpdateWebhookInput!): WebhookResponse!\n deleteWebhook(id: ID!): BooleanResponse!\n }\n\n extend type Query {\n webhooks: WebhookQuery!\n }\n\n extend type Mutation {\n webhooks: WebhookMutation!\n }\n `);\n\n builder.addResolver({\n path: \"Query.webhooks\",\n dependencies: [],\n resolver: () => () => ({})\n });\n\n builder.addResolver({\n path: \"Mutation.webhooks\",\n dependencies: [],\n resolver: () => () => ({})\n });\n\n builder.addResolver<IListWebhooksInput>({\n path: \"WebhookQuery.listWebhooks\",\n dependencies: [ListWebhooksUseCase],\n resolver: (listWebhooks: ListWebhooksUseCase.Interface) => {\n return async ({ args }) => {\n const result = await listWebhooks.execute(args);\n if (result.isFail()) {\n return new ListErrorResponse(result.error);\n }\n return new ListResponse(result.value.items, result.value.meta);\n };\n }\n });\n\n builder.addResolver<IIdArgs>({\n path: \"WebhookQuery.getWebhook\",\n dependencies: [GetWebhookUseCase],\n resolver: (getWebhook: GetWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await getWebhook.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<ICreateWebhookArgs>({\n path: \"WebhookMutation.createWebhook\",\n dependencies: [CreateWebhookUseCase],\n resolver: (createWebhook: CreateWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await createWebhook.execute(args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IUpdateWebhookArgs>({\n path: \"WebhookMutation.updateWebhook\",\n dependencies: [UpdateWebhookUseCase],\n resolver: (updateWebhook: UpdateWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await updateWebhook.execute(args.id, args.input);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n builder.addResolver<IIdArgs>({\n path: \"WebhookMutation.deleteWebhook\",\n dependencies: [DeleteWebhookUseCase],\n resolver: (deleteWebhook: DeleteWebhookUseCase.Interface) => {\n return async ({ args }) => {\n const result = await deleteWebhook.execute(args.id);\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(true);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebhookCrudSchema = GraphQLSchemaFactory.createImplementation({\n implementation: WebhookCrudSchema_,\n dependencies: []\n});\n"],"names":["WebhookCrudSchema_","builder","ListWebhooksUseCase","listWebhooks","args","result","ListErrorResponse","ListResponse","GetWebhookUseCase","getWebhook","ErrorResponse","Response","CreateWebhookUseCase","createWebhook","UpdateWebhookUseCase","updateWebhook","DeleteWebhookUseCase","deleteWebhook","WebhookCrudSchema","GraphQLSchemaFactory"],"mappings":";;;;;;;AAyBA,MAAMA;IACF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAiFnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc,EAAE;YAChB,UAAU,IAAM,IAAO,EAAC;QAC5B;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc,EAAE;YAChB,UAAU,IAAM,IAAO,EAAC;QAC5B;QAEAA,QAAQ,WAAW,CAAqB;YACpC,MAAM;YACN,cAAc;gBAACC;aAAoB;YACnC,UAAU,CAACC,eACA,OAAO,EAAEC,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMF,aAAa,OAAO,CAACC;oBAC1C,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,kBAAkBD,OAAO,KAAK;oBAE7C,OAAO,IAAIE,aAAaF,OAAO,KAAK,CAAC,KAAK,EAAEA,OAAO,KAAK,CAAC,IAAI;gBACjE;QAER;QAEAJ,QAAQ,WAAW,CAAU;YACzB,MAAM;YACN,cAAc;gBAACO;aAAkB;YACjC,UAAU,CAACC,aACA,OAAO,EAAEL,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMI,WAAW,OAAO,CAACL,KAAK,EAAE;oBAC/C,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAASN,OAAO,KAAK;gBACpC;QAER;QAEAJ,QAAQ,WAAW,CAAqB;YACpC,MAAM;YACN,cAAc;gBAACW;aAAqB;YACpC,UAAU,CAACC,gBACA,OAAO,EAAET,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMQ,cAAc,OAAO,CAACT,KAAK,KAAK;oBACrD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAASN,OAAO,KAAK;gBACpC;QAER;QAEAJ,QAAQ,WAAW,CAAqB;YACpC,MAAM;YACN,cAAc;gBAACa;aAAqB;YACpC,UAAU,CAACC,gBACA,OAAO,EAAEX,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMU,cAAc,OAAO,CAACX,KAAK,EAAE,EAAEA,KAAK,KAAK;oBAC9D,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAASN,OAAO,KAAK;gBACpC;QAER;QAEAJ,QAAQ,WAAW,CAAU;YACzB,MAAM;YACN,cAAc;gBAACe;aAAqB;YACpC,UAAU,CAACC,gBACA,OAAO,EAAEb,IAAI,EAAE;oBAClB,MAAMC,SAAS,MAAMY,cAAc,OAAO,CAACb,KAAK,EAAE;oBAClD,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIK,cAAcL,OAAO,KAAK;oBAEzC,OAAO,IAAIM,SAAS;gBACxB;QAER;QAEA,OAAOV;IACX;AACJ;AAEO,MAAMiB,oBAAoBC,qBAAqB,oBAAoB,CAAC;IACvE,gBAAgBnB;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api/graphql/WebhookEventSchema.js","sources":["../../../src/api/graphql/WebhookEventSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListAvailableWebhookEventsUseCase } from \"~/api/features/ListAvailableWebhookEvents/abstractions.js\";\n\nclass WebhookEventSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookEvent {\n app: String!\n entity: String!\n eventName: String!\n label: String!\n }\n\n type WebhookEventListResponse {\n data: [WebhookEvent!]\n error: WebhookError\n }\n\n extend type WebhookQuery {\n listAvailableWebhookEvents: WebhookEventListResponse!\n }\n `);\n\n builder.addResolver({\n path: \"WebhookQuery.listAvailableWebhookEvents\",\n dependencies: [ListAvailableWebhookEventsUseCase],\n resolver: (listEvents: ListAvailableWebhookEventsUseCase.Interface) => {\n return async () => {\n const result = await listEvents.execute();\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebhookEventSchema = GraphQLSchemaFactory.createImplementation({\n implementation: WebhookEventSchema_,\n dependencies: []\n});\n"],"names":["WebhookEventSchema_","builder","ListAvailableWebhookEventsUseCase","listEvents","result","ErrorResponse","Response","WebhookEventSchema","GraphQLSchemaFactory"],"mappings":";;;AAKA,MAAMA;IACF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC
|
|
1
|
+
{"version":3,"file":"api/graphql/WebhookEventSchema.js","sources":["../../../src/api/graphql/WebhookEventSchema.ts"],"sourcesContent":["import { GraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.js\";\nimport { Response } from \"@webiny/handler-graphql\";\nimport { ErrorResponse } from \"@webiny/handler-graphql\";\nimport { ListAvailableWebhookEventsUseCase } from \"~/api/features/ListAvailableWebhookEvents/abstractions.js\";\n\nclass WebhookEventSchema_ implements GraphQLSchemaFactory.Interface {\n async execute(\n builder: GraphQLSchemaFactory.SchemaBuilder\n ): Promise<GraphQLSchemaFactory.SchemaBuilder> {\n builder.addTypeDefs(/* GraphQL */ `\n type WebhookEvent {\n app: String!\n appLabel: String!\n entity: String!\n eventName: String!\n label: String!\n }\n\n type WebhookEventListResponse {\n data: [WebhookEvent!]\n error: WebhookError\n }\n\n extend type WebhookQuery {\n listAvailableWebhookEvents: WebhookEventListResponse!\n }\n `);\n\n builder.addResolver({\n path: \"WebhookQuery.listAvailableWebhookEvents\",\n dependencies: [ListAvailableWebhookEventsUseCase],\n resolver: (listEvents: ListAvailableWebhookEventsUseCase.Interface) => {\n return async () => {\n const result = await listEvents.execute();\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n return new Response(result.value);\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebhookEventSchema = GraphQLSchemaFactory.createImplementation({\n implementation: WebhookEventSchema_,\n dependencies: []\n});\n"],"names":["WebhookEventSchema_","builder","ListAvailableWebhookEventsUseCase","listEvents","result","ErrorResponse","Response","WebhookEventSchema","GraphQLSchemaFactory"],"mappings":";;;AAKA,MAAMA;IACF,MAAM,QACFC,OAA2C,EACA;QAC3CA,QAAQ,WAAW,CAAe,CAAC;;;;;;;;;;;;;;;;;QAiBnC,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc;gBAACC;aAAkC;YACjD,UAAU,CAACC,aACA;oBACH,MAAMC,SAAS,MAAMD,WAAW,OAAO;oBACvC,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;oBAEzC,OAAO,IAAIE,SAASF,OAAO,KAAK;gBACpC;QAER;QAEA,OAAOH;IACX;AACJ;AAEO,MAAMM,qBAAqBC,qBAAqB,oBAAoB,CAAC;IACxE,gBAAgBR;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GraphQLSchemaFactory } from "@webiny/handler-graphql/graphql/abstractions.js";
|
|
2
|
+
declare class WebhookSettingsSchema_ implements GraphQLSchemaFactory.Interface {
|
|
3
|
+
execute(builder: GraphQLSchemaFactory.SchemaBuilder): Promise<GraphQLSchemaFactory.SchemaBuilder>;
|
|
4
|
+
}
|
|
5
|
+
export declare const WebhookSettingsSchema: typeof WebhookSettingsSchema_ & {
|
|
6
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/handler-graphql/graphql/abstractions.public").IGraphQLSchemaFactory>;
|
|
7
|
+
};
|
|
8
|
+
export {};
|