@monorise/react 1.0.1 → 1.0.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.
Files changed (38) hide show
  1. package/dist/actions/config.action.d.ts +10 -0
  2. package/dist/actions/config.action.d.ts.map +1 -0
  3. package/dist/actions/config.action.js +31 -0
  4. package/dist/actions/config.action.js.map +1 -0
  5. package/dist/actions/core.action.d.ts.map +1 -1
  6. package/dist/actions/core.action.js +2 -3
  7. package/dist/actions/core.action.js.map +1 -1
  8. package/dist/index.d.ts +388 -24
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +12 -8
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.jsx +48 -0
  13. package/dist/index.jsx.map +1 -0
  14. package/dist/services/core.service.d.ts +2 -1
  15. package/dist/services/core.service.d.ts.map +1 -1
  16. package/dist/services/core.service.js +9 -10
  17. package/dist/services/core.service.js.map +1 -1
  18. package/dist/store/monorise.store.d.ts +9 -3
  19. package/dist/store/monorise.store.d.ts.map +1 -1
  20. package/dist/store/monorise.store.js +3 -11
  21. package/dist/store/monorise.store.js.map +1 -1
  22. package/index.ts +18 -4
  23. package/package.json +6 -4
  24. package/actions/app.action.ts +0 -218
  25. package/actions/auth.action.ts +0 -71
  26. package/actions/core.action.ts +0 -878
  27. package/lib/api.tsx +0 -132
  28. package/lib/config.ts +0 -36
  29. package/lib/constant.ts +0 -1
  30. package/lib/entity.ts +0 -81
  31. package/lib/utils.ts +0 -12
  32. package/services/auth.service.ts +0 -59
  33. package/services/core.service.ts +0 -416
  34. package/services/filestore.service.ts +0 -136
  35. package/store/monorise.store.ts +0 -111
  36. package/types/api.type.ts +0 -57
  37. package/types/axios.type.ts +0 -14
  38. package/types/monorise.type.ts +0 -8
package/lib/api.tsx DELETED
@@ -1,132 +0,0 @@
1
- import { IconCircleCheckFilled } from '@tabler/icons-react';
2
- import request, {
3
- type AxiosError,
4
- type AxiosRequestConfig,
5
- type AxiosResponse,
6
- } from 'axios';
7
- import { toast } from 'sonner';
8
- import type { AppActions } from '../actions/app.action';
9
- import type { AuthActions } from '../actions/auth.action';
10
- import type { MonoriseStore } from '../store/monorise.store';
11
- import type { ApplicationRequestError } from '../types/api.type';
12
-
13
- const initAxiosInterceptor = (store: MonoriseStore, appActions: AppActions) => {
14
- const { startLoading } = appActions;
15
-
16
- const axiosInstance = request.create();
17
-
18
- function makeRequest<T = any, R = AxiosResponse<T, any>, D = any>(
19
- url: string,
20
- config: AxiosRequestConfig<D>,
21
- data?: D,
22
- ): Promise<R> {
23
- const { requestKey, isInterruptive = false, feedback } = config;
24
- const { ongoingRequests } = store.getState().app;
25
-
26
- if (ongoingRequests.has(requestKey)) {
27
- return ongoingRequests.get(requestKey) as Promise<R>;
28
- }
29
-
30
- const promise = axiosInstance.request<T, R, D>({
31
- ...config,
32
- url,
33
- data,
34
- headers: {
35
- 'Mr-Interruptive': String(isInterruptive),
36
- },
37
- });
38
- startLoading({
39
- requestKey,
40
- isInterruptive,
41
- message: feedback?.loading,
42
- request: promise,
43
- });
44
-
45
- return promise;
46
- }
47
-
48
- const axios = {
49
- ...axiosInstance,
50
- post: <T = any, R = AxiosResponse<T, any>, D = any>(
51
- url: string,
52
- data: D,
53
- config: AxiosRequestConfig<D>,
54
- ): Promise<R> => makeRequest(url, { ...config, method: 'POST' }, data),
55
- put: <T = any, R = AxiosResponse<T, any>, D = any>(
56
- url: string,
57
- data: D,
58
- config: AxiosRequestConfig<D>,
59
- ): Promise<R> => makeRequest(url, { ...config, method: 'PUT' }, data),
60
- patch: <T = any, R = AxiosResponse<T, any>, D = any>(
61
- url: string,
62
- data: D,
63
- config: AxiosRequestConfig<D>,
64
- ): Promise<R> => makeRequest(url, { ...config, method: 'PATCH' }, data),
65
- delete: <T = any, R = AxiosResponse<T, any>, D = any>(
66
- url: string,
67
- config: AxiosRequestConfig<D>,
68
- ): Promise<R> => makeRequest(url, { ...config, method: 'DELETE' }),
69
- get: <T = any, R = AxiosResponse<T, any>, D = any>(
70
- url: string,
71
- config: AxiosRequestConfig<D>,
72
- ): Promise<R> => makeRequest(url, { ...config, method: 'GET' }),
73
- };
74
-
75
- return axios;
76
- };
77
-
78
- const injectAxiosInterceptor = (
79
- appActions: AppActions,
80
- authActions: AuthActions,
81
- axios: ReturnType<typeof initAxiosInterceptor>,
82
- ) => {
83
- const { endLoading, setError, clearError } = appActions;
84
- const { setIsUnauthorized } = authActions;
85
-
86
- const unknownError: ApplicationRequestError = {
87
- code: 'UNKNOWN_EXCEPTION',
88
- message: "Ops, something doesn't seems right",
89
- };
90
-
91
- axios.interceptors.response.use(
92
- (response) => {
93
- const { requestKey, isInterruptive, feedback } = response.config;
94
- endLoading({ requestKey, isInterruptive });
95
- clearError(requestKey);
96
-
97
- if (!feedback?.success) {
98
- return Promise.resolve(response);
99
- }
100
-
101
- switch (typeof feedback.success) {
102
- case 'function':
103
- toast(feedback.success(response.data));
104
- break;
105
- case 'string':
106
- toast(
107
- <>
108
- <IconCircleCheckFilled color='rgb(34 197 94)' />
109
- {feedback.success}
110
- </>,
111
- );
112
- break;
113
- case 'boolean':
114
- toast('Request success');
115
- break;
116
- }
117
-
118
- return Promise.resolve(response);
119
- },
120
- (error: AxiosError<ApplicationRequestError>) => {
121
- const { requestKey, isInterruptive } = error.config as AxiosRequestConfig;
122
- endLoading({ requestKey, isInterruptive });
123
- setError({ requestKey, error: error.response?.data || unknownError });
124
- if (error.response?.status === 401) {
125
- setIsUnauthorized(true);
126
- }
127
- return Promise.reject(error);
128
- },
129
- );
130
- };
131
-
132
- export { initAxiosInterceptor, injectAxiosInterceptor };
package/lib/config.ts DELETED
@@ -1,36 +0,0 @@
1
- // src/configLoader.ts
2
- import type { MonoriseConfig } from '@monorise/base';
3
-
4
- let config: MonoriseConfig | null = null;
5
-
6
- export async function loadConfig(configPath: string): Promise<MonoriseConfig> {
7
- try {
8
- const module = await import(configPath);
9
- config = module.default as MonoriseConfig;
10
-
11
- if (!config.configPath) {
12
- throw new Error(
13
- 'Configuration file must export a `customPath` property.',
14
- );
15
- }
16
-
17
- return config;
18
- } catch (error) {
19
- throw new Error(
20
- `Failed to load configuration file at ${configPath}: ${(error as Error).message}`,
21
- );
22
- }
23
- }
24
-
25
- export function getConfig(): MonoriseConfig {
26
- if (!config) {
27
- throw new Error(
28
- 'Configuration has not been loaded. Call `loadConfig()` first.',
29
- );
30
- }
31
- return config;
32
- }
33
-
34
- export async function getEntityConfig() {
35
- return await import(getConfig().configPath);
36
- }
package/lib/constant.ts DELETED
@@ -1 +0,0 @@
1
- export const HTML_TAG_REGEX = /<\/?("[^"]*"|'[^']*'|[^>])*(>|$)/g;
package/lib/entity.ts DELETED
@@ -1,81 +0,0 @@
1
- import type {
2
- CreatedEntity,
3
- Entity,
4
- EntitySchemaMap,
5
- Mutual,
6
- MutualData,
7
- } from '@monorise/base';
8
-
9
- export const constructLocal = (
10
- entityType: Entity,
11
- entityId: string,
12
- data: any,
13
- ): CreatedEntity<Entity> => {
14
- return {
15
- entityType: entityType as unknown as string,
16
- entityId,
17
- data,
18
- createdAt: new Date().toISOString(),
19
- updatedAt: new Date().toISOString(),
20
- };
21
- };
22
-
23
- export const constructMutual = <B extends Entity, T extends Entity>(
24
- byEntityType: B,
25
- byEntityId: string,
26
- entityType: T,
27
- entityId: string,
28
- mutualData: Partial<MutualData<B, T>>,
29
- data: EntitySchemaMap[T],
30
- ): Mutual => {
31
- return {
32
- mutualId: `${byEntityId}-${entityId}`,
33
- byEntityType,
34
- byEntityId,
35
- entityType,
36
- entityId,
37
- mutualData,
38
- data,
39
- createdAt: new Date().toISOString(),
40
- updatedAt: new Date().toISOString(),
41
- mutualUpdatedAt: new Date().toISOString(),
42
- };
43
- };
44
-
45
- export const flipMutual = (mutual: Mutual): Mutual => {
46
- return {
47
- ...mutual,
48
- entityId: mutual.byEntityId,
49
- entityType: mutual.byEntityType,
50
- byEntityId: mutual.entityId,
51
- byEntityType: mutual.entityType,
52
- };
53
- };
54
-
55
- export const byMutualIndex = (a: Mutual<any, any>, b: Mutual<any, any>) => {
56
- return a.mutualData.index - b.mutualData.index;
57
- };
58
-
59
- export const byEntityId = (a: CreatedEntity<any>, b: CreatedEntity<any>) => {
60
- if (b.entityId < a.entityId) return -1;
61
- return 1;
62
- };
63
-
64
- export const constructOrderByIndex = (mutuals: Mutual<any, any>[]) => {
65
- return mutuals.sort(byMutualIndex).map((mutual) => mutual.entityId);
66
- };
67
-
68
- export const injectFields = <T extends Entity>(
69
- entity: CreatedEntity<T> | undefined,
70
- fields: Record<string, any>,
71
- ): CreatedEntity<T> | undefined => {
72
- return entity
73
- ? {
74
- ...entity,
75
- data: {
76
- ...entity.data,
77
- ...fields,
78
- },
79
- }
80
- : undefined;
81
- };
package/lib/utils.ts DELETED
@@ -1,12 +0,0 @@
1
- export const convertToMap = <T extends Record<string, any>>(
2
- data: T[],
3
- mapKey: string,
4
- ) => {
5
- const map = new Map();
6
-
7
- for (const i in data) {
8
- map.set(data[i][mapKey], data[i]);
9
- }
10
-
11
- return map;
12
- };
@@ -1,59 +0,0 @@
1
- import type { Entity } from '@monorise/base';
2
- import type { AxiosInterceptor } from '../types/api.type';
3
-
4
- type LoginPayload = {
5
- email: string;
6
- };
7
-
8
- type Options = {
9
- apiBaseUrl?: string;
10
- };
11
-
12
- const initAuthService = (axios: AxiosInterceptor) => {
13
- let options: Options = {};
14
- const { apiBaseUrl = '/api/auth' } = options;
15
-
16
- const requestLoginMagicLink = (entityType: Entity, payload: LoginPayload) => {
17
- return axios.post(
18
- `${apiBaseUrl}/${entityType}`,
19
- {
20
- body: { ...payload },
21
- },
22
- {
23
- requestKey: `auth/${entityType}/request-login`,
24
- isInterruptive: true,
25
- feedback: {
26
- loading: 'Requesting login link',
27
- },
28
- },
29
- );
30
- };
31
-
32
- const getSessionProfile = <T extends Record<string, unknown>>() =>
33
- axios.get<
34
- T & {
35
- displayName: string;
36
- email: string;
37
- accountId: string;
38
- }
39
- >('/session', {
40
- requestKey: 'auth/session',
41
- });
42
-
43
- const setOptions = (opts: Options) => {
44
- options = {
45
- ...options,
46
- ...opts,
47
- };
48
- };
49
-
50
- return {
51
- requestLoginMagicLink,
52
- getSessionProfile,
53
- setOptions,
54
- };
55
- };
56
-
57
- export default initAuthService;
58
-
59
- export type AuthService = ReturnType<typeof initAuthService>;