@equinor/fusion-framework-module-http 6.1.0 → 6.2.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +145 -0
  2. package/README.md +49 -0
  3. package/dist/esm/configurator.js +7 -2
  4. package/dist/esm/configurator.js.map +1 -1
  5. package/dist/esm/lib/operators/capitalize-request-method.operator.js +17 -0
  6. package/dist/esm/lib/operators/capitalize-request-method.operator.js.map +1 -0
  7. package/dist/esm/lib/operators/fetch-request.schema.js +109 -0
  8. package/dist/esm/lib/operators/fetch-request.schema.js.map +1 -0
  9. package/dist/esm/lib/operators/index.js +2 -0
  10. package/dist/esm/lib/operators/index.js.map +1 -1
  11. package/dist/esm/lib/operators/process-operators.js +10 -0
  12. package/dist/esm/lib/operators/process-operators.js.map +1 -1
  13. package/dist/esm/lib/operators/request-validation.operator.js +29 -0
  14. package/dist/esm/lib/operators/request-validation.operator.js.map +1 -0
  15. package/dist/esm/version.js +1 -1
  16. package/dist/tsconfig.tsbuildinfo +1 -1
  17. package/dist/types/lib/operators/capitalize-request-method.operator.d.ts +10 -0
  18. package/dist/types/lib/operators/fetch-request.schema.d.ts +170 -0
  19. package/dist/types/lib/operators/index.d.ts +2 -0
  20. package/dist/types/lib/operators/process-operators.d.ts +7 -0
  21. package/dist/types/lib/operators/request-validation.operator.d.ts +33 -0
  22. package/dist/types/lib/operators/types.d.ts +6 -0
  23. package/dist/types/version.d.ts +1 -1
  24. package/package.json +2 -1
  25. package/src/configurator.ts +13 -4
  26. package/src/lib/operators/capitalize-request-method.operator.ts +22 -0
  27. package/src/lib/operators/fetch-request.schema.ts +119 -0
  28. package/src/lib/operators/index.ts +2 -0
  29. package/src/lib/operators/process-operators.ts +11 -0
  30. package/src/lib/operators/request-validation.operator.ts +50 -0
  31. package/src/lib/operators/types.ts +7 -0
  32. package/src/version.ts +1 -1
  33. package/tests/operators.test.ts +101 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,150 @@
1
1
  # Change Log
2
2
 
3
+ ## 6.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2491](https://github.com/equinor/fusion-framework/pull/2491) [`73af73e`](https://github.com/equinor/fusion-framework/commit/73af73e5582ca27b132210af8ba308b80e036d51) Thanks [@odinr](https://github.com/odinr)! - Added a new operator `capitalizeRequestMethodOperator` to ensure that the HTTP method of a given request is in uppercase.
8
+
9
+ - Introduced `capitalizeRequestMethodOperator` which processes an HTTP request object and converts its method to uppercase.
10
+ - Logs a warning if the HTTP method was converted, providing information about the change and a reference to RFC 7231 Section 4.1.
11
+
12
+ **Example usage:**
13
+
14
+ ```typescript
15
+ import { capitalizeRequestMethodOperator } from '@equinor/fusion-query';
16
+
17
+ const operator = capitalizeRequestMethodOperator();
18
+ const request = { method: 'get' };
19
+ const updatedRequest = operator(request);
20
+ console.log(updatedRequest.method); // Outputs: 'GET'
21
+ ```
22
+
23
+ Adding the operator to the `HttpClient`:
24
+
25
+ ```typescript
26
+ const httpClient = new HttpClient();
27
+ httpClient.requestHandler.add('capatalize-method', capitalizeRequestMethodOperator());
28
+
29
+ // transforms `method` to uppercase and logs a warning.
30
+ httpClient.get('https://example.com', { method: 'get' });
31
+ ```
32
+
33
+ - [#2491](https://github.com/equinor/fusion-framework/pull/2491) [`73af73e`](https://github.com/equinor/fusion-framework/commit/73af73e5582ca27b132210af8ba308b80e036d51) Thanks [@odinr](https://github.com/odinr)! - The `HttpClientConfigurator` now has by default the `capitalizeRequestMethodOperator` and `requestValidationOperator` enabled.
34
+
35
+ **CapitalizeRequestMethodOperator**
36
+
37
+ This operator will capitalize the HTTP method name before sending the request. This is useful when you are using a client that requires the HTTP method to be capitalized. If you want to disable this operator, you can do so by removing it from the `HttpClientConfigurator`:
38
+
39
+ ```typescript
40
+ httpConfig.defaultHttpRequestHandler.remove('capitalize-method');
41
+ ```
42
+
43
+ > [!NOTE]
44
+ > This operator is enabled by default and will log to the console if the method is not capitalized.
45
+
46
+ **RequestValidationOperator**
47
+
48
+ This operator will parse and validate the request before sending it. If the request is invalid, the error will be logged to the console. If you want to disable this operator, you can do so by removing it from the `HttpClientConfigurator`:
49
+
50
+ ```typescript
51
+ httpConfig.defaultHttpRequestHandler.remove('validate-request');
52
+ ```
53
+
54
+ > [!NOTE]
55
+ > This operator is enabled by default and will log to the console if the request parameters are invalid.
56
+
57
+ If you wish stricter validation, you can enable the `strict` mode by setting the `strict` property to `true`:
58
+
59
+ ```typescript
60
+ import { requestValidationOperator } from '@equinor/fusion-framework-module-http/operators';
61
+
62
+ httpConfig.defaultHttpRequestHandler.set(
63
+ 'validate-request'
64
+ requestValidationOperator({
65
+ strict: true, // will throw error if schema is not valid
66
+ parse: true // will not allow additional properties
67
+ })
68
+ );
69
+ ```
70
+
71
+ - [#2491](https://github.com/equinor/fusion-framework/pull/2491) [`73af73e`](https://github.com/equinor/fusion-framework/commit/73af73e5582ca27b132210af8ba308b80e036d51) Thanks [@odinr](https://github.com/odinr)! - Added `remove` to the `ProcessOperators` to allow for the removal of a specific operator. This is useful for removing operators that are not desired, example default operators included in initial configuration.
72
+
73
+ example:
74
+
75
+ ```typescript
76
+ httpClient.requestHandler.remove('capitalize-method');
77
+ ```
78
+
79
+ > [!NOTE]
80
+ > There are currently no code completion for the `remove` method, so you will need to know the name of the operator you want to remove. We assume this is so low level that if you are removing operators you know what the name of the operator is.
81
+
82
+ > [!TIP]
83
+ > If you only wish to replace the operator with another operator, you can use the `set` method instead of `remove` and `add`.
84
+
85
+ - [#2491](https://github.com/equinor/fusion-framework/pull/2491) [`73af73e`](https://github.com/equinor/fusion-framework/commit/73af73e5582ca27b132210af8ba308b80e036d51) Thanks [@odinr](https://github.com/odinr)! - **New Feature: Enhanced `requestValidationOperator`**
86
+
87
+ The `requestValidationOperator` is a utility function that validates incoming requests against a Zod schema. This function has two options: `strict` and `parse`. The `strict` option allows you to enforce strict validation, while the `parse` option enables you to return the parsed request object if it passes validation.
88
+
89
+ The `requestValidationOperator` is meant to be used as a request operator in the Fusion API framework. It is a higher-order function that takes a Zod schema as an argument and returns a function that validates incoming requests against that schema.
90
+
91
+ | Option | Description | Usage |
92
+ | --------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
93
+ | **Strict Validation** | When `strict` is set to `true`, the validation will fail if there are additional properties not defined in the schema. | If `strict` is set to `false` or omitted, additional properties will be allowed and passed through without causing validation errors. |
94
+ | **Parse Option** | When `parse` is enabled, the function will return the parsed and potentially transformed request object if it passes validation. | If `parse` is not enabled, the function will not return anything even if the request object is valid. |
95
+
96
+ To use the new `strict` and `parse` options, update your code as follows:
97
+
98
+ Example usage with strict validation:
99
+
100
+ ```typescript
101
+ const operator = requestValidationOperator({ strict: true });
102
+
103
+ // This will throw an error because of invalid method and extra property.
104
+ operator({
105
+ method: 'post',
106
+ body: 'foo',
107
+ extraProperty: 'This should not be here',
108
+ });
109
+ ```
110
+
111
+ Example usage with parsing enabled:
112
+
113
+ ```typescript
114
+ // Example usage with parsing enabled
115
+ const operator = requestValidationOperator({ parse: true });
116
+
117
+ // will return { method: 'GET' }
118
+ const parsedRequest = operator({
119
+ method: 'GET',
120
+ extraProperty: 'This should not be here',
121
+ });
122
+ ```
123
+
124
+ Example usage with both strict validation and parsing enabled:
125
+
126
+ ```typescript
127
+ const operator = requestValidationOperator({ strict: true, parse: true });
128
+
129
+ // will throw an error because of extra property.
130
+ const parsedStrictRequest = operator({
131
+ method: 'GET',
132
+ extraProperty: 'This should not be here',
133
+ });
134
+ ```
135
+
136
+ Example usage with the `HttpClient`:
137
+
138
+ ```typescript
139
+ const httpClient = new HttpClient();
140
+
141
+ // Add the request validation operator to the HttpClient.
142
+ httpClient.requestHandler.add('validate-init', requestValidationOperator({ parse: true }));
143
+
144
+ // will throw an error because of invalid method.
145
+ httpClient.get('https://example.com', { method: 'get' });
146
+ ```
147
+
3
148
  ## 6.1.0
4
149
 
5
150
  ### Minor Changes
package/README.md CHANGED
@@ -703,6 +703,55 @@ client.requestHandler.add(
703
703
  );
704
704
  ```
705
705
 
706
+ ##### Available Request Handlers
707
+
708
+ __`capitalizeRequestMethodOperator`__
709
+
710
+ operator to ensure that the HTTP method of a given request is in uppercase.
711
+
712
+ > [!NOTE]
713
+ > by default this plugin will log a warning if the method was not in uppercase.
714
+ > This can be disabled by setting the `silent` option to `true`.
715
+
716
+ ```typescript
717
+ import { capitalizeRequestMethodOperator } from '@equinor/fusion-framework-module-http/operators';
718
+ client.requestHandler.add(
719
+ 'capatalize-method',
720
+ capitalizeRequestMethodOperator()
721
+ );
722
+
723
+ // transforms `method` to uppercase and logs a warning.
724
+ client.get('https://example.com', { method: 'get' });
725
+ ```
726
+
727
+ __`requestValidationOperator`__
728
+
729
+ operator to validate the request before it is sent.
730
+
731
+ > [!NOTE]
732
+ > By default this plugin will only log a warning if the request is invalid.
733
+ > To allow the plugin to modify `FetchRequest` set the `parse` option to `true`.
734
+ > __NOTE__ this will also throw an error if the request is invalid.
735
+
736
+ ```typescript
737
+ import { requestValidationOperator } from '@equinor/fusion-framework-module-http/operators';
738
+ client.requestHandler.add(
739
+ 'validate-request',
740
+ requestValidationOperator(
741
+ {
742
+ // use parsed schema values for request
743
+ parse: true,
744
+ // only allow defined defined options
745
+ strict: false,
746
+ }
747
+ )
748
+ );
749
+ ```
750
+
751
+ > [!WARNING]
752
+ > Validating `RequestInit` should not be necessary, but a helpful tool for development.
753
+
754
+
706
755
  #### Response Handlers
707
756
 
708
757
  > [!IMPORTANT]
@@ -1,4 +1,4 @@
1
- import { HttpRequestHandler } from './lib/operators';
1
+ import { capitalizeRequestMethodOperator, requestValidationOperator, HttpRequestHandler, } from './lib/operators';
2
2
  /** @inheritdoc */
3
3
  export class HttpClientConfigurator {
4
4
  /** Get a clone of all configured clients */
@@ -12,7 +12,12 @@ export class HttpClientConfigurator {
12
12
  constructor(client) {
13
13
  this._clients = {};
14
14
  /** default request handler for http clients, applied on creation */
15
- this.defaultHttpRequestHandler = new HttpRequestHandler();
15
+ this.defaultHttpRequestHandler = new HttpRequestHandler({
16
+ // convert all request methods to uppercase
17
+ ['capitalize-method']: capitalizeRequestMethodOperator(),
18
+ // validate the request object
19
+ ['request-validation']: requestValidationOperator(),
20
+ });
16
21
  this.defaultHttpClientCtor = client;
17
22
  }
18
23
  /** @inheritdoc */
@@ -1 +1 @@
1
- {"version":3,"file":"configurator.js","sourceRoot":"","sources":["../../src/configurator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAuHrD,kBAAkB;AAClB,MAAM,OAAO,sBAAsB;IAK/B,4CAA4C;IAC5C,IAAW,OAAO;QACd,yBAAY,IAAI,CAAC,QAAQ,EAAG;IAChC,CAAC;IAUD;;;OAGG;IACH,YAAY,MAAsC;QAnBxC,aAAQ,GAA+C,EAAE,CAAC;QAUpE,oEAAoE;QAC3D,8BAAyB,GAAG,IAAI,kBAAkB,EAExD,CAAC;QAOA,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC;IACxC,CAAC;IAED,kBAAkB;IAClB,SAAS,CAAC,IAAY;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,kBAAkB;IAClB,eAAe,CACX,IAAY,EACZ,IAAsE;QAEtE,MAAM,KAAK,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAE,EAAE,OAAO,EAAE,IAAI,EAA2B,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5F,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAC1E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,mCACZ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAClB,OAAiD,CACxD,CAAC;Q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CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { requestMethodCasing } from './fetch-request.schema';
2
+ /**
3
+ * Ensures that the HTTP method of the given request is in uppercase.
4
+ *
5
+ * @param request - The HTTP request object to process.
6
+ * @returns A new request object with the HTTP method in uppercase.
7
+ */
8
+ export const capitalizeRequestMethodOperator = (options) => (request) => {
9
+ var _a;
10
+ const { error, success, data } = requestMethodCasing().safeParse(request.method);
11
+ request.method = success ? data : (_a = request.method) === null || _a === void 0 ? void 0 : _a.toUpperCase();
12
+ if (error && !(options === null || options === void 0 ? void 0 : options.silent)) {
13
+ error.errors.forEach((e) => console.warn(e.message));
14
+ }
15
+ return request;
16
+ };
17
+ //# sourceMappingURL=capitalize-request-method.operator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capitalize-request-method.operator.js","sourceRoot":"","sources":["../../../../src/lib/operators/capitalize-request-method.operator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GACxC,CAAwB,OAA8B,EAAsB,EAAE,CAC9E,CAAC,OAAO,EAAK,EAAE;;IACX,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,mBAAmB,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjF,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAA,OAAO,CAAC,MAAM,0CAAE,WAAW,EAAE,CAAC;IAEhE,IAAI,KAAK,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA,EAAE,CAAC;QAC5B,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Validates that the provided HTTP method string is in uppercase.
4
+ *
5
+ * @link https://www.rfc-editor.org/rfc/rfc7231#section-4.1
6
+ */
7
+ export const requestMethodCasing = () => {
8
+ return z.custom((value) => value === (value === null || value === void 0 ? void 0 : value.toUpperCase()), (value) => ({
9
+ code: z.ZodIssueCode.custom,
10
+ validation: 'uppercase',
11
+ path: ['method'],
12
+ message: [
13
+ `Provided HTTP method '${value}' must be in uppercase.`,
14
+ 'See RFC 7231 Section 4.1 for more information',
15
+ 'https://www.rfc-editor.org/rfc/rfc7231#section-4.1',
16
+ ].join(' '),
17
+ }));
18
+ };
19
+ /**
20
+ * Creates a Zod enum schema for HTTP request methods.
21
+ *
22
+ * The schema validates that the value is one of the standard HTTP methods:
23
+ * 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE'.
24
+ *
25
+ * If the validation fails, a custom error message is returned, indicating the
26
+ * expected methods and the received value. The error message also references
27
+ * RFC 2616 for more information.
28
+ *
29
+ * @link https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
30
+ */
31
+ export const requestMethodVerb = () => {
32
+ return z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD', 'CONNECT', 'TRACE'], {
33
+ errorMap: (error) => {
34
+ const { received, options } = error;
35
+ return {
36
+ message: [
37
+ 'Invalid request method.',
38
+ `Expected '${options.join(' | ')}', but received '${received}'.`,
39
+ 'See RFC 2615 Section 9 for more information',
40
+ 'https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html',
41
+ ].join(' '),
42
+ };
43
+ },
44
+ });
45
+ };
46
+ export const requestMethod = () => requestMethodCasing().pipe(requestMethodVerb());
47
+ /**
48
+ * Schema for validating the initialization options of a request.
49
+ *
50
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
51
+ *
52
+ * This schema is used to ensure that the request options conform to the expected structure and types.
53
+ */
54
+ export const requestInitSchema = z.object({
55
+ attributionReporting: z
56
+ .object({
57
+ eventSourceEligible: z.boolean().optional(),
58
+ triggerEligible: z.boolean().optional(),
59
+ })
60
+ .optional(),
61
+ body: z
62
+ .union([
63
+ z.string(),
64
+ z.instanceof(Blob),
65
+ z.instanceof(ArrayBuffer),
66
+ z.instanceof(FormData),
67
+ z.instanceof(URLSearchParams),
68
+ z.instanceof(ReadableStream),
69
+ ])
70
+ .optional(),
71
+ browsingTopics: z.boolean().optional(),
72
+ cache: z
73
+ .enum(['default', 'no-store', 'reload', 'no-cache', 'force-cache', 'only-if-cached'])
74
+ .optional(),
75
+ credentials: z.enum(['omit', 'same-origin', 'include']).optional(),
76
+ headers: z.record(z.string(), z.string()).optional().or(z.instanceof(Headers)),
77
+ integrity: z.string().optional(),
78
+ keepalive: z.boolean().optional(),
79
+ method: requestMethod().optional(),
80
+ mode: z.enum(['same-origin', 'cors', 'no-cors', 'navigate', 'websocket']).optional(),
81
+ priority: z.enum(['low', 'high', 'auto']).optional(),
82
+ redirect: z.enum(['follow', 'error', 'manual']).optional(),
83
+ referrer: z.string().optional(),
84
+ referrerPolicy: z
85
+ .enum([
86
+ 'no-referrer',
87
+ 'no-referrer-when-downgrade',
88
+ 'origin',
89
+ 'origin-when-cross-origin',
90
+ 'same-origin',
91
+ 'strict-origin',
92
+ 'strict-origin-when-cross-origin',
93
+ 'unsafe-url',
94
+ ])
95
+ .optional(),
96
+ signal: z.instanceof(AbortSignal).optional(),
97
+ });
98
+ /**
99
+ * Schema for validating fetch request configurations.
100
+ *
101
+ * This schema extends the `requestInitSchema` and adds additional properties:
102
+ * - `uri`: A required string representing the URI of the request.
103
+ * - `path`: An optional string representing the path of the request.
104
+ */
105
+ export const fetchRequestSchema = requestInitSchema.extend({
106
+ uri: z.string(),
107
+ path: z.string().optional(),
108
+ });
109
+ //# sourceMappingURL=fetch-request.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-request.schema.js","sourceRoot":"","sources":["../../../../src/lib/operators/fetch-request.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAsB,EAAE;IACvD,OAAO,CAAC,CAAC,MAAM,CACX,CAAC,KAAc,EAAE,EAAE,CAAC,KAAK,MAAK,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,EAAE,CAAA,EAClD,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC;QAChB,IAAI,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM;QAC3B,UAAU,EAAE,WAAW;QACvB,IAAI,EAAE,CAAC,QAAQ,CAAC;QAChB,OAAO,EAAE;YACL,yBAAyB,KAAK,yBAAyB;YACvD,+CAA+C;YAC/C,oDAAoD;SACvD,CAAC,IAAI,CAAC,GAAG,CAAC;KACd,CAAC,CACL,CAAC;AACN,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAClC,OAAO,CAAC,CAAC,IAAI,CACT,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,EAChF;QACI,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAChB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,KAAmC,CAAC;YAClE,OAAO;gBACH,OAAO,EAAE;oBACL,yBAAyB;oBACzB,aAAa,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,oBAAoB,QAAQ,IAAI;oBAChE,6CAA6C;oBAC7C,wDAAwD;iBAC3D,CAAC,IAAI,CAAC,G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AAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9E,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACjC,MAAM,EAAE,aAAa,EAAE,CAAC,QAAQ,EAAE;IAClC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,EAAE;IACpF,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE;IACpD,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE;IAC1D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,cAAc,EAAE,CAAC;SACZ,IAAI,CAAC;QACF,aAAa;QACb,4BAA4B;QAC5B,QAAQ;QACR,0BAA0B;QAC1B,aAAa;QACb,eAAe;QACf,iCAAiC;QACjC,YAAY;KACf,CAAC;SACD,QAAQ,EAAE;IACf,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE;CAC/C,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,MAAM,CAAC;IACvD,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC"}
@@ -1,5 +1,7 @@
1
1
  export { HttpRequestHandler } from './http-request-handler';
2
2
  export { HttpResponseHandler } from './http-response-handler';
3
3
  export { ProcessOperators } from './process-operators';
4
+ export { capitalizeRequestMethodOperator } from './capitalize-request-method.operator';
5
+ export { requestValidationOperator } from './request-validation.operator';
4
6
  export * from './types';
5
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/operators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/operators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,cAAc,SAAS,CAAC"}
@@ -50,6 +50,16 @@ export class ProcessOperators {
50
50
  this._operators[key] = operator;
51
51
  return this;
52
52
  }
53
+ /**
54
+ * Removes an operator from the collection by its key.
55
+ *
56
+ * @param key - The key of the operator to remove.
57
+ * @returns The current instance of `ProcessOperators` for method chaining.
58
+ */
59
+ remove(key) {
60
+ delete this._operators[key];
61
+ return this;
62
+ }
53
63
  /**
54
64
  * Retrieves an operator from the collection by its key.
55
65
  * @param key The key of the operator to retrieve.
@@ -1 +1 @@
1
- {"version":3,"file":"process-operators.js","sourceRoot":"","sources":["../../../../src/lib/operators/process-operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM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,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAC5C,SAAS;QACL,iEAAiE;QACjE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,cAAD,CAAC,GAAI,KAAK,CAAC;QAC7E,gBAAgB;QAChB,OAAO;QACP,yCAAyC;QACzC,CAAC,CACJ;QACD,iCAAiC;QACjC,IAAI,EAAE,CACT,CAAC;IACN,CAAC;CACJ"}
1
+ {"version":3,"file":"process-operators.js","sourceRoot":"","sources":["../../../../src/lib/operators/process-operators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGjD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAQzB;;;OAGG;IACH,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,YAAY,SAAqE;QAC7E,IAAI,SAAS,IAAI,WAAW,IAAI,SAAS,EAAE,CAAC;YACxC,IAAI,CAAC,UAAU,qBAAQ,SAAS,CAAC,SAAS,CAAE,CAAC;QACjD,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,UAAU,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,EAAE,CAAC;QACtC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,GAAG,CAAC,GAAW,EAAE,QAA4B;QACzC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;YAC1C,MAAM,KAAK,CAAC,aAAa,GAAG,mBAAmB,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAW,EAAE,QAA4B;QACzC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;QAChC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAW;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAAU;QACd,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACjD,mEAAmE;QACnE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAC5C,SAAS;QACL,iEAAiE;QACjE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAD,CAAC,cAAD,CAAC,GAAI,KAAK,CAAC;QAC7E,gBAAgB;QAChB,OAAO;QACP,yCAAyC;QACzC,CAAC,CACJ;QACD,iCAAiC;QACjC,IAAI,EAAE,CACT,CAAC;IACN,CAAC;CACJ"}
@@ -0,0 +1,29 @@
1
+ import { fetchRequestSchema } from './fetch-request.schema';
2
+ /**
3
+ * Validates the given request using the `requestInitSchema`.
4
+ *
5
+ * By default, the validation is not strict, meaning that additional properties
6
+ * not defined in the schema will be allowed and passed through without causing validation errors.
7
+ * Also the operator will not modify the request object, it will only log an error message if the validation fails.
8
+ *
9
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request
10
+ *
11
+ * @param request - The request object to be validated.
12
+ * @returns The validated request object if validation is successful.
13
+ * @throws Will log an error message if the request validation fails.
14
+ */
15
+ export const requestValidationOperator = (options) => (request) => {
16
+ const { strict, parse } = options !== null && options !== void 0 ? options : {};
17
+ const schema = strict ? fetchRequestSchema : fetchRequestSchema.passthrough();
18
+ try {
19
+ const result = schema.parse(request);
20
+ return parse ? result : void 0;
21
+ }
22
+ catch (error) {
23
+ if (parse) {
24
+ throw error;
25
+ }
26
+ console.error('Invalid request options', error.message);
27
+ }
28
+ };
29
+ //# sourceMappingURL=request-validation.operator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-validation.operator.js","sourceRoot":"","sources":["../../../../src/lib/operators/request-validation.operator.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAClC,CAAyB,OAiBxB,EAAsB,EAAE,CACzB,CAAC,OAAO,EAAE,EAAE;IACR,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,WAAW,EAAE,CAAC;IAC9E,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAM,CAAC;QAC1C,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,KAAK,EAAE,CAAC;YACR,MAAM,KAAK,CAAC;QAChB,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAG,KAAoB,CAAC,OAAO,CAAC,CAAC;IAC5E,CAAC;AACL,CAAC,CAAC"}
@@ -1,3 +1,3 @@
1
1
  // Generated by genversion.
2
- export const version = '6.1.0';
2
+ export const version = '6.2.0';
3
3
  //# sourceMappingURL=version.js.map