Git Product home page Git Product logo

figma-js's Introduction

Figma.js

A simple wrapper for the Figma API.

Cool projects using this:

Usage

Full documentation is available on the web and most everything is typed with TypeScript.

Creating a client

Quickest start is to grab a personal access token from your Figma account settings page

import * as Figma from 'figma-js';

const token = '12345';

const client = Figma.Client({
  personalAccessToken: token
});

Or if you're building an app with OAuth authentication, after you get back the OAuth access token…

import * as Figma from 'figma-js';

const token = '12345';

const client = Figma.Client({
  accessToken: token
});

Doing cool things

Once you have instantiated a client, have fun!

client.file('file-id').then(({ data }) => {
  console.log(data);
});

Just reusing types

All of the types in the Figma file format / API are exported.

import * as Figma from 'figma-js';

const textNode: Figma.Text = {
  // … this should autocomplete if your editor is set up for it!
};

Contributing

We used the typescript-starter repo for this - refer to its README for more detailed instructions.

Helpful development commands:

yarn watch
yarn docs
yarn docs:publish

Contributions welcomed

Committing

yarn global add commitizen

# instead of git commit

git cz

Contributors

figma-js's People

Contributors

anselmdk avatar bruno12mota avatar chrisdrackett avatar davidpett avatar dependabot[bot] avatar dmiller9911 avatar drakosvlad avatar dvdsgl avatar ergofriend avatar erictaylor avatar g-a-v-i-n avatar gaurav-bhardwaj-ind avatar gorango avatar jacoblapworth avatar jamiemill avatar jeetiss avatar jemgold avatar jhardy avatar jonrimmer avatar kerumen avatar liammartens avatar mathieudutour avatar mikkmartin avatar piperchester avatar saveyourtime avatar tujoworker avatar xtiandiaz avatar yonezo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

figma-js's Issues

File Nodes type not fully implemented

  • I'm submitting a ...
    [*] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Currently the types are, (notice only 3 props)

export interface FileNodesParams {
    /** A list of node IDs to retrieve and convert */
    readonly ids: ReadonlyArray<string>;
    /**
     * A specific version ID to get. Omitting this will get the current version of the file
     */
    readonly version?: string;
    /**
     * Set to "paths" to export vector data
     */
    readonly geometry?: string;
}

It seems that it's not the only place.

While official Figma docs state

image

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Maybe it could be fixed by renewing the types

Duplicate types for Vector

I can't believe my eyes and tslint missed this one.

We export 2 things called Vector
https://figma.com/developers/docs#vector-props
https://figma.com/developers/docs#vector-type

This is breaking the postComment call, which uses client_meta: Vector (the type, not the node).

I think perhaps a smart renaming strategy is in order - perhaps renaming all of the node types to VectorNode, LineNode etc etc? Maybe?

This is a high priority bug inasmuch as I'm having to cast to any to post comments rn :D

Support for Variables

  • I'm submitting a ...
    [ ] bug report
    [X] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    It would be nice to add support for the Variable beta endpoints: https://www.figma.com/developers/api#variables

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Any updates?

Are you still here?
Doesn't your type know about new Figma Api scheme?

image

image

Update axios to allow users to upgrade past CVE-2020-28168

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

The following CVE is patched in 0.21.1 of axios:

GHSA-4w2v-q235-vp99

package.json uses a caret range to define figma-js' dependency on axios:

https://github.com/jongold/figma-js/blob/3fbe4f390f7d67a2d4c6742cd46bed871fde23cb/package.json#L56-L58

The caret allows any updates as long as they do not modify the left-most non-zero digit:

https://docs.npmjs.com/cli/v6/using-npm/semver#caret-ranges-123-025-004

For users that eg depend on figma-js in a monorepo, this prevents an update to a version of axios that is not vulnerable to CVE-2020-28168.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Hopefully, relaxing the dependency range (perhaps with >=) would be safe for this project. A quick skim of recent axios release notes suggests that there are no breaking/material changes between 0.19 and 0.21.

https://github.com/axios/axios/releases

Call for maintainers

Hi y'all - I totally missed a ton of issues & PRs, I didn't think ppl were using this!

Would love to add some more people as maintainers - lmk if you're interested <3

Add absoluteRenderBounds

There is absoluteRenderBounds in the Figma answer API for elements extends FrameBase and VectorBase

{
  "id": "52:309",
  "name": "listText",
  "type": "TEXT",
  "scrollBehavior": "SCROLLS",
  "blendMode": "PASS_THROUGH",
  "absoluteBoundingBox": {
    "x": -104.83568572998047,
    "y": 330.29559326171875,
    "width": 158.5352325439453,
    "height": 18.87322998046875
  },
  "absoluteRenderBounds": {
    "x": -104.0505599975586,
    "y": 332.3878479003906,
    "width": 121.72467803955078,
    "height": 14.819244384765625
  },
  "constraints": {
    "vertical": "TOP",
    "horizontal": "LEFT"
  },
  "layoutVersion": 3,
  "/* --- */"
}

Add tests

The test harness is ready, I just don't know what to test.

Re-export axios types

Since figma-js returns axios types, a project needs to add axios as a dependency, even if it isn't directly depending on it. Re-exporting those types would probably be cleaner.

Types for style and file style responses do not match reality

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

The types for the GET file styles endpoint response say it returns an object with a root array property of styles containing style definitions, extending an object with a meta property with a key-value map of style definitions :

export interface FileStylesResponse extends StyleResponse {
  readonly styles: ReadonlyArray<FullStyleMetadata>;
}

export interface StyleResponse {
  readonly meta: {
    readonly err: string | null;
    readonly status: number;
    readonly [key: string]: FullStyleMetadata;
  };
}

This does not match the API:

https://www.figma.com/developers/api#get-file-styles-endpoint

The example response is:

{
  "status": Number,
  "error": Boolean,
  "meta": { 
    "styles": [
      {
       "key": String,
       "file_key": String,
       "node_id": String,
       "style_type": StyleType,
       "thumbnail_url": String,
       "name": String,
       "description": String,
       "updated_at": String,
       "created_at": String,
       "sort_position": String,
       "user": User, 
       },
      ...
    ],
   }, 
}
  1. There is no root styles property containing style metadata.
  2. The meta property has a single property, styles which maps to an array of style metadata.

The GET style endpoint is typed to return the StyleResponse object above. This does not match the API:

https://www.figma.com/developers/api#get-style-endpoint

The example response is:

{
  "status": Number,
  "error": Boolean,
  "meta": { 
     "key": String,
     "file_key": String,
     "node_id": String,
     "style_type": StyleType,
     "thumbnail_url": String,
     "name": String,
     "description": String,
     "updated_at": String,
     "created_at": String,
     "sort_position": String,
     "user": User, 
   }, 
}

The style definition object is not keyed within the meta property, it is the meta property.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

COMPONENT_SET is missing from NodeType declaration

  • I'm submitting a ...
    [ ] bug report
    [x] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    COMPONENT_SET is listed in Figma's API documentation, but is not present in this package's NodeType declaration

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)*
    Similar to this issue

Update axios to support PROXY env vars

  • I'm submitting a ...
    [ ] bug report
    [X] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Please update the axios dependency to support usage of HTTP_PROXY and HTTPS_PROXY environment variables.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Related issue on @figma-export/cli : marcomontalbano/figma-export#152

client.file Cannot read property 'join' of undefined

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    If params are not passed when fetching a file, the method will throw since ids is undefined. The change that causes this issue was introduced here: https://github.com/jongold/figma-js/pull/39/files#diff-f41e9d04a45c83f3b6f6e630f10117feR309

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Suggested fix:

    file: (fileId, params = {}) =>
      client.get(`files/${fileId}`, {
        params: {
          ...params,
          ids: params.ids ? params.ids.join(',') : '',
        },
      }),

Work around:

//before
client.file(fildId).then(() => {})

//after
client.file(fildId, { ids: [] }).then(() => {})

Site link doesn't work

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    jongold.github.io/figma-js/ link doesn't show the site.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Missing 'plugin_data' query params

  • I'm submitting a ...
    [ ] bug report
    [X] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Hey! Nice work here. Im just posting an issue to track that the figma api now supports fetching PluginData.

https://www.figma.com/developers/api#authentication

Screen Shot 2020-10-16 at 5 17 56 PM

No rush on this!

Thanks,
Colin

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Generate types automatically

I wrote all the types out by hand which was some pretty intense type 2 fun.

Would be excellent if someone (at Figma?) could figure out how to generate them automatically.

Potential nesting limits; failed node render

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Heya figma-js team. I'm running into an issue with fetching a frame at a certain nested level. Debatable design file hygiene aside, I wanted to touch base with y'all to see if this behavior's been encountered.

From the "Copy link" menu in Figma, I grab the URL,

https://www.figma.com/file/hash/project?node-id=4316%3A10002

and then pass the node ID into the .fileImages call,

const figma = Figma.Client({
	personalAccessToken: FIGMA_TOKEN,
});

const response = await figma.fileImages(key, {
	// passing in the IDs from the above link
	ids: ['4316:10002'],
});

and get a response with,

// response.data
{
    err: null,
    images:
    {
        '4316:10002':  null  // instead of the expected S3 URL 
    }
}

Here's an image of the limits:
figma

Checking the docs, the closest hunch I have to what's happening is:

Important: the image map may contain values that are null. This indicates that rendering of that specific node has failed. This may be due to the node id not existing, or other reasons such has the node having no renderable components.

https://www.figma.com/developers/api#get-images-endpoint

So perhaps the Frame I'm copying doesn't have any renderable components? If that's the case, apologies for the ticket and my blatant misuse :-)

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

Love this project! Huge kudos to the authors and maintainers.

Node.Type = 'BOOLEAN_OPERATION'

  • I'm submitting a ...
    [ ] bug report
    [x] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

there isn't BOOLEAN_OPERATION in NodeType.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

thumbnail_urlString property in SharedElement interface is incorrectly named

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    The thumbnail_urlString property currently defined in the SharedElement interface should be thumbnail_url (see https://www.figma.com/developers/api#library-items-types).

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

interface SharedElement extends ComponentMetadata {
  ...
  readonly thumbnail_urlString: string;
 ...
}

should instead be

interface SharedElement extends ComponentMetadata {
  ...
  readonly thumbnail_url: string;
 ...
}

Geometry and version options

  • I'm submitting a ...
    [ ] bug report
    [X] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Get:file exposes no geometry or version options, but it very much should.

webhooks support

  • I'm submitting a ...
    [ ] bug report
    [x] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary
    Add first-class support for working with webhooks. It is still in beta so I understand if this should wait. I'd be happy to start a PR for this just let me know :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.