fleetbo-svro 1.0.26 → 1.0.27
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/dist/cli.cjs +31 -16
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var N=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(n){throw o=0,n}};var
|
|
3
|
-
`),f("\u2192 Created svro.schema.json at project root.")}function
|
|
2
|
+
var N=(t,o)=>()=>{try{return o||t((o={exports:{}}).exports,o),o.exports}catch(n){throw o=0,n}};var C=N((le,k)=>{var c=require("fs"),p=require("path"),J=require("https"),{execSync:L}=require("child_process"),A="\x1B[38;2;231;233;237m",$="\x1B[31m",T="\x1B[0m";function f(t){console.log(` ${A}${t}${T}`)}function u(t){console.error(` ${$}${t}${T}`)}function D(t){let o={};return t.forEach(n=>{if(n.startsWith("--")){let[s,r]=n.slice(2).split("=");s&&r&&(o[s]=r)}}),o}function S(t,o){try{let n=JSON.parse(c.readFileSync(t,"utf8"));return!!(n.dependencies&&n.dependencies[o]||n.devDependencies&&n.devDependencies[o])}catch{return!1}}function U(t,o){if(!S(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{u("\u26A0\uFE0F Automatic installation failed. Please run 'npm install fleetbo-svro' manually.")}}}function B(t){let o=p.join(t,"svro.schema.json");if(c.existsSync(o))return;let n=new Date().toISOString(),s={createdAt:n,patchedAt:n,schemaVersion:1,collections:{}};c.writeFileSync(o,JSON.stringify(s,null,2)+`
|
|
3
|
+
`),f("\u2192 Created svro.schema.json at project root.")}function q(t){let o=p.join(t,"src");if(!c.existsSync(o))return;let n=p.join(o,"fleetbo.d.ts");if(c.existsSync(n))return;let s=`/* eslint-disable */
|
|
4
4
|
/* prettier-ignore */
|
|
5
5
|
// @ts-nocheck
|
|
6
6
|
export {}
|
|
@@ -84,15 +84,15 @@ declare module 'react' {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
`;try{c.writeFileSync(n,
|
|
87
|
+
`;try{c.writeFileSync(n,s),f("\u2192 Created src/fleetbo.d.ts stub for instant IDE auto-completion.")}catch(r){u(`\u26A0\uFE0F Unable to create src/fleetbo.d.ts: ${r.message}`)}}function M(t){let o=p.join(t,"index.d.ts");c.existsSync(o)||f("\u2192 Verified index.d.ts presence.")}function V(t){let o=["tsconfig.json","jsconfig.json"];for(let n of o){let s=p.join(t,n);if(c.existsSync(s)){let r=new Date;c.utimesSync(s,r,r);break}}}function H(t){return new Promise((o,n)=>{let s=JSON.stringify({token:t}),r={hostname:"bootstrapproject-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},b=J.request(r,e=>{let i="";e.on("data",l=>{i+=l}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{o(JSON.parse(i))}catch{n(new Error("Invalid response received from Fleetbo server."))}else try{let l=JSON.parse(i);n(new Error(l.error||`Server error ${e.statusCode}`))}catch{n(new Error(`Server error ${e.statusCode}`))}})});b.on("error",e=>n(e)),b.write(s),b.end()})}async function W(t,o=[]){let n=p.join(t,".env");if(c.existsSync(n)&&c.readFileSync(n,"utf8").includes("VITE_FLEETBO_DB_KEY")){f("\u2192 Fleetbo environment variables already present in .env \u2014 skipping step.");return}let s=D(o),r=s.keyApp,b=s.token||s.bootstrapToken,e=s.email||"";(!r||!b)&&(u("\u26A0\uFE0F Missing required parameters."),u("\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(b)}catch(a){u(`\u26A0\uFE0F Token exchange failed: ${a.message}`),u("\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)&&(u("\u26A0\uFE0F Incomplete response from Fleetbo server."),process.exit(1));let l=`
|
|
88
88
|
VITE_FLEETBO_DB_KEY=${i.fleetboDBKey}
|
|
89
89
|
VITE_FLEETBO_ENTERPRISE_ID=${i.enterpriseId}
|
|
90
|
-
VITE_FLEETBO_KEY_APP=${
|
|
90
|
+
VITE_FLEETBO_KEY_APP=${r}
|
|
91
91
|
${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
92
|
-
`:""}`;c.appendFileSync(n,l),f(".env file updated successfully with Fleetbo keys!")}function O(t){let o=p.join(t,"svro.d.ts");if(c.existsSync(o))try{c.unlinkSync(o),f("\u2192 Removed legacy svro.d.ts from project root.")}catch{}}function I(t,o){if(process.env.FLEETBO_SKIP_TYPECHECK_SETUP)return;let n=p.join(t,"tsconfig.json"),
|
|
93
|
-
`),f(`\u2192 Updated ${p.basename(
|
|
94
|
-
`):
|
|
95
|
-
`+
|
|
92
|
+
`:""}`;c.appendFileSync(n,l),f(".env file updated successfully with Fleetbo keys!")}function O(t){let o=p.join(t,"svro.d.ts");if(c.existsSync(o))try{c.unlinkSync(o),f("\u2192 Removed legacy svro.d.ts from project root.")}catch{}}function I(t,o){if(process.env.FLEETBO_SKIP_TYPECHECK_SETUP)return;let n=p.join(t,"tsconfig.json"),s=p.join(t,"jsconfig.json"),r=c.existsSync(n)?n:s,b=!c.existsSync(r),e={};if(!b)try{e=JSON.parse(c.readFileSync(r,"utf8"))}catch{u(`\u26A0\uFE0F Unable to read ${p.basename(r)} (Invalid JSON).`);return}e.compilerOptions=e.compilerOptions||{};let i=!1,l=S(o,"react"),a=S(o,"vite");b?(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)),l&&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&&(c.writeFileSync(r,JSON.stringify(e,null,2)+`
|
|
93
|
+
`),f(`\u2192 Updated ${p.basename(r)}.`))}function j(t){let o=["src/app/layout.tsx","src/app/layout.jsx","app/layout.tsx","app/layout.jsx","src/pages/_app.tsx","src/pages/_app.jsx","pages/_app.tsx","pages/_app.jsx","src/main.tsx","src/main.jsx","src/main.ts","src/main.js","src/index.tsx","src/index.jsx","src/index.ts","src/index.js","src/App.tsx","src/App.jsx","src/App.vue","app.vue","src/routes/+layout.svelte","src/routes/+layout.ts","src/main.singletons.ts"];for(let n of o){let s=p.join(t,n);if(c.existsSync(s)){let r=c.readFileSync(s,"utf8");r.includes("fleetbo-svro")||(r.startsWith('"use client"')||r.startsWith("'use client'")?r=r.replace(/(['"]use client['"];?\r?\n)/,`$1import 'fleetbo-svro';
|
|
94
|
+
`):r=`import 'fleetbo-svro';
|
|
95
|
+
`+r,c.writeFileSync(s,r));return}}}function w(t,o){if(process.env.FLEETBO_SKIP_AUTOIMPORT_SETUP)return;let s=["vite.config.ts","vite.config.js","vite.config.mjs"].map(l=>p.join(t,l)).find(l=>c.existsSync(l));if(!s)return;let r;try{r=c.readFileSync(s,"utf8")}catch{return}let b="fleetbo-svro",e=r,i=`{
|
|
96
96
|
name: 'fleetbo-auto-runtime',
|
|
97
97
|
transform(code, id) {
|
|
98
98
|
if (!id.includes('node_modules') && !code.includes('fleetbo-svro') && /(src[\\\\/](main|index|App|root))\\.(jsx?|tsx?|vue|svelte)/i.test(id)) {
|
|
@@ -151,16 +151,31 @@ ${e?`VITE_FLEETBO_TESTER_EMAIL=${e}
|
|
|
151
151
|
}),`;if(e=e.slice(0,a)+h+e.slice(a),!e.includes("import AutoImport")){let P=[...e.matchAll(/^import .+;?$/gm)].pop(),v=`import AutoImport from 'unplugin-auto-import/vite';
|
|
152
152
|
`;if(P){let m=P.index+P[0].length;e=e.slice(0,m)+`
|
|
153
153
|
`+v+e.slice(m)}else e=v+e}}}if(!e.includes("fleetbo-auto-runtime")){let l=e.match(/plugins\s*:\s*\[/);if(l){let a=l.index+l[0].length;e=e.slice(0,a)+`
|
|
154
|
-
`+i+e.slice(a)}}e!==
|
|
155
|
-
`).forEach(
|
|
156
|
-
[Fleetbo] Initializing and configuring Fleetbo...`),await
|
|
154
|
+
`+i+e.slice(a)}}e!==r&&c.writeFileSync(s,e)}function K(t,o,n={}){let{skipSelfInstall:s=!1}=n,r=p.join(__dirname,"..");s||U(t,o),B(t),M(r),q(t),O(t),I(t,o),w(t,o),j(t)}k.exports={touchTsConfig:V,log:f,logError:u,handleAuthAndEnv:W,detectDependency:S,cleanupLegacyRootDts:O,patchJsOrTsConfig:I,attemptViteAutoImportPatch:w,injectUniversalRuntime:j,runFullSetup:K}});var g=require("fs"),F=require("path"),_=require("https"),{runFullSetup:X,handleAuthAndEnv:z,touchTsConfig:Y,attemptViteAutoImportPatch:G,injectUniversalRuntime:Q}=C(),Z="\x1B[34m",ee="\x1B[31m",R="\x1B[0m";function d(t){console.log(`${Z}${t}${R}`)}function y(t){console.error(`${ee}${t}${R}`)}function te(t,o){return new Promise((n,s)=>{let r=JSON.stringify({enterpriseID:t,schema:o}),b={hostname:"fleetbo-gatekeeper.fleetbo.workers.dev",path:"/sync-schema",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(r)}},e=_.request(b,i=>{let l="";i.on("data",a=>{l+=a}),i.on("end",()=>{i.statusCode>=200&&i.statusCode<300?n(JSON.parse(l)):s(new Error(`Edge sync failed with HTTP ${i.statusCode}`))})});e.on("error",i=>s(i)),e.write(r),e.end()})}function oe(t){let o=F.join(t,".env");if(!g.existsSync(o))return{};let n=g.readFileSync(o,"utf8"),s={};return n.split(`
|
|
155
|
+
`).forEach(r=>{let[b,...e]=r.split("=");b&&e.length>0&&(s[b.trim()]=e.join("=").trim())}),s}function ne(t){return new Promise((o,n)=>{let s=JSON.stringify({projectId:t,moduleName:"svro.schema.json"}),r={hostname:"getmodulecache-jqycakhlxa-uc.a.run.app",path:"/",method:"POST",headers:{"Content-Type":"application/json","Content-Length":Buffer.byteLength(s)}},b=_.request(r,e=>{let i="";e.on("data",l=>{i+=l}),e.on("end",()=>{if(e.statusCode>=200&&e.statusCode<300)try{let l=JSON.parse(i);if(l.success&&l.found&&l.module){let a=l.module.code||l.module.mockCode;o(typeof a=="string"?JSON.parse(a):a)}else n(new Error("Schema not found in Fleetbo Cloud."))}catch{n(new Error("Invalid JSON response received from Fleetbo server."))}else n(new Error(`Server error ${e.statusCode}`))})});b.on("error",e=>n(e)),b.write(s),b.end()})}var E=process.argv.slice(2),x=E[0];async function se(){let t=process.cwd(),o=F.join(t,"package.json");if(x==="init"||x==="doctor")d(`
|
|
156
|
+
[Fleetbo] Initializing and configuring Fleetbo...`),await z(t,E),X(t,o),d(`
|
|
157
157
|
[Fleetbo] Configuration completed successfully!
|
|
158
158
|
`),d(`
|
|
159
159
|
Next step:`),d(` npx fleetbo-svro sync (Sync cloud schema & generate IDE types)
|
|
160
|
-
`);else if(x==="sync"){let n=
|
|
161
|
-
`),d("\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(
|
|
162
|
-
|
|
163
|
-
export type
|
|
160
|
+
`);else if(x==="sync"){let n=E.includes("--dry-run");d(`[Fleetbo] Syncing schema...${n?" (dry-run)":""}`);let s=F.join(t,"svro.schema.json"),r=F.join(__dirname,".."),b=F.join(r,"index.d.ts"),e=F.join(t,"src","fleetbo.d.ts"),l=oe(t).VITE_FLEETBO_ENTERPRISE_ID;if(l)try{d("\u2192 Fetching latest svro.schema.json from Fleetbo OS...");let a=await ne(l);g.writeFileSync(s,JSON.stringify(a,null,2)+`
|
|
161
|
+
`),d("\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")),h=Object.keys(a.collections||{});if(l)try{await te(l,a),d("\u2192 Schema successfully sealed at Fleetbo Global Edge (O(1)).")}catch(m){y(`\u26A0\uFE0F Fleetbo Edge Shield sync warning: ${m.message}`)}let P=h.length>0?h.map(m=>`'${m}'`).join(" | "):"string",v=`// Generated by fleetbo-svro \u2014 Updated via fleetbo sync
|
|
162
|
+
|
|
163
|
+
export type KnownFleetboTables = ${P};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Tables scell\xE9es au contrat.
|
|
167
|
+
* Les tables non scell\xE9es restent autoris\xE9es pour le maquettage UX (Hint Cyan non bloquant).
|
|
168
|
+
*/
|
|
169
|
+
export type FleetboTables =
|
|
170
|
+
| KnownFleetboTables
|
|
171
|
+
| (string & {
|
|
172
|
+
/**
|
|
173
|
+
* [Fleetbo SVRO - Pending Contract]
|
|
174
|
+
* Collection non scell\xE9e dans svro.schema.json.
|
|
175
|
+
* Validez d'abord votre UX, puis soumettez le composant \xE0 Alex pour scellage.
|
|
176
|
+
*/
|
|
177
|
+
_fleetboPending?: never;
|
|
178
|
+
});
|
|
164
179
|
|
|
165
180
|
declare global {
|
|
166
181
|
interface ImportMetaEnv {
|
|
@@ -493,4 +508,4 @@ declare module 'svelte/elements' {
|
|
|
493
508
|
'fleetbo-reference': FleetboProp;
|
|
494
509
|
}
|
|
495
510
|
}
|
|
496
|
-
`;g.writeFileSync(e,m)}
|
|
511
|
+
`;g.writeFileSync(e,m)}Y(t),G(t,o),Q(t),d(`[Fleetbo] Schema synced successfully (${h.length} collection(s)).`),n&&d("\u2192 [Dry-run] Schema is valid.")}catch(a){y(`Error during synchronization: ${a.message}`),process.exit(1)}}else y('Unknown command. Usage: "npx fleetbo-svro init" or "npx fleetbo-svro sync"'),process.exit(1)}se().catch(t=>{y(`Fleetbo CLI Error: ${t.message}`),process.exit(1)});
|