@frontfriend/sdk 1.2.5 → 1.2.6

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.
@@ -1 +1 @@
1
- var j=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var S=j((q,F)=>{F.exports={name:"@frontfriend/sdk",version:"1.2.5"}});var C=j(($,b)=>{var{name:w}=S();b.exports={PACKAGE_NAME:w}});var{PACKAGE_NAME:m}=C(),u=require("fs"),E=require("http"),O=require("https"),i=require("path"),g=["contracts","tokens","components"],T=["app/globals.css","src/app/globals.css","styles/globals.css","src/styles/globals.css","src/styles.css","src/index.css","src/style.css"],k={next:["next.config.js","next.config.mjs","next.config.ts"],vite:["vite.config.ts","vite.config.js","vite.config.mts","vite.config.mjs"]},x=["primereact","@mui/material","antd","@chakra-ui/react","@mantine/core","@fluentui/react"],I=["style-dictionary","@tokens-studio/sd-transforms","@vanilla-extract/css","styled-components","@emotion/react"];function A(n){try{return JSON.parse(u.readFileSync(n,"utf8"))}catch{return{}}}function h(n){if(n===void 0)return null;if(!Array.isArray(n)){let t=new Error("`adopt` in frontfriend.config.js must be an array.");throw t.code="FRONTFRIEND_CONFIG_VALIDATION",t}let e=n.filter(t=>!g.includes(t));if(e.length>0){let t=new Error(`Unknown Frontfriend adoption level: ${e.join(", ")}.`);throw t.code="FRONTFRIEND_CONFIG_VALIDATION",t}let o=n.includes("components")?2:n.includes("tokens")?1:0;return g.slice(0,o+1)}function _(n){for(let[e,o]of Object.entries(k)){let t=o.find(s=>u.existsSync(i.join(n,s)));if(!t)continue;let r=u.readFileSync(i.join(n,t),"utf8");return{buildTool:e,present:r.includes(`${m}/${e}`)}}return{buildTool:null,present:!1}}function v(n){let e=[i.join(n,"components","ui"),i.join(n,"src","components","ui"),i.join(n,"app","components","ui")].filter(r=>u.existsSync(r)),o=new Set;function t(r){for(let s of u.readdirSync(r,{withFileTypes:!0})){let c=i.join(r,s.name);if(s.isDirectory())t(c);else if(/\.(js|jsx|ts|tsx|vue)$/.test(s.name)){if(!u.readFileSync(c,"utf8").includes(m))continue;let a=i.basename(s.name,i.extname(s.name));o.add(a.toLowerCase()==="index"?i.basename(r):a.toLowerCase())}}}return e.forEach(t),[...o].sort()}function P(n){let e=A(i.join(n,"package.json")),o={...e.dependencies||{},...e.devDependencies||{}},t=o.tailwindcss||null,s=[A(i.join(n,"components.json"))?.tailwind?.css,...T].filter(Boolean).find(a=>u.existsSync(i.join(n,a))),c=s?u.readFileSync(i.join(n,s),"utf8"):"",l=I.filter(a=>o[a]);return!l.length&&/:root[\s\S]*--(?:color|spacing|font|radius)-[\w-]+\s*:/.test(c)&&!c.includes(`${m}/theme.css`)&&l.push("css-custom-properties"),{nativeTokens:{present:c.includes("/* Frontfriend managed native tokens: start */"),file:s||null},tailwind:{present:!!t,version:t,major:t&&Number((String(t).match(/\d+/)||[])[0])||null},componentsJson:u.existsSync(i.join(n,"components.json")),themeImport:{present:c.includes(`${m}/theme.css`)||/@import\s+["'][^"']*node_modules\/\.cache\/frontfriend\/theme\.css["']/.test(c),file:s||null},plugin:_(n),frontfriendComponents:v(n),foreignComponentLibraries:x.filter(a=>o[a]),foreignTokenSystems:l}}function D(n,e){let o=h(n)||g,t=o.includes("tokens"),r=o.includes("components"),s=[];return t&&!e.themeImport.present&&!e.nativeTokens?.present&&s.push("Config adopts tokens, but the Frontfriend theme import was not observed."),!t&&e.themeImport.present&&s.push("Frontfriend tokens are present in CSS but are not adopted in config."),r&&!e.componentsJson&&s.push("Config adopts components, but components.json was not observed."),!r&&e.frontfriendComponents.length>0&&s.push("Frontfriend components are installed but are not adopted in config."),s}function L({apiUrl:n,token:e,ffId:o,name:t,adopt:r,observed:s,framework:c,primitive:l}){if(!n||!e||!o||!t||!c||l===void 0)return Promise.resolve({reported:!1,unavailable:!0});let a=new URL("/api/apps/sync",n),y=JSON.stringify({ffId:o,name:t,adopt:h(r),observed:s,runtime:"sdk",framework:c,primitive:l}),N=a.protocol==="https:"?O:E;return new Promise(d=>{let f=N.request(a,{method:"POST",headers:{authorization:`Bearer ${e}`,"content-type":"application/json","content-length":Buffer.byteLength(y)}},p=>{p.resume(),p.on("end",()=>{p.statusCode>=200&&p.statusCode<300?d({reported:!0,unavailable:!1}):d({reported:!1,unavailable:!0})})});f.on("error",()=>d({reported:!1,unavailable:!0})),f.setTimeout(1500,()=>{f.destroy(),d({reported:!1,unavailable:!0})}),f.end(y)})}module.exports={ADOPTION_LEVELS:g,normalizeAdopt:h,probeAdoption:P,adoptionWarnings:D,reportAdoption:L};
1
+ var j=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var S=j((q,F)=>{F.exports={name:"@frontfriend/sdk",version:"1.2.6"}});var C=j(($,b)=>{var{name:w}=S();b.exports={PACKAGE_NAME:w}});var{PACKAGE_NAME:m}=C(),u=require("fs"),E=require("http"),O=require("https"),r=require("path"),g=["contracts","tokens","components"],T=["app/globals.css","src/app/globals.css","styles/globals.css","src/styles/globals.css","src/styles.css","src/index.css","src/style.css"],k={next:["next.config.js","next.config.mjs","next.config.ts"],vite:["vite.config.ts","vite.config.js","vite.config.mts","vite.config.mjs"]},x=["primereact","@mui/material","antd","@chakra-ui/react","@mantine/core","@fluentui/react"],I=["style-dictionary","@tokens-studio/sd-transforms","@vanilla-extract/css","styled-components","@emotion/react"];function A(n){try{return JSON.parse(u.readFileSync(n,"utf8"))}catch{return{}}}function h(n){if(n===void 0)return null;if(!Array.isArray(n)){let t=new Error("`adopt` in frontfriend.config.js must be an array.");throw t.code="FRONTFRIEND_CONFIG_VALIDATION",t}let e=n.filter(t=>!g.includes(t));if(e.length>0){let t=new Error(`Unknown Frontfriend adoption level: ${e.join(", ")}.`);throw t.code="FRONTFRIEND_CONFIG_VALIDATION",t}let i=n.includes("components")?2:n.includes("tokens")?1:0;return g.slice(0,i+1)}function _(n){for(let[e,i]of Object.entries(k)){let t=i.find(s=>u.existsSync(r.join(n,s)));if(!t)continue;let c=u.readFileSync(r.join(n,t),"utf8");return{buildTool:e,present:c.includes(`${m}/${e}`)}}return{buildTool:null,present:!1}}function v(n){let e=[r.join(n,"components","ui"),r.join(n,"src","components","ui"),r.join(n,"app","components","ui")].filter(c=>u.existsSync(c)),i=new Set;function t(c){for(let s of u.readdirSync(c,{withFileTypes:!0})){let o=r.join(c,s.name);if(s.isDirectory())t(o);else if(/\.(js|jsx|ts|tsx|vue)$/.test(s.name)){if(!u.readFileSync(o,"utf8").includes(m))continue;let a=r.basename(s.name,r.extname(s.name));i.add(a.toLowerCase()==="index"?r.basename(c):a.toLowerCase())}}}return e.forEach(t),[...i].sort()}function P(n){let e=A(r.join(n,"package.json")),i={...e.dependencies||{},...e.devDependencies||{}},t=i.tailwindcss||null,s=[A(r.join(n,"components.json"))?.tailwind?.css,...T].filter(Boolean).find(a=>u.existsSync(r.join(n,a))),o=s?u.readFileSync(r.join(n,s),"utf8"):"",l=I.filter(a=>i[a]);return!l.length&&/:root[\s\S]*--(?:color|spacing|font|radius)-[\w-]+\s*:/.test(o)&&!o.includes(`${m}/theme.css`)&&l.push("css-custom-properties"),{nativeTokens:{present:o.includes("/* Frontfriend managed native tokens: start */"),file:s||null},tailwind:{present:!!t,version:t,major:t&&Number((String(t).match(/\d+/)||[])[0])||null},componentsJson:u.existsSync(r.join(n,"components.json")),themeImport:{present:o.includes(`${m}/theme.css`)||/@import\s+["'][^"']*node_modules\/\.cache\/frontfriend\/theme\.css["']/.test(o),file:s||null},plugin:_(n),frontfriendComponents:v(n),foreignComponentLibraries:x.filter(a=>i[a]),foreignTokenSystems:l}}function D(n,e,{baseLibrary:i}={}){let t=h(n)||g,c=t.includes("tokens"),s=t.includes("components"),o=[];return c&&!e.themeImport.present&&!e.nativeTokens?.present&&o.push("Config adopts tokens, but the Frontfriend theme import was not observed."),!c&&e.themeImport.present&&o.push("Frontfriend tokens are present in CSS but are not adopted in config."),s&&i==="shadcn"&&!e.componentsJson&&o.push("Config adopts components, but components.json was not observed."),!s&&e.frontfriendComponents.length>0&&o.push("Frontfriend components are installed but are not adopted in config."),o}function L({apiUrl:n,token:e,ffId:i,name:t,adopt:c,observed:s,framework:o,primitive:l}){if(!n||!e||!i||!t||!o||l===void 0)return Promise.resolve({reported:!1,unavailable:!0});let a=new URL("/api/apps/sync",n),y=JSON.stringify({ffId:i,name:t,adopt:h(c),observed:s,runtime:"sdk",framework:o,primitive:l}),N=a.protocol==="https:"?O:E;return new Promise(d=>{let f=N.request(a,{method:"POST",headers:{authorization:`Bearer ${e}`,"content-type":"application/json","content-length":Buffer.byteLength(y)}},p=>{p.resume(),p.on("end",()=>{p.statusCode>=200&&p.statusCode<300?d({reported:!0,unavailable:!1}):d({reported:!1,unavailable:!0})})});f.on("error",()=>d({reported:!1,unavailable:!0})),f.setTimeout(1500,()=>{f.destroy(),d({reported:!1,unavailable:!0})}),f.end(y)})}module.exports={ADOPTION_LEVELS:g,normalizeAdopt:h,probeAdoption:P,adoptionWarnings:D,reportAdoption:L};