@figma-vars/hooks 3.0.0-beta.1 → 3.1.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 +417 -173
- package/dist/api/fetcher.d.ts +32 -1
- package/dist/api/fetcher.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/mutator.d.ts +36 -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/FigmaTokenContext.d.ts.map +1 -1
- package/dist/contexts/FigmaVarsProvider.d.ts +3 -1
- package/dist/contexts/FigmaVarsProvider.d.ts.map +1 -1
- package/dist/contexts/index.d.ts +1 -1
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/contexts/useFigmaTokenContext.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 +64 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useBulkUpdateVariables.d.ts.map +1 -1
- package/dist/hooks/useCollectionById.d.ts +31 -0
- package/dist/hooks/useCollectionById.d.ts.map +1 -0
- package/dist/hooks/useCreateVariable.d.ts.map +1 -1
- package/dist/hooks/useDeleteVariable.d.ts.map +1 -1
- package/dist/hooks/useFigmaToken.d.ts.map +1 -1
- package/dist/hooks/useInvalidateVariables.d.ts +34 -0
- package/dist/hooks/useInvalidateVariables.d.ts.map +1 -0
- package/dist/hooks/useModesByCollection.d.ts +34 -0
- package/dist/hooks/useModesByCollection.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/useVariableById.d.ts +31 -0
- package/dist/hooks/useVariableById.d.ts.map +1 -0
- package/dist/hooks/useVariableCollections.d.ts.map +1 -1
- package/dist/hooks/useVariableModes.d.ts.map +1 -1
- package/dist/hooks/useVariables.d.ts +3 -1
- package/dist/hooks/useVariables.d.ts.map +1 -1
- package/dist/index-5ZyKWuYv.cjs +1 -0
- package/dist/index-ClHLYVvu.js +142 -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 +319 -163
- package/dist/types/contexts.d.ts +30 -3
- package/dist/types/contexts.d.ts.map +1 -1
- package/dist/types/figma.d.ts +64 -3
- package/dist/types/figma.d.ts.map +1 -1
- package/dist/types/hooks.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mutations.d.ts +18 -4
- package/dist/types/mutations.d.ts.map +1 -1
- package/dist/utils/errorHelpers.d.ts +142 -0
- package/dist/utils/errorHelpers.d.ts.map +1 -0
- package/dist/utils/filterVariables.d.ts.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/swrKeys.d.ts +24 -0
- package/dist/utils/swrKeys.d.ts.map +1 -0
- package/dist/utils/typeGuards.d.ts +50 -0
- package/dist/utils/typeGuards.d.ts.map +1 -0
- package/package.json +75 -31
- package/scripts/export-variables.mjs +101 -0
- package/dist/index.d.mts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVariables.d.ts","sourceRoot":"","sources":["../../src/hooks/useVariables.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"useVariables.d.ts","sourceRoot":"","sources":["../../src/hooks/useVariables.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAIzD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,0LAgDxB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var N=Object.defineProperty;var g=(t,s,r)=>s in t?N(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var m=(t,s,r)=>g(t,typeof s!="symbol"?s+"":s,r);const T="https://api.figma.com",O=`${T}/v1/files`,v=t=>`/v1/files/${t}/variables/published`,P=t=>`/v1/files/${t}/variables`,y=t=>`${O}/${t}/variables/local`,D="application/json",p="X-FIGMA-TOKEN",h="A Figma API token is required.",B=`${h} and file key are required.`,U="Failed to perform bulk update.",w="Failed to create Figma variable.",b="Failed to delete Figma variable.",C="Failed to update Figma variable.",G="An error occurred while fetching data from the Figma API.";class l extends Error{constructor(r,o,c){super(r);m(this,"statusCode");m(this,"retryAfter");this.name="FigmaApiError",this.statusCode=o,this.retryAfter=c??void 0,Error.captureStackTrace&&Error.captureStackTrace(this,l)}}async function V(t,s,r){if(!s)throw new Error(h);const{signal:o,timeout:c,fetch:F=fetch}=r??{};let i,A;const a=o||(c?(A=new AbortController,i=setTimeout(()=>{A==null||A.abort()},c),A.signal):void 0);try{const E=t.startsWith("http://")||t.startsWith("https://")?t:`${T}${t.startsWith("/")?"":"/"}${t}`,n=await F(E,{method:"GET",headers:{[p]:s,"Content-Type":D},...a!==void 0&&{signal:a}});if(i!==void 0&&(clearTimeout(i),i=void 0),!n.ok){let R=G;const L=n.status;let d;if(L===429){const _=n.headers.get("Retry-After");if(_){const e=parseInt(_,10);Number.isNaN(e)||(d=e)}}try{const _=n.headers.get("content-type");if(_!=null&&_.includes("application/json")){const e=await n.json();e!=null&&e.message?R=e.message:e!=null&&e.err&&(R=e.err)}}catch{}throw new l(R,L,d)}return n.json()}catch(E){throw i!==void 0&&(clearTimeout(i),i=void 0),E}}async function H(t,s,r,o,c){if(!s)throw new Error(h);const{signal:F,timeout:i,fetch:A=fetch}=c??{};let a,E;const n=F||(i?(E=new AbortController,a=setTimeout(()=>{E==null||E.abort()},i),E.signal):void 0);try{const d={method:{CREATE:"POST",UPDATE:"PUT",DELETE:"DELETE"}[r],headers:{"Content-Type":"application/json",[p]:s},...n!==void 0&&{signal:n}};o&&(d.body=JSON.stringify(o));const _=t.startsWith("http://")||t.startsWith("https://")?t:`${T}${t.startsWith("/")?"":"/"}${t}`,e=await A(_,d);if(a!==void 0&&(clearTimeout(a),a=void 0),!e.ok){const S=e.status;let u="An API error occurred",M;if(S===429){const I=e.headers.get("Retry-After");if(I){const f=parseInt(I,10);Number.isNaN(f)||(M=f)}}try{const I=e.headers.get("content-type");if(I!=null&&I.includes("application/json")){const f=await e.json();u=f.err||f.message||u}}catch{}throw new l(u,S,M)}return e.status===204||!e.body?{}:e.json()}catch(R){throw a!==void 0&&(clearTimeout(a),a=void 0),R}}function $(t,s){return t.filter(r=>{let o=!0;return s.resolvedType&&(o=o&&r.resolvedType===s.resolvedType),s.name&&(o=o&&r.name.includes(s.name)),o})}exports.CONTENT_TYPE_JSON=D;exports.ERROR_MSG_BULK_UPDATE_FAILED=U;exports.ERROR_MSG_CREATE_VARIABLE_FAILED=w;exports.ERROR_MSG_DELETE_VARIABLE_FAILED=b;exports.ERROR_MSG_FETCH_FIGMA_DATA_FAILED=G;exports.ERROR_MSG_TOKEN_FILE_KEY_REQUIRED=B;exports.ERROR_MSG_TOKEN_REQUIRED=h;exports.ERROR_MSG_UPDATE_VARIABLE_FAILED=C;exports.FIGMA_API_BASE_URL=T;exports.FIGMA_FILES_ENDPOINT=O;exports.FIGMA_FILE_VARIABLES_PATH=P;exports.FIGMA_LOCAL_VARIABLES_ENDPOINT=y;exports.FIGMA_PUBLISHED_VARIABLES_PATH=v;exports.FIGMA_TOKEN_HEADER=p;exports.FigmaApiError=l;exports.fetcher=V;exports.filterVariables=$;exports.mutator=H;
|
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react/jsx-runtime"),u=require("react"),m=require("swr"),i=require("./index-5ZyKWuYv.cjs"),k=u.createContext(void 0);function A(e){if(typeof e!="object"||e===null)return!1;const r=e;if(typeof r.meta!="object"||r.meta===null)return!1;const t=r.meta;return!(typeof t.variableCollections!="object"||t.variableCollections===null||typeof t.variables!="object"||t.variables===null)}function _(e){if(A(e))return e}const V=({children:e,token:r,fileKey:t,fallbackFile:o,swrConfig:s})=>{const a=u.useId(),l=u.useMemo(()=>`figma-vars-provider-${a}`,[a]),f=u.useMemo(()=>{if(o){if(typeof o=="object"){const n=_(o);if(n)return n;process.env.NODE_ENV!=="production"&&console.warn("[figma-vars-hooks] fallbackFile object does not match expected Figma Variables API response structure. Expected { meta: { variableCollections: {...}, variables: {...} } }");return}if(typeof o=="string")try{const n=JSON.parse(o),d=_(n);if(d)return d;process.env.NODE_ENV!=="production"&&console.warn("[figma-vars-hooks] Parsed fallbackFile JSON does not match expected Figma Variables API response structure. Expected { meta: { variableCollections: {...}, variables: {...} } }");return}catch(n){process.env.NODE_ENV!=="production"&&console.error(`[figma-vars-hooks] Failed to parse fallbackFile JSON: ${n instanceof Error?n.message:"Unknown error"}`);return}}},[o]),c=u.useMemo(()=>{const n={token:r,fileKey:t,providerId:l,...s!==void 0&&{swrConfig:s}};return o===void 0?n:{...n,fallbackFile:o,parsedFallbackFile:f}},[r,t,o,f,l,s]);return g.jsx(k.Provider,{value:c,children:e})},b=()=>{const e=u.useContext(k);if(e===void 0)throw new Error("useFigmaTokenContext must be used within a FigmaVarsProvider");return e};function M(e){const{fileKey:r,token:t,providerId:o,hasFallback:s}=e;return!!(t&&r)&&t&&r?[`https://api.figma.com/v1/files/${r}/variables/local`,t]:s?[`fallback-${o??"default"}`,"fallback"]:null}function O(e){const{fileKey:r,token:t,providerId:o,hasFallback:s}=e;return!!(t&&r)&&t&&r?[`https://api.figma.com/v1/files/${r}/variables/published`,t]:s?[`fallback-${o??"default"}`,"fallback"]:null}function I(e){const{fileKey:r,token:t,providerId:o,hasFallback:s}=e,a=[];return t&&r&&(a.push([`https://api.figma.com/v1/files/${r}/variables/local`,t]),a.push([`https://api.figma.com/v1/files/${r}/variables/published`,t])),s&&o&&a.push([`fallback-${o}`,"fallback"]),a}const R=()=>{const{token:e,fileKey:r,fallbackFile:t,parsedFallbackFile:o,providerId:s,swrConfig:a}=b(),f=M({fileKey:r,token:e,providerId:s,hasFallback:!!(t||o)});return m(f,async(...n)=>{if(o)return o;if(t&&typeof t=="object")return t;const[d,E]=Array.isArray(n[0])?n[0]:[n[0],n[1]];if(!d||!E)throw new Error("Missing URL or token for live API request");return i.fetcher(d,E)},a)},S=()=>{const{data:e}=R(),r=u.useMemo(()=>e!=null&&e.meta?Object.values(e.meta.variableCollections):[],[e]),t=u.useMemo(()=>e!=null&&e.meta?e.meta.variableCollections:{},[e]);return{collections:r,collectionsById:t}},K=()=>{const{data:e}=R();return u.useMemo(()=>{const r=[],t={},o={};if(e!=null&&e.meta)for(const s of Object.values(e.meta.variableCollections)){r.push(...s.modes),t[s.id]=s.modes;for(const a of s.modes)o[a.modeId]=a}return{modes:r,modesByCollectionId:t,modesById:o}},[e])};function T(e,r){switch(r.type){case"loading":return{...e,status:"loading",error:null};case"success":return{...e,status:"success",data:r.payload};case"error":return{...e,status:"error",error:r.payload};default:return e}}const v=(e,r)=>{const{throwOnError:t=!1}={},o={status:"idle",data:null,error:null},[s,a]=u.useReducer(T,o),l=u.useRef(e),f=u.useRef({throwOnError:t}),c=u.useRef(!0),n=u.useRef(0);return u.useEffect(()=>{l.current=e,f.current={throwOnError:t}},[e,t]),u.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]),{mutate:u.useCallback(async E=>{if(!c.current)return;const y=++n.current;a({type:"loading"});try{const p=await l.current(E);return c.current&&y===n.current&&a({type:"success",payload:p}),p}catch(p){const h=p;if(c.current&&y===n.current&&a({type:"error",payload:h}),f.current.throwOnError)throw h;return}},[]),...s,isLoading:s.status==="loading",isSuccess:s.status==="success",isError:s.status==="error"}},C=()=>{const{token:e,fileKey:r}=b();return v(async o=>{if(!e)throw new Error(i.ERROR_MSG_TOKEN_REQUIRED);if(!r)throw new Error(i.ERROR_MSG_TOKEN_FILE_KEY_REQUIRED);return await i.mutator(i.FIGMA_FILE_VARIABLES_PATH(r),e,"CREATE",{variables:[{action:"CREATE",...o}]})})},L=()=>{const{token:e,fileKey:r}=b();return v(async({variableId:o,payload:s})=>{if(!e)throw new Error(i.ERROR_MSG_TOKEN_REQUIRED);if(!r)throw new Error(i.ERROR_MSG_TOKEN_FILE_KEY_REQUIRED);return await i.mutator(i.FIGMA_FILE_VARIABLES_PATH(r),e,"UPDATE",{variables:[{action:"UPDATE",id:o,...s}]})})},P=()=>{const{token:e,fileKey:r}=b();return v(async o=>{if(!e)throw new Error(i.ERROR_MSG_TOKEN_REQUIRED);if(!r)throw new Error(i.ERROR_MSG_TOKEN_FILE_KEY_REQUIRED);return await i.mutator(i.FIGMA_FILE_VARIABLES_PATH(r),e,"DELETE",{variables:[{action:"DELETE",id:o}]})})},D=()=>{const{token:e,fileKey:r}=b();return v(async o=>{if(!e)throw new Error(i.ERROR_MSG_TOKEN_REQUIRED);if(!r)throw new Error(i.ERROR_MSG_TOKEN_FILE_KEY_REQUIRED);return await i.mutator(i.FIGMA_FILE_VARIABLES_PATH(r),e,"UPDATE",o)})},U=()=>{const{mutate:e}=m.useSWRConfig(),{token:r,fileKey:t,fallbackFile:o,providerId:s}=b(),a=!!o;return{invalidate:()=>{const c=I({fileKey:t,token:r,providerId:s,hasFallback:a});for(const n of c)e(n)},revalidate:()=>{const c=I({fileKey:t,token:r,providerId:s,hasFallback:a});for(const n of c)e(n,void 0,{revalidate:!0})}}},N=()=>{const{token:e,fileKey:r,fallbackFile:t,parsedFallbackFile:o,providerId:s,swrConfig:a}=b(),f=O({fileKey:r,token:e,providerId:s,hasFallback:!!(t||o)});return m(f,async(...n)=>{if(o)return o;if(t&&typeof t=="object")return t;const[d,E]=Array.isArray(n[0])?n[0]:[n[0],n[1]];if(!d||!E)throw new Error("Missing URL or token for live API request");return i.fetcher(d,E)},a)};function w(e){return e instanceof i.FigmaApiError}function F(e){return w(e)?e.statusCode:null}function j(e,r="An error occurred"){return e instanceof Error?e.message||r:typeof e=="string"?e:r}function B(e,r){return F(e)===r}exports.FigmaApiError=i.FigmaApiError;exports.filterVariables=i.filterVariables;exports.FigmaVarsProvider=V;exports.getErrorMessage=j;exports.getErrorStatus=F;exports.hasErrorStatus=B;exports.isFigmaApiError=w;exports.useBulkUpdateVariables=D;exports.useCreateVariable=C;exports.useDeleteVariable=P;exports.useInvalidateVariables=U;exports.usePublishedVariables=N;exports.useUpdateVariable=L;exports.useVariableCollections=S;exports.useVariableModes=K;exports.useVariables=R;
|
package/dist/index.d.cts
CHANGED
|
@@ -52,20 +52,25 @@ export { FigmaVarsProvider } from 'contexts';
|
|
|
52
52
|
* }
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
export { useVariables, useVariableCollections, useVariableModes, useCreateVariable, useUpdateVariable, useDeleteVariable, useBulkUpdateVariables, } from 'hooks';
|
|
55
|
+
export { useVariables, usePublishedVariables, useVariableCollections, useVariableModes, useCreateVariable, useUpdateVariable, useDeleteVariable, useBulkUpdateVariables, useInvalidateVariables, } from 'hooks';
|
|
56
56
|
/**
|
|
57
57
|
* Utility functions for Figma Variable management.
|
|
58
58
|
*
|
|
59
59
|
* @remarks
|
|
60
|
-
* Helpers like `filterVariables` for searching and filtering variable lists. All utilities are stateless and type-safe—use for UI filtering, scripting, and dashboard logic.
|
|
60
|
+
* Helpers like `filterVariables` for searching and filtering variable lists, and error handling utilities. All utilities are stateless and type-safe—use for UI filtering, scripting, and dashboard logic.
|
|
61
61
|
*
|
|
62
62
|
* @example
|
|
63
63
|
* ```ts
|
|
64
|
-
* import { filterVariables } from '@figma-vars/hooks';
|
|
64
|
+
* import { filterVariables, isFigmaApiError, getErrorStatus } from '@figma-vars/hooks';
|
|
65
65
|
* const filtered = filterVariables(variables, { resolvedType: 'COLOR' });
|
|
66
|
+
*
|
|
67
|
+
* // Error handling
|
|
68
|
+
* if (isFigmaApiError(error)) {
|
|
69
|
+
* console.log('Status:', error.statusCode);
|
|
70
|
+
* }
|
|
66
71
|
* ```
|
|
67
72
|
*/
|
|
68
|
-
export { filterVariables } from 'utils';
|
|
73
|
+
export { filterVariables, isFigmaApiError, getErrorStatus, getErrorMessage, hasErrorStatus, } from 'utils';
|
|
69
74
|
/**
|
|
70
75
|
* All official TypeScript types for advanced usage and type-safe integration.
|
|
71
76
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -52,20 +52,25 @@ export { FigmaVarsProvider } from 'contexts';
|
|
|
52
52
|
* }
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
export { useVariables, useVariableCollections, useVariableModes, useCreateVariable, useUpdateVariable, useDeleteVariable, useBulkUpdateVariables, } from 'hooks';
|
|
55
|
+
export { useVariables, usePublishedVariables, useVariableCollections, useVariableModes, useCreateVariable, useUpdateVariable, useDeleteVariable, useBulkUpdateVariables, useInvalidateVariables, } from 'hooks';
|
|
56
56
|
/**
|
|
57
57
|
* Utility functions for Figma Variable management.
|
|
58
58
|
*
|
|
59
59
|
* @remarks
|
|
60
|
-
* Helpers like `filterVariables` for searching and filtering variable lists. All utilities are stateless and type-safe—use for UI filtering, scripting, and dashboard logic.
|
|
60
|
+
* Helpers like `filterVariables` for searching and filtering variable lists, and error handling utilities. All utilities are stateless and type-safe—use for UI filtering, scripting, and dashboard logic.
|
|
61
61
|
*
|
|
62
62
|
* @example
|
|
63
63
|
* ```ts
|
|
64
|
-
* import { filterVariables } from '@figma-vars/hooks';
|
|
64
|
+
* import { filterVariables, isFigmaApiError, getErrorStatus } from '@figma-vars/hooks';
|
|
65
65
|
* const filtered = filterVariables(variables, { resolvedType: 'COLOR' });
|
|
66
|
+
*
|
|
67
|
+
* // Error handling
|
|
68
|
+
* if (isFigmaApiError(error)) {
|
|
69
|
+
* console.log('Status:', error.statusCode);
|
|
70
|
+
* }
|
|
66
71
|
* ```
|
|
67
72
|
*/
|
|
68
|
-
export { filterVariables } from 'utils';
|
|
73
|
+
export { filterVariables, isFigmaApiError, getErrorStatus, getErrorMessage, hasErrorStatus, } from 'utils';
|
|
69
74
|
/**
|
|
70
75
|
* All official TypeScript types for advanced usage and type-safe integration.
|
|
71
76
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,OAAO,CAAA;AAEd;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,eAAe,EACf,eAAe,EACf,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,OAAO,CAAA;AAEd;;;;;;;;;;GAUG;AACH,cAAc,OAAO,CAAA"}
|