@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
- addVariables(title: string, value: any): this;
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.addVariables = function (title, value) {
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
  };
@@ -29,6 +29,7 @@ export interface WebhookRequest {
29
29
  inputEvent: WBBEvent;
30
30
  functionBlock: Block;
31
31
  formValue: any;
32
+ args?: any;
32
33
  }
33
34
  export interface BlockPointer {
34
35
  id: string;
@@ -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: string);
11
+ constructor(secret?: string);
12
12
  addHandler(handlerName: string, handler: WebhookHandler): this;
13
- handleRequest(body: string, token: string): Promise<WebhookResponse>;
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
- try {
69
- this.verifyPayload(body, token);
70
- }
71
- catch (err) {
72
- logger.warn(err);
73
- return [2 /*return*/, {
74
- status: http_status_codes_1.StatusCodes.UNAUTHORIZED,
75
- body: http_status_codes_1.ReasonPhrases.UNAUTHORIZED
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webuildbots/webuildbots-sdk",
3
- "version": "9.3.2",
3
+ "version": "9.5.0",
4
4
  "description": "webuildbots sdk",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",