@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.
- package/README.md +90 -0
- package/dist/api/api-extension.d.ts +1 -0
- package/dist/api/api-extension.js +49 -0
- package/dist/api/request-transformer.d.ts +23 -0
- package/dist/api/request-transformer.js +12 -0
- package/dist/api/webhook.entity.d.ts +12 -0
- package/dist/api/webhook.entity.js +44 -0
- package/dist/api/webhook.resolver.d.ts +26 -0
- package/dist/api/webhook.resolver.js +121 -0
- package/dist/api/webhook.service.d.ts +61 -0
- package/dist/api/webhook.service.js +182 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +5 -0
- package/dist/generated/graphql-types.d.ts +114 -0
- package/dist/generated/graphql-types.js +46 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/ui/graphql-types.ts +121 -0
- package/dist/ui/queries.ts +44 -0
- package/dist/ui/webhook-nav.module.ts +22 -0
- package/dist/ui/webhook.component.html +119 -0
- package/dist/ui/webhook.component.ts +157 -0
- package/dist/ui/webhook.module.ts +31 -0
- package/dist/webhook.plugin.d.ts +34 -0
- package/dist/webhook.plugin.js +73 -0
- package/package.json +43 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export type Maybe<T> = T | null;
|
|
2
|
+
export type InputMaybe<T> = Maybe<T>;
|
|
3
|
+
export type Exact<T extends {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}> = {
|
|
6
|
+
[K in keyof T]: T[K];
|
|
7
|
+
};
|
|
8
|
+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
9
|
+
[SubKey in K]?: Maybe<T[SubKey]>;
|
|
10
|
+
};
|
|
11
|
+
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
12
|
+
[SubKey in K]: Maybe<T[SubKey]>;
|
|
13
|
+
};
|
|
14
|
+
/** All built-in and custom scalars, mapped to their actual values */
|
|
15
|
+
export type Scalars = {
|
|
16
|
+
ID: number | string;
|
|
17
|
+
String: string;
|
|
18
|
+
Boolean: boolean;
|
|
19
|
+
Int: number;
|
|
20
|
+
Float: number;
|
|
21
|
+
};
|
|
22
|
+
export type Mutation = {
|
|
23
|
+
__typename?: 'Mutation';
|
|
24
|
+
/** Set all webhooks for the current channel. This will overwrite any existing webhooks. */
|
|
25
|
+
setWebhooks: Array<Webhook>;
|
|
26
|
+
};
|
|
27
|
+
export type MutationSetWebhooksArgs = {
|
|
28
|
+
webhooks: Array<WebhookInput>;
|
|
29
|
+
};
|
|
30
|
+
export type Query = {
|
|
31
|
+
__typename?: 'Query';
|
|
32
|
+
/** Get all available Vendure events that can be used to trigger webhooks */
|
|
33
|
+
availableWebhookEvents: Array<Scalars['String']>;
|
|
34
|
+
/**
|
|
35
|
+
* "
|
|
36
|
+
* Get all available webhook request transformers
|
|
37
|
+
*/
|
|
38
|
+
availableWebhookRequestTransformers: Array<WebhookRequestTransformer>;
|
|
39
|
+
/** Get all webhooks for the current channel */
|
|
40
|
+
webhooks: Array<Webhook>;
|
|
41
|
+
};
|
|
42
|
+
export type Webhook = {
|
|
43
|
+
__typename?: 'Webhook';
|
|
44
|
+
event: Scalars['String'];
|
|
45
|
+
id: Scalars['ID'];
|
|
46
|
+
requestTransformer?: Maybe<WebhookRequestTransformer>;
|
|
47
|
+
url: Scalars['String'];
|
|
48
|
+
};
|
|
49
|
+
export type WebhookInput = {
|
|
50
|
+
event: Scalars['String'];
|
|
51
|
+
transformerName?: InputMaybe<Scalars['String']>;
|
|
52
|
+
url: Scalars['String'];
|
|
53
|
+
};
|
|
54
|
+
export type WebhookRequestTransformer = {
|
|
55
|
+
__typename?: 'WebhookRequestTransformer';
|
|
56
|
+
name: Scalars['String'];
|
|
57
|
+
supportedEvents: Array<Scalars['String']>;
|
|
58
|
+
};
|
|
59
|
+
export type SetWebhooksMutationVariables = Exact<{
|
|
60
|
+
webhooks: Array<WebhookInput> | WebhookInput;
|
|
61
|
+
}>;
|
|
62
|
+
export type SetWebhooksMutation = {
|
|
63
|
+
__typename?: 'Mutation';
|
|
64
|
+
setWebhooks: Array<{
|
|
65
|
+
__typename?: 'Webhook';
|
|
66
|
+
id: number | string;
|
|
67
|
+
event: string;
|
|
68
|
+
url: string;
|
|
69
|
+
requestTransformer?: {
|
|
70
|
+
__typename?: 'WebhookRequestTransformer';
|
|
71
|
+
name: string;
|
|
72
|
+
supportedEvents: Array<string>;
|
|
73
|
+
} | null;
|
|
74
|
+
}>;
|
|
75
|
+
};
|
|
76
|
+
export type WebhooksQueryVariables = Exact<{
|
|
77
|
+
[key: string]: never;
|
|
78
|
+
}>;
|
|
79
|
+
export type WebhooksQuery = {
|
|
80
|
+
__typename?: 'Query';
|
|
81
|
+
webhooks: Array<{
|
|
82
|
+
__typename?: 'Webhook';
|
|
83
|
+
id: number | string;
|
|
84
|
+
event: string;
|
|
85
|
+
url: string;
|
|
86
|
+
requestTransformer?: {
|
|
87
|
+
__typename?: 'WebhookRequestTransformer';
|
|
88
|
+
name: string;
|
|
89
|
+
supportedEvents: Array<string>;
|
|
90
|
+
} | null;
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
export type AvailableWebhookEventsQueryVariables = Exact<{
|
|
94
|
+
[key: string]: never;
|
|
95
|
+
}>;
|
|
96
|
+
export type AvailableWebhookEventsQuery = {
|
|
97
|
+
__typename?: 'Query';
|
|
98
|
+
availableWebhookEvents: Array<string>;
|
|
99
|
+
};
|
|
100
|
+
export type AvailableWebhookRequestTransformersQueryVariables = Exact<{
|
|
101
|
+
[key: string]: never;
|
|
102
|
+
}>;
|
|
103
|
+
export type AvailableWebhookRequestTransformersQuery = {
|
|
104
|
+
__typename?: 'Query';
|
|
105
|
+
availableWebhookRequestTransformers: Array<{
|
|
106
|
+
__typename?: 'WebhookRequestTransformer';
|
|
107
|
+
name: string;
|
|
108
|
+
supportedEvents: Array<string>;
|
|
109
|
+
}>;
|
|
110
|
+
};
|
|
111
|
+
export declare const SetWebhooks: import("graphql").DocumentNode;
|
|
112
|
+
export declare const Webhooks: import("graphql").DocumentNode;
|
|
113
|
+
export declare const AvailableWebhookEvents: import("graphql").DocumentNode;
|
|
114
|
+
export declare const AvailableWebhookRequestTransformers: import("graphql").DocumentNode;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AvailableWebhookRequestTransformers = exports.AvailableWebhookEvents = exports.Webhooks = exports.SetWebhooks = void 0;
|
|
7
|
+
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
8
|
+
exports.SetWebhooks = (0, graphql_tag_1.default) `
|
|
9
|
+
mutation setWebhooks($webhooks: [WebhookInput!]!) {
|
|
10
|
+
setWebhooks(webhooks: $webhooks) {
|
|
11
|
+
id
|
|
12
|
+
event
|
|
13
|
+
requestTransformer {
|
|
14
|
+
name
|
|
15
|
+
supportedEvents
|
|
16
|
+
}
|
|
17
|
+
url
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
exports.Webhooks = (0, graphql_tag_1.default) `
|
|
22
|
+
query webhooks {
|
|
23
|
+
webhooks {
|
|
24
|
+
id
|
|
25
|
+
event
|
|
26
|
+
requestTransformer {
|
|
27
|
+
name
|
|
28
|
+
supportedEvents
|
|
29
|
+
}
|
|
30
|
+
url
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
exports.AvailableWebhookEvents = (0, graphql_tag_1.default) `
|
|
35
|
+
query availableWebhookEvents {
|
|
36
|
+
availableWebhookEvents
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
exports.AvailableWebhookRequestTransformers = (0, graphql_tag_1.default) `
|
|
40
|
+
query availableWebhookRequestTransformers {
|
|
41
|
+
availableWebhookRequestTransformers {
|
|
42
|
+
name
|
|
43
|
+
supportedEvents
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './webhook.plugin';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./webhook.plugin"), exports);
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import gql from 'graphql-tag';
|
|
2
|
+
export type Maybe<T> = T | null;
|
|
3
|
+
export type InputMaybe<T> = Maybe<T>;
|
|
4
|
+
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
|
|
5
|
+
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
|
|
6
|
+
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
|
|
7
|
+
/** All built-in and custom scalars, mapped to their actual values */
|
|
8
|
+
export type Scalars = {
|
|
9
|
+
ID: number | string;
|
|
10
|
+
String: string;
|
|
11
|
+
Boolean: boolean;
|
|
12
|
+
Int: number;
|
|
13
|
+
Float: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type Mutation = {
|
|
17
|
+
__typename?: 'Mutation';
|
|
18
|
+
/** Set all webhooks for the current channel. This will overwrite any existing webhooks. */
|
|
19
|
+
setWebhooks: Array<Webhook>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export type MutationSetWebhooksArgs = {
|
|
24
|
+
webhooks: Array<WebhookInput>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type Query = {
|
|
28
|
+
__typename?: 'Query';
|
|
29
|
+
/** Get all available Vendure events that can be used to trigger webhooks */
|
|
30
|
+
availableWebhookEvents: Array<Scalars['String']>;
|
|
31
|
+
/**
|
|
32
|
+
* "
|
|
33
|
+
* Get all available webhook request transformers
|
|
34
|
+
*/
|
|
35
|
+
availableWebhookRequestTransformers: Array<WebhookRequestTransformer>;
|
|
36
|
+
/** Get all webhooks for the current channel */
|
|
37
|
+
webhooks: Array<Webhook>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type Webhook = {
|
|
41
|
+
__typename?: 'Webhook';
|
|
42
|
+
event: Scalars['String'];
|
|
43
|
+
id: Scalars['ID'];
|
|
44
|
+
requestTransformer?: Maybe<WebhookRequestTransformer>;
|
|
45
|
+
url: Scalars['String'];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type WebhookInput = {
|
|
49
|
+
event: Scalars['String'];
|
|
50
|
+
transformerName?: InputMaybe<Scalars['String']>;
|
|
51
|
+
url: Scalars['String'];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type WebhookRequestTransformer = {
|
|
55
|
+
__typename?: 'WebhookRequestTransformer';
|
|
56
|
+
name: Scalars['String'];
|
|
57
|
+
supportedEvents: Array<Scalars['String']>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type SetWebhooksMutationVariables = Exact<{
|
|
61
|
+
webhooks: Array<WebhookInput> | WebhookInput;
|
|
62
|
+
}>;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
export type SetWebhooksMutation = { __typename?: 'Mutation', setWebhooks: Array<{ __typename?: 'Webhook', id: number | string, event: string, url: string, requestTransformer?: { __typename?: 'WebhookRequestTransformer', name: string, supportedEvents: Array<string> } | null }> };
|
|
66
|
+
|
|
67
|
+
export type WebhooksQueryVariables = Exact<{ [key: string]: never; }>;
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export type WebhooksQuery = { __typename?: 'Query', webhooks: Array<{ __typename?: 'Webhook', id: number | string, event: string, url: string, requestTransformer?: { __typename?: 'WebhookRequestTransformer', name: string, supportedEvents: Array<string> } | null }> };
|
|
71
|
+
|
|
72
|
+
export type AvailableWebhookEventsQueryVariables = Exact<{ [key: string]: never; }>;
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export type AvailableWebhookEventsQuery = { __typename?: 'Query', availableWebhookEvents: Array<string> };
|
|
76
|
+
|
|
77
|
+
export type AvailableWebhookRequestTransformersQueryVariables = Exact<{ [key: string]: never; }>;
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
export type AvailableWebhookRequestTransformersQuery = { __typename?: 'Query', availableWebhookRequestTransformers: Array<{ __typename?: 'WebhookRequestTransformer', name: string, supportedEvents: Array<string> }> };
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export const SetWebhooks = gql`
|
|
84
|
+
mutation setWebhooks($webhooks: [WebhookInput!]!) {
|
|
85
|
+
setWebhooks(webhooks: $webhooks) {
|
|
86
|
+
id
|
|
87
|
+
event
|
|
88
|
+
requestTransformer {
|
|
89
|
+
name
|
|
90
|
+
supportedEvents
|
|
91
|
+
}
|
|
92
|
+
url
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
export const Webhooks = gql`
|
|
97
|
+
query webhooks {
|
|
98
|
+
webhooks {
|
|
99
|
+
id
|
|
100
|
+
event
|
|
101
|
+
requestTransformer {
|
|
102
|
+
name
|
|
103
|
+
supportedEvents
|
|
104
|
+
}
|
|
105
|
+
url
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
export const AvailableWebhookEvents = gql`
|
|
110
|
+
query availableWebhookEvents {
|
|
111
|
+
availableWebhookEvents
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
export const AvailableWebhookRequestTransformers = gql`
|
|
115
|
+
query availableWebhookRequestTransformers {
|
|
116
|
+
availableWebhookRequestTransformers {
|
|
117
|
+
name
|
|
118
|
+
supportedEvents
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import gql from 'graphql-tag';
|
|
2
|
+
|
|
3
|
+
export const setWebhooksMutation = gql`
|
|
4
|
+
mutation setWebhooks($webhooks: [WebhookInput!]!) {
|
|
5
|
+
setWebhooks(webhooks: $webhooks) {
|
|
6
|
+
id
|
|
7
|
+
event
|
|
8
|
+
requestTransformer {
|
|
9
|
+
name
|
|
10
|
+
supportedEvents
|
|
11
|
+
}
|
|
12
|
+
url
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const getWebhooksQuery = gql`
|
|
18
|
+
query webhooks {
|
|
19
|
+
webhooks {
|
|
20
|
+
id
|
|
21
|
+
event
|
|
22
|
+
requestTransformer {
|
|
23
|
+
name
|
|
24
|
+
supportedEvents
|
|
25
|
+
}
|
|
26
|
+
url
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
export const getAvailableWebhookEventsQuery = gql`
|
|
32
|
+
query availableWebhookEvents {
|
|
33
|
+
availableWebhookEvents
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const getAvailableWebhookRequestTransformersQuery = gql`
|
|
38
|
+
query availableWebhookRequestTransformers {
|
|
39
|
+
availableWebhookRequestTransformers {
|
|
40
|
+
name
|
|
41
|
+
supportedEvents
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { addNavMenuItem, SharedModule } from '@vendure/admin-ui/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This module adds the webhook-sections to existing nav
|
|
6
|
+
*/
|
|
7
|
+
@NgModule({
|
|
8
|
+
imports: [SharedModule],
|
|
9
|
+
providers: [
|
|
10
|
+
addNavMenuItem(
|
|
11
|
+
{
|
|
12
|
+
id: 'webhook',
|
|
13
|
+
label: 'Webhook',
|
|
14
|
+
routerLink: ['/extensions/webhook'],
|
|
15
|
+
icon: 'cloud-traffic',
|
|
16
|
+
requiresPermission: 'SetWebhook',
|
|
17
|
+
},
|
|
18
|
+
'settings'
|
|
19
|
+
),
|
|
20
|
+
],
|
|
21
|
+
})
|
|
22
|
+
export class WebhookNavModule {}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<vdr-action-bar>
|
|
2
|
+
<vdr-ab-right>
|
|
3
|
+
<vdr-action-bar-items locationId="collection-list"></vdr-action-bar-items>
|
|
4
|
+
<button class="btn btn-primary" (click)="showCreateModal()">
|
|
5
|
+
<clr-icon shape="add"></clr-icon>
|
|
6
|
+
Add Webhook
|
|
7
|
+
</button>
|
|
8
|
+
</vdr-ab-right>
|
|
9
|
+
</vdr-action-bar>
|
|
10
|
+
<clr-modal [(clrModalOpen)]="showMessage">
|
|
11
|
+
<h3 class="modal-title">Add Webhook</h3>
|
|
12
|
+
<div class="modal-body">
|
|
13
|
+
<div class="popupContainer">
|
|
14
|
+
<div class="card">
|
|
15
|
+
<div style="width: 100%">
|
|
16
|
+
<ul class="list-group list-group-flush">
|
|
17
|
+
<li class="list-group-item">
|
|
18
|
+
<h4 class="card-title">Request Transformer</h4>
|
|
19
|
+
<select
|
|
20
|
+
clrSelect
|
|
21
|
+
[(ngModel)]="requestTransformerName"
|
|
22
|
+
(ngModelChange)="requestTransformerSelected()"
|
|
23
|
+
>
|
|
24
|
+
<option value="{{ undefined }}">--select---</option>
|
|
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"
|
|
42
|
+
>
|
|
43
|
+
{{ event }}
|
|
44
|
+
</option>
|
|
45
|
+
</select>
|
|
46
|
+
</li>
|
|
47
|
+
<li class="list-group-item">
|
|
48
|
+
<h4 class="card-title">URL *</h4>
|
|
49
|
+
<input
|
|
50
|
+
clrInput
|
|
51
|
+
placeholder="https://"
|
|
52
|
+
name="input"
|
|
53
|
+
[(ngModel)]="url"
|
|
54
|
+
/>
|
|
55
|
+
</li>
|
|
56
|
+
</ul>
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
<div class="modal-footer">
|
|
62
|
+
<button type="button" class="btn btn-outline" (click)="showMessage = false">
|
|
63
|
+
Cancel
|
|
64
|
+
</button>
|
|
65
|
+
<button class="btn btn-primary" (click)="create()">Submit</button>
|
|
66
|
+
</div>
|
|
67
|
+
</clr-modal>
|
|
68
|
+
<vdr-data-table
|
|
69
|
+
[items]="webhooks"
|
|
70
|
+
[itemsPerPage]="itemsPerPage"
|
|
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>
|
|
80
|
+
|
|
81
|
+
<ng-template let-webhook="item">
|
|
82
|
+
<td class="left align-middle">
|
|
83
|
+
{{ webhook.event }}
|
|
84
|
+
</td>
|
|
85
|
+
<td class="left align-middle">
|
|
86
|
+
{{ webhook.requestTransformer?.name }}
|
|
87
|
+
</td>
|
|
88
|
+
<td class="left align-middle">
|
|
89
|
+
{{ webhook.url }}
|
|
90
|
+
</td>
|
|
91
|
+
<td>
|
|
92
|
+
<vdr-dropdown>
|
|
93
|
+
<button type="button" class="btn btn-link btn-sm" vdrDropdownTrigger>
|
|
94
|
+
{{ 'common.actions' | translate }}
|
|
95
|
+
<clr-icon shape="caret down"></clr-icon>
|
|
96
|
+
</button>
|
|
97
|
+
<vdr-dropdown-menu vdrPosition="bottom-right">
|
|
98
|
+
<button
|
|
99
|
+
type="button"
|
|
100
|
+
class="delete-button"
|
|
101
|
+
(click)="deleteWeebhook(webhook.id)"
|
|
102
|
+
vdrDropdownItem
|
|
103
|
+
>
|
|
104
|
+
<clr-icon shape="trash" class="is-danger"></clr-icon>
|
|
105
|
+
{{ 'common.delete' | translate }}
|
|
106
|
+
</button>
|
|
107
|
+
<button
|
|
108
|
+
type="button"
|
|
109
|
+
(click)="duplicate(webhook.requestTransformer?.name, webhook.url)"
|
|
110
|
+
vdrDropdownItem
|
|
111
|
+
>
|
|
112
|
+
<clr-icon shape="copy"></clr-icon>
|
|
113
|
+
Duplicate
|
|
114
|
+
</button>
|
|
115
|
+
</vdr-dropdown-menu>
|
|
116
|
+
</vdr-dropdown>
|
|
117
|
+
</td>
|
|
118
|
+
</ng-template>
|
|
119
|
+
</vdr-data-table>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
|
2
|
+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
3
|
+
import { DataService, NotificationService } from '@vendure/admin-ui/core';
|
|
4
|
+
import {
|
|
5
|
+
getAvailableWebhookEventsQuery,
|
|
6
|
+
getAvailableWebhookRequestTransformersQuery,
|
|
7
|
+
getWebhooksQuery,
|
|
8
|
+
setWebhooksMutation,
|
|
9
|
+
} from './queries';
|
|
10
|
+
import {
|
|
11
|
+
Webhook,
|
|
12
|
+
WebhookInput,
|
|
13
|
+
WebhookRequestTransformer,
|
|
14
|
+
} from './graphql-types';
|
|
15
|
+
|
|
16
|
+
@Component({
|
|
17
|
+
selector: 'webhook-component',
|
|
18
|
+
templateUrl: './webhook.component.html',
|
|
19
|
+
})
|
|
20
|
+
export class WebhookComponent implements OnInit {
|
|
21
|
+
webhooks: Webhook[] = [];
|
|
22
|
+
currentPage: number = 1;
|
|
23
|
+
itemsPerPage: number = 10;
|
|
24
|
+
eventName: string | undefined;
|
|
25
|
+
requestTransformerName: string | undefined;
|
|
26
|
+
url: string | undefined;
|
|
27
|
+
showMessage = false;
|
|
28
|
+
availableWeebhookEvents: string[] = [];
|
|
29
|
+
filteredWeebhookEvents: string[] = [];
|
|
30
|
+
avaiabelWebhookRequestTransformers: WebhookRequestTransformer[] = [];
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
private formBuilder: FormBuilder,
|
|
34
|
+
protected dataService: DataService,
|
|
35
|
+
private changeDetector: ChangeDetectorRef,
|
|
36
|
+
private notificationService: NotificationService
|
|
37
|
+
) {}
|
|
38
|
+
|
|
39
|
+
ngOnInit() {
|
|
40
|
+
this.dataService
|
|
41
|
+
.query(getAvailableWebhookEventsQuery)
|
|
42
|
+
.single$.subscribe((e: any) => {
|
|
43
|
+
this.filteredWeebhookEvents = this.availableWeebhookEvents =
|
|
44
|
+
e.availableWebhookEvents;
|
|
45
|
+
});
|
|
46
|
+
this.dataService.query(getWebhooksQuery).single$.subscribe((s: any) => {
|
|
47
|
+
this.webhooks = s.webhooks;
|
|
48
|
+
});
|
|
49
|
+
this.dataService
|
|
50
|
+
.query(getAvailableWebhookRequestTransformersQuery)
|
|
51
|
+
.single$.toPromise()
|
|
52
|
+
.then((d: any) => {
|
|
53
|
+
this.avaiabelWebhookRequestTransformers =
|
|
54
|
+
d.availableWebhookRequestTransformers;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setPageNumber(event: number) {
|
|
59
|
+
this.currentPage = event;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setItemsPerPage(event: number) {
|
|
63
|
+
this.itemsPerPage = event;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
showCreateModal() {
|
|
67
|
+
this.showMessage = true;
|
|
68
|
+
this.eventName = '';
|
|
69
|
+
this.requestTransformerName = '';
|
|
70
|
+
this.url = '';
|
|
71
|
+
this.changeDetector.detectChanges();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
create() {
|
|
75
|
+
if (
|
|
76
|
+
this.url &&
|
|
77
|
+
this.url !== '' &&
|
|
78
|
+
this.eventName &&
|
|
79
|
+
this.eventName !== ''
|
|
80
|
+
) {
|
|
81
|
+
this.dataService
|
|
82
|
+
.mutate(setWebhooksMutation, {
|
|
83
|
+
webhooks: [
|
|
84
|
+
...this.webhooks.map((w: Webhook) => {
|
|
85
|
+
return {
|
|
86
|
+
event: w.event,
|
|
87
|
+
transformerName: w.requestTransformer?.name,
|
|
88
|
+
url: w.url,
|
|
89
|
+
};
|
|
90
|
+
}),
|
|
91
|
+
{
|
|
92
|
+
event: this.eventName,
|
|
93
|
+
transformerName: this.requestTransformerName,
|
|
94
|
+
url: this.url,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
})
|
|
98
|
+
.subscribe((s: any) => {
|
|
99
|
+
this.showMessage = false;
|
|
100
|
+
this.notificationService.success('Webhook created successfully');
|
|
101
|
+
this.webhooks = s.setWebhooks;
|
|
102
|
+
this.changeDetector.detectChanges();
|
|
103
|
+
});
|
|
104
|
+
} else {
|
|
105
|
+
this.notificationService.error('Please enter all the required fields');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
deleteWeebhook(id: number) {
|
|
110
|
+
this.webhooks = this.webhooks.filter((w: Webhook) => w.id != id);
|
|
111
|
+
this.changeDetector.detectChanges();
|
|
112
|
+
this.dataService
|
|
113
|
+
.mutate(setWebhooksMutation, {
|
|
114
|
+
webhooks: [
|
|
115
|
+
...this.webhooks.map((w: Webhook) => {
|
|
116
|
+
return {
|
|
117
|
+
event: w.event,
|
|
118
|
+
transformerName: w.requestTransformer?.name,
|
|
119
|
+
url: w.url,
|
|
120
|
+
};
|
|
121
|
+
}),
|
|
122
|
+
],
|
|
123
|
+
})
|
|
124
|
+
.subscribe((s: any) => {
|
|
125
|
+
this.webhooks = s.setWebhooks;
|
|
126
|
+
this.notificationService.success('Webhook deleted successfully');
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
requestTransformerSelected(setRequestTransformerName?: string) {
|
|
131
|
+
if (setRequestTransformerName) {
|
|
132
|
+
this.filteredWeebhookEvents =
|
|
133
|
+
this.avaiabelWebhookRequestTransformers.find(
|
|
134
|
+
(v) => v.name === this.requestTransformerName
|
|
135
|
+
)?.supportedEvents ?? [];
|
|
136
|
+
} else if (this.requestTransformerName) {
|
|
137
|
+
this.filteredWeebhookEvents =
|
|
138
|
+
this.avaiabelWebhookRequestTransformers.find(
|
|
139
|
+
(v) => v.name === this.requestTransformerName
|
|
140
|
+
)?.supportedEvents ?? [];
|
|
141
|
+
} else {
|
|
142
|
+
this.filteredWeebhookEvents = this.availableWeebhookEvents;
|
|
143
|
+
}
|
|
144
|
+
this.eventName = this.filteredWeebhookEvents.find(
|
|
145
|
+
(v) => v === this.eventName
|
|
146
|
+
);
|
|
147
|
+
this.changeDetector.detectChanges();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
duplicate(requestTransformer: string, url: string) {
|
|
151
|
+
this.requestTransformerName = requestTransformer;
|
|
152
|
+
this.requestTransformerSelected(requestTransformer);
|
|
153
|
+
this.url = url;
|
|
154
|
+
this.showMessage = true;
|
|
155
|
+
this.changeDetector.detectChanges();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { RouterModule } from '@angular/router';
|
|
3
|
+
import { addNavMenuItem, SharedModule } from '@vendure/admin-ui/core';
|
|
4
|
+
import { WebhookComponent } from './webhook.component';
|
|
5
|
+
|
|
6
|
+
@NgModule({
|
|
7
|
+
imports: [
|
|
8
|
+
SharedModule,
|
|
9
|
+
RouterModule.forChild([
|
|
10
|
+
{
|
|
11
|
+
path: '',
|
|
12
|
+
pathMatch: 'full',
|
|
13
|
+
component: WebhookComponent,
|
|
14
|
+
data: { breadcrumb: 'Webhook' },
|
|
15
|
+
},
|
|
16
|
+
]),
|
|
17
|
+
],
|
|
18
|
+
providers: [
|
|
19
|
+
addNavMenuItem(
|
|
20
|
+
{
|
|
21
|
+
id: 'webhook',
|
|
22
|
+
label: 'Webhook',
|
|
23
|
+
routerLink: ['/extensions/webhook'],
|
|
24
|
+
icon: 'cursor-hand-open',
|
|
25
|
+
},
|
|
26
|
+
'settings'
|
|
27
|
+
),
|
|
28
|
+
],
|
|
29
|
+
declarations: [WebhookComponent],
|
|
30
|
+
})
|
|
31
|
+
export class WebhookModule {}
|