@kuratchi/js 0.0.21 → 0.0.22
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 +65 -29
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +90 -39
- package/dist/compiler/compiler-shared.d.ts +1 -0
- package/dist/compiler/config-reading.d.ts +6 -0
- package/dist/compiler/config-reading.js +92 -16
- package/dist/compiler/desktop-manifest.d.ts +48 -0
- package/dist/compiler/desktop-manifest.js +175 -0
- package/dist/compiler/durable-object-pipeline.d.ts +7 -3
- package/dist/compiler/durable-object-pipeline.js +30 -34
- package/dist/compiler/index.js +2 -3
- package/dist/compiler/parser.js +6 -0
- package/dist/compiler/routes-module-feature-blocks.js +5 -1
- package/dist/compiler/template.js +37 -3
- package/dist/compiler/wrangler-sync.js +47 -0
- package/dist/create.js +19 -19
- package/dist/index.d.ts +1 -1
- package/dist/runtime/desktop.d.ts +19 -0
- package/dist/runtime/desktop.js +82 -0
- package/dist/runtime/types.d.ts +37 -0
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { getRequest } from './context.js';
|
|
2
|
+
function parseCookie(header, name) {
|
|
3
|
+
if (!header)
|
|
4
|
+
return null;
|
|
5
|
+
for (const part of header.split(';')) {
|
|
6
|
+
const [rawKey, ...rest] = part.split('=');
|
|
7
|
+
if ((rawKey ?? '').trim() !== name)
|
|
8
|
+
continue;
|
|
9
|
+
return rest.join('=').trim() || null;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
function getDesktopApiOrigin() {
|
|
14
|
+
const request = getRequest();
|
|
15
|
+
const headerOrigin = request.headers.get('x-kuratchi-desktop-api-origin')
|
|
16
|
+
|| request.headers.get('x-kuratchi-desktop-origin');
|
|
17
|
+
if (headerOrigin)
|
|
18
|
+
return headerOrigin;
|
|
19
|
+
const cookieOrigin = parseCookie(request.headers.get('cookie'), '__kuratchi_desktop_api');
|
|
20
|
+
if (!cookieOrigin)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
return decodeURIComponent(cookieOrigin);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return cookieOrigin;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export async function showDesktopNotification(payload) {
|
|
30
|
+
const title = payload.title?.trim();
|
|
31
|
+
if (!title) {
|
|
32
|
+
throw new Error('showDesktopNotification requires a title.');
|
|
33
|
+
}
|
|
34
|
+
const desktopApiOrigin = getDesktopApiOrigin();
|
|
35
|
+
if (!desktopApiOrigin) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const response = await fetch(new URL('/notifications/show', desktopApiOrigin), {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: {
|
|
41
|
+
'content-type': 'application/json',
|
|
42
|
+
},
|
|
43
|
+
body: JSON.stringify({
|
|
44
|
+
title,
|
|
45
|
+
body: payload.body ?? '',
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
if (response.status === 404) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
console.warn(`[kuratchi] Desktop notification request failed with status ${response.status}.`);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const payloadResult = await response.json().catch(() => null);
|
|
56
|
+
return payloadResult?.ok === true;
|
|
57
|
+
}
|
|
58
|
+
export async function runDesktopCommand(request) {
|
|
59
|
+
const command = request.command?.trim();
|
|
60
|
+
if (!command) {
|
|
61
|
+
throw new Error('runDesktopCommand requires a command.');
|
|
62
|
+
}
|
|
63
|
+
const desktopApiOrigin = getDesktopApiOrigin();
|
|
64
|
+
if (!desktopApiOrigin) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const response = await fetch(new URL('/commands/run', desktopApiOrigin), {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
'content-type': 'application/json',
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify({
|
|
73
|
+
command,
|
|
74
|
+
workingDirectory: request.workingDirectory ?? null,
|
|
75
|
+
timeoutMs: request.timeoutMs ?? 30000,
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
throw new Error(`[kuratchi] Desktop command request failed with status ${response.status}.`);
|
|
80
|
+
}
|
|
81
|
+
return await response.json();
|
|
82
|
+
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -78,6 +78,35 @@ export interface DatabaseConfig {
|
|
|
78
78
|
type?: 'd1' | 'do';
|
|
79
79
|
/** Skip migrations for this database (e.g., in production). Default: false */
|
|
80
80
|
skipMigrations?: boolean;
|
|
81
|
+
/** Use the deployed Cloudflare resource during local development. */
|
|
82
|
+
remote?: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface DesktopWindowConfig {
|
|
85
|
+
title?: string;
|
|
86
|
+
width?: number;
|
|
87
|
+
height?: number;
|
|
88
|
+
}
|
|
89
|
+
export interface DesktopRemoteBindingConfig {
|
|
90
|
+
type: 'd1' | 'r2';
|
|
91
|
+
remote?: boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface DesktopConfig {
|
|
94
|
+
/** Human-readable app name shown by the desktop host. */
|
|
95
|
+
appName?: string;
|
|
96
|
+
/** Stable app identifier used by the host/runtime. */
|
|
97
|
+
appId?: string;
|
|
98
|
+
/** Initial route loaded by the host. Defaults to '/'. */
|
|
99
|
+
initialPath?: string;
|
|
100
|
+
/** Single-window host settings. */
|
|
101
|
+
window?: DesktopWindowConfig;
|
|
102
|
+
/** Desktop-native bindings exposed by the host. */
|
|
103
|
+
bindings?: {
|
|
104
|
+
notifications?: boolean;
|
|
105
|
+
files?: boolean;
|
|
106
|
+
[key: string]: any;
|
|
107
|
+
};
|
|
108
|
+
/** Remote Cloudflare bindings the desktop runtime should proxy. */
|
|
109
|
+
remoteBindings?: Record<string, DesktopRemoteBindingConfig>;
|
|
81
110
|
}
|
|
82
111
|
/**
|
|
83
112
|
* Framework configuration â€" the user-facing config file (kuratchi.config.ts)
|
|
@@ -108,6 +137,12 @@ export interface kuratchiConfig<E extends Env = Env> {
|
|
|
108
137
|
ui?: {
|
|
109
138
|
/** Theme to inject: 'default' uses @kuratchi/ui's built-in theme, or a path to a custom CSS file */
|
|
110
139
|
theme?: 'default' | string;
|
|
140
|
+
/** Corner radius preference used by the built-in UI helpers. */
|
|
141
|
+
radius?: 'default' | 'none' | 'full';
|
|
142
|
+
/** Optional first-party styling library integration. */
|
|
143
|
+
library?: 'tailwindcss';
|
|
144
|
+
/** Optional plugin list for the selected UI library. */
|
|
145
|
+
plugins?: string[];
|
|
111
146
|
};
|
|
112
147
|
/** Auth configuration â€" @kuratchi/auth plugin setup */
|
|
113
148
|
auth?: AuthConfig | Record<string, any>;
|
|
@@ -137,6 +172,8 @@ export interface kuratchiConfig<E extends Env = Env> {
|
|
|
137
172
|
/** DO source files (e.g. ['auth.do.ts', 'sites.do.ts']) */
|
|
138
173
|
files?: string[];
|
|
139
174
|
}>;
|
|
175
|
+
/** Desktop target configuration consumed by `kuratchi run`. */
|
|
176
|
+
desktop?: DesktopConfig;
|
|
140
177
|
}
|
|
141
178
|
/** Auth configuration for kuratchi.config.ts */
|
|
142
179
|
export interface AuthConfig {
|