firebase-admin 10.3.0 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/lib/app/core.d.ts +1 -1
- package/lib/app/core.js +1 -1
- package/lib/app/credential-factory.d.ts +1 -1
- package/lib/app/credential-factory.js +8 -8
- package/lib/app/credential-internal.d.ts +1 -1
- package/lib/app/credential-internal.js +97 -106
- package/lib/app/credential.d.ts +1 -1
- package/lib/app/credential.js +1 -1
- package/lib/app/firebase-app.d.ts +1 -1
- package/lib/app/firebase-app.js +76 -91
- package/lib/app/firebase-namespace.d.ts +1 -1
- package/lib/app/firebase-namespace.js +209 -279
- package/lib/app/index.d.ts +1 -1
- package/lib/app/index.js +4 -4
- package/lib/app/lifecycle.d.ts +1 -1
- package/lib/app/lifecycle.js +37 -43
- package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
- package/lib/app-check/app-check-api-client-internal.js +54 -73
- package/lib/app-check/app-check-api.d.ts +1 -1
- package/lib/app-check/app-check-api.js +1 -1
- package/lib/app-check/app-check-namespace.d.ts +1 -1
- package/lib/app-check/app-check-namespace.js +1 -1
- package/lib/app-check/app-check.d.ts +1 -1
- package/lib/app-check/app-check.js +17 -19
- package/lib/app-check/index.d.ts +1 -1
- package/lib/app-check/index.js +7 -7
- package/lib/app-check/token-generator.d.ts +1 -1
- package/lib/app-check/token-generator.js +47 -52
- package/lib/app-check/token-verifier.d.ts +1 -1
- package/lib/app-check/token-verifier.js +46 -50
- package/lib/auth/action-code-settings-builder.d.ts +1 -1
- package/lib/auth/action-code-settings-builder.js +10 -11
- package/lib/auth/auth-api-request.d.ts +1 -1
- package/lib/auth/auth-api-request.js +346 -393
- package/lib/auth/auth-config.d.ts +1 -1
- package/lib/auth/auth-config.js +95 -106
- package/lib/auth/auth-namespace.d.ts +1 -1
- package/lib/auth/auth-namespace.js +1 -1
- package/lib/auth/auth.d.ts +1 -1
- package/lib/auth/auth.js +20 -40
- package/lib/auth/base-auth.d.ts +1 -1
- package/lib/auth/base-auth.js +137 -144
- package/lib/auth/identifier.d.ts +1 -1
- package/lib/auth/identifier.js +2 -2
- package/lib/auth/index.d.ts +1 -1
- package/lib/auth/index.js +7 -7
- package/lib/auth/tenant-manager.d.ts +1 -1
- package/lib/auth/tenant-manager.js +49 -71
- package/lib/auth/tenant.d.ts +1 -1
- package/lib/auth/tenant.js +44 -55
- package/lib/auth/token-generator.d.ts +1 -1
- package/lib/auth/token-generator.js +49 -53
- package/lib/auth/token-verifier.d.ts +1 -1
- package/lib/auth/token-verifier.js +83 -91
- package/lib/auth/user-import-builder.d.ts +1 -1
- package/lib/auth/user-import-builder.js +70 -73
- package/lib/auth/user-record.d.ts +1 -1
- package/lib/auth/user-record.js +61 -84
- package/lib/credential/index.d.ts +1 -1
- package/lib/credential/index.js +2 -2
- package/lib/database/database-namespace.d.ts +1 -1
- package/lib/database/database-namespace.js +1 -1
- package/lib/database/database.d.ts +1 -1
- package/lib/database/database.js +92 -108
- package/lib/database/index.d.ts +1 -1
- package/lib/database/index.js +10 -10
- package/lib/default-namespace.d.ts +1 -1
- package/lib/default-namespace.js +2 -2
- package/lib/eventarc/cloudevent.d.ts +1 -1
- package/lib/eventarc/cloudevent.js +1 -1
- package/lib/eventarc/eventarc-client-internal.d.ts +1 -1
- package/lib/eventarc/eventarc-client-internal.js +63 -129
- package/lib/eventarc/eventarc-utils.d.ts +1 -1
- package/lib/eventarc/eventarc-utils.js +16 -32
- package/lib/eventarc/eventarc.d.ts +1 -1
- package/lib/eventarc/eventarc.js +51 -65
- package/lib/eventarc/index.d.ts +1 -1
- package/lib/eventarc/index.js +7 -7
- package/lib/firebase-namespace-api.d.ts +1 -1
- package/lib/firebase-namespace-api.js +8 -3
- package/lib/firestore/firestore-internal.d.ts +1 -1
- package/lib/firestore/firestore-internal.js +28 -37
- package/lib/firestore/firestore-namespace.d.ts +9 -1
- package/lib/firestore/firestore-namespace.js +2 -2
- package/lib/firestore/index.d.ts +2 -2
- package/lib/firestore/index.js +7 -7
- package/lib/functions/functions-api-client-internal.d.ts +1 -1
- package/lib/functions/functions-api-client-internal.js +71 -93
- package/lib/functions/functions-api.d.ts +1 -1
- package/lib/functions/functions-api.js +1 -1
- package/lib/functions/functions.d.ts +1 -1
- package/lib/functions/functions.js +13 -15
- package/lib/functions/index.d.ts +1 -1
- package/lib/functions/index.js +7 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +14 -4
- package/lib/installations/index.d.ts +1 -1
- package/lib/installations/index.js +6 -6
- package/lib/installations/installations-namespace.d.ts +1 -1
- package/lib/installations/installations-namespace.js +1 -1
- package/lib/installations/installations-request-handler.d.ts +1 -1
- package/lib/installations/installations-request-handler.js +33 -36
- package/lib/installations/installations.d.ts +1 -1
- package/lib/installations/installations.js +17 -22
- package/lib/instance-id/index.d.ts +1 -1
- package/lib/instance-id/index.js +6 -6
- package/lib/instance-id/instance-id-namespace.d.ts +1 -1
- package/lib/instance-id/instance-id-namespace.js +1 -1
- package/lib/instance-id/instance-id.d.ts +1 -1
- package/lib/instance-id/instance-id.js +21 -26
- package/lib/machine-learning/index.d.ts +1 -1
- package/lib/machine-learning/index.js +7 -7
- package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
- package/lib/machine-learning/machine-learning-api-client.js +110 -124
- package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
- package/lib/machine-learning/machine-learning-namespace.js +1 -1
- package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
- package/lib/machine-learning/machine-learning-utils.js +9 -24
- package/lib/machine-learning/machine-learning.d.ts +1 -1
- package/lib/machine-learning/machine-learning.js +146 -207
- package/lib/messaging/batch-request-internal.d.ts +1 -1
- package/lib/messaging/batch-request-internal.js +33 -35
- package/lib/messaging/index.d.ts +1 -1
- package/lib/messaging/index.js +7 -7
- package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
- package/lib/messaging/messaging-api-request-internal.js +38 -40
- package/lib/messaging/messaging-api.d.ts +1 -1
- package/lib/messaging/messaging-api.js +1 -1
- package/lib/messaging/messaging-errors-internal.d.ts +1 -1
- package/lib/messaging/messaging-errors-internal.js +12 -13
- package/lib/messaging/messaging-internal.d.ts +1 -1
- package/lib/messaging/messaging-internal.js +51 -51
- package/lib/messaging/messaging-namespace.d.ts +1 -1
- package/lib/messaging/messaging-namespace.js +1 -1
- package/lib/messaging/messaging.d.ts +1 -1
- package/lib/messaging/messaging.js +184 -208
- package/lib/project-management/android-app.d.ts +1 -1
- package/lib/project-management/android-app.js +41 -43
- package/lib/project-management/app-metadata.d.ts +1 -1
- package/lib/project-management/app-metadata.js +1 -1
- package/lib/project-management/index.d.ts +1 -1
- package/lib/project-management/index.js +7 -7
- package/lib/project-management/ios-app.d.ts +1 -1
- package/lib/project-management/ios-app.js +25 -26
- package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
- package/lib/project-management/project-management-api-request-internal.js +84 -89
- package/lib/project-management/project-management-namespace.d.ts +1 -1
- package/lib/project-management/project-management-namespace.js +1 -1
- package/lib/project-management/project-management.d.ts +1 -1
- package/lib/project-management/project-management.js +80 -87
- package/lib/remote-config/index.d.ts +1 -1
- package/lib/remote-config/index.js +7 -7
- package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
- package/lib/remote-config/remote-config-api-client-internal.js +116 -154
- package/lib/remote-config/remote-config-api.d.ts +1 -1
- package/lib/remote-config/remote-config-api.js +1 -1
- package/lib/remote-config/remote-config-namespace.d.ts +1 -1
- package/lib/remote-config/remote-config-namespace.js +1 -1
- package/lib/remote-config/remote-config.d.ts +1 -1
- package/lib/remote-config/remote-config.js +51 -59
- package/lib/security-rules/index.d.ts +1 -1
- package/lib/security-rules/index.js +7 -7
- package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-api-client-internal.js +95 -107
- package/lib/security-rules/security-rules-internal.d.ts +1 -1
- package/lib/security-rules/security-rules-internal.js +6 -21
- package/lib/security-rules/security-rules-namespace.d.ts +1 -1
- package/lib/security-rules/security-rules-namespace.js +1 -1
- package/lib/security-rules/security-rules.d.ts +1 -1
- package/lib/security-rules/security-rules.js +82 -91
- package/lib/storage/index.d.ts +1 -1
- package/lib/storage/index.js +7 -7
- package/lib/storage/storage-namespace.d.ts +1 -1
- package/lib/storage/storage-namespace.js +1 -1
- package/lib/storage/storage.d.ts +1 -1
- package/lib/storage/storage.js +25 -30
- package/lib/utils/api-request.d.ts +3 -1
- package/lib/utils/api-request.js +278 -356
- package/lib/utils/crypto-signer.d.ts +1 -1
- package/lib/utils/crypto-signer.js +58 -93
- package/lib/utils/deep-copy.d.ts +1 -1
- package/lib/utils/deep-copy.js +3 -3
- package/lib/utils/error.d.ts +1 -1
- package/lib/utils/error.js +611 -681
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +38 -43
- package/lib/utils/jwt.d.ts +1 -1
- package/lib/utils/jwt.js +97 -123
- package/lib/utils/validator.d.ts +1 -1
- package/lib/utils/validator.js +13 -13
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -16,35 +16,24 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
var __assign = (this && this.__assign) || function () {
|
|
20
|
-
__assign = Object.assign || function(t) {
|
|
21
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
22
|
-
s = arguments[i];
|
|
23
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
24
|
-
t[p] = s[p];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
};
|
|
28
|
-
return __assign.apply(this, arguments);
|
|
29
|
-
};
|
|
30
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
20
|
exports.Messaging = void 0;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
const deep_copy_1 = require("../utils/deep-copy");
|
|
22
|
+
const error_1 = require("../utils/error");
|
|
23
|
+
const utils = require("../utils");
|
|
24
|
+
const validator = require("../utils/validator");
|
|
25
|
+
const messaging_internal_1 = require("./messaging-internal");
|
|
26
|
+
const messaging_api_request_internal_1 = require("./messaging-api-request-internal");
|
|
38
27
|
// FCM endpoints
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
const FCM_SEND_HOST = 'fcm.googleapis.com';
|
|
29
|
+
const FCM_SEND_PATH = '/fcm/send';
|
|
30
|
+
const FCM_TOPIC_MANAGEMENT_HOST = 'iid.googleapis.com';
|
|
31
|
+
const FCM_TOPIC_MANAGEMENT_ADD_PATH = '/iid/v1:batchAdd';
|
|
32
|
+
const FCM_TOPIC_MANAGEMENT_REMOVE_PATH = '/iid/v1:batchRemove';
|
|
44
33
|
// Maximum messages that can be included in a batch request.
|
|
45
|
-
|
|
34
|
+
const FCM_MAX_BATCH_SIZE = 500;
|
|
46
35
|
// Key renames for the messaging notification payload object.
|
|
47
|
-
|
|
36
|
+
const CAMELCASED_NOTIFICATION_PAYLOAD_KEYS_MAP = {
|
|
48
37
|
bodyLocArgs: 'body_loc_args',
|
|
49
38
|
bodyLocKey: 'body_loc_key',
|
|
50
39
|
clickAction: 'click_action',
|
|
@@ -52,7 +41,7 @@ var CAMELCASED_NOTIFICATION_PAYLOAD_KEYS_MAP = {
|
|
|
52
41
|
titleLocKey: 'title_loc_key',
|
|
53
42
|
};
|
|
54
43
|
// Key renames for the messaging options object.
|
|
55
|
-
|
|
44
|
+
const CAMELCASE_OPTIONS_KEYS_MAP = {
|
|
56
45
|
dryRun: 'dry_run',
|
|
57
46
|
timeToLive: 'time_to_live',
|
|
58
47
|
collapseKey: 'collapse_key',
|
|
@@ -61,29 +50,29 @@ var CAMELCASE_OPTIONS_KEYS_MAP = {
|
|
|
61
50
|
restrictedPackageName: 'restricted_package_name',
|
|
62
51
|
};
|
|
63
52
|
// Key renames for the MessagingDeviceResult object.
|
|
64
|
-
|
|
53
|
+
const MESSAGING_DEVICE_RESULT_KEYS_MAP = {
|
|
65
54
|
message_id: 'messageId',
|
|
66
55
|
registration_id: 'canonicalRegistrationToken',
|
|
67
56
|
};
|
|
68
57
|
// Key renames for the MessagingDevicesResponse object.
|
|
69
|
-
|
|
58
|
+
const MESSAGING_DEVICES_RESPONSE_KEYS_MAP = {
|
|
70
59
|
canonical_ids: 'canonicalRegistrationTokenCount',
|
|
71
60
|
failure: 'failureCount',
|
|
72
61
|
success: 'successCount',
|
|
73
62
|
multicast_id: 'multicastId',
|
|
74
63
|
};
|
|
75
64
|
// Key renames for the MessagingDeviceGroupResponse object.
|
|
76
|
-
|
|
65
|
+
const MESSAGING_DEVICE_GROUP_RESPONSE_KEYS_MAP = {
|
|
77
66
|
success: 'successCount',
|
|
78
67
|
failure: 'failureCount',
|
|
79
68
|
failed_registration_ids: 'failedRegistrationTokens',
|
|
80
69
|
};
|
|
81
70
|
// Key renames for the MessagingTopicResponse object.
|
|
82
|
-
|
|
71
|
+
const MESSAGING_TOPIC_RESPONSE_KEYS_MAP = {
|
|
83
72
|
message_id: 'messageId',
|
|
84
73
|
};
|
|
85
74
|
// Key renames for the MessagingConditionResponse object.
|
|
86
|
-
|
|
75
|
+
const MESSAGING_CONDITION_RESPONSE_KEYS_MAP = {
|
|
87
76
|
message_id: 'messageId',
|
|
88
77
|
};
|
|
89
78
|
/**
|
|
@@ -97,11 +86,11 @@ function mapRawResponseToDevicesResponse(response) {
|
|
|
97
86
|
// Rename properties on the server response
|
|
98
87
|
utils.renameProperties(response, MESSAGING_DEVICES_RESPONSE_KEYS_MAP);
|
|
99
88
|
if ('results' in response) {
|
|
100
|
-
response.results.forEach(
|
|
89
|
+
response.results.forEach((messagingDeviceResult) => {
|
|
101
90
|
utils.renameProperties(messagingDeviceResult, MESSAGING_DEVICE_RESULT_KEYS_MAP);
|
|
102
91
|
// Map the FCM server's error strings to actual error objects.
|
|
103
92
|
if ('error' in messagingDeviceResult) {
|
|
104
|
-
|
|
93
|
+
const newError = error_1.FirebaseMessagingError.fromServerError(messagingDeviceResult.error, /* message */ undefined, messagingDeviceResult.error);
|
|
105
94
|
messagingDeviceResult.error = newError;
|
|
106
95
|
}
|
|
107
96
|
});
|
|
@@ -132,19 +121,19 @@ function mapRawResponseToDeviceGroupResponse(response) {
|
|
|
132
121
|
*/
|
|
133
122
|
function mapRawResponseToTopicManagementResponse(response) {
|
|
134
123
|
// Add the success and failure counts.
|
|
135
|
-
|
|
124
|
+
const result = {
|
|
136
125
|
successCount: 0,
|
|
137
126
|
failureCount: 0,
|
|
138
127
|
errors: [],
|
|
139
128
|
};
|
|
140
129
|
if ('results' in response) {
|
|
141
|
-
response.results.forEach(
|
|
130
|
+
response.results.forEach((tokenManagementResult, index) => {
|
|
142
131
|
// Map the FCM server's error strings to actual error objects.
|
|
143
132
|
if ('error' in tokenManagementResult) {
|
|
144
133
|
result.failureCount += 1;
|
|
145
|
-
|
|
134
|
+
const newError = error_1.FirebaseMessagingError.fromTopicManagementServerError(tokenManagementResult.error, /* message */ undefined, tokenManagementResult.error);
|
|
146
135
|
result.errors.push({
|
|
147
|
-
index
|
|
136
|
+
index,
|
|
148
137
|
error: newError,
|
|
149
138
|
});
|
|
150
139
|
}
|
|
@@ -158,33 +147,29 @@ function mapRawResponseToTopicManagementResponse(response) {
|
|
|
158
147
|
/**
|
|
159
148
|
* Messaging service bound to the provided app.
|
|
160
149
|
*/
|
|
161
|
-
|
|
150
|
+
class Messaging {
|
|
162
151
|
/**
|
|
163
152
|
* @internal
|
|
164
153
|
*/
|
|
165
|
-
|
|
154
|
+
constructor(app) {
|
|
166
155
|
if (!validator.isNonNullObject(app) || !('options' in app)) {
|
|
167
156
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'First argument passed to admin.messaging() must be a valid Firebase app instance.');
|
|
168
157
|
}
|
|
169
158
|
this.appInternal = app;
|
|
170
159
|
this.messagingRequestHandler = new messaging_api_request_internal_1.FirebaseMessagingRequestHandler(app);
|
|
171
160
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
},
|
|
185
|
-
enumerable: false,
|
|
186
|
-
configurable: true
|
|
187
|
-
});
|
|
161
|
+
/**
|
|
162
|
+
* The {@link firebase-admin.app#App} associated with the current `Messaging` service
|
|
163
|
+
* instance.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```javascript
|
|
167
|
+
* var app = messaging.app;
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
get app() {
|
|
171
|
+
return this.appInternal;
|
|
172
|
+
}
|
|
188
173
|
/**
|
|
189
174
|
* Sends the given message via FCM.
|
|
190
175
|
*
|
|
@@ -195,25 +180,24 @@ var Messaging = /** @class */ (function () {
|
|
|
195
180
|
* string after the message has been successfully handed off to the FCM
|
|
196
181
|
* service for delivery.
|
|
197
182
|
*/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
messaging_internal_1.validateMessage(copy);
|
|
183
|
+
send(message, dryRun) {
|
|
184
|
+
const copy = (0, deep_copy_1.deepCopy)(message);
|
|
185
|
+
(0, messaging_internal_1.validateMessage)(copy);
|
|
202
186
|
if (typeof dryRun !== 'undefined' && !validator.isBoolean(dryRun)) {
|
|
203
187
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'dryRun must be a boolean');
|
|
204
188
|
}
|
|
205
189
|
return this.getUrlPath()
|
|
206
|
-
.then(
|
|
207
|
-
|
|
190
|
+
.then((urlPath) => {
|
|
191
|
+
const request = { message: copy };
|
|
208
192
|
if (dryRun) {
|
|
209
193
|
request.validate_only = true;
|
|
210
194
|
}
|
|
211
|
-
return
|
|
195
|
+
return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, urlPath, request);
|
|
212
196
|
})
|
|
213
|
-
.then(
|
|
197
|
+
.then((response) => {
|
|
214
198
|
return response.name;
|
|
215
199
|
});
|
|
216
|
-
}
|
|
200
|
+
}
|
|
217
201
|
/**
|
|
218
202
|
* Sends all the messages in the given array via Firebase Cloud Messaging.
|
|
219
203
|
* Employs batching to send the entire list as a single RPC call. Compared
|
|
@@ -233,40 +217,39 @@ var Messaging = /** @class */ (function () {
|
|
|
233
217
|
* @returns A Promise fulfilled with an object representing the result of the
|
|
234
218
|
* send operation.
|
|
235
219
|
*/
|
|
236
|
-
|
|
237
|
-
var _this = this;
|
|
220
|
+
sendAll(messages, dryRun) {
|
|
238
221
|
if (validator.isArray(messages) && messages.constructor !== Array) {
|
|
239
222
|
// In more recent JS specs, an array-like object might have a constructor that is not of
|
|
240
223
|
// Array type. Our deepCopy() method doesn't handle them properly. Convert such objects to
|
|
241
224
|
// a regular array here before calling deepCopy(). See issue #566 for details.
|
|
242
225
|
messages = Array.from(messages);
|
|
243
226
|
}
|
|
244
|
-
|
|
227
|
+
const copy = (0, deep_copy_1.deepCopy)(messages);
|
|
245
228
|
if (!validator.isNonEmptyArray(copy)) {
|
|
246
229
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'messages must be a non-empty array');
|
|
247
230
|
}
|
|
248
231
|
if (copy.length > FCM_MAX_BATCH_SIZE) {
|
|
249
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT,
|
|
232
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, `messages list must not contain more than ${FCM_MAX_BATCH_SIZE} items`);
|
|
250
233
|
}
|
|
251
234
|
if (typeof dryRun !== 'undefined' && !validator.isBoolean(dryRun)) {
|
|
252
235
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'dryRun must be a boolean');
|
|
253
236
|
}
|
|
254
237
|
return this.getUrlPath()
|
|
255
|
-
.then(
|
|
256
|
-
|
|
257
|
-
messaging_internal_1.validateMessage(message);
|
|
258
|
-
|
|
238
|
+
.then((urlPath) => {
|
|
239
|
+
const requests = copy.map((message) => {
|
|
240
|
+
(0, messaging_internal_1.validateMessage)(message);
|
|
241
|
+
const request = { message };
|
|
259
242
|
if (dryRun) {
|
|
260
243
|
request.validate_only = true;
|
|
261
244
|
}
|
|
262
245
|
return {
|
|
263
|
-
url:
|
|
246
|
+
url: `https://${FCM_SEND_HOST}${urlPath}`,
|
|
264
247
|
body: request,
|
|
265
248
|
};
|
|
266
249
|
});
|
|
267
|
-
return
|
|
250
|
+
return this.messagingRequestHandler.sendBatchRequest(requests);
|
|
268
251
|
});
|
|
269
|
-
}
|
|
252
|
+
}
|
|
270
253
|
/**
|
|
271
254
|
* Sends the given multicast message to all the FCM registration tokens
|
|
272
255
|
* specified in it.
|
|
@@ -285,8 +268,8 @@ var Messaging = /** @class */ (function () {
|
|
|
285
268
|
* @returns A Promise fulfilled with an object representing the result of the
|
|
286
269
|
* send operation.
|
|
287
270
|
*/
|
|
288
|
-
|
|
289
|
-
|
|
271
|
+
sendMulticast(message, dryRun) {
|
|
272
|
+
const copy = (0, deep_copy_1.deepCopy)(message);
|
|
290
273
|
if (!validator.isNonNullObject(copy)) {
|
|
291
274
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'MulticastMessage must be a non-null object');
|
|
292
275
|
}
|
|
@@ -294,11 +277,11 @@ var Messaging = /** @class */ (function () {
|
|
|
294
277
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'tokens must be a non-empty array');
|
|
295
278
|
}
|
|
296
279
|
if (copy.tokens.length > FCM_MAX_BATCH_SIZE) {
|
|
297
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT,
|
|
280
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, `tokens list must not contain more than ${FCM_MAX_BATCH_SIZE} items`);
|
|
298
281
|
}
|
|
299
|
-
|
|
282
|
+
const messages = copy.tokens.map((token) => {
|
|
300
283
|
return {
|
|
301
|
-
token
|
|
284
|
+
token,
|
|
302
285
|
android: copy.android,
|
|
303
286
|
apns: copy.apns,
|
|
304
287
|
data: copy.data,
|
|
@@ -308,7 +291,7 @@ var Messaging = /** @class */ (function () {
|
|
|
308
291
|
};
|
|
309
292
|
});
|
|
310
293
|
return this.sendAll(messages, dryRun);
|
|
311
|
-
}
|
|
294
|
+
}
|
|
312
295
|
/**
|
|
313
296
|
* Sends an FCM message to a single device corresponding to the provided
|
|
314
297
|
* registration token.
|
|
@@ -329,31 +312,29 @@ var Messaging = /** @class */ (function () {
|
|
|
329
312
|
* @returns A promise fulfilled with the server's response after the message
|
|
330
313
|
* has been sent.
|
|
331
314
|
*/
|
|
332
|
-
|
|
333
|
-
var _this = this;
|
|
334
|
-
if (options === void 0) { options = {}; }
|
|
315
|
+
sendToDevice(registrationTokenOrTokens, payload, options = {}) {
|
|
335
316
|
// Validate the input argument types. Since these are common developer errors when getting
|
|
336
317
|
// started, throw an error instead of returning a rejected promise.
|
|
337
318
|
this.validateRegistrationTokensType(registrationTokenOrTokens, 'sendToDevice', error_1.MessagingClientErrorCode.INVALID_RECIPIENT);
|
|
338
319
|
this.validateMessagingPayloadAndOptionsTypes(payload, options);
|
|
339
320
|
return Promise.resolve()
|
|
340
|
-
.then(
|
|
321
|
+
.then(() => {
|
|
341
322
|
// Validate the contents of the input arguments. Because we are now in a promise, any thrown
|
|
342
323
|
// error will cause this method to return a rejected promise.
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
deep_copy_1.deepExtend(request, optionsCopy);
|
|
324
|
+
this.validateRegistrationTokens(registrationTokenOrTokens, 'sendToDevice', error_1.MessagingClientErrorCode.INVALID_RECIPIENT);
|
|
325
|
+
const payloadCopy = this.validateMessagingPayload(payload);
|
|
326
|
+
const optionsCopy = this.validateMessagingOptions(options);
|
|
327
|
+
const request = (0, deep_copy_1.deepCopy)(payloadCopy);
|
|
328
|
+
(0, deep_copy_1.deepExtend)(request, optionsCopy);
|
|
348
329
|
if (validator.isString(registrationTokenOrTokens)) {
|
|
349
330
|
request.to = registrationTokenOrTokens;
|
|
350
331
|
}
|
|
351
332
|
else {
|
|
352
333
|
request.registration_ids = registrationTokenOrTokens;
|
|
353
334
|
}
|
|
354
|
-
return
|
|
335
|
+
return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
|
|
355
336
|
})
|
|
356
|
-
.then(
|
|
337
|
+
.then((response) => {
|
|
357
338
|
// The sendToDevice() and sendToDeviceGroup() methods both set the `to` query parameter in
|
|
358
339
|
// the underlying FCM request. If the provided registration token argument is actually a
|
|
359
340
|
// valid notification key, the response from the FCM server will be a device group response.
|
|
@@ -363,11 +344,16 @@ var Messaging = /** @class */ (function () {
|
|
|
363
344
|
return mapRawResponseToDevicesResponse(response);
|
|
364
345
|
}
|
|
365
346
|
else {
|
|
366
|
-
|
|
367
|
-
return
|
|
347
|
+
const groupResponse = mapRawResponseToDeviceGroupResponse(response);
|
|
348
|
+
return {
|
|
349
|
+
...groupResponse,
|
|
350
|
+
canonicalRegistrationTokenCount: -1,
|
|
351
|
+
multicastId: -1,
|
|
352
|
+
results: [],
|
|
353
|
+
};
|
|
368
354
|
}
|
|
369
355
|
});
|
|
370
|
-
}
|
|
356
|
+
}
|
|
371
357
|
/**
|
|
372
358
|
* Sends an FCM message to a device group corresponding to the provided
|
|
373
359
|
* notification key.
|
|
@@ -384,9 +370,7 @@ var Messaging = /** @class */ (function () {
|
|
|
384
370
|
* @returns A promise fulfilled with the server's response after the message
|
|
385
371
|
* has been sent.
|
|
386
372
|
*/
|
|
387
|
-
|
|
388
|
-
var _this = this;
|
|
389
|
-
if (options === void 0) { options = {}; }
|
|
373
|
+
sendToDeviceGroup(notificationKey, payload, options = {}) {
|
|
390
374
|
if (!validator.isNonEmptyString(notificationKey)) {
|
|
391
375
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_RECIPIENT, 'Notification key provided to sendToDeviceGroup() must be a non-empty string.');
|
|
392
376
|
}
|
|
@@ -403,17 +387,17 @@ var Messaging = /** @class */ (function () {
|
|
|
403
387
|
// errors, throw an error instead of returning a rejected promise.
|
|
404
388
|
this.validateMessagingPayloadAndOptionsTypes(payload, options);
|
|
405
389
|
return Promise.resolve()
|
|
406
|
-
.then(
|
|
390
|
+
.then(() => {
|
|
407
391
|
// Validate the contents of the payload and options objects. Because we are now in a
|
|
408
392
|
// promise, any thrown error will cause this method to return a rejected promise.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
deep_copy_1.deepExtend(request, optionsCopy);
|
|
393
|
+
const payloadCopy = this.validateMessagingPayload(payload);
|
|
394
|
+
const optionsCopy = this.validateMessagingOptions(options);
|
|
395
|
+
const request = (0, deep_copy_1.deepCopy)(payloadCopy);
|
|
396
|
+
(0, deep_copy_1.deepExtend)(request, optionsCopy);
|
|
413
397
|
request.to = notificationKey;
|
|
414
|
-
return
|
|
398
|
+
return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
|
|
415
399
|
})
|
|
416
|
-
.then(
|
|
400
|
+
.then((response) => {
|
|
417
401
|
// The sendToDevice() and sendToDeviceGroup() methods both set the `to` query parameter in
|
|
418
402
|
// the underlying FCM request. If the provided notification key argument has an invalid
|
|
419
403
|
// format (that is, it is either a registration token or some random string), the response
|
|
@@ -427,13 +411,16 @@ var Messaging = /** @class */ (function () {
|
|
|
427
411
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_RECIPIENT, 'Notification key provided to sendToDeviceGroup() is invalid.');
|
|
428
412
|
}
|
|
429
413
|
else {
|
|
430
|
-
|
|
431
|
-
return
|
|
414
|
+
const devicesResponse = mapRawResponseToDevicesResponse(response);
|
|
415
|
+
return {
|
|
416
|
+
...devicesResponse,
|
|
417
|
+
failedRegistrationTokens: [],
|
|
418
|
+
};
|
|
432
419
|
}
|
|
433
420
|
}
|
|
434
421
|
return mapRawResponseToDeviceGroupResponse(response);
|
|
435
422
|
});
|
|
436
|
-
}
|
|
423
|
+
}
|
|
437
424
|
/**
|
|
438
425
|
* Sends an FCM message to a topic.
|
|
439
426
|
*
|
|
@@ -448,9 +435,7 @@ var Messaging = /** @class */ (function () {
|
|
|
448
435
|
* @returns A promise fulfilled with the server's response after the message
|
|
449
436
|
* has been sent.
|
|
450
437
|
*/
|
|
451
|
-
|
|
452
|
-
var _this = this;
|
|
453
|
-
if (options === void 0) { options = {}; }
|
|
438
|
+
sendToTopic(topic, payload, options = {}) {
|
|
454
439
|
// Validate the input argument types. Since these are common developer errors when getting
|
|
455
440
|
// started, throw an error instead of returning a rejected promise.
|
|
456
441
|
this.validateTopicType(topic, 'sendToTopic', error_1.MessagingClientErrorCode.INVALID_RECIPIENT);
|
|
@@ -458,23 +443,23 @@ var Messaging = /** @class */ (function () {
|
|
|
458
443
|
// Prepend the topic with /topics/ if necessary.
|
|
459
444
|
topic = this.normalizeTopic(topic);
|
|
460
445
|
return Promise.resolve()
|
|
461
|
-
.then(
|
|
446
|
+
.then(() => {
|
|
462
447
|
// Validate the contents of the payload and options objects. Because we are now in a
|
|
463
448
|
// promise, any thrown error will cause this method to return a rejected promise.
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
deep_copy_1.deepExtend(request, optionsCopy);
|
|
449
|
+
const payloadCopy = this.validateMessagingPayload(payload);
|
|
450
|
+
const optionsCopy = this.validateMessagingOptions(options);
|
|
451
|
+
this.validateTopic(topic, 'sendToTopic', error_1.MessagingClientErrorCode.INVALID_RECIPIENT);
|
|
452
|
+
const request = (0, deep_copy_1.deepCopy)(payloadCopy);
|
|
453
|
+
(0, deep_copy_1.deepExtend)(request, optionsCopy);
|
|
469
454
|
request.to = topic;
|
|
470
|
-
return
|
|
455
|
+
return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
|
|
471
456
|
})
|
|
472
|
-
.then(
|
|
457
|
+
.then((response) => {
|
|
473
458
|
// Rename properties on the server response
|
|
474
459
|
utils.renameProperties(response, MESSAGING_TOPIC_RESPONSE_KEYS_MAP);
|
|
475
460
|
return response;
|
|
476
461
|
});
|
|
477
|
-
}
|
|
462
|
+
}
|
|
478
463
|
/**
|
|
479
464
|
* Sends an FCM message to a condition.
|
|
480
465
|
*
|
|
@@ -491,9 +476,7 @@ var Messaging = /** @class */ (function () {
|
|
|
491
476
|
* @returns A promise fulfilled with the server's response after the message
|
|
492
477
|
* has been sent.
|
|
493
478
|
*/
|
|
494
|
-
|
|
495
|
-
var _this = this;
|
|
496
|
-
if (options === void 0) { options = {}; }
|
|
479
|
+
sendToCondition(condition, payload, options = {}) {
|
|
497
480
|
if (!validator.isNonEmptyString(condition)) {
|
|
498
481
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_RECIPIENT, 'Condition provided to sendToCondition() must be a non-empty string.');
|
|
499
482
|
}
|
|
@@ -506,22 +489,22 @@ var Messaging = /** @class */ (function () {
|
|
|
506
489
|
// single quotes.
|
|
507
490
|
condition = condition.replace(/"/g, '\'');
|
|
508
491
|
return Promise.resolve()
|
|
509
|
-
.then(
|
|
492
|
+
.then(() => {
|
|
510
493
|
// Validate the contents of the payload and options objects. Because we are now in a
|
|
511
494
|
// promise, any thrown error will cause this method to return a rejected promise.
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
deep_copy_1.deepExtend(request, optionsCopy);
|
|
495
|
+
const payloadCopy = this.validateMessagingPayload(payload);
|
|
496
|
+
const optionsCopy = this.validateMessagingOptions(options);
|
|
497
|
+
const request = (0, deep_copy_1.deepCopy)(payloadCopy);
|
|
498
|
+
(0, deep_copy_1.deepExtend)(request, optionsCopy);
|
|
516
499
|
request.condition = condition;
|
|
517
|
-
return
|
|
500
|
+
return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
|
|
518
501
|
})
|
|
519
|
-
.then(
|
|
502
|
+
.then((response) => {
|
|
520
503
|
// Rename properties on the server response
|
|
521
504
|
utils.renameProperties(response, MESSAGING_CONDITION_RESPONSE_KEYS_MAP);
|
|
522
505
|
return response;
|
|
523
506
|
});
|
|
524
|
-
}
|
|
507
|
+
}
|
|
525
508
|
/**
|
|
526
509
|
* Subscribes a device to an FCM topic.
|
|
527
510
|
*
|
|
@@ -537,9 +520,9 @@ var Messaging = /** @class */ (function () {
|
|
|
537
520
|
* @returns A promise fulfilled with the server's response after the device has been
|
|
538
521
|
* subscribed to the topic.
|
|
539
522
|
*/
|
|
540
|
-
|
|
523
|
+
subscribeToTopic(registrationTokenOrTokens, topic) {
|
|
541
524
|
return this.sendTopicManagementRequest(registrationTokenOrTokens, topic, 'subscribeToTopic', FCM_TOPIC_MANAGEMENT_ADD_PATH);
|
|
542
|
-
}
|
|
525
|
+
}
|
|
543
526
|
/**
|
|
544
527
|
* Unsubscribes a device from an FCM topic.
|
|
545
528
|
*
|
|
@@ -555,26 +538,25 @@ var Messaging = /** @class */ (function () {
|
|
|
555
538
|
* @returns A promise fulfilled with the server's response after the device has been
|
|
556
539
|
* unsubscribed from the topic.
|
|
557
540
|
*/
|
|
558
|
-
|
|
541
|
+
unsubscribeFromTopic(registrationTokenOrTokens, topic) {
|
|
559
542
|
return this.sendTopicManagementRequest(registrationTokenOrTokens, topic, 'unsubscribeFromTopic', FCM_TOPIC_MANAGEMENT_REMOVE_PATH);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
var _this = this;
|
|
543
|
+
}
|
|
544
|
+
getUrlPath() {
|
|
563
545
|
if (this.urlPath) {
|
|
564
546
|
return Promise.resolve(this.urlPath);
|
|
565
547
|
}
|
|
566
548
|
return utils.findProjectId(this.app)
|
|
567
|
-
.then(
|
|
549
|
+
.then((projectId) => {
|
|
568
550
|
if (!validator.isNonEmptyString(projectId)) {
|
|
569
551
|
// Assert for an explicit project ID (either via AppOptions or the cert itself).
|
|
570
552
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_ARGUMENT, 'Failed to determine project ID for Messaging. Initialize the '
|
|
571
553
|
+ 'SDK with service account credentials or set project ID as an app option. '
|
|
572
554
|
+ 'Alternatively set the GOOGLE_CLOUD_PROJECT environment variable.');
|
|
573
555
|
}
|
|
574
|
-
|
|
575
|
-
return
|
|
556
|
+
this.urlPath = `/v1/projects/${projectId}/messages:send`;
|
|
557
|
+
return this.urlPath;
|
|
576
558
|
});
|
|
577
|
-
}
|
|
559
|
+
}
|
|
578
560
|
/**
|
|
579
561
|
* Helper method which sends and handles topic subscription management requests.
|
|
580
562
|
*
|
|
@@ -587,40 +569,39 @@ var Messaging = /** @class */ (function () {
|
|
|
587
569
|
* @returns A Promise fulfilled with the parsed server
|
|
588
570
|
* response.
|
|
589
571
|
*/
|
|
590
|
-
|
|
591
|
-
var _this = this;
|
|
572
|
+
sendTopicManagementRequest(registrationTokenOrTokens, topic, methodName, path) {
|
|
592
573
|
this.validateRegistrationTokensType(registrationTokenOrTokens, methodName);
|
|
593
574
|
this.validateTopicType(topic, methodName);
|
|
594
575
|
// Prepend the topic with /topics/ if necessary.
|
|
595
576
|
topic = this.normalizeTopic(topic);
|
|
596
577
|
return Promise.resolve()
|
|
597
|
-
.then(
|
|
578
|
+
.then(() => {
|
|
598
579
|
// Validate the contents of the input arguments. Because we are now in a promise, any thrown
|
|
599
580
|
// error will cause this method to return a rejected promise.
|
|
600
|
-
|
|
601
|
-
|
|
581
|
+
this.validateRegistrationTokens(registrationTokenOrTokens, methodName);
|
|
582
|
+
this.validateTopic(topic, methodName);
|
|
602
583
|
// Ensure the registration token(s) input argument is an array.
|
|
603
|
-
|
|
584
|
+
let registrationTokensArray = registrationTokenOrTokens;
|
|
604
585
|
if (validator.isString(registrationTokenOrTokens)) {
|
|
605
586
|
registrationTokensArray = [registrationTokenOrTokens];
|
|
606
587
|
}
|
|
607
|
-
|
|
588
|
+
const request = {
|
|
608
589
|
to: topic,
|
|
609
590
|
registration_tokens: registrationTokensArray,
|
|
610
591
|
};
|
|
611
|
-
return
|
|
592
|
+
return this.messagingRequestHandler.invokeRequestHandler(FCM_TOPIC_MANAGEMENT_HOST, path, request);
|
|
612
593
|
})
|
|
613
|
-
.then(
|
|
594
|
+
.then((response) => {
|
|
614
595
|
return mapRawResponseToTopicManagementResponse(response);
|
|
615
596
|
});
|
|
616
|
-
}
|
|
597
|
+
}
|
|
617
598
|
/**
|
|
618
599
|
* Validates the types of the messaging payload and options. If invalid, an error will be thrown.
|
|
619
600
|
*
|
|
620
601
|
* @param payload - The messaging payload to validate.
|
|
621
602
|
* @param options - The messaging options to validate.
|
|
622
603
|
*/
|
|
623
|
-
|
|
604
|
+
validateMessagingPayloadAndOptionsTypes(payload, options) {
|
|
624
605
|
// Validate the payload is an object
|
|
625
606
|
if (!validator.isNonNullObject(payload)) {
|
|
626
607
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Messaging payload must be an object with at least one of the "data" or "notification" properties.');
|
|
@@ -629,7 +610,7 @@ var Messaging = /** @class */ (function () {
|
|
|
629
610
|
if (!validator.isNonNullObject(options)) {
|
|
630
611
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, 'Messaging options must be an object.');
|
|
631
612
|
}
|
|
632
|
-
}
|
|
613
|
+
}
|
|
633
614
|
/**
|
|
634
615
|
* Validates the messaging payload. If invalid, an error will be thrown.
|
|
635
616
|
*
|
|
@@ -638,15 +619,15 @@ var Messaging = /** @class */ (function () {
|
|
|
638
619
|
* @returns A copy of the provided payload with whitelisted properties switched
|
|
639
620
|
* from camelCase to underscore_case.
|
|
640
621
|
*/
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
payloadKeys.forEach(
|
|
622
|
+
validateMessagingPayload(payload) {
|
|
623
|
+
const payloadCopy = (0, deep_copy_1.deepCopy)(payload);
|
|
624
|
+
const payloadKeys = Object.keys(payloadCopy);
|
|
625
|
+
const validPayloadKeys = ['data', 'notification'];
|
|
626
|
+
let containsDataOrNotificationKey = false;
|
|
627
|
+
payloadKeys.forEach((payloadKey) => {
|
|
647
628
|
// Validate the payload does not contain any invalid keys
|
|
648
629
|
if (validPayloadKeys.indexOf(payloadKey) === -1) {
|
|
649
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
630
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Messaging payload contains an invalid "${payloadKey}" property. Valid properties are ` +
|
|
650
631
|
'"data" and "notification".');
|
|
651
632
|
}
|
|
652
633
|
else {
|
|
@@ -657,21 +638,21 @@ var Messaging = /** @class */ (function () {
|
|
|
657
638
|
if (!containsDataOrNotificationKey) {
|
|
658
639
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Messaging payload must contain at least one of the "data" or "notification" properties.');
|
|
659
640
|
}
|
|
660
|
-
|
|
641
|
+
const validatePayload = (payloadKey, value) => {
|
|
661
642
|
// Validate each top-level key in the payload is an object
|
|
662
643
|
if (!validator.isNonNullObject(value)) {
|
|
663
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
644
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Messaging payload contains an invalid value for the "${payloadKey}" property. ` +
|
|
664
645
|
'Value must be an object.');
|
|
665
646
|
}
|
|
666
|
-
Object.keys(value).forEach(
|
|
647
|
+
Object.keys(value).forEach((subKey) => {
|
|
667
648
|
if (!validator.isString(value[subKey])) {
|
|
668
649
|
// Validate all sub-keys have a string value
|
|
669
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
650
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Messaging payload contains an invalid value for the "${payloadKey}.${subKey}" ` +
|
|
670
651
|
'property. Values must be strings.');
|
|
671
652
|
}
|
|
672
653
|
else if (payloadKey === 'data' && /^google\./.test(subKey)) {
|
|
673
654
|
// Validate the data payload does not contain keys which start with 'google.'.
|
|
674
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
655
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Messaging payload contains the blacklisted "data.${subKey}" property.`);
|
|
675
656
|
}
|
|
676
657
|
});
|
|
677
658
|
};
|
|
@@ -683,9 +664,9 @@ var Messaging = /** @class */ (function () {
|
|
|
683
664
|
}
|
|
684
665
|
// Validate the data payload object does not contain blacklisted properties
|
|
685
666
|
if ('data' in payloadCopy) {
|
|
686
|
-
messaging_internal_1.BLACKLISTED_DATA_PAYLOAD_KEYS.forEach(
|
|
667
|
+
messaging_internal_1.BLACKLISTED_DATA_PAYLOAD_KEYS.forEach((blacklistedKey) => {
|
|
687
668
|
if (blacklistedKey in payloadCopy.data) {
|
|
688
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
669
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Messaging payload contains the blacklisted "data.${blacklistedKey}" property.`);
|
|
689
670
|
}
|
|
690
671
|
});
|
|
691
672
|
}
|
|
@@ -694,7 +675,7 @@ var Messaging = /** @class */ (function () {
|
|
|
694
675
|
utils.renameProperties(payloadCopy.notification, CAMELCASED_NOTIFICATION_PAYLOAD_KEYS_MAP);
|
|
695
676
|
}
|
|
696
677
|
return payloadCopy;
|
|
697
|
-
}
|
|
678
|
+
}
|
|
698
679
|
/**
|
|
699
680
|
* Validates the messaging options. If invalid, an error will be thrown.
|
|
700
681
|
*
|
|
@@ -703,25 +684,25 @@ var Messaging = /** @class */ (function () {
|
|
|
703
684
|
* @returns A copy of the provided options with whitelisted properties switched
|
|
704
685
|
* from camelCase to underscore_case.
|
|
705
686
|
*/
|
|
706
|
-
|
|
707
|
-
|
|
687
|
+
validateMessagingOptions(options) {
|
|
688
|
+
const optionsCopy = (0, deep_copy_1.deepCopy)(options);
|
|
708
689
|
// Validate the options object does not contain blacklisted properties
|
|
709
|
-
messaging_internal_1.BLACKLISTED_OPTIONS_KEYS.forEach(
|
|
690
|
+
messaging_internal_1.BLACKLISTED_OPTIONS_KEYS.forEach((blacklistedKey) => {
|
|
710
691
|
if (blacklistedKey in optionsCopy) {
|
|
711
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS,
|
|
692
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, `Messaging options contains the blacklisted "${blacklistedKey}" property.`);
|
|
712
693
|
}
|
|
713
694
|
});
|
|
714
695
|
// Convert whitelisted camelCase keys to underscore_case
|
|
715
696
|
utils.renameProperties(optionsCopy, CAMELCASE_OPTIONS_KEYS_MAP);
|
|
716
697
|
// Validate the options object contains valid values for whitelisted properties
|
|
717
698
|
if ('collapse_key' in optionsCopy && !validator.isNonEmptyString(optionsCopy.collapse_key)) {
|
|
718
|
-
|
|
719
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS,
|
|
699
|
+
const keyName = ('collapseKey' in options) ? 'collapseKey' : 'collapse_key';
|
|
700
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, `Messaging options contains an invalid value for the "${keyName}" property. Value must ` +
|
|
720
701
|
'be a non-empty string.');
|
|
721
702
|
}
|
|
722
703
|
else if ('dry_run' in optionsCopy && !validator.isBoolean(optionsCopy.dry_run)) {
|
|
723
|
-
|
|
724
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS,
|
|
704
|
+
const keyName = ('dryRun' in options) ? 'dryRun' : 'dry_run';
|
|
705
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, `Messaging options contains an invalid value for the "${keyName}" property. Value must ` +
|
|
725
706
|
'be a boolean.');
|
|
726
707
|
}
|
|
727
708
|
else if ('priority' in optionsCopy && !validator.isNonEmptyString(optionsCopy.priority)) {
|
|
@@ -730,27 +711,27 @@ var Messaging = /** @class */ (function () {
|
|
|
730
711
|
}
|
|
731
712
|
else if ('restricted_package_name' in optionsCopy &&
|
|
732
713
|
!validator.isNonEmptyString(optionsCopy.restricted_package_name)) {
|
|
733
|
-
|
|
734
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS,
|
|
714
|
+
const keyName = ('restrictedPackageName' in options) ? 'restrictedPackageName' : 'restricted_package_name';
|
|
715
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, `Messaging options contains an invalid value for the "${keyName}" property. Value must ` +
|
|
735
716
|
'be a non-empty string.');
|
|
736
717
|
}
|
|
737
718
|
else if ('time_to_live' in optionsCopy && !validator.isNumber(optionsCopy.time_to_live)) {
|
|
738
|
-
|
|
739
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS,
|
|
719
|
+
const keyName = ('timeToLive' in options) ? 'timeToLive' : 'time_to_live';
|
|
720
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, `Messaging options contains an invalid value for the "${keyName}" property. Value must ` +
|
|
740
721
|
'be a number.');
|
|
741
722
|
}
|
|
742
723
|
else if ('content_available' in optionsCopy && !validator.isBoolean(optionsCopy.content_available)) {
|
|
743
|
-
|
|
744
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS,
|
|
724
|
+
const keyName = ('contentAvailable' in options) ? 'contentAvailable' : 'content_available';
|
|
725
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, `Messaging options contains an invalid value for the "${keyName}" property. Value must ` +
|
|
745
726
|
'be a boolean.');
|
|
746
727
|
}
|
|
747
728
|
else if ('mutable_content' in optionsCopy && !validator.isBoolean(optionsCopy.mutable_content)) {
|
|
748
|
-
|
|
749
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS,
|
|
729
|
+
const keyName = ('mutableContent' in options) ? 'mutableContent' : 'mutable_content';
|
|
730
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, `Messaging options contains an invalid value for the "${keyName}" property. Value must ` +
|
|
750
731
|
'be a boolean.');
|
|
751
732
|
}
|
|
752
733
|
return optionsCopy;
|
|
753
|
-
}
|
|
734
|
+
}
|
|
754
735
|
/**
|
|
755
736
|
* Validates the type of the provided registration token(s). If invalid, an error will be thrown.
|
|
756
737
|
*
|
|
@@ -758,14 +739,13 @@ var Messaging = /** @class */ (function () {
|
|
|
758
739
|
* @param method - The method name to use in error messages.
|
|
759
740
|
* @param errorInfo - The error info to use if the registration tokens are invalid.
|
|
760
741
|
*/
|
|
761
|
-
|
|
762
|
-
if (errorInfo === void 0) { errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT; }
|
|
742
|
+
validateRegistrationTokensType(registrationTokenOrTokens, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
|
763
743
|
if (!validator.isNonEmptyArray(registrationTokenOrTokens) &&
|
|
764
744
|
!validator.isNonEmptyString(registrationTokenOrTokens)) {
|
|
765
|
-
throw new error_1.FirebaseMessagingError(errorInfo,
|
|
745
|
+
throw new error_1.FirebaseMessagingError(errorInfo, `Registration token(s) provided to ${methodName}() must be a non-empty string or a ` +
|
|
766
746
|
'non-empty array.');
|
|
767
747
|
}
|
|
768
|
-
}
|
|
748
|
+
}
|
|
769
749
|
/**
|
|
770
750
|
* Validates the provided registration tokens. If invalid, an error will be thrown.
|
|
771
751
|
*
|
|
@@ -774,23 +754,22 @@ var Messaging = /** @class */ (function () {
|
|
|
774
754
|
* @param method - The method name to use in error messages.
|
|
775
755
|
* @param errorInfo - The error info to use if the registration tokens are invalid.
|
|
776
756
|
*/
|
|
777
|
-
|
|
778
|
-
if (errorInfo === void 0) { errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT; }
|
|
757
|
+
validateRegistrationTokens(registrationTokenOrTokens, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
|
779
758
|
if (validator.isArray(registrationTokenOrTokens)) {
|
|
780
759
|
// Validate the array contains no more than 1,000 registration tokens.
|
|
781
760
|
if (registrationTokenOrTokens.length > 1000) {
|
|
782
|
-
throw new error_1.FirebaseMessagingError(errorInfo,
|
|
761
|
+
throw new error_1.FirebaseMessagingError(errorInfo, `Too many registration tokens provided in a single request to ${methodName}(). Batch ` +
|
|
783
762
|
'your requests to contain no more than 1,000 registration tokens per request.');
|
|
784
763
|
}
|
|
785
764
|
// Validate the array contains registration tokens which are non-empty strings.
|
|
786
|
-
registrationTokenOrTokens.forEach(
|
|
765
|
+
registrationTokenOrTokens.forEach((registrationToken, index) => {
|
|
787
766
|
if (!validator.isNonEmptyString(registrationToken)) {
|
|
788
|
-
throw new error_1.FirebaseMessagingError(errorInfo,
|
|
767
|
+
throw new error_1.FirebaseMessagingError(errorInfo, `Registration token provided to ${methodName}() at index ${index} must be a ` +
|
|
789
768
|
'non-empty string.');
|
|
790
769
|
}
|
|
791
770
|
});
|
|
792
771
|
}
|
|
793
|
-
}
|
|
772
|
+
}
|
|
794
773
|
/**
|
|
795
774
|
* Validates the type of the provided topic. If invalid, an error will be thrown.
|
|
796
775
|
*
|
|
@@ -798,13 +777,12 @@ var Messaging = /** @class */ (function () {
|
|
|
798
777
|
* @param method - The method name to use in error messages.
|
|
799
778
|
* @param errorInfo - The error info to use if the topic is invalid.
|
|
800
779
|
*/
|
|
801
|
-
|
|
802
|
-
if (errorInfo === void 0) { errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT; }
|
|
780
|
+
validateTopicType(topic, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
|
803
781
|
if (!validator.isNonEmptyString(topic)) {
|
|
804
|
-
throw new error_1.FirebaseMessagingError(errorInfo,
|
|
782
|
+
throw new error_1.FirebaseMessagingError(errorInfo, `Topic provided to ${methodName}() must be a string which matches the format ` +
|
|
805
783
|
'"/topics/[a-zA-Z0-9-_.~%]+".');
|
|
806
784
|
}
|
|
807
|
-
}
|
|
785
|
+
}
|
|
808
786
|
/**
|
|
809
787
|
* Validates the provided topic. If invalid, an error will be thrown.
|
|
810
788
|
*
|
|
@@ -812,13 +790,12 @@ var Messaging = /** @class */ (function () {
|
|
|
812
790
|
* @param method - The method name to use in error messages.
|
|
813
791
|
* @param errorInfo - The error info to use if the topic is invalid.
|
|
814
792
|
*/
|
|
815
|
-
|
|
816
|
-
if (errorInfo === void 0) { errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT; }
|
|
793
|
+
validateTopic(topic, methodName, errorInfo = error_1.MessagingClientErrorCode.INVALID_ARGUMENT) {
|
|
817
794
|
if (!validator.isTopic(topic)) {
|
|
818
|
-
throw new error_1.FirebaseMessagingError(errorInfo,
|
|
795
|
+
throw new error_1.FirebaseMessagingError(errorInfo, `Topic provided to ${methodName}() must be a string which matches the format ` +
|
|
819
796
|
'"/topics/[a-zA-Z0-9-_.~%]+".');
|
|
820
797
|
}
|
|
821
|
-
}
|
|
798
|
+
}
|
|
822
799
|
/**
|
|
823
800
|
* Normalizes the provided topic name by prepending it with '/topics/', if necessary.
|
|
824
801
|
*
|
|
@@ -826,12 +803,11 @@ var Messaging = /** @class */ (function () {
|
|
|
826
803
|
*
|
|
827
804
|
* @returns The normalized topic name.
|
|
828
805
|
*/
|
|
829
|
-
|
|
806
|
+
normalizeTopic(topic) {
|
|
830
807
|
if (!/^\/topics\//.test(topic)) {
|
|
831
|
-
topic =
|
|
808
|
+
topic = `/topics/${topic}`;
|
|
832
809
|
}
|
|
833
810
|
return topic;
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
}());
|
|
811
|
+
}
|
|
812
|
+
}
|
|
837
813
|
exports.Messaging = Messaging;
|