@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.
- package/dist/{types.d.ts → global.d.ts} +4 -0
- package/dist/{types.js → global.js} +0 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +9 -3
- package/dist/interceptor.js +41 -12
- package/dist/modules/Services/I18n/I18n.js +1 -1
- package/dist/modules/Services/I18n/strings.json +716 -21
- package/dist/modules/Services/Vapor/Vapor.js +15 -7
- package/dist/modules/VoApi/GraphClient.d.ts +3 -2
- package/dist/modules/VoApi/GraphClient.js +57 -14
- package/dist/modules/VoApi/VoApi.d.ts +4 -1
- package/dist/modules/VoApi/VoApi.js +20 -2
- package/dist/modules/VoApi/graphql.d.ts +32 -0
- package/dist/modules/VoApi/graphql.js +57 -0
- package/dist/modules/VoApi/index.d.ts +1 -21
- package/dist/modules/VoApi/index.js +7 -31
- package/dist/modules/VoApi/mutations/acl.js +5 -5
- package/dist/modules/VoApi/mutations/applications.d.ts +3 -0
- package/dist/modules/VoApi/mutations/applications.js +12 -0
- package/dist/modules/VoApi/mutations/articles.js +3 -3
- package/dist/modules/VoApi/mutations/books.d.ts +3 -0
- package/dist/modules/VoApi/mutations/books.js +12 -0
- package/dist/modules/VoApi/mutations/cards.d.ts +3 -0
- package/dist/modules/VoApi/mutations/cards.js +12 -0
- package/dist/modules/VoApi/mutations/events.d.ts +3 -0
- package/dist/modules/VoApi/mutations/events.js +12 -0
- package/dist/modules/VoApi/mutations/navigation.js +3 -3
- package/dist/modules/VoApi/mutations/pages.js +3 -3
- package/dist/modules/VoApi/mutations/queues.js +3 -3
- package/dist/modules/VoApi/mutations/sections.d.ts +3 -0
- package/dist/modules/VoApi/mutations/sections.js +12 -0
- package/dist/modules/VoApi/mutations/settings.js +1 -1
- package/dist/modules/VoApi/mutations/users.js +3 -3
- package/dist/modules/VoApi/mutations/vodocs.js +9 -9
- package/dist/modules/VoApi/mutations/vogroups.d.ts +1 -0
- package/dist/modules/VoApi/mutations/vogroups.js +10 -9
- package/dist/modules/VoApi/queries/acl.js +4 -4
- package/dist/modules/VoApi/queries/applications.d.ts +2 -0
- package/dist/modules/VoApi/queries/applications.js +11 -0
- package/dist/modules/VoApi/queries/articles.js +2 -2
- package/dist/modules/VoApi/queries/books.d.ts +4 -0
- package/dist/modules/VoApi/queries/books.js +13 -0
- package/dist/modules/VoApi/queries/cards.d.ts +2 -0
- package/dist/modules/VoApi/queries/cards.js +11 -0
- package/dist/modules/VoApi/queries/events.d.ts +2 -0
- package/dist/modules/VoApi/queries/events.js +11 -0
- package/dist/modules/VoApi/queries/help.d.ts +1 -0
- package/dist/modules/VoApi/queries/help.js +11 -0
- package/dist/modules/VoApi/queries/navigation.js +4 -4
- package/dist/modules/VoApi/queries/pages.js +2 -2
- package/dist/modules/VoApi/queries/queues.js +2 -2
- package/dist/modules/VoApi/queries/search.d.ts +2 -0
- package/dist/modules/VoApi/queries/search.js +5 -3
- package/dist/modules/VoApi/queries/sections.d.ts +2 -0
- package/dist/modules/VoApi/queries/sections.js +11 -0
- package/dist/modules/VoApi/queries/settings.js +1 -1
- package/dist/modules/VoApi/queries/users.d.ts +1 -0
- package/dist/modules/VoApi/queries/users.js +5 -4
- package/dist/modules/VoApi/queries/vodocs.js +3 -3
- package/dist/modules/VoApi/queries/vogroups.d.ts +1 -0
- package/dist/modules/VoApi/queries/vogroups.js +9 -8
- package/dist/modules/VoApp.d.ts +1 -0
- package/dist/modules/VoApp.js +17 -0
- package/dist/modules/VoAuth.d.ts +2 -1
- package/dist/modules/VoAuth.js +126 -42
- package/dist/modules/VoBase.js +2 -2
- package/dist/modules/VoConfig.js +10 -0
- package/dist/modules/VoDocs/VoDocs.d.ts +1 -2
- package/dist/modules/VoDocs/VoDocs.js +12 -44
- package/dist/modules/VoGroups.d.ts +7 -0
- package/dist/modules/VoGroups.js +39 -0
- package/dist/modules/VoHelpers.d.ts +38 -1
- package/dist/modules/VoHelpers.js +348 -51
- package/dist/modules/VoRouter.js +10 -2
- package/dist/modules/{VoUtils.d.ts → VoUtils_REMOVE.d.ts} +1 -1
- package/dist/modules/{VoUtils.js → VoUtils_REMOVE.js} +16 -12
- package/package.json +17 -8
- package/src/global.ts +44 -0
- package/src/index.ts +3 -2
- package/src/interceptor.ts +39 -8
- package/src/modules/Services/I18n/strings.json +718 -22
- package/src/modules/Services/Vapor/Vapor.ts +14 -15
- package/src/modules/VoApi/GraphClient.ts +87 -24
- package/src/modules/VoApi/VoApi.ts +23 -3
- package/src/modules/VoApi/graphql.ts +47 -0
- package/src/modules/VoApi/index.ts +1 -37
- package/src/modules/VoApi/mutations/applications.ts +27 -0
- package/src/modules/VoApi/mutations/books.ts +27 -0
- package/src/modules/VoApi/mutations/cards.ts +27 -0
- package/src/modules/VoApi/mutations/events.ts +27 -0
- package/src/modules/VoApi/mutations/queues.ts +9 -1
- package/src/modules/VoApi/mutations/sections.ts +27 -0
- package/src/modules/VoApi/mutations/settings.ts +11 -3
- package/src/modules/VoApi/mutations/users.ts +19 -9
- package/src/modules/VoApi/mutations/vodocs.ts +4 -0
- package/src/modules/VoApi/mutations/vogroups.ts +21 -7
- package/src/modules/VoApi/queries/applications.ts +71 -0
- package/src/modules/VoApi/queries/articles.ts +26 -4
- package/src/modules/VoApi/queries/books.ts +101 -0
- package/src/modules/VoApi/queries/cards.ts +87 -0
- package/src/modules/VoApi/queries/events.ts +80 -0
- package/src/modules/VoApi/queries/help.ts +12 -0
- package/src/modules/VoApi/queries/navigation.ts +3 -4
- package/src/modules/VoApi/queries/pages.ts +29 -4
- package/src/modules/VoApi/queries/queues.ts +69 -4
- package/src/modules/VoApi/queries/search.ts +105 -4
- package/src/modules/VoApi/queries/sections.ts +63 -0
- package/src/modules/VoApi/queries/settings.ts +9 -3
- package/src/modules/VoApi/queries/users.ts +93 -8
- package/src/modules/VoApi/queries/vodocs.ts +8 -4
- package/src/modules/VoApi/queries/vogroups.ts +48 -2
- package/src/modules/VoApp.ts +25 -8
- package/src/modules/VoAuth.ts +136 -37
- package/src/modules/VoConfig.ts +13 -0
- package/src/modules/VoDocs/VoDocs.ts +31 -58
- package/src/modules/VoGroups.ts +33 -0
- package/src/modules/VoHelpers.ts +283 -43
- package/src/modules/VoRouter.ts +10 -3
- package/src/modules/{VoUtils.ts → VoUtils_REMOVE.ts} +17 -13
- package/src/types.ts +0 -38
package/src/modules/VoAuth.ts
CHANGED
|
@@ -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 "../
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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.
|
|
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.
|
|
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 || "",
|
package/src/modules/VoConfig.ts
CHANGED
|
@@ -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
|
|
2
|
+
import axios from "axios";
|
|
3
3
|
|
|
4
4
|
// Custom.
|
|
5
|
-
import GraphClient from
|
|
6
|
-
import VoBase from
|
|
7
|
-
import VoAuth from '../VoAuth';
|
|
8
|
-
import VoConfig from
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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(
|
|
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();
|