Files
dub-node/src/sdk/links.ts

1931 lines
67 KiB
TypeScript

/*
* 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 components from "../models/components";
import * as errors from "../models/errors";
import * as operations from "../models/operations";
import * as z from "zod";
export class Links 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 links
*
* @remarks
* Retrieve a list of links for the authenticated workspace. The list will be paginated and the provided query parameters allow filtering the returned links.
*/
async list(
request?: operations.GetLinksRequest | undefined,
options?: RequestOptions
): Promise<Array<components.LinkSchema>> {
const input$ = typeof request === "undefined" ? {} : request;
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
const payload$ = schemas$.parse(
input$,
(value$) => operations.GetLinksRequest$.outboundSchema.parse(value$),
"Input validation failed"
);
const body$ = null;
const path$ = this.templateURLComponent("/links")();
const query$ = [
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("page", payload$.page, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("search", payload$.search, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("showArchived", payload$.showArchived, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("sort", payload$.sort, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("tagIds", payload$.tagIds, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("tagNames", payload$.tagNames, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("userId", payload$.userId, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("withTags", payload$.withTags, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "getLinks",
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$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return z.array(components.LinkSchema$.inboundSchema).parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
/**
* Create a new link
*
* @remarks
* Create a new link for the authenticated workspace.
*/
async create(
request?: operations.CreateLinkRequestBody | undefined,
options?: RequestOptions
): Promise<components.LinkSchema> {
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.CreateLinkRequestBody$.outboundSchema.optional().parse(value$),
"Input validation failed"
);
const body$ =
payload$ === undefined ? null : enc$.encodeJSON("body", payload$, { explode: true });
const path$ = this.templateURLComponent("/links")();
const query$ = [
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "createLink",
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$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return components.LinkSchema$.inboundSchema.parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
/**
* Retrieve the number of links
*
* @remarks
* Retrieve the number of links for the authenticated workspace. The provided query parameters allow filtering the returned links.
*/
async count(
request?: operations.GetLinksCountRequest | undefined,
options?: RequestOptions
): Promise<number> {
const input$ = typeof request === "undefined" ? {} : request;
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
const payload$ = schemas$.parse(
input$,
(value$) => operations.GetLinksCountRequest$.outboundSchema.parse(value$),
"Input validation failed"
);
const body$ = null;
const path$ = this.templateURLComponent("/links/count")();
const query$ = [
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("groupBy", payload$.groupBy, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("search", payload$.search, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("showArchived", payload$.showArchived, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("tagIds", payload$.tagIds, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("tagNames", payload$.tagNames, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("userId", payload$.userId, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("withTags", payload$.withTags, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "getLinksCount",
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$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return z.number().parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
/**
* Retrieve a link
*
* @remarks
* Retrieve the info for a link.
*/
async get(
request?: operations.GetLinkInfoRequest | undefined,
options?: RequestOptions
): Promise<components.LinkSchema> {
const input$ = typeof request === "undefined" ? {} : request;
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
const payload$ = schemas$.parse(
input$,
(value$) => operations.GetLinkInfoRequest$.outboundSchema.parse(value$),
"Input validation failed"
);
const body$ = null;
const path$ = this.templateURLComponent("/links/info")();
const query$ = [
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("externalId", payload$.externalId, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "getLinkInfo",
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$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return components.LinkSchema$.inboundSchema.parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
/**
* Delete a link
*
* @remarks
* Delete a link for the authenticated workspace.
*/
async delete(
linkId: string,
options?: RequestOptions
): Promise<operations.DeleteLinkResponseBody> {
const input$: operations.DeleteLinkRequest = {
linkId: linkId,
};
const headers$ = new Headers();
headers$.set("user-agent", SDK_METADATA.userAgent);
headers$.set("Accept", "application/json");
const payload$ = schemas$.parse(
input$,
(value$) => operations.DeleteLinkRequest$.outboundSchema.parse(value$),
"Input validation failed"
);
const body$ = null;
const pathParams$ = {
linkId: enc$.encodeSimple("linkId", payload$.linkId, {
explode: false,
charEncoding: "percent",
}),
};
const path$ = this.templateURLComponent("/links/{linkId}")(pathParams$);
const query$ = [
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "deleteLink",
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: "DELETE",
path: path$,
headers: headers$,
query: query$,
body: body$,
},
options
);
const response = await this.do$(request$, doOptions);
const responseFields$ = {
HttpMeta: {
Response: response,
Request: request$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return operations.DeleteLinkResponseBody$.inboundSchema.parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
/**
* Update a link
*
* @remarks
* Update a link for the authenticated workspace. If there's no change, returns as is.
*/
async update(
linkId: string,
requestBody?: operations.UpdateLinkRequestBody | undefined,
options?: RequestOptions
): Promise<components.LinkSchema> {
const input$: operations.UpdateLinkRequest = {
linkId: linkId,
requestBody: requestBody,
};
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.UpdateLinkRequest$.outboundSchema.parse(value$),
"Input validation failed"
);
const body$ = enc$.encodeJSON("body", payload$.RequestBody, { explode: true });
const pathParams$ = {
linkId: enc$.encodeSimple("linkId", payload$.linkId, {
explode: false,
charEncoding: "percent",
}),
};
const path$ = this.templateURLComponent("/links/{linkId}")(pathParams$);
const query$ = [
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "updateLink",
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: "PATCH",
path: path$,
headers: headers$,
query: query$,
body: body$,
},
options
);
const response = await this.do$(request$, doOptions);
const responseFields$ = {
HttpMeta: {
Response: response,
Request: request$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return components.LinkSchema$.inboundSchema.parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
/**
* Bulk create links
*
* @remarks
* Bulk create up to 100 links for the authenticated workspace.
*/
async createMany(
request?: Array<operations.RequestBody> | undefined,
options?: RequestOptions
): Promise<Array<components.LinkSchema>> {
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$) => z.array(operations.RequestBody$.outboundSchema).optional().parse(value$),
"Input validation failed"
);
const body$ =
payload$ === undefined ? null : enc$.encodeJSON("body", payload$, { explode: true });
const path$ = this.templateURLComponent("/links/bulk")();
const query$ = [
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "bulkCreateLinks",
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$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return z.array(components.LinkSchema$.inboundSchema).parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
/**
* Upsert a link
*
* @remarks
* Upsert a link for the authenticated workspace by its URL. If a link with the same URL already exists, returns as is if there's no change, or update it. Otherwise, a new link will be created.
*/
async upsert(
request?: operations.UpsertLinkRequestBody | undefined,
options?: RequestOptions
): Promise<components.LinkSchema> {
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.UpsertLinkRequestBody$.outboundSchema.optional().parse(value$),
"Input validation failed"
);
const body$ =
payload$ === undefined ? null : enc$.encodeJSON("body", payload$, { explode: true });
const path$ = this.templateURLComponent("/links/upsert")();
const query$ = [
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
explode: true,
charEncoding: "percent",
}),
enc$.encodeForm("workspaceId", this.options$.workspaceId, {
explode: true,
charEncoding: "percent",
}),
]
.filter(Boolean)
.join("&");
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: "upsertLink",
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: "PUT",
path: path$,
headers: headers$,
query: query$,
body: body$,
},
options
);
const response = await this.do$(request$, doOptions);
const responseFields$ = {
HttpMeta: {
Response: response,
Request: request$,
},
};
if (this.matchResponse(response, 200, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return components.LinkSchema$.inboundSchema.parse(val$);
},
"Response validation failed"
);
return result;
} else if (this.matchResponse(response, 400, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.BadRequest$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 401, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Unauthorized$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 403, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Forbidden$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 404, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.NotFound$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 409, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.Conflict$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 410, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InviteExpired$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 422, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.UnprocessableEntity$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 429, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.RateLimitExceeded$.inboundSchema.parse({
...responseFields$,
...val$,
});
},
"Response validation failed"
);
throw result;
} else if (this.matchResponse(response, 500, "application/json")) {
const responseBody = await response.json();
const result = schemas$.parse(
responseBody,
(val$) => {
return errors.InternalServerError$.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
);
}
}
}