diff --git a/app/api/__generated__/Api.ts b/app/api/__generated__/Api.ts index 72bbed88f..4e33fc69b 100644 --- a/app/api/__generated__/Api.ts +++ b/app/api/__generated__/Api.ts @@ -8,9 +8,18 @@ /* eslint-disable */ -import { HttpClient, toQueryString, type FetchParams } from './http-client' +import { + dateReplacer, + handleResponse, + mergeParams, + toQueryString, + type ApiResult, + type FetchParams, + type FullParams, +} from './http-client' +import { snakeify } from './util' -export type { ApiConfig, ApiResult, ErrorBody, ErrorResult } from './http-client' +export type { ApiResult, ErrorBody, ErrorResult } from './http-client' /** * An IPv4 subnet @@ -6625,7 +6634,47 @@ export interface WebhookSecretsDeletePathParams { } type EmptyObj = Record -export class Api extends HttpClient { +export interface ApiConfig { + /** + * No host means requests will be sent to the current host. This is used in + * the web console. + */ + host?: string + token?: string + baseParams?: FetchParams +} + +export class Api { + host: string + token?: string + baseParams: FetchParams + + constructor({ host = '', baseParams = {}, token }: ApiConfig = {}) { + this.host = host + this.token = token + + const headers = new Headers({ 'Content-Type': 'application/json' }) + if (token) { + headers.append('Authorization', `Bearer ${token}`) + } + this.baseParams = mergeParams({ headers }, baseParams) + } + + public async request({ + body, + path, + query, + host, + ...fetchParams + }: FullParams): Promise> { + const url = (host || this.host) + path + toQueryString(query) + const init = { + ...mergeParams(this.baseParams, fetchParams), + body: JSON.stringify(snakeify(body), dateReplacer), + } + return handleResponse(await fetch(url, init)) + } + methods = { /** * Start an OAuth 2.0 Device Authorization Grant diff --git a/app/api/__generated__/http-client.ts b/app/api/__generated__/http-client.ts index 9bdcd97eb..619f8928f 100644 --- a/app/api/__generated__/http-client.ts +++ b/app/api/__generated__/http-client.ts @@ -6,7 +6,7 @@ * Copyright Oxide Computer Company */ -import { camelToSnake, isNotNull, processResponseBody, snakeify } from './util' +import { camelToSnake, isNotNull, processResponseBody } from './util' /** Success responses from the API */ export type ApiSuccess = { @@ -47,7 +47,7 @@ export type ApiResult = ApiSuccess | ErrorResult * body and query params. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -function replacer(_key: string, value: any) { +export function dateReplacer(_key: string, value: any) { if (value instanceof Date) { return value.toISOString() } @@ -56,7 +56,7 @@ function replacer(_key: string, value: any) { function encodeQueryParam(key: string, value: unknown) { return `${encodeURIComponent(camelToSnake(key))}=${encodeURIComponent( - replacer(key, value) + dateReplacer(key, value) )}` } @@ -114,48 +114,6 @@ export interface FullParams extends FetchParams { method?: string } -export interface ApiConfig { - /** - * No host means requests will be sent to the current host. This is used in - * the web console. - */ - host?: string - token?: string - baseParams?: FetchParams -} - -export class HttpClient { - host: string - token?: string - baseParams: FetchParams - - constructor({ host = '', baseParams = {}, token }: ApiConfig = {}) { - this.host = host - this.token = token - - const headers = new Headers({ 'Content-Type': 'application/json' }) - if (token) { - headers.append('Authorization', `Bearer ${token}`) - } - this.baseParams = mergeParams({ headers }, baseParams) - } - - public async request({ - body, - path, - query, - host, - ...fetchParams - }: FullParams): Promise> { - const url = (host || this.host) + path + toQueryString(query) - const init = { - ...mergeParams(this.baseParams, fetchParams), - body: JSON.stringify(snakeify(body), replacer), - } - return handleResponse(await fetch(url, init)) - } -} - export function mergeParams(a: FetchParams, b: FetchParams): FetchParams { // calling `new Headers()` normalizes `HeadersInit`, which could be a Headers // object, a plain object, or an array of tuples diff --git a/package-lock.json b/package-lock.json index 074b60ad0..1230c7569 100644 --- a/package-lock.json +++ b/package-lock.json @@ -61,7 +61,7 @@ "@eslint/js": "^9.38.0", "@ianvs/prettier-plugin-sort-imports": "^4.7.0", "@mswjs/http-middleware": "^0.10.3", - "@oxide/openapi-gen-ts": "~0.9.0", + "@oxide/openapi-gen-ts": "~0.10.0", "@playwright/test": "^1.56.1", "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^6.6.3", @@ -1831,9 +1831,9 @@ } }, "node_modules/@oxide/openapi-gen-ts": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/@oxide/openapi-gen-ts/-/openapi-gen-ts-0.9.0.tgz", - "integrity": "sha512-Yw6L8knvhAOonz3KS4RMHciWe7FEp6ry1pWoI0SRGRh6snAetwbI6dj9ZwCx2J8nM2lclSS3r99toF5C9Ux5Gw==", + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@oxide/openapi-gen-ts/-/openapi-gen-ts-0.10.0.tgz", + "integrity": "sha512-pi/sxdrJV7Waa7iBrMe/41QOdMAM4m3IZIsIR4LEkLQXFTmcOrJ8oetVZ+VzTBBs2UfzX/XZN7lGoGpv3spX+g==", "dev": true, "license": "MPL-2.0", "dependencies": { @@ -1846,7 +1846,7 @@ "openapi-gen-ts": "dist/index.cjs" }, "engines": { - "node": ">=18" + "node": ">=24" } }, "node_modules/@oxide/openapi-gen-ts/node_modules/prettier": { @@ -11158,9 +11158,9 @@ "license": "MIT" }, "node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.1.tgz", + "integrity": "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 5fefffaba..9d476d644 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "@eslint/js": "^9.38.0", "@ianvs/prettier-plugin-sort-imports": "^4.7.0", "@mswjs/http-middleware": "^0.10.3", - "@oxide/openapi-gen-ts": "~0.9.0", + "@oxide/openapi-gen-ts": "~0.10.0", "@playwright/test": "^1.56.1", "@testing-library/dom": "^10.4.0", "@testing-library/jest-dom": "^6.6.3",