jd_platform_sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/index.js +28 -44
  2. package/dist/sdk/configs/jdConfig.js +1 -5
  3. package/dist/sdk/jdConnector.js +72 -63
  4. package/dist/sdk/jdSdk.js +1 -5
  5. package/dist/sdk/models/jdApplication.js +63 -71
  6. package/dist/sdk/models/jdResource.js +104 -91
  7. package/dist/sdk/models/modules/dashboard/jdDashboardCombinations.js +15 -31
  8. package/dist/sdk/models/modules/geolocation/jdCity.js +49 -55
  9. package/dist/sdk/models/modules/geolocation/jdCountry.js +47 -53
  10. package/dist/sdk/models/modules/geolocation/jdDistrict.js +49 -57
  11. package/dist/sdk/models/modules/geolocation/jdState.js +49 -55
  12. package/dist/sdk/models/modules/karaoke/jdKtvShop.js +82 -88
  13. package/dist/sdk/models/modules/music/jdAlbum.js +96 -102
  14. package/dist/sdk/models/modules/music/jdArtist.js +87 -89
  15. package/dist/sdk/models/modules/music/jdComposer.js +83 -87
  16. package/dist/sdk/models/modules/music/jdMusicCombinations.js +15 -31
  17. package/dist/sdk/models/modules/music/jdSong.js +105 -113
  18. package/dist/sdk/models/modules/radio_station/jdRadioStation.js +82 -88
  19. package/dist/sdk/models/modules/user/jdPermission.js +55 -63
  20. package/dist/sdk/models/modules/user/jdPermissionGroup.js +51 -57
  21. package/dist/sdk/models/modules/user/jdSessionUser.js +70 -72
  22. package/dist/sdk/models/modules/user/jdUser.js +73 -75
  23. package/dist/sdk/models/modules/user/jdUserRole.js +50 -54
  24. package/dist/sdk/utilities/browserUtils.js +31 -24
  25. package/dist/sdk/utilities/cryptoUtils.js +6 -13
  26. package/dist/sdk/utilities/dateUtils.js +1 -5
  27. package/dist/sdk/utilities/globalEventHandler.js +4 -5
  28. package/dist/sdk/utilities/stringUtils.js +2 -6
  29. package/dist/sdk/utilities/utils.js +19 -22
  30. package/package.json +1 -1
@@ -1,9 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BrowserUtils = void 0;
4
- const utils_1 = require("./utils");
5
- const jdUser_1 = require("../models/modules/user/jdUser");
6
- class BrowserUtils {
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 {
7
13
  // Set a session storage item
8
14
  static setSessionItem(key, val) {
9
15
  if (typeof window !== "undefined") {
@@ -53,48 +59,49 @@ class BrowserUtils {
53
59
  return event.cookies.get(key);
54
60
  }
55
61
  static setServerUserSessionInfo(event, dataRaw) {
56
- const token = utils_1.Utils.getString(dataRaw, "token");
57
- const dataUser = utils_1.Utils.getObject(dataRaw, "user");
62
+ const token = Utils.getString(dataRaw, "token");
63
+ const dataUser = Utils.getObject(dataRaw, "user");
58
64
  //Save to browser session for long term user log in
59
65
  this.setCookie(event, "token", token);
60
- this.setCookie(event, "user", utils_1.Utils.objectToString(dataUser));
66
+ this.setCookie(event, "user", Utils.objectToString(dataUser));
61
67
  // console.log(`Saving token in locals: ${token}`);
62
68
  // Locals are a way to register trusted, server-side, per-request state only
63
69
  event.locals.token = token;
64
70
  // Save to svelte session as well
65
- return new jdUser_1.JDUser(dataUser);
71
+ return new JDUser(dataUser);
66
72
  }
67
73
  // Data coming back with the API response in {user, token} format from new user registration or authentication
68
74
  static setUserSessionInfo(dataRaw) {
69
- const token = utils_1.Utils.getString(dataRaw, "token");
70
- const dataUser = utils_1.Utils.getObject(dataRaw, "user");
75
+ const token = Utils.getString(dataRaw, "token");
76
+ const dataUser = Utils.getObject(dataRaw, "user");
71
77
  //Save to browser session for long term user log in
72
78
  this.setSessionItem("token", token);
73
- this.setSessionItem("user", utils_1.Utils.objectToString(dataUser));
79
+ this.setSessionItem("user", Utils.objectToString(dataUser));
74
80
  //Also save in client-side global variables
75
81
  globalThis.xAuthToken = token;
76
82
  globalThis.userData = dataUser;
77
83
  // Save to svelte session as well
78
- return new jdUser_1.JDUser(dataUser);
84
+ return new JDUser(dataUser);
79
85
  }
80
86
  static getUserFromSession() {
81
87
  const strUserInfo = this.getSessionItem("user");
82
88
  if (strUserInfo != null) {
83
- const dataUser = utils_1.Utils.stringToObject(strUserInfo);
84
- return new jdUser_1.JDUser(dataUser);
89
+ const dataUser = Utils.stringToObject(strUserInfo);
90
+ return new JDUser(dataUser);
85
91
  }
86
- return new jdUser_1.JDUser({});
92
+ return new JDUser({});
87
93
  }
88
94
  static isLoggedIn() {
89
95
  const token = this.getSessionItem("token");
90
96
  return token != null;
91
97
  }
92
- static async logout(connectorInfo) {
93
- const response = await new jdUser_1.JDUser({}, connectorInfo).logout();
94
- // Force to log out no matter what
95
- this.setSessionItem("token", "");
96
- this.setSessionItem("user", "");
97
- return response.statusCode == 200;
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
+ });
98
106
  }
99
107
  }
100
- exports.BrowserUtils = BrowserUtils;
@@ -1,18 +1,12 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CryptoUtils = void 0;
7
- const hmac_sha256_1 = __importDefault(require("crypto-js/hmac-sha256"));
8
- const utils_1 = require("./utils");
9
- class CryptoUtils {
1
+ import hmacSha256 from 'crypto-js/hmac-sha256';
2
+ import { Utils } from "./utils";
3
+ export class CryptoUtils {
10
4
  // Generate hash string to sign to communicate with the server to allow from this client only
11
5
  static generateBeforeHashString(paramsArray) {
12
6
  const curUserId = globalThis.userId;
13
7
  const curApplicationId = globalThis.applicationId;
14
8
  const curAppSecret = globalThis.appSecret;
15
- if (!utils_1.Utils.isset(curUserId) || !utils_1.Utils.isset(curApplicationId) || !utils_1.Utils.isset(curAppSecret)) {
9
+ if (!Utils.isset(curUserId) || !Utils.isset(curApplicationId) || !Utils.isset(curAppSecret)) {
16
10
  console.log("You need to initialise the required parameters before hashing!");
17
11
  return;
18
12
  }
@@ -23,10 +17,9 @@ class CryptoUtils {
23
17
  // console.log(`Cur Application Id: ${curApplicationId.get()}`);
24
18
  // console.log(`Cur User Id: ${userId}`);
25
19
  // console.log(`Before Hash: ${strBeforeHash}`);
26
- return (0, hmac_sha256_1.default)(strBeforeHash, curAppSecret).toString();
20
+ return hmacSha256(strBeforeHash, curAppSecret).toString();
27
21
  }
28
22
  static generateHash(strMessage, secret) {
29
- return (0, hmac_sha256_1.default)(strMessage, secret).toString();
23
+ return hmacSha256(strMessage, secret).toString();
30
24
  }
31
25
  }
32
- exports.CryptoUtils = CryptoUtils;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DateUtils = void 0;
4
- class DateUtils {
1
+ export class DateUtils {
5
2
  //////////////////////////////////////////////////////////////////////////////////
6
3
  // Example usage:
7
4
  // const targetDate = new Date('2023-08-01T12:00:00Z');
@@ -50,4 +47,3 @@ class DateUtils {
50
47
  return Date.now().toString();
51
48
  }
52
49
  }
53
- exports.DateUtils = DateUtils;
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.globalEventEmitter = void 0;
4
1
  ////////////////////////////////////////////////////////////////
5
2
  // Listening for an event
6
3
  // import { globalEventEmitter } from "./GlobalEventEmitter";
@@ -10,7 +7,9 @@ exports.globalEventEmitter = void 0;
10
7
  // });
11
8
  ////////////////////////////////////////////////////////////////
12
9
  class GlobalEventEmitter {
13
- events = {};
10
+ constructor() {
11
+ this.events = {};
12
+ }
14
13
  // Register an event listener
15
14
  on(event, handler) {
16
15
  if (!this.events[event]) {
@@ -32,4 +31,4 @@ class GlobalEventEmitter {
32
31
  }
33
32
  }
34
33
  // Export a singleton instance
35
- exports.globalEventEmitter = new GlobalEventEmitter();
34
+ export const globalEventEmitter = new GlobalEventEmitter();
@@ -1,10 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalize = capitalize;
4
- exports.lowercase = lowercase;
5
- function capitalize(text) {
1
+ export function capitalize(text) {
6
2
  return text.charAt(0).toUpperCase() + text.slice(1);
7
3
  }
8
- function lowercase(text) {
4
+ export function lowercase(text) {
9
5
  return text.toLowerCase();
10
6
  }
@@ -1,19 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Utils = exports.emailRegexp = void 0;
4
- const globalEventHandler_1 = require("./globalEventHandler");
5
- exports.emailRegexp = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
6
- class Utils {
7
- static rowsPerPage = [
8
- { value: "5", label: "5" },
9
- { value: "10", label: "10" },
10
- { value: "15", label: "15" },
11
- { value: "20", label: "20" },
12
- { value: "50", label: "50" },
13
- { value: "100", label: "100" },
14
- { value: "500", label: "500" },
15
- { value: "1000", label: "1000" }
16
- ];
1
+ import { globalEventEmitter } from "./globalEventHandler";
2
+ export const emailRegexp = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/;
3
+ export class Utils {
17
4
  static nl2br(str, is_xhtml) {
18
5
  const breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br ' + '/>' : '<br>'; // Adjust comment to avoid issue on phpjs.org display
19
6
  return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
@@ -130,10 +117,10 @@ class Utils {
130
117
  static copyToClipboard(val, message = 'Text copied') {
131
118
  navigator.clipboard.writeText(val)
132
119
  .then(() => {
133
- globalEventHandler_1.globalEventEmitter.emit("clipboard", { type: "success", message: "Text copied" });
120
+ globalEventEmitter.emit("clipboard", { type: "success", message: "Text copied" });
134
121
  })
135
122
  .catch((error) => {
136
- globalEventHandler_1.globalEventEmitter.emit("clipboard", { type: "danger", message: `${error.message}` });
123
+ globalEventEmitter.emit("clipboard", { type: "danger", message: `${error.message}` });
137
124
  });
138
125
  }
139
126
  // Check if a value is set
@@ -194,18 +181,19 @@ class Utils {
194
181
  }
195
182
  //String manipulations from JSON data
196
183
  static formatStringFromArray(dataArray, field = 'title', languageCode = 'en') {
184
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
197
185
  let strValue = '';
198
186
  for (const contentData of dataArray) {
199
187
  let val = '';
200
188
  switch (field) {
201
189
  case 'title':
202
- val = languageCode == 'en' ? contentData?.title?.en ?? '' : contentData?.title?.mm ?? '';
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 : '';
203
191
  break;
204
192
  case 'name':
205
- val = languageCode == 'en' ? contentData?.name?.en ?? '' : contentData?.name?.mm ?? '';
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 : '';
206
194
  break;
207
195
  default:
208
- val = languageCode == 'en' ? contentData?.title?.en ?? '' : contentData?.title?.mm ?? '';
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 : '';
209
197
  break;
210
198
  }
211
199
  if (val != '') {
@@ -219,4 +207,13 @@ class Utils {
219
207
  return new Promise((resolve) => setTimeout(resolve, ms));
220
208
  }
221
209
  }
222
- exports.Utils = Utils;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jd_platform_sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",