firebase-tools 15.32.1 → 15.34.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/README.md +9 -0
- package/lib/api.js +4 -2
- package/lib/apphosting/backend.js +1 -1
- package/lib/checkValidTargetFilters.js +1 -0
- package/lib/command.js +30 -23
- package/lib/commands/apps-create.js +34 -3
- package/lib/commands/crashlytics-heapdumps-disable.js +26 -0
- package/lib/commands/crashlytics-heapdumps-enable.js +54 -0
- package/lib/commands/crashlytics-heapdumps-status.js +32 -0
- package/lib/commands/deploy.js +3 -0
- package/lib/commands/functions-kits-uninstall.js +43 -21
- package/lib/commands/functions-lifecycle-list.js +5 -6
- package/lib/commands/hosting-channel-deploy.js +3 -3
- package/lib/commands/hosting-clone.js +102 -31
- package/lib/commands/hosting-disable.js +5 -1
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +7 -0
- package/lib/commands/run-services-update.js +16 -0
- package/lib/crashlytics/onboarding.js +17 -2
- package/lib/crashlytics/profilingManager.js +195 -0
- package/lib/deploy/apphosting/prepare.js +1 -0
- package/lib/deploy/auth/deploy.js +1 -1
- package/lib/deploy/auth/prepare.js +6 -7
- package/lib/deploy/firestore/prepare.js +5 -5
- package/lib/deploy/functions/build.js +3 -0
- package/lib/deploy/functions/cel.js +89 -58
- package/lib/deploy/functions/functionsDeployHelper.js +10 -0
- package/lib/deploy/functions/prepare.js +25 -8
- package/lib/deploy/functions/release/executor.js +7 -3
- package/lib/deploy/functions/release/fabricator.js +42 -14
- package/lib/deploy/functions/release/planner.js +3 -2
- package/lib/deploy/functions/release/sourceTokenScraper.js +1 -1
- package/lib/deploy/functions/validate.js +16 -0
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/deploy/hosting/release.js +2 -2
- package/lib/deploy/index.js +5 -0
- package/lib/deploy/run/args.js +2 -0
- package/lib/deploy/run/buildEnv.js +72 -0
- package/lib/deploy/run/deploy.js +214 -0
- package/lib/deploy/run/index.js +23 -0
- package/lib/deploy/run/prepare.js +47 -0
- package/lib/deploy/run/prereqs.js +32 -0
- package/lib/deploy/run/release.js +9 -0
- package/lib/deploy/run/update.js +50 -0
- package/lib/deploy/run/util.js +73 -0
- package/lib/emulator/apphosting/serve.js +1 -1
- package/lib/emulator/auth/utils.js +1 -1
- package/lib/emulator/commandUtils.js +7 -3
- package/lib/emulator/dataconnect/pgliteServer.js +1 -1
- package/lib/emulator/dataconnectEmulator.js +1 -1
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/downloadableEmulators.js +1 -3
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/functionsEmulatorShared.js +1 -41
- package/lib/experiments.js +12 -11
- package/lib/firestore/validator.js +1 -1
- package/lib/frameworks/next/constants.js +20 -12
- package/lib/frameworks/next/index.js +3 -0
- package/lib/functions/env.js +4 -2
- package/lib/functions/projectConfig.js +10 -5
- package/lib/gcp/artifactregistry.js +20 -0
- package/lib/gcp/cloudsql/permissions.js +21 -32
- package/lib/gcp/cloudsql/permissionsSetup.js +6 -6
- package/lib/gcp/cloudtasks.js +14 -0
- package/lib/gcp/cloudtrace.js +38 -0
- package/lib/gcp/run.js +5 -0
- package/lib/gcp/runv2.js +32 -11
- package/lib/gcp/storage.js +9 -5
- package/lib/hosting/api.js +15 -15
- package/lib/hosting/runTags.js +1 -1
- package/lib/init/features/auth.js +46 -8
- package/lib/init/features/index.js +4 -1
- package/lib/init/features/run.js +159 -0
- package/lib/init/index.js +6 -0
- package/lib/mcp/tools/firestore/converter.js +2 -2
- package/lib/mcp/util.js +11 -10
- package/lib/profileReport.js +12 -9
- package/lib/throttler/throttler.js +1 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +2 -8
- package/schema/firebaserc.json +133 -0
- package/lib/mcp/resources/guides/init_data_connect.js +0 -30
- package/lib/mcp/resources/guides/init_rtdb.js +0 -30
|
@@ -10,9 +10,10 @@ const CMP = /((?:!=)|(?:==)|(?:>=)|(?:<=)|>|<)/.source;
|
|
|
10
10
|
const identityRegexp = /{{ params\.(\S+) }}/;
|
|
11
11
|
const dualComparisonRegexp = new RegExp(/{{ params\.(\S+) CMP params\.(\S+) }}/.source.replace("CMP", CMP));
|
|
12
12
|
const comparisonRegexp = new RegExp(/{{ params\.(\S+) CMP (.+) }}/.source.replace("CMP", CMP));
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
13
|
+
const EXPR_PREFIX = "{{ ";
|
|
14
|
+
const EXPR_SUFFIX = " }}";
|
|
15
|
+
const QUESTION_TOKEN = " ? ";
|
|
16
|
+
const COLON_TOKEN = " : ";
|
|
16
17
|
function listEquals(a, b) {
|
|
17
18
|
return a.every((item) => b.includes(item)) && b.every((item) => a.includes(item));
|
|
18
19
|
}
|
|
@@ -28,36 +29,74 @@ function isComparisonExpression(value) {
|
|
|
28
29
|
function isDualComparisonExpression(value) {
|
|
29
30
|
return dualComparisonRegexp.test(value);
|
|
30
31
|
}
|
|
31
|
-
function isTernaryExpression(value) {
|
|
32
|
-
return ternaryRegexp.test(value);
|
|
33
|
-
}
|
|
34
|
-
function isLiteralTernaryExpression(value) {
|
|
35
|
-
return literalTernaryRegexp.test(value);
|
|
36
|
-
}
|
|
37
|
-
function isDualTernaryExpression(value) {
|
|
38
|
-
return dualTernaryRegexp.test(value);
|
|
39
|
-
}
|
|
40
32
|
class ExprParseError extends error_1.FirebaseError {
|
|
41
33
|
}
|
|
42
34
|
exports.ExprParseError = ExprParseError;
|
|
35
|
+
function parseTernary(expr) {
|
|
36
|
+
if (!expr.startsWith(EXPR_PREFIX) || !expr.endsWith(EXPR_SUFFIX)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const body = expr.slice(EXPR_PREFIX.length, -EXPR_SUFFIX.length);
|
|
40
|
+
let inQuotes = false;
|
|
41
|
+
let depth = 0;
|
|
42
|
+
let question = -1;
|
|
43
|
+
let colon = -1;
|
|
44
|
+
for (let i = 0; i < body.length; i++) {
|
|
45
|
+
if (inQuotes && body[i] === "\\") {
|
|
46
|
+
i++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (body[i] === '"') {
|
|
50
|
+
inQuotes = !inQuotes;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (inQuotes)
|
|
54
|
+
continue;
|
|
55
|
+
if (body.startsWith(QUESTION_TOKEN, i)) {
|
|
56
|
+
if (depth === 0) {
|
|
57
|
+
question = i;
|
|
58
|
+
}
|
|
59
|
+
depth++;
|
|
60
|
+
i += QUESTION_TOKEN.length - 1;
|
|
61
|
+
}
|
|
62
|
+
else if (body.startsWith(COLON_TOKEN, i)) {
|
|
63
|
+
if (depth > 0) {
|
|
64
|
+
depth--;
|
|
65
|
+
if (depth === 0) {
|
|
66
|
+
colon = i;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
i += COLON_TOKEN.length - 1;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (question === -1) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if (colon === -1) {
|
|
77
|
+
throw new ExprParseError(`Malformed CEL ternary expression '${expr}'`);
|
|
78
|
+
}
|
|
79
|
+
const condition = body.slice(0, question).trim();
|
|
80
|
+
const ifTrue = body.slice(question + QUESTION_TOKEN.length, colon).trim();
|
|
81
|
+
const ifFalse = body.slice(colon + COLON_TOKEN.length).trim();
|
|
82
|
+
if (!condition || !ifTrue || !ifFalse) {
|
|
83
|
+
throw new ExprParseError(`Malformed CEL ternary expression '${expr}'`);
|
|
84
|
+
}
|
|
85
|
+
return { condition, ifTrue, ifFalse };
|
|
86
|
+
}
|
|
43
87
|
function resolveExpression(wantType, expr, params) {
|
|
44
88
|
expr = preprocessLists(wantType, expr, params);
|
|
45
89
|
if (isIdentityExpression(expr)) {
|
|
46
90
|
return resolveIdentity(wantType, expr, params);
|
|
47
91
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
else if (isLiteralTernaryExpression(expr)) {
|
|
52
|
-
return resolveLiteralTernary(wantType, expr, params);
|
|
92
|
+
const ternary = parseTernary(expr);
|
|
93
|
+
if (ternary) {
|
|
94
|
+
return resolveTernary({ wantType, expr, parts: ternary, params });
|
|
53
95
|
}
|
|
54
|
-
else if (
|
|
55
|
-
return resolveTernary(wantType, expr, params);
|
|
56
|
-
}
|
|
57
|
-
else if (isDualComparisonExpression(expr)) {
|
|
96
|
+
else if (wantType === "boolean" && isDualComparisonExpression(expr)) {
|
|
58
97
|
return resolveDualComparison(expr, params);
|
|
59
98
|
}
|
|
60
|
-
else if (isComparisonExpression(expr)) {
|
|
99
|
+
else if (wantType === "boolean" && isComparisonExpression(expr)) {
|
|
61
100
|
return resolveComparison(expr, params);
|
|
62
101
|
}
|
|
63
102
|
else {
|
|
@@ -261,53 +300,45 @@ function resolveDualComparison(expr, params) {
|
|
|
261
300
|
throw new ExprParseError(`could not infer type of param ${lhsName} used in comparison operation`);
|
|
262
301
|
}
|
|
263
302
|
}
|
|
264
|
-
function resolveTernary(
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
return resolveParamListOrLiteral(wantType, match[5], params);
|
|
276
|
-
}
|
|
303
|
+
function resolveTernary(options) {
|
|
304
|
+
const { wantType, expr, parts, params } = options;
|
|
305
|
+
const isTrue = resolveTernaryCondition(expr, parts.condition, params);
|
|
306
|
+
return resolveTernaryBranch({
|
|
307
|
+
wantType,
|
|
308
|
+
expr,
|
|
309
|
+
branch: isTrue ? parts.ifTrue : parts.ifFalse,
|
|
310
|
+
params,
|
|
311
|
+
});
|
|
277
312
|
}
|
|
278
|
-
function
|
|
279
|
-
const
|
|
280
|
-
if (
|
|
281
|
-
|
|
313
|
+
function resolveTernaryCondition(expr, condition, params) {
|
|
314
|
+
const conditionExpr = `${EXPR_PREFIX}${condition}${EXPR_SUFFIX}`;
|
|
315
|
+
if (isDualComparisonExpression(conditionExpr)) {
|
|
316
|
+
return resolveDualComparison(conditionExpr, params);
|
|
282
317
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (isTrue) {
|
|
286
|
-
return resolveParamListOrLiteral(wantType, match[4], params);
|
|
318
|
+
else if (isComparisonExpression(conditionExpr)) {
|
|
319
|
+
return resolveComparison(conditionExpr, params);
|
|
287
320
|
}
|
|
288
|
-
|
|
289
|
-
return resolveParamListOrLiteral(wantType, match[5], params);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
function resolveLiteralTernary(wantType, expr, params) {
|
|
293
|
-
const match = literalTernaryRegexp.exec(expr);
|
|
321
|
+
const match = identityRegexp.exec(conditionExpr);
|
|
294
322
|
if (!match) {
|
|
295
|
-
throw new ExprParseError(
|
|
323
|
+
throw new ExprParseError(`CEL ternary expression '${expr}' is conditioned on an unsupported form`);
|
|
296
324
|
}
|
|
297
325
|
const paramName = match[1];
|
|
298
|
-
const paramValue = params[
|
|
326
|
+
const paramValue = params[paramName];
|
|
299
327
|
if (!paramValue) {
|
|
300
|
-
throw new ExprParseError(
|
|
328
|
+
throw new ExprParseError(`CEL ternary expression '${expr}' references missing param ${paramName}`);
|
|
301
329
|
}
|
|
302
330
|
if (!paramValue.legalBoolean) {
|
|
303
|
-
throw new ExprParseError(
|
|
331
|
+
throw new ExprParseError(`CEL ternary expression '${expr}' is conditional on non-boolean param ${paramName}`);
|
|
304
332
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
333
|
+
return paramValue.asBoolean();
|
|
334
|
+
}
|
|
335
|
+
function resolveTernaryBranch(options) {
|
|
336
|
+
const { wantType, expr, branch, params } = options;
|
|
337
|
+
const nested = parseTernary(`${EXPR_PREFIX}${branch}${EXPR_SUFFIX}`);
|
|
338
|
+
if (nested) {
|
|
339
|
+
return resolveTernary({ wantType, expr, parts: nested, params });
|
|
310
340
|
}
|
|
341
|
+
return resolveParamListOrLiteral(wantType, branch, params);
|
|
311
342
|
}
|
|
312
343
|
function resolveParamListOrLiteral(wantType, field, params) {
|
|
313
344
|
const match = paramRegexp.exec(field);
|
|
@@ -7,6 +7,7 @@ exports.parseFunctionSelector = parseFunctionSelector;
|
|
|
7
7
|
exports.getEndpointFilters = getEndpointFilters;
|
|
8
8
|
exports.getHumanFriendlyPlatformName = getHumanFriendlyPlatformName;
|
|
9
9
|
exports.getFunctionLabel = getFunctionLabel;
|
|
10
|
+
exports.generationDowngradeMessage = generationDowngradeMessage;
|
|
10
11
|
exports.targetCodebases = targetCodebases;
|
|
11
12
|
exports.groupEndpointsByCodebase = groupEndpointsByCodebase;
|
|
12
13
|
exports.isCodebaseFiltered = isCodebaseFiltered;
|
|
@@ -101,6 +102,15 @@ function getFunctionLabel(fn) {
|
|
|
101
102
|
}
|
|
102
103
|
return id;
|
|
103
104
|
}
|
|
105
|
+
function generationDowngradeMessage(want, have) {
|
|
106
|
+
if (want.platform !== "gcfv1" || have.platform === "gcfv1") {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const from = have.platform === "gcfv2" ? "GCFv2" : "Cloud Run";
|
|
110
|
+
return (`[${getFunctionLabel(want)}] Functions cannot be downgraded from ${from} to GCFv1. ` +
|
|
111
|
+
`To recreate it as GCFv1, delete the existing function first: ` +
|
|
112
|
+
`firebase functions:delete ${want.id} --region ${want.region}`);
|
|
113
|
+
}
|
|
104
114
|
function targetCodebases(config, filters) {
|
|
105
115
|
const codebasesFromConfig = getCodebasesFromConfig(config);
|
|
106
116
|
if (!filters) {
|
|
@@ -23,6 +23,7 @@ const experiments = require("../../experiments");
|
|
|
23
23
|
const ensureApiEnabled = require("../../ensureApiEnabled");
|
|
24
24
|
const functionsConfig = require("../../functionsConfig");
|
|
25
25
|
const functionsEnv = require("../../functions/env");
|
|
26
|
+
const params = require("./params");
|
|
26
27
|
const runtimes = require("./runtimes");
|
|
27
28
|
const supported = require("./runtimes/supported");
|
|
28
29
|
const validate = require("./validate");
|
|
@@ -206,12 +207,11 @@ async function prepare(context, options, payload) {
|
|
|
206
207
|
const rawUserEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
207
208
|
const { userEnvs: userEnvs, secretRefs: secretRefs } = partitionUserEnvs(rawUserEnvs);
|
|
208
209
|
const envs = { ...userEnvs, ...firebaseEnvs };
|
|
210
|
+
const parsedSecretRefs = (0, functional_1.mapObject)(secretRefs, (unparsed) => build.parseSecretRef(unparsed));
|
|
211
|
+
await build.applyEnvSecretBindingsToBuild(wantBuild, parsedSecretRefs);
|
|
209
212
|
const relevantEndpoints = backend
|
|
210
213
|
.allEndpoints(existingBackend)
|
|
211
214
|
.filter((e) => e.codebase === codebase || e.codebase === undefined);
|
|
212
|
-
await resolveDefaultRegionsForBuild(wantBuild, backend.of(...relevantEndpoints));
|
|
213
|
-
const parsedSecretRefs = (0, functional_1.mapObject)(secretRefs, (unparsed) => build.parseSecretRef(unparsed));
|
|
214
|
-
await build.applyEnvSecretBindingsToBuild(wantBuild, parsedSecretRefs);
|
|
215
215
|
const { backend: wantBackend, envs: resolvedEnvs, secretRefs: resolvedSecretRefs, } = await build.resolveBackend({
|
|
216
216
|
build: wantBuild,
|
|
217
217
|
firebaseConfig,
|
|
@@ -219,6 +219,7 @@ async function prepare(context, options, payload) {
|
|
|
219
219
|
codebase,
|
|
220
220
|
nonInteractive: options.nonInteractive,
|
|
221
221
|
isEmulator: false,
|
|
222
|
+
resolveRegions: (b, paramValues) => resolveDefaultRegionsForBuild(b, backend.of(...relevantEndpoints), paramValues),
|
|
222
223
|
});
|
|
223
224
|
functionsEnv.writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt);
|
|
224
225
|
if (experiments.isEnabled("secretEnvParams") &&
|
|
@@ -276,6 +277,7 @@ async function prepare(context, options, payload) {
|
|
|
276
277
|
context.codebaseDeployEvents[codebase].runtime = wantBuild.runtime;
|
|
277
278
|
}
|
|
278
279
|
validate.endpointsAreUnique(wantBackends);
|
|
280
|
+
validate.noGenerationDowngrades(wantBackends, existingBackend);
|
|
279
281
|
context.sources = {};
|
|
280
282
|
for (const [codebase, wantBackend] of Object.entries(wantBackends)) {
|
|
281
283
|
const cfg = (0, projectConfig_1.configForCodebase)(context.config, codebase);
|
|
@@ -352,7 +354,7 @@ async function prepare(context, options, payload) {
|
|
|
352
354
|
validate.checkFiltersIntegrity(wantBackends, context.filters);
|
|
353
355
|
(0, applyHash_1.applyBackendHashToBackends)(wantBackends, context);
|
|
354
356
|
}
|
|
355
|
-
async function resolveDefaultRegionsForBuild(buildObj, have) {
|
|
357
|
+
async function resolveDefaultRegionsForBuild(buildObj, have, paramValues = {}) {
|
|
356
358
|
for (const [id, endpoint] of Object.entries(buildObj.endpoints)) {
|
|
357
359
|
if (!endpoint.region?.length || endpoint.region.includes(build.REGION_TBD)) {
|
|
358
360
|
let resolvedRegion = services_1.FALLBACK_DEPLOYMENT_REGION;
|
|
@@ -370,7 +372,7 @@ async function resolveDefaultRegionsForBuild(buildObj, have) {
|
|
|
370
372
|
}
|
|
371
373
|
else {
|
|
372
374
|
try {
|
|
373
|
-
resolvedRegion = await resolveRegionForTrigger(endpoint);
|
|
375
|
+
resolvedRegion = await resolveRegionForTrigger(endpoint, paramValues);
|
|
374
376
|
}
|
|
375
377
|
catch (err) {
|
|
376
378
|
logger_1.logger.debug(`Failed to resolve region for endpoint ${id}. Defaulting to ${services_1.FALLBACK_DEPLOYMENT_REGION}.`, (0, error_1.getErrStack)(err));
|
|
@@ -380,9 +382,24 @@ async function resolveDefaultRegionsForBuild(buildObj, have) {
|
|
|
380
382
|
}
|
|
381
383
|
}
|
|
382
384
|
}
|
|
383
|
-
async function resolveRegionForTrigger(endpoint) {
|
|
384
|
-
|
|
385
|
-
|
|
385
|
+
async function resolveRegionForTrigger(endpoint, paramValues = {}) {
|
|
386
|
+
let targetEndpoint = endpoint;
|
|
387
|
+
if (Object.keys(paramValues).length > 0 && build.isEventTriggered(endpoint)) {
|
|
388
|
+
targetEndpoint = {
|
|
389
|
+
...endpoint,
|
|
390
|
+
eventTrigger: {
|
|
391
|
+
...endpoint.eventTrigger,
|
|
392
|
+
...(endpoint.eventTrigger.eventFilters && {
|
|
393
|
+
eventFilters: (0, functional_1.mapObject)(endpoint.eventTrigger.eventFilters, (v) => params.resolveString(v, paramValues)),
|
|
394
|
+
}),
|
|
395
|
+
...(endpoint.eventTrigger.eventFilterPathPatterns && {
|
|
396
|
+
eventFilterPathPatterns: (0, functional_1.mapObject)(endpoint.eventTrigger.eventFilterPathPatterns, (v) => params.resolveString(v, paramValues)),
|
|
397
|
+
}),
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
const service = (0, services_1.serviceForEndpoint)(targetEndpoint);
|
|
402
|
+
return await service.getDefaultRegion(targetEndpoint);
|
|
386
403
|
}
|
|
387
404
|
function inferDetailsFromExisting(want, have, usedDotenv) {
|
|
388
405
|
for (const wantE of backend.allEndpoints(want)) {
|
|
@@ -22,9 +22,10 @@ const isServiceUnavailable = (err) => parseErrorCode(err) === 503;
|
|
|
22
22
|
exports.isServiceUnavailable = isServiceUnavailable;
|
|
23
23
|
const isTransientError = (err) => (0, exports.isQuotaExhaustion)(err) || (0, exports.isConflict)(err) || (0, exports.isServiceUnavailable)(err);
|
|
24
24
|
exports.isTransientError = isTransientError;
|
|
25
|
+
const MANAGED_SERVICE_ACCOUNT_REGEX = /\bfirebase-fn-[0-9]+@/i;
|
|
25
26
|
const isServiceAccountPropagationError = (err) => {
|
|
26
27
|
const code = parseErrorCode(err);
|
|
27
|
-
if (code !== 404 && code !== 400) {
|
|
28
|
+
if (code !== 404 && code !== 400 && code !== 403) {
|
|
28
29
|
return false;
|
|
29
30
|
}
|
|
30
31
|
let message = "";
|
|
@@ -44,13 +45,16 @@ const isServiceAccountPropagationError = (err) => {
|
|
|
44
45
|
message = String(err).toLowerCase();
|
|
45
46
|
}
|
|
46
47
|
const hasSa = message.includes("serviceaccount") || message.includes("service account");
|
|
47
|
-
if (!hasSa) {
|
|
48
|
+
if (!hasSa || !MANAGED_SERVICE_ACCOUNT_REGEX.test(message)) {
|
|
48
49
|
return false;
|
|
49
50
|
}
|
|
50
51
|
if (code === 404) {
|
|
51
52
|
return true;
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
if (code === 400) {
|
|
55
|
+
return message.includes("invalid service account");
|
|
56
|
+
}
|
|
57
|
+
return message.includes("or it may not exist");
|
|
54
58
|
};
|
|
55
59
|
exports.isServiceAccountPropagationError = isServiceAccountPropagationError;
|
|
56
60
|
const isCloudRunResourceExhausted = (err) => parseErrorCode(err) === 8;
|
|
@@ -173,14 +173,26 @@ class Fabricator {
|
|
|
173
173
|
return this.applyUpserts(changes, scraperV1, scraperV2);
|
|
174
174
|
});
|
|
175
175
|
const createAndUpdateResultsArray = await Promise.allSettled(createAndUpdatePromises);
|
|
176
|
+
const upsertErrors = [];
|
|
176
177
|
summary.results = createAndUpdateResultsArray.reduce((acc, r) => {
|
|
177
178
|
if (r.status === "fulfilled") {
|
|
178
179
|
return [...acc, ...r.value];
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
+
upsertErrors.push((0, error_1.getError)(r.reason));
|
|
182
|
+
logger_1.logger.debug("Fabricator.applyUpserts returned an unhandled exception.", (0, error_1.getErrStack)(r.reason));
|
|
181
183
|
return acc;
|
|
182
184
|
}, []);
|
|
183
185
|
await this.cleanupUnusedServiceAccounts(plan, summary.results);
|
|
186
|
+
if (upsertErrors.length) {
|
|
187
|
+
const opts = upsertErrors.length === 1 ? { original: upsertErrors[0] } : { children: upsertErrors };
|
|
188
|
+
const msg = upsertErrors.length === 1
|
|
189
|
+
? `Fabricator.applyUpserts encountered an unhandled exception: ${upsertErrors[0].message}`
|
|
190
|
+
: "Fabricator.applyUpserts encountered unhandled exceptions";
|
|
191
|
+
throw new error_1.FirebaseError(msg, {
|
|
192
|
+
...opts,
|
|
193
|
+
exit: 2,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
184
196
|
const hasFailures = summary.results.some((r) => r.error);
|
|
185
197
|
if (hasFailures) {
|
|
186
198
|
utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes.");
|
|
@@ -196,14 +208,26 @@ class Fabricator {
|
|
|
196
208
|
return summary;
|
|
197
209
|
}
|
|
198
210
|
const deleteResultsArray = await Promise.allSettled(allChangesets.map((changes) => this.applyDeletes(changes)));
|
|
211
|
+
const deleteErrors = [];
|
|
199
212
|
const deleteResults = deleteResultsArray.reduce((acc, r) => {
|
|
200
213
|
if (r.status === "fulfilled") {
|
|
201
214
|
return [...acc, ...r.value];
|
|
202
215
|
}
|
|
203
|
-
|
|
216
|
+
deleteErrors.push((0, error_1.getError)(r.reason));
|
|
217
|
+
logger_1.logger.debug("Fabricator.applyDeletes returned an unhandled exception. This should never happen", (0, error_1.getErrStack)(r.reason));
|
|
204
218
|
return acc;
|
|
205
219
|
}, []);
|
|
206
220
|
summary.results.push(...deleteResults);
|
|
221
|
+
if (deleteErrors.length) {
|
|
222
|
+
const opts = deleteErrors.length === 1 ? { original: deleteErrors[0] } : { children: deleteErrors };
|
|
223
|
+
const msg = deleteErrors.length === 1
|
|
224
|
+
? `Fabricator.applyDeletes encountered an unhandled exception: ${deleteErrors[0].message}`
|
|
225
|
+
: "Fabricator.applyDeletes encountered unhandled exceptions";
|
|
226
|
+
throw new error_1.FirebaseError(msg, {
|
|
227
|
+
...opts,
|
|
228
|
+
exit: 2,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
207
231
|
for (const [codebase, codebasePlan] of Object.entries(plan)) {
|
|
208
232
|
await this.removeOldRoles(codebasePlan, codebase);
|
|
209
233
|
}
|
|
@@ -231,23 +255,29 @@ class Fabricator {
|
|
|
231
255
|
async applyUpserts(changes, scraperV1, scraperV2) {
|
|
232
256
|
const ops = [];
|
|
233
257
|
for (const endpoint of changes.endpointsToCreate) {
|
|
234
|
-
this.
|
|
235
|
-
|
|
258
|
+
ops.push(this.wrapOperation("create", endpoint, () => {
|
|
259
|
+
this.logOpStart("creating", endpoint);
|
|
260
|
+
return this.createEndpoint(endpoint, scraperV1, scraperV2);
|
|
261
|
+
}));
|
|
236
262
|
}
|
|
237
263
|
for (const endpoint of changes.endpointsToSkip) {
|
|
238
264
|
utils.logSuccess(this.getLogSuccessMessage("skip", endpoint));
|
|
239
265
|
}
|
|
240
266
|
for (const update of changes.endpointsToUpdate) {
|
|
241
|
-
this.
|
|
242
|
-
|
|
267
|
+
ops.push(this.wrapOperation("update", update.endpoint, () => {
|
|
268
|
+
this.logOpStart("updating", update.endpoint);
|
|
269
|
+
return this.updateEndpoint(update, scraperV1, scraperV2);
|
|
270
|
+
}));
|
|
243
271
|
}
|
|
244
272
|
return Promise.all(ops);
|
|
245
273
|
}
|
|
246
274
|
async applyDeletes(changes) {
|
|
247
275
|
const ops = [];
|
|
248
276
|
for (const endpoint of changes.endpointsToDelete) {
|
|
249
|
-
this.
|
|
250
|
-
|
|
277
|
+
ops.push(this.wrapOperation("delete", endpoint, () => {
|
|
278
|
+
this.logOpStart("deleting", endpoint);
|
|
279
|
+
return this.deleteEndpoint(endpoint);
|
|
280
|
+
}));
|
|
251
281
|
}
|
|
252
282
|
return Promise.all(ops);
|
|
253
283
|
}
|
|
@@ -871,12 +901,8 @@ class Fabricator {
|
|
|
871
901
|
.catch(rethrowAsUnlessNotFound(endpoint, "delete schedule"));
|
|
872
902
|
}
|
|
873
903
|
async disableTaskQueue(endpoint) {
|
|
874
|
-
const update = {
|
|
875
|
-
name: cloudtasks.queueNameForEndpoint(endpoint),
|
|
876
|
-
state: "DISABLED",
|
|
877
|
-
};
|
|
878
904
|
await this.executor
|
|
879
|
-
.run(() => cloudtasks.
|
|
905
|
+
.run(() => cloudtasks.disableQueue(cloudtasks.queueNameForEndpoint(endpoint)))
|
|
880
906
|
.catch(rethrowAs(endpoint, "disable task queue"));
|
|
881
907
|
}
|
|
882
908
|
async unregisterBlockingTrigger(endpoint) {
|
|
@@ -885,7 +911,9 @@ class Fabricator {
|
|
|
885
911
|
.catch(rethrowAs(endpoint, "unregister blocking trigger"));
|
|
886
912
|
}
|
|
887
913
|
logOpStart(op, endpoint) {
|
|
888
|
-
const runtime = endpoint.runtime
|
|
914
|
+
const runtime = endpoint.runtime
|
|
915
|
+
? supported_1.RUNTIMES[endpoint.runtime]?.friendly ?? endpoint.runtime
|
|
916
|
+
: "unknown";
|
|
889
917
|
const platform = (0, functionsDeployHelper_1.getHumanFriendlyPlatformName)(endpoint.platform);
|
|
890
918
|
const label = helper.getFunctionLabel(endpoint);
|
|
891
919
|
utils.logLabeledBullet("functions", `${op} ${runtime} (${platform}) function ${clc.bold(label)}...`);
|
|
@@ -250,8 +250,9 @@ function checkForIllegalUpdate(want, have) {
|
|
|
250
250
|
if (wantType !== haveType && !upgradingHttpsFunction) {
|
|
251
251
|
throw new error_1.FirebaseError(`[${(0, functionsDeployHelper_1.getFunctionLabel)(want)}] Changing from ${haveType} function to ${wantType} function is not allowed. Please delete your function and create a new one instead.`);
|
|
252
252
|
}
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
const downgrade = (0, functionsDeployHelper_1.generationDowngradeMessage)(want, have);
|
|
254
|
+
if (downgrade) {
|
|
255
|
+
throw new error_1.FirebaseError(downgrade);
|
|
255
256
|
}
|
|
256
257
|
exports.checkForV2Upgrade(want, have);
|
|
257
258
|
}
|
|
@@ -41,12 +41,12 @@ class SourceTokenScraper {
|
|
|
41
41
|
return tokenResult.token;
|
|
42
42
|
}
|
|
43
43
|
else if (this.fetchState === "VALID") {
|
|
44
|
-
const tokenResult = await this.promise;
|
|
45
44
|
if (this.isTokenExpired()) {
|
|
46
45
|
this.fetchState = "FETCHING";
|
|
47
46
|
this.promise = new Promise((resolve) => (this.resolve = resolve));
|
|
48
47
|
return undefined;
|
|
49
48
|
}
|
|
49
|
+
const tokenResult = await this.promise;
|
|
50
50
|
return tokenResult.token;
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MAX_V2_SCHEDULE_ATTEMPT_DEADLINE_SECONDS = exports.DEFAULT_V2_SCHEDULE_ATTEMPT_DEADLINE_SECONDS = void 0;
|
|
4
4
|
exports.endpointsAreValid = endpointsAreValid;
|
|
5
|
+
exports.noGenerationDowngrades = noGenerationDowngrades;
|
|
5
6
|
exports.cpuConfigIsValid = cpuConfigIsValid;
|
|
6
7
|
exports.validateTimeoutConfig = validateTimeoutConfig;
|
|
7
8
|
exports.endpointsAreUnique = endpointsAreUnique;
|
|
@@ -85,6 +86,21 @@ function endpointsAreValid(wantBackend, existingBackend) {
|
|
|
85
86
|
}
|
|
86
87
|
cpuConfigIsValid(endpoints);
|
|
87
88
|
}
|
|
89
|
+
function noGenerationDowngrades(wantBackends, existingBackend) {
|
|
90
|
+
const msgs = [];
|
|
91
|
+
for (const wantBackend of Object.values(wantBackends)) {
|
|
92
|
+
for (const want of backend.allEndpoints(wantBackend).sort(backend.compareFunctions)) {
|
|
93
|
+
const have = existingBackend.endpoints[want.region]?.[want.id];
|
|
94
|
+
const msg = have && (0, functionsDeployHelper_1.generationDowngradeMessage)(want, have);
|
|
95
|
+
if (msg) {
|
|
96
|
+
msgs.push(msg);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (msgs.length) {
|
|
101
|
+
throw new error_1.FirebaseError(msgs.join("\n"));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
88
104
|
function cpuConfigIsValid(endpoints) {
|
|
89
105
|
const gcfV1WithCPU = matchingIds(endpoints, (endpoint) => endpoint.platform === "gcfv1" && typeof endpoint["cpu"] !== "undefined");
|
|
90
106
|
if (gcfV1WithCPU.length) {
|
|
@@ -105,7 +105,7 @@ async function prepare(context, options) {
|
|
|
105
105
|
(0, track_1.trackGA4)("hosting_version", {
|
|
106
106
|
framework: config.webFramework || "classic",
|
|
107
107
|
}),
|
|
108
|
-
api.createVersion(config.site, version),
|
|
108
|
+
api.createVersion(context.projectId, config.site, version),
|
|
109
109
|
]);
|
|
110
110
|
return versionName;
|
|
111
111
|
}));
|
|
@@ -21,7 +21,7 @@ async function release(context, options, functionsPayload) {
|
|
|
21
21
|
config: await (0, convertConfig_1.convertConfig)(context, functionsPayload, deploy),
|
|
22
22
|
};
|
|
23
23
|
const versionId = utils.last(deploy.version.split("/"));
|
|
24
|
-
const finalizedVersion = await api.updateVersion(deploy.config.site, versionId, update);
|
|
24
|
+
const finalizedVersion = await api.updateVersion(context.projectId, deploy.config.site, versionId, update);
|
|
25
25
|
logger_1.logger.debug(`[hosting] finalized version for ${deploy.config.site}:${finalizedVersion}`);
|
|
26
26
|
utils.logLabeledSuccess(`hosting[${deploy.config.site}]`, "version finalized");
|
|
27
27
|
utils.logLabeledBullet(`hosting[${deploy.config.site}]`, "releasing new version...");
|
|
@@ -32,7 +32,7 @@ async function release(context, options, functionsPayload) {
|
|
|
32
32
|
if (options.message) {
|
|
33
33
|
otherReleaseOpts.message = options.message;
|
|
34
34
|
}
|
|
35
|
-
const release = await api.createRelease(deploy.config.site, context.hostingChannel || "live", deploy.version, otherReleaseOpts);
|
|
35
|
+
const release = await api.createRelease(context.projectId, deploy.config.site, context.hostingChannel || "live", deploy.version, otherReleaseOpts);
|
|
36
36
|
logger_1.logger.debug("[hosting] release:", release);
|
|
37
37
|
utils.logLabeledSuccess(`hosting[${deploy.config.site}]`, "release complete");
|
|
38
38
|
}));
|
package/lib/deploy/index.js
CHANGED
|
@@ -23,6 +23,8 @@ const DataConnectTarget = require("./dataconnect");
|
|
|
23
23
|
const AppHostingTarget = require("./apphosting");
|
|
24
24
|
const AuthTarget = require("./auth");
|
|
25
25
|
const AiLogicTarget = require("./ailogic");
|
|
26
|
+
const RunTarget = require("./run");
|
|
27
|
+
const prereqs_1 = require("./run/prereqs");
|
|
26
28
|
const frameworks_1 = require("../frameworks");
|
|
27
29
|
const prepare_1 = require("./hosting/prepare");
|
|
28
30
|
const requirePermissions_1 = require("../requirePermissions");
|
|
@@ -39,6 +41,7 @@ exports.VALID_DEPLOY_TARGETS = [
|
|
|
39
41
|
"apphosting",
|
|
40
42
|
"auth",
|
|
41
43
|
"ailogic",
|
|
44
|
+
"run",
|
|
42
45
|
];
|
|
43
46
|
exports.TARGET_PERMISSIONS = {
|
|
44
47
|
database: ["firebasedatabase.instances.update"],
|
|
@@ -95,6 +98,7 @@ exports.TARGET_PERMISSIONS = {
|
|
|
95
98
|
"firebasevertexai.templates.delete",
|
|
96
99
|
"serviceusage.services.get",
|
|
97
100
|
],
|
|
101
|
+
run: prereqs_1.RUN_PERMISSIONS,
|
|
98
102
|
};
|
|
99
103
|
exports.TARGETS = {
|
|
100
104
|
hosting: HostingTarget,
|
|
@@ -108,6 +112,7 @@ exports.TARGETS = {
|
|
|
108
112
|
apphosting: AppHostingTarget,
|
|
109
113
|
auth: AuthTarget,
|
|
110
114
|
ailogic: AiLogicTarget,
|
|
115
|
+
run: RunTarget,
|
|
111
116
|
};
|
|
112
117
|
const chain = async function (fns, context, options, payload) {
|
|
113
118
|
for (const latest of fns) {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BUILD_ENV_ANNOTATION = void 0;
|
|
4
|
+
exports.getBuildEnv = getBuildEnv;
|
|
5
|
+
exports.secretNames = secretNames;
|
|
6
|
+
exports.nonSecretValues = nonSecretValues;
|
|
7
|
+
exports.toLocalBuildEnv = toLocalBuildEnv;
|
|
8
|
+
const error_1 = require("../../error");
|
|
9
|
+
exports.BUILD_ENV_ANNOTATION = "firebase.google.com/buildConfig.environmentVariablesAndSecrets";
|
|
10
|
+
function getBuildEnv(service) {
|
|
11
|
+
const raw = service?.annotations?.[exports.BUILD_ENV_ANNOTATION];
|
|
12
|
+
if (!service || !raw) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const invalid = (reason) => new error_1.FirebaseError(`Invalid ${exports.BUILD_ENV_ANNOTATION} annotation on ${service.name}: ${reason}`);
|
|
16
|
+
let parsed;
|
|
17
|
+
try {
|
|
18
|
+
parsed = JSON.parse(raw);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw invalid("it isn't valid JSON.");
|
|
22
|
+
}
|
|
23
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
24
|
+
throw invalid("it must be a JSON object.");
|
|
25
|
+
}
|
|
26
|
+
const env = {};
|
|
27
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
28
|
+
if (typeof value === "string" || isSecretRef(value)) {
|
|
29
|
+
env[name] = value;
|
|
30
|
+
}
|
|
31
|
+
else if (typeof value === "number" || typeof value === "boolean") {
|
|
32
|
+
env[name] = String(value);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw invalid(`${name} must be a string, number, boolean, or {"secret": "<secret name>"}.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return env;
|
|
39
|
+
}
|
|
40
|
+
function isSecretRef(value) {
|
|
41
|
+
const ref = value;
|
|
42
|
+
return (typeof ref === "object" &&
|
|
43
|
+
ref !== null &&
|
|
44
|
+
Object.keys(ref).length === 1 &&
|
|
45
|
+
typeof ref.secret === "string");
|
|
46
|
+
}
|
|
47
|
+
function secretNames(env) {
|
|
48
|
+
return Object.entries(env)
|
|
49
|
+
.filter(([, value]) => isSecretRef(value))
|
|
50
|
+
.map(([name]) => name);
|
|
51
|
+
}
|
|
52
|
+
function nonSecretValues(env) {
|
|
53
|
+
const values = {};
|
|
54
|
+
for (const [name, value] of Object.entries(env)) {
|
|
55
|
+
if (!isSecretRef(value)) {
|
|
56
|
+
values[name] = value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return values;
|
|
60
|
+
}
|
|
61
|
+
function toLocalBuildEnv(env) {
|
|
62
|
+
const result = {};
|
|
63
|
+
for (const [name, value] of Object.entries(env)) {
|
|
64
|
+
if (isSecretRef(value)) {
|
|
65
|
+
result[name] = { secret: value.secret, availability: ["BUILD"] };
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
result[name] = { value, availability: ["BUILD"] };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|