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
package/lib/messaging/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.getMessaging = void 0;
|
|
19
|
+
exports.getMessaging = exports.Messaging = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* Firebase Cloud Messaging (FCM).
|
|
22
22
|
*
|
|
23
23
|
* @packageDocumentation
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const app_1 = require("../app");
|
|
26
|
+
const messaging_1 = require("./messaging");
|
|
27
27
|
var messaging_2 = require("./messaging");
|
|
28
28
|
Object.defineProperty(exports, "Messaging", { enumerable: true, get: function () { return messaging_2.Messaging; } });
|
|
29
29
|
/**
|
|
@@ -54,9 +54,9 @@ Object.defineProperty(exports, "Messaging", { enumerable: true, get: function ()
|
|
|
54
54
|
*/
|
|
55
55
|
function getMessaging(app) {
|
|
56
56
|
if (typeof app === 'undefined') {
|
|
57
|
-
app = app_1.getApp();
|
|
57
|
+
app = (0, app_1.getApp)();
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
return firebaseApp.getOrInitService('messaging',
|
|
59
|
+
const firebaseApp = app;
|
|
60
|
+
return firebaseApp.getOrInitService('messaging', (app) => new messaging_1.Messaging(app));
|
|
61
61
|
}
|
|
62
62
|
exports.getMessaging = getMessaging;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -18,30 +18,30 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.FirebaseMessagingRequestHandler = void 0;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const api_request_1 = require("../utils/api-request");
|
|
22
|
+
const messaging_errors_internal_1 = require("./messaging-errors-internal");
|
|
23
|
+
const batch_request_internal_1 = require("./batch-request-internal");
|
|
24
|
+
const index_1 = require("../utils/index");
|
|
25
25
|
// FCM backend constants
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
'X-Firebase-Client':
|
|
26
|
+
const FIREBASE_MESSAGING_TIMEOUT = 10000;
|
|
27
|
+
const FIREBASE_MESSAGING_BATCH_URL = 'https://fcm.googleapis.com/batch';
|
|
28
|
+
const FIREBASE_MESSAGING_HTTP_METHOD = 'POST';
|
|
29
|
+
const FIREBASE_MESSAGING_HEADERS = {
|
|
30
|
+
'X-Firebase-Client': `fire-admin-node/${(0, index_1.getSdkVersion)()}`,
|
|
31
31
|
};
|
|
32
|
-
|
|
33
|
-
'X-Firebase-Client':
|
|
32
|
+
const LEGACY_FIREBASE_MESSAGING_HEADERS = {
|
|
33
|
+
'X-Firebase-Client': `fire-admin-node/${(0, index_1.getSdkVersion)()}`,
|
|
34
34
|
'access_token_auth': 'true',
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* Class that provides a mechanism to send requests to the Firebase Cloud Messaging backend.
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
class FirebaseMessagingRequestHandler {
|
|
40
40
|
/**
|
|
41
41
|
* @param app - The app used to fetch access tokens to sign API requests.
|
|
42
42
|
* @constructor
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
constructor(app) {
|
|
45
45
|
this.httpClient = new api_request_1.AuthorizedHttpClient(app);
|
|
46
46
|
this.batchClient = new batch_request_internal_1.BatchRequestClient(this.httpClient, FIREBASE_MESSAGING_BATCH_URL, FIREBASE_MESSAGING_HEADERS);
|
|
47
47
|
}
|
|
@@ -53,35 +53,35 @@ var FirebaseMessagingRequestHandler = /** @class */ (function () {
|
|
|
53
53
|
* @param requestData - The request data.
|
|
54
54
|
* @returns A promise that resolves with the response.
|
|
55
55
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
invokeRequestHandler(host, path, requestData) {
|
|
57
|
+
const request = {
|
|
58
58
|
method: FIREBASE_MESSAGING_HTTP_METHOD,
|
|
59
|
-
url:
|
|
59
|
+
url: `https://${host}${path}`,
|
|
60
60
|
data: requestData,
|
|
61
61
|
headers: LEGACY_FIREBASE_MESSAGING_HEADERS,
|
|
62
62
|
timeout: FIREBASE_MESSAGING_TIMEOUT,
|
|
63
63
|
};
|
|
64
|
-
return this.httpClient.send(request).then(
|
|
64
|
+
return this.httpClient.send(request).then((response) => {
|
|
65
65
|
// Send non-JSON responses to the catch() below where they will be treated as errors.
|
|
66
66
|
if (!response.isJson()) {
|
|
67
67
|
throw new api_request_1.HttpError(response);
|
|
68
68
|
}
|
|
69
69
|
// Check for backend errors in the response.
|
|
70
|
-
|
|
70
|
+
const errorCode = (0, messaging_errors_internal_1.getErrorCode)(response.data);
|
|
71
71
|
if (errorCode) {
|
|
72
72
|
throw new api_request_1.HttpError(response);
|
|
73
73
|
}
|
|
74
74
|
// Return entire response.
|
|
75
75
|
return response.data;
|
|
76
76
|
})
|
|
77
|
-
.catch(
|
|
77
|
+
.catch((err) => {
|
|
78
78
|
if (err instanceof api_request_1.HttpError) {
|
|
79
|
-
throw messaging_errors_internal_1.createFirebaseError(err);
|
|
79
|
+
throw (0, messaging_errors_internal_1.createFirebaseError)(err);
|
|
80
80
|
}
|
|
81
81
|
// Re-throw the error if it already has the proper format.
|
|
82
82
|
throw err;
|
|
83
83
|
});
|
|
84
|
-
}
|
|
84
|
+
}
|
|
85
85
|
/**
|
|
86
86
|
* Sends the given array of sub requests as a single batch to FCM, and parses the result into
|
|
87
87
|
* a BatchResponse object.
|
|
@@ -89,40 +89,38 @@ var FirebaseMessagingRequestHandler = /** @class */ (function () {
|
|
|
89
89
|
* @param requests - An array of sub requests to send.
|
|
90
90
|
* @returns A promise that resolves when the send operation is complete.
|
|
91
91
|
*/
|
|
92
|
-
|
|
93
|
-
var _this = this;
|
|
92
|
+
sendBatchRequest(requests) {
|
|
94
93
|
return this.batchClient.send(requests)
|
|
95
|
-
.then(
|
|
96
|
-
return responses.map(
|
|
97
|
-
return
|
|
94
|
+
.then((responses) => {
|
|
95
|
+
return responses.map((part) => {
|
|
96
|
+
return this.buildSendResponse(part);
|
|
98
97
|
});
|
|
99
|
-
}).then(
|
|
100
|
-
|
|
98
|
+
}).then((responses) => {
|
|
99
|
+
const successCount = responses.filter((resp) => resp.success).length;
|
|
101
100
|
return {
|
|
102
|
-
responses
|
|
103
|
-
successCount
|
|
101
|
+
responses,
|
|
102
|
+
successCount,
|
|
104
103
|
failureCount: responses.length - successCount,
|
|
105
104
|
};
|
|
106
|
-
}).catch(
|
|
105
|
+
}).catch((err) => {
|
|
107
106
|
if (err instanceof api_request_1.HttpError) {
|
|
108
|
-
throw messaging_errors_internal_1.createFirebaseError(err);
|
|
107
|
+
throw (0, messaging_errors_internal_1.createFirebaseError)(err);
|
|
109
108
|
}
|
|
110
109
|
// Re-throw the error if it already has the proper format.
|
|
111
110
|
throw err;
|
|
112
111
|
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
}
|
|
113
|
+
buildSendResponse(response) {
|
|
114
|
+
const result = {
|
|
116
115
|
success: response.status === 200,
|
|
117
116
|
};
|
|
118
117
|
if (result.success) {
|
|
119
118
|
result.messageId = response.data.name;
|
|
120
119
|
}
|
|
121
120
|
else {
|
|
122
|
-
result.error = messaging_errors_internal_1.createFirebaseError(new api_request_1.HttpError(response));
|
|
121
|
+
result.error = (0, messaging_errors_internal_1.createFirebaseError)(new api_request_1.HttpError(response));
|
|
123
122
|
}
|
|
124
123
|
return result;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
}());
|
|
124
|
+
}
|
|
125
|
+
}
|
|
128
126
|
exports.FirebaseMessagingRequestHandler = FirebaseMessagingRequestHandler;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2019 Google Inc.
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.getErrorCode = exports.createFirebaseError = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const error_1 = require("../utils/error");
|
|
21
|
+
const validator = require("../utils/validator");
|
|
22
22
|
/**
|
|
23
23
|
* Creates a new FirebaseMessagingError by extracting the error code, message and other relevant
|
|
24
24
|
* details from an HTTP error response.
|
|
@@ -29,13 +29,13 @@ var validator = require("../utils/validator");
|
|
|
29
29
|
function createFirebaseError(err) {
|
|
30
30
|
if (err.response.isJson()) {
|
|
31
31
|
// For JSON responses, map the server response to a client-side error.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const json = err.response.data;
|
|
33
|
+
const errorCode = getErrorCode(json);
|
|
34
|
+
const errorMessage = getErrorMessage(json);
|
|
35
35
|
return error_1.FirebaseMessagingError.fromServerError(errorCode, errorMessage, json);
|
|
36
36
|
}
|
|
37
37
|
// Non-JSON response
|
|
38
|
-
|
|
38
|
+
let error;
|
|
39
39
|
switch (err.response.status) {
|
|
40
40
|
case 400:
|
|
41
41
|
error = error_1.MessagingClientErrorCode.INVALID_ARGUMENT;
|
|
@@ -56,8 +56,8 @@ function createFirebaseError(err) {
|
|
|
56
56
|
}
|
|
57
57
|
return new error_1.FirebaseMessagingError({
|
|
58
58
|
code: error.code,
|
|
59
|
-
message: error.message
|
|
60
|
-
|
|
59
|
+
message: `${error.message} Raw server response: "${err.response.text}". Status code: ` +
|
|
60
|
+
`${err.response.status}.`,
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
exports.createFirebaseError = createFirebaseError;
|
|
@@ -67,14 +67,13 @@ exports.createFirebaseError = createFirebaseError;
|
|
|
67
67
|
*/
|
|
68
68
|
function getErrorCode(response) {
|
|
69
69
|
if (validator.isNonNullObject(response) && 'error' in response) {
|
|
70
|
-
|
|
70
|
+
const error = response.error;
|
|
71
71
|
if (validator.isString(error)) {
|
|
72
72
|
return error;
|
|
73
73
|
}
|
|
74
74
|
if (validator.isArray(error.details)) {
|
|
75
|
-
|
|
76
|
-
for (
|
|
77
|
-
var element = _a[_i];
|
|
75
|
+
const fcmErrorType = 'type.googleapis.com/google.firebase.fcm.v1.FcmError';
|
|
76
|
+
for (const element of error.details) {
|
|
78
77
|
if (element['@type'] === fcmErrorType) {
|
|
79
78
|
return element.errorCode;
|
|
80
79
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v11.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2020 Google Inc.
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.validateMessage = exports.BLACKLISTED_OPTIONS_KEYS = exports.BLACKLISTED_DATA_PAYLOAD_KEYS = void 0;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const index_1 = require("../utils/index");
|
|
21
|
+
const error_1 = require("../utils/error");
|
|
22
|
+
const validator = require("../utils/validator");
|
|
23
23
|
// Keys which are not allowed in the messaging data payload object.
|
|
24
24
|
exports.BLACKLISTED_DATA_PAYLOAD_KEYS = ['from'];
|
|
25
25
|
// Keys which are not allowed in the messaging options object.
|
|
@@ -37,7 +37,7 @@ function validateMessage(message) {
|
|
|
37
37
|
if (!validator.isNonNullObject(message)) {
|
|
38
38
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Message must be a non-null object');
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
const anyMessage = message;
|
|
41
41
|
if (anyMessage.topic) {
|
|
42
42
|
// If the topic name is prefixed, remove it.
|
|
43
43
|
if (anyMessage.topic.startsWith('/topics/')) {
|
|
@@ -48,8 +48,8 @@ function validateMessage(message) {
|
|
|
48
48
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Malformed topic name');
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
if (targets.filter(
|
|
51
|
+
const targets = [anyMessage.token, anyMessage.topic, anyMessage.condition];
|
|
52
|
+
if (targets.filter((v) => validator.isNonEmptyString(v)).length !== 1) {
|
|
53
53
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'Exactly one of topic, token or condition is required');
|
|
54
54
|
}
|
|
55
55
|
validateStringMap(message.data, 'data');
|
|
@@ -71,11 +71,11 @@ function validateStringMap(map, label) {
|
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
else if (!validator.isNonNullObject(map)) {
|
|
74
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, label
|
|
74
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `${label} must be a non-null object`);
|
|
75
75
|
}
|
|
76
|
-
Object.keys(map).forEach(
|
|
76
|
+
Object.keys(map).forEach((key) => {
|
|
77
77
|
if (!validator.isString(map[key])) {
|
|
78
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, label
|
|
78
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `${label} must only contain string values`);
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
}
|
|
@@ -130,15 +130,15 @@ function validateApnsFcmOptions(fcmOptions) {
|
|
|
130
130
|
if (typeof fcmOptions.analyticsLabel !== 'undefined' && !validator.isString(fcmOptions.analyticsLabel)) {
|
|
131
131
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'analyticsLabel must be a string value');
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
const propertyMappings = {
|
|
134
134
|
imageUrl: 'image',
|
|
135
135
|
};
|
|
136
|
-
Object.keys(propertyMappings).forEach(
|
|
136
|
+
Object.keys(propertyMappings).forEach((key) => {
|
|
137
137
|
if (key in fcmOptions && propertyMappings[key] in fcmOptions) {
|
|
138
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
138
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Multiple specifications for ${key} in ApnsFcmOptions`);
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
|
-
index_1.renameProperties(fcmOptions, propertyMappings);
|
|
141
|
+
(0, index_1.renameProperties)(fcmOptions, propertyMappings);
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Checks if the given FcmOptions object is valid.
|
|
@@ -171,15 +171,15 @@ function validateNotification(notification) {
|
|
|
171
171
|
if (typeof notification.imageUrl !== 'undefined' && !validator.isURL(notification.imageUrl)) {
|
|
172
172
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'notification.imageUrl must be a valid URL string');
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
const propertyMappings = {
|
|
175
175
|
imageUrl: 'image',
|
|
176
176
|
};
|
|
177
|
-
Object.keys(propertyMappings).forEach(
|
|
177
|
+
Object.keys(propertyMappings).forEach((key) => {
|
|
178
178
|
if (key in notification && propertyMappings[key] in notification) {
|
|
179
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
179
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Multiple specifications for ${key} in Notification`);
|
|
180
180
|
}
|
|
181
181
|
});
|
|
182
|
-
index_1.renameProperties(notification, propertyMappings);
|
|
182
|
+
(0, index_1.renameProperties)(notification, propertyMappings);
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
185
|
* Checks if the given ApnsPayload object is valid. The object must have a valid aps value.
|
|
@@ -210,18 +210,18 @@ function validateAps(aps) {
|
|
|
210
210
|
}
|
|
211
211
|
validateApsAlert(aps.alert);
|
|
212
212
|
validateApsSound(aps.sound);
|
|
213
|
-
|
|
213
|
+
const propertyMappings = {
|
|
214
214
|
contentAvailable: 'content-available',
|
|
215
215
|
mutableContent: 'mutable-content',
|
|
216
216
|
threadId: 'thread-id',
|
|
217
217
|
};
|
|
218
|
-
Object.keys(propertyMappings).forEach(
|
|
218
|
+
Object.keys(propertyMappings).forEach((key) => {
|
|
219
219
|
if (key in aps && propertyMappings[key] in aps) {
|
|
220
|
-
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD,
|
|
220
|
+
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, `Multiple specifications for ${key} in Aps`);
|
|
221
221
|
}
|
|
222
222
|
});
|
|
223
|
-
index_1.renameProperties(aps, propertyMappings);
|
|
224
|
-
|
|
223
|
+
(0, index_1.renameProperties)(aps, propertyMappings);
|
|
224
|
+
const contentAvailable = aps['content-available'];
|
|
225
225
|
if (typeof contentAvailable !== 'undefined' && contentAvailable !== 1) {
|
|
226
226
|
if (contentAvailable === true) {
|
|
227
227
|
aps['content-available'] = 1;
|
|
@@ -230,7 +230,7 @@ function validateAps(aps) {
|
|
|
230
230
|
delete aps['content-available'];
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
|
|
233
|
+
const mutableContent = aps['mutable-content'];
|
|
234
234
|
if (typeof mutableContent !== 'undefined' && mutableContent !== 1) {
|
|
235
235
|
if (mutableContent === true) {
|
|
236
236
|
aps['mutable-content'] = 1;
|
|
@@ -250,7 +250,7 @@ function validateApsSound(sound) {
|
|
|
250
250
|
if (!validator.isNonEmptyString(sound.name)) {
|
|
251
251
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.sound.name must be a non-empty string');
|
|
252
252
|
}
|
|
253
|
-
|
|
253
|
+
const volume = sound.volume;
|
|
254
254
|
if (typeof volume !== 'undefined') {
|
|
255
255
|
if (!validator.isNumber(volume)) {
|
|
256
256
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.sound.volume must be a number');
|
|
@@ -259,9 +259,9 @@ function validateApsSound(sound) {
|
|
|
259
259
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.sound.volume must be in the interval [0, 1]');
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
262
|
+
const soundObject = sound;
|
|
263
|
+
const key = 'critical';
|
|
264
|
+
const critical = soundObject[key];
|
|
265
265
|
if (typeof critical !== 'undefined' && critical !== 1) {
|
|
266
266
|
if (critical === true) {
|
|
267
267
|
soundObject[key] = 1;
|
|
@@ -285,7 +285,7 @@ function validateApsAlert(alert) {
|
|
|
285
285
|
else if (!validator.isNonNullObject(alert)) {
|
|
286
286
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.alert must be a string or a non-null object');
|
|
287
287
|
}
|
|
288
|
-
|
|
288
|
+
const apsAlert = alert;
|
|
289
289
|
if (validator.isNonEmptyArray(apsAlert.locArgs) &&
|
|
290
290
|
!validator.isNonEmptyString(apsAlert.locKey)) {
|
|
291
291
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.alert.locKey is required when specifying locArgs');
|
|
@@ -298,7 +298,7 @@ function validateApsAlert(alert) {
|
|
|
298
298
|
!validator.isNonEmptyString(apsAlert.subtitleLocKey)) {
|
|
299
299
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'apns.payload.aps.alert.subtitleLocKey is required when specifying subtitleLocArgs');
|
|
300
300
|
}
|
|
301
|
-
|
|
301
|
+
const propertyMappings = {
|
|
302
302
|
locKey: 'loc-key',
|
|
303
303
|
locArgs: 'loc-args',
|
|
304
304
|
titleLocKey: 'title-loc-key',
|
|
@@ -308,7 +308,7 @@ function validateApsAlert(alert) {
|
|
|
308
308
|
actionLocKey: 'action-loc-key',
|
|
309
309
|
launchImage: 'launch-image',
|
|
310
310
|
};
|
|
311
|
-
index_1.renameProperties(apsAlert, propertyMappings);
|
|
311
|
+
(0, index_1.renameProperties)(apsAlert, propertyMappings);
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
314
|
* Checks if the given AndroidConfig object is valid. The object must have valid ttl, data,
|
|
@@ -328,17 +328,17 @@ function validateAndroidConfig(config) {
|
|
|
328
328
|
if (!validator.isNumber(config.ttl) || config.ttl < 0) {
|
|
329
329
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'TTL must be a non-negative duration in milliseconds');
|
|
330
330
|
}
|
|
331
|
-
|
|
331
|
+
const duration = (0, index_1.transformMillisecondsToSecondsString)(config.ttl);
|
|
332
332
|
config.ttl = duration;
|
|
333
333
|
}
|
|
334
334
|
validateStringMap(config.data, 'android.data');
|
|
335
335
|
validateAndroidNotification(config.notification);
|
|
336
336
|
validateAndroidFcmOptions(config.fcmOptions);
|
|
337
|
-
|
|
337
|
+
const propertyMappings = {
|
|
338
338
|
collapseKey: 'collapse_key',
|
|
339
339
|
restrictedPackageName: 'restricted_package_name',
|
|
340
340
|
};
|
|
341
|
-
index_1.renameProperties(config, propertyMappings);
|
|
341
|
+
(0, index_1.renameProperties)(config, propertyMappings);
|
|
342
342
|
}
|
|
343
343
|
/**
|
|
344
344
|
* Checks if the given AndroidNotification object is valid. The object must have valid color and
|
|
@@ -374,33 +374,33 @@ function validateAndroidNotification(notification) {
|
|
|
374
374
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.eventTimestamp must be a valid `Date` object');
|
|
375
375
|
}
|
|
376
376
|
// Convert timestamp to RFC3339 UTC "Zulu" format, example "2014-10-02T15:01:23.045123456Z"
|
|
377
|
-
|
|
377
|
+
const zuluTimestamp = notification.eventTimestamp.toISOString();
|
|
378
378
|
notification.eventTimestamp = zuluTimestamp;
|
|
379
379
|
}
|
|
380
380
|
if (typeof notification.vibrateTimingsMillis !== 'undefined') {
|
|
381
381
|
if (!validator.isNonEmptyArray(notification.vibrateTimingsMillis)) {
|
|
382
382
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.vibrateTimingsMillis must be a non-empty array of numbers');
|
|
383
383
|
}
|
|
384
|
-
|
|
385
|
-
notification.vibrateTimingsMillis.forEach(
|
|
384
|
+
const vibrateTimings = [];
|
|
385
|
+
notification.vibrateTimingsMillis.forEach((value) => {
|
|
386
386
|
if (!validator.isNumber(value) || value < 0) {
|
|
387
387
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.vibrateTimingsMillis must be non-negative durations in milliseconds');
|
|
388
388
|
}
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
const duration = (0, index_1.transformMillisecondsToSecondsString)(value);
|
|
390
|
+
vibrateTimings.push(duration);
|
|
391
391
|
});
|
|
392
|
-
notification.vibrateTimingsMillis =
|
|
392
|
+
notification.vibrateTimingsMillis = vibrateTimings;
|
|
393
393
|
}
|
|
394
394
|
if (typeof notification.priority !== 'undefined') {
|
|
395
|
-
|
|
395
|
+
const priority = 'PRIORITY_' + notification.priority.toUpperCase();
|
|
396
396
|
notification.priority = priority;
|
|
397
397
|
}
|
|
398
398
|
if (typeof notification.visibility !== 'undefined') {
|
|
399
|
-
|
|
399
|
+
const visibility = notification.visibility.toUpperCase();
|
|
400
400
|
notification.visibility = visibility;
|
|
401
401
|
}
|
|
402
402
|
validateLightSettings(notification.lightSettings);
|
|
403
|
-
|
|
403
|
+
const propertyMappings = {
|
|
404
404
|
clickAction: 'click_action',
|
|
405
405
|
bodyLocKey: 'body_loc_key',
|
|
406
406
|
bodyLocArgs: 'body_loc_args',
|
|
@@ -418,7 +418,7 @@ function validateAndroidNotification(notification) {
|
|
|
418
418
|
defaultLightSettings: 'default_light_settings',
|
|
419
419
|
notificationCount: 'notification_count',
|
|
420
420
|
};
|
|
421
|
-
index_1.renameProperties(notification, propertyMappings);
|
|
421
|
+
(0, index_1.renameProperties)(notification, propertyMappings);
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
424
|
* Checks if the given LightSettings object is valid. The object must have valid color and
|
|
@@ -437,34 +437,34 @@ function validateLightSettings(lightSettings) {
|
|
|
437
437
|
if (!validator.isNumber(lightSettings.lightOnDurationMillis) || lightSettings.lightOnDurationMillis < 0) {
|
|
438
438
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.lightSettings.lightOnDurationMillis must be a non-negative duration in milliseconds');
|
|
439
439
|
}
|
|
440
|
-
|
|
440
|
+
const durationOn = (0, index_1.transformMillisecondsToSecondsString)(lightSettings.lightOnDurationMillis);
|
|
441
441
|
lightSettings.lightOnDurationMillis = durationOn;
|
|
442
442
|
if (!validator.isNumber(lightSettings.lightOffDurationMillis) || lightSettings.lightOffDurationMillis < 0) {
|
|
443
443
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.lightSettings.lightOffDurationMillis must be a non-negative duration in milliseconds');
|
|
444
444
|
}
|
|
445
|
-
|
|
445
|
+
const durationOff = (0, index_1.transformMillisecondsToSecondsString)(lightSettings.lightOffDurationMillis);
|
|
446
446
|
lightSettings.lightOffDurationMillis = durationOff;
|
|
447
447
|
if (!validator.isString(lightSettings.color) ||
|
|
448
448
|
(!/^#[0-9a-fA-F]{6}$/.test(lightSettings.color) && !/^#[0-9a-fA-F]{8}$/.test(lightSettings.color))) {
|
|
449
449
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INVALID_PAYLOAD, 'android.notification.lightSettings.color must be in the form #RRGGBB or #RRGGBBAA format');
|
|
450
450
|
}
|
|
451
|
-
|
|
452
|
-
|
|
451
|
+
const colorString = lightSettings.color.length === 7 ? lightSettings.color + 'FF' : lightSettings.color;
|
|
452
|
+
const rgb = /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/i.exec(colorString);
|
|
453
453
|
if (!rgb || rgb.length < 4) {
|
|
454
454
|
throw new error_1.FirebaseMessagingError(error_1.MessagingClientErrorCode.INTERNAL_ERROR, 'regex to extract rgba values from ' + colorString + ' failed.');
|
|
455
455
|
}
|
|
456
|
-
|
|
456
|
+
const color = {
|
|
457
457
|
red: parseInt(rgb[1], 16) / 255.0,
|
|
458
458
|
green: parseInt(rgb[2], 16) / 255.0,
|
|
459
459
|
blue: parseInt(rgb[3], 16) / 255.0,
|
|
460
460
|
alpha: parseInt(rgb[4], 16) / 255.0,
|
|
461
461
|
};
|
|
462
462
|
lightSettings.color = color;
|
|
463
|
-
|
|
463
|
+
const propertyMappings = {
|
|
464
464
|
lightOnDurationMillis: 'light_on_duration',
|
|
465
465
|
lightOffDurationMillis: 'light_off_duration',
|
|
466
466
|
};
|
|
467
|
-
index_1.renameProperties(lightSettings, propertyMappings);
|
|
467
|
+
(0, index_1.renameProperties)(lightSettings, propertyMappings);
|
|
468
468
|
}
|
|
469
469
|
/**
|
|
470
470
|
* Checks if the given AndroidFcmOptions object is valid.
|