vayu-ts 0.2.14 → 0.3.4

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.
Files changed (217) hide show
  1. package/dist/example/index.d.ts +1 -0
  2. package/dist/example/index.js +74 -0
  3. package/dist/openapi/apis/CatalogProductsApi.d.ts +89 -0
  4. package/dist/openapi/apis/CatalogProductsApi.js +354 -0
  5. package/dist/openapi/apis/CloudUsageSubmissionApi.d.ts +25 -0
  6. package/dist/openapi/apis/CloudUsageSubmissionApi.js +85 -0
  7. package/dist/openapi/apis/ContractsApi.d.ts +21 -3
  8. package/dist/openapi/apis/ContractsApi.js +75 -3
  9. package/dist/openapi/apis/CustomersApi.d.ts +63 -0
  10. package/dist/openapi/apis/CustomersApi.js +257 -7
  11. package/dist/openapi/apis/EventsApi.d.ts +16 -0
  12. package/dist/openapi/apis/EventsApi.js +67 -12
  13. package/dist/openapi/apis/InvoicesApi.d.ts +19 -3
  14. package/dist/openapi/apis/InvoicesApi.js +69 -3
  15. package/dist/openapi/apis/ProductConsumptionsApi.js +0 -3
  16. package/dist/openapi/apis/WebhooksApi.js +0 -3
  17. package/dist/openapi/http/http.d.ts +6 -18
  18. package/dist/openapi/http/http.js +25 -13
  19. package/dist/openapi/http/isomorphic-fetch.d.ts +1 -0
  20. package/dist/openapi/http/isomorphic-fetch.js +4 -7
  21. package/dist/openapi/index.d.ts +1 -1
  22. package/dist/openapi/index.js +3 -1
  23. package/dist/openapi/models/Address.d.ts +5 -5
  24. package/dist/openapi/models/CloudUsageResult.d.ts +83 -0
  25. package/dist/openapi/models/CloudUsageResult.js +103 -0
  26. package/dist/openapi/models/Contact.d.ts +3 -1
  27. package/dist/openapi/models/Contact.js +12 -0
  28. package/dist/openapi/models/ContractStatus.d.ts +23 -0
  29. package/dist/openapi/models/ContractStatus.js +27 -0
  30. package/dist/openapi/models/CreateCatalogProductRequest.d.ts +42 -0
  31. package/dist/openapi/models/CreateCatalogProductRequest.js +44 -0
  32. package/dist/openapi/models/CreateCatalogProductResponse.d.ts +32 -0
  33. package/dist/openapi/models/CreateCatalogProductResponse.js +32 -0
  34. package/dist/openapi/models/CreateCatalogProductResponseCatalogProduct.d.ts +45 -0
  35. package/dist/openapi/models/CreateCatalogProductResponseCatalogProduct.js +62 -0
  36. package/dist/openapi/models/CreateContractRequest.d.ts +47 -5
  37. package/dist/openapi/models/CreateContractRequest.js +65 -5
  38. package/dist/openapi/models/CreateCustomerRelationRequest.d.ts +38 -0
  39. package/dist/openapi/models/CreateCustomerRelationRequest.js +38 -0
  40. package/dist/openapi/models/CreateCustomerRelationResponse.d.ts +32 -0
  41. package/dist/openapi/models/CreateCustomerRelationResponse.js +32 -0
  42. package/dist/openapi/models/CreateCustomerRelationResponseCustomerRelation.d.ts +41 -0
  43. package/dist/openapi/models/CreateCustomerRelationResponseCustomerRelation.js +56 -0
  44. package/dist/openapi/models/CreateCustomerRequest.d.ts +50 -2
  45. package/dist/openapi/models/CreateCustomerRequest.js +82 -6
  46. package/dist/openapi/models/CreateCustomerResponseCustomer.d.ts +50 -2
  47. package/dist/openapi/models/CreateCustomerResponseCustomer.js +82 -6
  48. package/dist/openapi/models/CreditLedgerEntry.d.ts +3 -1
  49. package/dist/openapi/models/CreditLedgerEntry.js +8 -2
  50. package/dist/openapi/models/Currency.d.ts +24 -0
  51. package/dist/openapi/models/Currency.js +28 -0
  52. package/dist/openapi/models/CustomField.d.ts +65 -0
  53. package/dist/openapi/models/CustomField.js +78 -0
  54. package/dist/openapi/models/CustomFieldValue.d.ts +33 -0
  55. package/dist/openapi/models/CustomFieldValue.js +44 -0
  56. package/dist/openapi/models/CustomFieldValueTypes.d.ts +19 -0
  57. package/dist/openapi/models/CustomFieldValueTypes.js +23 -0
  58. package/dist/openapi/models/CustomerCloudProviderSettings.d.ts +39 -0
  59. package/dist/openapi/models/CustomerCloudProviderSettings.js +51 -0
  60. package/dist/openapi/models/CustomerSource.d.ts +21 -0
  61. package/dist/openapi/models/CustomerSource.js +25 -0
  62. package/dist/openapi/models/DeleteCatalogProductResponse.d.ts +32 -0
  63. package/dist/openapi/models/DeleteCatalogProductResponse.js +32 -0
  64. package/dist/openapi/models/DeleteCatalogProductResponseCatalogProduct.d.ts +46 -0
  65. package/dist/openapi/models/DeleteCatalogProductResponseCatalogProduct.js +68 -0
  66. package/dist/openapi/models/DeleteContractResponseContract.d.ts +47 -5
  67. package/dist/openapi/models/DeleteContractResponseContract.js +65 -5
  68. package/dist/openapi/models/DeleteCustomerResponseCustomer.d.ts +50 -2
  69. package/dist/openapi/models/DeleteCustomerResponseCustomer.js +82 -6
  70. package/dist/openapi/models/DeleteEventsByRefsRequest.d.ts +31 -0
  71. package/dist/openapi/models/DeleteEventsByRefsRequest.js +32 -0
  72. package/dist/openapi/models/DeleteEventsByRefsResponse.d.ts +35 -0
  73. package/dist/openapi/models/DeleteEventsByRefsResponse.js +32 -0
  74. package/dist/openapi/models/DeleteEventsByRefsResponseEventsInner.d.ts +56 -0
  75. package/dist/openapi/models/DeleteEventsByRefsResponseEventsInner.js +80 -0
  76. package/dist/openapi/models/ExternalOverageStrategy.d.ts +20 -0
  77. package/dist/openapi/models/ExternalOverageStrategy.js +24 -0
  78. package/dist/openapi/models/GetCatalogProductResponse.d.ts +32 -0
  79. package/dist/openapi/models/GetCatalogProductResponse.js +32 -0
  80. package/dist/openapi/models/GetContractByIntegrationIdResponse.d.ts +32 -0
  81. package/dist/openapi/models/GetContractByIntegrationIdResponse.js +32 -0
  82. package/dist/openapi/models/GetContractResponseContract.d.ts +47 -5
  83. package/dist/openapi/models/GetContractResponseContract.js +65 -5
  84. package/dist/openapi/models/GetCustomerByIntegrationIdResponse.d.ts +32 -0
  85. package/dist/openapi/models/GetCustomerByIntegrationIdResponse.js +32 -0
  86. package/dist/openapi/models/GetCustomerByNameResponse.d.ts +32 -0
  87. package/dist/openapi/models/GetCustomerByNameResponse.js +32 -0
  88. package/dist/openapi/models/GetCustomerByNameResponseCustomer.d.ts +103 -0
  89. package/dist/openapi/models/GetCustomerByNameResponseCustomer.js +153 -0
  90. package/dist/openapi/models/GetCustomerRelationResponse.d.ts +32 -0
  91. package/dist/openapi/models/GetCustomerRelationResponse.js +32 -0
  92. package/dist/openapi/models/GetInvoiceResponseInvoice.d.ts +14 -0
  93. package/dist/openapi/models/GetInvoiceResponseInvoice.js +30 -0
  94. package/dist/openapi/models/GetInvoiceResponseInvoiceRevenueBreakdown.d.ts +39 -0
  95. package/dist/openapi/models/GetInvoiceResponseInvoiceRevenueBreakdown.js +65 -0
  96. package/dist/openapi/models/IntegrationEntity.d.ts +42 -0
  97. package/dist/openapi/models/IntegrationEntity.js +62 -0
  98. package/dist/openapi/models/IntegrationEntityTypes.d.ts +23 -0
  99. package/dist/openapi/models/IntegrationEntityTypes.js +27 -0
  100. package/dist/openapi/models/IntegrationProviders.d.ts +26 -0
  101. package/dist/openapi/models/IntegrationProviders.js +30 -0
  102. package/dist/openapi/models/IntegrationType.d.ts +26 -0
  103. package/dist/openapi/models/IntegrationType.js +30 -0
  104. package/dist/openapi/models/InvoiceBillingStatus.d.ts +21 -0
  105. package/dist/openapi/models/InvoiceBillingStatus.js +25 -0
  106. package/dist/openapi/models/InvoicePaymentStatusResponse.d.ts +39 -0
  107. package/dist/openapi/models/InvoicePaymentStatusResponse.js +74 -0
  108. package/dist/openapi/models/ListCatalogProductsResponse.d.ts +35 -0
  109. package/dist/openapi/models/ListCatalogProductsResponse.js +50 -0
  110. package/dist/openapi/models/NotificationEventType.d.ts +3 -1
  111. package/dist/openapi/models/NotificationEventType.js +2 -0
  112. package/dist/openapi/models/ObjectSerializer.d.ts +61 -0
  113. package/dist/openapi/models/ObjectSerializer.js +191 -0
  114. package/dist/openapi/models/PartnerSubmissionDetail.d.ts +46 -0
  115. package/dist/openapi/models/PartnerSubmissionDetail.js +49 -0
  116. package/dist/openapi/models/PaymentInfo.d.ts +45 -0
  117. package/dist/openapi/models/PaymentInfo.js +89 -0
  118. package/dist/openapi/models/PaymentInfoDepositTo.d.ts +32 -0
  119. package/dist/openapi/models/PaymentInfoDepositTo.js +38 -0
  120. package/dist/openapi/models/PaymentTerm.d.ts +18 -0
  121. package/dist/openapi/models/PaymentTerm.js +22 -0
  122. package/dist/openapi/models/ProductCloudProviderSettings.d.ts +39 -0
  123. package/dist/openapi/models/ProductCloudProviderSettings.js +51 -0
  124. package/dist/openapi/models/ProductGroup.d.ts +65 -0
  125. package/dist/openapi/models/ProductGroup.js +80 -0
  126. package/dist/openapi/models/ProductGroupCommitment.d.ts +45 -0
  127. package/dist/openapi/models/ProductGroupCommitment.js +53 -0
  128. package/dist/openapi/models/ProductGroupProductsInner.d.ts +68 -0
  129. package/dist/openapi/models/ProductGroupProductsInner.js +98 -0
  130. package/dist/openapi/models/ProductGroupProductsInnerCommitment.d.ts +45 -0
  131. package/dist/openapi/models/ProductGroupProductsInnerCommitment.js +53 -0
  132. package/dist/openapi/models/ProductGroupProductsInnerCommitmentScheduling.d.ts +39 -0
  133. package/dist/openapi/models/ProductGroupProductsInnerCommitmentScheduling.js +41 -0
  134. package/dist/openapi/models/ProductGroupProductsInnerPricing.d.ts +36 -0
  135. package/dist/openapi/models/ProductGroupProductsInnerPricing.js +24 -0
  136. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf.d.ts +35 -0
  137. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf.js +42 -0
  138. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf1.d.ts +37 -0
  139. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf1.js +48 -0
  140. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf1InstallmentsInner.d.ts +32 -0
  141. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf1InstallmentsInner.js +38 -0
  142. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf2.d.ts +37 -0
  143. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf2.js +48 -0
  144. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf2SubscriptionCadence.d.ts +38 -0
  145. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf2SubscriptionCadence.js +45 -0
  146. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf3.d.ts +46 -0
  147. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf3.js +78 -0
  148. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf3SubscriptionCadence.d.ts +38 -0
  149. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf3SubscriptionCadence.js +45 -0
  150. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf3TiersInner.d.ts +35 -0
  151. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf3TiersInner.js +56 -0
  152. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf4.d.ts +41 -0
  153. package/dist/openapi/models/ProductGroupProductsInnerPricingOneOf4.js +60 -0
  154. package/dist/openapi/models/ProductGroupProductsInnerScheduling.d.ts +39 -0
  155. package/dist/openapi/models/ProductGroupProductsInnerScheduling.js +41 -0
  156. package/dist/openapi/models/ProductGroupProductsInnerSchedulingDuration.d.ts +41 -0
  157. package/dist/openapi/models/ProductGroupProductsInnerSchedulingDuration.js +48 -0
  158. package/dist/openapi/models/SubmitCloudUsageRequest.d.ts +39 -0
  159. package/dist/openapi/models/SubmitCloudUsageRequest.js +38 -0
  160. package/dist/openapi/models/SyncStatus.d.ts +16 -0
  161. package/dist/openapi/models/SyncStatus.js +20 -0
  162. package/dist/openapi/models/UpdateCatalogProductRequest.d.ts +42 -0
  163. package/dist/openapi/models/UpdateCatalogProductRequest.js +44 -0
  164. package/dist/openapi/models/UpdateCatalogProductResponse.d.ts +32 -0
  165. package/dist/openapi/models/UpdateCatalogProductResponse.js +32 -0
  166. package/dist/openapi/models/UpdateCustomerRequest.d.ts +50 -2
  167. package/dist/openapi/models/UpdateCustomerRequest.js +82 -6
  168. package/dist/openapi/models/UsageWindow.d.ts +41 -0
  169. package/dist/openapi/models/UsageWindow.js +41 -0
  170. package/dist/openapi/models/all.d.ts +61 -0
  171. package/dist/openapi/models/all.js +61 -0
  172. package/dist/openapi/types/ObservableAPI.d.ts +212 -12
  173. package/dist/openapi/types/ObservableAPI.js +424 -17
  174. package/dist/openapi/types/PromiseAPI.d.ts +208 -12
  175. package/dist/openapi/types/PromiseAPI.js +294 -34
  176. package/dist/sdk/clients/CatalogProductsClient.d.ts +11 -0
  177. package/dist/sdk/clients/CatalogProductsClient.js +28 -0
  178. package/dist/sdk/clients/CloudUsageSubmissionClient.d.ts +6 -0
  179. package/dist/sdk/clients/CloudUsageSubmissionClient.js +14 -0
  180. package/dist/sdk/clients/ContractsClient.d.ts +2 -1
  181. package/dist/sdk/clients/ContractsClient.js +3 -0
  182. package/dist/sdk/clients/CreditsClient.d.ts +9 -0
  183. package/dist/sdk/clients/CreditsClient.js +22 -0
  184. package/dist/sdk/clients/CustomersClient.d.ts +6 -1
  185. package/dist/sdk/clients/CustomersClient.js +15 -0
  186. package/dist/sdk/clients/EventsClient.d.ts +2 -1
  187. package/dist/sdk/clients/EventsClient.js +3 -0
  188. package/dist/sdk/clients/InvoicesClient.d.ts +1 -0
  189. package/dist/sdk/clients/InvoicesClient.js +3 -0
  190. package/dist/sdk/clients/MeasurementsClient.d.ts +10 -0
  191. package/dist/sdk/clients/MeasurementsClient.js +25 -0
  192. package/dist/sdk/clients/index.d.ts +4 -0
  193. package/dist/sdk/clients/index.js +4 -0
  194. package/dist/sdk/index.d.ts +6 -1
  195. package/dist/sdk/index.js +13 -0
  196. package/dist/sdk/services/authenticated-http-library.d.ts +11 -0
  197. package/dist/sdk/services/authenticated-http-library.js +29 -0
  198. package/dist/sdk/services/authenticator.d.ts +11 -0
  199. package/dist/sdk/services/authenticator.js +57 -0
  200. package/dist/sdk/services/configuration.service.d.ts +7 -6
  201. package/dist/sdk/services/configuration.service.js +12 -44
  202. package/dist/sdk/types/CatalogProducts.d.ts +1 -0
  203. package/dist/sdk/types/CatalogProducts.js +2 -0
  204. package/dist/sdk/types/CloudUsageSubmission.d.ts +1 -0
  205. package/dist/sdk/types/CloudUsageSubmission.js +2 -0
  206. package/dist/sdk/types/Contracts.d.ts +1 -1
  207. package/dist/sdk/types/Credits.d.ts +1 -0
  208. package/dist/sdk/types/Credits.js +2 -0
  209. package/dist/sdk/types/Customers.d.ts +1 -1
  210. package/dist/sdk/types/Events.d.ts +1 -1
  211. package/dist/sdk/types/Invoices.d.ts +1 -1
  212. package/dist/sdk/types/Measurements.d.ts +1 -0
  213. package/dist/sdk/types/Measurements.js +2 -0
  214. package/dist/sdk/types/index.d.ts +4 -0
  215. package/dist/sdk/types/index.js +4 -0
  216. package/dist/sdk-v2/services/configuration.service.js +16 -8
  217. package/package.json +3 -4
@@ -0,0 +1,10 @@
1
+ import type { CreateMeasurementRequest } from '../../openapi';
2
+ import type { PaginationOptions } from '../types';
3
+ export declare class MeasurementsClient {
4
+ private client;
5
+ constructor();
6
+ create(payload: CreateMeasurementRequest): Promise<import("../types").CreateMeasurementResponse>;
7
+ delete(id: string): Promise<import("../types").DeleteMeasurementResponse>;
8
+ get(id: string): Promise<import("../types").GetMeasurementResponse>;
9
+ list(pagination?: PaginationOptions): Promise<import("../types").ListMeasurementsResponse>;
10
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MeasurementsClient = void 0;
4
+ const openapi_1 = require("../../openapi");
5
+ const services_1 = require("../services");
6
+ class MeasurementsClient {
7
+ constructor() {
8
+ this.client = services_1.ConfigurationService.instance.generateNewClient(openapi_1.MeasurementsApi);
9
+ }
10
+ async create(payload) {
11
+ return this.client.createMeasurement(payload);
12
+ }
13
+ async delete(id) {
14
+ return this.client.deleteMeasurement(id);
15
+ }
16
+ async get(id) {
17
+ return this.client.getMeasurement(id);
18
+ }
19
+ async list(pagination) {
20
+ const cursor = pagination?.cursor;
21
+ const limit = pagination?.limit;
22
+ return this.client.listMeasurements(limit, cursor);
23
+ }
24
+ }
25
+ exports.MeasurementsClient = MeasurementsClient;
@@ -1,3 +1,5 @@
1
+ export * from './CatalogProductsClient';
2
+ export * from './CloudUsageSubmissionClient';
1
3
  export * from './ContractsClient';
2
4
  export * from './CustomersClient';
3
5
  export * from './EventsClient';
@@ -5,3 +7,5 @@ export * from './InvoicesClient';
5
7
  export * from './MetersClient';
6
8
  export * from './WebhooksClient';
7
9
  export * from './ProductsConsumptionsClient';
10
+ export * from './CreditsClient';
11
+ export * from './MeasurementsClient';
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./CatalogProductsClient"), exports);
18
+ __exportStar(require("./CloudUsageSubmissionClient"), exports);
17
19
  __exportStar(require("./ContractsClient"), exports);
18
20
  __exportStar(require("./CustomersClient"), exports);
19
21
  __exportStar(require("./EventsClient"), exports);
@@ -21,3 +23,5 @@ __exportStar(require("./InvoicesClient"), exports);
21
23
  __exportStar(require("./MetersClient"), exports);
22
24
  __exportStar(require("./WebhooksClient"), exports);
23
25
  __exportStar(require("./ProductsConsumptionsClient"), exports);
26
+ __exportStar(require("./CreditsClient"), exports);
27
+ __exportStar(require("./MeasurementsClient"), exports);
@@ -1,8 +1,11 @@
1
- import { ContractsClient, CustomersClient, EventsClient, InvoicesClient, MetersClient, WebhooksClient, ProductConsumptionsClient } from './clients';
1
+ import { CatalogProductsClient, CloudUsageSubmissionClient, ContractsClient, CreditsClient, CustomersClient, EventsClient, InvoicesClient, MeasurementsClient, MetersClient, WebhooksClient, ProductConsumptionsClient } from './clients';
2
2
  export declare class Vayu {
3
3
  private configurationManager;
4
4
  constructor(apiKey: string, baseUrl?: string);
5
+ /** @deprecated Authentication is now handled automatically. You can remove this call. */
5
6
  login(): Promise<void>;
7
+ get catalogProducts(): CatalogProductsClient;
8
+ get cloudUsageSubmission(): CloudUsageSubmissionClient;
6
9
  get events(): EventsClient;
7
10
  get customers(): CustomersClient;
8
11
  get meters(): MetersClient;
@@ -10,5 +13,7 @@ export declare class Vayu {
10
13
  get invoices(): InvoicesClient;
11
14
  get webhooks(): WebhooksClient;
12
15
  get productConsumptions(): ProductConsumptionsClient;
16
+ get credits(): CreditsClient;
17
+ get measurements(): MeasurementsClient;
13
18
  }
14
19
  export * from './types';
package/dist/sdk/index.js CHANGED
@@ -22,9 +22,16 @@ class Vayu {
22
22
  const baseServer = services_1.ConfigurationService.generateServerConfiguration(baseUrl);
23
23
  this.configurationManager = services_1.ConfigurationService.initialize(apiKey, baseServer);
24
24
  }
25
+ /** @deprecated Authentication is now handled automatically. You can remove this call. */
25
26
  async login() {
26
27
  await this.configurationManager.generateToken();
27
28
  }
29
+ get catalogProducts() {
30
+ return new clients_1.CatalogProductsClient();
31
+ }
32
+ get cloudUsageSubmission() {
33
+ return new clients_1.CloudUsageSubmissionClient();
34
+ }
28
35
  get events() {
29
36
  return new clients_1.EventsClient();
30
37
  }
@@ -46,6 +53,12 @@ class Vayu {
46
53
  get productConsumptions() {
47
54
  return new clients_1.ProductConsumptionsClient();
48
55
  }
56
+ get credits() {
57
+ return new clients_1.CreditsClient();
58
+ }
59
+ get measurements() {
60
+ return new clients_1.MeasurementsClient();
61
+ }
49
62
  }
50
63
  exports.Vayu = Vayu;
51
64
  __exportStar(require("./types"), exports);
@@ -0,0 +1,11 @@
1
+ import type { HttpLibrary, RequestContext, ResponseContext } from '../../openapi/http/http';
2
+ import type { Observable } from '../../openapi/rxjsStub';
3
+ import type { VayuAuthenticator } from './authenticator';
4
+ export declare class AuthenticatedHttpLibrary implements HttpLibrary {
5
+ private readonly authenticator;
6
+ private readonly clientId;
7
+ private readonly inner;
8
+ constructor(authenticator: VayuAuthenticator, clientId: string);
9
+ send(request: RequestContext): Observable<ResponseContext>;
10
+ private sendWithRetry;
11
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthenticatedHttpLibrary = void 0;
4
+ const isomorphic_fetch_1 = require("../../openapi/http/isomorphic-fetch");
5
+ const rxjsStub_1 = require("../../openapi/rxjsStub");
6
+ class AuthenticatedHttpLibrary {
7
+ constructor(authenticator, clientId) {
8
+ this.authenticator = authenticator;
9
+ this.clientId = clientId;
10
+ this.inner = new isomorphic_fetch_1.IsomorphicFetchHttpLibrary();
11
+ }
12
+ send(request) {
13
+ return (0, rxjsStub_1.from)(this.sendWithRetry(request));
14
+ }
15
+ async sendWithRetry(request) {
16
+ const token = await this.authenticator.ensureValidToken();
17
+ request.setHeaderParam('Authorization', `Bearer ${token}`);
18
+ request.setHeaderParam('x-api-key', this.clientId);
19
+ const response = await this.inner.send(request).toPromise();
20
+ if (response.httpStatusCode === 401) {
21
+ await this.authenticator.authenticate();
22
+ const freshToken = await this.authenticator.ensureValidToken();
23
+ request.setHeaderParam('Authorization', `Bearer ${freshToken}`);
24
+ return this.inner.send(request).toPromise();
25
+ }
26
+ return response;
27
+ }
28
+ }
29
+ exports.AuthenticatedHttpLibrary = AuthenticatedHttpLibrary;
@@ -0,0 +1,11 @@
1
+ import type { BaseServerConfiguration } from '../../openapi';
2
+ export declare class VayuAuthenticator {
3
+ private readonly apiKey;
4
+ private readonly baseServer;
5
+ private accessToken;
6
+ private expiresAt;
7
+ constructor(apiKey: string, baseServer: BaseServerConfiguration);
8
+ get token(): string | undefined;
9
+ ensureValidToken(): Promise<string>;
10
+ authenticate(): Promise<void>;
11
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VayuAuthenticator = void 0;
4
+ const openapi_1 = require("../../openapi");
5
+ const EXPIRATION_THRESHOLD_MS = 1000 * 60 * 5;
6
+ class VayuAuthenticator {
7
+ constructor(apiKey, baseServer) {
8
+ this.apiKey = apiKey;
9
+ this.baseServer = baseServer;
10
+ this.expiresAt = 0;
11
+ }
12
+ get token() {
13
+ return this.accessToken;
14
+ }
15
+ async ensureValidToken() {
16
+ if (!this.accessToken || this.expiresAt <= Date.now() + EXPIRATION_THRESHOLD_MS) {
17
+ await this.authenticate();
18
+ }
19
+ if (!this.accessToken) {
20
+ throw new Error('Authentication failed: no access token available');
21
+ }
22
+ return this.accessToken;
23
+ }
24
+ async authenticate() {
25
+ const authClient = new openapi_1.AuthApi((0, openapi_1.createConfiguration)({
26
+ baseServer: this.baseServer,
27
+ }));
28
+ const login = await authClient.login({
29
+ refreshToken: this.apiKey,
30
+ });
31
+ this.accessToken = login.accessToken;
32
+ const payload = decodeJwtPayload(this.accessToken);
33
+ if (!payload) {
34
+ throw new Error('Invalid JWT token');
35
+ }
36
+ this.expiresAt = calculateJwtExpirationMs(payload.exp);
37
+ }
38
+ }
39
+ exports.VayuAuthenticator = VayuAuthenticator;
40
+ function decodeJwtPayload(token) {
41
+ const parts = token.split('.');
42
+ if (parts.length !== 3)
43
+ return null;
44
+ try {
45
+ const payload = Buffer.from(parts[1], 'base64url').toString('utf-8');
46
+ return JSON.parse(payload);
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ }
52
+ function calculateJwtExpirationMs(decodedJwtExpiration) {
53
+ const expirationSeconds = decodedJwtExpiration != null
54
+ ? decodedJwtExpiration
55
+ : Math.floor(Date.now() / 1000) + 60 * 15;
56
+ return expirationSeconds * 1000;
57
+ }
@@ -1,22 +1,23 @@
1
1
  import type { BaseServerConfiguration, Configuration } from '../../openapi';
2
2
  export declare class ConfigurationService {
3
- private apiKey;
4
3
  private baseServer;
5
4
  private static _instance;
6
5
  static get instance(): ConfigurationService;
7
6
  static initialize(apiKey: string, baseServer: BaseServerConfiguration): ConfigurationService;
8
7
  static generateServerConfiguration(baseUrl?: string): BaseServerConfiguration;
9
- private accessToken;
10
- private clientId;
11
- private expiresAt;
8
+ private readonly authenticator;
9
+ private readonly clientId;
12
10
  constructor(apiKey: string, baseServer: BaseServerConfiguration);
13
11
  generateNewClient<T extends {
14
12
  new (config: Configuration): InstanceType<T>;
15
13
  }>(ClientClass: T): InstanceType<T>;
14
+ /** @deprecated Authentication is now handled automatically.
15
+ * Note: expiresAt is no longer returned — use authenticator directly if needed. */
16
16
  generateToken(): Promise<{
17
- accessToken: string;
18
- expiresAt: number | undefined;
17
+ accessToken: string | undefined;
18
+ expiresAt: undefined;
19
19
  }>;
20
+ /** @deprecated Authentication is now handled automatically. */
20
21
  validateIsLoggedIn(): void;
21
22
  private get configuration();
22
23
  }
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ConfigurationService = void 0;
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
4
  const openapi_1 = require("../../openapi");
9
5
  const utils_1 = require("../utils");
6
+ const authenticator_1 = require("./authenticator");
7
+ const authenticated_http_library_1 = require("./authenticated-http-library");
10
8
  const CLIENT_ID_ENV_VAR_NAME = 'CLIENT_ID';
11
- const EXPIRATION_THRESHOLD = 1000 * 60 * 5;
12
9
  const BASE_URLS_MAP = new Map([
13
10
  ['https://connect.withvayu.com', openapi_1.server1],
14
11
  ['https://staging-connect.withvayu.com', openapi_1.server2],
@@ -36,59 +33,30 @@ class ConfigurationService {
36
33
  return baseServer ?? new openapi_1.ServerConfiguration(baseUrl, {});
37
34
  }
38
35
  constructor(apiKey, baseServer) {
39
- this.apiKey = apiKey;
40
36
  this.baseServer = baseServer;
41
- this.expiresAt = Date.now();
37
+ this.authenticator = new authenticator_1.VayuAuthenticator(apiKey, baseServer);
42
38
  this.clientId = (0, utils_1.getRequiredEnvVar)(CLIENT_ID_ENV_VAR_NAME);
43
39
  }
44
40
  generateNewClient(ClientClass) {
45
- this.validateIsLoggedIn();
46
- const newClient = new ClientClass(this.configuration);
47
- return newClient;
41
+ return new ClientClass(this.configuration);
48
42
  }
43
+ /** @deprecated Authentication is now handled automatically.
44
+ * Note: expiresAt is no longer returned — use authenticator directly if needed. */
49
45
  async generateToken() {
50
- const authClient = new openapi_1.AuthApi((0, openapi_1.createConfiguration)({
51
- baseServer: this.baseServer,
52
- }));
53
- const login = await authClient.login({
54
- refreshToken: this.apiKey,
55
- });
56
- this.accessToken = login.accessToken;
57
- const decodedJWT = jsonwebtoken_1.default.decode(this.accessToken);
58
- if (!decodedJWT) {
59
- throw new Error('Invalid JWT token');
60
- }
61
- this.expiresAt = (decodedJWT.exp ?? Math.floor(Date.now() / 1000) + 60 * 15) * 1000;
46
+ await this.authenticator.authenticate();
62
47
  return {
63
- accessToken: login.accessToken,
64
- expiresAt: decodedJWT.exp,
48
+ accessToken: this.authenticator.token,
49
+ expiresAt: undefined,
65
50
  };
66
51
  }
52
+ /** @deprecated Authentication is now handled automatically. */
67
53
  validateIsLoggedIn() {
68
- if (!this.accessToken) {
69
- throw new Error('Please login first');
70
- }
54
+ // No-op: login is handled lazily by authenticator
71
55
  }
72
56
  get configuration() {
73
57
  return (0, openapi_1.createConfiguration)({
74
58
  baseServer: this.baseServer,
75
- authMethods: {
76
- default: {
77
- getName: () => 'Logged In',
78
- applySecurityAuthentication: () => this.validateIsLoggedIn(),
79
- },
80
- },
81
- promiseMiddleware: [{
82
- pre: async (context) => {
83
- if (this.expiresAt <= Date.now() + EXPIRATION_THRESHOLD) {
84
- await this.generateToken();
85
- }
86
- context.setHeaderParam('Authorization', `Bearer ${this.accessToken}`);
87
- context.setHeaderParam('x-api-key', this.clientId);
88
- return context;
89
- },
90
- post: async (context) => (context),
91
- }],
59
+ httpApi: new authenticated_http_library_1.AuthenticatedHttpLibrary(this.authenticator, this.clientId),
92
60
  });
93
61
  }
94
62
  }
@@ -0,0 +1 @@
1
+ export type { CreateCatalogProductResponseCatalogProduct as CatalogProduct, CreateCatalogProductRequest, CreateCatalogProductResponse, DeleteCatalogProductResponse, GetCatalogProductResponse, ListCatalogProductsResponse, UpdateCatalogProductRequest, UpdateCatalogProductResponse, } from '../../openapi';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export type { SubmitCloudUsageRequest, } from '../../openapi';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- export type { GetContractResponseContract as Contract, ListContractsResponse, GetContractResponse, CreateContractRequest, CreateContractResponse, DeleteContractResponse, } from '../../openapi';
1
+ export type { GetContractResponseContract as Contract, GetContractByIntegrationIdResponse, ListContractsResponse, GetContractResponse, CreateContractRequest, CreateContractResponse, DeleteContractResponse, } from '../../openapi';
@@ -0,0 +1 @@
1
+ export type { DeductCreditsRequest, GrantCreditsRequest, ListCreditLedgerEntriesResponse, } from '../../openapi';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- export type { CreateCustomerResponseCustomer as Customer, CreateCustomerRequest, CreateCustomerResponse, DeleteCustomerResponse, GetCustomerResponse, ListCustomersResponse, UpdateCustomerRequest, UpdateCustomerResponse, } from '../../openapi';
1
+ export type { CreateCustomerResponseCustomer as Customer, CreateCustomerRequest, CreateCustomerResponse, CreateCustomerRelationRequest, CreateCustomerRelationResponse, CreateCustomerRelationResponseCustomerRelation as CustomerRelation, DeleteCustomerResponse, GetCustomerByIntegrationIdResponse, GetCustomerByNameResponse, GetCustomerRelationResponse, GetCustomerResponse, ListCustomersResponse, UpdateCustomerRequest, UpdateCustomerResponse, } from '../../openapi';
@@ -1 +1 @@
1
- export type { GetEventResponse, DeleteEventResponse, QueryEventsResponse, Event, SendEventsResponse, EventsDryRunResponse, } from '../../openapi';
1
+ export type { GetEventResponse, DeleteEventResponse, DeleteEventsByRefsRequest, DeleteEventsByRefsResponse, QueryEventsResponse, Event, SendEventsResponse, EventsDryRunResponse, } from '../../openapi';
@@ -1 +1 @@
1
- export type { GetInvoiceResponseInvoice as Invoice, ListInvoicesResponse, GetInvoiceResponse, } from '../../openapi';
1
+ export type { GetInvoiceResponseInvoice as Invoice, InvoicePaymentStatusResponse, ListInvoicesResponse, GetInvoiceResponse, } from '../../openapi';
@@ -0,0 +1 @@
1
+ export type { CreateMeasurementRequest, CreateMeasurementResponse, DeleteMeasurementResponse, GetMeasurementResponse, ListMeasurementsResponse, } from '../../openapi';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,10 @@
1
1
  export * from './pagination-options';
2
+ export * from './CatalogProducts';
3
+ export * from './CloudUsageSubmission';
2
4
  export * from './Contracts';
3
5
  export * from './Customers';
4
6
  export * from './Events';
5
7
  export * from './Invoices';
6
8
  export * from './Meters';
9
+ export * from './Credits';
10
+ export * from './Measurements';
@@ -15,8 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./pagination-options"), exports);
18
+ __exportStar(require("./CatalogProducts"), exports);
19
+ __exportStar(require("./CloudUsageSubmission"), exports);
18
20
  __exportStar(require("./Contracts"), exports);
19
21
  __exportStar(require("./Customers"), exports);
20
22
  __exportStar(require("./Events"), exports);
21
23
  __exportStar(require("./Invoices"), exports);
22
24
  __exportStar(require("./Meters"), exports);
25
+ __exportStar(require("./Credits"), exports);
26
+ __exportStar(require("./Measurements"), exports);
@@ -1,12 +1,20 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.ConfigurationService = void 0;
7
- const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
4
  const openapi_v2_1 = require("../../openapi-v2");
9
5
  const EXPIRATION_THRESHOLD = 1000 * 60 * 5;
6
+ function decodeJwtPayload(token) {
7
+ const parts = token.split('.');
8
+ if (parts.length !== 3)
9
+ return null;
10
+ try {
11
+ const payload = Buffer.from(parts[1], 'base64url').toString('utf-8');
12
+ return JSON.parse(payload);
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ }
10
18
  const BASE_URLS_MAP = new Map([]);
11
19
  /* eslint-disable no-underscore-dangle */
12
20
  class ConfigurationService {
@@ -45,14 +53,14 @@ class ConfigurationService {
45
53
  refreshToken: this.apiKey,
46
54
  });
47
55
  this.accessToken = login.accessToken;
48
- const decodedJWT = jsonwebtoken_1.default.decode(this.accessToken);
49
- if (!decodedJWT) {
56
+ const payload = decodeJwtPayload(this.accessToken);
57
+ if (!payload) {
50
58
  throw new Error('Invalid JWT token');
51
59
  }
52
- this.expiresAt = (decodedJWT.exp ?? Math.floor(Date.now() / 1000) + 60 * 15) * 1000;
60
+ this.expiresAt = (payload.exp ?? Math.floor(Date.now() / 1000) + 60 * 15) * 1000;
53
61
  return {
54
62
  accessToken: login.accessToken,
55
- expiresAt: decodedJWT.exp,
63
+ expiresAt: payload.exp,
56
64
  };
57
65
  }
58
66
  validateIsLoggedIn() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vayu-ts",
3
- "version": "0.2.14",
3
+ "version": "0.3.4",
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",
@@ -49,12 +49,11 @@
49
49
  "@types/node-fetch": "^2.5.7",
50
50
  "es6-promise": "^4.2.4",
51
51
  "form-data": "^2.5.0",
52
- "jsonwebtoken": "^9.0.2",
53
52
  "node-fetch": "^2.6.0",
54
- "url-parse": "^1.4.3"
53
+ "url-parse": "^1.4.3",
54
+ "whatwg-fetch": "^3.6.20"
55
55
  },
56
56
  "devDependencies": {
57
- "@types/jsonwebtoken": "^9.0.7",
58
57
  "@types/url-parse": "1.4.4",
59
58
  "@typescript-eslint/eslint-plugin": "^5.58.0",
60
59
  "@typescript-eslint/parser": "5.58.0",