From 60f06a20ba3eea8ca4bd5d4b89300d85da8dbed4 Mon Sep 17 00:00:00 2001 From: mustofa-id <25121822+mustofa-id@users.noreply.github.com> Date: Wed, 7 Jan 2026 11:29:43 +0700 Subject: [PATCH 1/3] init --- .changeset/wise-friends-shave.md | 5 +++++ README.md | 4 ++++ src/ihs.spec.ts | 29 ++++++++++++++++++++++++++--- src/ihs.ts | 21 +++++++++++++++++++-- words.txt | 4 ++++ 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 .changeset/wise-friends-shave.md diff --git a/.changeset/wise-friends-shave.md b/.changeset/wise-friends-shave.md new file mode 100644 index 0000000..457b530 --- /dev/null +++ b/.changeset/wise-friends-shave.md @@ -0,0 +1,5 @@ +--- +'@ssecd/ihs': patch +--- + +Allow request directly using base url diff --git a/README.md b/README.md index 8f7ba58..6a18ff1 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,10 @@ if (result2.error) { } ``` +### `ihs.request({ ... })` + +Request ke RestAPI secara langsung menggunakan method `request()` dari instansi `IHS`. + ## Konfigurasi Konfigurasi mengikuti interface berikut: diff --git a/src/ihs.spec.ts b/src/ihs.spec.ts index b377774..f2c29b0 100644 --- a/src/ihs.spec.ts +++ b/src/ihs.spec.ts @@ -1,6 +1,12 @@ -import { describe, expect, it } from 'vitest'; +import { beforeAll, describe, expect, it } from 'vitest'; import IHS, { AuthDetail, DefaultAuthStore, IHSConfig } from './ihs.js'; +let ihs: IHS; + +beforeAll(() => { + ihs = new IHS(); +}); + describe('ihs', () => { it('instance should be object and valid instance', () => { const ihs = new IHS(); @@ -70,8 +76,25 @@ describe('ihs', () => { expect(store.get()).toBeUndefined(); }); - it('get patient resource should be return ok', async () => { - const ihs = new IHS(); + it(`request with base type should be return 200`, async () => { + const response = await ihs.request({ + type: 'base', + path: '/masterdata/v1/mastersaranaindex/mastersarana', + searchParams: { + limit: '1', + page: '1', + jenis_sarana: '121' + } + }); + expect(response.ok).toBe(true); + + const result = await response.json(); + expect(result.status_code).toBe(200); + expect(result.page).toBe(1); + expect(result.data.length).toBe(1); + }); + + it('get patient resource should be valid resource type', async () => { const response = await ihs.fhir(`/Patient/${process.env.TEST_PATIENT_ID}`); expect(response.ok).toBe(true); diff --git a/src/ihs.ts b/src/ihs.ts index dd3f146..a7ae82b 100644 --- a/src/ihs.ts +++ b/src/ihs.ts @@ -44,7 +44,23 @@ export interface IHSConfig { type UserConfig = Partial | (() => MaybePromise>); type RequestConfig = { - type: Exclude; + /** + * Tipe dari RestAPI. Gunakan tipe `base` jika API belum diimplementasikan. + * Contoh: + * + * ```ts + * await ihs.request({ + * type: 'base', + * path: '/masterdata/v1/mastersaranaindex/mastersarana', // <- include endpoint '/masterdata/v1/' + * searchParams: { + * limit: '10', + * page: '1', + * jenis_sarana: '121', + * } + * }) + * ``` + */ + type: 'base' | Exclude; path: string; searchParams?: URLSearchParams | Record | [string, string][]; } & RequestInit; @@ -149,7 +165,8 @@ export default class IHS { async request(config: RequestConfig): Promise { const { mode } = await this.getConfig(); const { type, path, searchParams, ...init } = config; - const url = buildUrl(defaultEndpointUrls[mode][type], path); + const baseUrl = type == 'base' ? defaultBaseUrls[mode] : defaultEndpointUrls[mode][type]; + const url = buildUrl(baseUrl, path); url.search = searchParams ? new URLSearchParams(searchParams).toString() : url.search; const auth = await this.auth(); init.headers = { diff --git a/words.txt b/words.txt index 57edd41..a38c073 100644 --- a/words.txt +++ b/words.txt @@ -16,6 +16,9 @@ kbki kemkes kriptografi lkpp +masterdata +mastersarana +mastersaranaindex OAEP OPTIN OPTOUT @@ -26,6 +29,7 @@ rxterm Silampari simrs Sriwijaya +ssecd subkategori tkdn ucum From 025f94fd03c05d78d6637bdb88f157a6129ba3bb Mon Sep 17 00:00:00 2001 From: mustofa-id <25121822+mustofa-id@users.noreply.github.com> Date: Wed, 7 Jan 2026 11:32:04 +0700 Subject: [PATCH 2/3] tidy --- .changeset/wise-friends-shave.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wise-friends-shave.md b/.changeset/wise-friends-shave.md index 457b530..d287935 100644 --- a/.changeset/wise-friends-shave.md +++ b/.changeset/wise-friends-shave.md @@ -2,4 +2,4 @@ '@ssecd/ihs': patch --- -Allow request directly using base url +Allow requests to be made directly to the base URL From cb51f98f90b0961b3201654dda6b06c08aff62a4 Mon Sep 17 00:00:00 2001 From: mustofa-id <25121822+mustofa-id@users.noreply.github.com> Date: Wed, 7 Jan 2026 11:40:54 +0700 Subject: [PATCH 3/3] tidy up --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a18ff1..efc1543 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,19 @@ if (result2.error) { ### `ihs.request({ ... })` -Request ke RestAPI secara langsung menggunakan method `request()` dari instansi `IHS`. +Request ke RestAPI secara langsung menggunakan method `request()` dari instansi `IHS`. Sangat berguna saat API atau Endpoint belum diimplementasikan. Contoh: + +```ts +await ihs.request({ + type: 'base', + path: '/masterdata/v1/mastersaranaindex/mastersarana', + searchParams: { + limit: '10', + page: '1', + jenis_sarana: '121' + } +}); +``` ## Konfigurasi