*Update types to reflect relay refactoring and new plugin api
*Clean up old code
This commit is contained in:
parent
2d7bed64d5
commit
5242c16367
13
package.json
13
package.json
|
@ -5,9 +5,16 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@lumeweb/cfg": "https://github.com/LumeWeb/bcfg.git",
|
"@lumeweb/cfg": "https://github.com/LumeWeb/bcfg.git",
|
||||||
"@types/node": "^18.7.16",
|
"@types/node": "^18.11.17",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"loglevel": "^1.8.0",
|
"node-cache": "^5.1.2",
|
||||||
"node-cache": "^5.1.2"
|
"prettier": "^2.8.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@types/eventemitter2": "^4.1.0",
|
||||||
|
"arg": "^5.0.2",
|
||||||
|
"eventemitter2": "^6.4.9",
|
||||||
|
"micro-ed25519-hdkey": "^0.1.2",
|
||||||
|
"pino": "^8.8.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import type arg from "arg";
|
||||||
|
declare class Config {
|
||||||
|
private module;
|
||||||
|
private data;
|
||||||
|
constructor(module: string);
|
||||||
|
inject(options: object): void;
|
||||||
|
load(): void;
|
||||||
|
openDir(dir: string): void;
|
||||||
|
open(file: string): void;
|
||||||
|
save(file: string, data: object): void;
|
||||||
|
set(key: string, value: any): void;
|
||||||
|
has(key: string): any;
|
||||||
|
private normalize;
|
||||||
|
get(key: string, fallback?: any): any;
|
||||||
|
typeOf(
|
||||||
|
key: string
|
||||||
|
):
|
||||||
|
| "string"
|
||||||
|
| "number"
|
||||||
|
| "bigint"
|
||||||
|
| "boolean"
|
||||||
|
| "symbol"
|
||||||
|
| "undefined"
|
||||||
|
| "object"
|
||||||
|
| "function"
|
||||||
|
| "null";
|
||||||
|
str(key: string, fallback?: any): any;
|
||||||
|
int(key: any, fallback?: any): any;
|
||||||
|
uint(key: any, fallback?: any): any;
|
||||||
|
float(key: any, fallback?: any): any;
|
||||||
|
ufloat(key: any, fallback?: any): any;
|
||||||
|
fixed(key: any, exp: any, fallback?: any): any;
|
||||||
|
ufixed(key: any, exp: any, fallback?: any): any;
|
||||||
|
bool(key: any, fallback?: any): any;
|
||||||
|
buf(key: string, fallback?: any, enc?: BufferEncoding): any;
|
||||||
|
array(key: string, fallback?: any): any;
|
||||||
|
obj(key: string, fallback?: any): any;
|
||||||
|
func(key: string, fallback?: any): any;
|
||||||
|
mb(key: string, fallback?: any): any;
|
||||||
|
parseArg(args: arg.Result<any>): void;
|
||||||
|
parseEnv(env?: object): void;
|
||||||
|
}
|
||||||
|
export default Config;
|
|
@ -1,20 +1,12 @@
|
||||||
import Config from "@lumeweb/cfg";
|
import type { EventEmitter2 } from "eventemitter2";
|
||||||
import tls from "tls";
|
|
||||||
import { Logger } from "loglevel";
|
|
||||||
import { RPCMethod, RPCServer } from "./rpc.js";
|
import { RPCMethod, RPCServer } from "./rpc.js";
|
||||||
import { IndependentFileSmall, SavedSslData, SslData } from "./files.js";
|
import { Logger } from "pino";
|
||||||
import type { express } from "express";
|
import SSLManager from "./ssl.js";
|
||||||
// @ts-ignore
|
import type { HDKey } from "micro-ed25519-hdkey";
|
||||||
import type { Err } from "libskynet";
|
import Config from "./config.js";
|
||||||
|
|
||||||
export type PluginFunction = (api: PluginAPI) => Promise<void>;
|
export type PluginFunction = (api: PluginAPI) => Promise<void>;
|
||||||
|
|
||||||
export type DnsProvider = (ipAddress: string, domain: string) => Promise<void>;
|
|
||||||
|
|
||||||
export type OverwriteDataFn = (newData: Uint8Array) => Promise<Err>;
|
|
||||||
|
|
||||||
export type ReadDataFn = () => Promise<[Uint8Array, Err]>;
|
|
||||||
|
|
||||||
export interface Plugin {
|
export interface Plugin {
|
||||||
name: string;
|
name: string;
|
||||||
plugin: PluginFunction;
|
plugin: PluginFunction;
|
||||||
|
@ -22,46 +14,29 @@ export interface Plugin {
|
||||||
default?: Plugin;
|
default?: Plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PluginAPI {
|
declare class PluginAPI extends EventEmitter2 {
|
||||||
config: Config;
|
private _server;
|
||||||
registerMethod: (methodName: string, method: RPCMethod) => void;
|
constructor({
|
||||||
loadPlugin: (moduleName: string) => Promise<Plugin>;
|
config,
|
||||||
getRpcServer: () => RPCServer;
|
logger,
|
||||||
ssl: {
|
server,
|
||||||
setContext: (context: tls.SecureContext) => void;
|
swarm,
|
||||||
getContext: () => tls.SecureContext;
|
}: {
|
||||||
getSaved: (retry: boolean) => Promise<boolean | SavedSslData>;
|
config: Config;
|
||||||
set: (
|
logger: Logger;
|
||||||
cert: IndependentFileSmall | Uint8Array,
|
server: RPCServer;
|
||||||
key: IndependentFileSmall | Uint8Array
|
swarm: any;
|
||||||
) => void;
|
});
|
||||||
get: () => SslData;
|
private _swarm;
|
||||||
save: () => Promise<void>;
|
get swarm(): any;
|
||||||
setCheck(checker: () => Promise<void>): void;
|
private _config;
|
||||||
};
|
get config(): Config;
|
||||||
appRouter: {
|
private _logger;
|
||||||
get: () => express.Router;
|
get logger(): Logger;
|
||||||
set: (newRouter: express.Router) => void;
|
get rpcServer(): RPCServer;
|
||||||
reset: () => void;
|
get seed(): Uint8Array;
|
||||||
};
|
get identity(): HDKey;
|
||||||
files: {
|
get ssl(): SSLManager;
|
||||||
createIndependentFileSmall(
|
loadPlugin(moduleName: string): (moduleName: string) => Promise<Plugin>;
|
||||||
seed: Uint8Array,
|
registerMethod(methodName: string, method: RPCMethod): void;
|
||||||
userInode: string,
|
|
||||||
fileData: Uint8Array
|
|
||||||
): Promise<[IndependentFileSmall, Err]>;
|
|
||||||
openIndependentFileSmall(
|
|
||||||
seed: Uint8Array,
|
|
||||||
userInode: string
|
|
||||||
): Promise<[IndependentFileSmall, Err]>;
|
|
||||||
overwriteIndependentFileSmall(
|
|
||||||
file: IndependentFileSmall,
|
|
||||||
newData: Uint8Array
|
|
||||||
): Promise<Err>;
|
|
||||||
};
|
|
||||||
dns: {
|
|
||||||
setProvider(provider: DnsProvider): void;
|
|
||||||
};
|
|
||||||
logger: Logger;
|
|
||||||
getSeed: () => Uint8Array;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import type tls from "tls";
|
||||||
|
|
||||||
|
export type SSLManagerRenewHandler = (domain: string) => Promise<boolean>;
|
||||||
|
declare class SSLManager {
|
||||||
|
private _context?;
|
||||||
|
private _key?;
|
||||||
|
private _cert?;
|
||||||
|
private _domain;
|
||||||
|
private _renewHandler?;
|
||||||
|
constructor(domain: string);
|
||||||
|
get context(): tls.SecureContext;
|
||||||
|
set privateKey(key: Buffer);
|
||||||
|
set cert(cert: Buffer);
|
||||||
|
private _maybeUpdateContext;
|
||||||
|
renew(): Promise<boolean>;
|
||||||
|
get enabled(): any;
|
||||||
|
}
|
||||||
|
export default SSLManager;
|
Loading…
Reference in New Issue