|
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) { |
5 |
| - } |
| 4 | + constructor(private _http: Typeform.HTTPClient) {} |
6 | 5 |
|
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 |
| - } |
| 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 | + } |
17 | 16 |
|
18 |
| - public delete(args: { uid: string; tag: string }): Promise<null> { |
19 |
| - const {uid, tag} = args |
| 17 | + public delete(args: { uid: string; tag: string }): Promise<null> { |
| 18 | + const { uid, tag } = args |
20 | 19 |
|
21 |
| - return this._http.request({ |
22 |
| - method: 'delete', |
23 |
| - url: `/forms/${uid}/webhooks/${tag}`, |
24 |
| - }) |
25 |
| - } |
26 |
| - |
27 |
| - public get(args: { uid: string; tag: string }): Promise<Typeform.Webhook> { |
28 |
| - const {uid, tag} = args |
| 20 | + return this._http.request({ |
| 21 | + method: 'delete', |
| 22 | + url: `/forms/${uid}/webhooks/${tag}`, |
| 23 | + }) |
| 24 | + } |
29 | 25 |
|
30 |
| - return this._http.request({ |
31 |
| - method: 'get', |
32 |
| - url: `/forms/${uid}/webhooks/${tag}`, |
33 |
| - }) |
34 |
| - } |
| 26 | + public get(args: { uid: string; tag: string }): Promise<Typeform.Webhook> { |
| 27 | + const { uid, tag } = args |
35 | 28 |
|
36 |
| - public list(args: { uid: string }): Promise<Typeform.API.Webhooks.List> { |
37 |
| - const {uid} = args |
| 29 | + return this._http.request({ |
| 30 | + method: 'get', |
| 31 | + url: `/forms/${uid}/webhooks/${tag}`, |
| 32 | + }) |
| 33 | + } |
38 | 34 |
|
39 |
| - return this._http.request({ |
40 |
| - method: 'get', |
41 |
| - url: `/forms/${uid}/webhooks`, |
42 |
| - }) |
43 |
| - } |
| 35 | + public list(args: { uid: string }): Promise<Typeform.API.Webhooks.List> { |
| 36 | + const { uid } = args |
44 | 37 |
|
45 |
| - public toggle(args: { uid: string, tag: string, enabled: boolean }): Promise<Typeform.API.Webhooks.List> { |
46 |
| - const {uid, tag, enabled} = args |
| 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 |
47 | 46 |
|
48 |
| - return this._http.request({ |
49 |
| - method: 'put', |
50 |
| - url: `/forms/${uid}/webhooks/${tag}`, |
51 |
| - data: { |
52 |
| - enabled |
53 |
| - } |
54 |
| - }) |
55 |
| - } |
| 47 | + return this._http.request({ |
| 48 | + method: 'put', |
| 49 | + url: `/forms/${uid}/webhooks/${tag}`, |
| 50 | + data: { |
| 51 | + enabled |
| 52 | + } |
| 53 | + }) |
| 54 | + } |
56 | 55 |
|
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 |
| - } |
| 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 | + } |
67 | 66 | }
|
68 | 67 |
|
69 | 68 | const createOrUpdateWebhook = (
|
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 |
| - } |
| 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 | + } |
79 | 78 | ): Promise<Typeform.Webhook> => {
|
80 |
| - const {uid, tag, url, enabled = false, secret, verifySSL} = args |
| 79 | + const { uid, tag, url, enabled = false, secret, verifySSL } = args |
81 | 80 |
|
82 |
| - if (!url) { |
83 |
| - throw new Error(`Please provide a url for ${tag}`) |
84 |
| - } |
| 81 | + if (!url) { |
| 82 | + throw new Error(`Please provide an url for ${tag}`) |
| 83 | + } |
85 | 84 |
|
86 |
| - if (!tag) { |
87 |
| - throw new Error(`Please provide a tag name for the webhook`) |
88 |
| - } |
| 85 | + if (!tag) { |
| 86 | + throw new Error(`Please provide a tag name for the webhook`) |
| 87 | + } |
89 | 88 |
|
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 |
| - }) |
| 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 | + }) |
100 | 99 | }
|
0 commit comments