@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/VoHelpers.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import crypto from "crypto-js";
|
|
2
|
+
import he from "he";
|
|
3
|
+
|
|
4
|
+
// Custom.
|
|
5
|
+
import { GeneralObject } from "../global";
|
|
2
6
|
|
|
3
7
|
export const base64Url = (string: crypto.lib.WordArray | String) => {
|
|
4
8
|
return string
|
|
@@ -14,6 +18,7 @@ export const createRandomString = (num: number) => {
|
|
|
14
18
|
|
|
15
19
|
export const localStorage = {
|
|
16
20
|
set: (key: string, value: string) => {
|
|
21
|
+
if (typeof window === "undefined") return false;
|
|
17
22
|
try {
|
|
18
23
|
window.localStorage.setItem(key, value);
|
|
19
24
|
return true;
|
|
@@ -23,6 +28,7 @@ export const localStorage = {
|
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
get: (key: string) => {
|
|
31
|
+
if (typeof window === "undefined") return false;
|
|
26
32
|
try {
|
|
27
33
|
const item = window.localStorage.getItem(key);
|
|
28
34
|
return item;
|
|
@@ -53,17 +59,20 @@ export const encodeQueryData = (data: encodeQueryDataType) => {
|
|
|
53
59
|
};
|
|
54
60
|
|
|
55
61
|
export const regexPatterns = {
|
|
56
|
-
username: /(^[a-z]{3,})([0-9]?)+$/,
|
|
62
|
+
// username: /(^[a-z]{3,})([0-9]?)+$/,
|
|
63
|
+
username: /(^[a-z]{3,})([\.]|[\_]|[a-z]|[0-9]?)+$/,
|
|
57
64
|
email: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
|
58
65
|
stringNonDigit: /^[^0-9]+$/,
|
|
59
66
|
password: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/, // At least 8 characters, 1 uppercase, 1 lowercase and 1 digit.
|
|
60
|
-
cleanName: /(^[A-Za-z]{1,})(\w
|
|
67
|
+
cleanName: /(^[A-Za-z]{1,})(\w|-?)+$/,
|
|
68
|
+
personalNumber: /^(\d{8})[-]\d{4}$/,
|
|
69
|
+
orgnr: /^(\d{6})[-]\d{4}$/,
|
|
61
70
|
};
|
|
62
71
|
|
|
63
72
|
type errorObjectType = {
|
|
64
73
|
message: string;
|
|
65
74
|
fields?: {
|
|
66
|
-
[key: string]:
|
|
75
|
+
[key: string]: any;
|
|
67
76
|
};
|
|
68
77
|
};
|
|
69
78
|
|
|
@@ -149,46 +158,277 @@ export const wrapPromise = (promise: any) => {
|
|
|
149
158
|
return { read };
|
|
150
159
|
};
|
|
151
160
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
161
|
+
export const downloadFile = (url: string) => {
|
|
162
|
+
try {
|
|
163
|
+
let elId = `file-${url}`;
|
|
164
|
+
|
|
165
|
+
// Ensure that an old element is not left in the DOM.
|
|
166
|
+
let el = document.getElementById(elId);
|
|
167
|
+
if (el !== null && el.parentNode) {
|
|
168
|
+
el.parentNode.removeChild(el);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let anchor = document.createElement("a");
|
|
172
|
+
anchor.id = elId;
|
|
173
|
+
anchor.href = url;
|
|
174
|
+
anchor.download = url;
|
|
175
|
+
document.body.appendChild(anchor);
|
|
176
|
+
anchor.click();
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
if (anchor.parentNode) {
|
|
179
|
+
anchor.parentNode.removeChild(anchor);
|
|
180
|
+
}
|
|
181
|
+
}, 500);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export const orderByPosition = (a: any, b: any) => {
|
|
188
|
+
if (a.position < b.position) {
|
|
189
|
+
return -1;
|
|
190
|
+
}
|
|
191
|
+
if (a.position > b.position) {
|
|
192
|
+
return 1;
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const orderByField = (a: any, b: any, field: string) => {
|
|
198
|
+
if (a[field] < b[field]) {
|
|
199
|
+
return -1;
|
|
200
|
+
}
|
|
201
|
+
if (a[field] > b[field]) {
|
|
202
|
+
return 1;
|
|
203
|
+
}
|
|
204
|
+
return 0;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export const shortenText = (
|
|
208
|
+
str: string,
|
|
209
|
+
limit = 30,
|
|
210
|
+
stripHtml = true,
|
|
211
|
+
addEllipsis = false
|
|
212
|
+
) => {
|
|
213
|
+
let output = "";
|
|
214
|
+
if (stripHtml) {
|
|
215
|
+
output = str.replace(/(<([^>]+)>)/gi, "");
|
|
216
|
+
output = he.decode(output);
|
|
217
|
+
}
|
|
218
|
+
if (addEllipsis) {
|
|
219
|
+
output += "...";
|
|
220
|
+
}
|
|
221
|
+
return output.substring(0, limit).trim();
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export const getImageContact = (item: any, width = 400, height = 400) => {
|
|
225
|
+
let entity = item.entity || item;
|
|
226
|
+
return entity.images && entity.images[0] && entity.images[0]?.url
|
|
227
|
+
? `${entity.images[0]?.url}?d=${width}x${height}`
|
|
228
|
+
: "/images/avatar-user.png";
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export const getImage = (
|
|
232
|
+
item: any,
|
|
233
|
+
width: number,
|
|
234
|
+
height: number,
|
|
235
|
+
field = "images"
|
|
236
|
+
) => {
|
|
237
|
+
let entity =
|
|
238
|
+
(item.images && item.images.length > 0) || !item.entity
|
|
239
|
+
? item
|
|
240
|
+
: item.entity;
|
|
241
|
+
return entity[field] && entity[field][0]
|
|
242
|
+
? `${entity[field][0]?.url}?d=${width}x${height}`
|
|
243
|
+
: "/images/avatar-content.png";
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export const getImageDescription = (item: any, field = "images") => {
|
|
247
|
+
let entity =
|
|
248
|
+
(item.images && item.images.length > 0) || !item.entity
|
|
249
|
+
? item
|
|
250
|
+
: item.entity;
|
|
251
|
+
return entity[field] && entity[field][0]?.description;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const getContactName = (item?: GeneralObject) => {
|
|
255
|
+
if (!item) {
|
|
256
|
+
return "";
|
|
257
|
+
}
|
|
258
|
+
let name = [];
|
|
259
|
+
if (item.firstname) {
|
|
260
|
+
name.push(item.firstname);
|
|
261
|
+
}
|
|
262
|
+
if (item.lastname) {
|
|
263
|
+
name.push(item.lastname);
|
|
264
|
+
}
|
|
265
|
+
if (name.length === 0) {
|
|
266
|
+
name.push(item.name);
|
|
267
|
+
}
|
|
268
|
+
return name.join(" ");
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export const getUserString = (item?: GeneralObject) => {
|
|
272
|
+
if (!item) {
|
|
273
|
+
return "";
|
|
274
|
+
}
|
|
275
|
+
return `${getContactName(item)} | ${item.email}`;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export const parseState = (state: any, initialState: any) => {
|
|
279
|
+
let newState: GeneralObject = {};
|
|
280
|
+
for (const field in initialState) {
|
|
281
|
+
newState[field] = state[field];
|
|
282
|
+
}
|
|
283
|
+
return newState;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// This method is copied from
|
|
287
|
+
// https://stackoverflow.com/questions/6393943/convert-javascript-string-in-dot-notation-into-an-object-reference
|
|
288
|
+
//
|
|
289
|
+
// @TODO Maybe this entire logic can be replaced by Array.reduce(),
|
|
290
|
+
// something like this:
|
|
291
|
+
// let data = is.split(".").reduce((o: any, i) => o && o[i], pbj);
|
|
292
|
+
// data = value;
|
|
293
|
+
//
|
|
294
|
+
export const changeObj = (obj: any, is: any, value: any): {} => {
|
|
295
|
+
if (typeof is == "string") return changeObj(obj, is.split("."), value);
|
|
296
|
+
else if (is.length == 1 && value !== undefined) return (obj[is[0]] = value);
|
|
297
|
+
else if (is.length == 0) return obj;
|
|
298
|
+
else return changeObj(obj[is[0]], is.slice(1), value);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export const reducer = (state: any, action: any) => {
|
|
302
|
+
const { key, values } = action;
|
|
303
|
+
if (!key) {
|
|
304
|
+
return { ...state, ...values };
|
|
305
|
+
}
|
|
306
|
+
if (key === "loading") {
|
|
307
|
+
let i = state.loading.indexOf(values);
|
|
308
|
+
let newValues = [...state.loading];
|
|
309
|
+
if (i > -1) {
|
|
310
|
+
newValues.splice(i, 1);
|
|
311
|
+
} else {
|
|
312
|
+
newValues.push(values);
|
|
313
|
+
}
|
|
314
|
+
return { ...state, loading: newValues };
|
|
315
|
+
}
|
|
316
|
+
if (key.indexOf(".") > -1) {
|
|
317
|
+
changeObj(state, key, values);
|
|
318
|
+
return { ...state };
|
|
319
|
+
}
|
|
320
|
+
return { ...state, [key]: values };
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export const getGroupLogotype = (
|
|
324
|
+
group: GeneralObject,
|
|
325
|
+
logo = "logo2",
|
|
326
|
+
output: GeneralObject[] = []
|
|
327
|
+
) => {
|
|
328
|
+
if (group && Array.isArray(group[logo]) && group[logo].length > 0) {
|
|
329
|
+
output.push.apply(output, group[logo]);
|
|
330
|
+
} else if (group && group.parentGroups) {
|
|
331
|
+
return group.parentGroups.forEach((v: any) => {
|
|
332
|
+
return getGroupLogotype(v, logo, output);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return null;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// export const makeId = (length = 10) => {
|
|
339
|
+
// let result = "";
|
|
340
|
+
// let characters =
|
|
341
|
+
// "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
342
|
+
// let charactersLength = characters.length;
|
|
343
|
+
// for (var i = 0; i < length; i++) {
|
|
344
|
+
// result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
177
345
|
// }
|
|
178
|
-
// return
|
|
179
|
-
// <ul>
|
|
180
|
-
// {error.map((v) => (
|
|
181
|
-
// <li>{typeof error[0] === "object" ? error[0].message : error[0]}</li>
|
|
182
|
-
// ))}
|
|
183
|
-
// </ul>
|
|
184
|
-
// );
|
|
346
|
+
// return result;
|
|
185
347
|
// };
|
|
186
348
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
349
|
+
export const getObjValue = (obj: any, ...props: string[]): any => {
|
|
350
|
+
return (
|
|
351
|
+
obj &&
|
|
352
|
+
props.reduce(
|
|
353
|
+
(result, prop) => (result == null ? undefined : result[prop]),
|
|
354
|
+
obj
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Convert an SVG into an image.
|
|
361
|
+
* @param url
|
|
362
|
+
* @param width
|
|
363
|
+
* @param height
|
|
364
|
+
* @param format
|
|
365
|
+
* @param quality
|
|
366
|
+
* @returns Promise
|
|
367
|
+
*
|
|
368
|
+
* @note Convert logic inpired by
|
|
369
|
+
* https://levelup.gitconnected.com/draw-an-svg-to-canvas-and-download-it-as-image-in-javascript-f7f7713cf81f
|
|
370
|
+
* https://medium.com/@benjamin.black/using-blob-from-svg-text-as-image-source-2a8947af7a8e
|
|
371
|
+
*
|
|
372
|
+
* In this method we could actually assign "url" directly to "image.src" and then
|
|
373
|
+
* extract an image with canvas, but Firefox doesn't support drawing an SVG into
|
|
374
|
+
* canvas if it misses width/height attributes. Read more here:
|
|
375
|
+
* https://stackoverflow.com/questions/28690643/firefox-error-rendering-an-svg-image-to-html5-canvas-with-drawimage
|
|
376
|
+
* https://bugzilla.mozilla.org/show_bug.cgi?id=700533
|
|
377
|
+
*/
|
|
378
|
+
export const convertSvgToImage = (
|
|
379
|
+
url: string,
|
|
380
|
+
width: null | number = null,
|
|
381
|
+
height: null | number = null,
|
|
382
|
+
format = "image/png",
|
|
383
|
+
quality = 0.92
|
|
384
|
+
) => {
|
|
385
|
+
return new Promise(async (resolve, reject) => {
|
|
386
|
+
try {
|
|
387
|
+
let response = await fetch(url);
|
|
388
|
+
let svg = await response.text();
|
|
389
|
+
|
|
390
|
+
let parser = new DOMParser();
|
|
391
|
+
let doc = parser.parseFromString(svg, "image/svg+xml");
|
|
392
|
+
|
|
393
|
+
let viewBox = doc.documentElement.getAttribute("viewBox")?.split(" ");
|
|
394
|
+
|
|
395
|
+
let canvas = document.createElement("canvas");
|
|
396
|
+
if (!width) {
|
|
397
|
+
canvas.width = viewBox && viewBox[2] ? parseInt(viewBox[2]) : 100;
|
|
398
|
+
} else {
|
|
399
|
+
canvas.width = width;
|
|
400
|
+
}
|
|
401
|
+
if (!height && !width) {
|
|
402
|
+
canvas.height = viewBox && viewBox[3] ? parseInt(viewBox[3]) : 100;
|
|
403
|
+
} else if (!height) {
|
|
404
|
+
canvas.height =
|
|
405
|
+
viewBox && viewBox[3]
|
|
406
|
+
? (parseInt(viewBox[3]) / parseInt(viewBox[2])) * canvas.width
|
|
407
|
+
: 100;
|
|
408
|
+
} else {
|
|
409
|
+
canvas.height = height;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// These steps, to ensure that the SVG has width/height attributes
|
|
413
|
+
// are only required because of Firefox.
|
|
414
|
+
// Otherwise we could assign "url" directly to "image.src".
|
|
415
|
+
let inlineSVG = doc.getElementsByTagName("svg")[0];
|
|
416
|
+
inlineSVG.setAttribute("width", `${canvas.width}px`);
|
|
417
|
+
inlineSVG.setAttribute("height", `${canvas.height}px`);
|
|
418
|
+
let svg64 = btoa(new XMLSerializer().serializeToString(inlineSVG));
|
|
419
|
+
let image64 = "data:image/svg+xml;base64," + svg64;
|
|
420
|
+
|
|
421
|
+
let context = canvas.getContext("2d");
|
|
422
|
+
let image = new Image();
|
|
423
|
+
|
|
424
|
+
image.onload = () => {
|
|
425
|
+
context?.drawImage(image, 0, 0);
|
|
426
|
+
let result = canvas.toDataURL(format, quality);
|
|
427
|
+
resolve(result);
|
|
428
|
+
};
|
|
429
|
+
image.src = image64;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
reject(error);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
};
|
package/src/modules/VoRouter.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import Cookies from "js-cookie";
|
|
2
|
+
|
|
3
|
+
// Custom.
|
|
1
4
|
import VoConfig from "./VoConfig";
|
|
2
|
-
import VoAuth from "./VoAuth";
|
|
3
5
|
|
|
4
6
|
type RoutesType = {
|
|
5
7
|
[key: string]: any;
|
|
@@ -24,6 +26,7 @@ class VoRouter {
|
|
|
24
26
|
return params[arg];
|
|
25
27
|
}
|
|
26
28
|
isCurrentRouterProtected() {
|
|
29
|
+
if (typeof window === "undefined") return false;
|
|
27
30
|
const currentPath = this.getPath(window.location.pathname, 0);
|
|
28
31
|
// const routes = VoConfig.getConfigByKey('routes');
|
|
29
32
|
const routes = this.getRoutes();
|
|
@@ -47,9 +50,13 @@ class VoRouter {
|
|
|
47
50
|
const webUrl = [];
|
|
48
51
|
if (VoConfig.get.AUTH_BASE_URL) {
|
|
49
52
|
webUrl.push(VoConfig.get.AUTH_BASE_URL + "/logout");
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
let redirectTo = Cookies.get("voapp_redirectTo") || VoConfig.get.BASE_URL;
|
|
54
|
+
if (redirectTo) {
|
|
55
|
+
webUrl.push(`?redirect=${redirectTo}`);
|
|
52
56
|
}
|
|
57
|
+
// if (VoConfig.get.BASE_URL) {
|
|
58
|
+
// webUrl.push(`?redirect=${VoConfig.get.BASE_URL}`);
|
|
59
|
+
// }
|
|
53
60
|
}
|
|
54
61
|
if (webUrl.length > 0) {
|
|
55
62
|
window.location.href = webUrl.join("");
|
|
@@ -58,20 +58,20 @@ const regexPatterns = {
|
|
|
58
58
|
username: /(^[a-z]{3,})([0-9]?)+$/,
|
|
59
59
|
email: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
|
60
60
|
stringNonDigit: /^[^0-9]+$/,
|
|
61
|
-
password: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}
|
|
62
|
-
}
|
|
61
|
+
password: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/, // At least 8 characters, 1 uppercase, 1 lowercase and 1 digit.
|
|
62
|
+
};
|
|
63
63
|
|
|
64
64
|
type errorObjectType = {
|
|
65
65
|
message: string;
|
|
66
66
|
fields?: {
|
|
67
|
-
[key: string]: string
|
|
68
|
-
}
|
|
69
|
-
}
|
|
67
|
+
[key: string]: string;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
70
|
|
|
71
71
|
const getError = (error: any): errorObjectType => {
|
|
72
|
-
let message =
|
|
73
|
-
let fields: {[key: string]: string} = {};
|
|
74
|
-
if (typeof error ===
|
|
72
|
+
let message = "";
|
|
73
|
+
let fields: { [key: string]: string } = {};
|
|
74
|
+
if (typeof error === "string") {
|
|
75
75
|
message = error;
|
|
76
76
|
}
|
|
77
77
|
if (error.message) {
|
|
@@ -79,17 +79,21 @@ const getError = (error: any): errorObjectType => {
|
|
|
79
79
|
} else if (error.debugMessage) {
|
|
80
80
|
message = error.debugMessage;
|
|
81
81
|
}
|
|
82
|
-
if (
|
|
82
|
+
if (
|
|
83
|
+
error.graphQLErrors &&
|
|
84
|
+
error.graphQLErrors[0].extensions.category &&
|
|
85
|
+
error.graphQLErrors[0].extensions.category === "validation"
|
|
86
|
+
) {
|
|
83
87
|
fields = Object.assign({}, error.graphQLErrors[0].extensions.validation);
|
|
84
88
|
}
|
|
85
89
|
const result: errorObjectType = {
|
|
86
|
-
message
|
|
87
|
-
}
|
|
90
|
+
message,
|
|
91
|
+
};
|
|
88
92
|
if (Object.keys(fields).length > 0) {
|
|
89
93
|
result.fields = fields;
|
|
90
94
|
}
|
|
91
95
|
return result;
|
|
92
|
-
}
|
|
96
|
+
};
|
|
93
97
|
|
|
94
98
|
// const formatError = (error: string | [any]) => {
|
|
95
99
|
// if (typeof error === "string") {
|
|
@@ -113,5 +117,5 @@ export {
|
|
|
113
117
|
localStorage,
|
|
114
118
|
encodeQueryData,
|
|
115
119
|
regexPatterns,
|
|
116
|
-
getError
|
|
120
|
+
getError,
|
|
117
121
|
};
|
package/src/types.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type AuthStorageConfigType = {
|
|
2
|
-
STATE: string,
|
|
3
|
-
VERIFIER: string,
|
|
4
|
-
REFRESH_TOKEN: string,
|
|
5
|
-
ACCESS_TOKEN: string,
|
|
6
|
-
TOKEN_TYPE: string
|
|
7
|
-
EXPIRES_IN: string
|
|
8
|
-
}
|
|
9
|
-
export type AuthConfigType = {
|
|
10
|
-
BASE_URL: string,
|
|
11
|
-
CLIENT_ID?: string,
|
|
12
|
-
LOGIN?: string,
|
|
13
|
-
ENDPOINT?: string,
|
|
14
|
-
STORAGE?: AuthStorageConfigType
|
|
15
|
-
}
|
|
16
|
-
export type ApiConfigType = {
|
|
17
|
-
BASE_URL: string,
|
|
18
|
-
ENDPOINT?: string,
|
|
19
|
-
GRAPHQL?: string
|
|
20
|
-
}
|
|
21
|
-
export type AppConfigType = {
|
|
22
|
-
BASE_URL: string,
|
|
23
|
-
AUTH?: string,
|
|
24
|
-
HOME?: string,
|
|
25
|
-
LOGIN?: string
|
|
26
|
-
}
|
|
27
|
-
export type VoAppType = {
|
|
28
|
-
configure: Function,
|
|
29
|
-
config?: Function,
|
|
30
|
-
auth: any,
|
|
31
|
-
api: any
|
|
32
|
-
}
|
|
33
|
-
export type VoTokenType = {
|
|
34
|
-
token_type: string,
|
|
35
|
-
access_token: string,
|
|
36
|
-
refresh_token: string,
|
|
37
|
-
expires_in: string
|
|
38
|
-
}
|