@pinelab/vendure-plugin-webhook 0.0.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.
@@ -0,0 +1,34 @@
1
+ import { Type } from '@vendure/core';
2
+ import { AdminUiExtension } from '@vendure/ui-devkit/compiler';
3
+ import { EventWithContext, RequestTransformer } from './api/request-transformer';
4
+ export interface WebhookPluginOptions {
5
+ /**
6
+ * The plugin will listen to these events and call the corresponding webhooks
7
+ */
8
+ events: Type<EventWithContext>[];
9
+ /**
10
+ * A list of available transformers to create custom body and headers for webhook requests
11
+ */
12
+ requestTransformers?: Array<RequestTransformer<Type<EventWithContext>[]>>;
13
+ /**
14
+ * Wait for more of the same events before calling webhook, and only call the configured webhook once.
15
+ * E.g: With `delay: 100` only 1 call to your webhook will be done,
16
+ * even if 10 of the same events are fired within 100ms.
17
+ *
18
+ * Delay is in ms
19
+ */
20
+ delay?: number;
21
+ /**
22
+ * Disable the plugin. Default is false
23
+ */
24
+ disabled?: boolean;
25
+ }
26
+ /**
27
+ * Calls a configurable webhook when configured events arise.
28
+ * 1 webhook per channel is configurable
29
+ */
30
+ export declare class WebhookPlugin {
31
+ static options: WebhookPluginOptions;
32
+ static init(options: WebhookPluginOptions): typeof WebhookPlugin;
33
+ static ui: AdminUiExtension;
34
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ var WebhookPlugin_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.WebhookPlugin = void 0;
14
+ const core_1 = require("@vendure/core");
15
+ const path_1 = __importDefault(require("path"));
16
+ const api_extension_1 = require("./api/api-extension");
17
+ const webhook_resolver_1 = require("./api/webhook.resolver");
18
+ const webhook_service_1 = require("./api/webhook.service");
19
+ const constants_1 = require("./constants");
20
+ const webhook_entity_1 = require("./api/webhook.entity");
21
+ /**
22
+ * Calls a configurable webhook when configured events arise.
23
+ * 1 webhook per channel is configurable
24
+ */
25
+ let WebhookPlugin = WebhookPlugin_1 = class WebhookPlugin {
26
+ static init(options) {
27
+ this.options = {
28
+ ...this.options,
29
+ ...options,
30
+ };
31
+ return WebhookPlugin_1;
32
+ }
33
+ };
34
+ WebhookPlugin.options = {
35
+ events: [],
36
+ delay: 0,
37
+ };
38
+ WebhookPlugin.ui = {
39
+ extensionPath: path_1.default.join(__dirname, 'ui'),
40
+ ngModules: [
41
+ {
42
+ type: 'lazy',
43
+ route: 'webhook',
44
+ ngModuleFileName: 'webhook.module.ts',
45
+ ngModuleName: 'WebhookModule',
46
+ },
47
+ {
48
+ type: 'shared',
49
+ ngModuleFileName: 'webhook-nav.module.ts',
50
+ ngModuleName: 'WebhookNavModule',
51
+ },
52
+ ],
53
+ };
54
+ WebhookPlugin = WebhookPlugin_1 = __decorate([
55
+ (0, core_1.VendurePlugin)({
56
+ imports: [core_1.PluginCommonModule],
57
+ entities: [webhook_entity_1.Webhook],
58
+ providers: [
59
+ webhook_service_1.WebhookService,
60
+ { provide: constants_1.PLUGIN_INIT_OPTIONS, useFactory: () => WebhookPlugin_1.options },
61
+ ],
62
+ adminApiExtensions: {
63
+ schema: api_extension_1.adminSchema,
64
+ resolvers: [webhook_resolver_1.WebhookResolver, webhook_resolver_1.WebhookRequestTransformerResolver],
65
+ },
66
+ configuration: (config) => {
67
+ config.authOptions.customPermissions.push(webhook_resolver_1.webhookPermission);
68
+ return config;
69
+ },
70
+ compatibility: '^2.0.0',
71
+ })
72
+ ], WebhookPlugin);
73
+ exports.WebhookPlugin = WebhookPlugin;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@pinelab/vendure-plugin-webhook",
3
+ "version": "0.0.3",
4
+ "description": "Call webhooks based on configured events from Vendure",
5
+ "author": "Martijn van de Brug <martijn@pinelab.studio>",
6
+ "homepage": "https://pinelab-plugins.com/",
7
+ "repository": "https://github.com/Pinelab-studio/pinelab-vendure-plugins",
8
+ "license": "MIT",
9
+ "private": false,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "yarn graphql-codegen && rimraf dist && tsc && copyfiles -u 1 'src/ui/**/*' dist/",
21
+ "start": "yarn ts-node test/dev-server.ts",
22
+ "test": "vitest run"
23
+ },
24
+ "devDependencies": {
25
+ "@graphql-codegen/cli": "^3.3.1",
26
+ "@graphql-codegen/typescript": "^3.0.4",
27
+ "@graphql-codegen/typescript-document-nodes": "^3.0.4",
28
+ "@graphql-codegen/typescript-operations": "^3.0.4",
29
+ "@swc/core": "^1.3.61",
30
+ "@vendure/admin-ui-plugin": "2.0.4",
31
+ "@vendure/core": "2.0.4",
32
+ "@vendure/testing": "2.0.4",
33
+ "@vendure/ui-devkit": "2.0.4",
34
+ "copyfiles": "^2.4.1",
35
+ "nock": "^13.2.9",
36
+ "rimraf": "^3.0.2",
37
+ "ts-node": "^10.7.0",
38
+ "typescript": "4.9.5",
39
+ "unplugin-swc": "^1.3.2",
40
+ "vitest": "^0.31.1"
41
+ },
42
+ "gitHead": "5673faf91c029dc4716226965ce3531931b434b6"
43
+ }