zmp-sdk 2.19.1 → 2.21.0-rc

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.
@@ -2067,6 +2067,9 @@
2067
2067
 
2068
2068
  var set_1 = set;
2069
2069
 
2070
+ const isPromise = (obj) => !!obj &&
2071
+ (typeof obj === 'object' || typeof obj === 'function') &&
2072
+ typeof obj.then === 'function';
2070
2073
  var _ = {
2071
2074
  isEmpty: isEmpty_1,
2072
2075
  isNull: isNull_1,
@@ -2078,7 +2081,8 @@
2078
2081
  isArray: isArray_1,
2079
2082
  isRegExp: isRegExp_1,
2080
2083
  get: get_1,
2081
- set: set_1
2084
+ set: set_1,
2085
+ isPromise,
2082
2086
  };
2083
2087
 
2084
2088
  function Debug(name) {
@@ -2150,13 +2154,6 @@
2150
2154
  (function (VibrateType) {
2151
2155
  VibrateType[VibrateType["oneShot"] = 0] = "oneShot";
2152
2156
  })(VibrateType || (VibrateType = {}));
2153
- var NativeCode;
2154
- (function (NativeCode) {
2155
- NativeCode[NativeCode["token_invalid"] = -2] = "token_invalid";
2156
- NativeCode[NativeCode["not_permission"] = -1] = "not_permission";
2157
- NativeCode[NativeCode["client_not_support"] = -5] = "client_not_support";
2158
- NativeCode[NativeCode["decode_failed"] = -4] = "decode_failed";
2159
- })(NativeCode || (NativeCode = {}));
2160
2157
  var Events;
2161
2158
  (function (Events) {
2162
2159
  Events["AppPaused"] = "h5.event.paused";
@@ -2164,6 +2161,7 @@
2164
2161
  Events["NetworkChanged"] = "h5.event.connection.changed";
2165
2162
  Events["OnDataCallback"] = "h5.event.webview.result";
2166
2163
  Events["OpenApp"] = "h5.event.open.mp";
2164
+ Events["AppClose"] = "h5.event.action.close";
2167
2165
  })(Events || (Events = {}));
2168
2166
  var MediaPickerType;
2169
2167
  (function (MediaPickerType) {
@@ -2243,7 +2241,8 @@
2243
2241
  ZOAUTH: `h5.zdn.vn_zoauth`,
2244
2242
  ZACC_SESSiON: `h5.zdn.vn_zacc_session`,
2245
2243
  JS_TOKEN: `h5.zdn.vn_zlink3rd`,
2246
- ZOAUTH_VRF: `h5.zdn.vn_zoauth_vrf`
2244
+ ZOAUTH_VRF: `h5.zdn.vn_zoauth_vrf`,
2245
+ DEVICE_ID: `h5.zdn.vn_deviceID`
2247
2246
  };
2248
2247
  const APIS = {
2249
2248
  GET_USER_INFO: 'https://graph.zalo.me/v2.0/me',
@@ -2251,6 +2250,8 @@
2251
2250
  GET_ACCESS_TOKEN_V3: 'https://oauth.zaloapp.com/v3/access_token',
2252
2251
  GET_LIST_USER_INFO: 'https://graph.zalo.me/v2.0/me/friends/list',
2253
2252
  CREATE_ORDER: 'https://payment-mini.zalo.me/api/order/create',
2253
+ GET_APP_INFO: 'https://h5.zalo.me/apps/get-info',
2254
+ SEND_ACTION_LOG: 'https://h5.zalo.me/log/async'
2254
2255
  };
2255
2256
  const STORAGE_LIMIT = 5 * MB;
2256
2257
  const NETWORK_TYPE = (isAndroid) => ({
@@ -2261,6 +2262,78 @@
2261
2262
  '4G': isAndroid ? 13 : 2
2262
2263
  });
2263
2264
  const MEDIA_PICKER_LIMIT = 1 * MB;
2265
+ const RESPONSE_CODE = {
2266
+ SUCCESS: 0,
2267
+ UNKNOWN_ERROR: -2000,
2268
+ BAD_REQUEST: -1400,
2269
+ INTERNAL_SERVER_ERROR: -1500,
2270
+ UNAUTHORIZED: -1401,
2271
+ FORBIDDEN: -1403,
2272
+ CLIENT_NOT_SUPPORT: -1404,
2273
+ TIME_OUT: -1408,
2274
+ DECODE_FAILED: -2001,
2275
+ USER_DENIED: -2002,
2276
+ USER_CANCEL: -2003,
2277
+ // Media picker
2278
+ MEDIA_PICKER_FAIL: -2004,
2279
+ // Save image to gallery
2280
+ SAVE_IMAGE_FAIL: -2005
2281
+ };
2282
+ const MESSAGES = {
2283
+ SUCCESS: 'Success',
2284
+ UNKNOWN_ERROR: 'Unknown error. Please try again later.',
2285
+ TIME_OUT: 'Request timeout. Please try again later.',
2286
+ LOGIN_REQUIRED: 'Please login (https://miniapp.zalo.me/docs/api/login) before to call this api',
2287
+ LOGIN_FAILED: 'Login failed',
2288
+ NOT_PERMISSION: `You don't have permission to call this api`,
2289
+ CLIENT_NOT_SUPPORT: `This API is not supported in this Zalo version`,
2290
+ DECODE_FAILED: 'Can not decode id. Please check your params again.',
2291
+ INVALID_PARAM: 'Invalid parameter',
2292
+ USER_DENIED: 'User denied',
2293
+ USER_CANCEL: 'User cancel',
2294
+ // Media picker
2295
+ MEDIA_PICKER_FAIL: 'Unable to pick media',
2296
+ // Save image to gallery
2297
+ SAVE_IMAGE_FAIL: 'Unable to save image'
2298
+ };
2299
+ const RESPONSE = {
2300
+ SUCCESS: {
2301
+ code: RESPONSE_CODE.SUCCESS,
2302
+ message: MESSAGES.SUCCESS
2303
+ },
2304
+ UNKNOWN_ERROR: {
2305
+ code: RESPONSE_CODE.UNKNOWN_ERROR,
2306
+ message: MESSAGES.UNKNOWN_ERROR
2307
+ },
2308
+ UNAUTHORIZED: {
2309
+ code: RESPONSE_CODE.UNAUTHORIZED,
2310
+ message: MESSAGES.LOGIN_REQUIRED
2311
+ },
2312
+ FORBIDDEN: {
2313
+ code: RESPONSE_CODE.FORBIDDEN,
2314
+ message: MESSAGES.NOT_PERMISSION
2315
+ },
2316
+ CLIENT_NOT_SUPPORT: {
2317
+ code: RESPONSE_CODE.CLIENT_NOT_SUPPORT,
2318
+ message: MESSAGES.CLIENT_NOT_SUPPORT
2319
+ },
2320
+ DECODE_FAILED: {
2321
+ code: RESPONSE_CODE.DECODE_FAILED,
2322
+ message: MESSAGES.DECODE_FAILED
2323
+ },
2324
+ TIME_OUT: {
2325
+ code: RESPONSE_CODE.TIME_OUT,
2326
+ message: MESSAGES.TIME_OUT
2327
+ },
2328
+ USER_DENIED: {
2329
+ code: RESPONSE_CODE.USER_DENIED,
2330
+ message: MESSAGES.USER_DENIED
2331
+ },
2332
+ USER_CANCEL: {
2333
+ code: RESPONSE_CODE.USER_CANCEL,
2334
+ message: MESSAGES.USER_CANCEL
2335
+ }
2336
+ };
2264
2337
  const ACTION = {
2265
2338
  GET_DOWNLOADED_STICKER: {
2266
2339
  name: 'action.get.downloaded.sticker',
@@ -2373,7 +2446,19 @@
2373
2446
  have_callback: true
2374
2447
  },
2375
2448
  REQUEST_PERMISSION_CAMERA: {
2376
- name: 'action.request.permission.camera'
2449
+ name: 'action.request.permission.camera',
2450
+ error_list: {
2451
+ android: {
2452
+ '-2': {
2453
+ map_to: RESPONSE.USER_DENIED
2454
+ }
2455
+ },
2456
+ iOS: {
2457
+ '-2': {
2458
+ map_to: RESPONSE.USER_DENIED
2459
+ }
2460
+ }
2461
+ }
2377
2462
  },
2378
2463
  CHANGE_TITLE_HEADER: {
2379
2464
  name: 'action.change.title.header',
@@ -2442,7 +2527,19 @@
2442
2527
  },
2443
2528
  GET_LOCATION: {
2444
2529
  name: 'action.get.location',
2445
- have_callback: true
2530
+ have_callback: true,
2531
+ error_list: {
2532
+ android: {
2533
+ '-1': {
2534
+ map_to: RESPONSE.USER_DENIED
2535
+ }
2536
+ },
2537
+ iOS: {
2538
+ '-1': {
2539
+ map_to: RESPONSE.USER_DENIED
2540
+ }
2541
+ }
2542
+ }
2446
2543
  },
2447
2544
  QUERY_LOCATION_HIDE: {
2448
2545
  name: 'action.query.location.hide',
@@ -2540,7 +2637,34 @@
2540
2637
  },
2541
2638
  SAVE_IMAGE_GALLERY: {
2542
2639
  name: 'action.save.image.gallery',
2543
- version_live: { iOS: 408 }
2640
+ version_live: { iOS: 408 },
2641
+ error_list: {
2642
+ android: {
2643
+ '-101': {
2644
+ map_to: {
2645
+ code: RESPONSE_CODE.SAVE_IMAGE_FAIL,
2646
+ message: MESSAGES.SAVE_IMAGE_FAIL
2647
+ },
2648
+ need_more_detail: true
2649
+ },
2650
+ '-102': {
2651
+ map_to: {
2652
+ code: RESPONSE_CODE.SAVE_IMAGE_FAIL,
2653
+ message: MESSAGES.SAVE_IMAGE_FAIL
2654
+ },
2655
+ need_more_detail: true
2656
+ }
2657
+ },
2658
+ iOS: {
2659
+ '-10': {
2660
+ map_to: {
2661
+ code: RESPONSE_CODE.SAVE_IMAGE_FAIL,
2662
+ message: MESSAGES.SAVE_IMAGE_FAIL
2663
+ },
2664
+ need_more_detail: true
2665
+ }
2666
+ }
2667
+ }
2544
2668
  },
2545
2669
  OPEN_MP: {
2546
2670
  name: 'action.open.mp',
@@ -2561,11 +2685,41 @@
2561
2685
  },
2562
2686
  MP_GET_NUMBER: {
2563
2687
  name: 'action.mp.get.number',
2564
- version_live: { iOS: 416 }
2688
+ version_live: { iOS: 416 },
2689
+ error_list: {
2690
+ android: {
2691
+ '-1': {
2692
+ map_to: RESPONSE.USER_DENIED
2693
+ },
2694
+ '-101': {
2695
+ map_to: RESPONSE.USER_DENIED
2696
+ }
2697
+ },
2698
+ iOS: {
2699
+ '-1': {
2700
+ map_to: RESPONSE.USER_DENIED
2701
+ },
2702
+ '-10': {
2703
+ map_to: RESPONSE.USER_DENIED
2704
+ }
2705
+ }
2706
+ }
2565
2707
  },
2566
2708
  MP_OPEN_PROFILE_PICKER: {
2567
2709
  name: 'action.mp.open.profile.picker',
2568
- version_live: { iOS: 432 }
2710
+ version_live: { iOS: 432 },
2711
+ error_list: {
2712
+ android: {
2713
+ '-101': {
2714
+ map_to: RESPONSE.USER_CANCEL
2715
+ }
2716
+ },
2717
+ iOS: {
2718
+ '-101': {
2719
+ map_to: RESPONSE.USER_CANCEL
2720
+ }
2721
+ }
2722
+ }
2569
2723
  },
2570
2724
  GET_SUPPORTED_ACTIONS: {
2571
2725
  name: 'action.get.supported.actions',
@@ -2579,32 +2733,45 @@
2579
2733
  },
2580
2734
  PICK_MEDIA: {
2581
2735
  name: 'action.pick.media',
2582
- version_live: { iOS: 440 }
2736
+ version_live: { iOS: 440 },
2737
+ error_list: {
2738
+ android: {
2739
+ '-101': {
2740
+ map_to: RESPONSE.USER_CANCEL
2741
+ },
2742
+ '999': {
2743
+ map_to: {
2744
+ code: RESPONSE_CODE.MEDIA_PICKER_FAIL,
2745
+ message: MESSAGES.MEDIA_PICKER_FAIL
2746
+ },
2747
+ need_more_detail: true
2748
+ }
2749
+ },
2750
+ iOS: {
2751
+ '-10': {
2752
+ map_to: {
2753
+ code: RESPONSE_CODE.MEDIA_PICKER_FAIL,
2754
+ message: MESSAGES.MEDIA_PICKER_FAIL
2755
+ }
2756
+ }
2757
+ }
2758
+ }
2583
2759
  },
2584
2760
  MP_CLOSE_LOADINGVIEW: {
2585
2761
  name: 'action.mp.close.loadingview'
2586
2762
  }
2587
2763
  };
2588
- const RESPONSE_CODE = {
2589
- SUCCESS: 0,
2590
- BAD_REQUEST: -1400,
2591
- INTERNAL_SERVER_ERROR: -1500,
2592
- UNAUTHORIZED: -1401,
2593
- FORBIDDEN: -1403,
2594
- CLIENT_NOT_SUPPORT: -1404
2595
- };
2596
- const MESSAGES = {
2597
- SUCCESS: 'Success',
2598
- READ_MORE: 'Read more at: https://miniapp.zalo.me/docs/api',
2599
- LOGIN_REQUIRED: 'Please login before to call this api. Read more at: https://miniapp.zalo.me/docs/api/login',
2600
- LOGIN_FAILED: 'Login failed.',
2601
- NOT_PERMISSION: `You don't have permission to call this api`,
2602
- CLIENT_NOT_SUPPORT: `This API is not supported in this Zalo version`,
2603
- DECODE_FAILED: 'Can not decode your data. Read more at: https://miniapp.zalo.me/docs/api/error'
2604
- };
2605
- const API_DOMAIN = 'https://h5.zalo.me/';
2606
- const H5_API = {
2607
- GET_APP_INFO: 'apps/get-info'
2764
+ const COMMON_NATIVE_ERROR_CODE = {
2765
+ android: {
2766
+ '-4': RESPONSE.DECODE_FAILED,
2767
+ '-5': RESPONSE.CLIENT_NOT_SUPPORT,
2768
+ '-14': RESPONSE.TIME_OUT
2769
+ },
2770
+ iOS: {
2771
+ '-9': RESPONSE.DECODE_FAILED,
2772
+ '-5': RESPONSE.CLIENT_NOT_SUPPORT,
2773
+ '-14': RESPONSE.TIME_OUT
2774
+ }
2608
2775
  };
2609
2776
  const ZALO_SUPPORT_STORAGE_VERSION = {
2610
2777
  android: 12100571,
@@ -2716,124 +2883,36 @@
2716
2883
  };
2717
2884
  const PAYMENT_H5_URL = 'https://payment-mini.zalo.me';
2718
2885
 
2719
- class CommonError {
2886
+ class AppError {
2720
2887
  constructor(code, msg, api) {
2721
2888
  this.code = code;
2722
2889
  this.message = msg;
2723
2890
  this.api = api;
2724
2891
  }
2725
2892
  toString() {
2726
- return `api: ${this.api}; code: ${this.code}; message: ${this.message}`;
2893
+ return `api: ${String(this.api)}; code: ${this.code}; message: ${this.message}`;
2727
2894
  }
2728
- }
2729
- class NativeError extends CommonError {
2730
- constructor(code, msg) {
2731
- super(code, msg);
2732
- this.message = `${msg}. ${MESSAGES.READ_MORE}`;
2733
- this.handler();
2734
- }
2735
- handler() {
2736
- switch (this.code) {
2737
- case NativeCode.token_invalid:
2738
- this.code = RESPONSE_CODE.UNAUTHORIZED;
2739
- this.message = MESSAGES.LOGIN_REQUIRED;
2740
- break;
2741
- case NativeCode.not_permission:
2742
- this.code = RESPONSE_CODE.FORBIDDEN;
2743
- this.message = MESSAGES.NOT_PERMISSION;
2744
- break;
2745
- case NativeCode.client_not_support:
2746
- this.code = RESPONSE_CODE.CLIENT_NOT_SUPPORT;
2747
- this.message = MESSAGES.CLIENT_NOT_SUPPORT;
2748
- break;
2749
- case NativeCode.decode_failed:
2750
- this.message = MESSAGES.DECODE_FAILED;
2751
- break;
2752
- }
2895
+ toJSON() {
2896
+ return {
2897
+ code: this.code,
2898
+ message: this.message,
2899
+ api: this.api
2900
+ };
2753
2901
  }
2754
2902
  }
2755
- const catchDecoratorStore = {
2756
- handler: null,
2757
- setHandler(handler) {
2758
- this.handler = handler;
2759
- }
2903
+ const handleKnownExceptions = (error, api) => {
2904
+ error.api = api;
2905
+ return error.toJSON();
2760
2906
  };
2761
- const errorHandler = (api, error) => {
2762
- if (error instanceof CommonError) {
2763
- error.api = api;
2764
- return error;
2907
+ const handleUnknownExceptions = (error, api) => {
2908
+ if (error instanceof Error) {
2909
+ return new AppError(RESPONSE_CODE.UNKNOWN_ERROR, error.message, api).toJSON();
2765
2910
  }
2766
- return new CommonError(-2001, _.isNull(error.message) ? 'Unknown Error' : error.message, api);
2767
- };
2768
- catchDecoratorStore.setHandler(errorHandler);
2769
- const handleError = (target, propertyName, descriptor) => {
2770
- const fn = descriptor.value;
2771
- descriptor.value = function (...args) {
2772
- return __awaiter(this, void 0, void 0, function* () {
2773
- const { success, fail } = Array.isArray(args) && args.length > 0 && args[0];
2774
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
2775
- try {
2776
- const res = yield fn.apply(this, args);
2777
- if (!_.isNull(success) && _.isFunction(success)) {
2778
- success.call(null, res, this);
2779
- }
2780
- else {
2781
- resolve(res);
2782
- }
2783
- }
2784
- catch (error) {
2785
- if ((error === null || error === void 0 ? void 0 : error.api) !== 'login' && // login is not error
2786
- ((error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.UNAUTHORIZED ||
2787
- (error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.FORBIDDEN)) {
2788
- let loggedIn = false;
2789
- if (this instanceof SDKCreator) {
2790
- loggedIn = this.getLoginStatus();
2791
- }
2792
- if (!loggedIn) {
2793
- error = new CommonError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED);
2794
- }
2795
- }
2796
- const { handler } = catchDecoratorStore;
2797
- const errorParsed = handler.call(null, propertyName, error, this);
2798
- window.zmpSentry && window.zmpSentry.throwError(errorParsed.toString());
2799
- if (!_.isNull(fail) && _.isFunction(fail)) {
2800
- fail.call(null, errorParsed, this);
2801
- }
2802
- else {
2803
- reject(errorParsed);
2804
- }
2805
- }
2806
- }));
2807
- });
2808
- };
2809
- return descriptor;
2911
+ return new AppError(RESPONSE_CODE.UNKNOWN_ERROR, MESSAGES.UNKNOWN_ERROR, api).toJSON();
2810
2912
  };
2811
- const handleErrorSync = (target, key, descriptor) => {
2812
- const fn = descriptor.value;
2813
- descriptor.value = function (...args) {
2814
- try {
2815
- return fn.apply(this, args);
2816
- }
2817
- catch (error) {
2818
- if ((error === null || error === void 0 ? void 0 : error.api) !== 'login' && // login is not error
2819
- ((error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.UNAUTHORIZED ||
2820
- (error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.FORBIDDEN)) {
2821
- let loggedIn = false;
2822
- if (this instanceof SDKCreator) {
2823
- loggedIn = this.getLoginStatus();
2824
- }
2825
- if (!loggedIn) {
2826
- error = new CommonError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED);
2827
- }
2828
- }
2829
- const { handler } = catchDecoratorStore;
2830
- const errorParsed = handler.call(null, key, error, this);
2831
- window.zmpSentry && window.zmpSentry.throwError(errorParsed.toString());
2832
- throw errorParsed;
2833
- }
2834
- };
2835
- return descriptor;
2836
- };
2913
+ const errorHandler = (error, api) => error instanceof AppError
2914
+ ? handleKnownExceptions(error, api)
2915
+ : handleUnknownExceptions(error, api);
2837
2916
 
2838
2917
  const apiResponse = {
2839
2918
  success: (data, message) => ({
@@ -2842,13 +2921,13 @@
2842
2921
  data: data || {}
2843
2922
  }),
2844
2923
  error: {
2845
- badRequest: (message) => new CommonError(RESPONSE_CODE.BAD_REQUEST, message),
2846
- loginFailed: () => new CommonError(RESPONSE_CODE.BAD_REQUEST, MESSAGES.LOGIN_FAILED),
2847
- loginRequired: () => new CommonError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED),
2848
- missingParam: (params) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Missing required argument: ${params}`),
2849
- wrongTypeParam: (arg, expected, got) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Wrong type of parameter '${arg}'. Expected ${expected}, but got ${got}`),
2850
- cannotGetShareInfo: () => new CommonError(RESPONSE_CODE.INTERNAL_SERVER_ERROR, `Can not get app info to share`),
2851
- lengthInvalid: (arg) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`),
2924
+ badRequest: (message) => new AppError(RESPONSE_CODE.BAD_REQUEST, message),
2925
+ loginFailed: (message) => new AppError(RESPONSE_CODE.UNAUTHORIZED, `${MESSAGES.LOGIN_FAILED}: ${message}`),
2926
+ loginRequired: () => new AppError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED),
2927
+ missingParam: (params) => new AppError(RESPONSE_CODE.BAD_REQUEST, `Missing required argument: ${params}`),
2928
+ wrongTypeParam: (arg, expected, got) => new AppError(RESPONSE_CODE.BAD_REQUEST, `Wrong type of parameter '${arg}'. Expected ${expected}, but got ${got}`),
2929
+ cannotGetShareInfo: () => new AppError(RESPONSE_CODE.INTERNAL_SERVER_ERROR, `Can not get app info to share`),
2930
+ lengthInvalid: (arg) => new AppError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`)
2852
2931
  }
2853
2932
  };
2854
2933
 
@@ -3088,7 +3167,8 @@
3088
3167
  const formattedStr = str
3089
3168
  .replace(/\n/g, '\\n')
3090
3169
  .replace(/\r/g, '\\r')
3091
- .replace(/\t/g, '\\t');
3170
+ .replace(/\t/g, '\\t')
3171
+ .replace(/\x00/g, '');
3092
3172
  return JSON.parse(formattedStr, (key, value) => {
3093
3173
  return value;
3094
3174
  });
@@ -3262,7 +3342,7 @@
3262
3342
  if (!_.isUndefined(currentVersion)) {
3263
3343
  inputData.currentVersion = currentVersion;
3264
3344
  }
3265
- const api = QueryString.appendToUrl(`${API_DOMAIN}${H5_API.GET_APP_INFO}`, inputData);
3345
+ const api = QueryString.appendToUrl(APIS.GET_APP_INFO, inputData);
3266
3346
  const msgApi = yield fetch(api, {
3267
3347
  credentials: 'include'
3268
3348
  });
@@ -3654,504 +3734,97 @@
3654
3734
  }
3655
3735
  }
3656
3736
 
3657
- var wrappers = {};
3658
- var WrapperFn = function wrapFunction(fn, type, source) {
3659
- var t = type || 'default';
3660
- return function () {
3661
- var callee = t in wrappers ? wrappers[t](fn, source) : fn;
3662
- return callee.apply(this, arguments);
3663
- };
3664
- };
3665
- WrapperFn.setWrapper = function (fn) {
3666
- var type = arguments.length <= 1 || arguments[1] === undefined
3667
- ? 'default'
3668
- : arguments[1];
3669
- wrappers[type] = fn;
3670
- };
3671
- var ERROR = {
3672
- error: {
3673
- code: 1,
3674
- error_subcode: 1357046,
3675
- message: 'Received Invalid JSON reply.',
3676
- type: 'http'
3677
- }
3678
- };
3679
- function safelyParseResponse(rawResponse) {
3680
- try {
3681
- return rawResponse === null ? ERROR : JSON.parse(rawResponse);
3682
- }
3683
- catch (ex) {
3684
- return ERROR;
3737
+ var version = "2.21.0-rc";
3738
+
3739
+ class Basics {
3740
+ /**
3741
+ * Lấy version hiện tại của Zalo Mini Program SDK
3742
+ *
3743
+ * @category Basics
3744
+ *
3745
+ * @returns {string} Version hiện tại của Zalo Mini Program SDK.
3746
+ */
3747
+ static getVersion() {
3748
+ return version;
3685
3749
  }
3686
- }
3687
- function createCORSRequest(method, url) {
3688
- if (!self.XMLHttpRequest) {
3689
- return null;
3750
+ /**
3751
+ * Gets system information.
3752
+ *
3753
+ * @function getSystemInfo
3754
+ * @category Basics
3755
+ *
3756
+ *
3757
+ *
3758
+ */
3759
+ static getSystemInfo() {
3760
+ const system = {
3761
+ version: getMetaValue('version-id') || '',
3762
+ apiVersion: version,
3763
+ zaloVersion: getZaloVersion(),
3764
+ platform: getPlatform(),
3765
+ language: navigator.language,
3766
+ zaloLanguage: window.zLanguage || 'vi',
3767
+ zaloTheme: window.zTheme || 'light'
3768
+ };
3769
+ return system;
3690
3770
  }
3691
- var xhr = new XMLHttpRequest();
3692
- var noop = function noop() { };
3693
- if ('withCredentials' in xhr) {
3694
- xhr.open(method, url, true);
3695
- xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
3771
+ /**
3772
+ * Lấy thông tin mini app
3773
+ *
3774
+ * @async
3775
+ * @function getAppInfo
3776
+ * @category Device
3777
+ *
3778
+ */
3779
+ static getAppInfo() {
3780
+ return __awaiter(this, void 0, void 0, function* () {
3781
+ const appId = this.getAppId();
3782
+ const systemInfo = this.getSystemInfo();
3783
+ return yield getAppInfo(appId, 0, systemInfo.version);
3784
+ });
3696
3785
  }
3697
- else {
3698
- return null;
3699
- }
3700
- var wrapper = {
3701
- send: function send(data) {
3702
- xhr.send(data);
3703
- }
3704
- };
3705
- var onload = WrapperFn(function () {
3706
- onload = noop;
3707
- if ('onload' in wrapper) {
3708
- wrapper.onload(xhr);
3709
- }
3710
- }, 'entry', 'XMLHttpRequest:load');
3711
- var onerror = WrapperFn(function () {
3712
- onerror = noop;
3713
- if ('onerror' in wrapper) {
3714
- wrapper.onerror(xhr);
3715
- }
3716
- }, 'entry', 'XMLHttpRequest:error');
3717
- xhr.onload = function () {
3718
- onload();
3719
- };
3720
- xhr.onerror = function () {
3721
- onerror();
3722
- };
3723
- xhr.onreadystatechange = function () {
3724
- if (xhr.readyState == 4) {
3725
- if (xhr.status == 200) {
3726
- onload();
3727
- }
3728
- else {
3729
- onerror();
3730
- }
3731
- }
3732
- };
3733
- return wrapper;
3734
- }
3735
- function execute(url, method, params, cb) {
3736
- params.suppress_http_code = 1;
3737
- var data = QueryString.encode(params);
3738
- if (method != 'post') {
3739
- url = QueryString.appendToUrl(url, data);
3740
- data = '';
3741
- }
3742
- var request = createCORSRequest(method, url);
3743
- if (!request) {
3744
- return false;
3745
- }
3746
- request.onload = function (xhr) {
3747
- cb(safelyParseResponse(xhr.responseText));
3748
- };
3749
- request.onerror = function (xhr) {
3750
- if (xhr.responseText) {
3751
- cb(safelyParseResponse(xhr.responseText));
3752
- }
3753
- else {
3754
- cb({
3755
- error: {
3756
- code: 1,
3757
- error_subcode: 1357045,
3758
- message: 'unknown error (empty response)',
3759
- status: xhr.status,
3760
- type: 'http'
3761
- }
3762
- });
3763
- }
3764
- };
3765
- request.send(data);
3766
- return true;
3767
- }
3768
- var CORSRequest = {
3769
- execute: execute
3770
- };
3771
-
3772
- class ZaloJSBridge extends eventemitter3 {
3773
- constructor() {
3774
- super();
3775
- this.debug = Debug('zmp:ZaloJSBridge');
3776
- this.events = ZMPEEmitter.getInstance();
3777
- this._accessTk = getToken('zacc_session') || 'DEFAULT_ACCESS_TOKEN';
3778
- this._jsAccessTk = getToken('zlink3rd') || 'DEFAULT_JS_TOKEN';
3779
- this.results = [];
3780
- this._userAgent = getUserAgent();
3781
- this._device = checkPlatform();
3782
- this._jsCallFuncCallbacks = {};
3783
- this.events.on(Events.AppPaused, () => {
3784
- if (this.results.length > 0) {
3785
- let array = this.results;
3786
- this.results = [];
3787
- try {
3788
- this.sendLogData(array);
3789
- }
3790
- catch (error) { }
3791
- }
3792
- });
3793
- if (this.sendLogTimer) {
3794
- clearInterval(this.sendLogTimer);
3795
- }
3796
- else {
3797
- this.sendLogTimer = setInterval(() => {
3798
- if (this.results.length > 0) {
3799
- let array = this.results;
3800
- this.results = [];
3801
- try {
3802
- this.sendLogData(array);
3803
- }
3804
- catch (error) { }
3805
- }
3806
- }, 5000);
3807
- }
3808
- }
3809
- static getInstance() {
3810
- if (!ZaloJSBridge.instance) {
3811
- ZaloJSBridge.instance = new ZaloJSBridge();
3812
- }
3813
- return ZaloJSBridge.instance;
3814
- }
3815
- set accessTk(value) {
3816
- this._accessTk = value;
3817
- }
3818
- set jsAccessTk(value) {
3819
- this._jsAccessTk = value;
3820
- }
3821
- sendLogData(data) {
3822
- try {
3823
- CORSRequest.execute('https://h5.zalo.me/log/async', 'post', {
3824
- appId: window.APP_ID,
3825
- data: JSON.stringify(data)
3826
- }, (response) => { });
3827
- }
3828
- catch (error) { }
3829
- }
3830
- onJSCall(key, data) {
3831
- try {
3832
- this.debug('onJSCall', key, data);
3833
- const parsedData = parseJSON(data);
3834
- if (this._jsCallFuncCallbacks[key]) {
3835
- const callback = this._jsCallFuncCallbacks[key].callback;
3836
- const timeout = this._jsCallFuncCallbacks[key].timeout;
3837
- if (!!callback) {
3838
- try {
3839
- callback.call(this, parsedData);
3840
- }
3841
- catch (error) {
3842
- console.error('Call callback error', error);
3843
- }
3844
- !!timeout && clearTimeout(timeout);
3845
- this._jsCallFuncCallbacks[key] = null;
3846
- delete this._jsCallFuncCallbacks[key];
3847
- }
3848
- }
3849
- this.results.push({
3850
- action: parsedData.action,
3851
- error: parsedData.error_code
3852
- });
3853
- }
3854
- catch (e) {
3855
- console.log('onJSCall', 'error', e);
3856
- }
3857
- }
3858
- onMultiJSCall(key, data) {
3859
- try {
3860
- this.debug('onMultiJSCall', key, data);
3861
- const parsedData = parseJSON(data);
3862
- if (this._jsCallFuncCallbacks[key]) {
3863
- const callback = this._jsCallFuncCallbacks[key].callback;
3864
- const timeout = this._jsCallFuncCallbacks[key].timeout;
3865
- if (!!callback) {
3866
- try {
3867
- callback.call(this, parsedData);
3868
- }
3869
- catch (error) {
3870
- console.error('Call callback error', error);
3871
- }
3872
- !!timeout && clearTimeout(timeout);
3873
- }
3874
- }
3875
- this.results.push({
3876
- action: parsedData.action,
3877
- error: parsedData.error_code
3878
- });
3879
- }
3880
- catch (e) {
3881
- console.log('onMultiJSCall', 'error', e);
3882
- }
3883
- }
3884
- nativeEventHandler(eventId, eventName, eventData) {
3885
- this.debug(`eventId: ${eventId}, eventName: ${eventName}, eventData: ${eventData}`);
3886
- const data = stringToData(eventData);
3887
- this.debug(data);
3888
- const convertedData = this.handleEventData(eventName, data);
3889
- this.events.emit(eventName, eventId, convertedData);
3890
- }
3891
- handleEventData(eventName, data) {
3892
- try {
3893
- switch (eventName) {
3894
- case Events.OpenApp:
3895
- const { url } = data;
3896
- const validUrl = new URL(url);
3897
- const path = validUrl.pathname.split(`/zapps/${APP_ID}`)[1];
3898
- return {
3899
- path: `${path ? path : '/'}${validUrl.search}`
3900
- };
3901
- break;
3902
- default:
3903
- return data;
3904
- break;
3905
- }
3906
- }
3907
- catch (error) {
3908
- return data;
3909
- }
3910
- }
3911
- defaultCallback(data) {
3912
- if (data !== null && data !== undefined) {
3913
- data = parseJSON(data);
3914
- }
3915
- }
3916
- jsCall(action, options, callback, isMultiCallback = false, nRetry = 3, haveTimeout = true) {
3917
- try {
3918
- const actionName = action.name;
3919
- const key = generateUniqueString(actionName);
3920
- if (!this._device.isMobile || _.isEmpty(actionName)) {
3921
- this.onJSCall(key, {
3922
- error_code: -13,
3923
- error_message: 'params invalid!',
3924
- data: {
3925
- device: this._device.isMobile,
3926
- jsToken: this._jsAccessTk,
3927
- access_token: this._accessTk
3928
- },
3929
- action: actionName
3930
- });
3931
- return false;
3932
- }
3933
- if (options === undefined || options === null) {
3934
- options = {};
3935
- }
3936
- if (!callback) {
3937
- callback = this.defaultCallback;
3938
- }
3939
- const timeoutCallback = {
3940
- error_code: -14,
3941
- error_message: 'Request Timeout!',
3942
- data: {},
3943
- action: actionName
3944
- };
3945
- this._jsCallFuncCallbacks[key] = {
3946
- timeout: haveTimeout &&
3947
- action.have_callback &&
3948
- setTimeout(() => {
3949
- this.onJSCall(key, timeoutCallback);
3950
- }, 8000),
3951
- callback: callback
3952
- };
3953
- try {
3954
- options = serialize(options);
3955
- if (isMultiCallback) {
3956
- if (this._device.isIOS) {
3957
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onMultiJSCall(key));
3958
- }
3959
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onMultiJSCall('${key}')`);
3960
- }
3961
- if (this._device.isIOS) {
3962
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onJSCall(key));
3963
- }
3964
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onJSCall('${key}')`);
3965
- }
3966
- catch (error) {
3967
- if (nRetry-- > 0) {
3968
- setTimeout(() => {
3969
- this.jsCall(action, options, callback, isMultiCallback, nRetry);
3970
- }, 500);
3971
- }
3972
- else {
3973
- const errorCallback = {
3974
- error_code: -5,
3975
- error_message: 'Not ready!',
3976
- data: {
3977
- userAgent: this._userAgent,
3978
- options: options,
3979
- jsToken: this._jsAccessTk,
3980
- access_token: this._accessTk
3981
- },
3982
- action: actionName,
3983
- js_error: error
3984
- };
3985
- this.onJSCall(key, errorCallback);
3986
- return false;
3987
- }
3988
- }
3989
- }
3990
- catch (error) {
3991
- console.log('jsCall', 'error', error);
3992
- }
3993
- return false;
3994
- }
3995
- }
3996
-
3997
- var _ZJSBridgeProvider_bridge;
3998
- /** @ignore */
3999
- class ZJSBridgeProvider {
4000
- /** @ignore */
4001
- constructor() {
4002
- this.debug = Debug('zmp:ZJSBridgeProvider');
4003
- _ZJSBridgeProvider_bridge.set(this, void 0);
4004
- __classPrivateFieldSet(this, _ZJSBridgeProvider_bridge, ZaloJSBridge.getInstance(), "f");
4005
- }
4006
- setZAccSession(value) {
4007
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").accessTk = value;
4008
- }
4009
- setJSToken(value) {
4010
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").jsAccessTk = value;
4011
- }
4012
- callNative(action, data, option) {
4013
- this.debug(action.name, data);
4014
- return new Promise((resolve, reject) => {
4015
- const fn = (cb) => __awaiter(this, void 0, void 0, function* () {
4016
- try {
4017
- const error = new NativeError(cb.error_code, `${cb.action}: ${cb.error_message}`);
4018
- if (option === null || option === void 0 ? void 0 : option.callback) {
4019
- const res = yield option.callback(cb, error);
4020
- return resolve(res);
4021
- }
4022
- else {
4023
- if (cb && cb.error_code >= 0) {
4024
- resolve(cb.data || {});
4025
- }
4026
- else if (cb && cb.error_code < 0) {
4027
- try {
4028
- window.zmpSentry &&
4029
- window.zmpSentry.captureMessage(`${action.name}: call native fail`, {
4030
- extra: {
4031
- data: data,
4032
- rs: cb
4033
- }
4034
- });
4035
- }
4036
- catch (error) { }
4037
- return reject(error);
4038
- }
4039
- }
4040
- }
4041
- catch (error) {
4042
- return reject(error);
4043
- }
4044
- });
4045
- const isIOS = checkPlatform().isIOS;
4046
- const isSupportAction = checkIOSSupportAction(action);
4047
- if (isIOS && !isSupportAction) {
4048
- const error = new NativeError(-5, `${action}: Client isn't support this action`);
4049
- return reject(error);
4050
- }
4051
- else if (option === null || option === void 0 ? void 0 : option.delay) {
4052
- setTimeout(() => {
4053
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").jsCall(action, data, fn, option === null || option === void 0 ? void 0 : option.isMultiCallback, option === null || option === void 0 ? void 0 : option.nRetry, option === null || option === void 0 ? void 0 : option.haveTimeout);
4054
- }, option.delay);
4055
- }
4056
- else {
4057
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").jsCall(action, data, fn, option === null || option === void 0 ? void 0 : option.isMultiCallback, option === null || option === void 0 ? void 0 : option.nRetry, option === null || option === void 0 ? void 0 : option.haveTimeout);
4058
- }
4059
- });
4060
- }
4061
- }
4062
- _ZJSBridgeProvider_bridge = new WeakMap();
4063
-
4064
- var version = "2.19.1";
4065
-
4066
- class Basics {
4067
- /**
4068
- * Lấy version hiện tại của Zalo Mini Program SDK
4069
- *
4070
- * @category Basics
4071
- *
4072
- * @returns {string} Version hiện tại của Zalo Mini Program SDK.
4073
- */
4074
- static getVersion() {
4075
- return version;
4076
- }
4077
- /**
4078
- * Gets system information.
4079
- *
4080
- * @function getSystemInfo
4081
- * @category Basics
4082
- *
4083
- *
4084
- *
4085
- */
4086
- static getSystemInfo() {
4087
- const system = {
4088
- version: getMetaValue('version-id') || '',
4089
- apiVersion: version,
4090
- zaloVersion: getZaloVersion(),
4091
- platform: getPlatform(),
4092
- language: navigator.language,
4093
- zaloLanguage: window.zLanguage || 'vi',
4094
- zaloTheme: window.zTheme || 'light'
4095
- };
4096
- return system;
4097
- }
4098
- /**
4099
- * Lấy thông tin mini app
4100
- *
4101
- * @async
4102
- * @function getAppInfo
4103
- * @category Device
4104
- *
4105
- */
4106
- static getAppInfo() {
4107
- return __awaiter(this, void 0, void 0, function* () {
4108
- const appId = this.getAppId();
4109
- const systemInfo = this.getSystemInfo();
4110
- return yield getAppInfo(appId, 0, systemInfo.version);
4111
- });
4112
- }
4113
- }
4114
-
4115
- class NavigationBar {
4116
- /**
4117
- * A promise for the user's favorite color.
4118
- *
4119
- * @promise FavoriteColorPromise
4120
- * @fulfill {string} The user's favorite color.
4121
- * @reject {TypeError} The user's favorite color is an invalid type.
4122
- * @reject {MissingColorError} The user has not specified a favorite color.
4123
- */
4124
- /**
4125
- * Dynamically sets the title of the current page.
4126
- *
4127
- * @async
4128
- * @function setNavigationBarTitle
4129
- * @category Navigation Bar
4130
- *
4131
- * @example
4132
- *
4133
- * zmpApis.setNavigationBarTitle({
4134
- * title: "Current Page"
4135
- * }).then((res) => {
4136
- * console.log("Success");
4137
- * }).catch((error) => {
4138
- * console.log("Fail");
4139
- * });
4140
- *
4141
- * @param {Object} object
4142
- * @param {string} object.title - The title of the page
4143
- *
4144
- * @return {Promise}
4145
- *
4146
- */
4147
- static setNavigationBarTitle(object) {
4148
- return __awaiter(this, void 0, void 0, function* () {
4149
- yield this.callNative(ACTION.CHANGE_TITLE_HEADER, {
4150
- title: object.title
4151
- }, {
4152
- haveTimeout: false
4153
- });
4154
- });
3786
+ }
3787
+
3788
+ class NavigationBar {
3789
+ /**
3790
+ * A promise for the user's favorite color.
3791
+ *
3792
+ * @promise FavoriteColorPromise
3793
+ * @fulfill {string} The user's favorite color.
3794
+ * @reject {TypeError} The user's favorite color is an invalid type.
3795
+ * @reject {MissingColorError} The user has not specified a favorite color.
3796
+ */
3797
+ /**
3798
+ * Dynamically sets the title of the current page.
3799
+ *
3800
+ * @async
3801
+ * @function setNavigationBarTitle
3802
+ * @category Navigation Bar
3803
+ *
3804
+ * @example
3805
+ *
3806
+ * zmpApis.setNavigationBarTitle({
3807
+ * title: "Current Page"
3808
+ * }).then((res) => {
3809
+ * console.log("Success");
3810
+ * }).catch((error) => {
3811
+ * console.log("Fail");
3812
+ * });
3813
+ *
3814
+ * @param {Object} object
3815
+ * @param {string} object.title - The title of the page
3816
+ *
3817
+ * @return {Promise}
3818
+ *
3819
+ */
3820
+ static setNavigationBarTitle(object) {
3821
+ return __awaiter(this, void 0, void 0, function* () {
3822
+ yield this.getJSBridge().callNative(ACTION.CHANGE_TITLE_HEADER, {
3823
+ title: object.title
3824
+ }, {
3825
+ haveTimeout: false
3826
+ });
3827
+ });
4155
3828
  }
4156
3829
  /**
4157
3830
  * Sets the color of the navigation bar in the page.
@@ -4194,7 +3867,7 @@
4194
3867
  actionBarType = HIDE_ACTION_BAR;
4195
3868
  }
4196
3869
  this.setActionBarConfig((state) => (Object.assign(Object.assign({}, state), { actionbarType: actionBarType, dataConfig: Object.assign(Object.assign({}, state.dataConfig), dataConfig) })));
4197
- yield this.callNative(ACTION.CHANGE_ACTIONBAR, Object.assign({}, this.getActionBarConfig()), {
3870
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, Object.assign({}, this.getActionBarConfig()), {
4198
3871
  haveTimeout: false
4199
3872
  });
4200
3873
  });
@@ -4229,62 +3902,32 @@
4229
3902
  * @param {string} [object.dialogMessage="Bạn có muốn thoát?"] - Specifies a message that will be shown on native dialog. Only when ```confirmToExit``` is 1
4230
3903
  * @param {Function} [object.handleCloseEvent] - Specifies a function that will be called when user click close button. Only when ```confirmToExit``` is 2
4231
3904
  */
4232
- static setNavigationBarLeftButton(object) {
4233
- return __awaiter(this, void 0, void 0, function* () {
4234
- const leftButtonType = object.type === 'none' || object.type === 'home'
4235
- ? ACTION_LEFT_BUTTON_TYPE.HIDE_BACK
4236
- : ACTION_LEFT_BUTTON_TYPE.SHOW_BACK;
4237
- const showHomeButton = object.type === 'home' || object.type === 'both'
4238
- ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
4239
- : ACTION_LEFT_BUTTON_TYPE.HIDE_HOME;
4240
- this.setActionBarConfig((state) => (Object.assign(Object.assign({}, state), { buttonType: leftButtonType, dataConfig: Object.assign(Object.assign({}, state.dataConfig), { viewInLeftType: leftButtonType }), homeConfig: Object.assign(Object.assign({}, state.homeConfig), { enable: showHomeButton }) })));
4241
- yield this.callNative(ACTION.CHANGE_ACTIONBAR_LEFTBUTTON_TYPE, Object.assign({}, this.getActionBarConfig()), {
3905
+ static setNavigationBarLeftButton(type, confirmToExit) {
3906
+ return __awaiter(this, void 0, void 0, function* () {
3907
+ let leftButtonType;
3908
+ let showHomeButton;
3909
+ if (_.isString(type)) {
3910
+ leftButtonType =
3911
+ type === 'none' || type === 'home'
3912
+ ? ACTION_LEFT_BUTTON_TYPE.HIDE_BACK
3913
+ : ACTION_LEFT_BUTTON_TYPE.SHOW_BACK;
3914
+ showHomeButton =
3915
+ type === 'home' || type === 'both'
3916
+ ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
3917
+ : ACTION_LEFT_BUTTON_TYPE.HIDE_HOME;
3918
+ }
3919
+ this.setActionBarConfig((state) => (Object.assign(Object.assign({}, state), { buttonType: _.isNumber(leftButtonType) ? leftButtonType : state.buttonType, dataConfig: Object.assign(Object.assign({}, state.dataConfig), { confirmToExit: _.isNumber(confirmToExit) ? confirmToExit : state.dataConfig.confirmToExit, viewInLeftType: _.isNumber(leftButtonType) ? leftButtonType : state.dataConfig.viewInLeftType }), homeConfig: Object.assign(Object.assign({}, state.homeConfig), { enable: _.isNumber(showHomeButton) ? showHomeButton : state.homeConfig.enable }) })));
3920
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR_LEFTBUTTON_TYPE, Object.assign({}, this.getActionBarConfig()), {
4242
3921
  haveTimeout: false
4243
3922
  });
4244
3923
  });
4245
3924
  }
4246
- /**
4247
- * @ignore
4248
- * Dynamically sets the right button of the current page.
4249
- *
4250
- * @ignore
4251
- * @category Navigation Bar
4252
- *
4253
- * @example
4254
- * zmpApis.setNavigationBarRightButton({
4255
- * supportToolBar: 1,
4256
- * reset: 0,
4257
- * menuListItems: [{
4258
- * title: "Post on timeline",
4259
- * action: "zalo.web.internal.postfeed",
4260
- * showAsAction: 0,
4261
- * iconUrl: "https://cdn3.iconfinder.com/data/icons/user-interface-3-3/34/251-512.png",
4262
- * type: 0,
4263
- * data: {}
4264
- * }],
4265
- * }).then((res) => {
4266
- * console.log("Success");
4267
- * }).catch((error) => {
4268
- * console.log("Fail");
4269
- * });
4270
- *
4271
- * @param {Object} object
4272
- * @param {Number} object.title - Title of a menu item
4273
- * @param {Number} object.action - Native action
4274
- * @param {string} object.showAsAction
4275
- * If ```showAsAction``` is 1 and ```iconUrl``` can load,
4276
- * this item will be shown outside and next to more-button. Maximum 2 item will be shown
4277
- * @param {Function} object.iconUrl - Specifies icon of a menu item
4278
- * @param {0} object.type
4279
- * @param {Object} object.data - Data depends on ```action```
4280
- */
4281
- static setNavigationBarRightButton(object) {
3925
+ static setNavigationBar(data) {
4282
3926
  return __awaiter(this, void 0, void 0, function* () {
4283
- yield this.callNative(ACTION.CREATE_OPTIONS_MENU, {
4284
- supportToolBar: object.supportToolBar,
4285
- reset: object.reset,
4286
- menuListItems: object.menuListItems,
4287
- zapp: this.getAppId()
3927
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, {
3928
+ data
3929
+ }, {
3930
+ haveTimeout: false
4288
3931
  });
4289
3932
  });
4290
3933
  }
@@ -4316,7 +3959,7 @@
4316
3959
  return __awaiter(this, void 0, void 0, function* () {
4317
3960
  if (_.isString(object.backgroundColor) &&
4318
3961
  object.backgroundColor.length > 0) {
4319
- yield this.callNative(ACTION.CHANGE_ACTIONBAR, {
3962
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, {
4320
3963
  actionbarType: this.isShowNavBar ? 5 : 6,
4321
3964
  dataConfig: {
4322
3965
  backgroundColor: object.backgroundColor,
@@ -4428,7 +4071,7 @@
4428
4071
  */
4429
4072
  static setDeviceOrientation(object) {
4430
4073
  return __awaiter(this, void 0, void 0, function* () {
4431
- yield this.callNative(ACTION.CHANGE_AUTOROTATE, {
4074
+ yield this.getJSBridge().callNative(ACTION.CHANGE_AUTOROTATE, {
4432
4075
  autoRotate: OrientationType[object.rotate]
4433
4076
  });
4434
4077
  });
@@ -4452,7 +4095,7 @@
4452
4095
  */
4453
4096
  static getNetworkType(object) {
4454
4097
  return __awaiter(this, void 0, void 0, function* () {
4455
- const resData = yield this.callNative(ACTION.WEBVIEW_NETWORKTYPE, {
4098
+ const resData = yield this.getJSBridge().callNative(ACTION.WEBVIEW_NETWORKTYPE, {
4456
4099
  url: window.location.href,
4457
4100
  featureId: ''
4458
4101
  }).then((data) => {
@@ -4566,7 +4209,7 @@
4566
4209
  items: Array.isArray(object === null || object === void 0 ? void 0 : object.items) ? object === null || object === void 0 ? void 0 : object.items : []
4567
4210
  }
4568
4211
  };
4569
- yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4212
+ yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4570
4213
  return true;
4571
4214
  });
4572
4215
  }
@@ -4585,7 +4228,7 @@
4585
4228
  const data = {
4586
4229
  subaction: 2
4587
4230
  };
4588
- yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4231
+ yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4589
4232
  return true;
4590
4233
  });
4591
4234
  }
@@ -4606,7 +4249,7 @@
4606
4249
  const data = {
4607
4250
  subaction: 1
4608
4251
  };
4609
- const resData = yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data), {
4252
+ const resData = yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data), {
4610
4253
  isMultiCallback: true
4611
4254
  }).then((resData) => {
4612
4255
  const res = {
@@ -4648,7 +4291,7 @@
4648
4291
  */
4649
4292
  static stopBluetoothDevicesDiscovery() {
4650
4293
  return __awaiter(this, void 0, void 0, function* () {
4651
- return this.callNative({
4294
+ return this.getJSBridge().callNative({
4652
4295
  name: ''
4653
4296
  }, {});
4654
4297
  });
@@ -4675,7 +4318,7 @@
4675
4318
  */
4676
4319
  static startBluetoothDevicesDiscovery(object) {
4677
4320
  return __awaiter(this, void 0, void 0, function* () {
4678
- return this.callNative({
4321
+ return this.getJSBridge().callNative({
4679
4322
  name: ''
4680
4323
  }, Object.assign({}, object));
4681
4324
  });
@@ -4699,7 +4342,7 @@
4699
4342
  */
4700
4343
  static openBluetoothAdapter() {
4701
4344
  return __awaiter(this, void 0, void 0, function* () {
4702
- return this.callNative({
4345
+ return this.getJSBridge().callNative({
4703
4346
  name: ''
4704
4347
  }, {});
4705
4348
  });
@@ -4719,7 +4362,7 @@
4719
4362
  */
4720
4363
  static onBluetoothDeviceFound() {
4721
4364
  return __awaiter(this, void 0, void 0, function* () {
4722
- return this.callNative({
4365
+ return this.getJSBridge().callNative({
4723
4366
  name: ''
4724
4367
  }, {});
4725
4368
  });
@@ -4767,7 +4410,7 @@
4767
4410
  const data = {
4768
4411
  services: object.services || []
4769
4412
  };
4770
- return this.callNative({
4413
+ return this.getJSBridge().callNative({
4771
4414
  name: ''
4772
4415
  }, data);
4773
4416
  });
@@ -4788,7 +4431,7 @@
4788
4431
  */
4789
4432
  static getBluetoothDevices() {
4790
4433
  return __awaiter(this, void 0, void 0, function* () {
4791
- return this.callNative({
4434
+ return this.getJSBridge().callNative({
4792
4435
  name: ''
4793
4436
  }, {});
4794
4437
  });
@@ -4809,7 +4452,7 @@
4809
4452
  */
4810
4453
  static getBluetoothAdapterState() {
4811
4454
  return __awaiter(this, void 0, void 0, function* () {
4812
- return this.callNative({
4455
+ return this.getJSBridge().callNative({
4813
4456
  name: ''
4814
4457
  }, {});
4815
4458
  });
@@ -4830,7 +4473,7 @@
4830
4473
  */
4831
4474
  static closeBluetoothAdapter() {
4832
4475
  return __awaiter(this, void 0, void 0, function* () {
4833
- return this.callNative({
4476
+ return this.getJSBridge().callNative({
4834
4477
  name: ''
4835
4478
  }, {});
4836
4479
  });
@@ -4844,7 +4487,7 @@
4844
4487
  */
4845
4488
  static scanQRCode(object) {
4846
4489
  return __awaiter(this, void 0, void 0, function* () {
4847
- return yield this.callNative(ACTION.OPEN_QR, {
4490
+ return yield this.getJSBridge().callNative(ACTION.OPEN_QR, {
4848
4491
  skipOpenLink: true
4849
4492
  });
4850
4493
  });
@@ -4858,308 +4501,770 @@
4858
4501
  */
4859
4502
  static showToast(object) {
4860
4503
  return __awaiter(this, void 0, void 0, function* () {
4861
- yield this.callNative(ACTION.SHOW_TOAST, {
4504
+ yield this.getJSBridge().callNative(ACTION.SHOW_TOAST, {
4862
4505
  toast: object.message
4863
4506
  });
4864
4507
  });
4865
4508
  }
4866
- /**
4867
- * Ẩn keyboard
4868
- * @async
4869
- * @function hideKeyboard
4870
- * @category Device
4871
- *
4872
- */
4873
- static hideKeyboard(object) {
4509
+ /**
4510
+ * Ẩn keyboard
4511
+ * @async
4512
+ * @function hideKeyboard
4513
+ * @category Device
4514
+ *
4515
+ */
4516
+ static hideKeyboard(object) {
4517
+ return __awaiter(this, void 0, void 0, function* () {
4518
+ yield this.getJSBridge().callNative(ACTION.HIDE_KEYBOARD, {});
4519
+ });
4520
+ }
4521
+ /**
4522
+ * Open phone
4523
+ * @async
4524
+ * @function openPhone
4525
+ * @category Device
4526
+ *
4527
+ */
4528
+ static openPhone(object) {
4529
+ return __awaiter(this, void 0, void 0, function* () {
4530
+ yield this.getJSBridge().callNative(ACTION.OPEN_PHONE, {
4531
+ phoneNum: object.phoneNumber,
4532
+ phoneCode: object.phoneNumber
4533
+ });
4534
+ });
4535
+ }
4536
+ /**
4537
+ * Open SMS
4538
+ * @async
4539
+ * @function openSMS
4540
+ * @category Device
4541
+ *
4542
+ */
4543
+ static openSMS(object) {
4544
+ return __awaiter(this, void 0, void 0, function* () {
4545
+ yield this.getJSBridge().callNative(ACTION.OPEN_SMS, {
4546
+ content: object.content,
4547
+ phoneCode: object.phoneNumber
4548
+ });
4549
+ });
4550
+ }
4551
+ /**
4552
+ * Keep screen.
4553
+ * @async
4554
+ * @function keepScreen
4555
+ * @category Device
4556
+ *
4557
+ */
4558
+ static keepScreen(object) {
4559
+ return __awaiter(this, void 0, void 0, function* () {
4560
+ return yield this.getJSBridge().callNative(ACTION.KEEP_SCREEN, {
4561
+ data: {
4562
+ keep_screen_on: object.keepScreenOn ? 1 : 0
4563
+ }
4564
+ });
4565
+ });
4566
+ }
4567
+ /**
4568
+ * Xác thực bằng sinh trắc học
4569
+ * @async
4570
+ * @function openBioAuthentication
4571
+ * @category Authentication
4572
+ *
4573
+ */
4574
+ static openBioAuthentication(object) {
4575
+ return __awaiter(this, void 0, void 0, function* () {
4576
+ return yield this.getJSBridge().callNative(ACTION.PROMPT_AUTHENTICATION, {
4577
+ secret_data: object.secretData,
4578
+ app_id: this.getZAppId(),
4579
+ ui: {
4580
+ title: object.ui.title,
4581
+ sub_title: object.ui.subTitle,
4582
+ negative_text: object.ui.negativeButtonText
4583
+ },
4584
+ require_fingerprint: object.requireFingerprint ? 1 : 0
4585
+ }).then((data) => {
4586
+ var _a, _b, _c, _d;
4587
+ return {
4588
+ code: data === null || data === void 0 ? void 0 : data.error_code,
4589
+ message: data === null || data === void 0 ? void 0 : data.error_message,
4590
+ data: {
4591
+ domain: (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.domain,
4592
+ code: (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.error_code,
4593
+ message: (_c = data === null || data === void 0 ? void 0 : data.data) === null || _c === void 0 ? void 0 : _c.error_message,
4594
+ payToken: (_d = data === null || data === void 0 ? void 0 : data.data) === null || _d === void 0 ? void 0 : _d.pay_token
4595
+ }
4596
+ };
4597
+ });
4598
+ });
4599
+ }
4600
+ /**
4601
+ * Một phần của flow H5-Bio-Authentication. Dùng cho H5 kiểm tra xem bio-factor có bị thay đổi gì so với trước đây ko (thêm vân tay, reset...)
4602
+ * @async
4603
+ * @function checkStateBioAuthentication
4604
+ * @category Authentication
4605
+ *
4606
+ * @example
4607
+ * api.checkStateAuthen({
4608
+ * success: (res) => {},
4609
+ * fail: (err) => {}
4610
+ * })
4611
+ * @param {InputDataType.CallbackType} object
4612
+ */
4613
+ static checkStateBioAuthentication(object) {
4614
+ return __awaiter(this, void 0, void 0, function* () {
4615
+ return yield this.getJSBridge().callNative(ACTION.PROMPT_AUTHENTICATION_CHECK_STATE, {}).then((data) => {
4616
+ return {
4617
+ bioState: data === null || data === void 0 ? void 0 : data.bio_state
4618
+ };
4619
+ });
4620
+ });
4621
+ }
4622
+ /**
4623
+ * Vibrate.
4624
+ * @async
4625
+ * @function vibrate
4626
+ * @category Device
4627
+ *
4628
+ */
4629
+ static vibrate(object) {
4630
+ return __awaiter(this, void 0, void 0, function* () {
4631
+ return yield this.getJSBridge().callNative(ACTION.INTERACTIVE_VIBRATION, {
4632
+ type: VibrateType[object.type],
4633
+ vibrate_time: object.milliseconds
4634
+ });
4635
+ });
4636
+ }
4637
+ /**
4638
+ * Connect Wifi.
4639
+ * @async
4640
+ * @function connectWifi
4641
+ * @category Device
4642
+ *
4643
+ */
4644
+ static connectWifi(object) {
4645
+ return __awaiter(this, void 0, void 0, function* () {
4646
+ let securityType = 'open';
4647
+ if (_.isString(object.password) && object.password.length > 0) {
4648
+ securityType = 'wpa_wpa2';
4649
+ }
4650
+ return yield this.getJSBridge().callNative(ACTION.MP_JOIN_WIFI, {
4651
+ ssid: object.SSID,
4652
+ securityType: securityType,
4653
+ password: object.password,
4654
+ hiddenSsid: object.hiddenSSID
4655
+ });
4656
+ });
4657
+ }
4658
+ /**
4659
+ * Open App Store.
4660
+ * @async
4661
+ * @function openAppStore
4662
+ * @category Device
4663
+ *
4664
+ */
4665
+ static openAppStore(object) {
4666
+ return __awaiter(this, void 0, void 0, function* () {
4667
+ return yield this.getJSBridge().callNative(ACTION.OPEN_APPSTORE, object);
4668
+ });
4669
+ }
4670
+ }
4671
+
4672
+ var _LocalResourceStorage_storage, _LocalResourceStorage_prefix, _LocalResourceStorage_resourceInfo;
4673
+ class LocalResourceStorage {
4674
+ constructor(prefix) {
4675
+ _LocalResourceStorage_storage.set(this, localStorage);
4676
+ _LocalResourceStorage_prefix.set(this, void 0);
4677
+ _LocalResourceStorage_resourceInfo.set(this, void 0);
4678
+ checkPlatform();
4679
+ // if (platform.isMobile && platform.isZalo) {
4680
+ // Object.defineProperty(window, 'localStorage', {
4681
+ // value: null,
4682
+ // configurable: true,
4683
+ // enumerable: true,
4684
+ // writable: false
4685
+ // });
4686
+ // }
4687
+ __classPrivateFieldSet(this, _LocalResourceStorage_resourceInfo, {
4688
+ keys: new Set(),
4689
+ currentSize: 0,
4690
+ limitSize: STORAGE_LIMIT
4691
+ }, "f");
4692
+ __classPrivateFieldSet(this, _LocalResourceStorage_prefix, prefix, "f");
4693
+ this.findAllCurrentDataByApp(prefix);
4694
+ }
4695
+ findAllCurrentDataByApp(prefix) {
4696
+ try {
4697
+ let _x;
4698
+ for (_x in __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f")) {
4699
+ if (prefix) {
4700
+ const _prefix = _x.split('_')[0];
4701
+ if (_prefix !== prefix) {
4702
+ continue;
4703
+ }
4704
+ }
4705
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(_x);
4706
+ }
4707
+ }
4708
+ catch (error) {
4709
+ logger.error(error, 'LocalResourceStorage > findAllCurrentDataByApp');
4710
+ }
4711
+ }
4712
+ get(keys) {
4713
+ let res = new Map();
4714
+ keys.forEach((key) => {
4715
+ res.set(key, this.getSync(key));
4716
+ });
4717
+ return Promise.resolve(res);
4718
+ }
4719
+ getSync(key) {
4720
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
4721
+ key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
4722
+ }
4723
+ if (!__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key))
4724
+ return null;
4725
+ return __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").getItem(key);
4726
+ }
4727
+ set(data) {
4728
+ return __awaiter(this, void 0, void 0, function* () {
4729
+ Object.entries(data).forEach(([key, value]) => {
4730
+ this.setSync(key, value.replace(/\\"/g, '"'));
4731
+ });
4732
+ return Promise.resolve({ errorKeys: [] });
4733
+ });
4734
+ }
4735
+ setSync(key, value) {
4736
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
4737
+ key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
4738
+ }
4739
+ __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").setItem(key, value);
4740
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(key);
4741
+ }
4742
+ getInfo() {
4874
4743
  return __awaiter(this, void 0, void 0, function* () {
4875
- yield this.callNative(ACTION.HIDE_KEYBOARD, {});
4744
+ return Promise.resolve(this.getInfoSync());
4876
4745
  });
4877
4746
  }
4878
- /**
4879
- * Open phone
4880
- * @async
4881
- * @function openPhone
4882
- * @category Device
4883
- *
4884
- */
4885
- static openPhone(object) {
4747
+ getInfoSync() {
4748
+ const currentSize = calcLocalStorageSize(__classPrivateFieldGet(this, _LocalResourceStorage_storage, "f"), __classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f"));
4749
+ return {
4750
+ currentSize: _.isNumber(currentSize)
4751
+ ? Number((currentSize / 1024).toFixed(2))
4752
+ : 0,
4753
+ limitSize: Number((STORAGE_LIMIT / 1024).toFixed(2))
4754
+ };
4755
+ }
4756
+ remove(keys) {
4886
4757
  return __awaiter(this, void 0, void 0, function* () {
4887
- yield this.callNative(ACTION.OPEN_PHONE, {
4888
- phoneNum: object.phoneNumber,
4889
- phoneCode: object.phoneNumber
4758
+ keys.forEach((key) => {
4759
+ this.removeSync(key);
4890
4760
  });
4761
+ return Promise.resolve({ errorKeys: [] });
4891
4762
  });
4892
4763
  }
4893
- /**
4894
- * Open SMS
4895
- * @async
4896
- * @function openSMS
4897
- * @category Device
4898
- *
4899
- */
4900
- static openSMS(object) {
4764
+ removeSync(key) {
4765
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
4766
+ key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
4767
+ }
4768
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key)) {
4769
+ __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
4770
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
4771
+ }
4772
+ }
4773
+ clear() {
4901
4774
  return __awaiter(this, void 0, void 0, function* () {
4902
- yield this.callNative(ACTION.OPEN_SMS, {
4903
- content: object.content,
4904
- phoneCode: object.phoneNumber
4905
- });
4775
+ return Promise.resolve(this.clearSync());
4906
4776
  });
4907
4777
  }
4908
- /**
4909
- * Keep screen.
4910
- * @async
4911
- * @function keepScreen
4912
- * @category Device
4913
- *
4914
- */
4915
- static keepScreen(object) {
4916
- return __awaiter(this, void 0, void 0, function* () {
4917
- return yield this.callNative(ACTION.KEEP_SCREEN, {
4918
- data: {
4919
- keep_screen_on: object.keepScreenOn ? 1 : 0
4920
- }
4921
- });
4778
+ clearSync() {
4779
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.forEach((key) => {
4780
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f") && key.indexOf(__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) < 0) {
4781
+ return;
4782
+ }
4783
+ __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
4784
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
4922
4785
  });
4923
4786
  }
4924
- /**
4925
- * Xác thực bằng sinh trắc học
4926
- * @async
4927
- * @function openBioAuthentication
4928
- * @category Authentication
4929
- *
4930
- */
4931
- static openBioAuthentication(object) {
4932
- return __awaiter(this, void 0, void 0, function* () {
4933
- return yield this.callNative(ACTION.PROMPT_AUTHENTICATION, {
4934
- secret_data: object.secretData,
4935
- app_id: this.getZAppId(),
4936
- ui: {
4937
- title: object.ui.title,
4938
- sub_title: object.ui.subTitle,
4939
- negative_text: object.ui.negativeButtonText
4940
- },
4941
- require_fingerprint: object.requireFingerprint ? 1 : 0
4942
- }).then((data) => {
4943
- var _a, _b, _c, _d;
4944
- return {
4945
- code: data === null || data === void 0 ? void 0 : data.error_code,
4946
- message: data === null || data === void 0 ? void 0 : data.error_message,
4947
- data: {
4948
- domain: (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.domain,
4949
- code: (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.error_code,
4950
- message: (_c = data === null || data === void 0 ? void 0 : data.data) === null || _c === void 0 ? void 0 : _c.error_message,
4951
- payToken: (_d = data === null || data === void 0 ? void 0 : data.data) === null || _d === void 0 ? void 0 : _d.pay_token
4952
- }
4953
- };
4787
+ }
4788
+ _LocalResourceStorage_storage = new WeakMap(), _LocalResourceStorage_prefix = new WeakMap(), _LocalResourceStorage_resourceInfo = new WeakMap();
4789
+
4790
+ var wrappers = {};
4791
+ var WrapperFn = function wrapFunction(fn, type, source) {
4792
+ var t = type || 'default';
4793
+ return function () {
4794
+ var callee = t in wrappers ? wrappers[t](fn, source) : fn;
4795
+ return callee.apply(this, arguments);
4796
+ };
4797
+ };
4798
+ WrapperFn.setWrapper = function (fn) {
4799
+ var type = arguments.length <= 1 || arguments[1] === undefined
4800
+ ? 'default'
4801
+ : arguments[1];
4802
+ wrappers[type] = fn;
4803
+ };
4804
+ var ERROR = {
4805
+ error: {
4806
+ code: 1,
4807
+ error_subcode: 1357046,
4808
+ message: 'Received Invalid JSON reply.',
4809
+ type: 'http'
4810
+ }
4811
+ };
4812
+ function safelyParseResponse(rawResponse) {
4813
+ try {
4814
+ return rawResponse === null ? ERROR : JSON.parse(rawResponse);
4815
+ }
4816
+ catch (ex) {
4817
+ return ERROR;
4818
+ }
4819
+ }
4820
+ function createCORSRequest(method, url) {
4821
+ if (!self.XMLHttpRequest) {
4822
+ return null;
4823
+ }
4824
+ var xhr = new XMLHttpRequest();
4825
+ var noop = function noop() { };
4826
+ if ('withCredentials' in xhr) {
4827
+ xhr.open(method, url, true);
4828
+ xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
4829
+ }
4830
+ else {
4831
+ return null;
4832
+ }
4833
+ var wrapper = {
4834
+ send: function send(data) {
4835
+ xhr.send(data);
4836
+ }
4837
+ };
4838
+ var onload = WrapperFn(function () {
4839
+ onload = noop;
4840
+ if ('onload' in wrapper) {
4841
+ wrapper.onload(xhr);
4842
+ }
4843
+ }, 'entry', 'XMLHttpRequest:load');
4844
+ var onerror = WrapperFn(function () {
4845
+ onerror = noop;
4846
+ if ('onerror' in wrapper) {
4847
+ wrapper.onerror(xhr);
4848
+ }
4849
+ }, 'entry', 'XMLHttpRequest:error');
4850
+ xhr.onload = function () {
4851
+ onload();
4852
+ };
4853
+ xhr.onerror = function () {
4854
+ onerror();
4855
+ };
4856
+ xhr.onreadystatechange = function () {
4857
+ if (xhr.readyState == 4) {
4858
+ if (xhr.status == 200) {
4859
+ onload();
4860
+ }
4861
+ else {
4862
+ onerror();
4863
+ }
4864
+ }
4865
+ };
4866
+ return wrapper;
4867
+ }
4868
+ function execute(url, method, params, cb) {
4869
+ params.suppress_http_code = 1;
4870
+ var data = QueryString.encode(params);
4871
+ if (method != 'post') {
4872
+ url = QueryString.appendToUrl(url, data);
4873
+ data = '';
4874
+ }
4875
+ var request = createCORSRequest(method, url);
4876
+ if (!request) {
4877
+ return false;
4878
+ }
4879
+ request.onload = function (xhr) {
4880
+ cb(safelyParseResponse(xhr.responseText));
4881
+ };
4882
+ request.onerror = function (xhr) {
4883
+ if (xhr.responseText) {
4884
+ cb(safelyParseResponse(xhr.responseText));
4885
+ }
4886
+ else {
4887
+ cb({
4888
+ error: {
4889
+ code: 1,
4890
+ error_subcode: 1357045,
4891
+ message: 'unknown error (empty response)',
4892
+ status: xhr.status,
4893
+ type: 'http'
4894
+ }
4895
+ });
4896
+ }
4897
+ };
4898
+ request.send(data);
4899
+ return true;
4900
+ }
4901
+ var CORSRequest = {
4902
+ execute: execute
4903
+ };
4904
+
4905
+ var _ZaloJSBridge_instances, _ZaloJSBridge_cookies, _ZaloJSBridge_actionRuntimeInfo, _ZaloJSBridge_jsCall;
4906
+ class ZaloJSBridge extends eventemitter3 {
4907
+ constructor() {
4908
+ super();
4909
+ _ZaloJSBridge_instances.add(this);
4910
+ this.debug = Debug('zmp:ZaloJSBridge');
4911
+ this.events = ZMPEEmitter.getInstance();
4912
+ this._accessTk = getToken('zacc_session') || 'DEFAULT_ACCESS_TOKEN';
4913
+ this._jsAccessTk = getToken('zlink3rd') || 'DEFAULT_JS_TOKEN';
4914
+ this.results = [];
4915
+ this._userAgent = getUserAgent();
4916
+ this._device = checkPlatform();
4917
+ this.isJumped = false;
4918
+ _ZaloJSBridge_cookies.set(this, null);
4919
+ _ZaloJSBridge_actionRuntimeInfo.set(this, void 0);
4920
+ this.jump = () => {
4921
+ return new Promise((resolve, reject) => {
4922
+ if (!_.isUndefined(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) && !_.isNull(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"))) {
4923
+ resolve(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"));
4924
+ }
4925
+ else {
4926
+ this.callNative(ACTION.JUMP_LOGIN, {})
4927
+ .then((data) => {
4928
+ const cookies = (data && data.cookiesOAuthLogins) || [];
4929
+ const actionPermission = (data && data.actionPermission) || [];
4930
+ Object.entries(actionPermission).forEach((item) => {
4931
+ const key = item[0];
4932
+ const value = item[1] || { perm: 0, decode: 0 };
4933
+ if (!__classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key]) {
4934
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key] = {
4935
+ permission: false,
4936
+ support: false
4937
+ };
4938
+ }
4939
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key].permission = value.perm === 1;
4940
+ });
4941
+ const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
4942
+ if (jsToken) {
4943
+ this.jsAccessTk = jsToken.value;
4944
+ window.ZJSBridge.setJSToken &&
4945
+ window.ZJSBridge.setJSToken(jsToken.value);
4946
+ }
4947
+ __classPrivateFieldSet(this, _ZaloJSBridge_cookies, cookies, "f");
4948
+ this.isJumped = true;
4949
+ resolve(cookies);
4950
+ })
4951
+ .catch((error) => {
4952
+ this.isJumped = false;
4953
+ reject(error);
4954
+ });
4955
+ }
4954
4956
  });
4957
+ };
4958
+ this._jsCallFuncCallbacks = {};
4959
+ __classPrivateFieldSet(this, _ZaloJSBridge_actionRuntimeInfo, {}, "f");
4960
+ this.events.on(Events.AppPaused, () => {
4961
+ if (this.results.length > 0) {
4962
+ let array = this.results;
4963
+ this.results = [];
4964
+ try {
4965
+ this.sendLogData(array);
4966
+ }
4967
+ catch (error) { }
4968
+ }
4955
4969
  });
4970
+ if (this.sendLogTimer) {
4971
+ clearInterval(this.sendLogTimer);
4972
+ }
4973
+ else {
4974
+ this.sendLogTimer = setInterval(() => {
4975
+ if (this.results.length > 0) {
4976
+ let array = this.results;
4977
+ this.results = [];
4978
+ try {
4979
+ this.sendLogData(array);
4980
+ }
4981
+ catch (error) { }
4982
+ }
4983
+ }, 5000);
4984
+ }
4956
4985
  }
4957
- /**
4958
- * Một phần của flow H5-Bio-Authentication. Dùng cho H5 kiểm tra xem bio-factor có bị thay đổi gì so với trước đây ko (thêm vân tay, reset...)
4959
- * @async
4960
- * @function checkStateBioAuthentication
4961
- * @category Authentication
4962
- *
4963
- * @example
4964
- * api.checkStateAuthen({
4965
- * success: (res) => {},
4966
- * fail: (err) => {}
4967
- * })
4968
- * @param {InputDataType.CallbackType} object
4969
- */
4970
- static checkStateBioAuthentication(object) {
4971
- return __awaiter(this, void 0, void 0, function* () {
4972
- return yield this.callNative(ACTION.PROMPT_AUTHENTICATION_CHECK_STATE, {}).then((data) => {
4986
+ static getInstance() {
4987
+ if (!ZaloJSBridge.instance) {
4988
+ ZaloJSBridge.instance = new ZaloJSBridge();
4989
+ }
4990
+ return ZaloJSBridge.instance;
4991
+ }
4992
+ set accessTk(value) {
4993
+ this._accessTk = value;
4994
+ }
4995
+ set jsAccessTk(value) {
4996
+ this._jsAccessTk = value;
4997
+ }
4998
+ sendLogData(data) {
4999
+ try {
5000
+ const logData = data.map((item) => {
4973
5001
  return {
4974
- bioState: data === null || data === void 0 ? void 0 : data.bio_state
5002
+ action: item.action,
5003
+ error: item.error
4975
5004
  };
4976
5005
  });
4977
- });
5006
+ CORSRequest.execute(APIS.SEND_ACTION_LOG, 'post', {
5007
+ appId: window.APP_ID,
5008
+ data: JSON.stringify(logData)
5009
+ }, (response) => { });
5010
+ window.zmpSentry &&
5011
+ window.zmpSentry.captureMessage('Result from native', {
5012
+ extra: {
5013
+ data: data
5014
+ }
5015
+ });
5016
+ }
5017
+ catch (error) { }
4978
5018
  }
4979
- /**
4980
- * Vibrate.
4981
- * @async
4982
- * @function vibrate
4983
- * @category Device
4984
- *
4985
- */
4986
- static vibrate(object) {
4987
- return __awaiter(this, void 0, void 0, function* () {
4988
- return yield this.callNative(ACTION.INTERACTIVE_VIBRATION, {
4989
- type: VibrateType[object.type],
4990
- vibrate_time: object.milliseconds
5019
+ onJSCall(key, data) {
5020
+ try {
5021
+ this.debug('onJSCall', key, data);
5022
+ const parsedData = parseJSON(data);
5023
+ if (this._jsCallFuncCallbacks[key]) {
5024
+ const callback = this._jsCallFuncCallbacks[key].callback;
5025
+ const timeout = this._jsCallFuncCallbacks[key].timeout;
5026
+ if (!!callback) {
5027
+ try {
5028
+ callback.call(this, parsedData);
5029
+ }
5030
+ catch (error) {
5031
+ console.error('Call callback error', error);
5032
+ }
5033
+ !!timeout && clearTimeout(timeout);
5034
+ this._jsCallFuncCallbacks[key] = null;
5035
+ delete this._jsCallFuncCallbacks[key];
5036
+ }
5037
+ }
5038
+ this.results.push({
5039
+ action: parsedData.action,
5040
+ error: parsedData.error_code,
5041
+ message: parsedData.error_message
4991
5042
  });
4992
- });
5043
+ }
5044
+ catch (e) {
5045
+ console.log('onJSCall', 'error', e);
5046
+ }
4993
5047
  }
4994
- /**
4995
- * Connect Wifi.
4996
- * @async
4997
- * @function connectWifi
4998
- * @category Device
4999
- *
5000
- */
5001
- static connectWifi(object) {
5002
- return __awaiter(this, void 0, void 0, function* () {
5003
- let securityType = 'open';
5004
- if (_.isString(object.password) && object.password.length > 0) {
5005
- securityType = 'wpa_wpa2';
5048
+ onMultiJSCall(key, data) {
5049
+ try {
5050
+ this.debug('onMultiJSCall', key, data);
5051
+ const parsedData = parseJSON(data);
5052
+ if (this._jsCallFuncCallbacks[key]) {
5053
+ const callback = this._jsCallFuncCallbacks[key].callback;
5054
+ const timeout = this._jsCallFuncCallbacks[key].timeout;
5055
+ if (!!callback) {
5056
+ try {
5057
+ callback.call(this, parsedData);
5058
+ }
5059
+ catch (error) {
5060
+ console.error('Call callback error', error);
5061
+ }
5062
+ !!timeout && clearTimeout(timeout);
5063
+ }
5006
5064
  }
5007
- return yield this.callNative(ACTION.MP_JOIN_WIFI, {
5008
- ssid: object.SSID,
5009
- securityType: securityType,
5010
- password: object.password,
5011
- hiddenSsid: object.hiddenSSID
5065
+ this.results.push({
5066
+ action: parsedData.action,
5067
+ error: parsedData.error_code,
5068
+ message: parsedData.error_message
5012
5069
  });
5013
- });
5014
- }
5015
- /**
5016
- * Open App Store.
5017
- * @async
5018
- * @function openAppStore
5019
- * @category Device
5020
- *
5021
- */
5022
- static openAppStore(object) {
5023
- return __awaiter(this, void 0, void 0, function* () {
5024
- return yield this.callNative(ACTION.OPEN_APPSTORE, object);
5025
- });
5070
+ }
5071
+ catch (e) {
5072
+ console.log('onMultiJSCall', 'error', e);
5073
+ }
5026
5074
  }
5027
- }
5028
-
5029
- var _LocalResourceStorage_storage, _LocalResourceStorage_prefix, _LocalResourceStorage_resourceInfo;
5030
- class LocalResourceStorage {
5031
- constructor(prefix) {
5032
- _LocalResourceStorage_storage.set(this, localStorage);
5033
- _LocalResourceStorage_prefix.set(this, void 0);
5034
- _LocalResourceStorage_resourceInfo.set(this, void 0);
5035
- checkPlatform();
5036
- // if (platform.isMobile && platform.isZalo) {
5037
- // Object.defineProperty(window, 'localStorage', {
5038
- // value: null,
5039
- // configurable: true,
5040
- // enumerable: true,
5041
- // writable: false
5042
- // });
5043
- // }
5044
- __classPrivateFieldSet(this, _LocalResourceStorage_resourceInfo, {
5045
- keys: new Set(),
5046
- currentSize: 0,
5047
- limitSize: STORAGE_LIMIT
5048
- }, "f");
5049
- __classPrivateFieldSet(this, _LocalResourceStorage_prefix, prefix, "f");
5050
- this.findAllCurrentDataByApp(prefix);
5075
+ nativeEventHandler(eventId, eventName, eventData) {
5076
+ this.debug(`eventId: ${eventId}, eventName: ${eventName}, eventData: ${eventData}`);
5077
+ const data = stringToData(eventData);
5078
+ this.debug(data);
5079
+ const convertedData = this.handleEventData(eventName, data);
5080
+ this.events.emit(eventName, eventId, convertedData);
5051
5081
  }
5052
- findAllCurrentDataByApp(prefix) {
5082
+ handleEventData(eventName, data) {
5053
5083
  try {
5054
- let _x;
5055
- for (_x in __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f")) {
5056
- if (prefix) {
5057
- const _prefix = _x.split('_')[0];
5058
- if (_prefix !== prefix) {
5059
- continue;
5060
- }
5061
- }
5062
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(_x);
5084
+ switch (eventName) {
5085
+ case Events.OpenApp:
5086
+ const { url } = data;
5087
+ const validUrl = new URL(url);
5088
+ const path = validUrl.pathname.split(`/zapps/${APP_ID}`)[1];
5089
+ return {
5090
+ path: `${path ? path : '/'}${validUrl.search}`
5091
+ };
5092
+ break;
5093
+ default:
5094
+ return data;
5095
+ break;
5063
5096
  }
5064
5097
  }
5065
5098
  catch (error) {
5066
- logger.error(error, 'LocalResourceStorage > findAllCurrentDataByApp');
5099
+ return data;
5067
5100
  }
5068
5101
  }
5069
- get(keys) {
5070
- let res = new Map();
5071
- keys.forEach((key) => {
5072
- res.set(key, this.getSync(key));
5073
- });
5074
- return Promise.resolve(res);
5075
- }
5076
- getSync(key) {
5077
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5078
- key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
5102
+ defaultCallback(data) {
5103
+ if (data !== null && data !== undefined) {
5104
+ data = parseJSON(data);
5079
5105
  }
5080
- if (!__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key))
5081
- return null;
5082
- return __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").getItem(key);
5083
5106
  }
5084
- set(data) {
5085
- return __awaiter(this, void 0, void 0, function* () {
5086
- Object.entries(data).forEach(([key, value]) => {
5087
- this.setSync(key, value.replace(/\\"/g, '"'));
5107
+ callNative(action, data, option) {
5108
+ this.debug(action.name, data);
5109
+ return new Promise((resolve, reject) => {
5110
+ const handleNativeCallback = (cb) => __awaiter(this, void 0, void 0, function* () {
5111
+ var _a, _b, _c, _d, _e, _f, _g, _h;
5112
+ try {
5113
+ if (_.isUndefined(cb) || _.isNull(cb)) {
5114
+ return reject(new Error('Native callback is null'));
5115
+ }
5116
+ if (cb.error_code !== 0) {
5117
+ let error = new AppError(cb.error_code, cb.error_message);
5118
+ const platform = getPlatform();
5119
+ if (action === ACTION.JUMP_LOGIN) {
5120
+ error = new AppError(RESPONSE_CODE.UNKNOWN_ERROR, `Can not get auth code: ${cb.error_message}`);
5121
+ }
5122
+ else if (!this.isJumped && !action.skip_jump) {
5123
+ error = new AppError(RESPONSE.UNAUTHORIZED.code, RESPONSE.UNAUTHORIZED.message);
5124
+ }
5125
+ else if (String(error.message).toLowerCase() === 'permission required!' ||
5126
+ String(error.message).toLowerCase() === 'no permission!') {
5127
+ error = new AppError(RESPONSE.FORBIDDEN.code, RESPONSE.FORBIDDEN.message);
5128
+ }
5129
+ else if (COMMON_NATIVE_ERROR_CODE[platform][cb.error_code]) {
5130
+ error = new AppError(COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].code, COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].message);
5131
+ }
5132
+ else if ((_b = (_a = action.error_list) === null || _a === void 0 ? void 0 : _a[platform]) === null || _b === void 0 ? void 0 : _b[String(cb.error_code)]) {
5133
+ let error_message = action.error_list[platform][String(cb.error_code)].map_to.message;
5134
+ if ((_e = (_d = (_c = action.error_list) === null || _c === void 0 ? void 0 : _c[platform]) === null || _d === void 0 ? void 0 : _d[String(cb.error_code)]) === null || _e === void 0 ? void 0 : _e.need_more_detail) {
5135
+ error_message = `${(_h = (_g = (_f = action.error_list) === null || _f === void 0 ? void 0 : _f[platform]) === null || _g === void 0 ? void 0 : _g[String(cb.error_code)]) === null || _h === void 0 ? void 0 : _h.map_to.message}: ${cb.error_message}`;
5136
+ }
5137
+ error = new AppError(action.error_list[platform][String(cb.error_code)].map_to.code, error_message);
5138
+ }
5139
+ return reject(error);
5140
+ }
5141
+ if (option === null || option === void 0 ? void 0 : option.successCallback) {
5142
+ const res = yield option.successCallback(cb.data);
5143
+ return resolve(res);
5144
+ }
5145
+ else {
5146
+ resolve(cb.data || {});
5147
+ }
5148
+ }
5149
+ catch (error) {
5150
+ return reject(error);
5151
+ }
5088
5152
  });
5089
- return Promise.resolve({ errorKeys: [] });
5153
+ const isIOS = checkPlatform().isIOS;
5154
+ const isSupportAction = checkIOSSupportAction(action);
5155
+ if (isIOS && !isSupportAction) {
5156
+ const error = new AppError(-5, `Client isn't support this action`);
5157
+ return reject(error);
5158
+ }
5159
+ else if (option === null || option === void 0 ? void 0 : option.delay) {
5160
+ setTimeout(() => {
5161
+ __classPrivateFieldGet(this, _ZaloJSBridge_instances, "m", _ZaloJSBridge_jsCall).call(this, action, data, handleNativeCallback, option === null || option === void 0 ? void 0 : option.isMultiCallback, option === null || option === void 0 ? void 0 : option.nRetry, option === null || option === void 0 ? void 0 : option.haveTimeout);
5162
+ }, option.delay);
5163
+ }
5164
+ else {
5165
+ __classPrivateFieldGet(this, _ZaloJSBridge_instances, "m", _ZaloJSBridge_jsCall).call(this, action, data, handleNativeCallback, option === null || option === void 0 ? void 0 : option.isMultiCallback, option === null || option === void 0 ? void 0 : option.nRetry, option === null || option === void 0 ? void 0 : option.haveTimeout);
5166
+ }
5090
5167
  });
5091
5168
  }
5092
- setSync(key, value) {
5093
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5094
- key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
5169
+ }
5170
+ _ZaloJSBridge_cookies = new WeakMap(), _ZaloJSBridge_actionRuntimeInfo = new WeakMap(), _ZaloJSBridge_instances = new WeakSet(), _ZaloJSBridge_jsCall = function _ZaloJSBridge_jsCall(action, options, callback, isMultiCallback = false, nRetry = 3, haveTimeout = true) {
5171
+ try {
5172
+ const actionName = action.name;
5173
+ const key = generateUniqueString(actionName);
5174
+ if (!this._device.isMobile || _.isEmpty(actionName)) {
5175
+ this.onJSCall(key, {
5176
+ error_code: -13,
5177
+ error_message: 'params invalid!',
5178
+ data: {
5179
+ device: this._device.isMobile,
5180
+ jsToken: this._jsAccessTk,
5181
+ access_token: this._accessTk
5182
+ },
5183
+ action: actionName
5184
+ });
5185
+ return false;
5095
5186
  }
5096
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").setItem(key, value);
5097
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(key);
5098
- }
5099
- getInfo() {
5100
- return __awaiter(this, void 0, void 0, function* () {
5101
- return Promise.resolve(this.getInfoSync());
5102
- });
5103
- }
5104
- getInfoSync() {
5105
- const currentSize = calcLocalStorageSize(__classPrivateFieldGet(this, _LocalResourceStorage_storage, "f"), __classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f"));
5106
- return {
5107
- currentSize: _.isNumber(currentSize)
5108
- ? Number((currentSize / 1024).toFixed(2))
5109
- : 0,
5110
- limitSize: Number((STORAGE_LIMIT / 1024).toFixed(2))
5187
+ if (options === undefined || options === null) {
5188
+ options = {};
5189
+ }
5190
+ if (!callback) {
5191
+ callback = this.defaultCallback;
5192
+ }
5193
+ const timeoutCallback = {
5194
+ error_code: -14,
5195
+ error_message: 'Request Timeout!',
5196
+ data: {},
5197
+ action: actionName
5111
5198
  };
5112
- }
5113
- remove(keys) {
5114
- return __awaiter(this, void 0, void 0, function* () {
5115
- keys.forEach((key) => {
5116
- this.removeSync(key);
5117
- });
5118
- return Promise.resolve({ errorKeys: [] });
5119
- });
5120
- }
5121
- removeSync(key) {
5122
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5123
- key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
5199
+ this._jsCallFuncCallbacks[key] = {
5200
+ timeout: haveTimeout &&
5201
+ action.have_callback &&
5202
+ setTimeout(() => {
5203
+ this.onJSCall(key, timeoutCallback);
5204
+ }, 8000),
5205
+ callback: callback
5206
+ };
5207
+ try {
5208
+ options = serialize(options);
5209
+ if (isMultiCallback) {
5210
+ if (this._device.isIOS) {
5211
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onMultiJSCall(key));
5212
+ }
5213
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onMultiJSCall('${key}')`);
5214
+ }
5215
+ if (this._device.isIOS) {
5216
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onJSCall(key));
5217
+ }
5218
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onJSCall('${key}')`);
5124
5219
  }
5125
- if (__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key)) {
5126
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
5127
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
5220
+ catch (error) {
5221
+ if (nRetry-- > 0) {
5222
+ setTimeout(() => {
5223
+ __classPrivateFieldGet(this, _ZaloJSBridge_instances, "m", _ZaloJSBridge_jsCall).call(this, action, options, callback, isMultiCallback, nRetry);
5224
+ }, 500);
5225
+ }
5226
+ else {
5227
+ const errorCallback = {
5228
+ error_code: -5,
5229
+ error_message: 'Not ready!',
5230
+ data: {
5231
+ userAgent: this._userAgent,
5232
+ options: options,
5233
+ jsToken: this._jsAccessTk,
5234
+ access_token: this._accessTk
5235
+ },
5236
+ action: actionName,
5237
+ js_error: error
5238
+ };
5239
+ this.onJSCall(key, errorCallback);
5240
+ return false;
5241
+ }
5128
5242
  }
5129
5243
  }
5130
- clear() {
5131
- return __awaiter(this, void 0, void 0, function* () {
5132
- return Promise.resolve(this.clearSync());
5133
- });
5134
- }
5135
- clearSync() {
5136
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.forEach((key) => {
5137
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f") && key.indexOf(__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) < 0) {
5138
- return;
5139
- }
5140
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
5141
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
5142
- });
5244
+ catch (error) {
5245
+ console.log('jsCall', 'error', error);
5143
5246
  }
5144
- }
5145
- _LocalResourceStorage_storage = new WeakMap(), _LocalResourceStorage_prefix = new WeakMap(), _LocalResourceStorage_resourceInfo = new WeakMap();
5247
+ return false;
5248
+ };
5146
5249
 
5147
- var _NativeResourceStorage_appId, _NativeResourceStorage_resourceInfo;
5148
- class NativeResourceStorage extends ZJSBridgeProvider {
5250
+ var _NativeResourceStorage_appId, _NativeResourceStorage_resourceInfo, _NativeResourceStorage_bridge;
5251
+ class NativeResourceStorage {
5149
5252
  constructor(appId) {
5150
- super();
5151
5253
  _NativeResourceStorage_appId.set(this, void 0);
5152
5254
  _NativeResourceStorage_resourceInfo.set(this, void 0);
5255
+ _NativeResourceStorage_bridge.set(this, void 0);
5153
5256
  __classPrivateFieldSet(this, _NativeResourceStorage_resourceInfo, {
5154
5257
  keys: new Set(),
5155
5258
  currentSize: 0,
5156
5259
  limitSize: STORAGE_LIMIT
5157
5260
  }, "f");
5158
5261
  __classPrivateFieldSet(this, _NativeResourceStorage_appId, appId, "f");
5262
+ __classPrivateFieldSet(this, _NativeResourceStorage_bridge, ZaloJSBridge.getInstance(), "f");
5159
5263
  }
5160
5264
  get(keys) {
5161
5265
  return __awaiter(this, void 0, void 0, function* () {
5162
- return yield this.callNative(ACTION.ZBROWSER_MPDS, {
5266
+ return yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5267
+ .callNative(ACTION.ZBROWSER_MPDS, {
5163
5268
  mpds_action: 'mpds.get',
5164
5269
  mpds_data: {
5165
5270
  keys
@@ -5167,7 +5272,8 @@
5167
5272
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5168
5273
  }, {
5169
5274
  isMultiCallback: false
5170
- }).then((data) => {
5275
+ })
5276
+ .then((data) => {
5171
5277
  let res = new Map();
5172
5278
  if (data && data.mpds_data && data.mpds_data.map) {
5173
5279
  res = new Map(Object.entries(data.mpds_data.map));
@@ -5178,7 +5284,8 @@
5178
5284
  }
5179
5285
  set(data) {
5180
5286
  return __awaiter(this, void 0, void 0, function* () {
5181
- const errorKeys = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5287
+ const errorKeys = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5288
+ .callNative(ACTION.ZBROWSER_MPDS, {
5182
5289
  mpds_action: 'mpds.set',
5183
5290
  mpds_data: {
5184
5291
  map: data
@@ -5186,7 +5293,8 @@
5186
5293
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5187
5294
  }, {
5188
5295
  isMultiCallback: false
5189
- }).then((data) => {
5296
+ })
5297
+ .then((data) => {
5190
5298
  let res = [];
5191
5299
  if (data && data.mpds_data && data.mpds_data.error_keys) {
5192
5300
  res = data.mpds_data.error_keys;
@@ -5198,13 +5306,15 @@
5198
5306
  }
5199
5307
  getInfo() {
5200
5308
  return __awaiter(this, void 0, void 0, function* () {
5201
- const currentSize = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5309
+ const currentSize = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5310
+ .callNative(ACTION.ZBROWSER_MPDS, {
5202
5311
  mpds_action: 'mpds.get.size',
5203
5312
  mpds_data: {},
5204
5313
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5205
5314
  }, {
5206
5315
  isMultiCallback: false
5207
- }).then((data) => {
5316
+ })
5317
+ .then((data) => {
5208
5318
  let res = 0;
5209
5319
  if (data && data.mpds_data && data.mpds_data.size) {
5210
5320
  res = data.mpds_data.size;
@@ -5219,7 +5329,8 @@
5219
5329
  }
5220
5330
  remove(keys) {
5221
5331
  return __awaiter(this, void 0, void 0, function* () {
5222
- const errorKeys = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5332
+ const errorKeys = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5333
+ .callNative(ACTION.ZBROWSER_MPDS, {
5223
5334
  mpds_action: 'mpds.remove.key',
5224
5335
  mpds_data: {
5225
5336
  keys: keys
@@ -5227,7 +5338,8 @@
5227
5338
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5228
5339
  }, {
5229
5340
  isMultiCallback: false
5230
- }).then((data) => {
5341
+ })
5342
+ .then((data) => {
5231
5343
  let res = [];
5232
5344
  if (data && data.mpds_data && data.mpds_data.error_keys) {
5233
5345
  res = data.mpds_data.error_keys;
@@ -5239,7 +5351,7 @@
5239
5351
  }
5240
5352
  clear() {
5241
5353
  return __awaiter(this, void 0, void 0, function* () {
5242
- yield this.callNative(ACTION.ZBROWSER_MPDS, {
5354
+ yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f").callNative(ACTION.ZBROWSER_MPDS, {
5243
5355
  mpds_action: 'mpds.clear.appData',
5244
5356
  mpds_data: {},
5245
5357
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
@@ -5247,7 +5359,7 @@
5247
5359
  });
5248
5360
  }
5249
5361
  }
5250
- _NativeResourceStorage_appId = new WeakMap(), _NativeResourceStorage_resourceInfo = new WeakMap();
5362
+ _NativeResourceStorage_appId = new WeakMap(), _NativeResourceStorage_resourceInfo = new WeakMap(), _NativeResourceStorage_bridge = new WeakMap();
5251
5363
 
5252
5364
  var _LocalStorageCreator_appId, _NativeStorageCreator_appId;
5253
5365
  class StorageCreator {
@@ -5499,18 +5611,13 @@
5499
5611
  */
5500
5612
  static getPhoneNumber(object) {
5501
5613
  return __awaiter(this, void 0, void 0, function* () {
5502
- return yield this.callNative(ACTION.MP_GET_NUMBER, {}, {
5614
+ return yield this.getJSBridge().callNative(ACTION.MP_GET_NUMBER, {}, {
5503
5615
  isMultiCallback: true,
5504
- callback: (nativeData, error) => {
5505
- if (nativeData.error_code === 0) {
5506
- const res = {
5507
- number: nativeData.data
5508
- };
5509
- return Promise.resolve(res);
5510
- }
5511
- else {
5512
- return Promise.reject(error);
5513
- }
5616
+ successCallback: (data) => {
5617
+ const res = {
5618
+ number: data
5619
+ };
5620
+ return Promise.resolve(res);
5514
5621
  },
5515
5622
  delay: this.isIOS ? 400 : 0
5516
5623
  });
@@ -5529,7 +5636,7 @@
5529
5636
  */
5530
5637
  static closeApp(object) {
5531
5638
  return __awaiter(this, void 0, void 0, function* () {
5532
- yield this.callNative(ACTION.WINDOW_CLOSE, {});
5639
+ yield this.getJSBridge().callNative(ACTION.WINDOW_CLOSE, {});
5533
5640
  });
5534
5641
  }
5535
5642
  /**
@@ -5561,7 +5668,7 @@
5561
5668
  mpInfo.appName = appInfo.name;
5562
5669
  mpInfo.appAvtUrl = appInfo.logoUrl;
5563
5670
  }
5564
- yield this.callNative(ACTION.OPEN_MP, {
5671
+ yield this.getJSBridge().callNative(ACTION.OPEN_MP, {
5565
5672
  mpUrl: `${MINI_APP_INTERNAL_LINK}/${appId}/${queryParamString.length > 0 ? '?' + queryParamString : ''}`,
5566
5673
  mpInfo: mpInfo
5567
5674
  });
@@ -5577,7 +5684,7 @@
5577
5684
  */
5578
5685
  static openWebview(url) {
5579
5686
  return __awaiter(this, void 0, void 0, function* () {
5580
- yield this.callNative(ACTION.OPEN_INAPP, {
5687
+ yield this.getJSBridge().callNative(ACTION.OPEN_INAPP, {
5581
5688
  url: url
5582
5689
  });
5583
5690
  });
@@ -5592,7 +5699,7 @@
5592
5699
  */
5593
5700
  static closeLoading(when) {
5594
5701
  return __awaiter(this, void 0, void 0, function* () {
5595
- yield this.callNative(ACTION.MP_CLOSE_LOADINGVIEW, {
5702
+ yield this.getJSBridge().callNative(ACTION.MP_CLOSE_LOADINGVIEW, {
5596
5703
  at: new Date().getTime(),
5597
5704
  when: when,
5598
5705
  url: location.href
@@ -5619,30 +5726,24 @@
5619
5726
  */
5620
5727
  static getLocation(object) {
5621
5728
  return __awaiter(this, void 0, void 0, function* () {
5622
- return yield this.callNative(ACTION.GET_LOCATION, {
5729
+ return yield this.getJSBridge().callNative(ACTION.GET_LOCATION, {
5623
5730
  silent_request: false,
5624
5731
  permission_description: 'Cho phép Zalo truy cập vào vị trí của thiết bị này?'
5625
5732
  }, {
5626
5733
  isMultiCallback: true,
5627
5734
  haveTimeout: false,
5628
- callback: (nativeData, error) => {
5629
- if (nativeData.error_code === 0) {
5630
- const data = nativeData.data;
5631
- const res = {
5632
- /** latitude */
5633
- latitude: data.latitude,
5634
- /** longitude */
5635
- longitude: data.longitude,
5636
- /** timestamp */
5637
- timestamp: data.timestamp,
5638
- /** provider */
5639
- provider: data.provider
5640
- };
5641
- return Promise.resolve(res);
5642
- }
5643
- else {
5644
- return Promise.reject(error);
5645
- }
5735
+ successCallback: (data) => {
5736
+ const res = {
5737
+ /** latitude */
5738
+ latitude: data.latitude,
5739
+ /** longitude */
5740
+ longitude: data.longitude,
5741
+ /** timestamp */
5742
+ timestamp: data.timestamp,
5743
+ /** provider */
5744
+ provider: data.provider
5745
+ };
5746
+ return Promise.resolve(res);
5646
5747
  },
5647
5748
  delay: this.isIOS ? 400 : 0
5648
5749
  });
@@ -5658,7 +5759,7 @@
5658
5759
  */
5659
5760
  static sendLocation(object) {
5660
5761
  return __awaiter(this, void 0, void 0, function* () {
5661
- yield this.callNative(ACTION.QUERY_LOCATION_HIDE, {
5762
+ yield this.getJSBridge().callNative(ACTION.QUERY_LOCATION_HIDE, {
5662
5763
  title: object.title,
5663
5764
  touserid: object.toUserId,
5664
5765
  zapp: this.getZAppId()
@@ -5678,17 +5779,12 @@
5678
5779
  */
5679
5780
  static requestCameraPermission(object) {
5680
5781
  return __awaiter(this, void 0, void 0, function* () {
5681
- return yield this.callNative(ACTION.REQUEST_PERMISSION_CAMERA, {}, {
5682
- callback: (nativeData, error) => {
5683
- if (nativeData.error_code === -2 || nativeData.error_code >= 0) {
5684
- return Promise.resolve({
5685
- userAllow: nativeData.error_code === -2 ? false : true,
5686
- message: nativeData.error_message
5687
- });
5688
- }
5689
- else {
5690
- return Promise.reject(error);
5691
- }
5782
+ return yield this.getJSBridge().callNative(ACTION.REQUEST_PERMISSION_CAMERA, {}, {
5783
+ successCallback: () => {
5784
+ return Promise.resolve({
5785
+ userAllow: true,
5786
+ message: 'User Allow'
5787
+ });
5692
5788
  }
5693
5789
  });
5694
5790
  });
@@ -5714,7 +5810,7 @@
5714
5810
  imageUrl: object.imageUrl
5715
5811
  };
5716
5812
  }
5717
- return yield this.callNative(ACTION.SAVE_IMAGE_GALLERY, Object.assign({}, data));
5813
+ return yield this.getJSBridge().callNative(ACTION.SAVE_IMAGE_GALLERY, Object.assign({}, data));
5718
5814
  });
5719
5815
  }
5720
5816
  }
@@ -5729,7 +5825,7 @@
5729
5825
  */
5730
5826
  static viewOAQr(object) {
5731
5827
  return __awaiter(this, void 0, void 0, function* () {
5732
- yield this.callNative(ACTION.VIEW_MYQR, {
5828
+ yield this.getJSBridge().callNative(ACTION.VIEW_MYQR, {
5733
5829
  dpn: object.displayName,
5734
5830
  uid: object.id,
5735
5831
  zapp: this.getZAppId()
@@ -5748,7 +5844,7 @@
5748
5844
  */
5749
5845
  static openProfile(object) {
5750
5846
  return __awaiter(this, void 0, void 0, function* () {
5751
- return yield this.callNative(ACTION.OPEN_PROFILE, {
5847
+ return yield this.getJSBridge().callNative(ACTION.OPEN_PROFILE, {
5752
5848
  uId: object.id,
5753
5849
  type: ProfileType[object.type],
5754
5850
  zapp: this.getZAppId(),
@@ -5766,9 +5862,10 @@
5766
5862
  */
5767
5863
  static openChat(object) {
5768
5864
  return __awaiter(this, void 0, void 0, function* () {
5769
- return yield this.callNative(ACTION.OPEN_CHAT, {
5865
+ return yield this.getJSBridge().callNative(ACTION.OPEN_CHAT, {
5770
5866
  uId: object.id,
5771
5867
  type: ChatType[object.type],
5868
+ msg: object.message || '',
5772
5869
  zapp: this.getZAppId(),
5773
5870
  sourceId: object.sourceId,
5774
5871
  sourceIndex: object.sourceIndex
@@ -5807,7 +5904,9 @@
5807
5904
  };
5808
5905
  break;
5809
5906
  }
5810
- return yield this.callNative(ACTION.OPEN_POSTFEED, Object.assign(Object.assign({ type: PostFeedType[object.type] }, reqData), { zapp: this.getZAppId() })).then((res) => {
5907
+ return yield this.getJSBridge()
5908
+ .callNative(ACTION.OPEN_POSTFEED, Object.assign(Object.assign({ type: PostFeedType[object.type] }, reqData), { zapp: this.getZAppId() }))
5909
+ .then((res) => {
5811
5910
  return {
5812
5911
  status: res.status,
5813
5912
  shareType: res.share_type,
@@ -5826,7 +5925,7 @@
5826
5925
  */
5827
5926
  static followOA(object) {
5828
5927
  return __awaiter(this, void 0, void 0, function* () {
5829
- yield this.callNative(ACTION.FOLLOW_OA, {
5928
+ yield this.getJSBridge().callNative(ACTION.FOLLOW_OA, {
5830
5929
  uid: object.id,
5831
5930
  showDialogConfirm: true,
5832
5931
  zapp: this.getZAppId()
@@ -5845,7 +5944,7 @@
5845
5944
  */
5846
5945
  static unfollowOA(object) {
5847
5946
  return __awaiter(this, void 0, void 0, function* () {
5848
- yield this.callNative(ACTION.UNFOLLOW_OA, {
5947
+ yield this.getJSBridge().callNative(ACTION.UNFOLLOW_OA, {
5849
5948
  uid: object.id,
5850
5949
  zapp: this.getZAppId()
5851
5950
  }, {
@@ -5867,7 +5966,8 @@
5867
5966
  switch (object.type) {
5868
5967
  case 'image':
5869
5968
  let photoUrls = [];
5870
- if (Array.isArray(object.data.imageUrls) && object.data.imageUrls.length > 0) {
5969
+ if (Array.isArray(object.data.imageUrls) &&
5970
+ object.data.imageUrls.length > 0) {
5871
5971
  photoUrls = object.data.imageUrls;
5872
5972
  }
5873
5973
  else {
@@ -5934,9 +6034,11 @@
5934
6034
  object.type = 'link';
5935
6035
  }
5936
6036
  }
5937
- return yield this.callNative(ACTION.OPEN_SHARESHEET, Object.assign(Object.assign({ type: ShareSheetType[object.type] }, reqData), { zapp: this.getZAppId() }), {
6037
+ return yield this.getJSBridge()
6038
+ .callNative(ACTION.OPEN_SHARESHEET, Object.assign(Object.assign({ type: ShareSheetType[object.type] }, reqData), { zapp: this.getZAppId() }), {
5938
6039
  haveTimeout: false
5939
- }).then((res) => {
6040
+ })
6041
+ .then((res) => {
5940
6042
  return {
5941
6043
  status: res.status,
5942
6044
  shareType: res.share_type,
@@ -5955,7 +6057,7 @@
5955
6057
  */
5956
6058
  static createShortcut(url, title, icon) {
5957
6059
  return __awaiter(this, void 0, void 0, function* () {
5958
- return yield this.callNative(ACTION.CREATE_SHORTCUT, {
6060
+ return yield this.getJSBridge().callNative(ACTION.CREATE_SHORTCUT, {
5959
6061
  url: url,
5960
6062
  title: title,
5961
6063
  iconUrl: icon
@@ -5972,15 +6074,14 @@
5972
6074
  */
5973
6075
  static openProfilePicker(maxProfile) {
5974
6076
  return __awaiter(this, void 0, void 0, function* () {
5975
- return yield this.callNative(ACTION.MP_OPEN_PROFILE_PICKER, {
6077
+ return yield this.getJSBridge().callNative(ACTION.MP_OPEN_PROFILE_PICKER, {
5976
6078
  maxProfile: maxProfile
5977
6079
  }, {
5978
6080
  isMultiCallback: true,
5979
- callback: (nativeData, error) => {
5980
- if (nativeData.error_code === 0 && Array.isArray(nativeData.data)) {
5981
- return Promise.resolve(nativeData.data.map((item) => item.id));
6081
+ successCallback: (data) => {
6082
+ if (Array.isArray(data)) {
6083
+ return Promise.resolve(data.map((item) => item.id));
5982
6084
  }
5983
- return Promise.reject(error);
5984
6085
  }
5985
6086
  });
5986
6087
  });
@@ -5995,15 +6096,15 @@
5995
6096
  */
5996
6097
  static getActionsSupported(object) {
5997
6098
  return __awaiter(this, void 0, void 0, function* () {
5998
- return yield this.callNative(ACTION.GET_SUPPORTED_ACTIONS, {}, {
6099
+ return yield this.getJSBridge().callNative(ACTION.GET_SUPPORTED_ACTIONS, {}, {
5999
6100
  isMultiCallback: false,
6000
- callback: (nativeData, error) => {
6101
+ successCallback: (data) => {
6001
6102
  const platform = getPlatform();
6002
- if (Array.isArray(nativeData.actions) &&
6003
- nativeData.actions.length > 0) {
6103
+ if (Array.isArray(data.actions) &&
6104
+ data.actions.length > 0) {
6004
6105
  const skipJumpActions = Object.keys(ACTION).filter((item) => ACTION[item].skip_jump);
6005
6106
  const res = {
6006
- actions: [...nativeData.actions, ...skipJumpActions]
6107
+ actions: [...data.actions, ...skipJumpActions]
6007
6108
  };
6008
6109
  return Promise.resolve(res);
6009
6110
  }
@@ -6013,7 +6114,6 @@
6013
6114
  };
6014
6115
  return Promise.resolve(res);
6015
6116
  }
6016
- return Promise.reject(error);
6017
6117
  }
6018
6118
  });
6019
6119
  });
@@ -6037,7 +6137,7 @@
6037
6137
  enable: 1,
6038
6138
  aspect_ratio: '1:1'
6039
6139
  };
6040
- return yield this.callNative(ACTION.PICK_MEDIA, {
6140
+ return yield this.getJSBridge().callNative(ACTION.PICK_MEDIA, {
6041
6141
  media_type: MediaPickerType[type],
6042
6142
  edit_view: Object.assign(Object.assign({}, defaultEditView), editView),
6043
6143
  silent_request: silentRequest,
@@ -6045,15 +6145,11 @@
6045
6145
  max_select_items: maxSelectItem
6046
6146
  }, {
6047
6147
  isMultiCallback: true,
6048
- callback: (nativeData, error) => {
6049
- var _a;
6050
- if (nativeData.error_code === 0) {
6051
- const res = {
6052
- data: (_a = nativeData.data) === null || _a === void 0 ? void 0 : _a.result_content
6053
- };
6054
- return Promise.resolve(res);
6055
- }
6056
- return Promise.reject(error);
6148
+ successCallback: (data) => {
6149
+ const res = {
6150
+ data: data === null || data === void 0 ? void 0 : data.result_content
6151
+ };
6152
+ return Promise.resolve(res);
6057
6153
  }
6058
6154
  });
6059
6155
  });
@@ -6068,7 +6164,7 @@
6068
6164
  */
6069
6165
  static openOutApp(url) {
6070
6166
  return __awaiter(this, void 0, void 0, function* () {
6071
- return yield this.callNative(ACTION.OPEN_OUTAPP, {
6167
+ return yield this.getJSBridge().callNative(ACTION.OPEN_OUTAPP, {
6072
6168
  url: url
6073
6169
  });
6074
6170
  });
@@ -6107,7 +6203,7 @@
6107
6203
  */
6108
6204
  static sendDataToPreviousMiniApp(object) {
6109
6205
  return __awaiter(this, void 0, void 0, function* () {
6110
- return yield this.callNative(ACTION.WEBVIEW_SET_RESULT, {
6206
+ return yield this.getJSBridge().callNative(ACTION.WEBVIEW_SET_RESULT, {
6111
6207
  result: stringifyData(object.data)
6112
6208
  });
6113
6209
  });
@@ -6132,11 +6228,10 @@
6132
6228
  }
6133
6229
  }
6134
6230
 
6135
- var _ZaloMiniProgramSDKService_zAppId, _ZaloMiniProgramSDKService_appId, _ZaloMiniProgramSDKService_appConfig, _ZaloMiniProgramSDKService_zOAuth, _ZaloMiniProgramSDKService_zOAuthVrf, _ZaloMiniProgramSDKService_accessToken, _ZaloMiniProgramSDKService_refreshToken, _ZaloMiniProgramSDKService_cache, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, _ZaloMiniProgramSDKService_tokenExpiresIn, _ZaloMiniProgramSDKService_cookies, _ZaloMiniProgramSDKService_actionBarConfig, _ZaloMiniProgramSDKService_callJump, _ZaloMiniProgramSDKService_setNavigationBarRightButton, _ZaloMiniProgramSDKService_getActionsSupported;
6136
- class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6231
+ var _ZaloMiniProgramSDKService_zAppId, _ZaloMiniProgramSDKService_appId, _ZaloMiniProgramSDKService_appConfig, _ZaloMiniProgramSDKService_zOAuth, _ZaloMiniProgramSDKService_zOAuthVrf, _ZaloMiniProgramSDKService_accessToken, _ZaloMiniProgramSDKService_refreshToken, _ZaloMiniProgramSDKService_cache, _ZaloMiniProgramSDKService_bridge, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, _ZaloMiniProgramSDKService_tokenExpiresIn, _ZaloMiniProgramSDKService_deviceId, _ZaloMiniProgramSDKService_actionBarConfig, _ZaloMiniProgramSDKService_getActionsSupported;
6232
+ class ZaloMiniProgramSDKService {
6137
6233
  constructor() {
6138
6234
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
6139
- super();
6140
6235
  _ZaloMiniProgramSDKService_zAppId.set(this, ZAPP_ID);
6141
6236
  _ZaloMiniProgramSDKService_appId.set(this, APP_ID);
6142
6237
  _ZaloMiniProgramSDKService_appConfig.set(this, APP_CONFIG);
@@ -6149,9 +6244,10 @@
6149
6244
  getToken: 0
6150
6245
  }
6151
6246
  });
6247
+ _ZaloMiniProgramSDKService_bridge.set(this, void 0);
6152
6248
  _ZaloMiniProgramSDKService_prevGetTokenTimestamp.set(this, void 0);
6153
6249
  _ZaloMiniProgramSDKService_tokenExpiresIn.set(this, void 0);
6154
- _ZaloMiniProgramSDKService_cookies.set(this, null);
6250
+ _ZaloMiniProgramSDKService_deviceId.set(this, void 0);
6155
6251
  this.events = ZMPEEmitter.getInstance();
6156
6252
  this.isIOS = checkPlatform().isIOS;
6157
6253
  _ZaloMiniProgramSDKService_actionBarConfig.set(this, void 0);
@@ -6161,31 +6257,6 @@
6161
6257
  this.setActionBarConfig = (setState) => {
6162
6258
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_actionBarConfig, setState(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_actionBarConfig, "f")), "f");
6163
6259
  };
6164
- _ZaloMiniProgramSDKService_callJump.set(this, () => {
6165
- return new Promise((resolve, reject) => {
6166
- if (!_.isUndefined(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f")) && !_.isNull(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f"))) {
6167
- resolve(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f"));
6168
- }
6169
- else {
6170
- this.callNative(ACTION.JUMP_LOGIN, {})
6171
- .then((data) => {
6172
- const cookies = (data && data.cookiesOAuthLogins) || [];
6173
- const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
6174
- if (jsToken) {
6175
- this.setJSToken(jsToken.value);
6176
- window.ZJSBridge.setJSToken &&
6177
- window.ZJSBridge.setJSToken(jsToken.value);
6178
- }
6179
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_cookies, cookies, "f");
6180
- resolve(cookies);
6181
- })
6182
- .catch((error) => {
6183
- reject(error);
6184
- });
6185
- }
6186
- });
6187
- });
6188
- _ZaloMiniProgramSDKService_setNavigationBarRightButton.set(this, NavigationBar.setNavigationBarRightButton);
6189
6260
  this.getVersion = Basics.getVersion;
6190
6261
  this.getSystemInfo = Basics.getSystemInfo;
6191
6262
  this.setNavigationBarTitle = NavigationBar.setNavigationBarTitle;
@@ -6255,6 +6326,8 @@
6255
6326
  this.isShowNavBar = true;
6256
6327
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, 0, "f");
6257
6328
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, 0, "f");
6329
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_deviceId, '', "f");
6330
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_bridge, ZaloJSBridge.getInstance(), "f");
6258
6331
  const showHomeButton = ((_b = (_a = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_appConfig, "f")) === null || _a === void 0 ? void 0 : _a.app) === null || _b === void 0 ? void 0 : _b.leftButton) === 'home' ||
6259
6332
  ((_d = (_c = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_appConfig, "f")) === null || _c === void 0 ? void 0 : _c.app) === null || _d === void 0 ? void 0 : _d.leftButton) === 'both'
6260
6333
  ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
@@ -6298,9 +6371,19 @@
6298
6371
  getZAppId() {
6299
6372
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zAppId, "f");
6300
6373
  }
6374
+ getDeviceId() {
6375
+ return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_deviceId, "f");
6376
+ }
6377
+ getJSBridge() {
6378
+ return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f");
6379
+ }
6301
6380
  login(object) {
6302
6381
  return __awaiter(this, void 0, void 0, function* () {
6303
- const cookies = yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_callJump, "f").call(this);
6382
+ const cookies = yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").jump();
6383
+ const deviceId = cookies.find((cookie) => cookie.name === COOKIE_NAME.DEVICE_ID);
6384
+ if (deviceId) {
6385
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_deviceId, deviceId.value, "f");
6386
+ }
6304
6387
  const zOAuthCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH);
6305
6388
  const zOAuthVrfCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH_VRF);
6306
6389
  if (!_.isUndefined(zOAuthCookie) &&
@@ -6317,23 +6400,23 @@
6317
6400
  yield this.loginZaloV3();
6318
6401
  }
6319
6402
  if (!__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f")) {
6320
- throw apiResponse.error.loginFailed();
6403
+ throw apiResponse.error.loginFailed('Invalid authorization code');
6321
6404
  }
6322
6405
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
6323
6406
  }
6324
- throw apiResponse.error.loginFailed();
6407
+ throw apiResponse.error.loginFailed('Zalo app has not been activated');
6325
6408
  });
6326
6409
  }
6327
6410
  loginZaloV3() {
6328
6411
  return __awaiter(this, void 0, void 0, function* () {
6329
- return yield fetch(`${APIS.GET_ACCESS_TOKEN_V3}?app_id=${__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zAppId, "f")}&redirect_uri=${MINI_APP_INTERNAL_LINK}/${__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_appId, "f")}/&code=${__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zOAuth, "f")}&isSDK=true123`).then((response) => __awaiter(this, void 0, void 0, function* () {
6412
+ return yield fetch(`${APIS.GET_ACCESS_TOKEN_V3}?app_id=${__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zAppId, "f")}&redirect_uri=${MINI_APP_INTERNAL_LINK}/${__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_appId, "f")}/&code=${__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zOAuth, "f")}&isSDK=true`).then((response) => __awaiter(this, void 0, void 0, function* () {
6330
6413
  let resData = yield response.json();
6331
6414
  if (resData.access_token) {
6332
6415
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_accessToken, resData.access_token, "f");
6333
6416
  const expiresIn = parseInt(resData.expires_in) * 1000;
6334
6417
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, expiresIn, "f");
6335
6418
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, new Date().getTime(), "f");
6336
- this.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6419
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '';
6337
6420
  window.ZJSBridge.setZAccSession &&
6338
6421
  window.ZJSBridge.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6339
6422
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
@@ -6370,7 +6453,7 @@
6370
6453
  const expiresIn = parseInt(resData.expires_in) * 1000;
6371
6454
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, expiresIn, "f");
6372
6455
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, new Date().getTime(), "f");
6373
- this.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6456
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '';
6374
6457
  window.ZJSBridge.setZAccSession &&
6375
6458
  window.ZJSBridge.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6376
6459
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
@@ -6391,7 +6474,7 @@
6391
6474
  });
6392
6475
  }
6393
6476
  }
6394
- _ZaloMiniProgramSDKService_zAppId = new WeakMap(), _ZaloMiniProgramSDKService_appId = new WeakMap(), _ZaloMiniProgramSDKService_appConfig = new WeakMap(), _ZaloMiniProgramSDKService_zOAuth = new WeakMap(), _ZaloMiniProgramSDKService_zOAuthVrf = new WeakMap(), _ZaloMiniProgramSDKService_accessToken = new WeakMap(), _ZaloMiniProgramSDKService_refreshToken = new WeakMap(), _ZaloMiniProgramSDKService_cache = new WeakMap(), _ZaloMiniProgramSDKService_prevGetTokenTimestamp = new WeakMap(), _ZaloMiniProgramSDKService_tokenExpiresIn = new WeakMap(), _ZaloMiniProgramSDKService_cookies = new WeakMap(), _ZaloMiniProgramSDKService_actionBarConfig = new WeakMap(), _ZaloMiniProgramSDKService_callJump = new WeakMap(), _ZaloMiniProgramSDKService_setNavigationBarRightButton = new WeakMap(), _ZaloMiniProgramSDKService_getActionsSupported = new WeakMap();
6477
+ _ZaloMiniProgramSDKService_zAppId = new WeakMap(), _ZaloMiniProgramSDKService_appId = new WeakMap(), _ZaloMiniProgramSDKService_appConfig = new WeakMap(), _ZaloMiniProgramSDKService_zOAuth = new WeakMap(), _ZaloMiniProgramSDKService_zOAuthVrf = new WeakMap(), _ZaloMiniProgramSDKService_accessToken = new WeakMap(), _ZaloMiniProgramSDKService_refreshToken = new WeakMap(), _ZaloMiniProgramSDKService_cache = new WeakMap(), _ZaloMiniProgramSDKService_bridge = new WeakMap(), _ZaloMiniProgramSDKService_prevGetTokenTimestamp = new WeakMap(), _ZaloMiniProgramSDKService_tokenExpiresIn = new WeakMap(), _ZaloMiniProgramSDKService_deviceId = new WeakMap(), _ZaloMiniProgramSDKService_actionBarConfig = new WeakMap(), _ZaloMiniProgramSDKService_getActionsSupported = new WeakMap();
6395
6478
 
6396
6479
  var _MockSDKService_appId, _MockSDKService_appConfig, _MockSDKService_zOAuth, _MockSDKService_accessToken, _MockSDKService_cache, _MockSDKService_loggedId;
6397
6480
  class MockSDKService {
@@ -6412,6 +6495,9 @@
6412
6495
  this.getAppId = () => {
6413
6496
  return __classPrivateFieldGet(this, _MockSDKService_appId, "f");
6414
6497
  };
6498
+ this.getDeviceId = () => {
6499
+ return '';
6500
+ };
6415
6501
  this.login = () => {
6416
6502
  __classPrivateFieldSet(this, _MockSDKService_loggedId, true, "f");
6417
6503
  return Promise.resolve(__classPrivateFieldGet(this, _MockSDKService_zOAuth, "f"));
@@ -6764,90 +6850,175 @@
6764
6850
  .replace(/\s/gi, '')
6765
6851
  .split(',');
6766
6852
  }
6767
- const validate = (target, propertyName, descriptor) => {
6768
- const method = descriptor.value;
6769
- const argsName = getFnParamNames(method);
6770
- descriptor.value = function () {
6771
- const requiredParameters = Reflect.getOwnMetadata(requiredMetadataKey, target, propertyName);
6772
- const checkTypeParameters = Reflect.getOwnMetadata(checkTypeMetadataKey, target, propertyName);
6773
- if (checkTypeParameters) {
6774
- checkTypeParameters.forEach((parameter) => {
6775
- const { parameterIndex, type, properties, defaultValue } = parameter;
6776
- let argument = arguments[parameterIndex];
6777
- let argumentName = argsName[parameterIndex];
6778
- const parameterType = typeof argument;
6779
- if (!_.isUndefined(argument)) {
6780
- if (!isType(argument, type)) {
6781
- throw apiResponse.error.wrongTypeParam(argumentName, type, Array.isArray(argument)
6782
- ? 'array'
6783
- : argument === null
6784
- ? 'null'
6785
- : parameterType);
6853
+ /**
6854
+ * Copies all metadata from one object to another.
6855
+ * Useful for overwriting function definition in
6856
+ * decorators while keeping all previously
6857
+ * attached metadata
6858
+ *
6859
+ * @param from object to copy metadata from
6860
+ * @param to object to copy metadata to
6861
+ */
6862
+ function copyMetadata(from, to) {
6863
+ const metadataKeys = Reflect.getMetadataKeys(from);
6864
+ metadataKeys.map((key) => {
6865
+ const value = Reflect.getMetadata(key, from);
6866
+ Reflect.defineMetadata(key, value, to);
6867
+ });
6868
+ }
6869
+ /**
6870
+ * Apply the given decorator to all class methods
6871
+ *
6872
+ * @param decorator Method decorator to apply to all methods of a class
6873
+ * @param {string[]} options.exclude array of method names that won't be decorated
6874
+ * @param {boolean} options.deep if true, also decorates methods of the extended classes (recusrively)
6875
+ */
6876
+ const DecorateAll = (decorator, options = {}) => {
6877
+ return (target) => {
6878
+ var _a;
6879
+ let descriptors = Object.getOwnPropertyDescriptors(target.prototype);
6880
+ if (options.deep) {
6881
+ let base = Object.getPrototypeOf(target);
6882
+ while (base.prototype) {
6883
+ const baseDescriptors = Object.getOwnPropertyDescriptors(base.prototype);
6884
+ descriptors = Object.assign(Object.assign({}, baseDescriptors), descriptors);
6885
+ base = Object.getPrototypeOf(base);
6886
+ }
6887
+ }
6888
+ for (const [propName, descriptor] of Object.entries(descriptors)) {
6889
+ const isMethod = typeof descriptor.value == 'function' && propName != 'constructor';
6890
+ if ((_a = options.exclude) === null || _a === void 0 ? void 0 : _a.includes(propName))
6891
+ continue;
6892
+ if (options.excludePrefix && propName.startsWith(options.excludePrefix))
6893
+ continue;
6894
+ if (!isMethod)
6895
+ continue;
6896
+ const originalMethod = descriptor.value;
6897
+ decorator(target, propName, descriptor);
6898
+ if (originalMethod != descriptor.value) {
6899
+ copyMetadata(originalMethod, descriptor.value);
6900
+ }
6901
+ Object.defineProperty(target.prototype, propName, descriptor);
6902
+ }
6903
+ };
6904
+ };
6905
+ const centralizedFunctionHandler = (target, propertyName, descriptor) => {
6906
+ const fn = descriptor.value;
6907
+ const argsName = getFnParamNames(fn);
6908
+ descriptor.value = function (...args) {
6909
+ try {
6910
+ // begin validation
6911
+ const requiredParameters = Reflect.getOwnMetadata(requiredMetadataKey, target.prototype, propertyName);
6912
+ const checkTypeParameters = Reflect.getOwnMetadata(checkTypeMetadataKey, target.prototype, propertyName);
6913
+ if (checkTypeParameters) {
6914
+ checkTypeParameters.forEach((parameter) => {
6915
+ const { parameterIndex, type, properties, defaultValue } = parameter;
6916
+ let argument = args[parameterIndex];
6917
+ let argumentName = argsName[parameterIndex];
6918
+ const parameterType = typeof argument;
6919
+ if (!_.isUndefined(argument)) {
6920
+ if (!isType(argument, type)) {
6921
+ throw apiResponse.error.wrongTypeParam(argumentName, type, Array.isArray(argument)
6922
+ ? 'array'
6923
+ : argument === null
6924
+ ? 'null'
6925
+ : parameterType);
6926
+ }
6927
+ if (type === 'object') {
6928
+ Object.entries(properties).forEach(([propKey, propType]) => {
6929
+ const key = propKey.split('?')[0];
6930
+ const propValue = _.get(argument, key);
6931
+ if (!_.isUndefined(propValue) && !_.isNull(propValue)) {
6932
+ if (_.isFunction(propType)) {
6933
+ const res = propType(propValue);
6934
+ if (res && res.error) {
6935
+ throw apiResponse.error.wrongTypeParam(`${argumentName}.${key}`, res.errorMessage, typeof propValue);
6936
+ }
6937
+ }
6938
+ }
6939
+ else if (!propKey.includes('?')) {
6940
+ throw apiResponse.error.missingParam(propKey);
6941
+ }
6942
+ else if (!_.get(argument, key.split('.')[0]) &&
6943
+ defaultValue &&
6944
+ !_.isUndefined(_.get(defaultValue, key))) {
6945
+ _.set(args[parameterIndex], key, _.get(defaultValue, key));
6946
+ }
6947
+ });
6948
+ }
6949
+ }
6950
+ });
6951
+ }
6952
+ if (requiredParameters) {
6953
+ requiredParameters.forEach((parameter) => {
6954
+ const { parameterIndex, option, fields } = parameter;
6955
+ const argument = args[parameterIndex];
6956
+ const condition = option === null || option === void 0 ? void 0 : option.if;
6957
+ const defaultValue = option === null || option === void 0 ? void 0 : option.defaultValue;
6958
+ let isMeetCondition = true;
6959
+ if (condition) {
6960
+ isMeetCondition = Object.keys(condition).every((key) => _.get(argument, key) === condition[key]);
6786
6961
  }
6787
- if (type === 'object') {
6788
- Object.entries(properties).forEach(([propKey, propType]) => {
6789
- const key = propKey.split('?')[0];
6790
- const propValue = _.get(argument, key);
6791
- if (!_.isUndefined(propValue) && !_.isNull(propValue)) {
6792
- if (_.isFunction(propType)) {
6793
- const res = propType(propValue);
6794
- if (res && res.error) {
6795
- throw apiResponse.error.wrongTypeParam(`${argumentName}.${key}`, res.errorMessage, typeof propValue);
6962
+ if (isMeetCondition) {
6963
+ fields.forEach((item) => {
6964
+ const isInValidField = (field) => {
6965
+ let isInValid = false;
6966
+ if (_.isEmpty(_.get(argument, field))) {
6967
+ if (!_.isUndefined(_.get(defaultValue, field))) {
6968
+ _.set(args[parameterIndex], field, _.get(defaultValue, field));
6796
6969
  }
6970
+ isInValid = true;
6797
6971
  }
6972
+ return isInValid;
6973
+ };
6974
+ if (Array.isArray(item) &&
6975
+ item.length > 0 &&
6976
+ item.every(isInValidField)) {
6977
+ throw apiResponse.error.missingParam(item.join(' or '));
6798
6978
  }
6799
- else if (!propKey.includes('?')) {
6800
- throw apiResponse.error.missingParam(propKey);
6801
- }
6802
- else if (_.isObject(_.get(argument, key.split('.')[0])) &&
6803
- defaultValue &&
6804
- !_.isUndefined(_.get(defaultValue, key))) {
6805
- _.set(arguments[parameterIndex], key, _.get(defaultValue, key));
6979
+ else if (_.isString(item) && isInValidField(item)) {
6980
+ throw apiResponse.error.missingParam(item);
6806
6981
  }
6807
6982
  });
6808
6983
  }
6809
- }
6810
- });
6811
- }
6812
- if (requiredParameters) {
6813
- requiredParameters.forEach((parameter) => {
6814
- const { parameterIndex, option, fields } = parameter;
6815
- const argument = arguments[parameterIndex];
6816
- const condition = option === null || option === void 0 ? void 0 : option.if;
6817
- const defaultValue = option === null || option === void 0 ? void 0 : option.defaultValue;
6818
- let isMeetCondition = true;
6819
- if (condition) {
6820
- isMeetCondition = Object.keys(condition).every((key) => _.get(argument, key) === condition[key]);
6821
- }
6822
- if (isMeetCondition) {
6823
- fields.forEach((item) => {
6824
- const isInValidField = (field) => {
6825
- let isInValid = false;
6826
- if (_.isEmpty(_.get(argument, field))) {
6827
- if (!_.isUndefined(_.get(defaultValue, field))) {
6828
- _.set(arguments[parameterIndex], field, _.get(defaultValue, field));
6829
- }
6830
- isInValid = true;
6831
- }
6832
- return isInValid;
6833
- };
6834
- if (Array.isArray(item) && item.length > 0 && item.every(isInValidField)) {
6835
- throw apiResponse.error.missingParam(item.join(' or '));
6984
+ });
6985
+ }
6986
+ // end validation
6987
+ const res = fn.call(this, ...args);
6988
+ if (_.isPromise(res)) {
6989
+ const { success, fail } = Array.isArray(args) && args.length > 0 && args[0];
6990
+ return new Promise((resolve, reject) => {
6991
+ res
6992
+ .then((data) => {
6993
+ if (!_.isNull(success) && _.isFunction(success)) {
6994
+ success.call(null, data, this);
6995
+ }
6996
+ else {
6997
+ resolve(res);
6998
+ }
6999
+ })
7000
+ .catch((error) => {
7001
+ const errorParsed = errorHandler(error, propertyName);
7002
+ if (!_.isNull(fail) && _.isFunction(fail)) {
7003
+ fail.call(null, errorParsed, this);
6836
7004
  }
6837
- else if (_.isString(item) && isInValidField(item)) {
6838
- throw apiResponse.error.missingParam(item);
7005
+ else {
7006
+ reject(errorParsed);
6839
7007
  }
6840
7008
  });
6841
- }
6842
- });
7009
+ });
7010
+ }
7011
+ return res;
7012
+ }
7013
+ catch (error) {
7014
+ throw errorHandler(error, propertyName);
6843
7015
  }
6844
- return method.apply(this, arguments);
6845
7016
  };
6846
7017
  return descriptor;
6847
7018
  };
6848
7019
 
6849
7020
  var _SDKCreator_sdkService;
6850
- class SDKCreator {
7021
+ let SDKCreator = class SDKCreator {
6851
7022
  constructor() {
6852
7023
  this.events = ZMPEEmitter.getInstance();
6853
7024
  _SDKCreator_sdkService.set(this, void 0);
@@ -6908,7 +7079,7 @@
6908
7079
  }
6909
7080
  setNavigationBarTitle(object) {
6910
7081
  return __awaiter(this, void 0, void 0, function* () {
6911
- return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarTitle(object);
7082
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarTitle(object);
6912
7083
  });
6913
7084
  }
6914
7085
  setNavigationBarColor(object) {
@@ -6923,7 +7094,7 @@
6923
7094
  }
6924
7095
  setNavigationBarLeftButton(object) {
6925
7096
  return __awaiter(this, void 0, void 0, function* () {
6926
- return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(object);
7097
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(object.type);
6927
7098
  });
6928
7099
  }
6929
7100
  setDeviceOrientation(object) {
@@ -7178,6 +7349,7 @@
7178
7349
  }
7179
7350
  vibrate(object) {
7180
7351
  return __awaiter(this, void 0, void 0, function* () {
7352
+ console.log(object);
7181
7353
  yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").vibrate(object);
7182
7354
  });
7183
7355
  }
@@ -7322,33 +7494,25 @@
7322
7494
  return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").openOutApp(appStoreURL);
7323
7495
  });
7324
7496
  }
7325
- }
7497
+ onConfirmToExit(callback) {
7498
+ this.events.on(Events.AppClose, callback, '{"handle_h5": 1}');
7499
+ __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(undefined, 2);
7500
+ }
7501
+ offConfirmToExit() {
7502
+ this.events.off(Events.AppClose);
7503
+ __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(undefined, 0);
7504
+ }
7505
+ getDeviceId() {
7506
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceId();
7507
+ }
7508
+ };
7326
7509
  _SDKCreator_sdkService = new WeakMap();
7327
7510
  __decorate([
7328
- handleError
7329
- ], SDKCreator.prototype, "login", null);
7330
- __decorate([
7331
- handleErrorSync
7332
- ], SDKCreator.prototype, "getLoginStatus", null);
7333
- __decorate([
7334
- handleError
7335
- ], SDKCreator.prototype, "getAccessToken", null);
7336
- __decorate([
7337
- handleErrorSync
7338
- ], SDKCreator.prototype, "getVersion", null);
7339
- __decorate([
7340
- handleErrorSync
7341
- ], SDKCreator.prototype, "getSystemInfo", null);
7342
- __decorate([
7343
- handleError,
7344
- validate,
7345
7511
  __param(0, checkType('object', {
7346
7512
  title: checkData('string')
7347
7513
  }))
7348
7514
  ], SDKCreator.prototype, "setNavigationBarTitle", null);
7349
7515
  __decorate([
7350
- handleError,
7351
- validate,
7352
7516
  __param(0, checkType('object', {
7353
7517
  color: checkData('string'),
7354
7518
  'textColor?': checkData('string', { values: ['white', 'black'] }),
@@ -7356,57 +7520,37 @@
7356
7520
  }))
7357
7521
  ], SDKCreator.prototype, "setNavigationBarColor", null);
7358
7522
  __decorate([
7359
- handleError,
7360
- validate,
7361
7523
  __param(0, checkType('object', {
7362
7524
  backgroundColor: checkData('string'),
7363
7525
  'textColor?': checkData('string', { values: ['white', 'black'] })
7364
7526
  }))
7365
7527
  ], SDKCreator.prototype, "setBackgroundColor", null);
7366
7528
  __decorate([
7367
- handleError,
7368
- validate,
7369
7529
  __param(0, checkType('object', {
7370
7530
  type: checkData('string', { values: ['none', 'back', 'home', 'both'] })
7371
7531
  }))
7372
7532
  ], SDKCreator.prototype, "setNavigationBarLeftButton", null);
7373
7533
  __decorate([
7374
- handleError,
7375
- validate,
7376
7534
  __param(0, checkType('object', {
7377
7535
  rotate: checkData('string', { values: ['auto', 'portrait', 'landscape'] })
7378
7536
  }))
7379
7537
  ], SDKCreator.prototype, "setDeviceOrientation", null);
7380
7538
  __decorate([
7381
- handleError,
7382
- validate,
7383
7539
  __param(0, checkType('object', {
7384
7540
  data: checkData('object')
7385
7541
  }))
7386
7542
  ], SDKCreator.prototype, "setStorage", null);
7387
7543
  __decorate([
7388
- handleError,
7389
- validate,
7390
7544
  __param(0, checkType('object', {
7391
7545
  keys: checkData('array<string>')
7392
7546
  }))
7393
7547
  ], SDKCreator.prototype, "getStorage", null);
7394
7548
  __decorate([
7395
- handleError
7396
- ], SDKCreator.prototype, "getStorageInfo", null);
7397
- __decorate([
7398
- handleError,
7399
- validate,
7400
7549
  __param(0, checkType('object', {
7401
7550
  keys: checkData('array<string>')
7402
7551
  }))
7403
7552
  ], SDKCreator.prototype, "removeStorage", null);
7404
7553
  __decorate([
7405
- handleError
7406
- ], SDKCreator.prototype, "clearStorage", null);
7407
- __decorate([
7408
- handleError,
7409
- validate,
7410
7554
  __param(0, checkType('object', {
7411
7555
  'avatarType?': checkData('string', {
7412
7556
  values: ['small', 'normal', 'large']
@@ -7414,75 +7558,19 @@
7414
7558
  }))
7415
7559
  ], SDKCreator.prototype, "getUserInfo", null);
7416
7560
  __decorate([
7417
- handleError
7418
- ], SDKCreator.prototype, "getNetworkType", null);
7419
- __decorate([
7420
- handleError
7421
- ], SDKCreator.prototype, "onNetworkStatusChange", null);
7422
- __decorate([
7423
- handleError
7424
- ], SDKCreator.prototype, "startBeaconDiscovery", null);
7425
- __decorate([
7426
- handleError
7427
- ], SDKCreator.prototype, "stopBeaconDiscovery", null);
7428
- __decorate([
7429
- handleError
7430
- ], SDKCreator.prototype, "getBeacons", null);
7431
- __decorate([
7432
- handleError
7433
- ], SDKCreator.prototype, "closeApp", null);
7434
- __decorate([
7435
- handleError
7436
- ], SDKCreator.prototype, "getLocation", null);
7437
- __decorate([
7438
- handleError
7439
- ], SDKCreator.prototype, "stopBluetoothDevicesDiscovery", null);
7440
- __decorate([
7441
- handleError
7442
- ], SDKCreator.prototype, "startBluetoothDevicesDiscovery", null);
7443
- __decorate([
7444
- handleError
7445
- ], SDKCreator.prototype, "openBluetoothAdapter", null);
7446
- __decorate([
7447
- handleError
7448
- ], SDKCreator.prototype, "onBluetoothDeviceFound", null);
7449
- __decorate([
7450
- handleError
7451
- ], SDKCreator.prototype, "onBluetoothAdapterStateChange", null);
7452
- __decorate([
7453
- handleError
7454
- ], SDKCreator.prototype, "getConnectedBluetoothDevices", null);
7455
- __decorate([
7456
- handleError
7457
- ], SDKCreator.prototype, "getBluetoothDevices", null);
7458
- __decorate([
7459
- handleError
7460
- ], SDKCreator.prototype, "getBluetoothAdapterState", null);
7461
- __decorate([
7462
- handleError
7463
- ], SDKCreator.prototype, "closeBluetoothAdapter", null);
7464
- __decorate([
7465
- handleError
7466
- ], SDKCreator.prototype, "scanQRCode", null);
7467
- __decorate([
7468
- handleError,
7469
- validate,
7470
7561
  __param(0, checkType('object', {
7471
7562
  type: checkData('string', { values: ['user', 'oa', 'aliasOA'] }),
7472
7563
  id: checkData('string')
7473
7564
  }))
7474
7565
  ], SDKCreator.prototype, "openProfile", null);
7475
7566
  __decorate([
7476
- handleError,
7477
- validate,
7478
7567
  __param(0, checkType('object', {
7479
7568
  type: checkData('string', { values: ['user', 'oa'] }),
7480
- id: checkData('string')
7569
+ id: checkData('string'),
7570
+ 'message?': checkData('string')
7481
7571
  }))
7482
7572
  ], SDKCreator.prototype, "openChat", null);
7483
7573
  __decorate([
7484
- handleError,
7485
- validate,
7486
7574
  __param(0, required(['data.imageUrl'], { if: { type: 'image' } })),
7487
7575
  __param(0, required(['data.link'], { if: { type: 'link' } })),
7488
7576
  __param(0, required(['data.id'], { if: { type: 'profile' } })),
@@ -7500,23 +7588,17 @@
7500
7588
  }))
7501
7589
  ], SDKCreator.prototype, "openPostFeed", null);
7502
7590
  __decorate([
7503
- handleError,
7504
- validate,
7505
7591
  __param(0, checkType('object', {
7506
7592
  id: checkData('string'),
7507
7593
  'showDialogConfirm?': checkData('boolean')
7508
7594
  }))
7509
7595
  ], SDKCreator.prototype, "followOA", null);
7510
7596
  __decorate([
7511
- handleError,
7512
- validate,
7513
7597
  __param(0, checkType('object', {
7514
7598
  id: checkData('string')
7515
7599
  }))
7516
7600
  ], SDKCreator.prototype, "unfollowOA", null);
7517
7601
  __decorate([
7518
- handleError,
7519
- validate,
7520
7602
  __param(0, required([['data.imageUrl', 'data.imageUrls']], { if: { type: 'image' } })),
7521
7603
  __param(0, required(['data.link'], { if: { type: 'link' } })),
7522
7604
  __param(0, required(['data.id'], { if: { type: 'oa' } })),
@@ -7555,14 +7637,6 @@
7555
7637
  }))
7556
7638
  ], SDKCreator.prototype, "openShareSheet", null);
7557
7639
  __decorate([
7558
- handleError
7559
- ], SDKCreator.prototype, "requestCameraPermission", null);
7560
- __decorate([
7561
- handleError
7562
- ], SDKCreator.prototype, "createShortcut", null);
7563
- __decorate([
7564
- handleError,
7565
- validate,
7566
7640
  __param(0, checkType('object', {
7567
7641
  secretData: checkData('string'),
7568
7642
  'ui?': checkData('object'),
@@ -7580,44 +7654,28 @@
7580
7654
  }))
7581
7655
  ], SDKCreator.prototype, "openBioAuthentication", null);
7582
7656
  __decorate([
7583
- handleError
7584
- ], SDKCreator.prototype, "checkStateBioAuthentication", null);
7585
- __decorate([
7586
- handleError,
7587
- validate,
7588
7657
  __param(0, checkType('object', {
7589
7658
  toUserId: checkData('string'),
7590
7659
  'title?': checkData('string')
7591
7660
  }))
7592
7661
  ], SDKCreator.prototype, "sendLocation", null);
7593
7662
  __decorate([
7594
- handleError,
7595
- validate,
7596
7663
  __param(0, checkType('object', {
7597
7664
  message: checkData('string')
7598
7665
  }))
7599
7666
  ], SDKCreator.prototype, "showToast", null);
7600
7667
  __decorate([
7601
- handleError
7602
- ], SDKCreator.prototype, "hideKeyboard", null);
7603
- __decorate([
7604
- handleError,
7605
- validate,
7606
7668
  __param(0, checkType('object', {
7607
7669
  phoneNumber: checkData('string')
7608
7670
  }))
7609
7671
  ], SDKCreator.prototype, "openPhone", null);
7610
7672
  __decorate([
7611
- handleError,
7612
- validate,
7613
7673
  __param(0, checkType('object', {
7614
7674
  content: checkData('string'),
7615
7675
  phoneNumber: checkData('string', { regex: /^\+?\d+$/ })
7616
7676
  }))
7617
7677
  ], SDKCreator.prototype, "openSMS", null);
7618
7678
  __decorate([
7619
- handleError,
7620
- validate,
7621
7679
  __param(0, checkType('object', {
7622
7680
  id: checkData('string'),
7623
7681
  'displayName?': checkData('string')
@@ -7626,35 +7684,24 @@
7626
7684
  }))
7627
7685
  ], SDKCreator.prototype, "viewOAQr", null);
7628
7686
  __decorate([
7629
- handleError
7630
- ], SDKCreator.prototype, "keepScreen", null);
7631
- __decorate([
7632
- handleError,
7633
- validate,
7634
7687
  __param(0, checkType('object', {
7635
7688
  'imageBase64Data?': checkData('string'),
7636
7689
  'imageUrl?': checkData('url')
7637
7690
  }))
7638
7691
  ], SDKCreator.prototype, "saveImageToGallery", null);
7639
7692
  __decorate([
7640
- handleError,
7641
- validate,
7642
7693
  __param(0, checkType('object', {
7643
7694
  'imageBase64Data?': checkData('string'),
7644
7695
  'imageUrl?': checkData('url')
7645
7696
  }))
7646
7697
  ], SDKCreator.prototype, "saveImageToPhotosAlbum", null);
7647
7698
  __decorate([
7648
- handleError,
7649
- validate,
7650
7699
  __param(0, checkType('object', {
7651
7700
  appId: checkData('string'),
7652
7701
  'params?': checkData('object')
7653
7702
  }))
7654
7703
  ], SDKCreator.prototype, "openMiniApp", null);
7655
7704
  __decorate([
7656
- handleError,
7657
- validate,
7658
7705
  __param(0, checkType('object', {
7659
7706
  'type?': checkData('string', { values: ['oneShot'] }),
7660
7707
  'milliseconds?': checkData('number')
@@ -7664,30 +7711,11 @@
7664
7711
  }))
7665
7712
  ], SDKCreator.prototype, "vibrate", null);
7666
7713
  __decorate([
7667
- handleError,
7668
- validate,
7669
7714
  __param(0, checkType('object', {
7670
7715
  url: checkData('url')
7671
7716
  }))
7672
7717
  ], SDKCreator.prototype, "openWebview", null);
7673
7718
  __decorate([
7674
- handleErrorSync
7675
- ], SDKCreator.prototype, "getRouteParams", null);
7676
- __decorate([
7677
- handleError
7678
- ], SDKCreator.prototype, "getAppInfo", null);
7679
- __decorate([
7680
- handleError
7681
- ], SDKCreator.prototype, "sendDataToPreviousMiniApp", null);
7682
- __decorate([
7683
- handleError
7684
- ], SDKCreator.prototype, "onCallbackData", null);
7685
- __decorate([
7686
- handleError
7687
- ], SDKCreator.prototype, "getPhoneNumber", null);
7688
- __decorate([
7689
- handleError,
7690
- validate,
7691
7719
  __param(0, checkType('object', {
7692
7720
  'maxProfile?': checkData('number', { min: 1, max: 10 })
7693
7721
  }, {
@@ -7695,8 +7723,6 @@
7695
7723
  }))
7696
7724
  ], SDKCreator.prototype, "openProfilePicker", null);
7697
7725
  __decorate([
7698
- handleError,
7699
- validate,
7700
7726
  __param(0, required(['SSID'])),
7701
7727
  __param(0, checkType('object', {
7702
7728
  SSID: checkData('string'),
@@ -7705,8 +7731,6 @@
7705
7731
  }))
7706
7732
  ], SDKCreator.prototype, "connectWifi", null);
7707
7733
  __decorate([
7708
- handleError,
7709
- validate,
7710
7734
  __param(0, checkType('object', {
7711
7735
  type: checkData('string', {
7712
7736
  values: ['photo', 'video', 'file']
@@ -7721,8 +7745,6 @@
7721
7745
  }))
7722
7746
  ], SDKCreator.prototype, "openMediaPicker", null);
7723
7747
  __decorate([
7724
- handleError,
7725
- validate,
7726
7748
  __param(0, checkType('object', {
7727
7749
  title: checkData('string', { maxLength: 100 }),
7728
7750
  'thumbnail?': checkData('url'),
@@ -7732,14 +7754,9 @@
7732
7754
  description: ''
7733
7755
  }))
7734
7756
  ], SDKCreator.prototype, "getShareableLink", null);
7735
- __decorate([
7736
- handleError,
7737
- validate
7738
- ], SDKCreator.prototype, "closeLoading", null);
7739
- __decorate([
7740
- handleError,
7741
- validate
7742
- ], SDKCreator.prototype, "requestUpdateZalo", null);
7757
+ SDKCreator = __decorate([
7758
+ DecorateAll(centralizedFunctionHandler)
7759
+ ], SDKCreator);
7743
7760
  class ZaloMiniAppSDKCreator extends SDKCreator {
7744
7761
  getServiceInstance() {
7745
7762
  return ZaloMiniProgramSDKService.getInstance();
@@ -7935,7 +7952,7 @@
7935
7952
  _MockPaymentService_appId = new WeakMap();
7936
7953
 
7937
7954
  var _PaymentCreator_instance, _PaymentCreator_sdk;
7938
- class PaymentCreator {
7955
+ let PaymentCreator = class PaymentCreator {
7939
7956
  constructor(sdk) {
7940
7957
  _PaymentCreator_instance.set(this, void 0);
7941
7958
  _PaymentCreator_sdk.set(this, void 0);
@@ -7943,42 +7960,50 @@
7943
7960
  __classPrivateFieldSet(this, _PaymentCreator_sdk, sdk, "f");
7944
7961
  }
7945
7962
  /**
7946
- * Tạo đơn hàng
7947
- *
7948
- * @async
7949
- * @function createOrder
7950
- * @category Payment
7951
- * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
7952
- */
7963
+ * Tạo đơn hàng
7964
+ *
7965
+ * @async
7966
+ * @function createOrder
7967
+ * @category Payment
7968
+ * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
7969
+ */
7953
7970
  createOrder(object) {
7954
7971
  return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").createOrder(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
7955
7972
  }
7956
7973
  /**
7957
- * Lấy thông tin transaction
7958
- *
7959
- * @async
7960
- * @function checkTransaction
7961
- * @category Payment
7962
- * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
7963
- */
7974
+ * Lấy thông tin transaction
7975
+ *
7976
+ * @async
7977
+ * @function checkTransaction
7978
+ * @category Payment
7979
+ * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
7980
+ */
7964
7981
  checkTransaction(object) {
7965
7982
  return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").checkTransaction(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
7966
7983
  }
7967
- }
7984
+ };
7968
7985
  _PaymentCreator_instance = new WeakMap(), _PaymentCreator_sdk = new WeakMap();
7969
7986
  __decorate([
7970
- handleError,
7971
- validate,
7972
7987
  __param(0, checkType('object', {
7973
- 'amount': checkData(['string', 'number']),
7974
- 'desc': checkData('string'),
7975
- 'method?': checkData('string', { values: ['MOMO', 'ZALOPAY', 'MOMO_SANDBOX', 'ZALOPAY_SANDBOX', 'CC', 'CC_SANDBOX', 'ATM', 'ATM_SANDBOX'] })
7988
+ amount: checkData(['string', 'number']),
7989
+ desc: checkData('string'),
7990
+ 'method?': checkData('string', {
7991
+ values: [
7992
+ 'MOMO',
7993
+ 'ZALOPAY',
7994
+ 'MOMO_SANDBOX',
7995
+ 'ZALOPAY_SANDBOX',
7996
+ 'CC',
7997
+ 'CC_SANDBOX',
7998
+ 'ATM',
7999
+ 'ATM_SANDBOX'
8000
+ ]
8001
+ })
7976
8002
  }))
7977
8003
  ], PaymentCreator.prototype, "createOrder", null);
7978
- __decorate([
7979
- handleError,
7980
- validate
7981
- ], PaymentCreator.prototype, "checkTransaction", null);
8004
+ PaymentCreator = __decorate([
8005
+ DecorateAll(centralizedFunctionHandler)
8006
+ ], PaymentCreator);
7982
8007
  class ZaloMiniAppPaymentCreator extends PaymentCreator {
7983
8008
  getInstance() {
7984
8009
  return PaymentService.getInstance();