@figma-vars/hooks 2.0.0-beta.3 → 3.0.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.
- package/README.md +355 -220
- package/dist/api/fetcher.d.ts.map +1 -1
- package/dist/api/mutator.d.ts +10 -9
- package/dist/api/mutator.d.ts.map +1 -1
- package/dist/constants/index.d.ts +2 -28
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/contexts/FigmaVarsProvider.d.ts +1 -1
- package/dist/contexts/FigmaVarsProvider.d.ts.map +1 -1
- package/dist/core/index.d.cts +8 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core.cjs +1 -0
- package/dist/core.d.cts +2 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.mjs +20 -0
- package/dist/hooks/index.d.ts +19 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
- package/dist/hooks/useCreateVariable.d.ts.map +1 -1
- package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
- package/dist/hooks/useInvalidateVariables.d.ts +31 -0
- package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
- package/dist/hooks/usePublishedVariables.d.ts +42 -0
- package/dist/hooks/usePublishedVariables.d.ts.map +1 -0
- package/dist/hooks/useUpdateVariable.d.ts.map +1 -1
- package/dist/hooks/useVariables.d.ts.map +1 -1
- package/dist/index-BIUpDTdr.cjs +1 -0
- package/dist/index-Cd4HQQHO.js +94 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +229 -165
- package/dist/types/contexts.d.ts +29 -3
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/figma.d.ts +53 -0
- package/dist/types/figma.d.ts.map +1 -1
- package/dist/types/mutations.d.ts +1 -1
- package/dist/types/mutations.d.ts.map +1 -1
- package/dist/utils/errorHelpers.d.ts +96 -0
- package/dist/utils/errorHelpers.d.ts.map +1 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +67 -32
- package/scripts/export-variables.mjs +101 -0
- package/dist/index.d.mts +0 -2
package/dist/index.mjs
CHANGED
|
@@ -1,210 +1,274 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { jsx as K } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as L, useMemo as m, useContext as T, useReducer as V, useRef as w, useEffect as k, useCallback as _ } from "react";
|
|
3
|
+
import A, { useSWRConfig as S } from "swr";
|
|
4
|
+
import { f as I, E as v, a as p, m as E, F as b, b as h, c as P } from "./index-Cd4HQQHO.js";
|
|
5
|
+
import { d as te } from "./index-Cd4HQQHO.js";
|
|
6
|
+
const g = L(void 0);
|
|
7
|
+
let R = 0;
|
|
8
|
+
const G = ({
|
|
9
|
+
children: e,
|
|
10
|
+
token: t,
|
|
11
|
+
fileKey: r,
|
|
12
|
+
fallbackFile: o,
|
|
13
|
+
swrConfig: n
|
|
9
14
|
}) => {
|
|
10
|
-
const s =
|
|
11
|
-
|
|
15
|
+
const s = m(() => (R += 1, `figma-vars-provider-${R}`), []), c = m(() => {
|
|
16
|
+
const a = {
|
|
17
|
+
token: t,
|
|
18
|
+
fileKey: r,
|
|
19
|
+
providerId: s,
|
|
20
|
+
...n !== void 0 && { swrConfig: n }
|
|
21
|
+
};
|
|
22
|
+
return o === void 0 ? a : { ...a, fallbackFile: o };
|
|
23
|
+
}, [t, r, o, s, n]);
|
|
24
|
+
return /* @__PURE__ */ K(g.Provider, { value: c, children: e });
|
|
12
25
|
}, u = () => {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
26
|
+
const e = T(g);
|
|
27
|
+
if (e === void 0)
|
|
15
28
|
throw new Error(
|
|
16
29
|
"useFigmaTokenContext must be used within a FigmaVarsProvider"
|
|
17
30
|
);
|
|
18
|
-
return
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
const s = await e.json();
|
|
34
|
-
s != null && s.message && (r = s.message);
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
throw new Error(r);
|
|
38
|
-
}
|
|
39
|
-
return e.json();
|
|
40
|
-
}
|
|
41
|
-
const y = () => {
|
|
42
|
-
const { token: t, fileKey: o, fallbackFile: e } = u(), r = async (n, a) => e ? typeof e == "string" ? JSON.parse(e) : e : F(n, a), s = t && o ? `https://api.figma.com/v1/files/${o}/variables/local` : null;
|
|
43
|
-
return b(
|
|
44
|
-
s && t || e ? [s || "fallback", t || "fallback"] : null,
|
|
45
|
-
s && t || e ? ([n, a]) => r(n, a) : () => Promise.resolve(void 0)
|
|
31
|
+
return e;
|
|
32
|
+
}, C = () => {
|
|
33
|
+
const { token: e, fileKey: t, fallbackFile: r, providerId: o, swrConfig: n } = u(), s = t ? `https://api.figma.com/v1/files/${t}/variables/local` : null, l = !!(e && s) ? [s, e] : !!r ? [`fallback-${o ?? "default"}`, "fallback"] : null;
|
|
34
|
+
return A(
|
|
35
|
+
l,
|
|
36
|
+
async (...i) => {
|
|
37
|
+
const [f, d] = Array.isArray(i[0]) ? i[0] : [i[0], i[1]];
|
|
38
|
+
if (r)
|
|
39
|
+
return typeof r == "string" ? JSON.parse(r) : r;
|
|
40
|
+
if (!f || !d)
|
|
41
|
+
throw new Error("Missing URL or token for live API request");
|
|
42
|
+
return I(f, d);
|
|
43
|
+
},
|
|
44
|
+
n
|
|
46
45
|
);
|
|
47
|
-
},
|
|
48
|
-
const { data:
|
|
49
|
-
() =>
|
|
50
|
-
[
|
|
51
|
-
),
|
|
52
|
-
() =>
|
|
53
|
-
[
|
|
46
|
+
}, N = () => {
|
|
47
|
+
const { data: e } = C(), t = m(
|
|
48
|
+
() => e != null && e.meta ? Object.values(e.meta.variableCollections) : [],
|
|
49
|
+
[e]
|
|
50
|
+
), r = m(
|
|
51
|
+
() => e != null && e.meta ? e.meta.variableCollections : {},
|
|
52
|
+
[e]
|
|
54
53
|
);
|
|
55
54
|
return {
|
|
56
|
-
collections:
|
|
57
|
-
collectionsById:
|
|
55
|
+
collections: t,
|
|
56
|
+
collectionsById: r
|
|
58
57
|
};
|
|
59
|
-
},
|
|
60
|
-
const { data:
|
|
61
|
-
return
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
for (const
|
|
65
|
-
|
|
58
|
+
}, j = () => {
|
|
59
|
+
const { data: e } = C();
|
|
60
|
+
return m(() => {
|
|
61
|
+
const t = [], r = {}, o = {};
|
|
62
|
+
if (e != null && e.meta)
|
|
63
|
+
for (const n of Object.values(
|
|
64
|
+
e.meta.variableCollections
|
|
66
65
|
)) {
|
|
67
|
-
|
|
68
|
-
for (const
|
|
69
|
-
|
|
66
|
+
t.push(...n.modes), r[n.id] = n.modes;
|
|
67
|
+
for (const s of n.modes)
|
|
68
|
+
o[s.modeId] = s;
|
|
70
69
|
}
|
|
71
70
|
return {
|
|
72
|
-
modes:
|
|
73
|
-
modesByCollectionId:
|
|
74
|
-
modesById:
|
|
71
|
+
modes: t,
|
|
72
|
+
modesByCollectionId: r,
|
|
73
|
+
modesById: o
|
|
75
74
|
};
|
|
76
|
-
}, [
|
|
75
|
+
}, [e]);
|
|
77
76
|
};
|
|
78
|
-
function
|
|
79
|
-
switch (
|
|
77
|
+
function B(e, t) {
|
|
78
|
+
switch (t.type) {
|
|
80
79
|
case "loading":
|
|
81
|
-
return { ...
|
|
80
|
+
return { ...e, status: "loading", error: null };
|
|
82
81
|
case "success":
|
|
83
|
-
return { ...
|
|
82
|
+
return { ...e, status: "success", data: t.payload };
|
|
84
83
|
case "error":
|
|
85
|
-
return { ...
|
|
84
|
+
return { ...e, status: "error", error: t.payload };
|
|
86
85
|
default:
|
|
87
|
-
return
|
|
86
|
+
return e;
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
|
-
const
|
|
91
|
-
const
|
|
89
|
+
const y = (e) => {
|
|
90
|
+
const t = {
|
|
92
91
|
status: "idle",
|
|
93
92
|
data: null,
|
|
94
93
|
error: null
|
|
95
|
-
}, [
|
|
96
|
-
return {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
}, [r, o] = V(B, t), n = w(e), s = w(!0);
|
|
95
|
+
return k(() => {
|
|
96
|
+
n.current = e;
|
|
97
|
+
}, [e]), k(() => (s.current = !0, () => {
|
|
98
|
+
s.current = !1;
|
|
99
|
+
}), []), {
|
|
100
|
+
mutate: _(
|
|
101
|
+
async (a) => {
|
|
102
|
+
if (s.current) {
|
|
103
|
+
o({ type: "loading" });
|
|
104
|
+
try {
|
|
105
|
+
const l = await n.current(a);
|
|
106
|
+
return s.current && o({ type: "success", payload: l }), l;
|
|
107
|
+
} catch (l) {
|
|
108
|
+
s.current && o({ type: "error", payload: l });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
106
111
|
}
|
|
107
112
|
},
|
|
108
|
-
[
|
|
113
|
+
[]
|
|
114
|
+
// Empty deps array - mutationFn is accessed via ref
|
|
109
115
|
),
|
|
110
|
-
...
|
|
111
|
-
isLoading:
|
|
112
|
-
isSuccess:
|
|
113
|
-
isError:
|
|
116
|
+
...r,
|
|
117
|
+
isLoading: r.status === "loading",
|
|
118
|
+
isSuccess: r.status === "success",
|
|
119
|
+
isError: r.status === "error"
|
|
114
120
|
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
method: {
|
|
121
|
-
CREATE: "POST",
|
|
122
|
-
UPDATE: "PUT",
|
|
123
|
-
DELETE: "DELETE"
|
|
124
|
-
}[e],
|
|
125
|
-
headers: {
|
|
126
|
-
"Content-Type": "application/json",
|
|
127
|
-
[T]: o
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
r && (n.body = JSON.stringify(r));
|
|
131
|
-
const a = await fetch(`${p}${t}`, n);
|
|
132
|
-
if (!a.ok) {
|
|
133
|
-
const E = await a.json().catch(() => ({}));
|
|
134
|
-
throw new Error(
|
|
135
|
-
E.err || E.message || "An API error occurred"
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
return a.status === 204 || !a.body ? {} : a.json();
|
|
139
|
-
}
|
|
140
|
-
const B = () => {
|
|
141
|
-
const { token: t } = u();
|
|
142
|
-
return l(async (e) => {
|
|
121
|
+
}, H = () => {
|
|
122
|
+
const { token: e, fileKey: t } = u();
|
|
123
|
+
return y(async (o) => {
|
|
124
|
+
if (!e)
|
|
125
|
+
throw new Error(v);
|
|
143
126
|
if (!t)
|
|
144
|
-
throw new Error(
|
|
145
|
-
return await
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
127
|
+
throw new Error(p);
|
|
128
|
+
return await E(b(t), e, "CREATE", {
|
|
129
|
+
variables: [
|
|
130
|
+
{
|
|
131
|
+
action: "CREATE",
|
|
132
|
+
...o
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
});
|
|
151
136
|
});
|
|
152
|
-
},
|
|
153
|
-
const { token: t } = u();
|
|
154
|
-
return
|
|
137
|
+
}, q = () => {
|
|
138
|
+
const { token: e, fileKey: t } = u();
|
|
139
|
+
return y(
|
|
155
140
|
async ({
|
|
156
|
-
variableId:
|
|
157
|
-
payload:
|
|
141
|
+
variableId: o,
|
|
142
|
+
payload: n
|
|
158
143
|
}) => {
|
|
144
|
+
if (!e)
|
|
145
|
+
throw new Error(v);
|
|
159
146
|
if (!t)
|
|
160
|
-
throw new Error(
|
|
161
|
-
return await
|
|
162
|
-
|
|
163
|
-
|
|
147
|
+
throw new Error(p);
|
|
148
|
+
return await E(
|
|
149
|
+
b(t),
|
|
150
|
+
e,
|
|
164
151
|
"UPDATE",
|
|
165
|
-
|
|
152
|
+
{
|
|
153
|
+
variables: [
|
|
154
|
+
{
|
|
155
|
+
action: "UPDATE",
|
|
156
|
+
id: o,
|
|
157
|
+
...n
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
166
161
|
);
|
|
167
162
|
}
|
|
168
163
|
);
|
|
169
|
-
},
|
|
170
|
-
const { token: t } = u();
|
|
171
|
-
return
|
|
164
|
+
}, J = () => {
|
|
165
|
+
const { token: e, fileKey: t } = u();
|
|
166
|
+
return y(async (o) => {
|
|
167
|
+
if (!e)
|
|
168
|
+
throw new Error(v);
|
|
172
169
|
if (!t)
|
|
173
|
-
throw new Error(
|
|
174
|
-
return await
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
170
|
+
throw new Error(p);
|
|
171
|
+
return await E(b(t), e, "DELETE", {
|
|
172
|
+
variables: [
|
|
173
|
+
{
|
|
174
|
+
action: "DELETE",
|
|
175
|
+
id: o
|
|
176
|
+
}
|
|
177
|
+
]
|
|
178
|
+
});
|
|
180
179
|
});
|
|
181
|
-
},
|
|
182
|
-
const { token: t } = u();
|
|
183
|
-
return
|
|
180
|
+
}, Q = () => {
|
|
181
|
+
const { token: e, fileKey: t } = u();
|
|
182
|
+
return y(async (o) => {
|
|
183
|
+
if (!e)
|
|
184
|
+
throw new Error(v);
|
|
184
185
|
if (!t)
|
|
185
|
-
throw new Error(
|
|
186
|
-
return await
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"
|
|
190
|
-
|
|
186
|
+
throw new Error(p);
|
|
187
|
+
return await E(
|
|
188
|
+
b(t),
|
|
189
|
+
e,
|
|
190
|
+
"UPDATE",
|
|
191
|
+
o
|
|
191
192
|
);
|
|
192
193
|
});
|
|
194
|
+
}, W = () => {
|
|
195
|
+
const { mutate: e } = S(), { fileKey: t, providerId: r } = u();
|
|
196
|
+
return {
|
|
197
|
+
invalidate: () => {
|
|
198
|
+
if (!t) return;
|
|
199
|
+
const s = [
|
|
200
|
+
`https://api.figma.com/v1/files/${t}/variables/local`,
|
|
201
|
+
"token-placeholder"
|
|
202
|
+
];
|
|
203
|
+
e(s);
|
|
204
|
+
const c = [
|
|
205
|
+
h(t),
|
|
206
|
+
"token-placeholder"
|
|
207
|
+
];
|
|
208
|
+
if (e(c), r) {
|
|
209
|
+
const a = [`fallback-${r}`, "fallback"];
|
|
210
|
+
e(a);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
revalidate: () => {
|
|
214
|
+
if (!t) return;
|
|
215
|
+
const s = [
|
|
216
|
+
`https://api.figma.com/v1/files/${t}/variables/local`,
|
|
217
|
+
"token-placeholder"
|
|
218
|
+
];
|
|
219
|
+
e(s, void 0, { revalidate: !0 });
|
|
220
|
+
const c = [
|
|
221
|
+
h(t),
|
|
222
|
+
"token-placeholder"
|
|
223
|
+
];
|
|
224
|
+
if (e(c, void 0, { revalidate: !0 }), r) {
|
|
225
|
+
const a = [`fallback-${r}`, "fallback"];
|
|
226
|
+
e(a, void 0, { revalidate: !0 });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
}, Y = () => {
|
|
231
|
+
const { token: e, fileKey: t, fallbackFile: r, providerId: o, swrConfig: n } = u(), s = t ? h(t) : null, l = !!(e && s) ? [s, e] : !!r ? [`fallback-${o ?? "default"}`, "fallback"] : null;
|
|
232
|
+
return A(
|
|
233
|
+
l,
|
|
234
|
+
async (...i) => {
|
|
235
|
+
const [f, d] = Array.isArray(i[0]) ? i[0] : [i[0], i[1]];
|
|
236
|
+
if (r)
|
|
237
|
+
return typeof r == "string" ? JSON.parse(r) : r;
|
|
238
|
+
if (!f || !d)
|
|
239
|
+
throw new Error("Missing URL or token for live API request");
|
|
240
|
+
return I(f, d);
|
|
241
|
+
},
|
|
242
|
+
n
|
|
243
|
+
);
|
|
193
244
|
};
|
|
194
|
-
function
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
245
|
+
function M(e) {
|
|
246
|
+
return e instanceof P;
|
|
247
|
+
}
|
|
248
|
+
function U(e) {
|
|
249
|
+
return M(e) ? e.statusCode : null;
|
|
250
|
+
}
|
|
251
|
+
function z(e, t = "An error occurred") {
|
|
252
|
+
return e instanceof Error ? e.message || t : typeof e == "string" ? e : t;
|
|
253
|
+
}
|
|
254
|
+
function X(e, t) {
|
|
255
|
+
return U(e) === t;
|
|
199
256
|
}
|
|
200
257
|
export {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
258
|
+
P as FigmaApiError,
|
|
259
|
+
G as FigmaVarsProvider,
|
|
260
|
+
te as filterVariables,
|
|
261
|
+
z as getErrorMessage,
|
|
262
|
+
U as getErrorStatus,
|
|
263
|
+
X as hasErrorStatus,
|
|
264
|
+
M as isFigmaApiError,
|
|
265
|
+
Q as useBulkUpdateVariables,
|
|
266
|
+
H as useCreateVariable,
|
|
267
|
+
J as useDeleteVariable,
|
|
268
|
+
W as useInvalidateVariables,
|
|
269
|
+
Y as usePublishedVariables,
|
|
270
|
+
q as useUpdateVariable,
|
|
271
|
+
N as useVariableCollections,
|
|
272
|
+
j as useVariableModes,
|
|
273
|
+
C as useVariables
|
|
210
274
|
};
|
package/dist/types/contexts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SWRConfiguration } from 'swr';
|
|
3
|
+
import { LocalVariablesResponse, PublishedVariablesResponse } from 'types';
|
|
3
4
|
/**
|
|
4
5
|
* Central context shape for FigmaVars—provides authentication and file context to all hooks and consumers in the tree.
|
|
5
6
|
*
|
|
@@ -41,7 +42,12 @@ export interface FigmaTokenContextType {
|
|
|
41
42
|
* Optional fallback variable JSON file for offline or static use cases.
|
|
42
43
|
* Allows FigmaVars to function without a live API request.
|
|
43
44
|
*/
|
|
44
|
-
fallbackFile?: LocalVariablesResponse | string;
|
|
45
|
+
fallbackFile?: LocalVariablesResponse | PublishedVariablesResponse | string;
|
|
46
|
+
/**
|
|
47
|
+
* Optional SWR configuration to customize caching, revalidation, and error handling behavior.
|
|
48
|
+
* Applied to all SWR hooks within this provider.
|
|
49
|
+
*/
|
|
50
|
+
swrConfig?: SWRConfiguration | undefined;
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
53
|
* Props for the FigmaVarsProvider component, which injects Figma API authentication and file scoping for all descendant hooks and utilities.
|
|
@@ -83,6 +89,26 @@ export interface FigmaVarsProviderProps {
|
|
|
83
89
|
/**
|
|
84
90
|
* Optional fallback variable JSON file used when the API is unavailable or skipped.
|
|
85
91
|
*/
|
|
86
|
-
fallbackFile?: LocalVariablesResponse | string;
|
|
92
|
+
fallbackFile?: LocalVariablesResponse | PublishedVariablesResponse | string;
|
|
93
|
+
/**
|
|
94
|
+
* Optional SWR configuration to customize caching, revalidation, and error handling.
|
|
95
|
+
* Common options: `revalidateOnFocus`, `dedupingInterval`, `errorRetryCount`, `onError`, etc.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <FigmaVarsProvider
|
|
100
|
+
* token={token}
|
|
101
|
+
* fileKey={fileKey}
|
|
102
|
+
* swrConfig={{
|
|
103
|
+
* revalidateOnFocus: false,
|
|
104
|
+
* dedupingInterval: 5000,
|
|
105
|
+
* errorRetryCount: 3,
|
|
106
|
+
* }}
|
|
107
|
+
* >
|
|
108
|
+
* <App />
|
|
109
|
+
* </FigmaVarsProvider>
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
swrConfig?: SWRConfiguration;
|
|
87
113
|
}
|
|
88
114
|
//# sourceMappingURL=contexts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/types/contexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"contexts.d.ts","sourceRoot":"","sources":["../../src/types/contexts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,OAAO,CAAA;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,sBAAsB,GAAG,0BAA0B,GAAG,MAAM,CAAA;IAM3E;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB;;OAEG;IACH,YAAY,CAAC,EAAE,sBAAsB,GAAG,0BAA0B,GAAG,MAAM,CAAA;IAC3E;;;;;;;;;;;;;;;;;;OAkBG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAC7B"}
|
package/dist/types/figma.d.ts
CHANGED
|
@@ -216,6 +216,28 @@ export interface LocalVariablesResponse {
|
|
|
216
216
|
variables: Record<string, FigmaVariable>;
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
+
export interface PublishedVariable {
|
|
220
|
+
id: string;
|
|
221
|
+
subscribed_id: string;
|
|
222
|
+
name: string;
|
|
223
|
+
key: string;
|
|
224
|
+
variableCollectionId: string;
|
|
225
|
+
resolvedType: ResolvedType;
|
|
226
|
+
updatedAt: string;
|
|
227
|
+
}
|
|
228
|
+
export interface PublishedVariableCollection {
|
|
229
|
+
id: string;
|
|
230
|
+
subscribed_id: string;
|
|
231
|
+
name: string;
|
|
232
|
+
key: string;
|
|
233
|
+
updatedAt: string;
|
|
234
|
+
}
|
|
235
|
+
export interface PublishedVariablesResponse {
|
|
236
|
+
meta: {
|
|
237
|
+
variableCollections: Record<string, PublishedVariableCollection>;
|
|
238
|
+
variables: Record<string, PublishedVariable>;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
219
241
|
/**
|
|
220
242
|
* Standard error response shape for Figma API error objects.
|
|
221
243
|
*
|
|
@@ -242,4 +264,35 @@ export interface FigmaError {
|
|
|
242
264
|
/** Human-readable error message describing the failure. */
|
|
243
265
|
message: string;
|
|
244
266
|
}
|
|
267
|
+
/**
|
|
268
|
+
* Custom Error class for Figma API errors that preserves HTTP status codes.
|
|
269
|
+
*
|
|
270
|
+
* @remarks
|
|
271
|
+
* Extends the standard Error class to include HTTP status code information,
|
|
272
|
+
* making it easier for consumers to handle different error types (401, 403, 404, 429, etc.).
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* import { FigmaApiError } from '@figma-vars/hooks';
|
|
277
|
+
*
|
|
278
|
+
* try {
|
|
279
|
+
* await fetcher(url, token);
|
|
280
|
+
* } catch (error) {
|
|
281
|
+
* if (error instanceof FigmaApiError) {
|
|
282
|
+
* if (error.statusCode === 401) {
|
|
283
|
+
* // Handle authentication error
|
|
284
|
+
* } else if (error.statusCode === 429) {
|
|
285
|
+
* // Handle rate limit
|
|
286
|
+
* }
|
|
287
|
+
* }
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* @public
|
|
292
|
+
*/
|
|
293
|
+
export declare class FigmaApiError extends Error {
|
|
294
|
+
/** HTTP status code from the API response. */
|
|
295
|
+
readonly statusCode: number;
|
|
296
|
+
constructor(message: string, statusCode: number);
|
|
297
|
+
}
|
|
245
298
|
//# sourceMappingURL=figma.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"figma.d.ts","sourceRoot":"","sources":["../../src/types/figma.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEnE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,cAAc,GACd,eAAe,GACf,cAAc,GACd,KAAK,GACL,cAAc,GACd,SAAS,GACT,cAAc,GACd,aAAa,GACb,WAAW,GACX,aAAa,GACb,gBAAgB,GAChB,mBAAmB,GACnB,kBAAkB,GAClB,aAAa,GACb,YAAY,GACZ,iBAAiB,GACjB,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,cAAc,GACd,cAAc,CAAA;AAElB;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,KAAK;IACpB,uBAAuB;IACvB,CAAC,EAAE,MAAM,CAAA;IACT,yBAAyB;IACzB,CAAC,EAAE,MAAM,CAAA;IACT,wBAAwB;IACxB,CAAC,EAAE,MAAM,CAAA;IACT,mCAAmC;IACnC,CAAC,EAAE,MAAM,CAAA;CACV;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,IAAI,EAAE,gBAAgB,CAAA;IACtB,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAA;CACX;AAED;;;;;;;;GAQ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,EAAE,MAAM,CAAA;IAC5B,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAA;IACV,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE;QACJ,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAA;QAChE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAA;KAC7C,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,UAAU;IACzB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,8CAA8C;IAC9C,SAAgB,UAAU,EAAE,MAAM,CAAA;gBAEtB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAShD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/types/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/types/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ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