@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,33 @@
|
|
|
1
|
+
import type { PagedResponse } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Helper class for handling paginated database queries
|
|
4
|
+
*/
|
|
5
|
+
export declare class PagedResponseHelper<T = unknown> {
|
|
6
|
+
readonly pageNumber: number;
|
|
7
|
+
readonly pageSize: number;
|
|
8
|
+
constructor(page?: number, size?: number);
|
|
9
|
+
/**
|
|
10
|
+
* Get LIMIT value for SQL query
|
|
11
|
+
*/
|
|
12
|
+
get limit(): number;
|
|
13
|
+
/**
|
|
14
|
+
* Get OFFSET value for SQL query
|
|
15
|
+
*/
|
|
16
|
+
get offset(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Calculate total page count from total results
|
|
19
|
+
* @param totalResults Total number of results
|
|
20
|
+
* @returns Number of pages
|
|
21
|
+
*/
|
|
22
|
+
pageCount(totalResults: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Build a PagedResponse from query results
|
|
25
|
+
* Expects results to have a `fullCount` property from COUNT(*) OVER()
|
|
26
|
+
* @param results Query results with optional fullCount property
|
|
27
|
+
* @returns Formatted PagedResponse
|
|
28
|
+
*/
|
|
29
|
+
result(results?: (T & {
|
|
30
|
+
fullCount?: string | number;
|
|
31
|
+
})[] | null | undefined): PagedResponse<T>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=paged-response-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paged-response-helper.d.ts","sourceRoot":"","sources":["../../../src/database/helpers/paged-response-helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;GAEG;AACH,qBAAa,mBAAmB,CAAC,CAAC,GAAG,OAAO;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,IAAI,GAAE,MAAyC,EAAE,IAAI,GAAE,MAAsC;IAKzG;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;;OAIG;IACH,SAAS,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;IAOvC;;;;;OAKG;IACH,MAAM,CAAC,OAAO,GAAE,CAAC,CAAC,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC,EAAE,GAAG,IAAI,GAAG,SAAc,GAAG,aAAa,CAAC,CAAC,CAAC;CA2BnG"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { PAGINATION_DEFAULTS } from '../../constants/defaults.js';
|
|
2
|
+
/**
|
|
3
|
+
* Helper class for handling paginated database queries
|
|
4
|
+
*/
|
|
5
|
+
export class PagedResponseHelper {
|
|
6
|
+
pageNumber;
|
|
7
|
+
pageSize;
|
|
8
|
+
constructor(page = PAGINATION_DEFAULTS.DEFAULT_PAGE, size = PAGINATION_DEFAULTS.PAGE_SIZE) {
|
|
9
|
+
this.pageNumber = Math.max(1, page);
|
|
10
|
+
this.pageSize = Math.min(Math.max(1, size), PAGINATION_DEFAULTS.MAX_PAGE_SIZE);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get LIMIT value for SQL query
|
|
14
|
+
*/
|
|
15
|
+
get limit() {
|
|
16
|
+
return this.pageSize;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get OFFSET value for SQL query
|
|
20
|
+
*/
|
|
21
|
+
get offset() {
|
|
22
|
+
return (this.pageNumber - 1) * this.pageSize;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Calculate total page count from total results
|
|
26
|
+
* @param totalResults Total number of results
|
|
27
|
+
* @returns Number of pages
|
|
28
|
+
*/
|
|
29
|
+
pageCount(totalResults) {
|
|
30
|
+
if (totalResults <= 0 || this.pageSize <= 0) {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
return Math.ceil(totalResults / this.pageSize);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build a PagedResponse from query results
|
|
37
|
+
* Expects results to have a `fullCount` property from COUNT(*) OVER()
|
|
38
|
+
* @param results Query results with optional fullCount property
|
|
39
|
+
* @returns Formatted PagedResponse
|
|
40
|
+
*/
|
|
41
|
+
result(results = []) {
|
|
42
|
+
let count = 0;
|
|
43
|
+
let processedResults = results ? [...results] : [];
|
|
44
|
+
if (processedResults.length > 0) {
|
|
45
|
+
const firstResult = processedResults[0];
|
|
46
|
+
if (firstResult?.fullCount !== undefined) {
|
|
47
|
+
const parsedCount = parseInt(String(firstResult.fullCount), 10);
|
|
48
|
+
count = isNaN(parsedCount) ? 0 : parsedCount;
|
|
49
|
+
// Remove fullCount from all results
|
|
50
|
+
processedResults = processedResults.map((result) => {
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
|
+
const { fullCount: _fullCount, ...rest } = result;
|
|
53
|
+
return rest;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
pageNumber: this.pageNumber,
|
|
59
|
+
pageCount: this.pageCount(count),
|
|
60
|
+
totalCount: count,
|
|
61
|
+
results: processedResults
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDatabasePool, queryWithCamelCase, queryOneWithCamelCase } from './pool-factory.js';
|
|
2
|
+
export { BaseRepository } from './base-repository.js';
|
|
3
|
+
export { camelCaseRows, camelCaseRow, snakeCaseKeys, setupTypeParsers, parsePostgresArray, toPostgresArray } from './query-helpers.js';
|
|
4
|
+
export { ConverterHelper, PagedResponseHelper } from './helpers/index.js';
|
|
5
|
+
export type { DatabasePool, DatabasePoolConfig, QueryOptions, PagedResponse } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACvI,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createDatabasePool, queryWithCamelCase, queryOneWithCamelCase } from './pool-factory.js';
|
|
2
|
+
export { BaseRepository } from './base-repository.js';
|
|
3
|
+
export { camelCaseRows, camelCaseRow, snakeCaseKeys, setupTypeParsers, parsePostgresArray, toPostgresArray } from './query-helpers.js';
|
|
4
|
+
export { ConverterHelper, PagedResponseHelper } from './helpers/index.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DatabasePool, DatabasePoolConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new database pool instance
|
|
4
|
+
* @param config Database configuration
|
|
5
|
+
* @returns DatabasePool instance with query methods
|
|
6
|
+
*/
|
|
7
|
+
export declare function createDatabasePool(config: DatabasePoolConfig): DatabasePool;
|
|
8
|
+
/**
|
|
9
|
+
* Executes a query and returns camelCased results
|
|
10
|
+
* @param dbPool Database pool instance
|
|
11
|
+
* @param text SQL query text
|
|
12
|
+
* @param values Query parameter values
|
|
13
|
+
* @returns Array of camelCased result rows
|
|
14
|
+
*/
|
|
15
|
+
export declare function queryWithCamelCase<T>(dbPool: DatabasePool, text: string, values?: unknown[]): Promise<T[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Executes a query and returns a single camelCased result
|
|
18
|
+
* @param dbPool Database pool instance
|
|
19
|
+
* @param text SQL query text
|
|
20
|
+
* @param values Query parameter values
|
|
21
|
+
* @returns Single camelCased result or null
|
|
22
|
+
*/
|
|
23
|
+
export declare function queryOneWithCamelCase<T>(dbPool: DatabasePool, text: string, values?: unknown[]): Promise<T | null>;
|
|
24
|
+
//# sourceMappingURL=pool-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool-factory.d.ts","sourceRoot":"","sources":["../../src/database/pool-factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAMnE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAkE3E;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAGhH;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAGxH"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import pg from 'pg';
|
|
2
|
+
import { DATABASE_DEFAULTS } from '../constants/defaults.js';
|
|
3
|
+
import { camelCaseRows } from './query-helpers.js';
|
|
4
|
+
const { Pool } = pg;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new database pool instance
|
|
7
|
+
* @param config Database configuration
|
|
8
|
+
* @returns DatabasePool instance with query methods
|
|
9
|
+
*/
|
|
10
|
+
export function createDatabasePool(config) {
|
|
11
|
+
const pool = new Pool({
|
|
12
|
+
host: config.host,
|
|
13
|
+
port: config.port ?? 5432,
|
|
14
|
+
database: config.database,
|
|
15
|
+
user: config.user,
|
|
16
|
+
password: config.password,
|
|
17
|
+
ssl: config.ssl ?? false,
|
|
18
|
+
max: config.maxConnections ?? DATABASE_DEFAULTS.MAX_CONNECTIONS,
|
|
19
|
+
idleTimeoutMillis: config.idleTimeoutMs ?? DATABASE_DEFAULTS.IDLE_TIMEOUT_MS,
|
|
20
|
+
connectionTimeoutMillis: config.connectionTimeoutMs ?? DATABASE_DEFAULTS.CONNECTION_TIMEOUT_MS,
|
|
21
|
+
statement_timeout: config.statementTimeoutMs ?? DATABASE_DEFAULTS.STATEMENT_TIMEOUT_MS
|
|
22
|
+
});
|
|
23
|
+
let connected = false;
|
|
24
|
+
pool.on('connect', () => {
|
|
25
|
+
connected = true;
|
|
26
|
+
});
|
|
27
|
+
pool.on('error', (err) => {
|
|
28
|
+
console.error('Unexpected database pool error:', err);
|
|
29
|
+
connected = false;
|
|
30
|
+
});
|
|
31
|
+
async function query(text, values) {
|
|
32
|
+
const result = await pool.query(text, values);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
async function getClient() {
|
|
36
|
+
return pool.connect();
|
|
37
|
+
}
|
|
38
|
+
async function transaction(fn) {
|
|
39
|
+
const client = await pool.connect();
|
|
40
|
+
try {
|
|
41
|
+
await client.query('BEGIN');
|
|
42
|
+
const result = await fn(client);
|
|
43
|
+
await client.query('COMMIT');
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
await client.query('ROLLBACK');
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
client.release();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function close() {
|
|
55
|
+
await pool.end();
|
|
56
|
+
connected = false;
|
|
57
|
+
}
|
|
58
|
+
function isConnected() {
|
|
59
|
+
return connected && pool.totalCount > 0;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
pool,
|
|
63
|
+
query,
|
|
64
|
+
getClient,
|
|
65
|
+
transaction,
|
|
66
|
+
close,
|
|
67
|
+
isConnected
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Executes a query and returns camelCased results
|
|
72
|
+
* @param dbPool Database pool instance
|
|
73
|
+
* @param text SQL query text
|
|
74
|
+
* @param values Query parameter values
|
|
75
|
+
* @returns Array of camelCased result rows
|
|
76
|
+
*/
|
|
77
|
+
export async function queryWithCamelCase(dbPool, text, values) {
|
|
78
|
+
const result = await dbPool.query(text, values);
|
|
79
|
+
return camelCaseRows(result.rows);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Executes a query and returns a single camelCased result
|
|
83
|
+
* @param dbPool Database pool instance
|
|
84
|
+
* @param text SQL query text
|
|
85
|
+
* @param values Query parameter values
|
|
86
|
+
* @returns Single camelCased result or null
|
|
87
|
+
*/
|
|
88
|
+
export async function queryOneWithCamelCase(dbPool, text, values) {
|
|
89
|
+
const results = await queryWithCamelCase(dbPool, text, values);
|
|
90
|
+
return results[0] ?? null;
|
|
91
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts query result rows from snake_case to camelCase
|
|
3
|
+
* @param rows Array of row objects to convert
|
|
4
|
+
* @returns Array with camelCase keys
|
|
5
|
+
*/
|
|
6
|
+
export declare function camelCaseRows<T>(rows: Record<string, unknown>[]): T[];
|
|
7
|
+
/**
|
|
8
|
+
* Converts a single row from snake_case to camelCase
|
|
9
|
+
* @param row Row object to convert
|
|
10
|
+
* @returns Object with camelCase keys
|
|
11
|
+
*/
|
|
12
|
+
export declare function camelCaseRow<T>(row: Record<string, unknown> | null | undefined): T | null;
|
|
13
|
+
/**
|
|
14
|
+
* Converts object keys from camelCase to snake_case for database insertion
|
|
15
|
+
* @param obj Object with camelCase keys
|
|
16
|
+
* @returns Object with snake_case keys
|
|
17
|
+
*/
|
|
18
|
+
export declare function snakeCaseKeys<T extends Record<string, unknown>>(obj: T): Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Sets up custom type parsers for PostgreSQL
|
|
21
|
+
* Call this once at application startup
|
|
22
|
+
*/
|
|
23
|
+
export declare function setupTypeParsers(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Converts a PostgreSQL array string to a TypeScript array
|
|
26
|
+
* @param value PostgreSQL array string like "{a,b,c}"
|
|
27
|
+
* @returns Parsed array
|
|
28
|
+
*/
|
|
29
|
+
export declare function parsePostgresArray<T = string>(value: string | null | undefined): T[];
|
|
30
|
+
/**
|
|
31
|
+
* Formats a TypeScript array as a PostgreSQL array literal
|
|
32
|
+
* @param arr Array to format
|
|
33
|
+
* @returns PostgreSQL array literal string
|
|
34
|
+
*/
|
|
35
|
+
export declare function toPostgresArray(arr: (string | number)[]): string;
|
|
36
|
+
//# sourceMappingURL=query-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-helpers.d.ts","sourceRoot":"","sources":["../../src/database/query-helpers.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,EAAE,CAErE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,IAAI,CAGzF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEhG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAevC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,EAAE,CAOpF;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM,CAEhE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as humps from 'humps';
|
|
2
|
+
import pg from 'pg';
|
|
3
|
+
/**
|
|
4
|
+
* Converts query result rows from snake_case to camelCase
|
|
5
|
+
* @param rows Array of row objects to convert
|
|
6
|
+
* @returns Array with camelCase keys
|
|
7
|
+
*/
|
|
8
|
+
export function camelCaseRows(rows) {
|
|
9
|
+
return rows.map((row) => humps.camelizeKeys(row));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Converts a single row from snake_case to camelCase
|
|
13
|
+
* @param row Row object to convert
|
|
14
|
+
* @returns Object with camelCase keys
|
|
15
|
+
*/
|
|
16
|
+
export function camelCaseRow(row) {
|
|
17
|
+
if (!row)
|
|
18
|
+
return null;
|
|
19
|
+
return humps.camelizeKeys(row);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Converts object keys from camelCase to snake_case for database insertion
|
|
23
|
+
* @param obj Object with camelCase keys
|
|
24
|
+
* @returns Object with snake_case keys
|
|
25
|
+
*/
|
|
26
|
+
export function snakeCaseKeys(obj) {
|
|
27
|
+
return humps.decamelizeKeys(obj);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Sets up custom type parsers for PostgreSQL
|
|
31
|
+
* Call this once at application startup
|
|
32
|
+
*/
|
|
33
|
+
export function setupTypeParsers() {
|
|
34
|
+
// Parse NUMERIC as float instead of string
|
|
35
|
+
pg.types.setTypeParser(1700, (val) => parseFloat(val));
|
|
36
|
+
// Keep DATE as string instead of converting to Date object
|
|
37
|
+
pg.types.setTypeParser(1082, (val) => val);
|
|
38
|
+
// Parse BIGINT as number (be careful with very large numbers)
|
|
39
|
+
pg.types.setTypeParser(20, (val) => {
|
|
40
|
+
const num = parseInt(val, 10);
|
|
41
|
+
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
|
|
42
|
+
return BigInt(val);
|
|
43
|
+
}
|
|
44
|
+
return num;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts a PostgreSQL array string to a TypeScript array
|
|
49
|
+
* @param value PostgreSQL array string like "{a,b,c}"
|
|
50
|
+
* @returns Parsed array
|
|
51
|
+
*/
|
|
52
|
+
export function parsePostgresArray(value) {
|
|
53
|
+
if (!value)
|
|
54
|
+
return [];
|
|
55
|
+
return value
|
|
56
|
+
.replace(/^\{/, '')
|
|
57
|
+
.replace(/\}$/, '')
|
|
58
|
+
.split(',')
|
|
59
|
+
.filter((item) => item.length > 0);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Formats a TypeScript array as a PostgreSQL array literal
|
|
63
|
+
* @param arr Array to format
|
|
64
|
+
* @returns PostgreSQL array literal string
|
|
65
|
+
*/
|
|
66
|
+
export function toPostgresArray(arr) {
|
|
67
|
+
return `{${arr.join(',')}}`;
|
|
68
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Pool, PoolClient, QueryResult, QueryResultRow } from 'pg';
|
|
2
|
+
/**
|
|
3
|
+
* Database pool instance interface
|
|
4
|
+
*/
|
|
5
|
+
export interface DatabasePool {
|
|
6
|
+
/** The underlying pg Pool */
|
|
7
|
+
pool: Pool;
|
|
8
|
+
/** Execute a query with automatic connection handling */
|
|
9
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[]): Promise<QueryResult<T>>;
|
|
10
|
+
/** Get a client from the pool for transactions */
|
|
11
|
+
getClient(): Promise<PoolClient>;
|
|
12
|
+
/** Execute a transaction with automatic commit/rollback */
|
|
13
|
+
transaction<T>(fn: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
14
|
+
/** Close the pool */
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
/** Check if pool is connected */
|
|
17
|
+
isConnected(): boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Database configuration for pool creation
|
|
21
|
+
*/
|
|
22
|
+
export interface DatabasePoolConfig {
|
|
23
|
+
name?: string;
|
|
24
|
+
host: string;
|
|
25
|
+
port?: number;
|
|
26
|
+
database: string;
|
|
27
|
+
user: string;
|
|
28
|
+
password: string;
|
|
29
|
+
ssl?: boolean | {
|
|
30
|
+
rejectUnauthorized: boolean;
|
|
31
|
+
};
|
|
32
|
+
maxConnections?: number;
|
|
33
|
+
idleTimeoutMs?: number;
|
|
34
|
+
connectionTimeoutMs?: number;
|
|
35
|
+
statementTimeoutMs?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Query options for executing statements
|
|
39
|
+
*/
|
|
40
|
+
export interface QueryOptions {
|
|
41
|
+
/** Statement timeout in milliseconds */
|
|
42
|
+
timeout?: number;
|
|
43
|
+
/** Whether to camelCase result column names */
|
|
44
|
+
camelCase?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Paged response wrapper for paginated queries
|
|
48
|
+
*/
|
|
49
|
+
export interface PagedResponse<T> {
|
|
50
|
+
pageNumber: number;
|
|
51
|
+
pageCount: number;
|
|
52
|
+
totalCount: number;
|
|
53
|
+
results: T[];
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,IAAI,EAAE,IAAI,CAAC;IACX,yDAAyD;IACzD,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5G,kDAAkD;IAClD,SAAS,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;IACjC,2DAA2D;IAC3D,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnE,qBAAqB;IACrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,iCAAiC;IACjC,WAAW,IAAI,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,GAAG;QAAE,kBAAkB,EAAE,OAAO,CAAA;KAAE,CAAC;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,CAAC,EAAE,CAAC;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface DataObscurerOptions {
|
|
2
|
+
placeholder?: string;
|
|
3
|
+
showLeft?: number;
|
|
4
|
+
showRight?: number;
|
|
5
|
+
trim?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Obscures sensitive data by replacing middle characters with placeholders
|
|
9
|
+
* @param toObscure String to obscure
|
|
10
|
+
* @param options Obscuring options
|
|
11
|
+
* @returns Obscured string
|
|
12
|
+
*/
|
|
13
|
+
export declare function obscureData(toObscure: string, options?: DataObscurerOptions): string;
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use obscureData instead
|
|
16
|
+
*/
|
|
17
|
+
export default function (toObscure: string, options?: DataObscurerOptions): string;
|
|
18
|
+
//# sourceMappingURL=data-obscurer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-obscurer.d.ts","sourceRoot":"","sources":["../../src/helpers/data-obscurer.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AASD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAYxF;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAErF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import hideText from 'hide-text';
|
|
2
|
+
const defaultOptions = {
|
|
3
|
+
placeholder: '#',
|
|
4
|
+
showLeft: 4,
|
|
5
|
+
showRight: 4,
|
|
6
|
+
trim: 0
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Obscures sensitive data by replacing middle characters with placeholders
|
|
10
|
+
* @param toObscure String to obscure
|
|
11
|
+
* @param options Obscuring options
|
|
12
|
+
* @returns Obscured string
|
|
13
|
+
*/
|
|
14
|
+
export function obscureData(toObscure, options = {}) {
|
|
15
|
+
if (!toObscure) {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
19
|
+
if (toObscure.length <= (mergedOptions.showLeft || 0) + (mergedOptions.showRight || 0)) {
|
|
20
|
+
return toObscure;
|
|
21
|
+
}
|
|
22
|
+
return hideText(toObscure, mergedOptions);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use obscureData instead
|
|
26
|
+
*/
|
|
27
|
+
export default function (toObscure, options = {}) {
|
|
28
|
+
return obscureData(toObscure, options);
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely converts a value to an enum type
|
|
3
|
+
* @param value Value to convert
|
|
4
|
+
* @param enumType Enum object to validate against
|
|
5
|
+
* @returns The value as enum type or null if invalid
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertToEnum<ET>(value: unknown, enumType: Record<string, unknown>): ET | null;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a value is a valid enum member
|
|
10
|
+
* @param value Value to check
|
|
11
|
+
* @param enumType Enum object to validate against
|
|
12
|
+
* @returns True if value is a valid enum member
|
|
13
|
+
*/
|
|
14
|
+
export declare function isValidEnumValue<ET>(value: unknown, enumType: Record<string, unknown>): value is ET;
|
|
15
|
+
/**
|
|
16
|
+
* Gets all values of an enum
|
|
17
|
+
* @param enumType Enum object
|
|
18
|
+
* @returns Array of enum values
|
|
19
|
+
*/
|
|
20
|
+
export declare function getEnumValues<T>(enumType: Record<string, T>): T[];
|
|
21
|
+
/**
|
|
22
|
+
* Gets all keys of an enum
|
|
23
|
+
* @param enumType Enum object
|
|
24
|
+
* @returns Array of enum keys
|
|
25
|
+
*/
|
|
26
|
+
export declare function getEnumKeys(enumType: Record<string, unknown>): string[];
|
|
27
|
+
//# sourceMappingURL=enum-converters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-converters.d.ts","sourceRoot":"","sources":["../../src/helpers/enum-converters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAK9F;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,IAAI,EAAE,CAEnG;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAEvE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely converts a value to an enum type
|
|
3
|
+
* @param value Value to convert
|
|
4
|
+
* @param enumType Enum object to validate against
|
|
5
|
+
* @returns The value as enum type or null if invalid
|
|
6
|
+
*/
|
|
7
|
+
export function convertToEnum(value, enumType) {
|
|
8
|
+
if (Object.values(enumType).includes(value)) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Checks if a value is a valid enum member
|
|
15
|
+
* @param value Value to check
|
|
16
|
+
* @param enumType Enum object to validate against
|
|
17
|
+
* @returns True if value is a valid enum member
|
|
18
|
+
*/
|
|
19
|
+
export function isValidEnumValue(value, enumType) {
|
|
20
|
+
return Object.values(enumType).includes(value);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets all values of an enum
|
|
24
|
+
* @param enumType Enum object
|
|
25
|
+
* @returns Array of enum values
|
|
26
|
+
*/
|
|
27
|
+
export function getEnumValues(enumType) {
|
|
28
|
+
return Object.values(enumType);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets all keys of an enum
|
|
32
|
+
* @param enumType Enum object
|
|
33
|
+
* @returns Array of enum keys
|
|
34
|
+
*/
|
|
35
|
+
export function getEnumKeys(enumType) {
|
|
36
|
+
return Object.keys(enumType).filter((key) => isNaN(Number(key)));
|
|
37
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { obscureData } from './data-obscurer.js';
|
|
2
|
+
export type { DataObscurerOptions } from './data-obscurer.js';
|
|
3
|
+
export { convertToEnum, isValidEnumValue, getEnumValues, getEnumKeys } from './enum-converters.js';
|
|
4
|
+
export { removeSensitiveValues, redactSensitiveValues, DEFAULT_SENSITIVE_KEYS } from './remove-sensitive-values.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnG,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively removes specified keys from an object
|
|
3
|
+
* @param obj Object to process
|
|
4
|
+
* @param keysToRemove Keys to remove
|
|
5
|
+
* @returns New object with keys removed
|
|
6
|
+
*/
|
|
7
|
+
export declare function removeSensitiveValues<T>(obj: T, keysToRemove: string[]): T;
|
|
8
|
+
/**
|
|
9
|
+
* Redacts specified keys by replacing their values with a placeholder
|
|
10
|
+
* @param obj Object to process
|
|
11
|
+
* @param keysToRedact Keys to redact
|
|
12
|
+
* @param placeholder Replacement value (default: '[REDACTED]')
|
|
13
|
+
* @returns New object with keys redacted
|
|
14
|
+
*/
|
|
15
|
+
export declare function redactSensitiveValues<T>(obj: T, keysToRedact: string[], placeholder?: string): T;
|
|
16
|
+
/**
|
|
17
|
+
* Default sensitive keys commonly found in applications
|
|
18
|
+
*/
|
|
19
|
+
export declare const DEFAULT_SENSITIVE_KEYS: readonly ["password", "secret", "token", "apiKey", "api_key", "accessToken", "access_token", "refreshToken", "refresh_token", "privateKey", "private_key", "ssn", "creditCard", "credit_card", "cardNumber", "card_number", "cvv", "authorization"];
|
|
20
|
+
//# sourceMappingURL=remove-sensitive-values.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-sensitive-values.d.ts","sourceRoot":"","sources":["../../src/helpers/remove-sensitive-values.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,CAAC,CAoB1E;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,WAAW,GAAE,MAAqB,GAAG,CAAC,CAoB9G;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,qPAmBzB,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively removes specified keys from an object
|
|
3
|
+
* @param obj Object to process
|
|
4
|
+
* @param keysToRemove Keys to remove
|
|
5
|
+
* @returns New object with keys removed
|
|
6
|
+
*/
|
|
7
|
+
export function removeSensitiveValues(obj, keysToRemove) {
|
|
8
|
+
if (obj === null || typeof obj !== 'object') {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(obj)) {
|
|
12
|
+
return obj.map((item) => removeSensitiveValues(item, keysToRemove));
|
|
13
|
+
}
|
|
14
|
+
const objCopy = { ...obj };
|
|
15
|
+
for (const key of Object.keys(objCopy)) {
|
|
16
|
+
if (keysToRemove.includes(key)) {
|
|
17
|
+
delete objCopy[key];
|
|
18
|
+
}
|
|
19
|
+
else if (typeof objCopy[key] === 'object' && objCopy[key] !== null) {
|
|
20
|
+
objCopy[key] = removeSensitiveValues(objCopy[key], keysToRemove);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return objCopy;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Redacts specified keys by replacing their values with a placeholder
|
|
27
|
+
* @param obj Object to process
|
|
28
|
+
* @param keysToRedact Keys to redact
|
|
29
|
+
* @param placeholder Replacement value (default: '[REDACTED]')
|
|
30
|
+
* @returns New object with keys redacted
|
|
31
|
+
*/
|
|
32
|
+
export function redactSensitiveValues(obj, keysToRedact, placeholder = '[REDACTED]') {
|
|
33
|
+
if (obj === null || typeof obj !== 'object') {
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(obj)) {
|
|
37
|
+
return obj.map((item) => redactSensitiveValues(item, keysToRedact, placeholder));
|
|
38
|
+
}
|
|
39
|
+
const objCopy = { ...obj };
|
|
40
|
+
for (const key of Object.keys(objCopy)) {
|
|
41
|
+
if (keysToRedact.includes(key)) {
|
|
42
|
+
objCopy[key] = placeholder;
|
|
43
|
+
}
|
|
44
|
+
else if (typeof objCopy[key] === 'object' && objCopy[key] !== null) {
|
|
45
|
+
objCopy[key] = redactSensitiveValues(objCopy[key], keysToRedact, placeholder);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return objCopy;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Default sensitive keys commonly found in applications
|
|
52
|
+
*/
|
|
53
|
+
export const DEFAULT_SENSITIVE_KEYS = [
|
|
54
|
+
'password',
|
|
55
|
+
'secret',
|
|
56
|
+
'token',
|
|
57
|
+
'apiKey',
|
|
58
|
+
'api_key',
|
|
59
|
+
'accessToken',
|
|
60
|
+
'access_token',
|
|
61
|
+
'refreshToken',
|
|
62
|
+
'refresh_token',
|
|
63
|
+
'privateKey',
|
|
64
|
+
'private_key',
|
|
65
|
+
'ssn',
|
|
66
|
+
'creditCard',
|
|
67
|
+
'credit_card',
|
|
68
|
+
'cardNumber',
|
|
69
|
+
'card_number',
|
|
70
|
+
'cvv',
|
|
71
|
+
'authorization'
|
|
72
|
+
];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './config/index.js';
|
|
2
|
+
export * from './constants/index.js';
|
|
3
|
+
export * from './database/index.js';
|
|
4
|
+
export * from './redis/index.js';
|
|
5
|
+
export * from './rabbitmq/index.js';
|
|
6
|
+
export * from './caches/index.js';
|
|
7
|
+
export * from './logging/index.js';
|
|
8
|
+
export * from './security/index.js';
|
|
9
|
+
export * from './helpers/index.js';
|
|
10
|
+
export * from './types/index.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|