fleetbo-svro 1.0.3 → 1.0.4

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 +16 -14
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var j=(t,n)=>()=>{try{return n||t((n={exports:{}}).exports,n),n.exports}catch(o){throw n=0,o}};var k=j((ne,w)=>{var c=require("fs"),u=require("path"),C=require("https"),{execSync:N}=require("child_process"),L="\x1B[38;2;231;233;237m",A="\x1B[31m",x="\x1B[0m";function b(t){console.log(` ${L}${t}${x}`)}function g(t){console.error(` ${A}${t}${x}`)}function D(t){let n={};return t.forEach(o=>{if(o.startsWith("--")){let[r,i]=o.slice(2).split("=");r&&i&&(n[r]=i)}}),n}function E(t,n){try{let o=JSON.parse(c.readFileSync(t,"utf8"));return!!(o.dependencies&&o.dependencies[n]||o.devDependencies&&o.devDependencies[n])}catch{return!1}}function $(t,n){if(!E(n,"fleetbo-svro")){b("\u2192 Installing fleetbo-svro into the project...");try{N("npm install fleetbo-svro",{cwd:t,stdio:"inherit"}),b("fleetbo-svro installed successfully!")}catch{g("\u26A0\uFE0F Automatic installation failed. Please run 'npm install fleetbo-svro' manually.")}}}function J(t){let n=u.join(t,"svro.schema.json");if(c.existsSync(n))return;let o=new Date().toISOString(),r={createdAt:o,patchedAt:o,schemaVersion:1,collections:{}};c.writeFileSync(n,JSON.stringify(r,null,2)+`
2
+ var N=(t,n)=>()=>{try{return n||t((n={exports:{}}).exports,n),n.exports}catch(o){throw n=0,o}};var k=N((ne,w)=>{var c=require("fs"),u=require("path"),j=require("https"),{execSync:C}=require("child_process"),L="\x1B[38;2;231;233;237m",A="\x1B[31m",x="\x1B[0m";function b(t){console.log(` ${L}${t}${x}`)}function g(t){console.error(` ${A}${t}${x}`)}function D(t){let n={};return t.forEach(o=>{if(o.startsWith("--")){let[r,i]=o.slice(2).split("=");r&&i&&(n[r]=i)}}),n}function E(t,n){try{let o=JSON.parse(c.readFileSync(t,"utf8"));return!!(o.dependencies&&o.dependencies[n]||o.devDependencies&&o.devDependencies[n])}catch{return!1}}function $(t,n){if(!E(n,"fleetbo-svro")){b("\u2192 Installing fleetbo-svro into the project...");try{C("npm install fleetbo-svro",{cwd:t,stdio:"inherit"}),b("fleetbo-svro installed successfully!")}catch{g("\u26A0\uFE0F Automatic installation failed. Please run 'npm install fleetbo-svro' manually.")}}}function J(t){let n=u.join(t,"svro.schema.json");if(c.existsSync(n))return;let o=new Date().toISOString(),r={createdAt:o,patchedAt:o,schemaVersion:1,collections:{}};c.writeFileSync(n,JSON.stringify(r,null,2)+`
3
3
  `),b("\u2192 Created svro.schema.json at project root.")}function M(t){let n=u.join(t,"src");if(!c.existsSync(n))return;let o=u.join(n,"auto-imports.d.ts");if(c.existsSync(o))return;let r=`/* eslint-disable */
4
4
  /* prettier-ignore */
5
5
  // @ts-nocheck
@@ -9,7 +9,7 @@ declare global {
9
9
  const Fleetbo: typeof import('fleetbo-svro')['Fleetbo']
10
10
  const FleetboUI: typeof import('fleetbo-svro')['FleetboUI']
11
11
  }
12
- `;try{c.writeFileSync(o,r),b("\u2192 Created src/auto-imports.d.ts stub for instant IDE auto-completion.")}catch(i){g(`\u26A0\uFE0F Unable to create src/auto-imports.d.ts: ${i.message}`)}}function B(t){let n=["tsconfig.json","jsconfig.json"];for(let o of n){let r=u.join(t,o);if(c.existsSync(r)){let i=new Date;c.utimesSync(r,i,i);break}}}function q(t){let n=u.join(t,"index.d.ts");if(c.existsSync(n))return;c.writeFileSync(n,`// File generated/synchronized by fleetbo-svro \u2014 do not edit manually
12
+ `;try{c.writeFileSync(o,r),b("\u2192 Created src/auto-imports.d.ts stub for instant IDE auto-completion.")}catch(i){g(`\u26A0\uFE0F Unable to create src/auto-imports.d.ts: ${i.message}`)}}function B(t){let n=["tsconfig.json","jsconfig.json"];for(let o of n){let r=u.join(t,o);if(c.existsSync(r)){let i=new Date;c.utimesSync(r,i,i);break}}}function W(t){let n=u.join(t,"index.d.ts");if(c.existsSync(n))return;c.writeFileSync(n,`// File generated/synchronized by fleetbo-svro \u2014 do not edit manually
13
13
 
14
14
  export type FleetboTables = string;
15
15
 
@@ -183,7 +183,7 @@ declare global {
183
183
  FleetboUI: typeof FleetboUI;
184
184
  }
185
185
  }
186
- `),b("\u2192 Initialized index.d.ts.")}function W(t){return new Promise((n,o)=>{let r=JSON.stringify({token:t}),i={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},d=C.request(i,e=>{let l="";e.on("data",s=>{l+=s}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{n(JSON.parse(l))}catch{o(new Error("Invalid response received from Fleetbo server."))}else try{let s=JSON.parse(l);o(new Error(s.error||`Server error ${e.statusCode}`))}catch{o(new Error(`Server error ${e.statusCode}`))}})});d.on("error",e=>o(e)),d.write(r),d.end()})}async function H(t,n=[]){let o=u.join(t,".env");if(c.existsSync(o)&&c.readFileSync(o,"utf8").includes("VITE_FLEETBO_DB_KEY")){b("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let r=D(n),i=r.keyApp,d=r.token||r.bootstrapToken,e=r.email||"";(!i||!d)&&(g("\u26A0\uFE0F Missing required parameters."),g("\u{1F449} Usage: npx fleetbo-svro init --keyApp=YOUR_KEY --token=YOUR_TOKEN"),process.exit(1)),b("\u2192 Exchanging bootstrap token for project keys...");let l;try{l=await W(d)}catch(a){g(`\u26A0\uFE0F Token exchange failed: ${a.message}`),g("\u{1F449} The token may have expired (15 min limit) or was already used. Please regenerate one from the Fleetbo dashboard."),process.exit(1)}(!l.enterpriseId||!l.fleetboDBKey)&&(g("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let s=`
186
+ `),b("\u2192 Initialized index.d.ts.")}function q(t){return new Promise((n,o)=>{let r=JSON.stringify({token:t}),i={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},d=j.request(i,e=>{let l="";e.on("data",s=>{l+=s}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{n(JSON.parse(l))}catch{o(new Error("Invalid response received from Fleetbo server."))}else try{let s=JSON.parse(l);o(new Error(s.error||`Server error ${e.statusCode}`))}catch{o(new Error(`Server error ${e.statusCode}`))}})});d.on("error",e=>o(e)),d.write(r),d.end()})}async function H(t,n=[]){let o=u.join(t,".env");if(c.existsSync(o)&&c.readFileSync(o,"utf8").includes("VITE_FLEETBO_DB_KEY")){b("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let r=D(n),i=r.keyApp,d=r.token||r.bootstrapToken,e=r.email||"";(!i||!d)&&(g("\u26A0\uFE0F Missing required parameters."),g("\u{1F449} Usage: npx fleetbo-svro init --keyApp=YOUR_KEY --token=YOUR_TOKEN"),process.exit(1)),b("\u2192 Exchanging bootstrap token for project keys...");let l;try{l=await q(d)}catch(a){g(`\u26A0\uFE0F Token exchange failed: ${a.message}`),g("\u{1F449} The token may have expired (15 min limit) or was already used. Please regenerate one from the Fleetbo dashboard."),process.exit(1)}(!l.enterpriseId||!l.fleetboDBKey)&&(g("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let s=`
187
187
  VITE_FLEETBO_DB_KEY=${l.fleetboDBKey}
188
188
  VITE_FLEETBO_ENTERPRISE_ID=${l.enterpriseId}
189
189
  VITE_FLEETBO_KEY_APP=${i}
@@ -206,9 +206,9 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
206
206
  const schemaPath = path.join(process.cwd(), 'svro.schema.json');
207
207
  fs.writeFileSync(schemaPath, JSON.stringify(schema, null, 2) + '\\n');
208
208
  try {
209
- execSync('node ./node_modules/fleetbo-svro/bin/cli.js sql sync', { stdio: 'ignore' });
209
+ execSync('node ./node_modules/fleetbo-svro/bin/cli.js sync', { stdio: 'ignore' });
210
210
  } catch (_) {
211
- execSync('npx fleetbo-svro sql sync', { stdio: 'ignore' });
211
+ execSync('npx fleetbo-svro sync', { stdio: 'ignore' });
212
212
  }
213
213
  }
214
214
  res.writeHead(200, { 'Content-Type': 'application/json' });
@@ -237,15 +237,17 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
237
237
  imports: [{ '${d}': ['Fleetbo', 'FleetboUI'] }],
238
238
  dts: 'src/auto-imports.d.ts'
239
239
  }),`;if(e=e.slice(0,a)+F+e.slice(a),!e.includes("import AutoImport")){let T=[...e.matchAll(/^import .+;?$/gm)].pop(),v=`import AutoImport from 'unplugin-auto-import/vite';
240
- `;if(T){let f=T.index+T[0].length;e=e.slice(0,f)+`
241
- `+v+e.slice(f)}else e=v+e}}}if(e.includes("__fleetbo_sync_schema")){if(e.includes("require('fs')")||e.includes('require("fs")')){let s=/\{\s*name:\s*['"]fleetbo-schema-sync-middleware['"][\s\S]*?\},/g;s.test(e)&&(e=e.replace(s,l),b("\u2192 Updated legacy Fleetbo middleware to modern ESM version."))}}else{let s=e.match(/plugins\s*:\s*\[/);if(s){let a=s.index+s[0].length;e=e.slice(0,a)+`
240
+ `;if(T){let m=T.index+T[0].length;e=e.slice(0,m)+`
241
+ `+v+e.slice(m)}else e=v+e}}}if(e.includes("__fleetbo_sync_schema")){if(e.includes("require('fs')")||e.includes('require("fs")')){let s=/\{\s*name:\s*['"]fleetbo-schema-sync-middleware['"][\s\S]*?\},/g;s.test(e)&&(e=e.replace(s,l),b("\u2192 Updated legacy Fleetbo middleware to modern ESM version."))}}else{let s=e.match(/plugins\s*:\s*\[/);if(s){let a=s.index+s[0].length;e=e.slice(0,a)+`
242
242
  `+l+e.slice(a)}}if(e!==i)try{c.writeFileSync(r,e),b(`\u2192 Updated ${u.basename(r)} with Watcher and AutoImport configuration.`)}catch(s){g(`\u26A0\uFE0F Failed to write to ${u.basename(r)}: ${s.message}`)}try{let s=JSON.parse(c.readFileSync(n,"utf8"));s.devDependencies=s.devDependencies||{},s.devDependencies["unplugin-auto-import"]||(s.devDependencies["unplugin-auto-import"]="^0.18.0",c.writeFileSync(n,JSON.stringify(s,null,2)+`
243
- `),b("\u2192 Added unplugin-auto-import to devDependencies."))}catch(s){g(`\u26A0\uFE0F Failed to update ${u.basename(n)}: ${s.message}`)}}function V(t,n,o={}){let{skipSelfInstall:r=!1}=o,i=u.join(__dirname,"..");r||$(t,n),J(t),q(i),M(t),O(t),P(t,n),R(t,n)}w.exports={touchTsConfig:B,log:b,logError:g,handleAuthAndEnv:H,detectDependency:E,cleanupLegacyRootDts:O,patchJsOrTsConfig:P,attemptViteAutoImportPatch:R,runFullSetup:V}});var p=require("fs"),y=require("path"),_=require("https"),{runFullSetup:K,handleAuthAndEnv:Y,touchTsConfig:G}=k(),z="\x1B[34m",X="\x1B[31m",U="\x1B[0m";function m(t){console.log(`${z}${t}${U}`)}function h(t){console.error(`${X}${t}${U}`)}function Q(t,n){return new Promise((o,r)=>{let i=JSON.stringify({enterpriseID:t,schema:n}),d={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(i)}},e=_.request(d,l=>{let s="";l.on("data",a=>{s+=a}),l.on("end",()=>{l.statusCode>=200&&l.statusCode<300?o(JSON.parse(s)):r(new Error(`Edge sync failed with HTTP ${l.statusCode}`))})});e.on("error",l=>r(l)),e.write(i),e.end()})}function Z(t){let n=y.join(t,".env");if(!p.existsSync(n))return{};let o=p.readFileSync(n,"utf8"),r={};return o.split(`
244
- `).forEach(i=>{let[d,...e]=i.split("=");d&&e.length>0&&(r[d.trim()]=e.join("=").trim())}),r}function ee(t){return new Promise((n,o)=>{let r=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),i={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},d=_.request(i,e=>{let l="";e.on("data",s=>{l+=s}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let s=JSON.parse(l);if(s.success&&s.found&&s.module){let a=s.module.code||s.module.mockCode;n(typeof a=="string"?JSON.parse(a):a)}else o(new Error("Schema not found in Fleetbo Cloud."))}catch{o(new Error("Invalid JSON response received from Fleetbo server."))}else o(new Error(`Server error ${e.statusCode}`))})});d.on("error",e=>o(e)),d.write(r),d.end()})}var I=process.argv.slice(2),S=I[0];async function te(){let t=process.cwd(),n=y.join(t,"package.json");if(S==="init"||S==="doctor")m(`
245
- [Fleetbo] Initializing and configuring Fleetbo...`),await Y(t,I),K(t,n),m(`
243
+ `),b("\u2192 Added unplugin-auto-import to devDependencies."))}catch(s){g(`\u26A0\uFE0F Failed to update ${u.basename(n)}: ${s.message}`)}}function V(t,n,o={}){let{skipSelfInstall:r=!1}=o,i=u.join(__dirname,"..");r||$(t,n),J(t),W(i),M(t),O(t),P(t,n),R(t,n)}w.exports={touchTsConfig:B,log:b,logError:g,handleAuthAndEnv:H,detectDependency:E,cleanupLegacyRootDts:O,patchJsOrTsConfig:P,attemptViteAutoImportPatch:R,runFullSetup:V}});var p=require("fs"),y=require("path"),_=require("https"),{runFullSetup:K,handleAuthAndEnv:Y,touchTsConfig:G}=k(),z="\x1B[34m",X="\x1B[31m",U="\x1B[0m";function f(t){console.log(`${z}${t}${U}`)}function h(t){console.error(`${X}${t}${U}`)}function Q(t,n){return new Promise((o,r)=>{let i=JSON.stringify({enterpriseID:t,schema:n}),d={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(i)}},e=_.request(d,l=>{let s="";l.on("data",a=>{s+=a}),l.on("end",()=>{l.statusCode>=200&&l.statusCode<300?o(JSON.parse(s)):r(new Error(`Edge sync failed with HTTP ${l.statusCode}`))})});e.on("error",l=>r(l)),e.write(i),e.end()})}function Z(t){let n=y.join(t,".env");if(!p.existsSync(n))return{};let o=p.readFileSync(n,"utf8"),r={};return o.split(`
244
+ `).forEach(i=>{let[d,...e]=i.split("=");d&&e.length>0&&(r[d.trim()]=e.join("=").trim())}),r}function ee(t){return new Promise((n,o)=>{let r=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),i={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},d=_.request(i,e=>{let l="";e.on("data",s=>{l+=s}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let s=JSON.parse(l);if(s.success&&s.found&&s.module){let a=s.module.code||s.module.mockCode;n(typeof a=="string"?JSON.parse(a):a)}else o(new Error("Schema not found in Fleetbo Cloud."))}catch{o(new Error("Invalid JSON response received from Fleetbo server."))}else o(new Error(`Server error ${e.statusCode}`))})});d.on("error",e=>o(e)),d.write(r),d.end()})}var S=process.argv.slice(2),I=S[0];async function te(){let t=process.cwd(),n=y.join(t,"package.json");if(I==="init"||I==="doctor")f(`
245
+ [Fleetbo] Initializing and configuring Fleetbo...`),await Y(t,S),K(t,n),f(`
246
246
  [Fleetbo] Configuration completed successfully!
247
- `);else if(S==="sql"&&I[1]==="sync"){let o=I.includes("--dry-run");m(`[Fleetbo] Syncing schema...${o?" (dry-run)":""}`);let r=y.join(t,"svro.schema.json"),i=y.join(__dirname,".."),d=y.join(i,"index.d.ts"),e=y.join(t,"src","auto-imports.d.ts"),s=Z(t).VITE_FLEETBO_ENTERPRISE_ID;if(s)try{m("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let a=await ee(s);p.writeFileSync(r,JSON.stringify(a,null,2)+`
248
- `),m("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(a){h(`\u26A0\uFE0F Cloud fetch bypassed: ${a.message}. Using local file fallback.`)}else h("\u26A0\uFE0F VITE_FLEETBO_ENTERPRISE_ID missing in .env. Skipping cloud fetch.");p.existsSync(r)||(h("Error: svro.schema.json not found."),process.exit(1));try{let a=JSON.parse(p.readFileSync(r,"utf8")),F=Object.keys(a.collections||{});if(s)try{await Q(s,a),m("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(f){h(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${f.message}`)}let T=F.length>0?F.map(f=>`'${f}'`).join(" | "):"string",v=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sql sync
247
+ `),f(`
248
+ Next step:`),f(` npx fleetbo-svro sync (Sync cloud schema & generate IDE types)
249
+ `);else if(I==="sync"){let o=S.includes("--dry-run");f(`[Fleetbo] Syncing schema...${o?" (dry-run)":""}`);let r=y.join(t,"svro.schema.json"),i=y.join(__dirname,".."),d=y.join(i,"index.d.ts"),e=y.join(t,"src","auto-imports.d.ts"),s=Z(t).VITE_FLEETBO_ENTERPRISE_ID;if(s)try{f("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let a=await ee(s);p.writeFileSync(r,JSON.stringify(a,null,2)+`
250
+ `),f("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(a){h(`\u26A0\uFE0F Cloud fetch bypassed: ${a.message}. Using local file fallback.`)}else h("\u26A0\uFE0F VITE_FLEETBO_ENTERPRISE_ID missing in .env. Skipping cloud fetch.");p.existsSync(r)||(h("Error: svro.schema.json not found."),process.exit(1));try{let a=JSON.parse(p.readFileSync(r,"utf8")),F=Object.keys(a.collections||{});if(s)try{await Q(s,a),f("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(m){h(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${m.message}`)}let T=F.length>0?F.map(m=>`'${m}'`).join(" | "):"string",v=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sql sync
249
251
 
250
252
  export type FleetboTables = ${T};
251
253
 
@@ -419,7 +421,7 @@ declare global {
419
421
  FleetboUI: typeof FleetboUI;
420
422
  }
421
423
  }
422
- `;if(p.writeFileSync(d,v),p.existsSync(y.dirname(e))){let f=`/* eslint-disable */
424
+ `;if(p.writeFileSync(d,v),p.existsSync(y.dirname(e))){let m=`/* eslint-disable */
423
425
  /* prettier-ignore */
424
426
  // @ts-nocheck
425
427
  // Generated by fleetbo-svro \u2014 Updated via fleetbo sql sync
@@ -429,4 +431,4 @@ declare global {
429
431
  const Fleetbo: typeof import('fleetbo-svro')['Fleetbo'];
430
432
  const FleetboUI: typeof import('fleetbo-svro')['FleetboUI'];
431
433
  }
432
- `;p.writeFileSync(e,f)}G(t),m(`[Fleetbo] Schema synced successfully (${F.length} collection(s)).`),o&&m("\u2192 [Dry-run] Schema is valid.")}catch(a){h(`Error during synchronization: ${a.message}`),process.exit(1)}}else h('Unknown command. Usage: "npx fleetbo-svro init --keyApp=xxx --token=yyy"'),process.exit(1)}te().catch(t=>{h(`Fleetbo CLI Error: ${t.message}`),process.exit(1)});
434
+ `;p.writeFileSync(e,m)}G(t),f(`[Fleetbo] Schema synced successfully (${F.length} collection(s)).`),o&&f("\u2192 [Dry-run] Schema is valid.")}catch(a){h(`Error during synchronization: ${a.message}`),process.exit(1)}}else h('Unknown command. Usage: "npx fleetbo-svro init" or "npx fleetbo-svro sync"'),process.exit(1)}te().catch(t=>{h(`Fleetbo CLI Error: ${t.message}`),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbo-svro",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "types": "index.d.ts",