flarecms 0.2.2 → 0.2.3
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/dist/api/lib/cache.d.ts +18 -0
- package/dist/api/lib/response.d.ts +44 -0
- package/dist/api/middlewares/auth.d.ts +10 -0
- package/dist/api/middlewares/cors.d.ts +1 -0
- package/dist/api/middlewares/rbac.d.ts +21 -0
- package/dist/api/routes/auth.d.ts +6 -0
- package/dist/api/routes/collections.d.ts +6 -0
- package/dist/api/routes/content.d.ts +6 -0
- package/dist/api/routes/device.d.ts +6 -0
- package/dist/api/routes/magic.d.ts +6 -0
- package/dist/api/routes/mcp.d.ts +6 -0
- package/dist/api/routes/oauth.d.ts +6 -0
- package/dist/api/routes/plugins.d.ts +6 -0
- package/dist/api/routes/settings.d.ts +6 -0
- package/dist/api/routes/setup.d.ts +6 -0
- package/dist/api/routes/tokens.d.ts +6 -0
- package/dist/api/schemas/auth.d.ts +12 -0
- package/dist/api/schemas/index.d.ts +43 -0
- package/dist/api/schemas/tokens.d.ts +20 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/cli/commands.d.ts +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/mcp.d.ts +9 -0
- package/dist/cli/tests/cli.test.d.ts +1 -0
- package/dist/cli/tests/create-plugin-template.test.d.ts +1 -0
- package/dist/cli/tests/create.test.d.ts +1 -0
- package/dist/cli/tests/plugin.test.d.ts +1 -0
- package/dist/cli/tests/publish.test.d.ts +1 -0
- package/dist/client/FlareAdminRouter.d.ts +20 -0
- package/dist/client/app.d.ts +1 -0
- package/dist/client/components/app-sidebar.d.ts +5 -0
- package/dist/client/components/blocks/block-card.d.ts +7 -0
- package/dist/client/components/blocks/block-form.d.ts +7 -0
- package/dist/client/components/blocks/block-renderer.d.ts +10 -0
- package/dist/client/components/blocks/block-table.d.ts +7 -0
- package/dist/client/components/collection-modal.d.ts +6 -0
- package/dist/client/components/content-list.d.ts +3 -0
- package/dist/client/components/dynamic-form.d.ts +9 -0
- package/dist/client/components/field-modal.d.ts +8 -0
- package/dist/client/components/plugin-widget.d.ts +6 -0
- package/dist/client/components/settings/api-token-section.d.ts +1 -0
- package/dist/client/components/settings/general-section.d.ts +1 -0
- package/dist/client/components/settings/security-section.d.ts +1 -0
- package/dist/client/components/settings/seo-section.d.ts +1 -0
- package/dist/client/components/settings/signup-section.d.ts +1 -0
- package/dist/client/components/ui/accordion.d.ts +6 -0
- package/dist/client/components/ui/avatar.d.ts +11 -0
- package/dist/client/components/ui/badge.d.ts +7 -0
- package/dist/client/components/ui/button.d.ts +11 -0
- package/dist/client/components/ui/card.d.ts +11 -0
- package/dist/client/components/ui/checkbox.d.ts +3 -0
- package/dist/client/components/ui/collapsible.d.ts +5 -0
- package/dist/client/components/ui/dialog.d.ts +17 -0
- package/dist/client/components/ui/icon-picker.d.ts +27 -0
- package/dist/client/components/ui/icons-data.d.ts +5 -0
- package/dist/client/components/ui/input.d.ts +3 -0
- package/dist/client/components/ui/label.d.ts +3 -0
- package/dist/client/components/ui/popover.d.ts +10 -0
- package/dist/client/components/ui/select.d.ts +15 -0
- package/dist/client/components/ui/separator.d.ts +3 -0
- package/dist/client/components/ui/sheet.d.ts +14 -0
- package/dist/client/components/ui/sidebar.d.ts +63 -0
- package/dist/client/components/ui/skeleton.d.ts +2 -0
- package/dist/client/components/ui/sonner.d.ts +3 -0
- package/dist/client/components/ui/switch.d.ts +5 -0
- package/dist/client/components/ui/table.d.ts +10 -0
- package/dist/client/components/ui/tabs.d.ts +10 -0
- package/dist/client/components/ui/textarea.d.ts +3 -0
- package/dist/client/components/ui/tooltip.d.ts +6 -0
- package/dist/client/hooks/use-mobile.d.ts +1 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/layouts/admin-layout.d.ts +6 -0
- package/dist/client/layouts/settings-layout.d.ts +6 -0
- package/dist/client/lib/api.d.ts +18 -0
- package/dist/client/lib/block-registry.d.ts +24 -0
- package/dist/client/lib/block-types.d.ts +132 -0
- package/dist/client/lib/utils.d.ts +2 -0
- package/dist/client/main.d.ts +1 -0
- package/dist/client/pages/collection-detail.d.ts +7 -0
- package/dist/client/pages/collections.d.ts +1 -0
- package/dist/client/pages/dashboard.d.ts +1 -0
- package/dist/client/pages/device.d.ts +1 -0
- package/dist/client/pages/document-detail-page.d.ts +1 -0
- package/dist/client/pages/documents-page.d.ts +1 -0
- package/dist/client/pages/login.d.ts +1 -0
- package/dist/client/pages/plugin-manager.d.ts +1 -0
- package/dist/client/pages/plugin-page.d.ts +6 -0
- package/dist/client/pages/settings.d.ts +1 -0
- package/dist/client/pages/setup.d.ts +1 -0
- package/dist/client/pages/signup.d.ts +1 -0
- package/dist/client/store/auth.d.ts +10 -0
- package/dist/client/store/collections.d.ts +3 -0
- package/dist/client/store/config.d.ts +4 -0
- package/dist/client/store/fetcher.d.ts +4 -0
- package/dist/client/store/plugins.d.ts +21 -0
- package/dist/client/store/router.d.ts +84 -0
- package/dist/client/store/schema.d.ts +7 -0
- package/dist/client/store/settings.d.ts +7 -0
- package/dist/client/types.d.ts +31 -0
- package/dist/db/dynamic.d.ts +5 -0
- package/dist/db/index.d.ts +8 -0
- package/dist/db/migrations/001_initial_schema.d.ts +3 -0
- package/dist/db/migrations/002_auth_tables.d.ts +3 -0
- package/dist/db/migrations/003_plugins.d.ts +3 -0
- package/dist/db/migrator.d.ts +10 -0
- package/dist/db/schema.d.ts +151 -0
- package/dist/index.d.ts +11 -0
- package/dist/plugins/adapt-entry.d.ts +5 -0
- package/dist/plugins/context.d.ts +21 -0
- package/dist/plugins/define-plugin.d.ts +22 -0
- package/dist/plugins/hooks.d.ts +37 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/manager.d.ts +41 -0
- package/dist/plugins/middleware.d.ts +8 -0
- package/dist/plugins/noop-sandbox.d.ts +18 -0
- package/dist/plugins/routes.d.ts +32 -0
- package/dist/plugins/sandbox/bridge.d.ts +45 -0
- package/dist/plugins/sandbox/runner.d.ts +14 -0
- package/dist/plugins/sandbox/types.d.ts +71 -0
- package/dist/plugins/sandbox/wrapper.d.ts +6 -0
- package/dist/plugins/types.d.ts +725 -0
- package/dist/server/index.d.ts +18 -0
- package/dist/types.d.ts +19 -0
- package/package.json +1 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
|
|
2
|
+
export interface Database {
|
|
3
|
+
options: OptionsTable;
|
|
4
|
+
fc_collections: CollectionsTable;
|
|
5
|
+
fc_fields: FieldsTable;
|
|
6
|
+
fc_users: UsersTable;
|
|
7
|
+
fc_passkeys: PasskeysTable;
|
|
8
|
+
fc_sessions: SessionsTable;
|
|
9
|
+
fc_api_tokens: ApiTokensTable;
|
|
10
|
+
fc_oauth_accounts: OAuthAccountsTable;
|
|
11
|
+
fc_verification_tokens: VerificationTokensTable;
|
|
12
|
+
fc_device_codes: DeviceCodesTable;
|
|
13
|
+
fc_plugins: PluginsTable;
|
|
14
|
+
_fc_plugin_storage: PluginStorageTable;
|
|
15
|
+
_fc_cron_tasks: CronTasksTable;
|
|
16
|
+
[tableName: string]: any;
|
|
17
|
+
}
|
|
18
|
+
export interface PluginsTable {
|
|
19
|
+
id: string;
|
|
20
|
+
plugin_id: string;
|
|
21
|
+
version: string;
|
|
22
|
+
status: string;
|
|
23
|
+
capabilities: string | null;
|
|
24
|
+
allowed_hosts: string | null;
|
|
25
|
+
storage_config: string | null;
|
|
26
|
+
manifest: string | null;
|
|
27
|
+
backend_code: string | null;
|
|
28
|
+
installed_at: ColumnType<string, string | undefined, never>;
|
|
29
|
+
activated_at: string | null;
|
|
30
|
+
}
|
|
31
|
+
export interface PluginStorageTable {
|
|
32
|
+
plugin_id: string;
|
|
33
|
+
collection: string;
|
|
34
|
+
id: string;
|
|
35
|
+
data: string;
|
|
36
|
+
updated_at: ColumnType<string, string | undefined, string>;
|
|
37
|
+
}
|
|
38
|
+
export interface CronTasksTable {
|
|
39
|
+
id: string;
|
|
40
|
+
plugin_id: string;
|
|
41
|
+
schedule: string;
|
|
42
|
+
last_run_at: string | null;
|
|
43
|
+
next_run_at: string | null;
|
|
44
|
+
enabled: ColumnType<number, number | undefined, number>;
|
|
45
|
+
}
|
|
46
|
+
export interface OptionsTable {
|
|
47
|
+
name: string;
|
|
48
|
+
value: string;
|
|
49
|
+
}
|
|
50
|
+
export type Option = Selectable<OptionsTable>;
|
|
51
|
+
export type NewOption = Insertable<OptionsTable>;
|
|
52
|
+
export interface CollectionsTable {
|
|
53
|
+
id: string;
|
|
54
|
+
slug: string;
|
|
55
|
+
label: string;
|
|
56
|
+
label_singular: string | null;
|
|
57
|
+
description: string | null;
|
|
58
|
+
icon: string | null;
|
|
59
|
+
is_public: ColumnType<number, number | undefined, number>;
|
|
60
|
+
features: string | null;
|
|
61
|
+
url_pattern: string | null;
|
|
62
|
+
created_at: ColumnType<string, string | undefined, never>;
|
|
63
|
+
updated_at: ColumnType<string, string | undefined, string>;
|
|
64
|
+
}
|
|
65
|
+
export type Collection = Selectable<CollectionsTable>;
|
|
66
|
+
export type NewCollection = Insertable<CollectionsTable>;
|
|
67
|
+
export type CollectionUpdate = Updateable<CollectionsTable>;
|
|
68
|
+
export interface FieldsTable {
|
|
69
|
+
id: string;
|
|
70
|
+
collection_id: string;
|
|
71
|
+
label: string;
|
|
72
|
+
slug: string;
|
|
73
|
+
type: string;
|
|
74
|
+
required: ColumnType<number, number | undefined, number>;
|
|
75
|
+
created_at: ColumnType<string, string | undefined, never>;
|
|
76
|
+
}
|
|
77
|
+
export type Field = Selectable<FieldsTable>;
|
|
78
|
+
export type NewField = Insertable<FieldsTable>;
|
|
79
|
+
export interface UsersTable {
|
|
80
|
+
id: string;
|
|
81
|
+
email: string;
|
|
82
|
+
password: string | null;
|
|
83
|
+
role: string;
|
|
84
|
+
disabled: ColumnType<number, number | undefined, number>;
|
|
85
|
+
created_at: ColumnType<string, string | undefined, never>;
|
|
86
|
+
updated_at: ColumnType<string, string | undefined, string>;
|
|
87
|
+
}
|
|
88
|
+
export type User = Selectable<UsersTable>;
|
|
89
|
+
export type NewUser = Insertable<UsersTable>;
|
|
90
|
+
export type UserUpdate = Updateable<UsersTable>;
|
|
91
|
+
export interface PasskeysTable {
|
|
92
|
+
id: string;
|
|
93
|
+
user_id: string;
|
|
94
|
+
name: string | null;
|
|
95
|
+
public_key: string;
|
|
96
|
+
counter: number;
|
|
97
|
+
device_type: string;
|
|
98
|
+
backed_up: number;
|
|
99
|
+
transports: string | null;
|
|
100
|
+
created_at: ColumnType<string, string | undefined, never>;
|
|
101
|
+
last_used_at: string | null;
|
|
102
|
+
}
|
|
103
|
+
export type Passkey = Selectable<PasskeysTable>;
|
|
104
|
+
export type NewPasskey = Insertable<PasskeysTable>;
|
|
105
|
+
export type PasskeyUpdate = Updateable<PasskeysTable>;
|
|
106
|
+
export interface SessionsTable {
|
|
107
|
+
id: string;
|
|
108
|
+
user_id: string;
|
|
109
|
+
expires_at: string;
|
|
110
|
+
}
|
|
111
|
+
export type Session = Selectable<SessionsTable>;
|
|
112
|
+
export type NewSession = Insertable<SessionsTable>;
|
|
113
|
+
export type SessionUpdate = Updateable<SessionsTable>;
|
|
114
|
+
export interface ApiTokensTable {
|
|
115
|
+
id: string;
|
|
116
|
+
user_id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
hash: string;
|
|
119
|
+
scopes: string;
|
|
120
|
+
expires_at: string | null;
|
|
121
|
+
last_used_at: string | null;
|
|
122
|
+
created_at: ColumnType<string, string | undefined, never>;
|
|
123
|
+
}
|
|
124
|
+
export type ApiToken = Selectable<ApiTokensTable>;
|
|
125
|
+
export type NewApiToken = Insertable<ApiTokensTable>;
|
|
126
|
+
export interface OAuthAccountsTable {
|
|
127
|
+
provider_id: string;
|
|
128
|
+
provider_user_id: string;
|
|
129
|
+
user_id: string;
|
|
130
|
+
}
|
|
131
|
+
export type OAuthAccount = Selectable<OAuthAccountsTable>;
|
|
132
|
+
export type NewOAuthAccount = Insertable<OAuthAccountsTable>;
|
|
133
|
+
export interface VerificationTokensTable {
|
|
134
|
+
identifier: string;
|
|
135
|
+
token: string;
|
|
136
|
+
expires_at: string;
|
|
137
|
+
}
|
|
138
|
+
export type VerificationToken = Selectable<VerificationTokensTable>;
|
|
139
|
+
export type NewVerificationToken = Insertable<VerificationTokensTable>;
|
|
140
|
+
export interface DeviceCodesTable {
|
|
141
|
+
device_code: string;
|
|
142
|
+
user_code: string;
|
|
143
|
+
client_id: string;
|
|
144
|
+
user_id: string | null;
|
|
145
|
+
scopes: string;
|
|
146
|
+
expires_at: string;
|
|
147
|
+
created_at: ColumnType<string, string | undefined, never>;
|
|
148
|
+
}
|
|
149
|
+
export type DeviceCode = Selectable<DeviceCodesTable>;
|
|
150
|
+
export type NewDeviceCode = Insertable<DeviceCodesTable>;
|
|
151
|
+
export type DeviceCodeUpdate = Updateable<DeviceCodesTable>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './auth';
|
|
2
|
+
export * from './db';
|
|
3
|
+
export * from './server';
|
|
4
|
+
export * from './client';
|
|
5
|
+
export * from './types';
|
|
6
|
+
import { createFlareAPI } from './server';
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use createFlareAPI from 'flarecms/server' for better modularity.
|
|
9
|
+
*/
|
|
10
|
+
export declare const flarecms: typeof createFlareAPI;
|
|
11
|
+
export * from './plugins';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { FlareDb } from '../db/index.js';
|
|
2
|
+
import type { PluginContext, PluginCapability } from './types.js';
|
|
3
|
+
export interface ContextFactoryOptions {
|
|
4
|
+
pluginId: string;
|
|
5
|
+
version: string;
|
|
6
|
+
capabilities: PluginCapability[];
|
|
7
|
+
allowedHosts: string[];
|
|
8
|
+
storageCollections: string[];
|
|
9
|
+
db: FlareDb;
|
|
10
|
+
siteInfo: {
|
|
11
|
+
name: string;
|
|
12
|
+
url: string;
|
|
13
|
+
locale: string;
|
|
14
|
+
};
|
|
15
|
+
encryptionSecret?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Creates an in-process (trusted) PluginContext.
|
|
19
|
+
* Operations are executed directly against the provided database.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createPluginContext(options: ContextFactoryOptions): PluginContext;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FlarePluginDefinition } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* definePlugin() Helper
|
|
4
|
+
*
|
|
5
|
+
* Creates a properly typed plugin definition. This is an identity function
|
|
6
|
+
* that provides type inference and basic validation for the standard plugin format.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { definePlugin } from "flarecms/plugins";
|
|
11
|
+
*
|
|
12
|
+
* export default definePlugin({
|
|
13
|
+
* hooks: {
|
|
14
|
+
* "content:afterSave": async (event, ctx) => {
|
|
15
|
+
* ctx.log.info("Content saved!");
|
|
16
|
+
* },
|
|
17
|
+
* },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function definePlugin<T extends FlarePluginDefinition>(definition: T): T;
|
|
22
|
+
export default definePlugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ResolvedPlugin } from './types.js';
|
|
2
|
+
import type { FlareDb } from '../db/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* HookPipeline manages the registration and execution of hooks across all plugins.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HookPipeline {
|
|
7
|
+
private hooks;
|
|
8
|
+
private plugins;
|
|
9
|
+
private db;
|
|
10
|
+
private siteInfo;
|
|
11
|
+
constructor(plugins: ResolvedPlugin[], db: FlareDb, siteInfo: {
|
|
12
|
+
name: string;
|
|
13
|
+
url: string;
|
|
14
|
+
locale: string;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Run a chain of hooks that can modify the event data (Waterfall pattern).
|
|
18
|
+
* Example: content:beforeSave
|
|
19
|
+
*/
|
|
20
|
+
runChain<T>(hookName: string, initialData: T): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Run all hooks in parallel (Fire-and-forget pattern).
|
|
23
|
+
* Example: content:afterSave
|
|
24
|
+
*/
|
|
25
|
+
runParallel(hookName: string, event: unknown): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Run hooks where any hook returning 'false' aborts the operation.
|
|
28
|
+
* Example: content:beforeDelete
|
|
29
|
+
*/
|
|
30
|
+
runVeto(hookName: string, event: unknown): Promise<boolean>;
|
|
31
|
+
runContentBeforeSave(content: Record<string, unknown>, collection: string, isNew: boolean): Promise<Record<string, unknown>>;
|
|
32
|
+
runContentAfterSave(content: Record<string, unknown>, collection: string, isNew: boolean): Promise<void>;
|
|
33
|
+
runContentBeforeDelete(id: string, collection: string): Promise<boolean>;
|
|
34
|
+
runContentAfterDelete(id: string, collection: string): Promise<void>;
|
|
35
|
+
private createContextForHook;
|
|
36
|
+
private executeWithTimeout;
|
|
37
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { definePlugin } from './define-plugin.js';
|
|
2
|
+
export { PluginManager } from './manager.js';
|
|
3
|
+
export { NoopSandboxRunner, SandboxNotAvailableError } from './noop-sandbox.js';
|
|
4
|
+
export { adaptEntry } from './adapt-entry.js';
|
|
5
|
+
export { createPluginContext } from './context.js';
|
|
6
|
+
export { pluginMiddleware } from './middleware.js';
|
|
7
|
+
export type { BlockInteraction, BlockResponse, FlarePluginDefinition, FlarePlugin, PluginDescriptor, PluginManifest, PluginContext, SandboxRunner, SandboxRunnerFactory, PluginCapability, SerializedRequest, RouteCtx, } from './types';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type InvokeRouteOptions } from './routes.js';
|
|
2
|
+
import type { ResolvedPlugin, BlockInteraction, BlockResponse } from './types.js';
|
|
3
|
+
import type { FlareDb } from '../db/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* PluginManager is the central orchestrator for the FlareCMS plugin system.
|
|
6
|
+
* It coordinates hook execution, route handling, and plugin lifecycle.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PluginManager {
|
|
9
|
+
plugins: ResolvedPlugin[];
|
|
10
|
+
db: FlareDb;
|
|
11
|
+
siteInfo: {
|
|
12
|
+
name: string;
|
|
13
|
+
url: string;
|
|
14
|
+
locale: string;
|
|
15
|
+
};
|
|
16
|
+
encryptionSecret?: string | undefined;
|
|
17
|
+
private hookPipeline;
|
|
18
|
+
private routeRegistry;
|
|
19
|
+
constructor(plugins: ResolvedPlugin[], db: FlareDb, siteInfo: {
|
|
20
|
+
name: string;
|
|
21
|
+
url: string;
|
|
22
|
+
locale: string;
|
|
23
|
+
}, encryptionSecret?: string | undefined);
|
|
24
|
+
runContentBeforeSave(content: Record<string, unknown>, collection: string, isNew: boolean): Promise<Record<string, unknown>>;
|
|
25
|
+
runContentAfterSave(content: Record<string, unknown>, collection: string, isNew: boolean): Promise<void>;
|
|
26
|
+
runContentBeforeDelete(id: string, collection: string): Promise<boolean>;
|
|
27
|
+
runContentAfterDelete(id: string, collection: string): Promise<void>;
|
|
28
|
+
invokeRoute(pluginId: string, routeName: string, options: InvokeRouteOptions): Promise<unknown>;
|
|
29
|
+
/**
|
|
30
|
+
* Invokes the administrative UI handler for a plugin.
|
|
31
|
+
*/
|
|
32
|
+
invokeAdmin(pluginId: string, interaction: BlockInteraction): Promise<BlockResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the list of active plugins and their basic info.
|
|
35
|
+
*/
|
|
36
|
+
getActivePlugins(): ResolvedPlugin[];
|
|
37
|
+
/**
|
|
38
|
+
* Checks if a specific plugin is loaded and active.
|
|
39
|
+
*/
|
|
40
|
+
isActive(pluginId: string): boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
import type { FlarePlugin, PluginDescriptor } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Hono middleware to initialize the PluginManager.
|
|
5
|
+
*
|
|
6
|
+
* @param staticPlugins - Plugins declared at build-time/config.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pluginMiddleware(staticPlugins?: (PluginDescriptor | FlarePlugin)[]): MiddlewareHandler;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SandboxRunner, SandboxedPlugin, PluginManifest } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when a sandboxed operation is attempted but no sandbox runner is available.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SandboxNotAvailableError extends Error {
|
|
6
|
+
constructor(reason?: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* No-op Sandbox Runner
|
|
10
|
+
*
|
|
11
|
+
* Acts as a fallback for environments where sandboxing (e.g. Worker Loader)
|
|
12
|
+
* is not supported or configured.
|
|
13
|
+
*/
|
|
14
|
+
export declare class NoopSandboxRunner implements SandboxRunner {
|
|
15
|
+
isAvailable(): boolean;
|
|
16
|
+
load(_manifest: PluginManifest, _code: string): Promise<SandboxedPlugin>;
|
|
17
|
+
terminateAll(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ResolvedPlugin, SerializedRequest } from './types.js';
|
|
2
|
+
import type { FlareDb } from '../db/index.js';
|
|
3
|
+
export interface InvokeRouteOptions {
|
|
4
|
+
input: unknown;
|
|
5
|
+
request: SerializedRequest;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* PluginRouteRegistry manages custom HTTP routes exposed by plugins.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PluginRouteRegistry {
|
|
11
|
+
private plugins;
|
|
12
|
+
private db;
|
|
13
|
+
private siteInfo;
|
|
14
|
+
private encryptionSecret?;
|
|
15
|
+
constructor(db: FlareDb, siteInfo: {
|
|
16
|
+
name: string;
|
|
17
|
+
url: string;
|
|
18
|
+
locale: string;
|
|
19
|
+
}, encryptionSecret?: string);
|
|
20
|
+
/**
|
|
21
|
+
* Registers all routes for a given plugin.
|
|
22
|
+
*/
|
|
23
|
+
register(plugin: ResolvedPlugin): void;
|
|
24
|
+
/**
|
|
25
|
+
* Invokes a specific plugin route.
|
|
26
|
+
*/
|
|
27
|
+
invoke(pluginId: string, routeName: string, options: InvokeRouteOptions): Promise<unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets all registered routes for a specific plugin.
|
|
30
|
+
*/
|
|
31
|
+
getRoutes(pluginId: string): string[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { WorkerEntrypoint } from 'cloudflare:workers';
|
|
2
|
+
import type { PluginBridgeInterface, PluginBridgeEnv } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* PluginBridge is the RPC gateway that runs in the Host process.
|
|
5
|
+
* It exposes secure methods to the Sandboxed Plugin via Service Bindings.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PluginBridge extends WorkerEntrypoint<PluginBridgeEnv> implements PluginBridgeInterface {
|
|
8
|
+
private props;
|
|
9
|
+
constructor(ctx: any, env: PluginBridgeEnv);
|
|
10
|
+
private get db();
|
|
11
|
+
private hasCap;
|
|
12
|
+
kvGet(key: string): Promise<any>;
|
|
13
|
+
kvSet(key: string, value: any): Promise<void>;
|
|
14
|
+
kvDelete(key: string): Promise<boolean>;
|
|
15
|
+
kvList(prefix?: string): Promise<{
|
|
16
|
+
key: any;
|
|
17
|
+
value: any;
|
|
18
|
+
}[]>;
|
|
19
|
+
storageGet(collection: string, id: string): Promise<any>;
|
|
20
|
+
storagePut(collection: string, id: string, data: any): Promise<void>;
|
|
21
|
+
storageDelete(collection: string, id: string): Promise<boolean>;
|
|
22
|
+
storageQuery(collection: string, opts?: any): Promise<{
|
|
23
|
+
items: any[];
|
|
24
|
+
hasMore: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
contentGet(collection: string, id: string): Promise<{
|
|
27
|
+
[x: string]: any;
|
|
28
|
+
} | undefined>;
|
|
29
|
+
contentList(collection: string, opts?: any): Promise<{
|
|
30
|
+
items: {
|
|
31
|
+
[x: string]: any;
|
|
32
|
+
}[];
|
|
33
|
+
hasMore: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
contentCreate(collection: string, data: any): Promise<import("kysely").InsertResult[]>;
|
|
36
|
+
contentUpdate(collection: string, id: string, data: any): Promise<import("kysely").UpdateResult[]>;
|
|
37
|
+
contentDelete(collection: string, id: string): Promise<boolean>;
|
|
38
|
+
httpFetch(url: string, init?: any): Promise<{
|
|
39
|
+
status: number;
|
|
40
|
+
ok: boolean;
|
|
41
|
+
headers: Record<string, string>;
|
|
42
|
+
text: string;
|
|
43
|
+
}>;
|
|
44
|
+
log(level: string, message: string, data?: any): void;
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SandboxRunner, SandboxedPlugin, PluginManifest, SandboxOptions } from '../types.js';
|
|
2
|
+
import type { WorkerLoader } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sandbox Runner implementation for Cloudflare Workers.
|
|
5
|
+
* Uses the dynamic 'Worker Loader' API to spawn V8 isolates.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CloudflareSandboxRunner implements SandboxRunner {
|
|
8
|
+
private loader;
|
|
9
|
+
private options;
|
|
10
|
+
constructor(loader: WorkerLoader, options: SandboxOptions);
|
|
11
|
+
isAvailable(): boolean;
|
|
12
|
+
load(manifest: PluginManifest, code: string): Promise<SandboxedPlugin>;
|
|
13
|
+
terminateAll(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { PluginCapability } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for the Cloudflare Worker Loader API.
|
|
4
|
+
*/
|
|
5
|
+
export interface WorkerLoader {
|
|
6
|
+
get(id: string, configFactory: () => WorkerLoaderConfig): WorkerStub;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for a dynamic worker.
|
|
10
|
+
*/
|
|
11
|
+
export interface WorkerLoaderConfig {
|
|
12
|
+
compatibilityDate?: string;
|
|
13
|
+
compatibilityFlags?: string[];
|
|
14
|
+
mainModule: string;
|
|
15
|
+
modules: Record<string, {
|
|
16
|
+
js: string;
|
|
17
|
+
} | {
|
|
18
|
+
text: string;
|
|
19
|
+
} | {
|
|
20
|
+
data: ArrayBuffer;
|
|
21
|
+
}>;
|
|
22
|
+
env?: Record<string, any>;
|
|
23
|
+
limits?: {
|
|
24
|
+
cpuMs?: number;
|
|
25
|
+
subRequests?: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A stub for interacting with a dynamic worker.
|
|
30
|
+
*/
|
|
31
|
+
export interface WorkerStub {
|
|
32
|
+
fetch(request: Request | string, init?: RequestInit): Promise<Response>;
|
|
33
|
+
get(pluginId: string): any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Metadata passed to the PluginBridge when it's instantiated.
|
|
37
|
+
*/
|
|
38
|
+
export interface PluginBridgeProps {
|
|
39
|
+
pluginId: string;
|
|
40
|
+
version: string;
|
|
41
|
+
capabilities: PluginCapability[];
|
|
42
|
+
allowedHosts: string[];
|
|
43
|
+
storageCollections: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Typing for the environment available to the PluginBridge.
|
|
47
|
+
*/
|
|
48
|
+
export interface PluginBridgeEnv {
|
|
49
|
+
DB: any;
|
|
50
|
+
KV: any;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The RPC interface exposed by the PluginBridge.
|
|
54
|
+
*/
|
|
55
|
+
export interface PluginBridgeInterface {
|
|
56
|
+
kvGet(key: string): Promise<any>;
|
|
57
|
+
kvSet(key: string, value: any): Promise<void>;
|
|
58
|
+
kvDelete(key: string): Promise<boolean>;
|
|
59
|
+
kvList(prefix?: string): Promise<any[]>;
|
|
60
|
+
storageGet(collection: string, id: string): Promise<any>;
|
|
61
|
+
storagePut(collection: string, id: string, data: any): Promise<void>;
|
|
62
|
+
storageDelete(collection: string, id: string): Promise<boolean>;
|
|
63
|
+
storageQuery(collection: string, opts?: any): Promise<any>;
|
|
64
|
+
contentGet(collection: string, id: string): Promise<any>;
|
|
65
|
+
contentList(collection: string, opts?: any): Promise<any>;
|
|
66
|
+
contentCreate(collection: string, data: any): Promise<any>;
|
|
67
|
+
contentUpdate(collection: string, id: string, data: any): Promise<any>;
|
|
68
|
+
contentDelete(collection: string, id: string): Promise<boolean>;
|
|
69
|
+
httpFetch(url: string, init?: any): Promise<any>;
|
|
70
|
+
log(level: string, message: string, data?: any): void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PluginManifest } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generates the JavaScript wrapper code that runs inside the Worker Isolate.
|
|
4
|
+
* It sets up the RPC bridge to the host and provides the PluginContext.
|
|
5
|
+
*/
|
|
6
|
+
export declare function generatePluginWrapper(manifest: PluginManifest): string;
|