@vocollege/app 0.0.56 → 0.0.59

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 (120) hide show
  1. package/dist/{types.d.ts → global.d.ts} +4 -0
  2. package/dist/{types.js → global.js} +0 -0
  3. package/dist/index.d.ts +3 -2
  4. package/dist/index.js +9 -3
  5. package/dist/interceptor.js +41 -12
  6. package/dist/modules/Services/I18n/I18n.js +1 -1
  7. package/dist/modules/Services/I18n/strings.json +716 -21
  8. package/dist/modules/Services/Vapor/Vapor.js +15 -7
  9. package/dist/modules/VoApi/GraphClient.d.ts +3 -2
  10. package/dist/modules/VoApi/GraphClient.js +57 -14
  11. package/dist/modules/VoApi/VoApi.d.ts +4 -1
  12. package/dist/modules/VoApi/VoApi.js +20 -2
  13. package/dist/modules/VoApi/graphql.d.ts +32 -0
  14. package/dist/modules/VoApi/graphql.js +57 -0
  15. package/dist/modules/VoApi/index.d.ts +1 -21
  16. package/dist/modules/VoApi/index.js +7 -31
  17. package/dist/modules/VoApi/mutations/acl.js +5 -5
  18. package/dist/modules/VoApi/mutations/applications.d.ts +3 -0
  19. package/dist/modules/VoApi/mutations/applications.js +12 -0
  20. package/dist/modules/VoApi/mutations/articles.js +3 -3
  21. package/dist/modules/VoApi/mutations/books.d.ts +3 -0
  22. package/dist/modules/VoApi/mutations/books.js +12 -0
  23. package/dist/modules/VoApi/mutations/cards.d.ts +3 -0
  24. package/dist/modules/VoApi/mutations/cards.js +12 -0
  25. package/dist/modules/VoApi/mutations/events.d.ts +3 -0
  26. package/dist/modules/VoApi/mutations/events.js +12 -0
  27. package/dist/modules/VoApi/mutations/navigation.js +3 -3
  28. package/dist/modules/VoApi/mutations/pages.js +3 -3
  29. package/dist/modules/VoApi/mutations/queues.js +3 -3
  30. package/dist/modules/VoApi/mutations/sections.d.ts +3 -0
  31. package/dist/modules/VoApi/mutations/sections.js +12 -0
  32. package/dist/modules/VoApi/mutations/settings.js +1 -1
  33. package/dist/modules/VoApi/mutations/users.js +3 -3
  34. package/dist/modules/VoApi/mutations/vodocs.js +9 -9
  35. package/dist/modules/VoApi/mutations/vogroups.d.ts +1 -0
  36. package/dist/modules/VoApi/mutations/vogroups.js +10 -9
  37. package/dist/modules/VoApi/queries/acl.js +4 -4
  38. package/dist/modules/VoApi/queries/applications.d.ts +2 -0
  39. package/dist/modules/VoApi/queries/applications.js +11 -0
  40. package/dist/modules/VoApi/queries/articles.js +2 -2
  41. package/dist/modules/VoApi/queries/books.d.ts +4 -0
  42. package/dist/modules/VoApi/queries/books.js +13 -0
  43. package/dist/modules/VoApi/queries/cards.d.ts +2 -0
  44. package/dist/modules/VoApi/queries/cards.js +11 -0
  45. package/dist/modules/VoApi/queries/events.d.ts +2 -0
  46. package/dist/modules/VoApi/queries/events.js +11 -0
  47. package/dist/modules/VoApi/queries/help.d.ts +1 -0
  48. package/dist/modules/VoApi/queries/help.js +11 -0
  49. package/dist/modules/VoApi/queries/navigation.js +4 -4
  50. package/dist/modules/VoApi/queries/pages.js +2 -2
  51. package/dist/modules/VoApi/queries/queues.js +2 -2
  52. package/dist/modules/VoApi/queries/search.d.ts +2 -0
  53. package/dist/modules/VoApi/queries/search.js +5 -3
  54. package/dist/modules/VoApi/queries/sections.d.ts +2 -0
  55. package/dist/modules/VoApi/queries/sections.js +11 -0
  56. package/dist/modules/VoApi/queries/settings.js +1 -1
  57. package/dist/modules/VoApi/queries/users.d.ts +1 -0
  58. package/dist/modules/VoApi/queries/users.js +5 -4
  59. package/dist/modules/VoApi/queries/vodocs.js +3 -3
  60. package/dist/modules/VoApi/queries/vogroups.d.ts +1 -0
  61. package/dist/modules/VoApi/queries/vogroups.js +9 -8
  62. package/dist/modules/VoApp.d.ts +1 -0
  63. package/dist/modules/VoApp.js +17 -0
  64. package/dist/modules/VoAuth.d.ts +2 -1
  65. package/dist/modules/VoAuth.js +126 -42
  66. package/dist/modules/VoBase.js +2 -2
  67. package/dist/modules/VoConfig.js +10 -0
  68. package/dist/modules/VoDocs/VoDocs.d.ts +1 -2
  69. package/dist/modules/VoDocs/VoDocs.js +12 -44
  70. package/dist/modules/VoGroups.d.ts +7 -0
  71. package/dist/modules/VoGroups.js +39 -0
  72. package/dist/modules/VoHelpers.d.ts +38 -1
  73. package/dist/modules/VoHelpers.js +348 -51
  74. package/dist/modules/VoRouter.js +10 -2
  75. package/dist/modules/{VoUtils.d.ts → VoUtils_REMOVE.d.ts} +1 -1
  76. package/dist/modules/{VoUtils.js → VoUtils_REMOVE.js} +16 -12
  77. package/package.json +17 -8
  78. package/src/global.ts +44 -0
  79. package/src/index.ts +3 -2
  80. package/src/interceptor.ts +39 -8
  81. package/src/modules/Services/I18n/strings.json +718 -22
  82. package/src/modules/Services/Vapor/Vapor.ts +14 -15
  83. package/src/modules/VoApi/GraphClient.ts +87 -24
  84. package/src/modules/VoApi/VoApi.ts +23 -3
  85. package/src/modules/VoApi/graphql.ts +47 -0
  86. package/src/modules/VoApi/index.ts +1 -37
  87. package/src/modules/VoApi/mutations/applications.ts +27 -0
  88. package/src/modules/VoApi/mutations/books.ts +27 -0
  89. package/src/modules/VoApi/mutations/cards.ts +27 -0
  90. package/src/modules/VoApi/mutations/events.ts +27 -0
  91. package/src/modules/VoApi/mutations/queues.ts +9 -1
  92. package/src/modules/VoApi/mutations/sections.ts +27 -0
  93. package/src/modules/VoApi/mutations/settings.ts +11 -3
  94. package/src/modules/VoApi/mutations/users.ts +19 -9
  95. package/src/modules/VoApi/mutations/vodocs.ts +4 -0
  96. package/src/modules/VoApi/mutations/vogroups.ts +21 -7
  97. package/src/modules/VoApi/queries/applications.ts +71 -0
  98. package/src/modules/VoApi/queries/articles.ts +26 -4
  99. package/src/modules/VoApi/queries/books.ts +101 -0
  100. package/src/modules/VoApi/queries/cards.ts +87 -0
  101. package/src/modules/VoApi/queries/events.ts +80 -0
  102. package/src/modules/VoApi/queries/help.ts +12 -0
  103. package/src/modules/VoApi/queries/navigation.ts +3 -4
  104. package/src/modules/VoApi/queries/pages.ts +29 -4
  105. package/src/modules/VoApi/queries/queues.ts +69 -4
  106. package/src/modules/VoApi/queries/search.ts +105 -4
  107. package/src/modules/VoApi/queries/sections.ts +63 -0
  108. package/src/modules/VoApi/queries/settings.ts +9 -3
  109. package/src/modules/VoApi/queries/users.ts +93 -8
  110. package/src/modules/VoApi/queries/vodocs.ts +8 -4
  111. package/src/modules/VoApi/queries/vogroups.ts +48 -2
  112. package/src/modules/VoApp.ts +25 -8
  113. package/src/modules/VoAuth.ts +136 -37
  114. package/src/modules/VoConfig.ts +13 -0
  115. package/src/modules/VoDocs/VoDocs.ts +31 -58
  116. package/src/modules/VoGroups.ts +33 -0
  117. package/src/modules/VoHelpers.ts +283 -43
  118. package/src/modules/VoRouter.ts +10 -3
  119. package/src/modules/{VoUtils.ts → VoUtils_REMOVE.ts} +17 -13
  120. package/src/types.ts +0 -38
@@ -7,7 +7,9 @@ import VoBase from "./VoBase";
7
7
  import VoApi from "./VoApi";
8
8
  import VoRouter from "./VoRouter";
9
9
  import VoConfig from "./VoConfig";
10
- import { VoTokenType } from "../types";
10
+ import { VoTokenType } from "../global";
11
+ import VoGroups from "./VoGroups";
12
+ import JsCookies from "js-cookie";
11
13
 
12
14
  class VoAuth extends VoBase {
13
15
  state: string;
@@ -15,6 +17,7 @@ class VoAuth extends VoBase {
15
17
  challenge: string;
16
18
  user: any = null;
17
19
  ability: AnyMongoAbility;
20
+ globalAbility: AnyMongoAbility;
18
21
 
19
22
  constructor(key: string) {
20
23
  super(key);
@@ -22,6 +25,7 @@ class VoAuth extends VoBase {
22
25
  this.verifier = "";
23
26
  this.challenge = "";
24
27
  this.ability = new Ability();
28
+ this.globalAbility = new Ability();
25
29
  }
26
30
 
27
31
  get getAppLoginUrl() {
@@ -45,25 +49,39 @@ class VoAuth extends VoBase {
45
49
  const code = urlParams.get("code");
46
50
  const state = urlParams.get("state");
47
51
  const initiatedAuth = this.getInitiatedAuth();
48
- if (code && state && state === initiatedAuth.state) {
49
- let params = {
50
- grant_type: "authorization_code",
51
- client_id: VoConfig.get.AUTH_CLIENT_ID,
52
- redirect_uri: this.getAuthUrl,
53
- code_verifier: initiatedAuth.verifier,
54
- code,
55
- };
56
- const url = this.getUrl + "/token";
57
- const response = await axios.post(url, params);
58
- let state = VoConfig.get.AUTH_STORAGE_STATE || "";
59
- Helpers.localStorage.remove(state);
60
- let verifier = VoConfig.get.AUTH_STORAGE_VERIFIER || "";
61
- Helpers.localStorage.remove(verifier);
62
- this.setSession(response.data);
63
- await this.loadUser(true);
64
- resolve(true);
65
- } else {
66
- reject("Authorization failed");
52
+ try {
53
+ if (code && state && state === initiatedAuth.state) {
54
+ let params = {
55
+ grant_type: "authorization_code",
56
+ client_id: VoConfig.get.AUTH_CLIENT_ID,
57
+ redirect_uri: this.getAuthUrl,
58
+ code_verifier: initiatedAuth.verifier,
59
+ code,
60
+ };
61
+ const url = this.getUrl + "/token";
62
+ const response = await axios.post(url, params);
63
+ let state = VoConfig.get.AUTH_STORAGE_STATE || "";
64
+ // Helpers.localStorage.remove(state);
65
+ JsCookies.remove(state, {
66
+ domain: VoConfig.get.AUTH_DOMAIN,
67
+ sameSite: "Lax",
68
+ });
69
+
70
+ let verifier = VoConfig.get.AUTH_STORAGE_VERIFIER || "";
71
+ // Helpers.localStorage.remove(verifier);
72
+ JsCookies.remove(verifier, {
73
+ domain: VoConfig.get.AUTH_DOMAIN,
74
+ sameSite: "Lax",
75
+ });
76
+
77
+ this.setSession(response.data);
78
+ await this.loadUser(true);
79
+ resolve(true);
80
+ } else {
81
+ reject("Authorization failed");
82
+ }
83
+ } catch (error) {
84
+ reject(error);
67
85
  }
68
86
  });
69
87
  }
@@ -82,26 +100,72 @@ class VoAuth extends VoBase {
82
100
 
83
101
  setSession(token: any) {
84
102
  const { token_type, access_token, refresh_token, expires_in } = token;
103
+
85
104
  let refreshTokenKey = VoConfig.get.AUTH_STORAGE_REFRESH_TOKEN || "";
86
- Helpers.localStorage.set(refreshTokenKey, refresh_token);
105
+ // Helpers.localStorage.set(refreshTokenKey, refresh_token);
106
+ JsCookies.set(refreshTokenKey, refresh_token, {
107
+ expires: 20,
108
+ sameSite: "Lax",
109
+ domain: VoConfig.get.AUTH_DOMAIN,
110
+ });
111
+
87
112
  let accessTokenKey = VoConfig.get.AUTH_STORAGE_ACCESS_TOKEN || "";
88
- Helpers.localStorage.set(accessTokenKey, access_token);
113
+ // Helpers.localStorage.set(accessTokenKey, access_token);
114
+ JsCookies.set(accessTokenKey, access_token, {
115
+ expires: 20,
116
+ sameSite: "Lax",
117
+ domain: VoConfig.get.AUTH_DOMAIN,
118
+ });
119
+
89
120
  let tokenTypeKey = VoConfig.get.AUTH_STORAGE_TOKEN_TYPE || "";
90
- Helpers.localStorage.set(tokenTypeKey, token_type);
121
+ // Helpers.localStorage.set(tokenTypeKey, token_type);
122
+ JsCookies.set(tokenTypeKey, token_type, {
123
+ expires: 20,
124
+ sameSite: "Lax",
125
+ domain: VoConfig.get.AUTH_DOMAIN,
126
+ });
127
+
91
128
  let expiresInKey = VoConfig.get.AUTH_STORAGE_EXPIRES_IN || "";
92
- Helpers.localStorage.set(expiresInKey, expires_in);
129
+ // Helpers.localStorage.set(expiresInKey, expires_in);
130
+ JsCookies.set(expiresInKey, expires_in, {
131
+ expires: 20,
132
+ sameSite: "Lax",
133
+ domain: VoConfig.get.AUTH_DOMAIN,
134
+ });
135
+
93
136
  axios.defaults.headers.common["Authorization"] =
94
137
  token_type + " " + access_token;
138
+ let currentGroup = VoGroups.getCurrent(true);
139
+ axios.defaults.headers.common["VoGroup"] = currentGroup
140
+ ? currentGroup.id
141
+ : "";
95
142
  }
96
143
  resetSession() {
97
144
  let refreshTokenKey = VoConfig.get.AUTH_STORAGE_REFRESH_TOKEN || "";
98
145
  Helpers.localStorage.remove(refreshTokenKey);
146
+ JsCookies.remove(refreshTokenKey, { domain: VoConfig.get.AUTH_DOMAIN });
147
+
99
148
  let accessTokenKey = VoConfig.get.AUTH_STORAGE_ACCESS_TOKEN || "";
100
149
  Helpers.localStorage.remove(accessTokenKey);
150
+ JsCookies.remove(accessTokenKey, {
151
+ domain: VoConfig.get.AUTH_DOMAIN,
152
+ sameSite: "Lax",
153
+ });
154
+
101
155
  let tokenTypeKey = VoConfig.get.AUTH_STORAGE_TOKEN_TYPE || "";
102
156
  Helpers.localStorage.remove(tokenTypeKey);
157
+ JsCookies.remove(tokenTypeKey, {
158
+ domain: VoConfig.get.AUTH_DOMAIN,
159
+ sameSite: "Lax",
160
+ });
161
+
103
162
  let expiresInKey = VoConfig.get.AUTH_STORAGE_EXPIRES_IN || "";
104
163
  Helpers.localStorage.remove(expiresInKey);
164
+ JsCookies.remove(expiresInKey, {
165
+ domain: VoConfig.get.AUTH_DOMAIN,
166
+ sameSite: "Lax",
167
+ });
168
+
105
169
  delete axios.defaults.headers.common["Authorization"];
106
170
  }
107
171
  async refreshToken() {
@@ -121,6 +185,8 @@ class VoAuth extends VoBase {
121
185
  this.setSession(response.data);
122
186
  }
123
187
  return this.getToken();
188
+ } else {
189
+ throw new Error("Refresh token not found");
124
190
  }
125
191
  } catch (error) {
126
192
  this.resetSession();
@@ -134,12 +200,7 @@ class VoAuth extends VoBase {
134
200
  if (token) {
135
201
  try {
136
202
  this.setSession(token);
137
-
138
- // const response = await VoApi.getUser();
139
- // this.user = response.data.data;
140
- // this.ability.update(this.user.permissions);
141
203
  await this.loadUser(forceLoad);
142
-
143
204
  resolve(this.user);
144
205
  } catch (error) {
145
206
  reject(error);
@@ -160,6 +221,9 @@ class VoAuth extends VoBase {
160
221
  const response = await VoApi.getUser();
161
222
  this.user = response.data.data;
162
223
  this.ability.update(this.user.permissions);
224
+ if (VoGroups.getCurrent(true)) {
225
+ this.globalAbility.update(this.user.globalPermissions);
226
+ }
163
227
  }
164
228
  resolve(this.user);
165
229
  } catch (error) {
@@ -174,13 +238,21 @@ class VoAuth extends VoBase {
174
238
  getToken(): VoTokenType | void {
175
239
  try {
176
240
  let refreshTokenKey = VoConfig.get.AUTH_STORAGE_REFRESH_TOKEN || "";
177
- const refreshToken = Helpers.localStorage.get(refreshTokenKey);
241
+ // const refreshToken = Helpers.localStorage.get(refreshTokenKey);
242
+ const refreshToken = JsCookies.get(refreshTokenKey);
243
+
178
244
  let accessTokenKey = VoConfig.get.AUTH_STORAGE_ACCESS_TOKEN || "";
179
- const accessToken = Helpers.localStorage.get(accessTokenKey);
245
+ // const accessToken = Helpers.localStorage.get(accessTokenKey);
246
+ const accessToken = JsCookies.get(accessTokenKey);
247
+
180
248
  let tokenTypeKey = VoConfig.get.AUTH_STORAGE_TOKEN_TYPE || "";
181
- const tokenType = Helpers.localStorage.get(tokenTypeKey);
249
+ // const tokenType = Helpers.localStorage.get(tokenTypeKey);
250
+ const tokenType = JsCookies.get(tokenTypeKey);
251
+
182
252
  let expiresInKey = VoConfig.get.AUTH_STORAGE_EXPIRES_IN || "";
183
- const expiresIn = Helpers.localStorage.get(expiresInKey);
253
+ // const expiresIn = Helpers.localStorage.get(expiresInKey);
254
+ const expiresIn = JsCookies.get(expiresInKey);
255
+
184
256
  if (refreshToken && accessToken && tokenType && expiresIn) {
185
257
  return {
186
258
  refresh_token: refreshToken,
@@ -203,14 +275,37 @@ class VoAuth extends VoBase {
203
275
  let state = Helpers.createRandomString(40);
204
276
  let verifier = Helpers.createRandomString(128);
205
277
  let challenge = Helpers.base64Url(crypto.SHA256(verifier));
278
+
206
279
  let stateKey = VoConfig.get.AUTH_STORAGE_STATE || "";
207
- Helpers.localStorage.set(stateKey, state);
280
+ Helpers.localStorage.remove(stateKey);
281
+ JsCookies.set(stateKey, state, {
282
+ expires: 1,
283
+ sameSite: "Lax",
284
+ domain: VoConfig.get.AUTH_DOMAIN,
285
+ });
286
+
208
287
  let verifierKey = VoConfig.get.AUTH_STORAGE_VERIFIER || "";
209
- Helpers.localStorage.set(verifierKey, verifier);
288
+ Helpers.localStorage.remove(verifierKey);
289
+ JsCookies.set(verifierKey, verifier, {
290
+ expires: 1,
291
+ sameSite: "Lax",
292
+ domain: VoConfig.get.AUTH_DOMAIN,
293
+ });
294
+
210
295
  let accessTokenKey = VoConfig.get.AUTH_STORAGE_ACCESS_TOKEN || "";
211
296
  Helpers.localStorage.remove(accessTokenKey);
297
+ JsCookies.remove(accessTokenKey, {
298
+ domain: VoConfig.get.AUTH_DOMAIN,
299
+ sameSite: "Lax",
300
+ });
301
+
212
302
  let tokenTypeKey = VoConfig.get.AUTH_STORAGE_TOKEN_TYPE || "";
213
303
  Helpers.localStorage.remove(tokenTypeKey);
304
+ JsCookies.remove(tokenTypeKey, {
305
+ domain: VoConfig.get.AUTH_DOMAIN,
306
+ sameSite: "Lax",
307
+ });
308
+
214
309
  return {
215
310
  state,
216
311
  challenge,
@@ -221,9 +316,13 @@ class VoAuth extends VoBase {
221
316
  }
222
317
  getInitiatedAuth(): { state: string; verifier: string } {
223
318
  let stateKey = VoConfig.get.AUTH_STORAGE_STATE || "";
224
- const state = Helpers.localStorage.get(stateKey);
319
+ // const state = Helpers.localStorage.get(stateKey);
320
+ const state = JsCookies.get(stateKey);
321
+
225
322
  let verifierKey = VoConfig.get.AUTH_STORAGE_VERIFIER || "";
226
- const verifier = Helpers.localStorage.get(verifierKey);
323
+ // const verifier = Helpers.localStorage.get(verifierKey);
324
+ const verifier = JsCookies.get(verifierKey);
325
+
227
326
  return {
228
327
  state: state || "",
229
328
  verifier: verifier || "",
@@ -15,17 +15,27 @@ class VoConfig {
15
15
  // }
16
16
 
17
17
  config: VoConfigType = {
18
+ APP_VERSION: "",
19
+
18
20
  API_BASE_URL: "",
19
21
  API_ENDPOINT: "",
20
22
  API_GRAPHQL: "",
23
+ API_SUBSCRIPTIONS_BASE_URL: "",
24
+ API_GRAPHQL_SUBSCRIPTIONS: "",
21
25
 
22
26
  AUTH_CLIENT_ID: "",
23
27
  AUTH_BASE_URL: "",
24
28
  AUTH_ENDPOINT: "",
25
29
 
30
+ ADMIN_BASE_URL: "",
31
+
26
32
  DOCS_BASE_URL: "",
27
33
  DOCS_ENDPOINT: "",
28
34
  DOCS_GRAPHQL: "",
35
+ DOCS_PUBLIC_DISKS: "",
36
+ DOCS_PRIVATE_DISKS: "",
37
+ AWS_BUCKET_VOFRONT_FILES: "",
38
+ AWS_BUCKET_VODOCS_FILES: "",
29
39
 
30
40
  BASE_URL: "",
31
41
  AUTH: "",
@@ -39,6 +49,9 @@ class VoConfig {
39
49
  AUTH_STORAGE_ACCESS_TOKEN: "voapp_accesstoken",
40
50
  AUTH_STORAGE_TOKEN_TYPE: "voapp_tokentype",
41
51
  AUTH_STORAGE_EXPIRES_IN: "voapp_expiresin",
52
+ AUTH_DOMAIN: ".vo-college.se",
53
+
54
+ CURRENT_GROUP: "vo_group",
42
55
  };
43
56
 
44
57
  setConfig(config: VoConfigType) {
@@ -1,66 +1,39 @@
1
1
  // Vendors.
2
- import axios from 'axios';
2
+ import axios from "axios";
3
3
 
4
4
  // Custom.
5
- import GraphClient from '../VoApi/GraphClient';
6
- import VoBase from '../VoBase';
7
- import VoAuth from '../VoAuth';
8
- import VoConfig from '../VoConfig';
5
+ import GraphClient from "../VoApi/GraphClient";
6
+ import VoBase from "../VoBase";
7
+ // import VoAuth from '../VoAuth';
8
+ import VoConfig from "../VoConfig";
9
+ import VoGroups from "../VoGroups";
9
10
 
10
11
  class VoDocs extends VoBase {
11
-
12
- graphqlClient: any
13
-
14
- init() {
15
- this.graphqlClient = GraphClient.createGraphClient(this.getGraphqlUrl, true);
16
- }
17
-
18
- get getGraphqlUrl() {
19
- return VoConfig.get.DOCS_BASE_URL + '' + VoConfig.get.DOCS_GRAPHQL;
20
- }
21
-
22
- async getTemporaryFileUrl(id: string) {
23
- try {
24
- const url = `${this.getUrl}/docs/download/${id}`;
25
- return axios.get(url);
26
- } catch(error) {
27
- throw error;
28
- }
12
+ graphqlClient: any;
13
+
14
+ init() {
15
+ this.graphqlClient = GraphClient.createGraphClient(
16
+ this.getGraphqlUrl,
17
+ true
18
+ );
19
+ }
20
+
21
+ get getGraphqlUrl() {
22
+ return VoConfig.get.DOCS_BASE_URL + "" + VoConfig.get.DOCS_GRAPHQL;
23
+ }
24
+
25
+ async getTemporaryFileUrl(id: string) {
26
+ try {
27
+ let currentGroup = VoGroups.getCurrent(true);
28
+ axios.defaults.headers.common["VoGroup"] = currentGroup
29
+ ? currentGroup.id
30
+ : "";
31
+ const url = `${this.getUrl}/docs/download/${id}`;
32
+ return axios.get(url);
33
+ } catch (error) {
34
+ throw error;
29
35
  }
30
-
31
- async downloadFile(id: string) {
32
- try {
33
-
34
- let elId = `file-${id}`;
35
-
36
- // Ensure that an old element is not left in the DOM.
37
- let el = document.getElementById(elId);
38
- if (el !== null && el.parentNode) {
39
- el.parentNode.removeChild(el);
40
- }
41
-
42
- // Retrieve the temporary download URL.
43
- let fileUrl = await this.getTemporaryFileUrl(id);
44
- if (fileUrl.data) {
45
- let anchor = document.createElement('a');
46
- anchor.id = elId;
47
- anchor.href = fileUrl.data;
48
- anchor.download = fileUrl.data;
49
- document.body.appendChild(anchor);
50
- anchor.click();
51
- setTimeout(() => {
52
- if (anchor.parentNode) {
53
- anchor.parentNode.removeChild(anchor);
54
- }
55
- }, 500);
56
- } else {
57
- throw "No file was found";
58
- }
59
- } catch (error) {
60
- throw error;
61
- }
62
- }
63
-
36
+ }
64
37
  }
65
38
 
66
- export default new VoDocs('docs');
39
+ export default new VoDocs("docs");
@@ -0,0 +1,33 @@
1
+ import { localStorage } from "./VoHelpers";
2
+ import VoConfig from "./VoConfig";
3
+ import { GeneralObject } from "../global";
4
+
5
+ class VoGroups {
6
+ getCurrent(getFromDomain = false): null | GeneralObject {
7
+ const group: any = localStorage.get(VoConfig.get.CURRENT_GROUP);
8
+ if (group) {
9
+ return JSON.parse(group);
10
+ }
11
+ if (getFromDomain) {
12
+ let groupName = this.getGroupNameFromDomain(window.location.host);
13
+ if (groupName && groupName !== "") {
14
+ return { id: groupName };
15
+ }
16
+ }
17
+ return null;
18
+ }
19
+ getGroupNameFromDomain(host: string) {
20
+ let subdomain = host?.split(".")[0];
21
+ let localIndex = subdomain?.indexOf("local");
22
+ if (localIndex !== undefined && localIndex > -1) {
23
+ let hyphenIndex = subdomain?.indexOf("-") || 0;
24
+ subdomain = subdomain?.substring(hyphenIndex + 1);
25
+ }
26
+ if (subdomain === "admin") {
27
+ return null;
28
+ }
29
+ return subdomain;
30
+ }
31
+ }
32
+
33
+ export default new VoGroups();