/* * Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. */ import { SDKHooks } from "../hooks"; import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "../lib/config"; import * as enc$ from "../lib/encodings"; import { HTTPClient } from "../lib/http"; import * as schemas$ from "../lib/schemas"; import { ClientSDK, RequestOptions } from "../lib/sdks"; import * as errors from "../models/errors"; import * as operations from "../models/operations"; export class Updater extends ClientSDK { private readonly options$: SDKOptions & { hooks?: SDKHooks }; constructor(options: SDKOptions = {}) { const opt = options as unknown; let hooks: SDKHooks; if ( typeof opt === "object" && opt != null && "hooks" in opt && opt.hooks instanceof SDKHooks ) { hooks = opt.hooks; } else { hooks = new SDKHooks(); } super({ client: options.httpClient || new HTTPClient(), baseURL: serverURLFromOptions(options), hooks, }); this.options$ = { ...options, hooks }; void this.options$; } /** * Querying status of updates * * @remarks * Querying status of updates */ async getUpdateStatus(options?: RequestOptions): Promise { const headers$ = new Headers(); headers$.set("user-agent", SDK_METADATA.userAgent); headers$.set("Accept", "application/json"); const path$ = this.templateURLComponent("/updater/status")(); const query$ = ""; let security$; if (typeof this.options$.accessToken === "function") { security$ = { accessToken: await this.options$.accessToken() }; } else if (this.options$.accessToken) { security$ = { accessToken: this.options$.accessToken }; } else { security$ = {}; } const context = { operationID: "getUpdateStatus", oAuth2Scopes: [], securitySource: this.options$.accessToken, }; const securitySettings$ = this.resolveGlobalSecurity(security$); const doOptions = { context, errorCodes: ["400", "401", "4XX", "5XX"] }; const request$ = this.createRequest$( context, { security: securitySettings$, method: "GET", path: path$, headers: headers$, query: query$, }, options ); const response = await this.do$(request$, doOptions); const responseFields$ = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; if (this.matchResponse(response, 200, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return operations.GetUpdateStatusResponse$.inboundSchema.parse({ ...responseFields$, object: val$, }); }, "Response validation failed" ); return result; } else if (this.matchResponse(response, 401, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return errors.GetUpdateStatusResponseBody$.inboundSchema.parse({ ...responseFields$, ...val$, }); }, "Response validation failed" ); throw result; } else { const responseBody = await response.text(); throw new errors.SDKError( "Unexpected API response status or content-type", response, responseBody ); } } /** * Checking for updates * * @remarks * Checking for updates */ async checkForUpdates( download?: operations.Download | undefined, options?: RequestOptions ): Promise { const input$: operations.CheckForUpdatesRequest = { download: download, }; const headers$ = new Headers(); headers$.set("user-agent", SDK_METADATA.userAgent); headers$.set("Accept", "application/json"); const payload$ = schemas$.parse( input$, (value$) => operations.CheckForUpdatesRequest$.outboundSchema.parse(value$), "Input validation failed" ); const body$ = null; const path$ = this.templateURLComponent("/updater/check")(); const query$ = [ enc$.encodeForm("download", payload$.download, { explode: true, charEncoding: "percent", }), ] .filter(Boolean) .join("&"); let security$; if (typeof this.options$.accessToken === "function") { security$ = { accessToken: await this.options$.accessToken() }; } else if (this.options$.accessToken) { security$ = { accessToken: this.options$.accessToken }; } else { security$ = {}; } const context = { operationID: "checkForUpdates", oAuth2Scopes: [], securitySource: this.options$.accessToken, }; const securitySettings$ = this.resolveGlobalSecurity(security$); const doOptions = { context, errorCodes: ["400", "401", "4XX", "5XX"] }; const request$ = this.createRequest$( context, { security: securitySettings$, method: "PUT", path: path$, headers: headers$, query: query$, body: body$, }, options ); const response = await this.do$(request$, doOptions); const responseFields$ = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; if (this.matchStatusCode(response, 200)) { // fallthrough } else if (this.matchResponse(response, 401, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return errors.CheckForUpdatesResponseBody$.inboundSchema.parse({ ...responseFields$, ...val$, }); }, "Response validation failed" ); throw result; } else { const responseBody = await response.text(); throw new errors.SDKError( "Unexpected API response status or content-type", response, responseBody ); } return schemas$.parse( undefined, () => operations.CheckForUpdatesResponse$.inboundSchema.parse(responseFields$), "Response validation failed" ); } /** * Apply Updates * * @remarks * Note that these two parameters are effectively mutually exclusive. The `tonight` parameter takes precedence and `skip` will be ignored if `tonight` is also passed * */ async applyUpdates( tonight?: operations.Tonight | undefined, skip?: operations.Skip | undefined, options?: RequestOptions ): Promise { const input$: operations.ApplyUpdatesRequest = { tonight: tonight, skip: skip, }; const headers$ = new Headers(); headers$.set("user-agent", SDK_METADATA.userAgent); headers$.set("Accept", "application/json"); const payload$ = schemas$.parse( input$, (value$) => operations.ApplyUpdatesRequest$.outboundSchema.parse(value$), "Input validation failed" ); const body$ = null; const path$ = this.templateURLComponent("/updater/apply")(); const query$ = [ enc$.encodeForm("skip", payload$.skip, { explode: true, charEncoding: "percent" }), enc$.encodeForm("tonight", payload$.tonight, { explode: true, charEncoding: "percent", }), ] .filter(Boolean) .join("&"); let security$; if (typeof this.options$.accessToken === "function") { security$ = { accessToken: await this.options$.accessToken() }; } else if (this.options$.accessToken) { security$ = { accessToken: this.options$.accessToken }; } else { security$ = {}; } const context = { operationID: "applyUpdates", oAuth2Scopes: [], securitySource: this.options$.accessToken, }; const securitySettings$ = this.resolveGlobalSecurity(security$); const doOptions = { context, errorCodes: ["400", "401", "4XX", "500", "5XX"] }; const request$ = this.createRequest$( context, { security: securitySettings$, method: "PUT", path: path$, headers: headers$, query: query$, body: body$, }, options ); const response = await this.do$(request$, doOptions); const responseFields$ = { ContentType: response.headers.get("content-type") ?? "application/octet-stream", StatusCode: response.status, RawResponse: response, Headers: {}, }; if (this.matchStatusCode(response, 200)) { // fallthrough } else if (this.matchResponse(response, 401, "application/json")) { const responseBody = await response.json(); const result = schemas$.parse( responseBody, (val$) => { return errors.ApplyUpdatesResponseBody$.inboundSchema.parse({ ...responseFields$, ...val$, }); }, "Response validation failed" ); throw result; } else { const responseBody = await response.text(); throw new errors.SDKError( "Unexpected API response status or content-type", response, responseBody ); } return schemas$.parse( undefined, () => operations.ApplyUpdatesResponse$.inboundSchema.parse(responseFields$), "Response validation failed" ); } }