Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ultraviolet
Path: blob/main/uv.d.ts
302 views
1
const Ultraviolet: typeof import("./src/rewrite/index").default;
2
const UVClient: typeof import("./src/client/index").default;
3
4
export type UltravioletCtor = typeof Ultraviolet;
5
export type UVClientCtor = typeof UVClient;
6
7
/**
8
* The proxy part of the URL.
9
*/
10
type Coded = string;
11
12
/**
13
* The URL encoder.
14
* Encoders will have to encode the result using encodeURLComponent.
15
*/
16
export type UVEncode = (input: Coded) => string;
17
18
/**
19
* The URL encoder.
20
* Decoders will have to decode the input first using decodeURLComponent.
21
*/
22
export type UVDecode = (input: Coded) => string;
23
24
export type UVInject = {
25
/**
26
* The host(s) to inject the HTML on.
27
* This is a regex that's tested against the proxied URL's host.
28
*/
29
host: RegExp;
30
/**
31
* Where to inject the HTML
32
* Possible values: `"head" | "body"`
33
*/
34
injectTo: "head" | "body";
35
/**
36
* The HTML to inject.
37
*/
38
html: string;
39
};
40
41
/**
42
* The Ultraviolet configuration object.
43
* This interface defines the configuration options for the Ultraviolet library.
44
*/
45
export interface UVConfig {
46
/**
47
* The prefix for Ultraviolet to listen on.
48
* This prefix will be used to create the URL for the service worker and the client script.
49
* @example `https://example.org/uv/service/`
50
* @example `/uv/service/`
51
* @defaultValue `/service/`
52
*/
53
prefix?: string;
54
/**
55
* The path to the Ultraviolet client script.
56
* This script will be loaded by the browser and is responsible for communicating with the service worker.
57
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
58
* @example `/uv/uv.client.js`,
59
* @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
60
*/
61
client?: string;
62
/**
63
* The path to the Ultraviolet service worker script.
64
* This script will be registered as a service worker and is responsible for handling network requests.
65
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
66
* @example `/uv/uv.sw.js`,
67
* @defaultValue `/uv.sw.js`
68
*/
69
handler?: string;
70
/**
71
* The path to the bundled script that contains both the Ultraviolet client and service worker scripts.
72
* This path is optional and can be used instead of the `client` and `handler` paths to load a single bundled script.
73
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
74
* @example `/uv/uv.bundle.js`,
75
* @defaultValue `/uv.bundle.js`
76
*/
77
bundle?: string;
78
/**
79
* The path to the Ultraviolet configuration script.
80
* This script should export a configuration object that will be used to configure the client and service worker.
81
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
82
* @example `/uv/uv.config.js`,
83
* @defaultValue `/uv.config.js`
84
*/
85
config?: string;
86
/**
87
* The path to the Ultraviolet service worker script.
88
* This path is optional and can be used instead of the `handler` path to specify a custom service worker script.
89
* Both relative and absolute paths are accepted. Relative paths are resolved to the current URL
90
* @example `/uv/uv.sw.js`,
91
* @defaultValue `/uv.sw.js`
92
*/
93
sw?: string;
94
/**
95
* The URL encoder.
96
* This function will be used to encode URLs before they are sent to the server.
97
* The encoder should use `encodeURIComponent` to encode the URLs.
98
* @defaultValue `Ultraviolet.codec.xor.encode`
99
*/
100
encodeUrl?: UVEncode;
101
/**
102
* The URL decoder.
103
* This function will be used to decode URLs after they are received from the server.
104
* The decoder should use `decodeURIComponent` to decode the URLs.
105
* @defaultValue `Ultraviolet.codec.xor.decode`
106
*/
107
decodeUrl?: UVDecode;
108
/**
109
* HTML inject settings.
110
* This property expects an array of `UVInject`.
111
*/
112
inject?: UVInject[];
113
}
114
115