asma-helpers 0.2.47 → 0.2.49
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/.prettierrc +15 -15
- package/.vscode/settings.json +39 -39
- package/README.md +0 -0
- package/package.json +30 -30
- package/src/clients/srvAuth.ts +6 -6
- package/src/global.ts +46 -50
- package/src/helpers/CapitalizeFistLetter.ts +7 -7
- package/src/helpers/Config.ts +58 -58
- package/src/helpers/EnvironmentToOperateTypes.ts +6 -6
- package/src/helpers/EnvironmentsUrls.ts +102 -102
- package/src/helpers/FormatNumberConstants.ts +41 -41
- package/src/helpers/InitializeIDBListenersOnMstSnapshots.ts +62 -62
- package/src/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.ts +82 -82
- package/src/helpers/IsAdcuris.ts +4 -4
- package/src/helpers/IsNotEmpty.ts +2 -2
- package/src/helpers/NorwegianPostalCodes.ts +6 -6
- package/src/helpers/ProcessServerError.ts +92 -92
- package/src/helpers/attachUserJournalCredentials.ts +23 -23
- package/src/helpers/base64ToFile.ts +9 -9
- package/src/helpers/clearCacheData.ts +15 -15
- package/src/helpers/generateEnvConfigsBindings.ts +82 -82
- package/src/helpers/generateGenqlClient.ts +114 -120
- package/src/helpers/generateSrvAuthBindings.ts +231 -262
- package/src/helpers/getGqlOperationName.ts +20 -20
- package/src/helpers/getSubdomain.ts +50 -50
- package/src/helpers/isValidUrl.ts +12 -12
- package/src/helpers/parseJwt.ts +10 -10
- package/src/index.ts +34 -34
- package/src/interfaces/api/advoca/ISaveToDataBase.ts +17 -17
- package/src/interfaces/api/advoca/IUploadedDocument.ts +23 -23
- package/src/interfaces/enums.ts +56 -56
- package/src/utility/fetch.ts +9 -9
- package/tsconfig.json +84 -84
- package/lib/clients/srvAuth.d.ts +0 -2
- package/lib/clients/srvAuth.d.ts.map +0 -1
- package/lib/clients/srvAuth.js +0 -7
- package/lib/clients/srvAuth.js.map +0 -1
- package/lib/global.d.ts +0 -45
- package/lib/global.d.ts.map +0 -1
- package/lib/global.js +0 -5
- package/lib/global.js.map +0 -1
- package/lib/helpers/CapitalizeFistLetter.d.ts +0 -3
- package/lib/helpers/CapitalizeFistLetter.d.ts.map +0 -1
- package/lib/helpers/CapitalizeFistLetter.js +0 -7
- package/lib/helpers/CapitalizeFistLetter.js.map +0 -1
- package/lib/helpers/Config.d.ts +0 -6
- package/lib/helpers/Config.d.ts.map +0 -1
- package/lib/helpers/Config.js +0 -45
- package/lib/helpers/Config.js.map +0 -1
- package/lib/helpers/EnvironmentToOperateTypes.d.ts +0 -8
- package/lib/helpers/EnvironmentToOperateTypes.d.ts.map +0 -1
- package/lib/helpers/EnvironmentToOperateTypes.js +0 -9
- package/lib/helpers/EnvironmentToOperateTypes.js.map +0 -1
- package/lib/helpers/EnvironmentsUrls.d.ts +0 -94
- package/lib/helpers/EnvironmentsUrls.d.ts.map +0 -1
- package/lib/helpers/EnvironmentsUrls.js +0 -90
- package/lib/helpers/EnvironmentsUrls.js.map +0 -1
- package/lib/helpers/FormatNumberConstants.d.ts +0 -25
- package/lib/helpers/FormatNumberConstants.d.ts.map +0 -1
- package/lib/helpers/FormatNumberConstants.js +0 -41
- package/lib/helpers/FormatNumberConstants.js.map +0 -1
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts +0 -2
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts.map +0 -1
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js +0 -50
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js.map +0 -1
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.d.ts +0 -9
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.d.ts.map +0 -1
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.js +0 -69
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.js.map +0 -1
- package/lib/helpers/IsAdcuris.d.ts +0 -3
- package/lib/helpers/IsAdcuris.d.ts.map +0 -1
- package/lib/helpers/IsAdcuris.js +0 -5
- package/lib/helpers/IsAdcuris.js.map +0 -1
- package/lib/helpers/IsNotEmpty.d.ts +0 -2
- package/lib/helpers/IsNotEmpty.d.ts.map +0 -1
- package/lib/helpers/IsNotEmpty.js +0 -4
- package/lib/helpers/IsNotEmpty.js.map +0 -1
- package/lib/helpers/NorwegianPostalCodes.d.ts +0 -9
- package/lib/helpers/NorwegianPostalCodes.d.ts.map +0 -1
- package/lib/helpers/NorwegianPostalCodes.js +0 -4
- package/lib/helpers/NorwegianPostalCodes.js.map +0 -1
- package/lib/helpers/ProcessServerError.d.ts +0 -3
- package/lib/helpers/ProcessServerError.d.ts.map +0 -1
- package/lib/helpers/ProcessServerError.js +0 -101
- package/lib/helpers/ProcessServerError.js.map +0 -1
- package/lib/helpers/attachUserJournalCredentials.d.ts +0 -2
- package/lib/helpers/attachUserJournalCredentials.d.ts.map +0 -1
- package/lib/helpers/attachUserJournalCredentials.js +0 -17
- package/lib/helpers/attachUserJournalCredentials.js.map +0 -1
- package/lib/helpers/base64ToFile.d.ts +0 -2
- package/lib/helpers/base64ToFile.d.ts.map +0 -1
- package/lib/helpers/base64ToFile.js +0 -9
- package/lib/helpers/base64ToFile.js.map +0 -1
- package/lib/helpers/clearCacheData.d.ts +0 -2
- package/lib/helpers/clearCacheData.d.ts.map +0 -1
- package/lib/helpers/clearCacheData.js +0 -13
- package/lib/helpers/clearCacheData.js.map +0 -1
- package/lib/helpers/generateEnvConfigsBindings.d.ts +0 -31
- package/lib/helpers/generateEnvConfigsBindings.d.ts.map +0 -1
- package/lib/helpers/generateEnvConfigsBindings.js +0 -49
- package/lib/helpers/generateEnvConfigsBindings.js.map +0 -1
- package/lib/helpers/generateGenqlClient.d.ts +0 -22
- package/lib/helpers/generateGenqlClient.d.ts.map +0 -1
- package/lib/helpers/generateGenqlClient.js +0 -87
- package/lib/helpers/generateGenqlClient.js.map +0 -1
- package/lib/helpers/generateSrvAuthBindings.d.ts +0 -41
- package/lib/helpers/generateSrvAuthBindings.d.ts.map +0 -1
- package/lib/helpers/generateSrvAuthBindings.js +0 -200
- package/lib/helpers/generateSrvAuthBindings.js.map +0 -1
- package/lib/helpers/getGqlOperationName.d.ts +0 -2
- package/lib/helpers/getGqlOperationName.d.ts.map +0 -1
- package/lib/helpers/getGqlOperationName.js +0 -16
- package/lib/helpers/getGqlOperationName.js.map +0 -1
- package/lib/helpers/getSubdomain.d.ts +0 -13
- package/lib/helpers/getSubdomain.d.ts.map +0 -1
- package/lib/helpers/getSubdomain.js +0 -40
- package/lib/helpers/getSubdomain.js.map +0 -1
- package/lib/helpers/isValidUrl.d.ts +0 -2
- package/lib/helpers/isValidUrl.d.ts.map +0 -1
- package/lib/helpers/isValidUrl.js +0 -10
- package/lib/helpers/isValidUrl.js.map +0 -1
- package/lib/helpers/parseJwt.d.ts +0 -2
- package/lib/helpers/parseJwt.d.ts.map +0 -1
- package/lib/helpers/parseJwt.js +0 -8
- package/lib/helpers/parseJwt.js.map +0 -1
- package/lib/helpers/userTypingSignal.d.ts +0 -5
- package/lib/helpers/userTypingSignal.d.ts.map +0 -1
- package/lib/helpers/userTypingSignal.js +0 -33
- package/lib/helpers/userTypingSignal.js.map +0 -1
- package/lib/index.d.ts +0 -29
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -27
- package/lib/index.js.map +0 -1
- package/lib/interfaces/api/advoca/ISaveToDataBase.d.ts +0 -17
- package/lib/interfaces/api/advoca/ISaveToDataBase.d.ts.map +0 -1
- package/lib/interfaces/api/advoca/ISaveToDataBase.js +0 -2
- package/lib/interfaces/api/advoca/ISaveToDataBase.js.map +0 -1
- package/lib/interfaces/api/advoca/IUploadedDocument.d.ts +0 -27
- package/lib/interfaces/api/advoca/IUploadedDocument.d.ts.map +0 -1
- package/lib/interfaces/api/advoca/IUploadedDocument.js +0 -2
- package/lib/interfaces/api/advoca/IUploadedDocument.js.map +0 -1
- package/lib/interfaces/enums.d.ts +0 -51
- package/lib/interfaces/enums.d.ts.map +0 -1
- package/lib/interfaces/enums.js +0 -60
- package/lib/interfaces/enums.js.map +0 -1
- package/lib/utility/fetch.d.ts +0 -2
- package/lib/utility/fetch.d.ts.map +0 -1
- package/lib/utility/fetch.js +0 -6
- package/lib/utility/fetch.js.map +0 -1
|
@@ -1,262 +1,231 @@
|
|
|
1
|
-
import axios, { type AxiosResponse, type ResponseType } from 'axios'
|
|
2
|
-
import { EventBus } from 'asma-event-bus/lib/event-buss'
|
|
3
|
-
import { EnvironmentEnums, parseJwt } from '..'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
window.__ASMA__SHELL__.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
getNewJwtToken,
|
|
233
|
-
registerOnJwtChanges: register,
|
|
234
|
-
getUserId,
|
|
235
|
-
setCallbackToJwtNotifier,
|
|
236
|
-
getParsedJwt,
|
|
237
|
-
abortController,
|
|
238
|
-
getJwtToken,
|
|
239
|
-
// cancelRequest,
|
|
240
|
-
accessTokenHasExpired,
|
|
241
|
-
}
|
|
242
|
-
window.__ASMA__SHELL__ = window.__ASMA__SHELL__ || {}
|
|
243
|
-
|
|
244
|
-
window.__ASMA__SHELL__.auth_bindings = auth_bindings
|
|
245
|
-
|
|
246
|
-
return auth_bindings
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* @deprecated use generateSrvAuthBindings
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
export function generateSrvAuthBindingsMicroApp(
|
|
253
|
-
SRV_AUTH: () => string,
|
|
254
|
-
DEVELOPMENT: () => boolean,
|
|
255
|
-
ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums,
|
|
256
|
-
logout?: () => void,
|
|
257
|
-
) {
|
|
258
|
-
return (
|
|
259
|
-
window.__ASMA__SHELL__?.auth_bindings ||
|
|
260
|
-
generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout)
|
|
261
|
-
)
|
|
262
|
-
}
|
|
1
|
+
import axios, { type AxiosResponse, type ResponseType } from 'axios'
|
|
2
|
+
import { EventBus } from 'asma-event-bus/lib/event-buss'
|
|
3
|
+
import { EnvironmentEnums, parseJwt } from '..'
|
|
4
|
+
|
|
5
|
+
let logoutsuccesfull = false
|
|
6
|
+
|
|
7
|
+
export const { dispatch, register: registerCallbackOnSrvAuthEvents } = EventBus<{ jwt_changed: {}; logout_event: {} }>(
|
|
8
|
+
'auth-bindings',
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
export function generateSrvAuthBindings<FeatureEnums = never>(
|
|
12
|
+
SRV_AUTH: () => string,
|
|
13
|
+
DEVELOPMENT: () => boolean,
|
|
14
|
+
EnvironmentToOperateFn: () => string,
|
|
15
|
+
logout?: () => void,
|
|
16
|
+
) {
|
|
17
|
+
// let logoutMfes: (() => void)[] = []
|
|
18
|
+
|
|
19
|
+
if (logout) {
|
|
20
|
+
registerCallbackOnSrvAuthEvents('logout_event', logout)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (window.__ASMA__SHELL__?.auth_bindings) {
|
|
24
|
+
//window.__ASMA__SHELL__.logoutMfes = logoutMfes
|
|
25
|
+
|
|
26
|
+
return window.__ASMA__SHELL__.auth_bindings as typeof auth_bindings
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let jwtToken = ''
|
|
30
|
+
|
|
31
|
+
let features: Set<FeatureEnums> | undefined
|
|
32
|
+
|
|
33
|
+
let parsed_jwt: any | undefined
|
|
34
|
+
|
|
35
|
+
let fetchJwtPromise: Promise<{
|
|
36
|
+
data: { message: string; token?: string; features?: FeatureEnums[]; errors: { message: string }[] }
|
|
37
|
+
}> | null = null
|
|
38
|
+
|
|
39
|
+
const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken
|
|
40
|
+
|
|
41
|
+
const isJwtValid = () => !isJwtInvalid()
|
|
42
|
+
|
|
43
|
+
async function srvAuthGet<R>(url: string, headers?: Record<string, string>) {
|
|
44
|
+
if (DEVELOPMENT() && EnvironmentToOperateFn()) {
|
|
45
|
+
if (EnvironmentToOperateFn() in EnvironmentEnums) {
|
|
46
|
+
url = `${url}&env=${EnvironmentToOperateFn()}`
|
|
47
|
+
|
|
48
|
+
url = url.includes('&') && !url.includes('?') ? url.replace('&', '?') : url
|
|
49
|
+
} else {
|
|
50
|
+
console.warn(
|
|
51
|
+
'EnvironmentToOperateFn() is not a valid EnvironmentEnums',
|
|
52
|
+
'shall be one of:',
|
|
53
|
+
EnvironmentEnums,
|
|
54
|
+
'actual value:',
|
|
55
|
+
EnvironmentToOperateFn(),
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return axios.get<unknown, AxiosResponse<R>>(`${SRV_AUTH()}${url}`, {
|
|
61
|
+
headers: {
|
|
62
|
+
...headers,
|
|
63
|
+
'asma-origin': window.location.origin,
|
|
64
|
+
},
|
|
65
|
+
withCredentials: true,
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function accessTokenHasExpired(): boolean {
|
|
70
|
+
const tokenObj = getParsedJwt()
|
|
71
|
+
|
|
72
|
+
const accessTokenExpDate = tokenObj?.exp || 0
|
|
73
|
+
|
|
74
|
+
const nowTime = Math.floor(new Date().getTime() / 1000)
|
|
75
|
+
|
|
76
|
+
//set exp time -20sec for token to be refreshed early
|
|
77
|
+
return accessTokenExpDate - 10 <= nowTime
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function signin(url: string, headers?: Record<string, string>) {
|
|
81
|
+
const { data } = await srvAuthGet<{ token: string; features: FeatureEnums[] }>(url, headers)
|
|
82
|
+
|
|
83
|
+
setAuthData(data)
|
|
84
|
+
|
|
85
|
+
logoutsuccesfull = false
|
|
86
|
+
|
|
87
|
+
return data
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function signoutAuth() {
|
|
91
|
+
try {
|
|
92
|
+
setAuthData({ token: '' })
|
|
93
|
+
|
|
94
|
+
await srvAuthGet('/signout')
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error(e)
|
|
97
|
+
} finally {
|
|
98
|
+
dispatch('logout_event', {}, false)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getUserId(): string {
|
|
102
|
+
return getParsedJwt()?.['user_id'] || '-1'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function setAuthData(data: { token: string; features?: FeatureEnums[] }) {
|
|
106
|
+
jwtToken = data.token
|
|
107
|
+
features = new Set(data.features)
|
|
108
|
+
parsed_jwt = undefined
|
|
109
|
+
dispatch('jwt_changed', {}, false)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getJwtToken() {
|
|
113
|
+
return jwtToken
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function getJwtTokenAsync() {
|
|
117
|
+
if (isJwtInvalid()) {
|
|
118
|
+
const new_jwt = await getNewJwtToken()
|
|
119
|
+
|
|
120
|
+
return new_jwt
|
|
121
|
+
} else {
|
|
122
|
+
return jwtToken
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function setReqConfig<T = unknown>(data?: T, responseType?: ResponseType) {
|
|
127
|
+
const token = await getJwtTokenAsync()
|
|
128
|
+
|
|
129
|
+
const res = {
|
|
130
|
+
data: data,
|
|
131
|
+
responseType: responseType,
|
|
132
|
+
headers: {} as Record<string, string>,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (token) {
|
|
136
|
+
res.headers['Authorization'] = `Bearer ${token}`
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return res
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function getNewJwtToken() {
|
|
143
|
+
if (logoutsuccesfull) return
|
|
144
|
+
try {
|
|
145
|
+
if (!fetchJwtPromise) {
|
|
146
|
+
fetchJwtPromise = srvAuthGet('/token')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const { data } = await fetchJwtPromise
|
|
150
|
+
|
|
151
|
+
if (!data || data.errors || data.message != 'Success' || !data.token) {
|
|
152
|
+
logout?.()
|
|
153
|
+
logoutsuccesfull = true
|
|
154
|
+
|
|
155
|
+
//signoutAuth()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setAuthData({ token: data.token || '', features: data.features || [] })
|
|
159
|
+
} catch (error) {
|
|
160
|
+
logout?.()
|
|
161
|
+
logoutsuccesfull = true
|
|
162
|
+
//signoutAuth()
|
|
163
|
+
|
|
164
|
+
setAuthData({ token: '', features: [] })
|
|
165
|
+
|
|
166
|
+
console.error(error)
|
|
167
|
+
} finally {
|
|
168
|
+
fetchJwtPromise = null
|
|
169
|
+
|
|
170
|
+
return jwtToken
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getParsedJwt<R = { user_id: string; exp: number }>(): R | undefined {
|
|
175
|
+
if (!parsed_jwt) {
|
|
176
|
+
parsed_jwt = parseJwt<R>(jwtToken)
|
|
177
|
+
}
|
|
178
|
+
return parsed_jwt
|
|
179
|
+
}
|
|
180
|
+
function getFeatures() {
|
|
181
|
+
return features
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
*
|
|
185
|
+
* @param featureName feature_name_enums add this: generateSrvAuthBindings<feature_name_enums.>(...)
|
|
186
|
+
* @returns boolean
|
|
187
|
+
*/
|
|
188
|
+
function hasFeature(featureName: FeatureEnums) {
|
|
189
|
+
return !!features?.has(featureName)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const auth_bindings = {
|
|
193
|
+
hasFeature,
|
|
194
|
+
getFeatures,
|
|
195
|
+
isJwtValid,
|
|
196
|
+
signin,
|
|
197
|
+
srvAuthGet,
|
|
198
|
+
signoutAuth,
|
|
199
|
+
setReqConfig,
|
|
200
|
+
getJwtTokenAsync,
|
|
201
|
+
getNewJwtToken,
|
|
202
|
+
getUserId,
|
|
203
|
+
getParsedJwt,
|
|
204
|
+
getJwtToken,
|
|
205
|
+
accessTokenHasExpired,
|
|
206
|
+
}
|
|
207
|
+
window.__ASMA__SHELL__ = window.__ASMA__SHELL__ || {}
|
|
208
|
+
|
|
209
|
+
window.__ASMA__SHELL__.auth_bindings = auth_bindings
|
|
210
|
+
|
|
211
|
+
return auth_bindings
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @deprecated use generateSrvAuthBindings
|
|
215
|
+
* @param SRV_AUTH
|
|
216
|
+
* @param DEVELOPMENT
|
|
217
|
+
* @param ENVIRONMENT_TO_OPERATE
|
|
218
|
+
* @param logout
|
|
219
|
+
* @returns
|
|
220
|
+
*/
|
|
221
|
+
export function generateSrvAuthBindingsMicroApp(
|
|
222
|
+
SRV_AUTH: () => string,
|
|
223
|
+
DEVELOPMENT: () => boolean,
|
|
224
|
+
ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums,
|
|
225
|
+
logout?: () => void,
|
|
226
|
+
) {
|
|
227
|
+
return (
|
|
228
|
+
window.__ASMA__SHELL__?.auth_bindings ||
|
|
229
|
+
generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout)
|
|
230
|
+
)
|
|
231
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export function getGqlOperationName(query: string): string | undefined {
|
|
2
|
-
const is_query = query.includes('query') ? 'query' : undefined
|
|
3
|
-
|
|
4
|
-
const is_mutation = query.includes('mutation') ? 'mutation' : undefined
|
|
5
|
-
|
|
6
|
-
const is_subscription = query.includes('subscription') ? 'subscription' : undefined
|
|
7
|
-
|
|
8
|
-
const split_word = is_query || is_mutation || is_subscription
|
|
9
|
-
|
|
10
|
-
if (!split_word) {
|
|
11
|
-
return undefined
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let operationName = query?.split(split_word, 2)?.[1]?.split('{', 1)[0]?.split(' ')?.[1]?.trim()
|
|
15
|
-
|
|
16
|
-
if (operationName?.includes('(')) {
|
|
17
|
-
operationName = operationName.split('(', 1)[0]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return operationName
|
|
1
|
+
export function getGqlOperationName(query: string): string | undefined {
|
|
2
|
+
const is_query = query.includes('query') ? 'query' : undefined
|
|
3
|
+
|
|
4
|
+
const is_mutation = query.includes('mutation') ? 'mutation' : undefined
|
|
5
|
+
|
|
6
|
+
const is_subscription = query.includes('subscription') ? 'subscription' : undefined
|
|
7
|
+
|
|
8
|
+
const split_word = is_query || is_mutation || is_subscription
|
|
9
|
+
|
|
10
|
+
if (!split_word) {
|
|
11
|
+
return undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let operationName = query?.split(split_word, 2)?.[1]?.split('{', 1)[0]?.split(' ')?.[1]?.trim()
|
|
15
|
+
|
|
16
|
+
if (operationName?.includes('(')) {
|
|
17
|
+
operationName = operationName.split('(', 1)[0]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return operationName
|
|
21
21
|
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated moved to asma-genql-directory use from there
|
|
3
|
-
*/
|
|
4
|
-
function getSubdomain() {
|
|
5
|
-
const hostname_arr = window.location.hostname.split('.') // fretex-dfsf.advoca.no
|
|
6
|
-
|
|
7
|
-
let subdomain = ''
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
hostname_arr.length === 3 &&
|
|
11
|
-
hostname_arr[0] &&
|
|
12
|
-
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === hostname_arr[0])
|
|
13
|
-
) {
|
|
14
|
-
subdomain = hostname_arr[0]
|
|
15
|
-
|
|
16
|
-
const subdomain_arr = subdomain.split('-')
|
|
17
|
-
|
|
18
|
-
if (subdomain_arr.length === 2 && subdomain_arr[0]) {
|
|
19
|
-
subdomain = subdomain_arr[0]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return subdomain
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated moved to asma-genql-directory use from there
|
|
26
|
-
*/
|
|
27
|
-
export const subdomain = getSubdomain()
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated moved to asma-genql-directory use from there
|
|
30
|
-
*/
|
|
31
|
-
export function redirectFromSubdomainToDomain() {
|
|
32
|
-
const domain_hostname = `${createDomainUrlFromSubdomain()}${window.location.pathname}`
|
|
33
|
-
|
|
34
|
-
window.location.href = domain_hostname
|
|
35
|
-
|
|
36
|
-
return null
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated moved to asma-genql-directory use from there
|
|
40
|
-
*/
|
|
41
|
-
export function createDomainUrlFromSubdomain() {
|
|
42
|
-
let hostname = window.location.hostname.replace(subdomain, '')
|
|
43
|
-
|
|
44
|
-
;(hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
|
|
45
|
-
(hostname.startsWith('.') && (hostname = 'www' + hostname))
|
|
46
|
-
|
|
47
|
-
const { port, protocol } = window.location
|
|
48
|
-
|
|
49
|
-
return protocol + '//' + hostname + (port ? `:${port}` : '')
|
|
50
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated moved to asma-genql-directory use from there
|
|
3
|
+
*/
|
|
4
|
+
function getSubdomain() {
|
|
5
|
+
const hostname_arr = window.location.hostname.split('.') // fretex-dfsf.advoca.no
|
|
6
|
+
|
|
7
|
+
let subdomain = ''
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
hostname_arr.length === 3 &&
|
|
11
|
+
hostname_arr[0] &&
|
|
12
|
+
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === hostname_arr[0])
|
|
13
|
+
) {
|
|
14
|
+
subdomain = hostname_arr[0]
|
|
15
|
+
|
|
16
|
+
const subdomain_arr = subdomain.split('-')
|
|
17
|
+
|
|
18
|
+
if (subdomain_arr.length === 2 && subdomain_arr[0]) {
|
|
19
|
+
subdomain = subdomain_arr[0]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return subdomain
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated moved to asma-genql-directory use from there
|
|
26
|
+
*/
|
|
27
|
+
export const subdomain = getSubdomain()
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated moved to asma-genql-directory use from there
|
|
30
|
+
*/
|
|
31
|
+
export function redirectFromSubdomainToDomain() {
|
|
32
|
+
const domain_hostname = `${createDomainUrlFromSubdomain()}${window.location.pathname}`
|
|
33
|
+
|
|
34
|
+
window.location.href = domain_hostname
|
|
35
|
+
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated moved to asma-genql-directory use from there
|
|
40
|
+
*/
|
|
41
|
+
export function createDomainUrlFromSubdomain() {
|
|
42
|
+
let hostname = window.location.hostname.replace(subdomain, '')
|
|
43
|
+
|
|
44
|
+
;(hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
|
|
45
|
+
(hostname.startsWith('.') && (hostname = 'www' + hostname))
|
|
46
|
+
|
|
47
|
+
const { port, protocol } = window.location
|
|
48
|
+
|
|
49
|
+
return protocol + '//' + hostname + (port ? `:${port}` : '')
|
|
50
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function isValidUrl(urlString: string) {
|
|
2
|
-
const urlPattern = new RegExp(
|
|
3
|
-
'^(https?:\\/\\/)?' + // validate protocol
|
|
4
|
-
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
|
|
5
|
-
'((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
|
|
6
|
-
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
|
|
7
|
-
'(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
|
|
8
|
-
'(\\#[-a-z\\d_]*)?$',
|
|
9
|
-
'i',
|
|
10
|
-
)
|
|
11
|
-
return !!urlPattern.test(urlString)
|
|
12
|
-
}
|
|
1
|
+
export function isValidUrl(urlString: string) {
|
|
2
|
+
const urlPattern = new RegExp(
|
|
3
|
+
'^(https?:\\/\\/)?' + // validate protocol
|
|
4
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
|
|
5
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
|
|
6
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
|
|
7
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
|
|
8
|
+
'(\\#[-a-z\\d_]*)?$',
|
|
9
|
+
'i',
|
|
10
|
+
)
|
|
11
|
+
return !!urlPattern.test(urlString)
|
|
12
|
+
}
|