@pinelab/vendure-plugin-webhook 1.1.1 → 1.2.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 +8 -0
- package/README.md +3 -2
- package/dist/api/request-transformer.d.ts +2 -1
- package/dist/api/webhook.entity.js +2 -2
- package/dist/api/webhook.resolver.js +6 -6
- package/dist/api/webhook.service.js +14 -9
- package/dist/ui/webhook.component.html +121 -113
- package/dist/webhook.plugin.js +3 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -66,11 +66,12 @@ 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(event),
|
|
72
|
+
body: JSON.stringify({ event: webhook.event, ...event }), // Pass the event name to the body
|
|
73
73
|
headers: {
|
|
74
|
+
authorization: 'Bearer MyToken',
|
|
74
75
|
'x-custom-header': 'custom-example-header',
|
|
75
76
|
'content-type': 'application/json',
|
|
76
77
|
},
|
|
@@ -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
|
};
|
|
@@ -21,6 +21,7 @@ let Webhook = class Webhook extends core_1.VendureEntity {
|
|
|
21
21
|
super(input);
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
+
exports.Webhook = Webhook;
|
|
24
25
|
__decorate([
|
|
25
26
|
(0, typeorm_1.Column)(),
|
|
26
27
|
__metadata("design:type", String)
|
|
@@ -37,8 +38,7 @@ __decorate([
|
|
|
37
38
|
(0, typeorm_1.Column)({ nullable: true }),
|
|
38
39
|
__metadata("design:type", String)
|
|
39
40
|
], Webhook.prototype, "transformerName", void 0);
|
|
40
|
-
Webhook = __decorate([
|
|
41
|
+
exports.Webhook = Webhook = __decorate([
|
|
41
42
|
(0, typeorm_1.Entity)(),
|
|
42
43
|
__metadata("design:paramtypes", [Object])
|
|
43
44
|
], Webhook);
|
|
44
|
-
exports.Webhook = Webhook;
|
|
@@ -12,7 +12,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.WebhookRequestTransformerResolver = exports.WebhookResolver = exports.webhookPermission = void 0;
|
|
16
|
+
exports.mapToGraphqlTransformer = mapToGraphqlTransformer;
|
|
16
17
|
const graphql_1 = require("@nestjs/graphql");
|
|
17
18
|
const core_1 = require("@vendure/core");
|
|
18
19
|
const webhook_service_1 = require("./webhook.service");
|
|
@@ -43,6 +44,7 @@ let WebhookResolver = class WebhookResolver {
|
|
|
43
44
|
return transformers.map(mapToGraphqlTransformer);
|
|
44
45
|
}
|
|
45
46
|
};
|
|
47
|
+
exports.WebhookResolver = WebhookResolver;
|
|
46
48
|
__decorate([
|
|
47
49
|
(0, graphql_1.Mutation)(),
|
|
48
50
|
(0, core_1.Allow)(exports.webhookPermission.Permission),
|
|
@@ -74,11 +76,10 @@ __decorate([
|
|
|
74
76
|
__metadata("design:paramtypes", []),
|
|
75
77
|
__metadata("design:returntype", Promise)
|
|
76
78
|
], WebhookResolver.prototype, "availableWebhookRequestTransformers", null);
|
|
77
|
-
WebhookResolver = __decorate([
|
|
79
|
+
exports.WebhookResolver = WebhookResolver = __decorate([
|
|
78
80
|
(0, graphql_1.Resolver)(),
|
|
79
81
|
__metadata("design:paramtypes", [webhook_service_1.WebhookService])
|
|
80
82
|
], WebhookResolver);
|
|
81
|
-
exports.WebhookResolver = WebhookResolver;
|
|
82
83
|
let WebhookRequestTransformerResolver = class WebhookRequestTransformerResolver {
|
|
83
84
|
constructor(webhookService) {
|
|
84
85
|
this.webhookService = webhookService;
|
|
@@ -98,6 +99,7 @@ let WebhookRequestTransformerResolver = class WebhookRequestTransformerResolver
|
|
|
98
99
|
return mapToGraphqlTransformer(transformer);
|
|
99
100
|
}
|
|
100
101
|
};
|
|
102
|
+
exports.WebhookRequestTransformerResolver = WebhookRequestTransformerResolver;
|
|
101
103
|
__decorate([
|
|
102
104
|
(0, graphql_1.ResolveField)(),
|
|
103
105
|
__param(0, (0, core_1.Ctx)()),
|
|
@@ -107,15 +109,13 @@ __decorate([
|
|
|
107
109
|
webhook_entity_1.Webhook]),
|
|
108
110
|
__metadata("design:returntype", Promise)
|
|
109
111
|
], WebhookRequestTransformerResolver.prototype, "requestTransformer", null);
|
|
110
|
-
WebhookRequestTransformerResolver = __decorate([
|
|
112
|
+
exports.WebhookRequestTransformerResolver = WebhookRequestTransformerResolver = __decorate([
|
|
111
113
|
(0, graphql_1.Resolver)('Webhook'),
|
|
112
114
|
__metadata("design:paramtypes", [webhook_service_1.WebhookService])
|
|
113
115
|
], WebhookRequestTransformerResolver);
|
|
114
|
-
exports.WebhookRequestTransformerResolver = WebhookRequestTransformerResolver;
|
|
115
116
|
function mapToGraphqlTransformer(transformer) {
|
|
116
117
|
return {
|
|
117
118
|
name: transformer.name,
|
|
118
119
|
supportedEvents: transformer.supportedEvents.map((event) => event.name),
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
exports.mapToGraphqlTransformer = mapToGraphqlTransformer;
|
|
@@ -162,21 +162,26 @@ 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
|
-
WebhookService =
|
|
180
|
+
exports.WebhookService = WebhookService;
|
|
181
|
+
exports.WebhookService = WebhookService = __decorate([
|
|
176
182
|
(0, common_1.Injectable)(),
|
|
177
183
|
__param(3, (0, common_1.Inject)(constants_1.PLUGIN_INIT_OPTIONS)),
|
|
178
184
|
__metadata("design:paramtypes", [core_2.EventBus,
|
|
179
185
|
core_2.TransactionalConnection,
|
|
180
186
|
core_1.ModuleRef, Object])
|
|
181
187
|
], WebhookService);
|
|
182
|
-
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
|
@@ -31,6 +31,7 @@ let WebhookPlugin = WebhookPlugin_1 = class WebhookPlugin {
|
|
|
31
31
|
return WebhookPlugin_1;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
+
exports.WebhookPlugin = WebhookPlugin;
|
|
34
35
|
WebhookPlugin.options = {
|
|
35
36
|
events: [],
|
|
36
37
|
delay: 0,
|
|
@@ -51,13 +52,13 @@ WebhookPlugin.ui = {
|
|
|
51
52
|
},
|
|
52
53
|
],
|
|
53
54
|
};
|
|
54
|
-
WebhookPlugin = WebhookPlugin_1 = __decorate([
|
|
55
|
+
exports.WebhookPlugin = WebhookPlugin = WebhookPlugin_1 = __decorate([
|
|
55
56
|
(0, core_1.VendurePlugin)({
|
|
56
57
|
imports: [core_1.PluginCommonModule],
|
|
57
58
|
entities: [webhook_entity_1.Webhook],
|
|
58
59
|
providers: [
|
|
59
60
|
webhook_service_1.WebhookService,
|
|
60
|
-
{ provide: constants_1.PLUGIN_INIT_OPTIONS, useFactory: () =>
|
|
61
|
+
{ provide: constants_1.PLUGIN_INIT_OPTIONS, useFactory: () => WebhookPlugin.options },
|
|
61
62
|
],
|
|
62
63
|
adminApiExtensions: {
|
|
63
64
|
schema: api_extension_1.adminSchema,
|
|
@@ -70,4 +71,3 @@ WebhookPlugin = WebhookPlugin_1 = __decorate([
|
|
|
70
71
|
compatibility: '^2.0.0',
|
|
71
72
|
})
|
|
72
73
|
], WebhookPlugin);
|
|
73
|
-
exports.WebhookPlugin = WebhookPlugin;
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinelab/vendure-plugin-webhook",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Call webhooks based on configured events from Vendure",
|
|
5
|
-
"icon": "hook",
|
|
6
5
|
"author": "Martijn van de Brug <martijn@pinelab.studio>",
|
|
7
6
|
"homepage": "https://pinelab-plugins.com/",
|
|
8
7
|
"repository": "https://github.com/Pinelab-studio/pinelab-vendure-plugins",
|
|
@@ -21,7 +20,8 @@
|
|
|
21
20
|
"scripts": {
|
|
22
21
|
"build": "yarn graphql-codegen && rimraf dist && tsc && copyfiles -u 1 'src/ui/**/*' dist/",
|
|
23
22
|
"start": "yarn ts-node test/dev-server.ts",
|
|
24
|
-
"test": "vitest run"
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"lint": "echo 'No linting configured'"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "89ac3a3a6e1d156b43cd5d65a01ee057bd2ee43a"
|
|
27
27
|
}
|