asma-helpers 0.2.11 → 0.2.13

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 (91) 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 -81
  15. package/lib/helpers/EnvironmentsUrls.d.ts.map +1 -1
  16. package/lib/helpers/EnvironmentsUrls.js +89 -79
  17. package/lib/helpers/EnvironmentsUrls.js.map +1 -1
  18. package/lib/helpers/FormatNumberConstants.d.ts +24 -24
  19. package/lib/helpers/FormatNumberConstants.js +40 -40
  20. package/lib/helpers/InitializeIDBListenersOnMstSnapshots.d.ts +1 -1
  21. package/lib/helpers/InitializeIDBListenersOnMstSnapshots.js +49 -49
  22. package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.d.ts +8 -8
  23. package/lib/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.js +68 -68
  24. package/lib/helpers/IsAdcuris.d.ts +2 -2
  25. package/lib/helpers/IsAdcuris.js +4 -4
  26. package/lib/helpers/IsNotEmpty.d.ts +1 -1
  27. package/lib/helpers/IsNotEmpty.js +3 -3
  28. package/lib/helpers/NorwegianPostalCodes.d.ts +8 -8
  29. package/lib/helpers/NorwegianPostalCodes.js +3 -3
  30. package/lib/helpers/ProcessServerError.d.ts +2 -2
  31. package/lib/helpers/ProcessServerError.js +100 -100
  32. package/lib/helpers/base64ToFile.d.ts +1 -1
  33. package/lib/helpers/base64ToFile.js +8 -8
  34. package/lib/helpers/clearCacheData.d.ts +1 -1
  35. package/lib/helpers/clearCacheData.js +12 -12
  36. package/lib/helpers/generateEnvConfigsBindings.d.ts +30 -28
  37. package/lib/helpers/generateEnvConfigsBindings.d.ts.map +1 -1
  38. package/lib/helpers/generateEnvConfigsBindings.js +48 -48
  39. package/lib/helpers/generateGenqlClient.d.ts +18 -18
  40. package/lib/helpers/generateGenqlClient.js +56 -56
  41. package/lib/helpers/generateSrvAuthBindings.d.ts +33 -33
  42. package/lib/helpers/generateSrvAuthBindings.js +163 -163
  43. package/lib/helpers/getGqlOperationName.d.ts +1 -1
  44. package/lib/helpers/getGqlOperationName.js +15 -15
  45. package/lib/helpers/getSubdomain.d.ts +3 -3
  46. package/lib/helpers/getSubdomain.js +27 -27
  47. package/lib/helpers/isValidUrl.d.ts +1 -1
  48. package/lib/helpers/isValidUrl.js +9 -9
  49. package/lib/helpers/parseJwt.d.ts +1 -1
  50. package/lib/helpers/parseJwt.js +7 -7
  51. package/lib/helpers/userTypingSignal.d.ts +4 -4
  52. package/lib/helpers/userTypingSignal.js +32 -32
  53. package/lib/index.d.ts +27 -27
  54. package/lib/index.js +25 -25
  55. package/lib/interfaces/api/advoca/ISaveToDataBase.d.ts +16 -16
  56. package/lib/interfaces/api/advoca/ISaveToDataBase.js +1 -1
  57. package/lib/interfaces/api/advoca/IUploadedDocument.d.ts +26 -26
  58. package/lib/interfaces/api/advoca/IUploadedDocument.js +1 -1
  59. package/lib/interfaces/enums.d.ts +50 -50
  60. package/lib/interfaces/enums.js +59 -59
  61. package/lib/utility/fetch.d.ts +1 -1
  62. package/lib/utility/fetch.js +5 -5
  63. package/package.json +30 -30
  64. package/src/clients/srvAuth.ts +6 -6
  65. package/src/global.ts +45 -45
  66. package/src/helpers/CapitalizeFistLetter.ts +7 -7
  67. package/src/helpers/Config.ts +58 -58
  68. package/src/helpers/EnvironmentToOperateTypes.ts +6 -6
  69. package/src/helpers/EnvironmentsUrls.ts +102 -92
  70. package/src/helpers/FormatNumberConstants.ts +41 -41
  71. package/src/helpers/InitializeIDBListenersOnMstSnapshots.ts +62 -62
  72. package/src/helpers/InitializeIDBListenersOnMstSnapshotsThenCatch.ts +82 -82
  73. package/src/helpers/IsAdcuris.ts +4 -4
  74. package/src/helpers/IsNotEmpty.ts +2 -2
  75. package/src/helpers/NorwegianPostalCodes.ts +6 -6
  76. package/src/helpers/ProcessServerError.ts +92 -92
  77. package/src/helpers/base64ToFile.ts +9 -9
  78. package/src/helpers/clearCacheData.ts +15 -15
  79. package/src/helpers/generateEnvConfigsBindings.ts +82 -82
  80. package/src/helpers/generateGenqlClient.ts +85 -85
  81. package/src/helpers/generateSrvAuthBindings.ts +215 -215
  82. package/src/helpers/getGqlOperationName.ts +20 -20
  83. package/src/helpers/getSubdomain.ts +40 -40
  84. package/src/helpers/isValidUrl.ts +12 -12
  85. package/src/helpers/parseJwt.ts +10 -10
  86. package/src/index.ts +33 -33
  87. package/src/interfaces/api/advoca/ISaveToDataBase.ts +17 -17
  88. package/src/interfaces/api/advoca/IUploadedDocument.ts +23 -23
  89. package/src/interfaces/enums.ts +56 -56
  90. package/src/utility/fetch.ts +9 -9
  91. package/tsconfig.json +84 -84
@@ -1,34 +1,34 @@
1
- import type { feature_names_enum } from 'asma-genql-directory/lib';
2
- import { AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios';
3
- import { EnvironmentEnums } from '..';
4
- export declare function generateSrvAuthBindings(SRV_AUTH: () => string, DEVELOPMENT: () => boolean, EnvironmentToOperateFn: () => string, logout?: () => void): {
5
- hasFeature: (featureName: feature_names_enum) => boolean;
6
- getFeatures: () => Set<feature_names_enum> | undefined;
7
- isJwtValid: () => boolean;
8
- signin: (url: string, headers?: Record<string, string>) => Promise<{
9
- token: string;
10
- features: feature_names_enum[];
11
- }>;
12
- srvAuthGet: <R>(url: string, headers?: Record<string, string>) => Promise<AxiosResponse<R, any>>;
13
- signoutAuth: () => Promise<void>;
14
- setReqConfig: <T = unknown>(data?: T | undefined, responseType?: ResponseType) => Promise<AxiosRequestConfig>;
15
- getJwtTokenAsync: () => Promise<string>;
16
- getNewJwtToken: () => Promise<string>;
17
- getUserId: () => string;
18
- getParsedJwt: <R_1 = {
19
- user_id: string;
20
- exp: number;
21
- }>() => R_1 | undefined;
22
- getJwtToken: () => string;
23
- accessTokenHasExpired: () => boolean;
24
- };
25
- /**
26
- * @deprecated use generateSrvAuthBindings
27
- * @param SRV_AUTH
28
- * @param DEVELOPMENT
29
- * @param ENVIRONMENT_TO_OPERATE
30
- * @param logout
31
- * @returns
32
- */
33
- export declare function generateSrvAuthBindingsMicroApp(SRV_AUTH: () => string, DEVELOPMENT: () => boolean, ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums, logout?: () => void): {};
1
+ import type { feature_names_enum } from 'asma-genql-directory/lib';
2
+ import { AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios';
3
+ import { EnvironmentEnums } from '..';
4
+ export declare function generateSrvAuthBindings(SRV_AUTH: () => string, DEVELOPMENT: () => boolean, EnvironmentToOperateFn: () => string, logout?: () => void): {
5
+ hasFeature: (featureName: feature_names_enum) => boolean;
6
+ getFeatures: () => Set<feature_names_enum> | undefined;
7
+ isJwtValid: () => boolean;
8
+ signin: (url: string, headers?: Record<string, string>) => Promise<{
9
+ token: string;
10
+ features: feature_names_enum[];
11
+ }>;
12
+ srvAuthGet: <R>(url: string, headers?: Record<string, string>) => Promise<AxiosResponse<R, any>>;
13
+ signoutAuth: () => Promise<void>;
14
+ setReqConfig: <T = unknown>(data?: T | undefined, responseType?: ResponseType) => Promise<AxiosRequestConfig>;
15
+ getJwtTokenAsync: () => Promise<string>;
16
+ getNewJwtToken: () => Promise<string>;
17
+ getUserId: () => string;
18
+ getParsedJwt: <R_1 = {
19
+ user_id: string;
20
+ exp: number;
21
+ }>() => R_1 | undefined;
22
+ getJwtToken: () => string;
23
+ accessTokenHasExpired: () => boolean;
24
+ };
25
+ /**
26
+ * @deprecated use generateSrvAuthBindings
27
+ * @param SRV_AUTH
28
+ * @param DEVELOPMENT
29
+ * @param ENVIRONMENT_TO_OPERATE
30
+ * @param logout
31
+ * @returns
32
+ */
33
+ export declare function generateSrvAuthBindingsMicroApp(SRV_AUTH: () => string, DEVELOPMENT: () => boolean, ENVIRONMENT_TO_OPERATE: () => EnvironmentEnums, logout?: () => void): {};
34
34
  //# sourceMappingURL=generateSrvAuthBindings.d.ts.map
@@ -1,164 +1,164 @@
1
- import axios 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 function generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, EnvironmentToOperateFn, logout) {
17
- var _a;
18
- if ((_a = window.__ASMA__SHELL__) === null || _a === void 0 ? void 0 : _a.auth_bindings) {
19
- return window.__ASMA__SHELL__.auth_bindings;
20
- }
21
- let jwtToken = '';
22
- let features;
23
- let parsed_jwt;
24
- let fetchJwtPromise = null;
25
- const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken;
26
- const isJwtValid = () => !isJwtInvalid();
27
- async function srvAuthGet(url, headers) {
28
- if (DEVELOPMENT() && EnvironmentToOperateFn()) {
29
- if (EnvironmentToOperateFn() in EnvironmentEnums) {
30
- url = `${url}&env=${EnvironmentToOperateFn()}`;
31
- url = url.includes('&') && !url.includes('?') ? url.replace('&', '?') : url;
32
- }
33
- else {
34
- console.warn('EnvironmentToOperateFn() is not a valid EnvironmentEnums', 'shall be one of:', EnvironmentEnums, 'actual value:', EnvironmentToOperateFn());
35
- }
36
- }
37
- return axios.get(`${SRV_AUTH()}${url}`, {
38
- headers: {
39
- ...headers,
40
- 'asma-origin': window.location.origin,
41
- },
42
- withCredentials: true,
43
- });
44
- }
45
- function accessTokenHasExpired() {
46
- const tokenObj = getParsedJwt();
47
- const accessTokenExpDate = (tokenObj === null || tokenObj === void 0 ? void 0 : tokenObj.exp) || 0;
48
- const nowTime = Math.floor(new Date().getTime() / 1000);
49
- //set exp time -20sec for token to be refreshed early
50
- return accessTokenExpDate - 10 <= nowTime;
51
- }
52
- async function signin(url, headers) {
53
- const { data } = await srvAuthGet(url, headers);
54
- setAuthData(data);
55
- return data;
56
- }
57
- async function signoutAuth() {
58
- setAuthData({ token: '' });
59
- await srvAuthGet('/signout');
60
- }
61
- function getUserId() {
62
- var _a;
63
- return ((_a = getParsedJwt()) === null || _a === void 0 ? void 0 : _a['user_id']) || '-1';
64
- }
65
- function setAuthData(data) {
66
- jwtToken = data.token;
67
- features = new Set(data.features);
68
- }
69
- function getJwtToken() {
70
- return jwtToken;
71
- }
72
- async function getJwtTokenAsync() {
73
- if (isJwtInvalid()) {
74
- const new_jwt = await getNewJwtToken();
75
- return new_jwt;
76
- }
77
- else {
78
- return jwtToken;
79
- }
80
- }
81
- async function setReqConfig(data, responseType) {
82
- const token = await getJwtTokenAsync();
83
- const res = {
84
- data: data,
85
- responseType: responseType,
86
- headers: {},
87
- };
88
- if (token) {
89
- if (!res.headers) {
90
- res.headers = {};
91
- }
92
- res.headers['Authorization'] = `Bearer ${token}`;
93
- }
94
- return res;
95
- }
96
- async function getNewJwtToken() {
97
- try {
98
- if (!fetchJwtPromise) {
99
- fetchJwtPromise = srvAuthGet('/token');
100
- }
101
- const { data } = await fetchJwtPromise;
102
- if (!data || data.errors || data.message != 'Success') {
103
- (logout === null || logout === void 0 ? void 0 : logout()) || signoutAuth();
104
- }
105
- if (!data.token) {
106
- throw new Error('Token is not present in the result');
107
- }
108
- setAuthData({ token: data.token || '', features: data.features || [] });
109
- fetchJwtPromise = null;
110
- return jwtToken;
111
- }
112
- catch (error) {
113
- (logout === null || logout === void 0 ? void 0 : logout()) || signoutAuth();
114
- //signoutAuth()
115
- fetchJwtPromise = null;
116
- console.error(error);
117
- return jwtToken;
118
- }
119
- }
120
- function getParsedJwt() {
121
- if (!parsed_jwt) {
122
- parsed_jwt = parseJwt(jwtToken);
123
- }
124
- return parsed_jwt;
125
- }
126
- function getFeatures() {
127
- return features;
128
- }
129
- function hasFeature(featureName) {
130
- return !!(features === null || features === void 0 ? void 0 : features.has(featureName));
131
- }
132
- const auth_bindings = {
133
- hasFeature,
134
- getFeatures,
135
- isJwtValid,
136
- signin,
137
- srvAuthGet,
138
- signoutAuth,
139
- setReqConfig,
140
- getJwtTokenAsync,
141
- getNewJwtToken,
142
- getUserId,
143
- getParsedJwt,
144
- getJwtToken,
145
- accessTokenHasExpired,
146
- };
147
- window.__ASMA__SHELL__ = window.__ASMA__SHELL__ || {};
148
- window.__ASMA__SHELL__.auth_bindings = auth_bindings;
149
- return auth_bindings;
150
- }
151
- /**
152
- * @deprecated use generateSrvAuthBindings
153
- * @param SRV_AUTH
154
- * @param DEVELOPMENT
155
- * @param ENVIRONMENT_TO_OPERATE
156
- * @param logout
157
- * @returns
158
- */
159
- export function generateSrvAuthBindingsMicroApp(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout) {
160
- var _a;
161
- return (((_a = window.__ASMA__SHELL__) === null || _a === void 0 ? void 0 : _a.auth_bindings) ||
162
- generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout));
163
- }
1
+ import axios 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 function generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, EnvironmentToOperateFn, logout) {
17
+ var _a;
18
+ if ((_a = window.__ASMA__SHELL__) === null || _a === void 0 ? void 0 : _a.auth_bindings) {
19
+ return window.__ASMA__SHELL__.auth_bindings;
20
+ }
21
+ let jwtToken = '';
22
+ let features;
23
+ let parsed_jwt;
24
+ let fetchJwtPromise = null;
25
+ const isJwtInvalid = () => (jwtToken && accessTokenHasExpired()) || !jwtToken;
26
+ const isJwtValid = () => !isJwtInvalid();
27
+ async function srvAuthGet(url, headers) {
28
+ if (DEVELOPMENT() && EnvironmentToOperateFn()) {
29
+ if (EnvironmentToOperateFn() in EnvironmentEnums) {
30
+ url = `${url}&env=${EnvironmentToOperateFn()}`;
31
+ url = url.includes('&') && !url.includes('?') ? url.replace('&', '?') : url;
32
+ }
33
+ else {
34
+ console.warn('EnvironmentToOperateFn() is not a valid EnvironmentEnums', 'shall be one of:', EnvironmentEnums, 'actual value:', EnvironmentToOperateFn());
35
+ }
36
+ }
37
+ return axios.get(`${SRV_AUTH()}${url}`, {
38
+ headers: {
39
+ ...headers,
40
+ 'asma-origin': window.location.origin,
41
+ },
42
+ withCredentials: true,
43
+ });
44
+ }
45
+ function accessTokenHasExpired() {
46
+ const tokenObj = getParsedJwt();
47
+ const accessTokenExpDate = (tokenObj === null || tokenObj === void 0 ? void 0 : tokenObj.exp) || 0;
48
+ const nowTime = Math.floor(new Date().getTime() / 1000);
49
+ //set exp time -20sec for token to be refreshed early
50
+ return accessTokenExpDate - 10 <= nowTime;
51
+ }
52
+ async function signin(url, headers) {
53
+ const { data } = await srvAuthGet(url, headers);
54
+ setAuthData(data);
55
+ return data;
56
+ }
57
+ async function signoutAuth() {
58
+ setAuthData({ token: '' });
59
+ await srvAuthGet('/signout');
60
+ }
61
+ function getUserId() {
62
+ var _a;
63
+ return ((_a = getParsedJwt()) === null || _a === void 0 ? void 0 : _a['user_id']) || '-1';
64
+ }
65
+ function setAuthData(data) {
66
+ jwtToken = data.token;
67
+ features = new Set(data.features);
68
+ }
69
+ function getJwtToken() {
70
+ return jwtToken;
71
+ }
72
+ async function getJwtTokenAsync() {
73
+ if (isJwtInvalid()) {
74
+ const new_jwt = await getNewJwtToken();
75
+ return new_jwt;
76
+ }
77
+ else {
78
+ return jwtToken;
79
+ }
80
+ }
81
+ async function setReqConfig(data, responseType) {
82
+ const token = await getJwtTokenAsync();
83
+ const res = {
84
+ data: data,
85
+ responseType: responseType,
86
+ headers: {},
87
+ };
88
+ if (token) {
89
+ if (!res.headers) {
90
+ res.headers = {};
91
+ }
92
+ res.headers['Authorization'] = `Bearer ${token}`;
93
+ }
94
+ return res;
95
+ }
96
+ async function getNewJwtToken() {
97
+ try {
98
+ if (!fetchJwtPromise) {
99
+ fetchJwtPromise = srvAuthGet('/token');
100
+ }
101
+ const { data } = await fetchJwtPromise;
102
+ if (!data || data.errors || data.message != 'Success') {
103
+ (logout === null || logout === void 0 ? void 0 : logout()) || signoutAuth();
104
+ }
105
+ if (!data.token) {
106
+ throw new Error('Token is not present in the result');
107
+ }
108
+ setAuthData({ token: data.token || '', features: data.features || [] });
109
+ fetchJwtPromise = null;
110
+ return jwtToken;
111
+ }
112
+ catch (error) {
113
+ (logout === null || logout === void 0 ? void 0 : logout()) || signoutAuth();
114
+ //signoutAuth()
115
+ fetchJwtPromise = null;
116
+ console.error(error);
117
+ return jwtToken;
118
+ }
119
+ }
120
+ function getParsedJwt() {
121
+ if (!parsed_jwt) {
122
+ parsed_jwt = parseJwt(jwtToken);
123
+ }
124
+ return parsed_jwt;
125
+ }
126
+ function getFeatures() {
127
+ return features;
128
+ }
129
+ function hasFeature(featureName) {
130
+ return !!(features === null || features === void 0 ? void 0 : features.has(featureName));
131
+ }
132
+ const auth_bindings = {
133
+ hasFeature,
134
+ getFeatures,
135
+ isJwtValid,
136
+ signin,
137
+ srvAuthGet,
138
+ signoutAuth,
139
+ setReqConfig,
140
+ getJwtTokenAsync,
141
+ getNewJwtToken,
142
+ getUserId,
143
+ getParsedJwt,
144
+ getJwtToken,
145
+ accessTokenHasExpired,
146
+ };
147
+ window.__ASMA__SHELL__ = window.__ASMA__SHELL__ || {};
148
+ window.__ASMA__SHELL__.auth_bindings = auth_bindings;
149
+ return auth_bindings;
150
+ }
151
+ /**
152
+ * @deprecated use generateSrvAuthBindings
153
+ * @param SRV_AUTH
154
+ * @param DEVELOPMENT
155
+ * @param ENVIRONMENT_TO_OPERATE
156
+ * @param logout
157
+ * @returns
158
+ */
159
+ export function generateSrvAuthBindingsMicroApp(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout) {
160
+ var _a;
161
+ return (((_a = window.__ASMA__SHELL__) === null || _a === void 0 ? void 0 : _a.auth_bindings) ||
162
+ generateSrvAuthBindings(SRV_AUTH, DEVELOPMENT, ENVIRONMENT_TO_OPERATE, logout));
163
+ }
164
164
  //# sourceMappingURL=generateSrvAuthBindings.js.map
@@ -1,2 +1,2 @@
1
- export declare function getGqlOperationName(query: string): string | undefined;
1
+ export declare function getGqlOperationName(query: string): string | undefined;
2
2
  //# sourceMappingURL=getGqlOperationName.d.ts.map
@@ -1,16 +1,16 @@
1
- export function getGqlOperationName(query) {
2
- var _a, _b, _c, _d, _e;
3
- const is_query = query.includes('query') ? 'query' : undefined;
4
- const is_mutation = query.includes('mutation') ? 'mutation' : undefined;
5
- const is_subscription = query.includes('subscription') ? 'subscription' : undefined;
6
- const split_word = is_query || is_mutation || is_subscription;
7
- if (!split_word) {
8
- return undefined;
9
- }
10
- let operationName = (_e = (_d = (_c = (_b = (_a = query === null || query === void 0 ? void 0 : query.split(split_word, 2)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.split('{', 1)[0]) === null || _c === void 0 ? void 0 : _c.split(' ')) === null || _d === void 0 ? void 0 : _d[1]) === null || _e === void 0 ? void 0 : _e.trim();
11
- if (operationName === null || operationName === void 0 ? void 0 : operationName.includes('(')) {
12
- operationName = operationName.split('(', 1)[0];
13
- }
14
- return operationName;
15
- }
1
+ export function getGqlOperationName(query) {
2
+ var _a, _b, _c, _d, _e;
3
+ const is_query = query.includes('query') ? 'query' : undefined;
4
+ const is_mutation = query.includes('mutation') ? 'mutation' : undefined;
5
+ const is_subscription = query.includes('subscription') ? 'subscription' : undefined;
6
+ const split_word = is_query || is_mutation || is_subscription;
7
+ if (!split_word) {
8
+ return undefined;
9
+ }
10
+ let operationName = (_e = (_d = (_c = (_b = (_a = query === null || query === void 0 ? void 0 : query.split(split_word, 2)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.split('{', 1)[0]) === null || _c === void 0 ? void 0 : _c.split(' ')) === null || _d === void 0 ? void 0 : _d[1]) === null || _e === void 0 ? void 0 : _e.trim();
11
+ if (operationName === null || operationName === void 0 ? void 0 : operationName.includes('(')) {
12
+ operationName = operationName.split('(', 1)[0];
13
+ }
14
+ return operationName;
15
+ }
16
16
  //# sourceMappingURL=getGqlOperationName.js.map
@@ -1,4 +1,4 @@
1
- export declare const subdomain: string;
2
- export declare function redirectFromSubdomainToDomain(): null;
3
- export declare function createDomainUrlFromSubdomain(): string;
1
+ export declare const subdomain: string;
2
+ export declare function redirectFromSubdomainToDomain(): null;
3
+ export declare function createDomainUrlFromSubdomain(): string;
4
4
  //# sourceMappingURL=getSubdomain.d.ts.map
@@ -1,28 +1,28 @@
1
- function getSubdomain() {
2
- const hostname_arr = window.location.hostname.split('.'); // fretex-dfsf.advoca.no
3
- let subdomain = '';
4
- if (hostname_arr.length === 3 &&
5
- hostname_arr[0] &&
6
- !['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === hostname_arr[0])) {
7
- subdomain = hostname_arr[0];
8
- const subdomain_arr = subdomain.split('-');
9
- if (subdomain_arr.length === 2 && subdomain_arr[0]) {
10
- subdomain = subdomain_arr[0];
11
- }
12
- }
13
- return subdomain;
14
- }
15
- export const subdomain = getSubdomain();
16
- export function redirectFromSubdomainToDomain() {
17
- const domain_hostname = `${createDomainUrlFromSubdomain()}${window.location.pathname}`;
18
- window.location.href = domain_hostname;
19
- return null;
20
- }
21
- export function createDomainUrlFromSubdomain() {
22
- let hostname = window.location.hostname.replace(subdomain, '');
23
- (hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
24
- (hostname.startsWith('.') && (hostname = 'www' + hostname));
25
- const { port, protocol } = window.location;
26
- return protocol + '//' + hostname + (port ? `:${port}` : '');
27
- }
1
+ function getSubdomain() {
2
+ const hostname_arr = window.location.hostname.split('.'); // fretex-dfsf.advoca.no
3
+ let subdomain = '';
4
+ if (hostname_arr.length === 3 &&
5
+ hostname_arr[0] &&
6
+ !['dev', 'test', 'stage', 'intern', 'www'].find((sub) => sub === hostname_arr[0])) {
7
+ subdomain = hostname_arr[0];
8
+ const subdomain_arr = subdomain.split('-');
9
+ if (subdomain_arr.length === 2 && subdomain_arr[0]) {
10
+ subdomain = subdomain_arr[0];
11
+ }
12
+ }
13
+ return subdomain;
14
+ }
15
+ export const subdomain = getSubdomain();
16
+ export function redirectFromSubdomainToDomain() {
17
+ const domain_hostname = `${createDomainUrlFromSubdomain()}${window.location.pathname}`;
18
+ window.location.href = domain_hostname;
19
+ return null;
20
+ }
21
+ export function createDomainUrlFromSubdomain() {
22
+ let hostname = window.location.hostname.replace(subdomain, '');
23
+ (hostname.startsWith('-') && (hostname = hostname.substring(1))) ||
24
+ (hostname.startsWith('.') && (hostname = 'www' + hostname));
25
+ const { port, protocol } = window.location;
26
+ return protocol + '//' + hostname + (port ? `:${port}` : '');
27
+ }
28
28
  //# sourceMappingURL=getSubdomain.js.map
@@ -1,2 +1,2 @@
1
- export declare function isValidUrl(urlString: string): boolean;
1
+ export declare function isValidUrl(urlString: string): boolean;
2
2
  //# sourceMappingURL=isValidUrl.d.ts.map
@@ -1,10 +1,10 @@
1
- export function isValidUrl(urlString) {
2
- const urlPattern = new RegExp('^(https?:\\/\\/)?' + // validate protocol
3
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
4
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
5
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
6
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
7
- '(\\#[-a-z\\d_]*)?$', 'i');
8
- return !!urlPattern.test(urlString);
9
- }
1
+ export function isValidUrl(urlString) {
2
+ const urlPattern = new RegExp('^(https?:\\/\\/)?' + // validate protocol
3
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // validate domain name
4
+ '((\\d{1,3}\\.){3}\\d{1,3}))' + // validate OR ip (v4) address
5
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // validate port and path
6
+ '(\\?[;&a-z\\d%_.~+=-]*)?' + // validate query string
7
+ '(\\#[-a-z\\d_]*)?$', 'i');
8
+ return !!urlPattern.test(urlString);
9
+ }
10
10
  //# sourceMappingURL=isValidUrl.js.map
@@ -1,2 +1,2 @@
1
- export declare function parseJwt<R>(jwtToken: string): R | undefined;
1
+ export declare function parseJwt<R>(jwtToken: string): R | undefined;
2
2
  //# sourceMappingURL=parseJwt.d.ts.map
@@ -1,8 +1,8 @@
1
- export function parseJwt(jwtToken) {
2
- const base64Url = jwtToken === null || jwtToken === void 0 ? void 0 : jwtToken.split('.')[1];
3
- if (base64Url === undefined) {
4
- return {};
5
- }
6
- return JSON.parse(decodeURIComponent(escape(window.atob(base64Url))));
7
- }
1
+ export function parseJwt(jwtToken) {
2
+ const base64Url = jwtToken === null || jwtToken === void 0 ? void 0 : jwtToken.split('.')[1];
3
+ if (base64Url === undefined) {
4
+ return {};
5
+ }
6
+ return JSON.parse(decodeURIComponent(escape(window.atob(base64Url))));
7
+ }
8
8
  //# sourceMappingURL=parseJwt.js.map
@@ -1,5 +1,5 @@
1
- export declare function userTypingSignal(insertUserLastTyped: () => Promise<unknown>): {
2
- initiateUserTyping: () => void;
3
- setLastTyped: () => void;
4
- };
1
+ export declare function userTypingSignal(insertUserLastTyped: () => Promise<unknown>): {
2
+ initiateUserTyping: () => void;
3
+ setLastTyped: () => void;
4
+ };
5
5
  //# sourceMappingURL=userTypingSignal.d.ts.map
@@ -1,33 +1,33 @@
1
- export function userTypingSignal(insertUserLastTyped) {
2
- let timmer = undefined;
3
- let last_typed = undefined;
4
- function setLastTyped() {
5
- last_typed = Date.now();
6
- }
7
- function initiateUserTyping() {
8
- if (timmer) {
9
- return;
10
- }
11
- if (userIsTyping()) {
12
- timmer = window.setInterval(() => {
13
- if (!userIsTyping()) {
14
- window.clearInterval(timmer);
15
- timmer = undefined;
16
- return;
17
- }
18
- insertUserLastTyped();
19
- }, 1600);
20
- }
21
- }
22
- function userIsTyping() {
23
- if (!last_typed) {
24
- return false;
25
- }
26
- return last_typed > Date.now() - 2 * 1000;
27
- }
28
- return {
29
- initiateUserTyping,
30
- setLastTyped,
31
- };
32
- }
1
+ export function userTypingSignal(insertUserLastTyped) {
2
+ let timmer = undefined;
3
+ let last_typed = undefined;
4
+ function setLastTyped() {
5
+ last_typed = Date.now();
6
+ }
7
+ function initiateUserTyping() {
8
+ if (timmer) {
9
+ return;
10
+ }
11
+ if (userIsTyping()) {
12
+ timmer = window.setInterval(() => {
13
+ if (!userIsTyping()) {
14
+ window.clearInterval(timmer);
15
+ timmer = undefined;
16
+ return;
17
+ }
18
+ insertUserLastTyped();
19
+ }, 1600);
20
+ }
21
+ }
22
+ function userIsTyping() {
23
+ if (!last_typed) {
24
+ return false;
25
+ }
26
+ return last_typed > Date.now() - 2 * 1000;
27
+ }
28
+ return {
29
+ initiateUserTyping,
30
+ setLastTyped,
31
+ };
32
+ }
33
33
  //# sourceMappingURL=userTypingSignal.js.map