plac-micro-common 1.3.66 → 1.3.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,4 @@
1
- export declare const REDIS_CLIENTS = "REDIS_CLIENTS";
2
- /**
3
- * Named client token helper (if you want to inject a specific client directly)
4
- * Example: @Inject(getRedisClientToken('geo')) private geoRedis: Redis
5
- */
6
- export declare const getRedisClientToken: (name: string) => string;
7
- /**
8
- * Backward compatible tokens:
9
- * - REDIS_CLIENT is the "main" redis client
10
- * - REDIS_GEO_CLIENT is the "geo" redis client
11
- */
12
- export declare const REDIS_CLIENT: string;
13
- export declare const REDIS_GEO_CLIENT: string;
1
+ export declare const REDIS_CLIENT = "REDIS_CLIENT";
14
2
  export type RedisModuleOptions = {
15
3
  url?: string;
16
4
  host?: string;
@@ -1,17 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REDIS_GEO_CLIENT = exports.REDIS_CLIENT = exports.getRedisClientToken = exports.REDIS_CLIENTS = void 0;
4
- exports.REDIS_CLIENTS = "REDIS_CLIENTS";
5
- /**
6
- * Named client token helper (if you want to inject a specific client directly)
7
- * Example: @Inject(getRedisClientToken('geo')) private geoRedis: Redis
8
- */
9
- const getRedisClientToken = (name) => `REDIS_CLIENT:${name}`;
10
- exports.getRedisClientToken = getRedisClientToken;
11
- /**
12
- * Backward compatible tokens:
13
- * - REDIS_CLIENT is the "main" redis client
14
- * - REDIS_GEO_CLIENT is the "geo" redis client
15
- */
16
- exports.REDIS_CLIENT = (0, exports.getRedisClientToken)("main");
17
- exports.REDIS_GEO_CLIENT = (0, exports.getRedisClientToken)("geo");
3
+ exports.REDIS_CLIENT = void 0;
4
+ exports.REDIS_CLIENT = "REDIS_CLIENT";
@@ -16,92 +16,35 @@ const config_1 = require("@nestjs/config");
16
16
  const ioredis_1 = __importDefault(require("ioredis"));
17
17
  const redis_constant_1 = require("./redis.constant");
18
18
  const redis_service_1 = require("./redis.service");
19
- function parseNames(v) {
20
- // default includes geo for backward compatibility with your existing code
21
- const raw = (v ?? "main,geo")
22
- .split(",")
23
- .map((s) => s.trim())
24
- .filter(Boolean);
25
- // ensure unique
26
- return Array.from(new Set(raw));
27
- }
28
- function upper(name) {
29
- return name.replace(/[^a-zA-Z0-9]/g, "_").toUpperCase();
30
- }
31
19
  let RedisModule = RedisModule_1 = class RedisModule {
32
20
  static forRootAsync() {
33
21
  return {
34
22
  module: RedisModule_1,
35
23
  imports: [config_1.ConfigModule],
36
24
  providers: [
37
- // 1) Build ALL clients from env and store as a map
38
25
  {
39
- provide: redis_constant_1.REDIS_CLIENTS,
26
+ provide: redis_constant_1.REDIS_CLIENT,
40
27
  inject: [config_1.ConfigService],
41
28
  useFactory: (config) => {
42
- const names = parseNames(config.get("REDIS_NAMES"));
43
- const baseUrl = config.get("REDIS_URL");
44
- const baseHost = config.get("REDIS_HOST");
45
- const basePort = config.get("REDIS_PORT");
46
- const basePassword = config.get("REDIS_PASSWORD") || undefined;
47
- const baseDb = config.get("REDIS_DB") ?? 0;
48
- const baseKeyPrefix = config.get("REDIS_KEY_PREFIX") || undefined;
49
- const map = {};
50
- for (const name of names) {
51
- const N = upper(name);
52
- const url = config.get(`REDIS_${N}_URL`) ?? baseUrl;
53
- const host = config.get(`REDIS_${N}_HOST`) ?? baseHost;
54
- const port = config.get(`REDIS_${N}_PORT`) ?? basePort;
55
- const password = config.get(`REDIS_${N}_PASSWORD`) ?? basePassword;
56
- const db = config.get(`REDIS_${N}_DB`) ?? baseDb;
57
- const keyPrefix = config.get(`REDIS_${N}_KEY_PREFIX`) ?? baseKeyPrefix;
58
- const client = url
59
- ? new ioredis_1.default(url, { keyPrefix })
60
- : new ioredis_1.default({
61
- host,
62
- port,
63
- password,
64
- db,
65
- keyPrefix,
66
- });
67
- client.on("error", (err) => {
68
- // eslint-disable-next-line no-console
69
- console.error(`[redis:${name}] error:`, err?.message || err);
70
- });
71
- map[name] = client;
72
- }
73
- return map;
29
+ const url = config.get("REDIS_URL");
30
+ const host = config.get("REDIS_HOST");
31
+ const port = config.get("REDIS_PORT");
32
+ const password = config.get("REDIS_PASSWORD") || undefined;
33
+ const db = config.get("REDIS_DB") ?? 0;
34
+ const keyPrefix = config.get("REDIS_KEY_PREFIX") || undefined;
35
+ const client = url
36
+ ? new ioredis_1.default(url, { keyPrefix })
37
+ : new ioredis_1.default({ host, port, password, db, keyPrefix });
38
+ client.on("error", (err) => {
39
+ // eslint-disable-next-line no-console
40
+ console.error(`[redis] error:`, err?.message || err);
41
+ });
42
+ return client;
74
43
  },
75
44
  },
76
- // 2) Provide each named token for DI (optional but useful)
77
- // e.g. @Inject(getRedisClientToken('geo')) geoRedis: Redis
78
- {
79
- provide: (0, redis_constant_1.getRedisClientToken)("main"),
80
- inject: [redis_constant_1.REDIS_CLIENTS],
81
- useFactory: (clients) => {
82
- if (!clients.main)
83
- throw new Error(`[redis] missing client "main" (check REDIS_NAMES)`);
84
- return clients.main;
85
- },
86
- },
87
- {
88
- provide: (0, redis_constant_1.getRedisClientToken)("geo"),
89
- inject: [redis_constant_1.REDIS_CLIENTS],
90
- useFactory: (clients) => {
91
- if (!clients.geo)
92
- throw new Error(`[redis] missing client "geo" (check REDIS_NAMES)`);
93
- return clients.geo;
94
- },
95
- },
96
- // 3) Service uses the map; you can use any client name dynamically
97
- redis_service_1.RedisService,
98
- ],
99
- exports: [
100
- redis_constant_1.REDIS_CLIENTS,
101
45
  redis_service_1.RedisService,
102
- (0, redis_constant_1.getRedisClientToken)("main"),
103
- (0, redis_constant_1.getRedisClientToken)("geo"),
104
46
  ],
47
+ exports: [redis_constant_1.REDIS_CLIENT, redis_service_1.RedisService],
105
48
  };
106
49
  }
107
50
  };
@@ -1,18 +1,14 @@
1
1
  import { OnModuleDestroy } from "@nestjs/common";
2
2
  import { Redis } from "ioredis";
3
- type RedisClientMap = Record<string, Redis>;
4
3
  export declare class RedisService implements OnModuleDestroy {
5
- private readonly clients;
6
- constructor(clients: RedisClientMap);
7
- private pick;
8
- get(key: string, clientName?: string): Promise<string | null>;
9
- del(key: string, clientName?: string): Promise<number>;
10
- exists(key: string, clientName?: string): Promise<number>;
11
- client(clientName?: string): Redis;
12
- getJson<T>(key: string, clientName?: string): Promise<T | null>;
13
- setJson(key: string, value: unknown, ttlSeconds?: number, clientName?: string): Promise<"OK">;
14
- getGeoJson<T>(key: string): Promise<T | null>;
15
- setGeoJson(key: string, value: unknown, ttlSeconds?: number): Promise<"OK">;
4
+ private readonly redis;
5
+ constructor(redis: Redis);
6
+ get(key: string): Promise<string | null>;
7
+ set(key: string, value: string, ttlSeconds?: number): Promise<"OK">;
8
+ del(key: string): Promise<number>;
9
+ exists(key: string): Promise<number>;
10
+ client(): Redis;
11
+ getJson<T>(key: string): Promise<T | null>;
12
+ setJson(key: string, value: unknown, ttlSeconds?: number): Promise<"OK">;
16
13
  onModuleDestroy(): Promise<void>;
17
14
  }
18
- export {};
@@ -14,35 +14,33 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.RedisService = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
+ const ioredis_1 = require("ioredis");
17
18
  const redis_constant_1 = require("./redis.constant");
18
19
  let RedisService = class RedisService {
19
- constructor(clients) {
20
- this.clients = clients;
21
- }
22
- pick(name = "main") {
23
- const client = this.clients[name];
24
- if (!client) {
25
- const available = Object.keys(this.clients).join(", ");
26
- throw new Error(`[redis] client "${name}" not found. Available: ${available}`);
27
- }
28
- return client;
20
+ constructor(redis) {
21
+ this.redis = redis;
29
22
  }
30
23
  // -------------------- RAW --------------------
31
- get(key, clientName = "main") {
32
- return this.pick(clientName).get(key);
24
+ get(key) {
25
+ return this.redis.get(key);
33
26
  }
34
- del(key, clientName = "main") {
35
- return this.pick(clientName).del(key);
27
+ set(key, value, ttlSeconds) {
28
+ if (ttlSeconds && ttlSeconds > 0)
29
+ return this.redis.set(key, value, "EX", ttlSeconds);
30
+ return this.redis.set(key, value);
36
31
  }
37
- exists(key, clientName = "main") {
38
- return this.pick(clientName).exists(key);
32
+ del(key) {
33
+ return this.redis.del(key);
39
34
  }
40
- client(clientName = "main") {
41
- return this.pick(clientName);
35
+ exists(key) {
36
+ return this.redis.exists(key);
37
+ }
38
+ client() {
39
+ return this.redis;
42
40
  }
43
41
  // -------------------- JSON --------------------
44
- async getJson(key, clientName = "main") {
45
- const val = await this.pick(clientName).get(key);
42
+ async getJson(key) {
43
+ const val = await this.redis.get(key);
46
44
  if (!val)
47
45
  return null;
48
46
  try {
@@ -52,36 +50,24 @@ let RedisService = class RedisService {
52
50
  return null;
53
51
  }
54
52
  }
55
- async setJson(key, value, ttlSeconds, clientName = "main") {
53
+ async setJson(key, value, ttlSeconds) {
56
54
  const payload = JSON.stringify(value);
57
- const c = this.pick(clientName);
58
55
  if (ttlSeconds && ttlSeconds > 0)
59
- return c.set(key, payload, "EX", ttlSeconds);
60
- return c.set(key, payload);
61
- }
62
- // Backward-compat convenience (optional)
63
- async getGeoJson(key) {
64
- return this.getJson(key, "geo");
65
- }
66
- async setGeoJson(key, value, ttlSeconds) {
67
- return this.setJson(key, value, ttlSeconds, "geo");
56
+ return this.redis.set(key, payload, "EX", ttlSeconds);
57
+ return this.redis.set(key, payload);
68
58
  }
69
59
  async onModuleDestroy() {
70
- // Graceful shutdown for ALL clients
71
- const list = Object.values(this.clients);
72
- for (const c of list) {
73
- try {
74
- await c.quit();
75
- }
76
- catch {
77
- c.disconnect();
78
- }
60
+ try {
61
+ await this.redis.quit();
62
+ }
63
+ catch {
64
+ this.redis.disconnect();
79
65
  }
80
66
  }
81
67
  };
82
68
  exports.RedisService = RedisService;
83
69
  exports.RedisService = RedisService = __decorate([
84
70
  (0, common_1.Injectable)(),
85
- __param(0, (0, common_1.Inject)(redis_constant_1.REDIS_CLIENTS)),
86
- __metadata("design:paramtypes", [Object])
71
+ __param(0, (0, common_1.Inject)(redis_constant_1.REDIS_CLIENT)),
72
+ __metadata("design:paramtypes", [ioredis_1.Redis])
87
73
  ], RedisService);
@@ -1,6 +1,7 @@
1
1
  import { _BaseEntity } from "../_base_entity";
2
2
  import { CustomerEntity } from "./customer.entity";
3
3
  import { GeoCommuneEntity, GeoDistrictEntity, GeoProvinceEntity, GeoVillageEntity, OccupationEntity } from "../core";
4
+ import { CurrencyType } from "../../types";
4
5
  export declare class CustomerEmploymentEntity extends _BaseEntity {
5
6
  id: string;
6
7
  customer_id: string;
@@ -18,6 +19,8 @@ export declare class CustomerEmploymentEntity extends _BaseEntity {
18
19
  village_id?: string | null;
19
20
  joined_date?: string | null;
20
21
  left_date?: string | null;
22
+ currency?: CurrencyType | null;
23
+ annual_salary?: number;
21
24
  is_primary: boolean;
22
25
  customer: CustomerEntity;
23
26
  occupation?: OccupationEntity | null;
@@ -14,6 +14,8 @@ const typeorm_1 = require("typeorm");
14
14
  const _base_entity_1 = require("../_base_entity");
15
15
  const customer_entity_1 = require("./customer.entity");
16
16
  const core_1 = require("../core");
17
+ const types_1 = require("../../types");
18
+ const utils_1 = require("../../utils");
17
19
  let CustomerEmploymentEntity = class CustomerEmploymentEntity extends _base_entity_1._BaseEntity {
18
20
  };
19
21
  exports.CustomerEmploymentEntity = CustomerEmploymentEntity;
@@ -82,6 +84,19 @@ __decorate([
82
84
  (0, typeorm_1.Column)({ type: "date", nullable: true }),
83
85
  __metadata("design:type", Object)
84
86
  ], CustomerEmploymentEntity.prototype, "left_date", void 0);
87
+ __decorate([
88
+ (0, typeorm_1.Column)({
89
+ type: "varchar",
90
+ length: 5,
91
+ nullable: true,
92
+ comment: (0, utils_1.enumToCommentString)(types_1.CurrencyType),
93
+ }),
94
+ __metadata("design:type", Object)
95
+ ], CustomerEmploymentEntity.prototype, "currency", void 0);
96
+ __decorate([
97
+ (0, typeorm_1.Column)({ type: "decimal", precision: 15, scale: 2, nullable: true }),
98
+ __metadata("design:type", Number)
99
+ ], CustomerEmploymentEntity.prototype, "annual_salary", void 0);
85
100
  __decorate([
86
101
  (0, typeorm_1.Column)({ type: "bool", default: false }),
87
102
  __metadata("design:type", Boolean)
@@ -1,3 +1,7 @@
1
+ export declare enum CurrencyType {
2
+ USD = "USD",
3
+ KHR = "KHR"
4
+ }
1
5
  export declare enum ExchangeRateSourceType {
2
6
  Manual = "manual",
3
7
  Api = "api",
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExchangeRateSyncStatus = exports.ExchangeRateSourceType = void 0;
3
+ exports.ExchangeRateSyncStatus = exports.ExchangeRateSourceType = exports.CurrencyType = void 0;
4
+ var CurrencyType;
5
+ (function (CurrencyType) {
6
+ CurrencyType["USD"] = "USD";
7
+ CurrencyType["KHR"] = "KHR";
8
+ })(CurrencyType || (exports.CurrencyType = CurrencyType = {}));
4
9
  var ExchangeRateSourceType;
5
10
  (function (ExchangeRateSourceType) {
6
11
  ExchangeRateSourceType["Manual"] = "manual";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plac-micro-common",
3
- "version": "1.3.66",
3
+ "version": "1.3.68",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {