@innet/server 2.0.0-alpha.0 → 2.0.0-alpha.10

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.
Files changed (111) hide show
  1. package/README.md +309 -29
  2. package/example/requests/index.d.ts +1 -1
  3. package/example/requests/todo/AddTodo/AddTodo.d.ts +1 -0
  4. package/example/requests/todo/AddTodo/index.d.ts +1 -0
  5. package/example/requests/todo/DeleteTodo/DeleteTodo.d.ts +1 -0
  6. package/example/requests/todo/DeleteTodo/index.d.ts +1 -0
  7. package/example/requests/todo/EditTodo/EditTodo.d.ts +1 -0
  8. package/example/requests/todo/EditTodo/index.d.ts +1 -0
  9. package/example/requests/todo/GetTodo/GetTodo.d.ts +1 -0
  10. package/example/requests/todo/GetTodo/index.d.ts +1 -0
  11. package/example/requests/todo/GetTodos/GetTodos.d.ts +1 -0
  12. package/example/requests/todo/GetTodos/index.d.ts +1 -0
  13. package/example/requests/todo/index.d.ts +5 -0
  14. package/example/requests/todo/todos.d.ts +1 -0
  15. package/example/schemas/app/ListQueryParams/ListQueryParams.d.ts +1 -0
  16. package/example/schemas/app/ListQueryParams/index.d.ts +1 -0
  17. package/example/schemas/app/ListSchema/ListSchema.d.ts +4 -1
  18. package/example/schemas/app/index.d.ts +1 -0
  19. package/example/schemas/index.d.ts +1 -3
  20. package/example/schemas/todo/TodoSchema/TodoSchema.d.ts +4 -0
  21. package/example/schemas/todo/TodoSchema/index.d.ts +1 -0
  22. package/example/schemas/todo/index.d.ts +1 -0
  23. package/example/tags/Todo/Todo.d.ts +1 -0
  24. package/example/tags/Todo/index.d.ts +1 -0
  25. package/example/tags/index.d.ts +1 -1
  26. package/handler/handler.d.ts +3 -1
  27. package/handler/handler.es6.js +2 -0
  28. package/handler/handler.js +2 -0
  29. package/hooks/index.d.ts +2 -0
  30. package/hooks/index.es6.js +2 -0
  31. package/hooks/index.js +2 -0
  32. package/hooks/useClientIp/index.d.ts +1 -0
  33. package/hooks/useClientIp/index.es6.js +1 -0
  34. package/hooks/useClientIp/index.js +9 -0
  35. package/hooks/useClientIp/useClientIp.d.ts +1 -0
  36. package/hooks/useClientIp/useClientIp.es6.js +9 -0
  37. package/hooks/useClientIp/useClientIp.js +13 -0
  38. package/hooks/useComponentName/useComponentName.d.ts +1 -1
  39. package/hooks/useRequestPlugin/index.d.ts +1 -0
  40. package/hooks/useRequestPlugin/index.es6.js +1 -0
  41. package/hooks/useRequestPlugin/index.js +9 -0
  42. package/hooks/useRequestPlugin/useRequestPlugin.d.ts +2 -0
  43. package/hooks/useRequestPlugin/useRequestPlugin.es6.js +13 -0
  44. package/hooks/useRequestPlugin/useRequestPlugin.js +17 -0
  45. package/index.es6.js +4 -0
  46. package/index.js +9 -0
  47. package/package.json +2 -2
  48. package/plugins/main/api/api.es6.js +18 -11
  49. package/plugins/main/api/api.js +18 -11
  50. package/plugins/main/response/response.d.ts +1 -1
  51. package/plugins/main/response/response.es6.js +1 -1
  52. package/plugins/main/response/response.js +1 -1
  53. package/plugins/main/server/server.es6.js +10 -4
  54. package/plugins/main/server/server.js +10 -4
  55. package/plugins/request/cookie/cookie.es6.js +3 -19
  56. package/plugins/request/cookie/cookie.js +3 -23
  57. package/plugins/request/success/success.d.ts +1 -0
  58. package/plugins/request/success/success.es6.js +13 -4
  59. package/plugins/request/success/success.js +13 -4
  60. package/plugins/schema/boolean/boolean.es6.js +2 -4
  61. package/plugins/schema/boolean/boolean.js +1 -3
  62. package/plugins/utils/dts/dts.d.ts +1 -2
  63. package/plugins/utils/dts/dts.es6.js +6 -25
  64. package/plugins/utils/dts/dts.js +5 -29
  65. package/plugins/utils/index.d.ts +1 -0
  66. package/plugins/utils/index.es6.js +1 -0
  67. package/plugins/utils/index.js +1 -0
  68. package/plugins/utils/protection/index.d.ts +1 -0
  69. package/plugins/utils/protection/index.es6.js +1 -0
  70. package/plugins/utils/protection/index.js +9 -0
  71. package/plugins/utils/protection/protection.d.ts +8 -0
  72. package/plugins/utils/protection/protection.es6.js +34 -0
  73. package/plugins/utils/protection/protection.js +38 -0
  74. package/plugins/utils/swagger/swagger.es6.js +7 -11
  75. package/plugins/utils/swagger/swagger.js +7 -11
  76. package/types.d.ts +2 -3
  77. package/utils/action/Action.d.ts +7 -4
  78. package/utils/action/Action.es6.js +25 -3
  79. package/utils/action/Action.js +26 -4
  80. package/utils/generateTypes/generateTypes.d.ts +3 -0
  81. package/utils/generateTypes/generateTypes.es6.js +102 -0
  82. package/utils/generateTypes/generateTypes.js +107 -0
  83. package/utils/generateTypes/generateTypes.test.d.ts +1 -0
  84. package/utils/generateTypes/index.d.ts +1 -0
  85. package/utils/generateTypes/index.es6.js +1 -0
  86. package/utils/generateTypes/index.js +10 -0
  87. package/utils/index.d.ts +1 -0
  88. package/utils/index.es6.js +1 -0
  89. package/utils/index.js +1 -0
  90. package/utils/rules/objectOf/objectOf.es6.js +4 -1
  91. package/utils/rules/objectOf/objectOf.js +4 -1
  92. package/example/requests/partners/EditPartner/EditPartner.d.ts +0 -1
  93. package/example/requests/partners/EditPartner/index.d.ts +0 -1
  94. package/example/requests/partners/GetPartner/GetPartner.d.ts +0 -1
  95. package/example/requests/partners/GetPartner/index.d.ts +0 -1
  96. package/example/requests/partners/GetPartners/GetPartners.d.ts +0 -1
  97. package/example/requests/partners/GetPartners/index.d.ts +0 -1
  98. package/example/requests/partners/index.d.ts +0 -3
  99. package/example/schemas/address/AddressSchema/AddressSchema.d.ts +0 -1
  100. package/example/schemas/address/AddressSchema/index.d.ts +0 -1
  101. package/example/schemas/address/index.d.ts +0 -1
  102. package/example/schemas/location/LocationSchema/LocationSchema.d.ts +0 -1
  103. package/example/schemas/location/LocationSchema/index.d.ts +0 -1
  104. package/example/schemas/location/index.d.ts +0 -1
  105. package/example/schemas/partner/EditPartnerSchema/EditPartnerSchema.d.ts +0 -1
  106. package/example/schemas/partner/EditPartnerSchema/index.d.ts +0 -1
  107. package/example/schemas/partner/PartnerSchema/PartnerSchema.d.ts +0 -1
  108. package/example/schemas/partner/PartnerSchema/index.d.ts +0 -1
  109. package/example/schemas/partner/index.d.ts +0 -2
  110. package/example/tags/Partner/Partner.d.ts +0 -1
  111. package/example/tags/Partner/index.d.ts +0 -1
package/README.md CHANGED
@@ -317,7 +317,9 @@ This section contains elements of utils.
317
317
 
318
318
  [\<swagger>](#swagger)
319
319
  [\<dev>](#dev)
320
- [\<dts>](#dts)
320
+ [\<prod>](#prod)
321
+ [\<dts>](#dts)
322
+ [\<protection>](#protection)
321
323
 
322
324
  ---
323
325
 
@@ -374,6 +376,25 @@ export default (
374
376
  )
375
377
  ```
376
378
 
379
+ ### \<prod>
380
+
381
+ [← back](#utils)
382
+
383
+ Everything inside <prod> will work when `NODE_ENV` equals `production`.
384
+
385
+ *src/app.tsx*
386
+ ```typescript jsx
387
+ export default (
388
+ <server>
389
+ <api>
390
+ <prod>
391
+ <swagger />
392
+ </prod>
393
+ </api>
394
+ </server>
395
+ )
396
+ ```
397
+
377
398
  ### \<dts>
378
399
 
379
400
  [← back](#utils)
@@ -396,21 +417,170 @@ export default (
396
417
  )
397
418
  ```
398
419
 
399
- > You MUST add some [endpoint](#endpoint) with some schema otherwise you get the `Error: There is no schema in the input contents`.
400
-
420
+ You do not need to import types, use `Api` namespace everywhere.
401
421
  Here is an example of generated types usage.
402
422
 
403
- *src/GetPartner.tsx*
404
423
  ```typescript jsx
405
424
  import { useParams } from '@innet/server'
406
425
 
407
- export function GetPartner () {
408
- const { id } = useParams<Paths.Partners$Id.Get.PathParameters>()
409
- return <success>{{ id }}</success>
426
+ import { todos } from '../todos'
427
+
428
+ export function DeleteTodo () {
429
+ const { todoId } = useParams<Api.Endpoints['DELETE:/todos/{todoId}']['Params']>()
430
+
431
+ const todoIndex = todos.findIndex(({ id }) => id === todoId)
432
+
433
+ if (todoIndex === -1) {
434
+ return <error code='todoNotFound' status={404} />
435
+ }
436
+
437
+ todos.splice(todoIndex, 1)
438
+
439
+ return <success />
410
440
  }
411
441
  ```
412
442
 
413
- You do not need to import types, they generate as namespaces.
443
+ ### \<protection>
444
+
445
+ This element MUST be placed in `<api>` element.
446
+
447
+ [← back](#utils)
448
+
449
+ This element adds protection page.
450
+ You can use it when you want to protect your application.
451
+
452
+ If protection failed content of the element should be used.
453
+
454
+ *src/app.tsx*
455
+ ```typescript jsx
456
+ export default (
457
+ <server>
458
+ <api>
459
+ <protection>
460
+ <error
461
+ code='protection'
462
+ status='forbidden'
463
+ />
464
+ </protection>
465
+ </api>
466
+ </server>
467
+ )
468
+ ```
469
+
470
+ #### value
471
+
472
+ This prop is a secret string of protection value.
473
+ User must provide a protection query param equals the `value`.
474
+
475
+ By default, the value is `undefined` and protection does not work.
476
+ You can use `PROTECTION` env to set default protection `value`.
477
+
478
+ *src/app.tsx*
479
+ ```typescript jsx
480
+ import html from './protection.html'
481
+
482
+ export default (
483
+ <server>
484
+ <api>
485
+ <protection
486
+ value='secret'
487
+ html={html}
488
+ />
489
+ </api>
490
+ </server>
491
+ )
492
+ ```
493
+
494
+ #### maxAge
495
+
496
+ This prop sets how much time protection is qualified.
497
+
498
+ By default, the prop equals a year.
499
+ You can use `PROTECTION_MAX_AGE` env to set default `maxAge`.
500
+
501
+ *src/app.tsx*
502
+ ```typescript jsx
503
+ import html from './protection.html'
504
+
505
+ export default (
506
+ <server>
507
+ <api>
508
+ <protection
509
+ maxAge={24 * 60 * 60}
510
+ html={html}
511
+ />
512
+ </api>
513
+ </server>
514
+ )
515
+ ```
516
+
517
+ #### excludeIp
518
+
519
+ This prop sets a list of IP addresses (split by `,`) to ignore the protection.
520
+
521
+ You can use `PROTECTED_IP` env to set default `excludeIp`.
522
+
523
+ *src/app.tsx*
524
+ ```typescript jsx
525
+ import html from './protection.html'
526
+
527
+ export default (
528
+ <server>
529
+ <api>
530
+ <protection
531
+ excludeIp='0.0.0.0,127.0.0.0'
532
+ html={html}
533
+ />
534
+ </api>
535
+ </server>
536
+ )
537
+ ```
538
+
539
+ #### cookieKey
540
+
541
+ This prop sets a cookie field name used to store protection of a user.
542
+
543
+ By default, it equals `protection`.
544
+ You can use `PROTECTION_COOKIE_KEY` env to set default `cookieKey`.
545
+
546
+ *src/app.tsx*
547
+ ```typescript jsx
548
+ import html from './protection.html'
549
+
550
+ export default (
551
+ <server>
552
+ <api>
553
+ <protection
554
+ cookieKey='secret'
555
+ html={html}
556
+ />
557
+ </api>
558
+ </server>
559
+ )
560
+ ```
561
+
562
+ #### searchKey
563
+
564
+ This prop sets a search query field name used to check protection.
565
+
566
+ By default, it equals `protection`.
567
+ You can use `PROTECTION_SEARCH_KEY` env to set default `searchKey`.
568
+
569
+ *src/app.tsx*
570
+ ```typescript jsx
571
+ import html from './protection.html'
572
+
573
+ export default (
574
+ <server>
575
+ <api>
576
+ <protection
577
+ searchKey='secret'
578
+ html={html}
579
+ />
580
+ </api>
581
+ </server>
582
+ )
583
+ ```
414
584
 
415
585
  ## API Info
416
586
 
@@ -2624,6 +2794,26 @@ export default (
2624
2794
  )
2625
2795
  ```
2626
2796
 
2797
+ #### contentType
2798
+
2799
+ This props sets response content type.
2800
+ By default, it checks children element to define the prop.
2801
+
2802
+ *src/app.tsx*
2803
+ ```typescript jsx
2804
+ export default (
2805
+ <server>
2806
+ <api>
2807
+ <fallback>
2808
+ <success contentType='text/html'>
2809
+ Hello World!
2810
+ </success>
2811
+ </fallback>
2812
+ </api>
2813
+ </server>
2814
+ )
2815
+ ```
2816
+
2627
2817
  ### \<error>
2628
2818
 
2629
2819
  [← back](#run-time)
@@ -3310,7 +3500,7 @@ Hook functions give you all features to control parent element functionality.
3310
3500
 
3311
3501
  [← back](#index)
3312
3502
 
3313
- [useServer](#useserver)
3503
+ Real-time
3314
3504
  [useRequest](#userequest)
3315
3505
  [useResponse](#useresponse)
3316
3506
  [useHeaders](#useheaders)
@@ -3319,29 +3509,16 @@ Hook functions give you all features to control parent element functionality.
3319
3509
  [useParams](#useparams)
3320
3510
  [useSearch](#usesearch)
3321
3511
  [useBody](#usebody)
3512
+ [useClientIp](#useclientip)
3322
3513
 
3323
- ---
3324
-
3325
- ### useServer
3326
-
3327
- [← back](#hooks)
3328
-
3329
- This hook MUST be used in a component placed in `<server>`.
3330
- This hook returns current http(s) server instance.
3331
-
3332
- *src/Component.tsx*
3333
-
3334
- ```typescript jsx
3335
- import { useServer } from '@innet/sever'
3336
-
3337
- export function Component () {
3338
- const server = useServer()
3514
+ Server start
3515
+ [useRequestPlugin](#userequestplugin)
3339
3516
 
3340
- console.log(server)
3517
+ Both
3518
+ [useServer](#useserver)
3519
+ [useComponentName](#usecomponentname)
3341
3520
 
3342
- return <success />
3343
- }
3344
- ```
3521
+ ---
3345
3522
 
3346
3523
  ### useRequest
3347
3524
 
@@ -3496,6 +3673,109 @@ export function Component () {
3496
3673
  }
3497
3674
  ```
3498
3675
 
3676
+ ### useClientIp
3677
+
3678
+ [← back](#hooks)
3679
+
3680
+ This hook returns request user IP.
3681
+ This hook MUST be used in a component placed in [\<request>](#request) or [\<fallback>](#fallback).
3682
+
3683
+ *src/Component.tsx*
3684
+ ```typescript jsx
3685
+ import { useClientIp } from '@innet/sever'
3686
+
3687
+ export function Component () {
3688
+ const ip = useClientIp()
3689
+
3690
+ return <success>{{ ip }}</success>
3691
+ }
3692
+ ```
3693
+
3694
+ ### useRequestPlugin
3695
+
3696
+ [← back](#hooks)
3697
+
3698
+ This hook adds a request plugin function.
3699
+ The function runs before check endpoints.
3700
+ If the function returns `true` the request handling stops, and you get full control over the request.
3701
+
3702
+ This hook MUST be used in a component placed in [\<api>](#api).
3703
+
3704
+ *src/SecretEndpoint.tsx*
3705
+ ```typescript jsx
3706
+ import { useRequestPlugin } from '@innet/sever'
3707
+
3708
+ export function SecretEndpoint () {
3709
+ useRequestPlugin((req, res) => {
3710
+ if (req.url.startsWith('/secret-endpoint')) {
3711
+ res.statusCode = 200
3712
+ res.write('A secret message')
3713
+ res.end()
3714
+ return true
3715
+ }
3716
+ })
3717
+ }
3718
+ ```
3719
+
3720
+ Then use the plugin in [\<api>](#api).
3721
+
3722
+ *src/app.tsx*
3723
+ ```typescript jsx
3724
+ import { SecretEndpoint } from './SecretEndpoint'
3725
+
3726
+ export default (
3727
+ <server>
3728
+ <api>
3729
+ <fallback>
3730
+ <error />
3731
+ </fallback>
3732
+ <SecretEndpoint />
3733
+ </api>
3734
+ </server>
3735
+ )
3736
+ ```
3737
+
3738
+ Any endpoint returns an error except for `/secret-endpoint`.
3739
+ Elements order does not matter.
3740
+
3741
+ ### useServer
3742
+
3743
+ [← back](#hooks)
3744
+
3745
+ This hook MUST be used in a component placed in [\<server>](#server).
3746
+ This hook returns current http(s) server instance.
3747
+
3748
+ *src/Component.tsx*
3749
+ ```typescript jsx
3750
+ import { useServer } from '@innet/sever'
3751
+
3752
+ export function Component () {
3753
+ const server = useServer()
3754
+
3755
+ console.log(server)
3756
+
3757
+ return <success />
3758
+ }
3759
+ ```
3760
+
3761
+ ### useComponentName
3762
+
3763
+ [← back](#hooks)
3764
+
3765
+ This hook returns name of current component.
3766
+
3767
+ *src/Component.tsx*
3768
+ ```typescript jsx
3769
+ import { useComponentName } from '@innet/sever'
3770
+
3771
+ export function Component () {
3772
+ // returns this ^-------^
3773
+ const name = useComponentName()
3774
+
3775
+ return <success>{{ name }}</success>
3776
+ }
3777
+ ```
3778
+
3499
3779
  ## Issues
3500
3780
  If you find a bug or have a suggestion, please file an issue on [GitHub](https://github.com/d8corp/innet-server/issues).
3501
3781
 
@@ -1 +1 @@
1
- export * from './partners';
1
+ export * from './todo';
@@ -0,0 +1 @@
1
+ export declare function AddTodo(): any;
@@ -0,0 +1 @@
1
+ export * from './AddTodo';
@@ -0,0 +1 @@
1
+ export declare function DeleteTodo(): any;
@@ -0,0 +1 @@
1
+ export * from './DeleteTodo';
@@ -0,0 +1 @@
1
+ export declare function EditTodo(): any;
@@ -0,0 +1 @@
1
+ export * from './EditTodo';
@@ -0,0 +1 @@
1
+ export declare function GetTodo(): any;
@@ -0,0 +1 @@
1
+ export * from './GetTodo';
@@ -0,0 +1 @@
1
+ export declare function GetTodos(): any;
@@ -0,0 +1 @@
1
+ export * from './GetTodos';
@@ -0,0 +1,5 @@
1
+ export * from './GetTodos';
2
+ export * from './GetTodo';
3
+ export * from './AddTodo';
4
+ export * from './EditTodo';
5
+ export * from './DeleteTodo';
@@ -0,0 +1 @@
1
+ export declare const todos: Api.Schemas.TodoSchema[];
@@ -0,0 +1 @@
1
+ export declare function ListQueryParams(): any;
@@ -0,0 +1 @@
1
+ export * from './ListQueryParams';
@@ -1 +1,4 @@
1
- export declare function ListSchema(): any;
1
+ export interface ListSchemaProps {
2
+ key: string;
3
+ }
4
+ export declare function ListSchema({ key }: ListSchemaProps): any;
@@ -1 +1,2 @@
1
1
  export * from './ListSchema';
2
+ export * from './ListQueryParams';
@@ -1,4 +1,2 @@
1
- export * from './location';
2
- export * from './address';
3
- export * from './partner';
4
1
  export * from './app';
2
+ export * from './todo';
@@ -0,0 +1,4 @@
1
+ export interface TodoSchemaProps {
2
+ body?: boolean;
3
+ }
4
+ export declare function TodoSchema({ body }?: TodoSchemaProps): any;
@@ -0,0 +1 @@
1
+ export * from './TodoSchema';
@@ -0,0 +1 @@
1
+ export * from './TodoSchema';
@@ -0,0 +1 @@
1
+ export declare function Todo(): any;
@@ -0,0 +1 @@
1
+ export * from './Todo';
@@ -1 +1 @@
1
- export * from './Partner';
1
+ export * from './Todo';
@@ -1,6 +1,6 @@
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, 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, 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';
4
4
  export declare const arrayPlugins: (typeof arraySync)[];
5
5
  export declare const JSXPlugins: {
6
6
  api: import("innet").HandlerPlugin;
@@ -29,6 +29,7 @@ export declare const JSXPlugins: {
29
29
  object: import("innet").HandlerPlugin;
30
30
  param: import("innet").HandlerPlugin;
31
31
  prod: import("innet").HandlerPlugin;
32
+ protection: typeof protection;
32
33
  proxy: import("innet").HandlerPlugin;
33
34
  redirect: import("innet").HandlerPlugin;
34
35
  request: import("innet").HandlerPlugin;
@@ -77,6 +78,7 @@ declare global {
77
78
  object: ObjectProps;
78
79
  param: ParamProps;
79
80
  prod: ProdProps;
81
+ protection: ProtectionProps;
80
82
  proxy: ProxyProps;
81
83
  redirect: RedirectProps;
82
84
  request: RequestProps;
@@ -27,6 +27,7 @@ import { number } from '../plugins/schema/number/number.es6.js';
27
27
  import { object } from '../plugins/schema/object/object.es6.js';
28
28
  import { param } from '../plugins/main/param/param.es6.js';
29
29
  import { prod } from '../plugins/utils/prod/prod.es6.js';
30
+ import { protection } from '../plugins/utils/protection/protection.es6.js';
30
31
  import { proxy } from '../plugins/request/proxy/proxy.es6.js';
31
32
  import { redirect } from '../plugins/request/redirect/redirect.es6.js';
32
33
  import { request } from '../plugins/main/request/request.es6.js';
@@ -71,6 +72,7 @@ const JSXPlugins = {
71
72
  object,
72
73
  param,
73
74
  prod,
75
+ protection,
74
76
  proxy,
75
77
  redirect,
76
78
  request,
@@ -31,6 +31,7 @@ var number = require('../plugins/schema/number/number.js');
31
31
  var object = require('../plugins/schema/object/object.js');
32
32
  var param = require('../plugins/main/param/param.js');
33
33
  var prod = require('../plugins/utils/prod/prod.js');
34
+ var protection = require('../plugins/utils/protection/protection.js');
34
35
  var proxy = require('../plugins/request/proxy/proxy.js');
35
36
  var redirect = require('../plugins/request/redirect/redirect.js');
36
37
  var request = require('../plugins/main/request/request.js');
@@ -75,6 +76,7 @@ const JSXPlugins = {
75
76
  object: object.object,
76
77
  param: param.param,
77
78
  prod: prod.prod,
79
+ protection: protection.protection,
78
80
  proxy: proxy.proxy,
79
81
  redirect: redirect.redirect,
80
82
  request: request.request,
package/hooks/index.d.ts CHANGED
@@ -23,3 +23,5 @@ export * from './useRule';
23
23
  export * from './useObjectRule';
24
24
  export * from './useBodyFile';
25
25
  export * from './usePath';
26
+ export * from './useRequestPlugin';
27
+ export * from './useClientIp';
@@ -23,3 +23,5 @@ import './useRule/index.es6.js';
23
23
  import './useObjectRule/index.es6.js';
24
24
  import './useBodyFile/index.es6.js';
25
25
  import './usePath/index.es6.js';
26
+ import './useRequestPlugin/index.es6.js';
27
+ import './useClientIp/index.es6.js';
package/hooks/index.js CHANGED
@@ -25,4 +25,6 @@ require('./useRule/index.js');
25
25
  require('./useObjectRule/index.js');
26
26
  require('./useBodyFile/index.js');
27
27
  require('./usePath/index.js');
28
+ require('./useRequestPlugin/index.js');
29
+ require('./useClientIp/index.js');
28
30
 
@@ -0,0 +1 @@
1
+ export * from './useClientIp';
@@ -0,0 +1 @@
1
+ export { useClientIp } from './useClientIp.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useClientIp = require('./useClientIp.js');
6
+
7
+
8
+
9
+ exports.useClientIp = useClientIp.useClientIp;
@@ -0,0 +1 @@
1
+ export declare function useClientIp(): string | null;
@@ -0,0 +1,9 @@
1
+ import '../useAction/index.es6.js';
2
+ import { useAction } from '../useAction/useAction.es6.js';
3
+
4
+ function useClientIp() {
5
+ const action = useAction();
6
+ return action.clientIp;
7
+ }
8
+
9
+ export { useClientIp };
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('../useAction/index.js');
6
+ var useAction = require('../useAction/useAction.js');
7
+
8
+ function useClientIp() {
9
+ const action = useAction.useAction();
10
+ return action.clientIp;
11
+ }
12
+
13
+ exports.useClientIp = useClientIp;
@@ -1 +1 @@
1
- export declare function useComponentName(): any;
1
+ export declare function useComponentName(): string;
@@ -0,0 +1 @@
1
+ export * from './useRequestPlugin';
@@ -0,0 +1 @@
1
+ export { useRequestPlugin } from './useRequestPlugin.es6.js';
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useRequestPlugin = require('./useRequestPlugin.js');
6
+
7
+
8
+
9
+ exports.useRequestPlugin = useRequestPlugin.useRequestPlugin;
@@ -0,0 +1,2 @@
1
+ import { type RequestPlugin } from '../../types';
2
+ export declare function useRequestPlugin(listener: RequestPlugin): void;
@@ -0,0 +1,13 @@
1
+ import { onDestroy } from 'watch-state';
2
+ import '../useApi/index.es6.js';
3
+ import { useApi } from '../useApi/useApi.es6.js';
4
+
5
+ function useRequestPlugin(listener) {
6
+ const { requestPlugins } = useApi();
7
+ requestPlugins.add(listener);
8
+ onDestroy(() => {
9
+ requestPlugins.delete(listener);
10
+ });
11
+ }
12
+
13
+ export { useRequestPlugin };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var watchState = require('watch-state');
6
+ require('../useApi/index.js');
7
+ var useApi = require('../useApi/useApi.js');
8
+
9
+ function useRequestPlugin(listener) {
10
+ const { requestPlugins } = useApi.useApi();
11
+ requestPlugins.add(listener);
12
+ watchState.onDestroy(() => {
13
+ requestPlugins.delete(listener);
14
+ });
15
+ }
16
+
17
+ exports.useRequestPlugin = useRequestPlugin;