zmp-sdk 2.22.3 → 2.23.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3743,7 +3743,7 @@
3743
3743
  }
3744
3744
  }
3745
3745
 
3746
- var version = "2.22.3";
3746
+ var version = "2.23.0-rc.1";
3747
3747
 
3748
3748
  class Basics {
3749
3749
  /**
@@ -4911,7 +4911,7 @@
4911
4911
  execute: execute
4912
4912
  };
4913
4913
 
4914
- var _ZaloJSBridge_instances, _ZaloJSBridge_cookies, _ZaloJSBridge_actionRuntimeInfo, _ZaloJSBridge_jsCall;
4914
+ var _ZaloJSBridge_instances, _ZaloJSBridge_jumpRunning, _ZaloJSBridge_cookies, _ZaloJSBridge_actionRuntimeInfo, _ZaloJSBridge_jsCall;
4915
4915
  class ZaloJSBridge extends eventemitter3 {
4916
4916
  constructor() {
4917
4917
  super();
@@ -4924,45 +4924,19 @@
4924
4924
  this._userAgent = getUserAgent();
4925
4925
  this._device = checkPlatform();
4926
4926
  this.isJumped = false;
4927
- _ZaloJSBridge_cookies.set(this, null);
4927
+ _ZaloJSBridge_jumpRunning.set(this, void 0);
4928
+ _ZaloJSBridge_cookies.set(this, []);
4928
4929
  _ZaloJSBridge_actionRuntimeInfo.set(this, void 0);
4929
- this.jump = () => {
4930
- return new Promise((resolve, reject) => {
4931
- if (!_.isUndefined(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) && !_.isNull(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"))) {
4932
- resolve(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"));
4933
- }
4934
- else {
4935
- this.callNative(ACTION.JUMP_LOGIN, {})
4936
- .then((data) => {
4937
- const cookies = (data && data.cookiesOAuthLogins) || [];
4938
- const actionPermission = (data && data.actionPermission) || [];
4939
- Object.entries(actionPermission).forEach((item) => {
4940
- const key = item[0];
4941
- const value = item[1] || { perm: 0, decode: 0 };
4942
- if (!__classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key]) {
4943
- __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key] = {
4944
- permission: false,
4945
- support: false
4946
- };
4947
- }
4948
- __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key].permission = value.perm === 1;
4949
- });
4950
- const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
4951
- if (jsToken) {
4952
- this.jsAccessTk = jsToken.value;
4953
- window.ZJSBridge.setJSToken &&
4954
- window.ZJSBridge.setJSToken(jsToken.value);
4955
- }
4956
- __classPrivateFieldSet(this, _ZaloJSBridge_cookies, cookies, "f");
4957
- this.isJumped = true;
4958
- resolve(cookies);
4959
- })
4960
- .catch((error) => {
4961
- this.isJumped = false;
4962
- reject(error);
4963
- });
4964
- }
4965
- });
4930
+ this.getCookie = (name) => __awaiter(this, void 0, void 0, function* () {
4931
+ var _a;
4932
+ yield this.jump();
4933
+ const cookie = (_a = __classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) === null || _a === void 0 ? void 0 : _a.find((cookie) => cookie.name === name);
4934
+ return cookie;
4935
+ });
4936
+ this.getCookieSync = (name) => {
4937
+ var _a;
4938
+ const cookie = (_a = __classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) === null || _a === void 0 ? void 0 : _a.find((cookie) => cookie.name === name);
4939
+ return cookie;
4966
4940
  };
4967
4941
  this._jsCallFuncCallbacks = {};
4968
4942
  __classPrivateFieldSet(this, _ZaloJSBridge_actionRuntimeInfo, {}, "f");
@@ -4991,6 +4965,7 @@
4991
4965
  }
4992
4966
  }, 5000);
4993
4967
  }
4968
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, 0, "f");
4994
4969
  }
4995
4970
  static getInstance() {
4996
4971
  if (!ZaloJSBridge.instance) {
@@ -5004,6 +4979,68 @@
5004
4979
  set jsAccessTk(value) {
5005
4980
  this._jsAccessTk = value;
5006
4981
  }
4982
+ jump() {
4983
+ return __awaiter(this, void 0, void 0, function* () {
4984
+ const _this = this;
4985
+ function waiting() {
4986
+ return __awaiter(this, void 0, void 0, function* () {
4987
+ return yield new Promise((resolve) => {
4988
+ const interval = setInterval(() => {
4989
+ if (__classPrivateFieldGet(_this, _ZaloJSBridge_jumpRunning, "f") <= 1 || _this.isJumped) {
4990
+ resolve('done');
4991
+ clearInterval(interval);
4992
+ }
4993
+ }, 200);
4994
+ });
4995
+ });
4996
+ }
4997
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, +__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") + 1, "f");
4998
+ if (__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") > 1) {
4999
+ yield waiting();
5000
+ }
5001
+ return new Promise((resolve, reject) => {
5002
+ if (this.isJumped) {
5003
+ resolve(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"));
5004
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, +__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") - 1, "f");
5005
+ }
5006
+ else {
5007
+ this.debug('******** call jump ********');
5008
+ this.callNative(ACTION.JUMP_LOGIN, {})
5009
+ .then((data) => {
5010
+ const cookies = (data && data.cookiesOAuthLogins) || [];
5011
+ const actionPermission = (data && data.actionPermission) || [];
5012
+ Object.entries(actionPermission).forEach((item) => {
5013
+ const key = item[0];
5014
+ const value = item[1] || { perm: 0, decode: 0 };
5015
+ if (!__classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key]) {
5016
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key] = {
5017
+ permission: false,
5018
+ support: false
5019
+ };
5020
+ }
5021
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key].permission = value.perm === 1;
5022
+ });
5023
+ const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
5024
+ if (jsToken) {
5025
+ this.jsAccessTk = jsToken.value;
5026
+ window.ZJSBridge.setJSToken &&
5027
+ window.ZJSBridge.setJSToken(jsToken.value);
5028
+ }
5029
+ __classPrivateFieldSet(this, _ZaloJSBridge_cookies, cookies, "f");
5030
+ this.isJumped = true;
5031
+ resolve(cookies);
5032
+ })
5033
+ .catch((error) => {
5034
+ this.isJumped = false;
5035
+ reject(error);
5036
+ })
5037
+ .finally(() => {
5038
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, +__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") - 1, "f");
5039
+ });
5040
+ }
5041
+ });
5042
+ });
5043
+ }
5007
5044
  sendLogData(data) {
5008
5045
  try {
5009
5046
  const logData = data.map((item) => {
@@ -5115,7 +5152,7 @@
5115
5152
  }
5116
5153
  callNative(action, data, option) {
5117
5154
  this.debug(action.name, data);
5118
- return new Promise((resolve, reject) => {
5155
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
5119
5156
  const handleNativeCallback = (cb) => __awaiter(this, void 0, void 0, function* () {
5120
5157
  var _a, _b, _c, _d, _e, _f, _g, _h;
5121
5158
  try {
@@ -5139,7 +5176,8 @@
5139
5176
  error = new AppError(COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].code, COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].message);
5140
5177
  }
5141
5178
  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)]) {
5142
- let error_message = action.error_list[platform][String(cb.error_code)].map_to.message;
5179
+ let error_message = action.error_list[platform][String(cb.error_code)].map_to
5180
+ .message;
5143
5181
  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) {
5144
5182
  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}`;
5145
5183
  }
@@ -5159,6 +5197,12 @@
5159
5197
  return reject(error);
5160
5198
  }
5161
5199
  });
5200
+ /**
5201
+ * Check jump status and auto call jump
5202
+ */
5203
+ if (!action.skip_jump) {
5204
+ yield this.jump();
5205
+ }
5162
5206
  const isIOS = checkPlatform().isIOS;
5163
5207
  const isSupportAction = checkIOSSupportAction(action);
5164
5208
  if (isIOS && !isSupportAction) {
@@ -5173,10 +5217,10 @@
5173
5217
  else {
5174
5218
  __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);
5175
5219
  }
5176
- });
5220
+ }));
5177
5221
  }
5178
5222
  }
5179
- _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) {
5223
+ _ZaloJSBridge_jumpRunning = new WeakMap(), _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) {
5180
5224
  try {
5181
5225
  const actionName = action.name;
5182
5226
  const key = generateUniqueString(actionName);
@@ -6273,6 +6317,21 @@
6273
6317
  this.setActionBarConfig = (setState) => {
6274
6318
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_actionBarConfig, setState(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_actionBarConfig, "f")), "f");
6275
6319
  };
6320
+ this.getAuthCode = () => __awaiter(this, void 0, void 0, function* () {
6321
+ var _t, _u;
6322
+ const authCode = (_t = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.ZOAUTH))) === null || _t === void 0 ? void 0 : _t.value;
6323
+ const authCodeVerify = (_u = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.ZOAUTH_VRF))) === null || _u === void 0 ? void 0 : _u.value;
6324
+ return {
6325
+ authCode,
6326
+ authCodeVerify
6327
+ };
6328
+ });
6329
+ this.setAccessToken = (accessToken) => {
6330
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_accessToken, accessToken, "f");
6331
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = accessToken;
6332
+ window.ZJSBridge.setZAccSession &&
6333
+ window.ZJSBridge.setZAccSession(accessToken);
6334
+ };
6276
6335
  this.getVersion = Basics.getVersion;
6277
6336
  this.getSystemInfo = Basics.getSystemInfo;
6278
6337
  this.setNavigationBarTitle = NavigationBar.setNavigationBarTitle;
@@ -6389,10 +6448,34 @@
6389
6448
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zAppId, "f");
6390
6449
  }
6391
6450
  getDeviceId() {
6392
- return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_deviceId, "f");
6451
+ var _a;
6452
+ return __awaiter(this, void 0, void 0, function* () {
6453
+ return (_a = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.DEVICE_ID))) === null || _a === void 0 ? void 0 : _a.value;
6454
+ });
6455
+ }
6456
+ getDeviceIdSync() {
6457
+ var _a;
6458
+ return (_a = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookieSync(COOKIE_NAME.DEVICE_ID)) === null || _a === void 0 ? void 0 : _a.value;
6393
6459
  }
6394
6460
  getContext() {
6395
- return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_context, "f");
6461
+ var _a, _b;
6462
+ return __awaiter(this, void 0, void 0, function* () {
6463
+ const contextID = (_a = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.CONTEXT_ID))) === null || _a === void 0 ? void 0 : _a.value;
6464
+ const contextType = (_b = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.CONTEXT_TYPE))) === null || _b === void 0 ? void 0 : _b.value;
6465
+ return {
6466
+ type: contextType,
6467
+ id: contextID
6468
+ };
6469
+ });
6470
+ }
6471
+ getContextSync() {
6472
+ var _a, _b;
6473
+ const contextID = (_a = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookieSync(COOKIE_NAME.CONTEXT_ID)) === null || _a === void 0 ? void 0 : _a.value;
6474
+ const contextType = (_b = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookieSync(COOKIE_NAME.CONTEXT_TYPE)) === null || _b === void 0 ? void 0 : _b.value;
6475
+ return {
6476
+ type: contextType,
6477
+ id: contextID
6478
+ };
6396
6479
  }
6397
6480
  getJSBridge() {
6398
6481
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f");
@@ -6403,29 +6486,12 @@
6403
6486
  if (__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") && deltaTime < __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, "f")) {
6404
6487
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
6405
6488
  }
6406
- const cookies = yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").jump();
6407
- const deviceId = cookies.find((cookie) => cookie.name === COOKIE_NAME.DEVICE_ID);
6408
- const contextID = cookies.find((cookie) => cookie.name === COOKIE_NAME.CONTEXT_ID);
6409
- const contextType = cookies.find((cookie) => cookie.name === COOKIE_NAME.CONTEXT_TYPE);
6410
- if (deviceId) {
6411
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_deviceId, deviceId.value, "f");
6412
- }
6413
- if (contextID && contextType) {
6414
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_context, {
6415
- id: contextID.value,
6416
- type: contextType.value
6417
- }, "f");
6418
- }
6419
- const zOAuthCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH);
6420
- const zOAuthVrfCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH_VRF);
6421
- if (!_.isUndefined(zOAuthCookie) &&
6422
- !_.isNull(zOAuthCookie) &&
6423
- _.isString(zOAuthCookie.value)) {
6424
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuth, zOAuthCookie.value, "f");
6425
- if (!_.isUndefined(zOAuthVrfCookie) &&
6426
- !_.isNull(zOAuthVrfCookie) &&
6427
- _.isString(zOAuthVrfCookie.value)) {
6428
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuthVrf, zOAuthVrfCookie.value, "f");
6489
+ const zOAuth = yield (yield this.getAuthCode()).authCode;
6490
+ const zOAuthVrf = yield (yield this.getAuthCode()).authCodeVerify;
6491
+ if (zOAuth) {
6492
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuth, zOAuth, "f");
6493
+ if (zOAuthVrf) {
6494
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuthVrf, zOAuthVrf, "f");
6429
6495
  yield this.loginZaloV4();
6430
6496
  }
6431
6497
  else {
@@ -6500,7 +6566,7 @@
6500
6566
  if (!__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f")) {
6501
6567
  throw apiResponse.error.loginRequired();
6502
6568
  }
6503
- if (deltaTime < __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, "f"))
6569
+ if (!__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, "f") || deltaTime < __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, "f"))
6504
6570
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
6505
6571
  return yield this.login();
6506
6572
  });
@@ -6527,7 +6593,10 @@
6527
6593
  this.getAppId = () => {
6528
6594
  return __classPrivateFieldGet(this, _MockSDKService_appId, "f");
6529
6595
  };
6530
- this.getDeviceId = () => {
6596
+ this.getDeviceId = () => __awaiter(this, void 0, void 0, function* () {
6597
+ return Promise.resolve('');
6598
+ });
6599
+ this.getDeviceIdSync = () => {
6531
6600
  return '';
6532
6601
  };
6533
6602
  this.login = () => {
@@ -6830,8 +6899,19 @@
6830
6899
  this.openAppStore = (data) => {
6831
6900
  return Promise.resolve();
6832
6901
  };
6902
+ this.getAuthCode = () => {
6903
+ return Promise.resolve({
6904
+ authCode: '',
6905
+ authCodeVerify: ''
6906
+ });
6907
+ };
6833
6908
  }
6834
6909
  getContext() {
6910
+ return __awaiter(this, void 0, void 0, function* () {
6911
+ return Promise.resolve(null);
6912
+ });
6913
+ }
6914
+ getContextSync() {
6835
6915
  return null;
6836
6916
  }
6837
6917
  on(event, fn, context) {
@@ -6852,6 +6932,7 @@
6852
6932
  data: ''
6853
6933
  });
6854
6934
  }
6935
+ setAccessToken(accessToken) { }
6855
6936
  }
6856
6937
  _MockSDKService_appId = new WeakMap(), _MockSDKService_appConfig = new WeakMap(), _MockSDKService_zOAuth = new WeakMap(), _MockSDKService_accessToken = new WeakMap(), _MockSDKService_cache = new WeakMap(), _MockSDKService_loggedId = new WeakMap();
6857
6938
 
@@ -7383,7 +7464,6 @@
7383
7464
  }
7384
7465
  vibrate(object) {
7385
7466
  return __awaiter(this, void 0, void 0, function* () {
7386
- console.log(object);
7387
7467
  yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").vibrate(object);
7388
7468
  });
7389
7469
  }
@@ -7537,10 +7617,28 @@
7537
7617
  __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(undefined, 0);
7538
7618
  }
7539
7619
  getDeviceId() {
7540
- return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceId();
7620
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceIdSync();
7621
+ }
7622
+ getDeviceIdAsync(object) {
7623
+ return __awaiter(this, void 0, void 0, function* () {
7624
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceId();
7625
+ });
7541
7626
  }
7542
7627
  getContext() {
7543
- return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getContext();
7628
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getContextSync();
7629
+ }
7630
+ getContextAsync(object) {
7631
+ return __awaiter(this, void 0, void 0, function* () {
7632
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getContext();
7633
+ });
7634
+ }
7635
+ getAuthCode(object) {
7636
+ return __awaiter(this, void 0, void 0, function* () {
7637
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getAuthCode();
7638
+ });
7639
+ }
7640
+ setAccessToken(accessToken) {
7641
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setAccessToken(accessToken);
7544
7642
  }
7545
7643
  };
7546
7644
  _SDKCreator_sdkService = new WeakMap();