@sfxcode/nuxt-mongocamp-server 1.4.4 → 1.5.0

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.
Files changed (34) hide show
  1. package/README.md +63 -0
  2. package/dist/module.d.mts +16 -3
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +20 -642
  5. package/dist/runtime/composables/mongocampApi.d.ts +11 -22
  6. package/dist/runtime/composables/mongocampApi.js +4 -37
  7. package/dist/runtime/composables/mongocampApiAdmin.d.ts +15 -0
  8. package/dist/runtime/composables/mongocampApiAdmin.js +41 -0
  9. package/dist/runtime/composables/mongocampApiCollection.d.ts +26 -0
  10. package/dist/runtime/composables/mongocampApiCollection.js +40 -0
  11. package/dist/runtime/composables/mongocampApiCollections.d.ts +8 -0
  12. package/dist/runtime/composables/mongocampApiCollections.js +23 -0
  13. package/dist/runtime/composables/mongocampApiFiles.d.ts +14 -0
  14. package/dist/runtime/composables/mongocampApiFiles.js +38 -0
  15. package/dist/runtime/composables/mongocampApiJobs.d.ts +9 -0
  16. package/dist/runtime/composables/mongocampApiJobs.js +23 -0
  17. package/dist/runtime/composables/mongocampAuth.js +30 -22
  18. package/dist/runtime/composables/mongocampSearch.d.ts +23 -1
  19. package/dist/runtime/composables/mongocampSearch.js +34 -1
  20. package/dist/runtime/composables/mongocampStorage.d.ts +3 -2
  21. package/dist/runtime/composables/mongocampStorage.js +4 -3
  22. package/dist/runtime/composables/mongocampUser.js +1 -1
  23. package/dist/runtime/server/composables/mongocampApi.d.ts +14 -0
  24. package/dist/runtime/server/composables/mongocampApi.js +8 -0
  25. package/dist/runtime/server/composables/mongocampServerApi.d.ts +11 -12
  26. package/dist/runtime/server/composables/mongocampServerApi.js +4 -39
  27. package/dist/runtime/utils/buildFieldFilterExpression.d.ts +2 -0
  28. package/dist/runtime/utils/buildFieldFilterExpression.js +7 -0
  29. package/dist/runtime/utils/createMongocampApis.d.ts +15 -0
  30. package/dist/runtime/utils/createMongocampApis.js +28 -0
  31. package/dist/runtime/utils/toMongocampError.d.ts +7 -0
  32. package/dist/runtime/utils/toMongocampError.js +19 -0
  33. package/dist/types.d.mts +1 -1
  34. package/package.json +9 -3
package/README.md CHANGED
@@ -1,6 +1,69 @@
1
1
  # Nuxt Mongocamp Module
2
2
 
3
+ Nuxt module wrapping a generated OpenAPI client for [MongoCamp](https://mongocamp.io), with composables for browser-session auth and server-side API-key/bearer auth.
3
4
 
5
+ ## Setup
6
+
7
+ ```bash
8
+ pnpm add @sfxcode/nuxt-mongocamp-server
9
+ ```
10
+
11
+ ```ts
12
+ // nuxt.config.ts
13
+ export default defineNuxtConfig({
14
+ modules: ['@sfxcode/nuxt-mongocamp-server'],
15
+ mongocamp: {
16
+ url: process.env.MONGOCAMP_URL,
17
+ apiKey: process.env.MONGOCAMP_API_KEY, // optional, used by server composables
18
+ refreshToken: true,
19
+ tokenRefreshInterval: 60000,
20
+ },
21
+ })
22
+ ```
23
+
24
+ ### Module options
25
+
26
+ | Option | Type | Default | Description |
27
+ | ------------------------| --------- | ------- | ----------------------------------------------------------------------------------------------|
28
+ | `url` | `string` | — | Required. Base URL of the MongoCamp server. |
29
+ | `apiKey` | `string` | — | Optional. Stored server-side only; picked up automatically by `useMongocampApi(event)`. |
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. |
32
+ | `tokenRefreshInterval` | `number` | `5000` | Refresh interval in ms. Values below 5000 fall back to the default. |
33
+
34
+ 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
+ ### Client composables (`src/runtime/composables`)
37
+
38
+ | Composable | Purpose |
39
+ | ------------------------------------| ------------------------------------------------------------------------|
40
+ | `useMongocampApi()` | Builds all 11 generated API clients, authenticated with the browser session token. |
41
+ | `useMongocampAuth()` | Login/logout, `isLoggedIn`, `userRoles`/`userGrants`, and token-refresh lifecycle. |
42
+ | `useMongocampStorage()` | The session cookie (`{ token, profile }`) backing auth state; SSR-safe. |
43
+ | `useMongocampUser()` | Reactive current user profile. |
44
+ | `useMongocampUrl()` | The configured base URL. |
45
+ | `useMongocampSearch()` | `find`/`findAll`/`findByField` document search helpers. |
46
+ | `usePaginatedFind(collection, opts)`| Reactive pagination wrapper (`page`, `documents`, `pending`, `error`, `nextPage`/`previousPage`/`goToPage`). |
47
+ | `useMongocampApiCollection(name)` | Per-collection insert/update/delete/aggregate/schema helpers. |
48
+ | `useMongocampApiCollections()` | List collections/databases, database info. |
49
+ | `useMongocampApiFiles()` | Bucket and file upload/download/list helpers. |
50
+ | `useMongocampApiJobs()` | List/register/update/execute/delete scheduled jobs. |
51
+ | `useMongocampApiAdmin()` | User and role management. |
52
+
53
+ ### Server composables (`src/runtime/server/composables`)
54
+
55
+ | Composable | Purpose |
56
+ | -----------------------------------------------| -----------------------------------------------------------------------------------|
57
+ | `useMongocampApi(event, token?)` | Builds authenticated API clients using the module's `apiKey`, or the given `token` as a fallback. |
58
+ | `useMongocampServerApi(url, key?, token?)` | Lower-level factory when you need to authenticate against a different URL/credential explicitly. |
59
+
60
+ ```ts
61
+ // server/api/mongocamp/users.ts
62
+ export default defineEventHandler((event) => {
63
+ const { adminApi } = useMongocampApi(event)
64
+ return adminApi.listUsers()
65
+ })
66
+ ```
4
67
 
5
68
  ## Development
6
69
 
package/dist/module.d.mts CHANGED
@@ -1,13 +1,26 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- export * from '../dist/runtime/api/models/index.js';
2
+ export * from '../dist/runtime/api/index.js';
3
3
 
4
4
  interface ModuleOptions {
5
5
  url: string;
6
+ apiKey?: string;
6
7
  paginationSize?: number;
7
8
  refreshToken: boolean;
8
- tokenRefreshIntervall: number;
9
+ tokenRefreshInterval: number;
10
+ }
11
+ declare module '@nuxt/schema' {
12
+ interface PublicRuntimeConfig {
13
+ mongocamp: {
14
+ url: string;
15
+ paginationSize: number;
16
+ refreshToken: boolean;
17
+ tokenRefreshInterval: number;
18
+ };
19
+ }
20
+ interface RuntimeConfig {
21
+ mongocampApiKey: string;
22
+ }
9
23
  }
10
-
11
24
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
12
25
 
13
26
  export { _default as default };
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-mongocamp-server",
3
- "version": "1.4.4",
3
+ "version": "1.5.0",
4
4
  "configKey": "mongocamp",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.16.0"