@pinelab/vendure-plugin-webhook 1.3.0 → 1.4.1
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# 1.4.1 (2025-02-06)
|
|
2
|
+
|
|
3
|
+
- Log info message when event is ignored because transformer returned 'false'
|
|
4
|
+
|
|
5
|
+
# 1.4.0 (2025-02-06)
|
|
6
|
+
|
|
7
|
+
- Allow cancelling webhook by returning `false` in request transformers
|
|
8
|
+
- Fixed union type inference from events array in transformer
|
|
9
|
+
|
|
10
|
+
# 1.3.1 (2025-01-28)
|
|
11
|
+
|
|
12
|
+
- Correct UI label for actions dropdown
|
|
13
|
+
|
|
1
14
|
# 1.3.0 (2024-12-19)
|
|
2
15
|
|
|
3
16
|
- Update Vendure to 3.1.1
|
package/README.md
CHANGED
|
@@ -67,24 +67,20 @@ export const stringifyProductTransformer = new RequestTransformer({
|
|
|
67
67
|
name: 'Stringify Product events',
|
|
68
68
|
supportedEvents: [ProductEvent],
|
|
69
69
|
transform: (event, injector, webhook) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
event
|
|
75
|
-
|
|
76
|
-
ctx: undefined, // Remove ctx or use event.ctx.serialize()
|
|
77
|
-
},
|
|
78
|
-
}),
|
|
79
|
-
headers: {
|
|
80
|
-
authorization: 'Bearer MyToken',
|
|
81
|
-
'x-custom-header': 'custom-example-header',
|
|
82
|
-
'content-type': 'application/json',
|
|
70
|
+
return {
|
|
71
|
+
body: JSON.stringify({
|
|
72
|
+
type: webhook.event, // Name of the event ("ProductEvent")
|
|
73
|
+
event: {
|
|
74
|
+
...event,
|
|
75
|
+
ctx: undefined, // Remove ctx or use event.ctx.serialize()
|
|
83
76
|
},
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
}),
|
|
78
|
+
headers: {
|
|
79
|
+
authorization: 'Bearer MyToken',
|
|
80
|
+
'x-custom-header': 'custom-example-header',
|
|
81
|
+
'content-type': 'application/json',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
88
84
|
},
|
|
89
85
|
});
|
|
90
86
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Injector, RequestContext, Type, VendureEvent } from '@vendure/core';
|
|
2
2
|
import { Webhook } from './webhook.entity';
|
|
3
|
-
export type TransformFn<T extends EventWithContext> = (event: T, injector: Injector, webhook: Webhook) => WebhookRequest | Promise<WebhookRequest>;
|
|
3
|
+
export type TransformFn<T extends EventWithContext> = (event: T, injector: Injector, webhook: Webhook) => WebhookRequest | Promise<WebhookRequest> | false | Promise<false>;
|
|
4
4
|
export type EventWithContext = VendureEvent & {
|
|
5
5
|
ctx: RequestContext;
|
|
6
6
|
};
|
|
@@ -12,13 +12,17 @@ export declare class RequestTransformer<T extends Array<Type<EventWithContext>>>
|
|
|
12
12
|
private readonly options;
|
|
13
13
|
readonly name: string;
|
|
14
14
|
readonly supportedEvents: T;
|
|
15
|
-
readonly transform: TransformFn<
|
|
15
|
+
readonly transform: TransformFn<InstanceType<T[number]>>;
|
|
16
16
|
constructor(options: {
|
|
17
17
|
name: string;
|
|
18
18
|
/**
|
|
19
19
|
* The events that this transformer supports
|
|
20
20
|
*/
|
|
21
21
|
supportedEvents: T;
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Transform the body and/or headers for the webhook request.
|
|
24
|
+
* When returning `false`, the webhook will not be called.
|
|
25
|
+
*/
|
|
26
|
+
transform: TransformFn<InstanceType<T[number]>>;
|
|
23
27
|
});
|
|
24
28
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RequestTransformer = void 0;
|
|
4
|
+
const core_1 = require("@vendure/core");
|
|
4
5
|
class RequestTransformer {
|
|
5
6
|
constructor(options) {
|
|
6
7
|
this.options = options;
|
|
@@ -10,3 +11,11 @@ class RequestTransformer {
|
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
exports.RequestTransformer = RequestTransformer;
|
|
14
|
+
// This only exists to test TS type compilation for this plugin, because of the complex type inference above
|
|
15
|
+
new RequestTransformer({
|
|
16
|
+
name: 'Stringify Product events',
|
|
17
|
+
supportedEvents: [core_1.ProductEvent, core_1.ProductVariantEvent],
|
|
18
|
+
transform: (event, injector) => {
|
|
19
|
+
return {};
|
|
20
|
+
},
|
|
21
|
+
});
|
|
@@ -163,6 +163,11 @@ let WebhookService = class WebhookService {
|
|
|
163
163
|
throw Error(`Could not find transformer ${webhook.transformerName}`);
|
|
164
164
|
}
|
|
165
165
|
const request = await transformer.transform(event, new core_2.Injector(this.moduleRef), webhook);
|
|
166
|
+
if (request === false) {
|
|
167
|
+
// Don't call webhook if transformer returns false
|
|
168
|
+
core_2.Logger.info(`Ignoring event ${event.constructor.name} for channel ${webhook.channelId} because transformer "${webhook.transformerName}" returned false`, constants_1.loggerCtx);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
166
171
|
// Call the webhook with the constructed request
|
|
167
172
|
try {
|
|
168
173
|
await (0, node_fetch_1.default)(webhook.url, {
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
<td>
|
|
99
99
|
<vdr-dropdown>
|
|
100
100
|
<button type="button" class="btn btn-link btn-sm" vdrDropdownTrigger>
|
|
101
|
-
{{ '
|
|
101
|
+
{{ 'marketing.actions' | translate }}
|
|
102
102
|
<clr-icon shape="caret down"></clr-icon>
|
|
103
103
|
</button>
|
|
104
104
|
<vdr-dropdown-menu vdrPosition="bottom-right">
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
vdrDropdownItem
|
|
118
118
|
>
|
|
119
119
|
<clr-icon shape="copy"></clr-icon>
|
|
120
|
-
|
|
120
|
+
{{ 'common.duplicate' | translate }}
|
|
121
121
|
</button>
|
|
122
122
|
</vdr-dropdown-menu>
|
|
123
123
|
</vdr-dropdown>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinelab/vendure-plugin-webhook",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Call webhooks based on configured events from Vendure",
|
|
5
5
|
"author": "Martijn van de Brug <martijn@pinelab.studio>",
|
|
6
6
|
"homepage": "https://pinelab-plugins.com/",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"test": "vitest run",
|
|
24
24
|
"lint": "echo 'No linting configured'"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "70f5ad2f67926c28dc1179474c3973a61de4022b"
|
|
27
27
|
}
|