@govish/shared-services 1.4.0 → 1.6.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/CHANGELOG.md +14 -0
- package/README.md +2 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/middleware/authenticateDevice.d.ts +13 -2
- package/dist/middleware/authenticateDevice.js +551 -69
- package/dist/services/apiKeyService.d.ts +2 -1
- package/dist/services/apiKeyService.js +237 -45
- package/dist/services/auditService.d.ts +14 -2
- package/dist/services/auditService.js +289 -12
- package/dist/utils/rollingCache.d.ts +34 -0
- package/dist/utils/rollingCache.js +203 -0
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Version 1.6.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Rolling cache utilities** (`createRollingCache`): list/item pattern with `buildKey`, `get`, `set`, `getOrSet`, `invalidate`, `invalidateByPrefix`, `recordAccess` (Redis `ZINCRBY` for hot-key telemetry), and default TTL helpers from `CACHE_DAYS_LIST` / `CACHE_DAYS_ITEM`. Opt-in via `ROLLING_CACHE_ENABLED` / `CACHE_ENABLED`. Uses the host `redisClient` for `setEx`, `del`, `scan`, and sorted sets.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Version 1.5.1
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- **AuditService**: Fixed `microservice` field in audit logs to always use the receiving service name from `SERVER_NAME` environment variable instead of the API key's microservice. The `source_microservice` and `authenticated_microservice` fields now correctly contain the API key's microservice information.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
3
17
|
## Version 1.4.0
|
|
4
18
|
|
|
5
19
|
### Changed
|
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ const authenticateDeviceOrOfficer = createAuthenticateDeviceOrOfficer(dependenci
|
|
|
37
37
|
|
|
38
38
|
## Utilities Included
|
|
39
39
|
|
|
40
|
+
- **createRollingCache**: List/item rolling cache (`buildKey`, `get`, `set`, `getOrSet`, `invalidate`, `invalidateByPrefix`, `recordAccess`) with day-based TTL from `CACHE_DAYS_LIST` / `CACHE_DAYS_ITEM`; enable with `ROLLING_CACHE_ENABLED=true`
|
|
40
41
|
- **createSafeRedisGet**: Factory function to create a safe Redis GET operation with automatic reconnection
|
|
41
42
|
- **createSafeRedisSet**: Factory function to create a safe Redis SET operation with automatic reconnection
|
|
42
43
|
- **createSafeRedisUtils**: Factory function that creates both safeRedisGet and safeRedisSet functions
|
|
@@ -65,7 +66,7 @@ import {
|
|
|
65
66
|
ApiKeyService,
|
|
66
67
|
createAuthenticateDeviceOrOfficer,
|
|
67
68
|
SharedServicesDependencies
|
|
68
|
-
} from '@
|
|
69
|
+
} from '@govish/shared-services';
|
|
69
70
|
import { redisClient } from './app';
|
|
70
71
|
import { logger } from './utils/logger';
|
|
71
72
|
// ... other dependencies
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export { AuditEventType } from './services/auditService';
|
|
|
13
13
|
export type { AuditEventPayload } from './services/auditService';
|
|
14
14
|
export { createAuthenticateDeviceOrOfficer } from './middleware/authenticateDevice';
|
|
15
15
|
export { createSafeRedisGet, createSafeRedisSet, createSafeRedisUtils } from './utils/redis';
|
|
16
|
+
export { createRollingCache, ROLLING_CACHE_SEP, } from './utils/rollingCache';
|
|
17
|
+
export type { RollingCacheInstance, RollingCacheOptions, RollingCacheTtl, } from './utils/rollingCache';
|
|
16
18
|
export { getEnvironmentMode, isDevelopmentMode, isProductionMode, devLog, devError, devWarn, devDebug } from './utils/logMode';
|
|
17
19
|
export type { EnvironmentMode } from './utils/logMode';
|
|
18
20
|
export type { SharedServicesDependencies } from './types/dependencies';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.devDebug = exports.devWarn = exports.devError = exports.devLog = exports.isProductionMode = exports.isDevelopmentMode = exports.getEnvironmentMode = exports.createSafeRedisUtils = exports.createSafeRedisSet = exports.createSafeRedisGet = exports.createAuthenticateDeviceOrOfficer = exports.AuditEventType = exports.AuditService = exports.ApiKeyService = exports.RankLeaveDaysCacheService = exports.StationDutyBlockCacheService = exports.StationCacheService = exports.DeviceService = exports.DeviceCacheService = exports.PenalCodeCacheService = exports.OfficerService = exports.OfficerCacheService = void 0;
|
|
3
|
+
exports.devDebug = exports.devWarn = exports.devError = exports.devLog = exports.isProductionMode = exports.isDevelopmentMode = exports.getEnvironmentMode = exports.ROLLING_CACHE_SEP = exports.createRollingCache = exports.createSafeRedisUtils = exports.createSafeRedisSet = exports.createSafeRedisGet = exports.createAuthenticateDeviceOrOfficer = exports.AuditEventType = exports.AuditService = exports.ApiKeyService = exports.RankLeaveDaysCacheService = exports.StationDutyBlockCacheService = exports.StationCacheService = exports.DeviceService = exports.DeviceCacheService = exports.PenalCodeCacheService = exports.OfficerService = exports.OfficerCacheService = void 0;
|
|
4
4
|
// Export services
|
|
5
5
|
var officerCacheService_1 = require("./services/officerCacheService");
|
|
6
6
|
Object.defineProperty(exports, "OfficerCacheService", { enumerable: true, get: function () { return officerCacheService_1.OfficerCacheService; } });
|
|
@@ -32,6 +32,9 @@ var redis_1 = require("./utils/redis");
|
|
|
32
32
|
Object.defineProperty(exports, "createSafeRedisGet", { enumerable: true, get: function () { return redis_1.createSafeRedisGet; } });
|
|
33
33
|
Object.defineProperty(exports, "createSafeRedisSet", { enumerable: true, get: function () { return redis_1.createSafeRedisSet; } });
|
|
34
34
|
Object.defineProperty(exports, "createSafeRedisUtils", { enumerable: true, get: function () { return redis_1.createSafeRedisUtils; } });
|
|
35
|
+
var rollingCache_1 = require("./utils/rollingCache");
|
|
36
|
+
Object.defineProperty(exports, "createRollingCache", { enumerable: true, get: function () { return rollingCache_1.createRollingCache; } });
|
|
37
|
+
Object.defineProperty(exports, "ROLLING_CACHE_SEP", { enumerable: true, get: function () { return rollingCache_1.ROLLING_CACHE_SEP; } });
|
|
35
38
|
var logMode_1 = require("./utils/logMode");
|
|
36
39
|
Object.defineProperty(exports, "getEnvironmentMode", { enumerable: true, get: function () { return logMode_1.getEnvironmentMode; } });
|
|
37
40
|
Object.defineProperty(exports, "isDevelopmentMode", { enumerable: true, get: function () { return logMode_1.isDevelopmentMode; } });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from 'express';
|
|
2
2
|
import { SharedServicesDependencies } from '../types/dependencies';
|
|
3
3
|
/**
|
|
4
|
-
* Middleware to authenticate either a device, an officer,
|
|
4
|
+
* Middleware to authenticate either a device, an officer, a microservice (via API key), or combinations thereof
|
|
5
5
|
* Checks JWT token and validates against Device or Officer table
|
|
6
6
|
* Also checks for API keys for microservice authentication
|
|
7
7
|
*
|
|
@@ -10,6 +10,17 @@ import { SharedServicesDependencies } from '../types/dependencies';
|
|
|
10
10
|
* - Device-Token: <device_jwt_token> (for device authentication)
|
|
11
11
|
* - Authorization: Bearer <user_jwt_token> (for officer/user authentication)
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* Supports combined authentication:
|
|
14
|
+
* - API Key + Officer: X-API-Key + Authorization header (sets authType: 'api_key_and_officer')
|
|
15
|
+
* - Device + Officer: Device-Token + Authorization header (sets authType: 'both')
|
|
16
|
+
*
|
|
17
|
+
* Authentication Priority/Combination Logic:
|
|
18
|
+
* 1. API Key + Officer (if both headers present) -> authType: 'api_key_and_officer'
|
|
19
|
+
* 2. API Key only (if only X-API-Key present) -> authType: 'api_key'
|
|
20
|
+
* 3. Device + Officer (if both headers present) -> authType: 'both'
|
|
21
|
+
* 4. Device only (if only Device-Token present) -> authType: 'device'
|
|
22
|
+
* 5. Officer only (if only Authorization present) -> authType: 'officer'
|
|
23
|
+
*
|
|
24
|
+
* At least one authentication method must succeed for the request to proceed.
|
|
14
25
|
*/
|
|
15
26
|
export declare const createAuthenticateDeviceOrOfficer: (deps: SharedServicesDependencies) => (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|