Skip to content

Commit

Permalink
Release 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Dec 14, 2024
1 parent 361c846 commit a64d112
Show file tree
Hide file tree
Showing 28 changed files with 328 additions and 73 deletions.
37 changes: 7 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,8 @@ Instantiate and use the client with the following:
import { ReferralExchangeClient } from "@opengovsg/refx-ts-sdk";

const client = new ReferralExchangeClient({ environment: "YOUR_BASE_URL", apiKey: "YOUR_API_KEY" });
await client.referrals.upsert({
patient: {
uin: "uin",
name: "name",
phoneNumber: "91234567",
dob: "1990-01-01",
gender: "Male",
},
offeringId: "offeringId",
senderHciCode: "senderHciCode",
senderInstitutionName: "senderInstitutionName",
doctorMcr: "doctorMcr",
doctorName: "doctorName",
doctorEmail: "doctorEmail",
doctorContactNumber: "doctorContactNumber",
isSubsidised: {
key: "value",
},
isUrgent: {
key: "value",
},
isDraft: {
key: "value",
},
formResponses: [{}],
await client.apiHoldingControllerCreateNote("referralId", {
authorHciCode: "authorHciCode",
});
```

Expand All @@ -73,7 +50,7 @@ will be thrown.
import { ReferralExchangeError } from "@opengovsg/refx-ts-sdk";

try {
await client.referrals.upsert(...);
await client.apiHoldingControllerCreateNote(...);
} catch (err) {
if (err instanceof ReferralExchangeError) {
console.log(err.statusCode);
Expand All @@ -90,7 +67,7 @@ try {
If you would like to send additional headers as part of the request, use the `headers` request option.

```typescript
const response = await client.referrals.upsert(..., {
const response = await client.apiHoldingControllerCreateNote(..., {
headers: {
'X-Custom-Header': 'custom value'
}
Expand All @@ -112,7 +89,7 @@ A request is deemed retriable when any of the following HTTP status codes is ret
Use the `maxRetries` request option to configure this behavior.

```typescript
const response = await client.referrals.upsert(..., {
const response = await client.apiHoldingControllerCreateNote(..., {
maxRetries: 0 // override maxRetries at the request level
});
```
Expand All @@ -122,7 +99,7 @@ const response = await client.referrals.upsert(..., {
The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.

```typescript
const response = await client.referrals.upsert(..., {
const response = await client.apiHoldingControllerCreateNote(..., {
timeoutInSeconds: 30 // override timeout to 30s
});
```
Expand All @@ -133,7 +110,7 @@ The SDK allows users to abort requests at any point by passing in an abort signa

```typescript
const controller = new AbortController();
const response = await client.referrals.upsert(..., {
const response = await client.apiHoldingControllerCreateNote(..., {
abortSignal: controller.signal
});
controller.abort(); // aborts the request
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opengovsg/refx-ts-sdk",
"version": "2024.10.3",
"version": "0.0.7",
"private": false,
"repository": "https://github.com/opengovsg/refer-ts-sdk",
"main": "./index.js",
Expand Down
70 changes: 68 additions & 2 deletions reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
# Reference

<details><summary><code>client.<a href="/src/Client.ts">apiHoldingControllerBackToDraftReferral</a>(referralId) -> ReferralExchange.ReferralDto</code></summary>
<dl>
<dd>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```typescript
await client.apiHoldingControllerBackToDraftReferral("referralId");
```

</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**referralId:** `string`

</dd>
</dl>

<dl>
<dd>

**requestOptions:** `ReferralExchangeClient.RequestOptions`

</dd>
</dl>
</dd>
</dl>

</dd>
</dl>
</details>

##

## Eligibility

<details><summary><code>client.eligibility.<a href="/src/api/resources/eligibility/client/Client.ts">get</a>({ ...params }) -> ReferralExchange.EligibilityRes</code></summary>
Expand Down Expand Up @@ -178,7 +228,7 @@ await client.referrals.upsert({
</dl>
</details>

<details><summary><code>client.referrals.<a href="/src/api/resources/referrals/client/Client.ts">get</a>(referralId) -> ReferralExchange.FullReferralDto</code></summary>
<details><summary><code>client.referrals.<a href="/src/api/resources/referrals/client/Client.ts">get</a>(referralId, { ...params }) -> ReferralExchange.FullReferralDto</code></summary>
<dl>
<dd>

Expand Down Expand Up @@ -215,6 +265,14 @@ await client.referrals.get("referralId");
<dl>
<dd>

**request:** `ReferralExchange.ReferralsGetRequest`

</dd>
</dl>

<dl>
<dd>

**requestOptions:** `Referrals.RequestOptions`

</dd>
Expand Down Expand Up @@ -654,7 +712,7 @@ await client.offerings.listTimeslots("offeringId", {

## Public

<details><summary><code>client.public.<a href="/src/api/resources/public/client/Client.ts">getReferral</a>(referralId) -> ReferralExchange.PublicReferralDto[]</code></summary>
<details><summary><code>client.public.<a href="/src/api/resources/public/client/Client.ts">getReferral</a>(referralId, { ...params }) -> ReferralExchange.PublicReferralDto[]</code></summary>
<dl>
<dd>

Expand Down Expand Up @@ -691,6 +749,14 @@ await client.public.getReferral("referralId");
<dl>
<dd>

**request:** `ReferralExchange.PublicGetReferralRequest`

</dd>
</dl>

<dl>
<dd>

**requestOptions:** `Public.RequestOptions`

</dd>
Expand Down
135 changes: 135 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/

import * as core from "./core";
import * as ReferralExchange from "./api/index";
import urlJoin from "url-join";
import * as errors from "./errors/index";
import { Eligibility } from "./api/resources/eligibility/client/Client";
import { Referrals } from "./api/resources/referrals/client/Client";
import { Offerings } from "./api/resources/offerings/client/Client";
Expand Down Expand Up @@ -62,4 +65,136 @@ export class ReferralExchangeClient {
public get health(): Health {
return (this._health ??= new Health(this._options));
}

/**
* @param {string} referralId
* @param {ReferralExchange.CreateNoteReq} request
* @param {ReferralExchangeClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @example
* await client.apiHoldingControllerCreateNote("referralId", {
* authorHciCode: "authorHciCode"
* })
*/
public async apiHoldingControllerCreateNote(
referralId: string,
request: ReferralExchange.CreateNoteReq,
requestOptions?: ReferralExchangeClient.RequestOptions
): Promise<ReferralExchange.NoteDto> {
const _response = await (this._options.fetcher ?? core.fetcher)({
url: urlJoin(
await core.Supplier.get(this._options.environment),
`api/v1/referrals/${encodeURIComponent(referralId)}/notes`
),
method: "POST",
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@opengovsg/refx-ts-sdk",
"X-Fern-SDK-Version": "0.0.7",
"User-Agent": "@opengovsg/refx-ts-sdk/0.0.7",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
body: request,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ReferralExchange.NoteDto;
}

if (_response.error.reason === "status-code") {
throw new errors.ReferralExchangeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.ReferralExchangeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ReferralExchangeTimeoutError(
"Timeout exceeded when calling POST /api/v1/referrals/{referralId}/notes."
);
case "unknown":
throw new errors.ReferralExchangeError({
message: _response.error.errorMessage,
});
}
}

/**
* @param {string} referralId
* @param {ReferralExchangeClient.RequestOptions} requestOptions - Request-specific configuration.
*
* @example
* await client.apiHoldingControllerBackToDraftReferral("referralId")
*/
public async apiHoldingControllerBackToDraftReferral(
referralId: string,
requestOptions?: ReferralExchangeClient.RequestOptions
): Promise<ReferralExchange.ReferralDto> {
const _response = await (this._options.fetcher ?? core.fetcher)({
url: urlJoin(
await core.Supplier.get(this._options.environment),
`api/v1/referrals/${encodeURIComponent(referralId)}/back-to-draft`
),
method: "POST",
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@opengovsg/refx-ts-sdk",
"X-Fern-SDK-Version": "0.0.7",
"User-Agent": "@opengovsg/refx-ts-sdk/0.0.7",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
abortSignal: requestOptions?.abortSignal,
});
if (_response.ok) {
return _response.body as ReferralExchange.ReferralDto;
}

if (_response.error.reason === "status-code") {
throw new errors.ReferralExchangeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.ReferralExchangeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.ReferralExchangeTimeoutError(
"Timeout exceeded when calling POST /api/v1/referrals/{referralId}/back-to-draft."
);
case "unknown":
throw new errors.ReferralExchangeError({
message: _response.error.errorMessage,
});
}
}

protected async _getCustomAuthorizationHeaders() {
const apiKeyValue = await core.Supplier.get(this._options.apiKey);
return { Authorization: apiKeyValue };
}
}
1 change: 1 addition & 0 deletions src/api/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./requests";
16 changes: 16 additions & 0 deletions src/api/client/requests/CreateNoteReq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

/**
* @example
* {
* authorHciCode: "authorHciCode"
* }
*/
export interface CreateNoteReq {
/** Note content - plaintext. */
content?: string;
/** Author HCI code. Must be already tied by your system. */
authorHciCode: string;
}
1 change: 1 addition & 0 deletions src/api/client/requests/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { type CreateNoteReq } from "./CreateNoteReq";
1 change: 1 addition & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./resources";
export * from "./types";
export * from "./errors";
export * from "./client";
4 changes: 2 additions & 2 deletions src/api/resources/eligibility/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class Eligibility {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@opengovsg/refx-ts-sdk",
"X-Fern-SDK-Version": "2024.10.3",
"User-Agent": "@opengovsg/refx-ts-sdk/2024.10.3",
"X-Fern-SDK-Version": "0.0.7",
"User-Agent": "@opengovsg/refx-ts-sdk/0.0.7",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down
4 changes: 2 additions & 2 deletions src/api/resources/health/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class Health {
headers: {
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@opengovsg/refx-ts-sdk",
"X-Fern-SDK-Version": "2024.10.3",
"User-Agent": "@opengovsg/refx-ts-sdk/2024.10.3",
"X-Fern-SDK-Version": "0.0.7",
"User-Agent": "@opengovsg/refx-ts-sdk/0.0.7",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
Expand Down
1 change: 1 addition & 0 deletions src/api/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * as health from "./health";
export * from "./eligibility/client/requests";
export * from "./referrals/client/requests";
export * from "./offerings/client/requests";
export * from "./public/client/requests";
Loading

0 comments on commit a64d112

Please sign in to comment.