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.
Files changed (192) hide show
  1. package/README.md +1 -2
  2. package/lib/app/core.d.ts +1 -1
  3. package/lib/app/core.js +1 -1
  4. package/lib/app/credential-factory.d.ts +1 -1
  5. package/lib/app/credential-factory.js +8 -8
  6. package/lib/app/credential-internal.d.ts +1 -1
  7. package/lib/app/credential-internal.js +97 -106
  8. package/lib/app/credential.d.ts +1 -1
  9. package/lib/app/credential.js +1 -1
  10. package/lib/app/firebase-app.d.ts +1 -1
  11. package/lib/app/firebase-app.js +76 -91
  12. package/lib/app/firebase-namespace.d.ts +1 -1
  13. package/lib/app/firebase-namespace.js +209 -279
  14. package/lib/app/index.d.ts +1 -1
  15. package/lib/app/index.js +4 -4
  16. package/lib/app/lifecycle.d.ts +1 -1
  17. package/lib/app/lifecycle.js +37 -43
  18. package/lib/app-check/app-check-api-client-internal.d.ts +1 -1
  19. package/lib/app-check/app-check-api-client-internal.js +54 -73
  20. package/lib/app-check/app-check-api.d.ts +1 -1
  21. package/lib/app-check/app-check-api.js +1 -1
  22. package/lib/app-check/app-check-namespace.d.ts +1 -1
  23. package/lib/app-check/app-check-namespace.js +1 -1
  24. package/lib/app-check/app-check.d.ts +1 -1
  25. package/lib/app-check/app-check.js +17 -19
  26. package/lib/app-check/index.d.ts +1 -1
  27. package/lib/app-check/index.js +7 -7
  28. package/lib/app-check/token-generator.d.ts +1 -1
  29. package/lib/app-check/token-generator.js +47 -52
  30. package/lib/app-check/token-verifier.d.ts +1 -1
  31. package/lib/app-check/token-verifier.js +46 -50
  32. package/lib/auth/action-code-settings-builder.d.ts +1 -1
  33. package/lib/auth/action-code-settings-builder.js +10 -11
  34. package/lib/auth/auth-api-request.d.ts +1 -1
  35. package/lib/auth/auth-api-request.js +346 -393
  36. package/lib/auth/auth-config.d.ts +1 -1
  37. package/lib/auth/auth-config.js +95 -106
  38. package/lib/auth/auth-namespace.d.ts +1 -1
  39. package/lib/auth/auth-namespace.js +1 -1
  40. package/lib/auth/auth.d.ts +1 -1
  41. package/lib/auth/auth.js +20 -40
  42. package/lib/auth/base-auth.d.ts +1 -1
  43. package/lib/auth/base-auth.js +137 -144
  44. package/lib/auth/identifier.d.ts +1 -1
  45. package/lib/auth/identifier.js +2 -2
  46. package/lib/auth/index.d.ts +1 -1
  47. package/lib/auth/index.js +7 -7
  48. package/lib/auth/tenant-manager.d.ts +1 -1
  49. package/lib/auth/tenant-manager.js +49 -71
  50. package/lib/auth/tenant.d.ts +1 -1
  51. package/lib/auth/tenant.js +44 -55
  52. package/lib/auth/token-generator.d.ts +1 -1
  53. package/lib/auth/token-generator.js +49 -53
  54. package/lib/auth/token-verifier.d.ts +1 -1
  55. package/lib/auth/token-verifier.js +83 -91
  56. package/lib/auth/user-import-builder.d.ts +1 -1
  57. package/lib/auth/user-import-builder.js +70 -73
  58. package/lib/auth/user-record.d.ts +1 -1
  59. package/lib/auth/user-record.js +61 -84
  60. package/lib/credential/index.d.ts +1 -1
  61. package/lib/credential/index.js +2 -2
  62. package/lib/database/database-namespace.d.ts +1 -1
  63. package/lib/database/database-namespace.js +1 -1
  64. package/lib/database/database.d.ts +1 -1
  65. package/lib/database/database.js +92 -108
  66. package/lib/database/index.d.ts +1 -1
  67. package/lib/database/index.js +10 -10
  68. package/lib/default-namespace.d.ts +1 -1
  69. package/lib/default-namespace.js +2 -2
  70. package/lib/eventarc/cloudevent.d.ts +1 -1
  71. package/lib/eventarc/cloudevent.js +1 -1
  72. package/lib/eventarc/eventarc-client-internal.d.ts +1 -1
  73. package/lib/eventarc/eventarc-client-internal.js +63 -129
  74. package/lib/eventarc/eventarc-utils.d.ts +1 -1
  75. package/lib/eventarc/eventarc-utils.js +16 -32
  76. package/lib/eventarc/eventarc.d.ts +1 -1
  77. package/lib/eventarc/eventarc.js +51 -65
  78. package/lib/eventarc/index.d.ts +1 -1
  79. package/lib/eventarc/index.js +7 -7
  80. package/lib/firebase-namespace-api.d.ts +1 -1
  81. package/lib/firebase-namespace-api.js +8 -3
  82. package/lib/firestore/firestore-internal.d.ts +1 -1
  83. package/lib/firestore/firestore-internal.js +28 -37
  84. package/lib/firestore/firestore-namespace.d.ts +9 -1
  85. package/lib/firestore/firestore-namespace.js +2 -2
  86. package/lib/firestore/index.d.ts +2 -2
  87. package/lib/firestore/index.js +7 -7
  88. package/lib/functions/functions-api-client-internal.d.ts +1 -1
  89. package/lib/functions/functions-api-client-internal.js +71 -93
  90. package/lib/functions/functions-api.d.ts +1 -1
  91. package/lib/functions/functions-api.js +1 -1
  92. package/lib/functions/functions.d.ts +1 -1
  93. package/lib/functions/functions.js +13 -15
  94. package/lib/functions/index.d.ts +1 -1
  95. package/lib/functions/index.js +7 -7
  96. package/lib/index.d.ts +1 -1
  97. package/lib/index.js +14 -4
  98. package/lib/installations/index.d.ts +1 -1
  99. package/lib/installations/index.js +6 -6
  100. package/lib/installations/installations-namespace.d.ts +1 -1
  101. package/lib/installations/installations-namespace.js +1 -1
  102. package/lib/installations/installations-request-handler.d.ts +1 -1
  103. package/lib/installations/installations-request-handler.js +33 -36
  104. package/lib/installations/installations.d.ts +1 -1
  105. package/lib/installations/installations.js +17 -22
  106. package/lib/instance-id/index.d.ts +1 -1
  107. package/lib/instance-id/index.js +6 -6
  108. package/lib/instance-id/instance-id-namespace.d.ts +1 -1
  109. package/lib/instance-id/instance-id-namespace.js +1 -1
  110. package/lib/instance-id/instance-id.d.ts +1 -1
  111. package/lib/instance-id/instance-id.js +21 -26
  112. package/lib/machine-learning/index.d.ts +1 -1
  113. package/lib/machine-learning/index.js +7 -7
  114. package/lib/machine-learning/machine-learning-api-client.d.ts +1 -1
  115. package/lib/machine-learning/machine-learning-api-client.js +110 -124
  116. package/lib/machine-learning/machine-learning-namespace.d.ts +1 -1
  117. package/lib/machine-learning/machine-learning-namespace.js +1 -1
  118. package/lib/machine-learning/machine-learning-utils.d.ts +1 -1
  119. package/lib/machine-learning/machine-learning-utils.js +9 -24
  120. package/lib/machine-learning/machine-learning.d.ts +1 -1
  121. package/lib/machine-learning/machine-learning.js +146 -207
  122. package/lib/messaging/batch-request-internal.d.ts +1 -1
  123. package/lib/messaging/batch-request-internal.js +33 -35
  124. package/lib/messaging/index.d.ts +1 -1
  125. package/lib/messaging/index.js +7 -7
  126. package/lib/messaging/messaging-api-request-internal.d.ts +1 -1
  127. package/lib/messaging/messaging-api-request-internal.js +38 -40
  128. package/lib/messaging/messaging-api.d.ts +1 -1
  129. package/lib/messaging/messaging-api.js +1 -1
  130. package/lib/messaging/messaging-errors-internal.d.ts +1 -1
  131. package/lib/messaging/messaging-errors-internal.js +12 -13
  132. package/lib/messaging/messaging-internal.d.ts +1 -1
  133. package/lib/messaging/messaging-internal.js +51 -51
  134. package/lib/messaging/messaging-namespace.d.ts +1 -1
  135. package/lib/messaging/messaging-namespace.js +1 -1
  136. package/lib/messaging/messaging.d.ts +1 -1
  137. package/lib/messaging/messaging.js +184 -208
  138. package/lib/project-management/android-app.d.ts +1 -1
  139. package/lib/project-management/android-app.js +41 -43
  140. package/lib/project-management/app-metadata.d.ts +1 -1
  141. package/lib/project-management/app-metadata.js +1 -1
  142. package/lib/project-management/index.d.ts +1 -1
  143. package/lib/project-management/index.js +7 -7
  144. package/lib/project-management/ios-app.d.ts +1 -1
  145. package/lib/project-management/ios-app.js +25 -26
  146. package/lib/project-management/project-management-api-request-internal.d.ts +1 -1
  147. package/lib/project-management/project-management-api-request-internal.js +84 -89
  148. package/lib/project-management/project-management-namespace.d.ts +1 -1
  149. package/lib/project-management/project-management-namespace.js +1 -1
  150. package/lib/project-management/project-management.d.ts +1 -1
  151. package/lib/project-management/project-management.js +80 -87
  152. package/lib/remote-config/index.d.ts +1 -1
  153. package/lib/remote-config/index.js +7 -7
  154. package/lib/remote-config/remote-config-api-client-internal.d.ts +1 -1
  155. package/lib/remote-config/remote-config-api-client-internal.js +116 -154
  156. package/lib/remote-config/remote-config-api.d.ts +1 -1
  157. package/lib/remote-config/remote-config-api.js +1 -1
  158. package/lib/remote-config/remote-config-namespace.d.ts +1 -1
  159. package/lib/remote-config/remote-config-namespace.js +1 -1
  160. package/lib/remote-config/remote-config.d.ts +1 -1
  161. package/lib/remote-config/remote-config.js +51 -59
  162. package/lib/security-rules/index.d.ts +1 -1
  163. package/lib/security-rules/index.js +7 -7
  164. package/lib/security-rules/security-rules-api-client-internal.d.ts +1 -1
  165. package/lib/security-rules/security-rules-api-client-internal.js +95 -107
  166. package/lib/security-rules/security-rules-internal.d.ts +1 -1
  167. package/lib/security-rules/security-rules-internal.js +6 -21
  168. package/lib/security-rules/security-rules-namespace.d.ts +1 -1
  169. package/lib/security-rules/security-rules-namespace.js +1 -1
  170. package/lib/security-rules/security-rules.d.ts +1 -1
  171. package/lib/security-rules/security-rules.js +82 -91
  172. package/lib/storage/index.d.ts +1 -1
  173. package/lib/storage/index.js +7 -7
  174. package/lib/storage/storage-namespace.d.ts +1 -1
  175. package/lib/storage/storage-namespace.js +1 -1
  176. package/lib/storage/storage.d.ts +1 -1
  177. package/lib/storage/storage.js +25 -30
  178. package/lib/utils/api-request.d.ts +3 -1
  179. package/lib/utils/api-request.js +278 -356
  180. package/lib/utils/crypto-signer.d.ts +1 -1
  181. package/lib/utils/crypto-signer.js +58 -93
  182. package/lib/utils/deep-copy.d.ts +1 -1
  183. package/lib/utils/deep-copy.js +3 -3
  184. package/lib/utils/error.d.ts +1 -1
  185. package/lib/utils/error.js +611 -681
  186. package/lib/utils/index.d.ts +1 -1
  187. package/lib/utils/index.js +38 -43
  188. package/lib/utils/jwt.d.ts +1 -1
  189. package/lib/utils/jwt.js +97 -123
  190. package/lib/utils/validator.d.ts +1 -1
  191. package/lib/utils/validator.js +13 -13
  192. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- /*! firebase-admin v10.3.0 */
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
- var deep_copy_1 = require("../utils/deep-copy");
33
- var error_1 = require("../utils/error");
34
- var utils = require("../utils");
35
- var validator = require("../utils/validator");
36
- var messaging_internal_1 = require("./messaging-internal");
37
- var messaging_api_request_internal_1 = require("./messaging-api-request-internal");
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
- var FCM_SEND_HOST = 'fcm.googleapis.com';
40
- var FCM_SEND_PATH = '/fcm/send';
41
- var FCM_TOPIC_MANAGEMENT_HOST = 'iid.googleapis.com';
42
- var FCM_TOPIC_MANAGEMENT_ADD_PATH = '/iid/v1:batchAdd';
43
- var FCM_TOPIC_MANAGEMENT_REMOVE_PATH = '/iid/v1:batchRemove';
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
- var FCM_MAX_BATCH_SIZE = 500;
34
+ const FCM_MAX_BATCH_SIZE = 500;
46
35
  // Key renames for the messaging notification payload object.
47
- var CAMELCASED_NOTIFICATION_PAYLOAD_KEYS_MAP = {
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
- var CAMELCASE_OPTIONS_KEYS_MAP = {
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
- var MESSAGING_DEVICE_RESULT_KEYS_MAP = {
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
- var MESSAGING_DEVICES_RESPONSE_KEYS_MAP = {
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
- var MESSAGING_DEVICE_GROUP_RESPONSE_KEYS_MAP = {
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
- var MESSAGING_TOPIC_RESPONSE_KEYS_MAP = {
71
+ const MESSAGING_TOPIC_RESPONSE_KEYS_MAP = {
83
72
  message_id: 'messageId',
84
73
  };
85
74
  // Key renames for the MessagingConditionResponse object.
86
- var MESSAGING_CONDITION_RESPONSE_KEYS_MAP = {
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(function (messagingDeviceResult) {
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
- var newError = error_1.FirebaseMessagingError.fromServerError(messagingDeviceResult.error, /* message */ undefined, messagingDeviceResult.error);
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
- var result = {
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(function (tokenManagementResult, index) {
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
- var newError = error_1.FirebaseMessagingError.fromTopicManagementServerError(tokenManagementResult.error, /* message */ undefined, tokenManagementResult.error);
134
+ const newError = error_1.FirebaseMessagingError.fromTopicManagementServerError(tokenManagementResult.error, /* message */ undefined, tokenManagementResult.error);
146
135
  result.errors.push({
147
- index: 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
- var Messaging = /** @class */ (function () {
150
+ class Messaging {
162
151
  /**
163
152
  * @internal
164
153
  */
165
- function Messaging(app) {
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
- Object.defineProperty(Messaging.prototype, "app", {
173
- /**
174
- * The {@link firebase-admin.app#App} associated with the current `Messaging` service
175
- * instance.
176
- *
177
- * @example
178
- * ```javascript
179
- * var app = messaging.app;
180
- * ```
181
- */
182
- get: function () {
183
- return this.appInternal;
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
- Messaging.prototype.send = function (message, dryRun) {
199
- var _this = this;
200
- var copy = deep_copy_1.deepCopy(message);
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(function (urlPath) {
207
- var request = { message: copy };
190
+ .then((urlPath) => {
191
+ const request = { message: copy };
208
192
  if (dryRun) {
209
193
  request.validate_only = true;
210
194
  }
211
- return _this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, urlPath, request);
195
+ return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, urlPath, request);
212
196
  })
213
- .then(function (response) {
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
- Messaging.prototype.sendAll = function (messages, dryRun) {
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
- var copy = deep_copy_1.deepCopy(messages);
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, "messages list must not contain more than " + FCM_MAX_BATCH_SIZE + " items");
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(function (urlPath) {
256
- var requests = copy.map(function (message) {
257
- messaging_internal_1.validateMessage(message);
258
- var request = { message: message };
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: "https://" + FCM_SEND_HOST + urlPath,
246
+ url: `https://${FCM_SEND_HOST}${urlPath}`,
264
247
  body: request,
265
248
  };
266
249
  });
267
- return _this.messagingRequestHandler.sendBatchRequest(requests);
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
- Messaging.prototype.sendMulticast = function (message, dryRun) {
289
- var copy = deep_copy_1.deepCopy(message);
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, "tokens list must not contain more than " + FCM_MAX_BATCH_SIZE + " items");
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
- var messages = copy.tokens.map(function (token) {
282
+ const messages = copy.tokens.map((token) => {
300
283
  return {
301
- token: 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
- Messaging.prototype.sendToDevice = function (registrationTokenOrTokens, payload, options) {
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(function () {
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
- _this.validateRegistrationTokens(registrationTokenOrTokens, 'sendToDevice', error_1.MessagingClientErrorCode.INVALID_RECIPIENT);
344
- var payloadCopy = _this.validateMessagingPayload(payload);
345
- var optionsCopy = _this.validateMessagingOptions(options);
346
- var request = deep_copy_1.deepCopy(payloadCopy);
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 _this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
335
+ return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
355
336
  })
356
- .then(function (response) {
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
- var groupResponse = mapRawResponseToDeviceGroupResponse(response);
367
- return __assign(__assign({}, groupResponse), { canonicalRegistrationTokenCount: -1, multicastId: -1, results: [] });
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
- Messaging.prototype.sendToDeviceGroup = function (notificationKey, payload, options) {
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(function () {
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
- var payloadCopy = _this.validateMessagingPayload(payload);
410
- var optionsCopy = _this.validateMessagingOptions(options);
411
- var request = deep_copy_1.deepCopy(payloadCopy);
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 _this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
398
+ return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
415
399
  })
416
- .then(function (response) {
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
- var devicesResponse = mapRawResponseToDevicesResponse(response);
431
- return __assign(__assign({}, devicesResponse), { failedRegistrationTokens: [] });
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
- Messaging.prototype.sendToTopic = function (topic, payload, options) {
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(function () {
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
- var payloadCopy = _this.validateMessagingPayload(payload);
465
- var optionsCopy = _this.validateMessagingOptions(options);
466
- _this.validateTopic(topic, 'sendToTopic', error_1.MessagingClientErrorCode.INVALID_RECIPIENT);
467
- var request = deep_copy_1.deepCopy(payloadCopy);
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 _this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
455
+ return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
471
456
  })
472
- .then(function (response) {
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
- Messaging.prototype.sendToCondition = function (condition, payload, options) {
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(function () {
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
- var payloadCopy = _this.validateMessagingPayload(payload);
513
- var optionsCopy = _this.validateMessagingOptions(options);
514
- var request = deep_copy_1.deepCopy(payloadCopy);
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 _this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
500
+ return this.messagingRequestHandler.invokeRequestHandler(FCM_SEND_HOST, FCM_SEND_PATH, request);
518
501
  })
519
- .then(function (response) {
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
- Messaging.prototype.subscribeToTopic = function (registrationTokenOrTokens, topic) {
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
- Messaging.prototype.unsubscribeFromTopic = function (registrationTokenOrTokens, topic) {
541
+ unsubscribeFromTopic(registrationTokenOrTokens, topic) {
559
542
  return this.sendTopicManagementRequest(registrationTokenOrTokens, topic, 'unsubscribeFromTopic', FCM_TOPIC_MANAGEMENT_REMOVE_PATH);
560
- };
561
- Messaging.prototype.getUrlPath = function () {
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(function (projectId) {
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
- _this.urlPath = "/v1/projects/" + projectId + "/messages:send";
575
- return _this.urlPath;
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
- Messaging.prototype.sendTopicManagementRequest = function (registrationTokenOrTokens, topic, methodName, path) {
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(function () {
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
- _this.validateRegistrationTokens(registrationTokenOrTokens, methodName);
601
- _this.validateTopic(topic, methodName);
581
+ this.validateRegistrationTokens(registrationTokenOrTokens, methodName);
582
+ this.validateTopic(topic, methodName);
602
583
  // Ensure the registration token(s) input argument is an array.
603
- var registrationTokensArray = registrationTokenOrTokens;
584
+ let registrationTokensArray = registrationTokenOrTokens;
604
585
  if (validator.isString(registrationTokenOrTokens)) {
605
586
  registrationTokensArray = [registrationTokenOrTokens];
606
587
  }
607
- var request = {
588
+ const request = {
608
589
  to: topic,
609
590
  registration_tokens: registrationTokensArray,
610
591
  };
611
- return _this.messagingRequestHandler.invokeRequestHandler(FCM_TOPIC_MANAGEMENT_HOST, path, request);
592
+ return this.messagingRequestHandler.invokeRequestHandler(FCM_TOPIC_MANAGEMENT_HOST, path, request);
612
593
  })
613
- .then(function (response) {
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
- Messaging.prototype.validateMessagingPayloadAndOptionsTypes = function (payload, options) {
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
- Messaging.prototype.validateMessagingPayload = function (payload) {
642
- var payloadCopy = deep_copy_1.deepCopy(payload);
643
- var payloadKeys = Object.keys(payloadCopy);
644
- var validPayloadKeys = ['data', 'notification'];
645
- var containsDataOrNotificationKey = false;
646
- payloadKeys.forEach(function (payloadKey) {
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, "Messaging payload contains an invalid \"" + payloadKey + "\" property. Valid properties are " +
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
- var validatePayload = function (payloadKey, value) {
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, "Messaging payload contains an invalid value for the \"" + payloadKey + "\" property. " +
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(function (subKey) {
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, "Messaging payload contains an invalid value for the \"" + payloadKey + "." + subKey + "\" " +
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, "Messaging payload contains the blacklisted \"data." + subKey + "\" property.");
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(function (blacklistedKey) {
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, "Messaging payload contains the blacklisted \"data." + blacklistedKey + "\" property.");
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
- Messaging.prototype.validateMessagingOptions = function (options) {
707
- var optionsCopy = deep_copy_1.deepCopy(options);
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(function (blacklistedKey) {
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, "Messaging options contains the blacklisted \"" + blacklistedKey + "\" property.");
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
- var keyName = ('collapseKey' in options) ? 'collapseKey' : 'collapse_key';
719
- throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, "Messaging options contains an invalid value for the \"" + keyName + "\" property. Value must " +
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
- var keyName = ('dryRun' in options) ? 'dryRun' : 'dry_run';
724
- throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, "Messaging options contains an invalid value for the \"" + keyName + "\" property. Value must " +
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
- var keyName = ('restrictedPackageName' in options) ? 'restrictedPackageName' : 'restricted_package_name';
734
- throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, "Messaging options contains an invalid value for the \"" + keyName + "\" property. Value must " +
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
- var keyName = ('timeToLive' in options) ? 'timeToLive' : 'time_to_live';
739
- throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, "Messaging options contains an invalid value for the \"" + keyName + "\" property. Value must " +
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
- var keyName = ('contentAvailable' in options) ? 'contentAvailable' : 'content_available';
744
- throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, "Messaging options contains an invalid value for the \"" + keyName + "\" property. Value must " +
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
- var keyName = ('mutableContent' in options) ? 'mutableContent' : 'mutable_content';
749
- throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_OPTIONS, "Messaging options contains an invalid value for the \"" + keyName + "\" property. Value must " +
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
- Messaging.prototype.validateRegistrationTokensType = function (registrationTokenOrTokens, methodName, errorInfo) {
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, "Registration token(s) provided to " + methodName + "() must be a non-empty string or a " +
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
- Messaging.prototype.validateRegistrationTokens = function (registrationTokenOrTokens, methodName, errorInfo) {
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, "Too many registration tokens provided in a single request to " + methodName + "(). Batch " +
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(function (registrationToken, index) {
765
+ registrationTokenOrTokens.forEach((registrationToken, index) => {
787
766
  if (!validator.isNonEmptyString(registrationToken)) {
788
- throw new error_1.FirebaseMessagingError(errorInfo, "Registration token provided to " + methodName + "() at index " + index + " must be a " +
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
- Messaging.prototype.validateTopicType = function (topic, methodName, errorInfo) {
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, "Topic provided to " + methodName + "() must be a string which matches the format " +
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
- Messaging.prototype.validateTopic = function (topic, methodName, errorInfo) {
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, "Topic provided to " + methodName + "() must be a string which matches the format " +
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
- Messaging.prototype.normalizeTopic = function (topic) {
806
+ normalizeTopic(topic) {
830
807
  if (!/^\/topics\//.test(topic)) {
831
- topic = "/topics/" + topic;
808
+ topic = `/topics/${topic}`;
832
809
  }
833
810
  return topic;
834
- };
835
- return Messaging;
836
- }());
811
+ }
812
+ }
837
813
  exports.Messaging = Messaging;