@eventuras/core-nextjs 0.1.3
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 +77 -0
- package/dist/actions/index.d.ts +7 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +28 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/serverAction.d.ts +58 -0
- package/dist/actions/serverAction.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @eventuras/core-nextjs
|
|
2
|
+
|
|
3
|
+
Core Next.js utilities for Eventuras applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Server Action Utilities
|
|
8
|
+
|
|
9
|
+
Standardized types and helpers for Next.js server actions with proper success/error handling.
|
|
10
|
+
|
|
11
|
+
#### Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
'use server';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
ServerActionResult,
|
|
18
|
+
actionSuccess,
|
|
19
|
+
actionError
|
|
20
|
+
} from '@eventuras/core-nextjs/actions';
|
|
21
|
+
|
|
22
|
+
export async function createEvent(
|
|
23
|
+
formData: FormData
|
|
24
|
+
): Promise<ServerActionResult<{ eventId: number }>> {
|
|
25
|
+
try {
|
|
26
|
+
const event = await api.createEvent(...);
|
|
27
|
+
return actionSuccess({ eventId: event.id }, 'Event created successfully!');
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return actionError('Failed to create event', 'CREATE_FAILED');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### Client-side usage
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
'use client';
|
|
38
|
+
|
|
39
|
+
import { useToast } from '@eventuras/ratio-ui/toast';
|
|
40
|
+
import { createEvent } from './actions';
|
|
41
|
+
|
|
42
|
+
export function EventForm() {
|
|
43
|
+
const toast = useToast();
|
|
44
|
+
|
|
45
|
+
const handleSubmit = async (formData: FormData) => {
|
|
46
|
+
const result = await createEvent(formData);
|
|
47
|
+
|
|
48
|
+
if (result.success) {
|
|
49
|
+
toast.success(result.message || 'Success!');
|
|
50
|
+
// Access typed data
|
|
51
|
+
console.log(result.data.eventId);
|
|
52
|
+
} else {
|
|
53
|
+
toast.error(result.error.message);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return <form action={handleSubmit}>...</form>;
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Available Types & Functions
|
|
62
|
+
|
|
63
|
+
- `ServerActionResult<T>` - Discriminated union for success/error
|
|
64
|
+
- `ServerActionSuccess<T>` - Success type with data
|
|
65
|
+
- `ServerActionError` - Error type with message, code, details
|
|
66
|
+
- `actionSuccess(data, message?)` - Helper to create success result
|
|
67
|
+
- `actionError(message, code?, details?)` - Helper to create error result
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Build the library
|
|
73
|
+
pnpm build
|
|
74
|
+
|
|
75
|
+
# Watch mode for development
|
|
76
|
+
pnpm dev
|
|
77
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/actions/serverAction.ts
|
|
2
|
+
/**
|
|
3
|
+
* Helper to create a success result
|
|
4
|
+
*/
|
|
5
|
+
function actionSuccess(data, message) {
|
|
6
|
+
return {
|
|
7
|
+
success: true,
|
|
8
|
+
data,
|
|
9
|
+
message
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Helper to create an error result
|
|
14
|
+
*/
|
|
15
|
+
function actionError(message, code, details) {
|
|
16
|
+
return {
|
|
17
|
+
success: false,
|
|
18
|
+
error: {
|
|
19
|
+
message,
|
|
20
|
+
code,
|
|
21
|
+
details
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { actionError, actionSuccess };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/actions/serverAction.ts"],"sourcesContent":["/**\n * Common types for server actions\n *\n * Provides a standardized interface for server action responses\n * that supports both success and error states with proper typing.\n */\n\n/**\n * Success result from a server action\n */\nexport type ServerActionSuccess<T = void> = {\n success: true;\n data: T;\n message?: string;\n};\n\n/**\n * Error result from a server action\n */\nexport type ServerActionError = {\n success: false;\n error: {\n message: string;\n code?: string;\n details?: unknown;\n };\n};\n\n/**\n * Result type for server actions that can succeed or fail\n *\n * @example\n * // In server action\n * export async function createEvent(formData: FormData): Promise<ServerActionResult<{ eventId: number }>> {\n * try {\n * const event = await api.createEvent(...);\n * return { success: true, data: { eventId: event.id } };\n * } catch (error) {\n * return { success: false, error: { message: 'Failed to create event' } };\n * }\n * }\n *\n * // In client component\n * const result = await createEvent(formData);\n * if (result.success) {\n * toast.success('Event created!');\n * router.push(`/admin/events/${result.data.eventId}`);\n * } else {\n * toast.error(result.error.message);\n * }\n */\nexport type ServerActionResult<T = void> = ServerActionSuccess<T> | ServerActionError;\n\n/**\n * Helper to create a success result\n */\nexport function actionSuccess<T>(data: T, message?: string): ServerActionSuccess<T> {\n return { success: true, data, message };\n}\n\n/**\n * Helper to create an error result\n */\nexport function actionError(message: string, code?: string, details?: unknown): ServerActionError {\n return {\n success: false,\n error: { message, code, details },\n };\n}\n"],"mappings":";;;;AAwDA,SAAgB,cAAiB,MAAS,SAA0C;CAClF,OAAO;EAAE,SAAS;EAAM;EAAM;CAAQ;AACxC;;;;AAKA,SAAgB,YAAY,SAAiB,MAAe,SAAsC;CAChG,OAAO;EACL,SAAS;EACT,OAAO;GAAE;GAAS;GAAM;EAAQ;CAClC;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common types for server actions
|
|
3
|
+
*
|
|
4
|
+
* Provides a standardized interface for server action responses
|
|
5
|
+
* that supports both success and error states with proper typing.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Success result from a server action
|
|
9
|
+
*/
|
|
10
|
+
export type ServerActionSuccess<T = void> = {
|
|
11
|
+
success: true;
|
|
12
|
+
data: T;
|
|
13
|
+
message?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Error result from a server action
|
|
17
|
+
*/
|
|
18
|
+
export type ServerActionError = {
|
|
19
|
+
success: false;
|
|
20
|
+
error: {
|
|
21
|
+
message: string;
|
|
22
|
+
code?: string;
|
|
23
|
+
details?: unknown;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Result type for server actions that can succeed or fail
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // In server action
|
|
31
|
+
* export async function createEvent(formData: FormData): Promise<ServerActionResult<{ eventId: number }>> {
|
|
32
|
+
* try {
|
|
33
|
+
* const event = await api.createEvent(...);
|
|
34
|
+
* return { success: true, data: { eventId: event.id } };
|
|
35
|
+
* } catch (error) {
|
|
36
|
+
* return { success: false, error: { message: 'Failed to create event' } };
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* // In client component
|
|
41
|
+
* const result = await createEvent(formData);
|
|
42
|
+
* if (result.success) {
|
|
43
|
+
* toast.success('Event created!');
|
|
44
|
+
* router.push(`/admin/events/${result.data.eventId}`);
|
|
45
|
+
* } else {
|
|
46
|
+
* toast.error(result.error.message);
|
|
47
|
+
* }
|
|
48
|
+
*/
|
|
49
|
+
export type ServerActionResult<T = void> = ServerActionSuccess<T> | ServerActionError;
|
|
50
|
+
/**
|
|
51
|
+
* Helper to create a success result
|
|
52
|
+
*/
|
|
53
|
+
export declare function actionSuccess<T>(data: T, message?: string): ServerActionSuccess<T>;
|
|
54
|
+
/**
|
|
55
|
+
* Helper to create an error result
|
|
56
|
+
*/
|
|
57
|
+
export declare function actionError(message: string, code?: string, details?: unknown): ServerActionError;
|
|
58
|
+
//# sourceMappingURL=serverAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverAction.d.ts","sourceRoot":"","sources":["../../src/actions/serverAction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,GAAG,IAAI,IAAI;IAC1C,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,CAAC,CAAC;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,IAAI,IAAI,mBAAmB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC;AAEtF;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAElF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAKhG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eventuras/core-nextjs",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Core Next.js utilities for Eventuras",
|
|
5
|
+
"homepage": "https://github.com/losol/origo/tree/main/packages/core-nextjs#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/losol/origo/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/losol/origo.git",
|
|
12
|
+
"directory": "packages/core-nextjs"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
"./actions": {
|
|
18
|
+
"types": "./dist/actions/index.d.ts",
|
|
19
|
+
"import": "./dist/actions/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/react": "^19.2.14",
|
|
27
|
+
"@types/react-dom": "^19.2.3",
|
|
28
|
+
"next": "16.2.9",
|
|
29
|
+
"react": "^19.2.5",
|
|
30
|
+
"vite": "^8.1.0",
|
|
31
|
+
"@eventuras/eslint-config": "1.0.3",
|
|
32
|
+
"@eventuras/typescript-config": "1.0.0",
|
|
33
|
+
"@eventuras/vite-config": "0.2.2"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"next": "^16.0.0",
|
|
37
|
+
"react": "^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "vite build",
|
|
41
|
+
"dev": "vite build --watch",
|
|
42
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
43
|
+
}
|
|
44
|
+
}
|