From 31a0f2ea3d48da1391078773f601a1ae46a66a84 Mon Sep 17 00:00:00 2001 From: Louis LE GALL Date: Wed, 16 Nov 2022 18:37:59 +0100 Subject: [PATCH] feat: add support of http agents and proxy --- README.md | 16 ++++++++++++++++ src/index.ts | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a132223..221428a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,22 @@ const client = Figma.Client({ }); ``` +Or if you need to use a https proxy agent: + +```typescript +import * as Figma from 'figma-js'; +import { HttpsProxyAgent } from 'https-proxy-agent'; + +const token = '12345'; +const proxyAgent = new HttpsProxyAgent(process.env.https_proxy); + +const client = Figma.Client({ + accessToken: token, + httpsAgent: proxyAgent, + proxy: false +}); +``` + ### Doing cool things Once you have instantiated a client, have fun! diff --git a/src/index.ts b/src/index.ts index 9490aee..5280dc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ // export * from './lib/number'; import * as Figma from './figmaTypes'; export * from './figmaTypes'; -import axios, { AxiosInstance, AxiosPromise } from 'axios'; +import axios, { AxiosInstance, AxiosPromise, AxiosRequestConfig } from 'axios'; export interface FileParams { /** @@ -107,7 +107,10 @@ export interface PaginationParams { readonly cursor?: { readonly before?: number; readonly after?: number }; } -export interface ClientOptions { +export interface ClientOptions + extends Readonly< + Pick + > { /** access token returned from OAuth authentication */ readonly accessToken?: string; /** personal access token obtained from account settings */ @@ -340,6 +343,9 @@ export const Client = (opts: ClientOptions): ClientInterface => { }; const client = axios.create({ + proxy: opts.proxy, + httpAgent: opts.httpAgent, + httpsAgent: opts.httpsAgent, baseURL: `https://${opts.apiRoot || 'api.figma.com'}/v1/`, headers, });