@coze/cli 0.0.3 → 0.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.
package/dist/cli.mjs CHANGED
@@ -1 +1 @@
1
- import*as e from"commander";import*as t from"openid-client";import*as o from"picocolors";import*as i from"@npmcli/config/lib/definitions/index.js";import*as r from"@npmcli/config";let s={info(...e){console.log(o.default.blue("[INFO]"),...e)},success(...e){console.log(o.default.green("[SUCCESS]"),...e)},warning(...e){console.log(o.default.yellow("[WARNING]"),...e)},error(...e){console.error(o.default.red("[ERROR]"),...e)},debug(...e){process.env.DEBUG&&console.log(o.default.magenta("[DEBUG]"),...e)}};var n,a=((n={}).CN="cn",n);let c={cn:"npm-hub.coze.cn"},h={cn:"13474932957575400683007237571476.app.coze"},l={cn:"https://api.coze.cn"},p=Object.values(a),g=()=>!1;class u{constructor(e="cn"){let o=new t.Issuer({issuer:l[e],device_authorization_endpoint:`${l[e]}/api/permission/oauth2/device/code`,token_endpoint:`${l[e]}/api/permission/oauth2/token`,revocation_endpoint:`${l[e]}/api/permission/oauth2/revoke`,scope:"createMessage"});this.client=new o.Client({client_id:h[e],token_endpoint_auth_method:"none"})}async activate(e){let{refreshToken:t}=await e.loadConfig();if(t)try{let o=await this.client.refresh(t);await e.storeToken(o)}catch(t){s.error("refresh failed: ",t),await this.auth(e)}else await this.auth(e)}async deactivate(e){let{refreshToken:t}=await e.loadConfig();await this.client.revoke(t),await e.clearToken()}async auth(e){let t=await this.client.deviceAuthorization({duration_seconds:86399}),o=`${t.verification_uri}?user_code=${t.user_code}`,i=await import("open").then(e=>e.default);await i(o);let r=null;for(;!r;)try{r=await t.poll(),s.success("authenticated"),await e.storeToken(r)}catch(e){throw s.error("poll failed:",e),e}}}let{shorthands:f,definitions:d,flatten:y}=i.default,m="user";class w{constructor({projectDir:e,scope:t,region:o,source:i}={}){this.config={scope:t??"coze-kit",authToken:"",refreshToken:"",registryUrl:"",region:o,source:i??"coze"};let s=e??process.cwd();this.proxy=new r.default({npmPath:s,definitions:d,shorthands:f,flatten:y,cwd:s})}get registryScope(){return`@${this.config.scope}:registry`}get registryUrl(){let e=c[this.region];return g(this.region)?`http://${e}/`:`https://${e}/`}get registryAuthUrl(){let e=c[this.region];return`//${e}/:_authToken`}get refreshKey(){return`${this.config.source}_refresh_token`}get region(){if(this.config.region)return this.config.region;let e=this.proxy.get(this.registryScope);if(!e)return"cn";let t=new URL(e).host;for(let[e,o]of Object.entries(c))if(t===o)return e;return"cn"}async loadConfig(){if(this.proxy.loaded)return this.config;await this.proxy.load();let e=this.proxy.get(this.registryAuthUrl,m)??"";return Object.assign(this.config,{region:this.region,registryUrl:this.proxy.get(this.registryScope)||this.registryUrl,authToken:e,refreshToken:this.proxy.get(this.refreshKey,m)||""}),this.config}async storeToken(e){for(let[e]of Object.entries(c))e!==this.region&&this.proxy.delete(this.registryScope,m);this.proxy.set(this.registryScope,this.registryUrl,m),this.proxy.set(this.registryAuthUrl,`${this.config.source}:${e.access_token||""}`,m),this.proxy.set(this.refreshKey,e.refresh_token||"",m),await this.proxy.save(m),Object.assign(this.config,{authToken:e.access_token,refreshToken:e.refresh_token}),s.success(`token saved for registry: ${this.registryUrl}`)}async clearToken(){this.proxy.delete(this.registryScope,m),this.proxy.delete(this.registryAuthUrl,m),this.proxy.delete(this.refreshKey,m),await this.proxy.save(m),Object.assign(this.config,{authToken:"",refreshToken:""}),s.success(`token cleared for registry: ${this.registryUrl}`)}getProxy(){return this.proxy}}let k={name:"logout",description:"log out of the hub",action:async function e({region:e,scope:t,source:o}){let i=new w({region:e,scope:t,source:o}),r=new u(e);await r.deactivate(i)},options:[new e.Option("-r, --region <name>","the region of hub").choices(p),new e.Option("-s, --scope <name>","the scope of package"),new e.Option("-b, --source <name>","the business source")]},v={name:"login",description:"log in to the hub",action:async function e({region:e}){let t=new w({region:e}),o=new u(e);await o.activate(t)},options:[new e.Option("-r, --region <name>","the region of hub").choices(p)]},x=new e.Command;x.name("coze").version("0.0.3").description("A command-line tool for component development");[v,k].forEach(e=>{!function e({program:t,spec:o,runAuth:i}){let r=t.command(o.name);r.description(o.description),(o.arguments??[]).forEach(e=>{r.addArgument(e)}),(o.options??[]).forEach(e=>{r.addOption(e)}),o.action&&r.action(async(...e)=>{o.auth&&i&&await i(),await o.action?.(...e)}),(o.subCommands??[]).forEach(t=>{e({program:r,spec:t,runAuth:i})})}({spec:e,program:x,runAuth:async()=>{let e=new w,{region:t,registryUrl:o,scope:i}=await e.loadConfig(),r=new u(t);await r.activate(e),process.env.REGION=t,process.env.REGISTRY=o,process.env.SCOPE=i}})}),x.parse(process.argv);
1
+ import*as e from"commander";import*as t from"openid-client";import*as o from"picocolors";import*as i from"@npmcli/config/lib/definitions/index.js";import*as r from"@npmcli/config";let s={info(...e){console.log(o.default.blue("[INFO]"),...e)},success(...e){console.log(o.default.green("[SUCCESS]"),...e)},warning(...e){console.log(o.default.yellow("[WARNING]"),...e)},error(...e){console.error(o.default.red("[ERROR]"),...e)},debug(...e){process.env.DEBUG&&console.log(o.default.magenta("[DEBUG]"),...e)}};var n,a=((n={}).CN="cn",n);let c={cn:"npm-hub.coze.cn"},h={cn:"13474932957575400683007237571476.app.coze"},l={cn:"https://api.coze.cn"},p=Object.values(a),g=()=>!1;class u{constructor(e="cn"){let o=new t.Issuer({issuer:l[e],device_authorization_endpoint:`${l[e]}/api/permission/oauth2/device/code`,token_endpoint:`${l[e]}/api/permission/oauth2/token`,revocation_endpoint:`${l[e]}/api/permission/oauth2/revoke`,scope:"createMessage"});this.client=new o.Client({client_id:h[e],token_endpoint_auth_method:"none"})}async activate(e){let{refreshToken:t}=await e.loadConfig();if(t)try{let o=await this.client.refresh(t);await e.storeToken(o)}catch(t){s.error("refresh failed: ",t),await this.auth(e)}else await this.auth(e)}async deactivate(e){let{refreshToken:t}=await e.loadConfig();await this.client.revoke(t),await e.clearToken()}async auth(e){let t=await this.client.deviceAuthorization({duration_seconds:86399}),o=`${t.verification_uri}?user_code=${t.user_code}`,i=await import("open").then(e=>e.default);await i(o);let r=null;for(;!r;)try{r=await t.poll(),s.success("authenticated"),await e.storeToken(r)}catch(e){throw s.error("poll failed:",e),e}}}let{shorthands:f,definitions:d,flatten:y}=i.default,m="user";class w{constructor({projectDir:e,scope:t,region:o,source:i}={}){this.config={scope:t??"coze-kit",authToken:"",refreshToken:"",registryUrl:"",region:o,source:i??"coze"};let s=e??process.cwd();this.proxy=new r.default({npmPath:s,definitions:d,shorthands:f,flatten:y,cwd:s})}get registryScope(){return`@${this.config.scope}:registry`}get registryUrl(){let e=c[this.region];return g(this.region)?`http://${e}/`:`https://${e}/`}get registryAuthUrl(){let e=c[this.region];return`//${e}/:_authToken`}get refreshKey(){return`${this.config.source}_refresh_token`}get region(){if(this.config.region)return this.config.region;let e=this.proxy.get(this.registryScope);if(!e)return"cn";let t=new URL(e).host;for(let[e,o]of Object.entries(c))if(t===o)return e;return"cn"}async loadConfig(){if(this.proxy.loaded)return this.config;await this.proxy.load();let e=this.proxy.get(this.registryAuthUrl,m)??"";return Object.assign(this.config,{region:this.region,registryUrl:this.proxy.get(this.registryScope)||this.registryUrl,authToken:e,refreshToken:this.proxy.get(this.refreshKey,m)||""}),this.config}async storeToken(e){for(let[e]of Object.entries(c))e!==this.region&&this.proxy.delete(this.registryScope,m);this.proxy.set(this.registryScope,this.registryUrl,m),this.proxy.set(this.registryAuthUrl,`${this.config.source}:${e.access_token||""}`,m),this.proxy.set(this.refreshKey,e.refresh_token||"",m),await this.proxy.save(m),Object.assign(this.config,{authToken:e.access_token,refreshToken:e.refresh_token}),s.success(`token saved for registry: ${this.registryUrl}`)}async clearToken(){this.proxy.delete(this.registryScope,m),this.proxy.delete(this.registryAuthUrl,m),this.proxy.delete(this.refreshKey,m),await this.proxy.save(m),Object.assign(this.config,{authToken:"",refreshToken:""}),s.success(`token cleared for registry: ${this.registryUrl}`)}getProxy(){return this.proxy}}let k={name:"logout",description:"log out of the hub",action:async function e({region:e,scope:t,source:o}){let i=new w({region:e,scope:t,source:o}),r=new u(e);await r.deactivate(i)},options:[new e.Option("-r, --region <name>","the region of hub").choices(p),new e.Option("-s, --scope <name>","the scope of package"),new e.Option("-b, --source <name>","the business source")]},v={name:"login",description:"log in to the hub",action:async function e({region:e}){let t=new w({region:e}),o=new u(e);await o.activate(t)},options:[new e.Option("-r, --region <name>","the region of hub").choices(p)]},x=new e.Command;x.name("coze").version("0.0.4").description("A command-line tool for component development");[v,k].forEach(e=>{!function e({program:t,spec:o,runAuth:i}){let r=t.command(o.name);r.description(o.description),(o.arguments??[]).forEach(e=>{r.addArgument(e)}),(o.options??[]).forEach(e=>{r.addOption(e)}),o.action&&r.action(async(...e)=>{o.auth&&i&&await i(),await o.action?.(...e)}),(o.subCommands??[]).forEach(t=>{e({program:r,spec:t,runAuth:i})})}({spec:e,program:x,runAuth:async()=>{let e=new w,{region:t,registryUrl:o,scope:i}=await e.loadConfig(),r=new u(t);await r.activate(e),process.env.REGION=t,process.env.REGISTRY=o,process.env.SCOPE=i}})}),x.parse(process.argv);
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "@coze/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "command-line tool for component development",
5
- "license": "ISC",
5
+ "keywords": [
6
+ "coze",
7
+ "@coze/cli",
8
+ "cli"
9
+ ],
10
+ "license": "MIT",
6
11
  "author": "Coze Team <coze@feedback.com>",
7
- "maintainers": [],
8
12
  "main": "dist/index.mjs",
9
13
  "types": "dist/index.d.ts",
10
14
  "bin": {
File without changes