@figma-vars/hooks 3.0.0-beta.1 → 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.
Files changed (58) hide show
  1. package/README.md +371 -177
  2. package/dist/api/fetcher.d.ts.map +1 -1
  3. package/dist/api/index.d.ts.map +1 -1
  4. package/dist/api/mutator.d.ts +10 -9
  5. package/dist/api/mutator.d.ts.map +1 -1
  6. package/dist/constants/index.d.ts +2 -28
  7. package/dist/constants/index.d.ts.map +1 -1
  8. package/dist/contexts/FigmaTokenContext.d.ts.map +1 -1
  9. package/dist/contexts/FigmaVarsProvider.d.ts +1 -1
  10. package/dist/contexts/FigmaVarsProvider.d.ts.map +1 -1
  11. package/dist/contexts/index.d.ts +1 -1
  12. package/dist/contexts/index.d.ts.map +1 -1
  13. package/dist/contexts/useFigmaTokenContext.d.ts.map +1 -1
  14. package/dist/core/index.d.cts +8 -0
  15. package/dist/core/index.d.ts +8 -0
  16. package/dist/core/index.d.ts.map +1 -0
  17. package/dist/core.cjs +1 -0
  18. package/dist/core.d.cts +2 -0
  19. package/dist/core.d.ts +2 -0
  20. package/dist/core.mjs +20 -0
  21. package/dist/hooks/index.d.ts +19 -0
  22. package/dist/hooks/index.d.ts.map +1 -1
  23. package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
  24. package/dist/hooks/useCreateVariable.d.ts.map +1 -1
  25. package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
  26. package/dist/hooks/useFigmaToken.d.ts.map +1 -1
  27. package/dist/hooks/useInvalidateVariables.d.ts +31 -0
  28. package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
  29. package/dist/hooks/usePublishedVariables.d.ts +42 -0
  30. package/dist/hooks/usePublishedVariables.d.ts.map +1 -0
  31. package/dist/hooks/useUpdateVariable.d.ts.map +1 -1
  32. package/dist/hooks/useVariableCollections.d.ts.map +1 -1
  33. package/dist/hooks/useVariableModes.d.ts.map +1 -1
  34. package/dist/hooks/useVariables.d.ts +3 -1
  35. package/dist/hooks/useVariables.d.ts.map +1 -1
  36. package/dist/index-BIUpDTdr.cjs +1 -0
  37. package/dist/index-Cd4HQQHO.js +94 -0
  38. package/dist/index.cjs +1 -1
  39. package/dist/index.d.cts +9 -4
  40. package/dist/index.d.ts +9 -4
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.mjs +235 -162
  43. package/dist/types/contexts.d.ts +29 -3
  44. package/dist/types/contexts.d.ts.map +1 -1
  45. package/dist/types/figma.d.ts +56 -3
  46. package/dist/types/figma.d.ts.map +1 -1
  47. package/dist/types/hooks.d.ts.map +1 -1
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/mutations.d.ts +4 -4
  50. package/dist/types/mutations.d.ts.map +1 -1
  51. package/dist/utils/errorHelpers.d.ts +96 -0
  52. package/dist/utils/errorHelpers.d.ts.map +1 -0
  53. package/dist/utils/filterVariables.d.ts.map +1 -1
  54. package/dist/utils/index.d.ts +2 -1
  55. package/dist/utils/index.d.ts.map +1 -1
  56. package/package.json +75 -31
  57. package/scripts/export-variables.mjs +101 -0
  58. package/dist/index.d.mts +0 -2
package/dist/index.mjs CHANGED
@@ -1,201 +1,274 @@
1
- import { jsx as _ } from "react/jsx-runtime";
2
- import { createContext as I, useContext as v, useMemo as d, useReducer as R, useCallback as g } from "react";
3
- import C from "swr";
4
- const f = I(void 0), N = ({
5
- children: t,
6
- token: o,
7
- fileKey: e,
8
- fallbackFile: r
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 = r === void 0 ? { token: o, fileKey: e } : { token: o, fileKey: e, fallbackFile: r };
11
- return /* @__PURE__ */ _(f.Provider, { value: s, children: t });
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 t = v(f);
14
- if (t === void 0)
15
- throw new Error("useFigmaTokenContext must be used within a FigmaVarsProvider");
16
- return t;
17
- }, p = "https://api.figma.com", h = `${p}/v1/variables`, w = h, A = (t) => `${h}/${t}`, b = "application/json", T = "X-FIGMA-TOKEN", c = "A Figma API token is required.", P = "An error occurred while fetching data from the Figma API.";
18
- async function M(t, o) {
19
- if (!o)
20
- throw new Error(c);
21
- const e = await fetch(t, {
22
- method: "GET",
23
- headers: {
24
- [T]: o,
25
- "Content-Type": b
26
- }
27
- });
28
- if (!e.ok) {
29
- let r = P;
30
- try {
31
- const s = await e.json();
32
- s != null && s.message && (r = s.message);
33
- } catch {
34
- }
35
- throw new Error(r);
36
- }
37
- return e.json();
38
- }
39
- const y = () => {
40
- const { token: t, fileKey: o } = u(), e = t && o ? `https://api.figma.com/v1/files/${o}/variables/local` : null;
41
- return C(
42
- e && t ? [e, t] : null,
43
- e && t ? ([s, n]) => M(s, n) : () => Promise.resolve(void 0)
26
+ const e = T(g);
27
+ if (e === void 0)
28
+ throw new Error(
29
+ "useFigmaTokenContext must be used within a FigmaVarsProvider"
30
+ );
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
44
45
  );
45
- }, S = () => {
46
- const { data: t } = y(), o = d(
47
- () => t != null && t.meta ? Object.values(t.meta.variableCollections) : [],
48
- [t]
49
- ), e = d(
50
- () => t != null && t.meta ? t.meta.variableCollections : {},
51
- [t]
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]
52
53
  );
53
54
  return {
54
- collections: o,
55
- collectionsById: e
55
+ collections: t,
56
+ collectionsById: r
56
57
  };
57
- }, B = () => {
58
- const { data: t } = y();
59
- return d(() => {
60
- const o = [], e = {}, r = {};
61
- if (t != null && t.meta)
62
- for (const s of Object.values(t.meta.variableCollections)) {
63
- o.push(...s.modes), e[s.id] = s.modes;
64
- for (const n of s.modes)
65
- r[n.modeId] = n;
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
65
+ )) {
66
+ t.push(...n.modes), r[n.id] = n.modes;
67
+ for (const s of n.modes)
68
+ o[s.modeId] = s;
66
69
  }
67
70
  return {
68
- modes: o,
69
- modesByCollectionId: e,
70
- modesById: r
71
+ modes: t,
72
+ modesByCollectionId: r,
73
+ modesById: o
71
74
  };
72
- }, [t]);
75
+ }, [e]);
73
76
  };
74
- function O(t, o) {
75
- switch (o.type) {
77
+ function B(e, t) {
78
+ switch (t.type) {
76
79
  case "loading":
77
- return { ...t, status: "loading", error: null };
80
+ return { ...e, status: "loading", error: null };
78
81
  case "success":
79
- return { ...t, status: "success", data: o.payload };
82
+ return { ...e, status: "success", data: t.payload };
80
83
  case "error":
81
- return { ...t, status: "error", error: o.payload };
84
+ return { ...e, status: "error", error: t.payload };
82
85
  default:
83
- return t;
86
+ return e;
84
87
  }
85
88
  }
86
- const l = (t) => {
87
- const o = {
89
+ const y = (e) => {
90
+ const t = {
88
91
  status: "idle",
89
92
  data: null,
90
93
  error: null
91
- }, [e, r] = R(O, o);
92
- return {
93
- mutate: g(
94
- async (n) => {
95
- r({ type: "loading" });
96
- try {
97
- const a = await t(n);
98
- return r({ type: "success", payload: a }), a;
99
- } catch (a) {
100
- r({ type: "error", payload: a });
101
- return;
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
+ }
102
111
  }
103
112
  },
104
- [t]
113
+ []
114
+ // Empty deps array - mutationFn is accessed via ref
105
115
  ),
106
- ...e,
107
- isLoading: e.status === "loading",
108
- isSuccess: e.status === "success",
109
- isError: e.status === "error"
110
- };
111
- };
112
- async function m(t, o, e, r) {
113
- if (!o)
114
- throw new Error(c);
115
- const a = {
116
- method: {
117
- CREATE: "POST",
118
- UPDATE: "PUT",
119
- DELETE: "DELETE"
120
- }[e],
121
- headers: {
122
- "Content-Type": "application/json",
123
- [T]: o
124
- }
116
+ ...r,
117
+ isLoading: r.status === "loading",
118
+ isSuccess: r.status === "success",
119
+ isError: r.status === "error"
125
120
  };
126
- r && (a.body = JSON.stringify(r));
127
- const i = await fetch(`${p}${t}`, a);
128
- if (!i.ok) {
129
- const E = await i.json().catch(() => ({}));
130
- throw new Error(E.err || E.message || "An API error occurred");
131
- }
132
- return i.status === 204 || !i.body ? {} : i.json();
133
- }
134
- const G = () => {
135
- const { token: t } = u();
136
- 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);
137
126
  if (!t)
138
- throw new Error(c);
139
- return await m(
140
- w,
141
- t,
142
- "CREATE",
143
- e
144
- );
127
+ throw new Error(p);
128
+ return await E(b(t), e, "CREATE", {
129
+ variables: [
130
+ {
131
+ action: "CREATE",
132
+ ...o
133
+ }
134
+ ]
135
+ });
145
136
  });
146
- }, j = () => {
147
- const { token: t } = u();
148
- return l(
149
- async ({ variableId: e, payload: r }) => {
137
+ }, q = () => {
138
+ const { token: e, fileKey: t } = u();
139
+ return y(
140
+ async ({
141
+ variableId: o,
142
+ payload: n
143
+ }) => {
144
+ if (!e)
145
+ throw new Error(v);
150
146
  if (!t)
151
- throw new Error(c);
152
- return await m(
153
- A(e),
154
- t,
147
+ throw new Error(p);
148
+ return await E(
149
+ b(t),
150
+ e,
155
151
  "UPDATE",
156
- r
152
+ {
153
+ variables: [
154
+ {
155
+ action: "UPDATE",
156
+ id: o,
157
+ ...n
158
+ }
159
+ ]
160
+ }
157
161
  );
158
162
  }
159
163
  );
160
- }, k = () => {
161
- const { token: t } = u();
162
- return l(async (e) => {
164
+ }, J = () => {
165
+ const { token: e, fileKey: t } = u();
166
+ return y(async (o) => {
167
+ if (!e)
168
+ throw new Error(v);
163
169
  if (!t)
164
- throw new Error(c);
165
- return await m(
166
- A(e),
167
- t,
168
- "DELETE",
169
- void 0
170
- );
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
+ });
171
179
  });
172
- }, L = () => {
173
- const { token: t } = u();
174
- return l(async (e) => {
180
+ }, Q = () => {
181
+ const { token: e, fileKey: t } = u();
182
+ return y(async (o) => {
183
+ if (!e)
184
+ throw new Error(v);
175
185
  if (!t)
176
- throw new Error(c);
177
- return await m(
178
- w,
179
- t,
180
- "CREATE",
181
- e
186
+ throw new Error(p);
187
+ return await E(
188
+ b(t),
189
+ e,
190
+ "UPDATE",
191
+ o
182
192
  );
183
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
+ );
184
244
  };
185
- function x(t, o) {
186
- return t.filter((e) => {
187
- let r = !0;
188
- return o.resolvedType && (r = r && e.resolvedType === o.resolvedType), o.name && (r = r && e.name.includes(o.name)), r;
189
- });
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;
190
256
  }
191
257
  export {
192
- N as FigmaVarsProvider,
193
- x as filterVariables,
194
- L as useBulkUpdateVariables,
195
- G as useCreateVariable,
196
- k as useDeleteVariable,
197
- j as useUpdateVariable,
198
- S as useVariableCollections,
199
- B as useVariableModes,
200
- y as useVariables
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
201
274
  };
@@ -1,5 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
- import { LocalVariablesResponse } from 'types';
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,CAAC;AACvC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAAC;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;;OAGG;IACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAAC;CAChD"}
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"}
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * @public
13
13
  */
14
- export type ResolvedType = "BOOLEAN" | "FLOAT" | "STRING" | "COLOR";
14
+ export type ResolvedType = 'BOOLEAN' | 'FLOAT' | 'STRING' | 'COLOR';
15
15
  /**
16
16
  * Enum of all valid Figma variable scopes.
17
17
  *
@@ -26,7 +26,7 @@ export type ResolvedType = "BOOLEAN" | "FLOAT" | "STRING" | "COLOR";
26
26
  *
27
27
  * @public
28
28
  */
29
- export type VariableScope = "ALL_SCOPES" | "TEXT_CONTENT" | "CORNER_RADIUS" | "WIDTH_HEIGHT" | "GAP" | "STROKE_FLOAT" | "OPACITY" | "EFFECT_FLOAT" | "FONT_WEIGHT" | "FONT_SIZE" | "LINE_HEIGHT" | "LETTER_SPACING" | "PARAGRAPH_SPACING" | "PARAGRAPH_INDENT" | "FONT_FAMILY" | "FONT_STYLE" | "FONT_VARIATIONS" | "ALL_FILLS" | "FRAME_FILL" | "SHAPE_FILL" | "TEXT_FILL" | "STROKE_COLOR" | "EFFECT_COLOR";
29
+ export type VariableScope = 'ALL_SCOPES' | 'TEXT_CONTENT' | 'CORNER_RADIUS' | 'WIDTH_HEIGHT' | 'GAP' | 'STROKE_FLOAT' | 'OPACITY' | 'EFFECT_FLOAT' | 'FONT_WEIGHT' | 'FONT_SIZE' | 'LINE_HEIGHT' | 'LETTER_SPACING' | 'PARAGRAPH_SPACING' | 'PARAGRAPH_INDENT' | 'FONT_FAMILY' | 'FONT_STYLE' | 'FONT_VARIATIONS' | 'ALL_FILLS' | 'FRAME_FILL' | 'SHAPE_FILL' | 'TEXT_FILL' | 'STROKE_COLOR' | 'EFFECT_COLOR';
30
30
  /**
31
31
  * RGBA color value used by Figma variables of type COLOR.
32
32
  *
@@ -66,7 +66,7 @@ export interface Color {
66
66
  */
67
67
  export interface VariableAlias {
68
68
  /** Type identifier for variable alias objects. Always 'VARIABLE_ALIAS'. */
69
- type: "VARIABLE_ALIAS";
69
+ type: 'VARIABLE_ALIAS';
70
70
  /** The referenced variable's Figma variable ID. */
71
71
  id: string;
72
72
  }
@@ -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,CAAC;AAEpE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GACrB,YAAY,GACZ,cAAc,GACd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AAA;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":"hooks.d.ts","sourceRoot":"","sources":["../../src/types/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,sEAAsE;IACtE,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IACpD,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACzC"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/types/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAA;IAClB,mEAAmE;IACnE,OAAO,EAAE,qBAAqB,CAAA;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,sBAAsB;IACrC,0DAA0D;IAC1D,KAAK,EAAE,YAAY,EAAE,CAAA;IACrB,sEAAsE;IACtE,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,CAAA;IACnD,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;CACxC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { ResolvedType, VariableScope, VariableValue } from './figma';
1
+ import { ResolvedType, VariableScope, VariableValue } from './figma.js';
2
2
  /**
3
3
  * Payload for creating a new Figma variable in a specific collection.
4
4
  *
@@ -80,7 +80,7 @@ export interface UpdateVariablePayload {
80
80
  *
81
81
  * @public
82
82
  */
83
- export type VariableAction = "CREATE" | "UPDATE" | "DELETE";
83
+ export type VariableAction = 'CREATE' | 'UPDATE' | 'DELETE';
84
84
  /**
85
85
  * Represents a change operation on a Figma variable collection.
86
86
  *
@@ -288,7 +288,7 @@ export interface BulkUpdateResponse {
288
288
  * @public
289
289
  */
290
290
  export interface MutationState<TData> {
291
- status: "idle" | "loading" | "success" | "error";
291
+ status: 'idle' | 'loading' | 'success' | 'error';
292
292
  data: TData | null;
293
293
  error: Error | null;
294
294
  }
@@ -305,7 +305,7 @@ export interface MutationState<TData> {
305
305
  */
306
306
  export interface MutationResult<TData, TPayload> {
307
307
  mutate: (payload: TPayload) => Promise<TData | undefined>;
308
- status: "idle" | "loading" | "success" | "error";
308
+ status: 'idle' | 'loading' | 'success' | 'error';
309
309
  data: TData | null;
310
310
  error: Error | null;
311
311
  isLoading: boolean;