Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

revolt-api

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

revolt-api - npm Package Compare versions

Comparing version 0.5.3-alpha.8-patch.0 to 0.5.3-rc.1

.github/workflows/triage_issue.yml

134

dist/index.js

@@ -1,41 +0,103 @@

import { writeFile } from 'fs/promises';
import info from './openapi/info.js';
import definitions from './openapi/definitions.js';
import paths, { group, tags } from './openapi/paths.js';
import './routes/index.js';
async function generate() {
return {
['__comment']: "THIS FILE WAS AUTO-GENERATED USING https://github.com/revoltchat/api. DO NOT EDIT.",
openapi: "3.0.0",
info: await info(),
tags,
// Redoc tag groups
['x-tagGroups']: group(),
paths: await paths(),
definitions: await definitions(),
servers: [
{
"url": "https://api.revolt.chat",
"description": "Production instance of the Revolt API"
export * from './types';
import Axios from 'axios';
import { pathResolve, queryParams } from './params';
/**
* Get the specific path name of any given path.
* @param anyPath Any path
* @returns Specific path
*/
export function getPathName(anyPath) {
const segments = anyPath.split('/');
const list = pathResolve[(segments.length - 1).toString()] ?? [];
for (const entry of list) {
let i = 1;
let copy = [...segments];
for (i; i < segments.length; i++) {
if (Array.isArray(entry[i - 1])) {
copy[i] = entry[i - 1];
continue;
}
],
components: {
securitySchemes: {
'Session Token': {
type: "apiKey",
in: "header",
name: "x-session-token",
description: "Session is created by calling `/session/login`.\n"
},
'Bot Token': {
type: "apiKey",
in: "header",
name: "x-bot-token",
description: "Generate a bot token in-app by going to [\"My Bots\"](https://app.revolt.chat/settings/bots) in user settings.\n"
else if (entry[i - 1] !== segments[i])
break;
}
if (i === segments.length)
return copy.join('/');
}
}
/**
* Revolt API Client
*/
export class RevoltAPI {
constructor({ baseURL, authentication } = {}) {
this.baseURL = baseURL ?? 'https://api.revolt.chat';
this.authentication = authentication;
}
/**
* Generate config to pass through to API.
*/
get config() {
return {
baseURL: this.baseURL,
headers: typeof this.authentication === 'string'
? { 'X-Bot-Token': this.authentication }
: typeof this.authentication === 'object'
? { 'X-Session-Token': this.authentication.token }
: undefined
};
}
/**
* Send any arbitrary request.
* @param method HTTP Method
* @param path Path
* @param params Body or Query Parameters
* @param config Axios configuration
* @returns Typed Response Data
*/
req(method, path, params, config) {
let query, body;
let named = getPathName(path);
// If we are aware of this route, then match the parameters given.
if (named && typeof params === 'object') {
const route = queryParams[named];
const allowed_query = route[method];
// Map each parameter to the correct object.
for (const parameter of Object.keys(params)) {
if (allowed_query.includes(parameter)) {
query = {
...(query ?? {}),
[parameter]: params[parameter]
};
}
else {
body = {
...(body ?? {}),
[parameter]: params[parameter]
};
}
}
}
};
return Axios(path, {
...this.config,
...config,
method,
params: query,
data: body
})
.then(res => res.data);
}
get(path, params, config) {
return this.req('get', path, params, config);
}
patch(path, params, config) {
return this.req('patch', path, params, config);
}
put(path, params, config) {
return this.req('put', path, params, config);
}
delete(path, config) {
return this.req('delete', path, undefined, config);
}
post(path, params, config) {
return this.req('post', path, params, config);
}
}
generate()
.then(v => writeFile('OpenAPI.json', JSON.stringify(v, undefined, 2)));
{
"name": "revolt-api",
"version": "0.5.3-alpha.8-patch.0",
"version": "0.5.3-rc.1",
"description": "Revolt API typings",

@@ -12,21 +12,16 @@ "main": "dist/index.js",

"scripts": {
"build:generator": "tsc",
"start:generator": "node .",
"watch:generator": "tsc-watch",
"redoc": "docker run --network host -e SPEC_URL=http://localhost:5500/OpenAPI.json redocly/redoc",
"preview": "sirv . --port 5500 --host",
"dev": "concurrently \"yarn redoc\" \"nodemon --exec \\\"yarn build:generator && yarn start:generator && yarn preview\\\"\"",
"open": "concurrently \"yarn redoc\" \"yarn preview\" \"open-cli http://localhost:80\""
"build": "tsc",
"watch": "tsc-watch --onSuccess \"node --experimental-specifier-resolution=node dist\"",
"routes": "node scripts/generate_routes.js",
"exports": "node scripts/generate_exports.js",
"convert": "openapi-typescript OpenAPI.json --output src/schema.ts && node scripts/generate_routes.js && node scripts/generate_exports.js"
},
"devDependencies": {
"@openapi-contrib/json-schema-to-openapi-schema": "^2.0.0",
"concurrently": "^6.2.0",
"nodemon": "^2.0.12",
"open-cli": "^7.0.0",
"openapi-types": "^9.1.0",
"sirv-cli": "^1.0.12",
"tsc-watch": "^4.4.0",
"typescript": "^4.3.5",
"typescript-json-schema": "^0.50.1"
"typescript": "^4.3.5"
},
"dependencies": {
"axios": "^0.26.1",
"openapi-typescript": "^5.2.0"
}
}

@@ -15,29 +15,4 @@ # Revolt API

### Commit Style
### Tip (for development)
If publishing a new version of the spec, the first line should always be the API version.
```
0.5.0-alpha.0
Commit description.
Line 2.
```
If you are creating new changes for a PR, don't include any version!
For any subsequent lines, prepend the relevant text:
Prefix | Description
--------|-------------
`Structure` | Added a new data structure to the API.
`Route` | Added a new route to the API.
`Change` | Changed an existing route or data structure.
`Fix` | Fixes to structures / routes.
`Deprecation` | Use when deprecating a structure or route.
`Library` | Changes to this repo unrelated to the API.
Add new prefixes to this list as necessary.
### Tip
For faster compile times when working on API routes, comment out the categories you don't care about.

@@ -44,0 +19,0 @@

@@ -1,52 +0,224 @@

import { writeFile } from 'fs/promises';
import type { OpenAPIV3 } from "openapi-types";
import type * as TJS from "typescript-json-schema";
export * from './types';
type Document = OpenAPIV3.Document & { definitions?: TJS.Definition };
import type { Session } from './types';
import type { APIRoutes } from './routes';
import Axios, { AxiosRequestConfig } from 'axios';
import info from './openapi/info.js';
import definitions from './openapi/definitions.js';
import paths, { group, tags } from './openapi/paths.js';
import { pathResolve, queryParams } from './params';
import './routes/index.js';
/**
* Get the specific path name of any given path.
* @param anyPath Any path
* @returns Specific path
*/
export function getPathName(anyPath: string) {
const segments = anyPath.split('/');
async function generate(): Promise<Document> {
return {
['__comment' as any]: "THIS FILE WAS AUTO-GENERATED USING https://github.com/revoltchat/api. DO NOT EDIT.",
openapi: "3.0.0",
info: await info(),
tags,
// Redoc tag groups
['x-tagGroups' as any]: group(),
paths: await paths(),
definitions: await definitions(),
servers: [
{
"url": "https://api.revolt.chat",
"description": "Production instance of the Revolt API"
const list = (pathResolve as unknown as Record<string, (string | [string])[]>)[(segments.length - 1).toString()] ?? [];
for (const entry of list) {
let i = 1;
let copy = [...segments];
for (i;i<segments.length;i++) {
if (Array.isArray(entry[i - 1])) {
copy[i] = entry[i - 1];
continue;
}
],
components: {
securitySchemes: {
'Session Token': {
type: "apiKey",
in: "header",
name: "x-session-token",
description: "Session is created by calling `/session/login`.\n"
},
'Bot Token': {
type: "apiKey",
in: "header",
name: "x-bot-token",
description: "Generate a bot token in-app by going to [\"My Bots\"](https://app.revolt.chat/settings/bots) in user settings.\n"
else if (entry[i - 1] !== segments[i]) break;
}
if (i === segments.length) return copy.join('/');
}
}
type Methods = APIRoutes['method'];
type PickRoutes<Method extends Methods> = APIRoutes & { method: Method };
type GetRoutes = PickRoutes<'get'>;
type PatchRoutes = PickRoutes<'patch'>;
type PutRoutes = PickRoutes<'put'>;
type DeleteRoutes = PickRoutes<'delete'>;
type PostRoutes = PickRoutes<'post'>;
/**
* Client configuration options
*/
export interface Options {
/**
* Base URL of the Revolt node
*/
baseURL: string;
/**
* Authentication used for requests
*/
authentication: Session | string | undefined;
}
/**
* Revolt API Client
*/
export class RevoltAPI {
private baseURL: string;
private authentication: Session | string | undefined;
constructor({ baseURL, authentication }: Partial<Options> = { }) {
this.baseURL = baseURL ?? 'https://api.revolt.chat';
this.authentication = authentication;
}
/**
* Generate config to pass through to API.
*/
get config(): AxiosRequestConfig {
return {
baseURL: this.baseURL,
headers: typeof this.authentication === 'string'
? { 'X-Bot-Token': this.authentication }
: typeof this.authentication === 'object'
? { 'X-Session-Token': this.authentication.token }
: undefined
};
}
/**
* Send any arbitrary request.
* @param method HTTP Method
* @param path Path
* @param params Body or Query Parameters
* @param config Axios configuration
* @returns Typed Response Data
*/
req<Method extends Methods, Routes extends PickRoutes<Method>, Path extends Routes['path'], Route extends Routes & { path: Path }>(method: Method, path: Path, params: Route['params'], config?: AxiosRequestConfig): Promise<Route['response']> {
let query, body;
let named = getPathName(path);
// If we are aware of this route, then match the parameters given.
if (named && typeof params === 'object') {
const route = queryParams[named as keyof typeof queryParams];
const allowed_query = (route as unknown as Record<Method, string[]>)[method];
// Map each parameter to the correct object.
for (const parameter of Object.keys(params)) {
if (allowed_query.includes(parameter)) {
query = {
...(query ?? {}),
[parameter]: (params as Record<any, any>)[parameter]
};
} else {
body = {
...(body ?? {}),
[parameter]: (params as Record<any, any>)[parameter]
};
}
}
}
return Axios(path, {
...this.config,
...config,
method,
params: query,
data: body
})
.then(res => res.data);
}
/**
* Send HTTP GET request.
* @param path Path
* @param params Body or Query Parameters
* @param config Axios configuration
* @returns Typed Response Data
*/
get<Path extends GetRoutes['path'], Route extends GetRoutes & { path: Path }>(path: Path, params: Route['params'], config?: AxiosRequestConfig): Promise<Route['response']>;
/**
* Send HTTP GET request.
* @param path Path
* @returns Typed Response Data
*/
get<Path extends (GetRoutes & { params: undefined })['path'], Route extends GetRoutes & { path: Path }>(path: Path): Promise<Route['response']>;
get(path: any, params?: any, config?: AxiosRequestConfig): Promise<any> {
return this.req('get', path, params, config);
}
/**
* Send HTTP GET request.
* @param path Path
* @param params Body or Query Parameters
* @param config Axios configuration
* @returns Typed Response Data
*/
patch<Path extends PatchRoutes['path'], Route extends PatchRoutes & { path: Path }>(path: Path, params: Route['params'], config?: AxiosRequestConfig): Promise<Route['response']>;
/**
* Send HTTP PATCH request.
* @param path Path
* @returns Typed Response Data
*/
patch<Path extends (PatchRoutes & { params: undefined })['path'], Route extends PatchRoutes & { path: Path }>(path: Path): Promise<Route['response']>;
patch(path: any, params?: any, config?: AxiosRequestConfig): Promise<any> {
return this.req('patch', path, params, config);
}
/**
* Send HTTP PUT request.
* @param path Path
* @param params Body or Query Parameters
* @param config Axios configuration
* @returns Typed Response Data
*/
put<Path extends PutRoutes['path'], Route extends PutRoutes & { path: Path }>(path: Path, params: Route['params'], config?: AxiosRequestConfig): Promise<Route['response']>;
/**
* Send HTTP PUT request.
* @param path Path
* @returns Typed Response Data
*/
put<Path extends (PutRoutes & { params: undefined })['path'], Route extends PutRoutes & { path: Path }>(path: Path): Promise<Route['response']>;
put(path: any, params?: any, config?: AxiosRequestConfig): Promise<any> {
return this.req('put', path, params, config);
}
/**
* Send HTTP DELETE request.
* @param path Path
* @param params Body or Query Parameters
* @param config Axios configuration
* @returns Typed Response Data
*/
delete<Path extends DeleteRoutes['path'], Route extends DeleteRoutes & { path: Path }>(path: Path, config?: AxiosRequestConfig): Promise<Route['response']>;
/**
* Send HTTP DELETE request.
* @param path Path
* @returns Typed Response Data
*/
delete<Path extends (DeleteRoutes & { params: undefined })['path'], Route extends DeleteRoutes & { path: Path }>(path: Path): Promise<Route['response']>;
delete(path: any, config?: AxiosRequestConfig): Promise<any> {
return this.req('delete', path, undefined, config);
}
/**
* Send HTTP POST request.
* @param path Path
* @param params Body or Query Parameters
* @param config Axios configuration
* @returns Typed Response Data
*/
post<Path extends PostRoutes['path'], Route extends PostRoutes & { path: Path }>(path: Path, params: Route['params'], config?: AxiosRequestConfig): Promise<Route['response']>;
/**
* Send HTTP POST request.
* @param path Path
* @returns Typed Response Data
*/
post<Path extends (PostRoutes & { params: undefined })['path'], Route extends PostRoutes & { path: Path }>(path: Path): Promise<Route['response']>;
post(path: any, params?: any, config?: AxiosRequestConfig): Promise<any> {
return this.req('post', path, params, config);
}
}
generate()
.then(v =>
writeFile('OpenAPI.json', JSON.stringify(v, undefined, 2))
);

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc