@react-native-firebase/remote-config 24.1.0 → 25.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/android/src/reactnative/java/io/invertase/firebase/config/ReactNativeFirebaseConfigModule.java +11 -5
  3. package/dist/module/RemoteConfigValue.js +53 -0
  4. package/dist/module/RemoteConfigValue.js.map +1 -0
  5. package/dist/module/index.js +27 -0
  6. package/dist/module/index.js.map +1 -0
  7. package/dist/module/modular.js +155 -0
  8. package/dist/module/modular.js.map +1 -0
  9. package/dist/module/namespaced.js +400 -0
  10. package/dist/module/namespaced.js.map +1 -0
  11. package/dist/module/package.json +1 -0
  12. package/{lib → dist/module}/polyfills.js +26 -11
  13. package/dist/module/polyfills.js.map +1 -0
  14. package/dist/module/polyfills.web.js +3 -0
  15. package/dist/module/polyfills.web.js.map +1 -0
  16. package/{lib → dist/module}/statics.js +5 -3
  17. package/dist/module/statics.js.map +1 -0
  18. package/dist/module/types/internal.js +4 -0
  19. package/dist/module/types/internal.js.map +1 -0
  20. package/dist/module/types/namespaced.js +24 -0
  21. package/dist/module/types/namespaced.js.map +1 -0
  22. package/dist/module/types/remote-config.js +4 -0
  23. package/dist/module/types/remote-config.js.map +1 -0
  24. package/dist/module/version.js +5 -0
  25. package/dist/module/version.js.map +1 -0
  26. package/dist/module/web/RNFBConfigModule.android.js +6 -0
  27. package/dist/module/web/RNFBConfigModule.android.js.map +1 -0
  28. package/dist/module/web/RNFBConfigModule.ios.js +6 -0
  29. package/dist/module/web/RNFBConfigModule.ios.js.map +1 -0
  30. package/{lib → dist/module}/web/RNFBConfigModule.js +69 -77
  31. package/dist/module/web/RNFBConfigModule.js.map +1 -0
  32. package/dist/typescript/lib/RemoteConfigValue.d.ts +16 -0
  33. package/dist/typescript/lib/RemoteConfigValue.d.ts.map +1 -0
  34. package/dist/typescript/lib/index.d.ts +6 -0
  35. package/dist/typescript/lib/index.d.ts.map +1 -0
  36. package/dist/typescript/lib/modular.d.ts +76 -0
  37. package/dist/typescript/lib/modular.d.ts.map +1 -0
  38. package/dist/typescript/lib/namespaced.d.ts +11 -0
  39. package/dist/typescript/lib/namespaced.d.ts.map +1 -0
  40. package/dist/typescript/lib/polyfills.d.ts +2 -0
  41. package/dist/typescript/lib/polyfills.d.ts.map +1 -0
  42. package/dist/typescript/lib/polyfills.web.d.ts +1 -0
  43. package/dist/typescript/lib/polyfills.web.d.ts.map +1 -0
  44. package/dist/typescript/lib/statics.d.ts +12 -0
  45. package/dist/typescript/lib/statics.d.ts.map +1 -0
  46. package/dist/typescript/lib/types/internal.d.ts +94 -0
  47. package/dist/typescript/lib/types/internal.d.ts.map +1 -0
  48. package/dist/typescript/lib/types/namespaced.d.ts +124 -0
  49. package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
  50. package/dist/typescript/lib/types/remote-config.d.ts +37 -0
  51. package/dist/typescript/lib/types/remote-config.d.ts.map +1 -0
  52. package/dist/typescript/lib/version.d.ts +2 -0
  53. package/dist/typescript/lib/version.d.ts.map +1 -0
  54. package/dist/typescript/lib/web/RNFBConfigModule.android.d.ts +3 -0
  55. package/dist/typescript/lib/web/RNFBConfigModule.android.d.ts.map +1 -0
  56. package/dist/typescript/lib/web/RNFBConfigModule.d.ts +17 -0
  57. package/dist/typescript/lib/web/RNFBConfigModule.d.ts.map +1 -0
  58. package/dist/typescript/lib/web/RNFBConfigModule.ios.d.ts +3 -0
  59. package/dist/typescript/lib/web/RNFBConfigModule.ios.d.ts.map +1 -0
  60. package/dist/typescript/package.json +1 -0
  61. package/ios/RNFBConfig/RNFBConfigModule.m +10 -4
  62. package/lib/RemoteConfigValue.ts +66 -0
  63. package/lib/index.ts +25 -0
  64. package/lib/modular.ts +197 -0
  65. package/lib/namespaced.ts +552 -0
  66. package/lib/polyfills.ts +54 -0
  67. package/lib/statics.ts +27 -0
  68. package/lib/types/internal.ts +165 -0
  69. package/lib/types/namespaced.ts +163 -0
  70. package/lib/types/remote-config.ts +63 -0
  71. package/lib/version.ts +2 -0
  72. package/lib/web/RNFBConfigModule.android.ts +4 -0
  73. package/lib/web/RNFBConfigModule.ios.ts +4 -0
  74. package/lib/web/RNFBConfigModule.ts +254 -0
  75. package/package.json +42 -9
  76. package/tsconfig.json +21 -0
  77. package/typedoc.json +2 -3
  78. package/lib/RemoteConfigValue.js +0 -51
  79. package/lib/index.d.ts +0 -659
  80. package/lib/index.js +0 -400
  81. package/lib/modular/index.d.ts +0 -265
  82. package/lib/modular/index.js +0 -289
  83. package/lib/version.js +0 -2
  84. package/lib/web/RNFBConfigModule.android.js +0 -2
  85. package/lib/web/RNFBConfigModule.ios.js +0 -2
  86. /package/lib/{polyfills.web.js → polyfills.web.ts} +0 -0
@@ -0,0 +1,165 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import type {
19
+ ConfigUpdateObserver,
20
+ FetchStatus,
21
+ RemoteConfig,
22
+ RemoteConfigSettings,
23
+ Unsubscribe,
24
+ Value,
25
+ ValueSource,
26
+ } from './remote-config';
27
+ import type { FirebaseRemoteConfigTypes } from './namespaced';
28
+
29
+ export type ConfigValueSourceInternal = ValueSource;
30
+
31
+ export type LastFetchStatusInternal = FetchStatus;
32
+
33
+ export type RemoteConfigModularDeprecationArg = string;
34
+
35
+ export type WithRemoteConfigDeprecationArg<F> = F extends (...args: infer P) => infer R
36
+ ? (...args: [...P, RemoteConfigModularDeprecationArg?]) => R
37
+ : never;
38
+
39
+ export interface AppWithRemoteConfigInternal {
40
+ remoteConfig(deprecationArg?: RemoteConfigModularDeprecationArg): RemoteConfig;
41
+ }
42
+
43
+ export interface ConfigSettingsStateInternal {
44
+ fetchTimeoutMillis: number;
45
+ minimumFetchIntervalMillis: number;
46
+ }
47
+
48
+ export interface StoredConfigValueInternal {
49
+ value: string | number | boolean;
50
+ source: ConfigValueSourceInternal;
51
+ }
52
+
53
+ export interface NativeRemoteConfigConstants {
54
+ fetchTimeout?: number;
55
+ minimumFetchInterval?: number;
56
+ lastFetchTime?: number;
57
+ lastFetchStatus?: LastFetchStatusInternal;
58
+ values?: Record<string, StoredConfigValueInternal>;
59
+ }
60
+
61
+ export interface NativeRemoteConfigResult<T> {
62
+ result: T;
63
+ constants: NativeRemoteConfigConstants;
64
+ }
65
+
66
+ export interface RemoteConfigUpdateErrorInternal {
67
+ code?: string;
68
+ message?: string;
69
+ nativeErrorMessage?: string;
70
+ }
71
+
72
+ export interface RemoteConfigUpdateSuccessEventInternal {
73
+ resultType: 'success';
74
+ updatedKeys: string[];
75
+ }
76
+
77
+ export interface RemoteConfigUpdateErrorEventInternal extends RemoteConfigUpdateErrorInternal {
78
+ resultType?: string;
79
+ }
80
+
81
+ export interface RNFBConfigModule {
82
+ activate(): Promise<NativeRemoteConfigResult<boolean>>;
83
+ setConfigSettings(settings: {
84
+ fetchTimeout: number;
85
+ minimumFetchInterval: number;
86
+ }): Promise<NativeRemoteConfigResult<void>>;
87
+ fetch(expirationDurationSeconds: number): Promise<NativeRemoteConfigResult<void>>;
88
+ fetchAndActivate(): Promise<NativeRemoteConfigResult<boolean>>;
89
+ ensureInitialized(): Promise<NativeRemoteConfigResult<void>>;
90
+ setDefaults(
91
+ defaults: Record<string, string | number | boolean>,
92
+ ): Promise<NativeRemoteConfigResult<null>>;
93
+ setDefaultsFromResource(resourceName: string): Promise<NativeRemoteConfigResult<null>>;
94
+ reset(): Promise<NativeRemoteConfigResult<void>>;
95
+ onConfigUpdated(): void;
96
+ removeConfigUpdateRegistration(): void;
97
+ setCustomSignals(
98
+ customSignals: Record<string, string | number | null>,
99
+ ): Promise<NativeRemoteConfigResult<void>>;
100
+ }
101
+
102
+ export interface RemoteConfigInternal extends RemoteConfig {
103
+ settings: RemoteConfigSettings & {
104
+ fetchTimeMillis: number;
105
+ };
106
+ defaultConfig: {
107
+ [key: string]: string | number | boolean;
108
+ };
109
+ activate(deprecationArg?: RemoteConfigModularDeprecationArg): Promise<boolean>;
110
+ ensureInitialized(deprecationArg?: RemoteConfigModularDeprecationArg): Promise<void>;
111
+ fetchAndActivate(deprecationArg?: RemoteConfigModularDeprecationArg): Promise<boolean>;
112
+ fetch(
113
+ expirationDurationSeconds?: number,
114
+ deprecationArg?: RemoteConfigModularDeprecationArg,
115
+ ): Promise<void>;
116
+ getAll(deprecationArg?: RemoteConfigModularDeprecationArg): Record<string, Value>;
117
+ getBoolean(key: string, deprecationArg?: RemoteConfigModularDeprecationArg): boolean;
118
+ getNumber(key: string, deprecationArg?: RemoteConfigModularDeprecationArg): number;
119
+ getString(key: string, deprecationArg?: RemoteConfigModularDeprecationArg): string;
120
+ getValue(key: string, deprecationArg?: RemoteConfigModularDeprecationArg): Value;
121
+ reset(deprecationArg?: RemoteConfigModularDeprecationArg): Promise<void>;
122
+ setConfigSettings(
123
+ settings:
124
+ | RemoteConfigSettings
125
+ | {
126
+ minimumFetchIntervalMillis?: number;
127
+ fetchTimeMillis?: number;
128
+ fetchTimeoutMillis?: number;
129
+ },
130
+ deprecationArg?: RemoteConfigModularDeprecationArg,
131
+ ): Promise<void>;
132
+ setDefaults(
133
+ defaults: {
134
+ [key: string]: string | number | boolean;
135
+ },
136
+ deprecationArg?: RemoteConfigModularDeprecationArg,
137
+ ): Promise<null>;
138
+ setDefaultsFromResource(
139
+ resourceName: string,
140
+ deprecationArg?: RemoteConfigModularDeprecationArg,
141
+ ): Promise<null>;
142
+ onConfigUpdate(
143
+ observer: ConfigUpdateObserver,
144
+ deprecationArg?: RemoteConfigModularDeprecationArg,
145
+ ): Unsubscribe;
146
+ onConfigUpdated(
147
+ listenerOrObserver: FirebaseRemoteConfigTypes.CallbackOrObserver<FirebaseRemoteConfigTypes.OnConfigUpdatedListenerCallback>,
148
+ deprecationArg?: RemoteConfigModularDeprecationArg,
149
+ ): Unsubscribe;
150
+ readonly native: RNFBConfigModule;
151
+ _promiseWithConstants(
152
+ promise: Promise<NativeRemoteConfigResult<void>>,
153
+ deprecationArg?: RemoteConfigModularDeprecationArg,
154
+ ): Promise<void>;
155
+ _promiseWithConstants<T>(
156
+ promise: Promise<NativeRemoteConfigResult<T>>,
157
+ deprecationArg?: RemoteConfigModularDeprecationArg,
158
+ ): Promise<T>;
159
+ }
160
+
161
+ declare module '@react-native-firebase/app/dist/module/internal/NativeModules' {
162
+ interface ReactNativeFirebaseNativeModules {
163
+ RNFBConfigModule: RNFBConfigModule;
164
+ }
165
+ }
@@ -0,0 +1,163 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { ReactNativeFirebase } from '@react-native-firebase/app';
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-namespace
21
+ export namespace FirebaseRemoteConfigTypes {
22
+ import FirebaseModule = ReactNativeFirebase.FirebaseModule;
23
+
24
+ /**
25
+ * @deprecated Use modular log-level types instead.
26
+ */
27
+ export type RemoteConfigLogLevel = 'debug' | 'error' | 'silent';
28
+
29
+ /**
30
+ * @deprecated Use modular constants instead.
31
+ */
32
+ export interface LastFetchStatus {
33
+ SUCCESS: 'success';
34
+ FAILURE: 'failure';
35
+ THROTTLED: 'throttled';
36
+ NO_FETCH_YET: 'no_fetch_yet';
37
+ }
38
+
39
+ /**
40
+ * @deprecated Use modular constants instead.
41
+ */
42
+ export interface ValueSource {
43
+ REMOTE: 'remote';
44
+ DEFAULT: 'default';
45
+ STATIC: 'static';
46
+ }
47
+
48
+ /**
49
+ * @deprecated Namespaced statics remain for backwards compatibility.
50
+ */
51
+ export interface Statics {
52
+ ValueSource: ValueSource;
53
+ LastFetchStatus: LastFetchStatus;
54
+ SDK_VERSION: string;
55
+ }
56
+
57
+ /**
58
+ * @deprecated Use modular `Value` access patterns instead.
59
+ */
60
+ export interface ConfigValue {
61
+ getSource(): 'remote' | 'default' | 'static';
62
+ asBoolean(): true | false;
63
+ asNumber(): number;
64
+ asString(): string;
65
+ }
66
+
67
+ /**
68
+ * @deprecated Use modular APIs instead.
69
+ */
70
+ export interface ConfigValues {
71
+ [key: string]: ConfigValue;
72
+ }
73
+
74
+ /**
75
+ * @deprecated Use modular APIs instead.
76
+ */
77
+ export interface ConfigSettings {
78
+ minimumFetchIntervalMillis?: number;
79
+ fetchTimeMillis?: number;
80
+ }
81
+
82
+ /**
83
+ * @deprecated Use modular APIs instead.
84
+ */
85
+ export interface ConfigDefaults {
86
+ [key: string]: number | string | boolean;
87
+ }
88
+
89
+ export type LastFetchStatusType = 'success' | 'failure' | 'no_fetch_yet' | 'throttled';
90
+
91
+ export interface ConfigUpdate {
92
+ getUpdatedKeys(): Set<string>;
93
+ }
94
+
95
+ export interface ConfigUpdateObserver {
96
+ next: (configUpdate: ConfigUpdate) => void;
97
+ error: (error: ReactNativeFirebase.NativeFirebaseError) => void;
98
+ complete: () => void;
99
+ }
100
+
101
+ export type Unsubscribe = () => void;
102
+
103
+ /**
104
+ * @deprecated Use the package default export or modular APIs instead.
105
+ */
106
+ export declare class Module extends FirebaseModule {
107
+ app: ReactNativeFirebase.FirebaseApp;
108
+ fetchTimeMillis: number;
109
+ lastFetchStatus: LastFetchStatusType;
110
+ settings: ConfigSettings;
111
+ defaultConfig: ConfigDefaults;
112
+ setConfigSettings(configSettings: ConfigSettings): Promise<void>;
113
+ setDefaults(defaults: ConfigDefaults): Promise<null>;
114
+ setDefaultsFromResource(resourceName: string): Promise<null>;
115
+ onConfigUpdate(observer: ConfigUpdateObserver): Unsubscribe;
116
+ onConfigUpdated(listener: CallbackOrObserver<OnConfigUpdatedListenerCallback>): () => void;
117
+ activate(): Promise<boolean>;
118
+ ensureInitialized(): Promise<void>;
119
+ fetch(expirationDurationSeconds?: number): Promise<void>;
120
+ fetchAndActivate(): Promise<boolean>;
121
+ getAll(): ConfigValues;
122
+ getValue(key: string): ConfigValue;
123
+ getBoolean(key: string): boolean;
124
+ getString(key: string): string;
125
+ getNumber(key: string): number;
126
+ reset(): Promise<void>;
127
+ }
128
+
129
+ export type CallbackOrObserver<T extends (...args: any[]) => any> = T | { next: T };
130
+
131
+ export type OnConfigUpdatedListenerCallback = (
132
+ event?: { updatedKeys: string[] },
133
+ error?: {
134
+ code: string;
135
+ message: string;
136
+ nativeErrorMessage: string;
137
+ },
138
+ ) => void;
139
+ }
140
+
141
+ declare module '@react-native-firebase/app' {
142
+ // eslint-disable-next-line @typescript-eslint/no-namespace
143
+ namespace ReactNativeFirebase {
144
+ import FirebaseModuleWithStatics = ReactNativeFirebase.FirebaseModuleWithStatics;
145
+
146
+ interface Module {
147
+ /**
148
+ * @deprecated Use the package default export or modular APIs instead.
149
+ */
150
+ remoteConfig: FirebaseModuleWithStatics<
151
+ FirebaseRemoteConfigTypes.Module,
152
+ FirebaseRemoteConfigTypes.Statics
153
+ >;
154
+ }
155
+
156
+ interface FirebaseApp {
157
+ /**
158
+ * @deprecated Use the package default export or modular APIs instead.
159
+ */
160
+ remoteConfig(): FirebaseRemoteConfigTypes.Module;
161
+ }
162
+ }
163
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import type { FirebaseApp } from '@firebase/app';
19
+ import type { ReactNativeFirebase } from '@react-native-firebase/app';
20
+
21
+ export type LogLevel = 'debug' | 'error' | 'silent';
22
+
23
+ export type FetchStatus = 'success' | 'failure' | 'no_fetch_yet' | 'throttled';
24
+
25
+ export type ValueSource = 'static' | 'default' | 'remote';
26
+
27
+ export interface Value {
28
+ getSource(): ValueSource;
29
+ asBoolean(): boolean;
30
+ asNumber(): number;
31
+ asString(): string;
32
+ }
33
+
34
+ export interface RemoteConfigSettings {
35
+ minimumFetchIntervalMillis: number;
36
+ fetchTimeoutMillis: number;
37
+ }
38
+
39
+ export interface ConfigUpdate {
40
+ getUpdatedKeys(): Set<string>;
41
+ }
42
+
43
+ export interface ConfigUpdateObserver {
44
+ next: (configUpdate: ConfigUpdate) => void;
45
+ error: (error: ReactNativeFirebase.NativeFirebaseError) => void;
46
+ complete: () => void;
47
+ }
48
+
49
+ export type Unsubscribe = () => void;
50
+
51
+ export interface CustomSignals {
52
+ [key: string]: string | number | null;
53
+ }
54
+
55
+ export interface RemoteConfig {
56
+ app: FirebaseApp;
57
+ fetchTimeMillis: number;
58
+ lastFetchStatus: FetchStatus;
59
+ settings: RemoteConfigSettings;
60
+ defaultConfig: {
61
+ [key: string]: string | number | boolean;
62
+ };
63
+ }
package/lib/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Generated by genversion.
2
+ export const version = '25.0.0';
@@ -0,0 +1,4 @@
1
+ // No-op for android.
2
+ const noopNativeModule: Record<string, never> = {};
3
+
4
+ export default noopNativeModule;
@@ -0,0 +1,4 @@
1
+ // No-op for ios.
2
+ const noopNativeModule: Record<string, never> = {};
3
+
4
+ export default noopNativeModule;
@@ -0,0 +1,254 @@
1
+ import '../polyfills';
2
+ import {
3
+ activate,
4
+ ensureInitialized,
5
+ fetchAndActivate,
6
+ fetchConfig,
7
+ getAll,
8
+ getApp,
9
+ getRemoteConfig,
10
+ makeIDBAvailable,
11
+ onConfigUpdate,
12
+ setCustomSignals,
13
+ } from '@react-native-firebase/app/dist/module/internal/web/firebaseRemoteConfig';
14
+ import {
15
+ emitEvent,
16
+ getWebError,
17
+ guard,
18
+ } from '@react-native-firebase/app/dist/module/internal/web/utils';
19
+ import type { CustomSignals, RemoteConfig } from '../types/remote-config';
20
+ import type {
21
+ NativeRemoteConfigConstants,
22
+ NativeRemoteConfigResult,
23
+ RNFBConfigModule,
24
+ } from '../types/internal';
25
+
26
+ interface WebRemoteConfigSettings {
27
+ minimumFetchIntervalMillis: number;
28
+ fetchTimeoutMillis: number;
29
+ }
30
+
31
+ type WebRemoteConfigSettingsOverrides = Partial<WebRemoteConfigSettings>;
32
+ type WebRemoteConfig = ReturnType<typeof getRemoteConfig>;
33
+ type RemoteConfigWithWebSettings = WebRemoteConfig &
34
+ RemoteConfig & {
35
+ settings: WebRemoteConfig['settings'] & WebRemoteConfigSettings;
36
+ };
37
+
38
+ type ConfigSettingsForInstance = Partial<Record<string, WebRemoteConfigSettings>>;
39
+ type DefaultConfigForInstance = Partial<Record<string, Record<string, string | number | boolean>>>;
40
+ type ConfigUpdateListeners = Partial<Record<string, ReturnType<typeof onConfigUpdate>>>;
41
+
42
+ type WithAppName<F> = F extends (...args: infer P) => infer R
43
+ ? (appName: string, ...args: P) => R
44
+ : never;
45
+
46
+ interface RNFBConfigModuleWeb {
47
+ activate: WithAppName<RNFBConfigModule['activate']>;
48
+ setConfigSettings: WithAppName<RNFBConfigModule['setConfigSettings']>;
49
+ fetch: WithAppName<RNFBConfigModule['fetch']>;
50
+ fetchAndActivate: WithAppName<RNFBConfigModule['fetchAndActivate']>;
51
+ ensureInitialized: WithAppName<RNFBConfigModule['ensureInitialized']>;
52
+ setDefaults: WithAppName<RNFBConfigModule['setDefaults']>;
53
+ setCustomSignals: WithAppName<RNFBConfigModule['setCustomSignals']>;
54
+ onConfigUpdated: WithAppName<RNFBConfigModule['onConfigUpdated']>;
55
+ removeConfigUpdateRegistration: WithAppName<RNFBConfigModule['removeConfigUpdateRegistration']>;
56
+ }
57
+
58
+ const DEFAULT_CONFIG_SETTINGS: WebRemoteConfigSettings = {
59
+ minimumFetchIntervalMillis: 43200000,
60
+ fetchTimeoutMillis: 60000,
61
+ };
62
+
63
+ const configSettingsForInstance: ConfigSettingsForInstance = {};
64
+ const defaultConfigForInstance: DefaultConfigForInstance = {};
65
+ const onConfigUpdateListeners: ConfigUpdateListeners = {};
66
+
67
+ function makeGlobalsAvailable(): void {
68
+ (navigator as Navigator & { onLine: boolean }).onLine = true;
69
+ makeIDBAvailable();
70
+ }
71
+
72
+ function getRemoteConfigInstanceForApp(
73
+ appName: string,
74
+ overrides: WebRemoteConfigSettingsOverrides = {},
75
+ ): RemoteConfigWithWebSettings {
76
+ makeGlobalsAvailable();
77
+
78
+ const configSettings: WebRemoteConfigSettings = {
79
+ ...(configSettingsForInstance[appName] ?? DEFAULT_CONFIG_SETTINGS),
80
+ ...overrides,
81
+ };
82
+ const defaultConfig = defaultConfigForInstance[appName] ?? {};
83
+
84
+ const app = getApp(appName);
85
+ const instance = getRemoteConfig(app) as unknown as RemoteConfigWithWebSettings;
86
+
87
+ Object.assign(instance.settings, configSettings);
88
+ instance.defaultConfig = defaultConfig;
89
+
90
+ return instance;
91
+ }
92
+
93
+ function toLastFetchStatus(
94
+ status: string,
95
+ ): NonNullable<NativeRemoteConfigConstants['lastFetchStatus']> {
96
+ switch (status) {
97
+ case 'success':
98
+ case 'failure':
99
+ case 'no_fetch_yet':
100
+ case 'throttled':
101
+ return status;
102
+ case 'no-fetch-yet':
103
+ return 'no_fetch_yet';
104
+ case 'throttle':
105
+ return 'throttled';
106
+ default:
107
+ return 'no_fetch_yet';
108
+ }
109
+ }
110
+
111
+ function resultAndConstants<T>(
112
+ instance: RemoteConfigWithWebSettings,
113
+ result: T,
114
+ ): NativeRemoteConfigResult<T> {
115
+ const valuesRaw = getAll(instance);
116
+ const values: NonNullable<NativeRemoteConfigConstants['values']> = {};
117
+
118
+ for (const key in valuesRaw) {
119
+ const raw = valuesRaw[key];
120
+
121
+ if (raw) {
122
+ values[key] = {
123
+ source: raw.getSource(),
124
+ value: raw.asString(),
125
+ };
126
+ }
127
+ }
128
+
129
+ return {
130
+ result,
131
+ constants: {
132
+ values,
133
+ lastFetchTime: instance.fetchTimeMillis === -1 ? 0 : instance.fetchTimeMillis,
134
+ lastFetchStatus: toLastFetchStatus(instance.lastFetchStatus),
135
+ minimumFetchInterval: instance.settings.minimumFetchIntervalMillis
136
+ ? instance.settings.minimumFetchIntervalMillis / 1000
137
+ : 43200,
138
+ fetchTimeout: instance.settings.fetchTimeoutMillis
139
+ ? instance.settings.fetchTimeoutMillis / 1000
140
+ : 60,
141
+ },
142
+ };
143
+ }
144
+
145
+ const remoteConfigWebModule: RNFBConfigModuleWeb = {
146
+ activate(appName) {
147
+ return guard(async () => {
148
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
149
+ return resultAndConstants(remoteConfig, await activate(remoteConfig));
150
+ });
151
+ },
152
+
153
+ setConfigSettings(appName, settings) {
154
+ return guard(async () => {
155
+ const webSettings: WebRemoteConfigSettings = {
156
+ minimumFetchIntervalMillis: settings.minimumFetchInterval * 1000,
157
+ fetchTimeoutMillis: settings.fetchTimeout * 1000,
158
+ };
159
+
160
+ configSettingsForInstance[appName] = webSettings;
161
+
162
+ const remoteConfig = getRemoteConfigInstanceForApp(appName, webSettings);
163
+ return resultAndConstants(remoteConfig, undefined);
164
+ });
165
+ },
166
+
167
+ fetch(appName, expirationDurationSeconds) {
168
+ return guard(async () => {
169
+ const overrides: WebRemoteConfigSettingsOverrides = {};
170
+
171
+ if (expirationDurationSeconds !== -1) {
172
+ overrides.minimumFetchIntervalMillis = expirationDurationSeconds * 1000;
173
+ }
174
+
175
+ const remoteConfig = getRemoteConfigInstanceForApp(appName, overrides);
176
+ await fetchConfig(remoteConfig);
177
+
178
+ return resultAndConstants(remoteConfig, undefined);
179
+ });
180
+ },
181
+
182
+ fetchAndActivate(appName) {
183
+ return guard(async () => {
184
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
185
+ return resultAndConstants(remoteConfig, await fetchAndActivate(remoteConfig));
186
+ });
187
+ },
188
+
189
+ ensureInitialized(appName) {
190
+ return guard(async () => {
191
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
192
+ await ensureInitialized(remoteConfig);
193
+
194
+ return resultAndConstants(remoteConfig, undefined);
195
+ });
196
+ },
197
+
198
+ setDefaults(appName, defaults) {
199
+ return guard(async () => {
200
+ defaultConfigForInstance[appName] = defaults;
201
+
202
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
203
+ return resultAndConstants(remoteConfig, null);
204
+ });
205
+ },
206
+
207
+ setCustomSignals(appName, customSignals: CustomSignals) {
208
+ return guard(async () => {
209
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
210
+ await setCustomSignals(remoteConfig, customSignals);
211
+
212
+ return resultAndConstants(remoteConfig, undefined);
213
+ });
214
+ },
215
+
216
+ onConfigUpdated(appName) {
217
+ if (onConfigUpdateListeners[appName]) {
218
+ return;
219
+ }
220
+
221
+ const remoteConfig = getRemoteConfigInstanceForApp(appName);
222
+ const nativeObserver: Parameters<typeof onConfigUpdate>[1] = {
223
+ next(configUpdate) {
224
+ emitEvent('on_config_updated', {
225
+ appName,
226
+ resultType: 'success',
227
+ updatedKeys: Array.from(configUpdate.getUpdatedKeys()),
228
+ });
229
+ },
230
+ error(firebaseError) {
231
+ emitEvent('on_config_updated', {
232
+ appName,
233
+ event: getWebError(firebaseError),
234
+ });
235
+ },
236
+ complete() {},
237
+ };
238
+
239
+ onConfigUpdateListeners[appName] = onConfigUpdate(remoteConfig, nativeObserver);
240
+ },
241
+
242
+ removeConfigUpdateRegistration(appName) {
243
+ const unsubscribe = onConfigUpdateListeners[appName];
244
+
245
+ if (!unsubscribe) {
246
+ return;
247
+ }
248
+
249
+ unsubscribe();
250
+ delete onConfigUpdateListeners[appName];
251
+ },
252
+ };
253
+
254
+ export default remoteConfigWebModule;