|
3 | 3 | */
|
4 | 4 |
|
5 | 5 | import * as core from "./core";
|
| 6 | +import * as ReferralExchange from "./api/index"; |
| 7 | +import urlJoin from "url-join"; |
| 8 | +import * as errors from "./errors/index"; |
6 | 9 | import { Eligibility } from "./api/resources/eligibility/client/Client";
|
7 | 10 | import { Referrals } from "./api/resources/referrals/client/Client";
|
8 | 11 | import { Offerings } from "./api/resources/offerings/client/Client";
|
@@ -62,4 +65,136 @@ export class ReferralExchangeClient {
|
62 | 65 | public get health(): Health {
|
63 | 66 | return (this._health ??= new Health(this._options));
|
64 | 67 | }
|
| 68 | + |
| 69 | + /** |
| 70 | + * @param {string} referralId |
| 71 | + * @param {ReferralExchange.CreateNoteReq} request |
| 72 | + * @param {ReferralExchangeClient.RequestOptions} requestOptions - Request-specific configuration. |
| 73 | + * |
| 74 | + * @example |
| 75 | + * await client.apiHoldingControllerCreateNote("referralId", { |
| 76 | + * authorHciCode: "authorHciCode" |
| 77 | + * }) |
| 78 | + */ |
| 79 | + public async apiHoldingControllerCreateNote( |
| 80 | + referralId: string, |
| 81 | + request: ReferralExchange.CreateNoteReq, |
| 82 | + requestOptions?: ReferralExchangeClient.RequestOptions |
| 83 | + ): Promise<ReferralExchange.NoteDto> { |
| 84 | + const _response = await (this._options.fetcher ?? core.fetcher)({ |
| 85 | + url: urlJoin( |
| 86 | + await core.Supplier.get(this._options.environment), |
| 87 | + `api/v1/referrals/${encodeURIComponent(referralId)}/notes` |
| 88 | + ), |
| 89 | + method: "POST", |
| 90 | + headers: { |
| 91 | + "X-Fern-Language": "JavaScript", |
| 92 | + "X-Fern-SDK-Name": "@opengovsg/refx-ts-sdk", |
| 93 | + "X-Fern-SDK-Version": "0.0.7", |
| 94 | + "User-Agent": "@opengovsg/refx-ts-sdk/0.0.7", |
| 95 | + "X-Fern-Runtime": core.RUNTIME.type, |
| 96 | + "X-Fern-Runtime-Version": core.RUNTIME.version, |
| 97 | + ...(await this._getCustomAuthorizationHeaders()), |
| 98 | + ...requestOptions?.headers, |
| 99 | + }, |
| 100 | + contentType: "application/json", |
| 101 | + requestType: "json", |
| 102 | + body: request, |
| 103 | + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, |
| 104 | + maxRetries: requestOptions?.maxRetries, |
| 105 | + abortSignal: requestOptions?.abortSignal, |
| 106 | + }); |
| 107 | + if (_response.ok) { |
| 108 | + return _response.body as ReferralExchange.NoteDto; |
| 109 | + } |
| 110 | + |
| 111 | + if (_response.error.reason === "status-code") { |
| 112 | + throw new errors.ReferralExchangeError({ |
| 113 | + statusCode: _response.error.statusCode, |
| 114 | + body: _response.error.body, |
| 115 | + }); |
| 116 | + } |
| 117 | + |
| 118 | + switch (_response.error.reason) { |
| 119 | + case "non-json": |
| 120 | + throw new errors.ReferralExchangeError({ |
| 121 | + statusCode: _response.error.statusCode, |
| 122 | + body: _response.error.rawBody, |
| 123 | + }); |
| 124 | + case "timeout": |
| 125 | + throw new errors.ReferralExchangeTimeoutError( |
| 126 | + "Timeout exceeded when calling POST /api/v1/referrals/{referralId}/notes." |
| 127 | + ); |
| 128 | + case "unknown": |
| 129 | + throw new errors.ReferralExchangeError({ |
| 130 | + message: _response.error.errorMessage, |
| 131 | + }); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * @param {string} referralId |
| 137 | + * @param {ReferralExchangeClient.RequestOptions} requestOptions - Request-specific configuration. |
| 138 | + * |
| 139 | + * @example |
| 140 | + * await client.apiHoldingControllerBackToDraftReferral("referralId") |
| 141 | + */ |
| 142 | + public async apiHoldingControllerBackToDraftReferral( |
| 143 | + referralId: string, |
| 144 | + requestOptions?: ReferralExchangeClient.RequestOptions |
| 145 | + ): Promise<ReferralExchange.ReferralDto> { |
| 146 | + const _response = await (this._options.fetcher ?? core.fetcher)({ |
| 147 | + url: urlJoin( |
| 148 | + await core.Supplier.get(this._options.environment), |
| 149 | + `api/v1/referrals/${encodeURIComponent(referralId)}/back-to-draft` |
| 150 | + ), |
| 151 | + method: "POST", |
| 152 | + headers: { |
| 153 | + "X-Fern-Language": "JavaScript", |
| 154 | + "X-Fern-SDK-Name": "@opengovsg/refx-ts-sdk", |
| 155 | + "X-Fern-SDK-Version": "0.0.7", |
| 156 | + "User-Agent": "@opengovsg/refx-ts-sdk/0.0.7", |
| 157 | + "X-Fern-Runtime": core.RUNTIME.type, |
| 158 | + "X-Fern-Runtime-Version": core.RUNTIME.version, |
| 159 | + ...(await this._getCustomAuthorizationHeaders()), |
| 160 | + ...requestOptions?.headers, |
| 161 | + }, |
| 162 | + contentType: "application/json", |
| 163 | + requestType: "json", |
| 164 | + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, |
| 165 | + maxRetries: requestOptions?.maxRetries, |
| 166 | + abortSignal: requestOptions?.abortSignal, |
| 167 | + }); |
| 168 | + if (_response.ok) { |
| 169 | + return _response.body as ReferralExchange.ReferralDto; |
| 170 | + } |
| 171 | + |
| 172 | + if (_response.error.reason === "status-code") { |
| 173 | + throw new errors.ReferralExchangeError({ |
| 174 | + statusCode: _response.error.statusCode, |
| 175 | + body: _response.error.body, |
| 176 | + }); |
| 177 | + } |
| 178 | + |
| 179 | + switch (_response.error.reason) { |
| 180 | + case "non-json": |
| 181 | + throw new errors.ReferralExchangeError({ |
| 182 | + statusCode: _response.error.statusCode, |
| 183 | + body: _response.error.rawBody, |
| 184 | + }); |
| 185 | + case "timeout": |
| 186 | + throw new errors.ReferralExchangeTimeoutError( |
| 187 | + "Timeout exceeded when calling POST /api/v1/referrals/{referralId}/back-to-draft." |
| 188 | + ); |
| 189 | + case "unknown": |
| 190 | + throw new errors.ReferralExchangeError({ |
| 191 | + message: _response.error.errorMessage, |
| 192 | + }); |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + protected async _getCustomAuthorizationHeaders() { |
| 197 | + const apiKeyValue = await core.Supplier.get(this._options.apiKey); |
| 198 | + return { Authorization: apiKeyValue }; |
| 199 | + } |
65 | 200 | }
|
0 commit comments