asma-helpers 0.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/.prettierrc +15 -0
- package/.vscode/settings.json +39 -0
- package/README.md +20 -0
- package/lib/clients/srvAuth.d.ts +2 -0
- package/lib/clients/srvAuth.d.ts.map +1 -0
- package/lib/clients/srvAuth.js +7 -0
- package/lib/clients/srvAuth.js.map +1 -0
- package/lib/global.d.ts +41 -0
- package/lib/global.d.ts.map +1 -0
- package/lib/global.js +5 -0
- package/lib/global.js.map +1 -0
- package/lib/helpers/CapitalizeFistLetter.d.ts +3 -0
- package/lib/helpers/CapitalizeFistLetter.d.ts.map +1 -0
- package/lib/helpers/CapitalizeFistLetter.js +7 -0
- package/lib/helpers/CapitalizeFistLetter.js.map +1 -0
- package/lib/helpers/Config.d.ts +7 -0
- package/lib/helpers/Config.d.ts.map +1 -0
- package/lib/helpers/Config.js +48 -0
- package/lib/helpers/Config.js.map +1 -0
- package/lib/helpers/EnvironmentToOperateTypes.d.ts +8 -0
- package/lib/helpers/EnvironmentToOperateTypes.d.ts.map +1 -0
- package/lib/helpers/EnvironmentToOperateTypes.js +9 -0
- package/lib/helpers/EnvironmentToOperateTypes.js.map +1 -0
- package/lib/helpers/EnvironmentsUrls.d.ts +81 -0
- package/lib/helpers/EnvironmentsUrls.d.ts.map +1 -0
- package/lib/helpers/EnvironmentsUrls.js +79 -0
- package/lib/helpers/EnvironmentsUrls.js.map +1 -0
- package/lib/helpers/Execute.d.ts +20 -0
- package/lib/helpers/Execute.d.ts.map +1 -0
- package/lib/helpers/Execute.js +38 -0
- package/lib/helpers/Execute.js.map +1 -0
- package/lib/helpers/FormatNumberConstants.d.ts +25 -0
- package/lib/helpers/FormatNumberConstants.d.ts.map +1 -0
- package/lib/helpers/FormatNumberConstants.js +41 -0
- package/lib/helpers/FormatNumberConstants.js.map +1 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts +2 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts.map +1 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js +50 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js.map +1 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.d.ts +9 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.d.ts.map +1 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.js +69 -0
- package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.js.map +1 -0
- package/lib/helpers/IsAdcuris.d.ts +3 -0
- package/lib/helpers/IsAdcuris.d.ts.map +1 -0
- package/lib/helpers/IsAdcuris.js +5 -0
- package/lib/helpers/IsAdcuris.js.map +1 -0
- package/lib/helpers/IsNotEmpty.d.ts +2 -0
- package/lib/helpers/IsNotEmpty.d.ts.map +1 -0
- package/lib/helpers/IsNotEmpty.js +4 -0
- package/lib/helpers/IsNotEmpty.js.map +1 -0
- package/lib/helpers/NorwegianPostalCodes.d.ts +9 -0
- package/lib/helpers/NorwegianPostalCodes.d.ts.map +1 -0
- package/lib/helpers/NorwegianPostalCodes.js +4 -0
- package/lib/helpers/NorwegianPostalCodes.js.map +1 -0
- package/lib/helpers/ProcessServerError.d.ts +3 -0
- package/lib/helpers/ProcessServerError.d.ts.map +1 -0
- package/lib/helpers/ProcessServerError.js +101 -0
- package/lib/helpers/ProcessServerError.js.map +1 -0
- package/lib/helpers/clearCacheData.d.ts +2 -0
- package/lib/helpers/clearCacheData.d.ts.map +1 -0
- package/lib/helpers/clearCacheData.js +13 -0
- package/lib/helpers/clearCacheData.js.map +1 -0
- package/lib/helpers/generateGenqlClient.d.ts +16 -0
- package/lib/helpers/generateGenqlClient.d.ts.map +1 -0
- package/lib/helpers/generateGenqlClient.js +49 -0
- package/lib/helpers/generateGenqlClient.js.map +1 -0
- package/lib/helpers/generateSrvAuthBindings.d.ts +23 -0
- package/lib/helpers/generateSrvAuthBindings.d.ts.map +1 -0
- package/lib/helpers/generateSrvAuthBindings.js +122 -0
- package/lib/helpers/generateSrvAuthBindings.js.map +1 -0
- package/lib/helpers/getGqlOperationName.d.ts +2 -0
- package/lib/helpers/getGqlOperationName.d.ts.map +1 -0
- package/lib/helpers/getGqlOperationName.js +16 -0
- package/lib/helpers/getGqlOperationName.js.map +1 -0
- package/lib/helpers/getSubdomain.d.ts +4 -0
- package/lib/helpers/getSubdomain.d.ts.map +1 -0
- package/lib/helpers/getSubdomain.js +28 -0
- package/lib/helpers/getSubdomain.js.map +1 -0
- package/lib/helpers/parseJwt.d.ts +2 -0
- package/lib/helpers/parseJwt.d.ts.map +1 -0
- package/lib/helpers/parseJwt.js +8 -0
- package/lib/helpers/parseJwt.js.map +1 -0
- package/lib/hooks/useWindowWidthSise.hook.d.ts +2 -0
- package/lib/hooks/useWindowWidthSise.hook.d.ts.map +1 -0
- package/lib/hooks/useWindowWidthSise.hook.js +13 -0
- package/lib/hooks/useWindowWidthSise.hook.js.map +1 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +22 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/api/advoca/ISaveToDataBase.d.ts +17 -0
- package/lib/interfaces/api/advoca/ISaveToDataBase.d.ts.map +1 -0
- package/lib/interfaces/api/advoca/ISaveToDataBase.js +2 -0
- package/lib/interfaces/api/advoca/ISaveToDataBase.js.map +1 -0
- package/lib/interfaces/api/advoca/IUploadedDocument.d.ts +27 -0
- package/lib/interfaces/api/advoca/IUploadedDocument.d.ts.map +1 -0
- package/lib/interfaces/api/advoca/IUploadedDocument.js +2 -0
- package/lib/interfaces/api/advoca/IUploadedDocument.js.map +1 -0
- package/lib/interfaces/enums.d.ts +51 -0
- package/lib/interfaces/enums.d.ts.map +1 -0
- package/lib/interfaces/enums.js +60 -0
- package/lib/interfaces/enums.js.map +1 -0
- package/lib/utility/fetch.d.ts +2 -0
- package/lib/utility/fetch.d.ts.map +1 -0
- package/lib/utility/fetch.js +6 -0
- package/lib/utility/fetch.js.map +1 -0
- package/package.json +30 -0
- package/src/clients/srvAuth.ts +7 -0
- package/src/global.ts +44 -0
- package/src/helpers/CapitalizeFistLetter.ts +7 -0
- package/src/helpers/Config.ts +61 -0
- package/src/helpers/EnvironmentToOperateTypes.ts +7 -0
- package/src/helpers/EnvironmentsUrls.ts +91 -0
- package/src/helpers/FormatNumberConstants.ts +42 -0
- package/src/helpers/InitializeIDBListenersOnMstSnapshots.ts +62 -0
- package/src/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.ts +82 -0
- package/src/helpers/IsAdcuris.ts +5 -0
- package/src/helpers/IsNotEmpty.ts +3 -0
- package/src/helpers/NorwegianPostalCodes.ts +6 -0
- package/src/helpers/ProcessServerError.ts +92 -0
- package/src/helpers/clearCacheData.ts +16 -0
- package/src/helpers/generateGenqlClient.ts +75 -0
- package/src/helpers/generateSrvAuthBindings.ts +175 -0
- package/src/helpers/getGqlOperationName.ts +21 -0
- package/src/helpers/getSubdomain.ts +41 -0
- package/src/helpers/parseJwt.ts +11 -0
- package/src/index.ts +29 -0
- package/src/interfaces/api/advoca/ISaveToDataBase.ts +18 -0
- package/src/interfaces/api/advoca/IUploadedDocument.ts +24 -0
- package/src/interfaces/enums.ts +56 -0
- package/src/utility/fetch.ts +10 -0
- package/tsconfig.json +84 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export function processServerError(error: string | Record<string, any>): string {
|
|
2
|
+
console['error'](error)
|
|
3
|
+
|
|
4
|
+
let errorMessage = getServerErrorMessage(error)
|
|
5
|
+
|
|
6
|
+
/* if (i18n[errorMessage]) {
|
|
7
|
+
;(errorMessage = (window as any).strings)[errorMessage]
|
|
8
|
+
} */
|
|
9
|
+
|
|
10
|
+
//showErrorMessage(operationName || 'Error', errorMessage)
|
|
11
|
+
return errorMessage
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getServerErrorMessage(error: Record<string, any> | string): string {
|
|
15
|
+
if (typeof error == 'string') {
|
|
16
|
+
return error
|
|
17
|
+
} else if (error['data'] && error['data']['Message']) {
|
|
18
|
+
return error['data']['Message']
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(error)) {
|
|
21
|
+
return getArrayErrorsMessage(error)
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(error?.['errors'])) {
|
|
24
|
+
return getArrayErrorsMessage(error['errors'])
|
|
25
|
+
}
|
|
26
|
+
//graphql
|
|
27
|
+
else if (error['bodyText']) {
|
|
28
|
+
return error['bodyText']
|
|
29
|
+
} else if (error['response'] && error['response'].data) {
|
|
30
|
+
const data = error['response'].data?.['error'] ?? error['response'].data
|
|
31
|
+
|
|
32
|
+
if (typeof data == 'string') {
|
|
33
|
+
return data
|
|
34
|
+
} else if (data?.constructor === Object) {
|
|
35
|
+
const keys = Object.keys(data)
|
|
36
|
+
|
|
37
|
+
if (keys[0]) {
|
|
38
|
+
const objKey = keys[0]
|
|
39
|
+
|
|
40
|
+
if (data[objKey]['message']) {
|
|
41
|
+
return data[objKey]['message']
|
|
42
|
+
} else if (data[objKey][0] && data[objKey][0]['message']) {
|
|
43
|
+
return data[objKey][0]['message']
|
|
44
|
+
} else if (typeof data[objKey] == 'string') {
|
|
45
|
+
return data[objKey]
|
|
46
|
+
} else if (data[objKey].constructor === Object) {
|
|
47
|
+
const childKeys = Object.keys(data[objKey])
|
|
48
|
+
|
|
49
|
+
if (childKeys[0]) {
|
|
50
|
+
const objKey2 = childKeys[0]
|
|
51
|
+
|
|
52
|
+
return `${objKey2}: ${data[objKey][objKey2]}`
|
|
53
|
+
} else {
|
|
54
|
+
return 'Missing child field: empty keys'
|
|
55
|
+
}
|
|
56
|
+
} else if (data[objKey].constructor === Array) {
|
|
57
|
+
if (data[objKey][0] === 'validation.required') {
|
|
58
|
+
return `window.strings.field_is_required ${objKey}`
|
|
59
|
+
} else {
|
|
60
|
+
return `${objKey}: ${data[objKey][0]}`
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
return 'Missing field: Message not available'
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
return 'Missing field: Response keys are empty'
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
return 'Missing field: data type not processed'
|
|
70
|
+
}
|
|
71
|
+
} else if (error['message']) {
|
|
72
|
+
return error['message']
|
|
73
|
+
} else if (error['error']) {
|
|
74
|
+
return error['error']
|
|
75
|
+
} else if (error?.['request']?.['response']) {
|
|
76
|
+
return error['request']['response']
|
|
77
|
+
} else {
|
|
78
|
+
return "Missing field: Couldn't process error"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getArrayErrorsMessage(error: Record<string, unknown>[]): string {
|
|
83
|
+
const porcessed_error = error
|
|
84
|
+
.map((err) => {
|
|
85
|
+
if ('message' in err) {
|
|
86
|
+
return err['message'] as string
|
|
87
|
+
} else return ''
|
|
88
|
+
})
|
|
89
|
+
.join()
|
|
90
|
+
|
|
91
|
+
return porcessed_error ?? 'No message field found! plase check logs'
|
|
92
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const clearCacheData = async (CACHE_VERSION:string) => {
|
|
2
|
+
const version = localStorage.getItem('version')
|
|
3
|
+
if (
|
|
4
|
+
(!version || version !== CACHE_VERSION) &&
|
|
5
|
+
indexedDB &&
|
|
6
|
+
typeof indexedDB['databases'] === 'function'
|
|
7
|
+
) {
|
|
8
|
+
const IndexedDBS = await indexedDB.databases()
|
|
9
|
+
|
|
10
|
+
IndexedDBS.map((IndexedDB) => {
|
|
11
|
+
IndexedDB.name && indexedDB.deleteDatabase(IndexedDB.name)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
localStorage.setItem('version', CACHE_VERSION)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios'
|
|
2
|
+
import type { ClientOptions } from '@genql/runtime'
|
|
3
|
+
|
|
4
|
+
export function generateGenqlClient<T>({
|
|
5
|
+
accessTokenHasExpired,
|
|
6
|
+
setReqConfig,
|
|
7
|
+
createClient,
|
|
8
|
+
serviceUrl,
|
|
9
|
+
serviceUrlWs,
|
|
10
|
+
path = '/v1/graphql',
|
|
11
|
+
}: {
|
|
12
|
+
accessTokenHasExpired: () => boolean
|
|
13
|
+
setReqConfig: () => Promise<AxiosRequestConfig<any>>
|
|
14
|
+
createClient: (options?: ClientOptions | undefined) => T
|
|
15
|
+
serviceUrl: () => string | undefined
|
|
16
|
+
serviceUrlWs: () => string | undefined
|
|
17
|
+
path?: string
|
|
18
|
+
}) {
|
|
19
|
+
let directoryClient: T | null = null
|
|
20
|
+
|
|
21
|
+
async function getGenqlClient() {
|
|
22
|
+
if (accessTokenHasExpired() || directoryClient === null) {
|
|
23
|
+
directoryClient = await genqlClient()
|
|
24
|
+
|
|
25
|
+
return directoryClient
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return directoryClient
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function resetGenqlClient() {
|
|
32
|
+
directoryClient = null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function genqlClient(
|
|
36
|
+
anonymous: boolean | undefined = undefined,
|
|
37
|
+
headers: Record<string, string> = {},
|
|
38
|
+
): Promise<T> {
|
|
39
|
+
let req_headers: Record<string, string> = {}
|
|
40
|
+
if (!serviceUrl()) {
|
|
41
|
+
console.warn('requred param srv_url is undefined, please check EnvConfig object!')
|
|
42
|
+
}
|
|
43
|
+
if (!anonymous) {
|
|
44
|
+
req_headers = ((await setReqConfig()).headers ?? {}) as Record<string, string>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return createClient({
|
|
48
|
+
url: `${serviceUrl()}${path}`,
|
|
49
|
+
headers: {
|
|
50
|
+
...req_headers,
|
|
51
|
+
...headers,
|
|
52
|
+
},
|
|
53
|
+
batch: { batchInterval: 50, maxBatchSize: 100 },
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function genqlClientWs() {
|
|
58
|
+
const req_headers = ((await setReqConfig()).headers ?? {}) as Record<string, string>
|
|
59
|
+
|
|
60
|
+
return createClient({
|
|
61
|
+
url: `${serviceUrlWs()}${path}`,
|
|
62
|
+
cache: 'reload',
|
|
63
|
+
subscription: {
|
|
64
|
+
timeout: 1,
|
|
65
|
+
reconnect: true,
|
|
66
|
+
reconnectionAttempts: 5,
|
|
67
|
+
headers: {
|
|
68
|
+
...req_headers,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { getGenGqlClient: getGenqlClient, resetGenqlClient, genqlClient, genqlClientWs }
|
|
75
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import axios, { AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios'
|
|
2
|
+
import { EnvironmentEnums, parseJwt } from '..'
|
|
3
|
+
export interface IGenerateSRVAuthBindings {
|
|
4
|
+
isJwtValid: () => boolean
|
|
5
|
+
signin(url: string, headers?: Record<string, string>): Promise<{ token: string }>
|
|
6
|
+
srvAuthGet<R>(url: string, headers?: Record<string, string>): Promise<AxiosResponse<R, any>>
|
|
7
|
+
signoutAuth(): Promise<void>
|
|
8
|
+
setReqConfig<T = unknown>(data?: T, responseType?: ResponseType): Promise<AxiosRequestConfig>
|
|
9
|
+
getJwtTokenAsync(): Promise<string>
|
|
10
|
+
getNewJwtToken(): Promise<string>
|
|
11
|
+
getUserId(): string
|
|
12
|
+
getParsedJwt<R = { user_id: string; exp: number }>(): R | undefined
|
|
13
|
+
getJwtToken(): string
|
|
14
|
+
accessTokenHasExpired(): boolean
|
|
15
|
+
}
|
|
16
|
+
export function generateSrvAuthBindings(
|
|
17
|
+
SRV_AUTH: () => string,
|
|
18
|
+
DEVELOPMENT: () => boolean,
|
|
19
|
+
ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums,
|
|
20
|
+
logout?: () => void,
|
|
21
|
+
): IGenerateSRVAuthBindings {
|
|
22
|
+
let jwtToken = ''
|
|
23
|
+
let parsed_jwt: any | undefined = undefined
|
|
24
|
+
|
|
25
|
+
let fetchJwtPromise: Promise<{ data: { message: string; token?: string; errors: { message: string }[] } }> | null =
|
|
26
|
+
null
|
|
27
|
+
|
|
28
|
+
const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken
|
|
29
|
+
|
|
30
|
+
const isJwtValid = () => !isJwtInvalid()
|
|
31
|
+
|
|
32
|
+
async function srvAuthGet<R>(url: string, headers?: Record<string, string>) {
|
|
33
|
+
if (DEVELOPMENT() && ENVIRONMENT_TO_OPERATE()) {
|
|
34
|
+
url = `${url}&env=${ENVIRONMENT_TO_OPERATE()}`
|
|
35
|
+
|
|
36
|
+
url = url.includes('&') && !url.includes('?') ? url.replace('&', '?') : url
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return axios.get<unknown, AxiosResponse<R>>(`${SRV_AUTH()}${url}`, {
|
|
40
|
+
headers: {
|
|
41
|
+
...headers,
|
|
42
|
+
'asma-origin': window.location.origin,
|
|
43
|
+
},
|
|
44
|
+
withCredentials: true,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function accessTokenHasExpired(): boolean {
|
|
49
|
+
const tokenObj = getParsedJwt()
|
|
50
|
+
|
|
51
|
+
const accessTokenExpDate = tokenObj?.exp || 0
|
|
52
|
+
|
|
53
|
+
const nowTime = Math.floor(new Date().getTime() / 1000)
|
|
54
|
+
|
|
55
|
+
//set exp time -20sec for token to be refreshed early
|
|
56
|
+
return accessTokenExpDate - 10 <= nowTime
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function signin(url: string, headers?: Record<string, string>) {
|
|
60
|
+
const { data } = await srvAuthGet<{ token: string }>(url, headers)
|
|
61
|
+
|
|
62
|
+
setJwtToken(data.token)
|
|
63
|
+
|
|
64
|
+
return data
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function signoutAuth() {
|
|
68
|
+
setJwtToken('')
|
|
69
|
+
await srvAuthGet('/signout')
|
|
70
|
+
}
|
|
71
|
+
function getUserId(): string {
|
|
72
|
+
return getParsedJwt()?.['user_id'] || '-1'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function setJwtToken(token: string) {
|
|
76
|
+
jwtToken = token
|
|
77
|
+
}
|
|
78
|
+
function getJwtToken() {
|
|
79
|
+
return jwtToken
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function getJwtTokenAsync() {
|
|
83
|
+
if (isJwtInvalid()) {
|
|
84
|
+
const new_jwt = await getNewJwtToken()
|
|
85
|
+
|
|
86
|
+
return new_jwt
|
|
87
|
+
} else {
|
|
88
|
+
return jwtToken
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function setReqConfig<T = unknown>(data?: T, responseType?: ResponseType): Promise<AxiosRequestConfig> {
|
|
93
|
+
const token = await getJwtTokenAsync()
|
|
94
|
+
|
|
95
|
+
const res: AxiosRequestConfig = {
|
|
96
|
+
data: data,
|
|
97
|
+
responseType: responseType,
|
|
98
|
+
headers: {},
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (token) {
|
|
102
|
+
if (!res.headers) {
|
|
103
|
+
res.headers = {}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
res.headers['Authorization'] = `Bearer ${token}`
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return res
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function getNewJwtToken() {
|
|
113
|
+
try {
|
|
114
|
+
if (!fetchJwtPromise) {
|
|
115
|
+
fetchJwtPromise = srvAuthGet('/token')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const { data } = await fetchJwtPromise
|
|
119
|
+
|
|
120
|
+
if (!data || data.errors || data.message != 'Success') {
|
|
121
|
+
logout?.() || signoutAuth()
|
|
122
|
+
}
|
|
123
|
+
if (!data.token) {
|
|
124
|
+
throw new Error('Token is not present in the result')
|
|
125
|
+
}
|
|
126
|
+
setJwtToken(data.token ?? '')
|
|
127
|
+
|
|
128
|
+
fetchJwtPromise = null
|
|
129
|
+
|
|
130
|
+
return jwtToken
|
|
131
|
+
} catch (error) {
|
|
132
|
+
logout?.() || signoutAuth()
|
|
133
|
+
//signoutAuth()
|
|
134
|
+
|
|
135
|
+
fetchJwtPromise = null
|
|
136
|
+
|
|
137
|
+
console.error(error)
|
|
138
|
+
|
|
139
|
+
return jwtToken
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getParsedJwt<R = { user_id: string; exp: number }>(): R | undefined {
|
|
144
|
+
if (!parsed_jwt) {
|
|
145
|
+
parsed_jwt = parseJwt<R>(jwtToken)
|
|
146
|
+
}
|
|
147
|
+
return parsed_jwt
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
isJwtValid,
|
|
152
|
+
signin,
|
|
153
|
+
srvAuthGet,
|
|
154
|
+
signoutAuth,
|
|
155
|
+
setReqConfig,
|
|
156
|
+
getJwtTokenAsync,
|
|
157
|
+
getNewJwtToken,
|
|
158
|
+
getUserId,
|
|
159
|
+
getParsedJwt,
|
|
160
|
+
getJwtToken,
|
|
161
|
+
accessTokenHasExpired,
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function generateSrvAuthBindingsMicroApp(
|
|
166
|
+
SRV_AUTH: () => string,
|
|
167
|
+
DEVELOPMENT: () => boolean,
|
|
168
|
+
ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums,
|
|
169
|
+
logout?: () => void,
|
|
170
|
+
) {
|
|
171
|
+
return (
|
|
172
|
+
window.__ASMA__SHELL__?.auth_bindings ||
|
|
173
|
+
generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout)
|
|
174
|
+
)
|
|
175
|
+
}
|
|
@@ -0,0 +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
|
|
21
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function getSubdomain() {
|
|
2
|
+
const hostname_arr = window.location.hostname.split('.')// fretex-dfsf.advoca.no
|
|
3
|
+
|
|
4
|
+
let subdomain = ''
|
|
5
|
+
|
|
6
|
+
if (
|
|
7
|
+
hostname_arr.length === 3 &&
|
|
8
|
+
hostname_arr[0] &&
|
|
9
|
+
!['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === hostname_arr[0])
|
|
10
|
+
) {
|
|
11
|
+
subdomain = hostname_arr[0]
|
|
12
|
+
|
|
13
|
+
const subdomain_arr = subdomain.split('-')
|
|
14
|
+
|
|
15
|
+
if (subdomain_arr.length === 2 && subdomain_arr[0]) {
|
|
16
|
+
subdomain = subdomain_arr[0]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return subdomain
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const subdomain = getSubdomain()
|
|
23
|
+
|
|
24
|
+
export function redirectFromSubdomainToDomain() {
|
|
25
|
+
const domain_hostname = `${createDomainUrlFromSubdomain()}${window.location.pathname}`
|
|
26
|
+
|
|
27
|
+
window.location.href = domain_hostname
|
|
28
|
+
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function createDomainUrlFromSubdomain() {
|
|
33
|
+
let hostname = window.location.hostname.replace(subdomain, '')
|
|
34
|
+
|
|
35
|
+
;(hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
|
|
36
|
+
(hostname.startsWith('.') && (hostname = 'www' + hostname))
|
|
37
|
+
|
|
38
|
+
const { port, protocol } = window.location
|
|
39
|
+
|
|
40
|
+
return protocol + '//' + hostname + (port ? `:${port}` : '')
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { getServerErrorMessage, processServerError } from './helpers/ProcessServerError'
|
|
2
|
+
export { CURENCY_NOK, NORVEGIAN_PHONE_NUMBER, ORDINARY, PERSONAL_NUMBER, YEARS } from './helpers/FormatNumberConstants'
|
|
3
|
+
export { COUNTRIES, POSTAL_CODE } from './helpers/NorwegianPostalCodes'
|
|
4
|
+
export { capitalizeFirstLetter, toLowercaseAndCapitalizeFirstLetter } from './helpers/CapitalizeFistLetter'
|
|
5
|
+
export * from './helpers/IsAdcuris'
|
|
6
|
+
export * from './helpers/IsNotEmpty'
|
|
7
|
+
export * from './helpers/Config'
|
|
8
|
+
export * from './helpers/InitializeIDBListenersOnMstSnapshots'
|
|
9
|
+
export * from './helpers/InitializeIDBListenersOnMstSnapshotsThenCatch'
|
|
10
|
+
|
|
11
|
+
export * from './helpers/getGqlOperationName'
|
|
12
|
+
export * from './helpers/parseJwt'
|
|
13
|
+
export * from './helpers/EnvironmentsUrls'
|
|
14
|
+
export * from './helpers/EnvironmentToOperateTypes'
|
|
15
|
+
export * from './helpers/generateSrvAuthBindings'
|
|
16
|
+
export * from './helpers/getSubdomain'
|
|
17
|
+
export * from './helpers/clearCacheData'
|
|
18
|
+
export * from './helpers/generateGenqlClient'
|
|
19
|
+
|
|
20
|
+
export * from './utility/fetch'
|
|
21
|
+
|
|
22
|
+
export * from './clients/srvAuth'
|
|
23
|
+
|
|
24
|
+
export type { IUploadedDocument } from './interfaces/api/advoca/IUploadedDocument'
|
|
25
|
+
export type { IFeedBack, ISaveToDataBase } from './interfaces/api/advoca/ISaveToDataBase'
|
|
26
|
+
|
|
27
|
+
export * from './interfaces/enums'
|
|
28
|
+
|
|
29
|
+
export * from './global'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ISaveToDataBase {
|
|
2
|
+
method: string
|
|
3
|
+
json: string
|
|
4
|
+
uuid: string | undefined
|
|
5
|
+
feedback: IFeedBack
|
|
6
|
+
url: string
|
|
7
|
+
origin?: {
|
|
8
|
+
method: string
|
|
9
|
+
// history: any
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IFeedBack {
|
|
14
|
+
error?: string
|
|
15
|
+
type: string
|
|
16
|
+
message: string
|
|
17
|
+
show_time: number
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface IUploadedDocument {
|
|
2
|
+
created_at: string
|
|
3
|
+
customer: {
|
|
4
|
+
comm_consents_descr: string
|
|
5
|
+
contact_email: string
|
|
6
|
+
contact_message: string
|
|
7
|
+
contact_tel: string
|
|
8
|
+
|
|
9
|
+
id: number
|
|
10
|
+
logo: string
|
|
11
|
+
name: string
|
|
12
|
+
updated_at: string
|
|
13
|
+
}
|
|
14
|
+
customer_id: number
|
|
15
|
+
id: number
|
|
16
|
+
name: string
|
|
17
|
+
path: string
|
|
18
|
+
patientIds: { id: number; soknad_id: string }[]
|
|
19
|
+
region: number
|
|
20
|
+
sds_id: number
|
|
21
|
+
updated_at: string
|
|
22
|
+
upload_patient_id: number
|
|
23
|
+
success: string
|
|
24
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export enum InitiatorTypes {
|
|
2
|
+
Customer = 'customer',
|
|
3
|
+
Patient = 'patient',
|
|
4
|
+
SelfCompletable = 'self-completable',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum QnrContextTypes {
|
|
8
|
+
Advoca = 'advoca',
|
|
9
|
+
Portal = 'portal',
|
|
10
|
+
Outlook = 'outlook',
|
|
11
|
+
}
|
|
12
|
+
export enum DocSignicatSignStatusTypes {
|
|
13
|
+
Complteted = 'completed',
|
|
14
|
+
Rejected = 'rejected',
|
|
15
|
+
Waiting = 'waiting',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum DocProxyStatusTypes {
|
|
19
|
+
Signed = 'signed',
|
|
20
|
+
WaitingForSigning = 'waiting_for_signing',
|
|
21
|
+
OnlyForView = 'only_for_view',
|
|
22
|
+
/* download = 'download',
|
|
23
|
+
uploaded = 'uploaded' */
|
|
24
|
+
}
|
|
25
|
+
export enum QuestionTypes {
|
|
26
|
+
BooleanQuestion = 'BooleanQuestion',
|
|
27
|
+
CheckBoxes = 'CheckBoxes',
|
|
28
|
+
CompositeQuestion = 'CompositeQuestion',
|
|
29
|
+
DateField = 'DateField',
|
|
30
|
+
Dropdown = 'Dropdown',
|
|
31
|
+
FormatNumber = 'FormatNumber',
|
|
32
|
+
LinearScale = 'LinearScale',
|
|
33
|
+
Link = 'Link',
|
|
34
|
+
RadioButtons = 'RadioButtons',
|
|
35
|
+
TextLong = 'TextLong',
|
|
36
|
+
TextShort = 'TextShort',
|
|
37
|
+
Emoticons = 'Emoticons',
|
|
38
|
+
DocumentUpload = 'DocumentUpload',
|
|
39
|
+
Readonly = 'Readonly',
|
|
40
|
+
ExpressionQuestion = 'ExpressionQuestion',
|
|
41
|
+
Chart = 'Chart',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export enum ActorTypes {
|
|
45
|
+
Mappable = 'mappable',
|
|
46
|
+
Custom = 'custom',
|
|
47
|
+
Complex = 'complex',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export enum EnvironmentEnums {
|
|
51
|
+
local = 'local',
|
|
52
|
+
dev = 'dev',
|
|
53
|
+
test = 'test',
|
|
54
|
+
stage = 'stage',
|
|
55
|
+
prod = 'prod',
|
|
56
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Basic Options */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
"target": "ES2019" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
8
|
+
"module": "ES2020" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
|
9
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
+
"jsx": "react-jsx" /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */,
|
|
13
|
+
"declaration": true /* Generates corresponding '.d.ts' file. */,
|
|
14
|
+
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
|
|
15
|
+
"sourceMap": true /* Generates corresponding '.map' file. */,
|
|
16
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
+
"outDir": "lib" /* Redirect output structure to the directory. */,
|
|
18
|
+
"rootDir": "src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
|
19
|
+
// "composite": true, /* Enable project compilation */
|
|
20
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
+
"isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,
|
|
26
|
+
|
|
27
|
+
/* Strict Type-Checking Options */
|
|
28
|
+
"strict": true /* Enable all strict type-checking options. */,
|
|
29
|
+
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
|
30
|
+
"strictNullChecks": true /* Enable strict null checks. */,
|
|
31
|
+
"strictFunctionTypes": true /* Enable strict checking of function types. */,
|
|
32
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
+
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
|
|
35
|
+
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
|
|
36
|
+
"noUncheckedIndexedAccess": true,
|
|
37
|
+
/* Additional Checks */
|
|
38
|
+
"noUnusedLocals": true /* Report errors on unused locals. */,
|
|
39
|
+
"noUnusedParameters": true /* Report errors on unused parameters. */,
|
|
40
|
+
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
|
41
|
+
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
|
42
|
+
//"noUncheckedIndexedAccess": true /* Include 'undefined' in index signature results */,
|
|
43
|
+
//"noPropertyAccessFromIndexSignature": true /* Require undeclared properties from index signatures to use element accesses. */,
|
|
44
|
+
|
|
45
|
+
/* Module Resolution Options */
|
|
46
|
+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
|
|
47
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
48
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
49
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
50
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
51
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
52
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
53
|
+
"esModuleInterop": false /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
54
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
55
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
56
|
+
|
|
57
|
+
/* Source Map Options */
|
|
58
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
59
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
60
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
61
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
62
|
+
|
|
63
|
+
/* Experimental Options */
|
|
64
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
65
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
66
|
+
|
|
67
|
+
/* Advanced Options */
|
|
68
|
+
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
|
69
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
|
|
70
|
+
|
|
71
|
+
"allowJs": false,
|
|
72
|
+
"allowSyntheticDefaultImports": true,
|
|
73
|
+
|
|
74
|
+
"strictBindCallApply": true,
|
|
75
|
+
|
|
76
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
77
|
+
"resolveJsonModule": true,
|
|
78
|
+
"experimentalDecorators": false,
|
|
79
|
+
"importsNotUsedAsValues": "error",
|
|
80
|
+
"useUnknownInCatchVariables": false
|
|
81
|
+
},
|
|
82
|
+
"include": ["src", "lib/interfaces"],
|
|
83
|
+
"exclude": ["node_modules", "lib"]
|
|
84
|
+
}
|