1
- import axios , { AxiosInstance } from "axios" ;
1
+ import { AxiosInstance } from "axios" ;
2
2
import CryptlexWebApiClientOptions from "./client-options.js" ;
3
+ import { HttpClient } from "./http-client.js" ;
3
4
4
5
import { ApiResponse } from "./services/api.types.js" ;
5
6
import { LicenseService } from "./services/license.service.js" ;
@@ -26,16 +27,10 @@ export default class CryptlexWebApiClient {
26
27
/**
27
28
* HttpClient to communicate with the Cryptlex Web API
28
29
*/
29
- httpClient : AxiosInstance ;
30
+ httpClientInstance : AxiosInstance ;
30
31
31
32
constructor ( options : CryptlexWebApiClientOptions ) {
32
- this . httpClient = axios . create ( {
33
- baseURL : options . baseUrl ,
34
- timeout : options . timeout ,
35
- headers : {
36
- Authorization : `Bearer ${ options . accessToken } ` ,
37
- } ,
38
- } ) ;
33
+ this . httpClientInstance = new HttpClient ( options ) . instance ;
39
34
}
40
35
41
36
/**
@@ -46,7 +41,24 @@ export default class CryptlexWebApiClient {
46
41
createLicense (
47
42
license : LicenseCreateRequest
48
43
) : Promise < ApiResponse < LicenseResponse > > {
49
- return LicenseService . createLicense ( this . httpClient , license ) ;
44
+ return LicenseService . createLicense ( this . httpClientInstance , license ) ;
45
+ }
46
+
47
+ /**
48
+ * Create multiple licenses
49
+ * @param {LicenseCreateRequest } license License object to create
50
+ * @param {number } count Number of licenses to create
51
+ * @returns {Promise<ApiResponse<LicenseResponse>[]> } Promise that resolves to an array of Web API responses.
52
+ */
53
+ createLicenses (
54
+ license : LicenseCreateRequest ,
55
+ count : number
56
+ ) : Promise < ApiResponse < LicenseResponse > [ ] > {
57
+ return Promise . all (
58
+ Array . from ( { length : count } , ( ) => {
59
+ return LicenseService . createLicense ( this . httpClientInstance , license ) ;
60
+ } )
61
+ ) ;
50
62
}
51
63
52
64
/**
@@ -60,7 +72,7 @@ export default class CryptlexWebApiClient {
60
72
id : string ,
61
73
license : LicenseUpdateRequest
62
74
) : Promise < ApiResponse < LicenseResponse > > {
63
- return LicenseService . updateLicense ( this . httpClient , id , license ) ;
75
+ return LicenseService . updateLicense ( this . httpClientInstance , id , license ) ;
64
76
}
65
77
66
78
/**
@@ -69,7 +81,7 @@ export default class CryptlexWebApiClient {
69
81
* @returns {Promise<ApiResponse<LicenseResponse>> } Promise that resolves to the Web API response
70
82
*/
71
83
deleteLicense ( id : string ) : Promise < ApiResponse < any > > {
72
- return LicenseService . deleteLicense ( this . httpClient , id ) ;
84
+ return LicenseService . deleteLicense ( this . httpClientInstance , id ) ;
73
85
}
74
86
75
87
/**
@@ -84,7 +96,12 @@ export default class CryptlexWebApiClient {
84
96
limit : number ,
85
97
parameters ?: LicenseListQueryParameters
86
98
) {
87
- return LicenseService . getLicenses ( this . httpClient , page , limit , parameters ) ;
99
+ return LicenseService . getLicenses (
100
+ this . httpClientInstance ,
101
+ page ,
102
+ limit ,
103
+ parameters
104
+ ) ;
88
105
}
89
106
90
107
/**
@@ -93,7 +110,7 @@ export default class CryptlexWebApiClient {
93
110
* @returns {Promise<ApiResponse<LicenseResponse>> } Promise that resolves to the Web API response
94
111
*/
95
112
getLicense ( id : string ) : Promise < ApiResponse < LicenseResponse > > {
96
- return LicenseService . getLicense ( this . httpClient , id ) ;
113
+ return LicenseService . getLicense ( this . httpClientInstance , id ) ;
97
114
}
98
115
99
116
/**
@@ -102,7 +119,7 @@ export default class CryptlexWebApiClient {
102
119
* @returns {Promise<ApiResponse<LicenseResponse>> } Promise that resolves to the Web API response
103
120
*/
104
121
renewLicense ( id : string ) : Promise < ApiResponse < LicenseResponse > > {
105
- return LicenseService . renewLicense ( this . httpClient , id ) ;
122
+ return LicenseService . renewLicense ( this . httpClientInstance , id ) ;
106
123
}
107
124
108
125
/**
@@ -115,7 +132,11 @@ export default class CryptlexWebApiClient {
115
132
id : string ,
116
133
extensionLength : number
117
134
) : Promise < ApiResponse < LicenseResponse > > {
118
- return LicenseService . extendLicense ( this . httpClient , id , extensionLength ) ;
135
+ return LicenseService . extendLicense (
136
+ this . httpClientInstance ,
137
+ id ,
138
+ extensionLength
139
+ ) ;
119
140
}
120
141
121
142
/**
@@ -124,7 +145,7 @@ export default class CryptlexWebApiClient {
124
145
* @returns {Promise<ApiResponse<UserResponse>> } Promise that resolves to the Web API response
125
146
*/
126
147
createUser ( user : UserCreateRequest ) : Promise < ApiResponse < UserResponse > > {
127
- return UserService . createUser ( this . httpClient , user ) ;
148
+ return UserService . createUser ( this . httpClientInstance , user ) ;
128
149
}
129
150
130
151
/**
@@ -133,7 +154,7 @@ export default class CryptlexWebApiClient {
133
154
* @returns {Promise<ApiResponse<any>> } Promise that resolves to the Web API response
134
155
*/
135
156
deleteUser ( id : string ) : Promise < ApiResponse < any > > {
136
- return UserService . deleteUser ( this . httpClient , id ) ;
157
+ return UserService . deleteUser ( this . httpClientInstance , id ) ;
137
158
}
138
159
139
160
/**
@@ -142,7 +163,7 @@ export default class CryptlexWebApiClient {
142
163
* @returns {Promise<ApiResponse<UserResponse>> } Promise that resolves to the Web API response
143
164
*/
144
165
getUser ( id : string ) : Promise < ApiResponse < UserResponse > > {
145
- return UserService . getUser ( this . httpClient , id ) ;
166
+ return UserService . getUser ( this . httpClientInstance , id ) ;
146
167
}
147
168
148
169
/**
@@ -157,7 +178,12 @@ export default class CryptlexWebApiClient {
157
178
limit : number ,
158
179
parameters ?: UserListQueryParameters
159
180
) : Promise < ApiResponse < UserResponse [ ] > > {
160
- return UserService . getUsers ( this . httpClient , page , limit , parameters ) ;
181
+ return UserService . getUsers (
182
+ this . httpClientInstance ,
183
+ page ,
184
+ limit ,
185
+ parameters
186
+ ) ;
161
187
}
162
188
163
189
/**
@@ -167,7 +193,7 @@ export default class CryptlexWebApiClient {
167
193
* @returns {Promise<ApiResponse<UserResponse>> } Promise that resolves to the Web API response
168
194
*/
169
195
updateUser ( id : string , user : UserUpdateRequest ) {
170
- return UserService . updateUser ( this . httpClient , id , user ) ;
196
+ return UserService . updateUser ( this . httpClientInstance , id , user ) ;
171
197
}
172
198
173
199
/**
@@ -178,6 +204,6 @@ export default class CryptlexWebApiClient {
178
204
* @returns {Promise<ApiResponse<any>> } Promise that resolves to the Web API response
179
205
*/
180
206
generateResetPasswordToken ( id : string ) {
181
- return UserService . generateResetPasswordToken ( this . httpClient , id ) ;
207
+ return UserService . generateResetPasswordToken ( this . httpClientInstance , id ) ;
182
208
}
183
209
}
0 commit comments