@shiqianjiang/ceru-plugin-sdk 0.3.5 → 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,10 @@
1
1
  # SDK 变更记录
2
2
 
3
+ ## 0.3.6
4
+
5
+ - `ResourceRef.scope: 'provider'` 标记公共平台歌曲 ID;支持 Host 按用户的播放/歌词路由选择实现。私有资源默认仍归原插件,`retargetTrackRef` 跨插件时只保留公共标识,剥离私有数据。
6
+ - `TrackMetadata.qualitySizes` 按音质 ID 返回真实字节数,供原生下载界面显示;校验拒绝负值、非整数及未声明音质。
7
+
3
8
  ## 0.3.5
4
9
 
5
10
  - Web Surface 自动上报挂载内容高度;Host 可按视口调整短弹框高度,长内容保留滚动,关闭后停止尺寸观察。
package/dist/index.d.ts CHANGED
@@ -36,6 +36,11 @@ export interface ResourceRef {
36
36
  connectionId?: string;
37
37
  kind: string;
38
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';
39
44
  /** Opaque plugin-owned JSON persisted by the Host and returned only to this plugin. */
40
45
  data?: JsonObject;
41
46
  }
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))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiqianjiang/ceru-plugin-sdk",
3
- "version": "0.3.5",
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",