zmp-sdk 2.19.2 → 2.21.0

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
 
@@ -3263,7 +3342,7 @@
3263
3342
  if (!_.isUndefined(currentVersion)) {
3264
3343
  inputData.currentVersion = currentVersion;
3265
3344
  }
3266
- const api = QueryString.appendToUrl(`${API_DOMAIN}${H5_API.GET_APP_INFO}`, inputData);
3345
+ const api = QueryString.appendToUrl(APIS.GET_APP_INFO, inputData);
3267
3346
  const msgApi = yield fetch(api, {
3268
3347
  credentials: 'include'
3269
3348
  });
@@ -3655,504 +3734,97 @@
3655
3734
  }
3656
3735
  }
3657
3736
 
3658
- var wrappers = {};
3659
- var WrapperFn = function wrapFunction(fn, type, source) {
3660
- var t = type || 'default';
3661
- return function () {
3662
- var callee = t in wrappers ? wrappers[t](fn, source) : fn;
3663
- return callee.apply(this, arguments);
3664
- };
3665
- };
3666
- WrapperFn.setWrapper = function (fn) {
3667
- var type = arguments.length <= 1 || arguments[1] === undefined
3668
- ? 'default'
3669
- : arguments[1];
3670
- wrappers[type] = fn;
3671
- };
3672
- var ERROR = {
3673
- error: {
3674
- code: 1,
3675
- error_subcode: 1357046,
3676
- message: 'Received Invalid JSON reply.',
3677
- type: 'http'
3678
- }
3679
- };
3680
- function safelyParseResponse(rawResponse) {
3681
- try {
3682
- return rawResponse === null ? ERROR : JSON.parse(rawResponse);
3683
- }
3684
- catch (ex) {
3685
- return ERROR;
3737
+ var version = "2.21.0";
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;
3686
3749
  }
3687
- }
3688
- function createCORSRequest(method, url) {
3689
- if (!self.XMLHttpRequest) {
3690
- 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;
3691
3770
  }
3692
- var xhr = new XMLHttpRequest();
3693
- var noop = function noop() { };
3694
- if ('withCredentials' in xhr) {
3695
- xhr.open(method, url, true);
3696
- 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
+ });
3697
3785
  }
3698
- else {
3699
- return null;
3700
- }
3701
- var wrapper = {
3702
- send: function send(data) {
3703
- xhr.send(data);
3704
- }
3705
- };
3706
- var onload = WrapperFn(function () {
3707
- onload = noop;
3708
- if ('onload' in wrapper) {
3709
- wrapper.onload(xhr);
3710
- }
3711
- }, 'entry', 'XMLHttpRequest:load');
3712
- var onerror = WrapperFn(function () {
3713
- onerror = noop;
3714
- if ('onerror' in wrapper) {
3715
- wrapper.onerror(xhr);
3716
- }
3717
- }, 'entry', 'XMLHttpRequest:error');
3718
- xhr.onload = function () {
3719
- onload();
3720
- };
3721
- xhr.onerror = function () {
3722
- onerror();
3723
- };
3724
- xhr.onreadystatechange = function () {
3725
- if (xhr.readyState == 4) {
3726
- if (xhr.status == 200) {
3727
- onload();
3728
- }
3729
- else {
3730
- onerror();
3731
- }
3732
- }
3733
- };
3734
- return wrapper;
3735
- }
3736
- function execute(url, method, params, cb) {
3737
- params.suppress_http_code = 1;
3738
- var data = QueryString.encode(params);
3739
- if (method != 'post') {
3740
- url = QueryString.appendToUrl(url, data);
3741
- data = '';
3742
- }
3743
- var request = createCORSRequest(method, url);
3744
- if (!request) {
3745
- return false;
3746
- }
3747
- request.onload = function (xhr) {
3748
- cb(safelyParseResponse(xhr.responseText));
3749
- };
3750
- request.onerror = function (xhr) {
3751
- if (xhr.responseText) {
3752
- cb(safelyParseResponse(xhr.responseText));
3753
- }
3754
- else {
3755
- cb({
3756
- error: {
3757
- code: 1,
3758
- error_subcode: 1357045,
3759
- message: 'unknown error (empty response)',
3760
- status: xhr.status,
3761
- type: 'http'
3762
- }
3763
- });
3764
- }
3765
- };
3766
- request.send(data);
3767
- return true;
3768
- }
3769
- var CORSRequest = {
3770
- execute: execute
3771
- };
3772
-
3773
- class ZaloJSBridge extends eventemitter3 {
3774
- constructor() {
3775
- super();
3776
- this.debug = Debug('zmp:ZaloJSBridge');
3777
- this.events = ZMPEEmitter.getInstance();
3778
- this._accessTk = getToken('zacc_session') || 'DEFAULT_ACCESS_TOKEN';
3779
- this._jsAccessTk = getToken('zlink3rd') || 'DEFAULT_JS_TOKEN';
3780
- this.results = [];
3781
- this._userAgent = getUserAgent();
3782
- this._device = checkPlatform();
3783
- this._jsCallFuncCallbacks = {};
3784
- this.events.on(Events.AppPaused, () => {
3785
- if (this.results.length > 0) {
3786
- let array = this.results;
3787
- this.results = [];
3788
- try {
3789
- this.sendLogData(array);
3790
- }
3791
- catch (error) { }
3792
- }
3793
- });
3794
- if (this.sendLogTimer) {
3795
- clearInterval(this.sendLogTimer);
3796
- }
3797
- else {
3798
- this.sendLogTimer = setInterval(() => {
3799
- if (this.results.length > 0) {
3800
- let array = this.results;
3801
- this.results = [];
3802
- try {
3803
- this.sendLogData(array);
3804
- }
3805
- catch (error) { }
3806
- }
3807
- }, 5000);
3808
- }
3809
- }
3810
- static getInstance() {
3811
- if (!ZaloJSBridge.instance) {
3812
- ZaloJSBridge.instance = new ZaloJSBridge();
3813
- }
3814
- return ZaloJSBridge.instance;
3815
- }
3816
- set accessTk(value) {
3817
- this._accessTk = value;
3818
- }
3819
- set jsAccessTk(value) {
3820
- this._jsAccessTk = value;
3821
- }
3822
- sendLogData(data) {
3823
- try {
3824
- CORSRequest.execute('https://h5.zalo.me/log/async', 'post', {
3825
- appId: window.APP_ID,
3826
- data: JSON.stringify(data)
3827
- }, (response) => { });
3828
- }
3829
- catch (error) { }
3830
- }
3831
- onJSCall(key, data) {
3832
- try {
3833
- this.debug('onJSCall', key, data);
3834
- const parsedData = parseJSON(data);
3835
- if (this._jsCallFuncCallbacks[key]) {
3836
- const callback = this._jsCallFuncCallbacks[key].callback;
3837
- const timeout = this._jsCallFuncCallbacks[key].timeout;
3838
- if (!!callback) {
3839
- try {
3840
- callback.call(this, parsedData);
3841
- }
3842
- catch (error) {
3843
- console.error('Call callback error', error);
3844
- }
3845
- !!timeout && clearTimeout(timeout);
3846
- this._jsCallFuncCallbacks[key] = null;
3847
- delete this._jsCallFuncCallbacks[key];
3848
- }
3849
- }
3850
- this.results.push({
3851
- action: parsedData.action,
3852
- error: parsedData.error_code
3853
- });
3854
- }
3855
- catch (e) {
3856
- console.log('onJSCall', 'error', e);
3857
- }
3858
- }
3859
- onMultiJSCall(key, data) {
3860
- try {
3861
- this.debug('onMultiJSCall', key, data);
3862
- const parsedData = parseJSON(data);
3863
- if (this._jsCallFuncCallbacks[key]) {
3864
- const callback = this._jsCallFuncCallbacks[key].callback;
3865
- const timeout = this._jsCallFuncCallbacks[key].timeout;
3866
- if (!!callback) {
3867
- try {
3868
- callback.call(this, parsedData);
3869
- }
3870
- catch (error) {
3871
- console.error('Call callback error', error);
3872
- }
3873
- !!timeout && clearTimeout(timeout);
3874
- }
3875
- }
3876
- this.results.push({
3877
- action: parsedData.action,
3878
- error: parsedData.error_code
3879
- });
3880
- }
3881
- catch (e) {
3882
- console.log('onMultiJSCall', 'error', e);
3883
- }
3884
- }
3885
- nativeEventHandler(eventId, eventName, eventData) {
3886
- this.debug(`eventId: ${eventId}, eventName: ${eventName}, eventData: ${eventData}`);
3887
- const data = stringToData(eventData);
3888
- this.debug(data);
3889
- const convertedData = this.handleEventData(eventName, data);
3890
- this.events.emit(eventName, eventId, convertedData);
3891
- }
3892
- handleEventData(eventName, data) {
3893
- try {
3894
- switch (eventName) {
3895
- case Events.OpenApp:
3896
- const { url } = data;
3897
- const validUrl = new URL(url);
3898
- const path = validUrl.pathname.split(`/zapps/${APP_ID}`)[1];
3899
- return {
3900
- path: `${path ? path : '/'}${validUrl.search}`
3901
- };
3902
- break;
3903
- default:
3904
- return data;
3905
- break;
3906
- }
3907
- }
3908
- catch (error) {
3909
- return data;
3910
- }
3911
- }
3912
- defaultCallback(data) {
3913
- if (data !== null && data !== undefined) {
3914
- data = parseJSON(data);
3915
- }
3916
- }
3917
- jsCall(action, options, callback, isMultiCallback = false, nRetry = 3, haveTimeout = true) {
3918
- try {
3919
- const actionName = action.name;
3920
- const key = generateUniqueString(actionName);
3921
- if (!this._device.isMobile || _.isEmpty(actionName)) {
3922
- this.onJSCall(key, {
3923
- error_code: -13,
3924
- error_message: 'params invalid!',
3925
- data: {
3926
- device: this._device.isMobile,
3927
- jsToken: this._jsAccessTk,
3928
- access_token: this._accessTk
3929
- },
3930
- action: actionName
3931
- });
3932
- return false;
3933
- }
3934
- if (options === undefined || options === null) {
3935
- options = {};
3936
- }
3937
- if (!callback) {
3938
- callback = this.defaultCallback;
3939
- }
3940
- const timeoutCallback = {
3941
- error_code: -14,
3942
- error_message: 'Request Timeout!',
3943
- data: {},
3944
- action: actionName
3945
- };
3946
- this._jsCallFuncCallbacks[key] = {
3947
- timeout: haveTimeout &&
3948
- action.have_callback &&
3949
- setTimeout(() => {
3950
- this.onJSCall(key, timeoutCallback);
3951
- }, 8000),
3952
- callback: callback
3953
- };
3954
- try {
3955
- options = serialize(options);
3956
- if (isMultiCallback) {
3957
- if (this._device.isIOS) {
3958
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onMultiJSCall(key));
3959
- }
3960
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onMultiJSCall('${key}')`);
3961
- }
3962
- if (this._device.isIOS) {
3963
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onJSCall(key));
3964
- }
3965
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onJSCall('${key}')`);
3966
- }
3967
- catch (error) {
3968
- if (nRetry-- > 0) {
3969
- setTimeout(() => {
3970
- this.jsCall(action, options, callback, isMultiCallback, nRetry);
3971
- }, 500);
3972
- }
3973
- else {
3974
- const errorCallback = {
3975
- error_code: -5,
3976
- error_message: 'Not ready!',
3977
- data: {
3978
- userAgent: this._userAgent,
3979
- options: options,
3980
- jsToken: this._jsAccessTk,
3981
- access_token: this._accessTk
3982
- },
3983
- action: actionName,
3984
- js_error: error
3985
- };
3986
- this.onJSCall(key, errorCallback);
3987
- return false;
3988
- }
3989
- }
3990
- }
3991
- catch (error) {
3992
- console.log('jsCall', 'error', error);
3993
- }
3994
- return false;
3995
- }
3996
- }
3997
-
3998
- var _ZJSBridgeProvider_bridge;
3999
- /** @ignore */
4000
- class ZJSBridgeProvider {
4001
- /** @ignore */
4002
- constructor() {
4003
- this.debug = Debug('zmp:ZJSBridgeProvider');
4004
- _ZJSBridgeProvider_bridge.set(this, void 0);
4005
- __classPrivateFieldSet(this, _ZJSBridgeProvider_bridge, ZaloJSBridge.getInstance(), "f");
4006
- }
4007
- setZAccSession(value) {
4008
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").accessTk = value;
4009
- }
4010
- setJSToken(value) {
4011
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").jsAccessTk = value;
4012
- }
4013
- callNative(action, data, option) {
4014
- this.debug(action.name, data);
4015
- return new Promise((resolve, reject) => {
4016
- const fn = (cb) => __awaiter(this, void 0, void 0, function* () {
4017
- try {
4018
- const error = new NativeError(cb.error_code, `${cb.action}: ${cb.error_message}`);
4019
- if (option === null || option === void 0 ? void 0 : option.callback) {
4020
- const res = yield option.callback(cb, error);
4021
- return resolve(res);
4022
- }
4023
- else {
4024
- if (cb && cb.error_code >= 0) {
4025
- resolve(cb.data || {});
4026
- }
4027
- else if (cb && cb.error_code < 0) {
4028
- try {
4029
- window.zmpSentry &&
4030
- window.zmpSentry.captureMessage(`${action.name}: call native fail`, {
4031
- extra: {
4032
- data: data,
4033
- rs: cb
4034
- }
4035
- });
4036
- }
4037
- catch (error) { }
4038
- return reject(error);
4039
- }
4040
- }
4041
- }
4042
- catch (error) {
4043
- return reject(error);
4044
- }
4045
- });
4046
- const isIOS = checkPlatform().isIOS;
4047
- const isSupportAction = checkIOSSupportAction(action);
4048
- if (isIOS && !isSupportAction) {
4049
- const error = new NativeError(-5, `${action}: Client isn't support this action`);
4050
- return reject(error);
4051
- }
4052
- else if (option === null || option === void 0 ? void 0 : option.delay) {
4053
- setTimeout(() => {
4054
- __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);
4055
- }, option.delay);
4056
- }
4057
- else {
4058
- __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);
4059
- }
4060
- });
4061
- }
4062
- }
4063
- _ZJSBridgeProvider_bridge = new WeakMap();
4064
-
4065
- var version = "2.19.2";
4066
-
4067
- class Basics {
4068
- /**
4069
- * Lấy version hiện tại của Zalo Mini Program SDK
4070
- *
4071
- * @category Basics
4072
- *
4073
- * @returns {string} Version hiện tại của Zalo Mini Program SDK.
4074
- */
4075
- static getVersion() {
4076
- return version;
4077
- }
4078
- /**
4079
- * Gets system information.
4080
- *
4081
- * @function getSystemInfo
4082
- * @category Basics
4083
- *
4084
- *
4085
- *
4086
- */
4087
- static getSystemInfo() {
4088
- const system = {
4089
- version: getMetaValue('version-id') || '',
4090
- apiVersion: version,
4091
- zaloVersion: getZaloVersion(),
4092
- platform: getPlatform(),
4093
- language: navigator.language,
4094
- zaloLanguage: window.zLanguage || 'vi',
4095
- zaloTheme: window.zTheme || 'light'
4096
- };
4097
- return system;
4098
- }
4099
- /**
4100
- * Lấy thông tin mini app
4101
- *
4102
- * @async
4103
- * @function getAppInfo
4104
- * @category Device
4105
- *
4106
- */
4107
- static getAppInfo() {
4108
- return __awaiter(this, void 0, void 0, function* () {
4109
- const appId = this.getAppId();
4110
- const systemInfo = this.getSystemInfo();
4111
- return yield getAppInfo(appId, 0, systemInfo.version);
4112
- });
4113
- }
4114
- }
4115
-
4116
- class NavigationBar {
4117
- /**
4118
- * A promise for the user's favorite color.
4119
- *
4120
- * @promise FavoriteColorPromise
4121
- * @fulfill {string} The user's favorite color.
4122
- * @reject {TypeError} The user's favorite color is an invalid type.
4123
- * @reject {MissingColorError} The user has not specified a favorite color.
4124
- */
4125
- /**
4126
- * Dynamically sets the title of the current page.
4127
- *
4128
- * @async
4129
- * @function setNavigationBarTitle
4130
- * @category Navigation Bar
4131
- *
4132
- * @example
4133
- *
4134
- * zmpApis.setNavigationBarTitle({
4135
- * title: "Current Page"
4136
- * }).then((res) => {
4137
- * console.log("Success");
4138
- * }).catch((error) => {
4139
- * console.log("Fail");
4140
- * });
4141
- *
4142
- * @param {Object} object
4143
- * @param {string} object.title - The title of the page
4144
- *
4145
- * @return {Promise}
4146
- *
4147
- */
4148
- static setNavigationBarTitle(object) {
4149
- return __awaiter(this, void 0, void 0, function* () {
4150
- yield this.callNative(ACTION.CHANGE_TITLE_HEADER, {
4151
- title: object.title
4152
- }, {
4153
- haveTimeout: false
4154
- });
4155
- });
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
+ });
4156
3828
  }
4157
3829
  /**
4158
3830
  * Sets the color of the navigation bar in the page.
@@ -4195,7 +3867,7 @@
4195
3867
  actionBarType = HIDE_ACTION_BAR;
4196
3868
  }
4197
3869
  this.setActionBarConfig((state) => (Object.assign(Object.assign({}, state), { actionbarType: actionBarType, dataConfig: Object.assign(Object.assign({}, state.dataConfig), dataConfig) })));
4198
- yield this.callNative(ACTION.CHANGE_ACTIONBAR, Object.assign({}, this.getActionBarConfig()), {
3870
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, Object.assign({}, this.getActionBarConfig()), {
4199
3871
  haveTimeout: false
4200
3872
  });
4201
3873
  });
@@ -4230,62 +3902,32 @@
4230
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
4231
3903
  * @param {Function} [object.handleCloseEvent] - Specifies a function that will be called when user click close button. Only when ```confirmToExit``` is 2
4232
3904
  */
4233
- static setNavigationBarLeftButton(object) {
4234
- return __awaiter(this, void 0, void 0, function* () {
4235
- const leftButtonType = object.type === 'none' || object.type === 'home'
4236
- ? ACTION_LEFT_BUTTON_TYPE.HIDE_BACK
4237
- : ACTION_LEFT_BUTTON_TYPE.SHOW_BACK;
4238
- const showHomeButton = object.type === 'home' || object.type === 'both'
4239
- ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
4240
- : ACTION_LEFT_BUTTON_TYPE.HIDE_HOME;
4241
- 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 }) })));
4242
- 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()), {
4243
3921
  haveTimeout: false
4244
3922
  });
4245
3923
  });
4246
3924
  }
4247
- /**
4248
- * @ignore
4249
- * Dynamically sets the right button of the current page.
4250
- *
4251
- * @ignore
4252
- * @category Navigation Bar
4253
- *
4254
- * @example
4255
- * zmpApis.setNavigationBarRightButton({
4256
- * supportToolBar: 1,
4257
- * reset: 0,
4258
- * menuListItems: [{
4259
- * title: "Post on timeline",
4260
- * action: "zalo.web.internal.postfeed",
4261
- * showAsAction: 0,
4262
- * iconUrl: "https://cdn3.iconfinder.com/data/icons/user-interface-3-3/34/251-512.png",
4263
- * type: 0,
4264
- * data: {}
4265
- * }],
4266
- * }).then((res) => {
4267
- * console.log("Success");
4268
- * }).catch((error) => {
4269
- * console.log("Fail");
4270
- * });
4271
- *
4272
- * @param {Object} object
4273
- * @param {Number} object.title - Title of a menu item
4274
- * @param {Number} object.action - Native action
4275
- * @param {string} object.showAsAction
4276
- * If ```showAsAction``` is 1 and ```iconUrl``` can load,
4277
- * this item will be shown outside and next to more-button. Maximum 2 item will be shown
4278
- * @param {Function} object.iconUrl - Specifies icon of a menu item
4279
- * @param {0} object.type
4280
- * @param {Object} object.data - Data depends on ```action```
4281
- */
4282
- static setNavigationBarRightButton(object) {
3925
+ static setNavigationBar(data) {
4283
3926
  return __awaiter(this, void 0, void 0, function* () {
4284
- yield this.callNative(ACTION.CREATE_OPTIONS_MENU, {
4285
- supportToolBar: object.supportToolBar,
4286
- reset: object.reset,
4287
- menuListItems: object.menuListItems,
4288
- zapp: this.getAppId()
3927
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, {
3928
+ data
3929
+ }, {
3930
+ haveTimeout: false
4289
3931
  });
4290
3932
  });
4291
3933
  }
@@ -4317,7 +3959,7 @@
4317
3959
  return __awaiter(this, void 0, void 0, function* () {
4318
3960
  if (_.isString(object.backgroundColor) &&
4319
3961
  object.backgroundColor.length > 0) {
4320
- yield this.callNative(ACTION.CHANGE_ACTIONBAR, {
3962
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, {
4321
3963
  actionbarType: this.isShowNavBar ? 5 : 6,
4322
3964
  dataConfig: {
4323
3965
  backgroundColor: object.backgroundColor,
@@ -4429,7 +4071,7 @@
4429
4071
  */
4430
4072
  static setDeviceOrientation(object) {
4431
4073
  return __awaiter(this, void 0, void 0, function* () {
4432
- yield this.callNative(ACTION.CHANGE_AUTOROTATE, {
4074
+ yield this.getJSBridge().callNative(ACTION.CHANGE_AUTOROTATE, {
4433
4075
  autoRotate: OrientationType[object.rotate]
4434
4076
  });
4435
4077
  });
@@ -4453,7 +4095,7 @@
4453
4095
  */
4454
4096
  static getNetworkType(object) {
4455
4097
  return __awaiter(this, void 0, void 0, function* () {
4456
- const resData = yield this.callNative(ACTION.WEBVIEW_NETWORKTYPE, {
4098
+ const resData = yield this.getJSBridge().callNative(ACTION.WEBVIEW_NETWORKTYPE, {
4457
4099
  url: window.location.href,
4458
4100
  featureId: ''
4459
4101
  }).then((data) => {
@@ -4567,7 +4209,7 @@
4567
4209
  items: Array.isArray(object === null || object === void 0 ? void 0 : object.items) ? object === null || object === void 0 ? void 0 : object.items : []
4568
4210
  }
4569
4211
  };
4570
- yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4212
+ yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4571
4213
  return true;
4572
4214
  });
4573
4215
  }
@@ -4586,7 +4228,7 @@
4586
4228
  const data = {
4587
4229
  subaction: 2
4588
4230
  };
4589
- yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4231
+ yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4590
4232
  return true;
4591
4233
  });
4592
4234
  }
@@ -4607,7 +4249,7 @@
4607
4249
  const data = {
4608
4250
  subaction: 1
4609
4251
  };
4610
- const resData = yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data), {
4252
+ const resData = yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data), {
4611
4253
  isMultiCallback: true
4612
4254
  }).then((resData) => {
4613
4255
  const res = {
@@ -4649,7 +4291,7 @@
4649
4291
  */
4650
4292
  static stopBluetoothDevicesDiscovery() {
4651
4293
  return __awaiter(this, void 0, void 0, function* () {
4652
- return this.callNative({
4294
+ return this.getJSBridge().callNative({
4653
4295
  name: ''
4654
4296
  }, {});
4655
4297
  });
@@ -4676,7 +4318,7 @@
4676
4318
  */
4677
4319
  static startBluetoothDevicesDiscovery(object) {
4678
4320
  return __awaiter(this, void 0, void 0, function* () {
4679
- return this.callNative({
4321
+ return this.getJSBridge().callNative({
4680
4322
  name: ''
4681
4323
  }, Object.assign({}, object));
4682
4324
  });
@@ -4700,7 +4342,7 @@
4700
4342
  */
4701
4343
  static openBluetoothAdapter() {
4702
4344
  return __awaiter(this, void 0, void 0, function* () {
4703
- return this.callNative({
4345
+ return this.getJSBridge().callNative({
4704
4346
  name: ''
4705
4347
  }, {});
4706
4348
  });
@@ -4720,7 +4362,7 @@
4720
4362
  */
4721
4363
  static onBluetoothDeviceFound() {
4722
4364
  return __awaiter(this, void 0, void 0, function* () {
4723
- return this.callNative({
4365
+ return this.getJSBridge().callNative({
4724
4366
  name: ''
4725
4367
  }, {});
4726
4368
  });
@@ -4768,7 +4410,7 @@
4768
4410
  const data = {
4769
4411
  services: object.services || []
4770
4412
  };
4771
- return this.callNative({
4413
+ return this.getJSBridge().callNative({
4772
4414
  name: ''
4773
4415
  }, data);
4774
4416
  });
@@ -4789,7 +4431,7 @@
4789
4431
  */
4790
4432
  static getBluetoothDevices() {
4791
4433
  return __awaiter(this, void 0, void 0, function* () {
4792
- return this.callNative({
4434
+ return this.getJSBridge().callNative({
4793
4435
  name: ''
4794
4436
  }, {});
4795
4437
  });
@@ -4810,7 +4452,7 @@
4810
4452
  */
4811
4453
  static getBluetoothAdapterState() {
4812
4454
  return __awaiter(this, void 0, void 0, function* () {
4813
- return this.callNative({
4455
+ return this.getJSBridge().callNative({
4814
4456
  name: ''
4815
4457
  }, {});
4816
4458
  });
@@ -4831,7 +4473,7 @@
4831
4473
  */
4832
4474
  static closeBluetoothAdapter() {
4833
4475
  return __awaiter(this, void 0, void 0, function* () {
4834
- return this.callNative({
4476
+ return this.getJSBridge().callNative({
4835
4477
  name: ''
4836
4478
  }, {});
4837
4479
  });
@@ -4845,7 +4487,7 @@
4845
4487
  */
4846
4488
  static scanQRCode(object) {
4847
4489
  return __awaiter(this, void 0, void 0, function* () {
4848
- return yield this.callNative(ACTION.OPEN_QR, {
4490
+ return yield this.getJSBridge().callNative(ACTION.OPEN_QR, {
4849
4491
  skipOpenLink: true
4850
4492
  });
4851
4493
  });
@@ -4859,308 +4501,770 @@
4859
4501
  */
4860
4502
  static showToast(object) {
4861
4503
  return __awaiter(this, void 0, void 0, function* () {
4862
- yield this.callNative(ACTION.SHOW_TOAST, {
4504
+ yield this.getJSBridge().callNative(ACTION.SHOW_TOAST, {
4863
4505
  toast: object.message
4864
4506
  });
4865
4507
  });
4866
4508
  }
4867
- /**
4868
- * Ẩn keyboard
4869
- * @async
4870
- * @function hideKeyboard
4871
- * @category Device
4872
- *
4873
- */
4874
- 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() {
4875
4743
  return __awaiter(this, void 0, void 0, function* () {
4876
- yield this.callNative(ACTION.HIDE_KEYBOARD, {});
4744
+ return Promise.resolve(this.getInfoSync());
4877
4745
  });
4878
4746
  }
4879
- /**
4880
- * Open phone
4881
- * @async
4882
- * @function openPhone
4883
- * @category Device
4884
- *
4885
- */
4886
- 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) {
4887
4757
  return __awaiter(this, void 0, void 0, function* () {
4888
- yield this.callNative(ACTION.OPEN_PHONE, {
4889
- phoneNum: object.phoneNumber,
4890
- phoneCode: object.phoneNumber
4758
+ keys.forEach((key) => {
4759
+ this.removeSync(key);
4891
4760
  });
4761
+ return Promise.resolve({ errorKeys: [] });
4892
4762
  });
4893
4763
  }
4894
- /**
4895
- * Open SMS
4896
- * @async
4897
- * @function openSMS
4898
- * @category Device
4899
- *
4900
- */
4901
- 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() {
4902
4774
  return __awaiter(this, void 0, void 0, function* () {
4903
- yield this.callNative(ACTION.OPEN_SMS, {
4904
- content: object.content,
4905
- phoneCode: object.phoneNumber
4906
- });
4775
+ return Promise.resolve(this.clearSync());
4907
4776
  });
4908
4777
  }
4909
- /**
4910
- * Keep screen.
4911
- * @async
4912
- * @function keepScreen
4913
- * @category Device
4914
- *
4915
- */
4916
- static keepScreen(object) {
4917
- return __awaiter(this, void 0, void 0, function* () {
4918
- return yield this.callNative(ACTION.KEEP_SCREEN, {
4919
- data: {
4920
- keep_screen_on: object.keepScreenOn ? 1 : 0
4921
- }
4922
- });
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);
4923
4785
  });
4924
4786
  }
4925
- /**
4926
- * Xác thực bằng sinh trắc học
4927
- * @async
4928
- * @function openBioAuthentication
4929
- * @category Authentication
4930
- *
4931
- */
4932
- static openBioAuthentication(object) {
4933
- return __awaiter(this, void 0, void 0, function* () {
4934
- return yield this.callNative(ACTION.PROMPT_AUTHENTICATION, {
4935
- secret_data: object.secretData,
4936
- app_id: this.getZAppId(),
4937
- ui: {
4938
- title: object.ui.title,
4939
- sub_title: object.ui.subTitle,
4940
- negative_text: object.ui.negativeButtonText
4941
- },
4942
- require_fingerprint: object.requireFingerprint ? 1 : 0
4943
- }).then((data) => {
4944
- var _a, _b, _c, _d;
4945
- return {
4946
- code: data === null || data === void 0 ? void 0 : data.error_code,
4947
- message: data === null || data === void 0 ? void 0 : data.error_message,
4948
- data: {
4949
- domain: (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.domain,
4950
- code: (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.error_code,
4951
- message: (_c = data === null || data === void 0 ? void 0 : data.data) === null || _c === void 0 ? void 0 : _c.error_message,
4952
- payToken: (_d = data === null || data === void 0 ? void 0 : data.data) === null || _d === void 0 ? void 0 : _d.pay_token
4953
- }
4954
- };
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
+ }
4955
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
+ }
4956
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
+ }
4957
4985
  }
4958
- /**
4959
- * 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...)
4960
- * @async
4961
- * @function checkStateBioAuthentication
4962
- * @category Authentication
4963
- *
4964
- * @example
4965
- * api.checkStateAuthen({
4966
- * success: (res) => {},
4967
- * fail: (err) => {}
4968
- * })
4969
- * @param {InputDataType.CallbackType} object
4970
- */
4971
- static checkStateBioAuthentication(object) {
4972
- return __awaiter(this, void 0, void 0, function* () {
4973
- 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) => {
4974
5001
  return {
4975
- bioState: data === null || data === void 0 ? void 0 : data.bio_state
5002
+ action: item.action,
5003
+ error: item.error
4976
5004
  };
4977
5005
  });
4978
- });
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) { }
4979
5018
  }
4980
- /**
4981
- * Vibrate.
4982
- * @async
4983
- * @function vibrate
4984
- * @category Device
4985
- *
4986
- */
4987
- static vibrate(object) {
4988
- return __awaiter(this, void 0, void 0, function* () {
4989
- return yield this.callNative(ACTION.INTERACTIVE_VIBRATION, {
4990
- type: VibrateType[object.type],
4991
- 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
4992
5042
  });
4993
- });
5043
+ }
5044
+ catch (e) {
5045
+ console.log('onJSCall', 'error', e);
5046
+ }
4994
5047
  }
4995
- /**
4996
- * Connect Wifi.
4997
- * @async
4998
- * @function connectWifi
4999
- * @category Device
5000
- *
5001
- */
5002
- static connectWifi(object) {
5003
- return __awaiter(this, void 0, void 0, function* () {
5004
- let securityType = 'open';
5005
- if (_.isString(object.password) && object.password.length > 0) {
5006
- 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
+ }
5007
5064
  }
5008
- return yield this.callNative(ACTION.MP_JOIN_WIFI, {
5009
- ssid: object.SSID,
5010
- securityType: securityType,
5011
- password: object.password,
5012
- hiddenSsid: object.hiddenSSID
5065
+ this.results.push({
5066
+ action: parsedData.action,
5067
+ error: parsedData.error_code,
5068
+ message: parsedData.error_message
5013
5069
  });
5014
- });
5015
- }
5016
- /**
5017
- * Open App Store.
5018
- * @async
5019
- * @function openAppStore
5020
- * @category Device
5021
- *
5022
- */
5023
- static openAppStore(object) {
5024
- return __awaiter(this, void 0, void 0, function* () {
5025
- return yield this.callNative(ACTION.OPEN_APPSTORE, object);
5026
- });
5070
+ }
5071
+ catch (e) {
5072
+ console.log('onMultiJSCall', 'error', e);
5073
+ }
5027
5074
  }
5028
- }
5029
-
5030
- var _LocalResourceStorage_storage, _LocalResourceStorage_prefix, _LocalResourceStorage_resourceInfo;
5031
- class LocalResourceStorage {
5032
- constructor(prefix) {
5033
- _LocalResourceStorage_storage.set(this, localStorage);
5034
- _LocalResourceStorage_prefix.set(this, void 0);
5035
- _LocalResourceStorage_resourceInfo.set(this, void 0);
5036
- checkPlatform();
5037
- // if (platform.isMobile && platform.isZalo) {
5038
- // Object.defineProperty(window, 'localStorage', {
5039
- // value: null,
5040
- // configurable: true,
5041
- // enumerable: true,
5042
- // writable: false
5043
- // });
5044
- // }
5045
- __classPrivateFieldSet(this, _LocalResourceStorage_resourceInfo, {
5046
- keys: new Set(),
5047
- currentSize: 0,
5048
- limitSize: STORAGE_LIMIT
5049
- }, "f");
5050
- __classPrivateFieldSet(this, _LocalResourceStorage_prefix, prefix, "f");
5051
- 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);
5052
5081
  }
5053
- findAllCurrentDataByApp(prefix) {
5082
+ handleEventData(eventName, data) {
5054
5083
  try {
5055
- let _x;
5056
- for (_x in __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f")) {
5057
- if (prefix) {
5058
- const _prefix = _x.split('_')[0];
5059
- if (_prefix !== prefix) {
5060
- continue;
5061
- }
5062
- }
5063
- __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;
5064
5096
  }
5065
5097
  }
5066
5098
  catch (error) {
5067
- logger.error(error, 'LocalResourceStorage > findAllCurrentDataByApp');
5099
+ return data;
5068
5100
  }
5069
5101
  }
5070
- get(keys) {
5071
- let res = new Map();
5072
- keys.forEach((key) => {
5073
- res.set(key, this.getSync(key));
5074
- });
5075
- return Promise.resolve(res);
5076
- }
5077
- getSync(key) {
5078
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5079
- key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
5102
+ defaultCallback(data) {
5103
+ if (data !== null && data !== undefined) {
5104
+ data = parseJSON(data);
5080
5105
  }
5081
- if (!__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key))
5082
- return null;
5083
- return __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").getItem(key);
5084
5106
  }
5085
- set(data) {
5086
- return __awaiter(this, void 0, void 0, function* () {
5087
- Object.entries(data).forEach(([key, value]) => {
5088
- 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
+ }
5089
5152
  });
5090
- 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
+ }
5091
5167
  });
5092
5168
  }
5093
- setSync(key, value) {
5094
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5095
- 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;
5096
5186
  }
5097
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").setItem(key, value);
5098
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(key);
5099
- }
5100
- getInfo() {
5101
- return __awaiter(this, void 0, void 0, function* () {
5102
- return Promise.resolve(this.getInfoSync());
5103
- });
5104
- }
5105
- getInfoSync() {
5106
- const currentSize = calcLocalStorageSize(__classPrivateFieldGet(this, _LocalResourceStorage_storage, "f"), __classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f"));
5107
- return {
5108
- currentSize: _.isNumber(currentSize)
5109
- ? Number((currentSize / 1024).toFixed(2))
5110
- : 0,
5111
- 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
5112
5198
  };
5113
- }
5114
- remove(keys) {
5115
- return __awaiter(this, void 0, void 0, function* () {
5116
- keys.forEach((key) => {
5117
- this.removeSync(key);
5118
- });
5119
- return Promise.resolve({ errorKeys: [] });
5120
- });
5121
- }
5122
- removeSync(key) {
5123
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5124
- 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}')`);
5125
5219
  }
5126
- if (__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key)) {
5127
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
5128
- __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
+ }
5129
5242
  }
5130
5243
  }
5131
- clear() {
5132
- return __awaiter(this, void 0, void 0, function* () {
5133
- return Promise.resolve(this.clearSync());
5134
- });
5135
- }
5136
- clearSync() {
5137
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.forEach((key) => {
5138
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f") && key.indexOf(__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) < 0) {
5139
- return;
5140
- }
5141
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
5142
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
5143
- });
5244
+ catch (error) {
5245
+ console.log('jsCall', 'error', error);
5144
5246
  }
5145
- }
5146
- _LocalResourceStorage_storage = new WeakMap(), _LocalResourceStorage_prefix = new WeakMap(), _LocalResourceStorage_resourceInfo = new WeakMap();
5247
+ return false;
5248
+ };
5147
5249
 
5148
- var _NativeResourceStorage_appId, _NativeResourceStorage_resourceInfo;
5149
- class NativeResourceStorage extends ZJSBridgeProvider {
5250
+ var _NativeResourceStorage_appId, _NativeResourceStorage_resourceInfo, _NativeResourceStorage_bridge;
5251
+ class NativeResourceStorage {
5150
5252
  constructor(appId) {
5151
- super();
5152
5253
  _NativeResourceStorage_appId.set(this, void 0);
5153
5254
  _NativeResourceStorage_resourceInfo.set(this, void 0);
5255
+ _NativeResourceStorage_bridge.set(this, void 0);
5154
5256
  __classPrivateFieldSet(this, _NativeResourceStorage_resourceInfo, {
5155
5257
  keys: new Set(),
5156
5258
  currentSize: 0,
5157
5259
  limitSize: STORAGE_LIMIT
5158
5260
  }, "f");
5159
5261
  __classPrivateFieldSet(this, _NativeResourceStorage_appId, appId, "f");
5262
+ __classPrivateFieldSet(this, _NativeResourceStorage_bridge, ZaloJSBridge.getInstance(), "f");
5160
5263
  }
5161
5264
  get(keys) {
5162
5265
  return __awaiter(this, void 0, void 0, function* () {
5163
- return yield this.callNative(ACTION.ZBROWSER_MPDS, {
5266
+ return yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5267
+ .callNative(ACTION.ZBROWSER_MPDS, {
5164
5268
  mpds_action: 'mpds.get',
5165
5269
  mpds_data: {
5166
5270
  keys
@@ -5168,7 +5272,8 @@
5168
5272
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5169
5273
  }, {
5170
5274
  isMultiCallback: false
5171
- }).then((data) => {
5275
+ })
5276
+ .then((data) => {
5172
5277
  let res = new Map();
5173
5278
  if (data && data.mpds_data && data.mpds_data.map) {
5174
5279
  res = new Map(Object.entries(data.mpds_data.map));
@@ -5179,7 +5284,8 @@
5179
5284
  }
5180
5285
  set(data) {
5181
5286
  return __awaiter(this, void 0, void 0, function* () {
5182
- const errorKeys = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5287
+ const errorKeys = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5288
+ .callNative(ACTION.ZBROWSER_MPDS, {
5183
5289
  mpds_action: 'mpds.set',
5184
5290
  mpds_data: {
5185
5291
  map: data
@@ -5187,7 +5293,8 @@
5187
5293
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5188
5294
  }, {
5189
5295
  isMultiCallback: false
5190
- }).then((data) => {
5296
+ })
5297
+ .then((data) => {
5191
5298
  let res = [];
5192
5299
  if (data && data.mpds_data && data.mpds_data.error_keys) {
5193
5300
  res = data.mpds_data.error_keys;
@@ -5199,13 +5306,15 @@
5199
5306
  }
5200
5307
  getInfo() {
5201
5308
  return __awaiter(this, void 0, void 0, function* () {
5202
- const currentSize = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5309
+ const currentSize = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5310
+ .callNative(ACTION.ZBROWSER_MPDS, {
5203
5311
  mpds_action: 'mpds.get.size',
5204
5312
  mpds_data: {},
5205
5313
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5206
5314
  }, {
5207
5315
  isMultiCallback: false
5208
- }).then((data) => {
5316
+ })
5317
+ .then((data) => {
5209
5318
  let res = 0;
5210
5319
  if (data && data.mpds_data && data.mpds_data.size) {
5211
5320
  res = data.mpds_data.size;
@@ -5220,7 +5329,8 @@
5220
5329
  }
5221
5330
  remove(keys) {
5222
5331
  return __awaiter(this, void 0, void 0, function* () {
5223
- const errorKeys = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5332
+ const errorKeys = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5333
+ .callNative(ACTION.ZBROWSER_MPDS, {
5224
5334
  mpds_action: 'mpds.remove.key',
5225
5335
  mpds_data: {
5226
5336
  keys: keys
@@ -5228,7 +5338,8 @@
5228
5338
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5229
5339
  }, {
5230
5340
  isMultiCallback: false
5231
- }).then((data) => {
5341
+ })
5342
+ .then((data) => {
5232
5343
  let res = [];
5233
5344
  if (data && data.mpds_data && data.mpds_data.error_keys) {
5234
5345
  res = data.mpds_data.error_keys;
@@ -5240,7 +5351,7 @@
5240
5351
  }
5241
5352
  clear() {
5242
5353
  return __awaiter(this, void 0, void 0, function* () {
5243
- yield this.callNative(ACTION.ZBROWSER_MPDS, {
5354
+ yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f").callNative(ACTION.ZBROWSER_MPDS, {
5244
5355
  mpds_action: 'mpds.clear.appData',
5245
5356
  mpds_data: {},
5246
5357
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
@@ -5248,7 +5359,7 @@
5248
5359
  });
5249
5360
  }
5250
5361
  }
5251
- _NativeResourceStorage_appId = new WeakMap(), _NativeResourceStorage_resourceInfo = new WeakMap();
5362
+ _NativeResourceStorage_appId = new WeakMap(), _NativeResourceStorage_resourceInfo = new WeakMap(), _NativeResourceStorage_bridge = new WeakMap();
5252
5363
 
5253
5364
  var _LocalStorageCreator_appId, _NativeStorageCreator_appId;
5254
5365
  class StorageCreator {
@@ -5500,18 +5611,13 @@
5500
5611
  */
5501
5612
  static getPhoneNumber(object) {
5502
5613
  return __awaiter(this, void 0, void 0, function* () {
5503
- return yield this.callNative(ACTION.MP_GET_NUMBER, {}, {
5614
+ return yield this.getJSBridge().callNative(ACTION.MP_GET_NUMBER, {}, {
5504
5615
  isMultiCallback: true,
5505
- callback: (nativeData, error) => {
5506
- if (nativeData.error_code === 0) {
5507
- const res = {
5508
- number: nativeData.data
5509
- };
5510
- return Promise.resolve(res);
5511
- }
5512
- else {
5513
- return Promise.reject(error);
5514
- }
5616
+ successCallback: (data) => {
5617
+ const res = {
5618
+ number: data
5619
+ };
5620
+ return Promise.resolve(res);
5515
5621
  },
5516
5622
  delay: this.isIOS ? 400 : 0
5517
5623
  });
@@ -5530,7 +5636,7 @@
5530
5636
  */
5531
5637
  static closeApp(object) {
5532
5638
  return __awaiter(this, void 0, void 0, function* () {
5533
- yield this.callNative(ACTION.WINDOW_CLOSE, {});
5639
+ yield this.getJSBridge().callNative(ACTION.WINDOW_CLOSE, {});
5534
5640
  });
5535
5641
  }
5536
5642
  /**
@@ -5562,7 +5668,7 @@
5562
5668
  mpInfo.appName = appInfo.name;
5563
5669
  mpInfo.appAvtUrl = appInfo.logoUrl;
5564
5670
  }
5565
- yield this.callNative(ACTION.OPEN_MP, {
5671
+ yield this.getJSBridge().callNative(ACTION.OPEN_MP, {
5566
5672
  mpUrl: `${MINI_APP_INTERNAL_LINK}/${appId}/${queryParamString.length > 0 ? '?' + queryParamString : ''}`,
5567
5673
  mpInfo: mpInfo
5568
5674
  });
@@ -5578,7 +5684,7 @@
5578
5684
  */
5579
5685
  static openWebview(url) {
5580
5686
  return __awaiter(this, void 0, void 0, function* () {
5581
- yield this.callNative(ACTION.OPEN_INAPP, {
5687
+ yield this.getJSBridge().callNative(ACTION.OPEN_INAPP, {
5582
5688
  url: url
5583
5689
  });
5584
5690
  });
@@ -5593,7 +5699,7 @@
5593
5699
  */
5594
5700
  static closeLoading(when) {
5595
5701
  return __awaiter(this, void 0, void 0, function* () {
5596
- yield this.callNative(ACTION.MP_CLOSE_LOADINGVIEW, {
5702
+ yield this.getJSBridge().callNative(ACTION.MP_CLOSE_LOADINGVIEW, {
5597
5703
  at: new Date().getTime(),
5598
5704
  when: when,
5599
5705
  url: location.href
@@ -5620,30 +5726,24 @@
5620
5726
  */
5621
5727
  static getLocation(object) {
5622
5728
  return __awaiter(this, void 0, void 0, function* () {
5623
- return yield this.callNative(ACTION.GET_LOCATION, {
5729
+ return yield this.getJSBridge().callNative(ACTION.GET_LOCATION, {
5624
5730
  silent_request: false,
5625
5731
  permission_description: 'Cho phép Zalo truy cập vào vị trí của thiết bị này?'
5626
5732
  }, {
5627
5733
  isMultiCallback: true,
5628
5734
  haveTimeout: false,
5629
- callback: (nativeData, error) => {
5630
- if (nativeData.error_code === 0) {
5631
- const data = nativeData.data;
5632
- const res = {
5633
- /** latitude */
5634
- latitude: data.latitude,
5635
- /** longitude */
5636
- longitude: data.longitude,
5637
- /** timestamp */
5638
- timestamp: data.timestamp,
5639
- /** provider */
5640
- provider: data.provider
5641
- };
5642
- return Promise.resolve(res);
5643
- }
5644
- else {
5645
- return Promise.reject(error);
5646
- }
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);
5647
5747
  },
5648
5748
  delay: this.isIOS ? 400 : 0
5649
5749
  });
@@ -5659,7 +5759,7 @@
5659
5759
  */
5660
5760
  static sendLocation(object) {
5661
5761
  return __awaiter(this, void 0, void 0, function* () {
5662
- yield this.callNative(ACTION.QUERY_LOCATION_HIDE, {
5762
+ yield this.getJSBridge().callNative(ACTION.QUERY_LOCATION_HIDE, {
5663
5763
  title: object.title,
5664
5764
  touserid: object.toUserId,
5665
5765
  zapp: this.getZAppId()
@@ -5679,17 +5779,12 @@
5679
5779
  */
5680
5780
  static requestCameraPermission(object) {
5681
5781
  return __awaiter(this, void 0, void 0, function* () {
5682
- return yield this.callNative(ACTION.REQUEST_PERMISSION_CAMERA, {}, {
5683
- callback: (nativeData, error) => {
5684
- if (nativeData.error_code === -2 || nativeData.error_code >= 0) {
5685
- return Promise.resolve({
5686
- userAllow: nativeData.error_code === -2 ? false : true,
5687
- message: nativeData.error_message
5688
- });
5689
- }
5690
- else {
5691
- return Promise.reject(error);
5692
- }
5782
+ return yield this.getJSBridge().callNative(ACTION.REQUEST_PERMISSION_CAMERA, {}, {
5783
+ successCallback: () => {
5784
+ return Promise.resolve({
5785
+ userAllow: true,
5786
+ message: 'User Allow'
5787
+ });
5693
5788
  }
5694
5789
  });
5695
5790
  });
@@ -5715,7 +5810,7 @@
5715
5810
  imageUrl: object.imageUrl
5716
5811
  };
5717
5812
  }
5718
- return yield this.callNative(ACTION.SAVE_IMAGE_GALLERY, Object.assign({}, data));
5813
+ return yield this.getJSBridge().callNative(ACTION.SAVE_IMAGE_GALLERY, Object.assign({}, data));
5719
5814
  });
5720
5815
  }
5721
5816
  }
@@ -5730,7 +5825,7 @@
5730
5825
  */
5731
5826
  static viewOAQr(object) {
5732
5827
  return __awaiter(this, void 0, void 0, function* () {
5733
- yield this.callNative(ACTION.VIEW_MYQR, {
5828
+ yield this.getJSBridge().callNative(ACTION.VIEW_MYQR, {
5734
5829
  dpn: object.displayName,
5735
5830
  uid: object.id,
5736
5831
  zapp: this.getZAppId()
@@ -5749,7 +5844,7 @@
5749
5844
  */
5750
5845
  static openProfile(object) {
5751
5846
  return __awaiter(this, void 0, void 0, function* () {
5752
- return yield this.callNative(ACTION.OPEN_PROFILE, {
5847
+ return yield this.getJSBridge().callNative(ACTION.OPEN_PROFILE, {
5753
5848
  uId: object.id,
5754
5849
  type: ProfileType[object.type],
5755
5850
  zapp: this.getZAppId(),
@@ -5767,9 +5862,10 @@
5767
5862
  */
5768
5863
  static openChat(object) {
5769
5864
  return __awaiter(this, void 0, void 0, function* () {
5770
- return yield this.callNative(ACTION.OPEN_CHAT, {
5865
+ return yield this.getJSBridge().callNative(ACTION.OPEN_CHAT, {
5771
5866
  uId: object.id,
5772
5867
  type: ChatType[object.type],
5868
+ msg: object.message || '',
5773
5869
  zapp: this.getZAppId(),
5774
5870
  sourceId: object.sourceId,
5775
5871
  sourceIndex: object.sourceIndex
@@ -5808,7 +5904,9 @@
5808
5904
  };
5809
5905
  break;
5810
5906
  }
5811
- 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) => {
5812
5910
  return {
5813
5911
  status: res.status,
5814
5912
  shareType: res.share_type,
@@ -5827,7 +5925,7 @@
5827
5925
  */
5828
5926
  static followOA(object) {
5829
5927
  return __awaiter(this, void 0, void 0, function* () {
5830
- yield this.callNative(ACTION.FOLLOW_OA, {
5928
+ yield this.getJSBridge().callNative(ACTION.FOLLOW_OA, {
5831
5929
  uid: object.id,
5832
5930
  showDialogConfirm: true,
5833
5931
  zapp: this.getZAppId()
@@ -5846,7 +5944,7 @@
5846
5944
  */
5847
5945
  static unfollowOA(object) {
5848
5946
  return __awaiter(this, void 0, void 0, function* () {
5849
- yield this.callNative(ACTION.UNFOLLOW_OA, {
5947
+ yield this.getJSBridge().callNative(ACTION.UNFOLLOW_OA, {
5850
5948
  uid: object.id,
5851
5949
  zapp: this.getZAppId()
5852
5950
  }, {
@@ -5868,7 +5966,8 @@
5868
5966
  switch (object.type) {
5869
5967
  case 'image':
5870
5968
  let photoUrls = [];
5871
- if (Array.isArray(object.data.imageUrls) && object.data.imageUrls.length > 0) {
5969
+ if (Array.isArray(object.data.imageUrls) &&
5970
+ object.data.imageUrls.length > 0) {
5872
5971
  photoUrls = object.data.imageUrls;
5873
5972
  }
5874
5973
  else {
@@ -5935,9 +6034,11 @@
5935
6034
  object.type = 'link';
5936
6035
  }
5937
6036
  }
5938
- 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() }), {
5939
6039
  haveTimeout: false
5940
- }).then((res) => {
6040
+ })
6041
+ .then((res) => {
5941
6042
  return {
5942
6043
  status: res.status,
5943
6044
  shareType: res.share_type,
@@ -5956,7 +6057,7 @@
5956
6057
  */
5957
6058
  static createShortcut(url, title, icon) {
5958
6059
  return __awaiter(this, void 0, void 0, function* () {
5959
- return yield this.callNative(ACTION.CREATE_SHORTCUT, {
6060
+ return yield this.getJSBridge().callNative(ACTION.CREATE_SHORTCUT, {
5960
6061
  url: url,
5961
6062
  title: title,
5962
6063
  iconUrl: icon
@@ -5973,15 +6074,14 @@
5973
6074
  */
5974
6075
  static openProfilePicker(maxProfile) {
5975
6076
  return __awaiter(this, void 0, void 0, function* () {
5976
- return yield this.callNative(ACTION.MP_OPEN_PROFILE_PICKER, {
6077
+ return yield this.getJSBridge().callNative(ACTION.MP_OPEN_PROFILE_PICKER, {
5977
6078
  maxProfile: maxProfile
5978
6079
  }, {
5979
6080
  isMultiCallback: true,
5980
- callback: (nativeData, error) => {
5981
- if (nativeData.error_code === 0 && Array.isArray(nativeData.data)) {
5982
- 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));
5983
6084
  }
5984
- return Promise.reject(error);
5985
6085
  }
5986
6086
  });
5987
6087
  });
@@ -5996,15 +6096,15 @@
5996
6096
  */
5997
6097
  static getActionsSupported(object) {
5998
6098
  return __awaiter(this, void 0, void 0, function* () {
5999
- return yield this.callNative(ACTION.GET_SUPPORTED_ACTIONS, {}, {
6099
+ return yield this.getJSBridge().callNative(ACTION.GET_SUPPORTED_ACTIONS, {}, {
6000
6100
  isMultiCallback: false,
6001
- callback: (nativeData, error) => {
6101
+ successCallback: (data) => {
6002
6102
  const platform = getPlatform();
6003
- if (Array.isArray(nativeData.actions) &&
6004
- nativeData.actions.length > 0) {
6103
+ if (Array.isArray(data.actions) &&
6104
+ data.actions.length > 0) {
6005
6105
  const skipJumpActions = Object.keys(ACTION).filter((item) => ACTION[item].skip_jump);
6006
6106
  const res = {
6007
- actions: [...nativeData.actions, ...skipJumpActions]
6107
+ actions: [...data.actions, ...skipJumpActions]
6008
6108
  };
6009
6109
  return Promise.resolve(res);
6010
6110
  }
@@ -6014,7 +6114,6 @@
6014
6114
  };
6015
6115
  return Promise.resolve(res);
6016
6116
  }
6017
- return Promise.reject(error);
6018
6117
  }
6019
6118
  });
6020
6119
  });
@@ -6038,7 +6137,7 @@
6038
6137
  enable: 1,
6039
6138
  aspect_ratio: '1:1'
6040
6139
  };
6041
- return yield this.callNative(ACTION.PICK_MEDIA, {
6140
+ return yield this.getJSBridge().callNative(ACTION.PICK_MEDIA, {
6042
6141
  media_type: MediaPickerType[type],
6043
6142
  edit_view: Object.assign(Object.assign({}, defaultEditView), editView),
6044
6143
  silent_request: silentRequest,
@@ -6046,15 +6145,11 @@
6046
6145
  max_select_items: maxSelectItem
6047
6146
  }, {
6048
6147
  isMultiCallback: true,
6049
- callback: (nativeData, error) => {
6050
- var _a;
6051
- if (nativeData.error_code === 0) {
6052
- const res = {
6053
- data: (_a = nativeData.data) === null || _a === void 0 ? void 0 : _a.result_content
6054
- };
6055
- return Promise.resolve(res);
6056
- }
6057
- 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);
6058
6153
  }
6059
6154
  });
6060
6155
  });
@@ -6069,7 +6164,7 @@
6069
6164
  */
6070
6165
  static openOutApp(url) {
6071
6166
  return __awaiter(this, void 0, void 0, function* () {
6072
- return yield this.callNative(ACTION.OPEN_OUTAPP, {
6167
+ return yield this.getJSBridge().callNative(ACTION.OPEN_OUTAPP, {
6073
6168
  url: url
6074
6169
  });
6075
6170
  });
@@ -6108,7 +6203,7 @@
6108
6203
  */
6109
6204
  static sendDataToPreviousMiniApp(object) {
6110
6205
  return __awaiter(this, void 0, void 0, function* () {
6111
- return yield this.callNative(ACTION.WEBVIEW_SET_RESULT, {
6206
+ return yield this.getJSBridge().callNative(ACTION.WEBVIEW_SET_RESULT, {
6112
6207
  result: stringifyData(object.data)
6113
6208
  });
6114
6209
  });
@@ -6133,11 +6228,10 @@
6133
6228
  }
6134
6229
  }
6135
6230
 
6136
- 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;
6137
- 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 {
6138
6233
  constructor() {
6139
6234
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
6140
- super();
6141
6235
  _ZaloMiniProgramSDKService_zAppId.set(this, ZAPP_ID);
6142
6236
  _ZaloMiniProgramSDKService_appId.set(this, APP_ID);
6143
6237
  _ZaloMiniProgramSDKService_appConfig.set(this, APP_CONFIG);
@@ -6150,9 +6244,10 @@
6150
6244
  getToken: 0
6151
6245
  }
6152
6246
  });
6247
+ _ZaloMiniProgramSDKService_bridge.set(this, void 0);
6153
6248
  _ZaloMiniProgramSDKService_prevGetTokenTimestamp.set(this, void 0);
6154
6249
  _ZaloMiniProgramSDKService_tokenExpiresIn.set(this, void 0);
6155
- _ZaloMiniProgramSDKService_cookies.set(this, null);
6250
+ _ZaloMiniProgramSDKService_deviceId.set(this, void 0);
6156
6251
  this.events = ZMPEEmitter.getInstance();
6157
6252
  this.isIOS = checkPlatform().isIOS;
6158
6253
  _ZaloMiniProgramSDKService_actionBarConfig.set(this, void 0);
@@ -6162,31 +6257,6 @@
6162
6257
  this.setActionBarConfig = (setState) => {
6163
6258
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_actionBarConfig, setState(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_actionBarConfig, "f")), "f");
6164
6259
  };
6165
- _ZaloMiniProgramSDKService_callJump.set(this, () => {
6166
- return new Promise((resolve, reject) => {
6167
- if (!_.isUndefined(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f")) && !_.isNull(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f"))) {
6168
- resolve(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f"));
6169
- }
6170
- else {
6171
- this.callNative(ACTION.JUMP_LOGIN, {})
6172
- .then((data) => {
6173
- const cookies = (data && data.cookiesOAuthLogins) || [];
6174
- const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
6175
- if (jsToken) {
6176
- this.setJSToken(jsToken.value);
6177
- window.ZJSBridge.setJSToken &&
6178
- window.ZJSBridge.setJSToken(jsToken.value);
6179
- }
6180
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_cookies, cookies, "f");
6181
- resolve(cookies);
6182
- })
6183
- .catch((error) => {
6184
- reject(error);
6185
- });
6186
- }
6187
- });
6188
- });
6189
- _ZaloMiniProgramSDKService_setNavigationBarRightButton.set(this, NavigationBar.setNavigationBarRightButton);
6190
6260
  this.getVersion = Basics.getVersion;
6191
6261
  this.getSystemInfo = Basics.getSystemInfo;
6192
6262
  this.setNavigationBarTitle = NavigationBar.setNavigationBarTitle;
@@ -6256,6 +6326,8 @@
6256
6326
  this.isShowNavBar = true;
6257
6327
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, 0, "f");
6258
6328
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, 0, "f");
6329
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_deviceId, '', "f");
6330
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_bridge, ZaloJSBridge.getInstance(), "f");
6259
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' ||
6260
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'
6261
6333
  ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
@@ -6299,9 +6371,19 @@
6299
6371
  getZAppId() {
6300
6372
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zAppId, "f");
6301
6373
  }
6374
+ getDeviceId() {
6375
+ return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_deviceId, "f");
6376
+ }
6377
+ getJSBridge() {
6378
+ return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f");
6379
+ }
6302
6380
  login(object) {
6303
6381
  return __awaiter(this, void 0, void 0, function* () {
6304
- 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
+ }
6305
6387
  const zOAuthCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH);
6306
6388
  const zOAuthVrfCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH_VRF);
6307
6389
  if (!_.isUndefined(zOAuthCookie) &&
@@ -6318,23 +6400,23 @@
6318
6400
  yield this.loginZaloV3();
6319
6401
  }
6320
6402
  if (!__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f")) {
6321
- throw apiResponse.error.loginFailed();
6403
+ throw apiResponse.error.loginFailed('Invalid authorization code');
6322
6404
  }
6323
6405
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
6324
6406
  }
6325
- throw apiResponse.error.loginFailed();
6407
+ throw apiResponse.error.loginFailed('Zalo app has not been activated');
6326
6408
  });
6327
6409
  }
6328
6410
  loginZaloV3() {
6329
6411
  return __awaiter(this, void 0, void 0, function* () {
6330
- 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* () {
6331
6413
  let resData = yield response.json();
6332
6414
  if (resData.access_token) {
6333
6415
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_accessToken, resData.access_token, "f");
6334
6416
  const expiresIn = parseInt(resData.expires_in) * 1000;
6335
6417
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, expiresIn, "f");
6336
6418
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, new Date().getTime(), "f");
6337
- this.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6419
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '';
6338
6420
  window.ZJSBridge.setZAccSession &&
6339
6421
  window.ZJSBridge.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6340
6422
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
@@ -6371,7 +6453,7 @@
6371
6453
  const expiresIn = parseInt(resData.expires_in) * 1000;
6372
6454
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, expiresIn, "f");
6373
6455
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, new Date().getTime(), "f");
6374
- this.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6456
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '';
6375
6457
  window.ZJSBridge.setZAccSession &&
6376
6458
  window.ZJSBridge.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6377
6459
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
@@ -6392,7 +6474,7 @@
6392
6474
  });
6393
6475
  }
6394
6476
  }
6395
- _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();
6396
6478
 
6397
6479
  var _MockSDKService_appId, _MockSDKService_appConfig, _MockSDKService_zOAuth, _MockSDKService_accessToken, _MockSDKService_cache, _MockSDKService_loggedId;
6398
6480
  class MockSDKService {
@@ -6413,6 +6495,9 @@
6413
6495
  this.getAppId = () => {
6414
6496
  return __classPrivateFieldGet(this, _MockSDKService_appId, "f");
6415
6497
  };
6498
+ this.getDeviceId = () => {
6499
+ return '';
6500
+ };
6416
6501
  this.login = () => {
6417
6502
  __classPrivateFieldSet(this, _MockSDKService_loggedId, true, "f");
6418
6503
  return Promise.resolve(__classPrivateFieldGet(this, _MockSDKService_zOAuth, "f"));
@@ -6765,90 +6850,175 @@
6765
6850
  .replace(/\s/gi, '')
6766
6851
  .split(',');
6767
6852
  }
6768
- const validate = (target, propertyName, descriptor) => {
6769
- const method = descriptor.value;
6770
- const argsName = getFnParamNames(method);
6771
- descriptor.value = function () {
6772
- const requiredParameters = Reflect.getOwnMetadata(requiredMetadataKey, target, propertyName);
6773
- const checkTypeParameters = Reflect.getOwnMetadata(checkTypeMetadataKey, target, propertyName);
6774
- if (checkTypeParameters) {
6775
- checkTypeParameters.forEach((parameter) => {
6776
- const { parameterIndex, type, properties, defaultValue } = parameter;
6777
- let argument = arguments[parameterIndex];
6778
- let argumentName = argsName[parameterIndex];
6779
- const parameterType = typeof argument;
6780
- if (!_.isUndefined(argument)) {
6781
- if (!isType(argument, type)) {
6782
- throw apiResponse.error.wrongTypeParam(argumentName, type, Array.isArray(argument)
6783
- ? 'array'
6784
- : argument === null
6785
- ? 'null'
6786
- : 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]);
6787
6961
  }
6788
- if (type === 'object') {
6789
- Object.entries(properties).forEach(([propKey, propType]) => {
6790
- const key = propKey.split('?')[0];
6791
- const propValue = _.get(argument, key);
6792
- if (!_.isUndefined(propValue) && !_.isNull(propValue)) {
6793
- if (_.isFunction(propType)) {
6794
- const res = propType(propValue);
6795
- if (res && res.error) {
6796
- 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));
6797
6969
  }
6970
+ isInValid = true;
6798
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 '));
6799
6978
  }
6800
- else if (!propKey.includes('?')) {
6801
- throw apiResponse.error.missingParam(propKey);
6802
- }
6803
- else if (_.isObject(_.get(argument, key.split('.')[0])) &&
6804
- defaultValue &&
6805
- !_.isUndefined(_.get(defaultValue, key))) {
6806
- _.set(arguments[parameterIndex], key, _.get(defaultValue, key));
6979
+ else if (_.isString(item) && isInValidField(item)) {
6980
+ throw apiResponse.error.missingParam(item);
6807
6981
  }
6808
6982
  });
6809
6983
  }
6810
- }
6811
- });
6812
- }
6813
- if (requiredParameters) {
6814
- requiredParameters.forEach((parameter) => {
6815
- const { parameterIndex, option, fields } = parameter;
6816
- const argument = arguments[parameterIndex];
6817
- const condition = option === null || option === void 0 ? void 0 : option.if;
6818
- const defaultValue = option === null || option === void 0 ? void 0 : option.defaultValue;
6819
- let isMeetCondition = true;
6820
- if (condition) {
6821
- isMeetCondition = Object.keys(condition).every((key) => _.get(argument, key) === condition[key]);
6822
- }
6823
- if (isMeetCondition) {
6824
- fields.forEach((item) => {
6825
- const isInValidField = (field) => {
6826
- let isInValid = false;
6827
- if (_.isEmpty(_.get(argument, field))) {
6828
- if (!_.isUndefined(_.get(defaultValue, field))) {
6829
- _.set(arguments[parameterIndex], field, _.get(defaultValue, field));
6830
- }
6831
- isInValid = true;
6832
- }
6833
- return isInValid;
6834
- };
6835
- if (Array.isArray(item) && item.length > 0 && item.every(isInValidField)) {
6836
- 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);
6837
7004
  }
6838
- else if (_.isString(item) && isInValidField(item)) {
6839
- throw apiResponse.error.missingParam(item);
7005
+ else {
7006
+ reject(errorParsed);
6840
7007
  }
6841
7008
  });
6842
- }
6843
- });
7009
+ });
7010
+ }
7011
+ return res;
7012
+ }
7013
+ catch (error) {
7014
+ throw errorHandler(error, propertyName);
6844
7015
  }
6845
- return method.apply(this, arguments);
6846
7016
  };
6847
7017
  return descriptor;
6848
7018
  };
6849
7019
 
6850
7020
  var _SDKCreator_sdkService;
6851
- class SDKCreator {
7021
+ let SDKCreator = class SDKCreator {
6852
7022
  constructor() {
6853
7023
  this.events = ZMPEEmitter.getInstance();
6854
7024
  _SDKCreator_sdkService.set(this, void 0);
@@ -6909,7 +7079,7 @@
6909
7079
  }
6910
7080
  setNavigationBarTitle(object) {
6911
7081
  return __awaiter(this, void 0, void 0, function* () {
6912
- return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarTitle(object);
7082
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarTitle(object);
6913
7083
  });
6914
7084
  }
6915
7085
  setNavigationBarColor(object) {
@@ -6924,7 +7094,7 @@
6924
7094
  }
6925
7095
  setNavigationBarLeftButton(object) {
6926
7096
  return __awaiter(this, void 0, void 0, function* () {
6927
- return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(object);
7097
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(object.type);
6928
7098
  });
6929
7099
  }
6930
7100
  setDeviceOrientation(object) {
@@ -7179,6 +7349,7 @@
7179
7349
  }
7180
7350
  vibrate(object) {
7181
7351
  return __awaiter(this, void 0, void 0, function* () {
7352
+ console.log(object);
7182
7353
  yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").vibrate(object);
7183
7354
  });
7184
7355
  }
@@ -7323,33 +7494,25 @@
7323
7494
  return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").openOutApp(appStoreURL);
7324
7495
  });
7325
7496
  }
7326
- }
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
+ };
7327
7509
  _SDKCreator_sdkService = new WeakMap();
7328
7510
  __decorate([
7329
- handleError
7330
- ], SDKCreator.prototype, "login", null);
7331
- __decorate([
7332
- handleErrorSync
7333
- ], SDKCreator.prototype, "getLoginStatus", null);
7334
- __decorate([
7335
- handleError
7336
- ], SDKCreator.prototype, "getAccessToken", null);
7337
- __decorate([
7338
- handleErrorSync
7339
- ], SDKCreator.prototype, "getVersion", null);
7340
- __decorate([
7341
- handleErrorSync
7342
- ], SDKCreator.prototype, "getSystemInfo", null);
7343
- __decorate([
7344
- handleError,
7345
- validate,
7346
7511
  __param(0, checkType('object', {
7347
7512
  title: checkData('string')
7348
7513
  }))
7349
7514
  ], SDKCreator.prototype, "setNavigationBarTitle", null);
7350
7515
  __decorate([
7351
- handleError,
7352
- validate,
7353
7516
  __param(0, checkType('object', {
7354
7517
  color: checkData('string'),
7355
7518
  'textColor?': checkData('string', { values: ['white', 'black'] }),
@@ -7357,57 +7520,37 @@
7357
7520
  }))
7358
7521
  ], SDKCreator.prototype, "setNavigationBarColor", null);
7359
7522
  __decorate([
7360
- handleError,
7361
- validate,
7362
7523
  __param(0, checkType('object', {
7363
7524
  backgroundColor: checkData('string'),
7364
7525
  'textColor?': checkData('string', { values: ['white', 'black'] })
7365
7526
  }))
7366
7527
  ], SDKCreator.prototype, "setBackgroundColor", null);
7367
7528
  __decorate([
7368
- handleError,
7369
- validate,
7370
7529
  __param(0, checkType('object', {
7371
7530
  type: checkData('string', { values: ['none', 'back', 'home', 'both'] })
7372
7531
  }))
7373
7532
  ], SDKCreator.prototype, "setNavigationBarLeftButton", null);
7374
7533
  __decorate([
7375
- handleError,
7376
- validate,
7377
7534
  __param(0, checkType('object', {
7378
7535
  rotate: checkData('string', { values: ['auto', 'portrait', 'landscape'] })
7379
7536
  }))
7380
7537
  ], SDKCreator.prototype, "setDeviceOrientation", null);
7381
7538
  __decorate([
7382
- handleError,
7383
- validate,
7384
7539
  __param(0, checkType('object', {
7385
7540
  data: checkData('object')
7386
7541
  }))
7387
7542
  ], SDKCreator.prototype, "setStorage", null);
7388
7543
  __decorate([
7389
- handleError,
7390
- validate,
7391
7544
  __param(0, checkType('object', {
7392
7545
  keys: checkData('array<string>')
7393
7546
  }))
7394
7547
  ], SDKCreator.prototype, "getStorage", null);
7395
7548
  __decorate([
7396
- handleError
7397
- ], SDKCreator.prototype, "getStorageInfo", null);
7398
- __decorate([
7399
- handleError,
7400
- validate,
7401
7549
  __param(0, checkType('object', {
7402
7550
  keys: checkData('array<string>')
7403
7551
  }))
7404
7552
  ], SDKCreator.prototype, "removeStorage", null);
7405
7553
  __decorate([
7406
- handleError
7407
- ], SDKCreator.prototype, "clearStorage", null);
7408
- __decorate([
7409
- handleError,
7410
- validate,
7411
7554
  __param(0, checkType('object', {
7412
7555
  'avatarType?': checkData('string', {
7413
7556
  values: ['small', 'normal', 'large']
@@ -7415,75 +7558,19 @@
7415
7558
  }))
7416
7559
  ], SDKCreator.prototype, "getUserInfo", null);
7417
7560
  __decorate([
7418
- handleError
7419
- ], SDKCreator.prototype, "getNetworkType", null);
7420
- __decorate([
7421
- handleError
7422
- ], SDKCreator.prototype, "onNetworkStatusChange", null);
7423
- __decorate([
7424
- handleError
7425
- ], SDKCreator.prototype, "startBeaconDiscovery", null);
7426
- __decorate([
7427
- handleError
7428
- ], SDKCreator.prototype, "stopBeaconDiscovery", null);
7429
- __decorate([
7430
- handleError
7431
- ], SDKCreator.prototype, "getBeacons", null);
7432
- __decorate([
7433
- handleError
7434
- ], SDKCreator.prototype, "closeApp", null);
7435
- __decorate([
7436
- handleError
7437
- ], SDKCreator.prototype, "getLocation", null);
7438
- __decorate([
7439
- handleError
7440
- ], SDKCreator.prototype, "stopBluetoothDevicesDiscovery", null);
7441
- __decorate([
7442
- handleError
7443
- ], SDKCreator.prototype, "startBluetoothDevicesDiscovery", null);
7444
- __decorate([
7445
- handleError
7446
- ], SDKCreator.prototype, "openBluetoothAdapter", null);
7447
- __decorate([
7448
- handleError
7449
- ], SDKCreator.prototype, "onBluetoothDeviceFound", null);
7450
- __decorate([
7451
- handleError
7452
- ], SDKCreator.prototype, "onBluetoothAdapterStateChange", null);
7453
- __decorate([
7454
- handleError
7455
- ], SDKCreator.prototype, "getConnectedBluetoothDevices", null);
7456
- __decorate([
7457
- handleError
7458
- ], SDKCreator.prototype, "getBluetoothDevices", null);
7459
- __decorate([
7460
- handleError
7461
- ], SDKCreator.prototype, "getBluetoothAdapterState", null);
7462
- __decorate([
7463
- handleError
7464
- ], SDKCreator.prototype, "closeBluetoothAdapter", null);
7465
- __decorate([
7466
- handleError
7467
- ], SDKCreator.prototype, "scanQRCode", null);
7468
- __decorate([
7469
- handleError,
7470
- validate,
7471
7561
  __param(0, checkType('object', {
7472
7562
  type: checkData('string', { values: ['user', 'oa', 'aliasOA'] }),
7473
7563
  id: checkData('string')
7474
7564
  }))
7475
7565
  ], SDKCreator.prototype, "openProfile", null);
7476
7566
  __decorate([
7477
- handleError,
7478
- validate,
7479
7567
  __param(0, checkType('object', {
7480
7568
  type: checkData('string', { values: ['user', 'oa'] }),
7481
- id: checkData('string')
7569
+ id: checkData('string'),
7570
+ 'message?': checkData('string')
7482
7571
  }))
7483
7572
  ], SDKCreator.prototype, "openChat", null);
7484
7573
  __decorate([
7485
- handleError,
7486
- validate,
7487
7574
  __param(0, required(['data.imageUrl'], { if: { type: 'image' } })),
7488
7575
  __param(0, required(['data.link'], { if: { type: 'link' } })),
7489
7576
  __param(0, required(['data.id'], { if: { type: 'profile' } })),
@@ -7501,23 +7588,17 @@
7501
7588
  }))
7502
7589
  ], SDKCreator.prototype, "openPostFeed", null);
7503
7590
  __decorate([
7504
- handleError,
7505
- validate,
7506
7591
  __param(0, checkType('object', {
7507
7592
  id: checkData('string'),
7508
7593
  'showDialogConfirm?': checkData('boolean')
7509
7594
  }))
7510
7595
  ], SDKCreator.prototype, "followOA", null);
7511
7596
  __decorate([
7512
- handleError,
7513
- validate,
7514
7597
  __param(0, checkType('object', {
7515
7598
  id: checkData('string')
7516
7599
  }))
7517
7600
  ], SDKCreator.prototype, "unfollowOA", null);
7518
7601
  __decorate([
7519
- handleError,
7520
- validate,
7521
7602
  __param(0, required([['data.imageUrl', 'data.imageUrls']], { if: { type: 'image' } })),
7522
7603
  __param(0, required(['data.link'], { if: { type: 'link' } })),
7523
7604
  __param(0, required(['data.id'], { if: { type: 'oa' } })),
@@ -7556,14 +7637,6 @@
7556
7637
  }))
7557
7638
  ], SDKCreator.prototype, "openShareSheet", null);
7558
7639
  __decorate([
7559
- handleError
7560
- ], SDKCreator.prototype, "requestCameraPermission", null);
7561
- __decorate([
7562
- handleError
7563
- ], SDKCreator.prototype, "createShortcut", null);
7564
- __decorate([
7565
- handleError,
7566
- validate,
7567
7640
  __param(0, checkType('object', {
7568
7641
  secretData: checkData('string'),
7569
7642
  'ui?': checkData('object'),
@@ -7581,44 +7654,28 @@
7581
7654
  }))
7582
7655
  ], SDKCreator.prototype, "openBioAuthentication", null);
7583
7656
  __decorate([
7584
- handleError
7585
- ], SDKCreator.prototype, "checkStateBioAuthentication", null);
7586
- __decorate([
7587
- handleError,
7588
- validate,
7589
7657
  __param(0, checkType('object', {
7590
7658
  toUserId: checkData('string'),
7591
7659
  'title?': checkData('string')
7592
7660
  }))
7593
7661
  ], SDKCreator.prototype, "sendLocation", null);
7594
7662
  __decorate([
7595
- handleError,
7596
- validate,
7597
7663
  __param(0, checkType('object', {
7598
7664
  message: checkData('string')
7599
7665
  }))
7600
7666
  ], SDKCreator.prototype, "showToast", null);
7601
7667
  __decorate([
7602
- handleError
7603
- ], SDKCreator.prototype, "hideKeyboard", null);
7604
- __decorate([
7605
- handleError,
7606
- validate,
7607
7668
  __param(0, checkType('object', {
7608
7669
  phoneNumber: checkData('string')
7609
7670
  }))
7610
7671
  ], SDKCreator.prototype, "openPhone", null);
7611
7672
  __decorate([
7612
- handleError,
7613
- validate,
7614
7673
  __param(0, checkType('object', {
7615
7674
  content: checkData('string'),
7616
7675
  phoneNumber: checkData('string', { regex: /^\+?\d+$/ })
7617
7676
  }))
7618
7677
  ], SDKCreator.prototype, "openSMS", null);
7619
7678
  __decorate([
7620
- handleError,
7621
- validate,
7622
7679
  __param(0, checkType('object', {
7623
7680
  id: checkData('string'),
7624
7681
  'displayName?': checkData('string')
@@ -7627,35 +7684,24 @@
7627
7684
  }))
7628
7685
  ], SDKCreator.prototype, "viewOAQr", null);
7629
7686
  __decorate([
7630
- handleError
7631
- ], SDKCreator.prototype, "keepScreen", null);
7632
- __decorate([
7633
- handleError,
7634
- validate,
7635
7687
  __param(0, checkType('object', {
7636
7688
  'imageBase64Data?': checkData('string'),
7637
7689
  'imageUrl?': checkData('url')
7638
7690
  }))
7639
7691
  ], SDKCreator.prototype, "saveImageToGallery", null);
7640
7692
  __decorate([
7641
- handleError,
7642
- validate,
7643
7693
  __param(0, checkType('object', {
7644
7694
  'imageBase64Data?': checkData('string'),
7645
7695
  'imageUrl?': checkData('url')
7646
7696
  }))
7647
7697
  ], SDKCreator.prototype, "saveImageToPhotosAlbum", null);
7648
7698
  __decorate([
7649
- handleError,
7650
- validate,
7651
7699
  __param(0, checkType('object', {
7652
7700
  appId: checkData('string'),
7653
7701
  'params?': checkData('object')
7654
7702
  }))
7655
7703
  ], SDKCreator.prototype, "openMiniApp", null);
7656
7704
  __decorate([
7657
- handleError,
7658
- validate,
7659
7705
  __param(0, checkType('object', {
7660
7706
  'type?': checkData('string', { values: ['oneShot'] }),
7661
7707
  'milliseconds?': checkData('number')
@@ -7665,30 +7711,11 @@
7665
7711
  }))
7666
7712
  ], SDKCreator.prototype, "vibrate", null);
7667
7713
  __decorate([
7668
- handleError,
7669
- validate,
7670
7714
  __param(0, checkType('object', {
7671
7715
  url: checkData('url')
7672
7716
  }))
7673
7717
  ], SDKCreator.prototype, "openWebview", null);
7674
7718
  __decorate([
7675
- handleErrorSync
7676
- ], SDKCreator.prototype, "getRouteParams", null);
7677
- __decorate([
7678
- handleError
7679
- ], SDKCreator.prototype, "getAppInfo", null);
7680
- __decorate([
7681
- handleError
7682
- ], SDKCreator.prototype, "sendDataToPreviousMiniApp", null);
7683
- __decorate([
7684
- handleError
7685
- ], SDKCreator.prototype, "onCallbackData", null);
7686
- __decorate([
7687
- handleError
7688
- ], SDKCreator.prototype, "getPhoneNumber", null);
7689
- __decorate([
7690
- handleError,
7691
- validate,
7692
7719
  __param(0, checkType('object', {
7693
7720
  'maxProfile?': checkData('number', { min: 1, max: 10 })
7694
7721
  }, {
@@ -7696,8 +7723,6 @@
7696
7723
  }))
7697
7724
  ], SDKCreator.prototype, "openProfilePicker", null);
7698
7725
  __decorate([
7699
- handleError,
7700
- validate,
7701
7726
  __param(0, required(['SSID'])),
7702
7727
  __param(0, checkType('object', {
7703
7728
  SSID: checkData('string'),
@@ -7706,8 +7731,6 @@
7706
7731
  }))
7707
7732
  ], SDKCreator.prototype, "connectWifi", null);
7708
7733
  __decorate([
7709
- handleError,
7710
- validate,
7711
7734
  __param(0, checkType('object', {
7712
7735
  type: checkData('string', {
7713
7736
  values: ['photo', 'video', 'file']
@@ -7722,8 +7745,6 @@
7722
7745
  }))
7723
7746
  ], SDKCreator.prototype, "openMediaPicker", null);
7724
7747
  __decorate([
7725
- handleError,
7726
- validate,
7727
7748
  __param(0, checkType('object', {
7728
7749
  title: checkData('string', { maxLength: 100 }),
7729
7750
  'thumbnail?': checkData('url'),
@@ -7733,14 +7754,9 @@
7733
7754
  description: ''
7734
7755
  }))
7735
7756
  ], SDKCreator.prototype, "getShareableLink", null);
7736
- __decorate([
7737
- handleError,
7738
- validate
7739
- ], SDKCreator.prototype, "closeLoading", null);
7740
- __decorate([
7741
- handleError,
7742
- validate
7743
- ], SDKCreator.prototype, "requestUpdateZalo", null);
7757
+ SDKCreator = __decorate([
7758
+ DecorateAll(centralizedFunctionHandler)
7759
+ ], SDKCreator);
7744
7760
  class ZaloMiniAppSDKCreator extends SDKCreator {
7745
7761
  getServiceInstance() {
7746
7762
  return ZaloMiniProgramSDKService.getInstance();
@@ -7936,7 +7952,7 @@
7936
7952
  _MockPaymentService_appId = new WeakMap();
7937
7953
 
7938
7954
  var _PaymentCreator_instance, _PaymentCreator_sdk;
7939
- class PaymentCreator {
7955
+ let PaymentCreator = class PaymentCreator {
7940
7956
  constructor(sdk) {
7941
7957
  _PaymentCreator_instance.set(this, void 0);
7942
7958
  _PaymentCreator_sdk.set(this, void 0);
@@ -7944,42 +7960,50 @@
7944
7960
  __classPrivateFieldSet(this, _PaymentCreator_sdk, sdk, "f");
7945
7961
  }
7946
7962
  /**
7947
- * Tạo đơn hàng
7948
- *
7949
- * @async
7950
- * @function createOrder
7951
- * @category Payment
7952
- * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
7953
- */
7963
+ * Tạo đơn hàng
7964
+ *
7965
+ * @async
7966
+ * @function createOrder
7967
+ * @category Payment
7968
+ * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
7969
+ */
7954
7970
  createOrder(object) {
7955
7971
  return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").createOrder(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
7956
7972
  }
7957
7973
  /**
7958
- * Lấy thông tin transaction
7959
- *
7960
- * @async
7961
- * @function checkTransaction
7962
- * @category Payment
7963
- * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
7964
- */
7974
+ * Lấy thông tin transaction
7975
+ *
7976
+ * @async
7977
+ * @function checkTransaction
7978
+ * @category Payment
7979
+ * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
7980
+ */
7965
7981
  checkTransaction(object) {
7966
7982
  return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").checkTransaction(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
7967
7983
  }
7968
- }
7984
+ };
7969
7985
  _PaymentCreator_instance = new WeakMap(), _PaymentCreator_sdk = new WeakMap();
7970
7986
  __decorate([
7971
- handleError,
7972
- validate,
7973
7987
  __param(0, checkType('object', {
7974
- 'amount': checkData(['string', 'number']),
7975
- 'desc': checkData('string'),
7976
- '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
+ })
7977
8002
  }))
7978
8003
  ], PaymentCreator.prototype, "createOrder", null);
7979
- __decorate([
7980
- handleError,
7981
- validate
7982
- ], PaymentCreator.prototype, "checkTransaction", null);
8004
+ PaymentCreator = __decorate([
8005
+ DecorateAll(centralizedFunctionHandler)
8006
+ ], PaymentCreator);
7983
8007
  class ZaloMiniAppPaymentCreator extends PaymentCreator {
7984
8008
  getInstance() {
7985
8009
  return PaymentService.getInstance();