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.
package/dist/index.es.js CHANGED
@@ -3740,7 +3740,7 @@ class ZMPEEmitter extends eventemitter3 {
3740
3740
  }
3741
3741
  }
3742
3742
 
3743
- var version$1 = "2.22.3";
3743
+ var version$1 = "2.23.0-rc.1";
3744
3744
 
3745
3745
  class Basics {
3746
3746
  /**
@@ -4908,7 +4908,7 @@ var CORSRequest = {
4908
4908
  execute: execute
4909
4909
  };
4910
4910
 
4911
- var _ZaloJSBridge_instances, _ZaloJSBridge_cookies, _ZaloJSBridge_actionRuntimeInfo, _ZaloJSBridge_jsCall;
4911
+ var _ZaloJSBridge_instances, _ZaloJSBridge_jumpRunning, _ZaloJSBridge_cookies, _ZaloJSBridge_actionRuntimeInfo, _ZaloJSBridge_jsCall;
4912
4912
  class ZaloJSBridge extends eventemitter3 {
4913
4913
  constructor() {
4914
4914
  super();
@@ -4921,45 +4921,19 @@ class ZaloJSBridge extends eventemitter3 {
4921
4921
  this._userAgent = getUserAgent();
4922
4922
  this._device = checkPlatform();
4923
4923
  this.isJumped = false;
4924
- _ZaloJSBridge_cookies.set(this, null);
4924
+ _ZaloJSBridge_jumpRunning.set(this, void 0);
4925
+ _ZaloJSBridge_cookies.set(this, []);
4925
4926
  _ZaloJSBridge_actionRuntimeInfo.set(this, void 0);
4926
- this.jump = () => {
4927
- return new Promise((resolve, reject) => {
4928
- if (!_.isUndefined(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) && !_.isNull(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"))) {
4929
- resolve(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"));
4930
- }
4931
- else {
4932
- this.callNative(ACTION.JUMP_LOGIN, {})
4933
- .then((data) => {
4934
- const cookies = (data && data.cookiesOAuthLogins) || [];
4935
- const actionPermission = (data && data.actionPermission) || [];
4936
- Object.entries(actionPermission).forEach((item) => {
4937
- const key = item[0];
4938
- const value = item[1] || { perm: 0, decode: 0 };
4939
- if (!__classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key]) {
4940
- __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key] = {
4941
- permission: false,
4942
- support: false
4943
- };
4944
- }
4945
- __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key].permission = value.perm === 1;
4946
- });
4947
- const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
4948
- if (jsToken) {
4949
- this.jsAccessTk = jsToken.value;
4950
- window.ZJSBridge.setJSToken &&
4951
- window.ZJSBridge.setJSToken(jsToken.value);
4952
- }
4953
- __classPrivateFieldSet(this, _ZaloJSBridge_cookies, cookies, "f");
4954
- this.isJumped = true;
4955
- resolve(cookies);
4956
- })
4957
- .catch((error) => {
4958
- this.isJumped = false;
4959
- reject(error);
4960
- });
4961
- }
4962
- });
4927
+ this.getCookie = (name) => __awaiter(this, void 0, void 0, function* () {
4928
+ var _a;
4929
+ yield this.jump();
4930
+ const cookie = (_a = __classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) === null || _a === void 0 ? void 0 : _a.find((cookie) => cookie.name === name);
4931
+ return cookie;
4932
+ });
4933
+ this.getCookieSync = (name) => {
4934
+ var _a;
4935
+ const cookie = (_a = __classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f")) === null || _a === void 0 ? void 0 : _a.find((cookie) => cookie.name === name);
4936
+ return cookie;
4963
4937
  };
4964
4938
  this._jsCallFuncCallbacks = {};
4965
4939
  __classPrivateFieldSet(this, _ZaloJSBridge_actionRuntimeInfo, {}, "f");
@@ -4988,6 +4962,7 @@ class ZaloJSBridge extends eventemitter3 {
4988
4962
  }
4989
4963
  }, 5000);
4990
4964
  }
4965
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, 0, "f");
4991
4966
  }
4992
4967
  static getInstance() {
4993
4968
  if (!ZaloJSBridge.instance) {
@@ -5001,6 +4976,68 @@ class ZaloJSBridge extends eventemitter3 {
5001
4976
  set jsAccessTk(value) {
5002
4977
  this._jsAccessTk = value;
5003
4978
  }
4979
+ jump() {
4980
+ return __awaiter(this, void 0, void 0, function* () {
4981
+ const _this = this;
4982
+ function waiting() {
4983
+ return __awaiter(this, void 0, void 0, function* () {
4984
+ return yield new Promise((resolve) => {
4985
+ const interval = setInterval(() => {
4986
+ if (__classPrivateFieldGet(_this, _ZaloJSBridge_jumpRunning, "f") <= 1 || _this.isJumped) {
4987
+ resolve('done');
4988
+ clearInterval(interval);
4989
+ }
4990
+ }, 200);
4991
+ });
4992
+ });
4993
+ }
4994
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, +__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") + 1, "f");
4995
+ if (__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") > 1) {
4996
+ yield waiting();
4997
+ }
4998
+ return new Promise((resolve, reject) => {
4999
+ if (this.isJumped) {
5000
+ resolve(__classPrivateFieldGet(this, _ZaloJSBridge_cookies, "f"));
5001
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, +__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") - 1, "f");
5002
+ }
5003
+ else {
5004
+ this.debug('******** call jump ********');
5005
+ this.callNative(ACTION.JUMP_LOGIN, {})
5006
+ .then((data) => {
5007
+ const cookies = (data && data.cookiesOAuthLogins) || [];
5008
+ const actionPermission = (data && data.actionPermission) || [];
5009
+ Object.entries(actionPermission).forEach((item) => {
5010
+ const key = item[0];
5011
+ const value = item[1] || { perm: 0, decode: 0 };
5012
+ if (!__classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key]) {
5013
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key] = {
5014
+ permission: false,
5015
+ support: false
5016
+ };
5017
+ }
5018
+ __classPrivateFieldGet(this, _ZaloJSBridge_actionRuntimeInfo, "f")[key].permission = value.perm === 1;
5019
+ });
5020
+ const jsToken = cookies.find((cookie) => cookie.name === COOKIE_NAME.JS_TOKEN);
5021
+ if (jsToken) {
5022
+ this.jsAccessTk = jsToken.value;
5023
+ window.ZJSBridge.setJSToken &&
5024
+ window.ZJSBridge.setJSToken(jsToken.value);
5025
+ }
5026
+ __classPrivateFieldSet(this, _ZaloJSBridge_cookies, cookies, "f");
5027
+ this.isJumped = true;
5028
+ resolve(cookies);
5029
+ })
5030
+ .catch((error) => {
5031
+ this.isJumped = false;
5032
+ reject(error);
5033
+ })
5034
+ .finally(() => {
5035
+ __classPrivateFieldSet(this, _ZaloJSBridge_jumpRunning, +__classPrivateFieldGet(this, _ZaloJSBridge_jumpRunning, "f") - 1, "f");
5036
+ });
5037
+ }
5038
+ });
5039
+ });
5040
+ }
5004
5041
  sendLogData(data) {
5005
5042
  try {
5006
5043
  const logData = data.map((item) => {
@@ -5112,7 +5149,7 @@ class ZaloJSBridge extends eventemitter3 {
5112
5149
  }
5113
5150
  callNative(action, data, option) {
5114
5151
  this.debug(action.name, data);
5115
- return new Promise((resolve, reject) => {
5152
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
5116
5153
  const handleNativeCallback = (cb) => __awaiter(this, void 0, void 0, function* () {
5117
5154
  var _a, _b, _c, _d, _e, _f, _g, _h;
5118
5155
  try {
@@ -5136,7 +5173,8 @@ class ZaloJSBridge extends eventemitter3 {
5136
5173
  error = new AppError(COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].code, COMMON_NATIVE_ERROR_CODE[platform][cb.error_code].message);
5137
5174
  }
5138
5175
  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)]) {
5139
- let error_message = action.error_list[platform][String(cb.error_code)].map_to.message;
5176
+ let error_message = action.error_list[platform][String(cb.error_code)].map_to
5177
+ .message;
5140
5178
  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) {
5141
5179
  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}`;
5142
5180
  }
@@ -5156,6 +5194,12 @@ class ZaloJSBridge extends eventemitter3 {
5156
5194
  return reject(error);
5157
5195
  }
5158
5196
  });
5197
+ /**
5198
+ * Check jump status and auto call jump
5199
+ */
5200
+ if (!action.skip_jump) {
5201
+ yield this.jump();
5202
+ }
5159
5203
  const isIOS = checkPlatform().isIOS;
5160
5204
  const isSupportAction = checkIOSSupportAction(action);
5161
5205
  if (isIOS && !isSupportAction) {
@@ -5170,10 +5214,10 @@ class ZaloJSBridge extends eventemitter3 {
5170
5214
  else {
5171
5215
  __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);
5172
5216
  }
5173
- });
5217
+ }));
5174
5218
  }
5175
5219
  }
5176
- _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) {
5220
+ _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) {
5177
5221
  try {
5178
5222
  const actionName = action.name;
5179
5223
  const key = generateUniqueString(actionName);
@@ -6270,6 +6314,21 @@ class ZaloMiniProgramSDKService {
6270
6314
  this.setActionBarConfig = (setState) => {
6271
6315
  __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_actionBarConfig, setState(__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_actionBarConfig, "f")), "f");
6272
6316
  };
6317
+ this.getAuthCode = () => __awaiter(this, void 0, void 0, function* () {
6318
+ var _t, _u;
6319
+ const authCode = (_t = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.ZOAUTH))) === null || _t === void 0 ? void 0 : _t.value;
6320
+ const authCodeVerify = (_u = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.ZOAUTH_VRF))) === null || _u === void 0 ? void 0 : _u.value;
6321
+ return {
6322
+ authCode,
6323
+ authCodeVerify
6324
+ };
6325
+ });
6326
+ this.setAccessToken = (accessToken) => {
6327
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_accessToken, accessToken, "f");
6328
+ __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").accessTk = accessToken;
6329
+ window.ZJSBridge.setZAccSession &&
6330
+ window.ZJSBridge.setZAccSession(accessToken);
6331
+ };
6273
6332
  this.getVersion = Basics.getVersion;
6274
6333
  this.getSystemInfo = Basics.getSystemInfo;
6275
6334
  this.setNavigationBarTitle = NavigationBar.setNavigationBarTitle;
@@ -6386,10 +6445,34 @@ class ZaloMiniProgramSDKService {
6386
6445
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_zAppId, "f");
6387
6446
  }
6388
6447
  getDeviceId() {
6389
- return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_deviceId, "f");
6448
+ var _a;
6449
+ return __awaiter(this, void 0, void 0, function* () {
6450
+ return (_a = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.DEVICE_ID))) === null || _a === void 0 ? void 0 : _a.value;
6451
+ });
6452
+ }
6453
+ getDeviceIdSync() {
6454
+ var _a;
6455
+ return (_a = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookieSync(COOKIE_NAME.DEVICE_ID)) === null || _a === void 0 ? void 0 : _a.value;
6390
6456
  }
6391
6457
  getContext() {
6392
- return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_context, "f");
6458
+ var _a, _b;
6459
+ return __awaiter(this, void 0, void 0, function* () {
6460
+ const contextID = (_a = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.CONTEXT_ID))) === null || _a === void 0 ? void 0 : _a.value;
6461
+ const contextType = (_b = (yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookie(COOKIE_NAME.CONTEXT_TYPE))) === null || _b === void 0 ? void 0 : _b.value;
6462
+ return {
6463
+ type: contextType,
6464
+ id: contextID
6465
+ };
6466
+ });
6467
+ }
6468
+ getContextSync() {
6469
+ var _a, _b;
6470
+ const contextID = (_a = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookieSync(COOKIE_NAME.CONTEXT_ID)) === null || _a === void 0 ? void 0 : _a.value;
6471
+ const contextType = (_b = __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").getCookieSync(COOKIE_NAME.CONTEXT_TYPE)) === null || _b === void 0 ? void 0 : _b.value;
6472
+ return {
6473
+ type: contextType,
6474
+ id: contextID
6475
+ };
6393
6476
  }
6394
6477
  getJSBridge() {
6395
6478
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f");
@@ -6400,29 +6483,12 @@ class ZaloMiniProgramSDKService {
6400
6483
  if (__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f") && deltaTime < __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, "f")) {
6401
6484
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
6402
6485
  }
6403
- const cookies = yield __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_bridge, "f").jump();
6404
- const deviceId = cookies.find((cookie) => cookie.name === COOKIE_NAME.DEVICE_ID);
6405
- const contextID = cookies.find((cookie) => cookie.name === COOKIE_NAME.CONTEXT_ID);
6406
- const contextType = cookies.find((cookie) => cookie.name === COOKIE_NAME.CONTEXT_TYPE);
6407
- if (deviceId) {
6408
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_deviceId, deviceId.value, "f");
6409
- }
6410
- if (contextID && contextType) {
6411
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_context, {
6412
- id: contextID.value,
6413
- type: contextType.value
6414
- }, "f");
6415
- }
6416
- const zOAuthCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH);
6417
- const zOAuthVrfCookie = cookies.find((cookie) => cookie.name === COOKIE_NAME.ZOAUTH_VRF);
6418
- if (!_.isUndefined(zOAuthCookie) &&
6419
- !_.isNull(zOAuthCookie) &&
6420
- _.isString(zOAuthCookie.value)) {
6421
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuth, zOAuthCookie.value, "f");
6422
- if (!_.isUndefined(zOAuthVrfCookie) &&
6423
- !_.isNull(zOAuthVrfCookie) &&
6424
- _.isString(zOAuthVrfCookie.value)) {
6425
- __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuthVrf, zOAuthVrfCookie.value, "f");
6486
+ const zOAuth = yield (yield this.getAuthCode()).authCode;
6487
+ const zOAuthVrf = yield (yield this.getAuthCode()).authCodeVerify;
6488
+ if (zOAuth) {
6489
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuth, zOAuth, "f");
6490
+ if (zOAuthVrf) {
6491
+ __classPrivateFieldSet(this, _ZaloMiniProgramSDKService_zOAuthVrf, zOAuthVrf, "f");
6426
6492
  yield this.loginZaloV4();
6427
6493
  }
6428
6494
  else {
@@ -6497,7 +6563,7 @@ class ZaloMiniProgramSDKService {
6497
6563
  if (!__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f")) {
6498
6564
  throw apiResponse.error.loginRequired();
6499
6565
  }
6500
- if (deltaTime < __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, "f"))
6566
+ if (!__classPrivateFieldGet(this, _ZaloMiniProgramSDKService_prevGetTokenTimestamp, "f") || deltaTime < __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_tokenExpiresIn, "f"))
6501
6567
  return __classPrivateFieldGet(this, _ZaloMiniProgramSDKService_accessToken, "f");
6502
6568
  return yield this.login();
6503
6569
  });
@@ -6524,7 +6590,10 @@ class MockSDKService {
6524
6590
  this.getAppId = () => {
6525
6591
  return __classPrivateFieldGet(this, _MockSDKService_appId, "f");
6526
6592
  };
6527
- this.getDeviceId = () => {
6593
+ this.getDeviceId = () => __awaiter(this, void 0, void 0, function* () {
6594
+ return Promise.resolve('');
6595
+ });
6596
+ this.getDeviceIdSync = () => {
6528
6597
  return '';
6529
6598
  };
6530
6599
  this.login = () => {
@@ -6827,8 +6896,19 @@ class MockSDKService {
6827
6896
  this.openAppStore = (data) => {
6828
6897
  return Promise.resolve();
6829
6898
  };
6899
+ this.getAuthCode = () => {
6900
+ return Promise.resolve({
6901
+ authCode: '',
6902
+ authCodeVerify: ''
6903
+ });
6904
+ };
6830
6905
  }
6831
6906
  getContext() {
6907
+ return __awaiter(this, void 0, void 0, function* () {
6908
+ return Promise.resolve(null);
6909
+ });
6910
+ }
6911
+ getContextSync() {
6832
6912
  return null;
6833
6913
  }
6834
6914
  on(event, fn, context) {
@@ -6849,6 +6929,7 @@ class MockSDKService {
6849
6929
  data: ''
6850
6930
  });
6851
6931
  }
6932
+ setAccessToken(accessToken) { }
6852
6933
  }
6853
6934
  _MockSDKService_appId = new WeakMap(), _MockSDKService_appConfig = new WeakMap(), _MockSDKService_zOAuth = new WeakMap(), _MockSDKService_accessToken = new WeakMap(), _MockSDKService_cache = new WeakMap(), _MockSDKService_loggedId = new WeakMap();
6854
6935
 
@@ -8738,7 +8819,6 @@ let SDKCreator = class SDKCreator {
8738
8819
  }
8739
8820
  vibrate(object) {
8740
8821
  return __awaiter(this, void 0, void 0, function* () {
8741
- console.log(object);
8742
8822
  yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").vibrate(object);
8743
8823
  });
8744
8824
  }
@@ -8892,10 +8972,28 @@ let SDKCreator = class SDKCreator {
8892
8972
  __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setNavigationBarLeftButton(undefined, 0);
8893
8973
  }
8894
8974
  getDeviceId() {
8895
- return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceId();
8975
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceIdSync();
8976
+ }
8977
+ getDeviceIdAsync(object) {
8978
+ return __awaiter(this, void 0, void 0, function* () {
8979
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getDeviceId();
8980
+ });
8896
8981
  }
8897
8982
  getContext() {
8898
- return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getContext();
8983
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getContextSync();
8984
+ }
8985
+ getContextAsync(object) {
8986
+ return __awaiter(this, void 0, void 0, function* () {
8987
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getContext();
8988
+ });
8989
+ }
8990
+ getAuthCode(object) {
8991
+ return __awaiter(this, void 0, void 0, function* () {
8992
+ return yield __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").getAuthCode();
8993
+ });
8994
+ }
8995
+ setAccessToken(accessToken) {
8996
+ return __classPrivateFieldGet(this, _SDKCreator_sdkService, "f").setAccessToken(accessToken);
8899
8997
  }
8900
8998
  };
8901
8999
  _SDKCreator_sdkService = new WeakMap();