@innet/server 2.0.0-alpha.11 → 2.0.0-alpha.12

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 CHANGED
@@ -319,6 +319,8 @@ This section contains elements of utils.
319
319
  [\<dev>](#dev)
320
320
  [\<prod>](#prod)
321
321
  [\<dts>](#dts)
322
+ [\<blacklist>](#blacklist)
323
+ [\<whitelist>](#whitelist)
322
324
  [\<protection>](#protection)
323
325
 
324
326
  ---
@@ -440,6 +442,88 @@ export function DeleteTodo () {
440
442
  }
441
443
  ```
442
444
 
445
+ ### \<blacklist>
446
+
447
+ This element MUST be placed in `<api>` element.
448
+
449
+ [← back](#utils)
450
+
451
+ This element returns own content for a user from IPs list.
452
+
453
+ *src/app.tsx*
454
+ ```typescript jsx
455
+ export default (
456
+ <server>
457
+ <api>
458
+ <blacklist>
459
+ <error />
460
+ </blacklist>
461
+ </api>
462
+ </server>
463
+ )
464
+ ```
465
+
466
+ #### ip
467
+
468
+ `ip` prop sets black IPs. By default, it equals `BLACKLIST_IP` node environment variable.
469
+
470
+ You can split IPs by `,` char.
471
+
472
+ *src/app.tsx*
473
+ ```typescript jsx
474
+ export default (
475
+ <server>
476
+ <api>
477
+ <blacklist
478
+ ip='0.1.2.3,3.2.1.0'>
479
+ <error />
480
+ </blacklist>
481
+ </api>
482
+ </server>
483
+ )
484
+ ```
485
+
486
+ ### \<whitelist>
487
+
488
+ This element MUST be placed in `<api>` element.
489
+
490
+ [← back](#utils)
491
+
492
+ This element returns own content for a user IP, which is not in a list.
493
+
494
+ *src/app.tsx*
495
+ ```typescript jsx
496
+ export default (
497
+ <server>
498
+ <api>
499
+ <whitelist>
500
+ <error />
501
+ </whitelist>
502
+ </api>
503
+ </server>
504
+ )
505
+ ```
506
+
507
+ #### ip
508
+
509
+ `ip` prop sets white IPs. By default, it equals `WHITELIST_IP` node environment variable.
510
+
511
+ You can split IPs by `,` char.
512
+
513
+ *src/app.tsx*
514
+ ```typescript jsx
515
+ export default (
516
+ <server>
517
+ <api>
518
+ <whitelist
519
+ ip='0.1.2.3,3.2.1.0'>
520
+ <error />
521
+ </whitelist>
522
+ </api>
523
+ </server>
524
+ )
525
+ ```
526
+
443
527
  ### \<protection>
444
528
 
445
529
  This element MUST be placed in `<api>` element.
@@ -1,11 +1,12 @@
1
1
  import { context, type ContextProps, slot, type SlotProps, slots, type SlotsProps } from '@innet/jsx';
2
2
  import { arraySync, async } from '@innet/utils';
3
- import { type ApiProps, type ArrayProps, type BinaryProps, type BodyProps, type BooleanProps, cms, type CmsProps, type ContactProps, type CookieProps, type DateProps, type DevProps, type DtsProps, type EndpointProps, type ErrorProps, type FallbackProps, type FieldProps, file, type FileProps, type HeaderProps, type HostProps, type IntegerProps, type LicenseProps, type NullProps, type NumberProps, type ObjectProps, type ParamProps, type ProdProps, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type RequestProps, type ResponseProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UuidProps, type VariableProps } from '../plugins';
3
+ import { type ApiProps, type ArrayProps, type BinaryProps, blacklist, type BlacklistProps, type BodyProps, type BooleanProps, cms, type CmsProps, type ContactProps, type CookieProps, type DateProps, type DevProps, type DtsProps, type EndpointProps, type ErrorProps, type FallbackProps, type FieldProps, file, type FileProps, type HeaderProps, type HostProps, type IntegerProps, type LicenseProps, type NullProps, type NumberProps, type ObjectProps, type ParamProps, type ProdProps, protection, type ProtectionProps, type ProxyProps, type RedirectProps, type RequestProps, type ResponseProps, type ServerProps, type StringProps, type SuccessProps, type SwaggerProps, type TagProps, type TupleProps, type UuidProps, type VariableProps, whitelist, type WhitelistProps } from '../plugins';
4
4
  export declare const arrayPlugins: (typeof arraySync)[];
5
5
  export declare const JSXPlugins: {
6
6
  api: import("innet").HandlerPlugin;
7
7
  array: import("innet").HandlerPlugin;
8
8
  binary: import("innet").HandlerPlugin;
9
+ blacklist: typeof blacklist;
9
10
  body: import("innet").HandlerPlugin;
10
11
  boolean: import("innet").HandlerPlugin;
11
12
  cms: typeof cms;
@@ -44,6 +45,7 @@ export declare const JSXPlugins: {
44
45
  tuple: import("innet").HandlerPlugin;
45
46
  uuid: import("innet").HandlerPlugin;
46
47
  variable: import("innet").HandlerPlugin;
48
+ whitelist: typeof whitelist;
47
49
  };
48
50
  export declare const fnPlugins: import("innet").Plugin[];
49
51
  export declare const objectPlugins: import("innet").Plugin[];
@@ -55,6 +57,7 @@ declare global {
55
57
  api: ApiProps;
56
58
  array: ArrayProps;
57
59
  binary: BinaryProps;
60
+ blacklist: BlacklistProps;
58
61
  body: BodyProps;
59
62
  boolean: BooleanProps;
60
63
  cms: CmsProps;
@@ -93,6 +96,7 @@ declare global {
93
96
  tuple: TupleProps;
94
97
  uuid: UuidProps;
95
98
  variable: VariableProps;
99
+ whitelist: WhitelistProps;
96
100
  }
97
101
  }
98
102
  }
@@ -5,6 +5,7 @@ import '../plugins/index.es6.js';
5
5
  import { api } from '../plugins/main/api/api.es6.js';
6
6
  import { array } from '../plugins/schema/array/array.es6.js';
7
7
  import { binary } from '../plugins/schema/binary/binary.es6.js';
8
+ import { blacklist } from '../plugins/utils/blacklist/blacklist.es6.js';
8
9
  import { body } from '../plugins/main/body/body.es6.js';
9
10
  import { boolean } from '../plugins/schema/boolean/boolean.es6.js';
10
11
  import { cms } from '../plugins/request/cms/cms.es6.js';
@@ -40,6 +41,7 @@ import { tag } from '../plugins/main/tag/tag.es6.js';
40
41
  import { tuple } from '../plugins/schema/tuple/tuple.es6.js';
41
42
  import { uuid } from '../plugins/schema/uuid/uuid.es6.js';
42
43
  import { variable } from '../plugins/main/variable/variable.es6.js';
44
+ import { whitelist } from '../plugins/utils/whitelist/whitelist.es6.js';
43
45
  import { serverFn } from '../plugins/handler/serverFn/serverFn.es6.js';
44
46
 
45
47
  const arrayPlugins = [
@@ -49,6 +51,7 @@ const JSXPlugins = {
49
51
  api,
50
52
  array,
51
53
  binary,
54
+ blacklist,
52
55
  body,
53
56
  boolean,
54
57
  cms,
@@ -87,6 +90,7 @@ const JSXPlugins = {
87
90
  tuple,
88
91
  uuid,
89
92
  variable,
93
+ whitelist,
90
94
  };
91
95
  const fnPlugins = [
92
96
  serverFn,
@@ -9,6 +9,7 @@ require('../plugins/index.js');
9
9
  var api = require('../plugins/main/api/api.js');
10
10
  var array = require('../plugins/schema/array/array.js');
11
11
  var binary = require('../plugins/schema/binary/binary.js');
12
+ var blacklist = require('../plugins/utils/blacklist/blacklist.js');
12
13
  var body = require('../plugins/main/body/body.js');
13
14
  var boolean = require('../plugins/schema/boolean/boolean.js');
14
15
  var cms = require('../plugins/request/cms/cms.js');
@@ -44,6 +45,7 @@ var tag = require('../plugins/main/tag/tag.js');
44
45
  var tuple = require('../plugins/schema/tuple/tuple.js');
45
46
  var uuid = require('../plugins/schema/uuid/uuid.js');
46
47
  var variable = require('../plugins/main/variable/variable.js');
48
+ var whitelist = require('../plugins/utils/whitelist/whitelist.js');
47
49
  var serverFn = require('../plugins/handler/serverFn/serverFn.js');
48
50
 
49
51
  const arrayPlugins = [
@@ -53,6 +55,7 @@ const JSXPlugins = {
53
55
  api: api.api,
54
56
  array: array.array,
55
57
  binary: binary.binary,
58
+ blacklist: blacklist.blacklist,
56
59
  body: body.body,
57
60
  boolean: boolean.boolean,
58
61
  cms: cms.cms,
@@ -91,6 +94,7 @@ const JSXPlugins = {
91
94
  tuple: tuple.tuple,
92
95
  uuid: uuid.uuid,
93
96
  variable: variable.variable,
97
+ whitelist: whitelist.whitelist,
94
98
  };
95
99
  const fnPlugins = [
96
100
  serverFn.serverFn,
package/index.es6.js CHANGED
@@ -42,6 +42,8 @@ export { dts } from './plugins/utils/dts/dts.es6.js';
42
42
  export { dev } from './plugins/utils/dev/dev.es6.js';
43
43
  export { prod } from './plugins/utils/prod/prod.es6.js';
44
44
  export { protection } from './plugins/utils/protection/protection.es6.js';
45
+ export { blacklist } from './plugins/utils/blacklist/blacklist.es6.js';
46
+ export { whitelist } from './plugins/utils/whitelist/whitelist.es6.js';
45
47
  export { serverFn } from './plugins/handler/serverFn/serverFn.es6.js';
46
48
  export { EMPTY_SEARCH, parseSearch } from './utils/parseSearch/parseSearch.es6.js';
47
49
  export { stringifySearch } from './utils/stringifySearch/stringifySearch.es6.js';
package/index.js CHANGED
@@ -46,6 +46,8 @@ var dts = require('./plugins/utils/dts/dts.js');
46
46
  var dev = require('./plugins/utils/dev/dev.js');
47
47
  var prod = require('./plugins/utils/prod/prod.js');
48
48
  var protection = require('./plugins/utils/protection/protection.js');
49
+ var blacklist = require('./plugins/utils/blacklist/blacklist.js');
50
+ var whitelist = require('./plugins/utils/whitelist/whitelist.js');
49
51
  var serverFn = require('./plugins/handler/serverFn/serverFn.js');
50
52
  var parseSearch = require('./utils/parseSearch/parseSearch.js');
51
53
  var stringifySearch = require('./utils/stringifySearch/stringifySearch.js');
@@ -166,6 +168,8 @@ exports.dts = dts.dts;
166
168
  exports.dev = dev.dev;
167
169
  exports.prod = prod.prod;
168
170
  exports.protection = protection.protection;
171
+ exports.blacklist = blacklist.blacklist;
172
+ exports.whitelist = whitelist.whitelist;
169
173
  exports.serverFn = serverFn.serverFn;
170
174
  exports.EMPTY_SEARCH = parseSearch.EMPTY_SEARCH;
171
175
  exports.parseSearch = parseSearch.parseSearch;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-alpha.11",
3
+ "version": "2.0.0-alpha.12",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -0,0 +1,4 @@
1
+ export interface BlacklistProps {
2
+ ip?: string | string[];
3
+ }
4
+ export declare function blacklist(): void;
@@ -0,0 +1,17 @@
1
+ import { useProps, useChildren } from '@innet/jsx';
2
+ import '../../../hooks/index.es6.js';
3
+ import { useRequestPlugin } from '../../../hooks/useRequestPlugin/useRequestPlugin.es6.js';
4
+
5
+ function blacklist() {
6
+ const { ip = process.env.BLACKLIST_IP, } = useProps() || {};
7
+ const children = useChildren();
8
+ const ips = typeof ip === 'string' ? ip.split(',') : ip;
9
+ useRequestPlugin(action => {
10
+ console.log(action.clientIp);
11
+ if (!action.clientIp || (ips === null || ips === void 0 ? void 0 : ips.includes(action.clientIp))) {
12
+ return children;
13
+ }
14
+ });
15
+ }
16
+
17
+ export { blacklist };
@@ -0,0 +1,21 @@
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 useRequestPlugin = require('../../../hooks/useRequestPlugin/useRequestPlugin.js');
8
+
9
+ function blacklist() {
10
+ const { ip = process.env.BLACKLIST_IP, } = jsx.useProps() || {};
11
+ const children = jsx.useChildren();
12
+ const ips = typeof ip === 'string' ? ip.split(',') : ip;
13
+ useRequestPlugin.useRequestPlugin(action => {
14
+ console.log(action.clientIp);
15
+ if (!action.clientIp || (ips === null || ips === void 0 ? void 0 : ips.includes(action.clientIp))) {
16
+ return children;
17
+ }
18
+ });
19
+ }
20
+
21
+ exports.blacklist = blacklist;
@@ -0,0 +1 @@
1
+ export * from './blacklist';
@@ -0,0 +1 @@
1
+ export { blacklist } from './blacklist.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var blacklist = require('./blacklist.js');
6
+
7
+
8
+
9
+ exports.blacklist = blacklist.blacklist;
@@ -3,3 +3,5 @@ export * from './dts';
3
3
  export * from './dev';
4
4
  export * from './prod';
5
5
  export * from './protection';
6
+ export * from './blacklist';
7
+ export * from './whitelist';
@@ -3,3 +3,5 @@ import './dts/index.es6.js';
3
3
  import './dev/index.es6.js';
4
4
  import './prod/index.es6.js';
5
5
  import './protection/index.es6.js';
6
+ import './blacklist/index.es6.js';
7
+ import './whitelist/index.es6.js';
@@ -5,4 +5,6 @@ require('./dts/index.js');
5
5
  require('./dev/index.js');
6
6
  require('./prod/index.js');
7
7
  require('./protection/index.js');
8
+ require('./blacklist/index.js');
9
+ require('./whitelist/index.js');
8
10
 
@@ -0,0 +1 @@
1
+ export * from './whitelist';
@@ -0,0 +1 @@
1
+ export { whitelist } from './whitelist.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var whitelist = require('./whitelist.js');
6
+
7
+
8
+
9
+ exports.whitelist = whitelist.whitelist;
@@ -0,0 +1,4 @@
1
+ export interface WhitelistProps {
2
+ ip?: string | string[];
3
+ }
4
+ export declare function whitelist(): void;
@@ -0,0 +1,18 @@
1
+ import { useProps, useChildren } from '@innet/jsx';
2
+ import '../../../hooks/index.es6.js';
3
+ import { useRequestPlugin } from '../../../hooks/useRequestPlugin/useRequestPlugin.es6.js';
4
+
5
+ function whitelist() {
6
+ const { ip = process.env.WHITELIST_IP, } = useProps() || {};
7
+ const children = useChildren();
8
+ const ips = typeof ip === 'string' ? ip.split(',') : ip;
9
+ if (!ips)
10
+ return;
11
+ useRequestPlugin(action => {
12
+ if (!action.clientIp || !ips.includes(action.clientIp)) {
13
+ return children;
14
+ }
15
+ });
16
+ }
17
+
18
+ export { whitelist };
@@ -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 useRequestPlugin = require('../../../hooks/useRequestPlugin/useRequestPlugin.js');
8
+
9
+ function whitelist() {
10
+ const { ip = process.env.WHITELIST_IP, } = jsx.useProps() || {};
11
+ const children = jsx.useChildren();
12
+ const ips = typeof ip === 'string' ? ip.split(',') : ip;
13
+ if (!ips)
14
+ return;
15
+ useRequestPlugin.useRequestPlugin(action => {
16
+ if (!action.clientIp || !ips.includes(action.clientIp)) {
17
+ return children;
18
+ }
19
+ });
20
+ }
21
+
22
+ exports.whitelist = whitelist;