@nocobase/plugin-verification 1.7.0-beta.9 → 1.8.0-beta.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.
Files changed (49) hide show
  1. package/dist/client/83b24f85ae99a175.js +10 -0
  2. package/dist/client/937c9eccebc38607.js +10 -0
  3. package/dist/client/VerificationMenu.d.ts +1 -1
  4. package/dist/client/index.d.ts +1 -1
  5. package/dist/client/index.js +1 -1
  6. package/dist/client/otp-verification/VerificationCode.d.ts +1 -1
  7. package/dist/client/schemas/{verificators.d.ts → verifiers.d.ts} +2 -2
  8. package/dist/client/verification-manager/index.d.ts +2 -2
  9. package/dist/client/{verificators/VerificatorSelect.d.ts → verifiers/VerifierSelect.d.ts} +1 -1
  10. package/dist/client/{verificators/Verificators.d.ts → verifiers/Verifiers.d.ts} +1 -1
  11. package/dist/collections/verifiers.d.ts +50 -0
  12. package/dist/collections/verifiers.js +70 -0
  13. package/dist/externalVersion.js +6 -5
  14. package/dist/locale/en-US.json +6 -5
  15. package/dist/locale/zh-CN.json +6 -5
  16. package/dist/node_modules/@alicloud/dysmsapi20170525/dist/client.js +2 -2
  17. package/dist/node_modules/@alicloud/dysmsapi20170525/package.json +1 -1
  18. package/dist/node_modules/@alicloud/openapi-client/dist/client.js +2 -2
  19. package/dist/node_modules/@alicloud/openapi-client/package.json +1 -1
  20. package/dist/node_modules/@alicloud/tea-util/dist/client.js +1 -1
  21. package/dist/node_modules/@alicloud/tea-util/package.json +1 -1
  22. package/dist/node_modules/tencentcloud-sdk-nodejs/package.json +1 -1
  23. package/dist/node_modules/tencentcloud-sdk-nodejs/tencentcloud/index.js +2 -2
  24. package/dist/server/Plugin.d.ts +3 -0
  25. package/dist/server/Plugin.js +25 -13
  26. package/dist/server/actions/{verificators.js → verifiers.js} +38 -38
  27. package/dist/server/collections/otp-records.js +2 -2
  28. package/dist/server/collections/users-verificators.d.ts +0 -4
  29. package/dist/server/collections/users-verificators.js +1 -1
  30. package/dist/server/collections/users-verifiers.d.ts +14 -0
  31. package/dist/server/collections/users-verifiers.js +58 -0
  32. package/dist/server/collections/verificators.js +1 -1
  33. package/dist/server/collections/verifiers.d.ts +10 -0
  34. package/dist/server/collections/verifiers.js +47 -0
  35. package/dist/server/migrations/20250111192640-providers2verificators.js +16 -2
  36. package/dist/server/migrations/20250507220644-fix-verifier-typo.d.ts +14 -0
  37. package/dist/server/migrations/20250507220644-fix-verifier-typo.js +86 -0
  38. package/dist/server/otp-verification/index.d.ts +1 -0
  39. package/dist/server/otp-verification/index.js +62 -4
  40. package/dist/server/otp-verification/sms/resource/sms-otp.js +11 -11
  41. package/dist/server/verification-manager.d.ts +5 -5
  42. package/dist/server/verification-manager.js +29 -29
  43. package/dist/server/verification.d.ts +5 -5
  44. package/dist/server/verification.js +5 -5
  45. package/package.json +2 -2
  46. package/dist/client/cfedbdcfbe65d5f6.js +0 -10
  47. package/dist/client/d0b398212e5aa575.js +0 -10
  48. /package/dist/client/{verificators → verifiers}/verification-types.d.ts +0 -0
  49. /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 VerificationRepo = this.ctx.db.getRepository("otpRecords");
54
- const item = await VerificationRepo.findOne({
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
- verificatorName: this.verificator.name
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 || "verificators",
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, verificator: verificatorName } = ((_a = ctx.action.params) == null ? void 0 : _a.values) || {};
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 (!verificatorName) {
58
- return ctx.throw(400, "Invalid verificator");
57
+ if (!verifierName) {
58
+ return ctx.throw(400, "Invalid verifier");
59
59
  }
60
- const verificator = await ctx.db.getRepository("verificators").findOne({
60
+ const verifier = await ctx.db.getRepository("verifiers").findOne({
61
61
  filter: {
62
- name: verificatorName
62
+ name: verifierName
63
63
  }
64
64
  });
65
- if (!verificator) {
66
- return ctx.throw(400, "Invalid verificator");
65
+ if (!verifier) {
66
+ return ctx.throw(400, "Invalid verifier");
67
67
  }
68
- const Verification = verificationManager.getVerification(verificator.verificationType);
68
+ const Verification = verificationManager.getVerification(verifier.verificationType);
69
69
  const verification = new Verification({
70
70
  ctx,
71
- verificator,
72
- options: verificator.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
- verificatorName
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
- getVerificators?(ctx: Context): Promise<string[]>;
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
- getVerificator(verificatorName: string): Promise<any>;
56
- getVerificators(verificatorNames: string[]): Promise<any>;
57
- getBoundRecord(userId: number, verificator: string): Promise<any>;
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 validateAndGetVerificator;
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 getVerificator(verificatorName) {
85
- return await this.db.getRepository("verificators").findOne({
84
+ async getVerifier(verifierName) {
85
+ return await this.db.getRepository("verifiers").findOne({
86
86
  filter: {
87
- name: verificatorName
87
+ name: verifierName
88
88
  }
89
89
  });
90
90
  }
91
- async getVerificators(verificatorNames) {
92
- return await this.db.getRepository("verificators").find({
91
+ async getVerifiers(verifierNames) {
92
+ return await this.db.getRepository("verifiers").find({
93
93
  filter: {
94
- name: verificatorNames
94
+ name: verifierNames
95
95
  }
96
96
  });
97
97
  }
98
- async getBoundRecord(userId, verificator) {
99
- return await this.db.getRepository("usersVerificators").findOne({
98
+ async getBoundRecord(userId, verifier) {
99
+ return await this.db.getRepository("usersVerifiers").findOne({
100
100
  filter: {
101
101
  userId,
102
- verificator
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 validateAndGetVerificator(ctx, scene, verificatorName) {
127
- let verificator;
128
- if (!verificatorName) {
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.getVerificators) {
134
- const verificators = await sceneOptions.getVerificators(ctx);
135
- if (!verificators.includes(verificatorName)) {
133
+ if (sceneOptions.getVerifiers) {
134
+ const verifiers = await sceneOptions.getVerifiers(ctx);
135
+ if (!verifiers.includes(verifierName)) {
136
136
  return null;
137
137
  }
138
- verificator = await this.getVerificator(verificatorName);
139
- if (!verificator) {
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 verificators = await this.db.getRepository("verificators").find({
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
- verificator = verificators.find((item) => item.name === verificatorName);
150
- if (!verificator) {
149
+ verifier = verifiers.find((item) => item.name === verifierName);
150
+ if (!verifier) {
151
151
  return null;
152
152
  }
153
153
  }
154
154
  } else {
155
- verificator = await this.getVerificator(verificatorName);
156
- if (!verificator) {
155
+ verifier = await this.getVerifier(verifierName);
156
+ if (!verifier) {
157
157
  return null;
158
158
  }
159
159
  }
160
- return verificator;
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 { verificator: verificatorName } = ctx.action.params.values || {};
172
- const verificator = await this.validateAndGetVerificator(ctx, action.scene, verificatorName);
173
- if (!verificator) {
174
- ctx.throw(400, "Invalid verificator");
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(verificator.verificationType);
183
- const verification = new Verification2({ ctx, verificator, options: verificator.options });
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
- verificator: Model;
35
+ verifier: Model;
36
36
  protected ctx: Context;
37
37
  protected options: Record<string, any>;
38
- constructor({ ctx, verificator, options }: {
38
+ constructor({ ctx, verifier, options }: {
39
39
  ctx: any;
40
- verificator: any;
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, verificator, options }: {
66
+ export type VerificationExtend<T extends Verification> = new ({ ctx, verifier, options }: {
67
67
  ctx: any;
68
- verificator: any;
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
- verificator;
33
+ verifier;
34
34
  ctx;
35
35
  options;
36
- constructor({ ctx, verificator, options }) {
36
+ constructor({ ctx, verifier, options }) {
37
37
  this.ctx = ctx;
38
- this.verificator = verificator;
38
+ this.verifier = verifier;
39
39
  this.options = options;
40
40
  }
41
41
  get throughRepo() {
42
- return this.ctx.db.getRepository("usersVerificators");
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
- verificator: this.verificator.name,
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.0-beta.9",
7
+ "version": "1.8.0-beta.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": "7013a5080f3695d7750ab21005c90d2172c16480",
34
+ "gitHead": "103935669123174f2942247202e3d9ff15f0d4ed",
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}})))}}}]);