jd_platform_sdk 0.0.4 → 0.0.7
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 +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/sdk/configs/jdConfig.d.ts.map +1 -1
- package/dist/sdk/configs/jdConfig.js +0 -2
- package/dist/sdk/jdConnector.js +1 -1
- package/dist/sdk/models/jdApplication.d.ts +4 -4
- package/dist/sdk/models/jdApplication.d.ts.map +1 -1
- package/dist/sdk/models/jdApplication.js +8 -8
- package/dist/sdk/models/jdResource.d.ts +16 -10
- package/dist/sdk/models/jdResource.d.ts.map +1 -1
- package/dist/sdk/models/jdResource.js +43 -33
- package/dist/sdk/models/modules/geolocation/jdCity.d.ts +6 -6
- package/dist/sdk/models/modules/geolocation/jdCity.d.ts.map +1 -1
- package/dist/sdk/models/modules/geolocation/jdCity.js +14 -14
- package/dist/sdk/models/modules/geolocation/jdCountry.d.ts +6 -6
- package/dist/sdk/models/modules/geolocation/jdCountry.d.ts.map +1 -1
- package/dist/sdk/models/modules/geolocation/jdCountry.js +14 -14
- package/dist/sdk/models/modules/geolocation/jdDistrict.d.ts +5 -5
- package/dist/sdk/models/modules/geolocation/jdDistrict.d.ts.map +1 -1
- package/dist/sdk/models/modules/geolocation/jdDistrict.js +11 -11
- package/dist/sdk/models/modules/geolocation/jdState.d.ts +6 -6
- package/dist/sdk/models/modules/geolocation/jdState.d.ts.map +1 -1
- package/dist/sdk/models/modules/geolocation/jdState.js +14 -14
- package/dist/sdk/models/modules/karaoke/jdKtvShop.d.ts +5 -4
- package/dist/sdk/models/modules/karaoke/jdKtvShop.d.ts.map +1 -1
- package/dist/sdk/models/modules/karaoke/jdKtvShop.js +13 -8
- package/dist/sdk/models/modules/music/jdAlbum.d.ts +84 -0
- package/dist/sdk/models/modules/music/jdAlbum.d.ts.map +1 -0
- package/dist/sdk/models/modules/music/jdAlbum.js +131 -0
- package/dist/sdk/models/modules/music/jdArtist.d.ts +76 -0
- package/dist/sdk/models/modules/music/jdArtist.d.ts.map +1 -0
- package/dist/sdk/models/modules/music/jdArtist.js +115 -0
- package/dist/sdk/models/modules/music/jdComposer.d.ts +76 -0
- package/dist/sdk/models/modules/music/jdComposer.d.ts.map +1 -0
- package/dist/sdk/models/modules/music/jdComposer.js +115 -0
- package/dist/sdk/models/modules/music/jdMusicCombinations.d.ts +6 -0
- package/dist/sdk/models/modules/music/jdMusicCombinations.d.ts.map +1 -0
- package/dist/sdk/models/modules/music/jdMusicCombinations.js +21 -0
- package/dist/sdk/models/modules/music/jdSong.d.ts +88 -0
- package/dist/sdk/models/modules/music/jdSong.d.ts.map +1 -0
- package/dist/sdk/models/modules/music/jdSong.js +144 -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 +7 -7
- package/dist/sdk/models/modules/user/jdSessionUser.d.ts.map +1 -1
- package/dist/sdk/models/modules/user/jdSessionUser.js +14 -14
- package/dist/sdk/models/modules/user/jdUser.d.ts +8 -7
- package/dist/sdk/models/modules/user/jdUser.d.ts.map +1 -1
- package/dist/sdk/models/modules/user/jdUser.js +22 -23
- package/dist/sdk/utilities/browserUtils.d.ts +10 -1
- package/dist/sdk/utilities/browserUtils.d.ts.map +1 -1
- package/dist/sdk/utilities/browserUtils.js +80 -1
- package/dist/sdk/utilities/utils.d.ts +20 -10
- package/dist/sdk/utilities/utils.d.ts.map +1 -1
- package/dist/sdk/utilities/utils.js +71 -3
- package/package.json +1 -1
|
@@ -7,12 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import JDResource from "../../jdResource";
|
|
10
|
+
import JDResource, { ConnectorInfo } from "../../jdResource";
|
|
11
11
|
import { Utils } from "../../../utilities/utils";
|
|
12
12
|
export class JDSessionUser extends JDResource {
|
|
13
13
|
get isLoggedIn() { return Utils.isset(globalThis.xAuthToken); }
|
|
14
|
-
constructor(data) {
|
|
15
|
-
super(
|
|
14
|
+
constructor(data = {}, connectorInfo = new ConnectorInfo("", "")) {
|
|
15
|
+
super(connectorInfo);
|
|
16
16
|
this.cloudSessionId = "";
|
|
17
17
|
this.name = "";
|
|
18
18
|
this.username = "";
|
|
@@ -28,35 +28,35 @@ export class JDSessionUser extends JDResource {
|
|
|
28
28
|
this.phone = Utils.getString(data, "phone");
|
|
29
29
|
this.searchTokens = Utils.getArray(data, "search_tokens");
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
findSessionUsers(name_1) {
|
|
32
32
|
return __awaiter(this, arguments, void 0, function* (name, orderBy = 'updated_at', order = 'desc', pageIndex = 0, countPerPage = 20, fields = '') {
|
|
33
|
-
const params =
|
|
34
|
-
return yield
|
|
33
|
+
const params = this.getSortParameters(orderBy, order, pageIndex, countPerPage, fields);
|
|
34
|
+
return yield this.getRelative('/modules/user/session_users/find', params);
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
// TODO: Sign the API calls to only be able to call from this client only
|
|
38
|
-
|
|
38
|
+
authenticate(username, password) {
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
const body = { username, password };
|
|
41
|
-
return yield
|
|
41
|
+
return yield this.postRelative('/modules/user/session_users/authenticate', body);
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
register(name, username, email, phone, password) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
46
|
const body = { name, username, email, phone, password };
|
|
47
|
-
return yield
|
|
47
|
+
return yield this.postRelative('/modules/user/session_users/register', body);
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
logout(name, username, email, phone, password) {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52
52
|
const body = { name, username, email, phone, password };
|
|
53
|
-
return yield
|
|
53
|
+
return yield this.postRelative('/modules/user/session_users/register', body);
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
// Get the user information
|
|
57
|
-
|
|
57
|
+
getInfo(id) {
|
|
58
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
return yield
|
|
59
|
+
return yield this.getRelative(`/modules/user/session_users/${id}`, {});
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import JDResource from "../../jdResource";
|
|
1
|
+
import JDResource, { ConnectorInfo } from "../../jdResource";
|
|
2
2
|
export declare class JDUser extends JDResource {
|
|
3
3
|
name: string;
|
|
4
4
|
username: string;
|
|
@@ -6,12 +6,13 @@ export declare class JDUser extends JDResource {
|
|
|
6
6
|
email: string;
|
|
7
7
|
searchTokens: any[];
|
|
8
8
|
get isLoggedIn(): boolean;
|
|
9
|
-
constructor(data
|
|
9
|
+
constructor(data?: Record<string, any>, connectorInfo?: ConnectorInfo);
|
|
10
10
|
setData(data: Record<string, any>): void;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
getUsers(orderBy?: string, order?: string, pageIndex?: number, countPerPage?: number, fields?: string): Promise<import("../../../jdConnector").SimpleResponse>;
|
|
12
|
+
findUsers(name: string, orderBy?: string, order?: string, pageIndex?: number, countPerPage?: number, fields?: string): Promise<import("../../../jdConnector").SimpleResponse>;
|
|
13
|
+
authenticate(username: string, password: string): Promise<import("../../../jdConnector").SimpleResponse>;
|
|
14
|
+
register(name: string, username: string, email: string, phone: string, password: string): Promise<import("../../../jdConnector").SimpleResponse>;
|
|
15
|
+
logout(): Promise<import("../../../jdConnector").SimpleResponse>;
|
|
16
|
+
getInfo(id: string): Promise<import("../../../jdConnector").SimpleResponse>;
|
|
16
17
|
}
|
|
17
18
|
//# sourceMappingURL=jdUser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jdUser.d.ts","sourceRoot":"","sources":["../../../../../src/sdk/models/modules/user/jdUser.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"jdUser.d.ts","sourceRoot":"","sources":["../../../../../src/sdk/models/modules/user/jdUser.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,EAAE,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE3D,qBAAa,MAAO,SAAQ,UAAU;IACrC,IAAI,EAAC,MAAM,CAAM;IACjB,QAAQ,EAAC,MAAM,CAAM;IACrB,KAAK,EAAC,MAAM,CAAM;IAClB,KAAK,EAAC,MAAM,CAAM;IAClB,YAAY,EAAE,GAAG,EAAE,CAAM;IAEzB,IAAI,UAAU,IAAG,OAAO,CAA+C;gBAE3D,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAAE,aAAa,GAAE,aAAyC;IAKpG,OAAO,CAAC,IAAI,EAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAS1B,QAAQ,CAAC,OAAO,SAAe,EAAE,KAAK,SAAS,EAAE,SAAS,SAAI,EAAE,YAAY,SAAK,EAAE,MAAM,SAAK;IAK9F,SAAS,CAAC,IAAI,EAAC,MAAM,EAAE,OAAO,SAAe,EAAE,KAAK,SAAS,EAAE,SAAS,SAAI,EAAE,YAAY,SAAK,EAAE,MAAM,SAAK;IAM5G,YAAY,CAAC,QAAQ,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM;IAO7C,QAAQ,CAAC,IAAI,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM;IAOlF,MAAM;IAKN,OAAO,CAAC,EAAE,EAAC,MAAM;CAGvB"}
|
|
@@ -7,12 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import JDResource from "../../jdResource";
|
|
10
|
+
import JDResource, { ConnectorInfo } from "../../jdResource";
|
|
11
11
|
import { Utils } from "../../../utilities/utils";
|
|
12
12
|
export class JDUser extends JDResource {
|
|
13
13
|
get isLoggedIn() { return Utils.isset(globalThis.xAuthToken); }
|
|
14
|
-
constructor(data) {
|
|
15
|
-
super(
|
|
14
|
+
constructor(data = {}, connectorInfo = new ConnectorInfo("", "")) {
|
|
15
|
+
super(connectorInfo);
|
|
16
16
|
this.name = "";
|
|
17
17
|
this.username = "";
|
|
18
18
|
this.phone = "";
|
|
@@ -28,45 +28,44 @@ export class JDUser extends JDResource {
|
|
|
28
28
|
this.email = Utils.getString(data, "email");
|
|
29
29
|
this.searchTokens = Utils.getArray(data, "search_tokens");
|
|
30
30
|
}
|
|
31
|
-
|
|
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) {
|
|
32
38
|
return __awaiter(this, arguments, void 0, function* (name, orderBy = 'updated_at', order = 'desc', pageIndex = 0, countPerPage = 20, fields = '') {
|
|
33
|
-
const params =
|
|
34
|
-
return yield
|
|
39
|
+
const params = this.getSortParameters(orderBy, order, pageIndex, countPerPage, fields);
|
|
40
|
+
return yield this.getRelative('/modules/user/users/find', params);
|
|
35
41
|
});
|
|
36
42
|
}
|
|
37
43
|
// TODO: Sign the API calls to only be able to call from this client only
|
|
38
|
-
|
|
44
|
+
authenticate(username, password) {
|
|
39
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
46
|
const body = { username, password };
|
|
41
|
-
const response = yield
|
|
42
|
-
yield
|
|
47
|
+
const response = yield this.postRelative('/modules/user/users/authenticate', body);
|
|
48
|
+
yield this.checkUser(response);
|
|
43
49
|
return response;
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
|
-
|
|
52
|
+
register(name, username, email, phone, password) {
|
|
47
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
54
|
const body = { name, username, email, phone, password };
|
|
49
|
-
const response = yield
|
|
50
|
-
yield
|
|
55
|
+
const response = yield this.postRelative('/modules/user/users/register', body);
|
|
56
|
+
yield this.checkUser(response);
|
|
51
57
|
return response;
|
|
52
58
|
});
|
|
53
59
|
}
|
|
54
|
-
|
|
60
|
+
logout() {
|
|
55
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
|
|
57
|
-
const response = yield JDResource.postRelative('/modules/user/users/register', body);
|
|
58
|
-
// Reset the auth token information
|
|
59
|
-
if (response.statusCode == 200) {
|
|
60
|
-
globalThis.xAuthToken = "";
|
|
61
|
-
globalThis.user = new JDUser({});
|
|
62
|
-
}
|
|
63
|
-
return response;
|
|
62
|
+
return yield this.postRelative('/modules/user/users/logout', {});
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
65
|
// Get the user information
|
|
67
|
-
|
|
66
|
+
getInfo(id) {
|
|
68
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return yield
|
|
68
|
+
return yield this.getRelative(`/modules/user/users/${id}`, {});
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
71
|
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { JDUser } from "../models/modules/user/jdUser";
|
|
2
|
+
import { ConnectorInfo } from "../models/jdResource";
|
|
1
3
|
export declare class BrowserUtils {
|
|
2
4
|
static setSessionItem(key: string, val: string): void;
|
|
3
5
|
static getSessionItem(key: string): string | null;
|
|
4
|
-
static setStorageItem(key: string, val:
|
|
6
|
+
static setStorageItem(key: string, val: any): void;
|
|
5
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>;
|
|
6
15
|
}
|
|
7
16
|
//# sourceMappingURL=browserUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserUtils.d.ts","sourceRoot":"","sources":["../../../src/sdk/utilities/browserUtils.ts"],"names":[],"mappings":"
|
|
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,16 +1,30 @@
|
|
|
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";
|
|
1
12
|
export class BrowserUtils {
|
|
2
13
|
// Set a session storage item
|
|
3
14
|
static setSessionItem(key, val) {
|
|
4
15
|
if (typeof window !== "undefined") {
|
|
5
16
|
window.sessionStorage.setItem(key, val);
|
|
6
17
|
}
|
|
18
|
+
else {
|
|
19
|
+
console.log("Session is not supported in SSR");
|
|
20
|
+
}
|
|
7
21
|
}
|
|
8
22
|
// Get a session storage item
|
|
9
23
|
static getSessionItem(key) {
|
|
10
24
|
if (typeof window !== "undefined") {
|
|
11
25
|
return window.sessionStorage.getItem(key);
|
|
12
26
|
}
|
|
13
|
-
return
|
|
27
|
+
return "";
|
|
14
28
|
}
|
|
15
29
|
// Set a local storage item
|
|
16
30
|
static setStorageItem(key, val) {
|
|
@@ -25,4 +39,69 @@ export class BrowserUtils {
|
|
|
25
39
|
}
|
|
26
40
|
return null;
|
|
27
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
|
+
});
|
|
106
|
+
}
|
|
28
107
|
}
|
|
@@ -1,22 +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[];
|
|
18
24
|
static objectToString(data: object): string;
|
|
19
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;
|
|
20
29
|
static copyToClipboard(val: string, message?: string): void;
|
|
21
30
|
static isset(obj: Record<string, any> | null | undefined | string | boolean): boolean;
|
|
22
31
|
static issetNum(val: any): boolean;
|
|
@@ -28,6 +37,7 @@ export declare class Utils {
|
|
|
28
37
|
static numberFormatDecimals(num: number, decimals?: number): string;
|
|
29
38
|
static generateCode(length?: number): string;
|
|
30
39
|
static generateRandomString(length?: number): string;
|
|
40
|
+
static formatStringFromArray(dataArray: any[], field?: string, languageCode?: string): string;
|
|
31
41
|
static sleep(ms: number): Promise<void>;
|
|
32
42
|
}
|
|
33
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,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,CAAC,YAAY,CAAC,MAAM,GAAE,MAAU,GAAG,MAAM;IAU/C,MAAM,CAAC,oBAAoB,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM;IAUxD,MAAM,CAAC,qBAAqB,CAAC,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) {
|
|
@@ -82,6 +87,33 @@ export class Utils {
|
|
|
82
87
|
return "[]";
|
|
83
88
|
}
|
|
84
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
|
+
}
|
|
85
117
|
static copyToClipboard(val, message = 'Text copied') {
|
|
86
118
|
navigator.clipboard.writeText(val)
|
|
87
119
|
.then(() => {
|
|
@@ -96,7 +128,10 @@ export class Utils {
|
|
|
96
128
|
if (typeof obj == "string") {
|
|
97
129
|
return obj != "";
|
|
98
130
|
}
|
|
99
|
-
|
|
131
|
+
// if(typeof obj == "object"){
|
|
132
|
+
// return Object.keys(obj).length > 0
|
|
133
|
+
// }
|
|
134
|
+
return obj !== null && obj !== undefined;
|
|
100
135
|
}
|
|
101
136
|
// Check if a numeric value is set and valid
|
|
102
137
|
static issetNum(val) {
|
|
@@ -144,8 +179,41 @@ export class Utils {
|
|
|
144
179
|
}
|
|
145
180
|
return result;
|
|
146
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
|
+
}
|
|
147
205
|
// Sleep for a specified amount of time
|
|
148
206
|
static sleep(ms) {
|
|
149
207
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
150
208
|
}
|
|
151
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
|
+
];
|