@arcraz/common 1.0.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/LICENSE +190 -0
- package/README.md +373 -0
- package/dist/aws/bedrock/client-factory.d.ts +45 -0
- package/dist/aws/bedrock/client-factory.d.ts.map +1 -0
- package/dist/aws/bedrock/client-factory.js +113 -0
- package/dist/aws/bedrock/index.d.ts +3 -0
- package/dist/aws/bedrock/index.d.ts.map +1 -0
- package/dist/aws/bedrock/index.js +1 -0
- package/dist/aws/bedrock/types.d.ts +95 -0
- package/dist/aws/bedrock/types.d.ts.map +1 -0
- package/dist/aws/bedrock/types.js +1 -0
- package/dist/aws/cloudfront/index.d.ts +3 -0
- package/dist/aws/cloudfront/index.d.ts.map +1 -0
- package/dist/aws/cloudfront/index.js +1 -0
- package/dist/aws/cloudfront/signer-factory.d.ts +36 -0
- package/dist/aws/cloudfront/signer-factory.d.ts.map +1 -0
- package/dist/aws/cloudfront/signer-factory.js +75 -0
- package/dist/aws/cloudfront/types.d.ts +52 -0
- package/dist/aws/cloudfront/types.d.ts.map +1 -0
- package/dist/aws/cloudfront/types.js +1 -0
- package/dist/aws/s3/client-factory.d.ts +13 -0
- package/dist/aws/s3/client-factory.d.ts.map +1 -0
- package/dist/aws/s3/client-factory.js +25 -0
- package/dist/aws/s3/index.d.ts +4 -0
- package/dist/aws/s3/index.d.ts.map +1 -0
- package/dist/aws/s3/index.js +2 -0
- package/dist/aws/s3/operations.d.ts +106 -0
- package/dist/aws/s3/operations.d.ts.map +1 -0
- package/dist/aws/s3/operations.js +234 -0
- package/dist/aws/s3/types.d.ts +88 -0
- package/dist/aws/s3/types.d.ts.map +1 -0
- package/dist/aws/s3/types.js +1 -0
- package/dist/caches/api-cache.d.ts +40 -0
- package/dist/caches/api-cache.d.ts.map +1 -0
- package/dist/caches/api-cache.js +65 -0
- package/dist/caches/database-cache.d.ts +40 -0
- package/dist/caches/database-cache.d.ts.map +1 -0
- package/dist/caches/database-cache.js +65 -0
- package/dist/caches/index.d.ts +3 -0
- package/dist/caches/index.d.ts.map +1 -0
- package/dist/caches/index.js +2 -0
- package/dist/config/env-loader.d.ts +28 -0
- package/dist/config/env-loader.d.ts.map +1 -0
- package/dist/config/env-loader.js +39 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/schemas.d.ts +193 -0
- package/dist/config/schemas.d.ts.map +1 -0
- package/dist/config/schemas.js +92 -0
- package/dist/config/types.d.ts +23 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/constants/cache-durations.d.ts +29 -0
- package/dist/constants/cache-durations.d.ts.map +1 -0
- package/dist/constants/cache-durations.js +27 -0
- package/dist/constants/defaults.d.ts +50 -0
- package/dist/constants/defaults.d.ts.map +1 -0
- package/dist/constants/defaults.js +49 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +2 -0
- package/dist/database/base-repository.d.ts +45 -0
- package/dist/database/base-repository.d.ts.map +1 -0
- package/dist/database/base-repository.js +57 -0
- package/dist/database/helpers/converter-helper.d.ts +9 -0
- package/dist/database/helpers/converter-helper.d.ts.map +1 -0
- package/dist/database/helpers/converter-helper.js +20 -0
- package/dist/database/helpers/index.d.ts +3 -0
- package/dist/database/helpers/index.d.ts.map +1 -0
- package/dist/database/helpers/index.js +2 -0
- package/dist/database/helpers/paged-response-helper.d.ts +33 -0
- package/dist/database/helpers/paged-response-helper.d.ts.map +1 -0
- package/dist/database/helpers/paged-response-helper.js +64 -0
- package/dist/database/index.d.ts +6 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +4 -0
- package/dist/database/pool-factory.d.ts +24 -0
- package/dist/database/pool-factory.d.ts.map +1 -0
- package/dist/database/pool-factory.js +91 -0
- package/dist/database/query-helpers.d.ts +36 -0
- package/dist/database/query-helpers.d.ts.map +1 -0
- package/dist/database/query-helpers.js +68 -0
- package/dist/database/types.d.ts +55 -0
- package/dist/database/types.d.ts.map +1 -0
- package/dist/database/types.js +1 -0
- package/dist/helpers/data-obscurer.d.ts +18 -0
- package/dist/helpers/data-obscurer.d.ts.map +1 -0
- package/dist/helpers/data-obscurer.js +29 -0
- package/dist/helpers/enum-converters.d.ts +27 -0
- package/dist/helpers/enum-converters.d.ts.map +1 -0
- package/dist/helpers/enum-converters.js +37 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/remove-sensitive-values.d.ts +20 -0
- package/dist/helpers/remove-sensitive-values.d.ts.map +1 -0
- package/dist/helpers/remove-sensitive-values.js +72 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/logging/formatters.d.ts +19 -0
- package/dist/logging/formatters.d.ts.map +1 -0
- package/dist/logging/formatters.js +94 -0
- package/dist/logging/index.d.ts +4 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/logger-factory.d.ts +8 -0
- package/dist/logging/logger-factory.d.ts.map +1 -0
- package/dist/logging/logger-factory.js +86 -0
- package/dist/logging/types.d.ts +52 -0
- package/dist/logging/types.d.ts.map +1 -0
- package/dist/logging/types.js +1 -0
- package/dist/rabbitmq/connection-factory.d.ts +8 -0
- package/dist/rabbitmq/connection-factory.d.ts.map +1 -0
- package/dist/rabbitmq/connection-factory.js +117 -0
- package/dist/rabbitmq/consumer.d.ts +44 -0
- package/dist/rabbitmq/consumer.d.ts.map +1 -0
- package/dist/rabbitmq/consumer.js +107 -0
- package/dist/rabbitmq/index.d.ts +6 -0
- package/dist/rabbitmq/index.d.ts.map +1 -0
- package/dist/rabbitmq/index.js +4 -0
- package/dist/rabbitmq/namespace-helpers.d.ts +33 -0
- package/dist/rabbitmq/namespace-helpers.d.ts.map +1 -0
- package/dist/rabbitmq/namespace-helpers.js +44 -0
- package/dist/rabbitmq/publisher.d.ts +27 -0
- package/dist/rabbitmq/publisher.d.ts.map +1 -0
- package/dist/rabbitmq/publisher.js +94 -0
- package/dist/rabbitmq/types.d.ts +94 -0
- package/dist/rabbitmq/types.d.ts.map +1 -0
- package/dist/rabbitmq/types.js +1 -0
- package/dist/redis/client-factory.d.ts +14 -0
- package/dist/redis/client-factory.d.ts.map +1 -0
- package/dist/redis/client-factory.js +98 -0
- package/dist/redis/index.d.ts +6 -0
- package/dist/redis/index.d.ts.map +1 -0
- package/dist/redis/index.js +4 -0
- package/dist/redis/namespace-helpers.d.ts +33 -0
- package/dist/redis/namespace-helpers.d.ts.map +1 -0
- package/dist/redis/namespace-helpers.js +43 -0
- package/dist/redis/operations/index.d.ts +3 -0
- package/dist/redis/operations/index.d.ts.map +1 -0
- package/dist/redis/operations/index.js +2 -0
- package/dist/redis/operations/list.d.ts +102 -0
- package/dist/redis/operations/list.d.ts.map +1 -0
- package/dist/redis/operations/list.js +136 -0
- package/dist/redis/operations/standard.d.ts +85 -0
- package/dist/redis/operations/standard.d.ts.map +1 -0
- package/dist/redis/operations/standard.js +136 -0
- package/dist/redis/types.d.ts +81 -0
- package/dist/redis/types.d.ts.map +1 -0
- package/dist/redis/types.js +8 -0
- package/dist/security/cors-factory.d.ts +28 -0
- package/dist/security/cors-factory.d.ts.map +1 -0
- package/dist/security/cors-factory.js +73 -0
- package/dist/security/helmet-factory.d.ts +14 -0
- package/dist/security/helmet-factory.d.ts.map +1 -0
- package/dist/security/helmet-factory.js +80 -0
- package/dist/security/index.d.ts +4 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +2 -0
- package/dist/security/types.d.ts +103 -0
- package/dist/security/types.d.ts.map +1 -0
- package/dist/security/types.js +1 -0
- package/dist/types/custom-types.d.ts +102 -0
- package/dist/types/custom-types.d.ts.map +1 -0
- package/dist/types/custom-types.js +45 -0
- package/dist/types/enums.d.ts +26 -0
- package/dist/types/enums.d.ts.map +1 -0
- package/dist/types/enums.js +30 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/package.json +154 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { ListPosition } from '../types.js';
|
|
2
|
+
import { processKey } from '../namespace-helpers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Adds an element to a list
|
|
5
|
+
* @param redis Redis instance
|
|
6
|
+
* @param key The list key
|
|
7
|
+
* @param position Where to add (front or back)
|
|
8
|
+
* @param data The data to add
|
|
9
|
+
* @param useNamespace Whether to apply namespace
|
|
10
|
+
* @returns Length of list after operation
|
|
11
|
+
*/
|
|
12
|
+
export async function listPush(redis, key, position, data, useNamespace = true) {
|
|
13
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
14
|
+
if (position === ListPosition.FrontOfList) {
|
|
15
|
+
return redis.client.lpush(finalKey, data);
|
|
16
|
+
}
|
|
17
|
+
return redis.client.rpush(finalKey, data);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Adds an element to the front of a list
|
|
21
|
+
* @param redis Redis instance
|
|
22
|
+
* @param key The list key
|
|
23
|
+
* @param data The data to add
|
|
24
|
+
* @param useNamespace Whether to apply namespace
|
|
25
|
+
* @returns Length of list after operation
|
|
26
|
+
*/
|
|
27
|
+
export async function lpush(redis, key, data, useNamespace = true) {
|
|
28
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
29
|
+
return redis.client.lpush(finalKey, data);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Adds an element to the back of a list
|
|
33
|
+
* @param redis Redis instance
|
|
34
|
+
* @param key The list key
|
|
35
|
+
* @param data The data to add
|
|
36
|
+
* @param useNamespace Whether to apply namespace
|
|
37
|
+
* @returns Length of list after operation
|
|
38
|
+
*/
|
|
39
|
+
export async function rpush(redis, key, data, useNamespace = true) {
|
|
40
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
41
|
+
return redis.client.rpush(finalKey, data);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Removes and returns the first element of a list
|
|
45
|
+
* @param redis Redis instance
|
|
46
|
+
* @param key The list key
|
|
47
|
+
* @param useNamespace Whether to apply namespace
|
|
48
|
+
* @returns The element or null if list is empty
|
|
49
|
+
*/
|
|
50
|
+
export async function lpop(redis, key, useNamespace = true) {
|
|
51
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
52
|
+
return redis.client.lpop(finalKey);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Removes and returns the last element of a list
|
|
56
|
+
* @param redis Redis instance
|
|
57
|
+
* @param key The list key
|
|
58
|
+
* @param useNamespace Whether to apply namespace
|
|
59
|
+
* @returns The element or null if list is empty
|
|
60
|
+
*/
|
|
61
|
+
export async function rpop(redis, key, useNamespace = true) {
|
|
62
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
63
|
+
return redis.client.rpop(finalKey);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets a range of elements from a list
|
|
67
|
+
* @param redis Redis instance
|
|
68
|
+
* @param key The list key
|
|
69
|
+
* @param start Start index (0-based)
|
|
70
|
+
* @param stop Stop index (inclusive, -1 for end)
|
|
71
|
+
* @param useNamespace Whether to apply namespace
|
|
72
|
+
* @returns Array of elements
|
|
73
|
+
*/
|
|
74
|
+
export async function lrange(redis, key, start, stop, useNamespace = true) {
|
|
75
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
76
|
+
return redis.client.lrange(finalKey, start, stop);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Gets all elements from a list
|
|
80
|
+
* @param redis Redis instance
|
|
81
|
+
* @param key The list key
|
|
82
|
+
* @param useNamespace Whether to apply namespace
|
|
83
|
+
* @returns Array of all elements
|
|
84
|
+
*/
|
|
85
|
+
export async function lgetall(redis, key, useNamespace = true) {
|
|
86
|
+
return lrange(redis, key, 0, -1, useNamespace);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets the length of a list
|
|
90
|
+
* @param redis Redis instance
|
|
91
|
+
* @param key The list key
|
|
92
|
+
* @param useNamespace Whether to apply namespace
|
|
93
|
+
* @returns Length of list
|
|
94
|
+
*/
|
|
95
|
+
export async function llen(redis, key, useNamespace = true) {
|
|
96
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
97
|
+
return redis.client.llen(finalKey);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Gets an element at a specific index
|
|
101
|
+
* @param redis Redis instance
|
|
102
|
+
* @param key The list key
|
|
103
|
+
* @param index The index
|
|
104
|
+
* @param useNamespace Whether to apply namespace
|
|
105
|
+
* @returns The element or null
|
|
106
|
+
*/
|
|
107
|
+
export async function lindex(redis, key, index, useNamespace = true) {
|
|
108
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
109
|
+
return redis.client.lindex(finalKey, index);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Sets an element at a specific index
|
|
113
|
+
* @param redis Redis instance
|
|
114
|
+
* @param key The list key
|
|
115
|
+
* @param index The index
|
|
116
|
+
* @param value The new value
|
|
117
|
+
* @param useNamespace Whether to apply namespace
|
|
118
|
+
* @returns 'OK' on success
|
|
119
|
+
*/
|
|
120
|
+
export async function lset(redis, key, index, value, useNamespace = true) {
|
|
121
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
122
|
+
return redis.client.lset(finalKey, index, value);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Trims a list to the specified range
|
|
126
|
+
* @param redis Redis instance
|
|
127
|
+
* @param key The list key
|
|
128
|
+
* @param start Start index
|
|
129
|
+
* @param stop Stop index
|
|
130
|
+
* @param useNamespace Whether to apply namespace
|
|
131
|
+
* @returns 'OK' on success
|
|
132
|
+
*/
|
|
133
|
+
export async function ltrim(redis, key, start, stop, useNamespace = true) {
|
|
134
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
135
|
+
return redis.client.ltrim(finalKey, start, stop);
|
|
136
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { RedisInstance, RedisData, SetOptions, GetOptions } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sets a key with optional expiration
|
|
4
|
+
* @param redis Redis instance
|
|
5
|
+
* @param key The key to set
|
|
6
|
+
* @param data The data to store
|
|
7
|
+
* @param options Set options including TTL and namespace
|
|
8
|
+
* @returns 'OK' on success, null if conditional set failed
|
|
9
|
+
*/
|
|
10
|
+
export declare function set(redis: RedisInstance, key: string, data: RedisData, options?: SetOptions): Promise<string | null>;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the value of a key
|
|
13
|
+
* @param redis Redis instance
|
|
14
|
+
* @param key The key to get
|
|
15
|
+
* @param options Get options
|
|
16
|
+
* @returns The value or null if not found
|
|
17
|
+
*/
|
|
18
|
+
export declare function get(redis: RedisInstance, key: string, options?: GetOptions): Promise<string | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Deletes one or more keys
|
|
21
|
+
* @param redis Redis instance
|
|
22
|
+
* @param keys Keys to delete
|
|
23
|
+
* @param useNamespace Whether to apply namespace
|
|
24
|
+
* @returns Number of keys deleted
|
|
25
|
+
*/
|
|
26
|
+
export declare function del(redis: RedisInstance, keys: string | string[], useNamespace?: boolean): Promise<number>;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a key exists
|
|
29
|
+
* @param redis Redis instance
|
|
30
|
+
* @param key The key to check
|
|
31
|
+
* @param useNamespace Whether to apply namespace
|
|
32
|
+
* @returns true if key exists
|
|
33
|
+
*/
|
|
34
|
+
export declare function exists(redis: RedisInstance, key: string, useNamespace?: boolean): Promise<boolean>;
|
|
35
|
+
/**
|
|
36
|
+
* Gets all keys matching a pattern
|
|
37
|
+
* @param redis Redis instance
|
|
38
|
+
* @param pattern Pattern to match
|
|
39
|
+
* @param useNamespace Whether to apply namespace
|
|
40
|
+
* @returns Array of matching keys
|
|
41
|
+
*/
|
|
42
|
+
export declare function keys(redis: RedisInstance, pattern: string, useNamespace?: boolean): Promise<string[]>;
|
|
43
|
+
/**
|
|
44
|
+
* Sets a key's time to live in seconds
|
|
45
|
+
* @param redis Redis instance
|
|
46
|
+
* @param key The key
|
|
47
|
+
* @param seconds TTL in seconds
|
|
48
|
+
* @param useNamespace Whether to apply namespace
|
|
49
|
+
* @returns true if TTL was set
|
|
50
|
+
*/
|
|
51
|
+
export declare function expire(redis: RedisInstance, key: string, seconds: number, useNamespace?: boolean): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the remaining TTL of a key
|
|
54
|
+
* @param redis Redis instance
|
|
55
|
+
* @param key The key
|
|
56
|
+
* @param useNamespace Whether to apply namespace
|
|
57
|
+
* @returns TTL in seconds, -1 if no expiry, -2 if key doesn't exist
|
|
58
|
+
*/
|
|
59
|
+
export declare function ttl(redis: RedisInstance, key: string, useNamespace?: boolean): Promise<number>;
|
|
60
|
+
/**
|
|
61
|
+
* Increments a key's integer value
|
|
62
|
+
* @param redis Redis instance
|
|
63
|
+
* @param key The key
|
|
64
|
+
* @param useNamespace Whether to apply namespace
|
|
65
|
+
* @returns New value after increment
|
|
66
|
+
*/
|
|
67
|
+
export declare function incr(redis: RedisInstance, key: string, useNamespace?: boolean): Promise<number>;
|
|
68
|
+
/**
|
|
69
|
+
* Increments a key's integer value by a specific amount
|
|
70
|
+
* @param redis Redis instance
|
|
71
|
+
* @param key The key
|
|
72
|
+
* @param increment Amount to increment by
|
|
73
|
+
* @param useNamespace Whether to apply namespace
|
|
74
|
+
* @returns New value after increment
|
|
75
|
+
*/
|
|
76
|
+
export declare function incrBy(redis: RedisInstance, key: string, increment: number, useNamespace?: boolean): Promise<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Decrements a key's integer value
|
|
79
|
+
* @param redis Redis instance
|
|
80
|
+
* @param key The key
|
|
81
|
+
* @param useNamespace Whether to apply namespace
|
|
82
|
+
* @returns New value after decrement
|
|
83
|
+
*/
|
|
84
|
+
export declare function decr(redis: RedisInstance, key: string, useNamespace?: boolean): Promise<number>;
|
|
85
|
+
//# sourceMappingURL=standard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard.d.ts","sourceRoot":"","sources":["../../../src/redis/operations/standard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGpF;;;;;;;GAOG;AACH,wBAAsB,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyB9H;AAED;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAG7G;AAED;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAItH;AAED;;;;;;GAMG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAI9G;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAGjH;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAI/H;AAED;;;;;;GAMG;AACH,wBAAsB,GAAG,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAG1G;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3G;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAGhI;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3G"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { processKey } from '../namespace-helpers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sets a key with optional expiration
|
|
4
|
+
* @param redis Redis instance
|
|
5
|
+
* @param key The key to set
|
|
6
|
+
* @param data The data to store
|
|
7
|
+
* @param options Set options including TTL and namespace
|
|
8
|
+
* @returns 'OK' on success, null if conditional set failed
|
|
9
|
+
*/
|
|
10
|
+
export async function set(redis, key, data, options = {}) {
|
|
11
|
+
const finalKey = processKey(key, options.useNamespace ?? true, redis.namespace);
|
|
12
|
+
if (options.ttl) {
|
|
13
|
+
if (options.nx) {
|
|
14
|
+
const result = await redis.client.set(finalKey, data, 'EX', options.ttl, 'NX');
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
if (options.xx) {
|
|
18
|
+
const result = await redis.client.set(finalKey, data, 'EX', options.ttl, 'XX');
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
return redis.client.setex(finalKey, options.ttl, data);
|
|
22
|
+
}
|
|
23
|
+
if (options.nx) {
|
|
24
|
+
const result = await redis.client.setnx(finalKey, data);
|
|
25
|
+
return result === 1 ? 'OK' : null;
|
|
26
|
+
}
|
|
27
|
+
if (options.xx) {
|
|
28
|
+
const result = await redis.client.set(finalKey, data, 'XX');
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
return redis.client.set(finalKey, data);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Gets the value of a key
|
|
35
|
+
* @param redis Redis instance
|
|
36
|
+
* @param key The key to get
|
|
37
|
+
* @param options Get options
|
|
38
|
+
* @returns The value or null if not found
|
|
39
|
+
*/
|
|
40
|
+
export async function get(redis, key, options = {}) {
|
|
41
|
+
const finalKey = processKey(key, options.useNamespace ?? true, redis.namespace);
|
|
42
|
+
return redis.client.get(finalKey);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Deletes one or more keys
|
|
46
|
+
* @param redis Redis instance
|
|
47
|
+
* @param keys Keys to delete
|
|
48
|
+
* @param useNamespace Whether to apply namespace
|
|
49
|
+
* @returns Number of keys deleted
|
|
50
|
+
*/
|
|
51
|
+
export async function del(redis, keys, useNamespace = true) {
|
|
52
|
+
const keysArray = Array.isArray(keys) ? keys : [keys];
|
|
53
|
+
const finalKeys = keysArray.map((k) => processKey(k, useNamespace, redis.namespace));
|
|
54
|
+
return redis.client.del(...finalKeys);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks if a key exists
|
|
58
|
+
* @param redis Redis instance
|
|
59
|
+
* @param key The key to check
|
|
60
|
+
* @param useNamespace Whether to apply namespace
|
|
61
|
+
* @returns true if key exists
|
|
62
|
+
*/
|
|
63
|
+
export async function exists(redis, key, useNamespace = true) {
|
|
64
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
65
|
+
const result = await redis.client.exists(finalKey);
|
|
66
|
+
return result === 1;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets all keys matching a pattern
|
|
70
|
+
* @param redis Redis instance
|
|
71
|
+
* @param pattern Pattern to match
|
|
72
|
+
* @param useNamespace Whether to apply namespace
|
|
73
|
+
* @returns Array of matching keys
|
|
74
|
+
*/
|
|
75
|
+
export async function keys(redis, pattern, useNamespace = true) {
|
|
76
|
+
const finalPattern = processKey(pattern, useNamespace, redis.namespace);
|
|
77
|
+
return redis.client.keys(finalPattern);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sets a key's time to live in seconds
|
|
81
|
+
* @param redis Redis instance
|
|
82
|
+
* @param key The key
|
|
83
|
+
* @param seconds TTL in seconds
|
|
84
|
+
* @param useNamespace Whether to apply namespace
|
|
85
|
+
* @returns true if TTL was set
|
|
86
|
+
*/
|
|
87
|
+
export async function expire(redis, key, seconds, useNamespace = true) {
|
|
88
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
89
|
+
const result = await redis.client.expire(finalKey, seconds);
|
|
90
|
+
return result === 1;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gets the remaining TTL of a key
|
|
94
|
+
* @param redis Redis instance
|
|
95
|
+
* @param key The key
|
|
96
|
+
* @param useNamespace Whether to apply namespace
|
|
97
|
+
* @returns TTL in seconds, -1 if no expiry, -2 if key doesn't exist
|
|
98
|
+
*/
|
|
99
|
+
export async function ttl(redis, key, useNamespace = true) {
|
|
100
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
101
|
+
return redis.client.ttl(finalKey);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Increments a key's integer value
|
|
105
|
+
* @param redis Redis instance
|
|
106
|
+
* @param key The key
|
|
107
|
+
* @param useNamespace Whether to apply namespace
|
|
108
|
+
* @returns New value after increment
|
|
109
|
+
*/
|
|
110
|
+
export async function incr(redis, key, useNamespace = true) {
|
|
111
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
112
|
+
return redis.client.incr(finalKey);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Increments a key's integer value by a specific amount
|
|
116
|
+
* @param redis Redis instance
|
|
117
|
+
* @param key The key
|
|
118
|
+
* @param increment Amount to increment by
|
|
119
|
+
* @param useNamespace Whether to apply namespace
|
|
120
|
+
* @returns New value after increment
|
|
121
|
+
*/
|
|
122
|
+
export async function incrBy(redis, key, increment, useNamespace = true) {
|
|
123
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
124
|
+
return redis.client.incrby(finalKey, increment);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Decrements a key's integer value
|
|
128
|
+
* @param redis Redis instance
|
|
129
|
+
* @param key The key
|
|
130
|
+
* @param useNamespace Whether to apply namespace
|
|
131
|
+
* @returns New value after decrement
|
|
132
|
+
*/
|
|
133
|
+
export async function decr(redis, key, useNamespace = true) {
|
|
134
|
+
const finalKey = processKey(key, useNamespace, redis.namespace);
|
|
135
|
+
return redis.client.decr(finalKey);
|
|
136
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Redis, Cluster } from 'ioredis';
|
|
2
|
+
/**
|
|
3
|
+
* Redis client type - either single instance or cluster
|
|
4
|
+
*/
|
|
5
|
+
export type RedisClient = Redis | Cluster;
|
|
6
|
+
/**
|
|
7
|
+
* Data types that can be stored in Redis
|
|
8
|
+
*/
|
|
9
|
+
export type RedisData = Buffer | number | string;
|
|
10
|
+
/**
|
|
11
|
+
* List position for lpush/rpush operations
|
|
12
|
+
*/
|
|
13
|
+
export declare enum ListPosition {
|
|
14
|
+
FrontOfList = "FRONT",
|
|
15
|
+
BackOfList = "BACK"
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Redis instance interface wrapping the client with helper methods
|
|
19
|
+
*/
|
|
20
|
+
export interface RedisInstance {
|
|
21
|
+
/** The underlying ioredis client */
|
|
22
|
+
client: RedisClient;
|
|
23
|
+
/** Whether this is a cluster connection */
|
|
24
|
+
isCluster: boolean;
|
|
25
|
+
/** Default namespace for keys */
|
|
26
|
+
namespace: string;
|
|
27
|
+
/** Close the connection */
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
/** Check if connected */
|
|
30
|
+
isConnected(): boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for single Redis instance
|
|
34
|
+
*/
|
|
35
|
+
export interface RedisInstanceConfig {
|
|
36
|
+
host: string;
|
|
37
|
+
port?: number;
|
|
38
|
+
password?: string;
|
|
39
|
+
db?: number;
|
|
40
|
+
keyPrefix?: string;
|
|
41
|
+
tls?: boolean;
|
|
42
|
+
connectTimeout?: number;
|
|
43
|
+
commandTimeout?: number;
|
|
44
|
+
namespace?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Configuration for Redis cluster
|
|
48
|
+
*/
|
|
49
|
+
export interface RedisClusterInstanceConfig {
|
|
50
|
+
nodes: {
|
|
51
|
+
host: string;
|
|
52
|
+
port: number;
|
|
53
|
+
}[];
|
|
54
|
+
password?: string;
|
|
55
|
+
keyPrefix?: string;
|
|
56
|
+
tls?: boolean;
|
|
57
|
+
connectTimeout?: number;
|
|
58
|
+
commandTimeout?: number;
|
|
59
|
+
namespace?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Options for Redis set operations
|
|
63
|
+
*/
|
|
64
|
+
export interface SetOptions {
|
|
65
|
+
/** Time to live in seconds */
|
|
66
|
+
ttl?: number;
|
|
67
|
+
/** Only set if key doesn't exist */
|
|
68
|
+
nx?: boolean;
|
|
69
|
+
/** Only set if key exists */
|
|
70
|
+
xx?: boolean;
|
|
71
|
+
/** Whether to append environment namespace */
|
|
72
|
+
useNamespace?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Options for Redis get operations
|
|
76
|
+
*/
|
|
77
|
+
export interface GetOptions {
|
|
78
|
+
/** Whether to append environment namespace */
|
|
79
|
+
useNamespace?: boolean;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/redis/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,OAAO,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjD;;GAEG;AACH,oBAAY,YAAY;IACtB,WAAW,UAAU;IACrB,UAAU,SAAS;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,oCAAoC;IACpC,MAAM,EAAE,WAAW,CAAC;IACpB,2CAA2C;IAC3C,SAAS,EAAE,OAAO,CAAC;IACnB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,2BAA2B;IAC3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,yBAAyB;IACzB,WAAW,IAAI,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,8BAA8B;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,6BAA6B;IAC7B,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,8CAA8C;IAC9C,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CorsConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a CORS configuration object
|
|
4
|
+
* @param overrides Optional configuration overrides
|
|
5
|
+
* @returns CORS configuration
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCorsConfig(overrides?: Partial<CorsConfig>): CorsConfig;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a permissive CORS configuration for development
|
|
10
|
+
* WARNING: Do not use in production!
|
|
11
|
+
* @returns Permissive CORS configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function createDevCorsConfig(): CorsConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a CORS configuration for specific origins
|
|
16
|
+
* @param origins Allowed origins
|
|
17
|
+
* @param options Additional options
|
|
18
|
+
* @returns CORS configuration
|
|
19
|
+
*/
|
|
20
|
+
export declare function createOriginCorsConfig(origins: string | string[], options?: Partial<Omit<CorsConfig, 'origin'>>): CorsConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a CORS configuration with a dynamic origin validator
|
|
23
|
+
* @param validator Function that returns true if origin is allowed
|
|
24
|
+
* @param options Additional options
|
|
25
|
+
* @returns CORS configuration
|
|
26
|
+
*/
|
|
27
|
+
export declare function createDynamicCorsConfig(validator: (origin: string | undefined) => boolean, options?: Partial<Omit<CorsConfig, 'origin'>>): CorsConfig;
|
|
28
|
+
//# sourceMappingURL=cors-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors-factory.d.ts","sourceRoot":"","sources":["../../src/security/cors-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAe7C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,GAAE,OAAO,CAAC,UAAU,CAAM,GAAG,UAAU,CAKhF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,UAAU,CAUhD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAM,GAAG,UAAU,CAOhI;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,EAAE,OAAO,GAAE,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAM,GAAG,UAAU,CAYzJ"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default CORS configuration (restrictive)
|
|
3
|
+
*/
|
|
4
|
+
const DEFAULT_CORS_CONFIG = {
|
|
5
|
+
origin: false,
|
|
6
|
+
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
|
|
7
|
+
allowedHeaders: ['Content-Type', 'Authorization'],
|
|
8
|
+
credentials: false,
|
|
9
|
+
maxAge: 86400, // 24 hours
|
|
10
|
+
preflightContinue: false,
|
|
11
|
+
optionsSuccessStatus: 204
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a CORS configuration object
|
|
15
|
+
* @param overrides Optional configuration overrides
|
|
16
|
+
* @returns CORS configuration
|
|
17
|
+
*/
|
|
18
|
+
export function createCorsConfig(overrides = {}) {
|
|
19
|
+
return {
|
|
20
|
+
...DEFAULT_CORS_CONFIG,
|
|
21
|
+
...overrides
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a permissive CORS configuration for development
|
|
26
|
+
* WARNING: Do not use in production!
|
|
27
|
+
* @returns Permissive CORS configuration
|
|
28
|
+
*/
|
|
29
|
+
export function createDevCorsConfig() {
|
|
30
|
+
return {
|
|
31
|
+
origin: true,
|
|
32
|
+
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE', 'OPTIONS'],
|
|
33
|
+
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
|
34
|
+
credentials: true,
|
|
35
|
+
maxAge: 86400,
|
|
36
|
+
preflightContinue: false,
|
|
37
|
+
optionsSuccessStatus: 204
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a CORS configuration for specific origins
|
|
42
|
+
* @param origins Allowed origins
|
|
43
|
+
* @param options Additional options
|
|
44
|
+
* @returns CORS configuration
|
|
45
|
+
*/
|
|
46
|
+
export function createOriginCorsConfig(origins, options = {}) {
|
|
47
|
+
return {
|
|
48
|
+
...DEFAULT_CORS_CONFIG,
|
|
49
|
+
origin: origins,
|
|
50
|
+
credentials: true,
|
|
51
|
+
...options
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a CORS configuration with a dynamic origin validator
|
|
56
|
+
* @param validator Function that returns true if origin is allowed
|
|
57
|
+
* @param options Additional options
|
|
58
|
+
* @returns CORS configuration
|
|
59
|
+
*/
|
|
60
|
+
export function createDynamicCorsConfig(validator, options = {}) {
|
|
61
|
+
return {
|
|
62
|
+
...DEFAULT_CORS_CONFIG,
|
|
63
|
+
...options,
|
|
64
|
+
origin: (origin, callback) => {
|
|
65
|
+
if (!origin || validator(origin)) {
|
|
66
|
+
callback(null, true);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
callback(new Error('Not allowed by CORS'));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HelmetConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a Helmet configuration object
|
|
4
|
+
* @param overrides Optional configuration overrides
|
|
5
|
+
* @returns Helmet configuration
|
|
6
|
+
*/
|
|
7
|
+
export declare function createHelmetConfig(overrides?: Partial<HelmetConfig>): HelmetConfig;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a Helmet configuration for API-only services
|
|
10
|
+
* @param overrides Optional configuration overrides
|
|
11
|
+
* @returns Helmet configuration for APIs
|
|
12
|
+
*/
|
|
13
|
+
export declare function createApiHelmetConfig(overrides?: Partial<HelmetConfig>): HelmetConfig;
|
|
14
|
+
//# sourceMappingURL=helmet-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helmet-factory.d.ts","sourceRoot":"","sources":["../../src/security/helmet-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA8D/C;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,YAAY,CAKtF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,GAAE,OAAO,CAAC,YAAY,CAAM,GAAG,YAAY,CAKzF"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default secure Helmet configuration
|
|
3
|
+
*/
|
|
4
|
+
const DEFAULT_HELMET_CONFIG = {
|
|
5
|
+
contentSecurityPolicy: {
|
|
6
|
+
directives: {
|
|
7
|
+
defaultSrc: ["'self'"], // eslint-disable-line quotes
|
|
8
|
+
scriptSrc: ["'self'"], // eslint-disable-line quotes
|
|
9
|
+
styleSrc: ["'self'", "'unsafe-inline'"], // eslint-disable-line quotes
|
|
10
|
+
imgSrc: ["'self'", 'data:', 'https:'], // eslint-disable-line quotes
|
|
11
|
+
fontSrc: ["'self'"], // eslint-disable-line quotes
|
|
12
|
+
objectSrc: ["'none'"], // eslint-disable-line quotes
|
|
13
|
+
frameAncestors: ["'none'"], // eslint-disable-line quotes
|
|
14
|
+
formAction: ["'self'"], // eslint-disable-line quotes
|
|
15
|
+
upgradeInsecureRequests: []
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
crossOriginEmbedderPolicy: true,
|
|
19
|
+
crossOriginOpenerPolicy: { policy: 'same-origin' },
|
|
20
|
+
crossOriginResourcePolicy: { policy: 'same-origin' },
|
|
21
|
+
dnsPrefetchControl: { allow: false },
|
|
22
|
+
frameguard: { action: 'deny' },
|
|
23
|
+
hidePoweredBy: true,
|
|
24
|
+
hsts: {
|
|
25
|
+
maxAge: 31536000, // 1 year
|
|
26
|
+
includeSubDomains: true,
|
|
27
|
+
preload: true
|
|
28
|
+
},
|
|
29
|
+
ieNoOpen: true,
|
|
30
|
+
noSniff: true,
|
|
31
|
+
originAgentCluster: true,
|
|
32
|
+
permittedCrossDomainPolicies: { permittedPolicies: 'none' },
|
|
33
|
+
referrerPolicy: { policy: 'strict-origin-when-cross-origin' },
|
|
34
|
+
xssFilter: true
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Helmet configuration for API-only services (no CSP needed)
|
|
38
|
+
*/
|
|
39
|
+
const API_HELMET_CONFIG = {
|
|
40
|
+
contentSecurityPolicy: false,
|
|
41
|
+
crossOriginEmbedderPolicy: false,
|
|
42
|
+
crossOriginOpenerPolicy: false,
|
|
43
|
+
crossOriginResourcePolicy: { policy: 'cross-origin' },
|
|
44
|
+
dnsPrefetchControl: { allow: false },
|
|
45
|
+
frameguard: { action: 'deny' },
|
|
46
|
+
hidePoweredBy: true,
|
|
47
|
+
hsts: {
|
|
48
|
+
maxAge: 31536000,
|
|
49
|
+
includeSubDomains: true,
|
|
50
|
+
preload: true
|
|
51
|
+
},
|
|
52
|
+
ieNoOpen: true,
|
|
53
|
+
noSniff: true,
|
|
54
|
+
originAgentCluster: true,
|
|
55
|
+
permittedCrossDomainPolicies: { permittedPolicies: 'none' },
|
|
56
|
+
referrerPolicy: { policy: 'strict-origin-when-cross-origin' },
|
|
57
|
+
xssFilter: true
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Creates a Helmet configuration object
|
|
61
|
+
* @param overrides Optional configuration overrides
|
|
62
|
+
* @returns Helmet configuration
|
|
63
|
+
*/
|
|
64
|
+
export function createHelmetConfig(overrides = {}) {
|
|
65
|
+
return {
|
|
66
|
+
...DEFAULT_HELMET_CONFIG,
|
|
67
|
+
...overrides
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a Helmet configuration for API-only services
|
|
72
|
+
* @param overrides Optional configuration overrides
|
|
73
|
+
* @returns Helmet configuration for APIs
|
|
74
|
+
*/
|
|
75
|
+
export function createApiHelmetConfig(overrides = {}) {
|
|
76
|
+
return {
|
|
77
|
+
...API_HELMET_CONFIG,
|
|
78
|
+
...overrides
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createHelmetConfig, createApiHelmetConfig } from './helmet-factory.js';
|
|
2
|
+
export { createCorsConfig, createDevCorsConfig, createOriginCorsConfig, createDynamicCorsConfig } from './cors-factory.js';
|
|
3
|
+
export type { HelmetConfig, ContentSecurityPolicyConfig, HstsConfig, CorsConfig, CorsOriginCallback, RateLimitConfig } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC3H,YAAY,EAAE,YAAY,EAAE,2BAA2B,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|