@shiqianjiang/ceru-plugin-sdk 0.3.15 → 3.0.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 +14 -4
- package/dist/accounts.d.ts +107 -1
- package/dist/accounts.js +14 -0
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.js +23 -0
- package/dist/crypto-streams.d.ts +10 -0
- package/dist/crypto-streams.js +1 -0
- package/dist/events.d.ts +21 -0
- package/dist/events.js +14 -0
- package/dist/hooks.d.ts +211 -0
- package/dist/hooks.js +14 -0
- package/dist/index.d.ts +55 -22
- package/dist/index.js +46 -3
- package/dist/legacy-http.d.ts +1 -0
- package/dist/legacy-http.js +3 -0
- package/dist/lifecycle.d.ts +21 -0
- package/dist/lifecycle.js +1 -0
- package/dist/links.d.ts +2 -0
- package/dist/links.js +25 -0
- package/dist/manifest.d.ts +190 -131
- package/dist/music-api.d.ts +44 -0
- package/dist/music-api.js +1 -0
- package/dist/music.js +3 -0
- package/dist/navigation.d.ts +17 -0
- package/dist/navigation.js +45 -1
- package/dist/permissions.d.ts +92 -0
- package/dist/permissions.js +23 -0
- package/dist/plugins-api.d.ts +16 -0
- package/dist/plugins-api.js +1 -0
- package/dist/regions.d.ts +76 -0
- package/dist/regions.js +9 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.js +4 -0
- package/dist/services.d.ts +48 -24
- package/dist/services.js +6 -22
- package/dist/streams.d.ts +35 -0
- package/dist/streams.js +51 -0
- package/dist/validate.d.ts +2 -1
- package/dist/validate.js +18 -0
- package/dist/view-bridge.d.ts +6 -0
- package/dist/view-bridge.js +1 -0
- package/dist/view-contracts.d.ts +136 -0
- package/dist/view-contracts.js +1 -0
- package/dist/vue/index.d.ts +17 -0
- package/dist/vue/index.js +74 -0
- package/dist/vue/region.d.ts +7 -0
- package/dist/vue/region.js +5 -0
- package/dist/wasm.d.ts +5 -0
- package/dist/wasm.js +1 -0
- package/package.json +14 -6
- package/dist/host-library.d.ts +0 -29
- package/dist/host-library.js +0 -69
package/dist/index.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
export * from './catalog.js';
|
|
2
|
+
export * from './plugins-api.js';
|
|
2
3
|
export * from './http.js';
|
|
3
4
|
export * from './library.js';
|
|
4
5
|
export * from './validate.js';
|
|
5
6
|
export * from './sockets.js';
|
|
6
7
|
export * from './music.js';
|
|
8
|
+
export * from './streams.js';
|
|
9
|
+
export * from './server.js';
|
|
10
|
+
export * from './music-api.js';
|
|
7
11
|
export * from './lyrics.js';
|
|
12
|
+
export * from './regions.js';
|
|
8
13
|
export * from './quality.js';
|
|
9
14
|
export * from './guests.js';
|
|
10
15
|
export * from './share.js';
|
|
@@ -15,19 +20,56 @@ export * from './permissions.js';
|
|
|
15
20
|
export * from './services.js';
|
|
16
21
|
export * from './modules.js';
|
|
17
22
|
export * from './manifest.js';
|
|
23
|
+
export { publicLink } from './links.js';
|
|
24
|
+
import { LIFECYCLE_NAMES } from './lifecycle.js';
|
|
18
25
|
export function definePlugin(entry) {
|
|
19
|
-
|
|
26
|
+
if (typeof entry === 'function')
|
|
27
|
+
return entry;
|
|
28
|
+
return ctx => {
|
|
29
|
+
const single = ctx.lifecycleOnly;
|
|
30
|
+
if (single) {
|
|
31
|
+
if (single === 'onUpdate' && entry.onUpdate)
|
|
32
|
+
ctx.lifecycle.onUpdate(update => entry.onUpdate(ctx, update));
|
|
33
|
+
else if (single !== 'onUpdate' && entry[single])
|
|
34
|
+
ctx.lifecycle[single](() => entry[single](ctx));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
for (const name of LIFECYCLE_NAMES) {
|
|
38
|
+
const handler = entry[name];
|
|
39
|
+
if (!handler)
|
|
40
|
+
continue;
|
|
41
|
+
if (name === 'onThemeChange')
|
|
42
|
+
ctx.lifecycle.onThemeChange(theme => entry.onThemeChange(ctx, theme));
|
|
43
|
+
else if (name === 'onUpdate')
|
|
44
|
+
ctx.lifecycle.onUpdate(update => entry.onUpdate(ctx, update));
|
|
45
|
+
else if (name === 'onLocaleChange')
|
|
46
|
+
ctx.lifecycle.onLocaleChange(locale => entry.onLocaleChange(ctx, locale));
|
|
47
|
+
else if (name === 'onConfigChange' || name === 'onPermissionChange')
|
|
48
|
+
ctx.lifecycle[name](keys => entry[name](ctx, keys));
|
|
49
|
+
else
|
|
50
|
+
ctx.lifecycle[name](() => entry[name](ctx));
|
|
51
|
+
}
|
|
52
|
+
if (entry.onIdle) {
|
|
53
|
+
const { milliseconds, handler } = entry.onIdle;
|
|
54
|
+
ctx.lifecycle.onIdle(milliseconds, () => handler(ctx));
|
|
55
|
+
}
|
|
56
|
+
return entry.setup(ctx);
|
|
57
|
+
};
|
|
20
58
|
}
|
|
21
59
|
export function defineSurface(entry) {
|
|
22
60
|
return entry;
|
|
23
61
|
}
|
|
24
62
|
export { defineNativeView, assertNativeView } from './native-view.js';
|
|
25
|
-
/** Host-side playlist delegation; import in the Electron main/renderer host, not in a plugin. */
|
|
26
|
-
export { createHostLibraryBridge } from './host-library.js';
|
|
27
63
|
export function defineGuestAdapter(entry) {
|
|
28
64
|
return entry;
|
|
29
65
|
}
|
|
30
66
|
export function defineManifest(manifest) {
|
|
67
|
+
if (manifest?.manifestVersion !== 3 || !manifest.entry)
|
|
68
|
+
throw new Error('Expected a v3 manifest with entry');
|
|
69
|
+
for (const key of ['modules', 'contributes', 'permissions']) {
|
|
70
|
+
if (Object.hasOwn(manifest, key))
|
|
71
|
+
throw new Error('Unexpected v2 manifest field: ' + key);
|
|
72
|
+
}
|
|
31
73
|
return manifest;
|
|
32
74
|
}
|
|
33
75
|
export function definePluginConfig(config) {
|
|
@@ -36,6 +78,7 @@ export function definePluginConfig(config) {
|
|
|
36
78
|
export function failure(error) {
|
|
37
79
|
return { ok: false, error };
|
|
38
80
|
}
|
|
81
|
+
export * from './events.js';
|
|
39
82
|
export function defineUISchema(schema) {
|
|
40
83
|
return schema;
|
|
41
84
|
}
|
package/dist/legacy-http.d.ts
CHANGED
package/dist/legacy-http.js
CHANGED
|
@@ -105,6 +105,9 @@ export function createLegacyHttpBridge(host) {
|
|
|
105
105
|
headers: { ...response.headers, ...(firstLocation ? { location: url.href } : {}) },
|
|
106
106
|
raw: response.body,
|
|
107
107
|
url: url.href,
|
|
108
|
+
// 重定向由 Host 内部跟随,Location 头不会回传;用最终地址补上,
|
|
109
|
+
// 让需要还原短链的适配器(如 QQ 音乐 ?__= 短链)拿到真实目标。
|
|
110
|
+
finalUrl: typeof response.url === 'string' ? response.url : url.href,
|
|
108
111
|
};
|
|
109
112
|
})();
|
|
110
113
|
return {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PluginContext, LogicEntry } from './index.js';
|
|
2
|
+
export declare const LIFECYCLE_NAMES: readonly ["onAppReady", "onInstall", "onUninstall", "onEnable", "onDisable", "onUpdate", "onOnline", "onOffline", "onLocaleChange", "onBeforeQuit", "onWindowShow", "onWindowHide", "onWindowFocus", "onWindowBlur", "onSuspend", "onResume", "onLock", "onUnlock", "onThemeChange", "onConfigChange", "onPermissionChange"];
|
|
3
|
+
export type LifecycleName = (typeof LIFECYCLE_NAMES)[number];
|
|
4
|
+
export type LifecycleArgs<Name extends LifecycleName> = Name extends 'onUpdate' ? [update: {
|
|
5
|
+
from: string;
|
|
6
|
+
}] : Name extends 'onLocaleChange' ? [locale: string] : Name extends 'onThemeChange' ? [theme: 'light' | 'dark'] : Name extends 'onConfigChange' | 'onPermissionChange' ? [keys: string[]] : [];
|
|
7
|
+
export type LifecycleAPI = {
|
|
8
|
+
[Name in LifecycleName]: (handler: (...args: LifecycleArgs<Name>) => void | Promise<void>) => () => void;
|
|
9
|
+
} & {
|
|
10
|
+
onIdle(milliseconds: number, handler: () => void | Promise<void>): () => void;
|
|
11
|
+
};
|
|
12
|
+
export type PluginOptions = {
|
|
13
|
+
setup: LogicEntry;
|
|
14
|
+
} & {
|
|
15
|
+
[Name in LifecycleName]?: (ctx: PluginContext, ...args: LifecycleArgs<Name>) => void | Promise<void>;
|
|
16
|
+
} & {
|
|
17
|
+
onIdle?: {
|
|
18
|
+
milliseconds: number;
|
|
19
|
+
handler(ctx: PluginContext): void | Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const LIFECYCLE_NAMES = ['onAppReady', 'onInstall', 'onUninstall', 'onEnable', 'onDisable', 'onUpdate', 'onOnline', 'onOffline', 'onLocaleChange', 'onBeforeQuit', 'onWindowShow', 'onWindowHide', 'onWindowFocus', 'onWindowBlur', 'onSuspend', 'onResume', 'onLock', 'onUnlock', 'onThemeChange', 'onConfigChange', 'onPermissionChange'];
|
package/dist/links.d.ts
ADDED
package/dist/links.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Only explicit, single, credential-free URLs may enter the plugin hook pipeline. */
|
|
2
|
+
export function publicLink(value) {
|
|
3
|
+
if (typeof value !== 'string' || value.length > 8192 || /[\s\u0000-\u001f\u007f]/.test(value))
|
|
4
|
+
return null;
|
|
5
|
+
try {
|
|
6
|
+
const url = new URL(value);
|
|
7
|
+
if (!['https:', 'http:', 'cerumusic:', 'ceru:'].includes(url.protocol) || url.username || url.password)
|
|
8
|
+
return null;
|
|
9
|
+
if (url.protocol === 'ceru:')
|
|
10
|
+
url.protocol = 'cerumusic:';
|
|
11
|
+
const path = decodeURIComponent(url.host + url.pathname);
|
|
12
|
+
if (/(?:^|\/)(?:oauth|auth|login|logout|callback)(?:\/|$)/i.test(path) || /^plugin(?:\/|$)/i.test(path))
|
|
13
|
+
return null;
|
|
14
|
+
if (url.hash)
|
|
15
|
+
return null;
|
|
16
|
+
for (const key of url.searchParams.keys()) {
|
|
17
|
+
if (/(?:token|secret|password|passwd|credential|authorization|signature|cookie|session|^code$|^state$|^key$|^url$|^redirect)/i.test(key))
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return url.href;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HostIconName, PermissionName } from './catalog.js';
|
|
2
|
+
import type { LyricInputFormat } from './lyrics.js';
|
|
2
3
|
import type { MenuContribution } from './services.js';
|
|
3
4
|
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
4
5
|
[key: string]: JsonValue;
|
|
@@ -24,6 +25,8 @@ export interface PermissionDeclaration {
|
|
|
24
25
|
requiredFor?: string[];
|
|
25
26
|
}
|
|
26
27
|
export interface ProviderDeclaration {
|
|
28
|
+
when?: EntryVisibilityRule;
|
|
29
|
+
beforeSelect?: string;
|
|
27
30
|
id: string;
|
|
28
31
|
name: string;
|
|
29
32
|
protocols: string[];
|
|
@@ -32,48 +35,7 @@ export interface ProviderDeclaration {
|
|
|
32
35
|
icon?: IconRef;
|
|
33
36
|
connectionMode?: 'none' | 'single' | 'multiple';
|
|
34
37
|
}
|
|
35
|
-
export interface SurfaceDeclaration {
|
|
36
|
-
id: string;
|
|
37
|
-
kind: 'schema' | 'web' | 'native';
|
|
38
|
-
/** Native: declared action returning NativeView; Web: module; Schema: JSON resource. */
|
|
39
|
-
entry: string;
|
|
40
|
-
/** Host chrome only. The plugin owns all content inside a web Surface. */
|
|
41
|
-
title?: string;
|
|
42
|
-
presentation?: {
|
|
43
|
-
kind: 'drawer' | 'modal';
|
|
44
|
-
placement?: 'left' | 'right' | 'top' | 'bottom';
|
|
45
|
-
size?: number;
|
|
46
|
-
};
|
|
47
|
-
/** Declared logic actions. Open runs after mounting; close runs once per session. */
|
|
48
|
-
lifecycle?: {
|
|
49
|
-
openAction?: string;
|
|
50
|
-
closeAction?: string;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
export type HomeSectionKind = 'playlists' | 'charts' | 'custom';
|
|
54
38
|
export type UISlotName = 'home.header' | 'home.content.before' | 'home.content.after' | 'search.source-selector.after' | 'playlist.header.actions' | 'playlist.item.actions' | 'player.actions' | 'settings.sections';
|
|
55
|
-
export interface HomeSectionContribution {
|
|
56
|
-
id: string;
|
|
57
|
-
title: string;
|
|
58
|
-
kind: HomeSectionKind;
|
|
59
|
-
icon?: IconRef;
|
|
60
|
-
/** Required for custom sections; built-in playlist/chart sections keep the existing Host UI. */
|
|
61
|
-
view?: string;
|
|
62
|
-
providerIds?: string[];
|
|
63
|
-
order?: number;
|
|
64
|
-
}
|
|
65
|
-
export interface UIExtensionContribution {
|
|
66
|
-
id: string;
|
|
67
|
-
slot: UISlotName;
|
|
68
|
-
mode: 'append' | 'prepend' | 'wrap' | 'replace';
|
|
69
|
-
/** Sandboxed visible Surface. Plugin JavaScript never runs in the application renderer. */
|
|
70
|
-
view: string;
|
|
71
|
-
order?: number;
|
|
72
|
-
when?: {
|
|
73
|
-
loggedIn?: boolean;
|
|
74
|
-
route?: string;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
39
|
export interface StyleContribution {
|
|
78
40
|
id: string;
|
|
79
41
|
resource: string;
|
|
@@ -81,8 +43,15 @@ export interface StyleContribution {
|
|
|
81
43
|
slots?: UISlotName[];
|
|
82
44
|
order?: number;
|
|
83
45
|
}
|
|
84
|
-
export interface
|
|
85
|
-
|
|
46
|
+
export interface GuestPolicy {
|
|
47
|
+
maxDepth: 1;
|
|
48
|
+
allowedCapabilities: string[];
|
|
49
|
+
networkScopeMode: 'per-guest-user-approved';
|
|
50
|
+
allowNativeCode: false;
|
|
51
|
+
allowRemoteCodeExecution: false;
|
|
52
|
+
}
|
|
53
|
+
export interface PluginManifestV3 {
|
|
54
|
+
manifestVersion: 3;
|
|
86
55
|
id: string;
|
|
87
56
|
name: string;
|
|
88
57
|
version: string;
|
|
@@ -91,114 +60,204 @@ export interface PluginManifest {
|
|
|
91
60
|
publisher?: string;
|
|
92
61
|
license?: string;
|
|
93
62
|
homepage?: string;
|
|
94
|
-
/** Static defaults for ctx.config. Build-time @file sugar is expanded into this object. */
|
|
95
63
|
config?: JsonObject;
|
|
96
64
|
engines: {
|
|
97
65
|
hostApi: string;
|
|
98
66
|
logicRuntime: string;
|
|
99
|
-
uiSchema?: string;
|
|
100
67
|
libraries?: Partial<Record<'vue' | 'react' | 'react-dom', string>>;
|
|
101
68
|
};
|
|
102
|
-
|
|
69
|
+
entry: {
|
|
103
70
|
logic?: {
|
|
104
|
-
|
|
71
|
+
module: string;
|
|
105
72
|
activation?: string[];
|
|
106
73
|
};
|
|
107
|
-
/** Separate server-side playback resolver. Requires a compatible builder and share Host. */
|
|
108
74
|
share?: {
|
|
109
|
-
|
|
75
|
+
module: string;
|
|
110
76
|
configKeys?: string[];
|
|
111
77
|
guestAdapterId?: string;
|
|
112
78
|
guestGlobals?: string[];
|
|
113
79
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
80
|
+
views?: ViewDeclaration[];
|
|
81
|
+
server?: {
|
|
82
|
+
module: string;
|
|
83
|
+
runtime: 'sandbox' | 'node';
|
|
84
|
+
port?: number;
|
|
85
|
+
lan?: boolean;
|
|
86
|
+
};
|
|
87
|
+
native?: {
|
|
88
|
+
name: string;
|
|
89
|
+
platforms: Record<string, string>;
|
|
121
90
|
}[];
|
|
91
|
+
};
|
|
92
|
+
provides?: {
|
|
122
93
|
providers?: ProviderDeclaration[];
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
view: string;
|
|
130
|
-
order?: number;
|
|
131
|
-
}[];
|
|
132
|
-
/** Controlled UI composition. The Host owns the target DOM and lifecycle. */
|
|
133
|
-
uiExtensions?: UIExtensionContribution[];
|
|
134
|
-
/** Surface/slot styles are scoped. Application styles require ui.styles.global. */
|
|
135
|
-
styles?: StyleContribution[];
|
|
136
|
-
menus?: MenuContribution[];
|
|
137
|
-
/** Entries for the application's existing playlist import menu/dialog. */
|
|
138
|
-
playlistImporters?: {
|
|
139
|
-
id: string;
|
|
140
|
-
title: string;
|
|
141
|
-
providerId?: string;
|
|
142
|
-
examples?: {
|
|
143
|
-
label: string;
|
|
144
|
-
value: string;
|
|
145
|
-
}[];
|
|
146
|
-
instructions?: string[];
|
|
147
|
-
description?: string;
|
|
148
|
-
placeholder?: string;
|
|
149
|
-
}[];
|
|
150
|
-
commands?: {
|
|
151
|
-
id: string;
|
|
152
|
-
title: string;
|
|
153
|
-
description?: string;
|
|
154
|
-
action: string;
|
|
155
|
-
view?: string;
|
|
156
|
-
}[];
|
|
157
|
-
/** Subaccounts in the Host account menu. action returns AccountSummary; view owns login UI. */
|
|
158
|
-
accountItems?: {
|
|
159
|
-
id: string;
|
|
160
|
-
title: string;
|
|
161
|
-
view: string;
|
|
162
|
-
action: string;
|
|
163
|
-
logoutAction?: string;
|
|
164
|
-
}[];
|
|
165
|
-
sidebarItems?: {
|
|
166
|
-
id: string;
|
|
167
|
-
group: string;
|
|
168
|
-
title: string;
|
|
169
|
-
view: string;
|
|
170
|
-
}[];
|
|
171
|
-
settingsPages?: {
|
|
172
|
-
id: string;
|
|
173
|
-
title: string;
|
|
174
|
-
view: string;
|
|
175
|
-
}[];
|
|
176
|
-
guestAdapters?: {
|
|
177
|
-
id: string;
|
|
178
|
-
title?: string;
|
|
179
|
-
extensions?: string[];
|
|
180
|
-
format: string;
|
|
181
|
-
badge?: {
|
|
182
|
-
label: string;
|
|
183
|
-
backgroundColor: string;
|
|
184
|
-
textColor: string;
|
|
185
|
-
};
|
|
186
|
-
compatibilityProfile: string;
|
|
187
|
-
bootstrap: string;
|
|
188
|
-
runtime: string;
|
|
189
|
-
projectableProtocols: string[];
|
|
190
|
-
}[];
|
|
94
|
+
importers?: ImporterDeclaration[];
|
|
95
|
+
lyricConverters?: LyricConverterDeclaration[];
|
|
96
|
+
accounts?: AccountDeclaration[];
|
|
97
|
+
guestAdapters?: GuestAdapterDeclaration[];
|
|
98
|
+
services?: ServiceDeclaration[];
|
|
99
|
+
actions?: ActionDeclaration[];
|
|
191
100
|
};
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
101
|
+
uses?: {
|
|
102
|
+
permissions?: PermissionDeclaration[];
|
|
103
|
+
plugins?: PluginDependency[];
|
|
104
|
+
};
|
|
105
|
+
ui?: {
|
|
106
|
+
pages?: PageDeclaration[];
|
|
107
|
+
homeSections?: HomeSectionDeclaration[];
|
|
108
|
+
slots?: SlotDeclaration[];
|
|
109
|
+
menus?: MenuContribution[];
|
|
110
|
+
styles?: StyleContribution[];
|
|
111
|
+
regions?: RegionDeclaration[];
|
|
112
|
+
skins?: SkinDeclaration[];
|
|
199
113
|
};
|
|
114
|
+
guestPolicy?: GuestPolicy;
|
|
200
115
|
dataSchemas?: {
|
|
201
116
|
config: number;
|
|
202
117
|
state: number;
|
|
203
118
|
};
|
|
204
119
|
}
|
|
120
|
+
export interface ViewDeclaration {
|
|
121
|
+
id: string;
|
|
122
|
+
kind: 'component' | 'web' | 'native';
|
|
123
|
+
module: string;
|
|
124
|
+
title?: string;
|
|
125
|
+
presentation?: {
|
|
126
|
+
kind: 'drawer' | 'modal';
|
|
127
|
+
placement?: 'left' | 'right' | 'top' | 'bottom';
|
|
128
|
+
size?: number;
|
|
129
|
+
};
|
|
130
|
+
lifecycle?: {
|
|
131
|
+
openAction?: string;
|
|
132
|
+
closeAction?: string;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export interface ActionDeclaration {
|
|
136
|
+
id: string;
|
|
137
|
+
title: string;
|
|
138
|
+
description?: string;
|
|
139
|
+
view?: string;
|
|
140
|
+
}
|
|
141
|
+
export interface ImporterDeclaration {
|
|
142
|
+
id: string;
|
|
143
|
+
title: string;
|
|
144
|
+
providerId?: string;
|
|
145
|
+
examples?: {
|
|
146
|
+
label: string;
|
|
147
|
+
value: string;
|
|
148
|
+
}[];
|
|
149
|
+
instructions?: string[];
|
|
150
|
+
description?: string;
|
|
151
|
+
placeholder?: string;
|
|
152
|
+
}
|
|
153
|
+
export interface LyricConverterDeclaration {
|
|
154
|
+
id: string;
|
|
155
|
+
title: string;
|
|
156
|
+
formats: LyricInputFormat[];
|
|
157
|
+
}
|
|
158
|
+
export interface AccountDeclaration {
|
|
159
|
+
id: string;
|
|
160
|
+
title: string;
|
|
161
|
+
icon?: IconRef;
|
|
162
|
+
multiple?: boolean;
|
|
163
|
+
loginMethods: ('qrcode' | 'browser' | 'form' | 'oauth')[];
|
|
164
|
+
capabilities?: ('profile' | 'likes' | 'playlists' | 'history' | 'recommend')[];
|
|
165
|
+
providers?: string[];
|
|
166
|
+
view?: string;
|
|
167
|
+
}
|
|
168
|
+
export interface GuestAdapterDeclaration {
|
|
169
|
+
id: string;
|
|
170
|
+
title?: string;
|
|
171
|
+
extensions?: string[];
|
|
172
|
+
format: string;
|
|
173
|
+
badge?: {
|
|
174
|
+
label: string;
|
|
175
|
+
backgroundColor: string;
|
|
176
|
+
textColor: string;
|
|
177
|
+
};
|
|
178
|
+
compatibilityProfile: string;
|
|
179
|
+
bootstrap: string;
|
|
180
|
+
runtime: string;
|
|
181
|
+
projectableProtocols: string[];
|
|
182
|
+
}
|
|
183
|
+
export interface ServiceDeclaration {
|
|
184
|
+
id: string;
|
|
185
|
+
version: string;
|
|
186
|
+
methods: string[];
|
|
187
|
+
description?: string;
|
|
188
|
+
}
|
|
189
|
+
export interface PluginDependency {
|
|
190
|
+
pluginId: string;
|
|
191
|
+
service: string;
|
|
192
|
+
version: string;
|
|
193
|
+
optional?: boolean;
|
|
194
|
+
}
|
|
195
|
+
export interface EntryVisibilityRule {
|
|
196
|
+
loggedIn?: boolean;
|
|
197
|
+
selectedSource?: string;
|
|
198
|
+
predicate?: string;
|
|
199
|
+
combine?: 'all' | 'any';
|
|
200
|
+
}
|
|
201
|
+
export type EntryVisibilityDecision = boolean | 'force-show' | 'force-hide';
|
|
202
|
+
export type ProviderEntryDecision = EntryVisibilityDecision | {
|
|
203
|
+
state: 'disabled';
|
|
204
|
+
reason?: string;
|
|
205
|
+
};
|
|
206
|
+
export interface ProviderEntryContext extends SourceSelection {
|
|
207
|
+
providerId: string;
|
|
208
|
+
}
|
|
209
|
+
export type ProviderSelectionDecision = boolean | {
|
|
210
|
+
login: {
|
|
211
|
+
accountId: string;
|
|
212
|
+
method?: AccountDeclaration['loginMethods'][number];
|
|
213
|
+
connectionId?: string;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
export interface SourceSelection {
|
|
217
|
+
selectedSource: string | null;
|
|
218
|
+
selectedProvider: string | null;
|
|
219
|
+
}
|
|
220
|
+
export interface EntryVisibilityContext extends SourceSelection {
|
|
221
|
+
pageId: string;
|
|
222
|
+
}
|
|
223
|
+
export interface PageDeclaration {
|
|
224
|
+
id: string;
|
|
225
|
+
title: string;
|
|
226
|
+
mount: 'sidebar' | 'settings' | 'home-tab' | 'playlist-section';
|
|
227
|
+
view: string;
|
|
228
|
+
icon?: IconRef;
|
|
229
|
+
group?: 'discover' | 'library' | 'tools';
|
|
230
|
+
order?: number;
|
|
231
|
+
when?: EntryVisibilityRule;
|
|
232
|
+
}
|
|
233
|
+
export interface HomeSectionDeclaration {
|
|
234
|
+
id: string;
|
|
235
|
+
title: string;
|
|
236
|
+
kind: 'playlists' | 'charts';
|
|
237
|
+
providerIds?: string[];
|
|
238
|
+
icon?: IconRef;
|
|
239
|
+
order?: number;
|
|
240
|
+
}
|
|
241
|
+
export interface SlotDeclaration {
|
|
242
|
+
id: string;
|
|
243
|
+
slot: UISlotName;
|
|
244
|
+
mode: 'append' | 'prepend' | 'wrap' | 'replace';
|
|
245
|
+
view: string;
|
|
246
|
+
order?: number;
|
|
247
|
+
when?: {
|
|
248
|
+
loggedIn?: boolean;
|
|
249
|
+
route?: string;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export interface RegionDeclaration {
|
|
253
|
+
region: string;
|
|
254
|
+
view: string;
|
|
255
|
+
}
|
|
256
|
+
export interface SkinDeclaration {
|
|
257
|
+
id: string;
|
|
258
|
+
title: string;
|
|
259
|
+
preview?: IconRef;
|
|
260
|
+
regions: string[];
|
|
261
|
+
settings?: JsonObject;
|
|
262
|
+
}
|
|
263
|
+
export type PluginManifest = PluginManifestV3;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { SearchRequest, ContentEntity, Page, ResourceRef, ResolveResult, Disposable, ServiceCall, CrLyric, PlaylistTrackPage } from './index.js';
|
|
2
|
+
export interface MusicSource {
|
|
3
|
+
id: string;
|
|
4
|
+
pluginId: string;
|
|
5
|
+
runtime: 2 | 3 | 'host';
|
|
6
|
+
name: string;
|
|
7
|
+
protocols: string[];
|
|
8
|
+
qualities: string[];
|
|
9
|
+
icon?: string;
|
|
10
|
+
available: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface MusicAPI {
|
|
13
|
+
sources(): Promise<MusicSource[]>;
|
|
14
|
+
search(sourceId: string, request: SearchRequest, call: ServiceCall): Promise<Page<ContentEntity>>;
|
|
15
|
+
suggest(sourceId: string, query: string, call: ServiceCall): Promise<string[]>;
|
|
16
|
+
hotSearch(sourceId: string, call: ServiceCall): Promise<string[]>;
|
|
17
|
+
tracks: {
|
|
18
|
+
resolve(ref: ResourceRef, quality: string | undefined, call: ServiceCall): Promise<ResolveResult>;
|
|
19
|
+
lyrics(ref: ResourceRef, call: ServiceCall): Promise<CrLyric>;
|
|
20
|
+
artwork(ref: ResourceRef, call: ServiceCall): Promise<string | undefined>;
|
|
21
|
+
};
|
|
22
|
+
playlists: {
|
|
23
|
+
search(sourceId: string, request: SearchRequest, call: ServiceCall): Promise<Page<ContentEntity>>;
|
|
24
|
+
categories(sourceId: string, call: ServiceCall): Promise<Page<ContentEntity>>;
|
|
25
|
+
list(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>;
|
|
26
|
+
get(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<PlaylistTrackPage>;
|
|
27
|
+
};
|
|
28
|
+
charts: {
|
|
29
|
+
list(sourceId: string, call: ServiceCall): Promise<Page<ContentEntity>>;
|
|
30
|
+
getTracks(ref: ResourceRef, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>;
|
|
31
|
+
};
|
|
32
|
+
importers: {
|
|
33
|
+
list(): Promise<{
|
|
34
|
+
id: string;
|
|
35
|
+
pluginId: string;
|
|
36
|
+
title: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
}[]>;
|
|
39
|
+
parse(importerId: string, value: string, cursor: string | undefined, call: ServiceCall): Promise<Page<ContentEntity>>;
|
|
40
|
+
};
|
|
41
|
+
play(ref: ResourceRef, call: ServiceCall): Promise<void>;
|
|
42
|
+
enqueue(refs: ResourceRef[], position: 'next' | 'end', call: ServiceCall): Promise<void>;
|
|
43
|
+
on(event: 'sources.changed', handler: (sources: MusicSource[]) => void): Disposable;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/music.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertStreamSpec } from './streams.js';
|
|
1
2
|
const record = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
2
3
|
const text = (value, max = 4096) => typeof value === 'string' && value.length <= max;
|
|
3
4
|
const milliseconds = (value) => Number.isFinite(value) && Number(value) >= 0;
|
|
@@ -141,6 +142,8 @@ export function assertResolveResult(value) {
|
|
|
141
142
|
throw new Error('Invalid playback request header');
|
|
142
143
|
}
|
|
143
144
|
}
|
|
145
|
+
if (value.stream !== undefined)
|
|
146
|
+
assertStreamSpec(value.stream);
|
|
144
147
|
return;
|
|
145
148
|
}
|
|
146
149
|
if (!record(value.error) || !text(value.error.code, 128) || !text(value.error.message, 65536))
|
package/dist/navigation.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { ResourceRef } from './index.js';
|
|
2
2
|
import type { PluginManifest } from './manifest.js';
|
|
3
|
+
export declare const PLUGIN_ROUTE_NAMES: readonly ["welcome", "home", "find", "songlist", "local", "recent", "search", "recognize", "list", "download", "local-tag-editor", "profile", "community", "settings", "plugin-page"];
|
|
4
|
+
export type PluginRouteName = typeof PLUGIN_ROUTE_NAMES[number];
|
|
5
|
+
export interface PluginRoute {
|
|
6
|
+
name: PluginRouteName;
|
|
7
|
+
params: Record<string, string>;
|
|
8
|
+
query: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export type PluginRouteTarget = Pick<PluginRoute, 'name'> & Partial<Omit<PluginRoute, 'name'>>;
|
|
11
|
+
export type RouteGuard = (to: PluginRoute, from: PluginRoute | null) => void | false | PluginRouteTarget | Promise<void | false | PluginRouteTarget>;
|
|
12
|
+
export interface PluginRouter {
|
|
13
|
+
beforeEach(handler: RouteGuard): () => void;
|
|
14
|
+
afterEach(handler: (to: PluginRoute, from: PluginRoute | null) => void | Promise<void>): () => void;
|
|
15
|
+
current(): Promise<PluginRoute | null>;
|
|
16
|
+
push(to: PluginRouteTarget): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
export declare function projectPluginRoute(name: unknown, params: unknown, query: unknown, owner?: string): PluginRoute | null;
|
|
19
|
+
export declare function validatePluginRouteTarget(value: unknown, manifest: PluginManifest): PluginRoute;
|
|
3
20
|
export type HostNavigationRequest = {
|
|
4
21
|
query?: string;
|
|
5
22
|
ref?: ResourceRef;
|
package/dist/navigation.js
CHANGED
|
@@ -1,4 +1,48 @@
|
|
|
1
1
|
import { assertResourceRef } from './music.js';
|
|
2
|
+
export const PLUGIN_ROUTE_NAMES = ['welcome', 'home', 'find', 'songlist', 'local', 'recent', 'search', 'recognize', 'list', 'download', 'local-tag-editor', 'profile', 'community', 'settings', 'plugin-page'];
|
|
3
|
+
const routeKeys = { list: ['id'], 'plugin-page': ['pluginId', 'pageId'] };
|
|
4
|
+
const queryKeys = { search: ['keyword'], list: ['type', 'source'], settings: ['section'] };
|
|
5
|
+
const safeKey = (key) => /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(key) && !['constructor', 'prototype', '__proto__'].includes(key);
|
|
6
|
+
function routeFields(value, allowed, strict, ids) {
|
|
7
|
+
const result = {};
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
return result;
|
|
10
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
11
|
+
throw Error('Invalid route fields');
|
|
12
|
+
for (const [key, field] of Object.entries(value)) {
|
|
13
|
+
if (!safeKey(key) || (allowed && !allowed.includes(key)) || typeof field !== 'string' || field.length > 1024 || (ids && !/^[a-zA-Z0-9._-]{1,256}$/.test(field))) {
|
|
14
|
+
if (strict)
|
|
15
|
+
throw Error('Invalid route field: ' + key);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (Object.keys(result).length >= 24) {
|
|
19
|
+
if (strict)
|
|
20
|
+
throw Error('Too many route fields');
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
result[key] = field;
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
export function projectPluginRoute(name, params, query, owner) {
|
|
28
|
+
if (!PLUGIN_ROUTE_NAMES.includes(name))
|
|
29
|
+
return null;
|
|
30
|
+
const route = name;
|
|
31
|
+
const fields = routeFields(params, routeKeys[route] ?? [], false, true);
|
|
32
|
+
const ownPage = route === 'plugin-page' && owner !== undefined && owner === fields.pluginId;
|
|
33
|
+
return { name: route, params: fields, query: routeFields(query, ownPage ? undefined : queryKeys[route] ?? [], false, false) };
|
|
34
|
+
}
|
|
35
|
+
export function validatePluginRouteTarget(value, manifest) {
|
|
36
|
+
const target = value;
|
|
37
|
+
if (!target || typeof target !== 'object' || Array.isArray(target) || Object.keys(target).some(key => !['name', 'params', 'query'].includes(key)) || !PLUGIN_ROUTE_NAMES.includes(target.name))
|
|
38
|
+
throw Error('Invalid named plugin route');
|
|
39
|
+
const params = routeFields(target.params, routeKeys[target.name] ?? [], true, true);
|
|
40
|
+
if (routeKeys[target.name]?.some(key => !params[key]))
|
|
41
|
+
throw Error('Missing route parameter');
|
|
42
|
+
if (target.name === 'plugin-page' && (params.pluginId !== manifest.id || !manifest.ui?.pages?.some(page => page.id === params.pageId)))
|
|
43
|
+
throw Error('Plugin page is not owned by caller');
|
|
44
|
+
return { name: target.name, params, query: routeFields(target.query, target.name === 'plugin-page' ? undefined : queryKeys[target.name] ?? [], true, false) };
|
|
45
|
+
}
|
|
2
46
|
/** Validate using the calling plugin's manifest, never a caller-supplied owner ID. */
|
|
3
47
|
export function assertNavigationRequest(value, manifest) {
|
|
4
48
|
const request = value;
|
|
@@ -18,7 +62,7 @@ export function assertNavigationRequest(value, manifest) {
|
|
|
18
62
|
request.sectionId.length > 128)
|
|
19
63
|
throw new Error('sectionId is only valid for playlist navigation');
|
|
20
64
|
if (manifest &&
|
|
21
|
-
!manifest.
|
|
65
|
+
!manifest.ui?.pages?.some((page) => page.mount === 'playlist-section' && page.id === request.sectionId))
|
|
22
66
|
throw new Error('Unknown playlist section: ' + request.sectionId);
|
|
23
67
|
}
|
|
24
68
|
}
|