mirror of
https://github.com/LukeHagar/dub-node.git
synced 2025-12-06 04:19:37 +00:00
319 lines
10 KiB
TypeScript
319 lines
10 KiB
TypeScript
/*
|
|
* Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
*/
|
|
|
|
import { SDKHooks } from "../hooks/hooks.js";
|
|
import { SDK_METADATA, SDKOptions, serverURLFromOptions } from "../lib/config.js";
|
|
import { encodeJSON as encodeJSON$, encodeSimple as encodeSimple$ } from "../lib/encodings.js";
|
|
import { HTTPClient } from "../lib/http.js";
|
|
import * as schemas$ from "../lib/schemas.js";
|
|
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
|
|
import * as components from "../models/components/index.js";
|
|
import * as errors from "../models/errors/index.js";
|
|
import * as operations from "../models/operations/index.js";
|
|
import * as z from "zod";
|
|
|
|
export class Workspaces 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$;
|
|
}
|
|
|
|
/**
|
|
* Retrieve a list of workspaces
|
|
*
|
|
* @remarks
|
|
* Retrieve a list of workspaces for the authenticated user.
|
|
*/
|
|
async list(options?: RequestOptions): Promise<Array<components.WorkspaceSchema>> {
|
|
const headers$ = new Headers();
|
|
headers$.set("user-agent", SDK_METADATA.userAgent);
|
|
headers$.set("Accept", "application/json");
|
|
|
|
const path$ = this.templateURLComponent("/workspaces")();
|
|
|
|
const query$ = "";
|
|
|
|
let security$;
|
|
if (typeof this.options$.token === "function") {
|
|
security$ = { token: await this.options$.token() };
|
|
} else if (this.options$.token) {
|
|
security$ = { token: this.options$.token };
|
|
} else {
|
|
security$ = {};
|
|
}
|
|
const context = {
|
|
operationID: "getWorkspaces",
|
|
oAuth2Scopes: [],
|
|
securitySource: this.options$.token,
|
|
};
|
|
const securitySettings$ = this.resolveGlobalSecurity(security$);
|
|
|
|
const doOptions = {
|
|
context,
|
|
errorCodes: [
|
|
"400",
|
|
"401",
|
|
"403",
|
|
"404",
|
|
"409",
|
|
"410",
|
|
"422",
|
|
"429",
|
|
"4XX",
|
|
"500",
|
|
"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$ = {
|
|
HttpMeta: { Response: response, Request: request$ },
|
|
};
|
|
|
|
const [result$] = await this.matcher<Array<components.WorkspaceSchema>>()
|
|
.json(200, z.array(components.WorkspaceSchema$.inboundSchema))
|
|
.json(400, errors.BadRequest$, { err: true })
|
|
.json(401, errors.Unauthorized$, { err: true })
|
|
.json(403, errors.Forbidden$, { err: true })
|
|
.json(404, errors.NotFound$, { err: true })
|
|
.json(409, errors.Conflict$, { err: true })
|
|
.json(410, errors.InviteExpired$, { err: true })
|
|
.json(422, errors.UnprocessableEntity$, { err: true })
|
|
.json(429, errors.RateLimitExceeded$, { err: true })
|
|
.json(500, errors.InternalServerError$, { err: true })
|
|
.fail(["4XX", "5XX"])
|
|
.match(response, { extraFields: responseFields$ });
|
|
|
|
return result$;
|
|
}
|
|
|
|
/**
|
|
* Create a workspace
|
|
*
|
|
* @remarks
|
|
* Create a new workspace for the authenticated user.
|
|
*/
|
|
async create(
|
|
request?: operations.CreateWorkspaceRequestBody | undefined,
|
|
options?: RequestOptions
|
|
): Promise<components.WorkspaceSchema> {
|
|
const input$ = request;
|
|
const headers$ = new Headers();
|
|
headers$.set("user-agent", SDK_METADATA.userAgent);
|
|
headers$.set("Content-Type", "application/json");
|
|
headers$.set("Accept", "application/json");
|
|
|
|
const payload$ = schemas$.parse(
|
|
input$,
|
|
(value$) =>
|
|
operations.CreateWorkspaceRequestBody$.outboundSchema.optional().parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ =
|
|
payload$ === undefined ? null : encodeJSON$("body", payload$, { explode: true });
|
|
|
|
const path$ = this.templateURLComponent("/workspaces")();
|
|
|
|
const query$ = "";
|
|
|
|
let security$;
|
|
if (typeof this.options$.token === "function") {
|
|
security$ = { token: await this.options$.token() };
|
|
} else if (this.options$.token) {
|
|
security$ = { token: this.options$.token };
|
|
} else {
|
|
security$ = {};
|
|
}
|
|
const context = {
|
|
operationID: "createWorkspace",
|
|
oAuth2Scopes: [],
|
|
securitySource: this.options$.token,
|
|
};
|
|
const securitySettings$ = this.resolveGlobalSecurity(security$);
|
|
|
|
const doOptions = {
|
|
context,
|
|
errorCodes: [
|
|
"400",
|
|
"401",
|
|
"403",
|
|
"404",
|
|
"409",
|
|
"410",
|
|
"422",
|
|
"429",
|
|
"4XX",
|
|
"500",
|
|
"5XX",
|
|
],
|
|
};
|
|
const request$ = this.createRequest$(
|
|
context,
|
|
{
|
|
security: securitySettings$,
|
|
method: "POST",
|
|
path: path$,
|
|
headers: headers$,
|
|
query: query$,
|
|
body: body$,
|
|
},
|
|
options
|
|
);
|
|
|
|
const response = await this.do$(request$, doOptions);
|
|
|
|
const responseFields$ = {
|
|
HttpMeta: { Response: response, Request: request$ },
|
|
};
|
|
|
|
const [result$] = await this.matcher<components.WorkspaceSchema>()
|
|
.json(200, components.WorkspaceSchema$)
|
|
.json(400, errors.BadRequest$, { err: true })
|
|
.json(401, errors.Unauthorized$, { err: true })
|
|
.json(403, errors.Forbidden$, { err: true })
|
|
.json(404, errors.NotFound$, { err: true })
|
|
.json(409, errors.Conflict$, { err: true })
|
|
.json(410, errors.InviteExpired$, { err: true })
|
|
.json(422, errors.UnprocessableEntity$, { err: true })
|
|
.json(429, errors.RateLimitExceeded$, { err: true })
|
|
.json(500, errors.InternalServerError$, { err: true })
|
|
.fail(["4XX", "5XX"])
|
|
.match(response, { extraFields: responseFields$ });
|
|
|
|
return result$;
|
|
}
|
|
|
|
/**
|
|
* Retrieve a workspace
|
|
*
|
|
* @remarks
|
|
* Retrieve a workspace for the authenticated user.
|
|
*/
|
|
async get(
|
|
request: operations.GetWorkspaceRequest,
|
|
options?: RequestOptions
|
|
): Promise<components.WorkspaceSchema> {
|
|
const input$ = request;
|
|
const headers$ = new Headers();
|
|
headers$.set("user-agent", SDK_METADATA.userAgent);
|
|
headers$.set("Accept", "application/json");
|
|
|
|
const payload$ = schemas$.parse(
|
|
input$,
|
|
(value$) => operations.GetWorkspaceRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const pathParams$ = {
|
|
idOrSlug: encodeSimple$("idOrSlug", payload$.idOrSlug, {
|
|
explode: false,
|
|
charEncoding: "percent",
|
|
}),
|
|
};
|
|
const path$ = this.templateURLComponent("/workspaces/{idOrSlug}")(pathParams$);
|
|
|
|
const query$ = "";
|
|
|
|
let security$;
|
|
if (typeof this.options$.token === "function") {
|
|
security$ = { token: await this.options$.token() };
|
|
} else if (this.options$.token) {
|
|
security$ = { token: this.options$.token };
|
|
} else {
|
|
security$ = {};
|
|
}
|
|
const context = {
|
|
operationID: "getWorkspace",
|
|
oAuth2Scopes: [],
|
|
securitySource: this.options$.token,
|
|
};
|
|
const securitySettings$ = this.resolveGlobalSecurity(security$);
|
|
|
|
const doOptions = {
|
|
context,
|
|
errorCodes: [
|
|
"400",
|
|
"401",
|
|
"403",
|
|
"404",
|
|
"409",
|
|
"410",
|
|
"422",
|
|
"429",
|
|
"4XX",
|
|
"500",
|
|
"5XX",
|
|
],
|
|
};
|
|
const request$ = this.createRequest$(
|
|
context,
|
|
{
|
|
security: securitySettings$,
|
|
method: "GET",
|
|
path: path$,
|
|
headers: headers$,
|
|
query: query$,
|
|
body: body$,
|
|
},
|
|
options
|
|
);
|
|
|
|
const response = await this.do$(request$, doOptions);
|
|
|
|
const responseFields$ = {
|
|
HttpMeta: { Response: response, Request: request$ },
|
|
};
|
|
|
|
const [result$] = await this.matcher<components.WorkspaceSchema>()
|
|
.json(200, components.WorkspaceSchema$)
|
|
.json(400, errors.BadRequest$, { err: true })
|
|
.json(401, errors.Unauthorized$, { err: true })
|
|
.json(403, errors.Forbidden$, { err: true })
|
|
.json(404, errors.NotFound$, { err: true })
|
|
.json(409, errors.Conflict$, { err: true })
|
|
.json(410, errors.InviteExpired$, { err: true })
|
|
.json(422, errors.UnprocessableEntity$, { err: true })
|
|
.json(429, errors.RateLimitExceeded$, { err: true })
|
|
.json(500, errors.InternalServerError$, { err: true })
|
|
.fail(["4XX", "5XX"])
|
|
.match(response, { extraFields: responseFields$ });
|
|
|
|
return result$;
|
|
}
|
|
}
|