|
| 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 | +} |
0 commit comments