@shiqianjiang/ceru-plugin-cli 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 +26 -7
- package/assets/compatibility.json +18 -0
- package/dist/compatibility.d.ts +24 -0
- package/dist/compatibility.js +119 -0
- package/dist/component.d.ts +6 -0
- package/dist/component.js +60 -0
- package/dist/dev-music.d.ts +19 -0
- package/dist/dev-music.js +81 -0
- package/dist/dev-plugin-services.d.ts +10 -0
- package/dist/dev-plugin-services.js +67 -0
- package/dist/dev.d.ts +1 -9
- package/dist/dev.js +53 -713
- package/dist/frameworks.d.ts +5 -2
- package/dist/frameworks.js +43 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +54 -23
- package/dist/init.js +3 -3
- package/dist/migrate.d.ts +3 -0
- package/dist/migrate.js +109 -0
- package/dist/project.d.ts +5 -2
- package/dist/project.js +131 -43
- package/dist/test-hooks.d.ts +1 -0
- package/dist/test-hooks.js +209 -0
- package/dist/test-services.d.ts +4 -0
- package/dist/test-services.js +54 -0
- package/dist/watch-vue-types.d.ts +17 -0
- package/dist/watch-vue-types.js +145 -0
- package/package.json +10 -6
- package/schemas/config.schema.json +954 -452
- package/templates/account-qrcode/js/.vscode/extensions.json +3 -0
- package/templates/account-qrcode/js/.vscode/launch.json +19 -0
- package/templates/account-qrcode/js/.vscode/settings.json +20 -0
- package/templates/account-qrcode/js/.vscode/tasks.json +43 -0
- package/templates/account-qrcode/js/README.md +15 -0
- package/templates/account-qrcode/js/_gitignore +6 -0
- package/templates/account-qrcode/js/ceru-plugin.code-workspace +8 -0
- package/templates/account-qrcode/js/ceru.plugin.json +62 -0
- package/templates/account-qrcode/js/package.json +24 -0
- package/templates/account-qrcode/js/src/Login.vue +25 -0
- package/templates/account-qrcode/js/src/index.js +25 -0
- package/templates/account-qrcode/js/src/login-html.js +23 -0
- package/templates/account-qrcode/js/tsconfig.json +17 -0
- package/templates/account-qrcode/ts/.vscode/extensions.json +3 -0
- package/templates/account-qrcode/ts/.vscode/launch.json +19 -0
- package/templates/account-qrcode/ts/.vscode/settings.json +20 -0
- package/templates/account-qrcode/ts/.vscode/tasks.json +43 -0
- package/templates/account-qrcode/ts/README.md +15 -0
- package/templates/account-qrcode/ts/_gitignore +6 -0
- package/templates/account-qrcode/ts/ceru-plugin.code-workspace +8 -0
- package/templates/account-qrcode/ts/ceru.plugin.json +62 -0
- package/templates/account-qrcode/ts/package.json +24 -0
- package/templates/account-qrcode/ts/src/Login.vue +25 -0
- package/templates/account-qrcode/ts/src/index.ts +25 -0
- package/templates/account-qrcode/ts/src/login-html.ts +23 -0
- package/templates/account-qrcode/ts/tsconfig.json +17 -0
- package/templates/connected-library/js/.vscode/launch.json +12 -29
- package/templates/connected-library/js/.vscode/tasks.json +2 -3
- package/templates/connected-library/js/README.md +26 -12
- package/templates/connected-library/js/ceru.plugin.json +122 -50
- package/templates/connected-library/js/package.json +5 -5
- package/templates/connected-library/js/src/index.js +46 -5
- package/templates/connected-library/js/src/settings.js +28 -0
- package/templates/connected-library/ts/.vscode/launch.json +12 -29
- package/templates/connected-library/ts/.vscode/tasks.json +2 -3
- package/templates/connected-library/ts/README.md +26 -12
- package/templates/connected-library/ts/ceru.plugin.json +122 -50
- package/templates/connected-library/ts/package.json +5 -5
- package/templates/connected-library/ts/src/index.ts +46 -5
- package/templates/connected-library/ts/src/settings.ts +28 -0
- package/templates/encrypted-source/README.md +86 -0
- package/templates/encrypted-source/js/.prettierrc.json +5 -0
- package/templates/encrypted-source/js/.vscode/ceru.code-snippets +55 -0
- package/templates/encrypted-source/js/.vscode/extensions.json +3 -0
- package/templates/encrypted-source/js/.vscode/launch.json +15 -0
- package/templates/encrypted-source/js/.vscode/settings.json +20 -0
- package/templates/encrypted-source/js/.vscode/tasks.json +40 -0
- package/templates/encrypted-source/js/DEMO.md +77 -0
- package/templates/encrypted-source/js/README.md +13 -0
- package/templates/encrypted-source/js/_gitignore +6 -0
- package/templates/encrypted-source/js/ceru-plugin.code-workspace +8 -0
- package/templates/encrypted-source/js/ceru.plugin.json +95 -0
- package/templates/encrypted-source/js/package.json +26 -0
- package/templates/encrypted-source/js/resources/xor-byte.wasm +0 -0
- package/templates/encrypted-source/js/resources/xor-byte.wat +5 -0
- package/templates/encrypted-source/js/src/demo.js +200 -0
- package/templates/encrypted-source/js/src/fixtures.js +118 -0
- package/templates/encrypted-source/js/src/index.js +4 -0
- package/templates/encrypted-source/js/tests/demo.test.mjs +357 -0
- package/templates/encrypted-source/js/tsconfig.json +16 -0
- package/templates/encrypted-source/ts/.prettierrc.json +5 -0
- package/templates/encrypted-source/ts/.vscode/ceru.code-snippets +55 -0
- package/templates/encrypted-source/ts/.vscode/extensions.json +3 -0
- package/templates/encrypted-source/ts/.vscode/launch.json +15 -0
- package/templates/encrypted-source/ts/.vscode/settings.json +20 -0
- package/templates/encrypted-source/ts/.vscode/tasks.json +40 -0
- package/templates/encrypted-source/ts/DEMO.md +77 -0
- package/templates/encrypted-source/ts/README.md +13 -0
- package/templates/encrypted-source/ts/_gitignore +6 -0
- package/templates/encrypted-source/ts/ceru-plugin.code-workspace +8 -0
- package/templates/encrypted-source/ts/ceru.plugin.json +95 -0
- package/templates/encrypted-source/ts/package.json +26 -0
- package/templates/encrypted-source/ts/resources/xor-byte.wasm +0 -0
- package/templates/encrypted-source/ts/resources/xor-byte.wat +5 -0
- package/templates/encrypted-source/ts/src/demo.ts +212 -0
- package/templates/encrypted-source/ts/src/fixtures.ts +125 -0
- package/templates/encrypted-source/ts/src/index.ts +4 -0
- package/templates/encrypted-source/ts/tests/demo.test.mjs +357 -0
- package/templates/encrypted-source/ts/tsconfig.json +17 -0
- package/templates/guest-adapter/js/.vscode/launch.json +12 -29
- package/templates/guest-adapter/js/.vscode/tasks.json +2 -3
- package/templates/guest-adapter/js/README.md +10 -10
- package/templates/guest-adapter/js/ceru.plugin.json +67 -62
- package/templates/guest-adapter/js/package.json +5 -5
- package/templates/guest-adapter/js/src/index.js +1 -1
- package/templates/guest-adapter/js/src/settings.js +8 -0
- package/templates/guest-adapter/ts/.vscode/launch.json +12 -29
- package/templates/guest-adapter/ts/.vscode/tasks.json +2 -3
- package/templates/guest-adapter/ts/README.md +10 -10
- package/templates/guest-adapter/ts/ceru.plugin.json +67 -62
- package/templates/guest-adapter/ts/package.json +5 -5
- package/templates/guest-adapter/ts/src/index.ts +1 -1
- package/templates/guest-adapter/ts/src/settings.ts +8 -0
- package/templates/importer/js/.vscode/launch.json +12 -29
- package/templates/importer/js/.vscode/tasks.json +2 -3
- package/templates/importer/js/README.md +10 -10
- package/templates/importer/js/ceru.plugin.json +23 -21
- package/templates/importer/js/package.json +5 -5
- package/templates/importer/ts/.vscode/launch.json +12 -29
- package/templates/importer/ts/.vscode/tasks.json +2 -3
- package/templates/importer/ts/README.md +10 -10
- package/templates/importer/ts/ceru.plugin.json +23 -21
- package/templates/importer/ts/package.json +5 -5
- package/templates/page-extension/js/.vscode/extensions.json +3 -0
- package/templates/page-extension/js/.vscode/launch.json +19 -0
- package/templates/page-extension/js/.vscode/settings.json +20 -0
- package/templates/page-extension/js/.vscode/tasks.json +43 -0
- package/templates/page-extension/js/README.md +9 -0
- package/templates/page-extension/js/_gitignore +6 -0
- package/templates/page-extension/js/ceru-plugin.code-workspace +8 -0
- package/templates/page-extension/js/ceru.plugin.json +94 -0
- package/templates/page-extension/js/package.json +24 -0
- package/templates/page-extension/js/src/Open.vue +6 -0
- package/templates/page-extension/js/src/Search.vue +62 -0
- package/templates/page-extension/js/src/index.js +54 -0
- package/templates/page-extension/js/tsconfig.json +17 -0
- package/templates/page-extension/ts/.vscode/extensions.json +3 -0
- package/templates/page-extension/ts/.vscode/launch.json +19 -0
- package/templates/page-extension/ts/.vscode/settings.json +20 -0
- package/templates/page-extension/ts/.vscode/tasks.json +43 -0
- package/templates/page-extension/ts/README.md +9 -0
- package/templates/page-extension/ts/_gitignore +6 -0
- package/templates/page-extension/ts/ceru-plugin.code-workspace +8 -0
- package/templates/page-extension/ts/ceru.plugin.json +94 -0
- package/templates/page-extension/ts/package.json +24 -0
- package/templates/page-extension/ts/src/Open.vue +6 -0
- package/templates/page-extension/ts/src/Search.vue +62 -0
- package/templates/page-extension/ts/src/index.ts +54 -0
- package/templates/page-extension/ts/tsconfig.json +17 -0
- package/templates/playback-hook/js/.prettierrc.json +5 -0
- package/templates/playback-hook/js/.vscode/extensions.json +3 -0
- package/templates/playback-hook/js/.vscode/launch.json +19 -0
- package/templates/playback-hook/js/.vscode/settings.json +20 -0
- package/templates/playback-hook/js/.vscode/tasks.json +50 -0
- package/templates/playback-hook/js/README.md +24 -0
- package/templates/playback-hook/js/_gitignore +6 -0
- package/templates/playback-hook/js/ceru-plugin.code-workspace +8 -0
- package/templates/playback-hook/js/ceru.plugin.json +36 -0
- package/templates/playback-hook/js/package.json +23 -0
- package/templates/playback-hook/js/src/index.js +25 -0
- package/templates/playback-hook/js/tests/hooks.json +316 -0
- package/templates/playback-hook/js/tsconfig.json +16 -0
- package/templates/playback-hook/ts/.prettierrc.json +5 -0
- package/templates/playback-hook/ts/.vscode/extensions.json +3 -0
- package/templates/playback-hook/ts/.vscode/launch.json +19 -0
- package/templates/playback-hook/ts/.vscode/settings.json +20 -0
- package/templates/playback-hook/ts/.vscode/tasks.json +50 -0
- package/templates/playback-hook/ts/README.md +24 -0
- package/templates/playback-hook/ts/_gitignore +6 -0
- package/templates/playback-hook/ts/ceru-plugin.code-workspace +8 -0
- package/templates/playback-hook/ts/ceru.plugin.json +36 -0
- package/templates/playback-hook/ts/package.json +23 -0
- package/templates/playback-hook/ts/src/index.ts +25 -0
- package/templates/playback-hook/ts/tests/hooks.json +316 -0
- package/templates/playback-hook/ts/tsconfig.json +16 -0
- package/templates/player-skin/js/.vscode/extensions.json +3 -0
- package/templates/player-skin/js/.vscode/launch.json +19 -0
- package/templates/player-skin/js/.vscode/settings.json +20 -0
- package/templates/player-skin/js/.vscode/tasks.json +43 -0
- package/templates/player-skin/js/README.md +11 -0
- package/templates/player-skin/js/_gitignore +6 -0
- package/templates/player-skin/js/assets/studio-preview.svg +15 -0
- package/templates/player-skin/js/ceru-plugin.code-workspace +8 -0
- package/templates/player-skin/js/ceru.plugin.json +77 -0
- package/templates/player-skin/js/package.json +24 -0
- package/templates/player-skin/js/src/Artwork.vue +9 -0
- package/templates/player-skin/js/src/Background.vue +15 -0
- package/templates/player-skin/js/src/BuiltinLyrics.vue +15 -0
- package/templates/player-skin/js/src/Lyrics.vue +28 -0
- package/templates/player-skin/js/tsconfig.json +17 -0
- package/templates/player-skin/ts/.vscode/extensions.json +3 -0
- package/templates/player-skin/ts/.vscode/launch.json +19 -0
- package/templates/player-skin/ts/.vscode/settings.json +20 -0
- package/templates/player-skin/ts/.vscode/tasks.json +43 -0
- package/templates/player-skin/ts/README.md +11 -0
- package/templates/player-skin/ts/_gitignore +6 -0
- package/templates/player-skin/ts/assets/studio-preview.svg +15 -0
- package/templates/player-skin/ts/ceru-plugin.code-workspace +8 -0
- package/templates/player-skin/ts/ceru.plugin.json +77 -0
- package/templates/player-skin/ts/package.json +24 -0
- package/templates/player-skin/ts/src/Artwork.vue +9 -0
- package/templates/player-skin/ts/src/Background.vue +15 -0
- package/templates/player-skin/ts/src/BuiltinLyrics.vue +15 -0
- package/templates/player-skin/ts/src/Lyrics.vue +28 -0
- package/templates/player-skin/ts/tsconfig.json +17 -0
- package/templates/react/js/.vscode/launch.json +12 -29
- package/templates/react/js/.vscode/tasks.json +2 -3
- package/templates/react/js/README.md +10 -10
- package/templates/react/js/ceru.plugin.json +27 -22
- package/templates/react/js/package.json +5 -5
- package/templates/react/js/src/index.js +1 -1
- package/templates/react/ts/.vscode/launch.json +12 -29
- package/templates/react/ts/.vscode/tasks.json +2 -3
- package/templates/react/ts/README.md +10 -10
- package/templates/react/ts/ceru.plugin.json +27 -22
- package/templates/react/ts/package.json +5 -5
- package/templates/react/ts/src/index.ts +1 -1
- package/templates/snapshot.json +152 -6
- package/templates/source/js/.vscode/launch.json +12 -29
- package/templates/source/js/.vscode/tasks.json +2 -3
- package/templates/source/js/README.md +12 -10
- package/templates/source/js/ceru.plugin.json +44 -26
- package/templates/source/js/package.json +5 -5
- package/templates/source/js/src/index.js +10 -8
- package/templates/source/ts/.vscode/launch.json +12 -29
- package/templates/source/ts/.vscode/tasks.json +2 -3
- package/templates/source/ts/README.md +12 -10
- package/templates/source/ts/ceru.plugin.json +44 -26
- package/templates/source/ts/package.json +5 -5
- package/templates/source/ts/src/index.ts +10 -8
- package/templates/vue/js/.vscode/launch.json +12 -29
- package/templates/vue/js/.vscode/tasks.json +2 -3
- package/templates/vue/js/README.md +10 -10
- package/templates/vue/js/ceru.plugin.json +27 -22
- package/templates/vue/js/package.json +5 -5
- package/templates/vue/js/src/index.js +1 -1
- package/templates/vue/ts/.vscode/launch.json +12 -29
- package/templates/vue/ts/.vscode/tasks.json +2 -3
- package/templates/vue/ts/README.md +10 -10
- package/templates/vue/ts/ceru.plugin.json +27 -22
- package/templates/vue/ts/package.json +5 -5
- package/templates/vue/ts/src/index.ts +1 -1
- package/templates/vue-tsx/js/.vscode/launch.json +12 -29
- package/templates/vue-tsx/js/.vscode/tasks.json +2 -3
- package/templates/vue-tsx/js/README.md +10 -10
- package/templates/vue-tsx/js/ceru.plugin.json +27 -22
- package/templates/vue-tsx/js/package.json +5 -5
- package/templates/vue-tsx/js/src/index.js +1 -1
- package/templates/vue-tsx/ts/.vscode/launch.json +12 -29
- package/templates/vue-tsx/ts/.vscode/tasks.json +2 -3
- package/templates/vue-tsx/ts/README.md +10 -10
- package/templates/vue-tsx/ts/ceru.plugin.json +27 -22
- package/templates/vue-tsx/ts/package.json +5 -5
- package/templates/vue-tsx/ts/src/index.ts +1 -1
- package/templates/web-dist/js/.vscode/launch.json +12 -29
- package/templates/web-dist/js/.vscode/tasks.json +2 -3
- package/templates/web-dist/js/README.md +10 -10
- package/templates/web-dist/js/ceru.plugin.json +27 -22
- package/templates/web-dist/js/package.json +5 -5
- package/templates/web-dist/js/src/index.js +1 -1
- package/templates/web-dist/ts/.vscode/launch.json +12 -29
- package/templates/web-dist/ts/.vscode/tasks.json +2 -3
- package/templates/web-dist/ts/README.md +10 -10
- package/templates/web-dist/ts/ceru.plugin.json +27 -22
- package/templates/web-dist/ts/package.json +5 -5
- package/templates/web-dist/ts/src/index.ts +1 -1
- package/templates/web-surface/js/.vscode/launch.json +12 -29
- package/templates/web-surface/js/.vscode/tasks.json +2 -3
- package/templates/web-surface/js/README.md +10 -10
- package/templates/web-surface/js/ceru.plugin.json +35 -35
- package/templates/web-surface/js/package.json +5 -5
- package/templates/web-surface/js/src/index.js +1 -1
- package/templates/web-surface/ts/.vscode/launch.json +12 -29
- package/templates/web-surface/ts/.vscode/tasks.json +2 -3
- package/templates/web-surface/ts/README.md +10 -10
- package/templates/web-surface/ts/ceru.plugin.json +35 -35
- package/templates/web-surface/ts/package.json +5 -5
- package/templates/web-surface/ts/src/index.ts +1 -1
- package/assets/core-contracts.js +0 -1
- package/assets/electron-app/main.cjs +0 -1
- package/assets/electron-app/package.json +0 -8
- package/assets/electron.cjs +0 -42
- package/assets/index.html +0 -94
- package/assets/native-view.js +0 -197
- package/assets/playground.js +0 -883
- package/assets/sandbox.js +0 -67
- package/assets/style.css +0 -337
- package/dist/socket-broker.d.ts +0 -23
- package/dist/socket-broker.js +0 -229
- package/templates/connected-library/js/ui/settings.json +0 -24
- package/templates/connected-library/ts/ui/settings.json +0 -24
- package/templates/guest-adapter/js/ui/settings.json +0 -14
- 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.js'
|
|
7
|
+
import {
|
|
8
|
+
AES_KEY,
|
|
9
|
+
AES_IV,
|
|
10
|
+
XOR_MASK,
|
|
11
|
+
createWav,
|
|
12
|
+
createFixtures,
|
|
13
|
+
createHandler,
|
|
14
|
+
} from '../src/fixtures.js'
|
|
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,16 @@
|
|
|
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
|
+
},
|
|
15
|
+
"include": ["src", ".ceru-dev/types/**/*.d.ts"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Host platform icon": {
|
|
3
|
+
"prefix": "ceru-icon",
|
|
4
|
+
"body": ["{ kind: 'host', name: 'platform.${1:tx}' }"],
|
|
5
|
+
"description": "使用宿主平台图标,无需打入插件",
|
|
6
|
+
},
|
|
7
|
+
"Host lodash": {
|
|
8
|
+
"prefix": "ceru-lodash",
|
|
9
|
+
"body": ["ctx.utils.lodash.${1:uniqBy}(${2:items}, ${3:key})"],
|
|
10
|
+
"description": "调用宿主的带类型 Lodash 工具",
|
|
11
|
+
},
|
|
12
|
+
"Host HTTP client": {
|
|
13
|
+
"prefix": "ceru-http",
|
|
14
|
+
"body": [
|
|
15
|
+
"const http = ctx.http.create({",
|
|
16
|
+
" baseURL: '${1:https://example.com}',",
|
|
17
|
+
" permissionKey: '${2:api}',",
|
|
18
|
+
" requestPermission: true,",
|
|
19
|
+
"})",
|
|
20
|
+
],
|
|
21
|
+
"description": "使用宿主 Axios 代理;无需将请求库打入插件",
|
|
22
|
+
},
|
|
23
|
+
"Permission group": {
|
|
24
|
+
"prefix": "ceru-permission-group",
|
|
25
|
+
"body": [
|
|
26
|
+
"const permission = await ctx.permissions.requestGroup({",
|
|
27
|
+
" group: '${1:libraryRead}',",
|
|
28
|
+
" intent: operation.userIntent,",
|
|
29
|
+
"})",
|
|
30
|
+
],
|
|
31
|
+
"description": "一次申请一组用户可理解的能力",
|
|
32
|
+
},
|
|
33
|
+
"Grouped music provider": {
|
|
34
|
+
"prefix": "ceru-provider",
|
|
35
|
+
"body": [
|
|
36
|
+
"ctx.providers.register('${1:catalog}', {",
|
|
37
|
+
" tracks: { search: ${2:searchTracks}, resolve: ${3:resolveTrack}, lyrics: ${4:getLyrics} },",
|
|
38
|
+
" playlists: { search: ${5:searchPlaylists}, categories: ${6:getCategories}, list: ${7:listPlaylists}, get: ${8:getPlaylist} },",
|
|
39
|
+
" charts: { list: ${9:listCharts}, getTracks: ${10:getChartTracks} },",
|
|
40
|
+
"})",
|
|
41
|
+
],
|
|
42
|
+
"description": "注册分组 Provider,返回标准歌曲/歌单/歌词 JSON",
|
|
43
|
+
},
|
|
44
|
+
"Source rate limit": {
|
|
45
|
+
"prefix": "ceru-rate-limit",
|
|
46
|
+
"body": [
|
|
47
|
+
"return ctx.playback.failure({",
|
|
48
|
+
" code: 'RATE_LIMITED',",
|
|
49
|
+
" message: '${1:请稍后重试}',",
|
|
50
|
+
" recovery: { mode: 'await-user', maxWaitMs: 60000 }",
|
|
51
|
+
"})",
|
|
52
|
+
],
|
|
53
|
+
"description": "返回结构化限流结果,由 Host 决定换源与交互",
|
|
54
|
+
},
|
|
55
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"configurations": [
|
|
4
|
+
{
|
|
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": ["dev"],
|
|
10
|
+
"cwd": "${workspaceFolder}",
|
|
11
|
+
"console": "integratedTerminal",
|
|
12
|
+
"skipFiles": ["<node_internals>/**"]
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
3
|
+
"typescript.enablePromptUseWorkspaceTsdk": true,
|
|
4
|
+
"editor.formatOnSave": true,
|
|
5
|
+
"[typescript]": {
|
|
6
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
7
|
+
},
|
|
8
|
+
"[javascript]": {
|
|
9
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
10
|
+
},
|
|
11
|
+
"json.schemas": [
|
|
12
|
+
{
|
|
13
|
+
"fileMatch": ["/ceru.plugin.json"],
|
|
14
|
+
"url": "./node_modules/@shiqianjiang/ceru-plugin-cli/schemas/config.schema.json"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"files.exclude": {
|
|
18
|
+
"**/*.tsbuildinfo": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"tasks": [
|
|
4
|
+
{
|
|
5
|
+
"label": "Ceru: dev",
|
|
6
|
+
"type": "process",
|
|
7
|
+
"isBackground": true,
|
|
8
|
+
"problemMatcher": {
|
|
9
|
+
"owner": "ceru",
|
|
10
|
+
"pattern": {
|
|
11
|
+
"regexp": "^CERU_ERROR (.*)$",
|
|
12
|
+
"message": 1
|
|
13
|
+
},
|
|
14
|
+
"background": {
|
|
15
|
+
"activeOnStart": true,
|
|
16
|
+
"beginsPattern": "^.*$",
|
|
17
|
+
"endsPattern": "^CERU_BUILD_READY "
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"command": "node",
|
|
21
|
+
"args": ["${workspaceFolder}/node_modules/@shiqianjiang/ceru-plugin-cli/dist/bin.js", "dev"],
|
|
22
|
+
"options": {
|
|
23
|
+
"cwd": "${workspaceFolder}"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"label": "Ceru: typecheck",
|
|
28
|
+
"type": "npm",
|
|
29
|
+
"script": "typecheck",
|
|
30
|
+
"problemMatcher": "$tsc",
|
|
31
|
+
"group": "build"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"label": "Ceru: build",
|
|
35
|
+
"type": "npm",
|
|
36
|
+
"script": "build",
|
|
37
|
+
"problemMatcher": []
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# encrypted-source
|
|
2
|
+
|
|
3
|
+
This project contains three self-contained v3 music providers. Each generates the same quiet three-second 440 Hz PCM WAV, implements search / resolve / lyrics, and needs no external URL, account, paid API, or media download.
|
|
4
|
+
|
|
5
|
+
| Provider ID | Resolve result | Where bytes become audio | Permission |
|
|
6
|
+
| ----------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------- | --------------------------------------- |
|
|
7
|
+
| `builtin-decrypt` | Encrypted URL plus `stream.decrypt` with AES-128-CTR key/IV | Host's built-in media decryption | `network.serve` for the fixture server |
|
|
8
|
+
| `wasm-transform` | XOR-encoded URL plus `stream.transform: 'xor-byte'` | Registered transform in the plugin worker, calling embedded WASM | `network.serve` and `streams.transform` |
|
|
9
|
+
| `own-service` | Plain HTTP audio URL, without `stream` | Plugin decrypts its fixture through `ctx.crypto.createDecipher`, then serves WAV | `network.serve` |
|
|
10
|
+
|
|
11
|
+
The WASM export is only `decode(byte, mask) = byte XOR mask`. XOR is reversible obfuscation, **not secure encryption**, DRM, a codec, or a commercial music-service implementation. The AES key and IV are intentionally public, fixed demo values. Do not reuse them for real content.
|
|
12
|
+
|
|
13
|
+
`src/fixtures.*` generates WAV bytes, encrypts them with `ctx.crypto.createCipher`, and roundtrips through `createDecipher`; both crypto methods return Web `TransformStream`s. The tiny plaintext fixture is cached for random-access serving. `src/demo.*` registers providers, manages permissions/listener lifetime, and registers one WASM instance per stream. `resources/xor-byte.wat` is the readable source for the checked-in 44-byte `xor-byte.wasm`.
|
|
14
|
+
|
|
15
|
+
## Current integration contract
|
|
16
|
+
|
|
17
|
+
This template targets the in-progress v3 SDK/Host contract. It has not been synced into the CLI template catalogue. The parent task owns listing, snapshot sync, toolchain integration and desktop validation. Do not use published npm `latest` as a substitute for that matching toolchain.
|
|
18
|
+
|
|
19
|
+
- `ctx.server.serve(handler, options?)` accepts Web `Request` and returns a Web `Response` from the handler. It resolves to `{ url, port, close() }`. The template passes only `{ permissionKey: 'demo-server' }`, leaving the port random and binding to loopback by default. It never requests LAN serving.
|
|
20
|
+
- `ctx.permissions.query` and `requestGroup` use the declaration keys `demo-server` / `demo-transform`, groups `localServer` / `audioTransform`, and forward the operation's user intent. No prompt or socket is opened during activation, search, or lyrics. Starting or resolving audio may request a missing grant. Denial returns `PERMISSION_DENIED` with a recovery command.
|
|
21
|
+
- The Host requests/enforces `streams.transform` for a custom stream transform. Built-in `stream.decrypt` does **not** need that grant. The template explicitly requests it on WASM resolve so denial is explained before playback.
|
|
22
|
+
- `ctx.streams.registerTransform('xor-byte', { seekable, create })` accepts per-request `{ offset, signal }`; `transform(chunk)` returns a fresh `Uint8Array` created in the plugin worker. Bytewise XOR is independent of offset and preserves length, so this particular transform is seekable.
|
|
23
|
+
- `ctx.wasm.instantiate('xor-byte')` looks up an embedded resource and returns `{ module, instance }`. The config declares a binary `.wasm` file as `type: 'base64', mime: 'application/wasm'`; the CLI performs the base64 embedding. Do not put a base64 text file at that binary path.
|
|
24
|
+
- Resolve metadata's `contentLength: 96044` is the **plaintext** WAV byte count. The fixture happens to have equal plaintext/ciphertext lengths. The Host's owned-loopback-server exception allows these URLs through media preparation. Remote hosts still undergo the normal DNS/network checks.
|
|
25
|
+
- `ctx.effects.add` releases the registered transform and closes the owned listener, including when unload races a pending start. The Host also owns ultimate runtime cleanup. Cached URLs expire when the plugin stops; resolve again after a reload.
|
|
26
|
+
|
|
27
|
+
## Exact offline verification, before SDK sync
|
|
28
|
+
|
|
29
|
+
From this project directory, with Node **22.18 or newer**:
|
|
30
|
+
|
|
31
|
+
```powershell
|
|
32
|
+
node --test tests/demo.test.mjs
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This runs eight checks for this variant. No npm installation, CLI build, template sync, network credentials, or desktop launch is needed. Tests use Node's native TypeScript support for the TS variant.
|
|
36
|
+
|
|
37
|
+
The harness uses real Node crypto, Web streams, the checked-in WASM binary, and an ephemeral loopback HTTP listener behind small SDK adapters. It verifies WAV headers and exact byte equality, all 256 XOR inputs, split/offset transforms, cancellation, HTTP ranges/HEAD, search/lyrics without prompts, provider/ref isolation, denied grants, shared startup, retry, and unload races. It verifies plugin behavior, **not** the real SDK bridge, worker realm transfer, Host DNS exception, or audible playback.
|
|
38
|
+
|
|
39
|
+
## Desktop demo, after the parent integrates the matching toolchain
|
|
40
|
+
|
|
41
|
+
Use this project as copied by the CLI or manually from `templates/encrypted-source/ts`. If copied manually, rename `_gitignore` to `.gitignore`. Install the matching local v3 SDK and CLI development packages using the parent task's local-package instructions; `package.json` keeps the same `^3.0.0` dependency convention as the other templates. Once those packages are available in this copied project:
|
|
42
|
+
|
|
43
|
+
```powershell
|
|
44
|
+
npm run typecheck
|
|
45
|
+
npm run dev
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
In the v3 desktop app, enable **设置 → 插件管理 → 管理设置 → 插件开发者模式**, then add the JS file printed by `dev`. Open this project's `ceru-plugin.code-workspace` for VS Code F5 support. No second Electron app is launched.
|
|
49
|
+
|
|
50
|
+
1. Search **Encrypted Demo** in each of **Encrypted Demo / AES-CTR**, **Encrypted Demo / WASM XOR**, and **Encrypted Demo / Own Service**. Each source returns one three-second track. Opening lyrics shows the provider name and two explanatory lines; the tone contains no voice.
|
|
51
|
+
2. Select **启动本地音频 Demo** from the plugin commands, or play a track directly. Allow the local-server permission. The notification/log prints the actual random `http://127.0.0.1:<port>` origin. No fixed port is expected.
|
|
52
|
+
3. Play AES-CTR and Own Service. Both should play the same quiet tone without asking for audio-transform permission. Play WASM XOR and allow that additional grant; its audio should match.
|
|
53
|
+
4. Seek within each track and repeat playback. To see HTTP headers, paste the printed origin into the commands below. `plain.wav` returns `audio/wav`; the encrypted routes return `application/octet-stream` and are only playable through their provider's resolve processing.
|
|
54
|
+
|
|
55
|
+
```powershell
|
|
56
|
+
$DemoOrigin = 'http://127.0.0.1:REPLACE_WITH_PRINTED_PORT'
|
|
57
|
+
curl.exe -i "$DemoOrigin/health"
|
|
58
|
+
curl.exe -I "$DemoOrigin/plain.wav"
|
|
59
|
+
curl.exe -s -D - -H 'Range: bytes=44-75' "$DemoOrigin/plain.wav" -o NUL
|
|
60
|
+
curl.exe -s -D - -H 'Range: bytes=32-63' "$DemoOrigin/aes.wav.enc" -o NUL
|
|
61
|
+
curl.exe -s -D - -H 'Range: bytes=32-63' "$DemoOrigin/xor.wav.enc" -o NUL
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Expected: health is `200` with `encrypted-source ready`; HEAD has length `96044`; the three range requests return `206`, length `32`, and the requested `Content-Range`. The handler also supports open-ended and suffix ranges, rejects invalid/multipart ranges with `416`, and accepts only GET/HEAD.
|
|
65
|
+
|
|
66
|
+
5. Revoke/deny audio-transform permission in the Host. WASM playback must fail with the permission status and recovery action; AES-CTR and Own Service must still work. Deny local-server permission and all three must fail informatively; search/lyrics must remain available. Regrant and retry. Depending on Host grant persistence, clear grants/reload to exercise the initial prompt again.
|
|
67
|
+
6. Disable/unload the plugin. The printed URL must stop responding; re-enable and resolve again to obtain the new origin. Test quick reload during startup as well.
|
|
68
|
+
|
|
69
|
+
Record actual desktop results separately from the offline tests. The template authoring task deliberately does not run SDK sync, build, publish or commit. Once integration is ready, normal release verification is `npm run build`, `npm run validate`, and `npm run preview`; distribute `dist/plugin.js` only.
|
|
70
|
+
|
|
71
|
+
## Adapting an actual integration
|
|
72
|
+
|
|
73
|
+
- **Built-in decrypt:** replace the generated fixture URL/key/IV with values from your authorized media API. Return `stream.decrypt` with a supported algorithm and actual key/IV encoding; include the decoded content type and exact decoded length when known. Get fresh URLs on resolve if signed links expire. Authenticate API calls through the Host network/credential APIs and declare the actual domains/scopes. Never log or commit production keys.
|
|
74
|
+
- **WASM transform:** replace the tiny module and decoder with your own legitimate format handler. Keep mutable decode state per `create` call, handle cancellation and bounded chunks, and return worker-owned typed arrays. Set `seekable: false` until you can map nonzero byte offsets correctly; XOR's simple offset behavior does not generalize to block encryption, compression, or containers. Native built-in decryption is preferable for supported algorithms.
|
|
75
|
+
- **Own service:** replace `createFixtures`/`createHandler` with your upstream-fetch/decrypt/serve pipeline. This demo buffers only 96 KB; real tracks should stream with backpressure/cancellation, correct content headers and byte-range semantics. One plugin owns one listener, so add routes to that server instead of opening one listener per track. Keep loopback binding unless LAN access is explicitly intended and separately declared/granted.
|
|
76
|
+
- Keep search metadata and `ResourceRef`s stable, map unknown tracks and upstream errors to structured playback faults, and implement real lyrics. The sample text is intentionally labeled as a demonstration.
|
|
77
|
+
- The local fixture server itself does not fetch the network and needs no `network.request` / `network.private` grant. Adding remote API/CDN access requires those declarations and normal Host URL/DNS authorization as applicable. The owned-loopback exception is not a general bypass for arbitrary private-network URLs.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# encrypted-source / ts
|
|
2
|
+
|
|
3
|
+
Standalone TypeScript variant of the v3 encrypted-source demo. Three providers implement search, resolve and lyrics: built-in AES-CTR decryption, a worker WASM XOR transform, and ordinary audio from a plugin-owned HTTP server. The generated three-second WAV needs no external media, account or paid API.
|
|
4
|
+
|
|
5
|
+
Read [DEMO.md](DEMO.md) for the exact API assumptions, permission behavior, offline and desktop verification, and adaptation to real integrations. A copy is included inside this project so CLI scaffolding retains all instructions.
|
|
6
|
+
|
|
7
|
+
```powershell
|
|
8
|
+
node --test tests/demo.test.mjs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node 22.18+. This runs without installing the SDK and does not build anything. After the parent task integrates the matching local v3 SDK/CLI/Host, use `npm run typecheck` and `npm run dev`, then add the printed JS path to the desktop developer mode. Do not validate this in-progress contract against npm `latest`.
|
|
12
|
+
|
|
13
|
+
Open `ceru-plugin.code-workspace` for the standard VS Code tasks. `ceru.plugin.json` embeds `resources/xor-byte.wasm` as base64 and declares `network.serve` plus optional `streams.transform`. No configuration or credentials are necessary.
|