firebase-admin 9.12.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 (84) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +90 -0
  3. package/lib/app-check/app-check-api-client-internal.js +197 -0
  4. package/lib/app-check/app-check.js +79 -0
  5. package/lib/app-check/index.d.ts +160 -0
  6. package/lib/app-check/index.js +19 -0
  7. package/lib/app-check/token-generator.js +161 -0
  8. package/lib/app-check/token-verifier.js +152 -0
  9. package/lib/auth/action-code-settings-builder.js +118 -0
  10. package/lib/auth/auth-api-request.js +1856 -0
  11. package/lib/auth/auth-config.js +636 -0
  12. package/lib/auth/auth.js +836 -0
  13. package/lib/auth/identifier.js +40 -0
  14. package/lib/auth/index.d.ts +1927 -0
  15. package/lib/auth/index.js +18 -0
  16. package/lib/auth/tenant-manager.js +140 -0
  17. package/lib/auth/tenant.js +171 -0
  18. package/lib/auth/token-generator.js +200 -0
  19. package/lib/auth/token-verifier.js +259 -0
  20. package/lib/auth/user-import-builder.js +387 -0
  21. package/lib/auth/user-record.js +346 -0
  22. package/lib/credential/credential-internal.js +391 -0
  23. package/lib/credential/credential.js +44 -0
  24. package/lib/credential/index.d.ts +169 -0
  25. package/lib/credential/index.js +23 -0
  26. package/lib/database/database-internal.js +266 -0
  27. package/lib/database/index.d.ts +89 -0
  28. package/lib/database/index.js +31 -0
  29. package/lib/default-namespace.js +31 -0
  30. package/lib/firebase-app.js +349 -0
  31. package/lib/firebase-namespace-api.d.ts +243 -0
  32. package/lib/firebase-namespace-api.js +18 -0
  33. package/lib/firebase-namespace.d.ts +31 -0
  34. package/lib/firebase-namespace.js +417 -0
  35. package/lib/firestore/firestore-internal.js +105 -0
  36. package/lib/firestore/index.d.ts +50 -0
  37. package/lib/firestore/index.js +47 -0
  38. package/lib/index.d.ts +24 -0
  39. package/lib/index.js +27 -0
  40. package/lib/installations/index.d.ts +81 -0
  41. package/lib/installations/index.js +18 -0
  42. package/lib/installations/installations-request-handler.js +117 -0
  43. package/lib/installations/installations.js +62 -0
  44. package/lib/instance-id/index.d.ts +83 -0
  45. package/lib/instance-id/index.js +18 -0
  46. package/lib/instance-id/instance-id.js +87 -0
  47. package/lib/machine-learning/index.d.ts +249 -0
  48. package/lib/machine-learning/index.js +18 -0
  49. package/lib/machine-learning/machine-learning-api-client.js +304 -0
  50. package/lib/machine-learning/machine-learning-utils.js +62 -0
  51. package/lib/machine-learning/machine-learning.js +364 -0
  52. package/lib/messaging/batch-request-internal.js +129 -0
  53. package/lib/messaging/index.d.ts +1174 -0
  54. package/lib/messaging/index.js +18 -0
  55. package/lib/messaging/messaging-api-request-internal.js +128 -0
  56. package/lib/messaging/messaging-errors-internal.js +106 -0
  57. package/lib/messaging/messaging-internal.js +484 -0
  58. package/lib/messaging/messaging.js +846 -0
  59. package/lib/project-management/android-app.js +176 -0
  60. package/lib/project-management/index.d.ts +363 -0
  61. package/lib/project-management/index.js +41 -0
  62. package/lib/project-management/ios-app.js +88 -0
  63. package/lib/project-management/project-management-api-request-internal.js +273 -0
  64. package/lib/project-management/project-management.js +254 -0
  65. package/lib/remote-config/index.d.ts +369 -0
  66. package/lib/remote-config/index.js +18 -0
  67. package/lib/remote-config/remote-config-api-client-internal.js +407 -0
  68. package/lib/remote-config/remote-config.js +304 -0
  69. package/lib/security-rules/index.d.ts +216 -0
  70. package/lib/security-rules/index.js +18 -0
  71. package/lib/security-rules/security-rules-api-client-internal.js +237 -0
  72. package/lib/security-rules/security-rules-internal.js +41 -0
  73. package/lib/security-rules/security-rules.js +310 -0
  74. package/lib/storage/index.d.ts +60 -0
  75. package/lib/storage/index.js +18 -0
  76. package/lib/storage/storage.js +123 -0
  77. package/lib/utils/api-request.js +845 -0
  78. package/lib/utils/crypto-signer.js +237 -0
  79. package/lib/utils/deep-copy.js +78 -0
  80. package/lib/utils/error.js +1063 -0
  81. package/lib/utils/index.js +217 -0
  82. package/lib/utils/jwt.js +355 -0
  83. package/lib/utils/validator.js +271 -0
  84. package/package.json +122 -0
@@ -0,0 +1,18 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ "use strict";
3
+ /*!
4
+ * Copyright 2020 Google Inc.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,128 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ "use strict";
3
+ /*!
4
+ * @license
5
+ * Copyright 2017 Google Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.FirebaseMessagingRequestHandler = void 0;
21
+ var api_request_1 = require("../utils/api-request");
22
+ var messaging_errors_internal_1 = require("./messaging-errors-internal");
23
+ var batch_request_internal_1 = require("./batch-request-internal");
24
+ var index_1 = require("../utils/index");
25
+ // FCM backend constants
26
+ var FIREBASE_MESSAGING_TIMEOUT = 10000;
27
+ var FIREBASE_MESSAGING_BATCH_URL = 'https://fcm.googleapis.com/batch';
28
+ var FIREBASE_MESSAGING_HTTP_METHOD = 'POST';
29
+ var FIREBASE_MESSAGING_HEADERS = {
30
+ 'X-Firebase-Client': "fire-admin-node/" + index_1.getSdkVersion(),
31
+ };
32
+ var LEGACY_FIREBASE_MESSAGING_HEADERS = {
33
+ 'X-Firebase-Client': "fire-admin-node/" + index_1.getSdkVersion(),
34
+ 'access_token_auth': 'true',
35
+ };
36
+ /**
37
+ * Class that provides a mechanism to send requests to the Firebase Cloud Messaging backend.
38
+ */
39
+ var FirebaseMessagingRequestHandler = /** @class */ (function () {
40
+ /**
41
+ * @param {FirebaseApp} app The app used to fetch access tokens to sign API requests.
42
+ * @constructor
43
+ */
44
+ function FirebaseMessagingRequestHandler(app) {
45
+ this.httpClient = new api_request_1.AuthorizedHttpClient(app);
46
+ this.batchClient = new batch_request_internal_1.BatchRequestClient(this.httpClient, FIREBASE_MESSAGING_BATCH_URL, FIREBASE_MESSAGING_HEADERS);
47
+ }
48
+ /**
49
+ * Invokes the request handler with the provided request data.
50
+ *
51
+ * @param {string} host The host to which to send the request.
52
+ * @param {string} path The path to which to send the request.
53
+ * @param {object} requestData The request data.
54
+ * @return {Promise<object>} A promise that resolves with the response.
55
+ */
56
+ FirebaseMessagingRequestHandler.prototype.invokeRequestHandler = function (host, path, requestData) {
57
+ var request = {
58
+ method: FIREBASE_MESSAGING_HTTP_METHOD,
59
+ url: "https://" + host + path,
60
+ data: requestData,
61
+ headers: LEGACY_FIREBASE_MESSAGING_HEADERS,
62
+ timeout: FIREBASE_MESSAGING_TIMEOUT,
63
+ };
64
+ return this.httpClient.send(request).then(function (response) {
65
+ // Send non-JSON responses to the catch() below where they will be treated as errors.
66
+ if (!response.isJson()) {
67
+ throw new api_request_1.HttpError(response);
68
+ }
69
+ // Check for backend errors in the response.
70
+ var errorCode = messaging_errors_internal_1.getErrorCode(response.data);
71
+ if (errorCode) {
72
+ throw new api_request_1.HttpError(response);
73
+ }
74
+ // Return entire response.
75
+ return response.data;
76
+ })
77
+ .catch(function (err) {
78
+ if (err instanceof api_request_1.HttpError) {
79
+ throw messaging_errors_internal_1.createFirebaseError(err);
80
+ }
81
+ // Re-throw the error if it already has the proper format.
82
+ throw err;
83
+ });
84
+ };
85
+ /**
86
+ * Sends the given array of sub requests as a single batch to FCM, and parses the result into
87
+ * a BatchResponse object.
88
+ *
89
+ * @param {SubRequest[]} requests An array of sub requests to send.
90
+ * @return {Promise<BatchResponse>} A promise that resolves when the send operation is complete.
91
+ */
92
+ FirebaseMessagingRequestHandler.prototype.sendBatchRequest = function (requests) {
93
+ var _this = this;
94
+ return this.batchClient.send(requests)
95
+ .then(function (responses) {
96
+ return responses.map(function (part) {
97
+ return _this.buildSendResponse(part);
98
+ });
99
+ }).then(function (responses) {
100
+ var successCount = responses.filter(function (resp) { return resp.success; }).length;
101
+ return {
102
+ responses: responses,
103
+ successCount: successCount,
104
+ failureCount: responses.length - successCount,
105
+ };
106
+ }).catch(function (err) {
107
+ if (err instanceof api_request_1.HttpError) {
108
+ throw messaging_errors_internal_1.createFirebaseError(err);
109
+ }
110
+ // Re-throw the error if it already has the proper format.
111
+ throw err;
112
+ });
113
+ };
114
+ FirebaseMessagingRequestHandler.prototype.buildSendResponse = function (response) {
115
+ var result = {
116
+ success: response.status === 200,
117
+ };
118
+ if (result.success) {
119
+ result.messageId = response.data.name;
120
+ }
121
+ else {
122
+ result.error = messaging_errors_internal_1.createFirebaseError(new api_request_1.HttpError(response));
123
+ }
124
+ return result;
125
+ };
126
+ return FirebaseMessagingRequestHandler;
127
+ }());
128
+ exports.FirebaseMessagingRequestHandler = FirebaseMessagingRequestHandler;
@@ -0,0 +1,106 @@
1
+ /*! firebase-admin v9.12.0 */
2
+ "use strict";
3
+ /*!
4
+ * Copyright 2019 Google Inc.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.getErrorCode = exports.createFirebaseError = void 0;
20
+ var error_1 = require("../utils/error");
21
+ var validator = require("../utils/validator");
22
+ /**
23
+ * Creates a new FirebaseMessagingError by extracting the error code, message and other relevant
24
+ * details from an HTTP error response.
25
+ *
26
+ * @param {HttpError} err The HttpError to convert into a Firebase error
27
+ * @return {FirebaseMessagingError} A Firebase error that can be returned to the user.
28
+ */
29
+ function createFirebaseError(err) {
30
+ if (err.response.isJson()) {
31
+ // For JSON responses, map the server response to a client-side error.
32
+ var json = err.response.data;
33
+ var errorCode = getErrorCode(json);
34
+ var errorMessage = getErrorMessage(json);
35
+ return error_1.FirebaseMessagingError.fromServerError(errorCode, errorMessage, json);
36
+ }
37
+ // Non-JSON response
38
+ var error;
39
+ switch (err.response.status) {
40
+ case 400:
41
+ error = error_1.MessagingClientErrorCode.INVALID_ARGUMENT;
42
+ break;
43
+ case 401:
44
+ case 403:
45
+ error = error_1.MessagingClientErrorCode.AUTHENTICATION_ERROR;
46
+ break;
47
+ case 500:
48
+ error = error_1.MessagingClientErrorCode.INTERNAL_ERROR;
49
+ break;
50
+ case 503:
51
+ error = error_1.MessagingClientErrorCode.SERVER_UNAVAILABLE;
52
+ break;
53
+ default:
54
+ // Treat non-JSON responses with unexpected status codes as unknown errors.
55
+ error = error_1.MessagingClientErrorCode.UNKNOWN_ERROR;
56
+ }
57
+ return new error_1.FirebaseMessagingError({
58
+ code: error.code,
59
+ message: error.message + " Raw server response: \"" + err.response.text + "\". Status code: " +
60
+ (err.response.status + "."),
61
+ });
62
+ }
63
+ exports.createFirebaseError = createFirebaseError;
64
+ /**
65
+ * @param {object} response The response to check for errors.
66
+ * @return {string|null} The error code if present; null otherwise.
67
+ */
68
+ function getErrorCode(response) {
69
+ if (validator.isNonNullObject(response) && 'error' in response) {
70
+ var error = response.error;
71
+ if (validator.isString(error)) {
72
+ return error;
73
+ }
74
+ if (validator.isArray(error.details)) {
75
+ var fcmErrorType = 'type.googleapis.com/google.firebase.fcm.v1.FcmError';
76
+ for (var _i = 0, _a = error.details; _i < _a.length; _i++) {
77
+ var element = _a[_i];
78
+ if (element['@type'] === fcmErrorType) {
79
+ return element.errorCode;
80
+ }
81
+ }
82
+ }
83
+ if ('status' in error) {
84
+ return error.status;
85
+ }
86
+ else {
87
+ return error.message;
88
+ }
89
+ }
90
+ return null;
91
+ }
92
+ exports.getErrorCode = getErrorCode;
93
+ /**
94
+ * Extracts error message from the given response object.
95
+ *
96
+ * @param {object} response The response to check for errors.
97
+ * @return {string|null} The error message if present; null otherwise.
98
+ */
99
+ function getErrorMessage(response) {
100
+ if (validator.isNonNullObject(response) &&
101
+ 'error' in response &&
102
+ validator.isNonEmptyString(response.error.message)) {
103
+ return response.error.message;
104
+ }
105
+ return null;
106
+ }