abckit 0.0.69 → 0.0.70
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.
|
@@ -7,15 +7,20 @@ import {
|
|
|
7
7
|
let _Preferences = null;
|
|
8
8
|
let _Browser = null;
|
|
9
9
|
let _App = null;
|
|
10
|
-
|
|
10
|
+
let _PreferencesLoading = null;
|
|
11
|
+
async function ensurePreferences() {
|
|
12
|
+
if (_Preferences)
|
|
13
|
+
return;
|
|
14
|
+
if (!_PreferencesLoading) {
|
|
15
|
+
_PreferencesLoading = import("@capacitor/preferences").then((mod) => {
|
|
16
|
+
_Preferences = mod.Preferences;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
await _PreferencesLoading;
|
|
20
|
+
}
|
|
21
|
+
function getPreferencesSync() {
|
|
11
22
|
if (!_Preferences) {
|
|
12
|
-
|
|
13
|
-
const mod = await import("@capacitor/preferences");
|
|
14
|
-
console.log("[Capacitor] Module loaded, keys:", Object.keys(mod));
|
|
15
|
-
_Preferences = mod.Preferences;
|
|
16
|
-
if (!_Preferences) {
|
|
17
|
-
console.error("[Capacitor] Preferences is undefined! Module:", mod);
|
|
18
|
-
}
|
|
23
|
+
throw new Error("[Capacitor] Preferences not loaded. Call ensurePreferences() first.");
|
|
19
24
|
}
|
|
20
25
|
return _Preferences;
|
|
21
26
|
}
|
|
@@ -179,7 +184,8 @@ export function capacitorClient(opts) {
|
|
|
179
184
|
* Get stored cookie string for manual fetch requests
|
|
180
185
|
*/
|
|
181
186
|
getCookie: async () => {
|
|
182
|
-
|
|
187
|
+
await ensurePreferences();
|
|
188
|
+
const Preferences = getPreferencesSync();
|
|
183
189
|
const result = await Preferences.get({ key: normalizeCookieName(cookieName) });
|
|
184
190
|
return getCookie(result?.value || "{}");
|
|
185
191
|
},
|
|
@@ -187,7 +193,8 @@ export function capacitorClient(opts) {
|
|
|
187
193
|
* Get cached session data for offline use
|
|
188
194
|
*/
|
|
189
195
|
getCachedSession: async () => {
|
|
190
|
-
|
|
196
|
+
await ensurePreferences();
|
|
197
|
+
const Preferences = getPreferencesSync();
|
|
191
198
|
const result = await Preferences.get({ key: normalizeCookieName(localCacheName) });
|
|
192
199
|
if (!result?.value)
|
|
193
200
|
return null;
|
|
@@ -201,7 +208,8 @@ export function capacitorClient(opts) {
|
|
|
201
208
|
* Clear all stored auth data
|
|
202
209
|
*/
|
|
203
210
|
clearStorage: async () => {
|
|
204
|
-
|
|
211
|
+
await ensurePreferences();
|
|
212
|
+
const Preferences = getPreferencesSync();
|
|
205
213
|
await Preferences.remove({ key: normalizeCookieName(cookieName) });
|
|
206
214
|
await Preferences.remove({ key: normalizeCookieName(localCacheName) });
|
|
207
215
|
}
|
|
@@ -215,7 +223,8 @@ export function capacitorClient(opts) {
|
|
|
215
223
|
async onSuccess(context) {
|
|
216
224
|
if (!isNativePlatform())
|
|
217
225
|
return;
|
|
218
|
-
|
|
226
|
+
await ensurePreferences();
|
|
227
|
+
const Preferences = getPreferencesSync();
|
|
219
228
|
const normalizedCookieName = normalizeCookieName(cookieName);
|
|
220
229
|
const authToken = context.response.headers.get("set-auth-token");
|
|
221
230
|
if (authToken) {
|
|
@@ -292,7 +301,8 @@ export function capacitorClient(opts) {
|
|
|
292
301
|
return { url, options };
|
|
293
302
|
}
|
|
294
303
|
await initializeManagers();
|
|
295
|
-
|
|
304
|
+
await ensurePreferences();
|
|
305
|
+
const Preferences = getPreferencesSync();
|
|
296
306
|
const normalizedCookieName = normalizeCookieName(cookieName);
|
|
297
307
|
const storedCookie = (await Preferences.get({ key: normalizedCookieName }))?.value;
|
|
298
308
|
const cookie = getCookie(storedCookie || "{}");
|