@shiqianjiang/ceru-plugin-sdk 0.3.3 → 0.3.6

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # SDK 变更记录
2
2
 
3
+ ## 0.3.6
4
+
5
+ - `ResourceRef.scope: 'provider'` 标记公共平台歌曲 ID;支持 Host 按用户的播放/歌词路由选择实现。私有资源默认仍归原插件,`retargetTrackRef` 跨插件时只保留公共标识,剥离私有数据。
6
+ - `TrackMetadata.qualitySizes` 按音质 ID 返回真实字节数,供原生下载界面显示;校验拒绝负值、非整数及未声明音质。
7
+
8
+ ## 0.3.5
9
+
10
+ - Web Surface 自动上报挂载内容高度;Host 可按视口调整短弹框高度,长内容保留滚动,关闭后停止尺寸观察。
11
+
12
+ - 新增 `contributes.playlistSections`:插件的 native Surface 嵌入 Host 现有本地/云歌单页。
13
+ - `ui.navigation.open({ page: 'playlist', sectionId })` 跳转定位调用插件的已声明区块,SDK、Issuer 与 CLI 校验原生视图引用及导航归属。
14
+ - 独立工作台增加 Host 歌单页预览,多区块共用 Core Surface 生命周期;connected-library JS/TS 模板展示页内集成和导航。
15
+ - CLI 保留 0.3.4 的实际包版本查询。
16
+
3
17
  ## 0.3.3
4
18
 
5
19
  - 新增 Host 原生基础 UI Surface:插件返回经过校验的 `NativeView` 数据,宿主用自己的列表、网格和按钮组件渲染;平台业务与登录流程仍留在插件内。
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Ceru Plugin SDK
2
2
 
3
+ 0.3.5 新增 `contributes.playlistSections`、`HostNavigationRequest` 和 `assertNavigationRequest`。插件通过 `ui.navigation.open({ page: 'playlist', sectionId })` 前往 Host 现有歌单页的原生区块,校验以调用插件的 manifest 为准。
4
+
3
5
  ## 原生 UI 与账号菜单
4
6
 
5
7
  本节接口由 0.3.3 完整提供。
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from './guests.js';
17
17
  export * from './share.js';
18
18
  export * from './storage.js';
19
19
  export * from './accounts.js';
20
+ export * from './navigation.js';
20
21
  export * from './permissions.js';
21
22
  export * from './services.js';
22
23
  export * from './modules.js';
@@ -35,6 +36,11 @@ export interface ResourceRef {
35
36
  connectionId?: string;
36
37
  kind: string;
37
38
  id: string;
39
+ /** Public canonical track ID within providerId. Allows the Host's selected resolver.
40
+ * Omit for plugin/account-private IDs. Cannot be combined with connectionId.
41
+ * Cross-plugin calls receive only this public identity, never data.
42
+ */
43
+ scope?: 'provider';
38
44
  /** Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. */
39
45
  data?: JsonObject;
40
46
  }
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ export * from './guests.js';
9
9
  export * from './share.js';
10
10
  export * from './storage.js';
11
11
  export * from './accounts.js';
12
+ export * from './navigation.js';
12
13
  export * from './permissions.js';
13
14
  export * from './services.js';
14
15
  export * from './modules.js';
@@ -122,6 +122,13 @@ export interface PluginManifest {
122
122
  providers?: ProviderDeclaration[];
123
123
  /** Home tabs exist only while at least one enabled plugin contributes them. */
124
124
  homeSections?: HomeSectionContribution[];
125
+ /** Native sections inside the Host's existing local/cloud playlist page. */
126
+ playlistSections?: {
127
+ id: string;
128
+ title: string;
129
+ view: string;
130
+ order?: number;
131
+ }[];
125
132
  /** Controlled UI composition. The Host owns the target DOM and lifecycle. */
126
133
  uiExtensions?: UIExtensionContribution[];
127
134
  /** Surface/slot styles are scoped. Application styles require ui.styles.global. */
package/dist/music.d.ts CHANGED
@@ -34,6 +34,8 @@ export interface TrackMetadata {
34
34
  title: string;
35
35
  };
36
36
  qualities?: string[];
37
+ /** Actual file sizes in bytes, keyed by the same IDs as qualities. Omit unknown sizes. */
38
+ qualitySizes?: Record<string, number>;
37
39
  artworkUrl?: string;
38
40
  durationMs?: number;
39
41
  }
@@ -66,6 +68,8 @@ export interface MusicChart extends ContentEntity {
66
68
  chart?: ChartMetadata;
67
69
  }
68
70
  export declare function assertResourceRef(value: unknown): asserts value is ResourceRef;
71
+ /** Retarget a public track without disclosing the original plugin's private data. */
72
+ export declare function retargetTrackRef(ref: ResourceRef, pluginId: string): ResourceRef;
69
73
  export declare function assertContentPage(value: unknown): void;
70
74
  export declare function assertResolveResult(value: unknown): asserts value is ResolveResult;
71
75
  export declare function assertLyricsDocument(value: unknown): asserts value is LyricsDocument;
package/dist/music.js CHANGED
@@ -5,6 +5,11 @@ export function assertResourceRef(value) {
5
5
  if (!record(value) ||
6
6
  !['pluginId', 'providerId', 'kind', 'id'].every((key) => text(value[key], 2048) && value[key].length > 0))
7
7
  throw new Error('Invalid resource reference');
8
+ if (value.connectionId !== undefined && (!text(value.connectionId, 2048) || !value.connectionId))
9
+ throw new Error('Invalid resource connection');
10
+ if (value.scope !== undefined &&
11
+ (value.scope !== 'provider' || value.kind !== 'track' || value.connectionId !== undefined))
12
+ throw new Error('Provider scope requires a public track without a connection');
8
13
  if (value.data !== undefined) {
9
14
  if (!record(value.data))
10
15
  throw new Error('Invalid resource private data');
@@ -19,6 +24,19 @@ export function assertResourceRef(value) {
19
24
  throw new Error('Resource private data exceeds 64 KiB');
20
25
  }
21
26
  }
27
+ /** Retarget a public track without disclosing the original plugin's private data. */
28
+ export function retargetTrackRef(ref, pluginId) {
29
+ assertResourceRef(ref);
30
+ if (ref.kind !== 'track')
31
+ throw new Error('Expected a track reference');
32
+ if (!text(pluginId, 2048) || !pluginId)
33
+ throw new Error('Invalid target plugin');
34
+ if (ref.pluginId === pluginId)
35
+ return ref;
36
+ if (ref.scope !== 'provider')
37
+ throw new Error('Private tracks must stay with their owner');
38
+ return { pluginId, providerId: ref.providerId, kind: 'track', id: ref.id, scope: 'provider' };
39
+ }
22
40
  export function assertContentPage(value) {
23
41
  if (!record(value) || !Array.isArray(value.items) || value.items.length > 10000)
24
42
  throw new Error('Invalid content page');
@@ -38,6 +56,15 @@ export function assertContentPage(value) {
38
56
  throw new Error('Track metadata must contain artists');
39
57
  if (item.metadata.durationMs !== undefined && !milliseconds(item.metadata.durationMs))
40
58
  throw new Error('Invalid track duration');
59
+ const { qualities, qualitySizes } = item.metadata;
60
+ if (qualities !== undefined &&
61
+ (!Array.isArray(qualities) || qualities.length > 128 ||
62
+ !qualities.every((quality) => text(quality, 128) && !!quality)))
63
+ throw new Error('Invalid track qualities');
64
+ if (qualitySizes !== undefined &&
65
+ (!record(qualitySizes) || Object.keys(qualitySizes).length > 128 ||
66
+ Object.entries(qualitySizes).some(([quality, bytes]) => !qualities?.includes(quality) || !Number.isSafeInteger(bytes) || Number(bytes) <= 0)))
67
+ throw new Error('Invalid track quality sizes');
41
68
  }
42
69
  if (item.ref.kind === 'playlist' && item.playlist !== undefined) {
43
70
  if (!record(item.playlist))
@@ -0,0 +1,14 @@
1
+ import type { ResourceRef } from './index.js';
2
+ import type { PluginManifest } from './manifest.js';
3
+ export type HostNavigationRequest = {
4
+ query?: string;
5
+ ref?: ResourceRef;
6
+ } & ({
7
+ page: 'playlist';
8
+ sectionId?: string;
9
+ } | {
10
+ page: 'search' | 'charts' | 'downloads' | 'account' | 'settings';
11
+ sectionId?: never;
12
+ });
13
+ /** Validate using the calling plugin's manifest, never a caller-supplied owner ID. */
14
+ export declare function assertNavigationRequest(value: unknown, manifest?: PluginManifest): asserts value is HostNavigationRequest;
@@ -0,0 +1,24 @@
1
+ import { assertResourceRef } from './music.js';
2
+ /** Validate using the calling plugin's manifest, never a caller-supplied owner ID. */
3
+ export function assertNavigationRequest(value, manifest) {
4
+ const request = value;
5
+ if (!request ||
6
+ typeof request !== 'object' ||
7
+ Array.isArray(request) ||
8
+ !['search', 'playlist', 'charts', 'downloads', 'account', 'settings'].includes(request.page) ||
9
+ (request.query !== undefined &&
10
+ (typeof request.query !== 'string' || request.query.length > 8192)))
11
+ throw new Error('Invalid Host navigation request');
12
+ if (request.ref !== undefined)
13
+ assertResourceRef(request.ref);
14
+ if (request.sectionId !== undefined) {
15
+ if (request.page !== 'playlist' ||
16
+ typeof request.sectionId !== 'string' ||
17
+ !request.sectionId.length ||
18
+ request.sectionId.length > 128)
19
+ throw new Error('sectionId is only valid for playlist navigation');
20
+ if (manifest &&
21
+ !manifest.contributes?.playlistSections?.some((section) => section.id === request.sectionId))
22
+ throw new Error('Unknown playlist section: ' + request.sectionId);
23
+ }
24
+ }
@@ -3,6 +3,7 @@ import type { ContentEntity, MusicFault, OperationContext, Page, ResourceRef, As
3
3
  import type { LibraryPlaylist, PlaylistReference } from './library.js';
4
4
  import type { LyricsDocument } from './music.js';
5
5
  import type { PermissionGroup } from './permissions.js';
6
+ import type { HostNavigationRequest } from './navigation.js';
6
7
  /** Supplied by Host actions/events. Never construct trusted intents from plugin JSON. */
7
8
  export interface ServiceCall {
8
9
  operation: OperationContext;
@@ -284,11 +285,7 @@ export interface HostUI {
284
285
  }): Promise<LibraryPlaylist | null>;
285
286
  };
286
287
  navigation: {
287
- open(request: {
288
- page: 'search' | 'playlist' | 'charts' | 'downloads' | 'account' | 'settings';
289
- query?: string;
290
- ref?: ResourceRef;
291
- }): Promise<void>;
288
+ open(request: HostNavigationRequest): Promise<void>;
292
289
  };
293
290
  notifications: {
294
291
  show(request: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiqianjiang/ceru-plugin-sdk",
3
- "version": "0.3.3",
3
+ "version": "0.3.6",
4
4
  "description": "Typed authoring contracts for Ceru Music v2 single-file plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",