chayns-api 2.3.0 → 2.3.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.
@@ -16,48 +16,49 @@ function isAppStorageAvailable() {
16
16
  if (((_this$values$device$a = this.values.device.app) === null || _this$values$device$a === void 0 ? void 0 : _this$values$device$a.name) !== _IChaynsReact.AppName.Team) {
17
17
  return false;
18
18
  }
19
- return ((_this$values$device$a2 = this.values.device.app) === null || _this$values$device$a2 === void 0 ? void 0 : _this$values$device$a2.appVersion) >= (['iOS', 'Mac OS'].includes(this.values.device.os) ? 1046 : 1031);
19
+ return ((_this$values$device$a2 = this.values.device.app) === null || _this$values$device$a2 === void 0 ? void 0 : _this$values$device$a2.appVersion) >= (['iOS', 'Mac OS'].includes(this.values.device.os) ? 1046 : 1032);
20
20
  }
21
21
  function getAppStorageItem(storeName, key) {
22
- if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
23
- const callbackName = `chaynsApiV5Callback_${this.counter++}`;
24
- return new Promise(resolve => {
25
- window[callbackName] = (_key, _storeName, value) => {
26
- resolve(value);
22
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
23
+ return new Promise(resolve => {
24
+ window[callbackName] = (_key, _storeName, value) => {
25
+ try {
26
+ return resolve(typeof value === 'string' ? JSON.parse(value) : value);
27
+ } catch {
28
+ return resolve(value);
29
+ } finally {
27
30
  delete window[callbackName];
28
- };
31
+ }
32
+ };
33
+ if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
29
34
  window.webkit.messageHandlers.chaynsDataGetItem.postMessage({
30
35
  storeName,
31
36
  key,
32
37
  callback: callbackName
33
38
  });
34
- });
35
- }
36
- const result = window.chaynsWebViewStorage.chaynsDataGetItem(storeName, key);
37
- try {
38
- return Promise.resolve(result ? JSON.parse(result) : result);
39
- } catch {
40
- return Promise.resolve(result);
41
- }
39
+ } else {
40
+ window.chaynsWebViewStorage.chaynsDataGetItem(storeName, key, callbackName);
41
+ }
42
+ });
42
43
  }
43
44
  function setAppStorageItem(storeName, key, value) {
44
- if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
45
- const callbackName = `chaynsApiV5Callback_${this.counter++}`;
46
- return new Promise((resolve, reject) => {
47
- window[callbackName] = () => {
48
- resolve();
49
- delete window[callbackName];
50
- };
45
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
46
+ return new Promise((resolve, reject) => {
47
+ window[callbackName] = () => {
48
+ resolve();
49
+ delete window[callbackName];
50
+ };
51
+ if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
51
52
  window.webkit.messageHandlers.chaynsDataSetItem.postMessage({
52
53
  storeName,
53
54
  key,
54
55
  value,
55
56
  callback: callbackName
56
57
  });
57
- });
58
- }
59
- window.chaynsWebViewStorage.chaynsDataSetItem(storeName, key, JSON.stringify(value));
60
- return Promise.resolve();
58
+ } else {
59
+ window.chaynsWebViewStorage.chaynsDataSetItem(storeName, key, JSON.stringify(value), callbackName);
60
+ }
61
+ });
61
62
  }
62
63
  function removeAppStorageItem(storeName, key) {
63
64
  if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
@@ -5,48 +5,49 @@ export function isAppStorageAvailable() {
5
5
  if (((_this$values$device$a = this.values.device.app) === null || _this$values$device$a === void 0 ? void 0 : _this$values$device$a.name) !== AppName.Team) {
6
6
  return false;
7
7
  }
8
- return ((_this$values$device$a2 = this.values.device.app) === null || _this$values$device$a2 === void 0 ? void 0 : _this$values$device$a2.appVersion) >= (['iOS', 'Mac OS'].includes(this.values.device.os) ? 1046 : 1031);
8
+ return ((_this$values$device$a2 = this.values.device.app) === null || _this$values$device$a2 === void 0 ? void 0 : _this$values$device$a2.appVersion) >= (['iOS', 'Mac OS'].includes(this.values.device.os) ? 1046 : 1032);
9
9
  }
10
10
  export function getAppStorageItem(storeName, key) {
11
- if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
12
- const callbackName = `chaynsApiV5Callback_${this.counter++}`;
13
- return new Promise(resolve => {
14
- window[callbackName] = (_key, _storeName, value) => {
15
- resolve(value);
11
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
12
+ return new Promise(resolve => {
13
+ window[callbackName] = (_key, _storeName, value) => {
14
+ try {
15
+ return resolve(typeof value === 'string' ? JSON.parse(value) : value);
16
+ } catch {
17
+ return resolve(value);
18
+ } finally {
16
19
  delete window[callbackName];
17
- };
20
+ }
21
+ };
22
+ if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
18
23
  window.webkit.messageHandlers.chaynsDataGetItem.postMessage({
19
24
  storeName,
20
25
  key,
21
26
  callback: callbackName
22
27
  });
23
- });
24
- }
25
- const result = window.chaynsWebViewStorage.chaynsDataGetItem(storeName, key);
26
- try {
27
- return Promise.resolve(result ? JSON.parse(result) : result);
28
- } catch {
29
- return Promise.resolve(result);
30
- }
28
+ } else {
29
+ window.chaynsWebViewStorage.chaynsDataGetItem(storeName, key, callbackName);
30
+ }
31
+ });
31
32
  }
32
33
  export function setAppStorageItem(storeName, key, value) {
33
- if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
34
- const callbackName = `chaynsApiV5Callback_${this.counter++}`;
35
- return new Promise((resolve, reject) => {
36
- window[callbackName] = () => {
37
- resolve();
38
- delete window[callbackName];
39
- };
34
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
35
+ return new Promise((resolve, reject) => {
36
+ window[callbackName] = () => {
37
+ resolve();
38
+ delete window[callbackName];
39
+ };
40
+ if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
40
41
  window.webkit.messageHandlers.chaynsDataSetItem.postMessage({
41
42
  storeName,
42
43
  key,
43
44
  value,
44
45
  callback: callbackName
45
46
  });
46
- });
47
- }
48
- window.chaynsWebViewStorage.chaynsDataSetItem(storeName, key, JSON.stringify(value));
49
- return Promise.resolve();
47
+ } else {
48
+ window.chaynsWebViewStorage.chaynsDataSetItem(storeName, key, JSON.stringify(value), callbackName);
49
+ }
50
+ });
50
51
  }
51
52
  export function removeAppStorageItem(storeName, key) {
52
53
  if (this.values.device.os === 'iOS' || this.values.device.os === 'Mac OS') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",