@innet/server 2.0.0-alpha.3 → 2.0.0-alpha.30
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 +1375 -541
- package/handler/handler.d.ts +19 -13
- package/handler/handler.es6.js +17 -11
- package/handler/handler.js +17 -11
- package/hooks/index.d.ts +6 -0
- package/hooks/index.es6.js +6 -0
- package/hooks/index.js +6 -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.d.ts +1 -1
- package/hooks/useEndpoint/useEndpoint.es6.js +3 -1
- package/hooks/useEndpoint/useEndpoint.js +3 -1
- package/hooks/useIsServerHttps/index.d.ts +1 -0
- package/hooks/useIsServerHttps/index.es6.js +1 -0
- package/hooks/useIsServerHttps/index.js +10 -0
- package/hooks/useIsServerHttps/useIsServerHttps.d.ts +3 -0
- package/hooks/useIsServerHttps/useIsServerHttps.es6.js +14 -0
- package/hooks/useIsServerHttps/useIsServerHttps.js +19 -0
- 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 +5 -6
- package/hooks/useSchemaType/useSchemaType.js +5 -6
- package/hooks/useServer/useServer.d.ts +2 -1
- 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/hooks/useServerPort/index.d.ts +1 -0
- package/hooks/useServerPort/index.es6.js +1 -0
- package/hooks/useServerPort/index.js +10 -0
- package/hooks/useServerPort/useServerPort.d.ts +3 -0
- package/hooks/useServerPort/useServerPort.es6.js +14 -0
- package/hooks/useServerPort/useServerPort.js +19 -0
- package/index.es6.js +17 -8
- package/index.js +34 -12
- package/package.json +2 -2
- package/plugins/main/api/api.d.ts +10 -8
- package/plugins/main/api/api.es6.js +53 -55
- package/plugins/main/api/api.js +53 -55
- package/plugins/main/contact/contact.d.ts +2 -2
- package/plugins/main/endpoint/endpoint.d.ts +15 -15
- package/plugins/main/endpoint/endpoint.es6.js +7 -4
- package/plugins/main/endpoint/endpoint.js +7 -4
- package/plugins/main/host/host.d.ts +5 -5
- package/plugins/main/index.d.ts +2 -2
- package/plugins/main/index.es6.js +2 -2
- package/plugins/main/index.js +2 -2
- package/plugins/main/license/license.d.ts +5 -5
- package/plugins/main/param/param.d.ts +11 -11
- package/plugins/main/param/param.es6.js +3 -3
- package/plugins/main/param/param.js +3 -3
- package/plugins/main/preset/index.d.ts +1 -0
- package/plugins/main/preset/index.es6.js +1 -0
- package/plugins/{utils/prod → main/preset}/index.js +2 -2
- package/plugins/main/preset/preset.d.ts +3 -0
- package/plugins/main/preset/preset.es6.js +13 -0
- package/plugins/{utils/dev/dev.js → main/preset/preset.js} +9 -6
- 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 +18 -10
- package/plugins/main/response/response.js +18 -9
- package/plugins/main/return/index.d.ts +1 -0
- package/plugins/main/return/index.es6.js +1 -0
- package/plugins/main/return/index.js +9 -0
- package/plugins/main/return/return.d.ts +4 -0
- package/plugins/main/return/return.es6.js +10 -0
- package/plugins/main/return/return.js +14 -0
- package/plugins/main/server/server.d.ts +5 -5
- package/plugins/main/server/server.es6.js +36 -10
- package/plugins/main/server/server.js +36 -10
- package/plugins/main/tag/tag.d.ts +2 -2
- package/plugins/main/tag/tag.es6.js +5 -2
- package/plugins/main/tag/tag.js +5 -2
- package/plugins/main/variable/variable.d.ts +5 -5
- package/plugins/main/variable/variable.es6.js +3 -1
- package/plugins/main/variable/variable.js +3 -1
- package/plugins/request/cms/cms.es6.js +2 -2
- package/plugins/request/cms/cms.js +2 -2
- package/plugins/request/cookie/cookie.es6.js +3 -19
- package/plugins/request/cookie/cookie.js +3 -23
- package/plugins/request/error/error.d.ts +40 -40
- package/plugins/request/error/error.es6.js +45 -42
- package/plugins/request/error/error.js +45 -42
- package/plugins/request/file/file.es6.js +2 -3
- package/plugins/request/file/file.js +2 -3
- package/plugins/request/header/header.es6.js +1 -1
- package/plugins/request/header/header.js +1 -1
- package/plugins/request/proxy/proxy.d.ts +4 -1
- package/plugins/request/proxy/proxy.es6.js +5 -2
- package/plugins/request/proxy/proxy.js +5 -2
- package/plugins/request/redirect/redirect.d.ts +8 -7
- package/plugins/request/redirect/redirect.es6.js +7 -7
- package/plugins/request/redirect/redirect.js +7 -7
- package/plugins/request/success/success.d.ts +7 -6
- package/plugins/request/success/success.es6.js +21 -10
- package/plugins/request/success/success.js +21 -10
- 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/binary/binary.d.ts +3 -3
- package/plugins/schema/boolean/boolean.es6.js +2 -4
- package/plugins/schema/boolean/boolean.js +1 -3
- package/plugins/schema/date/date.d.ts +1 -1
- package/plugins/schema/date/date.es6.js +3 -3
- package/plugins/schema/date/date.js +3 -3
- package/plugins/schema/field/field.d.ts +1 -0
- package/plugins/schema/field/field.es6.js +7 -6
- package/plugins/schema/field/field.js +6 -5
- 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/integer/integer.d.ts +3 -3
- package/plugins/schema/integer/integer.es6.js +1 -1
- package/plugins/schema/integer/integer.js +1 -1
- package/plugins/schema/number/number.d.ts +2 -2
- package/plugins/schema/number/number.es6.js +1 -1
- package/plugins/schema/number/number.js +1 -1
- package/plugins/schema/object/object.es6.js +17 -4
- package/plugins/schema/object/object.js +17 -4
- package/plugins/schema/string/string.d.ts +2 -2
- package/plugins/schema/string/string.es6.js +44 -30
- package/plugins/schema/string/string.js +44 -30
- 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/env/env.d.ts +6 -0
- package/plugins/utils/env/env.es6.js +11 -0
- package/plugins/utils/{prod/prod.js → env/env.js} +4 -3
- package/plugins/utils/env/index.d.ts +1 -0
- package/plugins/utils/env/index.es6.js +1 -0
- package/plugins/utils/{dev → env}/index.js +2 -2
- package/plugins/utils/index.d.ts +4 -2
- package/plugins/utils/index.es6.js +4 -2
- package/plugins/utils/index.js +4 -2
- 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 +15 -23
- package/utils/FileData/Bin.d.ts +13 -13
- package/utils/FileData/Bin.es6.js +2 -2
- package/utils/FileData/Bin.js +2 -2
- package/utils/action/Action.d.ts +17 -14
- package/utils/action/Action.es6.js +102 -78
- package/utils/action/Action.js +102 -78
- package/utils/dateFormat/dateFormat.d.ts +1 -1
- package/utils/dateFormat/dateFormat.es6.js +1 -1
- package/utils/dateFormat/dateFormat.js +1 -1
- package/utils/generateTypes/generateTypes.d.ts +3 -0
- package/utils/generateTypes/generateTypes.es6.js +157 -0
- package/utils/generateTypes/generateTypes.js +162 -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/getOrAdd/getOrAdd.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.d.ts +1 -1
- package/utils/httpOnStart/httpOnStart.es6.js +1 -1
- package/utils/httpOnStart/httpOnStart.js +1 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.es6.js +1 -0
- package/utils/index.js +1 -0
- package/utils/rules/binaryAccept/binaryAccept.es6.js +2 -2
- package/utils/rules/binaryAccept/binaryAccept.js +2 -2
- package/utils/rules/dateTo/dateTo.d.ts +1 -1
- package/utils/rules/helpers.d.ts +1 -1
- 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/int/int.es6.js +2 -2
- package/utils/rules/int/int.js +2 -2
- package/utils/rules/max/max.d.ts +1 -1
- package/utils/rules/max/max.es6.js +3 -3
- package/utils/rules/max/max.js +3 -3
- package/utils/rules/maxBin/maxBin.es6.js +2 -2
- package/utils/rules/maxBin/maxBin.js +2 -2
- package/utils/rules/maxDate/maxDate.es6.js +1 -1
- package/utils/rules/maxDate/maxDate.js +1 -1
- package/utils/rules/maxLength/maxLength.es6.js +2 -2
- package/utils/rules/maxLength/maxLength.js +2 -2
- package/utils/rules/min/min.d.ts +1 -1
- package/utils/rules/min/min.es6.js +3 -3
- package/utils/rules/min/min.js +3 -3
- package/utils/rules/minBin/minBin.es6.js +2 -2
- package/utils/rules/minBin/minBin.js +2 -2
- package/utils/rules/minDate/minDate.es6.js +1 -1
- package/utils/rules/minDate/minDate.js +1 -1
- package/utils/rules/minLength/minLength.es6.js +2 -2
- package/utils/rules/minLength/minLength.js +2 -2
- 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/utils/rules/pattern/pattern.d.ts +1 -1
- package/utils/rules/pattern/pattern.es6.js +2 -1
- package/utils/rules/pattern/pattern.js +2 -1
- package/example/app/App/App.d.ts +0 -1
- package/example/app/App/index.d.ts +0 -1
- package/example/index.d.ts +0 -1
- package/example/requests/index.d.ts +0 -1
- 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/app/ListSchema/ListSchema.d.ts +0 -1
- package/example/schemas/app/ListSchema/index.d.ts +0 -1
- package/example/schemas/app/index.d.ts +0 -1
- package/example/schemas/index.d.ts +0 -4
- 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/example/tags/index.d.ts +0 -1
- package/openApi.test.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/plugins/main/request/index.d.ts +0 -1
- package/plugins/main/request/index.es6.js +0 -1
- package/plugins/main/request/index.js +0 -9
- package/plugins/main/request/request.d.ts +0 -4
- package/plugins/main/request/request.es6.js +0 -21
- package/plugins/main/request/request.js +0 -25
- package/plugins/utils/dev/dev.d.ts +0 -4
- package/plugins/utils/dev/dev.es6.js +0 -10
- package/plugins/utils/dev/index.d.ts +0 -1
- package/plugins/utils/dev/index.es6.js +0 -1
- package/plugins/utils/prod/index.d.ts +0 -1
- package/plugins/utils/prod/index.es6.js +0 -1
- package/plugins/utils/prod/prod.d.ts +0 -4
- package/plugins/utils/prod/prod.es6.js +0 -10
- package/utils/decorators/once/once.test.d.ts +0 -1
- package/utils/parseSearch/parseSearch.test.d.ts +0 -1
- package/utils/rules/any/any.d.ts +0 -1
- package/utils/rules/any/any.es6.js +0 -5
- package/utils/rules/any/any.js +0 -9
- /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
|
@@ -7,48 +7,62 @@ var jsx = require('@innet/jsx');
|
|
|
7
7
|
require('../../../hooks/index.js');
|
|
8
8
|
require('../../../hooks/useParentRule/index.js');
|
|
9
9
|
require('../../../utils/index.js');
|
|
10
|
+
var useApi = require('../../../hooks/useApi/useApi.js');
|
|
10
11
|
var useSchemaType = require('../../../hooks/useSchemaType/useSchemaType.js');
|
|
11
12
|
var defaultTo = require('../../../utils/rules/defaultTo/defaultTo.js');
|
|
12
13
|
var values = require('../../../utils/rules/values/values.js');
|
|
13
14
|
var minLength = require('../../../utils/rules/minLength/minLength.js');
|
|
14
15
|
var maxLength = require('../../../utils/rules/maxLength/maxLength.js');
|
|
15
16
|
var pattern = require('../../../utils/rules/pattern/pattern.js');
|
|
16
|
-
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
17
17
|
var pipe = require('../../../utils/rules/pipe/pipe.js');
|
|
18
|
+
var useRule = require('../../../hooks/useRule/useRule.js');
|
|
18
19
|
var useParentRule = require('../../../hooks/useParentRule/useParentRule.js');
|
|
19
20
|
|
|
20
21
|
const string = () => {
|
|
21
|
-
const _a = jsx.useProps() || {}, {
|
|
22
|
+
const _a = jsx.useProps() || {}, { max, min, pattern: pattern$1, patternId } = _a, props = tslib.__rest(_a, ["max", "min", "pattern", "patternId"]);
|
|
23
|
+
const { refRules } = useApi.useApi();
|
|
22
24
|
const schema = useSchemaType.useSchemaType('string', props);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
25
|
+
if (schema) {
|
|
26
|
+
const rules = [];
|
|
27
|
+
if (props.default !== undefined) {
|
|
28
|
+
rules.push(defaultTo.defaultTo(props.default));
|
|
29
|
+
}
|
|
30
|
+
rules.push(String);
|
|
31
|
+
if (props.values) {
|
|
32
|
+
rules.push(values.values(props.values));
|
|
33
|
+
}
|
|
34
|
+
if (min !== undefined) {
|
|
35
|
+
schema.minimum = min;
|
|
36
|
+
rules.push(minLength.minLength(min));
|
|
37
|
+
}
|
|
38
|
+
if (max !== undefined) {
|
|
39
|
+
schema.maximum = max;
|
|
40
|
+
rules.push(maxLength.maxLength(max));
|
|
41
|
+
}
|
|
42
|
+
if (pattern$1 !== undefined) {
|
|
43
|
+
schema.pattern = String(pattern$1);
|
|
44
|
+
rules.push(pattern.pattern(pattern$1, patternId));
|
|
45
|
+
}
|
|
46
|
+
const rule = pipe.pipe(...rules);
|
|
47
|
+
if (props.ref) {
|
|
48
|
+
refRules[props.ref] = rule;
|
|
49
|
+
}
|
|
50
|
+
if (props.default) {
|
|
51
|
+
useRule.useRule(rule);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const parentRule = useParentRule.useParentRule();
|
|
55
|
+
useRule.useRule(parentRule(rule));
|
|
56
|
+
}
|
|
48
57
|
}
|
|
49
|
-
else {
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
else if (props.ref) {
|
|
59
|
+
if (props.default) {
|
|
60
|
+
useRule.useRule(refRules[props.ref]);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const parentRule = useParentRule.useParentRule();
|
|
64
|
+
useRule.useRule(parentRule(refRules[props.ref]));
|
|
65
|
+
}
|
|
52
66
|
}
|
|
53
67
|
};
|
|
54
68
|
|
|
@@ -0,0 +1,18 @@
|
|
|
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 blacklist() {
|
|
7
|
+
const { ip = process.env.INNET_BLACKLIST_IP, } = useProps() || {};
|
|
8
|
+
const children = useChildren();
|
|
9
|
+
const ips = typeof ip === 'string' ? ip.split(',') : ip;
|
|
10
|
+
useServerPlugin(() => {
|
|
11
|
+
const action = useAction();
|
|
12
|
+
if (!action.clientIp || (ips === null || ips === void 0 ? void 0 : ips.includes(action.clientIp))) {
|
|
13
|
+
return children;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { blacklist };
|
|
@@ -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
|
-
path
|
|
2
|
+
export interface DtsProps {
|
|
3
|
+
namespace?: string;
|
|
4
|
+
path?: 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 { namespace = process.env.INNET_DTS_NAMESPACE, path = process.env.INNET_DTS_PATH || 'src/apiTypes.d.ts', } = 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 { namespace = process.env.INNET_DTS_NAMESPACE, path = process.env.INNET_DTS_PATH || 'src/apiTypes.d.ts', } = 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
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import innet, { useHandler } from 'innet';
|
|
2
|
+
import { useProps, useChildren } from '@innet/jsx';
|
|
3
|
+
|
|
4
|
+
const env = () => {
|
|
5
|
+
const { is, of = 'NODE_ENV', } = useProps();
|
|
6
|
+
if (Array.isArray(is) ? is.includes(process.env[of]) : process.env[of] === is) {
|
|
7
|
+
innet(useChildren(), useHandler());
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { env };
|
|
@@ -9,10 +9,11 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
9
9
|
|
|
10
10
|
var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
12
|
+
const env = () => {
|
|
13
|
+
const { is, of = 'NODE_ENV', } = jsx.useProps();
|
|
14
|
+
if (Array.isArray(is) ? is.includes(process.env[of]) : process.env[of] === is) {
|
|
14
15
|
innet__default["default"](jsx.useChildren(), innet.useHandler());
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
exports.
|
|
19
|
+
exports.env = env;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './env';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { env } from './env.es6.js';
|
package/plugins/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import './swagger/index.es6.js';
|
|
2
2
|
import './dts/index.es6.js';
|
|
3
|
-
import './
|
|
4
|
-
import './
|
|
3
|
+
import './env/index.es6.js';
|
|
4
|
+
import './protection/index.es6.js';
|
|
5
|
+
import './blacklist/index.es6.js';
|
|
6
|
+
import './whitelist/index.es6.js';
|
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 { cookieKey = process.env.INNET_PROTECTION_COOKIE_KEY || 'protection', excludeIp = process.env.INNET_PROTECTED_IP, maxAge = Number(process.env.INNET_PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, searchKey = process.env.INNET_PROTECTION_SEARCH_KEY || 'protection', value = process.env.INNET_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
|
+
httpOnly: true,
|
|
25
|
+
maxAge,
|
|
26
|
+
path: '/',
|
|
27
|
+
secure: true,
|
|
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 { cookieKey = process.env.INNET_PROTECTION_COOKIE_KEY || 'protection', excludeIp = process.env.INNET_PROTECTED_IP, maxAge = Number(process.env.INNET_PROTECTION_MAX_AGE) || 365 * 24 * 60 * 60, searchKey = process.env.INNET_PROTECTION_SEARCH_KEY || 'protection', value = process.env.INNET_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
|
+
httpOnly: true,
|
|
29
|
+
maxAge,
|
|
30
|
+
path: '/',
|
|
31
|
+
secure: true,
|
|
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;
|