{"id":30230152,"url":"https://github.com/addonbone/plugin-remote-config","last_synced_at":"2025-08-14T22:16:50.377Z","repository":{"id":298588900,"uuid":"1000476184","full_name":"addonbone/plugin-remote-config","owner":"addonbone","description":"Remote configuration plugin for Addon Bone that provides cached JSON config fetching with fallback support for browser extensions.","archived":false,"fork":false,"pushed_at":"2025-08-14T16:50:45.000Z","size":397,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-14T18:33:21.721Z","etag":null,"topics":["api","browser","chrome","chrome-extension","config","edge","firefox","opera","remote","safari"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/addonbone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-11T21:04:15.000Z","updated_at":"2025-08-14T16:50:48.000Z","dependencies_parsed_at":"2025-08-14T18:33:26.275Z","dependency_job_id":"c85a51f7-356f-4661-ad90-9c716464747f","html_url":"https://github.com/addonbone/plugin-remote-config","commit_stats":null,"previous_names":["addonbone/remote-config-plugin","addonbone/plugin-remote-config"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/addonbone/plugin-remote-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addonbone%2Fplugin-remote-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addonbone%2Fplugin-remote-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addonbone%2Fplugin-remote-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addonbone%2Fplugin-remote-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/addonbone","download_url":"https://codeload.github.com/addonbone/plugin-remote-config/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addonbone%2Fplugin-remote-config/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270488766,"owners_count":24592454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-14T02:00:10.309Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","browser","chrome","chrome-extension","config","edge","firefox","opera","remote","safari"],"created_at":"2025-08-14T22:16:49.632Z","updated_at":"2025-08-14T22:16:50.371Z","avatar_url":"https://github.com/addonbone.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @adnbn/plugin-remote-config\n\n[![npm version](https://img.shields.io/npm/v/@adnbn/plugin-remote-config.svg)](https://www.npmjs.com/package/@adnbn/plugin-remote-config)\n[![npm downloads](https://img.shields.io/npm/dm/@adnbn/plugin-remote-config.svg)](https://www.npmjs.com/package/@adnbn/plugin-remote-config)\n\nRemote configuration plugin for [Addon Bone](https://github.com/addonbone).\n\n## Features\n\n- Fetch JSON configuration from a remote endpoint with transparent caching.\n- Configurable cache time-to-live (TTL) in minutes.\n- Fallback to default configuration on failure.\n- Access configuration in background scripts, content scripts, or service workers.\n- React context provider and hook for easy consumption in React apps.\n\n## Installation\n\nUsing npm:\n\n```bash\n npm install @adnbn/plugin-remote-config\n```\n\nUsing Yarn:\n\n```bash\n yarn add @adnbn/plugin-remote-config\n```\n\n## Usage\n\n### Plugin Configuration\n\nIn your Addon Bone config (e.g., `adnbn.config.ts`), register the plugin:\n\n```ts\nimport {defineConfig} from \"adnbn\";\nimport remoteConfig from \"@adnbn/plugin-remote-config\";\n\nexport default defineConfig({\n    plugins: [\n        remoteConfig({\n            url: \"https://example.com/config.json\", // or an env var name\n            ttl: 60, // cache TTL in minutes (default: 1440)\n            config: {\n                // default/fallback config\n                featureFlag: false,\n                apiEndpoint: \"https://api.example.com\",\n            },\n        }),\n    ],\n});\n```\n\n### Accessing Configuration\n\n#### In a content script, background, or any other extension layer\n\n```ts\nimport {getRemoteConfig} from \"@adnbn/plugin-remote-config/api\";\n\nasync function initialize() {\n    try {\n        const config = await getRemoteConfig\u003c{apiEndpoint: string; featureFlag: boolean}\u003e();\n        console.log(\"Remote config:\", config);\n    } catch (error) {\n        console.error(\"Failed to load remote config:\", error);\n    }\n}\n```\n\n#### In React\n\nWrap your application with the `RemoteConfigProvider`, then use the `useRemoteConfig` hook:\n\n```tsx\nimport React, {FC} from \"react\";\nimport ReactDOM from \"react-dom\";\nimport {RemoteConfigProvider} from \"@adnbn/plugin-remote-config/react\";\nimport App from \"./App\";\n\nconst Popup: FC = () =\u003e {\n    return (\n        \u003cRemoteConfigProvider\u003e\n            \u003cApp /\u003e\n        \u003c/RemoteConfigProvider\u003e\n    );\n};\n\nexport default Popup;\n```\n\n```tsx\nimport {useRemoteConfig} from \"@adnbn/plugin-remote-config/react\";\n\nfunction FeatureComponent() {\n    const {featureFlag, apiEndpoint} = useRemoteConfig();\n\n    return (\n        \u003cdiv\u003e\n            {featureFlag ? \u003cp\u003eNew feature enabled!\u003c/p\u003e : \u003cp\u003eFeature disabled.\u003c/p\u003e}\n            \u003cp\u003eAPI Endpoint: {apiEndpoint}\u003c/p\u003e\n        \u003c/div\u003e\n    );\n}\n```\n\n## Options\n\nThe plugin accepts the following options:\n\n- `url?: string` — Remote endpoint URL or an environment variable key resolving to a URL.\n- `ttl?: number` — Cache time-to-live in minutes. Defaults to `1440` (1 day).\n- `config: RemoteConfig` — Default configuration object used as fallback.\n\n## TypeScript Configuration\n\nTo enable proper TypeScript support and type safety for your configuration, you need to extend the `RemoteConfig` interface in your project.\n\n### Creating Type Definitions\n\nCreate a declaration file in your project (e.g., `types/config.d.ts` or `config.d.ts`) and extend the `RemoteConfig` interface:\n\n```typescript\nimport \"@adnbn/plugin-remote-config\";\n\ndeclare module \"@adnbn/plugin-remote-config\" {\n    interface RemoteConfig {\n        featureFlag: boolean;\n        apiEndpoint: string;\n        theme: \"light\" | \"dark\";\n        maxRetries: number;\n        endpoints: {\n            auth: string;\n            api: string;\n        };\n    }\n}\n```\n\n### Benefits of Type Definitions\n\nOnce you've defined your configuration types, you'll get:\n\n- **IntelliSense support** - Auto-completion for configuration properties\n- **Type checking** - Compile-time validation of configuration usage\n- **Refactoring safety** - Automatic updates when renaming properties\n\n### Usage with Types\n\nAfter defining your types, you can use the configuration with full type safety:\n\n```typescript\n// No need for generic type parameter anymore\nconst config = await getRemoteConfig();\nconsole.log(config.featureFlag); // ✅ TypeScript knows this is boolean\nconsole.log(config.apiEndpoint); // ✅ TypeScript knows this is string\nconsole.log(config.theme); // ✅ TypeScript knows this is 'light' | 'dark'\n```\n\n```tsx\n// In React components\nfunction MyComponent() {\n    const config = useRemoteConfig();\n\n    return (\n        \u003cdiv className={config.theme === \"dark\" ? \"dark-theme\" : \"light-theme\"}\u003e\n            {config.featureFlag \u0026\u0026 \u003cNewFeature /\u003e}\n        \u003c/div\u003e\n    );\n}\n```\n\n### Configuration Validation\n\nMake sure your default configuration in `adnbn.config.ts` matches your type definitions:\n\n```typescript\nexport default defineConfig({\n    plugins: [\n        remoteConfig({\n            url: \"https://example.com/config.json\",\n            ttl: 60,\n            config: {\n                featureFlag: false,\n                apiEndpoint: \"https://api.example.com\",\n                theme: \"light\",\n                maxRetries: 3,\n                endpoints: {\n                    auth: \"https://auth.example.com\",\n                    api: \"https://api.example.com\",\n                },\n            } satisfies RemoteConfig, // ✅ Type validation\n        }),\n    ],\n});\n```\n\n## License\n\nMIT © Addon Bone\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddonbone%2Fplugin-remote-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faddonbone%2Fplugin-remote-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddonbone%2Fplugin-remote-config/lists"}