Files
Qiming Zhai fe19854bd7 feishu-sidebar 0.1.0: a page that opens Magpie Web in Feishu's sidebar (#1212)
A page plugin that turns a Magpie Web address into Feishu's
client/web_url/open AppLink (mode=appCenter), so Magpie Web opens in
Feishu desktop's left sidebar. No permissions, no request: the page only
builds the link. Addresses with credentials, a query or a fragment are
refused (keeps ?k= keys out of a shared link), and plain HTTP only on
loopback. By zhaiqiming.

Run at the reviewed head f3164eb2 (mica, temp HOME):
- bun test packages/feishu-sidebar: 3 pass, 0 fail.
- bun scripts/check.mjs feishu-sidebar: ok. bun test scripts: 39 pass.
- The page itself, with a stub bridge, in Playwright Chromium and
  WebKit at 400px, en and zh-CN: the title is translated, Enter on a
  loopback address shows the link, a ?k= address shows the error and
  hides the link, nothing scrolls sideways.

Not tried: Feishu desktop itself (the author verified it on macOS).
The package's first npm version waits for the owner; dist serves it.
2026-11-16 16:39:37 +08:00

36 lines
1.5 KiB
JavaScript

import { expect, test } from "bun:test"
import { readFileSync } from "node:fs"
const source = readFileSync(new URL("./page/applink.js", import.meta.url), "utf8")
const buildLink = new Function(source + "\nreturn buildFeishuLink")()
test("opens a Magpie Web URL with a path as an appCenter AppLink", () => {
const { link } = buildLink(" https://magpie.example.test/panels/magpie%20web/ ")
const url = new URL(link)
expect(url.origin + url.pathname).toBe("https://applink.feishu.cn/client/web_url/open")
expect(Object.fromEntries(url.searchParams)).toEqual({
mode: "appCenter",
url: "https://magpie.example.test/panels/magpie%20web/",
})
})
test("allows Magpie Web on the desktop computer over loopback HTTP", () => {
for (const host of ["127.0.0.1", "localhost", "[::1]"]) {
const address = `http://${host}:3430`
expect(new URL(buildLink(address).link).searchParams.get("url")).toBe(address + "/")
}
})
test("does not generate a shareable link from a sign-in URL or an unencrypted remote console", () => {
for (const address of [
"https://magpie.example.test/?k=example-access-key",
"https://user:secret@magpie.example.test/",
"https://magpie.example.test/#token",
]) expect(buildLink(address)).toEqual({ error: "plainAddress" })
expect(buildLink("http://magpie.example.test:3430")).toEqual({ error: "https" })
for (const address of ["javascript:alert(1)", "https:///example.test", "magpie.example.test", ""]) {
expect(buildLink(address)).toEqual({ error: "invalid" })
}
})