firebase-tools 15.25.0 → 15.26.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/lib/ailogic/templates.js +124 -0
- package/lib/api.js +6 -2
- package/lib/appcheck/api.js +33 -0
- package/lib/appcheck/prompts.js +2 -2
- package/lib/appcheck/services.js +135 -0
- package/lib/auth.js +33 -15
- package/lib/checkValidTargetFilters.js +1 -0
- package/lib/command.js +4 -1
- package/lib/commands/ailogic-templates-delete.js +53 -0
- package/lib/commands/ailogic-templates-get.js +33 -0
- package/lib/commands/ailogic-templates-list.js +49 -0
- package/lib/commands/ailogic-templates-lock.js +30 -0
- package/lib/commands/ailogic-templates-unlock.js +30 -0
- package/lib/commands/appcheck-debugtokens-delete.js +1 -1
- package/lib/commands/appcheck-debugtokens-list.js +1 -1
- package/lib/commands/appcheck-services-get.js +40 -0
- package/lib/commands/appcheck-services-list.js +52 -0
- package/lib/commands/appcheck-services-set.js +90 -0
- package/lib/commands/crashlytics-onboard-web.js +56 -0
- package/lib/commands/deploy.js +3 -0
- package/lib/commands/firestore-locations.js +3 -1
- package/lib/commands/index.js +14 -0
- package/lib/commands/login.js +53 -6
- package/lib/config.js +1 -0
- package/lib/crashlytics/firebasetelemetry.js +36 -0
- package/lib/crashlytics/onboarding.js +41 -0
- package/lib/crashlytics/sourcemap.js +102 -12
- package/lib/deploy/ailogic/index.js +19 -0
- package/lib/deploy/ailogic/prepare.js +78 -0
- package/lib/deploy/ailogic/release.js +60 -0
- package/lib/deploy/functions/build.js +1 -1
- package/lib/deploy/functions/functionsDeployHelper.js +18 -12
- package/lib/deploy/functions/prepare.js +16 -3
- package/lib/deploy/functions/release/executor.js +51 -8
- package/lib/deploy/functions/release/fabricator.js +34 -5
- package/lib/deploy/index.js +9 -0
- package/lib/emulator/controller.js +34 -15
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/experiments.js +13 -0
- package/lib/extensions/checkProjectBilling.js +3 -73
- package/lib/functions/projectConfig.js +98 -12
- package/lib/gcp/ailogic.js +70 -1
- package/lib/gcp/cloudbilling.js +74 -0
- package/lib/gcp/cloudlogging.js +54 -0
- package/lib/management/apps.js +1 -2
- package/lib/prompt.js +10 -1
- package/lib/requirePermissions.js +1 -1
- package/lib/serve/functions.js +25 -7
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/schema/firebase-config.json +132 -0
|
@@ -7,6 +7,8 @@ exports.getGitCommit = getGitCommit;
|
|
|
7
7
|
exports.getPackageVersion = getPackageVersion;
|
|
8
8
|
exports.upsertBucket = upsertBucket;
|
|
9
9
|
exports.findSourceMapMappings = findSourceMapMappings;
|
|
10
|
+
exports.extractSourceMapFileField = extractSourceMapFileField;
|
|
11
|
+
exports.findHiddenSourceMapTarget = findHiddenSourceMapTarget;
|
|
10
12
|
exports.getLinkedSourceMapPath = getLinkedSourceMapPath;
|
|
11
13
|
exports.uploadSourceMaps = uploadSourceMaps;
|
|
12
14
|
exports.uploadMap = uploadMap;
|
|
@@ -101,32 +103,120 @@ async function findSourceMapMappings(files, rootDir) {
|
|
|
101
103
|
const jsFiles = files.filter((f) => f.name.endsWith(".js"));
|
|
102
104
|
const mapFiles = files.filter((f) => f.name.endsWith(".js.map"));
|
|
103
105
|
const mappings = [];
|
|
104
|
-
const mapFilePathsSet = new Set(mapFiles.map((f) => f.name));
|
|
105
|
-
const
|
|
106
|
+
const mapFilePathsSet = new Set(mapFiles.map((f) => path.resolve(f.name)));
|
|
107
|
+
const jsFilesSet = new Set(jsFiles.map((f) => path.resolve(f.name)));
|
|
108
|
+
const linkedMapFilePaths = new Set();
|
|
109
|
+
const linkedJsFilePaths = new Set();
|
|
106
110
|
const limit = (0, utils_1.pLimit)(exports.CONCURRENCY);
|
|
107
|
-
const
|
|
111
|
+
const traditionalResults = await Promise.all(jsFiles.map((jsFile) => limit(async () => {
|
|
108
112
|
const mapFilePath = await getLinkedSourceMapPath(jsFile.name);
|
|
109
113
|
return { jsFile, mapFilePath };
|
|
110
114
|
})));
|
|
111
|
-
for (const { jsFile, mapFilePath } of
|
|
112
|
-
if (mapFilePath
|
|
115
|
+
for (const { jsFile, mapFilePath } of traditionalResults) {
|
|
116
|
+
if (mapFilePath) {
|
|
117
|
+
const resolvedMapPath = path.resolve(mapFilePath);
|
|
118
|
+
const resolvedJsPath = path.resolve(jsFile.name);
|
|
119
|
+
if (mapFilePathsSet.has(resolvedMapPath) && !linkedMapFilePaths.has(resolvedMapPath)) {
|
|
120
|
+
mappings.push({
|
|
121
|
+
mapFilePath,
|
|
122
|
+
obfuscatedFilePath: path.relative(rootDir, resolvedJsPath),
|
|
123
|
+
});
|
|
124
|
+
linkedMapFilePaths.add(resolvedMapPath);
|
|
125
|
+
linkedJsFilePaths.add(resolvedJsPath);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const unlinkedMapFiles = mapFiles.filter((f) => !linkedMapFilePaths.has(path.resolve(f.name)));
|
|
130
|
+
const availableJsFilesSet = new Set([...jsFilesSet].filter((jsPath) => !linkedJsFilePaths.has(jsPath)));
|
|
131
|
+
const hiddenResults = await Promise.all(unlinkedMapFiles.map((mapFile) => limit(async () => {
|
|
132
|
+
const resolvedMapPath = path.resolve(mapFile.name);
|
|
133
|
+
const targetJsPath = await findHiddenSourceMapTarget(mapFile.name, availableJsFilesSet);
|
|
134
|
+
return { mapFile, targetJsPath, resolvedMapPath };
|
|
135
|
+
})));
|
|
136
|
+
for (const { mapFile, targetJsPath, resolvedMapPath } of hiddenResults) {
|
|
137
|
+
if (targetJsPath && !linkedJsFilePaths.has(path.resolve(targetJsPath))) {
|
|
138
|
+
const resolvedJsPath = path.resolve(targetJsPath);
|
|
113
139
|
mappings.push({
|
|
114
|
-
mapFilePath,
|
|
115
|
-
obfuscatedFilePath: path.relative(rootDir,
|
|
140
|
+
mapFilePath: mapFile.name,
|
|
141
|
+
obfuscatedFilePath: path.relative(rootDir, resolvedJsPath),
|
|
116
142
|
});
|
|
117
|
-
|
|
143
|
+
linkedMapFilePaths.add(resolvedMapPath);
|
|
144
|
+
linkedJsFilePaths.add(resolvedJsPath);
|
|
118
145
|
}
|
|
119
|
-
|
|
120
|
-
for (const mapFile of mapFiles) {
|
|
121
|
-
if (!mapFilesLinkedInJsComment.has(mapFile.name)) {
|
|
146
|
+
else if (!linkedMapFilePaths.has(resolvedMapPath)) {
|
|
122
147
|
mappings.push({
|
|
123
148
|
mapFilePath: mapFile.name,
|
|
124
|
-
obfuscatedFilePath: path.relative(rootDir,
|
|
149
|
+
obfuscatedFilePath: path.relative(rootDir, resolvedMapPath),
|
|
125
150
|
});
|
|
151
|
+
linkedMapFilePaths.add(resolvedMapPath);
|
|
126
152
|
}
|
|
127
153
|
}
|
|
128
154
|
return mappings;
|
|
129
155
|
}
|
|
156
|
+
async function extractSourceMapFileField(mapFilePath) {
|
|
157
|
+
let fileHandle;
|
|
158
|
+
try {
|
|
159
|
+
const stat = await fs.promises.stat(mapFilePath);
|
|
160
|
+
const size = stat.size;
|
|
161
|
+
if (size === 0) {
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
const bufferSize = Math.min(size, 16384);
|
|
165
|
+
fileHandle = await fs.promises.open(mapFilePath, "r");
|
|
166
|
+
const buffer = Buffer.alloc(bufferSize);
|
|
167
|
+
const { bytesRead } = await fileHandle.read(buffer, 0, bufferSize, 0);
|
|
168
|
+
const header = buffer.toString("utf-8", 0, bytesRead);
|
|
169
|
+
const regex = /"file"\s*:\s*"(?<file>(?:[^"\\]|\\.)*)"/;
|
|
170
|
+
const match = regex.exec(header);
|
|
171
|
+
const file = match?.groups?.file;
|
|
172
|
+
if (file) {
|
|
173
|
+
try {
|
|
174
|
+
const decoded = JSON.parse(`"${file}"`);
|
|
175
|
+
const trimmed = decoded.trim();
|
|
176
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
const trimmed = file.trim();
|
|
180
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
catch (e) {
|
|
185
|
+
logger_1.logger.debug(`Error reading source map file property from ${mapFilePath}: ${e instanceof Error ? e.message : String(e)}`);
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
if (fileHandle) {
|
|
189
|
+
try {
|
|
190
|
+
await fileHandle.close();
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
async function findHiddenSourceMapTarget(mapFilePath, jsFilesSet) {
|
|
199
|
+
const resolvedMapPath = path.resolve(mapFilePath);
|
|
200
|
+
const mapDir = path.dirname(resolvedMapPath);
|
|
201
|
+
if (resolvedMapPath.endsWith(".map")) {
|
|
202
|
+
const candidateJsPath = resolvedMapPath.slice(0, -4);
|
|
203
|
+
if (jsFilesSet ? jsFilesSet.has(candidateJsPath) : fs.existsSync(candidateJsPath)) {
|
|
204
|
+
return candidateJsPath;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const fileField = await extractSourceMapFileField(resolvedMapPath);
|
|
208
|
+
if (fileField) {
|
|
209
|
+
const candidateJsPath = path.resolve(mapDir, fileField);
|
|
210
|
+
if (jsFilesSet ? jsFilesSet.has(candidateJsPath) : fs.existsSync(candidateJsPath)) {
|
|
211
|
+
return candidateJsPath;
|
|
212
|
+
}
|
|
213
|
+
const baseCandidate = path.resolve(mapDir, path.basename(fileField));
|
|
214
|
+
if (jsFilesSet ? jsFilesSet.has(baseCandidate) : fs.existsSync(baseCandidate)) {
|
|
215
|
+
return baseCandidate;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
130
220
|
async function getLinkedSourceMapPath(jsFilePath) {
|
|
131
221
|
let fileHandle;
|
|
132
222
|
try {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detailedHelp = exports.help = exports.release = exports.prepare = void 0;
|
|
4
|
+
exports.deploy = deploy;
|
|
5
|
+
const prepare_1 = require("./prepare");
|
|
6
|
+
Object.defineProperty(exports, "prepare", { enumerable: true, get: function () { return prepare_1.prepare; } });
|
|
7
|
+
const release_1 = require("./release");
|
|
8
|
+
Object.defineProperty(exports, "release", { enumerable: true, get: function () { return release_1.release; } });
|
|
9
|
+
async function deploy() { }
|
|
10
|
+
exports.help = "Deploys AI Logic server prompt templates defined in your project's firebase.json.";
|
|
11
|
+
exports.detailedHelp = "AI Logic deploys the .prompt files in your prompts directory as server prompt templates: " +
|
|
12
|
+
"new files are created, changed files are updated, unchanged files are skipped, and " +
|
|
13
|
+
"templates whose files were removed are deleted after confirmation.\n\n" +
|
|
14
|
+
"Configuration format in firebase.json:\n" +
|
|
15
|
+
"{\n" +
|
|
16
|
+
' "ailogic": {\n' +
|
|
17
|
+
' "templates": "prompts"\n' +
|
|
18
|
+
" }\n" +
|
|
19
|
+
"}";
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepare = prepare;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const utils = require("../../utils");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const prompt_1 = require("../../prompt");
|
|
8
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
9
|
+
const fsutils_1 = require("../../fsutils");
|
|
10
|
+
const ailogic = require("../../gcp/ailogic");
|
|
11
|
+
const templates = require("../../ailogic/templates");
|
|
12
|
+
const VALID_FILTERS = ["templates"];
|
|
13
|
+
function filterIncludes(options, subTarget) {
|
|
14
|
+
if (!options.only) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
const filters = options.only
|
|
18
|
+
.split(",")
|
|
19
|
+
.filter((t) => t === "ailogic" || t.startsWith("ailogic:"))
|
|
20
|
+
.map((t) => t.split(":")[1]);
|
|
21
|
+
for (const f of filters) {
|
|
22
|
+
if (f && !VALID_FILTERS.includes(f)) {
|
|
23
|
+
throw new error_1.FirebaseError(`Unknown AI Logic deploy filter ${clc.bold(`ailogic:${f}`)}. Valid filters:\n\n` +
|
|
24
|
+
VALID_FILTERS.map((v) => ` ailogic:${v}`).join("\n"));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return filters.some((f) => f === undefined || f === subTarget);
|
|
28
|
+
}
|
|
29
|
+
async function prepare(context, options) {
|
|
30
|
+
if (!filterIncludes(options, "templates")) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
34
|
+
const templatesDir = options.config.src.ailogic?.templates ?? templates.DEFAULT_PROMPTS_DIR;
|
|
35
|
+
const dir = options.config.path(templatesDir);
|
|
36
|
+
if (!(0, fsutils_1.dirExistsSync)(dir)) {
|
|
37
|
+
throw new error_1.FirebaseError(`AI Logic templates directory ${clc.bold(templatesDir)} (from firebase.json) does not exist.`);
|
|
38
|
+
}
|
|
39
|
+
const local = templates.readPromptDirectory(dir);
|
|
40
|
+
if (local.errors.length > 0) {
|
|
41
|
+
throw new error_1.FirebaseError(["The following prompt files failed validation:"]
|
|
42
|
+
.concat(local.errors.map((e) => ` ${e.file}: ${e.error}`))
|
|
43
|
+
.join("\n"));
|
|
44
|
+
}
|
|
45
|
+
await ailogic.ensureAILogicApiEnabled(projectId, options);
|
|
46
|
+
const remote = await ailogic.listTemplates(projectId);
|
|
47
|
+
const prune = local.templates.size > 0;
|
|
48
|
+
if (!prune && remote.length > 0) {
|
|
49
|
+
utils.logLabeledWarning("ailogic", `no ${templates.PROMPT_FILE_EXT} files found in ${clc.bold(templatesDir)}; ` +
|
|
50
|
+
`existing remote templates were left untouched.`);
|
|
51
|
+
}
|
|
52
|
+
const plan = templates.planTemplateDeploy(local.templates, remote, prune);
|
|
53
|
+
if (plan.lockedViolations.length > 0) {
|
|
54
|
+
throw new error_1.FirebaseError(`The following templates are locked and cannot be updated or deleted:\n\n` +
|
|
55
|
+
plan.lockedViolations.map((id) => ` ${id}`).join("\n") +
|
|
56
|
+
`\n\nUnlock them by running:\n\n firebase ailogic:templates:unlock <templateId>\n\nThen deploy again. No templates were deployed.`);
|
|
57
|
+
}
|
|
58
|
+
if (plan.unchanged.length > 0) {
|
|
59
|
+
utils.logLabeledBullet("ailogic", `skipping ${plan.unchanged.length} unchanged template(s): ${plan.unchanged.join(", ")}`);
|
|
60
|
+
}
|
|
61
|
+
if (plan.deletes.length > 0) {
|
|
62
|
+
const confirmed = await (0, prompt_1.confirm)({
|
|
63
|
+
message: `This will delete the following remote templates whose ${templates.PROMPT_FILE_EXT} files were removed:\n\n` +
|
|
64
|
+
plan.deletes.map((id) => ` ${id}`).join("\n") +
|
|
65
|
+
`\n\nAre you sure you want to proceed?`,
|
|
66
|
+
force: options.force,
|
|
67
|
+
nonInteractive: options.nonInteractive,
|
|
68
|
+
});
|
|
69
|
+
if (!confirmed) {
|
|
70
|
+
throw new error_1.FirebaseError("Command aborted.", { exit: 1 });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
context.ailogic = {
|
|
74
|
+
templates: local.templates,
|
|
75
|
+
plan,
|
|
76
|
+
etags: new Map(remote.map((t) => [ailogic.templateIdFromName(t.name), t.etag])),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.release = release;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const utils = require("../../utils");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
8
|
+
const ailogic = require("../../gcp/ailogic");
|
|
9
|
+
async function release(context, options) {
|
|
10
|
+
if (!context.ailogic) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
14
|
+
const { templates, plan, etags } = context.ailogic;
|
|
15
|
+
for (const templateId of plan.creates) {
|
|
16
|
+
utils.logLabeledBullet("ailogic", `creating template ${clc.bold(templateId)}...`);
|
|
17
|
+
await ailogic.updateTemplate(projectId, templateId, {
|
|
18
|
+
templateString: templates.get(templateId) ?? "",
|
|
19
|
+
displayName: templateId,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
for (const templateId of plan.updates) {
|
|
23
|
+
utils.logLabeledBullet("ailogic", `updating template ${clc.bold(templateId)}...`);
|
|
24
|
+
const etag = etags.get(templateId);
|
|
25
|
+
try {
|
|
26
|
+
await ailogic.updateTemplate(projectId, templateId, {
|
|
27
|
+
templateString: templates.get(templateId) ?? "",
|
|
28
|
+
...(etag ? { etag } : {}),
|
|
29
|
+
}, ["templateString"]);
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
if ((0, error_1.getErrStatus)(err) === 409) {
|
|
33
|
+
throw new error_1.FirebaseError(`Template ${clc.bold(templateId)} was modified while deploying. Re-run the deploy to apply your local files against the latest remote state.`);
|
|
34
|
+
}
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const templateId of plan.deletes) {
|
|
39
|
+
utils.logLabeledBullet("ailogic", `deleting template ${clc.bold(templateId)}...`);
|
|
40
|
+
try {
|
|
41
|
+
await ailogic.deleteTemplate(projectId, templateId, etags.get(templateId));
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if ((0, error_1.getErrStatus)(err) === 404) {
|
|
45
|
+
utils.logLabeledBullet("ailogic", `template ${clc.bold(templateId)} was already deleted.`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if ((0, error_1.getErrStatus)(err) === 409) {
|
|
49
|
+
throw new error_1.FirebaseError(`Template ${clc.bold(templateId)} was modified while deploying, so it was not deleted. Re-run the deploy to plan against the latest remote state.`);
|
|
50
|
+
}
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (plan.creates.length === 0 && plan.updates.length === 0 && plan.deletes.length === 0) {
|
|
55
|
+
utils.logLabeledSuccess("ailogic", "all templates are already up to date.");
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
utils.logLabeledSuccess("ailogic", `templates deployed: ${plan.creates.length} created, ${plan.updates.length} updated, ${plan.deletes.length} deleted.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -82,7 +82,7 @@ exports.AllIngressSettings = [
|
|
|
82
82
|
"ALLOW_INTERNAL_AND_GCLB",
|
|
83
83
|
];
|
|
84
84
|
async function resolveBackend(opts) {
|
|
85
|
-
const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams(opts.build.params, opts.firebaseConfig, envWithTypes(opts.build.params, opts.userEnvs), opts.nonInteractive, opts.
|
|
85
|
+
const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams(opts.build.params, opts.firebaseConfig, envWithTypes(opts.build.params, opts.userEnvs), opts.nonInteractive, opts.force, opts.isEmulator);
|
|
86
86
|
return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
|
|
87
87
|
}
|
|
88
88
|
function envWithTypes(definedParams, rawEnvs) {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.endpointMatchesAnyFilter = endpointMatchesAnyFilter;
|
|
4
4
|
exports.endpointMatchesFilter = endpointMatchesFilter;
|
|
5
|
+
exports.getCodebasesFromConfig = getCodebasesFromConfig;
|
|
5
6
|
exports.parseFunctionSelector = parseFunctionSelector;
|
|
6
7
|
exports.getEndpointFilters = getEndpointFilters;
|
|
7
8
|
exports.getHumanFriendlyPlatformName = getHumanFriendlyPlatformName;
|
|
@@ -39,13 +40,24 @@ function endpointMatchesFilter(endpoint, filter) {
|
|
|
39
40
|
}
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
43
|
+
function getCodebasesFromConfig(config) {
|
|
44
|
+
return [
|
|
45
|
+
...new Set(config.flatMap((c) => ((0, projectConfig_1.isKitConfig)(c) ? Object.keys(c.instances) : [c.codebase]))),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
42
48
|
function parseFunctionSelector(selector, config) {
|
|
43
49
|
const fragments = selector.split(":");
|
|
50
|
+
const target = fragments[0];
|
|
51
|
+
const codebaseNames = getCodebasesFromConfig(config);
|
|
52
|
+
if (codebaseNames.includes(target)) {
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
codebase: target,
|
|
56
|
+
...(fragments.length > 1 ? { idChunks: fragments[1].split(/[-.]/) } : {}),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
44
60
|
if (fragments.length < 2) {
|
|
45
|
-
const codebaseNames = config.map((c) => c.codebase);
|
|
46
|
-
if (codebaseNames.includes(fragments[0])) {
|
|
47
|
-
return [{ codebase: fragments[0] }];
|
|
48
|
-
}
|
|
49
61
|
return [{ codebase: projectConfig_1.DEFAULT_CODEBASE, idChunks: fragments[0].split(/[-.]/) }];
|
|
50
62
|
}
|
|
51
63
|
return [
|
|
@@ -94,7 +106,7 @@ function getFunctionLabel(fn) {
|
|
|
94
106
|
return id;
|
|
95
107
|
}
|
|
96
108
|
function targetCodebases(config, filters) {
|
|
97
|
-
const codebasesFromConfig =
|
|
109
|
+
const codebasesFromConfig = getCodebasesFromConfig(config);
|
|
98
110
|
if (!filters) {
|
|
99
111
|
return [...codebasesFromConfig];
|
|
100
112
|
}
|
|
@@ -104,13 +116,7 @@ function targetCodebases(config, filters) {
|
|
|
104
116
|
if (codebasesFromFilters.length === 0) {
|
|
105
117
|
return [...codebasesFromConfig];
|
|
106
118
|
}
|
|
107
|
-
|
|
108
|
-
for (const codebase of codebasesFromConfig) {
|
|
109
|
-
if (codebasesFromFilters.includes(codebase)) {
|
|
110
|
-
intersections.push(codebase);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return intersections;
|
|
119
|
+
return codebasesFromConfig.filter((codebase) => codebasesFromFilters.includes(codebase));
|
|
114
120
|
}
|
|
115
121
|
function groupEndpointsByCodebase(wantBackends, haveEndpoints) {
|
|
116
122
|
const grouped = {};
|
|
@@ -161,7 +161,12 @@ async function prepare(context, options, payload) {
|
|
|
161
161
|
context.firebaseConfig = firebaseConfig;
|
|
162
162
|
context.codebaseDeployEvents = {};
|
|
163
163
|
let runtimeConfig = { firebase: firebaseConfig };
|
|
164
|
-
const targetedCodebaseConfigs = context.config.filter((cfg) =>
|
|
164
|
+
const targetedCodebaseConfigs = context.config.filter((cfg) => {
|
|
165
|
+
if ((0, projectConfig_1.isKitConfig)(cfg)) {
|
|
166
|
+
return cfg.instances && Object.keys(cfg.instances).some((inst) => codebases.includes(inst));
|
|
167
|
+
}
|
|
168
|
+
return cfg.codebase && codebases.includes(cfg.codebase);
|
|
169
|
+
});
|
|
165
170
|
if (checkAPIsEnabled[1] && targetedCodebaseConfigs.some(projectConfig_1.shouldUseRuntimeConfig)) {
|
|
166
171
|
runtimeConfig = { ...runtimeConfig, ...(await (0, prepareFunctionsUpload_1.getFunctionsConfig)(projectId)) };
|
|
167
172
|
}
|
|
@@ -186,7 +191,12 @@ async function prepare(context, options, payload) {
|
|
|
186
191
|
projectId: projectId,
|
|
187
192
|
projectAlias: options.projectAlias,
|
|
188
193
|
};
|
|
189
|
-
|
|
194
|
+
if ((0, projectConfig_1.isKitConfig)(localCfg) && codebase in localCfg.instances) {
|
|
195
|
+
userEnvOpt.configDir = options.config.path(localCfg.instances[codebase]);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
proto.convertIfPresent(userEnvOpt, localCfg, "configDir", (cd) => options.config.path(cd));
|
|
199
|
+
}
|
|
190
200
|
const rawUserEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
191
201
|
const { userEnvs: userEnvs, secretRefs: secretRefs } = partitionUserEnvs(rawUserEnvs);
|
|
192
202
|
const envs = { ...userEnvs, ...firebaseEnvs };
|
|
@@ -498,7 +508,10 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
498
508
|
GOOGLE_CLOUD_QUOTA_PROJECT: projectId,
|
|
499
509
|
});
|
|
500
510
|
discoveredBuild.runtime = codebaseConfig.runtime;
|
|
501
|
-
|
|
511
|
+
const prefix = (0, projectConfig_1.isKitConfig)(codebaseConfig)
|
|
512
|
+
? (0, projectConfig_1.addKitPrefix)(codebase)
|
|
513
|
+
: codebaseConfig.prefix || "";
|
|
514
|
+
build.applyPrefix(discoveredBuild, prefix);
|
|
502
515
|
wantBuilds[codebase] = discoveredBuild;
|
|
503
516
|
}
|
|
504
517
|
return wantBuilds;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InlineExecutor = exports.QueueExecutor = exports.
|
|
3
|
+
exports.InlineExecutor = exports.QueueExecutor = exports.isCloudRunResourceExhausted = exports.isServiceAccount404 = exports.isTransientError = exports.isServiceUnavailable = exports.isConflict = exports.isQuotaExhaustion = void 0;
|
|
4
|
+
exports.parseErrorCode = parseErrorCode;
|
|
5
|
+
exports.hasErrorCode = hasErrorCode;
|
|
4
6
|
const queue_1 = require("../../../throttler/queue");
|
|
5
|
-
exports.DEFAULT_RETRY_CODES = [429, 409, 503];
|
|
6
7
|
function parseErrorCode(err) {
|
|
7
8
|
return (err.status ||
|
|
8
9
|
err.code ||
|
|
@@ -10,29 +11,71 @@ function parseErrorCode(err) {
|
|
|
10
11
|
err.original?.code ||
|
|
11
12
|
err.original?.context?.response?.statusCode);
|
|
12
13
|
}
|
|
14
|
+
function hasErrorCode(...codes) {
|
|
15
|
+
return (err) => codes.includes(parseErrorCode(err));
|
|
16
|
+
}
|
|
17
|
+
const isQuotaExhaustion = (err) => parseErrorCode(err) === 429;
|
|
18
|
+
exports.isQuotaExhaustion = isQuotaExhaustion;
|
|
19
|
+
const isConflict = (err) => parseErrorCode(err) === 409;
|
|
20
|
+
exports.isConflict = isConflict;
|
|
21
|
+
const isServiceUnavailable = (err) => parseErrorCode(err) === 503;
|
|
22
|
+
exports.isServiceUnavailable = isServiceUnavailable;
|
|
23
|
+
const isTransientError = (err) => (0, exports.isQuotaExhaustion)(err) || (0, exports.isConflict)(err) || (0, exports.isServiceUnavailable)(err);
|
|
24
|
+
exports.isTransientError = isTransientError;
|
|
25
|
+
const isServiceAccount404 = (err) => {
|
|
26
|
+
if (parseErrorCode(err) !== 404) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
let message = "";
|
|
30
|
+
try {
|
|
31
|
+
message = [
|
|
32
|
+
err?.message,
|
|
33
|
+
err?.original?.message,
|
|
34
|
+
err?.context?.body?.error?.message,
|
|
35
|
+
String(err),
|
|
36
|
+
]
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.join(" ")
|
|
39
|
+
.toLowerCase();
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
message = String(err).toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
return (message.includes("serviceaccount") ||
|
|
45
|
+
message.includes("service account") ||
|
|
46
|
+
/\b[a-z0-9._%+-]+@[a-z0-9.-]+\.gserviceaccount\.com\b/i.test(message) ||
|
|
47
|
+
/\bgserviceaccount\.com\b/i.test(message));
|
|
48
|
+
};
|
|
49
|
+
exports.isServiceAccount404 = isServiceAccount404;
|
|
50
|
+
const isCloudRunResourceExhausted = (err) => parseErrorCode(err) === 8;
|
|
51
|
+
exports.isCloudRunResourceExhausted = isCloudRunResourceExhausted;
|
|
13
52
|
async function handler(op) {
|
|
14
53
|
try {
|
|
15
54
|
op.result = await op.func();
|
|
16
55
|
}
|
|
17
56
|
catch (err) {
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
57
|
+
const shouldRetry = op.retryPredicates.some((predicate) => predicate(err));
|
|
58
|
+
if (shouldRetry) {
|
|
20
59
|
throw err;
|
|
21
60
|
}
|
|
22
|
-
err.code =
|
|
61
|
+
err.code = parseErrorCode(err);
|
|
23
62
|
op.error = err;
|
|
24
63
|
}
|
|
25
64
|
return;
|
|
26
65
|
}
|
|
27
66
|
class QueueExecutor {
|
|
28
67
|
constructor(options) {
|
|
29
|
-
|
|
68
|
+
const { defaultRetryPredicates, ...throttlerOptions } = options;
|
|
69
|
+
this.defaultRetryPredicates = defaultRetryPredicates || [exports.isTransientError];
|
|
70
|
+
this.queue = new queue_1.Queue({ ...throttlerOptions, handler });
|
|
30
71
|
}
|
|
31
72
|
async run(func, opts) {
|
|
32
|
-
const
|
|
73
|
+
const retryPredicates = opts?.retryPredicates
|
|
74
|
+
? [...opts.retryPredicates]
|
|
75
|
+
: [...this.defaultRetryPredicates];
|
|
33
76
|
const op = {
|
|
34
77
|
func,
|
|
35
|
-
|
|
78
|
+
retryPredicates,
|
|
36
79
|
};
|
|
37
80
|
await this.queue.run(op);
|
|
38
81
|
if (op.error) {
|
|
@@ -66,11 +66,13 @@ class Fabricator {
|
|
|
66
66
|
this.projectId = args.projectId;
|
|
67
67
|
}
|
|
68
68
|
async grantNewRoles(plan, codebase) {
|
|
69
|
+
let createdSA = false;
|
|
69
70
|
if (plan.serviceAccountToCreate) {
|
|
70
71
|
utils.logLabeledBullet("functions", `Creating managed service account ${plan.serviceAccountToCreate}...`);
|
|
71
72
|
const saName = plan.serviceAccountToCreate.split("@")[0];
|
|
72
73
|
try {
|
|
73
74
|
await iam.createServiceAccount(this.projectId, saName, `Managed by Firebase CLI for codebase ${codebase}`, `Firebase Functions ${codebase}`);
|
|
75
|
+
createdSA = true;
|
|
74
76
|
}
|
|
75
77
|
catch (e) {
|
|
76
78
|
throw new error_1.FirebaseError("Cannot enable declarative security because you do not have permissions necessary to create the service account. Please ask an IAM administrator to perform the next deploy.", { original: e });
|
|
@@ -87,6 +89,14 @@ class Fabricator {
|
|
|
87
89
|
await resourcemanager.addServiceAccountRoles(this.projectId, plan.managedServiceAccount, plan.rolesToAdd, true);
|
|
88
90
|
}
|
|
89
91
|
catch (e) {
|
|
92
|
+
if (createdSA && plan.serviceAccountToCreate) {
|
|
93
|
+
try {
|
|
94
|
+
await iam.deleteServiceAccount(this.projectId, plan.serviceAccountToCreate);
|
|
95
|
+
}
|
|
96
|
+
catch (cleanupErr) {
|
|
97
|
+
logger_1.logger.debug("Failed to clean up newly created service account after role grant error", cleanupErr);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
90
100
|
throw new error_1.FirebaseError("The declarative security roles for this codebase have changed, but you do not have access to see what has changed. Please ask an IAM administrator to perform the next deploy.", { original: e });
|
|
91
101
|
}
|
|
92
102
|
}
|
|
@@ -154,6 +164,7 @@ class Fabricator {
|
|
|
154
164
|
logger_1.logger.debug("Fabricator.applyUpserts returned an unhandled exception.", JSON.stringify(r.reason, null, 2));
|
|
155
165
|
return acc;
|
|
156
166
|
}, []);
|
|
167
|
+
await this.cleanupUnusedServiceAccounts(plan, summary.results);
|
|
157
168
|
const hasFailures = summary.results.some((r) => r.error);
|
|
158
169
|
if (hasFailures) {
|
|
159
170
|
utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes.");
|
|
@@ -183,6 +194,24 @@ class Fabricator {
|
|
|
183
194
|
summary.totalTime = timer.stop();
|
|
184
195
|
return summary;
|
|
185
196
|
}
|
|
197
|
+
async cleanupUnusedServiceAccounts(plan, results) {
|
|
198
|
+
for (const [codebase, codebasePlan] of Object.entries(plan)) {
|
|
199
|
+
if (!codebasePlan.serviceAccountToCreate) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const codebaseSuccesses = results.filter((r) => r.endpoint.codebase === codebase && !r.error);
|
|
203
|
+
if (codebaseSuccesses.length > 0) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
utils.logLabeledWarning("functions", `Cleaning up managed service account ${codebasePlan.serviceAccountToCreate} due to 100% deployment failure for codebase ${codebase}.`);
|
|
207
|
+
try {
|
|
208
|
+
await iam.deleteServiceAccount(this.projectId, codebasePlan.serviceAccountToCreate);
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
logger_1.logger.debug(`Failed to delete managed service account ${codebasePlan.serviceAccountToCreate} during failure cleanup`, e);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
186
215
|
async applyUpserts(changes, scraperV1, scraperV2) {
|
|
187
216
|
const ops = [];
|
|
188
217
|
for (const endpoint of changes.endpointsToCreate) {
|
|
@@ -289,7 +318,7 @@ class Fabricator {
|
|
|
289
318
|
operationResourceName: op.name,
|
|
290
319
|
onPoll: scraper.poller,
|
|
291
320
|
});
|
|
292
|
-
})
|
|
321
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404] })
|
|
293
322
|
.catch(rethrowAs(endpoint, "create"));
|
|
294
323
|
endpoint.uri = resultFunction?.httpsTrigger?.url;
|
|
295
324
|
if (backend.isHttpsTriggered(endpoint)) {
|
|
@@ -395,7 +424,7 @@ class Fabricator {
|
|
|
395
424
|
operationResourceName: op.name,
|
|
396
425
|
onPoll: scraper.poller,
|
|
397
426
|
});
|
|
398
|
-
})
|
|
427
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404] })
|
|
399
428
|
.catch(async (err) => {
|
|
400
429
|
scraper.abort();
|
|
401
430
|
if (err.code === CLOUD_RUN_RESOURCE_EXHAUSTED_CODE) {
|
|
@@ -522,7 +551,7 @@ class Fabricator {
|
|
|
522
551
|
operationResourceName: op.name,
|
|
523
552
|
onPoll: scraper.poller,
|
|
524
553
|
});
|
|
525
|
-
}, {
|
|
554
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isCloudRunResourceExhausted, executor_1.isServiceAccount404] })
|
|
526
555
|
.catch((err) => {
|
|
527
556
|
scraper.abort();
|
|
528
557
|
logger_1.logger.error(err.message);
|
|
@@ -592,7 +621,7 @@ class Fabricator {
|
|
|
592
621
|
operationResourceName: op.name,
|
|
593
622
|
};
|
|
594
623
|
await poller.pollOperation(pollerOptions);
|
|
595
|
-
}, {
|
|
624
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isCloudRunResourceExhausted, executor_1.isServiceAccount404] })
|
|
596
625
|
.catch(rethrowAs(endpoint, "delete"));
|
|
597
626
|
}
|
|
598
627
|
async createRunFunction(endpoint) {
|
|
@@ -615,7 +644,7 @@ class Fabricator {
|
|
|
615
644
|
const op = await runV2.createService(endpoint.project, endpoint.region, endpoint.id, service);
|
|
616
645
|
endpoint.uri = op.uri;
|
|
617
646
|
endpoint.runServiceId = endpoint.id;
|
|
618
|
-
})
|
|
647
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404] })
|
|
619
648
|
.catch(rethrowAs(endpoint, "create"));
|
|
620
649
|
const serviceName = `projects/${endpoint.project}/locations/${endpoint.region}/services/${endpoint.runServiceId}`;
|
|
621
650
|
if (backend.isHttpsTriggered(endpoint)) {
|
package/lib/deploy/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const ExtensionsTarget = require("./extensions");
|
|
|
22
22
|
const DataConnectTarget = require("./dataconnect");
|
|
23
23
|
const AppHostingTarget = require("./apphosting");
|
|
24
24
|
const AuthTarget = require("./auth");
|
|
25
|
+
const AiLogicTarget = require("./ailogic");
|
|
25
26
|
const frameworks_1 = require("../frameworks");
|
|
26
27
|
const prepare_1 = require("./hosting/prepare");
|
|
27
28
|
const requirePermissions_1 = require("../requirePermissions");
|
|
@@ -37,6 +38,7 @@ exports.VALID_DEPLOY_TARGETS = [
|
|
|
37
38
|
"dataconnect",
|
|
38
39
|
"apphosting",
|
|
39
40
|
"auth",
|
|
41
|
+
"ailogic",
|
|
40
42
|
];
|
|
41
43
|
exports.TARGET_PERMISSIONS = {
|
|
42
44
|
database: ["firebasedatabase.instances.update"],
|
|
@@ -87,6 +89,12 @@ exports.TARGET_PERMISSIONS = {
|
|
|
87
89
|
apphosting: [],
|
|
88
90
|
extensions: [],
|
|
89
91
|
auth: ["firebase.projects.update", "firebaseauth.configs.update"],
|
|
92
|
+
ailogic: [
|
|
93
|
+
"firebasevertexai.templates.update",
|
|
94
|
+
"firebasevertexai.templates.get",
|
|
95
|
+
"firebasevertexai.templates.delete",
|
|
96
|
+
"serviceusage.services.get",
|
|
97
|
+
],
|
|
90
98
|
};
|
|
91
99
|
exports.TARGETS = {
|
|
92
100
|
hosting: HostingTarget,
|
|
@@ -99,6 +107,7 @@ exports.TARGETS = {
|
|
|
99
107
|
dataconnect: DataConnectTarget,
|
|
100
108
|
apphosting: AppHostingTarget,
|
|
101
109
|
auth: AuthTarget,
|
|
110
|
+
ailogic: AiLogicTarget,
|
|
102
111
|
};
|
|
103
112
|
const chain = async function (fns, context, options, payload) {
|
|
104
113
|
for (const latest of fns) {
|