-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwebhooks.ts
More file actions
466 lines (421 loc) · 20.5 KB
/
Copy pathwebhooks.ts
File metadata and controls
466 lines (421 loc) · 20.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
import { Service } from '../service';
import { AppwriteException, Client, type Payload, UploadProgress } from '../client';
import type { Models } from '../models';
export class Webhooks {
client: Client;
constructor(client: Client) {
this.client = client;
}
/**
* Get a list of all webhooks belonging to the project. You can use the query params to filter your results.
*
* @param {string[]} params.queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, authUsername, tls, events, enabled, logs, attempts
* @param {boolean} params.total - When set to false, the total count returned will be 0 and will not be calculated.
* @throws {AppwriteException}
* @returns {Promise<Models.WebhookList>}
*/
list(params?: { queries?: string[], total?: boolean }): Promise<Models.WebhookList>;
/**
* Get a list of all webhooks belonging to the project. You can use the query params to filter your results.
*
* @param {string[]} queries - Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, url, authUsername, tls, events, enabled, logs, attempts
* @param {boolean} total - When set to false, the total count returned will be 0 and will not be calculated.
* @throws {AppwriteException}
* @returns {Promise<Models.WebhookList>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
list(queries?: string[], total?: boolean): Promise<Models.WebhookList>;
list(
paramsOrFirst?: { queries?: string[], total?: boolean } | string[],
...rest: [(boolean)?]
): Promise<Models.WebhookList> {
let params: { queries?: string[], total?: boolean };
if (!paramsOrFirst || (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { queries?: string[], total?: boolean };
} else {
params = {
queries: paramsOrFirst as string[],
total: rest[0] as boolean
};
}
const queries = params.queries;
const total = params.total;
const apiPath = '/webhooks';
const payload: Payload = {};
if (typeof queries !== 'undefined') {
payload['queries'] = queries;
}
if (typeof total !== 'undefined') {
payload['total'] = total;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Create a new webhook. Use this endpoint to configure a URL that will receive events from Appwrite when specific events occur.
*
* @param {string} params.webhookId - Webhook ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
* @param {string} params.url - Webhook URL.
* @param {string} params.name - Webhook name. Max length: 128 chars.
* @param {string[]} params.events - Events list. Maximum of 100 events are allowed.
* @param {boolean} params.enabled - Enable or disable a webhook.
* @param {boolean} params.tls - Certificate verification, false for disabled or true for enabled.
* @param {string} params.authUsername - Webhook HTTP user. Max length: 256 chars.
* @param {string} params.authPassword - Webhook HTTP password. Max length: 256 chars.
* @param {string} params.secret - Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
*/
create(params: { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string, secret?: string }): Promise<Models.Webhook>;
/**
* Create a new webhook. Use this endpoint to configure a URL that will receive events from Appwrite when specific events occur.
*
* @param {string} webhookId - Webhook ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
* @param {string} url - Webhook URL.
* @param {string} name - Webhook name. Max length: 128 chars.
* @param {string[]} events - Events list. Maximum of 100 events are allowed.
* @param {boolean} enabled - Enable or disable a webhook.
* @param {boolean} tls - Certificate verification, false for disabled or true for enabled.
* @param {string} authUsername - Webhook HTTP user. Max length: 256 chars.
* @param {string} authPassword - Webhook HTTP password. Max length: 256 chars.
* @param {string} secret - Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
create(webhookId: string, url: string, name: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string, secret?: string): Promise<Models.Webhook>;
create(
paramsOrFirst: { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string, secret?: string } | string,
...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?, (string)?, (string)?, (string)?]
): Promise<Models.Webhook> {
let params: { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string, secret?: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { webhookId: string, url: string, name: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string, secret?: string };
} else {
params = {
webhookId: paramsOrFirst as string,
url: rest[0] as string,
name: rest[1] as string,
events: rest[2] as string[],
enabled: rest[3] as boolean,
tls: rest[4] as boolean,
authUsername: rest[5] as string,
authPassword: rest[6] as string,
secret: rest[7] as string
};
}
const webhookId = params.webhookId;
const url = params.url;
const name = params.name;
const events = params.events;
const enabled = params.enabled;
const tls = params.tls;
const authUsername = params.authUsername;
const authPassword = params.authPassword;
const secret = params.secret;
if (typeof webhookId === 'undefined') {
throw new AppwriteException('Missing required parameter: "webhookId"');
}
if (typeof url === 'undefined') {
throw new AppwriteException('Missing required parameter: "url"');
}
if (typeof name === 'undefined') {
throw new AppwriteException('Missing required parameter: "name"');
}
if (typeof events === 'undefined') {
throw new AppwriteException('Missing required parameter: "events"');
}
const apiPath = '/webhooks';
const payload: Payload = {};
if (typeof webhookId !== 'undefined') {
payload['webhookId'] = webhookId;
}
if (typeof url !== 'undefined') {
payload['url'] = url;
}
if (typeof name !== 'undefined') {
payload['name'] = name;
}
if (typeof events !== 'undefined') {
payload['events'] = events;
}
if (typeof enabled !== 'undefined') {
payload['enabled'] = enabled;
}
if (typeof tls !== 'undefined') {
payload['tls'] = tls;
}
if (typeof authUsername !== 'undefined') {
payload['authUsername'] = authUsername;
}
if (typeof authPassword !== 'undefined') {
payload['authPassword'] = authPassword;
}
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'post',
uri,
apiHeaders,
payload
);
}
/**
* Get a webhook by its unique ID. This endpoint returns details about a specific webhook configured for a project.
*
* @param {string} params.webhookId - Webhook ID.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
*/
get(params: { webhookId: string }): Promise<Models.Webhook>;
/**
* Get a webhook by its unique ID. This endpoint returns details about a specific webhook configured for a project.
*
* @param {string} webhookId - Webhook ID.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
get(webhookId: string): Promise<Models.Webhook>;
get(
paramsOrFirst: { webhookId: string } | string
): Promise<Models.Webhook> {
let params: { webhookId: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { webhookId: string };
} else {
params = {
webhookId: paramsOrFirst as string
};
}
const webhookId = params.webhookId;
if (typeof webhookId === 'undefined') {
throw new AppwriteException('Missing required parameter: "webhookId"');
}
const apiPath = '/webhooks/{webhookId}'.replace('{webhookId}', webhookId);
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
}
return this.client.call(
'get',
uri,
apiHeaders,
payload
);
}
/**
* Update a webhook by its unique ID. Use this endpoint to update the URL, events, or status of an existing webhook.
*
* @param {string} params.webhookId - Webhook ID.
* @param {string} params.name - Webhook name. Max length: 128 chars.
* @param {string} params.url - Webhook URL.
* @param {string[]} params.events - Events list. Maximum of 100 events are allowed.
* @param {boolean} params.enabled - Enable or disable a webhook.
* @param {boolean} params.tls - Certificate verification, false for disabled or true for enabled.
* @param {string} params.authUsername - Webhook HTTP user. Max length: 256 chars.
* @param {string} params.authPassword - Webhook HTTP password. Max length: 256 chars.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
*/
update(params: { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string }): Promise<Models.Webhook>;
/**
* Update a webhook by its unique ID. Use this endpoint to update the URL, events, or status of an existing webhook.
*
* @param {string} webhookId - Webhook ID.
* @param {string} name - Webhook name. Max length: 128 chars.
* @param {string} url - Webhook URL.
* @param {string[]} events - Events list. Maximum of 100 events are allowed.
* @param {boolean} enabled - Enable or disable a webhook.
* @param {boolean} tls - Certificate verification, false for disabled or true for enabled.
* @param {string} authUsername - Webhook HTTP user. Max length: 256 chars.
* @param {string} authPassword - Webhook HTTP password. Max length: 256 chars.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
update(webhookId: string, name: string, url: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string): Promise<Models.Webhook>;
update(
paramsOrFirst: { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string } | string,
...rest: [(string)?, (string)?, (string[])?, (boolean)?, (boolean)?, (string)?, (string)?]
): Promise<Models.Webhook> {
let params: { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { webhookId: string, name: string, url: string, events: string[], enabled?: boolean, tls?: boolean, authUsername?: string, authPassword?: string };
} else {
params = {
webhookId: paramsOrFirst as string,
name: rest[0] as string,
url: rest[1] as string,
events: rest[2] as string[],
enabled: rest[3] as boolean,
tls: rest[4] as boolean,
authUsername: rest[5] as string,
authPassword: rest[6] as string
};
}
const webhookId = params.webhookId;
const name = params.name;
const url = params.url;
const events = params.events;
const enabled = params.enabled;
const tls = params.tls;
const authUsername = params.authUsername;
const authPassword = params.authPassword;
if (typeof webhookId === 'undefined') {
throw new AppwriteException('Missing required parameter: "webhookId"');
}
if (typeof name === 'undefined') {
throw new AppwriteException('Missing required parameter: "name"');
}
if (typeof url === 'undefined') {
throw new AppwriteException('Missing required parameter: "url"');
}
if (typeof events === 'undefined') {
throw new AppwriteException('Missing required parameter: "events"');
}
const apiPath = '/webhooks/{webhookId}'.replace('{webhookId}', webhookId);
const payload: Payload = {};
if (typeof name !== 'undefined') {
payload['name'] = name;
}
if (typeof url !== 'undefined') {
payload['url'] = url;
}
if (typeof events !== 'undefined') {
payload['events'] = events;
}
if (typeof enabled !== 'undefined') {
payload['enabled'] = enabled;
}
if (typeof tls !== 'undefined') {
payload['tls'] = tls;
}
if (typeof authUsername !== 'undefined') {
payload['authUsername'] = authUsername;
}
if (typeof authPassword !== 'undefined') {
payload['authPassword'] = authPassword;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'put',
uri,
apiHeaders,
payload
);
}
/**
* Delete a webhook by its unique ID. Once deleted, the webhook will no longer receive project events.
*
* @param {string} params.webhookId - Webhook ID.
* @throws {AppwriteException}
* @returns {Promise<{}>}
*/
delete(params: { webhookId: string }): Promise<{}>;
/**
* Delete a webhook by its unique ID. Once deleted, the webhook will no longer receive project events.
*
* @param {string} webhookId - Webhook ID.
* @throws {AppwriteException}
* @returns {Promise<{}>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
delete(webhookId: string): Promise<{}>;
delete(
paramsOrFirst: { webhookId: string } | string
): Promise<{}> {
let params: { webhookId: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { webhookId: string };
} else {
params = {
webhookId: paramsOrFirst as string
};
}
const webhookId = params.webhookId;
if (typeof webhookId === 'undefined') {
throw new AppwriteException('Missing required parameter: "webhookId"');
}
const apiPath = '/webhooks/{webhookId}'.replace('{webhookId}', webhookId);
const payload: Payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'delete',
uri,
apiHeaders,
payload
);
}
/**
* Update the webhook signing key. This endpoint can be used to regenerate the signing key used to sign and validate payload deliveries for a specific webhook.
*
* @param {string} params.webhookId - Webhook ID.
* @param {string} params.secret - Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
*/
updateSecret(params: { webhookId: string, secret?: string }): Promise<Models.Webhook>;
/**
* Update the webhook signing key. This endpoint can be used to regenerate the signing key used to sign and validate payload deliveries for a specific webhook.
*
* @param {string} webhookId - Webhook ID.
* @param {string} secret - Webhook secret key. If not provided, a new key will be generated automatically. Key must be at least 8 characters long, and at max 256 characters.
* @throws {AppwriteException}
* @returns {Promise<Models.Webhook>}
* @deprecated Use the object parameter style method for a better developer experience.
*/
updateSecret(webhookId: string, secret?: string): Promise<Models.Webhook>;
updateSecret(
paramsOrFirst: { webhookId: string, secret?: string } | string,
...rest: [(string)?]
): Promise<Models.Webhook> {
let params: { webhookId: string, secret?: string };
if ((paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst))) {
params = (paramsOrFirst || {}) as { webhookId: string, secret?: string };
} else {
params = {
webhookId: paramsOrFirst as string,
secret: rest[0] as string
};
}
const webhookId = params.webhookId;
const secret = params.secret;
if (typeof webhookId === 'undefined') {
throw new AppwriteException('Missing required parameter: "webhookId"');
}
const apiPath = '/webhooks/{webhookId}/secret'.replace('{webhookId}', webhookId);
const payload: Payload = {};
if (typeof secret !== 'undefined') {
payload['secret'] = secret;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders: { [header: string]: string } = {
'content-type': 'application/json',
}
return this.client.call(
'patch',
uri,
apiHeaders,
payload
);
}
}