@nrfcloud/lambda-helpers 1.1.9 → 2.0.1

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.
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Returns a Map of headers with keys in lowercase.
3
- * This is useful for consistent header handling, especially in environments
4
- * where header keys may be case-insensitive.
2
+ * Returns case-insensitive headers (a `Headers` instance).
3
+ *
4
+ * `undefined` values are skipped, and entries that are not valid HTTP headers
5
+ * are ignored instead of throwing.
5
6
  */
6
- export declare const parseHeaders: (headers: Record<string, string | undefined> | null) => ParsedHeaders;
7
- export type ParsedHeaders = Pick<Map<string, string | null>, 'get' | 'has' | 'size' | 'keys' | 'values' | 'entries' | 'forEach'>;
8
- export declare const CaseInsensitiveMap: (map: Map<string, string | null>) => ParsedHeaders;
7
+ export declare const parseHeaders: (headers: Record<string, string | undefined> | null | undefined) => ParsedHeaders;
8
+ export type ParsedHeaders = Pick<Headers, 'get' | 'has' | 'keys' | 'values' | 'entries' | 'forEach'>;
@@ -1,20 +1,17 @@
1
1
  /**
2
- * Returns a Map of headers with keys in lowercase.
3
- * This is useful for consistent header handling, especially in environments
4
- * where header keys may be case-insensitive.
2
+ * Returns case-insensitive headers (a `Headers` instance).
3
+ *
4
+ * `undefined` values are skipped, and entries that are not valid HTTP headers
5
+ * are ignored instead of throwing.
5
6
  */ export const parseHeaders = (headers)=>{
6
- if (headers === null) return new Map();
7
- return CaseInsensitiveMap(Object.entries(headers).reduce((h, [key, value])=>{
8
- h.set(key.toLowerCase(), value ?? null);
9
- return h;
10
- }, new Map()));
7
+ const parsed = new Headers();
8
+ for (const [key, value] of Object.entries(headers ?? {})){
9
+ if (value === undefined || value === null) continue;
10
+ try {
11
+ parsed.set(key, value);
12
+ } catch {
13
+ // Ignore invalid header names or values
14
+ }
15
+ }
16
+ return parsed;
11
17
  };
12
- export const CaseInsensitiveMap = (map)=>({
13
- get: (key)=>map.get(key.toLowerCase()),
14
- has: (key)=>map.has(key.toLowerCase()),
15
- size: map.size,
16
- keys: ()=>map.keys(),
17
- values: ()=>map.values(),
18
- entries: ()=>map.entries(),
19
- forEach: (callback, thisArg)=>map.forEach(callback, thisArg)
20
- });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nrfcloud/lambda-helpers",
3
- "version": "1.1.9",
3
+ "version": "2.0.1",
4
4
  "description": "Helper functions for AWS Lambda functions used in nRF Cloud.",
5
5
  "homepage": "https://github.com/nRFCloud/lambda-helpers#readme",
6
6
  "bugs": {
@@ -66,7 +66,7 @@
66
66
  "npm": ">=12.0.2 <13"
67
67
  },
68
68
  "dependencies": {
69
- "@aws-lambda-powertools/metrics": "2.36.0",
69
+ "@aws-lambda-powertools/metrics": "2.37.0",
70
70
  "@middy/core": "7.9.2",
71
71
  "@middy/input-output-logger": "7.9.2",
72
72
  "@nrfcloud/problem-detail": "1.7.1",