Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-friends-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ssecd/ihs': patch
---

Allow requests to be made directly to the base URL
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,22 @@ if (result2.error) {
}
```

### `ihs.request({ ... })`

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

Konfigurasi mengikuti interface berikut:
Expand Down
29 changes: 26 additions & 3 deletions src/ihs.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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);

Expand Down
21 changes: 19 additions & 2 deletions src/ihs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,23 @@ export interface IHSConfig {
type UserConfig = Partial<IHSConfig> | (() => MaybePromise<Partial<IHSConfig>>);

type RequestConfig = {
type: Exclude<API, 'auth'>;
/**
* 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<API, 'auth'>;
path: string;
searchParams?: URLSearchParams | Record<string, string> | [string, string][];
} & RequestInit;
Expand Down Expand Up @@ -149,7 +165,8 @@ export default class IHS {
async request(config: RequestConfig): Promise<Response> {
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 = {
Expand Down
4 changes: 4 additions & 0 deletions words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ kbki
kemkes
kriptografi
lkpp
masterdata
mastersarana
mastersaranaindex
OAEP
OPTIN
OPTOUT
Expand All @@ -26,6 +29,7 @@ rxterm
Silampari
simrs
Sriwijaya
ssecd
subkategori
tkdn
ucum