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.
- package/LICENSE +201 -0
- package/README.md +90 -0
- package/lib/app-check/app-check-api-client-internal.js +197 -0
- package/lib/app-check/app-check.js +79 -0
- package/lib/app-check/index.d.ts +160 -0
- package/lib/app-check/index.js +19 -0
- package/lib/app-check/token-generator.js +161 -0
- package/lib/app-check/token-verifier.js +152 -0
- package/lib/auth/action-code-settings-builder.js +118 -0
- package/lib/auth/auth-api-request.js +1856 -0
- package/lib/auth/auth-config.js +636 -0
- package/lib/auth/auth.js +836 -0
- package/lib/auth/identifier.js +40 -0
- package/lib/auth/index.d.ts +1927 -0
- package/lib/auth/index.js +18 -0
- package/lib/auth/tenant-manager.js +140 -0
- package/lib/auth/tenant.js +171 -0
- package/lib/auth/token-generator.js +200 -0
- package/lib/auth/token-verifier.js +259 -0
- package/lib/auth/user-import-builder.js +387 -0
- package/lib/auth/user-record.js +346 -0
- package/lib/credential/credential-internal.js +391 -0
- package/lib/credential/credential.js +44 -0
- package/lib/credential/index.d.ts +169 -0
- package/lib/credential/index.js +23 -0
- package/lib/database/database-internal.js +266 -0
- package/lib/database/index.d.ts +89 -0
- package/lib/database/index.js +31 -0
- package/lib/default-namespace.js +31 -0
- package/lib/firebase-app.js +349 -0
- package/lib/firebase-namespace-api.d.ts +243 -0
- package/lib/firebase-namespace-api.js +18 -0
- package/lib/firebase-namespace.d.ts +31 -0
- package/lib/firebase-namespace.js +417 -0
- package/lib/firestore/firestore-internal.js +105 -0
- package/lib/firestore/index.d.ts +50 -0
- package/lib/firestore/index.js +47 -0
- package/lib/index.d.ts +24 -0
- package/lib/index.js +27 -0
- package/lib/installations/index.d.ts +81 -0
- package/lib/installations/index.js +18 -0
- package/lib/installations/installations-request-handler.js +117 -0
- package/lib/installations/installations.js +62 -0
- package/lib/instance-id/index.d.ts +83 -0
- package/lib/instance-id/index.js +18 -0
- package/lib/instance-id/instance-id.js +87 -0
- package/lib/machine-learning/index.d.ts +249 -0
- package/lib/machine-learning/index.js +18 -0
- package/lib/machine-learning/machine-learning-api-client.js +304 -0
- package/lib/machine-learning/machine-learning-utils.js +62 -0
- package/lib/machine-learning/machine-learning.js +364 -0
- package/lib/messaging/batch-request-internal.js +129 -0
- package/lib/messaging/index.d.ts +1174 -0
- package/lib/messaging/index.js +18 -0
- package/lib/messaging/messaging-api-request-internal.js +128 -0
- package/lib/messaging/messaging-errors-internal.js +106 -0
- package/lib/messaging/messaging-internal.js +484 -0
- package/lib/messaging/messaging.js +846 -0
- package/lib/project-management/android-app.js +176 -0
- package/lib/project-management/index.d.ts +363 -0
- package/lib/project-management/index.js +41 -0
- package/lib/project-management/ios-app.js +88 -0
- package/lib/project-management/project-management-api-request-internal.js +273 -0
- package/lib/project-management/project-management.js +254 -0
- package/lib/remote-config/index.d.ts +369 -0
- package/lib/remote-config/index.js +18 -0
- package/lib/remote-config/remote-config-api-client-internal.js +407 -0
- package/lib/remote-config/remote-config.js +304 -0
- package/lib/security-rules/index.d.ts +216 -0
- package/lib/security-rules/index.js +18 -0
- package/lib/security-rules/security-rules-api-client-internal.js +237 -0
- package/lib/security-rules/security-rules-internal.js +41 -0
- package/lib/security-rules/security-rules.js +310 -0
- package/lib/storage/index.d.ts +60 -0
- package/lib/storage/index.js +18 -0
- package/lib/storage/storage.js +123 -0
- package/lib/utils/api-request.js +845 -0
- package/lib/utils/crypto-signer.js +237 -0
- package/lib/utils/deep-copy.js +78 -0
- package/lib/utils/error.js +1063 -0
- package/lib/utils/index.js +217 -0
- package/lib/utils/jwt.js +355 -0
- package/lib/utils/validator.js +271 -0
- package/package.json +122 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/*! firebase-admin v9.12.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
/*!
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2021 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
|
+
var __extends = (this && this.__extends) || (function () {
|
|
20
|
+
var extendStatics = function (d, b) {
|
|
21
|
+
extendStatics = Object.setPrototypeOf ||
|
|
22
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
23
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
24
|
+
return extendStatics(d, b);
|
|
25
|
+
};
|
|
26
|
+
return function (d, b) {
|
|
27
|
+
extendStatics(d, b);
|
|
28
|
+
function __() { this.constructor = d; }
|
|
29
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
+
};
|
|
31
|
+
})();
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.CryptoSignerErrorCode = exports.CryptoSignerError = exports.cryptoSignerFromApp = exports.IAMSigner = exports.ServiceAccountSigner = void 0;
|
|
34
|
+
var credential_internal_1 = require("../credential/credential-internal");
|
|
35
|
+
var api_request_1 = require("./api-request");
|
|
36
|
+
var validator = require("../utils/validator");
|
|
37
|
+
var ALGORITHM_RS256 = 'RS256';
|
|
38
|
+
/**
|
|
39
|
+
* A CryptoSigner implementation that uses an explicitly specified service account private key to
|
|
40
|
+
* sign data. Performs all operations locally, and does not make any RPC calls.
|
|
41
|
+
*/
|
|
42
|
+
var ServiceAccountSigner = /** @class */ (function () {
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new CryptoSigner instance from the given service account credential.
|
|
45
|
+
*
|
|
46
|
+
* @param {ServiceAccountCredential} credential A service account credential.
|
|
47
|
+
*/
|
|
48
|
+
function ServiceAccountSigner(credential) {
|
|
49
|
+
this.credential = credential;
|
|
50
|
+
this.algorithm = ALGORITHM_RS256;
|
|
51
|
+
if (!credential) {
|
|
52
|
+
throw new CryptoSignerError({
|
|
53
|
+
code: CryptoSignerErrorCode.INVALID_CREDENTIAL,
|
|
54
|
+
message: 'INTERNAL ASSERT: Must provide a service account credential to initialize ServiceAccountSigner.',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @inheritDoc
|
|
60
|
+
*/
|
|
61
|
+
ServiceAccountSigner.prototype.sign = function (buffer) {
|
|
62
|
+
var crypto = require('crypto'); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
63
|
+
var sign = crypto.createSign('RSA-SHA256');
|
|
64
|
+
sign.update(buffer);
|
|
65
|
+
return Promise.resolve(sign.sign(this.credential.privateKey));
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @inheritDoc
|
|
69
|
+
*/
|
|
70
|
+
ServiceAccountSigner.prototype.getAccountId = function () {
|
|
71
|
+
return Promise.resolve(this.credential.clientEmail);
|
|
72
|
+
};
|
|
73
|
+
return ServiceAccountSigner;
|
|
74
|
+
}());
|
|
75
|
+
exports.ServiceAccountSigner = ServiceAccountSigner;
|
|
76
|
+
/**
|
|
77
|
+
* A CryptoSigner implementation that uses the remote IAM service to sign data. If initialized without
|
|
78
|
+
* a service account ID, attempts to discover a service account ID by consulting the local Metadata
|
|
79
|
+
* service. This will succeed in managed environments like Google Cloud Functions and App Engine.
|
|
80
|
+
*
|
|
81
|
+
* @see https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob
|
|
82
|
+
* @see https://cloud.google.com/compute/docs/storing-retrieving-metadata
|
|
83
|
+
*/
|
|
84
|
+
var IAMSigner = /** @class */ (function () {
|
|
85
|
+
function IAMSigner(httpClient, serviceAccountId) {
|
|
86
|
+
this.algorithm = ALGORITHM_RS256;
|
|
87
|
+
if (!httpClient) {
|
|
88
|
+
throw new CryptoSignerError({
|
|
89
|
+
code: CryptoSignerErrorCode.INVALID_ARGUMENT,
|
|
90
|
+
message: 'INTERNAL ASSERT: Must provide a HTTP client to initialize IAMSigner.',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (typeof serviceAccountId !== 'undefined' && !validator.isNonEmptyString(serviceAccountId)) {
|
|
94
|
+
throw new CryptoSignerError({
|
|
95
|
+
code: CryptoSignerErrorCode.INVALID_ARGUMENT,
|
|
96
|
+
message: 'INTERNAL ASSERT: Service account ID must be undefined or a non-empty string.',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
this.httpClient = httpClient;
|
|
100
|
+
this.serviceAccountId = serviceAccountId;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @inheritDoc
|
|
104
|
+
*/
|
|
105
|
+
IAMSigner.prototype.sign = function (buffer) {
|
|
106
|
+
var _this = this;
|
|
107
|
+
return this.getAccountId().then(function (serviceAccount) {
|
|
108
|
+
var request = {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
url: "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/" + serviceAccount + ":signBlob",
|
|
111
|
+
data: { payload: buffer.toString('base64') },
|
|
112
|
+
};
|
|
113
|
+
return _this.httpClient.send(request);
|
|
114
|
+
}).then(function (response) {
|
|
115
|
+
// Response from IAM is base64 encoded. Decode it into a buffer and return.
|
|
116
|
+
return Buffer.from(response.data.signedBlob, 'base64');
|
|
117
|
+
}).catch(function (err) {
|
|
118
|
+
if (err instanceof api_request_1.HttpError) {
|
|
119
|
+
throw new CryptoSignerError({
|
|
120
|
+
code: CryptoSignerErrorCode.SERVER_ERROR,
|
|
121
|
+
message: err.message,
|
|
122
|
+
cause: err
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
throw err;
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* @inheritDoc
|
|
130
|
+
*/
|
|
131
|
+
IAMSigner.prototype.getAccountId = function () {
|
|
132
|
+
var _this = this;
|
|
133
|
+
if (validator.isNonEmptyString(this.serviceAccountId)) {
|
|
134
|
+
return Promise.resolve(this.serviceAccountId);
|
|
135
|
+
}
|
|
136
|
+
var request = {
|
|
137
|
+
method: 'GET',
|
|
138
|
+
url: 'http://metadata/computeMetadata/v1/instance/service-accounts/default/email',
|
|
139
|
+
headers: {
|
|
140
|
+
'Metadata-Flavor': 'Google',
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
var client = new api_request_1.HttpClient();
|
|
144
|
+
return client.send(request).then(function (response) {
|
|
145
|
+
if (!response.text) {
|
|
146
|
+
throw new CryptoSignerError({
|
|
147
|
+
code: CryptoSignerErrorCode.INTERNAL_ERROR,
|
|
148
|
+
message: 'HTTP Response missing payload',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
_this.serviceAccountId = response.text;
|
|
152
|
+
return response.text;
|
|
153
|
+
}).catch(function (err) {
|
|
154
|
+
throw new CryptoSignerError({
|
|
155
|
+
code: CryptoSignerErrorCode.INVALID_CREDENTIAL,
|
|
156
|
+
message: 'Failed to determine service account. Make sure to initialize ' +
|
|
157
|
+
'the SDK with a service account credential. Alternatively specify a service ' +
|
|
158
|
+
("account with iam.serviceAccounts.signBlob permission. Original error: " + err),
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
return IAMSigner;
|
|
163
|
+
}());
|
|
164
|
+
exports.IAMSigner = IAMSigner;
|
|
165
|
+
/**
|
|
166
|
+
* Creates a new CryptoSigner instance for the given app. If the app has been initialized with a
|
|
167
|
+
* service account credential, creates a ServiceAccountSigner.
|
|
168
|
+
*
|
|
169
|
+
* @param {FirebaseApp} app A FirebaseApp instance.
|
|
170
|
+
* @return {CryptoSigner} A CryptoSigner instance.
|
|
171
|
+
*/
|
|
172
|
+
function cryptoSignerFromApp(app) {
|
|
173
|
+
var credential = app.options.credential;
|
|
174
|
+
if (credential instanceof credential_internal_1.ServiceAccountCredential) {
|
|
175
|
+
return new ServiceAccountSigner(credential);
|
|
176
|
+
}
|
|
177
|
+
return new IAMSigner(new api_request_1.AuthorizedHttpClient(app), app.options.serviceAccountId);
|
|
178
|
+
}
|
|
179
|
+
exports.cryptoSignerFromApp = cryptoSignerFromApp;
|
|
180
|
+
/**
|
|
181
|
+
* CryptoSigner error code structure.
|
|
182
|
+
*
|
|
183
|
+
* @param {ErrorInfo} errorInfo The error information (code and message).
|
|
184
|
+
* @constructor
|
|
185
|
+
*/
|
|
186
|
+
var CryptoSignerError = /** @class */ (function (_super) {
|
|
187
|
+
__extends(CryptoSignerError, _super);
|
|
188
|
+
function CryptoSignerError(errorInfo) {
|
|
189
|
+
var _this = _super.call(this, errorInfo.message) || this;
|
|
190
|
+
_this.errorInfo = errorInfo;
|
|
191
|
+
/* tslint:disable:max-line-length */
|
|
192
|
+
// Set the prototype explicitly. See the following link for more details:
|
|
193
|
+
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
|
|
194
|
+
/* tslint:enable:max-line-length */
|
|
195
|
+
_this.__proto__ = CryptoSignerError.prototype;
|
|
196
|
+
return _this;
|
|
197
|
+
}
|
|
198
|
+
Object.defineProperty(CryptoSignerError.prototype, "code", {
|
|
199
|
+
/** @return {string} The error code. */
|
|
200
|
+
get: function () {
|
|
201
|
+
return this.errorInfo.code;
|
|
202
|
+
},
|
|
203
|
+
enumerable: false,
|
|
204
|
+
configurable: true
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(CryptoSignerError.prototype, "message", {
|
|
207
|
+
/** @return {string} The error message. */
|
|
208
|
+
get: function () {
|
|
209
|
+
return this.errorInfo.message;
|
|
210
|
+
},
|
|
211
|
+
enumerable: false,
|
|
212
|
+
configurable: true
|
|
213
|
+
});
|
|
214
|
+
Object.defineProperty(CryptoSignerError.prototype, "cause", {
|
|
215
|
+
/** @return {object} The error data. */
|
|
216
|
+
get: function () {
|
|
217
|
+
return this.errorInfo.cause;
|
|
218
|
+
},
|
|
219
|
+
enumerable: false,
|
|
220
|
+
configurable: true
|
|
221
|
+
});
|
|
222
|
+
return CryptoSignerError;
|
|
223
|
+
}(Error));
|
|
224
|
+
exports.CryptoSignerError = CryptoSignerError;
|
|
225
|
+
/**
|
|
226
|
+
* Crypto Signer error codes and their default messages.
|
|
227
|
+
*/
|
|
228
|
+
var CryptoSignerErrorCode = /** @class */ (function () {
|
|
229
|
+
function CryptoSignerErrorCode() {
|
|
230
|
+
}
|
|
231
|
+
CryptoSignerErrorCode.INVALID_ARGUMENT = 'invalid-argument';
|
|
232
|
+
CryptoSignerErrorCode.INTERNAL_ERROR = 'internal-error';
|
|
233
|
+
CryptoSignerErrorCode.INVALID_CREDENTIAL = 'invalid-credential';
|
|
234
|
+
CryptoSignerErrorCode.SERVER_ERROR = 'server-error';
|
|
235
|
+
return CryptoSignerErrorCode;
|
|
236
|
+
}());
|
|
237
|
+
exports.CryptoSignerErrorCode = CryptoSignerErrorCode;
|
|
@@ -0,0 +1,78 @@
|
|
|
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.deepExtend = exports.deepCopy = void 0;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a deep copy of an object or array.
|
|
23
|
+
*
|
|
24
|
+
* @param {object|array} value The object or array to deep copy.
|
|
25
|
+
* @return {object|array} A deep copy of the provided object or array.
|
|
26
|
+
*/
|
|
27
|
+
function deepCopy(value) {
|
|
28
|
+
return deepExtend(undefined, value);
|
|
29
|
+
}
|
|
30
|
+
exports.deepCopy = deepCopy;
|
|
31
|
+
/**
|
|
32
|
+
* Copies properties from source to target (recursively allows extension of objects and arrays).
|
|
33
|
+
* Scalar values in the target are over-written. If target is undefined, an object of the
|
|
34
|
+
* appropriate type will be created (and returned).
|
|
35
|
+
*
|
|
36
|
+
* We recursively copy all child properties of plain objects in the source - so that namespace-like
|
|
37
|
+
* objects are merged.
|
|
38
|
+
*
|
|
39
|
+
* Note that the target can be a function, in which case the properties in the source object are
|
|
40
|
+
* copied onto it as static properties of the function.
|
|
41
|
+
*
|
|
42
|
+
* @param {any} target The value which is being extended.
|
|
43
|
+
* @param {any} source The value whose properties are extending the target.
|
|
44
|
+
* @return {any} The target value.
|
|
45
|
+
*/
|
|
46
|
+
function deepExtend(target, source) {
|
|
47
|
+
if (!(source instanceof Object)) {
|
|
48
|
+
return source;
|
|
49
|
+
}
|
|
50
|
+
switch (source.constructor) {
|
|
51
|
+
case Date: {
|
|
52
|
+
// Treat Dates like scalars; if the target date object had any child
|
|
53
|
+
// properties - they will be lost!
|
|
54
|
+
var dateValue = source;
|
|
55
|
+
return new Date(dateValue.getTime());
|
|
56
|
+
}
|
|
57
|
+
case Object:
|
|
58
|
+
if (target === undefined) {
|
|
59
|
+
target = {};
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case Array:
|
|
63
|
+
// Always copy the array source and overwrite the target.
|
|
64
|
+
target = [];
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
// Not a plain Object - treat it as a scalar.
|
|
68
|
+
return source;
|
|
69
|
+
}
|
|
70
|
+
for (var prop in source) {
|
|
71
|
+
if (!Object.prototype.hasOwnProperty.call(source, prop)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
target[prop] = deepExtend(target[prop], source[prop]);
|
|
75
|
+
}
|
|
76
|
+
return target;
|
|
77
|
+
}
|
|
78
|
+
exports.deepExtend = deepExtend;
|