-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathreportWebhooksHandler.ts
More file actions
59 lines (47 loc) · 1.72 KB
/
reportWebhooksHandler.ts
File metadata and controls
59 lines (47 loc) · 1.72 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
/*
* The version of the OpenAPI document: v1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit this class manually.
*/
import { reportWebhooks } from "..";
/**
* Union type for all supported webhook requests.
* Allows generic handling of configuration-related webhook events.
*/
export type GenericWebhook =
| reportWebhooks.ReportNotificationRequest;
/**
* Handler for processing ReportWebhooks.
*
* This class provides functionality to deserialize the payload of ReportWebhooks events.
*/
export class ReportWebhooksHandler {
private readonly payload: Record<string, any>;
public constructor(jsonPayload: string) {
this.payload = JSON.parse(jsonPayload);
}
/**
* This method checks the type of the webhook payload and returns the appropriate deserialized object.
*
* @returns A deserialized object of type GenericWebhook.
* @throws Error if the type is not recognized.
*/
public getGenericWebhook(): GenericWebhook {
const type = this.payload["type"];
if(Object.values(reportWebhooks.ReportNotificationRequest.TypeEnum).includes(type)) {
return this.getReportNotificationRequest();
}
throw new Error("Could not parse the json payload: " + this.payload);
}
/**
* Deserialize the webhook payload into a ReportNotificationRequest
*
* @returns Deserialized ReportNotificationRequest object.
*/
public getReportNotificationRequest(): reportWebhooks.ReportNotificationRequest {
return reportWebhooks.ObjectSerializer.deserialize(this.payload, "ReportNotificationRequest");
}
}