@egdesk/next-api-plugin 1.5.3 → 1.5.5

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.
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * Generate API wrapper for handling basePath in client-side fetch calls
3
3
  *
4
- * Creates src/lib/api.ts that automatically prepends NEXT_PUBLIC_EGDESK_BASE_PATH
5
- * to relative URLs, solving the Next.js basePath limitation with client-side fetch.
4
+ * Creates lib/api.ts (or src/lib/api.ts) that re-exports apiFetch from egdesk-helpers.ts
5
+ * so apps can use either import path.
6
6
  */
7
7
  /**
8
- * Generate src/lib/api.ts file for basePath-aware fetch wrapper
8
+ * Generate lib/api.ts file that re-exports basePath-aware fetch from egdesk-helpers
9
9
  */
10
10
  export declare function generateApiWrapper(projectPath: string): void;
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * Generate API wrapper for handling basePath in client-side fetch calls
4
4
  *
5
- * Creates src/lib/api.ts that automatically prepends NEXT_PUBLIC_EGDESK_BASE_PATH
6
- * to relative URLs, solving the Next.js basePath limitation with client-side fetch.
5
+ * Creates lib/api.ts (or src/lib/api.ts) that re-exports apiFetch from egdesk-helpers.ts
6
+ * so apps can use either import path.
7
7
  */
8
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
9
  if (k2 === undefined) k2 = k;
@@ -66,13 +66,14 @@ function ensureLibDirectory(projectPath) {
66
66
  return libDir;
67
67
  }
68
68
  /**
69
- * Generate src/lib/api.ts file for basePath-aware fetch wrapper
69
+ * Generate lib/api.ts file that re-exports basePath-aware fetch from egdesk-helpers
70
70
  */
71
71
  function generateApiWrapper(projectPath) {
72
72
  const libDir = ensureLibDirectory(projectPath);
73
73
  const apiPath = path.join(libDir, 'api.ts');
74
+ const hasSrc = usesSrcDirectory(projectPath);
75
+ const helpersImport = hasSrc ? '../../egdesk-helpers' : '../egdesk-helpers';
74
76
  console.log(`📝 Generating API wrapper at: ${apiPath}`);
75
- // Check if api.ts already exists
76
77
  if (fs.existsSync(apiPath)) {
77
78
  console.log('⚠️ api.ts already exists - backing up to api.backup.ts');
78
79
  const backupPath = path.join(libDir, 'api.backup.ts');
@@ -81,38 +82,13 @@ function generateApiWrapper(projectPath) {
81
82
  const apiContent = `/**
82
83
  * API Fetch Wrapper for EGDesk Tunneling
83
84
  *
84
- * This wrapper automatically prepends NEXT_PUBLIC_EGDESK_BASE_PATH to relative URLs.
85
- * This is necessary because Next.js basePath does NOT automatically apply to
86
- * client-side fetch() calls - it's a known limitation.
85
+ * Re-exports apiFetch from egdesk-helpers.ts (canonical source).
86
+ * Use apiFetch for client-side /api/* calls — Next.js basePath does not apply to fetch().
87
87
  *
88
88
  * Generated by @egdesk/next-api-plugin
89
89
  */
90
90
 
91
- const isDev = process.env.NODE_ENV === 'development';
92
- const basePath = isDev ? '' : (process.env.NEXT_PUBLIC_EGDESK_BASE_PATH || '');
93
-
94
- /**
95
- * Fetch wrapper that handles basePath for tunneled environments
96
- *
97
- * @example
98
- * // ❌ Wrong - will return 404 in tunneled environment
99
- * fetch('/api/transactions')
100
- *
101
- * @example
102
- * // ✅ Correct - automatically prepends basePath
103
- * apiFetch('/api/transactions')
104
- *
105
- * @param path - The API path (e.g., '/api/transactions')
106
- * @param options - Standard fetch options
107
- */
108
- export async function apiFetch(path: string, options?: RequestInit): Promise<Response> {
109
- // Automatically prepend basePath to relative URLs
110
- const url = path.startsWith('/') && !path.startsWith('//')
111
- ? \`\${basePath}\${path}\`
112
- : path;
113
-
114
- return fetch(url, options);
115
- }
91
+ export { apiFetch, getEgdeskBasePath } from '${helpersImport}';
116
92
  `;
117
93
  fs.writeFileSync(apiPath, apiContent.replace(/\r?\n/g, os.EOL), 'utf-8');
118
94
  console.log(`✅ Generated ${apiPath}`);
@@ -3,6 +3,28 @@
3
3
  *
4
4
  * Creates egdesk-helpers.ts with type-safe helper functions.
5
5
  */
6
+ export interface SchemaTableDefinition {
7
+ tableName: string;
8
+ displayName: string;
9
+ columns: string[];
10
+ }
11
+ /**
12
+ * Format egdesk.schema.ts content — the committed, portable seed schema.
13
+ */
14
+ export declare function formatEgdeskSchemaFileContent(tables: SchemaTableDefinition[]): string;
15
+ /**
16
+ * Write egdesk.schema.ts to the project root.
17
+ */
18
+ export declare function generateSchemaFile(projectPath: string, tables: SchemaTableDefinition[]): void;
19
+ export type EnsureSchemaFileResult = {
20
+ created: boolean;
21
+ source: 'existing' | 'database' | 'template';
22
+ tableCount: number;
23
+ };
24
+ /**
25
+ * Create egdesk.schema.ts only when missing. Never overwrites an existing file.
26
+ */
27
+ export declare function ensureSchemaFile(projectPath: string, tables: SchemaTableDefinition[]): EnsureSchemaFileResult;
6
28
  /**
7
29
  * Generate egdesk-helpers.ts file
8
30
  */