mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
Fix messaging being optional and isSupported type definitions (#793)
Fixes firebase.messaging() method being optional in TS types. Modifies isSupported so it is a namespace export and not a property on the factory function, which is not actually exported.
This commit is contained in:
committed by
GitHub
parent
f761f69e48
commit
9dd79f40c3
Vendored
+4
-7
@@ -107,7 +107,7 @@ declare namespace firebase {
|
||||
|
||||
function initializeApp(options: Object, name?: string): firebase.app.App;
|
||||
|
||||
const messaging: firebase.messaging.MessagingFactory;
|
||||
function messaging(app?: firebase.app.App): firebase.messaging.Messaging;
|
||||
|
||||
function storage(app?: firebase.app.App): firebase.storage.Storage;
|
||||
|
||||
@@ -121,7 +121,7 @@ declare namespace firebase.app {
|
||||
auth(): firebase.auth.Auth;
|
||||
database(): firebase.database.Database;
|
||||
delete(): Promise<any>;
|
||||
messaging: firebase.messaging.MessagingFactory;
|
||||
messaging(): firebase.messaging.Messaging;
|
||||
name: string;
|
||||
options: Object;
|
||||
storage(url?: string): firebase.storage.Storage;
|
||||
@@ -549,11 +549,6 @@ declare namespace firebase.database.ServerValue {
|
||||
}
|
||||
|
||||
declare namespace firebase.messaging {
|
||||
interface MessagingFactory {
|
||||
(app?: firebase.app.App): Messaging;
|
||||
isSupported(): boolean;
|
||||
}
|
||||
|
||||
interface Messaging {
|
||||
deleteToken(token: string): Promise<boolean>;
|
||||
getToken(): Promise<string | null>;
|
||||
@@ -574,6 +569,8 @@ declare namespace firebase.messaging {
|
||||
useServiceWorker(registration: ServiceWorkerRegistration): void;
|
||||
usePublicVapidKey(b64PublicKey: string): void;
|
||||
}
|
||||
|
||||
function isSupported(): boolean;
|
||||
}
|
||||
|
||||
declare namespace firebase.storage {
|
||||
|
||||
@@ -19,21 +19,16 @@ import {
|
||||
_FirebaseNamespace,
|
||||
FirebaseServiceFactory
|
||||
} from '@firebase/app-types/private';
|
||||
import { FirebaseMessaging } from '@firebase/messaging-types';
|
||||
|
||||
import { SwController } from './src/controllers/sw-controller';
|
||||
import { WindowController } from './src/controllers/window-controller';
|
||||
import { ERROR_CODES, errorFactory } from './src/models/errors';
|
||||
|
||||
import * as types from '@firebase/messaging-types';
|
||||
|
||||
export interface MessagingServiceFactory extends FirebaseServiceFactory {
|
||||
isSupported?(): boolean;
|
||||
}
|
||||
|
||||
export function registerMessaging(instance: _FirebaseNamespace): void {
|
||||
const messagingName = 'messaging';
|
||||
|
||||
const factoryMethod: MessagingServiceFactory = app => {
|
||||
const factoryMethod: FirebaseServiceFactory = app => {
|
||||
if (!isSupported()) {
|
||||
throw errorFactory.create(ERROR_CODES.UNSUPPORTED_BROWSER);
|
||||
}
|
||||
@@ -46,11 +41,9 @@ export function registerMessaging(instance: _FirebaseNamespace): void {
|
||||
return new WindowController(app);
|
||||
}
|
||||
};
|
||||
factoryMethod.isSupported = isSupported;
|
||||
|
||||
const namespaceExports = {
|
||||
// no-inline
|
||||
Messaging: WindowController
|
||||
isSupported
|
||||
};
|
||||
|
||||
instance.INTERNAL.registerService(
|
||||
@@ -67,13 +60,13 @@ registerMessaging(firebase as _FirebaseNamespace);
|
||||
*/
|
||||
declare module '@firebase/app-types' {
|
||||
interface FirebaseNamespace {
|
||||
messaging?: {
|
||||
(app?: FirebaseApp): types.FirebaseMessaging;
|
||||
Messaging: typeof types.FirebaseMessaging;
|
||||
messaging: {
|
||||
(app?: FirebaseApp): FirebaseMessaging;
|
||||
isSupported(): boolean;
|
||||
};
|
||||
}
|
||||
interface FirebaseApp {
|
||||
messaging?(): types.FirebaseMessaging;
|
||||
messaging(): FirebaseMessaging;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,12 @@ import { expect } from 'chai';
|
||||
import { sandbox, SinonSandbox, SinonStub } from 'sinon';
|
||||
|
||||
import { FirebaseApp } from '@firebase/app-types';
|
||||
import { _FirebaseNamespace } from '@firebase/app-types/private';
|
||||
import {
|
||||
_FirebaseNamespace,
|
||||
FirebaseServiceFactory
|
||||
} from '@firebase/app-types/private';
|
||||
|
||||
import { MessagingServiceFactory, registerMessaging } from '../index';
|
||||
import { registerMessaging } from '../index';
|
||||
import { ERROR_CODES } from '../src/models/errors';
|
||||
|
||||
import { SwController } from '../src/controllers/sw-controller';
|
||||
@@ -52,7 +55,7 @@ describe('Firebase Messaging > registerMessaging', () => {
|
||||
});
|
||||
|
||||
describe('factoryMethod', () => {
|
||||
let factoryMethod: MessagingServiceFactory;
|
||||
let factoryMethod: FirebaseServiceFactory;
|
||||
let fakeApp: FirebaseApp;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -65,8 +68,9 @@ describe('Firebase Messaging > registerMessaging', () => {
|
||||
});
|
||||
|
||||
describe('isSupported', () => {
|
||||
it('is a static method on factoryMethod', () => {
|
||||
expect(factoryMethod.isSupported).to.be.a('function');
|
||||
it('is a namespace export', () => {
|
||||
const namespaceExports = registerService.getCall(0).args[2];
|
||||
expect(namespaceExports.isSupported).to.be.a('function');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user