@webuildbots/webuildbots-sdk 9.3.2 → 9.5.0
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.
|
@@ -20,7 +20,7 @@ export default class BlockBuilder {
|
|
|
20
20
|
description(description: string): this;
|
|
21
21
|
type(bt: BlockTypes): this;
|
|
22
22
|
next(blockId: string): this;
|
|
23
|
-
|
|
23
|
+
addVariable(title: string, value: any): this;
|
|
24
24
|
onReply(blockId: string, args?: any): this;
|
|
25
25
|
formFieldCallback(args: any): this;
|
|
26
26
|
voiceAction(voiceAction: VoiceAction): this;
|
|
@@ -47,7 +47,10 @@ var BlockBuilder = /** @class */ (function () {
|
|
|
47
47
|
this.block.next = blockId;
|
|
48
48
|
return this;
|
|
49
49
|
};
|
|
50
|
-
BlockBuilder.prototype.
|
|
50
|
+
BlockBuilder.prototype.addVariable = function (title, value) {
|
|
51
|
+
if (!this.block.variables) {
|
|
52
|
+
this.block.variables = [];
|
|
53
|
+
}
|
|
51
54
|
this.block.variables.push({ title: title, value: value });
|
|
52
55
|
return this;
|
|
53
56
|
};
|
|
@@ -6,11 +6,11 @@ interface WebhookResponse {
|
|
|
6
6
|
}
|
|
7
7
|
export declare type WebhookHandler = (webhookReq: WebhookRequest, respBuilder: ResponseBuilder) => Promise<void>;
|
|
8
8
|
export declare class WebhookClient {
|
|
9
|
-
private secret
|
|
9
|
+
private secret?;
|
|
10
10
|
private handlerMap;
|
|
11
|
-
constructor(secret
|
|
11
|
+
constructor(secret?: string);
|
|
12
12
|
addHandler(handlerName: string, handler: WebhookHandler): this;
|
|
13
|
-
handleRequest(body: string, token
|
|
13
|
+
handleRequest(body: string, token?: string): Promise<WebhookResponse>;
|
|
14
14
|
private verifyPayload;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
|
@@ -64,16 +64,18 @@ var WebhookClient = /** @class */ (function () {
|
|
|
64
64
|
return __generator(this, function (_a) {
|
|
65
65
|
switch (_a.label) {
|
|
66
66
|
case 0:
|
|
67
|
-
// Verify the request
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
// Verify the request if not public function
|
|
68
|
+
if (this.secret) {
|
|
69
|
+
try {
|
|
70
|
+
this.verifyPayload(body, token);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
logger.warn(err);
|
|
74
|
+
return [2 /*return*/, {
|
|
75
|
+
status: http_status_codes_1.StatusCodes.UNAUTHORIZED,
|
|
76
|
+
body: http_status_codes_1.ReasonPhrases.UNAUTHORIZED
|
|
77
|
+
}];
|
|
78
|
+
}
|
|
77
79
|
}
|
|
78
80
|
request = JSON.parse(body);
|
|
79
81
|
handlerName = request.functionBlock.function.handlerName;
|
|
@@ -108,6 +110,9 @@ var WebhookClient = /** @class */ (function () {
|
|
|
108
110
|
});
|
|
109
111
|
};
|
|
110
112
|
WebhookClient.prototype.verifyPayload = function (body, token) {
|
|
113
|
+
if (!token) {
|
|
114
|
+
throw Error('no token provided');
|
|
115
|
+
}
|
|
111
116
|
var bodyMd5Hash = jsonwebtoken_1.default.verify(token, this.secret).bodyMd5Hash;
|
|
112
117
|
// Make sure the requestId's match
|
|
113
118
|
if (bodyMd5Hash !== md5_1.default(body)) {
|