Skip to content

Allow FCM to auto-generate typings, separate internal vs external APIs #982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
File renamed without changes.
41 changes: 41 additions & 0 deletions src/messaging/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*!
* Copyright 2020 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file 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.
*/

import { FirebaseApp } from '../firebase-app';
import * as messagingApi from './messaging';
import * as firebaseAdmin from '../index';

export function messaging(app?: FirebaseApp): messagingApi.Messaging {
if (typeof(app) === 'undefined') {
app = firebaseAdmin.app();
}
return app.messaging();
}

/**
* We must define a namespace to make the typings work correctly. Otherwise
* `admin.messaging()` cannot be called like a function. Temporarily,
* admin.messaging is used as the namespace name because we cannot barrel
* re-export the contents from messsaging, and we want it to
* match the namespacing in the re-export inside src/index.d.ts
*/
/* eslint-disable @typescript-eslint/no-namespace */
export namespace admin.messaging {
// See https://github.com/microsoft/TypeScript/issues/4336
// Allows for exposing classes as interfaces in typings
/* eslint-disable @typescript-eslint/no-empty-interface */
export interface Messaging extends messagingApi.Messaging {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { FirebaseApp } from '../firebase-app';
import {
HttpMethod, AuthorizedHttpClient, HttpRequestConfig, HttpError, HttpResponse,
} from '../utils/api-request';
import { createFirebaseError, getErrorCode } from './messaging-errors';
import { SubRequest, BatchRequestClient } from './batch-request';
import { createFirebaseError, getErrorCode } from './messaging-errors-internal';
import { SubRequest, BatchRequestClient } from './batch-request-internal';
import { SendResponse, BatchResponse } from './messaging-types';
import { getSdkVersion } from '../utils/index';

Expand All @@ -35,7 +35,6 @@ const LEGACY_FIREBASE_MESSAGING_HEADERS = {
'access_token_auth': 'true',
};


/**
* Class that provides a mechanism to send requests to the Firebase Cloud Messaging backend.
*/
Expand Down
23 changes: 23 additions & 0 deletions src/messaging/messaging-internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*!
* Copyright 2020 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file 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.
*/

// Keys which are not allowed in the messaging data payload object.
export const BLACKLISTED_DATA_PAYLOAD_KEYS = ['from'];

// Keys which are not allowed in the messaging options object.
export const BLACKLISTED_OPTIONS_KEYS = [
'condition', 'data', 'notification', 'registrationIds', 'registration_ids', 'to',
];
Loading