@nocobase/plugin-user-data-sync 1.4.0-alpha.20240911231734 → 1.4.0-alpha.20240914084300

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.
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- (function(o,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("@nocobase/utils/client"),require("react-i18next"),require("react/jsx-runtime"),require("antd"),require("react"),require("@ant-design/icons"),require("@formily/react"),require("@formily/core")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/utils/client","react-i18next","react/jsx-runtime","antd","react","@ant-design/icons","@formily/react","@formily/core"],e):(o=typeof globalThis!="undefined"?globalThis:o||self,e(o["@nocobase/plugin-user-data-sync"]={},o["@nocobase/client"],o["@nocobase/utils"],o["react-i18next"],o.jsxRuntime,o.antd,o.react,o["@ant-design/icons"],o["@formily/react"],o["@formily/core"]))})(this,function(o,e,c,g,r,m,a,d,u,y){"use strict";var X=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var k=(o,e,c)=>e in o?X(o,e,{enumerable:!0,configurable:!0,writable:!0,value:c}):o[e]=c,C=(o,e)=>{for(var c in e||(e={}))$.call(e,c)&&k(o,c,e[c]);if(I)for(var c of I(e))ee.call(e,c)&&k(o,c,e[c]);return o},P=(o,e)=>Y(o,Z(e));var B=(o,e,c)=>(k(o,typeof e!="symbol"?e+"":e,c),c);var f=(o,e,c)=>new Promise((g,r)=>{var m=u=>{try{d(c.next(u))}catch(y){r(y)}},a=u=>{try{d(c.throw(u))}catch(y){r(y)}},d=u=>u.done?g(u.value):Promise.resolve(u.value).then(m,a);d((c=c.apply(o,e)).next())});const S="user-data-sync";function T(){return g.useTranslation([S,"client"],{nsMode:"fallback"})}const D={name:"userDataSyncSources",sortable:!0,filterTargetKey:"id",fields:[{name:"id",type:"string",interface:"id"},{interface:"input",type:"string",name:"name",uiSchema:{type:"string",title:'{{t("Source name")}}',"x-component":"Input",required:!0}},{interface:"input",type:"string",name:"sourceType",allowNull:!1,uiSchema:{type:"string",title:'{{t("Type")}}',"x-component":"Select",required:!0,dataSource:"{{ types }}"}},{type:"boolean",name:"enabled",uiSchema:{type:"boolean",title:'{{t("Enabled")}}',"x-component":"Checkbox"}}]},w={name:"userDataSyncTasks",filterTargetKey:"id",fields:[{name:"id",type:"bigInt",interface:"id"},{name:"batch",interface:"input",type:"string",allowNull:!1,uiSchema:{type:"string",title:'{{t("Batch")}}',"x-component":"Input",required:!0}},{name:"source",interface:"input",type:"belongsTo",target:"userDataSyncSources",targetKey:"id",foreignKey:"sourceId",allowNull:!1,uiSchema:{type:"object",title:'{{t("Source")}}',"x-component":"AssociationField","x-component-props":{fieldNames:{value:"id",label:"name"}},required:!0,"x-read-pretty":!0}},{name:"status",interface:"input",type:"string",allowNull:!1,uiSchema:{type:"string",title:'{{t("Status")}}',"x-component":"Select",required:!0,enum:[{label:'{{t("Init")}}',value:"init",color:"default"},{label:'{{t("Processing")}}',value:"processing",color:"processing"},{label:'{{t("Success")}}',value:"success",color:"success"},{label:'{{t("Failed")}}',value:"failed",color:"error"}]}},{name:"message",interface:"input",type:"string",allowNull:!0,uiSchema:{type:"string",title:'{{t("Message")}}',"x-component":"Input",required:!1}},{name:"cost",interface:"input",type:"integer",allowNull:!0,uiSchema:{type:"integer",title:'{{t("Cost")}}',"x-component":"InputNumber","x-component-props":{precision:0},required:!1}}]},q={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{t("Add new")}}',properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useCustomFormProps",properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},sourceType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":"useSubmitActionProps","x-component-props":{type:"primary"}}}}}}}}}},V={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{ t("Tasks") }}',properties:{table:{type:"void","x-decorator":"TableBlockProvider","x-use-decorator-props":"useTasksTableBlockProps","x-decorator-props":{collection:w.name,dragSort:!1,action:"list",showIndex:!0},properties:{table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id"},properties:{batch:{type:"void",title:'{{ t("Batch") }}',"x-component":"TableV2.Column",properties:{batch:{type:"string","x-component":"CollectionField","x-pattern":"readPretty"}}},status:{type:"void",title:'{{ t("Status") }}',"x-component":"TableV2.Column",properties:{status:{type:"string","x-component":"CollectionField","x-pattern":"readPretty"}}},message:{type:"void",title:'{{ t("Message") }}',"x-component":"TableV2.Column",properties:{message:{type:"string","x-component":"CollectionField","x-pattern":"readPretty"}}},actions:{type:"void",title:'{{t("Actions")}}',"x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{sync:{type:"void",title:'{{ t("Retry") }}',"x-component":"Action.Link","x-use-component-props":"useRetryActionProps","x-display":'{{ $record.status === "failed" ? "visible" : "hidden" }}'}}}}}}}}}}}}},N={type:"void",name:"userDataSyncSources","x-component":"CardItem","x-decorator":"TableBlockProvider","x-decorator-props":{collection:D.name,dragSort:!1,action:"list",params:{pageSize:10},showIndex:!0},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-component":"Action","x-use-component-props":"useBulkDestroyActionProps","x-component-props":{icon:"DeleteOutlined",confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"AddNew","x-component-props":{type:"primary"}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{name:{type:"void",title:'{{t("Source name")}}',"x-component":"TableV2.Column",properties:{name:{type:"string","x-component":"CollectionField","x-pattern":"readPretty"}}},sourceType:{type:"void",title:'{{t("Type")}}',"x-component":"TableV2.Column",properties:{sourceType:{type:"string","x-component":"Select","x-pattern":"readPretty",enum:"{{ types }}"}}},enabled:{type:"void",title:'{{t("Enabled")}}',"x-component":"TableV2.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-pattern":"readPretty"}}},actions:{type:"void",title:'{{t("Actions")}}',"x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{sync:{type:"void",title:'{{ t("Sync") }}',"x-component":"Action.Link","x-use-component-props":"useSyncActionProps","x-display":'{{ $record.enabled ? "visible" : "hidden" }}'},tasks:{type:"void",title:'{{ t("Tasks") }}',"x-component":"Tasks","x-component-props":{type:"primary"},"x-display":'{{ $record.enabled ? "visible" : "hidden" }}'},edit:{type:"void",title:'{{t("Configure")}}',"x-component":"Action.Link","x-component-props":{type:"primary",openMode:"drawer"},properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{t("Configure")}}',properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useEditFormProps",properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},sourceType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":"useSubmitActionProps","x-component-props":{type:"primary"}}}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-use-component-props":"useDeleteActionProps"}}}}}}}}},v=a.createContext({type:""});v.displayName="SourceTypeContext";const A=a.createContext({types:[]});A.displayName="SourceTypesContext";const E=()=>{const{types:t}=a.useContext(A);return t},M=t=>{const s=e.useCollectionRecordData(),n=e.useRequest(()=>Promise.resolve({data:C({},s.options)}),P(C({},t),{manual:!0})),{run:i}=n,p=e.useActionContext();return a.useEffect(()=>{p.visible&&i()},[p.visible,i]),n},K=t=>{var i;const n=e.usePlugin(h).sourceTypes.get(t);return(i=n==null?void 0:n.components)==null?void 0:i.AdminSettingsForm},j=u.observer(()=>{const t=u.useForm(),s=e.useCollectionRecordData(),n=K(t.values.sourceType||s.sourceType);return n?r.jsx(n,{}):null},{displayName:"Options"}),O=()=>{const t=e.useCollectionRecordData();return{form:a.useMemo(()=>y.createForm({values:t}),[])}},_=()=>{const{setVisible:t}=e.useActionContext(),{message:s}=m.App.useApp(),n=u.useForm(),i=e.useDataBlockResource(),{runAsync:p}=e.useDataBlockRequest(),x=e.useCollection();return{type:"primary",onClick(){return f(this,null,function*(){yield n.submit();const l=n.values;l[x.filterTargetKey]?yield i.update({values:l,filterByTk:l[x.filterTargetKey]}):yield i.create({values:l}),yield p(),s.success("Saved successfully"),t(!1)})}}};function L(){const{message:t}=m.App.useApp(),s=e.useCollectionRecordData(),n=e.useDataBlockResource(),i=e.useCollection(),{runAsync:p}=e.useDataBlockRequest();return{confirm:{title:"Delete",content:"Are you sure you want to delete it?"},onClick(){return f(this,null,function*(){yield n.destroy({filterByTk:s[i.filterTargetKey]}),yield p(),t.success("Deleted!")})}}}function z(){const{message:t}=m.App.useApp(),s=e.useCollectionRecordData(),n=e.useAPIClient(),{runAsync:i}=e.useDataBlockRequest();return{onClick(){return f(this,null,function*(){yield n.resource("userData").pull({name:s.name}),yield i(),t.success("Synced!")})}}}const U=()=>{const{type:t}=a.useContext(v);return{form:a.useMemo(()=>y.createForm({initialValues:{sourceType:t}}),[])}},R=()=>{const t=e.useCollectionRecordData(),s=e.useCollection();return{params:{pageSize:20,filter:{sourceId:t[s.filterTargetKey]},sort:["-sort"]}}};function G(){const{message:t}=m.App.useApp(),s=e.useCollectionRecordData();e.useDataBlockResource();const n=e.useCollection(),i=e.useAPIClient(),{runAsync:p}=e.useDataBlockRequest();return{onClick(){return f(this,null,function*(){yield i.resource("userData").retry({id:s[n.filterTargetKey],sourceId:s.sourceId}),yield p(),t.success("Successfully")})}}}const H=()=>{const{t}=T(),s=e.useAPIClient(),[n,i]=a.useState(!1),[p,x]=a.useState(""),b=E(),l=b.map(F=>P(C({},F),{onClick:()=>{i(!0),x(F.value)}})),W=[{key:"__empty__",label:r.jsx(m.Empty,{image:m.Empty.PRESENTED_IMAGE_SIMPLE,description:r.jsxs(r.Fragment,{children:[t("No user data source plugin installed",{ns:S}),r.jsx("br",{})," ",r.jsx("a",{target:"_blank",href:s.auth.locale==="zh-CN"?"https://docs-cn.nocobase.com/handbook/user-data-sync":"https://docs.nocobase.com/handbook/user-data-sync",rel:"noreferrer",children:t("View documentation",{ns:S})})]})}),onClick:()=>{}}];return r.jsx(e.ActionContextProvider,{value:{visible:n,setVisible:i},children:r.jsxs(v.Provider,{value:{type:p},children:[r.jsx(m.Dropdown,{menu:{items:l&&l.length>0?l:W},children:r.jsxs(m.Button,{icon:r.jsx(d.PlusOutlined,{}),type:"primary",children:[t("Add new")," ",r.jsx(d.DownOutlined,{})]})}),r.jsx(e.SchemaComponent,{scope:{types:b,setType:x,useCustomFormProps:U},schema:q})]})})},J=()=>{const{t}=T(),[s,n]=a.useState(!1);return r.jsxs(e.ActionContextProvider,{value:{visible:s,setVisible:n},children:[r.jsx(m.Button,{type:"link",onClick:()=>{n(!0)},children:t("Tasks")}),r.jsx(e.ExtendCollectionsProvider,{collections:[w],children:r.jsx(e.SchemaComponent,{scope:{useRetryActionProps:G,useTasksTableBlockProps:R},schema:V})})]})},Q=()=>{const{t}=T(),[s,n]=a.useState([]),i=e.useAPIClient();return e.useRequest(()=>i.resource("userData").listSyncTypes().then(p=>{var b;return(((b=p==null?void 0:p.data)==null?void 0:b.data)||[]).map(l=>({key:l.name,label:u.Schema.compile(l.title||l.name,{t}),value:l.name}))}),{onSuccess:p=>{n(p)}}),r.jsx(A.Provider,{value:{types:s},children:r.jsx(e.ExtendCollectionsProvider,{collections:[D],children:r.jsx(e.SchemaComponent,{schema:N,components:{AddNew:H,Options:j,Tasks:J},scope:{types:s,t,useEditFormProps:O,useSubmitActionProps:_,useDeleteActionProps:L,useSyncActionProps:z,useValuesFromOptions:M}})})})};class h extends e.Plugin{constructor(){super(...arguments);B(this,"sourceTypes",new c.Registry)}registerType(n,i){this.sourceTypes.register(n,i)}load(){return f(this,null,function*(){this.app.pluginSettingsManager.add("users-permissions.sync",{title:c.tval("Synchronize",{ns:S}),icon:"SyncOutlined",Component:Q,sort:99,aclSnippet:"pm.user-data-sync"})})}}o.PluginUserDataSyncClient=h,o.default=h,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
10
+ (function(o,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("@nocobase/utils/client"),require("react-i18next"),require("react/jsx-runtime"),require("antd"),require("react"),require("@ant-design/icons"),require("@formily/react"),require("@formily/core")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/utils/client","react-i18next","react/jsx-runtime","antd","react","@ant-design/icons","@formily/react","@formily/core"],e):(o=typeof globalThis!="undefined"?globalThis:o||self,e(o["@nocobase/plugin-user-data-sync"]={},o["@nocobase/client"],o["@nocobase/utils"],o["react-i18next"],o.jsxRuntime,o.antd,o.react,o["@ant-design/icons"],o["@formily/react"],o["@formily/core"]))})(this,function(o,e,c,T,r,m,p,b,l,f){"use strict";var X=Object.defineProperty,Z=Object.defineProperties;var $=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var k=(o,e,c)=>e in o?X(o,e,{enumerable:!0,configurable:!0,writable:!0,value:c}):o[e]=c,C=(o,e)=>{for(var c in e||(e={}))ee.call(e,c)&&k(o,c,e[c]);if(I)for(var c of I(e))te.call(e,c)&&k(o,c,e[c]);return o},P=(o,e)=>Z(o,$(e));var B=(o,e,c)=>(k(o,typeof e!="symbol"?e+"":e,c),c);var S=(o,e,c)=>new Promise((T,r)=>{var m=l=>{try{b(c.next(l))}catch(f){r(f)}},p=l=>{try{b(c.throw(l))}catch(f){r(f)}},b=l=>l.done?T(l.value):Promise.resolve(l.value).then(m,p);b((c=c.apply(o,e)).next())});const y="user-data-sync";function x(){return T.useTranslation([y,"client"],{nsMode:"fallback"})}const D={name:"userDataSyncSources",sortable:!0,filterTargetKey:"id",fields:[{name:"id",type:"string",interface:"id"},{interface:"input",type:"string",name:"name",uiSchema:{type:"string",title:'{{t("Source name")}}',"x-component":"Input",required:!0}},{interface:"input",type:"string",name:"sourceType",allowNull:!1,uiSchema:{type:"string",title:'{{t("Type")}}',"x-component":"Select",required:!0,dataSource:"{{ types }}"}},{type:"boolean",name:"enabled",uiSchema:{type:"boolean",title:'{{t("Enabled")}}',"x-component":"Checkbox"}}]},w={name:"userDataSyncTasks",filterTargetKey:"id",fields:[{name:"id",type:"bigInt",interface:"id"},{name:"batch",interface:"input",type:"string",allowNull:!1,uiSchema:{type:"string",title:'{{t("Batch")}}',"x-component":"Input",required:!0}},{name:"source",interface:"input",type:"belongsTo",target:"userDataSyncSources",targetKey:"id",foreignKey:"sourceId",allowNull:!1,uiSchema:{type:"object",title:'{{t("Source")}}',"x-component":"AssociationField","x-component-props":{fieldNames:{value:"id",label:"name"}},required:!0,"x-read-pretty":!0}},{name:"status",interface:"input",type:"string",allowNull:!1,uiSchema:{type:"string",title:'{{t("Status")}}',"x-component":"Select",required:!0,enum:[{label:'{{t("Init")}}',value:"init",color:"default"},{label:'{{t("Processing")}}',value:"processing",color:"processing"},{label:'{{t("Success")}}',value:"success",color:"success"},{label:'{{t("Failed")}}',value:"failed",color:"error"}]}},{name:"message",interface:"input",type:"string",allowNull:!0,uiSchema:{type:"string",title:'{{t("Message")}}',"x-component":"Input",required:!1}},{name:"cost",interface:"input",type:"integer",allowNull:!0,uiSchema:{type:"integer",title:'{{t("Cost")}}',"x-component":"InputNumber","x-component-props":{precision:0},required:!1}}]},q={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{t("Add new")}}',properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useCustomFormProps",properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},sourceType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":"useSubmitActionProps","x-component-props":{type:"primary"}}}}}}}}}},V={type:"object",properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{ t("Tasks") }}',properties:{table:{type:"void","x-decorator":"TableBlockProvider","x-use-decorator-props":"useTasksTableBlockProps","x-decorator-props":{collection:w.name,dragSort:!1,action:"list",showIndex:!0},properties:{table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id"},properties:{batch:{type:"void",title:'{{ t("Batch") }}',"x-component":"TableV2.Column",properties:{batch:{type:"string","x-component":"CollectionField","x-pattern":"readPretty"}}},status:{type:"void",title:'{{ t("Status") }}',"x-component":"TableV2.Column",properties:{status:{type:"string","x-component":"CollectionField","x-pattern":"readPretty"}}},message:{type:"void",title:'{{ t("Message") }}',"x-component":"TableV2.Column",properties:{message:{type:"string","x-component":"Message"}}},actions:{type:"void",title:'{{t("Actions")}}',"x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{sync:{type:"void",title:'{{ t("Retry") }}',"x-component":"Action.Link","x-use-component-props":"useRetryActionProps","x-display":'{{ $record.status === "failed" ? "visible" : "hidden" }}'}}}}}}}}}}}}},N={type:"void",name:"userDataSyncSources","x-component":"CardItem","x-decorator":"TableBlockProvider","x-decorator-props":{collection:D.name,dragSort:!1,action:"list",params:{pageSize:10},showIndex:!0},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:16}},properties:{delete:{type:"void",title:'{{t("Delete")}}',"x-component":"Action","x-use-component-props":"useBulkDestroyActionProps","x-component-props":{icon:"DeleteOutlined",confirm:{title:"{{t('Delete')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},create:{type:"void",title:'{{t("Add new")}}',"x-component":"AddNew","x-component-props":{type:"primary"}}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"id",rowSelection:{type:"checkbox"}},properties:{name:{type:"void",title:'{{t("Source name")}}',"x-component":"TableV2.Column",properties:{name:{type:"string","x-component":"CollectionField","x-pattern":"readPretty"}}},sourceType:{type:"void",title:'{{t("Type")}}',"x-component":"TableV2.Column",properties:{sourceType:{type:"string","x-component":"Select","x-pattern":"readPretty",enum:"{{ types }}"}}},enabled:{type:"void",title:'{{t("Enabled")}}',"x-component":"TableV2.Column",properties:{enabled:{type:"boolean","x-component":"CollectionField","x-pattern":"readPretty"}}},actions:{type:"void",title:'{{t("Actions")}}',"x-decorator":"TableV2.Column.ActionBar","x-component":"TableV2.Column",properties:{actions:{type:"void","x-component":"Space","x-component-props":{split:"|"},properties:{sync:{type:"void",title:'{{ t("Sync") }}',"x-component":"Action.Link","x-use-component-props":"useSyncActionProps","x-display":'{{ $record.enabled ? "visible" : "hidden" }}'},tasks:{type:"void",title:'{{ t("Tasks") }}',"x-component":"Tasks","x-component-props":{type:"primary"},"x-display":'{{ $record.enabled ? "visible" : "hidden" }}'},edit:{type:"void",title:'{{t("Configure")}}',"x-component":"Action.Link","x-component-props":{type:"primary",openMode:"drawer"},properties:{drawer:{type:"void","x-component":"Action.Drawer",title:'{{t("Configure")}}',properties:{form:{type:"void","x-component":"FormV2","x-use-component-props":"useEditFormProps",properties:{name:{"x-component":"CollectionField","x-decorator":"FormItem"},sourceType:{"x-component":"CollectionField","x-decorator":"FormItem","x-component-props":{options:"{{ types }}"}},enabled:{"x-component":"CollectionField","x-decorator":"FormItem"},options:{type:"object","x-component":"Options"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-use-component-props":"useSubmitActionProps","x-component-props":{type:"primary"}}}}}}}}}},delete:{type:"void",title:'{{ t("Delete") }}',"x-component":"Action.Link","x-use-component-props":"useDeleteActionProps"}}}}}}}}},g=p.createContext({type:""});g.displayName="SourceTypeContext";const v=p.createContext({types:[]});v.displayName="SourceTypesContext";const E=()=>{const{types:t}=p.useContext(v);return t},M=t=>{const n=e.useCollectionRecordData(),s=e.useRequest(()=>Promise.resolve({data:C({},n.options)}),P(C({},t),{manual:!0})),{run:i}=s,a=e.useActionContext();return p.useEffect(()=>{a.visible&&i()},[a.visible,i]),s},K=t=>{var i;const s=e.usePlugin(h).sourceTypes.get(t);return(i=s==null?void 0:s.components)==null?void 0:i.AdminSettingsForm},j=l.observer(()=>{const t=l.useForm(),n=e.useCollectionRecordData(),s=K(t.values.sourceType||n.sourceType);return s?r.jsx(s,{}):null},{displayName:"Options"}),O=()=>{const t=e.useCollectionRecordData();return{form:p.useMemo(()=>f.createForm({values:t}),[])}},_=()=>{const{setVisible:t}=e.useActionContext(),n=l.useForm(),s=e.useDataBlockResource(),{runAsync:i}=e.useDataBlockRequest(),a=e.useCollection();return{type:"primary",onClick(){return S(this,null,function*(){yield n.submit();const u=n.values;u[a.filterTargetKey]?yield s.update({values:u,filterByTk:u[a.filterTargetKey]}):yield s.create({values:u}),yield i(),t(!1)})}}};function z(){const t=e.useCollectionRecordData(),n=e.useDataBlockResource(),s=e.useCollection(),{runAsync:i}=e.useDataBlockRequest(),{t:a}=x();return{confirm:{title:a("Delete",{ns:y}),content:a("Are you sure you want to delete it?",{ns:y})},onClick(){return S(this,null,function*(){yield n.destroy({filterByTk:t[s.filterTargetKey]}),yield i()})}}}function L(){const{message:t}=m.App.useApp(),n=e.useCollectionRecordData(),s=e.useAPIClient(),{runAsync:i}=e.useDataBlockRequest(),{t:a}=x();return{onClick(){return S(this,null,function*(){yield s.resource("userData").pull({name:n.name}),yield i(),t.success(a("The synchronization has started. You can click on 'Tasks' to view the synchronization status.",{ns:y}))})}}}const U=()=>{const{type:t}=p.useContext(g);return{form:p.useMemo(()=>f.createForm({initialValues:{sourceType:t}}),[])}},R=()=>{const t=e.useCollectionRecordData(),n=e.useCollection();return{params:{pageSize:20,filter:{sourceId:t[n.filterTargetKey]},sort:["-sort"]}}};function G(){m.App.useApp();const t=e.useCollectionRecordData(),n=e.useCollection(),s=e.useAPIClient(),{runAsync:i}=e.useDataBlockRequest();return x(),{onClick(){return S(this,null,function*(){yield s.resource("userData").retry({id:t[n.filterTargetKey],sourceId:t.sourceId}),yield i()})}}}const Y=()=>{const{t}=x(),n=e.useAPIClient(),[s,i]=p.useState(!1),[a,A]=p.useState(""),u=E(),d=u.map(F=>P(C({},F),{onClick:()=>{i(!0),A(F.value)}})),W=[{key:"__empty__",label:r.jsx(m.Empty,{image:m.Empty.PRESENTED_IMAGE_SIMPLE,description:r.jsxs(r.Fragment,{children:[t("No user data source plugin installed",{ns:y}),r.jsx("br",{})," ",r.jsx("a",{target:"_blank",href:n.auth.locale==="zh-CN"?"https://docs-cn.nocobase.com/handbook/user-data-sync":"https://docs.nocobase.com/handbook/user-data-sync",rel:"noreferrer",children:t("View documentation",{ns:y})})]})}),onClick:()=>{}}];return r.jsx(e.ActionContextProvider,{value:{visible:s,setVisible:i},children:r.jsxs(g.Provider,{value:{type:a},children:[r.jsx(m.Dropdown,{menu:{items:d&&d.length>0?d:W},children:r.jsxs(m.Button,{icon:r.jsx(b.PlusOutlined,{}),type:"primary",children:[t("Add new")," ",r.jsx(b.DownOutlined,{})]})}),r.jsx(e.SchemaComponent,{scope:{types:u,setType:A,useCustomFormProps:U},schema:q})]})})},H=()=>{const{t}=x(),n=e.useCollectionRecordData();return r.jsx(e.ReadPretty.Input,{value:t(n.message),ellipsis:!0})},J=()=>{const{t}=x(),[n,s]=p.useState(!1);return r.jsxs(e.ActionContextProvider,{value:{visible:n,setVisible:s},children:[r.jsx(m.Button,{type:"link",onClick:()=>{s(!0)},children:t("Tasks")}),r.jsx(e.ExtendCollectionsProvider,{collections:[w],children:r.jsx(e.SchemaComponent,{scope:{useRetryActionProps:G,useTasksTableBlockProps:R,t},components:{Message:H},schema:V})})]})},Q=()=>{const{t}=x(),[n,s]=p.useState([]),i=e.useAPIClient();return e.useRequest(()=>i.resource("userData").listSyncTypes().then(a=>{var u;return(((u=a==null?void 0:a.data)==null?void 0:u.data)||[]).map(d=>({key:d.name,label:l.Schema.compile(d.title||d.name,{t}),value:d.name}))}),{onSuccess:a=>{s(a)}}),r.jsx(v.Provider,{value:{types:n},children:r.jsx(e.ExtendCollectionsProvider,{collections:[D],children:r.jsx(e.SchemaComponent,{schema:N,components:{AddNew:Y,Options:j,Tasks:J},scope:{types:n,t,useEditFormProps:O,useSubmitActionProps:_,useDeleteActionProps:z,useSyncActionProps:L,useValuesFromOptions:M}})})})};class h extends e.Plugin{constructor(){super(...arguments);B(this,"sourceTypes",new c.Registry)}registerType(s,i){this.sourceTypes.register(s,i)}load(){return S(this,null,function*(){this.app.pluginSettingsManager.add("users-permissions.sync",{title:c.tval("Synchronize",{ns:y}),icon:"SyncOutlined",Component:Q,sort:99,aclSnippet:"pm.user-data-sync"})})}}o.PluginUserDataSyncClient=h,o.default=h,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -10,15 +10,15 @@
10
10
  module.exports = {
11
11
  "react": "18.2.0",
12
12
  "@formily/react": "2.3.0",
13
- "@nocobase/client": "1.4.0-alpha.20240911231734",
13
+ "@nocobase/client": "1.4.0-alpha.20240914084300",
14
14
  "antd": "5.12.8",
15
15
  "@ant-design/icons": "5.2.6",
16
16
  "@formily/core": "2.3.0",
17
- "@nocobase/utils": "1.4.0-alpha.20240911231734",
18
- "@nocobase/server": "1.4.0-alpha.20240911231734",
19
- "@nocobase/logger": "1.4.0-alpha.20240911231734",
20
- "@nocobase/actions": "1.4.0-alpha.20240911231734",
17
+ "@nocobase/utils": "1.4.0-alpha.20240914084300",
18
+ "@nocobase/server": "1.4.0-alpha.20240914084300",
19
+ "@nocobase/logger": "1.4.0-alpha.20240914084300",
20
+ "@nocobase/actions": "1.4.0-alpha.20240914084300",
21
21
  "dayjs": "1.11.10",
22
- "@nocobase/database": "1.4.0-alpha.20240911231734",
22
+ "@nocobase/database": "1.4.0-alpha.20240914084300",
23
23
  "react-i18next": "11.18.6"
24
24
  };
package/dist/index.d.ts CHANGED
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  export * from './server';
10
- export { default, UserDataResource, FormatUser, SyncAccept, OriginRecord } from './server';
10
+ export { default, UserDataResource, FormatUser, SyncAccept, OriginRecord, ExternalAPIError, ErrorCodes, } from './server';
package/dist/index.js CHANGED
@@ -37,6 +37,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
  var src_exports = {};
39
39
  __export(src_exports, {
40
+ ErrorCodes: () => import_server.ErrorCodes,
41
+ ExternalAPIError: () => import_server.ExternalAPIError,
40
42
  FormatUser: () => import_server.FormatUser,
41
43
  OriginRecord: () => import_server.OriginRecord,
42
44
  SyncAccept: () => import_server.SyncAccept,
@@ -48,6 +50,8 @@ __reExport(src_exports, require("./server"), module.exports);
48
50
  var import_server = __toESM(require("./server"));
49
51
  // Annotate the CommonJS export names for ESM import in node:
50
52
  0 && (module.exports = {
53
+ ErrorCodes,
54
+ ExternalAPIError,
51
55
  FormatUser,
52
56
  OriginRecord,
53
57
  SyncAccept,
@@ -15,5 +15,7 @@
15
15
  "Authenticator": "Authenticator",
16
16
  "Retry": "Retry",
17
17
  "No user data source plugin installed": "No user data source plugin installed",
18
- "View documentation": "View documentation"
18
+ "View documentation": "View documentation",
19
+ "The synchronization has started. You can click on 'Tasks' to view the synchronization status.": "The synchronization has started. You can click on 'Tasks' to view the synchronization status.",
20
+ "The sync source API call failed. Please check the logs to troubleshoot the issue.": "The sync source API call failed. Please check the logs to troubleshoot the issue."
19
21
  }
@@ -18,5 +18,7 @@
18
18
  "default": "默认",
19
19
  "Retry": "重试",
20
20
  "No user data source plugin installed": "未安装同步数据源",
21
- "View documentation": "查看文档"
21
+ "View documentation": "查看文档",
22
+ "The synchronization has started. You can click on 'Tasks' to view the synchronization status.": "已开始同步,可点击「任务」查看同步任务状态",
23
+ "The sync source API call failed. Please check the logs to troubleshoot the issue.": "同步源 API 调用失败,请查看日志排查问题。"
22
24
  }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ export declare class ExternalAPIError extends Error {
10
+ code: number;
11
+ constructor(message: string);
12
+ }
13
+ export declare class ErrorCodes {
14
+ static SUCCESS: number;
15
+ static UNAUTHORIZED: number;
16
+ static EXTERNAL_API_ERROR: number;
17
+ static messages: {
18
+ [x: number]: string;
19
+ };
20
+ static getErrorMessage(code: any): string;
21
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var error_exports = {};
28
+ __export(error_exports, {
29
+ ErrorCodes: () => ErrorCodes,
30
+ ExternalAPIError: () => ExternalAPIError
31
+ });
32
+ module.exports = __toCommonJS(error_exports);
33
+ class ExternalAPIError extends Error {
34
+ code;
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = "ExternalAPIError";
38
+ this.code = ErrorCodes.EXTERNAL_API_ERROR;
39
+ }
40
+ }
41
+ class ErrorCodes {
42
+ static SUCCESS = 0;
43
+ static UNAUTHORIZED = 401;
44
+ static EXTERNAL_API_ERROR = 510;
45
+ static messages = {
46
+ [ErrorCodes.SUCCESS]: "Success",
47
+ [ErrorCodes.UNAUTHORIZED]: "Unauthorized",
48
+ [ErrorCodes.EXTERNAL_API_ERROR]: "External API Error"
49
+ };
50
+ static getErrorMessage(code) {
51
+ return this.messages[code] || "Unknown Error";
52
+ }
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ ErrorCodes,
57
+ ExternalAPIError
58
+ });
@@ -7,5 +7,6 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  export { SyncSource } from './sync-source';
10
+ export { ExternalAPIError, ErrorCodes } from './error';
10
11
  export * from './user-data-resource-manager';
11
12
  export { default } from './plugin';
@@ -37,15 +37,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
38
  var server_exports = {};
39
39
  __export(server_exports, {
40
+ ErrorCodes: () => import_error.ErrorCodes,
41
+ ExternalAPIError: () => import_error.ExternalAPIError,
40
42
  SyncSource: () => import_sync_source.SyncSource,
41
43
  default: () => import_plugin.default
42
44
  });
43
45
  module.exports = __toCommonJS(server_exports);
44
46
  var import_sync_source = require("./sync-source");
47
+ var import_error = require("./error");
45
48
  __reExport(server_exports, require("./user-data-resource-manager"), module.exports);
46
49
  var import_plugin = __toESM(require("./plugin"));
47
50
  // Annotate the CommonJS export names for ESM import in node:
48
51
  0 && (module.exports = {
52
+ ErrorCodes,
53
+ ExternalAPIError,
49
54
  SyncSource,
50
55
  ...require("./user-data-resource-manager")
51
56
  });
@@ -29,6 +29,7 @@ export type FormatDepartment = {
29
29
  export type FormatUserDepartment = {
30
30
  uid: string;
31
31
  isOwner?: boolean;
32
+ isMain?: boolean;
32
33
  };
33
34
  export type UserDataRecord = FormatUser | FormatDepartment;
34
35
  export type SyncDataType = 'user' | 'department';
@@ -29,6 +29,7 @@ __export(user_data_sync_service_exports, {
29
29
  UserDataSyncService: () => UserDataSyncService
30
30
  });
31
31
  module.exports = __toCommonJS(user_data_sync_service_exports);
32
+ var import_error = require("./error");
32
33
  class UserDataSyncService {
33
34
  resourceManager;
34
35
  sourceManager;
@@ -115,7 +116,11 @@ class UserDataSyncService {
115
116
  `sync task of source: ${source.instance.name} sourceType: ${source.instance.sourceType} error: ${err.message}`,
116
117
  { method: "runSync", err: err.stack, cause: err.cause }
117
118
  );
118
- await source.endTask({ taskId: task.id, success: false, message: err.message });
119
+ let message = err.message;
120
+ if (err instanceof import_error.ExternalAPIError) {
121
+ message = "The sync source API call failed. Please check the logs to troubleshoot the issue.";
122
+ }
123
+ await source.endTask({ taskId: task.id, success: false, message });
119
124
  }
120
125
  }
121
126
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "用户数据同步",
5
5
  "description": "Provide user data source management and user data synchronization interface. The data source can be DingTalk, WeCom, etc., and can be expanded.",
6
6
  "description.zh-CN": "提供用户数据源管理,用户数据同步接口,数据源可为钉钉、企业微信等,可扩展。",
7
- "version": "1.4.0-alpha.20240911231734",
7
+ "version": "1.4.0-alpha.20240914084300",
8
8
  "main": "dist/server/index.js",
9
9
  "peerDependencies": {
10
10
  "@nocobase/client": "1.x",
@@ -14,5 +14,5 @@
14
14
  "keywords": [
15
15
  "Users & permissions"
16
16
  ],
17
- "gitHead": "93db249b4151b72c654daeaff6dd81da26544122"
17
+ "gitHead": "9134514363875955f57ad07a311bb84783fc3399"
18
18
  }