@shiqianjiang/ceru-plugin-cli 0.3.16 → 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.
Files changed (302) hide show
  1. package/README.md +26 -7
  2. package/assets/compatibility.json +18 -0
  3. package/dist/compatibility.d.ts +24 -0
  4. package/dist/compatibility.js +119 -0
  5. package/dist/component.d.ts +6 -0
  6. package/dist/component.js +60 -0
  7. package/dist/dev-music.d.ts +19 -0
  8. package/dist/dev-music.js +81 -0
  9. package/dist/dev-plugin-services.d.ts +10 -0
  10. package/dist/dev-plugin-services.js +67 -0
  11. package/dist/dev.d.ts +1 -9
  12. package/dist/dev.js +53 -713
  13. package/dist/frameworks.d.ts +5 -2
  14. package/dist/frameworks.js +43 -6
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +54 -23
  17. package/dist/init.js +3 -3
  18. package/dist/migrate.d.ts +3 -0
  19. package/dist/migrate.js +109 -0
  20. package/dist/project.d.ts +5 -2
  21. package/dist/project.js +131 -43
  22. package/dist/test-hooks.d.ts +1 -0
  23. package/dist/test-hooks.js +209 -0
  24. package/dist/test-services.d.ts +4 -0
  25. package/dist/test-services.js +54 -0
  26. package/dist/watch-vue-types.d.ts +17 -0
  27. package/dist/watch-vue-types.js +145 -0
  28. package/package.json +10 -6
  29. package/schemas/config.schema.json +954 -452
  30. package/templates/account-qrcode/js/.vscode/extensions.json +3 -0
  31. package/templates/account-qrcode/js/.vscode/launch.json +19 -0
  32. package/templates/account-qrcode/js/.vscode/settings.json +20 -0
  33. package/templates/account-qrcode/js/.vscode/tasks.json +43 -0
  34. package/templates/account-qrcode/js/README.md +15 -0
  35. package/templates/account-qrcode/js/_gitignore +6 -0
  36. package/templates/account-qrcode/js/ceru-plugin.code-workspace +8 -0
  37. package/templates/account-qrcode/js/ceru.plugin.json +62 -0
  38. package/templates/account-qrcode/js/package.json +24 -0
  39. package/templates/account-qrcode/js/src/Login.vue +25 -0
  40. package/templates/account-qrcode/js/src/index.js +25 -0
  41. package/templates/account-qrcode/js/src/login-html.js +23 -0
  42. package/templates/account-qrcode/js/tsconfig.json +17 -0
  43. package/templates/account-qrcode/ts/.vscode/extensions.json +3 -0
  44. package/templates/account-qrcode/ts/.vscode/launch.json +19 -0
  45. package/templates/account-qrcode/ts/.vscode/settings.json +20 -0
  46. package/templates/account-qrcode/ts/.vscode/tasks.json +43 -0
  47. package/templates/account-qrcode/ts/README.md +15 -0
  48. package/templates/account-qrcode/ts/_gitignore +6 -0
  49. package/templates/account-qrcode/ts/ceru-plugin.code-workspace +8 -0
  50. package/templates/account-qrcode/ts/ceru.plugin.json +62 -0
  51. package/templates/account-qrcode/ts/package.json +24 -0
  52. package/templates/account-qrcode/ts/src/Login.vue +25 -0
  53. package/templates/account-qrcode/ts/src/index.ts +25 -0
  54. package/templates/account-qrcode/ts/src/login-html.ts +23 -0
  55. package/templates/account-qrcode/ts/tsconfig.json +17 -0
  56. package/templates/connected-library/js/.vscode/launch.json +12 -29
  57. package/templates/connected-library/js/.vscode/tasks.json +2 -3
  58. package/templates/connected-library/js/README.md +26 -12
  59. package/templates/connected-library/js/ceru.plugin.json +122 -50
  60. package/templates/connected-library/js/package.json +5 -5
  61. package/templates/connected-library/js/src/index.js +46 -5
  62. package/templates/connected-library/js/src/settings.js +28 -0
  63. package/templates/connected-library/ts/.vscode/launch.json +12 -29
  64. package/templates/connected-library/ts/.vscode/tasks.json +2 -3
  65. package/templates/connected-library/ts/README.md +26 -12
  66. package/templates/connected-library/ts/ceru.plugin.json +122 -50
  67. package/templates/connected-library/ts/package.json +5 -5
  68. package/templates/connected-library/ts/src/index.ts +46 -5
  69. package/templates/connected-library/ts/src/settings.ts +28 -0
  70. package/templates/encrypted-source/README.md +86 -0
  71. package/templates/encrypted-source/js/.prettierrc.json +5 -0
  72. package/templates/encrypted-source/js/.vscode/ceru.code-snippets +55 -0
  73. package/templates/encrypted-source/js/.vscode/extensions.json +3 -0
  74. package/templates/encrypted-source/js/.vscode/launch.json +15 -0
  75. package/templates/encrypted-source/js/.vscode/settings.json +20 -0
  76. package/templates/encrypted-source/js/.vscode/tasks.json +40 -0
  77. package/templates/encrypted-source/js/DEMO.md +77 -0
  78. package/templates/encrypted-source/js/README.md +13 -0
  79. package/templates/encrypted-source/js/_gitignore +6 -0
  80. package/templates/encrypted-source/js/ceru-plugin.code-workspace +8 -0
  81. package/templates/encrypted-source/js/ceru.plugin.json +95 -0
  82. package/templates/encrypted-source/js/package.json +26 -0
  83. package/templates/encrypted-source/js/resources/xor-byte.wasm +0 -0
  84. package/templates/encrypted-source/js/resources/xor-byte.wat +5 -0
  85. package/templates/encrypted-source/js/src/demo.js +200 -0
  86. package/templates/encrypted-source/js/src/fixtures.js +118 -0
  87. package/templates/encrypted-source/js/src/index.js +4 -0
  88. package/templates/encrypted-source/js/tests/demo.test.mjs +357 -0
  89. package/templates/encrypted-source/js/tsconfig.json +16 -0
  90. package/templates/encrypted-source/ts/.prettierrc.json +5 -0
  91. package/templates/encrypted-source/ts/.vscode/ceru.code-snippets +55 -0
  92. package/templates/encrypted-source/ts/.vscode/extensions.json +3 -0
  93. package/templates/encrypted-source/ts/.vscode/launch.json +15 -0
  94. package/templates/encrypted-source/ts/.vscode/settings.json +20 -0
  95. package/templates/encrypted-source/ts/.vscode/tasks.json +40 -0
  96. package/templates/encrypted-source/ts/DEMO.md +77 -0
  97. package/templates/encrypted-source/ts/README.md +13 -0
  98. package/templates/encrypted-source/ts/_gitignore +6 -0
  99. package/templates/encrypted-source/ts/ceru-plugin.code-workspace +8 -0
  100. package/templates/encrypted-source/ts/ceru.plugin.json +95 -0
  101. package/templates/encrypted-source/ts/package.json +26 -0
  102. package/templates/encrypted-source/ts/resources/xor-byte.wasm +0 -0
  103. package/templates/encrypted-source/ts/resources/xor-byte.wat +5 -0
  104. package/templates/encrypted-source/ts/src/demo.ts +212 -0
  105. package/templates/encrypted-source/ts/src/fixtures.ts +125 -0
  106. package/templates/encrypted-source/ts/src/index.ts +4 -0
  107. package/templates/encrypted-source/ts/tests/demo.test.mjs +357 -0
  108. package/templates/encrypted-source/ts/tsconfig.json +17 -0
  109. package/templates/guest-adapter/js/.vscode/launch.json +12 -29
  110. package/templates/guest-adapter/js/.vscode/tasks.json +2 -3
  111. package/templates/guest-adapter/js/README.md +10 -10
  112. package/templates/guest-adapter/js/ceru.plugin.json +67 -62
  113. package/templates/guest-adapter/js/package.json +5 -5
  114. package/templates/guest-adapter/js/src/index.js +1 -1
  115. package/templates/guest-adapter/js/src/settings.js +8 -0
  116. package/templates/guest-adapter/ts/.vscode/launch.json +12 -29
  117. package/templates/guest-adapter/ts/.vscode/tasks.json +2 -3
  118. package/templates/guest-adapter/ts/README.md +10 -10
  119. package/templates/guest-adapter/ts/ceru.plugin.json +67 -62
  120. package/templates/guest-adapter/ts/package.json +5 -5
  121. package/templates/guest-adapter/ts/src/index.ts +1 -1
  122. package/templates/guest-adapter/ts/src/settings.ts +8 -0
  123. package/templates/importer/js/.vscode/launch.json +12 -29
  124. package/templates/importer/js/.vscode/tasks.json +2 -3
  125. package/templates/importer/js/README.md +10 -10
  126. package/templates/importer/js/ceru.plugin.json +23 -21
  127. package/templates/importer/js/package.json +5 -5
  128. package/templates/importer/ts/.vscode/launch.json +12 -29
  129. package/templates/importer/ts/.vscode/tasks.json +2 -3
  130. package/templates/importer/ts/README.md +10 -10
  131. package/templates/importer/ts/ceru.plugin.json +23 -21
  132. package/templates/importer/ts/package.json +5 -5
  133. package/templates/page-extension/js/.vscode/extensions.json +3 -0
  134. package/templates/page-extension/js/.vscode/launch.json +19 -0
  135. package/templates/page-extension/js/.vscode/settings.json +20 -0
  136. package/templates/page-extension/js/.vscode/tasks.json +43 -0
  137. package/templates/page-extension/js/README.md +9 -0
  138. package/templates/page-extension/js/_gitignore +6 -0
  139. package/templates/page-extension/js/ceru-plugin.code-workspace +8 -0
  140. package/templates/page-extension/js/ceru.plugin.json +94 -0
  141. package/templates/page-extension/js/package.json +24 -0
  142. package/templates/page-extension/js/src/Open.vue +6 -0
  143. package/templates/page-extension/js/src/Search.vue +62 -0
  144. package/templates/page-extension/js/src/index.js +54 -0
  145. package/templates/page-extension/js/tsconfig.json +17 -0
  146. package/templates/page-extension/ts/.vscode/extensions.json +3 -0
  147. package/templates/page-extension/ts/.vscode/launch.json +19 -0
  148. package/templates/page-extension/ts/.vscode/settings.json +20 -0
  149. package/templates/page-extension/ts/.vscode/tasks.json +43 -0
  150. package/templates/page-extension/ts/README.md +9 -0
  151. package/templates/page-extension/ts/_gitignore +6 -0
  152. package/templates/page-extension/ts/ceru-plugin.code-workspace +8 -0
  153. package/templates/page-extension/ts/ceru.plugin.json +94 -0
  154. package/templates/page-extension/ts/package.json +24 -0
  155. package/templates/page-extension/ts/src/Open.vue +6 -0
  156. package/templates/page-extension/ts/src/Search.vue +62 -0
  157. package/templates/page-extension/ts/src/index.ts +54 -0
  158. package/templates/page-extension/ts/tsconfig.json +17 -0
  159. package/templates/playback-hook/js/.prettierrc.json +5 -0
  160. package/templates/playback-hook/js/.vscode/extensions.json +3 -0
  161. package/templates/playback-hook/js/.vscode/launch.json +19 -0
  162. package/templates/playback-hook/js/.vscode/settings.json +20 -0
  163. package/templates/playback-hook/js/.vscode/tasks.json +50 -0
  164. package/templates/playback-hook/js/README.md +24 -0
  165. package/templates/playback-hook/js/_gitignore +6 -0
  166. package/templates/playback-hook/js/ceru-plugin.code-workspace +8 -0
  167. package/templates/playback-hook/js/ceru.plugin.json +36 -0
  168. package/templates/playback-hook/js/package.json +23 -0
  169. package/templates/playback-hook/js/src/index.js +25 -0
  170. package/templates/playback-hook/js/tests/hooks.json +316 -0
  171. package/templates/playback-hook/js/tsconfig.json +16 -0
  172. package/templates/playback-hook/ts/.prettierrc.json +5 -0
  173. package/templates/playback-hook/ts/.vscode/extensions.json +3 -0
  174. package/templates/playback-hook/ts/.vscode/launch.json +19 -0
  175. package/templates/playback-hook/ts/.vscode/settings.json +20 -0
  176. package/templates/playback-hook/ts/.vscode/tasks.json +50 -0
  177. package/templates/playback-hook/ts/README.md +24 -0
  178. package/templates/playback-hook/ts/_gitignore +6 -0
  179. package/templates/playback-hook/ts/ceru-plugin.code-workspace +8 -0
  180. package/templates/playback-hook/ts/ceru.plugin.json +36 -0
  181. package/templates/playback-hook/ts/package.json +23 -0
  182. package/templates/playback-hook/ts/src/index.ts +25 -0
  183. package/templates/playback-hook/ts/tests/hooks.json +316 -0
  184. package/templates/playback-hook/ts/tsconfig.json +16 -0
  185. package/templates/player-skin/js/.vscode/extensions.json +3 -0
  186. package/templates/player-skin/js/.vscode/launch.json +19 -0
  187. package/templates/player-skin/js/.vscode/settings.json +20 -0
  188. package/templates/player-skin/js/.vscode/tasks.json +43 -0
  189. package/templates/player-skin/js/README.md +11 -0
  190. package/templates/player-skin/js/_gitignore +6 -0
  191. package/templates/player-skin/js/assets/studio-preview.svg +15 -0
  192. package/templates/player-skin/js/ceru-plugin.code-workspace +8 -0
  193. package/templates/player-skin/js/ceru.plugin.json +77 -0
  194. package/templates/player-skin/js/package.json +24 -0
  195. package/templates/player-skin/js/src/Artwork.vue +9 -0
  196. package/templates/player-skin/js/src/Background.vue +15 -0
  197. package/templates/player-skin/js/src/BuiltinLyrics.vue +15 -0
  198. package/templates/player-skin/js/src/Lyrics.vue +28 -0
  199. package/templates/player-skin/js/tsconfig.json +17 -0
  200. package/templates/player-skin/ts/.vscode/extensions.json +3 -0
  201. package/templates/player-skin/ts/.vscode/launch.json +19 -0
  202. package/templates/player-skin/ts/.vscode/settings.json +20 -0
  203. package/templates/player-skin/ts/.vscode/tasks.json +43 -0
  204. package/templates/player-skin/ts/README.md +11 -0
  205. package/templates/player-skin/ts/_gitignore +6 -0
  206. package/templates/player-skin/ts/assets/studio-preview.svg +15 -0
  207. package/templates/player-skin/ts/ceru-plugin.code-workspace +8 -0
  208. package/templates/player-skin/ts/ceru.plugin.json +77 -0
  209. package/templates/player-skin/ts/package.json +24 -0
  210. package/templates/player-skin/ts/src/Artwork.vue +9 -0
  211. package/templates/player-skin/ts/src/Background.vue +15 -0
  212. package/templates/player-skin/ts/src/BuiltinLyrics.vue +15 -0
  213. package/templates/player-skin/ts/src/Lyrics.vue +28 -0
  214. package/templates/player-skin/ts/tsconfig.json +17 -0
  215. package/templates/react/js/.vscode/launch.json +12 -29
  216. package/templates/react/js/.vscode/tasks.json +2 -3
  217. package/templates/react/js/README.md +10 -10
  218. package/templates/react/js/ceru.plugin.json +27 -22
  219. package/templates/react/js/package.json +5 -5
  220. package/templates/react/js/src/index.js +1 -1
  221. package/templates/react/ts/.vscode/launch.json +12 -29
  222. package/templates/react/ts/.vscode/tasks.json +2 -3
  223. package/templates/react/ts/README.md +10 -10
  224. package/templates/react/ts/ceru.plugin.json +27 -22
  225. package/templates/react/ts/package.json +5 -5
  226. package/templates/react/ts/src/index.ts +1 -1
  227. package/templates/snapshot.json +152 -6
  228. package/templates/source/js/.vscode/launch.json +12 -29
  229. package/templates/source/js/.vscode/tasks.json +2 -3
  230. package/templates/source/js/README.md +12 -10
  231. package/templates/source/js/ceru.plugin.json +44 -26
  232. package/templates/source/js/package.json +5 -5
  233. package/templates/source/js/src/index.js +10 -8
  234. package/templates/source/ts/.vscode/launch.json +12 -29
  235. package/templates/source/ts/.vscode/tasks.json +2 -3
  236. package/templates/source/ts/README.md +12 -10
  237. package/templates/source/ts/ceru.plugin.json +44 -26
  238. package/templates/source/ts/package.json +5 -5
  239. package/templates/source/ts/src/index.ts +10 -8
  240. package/templates/vue/js/.vscode/launch.json +12 -29
  241. package/templates/vue/js/.vscode/tasks.json +2 -3
  242. package/templates/vue/js/README.md +10 -10
  243. package/templates/vue/js/ceru.plugin.json +27 -22
  244. package/templates/vue/js/package.json +5 -5
  245. package/templates/vue/js/src/index.js +1 -1
  246. package/templates/vue/ts/.vscode/launch.json +12 -29
  247. package/templates/vue/ts/.vscode/tasks.json +2 -3
  248. package/templates/vue/ts/README.md +10 -10
  249. package/templates/vue/ts/ceru.plugin.json +27 -22
  250. package/templates/vue/ts/package.json +5 -5
  251. package/templates/vue/ts/src/index.ts +1 -1
  252. package/templates/vue-tsx/js/.vscode/launch.json +12 -29
  253. package/templates/vue-tsx/js/.vscode/tasks.json +2 -3
  254. package/templates/vue-tsx/js/README.md +10 -10
  255. package/templates/vue-tsx/js/ceru.plugin.json +27 -22
  256. package/templates/vue-tsx/js/package.json +5 -5
  257. package/templates/vue-tsx/js/src/index.js +1 -1
  258. package/templates/vue-tsx/ts/.vscode/launch.json +12 -29
  259. package/templates/vue-tsx/ts/.vscode/tasks.json +2 -3
  260. package/templates/vue-tsx/ts/README.md +10 -10
  261. package/templates/vue-tsx/ts/ceru.plugin.json +27 -22
  262. package/templates/vue-tsx/ts/package.json +5 -5
  263. package/templates/vue-tsx/ts/src/index.ts +1 -1
  264. package/templates/web-dist/js/.vscode/launch.json +12 -29
  265. package/templates/web-dist/js/.vscode/tasks.json +2 -3
  266. package/templates/web-dist/js/README.md +10 -10
  267. package/templates/web-dist/js/ceru.plugin.json +27 -22
  268. package/templates/web-dist/js/package.json +5 -5
  269. package/templates/web-dist/js/src/index.js +1 -1
  270. package/templates/web-dist/ts/.vscode/launch.json +12 -29
  271. package/templates/web-dist/ts/.vscode/tasks.json +2 -3
  272. package/templates/web-dist/ts/README.md +10 -10
  273. package/templates/web-dist/ts/ceru.plugin.json +27 -22
  274. package/templates/web-dist/ts/package.json +5 -5
  275. package/templates/web-dist/ts/src/index.ts +1 -1
  276. package/templates/web-surface/js/.vscode/launch.json +12 -29
  277. package/templates/web-surface/js/.vscode/tasks.json +2 -3
  278. package/templates/web-surface/js/README.md +10 -10
  279. package/templates/web-surface/js/ceru.plugin.json +35 -35
  280. package/templates/web-surface/js/package.json +5 -5
  281. package/templates/web-surface/js/src/index.js +1 -1
  282. package/templates/web-surface/ts/.vscode/launch.json +12 -29
  283. package/templates/web-surface/ts/.vscode/tasks.json +2 -3
  284. package/templates/web-surface/ts/README.md +10 -10
  285. package/templates/web-surface/ts/ceru.plugin.json +35 -35
  286. package/templates/web-surface/ts/package.json +5 -5
  287. package/templates/web-surface/ts/src/index.ts +1 -1
  288. package/assets/core-contracts.js +0 -1
  289. package/assets/electron-app/main.cjs +0 -1
  290. package/assets/electron-app/package.json +0 -8
  291. package/assets/electron.cjs +0 -42
  292. package/assets/index.html +0 -94
  293. package/assets/native-view.js +0 -197
  294. package/assets/playground.js +0 -883
  295. package/assets/sandbox.js +0 -67
  296. package/assets/style.css +0 -337
  297. package/dist/socket-broker.d.ts +0 -23
  298. package/dist/socket-broker.js +0 -229
  299. package/templates/connected-library/js/ui/settings.json +0 -24
  300. package/templates/connected-library/ts/ui/settings.json +0 -24
  301. package/templates/guest-adapter/js/ui/settings.json +0 -14
  302. package/templates/guest-adapter/ts/ui/settings.json +0 -14
@@ -0,0 +1,357 @@
1
+ import assert from 'node:assert/strict'
2
+ import { test } from 'node:test'
3
+ import { createCipheriv, createDecipheriv } from 'node:crypto'
4
+ import { createServer } from 'node:http'
5
+ import { readFile } from 'node:fs/promises'
6
+ import { installDemo, createWasmFactory, PROVIDERS } from '../src/demo.ts'
7
+ import {
8
+ AES_KEY,
9
+ AES_IV,
10
+ XOR_MASK,
11
+ createWav,
12
+ createFixtures,
13
+ createHandler,
14
+ } from '../src/fixtures.ts'
15
+
16
+ // These adapters test plugin logic with real crypto, WASM and loopback HTTP.
17
+ // They do not replace verification in a Ceru desktop worker/permission bridge.
18
+ function cipher(mode, algorithm, key, iv) {
19
+ const instance = (mode === 'encrypt' ? createCipheriv : createDecipheriv)(
20
+ algorithm,
21
+ Buffer.from(key, 'hex'),
22
+ Buffer.from(iv, 'hex'),
23
+ )
24
+ return new TransformStream({
25
+ transform(chunk, controller) {
26
+ controller.enqueue(new Uint8Array(instance.update(chunk)))
27
+ },
28
+ flush(controller) {
29
+ controller.enqueue(new Uint8Array(instance.final()))
30
+ },
31
+ })
32
+ }
33
+
34
+ function harness(t, { local = 'granted', audio = 'granted', failStart = false, beforeServe } = {}) {
35
+ const grants = new Map()
36
+ const prompts = []
37
+ const providers = new Map()
38
+ const actions = new Map()
39
+ const transforms = new Map()
40
+ const effects = []
41
+ const notifications = []
42
+ const handles = []
43
+ let starts = 0
44
+ const ctx = {
45
+ plugin: { id: 'local.encrypted-test' },
46
+ crypto: {
47
+ createCipher: (...args) => cipher('encrypt', ...args),
48
+ createDecipher: (...args) => cipher('decrypt', ...args),
49
+ },
50
+ wasm: {
51
+ async instantiate(id) {
52
+ assert.equal(id, 'xor-byte')
53
+ return WebAssembly.instantiate(
54
+ await readFile(new URL('../resources/xor-byte.wasm', import.meta.url)),
55
+ )
56
+ },
57
+ },
58
+ streams: {
59
+ registerTransform(id, factory) {
60
+ transforms.set(id, factory)
61
+ return () => {
62
+ transforms.delete(id)
63
+ }
64
+ },
65
+ },
66
+ effects: {
67
+ add(dispose) {
68
+ effects.push(dispose)
69
+ },
70
+ },
71
+ permissions: {
72
+ async query({ key }) {
73
+ return { status: grants.get(key) ?? 'prompt' }
74
+ },
75
+ async requestGroup(request) {
76
+ prompts.push(request)
77
+ const status = request.group === 'localServer' ? local : audio
78
+ for (const key of request.keys) grants.set(key, status)
79
+ return { group: request.group, status, grants: [] }
80
+ },
81
+ },
82
+ actions: {
83
+ register(id, action) {
84
+ actions.set(id, action)
85
+ },
86
+ },
87
+ providers: {
88
+ register(id, provider) {
89
+ providers.set(id, provider)
90
+ },
91
+ },
92
+ ui: {
93
+ async notify(value) {
94
+ notifications.push(value)
95
+ },
96
+ },
97
+ playback: {
98
+ failure(error) {
99
+ return { ok: false, error }
100
+ },
101
+ },
102
+ log: { info() {} },
103
+ server: {
104
+ async serve(handler, options) {
105
+ starts++
106
+ assert.deepEqual(options, { permissionKey: 'demo-server' })
107
+ assert.equal(grants.get('demo-server'), 'granted')
108
+ if (failStart && starts === 1) throw new Error('Simulated occupied listener')
109
+ await beforeServe?.()
110
+ const listener = createServer((incoming, outgoing) => {
111
+ Promise.resolve(
112
+ handler(
113
+ new Request(`http://127.0.0.1${incoming.url}`, {
114
+ method: incoming.method,
115
+ headers: incoming.headers,
116
+ }),
117
+ ),
118
+ )
119
+ .then(async (response) => {
120
+ outgoing.writeHead(response.status, Object.fromEntries(response.headers))
121
+ outgoing.end(Buffer.from(await response.arrayBuffer()))
122
+ })
123
+ .catch((error) => {
124
+ outgoing.writeHead(500)
125
+ outgoing.end(String(error))
126
+ })
127
+ })
128
+ await new Promise((resolve, reject) => {
129
+ listener.once('error', reject)
130
+ listener.listen(0, '127.0.0.1', resolve)
131
+ })
132
+ let closed = false
133
+ const handle = {
134
+ url: `http://127.0.0.1:${listener.address().port}`,
135
+ port: listener.address().port,
136
+ get closed() {
137
+ return closed
138
+ },
139
+ async close() {
140
+ if (closed) return
141
+ closed = true
142
+ await new Promise((resolve, reject) => {
143
+ listener.close((error) => (error ? reject(error) : resolve()))
144
+ listener.closeAllConnections()
145
+ })
146
+ },
147
+ }
148
+ handles.push(handle)
149
+ return handle
150
+ },
151
+ },
152
+ }
153
+ const dispose = async () => {
154
+ for (const effect of [...effects].reverse()) await effect()
155
+ }
156
+ t.after(dispose)
157
+ installDemo(ctx)
158
+ return {
159
+ ctx,
160
+ grants,
161
+ prompts,
162
+ providers,
163
+ actions,
164
+ transforms,
165
+ notifications,
166
+ handles,
167
+ dispose,
168
+ get starts() {
169
+ return starts
170
+ },
171
+ }
172
+ }
173
+
174
+ const operation = { userIntent: { kind: 'user-intent', id: 'test-click' } }
175
+ const ref = (id) => ({
176
+ pluginId: 'local.encrypted-test',
177
+ providerId: id,
178
+ kind: 'track',
179
+ id: 'tone-440',
180
+ })
181
+ const resolve = (h, id) => h.providers.get(id).tracks.resolve(ref(id), undefined, operation)
182
+ const bytes = async (response) => new Uint8Array(await response.arrayBuffer())
183
+
184
+ test('AES fixture roundtrip, WAV structure, WASM byte transform and concurrent offsets', async (t) => {
185
+ const h = harness(t)
186
+ const wav = createWav()
187
+ assert.equal(wav.length, 96044)
188
+ assert.equal(Buffer.from(wav.subarray(0, 4)).toString(), 'RIFF')
189
+ const view = new DataView(wav.buffer)
190
+ assert.equal(view.getUint32(4, true) + 8, wav.length)
191
+ assert.equal(view.getUint32(24, true), 16000)
192
+ assert.equal(view.getUint16(34, true), 16)
193
+ const fixture = await createFixtures(h.ctx)
194
+ assert.deepEqual(fixture.plain, wav)
195
+ assert.notDeepEqual(fixture.aes, wav)
196
+ assert.notDeepEqual(fixture.xor, wav)
197
+ const factory = createWasmFactory(h.ctx)
198
+ const controller = new AbortController()
199
+ const first = await factory.create({ offset: 0, signal: controller.signal })
200
+ const second = await factory.create({ offset: 37 })
201
+ assert.deepEqual(await first.transform(fixture.xor.subarray(0, 37)), wav.subarray(0, 37))
202
+ assert.deepEqual(await second.transform(fixture.xor.subarray(37)), wav.subarray(37))
203
+ const allBytes = Uint8Array.from({ length: 256 }, (_, index) => index)
204
+ assert.deepEqual(
205
+ await first.transform(allBytes),
206
+ allBytes.map((byte) => byte ^ XOR_MASK),
207
+ )
208
+ controller.abort()
209
+ assert.throws(() => first.transform(fixture.xor), /abort/i)
210
+ })
211
+
212
+ test('Web handler supports HEAD, exact, open, suffix and invalid byte ranges', async (t) => {
213
+ const h = harness(t)
214
+ const fixture = await createFixtures(h.ctx)
215
+ const handler = createHandler(fixture)
216
+ for (const [path, data] of [
217
+ ['/plain.wav', fixture.plain],
218
+ ['/aes.wav.enc', fixture.aes],
219
+ ['/xor.wav.enc', fixture.xor],
220
+ ]) {
221
+ for (const [range, start, end] of [
222
+ ['bytes=17-42', 17, 42],
223
+ ['bytes=96000-', 96000, 96043],
224
+ ['bytes=-31', 96013, 96043],
225
+ ['bytes=0-999999', 0, 96043],
226
+ ]) {
227
+ const response = handler(new Request('http://local' + path, { headers: { range } }))
228
+ assert.equal(response.status, 206)
229
+ assert.equal(response.headers.get('content-range'), `bytes ${start}-${end}/96044`)
230
+ assert.deepEqual(await bytes(response), data.slice(start, end + 1))
231
+ }
232
+ const head = handler(new Request('http://local' + path, { method: 'HEAD' }))
233
+ assert.equal(head.headers.get('content-length'), '96044')
234
+ assert.equal((await head.arrayBuffer()).byteLength, 0)
235
+ for (const range of [
236
+ 'bytes=-0',
237
+ 'bytes=9-3',
238
+ 'bytes=96044-',
239
+ 'bytes=0-1,4-5',
240
+ 'bytes=-',
241
+ 'garbage',
242
+ ]) {
243
+ assert.equal(handler(new Request('http://local' + path, { headers: { range } })).status, 416)
244
+ }
245
+ }
246
+ assert.equal(handler(new Request('http://local/missing')).status, 404)
247
+ assert.equal(handler(new Request('http://local/plain.wav', { method: 'POST' })).status, 405)
248
+ })
249
+
250
+ test('search/lyrics need no grants or listener, refs and paging stay provider scoped', async (t) => {
251
+ const h = harness(t)
252
+ assert.equal(h.providers.size, 3)
253
+ for (const { id } of PROVIDERS) {
254
+ const tracks = h.providers.get(id).tracks
255
+ const page = await tracks.search({ query: 'ENCRYPTED demo', limit: 10 })
256
+ assert.deepEqual(page.items[0].ref, ref(id))
257
+ assert.equal(page.items[0].durationMs, 3000)
258
+ assert.equal((await tracks.search({ query: 'unrelated', limit: 10 })).items.length, 0)
259
+ assert.equal((await tracks.search({ query: '', limit: 10, cursor: 'done' })).items.length, 0)
260
+ assert.equal((await tracks.lyrics(ref(id))).lines.length, 3)
261
+ assert.equal(
262
+ (await tracks.resolve({ ...ref(id), id: 'unknown' }, undefined, operation)).error.code,
263
+ 'NOT_FOUND',
264
+ )
265
+ assert.equal(
266
+ (await tracks.resolve(ref('other-provider'), undefined, operation)).error.code,
267
+ 'NOT_FOUND',
268
+ )
269
+ }
270
+ assert.equal(h.prompts.length, 0)
271
+ assert.equal(h.starts, 0)
272
+ })
273
+
274
+ test('three provider URLs play identical bytes using one real loopback listener', async (t) => {
275
+ const h = harness(t)
276
+ const results = await Promise.all(PROVIDERS.map(({ id }) => resolve(h, id)))
277
+ assert.equal(h.starts, 1)
278
+ for (const result of results) {
279
+ assert.equal(result.ok, true)
280
+ const response = await fetch(result.url)
281
+ assert.equal(response.status, 200)
282
+ let decoded = await bytes(response)
283
+ if (result.stream?.decrypt) {
284
+ const decoder = createDecipheriv(
285
+ 'aes-128-ctr',
286
+ Buffer.from(AES_KEY, 'hex'),
287
+ Buffer.from(AES_IV, 'hex'),
288
+ )
289
+ decoded = new Uint8Array(Buffer.concat([decoder.update(decoded), decoder.final()]))
290
+ } else if (result.stream?.transform) {
291
+ const transform = await h.transforms.get(result.stream.transform).create({ offset: 0 })
292
+ decoded = await transform.transform(decoded)
293
+ }
294
+ assert.deepEqual(decoded, createWav())
295
+ const range = await fetch(result.url, { headers: { Range: 'bytes=32-63' } })
296
+ assert.equal(range.status, 206)
297
+ assert.equal((await range.arrayBuffer()).byteLength, 32)
298
+ }
299
+ assert.equal(results[2].stream, undefined)
300
+ assert.ok(h.prompts.every((prompt) => prompt.intent === operation.userIntent))
301
+ await h.dispose()
302
+ assert.equal(h.transforms.size, 0)
303
+ assert.equal(h.handles[0].closed, true)
304
+ })
305
+
306
+ test('denied transform only blocks WASM; built-in decrypt and own service still work', async (t) => {
307
+ const h = harness(t, { audio: 'denied' })
308
+ const wasm = await resolve(h, 'wasm-transform')
309
+ assert.equal(wasm.error.code, 'PERMISSION_DENIED')
310
+ assert.match(wasm.error.message, /denied/)
311
+ assert.equal(wasm.error.recovery.actions[0].commandId, 'demo.start')
312
+ assert.equal(h.starts, 0)
313
+ assert.equal((await resolve(h, 'builtin-decrypt')).ok, true)
314
+ assert.equal((await resolve(h, 'own-service')).ok, true)
315
+ assert.equal(h.starts, 1)
316
+ })
317
+
318
+ test('denied server permission blocks every provider and start action explains it', async (t) => {
319
+ const h = harness(t, { local: 'denied' })
320
+ for (const { id } of PROVIDERS)
321
+ assert.equal((await resolve(h, id)).error.code, 'PERMISSION_DENIED')
322
+ await h.actions.get('demo.start')(null, operation)
323
+ assert.equal(h.notifications.at(-1).level, 'error')
324
+ assert.match(h.notifications.at(-1).message, /denied/)
325
+ assert.equal(h.starts, 0)
326
+ })
327
+
328
+ test('server start failure is actionable and the next resolve retries', async (t) => {
329
+ const h = harness(t, { failStart: true })
330
+ assert.equal((await resolve(h, 'own-service')).error.code, 'INTERNAL')
331
+ assert.equal((await resolve(h, 'own-service')).ok, true)
332
+ assert.equal(h.starts, 2)
333
+ })
334
+
335
+ test('unload during server startup closes the late listener', async (t) => {
336
+ let release
337
+ let entered
338
+ const atServe = new Promise((resolve) => {
339
+ entered = resolve
340
+ })
341
+ const gate = new Promise((resolve) => {
342
+ release = resolve
343
+ })
344
+ const h = harness(t, {
345
+ beforeServe: async () => {
346
+ entered()
347
+ await gate
348
+ },
349
+ })
350
+ const pending = resolve(h, 'own-service')
351
+ await atServe
352
+ const stopping = h.dispose()
353
+ release()
354
+ assert.equal((await pending).error.code, 'INTERNAL')
355
+ await stopping
356
+ assert.equal(h.handles[0].closed, true)
357
+ })
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "noEmit": true,
8
+ "skipLibCheck": true,
9
+ "allowJs": true,
10
+ "checkJs": false,
11
+ "lib": ["ES2022", "DOM"],
12
+ "types": [],
13
+ "jsx": "react-jsx",
14
+ "allowImportingTsExtensions": true
15
+ },
16
+ "include": ["src", ".ceru-dev/types/**/*.d.ts"]
17
+ }
@@ -2,35 +2,18 @@
2
2
  "version": "0.2.0",
3
3
  "configurations": [
4
4
  {
5
- "name": "Launch Ceru plugin",
6
- "type": "pwa-chrome",
7
- "request": "attach",
8
- "port": 9223,
9
- "preLaunchTask": "Ceru: dev",
10
- "webRoot": "${workspaceFolder}",
11
- "sourceMaps": true,
12
- "sourceMapPathOverrides": {
13
- "ceru:///*": "${workspaceFolder}/*"
14
- },
15
- "skipFiles": ["**/node_modules/**"],
16
- "address": "127.0.0.1",
17
- "urlFilter": "http://127.0.0.1:4179/",
18
- "timeout": 30000
19
- },
20
- {
21
- "name": "Attach to Ceru plugin",
22
- "type": "pwa-chrome",
23
- "request": "attach",
24
- "port": 9223,
25
- "webRoot": "${workspaceFolder}",
26
- "sourceMaps": true,
27
- "sourceMapPathOverrides": {
28
- "ceru:///*": "${workspaceFolder}/*"
29
- },
30
- "skipFiles": ["**/node_modules/**"],
31
- "address": "127.0.0.1",
32
- "urlFilter": "http://127.0.0.1:4179/",
33
- "timeout": 30000
5
+ "name": "Watch Ceru plugin",
6
+ "type": "node",
7
+ "request": "launch",
8
+ "program": "${workspaceFolder}/node_modules/@shiqianjiang/ceru-plugin-cli/dist/bin.js",
9
+ "args": [
10
+ "dev"
11
+ ],
12
+ "cwd": "${workspaceFolder}",
13
+ "console": "integratedTerminal",
14
+ "skipFiles": [
15
+ "<node_internals>/**"
16
+ ]
34
17
  }
35
18
  ]
36
19
  }
@@ -14,14 +14,13 @@
14
14
  "background": {
15
15
  "activeOnStart": true,
16
16
  "beginsPattern": "^.*$",
17
- "endsPattern": "^CERU_DEBUG_READY "
17
+ "endsPattern": "^CERU_BUILD_READY "
18
18
  }
19
19
  },
20
20
  "command": "node",
21
21
  "args": [
22
22
  "${workspaceFolder}/node_modules/@shiqianjiang/ceru-plugin-cli/dist/bin.js",
23
- "dev",
24
- "--ensure-running"
23
+ "dev"
25
24
  ],
26
25
  "options": {
27
26
  "cwd": "${workspaceFolder}"
@@ -1,22 +1,22 @@
1
1
  # guest-adapter / js
2
2
 
3
- Ceru Music v2 插件开发模板。此目录是源码,不是安装包。
3
+ Ceru Music v3 插件开发模板。此目录是源码,不是安装包。
4
4
 
5
5
  ## 运行 demo
6
6
 
7
- 1. 使用脚手架创建工程:
7
+ 1. 使用匹配的 v3 脚手架创建工程(本地开发套件可使用其 `npm run create` 命令):
8
8
 
9
- npm create ceru-plugin@latest my-plugin -- --template guest-adapter --lang js
9
+ ceru-plugin init my-plugin --template guest-adapter --lang js
10
10
 
11
11
  2. 进入目录,运行 npm install。
12
- 3. 运行 npm run dev,打开独立 Electron 调试工作台。
12
+ 3. 运行 npm run dev,在澜音「设置 → 插件管理 → 管理设置 → 插件开发者模式」添加终端打印的 JS 文件。
13
13
  4. 修改 src 中的代码;保存后自动类型检查并重载。
14
14
  5. 运行 npm run build,只分发 dist/plugin.js。
15
15
 
16
16
  ## 编辑器
17
17
 
18
- VS Code 按 F5 选择 Launch Ceru plugin;已有调试窗口时选择 Attach to Ceru plugin。
19
- 激活代码已经执行时,可点击“重新运行”再次命中断点。
18
+ VS Code 按 F5 选择 Watch Ceru plugin,会启动本地构建监听,不会另开 Electron。
19
+ 已在终端运行 npm run dev 时不必再按 F5。
20
20
  配置文件有 JSON Schema 提示,SDK 提供参数类型、图标名称与 Lodash 方法补全。
21
21
 
22
22
  ## 宿主资源
@@ -26,17 +26,17 @@ VS Code 按 F5 选择 Launch Ceru plugin;已有调试窗口时选择 Attach to
26
26
  - 默认封面:await ctx.assets.url('placeholder.cover')。
27
27
  - 共享工具:ctx.utils.lodash。
28
28
 
29
- Vue/React 的生产运行代码、页面和样式直接编入发行 JS,宿主不提供框架。
29
+ 视图是否自带框架由清单的 `entry.views[].kind` 决定:`web` 页面打包自己用到的框架;`native` 由宿主绘制;`component` 复用宿主提供的 Vue、TDesign 和音乐组件。开发宿主风格的页面可选 `page-extension` 模板,播放器区域可选 `player-skin`,不需要复制桌面组件源码。
30
30
  TypeScript、Vue 编译器、构建工具与开发服务器不会进入产物。
31
- 运行 npm run preview 可只加载 dist/plugin.js 检查发布后的行为。
31
+ 运行 `npm run typecheck` 只检查工程,不生成发行文件。可选 `npm run preview` 验证构建产物并打印路径;将该文件加入桌面的插件开发者模式即可预览,不会启动服务器。
32
32
 
33
33
  若 VS Code 打开的是父目录,请打开本工程的 ceru-plugin.code-workspace,
34
- 再在“运行和调试”中选择 Launch Ceru plugin;已经运行 npm/pnpm dev 时选择 Attach to Ceru plugin。
34
+ 再在“运行和调试”中选择 Watch Ceru plugin。
35
35
  F5 执行当前下拉框中的配置,不会自动选择终端所在的子工程。
36
36
 
37
37
  ## 边界
38
38
 
39
- 本模板面向 v2 协议。开发工作台不是当前 v1 桌面 Host 的兼容层。
39
+ 本模板面向 v3 协议。需要支持 v3 的宿主。
40
40
  凭据保险箱、完整音乐业务和 Guest 安装需要正式 Host;不支持的调试调用会明确报错。
41
41
  不要把私人 API Key、卡密或发行私钥提交到仓库。
42
42
 
@@ -1,43 +1,43 @@
1
1
  {
2
2
  "manifest": {
3
- "manifestVersion": 2,
3
+ "manifestVersion": 3,
4
4
  "id": "local.js",
5
5
  "name": "js",
6
6
  "version": "0.1.0",
7
- "description": "A Ceru Music v2 guest-adapter plugin",
7
+ "description": "A Ceru Music v3 guest-adapter plugin",
8
+ "dataSchemas": {
9
+ "config": 1,
10
+ "state": 1
11
+ },
12
+ "guestPolicy": {
13
+ "maxDepth": 1,
14
+ "allowedCapabilities": [
15
+ "network.request"
16
+ ],
17
+ "networkScopeMode": "per-guest-user-approved",
18
+ "allowNativeCode": false,
19
+ "allowRemoteCodeExecution": false
20
+ },
8
21
  "engines": {
9
- "hostApi": "^2.0.0",
10
- "logicRuntime": "ceru-js@1",
11
- "uiSchema": "^1.0.0"
22
+ "hostApi": "^3.0.0",
23
+ "logicRuntime": "ceru-js@1"
12
24
  },
13
- "modules": {
25
+ "entry": {
14
26
  "logic": {
15
- "entry": "logic.main",
16
- "activation": ["onCommand:hello"]
27
+ "activation": [
28
+ "onCommand:hello"
29
+ ],
30
+ "module": "logic.main"
17
31
  },
18
- "surfaces": [
32
+ "views": [
19
33
  {
20
34
  "id": "settings",
21
- "kind": "schema",
22
- "entry": "schema.settings"
35
+ "kind": "web",
36
+ "module": "view.settings"
23
37
  }
24
38
  ]
25
39
  },
26
- "contributes": {
27
- "commands": [
28
- {
29
- "id": "hello",
30
- "title": "Hello",
31
- "action": "hello"
32
- }
33
- ],
34
- "settingsPages": [
35
- {
36
- "id": "settings",
37
- "title": "插件设置",
38
- "view": "settings"
39
- }
40
- ],
40
+ "provides": {
41
41
  "guestAdapters": [
42
42
  {
43
43
  "id": "example-script",
@@ -45,51 +45,56 @@
45
45
  "compatibilityProfile": "basic@1",
46
46
  "bootstrap": "guest.bootstrap",
47
47
  "runtime": "ceru-js@1",
48
- "projectableProtocols": ["music.resolve@1"]
48
+ "projectableProtocols": [
49
+ "music.resolve@1"
50
+ ]
51
+ }
52
+ ],
53
+ "actions": [
54
+ {
55
+ "id": "hello",
56
+ "title": "Hello"
49
57
  }
50
58
  ]
51
59
  },
52
- "permissions": [
53
- {
54
- "key": "guest-manage",
55
- "name": "guests.manage",
56
- "scope": {
57
- "parent": "self"
58
- },
59
- "reason": "管理用户批准的子插件",
60
- "optional": true
61
- },
62
- {
63
- "key": "guest-run",
64
- "name": "guests.run",
65
- "scope": {
66
- "parent": "self"
60
+ "uses": {
61
+ "permissions": [
62
+ {
63
+ "key": "guest-manage",
64
+ "name": "guests.manage",
65
+ "scope": {
66
+ "parent": "self"
67
+ },
68
+ "reason": "管理用户批准的子插件",
69
+ "optional": true
67
70
  },
68
- "reason": "运行已批准的子插件",
69
- "optional": true
70
- }
71
- ],
72
- "dataSchemas": {
73
- "config": 1,
74
- "state": 1
71
+ {
72
+ "key": "guest-run",
73
+ "name": "guests.run",
74
+ "scope": {
75
+ "parent": "self"
76
+ },
77
+ "reason": "运行已批准的子插件",
78
+ "optional": true
79
+ }
80
+ ]
75
81
  },
76
- "guestPolicy": {
77
- "maxDepth": 1,
78
- "allowedCapabilities": ["network.request"],
79
- "networkScopeMode": "per-guest-user-approved",
80
- "allowNativeCode": false,
81
- "allowRemoteCodeExecution": false
82
+ "ui": {
83
+ "pages": [
84
+ {
85
+ "id": "settings",
86
+ "title": "插件设置",
87
+ "view": "settings",
88
+ "mount": "settings"
89
+ }
90
+ ]
82
91
  }
83
92
  },
84
93
  "entries": {
85
94
  "logic.main": "src/index.js",
86
- "guest.bootstrap": "src/guest.js"
87
- },
88
- "resources": {
89
- "schema.settings": {
90
- "path": "ui/settings.json",
91
- "type": "json"
92
- }
95
+ "guest.bootstrap": "src/guest.js",
96
+ "view.settings": "src/settings.js"
93
97
  },
98
+ "resources": {},
94
99
  "output": "dist/plugin.js"
95
100
  }
@@ -6,17 +6,17 @@
6
6
  "scripts": {
7
7
  "dev": "ceru-plugin dev",
8
8
  "build": "ceru-plugin build",
9
- "typecheck": "tsc --noEmit",
9
+ "typecheck": "ceru-plugin typecheck",
10
10
  "validate": "ceru-plugin validate dist/plugin.js",
11
- "preview": "ceru-plugin preview dist/plugin.js"
11
+ "preview": "ceru-plugin preview dist/plugin.js",
12
+ "check:compat": "ceru-plugin check-compat"
12
13
  },
13
14
  "dependencies": {
14
- "@shiqianjiang/ceru-plugin-sdk": "^0.3.16"
15
+ "@shiqianjiang/ceru-plugin-sdk": "^3.0.0"
15
16
  },
16
17
  "devDependencies": {
17
- "@shiqianjiang/ceru-plugin-cli": "^0.3.16",
18
+ "@shiqianjiang/ceru-plugin-cli": "^3.0.0",
18
19
  "typescript": "~5.9.3",
19
- "electron": "^44.4.2",
20
20
  "prettier": "^3.6.2"
21
21
  }
22
22
  }