Skip to content

Commit

Permalink
fix: add type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Sep 19, 2023
1 parent e17852f commit b1cfe83
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"files": [
"package.json",
"CHANGELOG.md",
"index.d.ts",
"proxy.d.ts",
"README.md",
"LICENSE",
"lib"
],
"main": "./lib/proxy.js",
"types": "./proxy.d.ts",
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint --fix .",
Expand Down
85 changes: 85 additions & 0 deletions proxy.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import MetricsClient from '@metrics/client';
import { HttpIncoming } from '@podium/utils';

declare class PodiumProxy {
readonly pathname: string;
readonly prefix: string;
readonly metrics: MetricsClient;

constructor(options?: PodiumProxy.PodiumProxyOptions);

register(proxyManifest: PodiumProxy.PodletManifest): void;
/**
* @returns `undefined` if the incoming request didn't match anything registered in the proxy. Otherwise it returns the incoming request with the `.proxy` property set to true if successfully proxied.
*/
process<T = { [key: string]: unknown }>(
incoming: HttpIncoming<T>,
): Promise<HttpIncoming<T> | undefined>;
/**
* @returns An array of all loaded manifests ready to be used by `.load()`
*/
dump(): PodiumProxy.PodletManifest[];
/**
* Loads an Array of manifests (provided by `.dump()`) into the proxy. If any of
* the items in the loaded Array contains a key which is already in the cache, the
* entry in the cache will be overwritten.
*
* If any of the entries in the loaded Array are not compatible with the format
* which `.dump()` exports, they will not be inserted into the cache.
*
* @returns An Array with the keys which were inserted into the cache.
*/
load(manifests: PodiumProxy.PodletManifest[]): string[];
}

declare namespace PodiumProxy {
export type PodletManifest = {
name: string;
version: string;
content: string;
fallback?: string;
proxy?: Record<string, string>;
assets?: {
js?: string[];
css?: string[];
};
css?: string[];
js?: string[];
};

export type AbsLogger = {
trace: LogFunction;
debug: LogFunction;
info: LogFunction;
warn: LogFunction;
error: LogFunction;
fatal: LogFunction;
};

type LogFunction = (...args: any) => void;

export type PodiumProxyOptions = {
/**
* @default "/"
*/
pathname?: string;
/**
* @default "/podium-resource"
*/
prefix?: string;
/**
* @default 20000
*/
timeout?: number;
/**
* @default Infinity
*/
maxAge?: number;
/**
* @default null
*/
logger?: AbsLogger | null;
};
}

export = PodiumProxy;

0 comments on commit b1cfe83

Please sign in to comment.