firebase-functions 3.20.0 → 3.21.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/lib/apps.js +1 -1
- package/lib/bin/firebase-functions.js +22 -1
- package/lib/cloud-functions.d.ts +56 -35
- package/lib/cloud-functions.js +12 -12
- package/lib/common/encoding.js +21 -1
- package/lib/common/providers/https.d.ts +37 -17
- package/lib/common/providers/https.js +11 -6
- package/lib/common/providers/identity.d.ts +11 -1
- package/lib/common/providers/identity.js +55 -207
- package/lib/common/providers/tasks.d.ts +9 -0
- package/lib/common/providers/tasks.js +12 -3
- package/lib/function-builder.d.ts +2 -2
- package/lib/function-builder.js +1 -1
- package/lib/handler-builder.js +3 -3
- package/lib/index.js +6 -2
- package/lib/logger/common.js +21 -0
- package/lib/logger/compat.js +22 -1
- package/lib/logger/index.d.ts +14 -6
- package/lib/logger/index.js +33 -6
- package/lib/providers/analytics.js +1 -1
- package/lib/providers/auth.d.ts +44 -10
- package/lib/providers/auth.js +80 -14
- package/lib/providers/database.js +11 -11
- package/lib/providers/firestore.js +7 -7
- package/lib/providers/https.js +7 -7
- package/lib/providers/pubsub.d.ts +6 -6
- package/lib/providers/pubsub.js +8 -8
- package/lib/providers/remoteConfig.js +1 -1
- package/lib/providers/storage.js +2 -2
- package/lib/providers/tasks.d.ts +30 -15
- package/lib/providers/tasks.js +19 -12
- package/lib/providers/testLab.js +1 -1
- package/lib/runtime/loader.js +9 -7
- package/lib/runtime/manifest.d.ts +5 -0
- package/lib/setup.js +3 -3
- package/lib/v2/core.d.ts +24 -20
- package/lib/v2/index.d.ts +11 -3
- package/lib/v2/index.js +12 -3
- package/lib/v2/options.d.ts +25 -35
- package/lib/v2/options.js +28 -88
- package/lib/v2/params/index.d.ts +4 -1
- package/lib/v2/params/index.js +25 -1
- package/lib/v2/params/types.js +21 -0
- package/lib/v2/providers/alerts/alerts.d.ts +107 -8
- package/lib/v2/providers/alerts/alerts.js +23 -7
- package/lib/v2/providers/alerts/appDistribution.d.ts +112 -12
- package/lib/v2/providers/alerts/appDistribution.js +29 -2
- package/lib/v2/providers/alerts/billing.d.ts +39 -12
- package/lib/v2/providers/alerts/billing.js +38 -1
- package/lib/v2/providers/alerts/crashlytics.d.ts +255 -47
- package/lib/v2/providers/alerts/crashlytics.js +63 -2
- package/lib/v2/providers/alerts/index.d.ts +6 -0
- package/lib/v2/providers/alerts/index.js +32 -1
- package/lib/v2/providers/eventarc.d.ts +116 -0
- package/lib/v2/providers/eventarc.js +69 -0
- package/lib/v2/providers/https.d.ts +128 -4
- package/lib/v2/providers/https.js +18 -14
- package/lib/v2/providers/identity.d.ts +126 -0
- package/lib/v2/providers/identity.js +104 -0
- package/lib/v2/providers/pubsub.d.ts +125 -8
- package/lib/v2/providers/pubsub.js +60 -7
- package/lib/v2/providers/storage.d.ts +209 -17
- package/lib/v2/providers/storage.js +57 -13
- package/lib/v2/providers/tasks.d.ts +107 -7
- package/lib/v2/providers/tasks.js +11 -8
- package/package.json +22 -3
|
@@ -21,23 +21,12 @@
|
|
|
21
21
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.
|
|
25
|
-
const
|
|
26
|
-
const
|
|
24
|
+
exports.wrapHandler = exports.getUpdateMask = exports.validateAuthResponse = exports.parseAuthEventContext = exports.parseAuthUserRecord = exports.parseMultiFactor = exports.parseDate = exports.parseProviderData = exports.parseMetadata = exports.isValidRequest = exports.userRecordConstructor = exports.UserRecordMetadata = exports.HttpsError = void 0;
|
|
25
|
+
const __1 = require("../..");
|
|
26
|
+
const apps_1 = require("../../apps");
|
|
27
|
+
const debug_1 = require("../debug");
|
|
27
28
|
const https_1 = require("./https");
|
|
28
29
|
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
|
|
29
|
-
const function_configuration_1 = require("../../function-configuration");
|
|
30
|
-
const __1 = require("../..");
|
|
31
|
-
/** @internal */
|
|
32
|
-
exports.INVALID_TOKEN_BUFFER = 60000; // set to 1 minute
|
|
33
|
-
/** @internal */
|
|
34
|
-
exports.JWT_CLIENT_CERT_URL = 'https://www.googleapis.com';
|
|
35
|
-
/** @internal */
|
|
36
|
-
exports.JWT_CLIENT_CERT_PATH = 'robot/v1/metadata/x509/securetoken@system.gserviceaccount.com';
|
|
37
|
-
/** @internal */
|
|
38
|
-
exports.JWT_ALG = 'RS256';
|
|
39
|
-
/** @internal */
|
|
40
|
-
exports.JWT_ISSUER = 'https://securetoken.google.com/';
|
|
41
30
|
const DISALLOWED_CUSTOM_CLAIMS = [
|
|
42
31
|
'acr',
|
|
43
32
|
'amr',
|
|
@@ -98,19 +87,14 @@ function userRecordConstructor(wireData) {
|
|
|
98
87
|
tokensValidAfterTime: null,
|
|
99
88
|
};
|
|
100
89
|
const record = { ...falseyValues, ...wireData };
|
|
101
|
-
const meta = record
|
|
90
|
+
const meta = record.metadata;
|
|
102
91
|
if (meta) {
|
|
103
|
-
record
|
|
92
|
+
record.metadata = new UserRecordMetadata(meta.createdAt || meta.creationTime, meta.lastSignedInAt || meta.lastSignInTime);
|
|
104
93
|
}
|
|
105
94
|
else {
|
|
106
|
-
record
|
|
95
|
+
record.metadata = new UserRecordMetadata(null, null);
|
|
107
96
|
}
|
|
108
|
-
|
|
109
|
-
entry['toJSON'] = () => {
|
|
110
|
-
return entry;
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
record['toJSON'] = () => {
|
|
97
|
+
record.toJSON = () => {
|
|
114
98
|
const { uid, email, emailVerified, displayName, photoURL, phoneNumber, disabled, passwordHash, passwordSalt, tokensValidAfterTime, } = record;
|
|
115
99
|
const json = {
|
|
116
100
|
uid,
|
|
@@ -124,58 +108,14 @@ function userRecordConstructor(wireData) {
|
|
|
124
108
|
passwordSalt,
|
|
125
109
|
tokensValidAfterTime,
|
|
126
110
|
};
|
|
127
|
-
json
|
|
128
|
-
json
|
|
129
|
-
json
|
|
111
|
+
json.metadata = record.metadata.toJSON();
|
|
112
|
+
json.customClaims = JSON.parse(JSON.stringify(record.customClaims));
|
|
113
|
+
json.providerData = record.providerData.map((entry) => entry.toJSON());
|
|
130
114
|
return json;
|
|
131
115
|
};
|
|
132
116
|
return record;
|
|
133
117
|
}
|
|
134
118
|
exports.userRecordConstructor = userRecordConstructor;
|
|
135
|
-
/**
|
|
136
|
-
* Helper to determine if we refresh the public keys
|
|
137
|
-
* @internal
|
|
138
|
-
*/
|
|
139
|
-
function invalidPublicKeys(keys, time = Date.now()) {
|
|
140
|
-
if (!keys.publicKeysExpireAt) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
return time + exports.INVALID_TOKEN_BUFFER >= keys.publicKeysExpireAt;
|
|
144
|
-
}
|
|
145
|
-
exports.invalidPublicKeys = invalidPublicKeys;
|
|
146
|
-
/**
|
|
147
|
-
* Helper to parse the response headers to obtain the expiration time.
|
|
148
|
-
* @internal
|
|
149
|
-
*/
|
|
150
|
-
function setKeyExpirationTime(response, keysCache, time) {
|
|
151
|
-
if (response.headers.has('cache-control')) {
|
|
152
|
-
const ccHeader = response.headers.get('cache-control');
|
|
153
|
-
const maxAgeEntry = ccHeader
|
|
154
|
-
.split(', ')
|
|
155
|
-
.find((item) => item.includes('max-age'));
|
|
156
|
-
if (maxAgeEntry) {
|
|
157
|
-
const maxAge = +maxAgeEntry.trim().split('=')[1];
|
|
158
|
-
keysCache.publicKeysExpireAt = time + maxAge * 1000;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.setKeyExpirationTime = setKeyExpirationTime;
|
|
163
|
-
/**
|
|
164
|
-
* Fetch the public keys for use in decoding and verifying the jwt sent from identity platform.
|
|
165
|
-
*/
|
|
166
|
-
async function refreshPublicKeys(keysCache, time = Date.now()) {
|
|
167
|
-
const url = `${exports.JWT_CLIENT_CERT_URL}/${exports.JWT_CLIENT_CERT_PATH}`;
|
|
168
|
-
try {
|
|
169
|
-
const response = await node_fetch_1.default(url);
|
|
170
|
-
setKeyExpirationTime(response, keysCache, time);
|
|
171
|
-
const data = await response.json();
|
|
172
|
-
keysCache.publicKeys = data;
|
|
173
|
-
}
|
|
174
|
-
catch (err) {
|
|
175
|
-
__1.logger.error(`Failed to obtain public keys for JWT verification: ${err.message}`);
|
|
176
|
-
throw new https_1.HttpsError('internal', 'Failed to obtain the public keys for JWT verification.');
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
119
|
/**
|
|
180
120
|
* Checks for a valid identity platform web request, otherwise throws an HttpsError
|
|
181
121
|
* @internal
|
|
@@ -198,120 +138,18 @@ function isValidRequest(req) {
|
|
|
198
138
|
return true;
|
|
199
139
|
}
|
|
200
140
|
exports.isValidRequest = isValidRequest;
|
|
201
|
-
/** @internal */
|
|
202
|
-
function getPublicKeyFromHeader(header, publicKeys) {
|
|
203
|
-
if (header.alg !== exports.JWT_ALG) {
|
|
204
|
-
throw new https_1.HttpsError('invalid-argument', `Provided JWT has incorrect algorithm. Expected ${exports.JWT_ALG} but got ${header.alg}.`);
|
|
205
|
-
}
|
|
206
|
-
if (!header.kid) {
|
|
207
|
-
throw new https_1.HttpsError('invalid-argument', 'JWT header missing "kid" claim.');
|
|
208
|
-
}
|
|
209
|
-
if (!publicKeys.hasOwnProperty(header.kid)) {
|
|
210
|
-
throw new https_1.HttpsError('invalid-argument', 'Provided JWT has "kid" claim which does not correspond to a known public key. Most likely the JWT is expired.');
|
|
211
|
-
}
|
|
212
|
-
return publicKeys[header.kid];
|
|
213
|
-
}
|
|
214
|
-
exports.getPublicKeyFromHeader = getPublicKeyFromHeader;
|
|
215
141
|
/**
|
|
216
|
-
*
|
|
217
|
-
*
|
|
142
|
+
* Decode, but not verify, an Auth Blocking token.
|
|
143
|
+
*
|
|
144
|
+
* Do not use in production. Token should always be verified using the Admin SDK.
|
|
145
|
+
*
|
|
146
|
+
* This is exposed only for testing.
|
|
218
147
|
*/
|
|
219
|
-
function
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
return res.length > 0;
|
|
223
|
-
}
|
|
224
|
-
exports.isAuthorizedCloudFunctionURL = isAuthorizedCloudFunctionURL;
|
|
225
|
-
/**
|
|
226
|
-
* Checks for errors in a decoded jwt
|
|
227
|
-
* @internal
|
|
228
|
-
*/
|
|
229
|
-
function checkDecodedToken(decodedJWT, eventType, projectId) {
|
|
230
|
-
if (decodedJWT.event_type !== eventType) {
|
|
231
|
-
throw new https_1.HttpsError('invalid-argument', `Expected "${eventType}" but received "${decodedJWT.event_type}".`);
|
|
232
|
-
}
|
|
233
|
-
if (!isAuthorizedCloudFunctionURL(decodedJWT.aud, projectId)) {
|
|
234
|
-
throw new https_1.HttpsError('invalid-argument', 'Provided JWT has incorrect "aud" (audience) claim.');
|
|
235
|
-
}
|
|
236
|
-
if (decodedJWT.iss !== `${exports.JWT_ISSUER}${projectId}`) {
|
|
237
|
-
throw new https_1.HttpsError('invalid-argument', `Provided JWT has incorrect "iss" (issuer) claim. Expected ` +
|
|
238
|
-
`"${exports.JWT_ISSUER}${projectId}" but got "${decodedJWT.iss}".`);
|
|
239
|
-
}
|
|
240
|
-
if (typeof decodedJWT.sub !== 'string' || decodedJWT.sub.length === 0) {
|
|
241
|
-
throw new https_1.HttpsError('invalid-argument', 'Provided JWT has no "sub" (subject) claim.');
|
|
242
|
-
}
|
|
243
|
-
if (decodedJWT.sub.length > 128) {
|
|
244
|
-
throw new https_1.HttpsError('invalid-argument', 'Provided JWT has "sub" (subject) claim longer than 128 characters.');
|
|
245
|
-
}
|
|
246
|
-
// set uid to sub
|
|
247
|
-
decodedJWT.uid = decodedJWT.sub;
|
|
248
|
-
}
|
|
249
|
-
exports.checkDecodedToken = checkDecodedToken;
|
|
250
|
-
/**
|
|
251
|
-
* Helper function to decode the jwt, internally uses the 'jsonwebtoken' package.
|
|
252
|
-
* @internal
|
|
253
|
-
*/
|
|
254
|
-
function decodeJWT(token) {
|
|
255
|
-
let decoded;
|
|
256
|
-
try {
|
|
257
|
-
decoded = jwt.decode(token, { complete: true });
|
|
258
|
-
}
|
|
259
|
-
catch (err) {
|
|
260
|
-
__1.logger.error('Decoding the JWT failed', err);
|
|
261
|
-
throw new https_1.HttpsError('internal', 'Failed to decode the JWT.');
|
|
262
|
-
}
|
|
263
|
-
if (!(decoded === null || decoded === void 0 ? void 0 : decoded.payload)) {
|
|
264
|
-
throw new https_1.HttpsError('internal', 'The decoded JWT is not structured correctly.');
|
|
265
|
-
}
|
|
148
|
+
function unsafeDecodeAuthBlockingToken(token) {
|
|
149
|
+
const decoded = (0, https_1.unsafeDecodeToken)(token);
|
|
150
|
+
decoded.uid = decoded.sub;
|
|
266
151
|
return decoded;
|
|
267
152
|
}
|
|
268
|
-
exports.decodeJWT = decodeJWT;
|
|
269
|
-
/**
|
|
270
|
-
* Helper function to determine if we need to do full verification of the jwt
|
|
271
|
-
* @internal
|
|
272
|
-
*/
|
|
273
|
-
function shouldVerifyJWT() {
|
|
274
|
-
// TODO(colerogers): add emulator support to skip verification
|
|
275
|
-
return true;
|
|
276
|
-
}
|
|
277
|
-
exports.shouldVerifyJWT = shouldVerifyJWT;
|
|
278
|
-
/**
|
|
279
|
-
* Verifies the jwt using the 'jwt' library and decodes the token with the public keys
|
|
280
|
-
* Throws an error if the event types do not match
|
|
281
|
-
* @internal
|
|
282
|
-
*/
|
|
283
|
-
function verifyJWT(token, rawDecodedJWT, keysCache, time = Date.now()) {
|
|
284
|
-
if (!rawDecodedJWT.header) {
|
|
285
|
-
throw new https_1.HttpsError('internal', 'Unable to verify JWT payload, the decoded JWT does not have a header property.');
|
|
286
|
-
}
|
|
287
|
-
const header = rawDecodedJWT.header;
|
|
288
|
-
let publicKey;
|
|
289
|
-
try {
|
|
290
|
-
if (invalidPublicKeys(keysCache, time)) {
|
|
291
|
-
refreshPublicKeys(keysCache);
|
|
292
|
-
}
|
|
293
|
-
publicKey = getPublicKeyFromHeader(header, keysCache.publicKeys);
|
|
294
|
-
return jwt.verify(token, publicKey, {
|
|
295
|
-
algorithms: [exports.JWT_ALG],
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
catch (err) {
|
|
299
|
-
__1.logger.error('Verifying the JWT failed', err);
|
|
300
|
-
}
|
|
301
|
-
// force refresh keys and retry one more time
|
|
302
|
-
try {
|
|
303
|
-
refreshPublicKeys(keysCache);
|
|
304
|
-
publicKey = getPublicKeyFromHeader(header, keysCache.publicKeys);
|
|
305
|
-
return jwt.verify(token, publicKey, {
|
|
306
|
-
algorithms: [exports.JWT_ALG],
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
__1.logger.error('Verifying the JWT failed again', err);
|
|
311
|
-
throw new https_1.HttpsError('internal', 'Failed to verify the JWT.');
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
exports.verifyJWT = verifyJWT;
|
|
315
153
|
/**
|
|
316
154
|
* Helper function to parse the decoded metadata object into a UserMetaData object
|
|
317
155
|
* @internal
|
|
@@ -436,13 +274,14 @@ exports.parseAuthUserRecord = parseAuthUserRecord;
|
|
|
436
274
|
/** Helper to get the AdditionalUserInfo from the decoded jwt */
|
|
437
275
|
function parseAdditionalUserInfo(decodedJWT) {
|
|
438
276
|
let profile, username;
|
|
439
|
-
if (decodedJWT.raw_user_info)
|
|
277
|
+
if (decodedJWT.raw_user_info) {
|
|
440
278
|
try {
|
|
441
279
|
profile = JSON.parse(decodedJWT.raw_user_info);
|
|
442
280
|
}
|
|
443
281
|
catch (err) {
|
|
444
282
|
__1.logger.debug(`Parse Error: ${err.message}`);
|
|
445
283
|
}
|
|
284
|
+
}
|
|
446
285
|
if (profile) {
|
|
447
286
|
if (decodedJWT.sign_in_method === 'github.com') {
|
|
448
287
|
username = profile.login;
|
|
@@ -570,17 +409,7 @@ function getUpdateMask(authResponse) {
|
|
|
570
409
|
}
|
|
571
410
|
exports.getUpdateMask = getUpdateMask;
|
|
572
411
|
/** @internal */
|
|
573
|
-
function
|
|
574
|
-
const wrappedHandler = wrapHandler(handler, eventType, keysCache);
|
|
575
|
-
return (req, res) => {
|
|
576
|
-
return new Promise((resolve) => {
|
|
577
|
-
res.on('finish', resolve);
|
|
578
|
-
resolve(wrappedHandler(req, res));
|
|
579
|
-
});
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
exports.createHandler = createHandler;
|
|
583
|
-
function wrapHandler(handler, eventType, keysCache) {
|
|
412
|
+
function wrapHandler(eventType, handler) {
|
|
584
413
|
return async (req, res) => {
|
|
585
414
|
try {
|
|
586
415
|
const projectId = process.env.GCLOUD_PROJECT;
|
|
@@ -588,22 +417,39 @@ function wrapHandler(handler, eventType, keysCache) {
|
|
|
588
417
|
__1.logger.error('Invalid request, unable to process');
|
|
589
418
|
throw new https_1.HttpsError('invalid-argument', 'Bad Request');
|
|
590
419
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
420
|
+
if (!(0, apps_1.apps)().admin.auth()._verifyAuthBlockingToken) {
|
|
421
|
+
throw new Error('Cannot validate Auth Blocking token. Please update Firebase Admin SDK to >= v10.1.0');
|
|
422
|
+
}
|
|
423
|
+
const decodedPayload = (0, debug_1.isDebugFeatureEnabled)('skipTokenVerification')
|
|
424
|
+
? unsafeDecodeAuthBlockingToken(req.body.data.jwt)
|
|
425
|
+
: await (0, apps_1.apps)()
|
|
426
|
+
.admin.auth()
|
|
427
|
+
._verifyAuthBlockingToken(req.body.data.jwt);
|
|
596
428
|
const authUserRecord = parseAuthUserRecord(decodedPayload.user_record);
|
|
597
429
|
const authEventContext = parseAuthEventContext(decodedPayload, projectId);
|
|
598
|
-
|
|
430
|
+
let authResponse;
|
|
431
|
+
if (handler.length === 2) {
|
|
432
|
+
authResponse =
|
|
433
|
+
(await handler(authUserRecord, authEventContext)) ||
|
|
434
|
+
undefined;
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
authResponse =
|
|
438
|
+
(await handler({
|
|
439
|
+
...authEventContext,
|
|
440
|
+
data: authUserRecord,
|
|
441
|
+
})) || undefined;
|
|
442
|
+
}
|
|
599
443
|
validateAuthResponse(eventType, authResponse);
|
|
600
444
|
const updateMask = getUpdateMask(authResponse);
|
|
601
|
-
const result =
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
445
|
+
const result = updateMask.length === 0
|
|
446
|
+
? {}
|
|
447
|
+
: {
|
|
448
|
+
userRecord: {
|
|
449
|
+
...authResponse,
|
|
450
|
+
updateMask,
|
|
451
|
+
},
|
|
452
|
+
};
|
|
607
453
|
res.status(200);
|
|
608
454
|
res.setHeader('Content-Type', 'application/json');
|
|
609
455
|
res.send(JSON.stringify(result));
|
|
@@ -614,9 +460,11 @@ function wrapHandler(handler, eventType, keysCache) {
|
|
|
614
460
|
__1.logger.error('Unhandled error', err);
|
|
615
461
|
err = new https_1.HttpsError('internal', 'An unexpected error occurred.');
|
|
616
462
|
}
|
|
617
|
-
|
|
463
|
+
const { status } = err.httpErrorCode;
|
|
464
|
+
const body = { error: err.toJSON() };
|
|
618
465
|
res.setHeader('Content-Type', 'application/json');
|
|
619
|
-
res.
|
|
466
|
+
res.status(status).send(body);
|
|
620
467
|
}
|
|
621
468
|
};
|
|
622
469
|
}
|
|
470
|
+
exports.wrapHandler = wrapHandler;
|
|
@@ -29,9 +29,18 @@ export interface RetryConfig {
|
|
|
29
29
|
}
|
|
30
30
|
/** How congestion control should be applied to the function. */
|
|
31
31
|
export interface RateLimits {
|
|
32
|
+
/**
|
|
33
|
+
* The maximum number of requests that can be outstanding at a time.
|
|
34
|
+
* If left unspecified, will default to 1000.
|
|
35
|
+
*/
|
|
32
36
|
maxConcurrentDispatches?: number;
|
|
37
|
+
/**
|
|
38
|
+
* The maximum number of requests that can be invoked per second.
|
|
39
|
+
* If left unspecified, will default to 500.
|
|
40
|
+
*/
|
|
33
41
|
maxDispatchesPerSecond?: number;
|
|
34
42
|
}
|
|
43
|
+
/** Metadata about the authorization used to invoke a function. */
|
|
35
44
|
export interface AuthData {
|
|
36
45
|
uid: string;
|
|
37
46
|
token: firebase.auth.DecodedIdToken;
|
|
@@ -27,17 +27,26 @@ const https = require("./https");
|
|
|
27
27
|
/** @internal */
|
|
28
28
|
function onDispatchHandler(handler) {
|
|
29
29
|
return async (req, res) => {
|
|
30
|
+
var _a;
|
|
30
31
|
try {
|
|
31
32
|
if (!https.isValidRequest(req)) {
|
|
32
33
|
logger.error('Invalid request, unable to process.');
|
|
33
34
|
throw new https.HttpsError('invalid-argument', 'Bad Request');
|
|
34
35
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
36
|
+
const authHeader = req.header('Authorization') || '';
|
|
37
|
+
const token = (_a = authHeader.match(/^Bearer (.*)$/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
37
38
|
// Note: this should never happen since task queue functions are guarded by IAM.
|
|
38
|
-
if (
|
|
39
|
+
if (!token) {
|
|
39
40
|
throw new https.HttpsError('unauthenticated', 'Unauthenticated');
|
|
40
41
|
}
|
|
42
|
+
// We skip authenticating the token since tq functions are guarded by IAM.
|
|
43
|
+
const authToken = await https.unsafeDecodeIdToken(token);
|
|
44
|
+
const context = {
|
|
45
|
+
auth: {
|
|
46
|
+
uid: authToken.uid,
|
|
47
|
+
token: authToken,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
41
50
|
const data = https.decode(req.body.data);
|
|
42
51
|
if (handler.length === 2) {
|
|
43
52
|
await handler(data, context);
|
|
@@ -78,7 +78,7 @@ export declare class FunctionBuilder {
|
|
|
78
78
|
* Declares a callable method for clients to call using a Firebase SDK.
|
|
79
79
|
* @param handler A method that takes a data and context and returns a value.
|
|
80
80
|
*/
|
|
81
|
-
onCall: (handler: (data: any, context: https.CallableContext) => any | Promise<any>) => import("./cloud-functions").
|
|
81
|
+
onCall: (handler: (data: any, context: https.CallableContext) => any | Promise<any>) => import("./cloud-functions").HttpsFunction & import("./cloud-functions").Runnable<any>;
|
|
82
82
|
};
|
|
83
83
|
get tasks(): {
|
|
84
84
|
/**
|
|
@@ -178,7 +178,7 @@ export declare class FunctionBuilder {
|
|
|
178
178
|
/**
|
|
179
179
|
* Handle events related to Firebase authentication users.
|
|
180
180
|
*/
|
|
181
|
-
user: () => auth.UserBuilder;
|
|
181
|
+
user: (userOptions?: auth.UserOptions) => auth.UserBuilder;
|
|
182
182
|
};
|
|
183
183
|
get testLab(): {
|
|
184
184
|
/**
|
package/lib/function-builder.js
CHANGED
|
@@ -356,7 +356,7 @@ class FunctionBuilder {
|
|
|
356
356
|
/**
|
|
357
357
|
* Handle events related to Firebase authentication users.
|
|
358
358
|
*/
|
|
359
|
-
user: () => auth._userWithOptions(this.options),
|
|
359
|
+
user: (userOptions) => auth._userWithOptions(this.options, userOptions),
|
|
360
360
|
};
|
|
361
361
|
}
|
|
362
362
|
get testLab() {
|
package/lib/handler-builder.js
CHANGED
|
@@ -141,12 +141,12 @@ class HandlerBuilder {
|
|
|
141
141
|
get instance() {
|
|
142
142
|
return {
|
|
143
143
|
get ref() {
|
|
144
|
-
return new database.RefBuilder(apps_1.apps(), () => null, {});
|
|
144
|
+
return new database.RefBuilder((0, apps_1.apps)(), () => null, {});
|
|
145
145
|
},
|
|
146
146
|
};
|
|
147
147
|
},
|
|
148
148
|
get ref() {
|
|
149
|
-
return new database.RefBuilder(apps_1.apps(), () => null, {});
|
|
149
|
+
return new database.RefBuilder((0, apps_1.apps)(), () => null, {});
|
|
150
150
|
},
|
|
151
151
|
};
|
|
152
152
|
}
|
|
@@ -323,7 +323,7 @@ class HandlerBuilder {
|
|
|
323
323
|
get auth() {
|
|
324
324
|
return {
|
|
325
325
|
get user() {
|
|
326
|
-
return new auth.UserBuilder(() => null, {});
|
|
326
|
+
return new auth.UserBuilder(() => null, {}, {});
|
|
327
327
|
},
|
|
328
328
|
};
|
|
329
329
|
}
|
package/lib/index.js
CHANGED
|
@@ -22,7 +22,11 @@
|
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
24
|
if (k2 === undefined) k2 = k;
|
|
25
|
-
Object.
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
26
30
|
}) : (function(o, m, k, k2) {
|
|
27
31
|
if (k2 === undefined) k2 = k;
|
|
28
32
|
o[k2] = m[k];
|
|
@@ -66,4 +70,4 @@ __exportStar(require("./cloud-functions"), exports);
|
|
|
66
70
|
__exportStar(require("./config"), exports);
|
|
67
71
|
__exportStar(require("./function-builder"), exports);
|
|
68
72
|
__exportStar(require("./function-configuration"), exports);
|
|
69
|
-
setup_1.setup();
|
|
73
|
+
(0, setup_1.setup)();
|
package/lib/logger/common.js
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2017 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
2
23
|
var _a, _b, _c;
|
|
3
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
25
|
exports.UNPATCHED_CONSOLE = exports.CONSOLE_SEVERITY = exports.SUPPORTS_STRUCTURED_LOGS = void 0;
|
package/lib/logger/compat.js
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2017 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
2
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
24
|
const util_1 = require("util");
|
|
4
25
|
const common_1 = require("./common");
|
|
@@ -6,7 +27,7 @@ const common_1 = require("./common");
|
|
|
6
27
|
function patchedConsole(severity) {
|
|
7
28
|
return function (data, ...args) {
|
|
8
29
|
if (common_1.SUPPORTS_STRUCTURED_LOGS) {
|
|
9
|
-
common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message: util_1.format(data, ...args) }));
|
|
30
|
+
common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](JSON.stringify({ severity, message: (0, util_1.format)(data, ...args) }));
|
|
10
31
|
return;
|
|
11
32
|
}
|
|
12
33
|
common_1.UNPATCHED_CONSOLE[common_1.CONSOLE_SEVERITY[severity]](data, ...args);
|
package/lib/logger/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `LogSeverity` indicates the detailed severity of the log entry. See [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity).
|
|
3
|
+
* @public
|
|
3
4
|
*/
|
|
4
5
|
export declare type LogSeverity = 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';
|
|
5
6
|
/**
|
|
6
7
|
* `LogEntry` represents a [structured Cloud Logging](https://cloud.google.com/logging/docs/structured-logging)
|
|
7
8
|
* entry. All keys aside from `severity` and `message` are
|
|
8
9
|
* included in the `jsonPayload` of the logged entry.
|
|
10
|
+
* @public
|
|
9
11
|
*/
|
|
10
12
|
export interface LogEntry {
|
|
11
13
|
severity: LogSeverity;
|
|
@@ -14,36 +16,42 @@ export interface LogEntry {
|
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Writes a `LogEntry` to `stdout`/`stderr` (depending on severity).
|
|
17
|
-
* @param entry The `LogEntry` including severity, message, and any additional structured metadata.
|
|
19
|
+
* @param entry - The `LogEntry` including severity, message, and any additional structured metadata.
|
|
20
|
+
* @public
|
|
18
21
|
*/
|
|
19
22
|
export declare function write(entry: LogEntry): void;
|
|
20
23
|
/**
|
|
21
24
|
* Writes a `DEBUG` severity log. If the last argument provided is a plain object,
|
|
22
25
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
23
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
26
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
27
|
+
* @public
|
|
24
28
|
*/
|
|
25
29
|
export declare function debug(...args: any[]): void;
|
|
26
30
|
/**
|
|
27
31
|
* Writes an `INFO` severity log. If the last argument provided is a plain object,
|
|
28
32
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
29
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
33
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
34
|
+
* @public
|
|
30
35
|
*/
|
|
31
36
|
export declare function log(...args: any[]): void;
|
|
32
37
|
/**
|
|
33
38
|
* Writes an `INFO` severity log. If the last argument provided is a plain object,
|
|
34
39
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
35
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
40
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
41
|
+
* @public
|
|
36
42
|
*/
|
|
37
43
|
export declare function info(...args: any[]): void;
|
|
38
44
|
/**
|
|
39
45
|
* Writes a `WARNING` severity log. If the last argument provided is a plain object,
|
|
40
46
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
41
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
47
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
48
|
+
* @public
|
|
42
49
|
*/
|
|
43
50
|
export declare function warn(...args: any[]): void;
|
|
44
51
|
/**
|
|
45
52
|
* Writes an `ERROR` severity log. If the last argument provided is a plain object,
|
|
46
53
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
47
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
54
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
55
|
+
* @public
|
|
48
56
|
*/
|
|
49
57
|
export declare function error(...args: any[]): void;
|