@innet/server 2.0.0-alpha.10 → 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.
@@ -477,15 +561,15 @@ You can use `PROTECTION` env to set default protection `value`.
477
561
 
478
562
  *src/app.tsx*
479
563
  ```typescript jsx
480
- import html from './protection.html'
481
-
482
564
  export default (
483
565
  <server>
484
566
  <api>
485
- <protection
486
- value='secret'
487
- html={html}
488
- />
567
+ <protection value='secret'>
568
+ <error
569
+ code='protection'
570
+ status='forbidden'
571
+ />
572
+ </protection>
489
573
  </api>
490
574
  </server>
491
575
  )
@@ -500,15 +584,17 @@ You can use `PROTECTION_MAX_AGE` env to set default `maxAge`.
500
584
 
501
585
  *src/app.tsx*
502
586
  ```typescript jsx
503
- import html from './protection.html'
504
-
505
587
  export default (
506
588
  <server>
507
589
  <api>
508
590
  <protection
509
591
  maxAge={24 * 60 * 60}
510
- html={html}
511
- />
592
+ value='secret'>
593
+ <error
594
+ code='protection'
595
+ status='forbidden'
596
+ />
597
+ </protection>
512
598
  </api>
513
599
  </server>
514
600
  )
@@ -522,15 +608,17 @@ You can use `PROTECTED_IP` env to set default `excludeIp`.
522
608
 
523
609
  *src/app.tsx*
524
610
  ```typescript jsx
525
- import html from './protection.html'
526
-
527
611
  export default (
528
612
  <server>
529
613
  <api>
530
614
  <protection
531
615
  excludeIp='0.0.0.0,127.0.0.0'
532
- html={html}
533
- />
616
+ value='secret'>
617
+ <error
618
+ code='protection'
619
+ status='forbidden'
620
+ />
621
+ </protection>
534
622
  </api>
535
623
  </server>
536
624
  )
@@ -545,15 +633,17 @@ You can use `PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
545
633
 
546
634
  *src/app.tsx*
547
635
  ```typescript jsx
548
- import html from './protection.html'
549
-
550
636
  export default (
551
637
  <server>
552
638
  <api>
553
639
  <protection
554
640
  cookieKey='secret'
555
- html={html}
556
- />
641
+ value='secret'>
642
+ <error
643
+ code='protection'
644
+ status='forbidden'
645
+ />
646
+ </protection>
557
647
  </api>
558
648
  </server>
559
649
  )
@@ -568,15 +658,17 @@ You can use `PROTECTION_SEARCH_KEY` env to set default `searchKey`.
568
658
 
569
659
  *src/app.tsx*
570
660
  ```typescript jsx
571
- import html from './protection.html'
572
-
573
661
  export default (
574
662
  <server>
575
663
  <api>
576
664
  <protection
577
665
  searchKey='secret'
578
- html={html}
579
- />
666
+ value='secret'>
667
+ <error
668
+ code='protection'
669
+ status='forbidden'
670
+ />
671
+ </protection>
580
672
  </api>
581
673
  </server>
582
674
  )
@@ -1150,6 +1242,7 @@ This element MUST be placed inside `<endpoint>`.
1150
1242
  It defines request body for the endpoint.
1151
1243
  `@innet/server` formats and validate the value automatically (real-time).
1152
1244
 
1245
+ *src/app.tsx*
1153
1246
  ```typescript jsx
1154
1247
  return (
1155
1248
  <server>
@@ -1183,6 +1276,105 @@ return (
1183
1276
  This element MUST be placed inside `<endpoint>`.
1184
1277
  It defines response body for the endpoint.
1185
1278
 
1279
+ *src/app.tsx*
1280
+ ```typescript jsx
1281
+ return (
1282
+ <server>
1283
+ <api>
1284
+ <endpoint method='get' path='/settings'>
1285
+ <response>
1286
+ <object />
1287
+ </response>
1288
+ </endpoint>
1289
+ </api>
1290
+ </server>
1291
+ )
1292
+ ```
1293
+
1294
+ #### status
1295
+ A status of the `<response>`.
1296
+ Any [HTTP status code](https://swagger.io/specification/#http-codes) can be used as a number of the property.
1297
+
1298
+ By default, `status` equals `'default'`.
1299
+
1300
+ *src/app.tsx*
1301
+ ```typescript jsx
1302
+ return (
1303
+ <server>
1304
+ <api>
1305
+ <endpoint method='get' path='/settings'>
1306
+ <response status={200}>
1307
+ <object />
1308
+ </response>
1309
+ </endpoint>
1310
+ </api>
1311
+ </server>
1312
+ )
1313
+ ```
1314
+
1315
+ To define a range of response codes, this field MAY contain the uppercase wildcard character `X`.
1316
+ For example, `2XX` represents all response codes between \[200-299].
1317
+ Only the following range definitions are allowed: `1XX`, `2XX`, `3XX`, `4XX` and `5XX`.
1318
+
1319
+ *src/app.tsx*
1320
+ ```typescript jsx
1321
+ return (
1322
+ <server>
1323
+ <api>
1324
+ <endpoint method='get' path='/settings'>
1325
+ <response status='2XX'>
1326
+ <object />
1327
+ </response>
1328
+ </endpoint>
1329
+ </api>
1330
+ </server>
1331
+ )
1332
+ ```
1333
+
1334
+ Many number statuses have a string id you can use on the property.
1335
+
1336
+ *src/app.tsx*
1337
+ ```typescript jsx
1338
+ return (
1339
+ <server>
1340
+ <api>
1341
+ <endpoint method='get' path='/settings'>
1342
+ <response status='notFound'>
1343
+ <object />
1344
+ </response>
1345
+ </endpoint>
1346
+ </api>
1347
+ </server>
1348
+ )
1349
+ ```
1350
+
1351
+ You can use many `<response>` elements in an endpoint.
1352
+
1353
+ *src/app.tsx*
1354
+ ```typescript jsx
1355
+ return (
1356
+ <server>
1357
+ <api>
1358
+ <endpoint method='get' path='/settings'>
1359
+ <response status='2XX'>
1360
+ <object />
1361
+ </response>
1362
+ <response status='4XX'>
1363
+ <object>
1364
+ <field key='error'>
1365
+ <string />
1366
+ </field>
1367
+ <field optional key='data'>
1368
+ <object />
1369
+ </field>
1370
+ </object>
1371
+ </response>
1372
+ </endpoint>
1373
+ </api>
1374
+ </server>
1375
+ )
1376
+ ```
1377
+
1186
1378
  ## Primitive Data
1187
1379
 
1188
1380
  [← back](#index)
@@ -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
@@ -12,7 +12,7 @@ export { host } from './plugins/main/host/host.es6.js';
12
12
  export { variable } from './plugins/main/variable/variable.es6.js';
13
13
  export { tag } from './plugins/main/tag/tag.es6.js';
14
14
  export { endpoint } from './plugins/main/endpoint/endpoint.es6.js';
15
- export { response } from './plugins/main/response/response.es6.js';
15
+ export { response, statuses } from './plugins/main/response/response.es6.js';
16
16
  export { request } from './plugins/main/request/request.es6.js';
17
17
  export { param } from './plugins/main/param/param.es6.js';
18
18
  export { body } from './plugins/main/body/body.es6.js';
@@ -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');
@@ -133,6 +135,7 @@ exports.variable = variable.variable;
133
135
  exports.tag = tag.tag;
134
136
  exports.endpoint = endpoint.endpoint;
135
137
  exports.response = response.response;
138
+ exports.statuses = response.statuses;
136
139
  exports.request = request.request;
137
140
  exports.param = param.param;
138
141
  exports.body = body.body;
@@ -165,6 +168,8 @@ exports.dts = dts.dts;
165
168
  exports.dev = dev.dev;
166
169
  exports.prod = prod.prod;
167
170
  exports.protection = protection.protection;
171
+ exports.blacklist = blacklist.blacklist;
172
+ exports.whitelist = whitelist.whitelist;
168
173
  exports.serverFn = serverFn.serverFn;
169
174
  exports.EMPTY_SEARCH = parseSearch.EMPTY_SEARCH;
170
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.10",
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",
@@ -1 +1 @@
1
- export { response } from './response.es6.js';
1
+ export { response, statuses } from './response.es6.js';
@@ -7,3 +7,4 @@ var response = require('./response.js');
7
7
 
8
8
 
9
9
  exports.response = response.response;
10
+ exports.statuses = response.statuses;
@@ -1,4 +1,6 @@
1
1
  import { type HandlerPlugin } from 'innet';
2
+ import { type ErrorStatuses, type RedirectStatuses, type SuccessStatuses } from '../../request';
3
+ export type StatusKey = ErrorStatuses | RedirectStatuses | SuccessStatuses;
2
4
  export interface ResponseProps {
3
5
  /**
4
6
  * A description of the response.
@@ -11,6 +13,7 @@ export interface ResponseProps {
11
13
  * For example, 2XX represents all response codes between [200-299].
12
14
  * Only the following range definitions are allowed: 1XX, 2XX, 3XX, 4XX, and 5XX.
13
15
  * */
14
- status?: number | 'default';
16
+ status?: number | `${1 | 2 | 3 | 4 | 5}XX` | 'default' | StatusKey;
15
17
  }
18
+ export declare const statuses: Record<StatusKey, number>;
16
19
  export declare const response: HandlerPlugin;
@@ -2,18 +2,26 @@ import innet, { useNewHandler } from 'innet';
2
2
  import { useProps, useChildren, useContext } from '@innet/jsx';
3
3
  import '../../../hooks/index.es6.js';
4
4
  import '../../../utils/index.es6.js';
5
+ import '../../request/index.es6.js';
6
+ import { errorStatuses } from '../../request/error/error.es6.js';
7
+ import { redirectStatuses } from '../../request/redirect/redirect.es6.js';
8
+ import { successStatuses } from '../../request/success/success.es6.js';
5
9
  import { useEndpoint, endpointContext } from '../../../hooks/useEndpoint/useEndpoint.es6.js';
6
10
  import { useThrow } from '../../../hooks/useThrow/useThrow.es6.js';
7
11
  import { schemaContext } from '../../../hooks/useSchemaContext/useSchemaContext.es6.js';
8
12
  import { getOrAdd } from '../../../utils/getOrAdd/getOrAdd.es6.js';
9
13
  import { ruleContext } from '../../../hooks/useRule/useRule.es6.js';
10
14
 
15
+ const statuses = Object.assign(Object.assign(Object.assign({}, errorStatuses), redirectStatuses), successStatuses);
11
16
  const response = () => {
12
- const { description = '', status = 'default' } = useProps() || {};
17
+ let { description = '', status = 'default' } = useProps() || {};
13
18
  const { operation, props: { path } } = useEndpoint();
14
19
  const children = useChildren();
15
20
  const handler = useNewHandler();
16
21
  const endpoint = useContext(endpointContext);
22
+ if (status in statuses) {
23
+ status = statuses[status];
24
+ }
17
25
  if (!endpoint) {
18
26
  useThrow('<{type}> MUST be placed in <endpoint> element');
19
27
  }
@@ -41,4 +49,4 @@ const response = () => {
41
49
  innet(children, handler);
42
50
  };
43
51
 
44
- export { response };
52
+ export { response, statuses };
@@ -6,6 +6,10 @@ var innet = require('innet');
6
6
  var jsx = require('@innet/jsx');
7
7
  require('../../../hooks/index.js');
8
8
  require('../../../utils/index.js');
9
+ require('../../request/index.js');
10
+ var error = require('../../request/error/error.js');
11
+ var redirect = require('../../request/redirect/redirect.js');
12
+ var success = require('../../request/success/success.js');
9
13
  var useEndpoint = require('../../../hooks/useEndpoint/useEndpoint.js');
10
14
  var useThrow = require('../../../hooks/useThrow/useThrow.js');
11
15
  var useSchemaContext = require('../../../hooks/useSchemaContext/useSchemaContext.js');
@@ -16,12 +20,16 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
16
20
 
17
21
  var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
18
22
 
23
+ const statuses = Object.assign(Object.assign(Object.assign({}, error.errorStatuses), redirect.redirectStatuses), success.successStatuses);
19
24
  const response = () => {
20
- const { description = '', status = 'default' } = jsx.useProps() || {};
25
+ let { description = '', status = 'default' } = jsx.useProps() || {};
21
26
  const { operation, props: { path } } = useEndpoint.useEndpoint();
22
27
  const children = jsx.useChildren();
23
28
  const handler = innet.useNewHandler();
24
29
  const endpoint = jsx.useContext(useEndpoint.endpointContext);
30
+ if (status in statuses) {
31
+ status = statuses[status];
32
+ }
25
33
  if (!endpoint) {
26
34
  useThrow.useThrow('<{type}> MUST be placed in <endpoint> element');
27
35
  }
@@ -50,3 +58,4 @@ const response = () => {
50
58
  };
51
59
 
52
60
  exports.response = response;
61
+ exports.statuses = statuses;
@@ -9,9 +9,10 @@ export declare const redirectStatuses: {
9
9
  temporaryRedirect: number;
10
10
  permanentRedirect: number;
11
11
  };
12
+ export type RedirectStatuses = keyof typeof redirectStatuses;
12
13
  export interface RedirectProps {
13
14
  to: string;
14
15
  encode?: boolean;
15
- status?: number | keyof typeof redirectStatuses;
16
+ status?: number | RedirectStatuses;
16
17
  }
17
18
  export declare const redirect: HandlerPlugin;
@@ -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;