jd_platform_sdk 0.0.3 → 0.0.6
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/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/sdk/configs/jdConfig.d.ts.map +1 -1
- package/dist/sdk/configs/jdConfig.js +0 -2
- package/dist/sdk/jdConnector.d.ts +2 -2
- package/dist/sdk/jdConnector.d.ts.map +1 -1
- package/dist/sdk/jdConnector.js +1 -1
- package/dist/sdk/models/jdApplication.d.ts +6 -6
- package/dist/sdk/models/jdApplication.d.ts.map +1 -1
- package/dist/sdk/models/jdApplication.js +9 -11
- package/dist/sdk/models/jdResource.d.ts +17 -10
- package/dist/sdk/models/jdResource.d.ts.map +1 -1
- package/dist/sdk/models/jdResource.js +50 -20
- package/dist/sdk/models/modules/geolocation/jdCity.d.ts +15 -0
- package/dist/sdk/models/modules/geolocation/jdCity.d.ts.map +1 -0
- package/dist/sdk/models/modules/geolocation/jdCity.js +50 -0
- package/dist/sdk/models/modules/geolocation/jdCountry.d.ts +10 -0
- package/dist/sdk/models/modules/geolocation/jdCountry.d.ts.map +1 -0
- package/dist/sdk/models/modules/geolocation/jdCountry.js +42 -0
- package/dist/sdk/models/modules/geolocation/jdDistrict.d.ts +14 -0
- package/dist/sdk/models/modules/geolocation/jdDistrict.d.ts.map +1 -0
- package/dist/sdk/models/modules/geolocation/jdDistrict.js +44 -0
- package/dist/sdk/models/modules/geolocation/jdState.d.ts +15 -0
- package/dist/sdk/models/modules/geolocation/jdState.d.ts.map +1 -0
- package/dist/sdk/models/modules/geolocation/jdState.js +50 -0
- package/dist/sdk/models/modules/karaoke/jdKtvShop.d.ts +6 -5
- package/dist/sdk/models/modules/karaoke/jdKtvShop.d.ts.map +1 -1
- package/dist/sdk/models/modules/karaoke/jdKtvShop.js +13 -11
- package/dist/sdk/models/modules/music/jdSong.d.ts +85 -0
- package/dist/sdk/models/modules/music/jdSong.d.ts.map +1 -0
- package/dist/sdk/models/modules/music/jdSong.js +140 -0
- package/dist/sdk/models/modules/user/jdPermission.d.ts +35 -0
- package/dist/sdk/models/modules/user/jdPermission.d.ts.map +1 -0
- package/dist/sdk/models/modules/user/jdPermission.js +73 -0
- package/dist/sdk/models/modules/user/jdSessionUser.d.ts +17 -0
- package/dist/sdk/models/modules/user/jdSessionUser.d.ts.map +1 -0
- package/dist/sdk/models/modules/user/jdSessionUser.js +62 -0
- package/dist/sdk/models/modules/user/jdUser.d.ts +18 -0
- package/dist/sdk/models/modules/user/jdUser.d.ts.map +1 -0
- package/dist/sdk/models/modules/user/jdUser.js +71 -0
- package/dist/sdk/utilities/browserUtils.d.ts +15 -4
- package/dist/sdk/utilities/browserUtils.d.ts.map +1 -1
- package/dist/sdk/utilities/browserUtils.js +102 -21
- package/dist/sdk/utilities/utils.d.ts +22 -10
- package/dist/sdk/utilities/utils.d.ts.map +1 -1
- package/dist/sdk/utilities/utils.js +87 -3
- package/package.json +4 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import JDResource, { ConnectorInfo } from "../../jdResource";
|
|
11
|
+
import { Utils } from "../../../utilities/utils";
|
|
12
|
+
export class JDUser extends JDResource {
|
|
13
|
+
get isLoggedIn() { return Utils.isset(globalThis.xAuthToken); }
|
|
14
|
+
constructor(data = {}, connectorInfo = new ConnectorInfo("", "")) {
|
|
15
|
+
super(connectorInfo);
|
|
16
|
+
this.name = "";
|
|
17
|
+
this.username = "";
|
|
18
|
+
this.phone = "";
|
|
19
|
+
this.email = "";
|
|
20
|
+
this.searchTokens = [];
|
|
21
|
+
this.setData(data);
|
|
22
|
+
}
|
|
23
|
+
setData(data) {
|
|
24
|
+
super.setData(data);
|
|
25
|
+
this.name = Utils.getString(data, "name");
|
|
26
|
+
this.username = Utils.getString(data, "username");
|
|
27
|
+
this.phone = Utils.getString(data, "phone");
|
|
28
|
+
this.email = Utils.getString(data, "email");
|
|
29
|
+
this.searchTokens = Utils.getArray(data, "search_tokens");
|
|
30
|
+
}
|
|
31
|
+
getUsers() {
|
|
32
|
+
return __awaiter(this, arguments, void 0, function* (orderBy = 'updated_at', order = 'desc', pageIndex = 0, countPerPage = 20, fields = '') {
|
|
33
|
+
const params = this.getSortParameters(orderBy, order, pageIndex, countPerPage, fields);
|
|
34
|
+
return yield this.getRelative('/modules/user/users', params);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
findUsers(name_1) {
|
|
38
|
+
return __awaiter(this, arguments, void 0, function* (name, orderBy = 'updated_at', order = 'desc', pageIndex = 0, countPerPage = 20, fields = '') {
|
|
39
|
+
const params = this.getSortParameters(orderBy, order, pageIndex, countPerPage, fields);
|
|
40
|
+
return yield this.getRelative('/modules/user/users/find', params);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// TODO: Sign the API calls to only be able to call from this client only
|
|
44
|
+
authenticate(username, password) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const body = { username, password };
|
|
47
|
+
const response = yield this.postRelative('/modules/user/users/authenticate', body);
|
|
48
|
+
yield this.checkUser(response);
|
|
49
|
+
return response;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
register(name, username, email, phone, password) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const body = { name, username, email, phone, password };
|
|
55
|
+
const response = yield this.postRelative('/modules/user/users/register', body);
|
|
56
|
+
yield this.checkUser(response);
|
|
57
|
+
return response;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
logout() {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
return yield this.postRelative('/modules/user/users/logout', {});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Get the user information
|
|
66
|
+
getInfo(id) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return yield this.getRelative(`/modules/user/users/${id}`, {});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
|
|
1
|
+
import { JDUser } from "../models/modules/user/jdUser";
|
|
2
|
+
import { ConnectorInfo } from "../models/jdResource";
|
|
3
|
+
export declare class BrowserUtils {
|
|
4
|
+
static setSessionItem(key: string, val: string): void;
|
|
5
|
+
static getSessionItem(key: string): string | null;
|
|
6
|
+
static setStorageItem(key: string, val: any): void;
|
|
7
|
+
static getStorageItem(key: string): string | null;
|
|
8
|
+
static setCookie(event: any, key: string, val: string): void;
|
|
9
|
+
static getCookie(event: any, key: string, val: string): string;
|
|
10
|
+
static setServerUserSessionInfo(event: any, dataRaw: Record<string, any>): JDUser;
|
|
11
|
+
static setUserSessionInfo(dataRaw: Record<string, any>): JDUser;
|
|
12
|
+
static getUserFromSession(): JDUser;
|
|
13
|
+
static isLoggedIn(): boolean;
|
|
14
|
+
static logout(connectorInfo: ConnectorInfo): Promise<boolean>;
|
|
15
|
+
}
|
|
5
16
|
//# sourceMappingURL=browserUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserUtils.d.ts","sourceRoot":"","sources":["../../../src/sdk/utilities/browserUtils.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"browserUtils.d.ts","sourceRoot":"","sources":["../../../src/sdk/utilities/browserUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,YAAY;IAErB,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IASrD,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQjD,MAAM,CAAE,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI;IAOnD,MAAM,CAAE,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAQlD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAUpD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAU7D,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAC,GAAG,EAAE,OAAO,EAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAI,MAAM;IAiBhF,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAI,MAAM;IAgB/D,MAAM,CAAC,kBAAkB;IAUzB,MAAM,CAAC,UAAU,IAAG,OAAO;WAKd,MAAM,CAAC,aAAa,EAAE,aAAa,GAAE,OAAO,CAAC,OAAO,CAAC;CASrE"}
|
|
@@ -1,26 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Utils } from "./utils";
|
|
11
|
+
import { JDUser } from "../models/modules/user/jdUser";
|
|
12
|
+
export class BrowserUtils {
|
|
13
|
+
// Set a session storage item
|
|
14
|
+
static setSessionItem(key, val) {
|
|
15
|
+
if (typeof window !== "undefined") {
|
|
16
|
+
window.sessionStorage.setItem(key, val);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
console.log("Session is not supported in SSR");
|
|
20
|
+
}
|
|
5
21
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
22
|
+
// Get a session storage item
|
|
23
|
+
static getSessionItem(key) {
|
|
24
|
+
if (typeof window !== "undefined") {
|
|
25
|
+
return window.sessionStorage.getItem(key);
|
|
26
|
+
}
|
|
27
|
+
return "";
|
|
11
28
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
window.localStorage.setItem(key, val);
|
|
29
|
+
// Set a local storage item
|
|
30
|
+
static setStorageItem(key, val) {
|
|
31
|
+
if (typeof window !== "undefined") {
|
|
32
|
+
window.localStorage.setItem(key, val);
|
|
33
|
+
}
|
|
18
34
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
// Get a local storage item
|
|
36
|
+
static getStorageItem(key) {
|
|
37
|
+
if (typeof window !== "undefined") {
|
|
38
|
+
return window.localStorage.getItem(key);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
// Cookies can be used between server and client-side. But for now, we'll use it for server side storage only
|
|
43
|
+
static setCookie(event, key, val) {
|
|
44
|
+
const cookieOptions = {
|
|
45
|
+
httpOnly: true, // Prevent client-side access
|
|
46
|
+
secure: true, // Use HTTPS
|
|
47
|
+
path: '/', // Available site-wide
|
|
48
|
+
maxAge: 60 * 60 * 24 * 7 // 1 week
|
|
49
|
+
};
|
|
50
|
+
event.cookies.set(key, val, cookieOptions);
|
|
51
|
+
}
|
|
52
|
+
static getCookie(event, key, val) {
|
|
53
|
+
const cookieOptions = {
|
|
54
|
+
httpOnly: true, // Prevent client-side access
|
|
55
|
+
secure: true, // Use HTTPS
|
|
56
|
+
path: '/', // Available site-wide
|
|
57
|
+
maxAge: 60 * 60 * 24 * 7 // 1 week
|
|
58
|
+
};
|
|
59
|
+
return event.cookies.get(key);
|
|
60
|
+
}
|
|
61
|
+
static setServerUserSessionInfo(event, dataRaw) {
|
|
62
|
+
const token = Utils.getString(dataRaw, "token");
|
|
63
|
+
const dataUser = Utils.getObject(dataRaw, "user");
|
|
64
|
+
//Save to browser session for long term user log in
|
|
65
|
+
this.setCookie(event, "token", token);
|
|
66
|
+
this.setCookie(event, "user", Utils.objectToString(dataUser));
|
|
67
|
+
// console.log(`Saving token in locals: ${token}`);
|
|
68
|
+
// Locals are a way to register trusted, server-side, per-request state only
|
|
69
|
+
event.locals.token = token;
|
|
70
|
+
// Save to svelte session as well
|
|
71
|
+
return new JDUser(dataUser);
|
|
72
|
+
}
|
|
73
|
+
// Data coming back with the API response in {user, token} format from new user registration or authentication
|
|
74
|
+
static setUserSessionInfo(dataRaw) {
|
|
75
|
+
const token = Utils.getString(dataRaw, "token");
|
|
76
|
+
const dataUser = Utils.getObject(dataRaw, "user");
|
|
77
|
+
//Save to browser session for long term user log in
|
|
78
|
+
this.setSessionItem("token", token);
|
|
79
|
+
this.setSessionItem("user", Utils.objectToString(dataUser));
|
|
80
|
+
//Also save in client-side global variables
|
|
81
|
+
globalThis.xAuthToken = token;
|
|
82
|
+
globalThis.userData = dataUser;
|
|
83
|
+
// Save to svelte session as well
|
|
84
|
+
return new JDUser(dataUser);
|
|
85
|
+
}
|
|
86
|
+
static getUserFromSession() {
|
|
87
|
+
const strUserInfo = this.getSessionItem("user");
|
|
88
|
+
if (strUserInfo != null) {
|
|
89
|
+
const dataUser = Utils.stringToObject(strUserInfo);
|
|
90
|
+
return new JDUser(dataUser);
|
|
91
|
+
}
|
|
92
|
+
return new JDUser({});
|
|
93
|
+
}
|
|
94
|
+
static isLoggedIn() {
|
|
95
|
+
const token = this.getSessionItem("token");
|
|
96
|
+
return token != null;
|
|
97
|
+
}
|
|
98
|
+
static logout(connectorInfo) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const response = yield new JDUser({}, connectorInfo).logout();
|
|
101
|
+
// Force to log out no matter what
|
|
102
|
+
this.setSessionItem("token", "");
|
|
103
|
+
this.setSessionItem("user", "");
|
|
104
|
+
return response.statusCode == 200;
|
|
105
|
+
});
|
|
24
106
|
}
|
|
25
|
-
return null;
|
|
26
107
|
}
|
|
@@ -1,20 +1,31 @@
|
|
|
1
|
+
export declare const emailRegexp: RegExp;
|
|
1
2
|
export declare class Utils {
|
|
2
|
-
static
|
|
3
|
-
|
|
3
|
+
static rowsPerPage: {
|
|
4
|
+
value: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}[];
|
|
7
|
+
static nl2br(str: string, is_xhtml: boolean): string;
|
|
8
|
+
static hasField(data: Record<string, any>, field: string): boolean;
|
|
9
|
+
static getString(data: Record<string, any>, field: string, defaultVal?: string): string;
|
|
4
10
|
static getNumber(data: Record<string, any>, field: string): number;
|
|
5
|
-
static getInteger(data:
|
|
6
|
-
static getBigInteger(data:
|
|
7
|
-
static getFloat(data:
|
|
8
|
-
static getBoolean(data:
|
|
11
|
+
static getInteger(data: Record<string, any>, field: string, defaultVal?: number): number;
|
|
12
|
+
static getBigInteger(data: Record<string, any>, field: string, defaultVal?: number): bigint;
|
|
13
|
+
static getFloat(data: Record<string, any>, field: string, defaultVal?: number): number;
|
|
14
|
+
static getBoolean(data: Record<string, any>, field: string): boolean;
|
|
9
15
|
static getObject(data: Record<string, any>, field: string): Record<string, any>;
|
|
10
16
|
static getArray(data: Record<string, any>, field: string): any[];
|
|
11
|
-
static getDate(data:
|
|
12
|
-
static isMongoDateExpiredFromField(data:
|
|
17
|
+
static getDate(data: Record<string, any>, field: string): Date;
|
|
18
|
+
static isMongoDateExpiredFromField(data: Record<string, any>, field: string): boolean;
|
|
13
19
|
static isMongoDateExpired(mongoDate: string | Date): boolean;
|
|
14
|
-
static addIntegerToField(data:
|
|
15
|
-
static addFloatToField(data:
|
|
20
|
+
static addIntegerToField(data: Record<string, any>, field: string, amount: number): number;
|
|
21
|
+
static addFloatToField(data: Record<string, any>, field: string, amount: number): number;
|
|
16
22
|
static stringToObject(strData: string): any;
|
|
17
23
|
static stringToArray(strData: string): any[];
|
|
24
|
+
static objectToString(data: object): string;
|
|
25
|
+
static arrayToString(dataArray: object): string;
|
|
26
|
+
static allFieldsToNumber(fields: Record<string, any>): Record<string, number>;
|
|
27
|
+
static parseServerValidationErrors(error: Record<string, any>, message?: string): Record<string, string>;
|
|
28
|
+
static slugify(text: string): string;
|
|
18
29
|
static copyToClipboard(val: string, message?: string): void;
|
|
19
30
|
static isset(obj: Record<string, any> | null | undefined | string | boolean): boolean;
|
|
20
31
|
static issetNum(val: any): boolean;
|
|
@@ -26,6 +37,7 @@ export declare class Utils {
|
|
|
26
37
|
static numberFormatDecimals(num: number, decimals?: number): string;
|
|
27
38
|
static generateCode(length?: number): string;
|
|
28
39
|
static generateRandomString(length?: number): string;
|
|
40
|
+
static formatStringFromArray(dataArray: any[], field?: string, languageCode?: string): string;
|
|
29
41
|
static sleep(ms: number): Promise<void>;
|
|
30
42
|
}
|
|
31
43
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sdk/utilities/utils.ts"],"names":[],"mappings":"AAEA,qBAAa,KAAK;IACd,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/sdk/utilities/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,QAA4C,CAAC;AAErE,qBAAa,KAAK;IACd,MAAM,CAAC,WAAW;;;QAShB;IAEF,MAAM,CAAC,KAAK,CAAE,GAAG,EAAC,MAAM,EAAE,QAAQ,EAAC,OAAO,GAAG,MAAM;IAKnD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlE,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,SAAK,GAAG,MAAM;IAInF,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAIlE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,SAAI,GAAG,MAAM;IAMnF,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,SAAI,GAAG,MAAM;IAItF,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,SAAM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C,SAAS,EAAE,GAAG,EAAE,EAAE,KAAK,SAAU,EAAE,YAAY,SAAO,GAAG,MAAM;IAkB5F,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG1C"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { globalEventEmitter } from "./globalEventHandler";
|
|
2
|
+
export const emailRegexp = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
|
|
2
3
|
export class Utils {
|
|
4
|
+
static nl2br(str, is_xhtml) {
|
|
5
|
+
const breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br ' + '/>' : '<br>'; // Adjust comment to avoid issue on phpjs.org display
|
|
6
|
+
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
|
|
7
|
+
}
|
|
3
8
|
static hasField(data, field) {
|
|
4
|
-
return
|
|
9
|
+
return data[field] != undefined;
|
|
5
10
|
}
|
|
6
11
|
static getString(data, field, defaultVal = '') {
|
|
7
12
|
return this.hasField(data, field) ? data[field] : defaultVal;
|
|
@@ -11,7 +16,7 @@ export class Utils {
|
|
|
11
16
|
}
|
|
12
17
|
static getInteger(data, field, defaultVal = 0) {
|
|
13
18
|
const fieldExist = this.hasField(data, field);
|
|
14
|
-
console.log(`Field Exist: ${fieldExist}`);
|
|
19
|
+
// console.log(`Field Exist: ${fieldExist}`);
|
|
15
20
|
return this.hasField(data, field) ? parseInt(data[field]) : defaultVal;
|
|
16
21
|
}
|
|
17
22
|
static getBigInteger(data, field, defaultVal = 0) {
|
|
@@ -66,6 +71,49 @@ export class Utils {
|
|
|
66
71
|
return [];
|
|
67
72
|
}
|
|
68
73
|
}
|
|
74
|
+
static objectToString(data) {
|
|
75
|
+
try {
|
|
76
|
+
return JSON.stringify(data);
|
|
77
|
+
}
|
|
78
|
+
catch (ex) {
|
|
79
|
+
return "{}";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
static arrayToString(dataArray) {
|
|
83
|
+
try {
|
|
84
|
+
return JSON.stringify(dataArray);
|
|
85
|
+
}
|
|
86
|
+
catch (ex) {
|
|
87
|
+
return "[]";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
static allFieldsToNumber(fields) {
|
|
91
|
+
const newFields = {};
|
|
92
|
+
Object.keys(fields).forEach((key) => {
|
|
93
|
+
newFields[key] = parseInt(this.getString(fields, key));
|
|
94
|
+
});
|
|
95
|
+
return newFields;
|
|
96
|
+
}
|
|
97
|
+
static parseServerValidationErrors(error, message = 'Form validation failed!') {
|
|
98
|
+
const errors = {};
|
|
99
|
+
if (error.name === 'ValidationError') {
|
|
100
|
+
// Extract the validation errors
|
|
101
|
+
Object.keys(error.errors).forEach((key) => {
|
|
102
|
+
errors[key] = error.errors[key].message;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
errors['message'] = message;
|
|
106
|
+
return errors;
|
|
107
|
+
}
|
|
108
|
+
static slugify(text) {
|
|
109
|
+
return text
|
|
110
|
+
.toString() // Convert to string
|
|
111
|
+
.toLowerCase() // Convert to lowercase
|
|
112
|
+
.trim() // Remove whitespace from both ends
|
|
113
|
+
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
|
114
|
+
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
|
|
115
|
+
.replace(/\-\-+/g, '-'); // Replace multiple hyphens with a single hyphen
|
|
116
|
+
}
|
|
69
117
|
static copyToClipboard(val, message = 'Text copied') {
|
|
70
118
|
navigator.clipboard.writeText(val)
|
|
71
119
|
.then(() => {
|
|
@@ -80,7 +128,10 @@ export class Utils {
|
|
|
80
128
|
if (typeof obj == "string") {
|
|
81
129
|
return obj != "";
|
|
82
130
|
}
|
|
83
|
-
|
|
131
|
+
// if(typeof obj == "object"){
|
|
132
|
+
// return Object.keys(obj).length > 0
|
|
133
|
+
// }
|
|
134
|
+
return obj !== null && obj !== undefined;
|
|
84
135
|
}
|
|
85
136
|
// Check if a numeric value is set and valid
|
|
86
137
|
static issetNum(val) {
|
|
@@ -128,8 +179,41 @@ export class Utils {
|
|
|
128
179
|
}
|
|
129
180
|
return result;
|
|
130
181
|
}
|
|
182
|
+
//String manipulations from JSON data
|
|
183
|
+
static formatStringFromArray(dataArray, field = 'title', languageCode = 'en') {
|
|
184
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
185
|
+
let strValue = '';
|
|
186
|
+
for (const contentData of dataArray) {
|
|
187
|
+
let val = '';
|
|
188
|
+
switch (field) {
|
|
189
|
+
case 'title':
|
|
190
|
+
val = languageCode == 'en' ? (_b = (_a = contentData === null || contentData === void 0 ? void 0 : contentData.title) === null || _a === void 0 ? void 0 : _a.en) !== null && _b !== void 0 ? _b : '' : (_d = (_c = contentData === null || contentData === void 0 ? void 0 : contentData.title) === null || _c === void 0 ? void 0 : _c.mm) !== null && _d !== void 0 ? _d : '';
|
|
191
|
+
break;
|
|
192
|
+
case 'name':
|
|
193
|
+
val = languageCode == 'en' ? (_f = (_e = contentData === null || contentData === void 0 ? void 0 : contentData.name) === null || _e === void 0 ? void 0 : _e.en) !== null && _f !== void 0 ? _f : '' : (_h = (_g = contentData === null || contentData === void 0 ? void 0 : contentData.name) === null || _g === void 0 ? void 0 : _g.mm) !== null && _h !== void 0 ? _h : '';
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
val = languageCode == 'en' ? (_k = (_j = contentData === null || contentData === void 0 ? void 0 : contentData.title) === null || _j === void 0 ? void 0 : _j.en) !== null && _k !== void 0 ? _k : '' : (_m = (_l = contentData === null || contentData === void 0 ? void 0 : contentData.title) === null || _l === void 0 ? void 0 : _l.mm) !== null && _m !== void 0 ? _m : '';
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
if (val != '') {
|
|
200
|
+
strValue += val;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return strValue;
|
|
204
|
+
}
|
|
131
205
|
// Sleep for a specified amount of time
|
|
132
206
|
static sleep(ms) {
|
|
133
207
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
134
208
|
}
|
|
135
209
|
}
|
|
210
|
+
Utils.rowsPerPage = [
|
|
211
|
+
{ value: "5", label: "5" },
|
|
212
|
+
{ value: "10", label: "10" },
|
|
213
|
+
{ value: "15", label: "15" },
|
|
214
|
+
{ value: "20", label: "20" },
|
|
215
|
+
{ value: "50", label: "50" },
|
|
216
|
+
{ value: "100", label: "100" },
|
|
217
|
+
{ value: "500", label: "500" },
|
|
218
|
+
{ value: "1000", label: "1000" }
|
|
219
|
+
];
|
package/package.json
CHANGED