@innet/server 2.0.0-alpha.2 → 2.0.0-alpha.20
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/README.md +1105 -403
- package/example/requests/index.d.ts +1 -1
- package/example/requests/todo/AddTodo/AddTodo.d.ts +1 -0
- package/example/requests/todo/AddTodo/index.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +1 -0
- package/example/requests/todo/DeleteTodo/index.d.ts +1 -0
- package/example/requests/todo/EditTodo/EditTodo.d.ts +1 -0
- package/example/requests/todo/EditTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodo/GetTodo.d.ts +1 -0
- package/example/requests/todo/GetTodo/index.d.ts +1 -0
- package/example/requests/todo/GetTodos/GetTodos.d.ts +1 -0
- package/example/requests/todo/GetTodos/index.d.ts +1 -0
- package/example/requests/todo/index.d.ts +5 -0
- package/example/requests/todo/todos.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +1 -0
- package/example/schemas/app/ListQueryParams/index.d.ts +1 -0
- package/example/schemas/app/ListSchema/ListSchema.d.ts +4 -1
- package/example/schemas/app/index.d.ts +1 -0
- package/example/schemas/index.d.ts +1 -3
- package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +4 -0
- package/example/schemas/todo/TodoSchema/index.d.ts +1 -0
- package/example/schemas/todo/index.d.ts +1 -0
- package/example/tags/Todo/Todo.d.ts +1 -0
- package/example/tags/Todo/index.d.ts +1 -0
- package/example/tags/index.d.ts +1 -1
- package/handler/handler.d.ts +11 -3
- package/handler/handler.es6.js +10 -2
- package/handler/handler.js +10 -2
- package/hooks/index.d.ts +4 -0
- package/hooks/index.es6.js +4 -0
- package/hooks/index.js +4 -0
- package/hooks/useAction/useAction.es6.js +1 -1
- package/hooks/useAction/useAction.js +1 -1
- package/hooks/useApi/useApi.d.ts +1 -3
- package/hooks/useClientIp/index.d.ts +1 -0
- package/hooks/useClientIp/index.es6.js +1 -0
- package/hooks/useClientIp/index.js +9 -0
- package/hooks/useClientIp/useClientIp.d.ts +1 -0
- package/hooks/useClientIp/useClientIp.es6.js +9 -0
- package/hooks/useClientIp/useClientIp.js +13 -0
- package/hooks/useComponentName/useComponentName.d.ts +1 -1
- package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
- package/hooks/useEndpoint/useEndpoint.js +3 -1
- package/hooks/useObjectSchemaContext/index.d.ts +1 -0
- package/hooks/useObjectSchemaContext/index.es6.js +1 -0
- package/hooks/useObjectSchemaContext/index.js +10 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.d.ts +3 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.es6.js +14 -0
- package/hooks/useObjectSchemaContext/useObjectSchemaContext.js +19 -0
- package/hooks/useRequest/index.es6.js +1 -1
- package/hooks/useRequest/index.js +0 -1
- package/hooks/useRequest/useRequest.d.ts +1 -4
- package/hooks/useRequest/useRequest.es6.js +4 -4
- package/hooks/useRequest/useRequest.js +3 -4
- package/hooks/useResponse/index.es6.js +1 -1
- package/hooks/useResponse/index.js +0 -1
- package/hooks/useResponse/useResponse.d.ts +1 -4
- package/hooks/useResponse/useResponse.es6.js +4 -4
- package/hooks/useResponse/useResponse.js +3 -4
- package/hooks/useSchemaType/useSchemaType.d.ts +3 -2
- package/hooks/useSchemaType/useSchemaType.es6.js +2 -3
- package/hooks/useSchemaType/useSchemaType.js +2 -3
- package/hooks/useServer/useServer.d.ts +1 -0
- package/hooks/useServer/useServer.es6.js +3 -1
- package/hooks/useServer/useServer.js +3 -1
- package/hooks/useServerPlugin/index.d.ts +1 -0
- package/hooks/useServerPlugin/index.es6.js +1 -0
- package/hooks/useServerPlugin/index.js +9 -0
- package/hooks/useServerPlugin/useServerPlugin.d.ts +2 -0
- package/hooks/useServerPlugin/useServerPlugin.es6.js +13 -0
- package/hooks/useServerPlugin/useServerPlugin.js +17 -0
- package/hooks/useServerPlugins/index.d.ts +1 -0
- package/hooks/useServerPlugins/index.es6.js +1 -0
- package/hooks/useServerPlugins/index.js +10 -0
- package/hooks/useServerPlugins/useServerPlugins.d.ts +4 -0
- package/hooks/useServerPlugins/useServerPlugins.es6.js +14 -0
- package/hooks/useServerPlugins/useServerPlugins.js +19 -0
- package/index.es6.js +13 -5
- package/index.js +24 -6
- package/package.json +2 -2
- package/plugins/main/api/api.d.ts +2 -0
- package/plugins/main/api/api.es6.js +49 -51
- package/plugins/main/api/api.js +49 -51
- package/plugins/main/endpoint/endpoint.es6.js +4 -1
- package/plugins/main/endpoint/endpoint.js +4 -1
- package/plugins/main/index.d.ts +1 -1
- package/plugins/main/index.es6.js +1 -1
- package/plugins/main/index.js +1 -1
- package/plugins/main/preset/index.d.ts +1 -0
- package/plugins/main/preset/index.es6.js +1 -0
- package/{utils/rules/any/any.js → plugins/main/preset/index.js} +4 -4
- package/plugins/main/preset/preset.d.ts +3 -0
- package/plugins/main/preset/preset.es6.js +13 -0
- package/plugins/main/preset/preset.js +21 -0
- package/plugins/main/request/request.es6.js +2 -13
- package/plugins/main/request/request.js +2 -13
- package/plugins/main/response/index.es6.js +1 -1
- package/plugins/main/response/index.js +1 -0
- package/plugins/main/response/response.d.ts +6 -2
- package/plugins/main/response/response.es6.js +16 -8
- package/plugins/main/response/response.js +16 -7
- package/plugins/main/server/server.d.ts +3 -3
- package/plugins/main/server/server.es6.js +29 -7
- package/plugins/main/server/server.js +29 -7
- package/plugins/main/tag/tag.es6.js +4 -1
- package/plugins/main/tag/tag.js +4 -1
- package/plugins/request/cms/cms.es6.js +1 -1
- package/plugins/request/cms/cms.js +1 -1
- package/plugins/request/cookie/cookie.es6.js +3 -19
- package/plugins/request/cookie/cookie.js +3 -23
- package/plugins/request/proxy/proxy.d.ts +3 -0
- package/plugins/request/proxy/proxy.es6.js +4 -1
- package/plugins/request/proxy/proxy.js +4 -1
- package/plugins/request/redirect/redirect.d.ts +2 -1
- package/plugins/request/success/success.d.ts +1 -0
- package/plugins/request/success/success.es6.js +13 -4
- package/plugins/request/success/success.js +13 -4
- package/plugins/schema/any/any.d.ts +5 -0
- package/plugins/schema/any/any.es6.js +27 -0
- package/plugins/schema/any/any.js +31 -0
- package/plugins/schema/boolean/boolean.es6.js +2 -4
- package/plugins/schema/boolean/boolean.js +1 -3
- package/plugins/schema/field/field.es6.js +3 -5
- package/plugins/schema/field/field.js +2 -4
- package/plugins/schema/index.d.ts +1 -0
- package/plugins/schema/index.es6.js +1 -0
- package/plugins/schema/index.js +1 -0
- package/plugins/schema/object/object.es6.js +17 -4
- package/plugins/schema/object/object.js +17 -4
- package/plugins/utils/blacklist/blacklist.d.ts +4 -0
- package/plugins/utils/blacklist/blacklist.es6.js +18 -0
- package/plugins/utils/blacklist/blacklist.js +22 -0
- package/plugins/utils/blacklist/index.d.ts +1 -0
- package/plugins/utils/blacklist/index.es6.js +1 -0
- package/plugins/utils/blacklist/index.js +9 -0
- package/plugins/utils/dts/dts.d.ts +3 -3
- package/plugins/utils/dts/dts.es6.js +6 -25
- package/plugins/utils/dts/dts.js +5 -29
- package/plugins/utils/index.d.ts +3 -0
- package/plugins/utils/index.es6.js +3 -0
- package/plugins/utils/index.js +3 -0
- package/plugins/utils/protection/index.d.ts +1 -0
- package/plugins/utils/protection/index.es6.js +1 -0
- package/plugins/utils/protection/index.js +9 -0
- package/plugins/utils/protection/protection.d.ts +8 -0
- package/plugins/utils/protection/protection.es6.js +36 -0
- package/plugins/utils/protection/protection.js +40 -0
- package/plugins/utils/swagger/swagger.es6.js +10 -12
- package/plugins/utils/swagger/swagger.js +10 -12
- package/plugins/utils/whitelist/index.d.ts +1 -0
- package/plugins/utils/whitelist/index.es6.js +1 -0
- package/plugins/utils/whitelist/index.js +9 -0
- package/plugins/utils/whitelist/whitelist.d.ts +4 -0
- package/plugins/utils/whitelist/whitelist.es6.js +20 -0
- package/plugins/utils/whitelist/whitelist.js +24 -0
- package/types.d.ts +2 -10
- package/utils/action/Action.d.ts +7 -4
- package/utils/action/Action.es6.js +35 -11
- package/utils/action/Action.js +36 -12
- package/utils/generateTypes/generateTypes.d.ts +3 -0
- package/utils/generateTypes/generateTypes.es6.js +151 -0
- package/utils/generateTypes/generateTypes.js +156 -0
- package/utils/generateTypes/generateTypes.test.d.ts +1 -0
- package/utils/generateTypes/index.d.ts +1 -0
- package/utils/generateTypes/index.es6.js +1 -0
- package/utils/generateTypes/index.js +10 -0
- package/utils/getEndpoint/getEndpoint.es6.js +2 -2
- package/utils/getEndpoint/getEndpoint.js +2 -2
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +1 -0
- package/utils/rules/index.d.ts +0 -1
- package/utils/rules/index.es6.js +0 -1
- package/utils/rules/index.js +0 -1
- package/utils/rules/objectOf/objectOf.d.ts +1 -1
- package/utils/rules/objectOf/objectOf.es6.js +15 -2
- package/utils/rules/objectOf/objectOf.js +15 -2
- package/example/requests/partners/EditPartner/EditPartner.d.ts +0 -1
- package/example/requests/partners/EditPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartner/GetPartner.d.ts +0 -1
- package/example/requests/partners/GetPartner/index.d.ts +0 -1
- package/example/requests/partners/GetPartners/GetPartners.d.ts +0 -1
- package/example/requests/partners/GetPartners/index.d.ts +0 -1
- package/example/requests/partners/index.d.ts +0 -3
- package/example/schemas/address/AddressSchema/AddressSchema.d.ts +0 -1
- package/example/schemas/address/AddressSchema/index.d.ts +0 -1
- package/example/schemas/address/index.d.ts +0 -1
- package/example/schemas/location/LocationSchema/LocationSchema.d.ts +0 -1
- package/example/schemas/location/LocationSchema/index.d.ts +0 -1
- package/example/schemas/location/index.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/EditPartnerSchema.d.ts +0 -1
- package/example/schemas/partner/EditPartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/PartnerSchema.d.ts +0 -1
- package/example/schemas/partner/PartnerSchema/index.d.ts +0 -1
- package/example/schemas/partner/index.d.ts +0 -2
- package/example/tags/Partner/Partner.d.ts +0 -1
- package/example/tags/Partner/index.d.ts +0 -1
- package/plugins/main/fallback/fallback.d.ts +0 -4
- package/plugins/main/fallback/fallback.es6.js +0 -19
- package/plugins/main/fallback/fallback.js +0 -23
- package/plugins/main/fallback/index.d.ts +0 -1
- package/plugins/main/fallback/index.es6.js +0 -1
- package/plugins/main/fallback/index.js +0 -9
- package/utils/rules/any/any.d.ts +0 -1
- package/utils/rules/any/any.es6.js +0 -5
- /package/{utils/rules → plugins/schema}/any/index.d.ts +0 -0
- /package/{utils/rules → plugins/schema}/any/index.es6.js +0 -0
- /package/{utils/rules → plugins/schema}/any/index.js +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsx = require('@innet/jsx');
|
|
6
|
+
require('../../../hooks/index.js');
|
|
7
|
+
var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
|
|
8
|
+
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
9
|
+
|
|
10
|
+
function blacklist() {
|
|
11
|
+
const { ip = process.env.INNET_BLACKLIST_IP, } = jsx.useProps() || {};
|
|
12
|
+
const children = jsx.useChildren();
|
|
13
|
+
const ips = typeof ip === 'string' ? ip.split(',') : ip;
|
|
14
|
+
useServerPlugin.useServerPlugin(() => {
|
|
15
|
+
const action = useAction.useAction();
|
|
16
|
+
if (!action.clientIp || (ips === null || ips === void 0 ? void 0 : ips.includes(action.clientIp))) {
|
|
17
|
+
return children;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.blacklist = blacklist;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './blacklist';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { blacklist } from './blacklist.es6.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HandlerPlugin } from 'innet';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export interface DtsProps {
|
|
3
|
+
path?: string;
|
|
4
|
+
namespace?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare const dts: HandlerPlugin;
|
|
@@ -1,34 +1,15 @@
|
|
|
1
|
-
import { __rest, __awaiter } from 'tslib';
|
|
2
1
|
import { useProps } from '@innet/jsx';
|
|
3
|
-
import
|
|
4
|
-
import fs from 'node:fs';
|
|
2
|
+
import { promises } from 'node:fs';
|
|
5
3
|
import '../../../hooks/index.es6.js';
|
|
4
|
+
import '../../../utils/index.es6.js';
|
|
6
5
|
import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
6
|
+
import { generateTypes } from '../../../utils/generateTypes/generateTypes.es6.js';
|
|
7
7
|
|
|
8
8
|
const dts = () => {
|
|
9
|
-
const
|
|
9
|
+
const { path = process.env.INNET_DTS_PATH || 'src/apiTypes.d.ts', namespace = process.env.INNET_DTS_NAMESPACE, } = useProps() || {};
|
|
10
10
|
const { docs } = useApi();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
config,
|
|
14
|
-
}).then((content) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
yield fs.promises.writeFile(path, `interface Bin {
|
|
16
|
-
filename: string
|
|
17
|
-
fieldName: string
|
|
18
|
-
originalFilename: string
|
|
19
|
-
path: string
|
|
20
|
-
type: string
|
|
21
|
-
disposition: string
|
|
22
|
-
size: number
|
|
23
|
-
extension?: string
|
|
24
|
-
}
|
|
25
|
-
${content
|
|
26
|
-
.replaceAll(';', '')
|
|
27
|
-
.replaceAll('number // int64', 'bigint')
|
|
28
|
-
.replaceAll('string // binary', 'Bin')
|
|
29
|
-
.replaceAll('string // date-time', 'Date')}`);
|
|
30
|
-
})).catch(error => {
|
|
31
|
-
console.warn(error);
|
|
11
|
+
promises.writeFile(path, generateTypes(docs, namespace)).catch(e => {
|
|
12
|
+
console.error(e);
|
|
32
13
|
});
|
|
33
14
|
};
|
|
34
15
|
|
package/plugins/utils/dts/dts.js
CHANGED
|
@@ -2,42 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib = require('tslib');
|
|
6
5
|
var jsx = require('@innet/jsx');
|
|
7
|
-
var dtsGenerator = require('dtsgenerator');
|
|
8
6
|
var fs = require('node:fs');
|
|
9
7
|
require('../../../hooks/index.js');
|
|
8
|
+
require('../../../utils/index.js');
|
|
10
9
|
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
11
|
-
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
-
|
|
14
|
-
var dtsGenerator__default = /*#__PURE__*/_interopDefaultLegacy(dtsGenerator);
|
|
15
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
10
|
+
var generateTypes = require('../../../utils/generateTypes/generateTypes.js');
|
|
16
11
|
|
|
17
12
|
const dts = () => {
|
|
18
|
-
const
|
|
13
|
+
const { path = process.env.INNET_DTS_PATH || 'src/apiTypes.d.ts', namespace = process.env.INNET_DTS_NAMESPACE, } = jsx.useProps() || {};
|
|
19
14
|
const { docs } = useApi.useApi();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
config,
|
|
23
|
-
}).then((content) => tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
yield fs__default["default"].promises.writeFile(path, `interface Bin {
|
|
25
|
-
filename: string
|
|
26
|
-
fieldName: string
|
|
27
|
-
originalFilename: string
|
|
28
|
-
path: string
|
|
29
|
-
type: string
|
|
30
|
-
disposition: string
|
|
31
|
-
size: number
|
|
32
|
-
extension?: string
|
|
33
|
-
}
|
|
34
|
-
${content
|
|
35
|
-
.replaceAll(';', '')
|
|
36
|
-
.replaceAll('number // int64', 'bigint')
|
|
37
|
-
.replaceAll('string // binary', 'Bin')
|
|
38
|
-
.replaceAll('string // date-time', 'Date')}`);
|
|
39
|
-
})).catch(error => {
|
|
40
|
-
console.warn(error);
|
|
15
|
+
fs.promises.writeFile(path, generateTypes.generateTypes(docs, namespace)).catch(e => {
|
|
16
|
+
console.error(e);
|
|
41
17
|
});
|
|
42
18
|
};
|
|
43
19
|
|
package/plugins/utils/index.d.ts
CHANGED
package/plugins/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './protection';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { protection } from './protection.es6.js';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useProps, useChildren } from '@innet/jsx';
|
|
2
|
+
import '../../../hooks/index.es6.js';
|
|
3
|
+
import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
|
|
4
|
+
import { useAction } from '../../../hooks/useAction/useAction.es6.js';
|
|
5
|
+
|
|
6
|
+
function protection() {
|
|
7
|
+
const { maxAge = Number(process.env.INNET_PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, value = process.env.INNET_PROTECTION, excludeIp = process.env.INNET_PROTECTED_IP, cookieKey = process.env.INNET_PROTECTION_COOKIE_KEY || 'protection', searchKey = process.env.INNET_PROTECTION_SEARCH_KEY || 'protection', } = useProps() || {};
|
|
8
|
+
const children = useChildren();
|
|
9
|
+
if (!value)
|
|
10
|
+
return;
|
|
11
|
+
const excludeIps = Array.isArray(excludeIp) ? excludeIp : excludeIp === null || excludeIp === void 0 ? void 0 : excludeIp.split(',');
|
|
12
|
+
useServerPlugin(() => {
|
|
13
|
+
const action = useAction();
|
|
14
|
+
if (!action.clientIp)
|
|
15
|
+
return children;
|
|
16
|
+
if (excludeIps === null || excludeIps === void 0 ? void 0 : excludeIps.includes(action.clientIp))
|
|
17
|
+
return;
|
|
18
|
+
const { [cookieKey]: cookieProtection } = action.cookies;
|
|
19
|
+
if (cookieProtection && cookieProtection === value)
|
|
20
|
+
return;
|
|
21
|
+
const { [searchKey]: searchProtection } = action.search;
|
|
22
|
+
if (searchProtection && searchProtection === value) {
|
|
23
|
+
action.setCookie(cookieKey, value, {
|
|
24
|
+
maxAge,
|
|
25
|
+
httpOnly: true,
|
|
26
|
+
secure: true,
|
|
27
|
+
path: '/',
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
action.setCookie(cookieKey);
|
|
32
|
+
return children;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { protection };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsx = require('@innet/jsx');
|
|
6
|
+
require('../../../hooks/index.js');
|
|
7
|
+
var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
|
|
8
|
+
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
9
|
+
|
|
10
|
+
function protection() {
|
|
11
|
+
const { maxAge = Number(process.env.INNET_PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, value = process.env.INNET_PROTECTION, excludeIp = process.env.INNET_PROTECTED_IP, cookieKey = process.env.INNET_PROTECTION_COOKIE_KEY || 'protection', searchKey = process.env.INNET_PROTECTION_SEARCH_KEY || 'protection', } = jsx.useProps() || {};
|
|
12
|
+
const children = jsx.useChildren();
|
|
13
|
+
if (!value)
|
|
14
|
+
return;
|
|
15
|
+
const excludeIps = Array.isArray(excludeIp) ? excludeIp : excludeIp === null || excludeIp === void 0 ? void 0 : excludeIp.split(',');
|
|
16
|
+
useServerPlugin.useServerPlugin(() => {
|
|
17
|
+
const action = useAction.useAction();
|
|
18
|
+
if (!action.clientIp)
|
|
19
|
+
return children;
|
|
20
|
+
if (excludeIps === null || excludeIps === void 0 ? void 0 : excludeIps.includes(action.clientIp))
|
|
21
|
+
return;
|
|
22
|
+
const { [cookieKey]: cookieProtection } = action.cookies;
|
|
23
|
+
if (cookieProtection && cookieProtection === value)
|
|
24
|
+
return;
|
|
25
|
+
const { [searchKey]: searchProtection } = action.search;
|
|
26
|
+
if (searchProtection && searchProtection === value) {
|
|
27
|
+
action.setCookie(cookieKey, value, {
|
|
28
|
+
maxAge,
|
|
29
|
+
httpOnly: true,
|
|
30
|
+
secure: true,
|
|
31
|
+
path: '/',
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
action.setCookie(cookieKey);
|
|
36
|
+
return children;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.protection = protection;
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { useProps } from '@innet/jsx';
|
|
2
|
-
import { onDestroy } from 'watch-state';
|
|
3
2
|
import '../../../hooks/index.es6.js';
|
|
4
3
|
import html from './swagger.html.es6.js';
|
|
5
4
|
import { useApi } from '../../../hooks/useApi/useApi.es6.js';
|
|
5
|
+
import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
|
|
6
|
+
import { useAction } from '../../../hooks/useAction/useAction.es6.js';
|
|
6
7
|
|
|
7
8
|
const swagger = () => {
|
|
8
|
-
const { path = '/swagger-ui' } = useProps() || {};
|
|
9
|
-
const { docs,
|
|
9
|
+
const { path = process.env.INNET_SWAGGER_PATH || '/swagger-ui', } = useProps() || {};
|
|
10
|
+
const { docs, prefix } = useApi();
|
|
10
11
|
let swaggerResponse;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
useServerPlugin(() => {
|
|
13
|
+
const action = useAction();
|
|
14
|
+
if (action.path === prefix + path) {
|
|
13
15
|
if (!swaggerResponse) {
|
|
14
16
|
swaggerResponse = html.replace('spec: {},', `spec: ${JSON.stringify(docs)},`);
|
|
15
17
|
}
|
|
16
|
-
res.statusCode = 200;
|
|
17
|
-
res.write(swaggerResponse);
|
|
18
|
-
res.end();
|
|
18
|
+
action.res.statusCode = 200;
|
|
19
|
+
action.res.write(swaggerResponse);
|
|
20
|
+
action.res.end();
|
|
19
21
|
return true;
|
|
20
22
|
}
|
|
21
|
-
};
|
|
22
|
-
requestPlugins.add(listener);
|
|
23
|
-
onDestroy(() => {
|
|
24
|
-
requestPlugins.delete(listener);
|
|
25
23
|
});
|
|
26
24
|
};
|
|
27
25
|
|
|
@@ -3,29 +3,27 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var jsx = require('@innet/jsx');
|
|
6
|
-
var watchState = require('watch-state');
|
|
7
6
|
require('../../../hooks/index.js');
|
|
8
7
|
var swagger$1 = require('./swagger.html.js');
|
|
9
8
|
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
9
|
+
var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
|
|
10
|
+
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
10
11
|
|
|
11
12
|
const swagger = () => {
|
|
12
|
-
const { path = '/swagger-ui' } = jsx.useProps() || {};
|
|
13
|
-
const { docs,
|
|
13
|
+
const { path = process.env.INNET_SWAGGER_PATH || '/swagger-ui', } = jsx.useProps() || {};
|
|
14
|
+
const { docs, prefix } = useApi.useApi();
|
|
14
15
|
let swaggerResponse;
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
useServerPlugin.useServerPlugin(() => {
|
|
17
|
+
const action = useAction.useAction();
|
|
18
|
+
if (action.path === prefix + path) {
|
|
17
19
|
if (!swaggerResponse) {
|
|
18
20
|
swaggerResponse = swagger$1["default"].replace('spec: {},', `spec: ${JSON.stringify(docs)},`);
|
|
19
21
|
}
|
|
20
|
-
res.statusCode = 200;
|
|
21
|
-
res.write(swaggerResponse);
|
|
22
|
-
res.end();
|
|
22
|
+
action.res.statusCode = 200;
|
|
23
|
+
action.res.write(swaggerResponse);
|
|
24
|
+
action.res.end();
|
|
23
25
|
return true;
|
|
24
26
|
}
|
|
25
|
-
};
|
|
26
|
-
requestPlugins.add(listener);
|
|
27
|
-
watchState.onDestroy(() => {
|
|
28
|
-
requestPlugins.delete(listener);
|
|
29
27
|
});
|
|
30
28
|
};
|
|
31
29
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './whitelist';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { whitelist } from './whitelist.es6.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useProps, useChildren } from '@innet/jsx';
|
|
2
|
+
import '../../../hooks/index.es6.js';
|
|
3
|
+
import { useServerPlugin } from '../../../hooks/useServerPlugin/useServerPlugin.es6.js';
|
|
4
|
+
import { useAction } from '../../../hooks/useAction/useAction.es6.js';
|
|
5
|
+
|
|
6
|
+
function whitelist() {
|
|
7
|
+
const { ip = process.env.INNET_WHITELIST_IP, } = useProps() || {};
|
|
8
|
+
const children = useChildren();
|
|
9
|
+
const ips = typeof ip === 'string' ? ip.split(',') : ip;
|
|
10
|
+
if (!ips)
|
|
11
|
+
return;
|
|
12
|
+
useServerPlugin(() => {
|
|
13
|
+
const action = useAction();
|
|
14
|
+
if (!action.clientIp || !ips.includes(action.clientIp)) {
|
|
15
|
+
return children;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { whitelist };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsx = require('@innet/jsx');
|
|
6
|
+
require('../../../hooks/index.js');
|
|
7
|
+
var useServerPlugin = require('../../../hooks/useServerPlugin/useServerPlugin.js');
|
|
8
|
+
var useAction = require('../../../hooks/useAction/useAction.js');
|
|
9
|
+
|
|
10
|
+
function whitelist() {
|
|
11
|
+
const { ip = process.env.INNET_WHITELIST_IP, } = jsx.useProps() || {};
|
|
12
|
+
const children = jsx.useChildren();
|
|
13
|
+
const ips = typeof ip === 'string' ? ip.split(',') : ip;
|
|
14
|
+
if (!ips)
|
|
15
|
+
return;
|
|
16
|
+
useServerPlugin.useServerPlugin(() => {
|
|
17
|
+
const action = useAction.useAction();
|
|
18
|
+
if (!action.clientIp || !ips.includes(action.clientIp)) {
|
|
19
|
+
return children;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.whitelist = whitelist;
|
package/types.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import type { Handler } from 'innet';
|
|
4
1
|
import type { OpenAPIV3_1 as API } from 'openapi-types';
|
|
5
2
|
import type { ApiErrorValue } from './constants';
|
|
3
|
+
import { type ServerPlugin } from './hooks';
|
|
6
4
|
import { type Rule, type RulesErrors } from './utils/rules';
|
|
7
5
|
export type TagObject = API.TagObject;
|
|
8
6
|
export type Document = API.Document;
|
|
@@ -38,10 +36,9 @@ export interface EndpointRulesMaps {
|
|
|
38
36
|
}
|
|
39
37
|
export interface Endpoint<I = unknown, O = unknown, E extends ApiErrorValue = ApiErrorValue, P extends InValidationErrorParam = InValidationErrorParam, D extends ValidationErrorData = ValidationErrorData> {
|
|
40
38
|
key: string;
|
|
41
|
-
|
|
39
|
+
plugins: Set<ServerPlugin>;
|
|
42
40
|
rules?: EndpointRules;
|
|
43
41
|
rulesMaps?: EndpointRulesMaps;
|
|
44
|
-
handler?: Handler;
|
|
45
42
|
static?: Record<string, Endpoint<I, O, E, P, D>>;
|
|
46
43
|
dynamic?: Endpoint<I, O, E, P, D>[];
|
|
47
44
|
}
|
|
@@ -69,8 +66,3 @@ export interface BaseSchemaProps<T> {
|
|
|
69
66
|
export interface ValuesSchemaProps<T> extends BaseSchemaProps<T> {
|
|
70
67
|
values?: T[];
|
|
71
68
|
}
|
|
72
|
-
export interface Fallback {
|
|
73
|
-
children: any;
|
|
74
|
-
handler: Handler;
|
|
75
|
-
}
|
|
76
|
-
export type RequestPlugin = (req: IncomingMessage, res: ServerResponse) => boolean | undefined;
|
package/utils/action/Action.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type
|
|
3
|
-
import { type IncomingHttpHeaders } from 'http';
|
|
2
|
+
import { type CookieSerializeOptions } from 'cookie';
|
|
3
|
+
import { type IncomingHttpHeaders, type IncomingMessage, type ServerResponse } from 'http';
|
|
4
4
|
import { type ParsedQs } from 'qs';
|
|
5
5
|
import { type BodyType } from '../../types';
|
|
6
6
|
export declare const URL_PARSER: RegExp;
|
|
@@ -10,8 +10,9 @@ export interface ParsedUrl {
|
|
|
10
10
|
}
|
|
11
11
|
export declare class Action {
|
|
12
12
|
#private;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
readonly req: IncomingMessage;
|
|
14
|
+
readonly res: ServerResponse;
|
|
15
|
+
constructor(req: IncomingMessage, res: ServerResponse);
|
|
15
16
|
get parsedUrl(): ParsedUrl;
|
|
16
17
|
get path(): string;
|
|
17
18
|
get originSearch(): ParsedQs;
|
|
@@ -26,4 +27,6 @@ export declare class Action {
|
|
|
26
27
|
get bodyType(): BodyType | undefined;
|
|
27
28
|
body?: object;
|
|
28
29
|
parseBody(): Promise<void>;
|
|
30
|
+
setCookie(name: string, value?: string, options?: CookieSerializeOptions): void;
|
|
31
|
+
get clientIp(): string | null;
|
|
29
32
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __runInitializers, __classPrivateFieldGet, __classPrivateFieldSet, __awaiter, __esDecorate } from 'tslib';
|
|
2
|
-
import
|
|
2
|
+
import cookieLib from 'cookie';
|
|
3
|
+
import { getClientIp } from 'request-ip';
|
|
3
4
|
import '../decorators/index.es6.js';
|
|
4
5
|
import '../parseBody/index.es6.js';
|
|
5
6
|
import '../parseFormBody/index.es6.js';
|
|
@@ -19,16 +20,18 @@ let Action = (() => {
|
|
|
19
20
|
let _get_originCookies_decorators;
|
|
20
21
|
let _get_bodyType_decorators;
|
|
21
22
|
let _parseBody_decorators;
|
|
23
|
+
let _get_clientIp_decorators;
|
|
22
24
|
return _a = class Action {
|
|
23
|
-
constructor(req) {
|
|
25
|
+
constructor(req, res) {
|
|
24
26
|
this.req = (__runInitializers(this, _instanceExtraInitializers), req);
|
|
27
|
+
this.res = res;
|
|
25
28
|
_Action_search.set(this, void 0);
|
|
26
29
|
_Action_headers.set(this, {});
|
|
27
30
|
_Action_cookie.set(this, {});
|
|
28
31
|
}
|
|
29
32
|
get parsedUrl() {
|
|
30
|
-
var
|
|
31
|
-
const match = (
|
|
33
|
+
var _b;
|
|
34
|
+
const match = (_b = this.req.url) === null || _b === void 0 ? void 0 : _b.match(URL_PARSER);
|
|
32
35
|
if (!match)
|
|
33
36
|
throw Error('cannot parse url');
|
|
34
37
|
const result = match.groups;
|
|
@@ -65,8 +68,8 @@ let Action = (() => {
|
|
|
65
68
|
__classPrivateFieldSet(this, _Action_headers, value, "f");
|
|
66
69
|
}
|
|
67
70
|
get originCookies() {
|
|
68
|
-
var
|
|
69
|
-
return
|
|
71
|
+
var _b;
|
|
72
|
+
return cookieLib.parse((_b = this.req.headers.cookie) !== null && _b !== void 0 ? _b : '');
|
|
70
73
|
}
|
|
71
74
|
get cookies() {
|
|
72
75
|
if (__classPrivateFieldGet(this, _Action_cookie, "f"))
|
|
@@ -103,21 +106,42 @@ let Action = (() => {
|
|
|
103
106
|
}
|
|
104
107
|
});
|
|
105
108
|
}
|
|
109
|
+
setCookie(name, value, options) {
|
|
110
|
+
let cookies = this.res.getHeader('Set-Cookie');
|
|
111
|
+
if (typeof cookies === 'string') {
|
|
112
|
+
cookies = [cookies];
|
|
113
|
+
}
|
|
114
|
+
const normValue = typeof value === 'string' ? cookieLib.serialize(name, value, options) : `${name}=; max-age=0`;
|
|
115
|
+
if (cookies) {
|
|
116
|
+
cookies.push(normValue);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
cookies = normValue;
|
|
120
|
+
}
|
|
121
|
+
this.res.setHeader('Set-Cookie', cookies);
|
|
122
|
+
}
|
|
123
|
+
get clientIp() {
|
|
124
|
+
return getClientIp(this.req);
|
|
125
|
+
}
|
|
106
126
|
},
|
|
107
127
|
_Action_search = new WeakMap(),
|
|
108
128
|
_Action_headers = new WeakMap(),
|
|
109
129
|
_Action_cookie = new WeakMap(),
|
|
110
130
|
(() => {
|
|
131
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
111
132
|
_get_parsedUrl_decorators = [once];
|
|
112
133
|
_get_originSearch_decorators = [once];
|
|
113
134
|
_get_originCookies_decorators = [once];
|
|
114
135
|
_get_bodyType_decorators = [once];
|
|
115
136
|
_parseBody_decorators = [once];
|
|
116
|
-
|
|
117
|
-
__esDecorate(_a, null,
|
|
118
|
-
__esDecorate(_a, null,
|
|
119
|
-
__esDecorate(_a, null,
|
|
120
|
-
__esDecorate(_a, null,
|
|
137
|
+
_get_clientIp_decorators = [once];
|
|
138
|
+
__esDecorate(_a, null, _get_parsedUrl_decorators, { kind: "getter", name: "parsedUrl", static: false, private: false, access: { has: obj => "parsedUrl" in obj, get: obj => obj.parsedUrl }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
139
|
+
__esDecorate(_a, null, _get_originSearch_decorators, { kind: "getter", name: "originSearch", static: false, private: false, access: { has: obj => "originSearch" in obj, get: obj => obj.originSearch }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
140
|
+
__esDecorate(_a, null, _get_originCookies_decorators, { kind: "getter", name: "originCookies", static: false, private: false, access: { has: obj => "originCookies" in obj, get: obj => obj.originCookies }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
141
|
+
__esDecorate(_a, null, _get_bodyType_decorators, { kind: "getter", name: "bodyType", static: false, private: false, access: { has: obj => "bodyType" in obj, get: obj => obj.bodyType }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
142
|
+
__esDecorate(_a, null, _parseBody_decorators, { kind: "method", name: "parseBody", static: false, private: false, access: { has: obj => "parseBody" in obj, get: obj => obj.parseBody }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
143
|
+
__esDecorate(_a, null, _get_clientIp_decorators, { kind: "getter", name: "clientIp", static: false, private: false, access: { has: obj => "clientIp" in obj, get: obj => obj.clientIp }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
144
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
121
145
|
})(),
|
|
122
146
|
_a;
|
|
123
147
|
})();
|