@todoforai/figma-api 1.0.1 → 1.0.2

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/bridge.ts +17 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/figma-api",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Figma CLI — full REST API wrapper (files, comments, variables, webhooks…) plus a plugin bridge for canvas writes.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/bridge.ts CHANGED
@@ -78,17 +78,32 @@ export function startBridge(port: number): void {
78
78
  console.log("Point the plugin at this URL (or a cloudflared tunnel of it), then run draw-* commands.");
79
79
  }
80
80
 
81
+ /** Setup instructions shown only when a canvas-write command can't reach the plugin. */
82
+ const SETUP = `
83
+ To run canvas commands (create frames/text/shapes, edit variables off-Enterprise),
84
+ the plugin bridge must be set up — the Figma REST API can't do these:
85
+ 1. Start the relay (keep running): figma-api bridge
86
+ 2. In the Figma DESKTOP app: Plugins → Development → Import plugin from manifest
87
+ → the plugin/manifest.json shipped with this package. Run it, paste the relay
88
+ URL (default http://localhost:8917), click Connect.
89
+ 3. Retry. Verify the round-trip with: figma-api ping
90
+ Cross-machine: expose the relay via 'cloudflared tunnel --url http://localhost:8917'
91
+ and paste that https URL into the plugin. Browser-only Figma can't load dev plugins.`;
92
+
81
93
  /** CLI helper: push a command to a running bridge and return the plugin's result. */
82
94
  export async function sendCommand(relay: string, op: string, params: Record<string, unknown>): Promise<void> {
83
95
  const res = await fetch(`${relay.replace(/\/$/, "")}/cmd`, {
84
96
  method: "POST",
85
97
  headers: { "content-type": "application/json" },
86
98
  body: JSON.stringify({ op, ...params }),
87
- }).catch((e) => { console.error(`Bridge not reachable at ${relay}: ${e.message}\nStart it with: figma-api bridge`); process.exit(1); });
99
+ }).catch((e) => {
100
+ console.error(`Bridge relay not reachable at ${relay} (${e.message}).${SETUP}`);
101
+ process.exit(1);
102
+ });
88
103
  const data = (await (res as Response).json()) as { result?: { timeout?: boolean; error?: string } };
89
104
  const result = data.result;
90
105
  if (result?.timeout) {
91
- console.error("Timed out waiting for the plugin. Is it open and Connected to the relay?");
106
+ console.error(`Timed out waiting for the plugin the relay is up but no plugin is Connected.${SETUP}`);
92
107
  process.exit(1);
93
108
  }
94
109
  console.log(JSON.stringify(result ?? data, null, 2));