@nexushub/client 0.1.6 → 0.1.7

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 (2) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -54,7 +54,7 @@ This directory contains seed data for your NexusHub project.
54
54
  `));let r=n.apiKey||process.env.NEXUS_API_KEY||process.env.NEXT_PUBLIC_NEXUS_KEY,o=n.projectId||process.env.NEXUS_PROJECT_ID||process.env.NEXT_PUBLIC_NEXUS_ID,s=n.apiUrl||process.env.NEXUS_API_URL||process.env.NEXT_PUBLIC_NEXUS_API_URL||"https://api.nexushub.com/v1",a=n.output||".nexus";(!r||!o)&&(console.error(_.red("\u274C Missing API Key or Project ID")),console.log(_.gray("Set NEXUS_API_KEY and NEXUS_PROJECT_ID in .env or use --api-key and --project-id flags")),process.exit(1));let u=ke(`Fetching content for project: ${_.green(o)}...`).start();try{let d=J.default.join(process.cwd(),a),g=J.default.join(d,"cache.json");await U.pathExists(g)&&!n.force&&(u.stop(),console.log(_.yellow("\u26A0\uFE0F Cache file already exists. Use --force to overwrite.")),process.exit(0));let[m,p,y]=await Promise.all([Fr(`${s}/content/${o}/pages`,r),Ef(`${s}/content/${o}`,r,o),Fr(`${s}/projects/${o}/globals`,r)]),P={pages:m.data||m,collections:p,globals:y.data||y,meta:{pulledAt:new Date().toISOString(),projectId:o,apiUrl:s,count:{pages:(m.data||m).length,collections:Object.keys(p).length}}};await U.ensureDir(d),await U.writeJson(g,P,{spaces:2}),u.succeed(_.green("Content synced successfully!")),console.log(_.gray(` \u{1F4C1} Saved to: ${g}`)),console.log(_.gray(` \u{1F4CA} Pages: ${P.meta.count.pages}`)),console.log(_.gray(` \u{1F4DA} Collections: ${P.meta.count.collections}`)),console.log(_.yellow(" \u26A1 Mode: Offline / Local Cache Enabled"))}catch(d){u.fail(_.red("Failed to sync content")),console.error(_.red(` Error: ${d.message}`)),d.message.includes("401")||d.message.includes("403")?console.log(_.yellow(" \u{1F511} Check your API key and permissions")):d.message.includes("404")&&console.log(_.yellow(" \u{1F50D} Project not found. Check your project ID")),process.exit(1)}}async function Af(n){console.log(_.bold.cyan(`
55
55
  \u{1F331} NexusHub CLI - Content Seeding
56
56
  `));let r=n.apiKey||process.env.NEXUS_API_KEY,o=n.projectId||process.env.NEXUS_PROJECT_ID,s=n.apiUrl||process.env.NEXUS_API_URL||"https://api.nexushub.com/v1",a=n.input||".nexus/seed",u=n.dryRun||!1;(!r||!o)&&(console.error(_.red("\u274C Missing API Key or Project ID")),process.exit(1));let d=J.default.join(process.cwd(),a);await U.pathExists(d)||(console.error(_.red(`\u274C Seed directory not found: ${d}`)),console.log(_.gray("Create a seed directory with your content files:")),console.log(_.gray(" mkdir -p .nexus/seed")),console.log(_.gray(" # Add pages.json, collections/ folder, globals.json")),process.exit(1));let g=ke("Validating seed data...").start();try{let m=J.default.join(d,"pages.json"),p=J.default.join(d,"collections"),y=J.default.join(d,"globals.json"),P=0,v=0,L=0;if(await U.pathExists(m)){let S=await U.readJson(m);P=Array.isArray(S)?S.length:0,!u&&Array.isArray(S)&&(g.text=`Seeding ${S.length} pages...`,await xf(S,s,o,r))}if(await U.pathExists(p))if(u)v=(await U.readdir(p)).filter($=>$.endsWith(".json")).length;else{g.text="Seeding collections...";let S=await Bf(p,s,o,r);v=S.collections,L=S.items}if(await U.pathExists(y)){let S=await U.readJson(y);u||(g.text="Seeding globals...",await Of(S,s,o,r))}u?(g.succeed(_.green("Seed data validated successfully!")),console.log(_.gray(` \u{1F4C4} Pages: ${P}`)),console.log(_.gray(` \u{1F4DA} Collections: ${v}`)),console.log(_.gray(` \u{1F4E6} Items: ${L}`))):g.succeed(_.green("Content seeded successfully!"))}catch(m){g.fail(_.red("Failed to seed content")),console.error(_.red(` Error: ${m.message}`)),process.exit(1)}}async function xf(n,r,o,s){let a=[];for(let g of n)try{let m=await fe(`${r}/content/${o}/pages`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(g)});if(m.ok)a.push({slug:g.slug,success:!0});else{let p=await m.text();a.push({slug:g.slug,success:!1,error:p})}}catch(m){a.push({slug:g.slug,success:!1,error:m.message})}let u=a.filter(g=>g.success),d=a.filter(g=>!g.success);d.length>0&&(console.warn(_.yellow(` \u26A0\uFE0F ${d.length} pages failed:`)),d.forEach(g=>{console.log(_.gray(` - ${g.slug}: ${g.error}`))}))}async function Bf(n,r,o,s){let u=(await U.readdir(n)).filter(g=>g.endsWith(".json")),d=0;for(let g of u){let m=J.default.basename(g,".json"),p=J.default.join(n,g),y=await U.readJson(p);if(!Array.isArray(y)){console.warn(_.yellow(` \u26A0\uFE0F ${g} does not contain a valid array of items`));continue}try{await fe(`${r}/content/${o}/collections`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify({name:m,slug:m,description:"Auto-generated from seed data"})});let P=0;for(let v of y)try{await fe(`${r}/content/${o}/collections/${m}/items`,{method:"POST",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(v)}),P++}catch(L){console.warn(_.yellow(` Failed to create item in ${m}: ${L instanceof Error?L.message:String(L)}`))}console.log(_.gray(` \u2705 Created collection ${m} with ${P} items`)),d+=P}catch(P){console.warn(_.yellow(` \u274C Failed to create collection ${m}: ${P.message}`))}}return{collections:u.length,items:d}}async function Of(n,r,o,s){try{await fe(`${r}/projects/${o}/globals`,{method:"PUT",headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json"},body:JSON.stringify(n)}),console.log(_.gray(" \u2705 Created globals"))}catch(a){console.warn(_.yellow(` \u274C Failed to create globals: ${a.message}`))}}async function If(n){console.log(_.bold.cyan(`
57
- \u{1F680} NexusHub | Deployment Protocol Initiated`)),console.log(_.gray("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014"));let{apiKey:r,projectId:o,apiUrl:s}=await tl(),a=n.environment||"production",u=ke(`Authenticating infrastructure for ${_.bold(a)}...`).start();try{let d=await Fr(`${s}/projects/${o}`,r),g=d.data||d;if(!!(g.githubOwner&&g.githubRepo)){u.text="GitHub link detected. Triggering Remote Build Pipeline...";let p=await fe(`${s}/projects/${o}/deploy`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({environment:a,trigger:"cli"})});if(!p.ok)throw new Error(`Orchestrator Handshake Failed: ${p.statusText}`);let y=await p.json();u.succeed(_.green("Remote Build Enqueued Successfully!")),console.log(_.gray(` \u{1F517} Deployment ID: ${y.deploymentId}`)),console.log(_.gray(` \u{1F3E2} Repository: ${g.githubOwner}/${g.githubRepo}`)),console.log(_.gray(" \u{1F6F0}\uFE0F Track progress live in your NexusHub Dashboard."))}else{u.text="No Repository linked. Validating local build artifacts...";let p=J.default.join(process.cwd(),".next"),y=J.default.join(process.cwd(),".vercel","output","static"),P="";U.existsSync(y)?P=".vercel/output/static":U.existsSync(p)?P=".next":(u.fail(_.red("Build Artifacts Not Found.")),console.log(_.yellow(" Please compile your project before deploying manually:")),console.log(_.white(" npm run build")),process.exit(1)),u.succeed(_.gray(`Found build artifacts in /${P}`));let v=ke("Requesting secure Edge Access Token...").start(),L=await fe(`${s}/devops/projects/${o}/deploy/token`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(!L.ok)throw v.fail(_.red("Failed to acquire Edge Access Token")),new Error("Ensure your API Key has deployment privileges.");let{token:S}=await L.json();v.succeed(_.gray("Temporary Edge Token acquired (Expires in 15m)"));let $=ke("Pushing artifacts to Global Edge network...").start();try{let O=g.cloudflareProjectName||g.subdomain,M=g.cloudflareAccountId||process.env.CLOUDFLARE_ACCOUNT_ID;if(!M)throw new Error("Missing Cloudflare Account ID in environment or database.");let ee=`CLOUDFLARE_API_TOKEN=${S} CLOUDFLARE_ACCOUNT_ID=${M} npx wrangler pages deploy ${P} --project-name=${O} --branch=main`;(0,el.execSync)(ee,{stdio:"pipe"}),$.succeed(_.green("Direct Uplink Successful!"))}catch(O){$.fail(_.red("Wrangler Upload Failed")),console.error(_.red(` Details: ${O.stderr?O.stderr.toString():O.message}`)),process.exit(1)}let F=ke("Synchronizing deployment status with NexusHub...").start();try{await fe(`${s}/devops/projects/${o}/deploy/complete`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({status:"success",environment:a})}),F.succeed(_.green("Deployment synchronized."))}catch{F.warn(_.yellow("Site is live, but status sync to Dashboard failed."))}}console.log(_.gray("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014")),console.log(_.white("\u{1F30D} Live URL: ")+_.cyan(`https://${g.subdomain}.gnx.io`)),console.log(_.gray(`\u23F0 Completed at: ${new Date().toLocaleTimeString()}`))}catch(d){u.isSpinning&&u.fail(_.red("Uplink Interrupted")),console.error(_.red(`
57
+ \u{1F680} NexusHub | Deployment Protocol Initiated`)),console.log(_.gray("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014"));let{apiKey:r,projectId:o,apiUrl:s}=await tl(),a=n.environment||"production",u=ke(`Authenticating infrastructure for ${_.bold(a)}...`).start();try{let d=await Fr(`${s}/projects/${o}`,r),g=d.data||d;if(!!(g.githubOwner&&g.githubRepo)){u.text="GitHub link detected. Triggering Remote Build Pipeline...";let p=await fe(`${s}/projects/${o}/deploy`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({environment:a,trigger:"cli"})});if(!p.ok)throw new Error(`Orchestrator Handshake Failed: ${p.statusText}`);let y=await p.json();u.succeed(_.green("Remote Build Enqueued Successfully!")),console.log(_.gray(` \u{1F517} Deployment ID: ${y.deploymentId}`)),console.log(_.gray(` \u{1F3E2} Repository: ${g.githubOwner}/${g.githubRepo}`)),console.log(_.gray(" \u{1F6F0}\uFE0F Track progress live in your NexusHub Dashboard."))}else{u.text="No Repository linked. Validating local build artifacts...";let p=J.default.join(process.cwd(),".next"),y=J.default.join(process.cwd(),".vercel","output","static"),P="";U.existsSync(y)?P=".vercel/output/static":U.existsSync(p)?P=".next":(u.fail(_.red("Build Artifacts Not Found.")),console.log(_.yellow(" Please compile your project before deploying manually:")),console.log(_.white(" npm run build")),process.exit(1)),u.succeed(_.gray(`Found build artifacts in /${P}`));let v=ke("Requesting secure Edge Access Token...").start(),L=await fe(`${s}/devops/projects/${o}/deploy/token`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(!L.ok)throw v.fail(_.red("Failed to acquire Edge Access Token")),new Error("Ensure your API Key has deployment privileges.");let{token:S}=await L.json();v.succeed(_.gray("Temporary Edge Token acquired (Expires in 15m)"));let $=ke("Pushing artifacts to Global Edge network...").start();try{let O=g.cloudflareProjectName||g.subdomain,M=g.cloudflareAccountId||process.env.CLOUDFLARE_ACCOUNT_ID;if(!M)throw new Error("Missing Cloudflare Account ID in environment or database.");let ee=`CLOUDFLARE_API_TOKEN=${S} CLOUDFLARE_ACCOUNT_ID=${M} npx wrangler pages deploy ${P} --project-name=${O} --branch=main`;(0,el.execSync)(ee,{stdio:"pipe"}),$.succeed(_.green("Direct Uplink Successful!"))}catch(O){$.fail(_.red("Wrangler Upload Failed")),console.error(_.red(` Details: ${O.stderr?O.stderr.toString():O.message}`)),process.exit(1)}let F=ke("Synchronizing deployment status with NexusHub...").start();try{await fe(`${s}/devops/projects/${o}/deploy/complete`,{method:"POST",headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"},body:JSON.stringify({status:"success",environment:a})}),F.succeed(_.green("Deployment synchronized."))}catch{F.warn(_.yellow("Site is live, but status sync to Dashboard failed."))}}console.log(_.gray("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014")),console.log(_.white("\u{1F30D} Live URL: ")+_.cyan(`https://${g.subdomain}.gnexus.co.tz`)),console.log(_.gray(`\u23F0 Completed at: ${new Date().toLocaleTimeString()}`))}catch(d){u.isSpinning&&u.fail(_.red("Uplink Interrupted")),console.error(_.red(`
58
58
  \u274C Error: ${d.message}`)),process.exit(1)}}async function kf(n){console.log(_.bold.cyan(`
59
59
  \u{1F4CA} NexusHub CLI - Project Status
60
60
  `));let r=n.apiKey||process.env.NEXUS_API_KEY,o=n.projectId||process.env.NEXUS_PROJECT_ID,s=n.apiUrl||process.env.NEXUS_API_URL||"https://api.nexushub.com/v1";(!r||!o)&&(console.error(_.red("\u274C Missing API Key or Project ID")),process.exit(1));let a=ke("Fetching project status...").start();try{let u=await fe(`${s}/projects/${o}/status`,{headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json"}});if(u.ok){let d=await u.json();a.succeed(_.green("Project status retrieved!")),console.log(_.gray(` \u{1F4CB} Project: ${d.project.name}`)),console.log(_.gray(` \u{1F194} ID: ${d.project.id}`)),console.log(_.gray(` \u{1F4C4} Pages: ${d.stats.pages}`)),console.log(_.gray(` \u{1F4DA} Collections: ${d.stats.collections}`)),console.log(_.gray(` \u{1F465} Users: ${d.stats.users}`)),console.log(_.gray(` \u{1F552} Last Updated: ${new Date(d.project.updatedAt).toLocaleString()}`))}else throw new Error(`API Error ${u.status}: ${u.statusText}`)}catch(u){a.fail(_.red("Failed to fetch project status")),console.error(_.red(` Error: ${u.message}`)),process.exit(1)}}async function Df(n){let{apiKey:r,projectId:o,apiUrl:s}=await tl(),a=ke("Fetching Content Schema...").start();try{let u=await fe(`${s}/content/${o}/schema`,{headers:{Authorization:`Bearer ${r}`}});if(!u.ok)throw new Error(`API Error: ${u.statusText}`);let g=(await u.json()).collections||[],m=`/**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nexushub/client",
3
3
  "private": false,
4
- "version": "0.1.6",
4
+ "version": "0.1.7",
5
5
  "description": "The God-Tier NexusHub SDK",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",