@livespace/plugin-studio 0.0.0-stage → 0.2.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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -2
  3. package/dist/auth.js +220 -0
  4. package/dist/cli.js +67 -0
  5. package/dist/keys.js +42 -0
  6. package/dist/manifest.js +16 -0
  7. package/dist/page/domain/address.js +79 -0
  8. package/dist/page/domain/connection.js +2 -0
  9. package/dist/page/domain/display.js +38 -0
  10. package/dist/page/domain/draft.js +80 -0
  11. package/dist/page/domain/failures-store.js +41 -0
  12. package/dist/page/domain/failures.js +75 -0
  13. package/dist/page/domain/layout-store.js +119 -0
  14. package/dist/page/domain/log-store.js +37 -0
  15. package/dist/page/domain/navigation-store.js +17 -0
  16. package/dist/page/domain/plugin-data.js +70 -0
  17. package/dist/page/domain/plugin-store.js +257 -0
  18. package/dist/page/domain/probe-store.js +100 -0
  19. package/dist/page/domain/profile-session.js +115 -0
  20. package/dist/page/domain/profile-store.js +51 -0
  21. package/dist/page/domain/samples.js +221 -0
  22. package/dist/page/domain/secrets-store.js +159 -0
  23. package/dist/page/domain/secrets.js +135 -0
  24. package/dist/page/domain/settings-data.js +64 -0
  25. package/dist/page/domain/settings-session.js +206 -0
  26. package/dist/page/domain/settings-store.js +62 -0
  27. package/dist/page/domain/slot-store.js +50 -0
  28. package/dist/page/domain/studio.js +162 -0
  29. package/dist/page/domain/surface-store.js +71 -0
  30. package/dist/page/domain/toasts-store.js +60 -0
  31. package/dist/page/domain/view-data.js +122 -0
  32. package/dist/page/domain/view-store.js +132 -0
  33. package/dist/page/host.css +907 -0
  34. package/dist/page/index.html +31 -0
  35. package/dist/page/main.js +43 -0
  36. package/dist/page/plugin-studio-logo.svg +4 -0
  37. package/dist/page/reload.svg +1 -0
  38. package/dist/page/transport/browser-storage.js +41 -0
  39. package/dist/page/transport/console-mirror.js +48 -0
  40. package/dist/page/transport/embed.js +142 -0
  41. package/dist/page/transport/plugin-keys.js +68 -0
  42. package/dist/page/transport/studio-api.js +74 -0
  43. package/dist/page/ui/app.js +61 -0
  44. package/dist/page/ui/boot.js +44 -0
  45. package/dist/page/ui/brand.js +3 -0
  46. package/dist/page/ui/context.js +11 -0
  47. package/dist/page/ui/json-field.js +19 -0
  48. package/dist/page/ui/json-tokens.js +40 -0
  49. package/dist/page/ui/json-view.js +11 -0
  50. package/dist/page/ui/memo.js +23 -0
  51. package/dist/page/ui/messages.js +34 -0
  52. package/dist/page/ui/page-switcher.js +11 -0
  53. package/dist/page/ui/plugin-frame.js +43 -0
  54. package/dist/page/ui/profile-page.js +13 -0
  55. package/dist/page/ui/resize-handle.js +63 -0
  56. package/dist/page/ui/root.js +9 -0
  57. package/dist/page/ui/section.js +19 -0
  58. package/dist/page/ui/settings/config-form.js +59 -0
  59. package/dist/page/ui/settings/secret-field.js +22 -0
  60. package/dist/page/ui/settings/settings-page.js +60 -0
  61. package/dist/page/ui/sidebar/custom-settings-section.js +10 -0
  62. package/dist/page/ui/sidebar/failures-section.js +27 -0
  63. package/dist/page/ui/sidebar/installation-section.js +30 -0
  64. package/dist/page/ui/sidebar/metadata-section.js +9 -0
  65. package/dist/page/ui/sidebar/plugin-section.js +18 -0
  66. package/dist/page/ui/sidebar/preferences-section.js +16 -0
  67. package/dist/page/ui/sidebar/record-section.js +17 -0
  68. package/dist/page/ui/sidebar/viewer-section.js +8 -0
  69. package/dist/page/ui/sidebar-group.js +4 -0
  70. package/dist/page/ui/splash.js +6 -0
  71. package/dist/page/ui/status.js +10 -0
  72. package/dist/page/ui/surface.js +23 -0
  73. package/dist/page/ui/theme.js +13 -0
  74. package/dist/page/ui/toasts.js +31 -0
  75. package/dist/page/ui/top-bar.js +37 -0
  76. package/dist/server.js +519 -0
  77. package/dist/start.js +108 -0
  78. package/package.json +55 -5
package/dist/start.js ADDED
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Starting the studio, a local stand-in for Livespace that embeds the plugin's page
3
+ * (docs/adr/0007-studio-is-its-own-package.md). It embeds a page the author's own dev server
4
+ * serves, and never starts one.
5
+ */
6
+ import { access } from "node:fs/promises";
7
+ import { join } from "node:path";
8
+ import { clientIdOf } from "./keys.js";
9
+ import { readManifestText } from "./manifest.js";
10
+ import { PortInUse } from "./server.js";
11
+ export const STUDIO_PORT = 5190;
12
+ export const DEFAULT_CLIENT_ID = "plugin:dev";
13
+ /** A flag the studio can't use. The bin prints the message, without a stack. */
14
+ export class UsageError extends Error {
15
+ }
16
+ /** Where each template's dev server listens, told apart by a file only it has. */
17
+ const TEMPLATE_URLS = [
18
+ ["vite.config.ts", "http://localhost:5173"],
19
+ ["dev.ts", "http://localhost:3000"],
20
+ ];
21
+ const exists = (path) => access(path).then(() => true, () => false);
22
+ export const untilSignal = () => new Promise((resolve) => {
23
+ process.once("SIGINT", () => resolve());
24
+ process.once("SIGTERM", () => resolve());
25
+ });
26
+ /** `--url`, else the template's dev server, else `null`: the page asks for an address. */
27
+ async function pluginUrlFor(options) {
28
+ const given = options.url;
29
+ if (given !== undefined) {
30
+ let url;
31
+ try {
32
+ url = new URL(given);
33
+ }
34
+ catch {
35
+ throw new UsageError(`--url isn't a URL: ${given}`);
36
+ }
37
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
38
+ throw new UsageError(`--url must be http or https: ${given}`);
39
+ }
40
+ return url.href;
41
+ }
42
+ for (const [file, url] of TEMPLATE_URLS) {
43
+ if (await exists(join(options.dir, file))) {
44
+ return url;
45
+ }
46
+ }
47
+ return null;
48
+ }
49
+ function portFor(options) {
50
+ if (options.port === undefined) {
51
+ return STUDIO_PORT;
52
+ }
53
+ const port = Number(options.port);
54
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
55
+ throw new UsageError(`--port is a port number, 1–65535: ${options.port}`);
56
+ }
57
+ return port;
58
+ }
59
+ /** `--client-id`, else the manifest's `plugin:<id>`, else a stand-in. */
60
+ async function clientIdFor(options) {
61
+ if (options.clientId !== undefined) {
62
+ return options.clientId;
63
+ }
64
+ const text = await readManifestText(options.dir);
65
+ if (text !== undefined) {
66
+ try {
67
+ const { id } = JSON.parse(text);
68
+ if (typeof id === "string" && id !== "") {
69
+ return clientIdOf(id);
70
+ }
71
+ }
72
+ catch { }
73
+ }
74
+ return DEFAULT_CLIENT_ID;
75
+ }
76
+ export async function start(options, deps) {
77
+ const pluginUrl = await pluginUrlFor(options);
78
+ const port = portFor(options);
79
+ const clientId = await clientIdFor(options);
80
+ let studio;
81
+ try {
82
+ studio = await deps.start({ port, pluginUrl, clientId, dir: options.dir });
83
+ }
84
+ catch (error) {
85
+ if (error instanceof PortInUse) {
86
+ throw new UsageError(`Port ${port} is in use. Pick another with --port, or stop what's using it.`);
87
+ }
88
+ throw error;
89
+ }
90
+ const { print } = deps;
91
+ print(`Plugin Studio: open ${studio.url}`);
92
+ print(pluginUrl === null
93
+ ? "Enter your plugin's address at the top of the page: any http or https page, a deployed one included."
94
+ : `It embeds ${pluginUrl}; change the address at the top of the page. Start your dev server first, if it isn't running.`);
95
+ const env = {
96
+ LIVESPACE_KEYS_URL: studio.keysUrl,
97
+ LIVESPACE_AUTH_URL: studio.authUrl,
98
+ PLUGIN_CLIENT_ID: clientId,
99
+ };
100
+ print("For your backend's env, to trust the dev account's tokens and reach its secrets (the page shows them too, as the client id changes):");
101
+ for (const [name, value] of Object.entries(env)) {
102
+ print(` ${name}=${value}`);
103
+ }
104
+ print("Ctrl-C to stop.");
105
+ await deps.untilStopped();
106
+ await studio.close();
107
+ print("Stopped.");
108
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
- "name": "@livespace/plugin-studio",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@livespace/plugin-studio",
3
+ "version": "0.2.0",
4
+ "description": "Plugin Studio: try and debug a Livespace plugin locally, embedded as Livespace embeds it.",
5
+ "author": "LS FE team",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "bin": {
9
+ "livespace-plugin-studio": "dist/cli.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "engines": {
15
+ "node": ">=20.12"
16
+ },
17
+ "keywords": [
18
+ "livespace",
19
+ "plugin",
20
+ "dev server",
21
+ "studio"
22
+ ],
23
+ "homepage": "https://www.npmjs.com/package/@livespace/plugin-studio",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://gitlab.com/livespace-it/plugin-platform/sdk-client.git",
27
+ "directory": "packages/studio"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.page.json && cp page/static/* dist/page/",
34
+ "lint:types": "tsc --noEmit && tsc -p tsconfig.page.json --noEmit && tsc -p page/tsconfig.json",
35
+ "prepublishOnly": "yarn test",
36
+ "test": "yarn build && vitest run --watch false",
37
+ "test:watch": "vitest",
38
+ "test:e2e": "yarn build && yarn workspace @livespace/plugin-sdk build && playwright test"
39
+ },
40
+ "dependencies": {
41
+ "@awesome.me/webawesome": "3.14.0",
42
+ "@preact/signals": "2.11.3",
43
+ "preact": "11.0.2"
44
+ },
45
+ "peerDependencies": {
46
+ "@livespace/plugin-sdk": "^1"
47
+ },
48
+ "devDependencies": {
49
+ "@livespace/plugin-sdk": "workspace:^",
50
+ "@playwright/test": "1.64.1",
51
+ "@types/node": "22.15.21",
52
+ "jose": "6.2.13",
53
+ "typescript": "5.2.2",
54
+ "vitest": "3.2.4"
55
+ }
56
+ }