fleetbo-svro 1.0.14 → 1.0.15

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 +15 -15
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var R=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(r){throw o=0,r}};var j=R((re,k)=>{var b=require("fs"),p=require("path"),J=require("https"),{execSync:L}=require("child_process"),$="\x1B[38;2;231;233;237m",D="\x1B[31m",x="\x1B[0m";function f(t){console.log(` ${$}${t}${x}`)}function d(t){console.error(` ${D}${t}${x}`)}function A(t){let o={};return t.forEach(r=>{if(r.startsWith("--")){let[s,l]=r.slice(2).split("=");s&&l&&(o[s]=l)}}),o}function E(t,o){try{let r=JSON.parse(b.readFileSync(t,"utf8"));return!!(r.dependencies&&r.dependencies[o]||r.devDependencies&&r.devDependencies[o])}catch{return!1}}function N(t,o){if(!E(o,"fleetbo-svro")){f("\u2192 Installing fleetbo-svro into the project...");try{L("npm install fleetbo-svro",{cwd:t,stdio:"inherit"}),f("fleetbo-svro installed successfully!")}catch{d("\u26A0\uFE0F Automatic installation failed. Please run 'npm install fleetbo-svro' manually.")}}}function U(t){let o=p.join(t,"svro.schema.json");if(b.existsSync(o))return;let r=new Date().toISOString(),s={createdAt:r,patchedAt:r,schemaVersion:1,collections:{}};b.writeFileSync(o,JSON.stringify(s,null,2)+`
2
+ var R=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(r){throw o=0,r}};var j=R((re,k)=>{var b=require("fs"),p=require("path"),J=require("https"),{execSync:L}=require("child_process"),$="\x1B[38;2;231;233;237m",D="\x1B[31m",T="\x1B[0m";function f(t){console.log(` ${$}${t}${T}`)}function d(t){console.error(` ${D}${t}${T}`)}function A(t){let o={};return t.forEach(r=>{if(r.startsWith("--")){let[s,l]=r.slice(2).split("=");s&&l&&(o[s]=l)}}),o}function E(t,o){try{let r=JSON.parse(b.readFileSync(t,"utf8"));return!!(r.dependencies&&r.dependencies[o]||r.devDependencies&&r.devDependencies[o])}catch{return!1}}function N(t,o){if(!E(o,"fleetbo-svro")){f("\u2192 Installing fleetbo-svro into the project...");try{L("npm install fleetbo-svro",{cwd:t,stdio:"inherit"}),f("fleetbo-svro installed successfully!")}catch{d("\u26A0\uFE0F Automatic installation failed. Please run 'npm install fleetbo-svro' manually.")}}}function U(t){let o=p.join(t,"svro.schema.json");if(b.existsSync(o))return;let r=new Date().toISOString(),s={createdAt:r,patchedAt:r,schemaVersion:1,collections:{}};b.writeFileSync(o,JSON.stringify(s,null,2)+`
3
3
  `),f("\u2192 Created svro.schema.json at project root.")}function B(t){let o=p.join(t,"src");if(!b.existsSync(o))return;let r=p.join(o,"auto-imports.d.ts");if(b.existsSync(r))return;let s=`/* eslint-disable */
4
4
  /* prettier-ignore */
5
5
  // @ts-nocheck
@@ -110,7 +110,7 @@ declare module 'svelte/elements' {
110
110
  'fleetbo-reference': FleetboProp;
111
111
  }
112
112
  }
113
- `;try{b.writeFileSync(r,s),f("\u2192 Created src/auto-imports.d.ts stub for instant IDE auto-completion.")}catch(l){d(`\u26A0\uFE0F Unable to create src/auto-imports.d.ts: ${l.message}`)}}function M(t){let o=p.join(t,"index.d.ts");b.existsSync(o)||f("\u2192 Verified index.d.ts presence.")}function q(t){let o=["tsconfig.json","jsconfig.json"];for(let r of o){let s=p.join(t,r);if(b.existsSync(s)){let l=new Date;b.utimesSync(s,l,l);break}}}function H(t){return new Promise((o,r)=>{let s=JSON.stringify({token:t}),l={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},c=J.request(l,e=>{let i="";e.on("data",n=>{i+=n}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{o(JSON.parse(i))}catch{r(new Error("Invalid response received from Fleetbo server."))}else try{let n=JSON.parse(i);r(new Error(n.error||`Server error ${e.statusCode}`))}catch{r(new Error(`Server error ${e.statusCode}`))}})});c.on("error",e=>r(e)),c.write(s),c.end()})}async function V(t,o=[]){let r=p.join(t,".env");if(b.existsSync(r)&&b.readFileSync(r,"utf8").includes("VITE_FLEETBO_DB_KEY")){f("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let s=A(o),l=s.keyApp,c=s.token||s.bootstrapToken,e=s.email||"";(!l||!c)&&(d("\u26A0\uFE0F Missing required parameters."),d("\u{1F449} Usage: npx fleetbo-svro init --keyApp=YOUR_KEY --token=YOUR_TOKEN"),process.exit(1)),f("\u2192 Exchanging bootstrap token for project keys...");let i;try{i=await H(c)}catch(a){d(`\u26A0\uFE0F Token exchange failed: ${a.message}`),d("\u{1F449} The token may have expired (15 min limit) or was already used. Please regenerate one from the Fleetbo dashboard."),process.exit(1)}(!i.enterpriseId||!i.fleetboDBKey)&&(d("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let n=`
113
+ `;try{b.writeFileSync(r,s),f("\u2192 Created src/auto-imports.d.ts stub for instant IDE auto-completion.")}catch(l){d(`\u26A0\uFE0F Unable to create src/auto-imports.d.ts: ${l.message}`)}}function M(t){let o=p.join(t,"index.d.ts");b.existsSync(o)||f("\u2192 Verified index.d.ts presence.")}function q(t){let o=["tsconfig.json","jsconfig.json"];for(let r of o){let s=p.join(t,r);if(b.existsSync(s)){let l=new Date;b.utimesSync(s,l,l);break}}}function V(t){return new Promise((o,r)=>{let s=JSON.stringify({token:t}),l={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},c=J.request(l,e=>{let i="";e.on("data",n=>{i+=n}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{o(JSON.parse(i))}catch{r(new Error("Invalid response received from Fleetbo server."))}else try{let n=JSON.parse(i);r(new Error(n.error||`Server error ${e.statusCode}`))}catch{r(new Error(`Server error ${e.statusCode}`))}})});c.on("error",e=>r(e)),c.write(s),c.end()})}async function H(t,o=[]){let r=p.join(t,".env");if(b.existsSync(r)&&b.readFileSync(r,"utf8").includes("VITE_FLEETBO_DB_KEY")){f("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let s=A(o),l=s.keyApp,c=s.token||s.bootstrapToken,e=s.email||"";(!l||!c)&&(d("\u26A0\uFE0F Missing required parameters."),d("\u{1F449} Usage: npx fleetbo-svro init --keyApp=YOUR_KEY --token=YOUR_TOKEN"),process.exit(1)),f("\u2192 Exchanging bootstrap token for project keys...");let i;try{i=await V(c)}catch(a){d(`\u26A0\uFE0F Token exchange failed: ${a.message}`),d("\u{1F449} The token may have expired (15 min limit) or was already used. Please regenerate one from the Fleetbo dashboard."),process.exit(1)}(!i.enterpriseId||!i.fleetboDBKey)&&(d("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let n=`
114
114
  VITE_FLEETBO_DB_KEY=${i.fleetboDBKey}
115
115
  VITE_FLEETBO_ENTERPRISE_ID=${i.enterpriseId}
116
116
  VITE_FLEETBO_KEY_APP=${l}
@@ -118,15 +118,15 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
118
118
  `:""}`;b.appendFileSync(r,n),f(".env file updated successfully with Fleetbo keys!")}function I(t){let o=p.join(t,"svro.d.ts");if(b.existsSync(o))try{b.unlinkSync(o),f("\u2192 Removed legacy svro.d.ts from project root.")}catch{}}function O(t,o){if(process.env.FLEETBO_SKIP_TYPECHECK_SETUP)return;let r=p.join(t,"tsconfig.json"),s=p.join(t,"jsconfig.json"),l=b.existsSync(r)?r:s,c=!b.existsSync(l),e={};if(!c)try{e=JSON.parse(b.readFileSync(l,"utf8"))}catch{d(`\u26A0\uFE0F Unable to read ${p.basename(l)} (Invalid JSON).`);return}e.compilerOptions=e.compilerOptions||{};let i=!1,n=E(o,"react"),a=E(o,"vite");c?(e.compilerOptions.checkJs=!0,e.compilerOptions.allowJs=!0,e.compilerOptions.target=e.compilerOptions.target||"ES2020",e.compilerOptions.module=e.compilerOptions.module||"ESNext",e.compilerOptions.moduleResolution=e.compilerOptions.moduleResolution||"bundler",e.include=e.include||["src"],i=!0):(e.compilerOptions.checkJs===void 0&&(e.compilerOptions.checkJs=!0,i=!0),e.compilerOptions.allowJs===void 0&&(e.compilerOptions.allowJs=!0,i=!0)),n&&e.compilerOptions.jsx===void 0&&(e.compilerOptions.jsx="react-jsx",i=!0),a&&e.compilerOptions.types===void 0&&(e.compilerOptions.types=["vite/client"],i=!0),i&&(b.writeFileSync(l,JSON.stringify(e,null,2)+`
119
119
  `),f(`\u2192 Updated ${p.basename(l)}.`))}function w(t,o){if(process.env.FLEETBO_SKIP_AUTOIMPORT_SETUP)return;let s=["vite.config.ts","vite.config.js","vite.config.mjs"].map(n=>p.join(t,n)).find(n=>b.existsSync(n));if(!s)return;let l;try{l=b.readFileSync(s,"utf8")}catch{return}let c="fleetbo-svro",e=l,i=`{
120
120
  name: 'fleetbo-schema-sync-middleware',
121
- transformIndexHtml() {
122
- return [
123
- {
124
- tag: 'script',
125
- attrs: { type: 'module' },
126
- children: "import 'fleetbo-svro';",
127
- injectTo: 'head-prepend'
128
- }
129
- ];
121
+ transform(code, id) {
122
+ // Intercepte le premier fichier d'entr\xE9e de l'application (main.* ou index.*)
123
+ if (/src[/\\\\](main|index).(jsx?|tsx?|vue|svelte)/.test(id) && !code.includes('fleetbo-svro')) {
124
+ return {
125
+ code: "import 'fleetbo-svro';\\n" + code,
126
+ map: null
127
+ };
128
+ }
129
+ return null;
130
130
  },
131
131
  configureServer(server) {
132
132
  server.middlewares.use('/__fleetbo_sync_schema', (req, res) => {
@@ -177,13 +177,13 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
177
177
  `;if(h){let u=h.index+h[0].length;e=e.slice(0,u)+`
178
178
  `+v+e.slice(u)}else e=v+e}}}if(!e.includes("transformIndexHtml")){if(e.includes("fleetbo-schema-sync-middleware")){let a=e.indexOf("{");e=e.replace(/\{[^{}]*name:\s*['"]fleetbo-schema-sync-middleware['"][\s\S]*?configureServer[\s\S]*?\}\s*\},?/g,"")}let n=e.match(/plugins\s*:\s*\[/);if(n){let a=n.index+n[0].length;e=e.slice(0,a)+`
179
179
  `+i+e.slice(a),f("\u2192 Updated Fleetbo Vite plugin with universal runtime injection.")}}if(e!==l)try{b.writeFileSync(s,e),f(`\u2192 Updated ${p.basename(s)} with Watcher and AutoImport configuration.`)}catch(n){d(`\u26A0\uFE0F Failed to write to ${p.basename(s)}: ${n.message}`)}try{let n=JSON.parse(b.readFileSync(o,"utf8"));n.devDependencies=n.devDependencies||{},n.devDependencies["unplugin-auto-import"]||(n.devDependencies["unplugin-auto-import"]="^0.18.0",b.writeFileSync(o,JSON.stringify(n,null,2)+`
180
- `),f("\u2192 Added unplugin-auto-import to devDependencies."))}catch(n){d(`\u26A0\uFE0F Failed to update ${p.basename(o)}: ${n.message}`)}}function W(t,o,r={}){let{skipSelfInstall:s=!1}=r,l=p.join(__dirname,"..");s||N(t,o),U(t),M(l),B(t),I(t),O(t,o),w(t,o)}k.exports={touchTsConfig:q,log:f,logError:d,handleAuthAndEnv:V,detectDependency:E,cleanupLegacyRootDts:I,patchJsOrTsConfig:O,attemptViteAutoImportPatch:w,runFullSetup:W}});var g=require("fs"),F=require("path"),C=require("https"),{runFullSetup:X,handleAuthAndEnv:K,touchTsConfig:G,attemptViteAutoImportPatch:Y}=j(),z="\x1B[34m",Q="\x1B[31m",_="\x1B[0m";function m(t){console.log(`${z}${t}${_}`)}function y(t){console.error(`${Q}${t}${_}`)}function Z(t,o){return new Promise((r,s)=>{let l=JSON.stringify({enterpriseID:t,schema:o}),c={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(l)}},e=C.request(c,i=>{let n="";i.on("data",a=>{n+=a}),i.on("end",()=>{i.statusCode>=200&&i.statusCode<300?r(JSON.parse(n)):s(new Error(`Edge sync failed with HTTP ${i.statusCode}`))})});e.on("error",i=>s(i)),e.write(l),e.end()})}function ee(t){let o=F.join(t,".env");if(!g.existsSync(o))return{};let r=g.readFileSync(o,"utf8"),s={};return r.split(`
181
- `).forEach(l=>{let[c,...e]=l.split("=");c&&e.length>0&&(s[c.trim()]=e.join("=").trim())}),s}function te(t){return new Promise((o,r)=>{let s=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),l={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},c=C.request(l,e=>{let i="";e.on("data",n=>{i+=n}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let n=JSON.parse(i);if(n.success&&n.found&&n.module){let a=n.module.code||n.module.mockCode;o(typeof a=="string"?JSON.parse(a):a)}else r(new Error("Schema not found in Fleetbo Cloud."))}catch{r(new Error("Invalid JSON response received from Fleetbo server."))}else r(new Error(`Server error ${e.statusCode}`))})});c.on("error",e=>r(e)),c.write(s),c.end()})}var T=process.argv.slice(2),S=T[0];async function oe(){let t=process.cwd(),o=F.join(t,"package.json");if(S==="init"||S==="doctor")m(`
182
- [Fleetbo] Initializing and configuring Fleetbo...`),await K(t,T),X(t,o),m(`
180
+ `),f("\u2192 Added unplugin-auto-import to devDependencies."))}catch(n){d(`\u26A0\uFE0F Failed to update ${p.basename(o)}: ${n.message}`)}}function W(t,o,r={}){let{skipSelfInstall:s=!1}=r,l=p.join(__dirname,"..");s||N(t,o),U(t),M(l),B(t),I(t),O(t,o),w(t,o)}k.exports={touchTsConfig:q,log:f,logError:d,handleAuthAndEnv:H,detectDependency:E,cleanupLegacyRootDts:I,patchJsOrTsConfig:O,attemptViteAutoImportPatch:w,runFullSetup:W}});var g=require("fs"),F=require("path"),C=require("https"),{runFullSetup:X,handleAuthAndEnv:K,touchTsConfig:G,attemptViteAutoImportPatch:Y}=j(),z="\x1B[34m",Q="\x1B[31m",_="\x1B[0m";function m(t){console.log(`${z}${t}${_}`)}function y(t){console.error(`${Q}${t}${_}`)}function Z(t,o){return new Promise((r,s)=>{let l=JSON.stringify({enterpriseID:t,schema:o}),c={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(l)}},e=C.request(c,i=>{let n="";i.on("data",a=>{n+=a}),i.on("end",()=>{i.statusCode>=200&&i.statusCode<300?r(JSON.parse(n)):s(new Error(`Edge sync failed with HTTP ${i.statusCode}`))})});e.on("error",i=>s(i)),e.write(l),e.end()})}function ee(t){let o=F.join(t,".env");if(!g.existsSync(o))return{};let r=g.readFileSync(o,"utf8"),s={};return r.split(`
181
+ `).forEach(l=>{let[c,...e]=l.split("=");c&&e.length>0&&(s[c.trim()]=e.join("=").trim())}),s}function te(t){return new Promise((o,r)=>{let s=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),l={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},c=C.request(l,e=>{let i="";e.on("data",n=>{i+=n}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let n=JSON.parse(i);if(n.success&&n.found&&n.module){let a=n.module.code||n.module.mockCode;o(typeof a=="string"?JSON.parse(a):a)}else r(new Error("Schema not found in Fleetbo Cloud."))}catch{r(new Error("Invalid JSON response received from Fleetbo server."))}else r(new Error(`Server error ${e.statusCode}`))})});c.on("error",e=>r(e)),c.write(s),c.end()})}var x=process.argv.slice(2),S=x[0];async function oe(){let t=process.cwd(),o=F.join(t,"package.json");if(S==="init"||S==="doctor")m(`
182
+ [Fleetbo] Initializing and configuring Fleetbo...`),await K(t,x),X(t,o),m(`
183
183
  [Fleetbo] Configuration completed successfully!
184
184
  `),m(`
185
185
  Next step:`),m(` npx fleetbo-svro sync (Sync cloud schema & generate IDE types)
186
- `);else if(S==="sync"){let r=T.includes("--dry-run");m(`[Fleetbo] Syncing schema...${r?" (dry-run)":""}`);let s=F.join(t,"svro.schema.json"),l=F.join(__dirname,".."),c=F.join(l,"index.d.ts"),e=F.join(t,"src","auto-imports.d.ts"),n=ee(t).VITE_FLEETBO_ENTERPRISE_ID;if(n)try{m("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let a=await te(n);g.writeFileSync(s,JSON.stringify(a,null,2)+`
186
+ `);else if(S==="sync"){let r=x.includes("--dry-run");m(`[Fleetbo] Syncing schema...${r?" (dry-run)":""}`);let s=F.join(t,"svro.schema.json"),l=F.join(__dirname,".."),c=F.join(l,"index.d.ts"),e=F.join(t,"src","auto-imports.d.ts"),n=ee(t).VITE_FLEETBO_ENTERPRISE_ID;if(n)try{m("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let a=await te(n);g.writeFileSync(s,JSON.stringify(a,null,2)+`
187
187
  `),m("\u2192 Local svro.schema.json updated from FLeetbo OS.")}catch(a){y(`\u26A0\uFE0F Cloud fetch bypassed: ${a.message}. Using local file fallback.`)}else y("\u26A0\uFE0F VITE_FLEETBO_ENTERPRISE_ID missing in .env. Skipping cloud fetch.");g.existsSync(s)||(y("Error: svro.schema.json not found."),process.exit(1));try{let a=JSON.parse(g.readFileSync(s,"utf8")),P=Object.keys(a.collections||{});if(n)try{await Z(n,a),m("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(u){y(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${u.message}`)}let h=P.length>0?P.map(u=>`'${u}'`).join(" | "):"string",v=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sync
188
188
 
189
189
  export type FleetboTables = ${h};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetbo-svro",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "types": "index.d.ts",