bpjs-bridge 1.0.3 โ†’ 1.0.10

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/README.md CHANGED
@@ -10,6 +10,15 @@
10
10
  Repository resmi: <a href="https://github.com/NewusTech/bpjs-bridge">NewusTech/bpjs-bridge</a>
11
11
  </p>
12
12
 
13
+ <div align="center">
14
+
15
+ ![npm version](https://img.shields.io/npm/v/bpjs-bridge?color=%2300aaff&label=npm%20version)
16
+ ![npm downloads](https://img.shields.io/npm/dm/bpjs-bridge?color=%23ffaa00&label=downloads)
17
+ ![npm license](https://img.shields.io/npm/l/bpjs-bridge)
18
+ ![GitHub Repo stars](https://img.shields.io/github/stars/newustechnology/bpjs-bridge?style=social)
19
+
20
+ </div>
21
+
13
22
  ## Installation
14
23
 
15
24
  ```bash
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const redis_1 = require("../lib/redis");
4
+ const fktpBPJS_service_1 = require("../services/antrean/fktpBPJS.service");
4
5
  const pcare_service_1 = require("../services/pcare/pcare.service");
5
6
  const config_1 = require("./config");
6
7
  // Setup PcareService
7
- const pcareService = new pcare_service_1.PcareService(config_1.PcareConfig, redis_1.redis, "redis_prefix_test");
8
+ const pcareService = new pcare_service_1.PcareService(config_1.PcareConfig, redis_1.redis);
9
+ const jkn = new fktpBPJS_service_1.AntreanFktpService(config_1.PcareConfig, redis_1.redis);
8
10
  describe("PcareService", () => {
9
11
  afterAll(() => {
10
12
  redis_1.redis.disconnect();
@@ -138,4 +140,32 @@ describe("PcareService", () => {
138
140
  ]),
139
141
  }));
140
142
  });
143
+ it("should fetch ref poli", async () => {
144
+ const response = await jkn.getReferensiPoli("2026-01-02");
145
+ // console.log(response);
146
+ // expect(response).toEqual(
147
+ // expect.objectContaining({
148
+ // list: expect.arrayContaining([
149
+ // expect.objectContaining({
150
+ // kdPrognosa: expect.any(String),
151
+ // nmPrognosa: expect.any(String),
152
+ // }),
153
+ // ]),
154
+ // })
155
+ // );
156
+ });
157
+ it("should fetch ref dokter", async () => {
158
+ const response = await jkn.getReferensiDokter("001", "2026-01-02");
159
+ // console.log(response);
160
+ // expect(response).toEqual(
161
+ // expect.objectContaining({
162
+ // list: expect.arrayContaining([
163
+ // expect.objectContaining({
164
+ // kdPrognosa: expect.any(String),
165
+ // nmPrognosa: expect.any(String),
166
+ // }),
167
+ // ]),
168
+ // })
169
+ // );
170
+ });
141
171
  });
@@ -268,6 +268,26 @@ export declare const enpoints: readonly [{
268
268
  readonly endpoint: "antrean/batal";
269
269
  readonly method: "POST";
270
270
  readonly description: "Membatalkan antrean pasien (WS Antrol)";
271
+ }, {
272
+ readonly name: "scrinning_rekap";
273
+ readonly endpoint: "skrinning/rekap";
274
+ readonly method: "GET";
275
+ readonly description: "Mengambil data rekapitulasi hasil Skrining Riwayat Kesehatan per penyakit";
276
+ }, {
277
+ readonly name: "scrinning_peserta";
278
+ readonly endpoint: "/skrinning/peserta/{nomor_peserta}/{start}/{limit}";
279
+ readonly method: "GET";
280
+ readonly description: "Mengambil data rekapitulasi Skrining Riwayat Kesehatan per peserta";
281
+ }, {
282
+ readonly name: "scrinning_diabetes_mellitus";
283
+ readonly endpoint: "/skrinning/prolanis/dm/{nomor_peserta}/{start}/{limit}";
284
+ readonly method: "GET";
285
+ readonly description: "Mengambil data peserta prolanis DM sejak tahun 2017";
286
+ }, {
287
+ readonly name: "scrinning_hipertensi";
288
+ readonly endpoint: "skrinning/prolanis/ht/{nomor_peserta}/{start}/{limit}";
289
+ readonly method: "GET";
290
+ readonly description: "Mengambil data peserta prolanis HT sejak tahun 2017";
271
291
  }];
272
292
  export declare const BaseUrl: {
273
293
  dev: {
@@ -326,6 +326,30 @@ exports.enpoints = [
326
326
  method: "POST",
327
327
  description: "Membatalkan antrean pasien (WS Antrol)",
328
328
  },
329
+ {
330
+ name: "scrinning_rekap",
331
+ endpoint: "skrinning/rekap",
332
+ method: "GET",
333
+ description: "Mengambil data rekapitulasi hasil Skrining Riwayat Kesehatan per penyakit",
334
+ },
335
+ {
336
+ name: "scrinning_peserta",
337
+ endpoint: "/skrinning/peserta/{nomor_peserta}/{start}/{limit}",
338
+ method: "GET",
339
+ description: "Mengambil data rekapitulasi Skrining Riwayat Kesehatan per peserta",
340
+ },
341
+ {
342
+ name: "scrinning_diabetes_mellitus",
343
+ endpoint: "/skrinning/prolanis/dm/{nomor_peserta}/{start}/{limit}",
344
+ method: "GET",
345
+ description: "Mengambil data peserta prolanis DM sejak tahun 2017",
346
+ },
347
+ {
348
+ name: "scrinning_hipertensi",
349
+ endpoint: "skrinning/prolanis/ht/{nomor_peserta}/{start}/{limit}",
350
+ method: "GET",
351
+ description: "Mengambil data peserta prolanis HT sejak tahun 2017",
352
+ },
329
353
  ];
330
354
  exports.BaseUrl = {
331
355
  dev: {
package/dist/index.d.ts CHANGED
@@ -13,4 +13,5 @@ export * from "./types/pendaftaran";
13
13
  export * from "./types/spesialis";
14
14
  export * from "./types/antreanFktp";
15
15
  export * from "./types/icare";
16
+ export * from "./types/skrinning";
16
17
  export { BpjsError } from "./types/globalErroModule";
package/dist/index.js CHANGED
@@ -31,6 +31,7 @@ __exportStar(require("./types/pendaftaran"), exports);
31
31
  __exportStar(require("./types/spesialis"), exports);
32
32
  __exportStar(require("./types/antreanFktp"), exports);
33
33
  __exportStar(require("./types/icare"), exports);
34
+ __exportStar(require("./types/skrinning"), exports);
34
35
  // error
35
36
  var globalErroModule_1 = require("./types/globalErroModule");
36
37
  Object.defineProperty(exports, "BpjsError", { enumerable: true, get: function () { return globalErroModule_1.BpjsError; } });
@@ -11,9 +11,8 @@ export declare class AntreanFktpService extends BaseService {
11
11
  * Constructor AntreanFktpService
12
12
  * @param config konfigurasi BPJS
13
13
  * @param redisClient instance Redis (opsional)
14
- * @param chachePrefix prefix untuk cache Redis (opsional)
15
14
  */
16
- constructor(config: configType, redisClient?: Redis, chachePrefix?: string);
15
+ constructor(config: configType, redisClient?: Redis);
17
16
  /**
18
17
  *
19
18
  * @param tanggal
@@ -11,11 +11,10 @@ class AntreanFktpService extends base_service_1.BaseService {
11
11
  * Constructor AntreanFktpService
12
12
  * @param config konfigurasi BPJS
13
13
  * @param redisClient instance Redis (opsional)
14
- * @param chachePrefix prefix untuk cache Redis (opsional)
15
14
  */
16
- constructor(config, redisClient, chachePrefix) {
15
+ constructor(config, redisClient) {
17
16
  const getBaseUrl = enpoints_1.BaseUrl[config.mode].url_antrean_fktp;
18
- super({ ...config, baseUrl: getBaseUrl }, redisClient, chachePrefix ?? "antreanfktp");
17
+ super({ ...config, baseUrl: getBaseUrl }, redisClient);
19
18
  }
20
19
  /**
21
20
  *
@@ -6,7 +6,7 @@ export declare class BaseService {
6
6
  private client;
7
7
  private redisClient;
8
8
  private defaultRedisKeyPrefix;
9
- constructor(config: BpjsCLient, redisClient?: Redis, chachePrefix?: string);
9
+ constructor(config: BpjsCLient, redisClient?: Redis);
10
10
  /**
11
11
  * Menyimpan data ke Redis dengan TTL (time-to-live)
12
12
  * @param key - Kunci data
@@ -5,7 +5,7 @@ const enpoints_1 = require("../config/enpoints");
5
5
  const httpClient_1 = require("../core/httpClient");
6
6
  const globalErroModule_1 = require("../types/globalErroModule");
7
7
  class BaseService {
8
- constructor(config, redisClient, chachePrefix) {
8
+ constructor(config, redisClient) {
9
9
  this.redisClient = null;
10
10
  this.defaultRedisKeyPrefix = "bpjs_bridge_fktp";
11
11
  this.client = (0, httpClient_1.createBpjsClient)(config); // client dari axios yang sudah disiapkan
@@ -17,10 +17,12 @@ class BaseService {
17
17
  this.redisClient.on("error", (err) => {
18
18
  console.error("[BRIDGE FKTP BPJS] => โŒ Redis error:", err);
19
19
  });
20
- if (chachePrefix) {
21
- this.defaultRedisKeyPrefix =
22
- this.defaultRedisKeyPrefix + "_" + chachePrefix + ":";
23
- }
20
+ this.defaultRedisKeyPrefix =
21
+ this.defaultRedisKeyPrefix +
22
+ "_" +
23
+ config.consId +
24
+ config.username +
25
+ ":";
24
26
  }
25
27
  }
26
28
  /**
@@ -10,9 +10,8 @@ export declare class IcareService extends BaseService {
10
10
  * Constructor AntreanFktpService
11
11
  * @param config konfigurasi BPJS
12
12
  * @param redisClient instance Redis (opsional)
13
- * @param chachePrefix prefix untuk cache Redis (opsional)
14
13
  */
15
- constructor(config: configType, redisClient?: Redis, chachePrefix?: string);
14
+ constructor(config: configType, redisClient?: Redis);
16
15
  /**
17
16
  *
18
17
  * @param body
@@ -11,11 +11,10 @@ class IcareService extends base_service_1.BaseService {
11
11
  * Constructor AntreanFktpService
12
12
  * @param config konfigurasi BPJS
13
13
  * @param redisClient instance Redis (opsional)
14
- * @param chachePrefix prefix untuk cache Redis (opsional)
15
14
  */
16
- constructor(config, redisClient, chachePrefix) {
15
+ constructor(config, redisClient) {
17
16
  const getBaseUrl = enpoints_1.BaseUrl[config.mode].url_antrean_fktp;
18
- super({ ...config, baseUrl: getBaseUrl }, redisClient, chachePrefix ?? "icare_validate");
17
+ super({ ...config, baseUrl: getBaseUrl }, redisClient);
19
18
  }
20
19
  /**
21
20
  *
@@ -34,11 +34,11 @@ export declare class KunjunganModule {
34
34
  * @description
35
35
  * untuk mendapatkan referensi tacc
36
36
  */
37
- ref_tacc(kodediags?: string[]): {
37
+ ref_tacc(kodediags?: string[]): Promise<{
38
38
  kdTacc: string;
39
39
  nmTacc: string;
40
40
  alasanTacc: string[];
41
- }[];
41
+ }[]>;
42
42
  /**
43
43
  *
44
44
  * @param body
@@ -48,13 +48,13 @@ class KunjunganModule {
48
48
  * @description
49
49
  * untuk mendapatkan referensi tacc
50
50
  */
51
- ref_tacc(kodediags) {
51
+ async ref_tacc(kodediags) {
52
52
  let options = [];
53
53
  if (kodediags) {
54
- kodediags.forEach(async (kodediag) => {
54
+ options = await Promise.all(kodediags.map(async (kodediag) => {
55
55
  const diag = await this.parent.diagnosa.get(kodediag, 0, 1);
56
- options.push(`${diag.list[0].kdDiag}-${diag.list[0].nmDiag}`);
57
- });
56
+ return `${diag.list[0].kdDiag}-${diag.list[0].nmDiag}`;
57
+ }));
58
58
  }
59
59
  return [
60
60
  { kdTacc: "-1", nmTacc: "Tanpa TACC", alasanTacc: [] },
@@ -0,0 +1,11 @@
1
+ import { DataArray, DataPaginate } from "../../../types/global";
2
+ import { ScrinningDMPayload, ScrinningHTPayload, ScrinningPesertaPayload, ScrinningRekapPayload } from "../../../types/skrinning";
3
+ import { PcareService } from "../pcare.service";
4
+ export declare class SkrinningModule {
5
+ private parent;
6
+ constructor(parent: PcareService);
7
+ getSkrinningRekap(): Promise<DataArray<ScrinningRekapPayload>>;
8
+ getSkrinningPeserta(nomor_peserta: string, start: number, limit: number): Promise<DataPaginate<ScrinningPesertaPayload>>;
9
+ getSkrinningDM(nomor_peserta: string, start: number, limit: number): Promise<DataPaginate<ScrinningDMPayload>>;
10
+ getSkrinningHT(nomor_peserta: string, start: number, limit: number): Promise<DataPaginate<ScrinningHTPayload>>;
11
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SkrinningModule = void 0;
4
+ class SkrinningModule {
5
+ constructor(parent) {
6
+ this.parent = parent;
7
+ }
8
+ async getSkrinningRekap() {
9
+ const response = await this.parent.callEndpoint("scrinning_rekap");
10
+ return response.data;
11
+ }
12
+ async getSkrinningPeserta(nomor_peserta, start, limit) {
13
+ const response = await this.parent.callEndpoint("scrinning_peserta", {
14
+ nomor_peserta,
15
+ start,
16
+ limit,
17
+ });
18
+ return response.data;
19
+ }
20
+ async getSkrinningDM(nomor_peserta, start, limit) {
21
+ const response = await this.parent.callEndpoint("scrinning_diabetes_mellitus", {
22
+ nomor_peserta,
23
+ start,
24
+ limit,
25
+ });
26
+ return response.data;
27
+ }
28
+ async getSkrinningHT(nomor_peserta, start, limit) {
29
+ const response = await this.parent.callEndpoint("scrinning_hipertensi", {
30
+ nomor_peserta,
31
+ start,
32
+ limit,
33
+ });
34
+ return response.data;
35
+ }
36
+ }
37
+ exports.SkrinningModule = SkrinningModule;
@@ -16,6 +16,7 @@ import { ProviderModule } from "./module/provider.module";
16
16
  import { SpesialisModule } from "./module/spesialis.module";
17
17
  import { StatusPulangModule } from "./module/statusPulang.module";
18
18
  import { TindakanPulangModule } from "./module/tindakan.module";
19
+ import { SkrinningModule } from "./module/skrinning.module";
19
20
  /**
20
21
  * Service untuk mengakses endpoint PCare BPJS
21
22
  */
@@ -35,11 +36,11 @@ export declare class PcareService extends BaseService {
35
36
  readonly mcu: MCUModule;
36
37
  readonly pendaftaran: PendaftaranModule;
37
38
  readonly spesialis: SpesialisModule;
39
+ readonly skrinning: SkrinningModule;
38
40
  /**
39
41
  * Constructor PcareService
40
42
  * @param config konfigurasi BPJS
41
43
  * @param redisClient instance Redis (opsional)
42
- * @param chachePrefix prefix untuk cache Redis (opsional)
43
44
  */
44
- constructor(config: configType, redisClient?: Redis, chachePrefix?: string);
45
+ constructor(config: configType, redisClient?: Redis);
45
46
  }
@@ -18,6 +18,7 @@ const provider_module_1 = require("./module/provider.module");
18
18
  const spesialis_module_1 = require("./module/spesialis.module");
19
19
  const statusPulang_module_1 = require("./module/statusPulang.module");
20
20
  const tindakan_module_1 = require("./module/tindakan.module");
21
+ const skrinning_module_1 = require("./module/skrinning.module");
21
22
  /**
22
23
  * Service untuk mengakses endpoint PCare BPJS
23
24
  */
@@ -26,11 +27,10 @@ class PcareService extends base_service_1.BaseService {
26
27
  * Constructor PcareService
27
28
  * @param config konfigurasi BPJS
28
29
  * @param redisClient instance Redis (opsional)
29
- * @param chachePrefix prefix untuk cache Redis (opsional)
30
30
  */
31
- constructor(config, redisClient, chachePrefix) {
31
+ constructor(config, redisClient) {
32
32
  const getBaseUrl = enpoints_1.BaseUrl[config.mode].url_pcare;
33
- super({ ...config, baseUrl: getBaseUrl }, redisClient, chachePrefix ?? "pcare");
33
+ super({ ...config, baseUrl: getBaseUrl }, redisClient);
34
34
  this.diagnosa = new diagnosa_module_1.DiagnosaModule(this);
35
35
  this.obat = new obat_module_1.ObatModule(this);
36
36
  this.dokter = new dokter_module_1.DokterModule(this);
@@ -46,6 +46,7 @@ class PcareService extends base_service_1.BaseService {
46
46
  this.mcu = new mcu_module_1.MCUModule(this);
47
47
  this.pendaftaran = new pendafataran_module_1.PendaftaranModule(this);
48
48
  this.spesialis = new spesialis_module_1.SpesialisModule(this);
49
+ this.skrinning = new skrinning_module_1.SkrinningModule(this);
49
50
  }
50
51
  }
51
52
  exports.PcareService = PcareService;
@@ -0,0 +1,44 @@
1
+ export interface ScrinningRekapPayload {
2
+ nama_penyakit: string;
3
+ beresiko: number;
4
+ tidak_beresiko: number;
5
+ }
6
+ export interface ScrinningPesertaPayload {
7
+ nomor_peserta: string;
8
+ nama: string;
9
+ usia: number;
10
+ no_hp: string;
11
+ email: string;
12
+ status_penyakit: StatusPenyakit;
13
+ }
14
+ interface StatusPenyakit {
15
+ anemia: string;
16
+ hepatitis_b: string;
17
+ hepatitis_c: string;
18
+ hipertensi_stroke_ischemic_heart_disease: string;
19
+ kanker_paru: string;
20
+ kanker_payudara: string;
21
+ kanker_serviks: string;
22
+ kolorektal: string;
23
+ paru_obstruktif_kronis: string;
24
+ penyakit_diabetes_mellitus: string;
25
+ thalasemia: string;
26
+ tuberkulosis: string;
27
+ }
28
+ export interface ScrinningDMPayload {
29
+ nomor_peserta: string;
30
+ nama: string;
31
+ usia: number;
32
+ jenis_kelamin: string;
33
+ diagnosa_terakhir: string;
34
+ status_prolanis: string;
35
+ }
36
+ export interface ScrinningHTPayload {
37
+ nomor_peserta: string;
38
+ nama: string;
39
+ usia: number;
40
+ jenis_kelamin: string;
41
+ diagnosa_terakhir: string;
42
+ status_prolanis: string;
43
+ }
44
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpjs-bridge",
3
- "version": "1.0.3",
3
+ "version": "1.0.10",
4
4
  "description": "Integrasi BPJS PCare, Antrean FKTP, VClaim, dan iCare dengan dukungan Redis Cache, Logging, dan Modular Service Architecture. ",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,6 +14,10 @@
14
14
  "icare",
15
15
  "bpjs-kesehatan"
16
16
  ],
17
+ "repository": "https://github.com/newustechnology/bpjs-bridge.git",
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
17
21
  "files": [
18
22
  "dist/**/*"
19
23
  ],
@@ -22,7 +26,8 @@
22
26
  "scripts": {
23
27
  "build": "tsc -p tsconfig.json",
24
28
  "test": "npx jest --detectOpenHandles",
25
- "prepare": "npm run build"
29
+ "prepare": "npm run build",
30
+ "release": "npm version patch && git push && git push --tags"
26
31
  },
27
32
  "dependencies": {
28
33
  "axios": "^1.13.2",
@@ -1,46 +0,0 @@
1
- import { AxiosResponse } from "axios";
2
- import Redis from "ioredis";
3
- import { EndpointName } from "../config/enpoints";
4
- import { BpjsCLient } from "../core/httpClient";
5
- export declare class FktpService {
6
- private client;
7
- private redisClient;
8
- private defaultRedisKeyPrefix;
9
- constructor(config: BpjsCLient, redisClient?: Redis, chachePrefix?: string);
10
- /**
11
- * Menyimpan data ke Redis dengan TTL (time-to-live)
12
- * @param key - Kunci data
13
- * @param value - Data yang akan disimpan
14
- * @param expInSecond - Waktu kadaluarsa dalam detik (default: 3600)
15
- */
16
- private set;
17
- /**
18
- * Mengambil data dari Redis
19
- * @param key - Kunci data
20
- * @returns Data dari Redis atau null jika tidak ditemukan
21
- */
22
- private get;
23
- /**
24
- * Menghapus data dari Redis
25
- * @param key - Kunci data
26
- */
27
- private del;
28
- /**
29
- *
30
- * @param pattern - Pola kunci untuk menghapus (misal: 'user_*' untuk menghapus semua kunci yang diawali 'user_')
31
- * Menghapus beberapa kunci berdasarkan pola (pattern)
32
- */
33
- private deleteKeysByPattern;
34
- /**
35
- * Membersihkan seluruh cache Redis
36
- */
37
- private flushAll;
38
- /**
39
- * Memanggil endpoint BPJS berdasarkan nama dan parameter yang diberikan
40
- * @param name
41
- * @param params
42
- * @param body
43
- * @returns
44
- */
45
- callEndpoint<T>(name: EndpointName, params?: Record<string, any>, body?: Record<string, any>): Promise<AxiosResponse<T>>;
46
- }
@@ -1,168 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FktpService = void 0;
4
- const enpoints_1 = require("../config/enpoints");
5
- const httpClient_1 = require("../core/httpClient");
6
- class FktpService {
7
- constructor(config, redisClient, chachePrefix) {
8
- this.redisClient = null;
9
- this.defaultRedisKeyPrefix = "bpjs_bridge_fktp";
10
- this.client = (0, httpClient_1.createBpjsClient)(config); // client dari axios yang sudah disiapkan
11
- if (redisClient) {
12
- this.redisClient = redisClient;
13
- this.redisClient.on("connect", () => {
14
- console.info("[BRIDGE FKTP BPJS] => โœ… Redis connected");
15
- });
16
- this.redisClient.on("error", (err) => {
17
- console.error("[BRIDGE FKTP BPJS] => โŒ Redis error:", err);
18
- });
19
- if (chachePrefix) {
20
- this.defaultRedisKeyPrefix =
21
- this.defaultRedisKeyPrefix + "_" + chachePrefix + ":";
22
- }
23
- }
24
- }
25
- /**
26
- * Menyimpan data ke Redis dengan TTL (time-to-live)
27
- * @param key - Kunci data
28
- * @param value - Data yang akan disimpan
29
- * @param expInSecond - Waktu kadaluarsa dalam detik (default: 3600)
30
- */
31
- async set(key, value, expInSecond = 3600) {
32
- if (typeof expInSecond !== "number") {
33
- expInSecond = 3600;
34
- }
35
- try {
36
- const data = typeof value === "object" ? JSON.stringify(value) : String(value);
37
- await this.redisClient.set(this.defaultRedisKeyPrefix + ":" + key, data, "EX", expInSecond);
38
- // console.info(
39
- // `๐Ÿ”ต Redis SET: ${
40
- // this.defaultRedisKeyPrefix + key
41
- // } (TTL: ${expInSecond}s)`
42
- // );
43
- }
44
- catch (error) {
45
- console.error("โŒ Redis set error:", error);
46
- }
47
- }
48
- /**
49
- * Mengambil data dari Redis
50
- * @param key - Kunci data
51
- * @returns Data dari Redis atau null jika tidak ditemukan
52
- */
53
- async get(key) {
54
- try {
55
- const data = await this.redisClient.get(this.defaultRedisKeyPrefix + ":" + key);
56
- if (data) {
57
- console.info(`๐Ÿ” Redis GET: ${this.defaultRedisKeyPrefix + key}`);
58
- return data;
59
- }
60
- // console.warn?.(
61
- // `โš ๏ธ Redis GET: ${
62
- // this.defaultRedisKeyPrefix + key
63
- // } (Data tidak ditemukan)`
64
- // );
65
- return null;
66
- }
67
- catch (error) {
68
- console.error("โŒ Redis get error:", error);
69
- return null;
70
- }
71
- }
72
- /**
73
- * Menghapus data dari Redis
74
- * @param key - Kunci data
75
- */
76
- async del(key) {
77
- try {
78
- await this.redisClient.del(this.defaultRedisKeyPrefix + ":" + key);
79
- console.info(`๐Ÿ—‘๏ธ Redis DEL: ${this.defaultRedisKeyPrefix + key}`);
80
- }
81
- catch (error) {
82
- console.error("โŒ Redis del error:", error);
83
- }
84
- }
85
- /**
86
- *
87
- * @param pattern - Pola kunci untuk menghapus (misal: 'user_*' untuk menghapus semua kunci yang diawali 'user_')
88
- * Menghapus beberapa kunci berdasarkan pola (pattern)
89
- */
90
- async deleteKeysByPattern(pattern) {
91
- let cursor = "0";
92
- pattern = this.defaultRedisKeyPrefix + ":" + pattern;
93
- do {
94
- const [nextCursor, foundKeys] = await this.redisClient.scan(cursor, "MATCH", pattern, "COUNT", 100);
95
- cursor = nextCursor;
96
- if (foundKeys.length > 0) {
97
- await this.redisClient.del(...foundKeys);
98
- }
99
- } while (cursor !== "0");
100
- }
101
- /**
102
- * Membersihkan seluruh cache Redis
103
- */
104
- async flushAll() {
105
- try {
106
- await this.redisClient.flushall();
107
- console.info("๐Ÿงน Redis cache cleared!");
108
- }
109
- catch (error) {
110
- console.error("โŒ Redis flush error:", error);
111
- }
112
- }
113
- /**
114
- * Memanggil endpoint BPJS berdasarkan nama dan parameter yang diberikan
115
- * @param name
116
- * @param params
117
- * @param body
118
- * @returns
119
- */
120
- async callEndpoint(name, params = {}, body = {}) {
121
- // Menambahkan tipe return yang jelas
122
- const endpointConfig = enpoints_1.enpoints.find((e) => e.name === name);
123
- if (!endpointConfig) {
124
- throw new Error(`Endpoint ${name} tidak ditemukan`);
125
- }
126
- // Membentuk URL endpoint dengan menggantikan parameter dinamis
127
- let endpoint = endpointConfig.endpoint;
128
- Object.keys(params).forEach((key) => {
129
- endpoint = endpoint.replace(`{${key}}`, params[key]);
130
- });
131
- const cacheKey = `${name}:${JSON.stringify(params)}`;
132
- if (this.redisClient) {
133
- const cachedData = await this.get(cacheKey);
134
- if (cachedData) {
135
- const parsed = JSON.parse(cachedData);
136
- const cachedResponse = {
137
- data: parsed,
138
- status: 200,
139
- statusText: "OK",
140
- headers: {},
141
- config: (this.client?.defaults ?? {}),
142
- };
143
- return cachedResponse;
144
- }
145
- }
146
- // Melakukan request sesuai dengan method yang ditentukan di statusConfig
147
- switch (endpointConfig.method) {
148
- case "GET":
149
- const res = await this.client({
150
- url: endpoint,
151
- method: "GET",
152
- });
153
- if (this.redisClient && typeof res.data !== "string") {
154
- await this.set(cacheKey, res.data);
155
- }
156
- return res;
157
- case "POST":
158
- return await this.client.post(endpoint, body);
159
- case "PUT":
160
- return await this.client.put(endpoint, body);
161
- case "DELETE":
162
- return await this.client.delete(endpoint, body);
163
- default:
164
- throw new Error(`Method ${endpointConfig.method} tidak didukung`);
165
- }
166
- }
167
- }
168
- exports.FktpService = FktpService;
@@ -1,6 +0,0 @@
1
- import { BridgeErrorType } from "./global";
2
- export declare class BrigeError extends Error {
3
- status: number;
4
- type: BridgeErrorType;
5
- constructor(type: BridgeErrorType | undefined, message: string, statusCode?: number);
6
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BrigeError = void 0;
4
- class BrigeError extends Error {
5
- constructor(type = "UNKNOWN_ERROR", message, statusCode = 400) {
6
- super(message);
7
- this.name = "UploadError";
8
- this.type = type;
9
- this.status = statusCode;
10
- }
11
- }
12
- exports.BrigeError = BrigeError;