@astera-app/plugin-sdk 0.2.0 → 0.3.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/CHANGELOG.md +32 -0
- package/README.md +15 -1
- package/dist/cjs/index.d.ts +56 -12
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/panel.d.ts +129 -0
- package/dist/cjs/panel.js +87 -0
- package/dist/esm/index.d.ts +56 -12
- package/dist/esm/index.js +4 -2
- package/dist/esm/panel.d.ts +129 -0
- package/dist/esm/panel.js +84 -0
- package/dist/plugin-api.md +504 -0
- package/manifest.schema.json +245 -0
- package/package.json +13 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** The methods of `window.astera`, as Astera's bridge names them. Astera's own list is checked against this one. */
|
|
2
|
+
export declare const PANEL_METHODS: readonly ['context', 'net.request', 'net.cancel', 'secrets.list', 'secrets.request', 'secrets.delete', 'files.pick', 'files.read', 'files.create', 'files.save', 'files.onOpen', 'storage.get', 'storage.set', 'storage.delete', 'storage.keys', 'host.send', 'host.onMessage'];
|
|
3
|
+
export type PanelMethod = (typeof PANEL_METHODS)[number];
|
|
4
|
+
/** Every code a call can be refused with. A refused call rejects with an `Error` whose message is `CODE: sentence`,
|
|
5
|
+
* such as `NO_GESTURE: net.request needs a key press or click in the panel within the last 5 seconds`: read the code
|
|
6
|
+
* before the first `:`.
|
|
7
|
+
* The sentence is for a person, and may change. Astera's sources are checked against this list. */
|
|
8
|
+
export declare const PANEL_ERROR_CODES: readonly ['BAD_HANDLE', 'BAD_KEY', 'BAD_REQUEST', 'BAD_SECRET', 'BAD_VALUE', 'BLOCKED_ADDRESS', 'BUSY', 'CANCELLED', 'CONFLICT', 'ENCODING', 'EXISTS', 'FAILED', 'FORBIDDEN', 'HOST', 'INVALID_ARGUMENTS', 'NETWORK', 'NOT_ANSWERED', 'NOT_FOUND', 'NOT_GRANTED', 'NOT_INSTALLED', 'NOT_SUPPORTED', 'NO_GESTURE', 'NO_HOST_CODE', 'NO_PERMISSION', 'NO_PROJECT', 'OUTSIDE_PROJECT', 'PAYLOAD_NOT_JSON', 'PAYLOAD_TOO_LARGE', 'PLUGIN_FAILED', 'PLUGIN_NOT_RUNNING', 'PLUGIN_OFF', 'PRIVATE_ADDRESS', 'REDIRECT_LIMIT', 'REFUSED', 'REPLY_TOO_LARGE', 'SAFE_MODE', 'SAVE_FAILED', 'SECRET_NOT_BOUND', 'SECRET_UNKNOWN', 'STORAGE_FULL', 'TIMEOUT', 'TLS', 'TOO_LARGE', 'TOO_MANY_CALLS', 'TOO_MANY_REQUESTS', 'UNKNOWN_METHOD', 'UNSAVED_IN_EDITOR', 'WRONG_TYPE'];
|
|
9
|
+
export type PanelErrorCode = (typeof PANEL_ERROR_CODES)[number];
|
|
10
|
+
/** What the panel was opened as: its plugin's id, its panel's id, and the project its tab was opened in, when the
|
|
11
|
+
* plugin was granted `workspace.read`. */
|
|
12
|
+
export interface PanelContext {
|
|
13
|
+
plugin: string;
|
|
14
|
+
panel: string;
|
|
15
|
+
project?: {
|
|
16
|
+
root: string;
|
|
17
|
+
name: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** A request to the network. `body` is text, at most 10 MiB; `timeoutMs` up to 120,000 (30 seconds without it). A
|
|
21
|
+
* header value, a query value or the body may name a secret as `{{secret:<name>}}`. `id`, at most 64 characters, is
|
|
22
|
+
* what `net.cancel` takes; Astera makes one when it is left out. */
|
|
23
|
+
export interface PanelNetRequest {
|
|
24
|
+
method: string;
|
|
25
|
+
url: string;
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
body?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
id?: string;
|
|
30
|
+
}
|
|
31
|
+
/** A response. A text body is `text`; anything else comes as `base64`. Past 20 MiB the body is cut and `truncated` is
|
|
32
|
+
* set. `redirectedTo` is the origin a redirect pointed at that the plugin may not reach: the request stopped there. */
|
|
33
|
+
export interface PanelNetResponse {
|
|
34
|
+
status: number;
|
|
35
|
+
headers: Record<string, string>;
|
|
36
|
+
body: string;
|
|
37
|
+
bodyEncoding: 'text' | 'base64';
|
|
38
|
+
ms: number;
|
|
39
|
+
truncated?: true;
|
|
40
|
+
redirectedTo?: string;
|
|
41
|
+
}
|
|
42
|
+
/** A secret entered for the plugin's panels, by name, with the origins it may be sent to. A panel never reads a value. */
|
|
43
|
+
export interface PanelSecretInfo {
|
|
44
|
+
name: string;
|
|
45
|
+
origins: string[];
|
|
46
|
+
}
|
|
47
|
+
/** A file the person picked, named or opened in the panel: a handle, never a path, and the file's name. */
|
|
48
|
+
export interface PanelFileHandle {
|
|
49
|
+
handle: string;
|
|
50
|
+
name: string;
|
|
51
|
+
}
|
|
52
|
+
/** A file's UTF-8 text, at most 5 MiB, and the revision `files.save` must be given next. */
|
|
53
|
+
export interface PanelFileText {
|
|
54
|
+
text: string;
|
|
55
|
+
revision: string;
|
|
56
|
+
}
|
|
57
|
+
/** `window.astera` in a plugin panel. Each method answers a promise that rejects with `CODE: sentence` when Astera
|
|
58
|
+
* refuses the call (see `PANEL_ERROR_CODES`). Methods marked "key press or click" need one in the panel within the
|
|
59
|
+
* last 5 seconds. */
|
|
60
|
+
export interface AsteraPanelBridge {
|
|
61
|
+
context(): Promise<PanelContext>;
|
|
62
|
+
net: {
|
|
63
|
+
/** Needs `network.request`; key press or click. The first request to an origin the plugin may not reach yet asks
|
|
64
|
+
* the person. */
|
|
65
|
+
request(req: PanelNetRequest): Promise<PanelNetResponse>;
|
|
66
|
+
/** Needs `network.request`. */
|
|
67
|
+
cancel(id: string): Promise<{
|
|
68
|
+
cancelled: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
secrets: {
|
|
72
|
+
/** Needs `network.request`. */
|
|
73
|
+
list(): Promise<{
|
|
74
|
+
secrets: PanelSecretInfo[];
|
|
75
|
+
}>;
|
|
76
|
+
/** Needs `network.request`; key press or click. Asks the person to enter it, for origins the plugin already holds. */
|
|
77
|
+
request(name: string, label: string, options: {
|
|
78
|
+
origins: string[];
|
|
79
|
+
}): Promise<{
|
|
80
|
+
secrets: PanelSecretInfo[];
|
|
81
|
+
}>;
|
|
82
|
+
/** Needs `network.request`; key press or click. */
|
|
83
|
+
delete(name: string): Promise<{
|
|
84
|
+
secrets: PanelSecretInfo[];
|
|
85
|
+
}>;
|
|
86
|
+
};
|
|
87
|
+
files: {
|
|
88
|
+
/** Needs `files.read`; key press or click. Null when the person picked nothing. */
|
|
89
|
+
pick(options?: {
|
|
90
|
+
extensions?: string[];
|
|
91
|
+
}): Promise<PanelFileHandle | null>;
|
|
92
|
+
/** Needs `files.read`. */
|
|
93
|
+
read(handle: string): Promise<PanelFileText>;
|
|
94
|
+
/** Needs `files.write`; key press or click. Asks the person for a folder and a name in the project; null when they
|
|
95
|
+
* chose none. Its first save takes `revision: null`. */
|
|
96
|
+
create(options: {
|
|
97
|
+
suggestedName: string;
|
|
98
|
+
extensions?: string[];
|
|
99
|
+
}): Promise<PanelFileHandle | null>;
|
|
100
|
+
/** Needs `files.write`; key press or click. `revision` is the one last read or saved (`CONFLICT` otherwise). */
|
|
101
|
+
save(handle: string, text: string, options: {
|
|
102
|
+
revision: string | null;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
revision: string;
|
|
105
|
+
}>;
|
|
106
|
+
/** Needs `files.read`. Called with each file the person opens in this panel; answers how to stop listening. */
|
|
107
|
+
onOpen(listener: (file: PanelFileHandle) => void): () => void;
|
|
108
|
+
};
|
|
109
|
+
storage: {
|
|
110
|
+
/** The value stored under `key`: `undefined` when there is none, `null` for a stored null. */
|
|
111
|
+
get(key: string): Promise<unknown>;
|
|
112
|
+
/** A JSON value; keys of at most 128 characters, at most 5 MiB a plugin. */
|
|
113
|
+
set(key: string, value: unknown): Promise<null>;
|
|
114
|
+
delete(key: string): Promise<null>;
|
|
115
|
+
keys(): Promise<string[]>;
|
|
116
|
+
};
|
|
117
|
+
host: {
|
|
118
|
+
/** For a plugin with Host code: reaches its `onPanelMessage`, whose answer is the reply. JSON, at most 64 KiB. */
|
|
119
|
+
send(message: unknown): Promise<unknown>;
|
|
120
|
+
/** For a plugin with Host code: called with each message its `ctx.panels.post` sends; answers how to stop
|
|
121
|
+
* listening. */
|
|
122
|
+
onMessage(listener: (message: unknown) => void): () => void;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
declare global {
|
|
126
|
+
interface Window {
|
|
127
|
+
astera: AsteraPanelBridge;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// @astera-app/plugin-sdk/panel: what a plugin panel's page is written against (Plugin API 2, the panel broker of PE-B
|
|
2
|
+
// part 1). A panel runs as a web page in Astera, apart from the plugin's Host code, and reaches the network, files,
|
|
3
|
+
// secrets, a lasting store and its plugin's Host code only through `window.astera`, which Astera answers after checking
|
|
4
|
+
// the permission the person granted and, for some methods, a key press or click in the panel within the last 5 seconds.
|
|
5
|
+
//
|
|
6
|
+
// Reference it from the page's code to have `window.astera` typed:
|
|
7
|
+
// /// <reference types="@astera-app/plugin-sdk/panel" />
|
|
8
|
+
// or with a type import (`import type { AsteraPanelBridge } from '@astera-app/plugin-sdk/panel'`). The subpath needs
|
|
9
|
+
// `moduleResolution` `NodeNext` or `bundler`. At run time this entry holds only the two lists below; the bridge itself
|
|
10
|
+
// is Astera's.
|
|
11
|
+
/** The methods of `window.astera`, as Astera's bridge names them. Astera's own list is checked against this one. */
|
|
12
|
+
export const PANEL_METHODS = [
|
|
13
|
+
'context',
|
|
14
|
+
'net.request',
|
|
15
|
+
'net.cancel',
|
|
16
|
+
'secrets.list',
|
|
17
|
+
'secrets.request',
|
|
18
|
+
'secrets.delete',
|
|
19
|
+
'files.pick',
|
|
20
|
+
'files.read',
|
|
21
|
+
'files.create',
|
|
22
|
+
'files.save',
|
|
23
|
+
'files.onOpen',
|
|
24
|
+
'storage.get',
|
|
25
|
+
'storage.set',
|
|
26
|
+
'storage.delete',
|
|
27
|
+
'storage.keys',
|
|
28
|
+
'host.send',
|
|
29
|
+
'host.onMessage'
|
|
30
|
+
];
|
|
31
|
+
/** Every code a call can be refused with. A refused call rejects with an `Error` whose message is `CODE: sentence`,
|
|
32
|
+
* such as `NO_GESTURE: net.request needs a key press or click in the panel within the last 5 seconds`: read the code
|
|
33
|
+
* before the first `:`.
|
|
34
|
+
* The sentence is for a person, and may change. Astera's sources are checked against this list. */
|
|
35
|
+
export const PANEL_ERROR_CODES = [
|
|
36
|
+
'BAD_HANDLE',
|
|
37
|
+
'BAD_KEY',
|
|
38
|
+
'BAD_REQUEST',
|
|
39
|
+
'BAD_SECRET',
|
|
40
|
+
'BAD_VALUE',
|
|
41
|
+
'BLOCKED_ADDRESS',
|
|
42
|
+
'BUSY',
|
|
43
|
+
'CANCELLED',
|
|
44
|
+
'CONFLICT',
|
|
45
|
+
'ENCODING',
|
|
46
|
+
'EXISTS',
|
|
47
|
+
'FAILED',
|
|
48
|
+
'FORBIDDEN',
|
|
49
|
+
'HOST',
|
|
50
|
+
'INVALID_ARGUMENTS',
|
|
51
|
+
'NETWORK',
|
|
52
|
+
'NOT_ANSWERED',
|
|
53
|
+
'NOT_FOUND',
|
|
54
|
+
'NOT_GRANTED',
|
|
55
|
+
'NOT_INSTALLED',
|
|
56
|
+
'NOT_SUPPORTED',
|
|
57
|
+
'NO_GESTURE',
|
|
58
|
+
'NO_HOST_CODE',
|
|
59
|
+
'NO_PERMISSION',
|
|
60
|
+
'NO_PROJECT',
|
|
61
|
+
'OUTSIDE_PROJECT',
|
|
62
|
+
'PAYLOAD_NOT_JSON',
|
|
63
|
+
'PAYLOAD_TOO_LARGE',
|
|
64
|
+
'PLUGIN_FAILED',
|
|
65
|
+
'PLUGIN_NOT_RUNNING',
|
|
66
|
+
'PLUGIN_OFF',
|
|
67
|
+
'PRIVATE_ADDRESS',
|
|
68
|
+
'REDIRECT_LIMIT',
|
|
69
|
+
'REFUSED',
|
|
70
|
+
'REPLY_TOO_LARGE',
|
|
71
|
+
'SAFE_MODE',
|
|
72
|
+
'SAVE_FAILED',
|
|
73
|
+
'SECRET_NOT_BOUND',
|
|
74
|
+
'SECRET_UNKNOWN',
|
|
75
|
+
'STORAGE_FULL',
|
|
76
|
+
'TIMEOUT',
|
|
77
|
+
'TLS',
|
|
78
|
+
'TOO_LARGE',
|
|
79
|
+
'TOO_MANY_CALLS',
|
|
80
|
+
'TOO_MANY_REQUESTS',
|
|
81
|
+
'UNKNOWN_METHOD',
|
|
82
|
+
'UNSAVED_IN_EDITOR',
|
|
83
|
+
'WRONG_TYPE'
|
|
84
|
+
];
|