vayu-ts 0.2.10 → 0.2.11

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.
@@ -14,7 +14,10 @@ export declare class GetProductConsumptionResponseProductConsumption {
14
14
  * The id of the product.
15
15
  */
16
16
  'productId': string;
17
- 'productName'?: string;
17
+ /**
18
+ * The name of the product.
19
+ */
20
+ 'productName': string;
18
21
  /**
19
22
  * The amount of units provisioned to the customer.
20
23
  */
@@ -14,5 +14,6 @@ export declare enum NotificationEventType {
14
14
  Overage = "Overage",
15
15
  UpcomingRenewal = "UpcomingRenewal",
16
16
  InvoiceApproved = "InvoiceApproved",
17
- CustomerPortalLinkSent = "CustomerPortalLinkSent"
17
+ CustomerPortalLinkSent = "CustomerPortalLinkSent",
18
+ CommitmentCrossed = "CommitmentCrossed"
18
19
  }
@@ -19,4 +19,5 @@ var NotificationEventType;
19
19
  NotificationEventType["UpcomingRenewal"] = "UpcomingRenewal";
20
20
  NotificationEventType["InvoiceApproved"] = "InvoiceApproved";
21
21
  NotificationEventType["CustomerPortalLinkSent"] = "CustomerPortalLinkSent";
22
+ NotificationEventType["CommitmentCrossed"] = "CommitmentCrossed";
22
23
  })(NotificationEventType = exports.NotificationEventType || (exports.NotificationEventType = {}));
@@ -14,7 +14,10 @@ export declare class ProductConsumption {
14
14
  * The id of the product.
15
15
  */
16
16
  'productId': string;
17
- 'productName'?: string;
17
+ /**
18
+ * The name of the product.
19
+ */
20
+ 'productName': string;
18
21
  /**
19
22
  * The amount of units provisioned to the customer.
20
23
  */
@@ -1,7 +1,13 @@
1
1
  export declare class WebhooksClient {
2
2
  private client;
3
3
  constructor();
4
- subscribeToOverage(callbackUrl: string): Promise<void>;
4
+ verifyWebhookSignature({ payload, timestamp, signature, tolerance, }: {
5
+ payload: string;
6
+ timestamp: number;
7
+ signature: string;
8
+ tolerance?: number;
9
+ }): boolean;
10
+ subscribeToCommitmentCrossed(callbackUrl: string): Promise<void>;
5
11
  subscribeToAnonymousCustomerCreated(callbackUrl: string): Promise<void>;
6
12
  private subscribe;
7
13
  }
@@ -1,16 +1,32 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.WebhooksClient = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
4
8
  const openapi_1 = require("../../openapi");
9
+ const public_webhook_key_1 = require("../consts/public-webhook-key");
5
10
  const services_1 = require("../services");
6
11
  class WebhooksClient {
7
12
  constructor() {
8
13
  this.client = services_1.ConfigurationService.instance.generateNewClient(openapi_1.WebhooksApi);
9
14
  }
10
- subscribeToOverage(callbackUrl) {
15
+ verifyWebhookSignature({ payload, timestamp, signature, tolerance = 300, }) {
16
+ const now = Math.floor(Date.now() / 1000);
17
+ if (Math.abs(now - timestamp) > tolerance) {
18
+ return false;
19
+ }
20
+ const message = `${timestamp}.${JSON.stringify(payload)}`;
21
+ const verifier = crypto_1.default.createVerify('RSA-SHA256');
22
+ verifier.update(message);
23
+ verifier.end();
24
+ return verifier.verify(public_webhook_key_1.PUBLIC_WEBHOOK_KEY, signature, 'base64');
25
+ }
26
+ subscribeToCommitmentCrossed(callbackUrl) {
11
27
  return this.subscribe({
12
28
  callbackUrl,
13
- eventType: openapi_1.NotificationEventType.Overage,
29
+ eventType: openapi_1.NotificationEventType.CommitmentCrossed,
14
30
  });
15
31
  }
16
32
  subscribeToAnonymousCustomerCreated(callbackUrl) {
@@ -0,0 +1 @@
1
+ export declare const PUBLIC_WEBHOOK_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1JNmKwmOMQ9S7JyQFg2j\n5OHFhLBjqZbgSturKADF9sEH0X21RqzGXefMDmKbXMkcQiamqK9Puoj3N1bFr5lE\nf7EeUUihpcpfaeMNbNr0J8fkaq4YBO6cU3UvexLYr8WKkhaWkxB45TnysVl9FxIw\ne9iI3+QMAs/5DTIc+hAstXim+HfFW8teWYGI55KPjqqAIda3GPpFd4JnlI86TQux\np2nStncGasBpXCww7qXtE1SsM/o3/WQabzmmk4ox6Dt1DeTfMhtK/aOkz9/Cpx8V\nKCxwrKliqSM5Ies/2R4lTIKntqPsIcxxEQnVydL8YAY1uMiePVwgJFP6xRSY6J1H\nBwIDAQAB\n-----END PUBLIC KEY-----";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PUBLIC_WEBHOOK_KEY = void 0;
4
+ exports.PUBLIC_WEBHOOK_KEY = `-----BEGIN PUBLIC KEY-----
5
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1JNmKwmOMQ9S7JyQFg2j
6
+ 5OHFhLBjqZbgSturKADF9sEH0X21RqzGXefMDmKbXMkcQiamqK9Puoj3N1bFr5lE
7
+ f7EeUUihpcpfaeMNbNr0J8fkaq4YBO6cU3UvexLYr8WKkhaWkxB45TnysVl9FxIw
8
+ e9iI3+QMAs/5DTIc+hAstXim+HfFW8teWYGI55KPjqqAIda3GPpFd4JnlI86TQux
9
+ p2nStncGasBpXCww7qXtE1SsM/o3/WQabzmmk4ox6Dt1DeTfMhtK/aOkz9/Cpx8V
10
+ KCxwrKliqSM5Ies/2R4lTIKntqPsIcxxEQnVydL8YAY1uMiePVwgJFP6xRSY6J1H
11
+ BwIDAQAB
12
+ -----END PUBLIC KEY-----`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vayu-ts",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "Simple and easy to use typescript package for utilizing vayu billing system",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",