Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bd49d05
refactor: first step to TS, package.json
russellwheatley Dec 2, 2025
e5a3672
refactor: create tsconfig.json for app package
russellwheatley Dec 2, 2025
0fdeb1e
refactor: move from JS to TS
russellwheatley Dec 2, 2025
bf7c589
refactor: further internal TS changes
russellwheatley Dec 2, 2025
7901610
refactor: internal TS implementation
russellwheatley Dec 2, 2025
0787c4a
fix: script to get version for generating versions natively
russellwheatley Dec 2, 2025
066f2d5
yarn.lock
russellwheatley Dec 2, 2025
7bd7705
fix: keep internal types internal
russellwheatley Dec 2, 2025
f9c9dc6
fix: other package TS config causing TS to output in app lib/ directory
russellwheatley Dec 3, 2025
6ec3871
fix: use types for app native module
russellwheatley Dec 3, 2025
6ffeb5e
fix: FirebaseModule types
russellwheatley Dec 3, 2025
dbbf9af
fix: FirebaseApp types
russellwheatley Dec 3, 2025
0126b84
fix: NativeModules types
russellwheatley Dec 3, 2025
d5b7c3f
fix: registry/nativeModule types
russellwheatley Dec 3, 2025
062218b
fix: update namespace types
russellwheatley Dec 3, 2025
0282cce
fix: native module types
russellwheatley Dec 3, 2025
423f30c
fix: improve native module types
russellwheatley Dec 3, 2025
34bec7b
refactor: ensure internals are on internal path
russellwheatley Dec 3, 2025
11e1e77
refactor: move to modular.ts
russellwheatley Dec 3, 2025
32e0b74
fix: remove incorrect imports
russellwheatley Dec 4, 2025
363723b
fix: metro updates to ensure compiled code is used
russellwheatley Dec 4, 2025
6b22a1f
chore: remove internal types
russellwheatley Dec 4, 2025
b3f4aae
fix: update export paths from app
russellwheatley Dec 4, 2025
a32908e
chore: fix test import
russellwheatley Dec 4, 2025
c847c2c
chore: delete index.d.ts
russellwheatley Dec 5, 2025
a2012cd
chore: remove unneeded types
russellwheatley Dec 5, 2025
36992e1
chore: remove import
russellwheatley Dec 5, 2025
d359f0c
Merge branch 'analytics-typescript' into app-typescript
russellwheatley Dec 5, 2025
deb281d
refactor: remove types and create internal types
russellwheatley Dec 5, 2025
488c869
Merge branch 'analytics-typescript' into app-typescript
russellwheatley Dec 8, 2025
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
12 changes: 6 additions & 6 deletions packages/ai/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"lib": [
"ESNext"
],
"lib": ["ESNext"],
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Bundler",
Expand All @@ -24,9 +22,11 @@
"strict": true,
"baseUrl": ".",
"paths": {
"@react-native-firebase/app": ["../app/lib"],
"@react-native-firebase/app": ["../app/dist/typescript/commonjs/lib"],
"@react-native-firebase/auth": ["../auth/lib"],
"@react-native-firebase/app-check": ["../app-check/lib"],
"@react-native-firebase/app-check": ["../app-check/lib"]
}
}
},
"include": ["lib/**/*"],
"exclude": ["node_modules", "dist", "__tests__", "**/*.test.ts"]
}
61 changes: 61 additions & 0 deletions packages/analytics/lib/internal-types/native-modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/**
* Internal type definitions for the Analytics native module.
* This file augments the base ReactNativeFirebaseNativeModules interface
* to add analytics-specific native methods.
*
* @internal - This file is not exposed to package consumers
*/

import type { ConsentSettings } from './types/analytics';

/**
* Interface for the Analytics native module methods
*/
export interface RNFBAnalyticsModuleInterface {
logEvent(name: string, params: { [key: string]: any }): Promise<void>;
setAnalyticsCollectionEnabled(enabled: boolean): Promise<void>;
setSessionTimeoutDuration(milliseconds: number): Promise<void>;
getAppInstanceId(): Promise<string | null>;
getSessionId(): Promise<number | null>;
setUserId(id: string | null): Promise<void>;
setUserProperty(name: string, value: string | null): Promise<void>;
setUserProperties(properties: { [key: string]: string | null }): Promise<void>;
resetAnalyticsData(): Promise<void>;
setConsent(consentSettings: ConsentSettings): Promise<void>;
setDefaultEventParameters(params: { [key: string]: any } | null | undefined): Promise<void>;
initiateOnDeviceConversionMeasurementWithEmailAddress(emailAddress: string): Promise<void>;
initiateOnDeviceConversionMeasurementWithHashedEmailAddress(
hashedEmailAddress: string,
): Promise<void>;
initiateOnDeviceConversionMeasurementWithPhoneNumber(phoneNumber: string): Promise<void>;
initiateOnDeviceConversionMeasurementWithHashedPhoneNumber(
hashedPhoneNumber: string,
): Promise<void>;
}

/**
* Augment the base ReactNativeFirebaseNativeModules interface
* from the app package to include our analytics module
*/
declare module '@react-native-firebase/app/lib/internal/NativeModules' {
interface ReactNativeFirebaseNativeModules {
RNFBAnalyticsModule: RNFBAnalyticsModuleInterface;
}
}
52 changes: 52 additions & 0 deletions packages/analytics/lib/internal-types/web-modules.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/**
* Type declarations for web-only modules from the app package.
* These modules are JavaScript files with separate .d.ts declarations.
*
* @internal - This file is not exposed to package consumers
*/

declare module '@react-native-firebase/app/lib/internal/web/firebaseApp' {
import type { ReactNativeFirebase } from '@react-native-firebase/app';

export function getApp(appName?: string): ReactNativeFirebase.FirebaseApp;
}

declare module '@react-native-firebase/app/lib/internal/web/utils' {
export function guard<T>(fn: () => T | Promise<T>): Promise<T>;
}

declare module '@react-native-firebase/app/lib/internal/web/firebaseInstallations' {
import type { ReactNativeFirebase } from '@react-native-firebase/app';

export interface Installations {
app: ReactNativeFirebase.FirebaseApp;
}

export type Unsubscribe = () => void;

export function getApp(appName?: string): ReactNativeFirebase.FirebaseApp;
export function getInstallations(app?: ReactNativeFirebase.FirebaseApp): Installations;
export function getId(installations: Installations): Promise<string>;
export function onIdChange(
installations: Installations,
callback: (installationId: string) => void,
): Unsubscribe;
export function makeIDBAvailable(): void;
}
16 changes: 10 additions & 6 deletions packages/analytics/lib/namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
import { ReactNativeFirebase } from '@react-native-firebase/app';
import type { ReactNativeFirebase } from '@react-native-firebase/app';
import {
isAlphaNumericUnderscore,
isE164PhoneNumber,
Expand All @@ -37,6 +37,10 @@ import {
import { setReactNativeModule } from '@react-native-firebase/app/lib/internal/nativeModule';
import { isBoolean } from '@react-native-firebase/app/lib/common';

// Import internal types to register native module augmentation
import './internal-types/native-modules';
import './internal-types/web-modules';

import { validateStruct, validateCompound } from './struct';
import { RNFBAnalyticsModule } from './web/RNFBAnalyticsModule';
import { version } from './version';
Expand Down Expand Up @@ -120,7 +124,7 @@ const namespace = 'analytics';

const nativeModuleName = 'RNFBAnalyticsModule';

class FirebaseAnalyticsModule extends FirebaseModule {
class FirebaseAnalyticsModule extends FirebaseModule<'RNFBAnalyticsModule'> {
logEvent(
name: string,
params: { [key: string]: any } = {},
Expand Down Expand Up @@ -879,13 +883,13 @@ export default createModuleNamespace({
hasMultiAppSupport: false,
hasCustomUrlOrRegionSupport: false,
ModuleClass: FirebaseAnalyticsModule,
}) as typeof defaultExport;
}) as unknown as typeof defaultExport;

// Register the interop module for non-native platforms.
setReactNativeModule(nativeModuleName, RNFBAnalyticsModule);
setReactNativeModule(nativeModuleName, RNFBAnalyticsModule as unknown as Record<string, unknown>);

export const firebase: FirebaseAnalyticsModule & {
export const firebase = getFirebaseRoot() as unknown as typeof defaultExport & {
analytics: typeof defaultExport;
SDK_VERSION: string;
app(name?: string): ReactNativeFirebase.FirebaseApp & { analytics(): FirebaseAnalyticsModule };
} = getFirebaseRoot();
};
97 changes: 0 additions & 97 deletions packages/analytics/lib/types.d.ts

This file was deleted.

12 changes: 10 additions & 2 deletions packages/analytics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@
"baseUrl": ".",
"rootDir": ".",
"paths": {
"@react-native-firebase/app/common/*": ["../app/lib/common/*"],
"@react-native-firebase/app": ["../app/lib"]
"@react-native-firebase/app/lib/common/*": ["../app/dist/typescript/commonjs/lib/common/*"],
"@react-native-firebase/app/lib/common": ["../app/dist/typescript/commonjs/lib/common"],
"@react-native-firebase/app/lib/internal/web/*": [
"../app/dist/typescript/commonjs/lib/internal/web/*"
],
"@react-native-firebase/app/lib/internal/*": [
"../app/dist/typescript/commonjs/lib/internal/*"
],
"@react-native-firebase/app/lib/internal": ["../app/dist/typescript/commonjs/lib/internal"],
"@react-native-firebase/app": ["../app/dist/typescript/commonjs/lib"]
}
},
"include": ["lib/**/*"],
Expand Down
43 changes: 31 additions & 12 deletions packages/app/lib/FirebaseApp.js → packages/app/lib/FirebaseApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,26 @@
* limitations under the License.
*
*/
import { warnIfNotModularCall } from '@react-native-firebase/app/lib/common';
import { warnIfNotModularCall } from './common';
import { getAppModule } from './internal/registry/nativeModule';
import type { ReactNativeFirebase, Utils } from './types';

export default class FirebaseApp {
constructor(options, appConfig, fromNative, deleteApp) {
const { name, automaticDataCollectionEnabled } = appConfig;
export default class FirebaseApp implements ReactNativeFirebase.FirebaseApp {
private _name: string;
private _deleted: boolean;
private _deleteApp: () => Promise<void>;
private _options: ReactNativeFirebase.FirebaseAppOptions;
private _automaticDataCollectionEnabled: boolean;
_initialized: boolean;
_nativeInitialized: boolean;

constructor(
options: ReactNativeFirebase.FirebaseAppOptions,
appConfig: ReactNativeFirebase.FirebaseAppConfig,
fromNative: boolean,
deleteApp: () => Promise<void>,
) {
const { name = '[DEFAULT]', automaticDataCollectionEnabled } = appConfig;

this._name = name;
this._deleted = false;
Expand All @@ -36,44 +50,49 @@ export default class FirebaseApp {
}
}

get name() {
get name(): string {
return this._name;
}

get options() {
get options(): ReactNativeFirebase.FirebaseAppOptions {
return Object.assign({}, this._options);
}

get automaticDataCollectionEnabled() {
get automaticDataCollectionEnabled(): boolean {
return this._automaticDataCollectionEnabled;
}

set automaticDataCollectionEnabled(enabled) {
set automaticDataCollectionEnabled(enabled: boolean) {
this._checkDestroyed();
getAppModule().setAutomaticDataCollectionEnabled(this.name, enabled);
this._automaticDataCollectionEnabled = enabled;
}

_checkDestroyed() {
private _checkDestroyed(): void {
if (this._deleted) {
throw new Error(`Firebase App named '${this._name}' already deleted`);
}
}

extendApp(extendedProps) {
extendApp(extendedProps: Record<string, unknown>): void {
warnIfNotModularCall(arguments);
this._checkDestroyed();
Object.assign(this, extendedProps);
}

delete() {
delete(): Promise<void> {
warnIfNotModularCall(arguments, 'deleteApp()');
this._checkDestroyed();
return this._deleteApp();
}

toString() {
toString(): string {
warnIfNotModularCall(arguments, '.name property');
return this.name;
}

// For backward compatibility - utils method added by registry
utils(): Utils.Module {
throw new Error('utils() should be added by registry');
}
}
Loading
Loading