asma-helpers 0.3.13 → 0.3.16
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 +40 -39
- package/README.md +0 -0
- package/lib/clients/srvAuth.d.ts +1 -1
- package/lib/clients/srvAuth.js +6 -6
- package/lib/global.d.ts +39 -39
- package/lib/global.js +4 -4
- package/lib/helpers/CapitalizeFistLetter.d.ts +2 -2
- package/lib/helpers/CapitalizeFistLetter.js +6 -6
- package/lib/helpers/Config.d.ts +5 -5
- package/lib/helpers/Config.js +44 -44
- package/lib/helpers/EnvironmentToOperateTypes.d.ts +7 -7
- package/lib/helpers/EnvironmentToOperateTypes.js +8 -8
- package/lib/helpers/EnvironmentsUrls.d.ts +93 -93
- package/lib/helpers/EnvironmentsUrls.js +89 -89
- package/lib/helpers/FormatNumberConstants.d.ts +26 -26
- package/lib/helpers/FormatNumberConstants.js +40 -40
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts +1 -1
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js +49 -49
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.d.ts +8 -8
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.js +68 -68
- package/lib/helpers/IsAdcuris.d.ts +2 -2
- package/lib/helpers/IsAdcuris.js +4 -4
- package/lib/helpers/IsNotEmpty.d.ts +1 -1
- package/lib/helpers/IsNotEmpty.js +3 -3
- package/lib/helpers/NorwegianPostalCodes.d.ts +8 -8
- package/lib/helpers/NorwegianPostalCodes.js +3 -3
- package/lib/helpers/ProcessServerError.d.ts +2 -2
- package/lib/helpers/ProcessServerError.js +100 -100
- package/lib/helpers/attachUserJournalCredentials.d.ts +1 -1
- package/lib/helpers/attachUserJournalCredentials.js +16 -16
- package/lib/helpers/base64ToFile.d.ts +1 -1
- package/lib/helpers/base64ToFile.js +8 -8
- package/lib/helpers/checkForRegisteredSubdomains.d.ts +21 -0
- package/lib/helpers/checkForRegisteredSubdomains.d.ts.map +1 -0
- package/lib/helpers/checkForRegisteredSubdomains.js +47 -0
- package/lib/helpers/checkForRegisteredSubdomains.js.map +1 -0
- package/lib/helpers/clearCacheData.d.ts +1 -1
- package/lib/helpers/clearCacheData.d.ts.map +1 -1
- package/lib/helpers/clearCacheData.js +10 -12
- package/lib/helpers/clearCacheData.js.map +1 -1
- package/lib/helpers/generateEnvConfigsBindings.d.ts +30 -30
- package/lib/helpers/generateEnvConfigsBindings.js +48 -48
- package/lib/helpers/generateGenqlClient.d.ts +19 -19
- package/lib/helpers/generateGenqlClient.js +72 -72
- package/lib/helpers/generateSrvAuthBindings.d.ts +65 -65
- package/lib/helpers/generateSrvAuthBindings.d.ts.map +1 -1
- package/lib/helpers/generateSrvAuthBindings.js +201 -196
- package/lib/helpers/generateSrvAuthBindings.js.map +1 -1
- package/lib/helpers/getGqlOperationName.d.ts +1 -1
- package/lib/helpers/getGqlOperationName.js +15 -15
- package/lib/helpers/getSubdomain.d.ts +3 -12
- package/lib/helpers/getSubdomain.d.ts.map +1 -1
- package/lib/helpers/getSubdomain.js +38 -39
- package/lib/helpers/getSubdomain.js.map +1 -1
- package/lib/helpers/isValidUrl.d.ts +1 -1
- package/lib/helpers/isValidUrl.js +9 -9
- package/lib/helpers/parseJwt.d.ts +1 -1
- package/lib/helpers/parseJwt.js +7 -7
- package/lib/helpers/userTypingSignal.d.ts +4 -4
- package/lib/helpers/userTypingSignal.js +32 -32
- package/lib/index.d.ts +29 -28
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +27 -26
- package/lib/index.js.map +1 -1
- package/lib/interfaces/api/advoca/ISaveToDataBase.d.ts +16 -16
- package/lib/interfaces/api/advoca/ISaveToDataBase.js +1 -1
- package/lib/interfaces/api/advoca/IUploadedDocument.d.ts +26 -26
- package/lib/interfaces/api/advoca/IUploadedDocument.js +1 -1
- package/lib/interfaces/enums.d.ts +50 -50
- package/lib/interfaces/enums.js +59 -59
- package/lib/utility/fetch.d.ts +1 -1
- package/lib/utility/fetch.js +5 -5
- package/package.json +30 -30
- package/src/clients/srvAuth.ts +6 -6
- package/src/global.ts +46 -46
- 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 +42 -42
- 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/checkForRegisteredSubdomains.ts +76 -0
- package/src/helpers/clearCacheData.ts +12 -16
- package/src/helpers/generateEnvConfigsBindings.ts +82 -82
- package/src/helpers/generateGenqlClient.ts +113 -113
- package/src/helpers/generateSrvAuthBindings.ts +276 -272
- package/src/helpers/getGqlOperationName.ts +20 -20
- package/src/helpers/getSubdomain.ts +51 -50
- package/src/helpers/isValidUrl.ts +12 -12
- package/src/helpers/parseJwt.ts +10 -10
- package/src/index.ts +35 -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
|
@@ -1,272 +1,276 @@
|
|
|
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
|
|
6
|
-
|
|
7
|
-
export const { dispatch: dispatchSrvAuthEvents, register: registerCallbackOnSrvAuthEvents } = EventBus<{
|
|
8
|
-
jwt_changed: {}
|
|
9
|
-
logout_event: {}
|
|
10
|
-
customer_changed: {}
|
|
11
|
-
}>('auth-bindings')
|
|
12
|
-
|
|
13
|
-
function dispatchLogoutEvent() {
|
|
14
|
-
dispatchSrvAuthEvents('logout_event', {}, false)
|
|
15
|
-
}
|
|
16
|
-
function dispatchJwtChangedEvent() {
|
|
17
|
-
dispatchSrvAuthEvents('jwt_changed', {}, false)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function generateSrvAuthBindings<FeatureEnums = never>(
|
|
21
|
-
SRV_AUTH: () => string,
|
|
22
|
-
DEVELOPMENT: () => boolean,
|
|
23
|
-
EnvironmentToOperateFn: () => string,
|
|
24
|
-
logout?: () => void,
|
|
25
|
-
) {
|
|
26
|
-
if (logout) {
|
|
27
|
-
registerCallbackOnSrvAuthEvents('logout_event', logout)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (window.__ASMA__SHELL__?.auth_bindings) {
|
|
31
|
-
return window.__ASMA__SHELL__.auth_bindings as typeof auth_bindings
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let jwtToken = ''
|
|
35
|
-
|
|
36
|
-
let features: Set<FeatureEnums> | undefined
|
|
37
|
-
|
|
38
|
-
let connector: string | undefined
|
|
39
|
-
|
|
40
|
-
let parsed_jwt: unknown | undefined
|
|
41
|
-
|
|
42
|
-
const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken
|
|
43
|
-
|
|
44
|
-
const isJwtValid = () => !isJwtInvalid()
|
|
45
|
-
|
|
46
|
-
const promiseRegistry: Record<string, Promise<unknown>> = <{}>{}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
EnvironmentToOperateFn(),
|
|
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
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
function
|
|
220
|
-
return
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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 logoutsuccessfull = false
|
|
6
|
+
|
|
7
|
+
export const { dispatch: dispatchSrvAuthEvents, register: registerCallbackOnSrvAuthEvents } = EventBus<{
|
|
8
|
+
jwt_changed: {}
|
|
9
|
+
logout_event: {}
|
|
10
|
+
customer_changed: {}
|
|
11
|
+
}>('auth-bindings')
|
|
12
|
+
|
|
13
|
+
function dispatchLogoutEvent() {
|
|
14
|
+
dispatchSrvAuthEvents('logout_event', {}, false)
|
|
15
|
+
}
|
|
16
|
+
function dispatchJwtChangedEvent() {
|
|
17
|
+
dispatchSrvAuthEvents('jwt_changed', {}, false)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function generateSrvAuthBindings<FeatureEnums = never>(
|
|
21
|
+
SRV_AUTH: () => string,
|
|
22
|
+
DEVELOPMENT: () => boolean,
|
|
23
|
+
EnvironmentToOperateFn: () => string,
|
|
24
|
+
logout?: () => void,
|
|
25
|
+
) {
|
|
26
|
+
if (logout) {
|
|
27
|
+
registerCallbackOnSrvAuthEvents('logout_event', logout)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (window.__ASMA__SHELL__?.auth_bindings) {
|
|
31
|
+
return window.__ASMA__SHELL__.auth_bindings as typeof auth_bindings
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let jwtToken = ''
|
|
35
|
+
|
|
36
|
+
let features: Set<FeatureEnums> | undefined
|
|
37
|
+
|
|
38
|
+
let connector: string | undefined
|
|
39
|
+
|
|
40
|
+
let parsed_jwt: unknown | undefined
|
|
41
|
+
|
|
42
|
+
const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken
|
|
43
|
+
|
|
44
|
+
const isJwtValid = () => !isJwtInvalid()
|
|
45
|
+
|
|
46
|
+
const promiseRegistry: Record<string, Promise<unknown>> = <{}>{}
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* 1.req /singing
|
|
50
|
+
* 2.req /token
|
|
51
|
+
*/
|
|
52
|
+
async function srvAuthGet<R>(url: string, headers?: Record<string, string>) {
|
|
53
|
+
if (DEVELOPMENT() && EnvironmentToOperateFn()) {
|
|
54
|
+
if (EnvironmentToOperateFn() in EnvironmentEnums) {
|
|
55
|
+
url = `${url}&env=${EnvironmentToOperateFn()}`
|
|
56
|
+
|
|
57
|
+
// file deepcode ignore GlobalReplacementRegex: <it is intended to be replaced only first occurrence>
|
|
58
|
+
url = url.includes('&') && !url.includes('?') ? url.replace('&', '?') : url
|
|
59
|
+
} else {
|
|
60
|
+
console.warn(
|
|
61
|
+
'EnvironmentToOperateFn() is not a valid EnvironmentEnums',
|
|
62
|
+
'shall be one of:',
|
|
63
|
+
EnvironmentEnums,
|
|
64
|
+
'actual value:',
|
|
65
|
+
EnvironmentToOperateFn(),
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const promise =
|
|
71
|
+
promiseRegistry[url] ||
|
|
72
|
+
axios.get<unknown, AxiosResponse<R>>(`${SRV_AUTH()}${url}`, {
|
|
73
|
+
headers: {
|
|
74
|
+
...headers,
|
|
75
|
+
'asma-origin': window.location.origin,
|
|
76
|
+
},
|
|
77
|
+
withCredentials: true,
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
if (!promiseRegistry[url]) {
|
|
81
|
+
promiseRegistry[url] = promise
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const res = await promise.finally(() => {
|
|
85
|
+
delete promiseRegistry[url]
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
return res as AxiosResponse<R, any>
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function accessTokenHasExpired(): boolean {
|
|
92
|
+
const tokenObj = getParsedJwt()
|
|
93
|
+
|
|
94
|
+
const accessTokenExpDate = tokenObj?.exp || 0
|
|
95
|
+
|
|
96
|
+
const nowTime = Math.floor(new Date().getTime() / 1000)
|
|
97
|
+
|
|
98
|
+
return accessTokenExpDate - 10 <= nowTime
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* TODO: need to investigate smarter way of registering and unregister on `logout_event`
|
|
104
|
+
**/
|
|
105
|
+
registerCallbackOnSrvAuthEvents('logout_event', () => {
|
|
106
|
+
setAuthData({ token: '' })
|
|
107
|
+
|
|
108
|
+
srvAuthGet('/signout')
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
async function signin(url: string, headers?: Record<string, string>) {
|
|
112
|
+
const data = await srvAuthGet<{ token: string; features: FeatureEnums[]; connector?: string }>(url, headers)
|
|
113
|
+
|
|
114
|
+
setAuthData(data?.data)
|
|
115
|
+
|
|
116
|
+
return data
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function getUserId(): string {
|
|
120
|
+
return getParsedJwt()?.['user_id'] || '-1'
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function setAuthData(data?: { token: string; features?: FeatureEnums[]; connector?: string }) {
|
|
124
|
+
if (data?.token) {
|
|
125
|
+
jwtToken = data?.token
|
|
126
|
+
|
|
127
|
+
features = new Set(data.features)
|
|
128
|
+
|
|
129
|
+
connector = data.connector
|
|
130
|
+
|
|
131
|
+
parsed_jwt = parseJwt(jwtToken)
|
|
132
|
+
|
|
133
|
+
dispatchJwtChangedEvent()
|
|
134
|
+
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
jwtToken = ''
|
|
138
|
+
|
|
139
|
+
parsed_jwt = undefined
|
|
140
|
+
|
|
141
|
+
features = undefined
|
|
142
|
+
|
|
143
|
+
connector = undefined
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function getJwtToken() {
|
|
147
|
+
return jwtToken
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function getCachedJwt() {
|
|
151
|
+
if (isJwtInvalid()) {
|
|
152
|
+
const new_jwt = await getNewJwtToken()
|
|
153
|
+
|
|
154
|
+
return new_jwt
|
|
155
|
+
} else {
|
|
156
|
+
return jwtToken
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function setReqConfig<T = unknown>(data?: T, responseType?: ResponseType) {
|
|
161
|
+
const token = await getCachedJwt()
|
|
162
|
+
|
|
163
|
+
const res = {
|
|
164
|
+
data: data,
|
|
165
|
+
responseType: responseType,
|
|
166
|
+
headers: {} as Record<string, string>,
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (token) {
|
|
170
|
+
res.headers['Authorization'] = `Bearer ${token}`
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return res
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function getNewJwtToken() {
|
|
177
|
+
try {
|
|
178
|
+
/* if (!fetchJwtPromise) {
|
|
179
|
+
fetchJwtPromise = srvAuthGet('/token')
|
|
180
|
+
} */
|
|
181
|
+
|
|
182
|
+
const data = await srvAuthGet<{
|
|
183
|
+
errors?: string
|
|
184
|
+
token: string
|
|
185
|
+
features: FeatureEnums[]
|
|
186
|
+
connector: string
|
|
187
|
+
}>('/token')
|
|
188
|
+
|
|
189
|
+
if (!data || data.data?.errors || !data.data.token) {
|
|
190
|
+
dispatchLogoutEvent()
|
|
191
|
+
return
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
setAuthData({ token: data.data.token, features: data.data.features || [], connector: data.data.connector })
|
|
195
|
+
return jwtToken
|
|
196
|
+
} catch (error) {
|
|
197
|
+
dispatchLogoutEvent()
|
|
198
|
+
|
|
199
|
+
console.error(error)
|
|
200
|
+
|
|
201
|
+
return jwtToken
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function getParsedJwt<R = { user_id: string; exp: number }>(): R | undefined {
|
|
206
|
+
if (!parsed_jwt) {
|
|
207
|
+
parsed_jwt = parseJwt<R>(jwtToken)
|
|
208
|
+
}
|
|
209
|
+
return parsed_jwt as R
|
|
210
|
+
}
|
|
211
|
+
function getFeatures() {
|
|
212
|
+
return features
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* @param featureName feature_name_enums add this: generateSrvAuthBindings<feature_name_enums.>(...)
|
|
217
|
+
* @returns boolean
|
|
218
|
+
*/
|
|
219
|
+
function hasFeature(featureName: FeatureEnums) {
|
|
220
|
+
return !!features?.has(featureName)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function getConnector() {
|
|
224
|
+
return connector
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const auth_bindings = {
|
|
228
|
+
hasFeature,
|
|
229
|
+
getConnector,
|
|
230
|
+
getFeatures,
|
|
231
|
+
isJwtValid,
|
|
232
|
+
signin,
|
|
233
|
+
srvAuthGet,
|
|
234
|
+
/**
|
|
235
|
+
* @deprecated use dispatchLogoutEvent directly
|
|
236
|
+
*/
|
|
237
|
+
signoutAuth: dispatchLogoutEvent,
|
|
238
|
+
dispatchLogoutEvent,
|
|
239
|
+
setReqConfig,
|
|
240
|
+
/**
|
|
241
|
+
* @deprecated use getCachedJwt
|
|
242
|
+
* */
|
|
243
|
+
getJwtTokenAsync: getCachedJwt,
|
|
244
|
+
getCachedJwt,
|
|
245
|
+
getNewJwtToken,
|
|
246
|
+
/**
|
|
247
|
+
* @deprecated use registerCallbackOnSrvAuthEvents directly
|
|
248
|
+
*/
|
|
249
|
+
registerOnJwtChanges: registerCallbackOnSrvAuthEvents,
|
|
250
|
+
getUserId,
|
|
251
|
+
getParsedJwt,
|
|
252
|
+
getJwtToken,
|
|
253
|
+
// cancelRequest,
|
|
254
|
+
accessTokenHasExpired,
|
|
255
|
+
}
|
|
256
|
+
window.__ASMA__SHELL__ = window.__ASMA__SHELL__ || {}
|
|
257
|
+
|
|
258
|
+
window.__ASMA__SHELL__.auth_bindings = auth_bindings
|
|
259
|
+
|
|
260
|
+
return auth_bindings
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* @deprecated use generateSrvAuthBindings
|
|
264
|
+
*
|
|
265
|
+
*/
|
|
266
|
+
export function generateSrvAuthBindingsMicroApp(
|
|
267
|
+
SRV_AUTH: () => string,
|
|
268
|
+
DEVELOPMENT: () => boolean,
|
|
269
|
+
ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums,
|
|
270
|
+
logout?: () => void,
|
|
271
|
+
) {
|
|
272
|
+
return (
|
|
273
|
+
window.__ASMA__SHELL__?.auth_bindings ||
|
|
274
|
+
generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout)
|
|
275
|
+
)
|
|
276
|
+
}
|
|
@@ -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
|
}
|