firebase-functions 3.20.1 → 3.21.2
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 +59 -207
- package/lib/common/providers/tasks.d.ts +9 -0
- 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 -4
- package/lib/v2/index.js +12 -5
- 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 +90 -6
- package/lib/v2/providers/eventarc.js +7 -3
- 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 +18 -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,18 @@ 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) => {
|
|
114
|
+
const newEntry = { ...entry };
|
|
115
|
+
newEntry.toJSON = () => entry;
|
|
116
|
+
return newEntry;
|
|
117
|
+
});
|
|
130
118
|
return json;
|
|
131
119
|
};
|
|
132
120
|
return record;
|
|
133
121
|
}
|
|
134
122
|
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
123
|
/**
|
|
180
124
|
* Checks for a valid identity platform web request, otherwise throws an HttpsError
|
|
181
125
|
* @internal
|
|
@@ -198,120 +142,18 @@ function isValidRequest(req) {
|
|
|
198
142
|
return true;
|
|
199
143
|
}
|
|
200
144
|
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
|
-
/**
|
|
216
|
-
* Checks for a well forms cloud functions url
|
|
217
|
-
* @internal
|
|
218
|
-
*/
|
|
219
|
-
function isAuthorizedCloudFunctionURL(cloudFunctionUrl, projectId) {
|
|
220
|
-
const re = new RegExp(`^https://(${function_configuration_1.SUPPORTED_REGIONS.join('|')})+-${projectId}\.cloudfunctions\.net/`);
|
|
221
|
-
const res = re.exec(cloudFunctionUrl) || [];
|
|
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
145
|
/**
|
|
251
|
-
*
|
|
252
|
-
*
|
|
146
|
+
* Decode, but not verify, an Auth Blocking token.
|
|
147
|
+
*
|
|
148
|
+
* Do not use in production. Token should always be verified using the Admin SDK.
|
|
149
|
+
*
|
|
150
|
+
* This is exposed only for testing.
|
|
253
151
|
*/
|
|
254
|
-
function
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
}
|
|
152
|
+
function unsafeDecodeAuthBlockingToken(token) {
|
|
153
|
+
const decoded = (0, https_1.unsafeDecodeToken)(token);
|
|
154
|
+
decoded.uid = decoded.sub;
|
|
266
155
|
return decoded;
|
|
267
156
|
}
|
|
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
157
|
/**
|
|
316
158
|
* Helper function to parse the decoded metadata object into a UserMetaData object
|
|
317
159
|
* @internal
|
|
@@ -436,13 +278,14 @@ exports.parseAuthUserRecord = parseAuthUserRecord;
|
|
|
436
278
|
/** Helper to get the AdditionalUserInfo from the decoded jwt */
|
|
437
279
|
function parseAdditionalUserInfo(decodedJWT) {
|
|
438
280
|
let profile, username;
|
|
439
|
-
if (decodedJWT.raw_user_info)
|
|
281
|
+
if (decodedJWT.raw_user_info) {
|
|
440
282
|
try {
|
|
441
283
|
profile = JSON.parse(decodedJWT.raw_user_info);
|
|
442
284
|
}
|
|
443
285
|
catch (err) {
|
|
444
286
|
__1.logger.debug(`Parse Error: ${err.message}`);
|
|
445
287
|
}
|
|
288
|
+
}
|
|
446
289
|
if (profile) {
|
|
447
290
|
if (decodedJWT.sign_in_method === 'github.com') {
|
|
448
291
|
username = profile.login;
|
|
@@ -570,17 +413,7 @@ function getUpdateMask(authResponse) {
|
|
|
570
413
|
}
|
|
571
414
|
exports.getUpdateMask = getUpdateMask;
|
|
572
415
|
/** @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) {
|
|
416
|
+
function wrapHandler(eventType, handler) {
|
|
584
417
|
return async (req, res) => {
|
|
585
418
|
try {
|
|
586
419
|
const projectId = process.env.GCLOUD_PROJECT;
|
|
@@ -588,22 +421,39 @@ function wrapHandler(handler, eventType, keysCache) {
|
|
|
588
421
|
__1.logger.error('Invalid request, unable to process');
|
|
589
422
|
throw new https_1.HttpsError('invalid-argument', 'Bad Request');
|
|
590
423
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
424
|
+
if (!(0, apps_1.apps)().admin.auth()._verifyAuthBlockingToken) {
|
|
425
|
+
throw new Error('Cannot validate Auth Blocking token. Please update Firebase Admin SDK to >= v10.1.0');
|
|
426
|
+
}
|
|
427
|
+
const decodedPayload = (0, debug_1.isDebugFeatureEnabled)('skipTokenVerification')
|
|
428
|
+
? unsafeDecodeAuthBlockingToken(req.body.data.jwt)
|
|
429
|
+
: await (0, apps_1.apps)()
|
|
430
|
+
.admin.auth()
|
|
431
|
+
._verifyAuthBlockingToken(req.body.data.jwt);
|
|
596
432
|
const authUserRecord = parseAuthUserRecord(decodedPayload.user_record);
|
|
597
433
|
const authEventContext = parseAuthEventContext(decodedPayload, projectId);
|
|
598
|
-
|
|
434
|
+
let authResponse;
|
|
435
|
+
if (handler.length === 2) {
|
|
436
|
+
authResponse =
|
|
437
|
+
(await handler(authUserRecord, authEventContext)) ||
|
|
438
|
+
undefined;
|
|
439
|
+
}
|
|
440
|
+
else {
|
|
441
|
+
authResponse =
|
|
442
|
+
(await handler({
|
|
443
|
+
...authEventContext,
|
|
444
|
+
data: authUserRecord,
|
|
445
|
+
})) || undefined;
|
|
446
|
+
}
|
|
599
447
|
validateAuthResponse(eventType, authResponse);
|
|
600
448
|
const updateMask = getUpdateMask(authResponse);
|
|
601
|
-
const result =
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
449
|
+
const result = updateMask.length === 0
|
|
450
|
+
? {}
|
|
451
|
+
: {
|
|
452
|
+
userRecord: {
|
|
453
|
+
...authResponse,
|
|
454
|
+
updateMask,
|
|
455
|
+
},
|
|
456
|
+
};
|
|
607
457
|
res.status(200);
|
|
608
458
|
res.setHeader('Content-Type', 'application/json');
|
|
609
459
|
res.send(JSON.stringify(result));
|
|
@@ -614,9 +464,11 @@ function wrapHandler(handler, eventType, keysCache) {
|
|
|
614
464
|
__1.logger.error('Unhandled error', err);
|
|
615
465
|
err = new https_1.HttpsError('internal', 'An unexpected error occurred.');
|
|
616
466
|
}
|
|
617
|
-
|
|
467
|
+
const { status } = err.httpErrorCode;
|
|
468
|
+
const body = { error: err.toJSON() };
|
|
618
469
|
res.setHeader('Content-Type', 'application/json');
|
|
619
|
-
res.
|
|
470
|
+
res.status(status).send(body);
|
|
620
471
|
}
|
|
621
472
|
};
|
|
622
473
|
}
|
|
474
|
+
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;
|
|
@@ -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;
|
package/lib/logger/index.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
|
exports.error = exports.warn = exports.info = exports.log = exports.debug = exports.write = void 0;
|
|
4
25
|
const util_1 = require("util");
|
|
@@ -37,7 +58,8 @@ function removeCircular(obj, refs = []) {
|
|
|
37
58
|
}
|
|
38
59
|
/**
|
|
39
60
|
* Writes a `LogEntry` to `stdout`/`stderr` (depending on severity).
|
|
40
|
-
* @param entry The `LogEntry` including severity, message, and any additional structured metadata.
|
|
61
|
+
* @param entry - The `LogEntry` including severity, message, and any additional structured metadata.
|
|
62
|
+
* @public
|
|
41
63
|
*/
|
|
42
64
|
function write(entry) {
|
|
43
65
|
if (common_1.SUPPORTS_STRUCTURED_LOGS) {
|
|
@@ -62,7 +84,8 @@ exports.write = write;
|
|
|
62
84
|
/**
|
|
63
85
|
* Writes a `DEBUG` severity log. If the last argument provided is a plain object,
|
|
64
86
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
65
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
87
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
88
|
+
* @public
|
|
66
89
|
*/
|
|
67
90
|
function debug(...args) {
|
|
68
91
|
write(entryFromArgs('DEBUG', args));
|
|
@@ -71,7 +94,8 @@ exports.debug = debug;
|
|
|
71
94
|
/**
|
|
72
95
|
* Writes an `INFO` severity log. If the last argument provided is a plain object,
|
|
73
96
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
74
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
97
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
98
|
+
* @public
|
|
75
99
|
*/
|
|
76
100
|
function log(...args) {
|
|
77
101
|
write(entryFromArgs('INFO', args));
|
|
@@ -80,7 +104,8 @@ exports.log = log;
|
|
|
80
104
|
/**
|
|
81
105
|
* Writes an `INFO` severity log. If the last argument provided is a plain object,
|
|
82
106
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
83
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
107
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
108
|
+
* @public
|
|
84
109
|
*/
|
|
85
110
|
function info(...args) {
|
|
86
111
|
write(entryFromArgs('INFO', args));
|
|
@@ -89,7 +114,8 @@ exports.info = info;
|
|
|
89
114
|
/**
|
|
90
115
|
* Writes a `WARNING` severity log. If the last argument provided is a plain object,
|
|
91
116
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
92
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
117
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
118
|
+
* @public
|
|
93
119
|
*/
|
|
94
120
|
function warn(...args) {
|
|
95
121
|
write(entryFromArgs('WARNING', args));
|
|
@@ -98,7 +124,8 @@ exports.warn = warn;
|
|
|
98
124
|
/**
|
|
99
125
|
* Writes an `ERROR` severity log. If the last argument provided is a plain object,
|
|
100
126
|
* it is added to the `jsonPayload` in the Cloud Logging entry.
|
|
101
|
-
* @param args Arguments, concatenated into the log message with space separators.
|
|
127
|
+
* @param args - Arguments, concatenated into the log message with space separators.
|
|
128
|
+
* @public
|
|
102
129
|
*/
|
|
103
130
|
function error(...args) {
|
|
104
131
|
write(entryFromArgs('ERROR', args));
|
|
@@ -73,7 +73,7 @@ class AnalyticsEventBuilder {
|
|
|
73
73
|
const dataConstructor = (raw) => {
|
|
74
74
|
return new AnalyticsEvent(raw.data);
|
|
75
75
|
};
|
|
76
|
-
return cloud_functions_1.makeCloudFunction({
|
|
76
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
77
77
|
handler,
|
|
78
78
|
provider: exports.provider,
|
|
79
79
|
eventType: 'event.log',
|