@govish/shared-services 1.2.0 → 1.4.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 CHANGED
@@ -1,11 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 1.4.0
4
+
5
+ ### Changed
6
+ - **StationDutyBlockCacheService**: Fetching data only (read-only). Get methods: `getBlocks`, `getBlocksByStationId`, `getBlock`, `getSectors`, `getSector`. App remains responsible for storing and invalidating cache.
7
+
8
+ ---
9
+
10
+ ## Version 1.3.0
11
+
12
+ ### Added
13
+ - **StationDutyBlockCacheService**: `getBlocksByStationId(stationId)` — get blocks by station ID from cache (key `station_blocks:${stationId}`; app populates)
14
+
15
+ ---
16
+
3
17
  ## Version 1.2.0
4
18
 
5
19
  ### Added
6
20
  - **StationDutyBlockCacheService**: Read-only cache for station-duty blocks and sectors
7
- - Keys: `station_duty_blocks:${stationDutyId}`, `station_duty_block:${blockId}`, `block_sectors:${blockId}`, `block_sector:${sectorId}`
8
- - `getBlocks(stationDutyId)`, `getBlock(blockId, stationDutyId?)`, `getSectors(blockId)`, `getSector(sectorId, blockId?)`
21
+ - Keys: `station_duty_blocks:${stationDutyId}`, `station_duty_block:${blockId}`, `block_sectors:${blockId}`, `block_sector:${sectorId}`, `station_blocks:${stationId}`
22
+ - `getBlocks(stationDutyId)`, `getBlocksByStationId(stationId)`, `getBlock(blockId, stationDutyId?)`, `getSectors(blockId)`, `getSector(sectorId, blockId?)`
9
23
  - **RankLeaveDaysCacheService**: Read-only cache for rank leave days
10
24
  - Keys: `rank_leave_days:${rankId}`, `rank_leave_day:${leaveDayId}`
11
25
  - `getLeaveDays(rankId)`, `getLeaveDay(leaveDayId, rankId?)`
package/README.md CHANGED
@@ -29,7 +29,7 @@ const authenticateDeviceOrOfficer = createAuthenticateDeviceOrOfficer(dependenci
29
29
  - **PenalCodeCacheService**: Redis-based caching service for penal codes
30
30
  - **DeviceCacheService**: Redis-based caching service for devices with indexing
31
31
  - **StationCacheService**: Redis-based caching service for police stations (JSON list, set of IDs, and per-station hashes)
32
- - **StationDutyBlockCacheService**: Read-only cache for station-duty blocks and sectors (`getBlocks`, `getBlock`, `getSectors`, `getSector`)
32
+ - **StationDutyBlockCacheService**: Read-only cache for station-duty blocks and sectors — fetch only (`getBlocks`, `getBlocksByStationId`, `getBlock`, `getSectors`, `getSector`)
33
33
  - **RankLeaveDaysCacheService**: Read-only cache for rank leave days (`getLeaveDays`, `getLeaveDay`)
34
34
  - **ApiKeyService**: Service for managing and validating API keys with Redis caching
35
35
  - **AuditService**: Service for logging audit events to Kafka with comprehensive event tracking
@@ -11,6 +11,11 @@ export declare class StationDutyBlockCacheService {
11
11
  * Get blocks for a station-duty from cache. Returns null on miss.
12
12
  */
13
13
  getBlocks(stationDutyId: number): Promise<Array<Record<string, unknown>> | null>;
14
+ /**
15
+ * Get blocks for a station by station ID from cache. Returns null on miss.
16
+ * App must populate key `station_blocks:${stationId}` with a JSON array of blocks for this to hit.
17
+ */
18
+ getBlocksByStationId(stationId: number): Promise<Array<Record<string, unknown>> | null>;
14
19
  /**
15
20
  * Get one block by ID from cache. Returns null on miss.
16
21
  * If stationDutyId is provided, returns null when cached block's station_duty_id does not match.
@@ -10,8 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.StationDutyBlockCacheService = void 0;
13
- /** Redis keys (must match app that writes: station_duty_blocks, station_duty_block, block_sectors, block_sector) */
13
+ /** Redis keys (must match app that writes: station_duty_blocks, station_duty_block, block_sectors, block_sector, station_blocks) */
14
14
  const BLOCKS_KEY = (stationDutyId) => `station_duty_blocks:${stationDutyId}`;
15
+ const BLOCKS_BY_STATION_KEY = (stationId) => `station_blocks:${stationId}`;
15
16
  const BLOCK_KEY = (blockId) => `station_duty_block:${blockId}`;
16
17
  const SECTORS_KEY = (blockId) => `block_sectors:${blockId}`;
17
18
  const SECTOR_KEY = (sectorId) => `block_sector:${sectorId}`;
@@ -56,6 +57,28 @@ class StationDutyBlockCacheService {
56
57
  }
57
58
  });
58
59
  }
60
+ /**
61
+ * Get blocks for a station by station ID from cache. Returns null on miss.
62
+ * App must populate key `station_blocks:${stationId}` with a JSON array of blocks for this to hit.
63
+ */
64
+ getBlocksByStationId(stationId) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ try {
67
+ const key = BLOCKS_BY_STATION_KEY(stationId);
68
+ const cached = yield this.redisClient.get(key);
69
+ if (!cached)
70
+ return null;
71
+ return safeJsonParse(cached, null, this.logger);
72
+ }
73
+ catch (error) {
74
+ this.logger.error('Error getting blocks by station from cache', {
75
+ error: error instanceof Error ? error.message : String(error),
76
+ stationId,
77
+ });
78
+ return null;
79
+ }
80
+ });
81
+ }
59
82
  /**
60
83
  * Get one block by ID from cache. Returns null on miss.
61
84
  * If stationDutyId is provided, returns null when cached block's station_duty_id does not match.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@govish/shared-services",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Govish shared services package - officer, device, station, penal code, station-duty block, and rank leave days cache services; API key service; audit logging; authentication middleware",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",