fmode-ng 0.0.215 → 0.0.216

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.
@@ -0,0 +1,10 @@
1
+
2
+ /**
3
+ * @copyright © 未来飞马 © 未来全栈 www.fmode.cn
4
+ * 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
5
+ * 保留所有权利 All Rights Reserved.
6
+ * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/social/wxdebug.mjs
7
+ */
8
+ export function wxdebug(...o){console.log(o)}
9
+ var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3NvY2lhbC93eGRlYnVnLm1qcw==`
10
+
@@ -5,6 +5,6 @@
5
5
  * 保留所有权利 All Rights Reserved.
6
6
  * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/social/wxwork/wxwork.corp.mjs
7
7
  */
8
- import{wxdebug}from"../../../social/wxdebug";export class WxworkCorp{constructor(t){this.config={},this.ticket={get:async(t="agent_config")=>{let e={};t&&(e.type=t);let a=await WwRequest({company:this.company,path:"ticket/get",method:"GET",queryParams:e});return a?.ticket}},this.service={async corpIdToOpenCorpId(t){return await WwRequest({company:this.company,path:"auth/getuserinfo",method:"GET",body:{corpid:t}})}},this.auth={getuserinfo:async t=>{wxdebug("getuserinfo request");let e=await WwRequest({company:this.company,path:"auth/getuserinfo",method:"GET",queryParams:{code:t}});if(e?.user_ticket){let t=await WwRequest({company:this.company,path:"auth/getuserdetail",method:"POST",body:{user_ticket:e?.user_ticket}});t?.qr_code&&Object.keys(t).forEach((a=>{e[a]=t[a]})),console.log("企业用户详情:",e)}return e?.openid,e||null}},this.user={getUserId:async t=>{let e=await WwRequest({company:this.company,path:"user/getuserid",method:"POST",body:{mobile:t}});return console.log(e),e?.userid||null},get:async t=>{let e=await WwRequest({company:this.company,path:"user/get",method:"GET",queryParams:{id:t}});return console.log(e),e?.department||null},listId:async(t,e,a)=>{let s="user/list_id",n="POST",o={limit:100};(t=t||null)&&(s="user/simplelist",n="GET",o=null);let i=await WwRequest({company:this.company,method:n,queryParams:{department_id:t},path:s,body:o});return console.log(i),t?i?.userlist||[]:i?.dept_user||[]},list:async t=>{let e=t?.id,a=await WwRequest({company:this.company,path:"department/list",method:"GET",queryParams:{id:e}});return console.log(a),a}},this.department={get:async t=>{let e=await WwRequest({company:this.company,path:"department/get",method:"GET",queryParams:{id:t}});return console.log(e),e?.department||null},listId:async t=>{let e=t?.id,a=await WwRequest({company:this.company,method:"GET",queryParams:{id:e},path:"department/simplelist"});return console.log(a),a?.department_id||[]},list:async t=>{let e=t?.id,a=await WwRequest({company:this.company,path:"department/list",method:"GET",queryParams:{id:e}});return console.log(a),a}},this.externalContact={get:async t=>await WwRequest({method:"GET",company:this.company,path:"externalcontact/get",queryParams:{external_userid:t}}),groupChat:{addJoinWay:async t=>await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/add_join_way",body:t}),getJoinWay:async t=>{if(!t)return null;return await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/get_join_way",body:{config_id:t}})},get:async t=>await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/get",body:{chat_id:t,need_name:1}}),list:async t=>{let e={limit:t?.limit||20};t?.userid_list&&(e.owner_filter={userid_list:[t?.userid_list]});let a=await WwRequest({company:this.company,path:"externalcontact/groupchat/list",body:e});return console.log(a),a}}},this.appchat={sendText:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"text",text:{content:e},safe:a}}),sendImage:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"image",image:{media_id:e},safe:a}}),sendVideo:async(t,e,a,s,n=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"video",video:{media_id:e,title:a,description:s},safe:n}}),sendFile:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"file",file:{media_id:e},safe:a}}),sendTextCard:async(t,e,a,s,n,o=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"textcard",textcard:{title:e,description:a,url:s,btntxt:n||"详情"},safe:o}}),sendNews:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"news",news:{articles:e},safe:a}}),sendMarkdown:async(t,e)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"markdown",markdown:{content:e}}}),send:async t=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:t})},this.meeting={create:async t=>await WwRequest({company:this.company,path:"meeting/create",method:"POST",body:t}),list:async t=>{let e={limit:t?.limit||20};return t?.userid&&(e.userid=t.userid),t?.cursor&&(e.cursor=t.cursor),t?.begin_time&&(e.begin_time=t.begin_time),t?.end_time&&(e.end_time=t.end_time),await WwRequest({company:this.company,path:"meeting/list",method:"POST",body:e})},get:async t=>await WwRequest({company:this.company,path:"meeting/get",method:"POST",body:{meetingid:t}})},this.company=t}}export async function WwRequest(t){let e,a,s=t?.company,n=t?.path,o=t?.method||"POST",i="https://server.fmode.cn/api/wework/func";t?.body&&Object.keys(t?.body)?.length&&(e=t?.body),t?.queryParams&&(a=t?.queryParams),e||(e={});let c=JSON.stringify({company:s,path:n,body:e,queryParams:a,method:o});console.log(c);let d={method:"POST",headers:{"Content-Type":"application/json"},body:c};console.log(d,i);try{let t=await fetch(i,d);return await t.json()}catch(t){return alert("wxreqErr:"+JSON.stringify(t)),null}}
8
+ import{wxdebug}from"../wxdebug";export class WxworkCorp{constructor(t){this.config={},this.ticket={get:async(t="agent_config")=>{let e={};t&&(e.type=t);let a=await WwRequest({company:this.company,path:"ticket/get",method:"GET",queryParams:e});return a?.ticket}},this.service={async corpIdToOpenCorpId(t){return await WwRequest({company:this.company,path:"auth/getuserinfo",method:"GET",body:{corpid:t}})}},this.auth={getuserinfo:async t=>{wxdebug("getuserinfo request");let e=await WwRequest({company:this.company,path:"auth/getuserinfo",method:"GET",queryParams:{code:t}});if(e?.user_ticket){let t=await WwRequest({company:this.company,path:"auth/getuserdetail",method:"POST",body:{user_ticket:e?.user_ticket}});t?.qr_code&&Object.keys(t).forEach((a=>{e[a]=t[a]})),console.log("企业用户详情:",e)}return e?.openid,e||null}},this.user={getUserId:async t=>{let e=await WwRequest({company:this.company,path:"user/getuserid",method:"POST",body:{mobile:t}});return console.log(e),e?.userid||null},get:async t=>{let e=await WwRequest({company:this.company,path:"user/get",method:"GET",queryParams:{id:t}});return console.log(e),e?.department||null},listId:async(t,e,a)=>{let s="user/list_id",n="POST",o={limit:100};(t=t||null)&&(s="user/simplelist",n="GET",o=null);let i=await WwRequest({company:this.company,method:n,queryParams:{department_id:t},path:s,body:o});return console.log(i),t?i?.userlist||[]:i?.dept_user||[]},list:async t=>{let e=t?.id,a=await WwRequest({company:this.company,path:"department/list",method:"GET",queryParams:{id:e}});return console.log(a),a}},this.department={get:async t=>{let e=await WwRequest({company:this.company,path:"department/get",method:"GET",queryParams:{id:t}});return console.log(e),e?.department||null},listId:async t=>{let e=t?.id,a=await WwRequest({company:this.company,method:"GET",queryParams:{id:e},path:"department/simplelist"});return console.log(a),a?.department_id||[]},list:async t=>{let e=t?.id,a=await WwRequest({company:this.company,path:"department/list",method:"GET",queryParams:{id:e}});return console.log(a),a}},this.externalContact={get:async t=>await WwRequest({method:"GET",company:this.company,path:"externalcontact/get",queryParams:{external_userid:t}}),groupChat:{addJoinWay:async t=>await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/add_join_way",body:t}),getJoinWay:async t=>{if(!t)return null;return await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/get_join_way",body:{config_id:t}})},get:async t=>await WwRequest({method:"POST",company:this.company,path:"externalcontact/groupchat/get",body:{chat_id:t,need_name:1}}),list:async t=>{let e={limit:t?.limit||20};t?.userid_list&&(e.owner_filter={userid_list:[t?.userid_list]});let a=await WwRequest({company:this.company,path:"externalcontact/groupchat/list",body:e});return console.log(a),a}}},this.appchat={sendText:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"text",text:{content:e},safe:a}}),sendImage:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"image",image:{media_id:e},safe:a}}),sendVideo:async(t,e,a,s,n=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"video",video:{media_id:e,title:a,description:s},safe:n}}),sendFile:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"file",file:{media_id:e},safe:a}}),sendTextCard:async(t,e,a,s,n,o=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"textcard",textcard:{title:e,description:a,url:s,btntxt:n||"详情"},safe:o}}),sendNews:async(t,e,a=0)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"news",news:{articles:e},safe:a}}),sendMarkdown:async(t,e)=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:{chatid:t,msgtype:"markdown",markdown:{content:e}}}),send:async t=>await WwRequest({company:this.company,path:"appchat/send",method:"POST",body:t})},this.meeting={create:async t=>await WwRequest({company:this.company,path:"meeting/create",method:"POST",body:t}),list:async t=>{let e={limit:t?.limit||20};return t?.userid&&(e.userid=t.userid),t?.cursor&&(e.cursor=t.cursor),t?.begin_time&&(e.begin_time=t.begin_time),t?.end_time&&(e.end_time=t.end_time),await WwRequest({company:this.company,path:"meeting/list",method:"POST",body:e})},get:async t=>await WwRequest({company:this.company,path:"meeting/get",method:"POST",body:{meetingid:t}})},this.company=t}}export async function WwRequest(t){let e,a,s=t?.company,n=t?.path,o=t?.method||"POST",i="https://server.fmode.cn/api/wework/func";t?.body&&Object.keys(t?.body)?.length&&(e=t?.body),t?.queryParams&&(a=t?.queryParams),e||(e={});let c=JSON.stringify({company:s,path:n,body:e,queryParams:a,method:o});console.log(c);let d={method:"POST",headers:{"Content-Type":"application/json"},body:c};console.log(d,i);try{let t=await fetch(i,d);return await t.json()}catch(t){return alert("wxreqErr:"+JSON.stringify(t)),null}}
9
9
  var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3NvY2lhbC93eHdvcmsvd3h3b3JrLmNvcnAubWpz`
10
10
 
@@ -5,6 +5,6 @@
5
5
  * 保留所有权利 All Rights Reserved.
6
6
  * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/core/social/wxwork/wxwork.sdk.mjs
7
7
  */
8
- import*as ww from"@wecom/jssdk";import{FmodeParse}from"../../parse";const Parse=FmodeParse.with("nova");import{WxworkCorp}from"./wxwork.corp";import{wxdebug}from"../../../social/wxdebug";export class WxworkSDK{constructor(e){this.companyMap={E4KpGvTEto:{corpResId:"vsVIWbd1i9"},uRiDGwEYLi:{corpResId:"JxfFXBr0ly"},cDL6R1hgSi:{corpResId:"SpL6gyD1Gu"}},this.suiteMap={crm:{suiteId:"dk2559ba758f33d8f5"}},this.ww=ww,this.groupChat={createGroupChat:async e=>{try{return wxdebug("createGroupChat"+JSON.stringify(e)),await this.registerCorpWithSuite()?new Promise(((t,r)=>{e.success=e=>{wxdebug(JSON.stringify(e)),t(e)},e.fail=e=>{wxdebug(JSON.stringify(e)),r(e)},ww.createCorpGroupChat(e)})):null}catch(e){wxdebug(JSON.stringify(e))}},addUserInfoGroup:async e=>{wxdebug("addUserInfoGroup"+JSON.stringify(e));try{let t=await this.registerCorpWithSuite();return wxdebug("isRegister"+t),t?(wxdebug(JSON.stringify(e)),new Promise(((t,r)=>{e.success=e=>{wxdebug(JSON.stringify(e)),t(e)},e.fail=e=>{wxdebug(JSON.stringify(e)),r(e)},ww.updateCorpGroupChat(e)}))):null}catch(e){wxdebug(JSON.stringify(e))}}},this.cid=e?.cid,this.appId=e?.appId,this.wecorp=new WxworkCorp(this.cid)}async syncGroupChat(e){let t=new Parse.Query("GroupChat");t.equalTo("chat_id",e?.chat_id);let r=await t.first();if(r?.id||(r=new Parse.Object("GroupChat")),!r?.get("joinUrl")){let t=(await this.wecorp.externalContact.groupChat.addJoinWay({scene:1,chat_id_list:[e.chat_id]}))?.config_id,o=(await this.wecorp.externalContact.groupChat.getJoinWay(t))?.join_way;r.set("joinUrl",o)}if(!r?.get("joinQrcode")){let t=(await this.wecorp.externalContact.groupChat.addJoinWay({scene:2,chat_id_list:[e.chat_id]}))?.config_id,o=(await this.wecorp.externalContact.groupChat.getJoinWay(t))?.join_way;r.set("joinQrcode",o)}let o={chat_id:e.chat_id,name:e.name,owner:e.owner,notice:e.notice},i=!1;return r.get("chat_id")!=e.chat_id&&(i=!0),r.get("name")!=e.name&&(i=!0),r.get("owner")!=e.owner&&(i=!0),r.get("notice")!=e.notice&&(i=!0),r.get("member_version")!=e.member_version&&(i=!0,o.member_list=e.member_list,o.member_version=e.member_version),r.set(o),this.cid&&r.set("company",{__type:"Pointer",className:"Company",objectId:this.cid}),i&&(r=await r.save()),r}async syncContact(e){const t=e.external_contact||e,r=t.external_userid;let o=new Parse.Query("ContactInfo");o.equalTo("external_userid",r);const i=new Parse.Object("Company");i.id=this.cid,o.equalTo("company",i);let a=await o.first();a?.id||(a=new Parse.Object("ContactInfo"),i?.id&&a.set("company",i.toPointer()));const n=t.name||"",s=t.mobile||"",c={...t,follow_user:e.follow_user||t.follow_user||[]};let l=!1;a.get("external_userid")!=r&&(l=!0),a.get("name")!=n&&n&&(l=!0),a.get("mobile")!=s&&s&&(l=!0);const d=a.get("data");return JSON.stringify(d)!==JSON.stringify(c)&&(l=!0),a.set("external_userid",r),a.set("name",n),a.set("mobile",s),a.set("data",c),wxdebug("syncContact",a.toJSON()),l&&(a=await a.save()),a}async getCurrentChatObject(){const e=await this.getCurrentChat();if(!e)return{currentChat:null};let t,r;try{if("chatId"===e.type&&e.group)t=await this.syncGroupChat(e.group);else if("userId"===e.type&&e.id){const t=await this.wecorp.externalContact.get(e.id);r=await this.syncContact(t)}}catch(e){console.error("getCurrentChatObject error:",e)}return{GroupChat:t,Contact:r,currentChat:e}}async syncUserInfo(e){let t=null;1==e.gender&&(t="男"),2==e.gender&&(t="女");let r=await this.getContactOrProfile(e);console.log("thisUser",r),console.log("userInfo",e),"UserSocial"==r.className&&r.set({data:{openid:e.openid,userid:e.userid,external_userid:e.external_userid,type:e.type&&String(e.type)||null,name:e.name,avatar:e.avatar,gender:t,qr_code:e.qr_code,mobile:e.mobile,email:e.email,biz_mail:e.biz_mail,address:e.address,position:e.position,corp_name:e.corp_name},type:"wecom-agency",company:{__type:"Pointer",className:"Company",objectId:this.cid}}),"Profile"==r.className&&(r.set({openid:e.openid,userid:e.userid,external_userid:e.external_userid,type:e.type&&String(e.type)||null,name:e.name,avatar:e.avatar,gender:t,qr_code:e.qr_code,mobile:e.mobile,email:e.email,biz_mail:e.biz_mail,address:e.address,position:e.position,corp_name:e.corp_name,company:{__type:"Pointer",className:"Company",objectId:this.cid}}),r.set("data",e));try{r=await r.save()}catch(e){wxdebug(e)}return r}async getUserinfo(e){let t,r;wxdebug("getUserinfo");let o=localStorage.getItem(`${this.cid}/USERINFO`);if(!e){t=JSON.parse(o),t.cid=this.cid,wxdebug("getContactOrProfile");try{r=await this.getContactOrProfile(t)}catch(e){}if(wxdebug("getUserinfo:"+o),t&&r)return t}if(!(e=new URL(location.href).searchParams.get("code")||e))return null;let i=await this.wecorp.auth.getuserinfo(e);if(wxdebug("result"+JSON.stringify(i)),i?.errcode)return console.error(i?.errmsg),null;let a=i?.external_userid;if(a){let e=await this.wecorp.externalContact.get(a);e?.external_contact&&Object.keys(e?.external_contact).forEach((t=>{i[t]=e?.external_contact[t]}))}return i.cid=this.cid,t=i,r=await this.getContactOrProfile(t),r?.get("mobile")&&(t.mobile=r?.get("mobile")),o=JSON.stringify(i),localStorage.setItem(`${this.cid}/USERINFO`,o),t}async getCurrentUser(){const e=await this.getUserinfo();if(!e)return null;return await this.getContactOrProfile(e)}async getContactOrProfile(e){let t;(e.openid||e.external_userid)&&(t="UserSocial"),e.userid&&(t="Profile");let r=[];"Profile"==t&&(e.openid&&r.push({openid:{$regex:e.openid}}),e.userid&&r.push({userid:{$regex:e.userid}}),e.mobile&&r.push({mobile:{$regex:e.mobile}}),e.email&&r.push({email:{$regex:e.email}}),e.external_userid&&r.push({external_userid:{$regex:e.external_userid}})),"UserSocial"==t&&(e.openid&&r.push({"data.openid":{$regex:e.openid}}),e.userid&&r.push({"data.userid":{$regex:e.userid}}),e.mobile&&r.push({"data.mobile":{$regex:e.mobile}}),e.email&&r.push({"data.email":{$regex:e.email}}),e.external_userid&&r.push({"data.external_userid":{$regex:e.external_userid}}));let o,i=Parse.Query.fromJSON(t,{where:{$or:r}});i.equalTo("company",this.cid),i.equalTo("userid",e.userid);try{o=await i.first()}catch(e){console.error(e)}o?.id||(o=new Parse.Object(t));let a=Parse.User.current();return a?.id&&(o?.get("user")?.id||o.set("user",a.toPointer())),o}async loginPC(){let e=await this.getCorpByCid(this.cid);console.log(this.cid,e);let t=e?.corpId,r=e?.agentId,o=new URL("https://app.fmode.cn"+location.pathname+location?.search);o.searchParams.delete("code"),o.searchParams.delete("state");let i=encodeURIComponent(o.href),a=ww.WWLoginType.corpApp,n=ww.WWLoginRedirectType.callback;return console.log("loginPC1"),new Promise((e=>{console.log("loginPC2");const o=this.ww.createWWLoginPanel({el:"#ww_login",params:{login_type:a,appid:t,agentid:r,redirect_uri:i,state:"loginState",redirect_type:n},onCheckWeComLogin({isWeComLogin:t}){console.log(t),e("")},onLoginSuccess({code:t}){console.log({code:t}),e(t)},onLoginFail(t){console.error("lpc",t),e("")}});console.log(o,o.el)}))}async oauth(e="snsapi_base",t=!1){t&&localStorage.removeItem(`${this.cid}/USERINFO`),wxdebug("oauth");let r=await this.getCorpByCid(this.cid);console.log(this.cid,r);let o=r?.corpId,i=r?.agentId,a=new URL("https://app.fmode.cn"+location.pathname+location?.search);a.searchParams.delete("code"),a.searchParams.delete("state");let n=encodeURIComponent(a.href),s=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${o}&redirect_uri=${n}&response_type=code&scope=${e}&state=STATE&agentid=${i}#wechat_redirect`;if("h5"==this.platform()){if(location.host?.startsWith("localhost"))return"";s=`https://login.work.weixin.qq.com/wwlogin/sso/login?login_type=CorpApp&appid=${o}&agentid=${i}&redirect_uri=${n}&state=WWLogin`,console.log("createWWLoginPanel")}return location.href=s,null}async getCorpByCid(e){if(console.log("cid",e),this.corpId)return this.corpId;let t=new Parse.Query("CloudResource"),r=(await t.get(this.companyMap[e]?.corpResId)).get("config");return console.log("config",r),r}async registerCorpWithSuite(e,t,r){if("wxwork"!=this.platform())return!1;if(!r?.length&&this.registerUrl==location.href)return!0;r=r||jsApiList;try{e=e||this.cid,t=t||this.appId;let o=await this.getCorpByCid(e);console.log(o);let i=o?.corpId,a=this.suiteMap[t]?.suiteId;console.log(i,a);let n=new Date,s=new Promise((e=>{ww.register({corpId:o.corpId,suiteId:a,agentId:o.agentId,jsApiList:r,getAgentConfigSignature:async()=>{let e=await this.wecorp.ticket.get();return ww.getSignature({ticket:e,nonceStr:"666",timestamp:(n.getTime()/1e3).toFixed(0),url:location.href})},onAgentConfigSuccess:()=>{this.registerUrl=location.href,e(!0)},onAgentConfigFail:t=>{e(!1)},onConfigFail:t=>{e(!1)}})}));return await s}catch(e){return wxdebug(JSON.stringify(e)),!1}}getUA(){return this.ua=navigator.userAgent.toLowerCase(),this.ua}platform(){return this.ua=navigator.userAgent.toLowerCase(),this.ua.indexOf("wxwork")>-1?"wxwork":this.ua.indexOf("wechat")>-1?"wechat":"h5"}async getContext(){await this.registerCorpWithSuite();try{let e=await ww.getContext();return e?.entry&&(this.entry=e?.entry),e}catch(e){this.entryError="请先注册JSAPI"+e.errCode+e.errMsg,console.error(e)}return null}async getCurrentChat(){let e;if(!await this.registerCorpWithSuite())return null;try{e=await ww.getContext()}catch(e){console.error(e)}let t,r,o,i,a=e?.entry;try{return"group_chat_tools"==a&&(t="chatId",r=(await ww.getCurExternalChat())?.chatId,i=await this.wecorp.externalContact.groupChat.get(r)),"contact_profile"!=a&&"single_chat_tools"!=a||(t="userId",r=(await ww.getCurExternalContact())?.userId,o=await this.wecorp.externalContact.get(r)),this.currentChat={type:t,id:r,group:i?.group_chat,contact:o?.external_contact,follow_user:o?.follow_user},this.currentChat}catch(e){return wxdebug(JSON.stringify(e)),null}}version(){return wxdebug(ww.SDK_VERSION),ww.SDK_VERSION}register(){ww.register({corpId:"ww7ca4776b2a70000",jsApiList:["getExternalContact"],getConfigSignature:this.getConfigSignature})}async getConfigSignature(e){return{timestamp:"",nonceStr:"",signature:""}}config(){}async selectEnterpriseContact(){let e=await ww.selectEnterpriseContact({fromDepartmentId:-1,mode:"multi",type:["department","user"]});console.log(e),wxdebug(e)}}export const jsApiList=["getContext","getCurExternalChat","getCurExternalContact","createCorpGroupChat","updateCorpGroupChat","checkJsApi","onMenuShareAppMessage","onMenuShareWechat","onMenuShareTimeline","shareAppMessage","shareWechatMessage","startRecord","stopRecord","onVoiceRecordEnd","playVoice","pauseVoice","stopVoice","uploadVoice","downloadVoice","chooseImage","previewImage","uploadImage","downloadImage","getNetworkType","openLocation","getLocation","hideOptionMenu","showOptionMenu","hideMenuItems","showMenuItems","hideAllNonBaseMenuItem","showAllNonBaseMenuItem","closeWindow","scanQRCode","previewFile","openEnterpriseChat","selectEnterpriseContact","onHistoryBack","openDefaultBrowser"];
8
+ import*as ww from"@wecom/jssdk";import{FmodeParse}from"../../parse";const Parse=FmodeParse.with("nova");import{WxworkCorp}from"./wxwork.corp";import{wxdebug}from"../wxdebug";export class WxworkSDK{constructor(e){this.companyMap={E4KpGvTEto:{corpResId:"vsVIWbd1i9"},uRiDGwEYLi:{corpResId:"JxfFXBr0ly"},cDL6R1hgSi:{corpResId:"SpL6gyD1Gu"}},this.suiteMap={crm:{suiteId:"dk2559ba758f33d8f5"}},this.ww=ww,this.groupChat={createGroupChat:async e=>{try{return wxdebug("createGroupChat"+JSON.stringify(e)),await this.registerCorpWithSuite()?new Promise(((t,r)=>{e.success=e=>{wxdebug(JSON.stringify(e)),t(e)},e.fail=e=>{wxdebug(JSON.stringify(e)),r(e)},ww.createCorpGroupChat(e)})):null}catch(e){wxdebug(JSON.stringify(e))}},addUserInfoGroup:async e=>{wxdebug("addUserInfoGroup"+JSON.stringify(e));try{let t=await this.registerCorpWithSuite();return wxdebug("isRegister"+t),t?(wxdebug(JSON.stringify(e)),new Promise(((t,r)=>{e.success=e=>{wxdebug(JSON.stringify(e)),t(e)},e.fail=e=>{wxdebug(JSON.stringify(e)),r(e)},ww.updateCorpGroupChat(e)}))):null}catch(e){wxdebug(JSON.stringify(e))}}},this.cid=e?.cid,this.appId=e?.appId,this.wecorp=new WxworkCorp(this.cid)}async syncGroupChat(e){let t=new Parse.Query("GroupChat");t.equalTo("chat_id",e?.chat_id);let r=await t.first();if(r?.id||(r=new Parse.Object("GroupChat")),!r?.get("joinUrl")){let t=(await this.wecorp.externalContact.groupChat.addJoinWay({scene:1,chat_id_list:[e.chat_id]}))?.config_id,o=(await this.wecorp.externalContact.groupChat.getJoinWay(t))?.join_way;r.set("joinUrl",o)}if(!r?.get("joinQrcode")){let t=(await this.wecorp.externalContact.groupChat.addJoinWay({scene:2,chat_id_list:[e.chat_id]}))?.config_id,o=(await this.wecorp.externalContact.groupChat.getJoinWay(t))?.join_way;r.set("joinQrcode",o)}let o={chat_id:e.chat_id,name:e.name,owner:e.owner,notice:e.notice},i=!1;return r.get("chat_id")!=e.chat_id&&(i=!0),r.get("name")!=e.name&&(i=!0),r.get("owner")!=e.owner&&(i=!0),r.get("notice")!=e.notice&&(i=!0),r.get("member_version")!=e.member_version&&(i=!0,o.member_list=e.member_list,o.member_version=e.member_version),r.set(o),this.cid&&r.set("company",{__type:"Pointer",className:"Company",objectId:this.cid}),i&&(r=await r.save()),r}async syncContact(e){const t=e.external_contact||e,r=t.external_userid;let o=new Parse.Query("ContactInfo");o.equalTo("external_userid",r);const i=new Parse.Object("Company");i.id=this.cid,o.equalTo("company",i);let a=await o.first();a?.id||(a=new Parse.Object("ContactInfo"),i?.id&&a.set("company",i.toPointer()));const n=t.name||"",s=t.mobile||"",c={...t,follow_user:e.follow_user||t.follow_user||[]};let l=!1;a.get("external_userid")!=r&&(l=!0),a.get("name")!=n&&n&&(l=!0),a.get("mobile")!=s&&s&&(l=!0);const d=a.get("data");return JSON.stringify(d)!==JSON.stringify(c)&&(l=!0),a.set("external_userid",r),a.set("name",n),a.set("mobile",s),a.set("data",c),wxdebug("syncContact",a.toJSON()),l&&(a=await a.save()),a}async getCurrentChatObject(){const e=await this.getCurrentChat();if(!e)return{currentChat:null};let t,r;try{if("chatId"===e.type&&e.group)t=await this.syncGroupChat(e.group);else if("userId"===e.type&&e.id){const t=await this.wecorp.externalContact.get(e.id);r=await this.syncContact(t)}}catch(e){console.error("getCurrentChatObject error:",e)}return{GroupChat:t,Contact:r,currentChat:e}}async syncUserInfo(e){let t=null;1==e.gender&&(t="男"),2==e.gender&&(t="女");let r=await this.getContactOrProfile(e);console.log("thisUser",r),console.log("userInfo",e),"UserSocial"==r.className&&r.set({data:{openid:e.openid,userid:e.userid,external_userid:e.external_userid,type:e.type&&String(e.type)||null,name:e.name,avatar:e.avatar,gender:t,qr_code:e.qr_code,mobile:e.mobile,email:e.email,biz_mail:e.biz_mail,address:e.address,position:e.position,corp_name:e.corp_name},type:"wecom-agency",company:{__type:"Pointer",className:"Company",objectId:this.cid}}),"Profile"==r.className&&(r.set({openid:e.openid,userid:e.userid,external_userid:e.external_userid,type:e.type&&String(e.type)||null,name:e.name,avatar:e.avatar,gender:t,qr_code:e.qr_code,mobile:e.mobile,email:e.email,biz_mail:e.biz_mail,address:e.address,position:e.position,corp_name:e.corp_name,company:{__type:"Pointer",className:"Company",objectId:this.cid}}),r.set("data",e));try{r=await r.save()}catch(e){wxdebug(e)}return r}async getUserinfo(e){let t,r;wxdebug("getUserinfo");let o=localStorage.getItem(`${this.cid}/USERINFO`);if(!e){t=JSON.parse(o),t.cid=this.cid,wxdebug("getContactOrProfile");try{r=await this.getContactOrProfile(t)}catch(e){}if(wxdebug("getUserinfo:"+o),t&&r)return t}if(!(e=new URL(location.href).searchParams.get("code")||e))return null;let i=await this.wecorp.auth.getuserinfo(e);if(wxdebug("result"+JSON.stringify(i)),i?.errcode)return console.error(i?.errmsg),null;let a=i?.external_userid;if(a){let e=await this.wecorp.externalContact.get(a);e?.external_contact&&Object.keys(e?.external_contact).forEach((t=>{i[t]=e?.external_contact[t]}))}return i.cid=this.cid,t=i,r=await this.getContactOrProfile(t),r?.get("mobile")&&(t.mobile=r?.get("mobile")),o=JSON.stringify(i),localStorage.setItem(`${this.cid}/USERINFO`,o),t}async getCurrentUser(){const e=await this.getUserinfo();if(!e)return null;return await this.getContactOrProfile(e)}async getContactOrProfile(e){let t;(e.openid||e.external_userid)&&(t="UserSocial"),e.userid&&(t="Profile");let r=[];"Profile"==t&&(e.openid&&r.push({openid:{$regex:e.openid}}),e.userid&&r.push({userid:{$regex:e.userid}}),e.mobile&&r.push({mobile:{$regex:e.mobile}}),e.email&&r.push({email:{$regex:e.email}}),e.external_userid&&r.push({external_userid:{$regex:e.external_userid}})),"UserSocial"==t&&(e.openid&&r.push({"data.openid":{$regex:e.openid}}),e.userid&&r.push({"data.userid":{$regex:e.userid}}),e.mobile&&r.push({"data.mobile":{$regex:e.mobile}}),e.email&&r.push({"data.email":{$regex:e.email}}),e.external_userid&&r.push({"data.external_userid":{$regex:e.external_userid}}));let o,i=Parse.Query.fromJSON(t,{where:{$or:r}});i.equalTo("company",this.cid),i.equalTo("userid",e.userid);try{o=await i.first()}catch(e){console.error(e)}o?.id||(o=new Parse.Object(t));let a=Parse.User.current();return a?.id&&(o?.get("user")?.id||o.set("user",a.toPointer())),o}async loginPC(){let e=await this.getCorpByCid(this.cid);console.log(this.cid,e);let t=e?.corpId,r=e?.agentId,o=new URL("https://app.fmode.cn"+location.pathname+location?.search);o.searchParams.delete("code"),o.searchParams.delete("state");let i=encodeURIComponent(o.href),a=ww.WWLoginType.corpApp,n=ww.WWLoginRedirectType.callback;return console.log("loginPC1"),new Promise((e=>{console.log("loginPC2");const o=this.ww.createWWLoginPanel({el:"#ww_login",params:{login_type:a,appid:t,agentid:r,redirect_uri:i,state:"loginState",redirect_type:n},onCheckWeComLogin({isWeComLogin:t}){console.log(t),e("")},onLoginSuccess({code:t}){console.log({code:t}),e(t)},onLoginFail(t){console.error("lpc",t),e("")}});console.log(o,o.el)}))}async oauth(e="snsapi_base",t=!1){t&&localStorage.removeItem(`${this.cid}/USERINFO`),wxdebug("oauth");let r=await this.getCorpByCid(this.cid);console.log(this.cid,r);let o=r?.corpId,i=r?.agentId,a=new URL("https://app.fmode.cn"+location.pathname+location?.search);a.searchParams.delete("code"),a.searchParams.delete("state");let n=encodeURIComponent(a.href),s=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${o}&redirect_uri=${n}&response_type=code&scope=${e}&state=STATE&agentid=${i}#wechat_redirect`;if("h5"==this.platform()){if(location.host?.startsWith("localhost"))return"";s=`https://login.work.weixin.qq.com/wwlogin/sso/login?login_type=CorpApp&appid=${o}&agentid=${i}&redirect_uri=${n}&state=WWLogin`,console.log("createWWLoginPanel")}return location.href=s,null}async getCorpByCid(e){if(console.log("cid",e),this.corpId)return this.corpId;let t=new Parse.Query("CloudResource"),r=(await t.get(this.companyMap[e]?.corpResId)).get("config");return console.log("config",r),r}async registerCorpWithSuite(e,t,r){if("wxwork"!=this.platform())return!1;if(!r?.length&&this.registerUrl==location.href)return!0;r=r||jsApiList;try{e=e||this.cid,t=t||this.appId;let o=await this.getCorpByCid(e);console.log(o);let i=o?.corpId,a=this.suiteMap[t]?.suiteId;console.log(i,a);let n=new Date,s=new Promise((e=>{ww.register({corpId:o.corpId,suiteId:a,agentId:o.agentId,jsApiList:r,getAgentConfigSignature:async()=>{let e=await this.wecorp.ticket.get();return ww.getSignature({ticket:e,nonceStr:"666",timestamp:(n.getTime()/1e3).toFixed(0),url:location.href})},onAgentConfigSuccess:()=>{this.registerUrl=location.href,e(!0)},onAgentConfigFail:t=>{e(!1)},onConfigFail:t=>{e(!1)}})}));return await s}catch(e){return wxdebug(JSON.stringify(e)),!1}}getUA(){return this.ua=navigator.userAgent.toLowerCase(),this.ua}platform(){return this.ua=navigator.userAgent.toLowerCase(),this.ua.indexOf("wxwork")>-1?"wxwork":this.ua.indexOf("wechat")>-1?"wechat":"h5"}async getContext(){await this.registerCorpWithSuite();try{let e=await ww.getContext();return e?.entry&&(this.entry=e?.entry),e}catch(e){this.entryError="请先注册JSAPI"+e.errCode+e.errMsg,console.error(e)}return null}async getCurrentChat(){let e;if(!await this.registerCorpWithSuite())return null;try{e=await ww.getContext()}catch(e){console.error(e)}let t,r,o,i,a=e?.entry;try{return"group_chat_tools"==a&&(t="chatId",r=(await ww.getCurExternalChat())?.chatId,i=await this.wecorp.externalContact.groupChat.get(r)),"contact_profile"!=a&&"single_chat_tools"!=a||(t="userId",r=(await ww.getCurExternalContact())?.userId,o=await this.wecorp.externalContact.get(r)),this.currentChat={type:t,id:r,group:i?.group_chat,contact:o?.external_contact,follow_user:o?.follow_user},this.currentChat}catch(e){return wxdebug(JSON.stringify(e)),null}}version(){return wxdebug(ww.SDK_VERSION),ww.SDK_VERSION}register(){ww.register({corpId:"ww7ca4776b2a70000",jsApiList:["getExternalContact"],getConfigSignature:this.getConfigSignature})}async getConfigSignature(e){return{timestamp:"",nonceStr:"",signature:""}}config(){}async selectEnterpriseContact(){let e=await ww.selectEnterpriseContact({fromDepartmentId:-1,mode:"multi",type:["department","user"]});console.log(e),wxdebug(e)}}export const jsApiList=["getContext","getCurExternalChat","getCurExternalContact","createCorpGroupChat","updateCorpGroupChat","checkJsApi","onMenuShareAppMessage","onMenuShareWechat","onMenuShareTimeline","shareAppMessage","shareWechatMessage","startRecord","stopRecord","onVoiceRecordEnd","playVoice","pauseVoice","stopVoice","uploadVoice","downloadVoice","chooseImage","previewImage","uploadImage","downloadImage","getNetworkType","openLocation","getLocation","hideOptionMenu","showOptionMenu","hideMenuItems","showMenuItems","hideAllNonBaseMenuItem","showAllNonBaseMenuItem","closeWindow","scanQRCode","previewFile","openEnterpriseChat","selectEnterpriseContact","onHistoryBack","openDefaultBrowser"];
9
9
  var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9jb3JlL3NvY2lhbC93eHdvcmsvd3h3b3JrLnNkay5tanM=`
10
10
 
@@ -5,6 +5,6 @@
5
5
  * 保留所有权利 All Rights Reserved.
6
6
  * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2022/lib/social/index.mjs
7
7
  */
8
- export*from"./wechat/wechat-jssdk.service";export*from"./wxwork/wxwork-auth.guard";export*from"./wxdebug";export*from"../core/social";
8
+ export*from"./wechat/wechat-jssdk.service";export*from"./wxwork/wxwork-auth.guard";export*from"../core/social";
9
9
  var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIyL2xpYi9zb2NpYWwvaW5kZXgubWpz`
10
10