initial commit
This commit is contained in:
53
server/node_modules/firebase-admin/lib/messaging/index.d.ts
generated
vendored
Normal file
53
server/node_modules/firebase-admin/lib/messaging/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* 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.
|
||||
*/
|
||||
/**
|
||||
* Firebase Cloud Messaging (FCM).
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
import { App } from '../app';
|
||||
import { Messaging } from './messaging';
|
||||
export { Messaging, } from './messaging';
|
||||
export { AndroidConfig, AndroidFcmOptions, AndroidNotification, ApnsConfig, ApnsFcmOptions, ApnsPayload, Aps, ApsAlert, BaseMessage, BatchResponse, CriticalSound, ConditionMessage, FcmOptions, LightSettings, Message, MessagingTopicManagementResponse, MulticastMessage, Notification, SendResponse, TokenMessage, TopicMessage, WebpushConfig, WebpushFcmOptions, WebpushNotification, DataMessagePayload, MessagingOptions, MessagingPayload, NotificationMessagePayload, } from './messaging-api';
|
||||
/**
|
||||
* Gets the {@link Messaging} service for the default app or a given app.
|
||||
*
|
||||
* `admin.messaging()` can be called with no arguments to access the default
|
||||
* app's `Messaging` service or as `admin.messaging(app)` to access the
|
||||
* `Messaging` service associated with aspecific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Messaging service for the default app
|
||||
* const defaultMessaging = getMessaging();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Messaging service for a given app
|
||||
* const otherMessaging = getMessaging(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app whose `Messaging` service to
|
||||
* return. If not provided, the default `Messaging` service will be returned.
|
||||
*
|
||||
* @returns The default `Messaging` service if no
|
||||
* app is provided or the `Messaging` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
export declare function getMessaging(app?: App): Messaging;
|
||||
export { FirebaseMessagingError, MessagingClientErrorCode } from '../utils/error';
|
||||
65
server/node_modules/firebase-admin/lib/messaging/index.js
generated
vendored
Normal file
65
server/node_modules/firebase-admin/lib/messaging/index.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.MessagingClientErrorCode = exports.FirebaseMessagingError = exports.Messaging = void 0;
|
||||
exports.getMessaging = getMessaging;
|
||||
/**
|
||||
* Firebase Cloud Messaging (FCM).
|
||||
*
|
||||
* @packageDocumentation
|
||||
*/
|
||||
const app_1 = require("../app");
|
||||
const messaging_1 = require("./messaging");
|
||||
var messaging_2 = require("./messaging");
|
||||
Object.defineProperty(exports, "Messaging", { enumerable: true, get: function () { return messaging_2.Messaging; } });
|
||||
/**
|
||||
* Gets the {@link Messaging} service for the default app or a given app.
|
||||
*
|
||||
* `admin.messaging()` can be called with no arguments to access the default
|
||||
* app's `Messaging` service or as `admin.messaging(app)` to access the
|
||||
* `Messaging` service associated with aspecific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Messaging service for the default app
|
||||
* const defaultMessaging = getMessaging();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Messaging service for a given app
|
||||
* const otherMessaging = getMessaging(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app whose `Messaging` service to
|
||||
* return. If not provided, the default `Messaging` service will be returned.
|
||||
*
|
||||
* @returns The default `Messaging` service if no
|
||||
* app is provided or the `Messaging` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
function getMessaging(app) {
|
||||
if (typeof app === 'undefined') {
|
||||
app = (0, app_1.getApp)();
|
||||
}
|
||||
const firebaseApp = app;
|
||||
return firebaseApp.getOrInitService('messaging', (app) => new messaging_1.Messaging(app));
|
||||
}
|
||||
var error_1 = require("../utils/error");
|
||||
Object.defineProperty(exports, "FirebaseMessagingError", { enumerable: true, get: function () { return error_1.FirebaseMessagingError; } });
|
||||
Object.defineProperty(exports, "MessagingClientErrorCode", { enumerable: true, get: function () { return error_1.MessagingClientErrorCode; } });
|
||||
61
server/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.d.ts
generated
vendored
Normal file
61
server/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 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 { App } from '../app';
|
||||
import { Http2SessionHandler } from '../utils/api-request';
|
||||
import { SendResponse } from './messaging-api';
|
||||
/**
|
||||
* Class that provides a mechanism to send requests to the Firebase Cloud Messaging backend.
|
||||
*/
|
||||
export declare class FirebaseMessagingRequestHandler {
|
||||
private readonly httpClient;
|
||||
private readonly http2Client;
|
||||
/**
|
||||
* @param app - The app used to fetch access tokens to sign API requests.
|
||||
* @constructor
|
||||
*/
|
||||
constructor(app: App);
|
||||
/**
|
||||
* Invokes the request handler with the provided request data.
|
||||
*
|
||||
* @param host - The host to which to send the request.
|
||||
* @param path - The path to which to send the request.
|
||||
* @param requestData - The request data.
|
||||
* @returns A promise that resolves with the response.
|
||||
*/
|
||||
invokeRequestHandler(host: string, path: string, requestData: object): Promise<object>;
|
||||
/**
|
||||
* Invokes the HTTP/1.1 request handler with the provided request data.
|
||||
*
|
||||
* @param host - The host to which to send the request.
|
||||
* @param path - The path to which to send the request.
|
||||
* @param requestData - The request data.
|
||||
* @returns A promise that resolves with the {@link SendResponse}.
|
||||
*/
|
||||
invokeHttpRequestHandlerForSendResponse(host: string, path: string, requestData: object): Promise<SendResponse>;
|
||||
/**
|
||||
* Invokes the HTTP/2 request handler with the provided request data.
|
||||
*
|
||||
* @param host - The host to which to send the request.
|
||||
* @param path - The path to which to send the request.
|
||||
* @param requestData - The request data.
|
||||
* @returns A promise that resolves with the {@link SendResponse}.
|
||||
*/
|
||||
invokeHttp2RequestHandlerForSendResponse(host: string, path: string, requestData: object, http2SessionHandler: Http2SessionHandler): Promise<SendResponse>;
|
||||
private buildSendResponse;
|
||||
private buildSendResponseFromError;
|
||||
}
|
||||
154
server/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js
generated
vendored
Normal file
154
server/node_modules/firebase-admin/lib/messaging/messaging-api-request-internal.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FirebaseMessagingRequestHandler = void 0;
|
||||
const api_request_1 = require("../utils/api-request");
|
||||
const messaging_errors_internal_1 = require("./messaging-errors-internal");
|
||||
const index_1 = require("../utils/index");
|
||||
// FCM backend constants
|
||||
const FIREBASE_MESSAGING_TIMEOUT = 15000;
|
||||
const FIREBASE_MESSAGING_HTTP_METHOD = 'POST';
|
||||
const FIREBASE_MESSAGING_HEADERS = {
|
||||
'X-Firebase-Client': `fire-admin-node/${(0, index_1.getSdkVersion)()}`,
|
||||
'access_token_auth': 'true',
|
||||
};
|
||||
/**
|
||||
* Class that provides a mechanism to send requests to the Firebase Cloud Messaging backend.
|
||||
*/
|
||||
class FirebaseMessagingRequestHandler {
|
||||
/**
|
||||
* @param app - The app used to fetch access tokens to sign API requests.
|
||||
* @constructor
|
||||
*/
|
||||
constructor(app) {
|
||||
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
||||
this.http2Client = new api_request_1.AuthorizedHttp2Client(app);
|
||||
}
|
||||
/**
|
||||
* Invokes the request handler with the provided request data.
|
||||
*
|
||||
* @param host - The host to which to send the request.
|
||||
* @param path - The path to which to send the request.
|
||||
* @param requestData - The request data.
|
||||
* @returns A promise that resolves with the response.
|
||||
*/
|
||||
invokeRequestHandler(host, path, requestData) {
|
||||
const request = {
|
||||
method: FIREBASE_MESSAGING_HTTP_METHOD,
|
||||
url: `https://${host}${path}`,
|
||||
data: requestData,
|
||||
headers: FIREBASE_MESSAGING_HEADERS,
|
||||
timeout: FIREBASE_MESSAGING_TIMEOUT,
|
||||
};
|
||||
return this.httpClient.send(request).then((response) => {
|
||||
// Send non-JSON responses to the catch() below where they will be treated as errors.
|
||||
if (!response.isJson()) {
|
||||
throw new api_request_1.RequestResponseError(response);
|
||||
}
|
||||
// Check for backend errors in the response.
|
||||
const errorCode = (0, messaging_errors_internal_1.getErrorCode)(response.data);
|
||||
if (errorCode) {
|
||||
throw new api_request_1.RequestResponseError(response);
|
||||
}
|
||||
// Return entire response.
|
||||
return response.data;
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err instanceof api_request_1.RequestResponseError) {
|
||||
throw (0, messaging_errors_internal_1.createFirebaseError)(err);
|
||||
}
|
||||
// Re-throw the error if it already has the proper format.
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Invokes the HTTP/1.1 request handler with the provided request data.
|
||||
*
|
||||
* @param host - The host to which to send the request.
|
||||
* @param path - The path to which to send the request.
|
||||
* @param requestData - The request data.
|
||||
* @returns A promise that resolves with the {@link SendResponse}.
|
||||
*/
|
||||
invokeHttpRequestHandlerForSendResponse(host, path, requestData) {
|
||||
const request = {
|
||||
method: FIREBASE_MESSAGING_HTTP_METHOD,
|
||||
url: `https://${host}${path}`,
|
||||
data: requestData,
|
||||
headers: FIREBASE_MESSAGING_HEADERS,
|
||||
timeout: FIREBASE_MESSAGING_TIMEOUT,
|
||||
};
|
||||
return this.httpClient.send(request).then((response) => {
|
||||
return this.buildSendResponse(response);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err instanceof api_request_1.RequestResponseError) {
|
||||
return this.buildSendResponseFromError(err);
|
||||
}
|
||||
// Re-throw the error if it already has the proper format.
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Invokes the HTTP/2 request handler with the provided request data.
|
||||
*
|
||||
* @param host - The host to which to send the request.
|
||||
* @param path - The path to which to send the request.
|
||||
* @param requestData - The request data.
|
||||
* @returns A promise that resolves with the {@link SendResponse}.
|
||||
*/
|
||||
invokeHttp2RequestHandlerForSendResponse(host, path, requestData, http2SessionHandler) {
|
||||
const request = {
|
||||
method: FIREBASE_MESSAGING_HTTP_METHOD,
|
||||
url: `https://${host}${path}`,
|
||||
data: requestData,
|
||||
headers: FIREBASE_MESSAGING_HEADERS,
|
||||
timeout: FIREBASE_MESSAGING_TIMEOUT,
|
||||
http2SessionHandler: http2SessionHandler
|
||||
};
|
||||
return this.http2Client.send(request).then((response) => {
|
||||
return this.buildSendResponse(response);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err instanceof api_request_1.RequestResponseError) {
|
||||
return this.buildSendResponseFromError(err);
|
||||
}
|
||||
// Re-throw the error if it already has the proper format.
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
buildSendResponse(response) {
|
||||
const result = {
|
||||
success: response.status === 200,
|
||||
};
|
||||
if (result.success) {
|
||||
result.messageId = response.data.name;
|
||||
}
|
||||
else {
|
||||
result.error = (0, messaging_errors_internal_1.createFirebaseError)(new api_request_1.RequestResponseError(response));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
buildSendResponseFromError(err) {
|
||||
return {
|
||||
success: false,
|
||||
error: (0, messaging_errors_internal_1.createFirebaseError)(err)
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.FirebaseMessagingRequestHandler = FirebaseMessagingRequestHandler;
|
||||
914
server/node_modules/firebase-admin/lib/messaging/messaging-api.d.ts
generated
vendored
Normal file
914
server/node_modules/firebase-admin/lib/messaging/messaging-api.d.ts
generated
vendored
Normal file
@@ -0,0 +1,914 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2021 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 { FirebaseArrayIndexError, FirebaseError } from '../app/index';
|
||||
export interface BaseMessage {
|
||||
data?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
notification?: Notification;
|
||||
android?: AndroidConfig;
|
||||
webpush?: WebpushConfig;
|
||||
apns?: ApnsConfig;
|
||||
fcmOptions?: FcmOptions;
|
||||
}
|
||||
export interface TokenMessage extends BaseMessage {
|
||||
token: string;
|
||||
}
|
||||
export interface TopicMessage extends BaseMessage {
|
||||
topic: string;
|
||||
}
|
||||
export interface ConditionMessage extends BaseMessage {
|
||||
condition: string;
|
||||
}
|
||||
/**
|
||||
* Payload for the {@link Messaging.send} operation. The payload contains all the fields
|
||||
* in the BaseMessage type, and exactly one of token, topic or condition.
|
||||
*/
|
||||
export type Message = TokenMessage | TopicMessage | ConditionMessage;
|
||||
/**
|
||||
* Payload for the {@link Messaging.sendEachForMulticast} method. The payload contains all the fields
|
||||
* in the BaseMessage type, and a list of tokens.
|
||||
*/
|
||||
export interface MulticastMessage extends BaseMessage {
|
||||
tokens: string[];
|
||||
}
|
||||
/**
|
||||
* A notification that can be included in {@link Message}.
|
||||
*/
|
||||
export interface Notification {
|
||||
/**
|
||||
* The title of the notification.
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* The notification body
|
||||
*/
|
||||
body?: string;
|
||||
/**
|
||||
* URL of an image to be displayed in the notification.
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
/**
|
||||
* Represents platform-independent options for features provided by the FCM SDKs.
|
||||
*/
|
||||
export interface FcmOptions {
|
||||
/**
|
||||
* The label associated with the message's analytics data.
|
||||
*/
|
||||
analyticsLabel?: string;
|
||||
}
|
||||
/**
|
||||
* Represents the WebPush protocol options that can be included in an
|
||||
* {@link Message}.
|
||||
*/
|
||||
export interface WebpushConfig {
|
||||
/**
|
||||
* A collection of WebPush headers. Header values must be strings.
|
||||
*
|
||||
* See {@link https://tools.ietf.org/html/rfc8030#section-5 | WebPush specification}
|
||||
* for supported headers.
|
||||
*/
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
/**
|
||||
* A collection of data fields.
|
||||
*/
|
||||
data?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
/**
|
||||
* A WebPush notification payload to be included in the message.
|
||||
*/
|
||||
notification?: WebpushNotification;
|
||||
/**
|
||||
* Options for features provided by the FCM SDK for Web.
|
||||
*/
|
||||
fcmOptions?: WebpushFcmOptions;
|
||||
}
|
||||
/** Represents options for features provided by the FCM SDK for Web
|
||||
* (which are not part of the Webpush standard).
|
||||
*/
|
||||
export interface WebpushFcmOptions {
|
||||
/**
|
||||
* The link to open when the user clicks on the notification.
|
||||
* For all URL values, HTTPS is required.
|
||||
*/
|
||||
link?: string;
|
||||
}
|
||||
/**
|
||||
* Represents the WebPush-specific notification options that can be included in
|
||||
* {@link WebpushConfig}. This supports most of the standard
|
||||
* options as defined in the Web Notification
|
||||
* {@link https://developer.mozilla.org/en-US/docs/Web/API/notification/Notification | specification}.
|
||||
*/
|
||||
export interface WebpushNotification {
|
||||
/**
|
||||
* Title text of the notification.
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* An array of notification actions representing the actions
|
||||
* available to the user when the notification is presented.
|
||||
*/
|
||||
actions?: Array<{
|
||||
/**
|
||||
* An action available to the user when the notification is presented
|
||||
*/
|
||||
action: string;
|
||||
/**
|
||||
* Optional icon for a notification action.
|
||||
*/
|
||||
icon?: string;
|
||||
/**
|
||||
* Title of the notification action.
|
||||
*/
|
||||
title: string;
|
||||
}>;
|
||||
/**
|
||||
* URL of the image used to represent the notification when there is
|
||||
* not enough space to display the notification itself.
|
||||
*/
|
||||
badge?: string;
|
||||
/**
|
||||
* Body text of the notification.
|
||||
*/
|
||||
body?: string;
|
||||
/**
|
||||
* Arbitrary data that you want associated with the notification.
|
||||
* This can be of any data type.
|
||||
*/
|
||||
data?: any;
|
||||
/**
|
||||
* The direction in which to display the notification. Must be one
|
||||
* of `auto`, `ltr` or `rtl`.
|
||||
*/
|
||||
dir?: 'auto' | 'ltr' | 'rtl';
|
||||
/**
|
||||
* URL to the notification icon.
|
||||
*/
|
||||
icon?: string;
|
||||
/**
|
||||
* URL of an image to be displayed in the notification.
|
||||
*/
|
||||
image?: string;
|
||||
/**
|
||||
* The notification's language as a BCP 47 language tag.
|
||||
*/
|
||||
lang?: string;
|
||||
/**
|
||||
* A boolean specifying whether the user should be notified after a
|
||||
* new notification replaces an old one. Defaults to false.
|
||||
*/
|
||||
renotify?: boolean;
|
||||
/**
|
||||
* Indicates that a notification should remain active until the user
|
||||
* clicks or dismisses it, rather than closing automatically.
|
||||
* Defaults to false.
|
||||
*/
|
||||
requireInteraction?: boolean;
|
||||
/**
|
||||
* A boolean specifying whether the notification should be silent.
|
||||
* Defaults to false.
|
||||
*/
|
||||
silent?: boolean;
|
||||
/**
|
||||
* An identifying tag for the notification.
|
||||
*/
|
||||
tag?: string;
|
||||
/**
|
||||
* Timestamp of the notification. Refer to
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/notification/timestamp
|
||||
* for details.
|
||||
*/
|
||||
timestamp?: number;
|
||||
/**
|
||||
* A vibration pattern for the device's vibration hardware to emit
|
||||
* when the notification fires.
|
||||
*/
|
||||
vibrate?: number | number[];
|
||||
[key: string]: any;
|
||||
}
|
||||
/**
|
||||
* Represents the APNs-specific options that can be included in an
|
||||
* {@link Message}. Refer to
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html |
|
||||
* Apple documentation} for various headers and payload fields supported by APNs.
|
||||
*/
|
||||
export interface ApnsConfig {
|
||||
/**
|
||||
* APN `pushToStartToken` or `pushToken` to start or update live activities.
|
||||
*/
|
||||
liveActivityToken?: string;
|
||||
/**
|
||||
* A collection of APNs headers. Header values must be strings.
|
||||
*/
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
/**
|
||||
* An APNs payload to be included in the message.
|
||||
*/
|
||||
payload?: ApnsPayload;
|
||||
/**
|
||||
* Options for features provided by the FCM SDK for iOS.
|
||||
*/
|
||||
fcmOptions?: ApnsFcmOptions;
|
||||
}
|
||||
/**
|
||||
* Represents the payload of an APNs message. Mainly consists of the `aps`
|
||||
* dictionary. But may also contain other arbitrary custom keys.
|
||||
*/
|
||||
export interface ApnsPayload {
|
||||
/**
|
||||
* The `aps` dictionary to be included in the message.
|
||||
*/
|
||||
aps: Aps;
|
||||
[customData: string]: any;
|
||||
}
|
||||
/**
|
||||
* Represents the {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
||||
* aps dictionary} that is part of APNs messages.
|
||||
*/
|
||||
export interface Aps {
|
||||
/**
|
||||
* Alert to be included in the message. This may be a string or an object of
|
||||
* type `admin.messaging.ApsAlert`.
|
||||
*/
|
||||
alert?: string | ApsAlert;
|
||||
/**
|
||||
* Badge to be displayed with the message. Set to 0 to remove the badge. When
|
||||
* not specified, the badge will remain unchanged.
|
||||
*/
|
||||
badge?: number;
|
||||
/**
|
||||
* Sound to be played with the message.
|
||||
*/
|
||||
sound?: string | CriticalSound;
|
||||
/**
|
||||
* Specifies whether to configure a background update notification.
|
||||
*/
|
||||
contentAvailable?: boolean;
|
||||
/**
|
||||
* Specifies whether to set the `mutable-content` property on the message
|
||||
* so the clients can modify the notification via app extensions.
|
||||
*/
|
||||
mutableContent?: boolean;
|
||||
/**
|
||||
* Type of the notification.
|
||||
*/
|
||||
category?: string;
|
||||
/**
|
||||
* An app-specific identifier for grouping notifications.
|
||||
*/
|
||||
threadId?: string;
|
||||
[customData: string]: any;
|
||||
}
|
||||
export interface ApsAlert {
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
body?: string;
|
||||
locKey?: string;
|
||||
locArgs?: string[];
|
||||
titleLocKey?: string;
|
||||
titleLocArgs?: string[];
|
||||
subtitleLocKey?: string;
|
||||
subtitleLocArgs?: string[];
|
||||
actionLocKey?: string;
|
||||
launchImage?: string;
|
||||
}
|
||||
/**
|
||||
* Represents a critical sound configuration that can be included in the
|
||||
* `aps` dictionary of an APNs payload.
|
||||
*/
|
||||
export interface CriticalSound {
|
||||
/**
|
||||
* The critical alert flag. Set to `true` to enable the critical alert.
|
||||
*/
|
||||
critical?: boolean;
|
||||
/**
|
||||
* The name of a sound file in the app's main bundle or in the `Library/Sounds`
|
||||
* folder of the app's container directory. Specify the string "default" to play
|
||||
* the system sound.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The volume for the critical alert's sound. Must be a value between 0.0
|
||||
* (silent) and 1.0 (full volume).
|
||||
*/
|
||||
volume?: number;
|
||||
}
|
||||
/**
|
||||
* Represents options for features provided by the FCM SDK for iOS.
|
||||
*/
|
||||
export interface ApnsFcmOptions {
|
||||
/**
|
||||
* The label associated with the message's analytics data.
|
||||
*/
|
||||
analyticsLabel?: string;
|
||||
/**
|
||||
* URL of an image to be displayed in the notification.
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
/**
|
||||
* Represents the Android-specific options that can be included in an
|
||||
* {@link Message}.
|
||||
*/
|
||||
export interface AndroidConfig {
|
||||
/**
|
||||
* Collapse key for the message. Collapse key serves as an identifier for a
|
||||
* group of messages that can be collapsed, so that only the last message gets
|
||||
* sent when delivery can be resumed. A maximum of four different collapse keys
|
||||
* may be active at any given time.
|
||||
*/
|
||||
collapseKey?: string;
|
||||
/**
|
||||
* Priority of the message. Must be either `normal` or `high`.
|
||||
*/
|
||||
priority?: ('high' | 'normal');
|
||||
/**
|
||||
* Time-to-live duration of the message in milliseconds.
|
||||
*/
|
||||
ttl?: number;
|
||||
/**
|
||||
* Package name of the application where the registration tokens must match
|
||||
* in order to receive the message.
|
||||
*/
|
||||
restrictedPackageName?: string;
|
||||
/**
|
||||
* A collection of data fields to be included in the message. All values must
|
||||
* be strings. When provided, overrides any data fields set on the top-level
|
||||
* {@link Message}.
|
||||
*/
|
||||
data?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
/**
|
||||
* Android notification to be included in the message.
|
||||
*/
|
||||
notification?: AndroidNotification;
|
||||
/**
|
||||
* Options for features provided by the FCM SDK for Android.
|
||||
*/
|
||||
fcmOptions?: AndroidFcmOptions;
|
||||
/**
|
||||
* A boolean indicating whether messages will be allowed to be delivered to
|
||||
* the app while the device is in direct boot mode.
|
||||
*/
|
||||
directBootOk?: boolean;
|
||||
}
|
||||
/**
|
||||
* Represents the Android-specific notification options that can be included in
|
||||
* {@link AndroidConfig}.
|
||||
*/
|
||||
export interface AndroidNotification {
|
||||
/**
|
||||
* Title of the Android notification. When provided, overrides the title set via
|
||||
* `admin.messaging.Notification`.
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* Body of the Android notification. When provided, overrides the body set via
|
||||
* `admin.messaging.Notification`.
|
||||
*/
|
||||
body?: string;
|
||||
/**
|
||||
* Icon resource for the Android notification.
|
||||
*/
|
||||
icon?: string;
|
||||
/**
|
||||
* Notification icon color in `#rrggbb` format.
|
||||
*/
|
||||
color?: string;
|
||||
/**
|
||||
* File name of the sound to be played when the device receives the
|
||||
* notification.
|
||||
*/
|
||||
sound?: string;
|
||||
/**
|
||||
* Notification tag. This is an identifier used to replace existing
|
||||
* notifications in the notification drawer. If not specified, each request
|
||||
* creates a new notification.
|
||||
*/
|
||||
tag?: string;
|
||||
/**
|
||||
* URL of an image to be displayed in the notification.
|
||||
*/
|
||||
imageUrl?: string;
|
||||
/**
|
||||
* Action associated with a user click on the notification. If specified, an
|
||||
* activity with a matching Intent Filter is launched when a user clicks on the
|
||||
* notification.
|
||||
*/
|
||||
clickAction?: string;
|
||||
/**
|
||||
* Key of the body string in the app's string resource to use to localize the
|
||||
* body text.
|
||||
*
|
||||
*/
|
||||
bodyLocKey?: string;
|
||||
/**
|
||||
* An array of resource keys that will be used in place of the format
|
||||
* specifiers in `bodyLocKey`.
|
||||
*/
|
||||
bodyLocArgs?: string[];
|
||||
/**
|
||||
* Key of the title string in the app's string resource to use to localize the
|
||||
* title text.
|
||||
*/
|
||||
titleLocKey?: string;
|
||||
/**
|
||||
* An array of resource keys that will be used in place of the format
|
||||
* specifiers in `titleLocKey`.
|
||||
*/
|
||||
titleLocArgs?: string[];
|
||||
/**
|
||||
* The Android notification channel ID (new in Android O). The app must create
|
||||
* a channel with this channel ID before any notification with this channel ID
|
||||
* can be received. If you don't send this channel ID in the request, or if the
|
||||
* channel ID provided has not yet been created by the app, FCM uses the channel
|
||||
* ID specified in the app manifest.
|
||||
*/
|
||||
channelId?: string;
|
||||
/**
|
||||
* Sets the "ticker" text, which is sent to accessibility services. Prior to
|
||||
* API level 21 (Lollipop), sets the text that is displayed in the status bar
|
||||
* when the notification first arrives.
|
||||
*/
|
||||
ticker?: string;
|
||||
/**
|
||||
* When set to `false` or unset, the notification is automatically dismissed when
|
||||
* the user clicks it in the panel. When set to `true`, the notification persists
|
||||
* even when the user clicks it.
|
||||
*/
|
||||
sticky?: boolean;
|
||||
/**
|
||||
* For notifications that inform users about events with an absolute time reference, sets
|
||||
* the time that the event in the notification occurred. Notifications
|
||||
* in the panel are sorted by this time.
|
||||
*/
|
||||
eventTimestamp?: Date;
|
||||
/**
|
||||
* Sets whether or not this notification is relevant only to the current device.
|
||||
* Some notifications can be bridged to other devices for remote display, such as
|
||||
* a Wear OS watch. This hint can be set to recommend this notification not be bridged.
|
||||
* See {@link https://developer.android.com/training/wearables/notifications/bridger#existing-method-of-preventing-bridging |
|
||||
* Wear OS guides}.
|
||||
*/
|
||||
localOnly?: boolean;
|
||||
/**
|
||||
* Sets the relative priority for this notification. Low-priority notifications
|
||||
* may be hidden from the user in certain situations. Note this priority differs
|
||||
* from `AndroidMessagePriority`. This priority is processed by the client after
|
||||
* the message has been delivered. Whereas `AndroidMessagePriority` is an FCM concept
|
||||
* that controls when the message is delivered.
|
||||
*/
|
||||
priority?: ('min' | 'low' | 'default' | 'high' | 'max');
|
||||
/**
|
||||
* Sets the vibration pattern to use. Pass in an array of milliseconds to
|
||||
* turn the vibrator on or off. The first value indicates the duration to wait before
|
||||
* turning the vibrator on. The next value indicates the duration to keep the
|
||||
* vibrator on. Subsequent values alternate between duration to turn the vibrator
|
||||
* off and to turn the vibrator on. If `vibrateTimingsMillis` is set and `defaultVibrateTimings`
|
||||
* is set to `true`, the default value is used instead of the user-specified `vibrateTimingsMillis`.
|
||||
*/
|
||||
vibrateTimingsMillis?: number[];
|
||||
/**
|
||||
* If set to `true`, use the Android framework's default vibrate pattern for the
|
||||
* notification. Default values are specified in {@link https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml |
|
||||
* config.xml}. If `defaultVibrateTimings` is set to `true` and `vibrateTimingsMillis` is also set,
|
||||
* the default value is used instead of the user-specified `vibrateTimingsMillis`.
|
||||
*/
|
||||
defaultVibrateTimings?: boolean;
|
||||
/**
|
||||
* If set to `true`, use the Android framework's default sound for the notification.
|
||||
* Default values are specified in {@link https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml |
|
||||
* config.xml}.
|
||||
*/
|
||||
defaultSound?: boolean;
|
||||
/**
|
||||
* Settings to control the notification's LED blinking rate and color if LED is
|
||||
* available on the device. The total blinking time is controlled by the OS.
|
||||
*/
|
||||
lightSettings?: LightSettings;
|
||||
/**
|
||||
* If set to `true`, use the Android framework's default LED light settings
|
||||
* for the notification. Default values are specified in {@link https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/config.xml |
|
||||
* config.xml}.
|
||||
* If `default_light_settings` is set to `true` and `light_settings` is also set,
|
||||
* the user-specified `light_settings` is used instead of the default value.
|
||||
*/
|
||||
defaultLightSettings?: boolean;
|
||||
/**
|
||||
* Sets the visibility of the notification. Must be either `private`, `public`,
|
||||
* or `secret`. If unspecified, it remains undefined in the Admin SDK, and
|
||||
* defers to the FCM backend's default mapping.
|
||||
*/
|
||||
visibility?: ('private' | 'public' | 'secret');
|
||||
/**
|
||||
* Sets the number of items this notification represents. May be displayed as a
|
||||
* badge count for Launchers that support badging. See {@link https://developer.android.com/training/notify-user/badges |
|
||||
* NotificationBadge}.
|
||||
* For example, this might be useful if you're using just one notification to
|
||||
* represent multiple new messages but you want the count here to represent
|
||||
* the number of total new messages. If zero or unspecified, systems
|
||||
* that support badging use the default, which is to increment a number
|
||||
* displayed on the long-press menu each time a new notification arrives.
|
||||
*/
|
||||
notificationCount?: number;
|
||||
/**
|
||||
* Sets if this notification should attempt to be proxied. Must be either
|
||||
* `allow`, `deny` or `if_priority_lowered`. If unspecified, it remains
|
||||
* undefined in the Admin SDK, and defers to the FCM backend's default mapping.
|
||||
*/
|
||||
proxy?: ('allow' | 'deny' | 'if_priority_lowered');
|
||||
}
|
||||
/**
|
||||
* Represents settings to control notification LED that can be included in
|
||||
* {@link AndroidNotification}.
|
||||
*/
|
||||
export interface LightSettings {
|
||||
/**
|
||||
* Required. Sets color of the LED in `#rrggbb` or `#rrggbbaa` format.
|
||||
*/
|
||||
color: string;
|
||||
/**
|
||||
* Required. Along with `light_off_duration`, defines the blink rate of LED flashes.
|
||||
*/
|
||||
lightOnDurationMillis: number;
|
||||
/**
|
||||
* Required. Along with `light_on_duration`, defines the blink rate of LED flashes.
|
||||
*/
|
||||
lightOffDurationMillis: number;
|
||||
}
|
||||
/**
|
||||
* Represents options for features provided by the FCM SDK for Android.
|
||||
*/
|
||||
export interface AndroidFcmOptions {
|
||||
/**
|
||||
* The label associated with the message's analytics data.
|
||||
*/
|
||||
analyticsLabel?: string;
|
||||
}
|
||||
/**
|
||||
* Interface representing an FCM legacy API data message payload. Data
|
||||
* messages let developers send up to 4KB of custom key-value pairs. The
|
||||
* keys and values must both be strings. Keys can be any custom string,
|
||||
* except for the following reserved strings:
|
||||
*
|
||||
* <ul>
|
||||
* <li><code>from</code></li>
|
||||
* <li>Anything starting with <code>google.</code></li>
|
||||
* </ul>
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
||||
* for code samples and detailed documentation.
|
||||
*/
|
||||
export interface DataMessagePayload {
|
||||
[key: string]: string;
|
||||
}
|
||||
/**
|
||||
* Interface representing an FCM legacy API notification message payload.
|
||||
* Notification messages let developers send up to 4KB of predefined
|
||||
* key-value pairs. Accepted keys are outlined below.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
||||
* for code samples and detailed documentation.
|
||||
*/
|
||||
export interface NotificationMessagePayload {
|
||||
/**
|
||||
* Identifier used to replace existing notifications in the notification drawer.
|
||||
*
|
||||
* If not specified, each request creates a new notification.
|
||||
*
|
||||
* If specified and a notification with the same tag is already being shown,
|
||||
* the new notification replaces the existing one in the notification drawer.
|
||||
*
|
||||
* **Platforms:** Android
|
||||
*/
|
||||
tag?: string;
|
||||
/**
|
||||
* The notification's body text.
|
||||
*
|
||||
* **Platforms:** iOS, Android, Web
|
||||
*/
|
||||
body?: string;
|
||||
/**
|
||||
* The notification's icon.
|
||||
*
|
||||
* **Android:** Sets the notification icon to `myicon` for drawable resource
|
||||
* `myicon`. If you don't send this key in the request, FCM displays the
|
||||
* launcher icon specified in your app manifest.
|
||||
*
|
||||
* **Web:** The URL to use for the notification's icon.
|
||||
*
|
||||
* **Platforms:** Android, Web
|
||||
*/
|
||||
icon?: string;
|
||||
/**
|
||||
* The value of the badge on the home screen app icon.
|
||||
*
|
||||
* If not specified, the badge is not changed.
|
||||
*
|
||||
* If set to `0`, the badge is removed.
|
||||
*
|
||||
* **Platforms:** iOS
|
||||
*/
|
||||
badge?: string;
|
||||
/**
|
||||
* The notification icon's color, expressed in `#rrggbb` format.
|
||||
*
|
||||
* **Platforms:** Android
|
||||
*/
|
||||
color?: string;
|
||||
/**
|
||||
* The sound to be played when the device receives a notification. Supports
|
||||
* "default" for the default notification sound of the device or the filename of a
|
||||
* sound resource bundled in the app.
|
||||
* Sound files must reside in `/res/raw/`.
|
||||
*
|
||||
* **Platforms:** Android
|
||||
*/
|
||||
sound?: string;
|
||||
/**
|
||||
* The notification's title.
|
||||
*
|
||||
* **Platforms:** iOS, Android, Web
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* The key to the body string in the app's string resources to use to localize
|
||||
* the body text to the user's current localization.
|
||||
*
|
||||
* **iOS:** Corresponds to `loc-key` in the APNs payload. See
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
||||
* Payload Key Reference} and
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
||||
* Localizing the Content of Your Remote Notifications} for more information.
|
||||
*
|
||||
* **Android:** See
|
||||
* {@link http://developer.android.com/guide/topics/resources/string-resource.html | String Resources}
|
||||
* for more information.
|
||||
*
|
||||
* **Platforms:** iOS, Android
|
||||
*/
|
||||
bodyLocKey?: string;
|
||||
/**
|
||||
* Variable string values to be used in place of the format specifiers in
|
||||
* `body_loc_key` to use to localize the body text to the user's current
|
||||
* localization.
|
||||
*
|
||||
* The value should be a stringified JSON array.
|
||||
*
|
||||
* **iOS:** Corresponds to `loc-args` in the APNs payload. See
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
||||
* Payload Key Reference} and
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
||||
* Localizing the Content of Your Remote Notifications} for more information.
|
||||
*
|
||||
* **Android:** See
|
||||
* {@link http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling |
|
||||
* Formatting and Styling} for more information.
|
||||
*
|
||||
* **Platforms:** iOS, Android
|
||||
*/
|
||||
bodyLocArgs?: string;
|
||||
/**
|
||||
* Action associated with a user click on the notification. If specified, an
|
||||
* activity with a matching Intent Filter is launched when a user clicks on the
|
||||
* notification.
|
||||
*
|
||||
* * **Platforms:** Android
|
||||
*/
|
||||
clickAction?: string;
|
||||
/**
|
||||
* The key to the title string in the app's string resources to use to localize
|
||||
* the title text to the user's current localization.
|
||||
*
|
||||
* **iOS:** Corresponds to `title-loc-key` in the APNs payload. See
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
||||
* Payload Key Reference} and
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
||||
* Localizing the Content of Your Remote Notifications} for more information.
|
||||
*
|
||||
* **Android:** See
|
||||
* {@link http://developer.android.com/guide/topics/resources/string-resource.html | String Resources}
|
||||
* for more information.
|
||||
*
|
||||
* **Platforms:** iOS, Android
|
||||
*/
|
||||
titleLocKey?: string;
|
||||
/**
|
||||
* Variable string values to be used in place of the format specifiers in
|
||||
* `title_loc_key` to use to localize the title text to the user's current
|
||||
* localization.
|
||||
*
|
||||
* The value should be a stringified JSON array.
|
||||
*
|
||||
* **iOS:** Corresponds to `title-loc-args` in the APNs payload. See
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html |
|
||||
* Payload Key Reference} and
|
||||
* {@link https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW9 |
|
||||
* Localizing the Content of Your Remote Notifications} for more information.
|
||||
*
|
||||
* **Android:** See
|
||||
* {@link http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling |
|
||||
* Formatting and Styling} for more information.
|
||||
*
|
||||
* **Platforms:** iOS, Android
|
||||
*/
|
||||
titleLocArgs?: string;
|
||||
[key: string]: string | undefined;
|
||||
}
|
||||
/**
|
||||
* Interface representing a Firebase Cloud Messaging message payload. One or
|
||||
* both of the `data` and `notification` keys are required.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
||||
* for code samples and detailed documentation.
|
||||
*/
|
||||
export interface MessagingPayload {
|
||||
/**
|
||||
* The data message payload.
|
||||
*/
|
||||
data?: DataMessagePayload;
|
||||
/**
|
||||
* The notification message payload.
|
||||
*/
|
||||
notification?: NotificationMessagePayload;
|
||||
}
|
||||
/**
|
||||
* Interface representing the options that can be provided when sending a
|
||||
* message via the FCM legacy APIs.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/send-message | Build send requests}
|
||||
* for code samples and detailed documentation.
|
||||
*/
|
||||
export interface MessagingOptions {
|
||||
/**
|
||||
* Whether or not the message should actually be sent. When set to `true`,
|
||||
* allows developers to test a request without actually sending a message. When
|
||||
* set to `false`, the message will be sent.
|
||||
*
|
||||
* **Default value:** `false`
|
||||
*/
|
||||
dryRun?: boolean;
|
||||
/**
|
||||
* The priority of the message. Valid values are `"normal"` and `"high".` On
|
||||
* iOS, these correspond to APNs priorities `5` and `10`.
|
||||
*
|
||||
* By default, notification messages are sent with high priority, and data
|
||||
* messages are sent with normal priority. Normal priority optimizes the client
|
||||
* app's battery consumption and should be used unless immediate delivery is
|
||||
* required. For messages with normal priority, the app may receive the message
|
||||
* with unspecified delay.
|
||||
*
|
||||
* When a message is sent with high priority, it is sent immediately, and the
|
||||
* app can wake a sleeping device and open a network connection to your server.
|
||||
*
|
||||
* For more information, see
|
||||
* {@link https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message |
|
||||
* Setting the priority of a message}.
|
||||
*
|
||||
* **Default value:** `"high"` for notification messages, `"normal"` for data
|
||||
* messages
|
||||
*/
|
||||
priority?: string;
|
||||
/**
|
||||
* How long (in seconds) the message should be kept in FCM storage if the device
|
||||
* is offline. The maximum time to live supported is four weeks, and the default
|
||||
* value is also four weeks. For more information, see
|
||||
* {@link https://firebase.google.com/docs/cloud-messaging/concept-options#ttl | Setting the lifespan of a message}.
|
||||
*
|
||||
* **Default value:** `2419200` (representing four weeks, in seconds)
|
||||
*/
|
||||
timeToLive?: number;
|
||||
/**
|
||||
* String identifying a group of messages (for example, "Updates Available")
|
||||
* that can be collapsed, so that only the last message gets sent when delivery
|
||||
* can be resumed. This is used to avoid sending too many of the same messages
|
||||
* when the device comes back online or becomes active.
|
||||
*
|
||||
* There is no guarantee of the order in which messages get sent.
|
||||
*
|
||||
* A maximum of four different collapse keys is allowed at any given time. This
|
||||
* means FCM server can simultaneously store four different
|
||||
* send-to-sync messages per client app. If you exceed this number, there is no
|
||||
* guarantee which four collapse keys the FCM server will keep.
|
||||
*
|
||||
* **Default value:** None
|
||||
*/
|
||||
collapseKey?: string;
|
||||
/**
|
||||
* On iOS, use this field to represent `mutable-content` in the APNs payload.
|
||||
* When a notification is sent and this is set to `true`, the content of the
|
||||
* notification can be modified before it is displayed, using a
|
||||
* {@link https://developer.apple.com/reference/usernotifications/unnotificationserviceextension |
|
||||
* Notification Service app extension}.
|
||||
*
|
||||
* On Android and Web, this parameter will be ignored.
|
||||
*
|
||||
* **Default value:** `false`
|
||||
*/
|
||||
mutableContent?: boolean;
|
||||
/**
|
||||
* On iOS, use this field to represent `content-available` in the APNs payload.
|
||||
* When a notification or data message is sent and this is set to `true`, an
|
||||
* inactive client app is awoken. On Android, data messages wake the app by
|
||||
* default. On Chrome, this flag is currently not supported.
|
||||
*
|
||||
* **Default value:** `false`
|
||||
*/
|
||||
contentAvailable?: boolean;
|
||||
/**
|
||||
* The package name of the application which the registration tokens must match
|
||||
* in order to receive the message.
|
||||
*
|
||||
* **Default value:** None
|
||||
*/
|
||||
restrictedPackageName?: string;
|
||||
[key: string]: any | undefined;
|
||||
}
|
||||
/**
|
||||
* Interface representing the server response from the
|
||||
* {@link Messaging.subscribeToTopic} and {@link Messaging.unsubscribeFromTopic}
|
||||
* methods.
|
||||
*
|
||||
* See
|
||||
* {@link https://firebase.google.com/docs/cloud-messaging/manage-topics |
|
||||
* Manage topics from the server} for code samples and detailed documentation.
|
||||
*/
|
||||
export interface MessagingTopicManagementResponse {
|
||||
/**
|
||||
* The number of registration tokens that could not be subscribed to the topic
|
||||
* and resulted in an error.
|
||||
*/
|
||||
failureCount: number;
|
||||
/**
|
||||
* The number of registration tokens that were successfully subscribed to the
|
||||
* topic.
|
||||
*/
|
||||
successCount: number;
|
||||
/**
|
||||
* An array of errors corresponding to the provided registration token(s). The
|
||||
* length of this array will be equal to {@link MessagingTopicManagementResponse.failureCount}.
|
||||
*/
|
||||
errors: FirebaseArrayIndexError[];
|
||||
}
|
||||
/**
|
||||
* Interface representing the server response from the
|
||||
* {@link Messaging.sendEach} and {@link Messaging.sendEachForMulticast} methods.
|
||||
*/
|
||||
export interface BatchResponse {
|
||||
/**
|
||||
* An array of responses, each corresponding to a message.
|
||||
*/
|
||||
responses: SendResponse[];
|
||||
/**
|
||||
* The number of messages that were successfully handed off for sending.
|
||||
*/
|
||||
successCount: number;
|
||||
/**
|
||||
* The number of messages that resulted in errors when sending.
|
||||
*/
|
||||
failureCount: number;
|
||||
}
|
||||
/**
|
||||
* Interface representing the status of an individual message that was sent as
|
||||
* part of a batch request.
|
||||
*/
|
||||
export interface SendResponse {
|
||||
/**
|
||||
* A boolean indicating if the message was successfully handed off to FCM or
|
||||
* not. When true, the `messageId` attribute is guaranteed to be set. When
|
||||
* false, the `error` attribute is guaranteed to be set.
|
||||
*/
|
||||
success: boolean;
|
||||
/**
|
||||
* A unique message ID string, if the message was handed off to FCM for
|
||||
* delivery.
|
||||
*
|
||||
*/
|
||||
messageId?: string;
|
||||
/**
|
||||
* An error, if the message was not handed off to FCM successfully.
|
||||
*/
|
||||
error?: FirebaseError;
|
||||
}
|
||||
19
server/node_modules/firebase-admin/lib/messaging/messaging-api.js
generated
vendored
Normal file
19
server/node_modules/firebase-admin/lib/messaging/messaging-api.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
31
server/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.d.ts
generated
vendored
Normal file
31
server/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* Copyright 2019 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 { RequestResponseError } from '../utils/api-request';
|
||||
import { FirebaseMessagingError } from '../utils/error';
|
||||
/**
|
||||
* Creates a new `FirebaseMessagingError` by extracting the error code, message and other relevant
|
||||
* details from a `RequestResponseError` response.
|
||||
*
|
||||
* @param err - The `RequestResponseError` to convert into a Firebase error
|
||||
* @returns A Firebase error that can be returned to the user.
|
||||
*/
|
||||
export declare function createFirebaseError(err: RequestResponseError): FirebaseMessagingError;
|
||||
/**
|
||||
* @param response - The response to check for errors.
|
||||
* @returns The error code if present; null otherwise.
|
||||
*/
|
||||
export declare function getErrorCode(response: any): string | null;
|
||||
104
server/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js
generated
vendored
Normal file
104
server/node_modules/firebase-admin/lib/messaging/messaging-errors-internal.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createFirebaseError = createFirebaseError;
|
||||
exports.getErrorCode = getErrorCode;
|
||||
const error_1 = require("../utils/error");
|
||||
const validator = require("../utils/validator");
|
||||
/**
|
||||
* Creates a new `FirebaseMessagingError` by extracting the error code, message and other relevant
|
||||
* details from a `RequestResponseError` response.
|
||||
*
|
||||
* @param err - The `RequestResponseError` to convert into a Firebase error
|
||||
* @returns A Firebase error that can be returned to the user.
|
||||
*/
|
||||
function createFirebaseError(err) {
|
||||
if (err.response.isJson()) {
|
||||
// For JSON responses, map the server response to a client-side error.
|
||||
const json = err.response.data;
|
||||
const errorCode = getErrorCode(json);
|
||||
const errorMessage = getErrorMessage(json);
|
||||
return error_1.FirebaseMessagingError.fromServerError(errorCode, errorMessage, json);
|
||||
}
|
||||
// Non-JSON response
|
||||
let error;
|
||||
switch (err.response.status) {
|
||||
case 400:
|
||||
error = error_1.MessagingClientErrorCode.INVALID_ARGUMENT;
|
||||
break;
|
||||
case 401:
|
||||
case 403:
|
||||
error = error_1.MessagingClientErrorCode.AUTHENTICATION_ERROR;
|
||||
break;
|
||||
case 500:
|
||||
error = error_1.MessagingClientErrorCode.INTERNAL_ERROR;
|
||||
break;
|
||||
case 503:
|
||||
error = error_1.MessagingClientErrorCode.SERVER_UNAVAILABLE;
|
||||
break;
|
||||
default:
|
||||
// Treat non-JSON responses with unexpected status codes as unknown errors.
|
||||
error = error_1.MessagingClientErrorCode.UNKNOWN_ERROR;
|
||||
}
|
||||
return new error_1.FirebaseMessagingError({
|
||||
code: error.code,
|
||||
message: `${error.message} Raw server response: "${err.response.text}". Status code: ` +
|
||||
`${err.response.status}.`,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param response - The response to check for errors.
|
||||
* @returns The error code if present; null otherwise.
|
||||
*/
|
||||
function getErrorCode(response) {
|
||||
if (validator.isNonNullObject(response) && 'error' in response) {
|
||||
const error = response.error;
|
||||
if (validator.isString(error)) {
|
||||
return error;
|
||||
}
|
||||
if (validator.isArray(error.details)) {
|
||||
const fcmErrorType = 'type.googleapis.com/google.firebase.fcm.v1.FcmError';
|
||||
for (const element of error.details) {
|
||||
if (element['@type'] === fcmErrorType) {
|
||||
return element.errorCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ('status' in error) {
|
||||
return error.status;
|
||||
}
|
||||
else {
|
||||
return error.message;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Extracts error message from the given response object.
|
||||
*
|
||||
* @param response - The response to check for errors.
|
||||
* @returns The error message if present; null otherwise.
|
||||
*/
|
||||
function getErrorMessage(response) {
|
||||
if (validator.isNonNullObject(response) &&
|
||||
'error' in response &&
|
||||
validator.isNonEmptyString(response.error.message)) {
|
||||
return response.error.message;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
27
server/node_modules/firebase-admin/lib/messaging/messaging-internal.d.ts
generated
vendored
Normal file
27
server/node_modules/firebase-admin/lib/messaging/messaging-internal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* 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 { Message } from './messaging-api';
|
||||
export declare const BLACKLISTED_DATA_PAYLOAD_KEYS: string[];
|
||||
export declare const BLACKLISTED_OPTIONS_KEYS: string[];
|
||||
/**
|
||||
* Checks if the given Message object is valid. Recursively validates all the child objects
|
||||
* included in the message (android, apns, data etc.). If successful, transforms the message
|
||||
* in place by renaming the keys to what's expected by the remote FCM service.
|
||||
*
|
||||
* @param {Message} Message An object to be validated.
|
||||
*/
|
||||
export declare function validateMessage(message: Message): void;
|
||||
505
server/node_modules/firebase-admin/lib/messaging/messaging-internal.js
generated
vendored
Normal file
505
server/node_modules/firebase-admin/lib/messaging/messaging-internal.js
generated
vendored
Normal file
@@ -0,0 +1,505 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BLACKLISTED_OPTIONS_KEYS = exports.BLACKLISTED_DATA_PAYLOAD_KEYS = void 0;
|
||||
exports.validateMessage = validateMessage;
|
||||
const index_1 = require("../utils/index");
|
||||
const error_1 = require("../utils/error");
|
||||
const validator = require("../utils/validator");
|
||||
// Keys which are not allowed in the messaging data payload object.
|
||||
exports.BLACKLISTED_DATA_PAYLOAD_KEYS = ['from'];
|
||||
// Keys which are not allowed in the messaging options object.
|
||||
exports.BLACKLISTED_OPTIONS_KEYS = [
|
||||
'condition', 'data', 'notification', 'registrationIds', 'registration_ids', 'to',
|
||||
];
|
||||
/**
|
||||
* Checks if the given Message object is valid. Recursively validates all the child objects
|
||||
* included in the message (android, apns, data etc.). If successful, transforms the message
|
||||
* in place by renaming the keys to what's expected by the remote FCM service.
|
||||
*
|
||||
* @param {Message} Message An object to be validated.
|
||||
*/
|
||||
function validateMessage(message) {
|
||||
if (!validator.isNonNullObject(message)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Message must be a non-null object');
|
||||
}
|
||||
const anyMessage = message;
|
||||
if (anyMessage.topic) {
|
||||
// If the topic name is prefixed, remove it.
|
||||
if (anyMessage.topic.startsWith('/topics/')) {
|
||||
anyMessage.topic = anyMessage.topic.replace(/^\/topics\//, '');
|
||||
}
|
||||
// Checks for illegal characters and empty string.
|
||||
if (!/^[a-zA-Z0-9-_.~%]+$/.test(anyMessage.topic)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Malformed topic name');
|
||||
}
|
||||
}
|
||||
const targets = [anyMessage.token, anyMessage.topic, anyMessage.condition];
|
||||
if (targets.filter((v) => validator.isNonEmptyString(v)).length !== 1) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Exactly one of topic, token or condition is required');
|
||||
}
|
||||
validateStringMap(message.data, 'data');
|
||||
validateAndroidConfig(message.android);
|
||||
validateWebpushConfig(message.webpush);
|
||||
validateApnsConfig(message.apns);
|
||||
validateFcmOptions(message.fcmOptions);
|
||||
validateNotification(message.notification);
|
||||
}
|
||||
/**
|
||||
* Checks if the given object only contains strings as child values.
|
||||
*
|
||||
* @param {object} map An object to be validated.
|
||||
* @param {string} label A label to be included in the errors thrown.
|
||||
*/
|
||||
function validateStringMap(map, label) {
|
||||
if (typeof map === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(map)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `${label} must be a non-null object`);
|
||||
}
|
||||
Object.keys(map).forEach((key) => {
|
||||
if (!validator.isString(map[key])) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `${label} must only contain string values`);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Checks if the given WebpushConfig object is valid. The object must have valid headers and data.
|
||||
*
|
||||
* @param {WebpushConfig} config An object to be validated.
|
||||
*/
|
||||
function validateWebpushConfig(config) {
|
||||
if (typeof config === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(config)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'webpush must be a non-null object');
|
||||
}
|
||||
validateStringMap(config.headers, 'webpush.headers');
|
||||
validateStringMap(config.data, 'webpush.data');
|
||||
}
|
||||
/**
|
||||
* Checks if the given ApnsConfig object is valid. The object must have valid headers and a
|
||||
* payload.
|
||||
*
|
||||
* @param {ApnsConfig} config An object to be validated.
|
||||
*/
|
||||
function validateApnsConfig(config) {
|
||||
if (typeof config === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(config)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns must be a non-null object');
|
||||
}
|
||||
validateApnsLiveActivityToken(config.liveActivityToken);
|
||||
validateStringMap(config.headers, 'apns.headers');
|
||||
validateApnsPayload(config.payload);
|
||||
validateApnsFcmOptions(config.fcmOptions);
|
||||
const propertyMappings = {
|
||||
liveActivityToken: 'live_activity_token'
|
||||
};
|
||||
(0, index_1.renameProperties)(config, propertyMappings);
|
||||
}
|
||||
function validateApnsLiveActivityToken(liveActivityToken) {
|
||||
if (typeof liveActivityToken === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isString(liveActivityToken)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.liveActivityToken must be a string value');
|
||||
}
|
||||
else if (!validator.isNonEmptyString(liveActivityToken)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.liveActivityToken must be a non-empty string');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if the given ApnsFcmOptions object is valid.
|
||||
*
|
||||
* @param {ApnsFcmOptions} fcmOptions An object to be validated.
|
||||
*/
|
||||
function validateApnsFcmOptions(fcmOptions) {
|
||||
if (typeof fcmOptions === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(fcmOptions)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'fcmOptions must be a non-null object');
|
||||
}
|
||||
if (typeof fcmOptions.imageUrl !== 'undefined' &&
|
||||
!validator.isURL(fcmOptions.imageUrl)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'imageUrl must be a valid URL string');
|
||||
}
|
||||
if (typeof fcmOptions.analyticsLabel !== 'undefined' && !validator.isString(fcmOptions.analyticsLabel)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'analyticsLabel must be a string value');
|
||||
}
|
||||
const propertyMappings = {
|
||||
imageUrl: 'image',
|
||||
};
|
||||
Object.keys(propertyMappings).forEach((key) => {
|
||||
if (key in fcmOptions && propertyMappings[key] in fcmOptions) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Multiple specifications for ${key} in ApnsFcmOptions`);
|
||||
}
|
||||
});
|
||||
(0, index_1.renameProperties)(fcmOptions, propertyMappings);
|
||||
}
|
||||
/**
|
||||
* Checks if the given FcmOptions object is valid.
|
||||
*
|
||||
* @param {FcmOptions} fcmOptions An object to be validated.
|
||||
*/
|
||||
function validateFcmOptions(fcmOptions) {
|
||||
if (typeof fcmOptions === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(fcmOptions)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'fcmOptions must be a non-null object');
|
||||
}
|
||||
if (typeof fcmOptions.analyticsLabel !== 'undefined' && !validator.isString(fcmOptions.analyticsLabel)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'analyticsLabel must be a string value');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if the given Notification object is valid.
|
||||
*
|
||||
* @param {Notification} notification An object to be validated.
|
||||
*/
|
||||
function validateNotification(notification) {
|
||||
if (typeof notification === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(notification)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'notification must be a non-null object');
|
||||
}
|
||||
if (typeof notification.imageUrl !== 'undefined' && !validator.isURL(notification.imageUrl)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'notification.imageUrl must be a valid URL string');
|
||||
}
|
||||
const propertyMappings = {
|
||||
imageUrl: 'image',
|
||||
};
|
||||
Object.keys(propertyMappings).forEach((key) => {
|
||||
if (key in notification && propertyMappings[key] in notification) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Multiple specifications for ${key} in Notification`);
|
||||
}
|
||||
});
|
||||
(0, index_1.renameProperties)(notification, propertyMappings);
|
||||
}
|
||||
/**
|
||||
* Checks if the given ApnsPayload object is valid. The object must have a valid aps value.
|
||||
*
|
||||
* @param {ApnsPayload} payload An object to be validated.
|
||||
*/
|
||||
function validateApnsPayload(payload) {
|
||||
if (typeof payload === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(payload)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload must be a non-null object');
|
||||
}
|
||||
validateAps(payload.aps);
|
||||
}
|
||||
/**
|
||||
* Checks if the given Aps object is valid. The object must have a valid alert. If the validation
|
||||
* is successful, transforms the input object by renaming the keys to valid APNS payload keys.
|
||||
*
|
||||
* @param {Aps} aps An object to be validated.
|
||||
*/
|
||||
function validateAps(aps) {
|
||||
if (typeof aps === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(aps)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps must be a non-null object');
|
||||
}
|
||||
validateApsAlert(aps.alert);
|
||||
validateApsSound(aps.sound);
|
||||
const propertyMappings = {
|
||||
contentAvailable: 'content-available',
|
||||
mutableContent: 'mutable-content',
|
||||
threadId: 'thread-id',
|
||||
};
|
||||
Object.keys(propertyMappings).forEach((key) => {
|
||||
if (key in aps && propertyMappings[key] in aps) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Multiple specifications for ${key} in Aps`);
|
||||
}
|
||||
});
|
||||
(0, index_1.renameProperties)(aps, propertyMappings);
|
||||
const contentAvailable = aps['content-available'];
|
||||
if (typeof contentAvailable !== 'undefined' && contentAvailable !== 1) {
|
||||
if (contentAvailable === true) {
|
||||
aps['content-available'] = 1;
|
||||
}
|
||||
else {
|
||||
delete aps['content-available'];
|
||||
}
|
||||
}
|
||||
const mutableContent = aps['mutable-content'];
|
||||
if (typeof mutableContent !== 'undefined' && mutableContent !== 1) {
|
||||
if (mutableContent === true) {
|
||||
aps['mutable-content'] = 1;
|
||||
}
|
||||
else {
|
||||
delete aps['mutable-content'];
|
||||
}
|
||||
}
|
||||
}
|
||||
function validateApsSound(sound) {
|
||||
if (typeof sound === 'undefined' || validator.isNonEmptyString(sound)) {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(sound)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.sound must be a non-empty string or a non-null object');
|
||||
}
|
||||
if (!validator.isNonEmptyString(sound.name)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.sound.name must be a non-empty string');
|
||||
}
|
||||
const volume = sound.volume;
|
||||
if (typeof volume !== 'undefined') {
|
||||
if (!validator.isNumber(volume)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.sound.volume must be a number');
|
||||
}
|
||||
if (volume < 0 || volume > 1) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.sound.volume must be in the interval [0, 1]');
|
||||
}
|
||||
}
|
||||
const soundObject = sound;
|
||||
const key = 'critical';
|
||||
const critical = soundObject[key];
|
||||
if (typeof critical !== 'undefined' && critical !== 1) {
|
||||
if (critical === true) {
|
||||
soundObject[key] = 1;
|
||||
}
|
||||
else {
|
||||
delete soundObject[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks if the given alert object is valid. Alert could be a string or a complex object.
|
||||
* If specified as an object, it must have valid localization parameters. If successful, transforms
|
||||
* the input object by renaming the keys to valid APNS payload keys.
|
||||
*
|
||||
* @param {string | ApsAlert} alert An alert string or an object to be validated.
|
||||
*/
|
||||
function validateApsAlert(alert) {
|
||||
if (typeof alert === 'undefined' || validator.isString(alert)) {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(alert)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.alert must be a string or a non-null object');
|
||||
}
|
||||
const apsAlert = alert;
|
||||
if (validator.isNonEmptyArray(apsAlert.locArgs) &&
|
||||
!validator.isNonEmptyString(apsAlert.locKey)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.alert.locKey is required when specifying locArgs');
|
||||
}
|
||||
if (validator.isNonEmptyArray(apsAlert.titleLocArgs) &&
|
||||
!validator.isNonEmptyString(apsAlert.titleLocKey)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.alert.titleLocKey is required when specifying titleLocArgs');
|
||||
}
|
||||
if (validator.isNonEmptyArray(apsAlert.subtitleLocArgs) &&
|
||||
!validator.isNonEmptyString(apsAlert.subtitleLocKey)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.alert.subtitleLocKey is required when specifying subtitleLocArgs');
|
||||
}
|
||||
const propertyMappings = {
|
||||
locKey: 'loc-key',
|
||||
locArgs: 'loc-args',
|
||||
titleLocKey: 'title-loc-key',
|
||||
titleLocArgs: 'title-loc-args',
|
||||
subtitleLocKey: 'subtitle-loc-key',
|
||||
subtitleLocArgs: 'subtitle-loc-args',
|
||||
actionLocKey: 'action-loc-key',
|
||||
launchImage: 'launch-image',
|
||||
};
|
||||
(0, index_1.renameProperties)(apsAlert, propertyMappings);
|
||||
}
|
||||
/**
|
||||
* Checks if the given AndroidConfig object is valid. The object must have valid ttl, data,
|
||||
* and notification fields. If successful, transforms the input object by renaming keys to valid
|
||||
* Android keys. Also transforms the ttl value to the format expected by FCM service.
|
||||
*
|
||||
* @param config - An object to be validated.
|
||||
*/
|
||||
function validateAndroidConfig(config) {
|
||||
if (typeof config === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(config)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android must be a non-null object');
|
||||
}
|
||||
if (typeof config.ttl !== 'undefined') {
|
||||
if (!validator.isNumber(config.ttl) || config.ttl < 0) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'TTL must be a non-negative duration in milliseconds');
|
||||
}
|
||||
const duration = (0, index_1.transformMillisecondsToSecondsString)(config.ttl);
|
||||
config.ttl = duration;
|
||||
}
|
||||
validateStringMap(config.data, 'android.data');
|
||||
validateAndroidNotification(config.notification);
|
||||
validateAndroidFcmOptions(config.fcmOptions);
|
||||
const propertyMappings = {
|
||||
collapseKey: 'collapse_key',
|
||||
restrictedPackageName: 'restricted_package_name',
|
||||
directBootOk: 'direct_boot_ok',
|
||||
};
|
||||
(0, index_1.renameProperties)(config, propertyMappings);
|
||||
}
|
||||
/**
|
||||
* Checks if the given AndroidNotification object is valid. The object must have valid color and
|
||||
* localization parameters. If successful, transforms the input object by renaming keys to valid
|
||||
* Android keys.
|
||||
*
|
||||
* @param {AndroidNotification} notification An object to be validated.
|
||||
*/
|
||||
function validateAndroidNotification(notification) {
|
||||
if (typeof notification === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(notification)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification must be a non-null object');
|
||||
}
|
||||
if (typeof notification.color !== 'undefined' && !/^#[0-9a-fA-F]{6}$/.test(notification.color)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.color must be in the form #RRGGBB');
|
||||
}
|
||||
if (validator.isNonEmptyArray(notification.bodyLocArgs) &&
|
||||
!validator.isNonEmptyString(notification.bodyLocKey)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.bodyLocKey is required when specifying bodyLocArgs');
|
||||
}
|
||||
if (validator.isNonEmptyArray(notification.titleLocArgs) &&
|
||||
!validator.isNonEmptyString(notification.titleLocKey)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.titleLocKey is required when specifying titleLocArgs');
|
||||
}
|
||||
if (typeof notification.imageUrl !== 'undefined' &&
|
||||
!validator.isURL(notification.imageUrl)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.imageUrl must be a valid URL string');
|
||||
}
|
||||
if (typeof notification.eventTimestamp !== 'undefined') {
|
||||
if (!(notification.eventTimestamp instanceof Date)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.eventTimestamp must be a valid `Date` object');
|
||||
}
|
||||
// Convert timestamp to RFC3339 UTC "Zulu" format, example "2014-10-02T15:01:23.045123456Z"
|
||||
const zuluTimestamp = notification.eventTimestamp.toISOString();
|
||||
notification.eventTimestamp = zuluTimestamp;
|
||||
}
|
||||
if (typeof notification.vibrateTimingsMillis !== 'undefined') {
|
||||
if (!validator.isNonEmptyArray(notification.vibrateTimingsMillis)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.vibrateTimingsMillis must be a non-empty array of numbers');
|
||||
}
|
||||
const vibrateTimings = [];
|
||||
notification.vibrateTimingsMillis.forEach((value) => {
|
||||
if (!validator.isNumber(value) || value < 0) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.vibrateTimingsMillis must be non-negative durations in milliseconds');
|
||||
}
|
||||
const duration = (0, index_1.transformMillisecondsToSecondsString)(value);
|
||||
vibrateTimings.push(duration);
|
||||
});
|
||||
notification.vibrateTimingsMillis = vibrateTimings;
|
||||
}
|
||||
if (typeof notification.priority !== 'undefined') {
|
||||
const priority = 'PRIORITY_' + notification.priority.toUpperCase();
|
||||
notification.priority = priority;
|
||||
}
|
||||
if (typeof notification.proxy !== 'undefined') {
|
||||
const proxy = notification.proxy.toUpperCase();
|
||||
notification.proxy = proxy;
|
||||
}
|
||||
if (typeof notification.visibility !== 'undefined') {
|
||||
const visibility = notification.visibility.toUpperCase();
|
||||
notification.visibility = visibility;
|
||||
}
|
||||
validateLightSettings(notification.lightSettings);
|
||||
const propertyMappings = {
|
||||
clickAction: 'click_action',
|
||||
bodyLocKey: 'body_loc_key',
|
||||
bodyLocArgs: 'body_loc_args',
|
||||
titleLocKey: 'title_loc_key',
|
||||
titleLocArgs: 'title_loc_args',
|
||||
channelId: 'channel_id',
|
||||
imageUrl: 'image',
|
||||
eventTimestamp: 'event_time',
|
||||
localOnly: 'local_only',
|
||||
priority: 'notification_priority',
|
||||
vibrateTimingsMillis: 'vibrate_timings',
|
||||
defaultVibrateTimings: 'default_vibrate_timings',
|
||||
defaultSound: 'default_sound',
|
||||
lightSettings: 'light_settings',
|
||||
defaultLightSettings: 'default_light_settings',
|
||||
notificationCount: 'notification_count',
|
||||
};
|
||||
(0, index_1.renameProperties)(notification, propertyMappings);
|
||||
}
|
||||
/**
|
||||
* Checks if the given LightSettings object is valid. The object must have valid color and
|
||||
* light on/off duration parameters. If successful, transforms the input object by renaming
|
||||
* keys to valid Android keys.
|
||||
*
|
||||
* @param {LightSettings} lightSettings An object to be validated.
|
||||
*/
|
||||
function validateLightSettings(lightSettings) {
|
||||
if (typeof lightSettings === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(lightSettings)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.lightSettings must be a non-null object');
|
||||
}
|
||||
if (!validator.isNumber(lightSettings.lightOnDurationMillis) || lightSettings.lightOnDurationMillis < 0) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.lightSettings.lightOnDurationMillis must be a non-negative duration in milliseconds');
|
||||
}
|
||||
const durationOn = (0, index_1.transformMillisecondsToSecondsString)(lightSettings.lightOnDurationMillis);
|
||||
lightSettings.lightOnDurationMillis = durationOn;
|
||||
if (!validator.isNumber(lightSettings.lightOffDurationMillis) || lightSettings.lightOffDurationMillis < 0) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.lightSettings.lightOffDurationMillis must be a non-negative duration in milliseconds');
|
||||
}
|
||||
const durationOff = (0, index_1.transformMillisecondsToSecondsString)(lightSettings.lightOffDurationMillis);
|
||||
lightSettings.lightOffDurationMillis = durationOff;
|
||||
if (!validator.isString(lightSettings.color) ||
|
||||
(!/^#[0-9a-fA-F]{6}$/.test(lightSettings.color) && !/^#[0-9a-fA-F]{8}$/.test(lightSettings.color))) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.lightSettings.color must be in the form #RRGGBB or #RRGGBBAA format');
|
||||
}
|
||||
const colorString = lightSettings.color.length === 7 ? lightSettings.color + 'FF' : lightSettings.color;
|
||||
const rgb = /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/i.exec(colorString);
|
||||
if (!rgb || rgb.length < 4) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INTERNAL_ERROR, 'regex to extract rgba values from ' + colorString + ' failed.');
|
||||
}
|
||||
const color = {
|
||||
red: parseInt(rgb[1], 16) / 255.0,
|
||||
green: parseInt(rgb[2], 16) / 255.0,
|
||||
blue: parseInt(rgb[3], 16) / 255.0,
|
||||
alpha: parseInt(rgb[4], 16) / 255.0,
|
||||
};
|
||||
lightSettings.color = color;
|
||||
const propertyMappings = {
|
||||
lightOnDurationMillis: 'light_on_duration',
|
||||
lightOffDurationMillis: 'light_off_duration',
|
||||
};
|
||||
(0, index_1.renameProperties)(lightSettings, propertyMappings);
|
||||
}
|
||||
/**
|
||||
* Checks if the given AndroidFcmOptions object is valid.
|
||||
*
|
||||
* @param {AndroidFcmOptions} fcmOptions An object to be validated.
|
||||
*/
|
||||
function validateAndroidFcmOptions(fcmOptions) {
|
||||
if (typeof fcmOptions === 'undefined') {
|
||||
return;
|
||||
}
|
||||
else if (!validator.isNonNullObject(fcmOptions)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'fcmOptions must be a non-null object');
|
||||
}
|
||||
if (typeof fcmOptions.analyticsLabel !== 'undefined' && !validator.isString(fcmOptions.analyticsLabel)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'analyticsLabel must be a string value');
|
||||
}
|
||||
}
|
||||
161
server/node_modules/firebase-admin/lib/messaging/messaging-namespace.d.ts
generated
vendored
Normal file
161
server/node_modules/firebase-admin/lib/messaging/messaging-namespace.d.ts
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* Copyright 2021 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 { App } from '../app';
|
||||
import { Messaging as TMessaging } from './messaging';
|
||||
import { AndroidConfig as TAndroidConfig, AndroidFcmOptions as TAndroidFcmOptions, AndroidNotification as TAndroidNotification, ApnsConfig as TApnsConfig, ApnsFcmOptions as TApnsFcmOptions, ApnsPayload as TApnsPayload, Aps as TAps, ApsAlert as TApsAlert, BatchResponse as TBatchResponse, CriticalSound as TCriticalSound, ConditionMessage as TConditionMessage, FcmOptions as TFcmOptions, LightSettings as TLightSettings, Message as TMessage, MessagingTopicManagementResponse as TMessagingTopicManagementResponse, MulticastMessage as TMulticastMessage, Notification as TNotification, SendResponse as TSendResponse, TokenMessage as TTokenMessage, TopicMessage as TTopicMessage, WebpushConfig as TWebpushConfig, WebpushFcmOptions as TWebpushFcmOptions, WebpushNotification as TWebpushNotification, DataMessagePayload as TDataMessagePayload, MessagingOptions as TMessagingOptions, MessagingPayload as TMessagingPayload, NotificationMessagePayload as TNotificationMessagePayload } from './messaging-api';
|
||||
/**
|
||||
* Gets the {@link firebase-admin.messaging#Messaging} service for the
|
||||
* default app or a given app.
|
||||
*
|
||||
* `admin.messaging()` can be called with no arguments to access the default
|
||||
* app's `Messaging` service or as `admin.messaging(app)` to access the
|
||||
* `Messaging` service associated with a specific app.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Messaging service for the default app
|
||||
* var defaultMessaging = admin.messaging();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* // Get the Messaging service for a given app
|
||||
* var otherMessaging = admin.messaging(otherApp);
|
||||
* ```
|
||||
*
|
||||
* @param app - Optional app whose `Messaging` service to
|
||||
* return. If not provided, the default `Messaging` service will be returned.
|
||||
*
|
||||
* @returns The default `Messaging` service if no
|
||||
* app is provided or the `Messaging` service associated with the provided
|
||||
* app.
|
||||
*/
|
||||
export declare function messaging(app?: App): messaging.Messaging;
|
||||
export declare namespace messaging {
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#Messaging}.
|
||||
*/
|
||||
type Messaging = TMessaging;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#AndroidConfig}.
|
||||
*/
|
||||
type AndroidConfig = TAndroidConfig;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#AndroidFcmOptions}.
|
||||
*/
|
||||
type AndroidFcmOptions = TAndroidFcmOptions;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#AndroidNotification}.
|
||||
*/
|
||||
type AndroidNotification = TAndroidNotification;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#ApnsConfig}.
|
||||
*/
|
||||
type ApnsConfig = TApnsConfig;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#ApnsFcmOptions}.
|
||||
*/
|
||||
type ApnsFcmOptions = TApnsFcmOptions;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#ApnsPayload}.
|
||||
*/
|
||||
type ApnsPayload = TApnsPayload;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#Aps}.
|
||||
*/
|
||||
type Aps = TAps;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#ApsAlert}.
|
||||
*/
|
||||
type ApsAlert = TApsAlert;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#BatchResponse}.
|
||||
*/
|
||||
type BatchResponse = TBatchResponse;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#CriticalSound}.
|
||||
*/
|
||||
type CriticalSound = TCriticalSound;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#ConditionMessage}.
|
||||
*/
|
||||
type ConditionMessage = TConditionMessage;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#FcmOptions}.
|
||||
*/
|
||||
type FcmOptions = TFcmOptions;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#LightSettings}.
|
||||
*/
|
||||
type LightSettings = TLightSettings;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#Message}.
|
||||
*/
|
||||
type Message = TMessage;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#MessagingTopicManagementResponse}.
|
||||
*/
|
||||
type MessagingTopicManagementResponse = TMessagingTopicManagementResponse;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#MulticastMessage}.
|
||||
*/
|
||||
type MulticastMessage = TMulticastMessage;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#Notification}.
|
||||
*/
|
||||
type Notification = TNotification;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#SendResponse}.
|
||||
*/
|
||||
type SendResponse = TSendResponse;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#TokenMessage}.
|
||||
*/
|
||||
type TokenMessage = TTokenMessage;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#TopicMessage}.
|
||||
*/
|
||||
type TopicMessage = TTopicMessage;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#WebpushConfig}.
|
||||
*/
|
||||
type WebpushConfig = TWebpushConfig;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#WebpushFcmOptions}.
|
||||
*/
|
||||
type WebpushFcmOptions = TWebpushFcmOptions;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#WebpushNotification}.
|
||||
*/
|
||||
type WebpushNotification = TWebpushNotification;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#DataMessagePayload}.
|
||||
*/
|
||||
type DataMessagePayload = TDataMessagePayload;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#MessagingOptions}.
|
||||
*/
|
||||
type MessagingOptions = TMessagingOptions;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#MessagingPayload}.
|
||||
*/
|
||||
type MessagingPayload = TMessagingPayload;
|
||||
/**
|
||||
* Type alias to {@link firebase-admin.messaging#NotificationMessagePayload}.
|
||||
*/
|
||||
type NotificationMessagePayload = TNotificationMessagePayload;
|
||||
}
|
||||
18
server/node_modules/firebase-admin/lib/messaging/messaging-namespace.js
generated
vendored
Normal file
18
server/node_modules/firebase-admin/lib/messaging/messaging-namespace.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
189
server/node_modules/firebase-admin/lib/messaging/messaging.d.ts
generated
vendored
Normal file
189
server/node_modules/firebase-admin/lib/messaging/messaging.d.ts
generated
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 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 { App } from '../app';
|
||||
import { BatchResponse, Message, MessagingTopicManagementResponse, MulticastMessage } from './messaging-api';
|
||||
/**
|
||||
* Messaging service bound to the provided app.
|
||||
*/
|
||||
export declare class Messaging {
|
||||
private urlPath;
|
||||
private readonly appInternal;
|
||||
private readonly messagingRequestHandler;
|
||||
private useLegacyTransport;
|
||||
/**
|
||||
* The {@link firebase-admin.app#App} associated with the current `Messaging` service
|
||||
* instance.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* var app = messaging.app;
|
||||
* ```
|
||||
*/
|
||||
get app(): App;
|
||||
/**
|
||||
* Enables the use of legacy HTTP/1.1 transport for `sendEach()` and `sendEachForMulticast()`.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* const messaging = getMessaging(app);
|
||||
* messaging.enableLegacyTransport();
|
||||
* messaging.sendEach(messages);
|
||||
* ```
|
||||
*
|
||||
* @deprecated This will be removed when the HTTP/2 transport implementation reaches the same
|
||||
* stability as the legacy HTTP/1.1 implementation.
|
||||
*/
|
||||
enableLegacyHttpTransport(): void;
|
||||
/**
|
||||
* Sends the given message via FCM.
|
||||
*
|
||||
* @param message - The message payload.
|
||||
* @param dryRun - Whether to send the message in the dry-run
|
||||
* (validation only) mode.
|
||||
* @returns A promise fulfilled with a unique message ID
|
||||
* string after the message has been successfully handed off to the FCM
|
||||
* service for delivery.
|
||||
*/
|
||||
send(message: Message, dryRun?: boolean): Promise<string>;
|
||||
/**
|
||||
* Sends each message in the given array via Firebase Cloud Messaging.
|
||||
*
|
||||
* This method makes a single RPC call for each message
|
||||
* in the given array.
|
||||
*
|
||||
* The responses list obtained from the return value corresponds to the order of `messages`.
|
||||
* An error from this method or a `BatchResponse` with all failures indicates a total failure,
|
||||
* meaning that none of the messages in the list could be sent. Partial failures or no
|
||||
* failures are only indicated by a `BatchResponse` return value.
|
||||
*
|
||||
* @param messages - A non-empty array
|
||||
* containing up to 500 messages.
|
||||
* @param dryRun - Whether to send the messages in the dry-run
|
||||
* (validation only) mode.
|
||||
* @returns A Promise fulfilled with an object representing the result of the
|
||||
* send operation.
|
||||
*/
|
||||
sendEach(messages: Message[], dryRun?: boolean): Promise<BatchResponse>;
|
||||
private parseSendResponses;
|
||||
/**
|
||||
* Sends the given multicast message to all the FCM registration tokens
|
||||
* specified in it.
|
||||
*
|
||||
* This method uses the {@link Messaging.sendEach} API under the hood to send the given
|
||||
* message to all the target recipients. The responses list obtained from the
|
||||
* return value corresponds to the order of tokens in the `MulticastMessage`.
|
||||
* An error from this method or a `BatchResponse` with all failures indicates a total
|
||||
* failure, meaning that the messages in the list could be sent. Partial failures or
|
||||
* failures are only indicated by a `BatchResponse` return value.
|
||||
*
|
||||
* @param message - A multicast message
|
||||
* containing up to 500 tokens.
|
||||
* @param dryRun - Whether to send the message in the dry-run
|
||||
* (validation only) mode.
|
||||
* @returns A Promise fulfilled with an object representing the result of the
|
||||
* send operation.
|
||||
*/
|
||||
sendEachForMulticast(message: MulticastMessage, dryRun?: boolean): Promise<BatchResponse>;
|
||||
/**
|
||||
* Subscribes a device to an FCM topic.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/manage-topics#suscribe_and_unsubscribe_using_the |
|
||||
* Subscribe to a topic}
|
||||
* for code samples and detailed documentation. Optionally, you can provide an
|
||||
* array of tokens to subscribe multiple devices.
|
||||
*
|
||||
* @param registrationTokens - A token or array of registration tokens
|
||||
* for the devices to subscribe to the topic.
|
||||
* @param topic - The topic to which to subscribe.
|
||||
*
|
||||
* @returns A promise fulfilled with the server's response after the device has been
|
||||
* subscribed to the topic.
|
||||
*/
|
||||
subscribeToTopic(registrationTokenOrTokens: string | string[], topic: string): Promise<MessagingTopicManagementResponse>;
|
||||
/**
|
||||
* Unsubscribes a device from an FCM topic.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#unsubscribe_from_a_topic |
|
||||
* Unsubscribe from a topic}
|
||||
* for code samples and detailed documentation. Optionally, you can provide an
|
||||
* array of tokens to unsubscribe multiple devices.
|
||||
*
|
||||
* @param registrationTokens - A device registration token or an array of
|
||||
* device registration tokens to unsubscribe from the topic.
|
||||
* @param topic - The topic from which to unsubscribe.
|
||||
*
|
||||
* @returns A promise fulfilled with the server's response after the device has been
|
||||
* unsubscribed from the topic.
|
||||
*/
|
||||
unsubscribeFromTopic(registrationTokenOrTokens: string | string[], topic: string): Promise<MessagingTopicManagementResponse>;
|
||||
private getUrlPath;
|
||||
/**
|
||||
* Helper method which sends and handles topic subscription management requests.
|
||||
*
|
||||
* @param registrationTokenOrTokens - The registration token or an array of
|
||||
* registration tokens to unsubscribe from the topic.
|
||||
* @param topic - The topic to which to subscribe.
|
||||
* @param methodName - The name of the original method called.
|
||||
* @param path - The endpoint path to use for the request.
|
||||
*
|
||||
* @returns A Promise fulfilled with the parsed server
|
||||
* response.
|
||||
*/
|
||||
private sendTopicManagementRequest;
|
||||
/**
|
||||
* Validates the type of the provided registration token(s). If invalid, an error will be thrown.
|
||||
*
|
||||
* @param registrationTokenOrTokens - The registration token(s) to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the registration tokens are invalid.
|
||||
*/
|
||||
private validateRegistrationTokensType;
|
||||
/**
|
||||
* Validates the provided registration tokens. If invalid, an error will be thrown.
|
||||
*
|
||||
* @param registrationTokenOrTokens - The registration token or an array of
|
||||
* registration tokens to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the registration tokens are invalid.
|
||||
*/
|
||||
private validateRegistrationTokens;
|
||||
/**
|
||||
* Validates the type of the provided topic. If invalid, an error will be thrown.
|
||||
*
|
||||
* @param topic - The topic to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the topic is invalid.
|
||||
*/
|
||||
private validateTopicType;
|
||||
/**
|
||||
* Validates the provided topic. If invalid, an error will be thrown.
|
||||
*
|
||||
* @param topic - The topic to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the topic is invalid.
|
||||
*/
|
||||
private validateTopic;
|
||||
/**
|
||||
* Normalizes the provided topic name by prepending it with '/topics/', if necessary.
|
||||
*
|
||||
* @param topic - The topic name to normalize.
|
||||
*
|
||||
* @returns The normalized topic name.
|
||||
*/
|
||||
private normalizeTopic;
|
||||
}
|
||||
442
server/node_modules/firebase-admin/lib/messaging/messaging.js
generated
vendored
Normal file
442
server/node_modules/firebase-admin/lib/messaging/messaging.js
generated
vendored
Normal file
@@ -0,0 +1,442 @@
|
||||
/*! firebase-admin v13.5.0 */
|
||||
"use strict";
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2017 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.
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Messaging = void 0;
|
||||
const deep_copy_1 = require("../utils/deep-copy");
|
||||
const error_1 = require("../utils/error");
|
||||
const utils = require("../utils");
|
||||
const validator = require("../utils/validator");
|
||||
const messaging_internal_1 = require("./messaging-internal");
|
||||
const messaging_api_request_internal_1 = require("./messaging-api-request-internal");
|
||||
const api_request_1 = require("../utils/api-request");
|
||||
// FCM endpoints
|
||||
const FCM_SEND_HOST = 'fcm.googleapis.com';
|
||||
const FCM_TOPIC_MANAGEMENT_HOST = 'iid.googleapis.com';
|
||||
const FCM_TOPIC_MANAGEMENT_ADD_PATH = '/iid/v1:batchAdd';
|
||||
const FCM_TOPIC_MANAGEMENT_REMOVE_PATH = '/iid/v1:batchRemove';
|
||||
// Maximum messages that can be included in a batch request.
|
||||
const FCM_MAX_BATCH_SIZE = 500;
|
||||
/**
|
||||
* Maps a raw FCM server response to a `MessagingTopicManagementResponse` object.
|
||||
*
|
||||
* @param {object} response The raw FCM server response to map.
|
||||
*
|
||||
* @returns {MessagingTopicManagementResponse} The mapped `MessagingTopicManagementResponse` object.
|
||||
*/
|
||||
function mapRawResponseToTopicManagementResponse(response) {
|
||||
// Add the success and failure counts.
|
||||
const result = {
|
||||
successCount: 0,
|
||||
failureCount: 0,
|
||||
errors: [],
|
||||
};
|
||||
if ('results' in response) {
|
||||
response.results.forEach((tokenManagementResult, index) => {
|
||||
// Map the FCM server's error strings to actual error objects.
|
||||
if ('error' in tokenManagementResult) {
|
||||
result.failureCount += 1;
|
||||
const newError = error_1.FirebaseMessagingError.fromTopicManagementServerError(tokenManagementResult.error, /* message */ undefined, tokenManagementResult.error);
|
||||
result.errors.push({
|
||||
index,
|
||||
error: newError,
|
||||
});
|
||||
}
|
||||
else {
|
||||
result.successCount += 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Messaging service bound to the provided app.
|
||||
*/
|
||||
class Messaging {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(app) {
|
||||
this.useLegacyTransport = false;
|
||||
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'First argument passed to admin.messaging() must be a valid Firebase app instance.');
|
||||
}
|
||||
this.appInternal = app;
|
||||
this.messagingRequestHandler = new messaging_api_request_internal_1.FirebaseMessagingRequestHandler(app);
|
||||
}
|
||||
/**
|
||||
* The {@link firebase-admin.app#App} associated with the current `Messaging` service
|
||||
* instance.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* var app = messaging.app;
|
||||
* ```
|
||||
*/
|
||||
get app() {
|
||||
return this.appInternal;
|
||||
}
|
||||
/**
|
||||
* Enables the use of legacy HTTP/1.1 transport for `sendEach()` and `sendEachForMulticast()`.
|
||||
*
|
||||
* @example
|
||||
* ```javascript
|
||||
* const messaging = getMessaging(app);
|
||||
* messaging.enableLegacyTransport();
|
||||
* messaging.sendEach(messages);
|
||||
* ```
|
||||
*
|
||||
* @deprecated This will be removed when the HTTP/2 transport implementation reaches the same
|
||||
* stability as the legacy HTTP/1.1 implementation.
|
||||
*/
|
||||
enableLegacyHttpTransport() {
|
||||
this.useLegacyTransport = true;
|
||||
}
|
||||
/**
|
||||
* Sends the given message via FCM.
|
||||
*
|
||||
* @param message - The message payload.
|
||||
* @param dryRun - Whether to send the message in the dry-run
|
||||
* (validation only) mode.
|
||||
* @returns A promise fulfilled with a unique message ID
|
||||
* string after the message has been successfully handed off to the FCM
|
||||
* service for delivery.
|
||||
*/
|
||||
send(message, dryRun) {
|
||||
const copy = (0, deep_copy_1.deepCopy)(message);
|
||||
(0, messaging_internal_1.validateMessage)(copy);
|
||||
if (typeof dryRun !== 'undefined' && !validator.isBoolean(dryRun)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'dryRun must be a boolean');
|
||||
}
|
||||
return this.getUrlPath()
|
||||
.then((urlPath) => {
|
||||
const request = { message: copy };
|
||||
if (dryRun) {
|
||||
request.validate_only = true;
|
||||
}
|
||||
return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, urlPath, request);
|
||||
})
|
||||
.then((response) => {
|
||||
return response.name;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Sends each message in the given array via Firebase Cloud Messaging.
|
||||
*
|
||||
* This method makes a single RPC call for each message
|
||||
* in the given array.
|
||||
*
|
||||
* The responses list obtained from the return value corresponds to the order of `messages`.
|
||||
* An error from this method or a `BatchResponse` with all failures indicates a total failure,
|
||||
* meaning that none of the messages in the list could be sent. Partial failures or no
|
||||
* failures are only indicated by a `BatchResponse` return value.
|
||||
*
|
||||
* @param messages - A non-empty array
|
||||
* containing up to 500 messages.
|
||||
* @param dryRun - Whether to send the messages in the dry-run
|
||||
* (validation only) mode.
|
||||
* @returns A Promise fulfilled with an object representing the result of the
|
||||
* send operation.
|
||||
*/
|
||||
sendEach(messages, dryRun) {
|
||||
if (validator.isArray(messages) && messages.constructor !== Array) {
|
||||
// In more recent JS specs, an array-like object might have a constructor that is not of
|
||||
// Array type. Our deepCopy() method doesn't handle them properly. Convert such objects to
|
||||
// a regular array here before calling deepCopy(). See issue #566 for details.
|
||||
messages = Array.from(messages);
|
||||
}
|
||||
const copy = (0, deep_copy_1.deepCopy)(messages);
|
||||
if (!validator.isNonEmptyArray(copy)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'messages must be a non-empty array');
|
||||
}
|
||||
if (copy.length > FCM_MAX_BATCH_SIZE) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, `messages list must not contain more than ${FCM_MAX_BATCH_SIZE} items`);
|
||||
}
|
||||
if (typeof dryRun !== 'undefined' && !validator.isBoolean(dryRun)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'dryRun must be a boolean');
|
||||
}
|
||||
const http2SessionHandler = this.useLegacyTransport ? undefined : new api_request_1.Http2SessionHandler(`https://${FCM_SEND_HOST}`);
|
||||
return this.getUrlPath()
|
||||
.then((urlPath) => {
|
||||
if (http2SessionHandler) {
|
||||
let sendResponsePromise;
|
||||
return new Promise((resolve, reject) => {
|
||||
// Start session listeners
|
||||
http2SessionHandler.invoke().catch((error) => {
|
||||
const pendingBatchResponse = sendResponsePromise ? sendResponsePromise.then(this.parseSendResponses) : undefined;
|
||||
reject(new error_1.FirebaseMessagingSessionError(error, undefined, pendingBatchResponse));
|
||||
});
|
||||
// Start making requests
|
||||
const requests = copy.map(async (message) => {
|
||||
(0, messaging_internal_1.validateMessage)(message);
|
||||
const request = { message };
|
||||
if (dryRun) {
|
||||
request.validate_only = true;
|
||||
}
|
||||
return this.messagingRequestHandler.invokeHttp2RequestHandlerForSendResponse(FCM_SEND_HOST, urlPath, request, http2SessionHandler);
|
||||
});
|
||||
// Resolve once all requests have completed
|
||||
sendResponsePromise = Promise.allSettled(requests);
|
||||
sendResponsePromise.then(resolve);
|
||||
});
|
||||
}
|
||||
else {
|
||||
const requests = copy.map(async (message) => {
|
||||
(0, messaging_internal_1.validateMessage)(message);
|
||||
const request = { message };
|
||||
if (dryRun) {
|
||||
request.validate_only = true;
|
||||
}
|
||||
return this.messagingRequestHandler.invokeHttpRequestHandlerForSendResponse(FCM_SEND_HOST, urlPath, request);
|
||||
});
|
||||
return Promise.allSettled(requests);
|
||||
}
|
||||
})
|
||||
.then(this.parseSendResponses)
|
||||
.finally(() => {
|
||||
http2SessionHandler?.close();
|
||||
});
|
||||
}
|
||||
parseSendResponses(results) {
|
||||
const responses = [];
|
||||
results.forEach(result => {
|
||||
if (result.status === 'fulfilled') {
|
||||
responses.push(result.value);
|
||||
}
|
||||
else { // rejected
|
||||
responses.push({ success: false, error: result.reason });
|
||||
}
|
||||
});
|
||||
const successCount = responses.filter((resp) => resp.success).length;
|
||||
return {
|
||||
responses,
|
||||
successCount,
|
||||
failureCount: responses.length - successCount,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Sends the given multicast message to all the FCM registration tokens
|
||||
* specified in it.
|
||||
*
|
||||
* This method uses the {@link Messaging.sendEach} API under the hood to send the given
|
||||
* message to all the target recipients. The responses list obtained from the
|
||||
* return value corresponds to the order of tokens in the `MulticastMessage`.
|
||||
* An error from this method or a `BatchResponse` with all failures indicates a total
|
||||
* failure, meaning that the messages in the list could be sent. Partial failures or
|
||||
* failures are only indicated by a `BatchResponse` return value.
|
||||
*
|
||||
* @param message - A multicast message
|
||||
* containing up to 500 tokens.
|
||||
* @param dryRun - Whether to send the message in the dry-run
|
||||
* (validation only) mode.
|
||||
* @returns A Promise fulfilled with an object representing the result of the
|
||||
* send operation.
|
||||
*/
|
||||
sendEachForMulticast(message, dryRun) {
|
||||
const copy = (0, deep_copy_1.deepCopy)(message);
|
||||
if (!validator.isNonNullObject(copy)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'MulticastMessage must be a non-null object');
|
||||
}
|
||||
if (!validator.isNonEmptyArray(copy.tokens)) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'tokens must be a non-empty array');
|
||||
}
|
||||
if (copy.tokens.length > FCM_MAX_BATCH_SIZE) {
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, `tokens list must not contain more than ${FCM_MAX_BATCH_SIZE} items`);
|
||||
}
|
||||
const messages = copy.tokens.map((token) => {
|
||||
return {
|
||||
token,
|
||||
android: copy.android,
|
||||
apns: copy.apns,
|
||||
data: copy.data,
|
||||
notification: copy.notification,
|
||||
webpush: copy.webpush,
|
||||
fcmOptions: copy.fcmOptions,
|
||||
};
|
||||
});
|
||||
return this.sendEach(messages, dryRun);
|
||||
}
|
||||
/**
|
||||
* Subscribes a device to an FCM topic.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/manage-topics#suscribe_and_unsubscribe_using_the |
|
||||
* Subscribe to a topic}
|
||||
* for code samples and detailed documentation. Optionally, you can provide an
|
||||
* array of tokens to subscribe multiple devices.
|
||||
*
|
||||
* @param registrationTokens - A token or array of registration tokens
|
||||
* for the devices to subscribe to the topic.
|
||||
* @param topic - The topic to which to subscribe.
|
||||
*
|
||||
* @returns A promise fulfilled with the server's response after the device has been
|
||||
* subscribed to the topic.
|
||||
*/
|
||||
subscribeToTopic(registrationTokenOrTokens, topic) {
|
||||
return this.sendTopicManagementRequest(registrationTokenOrTokens, topic, 'subscribeToTopic', FCM_TOPIC_MANAGEMENT_ADD_PATH);
|
||||
}
|
||||
/**
|
||||
* Unsubscribes a device from an FCM topic.
|
||||
*
|
||||
* See {@link https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#unsubscribe_from_a_topic |
|
||||
* Unsubscribe from a topic}
|
||||
* for code samples and detailed documentation. Optionally, you can provide an
|
||||
* array of tokens to unsubscribe multiple devices.
|
||||
*
|
||||
* @param registrationTokens - A device registration token or an array of
|
||||
* device registration tokens to unsubscribe from the topic.
|
||||
* @param topic - The topic from which to unsubscribe.
|
||||
*
|
||||
* @returns A promise fulfilled with the server's response after the device has been
|
||||
* unsubscribed from the topic.
|
||||
*/
|
||||
unsubscribeFromTopic(registrationTokenOrTokens, topic) {
|
||||
return this.sendTopicManagementRequest(registrationTokenOrTokens, topic, 'unsubscribeFromTopic', FCM_TOPIC_MANAGEMENT_REMOVE_PATH);
|
||||
}
|
||||
getUrlPath() {
|
||||
if (this.urlPath) {
|
||||
return Promise.resolve(this.urlPath);
|
||||
}
|
||||
return utils.findProjectId(this.app)
|
||||
.then((projectId) => {
|
||||
if (!validator.isNonEmptyString(projectId)) {
|
||||
// Assert for an explicit project ID (either via AppOptions or the cert itself).
|
||||
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'Failed to determine project ID for Messaging. Initialize the '
|
||||
+ 'SDK with service account credentials or set project ID as an app option. '
|
||||
+ 'Alternatively set the GOOGLE_CLOUD_PROJECT environment variable.');
|
||||
}
|
||||
this.urlPath = `/v1/projects/${projectId}/messages:send`;
|
||||
return this.urlPath;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Helper method which sends and handles topic subscription management requests.
|
||||
*
|
||||
* @param registrationTokenOrTokens - The registration token or an array of
|
||||
* registration tokens to unsubscribe from the topic.
|
||||
* @param topic - The topic to which to subscribe.
|
||||
* @param methodName - The name of the original method called.
|
||||
* @param path - The endpoint path to use for the request.
|
||||
*
|
||||
* @returns A Promise fulfilled with the parsed server
|
||||
* response.
|
||||
*/
|
||||
sendTopicManagementRequest(registrationTokenOrTokens, topic, methodName, path) {
|
||||
this.validateRegistrationTokensType(registrationTokenOrTokens, methodName);
|
||||
this.validateTopicType(topic, methodName);
|
||||
// Prepend the topic with /topics/ if necessary.
|
||||
topic = this.normalizeTopic(topic);
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
// Validate the contents of the input arguments. Because we are now in a promise, any thrown
|
||||
// error will cause this method to return a rejected promise.
|
||||
this.validateRegistrationTokens(registrationTokenOrTokens, methodName);
|
||||
this.validateTopic(topic, methodName);
|
||||
// Ensure the registration token(s) input argument is an array.
|
||||
let registrationTokensArray = registrationTokenOrTokens;
|
||||
if (validator.isString(registrationTokenOrTokens)) {
|
||||
registrationTokensArray = [registrationTokenOrTokens];
|
||||
}
|
||||
const request = {
|
||||
to: topic,
|
||||
registration_tokens: registrationTokensArray,
|
||||
};
|
||||
return this.messagingRequestHandler.invokeRequestHandler(FCM_TOPIC_MANAGEMENT_HOST, path, request);
|
||||
})
|
||||
.then((response) => {
|
||||
return mapRawResponseToTopicManagementResponse(response);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Validates the type of the provided registration token(s). If invalid, an error will be thrown.
|
||||
*
|
||||
* @param registrationTokenOrTokens - The registration token(s) to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the registration tokens are invalid.
|
||||
*/
|
||||
validateRegistrationTokensType(registrationTokenOrTokens, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
||||
if (!validator.isNonEmptyArray(registrationTokenOrTokens) &&
|
||||
!validator.isNonEmptyString(registrationTokenOrTokens)) {
|
||||
throw new error_1.FirebaseMessagingError(errorInfo, `Registration token(s) provided to ${methodName}() must be a non-empty string or a ` +
|
||||
'non-empty array.');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validates the provided registration tokens. If invalid, an error will be thrown.
|
||||
*
|
||||
* @param registrationTokenOrTokens - The registration token or an array of
|
||||
* registration tokens to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the registration tokens are invalid.
|
||||
*/
|
||||
validateRegistrationTokens(registrationTokenOrTokens, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
||||
if (validator.isArray(registrationTokenOrTokens)) {
|
||||
// Validate the array contains no more than 1,000 registration tokens.
|
||||
if (registrationTokenOrTokens.length > 1000) {
|
||||
throw new error_1.FirebaseMessagingError(errorInfo, `Too many registration tokens provided in a single request to ${methodName}(). Batch ` +
|
||||
'your requests to contain no more than 1,000 registration tokens per request.');
|
||||
}
|
||||
// Validate the array contains registration tokens which are non-empty strings.
|
||||
registrationTokenOrTokens.forEach((registrationToken, index) => {
|
||||
if (!validator.isNonEmptyString(registrationToken)) {
|
||||
throw new error_1.FirebaseMessagingError(errorInfo, `Registration token provided to ${methodName}() at index ${index} must be a ` +
|
||||
'non-empty string.');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validates the type of the provided topic. If invalid, an error will be thrown.
|
||||
*
|
||||
* @param topic - The topic to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the topic is invalid.
|
||||
*/
|
||||
validateTopicType(topic, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
||||
if (!validator.isNonEmptyString(topic)) {
|
||||
throw new error_1.FirebaseMessagingError(errorInfo, `Topic provided to ${methodName}() must be a string which matches the format ` +
|
||||
'"/topics/[a-zA-Z0-9-_.~%]+".');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validates the provided topic. If invalid, an error will be thrown.
|
||||
*
|
||||
* @param topic - The topic to validate.
|
||||
* @param method - The method name to use in error messages.
|
||||
* @param errorInfo - The error info to use if the topic is invalid.
|
||||
*/
|
||||
validateTopic(topic, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
||||
if (!validator.isTopic(topic)) {
|
||||
throw new error_1.FirebaseMessagingError(errorInfo, `Topic provided to ${methodName}() must be a string which matches the format ` +
|
||||
'"/topics/[a-zA-Z0-9-_.~%]+".');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Normalizes the provided topic name by prepending it with '/topics/', if necessary.
|
||||
*
|
||||
* @param topic - The topic name to normalize.
|
||||
*
|
||||
* @returns The normalized topic name.
|
||||
*/
|
||||
normalizeTopic(topic) {
|
||||
if (!/^\/topics\//.test(topic)) {
|
||||
topic = `/topics/${topic}`;
|
||||
}
|
||||
return topic;
|
||||
}
|
||||
}
|
||||
exports.Messaging = Messaging;
|
||||
Reference in New Issue
Block a user