2022-08-18 20:51:48 +00:00
|
|
|
import { ResolverOptions } from "@lumeweb/resolver-common";
|
|
|
|
|
2022-07-20 11:11:06 +00:00
|
|
|
const DNS_MODULE = "AQBLKpieqOfKVRgMa8k45P4S_ILYgJmswVso4vT1qzoG-A";
|
|
|
|
|
2022-08-14 10:54:18 +00:00
|
|
|
let callModule: any, connectModule: any;
|
2022-07-20 11:11:06 +00:00
|
|
|
|
2022-07-21 17:21:41 +00:00
|
|
|
async function loadLibs() {
|
2022-08-14 10:54:18 +00:00
|
|
|
if (callModule && connectModule) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (typeof window !== "undefined" && window?.document) {
|
|
|
|
const pkg = await import("libkernel");
|
|
|
|
callModule = pkg.callModule;
|
|
|
|
connectModule = pkg.connectModule;
|
|
|
|
} else {
|
|
|
|
const pkg = await import("libkmodule");
|
|
|
|
callModule = pkg.callModule;
|
|
|
|
connectModule = pkg.connectModule;
|
|
|
|
}
|
2022-07-20 11:11:06 +00:00
|
|
|
}
|
|
|
|
|
2022-08-18 20:51:48 +00:00
|
|
|
export async function resolve(
|
|
|
|
domain: string,
|
|
|
|
options: ResolverOptions,
|
|
|
|
bypassCache = false
|
|
|
|
) {
|
2022-08-14 10:54:18 +00:00
|
|
|
await loadLibs();
|
|
|
|
const [resp, err] = await callModule(DNS_MODULE, "resolve", {
|
|
|
|
domain,
|
2022-08-18 20:51:48 +00:00
|
|
|
options,
|
|
|
|
bypassCache,
|
2022-08-14 10:54:18 +00:00
|
|
|
});
|
2022-07-20 11:11:06 +00:00
|
|
|
|
2022-08-14 10:54:18 +00:00
|
|
|
if (err) {
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
2022-07-20 11:11:06 +00:00
|
|
|
|
2022-08-14 10:54:18 +00:00
|
|
|
return resp;
|
|
|
|
}
|
2022-08-18 20:51:48 +00:00
|
|
|
|
|
|
|
export async function register() {
|
|
|
|
await loadLibs();
|
|
|
|
await callModule(DNS_MODULE, "register");
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function clear() {
|
|
|
|
await loadLibs();
|
|
|
|
await callModule(DNS_MODULE, "clear");
|
|
|
|
}
|
|
|
|
|
2022-08-14 10:54:18 +00:00
|
|
|
export async function ready() {
|
|
|
|
await loadLibs();
|
|
|
|
const [resp, err] = await callModule(DNS_MODULE, "ready");
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp;
|
2022-07-20 11:11:06 +00:00
|
|
|
}
|