firebase-tools-with-isolate 15.28.2 → 15.30.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/api.js +4 -2
- package/lib/apphosting/config.js +10 -8
- package/lib/apphosting/localbuilds.js +8 -0
- package/lib/apphosting/yaml.js +27 -0
- package/lib/bin/cli.js +1 -1
- package/lib/bin/mcp.js +8 -3
- package/lib/commands/ext-export.js +52 -14
- package/lib/commands/ext-migrate.js +70 -4
- package/lib/commands/ext-uninstall.js +2 -28
- package/lib/commands/functions-delete.js +6 -67
- package/lib/commands/functions-kits-install.js +7 -0
- package/lib/commands/functions-kits-uninstall.js +30 -86
- package/lib/crashlytics/onboarding.js +23 -2
- package/lib/deploy/apphosting/deploy.js +2 -1
- package/lib/deploy/apphosting/prepare.js +12 -3
- package/lib/deploy/apphosting/release.js +3 -0
- package/lib/deploy/apphosting/util.js +3 -1
- package/lib/deploy/extensions/secrets.js +10 -0
- package/lib/deploy/functions/delete.js +105 -0
- package/lib/deploy/functions/release/executor.js +14 -8
- package/lib/deploy/functions/release/fabricator.js +42 -20
- package/lib/deploy/functions/release/sourceTokenScraper.js +16 -2
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/tasksEmulator.js +2 -2
- package/lib/emulator/types.js +3 -1
- package/lib/extensions/askUserForParam.js +9 -8
- package/lib/extensions/export.js +47 -10
- package/lib/extensions/extensionsHelper.js +29 -2
- package/lib/extensions/manifest.js +5 -4
- package/lib/extensions/migrate.js +176 -2
- package/lib/extensions/paramHelper.js +78 -25
- package/lib/extensions/secretsUtils.js +3 -0
- package/lib/extensions/updateHelper.js +3 -1
- package/lib/functions/kits/install.js +322 -70
- package/lib/gcp/apikeys.js +89 -0
- package/lib/gcp/resourceManager.js +31 -22
- package/lib/gcp/run.js +2 -2
- package/lib/gcp/storage.js +3 -2
- package/lib/logger.js +83 -9
- package/lib/mcp/onemcp/index.js +19 -0
- package/lib/mcp/onemcp/onemcp_server.js +12 -7
- package/lib/mcp/tools/apphosting/fetch_logs.js +1 -0
- package/lib/mcp/tools/apphosting/list_backends.js +1 -0
- package/lib/mcp/tools/apptesting/tests.js +2 -0
- package/lib/mcp/tools/auth/get_users.js +1 -0
- package/lib/mcp/tools/auth/set_sms_region_policy.js +1 -0
- package/lib/mcp/tools/auth/update_user.js +1 -0
- package/lib/mcp/tools/core/create_android_sha.js +1 -0
- package/lib/mcp/tools/core/create_app.js +1 -0
- package/lib/mcp/tools/core/create_project.js +1 -0
- package/lib/mcp/tools/core/deploy.js +1 -0
- package/lib/mcp/tools/core/deploy_status.js +1 -0
- package/lib/mcp/tools/core/get_environment.js +1 -0
- package/lib/mcp/tools/core/get_project.js +1 -0
- package/lib/mcp/tools/core/get_sdk_config.js +1 -0
- package/lib/mcp/tools/core/get_security_rules.js +1 -0
- package/lib/mcp/tools/core/init.js +1 -0
- package/lib/mcp/tools/core/list_apps.js +1 -0
- package/lib/mcp/tools/core/list_projects.js +1 -0
- package/lib/mcp/tools/core/login.js +1 -0
- package/lib/mcp/tools/core/logout.js +1 -0
- package/lib/mcp/tools/core/read_resources.js +1 -0
- package/lib/mcp/tools/core/update_environment.js +1 -0
- package/lib/mcp/tools/core/validate_security_rules.js +1 -0
- package/lib/mcp/tools/crashlytics/events.js +2 -0
- package/lib/mcp/tools/crashlytics/issues.js +2 -0
- package/lib/mcp/tools/crashlytics/notes.js +3 -0
- package/lib/mcp/tools/crashlytics/reports.js +1 -0
- package/lib/mcp/tools/dataconnect/compile.js +1 -0
- package/lib/mcp/tools/dataconnect/execute.js +34 -19
- package/lib/mcp/tools/dataconnect/index.js +1 -1
- package/lib/mcp/tools/dataconnect/list_services.js +1 -0
- package/lib/mcp/tools/firestore/query_collection.js +1 -0
- package/lib/mcp/tools/functions/get_logs.js +1 -0
- package/lib/mcp/tools/functions/list_functions.js +1 -0
- package/lib/mcp/tools/index.js +3 -1
- package/lib/mcp/tools/messaging/send_message.js +1 -0
- package/lib/mcp/tools/realtime_database/get_data.js +1 -0
- package/lib/mcp/tools/realtime_database/set_data.js +1 -0
- package/lib/mcp/tools/remoteconfig/get_template.js +1 -0
- package/lib/mcp/tools/remoteconfig/update_template.js +1 -0
- package/lib/mcp/tools/storage/get_download_url.js +1 -0
- package/lib/prompt.js +10 -1
- package/lib/throttler/throttler.js +2 -11
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +26 -0
- package/package.json +5 -5
- package/templates/init/functions/typescript/index-kit-migration.ts +21 -2
- package/templates/init/functions/typescript/index-kit.ts +1 -0
- package/templates/init/functions/typescript/package-kit.json +21 -0
|
@@ -10,8 +10,23 @@ class SourceTokenScraper {
|
|
|
10
10
|
this.promise = new Promise((resolve) => (this.resolve = resolve));
|
|
11
11
|
this.fetchState = "NONE";
|
|
12
12
|
}
|
|
13
|
+
async withToken(fn) {
|
|
14
|
+
const token = await this.getToken();
|
|
15
|
+
try {
|
|
16
|
+
return await fn(token);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
this.abort();
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
13
23
|
abort() {
|
|
14
|
-
this.
|
|
24
|
+
if (this.fetchState === "FETCHING") {
|
|
25
|
+
this.fetchState = "NONE";
|
|
26
|
+
const resolve = this.resolve;
|
|
27
|
+
this.promise = new Promise((r) => (this.resolve = r));
|
|
28
|
+
resolve({ aborted: true });
|
|
29
|
+
}
|
|
15
30
|
}
|
|
16
31
|
async getToken() {
|
|
17
32
|
if (this.fetchState === "NONE") {
|
|
@@ -21,7 +36,6 @@ class SourceTokenScraper {
|
|
|
21
36
|
else if (this.fetchState === "FETCHING") {
|
|
22
37
|
const tokenResult = await this.promise;
|
|
23
38
|
if (tokenResult.aborted) {
|
|
24
|
-
this.promise = new Promise((resolve) => (this.resolve = resolve));
|
|
25
39
|
return undefined;
|
|
26
40
|
}
|
|
27
41
|
return tokenResult.token;
|
|
@@ -54,36 +54,36 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dataconnect": {
|
|
56
56
|
"darwin": {
|
|
57
|
-
"version": "3.4.
|
|
58
|
-
"expectedSize":
|
|
59
|
-
"expectedChecksum": "
|
|
60
|
-
"expectedChecksumSHA256": "
|
|
61
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.
|
|
62
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
57
|
+
"version": "3.4.19",
|
|
58
|
+
"expectedSize": 33412928,
|
|
59
|
+
"expectedChecksum": "5a65cd626d5c022eab4c2036b18f0314",
|
|
60
|
+
"expectedChecksumSHA256": "4a63243e720d26de7e2e5bd5060fc92768f09446ec42b3369fb6ddc06a9cdddf",
|
|
61
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.19",
|
|
62
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19"
|
|
63
63
|
},
|
|
64
64
|
"darwin_arm64": {
|
|
65
|
-
"version": "3.4.
|
|
66
|
-
"expectedSize":
|
|
67
|
-
"expectedChecksum": "
|
|
68
|
-
"expectedChecksumSHA256": "
|
|
69
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.
|
|
70
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
65
|
+
"version": "3.4.19",
|
|
66
|
+
"expectedSize": 31539602,
|
|
67
|
+
"expectedChecksum": "cd914718f705a9e614bc3024f443bb52",
|
|
68
|
+
"expectedChecksumSHA256": "dafb2e532c29d876cb30d5c2bf32b2e50a614386dc16ba82b0ed6a9fca2a6db3",
|
|
69
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.19",
|
|
70
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19"
|
|
71
71
|
},
|
|
72
72
|
"win32": {
|
|
73
|
-
"version": "3.4.
|
|
74
|
-
"expectedSize":
|
|
75
|
-
"expectedChecksum": "
|
|
76
|
-
"expectedChecksumSHA256": "
|
|
77
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.
|
|
78
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
73
|
+
"version": "3.4.19",
|
|
74
|
+
"expectedSize": 33444864,
|
|
75
|
+
"expectedChecksum": "e2f84df8d6c536bea29d2ccc4cb21e79",
|
|
76
|
+
"expectedChecksumSHA256": "756e370334ef982547e7252b3f91fd75b35f85c5d3666e8f3773a4a19a00c8f8",
|
|
77
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.19",
|
|
78
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19.exe"
|
|
79
79
|
},
|
|
80
80
|
"linux": {
|
|
81
|
-
"version": "3.4.
|
|
82
|
-
"expectedSize":
|
|
83
|
-
"expectedChecksum": "
|
|
84
|
-
"expectedChecksumSHA256": "
|
|
85
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.
|
|
86
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
81
|
+
"version": "3.4.19",
|
|
82
|
+
"expectedSize": 32542904,
|
|
83
|
+
"expectedChecksum": "63f099c9b9dad6e7d2adddae8af884a3",
|
|
84
|
+
"expectedChecksumSHA256": "bc74b68cc4bafcccc57dbe659a74b4403c225f01f851b5a4a61dcea81e8b1310",
|
|
85
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.19",
|
|
86
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.19"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -116,8 +116,8 @@ class TasksEmulator {
|
|
|
116
116
|
const queueName = req.params.queue_name;
|
|
117
117
|
if (!this.validateQueueId(queueName)) {
|
|
118
118
|
res.status(400).json({
|
|
119
|
-
error: "Queue ID
|
|
120
|
-
"
|
|
119
|
+
error: "Queue ID can contain only letters ([A-Za-z]), numbers ([0-9]), or hyphens (-). Queue ID " +
|
|
120
|
+
"must be between 1 and 100 characters.",
|
|
121
121
|
});
|
|
122
122
|
return;
|
|
123
123
|
}
|
package/lib/emulator/types.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Severity = exports.EmulatorLog = exports.FunctionsExecutionMode = exports.ALL_EMULATORS = exports.EMULATORS_SUPPORTED_BY_USE_EMULATOR = exports.EMULATORS_SUPPORTED_BY_UI = exports.EMULATORS_SUPPORTED_BY_FUNCTIONS = exports.ALL_SERVICE_EMULATORS = exports.IMPORT_EXPORT_EMULATORS = exports.DOWNLOADABLE_EMULATORS = exports.Emulators = void 0;
|
|
4
4
|
exports.isDownloadableEmulator = isDownloadableEmulator;
|
|
5
5
|
exports.isEmulator = isEmulator;
|
|
6
|
+
const error_1 = require("../error");
|
|
6
7
|
var Emulators;
|
|
7
8
|
(function (Emulators) {
|
|
8
9
|
Emulators["AUTH"] = "auth";
|
|
@@ -177,7 +178,8 @@ class EmulatorLog {
|
|
|
177
178
|
if (process.send) {
|
|
178
179
|
process.send(nextMsg, undefined, {}, (err) => {
|
|
179
180
|
if (err) {
|
|
180
|
-
process.stderr.write(err);
|
|
181
|
+
process.stderr.write(`${(0, error_1.getErrStack)(err)}\n`);
|
|
182
|
+
EmulatorLog.LOG_BUFFER = [];
|
|
181
183
|
}
|
|
182
184
|
EmulatorLog.WAITING_FOR_FLUSH = EmulatorLog.LOG_BUFFER.length > 0;
|
|
183
185
|
this.flush();
|
|
@@ -135,19 +135,20 @@ async function askForParam(args) {
|
|
|
135
135
|
});
|
|
136
136
|
valid = checkResponse(response, paramSpec);
|
|
137
137
|
break;
|
|
138
|
-
case types_1.ParamType.MULTISELECT:
|
|
138
|
+
case types_1.ParamType.MULTISELECT: {
|
|
139
|
+
const defaultValues = (paramSpec.default || "").split(",");
|
|
139
140
|
response = (await (0, prompt_1.checkbox)({
|
|
140
|
-
default: paramSpec.default
|
|
141
|
-
? paramSpec.default.split(",").map((def) => {
|
|
142
|
-
return getInquirerDefault(_.get(paramSpec, "options", []), def);
|
|
143
|
-
})
|
|
144
|
-
: undefined,
|
|
145
141
|
message: "Which options do you want enabled for this parameter? " +
|
|
146
142
|
"Press Space to select, then Enter to confirm your choices. ",
|
|
147
|
-
choices:
|
|
143
|
+
choices: paramSpec.options.map((option) => ({
|
|
144
|
+
checked: defaultValues.includes(option.value),
|
|
145
|
+
name: option.label || option.value,
|
|
146
|
+
value: option.value,
|
|
147
|
+
})),
|
|
148
148
|
})).join(",");
|
|
149
149
|
valid = checkResponse(response, paramSpec);
|
|
150
150
|
break;
|
|
151
|
+
}
|
|
151
152
|
case types_1.ParamType.SECRET:
|
|
152
153
|
do {
|
|
153
154
|
secretLocations = await promptSecretLocations(paramSpec);
|
|
@@ -165,7 +166,7 @@ async function askForParam(args) {
|
|
|
165
166
|
break;
|
|
166
167
|
default:
|
|
167
168
|
response = await (0, prompt_1.input)({
|
|
168
|
-
default: paramSpec.default,
|
|
169
|
+
default: paramSpec.default ?? (paramSpec.required ? undefined : ""),
|
|
169
170
|
message: `Enter a value for ${label}:`,
|
|
170
171
|
});
|
|
171
172
|
valid = checkResponse(response, paramSpec);
|
package/lib/extensions/export.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.parameterizeProject = parameterizeProject;
|
|
|
4
4
|
exports.setSecretParamsToLatest = setSecretParamsToLatest;
|
|
5
5
|
exports.displayExportInfo = displayExportInfo;
|
|
6
6
|
exports.functionsEnvFromInstance = functionsEnvFromInstance;
|
|
7
|
+
exports.secretsNeedingEjection = secretsNeedingEjection;
|
|
7
8
|
exports.ejectSecretsFromInstance = ejectSecretsFromInstance;
|
|
8
9
|
const planner_1 = require("../deploy/extensions/planner");
|
|
9
10
|
const deploymentSummary_1 = require("../deploy/extensions/deploymentSummary");
|
|
@@ -12,6 +13,7 @@ const secretManager_1 = require("../gcp/secretManager");
|
|
|
12
13
|
const secretsUtils_1 = require("./secretsUtils");
|
|
13
14
|
const secrets_1 = require("../deploy/extensions/secrets");
|
|
14
15
|
const error_1 = require("../error");
|
|
16
|
+
const utils_1 = require("../utils");
|
|
15
17
|
function parameterizeProject(projectId, projectNumber, spec) {
|
|
16
18
|
const newParams = {};
|
|
17
19
|
for (const [key, val] of Object.entries(spec.params)) {
|
|
@@ -67,8 +69,8 @@ function displaySpecs(specs) {
|
|
|
67
69
|
function functionsEnvFromInstance(instance) {
|
|
68
70
|
const liveParams = instance.config?.params || {};
|
|
69
71
|
const liveSystemParams = instance.config?.systemParams || {};
|
|
70
|
-
const specParams = instance.config?.source?.spec?.params ||
|
|
71
|
-
const specSystemParams = instance.config?.source?.spec?.systemParams ||
|
|
72
|
+
const specParams = instance.config?.source?.spec?.params || [];
|
|
73
|
+
const specSystemParams = instance.config?.source?.spec?.systemParams || [];
|
|
72
74
|
const envs = {};
|
|
73
75
|
specParams.forEach((specParam) => {
|
|
74
76
|
if (specParam.type === "SECRET") {
|
|
@@ -87,19 +89,22 @@ function functionsEnvFromInstance(instance) {
|
|
|
87
89
|
.replace(/^firebaseextensions\.v1beta\.(v2)?function\//, "EXT_MIGRATED_SYSTEM_")
|
|
88
90
|
.toUpperCase();
|
|
89
91
|
if (renamed === "EXT_MIGRATED_SYSTEM_LOCATION") {
|
|
90
|
-
renamed = "
|
|
92
|
+
renamed = "FUNCTION_DEFAULT_REGION";
|
|
91
93
|
}
|
|
92
94
|
envs[renamed] = sysParamValue;
|
|
93
95
|
}
|
|
94
|
-
for (const specSystemParam of
|
|
96
|
+
for (const specSystemParam of specSystemParams) {
|
|
95
97
|
if (specSystemParam.param in liveSystemParams) {
|
|
96
98
|
continue;
|
|
97
99
|
}
|
|
98
100
|
if ("default" in specSystemParam) {
|
|
99
|
-
|
|
101
|
+
let renamed = specSystemParam.param
|
|
100
102
|
.replace(/^firebaseextensions\.v1beta\.(v2)?function\//, "EXT_MIGRATED_SYSTEM_")
|
|
101
103
|
.toUpperCase();
|
|
102
|
-
|
|
104
|
+
if (renamed === "EXT_MIGRATED_SYSTEM_LOCATION") {
|
|
105
|
+
renamed = "FUNCTION_DEFAULT_REGION";
|
|
106
|
+
}
|
|
107
|
+
envs[renamed] = String(specSystemParam.default ?? "");
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
if (typeof instance.config.allowedEventTypes !== "undefined") {
|
|
@@ -110,8 +115,32 @@ function functionsEnvFromInstance(instance) {
|
|
|
110
115
|
}
|
|
111
116
|
return envs;
|
|
112
117
|
}
|
|
118
|
+
async function secretsNeedingEjection(instance) {
|
|
119
|
+
const liveParams = instance.config?.params || {};
|
|
120
|
+
const secretParams = (instance.config?.source?.spec?.params ?? []).filter((p) => p.type === "SECRET");
|
|
121
|
+
const checks = secretParams.map(async (specParam) => {
|
|
122
|
+
const secretName = specParam.param;
|
|
123
|
+
const resourceName = liveParams[secretName];
|
|
124
|
+
if (!resourceName) {
|
|
125
|
+
throw new error_1.FirebaseError("Secret " +
|
|
126
|
+
secretName +
|
|
127
|
+
" was defined in the extension spec, but is missing in live deployed secrets.", { exit: 1 });
|
|
128
|
+
}
|
|
129
|
+
const match = resourceName.match(secretManager_1.SECRET_VERSION_NAME_REGEX);
|
|
130
|
+
if (!match?.groups) {
|
|
131
|
+
throw new error_1.FirebaseError("Invalid secret version resource name [" + resourceName + "].");
|
|
132
|
+
}
|
|
133
|
+
const projectId = match.groups.project;
|
|
134
|
+
const secretId = match.groups.secret;
|
|
135
|
+
const hasLabel = await (0, secrets_1.secretHasExtensionsLabel)(projectId, secretId);
|
|
136
|
+
return hasLabel ? `${projectId}/${secretId}` : undefined;
|
|
137
|
+
});
|
|
138
|
+
const results = await Promise.all(checks);
|
|
139
|
+
return results.filter((r) => r !== undefined);
|
|
140
|
+
}
|
|
113
141
|
async function ejectSecretsFromInstance(instance) {
|
|
114
|
-
const
|
|
142
|
+
const success = [];
|
|
143
|
+
const fail = [];
|
|
115
144
|
const liveParams = instance.config?.params || {};
|
|
116
145
|
for (const specParam of instance.config?.source?.spec?.params ?? []) {
|
|
117
146
|
if (specParam.type !== "SECRET") {
|
|
@@ -128,8 +157,16 @@ async function ejectSecretsFromInstance(instance) {
|
|
|
128
157
|
}
|
|
129
158
|
const projectId = match.groups.project;
|
|
130
159
|
const secretId = match.groups.secret;
|
|
131
|
-
|
|
132
|
-
|
|
160
|
+
const combinedId = `${projectId}/${secretId}`;
|
|
161
|
+
try {
|
|
162
|
+
await (0, secrets_1.transferSecretToKits)(projectId, secretId);
|
|
163
|
+
success.push(combinedId);
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
fail.push(combinedId);
|
|
167
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
168
|
+
(0, utils_1.logLabeledError)("extensions", "failed to change labels on " + combinedId + ": " + message);
|
|
169
|
+
}
|
|
133
170
|
}
|
|
134
|
-
return
|
|
171
|
+
return { success: success, fail: fail };
|
|
135
172
|
}
|
|
@@ -29,6 +29,7 @@ exports.isLocalPath = isLocalPath;
|
|
|
29
29
|
exports.isLocalOrURLPath = isLocalOrURLPath;
|
|
30
30
|
exports.getSourceOrigin = getSourceOrigin;
|
|
31
31
|
exports.diagnoseAndFixProject = diagnoseAndFixProject;
|
|
32
|
+
exports.ensureInstanceSpec = ensureInstanceSpec;
|
|
32
33
|
const clc = require("colorette");
|
|
33
34
|
const ora = require("ora");
|
|
34
35
|
const semver = require("semver");
|
|
@@ -161,8 +162,7 @@ async function substituteSecretParams(projectNumber, params) {
|
|
|
161
162
|
const newParams = {};
|
|
162
163
|
for await (const [key, value] of Object.entries(params)) {
|
|
163
164
|
if (typeof value !== "string") {
|
|
164
|
-
newParams[key] =
|
|
165
|
-
`projects/${projectNumber}/secrets/${value.name}/versions/latest`;
|
|
165
|
+
newParams[key] = `projects/${projectNumber}/secrets/${value.name}/versions/latest`;
|
|
166
166
|
}
|
|
167
167
|
else {
|
|
168
168
|
newParams[key] = value;
|
|
@@ -870,3 +870,30 @@ async function diagnoseAndFixProject(options) {
|
|
|
870
870
|
throw new error_1.FirebaseError("Unable to proceed until all issues are resolved.");
|
|
871
871
|
}
|
|
872
872
|
}
|
|
873
|
+
async function ensureInstanceSpec(instance) {
|
|
874
|
+
if (instance.config?.source?.spec) {
|
|
875
|
+
return instance;
|
|
876
|
+
}
|
|
877
|
+
const extensionRef = instance.config?.extensionRef ?? instance.extensionRef;
|
|
878
|
+
if (!extensionRef) {
|
|
879
|
+
return instance;
|
|
880
|
+
}
|
|
881
|
+
const ref = refs.parse(extensionRef);
|
|
882
|
+
const extensionVersion = instance.config?.extensionVersion ?? instance.extensionVersion ?? ref.version ?? "latest";
|
|
883
|
+
const extVersion = await (0, publisherApi_1.getExtensionVersion)(`${ref.publisherId}/${ref.extensionId}@${extensionVersion}`);
|
|
884
|
+
return {
|
|
885
|
+
...instance,
|
|
886
|
+
config: {
|
|
887
|
+
...instance.config,
|
|
888
|
+
source: {
|
|
889
|
+
...instance.config?.source,
|
|
890
|
+
name: instance.config?.source?.name ?? extVersion.name,
|
|
891
|
+
state: instance.config?.source?.state ??
|
|
892
|
+
(extVersion.state === "PUBLISHED" ? "ACTIVE" : "STATE_UNSPECIFIED"),
|
|
893
|
+
packageUri: instance.config?.source?.packageUri ?? extVersion.sourceDownloadUri,
|
|
894
|
+
hash: instance.config?.source?.hash ?? extVersion.hash,
|
|
895
|
+
spec: extVersion.spec,
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
};
|
|
899
|
+
}
|
|
@@ -21,6 +21,7 @@ const prompt_1 = require("../prompt");
|
|
|
21
21
|
const paramHelper_1 = require("./paramHelper");
|
|
22
22
|
const error_1 = require("../error");
|
|
23
23
|
const extensionsHelper_1 = require("./extensionsHelper");
|
|
24
|
+
const utils_1 = require("../utils");
|
|
24
25
|
const types_1 = require("./types");
|
|
25
26
|
exports.ENV_DIRECTORY = "extensions";
|
|
26
27
|
async function writeToManifest(specs, config, options, allowOverwrite = false) {
|
|
@@ -99,16 +100,16 @@ function removeFromManifest(instanceId, config) {
|
|
|
99
100
|
extensions[instanceId] = undefined;
|
|
100
101
|
config.set("extensions", extensions);
|
|
101
102
|
config.writeProjectFile("firebase.json", config.src);
|
|
102
|
-
|
|
103
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance ${instanceId} from firebase.json`);
|
|
103
104
|
config.deleteProjectFile(`extensions/${instanceId}.env`);
|
|
104
|
-
|
|
105
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance environment config extensions/${instanceId}.env`);
|
|
105
106
|
if (config.projectFileExists(`extensions/${instanceId}.env.local`)) {
|
|
106
107
|
config.deleteProjectFile(`extensions/${instanceId}.env.local`);
|
|
107
|
-
|
|
108
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance local environment config extensions/${instanceId}.env.local`);
|
|
108
109
|
}
|
|
109
110
|
if (config.projectFileExists(`extensions/${instanceId}.secret.local`)) {
|
|
110
111
|
config.deleteProjectFile(`extensions/${instanceId}.secret.local`);
|
|
111
|
-
|
|
112
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Removed extension instance local secret config extensions/${instanceId}.secret.local`);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
function loadConfig(options) {
|
|
@@ -7,15 +7,23 @@ exports.formatExtensionsTable = formatExtensionsTable;
|
|
|
7
7
|
exports.getMigratableInstances = getMigratableInstances;
|
|
8
8
|
exports.promptInstanceSelection = promptInstanceSelection;
|
|
9
9
|
exports.createMigrationPlan = createMigrationPlan;
|
|
10
|
+
exports.ensureInstanceUpToDate = ensureInstanceUpToDate;
|
|
11
|
+
exports.migrateSecrets = migrateSecrets;
|
|
12
|
+
exports.uninstallExtension = uninstallExtension;
|
|
10
13
|
const clc = require("colorette");
|
|
11
14
|
const Table = require("cli-table3");
|
|
12
15
|
const error_1 = require("../error");
|
|
13
16
|
const logger_1 = require("../logger");
|
|
14
17
|
const utils_1 = require("../utils");
|
|
15
18
|
const extensionsHelper_1 = require("./extensionsHelper");
|
|
16
|
-
const extensionsApi_1 = require("./extensionsApi");
|
|
17
19
|
const prompt_1 = require("../prompt");
|
|
20
|
+
const extensionsApi = require("./extensionsApi");
|
|
21
|
+
const refs = require("./refs");
|
|
22
|
+
const paramHelper = require("./paramHelper");
|
|
23
|
+
const updateHelper = require("./updateHelper");
|
|
18
24
|
const replacements = require("./replacements.json");
|
|
25
|
+
const export_1 = require("./export");
|
|
26
|
+
const manifest = require("./manifest");
|
|
19
27
|
function getKitPackage(extensionRef, packageOverride) {
|
|
20
28
|
if (packageOverride) {
|
|
21
29
|
return packageOverride;
|
|
@@ -101,7 +109,7 @@ async function promptInstanceSelection(migratableInstances, nonInteractive) {
|
|
|
101
109
|
return selected;
|
|
102
110
|
}
|
|
103
111
|
async function createMigrationPlan(projectId, options) {
|
|
104
|
-
const instances = await
|
|
112
|
+
const instances = await extensionsApi.listInstances(projectId);
|
|
105
113
|
if (options.extInstance) {
|
|
106
114
|
const foundInstance = instances.find((inst) => getInstanceId(inst) === options.extInstance);
|
|
107
115
|
if (!foundInstance) {
|
|
@@ -169,3 +177,169 @@ async function createMigrationPlan(projectId, options) {
|
|
|
169
177
|
}
|
|
170
178
|
return promptInstanceSelection(migratable, options.nonInteractive);
|
|
171
179
|
}
|
|
180
|
+
async function fetchOldSpec(instance, rawRef) {
|
|
181
|
+
if (instance.config.source?.spec) {
|
|
182
|
+
return instance.config.source.spec;
|
|
183
|
+
}
|
|
184
|
+
if (!rawRef) {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
const oldVersion = instance.config.extensionVersion;
|
|
189
|
+
const oldVersionRef = rawRef.includes("@")
|
|
190
|
+
? rawRef
|
|
191
|
+
: oldVersion
|
|
192
|
+
? `${rawRef}@${oldVersion}`
|
|
193
|
+
: rawRef;
|
|
194
|
+
logger_1.logger.debug(`[ensureInstanceUpToDate] Fetching oldSpec for ${oldVersionRef}...`);
|
|
195
|
+
const oldExtVersion = await extensionsApi.getExtensionVersion(oldVersionRef);
|
|
196
|
+
return oldExtVersion.spec;
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
logger_1.logger.debug(`Could not fetch old spec for ${rawRef}:`, err);
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function getLatestExtensionVersionNumber(baseRef) {
|
|
204
|
+
try {
|
|
205
|
+
const extInfo = await extensionsApi.getExtension(baseRef);
|
|
206
|
+
return extInfo.latestApprovedVersion || extInfo.latestVersion;
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
logger_1.logger.debug(`Could not fetch extension details for ${baseRef}:`, err);
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
214
|
+
const instanceId = getInstanceId(instance);
|
|
215
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Checking whether extension instance ${clc.bold(instanceId)} is up to date...`);
|
|
216
|
+
const rawRef = getExtensionRef(instance);
|
|
217
|
+
if (!rawRef) {
|
|
218
|
+
return instance;
|
|
219
|
+
}
|
|
220
|
+
let baseRef;
|
|
221
|
+
let currentVersion;
|
|
222
|
+
try {
|
|
223
|
+
const parsed = refs.parse(rawRef);
|
|
224
|
+
baseRef = refs.toExtensionRef(parsed);
|
|
225
|
+
currentVersion = parsed.version || instance.config.source?.spec?.version;
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
logger_1.logger.debug(`[ensureInstanceUpToDate] Could not parse extension reference '${rawRef}':`, err);
|
|
229
|
+
(0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, `Unable to parse extension reference ${clc.bold(rawRef)} to check for available updates.`);
|
|
230
|
+
const shouldContinue = await (0, prompt_1.confirm)({
|
|
231
|
+
message: `Do you want to proceed with migrating instance ${clc.bold(instanceId)} using its current configuration?`,
|
|
232
|
+
default: true,
|
|
233
|
+
nonInteractive: options?.nonInteractive,
|
|
234
|
+
force: options?.force,
|
|
235
|
+
});
|
|
236
|
+
if (!shouldContinue) {
|
|
237
|
+
throw new error_1.FirebaseError("Migration cancelled.");
|
|
238
|
+
}
|
|
239
|
+
return instance;
|
|
240
|
+
}
|
|
241
|
+
if (!currentVersion) {
|
|
242
|
+
return instance;
|
|
243
|
+
}
|
|
244
|
+
const latestVersion = await getLatestExtensionVersionNumber(baseRef);
|
|
245
|
+
if (!latestVersion || currentVersion === latestVersion) {
|
|
246
|
+
return instance;
|
|
247
|
+
}
|
|
248
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Upgrading extension instance ${clc.bold(instanceId)} from version ${clc.bold(currentVersion)} to ${clc.bold(latestVersion)} to ensure a smooth migration...`);
|
|
249
|
+
const targetRef = `${baseRef}@${latestVersion}`;
|
|
250
|
+
let finalParams = {
|
|
251
|
+
...instance.config.params,
|
|
252
|
+
...(instance.config.systemParams ?? {}),
|
|
253
|
+
};
|
|
254
|
+
const newExtensionVersion = await extensionsApi.getExtensionVersion(targetRef);
|
|
255
|
+
const oldSpec = await fetchOldSpec(instance, rawRef);
|
|
256
|
+
if (oldSpec) {
|
|
257
|
+
logger_1.logger.debug(`[ensureInstanceUpToDate] Comparing oldSpec (${oldSpec.version}) with newSpec (${newExtensionVersion.spec.version})...`);
|
|
258
|
+
const paramBindings = await paramHelper.promptForNewParams({
|
|
259
|
+
spec: oldSpec,
|
|
260
|
+
newSpec: newExtensionVersion.spec,
|
|
261
|
+
currentParams: finalParams ?? {},
|
|
262
|
+
projectId,
|
|
263
|
+
instanceId,
|
|
264
|
+
});
|
|
265
|
+
finalParams = paramHelper.getBaseParamBindings(paramBindings);
|
|
266
|
+
logger_1.logger.debug(`[ensureInstanceUpToDate] Resulting finalParams:`, JSON.stringify(finalParams, null, 2));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
logger_1.logger.debug(`[ensureInstanceUpToDate] WARNING: Could not resolve oldSpec for instance ${instanceId}`);
|
|
270
|
+
}
|
|
271
|
+
if (finalParams["LOCATION"] && !finalParams["firebaseextensions.v1beta.function/location"]) {
|
|
272
|
+
finalParams["firebaseextensions.v1beta.function/location"] = finalParams["LOCATION"];
|
|
273
|
+
}
|
|
274
|
+
const { params, systemParams } = paramHelper.partitionParams(finalParams);
|
|
275
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Updating instance ${clc.bold(instanceId)}...`);
|
|
276
|
+
try {
|
|
277
|
+
await updateHelper.update({
|
|
278
|
+
projectId,
|
|
279
|
+
instanceId,
|
|
280
|
+
extRef: targetRef,
|
|
281
|
+
canEmitEvents: Boolean(instance.config.allowedEventTypes?.length),
|
|
282
|
+
allowedEventTypes: instance.config.allowedEventTypes,
|
|
283
|
+
eventarcChannel: instance.config.eventarcChannel,
|
|
284
|
+
params,
|
|
285
|
+
systemParams,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
290
|
+
throw new error_1.FirebaseError(`Failed to automatically upgrade extension instance ${instanceId} to version ${latestVersion}: ${message}. Please upgrade your extension instance manually using 'firebase ext:update ${instanceId}' before attempting migration.`, { original: err instanceof Error ? err : undefined });
|
|
291
|
+
}
|
|
292
|
+
const updatedInstance = await extensionsApi.getInstance(projectId, instanceId);
|
|
293
|
+
return updatedInstance ?? instance;
|
|
294
|
+
}
|
|
295
|
+
async function migrateSecrets(instance, options) {
|
|
296
|
+
const secrets = await (0, export_1.secretsNeedingEjection)(instance);
|
|
297
|
+
if (secrets.length === 0) {
|
|
298
|
+
return [];
|
|
299
|
+
}
|
|
300
|
+
const instanceId = getInstanceId(instance);
|
|
301
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Transferring secrets for instance ${clc.bold(instanceId)} to Functions management...`);
|
|
302
|
+
const results = await (0, export_1.ejectSecretsFromInstance)(instance);
|
|
303
|
+
if (results.success.length > 0) {
|
|
304
|
+
(0, utils_1.logLabeledSuccess)(extensionsHelper_1.logPrefix, `Successfully transferred secrets to Functions management: ${results.success.join(", ")}`);
|
|
305
|
+
}
|
|
306
|
+
if (results.fail.length > 0) {
|
|
307
|
+
const resultMsg = `${results.fail.length} secrets failed to update: ${results.fail.join(", ")}.`;
|
|
308
|
+
(0, utils_1.logLabeledError)("functions", resultMsg);
|
|
309
|
+
(0, utils_1.logLabeledError)("functions", "Ensure you have Secret Manager Admin (roles/secretmanager.admin) permissions to transfer secrets.");
|
|
310
|
+
if (!options?.force) {
|
|
311
|
+
throw new error_1.FirebaseError("Secret migration failed.", { exit: 1 });
|
|
312
|
+
}
|
|
313
|
+
(0, utils_1.logLabeledWarning)("functions", "Proceeding after secret migration failure in --force mode. Manually remove the 'firebase-extensions-managed' label from the secrets before running ext:uninstall, or risk permanent data loss.");
|
|
314
|
+
}
|
|
315
|
+
return results.success;
|
|
316
|
+
}
|
|
317
|
+
async function uninstallExtension(projectId, instanceId, options, skipConfirm = false) {
|
|
318
|
+
if (!skipConfirm &&
|
|
319
|
+
!(await (0, prompt_1.confirm)({
|
|
320
|
+
message: `About to delete Extensions instance ${projectId}/${instanceId}, its associated resources, and service account. Continue?`,
|
|
321
|
+
nonInteractive: options.nonInteractive,
|
|
322
|
+
force: options.force,
|
|
323
|
+
default: true,
|
|
324
|
+
}))) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
let config;
|
|
328
|
+
try {
|
|
329
|
+
config = manifest.loadConfig(options);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, "No firebase.json found. Proceeding to immediate extension instance teardown.");
|
|
333
|
+
}
|
|
334
|
+
if (config && manifest.instanceExists(instanceId, config)) {
|
|
335
|
+
manifest.removeFromManifest(instanceId, config);
|
|
336
|
+
}
|
|
337
|
+
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Uninstalling extension instance ${clc.bold(instanceId)}...`);
|
|
338
|
+
try {
|
|
339
|
+
await extensionsApi.deleteInstance(projectId, instanceId);
|
|
340
|
+
}
|
|
341
|
+
catch (err) {
|
|
342
|
+
throw new error_1.FirebaseError(`Error when attempting deletion: ${err instanceof Error ? err.message : String(err)}`, { original: err instanceof Error ? err : undefined });
|
|
343
|
+
}
|
|
344
|
+
(0, utils_1.logLabeledSuccess)(extensionsHelper_1.logPrefix, `Deleted Extensions instance ${projectId}/${instanceId}.`);
|
|
345
|
+
}
|