@pinelab/vendure-plugin-webhook 1.2.0 → 1.2.2
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 +9 -1
- package/README.md +9 -2
- package/dist/api/request-transformer.d.ts +2 -1
- package/dist/api/webhook.service.js +12 -7
- package/dist/ui/webhook.component.html +121 -113
- package/dist/webhook.plugin.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
# 1.2.
|
|
1
|
+
# 1.2.2 (2024-08-04)
|
|
2
|
+
|
|
3
|
+
- Update compatibility range (#480)
|
|
4
|
+
|
|
5
|
+
# 1.2.1 (2024-06-26)
|
|
6
|
+
|
|
7
|
+
- Extended transformer function with webhook entity to make the event name accessible
|
|
8
|
+
|
|
9
|
+
# 1.2.0 (2024-06-21)
|
|
2
10
|
|
|
3
11
|
- Updated Vendure to 2.2.6
|
|
4
12
|
|
package/README.md
CHANGED
|
@@ -66,11 +66,18 @@ import { RequestTransformer } from '@pinelab/vendure-plugin-webhook';
|
|
|
66
66
|
export const stringifyProductTransformer = new RequestTransformer({
|
|
67
67
|
name: 'Stringify Product events',
|
|
68
68
|
supportedEvents: [ProductEvent],
|
|
69
|
-
transform: (event, injector) => {
|
|
69
|
+
transform: (event, injector, webhook) => {
|
|
70
70
|
if (event instanceof ProductEvent) {
|
|
71
71
|
return {
|
|
72
|
-
body: JSON.stringify(
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
type: webhook.event, // Name of the event ("ProductEvent")
|
|
74
|
+
event: {
|
|
75
|
+
...event,
|
|
76
|
+
ctx: undefined, // Remove ctx or use event.ctx.serialize()
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
73
79
|
headers: {
|
|
80
|
+
authorization: 'Bearer MyToken',
|
|
74
81
|
'x-custom-header': 'custom-example-header',
|
|
75
82
|
'content-type': 'application/json',
|
|
76
83
|
},
|
|
@@ -1,5 +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
4
|
export type EventWithContext = VendureEvent & {
|
|
4
5
|
ctx: RequestContext;
|
|
5
6
|
};
|
|
@@ -162,14 +162,19 @@ let WebhookService = class WebhookService {
|
|
|
162
162
|
if (!transformer) {
|
|
163
163
|
throw Error(`Could not find transformer ${webhook.transformerName}`);
|
|
164
164
|
}
|
|
165
|
-
const request = await transformer.transform(event, new core_2.Injector(this.moduleRef));
|
|
165
|
+
const request = await transformer.transform(event, new core_2.Injector(this.moduleRef), webhook);
|
|
166
166
|
// Call the webhook with the constructed request
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
try {
|
|
168
|
+
await (0, node_fetch_1.default)(webhook.url, {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers: request.headers,
|
|
171
|
+
body: request.body,
|
|
172
|
+
});
|
|
173
|
+
core_2.Logger.info(`Successfully triggered webhook for event ${event.constructor.name} for channel ${webhook.channelId} with transformer "${webhook.transformerName}"`, constants_1.loggerCtx);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
core_2.Logger.error(`Failed to call webhook for event ${webhook.event} channel ${webhook.channelId}: ${error}`, constants_1.loggerCtx);
|
|
177
|
+
}
|
|
173
178
|
}
|
|
174
179
|
};
|
|
175
180
|
exports.WebhookService = WebhookService;
|
|
@@ -1,119 +1,127 @@
|
|
|
1
|
-
<vdr-
|
|
2
|
-
<vdr-
|
|
3
|
-
<vdr-
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
</vdr-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
<
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<option
|
|
26
|
-
*ngFor="
|
|
27
|
-
let transformers of avaiabelWebhookRequestTransformers
|
|
28
|
-
"
|
|
29
|
-
[value]="transformers.name"
|
|
30
|
-
>
|
|
31
|
-
{{ transformers.name }}
|
|
32
|
-
</option>
|
|
33
|
-
</select>
|
|
34
|
-
</li>
|
|
35
|
-
<li class="list-group-item">
|
|
36
|
-
<h4 class="card-title">Event *</h4>
|
|
37
|
-
<select clrSelect [(ngModel)]="eventName">
|
|
38
|
-
<option value="{{ undefined }}">--select---</option>
|
|
39
|
-
<option
|
|
40
|
-
*ngFor="let event of filteredWeebhookEvents"
|
|
41
|
-
[value]="event"
|
|
1
|
+
<vdr-page-block>
|
|
2
|
+
<vdr-action-bar>
|
|
3
|
+
<vdr-ab-right>
|
|
4
|
+
<vdr-action-bar-items locationId="collection-list"></vdr-action-bar-items>
|
|
5
|
+
<button class="btn btn-primary" (click)="showCreateModal()">
|
|
6
|
+
<clr-icon shape="add"></clr-icon>
|
|
7
|
+
Add Webhook
|
|
8
|
+
</button>
|
|
9
|
+
</vdr-ab-right>
|
|
10
|
+
</vdr-action-bar>
|
|
11
|
+
|
|
12
|
+
<clr-modal [(clrModalOpen)]="showMessage">
|
|
13
|
+
<h3 class="modal-title">Add Webhook</h3>
|
|
14
|
+
<div class="modal-body">
|
|
15
|
+
<div class="popupContainer">
|
|
16
|
+
<div class="card">
|
|
17
|
+
<div style="width: 100%">
|
|
18
|
+
<ul class="list-group list-group-flush">
|
|
19
|
+
<li class="list-group-item">
|
|
20
|
+
<h4 class="card-title">Request Transformer</h4>
|
|
21
|
+
<select
|
|
22
|
+
clrSelect
|
|
23
|
+
[(ngModel)]="requestTransformerName"
|
|
24
|
+
(ngModelChange)="requestTransformerSelected()"
|
|
42
25
|
>
|
|
43
|
-
{{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
26
|
+
<option value="{{ undefined }}">--select---</option>
|
|
27
|
+
<option
|
|
28
|
+
*ngFor="
|
|
29
|
+
let transformers of avaiabelWebhookRequestTransformers
|
|
30
|
+
"
|
|
31
|
+
[value]="transformers.name"
|
|
32
|
+
>
|
|
33
|
+
{{ transformers.name }}
|
|
34
|
+
</option>
|
|
35
|
+
</select>
|
|
36
|
+
</li>
|
|
37
|
+
<li class="list-group-item">
|
|
38
|
+
<h4 class="card-title">Event *</h4>
|
|
39
|
+
<select clrSelect [(ngModel)]="eventName">
|
|
40
|
+
<option value="{{ undefined }}">--select---</option>
|
|
41
|
+
<option
|
|
42
|
+
*ngFor="let event of filteredWeebhookEvents"
|
|
43
|
+
[value]="event"
|
|
44
|
+
>
|
|
45
|
+
{{ event }}
|
|
46
|
+
</option>
|
|
47
|
+
</select>
|
|
48
|
+
</li>
|
|
49
|
+
<li class="list-group-item">
|
|
50
|
+
<h4 class="card-title">URL *</h4>
|
|
51
|
+
<input
|
|
52
|
+
clrInput
|
|
53
|
+
placeholder="https://"
|
|
54
|
+
name="input"
|
|
55
|
+
[(ngModel)]="url"
|
|
56
|
+
/>
|
|
57
|
+
</li>
|
|
58
|
+
</ul>
|
|
59
|
+
</div>
|
|
57
60
|
</div>
|
|
58
61
|
</div>
|
|
59
62
|
</div>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
</
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
[totalItems]="webhooks.length"
|
|
72
|
-
[currentPage]="currentPage"
|
|
73
|
-
(pageChange)="setPageNumber($event)"
|
|
74
|
-
(itemsPerPageChange)="setItemsPerPage($event)"
|
|
75
|
-
>
|
|
76
|
-
<vdr-dt-column>Event</vdr-dt-column>
|
|
77
|
-
<vdr-dt-column>Request Transformer</vdr-dt-column>
|
|
78
|
-
<vdr-dt-column>URL</vdr-dt-column>
|
|
79
|
-
<vdr-dt-column></vdr-dt-column>
|
|
63
|
+
<div class="modal-footer">
|
|
64
|
+
<button
|
|
65
|
+
type="button"
|
|
66
|
+
class="btn btn-outline"
|
|
67
|
+
(click)="showMessage = false"
|
|
68
|
+
>
|
|
69
|
+
Cancel
|
|
70
|
+
</button>
|
|
71
|
+
<button class="btn btn-primary" (click)="create()">Submit</button>
|
|
72
|
+
</div>
|
|
73
|
+
</clr-modal>
|
|
80
74
|
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
</
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
(click)="duplicate(webhook.requestTransformer?.name, webhook.url)"
|
|
110
|
-
vdrDropdownItem
|
|
111
|
-
>
|
|
112
|
-
<clr-icon shape="copy"></clr-icon>
|
|
113
|
-
Duplicate
|
|
75
|
+
<vdr-data-table
|
|
76
|
+
[items]="webhooks"
|
|
77
|
+
[itemsPerPage]="itemsPerPage"
|
|
78
|
+
[totalItems]="webhooks.length"
|
|
79
|
+
[currentPage]="currentPage"
|
|
80
|
+
(pageChange)="setPageNumber($event)"
|
|
81
|
+
(itemsPerPageChange)="setItemsPerPage($event)"
|
|
82
|
+
>
|
|
83
|
+
<vdr-dt-column>Event</vdr-dt-column>
|
|
84
|
+
<vdr-dt-column>Request Transformer</vdr-dt-column>
|
|
85
|
+
<vdr-dt-column>URL</vdr-dt-column>
|
|
86
|
+
<vdr-dt-column></vdr-dt-column>
|
|
87
|
+
|
|
88
|
+
<ng-template let-webhook="item">
|
|
89
|
+
<td class="left align-middle">
|
|
90
|
+
{{ webhook.event }}
|
|
91
|
+
</td>
|
|
92
|
+
<td class="left align-middle">
|
|
93
|
+
{{ webhook.requestTransformer?.name }}
|
|
94
|
+
</td>
|
|
95
|
+
<td class="left align-middle">
|
|
96
|
+
{{ webhook.url }}
|
|
97
|
+
</td>
|
|
98
|
+
<td>
|
|
99
|
+
<vdr-dropdown>
|
|
100
|
+
<button type="button" class="btn btn-link btn-sm" vdrDropdownTrigger>
|
|
101
|
+
{{ 'common.actions' | translate }}
|
|
102
|
+
<clr-icon shape="caret down"></clr-icon>
|
|
114
103
|
</button>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
104
|
+
<vdr-dropdown-menu vdrPosition="bottom-right">
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
class="delete-button"
|
|
108
|
+
(click)="deleteWeebhook(webhook.id)"
|
|
109
|
+
vdrDropdownItem
|
|
110
|
+
>
|
|
111
|
+
<clr-icon shape="trash" class="is-danger"></clr-icon>
|
|
112
|
+
{{ 'common.delete' | translate }}
|
|
113
|
+
</button>
|
|
114
|
+
<button
|
|
115
|
+
type="button"
|
|
116
|
+
(click)="duplicate(webhook.requestTransformer?.name, webhook.url)"
|
|
117
|
+
vdrDropdownItem
|
|
118
|
+
>
|
|
119
|
+
<clr-icon shape="copy"></clr-icon>
|
|
120
|
+
Duplicate
|
|
121
|
+
</button>
|
|
122
|
+
</vdr-dropdown-menu>
|
|
123
|
+
</vdr-dropdown>
|
|
124
|
+
</td>
|
|
125
|
+
</ng-template>
|
|
126
|
+
</vdr-data-table>
|
|
127
|
+
</vdr-page-block>
|
package/dist/webhook.plugin.js
CHANGED
|
@@ -68,6 +68,6 @@ exports.WebhookPlugin = WebhookPlugin = WebhookPlugin_1 = __decorate([
|
|
|
68
68
|
config.authOptions.customPermissions.push(webhook_resolver_1.webhookPermission);
|
|
69
69
|
return config;
|
|
70
70
|
},
|
|
71
|
-
compatibility: '
|
|
71
|
+
compatibility: '>=2.2.0',
|
|
72
72
|
})
|
|
73
73
|
], WebhookPlugin);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinelab/vendure-plugin-webhook",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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": "2414f11eb04b280eea1a2c937a96dbf3696195dc"
|
|
27
27
|
}
|