https://github.com/vodyani/apollo-client
🛸 携程 apollo 配置中心客户端。支持查询配置、订阅配置、使用开放中心提供的公共 API。
https://github.com/vodyani/apollo-client
apollo-client config-management nestjs npm remote-config-core
Last synced: 3 months ago
JSON representation
🛸 携程 apollo 配置中心客户端。支持查询配置、订阅配置、使用开放中心提供的公共 API。
- Host: GitHub
- URL: https://github.com/vodyani/apollo-client
- Owner: vodyani
- License: mit
- Created: 2022-09-27T07:12:27.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2025-06-29T16:03:08.000Z (4 months ago)
- Last Synced: 2025-06-29T17:19:38.171Z (4 months ago)
- Topics: apollo-client, config-management, nestjs, npm, remote-config-core
- Language: TypeScript
- Homepage: https://www.apolloconfig.com
- Size: 318 KB
- Stars: 30
- Watchers: 1
- Forks: 3
- Open Issues: 11
-
Metadata Files:
- Readme: README.MD
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Vodyani apollo-client
🛸 携程 apollo 配置中心客户端。支持查询配置、订阅配置、使用开放中心提供的公共 API。
[](https://www.npmjs.com/package/@vodyani/apollo-client)
[](https://www.npmjs.com/package/@vodyani/apollo-client)
[](https://www.npmjs.com/package/@vodyani/apollo-client)
[](LICENSE)
[](https://codecov.io/gh/vodyani/apollo-client)

[](https://github.com/semantic-release/semantic-release)## Installation
```sh
npm install @vodyani/apollo-client
```## Usage
*Base Usage*
- [ApolloHttpClient](#apollohttpclient)
- [getConfig](#apollohttpclient-getconfig)
- [getConfigByCache](#apollohttpclient-getconfigbycache)
- [getConfigNotifications](#apollohttpclient-getconfignotifications)
- [ApolloThirdPartyHttpClient](#apollothirdpartyhttpclient)
- [getConfig](#apollothirdpartyhttpclient-getconfig)
- [saveConfig](#apollothirdpartyhttpclient-saveconfig)
- [deleteConfig](#apollothirdpartyhttpclient-deleteconfig)
- [publishConfig](#apollothirdpartyhttpclient-publishconfig)
- [Supported Configuration types](#supported-configuration-types)*Advanced Usage*
- [Use With Config Observer](https://github.com/vodyani/apollo-client/tree/master/sample/use-with-config-observer.ts)
- [Use With Ark Manager](https://github.com/vodyani/apollo-client/tree/master/sample/use-with-ark-manager.ts)
- [Use With Dependency injection (Recommendation ⭐️)](https://github.com/vodyani/apollo-client/tree/master/sample/use-with-ark.ts)### ApolloHttpClient
```ts
import { ApolloHttpClient } from '@vodyani/apollo-client'const options = {
appId: 'your_apollo_app_id',
configServerUrl: 'your_apollo_config_server_url',
clusterName: 'your_apollo_cluster_name',
currentIp: 'your_server_ip',
secret: 'your_apollo_app_secret',
};const httpClient = new ApolloHttpClient(options);
```**options**
- appId (require: ✅) apollo app id
- configServerUrl (require: ✅) apollo config server url
- clusterName (require: ❎) apollo app cluster name
- currentIp (require: ❎) your server ip
- secret (require: ❎) apollo app secret#### ApolloHttpClient getConfig
```ts
const result = await httpClient.getConfig(
'your_apollo_namespace',
'properties'
)
```**params**
- namespace `string` apollo app namespace. (require: ✅)
- type [`NamespaceType`](#supported-configuration-types) apollo app namespace type. (require: ✅)**return**
```ts
{
'your_apollo_namespace_key': 'your_apollo_namespace_value'
}
```- *Other than txt, which returns text, all formats are deserialized as objects.*
#### ApolloHttpClient getConfigByCache
> Call this method to access cached data.
```ts
const result = await httpClient.getConfigByCache(
'your_apollo_namespace',
'properties',
)
```**params**
- namespace `string` apollo app namespace. (require: ✅)
- type [`NamespaceType`](#supported-configuration-types) apollo app namespace type. (require: ✅)**return**
```ts
{
'your_apollo_namespace_key': 'your_apollo_namespace_value'
}
```- *Other than txt, which returns text, all formats are deserialized as objects.*
#### ApolloHttpClient getConfigNotifications
> Call this method to initiate a long poll that listens to the specified namespace and receives updates back from the server.
```ts
const result = await httpClient.getConfigNotifications([
{
namespace: 'your_apollo_namespace',
type: 'properties',
}
])
```**params**
- namespace `string` apollo app namespace. (require: ✅)
- type [`NamespaceType`](#supported-configuration-types) apollo app namespace type. (require: ✅)**return**
```ts
[
{
namespaceName: 'your_apollo_namespace_name';
notificationId: 'your_apollo_notify_id',
},
]
```### ApolloThirdPartyHttpClient
```ts
import { ApolloThirdPartyHttpClient } from '@vodyani/apollo-client'const options = {
appId: 'your_apollo_app_id',
clusterName: 'your_apollo_cluster_name',
env: 'your_apollo_env',
secret: 'your_apollo_app_secret',
token: 'your_apollo_open_api_token',
portalServerUrl: 'your_apollo_portal_server_url',
operator: 'your_apollo_open_api_operator_user_name',
};const thirdPartyOptions = new ApolloThirdPartyHttpClient(options);
```**options**
- appId (require: ✅) apollo app id
- env (require: ✅) apollo env
- token (require: ✅) apollo app open api token
- portalServerUrl (require: ✅) apollo portal server url
- operator (require: ✅) apollo open api operator user name
- clusterName (require: ❎) apollo app cluster name#### ApolloThirdPartyHttpClient getConfig
```ts
const result = await thirdPartyOptions.getConfig(
'your_apollo_namespace',
'properties',
'your_apollo_namespace_property'
)const result = await thirdPartyOptions.getConfig(
'your_apollo_namespace',
'json'
)
```**params**
- namespace `string` apollo app namespace. (require: ✅)
- type [`NamespaceType`](#supported-configuration-types) apollo app namespace type. (require: ✅)
- key `string` apollo app namespace property, this parameter is mandatory only when type `properties` is queried**return**
```ts
{
'your_apollo_namespace_key': 'your_apollo_namespace_value'
}
```#### ApolloThirdPartyHttpClient saveConfig
> If you need to publish the configuration, don't forget to call it after execution `publishConfig`
```ts
const result = await thirdPartyOptions.saveConfig(
'your_apollo_namespace',
'properties',
'your_apollo_namespace_property'
)const result = await thirdPartyOptions.saveConfig(
'your_apollo_namespace',
'json'
)
```**params**
- namespace `string` apollo app namespace. (require: ✅)
- type [`NamespaceType`](#supported-configuration-types) apollo app namespace type. (require: ✅)
- key `string` apollo app namespace property, this parameter is mandatory only when type `properties` is queried**return**
void#### ApolloThirdPartyHttpClient deleteConfig
> If you need to publish the configuration, don't forget to call it after execution `publishConfig`
```ts
const result = await thirdPartyOptions.deleteConfig(
'your_apollo_namespace',
'properties',
'your_apollo_namespace_property'
)const result = await thirdPartyOptions.deleteConfig(
'your_apollo_namespace',
'json'
)
```**params**
- namespace `string` apollo app namespace. (require: ✅)
- type [`NamespaceType`](#supported-configuration-types) apollo app namespace type. (require: ✅)
- key `string` apollo app namespace property, this parameter is mandatory only when type `properties` is queried**return**
void#### ApolloThirdPartyHttpClient publishConfig
```ts
const result = await thirdPartyOptions.publishConfig(
'your_apollo_namespace',
'properties'
)const result = await thirdPartyOptions.publishConfig(
'your_apollo_namespace',
'json'
)
```**params**
- namespace `string` apollo app namespace. (require: ✅)
- type [`NamespaceType`](#supported-configuration-types) apollo app namespace type. (require: ✅)**return**
void### Supported Configuration types
- properties ✅
- yaml ✅
- yml ✅
- json ✅
- txt ✅
- xml ❎## Questions
- [Discussions 🧐](https://github.com/vodyani/apollo-client/discussions)
## Team
|[](https://github.com/chogathK)|
|:-:|
|[ChoGathK](https://github.com/chogathK)|
## License
Vodyani apollo-client is [MIT licensed](LICENSE).