@nocobase/plugin-verification 1.7.0-beta.9 → 1.7.1
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/client/83b24f85ae99a175.js +10 -0
- package/dist/client/937c9eccebc38607.js +10 -0
- package/dist/client/VerificationMenu.d.ts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/otp-verification/VerificationCode.d.ts +1 -1
- package/dist/client/schemas/{verificators.d.ts → verifiers.d.ts} +2 -2
- package/dist/client/verification-manager/index.d.ts +2 -2
- package/dist/client/{verificators/VerificatorSelect.d.ts → verifiers/VerifierSelect.d.ts} +1 -1
- package/dist/client/{verificators/Verificators.d.ts → verifiers/Verifiers.d.ts} +1 -1
- package/dist/collections/verifiers.d.ts +50 -0
- package/dist/collections/verifiers.js +70 -0
- package/dist/externalVersion.js +6 -5
- package/dist/locale/en-US.json +6 -5
- package/dist/locale/zh-CN.json +6 -5
- package/dist/node_modules/@alicloud/dysmsapi20170525/dist/client.js +2 -2
- package/dist/node_modules/@alicloud/dysmsapi20170525/package.json +1 -1
- package/dist/node_modules/@alicloud/openapi-client/dist/client.js +2 -2
- package/dist/node_modules/@alicloud/openapi-client/package.json +1 -1
- package/dist/node_modules/@alicloud/tea-util/dist/client.js +1 -1
- package/dist/node_modules/@alicloud/tea-util/package.json +1 -1
- package/dist/node_modules/tencentcloud-sdk-nodejs/package.json +1 -1
- package/dist/node_modules/tencentcloud-sdk-nodejs/tencentcloud/index.js +2 -2
- package/dist/server/Plugin.d.ts +3 -0
- package/dist/server/Plugin.js +25 -13
- package/dist/server/actions/{verificators.js → verifiers.js} +38 -38
- package/dist/server/collections/otp-records.js +2 -2
- package/dist/server/collections/users-verificators.d.ts +0 -4
- package/dist/server/collections/users-verificators.js +1 -1
- package/dist/server/collections/users-verifiers.d.ts +14 -0
- package/dist/server/collections/users-verifiers.js +58 -0
- package/dist/server/collections/verificators.js +1 -1
- package/dist/server/collections/verifiers.d.ts +10 -0
- package/dist/server/collections/verifiers.js +47 -0
- package/dist/server/migrations/20250111192640-providers2verificators.js +16 -2
- package/dist/server/migrations/20250507220644-fix-verifier-typo.d.ts +14 -0
- package/dist/server/migrations/20250507220644-fix-verifier-typo.js +86 -0
- package/dist/server/otp-verification/index.d.ts +1 -0
- package/dist/server/otp-verification/index.js +62 -4
- package/dist/server/otp-verification/sms/resource/sms-otp.js +11 -11
- package/dist/server/verification-manager.d.ts +5 -5
- package/dist/server/verification-manager.js +29 -29
- package/dist/server/verification.d.ts +5 -5
- package/dist/server/verification.js +5 -5
- package/package.json +2 -2
- package/dist/client/cfedbdcfbe65d5f6.js +0 -10
- package/dist/client/d0b398212e5aa575.js +0 -10
- /package/dist/client/{verificators → verifiers}/verification-types.d.ts +0 -0
- /package/dist/server/actions/{verificators.d.ts → verifiers.d.ts} +0 -0
|
@@ -42,16 +42,40 @@ module.exports = __toCommonJS(otp_verification_exports);
|
|
|
42
42
|
var import_verification = require("../verification");
|
|
43
43
|
var import_constants = require("../constants");
|
|
44
44
|
var import_package = __toESM(require("../../../package.json"));
|
|
45
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
45
46
|
class OTPVerification extends import_verification.Verification {
|
|
46
47
|
expiresIn = 120;
|
|
48
|
+
maxVerifyAttempts = 5;
|
|
47
49
|
async verify({ resource, action, boundInfo, verifyParams }) {
|
|
48
50
|
const { uuid: receiver } = boundInfo;
|
|
49
51
|
const code = verifyParams.code;
|
|
50
52
|
if (!code) {
|
|
51
53
|
return this.ctx.throw(400, "Verification code is invalid");
|
|
52
54
|
}
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
+
const plugin = this.ctx.app.pm.get("verification");
|
|
56
|
+
const counter = plugin.smsOTPCounter;
|
|
57
|
+
const key = `${resource}:${action}:${receiver}`;
|
|
58
|
+
let attempts = 0;
|
|
59
|
+
try {
|
|
60
|
+
attempts = await counter.get(key);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
this.ctx.logger.error(e.message, {
|
|
63
|
+
module: "verification",
|
|
64
|
+
submodule: "sms-otp",
|
|
65
|
+
method: "verify",
|
|
66
|
+
receiver,
|
|
67
|
+
action: `${resource}:${action}`
|
|
68
|
+
});
|
|
69
|
+
this.ctx.throw(500, "Internal Server Error");
|
|
70
|
+
}
|
|
71
|
+
if (attempts > this.maxVerifyAttempts) {
|
|
72
|
+
this.ctx.throw(
|
|
73
|
+
429,
|
|
74
|
+
this.ctx.t("Too many failed attempts. Please request a new verification code.", { ns: import_package.default.name })
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const repo = this.ctx.db.getRepository("otpRecords");
|
|
78
|
+
const item = await repo.findOne({
|
|
55
79
|
filter: {
|
|
56
80
|
receiver,
|
|
57
81
|
action: `${resource}:${action}`,
|
|
@@ -60,21 +84,55 @@ class OTPVerification extends import_verification.Verification {
|
|
|
60
84
|
$dateAfter: /* @__PURE__ */ new Date()
|
|
61
85
|
},
|
|
62
86
|
status: import_constants.CODE_STATUS_UNUSED,
|
|
63
|
-
|
|
87
|
+
verifierName: this.verifier.name
|
|
64
88
|
}
|
|
65
89
|
});
|
|
66
90
|
if (!item) {
|
|
91
|
+
let attempts2 = 0;
|
|
92
|
+
try {
|
|
93
|
+
let ttl = this.expiresIn * 1e3;
|
|
94
|
+
const record = await repo.findOne({
|
|
95
|
+
filter: {
|
|
96
|
+
action: `${resource}:${action}`,
|
|
97
|
+
receiver,
|
|
98
|
+
status: import_constants.CODE_STATUS_UNUSED,
|
|
99
|
+
expiresAt: {
|
|
100
|
+
$dateAfter: /* @__PURE__ */ new Date()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (record) {
|
|
105
|
+
ttl = (0, import_dayjs.default)(record.get("expiresAt")).diff((0, import_dayjs.default)());
|
|
106
|
+
}
|
|
107
|
+
attempts2 = await counter.incr(key, ttl);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
this.ctx.logger.error(e.message, {
|
|
110
|
+
module: "verification",
|
|
111
|
+
submodule: "totp-authenticator",
|
|
112
|
+
method: "verify",
|
|
113
|
+
receiver,
|
|
114
|
+
action: `${resource}:${action}`
|
|
115
|
+
});
|
|
116
|
+
this.ctx.throw(500, "Internal Server Error");
|
|
117
|
+
}
|
|
118
|
+
if (attempts2 > this.maxVerifyAttempts) {
|
|
119
|
+
this.ctx.throw(
|
|
120
|
+
429,
|
|
121
|
+
this.ctx.t("Too many failed attempts. Please request a new verification code", { ns: import_package.default.name })
|
|
122
|
+
);
|
|
123
|
+
}
|
|
67
124
|
return this.ctx.throw(400, {
|
|
68
125
|
code: "InvalidVerificationCode",
|
|
69
126
|
message: this.ctx.t("Verification code is invalid", { ns: import_package.default.name })
|
|
70
127
|
});
|
|
71
128
|
}
|
|
129
|
+
await counter.reset(key);
|
|
72
130
|
return { codeInfo: item };
|
|
73
131
|
}
|
|
74
132
|
async bind(userId, resource, action) {
|
|
75
133
|
const { uuid, code } = this.ctx.action.params.values || {};
|
|
76
134
|
await this.verify({
|
|
77
|
-
resource: resource || "
|
|
135
|
+
resource: resource || "verifiers",
|
|
78
136
|
action: action || "bind",
|
|
79
137
|
boundInfo: { uuid },
|
|
80
138
|
verifyParams: { code }
|
|
@@ -47,29 +47,29 @@ var import__2 = require("../../..");
|
|
|
47
47
|
const asyncRandomInt = (0, import_util.promisify)(import_crypto.randomInt);
|
|
48
48
|
async function create(ctx, next) {
|
|
49
49
|
var _a;
|
|
50
|
-
const { action: actionName,
|
|
50
|
+
const { action: actionName, verifier: verifierName } = ((_a = ctx.action.params) == null ? void 0 : _a.values) || {};
|
|
51
51
|
const plugin = ctx.app.getPlugin("verification");
|
|
52
52
|
const verificationManager = plugin.verificationManager;
|
|
53
53
|
const action = verificationManager.actions.get(actionName);
|
|
54
54
|
if (!action) {
|
|
55
55
|
return ctx.throw(400, "Invalid action type");
|
|
56
56
|
}
|
|
57
|
-
if (!
|
|
58
|
-
return ctx.throw(400, "Invalid
|
|
57
|
+
if (!verifierName) {
|
|
58
|
+
return ctx.throw(400, "Invalid verifier");
|
|
59
59
|
}
|
|
60
|
-
const
|
|
60
|
+
const verifier = await ctx.db.getRepository("verifiers").findOne({
|
|
61
61
|
filter: {
|
|
62
|
-
name:
|
|
62
|
+
name: verifierName
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
|
-
if (!
|
|
66
|
-
return ctx.throw(400, "Invalid
|
|
65
|
+
if (!verifier) {
|
|
66
|
+
return ctx.throw(400, "Invalid verifier");
|
|
67
67
|
}
|
|
68
|
-
const Verification = verificationManager.getVerification(
|
|
68
|
+
const Verification = verificationManager.getVerification(verifier.verificationType);
|
|
69
69
|
const verification = new Verification({
|
|
70
70
|
ctx,
|
|
71
|
-
|
|
72
|
-
options:
|
|
71
|
+
verifier,
|
|
72
|
+
options: verifier.options
|
|
73
73
|
});
|
|
74
74
|
const provider = await verification.getProvider();
|
|
75
75
|
if (!provider) {
|
|
@@ -123,7 +123,7 @@ async function create(ctx, next) {
|
|
|
123
123
|
code,
|
|
124
124
|
expiresAt: Date.now() + (verification.expiresIn ?? 60) * 1e3,
|
|
125
125
|
status: import_constants.CODE_STATUS_UNUSED,
|
|
126
|
-
|
|
126
|
+
verifierName
|
|
127
127
|
}
|
|
128
128
|
});
|
|
129
129
|
ctx.body = {
|
|
@@ -29,7 +29,7 @@ export interface SceneOptions {
|
|
|
29
29
|
actions: {
|
|
30
30
|
[key: string]: ActionOptions;
|
|
31
31
|
};
|
|
32
|
-
|
|
32
|
+
getVerifiers?(ctx: Context): Promise<string[]>;
|
|
33
33
|
}
|
|
34
34
|
export declare class VerificationManager {
|
|
35
35
|
db: Database;
|
|
@@ -52,16 +52,16 @@ export declare class VerificationManager {
|
|
|
52
52
|
registerScene(scene: string, options: SceneOptions): void;
|
|
53
53
|
getVerificationTypesByScene(scene: string): any[];
|
|
54
54
|
getVerification(type: string): VerificationExtend<Verification>;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
getBoundRecord(userId: number,
|
|
55
|
+
getVerifier(verifierName: string): Promise<any>;
|
|
56
|
+
getVerifiers(verifierNames: string[]): Promise<any>;
|
|
57
|
+
getBoundRecord(userId: number, verifier: string): Promise<any>;
|
|
58
58
|
getAndValidateBoundInfo(ctx: Context, action: ActionOptions, verification: Verification): Promise<{
|
|
59
59
|
boundInfo: {
|
|
60
60
|
uuid: string;
|
|
61
61
|
};
|
|
62
62
|
userId: number;
|
|
63
63
|
}>;
|
|
64
|
-
private
|
|
64
|
+
private validateAndGetVerifier;
|
|
65
65
|
verify(ctx: Context, next: Next): Promise<void>;
|
|
66
66
|
middleware(): (ctx: Context, next: Next) => Promise<any>;
|
|
67
67
|
}
|
|
@@ -81,25 +81,25 @@ class VerificationManager {
|
|
|
81
81
|
}
|
|
82
82
|
return verificationType.verification;
|
|
83
83
|
}
|
|
84
|
-
async
|
|
85
|
-
return await this.db.getRepository("
|
|
84
|
+
async getVerifier(verifierName) {
|
|
85
|
+
return await this.db.getRepository("verifiers").findOne({
|
|
86
86
|
filter: {
|
|
87
|
-
name:
|
|
87
|
+
name: verifierName
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
|
-
async
|
|
92
|
-
return await this.db.getRepository("
|
|
91
|
+
async getVerifiers(verifierNames) {
|
|
92
|
+
return await this.db.getRepository("verifiers").find({
|
|
93
93
|
filter: {
|
|
94
|
-
name:
|
|
94
|
+
name: verifierNames
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
|
-
async getBoundRecord(userId,
|
|
99
|
-
return await this.db.getRepository("
|
|
98
|
+
async getBoundRecord(userId, verifier) {
|
|
99
|
+
return await this.db.getRepository("usersVerifiers").findOne({
|
|
100
100
|
filter: {
|
|
101
101
|
userId,
|
|
102
|
-
|
|
102
|
+
verifier
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
}
|
|
@@ -123,41 +123,41 @@ class VerificationManager {
|
|
|
123
123
|
await verification.validateBoundInfo(boundInfo);
|
|
124
124
|
return { boundInfo, userId };
|
|
125
125
|
}
|
|
126
|
-
async
|
|
127
|
-
let
|
|
128
|
-
if (!
|
|
126
|
+
async validateAndGetVerifier(ctx, scene, verifierName) {
|
|
127
|
+
let verifier;
|
|
128
|
+
if (!verifierName) {
|
|
129
129
|
return null;
|
|
130
130
|
}
|
|
131
131
|
if (scene) {
|
|
132
132
|
const sceneOptions = this.scenes.get(scene);
|
|
133
|
-
if (sceneOptions.
|
|
134
|
-
const
|
|
135
|
-
if (!
|
|
133
|
+
if (sceneOptions.getVerifiers) {
|
|
134
|
+
const verifiers = await sceneOptions.getVerifiers(ctx);
|
|
135
|
+
if (!verifiers.includes(verifierName)) {
|
|
136
136
|
return null;
|
|
137
137
|
}
|
|
138
|
-
|
|
139
|
-
if (!
|
|
138
|
+
verifier = await this.getVerifier(verifierName);
|
|
139
|
+
if (!verifier) {
|
|
140
140
|
return null;
|
|
141
141
|
}
|
|
142
142
|
} else {
|
|
143
143
|
const verificationTypes = this.getVerificationTypesByScene(scene);
|
|
144
|
-
const
|
|
144
|
+
const verifiers = await this.db.getRepository("verifiers").find({
|
|
145
145
|
filter: {
|
|
146
146
|
verificationType: verificationTypes.map((item) => item.type)
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
|
-
|
|
150
|
-
if (!
|
|
149
|
+
verifier = verifiers.find((item) => item.name === verifierName);
|
|
150
|
+
if (!verifier) {
|
|
151
151
|
return null;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
} else {
|
|
155
|
-
|
|
156
|
-
if (!
|
|
155
|
+
verifier = await this.getVerifier(verifierName);
|
|
156
|
+
if (!verifier) {
|
|
157
157
|
return null;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
return
|
|
160
|
+
return verifier;
|
|
161
161
|
}
|
|
162
162
|
// verify manually
|
|
163
163
|
async verify(ctx, next) {
|
|
@@ -168,10 +168,10 @@ class VerificationManager {
|
|
|
168
168
|
if (!action) {
|
|
169
169
|
ctx.throw(400, "Invalid action");
|
|
170
170
|
}
|
|
171
|
-
const {
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
174
|
-
ctx.throw(400, "Invalid
|
|
171
|
+
const { verifier: verifierName } = ctx.action.params.values || {};
|
|
172
|
+
const verifier = await this.validateAndGetVerifier(ctx, action.scene, verifierName);
|
|
173
|
+
if (!verifier) {
|
|
174
|
+
ctx.throw(400, "Invalid verifier");
|
|
175
175
|
}
|
|
176
176
|
const verifyParams = action.getVerifyParams ? await action.getVerifyParams(ctx) : ctx.action.params.values;
|
|
177
177
|
if (!verifyParams) {
|
|
@@ -179,8 +179,8 @@ class VerificationManager {
|
|
|
179
179
|
}
|
|
180
180
|
const plugin = ctx.app.pm.get("verification");
|
|
181
181
|
const verificationManager = plugin.verificationManager;
|
|
182
|
-
const Verification2 = verificationManager.getVerification(
|
|
183
|
-
const verification = new Verification2({ ctx,
|
|
182
|
+
const Verification2 = verificationManager.getVerification(verifier.verificationType);
|
|
183
|
+
const verification = new Verification2({ ctx, verifier, options: verifier.options });
|
|
184
184
|
const { boundInfo, userId } = await this.getAndValidateBoundInfo(ctx, action, verification);
|
|
185
185
|
try {
|
|
186
186
|
const verifyResult = await verification.verify({
|
|
@@ -32,12 +32,12 @@ export interface IVerification {
|
|
|
32
32
|
}>;
|
|
33
33
|
}
|
|
34
34
|
export declare abstract class Verification implements IVerification {
|
|
35
|
-
|
|
35
|
+
verifier: Model;
|
|
36
36
|
protected ctx: Context;
|
|
37
37
|
protected options: Record<string, any>;
|
|
38
|
-
constructor({ ctx,
|
|
38
|
+
constructor({ ctx, verifier, options }: {
|
|
39
39
|
ctx: any;
|
|
40
|
-
|
|
40
|
+
verifier: any;
|
|
41
41
|
options: any;
|
|
42
42
|
});
|
|
43
43
|
get throughRepo(): import("@nocobase/database").Repository<any, any>;
|
|
@@ -63,8 +63,8 @@ export declare abstract class Verification implements IVerification {
|
|
|
63
63
|
}>;
|
|
64
64
|
validateBoundInfo(boundInfo: any): Promise<boolean>;
|
|
65
65
|
}
|
|
66
|
-
export type VerificationExtend<T extends Verification> = new ({ ctx,
|
|
66
|
+
export type VerificationExtend<T extends Verification> = new ({ ctx, verifier, options }: {
|
|
67
67
|
ctx: any;
|
|
68
|
-
|
|
68
|
+
verifier: any;
|
|
69
69
|
options: any;
|
|
70
70
|
}) => T;
|
|
@@ -30,16 +30,16 @@ __export(verification_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(verification_exports);
|
|
32
32
|
class Verification {
|
|
33
|
-
|
|
33
|
+
verifier;
|
|
34
34
|
ctx;
|
|
35
35
|
options;
|
|
36
|
-
constructor({ ctx,
|
|
36
|
+
constructor({ ctx, verifier, options }) {
|
|
37
37
|
this.ctx = ctx;
|
|
38
|
-
this.
|
|
38
|
+
this.verifier = verifier;
|
|
39
39
|
this.options = options;
|
|
40
40
|
}
|
|
41
41
|
get throughRepo() {
|
|
42
|
-
return this.ctx.db.getRepository("
|
|
42
|
+
return this.ctx.db.getRepository("usersVerifiers");
|
|
43
43
|
}
|
|
44
44
|
async onActionComplete(options) {
|
|
45
45
|
}
|
|
@@ -49,7 +49,7 @@ class Verification {
|
|
|
49
49
|
async getBoundInfo(userId) {
|
|
50
50
|
return this.throughRepo.findOne({
|
|
51
51
|
filter: {
|
|
52
|
-
|
|
52
|
+
verifier: this.verifier.name,
|
|
53
53
|
userId
|
|
54
54
|
}
|
|
55
55
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "验证",
|
|
5
5
|
"description": "User identity verification management, including SMS, TOTP authenticator, with extensibility.",
|
|
6
6
|
"description.zh-CN": "用户身份验证管理,包含短信、TOTP 认证器等,可扩展。",
|
|
7
|
-
"version": "1.7.
|
|
7
|
+
"version": "1.7.1",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/verification",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@nocobase/test": "1.x",
|
|
32
32
|
"@nocobase/utils": "1.x"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "8324f0fcc37d68f1e37fbdad70dea1bdce81866c",
|
|
35
35
|
"keywords": [
|
|
36
36
|
"Authentication",
|
|
37
37
|
"Verification",
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
"use strict";(self.webpackChunk_nocobase_plugin_verification=self.webpackChunk_nocobase_plugin_verification||[]).push([["835"],{564:function(e,t,n){n.r(t),n.d(t,{VerificatorSelect:function(){return v}});var i=n(156),a=n.n(i),l=n(505),r=n(721),o=n(772),u=n(573),c=n(128),s=n(632),v=(0,l.connect)(function(e){var t=(0,u.SD)().t,n=e.scene,v=e.value,f=e.title,m=e.onChange,p=e.multiple;p=p?"multiple":void 0;var d=(0,o.useAPIClient)(),h=(0,o.useRequest)(function(){return d.resource("verificators").listByScene({scene:n}).then(function(e){var t;return null==e?void 0:null===(t=e.data)||void 0===t?void 0:t.data})}).data||{},g=h.verificators,b=void 0===g?[]:g,E=h.availableTypes,k=(0,i.useMemo)(function(){return null==b?void 0:b.map(function(e){return{label:e.title,value:e.name}})},[b]);return a().createElement(s.FormItem,{label:f||t("Verificators"),extra:a().createElement(a().Fragment,null,t("The following types of verificators are available:"),(void 0===E?[]:E).map(function(e){return l.Schema.compile(e.title,{t:t})}).join(", "),". ",t("Go to")," ",a().createElement(c.Link,{to:"/admin/settings/verification"},t("create verificators")))},a().createElement(r.Select,{allowClear:!0,options:k,value:v,mode:p,onChange:m}))},(0,l.mapReadPretty)(function(){var e,t=(0,l.useField)();return(null===(e=t.value)||void 0===e?void 0:e.length)?a().createElement(o.EllipsisWithTooltip,{ellipsis:!0},t.value.map(function(e){return a().createElement(r.Tag,{key:e.name},e.title)})):null}))}}]);
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
"use strict";(self.webpackChunk_nocobase_plugin_verification=self.webpackChunk_nocobase_plugin_verification||[]).push([["995"],{252:function(e,t,n){n.r(t),n.d(t,{Verificators:function(){return E},useAdminSettingsForm:function(){return T},Settings:function(){return k}});var o=n("156"),r=n.n(o),i=n("772"),c={type:"void",properties:{drawer:{type:"void",title:'{{ t("Add new") }}',"x-component":"Action.Drawer","x-decorator":"FormV2","x-use-decorator-props":"useCreateFormProps",properties:{name:{type:"string","x-decorator":"FormItem",title:'{{ t("UID") }}',"x-component":"Input","x-validator":function(e){return/^[a-zA-Z0-9_-]+$/.test(e)?"":"a-z, A-Z, 0-9, _, -"}},title:{type:"string","x-decorator":"FormItem",title:'{{ t("Title") }}',"x-component":"Input"},description:{"x-decorator":"FormItem",type:"string",title:'{{ t("Description") }}',"x-component":"Input.TextArea"},options:{type:"object","x-component":"Settings"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-component-props":{type:"primary"},"x-use-component-props":"useCreateActionProps"}}}}}}},s={type:"void",properties:{card:{type:"void","x-component":"CardItem","x-component-props":{heightMode:"fullHeight"},"x-decorator":"TableBlockProvider","x-decorator-props":{collection:"verificators",action:"list"},properties:{actions:{type:"void","x-component":"ActionBar","x-component-props":{style:{marginBottom:20}},properties:{refresh:{title:"{{t('Refresh')}}","x-component":"Action","x-use-component-props":"useRefreshActionProps","x-component-props":{icon:"ReloadOutlined"}},bulkDelete:{title:"{{t('Delete')}}","x-action":"destroy","x-component":"Action","x-use-component-props":"useBulkDestroyActionProps","x-component-props":{icon:"DeleteOutlined",confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"}}},add:{type:"void","x-component":"AddNew",title:"{{t('Add new')}}","x-align":"right"}}},table:{type:"array","x-component":"TableV2","x-use-component-props":"useTableBlockProps","x-component-props":{rowKey:"name",rowSelection:{type:"checkbox"}},properties:{column1:{type:"void",title:'{{ t("UID") }}',"x-component":"TableV2.Column",properties:{name:{type:"string","x-component":"Input","x-read-pretty":!0}}},column2:{type:"void",title:'{{ t("Title") }}',"x-component":"TableV2.Column",properties:{title:{type:"string","x-component":"Input","x-read-pretty":!0}}},column3:{type:"void",title:'{{ t("Verification type") }}',"x-component":"TableV2.Column",properties:{verificationType:{type:"string","x-component":"Select","x-read-pretty":!0,enum:"{{ types }}"}}},column4:{type:"void",title:'{{ t("Description") }}',"x-component":"TableV2.Column",properties:{description:{type:"string","x-component":"Input.TextArea","x-component-props":{ellipsis:!0},"x-pattern":"readPretty"}}},column5:{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:{edit:{type:"void",title:'{{ t("Edit") }}',"x-action":"update","x-component":"Action.Link","x-component-props":{openMode:"drawer",icon:"EditOutlined"},properties:{drawer:{type:"void",title:'{{ t("Edit record") }}',"x-component":"Action.Drawer","x-decorator":"FormV2","x-use-decorator-props":"useEditFormProps",properties:{title:{type:"string","x-decorator":"FormItem",title:'{{ t("Title") }}',"x-component":"Input"},description:{"x-decorator":"FormItem",type:"string",title:'{{ t("Description") }}',"x-component":"Input.TextArea"},options:{type:"object","x-component":"Settings"},footer:{type:"void","x-component":"Action.Drawer.Footer",properties:{cancel:{title:'{{ t("Cancel") }}',"x-component":"Action","x-use-component-props":"useCancelActionProps"},submit:{title:'{{ t("Submit") }}',"x-component":"Action","x-component-props":{type:"primary"},"x-use-component-props":"useEditActionProps"}}}}}}},destroy:{type:"void",title:'{{ t("Delete") }}',"x-action":"destroy","x-component":"Action.Link","x-use-component-props":"useDestroyActionProps","x-component-props":{confirm:{title:"{{t('Delete record')}}",content:"{{t('Are you sure you want to delete it?')}}"}}}}}}}}}}}}},p={name:"verificators",autoGenId:!1,fields:[{type:"uid",name:"name",primaryKey:!0},{type:"string",name:"title"},{type:"string",name:"verificationType"},{type:"string",name:"description"},{type:"jsonb",name:"options"},{interface:"m2m",type:"belongsToMany",name:"users",target:"users",foreignKey:"verificator",otherKey:"userId",onDelete:"CASCADE",sourceKey:"name",targetKey:"id",through:"usersVerificators"}]},a=n("573"),u=n("721"),l=n("482"),m=(0,o.createContext)({type:""});m.displayName="VerificationTypeContext";var y=(0,o.createContext)({types:[]});y.displayName="VerificationTypesContext";var d=n("505"),f=n("563"),v=n("875");function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function b(e,t,n,o,r,i,c){try{var s=e[i](c),p=s.value}catch(e){n(e);return}s.done?t(p):Promise.resolve(p).then(o,r)}function g(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var i=e.apply(t,n);function c(e){b(i,o,r,c,s,"next",e)}function s(e){b(i,o,r,c,s,"throw",e)}c(void 0)})}}function A(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,o,r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var i=[],c=!0,s=!1;try{for(r=r.call(e);!(c=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);c=!0);}catch(e){s=!0,o=e}finally{try{!c&&null!=r.return&&r.return()}finally{if(s)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return x(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return x(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,t){var n,o,r,i,c={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw TypeError("Generator is already executing.");for(;c;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return c.label++,{value:i[1],done:!1};case 5:c.label++,o=i[1],i=[0];continue;case 7:i=c.ops.pop(),c.trys.pop();continue;default:if(!(r=(r=c.trys).length>0&&r[r.length-1])&&(6===i[0]||2===i[0])){c=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){c.label=i[1];break}if(6===i[0]&&c.label<r[1]){c.label=r[1],r=i;break}if(r&&c.label<r[2]){c.label=r[2],c.ops.push(i);break}r[2]&&c.ops.pop(),c.trys.pop();continue}i=t.call(e,c)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var C=function(){var e=(0,o.useContext)(m).type;return{form:(0,o.useMemo)(function(){return(0,f.createForm)({initialValues:{name:"v_".concat((0,v.uid)()),verificationType:e}})},[e])}},w=function(){var e=(0,i.useCollectionRecordData)();return{form:(0,o.useMemo)(function(){return(0,f.createForm)({initialValues:e})},[e])}},P=function(){var e=(0,i.useActionContext)().setVisible,t=(0,d.useForm)();return{type:"default",onClick:function(){e(!1),t.reset()}}},S=function(){var e=(0,i.useActionContext)().setVisible,t=u.App.useApp().message,n=(0,d.useForm)(),o=(0,i.useDataBlockResource)(),r=(0,i.useDataBlockRequest)().refresh,c=(0,a.SD)().t;return{type:"primary",onClick:function(){return g(function(){var i;return h(this,function(s){switch(s.label){case 0:return[4,n.submit()];case 1:return s.sent(),i=n.values,[4,o.create({values:i})];case 2:return s.sent(),r(),t.success(c("Saved successfully")),e(!1),n.reset(),[2]}})})()}}},D=function(){var e=(0,i.useActionContext)().setVisible,t=u.App.useApp().message,n=(0,d.useForm)(),o=(0,i.useDataBlockResource)(),r=(0,i.useDataBlockRequest)().refresh,c=(0,i.useCollection)().getFilterTargetKey(),s=(0,a.SD)().t;return{type:"primary",onClick:function(){return g(function(){var i;return h(this,function(p){switch(p.label){case 0:return[4,n.submit()];case 1:return p.sent(),i=n.values,[4,o.update({values:i,filterByTk:i[c]})];case 2:return p.sent(),r(),t.success(s("Saved successfully")),e(!1),n.reset(),[2]}})})()}}},O=function(){var e=(0,a.SD)().t,t=A((0,o.useState)(!1),2),n=t[0],s=t[1],p=A((0,o.useState)(""),2),d=p[0],f=p[1],v=(0,o.useContext)(y).types.map(function(e){var t,n;return t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),o.forEach(function(t){var o,r,i;o=e,r=t,i=n[t],r in o?Object.defineProperty(o,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):o[r]=i})}return e}({},e),n=(n={onClick:function(){s(!0),f(e.value)}},n),Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);n.push.apply(n,o)}return n})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t});return r().createElement(i.ActionContextProvider,{value:{visible:n,setVisible:s}},r().createElement(m.Provider,{value:{type:d}},r().createElement(u.Dropdown,{menu:{items:v}},r().createElement(u.Button,{icon:r().createElement(l.PlusOutlined,null),type:"primary"},e("Add new")," ",r().createElement(l.DownOutlined,null))),r().createElement(i.SchemaComponent,{scope:{setType:f,useCreateFormProps:C},schema:c})))},T=function(e){var t,n=(0,i.usePlugin)("verification").verificationManager.getVerification(e);return null==n?void 0:null===(t=n.components)||void 0===t?void 0:t.AdminSettingsForm},k=(0,d.observer)(function(){var e=(0,d.useForm)(),t=(0,i.useCollectionRecordData)(),n=T(e.values.verificationType||t.verificationType);return n?r().createElement(n,null):null},{displayName:"VerificationSettings"}),E=function(){var e=(0,a.SD)().t,t=A((0,o.useState)([]),2),n=t[0],c=t[1],u=(0,i.useAPIClient)();return(0,i.useRequest)(function(){return u.resource("verificators").listTypes().then(function(t){var n;return((null==t?void 0:null===(n=t.data)||void 0===n?void 0:n.data)||[]).map(function(t){return{key:t.name,label:d.Schema.compile(t.title||t.name,{t:e}),value:t.name}})})},{onSuccess:function(e){c(e)}}),r().createElement(y.Provider,{value:{types:n}},r().createElement(i.ExtendCollectionsProvider,{collections:[p]},r().createElement(i.SchemaComponent,{schema:s,components:{AddNew:O,Settings:k},scope:{types:n,useEditFormProps:w,useCancelActionProps:P,useCreateActionProps:S,useEditActionProps:D}})))}}}]);
|
|
File without changes
|
|
File without changes
|