spfn 0.2.0-beta.6 → 0.2.0-beta.8

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/dist/index.js CHANGED
@@ -521,14 +521,27 @@ import { existsSync as existsSync6 } from "fs";
521
521
  import { join as join6 } from "path";
522
522
  import fse3 from "fs-extra";
523
523
  async function setupApiProxy(cwd, includeAuth) {
524
- const appDir = existsSync6(join6(cwd, "src", "app")) ? join6(cwd, "src", "app") : join6(cwd, "app");
524
+ const srcAppDir = join6(cwd, "src", "app");
525
+ const rootAppDir = join6(cwd, "app");
526
+ let appDir;
527
+ if (existsSync6(srcAppDir)) {
528
+ appDir = srcAppDir;
529
+ } else if (existsSync6(rootAppDir)) {
530
+ appDir = rootAppDir;
531
+ } else {
532
+ logger.error("Next.js app directory not found. Expected src/app or app directory.");
533
+ process.exit(1);
534
+ }
525
535
  const rpcDir = join6(appDir, "api", "rpc", "[routeName]");
526
536
  const rpcRoutePath = join6(rpcDir, "route.ts");
527
- if (!existsSync6(rpcRoutePath)) {
528
- ensureDirSync3(rpcDir);
529
- const authImport = includeAuth ? `import '@spfn/auth/nextjs/api';
537
+ if (existsSync6(rpcRoutePath)) {
538
+ logger.error(`RPC proxy route already exists: ${rpcRoutePath.replace(cwd + "/", "")}`);
539
+ process.exit(1);
540
+ }
541
+ ensureDirSync3(rpcDir);
542
+ const authImport = includeAuth ? `import '@spfn/auth/nextjs/api';
530
543
  ` : "";
531
- const routeContent = `/**
544
+ const routeContent = `/**
532
545
  * SPFN RPC Proxy
533
546
  *
534
547
  * Resolves routeName to actual HTTP method and path from routeMap,
@@ -546,10 +559,9 @@ import { createRpcProxy } from '@spfn/core/nextjs/server';
546
559
 
547
560
  export const { GET, POST } = createRpcProxy({ routeMap });
548
561
  `;
549
- writeFileSync2(rpcRoutePath, routeContent);
550
- const relativePath = rpcRoutePath.replace(cwd + "/", "");
551
- logger.success(`Created ${relativePath} (RPC proxy)`);
552
- }
562
+ writeFileSync2(rpcRoutePath, routeContent);
563
+ const relativePath = rpcRoutePath.replace(cwd + "/", "");
564
+ logger.success(`Created ${relativePath} (RPC proxy)`);
553
565
  }
554
566
  var ensureDirSync3, writeFileSync2;
555
567
  var init_api_proxy = __esm({
@@ -743,7 +755,7 @@ var init_deployment_config = __esm({
743
755
 
744
756
  // src/utils/version.ts
745
757
  function getCliVersion() {
746
- return "0.2.0-beta.6";
758
+ return "0.2.0-beta.8";
747
759
  }
748
760
  function getTagFromVersion(version) {
749
761
  const match = version.match(/-([a-z]+)\./i);
@@ -1,47 +1,80 @@
1
1
  /**
2
2
  * API Client Configuration
3
3
  *
4
- * Type-safe client for accessing server routes
5
- */
6
-
7
- import { createApi } from '@spfn/core/nextjs';
8
- import { errorRegistry } from "@spfn/core/errors";
9
-
10
- import type { AppRouter } from '@/server/router';
11
-
12
- /**
13
- * Pre-configured type-safe API client
14
- *
4
+ * Type-safe client for accessing server routes.
15
5
  * Core HTTP errors are automatically registered.
16
- * Add custom application errors via the errors field if needed.
17
6
  *
18
7
  * @example
19
8
  * ```typescript
20
9
  * import { api } from '@/lib/api-client';
21
10
  *
22
11
  * // Basic call
23
- * const user = await api.getUser
24
- * .call({ id: '123' });
12
+ * const user = await api.getUser.call({ params: { id: '123' } });
25
13
  *
26
- * // Error handling with instanceof
27
- * try {
28
- * await api.someRoute.call();
29
- * } catch (error) {
30
- * if (error instanceof NotFoundError) {
31
- * console.log('Resource not found');
32
- * } else if (error instanceof ValidationError) {
33
- * console.log('Validation failed:', error.fields);
34
- * }
35
- * }
14
+ * // With options
15
+ * const data = await api.getData
16
+ * .headers({ 'X-Custom': 'value' })
17
+ * .fetchOptions({ next: { revalidate: 60 } })
18
+ * .call({ query: { page: 1 } });
36
19
  * ```
37
- *
38
- * Works in:
39
- * - Server Components (no router import needed)
40
- * - Client Components (proxied through /api/actions)
41
- * - Server Actions
42
- * - Route Handlers
43
20
  */
21
+
22
+ import { createApi } from '@spfn/core/nextjs';
23
+ import type { AppRouter } from '@/server/router';
24
+
44
25
  export const api = createApi<AppRouter>({
45
- errorRegistry: errorRegistry,
46
- debug: true
26
+ /**
27
+ * Base URL for RPC endpoint
28
+ * @default '/api/rpc'
29
+ */
30
+ // baseUrl: '/api/rpc',
31
+
32
+ /**
33
+ * Default headers for all requests
34
+ */
35
+ // headers: { 'X-Client': 'web' },
36
+
37
+ /**
38
+ * Request timeout in milliseconds
39
+ * @default 30000
40
+ */
41
+ // timeout: 30000,
42
+
43
+ /**
44
+ * Custom error registry for deserialization
45
+ * Core HTTP errors are automatically included.
46
+ *
47
+ * @example
48
+ * import { authErrorRegistry } from '@myapp/auth/errors';
49
+ * errorRegistry: [authErrorRegistry, MyCustomError]
50
+ */
51
+ // errorRegistry: [],
52
+
53
+ /**
54
+ * Global request interceptor
55
+ *
56
+ * @example
57
+ * onRequest: async (url, init) => {
58
+ * init.headers = { ...init.headers, 'X-Request-Id': crypto.randomUUID() };
59
+ * return init;
60
+ * }
61
+ */
62
+ // onRequest: async (url, init) => init,
63
+
64
+ /**
65
+ * Global response interceptor
66
+ *
67
+ * @example
68
+ * onResponse: async (response, body) => {
69
+ * if (response.status === 401) redirect('/login');
70
+ * return { response, body };
71
+ * }
72
+ */
73
+ // onResponse: async (response, body) => ({ response, body }),
74
+
75
+ /**
76
+ * Enable debug logging
77
+ * @default false
78
+ */
79
+ debug: process.env.NODE_ENV === 'development',
47
80
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spfn",
3
- "version": "0.2.0-beta.6",
3
+ "version": "0.2.0-beta.8",
4
4
  "description": "Superfunction CLI - Add SPFN to your Next.js project",
5
5
  "type": "module",
6
6
  "bin": {
@@ -67,7 +67,7 @@
67
67
  "postgres": "^3.4.0",
68
68
  "prompts": "^2.4.2",
69
69
  "tsup": "^8.5.0",
70
- "@spfn/core": "0.2.0-beta.8"
70
+ "@spfn/core": "0.2.0-beta.12"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@types/fs-extra": "^11.0.4",