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
5 changes: 5 additions & 0 deletions .changeset/remote-config-get-all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capacitor-firebase/remote-config': minor
---

feat: add `getAll()` method
31 changes: 31 additions & 0 deletions packages/remote-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const removeAllListeners = async () => {
* [`getBoolean(...)`](#getboolean)
* [`getNumber(...)`](#getnumber)
* [`getString(...)`](#getstring)
* [`getAll()`](#getall)
* [`getInfo()`](#getinfo)
* [`setMinimumFetchInterval(...)`](#setminimumfetchinterval)
* [`setDefaults(...)`](#setdefaults)
Expand Down Expand Up @@ -268,6 +269,21 @@ Get the value for the given key as a string.
--------------------


### getAll()

```typescript
getAll() => Promise<GetAllResult>
```

Get all the values from the Remote Config service.

**Returns:** <code>Promise&lt;<a href="#getallresult">GetAllResult</a>&gt;</code>

**Since:** 8.3.0

--------------------


### getInfo()

```typescript
Expand Down Expand Up @@ -432,6 +448,21 @@ Remove all listeners for this plugin.
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 |


#### GetAllResult

| Prop | Type | Description | Since |
| ------------ | ------------------------------------------------------------------------------------- | ------------------------ | ----- |
| **`values`** | <code>Record&lt;string, <a href="#getallresultvalue">GetAllResultValue</a>&gt;</code> | The values for all keys. | 8.3.0 |


#### GetAllResultValue

| Prop | Type | Description | Since |
| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- |
| **`value`** | <code>string</code> | The value as a string. | 8.3.0 |
| **`source`** | <code><a href="#getvaluesource">GetValueSource</a></code> | Indicates at which source this value came from. Only available for Android and iOS. | 8.3.0 |


#### GetInfoResult

| Prop | Type | Description | Since |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public GetValueResult<String> getString(String key) {
return new GetValueResult<String>(value.asString(), value.getSource());
}

public Map<String, FirebaseRemoteConfigValue> getAll() {
return getFirebaseRemoteConfigInstance().getAll();
}

public GetInfoResult getInfo() {
FirebaseRemoteConfigInfo info = getFirebaseRemoteConfigInstance().getInfo();
long lastFetchTime = info.getFetchTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
import io.capawesome.capacitorjs.plugins.firebase.remoteconfig.classes.options.AddConfigUpdateListenerOptions;
import io.capawesome.capacitorjs.plugins.firebase.remoteconfig.classes.options.RemoveConfigUpdateListenerOptions;
import io.capawesome.capacitorjs.plugins.firebase.remoteconfig.interfaces.NonEmptyResultCallback;
Expand Down Expand Up @@ -158,6 +159,27 @@ public void getString(PluginCall call) {
}
}

@PluginMethod
public void getAll(PluginCall call) {
try {
Map<String, FirebaseRemoteConfigValue> all = implementation.getAll();
JSObject values = new JSObject();
for (Map.Entry<String, FirebaseRemoteConfigValue> entry : all.entrySet()) {
FirebaseRemoteConfigValue value = entry.getValue();
JSObject valueObject = new JSObject();
valueObject.put("value", value.asString());
valueObject.put("source", value.getSource());
values.put(entry.getKey(), valueObject);
}
JSObject result = new JSObject();
result.put("values", values);
call.resolve(result);
} catch (Exception exception) {
Logger.error(TAG, exception.getMessage(), exception);
call.reject(exception.getMessage());
}
}

@PluginMethod
public void getInfo(PluginCall call) {
try {
Expand Down
12 changes: 12 additions & 0 deletions packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ import Capacitor
return RemoteConfig.remoteConfig().configValue(forKey: key)
}

@objc public func getAll() -> [String: RemoteConfigValue] {
let rc = RemoteConfig.remoteConfig()
var keys = Set<String>()
keys.formUnion(rc.allKeys(from: .remote))
keys.formUnion(rc.allKeys(from: .default))
var values: [String: RemoteConfigValue] = [:]
for key in keys {
values[key] = rc.configValue(forKey: key)
}
return values
}

@objc public func getInfo(completion: @escaping (Double, Int, String?) -> Void) {
let rc = RemoteConfig.remoteConfig()

Expand Down
15 changes: 15 additions & 0 deletions packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FirebaseRemoteConfigPlugin: CAPPlugin, CAPBridgedPlugin {
CAPPluginMethod(name: "getBoolean", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "getNumber", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "getString", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "getAll", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setMinimumFetchInterval", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setDefaults", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "setSettings", returnType: CAPPluginReturnPromise),
Expand Down Expand Up @@ -105,6 +106,20 @@ public class FirebaseRemoteConfigPlugin: CAPPlugin, CAPBridgedPlugin {
])
}

@objc func getAll(_ call: CAPPluginCall) {
let all = implementation?.getAll() ?? [:]
var values: [String: Any] = [:]
for (key, value) in all {
values[key] = [
"value": value.stringValue ?? "",
"source": FirebaseRemoteConfigHelper.mapRemoteConfigSourceToInt(value.source)
]
}
call.resolve([
"values": values
])
}

@objc func setMinimumFetchInterval(_ call: CAPPluginCall) {
call.reject("Not available on iOS.")
}
Expand Down
38 changes: 38 additions & 0 deletions packages/remote-config/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export interface FirebaseRemoteConfigPlugin {
* @since 1.3.0
*/
getString(options: GetStringOptions): Promise<GetStringResult>;
/**
* Get all the values from the Remote Config service.
*
* @since 8.3.0
*/
getAll(): Promise<GetAllResult>;
/**
* Get information about the last fetch operation.
*
Expand Down Expand Up @@ -198,6 +204,38 @@ export interface GetStringResult {
source?: GetValueSource;
}

/**
* @since 8.3.0
*/
export interface GetAllResult {
/**
* The values for all keys.
*
* @since 8.3.0
*/
values: Record<string, GetAllResultValue>;
}

/**
* @since 8.3.0
*/
export interface GetAllResultValue {
/**
* The value as a string.
*
* @since 8.3.0
*/
value: string;
/**
* Indicates at which source this value came from.
*
* Only available for Android and iOS.
*
* @since 8.3.0
*/
source?: GetValueSource;
}

/**
* @since 1.3.0
*/
Expand Down
13 changes: 13 additions & 0 deletions packages/remote-config/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
activate,
fetchAndActivate,
fetchConfig,
getAll,
getBoolean,
getNumber,
getRemoteConfig,
Expand All @@ -12,6 +13,8 @@
import type {
AddConfigUpdateListenerOptionsCallback,
FirebaseRemoteConfigPlugin,
GetAllResult,
GetAllResultValue,
GetBooleanResult,
GetInfoResult,
GetNumberResult,
Expand Down Expand Up @@ -61,6 +64,16 @@
return { value };
}

public async getAll(): Promise<GetAllResult> {
const remoteConfig = getRemoteConfig();
const all = getAll(remoteConfig);
const values: Record<string, GetAllResultValue> = {};
for (const key of Object.keys(all)) {
values[key] = { value: all[key].asString() };
}
return { values };
}

public async getInfo(): Promise<GetInfoResult> {
const remoteConfig = getRemoteConfig();

Expand Down Expand Up @@ -103,13 +116,13 @@
}

public async addConfigUpdateListener(
_callback: AddConfigUpdateListenerOptionsCallback,

Check warning on line 119 in packages/remote-config/src/web.ts

View workflow job for this annotation

GitHub Actions / Lint

'_callback' is defined but never used
): Promise<string> {
this.throwUnimplementedError();
}

public async removeConfigUpdateListener(
_options: RemoveConfigUpdateListenerOptions,

Check warning on line 125 in packages/remote-config/src/web.ts

View workflow job for this annotation

GitHub Actions / Lint

'_options' is defined but never used
): Promise<void> {
this.throwUnimplementedError();
}
Expand Down
Loading