@apexkit/cli 1.0.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kipeles Kemboi
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,396 @@
1
+ Here is a complete, production-ready `README.md` for **`@apexkit/cli`**.
2
+
3
+ ---
4
+
5
+ # `@apexkit/cli`
6
+
7
+ > The official Command Line Interface and Developer Sync Engine for [ApexKit](https://github.com/deniskipeles/apexkit).
8
+
9
+ `@apexkit/cli` allows you to develop, test, and synchronize backend scripts, server-side rendered (SSR) templates, custom modules, AI actions, and database schemas directly from your local IDE (VS Code, Cursor, WebStorm, etc.) with real-time live reloading and full TypeScript IntelliSense.
10
+
11
+ ---
12
+
13
+ ## Table of Contents
14
+
15
+ - [Installation](#installation)
16
+ - [Quick Start](#quick-start)
17
+ - [Configuration (`.env`)](#configuration-env)
18
+ - [CLI Commands](#cli-commands)
19
+ - [`apexkit init`](#apexkit-init)
20
+ - [`apexkit create` / `apexkit new`](#apexkit-create--apexkit-new)
21
+ - [`apexkit watch` (Default)](#apexkit-watch-default)
22
+ - [`apexkit push`](#apexkit-push)
23
+ - [`apexkit pull`](#apexkit-pull)
24
+ - [`apexkit commit`](#apexkit-commit)
25
+ - [`apexkit status`](#apexkit-status)
26
+ - [Workspace Directory Architecture](#workspace-directory-architecture)
27
+ - [File Metadata Specifications](#file-metadata-specifications)
28
+ - [TypeScript & IDE IntelliSense Setup](#typescript--ide-intellisense-setup)
29
+ - [License](#license)
30
+
31
+ ---
32
+
33
+ ## Installation
34
+
35
+ You can install `@apexkit/cli` globally or execute it on-demand with `npx`.
36
+
37
+ ```bash
38
+ # Global installation (recommended)
39
+ npm install -g @apexkit/cli
40
+
41
+ # Verify installation
42
+ apexkit --version
43
+ ```
44
+
45
+ Or run directly without installing:
46
+
47
+ ```bash
48
+ npx @apexkit/cli <command>
49
+ ```
50
+
51
+ > **Alias**: Both `apexkit` and `apex` commands are registered automatically upon installation.
52
+
53
+ ---
54
+
55
+ ## Quick Start
56
+
57
+ ### 1. Initialize a Local Workspace
58
+ Run the interactive setup wizard inside an empty folder:
59
+
60
+ ```bash
61
+ mkdir my-apex-app && cd my-apex-app
62
+ apexkit init
63
+ ```
64
+
65
+ ### 2. Pull Existing Backend Resources
66
+ Download all remote collections, webhooks, templates, and AI actions from your ApexKit server:
67
+
68
+ ```bash
69
+ apexkit pull
70
+ ```
71
+
72
+ ### 3. Start Live Development
73
+ Start the bidirectional file watcher:
74
+
75
+ ```bash
76
+ apexkit watch
77
+ ```
78
+
79
+ Every time you edit and save a script, template, or AI action in your editor, it automatically syncs to your live ApexKit instance in under 50ms.
80
+
81
+ ---
82
+
83
+ ## Configuration (`.env`)
84
+
85
+ `@apexkit/cli` reads configuration from a `.env` file in the root of your workspace:
86
+
87
+ ```env
88
+ # ApexKit Server Endpoint
89
+ APEXKIT_URL=http://localhost:5000
90
+
91
+ # Administrative API Key (Root key or Scoped Tenant/Sandbox key)
92
+ APEXKIT_API_KEY=root_sys_prod_xxxxxxxxxxxx_yyyy
93
+
94
+ # Execution Context (root | tenant:<tenant_id> | sandbox:<session_id>)
95
+ SCOPE_KEY=root
96
+ ```
97
+
98
+ | Variable | Description | Default |
99
+ | :--- | :--- | :--- |
100
+ | `APEXKIT_URL` | Base URL where your ApexKit server is running. | `http://localhost:5000` |
101
+ | `APEXKIT_API_KEY` | Admin or system API key with write access. | *None (Required)* |
102
+ | `SCOPE_KEY` | Target environment (`root`, `tenant:<id>`, `sandbox:<id>`). | `root` |
103
+
104
+ ---
105
+
106
+ ## CLI Commands
107
+
108
+ ### `apexkit init`
109
+
110
+ Runs an interactive setup wizard that:
111
+ 1. Prompts for your ApexKit server URL, API Key, and target scope.
112
+ 2. Generates the `.env` file.
113
+ 3. Provisions the standard folder structure (`webhooks/`, `modules/`, `templates/`, `ai_actions/`, `schemas/`).
114
+ 4. Generates `apexkit.d.ts` (with full database collection types) and `jsconfig.json` for IDE autocompletion.
115
+
116
+ ```bash
117
+ apexkit init
118
+ ```
119
+
120
+ ---
121
+
122
+ ### `apexkit create` / `apexkit new`
123
+
124
+ Interactive scaffolding wizard to create a new webhook, database hook, reusable custom module, or SSR template with boilerplate and type annotations.
125
+
126
+ ```bash
127
+ apexkit create
128
+ # or
129
+ apexkit new
130
+ # or
131
+ apexkit init:file
132
+ ```
133
+
134
+ **Options Scaffolded:**
135
+ - **Webhooks & Endpoints** (REST endpoints with Hono / native Request-Response)
136
+ - **Database Lifecycle Hooks** (`before_create_record`, `after_update_record`, etc.)
137
+ - **System & Auth Hooks** (`before_user_login`, `after_user_create`, etc.)
138
+ - **Reusable Modules** (Imported across scripts via `@/custom/*`)
139
+ - **SSR HTML Templates** (Astro-like Frontmatter + Tailwind + Tera engine)
140
+
141
+ ---
142
+
143
+ ### `apexkit watch` (Default)
144
+
145
+ Starts a live WebSocket file-watcher. Whenever a `.js`, `.ts`, `.html`, or `.json` file is saved, it is compiled, validated, and pushed directly to the live server.
146
+
147
+ ```bash
148
+ # Start watch mode with auto-commit to SQLite DB
149
+ apexkit watch
150
+ # or simply
151
+ apexkit
152
+
153
+ # Start watch mode in transient memory (VFS only, skips DB commit)
154
+ apexkit watch --no-auto-commit
155
+ ```
156
+
157
+ ---
158
+
159
+ ### `apexkit push`
160
+
161
+ Performs an immediate, one-time manual push and commit of local files to the live ApexKit database.
162
+
163
+ ```bash
164
+ # Push scripts & webhooks only (Default)
165
+ apexkit push
166
+ apexkit push --scripts
167
+ apexkit push -s
168
+
169
+ # Push SSR templates only
170
+ apexkit push --templates
171
+ apexkit push -t
172
+
173
+ # Push AI actions only
174
+ apexkit push --actions
175
+ apexkit push -a
176
+
177
+ # Push all categories (Scripts, Templates, AI Actions)
178
+ apexkit push --all
179
+ apexkit push -A
180
+
181
+ # Combine specific categories
182
+ apexkit push --templates --actions
183
+ ```
184
+
185
+ #### Pruning Deleted Remote Items (`--delete-remote`)
186
+ To delete items from the remote ApexKit database that no longer exist in your local workspace:
187
+
188
+ ```bash
189
+ # Prune all orphaned scripts, templates, and actions
190
+ apexkit push --all --delete-remote=all
191
+
192
+ # Prune only orphaned templates
193
+ apexkit push --templates --delete-remote=templates
194
+
195
+ # Prune only orphaned scripts
196
+ apexkit push --scripts --delete-remote=scripts
197
+ ```
198
+
199
+ ---
200
+
201
+ ### `apexkit pull`
202
+
203
+ Downloads all remote assets from your ApexKit instance to your local workspace:
204
+ - Collection schemas & policies (`schemas/`)
205
+ - Webhooks, custom modules, and hooks (`webhooks/`, `modules/`)
206
+ - SSR page templates (`templates/`)
207
+ - AI prompt actions (`ai_actions/`)
208
+ - Generates refreshed `apexkit.d.ts` typings matching your live DB schema.
209
+
210
+ ```bash
211
+ apexkit pull
212
+ ```
213
+
214
+ ---
215
+
216
+ ### `apexkit commit`
217
+
218
+ Pushes local files into the active server's in-memory Virtual File System (VFS) without persisting changes permanently to the SQLite database. Useful for rapid staging.
219
+
220
+ ```bash
221
+ apexkit commit
222
+ ```
223
+
224
+ ---
225
+
226
+ ### `apexkit status`
227
+
228
+ Displays the active connection information, target scope, server health, and sync settings.
229
+
230
+ ```bash
231
+ apexkit status
232
+ ```
233
+
234
+ ---
235
+
236
+ ## Workspace Directory Architecture
237
+
238
+ ```
239
+ my-apex-app/
240
+ ├── .env # Server URL, API Key, and Scope configuration
241
+ ├── jsconfig.json # Module alias resolution for VS Code / IDEs
242
+ ├── apexkit.d.ts # Auto-generated IntelliSense typings for DB & APIs
243
+ ├── package.json # Workspace package descriptor
244
+ │
245
+ ├── webhooks/ # API Endpoints and Database Lifecycle Hooks
246
+ │ ├── handle-payment.js
247
+ │ └── validate-order.ts
248
+ │
249
+ ├── modules/
250
+ │ ├── custom/ # Reusable local modules (import via "@/custom/<name>")
251
+ │ │ └── formatters.js
252
+ │ └── esm/ # Third-party ES modules
253
+ │
254
+ ├── templates/ # Server-Side Rendered (SSR) HTML Pages
255
+ │ ├── index.html
256
+ │ └── dashboard.html
257
+ │
258
+ ├── ai_actions/ # Structured LLM Prompts & RAG Actions
259
+ │ └── summarize-doc.json
260
+ │
261
+ └── schemas/ # Database Schema Snapshots (JSON)
262
+ └── collections.json
263
+ ```
264
+
265
+ ---
266
+
267
+ ## File Metadata Specifications
268
+
269
+ ApexKit uses a standard file header block to bind scripts and templates to collections, routes, and database triggers.
270
+
271
+ ### 1. Webhooks & Scripts (`.js` / `.ts`)
272
+
273
+ ```typescript
274
+ /** @type {import("../apexkit").FileMetadata} */
275
+ export const __fileMetadata__ = {
276
+ "name": "create-profile-on-register",
277
+ "extension": "js",
278
+ "type": "webhook",
279
+ "path": "./webhooks/",
280
+ "trigger_type": "after_user_create",
281
+ "target_collection": "profiles",
282
+ "active": true,
283
+ "visibility": "private"
284
+ };
285
+
286
+ export default async function (event) {
287
+ const { id, email } = event.record;
288
+
289
+ await $db.records.create("profiles", {
290
+ user_id: id,
291
+ display_name: email.split("@")[0]
292
+ });
293
+ }
294
+ ```
295
+
296
+ ### 2. SSR HTML Templates (`.html`)
297
+
298
+ ```html
299
+ <!--
300
+ __fileMetadata__ = {
301
+ "name": "home",
302
+ "extension": "html",
303
+ "type": "template",
304
+ "path": "./templates/",
305
+ "active": true
306
+ }
307
+ -->
308
+ <script server lang="ts">
309
+ /// <reference path="../apexkit.d.ts" />
310
+
311
+ export default async function(req) {
312
+ const posts = await $db.records.list("posts", { limit: 10 });
313
+ return {
314
+ title: "ApexKit Portal",
315
+ posts: posts.items
316
+ };
317
+ }
318
+ </script>
319
+
320
+ <!DOCTYPE html>
321
+ <html lang="en">
322
+ <head>
323
+ <meta charset="UTF-8">
324
+ <title>{{ title }}</title>
325
+ <link rel="stylesheet" href="/styles.css">
326
+ <script src="/static/js/htmx.js"></script>
327
+ <script src="/static/js/alpine.js" defer></script>
328
+ </head>
329
+ <body class="bg-slate-900 text-slate-100 p-8">
330
+ <h1 class="text-3xl font-bold text-indigo-400">{{ title }}</h1>
331
+ <ul class="mt-4 space-y-2">
332
+ {% for post in posts %}
333
+ <li class="p-4 bg-slate-800 rounded border border-slate-700">
334
+ {{ post.data.title }}
335
+ </li>
336
+ {% endfor %}
337
+ </ul>
338
+ </body>
339
+ </html>
340
+ ```
341
+
342
+ ### 3. AI Actions (`.json`)
343
+
344
+ ```json
345
+ {
346
+ "action": {
347
+ "slug": "content-editor",
348
+ "name": "Content Editor",
349
+ "model": "gemini-2.5-flash-lite",
350
+ "system_prompt": "You are an expert copywriter. Output clean Markdown.",
351
+ "template": "Improve the clarity of this text:\n\n{{text}}",
352
+ "config": {
353
+ "provider": "gemini",
354
+ "grounding": false,
355
+ "streaming": true
356
+ }
357
+ }
358
+ }
359
+ ```
360
+
361
+ ---
362
+
363
+ ## TypeScript & IDE IntelliSense Setup
364
+
365
+ `@apexkit/cli` automatically produces an `apexkit.d.ts` file tailored to your live database. It defines all globals provided by the runtime:
366
+
367
+ - `$db` – Strongly typed CRUD, Query Engine, and Vector Search.
368
+ - `$root` – Multitenancy management (Root scope only).
369
+ - `$files` – File storage operations (read, save, signed URLs).
370
+ - `$fs` – Virtual file system scratchpad.
371
+ - `$ai` – Local and remote vector embeddings and similarity math.
372
+ - `$cache` – In-memory cache operations with TTL support.
373
+ - `$queue` – Background task orchestration and status tracking.
374
+ - `$realtime` – Real-time WebSocket and SSE event dispatcher.
375
+ - `$wasm` – WebAssembly memory loader and WASI execution.
376
+ - `$util` – Crypto, hashing, base64, and string formatting utilities.
377
+ - `$env` – Environment secrets accessor.
378
+
379
+ ### Enabling Autocomplete in HTML `<script server>` Blocks
380
+ To ensure VS Code provides autocomplete inside `.html` template scripts, add the reference directive at the top of your `<script server>` block:
381
+
382
+ ```html
383
+ <script server lang="ts">
384
+ /// <reference path="../apexkit.d.ts" />
385
+
386
+ export default async function(req) {
387
+ // Full autocompletion for $db, $http, and database collections
388
+ }
389
+ </script>
390
+ ```
391
+
392
+ ---
393
+
394
+ ## License
395
+
396
+ MIT © [Denis Kipeles](https://github.com/deniskipeles)
package/bin/apexkit.js ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Forward execution to main CLI logic
4
+ import("../src/index.js").catch((err) => {
5
+ console.error("❌ Fatal CLI Error:", err);
6
+ process.exit(1);
7
+ });
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@apexkit/cli",
3
+ "version": "1.0.0",
4
+ "description": "The official CLI and developer sync engine for ApexKit",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "bin": {
8
+ "apexkit": "./bin/apexkit.js",
9
+ "apex": "./bin/apexkit.js"
10
+ },
11
+ "scripts": {
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/deniskipeles/apexkit-cli.git"
17
+ },
18
+ "dependencies": {
19
+ "ws": "^8.18.0"
20
+ },
21
+ "files": [
22
+ "bin",
23
+ "src",
24
+ "README.md"
25
+ ],
26
+ "engines": {
27
+ "node": ">=18.0.0"
28
+ },
29
+ "keywords": [
30
+ "apexkit",
31
+ "baas",
32
+ "cli",
33
+ "devtools",
34
+ "sync",
35
+ "watch"
36
+ ],
37
+ "author": "deniskipeles",
38
+ "license": "MIT",
39
+ "bugs": {
40
+ "url": "https://github.com/deniskipeles/apexkit-cli/issues"
41
+ },
42
+ "homepage": "https://github.com/deniskipeles/apexkit-cli#readme"
43
+ }