@fkn/lib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # FKN web library
2
+
3
+
4
+
5
+ ## TODOs:
6
+ - make docs using vitepress
package/build/api.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Target } from 'osra';
2
+ export declare const setApiTarget: (messagePort: Target | Promise<Target>) => Promise<void>;
3
+ export declare const apiTargetIsReady: () => Promise<Target>;
4
+ export declare const getApiTargetPort: () => Promise<any>;
package/build/dom.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare const isWorker: boolean;
2
+ export declare const foundIframe: HTMLIFrameElement | null;
3
+ export declare const createdIframe: HTMLIFrameElement | undefined;
4
+ export declare const iframe: HTMLIFrameElement | undefined;
5
+ export declare const targetWindow: Window | null | undefined;
@@ -0,0 +1,3 @@
1
+ export { serverProxyFetch } from './proxy';
2
+ export { torrent, torrentFile } from './torrent';
3
+ export { setApiTarget, apiTargetIsReady as getApiTarget, getApiTargetPort } from './api';
package/build/index.js ADDED
@@ -0,0 +1,76 @@
1
+ import { call as w } from "osra";
2
+ let f, a;
3
+ const g = () => (a = new Promise((e, t) => {
4
+ f = e;
5
+ }), a), m = g(), l = async (e) => {
6
+ e === m && g(), f(await e);
7
+ }, T = "https://fkn.app", y = globalThis.window === void 0, h = globalThis.document?.body.querySelector(`iframe[src="${`${T}/sandbox-api`}"]`), s = h ? void 0 : globalThis.document?.createElement("iframe");
8
+ s && (s.src = `${T}/sandbox-api`, s.style.display = "none", document.body.appendChild(s));
9
+ const c = globalThis.window?.parent === globalThis.window ? h ?? s : void 0, r = globalThis.window?.parent === globalThis.window ? c?.contentWindow : globalThis.window?.parent, k = (e) => l(e), b = () => a, E = async () => w(await b(), { key: "fkn-sandbox-api" })("API_PORT", {});
10
+ if (y) {
11
+ let e = !1;
12
+ a.then(() => {
13
+ e = !0;
14
+ }), setTimeout(() => {
15
+ e || console.warn("@fkn/lib's api target has not resolved after 250ms while in a worker, make sure to call `setApiTarget(messagePort)`");
16
+ }, 250);
17
+ } else {
18
+ if (!r)
19
+ throw new Error("Missing target window on non worker thread");
20
+ if (window.parent === window && !h) {
21
+ if (!c)
22
+ throw new Error("Missing appended iframe");
23
+ c.addEventListener("load", () => {
24
+ const e = setInterval(
25
+ () => w(r, { key: "fkn-sandbox" })("APP_READY", {}).then(() => {
26
+ l(r), clearInterval(e);
27
+ }),
28
+ 10
29
+ );
30
+ });
31
+ } else
32
+ l(r);
33
+ }
34
+ const p = (e, t) => b().then(
35
+ (n) => w(n, { key: "fkn-sandbox-api" })(e, t)
36
+ ), u = async (e, t) => {
37
+ const n = e, i = t, { body: d, ...o } = await p("SERVER_PROXY_FETCH", { input: n, init: i });
38
+ return new Response(
39
+ d,
40
+ {
41
+ ...o,
42
+ headers: {
43
+ ...o.headers,
44
+ ...o.headers && {
45
+ setCookie: o.headers["set-cookie"]
46
+ }
47
+ }
48
+ }
49
+ );
50
+ }, v = async ({ magnet: e, path: t, offset: n, end: i }) => {
51
+ const { body: d, ...o } = await p("TORRENT", { magnet: e, path: t, offset: n, end: i });
52
+ return new Response(
53
+ d,
54
+ {
55
+ ...o,
56
+ headers: Object.fromEntries(o.headers)
57
+ }
58
+ );
59
+ }, P = async ({ magnet: e }) => {
60
+ const { body: t, ...n } = await p("TORRENT_FILE", { magnet: e });
61
+ return new Response(
62
+ t,
63
+ {
64
+ ...n,
65
+ headers: Object.fromEntries(n.headers)
66
+ }
67
+ );
68
+ };
69
+ export {
70
+ b as getApiTarget,
71
+ E as getApiTargetPort,
72
+ u as serverProxyFetch,
73
+ k as setApiTarget,
74
+ v as torrent,
75
+ P as torrentFile
76
+ };
@@ -0,0 +1 @@
1
+ export declare const showPluginBrowser: () => Promise<any>;
@@ -0,0 +1,13 @@
1
+ export type NativeFetch = typeof globalThis.fetch;
2
+ export type ProxyFetchRequestInit = Omit<RequestInit, "body" | "headers" | "signal"> & {
3
+ body: Exclude<RequestInit['body'], FormData | URLSearchParams>;
4
+ headers: Exclude<RequestInit['headers'], Headers>;
5
+ };
6
+ export type FetchInitOptions = {
7
+ proxyCache?: string | undefined;
8
+ proxyDelay?: string | undefined;
9
+ proxyRuntime?: boolean | undefined;
10
+ noProxy?: boolean | undefined;
11
+ };
12
+ export type ProxyFetchRequestInfo = string | Omit<Request, "arrayBuffer" | "text" | "headers" | "signal" | "clone" | "blob" | "formData" | "json">;
13
+ export declare const serverProxyFetch: (_input: Parameters<NativeFetch>[0], _init?: Parameters<NativeFetch>[1]) => Promise<Response>;
@@ -0,0 +1,6 @@
1
+ import { Target } from 'osra';
2
+ export declare let _resolve: any, _reject: any;
3
+ export declare let target: Promise<Target>;
4
+ export declare const initTargetPromise: () => Promise<Target>;
5
+ export declare const initialTargetPromise: Promise<Target>;
6
+ export declare const setTarget: (newTarget: Target | Promise<Target>) => Promise<void>;
@@ -0,0 +1,10 @@
1
+ export type TorrentOptions = {
2
+ magnet: string;
3
+ path: string;
4
+ offset?: number;
5
+ end?: number;
6
+ };
7
+ export declare const torrent: ({ magnet, path, offset, end }: TorrentOptions) => Promise<Response>;
8
+ export declare const torrentFile: ({ magnet }: {
9
+ magnet: string;
10
+ }) => Promise<Response>;
@@ -0,0 +1,2 @@
1
+ declare const readyCall: <T2 extends SandboxApiResolvers, T3 extends keyof T2>(type: T3, data?: Parameters<T2[T3]>[0] | undefined) => Promise<any>;
2
+ export { readyCall as call, };
@@ -0,0 +1 @@
1
+ export * from './call';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@fkn/lib",
3
+ "version": "0.0.1",
4
+ "main": "build/index.js",
5
+ "types": "build/index.d.ts",
6
+ "type": "module",
7
+ "files": ["build"],
8
+ "devDependencies": {
9
+ "@mfkn/web": "file:../web",
10
+ "@mfkn/web-extension": "git+https://github.com/MFKN/web-extension.git",
11
+ "concurrently": "^7.6.0",
12
+ "parse-torrent-file": "^4.2.2",
13
+ "typescript": "^4.9.3",
14
+ "vite": "^3.2.5",
15
+ "webextension-polyfill": "^0.10.0"
16
+ },
17
+ "scripts": {
18
+ "dev": "concurrently \"vite build --watch --mode development\" \"tsc --watch\"",
19
+ "build": "vite build && tsc",
20
+ "build-dev": "vite build --mode development && tsc",
21
+ "dev-watch": "vite build --watch --mode development",
22
+ "build-types": "tsc"
23
+ },
24
+ "dependencies": {
25
+ "osra": "^0.0.9"
26
+ }
27
+ }