Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 111 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,26 +26,27 @@
"exports": {
".": "./plugin/index.ts",
"./api": "./plugin/api.ts",
"./react": "./plugin/react/index.ts",
"./hooks": "./plugin/hooks.ts",
"./service": "./plugin/service.ts"
},
"scripts": {
"format": "prettier --write ."
},
"dependencies": {
"await-lock": "^3.0.0",
"date-fns": "^2.25.0",
"validator": "^13.15.15"
"is-url": "^1.2.4"
},
"devDependencies": {
"@types/is-url": "^1.2.32",
"@types/react": "^19.0",
"@types/react-dom": "^19.0",
"@types/validator": "^13.15.2",
"adnbn": "^0.2.7",
"adnbn": "^0.4.2",
"prettier": "^3.5.3"
},
"peerDependencies": {
"adnbn": ">=0.4.0",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"adnbn": ">=0.2.3"
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
}
}
31 changes: 28 additions & 3 deletions plugin/api.ts
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
import {getService as getServiceProxy} from "adnbn";
import {getEnv, getService as getServiceProxy} from "adnbn";
import {getService as getServiceOrigin} from "adnbn/service";

import {isBackground} from "@adnbn/browser";
import {isBackground} from "@addon-core/browser";

import {RemoteConfig} from "./types";
import isURL from "is-url";

import {RemoteConfig, RemoteConfigOptions} from "./types";

export const getRemoteConfig = async <T extends RemoteConfig = RemoteConfig>(): Promise<T> => {
const service = isBackground() ? getServiceOrigin : getServiceProxy;

return await service("@adnbn/plugin-remote-config/service").get();
};

export const getRemoteConfigOptions = (): RemoteConfigOptions => {
let options: Partial<RemoteConfigOptions> = {};

try {
//@ts-expect-error: __REMOTE_CONFIG_OPTIONS__ is a virtual variable generated by the bundler `plugin/index.ts`
options = __REMOTE_CONFIG_OPTIONS__;
} catch (e) {
console.error(
"Failed to load @adnbn/plugin-remote-config parameters. Make sure the plugin is properly configured in the adnbn configuration file."
);
}

let {url, ttl = 1440, config = {}} = options;

if (typeof url === "string") {
url = isURL(url) ? url : getEnv(url);
} else {
url = undefined;
}

return {ttl, config, url};
};
Loading