@eldrin-project/eldrin-app-core 0.0.1
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/LICENSE +21 -0
- package/README.md +248 -0
- package/dist/cli/release.d.ts +35 -0
- package/dist/cli/release.js +592 -0
- package/dist/cli/release.js.map +1 -0
- package/dist/cli/submit.d.ts +37 -0
- package/dist/cli/submit.js +261 -0
- package/dist/cli/submit.js.map +1 -0
- package/dist/index.cjs +582 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +485 -0
- package/dist/index.d.ts +485 -0
- package/dist/index.js +562 -0
- package/dist/index.js.map +1 -0
- package/dist/vite.cjs +91 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +41 -0
- package/dist/vite.d.ts +41 -0
- package/dist/vite.js +89 -0
- package/dist/vite.js.map +1 -0
- package/package.json +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Eldrin Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# @eldrin-project/eldrin-app-core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@eldrin-project/eldrin-app-core)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
Standard library for building Eldrin marketplace apps. Provides database migrations, React hooks for D1 database access, single-spa lifecycle management, and CLI tools for releasing to the Eldrin marketplace.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Zero-config migrations** - SQL migrations run automatically during app bootstrap
|
|
12
|
+
- **Type-safe database access** - React hooks with full TypeScript support
|
|
13
|
+
- **Single-spa compatible** - Seamless integration with micro-frontend architecture
|
|
14
|
+
- **Cloudflare Workers ready** - Built for D1 databases and Workers runtime
|
|
15
|
+
- **CLI tools included** - Release and submit apps to the Eldrin marketplace
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @eldrin-project/eldrin-app-core
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### 1. Create your app entry point
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// src/index.tsx
|
|
29
|
+
import { createApp } from '@eldrin-project/eldrin-app-core';
|
|
30
|
+
import migrations from 'virtual:eldrin/migrations';
|
|
31
|
+
import App from './App';
|
|
32
|
+
|
|
33
|
+
export const { bootstrap, mount, unmount } = createApp({
|
|
34
|
+
name: 'my-app',
|
|
35
|
+
root: App,
|
|
36
|
+
migrations,
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Configure Vite
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// vite.config.ts
|
|
44
|
+
import { defineConfig } from 'vite';
|
|
45
|
+
import { eldrinPlugin } from '@eldrin-project/eldrin-app-core/vite';
|
|
46
|
+
|
|
47
|
+
export default defineConfig({
|
|
48
|
+
plugins: [
|
|
49
|
+
eldrinPlugin({
|
|
50
|
+
migrationsDir: './migrations',
|
|
51
|
+
seedsDir: './seeds',
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 3. Add TypeScript support for virtual modules
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// src/vite-env.d.ts
|
|
61
|
+
/// <reference types="@eldrin-project/eldrin-app-core/vite-env" />
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 4. Use the database in components
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { useDatabase } from '@eldrin-project/eldrin-app-core';
|
|
68
|
+
|
|
69
|
+
function InvoiceList() {
|
|
70
|
+
const db = useDatabase();
|
|
71
|
+
const [invoices, setInvoices] = useState([]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (!db) return;
|
|
75
|
+
db.prepare('SELECT * FROM invoices ORDER BY created_at DESC')
|
|
76
|
+
.all()
|
|
77
|
+
.then(({ results }) => setInvoices(results));
|
|
78
|
+
}, [db]);
|
|
79
|
+
|
|
80
|
+
return <ul>{invoices.map(inv => <li key={inv.id}>{inv.name}</li>)}</ul>;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Migrations
|
|
85
|
+
|
|
86
|
+
Create SQL migration files in your `migrations/` directory:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
migrations/
|
|
90
|
+
├── 20250101120000-create-invoices.sql
|
|
91
|
+
├── 20250101120000-create-invoices.rollback.sql
|
|
92
|
+
└── 20250102100000-add-status-column.sql
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Migration filenames must follow the pattern: `YYYYMMDDHHMMSS-description.sql`
|
|
96
|
+
|
|
97
|
+
Migrations run automatically during the app bootstrap phase. The system tracks executed migrations in the `_eldrin_migrations` table with SHA-256 checksums to detect tampering.
|
|
98
|
+
|
|
99
|
+
### Migration Hooks
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
export const { bootstrap, mount, unmount } = createApp({
|
|
103
|
+
name: 'my-app',
|
|
104
|
+
root: App,
|
|
105
|
+
migrations,
|
|
106
|
+
onMigrationsComplete: (result) => {
|
|
107
|
+
console.log(`Executed ${result.executed} migrations`);
|
|
108
|
+
},
|
|
109
|
+
onMigrationError: (error) => {
|
|
110
|
+
console.error('Migration failed:', error);
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## API Reference
|
|
116
|
+
|
|
117
|
+
### createApp(options)
|
|
118
|
+
|
|
119
|
+
Creates a single-spa compatible app lifecycle.
|
|
120
|
+
|
|
121
|
+
| Option | Type | Description |
|
|
122
|
+
|--------|------|-------------|
|
|
123
|
+
| `name` | `string` | Unique app identifier |
|
|
124
|
+
| `root` | `React.ComponentType` | Root React component |
|
|
125
|
+
| `migrations` | `MigrationFile[]` | Migration files (from virtual module) |
|
|
126
|
+
| `onMigrationsComplete` | `(result) => void` | Called after successful migrations |
|
|
127
|
+
| `onMigrationError` | `(error) => void` | Called if migrations fail |
|
|
128
|
+
|
|
129
|
+
### useDatabase()
|
|
130
|
+
|
|
131
|
+
React hook that returns the D1 database instance or `null`.
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
const db = useDatabase();
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### useDatabaseContext()
|
|
138
|
+
|
|
139
|
+
React hook that returns the full database context including migration status.
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
const { db, migrationsComplete, migrationResult } = useDatabaseContext();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### useMigrationsComplete()
|
|
146
|
+
|
|
147
|
+
React hook that returns `true` when migrations have finished.
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
const ready = useMigrationsComplete();
|
|
151
|
+
if (!ready) return <Loading />;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## CLI Tools
|
|
155
|
+
|
|
156
|
+
### eldrin-release
|
|
157
|
+
|
|
158
|
+
Prepares your app for marketplace submission.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npx eldrin-release [options]
|
|
162
|
+
|
|
163
|
+
Options:
|
|
164
|
+
-t, --type <type> Bump version: patch, minor, or major
|
|
165
|
+
-v, --version <ver> Set explicit version
|
|
166
|
+
--skip-build Skip the build step
|
|
167
|
+
-m, --manifest <path> Path to manifest file
|
|
168
|
+
-o, --output <path> Output directory
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Creates a release package at `dist/release/{developerId}/{appId}/v{version}/` containing:
|
|
172
|
+
- `eldrin-app.manifest.json` - App metadata
|
|
173
|
+
- `bundle.js` - Built app bundle
|
|
174
|
+
- `deploy-bundle.json` - Worker + client assets (if applicable)
|
|
175
|
+
- `migrations/` - Migration files with checksums
|
|
176
|
+
|
|
177
|
+
### eldrin-submit
|
|
178
|
+
|
|
179
|
+
Submits a release to the Eldrin marketplace.
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npx eldrin-submit -d ./dist/release/eldrin.io/my-app/v1.0.0
|
|
183
|
+
|
|
184
|
+
Options:
|
|
185
|
+
-d, --release-dir <dir> Release directory to submit
|
|
186
|
+
-k, --api-key <key> Developer API key
|
|
187
|
+
--developer-id <id> Developer ID
|
|
188
|
+
--dry-run Preview without submitting
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Environment variables:
|
|
192
|
+
- `ELDRIN_API_KEY` - Your developer API key
|
|
193
|
+
- `ELDRIN_DEVELOPER_ID` - Your developer ID
|
|
194
|
+
- `ELDRIN_MARKETPLACE_URL` - Marketplace URL (default: https://eldrin.io)
|
|
195
|
+
|
|
196
|
+
## Configuration
|
|
197
|
+
|
|
198
|
+
Create `.eldrinrc.json` in your project root:
|
|
199
|
+
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"developerId": "your-developer-id",
|
|
203
|
+
"marketplaceUrl": "https://eldrin.io",
|
|
204
|
+
"manifestPath": "./eldrin-app.manifest.json",
|
|
205
|
+
"migrationsDir": "./migrations",
|
|
206
|
+
"buildCommand": "npm run build:lib",
|
|
207
|
+
"clientDir": "dist/client",
|
|
208
|
+
"workerEntry": "dist/worker/index.js"
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## App Manifest
|
|
213
|
+
|
|
214
|
+
Create `eldrin-app.manifest.json`:
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{
|
|
218
|
+
"id": "my-app",
|
|
219
|
+
"name": "My App",
|
|
220
|
+
"version": "1.0.0",
|
|
221
|
+
"description": "Description of my app",
|
|
222
|
+
"developer": {
|
|
223
|
+
"id": "your-developer-id",
|
|
224
|
+
"name": "Your Name"
|
|
225
|
+
},
|
|
226
|
+
"entry": "bundle.js"
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Requirements
|
|
231
|
+
|
|
232
|
+
- Node.js 18.0.0 or later
|
|
233
|
+
- React 18.x or 19.x
|
|
234
|
+
- Vite 6.x or 7.x
|
|
235
|
+
|
|
236
|
+
## Contributing
|
|
237
|
+
|
|
238
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
239
|
+
|
|
240
|
+
1. Fork the repository
|
|
241
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
242
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
243
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
244
|
+
5. Open a Pull Request
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Release Script for Eldrin Apps
|
|
3
|
+
*
|
|
4
|
+
* Prepares app for marketplace submission by:
|
|
5
|
+
* 1. Building the library bundle
|
|
6
|
+
* 2. Generating migration manifest with checksums
|
|
7
|
+
* 3. Creating deployment bundle (worker + client assets)
|
|
8
|
+
* 4. Copying files to release directory
|
|
9
|
+
*
|
|
10
|
+
* Usage: npx eldrin-release [options]
|
|
11
|
+
*
|
|
12
|
+
* Output structure:
|
|
13
|
+
* dist/release/{developerId}/{appId}/
|
|
14
|
+
* ├── migrations/ # All migrations at app level (shared across versions)
|
|
15
|
+
* │ ├── index.json
|
|
16
|
+
* │ └── *.sql
|
|
17
|
+
* └── v{version}/
|
|
18
|
+
* ├── eldrin-app.manifest.json
|
|
19
|
+
* ├── bundle.js
|
|
20
|
+
* └── deploy-bundle.json (if client assets exist)
|
|
21
|
+
*/
|
|
22
|
+
type BumpType = 'patch' | 'minor' | 'major';
|
|
23
|
+
interface ReleaseOptions {
|
|
24
|
+
version?: string;
|
|
25
|
+
bumpType?: BumpType;
|
|
26
|
+
skipBuild?: boolean;
|
|
27
|
+
manifestPath?: string;
|
|
28
|
+
bundlePath?: string;
|
|
29
|
+
migrationsDir?: string;
|
|
30
|
+
outputDir?: string;
|
|
31
|
+
marketplaceUrl?: string;
|
|
32
|
+
}
|
|
33
|
+
declare function release(options?: ReleaseOptions): Promise<void>;
|
|
34
|
+
|
|
35
|
+
export { release };
|