Skip to content

Commit c9f4f75

Browse files
committed
Release 0.0.1
0 parents  commit c9f4f75

File tree

125 files changed

+8771
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+8771
-0
lines changed

.fernignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Specify files that shouldn't be modified by Fern

.github/workflows/ci.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: ci
2+
3+
on: [push]
4+
5+
jobs:
6+
compile:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout repo
11+
uses: actions/checkout@v3
12+
13+
- name: Set up node
14+
uses: actions/setup-node@v3
15+
16+
- name: Compile
17+
run: yarn && yarn build
18+
19+
test:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v3
25+
26+
- name: Set up node
27+
uses: actions/setup-node@v3
28+
29+
- name: Compile
30+
run: yarn && yarn test
31+
32+
publish:
33+
needs: [ compile, test ]
34+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout repo
38+
uses: actions/checkout@v3
39+
- name: Set up node
40+
uses: actions/setup-node@v3
41+
- name: Install dependencies
42+
run: yarn install
43+
- name: Build
44+
run: yarn build
45+
46+
- name: Publish to npm
47+
run: |
48+
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
49+
if [[ ${GITHUB_REF} == *alpha* ]]; then
50+
npm publish --access public --tag alpha
51+
elif [[ ${GITHUB_REF} == *beta* ]]; then
52+
npm publish --access public --tag beta
53+
else
54+
npm publish --access public
55+
fi
56+
env:
57+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
/dist

.npmignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
src
3+
tests
4+
.gitignore
5+
.github
6+
.fernignore
7+
.prettierrc.yml
8+
tsconfig.json
9+
yarn.lock

.prettierrc.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tabWidth: 4
2+
printWidth: 120

README.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Ogp TypeScript Library
2+
3+
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fopengovsg%2Frefer-ts-sdk)
4+
[![npm shield](https://img.shields.io/npm/v/ogp-refx)](https://www.npmjs.com/package/ogp-refx)
5+
6+
The Ogp TypeScript library provides convenient access to the Ogp API from TypeScript.
7+
8+
## Installation
9+
10+
```sh
11+
npm i -s ogp-refx
12+
```
13+
14+
## Reference
15+
16+
A full reference for this library is available [here](./reference.md).
17+
18+
## Usage
19+
20+
Instantiate and use the client with the following:
21+
22+
```typescript
23+
import { ReferralExchangeClient } from "ogp-refx";
24+
25+
const client = new ReferralExchangeClient({ environment: "YOUR_BASE_URL", apiKey: "YOUR_API_KEY" });
26+
await client.formSgWebhooksControllerHandleDoctorNotesFormWebhook({
27+
key: "value",
28+
});
29+
```
30+
31+
## Request And Response Types
32+
33+
The SDK exports all request and response types as TypeScript interfaces. Simply import them with the
34+
following namespace:
35+
36+
```typescript
37+
import { ReferralExchange } from "ogp-refx";
38+
39+
const request: ReferralExchange.EligibilityGetRequest = {
40+
...
41+
};
42+
```
43+
44+
## Exception Handling
45+
46+
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error
47+
will be thrown.
48+
49+
```typescript
50+
import { ReferralExchangeError } from "ogp-refx";
51+
52+
try {
53+
await client.formSgWebhooksControllerHandleDoctorNotesFormWebhook(...);
54+
} catch (err) {
55+
if (err instanceof ReferralExchangeError) {
56+
console.log(err.statusCode);
57+
console.log(err.message);
58+
console.log(err.body);
59+
}
60+
}
61+
```
62+
63+
## Advanced
64+
65+
### Additional Headers
66+
67+
If you would like to send additional headers as part of the request, use the `headers` request option.
68+
69+
```typescript
70+
const response = await client.formSgWebhooksControllerHandleDoctorNotesFormWebhook(..., {
71+
headers: {
72+
'X-Custom-Header': 'custom value'
73+
}
74+
});
75+
```
76+
77+
### Retries
78+
79+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
80+
as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
81+
retry limit (default: 2).
82+
83+
A request is deemed retriable when any of the following HTTP status codes is returned:
84+
85+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
86+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
87+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
88+
89+
Use the `maxRetries` request option to configure this behavior.
90+
91+
```typescript
92+
const response = await client.formSgWebhooksControllerHandleDoctorNotesFormWebhook(..., {
93+
maxRetries: 0 // override maxRetries at the request level
94+
});
95+
```
96+
97+
### Timeouts
98+
99+
The SDK defaults to a 60 second timeout. Use the `timeoutInSeconds` option to configure this behavior.
100+
101+
```typescript
102+
const response = await client.formSgWebhooksControllerHandleDoctorNotesFormWebhook(..., {
103+
timeoutInSeconds: 30 // override timeout to 30s
104+
});
105+
```
106+
107+
### Aborting Requests
108+
109+
The SDK allows users to abort requests at any point by passing in an abort signal.
110+
111+
```typescript
112+
const controller = new AbortController();
113+
const response = await client.formSgWebhooksControllerHandleDoctorNotesFormWebhook(..., {
114+
abortSignal: controller.signal
115+
});
116+
controller.abort(); // aborts the request
117+
```
118+
119+
### Runtime Compatibility
120+
121+
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
122+
runtimes:
123+
124+
- Node.js 18+
125+
- Vercel
126+
- Cloudflare Workers
127+
- Deno v1.25+
128+
- Bun 1.0+
129+
- React Native
130+
131+
### Customizing Fetch Client
132+
133+
The SDK provides a way for your to customize the underlying HTTP client / Fetch function. If you're running in an
134+
unsupported environment, this provides a way for you to break glass and ensure the SDK works.
135+
136+
```typescript
137+
import { ReferralExchangeClient } from "ogp-refx";
138+
139+
const client = new ReferralExchangeClient({
140+
...
141+
fetcher: // provide your implementation here
142+
});
143+
```
144+
145+
## Contributing
146+
147+
While we value open-source contributions to this SDK, this library is generated programmatically.
148+
Additions made directly to this library would have to be moved over to our generation code,
149+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
150+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
151+
an issue first to discuss with us!
152+
153+
On the other hand, contributions to the README are always very welcome!

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
};

package.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "ogp-refx",
3+
"version": "0.0.1",
4+
"private": false,
5+
"repository": "https://github.com/opengovsg/refer-ts-sdk",
6+
"main": "./index.js",
7+
"types": "./index.d.ts",
8+
"scripts": {
9+
"format": "prettier . --write --ignore-unknown",
10+
"build": "tsc",
11+
"prepack": "cp -rv dist/. .",
12+
"test": "jest"
13+
},
14+
"dependencies": {
15+
"url-join": "4.0.1",
16+
"form-data": "^4.0.0",
17+
"formdata-node": "^6.0.3",
18+
"node-fetch": "2.7.0",
19+
"qs": "6.11.2",
20+
"readable-stream": "^4.5.2"
21+
},
22+
"devDependencies": {
23+
"@types/url-join": "4.0.1",
24+
"@types/qs": "6.9.8",
25+
"@types/node-fetch": "2.6.9",
26+
"@types/readable-stream": "^4.0.15",
27+
"webpack": "^5.94.0",
28+
"ts-loader": "^9.3.1",
29+
"jest": "29.7.0",
30+
"@types/jest": "29.5.5",
31+
"ts-jest": "29.1.1",
32+
"jest-environment-jsdom": "29.7.0",
33+
"@types/node": "17.0.33",
34+
"prettier": "2.7.1",
35+
"typescript": "4.6.4"
36+
},
37+
"browser": {
38+
"fs": false,
39+
"os": false,
40+
"path": false
41+
}
42+
}

0 commit comments

Comments
 (0)