@sfxcode/nuxt-mongocamp-server 1.5.0 → 1.5.2

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/README.md CHANGED
@@ -28,8 +28,9 @@ export default defineNuxtConfig({
28
28
  | `url` | `string` | — | Required. Base URL of the MongoCamp server. |
29
29
  | `apiKey` | `string` | — | Optional. Stored server-side only; picked up automatically by `useMongocampApi(event)`. |
30
30
  | `paginationSize` | `number` | `500` | Default rows per page for search/list composables. Values below 10 fall back to the default. |
31
- | `refreshToken` | `boolean` | — | Whether the client auto-refreshes the session token on an interval after login. |
31
+ | `refreshToken` | `boolean` | `false` | Whether the client auto-refreshes the session token on an interval after login. |
32
32
  | `tokenRefreshInterval` | `number` | `5000` | Refresh interval in ms. Values below 5000 fall back to the default. |
33
+ | `sessionMaxAge` | `number` | `2592000` (30 days) | Max age in seconds of the `mongocamp-session` cookie. Values <= 0 fall back to the default. |
33
34
 
34
35
  A missing `url` throws during `nuxi dev`/`nuxi build`/`nuxi generate` (not during `nuxi prepare`, so IDE/type-stub generation still works without a configured backend).
35
36
 
@@ -37,10 +38,10 @@ A missing `url` throws during `nuxi dev`/`nuxi build`/`nuxi generate` (not durin
37
38
 
38
39
  | Composable | Purpose |
39
40
  | ------------------------------------| ------------------------------------------------------------------------|
40
- | `useMongocampApi()` | Builds all 11 generated API clients, authenticated with the browser session token. |
41
+ | `useMongocampApi()` | Builds all 11 generated API clients, authenticated with the browser session token. A `401` response from any of them clears the local session automatically. |
41
42
  | `useMongocampAuth()` | Login/logout, `isLoggedIn`, `userRoles`/`userGrants`, and token-refresh lifecycle. |
42
43
  | `useMongocampStorage()` | The session cookie (`{ token, profile }`) backing auth state; SSR-safe. |
43
- | `useMongocampUser()` | Reactive current user profile. |
44
+ | `useMongocampUser()` | Reactive current user profile, derived from `useMongocampStorage()` (read-only). |
44
45
  | `useMongocampUrl()` | The configured base URL. |
45
46
  | `useMongocampSearch()` | `find`/`findAll`/`findByField` document search helpers. |
46
47
  | `usePaginatedFind(collection, opts)`| Reactive pagination wrapper (`page`, `documents`, `pending`, `error`, `nextPage`/`previousPage`/`goToPage`). |
package/dist/module.d.mts CHANGED
@@ -5,8 +5,9 @@ interface ModuleOptions {
5
5
  url: string;
6
6
  apiKey?: string;
7
7
  paginationSize?: number;
8
- refreshToken: boolean;
8
+ refreshToken?: boolean;
9
9
  tokenRefreshInterval: number;
10
+ sessionMaxAge?: number;
10
11
  }
11
12
  declare module '@nuxt/schema' {
12
13
  interface PublicRuntimeConfig {
@@ -15,6 +16,7 @@ declare module '@nuxt/schema' {
15
16
  paginationSize: number;
16
17
  refreshToken: boolean;
17
18
  tokenRefreshInterval: number;
19
+ sessionMaxAge: number;
18
20
  };
19
21
  }
20
22
  interface RuntimeConfig {
package/dist/module.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-mongocamp-server",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "configKey": "mongocamp",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.16.0"
7
7
  },
8
8
  "builder": {
9
- "@nuxt/module-builder": "1.0.2",
9
+ "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
11
11
  }
12
12
  }
package/dist/module.mjs CHANGED
@@ -4,7 +4,7 @@ import { consola } from 'consola';
4
4
  export * from '../dist/runtime/api/index.js';
5
5
 
6
6
  const name = "@sfxcode/nuxt-mongocamp-server";
7
- const version = "1.5.0";
7
+ const version = "1.5.2";
8
8
 
9
9
  const module$1 = defineNuxtModule({
10
10
  meta: {
@@ -30,13 +30,20 @@ const module$1 = defineNuxtModule({
30
30
  consola.warn(`[mongocamp] tokenRefreshInterval of ${options.tokenRefreshInterval} is below the minimum of 5000, falling back to 5000`);
31
31
  if (!options.tokenRefreshInterval || options.tokenRefreshInterval < 5e3)
32
32
  options.tokenRefreshInterval = 5e3;
33
+ if (options.refreshToken === void 0) {
34
+ consola.warn('[mongocamp] "refreshToken" module option is not set, falling back to false (no auto token refresh)');
35
+ options.refreshToken = false;
36
+ }
37
+ if (!options.sessionMaxAge || options.sessionMaxAge <= 0)
38
+ options.sessionMaxAge = 60 * 60 * 24 * 30;
33
39
  nuxt.options.runtimeConfig.public.mongocamp = defu(
34
40
  nuxt.options.runtimeConfig.public.mongocamp,
35
41
  {
36
42
  url: options.url,
37
43
  paginationSize: options.paginationSize,
38
44
  refreshToken: options.refreshToken,
39
- tokenRefreshInterval: options.tokenRefreshInterval
45
+ tokenRefreshInterval: options.tokenRefreshInterval,
46
+ sessionMaxAge: options.sessionMaxAge
40
47
  }
41
48
  );
42
49
  nuxt.options.runtimeConfig.mongocampApiKey = nuxt.options.runtimeConfig.mongocampApiKey ?? options.apiKey ?? "";
@@ -5,6 +5,21 @@ import { useMongocampStorage } from "./mongocampStorage.js";
5
5
  export function useMongocampApi() {
6
6
  const url = useMongocampUrl();
7
7
  const state = useMongocampStorage();
8
- const configuration = new Configuration({ basePath: url, accessToken: () => state.value.token });
8
+ const configuration = new Configuration({
9
+ basePath: url,
10
+ accessToken: () => state.value.token,
11
+ middleware: [{
12
+ // a 401 means the token itself is invalid/expired, so clear it everywhere.
13
+ // a 403 is left alone here — it usually means "authenticated but missing a grant
14
+ // for this specific action", not "the session is dead".
15
+ post: async ({ response }) => {
16
+ if (response.status === 401 && state.value.token) {
17
+ state.value.token = "";
18
+ state.value.profile = { user: "", isAdmin: false };
19
+ }
20
+ return response;
21
+ }
22
+ }]
23
+ });
9
24
  return createMongocampApis(configuration);
10
25
  }
@@ -3,7 +3,6 @@ import { consola } from "consola";
3
3
  import { toMongocampError } from "../utils/toMongocampError.js";
4
4
  import { useMongocampApi } from "./mongocampApi.js";
5
5
  import { useMongocampStorage } from "./mongocampStorage.js";
6
- import { useMongocampUser } from "./mongocampUser.js";
7
6
  import { useRuntimeConfig, useState } from "#app";
8
7
  export function useMongocampAuth() {
9
8
  const config = useRuntimeConfig();
@@ -11,7 +10,6 @@ export function useMongocampAuth() {
11
10
  const tokenRefreshInterval = config.public.mongocamp?.tokenRefreshInterval;
12
11
  const state = useMongocampStorage();
13
12
  const { authApi } = useMongocampApi();
14
- const user = useMongocampUser();
15
13
  const updateTokenInterval = useState("mongocamp.tokenRefreshInterval", () => void 0);
16
14
  function startTokenRefresh() {
17
15
  if (import.meta.client && refreshToken && !updateTokenInterval.value)
@@ -40,7 +38,6 @@ export function useMongocampAuth() {
40
38
  function updateUserState(result) {
41
39
  state.value.token = result.authToken;
42
40
  state.value.profile = result.userProfile;
43
- user.value = result.userProfile;
44
41
  }
45
42
  const login = async (loginId, loginPassword) => {
46
43
  logout();
@@ -53,9 +50,7 @@ export function useMongocampAuth() {
53
50
  if (state.value.token)
54
51
  authApi.logout().catch((e) => consola.error(e));
55
52
  state.value.token = "";
56
- const profile = { user: "", isAdmin: false };
57
- state.value.profile = profile;
58
- user.value = profile;
53
+ state.value.profile = { user: "", isAdmin: false };
59
54
  };
60
55
  const isLoggedIn = computed(() => (state.value.token?.length ?? 0) > 0);
61
56
  if (import.meta.client) {
@@ -1,6 +1,10 @@
1
- import { useCookie } from "#app";
1
+ import { useCookie, useRuntimeConfig } from "#app";
2
2
  export function useMongocampStorage() {
3
- return useCookie("mongocamp", {
4
- default: () => ({ token: "", profile: { user: "", isAdmin: false } })
3
+ const config = useRuntimeConfig();
4
+ return useCookie("mongocamp-session", {
5
+ default: () => ({ token: "", profile: { user: "", isAdmin: false } }),
6
+ maxAge: config.public.mongocamp?.sessionMaxAge ?? 60 * 60 * 24 * 30,
7
+ sameSite: "lax",
8
+ secure: !import.meta.dev
5
9
  });
6
10
  }
@@ -1,3 +1,3 @@
1
- import type { Ref } from 'vue';
1
+ import type { ComputedRef } from 'vue';
2
2
  import type { UserProfile } from '../api/index.js';
3
- export declare function useMongocampUser(): Ref<UserProfile>;
3
+ export declare function useMongocampUser(): ComputedRef<UserProfile>;
@@ -1,4 +1,6 @@
1
- import { useState } from "#app";
1
+ import { computed } from "vue";
2
+ import { useMongocampStorage } from "./mongocampStorage.js";
2
3
  export function useMongocampUser() {
3
- return useState("mongocamp.user", () => ({ user: "", isAdmin: false }));
4
+ const state = useMongocampStorage();
5
+ return computed(() => state.value.profile);
4
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-mongocamp-server",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -32,7 +32,7 @@
32
32
  "dev": "nuxi dev playground",
33
33
  "dev:build": "nuxi build playground",
34
34
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
35
- "release": "npm run lint && npm run test && npm run prepack && changelogen --minor --release && npm publish --access public && git push --follow-tags",
35
+ "release": "npm run lint && npm run test && npm run prepack && changelogen --patch --release && npm publish --access public && git push --follow-tags",
36
36
  "lint": "eslint .",
37
37
  "lint:fix": "eslint --fix .",
38
38
  "test": "vitest run",
@@ -43,24 +43,24 @@
43
43
  "api-codegen": "openapi-generator-cli generate -i ./openapi/docs.yaml -g typescript-fetch -o src/runtime/api --additional-properties=typescriptThreePlus=true,supportsES6=true"
44
44
  },
45
45
  "dependencies": {
46
- "@nuxt/kit": "^4.4.8",
47
- "@vueuse/nuxt": "^14.3.0",
46
+ "@nuxt/kit": "^4.5.1",
47
+ "@vueuse/nuxt": "^14.4.0",
48
48
  "consola": "^3.4.2",
49
49
  "defu": "^6.1.7"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@nuxt/devtools": "4.0.0-alpha.7",
53
53
  "@nuxt/eslint-config": "^1.16.0",
54
- "@nuxt/module-builder": "^1.0.2",
55
- "@nuxt/schema": "^4.4.8",
56
- "@nuxt/test-utils": "^4.0.3",
57
- "@openapitools/openapi-generator-cli": "^2.39.0",
58
- "@types/node": "^26.0.0",
54
+ "@nuxt/module-builder": "^1.0.3",
55
+ "@nuxt/schema": "^4.5.1",
56
+ "@nuxt/test-utils": "^4.1.0",
57
+ "@openapitools/openapi-generator-cli": "^2.40.1",
58
+ "@types/node": "^26.1.2",
59
59
  "@unocss/nuxt": "66.7.2",
60
60
  "changelogen": "^0.6.2",
61
- "eslint": "^10.5.0",
62
- "nuxt": "^4.4.8",
63
- "vitest": "^4.1.9"
61
+ "eslint": "^10.8.0",
62
+ "nuxt": "^4.5.1",
63
+ "vitest": "^4.1.10"
64
64
  },
65
65
  "packageManager": "pnpm@10.30.0+sha512.2b5753de015d480eeb88f5b5b61e0051f05b4301808a82ec8b840c9d2adf7748eb352c83f5c1593ca703ff1017295bc3fdd3119abb9686efc96b9fcb18200937"
66
66
  }