dolphin-server-modules 2.12.0 → 2.12.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/package.json +1 -1
- package/scripts/client.js +30 -7
package/package.json
CHANGED
package/scripts/client.js
CHANGED
|
@@ -494,15 +494,27 @@ class DolphinClient {
|
|
|
494
494
|
/** @type {WebSocket|null} */
|
|
495
495
|
this.socket = null;
|
|
496
496
|
|
|
497
|
-
// Storage polyfill
|
|
498
|
-
this.storage = typeof localStorage !== 'undefined' ? localStorage : {
|
|
497
|
+
// Storage polyfill (Supports Web localStorage & Mobile AsyncStorage)
|
|
498
|
+
this.storage = this.options.storage || (typeof localStorage !== 'undefined' ? localStorage : {
|
|
499
499
|
getItem: () => null,
|
|
500
500
|
setItem: () => {},
|
|
501
501
|
removeItem: () => {},
|
|
502
|
-
};
|
|
502
|
+
});
|
|
503
503
|
|
|
504
504
|
/** @type {string|null} */
|
|
505
|
-
this.accessToken =
|
|
505
|
+
this.accessToken = null;
|
|
506
|
+
|
|
507
|
+
// Handle both Sync (Web) and Async (React Native) storage safely
|
|
508
|
+
try {
|
|
509
|
+
const tokenVal = this.storage.getItem('dolphin_token');
|
|
510
|
+
if (tokenVal && typeof tokenVal.then === 'function') {
|
|
511
|
+
tokenVal.then(t => this.accessToken = t).catch(() => {});
|
|
512
|
+
} else {
|
|
513
|
+
this.accessToken = tokenVal;
|
|
514
|
+
}
|
|
515
|
+
} catch (e) {
|
|
516
|
+
this.accessToken = null;
|
|
517
|
+
}
|
|
506
518
|
|
|
507
519
|
// Sub-handlers
|
|
508
520
|
this.api = new APIHandler(this);
|
|
@@ -533,9 +545,10 @@ class DolphinClient {
|
|
|
533
545
|
/** Save or clear the access token */
|
|
534
546
|
setToken(token) {
|
|
535
547
|
this.accessToken = token;
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
548
|
+
try {
|
|
549
|
+
if (token) this.storage.setItem('dolphin_token', token);
|
|
550
|
+
else this.storage.removeItem('dolphin_token');
|
|
551
|
+
} catch (e) {}
|
|
539
552
|
}
|
|
540
553
|
|
|
541
554
|
// ── WebSocket ─────────────────────────────────────────────────────────────
|
|
@@ -885,6 +898,11 @@ class DolphinClient {
|
|
|
885
898
|
const result = await this.api.request(method, path, data);
|
|
886
899
|
const resultBind = e.target.getAttribute('data-api-result');
|
|
887
900
|
if (resultBind) this._updateDOM(resultBind, result);
|
|
901
|
+
|
|
902
|
+
// Auto Navigation (Hookless Routing)
|
|
903
|
+
const redirect = e.target.getAttribute('data-api-redirect');
|
|
904
|
+
if (redirect) window.location.href = redirect;
|
|
905
|
+
if (e.target.hasAttribute('data-api-reload')) window.location.reload();
|
|
888
906
|
} catch (err) {
|
|
889
907
|
console.error('[Dolphin] API Submit Error:', err);
|
|
890
908
|
}
|
|
@@ -915,6 +933,11 @@ class DolphinClient {
|
|
|
915
933
|
const result = await this.api.request(method, path, payload);
|
|
916
934
|
const resultBind = apiBtn.getAttribute('data-api-result');
|
|
917
935
|
if (resultBind) this._updateDOM(resultBind, result);
|
|
936
|
+
|
|
937
|
+
// Auto Navigation (Hookless Routing)
|
|
938
|
+
const redirect = apiBtn.getAttribute('data-api-redirect');
|
|
939
|
+
if (redirect) window.location.href = redirect;
|
|
940
|
+
if (apiBtn.hasAttribute('data-api-reload')) window.location.reload();
|
|
918
941
|
} catch (err) {
|
|
919
942
|
console.error('[Dolphin] API Click Error:', err);
|
|
920
943
|
}
|