@figma-vars/hooks 3.1.0 → 4.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 +83 -24
- package/dist/api/fetcher.d.ts +5 -0
- package/dist/api/fetcher.d.ts.map +1 -1
- package/dist/api/mutator.d.ts +5 -0
- package/dist/api/mutator.d.ts.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.mjs +1 -1
- package/dist/hooks/useBulkUpdateVariables.d.ts +18 -4
- package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
- package/dist/hooks/useCreateVariable.d.ts +22 -4
- package/dist/hooks/useCreateVariable.d.ts.map +1 -1
- package/dist/hooks/useDeleteVariable.d.ts +19 -3
- package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
- package/dist/hooks/useUpdateVariable.d.ts +19 -3
- package/dist/hooks/useUpdateVariable.d.ts.map +1 -1
- package/dist/index-DFB8mxu_.cjs +1 -0
- package/dist/index-Dqg9kaMQ.js +150 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +49 -49
- package/dist/types/mutations.d.ts +61 -3
- package/dist/types/mutations.d.ts.map +1 -1
- package/dist/utils/filterVariables.d.ts +25 -5
- package/dist/utils/filterVariables.d.ts.map +1 -1
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/redactToken.d.ts +44 -0
- package/dist/utils/redactToken.d.ts.map +1 -0
- package/dist/utils/retry.d.ts +65 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/index-5ZyKWuYv.cjs +0 -1
- package/dist/index-ClHLYVvu.js +0 -142
package/dist/index-ClHLYVvu.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
var L = Object.defineProperty;
|
|
2
|
-
var S = (t, s, r) => s in t ? L(t, s, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[s] = r;
|
|
3
|
-
var I = (t, s, r) => S(t, typeof s != "symbol" ? s + "" : s, r);
|
|
4
|
-
const T = "https://api.figma.com", M = `${T}/v1/files`, D = (t) => `/v1/files/${t}/variables/published`, G = (t) => `/v1/files/${t}/variables`, b = (t) => `${M}/${t}/variables/local`, N = "application/json", y = "X-FIGMA-TOKEN", F = "A Figma API token is required.", P = `${F} and file key are required.`, C = "Failed to perform bulk update.", $ = "Failed to create Figma variable.", U = "Failed to delete Figma variable.", j = "Failed to update Figma variable.", O = "An error occurred while fetching data from the Figma API.";
|
|
5
|
-
class p extends Error {
|
|
6
|
-
constructor(r, a, A) {
|
|
7
|
-
super(r);
|
|
8
|
-
/** HTTP status code from the API response. */
|
|
9
|
-
I(this, "statusCode");
|
|
10
|
-
/**
|
|
11
|
-
* Retry-After header value in seconds (for 429 rate limit errors).
|
|
12
|
-
* Undefined if not a rate limit error or header not present.
|
|
13
|
-
*/
|
|
14
|
-
I(this, "retryAfter");
|
|
15
|
-
this.name = "FigmaApiError", this.statusCode = a, this.retryAfter = A ?? void 0, Error.captureStackTrace && Error.captureStackTrace(this, p);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function B(t, s, r) {
|
|
19
|
-
if (!s)
|
|
20
|
-
throw new Error(F);
|
|
21
|
-
const {
|
|
22
|
-
signal: a,
|
|
23
|
-
timeout: A,
|
|
24
|
-
fetch: u = fetch
|
|
25
|
-
} = r ?? {};
|
|
26
|
-
let o, d;
|
|
27
|
-
const i = a || (A ? (d = new AbortController(), o = setTimeout(() => {
|
|
28
|
-
d == null || d.abort();
|
|
29
|
-
}, A), d.signal) : void 0);
|
|
30
|
-
try {
|
|
31
|
-
const n = t.startsWith("http://") || t.startsWith("https://") ? t : `${T}${t.startsWith("/") ? "" : "/"}${t}`, c = await u(n, {
|
|
32
|
-
method: "GET",
|
|
33
|
-
headers: {
|
|
34
|
-
[y]: s,
|
|
35
|
-
"Content-Type": N
|
|
36
|
-
},
|
|
37
|
-
...i !== void 0 && { signal: i }
|
|
38
|
-
});
|
|
39
|
-
if (o !== void 0 && (clearTimeout(o), o = void 0), !c.ok) {
|
|
40
|
-
let f = O;
|
|
41
|
-
const m = c.status;
|
|
42
|
-
let h;
|
|
43
|
-
if (m === 429) {
|
|
44
|
-
const E = c.headers.get("Retry-After");
|
|
45
|
-
if (E) {
|
|
46
|
-
const e = parseInt(E, 10);
|
|
47
|
-
Number.isNaN(e) || (h = e);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
const E = c.headers.get("content-type");
|
|
52
|
-
if (E != null && E.includes("application/json")) {
|
|
53
|
-
const e = await c.json();
|
|
54
|
-
e != null && e.message ? f = e.message : e != null && e.err && (f = e.err);
|
|
55
|
-
}
|
|
56
|
-
} catch {
|
|
57
|
-
}
|
|
58
|
-
throw new p(f, m, h);
|
|
59
|
-
}
|
|
60
|
-
return c.json();
|
|
61
|
-
} catch (n) {
|
|
62
|
-
throw o !== void 0 && (clearTimeout(o), o = void 0), n;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function H(t, s, r, a, A) {
|
|
66
|
-
if (!s)
|
|
67
|
-
throw new Error(F);
|
|
68
|
-
const {
|
|
69
|
-
signal: u,
|
|
70
|
-
timeout: o,
|
|
71
|
-
fetch: d = fetch
|
|
72
|
-
} = A ?? {};
|
|
73
|
-
let i, n;
|
|
74
|
-
const c = u || (o ? (n = new AbortController(), i = setTimeout(() => {
|
|
75
|
-
n == null || n.abort();
|
|
76
|
-
}, o), n.signal) : void 0);
|
|
77
|
-
try {
|
|
78
|
-
const h = {
|
|
79
|
-
method: {
|
|
80
|
-
CREATE: "POST",
|
|
81
|
-
UPDATE: "PUT",
|
|
82
|
-
DELETE: "DELETE"
|
|
83
|
-
}[r],
|
|
84
|
-
headers: {
|
|
85
|
-
"Content-Type": "application/json",
|
|
86
|
-
[y]: s
|
|
87
|
-
},
|
|
88
|
-
...c !== void 0 && { signal: c }
|
|
89
|
-
};
|
|
90
|
-
a && (h.body = JSON.stringify(a));
|
|
91
|
-
const E = t.startsWith("http://") || t.startsWith("https://") ? t : `${T}${t.startsWith("/") ? "" : "/"}${t}`, e = await d(E, h);
|
|
92
|
-
if (i !== void 0 && (clearTimeout(i), i = void 0), !e.ok) {
|
|
93
|
-
const g = e.status;
|
|
94
|
-
let R = "An API error occurred", v;
|
|
95
|
-
if (g === 429) {
|
|
96
|
-
const l = e.headers.get("Retry-After");
|
|
97
|
-
if (l) {
|
|
98
|
-
const _ = parseInt(l, 10);
|
|
99
|
-
Number.isNaN(_) || (v = _);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
try {
|
|
103
|
-
const l = e.headers.get("content-type");
|
|
104
|
-
if (l != null && l.includes("application/json")) {
|
|
105
|
-
const _ = await e.json();
|
|
106
|
-
R = _.err || _.message || R;
|
|
107
|
-
}
|
|
108
|
-
} catch {
|
|
109
|
-
}
|
|
110
|
-
throw new p(R, g, v);
|
|
111
|
-
}
|
|
112
|
-
return e.status === 204 || !e.body ? {} : e.json();
|
|
113
|
-
} catch (f) {
|
|
114
|
-
throw i !== void 0 && (clearTimeout(i), i = void 0), f;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function V(t, s) {
|
|
118
|
-
return t.filter((r) => {
|
|
119
|
-
let a = !0;
|
|
120
|
-
return s.resolvedType && (a = a && r.resolvedType === s.resolvedType), s.name && (a = a && r.name.includes(s.name)), a;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
export {
|
|
124
|
-
N as C,
|
|
125
|
-
F as E,
|
|
126
|
-
G as F,
|
|
127
|
-
P as a,
|
|
128
|
-
p as b,
|
|
129
|
-
V as c,
|
|
130
|
-
T as d,
|
|
131
|
-
M as e,
|
|
132
|
-
B as f,
|
|
133
|
-
D as g,
|
|
134
|
-
b as h,
|
|
135
|
-
y as i,
|
|
136
|
-
C as j,
|
|
137
|
-
$ as k,
|
|
138
|
-
U as l,
|
|
139
|
-
H as m,
|
|
140
|
-
j as n,
|
|
141
|
-
O as o
|
|
142
|
-
};
|