UNPKG

figma-api

Version:

Thin typed wrapper around the Figma REST API

1,234 lines (1,110 loc) 162 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Figma = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ (function (Buffer){(function (){ "use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Api = void 0; exports.oAuthLink = oAuthLink; exports.oAuthToken = oAuthToken; var ApiEndpoints = __importStar(require("./api-endpoints")); var utils_1 = require("./utils"); var axios_1 = __importDefault(require("axios")); var Api = /** @class */ (function () { function Api(params) { var _this = this; this.appendHeaders = function (headers) { if (_this.personalAccessToken) headers['X-Figma-Token'] = _this.personalAccessToken; if (_this.oAuthToken) headers['Authorization'] = "Bearer ".concat(_this.oAuthToken); }; this.request = function (url, opts) { return __awaiter(_this, void 0, void 0, function () { var headers, axiosParams, res; return __generator(this, function (_a) { switch (_a.label) { case 0: headers = {}; this.appendHeaders(headers); axiosParams = __assign(__assign({ url: url }, opts), { headers: headers }); return [4 /*yield*/, (0, axios_1.default)(axiosParams)]; case 1: res = _a.sent(); if (Math.floor(res.status / 100) !== 2) throw res.statusText; return [2 /*return*/, res.data]; } }); }); }; this.getFile = ApiEndpoints.getFileApi; this.getFileNodes = ApiEndpoints.getFileNodesApi; this.getImages = ApiEndpoints.getImagesApi; this.getImageFills = ApiEndpoints.getImageFillsApi; this.getComments = ApiEndpoints.getCommentsApi; this.postComment = ApiEndpoints.postCommentApi; this.deleteComment = ApiEndpoints.deleteCommentApi; this.getCommentReactions = ApiEndpoints.getCommentReactionsApi; this.postCommentReaction = ApiEndpoints.postCommentReactionApi; this.deleteCommentReactions = ApiEndpoints.deleteCommentReactionsApi; this.getUserMe = ApiEndpoints.getUserMeApi; this.getFileVersions = ApiEndpoints.getFileVersionsApi; this.getTeamProjects = ApiEndpoints.getTeamProjectsApi; this.getProjectFiles = ApiEndpoints.getProjectFilesApi; this.getTeamComponents = ApiEndpoints.getTeamComponentsApi; this.getFileComponents = ApiEndpoints.getFileComponentsApi; this.getComponent = ApiEndpoints.getComponentApi; this.getTeamComponentSets = ApiEndpoints.getTeamComponentSetsApi; this.getFileComponentSets = ApiEndpoints.getFileComponentSetsApi; this.getComponentSet = ApiEndpoints.getComponentSetApi; this.getTeamStyles = ApiEndpoints.getTeamStylesApi; this.getFileStyles = ApiEndpoints.getFileStylesApi; this.getStyle = ApiEndpoints.getStyleApi; this.getWebhook = ApiEndpoints.getWebhookApi; this.postWebhook = ApiEndpoints.postWebhookApi; this.putWebhook = ApiEndpoints.putWebhookApi; this.deleteWebhook = ApiEndpoints.deleteWebhookApi; this.getTeamWebhooks = ApiEndpoints.getTeamWebhooksApi; this.getWebhookRequests = ApiEndpoints.getWebhookRequestsApi; this.getLocalVariables = ApiEndpoints.getLocalVariablesApi; this.getPublishedVariables = ApiEndpoints.getPublishedVariablesApi; this.postVariables = ApiEndpoints.postVariablesApi; this.getDevResources = ApiEndpoints.getDevResourcesApi; this.postDevResources = ApiEndpoints.postDevResourcesApi; this.putDevResources = ApiEndpoints.putDevResourcesApi; this.deleteDevResources = ApiEndpoints.deleteDevResourcesApi; this.getLibraryAnalyticsComponentActions = ApiEndpoints.getLibraryAnalyticsComponentActionsApi; this.getLibraryAnalyticsComponentUsages = ApiEndpoints.getLibraryAnalyticsComponentUsagesApi; this.getLibraryAnalyticsStyleActions = ApiEndpoints.getLibraryAnalyticsStyleActionsApi; this.getLibraryAnalyticsStyleUsages = ApiEndpoints.getLibraryAnalyticsStyleUsagesApi; this.getLibraryAnalyticsVariableActions = ApiEndpoints.getLibraryAnalyticsVariableActionsApi; this.getLibraryAnalyticsVariableUsages = ApiEndpoints.getLibraryAnalyticsVariableUsagesApi; if ('personalAccessToken' in params) { this.personalAccessToken = params.personalAccessToken; } if ('oAuthToken' in params) { this.oAuthToken = params.oAuthToken; } } return Api; }()); exports.Api = Api; // see: https://www.figma.com/developers/api#auth-oauth2 function oAuthLink(client_id, redirect_uri, scope, state, response_type) { var queryParams = (0, utils_1.toQueryParams)({ client_id: client_id, redirect_uri: redirect_uri, scope: scope, state: state, response_type: response_type, }); return "https://www.figma.com/oauth?".concat(queryParams); } function oAuthToken(client_id, client_secret, redirect_uri, code, grant_type) { return __awaiter(this, void 0, void 0, function () { var headers, queryParams, url, res; return __generator(this, function (_a) { switch (_a.label) { case 0: headers = { 'Authorization': "Basic ".concat(Buffer.from("".concat(client_id, ":").concat(client_secret)).toString('base64')), }; queryParams = (0, utils_1.toQueryParams)({ redirect_uri: redirect_uri, code: code, grant_type: grant_type, }); url = "https://api.figma.com/v1/oauth/token?".concat(queryParams); return [4 /*yield*/, axios_1.default.post(url, null, { headers: headers })]; case 1: res = _a.sent(); if (res.status !== 200) throw res.statusText; return [2 /*return*/, res.data]; } }); }); } }).call(this)}).call(this,require("buffer").Buffer) },{"./api-endpoints":2,"./utils":5,"axios":6,"buffer":46}],2:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFileApi = getFileApi; exports.getFileNodesApi = getFileNodesApi; exports.getImagesApi = getImagesApi; exports.getImageFillsApi = getImageFillsApi; exports.getCommentsApi = getCommentsApi; exports.postCommentApi = postCommentApi; exports.deleteCommentApi = deleteCommentApi; exports.getCommentReactionsApi = getCommentReactionsApi; exports.postCommentReactionApi = postCommentReactionApi; exports.deleteCommentReactionsApi = deleteCommentReactionsApi; exports.getUserMeApi = getUserMeApi; exports.getFileVersionsApi = getFileVersionsApi; exports.getTeamProjectsApi = getTeamProjectsApi; exports.getProjectFilesApi = getProjectFilesApi; exports.getTeamComponentsApi = getTeamComponentsApi; exports.getFileComponentsApi = getFileComponentsApi; exports.getComponentApi = getComponentApi; exports.getTeamComponentSetsApi = getTeamComponentSetsApi; exports.getFileComponentSetsApi = getFileComponentSetsApi; exports.getComponentSetApi = getComponentSetApi; exports.getTeamStylesApi = getTeamStylesApi; exports.getFileStylesApi = getFileStylesApi; exports.getStyleApi = getStyleApi; exports.getWebhookApi = getWebhookApi; exports.postWebhookApi = postWebhookApi; exports.putWebhookApi = putWebhookApi; exports.deleteWebhookApi = deleteWebhookApi; exports.getTeamWebhooksApi = getTeamWebhooksApi; exports.getWebhookRequestsApi = getWebhookRequestsApi; exports.getLocalVariablesApi = getLocalVariablesApi; exports.getPublishedVariablesApi = getPublishedVariablesApi; exports.postVariablesApi = postVariablesApi; exports.getDevResourcesApi = getDevResourcesApi; exports.postDevResourcesApi = postDevResourcesApi; exports.putDevResourcesApi = putDevResourcesApi; exports.deleteDevResourcesApi = deleteDevResourcesApi; exports.getLibraryAnalyticsComponentActionsApi = getLibraryAnalyticsComponentActionsApi; exports.getLibraryAnalyticsComponentUsagesApi = getLibraryAnalyticsComponentUsagesApi; exports.getLibraryAnalyticsStyleActionsApi = getLibraryAnalyticsStyleActionsApi; exports.getLibraryAnalyticsStyleUsagesApi = getLibraryAnalyticsStyleUsagesApi; exports.getLibraryAnalyticsVariableActionsApi = getLibraryAnalyticsVariableActionsApi; exports.getLibraryAnalyticsVariableUsagesApi = getLibraryAnalyticsVariableUsagesApi; var config_1 = require("./config"); var utils_1 = require("./utils"); // FILES // https://www.figma.com/developers/api#files-endpoints // ----------------------------------------------------------------- function getFileApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "?").concat(encodedQueryParams)); } function getFileNodesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/nodes?").concat(encodedQueryParams)); } function getImagesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/images/").concat(pathParams.file_key, "?").concat(encodedQueryParams)); } function getImageFillsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/images")); } // COMMENTS // https://www.figma.com/developers/api#comments-endpoints // ----------------------------------------------------------------- function getCommentsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/comments")); } function postCommentApi(pathParams, requestBody) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/comments"), { method: 'POST', data: requestBody, }); } function deleteCommentApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/comments/").concat(pathParams.comment_id), { method: 'DELETE', data: '' }); } function getCommentReactionsApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/comments/").concat(pathParams.comment_id, "/reactions?").concat(encodedQueryParams)); } function postCommentReactionApi(pathParams, requestBody) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/comments/").concat(pathParams.comment_id, "/reactions"), { method: 'POST', data: requestBody, }); } function deleteCommentReactionsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/comments/").concat(pathParams.comment_id, "/reactions"), { method: 'DELETE', data: '' }); } // USERS // https://www.figma.com/developers/api#users-endpoints // ----------------------------------------------------------------- function getUserMeApi() { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/me")); } // VERSION HISTORY (FILE VERSIONS) // https://www.figma.com/developers/api#version-history-endpoints // ----------------------------------------------------------------- function getFileVersionsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/versions")); } // PROJECTS // https://www.figma.com/developers/api#projects-endpoints // ----------------------------------------------------------------- function getTeamProjectsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/teams/").concat(pathParams.team_id, "/projects")); } function getProjectFilesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/projects/").concat(pathParams.project_id, "/files?").concat(encodedQueryParams)); } // COMPONENTS AND STYLES (LIBRARY ITEMS) // https://www.figma.com/developers/api#library-items-endpoints // ----------------------------------------------------------------- function getTeamComponentsApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/teams/").concat(pathParams.team_id, "/components?").concat(encodedQueryParams)); } function getFileComponentsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/components")); } function getComponentApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/components/").concat(pathParams.key)); } function getTeamComponentSetsApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/teams/").concat(pathParams.team_id, "/component_sets?").concat(encodedQueryParams)); } function getFileComponentSetsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/component_sets")); } function getComponentSetApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/component_sets/").concat(pathParams.key)); } function getTeamStylesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/teams/").concat(pathParams.team_id, "/styles?").concat(encodedQueryParams)); } function getFileStylesApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/styles")); } function getStyleApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/styles/").concat(pathParams.key)); } // WEBHOOKS // https://www.figma.com/developers/api#webhooks_v2 // ----------------------------------------------------------------- function getWebhookApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER_WEBHOOKS, "/webhooks/").concat(pathParams.webhook_id)); } function postWebhookApi(requestBody) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER_WEBHOOKS, "/webhooks"), { method: 'POST', data: requestBody, }); } function putWebhookApi(pathParams, requestBody) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER_WEBHOOKS, "/webhooks/").concat(pathParams.webhook_id), { method: 'PUT', data: requestBody, }); } function deleteWebhookApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER_WEBHOOKS, "/webhooks/").concat(pathParams.webhook_id, "/"), { method: 'DELETE', data: '' }); } function getTeamWebhooksApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER_WEBHOOKS, "/teams/").concat(pathParams.team_id, "/webhooks")); } function getWebhookRequestsApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER_WEBHOOKS, "/webhooks/").concat(pathParams.webhook_id, "/requests")); } // ACTIVITY LOGS // https://www.figma.com/developers/api#activity-logs-endpoints // ----------------------------------------------------------------- // TODO - Open to contributions if someone is needs to use these endpoints // PAYMENTS // https://www.figma.com/developers/api#payments-endpoints // ----------------------------------------------------------------- // TODO - Open to contributions if someone is needs to use these endpoints // VARIABLES // These APIs are available only to full members of Enterprise orgs. // https://www.figma.com/developers/api#variables-endpoints // ----------------------------------------------------------------- function getLocalVariablesApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/variables/local")); } function getPublishedVariablesApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/analytics/libraries/").concat(pathParams.file_key, "/variables/published")); } function postVariablesApi(pathParams, requestBody) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/variables"), { method: 'POST', data: requestBody, }); } // DEV RESOURCES // https://www.figma.com/developers/api#dev-resources-endpoints // ----------------------------------------------------------------- function getDevResourcesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/dev_resources")); } function postDevResourcesApi(requestBody) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/dev_resources"), { method: 'POST', data: requestBody, }); } function putDevResourcesApi(requestBody) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/dev_resources"), { method: 'PUT', data: requestBody, }); } function deleteDevResourcesApi(pathParams) { return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/files/").concat(pathParams.file_key, "/dev_resources/").concat(pathParams.dev_resource_id), { method: 'DELETE', data: '' }); } // ANALYTICS // https://www.figma.com/developers/api#library-analytics-endpoints // ----------------------------------------------------------------- function getLibraryAnalyticsComponentActionsApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/analytics/libraries/").concat(pathParams.file_key, "/component/actions?").concat(encodedQueryParams)); } function getLibraryAnalyticsComponentUsagesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/analytics/libraries/").concat(pathParams.file_key, "/component/usages?").concat(encodedQueryParams)); } function getLibraryAnalyticsStyleActionsApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/analytics/libraries/").concat(pathParams.file_key, "/style/actions?").concat(encodedQueryParams)); } function getLibraryAnalyticsStyleUsagesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/analytics/libraries/").concat(pathParams.file_key, "/style/usages?").concat(encodedQueryParams)); } function getLibraryAnalyticsVariableActionsApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/analytics/libraries/").concat(pathParams.file_key, "/variable/actions?").concat(encodedQueryParams)); } function getLibraryAnalyticsVariableUsagesApi(pathParams, queryParams) { var encodedQueryParams = (0, utils_1.toQueryParams)(queryParams); return this.request("".concat(config_1.API_DOMAIN, "/").concat(config_1.API_VER, "/analytics/libraries/").concat(pathParams.file_key, "/variable/usages?").concat(encodedQueryParams)); } },{"./config":3,"./utils":5}],3:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.API_VER_WEBHOOKS = exports.API_VER = exports.API_DOMAIN = void 0; exports.API_DOMAIN = 'https://api.figma.com'; exports.API_VER = 'v1'; exports.API_VER_WEBHOOKS = 'v2'; },{}],4:[function(require,module,exports){ "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./config"), exports); __exportStar(require("./api-class"), exports); },{"./api-class":1,"./config":3}],5:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ApiError = void 0; exports.toQueryParams = toQueryParams; function toQueryParams(x) { if (!x) return ''; return Object.entries(x).map(function (_a) { var k = _a[0], v = _a[1]; return (k && v && "".concat(k, "=").concat(encodeURIComponent(v))); }).filter(Boolean).join('&'); } var ApiError = /** @class */ (function (_super) { __extends(ApiError, _super); function ApiError(response, message) { var _this = _super.call(this, message) || this; _this.response = response; return _this; } return ApiError; }(Error)); exports.ApiError = ApiError; },{}],6:[function(require,module,exports){ module.exports = require('./lib/axios'); },{"./lib/axios":8}],7:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); var settle = require('./../core/settle'); var cookies = require('./../helpers/cookies'); var buildURL = require('./../helpers/buildURL'); var buildFullPath = require('../core/buildFullPath'); var parseHeaders = require('./../helpers/parseHeaders'); var isURLSameOrigin = require('./../helpers/isURLSameOrigin'); var transitionalDefaults = require('../defaults/transitional'); var AxiosError = require('../core/AxiosError'); var CanceledError = require('../cancel/CanceledError'); var parseProtocol = require('../helpers/parseProtocol'); var platform = require('../platform'); module.exports = function xhrAdapter(config) { return new Promise(function dispatchXhrRequest(resolve, reject) { var requestData = config.data; var requestHeaders = config.headers; var responseType = config.responseType; var withXSRFToken = config.withXSRFToken; var onCanceled; function done() { if (config.cancelToken) { config.cancelToken.unsubscribe(onCanceled); } if (config.signal) { config.signal.removeEventListener('abort', onCanceled); } } if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) { delete requestHeaders['Content-Type']; // Let the browser set it } var request = new XMLHttpRequest(); // HTTP basic authentication if (config.auth) { var username = config.auth.username || ''; var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : ''; requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password); } var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls); request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true); // Set the request timeout in MS request.timeout = config.timeout; function onloadend() { if (!request) { return; } // Prepare the response var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null; var responseData = !responseType || responseType === 'text' || responseType === 'json' ? request.responseText : request.response; var response = { data: responseData, status: request.status, statusText: request.statusText, headers: responseHeaders, config: config, request: request }; settle(function _resolve(value) { resolve(value); done(); }, function _reject(err) { reject(err); done(); }, response); // Clean up request request = null; } if ('onloadend' in request) { // Use onloadend if available request.onloadend = onloadend; } else { // Listen for ready state to emulate onloadend request.onreadystatechange = function handleLoad() { if (!request || request.readyState !== 4) { return; } // The request errored out and we didn't get a response, this will be // handled by onerror instead // With one exception: request that using file: protocol, most browsers // will return status as 0 even though it's a successful request if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) { return; } // readystate handler is calling before onerror or ontimeout handlers, // so we should call onloadend on the next 'tick' setTimeout(onloadend); }; } // Handle browser request cancellation (as opposed to a manual cancellation) request.onabort = function handleAbort() { if (!request) { return; } reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request)); // Clean up request request = null; }; // Handle low level network errors request.onerror = function handleError() { // Real errors are hidden from us by the browser // onerror should only fire if it's a network error reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request)); // Clean up request request = null; }; // Handle timeout request.ontimeout = function handleTimeout() { var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded'; var transitional = config.transitional || transitionalDefaults; if (config.timeoutErrorMessage) { timeoutErrorMessage = config.timeoutErrorMessage; } reject(new AxiosError( timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, request)); // Clean up request request = null; }; // Add xsrf header // This is only done if running in a standard browser environment. // Specifically not if we're in a web worker, or react-native. if (utils.isStandardBrowserEnv()) { // Add xsrf header withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config)); if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) { // Add xsrf header var xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName); if (xsrfValue) { requestHeaders[config.xsrfHeaderName] = xsrfValue; } } } // Add headers to the request if ('setRequestHeader' in request) { utils.forEach(requestHeaders, function setRequestHeader(val, key) { if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') { // Remove Content-Type if data is undefined delete requestHeaders[key]; } else { // Otherwise add header to the request request.setRequestHeader(key, val); } }); } // Add withCredentials to request if needed if (!utils.isUndefined(config.withCredentials)) { request.withCredentials = !!config.withCredentials; } // Add responseType to request if needed if (responseType && responseType !== 'json') { request.responseType = config.responseType; } // Handle progress if needed if (typeof config.onDownloadProgress === 'function') { request.addEventListener('progress', config.onDownloadProgress); } // Not all browsers support upload events if (typeof config.onUploadProgress === 'function' && request.upload) { request.upload.addEventListener('progress', config.onUploadProgress); } if (config.cancelToken || config.signal) { // Handle cancellation // eslint-disable-next-line func-names onCanceled = function(cancel) { if (!request) { return; } reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel); request.abort(); request = null; }; config.cancelToken && config.cancelToken.subscribe(onCanceled); if (config.signal) { config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled); } } // false, 0 (zero number), and '' (empty string) are valid JSON values if (!requestData && requestData !== false && requestData !== 0 && requestData !== '') { requestData = null; } var protocol = parseProtocol(fullPath); if (protocol && platform.protocols.indexOf(protocol) === -1) { reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config)); return; } // Send the request request.send(requestData); }); }; },{"../cancel/CanceledError":10,"../core/AxiosError":13,"../core/buildFullPath":15,"../defaults/transitional":21,"../helpers/parseProtocol":35,"../platform":43,"./../core/settle":18,"./../helpers/buildURL":26,"./../helpers/cookies":28,"./../helpers/isURLSameOrigin":32,"./../helpers/parseHeaders":34,"./../utils":44}],8:[function(require,module,exports){ 'use strict'; var utils = require('./utils'); var bind = require('./helpers/bind'); var Axios = require('./core/Axios'); var mergeConfig = require('./core/mergeConfig'); var defaults = require('./defaults'); var formDataToJSON = require('./helpers/formDataToJSON'); /** * Create an instance of Axios * * @param {Object} defaultConfig The default config for the instance * @return {Axios} A new instance of Axios */ function createInstance(defaultConfig) { var context = new Axios(defaultConfig); var instance = bind(Axios.prototype.request, context); // Copy axios.prototype to instance utils.extend(instance, Axios.prototype, context); // Copy context to instance utils.extend(instance, context); // Factory for creating new instances instance.create = function create(instanceConfig) { return createInstance(mergeConfig(defaultConfig, instanceConfig)); }; return instance; } // Create the default instance to be exported var axios = createInstance(defaults); // Expose Axios class to allow class inheritance axios.Axios = Axios; // Expose Cancel & CancelToken axios.CanceledError = require('./cancel/CanceledError'); axios.CancelToken = require('./cancel/CancelToken'); axios.isCancel = require('./cancel/isCancel'); axios.VERSION = require('./env/data').version; axios.toFormData = require('./helpers/toFormData'); // Expose AxiosError class axios.AxiosError = require('../lib/core/AxiosError'); // alias for CanceledError for backward compatibility axios.Cancel = axios.CanceledError; // Expose all/spread axios.all = function all(promises) { return Promise.all(promises); }; axios.spread = require('./helpers/spread'); // Expose isAxiosError axios.isAxiosError = require('./helpers/isAxiosError'); axios.formToJSON = function(thing) { return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing); }; module.exports = axios; // Allow use of default import syntax in TypeScript module.exports.default = axios; },{"../lib/core/AxiosError":13,"./cancel/CancelToken":9,"./cancel/CanceledError":10,"./cancel/isCancel":11,"./core/Axios":12,"./core/mergeConfig":17,"./defaults":20,"./env/data":23,"./helpers/bind":25,"./helpers/formDataToJSON":29,"./helpers/isAxiosError":31,"./helpers/spread":36,"./helpers/toFormData":37,"./utils":44}],9:[function(require,module,exports){ 'use strict'; var CanceledError = require('./CanceledError'); /** * A `CancelToken` is an object that can be used to request cancellation of an operation. * * @class * @param {Function} executor The executor function. */ function CancelToken(executor) { if (typeof executor !== 'function') { throw new TypeError('executor must be a function.'); } var resolvePromise; this.promise = new Promise(function promiseExecutor(resolve) { resolvePromise = resolve; }); var token = this; // eslint-disable-next-line func-names this.promise.then(function(cancel) { if (!token._listeners) return; var i = token._listeners.length; while (i-- > 0) { token._listeners[i](cancel); } token._listeners = null; }); // eslint-disable-next-line func-names this.promise.then = function(onfulfilled) { var _resolve; // eslint-disable-next-line func-names var promise = new Promise(function(resolve) { token.subscribe(resolve); _resolve = resolve; }).then(onfulfilled); promise.cancel = function reject() { token.unsubscribe(_resolve); }; return promise; }; executor(function cancel(message, config, request) { if (token.reason) { // Cancellation has already been requested return; } token.reason = new CanceledError(message, config, request); resolvePromise(token.reason); }); } /** * Throws a `CanceledError` if cancellation has been requested. */ CancelToken.prototype.throwIfRequested = function throwIfRequested() { if (this.reason) { throw this.reason; } }; /** * Subscribe to the cancel signal */ CancelToken.prototype.subscribe = function subscribe(listener) { if (this.reason) { listener(this.reason); return; } if (this._listeners) { this._listeners.push(listener); } else { this._listeners = [listener]; } }; /** * Unsubscribe from the cancel signal */ CancelToken.prototype.unsubscribe = function unsubscribe(listener) { if (!this._listeners) { return; } var index = this._listeners.indexOf(listener); if (index !== -1) { this._listeners.splice(index, 1); } }; /** * Returns an object that contains a new `CancelToken` and a function that, when called, * cancels the `CancelToken`. */ CancelToken.source = function source() { var cancel; var token = new CancelToken(function executor(c) { cancel = c; }); return { token: token, cancel: cancel }; }; module.exports = CancelToken; },{"./CanceledError":10}],10:[function(require,module,exports){ 'use strict'; var AxiosError = require('../core/AxiosError'); var utils = require('../utils'); /** * A `CanceledError` is an object that is thrown when an operation is canceled. * * @class * @param {string=} message The message. * @param {Object=} config The config. * @param {Object=} request The request. */ function CanceledError(message, config, request) { // eslint-disable-next-line no-eq-null,eqeqeq AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request); this.name = 'CanceledError'; } utils.inherits(CanceledError, AxiosError, { __CANCEL__: true }); module.exports = CanceledError; },{"../core/AxiosError":13,"../utils":44}],11:[function(require,module,exports){ 'use strict'; module.exports = function isCancel(value) { return !!(value && value.__CANCEL__); }; },{}],12:[function(require,module,exports){ 'use strict'; var utils = require('./../utils'); var buildURL = require('../helpers/buildURL'); var InterceptorManager = require('./InterceptorManager'); var dispatchRequest = require('./dispatchRequest'); var mergeConfig = require('./mergeConfig'); var buildFullPath = require('./buildFullPath'); var validator = require('../helpers/validator'); var validators = validator.validators; /** * Create a new instance of Axios * * @param {Object} instanceConfig The default config for the instance */ function Axios(instanceConfig) { this.defaults = instanceConfig; this.interceptors = { request: new InterceptorManager(), response: new InterceptorManager() }; } /** * Dispatch a request * * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults) * @param {?Object} config */ Axios.prototype.request = function request(configOrUrl, config) { /*eslint no-param-reassign:0*/ // Allow for axios('example/url'[, config]) a la fetch API if (typeof configOrUrl === 'string') { config = config || {}; config.url = configOrUrl; } else { config = configOrUrl || {}; } config = mergeConfig(this.defaults, config); // Set config.method if (config.method) { config.method = config.method.toLowerCase(); } else if (this.defaults.method) { config.method = this.defaults.method.toLowerCase(); } else { config.method = 'get'; } var transitional = config.transitional; if (transitional !== undefined) { validator.assertOptions(transitional, { silentJSONParsing: validators.transitional(validators.boolean), forcedJSONParsing: validators.transitional(validators.boolean), clarifyTimeoutError: validators.transitional(validators.boolean) }, false); } var paramsSerializer = config.paramsSerializer; if (paramsSerializer != null) { if (utils.isFunction(paramsSerializer)) { config.paramsSerializer = { serialize: paramsSerializer }; } else { validator.assertOptions(paramsSerializer, { encode: validators.function, serialize: validators.function }, true); } } // filter out skipped interceptors var requestInterceptorChain = []; var synchronousRequestInterceptors = true; this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) { if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) { return; } synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous; requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected); }); var responseInterceptorChain = []; this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) { responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected); }); var promise; if (!synchronousRequestInterceptors) { var chain = [dispatchRequest, undefined]; Array.prototype.unshift.apply(chain, requestInterceptorChain); chain = chain.concat(responseInterceptorChain); promise = Promise.resolve(config); while (chain.length) { promise = promise.then(chain.shift(), chain.shift()); } return promise; } var newConfig = config; while (requestInterceptorChain.length) { var onFulfilled = requestInterceptorChain.shift(); var onRejected = requestInterceptorChain.shift(); try { newConfig = onFulfilled(newConfig); } catch (error) { onRejected(error); break; } } try { promise = dispatchRequest(newConfig); } catch (error) { return Promise.reject(error); } while (responseInterceptorChain.length) { promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift()); } return promise; }; Axios.prototype.getUri = function getUri(config) { config = mergeConfig(this.defaults, config); var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls); return buildURL(fullPath, config.params, config.paramsSerializer); }; // Provide aliases for supported request methods utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) { /*eslint func-names:0*/ Axios.prototype[method] = function(url, config) { return this.request(mergeConfig(config || {}, { method: method, url: url, data: (config || {}).data })); }; }); utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) { /*eslint func-names:0*/ function generateHTTPMethod(isForm) { return function httpMethod(url, data, config) { return this.request(mergeConfig(config || {}, { method: method, headers: isForm ? { 'Content-Type': 'multipart/form-data' } : {}, url: url, data: data })); }; } Axios.prototype[method] = generateHTTPMethod(); Axios.prototype[method + 'Form'] = generateHTTPMethod(true); }); module.exports = Axios; },{"../helpers/buildURL":26,"../helpers/validator":39,"./../utils":44,"./InterceptorManager":14,"./buildFullPath":15,"./dispatchRequest":16,"./mergeConfig":17}],13:[function(require,module,exports){ 'use strict'; var utils = require('../utils'); /** * Create an Error with the specified message, config, error code, request and response. * * @param {string} message The error message. * @param {string} [code] The error code (for example, 'ECONNABORTED'). * @param {Object} [config] The config. * @param {Object} [request] The request. * @param {Object} [response] The response. * @returns {Error} The created error. */ function AxiosError(message, code, config, request, response) { Error.call(this); if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } else { this.stack = (new Error()).stack; } this.message = message; this.name = 'AxiosError'; code && (this.code = code); config && (this.config = config); request && (this.request = request); response && (this.response = response); } utils.inherits(AxiosError, Error, { toJSON: function toJSON() { return { // Standard message: this.message, name: this.name, // Microsoft description: this.description, number: this.number, // Mozilla fileName: this.fileName, lineNumber: this.lineNumber, columnNumber: this.columnNumber, stack: this.stack, // Axios config: this.config, code: this.code, status: this.response && this.response.status ? this.response.status : null }; } }); var prototype = AxiosError.prototype; var descriptors = {}; [ 'ERR_BAD_OPTION_VALUE', 'ERR_BAD_OPTION', 'ECONNABORTED', 'ETIMEDOUT', 'ERR_NETWORK', 'ERR_FR_TOO_MANY_REDIRECTS', 'ERR_DEPRECATED',