neo-cmp-cli 1.9.18 → 1.9.19
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/neo/env.js +1 -1
- package/dist/neo/neoLogin.js +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +1 -1
- package/template/neo-custom-cmp-template/src/components/entityCardList__c/index.tsx +10 -0
- package/template/neo-custom-cmp-template/src/components/entityForm__c/index.tsx +4 -0
- package/template/neo-custom-cmp-template/src/components/entityForm__c/model.ts +1 -1
- package/template/neo-custom-cmp-template/src/components/entityTable__c/index.tsx +10 -0
package/dist/neo/env.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("lodash");var t,a;exports.__require=function(){if(a)return t;a=1;const e=o,s={neoBaseURL:"https://crm.xiaoshouyi.com",loginAPI:"https://login.xiaoshouyi.com/auc/oauth2/auth",tokenAPI:"https://login.xiaoshouyi.com/auc/oauth2/token"},
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("lodash");var t,a;exports.__require=function(){if(a)return t;a=1;const e=o,s={neoBaseURL:"https://crm.xiaoshouyi.com",loginAPI:"https://login.xiaoshouyi.com/auc/oauth2/auth",tokenAPI:"https://login.xiaoshouyi.com/auc/oauth2/token"},n={neoBaseURL:"https://crm-gray.xiaoshouyi.com",loginAPI:"https://login-gray.xiaoshouyi.com/auc/oauth2/auth",tokenAPI:"https://login-gray.xiaoshouyi.com/auc/oauth2/token"},u={neoBaseURL:"https://crm-sandbox.xiaoshouyi.com",loginAPI:"https://login-sandbox.xiaoshouyi.com/auc/oauth2/auth",tokenAPI:"https://login-sandbox.xiaoshouyi.com/auc/oauth2/token"},i={neoBaseURL:"https://crm-cd.xiaoshouyi.com",loginAPI:"https://login-cd.xiaoshouyi.com/auc/oauth2/auth",tokenAPI:"https://login-cd.xiaoshouyi.com/auc/oauth2/token"},c={neoBaseURL:"https://crm-cd.xiaoshouyi.com",loginAPI:"https://login-cd.xiaoshouyi.com/auc/oauth2/auth",tokenAPI:"https://login-cd.xiaoshouyi.com/auc/oauth2/token",delete:"/rest/metadata/v3.0/ui/customComponents",saveAPI:"/rest/metadata/v3.0/ui/customComponents/actions/saveOrUpdateComponent",queryAll:"/rest/metadata/v3.0/ui/components/filter?custom=true",getCodeLibAPI:o=>`/rest/metadata/v3.0/ui/customComponents/${o}/codeLib`,uploadAPI:"/rest/metadata/v3.0/ui/customComponents/actions/upload",query:"/rest/metadata/v3.0/ui/customComponents/actions/queryCustomComponents"};return t={DefaultNeoCrmAPI:c,getNeoCrmAPI:(o="cd",t={})=>{let a=e.cloneDeep(c),h=i;switch(o){case"production":h=s;break;case"gray":h=n;break;case"sandbox":h=u;break;case"cd":default:h=i;break;case"custom":h={...t,neoBaseURL:t.neoBaseURL,loginAPI:t.loginAPI,tokenAPI:t.tokenAPI}}return console.log("curEnvConfig:",o,h,h),{...a,...h}}}};
|
package/dist/neo/neoLogin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("axios"),t=require("node:fs"),n=require("node:path"),s=require("ora"),r=require("node:http"),o=require("node:url"),i=require("open"),a=require("node:net"),c=require("lodash"),l=require("../utils/common.js"),h=require("./neoEnvManager.js");var p,u;exports.__require=function(){if(u)return p;u=1;const d=e,g=t,y=n,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("axios"),t=require("node:fs"),n=require("node:path"),s=require("ora"),r=require("node:http"),o=require("node:url"),i=require("open"),a=require("node:net"),c=require("lodash"),l=require("../utils/common.js"),h=require("./neoEnvManager.js");var p,u;exports.__require=function(){if(u)return p;u=1;const d=e,g=t,y=n,k=s,m=r,_=o,T=i,w=a,f=c,{errorLog:S,successLog:x}=l.__require(),R=h.__require();return p=class{constructor(e){if(!e)return;const{loginURL:t,tokenAPI:n}=e,s=R.getAuthConfig(),{redirectUri:r,authType:o,auth:i}=s;if(!t||!n)throw new Error("auth.config.js 配置不完整,需要包含 loginURL、tokenAPI");this.loginURL=t,this.tokenAPI=n,this.redirectUri=r,this.authType=o||"oauth2",this.response_type=i.response_type||"code",this.client_id=i.client_id,this.client_secret=i.client_secret,this.scope=i.scope||"all",this.oauthType=i.oauthType||"standard",this.access_type=i.access_type||"offline",this.grant_type=i.grant_type||"authorization_code",this.tokenDir=y.join(process.cwd(),".neo-cli"),this.tokenFile=y.join(this.tokenDir,"token.json"),this.pageDir=y.join(__dirname,"../../template/pageHtml"),this.authErrorTemplate=y.join(this.pageDir,"auth-error.html"),this.authSuccessTemplate=y.join(this.pageDir,"auth-success.html"),this.tokenErrorTemplate=y.join(this.pageDir,"token-error.html"),this.authFailedTemplate=y.join(this.pageDir,"auth-failed.html");try{R.setEnvConfig(f.pick(e,["neoBaseURL","loginURL","tokenAPI"]))}catch(e){S(`保存环境配置失败: ${e.message||e.msg}`)}}ensureTokenDir(){g.existsSync(this.tokenDir)||g.mkdirSync(this.tokenDir,{recursive:!0})}saveToken(e){this.ensureTokenDir();const t={...e,savedAt:Date.now(),expiresAt:Date.now()+1e3*(e.expires_in||7200)};g.writeFileSync(this.tokenFile,JSON.stringify(t,null,2),"utf-8")}readToken(){if(!g.existsSync(this.tokenFile))return null;try{return JSON.parse(g.readFileSync(this.tokenFile,"utf-8"))}catch(e){return S(`读取 token 文件失败: ${e.message||e.msg}`),null}}isTokenExpired(e){return!e||!e.expiresAt||Date.now()>=e.expiresAt-3e5}clearToken(){g.existsSync(this.tokenFile)&&g.unlinkSync(this.tokenFile)}getRedirectURI(e){return`http://localhost:${e}`}buildAuthUrl(e){const t=new URLSearchParams({response_type:this.response_type,client_id:this.client_id,redirect_uri:e,scope:this.scope,oauthType:this.oauthType,access_type:this.access_type});return`${this.loginURL}?${t.toString()}`}async openBrowser(e){try{await T(e)}catch(t){S(`无法自动打开浏览器: ${t.message||t.msg}`),console.log(`\n请手动访问以下 URL 进行授权:\n${e}\n`)}}getHtmlTemplate(e,t={}){try{let n=g.readFileSync(e,"utf-8");return Object.keys(t).forEach(e=>{const s=`{{${e}}}`;n=n.replace(new RegExp(s,"g"),t[e])}),n}catch(e){return S(`读取 HTML 模板失败: ${e.message||e.msg}`),"<html><body><h1>页面加载失败</h1></body></html>"}}async isPortInUse(e){return new Promise(t=>{const n=w.createServer();n.once("error",e=>{"EADDRINUSE"===e.code?t(!0):t(!1)}),n.once("listening",()=>{n.once("close",()=>{t(!1)}),n.close()}),n.listen(e)})}async startCallbackServer(){let e=this.redirectUri,t=new URL(e),n=parseInt(t.port,10);await this.isPortInUse(n)&&(S(`\n警告: 端口 ${n} 已被占用,请调整 redirectUri 配置项,使其指向一个未被占用的端口。`),process.exit(1));const s=new Promise((s,r)=>{const o=m.createServer(async(n,i)=>{const a=_.parse(n.url,!0);if(a.pathname===t.pathname||"/"===a.pathname){const t=a.query.code,n=a.query.error;if(n){i.writeHead(400,{"Content-Type":"text/html; charset=utf-8"});const e=this.getHtmlTemplate(this.authErrorTemplate,{ERROR:n});return i.end(e),o.close(),void r(new Error(`授权失败: ${n}`))}if(t)try{const n=await this.getTokenByCode(t,e);this.saveToken(n);const r=n.tenant_id||"未返回",a=n.instance_uri||"未返回";i.writeHead(200,{"Content-Type":"text/html; charset=utf-8"});const c=this.getHtmlTemplate(this.authSuccessTemplate,{TENANT_ID:r,INSTANCE_URI:a});return i.end(c),o.close(),void s({code:t,tokenData:n})}catch(e){i.writeHead(500,{"Content-Type":"text/html; charset=utf-8"});const t=this.getHtmlTemplate(this.tokenErrorTemplate,{ERROR:e});return i.end(t),o.close(),void r(e)}i.writeHead(400,{"Content-Type":"text/html; charset=utf-8"});const c=this.getHtmlTemplate(this.authFailedTemplate);i.end(c),o.close(),r(new Error("未获取到授权码"))}else i.writeHead(404,{"Content-Type":"text/plain"}),i.end("Not Found")});o.on("error",e=>{"EADDRINUSE"===e.code?r(new Error(`端口 ${n} 已被占用,无法启动回调服务器`)):r(e)}),o.listen(n,()=>{console.log(`\n本地回调服务器已启动,监听端口: ${n}`),console.log(`回调地址: ${e}`)}),setTimeout(()=>{o.close(),r(new Error("授权超时,请重试"))},3e5)});return{redirectUri:e,getCodeAndTokenPromise:s}}async getTokenByCode(e,t){const n=k("正在获取 access token...").start();try{const s=new URLSearchParams;s.append("grant_type",this.grant_type),s.append("client_id",this.client_id),s.append("client_secret",this.client_secret),s.append("code",e),s.append("redirect_uri",t);const r=(await d.post(this.tokenAPI,s.toString(),{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;return r&&r.access_token||(S("获取 token 失败:响应中未包含 access_token",n),S(`响应数据: ${JSON.stringify(r)}`),process.exit(1)),x("成功获取 access token",n),r}catch(e){S("获取 token 失败",n),S(`\n获取 token 失败: ${e.message||e.msg}`),e.response&&S(`响应数据: ${JSON.stringify(e.response.data)}`),process.exit(1)}}async refreshToken(e){const t=k("正在刷新授权信息(token)...").start();try{const n=new URLSearchParams;n.append("grant_type","refresh_token"),n.append("client_id",this.client_id),n.append("client_secret",this.client_secret),n.append("refresh_token",e);const s=(await d.post(this.tokenAPI,n.toString(),{headers:{"Content-Type":"application/x-www-form-urlencoded"}})).data;return s&&s.access_token?(x("刷新授权信息成功(token)。",t),s):(S("刷新授权信息失败:响应中未包含 access_token",t),S(`响应数据: ${JSON.stringify(s)}`),null)}catch(e){return S("刷新授权信息失败",t),S(`\n刷新授权信息失败: ${e.message||e.msg}`),e.response&&S(`响应数据: ${JSON.stringify(e.response.data)}`),null}}async login(){console.log("\n========== NeoCRM 登录授权 ==========\n");try{const{redirectUri:e,getCodeAndTokenPromise:t}=await this.startCallbackServer(),n=this.buildAuthUrl(e);console.log("授权 URL:",n),console.log("\n正在打开浏览器进行授权..."),await this.openBrowser(n);const{code:s,tokenData:r}=await t;return x("\n✓ 已获取授权码"),console.log("\n========== 登录成功 ==========\n"),console.log(`实例地址: ${r.instance_uri||"未返回"}`),console.log(`租户 ID: ${r.tenant_id||"未返回"}`),r}catch(e){S(`\n登录失败: ${e.message||e.msg}`),process.exit(1)}}async logout(){if(console.log("\n========== NeoCRM 登出 ==========\n"),g.existsSync(this.tokenFile))try{R.clearEnvConfig(),this.clearToken(),x("已清除授权信息,下次登录需要重新授权。"),console.log("\n登出成功!\n")}catch(e){S(`登出失败: ${e.message||e.msg}`),process.exit(1)}else console.log("当前未登录,无需登出。")}async getValidToken(){const e=this.readToken();if(e||(S("未找到授权信息,请先执行 neo login 进行登录。"),process.exit(1)),this.isTokenExpired(e)){console.log("授权信息已过期,正在尝试刷新..."),e.refresh_token||(S("自动刷新授权信息失败,请重新登录(neo login)。"),process.exit(1));const t=await this.refreshToken(e.refresh_token);return t||(S("刷新授权信息失败,请重新登录 (neo login)"),process.exit(1)),this.saveToken(t),t}return e}async getAccessToken(){return await this.getValidToken()}}};
|
package/dist/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e="1.9.
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e="1.9.19";const o={version:e};exports.default=o,exports.version=e;
|
package/package.json
CHANGED
|
@@ -8,6 +8,10 @@ import { xObject } from 'neo-open-api';
|
|
|
8
8
|
// @ts-ignore
|
|
9
9
|
import { BaseCmp } from 'neo-ui-common';
|
|
10
10
|
|
|
11
|
+
// 引入 neo-ui-common / NeoEvent
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import { NeoEvent } from 'neo-ui-common'; // 后续考虑 使用 props.dispatchEvent 方法替代
|
|
14
|
+
|
|
11
15
|
import './style.scss';
|
|
12
16
|
|
|
13
17
|
interface EntityCardListProps {
|
|
@@ -50,6 +54,12 @@ export default class EntityCardList extends BaseCmp<
|
|
|
50
54
|
|
|
51
55
|
componentDidMount() {
|
|
52
56
|
this.loadObjectData();
|
|
57
|
+
|
|
58
|
+
// 监听一个广播事件
|
|
59
|
+
NeoEvent.listen('reloadData', (eventData: any) => {
|
|
60
|
+
console.log('EntityCardList 监听到了一个广播事件 reloadData: ', eventData);
|
|
61
|
+
this.loadObjectData();
|
|
62
|
+
});
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
componentDidUpdate(prevProps: Readonly<EntityCardListProps>) {
|
|
@@ -236,6 +236,10 @@ export default class EntityForm extends React.PureComponent<
|
|
|
236
236
|
@NeoEvent.dispatch
|
|
237
237
|
onSubmit() {
|
|
238
238
|
console.log('触发了表单提交事件:', this.props);
|
|
239
|
+
|
|
240
|
+
// 触发一个广播事件
|
|
241
|
+
console.log('触发了一个广播事件 reloadData。');
|
|
242
|
+
NeoEvent.broadcast('reloadData', this.props);
|
|
239
243
|
}
|
|
240
244
|
|
|
241
245
|
/**
|
|
@@ -38,6 +38,10 @@ import isEqual from 'lodash/isEqual';
|
|
|
38
38
|
// @ts-ignore
|
|
39
39
|
import { BaseCmp } from 'neo-ui-common';
|
|
40
40
|
|
|
41
|
+
// 引入 neo-ui-common / NeoEvent
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
import { NeoEvent } from 'neo-ui-common'; // 后续考虑 使用 props.dispatchEvent 方法替代
|
|
44
|
+
|
|
41
45
|
import './style.scss';
|
|
42
46
|
|
|
43
47
|
const { Option } = Select;
|
|
@@ -175,6 +179,12 @@ export default class EntityTable extends BaseCmp<
|
|
|
175
179
|
this.loadData(page, pageSize);
|
|
176
180
|
}
|
|
177
181
|
}
|
|
182
|
+
|
|
183
|
+
// 监听一个广播事件
|
|
184
|
+
NeoEvent.listen('reloadData', (eventData: any) => {
|
|
185
|
+
console.log('EntityTable 监听到了一个广播事件 reloadData: ', eventData);
|
|
186
|
+
this.loadData();
|
|
187
|
+
});
|
|
178
188
|
}
|
|
179
189
|
|
|
180
190
|
/**
|