|
1 | | -import { Typeform } from './typeform-types' |
| 1 | +import {Typeform} from './typeform-types' |
2 | 2 |
|
3 | 3 | export class Webhooks { |
4 | | - constructor(private _http: Typeform.HTTPClient) {} |
| 4 | + constructor(private _http: Typeform.HTTPClient) { |
| 5 | + } |
5 | 6 |
|
6 | | - public create(args: { |
7 | | - uid: string |
8 | | - tag: string |
9 | | - url: string |
10 | | - enabled?: boolean |
11 | | - secret?: string |
12 | | - verifySSL?: boolean |
13 | | - }): Promise<Typeform.Webhook> { |
14 | | - return createOrUpdateWebhook(this._http, args) |
15 | | - } |
| 7 | + public create(args: { |
| 8 | + uid: string |
| 9 | + tag: string |
| 10 | + url: string |
| 11 | + enabled?: boolean |
| 12 | + secret?: string |
| 13 | + verifySSL?: boolean |
| 14 | + }): Promise<Typeform.Webhook> { |
| 15 | + return createOrUpdateWebhook(this._http, args) |
| 16 | + } |
16 | 17 |
|
17 | | - public delete(args: { uid: string; tag: string }): Promise<null> { |
18 | | - const { uid, tag } = args |
| 18 | + public delete(args: { uid: string; tag: string }): Promise<null> { |
| 19 | + const {uid, tag} = args |
19 | 20 |
|
20 | | - return this._http.request({ |
21 | | - method: 'delete', |
22 | | - url: `/forms/${uid}/webhooks/${tag}`, |
23 | | - }) |
24 | | - } |
| 21 | + return this._http.request({ |
| 22 | + method: 'delete', |
| 23 | + url: `/forms/${uid}/webhooks/${tag}`, |
| 24 | + }) |
| 25 | + } |
25 | 26 |
|
26 | | - public get(args: { uid: string; tag: string }): Promise<Typeform.Webhook> { |
27 | | - const { uid, tag } = args |
| 27 | + public get(args: { uid: string; tag: string }): Promise<Typeform.Webhook> { |
| 28 | + const {uid, tag} = args |
28 | 29 |
|
29 | | - return this._http.request({ |
30 | | - method: 'get', |
31 | | - url: `/forms/${uid}/webhooks/${tag}`, |
32 | | - }) |
33 | | - } |
| 30 | + return this._http.request({ |
| 31 | + method: 'get', |
| 32 | + url: `/forms/${uid}/webhooks/${tag}`, |
| 33 | + }) |
| 34 | + } |
34 | 35 |
|
35 | | - public list(args: { uid: string }): Promise<Typeform.API.Webhooks.List> { |
36 | | - const { uid } = args |
| 36 | + public list(args: { uid: string }): Promise<Typeform.API.Webhooks.List> { |
| 37 | + const {uid} = args |
37 | 38 |
|
38 | | - return this._http.request({ |
39 | | - method: 'get', |
40 | | - url: `/forms/${uid}/webhooks`, |
41 | | - }) |
42 | | - } |
43 | | - |
44 | | - public toggle (args: { uid: string, tag: string, enabled: boolean }): Promise<Typeform.API.Webhooks.List> { |
45 | | - const { uid, tag, enabled } = args |
| 39 | + return this._http.request({ |
| 40 | + method: 'get', |
| 41 | + url: `/forms/${uid}/webhooks`, |
| 42 | + }) |
| 43 | + } |
46 | 44 |
|
47 | | - return this._http.request({ |
48 | | - method: 'put', |
49 | | - url: `/forms/${uid}/webhooks/${tag}`, |
50 | | - data: { |
51 | | - enabled |
52 | | - } |
53 | | - }) |
54 | | - } |
| 45 | + public toggle(args: { uid: string, tag: string, enabled: boolean }): Promise<Typeform.API.Webhooks.List> { |
| 46 | + const {uid, tag, enabled} = args |
| 47 | + |
| 48 | + return this._http.request({ |
| 49 | + method: 'put', |
| 50 | + url: `/forms/${uid}/webhooks/${tag}`, |
| 51 | + data: { |
| 52 | + enabled |
| 53 | + } |
| 54 | + }) |
| 55 | + } |
55 | 56 |
|
56 | | - update(args: { |
57 | | - uid: string |
58 | | - tag: string |
59 | | - url: string |
60 | | - enabled?: boolean |
61 | | - secret?: string |
62 | | - verifySSL?: boolean |
63 | | - }): Promise<Typeform.Webhook> { |
64 | | - return createOrUpdateWebhook(this._http, args) |
65 | | - } |
| 57 | + update(args: { |
| 58 | + uid: string |
| 59 | + tag: string |
| 60 | + url: string |
| 61 | + enabled?: boolean |
| 62 | + secret?: string |
| 63 | + verifySSL?: boolean |
| 64 | + }): Promise<Typeform.Webhook> { |
| 65 | + return createOrUpdateWebhook(this._http, args) |
| 66 | + } |
66 | 67 | } |
67 | 68 |
|
68 | 69 | const createOrUpdateWebhook = ( |
69 | | - http: Typeform.HTTPClient, |
70 | | - args: { |
71 | | - uid: string |
72 | | - tag: string |
73 | | - url: string |
74 | | - enabled?: boolean |
75 | | - secret?: string |
76 | | - verifySSL?: boolean |
77 | | - } |
| 70 | + http: Typeform.HTTPClient, |
| 71 | + args: { |
| 72 | + uid: string |
| 73 | + tag: string |
| 74 | + url: string |
| 75 | + enabled?: boolean |
| 76 | + secret?: string |
| 77 | + verifySSL?: boolean |
| 78 | + } |
78 | 79 | ): Promise<Typeform.Webhook> => { |
79 | | - const { uid, tag, url, enabled = false, secret, verifySSL } = args |
| 80 | + const {uid, tag, url, enabled = false, secret, verifySSL} = args |
80 | 81 |
|
81 | | - if (!url) { |
82 | | - throw new Error(`Please provide an url for ${tag}`) |
83 | | - } |
| 82 | + if (!url) { |
| 83 | + throw new Error(`Please provide an url for ${tag}`) |
| 84 | + } |
84 | 85 |
|
85 | | - if (!tag) { |
86 | | - throw new Error(`Please provide a tag name for the webhook`) |
87 | | - } |
| 86 | + if (!tag) { |
| 87 | + throw new Error(`Please provide a tag name for the webhook`) |
| 88 | + } |
88 | 89 |
|
89 | | - return http.request({ |
90 | | - method: 'put', |
91 | | - url: `/forms/${uid}/webhooks/${tag}`, |
92 | | - data: { |
93 | | - url, |
94 | | - enabled, |
95 | | - secret, |
96 | | - verify_ssl: verifySSL ? true : undefined, |
97 | | - }, |
98 | | - }) |
| 90 | + return http.request({ |
| 91 | + method: 'put', |
| 92 | + url: `/forms/${uid}/webhooks/${tag}`, |
| 93 | + data: { |
| 94 | + url, |
| 95 | + enabled, |
| 96 | + secret, |
| 97 | + verify_ssl: verifySSL ? true : undefined, |
| 98 | + }, |
| 99 | + }) |
99 | 100 | } |
0 commit comments