Move getToken/getMoonToken and add cli-table types

This commit is contained in:
Samuel Elliott
2022-05-09 21:28:31 +01:00
parent 992f8900f2
commit 784e882dd4
52 changed files with 493 additions and 234 deletions

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nooklink.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getUserToken, getWebServiceToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nooklink.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getUserToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nooklink.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getUserToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nooklink.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getUserToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nooklink.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getWebServiceToken } from './util.js';

View File

@@ -1,6 +1,6 @@
import createDebug from 'debug';
import persist from 'node-persist';
import { getToken } from '../../util.js';
import { getToken } from '../nso/util.js';
import NooklinkApi, { NooklinkUserApi } from '../../api/nooklink.js';
import { AuthToken, Users } from '../../api/nooklink-types.js';
import { WebServiceToken } from '../../api/znc-types.js';

View File

@@ -1,8 +1,8 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
const debug = createDebug('cli:nso:announcements');

View File

@@ -2,7 +2,8 @@ import * as util from 'util';
import createDebug from 'debug';
import * as crypto from 'crypto';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
import { getNintendoAccountSessionToken } from '../../api/na.js';
import { ZNCA_CLIENT_ID } from '../../api/znc.js';

View File

@@ -1,9 +1,9 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import { PresenceState } from '../../api/znc-types.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, hrduration, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, hrduration, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
const debug = createDebug('cli:nso:friends');

View File

@@ -6,7 +6,8 @@ import { v4 as uuidgen } from 'uuid';
import { Announcement, CurrentUser, Friend, GetActiveEventResult, Presence, WebService } from '../../api/znc-types.js';
import ZncApi from '../../api/znc.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, SavedToken, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken, SavedToken } from './util.js';
import { NotificationManager, ZncNotifications } from './notify.js';
declare global {

View File

@@ -5,7 +5,8 @@ import * as path from 'path';
import { ActiveEvent, Announcements, CurrentUser, Friend, Game, Presence, PresenceState, WebServices, ZncErrorResponse } from '../../api/znc-types.js';
import ZncApi from '../../api/znc.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getTitleIdFromEcUrl, getToken, hrduration, initStorage, Loop, LoopResult, SavedToken, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, getTitleIdFromEcUrl, hrduration, initStorage, Loop, LoopResult, YargsArguments } from '../../util.js';
import { getToken, SavedToken } from './util.js';
import ZncProxyApi from '../../api/znc-proxy.js';
import { SplatNet2RecordsMonitor } from '../splatnet2/monitor.js';
import { getIksmToken } from '../splatnet2/util.js';

View File

@@ -1,7 +1,8 @@
import createDebug from 'debug';
import { PresencePermissions } from '../../api/znc-types.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
const debug = createDebug('cli:nso:permissions');

View File

@@ -4,7 +4,8 @@ import DiscordRPC from 'discord-rpc';
import { ActiveEvent, CurrentUser, Friend, Presence, PresenceState, ZncErrorResponse } from '../../api/znc-types.js';
import ZncApi from '../../api/znc.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, LoopResult, SavedToken, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, LoopResult, YargsArguments } from '../../util.js';
import { getToken, SavedToken } from './util.js';
import { DiscordPresencePlayTime, DiscordPresenceContext, getDiscordPresence, getInactiveDiscordPresence } from '../../discord/util.js';
import { handleEnableSplatNet2Monitoring, ZncNotifications } from './notify.js';
import { ErrorResponse } from '../../index.js';

View File

@@ -1,7 +1,8 @@
import * as util from 'util';
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
const debug = createDebug('cli:nso:token');

View File

@@ -1,6 +1,7 @@
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
const debug = createDebug('cli:nso:user');

86
src/cli/nso/util.ts Normal file
View File

@@ -0,0 +1,86 @@
import createDebug from 'debug';
import * as persist from 'node-persist';
import { FlapgApiResponse } from '../../api/f.js';
import { NintendoAccountSessionTokenJwtPayload, NintendoAccountToken, NintendoAccountUser } from '../../api/na.js';
import { Jwt } from '../../api/util.js';
import { AccountLogin } from '../../api/znc-types.js';
import ZncApi, { ZNCA_CLIENT_ID } from '../../api/znc.js';
import ZncProxyApi from '../../api/znc-proxy.js';
const debug = createDebug('cli:nso');
export interface SavedToken {
uuid: string;
timestamp: string;
nintendoAccountToken: NintendoAccountToken;
user: NintendoAccountUser;
flapg: FlapgApiResponse['result'];
nsoAccount: AccountLogin;
credential: AccountLogin['webApiServerCredential'];
expires_at: number;
proxy_url?: string;
}
export async function getToken(storage: persist.LocalStorage, token: string, proxy_url: string): Promise<{
nso: ZncProxyApi;
data: SavedToken;
}>
export async function getToken(storage: persist.LocalStorage, token: string, proxy_url?: string): Promise<{
nso: ZncApi;
data: SavedToken;
}>
export async function getToken(storage: persist.LocalStorage, token: string, proxy_url?: string) {
if (!token) {
console.error('No token set. Set a Nintendo Account session token using the `--token` option or by running `nxapi nso token`.');
throw new Error('Invalid token');
}
const [jwt, sig] = Jwt.decode<NintendoAccountSessionTokenJwtPayload>(token);
if (jwt.payload.iss !== 'https://accounts.nintendo.com') {
throw new Error('Invalid Nintendo Account session token issuer');
}
if (jwt.payload.typ !== 'session_token') {
throw new Error('Invalid Nintendo Account session token type');
}
if (jwt.payload.aud !== ZNCA_CLIENT_ID) {
throw new Error('Invalid Nintendo Account session token audience');
}
if (jwt.payload.exp <= (Date.now() / 1000)) {
throw new Error('Nintendo Account session token expired');
}
// Nintendo Account session tokens use a HMAC SHA256 signature, so we can't verify this is valid
const existingToken: SavedToken | undefined = await storage.getItem('NsoToken.' + token);
if (!existingToken || existingToken.expires_at <= Date.now()) {
console.warn('Authenticating to Nintendo Switch Online app');
debug('Authenticating to znc with session token');
const {nso, data} = proxy_url ?
await ZncProxyApi.createWithSessionToken(proxy_url, token) :
await ZncApi.createWithSessionToken(token);
const existingToken: SavedToken = {
...data,
expires_at: Date.now() + (data.credential.expiresIn * 1000),
};
await storage.setItem('NsoToken.' + token, existingToken);
await storage.setItem('NintendoAccountToken.' + data.user.id, token);
return {nso, data: existingToken};
}
debug('Using existing token');
await storage.setItem('NintendoAccountToken.' + existingToken.user.id, token);
return {
nso: proxy_url ?
new ZncProxyApi(proxy_url, token) :
new ZncApi(existingToken.credential.accessToken),
data: existingToken,
};
}

View File

@@ -1,8 +1,8 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
const debug = createDebug('cli:nso:webservices');

View File

@@ -1,6 +1,7 @@
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../nso.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from './util.js';
const debug = createDebug('cli:nso:webservicetoken');

View File

@@ -1,9 +1,9 @@
import createDebug from 'debug';
import fetch from 'node-fetch';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../nso.js';
import { Argv, getToken, initStorage } from '../../util.js';
import { Argv, initStorage } from '../../util.js';
import { getToken } from './util.js';
import { AuthPolicy, AuthToken } from './http-server.js';
const debug = createDebug('cli:nso:znc-proxy-tokens');

View File

@@ -1,8 +1,9 @@
import * as util from 'util';
import createDebug from 'debug';
import * as crypto from 'crypto';
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
import { getNintendoAccountSessionToken } from '../../api/na.js';
import { ZNMA_CLIENT_ID } from '../../api/moon.js';

View File

@@ -1,8 +1,8 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, hrduration, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, hrduration, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
const debug = createDebug('cli:pctl:daily-summaries');

View File

@@ -1,8 +1,8 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
const debug = createDebug('cli:pctl:devices');

View File

@@ -1,9 +1,10 @@
import createDebug from 'debug';
import * as path from 'path';
import * as fs from 'fs/promises';
import createDebug from 'debug';
import mkdirp from 'mkdirp';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import * as path from 'path';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
import { DailySummaryResult } from '../../api/moon-types.js';
import MoonApi from '../../api/moon.js';

View File

@@ -1,8 +1,8 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
const debug = createDebug('cli:pctl:monthly-summaries');

View File

@@ -1,8 +1,8 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
const debug = createDebug('cli:pctl:monthly-summary');

View File

@@ -1,6 +1,7 @@
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
const debug = createDebug('cli:pctl:settings');

View File

@@ -1,7 +1,8 @@
import * as util from 'util';
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
const debug = createDebug('cli:pctl:token');

View File

@@ -1,6 +1,7 @@
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../../cli.js';
import { ArgumentsCamelCase, Argv, getPctlToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getPctlToken } from './util.js';
const debug = createDebug('cli:pctl:user');

66
src/cli/pctl/util.ts Normal file
View File

@@ -0,0 +1,66 @@
import createDebug from 'debug';
import * as persist from 'node-persist';
import { ZNMA_CLIENT_ID } from '../../api/moon.js';
import { NintendoAccountSessionTokenJwtPayload, NintendoAccountToken, NintendoAccountUser } from '../../api/na.js';
import { Jwt } from '../../api/util.js';
import MoonApi from '../../api/moon.js';
const debug = createDebug('cli:nso');
export interface SavedMoonToken {
nintendoAccountToken: NintendoAccountToken;
user: NintendoAccountUser;
expires_at: number;
}
export async function getPctlToken(storage: persist.LocalStorage, token: string) {
if (!token) {
console.error('No token set. Set a Nintendo Account session token using the `--token` option or by running `nxapi pctl auth`.');
throw new Error('Invalid token');
}
const [jwt, sig] = Jwt.decode<NintendoAccountSessionTokenJwtPayload>(token);
if (jwt.payload.iss !== 'https://accounts.nintendo.com') {
throw new Error('Invalid Nintendo Account session token issuer');
}
if (jwt.payload.typ !== 'session_token') {
throw new Error('Invalid Nintendo Account session token type');
}
if (jwt.payload.aud !== ZNMA_CLIENT_ID) {
throw new Error('Invalid Nintendo Account session token audience');
}
if (jwt.payload.exp <= (Date.now() / 1000)) {
throw new Error('Nintendo Account session token expired');
}
// Nintendo Account session tokens use a HMAC SHA256 signature, so we can't verify this is valid
const existingToken: SavedMoonToken | undefined = await storage.getItem('MoonToken.' + token);
if (!existingToken || existingToken.expires_at <= Date.now()) {
console.warn('Authenticating to Nintendo Switch Parental Controls app');
debug('Authenticating to pctl with session token');
const {moon, data} = await MoonApi.createWithSessionToken(token);
const existingToken: SavedMoonToken = {
...data,
expires_at: Date.now() + (data.nintendoAccountToken.expires_in * 1000),
};
await storage.setItem('MoonToken.' + token, existingToken);
await storage.setItem('NintendoAccountToken-pctl.' + data.user.id, token);
return {moon, data: existingToken};
}
debug('Using existing token');
await storage.setItem('NintendoAccountToken-pctl.' + existingToken.user.id, token);
return {
moon: new MoonApi(existingToken.nintendoAccountToken.access_token!, existingToken.user.id),
data: existingToken,
};
}

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../splatnet2.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getIksmToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../splatnet2.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getIksmToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../splatnet2.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getIksmToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../splatnet2.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getIksmToken } from './util.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../splatnet2.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getIksmToken } from './util.js';

View File

@@ -1,7 +1,7 @@
import createDebug from 'debug';
import persist from 'node-persist';
import * as fs from 'fs';
import { getToken } from '../../util.js';
import { getToken } from '../nso/util.js';
import SplatNet2Api from '../../api/splatnet2.js';
import { WebServiceToken } from '../../api/znc-types.js';

View File

@@ -1,6 +1,5 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from '../util/table.js';
import type { Arguments as ParentArguments } from '../splatnet2.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getIksmToken } from './util.js';

View File

@@ -1,8 +1,9 @@
import createDebug from 'debug';
// @ts-expect-error
import Table from 'cli-table/lib/index.js';
import Table from './util/table.js';
import type { Arguments as ParentArguments } from '../cli.js';
import { Argv, initStorage, SavedMoonToken, SavedToken } from '../util.js';
import { Argv, initStorage } from '../util.js';
import { SavedToken } from './nso/util.js';
import { SavedMoonToken } from './pctl/util.js';
const debug = createDebug('cli:users');

View File

@@ -1,4 +1,5 @@
import * as crypto from 'crypto';
import { Buffer } from 'buffer';
import createDebug from 'debug';
import type { Arguments as ParentArguments } from '../../cli.js';
import { Argv } from '../../util.js';

View File

@@ -4,7 +4,8 @@ import { getPresenceFromUrl } from '../../api/znc-proxy.js';
import { ActiveEvent, CurrentUser, Friend, Game, Presence, PresenceState } from '../../api/znc-types.js';
import type { Arguments as ParentArguments } from '../../cli.js';
import { DiscordPresenceContext, DiscordPresencePlayTime, getDiscordPresence, getInactiveDiscordPresence } from '../../discord/util.js';
import { ArgumentsCamelCase, Argv, getToken, initStorage, YargsArguments } from '../../util.js';
import { ArgumentsCamelCase, Argv, initStorage, YargsArguments } from '../../util.js';
import { getToken } from '../nso/util.js';
const debug = createDebug('cli:util:discord-activity');

127
src/cli/util/table.ts Normal file
View File

@@ -0,0 +1,127 @@
// @ts-expect-error
import __Table from 'cli-table/lib/index.js';
export type Cell = string | number;
export type Row = Cell[];
export enum CellAlign {
LEFT = 'left',
MIDDLE = 'middle',
RIGHT = 'right',
}
export enum Style {
BLACK = 'black',
RED = 'red',
GREEN = 'green',
YELLOW = 'yellow',
BLUE = 'blue',
MAGENTA = 'magenta',
CYAN = 'cyan',
WHITE = 'white',
GREY = 'grey',
BRIGHTRED = 'brightRed',
BRIGHTGREEN = 'brightGreen',
BRIGHTYELLOW = 'brightYellow',
BRIGHTBLUE = 'brightBlue',
BRIGHTMAGENTA = 'brightMagenta',
BRIGHTCYAN = 'brightCyan',
BRIGHTWHITE = 'brightWhite',
BG_BLACK = 'bgBlack',
BG_RED = 'bgRed',
BG_GREEN = 'bgGreen',
BG_YELLOW = 'bgYellow',
BG_BLUE = 'bgBlue',
BG_MAGENTA = 'bgMagenta',
BG_CYAN = 'bgCyan',
BG_WHITE = 'bgWhite',
BG_GREY = 'bgGrey',
BG_BRIGHTRED = 'bgBrightRed',
BG_BRIGHTGREEN = 'bgBrightGreen',
BG_BRIGHTYELLOW = 'bgBrightYellow',
BG_BRIGHTBLUE = 'bgBrightBlue',
BG_BRIGHTMAGENTA = 'bgBrightMagenta',
BG_BRIGHTCYAN = 'bgBrightCyan',
BG_BRIGHTWHITE = 'bgBrightWhite',
RESET = 'reset',
BOLD = 'bold',
DIM = 'dim',
ITALIC = 'italic',
UNDERLINE = 'underline',
INVERSE = 'inverse',
HIDDEN = 'hidden',
STRIKETHROUGH = 'strikethrough',
RAINBOW = 'rainbow',
ZEBRA = 'zebra',
AMERICA = 'america',
TRAP = 'trap',
RANDOM = 'random',
}
export interface TableOptions {
chars: {
'top': string;
'top-mid': string;
'top-left': string;
'top-right': string;
'bottom': string;
'bottom-mid': string;
'bottom-left': string;
'bottom-right': string;
'left': string;
'left-mid': string;
'mid': string;
'mid-mid': string;
'right': string;
'right-mid': string;
'middle': string;
};
truncate: string;
colWidths: number[];
colAligns: CellAlign[];
style: {
'padding-left': number;
'padding-right': number;
/** @default [Style.RED] */
head: Style[];
/** @default [Style.GREY] */
border: Style[];
compact: boolean;
};
head: Row;
rows: Row[];
}
type RecursivePartial<T extends {}> = {
[P in keyof T]?: (T[P] extends Array<unknown> ? T[P] : RecursivePartial<T[P]>) | undefined;
};
export type PartialTableOptions = RecursivePartial<TableOptions>;
declare class Table extends Array<Row> {
options: TableOptions;
constructor(options: PartialTableOptions);
/**
* Width getter
*/
get width(): number;
/**
* Render to a string.
*/
render(): string;
/**
* Render to a string.
*/
toString(): string;
static version: string;
}
const _Table: typeof Table = __Table;
type _Table = Table;
export default _Table;