oro-sdk-apis 1.8.1 → 1.8.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/oro-sdk-apis.cjs.development.js +5 -20
- package/dist/oro-sdk-apis.cjs.development.js.map +1 -1
- package/dist/oro-sdk-apis.cjs.production.min.js +1 -1
- package/dist/oro-sdk-apis.cjs.production.min.js.map +1 -1
- package/dist/oro-sdk-apis.esm.js +5 -20
- package/dist/oro-sdk-apis.esm.js.map +1 -1
- package/dist/services/guard.d.ts +0 -1
- package/package.json +1 -1
- package/src/services/guard.ts +38 -47
- package/LICENSE +0 -21
package/dist/services/guard.d.ts
CHANGED
package/package.json
CHANGED
package/src/services/guard.ts
CHANGED
|
@@ -2,24 +2,36 @@ import { AxiosError } from 'axios'
|
|
|
2
2
|
import type { AxiosAuthRefreshRequestConfig } from 'axios-auth-refresh'
|
|
3
3
|
import {
|
|
4
4
|
AuthenticationBadRequest,
|
|
5
|
-
AuthenticationFailed,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
AuthenticationFailed,
|
|
6
|
+
AuthenticationServerError,
|
|
7
|
+
AuthenticationUnconfirmedEmail,
|
|
8
|
+
AuthRecoverRequest,
|
|
9
|
+
AuthTokenRequest,
|
|
10
|
+
AuthTokenResponse,
|
|
11
|
+
Base64String,
|
|
12
|
+
IdentityCreateRequest,
|
|
13
|
+
IdentityCreationBadRequest,
|
|
14
|
+
IdentityCreationConflict,
|
|
15
|
+
IdentityCreationFailed,
|
|
16
|
+
IdentityResendConfirmEmailRequest,
|
|
17
|
+
IdentityResponse,
|
|
18
|
+
IdentityUpdateRequest,
|
|
19
|
+
QRCodeRequest,
|
|
20
|
+
QRCodeResponse,
|
|
21
|
+
Tokens,
|
|
22
|
+
Uuid,
|
|
23
|
+
WhoAmIResponse,
|
|
10
24
|
} from '../models'
|
|
11
25
|
import { APIService } from './api'
|
|
12
26
|
|
|
13
27
|
export interface GuardRequestConfig extends AxiosAuthRefreshRequestConfig {
|
|
14
|
-
useRefreshToken
|
|
28
|
+
useRefreshToken: boolean
|
|
15
29
|
}
|
|
16
30
|
export class GuardService {
|
|
17
|
-
private identityCache: Record<string, IdentityResponse>
|
|
18
31
|
private whoAmICache: Record<string, WhoAmIResponse>
|
|
19
32
|
|
|
20
33
|
constructor(private api: APIService, private baseURL: string) {
|
|
21
34
|
this.api.setAuthRefreshFn(this.authRefresh.bind(this))
|
|
22
|
-
this.identityCache = {}
|
|
23
35
|
this.whoAmICache = {}
|
|
24
36
|
}
|
|
25
37
|
|
|
@@ -35,7 +47,7 @@ export class GuardService {
|
|
|
35
47
|
* @param tokens
|
|
36
48
|
*/
|
|
37
49
|
public setTokens(tokens: Tokens) {
|
|
38
|
-
this.api.setTokens({...this.api.getTokens()
|
|
50
|
+
this.api.setTokens({ ...this.api.getTokens(), ...tokens })
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
/**
|
|
@@ -46,21 +58,21 @@ export class GuardService {
|
|
|
46
58
|
* @returns AuthTokenResponse
|
|
47
59
|
*/
|
|
48
60
|
public async authToken(req: AuthTokenRequest): Promise<AuthTokenResponse> {
|
|
49
|
-
let resp
|
|
61
|
+
let resp: AuthTokenResponse
|
|
50
62
|
|
|
51
63
|
try {
|
|
52
64
|
let config: AxiosAuthRefreshRequestConfig = {
|
|
53
|
-
skipAuthRefresh: true
|
|
65
|
+
skipAuthRefresh: true,
|
|
54
66
|
}
|
|
55
67
|
|
|
56
68
|
resp = await this.api.post<AuthTokenResponse>(`${this.baseURL}/v1/auth/token`, req, config)
|
|
57
69
|
|
|
58
70
|
this.api.setTokens({
|
|
59
71
|
accessToken: resp.accessToken,
|
|
60
|
-
refreshToken: resp.refreshToken
|
|
72
|
+
refreshToken: resp.refreshToken,
|
|
61
73
|
})
|
|
62
|
-
} catch(e) {
|
|
63
|
-
if((e as any).isAxiosError){
|
|
74
|
+
} catch (e) {
|
|
75
|
+
if ((e as any).isAxiosError) {
|
|
64
76
|
const code = (e as AxiosError).response?.status
|
|
65
77
|
switch (code) {
|
|
66
78
|
case 400:
|
|
@@ -75,7 +87,6 @@ export class GuardService {
|
|
|
75
87
|
}
|
|
76
88
|
}
|
|
77
89
|
throw new AuthenticationFailed()
|
|
78
|
-
|
|
79
90
|
}
|
|
80
91
|
return resp
|
|
81
92
|
}
|
|
@@ -88,12 +99,11 @@ export class GuardService {
|
|
|
88
99
|
public async authRefresh(refreshToken?: string): Promise<AuthTokenResponse> {
|
|
89
100
|
let config: GuardRequestConfig = {
|
|
90
101
|
skipAuthRefresh: true,
|
|
91
|
-
useRefreshToken: true
|
|
102
|
+
useRefreshToken: true,
|
|
92
103
|
}
|
|
93
104
|
return this.api.put<AuthTokenResponse>(`${this.baseURL}/v1/auth/token`, null, config)
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
|
|
97
107
|
/**
|
|
98
108
|
* Call guard to overwrite existing refresh token cookie
|
|
99
109
|
*
|
|
@@ -103,7 +113,6 @@ export class GuardService {
|
|
|
103
113
|
return this.api.get<void>(`${this.baseURL}/v1/auth/logout`)
|
|
104
114
|
}
|
|
105
115
|
|
|
106
|
-
|
|
107
116
|
/**
|
|
108
117
|
* Call guard to attempt account recovery
|
|
109
118
|
*
|
|
@@ -114,7 +123,6 @@ export class GuardService {
|
|
|
114
123
|
return this.api.post<void>(`${this.baseURL}/v1/auth/recover`, req)
|
|
115
124
|
}
|
|
116
125
|
|
|
117
|
-
|
|
118
126
|
/**
|
|
119
127
|
* Allow to create a new identity. The identity will then need to be confirmed
|
|
120
128
|
* via an email link
|
|
@@ -123,15 +131,15 @@ export class GuardService {
|
|
|
123
131
|
* @returns IdentityResponse
|
|
124
132
|
*/
|
|
125
133
|
public async identityCreate(req: IdentityCreateRequest): Promise<IdentityResponse> {
|
|
126
|
-
let resp
|
|
134
|
+
let resp: IdentityResponse
|
|
127
135
|
|
|
128
136
|
try {
|
|
129
137
|
resp = await this.api.post<IdentityResponse>(`${this.baseURL}/v1/identities`, req)
|
|
130
138
|
this.api.setTokens({
|
|
131
|
-
refreshToken: resp.refreshToken
|
|
139
|
+
refreshToken: resp.refreshToken,
|
|
132
140
|
})
|
|
133
141
|
} catch (e) {
|
|
134
|
-
if((e as any).isAxiosError){
|
|
142
|
+
if ((e as any).isAxiosError) {
|
|
135
143
|
const code = (e as AxiosError).response?.status
|
|
136
144
|
switch (code) {
|
|
137
145
|
case 400:
|
|
@@ -148,7 +156,6 @@ export class GuardService {
|
|
|
148
156
|
return resp
|
|
149
157
|
}
|
|
150
158
|
|
|
151
|
-
|
|
152
159
|
/**
|
|
153
160
|
* Retrieve an identity. Will return public fields only when requested
|
|
154
161
|
* without authentication
|
|
@@ -156,21 +163,10 @@ export class GuardService {
|
|
|
156
163
|
* @param identityID Unique id of the identity to retrieve
|
|
157
164
|
* @returns IdentityResponse
|
|
158
165
|
*/
|
|
159
|
-
public async identityGet(
|
|
160
|
-
identityID
|
|
161
|
-
): Promise<IdentityResponse> {
|
|
162
|
-
const tokens = this.api.getTokens()
|
|
163
|
-
const cacheKey = (tokens.accessToken ?? '') + (tokens.refreshToken ?? '') + identityID
|
|
164
|
-
|
|
165
|
-
if (!tokens.accessToken || !this.identityCache[cacheKey]) {
|
|
166
|
-
this.identityCache[cacheKey] = await this.api.get<IdentityResponse>(
|
|
167
|
-
`${this.baseURL}/v1/identities/${identityID}`
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
return this.identityCache[cacheKey]
|
|
166
|
+
public async identityGet(identityID: Uuid): Promise<IdentityResponse> {
|
|
167
|
+
return await this.api.get<IdentityResponse>(`${this.baseURL}/v1/identities/${identityID}`)
|
|
171
168
|
}
|
|
172
169
|
|
|
173
|
-
|
|
174
170
|
/**
|
|
175
171
|
* Get information about the current authenticated user
|
|
176
172
|
*
|
|
@@ -192,10 +188,7 @@ export class GuardService {
|
|
|
192
188
|
* @param req update request
|
|
193
189
|
* @returns IdentityResponse
|
|
194
190
|
*/
|
|
195
|
-
public async identityUpdate(
|
|
196
|
-
identityID: Uuid,
|
|
197
|
-
req: IdentityUpdateRequest
|
|
198
|
-
): Promise<IdentityResponse> {
|
|
191
|
+
public async identityUpdate(identityID: Uuid, req: IdentityUpdateRequest): Promise<IdentityResponse> {
|
|
199
192
|
return this.api.put<IdentityResponse>(`${this.baseURL}/v1/identities/${identityID}`, req)
|
|
200
193
|
}
|
|
201
194
|
|
|
@@ -207,12 +200,11 @@ export class GuardService {
|
|
|
207
200
|
* @param password the identity password (already hashed and in base64)
|
|
208
201
|
* @returns QRCodeResponse
|
|
209
202
|
*/
|
|
210
|
-
public async identityMFAQRCode(
|
|
211
|
-
identityID: Uuid,
|
|
212
|
-
password: Base64String
|
|
213
|
-
): Promise<QRCodeResponse> {
|
|
203
|
+
public async identityMFAQRCode(identityID: Uuid, password: Base64String): Promise<QRCodeResponse> {
|
|
214
204
|
const req: QRCodeRequest = { password }
|
|
215
|
-
return this.api.post<QRCodeResponse>(`${this.baseURL}/v1/identities/${identityID}/mfa`, req, {
|
|
205
|
+
return this.api.post<QRCodeResponse>(`${this.baseURL}/v1/identities/${identityID}/mfa`, req, {
|
|
206
|
+
headers: { Accept: 'application/json' },
|
|
207
|
+
})
|
|
216
208
|
}
|
|
217
209
|
|
|
218
210
|
/**
|
|
@@ -221,8 +213,7 @@ export class GuardService {
|
|
|
221
213
|
* @param req IdentityResendConfirmEmailRequest
|
|
222
214
|
* @return void
|
|
223
215
|
*/
|
|
224
|
-
public async identitySendConfirmEmail(req
|
|
216
|
+
public async identitySendConfirmEmail(req: IdentityResendConfirmEmailRequest): Promise<void> {
|
|
225
217
|
return this.api.post<void>(`${this.baseURL}/v1/identity/confirm`, req)
|
|
226
218
|
}
|
|
227
219
|
}
|
|
228
|
-
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 ORO Health Inc.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|