vayu-ts 0.2.9 → 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.
- package/README.md +27 -5
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/openapi/models/GetProductConsumptionResponseProductConsumption.d.ts +4 -1
- package/dist/openapi/models/NotificationEventType.d.ts +2 -1
- package/dist/openapi/models/NotificationEventType.js +1 -0
- package/dist/openapi/models/ProductConsumption.d.ts +4 -1
- package/dist/sdk/clients/WebhooksClient.d.ts +9 -2
- package/dist/sdk/clients/WebhooksClient.js +28 -0
- package/dist/sdk/consts/public-webhook-key.d.ts +1 -0
- package/dist/sdk/consts/public-webhook-key.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,6 +133,16 @@ const response = await vayu.customers.delete('customer-id');
|
|
|
133
133
|
console.log(response.customer);
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
+
#### Getting Product Consumptions
|
|
137
|
+
|
|
138
|
+
To get product consumptions for a customer:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const response = await vayu.customers.getProductConsumptions('customer-id');
|
|
142
|
+
|
|
143
|
+
console.log(response.productConsumptions);
|
|
144
|
+
```
|
|
145
|
+
|
|
136
146
|
### Contracts
|
|
137
147
|
|
|
138
148
|
#### Assigning a contract to a customer
|
|
@@ -170,13 +180,19 @@ console.log(response.hasMore);
|
|
|
170
180
|
console.log(response.nextCursor);
|
|
171
181
|
```
|
|
172
182
|
|
|
173
|
-
|
|
183
|
+
### Webhooks
|
|
184
|
+
|
|
185
|
+
#### Subscribing to Events
|
|
186
|
+
|
|
187
|
+
You can subscribe to various events using webhooks. Here are the available subscription methods:
|
|
174
188
|
|
|
175
189
|
```typescript
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
190
|
+
// Subscribe to overage notifications
|
|
191
|
+
await vayu.webhooks.subscribeToOverage('https://your-webhook-url.com/overage');
|
|
192
|
+
|
|
193
|
+
// Subscribe to anonymous customer creation notifications
|
|
194
|
+
await vayu.webhooks.subscribeToAnonymousCustomerCreated('https://your-webhook-url.com/your_path');
|
|
195
|
+
|
|
180
196
|
```
|
|
181
197
|
|
|
182
198
|
## Features
|
|
@@ -198,6 +214,7 @@ The Vayu API client library provides access to the following features:
|
|
|
198
214
|
- `customers.list()`
|
|
199
215
|
- `customers.get()`
|
|
200
216
|
- `customers.getByExternalId()`
|
|
217
|
+
- `customers.getProductConsumptions()`
|
|
201
218
|
- **Meters**
|
|
202
219
|
- `meters.get()`
|
|
203
220
|
- `meters.update()`
|
|
@@ -215,6 +232,11 @@ The Vayu API client library provides access to the following features:
|
|
|
215
232
|
- **Invoices**
|
|
216
233
|
- `invoices.get()`
|
|
217
234
|
- `invoices.list()`
|
|
235
|
+
- **Webhooks**
|
|
236
|
+
- `webhooks.subscribeToOverage()`
|
|
237
|
+
- `webhooks.subscribeToAnonymousCustomerCreated()`
|
|
238
|
+
- **Product Consumption**
|
|
239
|
+
- `productConsumption.get()`
|
|
218
240
|
|
|
219
241
|
## Support
|
|
220
242
|
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -14,7 +14,10 @@ export declare class GetProductConsumptionResponseProductConsumption {
|
|
|
14
14
|
* The id of the product.
|
|
15
15
|
*/
|
|
16
16
|
'productId': string;
|
|
17
|
-
|
|
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
|
-
|
|
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,6 +1,13 @@
|
|
|
1
|
-
import type { WebhookSubscribeRequest } from '../../openapi';
|
|
2
1
|
export declare class WebhooksClient {
|
|
3
2
|
private client;
|
|
4
3
|
constructor();
|
|
5
|
-
|
|
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>;
|
|
11
|
+
subscribeToAnonymousCustomerCreated(callbackUrl: string): Promise<void>;
|
|
12
|
+
private subscribe;
|
|
6
13
|
}
|
|
@@ -1,12 +1,40 @@
|
|
|
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
|
}
|
|
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) {
|
|
27
|
+
return this.subscribe({
|
|
28
|
+
callbackUrl,
|
|
29
|
+
eventType: openapi_1.NotificationEventType.CommitmentCrossed,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
subscribeToAnonymousCustomerCreated(callbackUrl) {
|
|
33
|
+
return this.subscribe({
|
|
34
|
+
callbackUrl,
|
|
35
|
+
eventType: openapi_1.NotificationEventType.AnonymousCustomer,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
10
38
|
async subscribe(payload) {
|
|
11
39
|
return this.client.webhookSubscribe(payload);
|
|
12
40
|
}
|
|
@@ -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-----`;
|