@nocobase/plugin-verification 1.7.0-beta.9 → 1.7.0

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
@@ -9,9 +9,12 @@
9
9
  import { Plugin } from '@nocobase/server';
10
10
  import { VerificationManager } from './verification-manager';
11
11
  import { SMSOTPProviderManager } from './otp-verification/sms';
12
+ import { Counter } from '@nocobase/cache';
12
13
  export default class PluginVerficationServer extends Plugin {
13
14
  verificationManager: VerificationManager;
14
15
  smsOTPProviderManager: SMSOTPProviderManager;
16
+ smsOTPCounter: Counter;
17
+ afterAdd(): Promise<void>;
15
18
  load(): Promise<void>;
16
19
  install(): Promise<void>;
17
20
  }
@@ -46,7 +46,7 @@ var import_constants = require("../constants");
46
46
  var import_verification_manager = require("./verification-manager");
47
47
  var import_sms = require("./otp-verification/sms");
48
48
  var import_constants2 = require("../constants");
49
- var import_verificators = __toESM(require("./actions/verificators"));
49
+ var import_verifiers = __toESM(require("./actions/verifiers"));
50
50
  var import_sms_aliyun = __toESM(require("./otp-verification/sms/providers/sms-aliyun"));
51
51
  var import_sms_tencent = __toESM(require("./otp-verification/sms/providers/sms-tencent"));
52
52
  var import_sms_otp_providers = __toESM(require("./otp-verification/sms/resource/sms-otp-providers"));
@@ -54,22 +54,34 @@ var import_sms_otp = __toESM(require("./otp-verification/sms/resource/sms-otp"))
54
54
  class PluginVerficationServer extends import_server.Plugin {
55
55
  verificationManager = new import_verification_manager.VerificationManager({ db: this.db });
56
56
  smsOTPProviderManager = new import_sms.SMSOTPProviderManager();
57
+ smsOTPCounter;
58
+ async afterAdd() {
59
+ this.app.on("afterLoad", async () => {
60
+ this.smsOTPCounter = await this.app.cacheManager.createCounter(
61
+ {
62
+ name: "smsOTPCounter",
63
+ prefix: "sms-otp:attempts"
64
+ },
65
+ this.app.lockManager
66
+ );
67
+ });
68
+ }
57
69
  async load() {
58
70
  this.app.dataSourceManager.use(this.verificationManager.middleware());
59
71
  this.app.resourceManager.define(import_sms_otp_providers.default);
60
72
  this.app.resourceManager.define(import_sms_otp.default);
61
- Object.entries(import_verificators.default).forEach(
62
- ([action, handler]) => this.app.resourceManager.registerActionHandler(`verificators:${action}`, handler)
73
+ Object.entries(import_verifiers.default).forEach(
74
+ ([action, handler]) => this.app.resourceManager.registerActionHandler(`verifiers:${action}`, handler)
63
75
  );
64
- this.app.acl.allow("verificators", "listByUser", "loggedIn");
65
- this.app.acl.allow("verificators", "listForVerify", "loggedIn");
66
- this.app.acl.allow("verificators", "bind", "loggedIn");
67
- this.app.acl.allow("verificators", "unbind", "loggedIn");
76
+ this.app.acl.allow("verifiers", "listByUser", "loggedIn");
77
+ this.app.acl.allow("verifiers", "listForVerify", "loggedIn");
78
+ this.app.acl.allow("verifiers", "bind", "loggedIn");
79
+ this.app.acl.allow("verifiers", "unbind", "loggedIn");
68
80
  this.app.acl.allow("smsOTP", "create", "loggedIn");
69
81
  this.app.acl.allow("smsOTP", "publicCreate");
70
82
  this.app.acl.registerSnippet({
71
- name: `pm.${this.name}.verificators`,
72
- actions: ["verificators:*", "smsOTPProviders:*"]
83
+ name: `pm.${this.name}.verifiers`,
84
+ actions: ["verifiers:*", "smsOTPProviders:*"]
73
85
  });
74
86
  this.verificationManager.registerVerificationType(import_constants2.SMS_OTP_VERIFICATION_TYPE, {
75
87
  title: (0, import_utils.tval)("SMS OTP", { ns: import__.namespace }),
@@ -80,17 +92,17 @@ class PluginVerficationServer extends import_server.Plugin {
80
92
  verification: import_sms.SMSOTPVerification
81
93
  });
82
94
  this.verificationManager.addSceneRule(
83
- (scene, verificationType) => ["auth-sms", "unbind-verificator"].includes(scene) && verificationType === import_constants2.SMS_OTP_VERIFICATION_TYPE
95
+ (scene, verificationType) => ["auth-sms", "unbind-verifier"].includes(scene) && verificationType === import_constants2.SMS_OTP_VERIFICATION_TYPE
84
96
  );
85
- this.verificationManager.registerAction("verificators:bind", {
97
+ this.verificationManager.registerAction("verifiers:bind", {
86
98
  manual: true,
87
99
  getBoundInfoFromCtx: (ctx) => {
88
100
  return ctx.action.params.values || {};
89
101
  }
90
102
  });
91
- this.verificationManager.registerScene("unbind-verificator", {
103
+ this.verificationManager.registerScene("unbind-verifier", {
92
104
  actions: {
93
- "verificators:unbind": {}
105
+ "verifiers:unbind": {}
94
106
  }
95
107
  });
96
108
  this.smsOTPProviderManager.registerProvider(import_constants.PROVIDER_TYPE_SMS_ALIYUN, {
@@ -34,13 +34,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
34
34
  mod
35
35
  ));
36
36
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var verificators_exports = {};
38
- __export(verificators_exports, {
39
- default: () => verificators_default
37
+ var verifiers_exports = {};
38
+ __export(verifiers_exports, {
39
+ default: () => verifiers_default
40
40
  });
41
- module.exports = __toCommonJS(verificators_exports);
41
+ module.exports = __toCommonJS(verifiers_exports);
42
42
  var import_package = __toESM(require("../../../package.json"));
43
- var verificators_default = {
43
+ var verifiers_default = {
44
44
  listTypes: async (ctx, next) => {
45
45
  const plugin = ctx.app.pm.get("verification");
46
46
  ctx.body = plugin.verificationManager.listTypes();
@@ -51,16 +51,16 @@ var verificators_default = {
51
51
  const plugin = ctx.app.pm.get("verification");
52
52
  const verificationTypes = plugin.verificationManager.getVerificationTypesByScene(scene);
53
53
  if (!verificationTypes.length) {
54
- ctx.body = { verificators: [], availableTypes: [] };
54
+ ctx.body = { verifiers: [], availableTypes: [] };
55
55
  return next();
56
56
  }
57
- const verificators = await ctx.db.getRepository("verificators").find({
57
+ const verifiers = await ctx.db.getRepository("verifiers").find({
58
58
  filter: {
59
59
  verificationType: verificationTypes.map((item) => item.type)
60
60
  }
61
61
  });
62
62
  ctx.body = {
63
- verificators: (verificators || []).map((item) => ({
63
+ verifiers: (verifiers || []).map((item) => ({
64
64
  name: item.name,
65
65
  title: item.title
66
66
  })),
@@ -75,22 +75,22 @@ var verificators_default = {
75
75
  const plugin = ctx.app.pm.get("verification");
76
76
  const verificationTypes = plugin.verificationManager.verificationTypes;
77
77
  const bindingRequiredTypes = Array.from(verificationTypes.getEntities()).filter(([, options]) => options.bindingRequired).map(([type]) => type);
78
- const verificators = await ctx.db.getRepository("verificators").find({
78
+ const verifiers = await ctx.db.getRepository("verifiers").find({
79
79
  filter: {
80
80
  verificationType: bindingRequiredTypes
81
81
  }
82
82
  });
83
83
  const result = [];
84
- for (const verificator of verificators) {
84
+ for (const verifier of verifiers) {
85
85
  try {
86
- const verificationType = plugin.verificationManager.verificationTypes.get(verificator.verificationType);
87
- const Verification = plugin.verificationManager.getVerification(verificator.verificationType);
88
- const verification = new Verification({ ctx, verificator, options: verificator.options });
86
+ const verificationType = plugin.verificationManager.verificationTypes.get(verifier.verificationType);
87
+ const Verification = plugin.verificationManager.getVerification(verifier.verificationType);
88
+ const verification = new Verification({ ctx, verifier, options: verifier.options });
89
89
  const boundInfo = await verification.getPublicBoundInfo(ctx.auth.user.id);
90
90
  result.push({
91
- ...verificator.dataValues,
92
- title: verificator.title || verificationType.title,
93
- description: verificator.description || verificationType.description,
91
+ ...verifier.dataValues,
92
+ title: verifier.title || verificationType.title,
93
+ description: verifier.description || verificationType.description,
94
94
  boundInfo
95
95
  });
96
96
  } catch (error) {
@@ -108,28 +108,28 @@ var verificators_default = {
108
108
  ctx.body = [];
109
109
  return next();
110
110
  }
111
- const verificators = await ctx.db.getRepository("verificators").find({
111
+ const verifiers = await ctx.db.getRepository("verifiers").find({
112
112
  filter: {
113
113
  verificationType: verificationTypes.map((item) => item.type)
114
114
  }
115
115
  });
116
- if (!verificators.length) {
116
+ if (!verifiers.length) {
117
117
  ctx.body = [];
118
118
  return next();
119
119
  }
120
120
  const result = [];
121
- for (const verificator of verificators) {
122
- const verificationType = plugin.verificationManager.verificationTypes.get(verificator.verificationType);
123
- const Verification = plugin.verificationManager.getVerification(verificator.verificationType);
124
- const verification = new Verification({ ctx, verificator, options: verificator.options });
121
+ for (const verifier of verifiers) {
122
+ const verificationType = plugin.verificationManager.verificationTypes.get(verifier.verificationType);
123
+ const Verification = plugin.verificationManager.getVerification(verifier.verificationType);
124
+ const verification = new Verification({ ctx, verifier, options: verifier.options });
125
125
  const publicBoundInfo = await verification.getPublicBoundInfo(ctx.auth.user.id);
126
126
  if (!(publicBoundInfo == null ? void 0 : publicBoundInfo.bound)) {
127
127
  continue;
128
128
  }
129
129
  result.push({
130
- name: verificator.name,
131
- title: verificator.title,
132
- verificationType: verificator.verificationType,
130
+ name: verifier.name,
131
+ title: verifier.title,
132
+ verificationType: verifier.verificationType,
133
133
  verificationTypeTitle: verificationType == null ? void 0 : verificationType.title,
134
134
  boundInfo: publicBoundInfo
135
135
  });
@@ -138,21 +138,21 @@ var verificators_default = {
138
138
  await next();
139
139
  },
140
140
  bind: async (ctx, next) => {
141
- const { verificator: name } = ctx.action.params.values || {};
141
+ const { verifier: name } = ctx.action.params.values || {};
142
142
  const user = ctx.auth.user;
143
143
  const verificationPlugin = ctx.app.pm.get("verification");
144
144
  const record = await verificationPlugin.verificationManager.getBoundRecord(user.id, name);
145
145
  if (record) {
146
- return ctx.throw(400, ctx.t("You have already bound this verificator", { ns: import_package.default.name }));
146
+ return ctx.throw(400, ctx.t("You have already bound this verifier", { ns: import_package.default.name }));
147
147
  }
148
- const verificator = await verificationPlugin.verificationManager.getVerificator(name);
149
- if (!verificator) {
150
- return ctx.throw(400, ctx.t("Invalid verificator"));
148
+ const verifier = await verificationPlugin.verificationManager.getVerifier(name);
149
+ if (!verifier) {
150
+ return ctx.throw(400, ctx.t("Invalid verifier"));
151
151
  }
152
- const Verification = verificationPlugin.verificationManager.getVerification(verificator.verificationType);
153
- const verification = new Verification({ ctx, verificator, options: verificator.options });
152
+ const Verification = verificationPlugin.verificationManager.getVerification(verifier.verificationType);
153
+ const verification = new Verification({ ctx, verifier, options: verifier.options });
154
154
  const { uuid, meta } = await verification.bind(user.id);
155
- await verificator.addUser(user.id, {
155
+ await verifier.addUser(user.id, {
156
156
  through: {
157
157
  uuid,
158
158
  meta
@@ -162,14 +162,14 @@ var verificators_default = {
162
162
  await next();
163
163
  },
164
164
  unbind: async (ctx, next) => {
165
- const { unbindVerificator: name } = ctx.action.params.values || {};
165
+ const { unbindVerifier: name } = ctx.action.params.values || {};
166
166
  const user = ctx.auth.user;
167
167
  const verificationPlugin = ctx.app.pm.get("verification");
168
- const verificator = await verificationPlugin.verificationManager.getVerificator(name);
169
- if (!verificator) {
170
- return ctx.throw(400, ctx.t("Invalid verificator"));
168
+ const verifier = await verificationPlugin.verificationManager.getVerifier(name);
169
+ if (!verifier) {
170
+ return ctx.throw(400, ctx.t("Invalid verifier"));
171
171
  }
172
- await verificator.removeUser(user.id);
172
+ await verifier.removeUser(user.id);
173
173
  await next();
174
174
  }
175
175
  };
@@ -67,8 +67,8 @@ var otp_records_default = (0, import_database.defineCollection)({
67
67
  },
68
68
  {
69
69
  type: "belongsTo",
70
- name: "verificator",
71
- target: "verificators",
70
+ name: "verifier",
71
+ target: "verifiers",
72
72
  targetKey: "name"
73
73
  }
74
74
  ]
@@ -6,9 +6,5 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- /**
10
- * Collection for user information of extended authentication methods,
11
- * such as saml, oicd, oauth, sms, etc.
12
- */
13
9
  declare const _default: import("@nocobase/database").CollectionOptions;
14
10
  export default _default;
@@ -31,7 +31,7 @@ __export(users_verificators_exports, {
31
31
  module.exports = __toCommonJS(users_verificators_exports);
32
32
  var import_database = require("@nocobase/database");
33
33
  var users_verificators_default = (0, import_database.defineCollection)({
34
- migrationRules: ["schema-only", "overwrite", "skip"],
34
+ migrationRules: ["skip"],
35
35
  name: "usersVerificators",
36
36
  createdBy: true,
37
37
  updatedBy: true,
@@ -0,0 +1,14 @@
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
+ * Collection for user information of extended authentication methods,
11
+ * such as saml, oicd, oauth, sms, etc.
12
+ */
13
+ declare const _default: import("@nocobase/database").CollectionOptions;
14
+ export default _default;
@@ -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 users_verifiers_exports = {};
28
+ __export(users_verifiers_exports, {
29
+ default: () => users_verifiers_default
30
+ });
31
+ module.exports = __toCommonJS(users_verifiers_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var users_verifiers_default = (0, import_database.defineCollection)({
34
+ migrationRules: ["schema-only", "overwrite", "skip"],
35
+ name: "usersVerifiers",
36
+ createdBy: true,
37
+ updatedBy: true,
38
+ logging: true,
39
+ fields: [
40
+ {
41
+ name: "uuid",
42
+ interface: "input",
43
+ type: "string",
44
+ allowNull: false,
45
+ uiSchema: {
46
+ type: "string",
47
+ title: '{{t("UUID")}}',
48
+ "x-component": "Input",
49
+ required: true
50
+ }
51
+ },
52
+ {
53
+ type: "json",
54
+ name: "meta",
55
+ defaultValue: {}
56
+ }
57
+ ]
58
+ });
@@ -42,6 +42,6 @@ module.exports = __toCommonJS(verificators_exports);
42
42
  var import_database = require("@nocobase/database");
43
43
  var import_verificators = __toESM(require("../../collections/verificators"));
44
44
  var verificators_default = (0, import_database.defineCollection)({
45
- migrationRules: ["overwrite", "skip"],
45
+ migrationRules: ["skip"],
46
46
  ...import_verificators.default
47
47
  });
@@ -0,0 +1,10 @@
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: import("@nocobase/database").CollectionOptions;
10
+ export default _default;
@@ -0,0 +1,47 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var verifiers_exports = {};
38
+ __export(verifiers_exports, {
39
+ default: () => verifiers_default
40
+ });
41
+ module.exports = __toCommonJS(verifiers_exports);
42
+ var import_database = require("@nocobase/database");
43
+ var import_verifiers = __toESM(require("../../collections/verifiers"));
44
+ var verifiers_default = (0, import_database.defineCollection)({
45
+ migrationRules: ["overwrite", "skip"],
46
+ ...import_verifiers.default
47
+ });
@@ -35,9 +35,20 @@ var import_constants = require("../../constants");
35
35
  class providers2verificators_default extends import_server.Migration {
36
36
  on = "afterLoad";
37
37
  // 'beforeLoad' or 'afterLoad'
38
- appVersion = "<1.6.1";
38
+ appVersion = "<1.7.0";
39
39
  async up() {
40
+ const verificatorsRepo = this.db.getRepository("verificators");
41
+ if (await verificatorsRepo.count()) {
42
+ return;
43
+ }
44
+ const repo = this.db.getRepository("verifications_providers");
45
+ if (!repo) {
46
+ return;
47
+ }
40
48
  const providers = await this.db.getRepository("verifications_providers").find();
49
+ if (!providers.length) {
50
+ return;
51
+ }
41
52
  const verificators = [];
42
53
  let defaultVerificator;
43
54
  providers.forEach((provider) => {
@@ -55,6 +66,9 @@ class providers2verificators_default extends import_server.Migration {
55
66
  defaultVerificator = verificator;
56
67
  }
57
68
  });
69
+ if (!defaultVerificator) {
70
+ defaultVerificator = verificators[0];
71
+ }
58
72
  const smsAuth = await this.db.getRepository("authenticators").find({
59
73
  filter: {
60
74
  authType: "SMS"
@@ -71,7 +85,7 @@ class providers2verificators_default extends import_server.Migration {
71
85
  ...item.options,
72
86
  public: {
73
87
  ...(_a = item.options) == null ? void 0 : _a.public,
74
- verificator: defaultVerificator.name
88
+ verificator: defaultVerificator == null ? void 0 : defaultVerificator.name
75
89
  }
76
90
  }
77
91
  },
@@ -0,0 +1,14 @@
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
+ import { Migration } from '@nocobase/server';
10
+ export default class extends Migration {
11
+ on: string;
12
+ appVersion: string;
13
+ up(): Promise<void>;
14
+ }
@@ -0,0 +1,86 @@
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 fix_verifier_typo_exports = {};
28
+ __export(fix_verifier_typo_exports, {
29
+ default: () => fix_verifier_typo_default
30
+ });
31
+ module.exports = __toCommonJS(fix_verifier_typo_exports);
32
+ var import_server = require("@nocobase/server");
33
+ class fix_verifier_typo_default extends import_server.Migration {
34
+ on = "afterLoad";
35
+ // 'beforeLoad' or 'afterLoad'
36
+ appVersion = "<1.7.0";
37
+ async up() {
38
+ const oldRepo = await this.db.getRepository("verificators");
39
+ const newRepo = await this.db.getRepository("verifiers");
40
+ const oldThroughRepo = await this.db.getRepository("usersVerificators");
41
+ const newThroughRepo = await this.db.getRepository("usersVerifiers");
42
+ await this.db.sequelize.transaction(async (transaction) => {
43
+ if (await newRepo.count({ transaction })) {
44
+ return;
45
+ }
46
+ const oldRecords = await oldRepo.find({ transaction });
47
+ if (!oldRecords.length) {
48
+ return;
49
+ }
50
+ const newRecords = oldRecords.map((record) => ({
51
+ createdAt: record.createdAt,
52
+ updatedAt: record.updatedAt,
53
+ name: record.name,
54
+ title: record.title,
55
+ verificationType: record.verificationType,
56
+ description: record.description,
57
+ options: record.options
58
+ }));
59
+ const model = await this.db.getModel("verifiers");
60
+ await model.bulkCreate(newRecords, {
61
+ transaction
62
+ });
63
+ if (await newThroughRepo.count({ transaction })) {
64
+ return;
65
+ }
66
+ const oldThroughRecords = await oldThroughRepo.find({ transaction });
67
+ if (!oldThroughRecords.length) {
68
+ return;
69
+ }
70
+ const newThroughRecords = oldThroughRecords.map((record) => ({
71
+ createdAt: record.createdAt,
72
+ updatedAt: record.updatedAt,
73
+ userId: record.userId,
74
+ uuid: record.uuid,
75
+ meta: record.meta,
76
+ verifier: record.verificator,
77
+ createdById: record.createdById,
78
+ updatedById: record.updatedById
79
+ }));
80
+ const throughModel = await this.db.getModel("usersVerifiers");
81
+ await throughModel.bulkCreate(newThroughRecords, {
82
+ transaction
83
+ });
84
+ });
85
+ }
86
+ }
@@ -9,6 +9,7 @@
9
9
  import { Verification } from '../verification';
10
10
  export declare class OTPVerification extends Verification {
11
11
  expiresIn: number;
12
+ maxVerifyAttempts: number;
12
13
  verify({ resource, action, boundInfo, verifyParams }: {
13
14
  resource: any;
14
15
  action: any;