flint-plugin-api 0.11.0 → 0.13.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 +5 -2
- package/index.d.ts +34 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,11 +28,12 @@ A plugin is a folder inside a vault's `.flint/plugins/` directory:
|
|
|
28
28
|
"version": "1.0.0",
|
|
29
29
|
"author": "You",
|
|
30
30
|
"description": "What it does.",
|
|
31
|
-
"license": "AGPL-3.0-or-later"
|
|
31
|
+
"license": "AGPL-3.0-or-later",
|
|
32
|
+
"minAppVersion": "0.12.0"
|
|
32
33
|
}
|
|
33
34
|
```
|
|
34
35
|
|
|
35
|
-
The `license` is an [SPDX expression](https://spdx.org/licenses/). Flint is AGPL-3.0-or-later, so plugins must use a compatible free license; Flint warns before enabling a plugin that doesn't.
|
|
36
|
+
The `license` is an [SPDX expression](https://spdx.org/licenses/). Flint is AGPL-3.0-or-later, so plugins must use a compatible free license; Flint warns before enabling a plugin that doesn't. `minAppVersion` is optional: older versions of Flint refuse to load the plugin and say which version it needs.
|
|
36
37
|
|
|
37
38
|
`main.js` is an ES module whose default export receives the Flint API:
|
|
38
39
|
|
|
@@ -50,6 +51,8 @@ Everything registered through the API (commands, editor extensions, sidebar tabs
|
|
|
50
51
|
|
|
51
52
|
Use `flint.codemirror` instead of bundling your own copy of CodeMirror; two copies in the same editor break it.
|
|
52
53
|
|
|
54
|
+
To talk to a web service, use `flint.http.request()`: it runs in Flint's backend, so the server doesn't have to allow the app's origin (CORS), and it trusts certificates from the system's store. Keep tokens and passwords in `flint.secrets`, which stores them in the system's keychain instead of the vault. `flint.ui.renderDataView()` shows your own rows with the views of Bases (table, cards, list and map) along with their filters, sorting and summaries.
|
|
55
|
+
|
|
53
56
|
For type hints, copy [`index.d.ts`](index.d.ts) next to your plugin and annotate `activate` with `/** @type {import('./index').ActivatePlugin} */`. See it for the full API and [`examples/word-count`](../examples/word-count) for a working plugin. To try it, copy the folder into your vault's `.flint/plugins/` and turn it on in Settings.
|
|
54
57
|
|
|
55
58
|
Plugins run inside Flint with the same access as the app itself. Only turn on plugins you trust.
|
package/index.d.ts
CHANGED
|
@@ -65,6 +65,25 @@ export type CodeBlockProcessor = (
|
|
|
65
65
|
context: MarkdownContext,
|
|
66
66
|
) => unknown
|
|
67
67
|
|
|
68
|
+
export interface HttpRequest {
|
|
69
|
+
/** An `http://` or `https://` URL. */
|
|
70
|
+
url: string
|
|
71
|
+
/** Defaults to `GET`. */
|
|
72
|
+
method?: string
|
|
73
|
+
headers?: Record<string, string>
|
|
74
|
+
body?: string
|
|
75
|
+
/** Defaults to 30 seconds. */
|
|
76
|
+
timeoutMs?: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface HttpResponse {
|
|
80
|
+
status: number
|
|
81
|
+
headers: Record<string, string>
|
|
82
|
+
body: string
|
|
83
|
+
/** The body parsed as JSON. */
|
|
84
|
+
json<T = unknown>(): T
|
|
85
|
+
}
|
|
86
|
+
|
|
68
87
|
/** A row a plugin shows in a data view. */
|
|
69
88
|
export interface DataRow {
|
|
70
89
|
/** Unique within the view. */
|
|
@@ -132,6 +151,8 @@ export interface FlintApi {
|
|
|
132
151
|
|
|
133
152
|
ui: {
|
|
134
153
|
notice(message: string): void
|
|
154
|
+
/** Opens a web or mail link in the system's default app. */
|
|
155
|
+
openUrl(url: string): void
|
|
135
156
|
registerSidebarTab(tab: SidebarTab): Disposer
|
|
136
157
|
/** Adds a section named after the plugin to Settings. */
|
|
137
158
|
registerSettingsTab(tab: SettingsTab): Disposer
|
|
@@ -147,6 +168,19 @@ export interface FlintApi {
|
|
|
147
168
|
registerCodeBlockProcessor(language: string, processor: CodeBlockProcessor): Disposer
|
|
148
169
|
}
|
|
149
170
|
|
|
171
|
+
/** Requests made from Flint's backend, so servers don't need to allow the app's origin (CORS).
|
|
172
|
+
* Certificates are checked against the system's store, where companies install their own. */
|
|
173
|
+
http: {
|
|
174
|
+
request(request: HttpRequest): Promise<HttpResponse>
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Secrets such as API tokens, kept in the system's keychain rather than in the vault. */
|
|
178
|
+
secrets: {
|
|
179
|
+
get(key: string): Promise<string | null>
|
|
180
|
+
set(key: string, value: string): Promise<void>
|
|
181
|
+
delete(key: string): Promise<void>
|
|
182
|
+
}
|
|
183
|
+
|
|
150
184
|
storage: {
|
|
151
185
|
load<T = unknown>(): Promise<T | null>
|
|
152
186
|
save(data: unknown): Promise<void>
|