abckit 0.0.35 → 0.0.37

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/module.mjs CHANGED
@@ -42,6 +42,11 @@ function getModuleDependencies(nuxt) {
42
42
  };
43
43
  }
44
44
 
45
+ const CAPACITOR_EXTERNAL_PACKAGES = [
46
+ "@capacitor/preferences",
47
+ "@capacitor/app",
48
+ "@capacitor/network"
49
+ ];
45
50
  const VITE_EXCLUDE_PACKAGES = [
46
51
  "abckit",
47
52
  "shadcn-nuxt",
@@ -69,6 +74,7 @@ const VITE_EXCLUDE_PACKAGES = [
69
74
  "@capacitor/network",
70
75
  "@capacitor/push-notifications",
71
76
  "@capacitor/device",
77
+ "@capacitor/app",
72
78
  "capacitor-native-settings",
73
79
  "@capacitor/haptics",
74
80
  "@unovis/vue"
@@ -283,6 +289,14 @@ function setupVite(nuxt) {
283
289
  const excludeSet = new Set(nuxt.options.vite.optimizeDeps.exclude);
284
290
  VITE_EXCLUDE_PACKAGES.forEach((pkg) => excludeSet.add(pkg));
285
291
  nuxt.options.vite.optimizeDeps.exclude = Array.from(excludeSet);
292
+ nuxt.options.vite.build = nuxt.options.vite.build || {};
293
+ nuxt.options.vite.build.rollupOptions = nuxt.options.vite.build.rollupOptions || {};
294
+ const existingExternal = nuxt.options.vite.build.rollupOptions.external;
295
+ const externalSet = new Set(
296
+ Array.isArray(existingExternal) ? existingExternal.filter((e) => typeof e === "string") : []
297
+ );
298
+ CAPACITOR_EXTERNAL_PACKAGES.forEach((pkg) => externalSet.add(pkg));
299
+ nuxt.options.vite.build.rollupOptions.external = Array.from(externalSet);
286
300
  if (nuxt.options.dev) {
287
301
  nuxt.options.vite.server = nuxt.options.vite.server || {};
288
302
  nuxt.options.vite.server.allowedHosts = true;
@@ -21,12 +21,18 @@ async function initOfflineSession(isCapacitor) {
21
21
  offlineChecked.value = true;
22
22
  }
23
23
  }
24
+ function isCapacitorNative() {
25
+ if (typeof window === "undefined")
26
+ return false;
27
+ const cap = window.Capacitor;
28
+ return cap?.isNativePlatform?.() ?? false;
29
+ }
24
30
  function getAuthClient() {
25
31
  if (authClient)
26
32
  return authClient;
27
33
  const config = useRuntimeConfig();
28
34
  const authConfig = config.public.abckit?.auth;
29
- const isCapacitor = authConfig?.capacitor ?? false;
35
+ const isCapacitor = authConfig?.capacitor ?? isCapacitorNative();
30
36
  initOfflineSession(isCapacitor);
31
37
  const plugins = [adminClient()];
32
38
  if (authConfig?.oauthProvider) {
@@ -48,7 +54,7 @@ export function useAuth() {
48
54
  const client = getAuthClient();
49
55
  const session = client.useSession();
50
56
  const config = useRuntimeConfig();
51
- const isCapacitor = config.public.abckit?.auth?.capacitor ?? false;
57
+ const isCapacitor = config.public.abckit?.auth?.capacitor ?? isCapacitorNative();
52
58
  const isLoading = computed(() => {
53
59
  if (session.value.isPending)
54
60
  return true;
@@ -1,5 +1,12 @@
1
- import { Preferences } from "@capacitor/preferences";
2
1
  import { kFocusManager, kOnlineManager } from "better-auth/client";
2
+ let Preferences = null;
3
+ async function getPreferences() {
4
+ if (!Preferences) {
5
+ const mod = await import("@capacitor/preferences");
6
+ Preferences = mod.Preferences;
7
+ }
8
+ return Preferences;
9
+ }
3
10
  class CapacitorFocusManager {
4
11
  listeners = /* @__PURE__ */ new Set();
5
12
  unsubscribe;
@@ -216,14 +223,16 @@ export function capacitorClient(opts) {
216
223
  * Get stored cookie string for manual fetch requests
217
224
  */
218
225
  getCookie: async () => {
219
- const result = await Preferences.get({ key: cookieName });
226
+ const prefs = await getPreferences();
227
+ const result = await prefs.get({ key: cookieName });
220
228
  return getCookieString(result?.value || "{}");
221
229
  },
222
230
  /**
223
231
  * Get cached session data for offline use
224
232
  */
225
233
  getCachedSession: async () => {
226
- const result = await Preferences.get({ key: sessionCacheName });
234
+ const prefs = await getPreferences();
235
+ const result = await prefs.get({ key: sessionCacheName });
227
236
  if (!result?.value)
228
237
  return null;
229
238
  try {
@@ -236,8 +245,9 @@ export function capacitorClient(opts) {
236
245
  * Clear all stored auth data
237
246
  */
238
247
  clearStorage: async () => {
239
- await Preferences.remove({ key: cookieName });
240
- await Preferences.remove({ key: sessionCacheName });
248
+ const prefs = await getPreferences();
249
+ await prefs.remove({ key: cookieName });
250
+ await prefs.remove({ key: sessionCacheName });
241
251
  }
242
252
  };
243
253
  },
@@ -247,34 +257,35 @@ export function capacitorClient(opts) {
247
257
  name: "Capacitor Auth",
248
258
  hooks: {
249
259
  async onSuccess(context) {
260
+ const prefs = await getPreferences();
250
261
  const authToken = context.response.headers.get("set-auth-token");
251
262
  if (authToken) {
252
- const prevCookie = (await Preferences.get({ key: cookieName }))?.value;
263
+ const prevCookie = (await prefs.get({ key: cookieName }))?.value;
253
264
  const tokenCookie = `${cookiePrefix}.session_token=${authToken}`;
254
265
  const newCookie = mergeCookies(tokenCookie, prevCookie ?? void 0);
255
266
  if (hasSessionCookieChanged(prevCookie ?? null, newCookie)) {
256
- await Preferences.set({ key: cookieName, value: newCookie });
267
+ await prefs.set({ key: cookieName, value: newCookie });
257
268
  store?.notify("$sessionSignal");
258
269
  } else {
259
- await Preferences.set({ key: cookieName, value: newCookie });
270
+ await prefs.set({ key: cookieName, value: newCookie });
260
271
  }
261
272
  }
262
273
  const setCookie = context.response.headers.get("set-cookie");
263
274
  if (setCookie) {
264
275
  if (hasBetterAuthCookies(setCookie, cookiePrefix)) {
265
- const prevCookie = (await Preferences.get({ key: cookieName }))?.value;
276
+ const prevCookie = (await prefs.get({ key: cookieName }))?.value;
266
277
  const newCookie = mergeCookies(setCookie, prevCookie ?? void 0);
267
278
  if (hasSessionCookieChanged(prevCookie ?? null, newCookie)) {
268
- await Preferences.set({ key: cookieName, value: newCookie });
279
+ await prefs.set({ key: cookieName, value: newCookie });
269
280
  store?.notify("$sessionSignal");
270
281
  } else {
271
- await Preferences.set({ key: cookieName, value: newCookie });
282
+ await prefs.set({ key: cookieName, value: newCookie });
272
283
  }
273
284
  }
274
285
  }
275
286
  if (context.request.url.toString().includes("/get-session")) {
276
287
  if (context.data?.session || context.data?.user) {
277
- await Preferences.set({
288
+ await prefs.set({
278
289
  key: sessionCacheName,
279
290
  value: JSON.stringify(context.data)
280
291
  });
@@ -283,7 +294,8 @@ export function capacitorClient(opts) {
283
294
  }
284
295
  },
285
296
  async init(url, options) {
286
- const storedCookie = (await Preferences.get({ key: cookieName }))?.value;
297
+ const prefs = await getPreferences();
298
+ const storedCookie = (await prefs.get({ key: cookieName }))?.value;
287
299
  const cookie = getCookieString(storedCookie || "{}");
288
300
  if (cookie) {
289
301
  options = options || {};
@@ -293,8 +305,8 @@ export function capacitorClient(opts) {
293
305
  };
294
306
  }
295
307
  if (url.includes("/sign-out")) {
296
- await Preferences.remove({ key: cookieName });
297
- await Preferences.remove({ key: sessionCacheName });
308
+ await prefs.remove({ key: cookieName });
309
+ await prefs.remove({ key: sessionCacheName });
298
310
  if (store?.atoms?.session) {
299
311
  const currentSession = store.atoms.session.get();
300
312
  store.atoms.session.set({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "abckit",
3
3
  "type": "module",
4
- "version": "0.0.35",
4
+ "version": "0.0.37",
5
5
  "description": "Nuxt 4 module — UI components, auth, storage, GraphQL",
6
6
  "author": "productdevbook",
7
7
  "license": "MIT",
@@ -71,17 +71,6 @@
71
71
  "files": [
72
72
  "dist"
73
73
  ],
74
- "scripts": {
75
- "build": "nuxt-module-build build",
76
- "prepack": "nuxt-module-build build",
77
- "dev": "nuxt dev playground",
78
- "dev:build": "nuxi build playground",
79
- "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
80
- "lint": "eslint .",
81
- "lint:fix": "eslint . --fix",
82
- "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
83
- "release": "pnpm publish --no-git-checks --access public"
84
- },
85
74
  "dependencies": {
86
75
  "@better-auth/oauth-provider": "^1.4.9",
87
76
  "@capacitor/android": "^8.0.0",
@@ -270,5 +259,15 @@
270
259
  "patchedDependencies": {
271
260
  "entities@7.0.0": "patches/entities@7.0.0.patch",
272
261
  "entities@7.0.0@7.0.0": "patches/entities@7.0.0.patch"
262
+ },
263
+ "scripts": {
264
+ "build": "nuxt-module-build build",
265
+ "dev": "nuxt dev playground",
266
+ "dev:build": "nuxi build playground",
267
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
268
+ "lint": "eslint .",
269
+ "lint:fix": "eslint . --fix",
270
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
271
+ "release": "pnpm publish --no-git-checks --access public"
273
272
  }
274
- }
273
+ }