@mapomodule/core 1.0.0 → 2.0.0-beta.10

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 (96) hide show
  1. package/README.md +56 -0
  2. package/dist/index.d.mts +14 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.mjs +4 -0
  6. package/dist/module.d.mts +11 -0
  7. package/dist/module.d.ts +10 -0
  8. package/dist/module.d.ts.map +1 -0
  9. package/dist/module.json +9 -0
  10. package/dist/module.mjs +78 -0
  11. package/dist/runtime/__tests__/plugins/00.fetch.real.spec.d.ts +2 -0
  12. package/dist/runtime/__tests__/plugins/00.fetch.real.spec.d.ts.map +1 -0
  13. package/dist/runtime/__tests__/plugins/00.fetch.spec.d.ts +2 -0
  14. package/dist/runtime/__tests__/plugins/00.fetch.spec.d.ts.map +1 -0
  15. package/dist/runtime/__tests__/plugins/01.init.server.spec.d.ts +2 -0
  16. package/dist/runtime/__tests__/plugins/01.init.server.spec.d.ts.map +1 -0
  17. package/dist/runtime/__tests__/utils/fetchError.spec.d.ts +2 -0
  18. package/dist/runtime/__tests__/utils/fetchError.spec.d.ts.map +1 -0
  19. package/dist/runtime/api/crud.d.ts +23 -0
  20. package/dist/runtime/api/crud.d.ts.map +1 -0
  21. package/dist/runtime/api/crud.js +80 -0
  22. package/dist/runtime/api/multipart.d.ts +15 -0
  23. package/dist/runtime/api/multipart.d.ts.map +1 -0
  24. package/dist/runtime/api/multipart.js +31 -0
  25. package/dist/runtime/auth/useCanAccessRoute.d.ts +12 -0
  26. package/dist/runtime/auth/useCanAccessRoute.d.ts.map +1 -0
  27. package/dist/runtime/auth/useCanAccessRoute.js +28 -0
  28. package/dist/runtime/auth/useMapoAuth.d.ts +28 -0
  29. package/dist/runtime/auth/useMapoAuth.d.ts.map +1 -0
  30. package/dist/runtime/auth/useMapoAuth.js +38 -0
  31. package/dist/runtime/composables/useMapo.d.ts +48 -0
  32. package/dist/runtime/composables/useMapo.d.ts.map +1 -0
  33. package/dist/runtime/composables/useMapo.js +15 -0
  34. package/dist/runtime/middleware/auth.d.ts +10 -0
  35. package/dist/runtime/middleware/auth.d.ts.map +1 -0
  36. package/dist/runtime/middleware/auth.js +15 -0
  37. package/dist/runtime/middleware/permissions.d.ts +20 -0
  38. package/dist/runtime/middleware/permissions.d.ts.map +1 -0
  39. package/dist/runtime/middleware/permissions.js +27 -0
  40. package/dist/runtime/middleware/roles.d.ts +12 -0
  41. package/dist/runtime/middleware/roles.d.ts.map +1 -0
  42. package/dist/runtime/middleware/roles.js +13 -0
  43. package/dist/runtime/page-meta.nuxt.d.ts +23 -0
  44. package/dist/runtime/plugins/00.fetch.d.ts +21 -0
  45. package/dist/runtime/plugins/00.fetch.d.ts.map +1 -0
  46. package/dist/runtime/plugins/00.fetch.js +61 -0
  47. package/dist/runtime/plugins/01.init.server.d.ts +15 -0
  48. package/dist/runtime/plugins/01.init.server.d.ts.map +1 -0
  49. package/dist/runtime/plugins/01.init.server.js +35 -0
  50. package/dist/runtime/types.d.ts +75 -0
  51. package/dist/runtime/types.d.ts.map +1 -0
  52. package/dist/runtime/types.js +10 -0
  53. package/dist/runtime/types.nuxt.d.ts +18 -0
  54. package/dist/runtime/utils/fetchError.d.ts +29 -0
  55. package/dist/runtime/utils/fetchError.d.ts.map +1 -0
  56. package/dist/runtime/utils/fetchError.js +12 -0
  57. package/dist/runtime/utils/useMapoFetch.d.ts +30 -0
  58. package/dist/runtime/utils/useMapoFetch.d.ts.map +1 -0
  59. package/dist/runtime/utils/useMapoFetch.js +8 -0
  60. package/dist/types.d.mts +13 -0
  61. package/dist/types.d.ts +13 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/package.json +58 -15
  64. package/src/index.ts +9 -0
  65. package/src/module.ts +114 -0
  66. package/src/runtime/__tests__/plugins/00.fetch.real.spec.ts +124 -0
  67. package/src/runtime/__tests__/plugins/00.fetch.spec.ts +146 -0
  68. package/src/runtime/__tests__/plugins/01.init.server.spec.ts +94 -0
  69. package/src/runtime/__tests__/utils/fetchError.spec.ts +97 -0
  70. package/src/runtime/api/crud.ts +138 -0
  71. package/src/runtime/api/multipart.ts +78 -0
  72. package/src/runtime/auth/useCanAccessRoute.ts +48 -0
  73. package/src/runtime/auth/useMapoAuth.ts +91 -0
  74. package/src/runtime/composables/useMapo.ts +61 -0
  75. package/src/runtime/middleware/auth.ts +24 -0
  76. package/src/runtime/middleware/permissions.ts +52 -0
  77. package/src/runtime/middleware/roles.ts +23 -0
  78. package/src/runtime/page-meta.nuxt.d.ts +23 -0
  79. package/src/runtime/plugins/00.fetch.ts +92 -0
  80. package/src/runtime/plugins/01.init.server.ts +66 -0
  81. package/src/runtime/types.nuxt.d.ts +18 -0
  82. package/src/runtime/types.ts +102 -0
  83. package/src/runtime/utils/fetchError.ts +50 -0
  84. package/src/runtime/utils/useMapoFetch.ts +41 -0
  85. package/src/types.ts +13 -0
  86. package/CHANGELOG.md +0 -248
  87. package/api/crud.js +0 -141
  88. package/api/multipart.js +0 -41
  89. package/index.js +0 -134
  90. package/interceptor/auth.js +0 -26
  91. package/interceptor/index.js +0 -5
  92. package/middleware/auth.js +0 -10
  93. package/middleware/permissions.js +0 -36
  94. package/middleware/roles.js +0 -10
  95. package/module.js +0 -44
  96. package/templates/options.js +0 -1
@@ -0,0 +1,66 @@
1
+ import {
2
+ defineNuxtPlugin,
3
+ useRuntimeConfig,
4
+ useCookie,
5
+ useRequestHeaders,
6
+ } from "nuxt/app";
7
+ import { setActivePinia } from "pinia";
8
+ import type { Pinia } from "pinia";
9
+ import { useAuthStore } from "@mapomodule/store/runtime/stores/auth";
10
+ import { useSidebarStore } from "@mapomodule/store/runtime/stores/sidebar";
11
+ import type { MapoUser } from "@mapomodule/store/runtime/types";
12
+ import { CoreCookieEnum } from "../types";
13
+ import type { MapoCoreRuntimeConfig } from "../types";
14
+
15
+ /**
16
+ * Performs server-side bootstrap of Mapo runtime stores.
17
+ *
18
+ * On each SSR request, this plugin:
19
+ * - Activates the request Pinia instance and initializes auth/sidebar stores.
20
+ * - Restores sidebar UI state from cookies.
21
+ * - If the HttpOnly session cookie is present, calls the configured `userInfoApi`
22
+ * (forwarding request cookies) to restore the authenticated user in the auth store.
23
+ *
24
+ * On session restore failure it resets auth state, and clears the session cookie only
25
+ * when the backend rejected the session (401/403) — never on a transport error.
26
+ */
27
+ export default defineNuxtPlugin({
28
+ name: "mapo-core:init",
29
+ async setup(nuxtApp) {
30
+ const runtimeConfig = useRuntimeConfig().public.mapoCore as
31
+ | MapoCoreRuntimeConfig
32
+ | undefined;
33
+ const userInfoApi = runtimeConfig?.userInfoApi ?? "/api/profiles/me/";
34
+
35
+ const pinia = nuxtApp.$pinia as Pinia;
36
+ setActivePinia(pinia);
37
+ const authStore = useAuthStore(pinia);
38
+ const sidebarStore = useSidebarStore(pinia);
39
+
40
+ sidebarStore.hydrateFromCookies();
41
+
42
+ // The session cookie is HttpOnly — readable on SSR but not on the client.
43
+ // If present, hydrate the auth store by fetching the user with the
44
+ // incoming Cookie header forwarded to the proxy middleware.
45
+ const sessionCookie = useCookie(CoreCookieEnum.Session);
46
+ if (!sessionCookie.value) return;
47
+
48
+ try {
49
+ const headers = useRequestHeaders(["cookie"]);
50
+ const user = await (
51
+ nuxtApp.$mapoFetch as (url: string, opts: object) => Promise<unknown>
52
+ )(userInfoApi, { method: "GET", headers });
53
+ authStore.setUser(user as MapoUser);
54
+ } catch (e) {
55
+ console.error(`[mapo] Cannot restore session from cookie:\n${e}`);
56
+ authStore.reset();
57
+ // Only drop the cookie when the backend actually rejected the session.
58
+ // A network blip or a 5xx must not log the user out: the cookie is HttpOnly,
59
+ // so clearing it here is irreversible for the client.
60
+ const status =
61
+ (e as { status?: number; response?: { status?: number } })?.status ??
62
+ (e as { response?: { status?: number } })?.response?.status;
63
+ if (status === 401 || status === 403) sessionCookie.value = null;
64
+ }
65
+ },
66
+ });
@@ -0,0 +1,18 @@
1
+ import type { $Fetch } from "ofetch";
2
+
3
+ declare module "nuxt/app" {
4
+ interface NuxtApp {
5
+ $mapoFetch: $Fetch;
6
+ }
7
+ }
8
+
9
+ declare module "vue-router" {
10
+ interface RouteMeta {
11
+ permissions?: { model: string } | string[];
12
+ roles?: string[];
13
+ /** Route middleware names applied to this route. Read by useCanAccessRoute for sidebar visibility. */
14
+ middleware?: string | string[];
15
+ }
16
+ }
17
+
18
+ export {};
@@ -0,0 +1,102 @@
1
+ export enum MultipartPolicyEnum {
2
+ Auto = "auto",
3
+ Force = "force",
4
+ Disable = "disable",
5
+ }
6
+
7
+ export type MultipartPolicy = `${MultipartPolicyEnum}`;
8
+
9
+ export enum CoreCookieEnum {
10
+ Session = "__mapo_session",
11
+ }
12
+
13
+ export interface ListParams {
14
+ page?: number;
15
+ limit?: number;
16
+ search?: string;
17
+ ordering?: string;
18
+ [key: string]: unknown;
19
+ }
20
+
21
+ export interface PaginatedResponse<T> {
22
+ results: T[];
23
+ count: number;
24
+ next?: string | null;
25
+ previous?: string | null;
26
+ }
27
+
28
+ export type ApiResponse<T> = T;
29
+
30
+ export interface CrudConfig {
31
+ baseURL?: string;
32
+ headers?: Record<string, string>;
33
+ [key: string]: unknown;
34
+ }
35
+
36
+ export interface CrudOptions {
37
+ multipart?: MultipartPolicy;
38
+ }
39
+
40
+ /**
41
+ * What an endpoint returns from OPTIONS. Deliberately loose: backends extend it
42
+ * (Camomilla adds `lang_info`), and clients read only the keys they know.
43
+ */
44
+ export interface ResourceMetadata {
45
+ name?: string;
46
+ description?: string;
47
+ renders?: string[];
48
+ parses?: string[];
49
+ actions?: Record<string, unknown>;
50
+ [key: string]: unknown;
51
+ }
52
+
53
+ export interface CrudRepository<T> {
54
+ list(params?: ListParams, config?: CrudConfig): Promise<PaginatedResponse<T>>;
55
+ detail(id: string | number, config?: CrudConfig): Promise<T>;
56
+ create(data: Partial<T>, config?: CrudConfig, opts?: CrudOptions): Promise<T>;
57
+ update(
58
+ id: string | number,
59
+ data: Partial<T>,
60
+ config?: CrudConfig,
61
+ opts?: CrudOptions,
62
+ ): Promise<T>;
63
+ partialUpdate(
64
+ id: string | number,
65
+ diff: Partial<T>,
66
+ config?: CrudConfig,
67
+ opts?: CrudOptions,
68
+ ): Promise<T>;
69
+ delete(id: string | number, config?: CrudConfig): Promise<void>;
70
+ options(config?: CrudConfig): Promise<ResourceMetadata>;
71
+ updateOrCreate(
72
+ data: Partial<T> & { id?: string | number },
73
+ config?: CrudConfig,
74
+ opts?: CrudOptions,
75
+ ): Promise<T>;
76
+ updateOrder(
77
+ startId: string | number,
78
+ endId: string | number,
79
+ config?: CrudConfig,
80
+ ): Promise<void>;
81
+ }
82
+
83
+ export interface Credentials {
84
+ username: string;
85
+ password: string;
86
+ }
87
+
88
+ export interface AuthToken {
89
+ token: string;
90
+ [key: string]: unknown;
91
+ }
92
+
93
+ /**
94
+ * Shape of `runtimeConfig.public.mapoCore` as written by the module setup.
95
+ * All entries are guaranteed by the module `defaults`.
96
+ */
97
+ export interface MapoCoreRuntimeConfig {
98
+ authLoginUrl: string;
99
+ userInfoApi: string;
100
+ logoutUrl: string;
101
+ loginUrl: string;
102
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Helpers to read the backend payload out of a failed `$mapoFetch` call.
3
+ *
4
+ * `ofetch` throws a `FetchError` that exposes the parsed response body as
5
+ * `error.data` (and `error.response._data`) — NOT as `error.response.data`.
6
+ * Reading the wrong path silently yields `undefined`, which turns every
7
+ * backend validation message into a generic "something went wrong".
8
+ * Use these helpers instead of destructuring the error by hand.
9
+ */
10
+
11
+ /** Minimal structural view of an ofetch `FetchError`. */
12
+ interface FetchErrorLike {
13
+ status?: number;
14
+ statusCode?: number;
15
+ data?: unknown;
16
+ response?: { status?: number; _data?: unknown };
17
+ }
18
+
19
+ /**
20
+ * Parsed response body of a failed request, or `undefined` when the request
21
+ * failed before a response was received (network error, abort…).
22
+ *
23
+ * @example
24
+ * try { await crud.create(model) }
25
+ * catch (err) {
26
+ * const data = getErrorData<{ title?: string[] }>(err)
27
+ * errors.value = data ?? {}
28
+ * }
29
+ */
30
+ export function getErrorData<T = Record<string, unknown>>(
31
+ error: unknown,
32
+ ): T | undefined {
33
+ const e = error as FetchErrorLike | null | undefined;
34
+ return (e?.data ?? e?.response?._data) as T | undefined;
35
+ }
36
+
37
+ /** HTTP status of a failed request, or `0` when no response was received. */
38
+ export function getErrorStatus(error: unknown): number {
39
+ const e = error as FetchErrorLike | null | undefined;
40
+ return e?.status ?? e?.statusCode ?? e?.response?.status ?? 0;
41
+ }
42
+
43
+ /**
44
+ * `detail` message returned by the backend (DRF convention), when present.
45
+ * Falls back to `undefined` so callers can substitute a translated default.
46
+ */
47
+ export function getErrorDetail(error: unknown): string | undefined {
48
+ const data = getErrorData<{ detail?: unknown }>(error);
49
+ return typeof data?.detail === "string" ? data.detail : undefined;
50
+ }
@@ -0,0 +1,41 @@
1
+ import { useNuxtApp } from "nuxt/app";
2
+ import type { $Fetch } from "ofetch";
3
+ import type { ComputedRef } from "vue";
4
+
5
+ export interface UseMapoFetchReturn {
6
+ /** The auth-aware `$mapoFetch` instance (same one provided by the plugin). */
7
+ fetch: $Fetch;
8
+ /**
9
+ * `true` while at least one `$mapoFetch` request is in flight — globally,
10
+ * across the entire app. Incremented by the plugin-level `onRequest` hook
11
+ * and decremented by `onResponse` / `onResponseError`, so it stays accurate
12
+ * even for raw `useNuxtApp().$mapoFetch` calls outside this composable.
13
+ */
14
+ loading: ComputedRef<boolean>;
15
+ }
16
+
17
+ /**
18
+ * Returns the global `$mapoFetch` instance together with a centralized
19
+ * `loading` indicator that tracks **all** in-flight `$mapoFetch` requests,
20
+ * not just the ones made through this composable.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const { fetch, loading } = useMapoFetch()
25
+ * await fetch('/api/articles/', { method: 'POST', body: payload })
26
+ * ```
27
+ *
28
+ * ```vue
29
+ * <UButton :loading="loading" @click="submit">Save</UButton>
30
+ * ```
31
+ */
32
+ export function useMapoFetch(): UseMapoFetchReturn {
33
+ const nuxt = useNuxtApp() as unknown as {
34
+ $mapoFetch: $Fetch;
35
+ $mapoFetchLoading: ComputedRef<boolean>;
36
+ };
37
+ return {
38
+ fetch: nuxt.$mapoFetch,
39
+ loading: nuxt.$mapoFetchLoading,
40
+ };
41
+ }
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
1
+ export interface MapoOptions {
2
+ authLoginUrl?: string;
3
+ userInfoApi?: string;
4
+ logoutUrl?: string;
5
+ loginUrl?: string;
6
+ }
7
+
8
+ export const MAPO_DEFAULTS = {
9
+ authLoginUrl: "/api/auth/login",
10
+ userInfoApi: "/api/profiles/me/",
11
+ logoutUrl: "/api/auth/logout",
12
+ loginUrl: "/login",
13
+ } satisfies Required<MapoOptions>;
package/CHANGELOG.md DELETED
@@ -1,248 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [1.0.0](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.60...v1.0.0) (2026-07-02)
7
-
8
- **Note:** Version bump only for package @mapomodule/core
9
-
10
-
11
-
12
-
13
-
14
- # [1.0.0-alpha.49](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.48...v1.0.0-alpha.49) (2023-07-27)
15
-
16
- **Note:** Version bump only for package @mapomodule/core
17
-
18
-
19
-
20
-
21
-
22
- # [1.0.0-alpha.45](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.44...v1.0.0-alpha.45) (2023-06-10)
23
-
24
- **Note:** Version bump only for package @mapomodule/core
25
-
26
-
27
-
28
-
29
-
30
- # [1.0.0-alpha.44](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.43...v1.0.0-alpha.44) (2023-06-10)
31
-
32
- **Note:** Version bump only for package @mapomodule/core
33
-
34
-
35
-
36
-
37
-
38
- # [1.0.0-alpha.43](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.42...v1.0.0-alpha.43) (2023-02-02)
39
-
40
- **Note:** Version bump only for package @mapomodule/core
41
-
42
-
43
-
44
-
45
-
46
- # [1.0.0-alpha.41](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.40...v1.0.0-alpha.41) (2022-12-20)
47
-
48
-
49
- ### Features
50
-
51
- * handle all_permissions prop in user ([14d4252](https://github.com/lotrekagency/mapo/commit/14d425215434e29f82093fc96e53b172bf247b8f))
52
-
53
-
54
-
55
-
56
-
57
- # [1.0.0-alpha.40](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.39...v1.0.0-alpha.40) (2022-12-20)
58
-
59
- **Note:** Version bump only for package @mapomodule/core
60
-
61
-
62
-
63
-
64
-
65
- # [1.0.0-alpha.39](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.38...v1.0.0-alpha.39) (2022-12-03)
66
-
67
-
68
- ### Features
69
-
70
- * give the option to rewrite form fields components defaults in nuxt.config.js ([c4e76b1](https://github.com/lotrekagency/mapo/commit/c4e76b153b145cc670ef988e9501e1a8fbc0005e))
71
-
72
-
73
-
74
-
75
-
76
- # [1.0.0-alpha.34](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.33...v1.0.0-alpha.34) (2022-11-11)
77
-
78
-
79
- ### Features
80
-
81
- * default upload in multipart autodiscover ([b153307](https://github.com/lotrekagency/mapo/commit/b15330725a64a0931d2de49929a01e3a7319b382))
82
-
83
-
84
-
85
-
86
-
87
- # [1.0.0-alpha.31](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.30...v1.0.0-alpha.31) (2022-09-14)
88
-
89
-
90
- ### Bug Fixes
91
-
92
- * **interceptor:** remove token injection for axios requests ([59b2f5c](https://github.com/lotrekagency/mapo/commit/59b2f5cb3dfd0becd78df02f30bc32967643e276))
93
- * **middleware:** fix auth middleware to correclty redirect based on router base ([1d49cd7](https://github.com/lotrekagency/mapo/commit/1d49cd72e141888ef7aae91ac0ddb13f8d0fce7a))
94
-
95
-
96
-
97
-
98
-
99
- # [1.0.0-alpha.30](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.29...v1.0.0-alpha.30) (2022-09-13)
100
-
101
- **Note:** Version bump only for package @mapomodule/core
102
-
103
-
104
-
105
-
106
-
107
- # [1.0.0-alpha.27](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.26...v1.0.0-alpha.27) (2022-08-25)
108
-
109
-
110
- ### Bug Fixes
111
-
112
- * remove unused options plugin ([45004bb](https://github.com/lotrekagency/mapo/commit/45004bb158267c7e2f7795c1d12cf568f9d7ded2))
113
-
114
-
115
-
116
-
117
-
118
- # [1.0.0-alpha.23](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.22...v1.0.0-alpha.23) (2022-05-04)
119
-
120
- **Note:** Version bump only for package @mapomodule/core
121
-
122
-
123
-
124
-
125
-
126
- # [1.0.0-alpha.22](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.21...v1.0.0-alpha.22) (2022-05-01)
127
-
128
- **Note:** Version bump only for package @mapomodule/core
129
-
130
-
131
-
132
-
133
-
134
- # [1.0.0-alpha.19](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.18...v1.0.0-alpha.19) (2022-04-06)
135
-
136
-
137
- ### Bug Fixes
138
-
139
- * fix logout loop ([3177cca](https://github.com/lotrekagency/mapo/commit/3177ccaf4be6151feec379c4241f8784b79d4361))
140
-
141
-
142
-
143
-
144
-
145
- # [1.0.0-alpha.18](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.17...v1.0.0-alpha.18) (2022-04-04)
146
-
147
-
148
- ### Bug Fixes
149
-
150
- * fix core interceptor syntax ([c546a48](https://github.com/lotrekagency/mapo/commit/c546a48f22bf689d4b679aaab82b2b9ed62f26cc))
151
-
152
-
153
-
154
-
155
-
156
- # [1.0.0-alpha.17](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.16...v1.0.0-alpha.17) (2022-04-03)
157
-
158
-
159
- ### Bug Fixes
160
-
161
- * various fixes to auth loops ([58cdb58](https://github.com/lotrekagency/mapo/commit/58cdb586e88df8e595876ba4dd4d4cc11865f7e3))
162
-
163
-
164
-
165
-
166
-
167
- # [1.0.0-alpha.16](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.15...v1.0.0-alpha.16) (2022-04-03)
168
-
169
-
170
- ### Features
171
-
172
- * Added mapo integrations module! 🎉 ([76d2c80](https://github.com/lotrekagency/mapo/commit/76d2c805245b4cf49a33696339da52e4c17f4053))
173
- * added mapo options to mapo helper ([38dcbf2](https://github.com/lotrekagency/mapo/commit/38dcbf28d286eb02c2a6785a883a14edaa0837b1))
174
-
175
-
176
- ### BREAKING CHANGES
177
-
178
- * This change removes all the camomilla cms references moving the compatibility layer in a detached package [mapo-integrations-camomilla](https://github.com/lotrekagency/mapo-integrations-camomilla). The guidelines to make mapo work with camomilla will be provided in the package readme.
179
-
180
-
181
-
182
-
183
-
184
- # [1.0.0-alpha.15](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.14...v1.0.0-alpha.15) (2022-03-11)
185
-
186
-
187
- ### Features
188
-
189
- * **ordering:** added sortablejs to drag and reorder list ([eb8bf21](https://github.com/lotrekagency/mapo/commit/eb8bf21c3178c3ad62db5aa7c06c0562e944dea6))
190
-
191
-
192
-
193
-
194
-
195
- # [1.0.0-alpha.13](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.12...v1.0.0-alpha.13) (2022-03-01)
196
-
197
-
198
- ### Features
199
-
200
- * added snack message in the requst interceptor ([acf9cd1](https://github.com/lotrekagency/mapo/commit/acf9cd1efbabc13eb99af7f4bfe0dcf096112ec0))
201
-
202
-
203
-
204
-
205
-
206
- # [1.0.0-alpha.10](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2022-02-11)
207
-
208
-
209
- ### Bug Fixes
210
-
211
- * fix crud requests without multipart policy ([5875833](https://github.com/lotrekagency/mapo/commit/5875833209872a2609b653a089fff80c447b14e9))
212
-
213
-
214
- ### Features
215
-
216
- * **core:** Completely rewritten multipart capabilities, now the crud helper autodiscovers whet to use a multipart request. ([0a6546c](https://github.com/lotrekagency/mapo/commit/0a6546c9adeaf1fcf57a88105101e476b8b786dc))
217
-
218
-
219
-
220
-
221
-
222
- # [1.0.0-alpha.9](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2022-02-08)
223
-
224
- **Note:** Version bump only for package @mapomodule/core
225
-
226
-
227
-
228
-
229
-
230
- # [1.0.0-alpha.8](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2022-01-23)
231
-
232
-
233
- ### Bug Fixes
234
-
235
- * **auth:** logout user only on 401 ([818f3d5](https://github.com/lotrekagency/mapo/commit/818f3d5ff315635438ac9bc9566a1b2fd2c5cf03))
236
- * **permission:** fix bad store initialization on ssr ([f075824](https://github.com/lotrekagency/mapo/commit/f075824561d6a71ce07ecbba70e994102abd623b))
237
- * **permissions:** add route permissions with routename instead on path ([16ff6ee](https://github.com/lotrekagency/mapo/commit/16ff6eee5e3a8ddbf9e7aea1ba05e8a88fb43932))
238
-
239
-
240
-
241
-
242
-
243
- # [1.0.0-alpha.6](https://github.com/lotrekagency/mapo/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2021-12-26)
244
-
245
-
246
- ### Features
247
-
248
- * **core:** reject promise for crud methods if no endpoint was passed during configuration ([bb8d447](https://github.com/lotrekagency/mapo/commit/bb8d4474efe41af5d7f38dbcd47731133d6ba154))
package/api/crud.js DELETED
@@ -1,141 +0,0 @@
1
- const transformRequestInMultipart = require('@mapomodule/core/api/multipart')
2
- const trimslashes = (str) => (str || "").replace(/^\/|\/$/g, '')
3
- const preparePayload = (payload, options) => {
4
- const { multipart } = (options || {})
5
- if (!(payload instanceof FormData) && multipart !== 'disable') {
6
- payload = transformRequestInMultipart(payload, multipart || 'auto');
7
- }
8
- return payload
9
- }
10
- const endpointError = "This crud is badly configured. No endpoint was passed"
11
-
12
- /**
13
- * This function generates a fully functional crud helper given the endpoint.
14
- *
15
- * @alias $api.crud
16
- * @param {string} endpoint This is the endpoint that will be used for all the methods exposed by this function.
17
- * @param {external:AxiosRequestConfig} [higherConf={}] This is an axios configuration object that allows you to inject all the additional options you want.
18
- *
19
- */
20
- const createRepository = ($axios) => (endpoint, higherConf = {}) => ({
21
- /**
22
- * This makes a GET http call to the crud endpoint. Returns as a promise the server response.
23
- * @alias $api.crud.list
24
- * @param {external:AxiosRequestConfig} [config]
25
- * @returns {Promise<external:AxiosResponse>}
26
- */
27
- list(config) {
28
- const func = $axios.$get(`/${trimslashes(endpoint)}/`, { ...higherConf, ...config })
29
- return endpoint !== null ? func : Promise.reject(endpointError)
30
- },
31
-
32
- /**
33
- * This makes a POST http call with the data specified in the payload to the crud endpoint. Returns as a promise the server response.
34
- * @alias $api.crud.create
35
- * @param {Object} payload The payload containing the data that we want to send.
36
- * @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
37
- * @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
38
- * @returns {Promise<external:AxiosResponse>}
39
- */
40
- create(payload, config, options) {
41
-
42
- const func = $axios.$post(`/${trimslashes(endpoint)}/`, preparePayload(payload, options), { ...higherConf, ...config })
43
- return endpoint !== null ? func : Promise.reject(endpointError)
44
- },
45
-
46
- /**
47
- * This makes a GET http call to the crud endpoint slash the given id. Returns as a promise the server response.
48
- * @alias $api.crud.detail
49
- * @param {String} id The id of the data we want to get from the server.
50
- * @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
51
- * @returns {Promise<external:AxiosResponse>}
52
- */
53
- detail(id, config) {
54
- const func = $axios.$get(`/${trimslashes(endpoint)}/${id}/`, { ...higherConf, ...config })
55
- return endpoint !== null ? func : Promise.reject(endpointError)
56
- },
57
-
58
- /**
59
- * This shortcut calls the update method or the create method depending on the presence of the id field in the payload.
60
- * @alias $api.crud.updateOrCreate
61
- * @param {Object} payload The payload containing the data that we want to send.
62
- * @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
63
- * @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
64
- * @returns {Promise<external:AxiosResponse>}
65
- */
66
- updateOrCreate(payload, config, options) {
67
- const func = payload.id ? this.update(payload.id, payload, { ...higherConf, ...config }, options) : this.create(payload, { ...higherConf, ...config }, options)
68
- return endpoint !== null ? func : Promise.reject(endpointError)
69
- },
70
-
71
- /**
72
- * This makes a PUT http call to the crud endpoint slash the given id, sending the payload. Returns as a promise the server response.
73
- * @alias $api.crud.update
74
- * @param {String} id The id of the data we want to update.
75
- * @param {Object} payload The payload containing the data that we want to send.
76
- * @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
77
- * @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
78
- * @returns {Promise<external:AxiosResponse>}
79
- */
80
- update(id, payload, config, options) {
81
- const func = $axios.$put(`/${trimslashes(endpoint)}/${id}/`, preparePayload(payload, options), { ...higherConf, ...config })
82
- return endpoint !== null ? func : Promise.reject(endpointError)
83
- },
84
-
85
- /**
86
- * This makes a PATCH http call to the crud endpoint slash the given id, sending the payload. Returns as a promise the server response.
87
- * @alias $api.crud.partialUpdate
88
- * @param {String} id The id of the data we want to partially update.
89
- * @param {Object} payload The payload containing the data that we want to send.
90
- * @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
91
- * @param {MapoRequestConfig} options Additional option configuration. Here you can configure some mapo reserved options. Like the multipart autodiscover politic.
92
- * @returns {Promise<external:AxiosResponse>}
93
- */
94
- partialUpdate(id, payload, config, options) {
95
- const func = $axios.$patch(`/${trimslashes(endpoint)}/${id}/`, preparePayload(payload, options), { ...higherConf, ...config })
96
- return endpoint !== null ? func : Promise.reject(endpointError)
97
- },
98
- /**
99
- * This makes a DELETE http call to the crud endpoint slash the given id. Returns as a promise the server response.
100
- * @alias $api.crud.delete
101
- * @param {String} id The id of the data we want to delete from the server.
102
- * @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
103
- * @returns {Promise<external:AxiosResponse>}
104
- */
105
- delete(id, config) {
106
- const func = $axios.$delete(`/${trimslashes(endpoint)}/${id}/`, { ...higherConf, ...config })
107
- return endpoint !== null ? func : Promise.reject(endpointError)
108
- },
109
- /**
110
- * This makes a POST http call to the crud endpoint slash update_order. Returns as a promise the server response.
111
- * Use this endpoint to change the order of the items in the list.
112
- * @alias $api.crud.update_order
113
- * @param {String} startId The id of the item we want to move in the list.
114
- * @param {String} endId The id of the item in the position where we want to move.
115
- * @param {external:AxiosRequestConfig} [config] This is a further axios configuration object that allows you to override the options previously setted.
116
- * @returns {Promise<external:AxiosResponse>}
117
- */
118
- update_order(startId, endId, config) {
119
- const func = $axios.$post(`/${trimslashes(endpoint)}/update_order/`, { startId, endId }, { ...higherConf, ...config })
120
- return endpoint !== null ? func : Promise.reject(endpointError)
121
- },
122
-
123
-
124
- })
125
- /**
126
- * @external AxiosResponse
127
- * @see https://axios-http.com/docs/res_schema
128
- */
129
-
130
- /**
131
- * @external AxiosRequestConfig
132
- * @see https://axios-http.com/docs/req_config
133
- */
134
-
135
- /**
136
- * Additional option configuration. Here you can configure some mapo reserved options.
137
- * @typedef {MapoRequestConfig} MapoRequestConfig
138
- * @property {string} multipart - Set the multipart politic. Accepts `'auto'|'force|'disable'`. If auto is set the request is transformed in multipart if any file is in the payload. If set to force the request is transformed in multipart no matter if files are found. If set to `'disable'` the request is never transformed in multipart.
139
- */
140
-
141
- module.exports = createRepository