@blinkhost/cli 2.1.0 → 2.3.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/README.md +23 -5
- package/dist/cli.js +6 -2
- package/dist/detect.js +39 -2
- package/dist/guidance.d.ts +1 -1
- package/dist/guidance.js +12 -6
- package/dist/manifest.d.ts +1 -1
- package/dist/manifest.js +2 -2
- package/dist/remote.d.ts +1 -0
- package/dist/remote.js +91 -1
- package/dist/templates.js +13 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ The BlinkHost CLI brings project setup, local development, source control, previ
|
|
|
7
7
|
Node.js 22.12 or newer is required.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install --global @blinkhost/cli
|
|
10
|
+
npm install --global @blinkhost/cli@2.3.0
|
|
11
11
|
blinkhost --version
|
|
12
12
|
```
|
|
13
13
|
|
|
@@ -46,20 +46,20 @@ Interactive credential storage uses macOS Keychain, Windows Password Vault, or L
|
|
|
46
46
|
## Create or adopt a project
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
|
-
blinkhost create study-circle --template astro --module search:
|
|
49
|
+
blinkhost create study-circle --template astro --module search:typescript --module reminders:python --database PRIMARY_DB
|
|
50
50
|
cd study-circle
|
|
51
51
|
blinkhost validate
|
|
52
52
|
blinkhost projects link PROJECT_ID
|
|
53
53
|
blinkhost dev
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
Supported frontends are Astro, HTML, React, Solid, Svelte, and Vue. Backend modules may use Go, Python, or
|
|
56
|
+
Supported frontends are Astro, HTML, React, Solid, Svelte, and Vue. Backend modules may use Rust, Go, Python, JavaScript, or TypeScript. Python, JavaScript, and TypeScript Functions are beta capabilities with bounded runtime and dependency policies. `blinkhost init` detects supported frontend metadata and reviewed `_server_islands/*/blinkhost.toml` module declarations in an existing repository, then creates `blinkhost.yaml` for review. Preview the exact result without writing anything first:
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
59
|
blinkhost init apps/storefront --dry-run --json
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
`init` writes only `blinkhost.yaml`, refuses an existing manifest unless `--force` is explicitly supplied, and never rewrites application source. It
|
|
62
|
+
`init` writes only `blinkhost.yaml`, refuses an existing manifest unless `--force` is explicitly supplied, and never rewrites application source. It proposes only safe module declarations already present under `_server_islands`; review them and add other intended modules explicitly. One manifest describes one deployable application. In a monorepo, select the application directory, or place the manifest at a build-context root that contains the app and its shared workspace packages; use separate BlinkHost projects for independently deployable apps.
|
|
63
63
|
|
|
64
64
|
Creation is atomic and refuses to replace an existing path. Dependency lifecycle scripts are disabled. Validation rejects unknown manifest fields, duplicate YAML keys, aliases, traversal, unsafe symbolic links, invalid cross-platform paths, duplicate module names, and missing declared inputs.
|
|
65
65
|
|
|
@@ -102,6 +102,24 @@ blinkhost previews delete PREVIEW_ID --confirm PREVIEW_ID
|
|
|
102
102
|
|
|
103
103
|
Connected repository, release, approval, agency handoff, enterprise policy, and template APIs are available through `repositories`, `connections`, `builds`, `approvals`, `handoffs`, `policies`, and `templates`. Advanced customer API operations can use `blinkhost api METHOD /api/path/`; internal, staff, and authentication routes are blocked.
|
|
104
104
|
|
|
105
|
+
## Function triggers and runs
|
|
106
|
+
|
|
107
|
+
Manage beta event, schedule, and background triggers without using raw API routes:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
blinkhost functions status [PROJECT_ID]
|
|
111
|
+
blinkhost functions triggers list MODULE_ID
|
|
112
|
+
blinkhost functions triggers create MODULE_ID --data @trigger.json
|
|
113
|
+
blinkhost functions invoke run MODULE_ID TRIGGER_ID --data @payload.json --idempotency-key order-1042
|
|
114
|
+
blinkhost functions invocations list MODULE_ID
|
|
115
|
+
blinkhost functions invocations get MODULE_ID INVOCATION_ID
|
|
116
|
+
blinkhost functions invocations result MODULE_ID INVOCATION_ID
|
|
117
|
+
blinkhost functions invocations cancel MODULE_ID INVOCATION_ID
|
|
118
|
+
blinkhost functions invocations retry MODULE_ID INVOCATION_ID --idempotency-key retry-order-1042
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`functions status` reports the effective language and trigger capabilities for a project; omit the project ID inside a linked directory. Payloads must be JSON objects no larger than 256 KiB. Use a stable idempotency key when repeating the same logical request. Runs remain subject to workspace roles, rollout availability, verified artifacts, runtime policy, and plan limits.
|
|
122
|
+
|
|
105
123
|
## Secrets and resources
|
|
106
124
|
|
|
107
125
|
Secret values never appear in command arguments or `blinkhost.yaml`. Pipe them over standard input:
|
|
@@ -160,7 +178,7 @@ Pin or roll back explicitly with `npm install --global @blinkhost/cli@VERSION`.
|
|
|
160
178
|
```bash
|
|
161
179
|
cosign verify-blob \
|
|
162
180
|
--bundle SHA256SUMS.sigstore.json \
|
|
163
|
-
--certificate-identity "https://github.com/blinkhost-ltd/blinkhost-cli/.github/workflows/release.yml@refs/tags/v2.
|
|
181
|
+
--certificate-identity "https://github.com/blinkhost-ltd/blinkhost-cli/.github/workflows/release.yml@refs/tags/v2.3.0" \
|
|
164
182
|
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
|
|
165
183
|
SHA256SUMS
|
|
166
184
|
```
|
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import { createScaffold } from './templates.js';
|
|
|
11
11
|
import { ApiClient } from './api.js';
|
|
12
12
|
import { login, logout } from './auth.js';
|
|
13
13
|
import { activeProfile, readConfig, validateProfileName, writeConfig } from './config.js';
|
|
14
|
-
import { openPreview, projectStatus, rawApi, readProjectLink, runRemote, runSecrets, syncProject, unlinkProject, uploadAsset, waitForRemote, writeProjectLink } from './remote.js';
|
|
14
|
+
import { openPreview, projectStatus, rawApi, readProjectLink, runFunctions, runRemote, runSecrets, syncProject, unlinkProject, uploadAsset, waitForRemote, writeProjectLink } from './remote.js';
|
|
15
15
|
import { checkForUpdate, ciCheck, completion, observability, runDev, runPlugins, supportBundle, testProject } from './workflows.js';
|
|
16
16
|
import { documentationIndex, documentationTopic, quickstart, renderTopHelp, renderTopic, searchDocumentation, TOP_LEVEL_COMMANDS } from './guidance.js';
|
|
17
17
|
import { VERSION, supportedNodeVersion } from './version.js';
|
|
@@ -71,7 +71,7 @@ function assertNoUnknown(args) {
|
|
|
71
71
|
function parseModule(value) {
|
|
72
72
|
const [name, language, extra] = value.split(':');
|
|
73
73
|
if (extra || !name || !language || !/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/.test(name) || !SUPPORTED_MODULES.includes(language)) {
|
|
74
|
-
throw new CliError('Use --module name:language with a safe name and
|
|
74
|
+
throw new CliError('Use --module name:language with a safe name and rust, go, python, javascript or typescript.', EXIT.usage, 'invalid_module');
|
|
75
75
|
}
|
|
76
76
|
return { name, language: language };
|
|
77
77
|
}
|
|
@@ -433,6 +433,10 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
433
433
|
const data = await runSecrets(args, profile);
|
|
434
434
|
emit({ ok: true, command, message: 'Secret operation completed.', data }, json);
|
|
435
435
|
}
|
|
436
|
+
else if (command === 'functions') {
|
|
437
|
+
const data = await runFunctions(args, profile);
|
|
438
|
+
emit({ ok: true, command, message: 'Function operation completed.', data }, json);
|
|
439
|
+
}
|
|
436
440
|
else if (command === 'dev') {
|
|
437
441
|
const data = await runDev(args, json);
|
|
438
442
|
emit({ ok: true, command, message: 'Local development process finished.', data }, json);
|
package/dist/detect.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lstat, readFile } from 'node:fs/promises';
|
|
1
|
+
import { lstat, readFile, readdir } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
async function readable(path) {
|
|
4
4
|
try {
|
|
@@ -44,6 +44,43 @@ export async function detectManifest(root) {
|
|
|
44
44
|
else if (await readable(join(root, 'bun.lock')) || await readable(join(root, 'bun.lockb')))
|
|
45
45
|
packageManager = 'bun';
|
|
46
46
|
const install = packageManager === 'npm' ? 'npm ci' : `${packageManager} install --frozen-lockfile`;
|
|
47
|
+
const modules = [];
|
|
48
|
+
const moduleRoot = join(root, '_server_islands');
|
|
49
|
+
try {
|
|
50
|
+
const entries = (await readdir(moduleRoot, { withFileTypes: true })).sort((left, right) => left.name.localeCompare(right.name));
|
|
51
|
+
if (entries.length > 100)
|
|
52
|
+
throw new Error('A BlinkHost project cannot declare more than 100 backend modules.');
|
|
53
|
+
const languageMap = {
|
|
54
|
+
'rust-wasi': 'rust', 'go-wasi': 'go', 'python-wasi': 'python',
|
|
55
|
+
'javascript-wasi': 'javascript', 'typescript-wasi': 'typescript',
|
|
56
|
+
};
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || !/^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/.test(entry.name))
|
|
59
|
+
continue;
|
|
60
|
+
const manifestPath = join(moduleRoot, entry.name, 'blinkhost.toml');
|
|
61
|
+
let source;
|
|
62
|
+
try {
|
|
63
|
+
const metadata = await lstat(manifestPath);
|
|
64
|
+
if (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size > 32 * 1024)
|
|
65
|
+
continue;
|
|
66
|
+
source = await readFile(manifestPath, 'utf8');
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const language = /^language\s*=\s*["']([^"']+)["']\s*$/m.exec(source)?.[1];
|
|
72
|
+
const entrypoint = /^entrypoint\s*=\s*["']([^"']+)["']\s*$/m.exec(source)?.[1];
|
|
73
|
+
const abi = /^abi_version\s*=\s*["']([^"']+)["']\s*$/m.exec(source)?.[1] || 'blinkhost-wasi-1';
|
|
74
|
+
const sdk = /^sdk_version\s*=\s*["']([^"']+)["']\s*$/m.exec(source)?.[1] || '1.1.0';
|
|
75
|
+
if (!language || !entrypoint || !languageMap[language])
|
|
76
|
+
continue;
|
|
77
|
+
modules.push({ name: entry.name, path: `_server_islands/${entry.name}`, language: languageMap[language], entrypoint, abi, sdk });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
if (error.code !== 'ENOENT')
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
47
84
|
return {
|
|
48
85
|
schema: 'blinkhost/v1', application: { root: '.' },
|
|
49
86
|
frontend: {
|
|
@@ -53,7 +90,7 @@ export async function detectManifest(root) {
|
|
|
53
90
|
dev: framework === 'html' ? '' : `${packageManager} run dev`,
|
|
54
91
|
output: framework === 'html' ? '.' : 'dist',
|
|
55
92
|
},
|
|
56
|
-
modules
|
|
93
|
+
modules, resources: { databases: [], secrets: [] },
|
|
57
94
|
preview: { enabled: true, database_mode: 'none' },
|
|
58
95
|
ignore: ['.blinkhost', 'node_modules', 'dist'],
|
|
59
96
|
};
|
package/dist/guidance.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface DocumentationTopic {
|
|
|
8
8
|
related: string[];
|
|
9
9
|
url: string;
|
|
10
10
|
}
|
|
11
|
-
export declare const TOP_LEVEL_COMMANDS: ("plugins" | "profile" | "modules" | "dev" | "databases" | "secrets" | "manifest" | "projects" | "repositories" | "connections" | "previews" | "builds" | "deployments" | "bindings" | "assets" | "organizations" | "templates" | "approvals" | "handoffs" | "policies" | "workloads" | "create" | "update" | "quickstart" | "init" | "doctor" | "auth" | "validate" | "test" | "ci" | "logs" | "support" | "metrics" | "analytics" | "completion" | "api" | "docs")[];
|
|
11
|
+
export declare const TOP_LEVEL_COMMANDS: ("plugins" | "profile" | "modules" | "dev" | "databases" | "secrets" | "manifest" | "projects" | "repositories" | "connections" | "previews" | "builds" | "deployments" | "bindings" | "assets" | "organizations" | "templates" | "approvals" | "handoffs" | "policies" | "workloads" | "create" | "update" | "quickstart" | "init" | "doctor" | "auth" | "validate" | "test" | "ci" | "functions" | "logs" | "support" | "metrics" | "analytics" | "completion" | "api" | "docs")[];
|
|
12
12
|
export declare function documentationIndex(): {
|
|
13
13
|
schema: string;
|
|
14
14
|
cli_version: string;
|
package/dist/guidance.js
CHANGED
|
@@ -42,7 +42,7 @@ const TOPICS = {
|
|
|
42
42
|
init: {
|
|
43
43
|
name: 'init', title: 'Adopt an existing repository', summary: 'Detect supported project metadata and write a reviewable blinkhost.yaml.',
|
|
44
44
|
usage: ['blinkhost init [path] [--dry-run|--force]'],
|
|
45
|
-
details: ['Detection reads package.json dependencies and the pnpm, Yarn, Bun or npm lockfile at the selected application root. It recognizes Astro, React, Vue, Svelte and Solid; a directory without recognized framework metadata is described as static HTML.', '`--dry-run` returns the proposed manifest and writes nothing. Without it, init writes only blinkhost.yaml and refuses an existing manifest. `--force` replaces only an existing regular blinkhost.yaml after explicit use; application source and configuration are never rewritten.', 'Detection
|
|
45
|
+
details: ['Detection reads package.json dependencies and the pnpm, Yarn, Bun or npm lockfile at the selected application root. It recognizes Astro, React, Vue, Svelte and Solid; a directory without recognized framework metadata is described as static HTML.', '`--dry-run` returns the proposed manifest and writes nothing. Without it, init writes only blinkhost.yaml and refuses an existing manifest. `--force` replaces only an existing regular blinkhost.yaml after explicit use; application source and configuration are never rewritten.', 'Detection proposes modules only from safe, regular blinkhost.toml files under _server_islands. Review every detected module before validation; other backend directories are never silently registered.', 'One manifest represents one deployable application. For a nested app, pass that directory. For a workspace app that imports shared packages, place the manifest at a root containing the complete build context and set frontend.root and frontend.dependency_root explicitly. Use separate application roots and BlinkHost projects for independently deployable monorepo applications.'],
|
|
46
46
|
examples: ['blinkhost init . --dry-run --json', 'blinkhost init apps/storefront', 'blinkhost docs manifest-reference'], related: ['validate', 'manifest-reference', 'projects'], url: DOCUMENTATION_URL,
|
|
47
47
|
},
|
|
48
48
|
validate: {
|
|
@@ -79,8 +79,14 @@ const TOPICS = {
|
|
|
79
79
|
previews: resource('previews', 'Manage temporary preview environments.', ['`previews wait ID [--timeout 10..3600]` waits for a terminal state. `previews open ID` accepts only trusted BlinkHost HTTPS preview hosts. Preview operations can consume plan resources.']),
|
|
80
80
|
builds: resource('builds', 'Create, inspect and wait for verified builds.', ['`builds wait ID [--timeout 10..3600]` stops on success, failure, cancellation, expiry or timeout. Builds can consume plan resources.']),
|
|
81
81
|
deployments: resource('deployments', 'Manage production deployments and protected release actions.', ['Rollback uses `deployments action DEPLOYMENT_ID rollback --data @rollback.json`. Protected environments can require approval and a verified artifact. Deployment operations can consume plan resources.']),
|
|
82
|
-
modules: resource('modules', 'Manage Rust, Go and
|
|
83
|
-
|
|
82
|
+
modules: resource('modules', 'Manage Rust, Go, Python, JavaScript and TypeScript Functions.'),
|
|
83
|
+
functions: {
|
|
84
|
+
name: 'functions', title: 'Function triggers and runs', summary: 'Manage beta event, schedule and background triggers with explicit retry and idempotency controls.',
|
|
85
|
+
usage: ['blinkhost functions status [PROJECT_ID]', 'blinkhost functions triggers list MODULE_ID', 'blinkhost functions triggers create MODULE_ID --data @trigger.json', 'blinkhost functions triggers update MODULE_ID TRIGGER_ID --data @trigger.json', 'blinkhost functions triggers delete MODULE_ID TRIGGER_ID --confirm TRIGGER_ID', 'blinkhost functions invoke run MODULE_ID TRIGGER_ID --data @payload.json [--idempotency-key KEY]', 'blinkhost functions invocations list MODULE_ID', 'blinkhost functions invocations get|result|cancel MODULE_ID INVOCATION_ID', 'blinkhost functions invocations retry MODULE_ID INVOCATION_ID [--idempotency-key KEY]'],
|
|
86
|
+
details: ['Event, schedule and background triggers are beta capabilities and may be enabled progressively by workspace. Workspace roles, runtime policy, verified artifacts, plan limits and the service rollout gate remain authoritative.', 'Payloads must be JSON objects no larger than 256 KiB. Results are bounded by the service. Use a stable idempotency key when repeating the same logical request; otherwise the CLI generates one for each submission.', 'Delivery is at least once. Handlers that can create duplicate writes, messages or charges must be idempotent. Cancellation cannot undo application work that has already completed.'],
|
|
87
|
+
examples: ['blinkhost functions status PROJECT_ID --json', 'blinkhost functions triggers list MODULE_ID --json', 'blinkhost functions invoke run MODULE_ID TRIGGER_ID --data @payload.json --idempotency-key order-1042 --json'], related: ['modules', 'automation', 'limits', 'troubleshooting'], url: DOCUMENTATION_URL,
|
|
88
|
+
},
|
|
89
|
+
databases: resource('databases', 'Manage database resources.', ['Database list, get, create, update, delete and supported server actions are remote and may require plan capacity or protected-environment approval.', 'The CLI does not invent local backup, restore, credential-rotation or migration semantics. Use only actions returned by the active workspace API and consult the detailed database guide before production data changes. Deletion retains exact-ID confirmation and server authorization.']),
|
|
84
90
|
bindings: resource('bindings', 'Manage explicit application-to-resource bindings.'),
|
|
85
91
|
assets: resource('assets', 'Manage project assets.', ['Upload with `assets upload FILE --project PROJECT_ID [--parent ID] [--revision VALUE] [--replace ID]`. Uploads accept listed image, font, MP3 and MP4 types, reject symbolic links, verify SHA-256 and count against plan storage.']),
|
|
86
92
|
organizations: resource('organizations', 'Manage organizations within the permissions granted to your account.'),
|
|
@@ -128,7 +134,7 @@ const TOPICS = {
|
|
|
128
134
|
},
|
|
129
135
|
glossary: {
|
|
130
136
|
name: 'glossary', title: 'BlinkHost terminology', summary: 'Translate platform terms into the developer actions they represent.', usage: ['blinkhost docs glossary'],
|
|
131
|
-
details: ['Project: one deployable application and its resources. Module: a Go, Python or
|
|
137
|
+
details: ['Project: one deployable application and its resources. Module: a Rust, Go, Python, JavaScript or TypeScript Function declared by that project. Binding: an explicit connection between application code and a managed resource.', 'Preview: a temporary environment for reviewing a change. Build: compilation and verification of source. Deployment: promotion of a verified artifact to an environment.', 'Profile: a local named account configuration. Workload: a narrowly scoped short-lived automation identity. Approval: a required authorized decision before a protected action. Handoff: an audited transfer of agency or team responsibility.'],
|
|
132
138
|
examples: ['blinkhost docs manifest-reference', 'blinkhost docs limits'], related: ['commands', 'manifest-reference'], url: DOCUMENTATION_URL,
|
|
133
139
|
},
|
|
134
140
|
portability: {
|
|
@@ -155,7 +161,7 @@ const TOPICS = {
|
|
|
155
161
|
};
|
|
156
162
|
const COMMANDS = [
|
|
157
163
|
'quickstart', 'docs', 'create', 'init', 'validate', 'manifest', 'doctor', 'test', 'auth', 'profile', 'projects',
|
|
158
|
-
'repositories', 'connections', 'previews', 'builds', 'deployments', 'modules', 'databases', 'bindings', 'assets',
|
|
164
|
+
'repositories', 'connections', 'previews', 'builds', 'deployments', 'modules', 'functions', 'databases', 'bindings', 'assets',
|
|
159
165
|
'secrets', 'organizations', 'templates', 'approvals', 'handoffs', 'policies', 'workloads', 'dev', 'logs', 'metrics',
|
|
160
166
|
'analytics', 'support', 'completion', 'update', 'ci', 'plugins', 'api',
|
|
161
167
|
];
|
|
@@ -246,7 +252,7 @@ export async function quickstart(path) {
|
|
|
246
252
|
capabilities: {
|
|
247
253
|
frontends: SUPPORTED_FRONTENDS, package_managers: SUPPORTED_MANAGERS, backend_modules: SUPPORTED_MODULES,
|
|
248
254
|
local: ['create', 'init', 'validate', 'manifest', 'doctor', 'test', 'dev', 'docs'],
|
|
249
|
-
remote: ['projects', 'repositories', 'previews', 'builds', 'deployments', 'modules', 'databases', 'assets'],
|
|
255
|
+
remote: ['projects', 'repositories', 'previews', 'builds', 'deployments', 'modules', 'functions', 'databases', 'assets'],
|
|
250
256
|
remote_requirements: 'Authentication, workspace permission, plan capacity, and approval where applicable.',
|
|
251
257
|
},
|
|
252
258
|
next_steps: nextSteps,
|
package/dist/manifest.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const MANIFEST_FILENAME = "blinkhost.yaml";
|
|
|
3
3
|
export declare const MAX_MANIFEST_BYTES: number;
|
|
4
4
|
export declare const SUPPORTED_FRONTENDS: readonly ["astro", "html", "react", "solid", "svelte", "vue"];
|
|
5
5
|
export declare const SUPPORTED_MANAGERS: readonly ["bun", "npm", "pnpm", "yarn"];
|
|
6
|
-
export declare const SUPPORTED_MODULES: readonly ["go", "python", "rust"];
|
|
6
|
+
export declare const SUPPORTED_MODULES: readonly ["go", "javascript", "python", "rust", "typescript"];
|
|
7
7
|
export type FrontendFramework = typeof SUPPORTED_FRONTENDS[number];
|
|
8
8
|
export type PackageManager = typeof SUPPORTED_MANAGERS[number];
|
|
9
9
|
export type ModuleLanguage = typeof SUPPORTED_MODULES[number];
|
package/dist/manifest.js
CHANGED
|
@@ -5,7 +5,7 @@ export const MANIFEST_FILENAME = 'blinkhost.yaml';
|
|
|
5
5
|
export const MAX_MANIFEST_BYTES = 128 * 1024;
|
|
6
6
|
export const SUPPORTED_FRONTENDS = ['astro', 'html', 'react', 'solid', 'svelte', 'vue'];
|
|
7
7
|
export const SUPPORTED_MANAGERS = ['bun', 'npm', 'pnpm', 'yarn'];
|
|
8
|
-
export const SUPPORTED_MODULES = ['go', 'python', 'rust'];
|
|
8
|
+
export const SUPPORTED_MODULES = ['go', 'javascript', 'python', 'rust', 'typescript'];
|
|
9
9
|
const TOP_LEVEL = new Set(['schema', 'application', 'frontend', 'modules', 'resources', 'preview', 'ignore']);
|
|
10
10
|
const APPLICATION_FIELDS = new Set(['root']);
|
|
11
11
|
const FRONTEND_FIELDS = new Set(['root', 'dependency_root', 'framework', 'package_manager', 'install', 'build', 'dev', 'output']);
|
|
@@ -127,7 +127,7 @@ export function parseManifest(raw) {
|
|
|
127
127
|
const absolutePath = applicationRoot === '.' ? path : `${applicationRoot}/${path}`;
|
|
128
128
|
const language = stringValue(module.language, `${field}.language`, 16).toLowerCase();
|
|
129
129
|
if (!SUPPORTED_MODULES.includes(language))
|
|
130
|
-
fail(`${field}.language`, '
|
|
130
|
+
fail(`${field}.language`, 'Choose Rust, Go, Python, JavaScript or TypeScript Functions.');
|
|
131
131
|
if (moduleNames.has(name))
|
|
132
132
|
fail(`${field}.name`, 'Module names must be unique.');
|
|
133
133
|
if (modulePaths.has(absolutePath.toLowerCase()))
|
package/dist/remote.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare function runRemote(group: string, input: string[], profile?: string): Promise<unknown>;
|
|
2
|
+
export declare function runFunctions(input: string[], profile?: string): Promise<unknown>;
|
|
2
3
|
interface ProjectLink {
|
|
3
4
|
schema: 'blinkhost/project-link/v1';
|
|
4
5
|
project_id: string;
|
package/dist/remote.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { lstat, mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { basename, extname } from 'node:path';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { stdin } from 'node:process';
|
|
@@ -58,6 +58,11 @@ function safeIdentifier(value, label = 'ID') {
|
|
|
58
58
|
throw new CliError(`${label} is missing or invalid.`, EXIT.usage, 'invalid_identifier');
|
|
59
59
|
return encodeURIComponent(value);
|
|
60
60
|
}
|
|
61
|
+
function validIdempotencyKey(value) {
|
|
62
|
+
if (!value || Buffer.byteLength(value, 'utf8') > 256 || /[\u0000-\u001f\u007f-\u009f]/.test(value))
|
|
63
|
+
throw new CliError('Idempotency keys must be from 1 to 256 bytes and cannot contain control characters.', EXIT.usage, 'invalid_idempotency_key');
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
61
66
|
async function readPayload(value) {
|
|
62
67
|
if (!value)
|
|
63
68
|
return {};
|
|
@@ -142,6 +147,91 @@ export async function runRemote(group, input, profile) {
|
|
|
142
147
|
}
|
|
143
148
|
throw new CliError(`Unknown ${group} action: ${action}.`, EXIT.usage, 'unknown_action');
|
|
144
149
|
}
|
|
150
|
+
export async function runFunctions(input, profile) {
|
|
151
|
+
const args = [...input];
|
|
152
|
+
const resource = args.shift();
|
|
153
|
+
if (resource === 'status') {
|
|
154
|
+
let project = args.shift();
|
|
155
|
+
let selectedProfile = profile;
|
|
156
|
+
if (!project) {
|
|
157
|
+
const link = await readProjectLink();
|
|
158
|
+
project = link.project_id;
|
|
159
|
+
selectedProfile ||= link.profile;
|
|
160
|
+
}
|
|
161
|
+
const projectId = safeIdentifier(project, 'Project ID');
|
|
162
|
+
noExtra(args);
|
|
163
|
+
const client = await ApiClient.create(selectedProfile);
|
|
164
|
+
return client.request(`/api/backend-modules/rollout-status/?site_id=${projectId}`);
|
|
165
|
+
}
|
|
166
|
+
const action = args.shift() || 'list';
|
|
167
|
+
const moduleId = safeIdentifier(args.shift(), 'Module ID');
|
|
168
|
+
const client = await ApiClient.create(profile);
|
|
169
|
+
if (resource === 'triggers') {
|
|
170
|
+
const base = `/api/backend-modules/${moduleId}/triggers/`;
|
|
171
|
+
if (action === 'list') {
|
|
172
|
+
noExtra(args);
|
|
173
|
+
return client.request(base);
|
|
174
|
+
}
|
|
175
|
+
if (action === 'create') {
|
|
176
|
+
const data = await readPayload(takeOption(args, '--data'));
|
|
177
|
+
noExtra(args);
|
|
178
|
+
return client.request(base, { method: 'POST', body: JSON.stringify(data) });
|
|
179
|
+
}
|
|
180
|
+
const triggerIdRaw = args.shift();
|
|
181
|
+
const triggerId = safeIdentifier(triggerIdRaw, 'Trigger ID');
|
|
182
|
+
if (action === 'update') {
|
|
183
|
+
const data = await readPayload(takeOption(args, '--data'));
|
|
184
|
+
noExtra(args);
|
|
185
|
+
return client.request(`${base}${triggerId}/`, { method: 'PATCH', body: JSON.stringify(data) });
|
|
186
|
+
}
|
|
187
|
+
if (action === 'delete') {
|
|
188
|
+
const confirmed = takeOption(args, '--confirm');
|
|
189
|
+
noExtra(args);
|
|
190
|
+
if (confirmed !== triggerIdRaw)
|
|
191
|
+
throw new CliError('Repeat the trigger ID with --confirm before deleting it.', EXIT.usage, 'confirmation_required');
|
|
192
|
+
return client.request(`${base}${triggerId}/`, { method: 'DELETE' });
|
|
193
|
+
}
|
|
194
|
+
throw new CliError(`Unknown trigger action: ${action}.`, EXIT.usage, 'unknown_action');
|
|
195
|
+
}
|
|
196
|
+
if (resource === 'invoke') {
|
|
197
|
+
if (action !== 'run')
|
|
198
|
+
throw new CliError('Use `functions invoke run MODULE_ID TRIGGER_ID`.', EXIT.usage, 'invalid_function_command');
|
|
199
|
+
const triggerId = safeIdentifier(args.shift(), 'Trigger ID');
|
|
200
|
+
const payload = await readPayload(takeOption(args, '--data'));
|
|
201
|
+
if (Buffer.byteLength(JSON.stringify(payload), 'utf8') > 262_144)
|
|
202
|
+
throw new CliError('Function payloads cannot exceed 256 KiB.', EXIT.validation, 'function_payload_too_large');
|
|
203
|
+
const idempotencyKey = validIdempotencyKey(takeOption(args, '--idempotency-key') || randomUUID());
|
|
204
|
+
noExtra(args);
|
|
205
|
+
return client.request(`/api/backend-modules/${moduleId}/triggers/${triggerId}/invoke/`, { method: 'POST', headers: { 'Idempotency-Key': idempotencyKey }, body: JSON.stringify({ payload }) });
|
|
206
|
+
}
|
|
207
|
+
if (resource === 'invocations') {
|
|
208
|
+
const base = `/api/backend-modules/${moduleId}/invocations/`;
|
|
209
|
+
if (action === 'list') {
|
|
210
|
+
noExtra(args);
|
|
211
|
+
return client.request(base);
|
|
212
|
+
}
|
|
213
|
+
const invocationId = safeIdentifier(args.shift(), 'Invocation ID');
|
|
214
|
+
if (action === 'get') {
|
|
215
|
+
noExtra(args);
|
|
216
|
+
return client.request(`${base}${invocationId}/`);
|
|
217
|
+
}
|
|
218
|
+
if (action === 'result') {
|
|
219
|
+
noExtra(args);
|
|
220
|
+
return client.request(`${base}${invocationId}/result/`);
|
|
221
|
+
}
|
|
222
|
+
if (action === 'cancel') {
|
|
223
|
+
noExtra(args);
|
|
224
|
+
return client.request(`${base}${invocationId}/cancel/`, { method: 'POST', body: '{}' });
|
|
225
|
+
}
|
|
226
|
+
if (action === 'retry') {
|
|
227
|
+
const idempotencyKey = validIdempotencyKey(takeOption(args, '--idempotency-key') || randomUUID());
|
|
228
|
+
noExtra(args);
|
|
229
|
+
return client.request(`${base}${invocationId}/retry/`, { method: 'POST', headers: { 'Idempotency-Key': idempotencyKey }, body: '{}' });
|
|
230
|
+
}
|
|
231
|
+
throw new CliError(`Unknown invocation action: ${action}.`, EXIT.usage, 'unknown_action');
|
|
232
|
+
}
|
|
233
|
+
throw new CliError('Use `functions status`, `functions triggers`, `functions invoke`, or `functions invocations`.', EXIT.usage, 'invalid_function_command');
|
|
234
|
+
}
|
|
145
235
|
export async function writeProjectLink(projectId, profile, root) {
|
|
146
236
|
safeIdentifier(projectId, 'Project ID');
|
|
147
237
|
const directory = join(resolveLocalPath(root), '.blinkhost');
|
package/dist/templates.js
CHANGED
|
@@ -67,6 +67,19 @@ function moduleFiles(module) {
|
|
|
67
67
|
files.set(`${root}/main.go`, 'package main\n\nfunc main() {}\n');
|
|
68
68
|
return { entrypoint: 'main.go', files };
|
|
69
69
|
}
|
|
70
|
+
if (module.language === 'javascript' || module.language === 'typescript') {
|
|
71
|
+
const typescript = module.language === 'typescript';
|
|
72
|
+
const entrypoint = typescript ? 'index.ts' : 'index.js';
|
|
73
|
+
const runtime = typescript ? 'typescript-wasi' : 'javascript-wasi';
|
|
74
|
+
const packageName = `blinkhost-${module.name}-function`;
|
|
75
|
+
files.set(`${root}/blinkhost.toml`, `schema_version = 1\nlanguage = "${runtime}"\nentrypoint = "${entrypoint}"\nabi_version = "blinkhost-wasi-1"\nsdk_version = "1.1.0"\n`);
|
|
76
|
+
files.set(`${root}/package.json`, JSON.stringify({ name: packageName, version: '1.0.0', private: true, type: 'module' }, null, 2) + '\n');
|
|
77
|
+
files.set(`${root}/package-lock.json`, JSON.stringify({ name: packageName, version: '1.0.0', lockfileVersion: 3, requires: true, packages: { '': { name: packageName, version: '1.0.0' } } }, null, 2) + '\n');
|
|
78
|
+
const declaration = typescript ? 'interface FunctionRequest { json(): unknown }\n\n' : '';
|
|
79
|
+
const annotation = typescript ? ': FunctionRequest' : '';
|
|
80
|
+
files.set(`${root}/${entrypoint}`, `${declaration}export default function handler(request${annotation}) {\n return {\n status: 200,\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ ok: true, received: request.json() }),\n };\n}\n`);
|
|
81
|
+
return { entrypoint, files };
|
|
82
|
+
}
|
|
70
83
|
files.set(`${root}/Cargo.toml`, `[package]\nname = "${module.name}"\nversion = "0.1.0"\nedition = "2021"\n\n[lib]\ncrate-type = ["cdylib"]\n`);
|
|
71
84
|
files.set(`${root}/src/lib.rs`, '#[no_mangle]\npub extern "C" fn blinkhost_module_version() -> u32 { 1 }\n');
|
|
72
85
|
return { entrypoint: 'src/lib.rs', files };
|
package/dist/version.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const VERSION = "2.
|
|
1
|
+
export declare const VERSION = "2.3.0";
|
|
2
2
|
export declare const DOCUMENTATION_URL = "https://app.blinkhost.me/docs/source-control/cli";
|
|
3
3
|
export declare const RELEASES_URL = "https://github.com/blinkhost-ltd/blinkhost-cli/releases";
|
|
4
4
|
export declare function supportedNodeVersion(version?: string): boolean;
|
package/dist/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const VERSION = '2.
|
|
1
|
+
export const VERSION = '2.3.0';
|
|
2
2
|
export const DOCUMENTATION_URL = 'https://app.blinkhost.me/docs/source-control/cli';
|
|
3
3
|
export const RELEASES_URL = 'https://github.com/blinkhost-ltd/blinkhost-cli/releases';
|
|
4
4
|
export function supportedNodeVersion(version = process.versions.node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blinkhost/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Secure local and remote developer workflows for BlinkHost",
|
|
5
5
|
"keywords": ["blinkhost", "deployment", "hosting", "cloud", "cli", "developer-tools"],
|
|
6
6
|
"homepage": "https://app.blinkhost.me/docs/source-control/cli",
|