diff --git a/.changeset/remote-config-get-all.md b/.changeset/remote-config-get-all.md new file mode 100644 index 000000000..f46c6f31d --- /dev/null +++ b/.changeset/remote-config-get-all.md @@ -0,0 +1,5 @@ +--- +'@capacitor-firebase/remote-config': minor +--- + +feat: add `getAll()` method diff --git a/packages/remote-config/README.md b/packages/remote-config/README.md index 8cb0ba7e2..a76b739ca 100644 --- a/packages/remote-config/README.md +++ b/packages/remote-config/README.md @@ -152,6 +152,7 @@ const removeAllListeners = async () => { * [`getBoolean(...)`](#getboolean) * [`getNumber(...)`](#getnumber) * [`getString(...)`](#getstring) +* [`getAll()`](#getall) * [`getInfo()`](#getinfo) * [`setMinimumFetchInterval(...)`](#setminimumfetchinterval) * [`setDefaults(...)`](#setdefaults) @@ -268,6 +269,21 @@ Get the value for the given key as a string. -------------------- +### getAll() + +```typescript +getAll() => Promise +``` + +Get all the values from the Remote Config service. + +**Returns:** Promise<GetAllResult> + +**Since:** 8.3.0 + +-------------------- + + ### getInfo() ```typescript @@ -432,6 +448,21 @@ Remove all listeners for this plugin. | **`source`** | GetValueSource | Indicates at which source this value came from. Only available for Android and iOS. | 1.3.0 | +#### GetAllResult + +| Prop | Type | Description | Since | +| ------------ | ------------------------------------------------------------------------------------- | ------------------------ | ----- | +| **`values`** | Record<string, GetAllResultValue> | The values for all keys. | 8.3.0 | + + +#### GetAllResultValue + +| Prop | Type | Description | Since | +| ------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ----- | +| **`value`** | string | The value as a string. | 8.3.0 | +| **`source`** | GetValueSource | Indicates at which source this value came from. Only available for Android and iOS. | 8.3.0 | + + #### GetInfoResult | Prop | Type | Description | Since | diff --git a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfig.java b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfig.java index 34c2c81a3..2e0187246 100644 --- a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfig.java +++ b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfig.java @@ -81,6 +81,10 @@ public GetValueResult getString(String key) { return new GetValueResult(value.asString(), value.getSource()); } + public Map getAll() { + return getFirebaseRemoteConfigInstance().getAll(); + } + public GetInfoResult getInfo() { FirebaseRemoteConfigInfo info = getFirebaseRemoteConfigInstance().getInfo(); long lastFetchTime = info.getFetchTimeMillis(); diff --git a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfigPlugin.java b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfigPlugin.java index 5cdc4dc35..80e84f3ec 100644 --- a/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfigPlugin.java +++ b/packages/remote-config/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/remoteconfig/FirebaseRemoteConfigPlugin.java @@ -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; @@ -158,6 +159,27 @@ public void getString(PluginCall call) { } } + @PluginMethod + public void getAll(PluginCall call) { + try { + Map all = implementation.getAll(); + JSObject values = new JSObject(); + for (Map.Entry 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 { diff --git a/packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift b/packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift index f56eb49ce..92355a45d 100644 --- a/packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift +++ b/packages/remote-config/ios/Plugin/FirebaseRemoteConfig.swift @@ -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() + 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() diff --git a/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift index 0f52cc510..4868d5820 100644 --- a/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift +++ b/packages/remote-config/ios/Plugin/FirebaseRemoteConfigPlugin.swift @@ -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), @@ -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.") } diff --git a/packages/remote-config/src/definitions.ts b/packages/remote-config/src/definitions.ts index e1b03bfac..3ccfa8325 100644 --- a/packages/remote-config/src/definitions.ts +++ b/packages/remote-config/src/definitions.ts @@ -35,6 +35,12 @@ export interface FirebaseRemoteConfigPlugin { * @since 1.3.0 */ getString(options: GetStringOptions): Promise; + /** + * Get all the values from the Remote Config service. + * + * @since 8.3.0 + */ + getAll(): Promise; /** * Get information about the last fetch operation. * @@ -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; +} + +/** + * @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 */ diff --git a/packages/remote-config/src/web.ts b/packages/remote-config/src/web.ts index 6902b0516..d1cbd2077 100644 --- a/packages/remote-config/src/web.ts +++ b/packages/remote-config/src/web.ts @@ -3,6 +3,7 @@ import { activate, fetchAndActivate, fetchConfig, + getAll, getBoolean, getNumber, getRemoteConfig, @@ -12,6 +13,8 @@ import { import type { AddConfigUpdateListenerOptionsCallback, FirebaseRemoteConfigPlugin, + GetAllResult, + GetAllResultValue, GetBooleanResult, GetInfoResult, GetNumberResult, @@ -61,6 +64,16 @@ export class FirebaseRemoteConfigWeb return { value }; } + public async getAll(): Promise { + const remoteConfig = getRemoteConfig(); + const all = getAll(remoteConfig); + const values: Record = {}; + for (const key of Object.keys(all)) { + values[key] = { value: all[key].asString() }; + } + return { values }; + } + public async getInfo(): Promise { const remoteConfig = getRemoteConfig();