@nocobase/plugin-user-data-sync 1.4.0-alpha.20240826214041
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/LICENSE.txt +121 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/Options.d.ts +12 -0
- package/dist/client/UserDataSyncSource.d.ts +10 -0
- package/dist/client/index.d.ts +21 -0
- package/dist/client/index.js +10 -0
- package/dist/client/locale/index.d.ts +10 -0
- package/dist/client/schemas/user-data-sync-sources.d.ts +155 -0
- package/dist/client/sourceType.d.ts +24 -0
- package/dist/externalVersion.js +24 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +56 -0
- package/dist/locale/en-US.json +19 -0
- package/dist/locale/zh-CN.json +22 -0
- package/dist/server/actions/user-data.d.ts +16 -0
- package/dist/server/actions/user-data.js +64 -0
- package/dist/server/collections/user-data-sync-records-resources.d.ts +10 -0
- package/dist/server/collections/user-data-sync-records-resources.js +54 -0
- package/dist/server/collections/user-data-sync-records.d.ts +10 -0
- package/dist/server/collections/user-data-sync-records.js +85 -0
- package/dist/server/collections/user-data-sync-sources.d.ts +10 -0
- package/dist/server/collections/user-data-sync-sources.js +109 -0
- package/dist/server/collections/user-data-sync-tasks.d.ts +10 -0
- package/dist/server/collections/user-data-sync-tasks.js +131 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.js +51 -0
- package/dist/server/models/sync-source.d.ts +15 -0
- package/dist/server/models/sync-source.js +38 -0
- package/dist/server/plugin.d.ts +27 -0
- package/dist/server/plugin.js +100 -0
- package/dist/server/sync-source-manager.d.ts +28 -0
- package/dist/server/sync-source-manager.js +71 -0
- package/dist/server/sync-source.d.ts +42 -0
- package/dist/server/sync-source.js +107 -0
- package/dist/server/user-data-resource-manager.d.ts +103 -0
- package/dist/server/user-data-resource-manager.js +214 -0
- package/dist/server/user-data-sync-service.d.ts +23 -0
- package/dist/server/user-data-sync-service.js +125 -0
- package/dist/swagger/index.d.ts +116 -0
- package/dist/swagger/index.js +138 -0
- package/package.json +18 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,125 @@
|
|
|
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 user_data_sync_service_exports = {};
|
|
28
|
+
__export(user_data_sync_service_exports, {
|
|
29
|
+
UserDataSyncService: () => UserDataSyncService
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(user_data_sync_service_exports);
|
|
32
|
+
class UserDataSyncService {
|
|
33
|
+
resourceManager;
|
|
34
|
+
sourceManager;
|
|
35
|
+
logger;
|
|
36
|
+
constructor(resourceManager, sourceManager, logger) {
|
|
37
|
+
this.resourceManager = resourceManager;
|
|
38
|
+
this.sourceManager = sourceManager;
|
|
39
|
+
this.logger = logger;
|
|
40
|
+
}
|
|
41
|
+
async pull(sourceName, ctx) {
|
|
42
|
+
const source = await this.sourceManager.getByName(sourceName, ctx);
|
|
43
|
+
const task = await source.newTask();
|
|
44
|
+
await source.beginTask(task.id);
|
|
45
|
+
ctx.log.info("begin sync task of source", { source: sourceName, sourceType: source.instance.sourceType });
|
|
46
|
+
this.runSync(source, task, ctx);
|
|
47
|
+
}
|
|
48
|
+
async push(data) {
|
|
49
|
+
const { dataType, records } = data;
|
|
50
|
+
if (dataType === void 0) {
|
|
51
|
+
throw new Error("dataType for user data synchronize is required");
|
|
52
|
+
}
|
|
53
|
+
if (dataType !== "user" && dataType !== "department") {
|
|
54
|
+
throw new Error("dataType must be user or department");
|
|
55
|
+
}
|
|
56
|
+
if (records === void 0) {
|
|
57
|
+
throw new Error("records for user data synchronize is required");
|
|
58
|
+
}
|
|
59
|
+
if (records.length === 0) {
|
|
60
|
+
throw new Error("records must have at least one piece of data");
|
|
61
|
+
}
|
|
62
|
+
const userData = {
|
|
63
|
+
dataType: data.dataType,
|
|
64
|
+
matchKey: data.matchKey,
|
|
65
|
+
records: data.records,
|
|
66
|
+
sourceName: data.sourceName ? data.sourceName : "api"
|
|
67
|
+
};
|
|
68
|
+
this.logger.info({
|
|
69
|
+
source: data.sourceName ? data.sourceName : "api",
|
|
70
|
+
sourceType: "api",
|
|
71
|
+
data
|
|
72
|
+
});
|
|
73
|
+
return await this.resourceManager.updateOrCreate(userData);
|
|
74
|
+
}
|
|
75
|
+
async retry(sourceId, taskId, ctx) {
|
|
76
|
+
const source = await this.sourceManager.getById(sourceId, ctx);
|
|
77
|
+
const task = await source.retryTask(taskId);
|
|
78
|
+
ctx.log.info("retry sync task of source", {
|
|
79
|
+
source: source.instance.name,
|
|
80
|
+
sourceType: source.instance.name,
|
|
81
|
+
task: task.id
|
|
82
|
+
});
|
|
83
|
+
this.runSync(source, task, ctx);
|
|
84
|
+
}
|
|
85
|
+
async runSync(source, task, ctx) {
|
|
86
|
+
const currentTimeMillis = (/* @__PURE__ */ new Date()).getTime();
|
|
87
|
+
try {
|
|
88
|
+
ctx.log.info("begin pull data of source", {
|
|
89
|
+
source: source.instance.name,
|
|
90
|
+
sourceType: source.instance.sourceType
|
|
91
|
+
});
|
|
92
|
+
const data = await source.pull();
|
|
93
|
+
this.logger.info({
|
|
94
|
+
source: source.instance.name,
|
|
95
|
+
sourceType: source.instance.sourceType,
|
|
96
|
+
batch: task.batch,
|
|
97
|
+
data
|
|
98
|
+
});
|
|
99
|
+
ctx.log.info("end pull data of source", { source: source.instance.name, sourceType: source.instance.sourceType });
|
|
100
|
+
ctx.log.info("begin update data of source", {
|
|
101
|
+
source: source.instance.name,
|
|
102
|
+
sourceType: source.instance.sourceType
|
|
103
|
+
});
|
|
104
|
+
for (const item of data) {
|
|
105
|
+
await this.resourceManager.updateOrCreate(item);
|
|
106
|
+
}
|
|
107
|
+
ctx.log.info("end update data of source", {
|
|
108
|
+
source: source.instance.name,
|
|
109
|
+
sourceType: source.instance.sourceType
|
|
110
|
+
});
|
|
111
|
+
const costTime = (/* @__PURE__ */ new Date()).getTime() - currentTimeMillis;
|
|
112
|
+
await source.endTask({ taskId: task.id, success: true, cost: costTime });
|
|
113
|
+
} catch (err) {
|
|
114
|
+
ctx.log.error(
|
|
115
|
+
`sync task of source: ${source.instance.name} sourceType: ${source.instance.sourceType} error: ${err.message}`,
|
|
116
|
+
{ method: "runSync", err: err.stack, cause: err.cause }
|
|
117
|
+
);
|
|
118
|
+
await source.endTask({ taskId: task.id, success: false, message: err.message });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
124
|
+
UserDataSyncService
|
|
125
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
declare const _default: {
|
|
10
|
+
info: {
|
|
11
|
+
title: string;
|
|
12
|
+
};
|
|
13
|
+
paths: {
|
|
14
|
+
'/userData:push': {
|
|
15
|
+
post: {
|
|
16
|
+
description: string;
|
|
17
|
+
tags: string[];
|
|
18
|
+
security: any[];
|
|
19
|
+
requestBody: {
|
|
20
|
+
content: {
|
|
21
|
+
'application/json': {
|
|
22
|
+
schema: {
|
|
23
|
+
type: string;
|
|
24
|
+
items: {
|
|
25
|
+
$ref: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
responses: {
|
|
32
|
+
200: {
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
components: {
|
|
40
|
+
schemas: {
|
|
41
|
+
userData: {
|
|
42
|
+
type: string;
|
|
43
|
+
description: string;
|
|
44
|
+
properties: {
|
|
45
|
+
dataType: {
|
|
46
|
+
type: string;
|
|
47
|
+
description: string;
|
|
48
|
+
};
|
|
49
|
+
uniqueKey: {
|
|
50
|
+
type: string;
|
|
51
|
+
description: string;
|
|
52
|
+
};
|
|
53
|
+
records: {
|
|
54
|
+
type: string;
|
|
55
|
+
description: string;
|
|
56
|
+
items: {
|
|
57
|
+
type: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
sourceName: {
|
|
61
|
+
type: string;
|
|
62
|
+
description: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
user: {
|
|
67
|
+
type: string;
|
|
68
|
+
description: string;
|
|
69
|
+
properties: {
|
|
70
|
+
id: {
|
|
71
|
+
type: string;
|
|
72
|
+
description: string;
|
|
73
|
+
};
|
|
74
|
+
nickname: {
|
|
75
|
+
type: string;
|
|
76
|
+
description: string;
|
|
77
|
+
};
|
|
78
|
+
email: {
|
|
79
|
+
type: string;
|
|
80
|
+
description: string;
|
|
81
|
+
};
|
|
82
|
+
phone: {
|
|
83
|
+
type: string;
|
|
84
|
+
description: string;
|
|
85
|
+
};
|
|
86
|
+
departments: {
|
|
87
|
+
type: string;
|
|
88
|
+
description: string;
|
|
89
|
+
items: {
|
|
90
|
+
type: string;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
department: {
|
|
96
|
+
type: string;
|
|
97
|
+
description: string;
|
|
98
|
+
properties: {
|
|
99
|
+
id: {
|
|
100
|
+
type: string;
|
|
101
|
+
description: string;
|
|
102
|
+
};
|
|
103
|
+
name: {
|
|
104
|
+
type: string;
|
|
105
|
+
description: string;
|
|
106
|
+
};
|
|
107
|
+
parentId: {
|
|
108
|
+
type: string;
|
|
109
|
+
description: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
export default _default;
|
|
@@ -0,0 +1,138 @@
|
|
|
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 swagger_exports = {};
|
|
28
|
+
__export(swagger_exports, {
|
|
29
|
+
default: () => swagger_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(swagger_exports);
|
|
32
|
+
var swagger_default = {
|
|
33
|
+
info: {
|
|
34
|
+
title: "NocoBase API - User data synchronization plugin"
|
|
35
|
+
},
|
|
36
|
+
paths: {
|
|
37
|
+
"/userData:push": {
|
|
38
|
+
post: {
|
|
39
|
+
description: "Push user data",
|
|
40
|
+
tags: ["Push"],
|
|
41
|
+
security: [],
|
|
42
|
+
requestBody: {
|
|
43
|
+
content: {
|
|
44
|
+
"application/json": {
|
|
45
|
+
schema: {
|
|
46
|
+
type: "array",
|
|
47
|
+
items: {
|
|
48
|
+
$ref: "#/components/schemas/userData"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
responses: {
|
|
55
|
+
200: {
|
|
56
|
+
description: "ok"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
components: {
|
|
63
|
+
schemas: {
|
|
64
|
+
userData: {
|
|
65
|
+
type: "object",
|
|
66
|
+
description: "\u7528\u6237\u6570\u636E",
|
|
67
|
+
properties: {
|
|
68
|
+
dataType: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "\u6570\u636E\u7C7B\u578B, \u76EE\u524D\u53EF\u9009\u503C\u4E3A: user, department"
|
|
71
|
+
},
|
|
72
|
+
uniqueKey: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "\u552F\u4E00\u952E"
|
|
75
|
+
},
|
|
76
|
+
records: {
|
|
77
|
+
type: "array",
|
|
78
|
+
description: "\u6570\u636E, \u82E5 dataType \u4E3A user, \u5219\u4E3A\u7528\u6237\u6570\u636E\u5B57\u6BB5\u89C1schemas/user, \u82E5 dataType \u4E3A department, \u5219\u4E3A\u90E8\u95E8\u6570\u636E\u5B57\u6BB5\u89C1schemas/department",
|
|
79
|
+
items: {
|
|
80
|
+
type: "object"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
sourceName: {
|
|
84
|
+
type: "string",
|
|
85
|
+
description: "\u6570\u636E\u6E90\u540D\u79F0"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
user: {
|
|
90
|
+
type: "object",
|
|
91
|
+
description: "\u7528\u6237",
|
|
92
|
+
properties: {
|
|
93
|
+
id: {
|
|
94
|
+
type: "integer",
|
|
95
|
+
description: "ID"
|
|
96
|
+
},
|
|
97
|
+
nickname: {
|
|
98
|
+
type: "string",
|
|
99
|
+
description: "\u6635\u79F0"
|
|
100
|
+
},
|
|
101
|
+
email: {
|
|
102
|
+
type: "string",
|
|
103
|
+
description: "\u90AE\u7BB1"
|
|
104
|
+
},
|
|
105
|
+
phone: {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: "\u624B\u673A\u53F7"
|
|
108
|
+
},
|
|
109
|
+
departments: {
|
|
110
|
+
type: "array",
|
|
111
|
+
description: "\u6240\u5C5E\u90E8\u95E8, \u90E8\u95E8ID \u6570\u7EC4",
|
|
112
|
+
items: {
|
|
113
|
+
type: "string"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
department: {
|
|
119
|
+
type: "object",
|
|
120
|
+
description: "\u90E8\u95E8",
|
|
121
|
+
properties: {
|
|
122
|
+
id: {
|
|
123
|
+
type: "string",
|
|
124
|
+
description: "ID"
|
|
125
|
+
},
|
|
126
|
+
name: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "\u540D\u79F0"
|
|
129
|
+
},
|
|
130
|
+
parentId: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "\u7236\u7EA7\u90E8\u95E8ID"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-user-data-sync",
|
|
3
|
+
"displayName": "User data synchronization",
|
|
4
|
+
"displayName.zh-CN": "用户数据同步",
|
|
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
|
+
"description.zh-CN": "提供用户数据源管理,用户数据同步接口,数据源可为钉钉、企业微信等,可扩展。",
|
|
7
|
+
"version": "1.4.0-alpha.20240826214041",
|
|
8
|
+
"main": "dist/server/index.js",
|
|
9
|
+
"peerDependencies": {
|
|
10
|
+
"@nocobase/client": "1.x",
|
|
11
|
+
"@nocobase/server": "1.x",
|
|
12
|
+
"@nocobase/test": "1.x"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"Users & permissions"
|
|
16
|
+
],
|
|
17
|
+
"gitHead": "05146e0a96cda923d2c95a92b0fe1bc53390af7a"
|
|
18
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|