diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..c2f71e2 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1 @@ +declare const __uv$config: import('./uv').UVConfig; diff --git a/src/rewrite/index.js b/src/rewrite/index.js index 3cdae2a..4f1986e 100644 --- a/src/rewrite/index.js +++ b/src/rewrite/index.js @@ -37,7 +37,15 @@ import { openDB } from 'idb'; import BareClient from '@tomphttp/bare-client'; import EventEmitter from 'events'; +/** + * @typedef {import('../uv.js').UVConfig} UVConfig + */ + class Ultraviolet { + /** + * + * @param {UVConfig} [options] + */ constructor(options = {}) { this.prefix = options.prefix || '/service/'; //this.urlRegex = /^(#|about:|data:|mailto:|javascript:)/; diff --git a/src/uv.config.js b/src/uv.config.js index 6455518..56d1a92 100644 --- a/src/uv.config.js +++ b/src/uv.config.js @@ -1,7 +1,7 @@ /*global Ultraviolet*/ self.__uv$config = { prefix: '/service/', - bare: 'https://uv.holyubofficial.net/', + bare: '/bare/', encodeUrl: Ultraviolet.codec.xor.encode, decodeUrl: Ultraviolet.codec.xor.decode, handler: '/uv.handler.js', diff --git a/src/uv.d.ts b/src/uv.d.ts index c08744d..8942e56 100644 --- a/src/uv.d.ts +++ b/src/uv.d.ts @@ -3,3 +3,92 @@ const UVClient: typeof import('./client/index').default; export type UltravioletCtor = typeof Ultraviolet; export type UVClientCtor = typeof UVClient; + +/** + * The proxy part of the URL. + */ +type Coded = string; + +/** + * The URL encoder. + * Encoders will have to encode the result using encodeURLComponent. + */ +export type UVEncode = (input: Coded) => string; + +/** + * The URL encoder. + * Decoders will have to decode the input first using decodeURLComponent. + */ +export type UVDecode = (input: Coded) => string; + +/** + * The Ultraviolet configuration object. + */ +export interface UVConfig { + /** + * The Bare server(s) to use. + * If an array is specified, the service worker will randomly select a server to use. + * The selected server will be used for the duration of the session. + * Both relative and absolute paths are accepted. Relative paths are resolved to the current URL. + * @example // A Bare server running on the subdomain `bare.`, automatically correcting the apex record: + * `${location.protocol}//bare.${location.host.replace(/^www\./, "")} + * @example `http://localhost:8080/` + * @example `http://localhost:8080/bare/` + * @defaultValue `/bare/` + * @see {@link|https://github.com/tomphttp/specifications/blob/master/BareServer.md} + */ + bare?: string | string[]; + /** + * The prefix for Ultraviolet to listen on. + * @example `https://example.org/uv/service/` + * @example `/uv/service/` + * @defaultValue `/service/` + */ + prefix?: string; + /** + * The path to the Ultraviolet client script. + * Both relative and absolute paths are accepted. Relative paths are resolved to the current URL + * @example `/uv/uv.client.js`, + * @defaultValue `/uv.client.js` or if bundle is specified and the filename is `uv.bundle.js`, the directory of the bundle + `uv.client.js` will be used automatically + */ + client?: string; + /** + * The path to the Ultraviolet service worker script. + * Both relative and absolute paths are accepted. Relative paths are resolved to the current URL + * @example `/uv/uv.sw.js`, + * @defaultValue `/uv.sw.js` + */ + handler?: string; + /** + * The path to the Ultraviolet service worker script. + * Both relative and absolute paths are accepted. Relative paths are resolved to the current URL + * @example `/uv/uv.sw.js`, + * @defaultValue `/uv.sw.js` + */ + bundle?: string; + /** + * The path to the Ultraviolet service worker script. + * Both relative and absolute paths are accepted. Relative paths are resolved to the current URL + * @example `/uv/uv.config.js`, + * @defaultValue `/uv.config.js` + */ + config?: string; + /** + * The path to the Ultraviolet service worker script. + * Both relative and absolute paths are accepted. Relative paths are resolved to the current URL + * @example `/uv/uv.sw.js`, + * @defaultValue `/uv.sw.js` + */ + sw?: string; + /** + * The URL encoder. + * @defaultValue `Ultraviolet.codec.xor.encode` + */ + encodeUrl?: UVEncode; + /** + * The URL decoder. + * @defaultValue `Ultraviolet.codec.xor.encode` + * + */ + decodeUrl?: UVDecode; +}