@calibrate-ds/figma-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import type { FigmaClientOptions } from "./types.js";
2
+ type FetchOptions = {
3
+ method?: string;
4
+ headers?: Record<string, string>;
5
+ body?: string;
6
+ };
7
+ export declare function createFigmaClient(options: FigmaClientOptions): {
8
+ request: <T>(endpoint: string, fetchOptions?: FetchOptions) => Promise<T>;
9
+ };
10
+ export {};
11
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAsB,MAAM,YAAY,CAAC;AAEzE,KAAK,YAAY,GAAG;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB;cAGlC,CAAC,YAAY,MAAM,iBAAgB,YAAY,KAAQ,OAAO,CAAC,CAAC,CAAC;EAmC3F"}
package/dist/client.js ADDED
@@ -0,0 +1,33 @@
1
+ export function createFigmaClient(options) {
2
+ const baseUrl = options.baseUrl || "https://api.figma.com/v1";
3
+ async function request(endpoint, fetchOptions = {}) {
4
+ const url = `${baseUrl}${endpoint.startsWith("/") ? endpoint : `/${endpoint}`}`;
5
+ const headers = {
6
+ "X-Figma-Token": options.token,
7
+ "Content-Type": "application/json",
8
+ ...(fetchOptions.headers || {}),
9
+ };
10
+ const response = await fetch(url, {
11
+ ...fetchOptions,
12
+ headers,
13
+ });
14
+ if (!response.ok) {
15
+ let errorData;
16
+ try {
17
+ // Attempt to parse standard Figma error format
18
+ errorData = await response.json();
19
+ }
20
+ catch {
21
+ // Fallback if not JSON
22
+ }
23
+ const rawErrorMessage = errorData?.err || response.statusText;
24
+ const errorMessage = typeof rawErrorMessage === 'string'
25
+ ? rawErrorMessage.replace(/(?:figd|figa)_[a-zA-Z0-9\-_]+/g, "[REDACTED]")
26
+ : String(rawErrorMessage);
27
+ throw new Error(`Figma API Error (${response.status}): ${errorMessage} - while requesting ${url}`);
28
+ }
29
+ return response.json();
30
+ }
31
+ return { request };
32
+ }
33
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAQA,MAAM,UAAU,iBAAiB,CAAC,OAA2B;IACzD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,0BAA0B,CAAC;IAE9D,KAAK,UAAU,OAAO,CAAI,QAAgB,EAAE,eAA6B,EAAE;QACvE,MAAM,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,EAAE,CAAC;QAEhF,MAAM,OAAO,GAAG;YACZ,eAAe,EAAE,OAAO,CAAC,KAAK;YAC9B,cAAc,EAAE,kBAAkB;YAClC,GAAG,CAAC,YAAY,CAAC,OAAO,IAAI,EAAE,CAAC;SAClC,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAC9B,GAAG,YAAY;YACf,OAAO;SACV,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,IAAI,SAAyC,CAAC;YAC9C,IAAI,CAAC;gBACD,+CAA+C;gBAC/C,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACtC,CAAC;YAAC,MAAM,CAAC;gBACL,uBAAuB;YAC3B,CAAC;YAED,MAAM,eAAe,GAAG,SAAS,EAAE,GAAG,IAAI,QAAQ,CAAC,UAAU,CAAC;YAC9D,MAAM,YAAY,GAAG,OAAO,eAAe,KAAK,QAAQ;gBACpD,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,gCAAgC,EAAE,YAAY,CAAC;gBACzE,CAAC,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;YAE9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,CAAC,MAAM,MAAM,YAAY,uBAAuB,GAAG,EAAE,CAAC,CAAC;QACvG,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,EAAgB,CAAC;IACzC,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACvB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { FigmaFileResponse } from "./types.js";
2
+ type GetFigmaFileParams = {
3
+ fileKey: string;
4
+ token: string;
5
+ baseUrl?: string;
6
+ };
7
+ /**
8
+ * Fetch the complete Figma file contents (document tree, components, component sets, and styles).
9
+ */
10
+ export declare function getFigmaFile(params: GetFigmaFileParams): Promise<FigmaFileResponse>;
11
+ export {};
12
+ //# sourceMappingURL=get-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-file.d.ts","sourceRoot":"","sources":["../src/get-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,KAAK,kBAAkB,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAOzF"}
@@ -0,0 +1,12 @@
1
+ import { createFigmaClient } from "./client.js";
2
+ /**
3
+ * Fetch the complete Figma file contents (document tree, components, component sets, and styles).
4
+ */
5
+ export async function getFigmaFile(params) {
6
+ const client = createFigmaClient({
7
+ token: params.token,
8
+ baseUrl: params.baseUrl,
9
+ });
10
+ return client.request(`/files/${params.fileKey}`);
11
+ }
12
+ //# sourceMappingURL=get-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-file.js","sourceRoot":"","sources":["../src/get-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAShD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAA0B;IACzD,MAAM,MAAM,GAAG,iBAAiB,CAAC;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,MAAM,CAAC,OAAO;KAC1B,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,OAAO,CAAoB,UAAU,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { FigmaClientOptions } from "./types.js";
2
+ export type GetImageExportsParams = {
3
+ fileKey: string;
4
+ nodeIds: string[];
5
+ format?: "svg" | "png" | "jpg";
6
+ } & Pick<FigmaClientOptions, "token" | "baseUrl">;
7
+ export declare function getImageExports(params: GetImageExportsParams): Promise<Record<string, string | null>>;
8
+ //# sourceMappingURL=get-image-exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-image-exports.d.ts","sourceRoot":"","sources":["../src/get-image-exports.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,MAAM,MAAM,qBAAqB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;CAClC,GAAG,IAAI,CAAC,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;AAOlD,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAS3G"}
@@ -0,0 +1,11 @@
1
+ import { createFigmaClient } from "./client.js";
2
+ export async function getImageExports(params) {
3
+ const client = createFigmaClient({ token: params.token, baseUrl: params.baseUrl });
4
+ const ids = params.nodeIds.join(",");
5
+ const format = params.format ?? "svg";
6
+ const response = await client.request(`/images/${params.fileKey}?ids=${ids}&format=${format}&svg_include_id=false`);
7
+ if (response.err)
8
+ throw new Error(`Figma image export error: ${response.err}`);
9
+ return response.images;
10
+ }
11
+ //# sourceMappingURL=get-image-exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-image-exports.js","sourceRoot":"","sources":["../src/get-image-exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAchD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAA6B;IAC/D,MAAM,MAAM,GAAG,iBAAiB,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IACnF,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC;IACtC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CACjC,WAAW,MAAM,CAAC,OAAO,QAAQ,GAAG,WAAW,MAAM,uBAAuB,CAC/E,CAAC;IACF,IAAI,QAAQ,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/E,OAAO,QAAQ,CAAC,MAAM,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { FigmaVariablesResponse } from "./types.js";
2
+ type GetFigmaLocalVariablesParams = {
3
+ fileKey: string;
4
+ token: string;
5
+ baseUrl?: string;
6
+ };
7
+ /**
8
+ * Fetch the local variables and collections associated with the given Figma file.
9
+ */
10
+ export declare function getFigmaLocalVariables(params: GetFigmaLocalVariablesParams): Promise<FigmaVariablesResponse>;
11
+ export {};
12
+ //# sourceMappingURL=get-local-variables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-local-variables.d.ts","sourceRoot":"","sources":["../src/get-local-variables.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,KAAK,4BAA4B,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,wBAAsB,sBAAsB,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAOlH"}
@@ -0,0 +1,12 @@
1
+ import { createFigmaClient } from "./client.js";
2
+ /**
3
+ * Fetch the local variables and collections associated with the given Figma file.
4
+ */
5
+ export async function getFigmaLocalVariables(params) {
6
+ const client = createFigmaClient({
7
+ token: params.token,
8
+ baseUrl: params.baseUrl,
9
+ });
10
+ return client.request(`/files/${params.fileKey}/variables/local`);
11
+ }
12
+ //# sourceMappingURL=get-local-variables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-local-variables.js","sourceRoot":"","sources":["../src/get-local-variables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAShD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,MAAoC;IAC7E,MAAM,MAAM,GAAG,iBAAiB,CAAC;QAC7B,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,OAAO,EAAE,MAAM,CAAC,OAAO;KAC1B,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,OAAO,CAAyB,UAAU,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./types.js";
2
+ export * from "./client.js";
3
+ export * from "./get-file.js";
4
+ export * from "./get-local-variables.js";
5
+ export * from "./get-image-exports.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./types.js";
2
+ export * from "./client.js";
3
+ export * from "./get-file.js";
4
+ export * from "./get-local-variables.js";
5
+ export * from "./get-image-exports.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,29 @@
1
+ export type FigmaClientOptions = {
2
+ token: string;
3
+ baseUrl?: string;
4
+ };
5
+ export type FigmaApiErrorShape = {
6
+ status: number;
7
+ err: string;
8
+ };
9
+ export type FigmaFileResponse = {
10
+ document: any;
11
+ components: Record<string, any>;
12
+ componentSets: Record<string, any>;
13
+ schemaVersion: number;
14
+ styles: Record<string, any>;
15
+ name: string;
16
+ lastModified: string;
17
+ thumbnailUrl: string;
18
+ version: string;
19
+ role: string;
20
+ };
21
+ export type FigmaVariablesResponse = {
22
+ status: number;
23
+ error?: boolean;
24
+ meta: {
25
+ variableCollections: Record<string, any>;
26
+ variables: Record<string, any>;
27
+ };
28
+ };
29
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,QAAQ,EAAE,GAAG,CAAC;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE;QACF,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACzC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAClC,CAAC;CACL,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@calibrate-ds/figma-client",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json",
22
+ "lint": "echo \"No lint yet\"",
23
+ "test": "echo \"No tests yet\""
24
+ }
25
+ }