stellate 2.14.0 → 2.14.1
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/bin.js +23 -23
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -1104,7 +1104,7 @@ Try running "stellate pull" first if your service has been created already.`);le
|
|
|
1104
1104
|
|
|
1105
1105
|
-s, --service Name of the service
|
|
1106
1106
|
-b, --browser Automatically open the preview UI with the default browser
|
|
1107
|
-
`);var An=Ne(hs());var kv=Ne(hs());var lN=class{async parse(e){return Yi(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.14.
|
|
1107
|
+
`);var An=Ne(hs());var kv=Ne(hs());var lN=class{async parse(e){return Yi(e,{"--help":Boolean,"-h":"--help","--version":Boolean,"-v":"--version","--json":Boolean})["--help"]?this.help():"stellate@2.14.1"}help(e){if(e)throw new Ss(`
|
|
1108
1108
|
${kv.default.bold.red("!")} ${e}
|
|
1109
1109
|
${lN.help}`);return lN.help}},Uy=lN;Uy.help=Hi(`
|
|
1110
1110
|
Print current version of Stellate
|
|
@@ -1306,18 +1306,18 @@ ${ZN.help}`);return ZN.help}},Iw=ZN;Iw.help=Hi(`
|
|
|
1306
1306
|
|
|
1307
1307
|
`);var As=Ne(hs()),SDe=Ne(ip()),dX=Ne(require("is-ci"));var Ow=Ne(hs()),fX="stellate_cache";function vDe(t,e,r){let i=[],s=t.getDirective(fX);if(!s)return r;if(!(s.locations.includes(pt.FIELD_DEFINITION)&&s.locations.includes(pt.OBJECT)))return console.warn(Ow.default.yellowBright("The @stellate_cache defined by the schema is defined for unexpected locations, expected are 'FIELD_DEFINITION' and 'OBJECT'.")),r;if(!s.args.find(c=>c.name==="maxAge"))return console.warn(Ow.default.yellowBright("The @stellate_cache directive defined by the schema is missing the 'maxAge: Int!' argument.")),r;if(!s.args.find(c=>c.name==="swr"))return console.warn(Ow.default.yellowBright("The @stellate_cache directive defined by the schema is missing the 'swr: Int' argument.")),r;if(!s.args.find(c=>c.name==="scope"))return console.warn(Ow.default.yellowBright("The @stellate_cache directive defined by the schema is missing the 'scope: String' argument.")),r;let u=Object.entries(t.getTypeMap()).map(([c,p])=>c.startsWith("__")?void 0:p).filter(Boolean);for(let c=0;c<u.length;c++){let p=u[c];if(!$e(p))continue;let d=Sw(t,p,fX);if(d&&d.length){let[h]=d;if(h.scope&&!e.includes(h.scope))throw new Error(`Found scope "${h.scope}" in the schema but not in the stellate config.`);i.push({type:p.name,field:void 0,...h})}let f=Object.values(p.getFields());for(let h=0;h<f.length;h++){let m=f[h],g=Sw(t,m,fX);if(!g||!g.length)continue;let[b]=g;if(b.scope&&!e.includes(b.scope))throw new Error(`Found scope "${b.scope}" in the schema but not in the stellate config.`);i.push({type:p.name,field:m.name,...b})}}return i.reduce((c,p)=>{let d=Zfr(p,c);if(!d)c.push({description:"This rule was generated from schema-directives",types:{[p.type]:p.field?[p.field]:!0},maxAge:p.maxAge,swr:p.swr,scope:p.scope});else if(p.field)if(Array.isArray(d.types[p.type]))d.types[p.type].includes(p.field)||d.types[p.type].push(p.field);else if(!d.types[p.type])d.types[p.type]=[p.field];else throw new Error(`Found "${typeof d.types[p.type]}" for "${p.type}" which is unexpected, file an issue at https://github.com/StellateHQ/cli/issues`);else Array.isArray(d.types[p.type])?c.push({description:"This rule was generated from schema-directives",types:{[p.type]:p.field?[p.field]:!0},maxAge:p.maxAge,swr:p.swr,scope:p.scope}):d.types[p.type]=!0;return c},r)}function Zfr(t,e){let r=e.filter(i=>i.maxAge===t.maxAge);if(r.length)if(t.swr){let i=r.filter(s=>s.swr===t.swr);if(t.scope){let s=i.filter(n=>n.scope===t.scope);return t.field?s.find(n=>Array.isArray(n.types[t.type])):s.find(n=>!n.types[t.type])}else{let s=i.filter(n=>!n.scope);return t.field?s.find(n=>Array.isArray(n.types[t.type])):s.find(n=>!n.types[t.type])}}else if(t.scope){let i=r.filter(s=>s.scope===t.scope&&!s.swr);return t.field?i.find(s=>Array.isArray(s.types[t.type])):i.find(s=>!s.types[t.type])}else return r.find(i=>!i.swr&&!i.scope)}var tI=class{async parse(e){let r=Yi(e,{"--service":String,"--env":String,"--org":String,"--help":Boolean,"--dry":Boolean,"-e":"--env","-o":"--org","-h":"--help","--app":"--service"},!1);if(r["--help"])return this.help();if(r["--env"]&&r["--service"])throw new Error("Please only specify --env or --service.");let i=r._[0];if(i&&i!=="schema")throw new Error("The CLI does not support `stellate push [field]` anymore.\nInstead the entire configuration is now pushed for your environment to match it exactly.\nTo migrate, pull the latest configuration, which may include new fields you have set up in your dashboard, and run `stellate push`.");let s=r._[0]==="schema",n=await Bs(),a=r["--env"],o=await la(a),l=Cl(o,r["--service"]),u=r["--dry"];if(a&&!o)throw new Error(`Could not find configuration for environment "${a}".
|
|
1308
1308
|
Either remove the --env (-e) flag or add configuration for this environment.`);if(!o)throw new Error(`Could not find stellate configuration file.
|
|
1309
|
-
Try running "stellate pull" first if your service has been created already.`);let c=new os(n);if(u&&s)throw new Error(`We currently don't support combining "--dry" with schema pushes.`);if(Array.isArray(o.rateLimits)){let
|
|
1310
|
-
Please make sure to provide a unique name for each rate limit.`)}}let p=await CJ(o.schema,o.headers),d=await Vf(p,o.headers,o.schemaView);if(zn(p)){let
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1309
|
+
Try running "stellate pull" first if your service has been created already.`);let c=new os(n);if(u&&s)throw new Error(`We currently don't support combining "--dry" with schema pushes.`);if(Array.isArray(o.rateLimits)){let g=o.rateLimits.map(T=>T.name),b=new Set(g.filter((T,x)=>g.indexOf(T)!==x));if(b.size>0){let T=[...b].join(", ");throw new Error(`You have configured rate limits with the same name: ${T}.
|
|
1310
|
+
Please make sure to provide a unique name for each rate limit.`)}}let p=await CJ(o.schema,o.headers),d=await Vf(p,o.headers,o.schemaView);if(zn(p)){let g=vDe(p,Object.keys(o.scopes||{}),o.rules||[]);o.rules=g}if(!s)try{await this.diffConfig(c,o,l)||process.exit(0)}catch{}if(u)return"";let f=(0,SDe.default)(`Pushing ${s?"schema":"configuration"} for ${As.default.bold(o.name)}`).start(),h=null;try{let{app:g}=await c.query(`
|
|
1311
|
+
query app($name: ServiceName) {
|
|
1312
|
+
app(name: $name) {
|
|
1313
|
+
organization {
|
|
1314
|
+
id
|
|
1315
|
+
name
|
|
1316
|
+
slug
|
|
1317
|
+
}
|
|
1317
1318
|
}
|
|
1318
1319
|
}
|
|
1319
|
-
}
|
|
1320
|
-
`,{name:l}),m=(h==null?void 0:h.organization)||null;try{s?await c.query(`
|
|
1320
|
+
`,{name:l});h=g.organization}catch{}try{s?await c.query(`
|
|
1321
1321
|
mutation pushAppSchema(
|
|
1322
1322
|
$appName: ServiceName!
|
|
1323
1323
|
$schema: IntrospectionQuery!
|
|
@@ -1340,7 +1340,7 @@ Please make sure to provide a unique name for each rate limit.`)}}let p=await CJ
|
|
|
1340
1340
|
allowDeletion: true
|
|
1341
1341
|
)
|
|
1342
1342
|
}
|
|
1343
|
-
`,{input:o,appName:l,source:dX.default?"CI":"CLI",schema:d})}catch(
|
|
1343
|
+
`,{input:o,appName:l,source:dX.default?"CI":"CLI",schema:d})}catch(g){let b=g.message;if(!b.includes("Could not find app")&&!b.includes("App could not be accessed or found"))if(f.fail(),b.includes("Using the rate-limiting feature is not allowed for this user.")){let T=h?` See ${Gn(hp(h.slug,l,"security/rate-limiting"))} for how to activate the feature.`:"";throw new Error(`${b}${T}`)}else throw g;if(s)throw f.fail(),new Error("Can't create an app in schema-push mode.");return h=await Lv(c,r["--org"]||process.env.STELLATE_ORG||process.env.GRAPHCDN_ORG),await c.query(`
|
|
1344
1344
|
mutation createApp(
|
|
1345
1345
|
$input: Input!
|
|
1346
1346
|
$schema: IntrospectionQuery
|
|
@@ -1354,18 +1354,18 @@ Please make sure to provide a unique name for each rate limit.`)}}let p=await CJ
|
|
|
1354
1354
|
id
|
|
1355
1355
|
}
|
|
1356
1356
|
}
|
|
1357
|
-
`,{input:o,schema:d,organizationId:
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1357
|
+
`,{input:o,schema:d,organizationId:h.id}),f.stop(),`${As.default.greenBright("\u2714")} Created service ${As.default.bold(o.name)}.`}f.stop();let m=h?` (${hp(h.slug,l)})`:"";return`${As.default.greenBright("\u2714")} ${(0,As.default)(`Pushed ${s?"schema":"configuration"} for ${As.default.bold(o.name)}${m}.`)}`}async diffConfig(e,r,i){let s;try{({app:s}=await e.query(`
|
|
1358
|
+
query app($name: ServiceName) {
|
|
1359
|
+
app(name: $name) {
|
|
1360
|
+
organization {
|
|
1361
|
+
slug
|
|
1362
|
+
}
|
|
1363
|
+
config {
|
|
1364
|
+
input
|
|
1365
|
+
}
|
|
1365
1366
|
}
|
|
1366
1367
|
}
|
|
1367
|
-
}
|
|
1368
|
-
`,{name:i});if(!s||!s.config||!s.config.input)return!1;let n=Rm(s.config.input,r);return!n.added.length&&!n.changed.length&&!n.changed.length?(console.log("No configuration changes found!"),!1):(n.added.length>0&&(console.log(`${n.added.length} additions
|
|
1368
|
+
`,{name:i}))}catch(o){if(o.message.includes("Could not find app")||o.message.includes("App could not be accessed or found"))return!1;throw o}if(!s||!s.config||!s.config.input)return!1;let n=Rm(s.config.input,r);return!n.added.length&&!n.changed.length&&!n.changed.length?(console.log("No configuration changes found!"),!1):(n.added.length>0&&(console.log(`${n.added.length} additions
|
|
1369
1369
|
`),n.added.forEach(o=>{console.log(As.default.greenBright(`+ ${o.key}: ${eI(o.newValue)}`))})),n.changed.length>0&&(console.log(`
|
|
1370
1370
|
${n.changed.length} changes
|
|
1371
1371
|
`),n.changed.forEach(o=>{console.log(As.default.yellowBright(`~ ${o.key}: ${As.default.strikethrough(eI(o.previousValue))} --> ${eI(o.newValue)}`))})),n.deleted.length>0&&(console.log(`
|
|
@@ -1402,7 +1402,7 @@ Try running "stellate pull" first if your service has been created already.`);le
|
|
|
1402
1402
|
value
|
|
1403
1403
|
}
|
|
1404
1404
|
}
|
|
1405
|
-
`,u=await Bs();a=(await new os(u).query(l,{name:"serve-token-"+Date.now(),appName:e})).createAdminApiToken.value,this.writePurgeToken(e,a)}let o=(0,LX.default)();o.use("/",(0,kX.createProxyMiddleware)({target:n,changeOrigin:!0,logLevel:"silent",onProxyReq:l=>{l.path.endsWith("/")&&(l.path=l.path.slice(0,-1)),l.setHeader("stellate-cli-serve-port",r),l.setHeader("stellate-token",a)}})),o.listen(r)}setupApiProxy(e,r){let i=`https://${e}.stellate.${process.env.STELLATE_ENDPOINT==="staging"||process.env.STELLATE_ENDPOINT==="local"?"dev":"sh"}`,s=(0,LX.default)();s.use("/",(0,kX.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),s.listen(r)}ensureConfig(){rm.default.existsSync(gc)||rm.default.mkdirSync(gc)}getCache(){try{this.ensureConfig();let e=rm.default.readFileSync(ZS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=rm.default.readFileSync(ZS,"utf-8"),i=JSON.parse(r);if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return i[e]||{checksum:"",envName:""}}catch{return{checksum:"",envName:""}}}getChecksum(e){return yhr(JSON.stringify(e)+"2.14.
|
|
1405
|
+
`,u=await Bs();a=(await new os(u).query(l,{name:"serve-token-"+Date.now(),appName:e})).createAdminApiToken.value,this.writePurgeToken(e,a)}let o=(0,LX.default)();o.use("/",(0,kX.createProxyMiddleware)({target:n,changeOrigin:!0,logLevel:"silent",onProxyReq:l=>{l.path.endsWith("/")&&(l.path=l.path.slice(0,-1)),l.setHeader("stellate-cli-serve-port",r),l.setHeader("stellate-token",a)}})),o.listen(r)}setupApiProxy(e,r){let i=`https://${e}.stellate.${process.env.STELLATE_ENDPOINT==="staging"||process.env.STELLATE_ENDPOINT==="local"?"dev":"sh"}`,s=(0,LX.default)();s.use("/",(0,kX.createProxyMiddleware)({target:i,changeOrigin:!0,headers:{"stellate-cli-serve-port":""+r},logLevel:"silent"})),s.listen(r)}ensureConfig(){rm.default.existsSync(gc)||rm.default.mkdirSync(gc)}getCache(){try{this.ensureConfig();let e=rm.default.readFileSync(ZS,"utf-8");return JSON.parse(e)}catch{return{}}}getCacheEntry(e){try{this.ensureConfig();let r=rm.default.readFileSync(ZS,"utf-8"),i=JSON.parse(r);if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return i[e]||{checksum:"",envName:""}}catch{return{checksum:"",envName:""}}}getChecksum(e){return yhr(JSON.stringify(e)+"2.14.1")}writePurgeToken(e,r){let i=this.getCache();i[e]={...i[e],purgeToken:r},rm.default.writeFileSync(ZS,JSON.stringify(i))}writeCache(e,r,i){let s=this.getCache();if(!e)throw new Error('You need a service-name in your "stellate" config or as the "--service" argument.');return s[e]={checksum:this.getChecksum(r),envName:i},rm.default.writeFileSync(ZS,JSON.stringify(s)),s[e]}},Ww=FX;Ww.help=Hi(`
|
|
1406
1406
|
(BETA) - Use a local backend with Stellate\u2019s GraphQL Edge Cache.
|
|
1407
1407
|
|
|
1408
1408
|
${zv.default.bold("Usage")}
|