@figma-vars/hooks 1.0.5 → 1.0.9
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.
- package/dist/constants/index.d.ts +11 -0
- package/dist/experimental/usePublishVars.d.ts +2 -0
- package/dist/experimental/useSync.d.ts +2 -0
- package/dist/experimental/useVariableAliases.d.ts +9 -0
- package/dist/experimental/useVariableBindings.d.ts +7 -0
- package/dist/figma-vars-hooks.js +222 -0
- package/dist/figma-vars-hooks.umd.cjs +1 -0
- package/dist/hooks/useFigmaToken.d.ts +5 -0
- package/dist/hooks/useVariableCollections.d.ts +3 -0
- package/dist/hooks/useVariableModes.d.ts +5 -0
- package/dist/hooks/useVariables.d.ts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/mutations/createVariable.d.ts +8 -0
- package/dist/mutations/deleteVariable.d.ts +8 -0
- package/dist/mutations/updateVariable.d.ts +9 -0
- package/dist/mutations/updateVariableValues.d.ts +8 -0
- package/dist/types/figma.d.ts +20 -0
- package/dist/types/hooks.d.ts +10 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mutations.d.ts +9 -0
- package/dist/utils/authHelpers.d.ts +8 -0
- package/dist/utils/cache.d.ts +7 -0
- package/dist/utils/fetchHelpers.d.ts +10 -0
- package/dist/utils/filterVariables.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const FIGMA_API_BASE_URL = "https://api.figma.com";
|
|
2
|
+
export declare const FIGMA_FILES_ENDPOINT = "https://api.figma.com/v1/files";
|
|
3
|
+
export declare const FIGMA_VARIABLES_ENDPOINT: (fileKey: string) => string;
|
|
4
|
+
export declare const FIGMA_COLLECTIONS_ENDPOINT: (fileKey: string) => string;
|
|
5
|
+
export declare const CREATE_VARIABLE_ACTION = "CREATE";
|
|
6
|
+
export declare const UPDATE_VARIABLE_ACTION = "UPDATE";
|
|
7
|
+
export declare const DELETE_VARIABLE_ACTION = "DELETE";
|
|
8
|
+
export declare const DEFAULT_HEADERS: {
|
|
9
|
+
'Content-Type': string;
|
|
10
|
+
};
|
|
11
|
+
export declare const DEFAULT_ERROR_MESSAGE = "An error occurred while communicating with the Figma API.";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FigmaVariable } from 'types';
|
|
2
|
+
declare const useVariableAliases: () => {
|
|
3
|
+
aliases: {
|
|
4
|
+
[alias: string]: FigmaVariable;
|
|
5
|
+
};
|
|
6
|
+
setAlias: (alias: string, variable: FigmaVariable) => void;
|
|
7
|
+
removeAlias: (alias: string) => void;
|
|
8
|
+
};
|
|
9
|
+
export default useVariableAliases;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { FigmaVariable } from 'types';
|
|
2
|
+
declare const useVariableBindings: () => {
|
|
3
|
+
bindings: Map<string, FigmaVariable>;
|
|
4
|
+
bindVariable: (elementId: string, variable: FigmaVariable) => void;
|
|
5
|
+
unbindVariable: (elementId: string) => void;
|
|
6
|
+
};
|
|
7
|
+
export default useVariableBindings;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var k = (t, e, r) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
|
+
var w = (t, e, r) => k(t, typeof e != "symbol" ? e + "" : e, r);
|
|
4
|
+
import { useState as i, useEffect as d, useRef as F, useCallback as p } from "react";
|
|
5
|
+
const c = () => {
|
|
6
|
+
const [t, e] = i("");
|
|
7
|
+
return d(() => {
|
|
8
|
+
e("");
|
|
9
|
+
}, []), t;
|
|
10
|
+
}, A = (t, e) => {
|
|
11
|
+
const [r, a] = i(null), [n, s] = i(!0), [o, l] = i(null), h = c(), m = F(null), u = p(async () => {
|
|
12
|
+
if (!h) {
|
|
13
|
+
l(new Error("API token is not provided")), s(!1);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
s(!0), l(null);
|
|
17
|
+
try {
|
|
18
|
+
const f = `https://api.figma.com/v1/files/${t}/variables`, b = await fetch(f, {
|
|
19
|
+
method: "GET",
|
|
20
|
+
headers: {
|
|
21
|
+
"X-FIGMA-TOKEN": h
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (!b.ok)
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Failed to fetch Figma variables: ${b.statusText}`
|
|
27
|
+
);
|
|
28
|
+
const g = await b.json();
|
|
29
|
+
a(g.meta.variables);
|
|
30
|
+
} catch (f) {
|
|
31
|
+
l(
|
|
32
|
+
f instanceof Error ? f : new Error("Failed to fetch variables")
|
|
33
|
+
);
|
|
34
|
+
} finally {
|
|
35
|
+
s(!1);
|
|
36
|
+
}
|
|
37
|
+
}, [t, h]), v = p(() => {
|
|
38
|
+
u();
|
|
39
|
+
}, [u]);
|
|
40
|
+
return d(() => {
|
|
41
|
+
if (u(), e != null && e.pollInterval)
|
|
42
|
+
return m.current = setInterval(u, e.pollInterval), () => {
|
|
43
|
+
m.current && clearInterval(m.current);
|
|
44
|
+
};
|
|
45
|
+
}, [u, e == null ? void 0 : e.pollInterval]), { variables: r, loading: n, error: o, refresh: v };
|
|
46
|
+
}, V = (t) => {
|
|
47
|
+
const [e, r] = i({
|
|
48
|
+
data: null,
|
|
49
|
+
loading: !0,
|
|
50
|
+
error: null
|
|
51
|
+
}), a = c();
|
|
52
|
+
return d(() => {
|
|
53
|
+
(async () => {
|
|
54
|
+
if (!a) {
|
|
55
|
+
r((o) => ({
|
|
56
|
+
...o,
|
|
57
|
+
loading: !1,
|
|
58
|
+
error: new Error("API token is not provided")
|
|
59
|
+
}));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const s = `https://api.figma.com/v1/files/${t}/variable_collections`;
|
|
63
|
+
try {
|
|
64
|
+
const o = await fetch(s, {
|
|
65
|
+
headers: {
|
|
66
|
+
"X-FIGMA-TOKEN": a
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (!o.ok)
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Failed to fetch Figma collections: ${o.statusText}`
|
|
72
|
+
);
|
|
73
|
+
const l = await o.json();
|
|
74
|
+
r({
|
|
75
|
+
data: l.meta.variableCollections,
|
|
76
|
+
loading: !1,
|
|
77
|
+
error: null
|
|
78
|
+
});
|
|
79
|
+
} catch (o) {
|
|
80
|
+
r((l) => ({
|
|
81
|
+
...l,
|
|
82
|
+
loading: !1,
|
|
83
|
+
error: o instanceof Error ? o : new Error("Failed to fetch")
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
}, [t, a]), e;
|
|
88
|
+
}, I = (t) => {
|
|
89
|
+
const [e, r] = i(null), a = c();
|
|
90
|
+
return d(() => {
|
|
91
|
+
(async () => {
|
|
92
|
+
const s = `https://api.figma.com/v1/collections/${t}/modes`;
|
|
93
|
+
try {
|
|
94
|
+
if (!(await fetch(s, {
|
|
95
|
+
headers: {
|
|
96
|
+
"X-FIGMA-TOKEN": a
|
|
97
|
+
}
|
|
98
|
+
})).ok) throw new Error("Failed to fetch Figma modes");
|
|
99
|
+
r({ success: !0, message: "Modes fetched successfully" });
|
|
100
|
+
} catch (o) {
|
|
101
|
+
r({
|
|
102
|
+
success: !1,
|
|
103
|
+
message: o instanceof Error ? o.message : "Unknown error"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
})();
|
|
107
|
+
}, [t, a]), { response: e };
|
|
108
|
+
};
|
|
109
|
+
async function M(t, e) {
|
|
110
|
+
const r = c();
|
|
111
|
+
if (!r) throw new Error("API token is not provided");
|
|
112
|
+
const a = `https://api.figma.com/v1/files/${t}/variables`, n = await fetch(a, {
|
|
113
|
+
method: "POST",
|
|
114
|
+
headers: {
|
|
115
|
+
"Content-Type": "application/json",
|
|
116
|
+
"X-FIGMA-TOKEN": r
|
|
117
|
+
},
|
|
118
|
+
body: JSON.stringify(e)
|
|
119
|
+
});
|
|
120
|
+
if (!n.ok)
|
|
121
|
+
throw new Error("Failed to create Figma variable");
|
|
122
|
+
return n.json();
|
|
123
|
+
}
|
|
124
|
+
async function O(t, e, r) {
|
|
125
|
+
const a = c();
|
|
126
|
+
if (!a) throw new Error("API token is not provided");
|
|
127
|
+
const n = `https://api.figma.com/v1/files/${t}/variables/${e}`, s = await fetch(n, {
|
|
128
|
+
method: "PUT",
|
|
129
|
+
headers: {
|
|
130
|
+
"Content-Type": "application/json",
|
|
131
|
+
"X-FIGMA-TOKEN": a
|
|
132
|
+
},
|
|
133
|
+
body: JSON.stringify(r)
|
|
134
|
+
});
|
|
135
|
+
if (!s.ok)
|
|
136
|
+
throw new Error("Failed to update Figma variable");
|
|
137
|
+
return s.json();
|
|
138
|
+
}
|
|
139
|
+
async function P(t, e) {
|
|
140
|
+
const r = c();
|
|
141
|
+
if (!r) throw new Error("API token is not provided");
|
|
142
|
+
const a = `https://api.figma.com/v1/files/${t}/variables/${e}`, n = await fetch(a, {
|
|
143
|
+
method: "DELETE",
|
|
144
|
+
headers: {
|
|
145
|
+
"X-FIGMA-TOKEN": r
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (!n.ok)
|
|
149
|
+
throw new Error("Failed to delete Figma variable");
|
|
150
|
+
return n.json();
|
|
151
|
+
}
|
|
152
|
+
async function $(t, e) {
|
|
153
|
+
const r = c();
|
|
154
|
+
if (!r) throw new Error("API token is not provided");
|
|
155
|
+
const a = `https://api.figma.com/v1/variables/${t}/values`, n = await fetch(a, {
|
|
156
|
+
method: "PUT",
|
|
157
|
+
headers: {
|
|
158
|
+
"X-FIGMA-TOKEN": r,
|
|
159
|
+
"Content-Type": "application/json"
|
|
160
|
+
},
|
|
161
|
+
body: JSON.stringify(e)
|
|
162
|
+
});
|
|
163
|
+
if (!n.ok)
|
|
164
|
+
throw new Error("Failed to update variable values");
|
|
165
|
+
return n.json();
|
|
166
|
+
}
|
|
167
|
+
function j(t, e) {
|
|
168
|
+
return t.filter((r) => {
|
|
169
|
+
let a = !0;
|
|
170
|
+
return e.type && (a = a && r.type === e.type), e.name && (a = a && r.name === e.name), a;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
class N {
|
|
174
|
+
constructor() {
|
|
175
|
+
w(this, "cache", {});
|
|
176
|
+
}
|
|
177
|
+
get(e) {
|
|
178
|
+
return this.cache[e];
|
|
179
|
+
}
|
|
180
|
+
set(e, r) {
|
|
181
|
+
this.cache[e] = r;
|
|
182
|
+
}
|
|
183
|
+
clear(e) {
|
|
184
|
+
e ? delete this.cache[e] : this.cache = {};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const C = () => null, G = () => !0, S = async (t, e = { method: "GET" }) => {
|
|
188
|
+
throw new Error("Figma API token is not available.");
|
|
189
|
+
}, X = () => {
|
|
190
|
+
const [t, e] = i({});
|
|
191
|
+
return { aliases: t, setAlias: (n, s) => e((o) => ({ ...o, [n]: s })), removeAlias: (n) => {
|
|
192
|
+
const s = { ...t };
|
|
193
|
+
delete s[n], e(s);
|
|
194
|
+
} };
|
|
195
|
+
}, K = () => {
|
|
196
|
+
const [t, e] = i(
|
|
197
|
+
/* @__PURE__ */ new Map()
|
|
198
|
+
);
|
|
199
|
+
return { bindings: t, bindVariable: (n, s) => e(new Map(t.set(n, s))), unbindVariable: (n) => {
|
|
200
|
+
const s = new Map(t);
|
|
201
|
+
s.delete(n), e(s);
|
|
202
|
+
} };
|
|
203
|
+
}, x = () => ({}), B = () => ({});
|
|
204
|
+
export {
|
|
205
|
+
N as VariablesCache,
|
|
206
|
+
M as createVariable,
|
|
207
|
+
P as deleteVariable,
|
|
208
|
+
S as fetchWithAuth,
|
|
209
|
+
j as filterVariables,
|
|
210
|
+
C as getFigmaToken,
|
|
211
|
+
O as updateVariable,
|
|
212
|
+
$ as updateVariableValues,
|
|
213
|
+
c as useFigmaToken,
|
|
214
|
+
x as usePublishVars,
|
|
215
|
+
B as useSync,
|
|
216
|
+
X as useVariableAliases,
|
|
217
|
+
K as useVariableBindings,
|
|
218
|
+
V as useVariableCollections,
|
|
219
|
+
I as useVariableModes,
|
|
220
|
+
A as useVariables,
|
|
221
|
+
G as validateToken
|
|
222
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(t,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],s):(t=typeof globalThis<"u"?globalThis:t||self,s(t.FigmaVarsHooks={},t.react))})(this,function(t,s){"use strict";var N=Object.defineProperty;var G=(t,s,c)=>s in t?N(t,s,{enumerable:!0,configurable:!0,writable:!0,value:c}):t[s]=c;var w=(t,s,c)=>G(t,typeof s!="symbol"?s+"":s,c);const c=()=>{const[a,e]=s.useState("");return s.useEffect(()=>{e("")},[]),a},g=(a,e)=>{const[n,r]=s.useState(null),[o,i]=s.useState(!0),[l,u]=s.useState(null),h=c(),b=s.useRef(null),f=s.useCallback(async()=>{if(!h){u(new Error("API token is not provided")),i(!1);return}i(!0),u(null);try{const d=`https://api.figma.com/v1/files/${a}/variables`,m=await fetch(d,{method:"GET",headers:{"X-FIGMA-TOKEN":h}});if(!m.ok)throw new Error(`Failed to fetch Figma variables: ${m.statusText}`);const $=await m.json();r($.meta.variables)}catch(d){u(d instanceof Error?d:new Error("Failed to fetch variables"))}finally{i(!1)}},[a,h]),O=s.useCallback(()=>{f()},[f]);return s.useEffect(()=>{if(f(),e!=null&&e.pollInterval)return b.current=setInterval(f,e.pollInterval),()=>{b.current&&clearInterval(b.current)}},[f,e==null?void 0:e.pollInterval]),{variables:n,loading:o,error:l,refresh:O}},v=a=>{const[e,n]=s.useState({data:null,loading:!0,error:null}),r=c();return s.useEffect(()=>{(async()=>{if(!r){n(l=>({...l,loading:!1,error:new Error("API token is not provided")}));return}const i=`https://api.figma.com/v1/files/${a}/variable_collections`;try{const l=await fetch(i,{headers:{"X-FIGMA-TOKEN":r}});if(!l.ok)throw new Error(`Failed to fetch Figma collections: ${l.statusText}`);const u=await l.json();n({data:u.meta.variableCollections,loading:!1,error:null})}catch(l){n(u=>({...u,loading:!1,error:l instanceof Error?l:new Error("Failed to fetch")}))}})()},[a,r]),e},E=a=>{const[e,n]=s.useState(null),r=c();return s.useEffect(()=>{(async()=>{const i=`https://api.figma.com/v1/collections/${a}/modes`;try{if(!(await fetch(i,{headers:{"X-FIGMA-TOKEN":r}})).ok)throw new Error("Failed to fetch Figma modes");n({success:!0,message:"Modes fetched successfully"})}catch(l){n({success:!1,message:l instanceof Error?l.message:"Unknown error"})}})()},[a,r]),{response:e}};async function k(a,e){const n=c();if(!n)throw new Error("API token is not provided");const r=`https://api.figma.com/v1/files/${a}/variables`,o=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":n},body:JSON.stringify(e)});if(!o.ok)throw new Error("Failed to create Figma variable");return o.json()}async function V(a,e,n){const r=c();if(!r)throw new Error("API token is not provided");const o=`https://api.figma.com/v1/files/${a}/variables/${e}`,i=await fetch(o,{method:"PUT",headers:{"Content-Type":"application/json","X-FIGMA-TOKEN":r},body:JSON.stringify(n)});if(!i.ok)throw new Error("Failed to update Figma variable");return i.json()}async function p(a,e){const n=c();if(!n)throw new Error("API token is not provided");const r=`https://api.figma.com/v1/files/${a}/variables/${e}`,o=await fetch(r,{method:"DELETE",headers:{"X-FIGMA-TOKEN":n}});if(!o.ok)throw new Error("Failed to delete Figma variable");return o.json()}async function T(a,e){const n=c();if(!n)throw new Error("API token is not provided");const r=`https://api.figma.com/v1/variables/${a}/values`,o=await fetch(r,{method:"PUT",headers:{"X-FIGMA-TOKEN":n,"Content-Type":"application/json"},body:JSON.stringify(e)});if(!o.ok)throw new Error("Failed to update variable values");return o.json()}function y(a,e){return a.filter(n=>{let r=!0;return e.type&&(r=r&&n.type===e.type),e.name&&(r=r&&n.name===e.name),r})}class F{constructor(){w(this,"cache",{})}get(e){return this.cache[e]}set(e,n){this.cache[e]=n}clear(e){e?delete this.cache[e]:this.cache={}}}const A=()=>null,I=()=>!0,S=async(a,e={method:"GET"})=>{throw new Error("Figma API token is not available.")},M=()=>{const[a,e]=s.useState({});return{aliases:a,setAlias:(o,i)=>e(l=>({...l,[o]:i})),removeAlias:o=>{const i={...a};delete i[o],e(i)}}},P=()=>{const[a,e]=s.useState(new Map);return{bindings:a,bindVariable:(o,i)=>e(new Map(a.set(o,i))),unbindVariable:o=>{const i=new Map(a);i.delete(o),e(i)}}},j=()=>({}),C=()=>({});t.VariablesCache=F,t.createVariable=k,t.deleteVariable=p,t.fetchWithAuth=S,t.filterVariables=y,t.getFigmaToken=A,t.updateVariable=V,t.updateVariableValues=T,t.useFigmaToken=c,t.usePublishVars=j,t.useSync=C,t.useVariableAliases=M,t.useVariableBindings=P,t.useVariableCollections=v,t.useVariableModes=E,t.useVariables=g,t.validateToken=I,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FigmaVariable } from 'types';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches Figma variables for a given document (file) ID.
|
|
4
|
+
* Supports polling and manual refresh.
|
|
5
|
+
* @param documentId - The Figma file ID
|
|
6
|
+
* @param options - { pollInterval?: number }
|
|
7
|
+
*/
|
|
8
|
+
declare const useVariables: (documentId: string, options?: {
|
|
9
|
+
pollInterval?: number;
|
|
10
|
+
}) => {
|
|
11
|
+
variables: FigmaVariable[] | null;
|
|
12
|
+
loading: boolean;
|
|
13
|
+
error: Error | null;
|
|
14
|
+
refresh: () => void;
|
|
15
|
+
};
|
|
16
|
+
export default useVariables;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { default as useFigmaToken } from './hooks/useFigmaToken';
|
|
2
|
+
export { default as useVariables } from './hooks/useVariables';
|
|
3
|
+
export { default as useVariableCollections } from './hooks/useVariableCollections';
|
|
4
|
+
export { default as useVariableModes } from 'hooks/useVariableModes';
|
|
5
|
+
export * from 'mutations/createVariable';
|
|
6
|
+
export * from 'mutations/updateVariable';
|
|
7
|
+
export * from 'mutations/deleteVariable';
|
|
8
|
+
export * from 'mutations/updateVariableValues';
|
|
9
|
+
export * from 'utils/filterVariables';
|
|
10
|
+
export * from 'utils/cache';
|
|
11
|
+
export * from 'utils/fetchHelpers';
|
|
12
|
+
export * from 'utils/authHelpers';
|
|
13
|
+
export { default as useVariableAliases } from 'experimental/useVariableAliases';
|
|
14
|
+
export { default as useVariableBindings } from 'experimental/useVariableBindings';
|
|
15
|
+
export { default as usePublishVars } from 'experimental/usePublishVars';
|
|
16
|
+
export { default as useSync } from 'experimental/useSync';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FigmaOperationResponse } from 'types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a new Figma variable in a file.
|
|
4
|
+
* @param fileKey The Figma file ID
|
|
5
|
+
* @param variableData The variable data (see Figma Variables API)
|
|
6
|
+
* @returns Promise<FigmaOperationResponse>
|
|
7
|
+
*/
|
|
8
|
+
export declare function createVariable(fileKey: string, variableData: any): Promise<FigmaOperationResponse>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FigmaOperationResponse } from 'types';
|
|
2
|
+
/**
|
|
3
|
+
* Delete a Figma variable from a file.
|
|
4
|
+
* @param fileKey The Figma file ID
|
|
5
|
+
* @param variableId The variable ID
|
|
6
|
+
* @returns Promise<FigmaOperationResponse>
|
|
7
|
+
*/
|
|
8
|
+
export declare function deleteVariable(fileKey: string, variableId: string): Promise<FigmaOperationResponse>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FigmaOperationResponse } from 'types';
|
|
2
|
+
/**
|
|
3
|
+
* Update an existing Figma variable in a file.
|
|
4
|
+
* @param fileKey The Figma file ID
|
|
5
|
+
* @param variableId The variable ID
|
|
6
|
+
* @param newVariableData The new variable data (see Figma Variables API)
|
|
7
|
+
* @returns Promise<FigmaOperationResponse>
|
|
8
|
+
*/
|
|
9
|
+
export declare function updateVariable(fileKey: string, variableId: string, newVariableData: any): Promise<FigmaOperationResponse>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FigmaOperationResponse } from 'types';
|
|
2
|
+
/**
|
|
3
|
+
* Update a variable's value across modes (Figma Variables API).
|
|
4
|
+
* @param variableId The variable ID
|
|
5
|
+
* @param values The new values for each mode
|
|
6
|
+
* @returns Promise<FigmaOperationResponse>
|
|
7
|
+
*/
|
|
8
|
+
export declare function updateVariableValues(variableId: string, values: any): Promise<FigmaOperationResponse>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface FigmaVariable {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FigmaCollection {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
variables: FigmaVariable[];
|
|
11
|
+
}
|
|
12
|
+
export interface VariablesResponse {
|
|
13
|
+
meta: {
|
|
14
|
+
variables: FigmaVariable[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface FigmaError {
|
|
18
|
+
statusCode: number;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves the Figma API token from environment variables or any other secure storage mechanism you've implemented.
|
|
3
|
+
*/
|
|
4
|
+
export declare const getFigmaToken: () => string | null;
|
|
5
|
+
/**
|
|
6
|
+
* Placeholder for a more complex token validation or renewal logic, if needed.
|
|
7
|
+
*/
|
|
8
|
+
export declare const validateToken: () => boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface FetchOptions {
|
|
2
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
+
body?: BodyInit | null;
|
|
4
|
+
headers?: HeadersInit;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A helper function for making authenticated fetch requests to the Figma API.
|
|
8
|
+
*/
|
|
9
|
+
export declare const fetchWithAuth: (endpoint: string, options?: FetchOptions) => Promise<any>;
|
|
10
|
+
export {};
|