@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.
Files changed (46) hide show
  1. package/README.md +355 -220
  2. package/dist/api/fetcher.d.ts.map +1 -1
  3. package/dist/api/mutator.d.ts +10 -9
  4. package/dist/api/mutator.d.ts.map +1 -1
  5. package/dist/constants/index.d.ts +2 -28
  6. package/dist/constants/index.d.ts.map +1 -1
  7. package/dist/contexts/FigmaVarsProvider.d.ts +1 -1
  8. package/dist/contexts/FigmaVarsProvider.d.ts.map +1 -1
  9. package/dist/core/index.d.cts +8 -0
  10. package/dist/core/index.d.ts +8 -0
  11. package/dist/core/index.d.ts.map +1 -0
  12. package/dist/core.cjs +1 -0
  13. package/dist/core.d.cts +2 -0
  14. package/dist/core.d.ts +2 -0
  15. package/dist/core.mjs +20 -0
  16. package/dist/hooks/index.d.ts +19 -0
  17. package/dist/hooks/index.d.ts.map +1 -1
  18. package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
  19. package/dist/hooks/useCreateVariable.d.ts.map +1 -1
  20. package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
  21. package/dist/hooks/useInvalidateVariables.d.ts +31 -0
  22. package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
  23. package/dist/hooks/usePublishedVariables.d.ts +42 -0
  24. package/dist/hooks/usePublishedVariables.d.ts.map +1 -0
  25. package/dist/hooks/useUpdateVariable.d.ts.map +1 -1
  26. package/dist/hooks/useVariables.d.ts.map +1 -1
  27. package/dist/index-BIUpDTdr.cjs +1 -0
  28. package/dist/index-Cd4HQQHO.js +94 -0
  29. package/dist/index.cjs +1 -1
  30. package/dist/index.d.cts +9 -4
  31. package/dist/index.d.ts +9 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.mjs +229 -165
  34. package/dist/types/contexts.d.ts +29 -3
  35. package/dist/types/contexts.d.ts.map +1 -1
  36. package/dist/types/figma.d.ts +53 -0
  37. package/dist/types/figma.d.ts.map +1 -1
  38. package/dist/types/mutations.d.ts +1 -1
  39. package/dist/types/mutations.d.ts.map +1 -1
  40. package/dist/utils/errorHelpers.d.ts +96 -0
  41. package/dist/utils/errorHelpers.d.ts.map +1 -0
  42. package/dist/utils/index.d.ts +2 -1
  43. package/dist/utils/index.d.ts.map +1 -1
  44. package/package.json +67 -32
  45. package/scripts/export-variables.mjs +101 -0
  46. package/dist/index.d.mts +0 -2
package/dist/index.mjs CHANGED
@@ -1,210 +1,274 @@
1
- import { jsx as _ } from "react/jsx-runtime";
2
- import { createContext as I, useContext as v, useMemo as d, useReducer as g, useCallback as R } from "react";
3
- import b from "swr";
4
- const f = I(void 0), S = ({
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)
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 t;
19
- }, p = "https://api.figma.com", h = `${p}/v1/variables`, w = h, A = (t) => `${h}/${t}`, C = "application/json", T = "X-FIGMA-TOKEN", i = "A Figma API token is required.", P = "An error occurred while fetching data from the Figma API.";
20
- async function F(t, o) {
21
- if (!o)
22
- throw new Error(i);
23
- const e = await fetch(t, {
24
- method: "GET",
25
- headers: {
26
- [T]: o,
27
- "Content-Type": C
28
- }
29
- });
30
- if (!e.ok) {
31
- let r = P;
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
- }, V = () => {
48
- const { data: t } = y(), o = d(
49
- () => t != null && t.meta ? Object.values(t.meta.variableCollections) : [],
50
- [t]
51
- ), e = d(
52
- () => t != null && t.meta ? t.meta.variableCollections : {},
53
- [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]
54
53
  );
55
54
  return {
56
- collections: o,
57
- collectionsById: e
55
+ collections: t,
56
+ collectionsById: r
58
57
  };
59
- }, k = () => {
60
- const { data: t } = y();
61
- return d(() => {
62
- const o = [], e = {}, r = {};
63
- if (t != null && t.meta)
64
- for (const s of Object.values(
65
- t.meta.variableCollections
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
- o.push(...s.modes), e[s.id] = s.modes;
68
- for (const c of s.modes)
69
- r[c.modeId] = c;
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: o,
73
- modesByCollectionId: e,
74
- modesById: r
71
+ modes: t,
72
+ modesByCollectionId: r,
73
+ modesById: o
75
74
  };
76
- }, [t]);
75
+ }, [e]);
77
76
  };
78
- function O(t, o) {
79
- switch (o.type) {
77
+ function B(e, t) {
78
+ switch (t.type) {
80
79
  case "loading":
81
- return { ...t, status: "loading", error: null };
80
+ return { ...e, status: "loading", error: null };
82
81
  case "success":
83
- return { ...t, status: "success", data: o.payload };
82
+ return { ...e, status: "success", data: t.payload };
84
83
  case "error":
85
- return { ...t, status: "error", error: o.payload };
84
+ return { ...e, status: "error", error: t.payload };
86
85
  default:
87
- return t;
86
+ return e;
88
87
  }
89
88
  }
90
- const l = (t) => {
91
- const o = {
89
+ const y = (e) => {
90
+ const t = {
92
91
  status: "idle",
93
92
  data: null,
94
93
  error: null
95
- }, [e, r] = g(O, o);
96
- return {
97
- mutate: R(
98
- async (c) => {
99
- r({ type: "loading" });
100
- try {
101
- const n = await t(c);
102
- return r({ type: "success", payload: n }), n;
103
- } catch (n) {
104
- r({ type: "error", payload: n });
105
- 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
+ }
106
111
  }
107
112
  },
108
- [t]
113
+ []
114
+ // Empty deps array - mutationFn is accessed via ref
109
115
  ),
110
- ...e,
111
- isLoading: e.status === "loading",
112
- isSuccess: e.status === "success",
113
- isError: e.status === "error"
116
+ ...r,
117
+ isLoading: r.status === "loading",
118
+ isSuccess: r.status === "success",
119
+ isError: r.status === "error"
114
120
  };
115
- };
116
- async function m(t, o, e, r) {
117
- if (!o)
118
- throw new Error(i);
119
- const n = {
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(i);
145
- return await m(
146
- w,
147
- t,
148
- "CREATE",
149
- e
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
- }, G = () => {
153
- const { token: t } = u();
154
- return l(
137
+ }, q = () => {
138
+ const { token: e, fileKey: t } = u();
139
+ return y(
155
140
  async ({
156
- variableId: e,
157
- payload: r
141
+ variableId: o,
142
+ payload: n
158
143
  }) => {
144
+ if (!e)
145
+ throw new Error(v);
159
146
  if (!t)
160
- throw new Error(i);
161
- return await m(
162
- A(e),
163
- t,
147
+ throw new Error(p);
148
+ return await E(
149
+ b(t),
150
+ e,
164
151
  "UPDATE",
165
- r
152
+ {
153
+ variables: [
154
+ {
155
+ action: "UPDATE",
156
+ id: o,
157
+ ...n
158
+ }
159
+ ]
160
+ }
166
161
  );
167
162
  }
168
163
  );
169
- }, j = () => {
170
- const { token: t } = u();
171
- 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);
172
169
  if (!t)
173
- throw new Error(i);
174
- return await m(
175
- A(e),
176
- t,
177
- "DELETE",
178
- void 0
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
- }, L = () => {
182
- const { token: t } = u();
183
- 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);
184
185
  if (!t)
185
- throw new Error(i);
186
- return await m(
187
- w,
188
- t,
189
- "CREATE",
190
- e
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 x(t, o) {
195
- return t.filter((e) => {
196
- let r = !0;
197
- return o.resolvedType && (r = r && e.resolvedType === o.resolvedType), o.name && (r = r && e.name.includes(o.name)), r;
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
- S as FigmaVarsProvider,
202
- x as filterVariables,
203
- L as useBulkUpdateVariables,
204
- B as useCreateVariable,
205
- j as useDeleteVariable,
206
- G as useUpdateVariable,
207
- V as useVariableCollections,
208
- k as useVariableModes,
209
- 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
210
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,CAAA;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,CAAA;CAC/C;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,MAAM,CAAA;CAC/C"}
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"}
@@ -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,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;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QACJ,wDAAwD;QACxD,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;QACpD,oDAAoD;QACpD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;KACzC,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,UAAU;IACzB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAA;CAChB"}
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;IACn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MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;KACzC,CAAA;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,aAAa,EAAE,MAAM,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,oBAAoB,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,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
  *
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/types/mutations.ts"],"names":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