plugin-typings icon indicating copy to clipboard operation
plugin-typings copied to clipboard

Getting the docuemnt's id (something unique)

Open softmarshmallow opened this issue 6 years ago • 12 comments

The document node's id always returns 0:0 and figma.fileKey returns undefined.

I cannot identify the current file running the plugin.

https://www.figma.com/plugin-docs/api/DocumentNode/

read it on reddit

softmarshmallow avatar Nov 10 '20 03:11 softmarshmallow

That's not a bug. fileKey is available only in private plug-ins and you need to enable enablePrivatePluginApi in manifest.json

Also check out Slack channels for plug-in developers: https://join.slack.com/t/figmaplugins/shared_invite/enQtNjg5NzQ4NTQ4OTAyLWJjOWQyZGRjNmYyZTRmYjk3ZTgzNjJhZTYzZmU5NmJkYzA4MzdjMDFlNzVlM2QwZjhlMGMwMTA5ZWI0N2UxZTA

cyberalien avatar Nov 10 '20 07:11 cyberalien

How about figma.root.id ?

softmarshmallow avatar Nov 10 '20 09:11 softmarshmallow

It is always 0:0. It is not meant to identify document, it is only to reference node within current document.

If you want to identify documents for some reason in your plug-in, best approach is to set plug-in data on root node using setPluginData. Then when next time plug-in is ran, that data is available. You can store document specific data that way. If you want multiple plug-ins to access it, use setSharedPluginData.

cyberalien avatar Nov 10 '20 09:11 cyberalien

I want to implement a feature that makes sharable link to specific node.

which is figma.com/file/<doc-id>/?node-id=<node-id>

i need the value of <doc-id>

softmarshmallow avatar Nov 10 '20 10:11 softmarshmallow

There is no way to get it in plug-in.

cyberalien avatar Nov 10 '20 10:11 cyberalien

Well i think you guys should provide one. Please bring it on the table. closing for now

softmarshmallow avatar Nov 10 '20 10:11 softmarshmallow

@cyberalien Can we get an update / eta for this feature? I think you can generally agree providing the file id via plugin api is essential.

Use case scenario.

  1. Select some node from file
  2. If no id provided from plugin, we have to issue new id and manage it customly on app's BE.
  3. What happens user moves the node between files? How will we ever access the same node via REST API?

This is very basic feature, must be provided soon.

https://www.figma.com/plugin-docs/api/figma/#filekey - only available for private plugins. WHY?

softmarshmallow avatar Jul 16 '21 06:07 softmarshmallow

@cyberalien Can we get an update / eta for this feature?

I'm a plugin developer, not part of Figma team.

cyberalien avatar Jul 16 '21 06:07 cyberalien

@cyberalien Can we get an update / eta for this feature?

I'm a plugin developer, not part of Figma team.

Ah. my bad. sorry :)

softmarshmallow avatar Jul 16 '21 06:07 softmarshmallow

@delfu

softmarshmallow avatar Jul 16 '21 06:07 softmarshmallow

@softmarshmallow thank you for trying to develop the best user plugin experience possible :) Unfortunately there's no plan to provide that capability for non-private plugins because it a plugin security concern. There's been a more detailed discussion on the plugin slack group.

The summary is exposing file-key can lead to unauthorized access to file content even when a plugin has been uninstalled (eg: plugin gets installed, sends file-key to a server, plugin get uninstalled, the server can still access content through the HTTP API)

Hope this helps explain the decision

delfu avatar Jul 16 '21 17:07 delfu

@delfu I think the suggestion is not necessarily to provide the file key (which would be nice) but to provide any kind of unique identifier for the document. Currently the only option is to send the request to the server which would generate a unique id and store it in node storage, but that won't help if the user resets the document to the previous version before the plugin ran. On the next plugin launch this will be considered a separate doc by the plugin. Currently this is a problem for my plugins as well, for example Master plugin which stores trial usages per file. Technically you can use it infinitely because you can always undo the last action which is stored in the document node plugin storage.

glebsexy avatar Jul 16 '21 23:07 glebsexy