|
3 | 3 | */
|
4 | 4 |
|
5 | 5 | import * as core from "./core";
|
| 6 | +import * as TrueFoundry from "./api/index"; |
| 7 | +import urlJoin from "url-join"; |
| 8 | +import * as errors from "./errors/index"; |
6 | 9 | import { Internal } from "./api/resources/internal/client/Client";
|
7 | 10 | import { Users } from "./api/resources/users/client/Client";
|
8 | 11 | import { Teams } from "./api/resources/teams/client/Client";
|
@@ -202,4 +205,182 @@ export class TrueFoundryClient {
|
202 | 205 | public get tracingProjects(): TracingProjects {
|
203 | 206 | return (this._tracingProjects ??= new TracingProjects(this._options));
|
204 | 207 | }
|
| 208 | + |
| 209 | + /** |
| 210 | + * Applies a given manifest to create or update resources of specific types, such as provider-account, cluster, workspace, or ml-repo. |
| 211 | + * |
| 212 | + * @param {TrueFoundry.TrueFoundryApplyRequest} request |
| 213 | + * @param {TrueFoundryClient.RequestOptions} requestOptions - Request-specific configuration. |
| 214 | + * |
| 215 | + * @example |
| 216 | + * await client.apply({ |
| 217 | + * manifest: { |
| 218 | + * type: "ml-repo", |
| 219 | + * name: "name", |
| 220 | + * storage_integration_fqn: "storage_integration_fqn", |
| 221 | + * collaborators: [{ |
| 222 | + * subject: "subject", |
| 223 | + * role_id: "role_id" |
| 224 | + * }] |
| 225 | + * } |
| 226 | + * }) |
| 227 | + */ |
| 228 | + public apply( |
| 229 | + request: TrueFoundry.TrueFoundryApplyRequest, |
| 230 | + requestOptions?: TrueFoundryClient.RequestOptions, |
| 231 | + ): core.HttpResponsePromise<TrueFoundry.TrueFoundryApplyResponse> { |
| 232 | + return core.HttpResponsePromise.fromPromise(this.__apply(request, requestOptions)); |
| 233 | + } |
| 234 | + |
| 235 | + private async __apply( |
| 236 | + request: TrueFoundry.TrueFoundryApplyRequest, |
| 237 | + requestOptions?: TrueFoundryClient.RequestOptions, |
| 238 | + ): Promise<core.WithRawResponse<TrueFoundry.TrueFoundryApplyResponse>> { |
| 239 | + const _response = await (this._options.fetcher ?? core.fetcher)({ |
| 240 | + url: urlJoin( |
| 241 | + (await core.Supplier.get(this._options.baseUrl)) ?? |
| 242 | + (await core.Supplier.get(this._options.environment)), |
| 243 | + "api/svc/v1/apply", |
| 244 | + ), |
| 245 | + method: "PUT", |
| 246 | + headers: { |
| 247 | + Authorization: await this._getAuthorizationHeader(), |
| 248 | + "X-Fern-Language": "JavaScript", |
| 249 | + "X-Fern-SDK-Name": "truefoundry-sdk", |
| 250 | + "X-Fern-SDK-Version": "0.0.0", |
| 251 | + "User-Agent": "truefoundry-sdk/0.0.0", |
| 252 | + "X-Fern-Runtime": core.RUNTIME.type, |
| 253 | + "X-Fern-Runtime-Version": core.RUNTIME.version, |
| 254 | + ...requestOptions?.headers, |
| 255 | + }, |
| 256 | + contentType: "application/json", |
| 257 | + requestType: "json", |
| 258 | + body: request, |
| 259 | + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, |
| 260 | + maxRetries: requestOptions?.maxRetries, |
| 261 | + abortSignal: requestOptions?.abortSignal, |
| 262 | + }); |
| 263 | + if (_response.ok) { |
| 264 | + return { data: _response.body as TrueFoundry.TrueFoundryApplyResponse, rawResponse: _response.rawResponse }; |
| 265 | + } |
| 266 | + |
| 267 | + if (_response.error.reason === "status-code") { |
| 268 | + throw new errors.TrueFoundryError({ |
| 269 | + statusCode: _response.error.statusCode, |
| 270 | + body: _response.error.body, |
| 271 | + rawResponse: _response.rawResponse, |
| 272 | + }); |
| 273 | + } |
| 274 | + |
| 275 | + switch (_response.error.reason) { |
| 276 | + case "non-json": |
| 277 | + throw new errors.TrueFoundryError({ |
| 278 | + statusCode: _response.error.statusCode, |
| 279 | + body: _response.error.rawBody, |
| 280 | + rawResponse: _response.rawResponse, |
| 281 | + }); |
| 282 | + case "timeout": |
| 283 | + throw new errors.TrueFoundryTimeoutError("Timeout exceeded when calling PUT /api/svc/v1/apply."); |
| 284 | + case "unknown": |
| 285 | + throw new errors.TrueFoundryError({ |
| 286 | + message: _response.error.errorMessage, |
| 287 | + rawResponse: _response.rawResponse, |
| 288 | + }); |
| 289 | + } |
| 290 | + } |
| 291 | + |
| 292 | + /** |
| 293 | + * Deletes resources of specific types, such as provider-account, cluster, workspace, or application. |
| 294 | + * |
| 295 | + * @param {TrueFoundry.TrueFoundryDeleteRequest} request |
| 296 | + * @param {TrueFoundryClient.RequestOptions} requestOptions - Request-specific configuration. |
| 297 | + * |
| 298 | + * @example |
| 299 | + * await client.delete({ |
| 300 | + * manifest: { |
| 301 | + * type: "ml-repo", |
| 302 | + * name: "name", |
| 303 | + * storage_integration_fqn: "storage_integration_fqn", |
| 304 | + * collaborators: [{ |
| 305 | + * subject: "subject", |
| 306 | + * role_id: "role_id" |
| 307 | + * }] |
| 308 | + * } |
| 309 | + * }) |
| 310 | + */ |
| 311 | + public delete( |
| 312 | + request: TrueFoundry.TrueFoundryDeleteRequest, |
| 313 | + requestOptions?: TrueFoundryClient.RequestOptions, |
| 314 | + ): core.HttpResponsePromise<void> { |
| 315 | + return core.HttpResponsePromise.fromPromise(this.__delete(request, requestOptions)); |
| 316 | + } |
| 317 | + |
| 318 | + private async __delete( |
| 319 | + request: TrueFoundry.TrueFoundryDeleteRequest, |
| 320 | + requestOptions?: TrueFoundryClient.RequestOptions, |
| 321 | + ): Promise<core.WithRawResponse<void>> { |
| 322 | + const _response = await (this._options.fetcher ?? core.fetcher)({ |
| 323 | + url: urlJoin( |
| 324 | + (await core.Supplier.get(this._options.baseUrl)) ?? |
| 325 | + (await core.Supplier.get(this._options.environment)), |
| 326 | + "api/svc/v1/delete", |
| 327 | + ), |
| 328 | + method: "POST", |
| 329 | + headers: { |
| 330 | + Authorization: await this._getAuthorizationHeader(), |
| 331 | + "X-Fern-Language": "JavaScript", |
| 332 | + "X-Fern-SDK-Name": "truefoundry-sdk", |
| 333 | + "X-Fern-SDK-Version": "0.0.0", |
| 334 | + "User-Agent": "truefoundry-sdk/0.0.0", |
| 335 | + "X-Fern-Runtime": core.RUNTIME.type, |
| 336 | + "X-Fern-Runtime-Version": core.RUNTIME.version, |
| 337 | + ...requestOptions?.headers, |
| 338 | + }, |
| 339 | + contentType: "application/json", |
| 340 | + requestType: "json", |
| 341 | + body: request, |
| 342 | + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, |
| 343 | + maxRetries: requestOptions?.maxRetries, |
| 344 | + abortSignal: requestOptions?.abortSignal, |
| 345 | + }); |
| 346 | + if (_response.ok) { |
| 347 | + return { data: undefined, rawResponse: _response.rawResponse }; |
| 348 | + } |
| 349 | + |
| 350 | + if (_response.error.reason === "status-code") { |
| 351 | + throw new errors.TrueFoundryError({ |
| 352 | + statusCode: _response.error.statusCode, |
| 353 | + body: _response.error.body, |
| 354 | + rawResponse: _response.rawResponse, |
| 355 | + }); |
| 356 | + } |
| 357 | + |
| 358 | + switch (_response.error.reason) { |
| 359 | + case "non-json": |
| 360 | + throw new errors.TrueFoundryError({ |
| 361 | + statusCode: _response.error.statusCode, |
| 362 | + body: _response.error.rawBody, |
| 363 | + rawResponse: _response.rawResponse, |
| 364 | + }); |
| 365 | + case "timeout": |
| 366 | + throw new errors.TrueFoundryTimeoutError("Timeout exceeded when calling POST /api/svc/v1/delete."); |
| 367 | + case "unknown": |
| 368 | + throw new errors.TrueFoundryError({ |
| 369 | + message: _response.error.errorMessage, |
| 370 | + rawResponse: _response.rawResponse, |
| 371 | + }); |
| 372 | + } |
| 373 | + } |
| 374 | + |
| 375 | + protected async _getAuthorizationHeader(): Promise<string> { |
| 376 | + const bearer = (await core.Supplier.get(this._options.apiKey)) ?? process?.env["TFY_API_KEY"]; |
| 377 | + if (bearer == null) { |
| 378 | + throw new errors.TrueFoundryError({ |
| 379 | + message: |
| 380 | + "Please specify a bearer by either passing it in to the constructor or initializing a TFY_API_KEY environment variable", |
| 381 | + }); |
| 382 | + } |
| 383 | + |
| 384 | + return `Bearer ${bearer}`; |
| 385 | + } |
205 | 386 | }
|
0 commit comments