Skip to content

Commit 24ac03f

Browse files
authored
Allow FCM to auto-generate typings, separate internal vs external APIs (#982)
1 parent 1984f1f commit 24ac03f

10 files changed

+1677
-701
lines changed

gulpfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ var paths = {
5656
'src/*.d.ts',
5757
'!src/instance-id.d.ts',
5858
'!src/security-rules.d.ts',
59-
'!src/project-management.d.ts'
59+
'!src/project-management.d.ts',
60+
'!src/messaging.d.ts',
6061
],
6162
};
6263

@@ -69,10 +70,9 @@ const TEMPORARY_TYPING_EXCLUDES = [
6970
'!lib/database/*.d.ts',
7071
'!lib/firestore/*.d.ts',
7172
'!lib/machine-learning/*.d.ts',
72-
'!lib/messaging/*.d.ts',
7373
'!lib/remote-config/*.d.ts',
7474
'!lib/storage/*.d.ts',
75-
'!lib/utils/*.d.ts'
75+
'!lib/utils/*.d.ts',
7676
];
7777

7878
// Create a separate project for buildProject that overrides the rootDir.

src/messaging/index.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*!
2+
* Copyright 2020 Google Inc.
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+
import { FirebaseApp } from '../firebase-app';
18+
import * as messagingApi from './messaging';
19+
import * as messagingTypesApi from './messaging-types';
20+
import * as firebaseAdmin from '../index';
21+
22+
export function messaging(app?: FirebaseApp): messagingApi.Messaging {
23+
if (typeof(app) === 'undefined') {
24+
app = firebaseAdmin.app();
25+
}
26+
return app.messaging();
27+
}
28+
29+
/**
30+
* We must define a namespace to make the typings work correctly. Otherwise
31+
* `admin.messaging()` cannot be called like a function. Temporarily,
32+
* admin.messaging is used as the namespace name because we cannot barrel
33+
* re-export the contents from messsaging, and we want it to
34+
* match the namespacing in the re-export inside src/index.d.ts
35+
*/
36+
/* eslint-disable @typescript-eslint/no-namespace */
37+
export namespace admin.messaging {
38+
// See https://github.com/microsoft/TypeScript/issues/4336
39+
/* eslint-disable @typescript-eslint/no-unused-vars */
40+
// See https://github.com/typescript-eslint/typescript-eslint/issues/363
41+
export import AndroidConfig = messagingTypesApi.AndroidConfig;
42+
export import AndroidFcmOptions = messagingTypesApi.AndroidFcmOptions;
43+
export import AndroidNotification = messagingTypesApi.AndroidNotification;
44+
export import ApnsConfig = messagingTypesApi.ApnsConfig;
45+
export import ApnsFcmOptions = messagingTypesApi.ApnsFcmOptions;
46+
export import ApnsPayload = messagingTypesApi.ApnsPayload;
47+
export import Aps = messagingTypesApi.Aps;
48+
export import ApsAlert = messagingTypesApi.ApsAlert;
49+
export import BatchResponse = messagingTypesApi.BatchResponse;
50+
export import CriticalSound = messagingTypesApi.CriticalSound;
51+
export import FcmOptions = messagingTypesApi.FcmOptions;
52+
export import LightSettings = messagingTypesApi.LightSettings;
53+
export import Message = messagingTypesApi.Message;
54+
export import MessagingTopicManagementResponse = messagingTypesApi.MessagingTopicManagementResponse;
55+
export import MulticastMessage = messagingTypesApi.MulticastMessage;
56+
export import Notification = messagingTypesApi.Notification;
57+
export import SendResponse = messagingTypesApi.SendResponse;
58+
export import WebpushConfig = messagingTypesApi.WebpushConfig;
59+
export import WebpushFcmOptions = messagingTypesApi.WebpushFcmOptions;
60+
export import WebpushNotification = messagingTypesApi.WebpushNotification;
61+
62+
// See https://github.com/microsoft/TypeScript/issues/4336
63+
// Allows for exposing classes as interfaces in typings
64+
/* eslint-disable @typescript-eslint/no-empty-interface */
65+
export interface Messaging extends messagingApi.Messaging {}
66+
67+
// Legacy API types.
68+
export import DataMessagePayload = messagingTypesApi.DataMessagePayload;
69+
export import MessagingConditionResponse = messagingTypesApi.MessagingConditionResponse;
70+
export import MessagingDeviceGroupResponse = messagingTypesApi.MessagingDeviceGroupResponse;
71+
export import MessagingDevicesResponse = messagingTypesApi.MessagingDevicesResponse;
72+
export import MessagingDeviceResult = messagingTypesApi.MessagingDeviceResult;
73+
export import MessagingOptions = messagingTypesApi.MessagingOptions;
74+
export import MessagingPayload = messagingTypesApi.MessagingPayload;
75+
export import MessagingTopicResponse = messagingTypesApi.MessagingTopicResponse;
76+
export import NotificationMessagePayload = messagingTypesApi.NotificationMessagePayload;
77+
}

src/messaging/messaging-api-request.ts renamed to src/messaging/messaging-api-request-internal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { FirebaseApp } from '../firebase-app';
1818
import {
1919
HttpMethod, AuthorizedHttpClient, HttpRequestConfig, HttpError, HttpResponse,
2020
} from '../utils/api-request';
21-
import { createFirebaseError, getErrorCode } from './messaging-errors';
22-
import { SubRequest, BatchRequestClient } from './batch-request';
21+
import { createFirebaseError, getErrorCode } from './messaging-errors-internal';
22+
import { SubRequest, BatchRequestClient } from './batch-request-internal';
2323
import { SendResponse, BatchResponse } from './messaging-types';
2424
import { getSdkVersion } from '../utils/index';
2525

0 commit comments

Comments
 (0)