firebase-tools-with-isolate 15.25.1 → 15.27.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 +52 -0
- package/lib/appcheck/providers.js +240 -0
- 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-apps-list.js +78 -0
- package/lib/commands/appcheck-debugtokens-create.js +2 -2
- package/lib/commands/appcheck-debugtokens-delete.js +2 -2
- package/lib/commands/appcheck-debugtokens-list.js +2 -2
- package/lib/commands/appcheck-prompts.js +55 -0
- package/lib/commands/appcheck-providers-get.js +73 -0
- package/lib/commands/appcheck-providers-list.js +67 -0
- package/lib/commands/appcheck-providers-set.js +96 -0
- 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/ext-export.js +75 -3
- package/lib/commands/firestore-locations.js +3 -1
- package/lib/commands/functions-kits-install.js +294 -0
- package/lib/commands/index.js +24 -0
- package/lib/commands/login.js +53 -6
- package/lib/config.js +1 -0
- package/lib/crashlytics/filters.js +12 -4
- package/lib/crashlytics/firebasetelemetry.js +36 -0
- package/lib/crashlytics/onboarding.js +41 -0
- package/lib/crashlytics/reports.js +2 -0
- package/lib/crashlytics/sourcemap.js +102 -12
- package/lib/crashlytics/types.js +8 -1
- 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/backend.js +11 -1
- package/lib/deploy/functions/build.js +1 -1
- package/lib/deploy/functions/params.js +5 -1
- package/lib/deploy/functions/prepare.js +26 -13
- package/lib/deploy/functions/prompts.js +1 -1
- package/lib/deploy/functions/release/lifecycle.js +11 -0
- package/lib/deploy/functions/release/planner.js +5 -2
- package/lib/deploy/index.js +9 -0
- package/lib/emulator/controller.js +1 -0
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/functionsEmulator.js +3 -1
- package/lib/experiments.js +13 -0
- package/lib/extensions/checkProjectBilling.js +3 -73
- package/lib/extensions/export.js +47 -0
- package/lib/functions/env.js +20 -7
- package/lib/functions/projectConfig.js +19 -11
- package/lib/functions/python.js +1 -1
- package/lib/gcp/ailogic.js +70 -1
- package/lib/gcp/cloudbilling.js +74 -0
- package/lib/gcp/cloudlogging.js +54 -0
- package/lib/gcp/runv2.js +1 -0
- package/lib/management/apps.js +1 -2
- package/lib/mcp/onemcp/index.js +2 -1
- package/lib/mcp/onemcp/onemcp_server.js +38 -11
- package/lib/mcp/prompts/crashlytics/connect.js +1 -1
- package/lib/mcp/resources/guides/crashlytics_issues.js +3 -3
- package/lib/mcp/resources/guides/crashlytics_reports.js +32 -11
- package/lib/mcp/tool.js +5 -0
- package/lib/mcp/tools/crashlytics/notes.js +3 -3
- package/lib/mcp/tools/crashlytics/reports.js +2 -0
- package/lib/mcp/util/crashlytics/availability.js +54 -1
- package/lib/prompt.js +10 -1
- package/lib/requirePermissions.js +1 -1
- package/lib/serve/functions.js +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/schema/firebase-config.json +42 -3
- package/templates/init/functions/typescript/index-kit-migration.ts +49 -0
- package/templates/init/functions/typescript/index-kit.ts +35 -0
- package/lib/appcheck/prompts.js +0 -41
|
@@ -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 {
|
package/lib/crashlytics/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ThreadState = exports.Signal = exports.State = exports.SessionEventType = exports.FormFactor = exports.TrackType = exports.ErrorType = void 0;
|
|
3
|
+
exports.TimeGranularity = exports.ThreadState = exports.Signal = exports.State = exports.SessionEventType = exports.FormFactor = exports.TrackType = exports.ErrorType = void 0;
|
|
4
4
|
var ErrorType;
|
|
5
5
|
(function (ErrorType) {
|
|
6
6
|
ErrorType["ERROR_TYPE_UNSPECIFIED"] = "ERROR_TYPE_UNSPECIFIED";
|
|
@@ -58,3 +58,10 @@ var ThreadState;
|
|
|
58
58
|
ThreadState["THREAD_STATE_NATIVE_RUNNABLE"] = "THREAD_STATE_NATIVE_RUNNABLE";
|
|
59
59
|
ThreadState["THREAD_STATE_NATIVE_WAITING"] = "THREAD_STATE_NATIVE_WAITING";
|
|
60
60
|
})(ThreadState || (exports.ThreadState = ThreadState = {}));
|
|
61
|
+
var TimeGranularity;
|
|
62
|
+
(function (TimeGranularity) {
|
|
63
|
+
TimeGranularity["TIME_GRANULARITY_UNSPECIFIED"] = "TIME_GRANULARITY_UNSPECIFIED";
|
|
64
|
+
TimeGranularity["TIME_GRANULARITY_NONE"] = "TIME_GRANULARITY_NONE";
|
|
65
|
+
TimeGranularity["TIME_GRANULARITY_HOUR"] = "TIME_GRANULARITY_HOUR";
|
|
66
|
+
TimeGranularity["TIME_GRANULARITY_DAY"] = "TIME_GRANULARITY_DAY";
|
|
67
|
+
})(TimeGranularity || (exports.TimeGranularity = TimeGranularity = {}));
|
|
@@ -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
|
+
}
|
|
@@ -246,10 +246,20 @@ async function loadExistingBackend(ctx) {
|
|
|
246
246
|
}
|
|
247
247
|
async function loadCloudRunServices(ctx, existingBackend, unreachableRegions, onlyMissing) {
|
|
248
248
|
try {
|
|
249
|
+
const runServiceIdsByRegion = {};
|
|
250
|
+
for (const [region, endpoints] of Object.entries(existingBackend.endpoints)) {
|
|
251
|
+
const ids = Object.values(endpoints)
|
|
252
|
+
.map((e) => e.runServiceId)
|
|
253
|
+
.filter((id) => !!id);
|
|
254
|
+
runServiceIdsByRegion[region] = new Set(ids);
|
|
255
|
+
}
|
|
249
256
|
const runServices = await run.listServices(ctx.projectId);
|
|
250
257
|
for (const service of runServices) {
|
|
251
258
|
const endpoint = run.endpointFromService(service);
|
|
252
|
-
|
|
259
|
+
const hasMatchingId = !!existingBackend.endpoints[endpoint.region]?.[endpoint.id];
|
|
260
|
+
const hasMatchingServiceId = !!(endpoint.runServiceId && runServiceIdsByRegion[endpoint.region]?.has(endpoint.runServiceId));
|
|
261
|
+
const alreadyLoaded = hasMatchingId || hasMatchingServiceId;
|
|
262
|
+
if (!onlyMissing || !alreadyLoaded) {
|
|
253
263
|
existingBackend.endpoints[endpoint.region] =
|
|
254
264
|
existingBackend.endpoints[endpoint.region] || {};
|
|
255
265
|
existingBackend.endpoints[endpoint.region][endpoint.id] = endpoint;
|
|
@@ -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.force, opts.isEmulator);
|
|
85
|
+
const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams(opts.build.params, opts.firebaseConfig, envWithTypes(opts.build.params, opts.userEnvs), opts.codebase, 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) {
|
|
@@ -10,6 +10,7 @@ exports.isSelectInput = isSelectInput;
|
|
|
10
10
|
exports.isResourceInput = isResourceInput;
|
|
11
11
|
exports.isMultiSelectInput = isMultiSelectInput;
|
|
12
12
|
exports.resolveParams = resolveParams;
|
|
13
|
+
const clc = require("colorette");
|
|
13
14
|
const logger_1 = require("../../logger");
|
|
14
15
|
const error_1 = require("../../error");
|
|
15
16
|
const prompt_1 = require("../../prompt");
|
|
@@ -162,7 +163,7 @@ function canSatisfyParam(param, value) {
|
|
|
162
163
|
}
|
|
163
164
|
(0, functional_1.assertExhaustive)(param);
|
|
164
165
|
}
|
|
165
|
-
async function resolveParams(params, firebaseConfig, userEnvs, nonInteractive, force, isEmulator = false) {
|
|
166
|
+
async function resolveParams(params, firebaseConfig, userEnvs, codebase, nonInteractive, force, isEmulator = false) {
|
|
166
167
|
const paramValues = populateDefaultParams(firebaseConfig);
|
|
167
168
|
const secretRefs = {};
|
|
168
169
|
const [resolved, outstanding] = (0, functional_1.partition)(params, (param) => {
|
|
@@ -183,6 +184,9 @@ async function resolveParams(params, firebaseConfig, userEnvs, nonInteractive, f
|
|
|
183
184
|
"To continue, either run `firebase deploy` with an interactive terminal, or add values to a dotenv file. " +
|
|
184
185
|
"For information regarding how to use dotenv files, see https://firebase.google.com/docs/functions/config-env");
|
|
185
186
|
}
|
|
187
|
+
if (needPrompt.length > 0) {
|
|
188
|
+
logger_1.logger.info(`Prompting for parameters for codebase ${clc.bold(codebase)}:`);
|
|
189
|
+
}
|
|
186
190
|
for (const param of needPrompt) {
|
|
187
191
|
const promptable = param;
|
|
188
192
|
let paramDefault = promptable.default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EVENTARC_SOURCE_ENV = void 0;
|
|
3
|
+
exports.DECLARATIVE_SECURITY_ETAG_LABEL = exports.EVENTARC_SOURCE_ENV = void 0;
|
|
4
4
|
exports.discoverSecurityDetails = discoverSecurityDetails;
|
|
5
5
|
exports.prepare = prepare;
|
|
6
6
|
exports.resolveDefaultRegionsForBuild = resolveDefaultRegionsForBuild;
|
|
@@ -13,6 +13,7 @@ exports.loadCodebases = loadCodebases;
|
|
|
13
13
|
exports.warnIfNewGenkitFunctionIsMissingSecrets = warnIfNewGenkitFunctionIsMissingSecrets;
|
|
14
14
|
exports.ensureAllRequiredAPIsEnabled = ensureAllRequiredAPIsEnabled;
|
|
15
15
|
exports.partitionUserEnvs = partitionUserEnvs;
|
|
16
|
+
exports.checkKitForGen1 = checkKitForGen1;
|
|
16
17
|
const clc = require("colorette");
|
|
17
18
|
const proto = require("../../gcp/proto");
|
|
18
19
|
const backend = require("./backend");
|
|
@@ -48,17 +49,11 @@ const prompt = require("../../prompt");
|
|
|
48
49
|
const iam = require("../../gcp/iam");
|
|
49
50
|
const resourcemanager = require("../../gcp/resourceManager");
|
|
50
51
|
exports.EVENTARC_SOURCE_ENV = "EVENTARC_CLOUD_EVENT_SOURCE";
|
|
52
|
+
exports.DECLARATIVE_SECURITY_ETAG_LABEL = "firebase-declarative-security-etag";
|
|
51
53
|
async function discoverSecurityDetails(codebase, want, have, projectId, filters) {
|
|
52
54
|
const requiredRoles = want.requiredRoles;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
let haveRolesEtag;
|
|
56
|
-
if (firstHave) {
|
|
57
|
-
haveRolesEtag = firstHave.labels?.["firebase-declarative-security-etag"];
|
|
58
|
-
existingManagedSA = firstHave.serviceAccount?.startsWith("firebase-fn-")
|
|
59
|
-
? firstHave.serviceAccount
|
|
60
|
-
: undefined;
|
|
61
|
-
}
|
|
55
|
+
const existingManagedSA = backend.findEndpoint(have, (e) => typeof e.serviceAccount === "string" && e.serviceAccount.startsWith("firebase-fn-"))?.serviceAccount ?? undefined;
|
|
56
|
+
const haveRolesEtag = backend.findEndpoint(have, (e) => !!e.labels?.[exports.DECLARATIVE_SECURITY_ETAG_LABEL])?.labels?.[exports.DECLARATIVE_SECURITY_ETAG_LABEL];
|
|
62
57
|
const isPartiallyFiltered = !!(filters &&
|
|
63
58
|
filters.some((f) => (!f.codebase || f.codebase === codebase) && f.idChunks && f.idChunks.length > 0));
|
|
64
59
|
const isEnrolling = !!requiredRoles && !existingManagedSA;
|
|
@@ -67,6 +62,15 @@ async function discoverSecurityDetails(codebase, want, have, projectId, filters)
|
|
|
67
62
|
throw new error_1.FirebaseError("To ensure a whole codebase is migrated cleanly, you may not deploy only part of a " +
|
|
68
63
|
"codebase when opting into or out of declarative security (starting or no longer using `requireRoles`)");
|
|
69
64
|
}
|
|
65
|
+
if (!backend.someEndpoint(want, () => true)) {
|
|
66
|
+
if (existingManagedSA) {
|
|
67
|
+
return {
|
|
68
|
+
existingManagedSA,
|
|
69
|
+
...(haveRolesEtag ? { haveRolesEtag } : {}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
70
74
|
if (!requiredRoles && (!existingManagedSA || !haveRolesEtag)) {
|
|
71
75
|
return {};
|
|
72
76
|
}
|
|
@@ -98,7 +102,7 @@ async function discoverSecurityDetails(codebase, want, have, projectId, filters)
|
|
|
98
102
|
for (const endpoint of backend.allEndpoints(want)) {
|
|
99
103
|
endpoint.serviceAccount = managedSA;
|
|
100
104
|
endpoint.labels = endpoint.labels || {};
|
|
101
|
-
endpoint.labels[
|
|
105
|
+
endpoint.labels[exports.DECLARATIVE_SECURITY_ETAG_LABEL] = newEtag;
|
|
102
106
|
}
|
|
103
107
|
if (haveRolesEtag && haveRolesEtag === newEtag) {
|
|
104
108
|
return {
|
|
@@ -184,12 +188,14 @@ async function prepare(context, options, payload) {
|
|
|
184
188
|
const wantBackends = {};
|
|
185
189
|
for (const [codebase, wantBuild] of Object.entries(wantBuilds)) {
|
|
186
190
|
const config = (0, projectConfig_1.configForCodebase)(context.config, codebase);
|
|
187
|
-
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId);
|
|
191
|
+
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId, (0, projectConfig_1.isKitConfig)(config) ? codebase : undefined);
|
|
188
192
|
const localCfg = (0, projectConfig_1.requireLocal)(config, "Remote sources are not supported.");
|
|
193
|
+
checkKitForGen1(localCfg, wantBuild);
|
|
189
194
|
const userEnvOpt = {
|
|
190
195
|
functionsSource: options.config.path(localCfg.source),
|
|
191
196
|
projectId: projectId,
|
|
192
197
|
projectAlias: options.projectAlias,
|
|
198
|
+
projectDir: options.config.projectDir,
|
|
193
199
|
};
|
|
194
200
|
if ((0, projectConfig_1.isKitConfig)(localCfg) && codebase in localCfg.instances) {
|
|
195
201
|
userEnvOpt.configDir = options.config.path(localCfg.instances[codebase]);
|
|
@@ -210,6 +216,7 @@ async function prepare(context, options, payload) {
|
|
|
210
216
|
build: wantBuild,
|
|
211
217
|
firebaseConfig,
|
|
212
218
|
userEnvs,
|
|
219
|
+
codebase,
|
|
213
220
|
nonInteractive: options.nonInteractive,
|
|
214
221
|
force: options.force,
|
|
215
222
|
isEmulator: false,
|
|
@@ -504,7 +511,7 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
504
511
|
await runtimeDelegate.validate();
|
|
505
512
|
logger_1.logger.debug(`Building ${runtimeDelegate.language} source`);
|
|
506
513
|
await runtimeDelegate.build();
|
|
507
|
-
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId);
|
|
514
|
+
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId, (0, projectConfig_1.isKitConfig)(codebaseConfig) ? codebase : undefined);
|
|
508
515
|
(0, utils_1.logLabeledBullet)("functions", `Loading and analyzing source code for codebase ${codebase} to determine what to deploy`);
|
|
509
516
|
const codebaseRuntimeConfig = (0, projectConfig_1.shouldUseRuntimeConfig)(codebaseConfig)
|
|
510
517
|
? runtimeConfig
|
|
@@ -625,3 +632,9 @@ function partitionUserEnvs(allEnvs) {
|
|
|
625
632
|
}, [{}, {}]);
|
|
626
633
|
return { userEnvs: userEnvs, secretRefs: secretRefs };
|
|
627
634
|
}
|
|
635
|
+
function checkKitForGen1(localCfg, wantBuild) {
|
|
636
|
+
if ((0, projectConfig_1.isKitConfig)(localCfg) &&
|
|
637
|
+
Object.values(wantBuild.endpoints).some((e) => e.platform === "gcfv1")) {
|
|
638
|
+
throw new error_1.FirebaseError(`Function kit "${localCfg.kit}" contains gen1 functions, which are not supported in kits. Please remove this kit or upgrade these functions to gen2.`);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
@@ -265,7 +265,7 @@ async function promptForLifecycleEvent(codebase, wantBackend, options) {
|
|
|
265
265
|
}
|
|
266
266
|
choices.push({ name: "skip (default)", value: "skip" });
|
|
267
267
|
const selection = await (0, prompt_1.select)({
|
|
268
|
-
message: `
|
|
268
|
+
message: `Cannot determine if this is a first deploy or a redeploy for codebase "${codebase}" because the last deployment was partial (either due to a failure or a filtered deploy).`,
|
|
269
269
|
choices,
|
|
270
270
|
default: "skip",
|
|
271
271
|
nonInteractive: options?.nonInteractive,
|
|
@@ -42,6 +42,17 @@ async function executeLifecycleHooks(wantBackend, haveBackend, plan, codebase, o
|
|
|
42
42
|
if (!hasLifecycleHooks(wantBackend)) {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
+
const codebasePlan = plan && codebase ? plan[codebase] : undefined;
|
|
46
|
+
if (codebasePlan && codebase) {
|
|
47
|
+
const allWantEndpoints = backend.allEndpoints(wantBackend);
|
|
48
|
+
const isFiltered = allWantEndpoints.some(backend.missingEndpoint(codebasePlan.plannedBackend));
|
|
49
|
+
if (isFiltered) {
|
|
50
|
+
const event = determineLifecycleEvent(haveBackend);
|
|
51
|
+
(0, utils_1.logLabeledWarning)("functions", `Lifecycle hook "${event}" for codebase "${codebase}" was configured but not executed because this was a partial deployment (filtered).`);
|
|
52
|
+
(0, utils_1.logLabeledBullet)("functions", `You can run the lifecycle hook in isolation by running: firebase functions:lifecycle:run ${event} ${codebase}`);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
45
56
|
let event;
|
|
46
57
|
if (isRecoveryDeployment(wantBackend, haveBackend)) {
|
|
47
58
|
event = await prompts.promptForLifecycleEvent(codebase ?? "default", wantBackend, options);
|
|
@@ -86,7 +86,8 @@ async function createDeploymentPlan(args) {
|
|
|
86
86
|
const isFiltered = !!(filters &&
|
|
87
87
|
filters.some((f) => f.idChunks && f.idChunks.length > 0) &&
|
|
88
88
|
!deleteAll);
|
|
89
|
-
|
|
89
|
+
const hasWantEndpoints = backend.someEndpoint(wantBackend, () => true);
|
|
90
|
+
if (requiredRoles && hasWantEndpoints) {
|
|
90
91
|
rolesToAdd = requiredRoles.filter((r) => !roles.includes(r));
|
|
91
92
|
rolesToRemove = roles.filter((r) => !requiredRoles.includes(r));
|
|
92
93
|
if (!existingManagedSA && managedSA) {
|
|
@@ -118,7 +119,7 @@ async function createDeploymentPlan(args) {
|
|
|
118
119
|
"default to 80 concurrent executions, but existing functions keep the " +
|
|
119
120
|
"old default of 1. You can change this with the 'concurrency' option.");
|
|
120
121
|
}
|
|
121
|
-
if (requiredRoles) {
|
|
122
|
+
if (requiredRoles && hasWantEndpoints) {
|
|
122
123
|
if (!managedSA) {
|
|
123
124
|
throw new error_1.FirebaseError("managedServiceAccount is required when requiredRoles is defined.", {
|
|
124
125
|
exit: 1,
|
|
@@ -126,6 +127,7 @@ async function createDeploymentPlan(args) {
|
|
|
126
127
|
}
|
|
127
128
|
return {
|
|
128
129
|
regionalChangesets,
|
|
130
|
+
plannedBackend: wantBackend,
|
|
129
131
|
rolesToAdd,
|
|
130
132
|
rolesToRemove,
|
|
131
133
|
serviceAccountToCreate,
|
|
@@ -135,6 +137,7 @@ async function createDeploymentPlan(args) {
|
|
|
135
137
|
else {
|
|
136
138
|
return {
|
|
137
139
|
regionalChangesets,
|
|
140
|
+
plannedBackend: wantBackend,
|
|
138
141
|
serviceAccountToDelete,
|
|
139
142
|
};
|
|
140
143
|
}
|
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) {
|
|
@@ -355,6 +355,7 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
355
355
|
configDir: path.join(projectDir, configDir),
|
|
356
356
|
env: {
|
|
357
357
|
...options.extDevEnv,
|
|
358
|
+
FIREBASE_KIT_INSTANCE_ID: instanceId,
|
|
358
359
|
},
|
|
359
360
|
secretEnv: [],
|
|
360
361
|
predefinedTriggers: options.extDevTriggers,
|