mirror of
https://github.com/LukeHagar/dub-node.git
synced 2025-12-08 04:19:43 +00:00
2644 lines
98 KiB
TypeScript
2644 lines
98 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 errors from "../models/errors";
|
|
import * as operations from "../models/operations";
|
|
import * as z from "zod";
|
|
|
|
export class Analytics 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 clicks analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the number of clicks for a link, a domain, or the authenticated workspace.
|
|
*/
|
|
async clicks(
|
|
request?: operations.GetClicksAnalyticsRequest | 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.GetClicksAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/clicks")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getClicksAnalytics",
|
|
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 timeseries analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the number of clicks for a link, a domain, or the authenticated workspace over a period of time.
|
|
*/
|
|
async timeseries(
|
|
request?: operations.GetTimeseriesAnalyticsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.ResponseBody>> {
|
|
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.GetTimeseriesAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/timeseries")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getTimeseriesAnalytics",
|
|
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(operations.ResponseBody$.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 country analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the top countries by number of clicks for a link, a domain, or the authenticated workspace.
|
|
*/
|
|
async countries(
|
|
request?: operations.GetCountryAnalyticsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetCountryAnalyticsResponseBody>> {
|
|
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.GetCountryAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/country")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getCountryAnalytics",
|
|
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(operations.GetCountryAnalyticsResponseBody$.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 city analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the top countries by number of clicks for a link, a domain, or the authenticated workspace.
|
|
*/
|
|
async cities(
|
|
request?: operations.GetCityAnalyticsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetCityAnalyticsResponseBody>> {
|
|
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.GetCityAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/city")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getCityAnalytics",
|
|
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(operations.GetCityAnalyticsResponseBody$.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 device analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the top devices by number of clicks for a link, a domain, or the authenticated workspace.
|
|
*/
|
|
async devices(
|
|
request?: operations.GetDeviceAnalyticsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetDeviceAnalyticsResponseBody>> {
|
|
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.GetDeviceAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/device")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getDeviceAnalytics",
|
|
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(operations.GetDeviceAnalyticsResponseBody$.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 browser analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the top browsers by number of clicks for a link, a domain, or the authenticated workspace.
|
|
*/
|
|
async browsers(
|
|
request?: operations.GetBrowserAnalyticsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetBrowserAnalyticsResponseBody>> {
|
|
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.GetBrowserAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/browser")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getBrowserAnalytics",
|
|
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(operations.GetBrowserAnalyticsResponseBody$.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 OS analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the top OS by number of clicks for a link, a domain, or the authenticated workspace.
|
|
*/
|
|
async os(
|
|
request?: operations.GetOSAnalyticsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetOSAnalyticsResponseBody>> {
|
|
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.GetOSAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/os")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getOSAnalytics",
|
|
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(operations.GetOSAnalyticsResponseBody$.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 referer analytics
|
|
*
|
|
* @remarks
|
|
* Retrieve the top referers by number of clicks for a link, a domain, or the authenticated workspace.
|
|
*/
|
|
async referers(
|
|
request?: operations.GetRefererAnalyticsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetRefererAnalyticsResponseBody>> {
|
|
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.GetRefererAnalyticsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/referer")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getRefererAnalytics",
|
|
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(operations.GetRefererAnalyticsResponseBody$.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 top links
|
|
*
|
|
* @remarks
|
|
* Retrieve the top links by number of clicks for a domain or the authenticated workspace.
|
|
*/
|
|
async topLinks(
|
|
request?: operations.GetTopLinksRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetTopLinksResponseBody>> {
|
|
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.GetTopLinksRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/top_links")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getTopLinks",
|
|
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(operations.GetTopLinksResponseBody$.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 top URLs
|
|
*
|
|
* @remarks
|
|
* Retrieve the top URLs by number of clicks for a given short link.
|
|
*/
|
|
async topUrls(
|
|
request?: operations.GetTopURLsRequest | undefined,
|
|
options?: RequestOptions
|
|
): Promise<Array<operations.GetTopURLsResponseBody>> {
|
|
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.GetTopURLsRequest$.outboundSchema.parse(value$),
|
|
"Input validation failed"
|
|
);
|
|
const body$ = null;
|
|
|
|
const path$ = this.templateURLComponent("/analytics/top_urls")();
|
|
|
|
const query$ = [
|
|
enc$.encodeForm("browser", payload$.browser, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("city", payload$.city, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("country", payload$.country, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("device", payload$.device, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("domain", payload$.domain, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("end", payload$.end, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("externalId", payload$.externalId, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("interval", payload$.interval, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("key", payload$.key, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("linkId", payload$.linkId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("os", payload$.os, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("projectSlug", this.options$.projectSlug, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("qr", payload$.qr, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("referer", payload$.referer, {
|
|
explode: true,
|
|
charEncoding: "percent",
|
|
}),
|
|
enc$.encodeForm("root", payload$.root, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("start", payload$.start, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("tagId", payload$.tagId, { explode: true, charEncoding: "percent" }),
|
|
enc$.encodeForm("url", payload$.url, { 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: "getTopURLs",
|
|
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(operations.GetTopURLsResponseBody$.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
|
|
);
|
|
}
|
|
}
|
|
}
|