@rasadov/lumoar-sdk 2.0.1 → 2.0.2

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/dist/index.d.ts CHANGED
@@ -11,3 +11,4 @@
11
11
  */
12
12
  export * from "./api";
13
13
  export * from "./configuration";
14
+ export * from "./sdk";
package/dist/index.js CHANGED
@@ -13,3 +13,4 @@
13
13
  */
14
14
  export * from "./api";
15
15
  export * from "./configuration";
16
+ export * from "./sdk";
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ import { APIKeysApi, AssetsApi, AuditLogsApi, AuthApi, CompanyApi, ControlsApi, EvidenceApi, FrameworksApi, HealthApi, IntegrationsApi, PaymentsApi, ReportsApi, RisksApi, RolesApi, TasksApi, UserApi, V2Api, VendorContactsApi, VendorDocumentsApi, VendorRiskAssessmentsApi, VendorsApi } from './api';
2
+ export declare class ApiSDK {
3
+ private aPIKeysApi;
4
+ private assetsApi;
5
+ private auditLogsApi;
6
+ private authApi;
7
+ private companyApi;
8
+ private controlsApi;
9
+ private evidenceApi;
10
+ private frameworksApi;
11
+ private healthApi;
12
+ private integrationsApi;
13
+ private paymentsApi;
14
+ private reportsApi;
15
+ private risksApi;
16
+ private rolesApi;
17
+ private tasksApi;
18
+ private userApi;
19
+ private v2Api;
20
+ private vendorContactsApi;
21
+ private vendorDocumentsApi;
22
+ private vendorRiskAssessmentsApi;
23
+ private vendorsApi;
24
+ private token;
25
+ private axiosInstance;
26
+ constructor(basePath?: string);
27
+ setToken(newToken: string): void;
28
+ private getAuthHeader;
29
+ private setupInterceptors;
30
+ getApi(): {
31
+ aPIKeysApi: APIKeysApi;
32
+ assetsApi: AssetsApi;
33
+ auditLogsApi: AuditLogsApi;
34
+ authApi: AuthApi;
35
+ companyApi: CompanyApi;
36
+ controlsApi: ControlsApi;
37
+ evidenceApi: EvidenceApi;
38
+ frameworksApi: FrameworksApi;
39
+ healthApi: HealthApi;
40
+ integrationsApi: IntegrationsApi;
41
+ paymentsApi: PaymentsApi;
42
+ reportsApi: ReportsApi;
43
+ risksApi: RisksApi;
44
+ rolesApi: RolesApi;
45
+ tasksApi: TasksApi;
46
+ userApi: UserApi;
47
+ v2Api: V2Api;
48
+ vendorContactsApi: VendorContactsApi;
49
+ vendorDocumentsApi: VendorDocumentsApi;
50
+ vendorRiskAssessmentsApi: VendorRiskAssessmentsApi;
51
+ vendorsApi: VendorsApi;
52
+ };
53
+ }
package/dist/sdk.js ADDED
@@ -0,0 +1,97 @@
1
+ import axios from 'axios';
2
+ import { APIKeysApi, AssetsApi, AuditLogsApi, AuthApi, CompanyApi, ControlsApi, EvidenceApi, FrameworksApi, HealthApi, IntegrationsApi, PaymentsApi, ReportsApi, RisksApi, RolesApi, TasksApi, UserApi, V2Api, VendorContactsApi, VendorDocumentsApi, VendorRiskAssessmentsApi, VendorsApi } from './api';
3
+ import { Configuration } from './configuration';
4
+ export class ApiSDK {
5
+ constructor(basePath) {
6
+ this.token = null;
7
+ this.axiosInstance = axios.create({
8
+ baseURL: basePath,
9
+ withCredentials: true
10
+ });
11
+ this.setupInterceptors();
12
+ const config = new Configuration({
13
+ basePath,
14
+ apiKey: () => this.getAuthHeader(),
15
+ baseOptions: {
16
+ axios: this.axiosInstance
17
+ },
18
+ });
19
+ this.aPIKeysApi = new APIKeysApi(config, undefined, this.axiosInstance);
20
+ this.assetsApi = new AssetsApi(config, undefined, this.axiosInstance);
21
+ this.auditLogsApi = new AuditLogsApi(config, undefined, this.axiosInstance);
22
+ this.authApi = new AuthApi(config, undefined, this.axiosInstance);
23
+ this.companyApi = new CompanyApi(config, undefined, this.axiosInstance);
24
+ this.controlsApi = new ControlsApi(config, undefined, this.axiosInstance);
25
+ this.evidenceApi = new EvidenceApi(config, undefined, this.axiosInstance);
26
+ this.frameworksApi = new FrameworksApi(config, undefined, this.axiosInstance);
27
+ this.healthApi = new HealthApi(config, undefined, this.axiosInstance);
28
+ this.integrationsApi = new IntegrationsApi(config, undefined, this.axiosInstance);
29
+ this.paymentsApi = new PaymentsApi(config, undefined, this.axiosInstance);
30
+ this.reportsApi = new ReportsApi(config, undefined, this.axiosInstance);
31
+ this.risksApi = new RisksApi(config, undefined, this.axiosInstance);
32
+ this.rolesApi = new RolesApi(config, undefined, this.axiosInstance);
33
+ this.tasksApi = new TasksApi(config, undefined, this.axiosInstance);
34
+ this.userApi = new UserApi(config, undefined, this.axiosInstance);
35
+ this.v2Api = new V2Api(config, undefined, this.axiosInstance);
36
+ this.vendorContactsApi = new VendorContactsApi(config, undefined, this.axiosInstance);
37
+ this.vendorDocumentsApi = new VendorDocumentsApi(config, undefined, this.axiosInstance);
38
+ this.vendorRiskAssessmentsApi = new VendorRiskAssessmentsApi(config, undefined, this.axiosInstance);
39
+ this.vendorsApi = new VendorsApi(config, undefined, this.axiosInstance);
40
+ }
41
+ setToken(newToken) {
42
+ this.token = newToken;
43
+ }
44
+ getAuthHeader() {
45
+ if (!this.token) {
46
+ throw new Error('No token set. Call setToken() first.');
47
+ }
48
+ return `Bearer ${this.token}`;
49
+ }
50
+ setupInterceptors() {
51
+ this.axiosInstance.interceptors.request.use((config) => {
52
+ if (this.token) {
53
+ config.headers['Authorization'] = this.getAuthHeader();
54
+ }
55
+ return config;
56
+ });
57
+ this.axiosInstance.interceptors.response.use((response) => {
58
+ const newToken = response.data.newToken || response.headers['Authorization'];
59
+ if (newToken) {
60
+ this.setToken(newToken.replace('Bearer ', ''));
61
+ console.log('Token automatically updated via backend refresh');
62
+ }
63
+ return response;
64
+ }, (error) => {
65
+ var _a;
66
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
67
+ console.error('Authentication failed - session expired');
68
+ }
69
+ return Promise.reject(error);
70
+ });
71
+ }
72
+ getApi() {
73
+ return {
74
+ aPIKeysApi: this.aPIKeysApi,
75
+ assetsApi: this.assetsApi,
76
+ auditLogsApi: this.auditLogsApi,
77
+ authApi: this.authApi,
78
+ companyApi: this.companyApi,
79
+ controlsApi: this.controlsApi,
80
+ evidenceApi: this.evidenceApi,
81
+ frameworksApi: this.frameworksApi,
82
+ healthApi: this.healthApi,
83
+ integrationsApi: this.integrationsApi,
84
+ paymentsApi: this.paymentsApi,
85
+ reportsApi: this.reportsApi,
86
+ risksApi: this.risksApi,
87
+ rolesApi: this.rolesApi,
88
+ tasksApi: this.tasksApi,
89
+ userApi: this.userApi,
90
+ v2Api: this.v2Api,
91
+ vendorContactsApi: this.vendorContactsApi,
92
+ vendorDocumentsApi: this.vendorDocumentsApi,
93
+ vendorRiskAssessmentsApi: this.vendorRiskAssessmentsApi,
94
+ vendorsApi: this.vendorsApi,
95
+ };
96
+ }
97
+ }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@rasadov/lumoar-sdk",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Lumoar API SDK for dashboard use (session-based authentication)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist",
9
9
  "openapi.json",
10
- "README.md"
10
+ "README.md",
11
+ "sdk.ts"
11
12
  ],
12
13
  "scripts": {
13
14
  "build": "tsc",
@@ -36,4 +37,4 @@
36
37
  "@types/node": "^24.5.2",
37
38
  "typescript": "^5.9.2"
38
39
  }
39
- }
40
+ }
package/sdk.ts ADDED
@@ -0,0 +1,148 @@
1
+ import axios, { AxiosInstance, AxiosResponse } from 'axios';
2
+ import {
3
+ APIKeysApi,
4
+ AssetsApi,
5
+ AuditLogsApi,
6
+ AuthApi,
7
+ CompanyApi,
8
+ ControlsApi,
9
+ EvidenceApi,
10
+ FrameworksApi,
11
+ HealthApi,
12
+ IntegrationsApi,
13
+ PaymentsApi,
14
+ ReportsApi,
15
+ RisksApi,
16
+ RolesApi,
17
+ TasksApi,
18
+ UserApi,
19
+ V2Api,
20
+ VendorContactsApi,
21
+ VendorDocumentsApi,
22
+ VendorRiskAssessmentsApi,
23
+ VendorsApi
24
+ } from './api';
25
+ import { Configuration } from './configuration';
26
+
27
+ export class ApiSDK {
28
+ private aPIKeysApi: APIKeysApi;
29
+ private assetsApi: AssetsApi;
30
+ private auditLogsApi: AuditLogsApi;
31
+ private authApi: AuthApi;
32
+ private companyApi: CompanyApi;
33
+ private controlsApi: ControlsApi;
34
+ private evidenceApi: EvidenceApi;
35
+ private frameworksApi: FrameworksApi;
36
+ private healthApi: HealthApi;
37
+ private integrationsApi: IntegrationsApi;
38
+ private paymentsApi: PaymentsApi;
39
+ private reportsApi: ReportsApi;
40
+ private risksApi: RisksApi;
41
+ private rolesApi: RolesApi;
42
+ private tasksApi: TasksApi;
43
+ private userApi: UserApi;
44
+ private v2Api: V2Api;
45
+ private vendorContactsApi: VendorContactsApi;
46
+ private vendorDocumentsApi: VendorDocumentsApi;
47
+ private vendorRiskAssessmentsApi: VendorRiskAssessmentsApi;
48
+ private vendorsApi: VendorsApi;
49
+ private token: string | null = null;
50
+ private axiosInstance: AxiosInstance;
51
+
52
+ constructor(basePath?: string) {
53
+ this.axiosInstance = axios.create({
54
+ baseURL: basePath,
55
+ withCredentials: true
56
+ });
57
+ this.setupInterceptors();
58
+ const config = new Configuration({
59
+ basePath,
60
+ apiKey: () => this.getAuthHeader(),
61
+ baseOptions: {
62
+ axios: this.axiosInstance
63
+ },
64
+ });
65
+
66
+ this.aPIKeysApi = new APIKeysApi(config, undefined, this.axiosInstance);
67
+ this.assetsApi = new AssetsApi(config, undefined, this.axiosInstance);
68
+ this.auditLogsApi = new AuditLogsApi(config, undefined, this.axiosInstance);
69
+ this.authApi = new AuthApi(config, undefined, this.axiosInstance);
70
+ this.companyApi = new CompanyApi(config, undefined, this.axiosInstance);
71
+ this.controlsApi = new ControlsApi(config, undefined, this.axiosInstance);
72
+ this.evidenceApi = new EvidenceApi(config, undefined, this.axiosInstance);
73
+ this.frameworksApi = new FrameworksApi(config, undefined, this.axiosInstance);
74
+ this.healthApi = new HealthApi(config, undefined, this.axiosInstance);
75
+ this.integrationsApi = new IntegrationsApi(config, undefined, this.axiosInstance);
76
+ this.paymentsApi = new PaymentsApi(config, undefined, this.axiosInstance);
77
+ this.reportsApi = new ReportsApi(config, undefined, this.axiosInstance);
78
+ this.risksApi = new RisksApi(config, undefined, this.axiosInstance);
79
+ this.rolesApi = new RolesApi(config, undefined, this.axiosInstance);
80
+ this.tasksApi = new TasksApi(config, undefined, this.axiosInstance);
81
+ this.userApi = new UserApi(config, undefined, this.axiosInstance);
82
+ this.v2Api = new V2Api(config, undefined, this.axiosInstance);
83
+ this.vendorContactsApi = new VendorContactsApi(config, undefined, this.axiosInstance);
84
+ this.vendorDocumentsApi = new VendorDocumentsApi(config, undefined, this.axiosInstance);
85
+ this.vendorRiskAssessmentsApi = new VendorRiskAssessmentsApi(config, undefined, this.axiosInstance);
86
+ this.vendorsApi = new VendorsApi(config, undefined, this.axiosInstance);
87
+ }
88
+
89
+ public setToken(newToken: string) {
90
+ this.token = newToken;
91
+ }
92
+
93
+ private getAuthHeader(): string {
94
+ if (!this.token) {
95
+ throw new Error('No token set. Call setToken() first.');
96
+ }
97
+ return `Bearer ${this.token}`;
98
+ }
99
+
100
+ private setupInterceptors() {
101
+ this.axiosInstance.interceptors.request.use((config) => {
102
+ if (this.token) {
103
+ config.headers['Authorization'] = this.getAuthHeader();
104
+ }
105
+ return config;
106
+ });
107
+
108
+ this.axiosInstance.interceptors.response.use((response: AxiosResponse) => {
109
+ const newToken = response.data.newToken || response.headers['Authorization'];
110
+ if (newToken) {
111
+ this.setToken(newToken.replace('Bearer ', ''));
112
+ console.log('Token automatically updated via backend refresh');
113
+ }
114
+ return response;
115
+ }, (error) => {
116
+ if (error.response?.status === 401) {
117
+ console.error('Authentication failed - session expired');
118
+ }
119
+ return Promise.reject(error);
120
+ });
121
+ }
122
+
123
+ public getApi() {
124
+ return {
125
+ aPIKeysApi: this.aPIKeysApi,
126
+ assetsApi: this.assetsApi,
127
+ auditLogsApi: this.auditLogsApi,
128
+ authApi: this.authApi,
129
+ companyApi: this.companyApi,
130
+ controlsApi: this.controlsApi,
131
+ evidenceApi: this.evidenceApi,
132
+ frameworksApi: this.frameworksApi,
133
+ healthApi: this.healthApi,
134
+ integrationsApi: this.integrationsApi,
135
+ paymentsApi: this.paymentsApi,
136
+ reportsApi: this.reportsApi,
137
+ risksApi: this.risksApi,
138
+ rolesApi: this.rolesApi,
139
+ tasksApi: this.tasksApi,
140
+ userApi: this.userApi,
141
+ v2Api: this.v2Api,
142
+ vendorContactsApi: this.vendorContactsApi,
143
+ vendorDocumentsApi: this.vendorDocumentsApi,
144
+ vendorRiskAssessmentsApi: this.vendorRiskAssessmentsApi,
145
+ vendorsApi: this.vendorsApi,
146
+ };
147
+ }
148
+ }