firebase-admin 9.12.0 → 10.0.1
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 +7 -3
- package/lib/app/core.d.ts +188 -0
- package/lib/app/core.js +19 -0
- package/lib/app/credential-factory.d.ts +123 -0
- package/lib/app/credential-factory.js +150 -0
- package/lib/app/credential-internal.d.ts +90 -0
- package/lib/{credential → app}/credential-internal.js +15 -13
- package/lib/app/credential.d.ts +45 -0
- package/lib/app/credential.js +19 -0
- package/lib/app/firebase-app.d.ts +51 -0
- package/lib/{firebase-app.js → app/firebase-app.js} +26 -156
- package/lib/app/firebase-namespace.d.ts +163 -0
- package/lib/{firebase-namespace.js → app/firebase-namespace.js} +99 -111
- package/lib/app/index.d.ts +27 -0
- package/lib/app/index.js +31 -0
- package/lib/app/lifecycle.d.ts +60 -0
- package/lib/app/lifecycle.js +165 -0
- package/lib/app-check/app-check-api-client-internal.d.ts +32 -0
- package/lib/app-check/app-check-api-client-internal.js +10 -10
- package/lib/app-check/app-check-api.d.ts +95 -0
- package/lib/app-check/app-check-api.js +19 -0
- package/lib/app-check/app-check-namespace.d.ts +65 -0
- package/lib/app-check/app-check-namespace.js +18 -0
- package/lib/app-check/app-check.d.ts +49 -0
- package/lib/app-check/app-check.js +13 -10
- package/lib/app-check/index.d.ts +19 -126
- package/lib/app-check/index.js +45 -1
- package/lib/app-check/token-generator.d.ts +25 -0
- package/lib/app-check/token-generator.js +9 -9
- package/lib/app-check/token-verifier.d.ts +17 -0
- package/lib/app-check/token-verifier.js +6 -6
- package/lib/auth/action-code-settings-builder.d.ts +87 -0
- package/lib/auth/action-code-settings-builder.js +4 -2
- package/lib/auth/auth-api-request.d.ts +174 -0
- package/lib/auth/auth-api-request.js +202 -127
- package/lib/auth/auth-config.d.ts +575 -0
- package/lib/auth/auth-config.js +43 -34
- package/lib/auth/auth-namespace.d.ts +255 -0
- package/lib/auth/auth-namespace.js +18 -0
- package/lib/auth/auth.d.ts +40 -0
- package/lib/auth/auth.js +12 -772
- package/lib/auth/base-auth.d.ts +613 -0
- package/lib/auth/base-auth.js +951 -0
- package/lib/auth/identifier.d.ts +57 -0
- package/lib/auth/identifier.js +1 -1
- package/lib/auth/index.d.ts +25 -1897
- package/lib/auth/index.js +54 -1
- package/lib/auth/tenant-manager.d.ts +146 -0
- package/lib/auth/tenant-manager.js +151 -39
- package/lib/auth/tenant.d.ts +130 -0
- package/lib/auth/tenant.js +62 -16
- package/lib/auth/token-generator.d.ts +44 -0
- package/lib/auth/token-generator.js +11 -9
- package/lib/auth/token-verifier.d.ts +150 -0
- package/lib/auth/token-verifier.js +27 -15
- package/lib/auth/user-import-builder.d.ts +322 -0
- package/lib/auth/user-import-builder.js +9 -9
- package/lib/auth/user-record.d.ts +265 -0
- package/lib/auth/user-record.js +80 -45
- package/lib/credential/index.d.ts +24 -66
- package/lib/credential/index.js +101 -1
- package/lib/database/database-namespace.d.ts +95 -0
- package/lib/database/database-namespace.js +23 -0
- package/lib/database/database.d.ts +66 -0
- package/lib/database/{database-internal.js → database.js} +16 -9
- package/lib/database/index.d.ts +55 -54
- package/lib/database/index.js +84 -13
- package/lib/{firebase-namespace.d.ts → default-namespace.d.ts} +7 -14
- package/lib/default-namespace.js +4 -5
- package/lib/esm/app/index.js +10 -0
- package/lib/esm/app-check/index.js +4 -0
- package/lib/esm/auth/index.js +14 -0
- package/lib/esm/database/index.js +6 -0
- package/lib/esm/firestore/index.js +24 -0
- package/lib/esm/installations/index.js +4 -0
- package/lib/esm/instance-id/index.js +4 -0
- package/lib/esm/machine-learning/index.js +5 -0
- package/lib/esm/messaging/index.js +4 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/project-management/index.js +8 -0
- package/lib/esm/remote-config/index.js +4 -0
- package/lib/esm/security-rules/index.js +6 -0
- package/lib/esm/storage/index.js +4 -0
- package/lib/firebase-namespace-api.d.ts +34 -186
- package/lib/firebase-namespace-api.js +37 -2
- package/lib/firestore/firestore-internal.d.ts +32 -0
- package/lib/firestore/firestore-internal.js +3 -3
- package/lib/firestore/firestore-namespace.d.ts +55 -0
- package/lib/firestore/firestore-namespace.js +48 -0
- package/lib/firestore/index.d.ts +37 -35
- package/lib/firestore/index.js +62 -30
- package/lib/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/installations/index.d.ts +34 -63
- package/lib/installations/index.js +45 -1
- package/lib/installations/installations-namespace.d.ts +55 -0
- package/lib/installations/installations-namespace.js +18 -0
- package/lib/installations/installations-request-handler.d.ts +43 -0
- package/lib/installations/installations-request-handler.js +4 -4
- package/lib/installations/installations.d.ts +38 -0
- package/lib/installations/installations.js +6 -5
- package/lib/instance-id/index.d.ts +23 -45
- package/lib/instance-id/index.js +54 -1
- package/lib/instance-id/instance-id-namespace.d.ts +38 -0
- package/lib/instance-id/instance-id-namespace.js +3 -0
- package/lib/instance-id/instance-id.d.ts +47 -0
- package/lib/instance-id/instance-id.js +14 -19
- package/lib/machine-learning/index.d.ts +19 -216
- package/lib/machine-learning/index.js +46 -1
- package/lib/machine-learning/machine-learning-api-client.d.ts +102 -0
- package/lib/machine-learning/machine-learning-api-client.js +6 -6
- package/lib/machine-learning/machine-learning-namespace.d.ts +85 -0
- package/lib/machine-learning/machine-learning-namespace.js +18 -0
- package/lib/machine-learning/machine-learning-utils.d.ts +22 -0
- package/lib/machine-learning/machine-learning-utils.js +1 -1
- package/lib/machine-learning/machine-learning.d.ts +181 -0
- package/lib/machine-learning/machine-learning.js +72 -37
- package/lib/messaging/batch-request-internal.d.ts +55 -0
- package/lib/messaging/batch-request-internal.js +9 -9
- package/lib/messaging/index.d.ts +18 -1140
- package/lib/messaging/index.js +45 -1
- package/lib/messaging/messaging-api-request-internal.d.ts +50 -0
- package/lib/messaging/messaging-api-request-internal.js +8 -8
- package/lib/messaging/messaging-api.d.ts +980 -0
- package/lib/messaging/messaging-api.js +19 -0
- package/lib/messaging/messaging-errors-internal.d.ts +31 -0
- package/lib/messaging/messaging-errors-internal.js +7 -7
- package/lib/messaging/messaging-internal.d.ts +27 -0
- package/lib/messaging/messaging-internal.js +2 -2
- package/lib/messaging/messaging-namespace.d.ts +181 -0
- package/lib/messaging/messaging-namespace.js +18 -0
- package/lib/messaging/messaging.d.ts +269 -0
- package/lib/messaging/messaging.js +83 -91
- package/lib/project-management/android-app.d.ts +110 -0
- package/lib/project-management/android-app.js +24 -15
- package/lib/project-management/app-metadata.d.ts +85 -0
- package/lib/project-management/app-metadata.js +37 -0
- package/lib/project-management/index.d.ts +21 -331
- package/lib/project-management/index.js +51 -24
- package/lib/project-management/ios-app.d.ts +66 -0
- package/lib/project-management/ios-app.js +15 -8
- package/lib/project-management/project-management-api-request-internal.d.ts +17 -0
- package/lib/project-management/project-management-api-request-internal.js +15 -15
- package/lib/project-management/project-management-namespace.d.ts +82 -0
- package/lib/project-management/project-management-namespace.js +18 -0
- package/lib/project-management/project-management.d.ts +115 -0
- package/lib/project-management/project-management.js +22 -25
- package/lib/remote-config/index.d.ts +19 -336
- package/lib/remote-config/index.js +45 -1
- package/lib/remote-config/remote-config-api-client-internal.d.ts +28 -0
- package/lib/remote-config/remote-config-api-client-internal.js +3 -3
- package/lib/remote-config/remote-config-api.d.ts +258 -0
- package/lib/remote-config/remote-config-api.js +18 -0
- package/lib/remote-config/remote-config-namespace.d.ts +105 -0
- package/lib/remote-config/remote-config-namespace.js +18 -0
- package/lib/remote-config/remote-config.d.ts +94 -0
- package/lib/remote-config/remote-config.js +27 -26
- package/lib/security-rules/index.d.ts +18 -184
- package/lib/security-rules/index.js +46 -1
- package/lib/security-rules/security-rules-api-client-internal.d.ts +73 -0
- package/lib/security-rules/security-rules-api-client-internal.js +1 -1
- package/lib/security-rules/security-rules-internal.d.ts +21 -0
- package/lib/security-rules/security-rules-internal.js +1 -1
- package/lib/security-rules/security-rules-namespace.d.ts +69 -0
- package/lib/security-rules/security-rules-namespace.js +18 -0
- package/lib/security-rules/security-rules.d.ts +196 -0
- package/lib/security-rules/security-rules.js +73 -55
- package/lib/storage/index.d.ts +16 -32
- package/lib/storage/index.js +38 -1
- package/lib/storage/storage-namespace.d.ts +45 -0
- package/lib/storage/storage-namespace.js +18 -0
- package/lib/storage/storage.d.ts +42 -0
- package/lib/storage/storage.js +9 -6
- package/lib/utils/api-request.d.ts +230 -0
- package/lib/utils/api-request.js +25 -25
- package/lib/utils/crypto-signer.d.ts +128 -0
- package/lib/utils/crypto-signer.js +9 -9
- package/lib/utils/deep-copy.d.ts +40 -0
- package/lib/utils/deep-copy.js +6 -6
- package/lib/utils/error.d.ts +650 -0
- package/lib/utils/error.js +36 -34
- package/lib/utils/index.d.ts +105 -0
- package/lib/utils/index.js +22 -21
- package/lib/utils/jwt.d.ts +131 -0
- package/lib/utils/jwt.js +11 -11
- package/lib/utils/validator.d.ts +144 -0
- package/lib/utils/validator.js +37 -37
- package/package.json +112 -10
- package/lib/credential/credential.js +0 -44
package/lib/utils/error.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v10.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -35,7 +35,7 @@ var deep_copy_1 = require("../utils/deep-copy");
|
|
|
35
35
|
/**
|
|
36
36
|
* Firebase error code structure. This extends Error.
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
38
|
+
* @param errorInfo - The error information (code and message).
|
|
39
39
|
* @constructor
|
|
40
40
|
*/
|
|
41
41
|
var FirebaseError = /** @class */ (function (_super) {
|
|
@@ -51,7 +51,7 @@ var FirebaseError = /** @class */ (function (_super) {
|
|
|
51
51
|
return _this;
|
|
52
52
|
}
|
|
53
53
|
Object.defineProperty(FirebaseError.prototype, "code", {
|
|
54
|
-
/** @
|
|
54
|
+
/** @returns The error code. */
|
|
55
55
|
get: function () {
|
|
56
56
|
return this.errorInfo.code;
|
|
57
57
|
},
|
|
@@ -59,14 +59,14 @@ var FirebaseError = /** @class */ (function (_super) {
|
|
|
59
59
|
configurable: true
|
|
60
60
|
});
|
|
61
61
|
Object.defineProperty(FirebaseError.prototype, "message", {
|
|
62
|
-
/** @
|
|
62
|
+
/** @returns The error message. */
|
|
63
63
|
get: function () {
|
|
64
64
|
return this.errorInfo.message;
|
|
65
65
|
},
|
|
66
66
|
enumerable: false,
|
|
67
67
|
configurable: true
|
|
68
68
|
});
|
|
69
|
-
/** @
|
|
69
|
+
/** @returns The object representation of the error. */
|
|
70
70
|
FirebaseError.prototype.toJSON = function () {
|
|
71
71
|
return {
|
|
72
72
|
code: this.code,
|
|
@@ -79,9 +79,9 @@ exports.FirebaseError = FirebaseError;
|
|
|
79
79
|
/**
|
|
80
80
|
* A FirebaseError with a prefix in front of the error code.
|
|
81
81
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @param
|
|
82
|
+
* @param codePrefix - The prefix to apply to the error code.
|
|
83
|
+
* @param code - The error code.
|
|
84
|
+
* @param message - The error message.
|
|
85
85
|
* @constructor
|
|
86
86
|
*/
|
|
87
87
|
var PrefixedFirebaseError = /** @class */ (function (_super) {
|
|
@@ -103,8 +103,8 @@ var PrefixedFirebaseError = /** @class */ (function (_super) {
|
|
|
103
103
|
* Allows the error type to be checked without needing to know implementation details
|
|
104
104
|
* of the code prefixing.
|
|
105
105
|
*
|
|
106
|
-
* @param
|
|
107
|
-
* @
|
|
106
|
+
* @param code - The non-prefixed error code to test against.
|
|
107
|
+
* @returns True if the code matches, false otherwise.
|
|
108
108
|
*/
|
|
109
109
|
PrefixedFirebaseError.prototype.hasCode = function (code) {
|
|
110
110
|
return this.codePrefix + "/" + code === this.code;
|
|
@@ -115,8 +115,8 @@ exports.PrefixedFirebaseError = PrefixedFirebaseError;
|
|
|
115
115
|
/**
|
|
116
116
|
* Firebase App error code structure. This extends PrefixedFirebaseError.
|
|
117
117
|
*
|
|
118
|
-
* @param
|
|
119
|
-
* @param
|
|
118
|
+
* @param code - The error code.
|
|
119
|
+
* @param message - The error message.
|
|
120
120
|
* @constructor
|
|
121
121
|
*/
|
|
122
122
|
var FirebaseAppError = /** @class */ (function (_super) {
|
|
@@ -136,8 +136,8 @@ exports.FirebaseAppError = FirebaseAppError;
|
|
|
136
136
|
/**
|
|
137
137
|
* Firebase Auth error code structure. This extends PrefixedFirebaseError.
|
|
138
138
|
*
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
139
|
+
* @param info - The error code info.
|
|
140
|
+
* @param [message] The error message. This will override the default
|
|
141
141
|
* message if provided.
|
|
142
142
|
* @constructor
|
|
143
143
|
*/
|
|
@@ -157,11 +157,11 @@ var FirebaseAuthError = /** @class */ (function (_super) {
|
|
|
157
157
|
/**
|
|
158
158
|
* Creates the developer-facing error corresponding to the backend error code.
|
|
159
159
|
*
|
|
160
|
-
* @param
|
|
161
|
-
* @param
|
|
160
|
+
* @param serverErrorCode - The server error code.
|
|
161
|
+
* @param [message] The error message. The default message is used
|
|
162
162
|
* if not provided.
|
|
163
|
-
* @param
|
|
164
|
-
* @
|
|
163
|
+
* @param [rawServerResponse] The error's raw server response.
|
|
164
|
+
* @returns The corresponding developer-facing error.
|
|
165
165
|
*/
|
|
166
166
|
FirebaseAuthError.fromServerError = function (serverErrorCode, message, rawServerResponse) {
|
|
167
167
|
// serverErrorCode could contain additional details:
|
|
@@ -193,8 +193,8 @@ exports.FirebaseAuthError = FirebaseAuthError;
|
|
|
193
193
|
/**
|
|
194
194
|
* Firebase Database error code structure. This extends FirebaseError.
|
|
195
195
|
*
|
|
196
|
-
* @param
|
|
197
|
-
* @param
|
|
196
|
+
* @param info - The error code info.
|
|
197
|
+
* @param [message] The error message. This will override the default
|
|
198
198
|
* message if provided.
|
|
199
199
|
* @constructor
|
|
200
200
|
*/
|
|
@@ -210,8 +210,8 @@ exports.FirebaseDatabaseError = FirebaseDatabaseError;
|
|
|
210
210
|
/**
|
|
211
211
|
* Firebase Firestore error code structure. This extends FirebaseError.
|
|
212
212
|
*
|
|
213
|
-
* @param
|
|
214
|
-
* @param
|
|
213
|
+
* @param info - The error code info.
|
|
214
|
+
* @param [message] The error message. This will override the default
|
|
215
215
|
* message if provided.
|
|
216
216
|
* @constructor
|
|
217
217
|
*/
|
|
@@ -227,8 +227,8 @@ exports.FirebaseFirestoreError = FirebaseFirestoreError;
|
|
|
227
227
|
/**
|
|
228
228
|
* Firebase instance ID error code structure. This extends FirebaseError.
|
|
229
229
|
*
|
|
230
|
-
* @param
|
|
231
|
-
* @param
|
|
230
|
+
* @param info - The error code info.
|
|
231
|
+
* @param [message] The error message. This will override the default
|
|
232
232
|
* message if provided.
|
|
233
233
|
* @constructor
|
|
234
234
|
*/
|
|
@@ -247,8 +247,8 @@ exports.FirebaseInstanceIdError = FirebaseInstanceIdError;
|
|
|
247
247
|
/**
|
|
248
248
|
* Firebase Installations service error code structure. This extends `FirebaseError`.
|
|
249
249
|
*
|
|
250
|
-
* @param info The error code info.
|
|
251
|
-
* @param message The error message. This will override the default
|
|
250
|
+
* @param info - The error code info.
|
|
251
|
+
* @param message - The error message. This will override the default
|
|
252
252
|
* message if provided.
|
|
253
253
|
* @constructor
|
|
254
254
|
*/
|
|
@@ -267,8 +267,8 @@ exports.FirebaseInstallationsError = FirebaseInstallationsError;
|
|
|
267
267
|
/**
|
|
268
268
|
* Firebase Messaging error code structure. This extends PrefixedFirebaseError.
|
|
269
269
|
*
|
|
270
|
-
* @param
|
|
271
|
-
* @param
|
|
270
|
+
* @param info - The error code info.
|
|
271
|
+
* @param [message] The error message. This will override the default message if provided.
|
|
272
272
|
* @constructor
|
|
273
273
|
*/
|
|
274
274
|
var FirebaseMessagingError = /** @class */ (function (_super) {
|
|
@@ -287,11 +287,11 @@ var FirebaseMessagingError = /** @class */ (function (_super) {
|
|
|
287
287
|
/**
|
|
288
288
|
* Creates the developer-facing error corresponding to the backend error code.
|
|
289
289
|
*
|
|
290
|
-
* @param
|
|
291
|
-
* @param
|
|
290
|
+
* @param serverErrorCode - The server error code.
|
|
291
|
+
* @param [message] The error message. The default message is used
|
|
292
292
|
* if not provided.
|
|
293
|
-
* @param
|
|
294
|
-
* @
|
|
293
|
+
* @param [rawServerResponse] The error's raw server response.
|
|
294
|
+
* @returns The corresponding developer-facing error.
|
|
295
295
|
*/
|
|
296
296
|
FirebaseMessagingError.fromServerError = function (serverErrorCode, message, rawServerResponse) {
|
|
297
297
|
// If not found, default to unknown error.
|
|
@@ -332,8 +332,8 @@ exports.FirebaseMessagingError = FirebaseMessagingError;
|
|
|
332
332
|
/**
|
|
333
333
|
* Firebase project management error code structure. This extends PrefixedFirebaseError.
|
|
334
334
|
*
|
|
335
|
-
* @param
|
|
336
|
-
* @param
|
|
335
|
+
* @param code - The error code.
|
|
336
|
+
* @param message - The error message.
|
|
337
337
|
* @constructor
|
|
338
338
|
*/
|
|
339
339
|
var FirebaseProjectManagementError = /** @class */ (function (_super) {
|
|
@@ -1000,6 +1000,8 @@ var AUTH_SERVER_TO_CLIENT_CODE = {
|
|
|
1000
1000
|
UNVERIFIED_EMAIL: 'UNVERIFIED_EMAIL',
|
|
1001
1001
|
// User on which action is to be performed is not found.
|
|
1002
1002
|
USER_NOT_FOUND: 'USER_NOT_FOUND',
|
|
1003
|
+
// User record is disabled.
|
|
1004
|
+
USER_DISABLED: 'USER_DISABLED',
|
|
1003
1005
|
// Password provided is too weak.
|
|
1004
1006
|
WEAK_PASSWORD: 'INVALID_PASSWORD',
|
|
1005
1007
|
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*! firebase-admin v10.0.1 */
|
|
2
|
+
/*!
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2017 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
|
+
/// <reference types="node" />
|
|
19
|
+
import { App } from '../app/index';
|
|
20
|
+
export declare function getSdkVersion(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Renames properties on an object given a mapping from old to new property names.
|
|
23
|
+
*
|
|
24
|
+
* For example, this can be used to map underscore_cased properties to camelCase.
|
|
25
|
+
*
|
|
26
|
+
* @param obj - The object whose properties to rename.
|
|
27
|
+
* @param keyMap - The mapping from old to new property names.
|
|
28
|
+
*/
|
|
29
|
+
export declare function renameProperties(obj: {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}, keyMap: {
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
}): void;
|
|
34
|
+
/**
|
|
35
|
+
* Defines a new read-only property directly on an object and returns the object.
|
|
36
|
+
*
|
|
37
|
+
* @param obj - The object on which to define the property.
|
|
38
|
+
* @param prop - The name of the property to be defined or modified.
|
|
39
|
+
* @param value - The value associated with the property.
|
|
40
|
+
*/
|
|
41
|
+
export declare function addReadonlyGetter(obj: object, prop: string, value: any): void;
|
|
42
|
+
/**
|
|
43
|
+
* Returns the Google Cloud project ID associated with a Firebase app, if it's explicitly
|
|
44
|
+
* specified in either the Firebase app options, credentials or the local environment.
|
|
45
|
+
* Otherwise returns null.
|
|
46
|
+
*
|
|
47
|
+
* @param app - A Firebase app to get the project ID from.
|
|
48
|
+
*
|
|
49
|
+
* @returns A project ID string or null.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getExplicitProjectId(app: App): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Determines the Google Cloud project ID associated with a Firebase app. This method
|
|
54
|
+
* first checks if a project ID is explicitly specified in either the Firebase app options,
|
|
55
|
+
* credentials or the local environment in that order. If no explicit project ID is
|
|
56
|
+
* configured, but the SDK has been initialized with ComputeEngineCredentials, this
|
|
57
|
+
* method attempts to discover the project ID from the local metadata service.
|
|
58
|
+
*
|
|
59
|
+
* @param app - A Firebase app to get the project ID from.
|
|
60
|
+
*
|
|
61
|
+
* @returns A project ID string or null.
|
|
62
|
+
*/
|
|
63
|
+
export declare function findProjectId(app: App): Promise<string | null>;
|
|
64
|
+
/**
|
|
65
|
+
* Encodes data using web-safe-base64.
|
|
66
|
+
*
|
|
67
|
+
* @param data - The raw data byte input.
|
|
68
|
+
* @returns The base64-encoded result.
|
|
69
|
+
*/
|
|
70
|
+
export declare function toWebSafeBase64(data: Buffer): string;
|
|
71
|
+
/**
|
|
72
|
+
* Formats a string of form 'project/{projectId}/{api}' and replaces
|
|
73
|
+
* with corresponding arguments {projectId: '1234', api: 'resource'}
|
|
74
|
+
* and returns output: 'project/1234/resource'.
|
|
75
|
+
*
|
|
76
|
+
* @param str - The original string where the param need to be
|
|
77
|
+
* replaced.
|
|
78
|
+
* @param params - The optional parameters to replace in the
|
|
79
|
+
* string.
|
|
80
|
+
* @returns The resulting formatted string.
|
|
81
|
+
*/
|
|
82
|
+
export declare function formatString(str: string, params?: object): string;
|
|
83
|
+
/**
|
|
84
|
+
* Generates the update mask for the provided object.
|
|
85
|
+
* Note this will ignore the last key with value undefined.
|
|
86
|
+
*
|
|
87
|
+
* @param obj - The object to generate the update mask for.
|
|
88
|
+
* @param terminalPaths - The optional map of keys for maximum paths to traverse.
|
|
89
|
+
* Nested objects beyond that path will be ignored. This is useful for
|
|
90
|
+
* keys with variable object values.
|
|
91
|
+
* @param root - The path so far.
|
|
92
|
+
* @returns The computed update mask list.
|
|
93
|
+
*/
|
|
94
|
+
export declare function generateUpdateMask(obj: any, terminalPaths?: string[], root?: string): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Transforms milliseconds to a protobuf Duration type string.
|
|
97
|
+
* Returns the duration in seconds with up to nine fractional
|
|
98
|
+
* digits, terminated by 's'. Example: "3 seconds 0 nano seconds as 3s,
|
|
99
|
+
* 3 seconds 1 nano seconds as 3.000000001s".
|
|
100
|
+
*
|
|
101
|
+
* @param milliseconds - The duration in milliseconds.
|
|
102
|
+
* @returns The resulting formatted string in seconds with up to nine fractional
|
|
103
|
+
* digits, terminated by 's'.
|
|
104
|
+
*/
|
|
105
|
+
export declare function transformMillisecondsToSecondsString(milliseconds: number): string;
|
package/lib/utils/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v10.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* @license
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.transformMillisecondsToSecondsString = exports.generateUpdateMask = exports.formatString = exports.toWebSafeBase64 = exports.findProjectId = exports.getExplicitProjectId = exports.addReadonlyGetter = exports.renameProperties = exports.getSdkVersion = void 0;
|
|
21
|
-
var credential_internal_1 = require("../
|
|
21
|
+
var credential_internal_1 = require("../app/credential-internal");
|
|
22
22
|
var validator = require("./validator");
|
|
23
23
|
var sdkVersion;
|
|
24
|
+
// TODO: Move to firebase-admin/app as an internal member.
|
|
24
25
|
function getSdkVersion() {
|
|
25
26
|
if (!sdkVersion) {
|
|
26
27
|
var version = require('../../package.json').version; // eslint-disable-line @typescript-eslint/no-var-requires
|
|
@@ -34,8 +35,8 @@ exports.getSdkVersion = getSdkVersion;
|
|
|
34
35
|
*
|
|
35
36
|
* For example, this can be used to map underscore_cased properties to camelCase.
|
|
36
37
|
*
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
38
|
+
* @param obj - The object whose properties to rename.
|
|
39
|
+
* @param keyMap - The mapping from old to new property names.
|
|
39
40
|
*/
|
|
40
41
|
function renameProperties(obj, keyMap) {
|
|
41
42
|
Object.keys(keyMap).forEach(function (oldKey) {
|
|
@@ -51,9 +52,9 @@ exports.renameProperties = renameProperties;
|
|
|
51
52
|
/**
|
|
52
53
|
* Defines a new read-only property directly on an object and returns the object.
|
|
53
54
|
*
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @param
|
|
55
|
+
* @param obj - The object on which to define the property.
|
|
56
|
+
* @param prop - The name of the property to be defined or modified.
|
|
57
|
+
* @param value - The value associated with the property.
|
|
57
58
|
*/
|
|
58
59
|
function addReadonlyGetter(obj, prop, value) {
|
|
59
60
|
Object.defineProperty(obj, prop, {
|
|
@@ -70,9 +71,9 @@ exports.addReadonlyGetter = addReadonlyGetter;
|
|
|
70
71
|
* specified in either the Firebase app options, credentials or the local environment.
|
|
71
72
|
* Otherwise returns null.
|
|
72
73
|
*
|
|
73
|
-
* @param app A Firebase app to get the project ID from.
|
|
74
|
+
* @param app - A Firebase app to get the project ID from.
|
|
74
75
|
*
|
|
75
|
-
* @
|
|
76
|
+
* @returns A project ID string or null.
|
|
76
77
|
*/
|
|
77
78
|
function getExplicitProjectId(app) {
|
|
78
79
|
var options = app.options;
|
|
@@ -97,9 +98,9 @@ exports.getExplicitProjectId = getExplicitProjectId;
|
|
|
97
98
|
* configured, but the SDK has been initialized with ComputeEngineCredentials, this
|
|
98
99
|
* method attempts to discover the project ID from the local metadata service.
|
|
99
100
|
*
|
|
100
|
-
* @param app A Firebase app to get the project ID from.
|
|
101
|
+
* @param app - A Firebase app to get the project ID from.
|
|
101
102
|
*
|
|
102
|
-
* @
|
|
103
|
+
* @returns A project ID string or null.
|
|
103
104
|
*/
|
|
104
105
|
function findProjectId(app) {
|
|
105
106
|
var projectId = getExplicitProjectId(app);
|
|
@@ -116,8 +117,8 @@ exports.findProjectId = findProjectId;
|
|
|
116
117
|
/**
|
|
117
118
|
* Encodes data using web-safe-base64.
|
|
118
119
|
*
|
|
119
|
-
* @param
|
|
120
|
-
* @
|
|
120
|
+
* @param data - The raw data byte input.
|
|
121
|
+
* @returns The base64-encoded result.
|
|
121
122
|
*/
|
|
122
123
|
function toWebSafeBase64(data) {
|
|
123
124
|
return data.toString('base64').replace(/\//g, '_').replace(/\+/g, '-');
|
|
@@ -128,11 +129,11 @@ exports.toWebSafeBase64 = toWebSafeBase64;
|
|
|
128
129
|
* with corresponding arguments {projectId: '1234', api: 'resource'}
|
|
129
130
|
* and returns output: 'project/1234/resource'.
|
|
130
131
|
*
|
|
131
|
-
* @param
|
|
132
|
+
* @param str - The original string where the param need to be
|
|
132
133
|
* replaced.
|
|
133
|
-
* @param
|
|
134
|
+
* @param params - The optional parameters to replace in the
|
|
134
135
|
* string.
|
|
135
|
-
* @
|
|
136
|
+
* @returns The resulting formatted string.
|
|
136
137
|
*/
|
|
137
138
|
function formatString(str, params) {
|
|
138
139
|
var formatted = str;
|
|
@@ -146,12 +147,12 @@ exports.formatString = formatString;
|
|
|
146
147
|
* Generates the update mask for the provided object.
|
|
147
148
|
* Note this will ignore the last key with value undefined.
|
|
148
149
|
*
|
|
149
|
-
* @param obj The object to generate the update mask for.
|
|
150
|
-
* @param terminalPaths The optional map of keys for maximum paths to traverse.
|
|
150
|
+
* @param obj - The object to generate the update mask for.
|
|
151
|
+
* @param terminalPaths - The optional map of keys for maximum paths to traverse.
|
|
151
152
|
* Nested objects beyond that path will be ignored. This is useful for
|
|
152
153
|
* keys with variable object values.
|
|
153
|
-
* @param root The path so far.
|
|
154
|
-
* @
|
|
154
|
+
* @param root - The path so far.
|
|
155
|
+
* @returns The computed update mask list.
|
|
155
156
|
*/
|
|
156
157
|
function generateUpdateMask(obj, terminalPaths, root) {
|
|
157
158
|
if (terminalPaths === void 0) { terminalPaths = []; }
|
|
@@ -194,7 +195,7 @@ exports.generateUpdateMask = generateUpdateMask;
|
|
|
194
195
|
* digits, terminated by 's'. Example: "3 seconds 0 nano seconds as 3s,
|
|
195
196
|
* 3 seconds 1 nano seconds as 3.000000001s".
|
|
196
197
|
*
|
|
197
|
-
* @param milliseconds The duration in milliseconds.
|
|
198
|
+
* @param milliseconds - The duration in milliseconds.
|
|
198
199
|
* @returns The resulting formatted string in seconds with up to nine fractional
|
|
199
200
|
* digits, terminated by 's'.
|
|
200
201
|
*/
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*! firebase-admin v10.0.1 */
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright 2021 Google Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/// <reference types="node" />
|
|
18
|
+
import * as jwt from 'jsonwebtoken';
|
|
19
|
+
import { Agent } from 'http';
|
|
20
|
+
export declare const ALGORITHM_RS256: jwt.Algorithm;
|
|
21
|
+
export declare type Dictionary = {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
};
|
|
24
|
+
export declare type DecodedToken = {
|
|
25
|
+
header: Dictionary;
|
|
26
|
+
payload: Dictionary;
|
|
27
|
+
};
|
|
28
|
+
export interface SignatureVerifier {
|
|
29
|
+
verify(token: string): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
interface KeyFetcher {
|
|
32
|
+
fetchPublicKeys(): Promise<{
|
|
33
|
+
[key: string]: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
36
|
+
export declare class JwksFetcher implements KeyFetcher {
|
|
37
|
+
private publicKeys;
|
|
38
|
+
private publicKeysExpireAt;
|
|
39
|
+
private client;
|
|
40
|
+
constructor(jwksUrl: string);
|
|
41
|
+
fetchPublicKeys(): Promise<{
|
|
42
|
+
[key: string]: string;
|
|
43
|
+
}>;
|
|
44
|
+
private shouldRefresh;
|
|
45
|
+
private refresh;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Class to fetch public keys from a client certificates URL.
|
|
49
|
+
*/
|
|
50
|
+
export declare class UrlKeyFetcher implements KeyFetcher {
|
|
51
|
+
private clientCertUrl;
|
|
52
|
+
private readonly httpAgent?;
|
|
53
|
+
private publicKeys;
|
|
54
|
+
private publicKeysExpireAt;
|
|
55
|
+
constructor(clientCertUrl: string, httpAgent?: Agent | undefined);
|
|
56
|
+
/**
|
|
57
|
+
* Fetches the public keys for the Google certs.
|
|
58
|
+
*
|
|
59
|
+
* @returns A promise fulfilled with public keys for the Google certs.
|
|
60
|
+
*/
|
|
61
|
+
fetchPublicKeys(): Promise<{
|
|
62
|
+
[key: string]: string;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if the cached public keys need to be refreshed.
|
|
66
|
+
*
|
|
67
|
+
* @returns Whether the keys should be fetched from the client certs url or not.
|
|
68
|
+
*/
|
|
69
|
+
private shouldRefresh;
|
|
70
|
+
private refresh;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Class for verifying JWT signature with a public key.
|
|
74
|
+
*/
|
|
75
|
+
export declare class PublicKeySignatureVerifier implements SignatureVerifier {
|
|
76
|
+
private keyFetcher;
|
|
77
|
+
constructor(keyFetcher: KeyFetcher);
|
|
78
|
+
static withCertificateUrl(clientCertUrl: string, httpAgent?: Agent): PublicKeySignatureVerifier;
|
|
79
|
+
static withJwksUrl(jwksUrl: string): PublicKeySignatureVerifier;
|
|
80
|
+
verify(token: string): Promise<void>;
|
|
81
|
+
private verifyWithoutKid;
|
|
82
|
+
private verifyWithAllKeys;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Class for verifying unsigned (emulator) JWTs.
|
|
86
|
+
*/
|
|
87
|
+
export declare class EmulatorSignatureVerifier implements SignatureVerifier {
|
|
88
|
+
verify(token: string): Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Verifies the signature of a JWT using the provided secret or a function to fetch
|
|
92
|
+
* the secret or public key.
|
|
93
|
+
*
|
|
94
|
+
* @param token - The JWT to be verified.
|
|
95
|
+
* @param secretOrPublicKey - The secret or a function to fetch the secret or public key.
|
|
96
|
+
* @param options - JWT verification options.
|
|
97
|
+
* @returns A Promise resolving for a token with a valid signature.
|
|
98
|
+
*/
|
|
99
|
+
export declare function verifyJwtSignature(token: string, secretOrPublicKey: jwt.Secret | jwt.GetPublicKeyOrSecret, options?: jwt.VerifyOptions): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Decodes general purpose Firebase JWTs.
|
|
102
|
+
*
|
|
103
|
+
* @param jwtToken - JWT token to be decoded.
|
|
104
|
+
* @returns Decoded token containing the header and payload.
|
|
105
|
+
*/
|
|
106
|
+
export declare function decodeJwt(jwtToken: string): Promise<DecodedToken>;
|
|
107
|
+
/**
|
|
108
|
+
* Jwt error code structure.
|
|
109
|
+
*
|
|
110
|
+
* @param code - The error code.
|
|
111
|
+
* @param message - The error message.
|
|
112
|
+
* @constructor
|
|
113
|
+
*/
|
|
114
|
+
export declare class JwtError extends Error {
|
|
115
|
+
readonly code: JwtErrorCode;
|
|
116
|
+
readonly message: string;
|
|
117
|
+
constructor(code: JwtErrorCode, message: string);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* JWT error codes.
|
|
121
|
+
*/
|
|
122
|
+
export declare enum JwtErrorCode {
|
|
123
|
+
INVALID_ARGUMENT = "invalid-argument",
|
|
124
|
+
INVALID_CREDENTIAL = "invalid-credential",
|
|
125
|
+
TOKEN_EXPIRED = "token-expired",
|
|
126
|
+
INVALID_SIGNATURE = "invalid-token",
|
|
127
|
+
NO_MATCHING_KID = "no-matching-kid-error",
|
|
128
|
+
NO_KID_IN_HEADER = "no-kid-error",
|
|
129
|
+
KEY_FETCH_ERROR = "key-fetch-error"
|
|
130
|
+
}
|
|
131
|
+
export {};
|
package/lib/utils/jwt.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! firebase-admin
|
|
1
|
+
/*! firebase-admin v10.0.1 */
|
|
2
2
|
"use strict";
|
|
3
3
|
/*!
|
|
4
4
|
* Copyright 2021 Google Inc.
|
|
@@ -98,7 +98,7 @@ var UrlKeyFetcher = /** @class */ (function () {
|
|
|
98
98
|
/**
|
|
99
99
|
* Fetches the public keys for the Google certs.
|
|
100
100
|
*
|
|
101
|
-
* @
|
|
101
|
+
* @returns A promise fulfilled with public keys for the Google certs.
|
|
102
102
|
*/
|
|
103
103
|
UrlKeyFetcher.prototype.fetchPublicKeys = function () {
|
|
104
104
|
if (this.shouldRefresh()) {
|
|
@@ -165,7 +165,7 @@ var UrlKeyFetcher = /** @class */ (function () {
|
|
|
165
165
|
}());
|
|
166
166
|
exports.UrlKeyFetcher = UrlKeyFetcher;
|
|
167
167
|
/**
|
|
168
|
-
* Class for
|
|
168
|
+
* Class for verifying JWT signature with a public key.
|
|
169
169
|
*/
|
|
170
170
|
var PublicKeySignatureVerifier = /** @class */ (function () {
|
|
171
171
|
function PublicKeySignatureVerifier(keyFetcher) {
|
|
@@ -223,7 +223,7 @@ var PublicKeySignatureVerifier = /** @class */ (function () {
|
|
|
223
223
|
}());
|
|
224
224
|
exports.PublicKeySignatureVerifier = PublicKeySignatureVerifier;
|
|
225
225
|
/**
|
|
226
|
-
* Class for
|
|
226
|
+
* Class for verifying unsigned (emulator) JWTs.
|
|
227
227
|
*/
|
|
228
228
|
var EmulatorSignatureVerifier = /** @class */ (function () {
|
|
229
229
|
function EmulatorSignatureVerifier() {
|
|
@@ -238,7 +238,7 @@ exports.EmulatorSignatureVerifier = EmulatorSignatureVerifier;
|
|
|
238
238
|
/**
|
|
239
239
|
* Provides a callback to fetch public keys.
|
|
240
240
|
*
|
|
241
|
-
* @param fetcher KeyFetcher to fetch the keys from.
|
|
241
|
+
* @param fetcher - KeyFetcher to fetch the keys from.
|
|
242
242
|
* @returns A callback function that can be used to get keys in `jsonwebtoken`.
|
|
243
243
|
*/
|
|
244
244
|
function getKeyCallback(fetcher) {
|
|
@@ -264,9 +264,9 @@ function getKeyCallback(fetcher) {
|
|
|
264
264
|
* Verifies the signature of a JWT using the provided secret or a function to fetch
|
|
265
265
|
* the secret or public key.
|
|
266
266
|
*
|
|
267
|
-
* @param token The JWT to be
|
|
268
|
-
* @param secretOrPublicKey The secret or a function to fetch the secret or public key.
|
|
269
|
-
* @param options JWT verification options.
|
|
267
|
+
* @param token - The JWT to be verified.
|
|
268
|
+
* @param secretOrPublicKey - The secret or a function to fetch the secret or public key.
|
|
269
|
+
* @param options - JWT verification options.
|
|
270
270
|
* @returns A Promise resolving for a token with a valid signature.
|
|
271
271
|
*/
|
|
272
272
|
function verifyJwtSignature(token, secretOrPublicKey, options) {
|
|
@@ -303,7 +303,7 @@ exports.verifyJwtSignature = verifyJwtSignature;
|
|
|
303
303
|
/**
|
|
304
304
|
* Decodes general purpose Firebase JWTs.
|
|
305
305
|
*
|
|
306
|
-
* @param jwtToken JWT token to be decoded.
|
|
306
|
+
* @param jwtToken - JWT token to be decoded.
|
|
307
307
|
* @returns Decoded token containing the header and payload.
|
|
308
308
|
*/
|
|
309
309
|
function decodeJwt(jwtToken) {
|
|
@@ -324,8 +324,8 @@ exports.decodeJwt = decodeJwt;
|
|
|
324
324
|
/**
|
|
325
325
|
* Jwt error code structure.
|
|
326
326
|
*
|
|
327
|
-
* @param code The error code.
|
|
328
|
-
* @param message The error message.
|
|
327
|
+
* @param code - The error code.
|
|
328
|
+
* @param message - The error message.
|
|
329
329
|
* @constructor
|
|
330
330
|
*/
|
|
331
331
|
var JwtError = /** @class */ (function (_super) {
|