hapi-terminator 0.4.0 → 0.5.0

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
@@ -44,7 +44,7 @@ await server.register({
44
44
  });
45
45
 
46
46
  server.route({
47
- method: ['GET', 'POST'],
47
+ method: ['POST'],
48
48
  path: '/',
49
49
  handler: () => 'Hello World!',
50
50
  options: {
@@ -62,7 +62,7 @@ console.log('Server running on %s', server.info.uri);
62
62
 
63
63
  You can set limits for specific routes using Hapi's native `payload.maxBytes` configuration:
64
64
 
65
- ````typescript
65
+ ```typescript
66
66
  import Hapi from '@hapi/hapi';
67
67
  import terminatorPlugin, { type TerminatorOptions } from 'hapi-terminator';
68
68
 
@@ -75,16 +75,10 @@ await server.register({
75
75
  },
76
76
  });
77
77
 
78
- // Standard route with 500KB limit
79
78
  server.route({
80
79
  method: ['GET', 'POST'],
81
80
  path: '/',
82
81
  handler: () => 'Hello World!',
83
- options: {
84
- payload: {
85
- maxBytes: 500 * 1024, // 500KB
86
- },
87
- },
88
82
  });
89
83
 
90
84
  // Upload route with higher limit (10MB)
@@ -99,7 +93,8 @@ server.route({
99
93
  },
100
94
  });
101
95
 
102
- });\n\nawait server.start();\n```
96
+ await server.start();
97
+ ```
103
98
 
104
99
  ### Boolean Limits for Unregistered Routes
105
100
 
@@ -133,7 +128,7 @@ server.route({
133
128
 
134
129
  // Any request to unregistered routes (e.g., /unknown) will be rejected immediately
135
130
  await server.start();
136
- ````
131
+ ```
137
132
 
138
133
  You can also set `unregisteredLimit` to `false` to bypass payload size checks for unregistered routes:
139
134
 
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Server } from '@hapi/hapi';
2
- import { z } from 'zod/mini';
3
- export type TerminatorOptions = z.infer<typeof TerminatorOptionsSchema>;
2
+ export type TerminatorOptions = {
3
+ unregisteredLimit?: number | boolean | null;
4
+ };
4
5
  export declare const plugin: {
5
6
  pkg: {
6
7
  name: string;
@@ -26,9 +27,6 @@ export declare const plugin: {
26
27
  typescript: string;
27
28
  "typescript-eslint": string;
28
29
  };
29
- dependencies: {
30
- zod: string;
31
- };
32
30
  prettier: string;
33
31
  "lint-staged": {
34
32
  "**/*.{js,ts,tsx}": string[];
@@ -52,10 +50,7 @@ export declare const plugin: {
52
50
  };
53
51
  register: typeof register;
54
52
  };
55
- declare const TerminatorOptionsSchema: z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniObject<{
56
- unregisteredLimit: z.ZodMiniUnion<readonly [z.ZodMiniOptional<z.ZodMiniNullable<z.ZodMiniNumber<number>>>, z.ZodMiniBoolean<boolean>]>;
57
- }, z.core.$strip>>>;
58
- declare function register(server: Server, rawOptions: TerminatorOptions): Promise<void>;
53
+ declare function register(server: Server, rawOptions: Record<string, unknown> | null | undefined): Promise<void>;
59
54
  declare const _default: {
60
55
  plugin: {
61
56
  pkg: {
@@ -82,9 +77,6 @@ declare const _default: {
82
77
  typescript: string;
83
78
  "typescript-eslint": string;
84
79
  };
85
- dependencies: {
86
- zod: string;
87
- };
88
80
  prettier: string;
89
81
  "lint-staged": {
90
82
  "**/*.{js,ts,tsx}": string[];
package/index.js CHANGED
@@ -1,11 +1,7 @@
1
- import { z } from 'zod/mini';
2
1
  import pkg from './package.json';
3
2
  export const plugin = { pkg, register };
4
- const TerminatorOptionsSchema = z.nullish(z.object({
5
- unregisteredLimit: z.union([z.nullish(z.number().check(z.minimum(0))), z.boolean()]),
6
- }));
7
3
  async function register(server, rawOptions) {
8
- const options = TerminatorOptionsSchema.parse(rawOptions);
4
+ const options = validateOptions(rawOptions);
9
5
  server.ext('onRequest', validateHookHandler(options));
10
6
  }
11
7
  function validateHookHandler(pluginOptions) {
@@ -68,4 +64,20 @@ function closeSocketsOnFinish(request) {
68
64
  }
69
65
  });
70
66
  }
67
+ function validateOptions(options) {
68
+ if (options == null) {
69
+ return { unregisteredLimit: null };
70
+ }
71
+ if (!('unregisteredLimit' in options)) {
72
+ return { unregisteredLimit: null };
73
+ }
74
+ const unregisteredLimit = options.unregisteredLimit;
75
+ if (typeof unregisteredLimit === 'number') {
76
+ return { unregisteredLimit: Math.max(0, unregisteredLimit) };
77
+ }
78
+ if (typeof unregisteredLimit === 'boolean') {
79
+ return { unregisteredLimit };
80
+ }
81
+ return { unregisteredLimit: null };
82
+ }
71
83
  export default { plugin };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "index.js",
4
4
  "typings": "index.d.ts",
5
5
  "type": "module",
6
- "version": "0.4.0",
6
+ "version": "0.5.0",
7
7
  "license": "MIT",
8
8
  "author": {
9
9
  "name": "Kamaal Farah"
@@ -22,9 +22,6 @@
22
22
  "typescript": "^5.9.3",
23
23
  "typescript-eslint": "^8.52.0"
24
24
  },
25
- "dependencies": {
26
- "zod": "^4.3.5"
27
- },
28
25
  "prettier": "@kamaalio/prettier-config",
29
26
  "lint-staged": {
30
27
  "**/*.{js,ts,tsx}": [