zmp-sdk 2.19.1 → 2.21.0-rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -2064,6 +2064,9 @@ function set(object, path, value) {
2064
2064
 
2065
2065
  var set_1 = set;
2066
2066
 
2067
+ const isPromise = (obj) => !!obj &&
2068
+ (typeof obj === 'object' || typeof obj === 'function') &&
2069
+ typeof obj.then === 'function';
2067
2070
  var _ = {
2068
2071
  isEmpty: isEmpty_1,
2069
2072
  isNull: isNull_1,
@@ -2075,7 +2078,8 @@ var _ = {
2075
2078
  isArray: isArray_1,
2076
2079
  isRegExp: isRegExp_1,
2077
2080
  get: get_1,
2078
- set: set_1
2081
+ set: set_1,
2082
+ isPromise,
2079
2083
  };
2080
2084
 
2081
2085
  function Debug(name) {
@@ -2147,13 +2151,6 @@ var VibrateType;
2147
2151
  (function (VibrateType) {
2148
2152
  VibrateType[VibrateType["oneShot"] = 0] = "oneShot";
2149
2153
  })(VibrateType || (VibrateType = {}));
2150
- var NativeCode;
2151
- (function (NativeCode) {
2152
- NativeCode[NativeCode["token_invalid"] = -2] = "token_invalid";
2153
- NativeCode[NativeCode["not_permission"] = -1] = "not_permission";
2154
- NativeCode[NativeCode["client_not_support"] = -5] = "client_not_support";
2155
- NativeCode[NativeCode["decode_failed"] = -4] = "decode_failed";
2156
- })(NativeCode || (NativeCode = {}));
2157
2154
  var Events;
2158
2155
  (function (Events) {
2159
2156
  Events["AppPaused"] = "h5.event.paused";
@@ -2161,6 +2158,7 @@ var Events;
2161
2158
  Events["NetworkChanged"] = "h5.event.connection.changed";
2162
2159
  Events["OnDataCallback"] = "h5.event.webview.result";
2163
2160
  Events["OpenApp"] = "h5.event.open.mp";
2161
+ Events["AppClose"] = "h5.event.action.close";
2164
2162
  })(Events || (Events = {}));
2165
2163
  var MediaPickerType;
2166
2164
  (function (MediaPickerType) {
@@ -2240,7 +2238,8 @@ const COOKIE_NAME = {
2240
2238
  ZOAUTH: `h5.zdn.vn_zoauth`,
2241
2239
  ZACC_SESSiON: `h5.zdn.vn_zacc_session`,
2242
2240
  JS_TOKEN: `h5.zdn.vn_zlink3rd`,
2243
- ZOAUTH_VRF: `h5.zdn.vn_zoauth_vrf`
2241
+ ZOAUTH_VRF: `h5.zdn.vn_zoauth_vrf`,
2242
+ DEVICE_ID: `h5.zdn.vn_deviceID`
2244
2243
  };
2245
2244
  const APIS = {
2246
2245
  GET_USER_INFO: 'https://graph.zalo.me/v2.0/me',
@@ -2248,6 +2247,8 @@ const APIS = {
2248
2247
  GET_ACCESS_TOKEN_V3: 'https://oauth.zaloapp.com/v3/access_token',
2249
2248
  GET_LIST_USER_INFO: 'https://graph.zalo.me/v2.0/me/friends/list',
2250
2249
  CREATE_ORDER: 'https://payment-mini.zalo.me/api/order/create',
2250
+ GET_APP_INFO: 'https://h5.zalo.me/apps/get-info',
2251
+ SEND_ACTION_LOG: 'https://h5.zalo.me/log/async'
2251
2252
  };
2252
2253
  const STORAGE_LIMIT = 5 * MB;
2253
2254
  const NETWORK_TYPE = (isAndroid) => ({
@@ -2258,6 +2259,78 @@ const NETWORK_TYPE = (isAndroid) => ({
2258
2259
  '4G': isAndroid ? 13 : 2
2259
2260
  });
2260
2261
  const MEDIA_PICKER_LIMIT = 1 * MB;
2262
+ const RESPONSE_CODE = {
2263
+ SUCCESS: 0,
2264
+ UNKNOWN_ERROR: -2000,
2265
+ BAD_REQUEST: -1400,
2266
+ INTERNAL_SERVER_ERROR: -1500,
2267
+ UNAUTHORIZED: -1401,
2268
+ FORBIDDEN: -1403,
2269
+ CLIENT_NOT_SUPPORT: -1404,
2270
+ TIME_OUT: -1408,
2271
+ DECODE_FAILED: -2001,
2272
+ USER_DENIED: -2002,
2273
+ USER_CANCEL: -2003,
2274
+ // Media picker
2275
+ MEDIA_PICKER_FAIL: -2004,
2276
+ // Save image to gallery
2277
+ SAVE_IMAGE_FAIL: -2005
2278
+ };
2279
+ const MESSAGES = {
2280
+ SUCCESS: 'Success',
2281
+ UNKNOWN_ERROR: 'Unknown error. Please try again later.',
2282
+ TIME_OUT: 'Request timeout. Please try again later.',
2283
+ LOGIN_REQUIRED: 'Please login (https://miniapp.zalo.me/docs/api/login) before to call this api',
2284
+ LOGIN_FAILED: 'Login failed',
2285
+ NOT_PERMISSION: `You don't have permission to call this api`,
2286
+ CLIENT_NOT_SUPPORT: `This API is not supported in this Zalo version`,
2287
+ DECODE_FAILED: 'Can not decode id. Please check your params again.',
2288
+ INVALID_PARAM: 'Invalid parameter',
2289
+ USER_DENIED: 'User denied',
2290
+ USER_CANCEL: 'User cancel',
2291
+ // Media picker
2292
+ MEDIA_PICKER_FAIL: 'Unable to pick media',
2293
+ // Save image to gallery
2294
+ SAVE_IMAGE_FAIL: 'Unable to save image'
2295
+ };
2296
+ const RESPONSE = {
2297
+ SUCCESS: {
2298
+ code: RESPONSE_CODE.SUCCESS,
2299
+ message: MESSAGES.SUCCESS
2300
+ },
2301
+ UNKNOWN_ERROR: {
2302
+ code: RESPONSE_CODE.UNKNOWN_ERROR,
2303
+ message: MESSAGES.UNKNOWN_ERROR
2304
+ },
2305
+ UNAUTHORIZED: {
2306
+ code: RESPONSE_CODE.UNAUTHORIZED,
2307
+ message: MESSAGES.LOGIN_REQUIRED
2308
+ },
2309
+ FORBIDDEN: {
2310
+ code: RESPONSE_CODE.FORBIDDEN,
2311
+ message: MESSAGES.NOT_PERMISSION
2312
+ },
2313
+ CLIENT_NOT_SUPPORT: {
2314
+ code: RESPONSE_CODE.CLIENT_NOT_SUPPORT,
2315
+ message: MESSAGES.CLIENT_NOT_SUPPORT
2316
+ },
2317
+ DECODE_FAILED: {
2318
+ code: RESPONSE_CODE.DECODE_FAILED,
2319
+ message: MESSAGES.DECODE_FAILED
2320
+ },
2321
+ TIME_OUT: {
2322
+ code: RESPONSE_CODE.TIME_OUT,
2323
+ message: MESSAGES.TIME_OUT
2324
+ },
2325
+ USER_DENIED: {
2326
+ code: RESPONSE_CODE.USER_DENIED,
2327
+ message: MESSAGES.USER_DENIED
2328
+ },
2329
+ USER_CANCEL: {
2330
+ code: RESPONSE_CODE.USER_CANCEL,
2331
+ message: MESSAGES.USER_CANCEL
2332
+ }
2333
+ };
2261
2334
  const ACTION = {
2262
2335
  GET_DOWNLOADED_STICKER: {
2263
2336
  name: 'action.get.downloaded.sticker',
@@ -2370,7 +2443,19 @@ const ACTION = {
2370
2443
  have_callback: true
2371
2444
  },
2372
2445
  REQUEST_PERMISSION_CAMERA: {
2373
- name: 'action.request.permission.camera'
2446
+ name: 'action.request.permission.camera',
2447
+ error_list: {
2448
+ android: {
2449
+ '-2': {
2450
+ map_to: RESPONSE.USER_DENIED
2451
+ }
2452
+ },
2453
+ iOS: {
2454
+ '-2': {
2455
+ map_to: RESPONSE.USER_DENIED
2456
+ }
2457
+ }
2458
+ }
2374
2459
  },
2375
2460
  CHANGE_TITLE_HEADER: {
2376
2461
  name: 'action.change.title.header',
@@ -2439,7 +2524,19 @@ const ACTION = {
2439
2524
  },
2440
2525
  GET_LOCATION: {
2441
2526
  name: 'action.get.location',
2442
- have_callback: true
2527
+ have_callback: true,
2528
+ error_list: {
2529
+ android: {
2530
+ '-1': {
2531
+ map_to: RESPONSE.USER_DENIED
2532
+ }
2533
+ },
2534
+ iOS: {
2535
+ '-1': {
2536
+ map_to: RESPONSE.USER_DENIED
2537
+ }
2538
+ }
2539
+ }
2443
2540
  },
2444
2541
  QUERY_LOCATION_HIDE: {
2445
2542
  name: 'action.query.location.hide',
@@ -2537,7 +2634,34 @@ const ACTION = {
2537
2634
  },
2538
2635
  SAVE_IMAGE_GALLERY: {
2539
2636
  name: 'action.save.image.gallery',
2540
- version_live: { iOS: 408 }
2637
+ version_live: { iOS: 408 },
2638
+ error_list: {
2639
+ android: {
2640
+ '-101': {
2641
+ map_to: {
2642
+ code: RESPONSE_CODE.SAVE_IMAGE_FAIL,
2643
+ message: MESSAGES.SAVE_IMAGE_FAIL
2644
+ },
2645
+ need_more_detail: true
2646
+ },
2647
+ '-102': {
2648
+ map_to: {
2649
+ code: RESPONSE_CODE.SAVE_IMAGE_FAIL,
2650
+ message: MESSAGES.SAVE_IMAGE_FAIL
2651
+ },
2652
+ need_more_detail: true
2653
+ }
2654
+ },
2655
+ iOS: {
2656
+ '-10': {
2657
+ map_to: {
2658
+ code: RESPONSE_CODE.SAVE_IMAGE_FAIL,
2659
+ message: MESSAGES.SAVE_IMAGE_FAIL
2660
+ },
2661
+ need_more_detail: true
2662
+ }
2663
+ }
2664
+ }
2541
2665
  },
2542
2666
  OPEN_MP: {
2543
2667
  name: 'action.open.mp',
@@ -2558,11 +2682,41 @@ const ACTION = {
2558
2682
  },
2559
2683
  MP_GET_NUMBER: {
2560
2684
  name: 'action.mp.get.number',
2561
- version_live: { iOS: 416 }
2685
+ version_live: { iOS: 416 },
2686
+ error_list: {
2687
+ android: {
2688
+ '-1': {
2689
+ map_to: RESPONSE.USER_DENIED
2690
+ },
2691
+ '-101': {
2692
+ map_to: RESPONSE.USER_DENIED
2693
+ }
2694
+ },
2695
+ iOS: {
2696
+ '-1': {
2697
+ map_to: RESPONSE.USER_DENIED
2698
+ },
2699
+ '-10': {
2700
+ map_to: RESPONSE.USER_DENIED
2701
+ }
2702
+ }
2703
+ }
2562
2704
  },
2563
2705
  MP_OPEN_PROFILE_PICKER: {
2564
2706
  name: 'action.mp.open.profile.picker',
2565
- version_live: { iOS: 432 }
2707
+ version_live: { iOS: 432 },
2708
+ error_list: {
2709
+ android: {
2710
+ '-101': {
2711
+ map_to: RESPONSE.USER_CANCEL
2712
+ }
2713
+ },
2714
+ iOS: {
2715
+ '-101': {
2716
+ map_to: RESPONSE.USER_CANCEL
2717
+ }
2718
+ }
2719
+ }
2566
2720
  },
2567
2721
  GET_SUPPORTED_ACTIONS: {
2568
2722
  name: 'action.get.supported.actions',
@@ -2576,32 +2730,45 @@ const ACTION = {
2576
2730
  },
2577
2731
  PICK_MEDIA: {
2578
2732
  name: 'action.pick.media',
2579
- version_live: { iOS: 440 }
2733
+ version_live: { iOS: 440 },
2734
+ error_list: {
2735
+ android: {
2736
+ '-101': {
2737
+ map_to: RESPONSE.USER_CANCEL
2738
+ },
2739
+ '999': {
2740
+ map_to: {
2741
+ code: RESPONSE_CODE.MEDIA_PICKER_FAIL,
2742
+ message: MESSAGES.MEDIA_PICKER_FAIL
2743
+ },
2744
+ need_more_detail: true
2745
+ }
2746
+ },
2747
+ iOS: {
2748
+ '-10': {
2749
+ map_to: {
2750
+ code: RESPONSE_CODE.MEDIA_PICKER_FAIL,
2751
+ message: MESSAGES.MEDIA_PICKER_FAIL
2752
+ }
2753
+ }
2754
+ }
2755
+ }
2580
2756
  },
2581
2757
  MP_CLOSE_LOADINGVIEW: {
2582
2758
  name: 'action.mp.close.loadingview'
2583
2759
  }
2584
2760
  };
2585
- const RESPONSE_CODE = {
2586
- SUCCESS: 0,
2587
- BAD_REQUEST: -1400,
2588
- INTERNAL_SERVER_ERROR: -1500,
2589
- UNAUTHORIZED: -1401,
2590
- FORBIDDEN: -1403,
2591
- CLIENT_NOT_SUPPORT: -1404
2592
- };
2593
- const MESSAGES = {
2594
- SUCCESS: 'Success',
2595
- READ_MORE: 'Read more at: https://miniapp.zalo.me/docs/api',
2596
- LOGIN_REQUIRED: 'Please login before to call this api. Read more at: https://miniapp.zalo.me/docs/api/login',
2597
- LOGIN_FAILED: 'Login failed.',
2598
- NOT_PERMISSION: `You don't have permission to call this api`,
2599
- CLIENT_NOT_SUPPORT: `This API is not supported in this Zalo version`,
2600
- DECODE_FAILED: 'Can not decode your data. Read more at: https://miniapp.zalo.me/docs/api/error'
2601
- };
2602
- const API_DOMAIN = 'https://h5.zalo.me/';
2603
- const H5_API = {
2604
- GET_APP_INFO: 'apps/get-info'
2761
+ const COMMON_NATIVE_ERROR_CODE = {
2762
+ android: {
2763
+ '-4': RESPONSE.DECODE_FAILED,
2764
+ '-5': RESPONSE.CLIENT_NOT_SUPPORT,
2765
+ '-14': RESPONSE.TIME_OUT
2766
+ },
2767
+ iOS: {
2768
+ '-9': RESPONSE.DECODE_FAILED,
2769
+ '-5': RESPONSE.CLIENT_NOT_SUPPORT,
2770
+ '-14': RESPONSE.TIME_OUT
2771
+ }
2605
2772
  };
2606
2773
  const ZALO_SUPPORT_STORAGE_VERSION = {
2607
2774
  android: 12100571,
@@ -2713,124 +2880,36 @@ const PAYMENT_APIS = {
2713
2880
  };
2714
2881
  const PAYMENT_H5_URL = 'https://payment-mini.zalo.me';
2715
2882
 
2716
- class CommonError {
2883
+ class AppError {
2717
2884
  constructor(code, msg, api) {
2718
2885
  this.code = code;
2719
2886
  this.message = msg;
2720
2887
  this.api = api;
2721
2888
  }
2722
2889
  toString() {
2723
- return `api: ${this.api}; code: ${this.code}; message: ${this.message}`;
2890
+ return `api: ${String(this.api)}; code: ${this.code}; message: ${this.message}`;
2724
2891
  }
2725
- }
2726
- class NativeError extends CommonError {
2727
- constructor(code, msg) {
2728
- super(code, msg);
2729
- this.message = `${msg}. ${MESSAGES.READ_MORE}`;
2730
- this.handler();
2731
- }
2732
- handler() {
2733
- switch (this.code) {
2734
- case NativeCode.token_invalid:
2735
- this.code = RESPONSE_CODE.UNAUTHORIZED;
2736
- this.message = MESSAGES.LOGIN_REQUIRED;
2737
- break;
2738
- case NativeCode.not_permission:
2739
- this.code = RESPONSE_CODE.FORBIDDEN;
2740
- this.message = MESSAGES.NOT_PERMISSION;
2741
- break;
2742
- case NativeCode.client_not_support:
2743
- this.code = RESPONSE_CODE.CLIENT_NOT_SUPPORT;
2744
- this.message = MESSAGES.CLIENT_NOT_SUPPORT;
2745
- break;
2746
- case NativeCode.decode_failed:
2747
- this.message = MESSAGES.DECODE_FAILED;
2748
- break;
2749
- }
2892
+ toJSON() {
2893
+ return {
2894
+ code: this.code,
2895
+ message: this.message,
2896
+ api: this.api
2897
+ };
2750
2898
  }
2751
2899
  }
2752
- const catchDecoratorStore = {
2753
- handler: null,
2754
- setHandler(handler) {
2755
- this.handler = handler;
2756
- }
2900
+ const handleKnownExceptions = (error, api) => {
2901
+ error.api = api;
2902
+ return error.toJSON();
2757
2903
  };
2758
- const errorHandler = (api, error) => {
2759
- if (error instanceof CommonError) {
2760
- error.api = api;
2761
- return error;
2904
+ const handleUnknownExceptions = (error, api) => {
2905
+ if (error instanceof Error) {
2906
+ return new AppError(RESPONSE_CODE.UNKNOWN_ERROR, error.message, api).toJSON();
2762
2907
  }
2763
- return new CommonError(-2001, _.isNull(error.message) ? 'Unknown Error' : error.message, api);
2764
- };
2765
- catchDecoratorStore.setHandler(errorHandler);
2766
- const handleError = (target, propertyName, descriptor) => {
2767
- const fn = descriptor.value;
2768
- descriptor.value = function (...args) {
2769
- return __awaiter(this, void 0, void 0, function* () {
2770
- const { success, fail } = Array.isArray(args) && args.length > 0 && args[0];
2771
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
2772
- try {
2773
- const res = yield fn.apply(this, args);
2774
- if (!_.isNull(success) && _.isFunction(success)) {
2775
- success.call(null, res, this);
2776
- }
2777
- else {
2778
- resolve(res);
2779
- }
2780
- }
2781
- catch (error) {
2782
- if ((error === null || error === void 0 ? void 0 : error.api) !== 'login' && // login is not error
2783
- ((error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.UNAUTHORIZED ||
2784
- (error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.FORBIDDEN)) {
2785
- let loggedIn = false;
2786
- if (this instanceof SDKCreator) {
2787
- loggedIn = this.getLoginStatus();
2788
- }
2789
- if (!loggedIn) {
2790
- error = new CommonError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED);
2791
- }
2792
- }
2793
- const { handler } = catchDecoratorStore;
2794
- const errorParsed = handler.call(null, propertyName, error, this);
2795
- window.zmpSentry && window.zmpSentry.throwError(errorParsed.toString());
2796
- if (!_.isNull(fail) && _.isFunction(fail)) {
2797
- fail.call(null, errorParsed, this);
2798
- }
2799
- else {
2800
- reject(errorParsed);
2801
- }
2802
- }
2803
- }));
2804
- });
2805
- };
2806
- return descriptor;
2908
+ return new AppError(RESPONSE_CODE.UNKNOWN_ERROR, MESSAGES.UNKNOWN_ERROR, api).toJSON();
2807
2909
  };
2808
- const handleErrorSync = (target, key, descriptor) => {
2809
- const fn = descriptor.value;
2810
- descriptor.value = function (...args) {
2811
- try {
2812
- return fn.apply(this, args);
2813
- }
2814
- catch (error) {
2815
- if ((error === null || error === void 0 ? void 0 : error.api) !== 'login' && // login is not error
2816
- ((error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.UNAUTHORIZED ||
2817
- (error === null || error === void 0 ? void 0 : error.code) === RESPONSE_CODE.FORBIDDEN)) {
2818
- let loggedIn = false;
2819
- if (this instanceof SDKCreator) {
2820
- loggedIn = this.getLoginStatus();
2821
- }
2822
- if (!loggedIn) {
2823
- error = new CommonError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED);
2824
- }
2825
- }
2826
- const { handler } = catchDecoratorStore;
2827
- const errorParsed = handler.call(null, key, error, this);
2828
- window.zmpSentry && window.zmpSentry.throwError(errorParsed.toString());
2829
- throw errorParsed;
2830
- }
2831
- };
2832
- return descriptor;
2833
- };
2910
+ const errorHandler = (error, api) => error instanceof AppError
2911
+ ? handleKnownExceptions(error, api)
2912
+ : handleUnknownExceptions(error, api);
2834
2913
 
2835
2914
  const apiResponse = {
2836
2915
  success: (data, message) => ({
@@ -2839,13 +2918,13 @@ const apiResponse = {
2839
2918
  data: data || {}
2840
2919
  }),
2841
2920
  error: {
2842
- badRequest: (message) => new CommonError(RESPONSE_CODE.BAD_REQUEST, message),
2843
- loginFailed: () => new CommonError(RESPONSE_CODE.BAD_REQUEST, MESSAGES.LOGIN_FAILED),
2844
- loginRequired: () => new CommonError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED),
2845
- missingParam: (params) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Missing required argument: ${params}`),
2846
- wrongTypeParam: (arg, expected, got) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `Wrong type of parameter '${arg}'. Expected ${expected}, but got ${got}`),
2847
- cannotGetShareInfo: () => new CommonError(RESPONSE_CODE.INTERNAL_SERVER_ERROR, `Can not get app info to share`),
2848
- lengthInvalid: (arg) => new CommonError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`),
2921
+ badRequest: (message) => new AppError(RESPONSE_CODE.BAD_REQUEST, message),
2922
+ loginFailed: (message) => new AppError(RESPONSE_CODE.UNAUTHORIZED, `${MESSAGES.LOGIN_FAILED}: ${message}`),
2923
+ loginRequired: () => new AppError(RESPONSE_CODE.UNAUTHORIZED, MESSAGES.LOGIN_REQUIRED),
2924
+ missingParam: (params) => new AppError(RESPONSE_CODE.BAD_REQUEST, `Missing required argument: ${params}`),
2925
+ wrongTypeParam: (arg, expected, got) => new AppError(RESPONSE_CODE.BAD_REQUEST, `Wrong type of parameter '${arg}'. Expected ${expected}, but got ${got}`),
2926
+ cannotGetShareInfo: () => new AppError(RESPONSE_CODE.INTERNAL_SERVER_ERROR, `Can not get app info to share`),
2927
+ lengthInvalid: (arg) => new AppError(RESPONSE_CODE.BAD_REQUEST, `${arg} length is invalid.`)
2849
2928
  }
2850
2929
  };
2851
2930
 
@@ -3085,7 +3164,8 @@ const parseJSON = (str) => {
3085
3164
  const formattedStr = str
3086
3165
  .replace(/\n/g, '\\n')
3087
3166
  .replace(/\r/g, '\\r')
3088
- .replace(/\t/g, '\\t');
3167
+ .replace(/\t/g, '\\t')
3168
+ .replace(/\x00/g, '');
3089
3169
  return JSON.parse(formattedStr, (key, value) => {
3090
3170
  return value;
3091
3171
  });
@@ -3259,7 +3339,7 @@ const getAppInfo = (appId, versionStatus, currentVersion) => __awaiter(void 0, v
3259
3339
  if (!_.isUndefined(currentVersion)) {
3260
3340
  inputData.currentVersion = currentVersion;
3261
3341
  }
3262
- const api = QueryString.appendToUrl(`${API_DOMAIN}${H5_API.GET_APP_INFO}`, inputData);
3342
+ const api = QueryString.appendToUrl(APIS.GET_APP_INFO, inputData);
3263
3343
  const msgApi = yield fetch(api, {
3264
3344
  credentials: 'include'
3265
3345
  });
@@ -3651,504 +3731,97 @@ class ZMPEEmitter extends eventemitter3 {
3651
3731
  }
3652
3732
  }
3653
3733
 
3654
- var wrappers = {};
3655
- var WrapperFn = function wrapFunction(fn, type, source) {
3656
- var t = type || 'default';
3657
- return function () {
3658
- var callee = t in wrappers ? wrappers[t](fn, source) : fn;
3659
- return callee.apply(this, arguments);
3660
- };
3661
- };
3662
- WrapperFn.setWrapper = function (fn) {
3663
- var type = arguments.length <= 1 || arguments[1] === undefined
3664
- ? 'default'
3665
- : arguments[1];
3666
- wrappers[type] = fn;
3667
- };
3668
- var ERROR = {
3669
- error: {
3670
- code: 1,
3671
- error_subcode: 1357046,
3672
- message: 'Received Invalid JSON reply.',
3673
- type: 'http'
3674
- }
3675
- };
3676
- function safelyParseResponse(rawResponse) {
3677
- try {
3678
- return rawResponse === null ? ERROR : JSON.parse(rawResponse);
3679
- }
3680
- catch (ex) {
3681
- return ERROR;
3734
+ var version$1 = "2.21.0-rc";
3735
+
3736
+ class Basics {
3737
+ /**
3738
+ * Lấy version hiện tại của Zalo Mini Program SDK
3739
+ *
3740
+ * @category Basics
3741
+ *
3742
+ * @returns {string} Version hiện tại của Zalo Mini Program SDK.
3743
+ */
3744
+ static getVersion() {
3745
+ return version$1;
3682
3746
  }
3683
- }
3684
- function createCORSRequest(method, url) {
3685
- if (!self.XMLHttpRequest) {
3686
- return null;
3747
+ /**
3748
+ * Gets system information.
3749
+ *
3750
+ * @function getSystemInfo
3751
+ * @category Basics
3752
+ *
3753
+ *
3754
+ *
3755
+ */
3756
+ static getSystemInfo() {
3757
+ const system = {
3758
+ version: getMetaValue('version-id') || '',
3759
+ apiVersion: version$1,
3760
+ zaloVersion: getZaloVersion(),
3761
+ platform: getPlatform(),
3762
+ language: navigator.language,
3763
+ zaloLanguage: window.zLanguage || 'vi',
3764
+ zaloTheme: window.zTheme || 'light'
3765
+ };
3766
+ return system;
3687
3767
  }
3688
- var xhr = new XMLHttpRequest();
3689
- var noop = function noop() { };
3690
- if ('withCredentials' in xhr) {
3691
- xhr.open(method, url, true);
3692
- xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
3768
+ /**
3769
+ * Lấy thông tin mini app
3770
+ *
3771
+ * @async
3772
+ * @function getAppInfo
3773
+ * @category Device
3774
+ *
3775
+ */
3776
+ static getAppInfo() {
3777
+ return __awaiter(this, void 0, void 0, function* () {
3778
+ const appId = this.getAppId();
3779
+ const systemInfo = this.getSystemInfo();
3780
+ return yield getAppInfo(appId, 0, systemInfo.version);
3781
+ });
3693
3782
  }
3694
- else {
3695
- return null;
3696
- }
3697
- var wrapper = {
3698
- send: function send(data) {
3699
- xhr.send(data);
3700
- }
3701
- };
3702
- var onload = WrapperFn(function () {
3703
- onload = noop;
3704
- if ('onload' in wrapper) {
3705
- wrapper.onload(xhr);
3706
- }
3707
- }, 'entry', 'XMLHttpRequest:load');
3708
- var onerror = WrapperFn(function () {
3709
- onerror = noop;
3710
- if ('onerror' in wrapper) {
3711
- wrapper.onerror(xhr);
3712
- }
3713
- }, 'entry', 'XMLHttpRequest:error');
3714
- xhr.onload = function () {
3715
- onload();
3716
- };
3717
- xhr.onerror = function () {
3718
- onerror();
3719
- };
3720
- xhr.onreadystatechange = function () {
3721
- if (xhr.readyState == 4) {
3722
- if (xhr.status == 200) {
3723
- onload();
3724
- }
3725
- else {
3726
- onerror();
3727
- }
3728
- }
3729
- };
3730
- return wrapper;
3731
- }
3732
- function execute(url, method, params, cb) {
3733
- params.suppress_http_code = 1;
3734
- var data = QueryString.encode(params);
3735
- if (method != 'post') {
3736
- url = QueryString.appendToUrl(url, data);
3737
- data = '';
3738
- }
3739
- var request = createCORSRequest(method, url);
3740
- if (!request) {
3741
- return false;
3742
- }
3743
- request.onload = function (xhr) {
3744
- cb(safelyParseResponse(xhr.responseText));
3745
- };
3746
- request.onerror = function (xhr) {
3747
- if (xhr.responseText) {
3748
- cb(safelyParseResponse(xhr.responseText));
3749
- }
3750
- else {
3751
- cb({
3752
- error: {
3753
- code: 1,
3754
- error_subcode: 1357045,
3755
- message: 'unknown error (empty response)',
3756
- status: xhr.status,
3757
- type: 'http'
3758
- }
3759
- });
3760
- }
3761
- };
3762
- request.send(data);
3763
- return true;
3764
- }
3765
- var CORSRequest = {
3766
- execute: execute
3767
- };
3768
-
3769
- class ZaloJSBridge extends eventemitter3 {
3770
- constructor() {
3771
- super();
3772
- this.debug = Debug('zmp:ZaloJSBridge');
3773
- this.events = ZMPEEmitter.getInstance();
3774
- this._accessTk = getToken('zacc_session') || 'DEFAULT_ACCESS_TOKEN';
3775
- this._jsAccessTk = getToken('zlink3rd') || 'DEFAULT_JS_TOKEN';
3776
- this.results = [];
3777
- this._userAgent = getUserAgent();
3778
- this._device = checkPlatform();
3779
- this._jsCallFuncCallbacks = {};
3780
- this.events.on(Events.AppPaused, () => {
3781
- if (this.results.length > 0) {
3782
- let array = this.results;
3783
- this.results = [];
3784
- try {
3785
- this.sendLogData(array);
3786
- }
3787
- catch (error) { }
3788
- }
3789
- });
3790
- if (this.sendLogTimer) {
3791
- clearInterval(this.sendLogTimer);
3792
- }
3793
- else {
3794
- this.sendLogTimer = setInterval(() => {
3795
- if (this.results.length > 0) {
3796
- let array = this.results;
3797
- this.results = [];
3798
- try {
3799
- this.sendLogData(array);
3800
- }
3801
- catch (error) { }
3802
- }
3803
- }, 5000);
3804
- }
3805
- }
3806
- static getInstance() {
3807
- if (!ZaloJSBridge.instance) {
3808
- ZaloJSBridge.instance = new ZaloJSBridge();
3809
- }
3810
- return ZaloJSBridge.instance;
3811
- }
3812
- set accessTk(value) {
3813
- this._accessTk = value;
3814
- }
3815
- set jsAccessTk(value) {
3816
- this._jsAccessTk = value;
3817
- }
3818
- sendLogData(data) {
3819
- try {
3820
- CORSRequest.execute('https://h5.zalo.me/log/async', 'post', {
3821
- appId: window.APP_ID,
3822
- data: JSON.stringify(data)
3823
- }, (response) => { });
3824
- }
3825
- catch (error) { }
3826
- }
3827
- onJSCall(key, data) {
3828
- try {
3829
- this.debug('onJSCall', key, data);
3830
- const parsedData = parseJSON(data);
3831
- if (this._jsCallFuncCallbacks[key]) {
3832
- const callback = this._jsCallFuncCallbacks[key].callback;
3833
- const timeout = this._jsCallFuncCallbacks[key].timeout;
3834
- if (!!callback) {
3835
- try {
3836
- callback.call(this, parsedData);
3837
- }
3838
- catch (error) {
3839
- console.error('Call callback error', error);
3840
- }
3841
- !!timeout && clearTimeout(timeout);
3842
- this._jsCallFuncCallbacks[key] = null;
3843
- delete this._jsCallFuncCallbacks[key];
3844
- }
3845
- }
3846
- this.results.push({
3847
- action: parsedData.action,
3848
- error: parsedData.error_code
3849
- });
3850
- }
3851
- catch (e) {
3852
- console.log('onJSCall', 'error', e);
3853
- }
3854
- }
3855
- onMultiJSCall(key, data) {
3856
- try {
3857
- this.debug('onMultiJSCall', key, data);
3858
- const parsedData = parseJSON(data);
3859
- if (this._jsCallFuncCallbacks[key]) {
3860
- const callback = this._jsCallFuncCallbacks[key].callback;
3861
- const timeout = this._jsCallFuncCallbacks[key].timeout;
3862
- if (!!callback) {
3863
- try {
3864
- callback.call(this, parsedData);
3865
- }
3866
- catch (error) {
3867
- console.error('Call callback error', error);
3868
- }
3869
- !!timeout && clearTimeout(timeout);
3870
- }
3871
- }
3872
- this.results.push({
3873
- action: parsedData.action,
3874
- error: parsedData.error_code
3875
- });
3876
- }
3877
- catch (e) {
3878
- console.log('onMultiJSCall', 'error', e);
3879
- }
3880
- }
3881
- nativeEventHandler(eventId, eventName, eventData) {
3882
- this.debug(`eventId: ${eventId}, eventName: ${eventName}, eventData: ${eventData}`);
3883
- const data = stringToData(eventData);
3884
- this.debug(data);
3885
- const convertedData = this.handleEventData(eventName, data);
3886
- this.events.emit(eventName, eventId, convertedData);
3887
- }
3888
- handleEventData(eventName, data) {
3889
- try {
3890
- switch (eventName) {
3891
- case Events.OpenApp:
3892
- const { url } = data;
3893
- const validUrl = new URL(url);
3894
- const path = validUrl.pathname.split(`/zapps/${APP_ID}`)[1];
3895
- return {
3896
- path: `${path ? path : '/'}${validUrl.search}`
3897
- };
3898
- break;
3899
- default:
3900
- return data;
3901
- break;
3902
- }
3903
- }
3904
- catch (error) {
3905
- return data;
3906
- }
3907
- }
3908
- defaultCallback(data) {
3909
- if (data !== null && data !== undefined) {
3910
- data = parseJSON(data);
3911
- }
3912
- }
3913
- jsCall(action, options, callback, isMultiCallback = false, nRetry = 3, haveTimeout = true) {
3914
- try {
3915
- const actionName = action.name;
3916
- const key = generateUniqueString(actionName);
3917
- if (!this._device.isMobile || _.isEmpty(actionName)) {
3918
- this.onJSCall(key, {
3919
- error_code: -13,
3920
- error_message: 'params invalid!',
3921
- data: {
3922
- device: this._device.isMobile,
3923
- jsToken: this._jsAccessTk,
3924
- access_token: this._accessTk
3925
- },
3926
- action: actionName
3927
- });
3928
- return false;
3929
- }
3930
- if (options === undefined || options === null) {
3931
- options = {};
3932
- }
3933
- if (!callback) {
3934
- callback = this.defaultCallback;
3935
- }
3936
- const timeoutCallback = {
3937
- error_code: -14,
3938
- error_message: 'Request Timeout!',
3939
- data: {},
3940
- action: actionName
3941
- };
3942
- this._jsCallFuncCallbacks[key] = {
3943
- timeout: haveTimeout &&
3944
- action.have_callback &&
3945
- setTimeout(() => {
3946
- this.onJSCall(key, timeoutCallback);
3947
- }, 8000),
3948
- callback: callback
3949
- };
3950
- try {
3951
- options = serialize(options);
3952
- if (isMultiCallback) {
3953
- if (this._device.isIOS) {
3954
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onMultiJSCall(key));
3955
- }
3956
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onMultiJSCall('${key}')`);
3957
- }
3958
- if (this._device.isIOS) {
3959
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onJSCall(key));
3960
- }
3961
- return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onJSCall('${key}')`);
3962
- }
3963
- catch (error) {
3964
- if (nRetry-- > 0) {
3965
- setTimeout(() => {
3966
- this.jsCall(action, options, callback, isMultiCallback, nRetry);
3967
- }, 500);
3968
- }
3969
- else {
3970
- const errorCallback = {
3971
- error_code: -5,
3972
- error_message: 'Not ready!',
3973
- data: {
3974
- userAgent: this._userAgent,
3975
- options: options,
3976
- jsToken: this._jsAccessTk,
3977
- access_token: this._accessTk
3978
- },
3979
- action: actionName,
3980
- js_error: error
3981
- };
3982
- this.onJSCall(key, errorCallback);
3983
- return false;
3984
- }
3985
- }
3986
- }
3987
- catch (error) {
3988
- console.log('jsCall', 'error', error);
3989
- }
3990
- return false;
3991
- }
3992
- }
3993
-
3994
- var _ZJSBridgeProvider_bridge;
3995
- /** @ignore */
3996
- class ZJSBridgeProvider {
3997
- /** @ignore */
3998
- constructor() {
3999
- this.debug = Debug('zmp:ZJSBridgeProvider');
4000
- _ZJSBridgeProvider_bridge.set(this, void 0);
4001
- __classPrivateFieldSet(this, _ZJSBridgeProvider_bridge, ZaloJSBridge.getInstance(), "f");
4002
- }
4003
- setZAccSession(value) {
4004
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").accessTk = value;
4005
- }
4006
- setJSToken(value) {
4007
- __classPrivateFieldGet(this, _ZJSBridgeProvider_bridge, "f").jsAccessTk = value;
4008
- }
4009
- callNative(action, data, option) {
4010
- this.debug(action.name, data);
4011
- return new Promise((resolve, reject) => {
4012
- const fn = (cb) => __awaiter(this, void 0, void 0, function* () {
4013
- try {
4014
- const error = new NativeError(cb.error_code, `${cb.action}: ${cb.error_message}`);
4015
- if (option === null || option === void 0 ? void 0 : option.callback) {
4016
- const res = yield option.callback(cb, error);
4017
- return resolve(res);
4018
- }
4019
- else {
4020
- if (cb && cb.error_code >= 0) {
4021
- resolve(cb.data || {});
4022
- }
4023
- else if (cb && cb.error_code < 0) {
4024
- try {
4025
- window.zmpSentry &&
4026
- window.zmpSentry.captureMessage(`${action.name}: call native fail`, {
4027
- extra: {
4028
- data: data,
4029
- rs: cb
4030
- }
4031
- });
4032
- }
4033
- catch (error) { }
4034
- return reject(error);
4035
- }
4036
- }
4037
- }
4038
- catch (error) {
4039
- return reject(error);
4040
- }
4041
- });
4042
- const isIOS = checkPlatform().isIOS;
4043
- const isSupportAction = checkIOSSupportAction(action);
4044
- if (isIOS && !isSupportAction) {
4045
- const error = new NativeError(-5, `${action}: Client isn't support this action`);
4046
- return reject(error);
4047
- }
4048
- else if (option === null || option === void 0 ? void 0 : option.delay) {
4049
- setTimeout(() => {
4050
- __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);
4051
- }, option.delay);
4052
- }
4053
- else {
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
- }
4056
- });
4057
- }
4058
- }
4059
- _ZJSBridgeProvider_bridge = new WeakMap();
4060
-
4061
- var version$1 = "2.19.1";
4062
-
4063
- class Basics {
4064
- /**
4065
- * Lấy version hiện tại của Zalo Mini Program SDK
4066
- *
4067
- * @category Basics
4068
- *
4069
- * @returns {string} Version hiện tại của Zalo Mini Program SDK.
4070
- */
4071
- static getVersion() {
4072
- return version$1;
4073
- }
4074
- /**
4075
- * Gets system information.
4076
- *
4077
- * @function getSystemInfo
4078
- * @category Basics
4079
- *
4080
- *
4081
- *
4082
- */
4083
- static getSystemInfo() {
4084
- const system = {
4085
- version: getMetaValue('version-id') || '',
4086
- apiVersion: version$1,
4087
- zaloVersion: getZaloVersion(),
4088
- platform: getPlatform(),
4089
- language: navigator.language,
4090
- zaloLanguage: window.zLanguage || 'vi',
4091
- zaloTheme: window.zTheme || 'light'
4092
- };
4093
- return system;
4094
- }
4095
- /**
4096
- * Lấy thông tin mini app
4097
- *
4098
- * @async
4099
- * @function getAppInfo
4100
- * @category Device
4101
- *
4102
- */
4103
- static getAppInfo() {
4104
- return __awaiter(this, void 0, void 0, function* () {
4105
- const appId = this.getAppId();
4106
- const systemInfo = this.getSystemInfo();
4107
- return yield getAppInfo(appId, 0, systemInfo.version);
4108
- });
4109
- }
4110
- }
4111
-
4112
- class NavigationBar {
4113
- /**
4114
- * A promise for the user's favorite color.
4115
- *
4116
- * @promise FavoriteColorPromise
4117
- * @fulfill {string} The user's favorite color.
4118
- * @reject {TypeError} The user's favorite color is an invalid type.
4119
- * @reject {MissingColorError} The user has not specified a favorite color.
4120
- */
4121
- /**
4122
- * Dynamically sets the title of the current page.
4123
- *
4124
- * @async
4125
- * @function setNavigationBarTitle
4126
- * @category Navigation Bar
4127
- *
4128
- * @example
4129
- *
4130
- * zmpApis.setNavigationBarTitle({
4131
- * title: "Current Page"
4132
- * }).then((res) => {
4133
- * console.log("Success");
4134
- * }).catch((error) => {
4135
- * console.log("Fail");
4136
- * });
4137
- *
4138
- * @param {Object} object
4139
- * @param {string} object.title - The title of the page
4140
- *
4141
- * @return {Promise}
4142
- *
4143
- */
4144
- static setNavigationBarTitle(object) {
4145
- return __awaiter(this, void 0, void 0, function* () {
4146
- yield this.callNative(ACTION.CHANGE_TITLE_HEADER, {
4147
- title: object.title
4148
- }, {
4149
- haveTimeout: false
4150
- });
4151
- });
3783
+ }
3784
+
3785
+ class NavigationBar {
3786
+ /**
3787
+ * A promise for the user's favorite color.
3788
+ *
3789
+ * @promise FavoriteColorPromise
3790
+ * @fulfill {string} The user's favorite color.
3791
+ * @reject {TypeError} The user's favorite color is an invalid type.
3792
+ * @reject {MissingColorError} The user has not specified a favorite color.
3793
+ */
3794
+ /**
3795
+ * Dynamically sets the title of the current page.
3796
+ *
3797
+ * @async
3798
+ * @function setNavigationBarTitle
3799
+ * @category Navigation Bar
3800
+ *
3801
+ * @example
3802
+ *
3803
+ * zmpApis.setNavigationBarTitle({
3804
+ * title: "Current Page"
3805
+ * }).then((res) => {
3806
+ * console.log("Success");
3807
+ * }).catch((error) => {
3808
+ * console.log("Fail");
3809
+ * });
3810
+ *
3811
+ * @param {Object} object
3812
+ * @param {string} object.title - The title of the page
3813
+ *
3814
+ * @return {Promise}
3815
+ *
3816
+ */
3817
+ static setNavigationBarTitle(object) {
3818
+ return __awaiter(this, void 0, void 0, function* () {
3819
+ yield this.getJSBridge().callNative(ACTION.CHANGE_TITLE_HEADER, {
3820
+ title: object.title
3821
+ }, {
3822
+ haveTimeout: false
3823
+ });
3824
+ });
4152
3825
  }
4153
3826
  /**
4154
3827
  * Sets the color of the navigation bar in the page.
@@ -4191,7 +3864,7 @@ class NavigationBar {
4191
3864
  actionBarType = HIDE_ACTION_BAR;
4192
3865
  }
4193
3866
  this.setActionBarConfig((state) => (Object.assign(Object.assign({}, state), { actionbarType: actionBarType, dataConfig: Object.assign(Object.assign({}, state.dataConfig), dataConfig) })));
4194
- yield this.callNative(ACTION.CHANGE_ACTIONBAR, Object.assign({}, this.getActionBarConfig()), {
3867
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, Object.assign({}, this.getActionBarConfig()), {
4195
3868
  haveTimeout: false
4196
3869
  });
4197
3870
  });
@@ -4226,62 +3899,32 @@ class NavigationBar {
4226
3899
  * @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
4227
3900
  * @param {Function} [object.handleCloseEvent] - Specifies a function that will be called when user click close button. Only when ```confirmToExit``` is 2
4228
3901
  */
4229
- static setNavigationBarLeftButton(object) {
4230
- return __awaiter(this, void 0, void 0, function* () {
4231
- const leftButtonType = object.type === 'none' || object.type === 'home'
4232
- ? ACTION_LEFT_BUTTON_TYPE.HIDE_BACK
4233
- : ACTION_LEFT_BUTTON_TYPE.SHOW_BACK;
4234
- const showHomeButton = object.type === 'home' || object.type === 'both'
4235
- ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
4236
- : ACTION_LEFT_BUTTON_TYPE.HIDE_HOME;
4237
- 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 }) })));
4238
- yield this.callNative(ACTION.CHANGE_ACTIONBAR_LEFTBUTTON_TYPE, Object.assign({}, this.getActionBarConfig()), {
3902
+ static setNavigationBarLeftButton(type, confirmToExit) {
3903
+ return __awaiter(this, void 0, void 0, function* () {
3904
+ let leftButtonType;
3905
+ let showHomeButton;
3906
+ if (_.isString(type)) {
3907
+ leftButtonType =
3908
+ type === 'none' || type === 'home'
3909
+ ? ACTION_LEFT_BUTTON_TYPE.HIDE_BACK
3910
+ : ACTION_LEFT_BUTTON_TYPE.SHOW_BACK;
3911
+ showHomeButton =
3912
+ type === 'home' || type === 'both'
3913
+ ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
3914
+ : ACTION_LEFT_BUTTON_TYPE.HIDE_HOME;
3915
+ }
3916
+ 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 }) })));
3917
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR_LEFTBUTTON_TYPE, Object.assign({}, this.getActionBarConfig()), {
4239
3918
  haveTimeout: false
4240
3919
  });
4241
3920
  });
4242
3921
  }
4243
- /**
4244
- * @ignore
4245
- * Dynamically sets the right button of the current page.
4246
- *
4247
- * @ignore
4248
- * @category Navigation Bar
4249
- *
4250
- * @example
4251
- * zmpApis.setNavigationBarRightButton({
4252
- * supportToolBar: 1,
4253
- * reset: 0,
4254
- * menuListItems: [{
4255
- * title: "Post on timeline",
4256
- * action: "zalo.web.internal.postfeed",
4257
- * showAsAction: 0,
4258
- * iconUrl: "https://cdn3.iconfinder.com/data/icons/user-interface-3-3/34/251-512.png",
4259
- * type: 0,
4260
- * data: {}
4261
- * }],
4262
- * }).then((res) => {
4263
- * console.log("Success");
4264
- * }).catch((error) => {
4265
- * console.log("Fail");
4266
- * });
4267
- *
4268
- * @param {Object} object
4269
- * @param {Number} object.title - Title of a menu item
4270
- * @param {Number} object.action - Native action
4271
- * @param {string} object.showAsAction
4272
- * If ```showAsAction``` is 1 and ```iconUrl``` can load,
4273
- * this item will be shown outside and next to more-button. Maximum 2 item will be shown
4274
- * @param {Function} object.iconUrl - Specifies icon of a menu item
4275
- * @param {0} object.type
4276
- * @param {Object} object.data - Data depends on ```action```
4277
- */
4278
- static setNavigationBarRightButton(object) {
3922
+ static setNavigationBar(data) {
4279
3923
  return __awaiter(this, void 0, void 0, function* () {
4280
- yield this.callNative(ACTION.CREATE_OPTIONS_MENU, {
4281
- supportToolBar: object.supportToolBar,
4282
- reset: object.reset,
4283
- menuListItems: object.menuListItems,
4284
- zapp: this.getAppId()
3924
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, {
3925
+ data
3926
+ }, {
3927
+ haveTimeout: false
4285
3928
  });
4286
3929
  });
4287
3930
  }
@@ -4313,7 +3956,7 @@ class Background {
4313
3956
  return __awaiter(this, void 0, void 0, function* () {
4314
3957
  if (_.isString(object.backgroundColor) &&
4315
3958
  object.backgroundColor.length > 0) {
4316
- yield this.callNative(ACTION.CHANGE_ACTIONBAR, {
3959
+ yield this.getJSBridge().callNative(ACTION.CHANGE_ACTIONBAR, {
4317
3960
  actionbarType: this.isShowNavBar ? 5 : 6,
4318
3961
  dataConfig: {
4319
3962
  backgroundColor: object.backgroundColor,
@@ -4425,7 +4068,7 @@ class Device {
4425
4068
  */
4426
4069
  static setDeviceOrientation(object) {
4427
4070
  return __awaiter(this, void 0, void 0, function* () {
4428
- yield this.callNative(ACTION.CHANGE_AUTOROTATE, {
4071
+ yield this.getJSBridge().callNative(ACTION.CHANGE_AUTOROTATE, {
4429
4072
  autoRotate: OrientationType[object.rotate]
4430
4073
  });
4431
4074
  });
@@ -4449,7 +4092,7 @@ class Device {
4449
4092
  */
4450
4093
  static getNetworkType(object) {
4451
4094
  return __awaiter(this, void 0, void 0, function* () {
4452
- const resData = yield this.callNative(ACTION.WEBVIEW_NETWORKTYPE, {
4095
+ const resData = yield this.getJSBridge().callNative(ACTION.WEBVIEW_NETWORKTYPE, {
4453
4096
  url: window.location.href,
4454
4097
  featureId: ''
4455
4098
  }).then((data) => {
@@ -4563,7 +4206,7 @@ class Device {
4563
4206
  items: Array.isArray(object === null || object === void 0 ? void 0 : object.items) ? object === null || object === void 0 ? void 0 : object.items : []
4564
4207
  }
4565
4208
  };
4566
- yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4209
+ yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4567
4210
  return true;
4568
4211
  });
4569
4212
  }
@@ -4582,7 +4225,7 @@ class Device {
4582
4225
  const data = {
4583
4226
  subaction: 2
4584
4227
  };
4585
- yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4228
+ yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data));
4586
4229
  return true;
4587
4230
  });
4588
4231
  }
@@ -4603,7 +4246,7 @@ class Device {
4603
4246
  const data = {
4604
4247
  subaction: 1
4605
4248
  };
4606
- const resData = yield this.callNative(ACTION.SCAN_IBEACON, Object.assign({}, data), {
4249
+ const resData = yield this.getJSBridge().callNative(ACTION.SCAN_IBEACON, Object.assign({}, data), {
4607
4250
  isMultiCallback: true
4608
4251
  }).then((resData) => {
4609
4252
  const res = {
@@ -4645,7 +4288,7 @@ class Device {
4645
4288
  */
4646
4289
  static stopBluetoothDevicesDiscovery() {
4647
4290
  return __awaiter(this, void 0, void 0, function* () {
4648
- return this.callNative({
4291
+ return this.getJSBridge().callNative({
4649
4292
  name: ''
4650
4293
  }, {});
4651
4294
  });
@@ -4672,7 +4315,7 @@ class Device {
4672
4315
  */
4673
4316
  static startBluetoothDevicesDiscovery(object) {
4674
4317
  return __awaiter(this, void 0, void 0, function* () {
4675
- return this.callNative({
4318
+ return this.getJSBridge().callNative({
4676
4319
  name: ''
4677
4320
  }, Object.assign({}, object));
4678
4321
  });
@@ -4696,7 +4339,7 @@ class Device {
4696
4339
  */
4697
4340
  static openBluetoothAdapter() {
4698
4341
  return __awaiter(this, void 0, void 0, function* () {
4699
- return this.callNative({
4342
+ return this.getJSBridge().callNative({
4700
4343
  name: ''
4701
4344
  }, {});
4702
4345
  });
@@ -4716,7 +4359,7 @@ class Device {
4716
4359
  */
4717
4360
  static onBluetoothDeviceFound() {
4718
4361
  return __awaiter(this, void 0, void 0, function* () {
4719
- return this.callNative({
4362
+ return this.getJSBridge().callNative({
4720
4363
  name: ''
4721
4364
  }, {});
4722
4365
  });
@@ -4764,7 +4407,7 @@ class Device {
4764
4407
  const data = {
4765
4408
  services: object.services || []
4766
4409
  };
4767
- return this.callNative({
4410
+ return this.getJSBridge().callNative({
4768
4411
  name: ''
4769
4412
  }, data);
4770
4413
  });
@@ -4785,7 +4428,7 @@ class Device {
4785
4428
  */
4786
4429
  static getBluetoothDevices() {
4787
4430
  return __awaiter(this, void 0, void 0, function* () {
4788
- return this.callNative({
4431
+ return this.getJSBridge().callNative({
4789
4432
  name: ''
4790
4433
  }, {});
4791
4434
  });
@@ -4806,7 +4449,7 @@ class Device {
4806
4449
  */
4807
4450
  static getBluetoothAdapterState() {
4808
4451
  return __awaiter(this, void 0, void 0, function* () {
4809
- return this.callNative({
4452
+ return this.getJSBridge().callNative({
4810
4453
  name: ''
4811
4454
  }, {});
4812
4455
  });
@@ -4827,7 +4470,7 @@ class Device {
4827
4470
  */
4828
4471
  static closeBluetoothAdapter() {
4829
4472
  return __awaiter(this, void 0, void 0, function* () {
4830
- return this.callNative({
4473
+ return this.getJSBridge().callNative({
4831
4474
  name: ''
4832
4475
  }, {});
4833
4476
  });
@@ -4841,7 +4484,7 @@ class Device {
4841
4484
  */
4842
4485
  static scanQRCode(object) {
4843
4486
  return __awaiter(this, void 0, void 0, function* () {
4844
- return yield this.callNative(ACTION.OPEN_QR, {
4487
+ return yield this.getJSBridge().callNative(ACTION.OPEN_QR, {
4845
4488
  skipOpenLink: true
4846
4489
  });
4847
4490
  });
@@ -4855,308 +4498,770 @@ class Device {
4855
4498
  */
4856
4499
  static showToast(object) {
4857
4500
  return __awaiter(this, void 0, void 0, function* () {
4858
- yield this.callNative(ACTION.SHOW_TOAST, {
4501
+ yield this.getJSBridge().callNative(ACTION.SHOW_TOAST, {
4859
4502
  toast: object.message
4860
4503
  });
4861
4504
  });
4862
4505
  }
4863
- /**
4864
- * Ẩn keyboard
4865
- * @async
4866
- * @function hideKeyboard
4867
- * @category Device
4868
- *
4869
- */
4870
- static hideKeyboard(object) {
4506
+ /**
4507
+ * Ẩn keyboard
4508
+ * @async
4509
+ * @function hideKeyboard
4510
+ * @category Device
4511
+ *
4512
+ */
4513
+ static hideKeyboard(object) {
4514
+ return __awaiter(this, void 0, void 0, function* () {
4515
+ yield this.getJSBridge().callNative(ACTION.HIDE_KEYBOARD, {});
4516
+ });
4517
+ }
4518
+ /**
4519
+ * Open phone
4520
+ * @async
4521
+ * @function openPhone
4522
+ * @category Device
4523
+ *
4524
+ */
4525
+ static openPhone(object) {
4526
+ return __awaiter(this, void 0, void 0, function* () {
4527
+ yield this.getJSBridge().callNative(ACTION.OPEN_PHONE, {
4528
+ phoneNum: object.phoneNumber,
4529
+ phoneCode: object.phoneNumber
4530
+ });
4531
+ });
4532
+ }
4533
+ /**
4534
+ * Open SMS
4535
+ * @async
4536
+ * @function openSMS
4537
+ * @category Device
4538
+ *
4539
+ */
4540
+ static openSMS(object) {
4541
+ return __awaiter(this, void 0, void 0, function* () {
4542
+ yield this.getJSBridge().callNative(ACTION.OPEN_SMS, {
4543
+ content: object.content,
4544
+ phoneCode: object.phoneNumber
4545
+ });
4546
+ });
4547
+ }
4548
+ /**
4549
+ * Keep screen.
4550
+ * @async
4551
+ * @function keepScreen
4552
+ * @category Device
4553
+ *
4554
+ */
4555
+ static keepScreen(object) {
4556
+ return __awaiter(this, void 0, void 0, function* () {
4557
+ return yield this.getJSBridge().callNative(ACTION.KEEP_SCREEN, {
4558
+ data: {
4559
+ keep_screen_on: object.keepScreenOn ? 1 : 0
4560
+ }
4561
+ });
4562
+ });
4563
+ }
4564
+ /**
4565
+ * Xác thực bằng sinh trắc học
4566
+ * @async
4567
+ * @function openBioAuthentication
4568
+ * @category Authentication
4569
+ *
4570
+ */
4571
+ static openBioAuthentication(object) {
4572
+ return __awaiter(this, void 0, void 0, function* () {
4573
+ return yield this.getJSBridge().callNative(ACTION.PROMPT_AUTHENTICATION, {
4574
+ secret_data: object.secretData,
4575
+ app_id: this.getZAppId(),
4576
+ ui: {
4577
+ title: object.ui.title,
4578
+ sub_title: object.ui.subTitle,
4579
+ negative_text: object.ui.negativeButtonText
4580
+ },
4581
+ require_fingerprint: object.requireFingerprint ? 1 : 0
4582
+ }).then((data) => {
4583
+ var _a, _b, _c, _d;
4584
+ return {
4585
+ code: data === null || data === void 0 ? void 0 : data.error_code,
4586
+ message: data === null || data === void 0 ? void 0 : data.error_message,
4587
+ data: {
4588
+ domain: (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.domain,
4589
+ code: (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.error_code,
4590
+ message: (_c = data === null || data === void 0 ? void 0 : data.data) === null || _c === void 0 ? void 0 : _c.error_message,
4591
+ payToken: (_d = data === null || data === void 0 ? void 0 : data.data) === null || _d === void 0 ? void 0 : _d.pay_token
4592
+ }
4593
+ };
4594
+ });
4595
+ });
4596
+ }
4597
+ /**
4598
+ * 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...)
4599
+ * @async
4600
+ * @function checkStateBioAuthentication
4601
+ * @category Authentication
4602
+ *
4603
+ * @example
4604
+ * api.checkStateAuthen({
4605
+ * success: (res) => {},
4606
+ * fail: (err) => {}
4607
+ * })
4608
+ * @param {InputDataType.CallbackType} object
4609
+ */
4610
+ static checkStateBioAuthentication(object) {
4611
+ return __awaiter(this, void 0, void 0, function* () {
4612
+ return yield this.getJSBridge().callNative(ACTION.PROMPT_AUTHENTICATION_CHECK_STATE, {}).then((data) => {
4613
+ return {
4614
+ bioState: data === null || data === void 0 ? void 0 : data.bio_state
4615
+ };
4616
+ });
4617
+ });
4618
+ }
4619
+ /**
4620
+ * Vibrate.
4621
+ * @async
4622
+ * @function vibrate
4623
+ * @category Device
4624
+ *
4625
+ */
4626
+ static vibrate(object) {
4627
+ return __awaiter(this, void 0, void 0, function* () {
4628
+ return yield this.getJSBridge().callNative(ACTION.INTERACTIVE_VIBRATION, {
4629
+ type: VibrateType[object.type],
4630
+ vibrate_time: object.milliseconds
4631
+ });
4632
+ });
4633
+ }
4634
+ /**
4635
+ * Connect Wifi.
4636
+ * @async
4637
+ * @function connectWifi
4638
+ * @category Device
4639
+ *
4640
+ */
4641
+ static connectWifi(object) {
4642
+ return __awaiter(this, void 0, void 0, function* () {
4643
+ let securityType = 'open';
4644
+ if (_.isString(object.password) && object.password.length > 0) {
4645
+ securityType = 'wpa_wpa2';
4646
+ }
4647
+ return yield this.getJSBridge().callNative(ACTION.MP_JOIN_WIFI, {
4648
+ ssid: object.SSID,
4649
+ securityType: securityType,
4650
+ password: object.password,
4651
+ hiddenSsid: object.hiddenSSID
4652
+ });
4653
+ });
4654
+ }
4655
+ /**
4656
+ * Open App Store.
4657
+ * @async
4658
+ * @function openAppStore
4659
+ * @category Device
4660
+ *
4661
+ */
4662
+ static openAppStore(object) {
4663
+ return __awaiter(this, void 0, void 0, function* () {
4664
+ return yield this.getJSBridge().callNative(ACTION.OPEN_APPSTORE, object);
4665
+ });
4666
+ }
4667
+ }
4668
+
4669
+ var _LocalResourceStorage_storage, _LocalResourceStorage_prefix, _LocalResourceStorage_resourceInfo;
4670
+ class LocalResourceStorage {
4671
+ constructor(prefix) {
4672
+ _LocalResourceStorage_storage.set(this, localStorage);
4673
+ _LocalResourceStorage_prefix.set(this, void 0);
4674
+ _LocalResourceStorage_resourceInfo.set(this, void 0);
4675
+ checkPlatform();
4676
+ // if (platform.isMobile && platform.isZalo) {
4677
+ // Object.defineProperty(window, 'localStorage', {
4678
+ // value: null,
4679
+ // configurable: true,
4680
+ // enumerable: true,
4681
+ // writable: false
4682
+ // });
4683
+ // }
4684
+ __classPrivateFieldSet(this, _LocalResourceStorage_resourceInfo, {
4685
+ keys: new Set(),
4686
+ currentSize: 0,
4687
+ limitSize: STORAGE_LIMIT
4688
+ }, "f");
4689
+ __classPrivateFieldSet(this, _LocalResourceStorage_prefix, prefix, "f");
4690
+ this.findAllCurrentDataByApp(prefix);
4691
+ }
4692
+ findAllCurrentDataByApp(prefix) {
4693
+ try {
4694
+ let _x;
4695
+ for (_x in __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f")) {
4696
+ if (prefix) {
4697
+ const _prefix = _x.split('_')[0];
4698
+ if (_prefix !== prefix) {
4699
+ continue;
4700
+ }
4701
+ }
4702
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(_x);
4703
+ }
4704
+ }
4705
+ catch (error) {
4706
+ logger.error(error, 'LocalResourceStorage > findAllCurrentDataByApp');
4707
+ }
4708
+ }
4709
+ get(keys) {
4710
+ let res = new Map();
4711
+ keys.forEach((key) => {
4712
+ res.set(key, this.getSync(key));
4713
+ });
4714
+ return Promise.resolve(res);
4715
+ }
4716
+ getSync(key) {
4717
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
4718
+ key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
4719
+ }
4720
+ if (!__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key))
4721
+ return null;
4722
+ return __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").getItem(key);
4723
+ }
4724
+ set(data) {
4725
+ return __awaiter(this, void 0, void 0, function* () {
4726
+ Object.entries(data).forEach(([key, value]) => {
4727
+ this.setSync(key, value.replace(/\\"/g, '"'));
4728
+ });
4729
+ return Promise.resolve({ errorKeys: [] });
4730
+ });
4731
+ }
4732
+ setSync(key, value) {
4733
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
4734
+ key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
4735
+ }
4736
+ __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").setItem(key, value);
4737
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(key);
4738
+ }
4739
+ getInfo() {
4871
4740
  return __awaiter(this, void 0, void 0, function* () {
4872
- yield this.callNative(ACTION.HIDE_KEYBOARD, {});
4741
+ return Promise.resolve(this.getInfoSync());
4873
4742
  });
4874
4743
  }
4875
- /**
4876
- * Open phone
4877
- * @async
4878
- * @function openPhone
4879
- * @category Device
4880
- *
4881
- */
4882
- static openPhone(object) {
4744
+ getInfoSync() {
4745
+ const currentSize = calcLocalStorageSize(__classPrivateFieldGet(this, _LocalResourceStorage_storage, "f"), __classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f"));
4746
+ return {
4747
+ currentSize: _.isNumber(currentSize)
4748
+ ? Number((currentSize / 1024).toFixed(2))
4749
+ : 0,
4750
+ limitSize: Number((STORAGE_LIMIT / 1024).toFixed(2))
4751
+ };
4752
+ }
4753
+ remove(keys) {
4883
4754
  return __awaiter(this, void 0, void 0, function* () {
4884
- yield this.callNative(ACTION.OPEN_PHONE, {
4885
- phoneNum: object.phoneNumber,
4886
- phoneCode: object.phoneNumber
4755
+ keys.forEach((key) => {
4756
+ this.removeSync(key);
4887
4757
  });
4758
+ return Promise.resolve({ errorKeys: [] });
4888
4759
  });
4889
4760
  }
4890
- /**
4891
- * Open SMS
4892
- * @async
4893
- * @function openSMS
4894
- * @category Device
4895
- *
4896
- */
4897
- static openSMS(object) {
4761
+ removeSync(key) {
4762
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
4763
+ key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
4764
+ }
4765
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key)) {
4766
+ __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
4767
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
4768
+ }
4769
+ }
4770
+ clear() {
4898
4771
  return __awaiter(this, void 0, void 0, function* () {
4899
- yield this.callNative(ACTION.OPEN_SMS, {
4900
- content: object.content,
4901
- phoneCode: object.phoneNumber
4902
- });
4772
+ return Promise.resolve(this.clearSync());
4903
4773
  });
4904
4774
  }
4905
- /**
4906
- * Keep screen.
4907
- * @async
4908
- * @function keepScreen
4909
- * @category Device
4910
- *
4911
- */
4912
- static keepScreen(object) {
4913
- return __awaiter(this, void 0, void 0, function* () {
4914
- return yield this.callNative(ACTION.KEEP_SCREEN, {
4915
- data: {
4916
- keep_screen_on: object.keepScreenOn ? 1 : 0
4917
- }
4918
- });
4775
+ clearSync() {
4776
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.forEach((key) => {
4777
+ if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f") && key.indexOf(__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) < 0) {
4778
+ return;
4779
+ }
4780
+ __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
4781
+ __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
4919
4782
  });
4920
4783
  }
4921
- /**
4922
- * Xác thực bằng sinh trắc học
4923
- * @async
4924
- * @function openBioAuthentication
4925
- * @category Authentication
4926
- *
4927
- */
4928
- static openBioAuthentication(object) {
4929
- return __awaiter(this, void 0, void 0, function* () {
4930
- return yield this.callNative(ACTION.PROMPT_AUTHENTICATION, {
4931
- secret_data: object.secretData,
4932
- app_id: this.getZAppId(),
4933
- ui: {
4934
- title: object.ui.title,
4935
- sub_title: object.ui.subTitle,
4936
- negative_text: object.ui.negativeButtonText
4937
- },
4938
- require_fingerprint: object.requireFingerprint ? 1 : 0
4939
- }).then((data) => {
4940
- var _a, _b, _c, _d;
4941
- return {
4942
- code: data === null || data === void 0 ? void 0 : data.error_code,
4943
- message: data === null || data === void 0 ? void 0 : data.error_message,
4944
- data: {
4945
- domain: (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.domain,
4946
- code: (_b = data === null || data === void 0 ? void 0 : data.data) === null || _b === void 0 ? void 0 : _b.error_code,
4947
- message: (_c = data === null || data === void 0 ? void 0 : data.data) === null || _c === void 0 ? void 0 : _c.error_message,
4948
- payToken: (_d = data === null || data === void 0 ? void 0 : data.data) === null || _d === void 0 ? void 0 : _d.pay_token
4949
- }
4950
- };
4784
+ }
4785
+ _LocalResourceStorage_storage = new WeakMap(), _LocalResourceStorage_prefix = new WeakMap(), _LocalResourceStorage_resourceInfo = new WeakMap();
4786
+
4787
+ var wrappers = {};
4788
+ var WrapperFn = function wrapFunction(fn, type, source) {
4789
+ var t = type || 'default';
4790
+ return function () {
4791
+ var callee = t in wrappers ? wrappers[t](fn, source) : fn;
4792
+ return callee.apply(this, arguments);
4793
+ };
4794
+ };
4795
+ WrapperFn.setWrapper = function (fn) {
4796
+ var type = arguments.length <= 1 || arguments[1] === undefined
4797
+ ? 'default'
4798
+ : arguments[1];
4799
+ wrappers[type] = fn;
4800
+ };
4801
+ var ERROR = {
4802
+ error: {
4803
+ code: 1,
4804
+ error_subcode: 1357046,
4805
+ message: 'Received Invalid JSON reply.',
4806
+ type: 'http'
4807
+ }
4808
+ };
4809
+ function safelyParseResponse(rawResponse) {
4810
+ try {
4811
+ return rawResponse === null ? ERROR : JSON.parse(rawResponse);
4812
+ }
4813
+ catch (ex) {
4814
+ return ERROR;
4815
+ }
4816
+ }
4817
+ function createCORSRequest(method, url) {
4818
+ if (!self.XMLHttpRequest) {
4819
+ return null;
4820
+ }
4821
+ var xhr = new XMLHttpRequest();
4822
+ var noop = function noop() { };
4823
+ if ('withCredentials' in xhr) {
4824
+ xhr.open(method, url, true);
4825
+ xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
4826
+ }
4827
+ else {
4828
+ return null;
4829
+ }
4830
+ var wrapper = {
4831
+ send: function send(data) {
4832
+ xhr.send(data);
4833
+ }
4834
+ };
4835
+ var onload = WrapperFn(function () {
4836
+ onload = noop;
4837
+ if ('onload' in wrapper) {
4838
+ wrapper.onload(xhr);
4839
+ }
4840
+ }, 'entry', 'XMLHttpRequest:load');
4841
+ var onerror = WrapperFn(function () {
4842
+ onerror = noop;
4843
+ if ('onerror' in wrapper) {
4844
+ wrapper.onerror(xhr);
4845
+ }
4846
+ }, 'entry', 'XMLHttpRequest:error');
4847
+ xhr.onload = function () {
4848
+ onload();
4849
+ };
4850
+ xhr.onerror = function () {
4851
+ onerror();
4852
+ };
4853
+ xhr.onreadystatechange = function () {
4854
+ if (xhr.readyState == 4) {
4855
+ if (xhr.status == 200) {
4856
+ onload();
4857
+ }
4858
+ else {
4859
+ onerror();
4860
+ }
4861
+ }
4862
+ };
4863
+ return wrapper;
4864
+ }
4865
+ function execute(url, method, params, cb) {
4866
+ params.suppress_http_code = 1;
4867
+ var data = QueryString.encode(params);
4868
+ if (method != 'post') {
4869
+ url = QueryString.appendToUrl(url, data);
4870
+ data = '';
4871
+ }
4872
+ var request = createCORSRequest(method, url);
4873
+ if (!request) {
4874
+ return false;
4875
+ }
4876
+ request.onload = function (xhr) {
4877
+ cb(safelyParseResponse(xhr.responseText));
4878
+ };
4879
+ request.onerror = function (xhr) {
4880
+ if (xhr.responseText) {
4881
+ cb(safelyParseResponse(xhr.responseText));
4882
+ }
4883
+ else {
4884
+ cb({
4885
+ error: {
4886
+ code: 1,
4887
+ error_subcode: 1357045,
4888
+ message: 'unknown error (empty response)',
4889
+ status: xhr.status,
4890
+ type: 'http'
4891
+ }
4892
+ });
4893
+ }
4894
+ };
4895
+ request.send(data);
4896
+ return true;
4897
+ }
4898
+ var CORSRequest = {
4899
+ execute: execute
4900
+ };
4901
+
4902
+ var _ZaloJSBridge_instances, _ZaloJSBridge_cookies, _ZaloJSBridge_actionRuntimeInfo, _ZaloJSBridge_jsCall;
4903
+ class ZaloJSBridge extends eventemitter3 {
4904
+ constructor() {
4905
+ super();
4906
+ _ZaloJSBridge_instances.add(this);
4907
+ this.debug = Debug('zmp:ZaloJSBridge');
4908
+ this.events = ZMPEEmitter.getInstance();
4909
+ this._accessTk = getToken('zacc_session') || 'DEFAULT_ACCESS_TOKEN';
4910
+ this._jsAccessTk = getToken('zlink3rd') || 'DEFAULT_JS_TOKEN';
4911
+ this.results = [];
4912
+ this._userAgent = getUserAgent();
4913
+ this._device = checkPlatform();
4914
+ this.isJumped = false;
4915
+ _ZaloJSBridge_cookies.set(this, null);
4916
+ _ZaloJSBridge_actionRuntimeInfo.set(this, void 0);
4917
+ this.jump = () => {
4918
+ return new Promise((resolve, reject) => {
4919
+ if (!_.isUndefined(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) && !_.isNull(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"))) {
4920
+ resolve(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"));
4921
+ }
4922
+ else {
4923
+ this.callNative(ACTION.JUMP_LOGIN, {})
4924
+ .then((data) => {
4925
+ const cookies = (data && data.cookiesOAuthLogins) || [];
4926
+ const actionPermission = (data && data.actionPermission) || [];
4927
+ Object.entries(actionPermission).forEach((item) => {
4928
+ const key = item[0];
4929
+ const value = item[1] || { perm: 0, decode: 0 };
4930
+ if (!__classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key]) {
4931
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key] = {
4932
+ permission: false,
4933
+ support: false
4934
+ };
4935
+ }
4936
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key].permission = value.perm === 1;
4937
+ });
4938
+ const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
4939
+ if (jsToken) {
4940
+ this.jsAccessTk = jsToken.value;
4941
+ window.ZJSBridge.setJSToken &&
4942
+ window.ZJSBridge.setJSToken(jsToken.value);
4943
+ }
4944
+ __classPrivateFieldSet(this, _ZaloJSBridge_cookies, cookies, "f");
4945
+ this.isJumped = true;
4946
+ resolve(cookies);
4947
+ })
4948
+ .catch((error) => {
4949
+ this.isJumped = false;
4950
+ reject(error);
4951
+ });
4952
+ }
4951
4953
  });
4954
+ };
4955
+ this._jsCallFuncCallbacks = {};
4956
+ __classPrivateFieldSet(this, _ZaloJSBridge_actionRuntimeInfo, {}, "f");
4957
+ this.events.on(Events.AppPaused, () => {
4958
+ if (this.results.length > 0) {
4959
+ let array = this.results;
4960
+ this.results = [];
4961
+ try {
4962
+ this.sendLogData(array);
4963
+ }
4964
+ catch (error) { }
4965
+ }
4952
4966
  });
4967
+ if (this.sendLogTimer) {
4968
+ clearInterval(this.sendLogTimer);
4969
+ }
4970
+ else {
4971
+ this.sendLogTimer = setInterval(() => {
4972
+ if (this.results.length > 0) {
4973
+ let array = this.results;
4974
+ this.results = [];
4975
+ try {
4976
+ this.sendLogData(array);
4977
+ }
4978
+ catch (error) { }
4979
+ }
4980
+ }, 5000);
4981
+ }
4953
4982
  }
4954
- /**
4955
- * 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...)
4956
- * @async
4957
- * @function checkStateBioAuthentication
4958
- * @category Authentication
4959
- *
4960
- * @example
4961
- * api.checkStateAuthen({
4962
- * success: (res) => {},
4963
- * fail: (err) => {}
4964
- * })
4965
- * @param {InputDataType.CallbackType} object
4966
- */
4967
- static checkStateBioAuthentication(object) {
4968
- return __awaiter(this, void 0, void 0, function* () {
4969
- return yield this.callNative(ACTION.PROMPT_AUTHENTICATION_CHECK_STATE, {}).then((data) => {
4983
+ static getInstance() {
4984
+ if (!ZaloJSBridge.instance) {
4985
+ ZaloJSBridge.instance = new ZaloJSBridge();
4986
+ }
4987
+ return ZaloJSBridge.instance;
4988
+ }
4989
+ set accessTk(value) {
4990
+ this._accessTk = value;
4991
+ }
4992
+ set jsAccessTk(value) {
4993
+ this._jsAccessTk = value;
4994
+ }
4995
+ sendLogData(data) {
4996
+ try {
4997
+ const logData = data.map((item) => {
4970
4998
  return {
4971
- bioState: data === null || data === void 0 ? void 0 : data.bio_state
4999
+ action: item.action,
5000
+ error: item.error
4972
5001
  };
4973
5002
  });
4974
- });
5003
+ CORSRequest.execute(APIS.SEND_ACTION_LOG, 'post', {
5004
+ appId: window.APP_ID,
5005
+ data: JSON.stringify(logData)
5006
+ }, (response) => { });
5007
+ window.zmpSentry &&
5008
+ window.zmpSentry.captureMessage('Result from native', {
5009
+ extra: {
5010
+ data: data
5011
+ }
5012
+ });
5013
+ }
5014
+ catch (error) { }
4975
5015
  }
4976
- /**
4977
- * Vibrate.
4978
- * @async
4979
- * @function vibrate
4980
- * @category Device
4981
- *
4982
- */
4983
- static vibrate(object) {
4984
- return __awaiter(this, void 0, void 0, function* () {
4985
- return yield this.callNative(ACTION.INTERACTIVE_VIBRATION, {
4986
- type: VibrateType[object.type],
4987
- vibrate_time: object.milliseconds
5016
+ onJSCall(key, data) {
5017
+ try {
5018
+ this.debug('onJSCall', key, data);
5019
+ const parsedData = parseJSON(data);
5020
+ if (this._jsCallFuncCallbacks[key]) {
5021
+ const callback = this._jsCallFuncCallbacks[key].callback;
5022
+ const timeout = this._jsCallFuncCallbacks[key].timeout;
5023
+ if (!!callback) {
5024
+ try {
5025
+ callback.call(this, parsedData);
5026
+ }
5027
+ catch (error) {
5028
+ console.error('Call callback error', error);
5029
+ }
5030
+ !!timeout && clearTimeout(timeout);
5031
+ this._jsCallFuncCallbacks[key] = null;
5032
+ delete this._jsCallFuncCallbacks[key];
5033
+ }
5034
+ }
5035
+ this.results.push({
5036
+ action: parsedData.action,
5037
+ error: parsedData.error_code,
5038
+ message: parsedData.error_message
4988
5039
  });
4989
- });
5040
+ }
5041
+ catch (e) {
5042
+ console.log('onJSCall', 'error', e);
5043
+ }
4990
5044
  }
4991
- /**
4992
- * Connect Wifi.
4993
- * @async
4994
- * @function connectWifi
4995
- * @category Device
4996
- *
4997
- */
4998
- static connectWifi(object) {
4999
- return __awaiter(this, void 0, void 0, function* () {
5000
- let securityType = 'open';
5001
- if (_.isString(object.password) && object.password.length > 0) {
5002
- securityType = 'wpa_wpa2';
5045
+ onMultiJSCall(key, data) {
5046
+ try {
5047
+ this.debug('onMultiJSCall', key, data);
5048
+ const parsedData = parseJSON(data);
5049
+ if (this._jsCallFuncCallbacks[key]) {
5050
+ const callback = this._jsCallFuncCallbacks[key].callback;
5051
+ const timeout = this._jsCallFuncCallbacks[key].timeout;
5052
+ if (!!callback) {
5053
+ try {
5054
+ callback.call(this, parsedData);
5055
+ }
5056
+ catch (error) {
5057
+ console.error('Call callback error', error);
5058
+ }
5059
+ !!timeout && clearTimeout(timeout);
5060
+ }
5003
5061
  }
5004
- return yield this.callNative(ACTION.MP_JOIN_WIFI, {
5005
- ssid: object.SSID,
5006
- securityType: securityType,
5007
- password: object.password,
5008
- hiddenSsid: object.hiddenSSID
5062
+ this.results.push({
5063
+ action: parsedData.action,
5064
+ error: parsedData.error_code,
5065
+ message: parsedData.error_message
5009
5066
  });
5010
- });
5011
- }
5012
- /**
5013
- * Open App Store.
5014
- * @async
5015
- * @function openAppStore
5016
- * @category Device
5017
- *
5018
- */
5019
- static openAppStore(object) {
5020
- return __awaiter(this, void 0, void 0, function* () {
5021
- return yield this.callNative(ACTION.OPEN_APPSTORE, object);
5022
- });
5067
+ }
5068
+ catch (e) {
5069
+ console.log('onMultiJSCall', 'error', e);
5070
+ }
5023
5071
  }
5024
- }
5025
-
5026
- var _LocalResourceStorage_storage, _LocalResourceStorage_prefix, _LocalResourceStorage_resourceInfo;
5027
- class LocalResourceStorage {
5028
- constructor(prefix) {
5029
- _LocalResourceStorage_storage.set(this, localStorage);
5030
- _LocalResourceStorage_prefix.set(this, void 0);
5031
- _LocalResourceStorage_resourceInfo.set(this, void 0);
5032
- checkPlatform();
5033
- // if (platform.isMobile && platform.isZalo) {
5034
- // Object.defineProperty(window, 'localStorage', {
5035
- // value: null,
5036
- // configurable: true,
5037
- // enumerable: true,
5038
- // writable: false
5039
- // });
5040
- // }
5041
- __classPrivateFieldSet(this, _LocalResourceStorage_resourceInfo, {
5042
- keys: new Set(),
5043
- currentSize: 0,
5044
- limitSize: STORAGE_LIMIT
5045
- }, "f");
5046
- __classPrivateFieldSet(this, _LocalResourceStorage_prefix, prefix, "f");
5047
- this.findAllCurrentDataByApp(prefix);
5072
+ nativeEventHandler(eventId, eventName, eventData) {
5073
+ this.debug(`eventId: ${eventId}, eventName: ${eventName}, eventData: ${eventData}`);
5074
+ const data = stringToData(eventData);
5075
+ this.debug(data);
5076
+ const convertedData = this.handleEventData(eventName, data);
5077
+ this.events.emit(eventName, eventId, convertedData);
5048
5078
  }
5049
- findAllCurrentDataByApp(prefix) {
5079
+ handleEventData(eventName, data) {
5050
5080
  try {
5051
- let _x;
5052
- for (_x in __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f")) {
5053
- if (prefix) {
5054
- const _prefix = _x.split('_')[0];
5055
- if (_prefix !== prefix) {
5056
- continue;
5057
- }
5058
- }
5059
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(_x);
5081
+ switch (eventName) {
5082
+ case Events.OpenApp:
5083
+ const { url } = data;
5084
+ const validUrl = new URL(url);
5085
+ const path = validUrl.pathname.split(`/zapps/${APP_ID}`)[1];
5086
+ return {
5087
+ path: `${path ? path : '/'}${validUrl.search}`
5088
+ };
5089
+ break;
5090
+ default:
5091
+ return data;
5092
+ break;
5060
5093
  }
5061
5094
  }
5062
5095
  catch (error) {
5063
- logger.error(error, 'LocalResourceStorage > findAllCurrentDataByApp');
5096
+ return data;
5064
5097
  }
5065
5098
  }
5066
- get(keys) {
5067
- let res = new Map();
5068
- keys.forEach((key) => {
5069
- res.set(key, this.getSync(key));
5070
- });
5071
- return Promise.resolve(res);
5072
- }
5073
- getSync(key) {
5074
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5075
- key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
5099
+ defaultCallback(data) {
5100
+ if (data !== null && data !== undefined) {
5101
+ data = parseJSON(data);
5076
5102
  }
5077
- if (!__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key))
5078
- return null;
5079
- return __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").getItem(key);
5080
5103
  }
5081
- set(data) {
5082
- return __awaiter(this, void 0, void 0, function* () {
5083
- Object.entries(data).forEach(([key, value]) => {
5084
- this.setSync(key, value.replace(/\\"/g, '"'));
5104
+ callNative(action, data, option) {
5105
+ this.debug(action.name, data);
5106
+ return new Promise((resolve, reject) => {
5107
+ const handleNativeCallback = (cb) => __awaiter(this, void 0, void 0, function* () {
5108
+ var _a, _b, _c, _d, _e, _f, _g, _h;
5109
+ try {
5110
+ if (_.isUndefined(cb) || _.isNull(cb)) {
5111
+ return reject(new Error('Native callback is null'));
5112
+ }
5113
+ if (cb.error_code !== 0) {
5114
+ let error = new AppError(cb.error_code, cb.error_message);
5115
+ const platform = getPlatform();
5116
+ if (action === ACTION.JUMP_LOGIN) {
5117
+ error = new AppError(RESPONSE_CODE.UNKNOWN_ERROR, `Can not get auth code: ${cb.error_message}`);
5118
+ }
5119
+ else if (!this.isJumped && !action.skip_jump) {
5120
+ error = new AppError(RESPONSE.UNAUTHORIZED.code, RESPONSE.UNAUTHORIZED.message);
5121
+ }
5122
+ else if (String(error.message).toLowerCase() === 'permission required!' ||
5123
+ String(error.message).toLowerCase() === 'no permission!') {
5124
+ error = new AppError(RESPONSE.FORBIDDEN.code, RESPONSE.FORBIDDEN.message);
5125
+ }
5126
+ else if (COMMON_NATIVE_ERROR_CODE[platform][cb.error_code]) {
5127
+ error = new AppError(COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].code, COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].message);
5128
+ }
5129
+ 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)]) {
5130
+ let error_message = action.error_list[platform][String(cb.error_code)].map_to.message;
5131
+ 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) {
5132
+ 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}`;
5133
+ }
5134
+ error = new AppError(action.error_list[platform][String(cb.error_code)].map_to.code, error_message);
5135
+ }
5136
+ return reject(error);
5137
+ }
5138
+ if (option === null || option === void 0 ? void 0 : option.successCallback) {
5139
+ const res = yield option.successCallback(cb.data);
5140
+ return resolve(res);
5141
+ }
5142
+ else {
5143
+ resolve(cb.data || {});
5144
+ }
5145
+ }
5146
+ catch (error) {
5147
+ return reject(error);
5148
+ }
5085
5149
  });
5086
- return Promise.resolve({ errorKeys: [] });
5150
+ const isIOS = checkPlatform().isIOS;
5151
+ const isSupportAction = checkIOSSupportAction(action);
5152
+ if (isIOS && !isSupportAction) {
5153
+ const error = new AppError(-5, `Client isn't support this action`);
5154
+ return reject(error);
5155
+ }
5156
+ else if (option === null || option === void 0 ? void 0 : option.delay) {
5157
+ setTimeout(() => {
5158
+ __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);
5159
+ }, option.delay);
5160
+ }
5161
+ else {
5162
+ __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);
5163
+ }
5087
5164
  });
5088
5165
  }
5089
- setSync(key, value) {
5090
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5091
- key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
5166
+ }
5167
+ _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) {
5168
+ try {
5169
+ const actionName = action.name;
5170
+ const key = generateUniqueString(actionName);
5171
+ if (!this._device.isMobile || _.isEmpty(actionName)) {
5172
+ this.onJSCall(key, {
5173
+ error_code: -13,
5174
+ error_message: 'params invalid!',
5175
+ data: {
5176
+ device: this._device.isMobile,
5177
+ jsToken: this._jsAccessTk,
5178
+ access_token: this._accessTk
5179
+ },
5180
+ action: actionName
5181
+ });
5182
+ return false;
5092
5183
  }
5093
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").setItem(key, value);
5094
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.add(key);
5095
- }
5096
- getInfo() {
5097
- return __awaiter(this, void 0, void 0, function* () {
5098
- return Promise.resolve(this.getInfoSync());
5099
- });
5100
- }
5101
- getInfoSync() {
5102
- const currentSize = calcLocalStorageSize(__classPrivateFieldGet(this, _LocalResourceStorage_storage, "f"), __classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f"));
5103
- return {
5104
- currentSize: _.isNumber(currentSize)
5105
- ? Number((currentSize / 1024).toFixed(2))
5106
- : 0,
5107
- limitSize: Number((STORAGE_LIMIT / 1024).toFixed(2))
5184
+ if (options === undefined || options === null) {
5185
+ options = {};
5186
+ }
5187
+ if (!callback) {
5188
+ callback = this.defaultCallback;
5189
+ }
5190
+ const timeoutCallback = {
5191
+ error_code: -14,
5192
+ error_message: 'Request Timeout!',
5193
+ data: {},
5194
+ action: actionName
5108
5195
  };
5109
- }
5110
- remove(keys) {
5111
- return __awaiter(this, void 0, void 0, function* () {
5112
- keys.forEach((key) => {
5113
- this.removeSync(key);
5114
- });
5115
- return Promise.resolve({ errorKeys: [] });
5116
- });
5117
- }
5118
- removeSync(key) {
5119
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) {
5120
- key = `${__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")}_${key}`;
5196
+ this._jsCallFuncCallbacks[key] = {
5197
+ timeout: haveTimeout &&
5198
+ action.have_callback &&
5199
+ setTimeout(() => {
5200
+ this.onJSCall(key, timeoutCallback);
5201
+ }, 8000),
5202
+ callback: callback
5203
+ };
5204
+ try {
5205
+ options = serialize(options);
5206
+ if (isMultiCallback) {
5207
+ if (this._device.isIOS) {
5208
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onMultiJSCall(key));
5209
+ }
5210
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onMultiJSCall('${key}')`);
5211
+ }
5212
+ if (this._device.isIOS) {
5213
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, window.onJSCall(key));
5214
+ }
5215
+ return ZaloJavaScriptInterface.jsCall(this._jsAccessTk, actionName, this._accessTk, options, `window.onJSCall('${key}')`);
5121
5216
  }
5122
- if (__classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.has(key)) {
5123
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
5124
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
5217
+ catch (error) {
5218
+ if (nRetry-- > 0) {
5219
+ setTimeout(() => {
5220
+ __classPrivateFieldGet(this, _ZaloJSBridge_instances, "m", _ZaloJSBridge_jsCall).call(this, action, options, callback, isMultiCallback, nRetry);
5221
+ }, 500);
5222
+ }
5223
+ else {
5224
+ const errorCallback = {
5225
+ error_code: -5,
5226
+ error_message: 'Not ready!',
5227
+ data: {
5228
+ userAgent: this._userAgent,
5229
+ options: options,
5230
+ jsToken: this._jsAccessTk,
5231
+ access_token: this._accessTk
5232
+ },
5233
+ action: actionName,
5234
+ js_error: error
5235
+ };
5236
+ this.onJSCall(key, errorCallback);
5237
+ return false;
5238
+ }
5125
5239
  }
5126
5240
  }
5127
- clear() {
5128
- return __awaiter(this, void 0, void 0, function* () {
5129
- return Promise.resolve(this.clearSync());
5130
- });
5131
- }
5132
- clearSync() {
5133
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.forEach((key) => {
5134
- if (__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f") && key.indexOf(__classPrivateFieldGet(this, _LocalResourceStorage_prefix, "f")) < 0) {
5135
- return;
5136
- }
5137
- __classPrivateFieldGet(this, _LocalResourceStorage_storage, "f").removeItem(key);
5138
- __classPrivateFieldGet(this, _LocalResourceStorage_resourceInfo, "f").keys.delete(key);
5139
- });
5241
+ catch (error) {
5242
+ console.log('jsCall', 'error', error);
5140
5243
  }
5141
- }
5142
- _LocalResourceStorage_storage = new WeakMap(), _LocalResourceStorage_prefix = new WeakMap(), _LocalResourceStorage_resourceInfo = new WeakMap();
5244
+ return false;
5245
+ };
5143
5246
 
5144
- var _NativeResourceStorage_appId, _NativeResourceStorage_resourceInfo;
5145
- class NativeResourceStorage extends ZJSBridgeProvider {
5247
+ var _NativeResourceStorage_appId, _NativeResourceStorage_resourceInfo, _NativeResourceStorage_bridge;
5248
+ class NativeResourceStorage {
5146
5249
  constructor(appId) {
5147
- super();
5148
5250
  _NativeResourceStorage_appId.set(this, void 0);
5149
5251
  _NativeResourceStorage_resourceInfo.set(this, void 0);
5252
+ _NativeResourceStorage_bridge.set(this, void 0);
5150
5253
  __classPrivateFieldSet(this, _NativeResourceStorage_resourceInfo, {
5151
5254
  keys: new Set(),
5152
5255
  currentSize: 0,
5153
5256
  limitSize: STORAGE_LIMIT
5154
5257
  }, "f");
5155
5258
  __classPrivateFieldSet(this, _NativeResourceStorage_appId, appId, "f");
5259
+ __classPrivateFieldSet(this, _NativeResourceStorage_bridge, ZaloJSBridge.getInstance(), "f");
5156
5260
  }
5157
5261
  get(keys) {
5158
5262
  return __awaiter(this, void 0, void 0, function* () {
5159
- return yield this.callNative(ACTION.ZBROWSER_MPDS, {
5263
+ return yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5264
+ .callNative(ACTION.ZBROWSER_MPDS, {
5160
5265
  mpds_action: 'mpds.get',
5161
5266
  mpds_data: {
5162
5267
  keys
@@ -5164,7 +5269,8 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5164
5269
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5165
5270
  }, {
5166
5271
  isMultiCallback: false
5167
- }).then((data) => {
5272
+ })
5273
+ .then((data) => {
5168
5274
  let res = new Map();
5169
5275
  if (data && data.mpds_data && data.mpds_data.map) {
5170
5276
  res = new Map(Object.entries(data.mpds_data.map));
@@ -5175,7 +5281,8 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5175
5281
  }
5176
5282
  set(data) {
5177
5283
  return __awaiter(this, void 0, void 0, function* () {
5178
- const errorKeys = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5284
+ const errorKeys = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5285
+ .callNative(ACTION.ZBROWSER_MPDS, {
5179
5286
  mpds_action: 'mpds.set',
5180
5287
  mpds_data: {
5181
5288
  map: data
@@ -5183,7 +5290,8 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5183
5290
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5184
5291
  }, {
5185
5292
  isMultiCallback: false
5186
- }).then((data) => {
5293
+ })
5294
+ .then((data) => {
5187
5295
  let res = [];
5188
5296
  if (data && data.mpds_data && data.mpds_data.error_keys) {
5189
5297
  res = data.mpds_data.error_keys;
@@ -5195,13 +5303,15 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5195
5303
  }
5196
5304
  getInfo() {
5197
5305
  return __awaiter(this, void 0, void 0, function* () {
5198
- const currentSize = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5306
+ const currentSize = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5307
+ .callNative(ACTION.ZBROWSER_MPDS, {
5199
5308
  mpds_action: 'mpds.get.size',
5200
5309
  mpds_data: {},
5201
5310
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5202
5311
  }, {
5203
5312
  isMultiCallback: false
5204
- }).then((data) => {
5313
+ })
5314
+ .then((data) => {
5205
5315
  let res = 0;
5206
5316
  if (data && data.mpds_data && data.mpds_data.size) {
5207
5317
  res = data.mpds_data.size;
@@ -5216,7 +5326,8 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5216
5326
  }
5217
5327
  remove(keys) {
5218
5328
  return __awaiter(this, void 0, void 0, function* () {
5219
- const errorKeys = yield this.callNative(ACTION.ZBROWSER_MPDS, {
5329
+ const errorKeys = yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f")
5330
+ .callNative(ACTION.ZBROWSER_MPDS, {
5220
5331
  mpds_action: 'mpds.remove.key',
5221
5332
  mpds_data: {
5222
5333
  keys: keys
@@ -5224,7 +5335,8 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5224
5335
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
5225
5336
  }, {
5226
5337
  isMultiCallback: false
5227
- }).then((data) => {
5338
+ })
5339
+ .then((data) => {
5228
5340
  let res = [];
5229
5341
  if (data && data.mpds_data && data.mpds_data.error_keys) {
5230
5342
  res = data.mpds_data.error_keys;
@@ -5236,7 +5348,7 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5236
5348
  }
5237
5349
  clear() {
5238
5350
  return __awaiter(this, void 0, void 0, function* () {
5239
- yield this.callNative(ACTION.ZBROWSER_MPDS, {
5351
+ yield __classPrivateFieldGet(this, _NativeResourceStorage_bridge, "f").callNative(ACTION.ZBROWSER_MPDS, {
5240
5352
  mpds_action: 'mpds.clear.appData',
5241
5353
  mpds_data: {},
5242
5354
  appId: __classPrivateFieldGet(this, _NativeResourceStorage_appId, "f")
@@ -5244,7 +5356,7 @@ class NativeResourceStorage extends ZJSBridgeProvider {
5244
5356
  });
5245
5357
  }
5246
5358
  }
5247
- _NativeResourceStorage_appId = new WeakMap(), _NativeResourceStorage_resourceInfo = new WeakMap();
5359
+ _NativeResourceStorage_appId = new WeakMap(), _NativeResourceStorage_resourceInfo = new WeakMap(), _NativeResourceStorage_bridge = new WeakMap();
5248
5360
 
5249
5361
  var _LocalStorageCreator_appId, _NativeStorageCreator_appId;
5250
5362
  class StorageCreator {
@@ -5496,18 +5608,13 @@ class OpenApi {
5496
5608
  */
5497
5609
  static getPhoneNumber(object) {
5498
5610
  return __awaiter(this, void 0, void 0, function* () {
5499
- return yield this.callNative(ACTION.MP_GET_NUMBER, {}, {
5611
+ return yield this.getJSBridge().callNative(ACTION.MP_GET_NUMBER, {}, {
5500
5612
  isMultiCallback: true,
5501
- callback: (nativeData, error) => {
5502
- if (nativeData.error_code === 0) {
5503
- const res = {
5504
- number: nativeData.data
5505
- };
5506
- return Promise.resolve(res);
5507
- }
5508
- else {
5509
- return Promise.reject(error);
5510
- }
5613
+ successCallback: (data) => {
5614
+ const res = {
5615
+ number: data
5616
+ };
5617
+ return Promise.resolve(res);
5511
5618
  },
5512
5619
  delay: this.isIOS ? 400 : 0
5513
5620
  });
@@ -5526,7 +5633,7 @@ class Window {
5526
5633
  */
5527
5634
  static closeApp(object) {
5528
5635
  return __awaiter(this, void 0, void 0, function* () {
5529
- yield this.callNative(ACTION.WINDOW_CLOSE, {});
5636
+ yield this.getJSBridge().callNative(ACTION.WINDOW_CLOSE, {});
5530
5637
  });
5531
5638
  }
5532
5639
  /**
@@ -5558,7 +5665,7 @@ class Window {
5558
5665
  mpInfo.appName = appInfo.name;
5559
5666
  mpInfo.appAvtUrl = appInfo.logoUrl;
5560
5667
  }
5561
- yield this.callNative(ACTION.OPEN_MP, {
5668
+ yield this.getJSBridge().callNative(ACTION.OPEN_MP, {
5562
5669
  mpUrl: `${MINI_APP_INTERNAL_LINK}/${appId}/${queryParamString.length > 0 ? '?' + queryParamString : ''}`,
5563
5670
  mpInfo: mpInfo
5564
5671
  });
@@ -5574,7 +5681,7 @@ class Window {
5574
5681
  */
5575
5682
  static openWebview(url) {
5576
5683
  return __awaiter(this, void 0, void 0, function* () {
5577
- yield this.callNative(ACTION.OPEN_INAPP, {
5684
+ yield this.getJSBridge().callNative(ACTION.OPEN_INAPP, {
5578
5685
  url: url
5579
5686
  });
5580
5687
  });
@@ -5589,7 +5696,7 @@ class Window {
5589
5696
  */
5590
5697
  static closeLoading(when) {
5591
5698
  return __awaiter(this, void 0, void 0, function* () {
5592
- yield this.callNative(ACTION.MP_CLOSE_LOADINGVIEW, {
5699
+ yield this.getJSBridge().callNative(ACTION.MP_CLOSE_LOADINGVIEW, {
5593
5700
  at: new Date().getTime(),
5594
5701
  when: when,
5595
5702
  url: location.href
@@ -5616,30 +5723,24 @@ class Location {
5616
5723
  */
5617
5724
  static getLocation(object) {
5618
5725
  return __awaiter(this, void 0, void 0, function* () {
5619
- return yield this.callNative(ACTION.GET_LOCATION, {
5726
+ return yield this.getJSBridge().callNative(ACTION.GET_LOCATION, {
5620
5727
  silent_request: false,
5621
5728
  permission_description: 'Cho phép Zalo truy cập vào vị trí của thiết bị này?'
5622
5729
  }, {
5623
5730
  isMultiCallback: true,
5624
5731
  haveTimeout: false,
5625
- callback: (nativeData, error) => {
5626
- if (nativeData.error_code === 0) {
5627
- const data = nativeData.data;
5628
- const res = {
5629
- /** latitude */
5630
- latitude: data.latitude,
5631
- /** longitude */
5632
- longitude: data.longitude,
5633
- /** timestamp */
5634
- timestamp: data.timestamp,
5635
- /** provider */
5636
- provider: data.provider
5637
- };
5638
- return Promise.resolve(res);
5639
- }
5640
- else {
5641
- return Promise.reject(error);
5642
- }
5732
+ successCallback: (data) => {
5733
+ const res = {
5734
+ /** latitude */
5735
+ latitude: data.latitude,
5736
+ /** longitude */
5737
+ longitude: data.longitude,
5738
+ /** timestamp */
5739
+ timestamp: data.timestamp,
5740
+ /** provider */
5741
+ provider: data.provider
5742
+ };
5743
+ return Promise.resolve(res);
5643
5744
  },
5644
5745
  delay: this.isIOS ? 400 : 0
5645
5746
  });
@@ -5655,7 +5756,7 @@ class Location {
5655
5756
  */
5656
5757
  static sendLocation(object) {
5657
5758
  return __awaiter(this, void 0, void 0, function* () {
5658
- yield this.callNative(ACTION.QUERY_LOCATION_HIDE, {
5759
+ yield this.getJSBridge().callNative(ACTION.QUERY_LOCATION_HIDE, {
5659
5760
  title: object.title,
5660
5761
  touserid: object.toUserId,
5661
5762
  zapp: this.getZAppId()
@@ -5675,17 +5776,12 @@ class Media {
5675
5776
  */
5676
5777
  static requestCameraPermission(object) {
5677
5778
  return __awaiter(this, void 0, void 0, function* () {
5678
- return yield this.callNative(ACTION.REQUEST_PERMISSION_CAMERA, {}, {
5679
- callback: (nativeData, error) => {
5680
- if (nativeData.error_code === -2 || nativeData.error_code >= 0) {
5681
- return Promise.resolve({
5682
- userAllow: nativeData.error_code === -2 ? false : true,
5683
- message: nativeData.error_message
5684
- });
5685
- }
5686
- else {
5687
- return Promise.reject(error);
5688
- }
5779
+ return yield this.getJSBridge().callNative(ACTION.REQUEST_PERMISSION_CAMERA, {}, {
5780
+ successCallback: () => {
5781
+ return Promise.resolve({
5782
+ userAllow: true,
5783
+ message: 'User Allow'
5784
+ });
5689
5785
  }
5690
5786
  });
5691
5787
  });
@@ -5711,7 +5807,7 @@ class Media {
5711
5807
  imageUrl: object.imageUrl
5712
5808
  };
5713
5809
  }
5714
- return yield this.callNative(ACTION.SAVE_IMAGE_GALLERY, Object.assign({}, data));
5810
+ return yield this.getJSBridge().callNative(ACTION.SAVE_IMAGE_GALLERY, Object.assign({}, data));
5715
5811
  });
5716
5812
  }
5717
5813
  }
@@ -5726,7 +5822,7 @@ class Zalo {
5726
5822
  */
5727
5823
  static viewOAQr(object) {
5728
5824
  return __awaiter(this, void 0, void 0, function* () {
5729
- yield this.callNative(ACTION.VIEW_MYQR, {
5825
+ yield this.getJSBridge().callNative(ACTION.VIEW_MYQR, {
5730
5826
  dpn: object.displayName,
5731
5827
  uid: object.id,
5732
5828
  zapp: this.getZAppId()
@@ -5745,7 +5841,7 @@ class Zalo {
5745
5841
  */
5746
5842
  static openProfile(object) {
5747
5843
  return __awaiter(this, void 0, void 0, function* () {
5748
- return yield this.callNative(ACTION.OPEN_PROFILE, {
5844
+ return yield this.getJSBridge().callNative(ACTION.OPEN_PROFILE, {
5749
5845
  uId: object.id,
5750
5846
  type: ProfileType[object.type],
5751
5847
  zapp: this.getZAppId(),
@@ -5763,9 +5859,10 @@ class Zalo {
5763
5859
  */
5764
5860
  static openChat(object) {
5765
5861
  return __awaiter(this, void 0, void 0, function* () {
5766
- return yield this.callNative(ACTION.OPEN_CHAT, {
5862
+ return yield this.getJSBridge().callNative(ACTION.OPEN_CHAT, {
5767
5863
  uId: object.id,
5768
5864
  type: ChatType[object.type],
5865
+ msg: object.message || '',
5769
5866
  zapp: this.getZAppId(),
5770
5867
  sourceId: object.sourceId,
5771
5868
  sourceIndex: object.sourceIndex
@@ -5804,7 +5901,9 @@ class Zalo {
5804
5901
  };
5805
5902
  break;
5806
5903
  }
5807
- return yield this.callNative(ACTION.OPEN_POSTFEED, Object.assign(Object.assign({ type: PostFeedType[object.type] }, reqData), { zapp: this.getZAppId() })).then((res) => {
5904
+ return yield this.getJSBridge()
5905
+ .callNative(ACTION.OPEN_POSTFEED, Object.assign(Object.assign({ type: PostFeedType[object.type] }, reqData), { zapp: this.getZAppId() }))
5906
+ .then((res) => {
5808
5907
  return {
5809
5908
  status: res.status,
5810
5909
  shareType: res.share_type,
@@ -5823,7 +5922,7 @@ class Zalo {
5823
5922
  */
5824
5923
  static followOA(object) {
5825
5924
  return __awaiter(this, void 0, void 0, function* () {
5826
- yield this.callNative(ACTION.FOLLOW_OA, {
5925
+ yield this.getJSBridge().callNative(ACTION.FOLLOW_OA, {
5827
5926
  uid: object.id,
5828
5927
  showDialogConfirm: true,
5829
5928
  zapp: this.getZAppId()
@@ -5842,7 +5941,7 @@ class Zalo {
5842
5941
  */
5843
5942
  static unfollowOA(object) {
5844
5943
  return __awaiter(this, void 0, void 0, function* () {
5845
- yield this.callNative(ACTION.UNFOLLOW_OA, {
5944
+ yield this.getJSBridge().callNative(ACTION.UNFOLLOW_OA, {
5846
5945
  uid: object.id,
5847
5946
  zapp: this.getZAppId()
5848
5947
  }, {
@@ -5864,7 +5963,8 @@ class Zalo {
5864
5963
  switch (object.type) {
5865
5964
  case 'image':
5866
5965
  let photoUrls = [];
5867
- if (Array.isArray(object.data.imageUrls) && object.data.imageUrls.length > 0) {
5966
+ if (Array.isArray(object.data.imageUrls) &&
5967
+ object.data.imageUrls.length > 0) {
5868
5968
  photoUrls = object.data.imageUrls;
5869
5969
  }
5870
5970
  else {
@@ -5931,9 +6031,11 @@ class Zalo {
5931
6031
  object.type = 'link';
5932
6032
  }
5933
6033
  }
5934
- return yield this.callNative(ACTION.OPEN_SHARESHEET, Object.assign(Object.assign({ type: ShareSheetType[object.type] }, reqData), { zapp: this.getZAppId() }), {
6034
+ return yield this.getJSBridge()
6035
+ .callNative(ACTION.OPEN_SHARESHEET, Object.assign(Object.assign({ type: ShareSheetType[object.type] }, reqData), { zapp: this.getZAppId() }), {
5935
6036
  haveTimeout: false
5936
- }).then((res) => {
6037
+ })
6038
+ .then((res) => {
5937
6039
  return {
5938
6040
  status: res.status,
5939
6041
  shareType: res.share_type,
@@ -5952,7 +6054,7 @@ class Zalo {
5952
6054
  */
5953
6055
  static createShortcut(url, title, icon) {
5954
6056
  return __awaiter(this, void 0, void 0, function* () {
5955
- return yield this.callNative(ACTION.CREATE_SHORTCUT, {
6057
+ return yield this.getJSBridge().callNative(ACTION.CREATE_SHORTCUT, {
5956
6058
  url: url,
5957
6059
  title: title,
5958
6060
  iconUrl: icon
@@ -5969,15 +6071,14 @@ class Zalo {
5969
6071
  */
5970
6072
  static openProfilePicker(maxProfile) {
5971
6073
  return __awaiter(this, void 0, void 0, function* () {
5972
- return yield this.callNative(ACTION.MP_OPEN_PROFILE_PICKER, {
6074
+ return yield this.getJSBridge().callNative(ACTION.MP_OPEN_PROFILE_PICKER, {
5973
6075
  maxProfile: maxProfile
5974
6076
  }, {
5975
6077
  isMultiCallback: true,
5976
- callback: (nativeData, error) => {
5977
- if (nativeData.error_code === 0 && Array.isArray(nativeData.data)) {
5978
- return Promise.resolve(nativeData.data.map((item) => item.id));
6078
+ successCallback: (data) => {
6079
+ if (Array.isArray(data)) {
6080
+ return Promise.resolve(data.map((item) => item.id));
5979
6081
  }
5980
- return Promise.reject(error);
5981
6082
  }
5982
6083
  });
5983
6084
  });
@@ -5992,15 +6093,15 @@ class Zalo {
5992
6093
  */
5993
6094
  static getActionsSupported(object) {
5994
6095
  return __awaiter(this, void 0, void 0, function* () {
5995
- return yield this.callNative(ACTION.GET_SUPPORTED_ACTIONS, {}, {
6096
+ return yield this.getJSBridge().callNative(ACTION.GET_SUPPORTED_ACTIONS, {}, {
5996
6097
  isMultiCallback: false,
5997
- callback: (nativeData, error) => {
6098
+ successCallback: (data) => {
5998
6099
  const platform = getPlatform();
5999
- if (Array.isArray(nativeData.actions) &&
6000
- nativeData.actions.length > 0) {
6100
+ if (Array.isArray(data.actions) &&
6101
+ data.actions.length > 0) {
6001
6102
  const skipJumpActions = Object.keys(ACTION).filter((item) => ACTION[item].skip_jump);
6002
6103
  const res = {
6003
- actions: [...nativeData.actions, ...skipJumpActions]
6104
+ actions: [...data.actions, ...skipJumpActions]
6004
6105
  };
6005
6106
  return Promise.resolve(res);
6006
6107
  }
@@ -6010,7 +6111,6 @@ class Zalo {
6010
6111
  };
6011
6112
  return Promise.resolve(res);
6012
6113
  }
6013
- return Promise.reject(error);
6014
6114
  }
6015
6115
  });
6016
6116
  });
@@ -6034,7 +6134,7 @@ class Zalo {
6034
6134
  enable: 1,
6035
6135
  aspect_ratio: '1:1'
6036
6136
  };
6037
- return yield this.callNative(ACTION.PICK_MEDIA, {
6137
+ return yield this.getJSBridge().callNative(ACTION.PICK_MEDIA, {
6038
6138
  media_type: MediaPickerType[type],
6039
6139
  edit_view: Object.assign(Object.assign({}, defaultEditView), editView),
6040
6140
  silent_request: silentRequest,
@@ -6042,15 +6142,11 @@ class Zalo {
6042
6142
  max_select_items: maxSelectItem
6043
6143
  }, {
6044
6144
  isMultiCallback: true,
6045
- callback: (nativeData, error) => {
6046
- var _a;
6047
- if (nativeData.error_code === 0) {
6048
- const res = {
6049
- data: (_a = nativeData.data) === null || _a === void 0 ? void 0 : _a.result_content
6050
- };
6051
- return Promise.resolve(res);
6052
- }
6053
- return Promise.reject(error);
6145
+ successCallback: (data) => {
6146
+ const res = {
6147
+ data: data === null || data === void 0 ? void 0 : data.result_content
6148
+ };
6149
+ return Promise.resolve(res);
6054
6150
  }
6055
6151
  });
6056
6152
  });
@@ -6065,7 +6161,7 @@ class Zalo {
6065
6161
  */
6066
6162
  static openOutApp(url) {
6067
6163
  return __awaiter(this, void 0, void 0, function* () {
6068
- return yield this.callNative(ACTION.OPEN_OUTAPP, {
6164
+ return yield this.getJSBridge().callNative(ACTION.OPEN_OUTAPP, {
6069
6165
  url: url
6070
6166
  });
6071
6167
  });
@@ -6104,7 +6200,7 @@ class Routing {
6104
6200
  */
6105
6201
  static sendDataToPreviousMiniApp(object) {
6106
6202
  return __awaiter(this, void 0, void 0, function* () {
6107
- return yield this.callNative(ACTION.WEBVIEW_SET_RESULT, {
6203
+ return yield this.getJSBridge().callNative(ACTION.WEBVIEW_SET_RESULT, {
6108
6204
  result: stringifyData(object.data)
6109
6205
  });
6110
6206
  });
@@ -6129,11 +6225,10 @@ class Routing {
6129
6225
  }
6130
6226
  }
6131
6227
 
6132
- 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;
6133
- class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6228
+ 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;
6229
+ class ZaloMiniProgramSDKService {
6134
6230
  constructor() {
6135
6231
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
6136
- super();
6137
6232
  _ZaloMiniProgramSDKService_zAppId.set(this, ZAPP_ID);
6138
6233
  _ZaloMiniProgramSDKService_appId.set(this, APP_ID);
6139
6234
  _ZaloMiniProgramSDKService_appConfig.set(this, APP_CONFIG);
@@ -6146,9 +6241,10 @@ class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6146
6241
  getToken: 0
6147
6242
  }
6148
6243
  });
6244
+ _ZaloMiniProgramSDKService_bridge.set(this, void 0);
6149
6245
  _ZaloMiniProgramSDKService_prevGetTokenTimestamp.set(this, void 0);
6150
6246
  _ZaloMiniProgramSDKService_tokenExpiresIn.set(this, void 0);
6151
- _ZaloMiniProgramSDKService_cookies.set(this, null);
6247
+ _ZaloMiniProgramSDKService_deviceId.set(this, void 0);
6152
6248
  this.events = ZMPEEmitter.getInstance();
6153
6249
  this.isIOS = checkPlatform().isIOS;
6154
6250
  _ZaloMiniProgramSDKService_actionBarConfig.set(this, void 0);
@@ -6158,31 +6254,6 @@ class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6158
6254
  this.setActionBarConfig = (setState) => {
6159
6255
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_actionBarConfig, setState(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_actionBarConfig, "f")), "f");
6160
6256
  };
6161
- _ZaloMiniProgramSDKService_callJump.set(this, () => {
6162
- return new Promise((resolve, reject) => {
6163
- if (!_.isUndefined(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f")) && !_.isNull(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f"))) {
6164
- resolve(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_cookies, "f"));
6165
- }
6166
- else {
6167
- this.callNative(ACTION.JUMP_LOGIN, {})
6168
- .then((data) => {
6169
- const cookies = (data && data.cookiesOAuthLogins) || [];
6170
- const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
6171
- if (jsToken) {
6172
- this.setJSToken(jsToken.value);
6173
- window.ZJSBridge.setJSToken &&
6174
- window.ZJSBridge.setJSToken(jsToken.value);
6175
- }
6176
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_cookies, cookies, "f");
6177
- resolve(cookies);
6178
- })
6179
- .catch((error) => {
6180
- reject(error);
6181
- });
6182
- }
6183
- });
6184
- });
6185
- _ZaloMiniProgramSDKService_setNavigationBarRightButton.set(this, NavigationBar.setNavigationBarRightButton);
6186
6257
  this.getVersion = Basics.getVersion;
6187
6258
  this.getSystemInfo = Basics.getSystemInfo;
6188
6259
  this.setNavigationBarTitle = NavigationBar.setNavigationBarTitle;
@@ -6252,6 +6323,8 @@ class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6252
6323
  this.isShowNavBar = true;
6253
6324
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, 0, "f");
6254
6325
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, 0, "f");
6326
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_deviceId, '', "f");
6327
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_bridge, ZaloJSBridge.getInstance(), "f");
6255
6328
  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' ||
6256
6329
  ((_d = (_c = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_appConfig, "f")) === null || _c === void 0 ? void 0 : _c.app) === null || _d === void 0 ? void 0 : _d.leftButton) === 'both'
6257
6330
  ? ACTION_LEFT_BUTTON_TYPE.SHOW_HOME
@@ -6295,9 +6368,19 @@ class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6295
6368
  getZAppId() {
6296
6369
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zAppId, "f");
6297
6370
  }
6371
+ getDeviceId() {
6372
+ return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_deviceId, "f");
6373
+ }
6374
+ getJSBridge() {
6375
+ return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f");
6376
+ }
6298
6377
  login(object) {
6299
6378
  return __awaiter(this, void 0, void 0, function* () {
6300
- const cookies = yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_callJump, "f").call(this);
6379
+ const cookies = yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").jump();
6380
+ const deviceId = cookies.find((cookie) => cookie.name === COOKIE_NAME.DEVICE_ID);
6381
+ if (deviceId) {
6382
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_deviceId, deviceId.value, "f");
6383
+ }
6301
6384
  const zOAuthCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH);
6302
6385
  const zOAuthVrfCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH_VRF);
6303
6386
  if (!_.isUndefined(zOAuthCookie) &&
@@ -6314,23 +6397,23 @@ class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6314
6397
  yield this.loginZaloV3();
6315
6398
  }
6316
6399
  if (!__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f")) {
6317
- throw apiResponse.error.loginFailed();
6400
+ throw apiResponse.error.loginFailed('Invalid authorization code');
6318
6401
  }
6319
6402
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
6320
6403
  }
6321
- throw apiResponse.error.loginFailed();
6404
+ throw apiResponse.error.loginFailed('Zalo app has not been activated');
6322
6405
  });
6323
6406
  }
6324
6407
  loginZaloV3() {
6325
6408
  return __awaiter(this, void 0, void 0, function* () {
6326
- 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* () {
6409
+ 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* () {
6327
6410
  let resData = yield response.json();
6328
6411
  if (resData.access_token) {
6329
6412
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_accessToken, resData.access_token, "f");
6330
6413
  const expiresIn = parseInt(resData.expires_in) * 1000;
6331
6414
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, expiresIn, "f");
6332
6415
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, new Date().getTime(), "f");
6333
- this.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6416
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '';
6334
6417
  window.ZJSBridge.setZAccSession &&
6335
6418
  window.ZJSBridge.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6336
6419
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
@@ -6367,7 +6450,7 @@ class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6367
6450
  const expiresIn = parseInt(resData.expires_in) * 1000;
6368
6451
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, expiresIn, "f");
6369
6452
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, new Date().getTime(), "f");
6370
- this.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6453
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '';
6371
6454
  window.ZJSBridge.setZAccSession &&
6372
6455
  window.ZJSBridge.setZAccSession(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") || '');
6373
6456
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
@@ -6388,7 +6471,7 @@ class ZaloMiniProgramSDKService extends ZJSBridgeProvider {
6388
6471
  });
6389
6472
  }
6390
6473
  }
6391
- _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();
6474
+ _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();
6392
6475
 
6393
6476
  var _MockSDKService_appId, _MockSDKService_appConfig, _MockSDKService_zOAuth, _MockSDKService_accessToken, _MockSDKService_cache, _MockSDKService_loggedId;
6394
6477
  class MockSDKService {
@@ -6409,6 +6492,9 @@ class MockSDKService {
6409
6492
  this.getAppId = () => {
6410
6493
  return __classPrivateFieldGet(this, _MockSDKService_appId, "f");
6411
6494
  };
6495
+ this.getDeviceId = () => {
6496
+ return '';
6497
+ };
6412
6498
  this.login = () => {
6413
6499
  __classPrivateFieldSet(this, _MockSDKService_loggedId, true, "f");
6414
6500
  return Promise.resolve(__classPrivateFieldGet(this, _MockSDKService_zOAuth, "f"));
@@ -8119,90 +8205,175 @@ function getFnParamNames(fn) {
8119
8205
  .replace(/\s/gi, '')
8120
8206
  .split(',');
8121
8207
  }
8122
- const validate = (target, propertyName, descriptor) => {
8123
- const method = descriptor.value;
8124
- const argsName = getFnParamNames(method);
8125
- descriptor.value = function () {
8126
- const requiredParameters = Reflect.getOwnMetadata(requiredMetadataKey, target, propertyName);
8127
- const checkTypeParameters = Reflect.getOwnMetadata(checkTypeMetadataKey, target, propertyName);
8128
- if (checkTypeParameters) {
8129
- checkTypeParameters.forEach((parameter) => {
8130
- const { parameterIndex, type, properties, defaultValue } = parameter;
8131
- let argument = arguments[parameterIndex];
8132
- let argumentName = argsName[parameterIndex];
8133
- const parameterType = typeof argument;
8134
- if (!_.isUndefined(argument)) {
8135
- if (!isType(argument, type)) {
8136
- throw apiResponse.error.wrongTypeParam(argumentName, type, Array.isArray(argument)
8137
- ? 'array'
8138
- : argument === null
8139
- ? 'null'
8140
- : parameterType);
8208
+ /**
8209
+ * Copies all metadata from one object to another.
8210
+ * Useful for overwriting function definition in
8211
+ * decorators while keeping all previously
8212
+ * attached metadata
8213
+ *
8214
+ * @param from object to copy metadata from
8215
+ * @param to object to copy metadata to
8216
+ */
8217
+ function copyMetadata(from, to) {
8218
+ const metadataKeys = Reflect.getMetadataKeys(from);
8219
+ metadataKeys.map((key) => {
8220
+ const value = Reflect.getMetadata(key, from);
8221
+ Reflect.defineMetadata(key, value, to);
8222
+ });
8223
+ }
8224
+ /**
8225
+ * Apply the given decorator to all class methods
8226
+ *
8227
+ * @param decorator Method decorator to apply to all methods of a class
8228
+ * @param {string[]} options.exclude array of method names that won't be decorated
8229
+ * @param {boolean} options.deep if true, also decorates methods of the extended classes (recusrively)
8230
+ */
8231
+ const DecorateAll = (decorator, options = {}) => {
8232
+ return (target) => {
8233
+ var _a;
8234
+ let descriptors = Object.getOwnPropertyDescriptors(target.prototype);
8235
+ if (options.deep) {
8236
+ let base = Object.getPrototypeOf(target);
8237
+ while (base.prototype) {
8238
+ const baseDescriptors = Object.getOwnPropertyDescriptors(base.prototype);
8239
+ descriptors = Object.assign(Object.assign({}, baseDescriptors), descriptors);
8240
+ base = Object.getPrototypeOf(base);
8241
+ }
8242
+ }
8243
+ for (const [propName, descriptor] of Object.entries(descriptors)) {
8244
+ const isMethod = typeof descriptor.value == 'function' && propName != 'constructor';
8245
+ if ((_a = options.exclude) === null || _a === void 0 ? void 0 : _a.includes(propName))
8246
+ continue;
8247
+ if (options.excludePrefix && propName.startsWith(options.excludePrefix))
8248
+ continue;
8249
+ if (!isMethod)
8250
+ continue;
8251
+ const originalMethod = descriptor.value;
8252
+ decorator(target, propName, descriptor);
8253
+ if (originalMethod != descriptor.value) {
8254
+ copyMetadata(originalMethod, descriptor.value);
8255
+ }
8256
+ Object.defineProperty(target.prototype, propName, descriptor);
8257
+ }
8258
+ };
8259
+ };
8260
+ const centralizedFunctionHandler = (target, propertyName, descriptor) => {
8261
+ const fn = descriptor.value;
8262
+ const argsName = getFnParamNames(fn);
8263
+ descriptor.value = function (...args) {
8264
+ try {
8265
+ // begin validation
8266
+ const requiredParameters = Reflect.getOwnMetadata(requiredMetadataKey, target.prototype, propertyName);
8267
+ const checkTypeParameters = Reflect.getOwnMetadata(checkTypeMetadataKey, target.prototype, propertyName);
8268
+ if (checkTypeParameters) {
8269
+ checkTypeParameters.forEach((parameter) => {
8270
+ const { parameterIndex, type, properties, defaultValue } = parameter;
8271
+ let argument = args[parameterIndex];
8272
+ let argumentName = argsName[parameterIndex];
8273
+ const parameterType = typeof argument;
8274
+ if (!_.isUndefined(argument)) {
8275
+ if (!isType(argument, type)) {
8276
+ throw apiResponse.error.wrongTypeParam(argumentName, type, Array.isArray(argument)
8277
+ ? 'array'
8278
+ : argument === null
8279
+ ? 'null'
8280
+ : parameterType);
8281
+ }
8282
+ if (type === 'object') {
8283
+ Object.entries(properties).forEach(([propKey, propType]) => {
8284
+ const key = propKey.split('?')[0];
8285
+ const propValue = _.get(argument, key);
8286
+ if (!_.isUndefined(propValue) && !_.isNull(propValue)) {
8287
+ if (_.isFunction(propType)) {
8288
+ const res = propType(propValue);
8289
+ if (res && res.error) {
8290
+ throw apiResponse.error.wrongTypeParam(`${argumentName}.${key}`, res.errorMessage, typeof propValue);
8291
+ }
8292
+ }
8293
+ }
8294
+ else if (!propKey.includes('?')) {
8295
+ throw apiResponse.error.missingParam(propKey);
8296
+ }
8297
+ else if (!_.get(argument, key.split('.')[0]) &&
8298
+ defaultValue &&
8299
+ !_.isUndefined(_.get(defaultValue, key))) {
8300
+ _.set(args[parameterIndex], key, _.get(defaultValue, key));
8301
+ }
8302
+ });
8303
+ }
8304
+ }
8305
+ });
8306
+ }
8307
+ if (requiredParameters) {
8308
+ requiredParameters.forEach((parameter) => {
8309
+ const { parameterIndex, option, fields } = parameter;
8310
+ const argument = args[parameterIndex];
8311
+ const condition = option === null || option === void 0 ? void 0 : option.if;
8312
+ const defaultValue = option === null || option === void 0 ? void 0 : option.defaultValue;
8313
+ let isMeetCondition = true;
8314
+ if (condition) {
8315
+ isMeetCondition = Object.keys(condition).every((key) => _.get(argument, key) === condition[key]);
8141
8316
  }
8142
- if (type === 'object') {
8143
- Object.entries(properties).forEach(([propKey, propType]) => {
8144
- const key = propKey.split('?')[0];
8145
- const propValue = _.get(argument, key);
8146
- if (!_.isUndefined(propValue) && !_.isNull(propValue)) {
8147
- if (_.isFunction(propType)) {
8148
- const res = propType(propValue);
8149
- if (res && res.error) {
8150
- throw apiResponse.error.wrongTypeParam(`${argumentName}.${key}`, res.errorMessage, typeof propValue);
8317
+ if (isMeetCondition) {
8318
+ fields.forEach((item) => {
8319
+ const isInValidField = (field) => {
8320
+ let isInValid = false;
8321
+ if (_.isEmpty(_.get(argument, field))) {
8322
+ if (!_.isUndefined(_.get(defaultValue, field))) {
8323
+ _.set(args[parameterIndex], field, _.get(defaultValue, field));
8151
8324
  }
8325
+ isInValid = true;
8152
8326
  }
8327
+ return isInValid;
8328
+ };
8329
+ if (Array.isArray(item) &&
8330
+ item.length > 0 &&
8331
+ item.every(isInValidField)) {
8332
+ throw apiResponse.error.missingParam(item.join(' or '));
8153
8333
  }
8154
- else if (!propKey.includes('?')) {
8155
- throw apiResponse.error.missingParam(propKey);
8156
- }
8157
- else if (_.isObject(_.get(argument, key.split('.')[0])) &&
8158
- defaultValue &&
8159
- !_.isUndefined(_.get(defaultValue, key))) {
8160
- _.set(arguments[parameterIndex], key, _.get(defaultValue, key));
8334
+ else if (_.isString(item) && isInValidField(item)) {
8335
+ throw apiResponse.error.missingParam(item);
8161
8336
  }
8162
8337
  });
8163
8338
  }
8164
- }
8165
- });
8166
- }
8167
- if (requiredParameters) {
8168
- requiredParameters.forEach((parameter) => {
8169
- const { parameterIndex, option, fields } = parameter;
8170
- const argument = arguments[parameterIndex];
8171
- const condition = option === null || option === void 0 ? void 0 : option.if;
8172
- const defaultValue = option === null || option === void 0 ? void 0 : option.defaultValue;
8173
- let isMeetCondition = true;
8174
- if (condition) {
8175
- isMeetCondition = Object.keys(condition).every((key) => _.get(argument, key) === condition[key]);
8176
- }
8177
- if (isMeetCondition) {
8178
- fields.forEach((item) => {
8179
- const isInValidField = (field) => {
8180
- let isInValid = false;
8181
- if (_.isEmpty(_.get(argument, field))) {
8182
- if (!_.isUndefined(_.get(defaultValue, field))) {
8183
- _.set(arguments[parameterIndex], field, _.get(defaultValue, field));
8184
- }
8185
- isInValid = true;
8186
- }
8187
- return isInValid;
8188
- };
8189
- if (Array.isArray(item) && item.length > 0 && item.every(isInValidField)) {
8190
- throw apiResponse.error.missingParam(item.join(' or '));
8339
+ });
8340
+ }
8341
+ // end validation
8342
+ const res = fn.call(this, ...args);
8343
+ if (_.isPromise(res)) {
8344
+ const { success, fail } = Array.isArray(args) && args.length > 0 && args[0];
8345
+ return new Promise((resolve, reject) => {
8346
+ res
8347
+ .then((data) => {
8348
+ if (!_.isNull(success) && _.isFunction(success)) {
8349
+ success.call(null, data, this);
8350
+ }
8351
+ else {
8352
+ resolve(res);
8353
+ }
8354
+ })
8355
+ .catch((error) => {
8356
+ const errorParsed = errorHandler(error, propertyName);
8357
+ if (!_.isNull(fail) && _.isFunction(fail)) {
8358
+ fail.call(null, errorParsed, this);
8191
8359
  }
8192
- else if (_.isString(item) && isInValidField(item)) {
8193
- throw apiResponse.error.missingParam(item);
8360
+ else {
8361
+ reject(errorParsed);
8194
8362
  }
8195
8363
  });
8196
- }
8197
- });
8364
+ });
8365
+ }
8366
+ return res;
8367
+ }
8368
+ catch (error) {
8369
+ throw errorHandler(error, propertyName);
8198
8370
  }
8199
- return method.apply(this, arguments);
8200
8371
  };
8201
8372
  return descriptor;
8202
8373
  };
8203
8374
 
8204
8375
  var _SDKCreator_sdkService;
8205
- class SDKCreator {
8376
+ let SDKCreator = class SDKCreator {
8206
8377
  constructor() {
8207
8378
  this.events = ZMPEEmitter.getInstance();
8208
8379
  _SDKCreator_sdkService.set(this, void 0);
@@ -8263,7 +8434,7 @@ class SDKCreator {
8263
8434
  }
8264
8435
  setNavigationBarTitle(object) {
8265
8436
  return __awaiter(this, void 0, void 0, function* () {
8266
- return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarTitle(object);
8437
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarTitle(object);
8267
8438
  });
8268
8439
  }
8269
8440
  setNavigationBarColor(object) {
@@ -8278,7 +8449,7 @@ class SDKCreator {
8278
8449
  }
8279
8450
  setNavigationBarLeftButton(object) {
8280
8451
  return __awaiter(this, void 0, void 0, function* () {
8281
- return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(object);
8452
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(object.type);
8282
8453
  });
8283
8454
  }
8284
8455
  setDeviceOrientation(object) {
@@ -8533,6 +8704,7 @@ class SDKCreator {
8533
8704
  }
8534
8705
  vibrate(object) {
8535
8706
  return __awaiter(this, void 0, void 0, function* () {
8707
+ console.log(object);
8536
8708
  yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").vibrate(object);
8537
8709
  });
8538
8710
  }
@@ -8677,33 +8849,25 @@ class SDKCreator {
8677
8849
  return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").openOutApp(appStoreURL);
8678
8850
  });
8679
8851
  }
8680
- }
8852
+ onConfirmToExit(callback) {
8853
+ this.events.on(Events.AppClose, callback, '{"handle_h5": 1}');
8854
+ __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(undefined, 2);
8855
+ }
8856
+ offConfirmToExit() {
8857
+ this.events.off(Events.AppClose);
8858
+ __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(undefined, 0);
8859
+ }
8860
+ getDeviceId() {
8861
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceId();
8862
+ }
8863
+ };
8681
8864
  _SDKCreator_sdkService = new WeakMap();
8682
8865
  __decorate([
8683
- handleError
8684
- ], SDKCreator.prototype, "login", null);
8685
- __decorate([
8686
- handleErrorSync
8687
- ], SDKCreator.prototype, "getLoginStatus", null);
8688
- __decorate([
8689
- handleError
8690
- ], SDKCreator.prototype, "getAccessToken", null);
8691
- __decorate([
8692
- handleErrorSync
8693
- ], SDKCreator.prototype, "getVersion", null);
8694
- __decorate([
8695
- handleErrorSync
8696
- ], SDKCreator.prototype, "getSystemInfo", null);
8697
- __decorate([
8698
- handleError,
8699
- validate,
8700
8866
  __param(0, checkType('object', {
8701
8867
  title: checkData('string')
8702
8868
  }))
8703
8869
  ], SDKCreator.prototype, "setNavigationBarTitle", null);
8704
8870
  __decorate([
8705
- handleError,
8706
- validate,
8707
8871
  __param(0, checkType('object', {
8708
8872
  color: checkData('string'),
8709
8873
  'textColor?': checkData('string', { values: ['white', 'black'] }),
@@ -8711,57 +8875,37 @@ __decorate([
8711
8875
  }))
8712
8876
  ], SDKCreator.prototype, "setNavigationBarColor", null);
8713
8877
  __decorate([
8714
- handleError,
8715
- validate,
8716
8878
  __param(0, checkType('object', {
8717
8879
  backgroundColor: checkData('string'),
8718
8880
  'textColor?': checkData('string', { values: ['white', 'black'] })
8719
8881
  }))
8720
8882
  ], SDKCreator.prototype, "setBackgroundColor", null);
8721
8883
  __decorate([
8722
- handleError,
8723
- validate,
8724
8884
  __param(0, checkType('object', {
8725
8885
  type: checkData('string', { values: ['none', 'back', 'home', 'both'] })
8726
8886
  }))
8727
8887
  ], SDKCreator.prototype, "setNavigationBarLeftButton", null);
8728
8888
  __decorate([
8729
- handleError,
8730
- validate,
8731
8889
  __param(0, checkType('object', {
8732
8890
  rotate: checkData('string', { values: ['auto', 'portrait', 'landscape'] })
8733
8891
  }))
8734
8892
  ], SDKCreator.prototype, "setDeviceOrientation", null);
8735
8893
  __decorate([
8736
- handleError,
8737
- validate,
8738
8894
  __param(0, checkType('object', {
8739
8895
  data: checkData('object')
8740
8896
  }))
8741
8897
  ], SDKCreator.prototype, "setStorage", null);
8742
8898
  __decorate([
8743
- handleError,
8744
- validate,
8745
8899
  __param(0, checkType('object', {
8746
8900
  keys: checkData('array<string>')
8747
8901
  }))
8748
8902
  ], SDKCreator.prototype, "getStorage", null);
8749
8903
  __decorate([
8750
- handleError
8751
- ], SDKCreator.prototype, "getStorageInfo", null);
8752
- __decorate([
8753
- handleError,
8754
- validate,
8755
8904
  __param(0, checkType('object', {
8756
8905
  keys: checkData('array<string>')
8757
8906
  }))
8758
8907
  ], SDKCreator.prototype, "removeStorage", null);
8759
8908
  __decorate([
8760
- handleError
8761
- ], SDKCreator.prototype, "clearStorage", null);
8762
- __decorate([
8763
- handleError,
8764
- validate,
8765
8909
  __param(0, checkType('object', {
8766
8910
  'avatarType?': checkData('string', {
8767
8911
  values: ['small', 'normal', 'large']
@@ -8769,75 +8913,19 @@ __decorate([
8769
8913
  }))
8770
8914
  ], SDKCreator.prototype, "getUserInfo", null);
8771
8915
  __decorate([
8772
- handleError
8773
- ], SDKCreator.prototype, "getNetworkType", null);
8774
- __decorate([
8775
- handleError
8776
- ], SDKCreator.prototype, "onNetworkStatusChange", null);
8777
- __decorate([
8778
- handleError
8779
- ], SDKCreator.prototype, "startBeaconDiscovery", null);
8780
- __decorate([
8781
- handleError
8782
- ], SDKCreator.prototype, "stopBeaconDiscovery", null);
8783
- __decorate([
8784
- handleError
8785
- ], SDKCreator.prototype, "getBeacons", null);
8786
- __decorate([
8787
- handleError
8788
- ], SDKCreator.prototype, "closeApp", null);
8789
- __decorate([
8790
- handleError
8791
- ], SDKCreator.prototype, "getLocation", null);
8792
- __decorate([
8793
- handleError
8794
- ], SDKCreator.prototype, "stopBluetoothDevicesDiscovery", null);
8795
- __decorate([
8796
- handleError
8797
- ], SDKCreator.prototype, "startBluetoothDevicesDiscovery", null);
8798
- __decorate([
8799
- handleError
8800
- ], SDKCreator.prototype, "openBluetoothAdapter", null);
8801
- __decorate([
8802
- handleError
8803
- ], SDKCreator.prototype, "onBluetoothDeviceFound", null);
8804
- __decorate([
8805
- handleError
8806
- ], SDKCreator.prototype, "onBluetoothAdapterStateChange", null);
8807
- __decorate([
8808
- handleError
8809
- ], SDKCreator.prototype, "getConnectedBluetoothDevices", null);
8810
- __decorate([
8811
- handleError
8812
- ], SDKCreator.prototype, "getBluetoothDevices", null);
8813
- __decorate([
8814
- handleError
8815
- ], SDKCreator.prototype, "getBluetoothAdapterState", null);
8816
- __decorate([
8817
- handleError
8818
- ], SDKCreator.prototype, "closeBluetoothAdapter", null);
8819
- __decorate([
8820
- handleError
8821
- ], SDKCreator.prototype, "scanQRCode", null);
8822
- __decorate([
8823
- handleError,
8824
- validate,
8825
8916
  __param(0, checkType('object', {
8826
8917
  type: checkData('string', { values: ['user', 'oa', 'aliasOA'] }),
8827
8918
  id: checkData('string')
8828
8919
  }))
8829
8920
  ], SDKCreator.prototype, "openProfile", null);
8830
8921
  __decorate([
8831
- handleError,
8832
- validate,
8833
8922
  __param(0, checkType('object', {
8834
8923
  type: checkData('string', { values: ['user', 'oa'] }),
8835
- id: checkData('string')
8924
+ id: checkData('string'),
8925
+ 'message?': checkData('string')
8836
8926
  }))
8837
8927
  ], SDKCreator.prototype, "openChat", null);
8838
8928
  __decorate([
8839
- handleError,
8840
- validate,
8841
8929
  __param(0, required(['data.imageUrl'], { if: { type: 'image' } })),
8842
8930
  __param(0, required(['data.link'], { if: { type: 'link' } })),
8843
8931
  __param(0, required(['data.id'], { if: { type: 'profile' } })),
@@ -8855,23 +8943,17 @@ __decorate([
8855
8943
  }))
8856
8944
  ], SDKCreator.prototype, "openPostFeed", null);
8857
8945
  __decorate([
8858
- handleError,
8859
- validate,
8860
8946
  __param(0, checkType('object', {
8861
8947
  id: checkData('string'),
8862
8948
  'showDialogConfirm?': checkData('boolean')
8863
8949
  }))
8864
8950
  ], SDKCreator.prototype, "followOA", null);
8865
8951
  __decorate([
8866
- handleError,
8867
- validate,
8868
8952
  __param(0, checkType('object', {
8869
8953
  id: checkData('string')
8870
8954
  }))
8871
8955
  ], SDKCreator.prototype, "unfollowOA", null);
8872
8956
  __decorate([
8873
- handleError,
8874
- validate,
8875
8957
  __param(0, required([['data.imageUrl', 'data.imageUrls']], { if: { type: 'image' } })),
8876
8958
  __param(0, required(['data.link'], { if: { type: 'link' } })),
8877
8959
  __param(0, required(['data.id'], { if: { type: 'oa' } })),
@@ -8910,14 +8992,6 @@ __decorate([
8910
8992
  }))
8911
8993
  ], SDKCreator.prototype, "openShareSheet", null);
8912
8994
  __decorate([
8913
- handleError
8914
- ], SDKCreator.prototype, "requestCameraPermission", null);
8915
- __decorate([
8916
- handleError
8917
- ], SDKCreator.prototype, "createShortcut", null);
8918
- __decorate([
8919
- handleError,
8920
- validate,
8921
8995
  __param(0, checkType('object', {
8922
8996
  secretData: checkData('string'),
8923
8997
  'ui?': checkData('object'),
@@ -8935,44 +9009,28 @@ __decorate([
8935
9009
  }))
8936
9010
  ], SDKCreator.prototype, "openBioAuthentication", null);
8937
9011
  __decorate([
8938
- handleError
8939
- ], SDKCreator.prototype, "checkStateBioAuthentication", null);
8940
- __decorate([
8941
- handleError,
8942
- validate,
8943
9012
  __param(0, checkType('object', {
8944
9013
  toUserId: checkData('string'),
8945
9014
  'title?': checkData('string')
8946
9015
  }))
8947
9016
  ], SDKCreator.prototype, "sendLocation", null);
8948
9017
  __decorate([
8949
- handleError,
8950
- validate,
8951
9018
  __param(0, checkType('object', {
8952
9019
  message: checkData('string')
8953
9020
  }))
8954
9021
  ], SDKCreator.prototype, "showToast", null);
8955
9022
  __decorate([
8956
- handleError
8957
- ], SDKCreator.prototype, "hideKeyboard", null);
8958
- __decorate([
8959
- handleError,
8960
- validate,
8961
9023
  __param(0, checkType('object', {
8962
9024
  phoneNumber: checkData('string')
8963
9025
  }))
8964
9026
  ], SDKCreator.prototype, "openPhone", null);
8965
9027
  __decorate([
8966
- handleError,
8967
- validate,
8968
9028
  __param(0, checkType('object', {
8969
9029
  content: checkData('string'),
8970
9030
  phoneNumber: checkData('string', { regex: /^\+?\d+$/ })
8971
9031
  }))
8972
9032
  ], SDKCreator.prototype, "openSMS", null);
8973
9033
  __decorate([
8974
- handleError,
8975
- validate,
8976
9034
  __param(0, checkType('object', {
8977
9035
  id: checkData('string'),
8978
9036
  'displayName?': checkData('string')
@@ -8981,35 +9039,24 @@ __decorate([
8981
9039
  }))
8982
9040
  ], SDKCreator.prototype, "viewOAQr", null);
8983
9041
  __decorate([
8984
- handleError
8985
- ], SDKCreator.prototype, "keepScreen", null);
8986
- __decorate([
8987
- handleError,
8988
- validate,
8989
9042
  __param(0, checkType('object', {
8990
9043
  'imageBase64Data?': checkData('string'),
8991
9044
  'imageUrl?': checkData('url')
8992
9045
  }))
8993
9046
  ], SDKCreator.prototype, "saveImageToGallery", null);
8994
9047
  __decorate([
8995
- handleError,
8996
- validate,
8997
9048
  __param(0, checkType('object', {
8998
9049
  'imageBase64Data?': checkData('string'),
8999
9050
  'imageUrl?': checkData('url')
9000
9051
  }))
9001
9052
  ], SDKCreator.prototype, "saveImageToPhotosAlbum", null);
9002
9053
  __decorate([
9003
- handleError,
9004
- validate,
9005
9054
  __param(0, checkType('object', {
9006
9055
  appId: checkData('string'),
9007
9056
  'params?': checkData('object')
9008
9057
  }))
9009
9058
  ], SDKCreator.prototype, "openMiniApp", null);
9010
9059
  __decorate([
9011
- handleError,
9012
- validate,
9013
9060
  __param(0, checkType('object', {
9014
9061
  'type?': checkData('string', { values: ['oneShot'] }),
9015
9062
  'milliseconds?': checkData('number')
@@ -9019,30 +9066,11 @@ __decorate([
9019
9066
  }))
9020
9067
  ], SDKCreator.prototype, "vibrate", null);
9021
9068
  __decorate([
9022
- handleError,
9023
- validate,
9024
9069
  __param(0, checkType('object', {
9025
9070
  url: checkData('url')
9026
9071
  }))
9027
9072
  ], SDKCreator.prototype, "openWebview", null);
9028
9073
  __decorate([
9029
- handleErrorSync
9030
- ], SDKCreator.prototype, "getRouteParams", null);
9031
- __decorate([
9032
- handleError
9033
- ], SDKCreator.prototype, "getAppInfo", null);
9034
- __decorate([
9035
- handleError
9036
- ], SDKCreator.prototype, "sendDataToPreviousMiniApp", null);
9037
- __decorate([
9038
- handleError
9039
- ], SDKCreator.prototype, "onCallbackData", null);
9040
- __decorate([
9041
- handleError
9042
- ], SDKCreator.prototype, "getPhoneNumber", null);
9043
- __decorate([
9044
- handleError,
9045
- validate,
9046
9074
  __param(0, checkType('object', {
9047
9075
  'maxProfile?': checkData('number', { min: 1, max: 10 })
9048
9076
  }, {
@@ -9050,8 +9078,6 @@ __decorate([
9050
9078
  }))
9051
9079
  ], SDKCreator.prototype, "openProfilePicker", null);
9052
9080
  __decorate([
9053
- handleError,
9054
- validate,
9055
9081
  __param(0, required(['SSID'])),
9056
9082
  __param(0, checkType('object', {
9057
9083
  SSID: checkData('string'),
@@ -9060,8 +9086,6 @@ __decorate([
9060
9086
  }))
9061
9087
  ], SDKCreator.prototype, "connectWifi", null);
9062
9088
  __decorate([
9063
- handleError,
9064
- validate,
9065
9089
  __param(0, checkType('object', {
9066
9090
  type: checkData('string', {
9067
9091
  values: ['photo', 'video', 'file']
@@ -9076,8 +9100,6 @@ __decorate([
9076
9100
  }))
9077
9101
  ], SDKCreator.prototype, "openMediaPicker", null);
9078
9102
  __decorate([
9079
- handleError,
9080
- validate,
9081
9103
  __param(0, checkType('object', {
9082
9104
  title: checkData('string', { maxLength: 100 }),
9083
9105
  'thumbnail?': checkData('url'),
@@ -9087,14 +9109,9 @@ __decorate([
9087
9109
  description: ''
9088
9110
  }))
9089
9111
  ], SDKCreator.prototype, "getShareableLink", null);
9090
- __decorate([
9091
- handleError,
9092
- validate
9093
- ], SDKCreator.prototype, "closeLoading", null);
9094
- __decorate([
9095
- handleError,
9096
- validate
9097
- ], SDKCreator.prototype, "requestUpdateZalo", null);
9112
+ SDKCreator = __decorate([
9113
+ DecorateAll(centralizedFunctionHandler)
9114
+ ], SDKCreator);
9098
9115
  class ZaloMiniAppSDKCreator extends SDKCreator {
9099
9116
  getServiceInstance() {
9100
9117
  return ZaloMiniProgramSDKService.getInstance();
@@ -9290,7 +9307,7 @@ class MockPaymentService {
9290
9307
  _MockPaymentService_appId = new WeakMap();
9291
9308
 
9292
9309
  var _PaymentCreator_instance, _PaymentCreator_sdk;
9293
- class PaymentCreator {
9310
+ let PaymentCreator = class PaymentCreator {
9294
9311
  constructor(sdk) {
9295
9312
  _PaymentCreator_instance.set(this, void 0);
9296
9313
  _PaymentCreator_sdk.set(this, void 0);
@@ -9298,42 +9315,50 @@ class PaymentCreator {
9298
9315
  __classPrivateFieldSet(this, _PaymentCreator_sdk, sdk, "f");
9299
9316
  }
9300
9317
  /**
9301
- * Tạo đơn hàng
9302
- *
9303
- * @async
9304
- * @function createOrder
9305
- * @category Payment
9306
- * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
9307
- */
9318
+ * Tạo đơn hàng
9319
+ *
9320
+ * @async
9321
+ * @function createOrder
9322
+ * @category Payment
9323
+ * @returns {Promise<CallbackDataType.CreateOrderCallBack>}
9324
+ */
9308
9325
  createOrder(object) {
9309
9326
  return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").createOrder(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
9310
9327
  }
9311
9328
  /**
9312
- * Lấy thông tin transaction
9313
- *
9314
- * @async
9315
- * @function checkTransaction
9316
- * @category Payment
9317
- * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
9318
- */
9329
+ * Lấy thông tin transaction
9330
+ *
9331
+ * @async
9332
+ * @function checkTransaction
9333
+ * @category Payment
9334
+ * @returns {Promise<CallbackDataType.CheckTransactionSuccessCallBack>}
9335
+ */
9319
9336
  checkTransaction(object) {
9320
9337
  return __classPrivateFieldGet(this, _PaymentCreator_instance, "f").checkTransaction(__classPrivateFieldGet(this, _PaymentCreator_sdk, "f"), object);
9321
9338
  }
9322
- }
9339
+ };
9323
9340
  _PaymentCreator_instance = new WeakMap(), _PaymentCreator_sdk = new WeakMap();
9324
9341
  __decorate([
9325
- handleError,
9326
- validate,
9327
9342
  __param(0, checkType('object', {
9328
- 'amount': checkData(['string', 'number']),
9329
- 'desc': checkData('string'),
9330
- 'method?': checkData('string', { values: ['MOMO', 'ZALOPAY', 'MOMO_SANDBOX', 'ZALOPAY_SANDBOX', 'CC', 'CC_SANDBOX', 'ATM', 'ATM_SANDBOX'] })
9343
+ amount: checkData(['string', 'number']),
9344
+ desc: checkData('string'),
9345
+ 'method?': checkData('string', {
9346
+ values: [
9347
+ 'MOMO',
9348
+ 'ZALOPAY',
9349
+ 'MOMO_SANDBOX',
9350
+ 'ZALOPAY_SANDBOX',
9351
+ 'CC',
9352
+ 'CC_SANDBOX',
9353
+ 'ATM',
9354
+ 'ATM_SANDBOX'
9355
+ ]
9356
+ })
9331
9357
  }))
9332
9358
  ], PaymentCreator.prototype, "createOrder", null);
9333
- __decorate([
9334
- handleError,
9335
- validate
9336
- ], PaymentCreator.prototype, "checkTransaction", null);
9359
+ PaymentCreator = __decorate([
9360
+ DecorateAll(centralizedFunctionHandler)
9361
+ ], PaymentCreator);
9337
9362
  class ZaloMiniAppPaymentCreator extends PaymentCreator {
9338
9363
  getInstance() {
9339
9364
  return PaymentService.getInstance();
@@ -9375,4 +9400,4 @@ else {
9375
9400
  window.ZaloMiniAppSDK = app;
9376
9401
 
9377
9402
  export default app;
9378
- export { ChatType, Events, MediaPickerType, NativeCode, NetworkType, OrientationType, payment as Payment, PlatformType, PostFeedType, ProfileType, SDKCreator, ShareSheetType, VibrateType };
9403
+ export { ChatType, Events, MediaPickerType, NetworkType, OrientationType, payment as Payment, PlatformType, PostFeedType, ProfileType, SDKCreator, ShareSheetType, VibrateType };