@nocobase/plugin-verification 0.7.7-alpha.1 → 0.8.0-alpha.4
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/lib/Plugin.d.ts +2 -3
- package/lib/Plugin.js +12 -18
- package/lib/actions/verifications.js +16 -16
- package/package.json +7 -7
- package/src/Plugin.ts +20 -24
- package/src/__tests__/Plugin.test.ts +2 -2
- package/src/__tests__/index.ts +3 -3
- package/src/actions/verifications.ts +4 -4
package/lib/Plugin.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Context } from '@nocobase/actions';
|
|
2
|
+
import { HandlerType } from '@nocobase/resourcer';
|
|
1
3
|
import { Plugin } from '@nocobase/server';
|
|
2
4
|
import { Registry } from '@nocobase/utils';
|
|
3
|
-
import { HandlerType } from '@nocobase/resourcer';
|
|
4
|
-
import { Context } from '@nocobase/actions';
|
|
5
5
|
import { Provider } from './providers';
|
|
6
6
|
export interface Interceptor {
|
|
7
7
|
manual?: boolean;
|
|
@@ -15,7 +15,6 @@ export default class VerificationPlugin extends Plugin {
|
|
|
15
15
|
providers: Registry<typeof Provider>;
|
|
16
16
|
interceptors: Registry<Interceptor>;
|
|
17
17
|
intercept: HandlerType;
|
|
18
|
-
getName(): string;
|
|
19
18
|
install(): Promise<void>;
|
|
20
19
|
load(): Promise<void>;
|
|
21
20
|
}
|
package/lib/Plugin.js
CHANGED
|
@@ -15,54 +15,52 @@ function _path() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function
|
|
19
|
-
const data = require("@nocobase/
|
|
18
|
+
function _database() {
|
|
19
|
+
const data = require("@nocobase/database");
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
_database = function _database() {
|
|
22
22
|
return data;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function
|
|
29
|
-
const data = require("@nocobase/
|
|
28
|
+
function _server() {
|
|
29
|
+
const data = require("@nocobase/server");
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
_server = function _server() {
|
|
32
32
|
return data;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
return data;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function
|
|
39
|
-
const data = require("@nocobase/
|
|
38
|
+
function _utils() {
|
|
39
|
+
const data = require("@nocobase/utils");
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
_utils = function _utils() {
|
|
42
42
|
return data;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
return data;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
var
|
|
48
|
+
var _ = require(".");
|
|
49
49
|
|
|
50
50
|
var _actions = _interopRequireDefault(require("./actions"));
|
|
51
51
|
|
|
52
52
|
var _constants = require("./constants");
|
|
53
53
|
|
|
54
|
-
var _ = require(".");
|
|
55
|
-
|
|
56
54
|
var _locale = require("./locale");
|
|
57
55
|
|
|
56
|
+
var _providers = _interopRequireDefault(require("./providers"));
|
|
57
|
+
|
|
58
58
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
59
59
|
|
|
60
60
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
61
61
|
|
|
62
62
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
63
63
|
|
|
64
|
-
;
|
|
65
|
-
|
|
66
64
|
class VerificationPlugin extends _server().Plugin {
|
|
67
65
|
constructor(...args) {
|
|
68
66
|
var _this;
|
|
@@ -134,10 +132,6 @@ class VerificationPlugin extends _server().Plugin {
|
|
|
134
132
|
}();
|
|
135
133
|
}
|
|
136
134
|
|
|
137
|
-
getName() {
|
|
138
|
-
return this.getPackageName(__dirname);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
135
|
install() {
|
|
142
136
|
var _this2 = this;
|
|
143
137
|
|
|
@@ -5,16 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.create = create;
|
|
7
7
|
|
|
8
|
-
function _util() {
|
|
9
|
-
const data = require("util");
|
|
10
|
-
|
|
11
|
-
_util = function _util() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
8
|
function _crypto() {
|
|
19
9
|
const data = require("crypto");
|
|
20
10
|
|
|
@@ -25,10 +15,10 @@ function _crypto() {
|
|
|
25
15
|
return data;
|
|
26
16
|
}
|
|
27
17
|
|
|
28
|
-
function
|
|
29
|
-
const data = require("
|
|
18
|
+
function _util() {
|
|
19
|
+
const data = require("util");
|
|
30
20
|
|
|
31
|
-
|
|
21
|
+
_util = function _util() {
|
|
32
22
|
return data;
|
|
33
23
|
};
|
|
34
24
|
|
|
@@ -45,9 +35,15 @@ function _actions() {
|
|
|
45
35
|
return data;
|
|
46
36
|
}
|
|
47
37
|
|
|
48
|
-
|
|
38
|
+
function _database() {
|
|
39
|
+
const data = require("@nocobase/database");
|
|
49
40
|
|
|
50
|
-
|
|
41
|
+
_database = function _database() {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
51
47
|
|
|
52
48
|
function _moment() {
|
|
53
49
|
const data = _interopRequireDefault(require("moment"));
|
|
@@ -59,6 +55,10 @@ function _moment() {
|
|
|
59
55
|
return data;
|
|
60
56
|
}
|
|
61
57
|
|
|
58
|
+
var _ = require("..");
|
|
59
|
+
|
|
60
|
+
var _constants = require("../constants");
|
|
61
|
+
|
|
62
62
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
63
63
|
|
|
64
64
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
@@ -75,7 +75,7 @@ function _create() {
|
|
|
75
75
|
_create = _asyncToGenerator(function* (context, next) {
|
|
76
76
|
var _interceptor$expiresI;
|
|
77
77
|
|
|
78
|
-
const plugin = context.app.getPlugin('
|
|
78
|
+
const plugin = context.app.getPlugin('verification');
|
|
79
79
|
const values = context.action.params.values;
|
|
80
80
|
const interceptor = plugin.interceptors.get(values === null || values === void 0 ? void 0 : values.type);
|
|
81
81
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-verification",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-alpha.4",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"licenses": [
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"@alicloud/dysmsapi20170525": "2.0.17",
|
|
14
14
|
"@alicloud/openapi-client": "0.4.1",
|
|
15
15
|
"@alicloud/tea-util": "1.4.4",
|
|
16
|
-
"@nocobase/actions": "0.
|
|
17
|
-
"@nocobase/resourcer": "0.
|
|
18
|
-
"@nocobase/server": "0.
|
|
19
|
-
"@nocobase/utils": "0.
|
|
16
|
+
"@nocobase/actions": "0.8.0-alpha.4",
|
|
17
|
+
"@nocobase/resourcer": "0.8.0-alpha.4",
|
|
18
|
+
"@nocobase/server": "0.8.0-alpha.4",
|
|
19
|
+
"@nocobase/utils": "0.8.0-alpha.4"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@nocobase/test": "0.
|
|
22
|
+
"@nocobase/test": "0.8.0-alpha.4"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "433f068ce4479a53f51d3ceac3f22b710e7bb13e"
|
|
25
25
|
}
|
package/src/Plugin.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { Registry } from '@nocobase/utils';
|
|
3
|
+
import { Context } from '@nocobase/actions';
|
|
5
4
|
import { Op } from '@nocobase/database';
|
|
6
5
|
import { HandlerType } from '@nocobase/resourcer';
|
|
7
|
-
import {
|
|
6
|
+
import { Plugin } from '@nocobase/server';
|
|
7
|
+
import { Registry } from '@nocobase/utils';
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import { namespace } from '.';
|
|
10
10
|
import initActions from './actions';
|
|
11
11
|
import { CODE_STATUS_UNUSED, CODE_STATUS_USED, PROVIDER_TYPE_SMS_ALIYUN } from './constants';
|
|
12
|
-
import { namespace } from '.';
|
|
13
12
|
import { zhCN } from './locale';
|
|
13
|
+
import initProviders, { Provider } from './providers';
|
|
14
14
|
|
|
15
15
|
export interface Interceptor {
|
|
16
16
|
manual?: boolean;
|
|
@@ -19,7 +19,7 @@ export interface Interceptor {
|
|
|
19
19
|
getReceiver(ctx): string;
|
|
20
20
|
getCode?(ctx): string;
|
|
21
21
|
validate?(ctx: Context, receiver: string): boolean | Promise<boolean>;
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
23
|
|
|
24
24
|
export default class VerificationPlugin extends Plugin {
|
|
25
25
|
providers: Registry<typeof Provider> = new Registry();
|
|
@@ -49,10 +49,10 @@ export default class VerificationPlugin extends Plugin {
|
|
|
49
49
|
type: key,
|
|
50
50
|
content,
|
|
51
51
|
expiresAt: {
|
|
52
|
-
[Op.gt]: new Date()
|
|
52
|
+
[Op.gt]: new Date(),
|
|
53
53
|
},
|
|
54
|
-
status: CODE_STATUS_UNUSED
|
|
55
|
-
}
|
|
54
|
+
status: CODE_STATUS_UNUSED,
|
|
55
|
+
},
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
if (!item) {
|
|
@@ -70,14 +70,9 @@ export default class VerificationPlugin extends Plugin {
|
|
|
70
70
|
|
|
71
71
|
// or delete
|
|
72
72
|
await item.update({
|
|
73
|
-
status: CODE_STATUS_USED
|
|
73
|
+
status: CODE_STATUS_USED,
|
|
74
74
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
getName(): string {
|
|
79
|
-
return this.getPackageName(__dirname);
|
|
80
|
-
}
|
|
75
|
+
};
|
|
81
76
|
|
|
82
77
|
async install() {
|
|
83
78
|
const {
|
|
@@ -86,13 +81,14 @@ export default class VerificationPlugin extends Plugin {
|
|
|
86
81
|
INIT_ALI_SMS_ACCESS_KEY_SECRET,
|
|
87
82
|
INIT_ALI_SMS_ENDPOINT = 'dysmsapi.aliyuncs.com',
|
|
88
83
|
INIT_ALI_SMS_VERIFY_CODE_TEMPLATE,
|
|
89
|
-
INIT_ALI_SMS_VERIFY_CODE_SIGN
|
|
84
|
+
INIT_ALI_SMS_VERIFY_CODE_SIGN,
|
|
90
85
|
} = process.env;
|
|
91
86
|
|
|
92
|
-
if (
|
|
93
|
-
&&
|
|
94
|
-
&&
|
|
95
|
-
&&
|
|
87
|
+
if (
|
|
88
|
+
INIT_ALI_SMS_ACCESS_KEY &&
|
|
89
|
+
INIT_ALI_SMS_ACCESS_KEY_SECRET &&
|
|
90
|
+
INIT_ALI_SMS_VERIFY_CODE_TEMPLATE &&
|
|
91
|
+
INIT_ALI_SMS_VERIFY_CODE_SIGN
|
|
96
92
|
) {
|
|
97
93
|
const ProviderRepo = this.db.getRepository('verifications_providers');
|
|
98
94
|
await ProviderRepo.create({
|
|
@@ -105,9 +101,9 @@ export default class VerificationPlugin extends Plugin {
|
|
|
105
101
|
accessKeySecret: INIT_ALI_SMS_ACCESS_KEY_SECRET,
|
|
106
102
|
endpoint: INIT_ALI_SMS_ENDPOINT,
|
|
107
103
|
sign: INIT_ALI_SMS_VERIFY_CODE_SIGN,
|
|
108
|
-
template: INIT_ALI_SMS_VERIFY_CODE_TEMPLATE
|
|
109
|
-
}
|
|
110
|
-
}
|
|
104
|
+
template: INIT_ALI_SMS_VERIFY_CODE_TEMPLATE,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
111
107
|
});
|
|
112
108
|
}
|
|
113
109
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { MockServer } from '@nocobase/test';
|
|
2
1
|
import Database from '@nocobase/database';
|
|
2
|
+
import { MockServer } from '@nocobase/test';
|
|
3
3
|
|
|
4
4
|
import Plugin, { Provider } from '..';
|
|
5
5
|
|
|
@@ -21,7 +21,7 @@ describe('verification > Plugin', () => {
|
|
|
21
21
|
app = await getApp();
|
|
22
22
|
agent = app.agent();
|
|
23
23
|
db = app.db;
|
|
24
|
-
plugin = <Plugin>app.getPlugin('
|
|
24
|
+
plugin = <Plugin>app.getPlugin('verification');
|
|
25
25
|
VerificationModel = db.getCollection('verifications').model;
|
|
26
26
|
AuthorModel = db.getCollection('authors').model;
|
|
27
27
|
AuthorRepo = db.getCollection('authors').repository;
|
package/src/__tests__/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { MockServer, mockServer } from '@nocobase/test';
|
|
2
|
+
import path from 'path';
|
|
3
3
|
|
|
4
|
-
import Plugin from '..';
|
|
5
4
|
import { ApplicationOptions } from '@nocobase/server';
|
|
5
|
+
import Plugin from '..';
|
|
6
6
|
|
|
7
7
|
export function sleep(ms: number) {
|
|
8
8
|
return new Promise(resolve => {
|
|
@@ -17,7 +17,7 @@ interface MockAppOptions extends ApplicationOptions {
|
|
|
17
17
|
export async function getApp({ manual, ...options }: MockAppOptions = {}): Promise<MockServer> {
|
|
18
18
|
const app = mockServer(options);
|
|
19
19
|
|
|
20
|
-
app.plugin(Plugin);
|
|
20
|
+
app.plugin(Plugin, { name: 'verification' });
|
|
21
21
|
|
|
22
22
|
await app.load();
|
|
23
23
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { promisify } from 'util';
|
|
2
1
|
import { randomInt, randomUUID } from 'crypto';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
3
|
|
|
4
|
-
import { Op } from '@nocobase/database';
|
|
5
4
|
import actions, { Context, Next } from '@nocobase/actions';
|
|
5
|
+
import { Op } from '@nocobase/database';
|
|
6
6
|
|
|
7
|
+
import moment from 'moment';
|
|
7
8
|
import Plugin, { namespace } from '..';
|
|
8
9
|
import { CODE_STATUS_UNUSED } from '../constants';
|
|
9
|
-
import moment from 'moment';
|
|
10
10
|
|
|
11
11
|
const asyncRandomInt = promisify(randomInt);
|
|
12
12
|
|
|
13
13
|
export async function create(context: Context, next: Next) {
|
|
14
|
-
const plugin = context.app.getPlugin('
|
|
14
|
+
const plugin = context.app.getPlugin('verification') as Plugin;
|
|
15
15
|
|
|
16
16
|
const { values } = context.action.params;
|
|
17
17
|
const interceptor = plugin.interceptors.get(values?.type);
|