asma-helpers 0.2.26 → 0.2.28

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.
Files changed (95) hide show
  1. package/.prettierrc +15 -15
  2. package/.vscode/settings.json +39 -39
  3. package/README.md +0 -0
  4. package/lib/clients/srvAuth.d.ts +1 -1
  5. package/lib/clients/srvAuth.js +6 -6
  6. package/lib/global.d.ts +39 -39
  7. package/lib/global.js +4 -4
  8. package/lib/helpers/CapitalizeFistLetter.d.ts +2 -2
  9. package/lib/helpers/CapitalizeFistLetter.js +6 -6
  10. package/lib/helpers/Config.d.ts +5 -5
  11. package/lib/helpers/Config.js +44 -44
  12. package/lib/helpers/EnvironmentToOperateTypes.d.ts +7 -7
  13. package/lib/helpers/EnvironmentToOperateTypes.js +8 -8
  14. package/lib/helpers/EnvironmentsUrls.d.ts +93 -93
  15. package/lib/helpers/EnvironmentsUrls.js +89 -89
  16. package/lib/helpers/FormatNumberConstants.d.ts +24 -24
  17. package/lib/helpers/FormatNumberConstants.js +40 -40
  18. package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts +1 -1
  19. package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js +49 -49
  20. package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.d.ts +8 -8
  21. package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.js +68 -68
  22. package/lib/helpers/IsAdcuris.d.ts +2 -2
  23. package/lib/helpers/IsAdcuris.js +4 -4
  24. package/lib/helpers/IsNotEmpty.d.ts +1 -1
  25. package/lib/helpers/IsNotEmpty.js +3 -3
  26. package/lib/helpers/NorwegianPostalCodes.d.ts +8 -8
  27. package/lib/helpers/NorwegianPostalCodes.js +3 -3
  28. package/lib/helpers/ProcessServerError.d.ts +2 -2
  29. package/lib/helpers/ProcessServerError.js +100 -100
  30. package/lib/helpers/attachUserJournalCredentials.d.ts +2 -0
  31. package/lib/helpers/attachUserJournalCredentials.d.ts.map +1 -0
  32. package/lib/helpers/attachUserJournalCredentials.js +17 -0
  33. package/lib/helpers/attachUserJournalCredentials.js.map +1 -0
  34. package/lib/helpers/base64ToFile.d.ts +1 -1
  35. package/lib/helpers/base64ToFile.js +8 -8
  36. package/lib/helpers/clearCacheData.d.ts +1 -1
  37. package/lib/helpers/clearCacheData.js +12 -12
  38. package/lib/helpers/generateEnvConfigsBindings.d.ts +30 -30
  39. package/lib/helpers/generateEnvConfigsBindings.js +48 -48
  40. package/lib/helpers/generateGenqlClient.d.ts +18 -18
  41. package/lib/helpers/generateGenqlClient.js +56 -56
  42. package/lib/helpers/generateSrvAuthBindings.d.ts +36 -37
  43. package/lib/helpers/generateSrvAuthBindings.d.ts.map +1 -1
  44. package/lib/helpers/generateSrvAuthBindings.js +153 -148
  45. package/lib/helpers/generateSrvAuthBindings.js.map +1 -1
  46. package/lib/helpers/getGqlOperationName.d.ts +1 -1
  47. package/lib/helpers/getGqlOperationName.js +15 -15
  48. package/lib/helpers/getSubdomain.d.ts +12 -12
  49. package/lib/helpers/getSubdomain.js +39 -39
  50. package/lib/helpers/isValidUrl.d.ts +1 -1
  51. package/lib/helpers/isValidUrl.js +9 -9
  52. package/lib/helpers/parseJwt.d.ts +1 -1
  53. package/lib/helpers/parseJwt.js +7 -7
  54. package/lib/helpers/userTypingSignal.d.ts +4 -4
  55. package/lib/helpers/userTypingSignal.js +32 -32
  56. package/lib/index.d.ts +27 -27
  57. package/lib/index.js +25 -25
  58. package/lib/interfaces/api/advoca/ISaveToDataBase.d.ts +16 -16
  59. package/lib/interfaces/api/advoca/ISaveToDataBase.js +1 -1
  60. package/lib/interfaces/api/advoca/IUploadedDocument.d.ts +26 -26
  61. package/lib/interfaces/api/advoca/IUploadedDocument.js +1 -1
  62. package/lib/interfaces/enums.d.ts +50 -50
  63. package/lib/interfaces/enums.js +59 -59
  64. package/lib/utility/fetch.d.ts +1 -1
  65. package/lib/utility/fetch.js +5 -5
  66. package/package.json +29 -29
  67. package/src/clients/srvAuth.ts +6 -6
  68. package/src/global.ts +45 -45
  69. package/src/helpers/CapitalizeFistLetter.ts +7 -7
  70. package/src/helpers/Config.ts +58 -58
  71. package/src/helpers/EnvironmentToOperateTypes.ts +6 -6
  72. package/src/helpers/EnvironmentsUrls.ts +102 -102
  73. package/src/helpers/FormatNumberConstants.ts +41 -41
  74. package/src/helpers/InitializeIDBListenersOnMstSnapshots.ts +62 -62
  75. package/src/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.ts +82 -82
  76. package/src/helpers/IsAdcuris.ts +4 -4
  77. package/src/helpers/IsNotEmpty.ts +2 -2
  78. package/src/helpers/NorwegianPostalCodes.ts +6 -6
  79. package/src/helpers/ProcessServerError.ts +92 -92
  80. package/src/helpers/attachUserJournalCredentials.ts +23 -0
  81. package/src/helpers/base64ToFile.ts +9 -9
  82. package/src/helpers/clearCacheData.ts +15 -15
  83. package/src/helpers/generateEnvConfigsBindings.ts +82 -82
  84. package/src/helpers/generateGenqlClient.ts +85 -85
  85. package/src/helpers/generateSrvAuthBindings.ts +204 -233
  86. package/src/helpers/getGqlOperationName.ts +20 -20
  87. package/src/helpers/getSubdomain.ts +50 -50
  88. package/src/helpers/isValidUrl.ts +12 -12
  89. package/src/helpers/parseJwt.ts +10 -10
  90. package/src/index.ts +33 -33
  91. package/src/interfaces/api/advoca/ISaveToDataBase.ts +17 -17
  92. package/src/interfaces/api/advoca/IUploadedDocument.ts +23 -23
  93. package/src/interfaces/enums.ts +56 -56
  94. package/src/utility/fetch.ts +9 -9
  95. package/tsconfig.json +84 -84
@@ -1,233 +1,204 @@
1
- import axios, { AxiosResponse, ResponseType } from 'axios'
2
- import { EnvironmentEnums, parseJwt } from '..'
3
- /* export interface IGenerateSRVAuthBindings extends ReturnType<typeof generateSrvAuthBindings> {} */ /*{
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 type feature_names_enum =
17
- | 'artifact_createQnrCustomContext'
18
- | 'autoImportableQnr'
19
- | 'calendar_BusyTimesAccess'
20
- | 'calendar_CoursesAccess'
21
- | 'calendar_EventsAccess'
22
- | 'calendar_EventsRequestsAccess'
23
- | 'calendar_TasksAccess'
24
- | 'calendar_access'
25
- | 'calendar_taskTemplatesCRUD'
26
- | 'dashboardTraceability'
27
- | 'directory_AdvocaCandidatProfile'
28
- | 'directory_AdvocaInvormationOnTiltak'
29
- | 'documentUploadFromAdopusPicker'
30
- | 'documentUploadFromDokkladPicker'
31
- | 'documentUploadFromLocalPicker'
32
- | 'documentUploadPickedDocuments'
33
- | 'experimental'
34
- | 'ordersOverviewOnSelectedRecipientsForQnr'
35
- | 'predefinedUserForQnr'
36
- | 'rejectableQnr'
37
- | 'signByTherapistDocument'
38
- export function generateSrvAuthBindings(
39
- SRV_AUTH: () => string,
40
- DEVELOPMENT: () => boolean,
41
- EnvironmentToOperateFn: () => string,
42
- logout?: () => void,
43
- ) {
44
- if (window.__ASMA__SHELL__?.auth_bindings) {
45
- return window.__ASMA__SHELL__.auth_bindings as typeof auth_bindings
46
- }
47
- let jwtToken = ''
48
-
49
- let features: Set<feature_names_enum> | undefined
50
-
51
- let parsed_jwt: any | undefined
52
-
53
- let fetchJwtPromise: Promise<{
54
- data: { message: string; token?: string; features?: feature_names_enum[]; errors: { message: string }[] }
55
- }> | null = null
56
-
57
- const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken
58
-
59
- const isJwtValid = () => !isJwtInvalid()
60
-
61
- async function srvAuthGet<R>(url: string, headers?: Record<string, string>) {
62
- if (DEVELOPMENT() && EnvironmentToOperateFn()) {
63
- if (EnvironmentToOperateFn() in EnvironmentEnums) {
64
- url = `${url}&env=${EnvironmentToOperateFn()}`
65
-
66
- url = url.includes('&') && !url.includes('?') ? url.replace('&', '?') : url
67
- } else {
68
- console.warn(
69
- 'EnvironmentToOperateFn() is not a valid EnvironmentEnums',
70
- 'shall be one of:',
71
- EnvironmentEnums,
72
- 'actual value:',
73
- EnvironmentToOperateFn(),
74
- )
75
- }
76
- }
77
-
78
- return axios.get<unknown, AxiosResponse<R>>(`${SRV_AUTH()}${url}`, {
79
- headers: {
80
- ...headers,
81
- 'asma-origin': window.location.origin,
82
- },
83
- withCredentials: true,
84
- })
85
- }
86
-
87
- function accessTokenHasExpired(): boolean {
88
- const tokenObj = getParsedJwt()
89
-
90
- const accessTokenExpDate = tokenObj?.exp || 0
91
-
92
- const nowTime = Math.floor(new Date().getTime() / 1000)
93
-
94
- //set exp time -20sec for token to be refreshed early
95
- return accessTokenExpDate - 10 <= nowTime
96
- }
97
-
98
- async function signin(url: string, headers?: Record<string, string>) {
99
- const { data } = await srvAuthGet<{ token: string; features: feature_names_enum[] }>(url, headers)
100
-
101
- setAuthData(data)
102
-
103
- return data
104
- }
105
-
106
- async function signoutAuth() {
107
- setAuthData({ token: '' })
108
- await srvAuthGet('/signout')
109
- }
110
- function getUserId(): string {
111
- return getParsedJwt()?.['user_id'] || '-1'
112
- }
113
-
114
- function setAuthData(data: { token: string; features?: feature_names_enum[] }) {
115
- jwtToken = data.token
116
- features = new Set(data.features)
117
- parsed_jwt = undefined
118
- }
119
-
120
- function getJwtToken() {
121
- return jwtToken
122
- }
123
-
124
- async function getJwtTokenAsync() {
125
- if (isJwtInvalid()) {
126
- const new_jwt = await getNewJwtToken()
127
-
128
- return new_jwt
129
- } else {
130
- return jwtToken
131
- }
132
- }
133
-
134
- async function setReqConfig<T = unknown>(data?: T, responseType?: ResponseType) {
135
- const token = await getJwtTokenAsync()
136
-
137
- const res = {
138
- data: data,
139
- responseType: responseType,
140
- headers: {} as Record<string, string>,
141
- }
142
-
143
- if (token) {
144
- res.headers['Authorization'] = `Bearer ${token}`
145
- }
146
-
147
- return res
148
- }
149
-
150
- async function getNewJwtToken() {
151
- try {
152
- if (!fetchJwtPromise) {
153
- fetchJwtPromise = srvAuthGet('/token')
154
- }
155
-
156
- const { data } = await fetchJwtPromise
157
-
158
- if (!data || data.errors || data.message != 'Success') {
159
- logout?.() || signoutAuth()
160
- }
161
- if (!data.token) {
162
- throw new Error('Token is not present in the result')
163
- }
164
- setAuthData({ token: data.token || '', features: data.features || [] })
165
-
166
- fetchJwtPromise = null
167
-
168
- return jwtToken
169
- } catch (error) {
170
- logout?.() || signoutAuth()
171
- //signoutAuth()
172
-
173
- fetchJwtPromise = null
174
-
175
- console.error(error)
176
-
177
- return jwtToken
178
- }
179
- }
180
-
181
- function getParsedJwt<R = { user_id: string; exp: number }>(): R | undefined {
182
- if (!parsed_jwt) {
183
- parsed_jwt = parseJwt<R>(jwtToken)
184
- }
185
- return parsed_jwt
186
- }
187
- function getFeatures() {
188
- return features
189
- }
190
- function hasFeature(featureName: feature_names_enum) {
191
- return !!features?.has(featureName)
192
- }
193
-
194
- const auth_bindings = {
195
- hasFeature,
196
- getFeatures,
197
- isJwtValid,
198
- signin,
199
- srvAuthGet,
200
- signoutAuth,
201
- setReqConfig,
202
- getJwtTokenAsync,
203
- getNewJwtToken,
204
- getUserId,
205
- getParsedJwt,
206
- getJwtToken,
207
- accessTokenHasExpired,
208
- }
209
- window.__ASMA__SHELL__ = window.__ASMA__SHELL__ || {}
210
-
211
- window.__ASMA__SHELL__.auth_bindings = auth_bindings
212
-
213
- return auth_bindings
214
- }
215
- /**
216
- * @deprecated use generateSrvAuthBindings
217
- * @param SRV_AUTH
218
- * @param DEVELOPMENT
219
- * @param ENVIRONMENT_TO_OPERATE
220
- * @param logout
221
- * @returns
222
- */
223
- export function generateSrvAuthBindingsMicroApp(
224
- SRV_AUTH: () => string,
225
- DEVELOPMENT: () => boolean,
226
- ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums,
227
- logout?: () => void,
228
- ) {
229
- return (
230
- window.__ASMA__SHELL__?.auth_bindings ||
231
- generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout)
232
- )
233
- }
1
+ import axios, { AxiosResponse, ResponseType } from 'axios'
2
+ import { EnvironmentEnums, parseJwt } from '..'
3
+
4
+ export function generateSrvAuthBindings<FeatureEnums = never>(
5
+ SRV_AUTH: () => string,
6
+ DEVELOPMENT: () => boolean,
7
+ EnvironmentToOperateFn: () => string,
8
+ logout?: () => void,
9
+ ) {
10
+ if (window.__ASMA__SHELL__?.auth_bindings) {
11
+ return window.__ASMA__SHELL__.auth_bindings as typeof auth_bindings
12
+ }
13
+ let jwtToken = ''
14
+
15
+ let features: Set<FeatureEnums> | undefined
16
+
17
+ let parsed_jwt: any | undefined
18
+
19
+ let fetchJwtPromise: Promise<{
20
+ data: { message: string; token?: string; features?: FeatureEnums[]; errors: { message: string }[] }
21
+ }> | null = null
22
+
23
+ const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken
24
+
25
+ const isJwtValid = () => !isJwtInvalid()
26
+
27
+ async function srvAuthGet<R>(url: string, headers?: Record<string, string>) {
28
+ if (DEVELOPMENT() && EnvironmentToOperateFn()) {
29
+ if (EnvironmentToOperateFn() in EnvironmentEnums) {
30
+ url = `${url}&env=${EnvironmentToOperateFn()}`
31
+
32
+ url = url.includes('&') && !url.includes('?') ? url.replace('&', '?') : url
33
+ } else {
34
+ console.warn(
35
+ 'EnvironmentToOperateFn() is not a valid EnvironmentEnums',
36
+ 'shall be one of:',
37
+ EnvironmentEnums,
38
+ 'actual value:',
39
+ EnvironmentToOperateFn(),
40
+ )
41
+ }
42
+ }
43
+
44
+ return axios.get<unknown, AxiosResponse<R>>(`${SRV_AUTH()}${url}`, {
45
+ headers: {
46
+ ...headers,
47
+ 'asma-origin': window.location.origin,
48
+ },
49
+ withCredentials: true,
50
+ })
51
+ }
52
+
53
+ function accessTokenHasExpired(): boolean {
54
+ const tokenObj = getParsedJwt()
55
+
56
+ const accessTokenExpDate = tokenObj?.exp || 0
57
+
58
+ const nowTime = Math.floor(new Date().getTime() / 1000)
59
+
60
+ //set exp time -20sec for token to be refreshed early
61
+ return accessTokenExpDate - 10 <= nowTime
62
+ }
63
+
64
+ async function signin(url: string, headers?: Record<string, string>) {
65
+ const { data } = await srvAuthGet<{ token: string; features: FeatureEnums[] }>(url, headers)
66
+
67
+ setAuthData(data)
68
+
69
+ return data
70
+ }
71
+
72
+ async function signoutAuth() {
73
+ setAuthData({ token: '' })
74
+ await srvAuthGet('/signout')
75
+ }
76
+ function getUserId(): string {
77
+ return getParsedJwt()?.['user_id'] || '-1'
78
+ }
79
+
80
+ function setAuthData(data: { token: string; features?: FeatureEnums[] }) {
81
+ jwtToken = data.token
82
+ features = new Set(data.features)
83
+ parsed_jwt = undefined
84
+ }
85
+
86
+ function getJwtToken() {
87
+ return jwtToken
88
+ }
89
+
90
+ async function getJwtTokenAsync() {
91
+ if (isJwtInvalid()) {
92
+ const new_jwt = await getNewJwtToken()
93
+
94
+ return new_jwt
95
+ } else {
96
+ return jwtToken
97
+ }
98
+ }
99
+
100
+ async function setReqConfig<T = unknown>(data?: T, responseType?: ResponseType) {
101
+ const token = await getJwtTokenAsync()
102
+
103
+ const res = {
104
+ data: data,
105
+ responseType: responseType,
106
+ headers: {} as Record<string, string>,
107
+ }
108
+
109
+ if (token) {
110
+ res.headers['Authorization'] = `Bearer ${token}`
111
+ }
112
+
113
+ return res
114
+ }
115
+
116
+ async function getNewJwtToken() {
117
+ try {
118
+ if (!fetchJwtPromise) {
119
+ fetchJwtPromise = srvAuthGet('/token')
120
+ }
121
+
122
+ const { data } = await fetchJwtPromise
123
+
124
+ if (!data || data.errors || data.message != 'Success') {
125
+ logout?.() || signoutAuth()
126
+ }
127
+ if (!data.token) {
128
+ throw new Error('Token is not present in the result')
129
+ }
130
+ setAuthData({ token: data.token || '', features: data.features || [] })
131
+
132
+ fetchJwtPromise = null
133
+
134
+ return jwtToken
135
+ } catch (error) {
136
+ logout?.() || signoutAuth()
137
+ //signoutAuth()
138
+
139
+ fetchJwtPromise = null
140
+
141
+ console.error(error)
142
+
143
+ return jwtToken
144
+ }
145
+ }
146
+
147
+ function getParsedJwt<R = { user_id: string; exp: number }>(): R | undefined {
148
+ if (!parsed_jwt) {
149
+ parsed_jwt = parseJwt<R>(jwtToken)
150
+ }
151
+ return parsed_jwt
152
+ }
153
+ function getFeatures() {
154
+ return features
155
+ }
156
+ /**
157
+ *
158
+ * @param featureName feature_name_enums add this: generateSrvAuthBindings<feature_name_enums.>(...)
159
+ * @returns boolean
160
+ */
161
+ function hasFeature(featureName: FeatureEnums) {
162
+ return !!features?.has(featureName)
163
+ }
164
+
165
+ const auth_bindings = {
166
+ hasFeature,
167
+ getFeatures,
168
+ isJwtValid,
169
+ signin,
170
+ srvAuthGet,
171
+ signoutAuth,
172
+ setReqConfig,
173
+ getJwtTokenAsync,
174
+ getNewJwtToken,
175
+ getUserId,
176
+ getParsedJwt,
177
+ getJwtToken,
178
+ accessTokenHasExpired,
179
+ }
180
+ window.__ASMA__SHELL__ = window.__ASMA__SHELL__ || {}
181
+
182
+ window.__ASMA__SHELL__.auth_bindings = auth_bindings
183
+
184
+ return auth_bindings
185
+ }
186
+ /**
187
+ * @deprecated use generateSrvAuthBindings
188
+ * @param SRV_AUTH
189
+ * @param DEVELOPMENT
190
+ * @param ENVIRONMENT_TO_OPERATE
191
+ * @param logout
192
+ * @returns
193
+ */
194
+ export function generateSrvAuthBindingsMicroApp(
195
+ SRV_AUTH: () => string,
196
+ DEVELOPMENT: () => boolean,
197
+ ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums,
198
+ logout?: () => void,
199
+ ) {
200
+ return (
201
+ window.__ASMA__SHELL__?.auth_bindings ||
202
+ generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout)
203
+ )
204
+ }
@@ -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
+ }
@@ -1,11 +1,11 @@
1
-
2
-
3
- export function parseJwt<R>(jwtToken: string): R|undefined {
4
- const base64Url = jwtToken?.split('.')[1]
5
-
6
- if (base64Url === undefined) {
7
- return {} as any
8
- }
9
-
10
- return JSON.parse(decodeURIComponent(escape(window.atob(base64Url))))
1
+
2
+
3
+ export function parseJwt<R>(jwtToken: string): R|undefined {
4
+ const base64Url = jwtToken?.split('.')[1]
5
+
6
+ if (base64Url === undefined) {
7
+ return {} as any
8
+ }
9
+
10
+ return JSON.parse(decodeURIComponent(escape(window.atob(base64Url))))
11
11
  }