wexts 3.0.0 → 3.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.
@@ -0,0 +1,115 @@
1
+ /**
2
+ * WEXTS Internal SDK
3
+ * Type-safe API client - ZERO URLs needed!
4
+ * Works in both Client and Server Components
5
+ */
6
+
7
+ // HTTP client - uses relative paths only
8
+ async function request<T>(method: string, path: string, data?: any): Promise<T> {
9
+ const url = `/api${path}`;
10
+
11
+ const options: RequestInit = {
12
+ method,
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ },
16
+ credentials: 'include',
17
+ };
18
+
19
+ if (data) {
20
+ options.body = JSON.stringify(data);
21
+ }
22
+
23
+ const response = await fetch(url, options);
24
+
25
+ if (!response.ok) {
26
+ const error = await response.json().catch(() => ({ message: response.statusText }));
27
+ throw new Error(error.message || 'Request failed');
28
+ }
29
+
30
+ return response.json();
31
+ }
32
+
33
+ // ==========================================
34
+ // TYPE-SAFE API - NO URLs ANYWHERE!
35
+ // ==========================================
36
+
37
+ export const api = {
38
+ /**
39
+ * Authentication API
40
+ */
41
+ auth: {
42
+ /**
43
+ * Register new user
44
+ * @example await api.auth.register({ email, password, name })
45
+ */
46
+ register: (data: { email: string; password: string; name?: string }) =>
47
+ request<{ user: any; access_token: string }>('POST', '/auth/register', data),
48
+
49
+ /**
50
+ * Login user
51
+ * @example await api.auth.login({ email, password })
52
+ */
53
+ login: (data: { email: string; password: string }) =>
54
+ request<{ user: any; access_token: string }>('POST', '/auth/login', data),
55
+
56
+ /**
57
+ * Get current user
58
+ * @example const user = await api.auth.me()
59
+ */
60
+ me: () => request<any>('GET', '/auth/me'),
61
+ },
62
+
63
+ /**
64
+ * Users API
65
+ */
66
+ users: {
67
+ /**
68
+ * Get current user profile
69
+ * @example const profile = await api.users.me()
70
+ */
71
+ me: () => request<any>('GET', '/users/me'),
72
+ },
73
+
74
+ /**
75
+ * Todos API
76
+ */
77
+ todos: {
78
+ /**
79
+ * Get all todos
80
+ * @example const todos = await api.todos.findAll()
81
+ */
82
+ findAll: () => request<any[]>('GET', '/todos'),
83
+
84
+ /**
85
+ * Get single todo
86
+ * @example const todo = await api.todos.findOne('123')
87
+ */
88
+ findOne: (id: string) => request<any>('GET', `/todos/${id}`),
89
+
90
+ /**
91
+ * Create new todo
92
+ * @example await api.todos.create({ title: 'Task', description: 'Do it' })
93
+ */
94
+ create: (data: { title: string; description?: string }) =>
95
+ request<any>('POST', '/todos', data),
96
+
97
+ /**
98
+ * Update todo
99
+ * @example await api.todos.update('123', { completed: true })
100
+ */
101
+ update: (id: string, data: { title?: string; description?: string; completed?: boolean }) =>
102
+ request<any>('PUT', `/todos/${id}`, data),
103
+
104
+ /**
105
+ * Delete todo
106
+ * @example await api.todos.delete('123')
107
+ */
108
+ delete: (id: string) => request<void>('DELETE', `/todos/${id}`),
109
+ },
110
+ };
111
+
112
+ /**
113
+ * Export type-safe API
114
+ */
115
+ export type API = typeof api;
@@ -0,0 +1,11 @@
1
+ [phases.setup]
2
+ nixPacks = ["nodejs-20", "pnpm"]
3
+
4
+ [phases.install]
5
+ cmds = ["pnpm install"]
6
+
7
+ [phases.build]
8
+ cmds = ["pnpm run build"]
9
+
10
+ [start]
11
+ cmd = "pnpm start"
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "wexts-app",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "tsx server.ts",
7
+ "build": "pnpm run build:api && pnpm run build:web && pnpm run build:server",
8
+ "build:api": "cd apps/api && npm run build",
9
+ "build:web": "cd apps/web && npm run build",
10
+ "build:server": "tsc",
11
+ "start": "node dist/server.js",
12
+ "postinstall": "cd apps/api && npx prisma generate"
13
+ },
14
+ "dependencies": {
15
+ "@nestjs/common": "^11.0.0",
16
+ "@nestjs/core": "^11.0.0",
17
+ "@nestjs/platform-express": "^11.1.9",
18
+ "express": "^5.1.0",
19
+ "next": "16.0.0",
20
+ "react": "^19.0.0",
21
+ "react-dom": "^19.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "@types/express": "^4.17.21",
25
+ "@types/node": "^20.0.0",
26
+ "tsx": "^4.7.0",
27
+ "typescript": "^5.3.0"
28
+ },
29
+ "engines": {
30
+ "node": ">=18.0.0"
31
+ }
32
+ }
@@ -0,0 +1,66 @@
1
+ import express from 'express';
2
+ import { NestFactory } from '@nestjs/core';
3
+ import { ExpressAdapter } from '@nestjs/platform-express';
4
+ import next from 'next';
5
+ import path from 'path';
6
+
7
+ const dev = process.env.NODE_ENV !== 'production';
8
+ const port = parseInt(process.env.PORT || '3000', 10);
9
+
10
+ async function bootstrap() {
11
+ console.log('šŸš€ Starting WEXTS Unified Server...\n');
12
+
13
+ // 1. Initialize Next.js
14
+ console.log('šŸ“¦ Loading Next.js...');
15
+ const nextApp = next({
16
+ dev,
17
+ dir: path.join(__dirname, 'apps/web'),
18
+ });
19
+ await nextApp.prepare();
20
+ const nextHandler = nextApp.getRequestHandler();
21
+ console.log('āœ… Next.js ready\n');
22
+
23
+ // 2. Initialize NestJS with Express
24
+ console.log('šŸ“¦ Loading NestJS...');
25
+ const server = express();
26
+
27
+ // Import AppModule dynamically
28
+ const { AppModule } = dev
29
+ ? await import('./apps/api/src/app.module')
30
+ : await import('./apps/api/dist/app.module');
31
+
32
+ const app = await NestFactory.create(
33
+ AppModule,
34
+ new ExpressAdapter(server),
35
+ { cors: true }
36
+ );
37
+
38
+ app.setGlobalPrefix('api');
39
+
40
+ // Smart routing middleware - MUST be before NestJS init
41
+ server.use((req, res, next) => {
42
+ if (req.url.startsWith('/api')) {
43
+ return next(); // Let NestJS handle API routes
44
+ }
45
+ return nextHandler(req, res); // Next.js handles everything else
46
+ });
47
+
48
+ await app.init();
49
+ console.log('āœ… NestJS ready\n');
50
+
51
+ // 3. Start server
52
+ server.listen(port, () => {
53
+ console.log('\nšŸŽ‰ WEXTS Unified Server Running!');
54
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
55
+ console.log(` 🌐 Server: http://localhost:${port}`);
56
+ console.log(` šŸ“± Frontend: All routes except /api/*`);
57
+ console.log(` šŸ”Œ Backend: /api/*`);
58
+ console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
59
+ console.log('✨ Routes are smartly separated!\n');
60
+ });
61
+ }
62
+
63
+ bootstrap().catch((err) => {
64
+ console.error('āŒ Failed to start:', err);
65
+ process.exit(1);
66
+ });
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": [
6
+ "ES2020"
7
+ ],
8
+ "experimentalDecorators": true,
9
+ "emitDecoratorMetadata": true,
10
+ "esModuleInterop": true,
11
+ "allowSyntheticDefaultImports": true,
12
+ "skipLibCheck": true,
13
+ "strict": false,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "moduleResolution": "node",
16
+ "resolveJsonModule": true,
17
+ "outDir": "./dist",
18
+ "declaration": true,
19
+ "declarationMap": true,
20
+ "sourceMap": true
21
+ },
22
+ "include": [
23
+ "server.ts",
24
+ "apps/api/src/**/*"
25
+ ],
26
+ "exclude": [
27
+ "node_modules",
28
+ "dist",
29
+ "apps/web"
30
+ ]
31
+ }