jemgold / figma-js

Little wrapper (+ types) for the Figma API
https://jongold.github.io/figma-js/
MIT License
492 stars 47 forks source link

Types for style and file style responses do not match reality #34

Closed jonrimmer closed 2 years ago

jonrimmer commented 4 years ago

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.