firebase-tools-with-isolate 15.27.0 → 15.28.1
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/commands/ext-export.js +85 -20
- package/lib/commands/ext-uninstall.js +35 -1
- package/lib/commands/functions-delete.js +19 -5
- package/lib/commands/functions-kits-install.js +228 -105
- package/lib/commands/functions-kits-list.js +27 -0
- package/lib/commands/index.js +1 -0
- package/lib/dataconnect/client.js +11 -0
- package/lib/dataconnect/schemaMigration.js +16 -5
- package/lib/deploy/extensions/secrets.js +18 -0
- package/lib/deploy/functions/functionsDeployHelper.js +39 -15
- package/lib/deploy/functions/prepare.js +43 -9
- package/lib/deploy/functions/runtimes/dart/features.js +51 -0
- package/lib/deploy/functions/runtimes/dart/index.js +60 -16
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/functionsEmulator.js +4 -1
- package/lib/experiments.js +6 -0
- package/lib/extensions/export.js +26 -0
- package/lib/extensions/replacementRegistry.js +30 -0
- package/lib/extensions/replacements.json +464 -0
- package/lib/fetchMOTD.js +3 -0
- package/lib/functions/env.js +11 -0
- package/lib/functions/iac/export.js +16 -1
- package/lib/functions/kits/config.js +8 -0
- package/lib/gcp/secretManager.js +3 -3
- package/lib/init/features/functions/dart.js +1 -1
- package/lib/mcp/tools/core/deploy.js +2 -0
- package/lib/mcp/tools/core/login.js +59 -4
- package/lib/mcp/tools/dataconnect/compile.js +23 -2
- package/lib/mcp/tools/dataconnect/list_services.js +3 -4
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/unzip.js +12 -2
- package/package.json +2 -1
- package/templates/init/functions/dart/_gitignore +1 -0
- package/templates/init/functions/typescript/index.ts +3 -3
- package/templates/init/functions/typescript/package-ongraphrequest.lint.json +3 -3
- package/templates/init/functions/typescript/package.lint.json +3 -3
- package/templates/init/functions/typescript/tsconfig.dev.json +4 -0
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.command = void 0;
|
|
3
|
+
exports.command = exports.FUNCTION_KITS_DIR = exports.DEFAULT_TEMPLATE = exports.TEMPLATES = void 0;
|
|
4
4
|
exports.generateUniqueId = generateUniqueId;
|
|
5
5
|
exports.parseNpmPackageSpecifier = parseNpmPackageSpecifier;
|
|
6
6
|
exports.validateNpmPackageName = validateNpmPackageName;
|
|
7
7
|
exports.sanitizePackageNameToKitName = sanitizePackageNameToKitName;
|
|
8
8
|
exports.isThirdPartyPackage = isThirdPartyPackage;
|
|
9
9
|
exports.checkPackageHasShrinkwrap = checkPackageHasShrinkwrap;
|
|
10
|
+
exports.isKitConfiguredForProject = isKitConfiguredForProject;
|
|
11
|
+
exports.extractExistingFunctionsInfo = extractExistingFunctionsInfo;
|
|
12
|
+
exports.promptKitInstanceId = promptKitInstanceId;
|
|
13
|
+
exports.promptKitId = promptKitId;
|
|
14
|
+
exports.promptSecurityConfirmation = promptSecurityConfirmation;
|
|
15
|
+
exports.promptExistingInstanceForProject = promptExistingInstanceForProject;
|
|
16
|
+
exports.addKitInstanceOrConfigureProject = addKitInstanceOrConfigureProject;
|
|
17
|
+
exports.scaffoldKitFiles = scaffoldKitFiles;
|
|
18
|
+
exports.buildAndInstallKit = buildAndInstallKit;
|
|
19
|
+
exports.addKitToConfig = addKitToConfig;
|
|
10
20
|
const clc = require("colorette");
|
|
11
21
|
const crypto = require("crypto");
|
|
12
22
|
const path = require("path");
|
|
13
23
|
const fs = require("fs-extra");
|
|
14
24
|
const command_1 = require("../command");
|
|
15
25
|
const error_1 = require("../error");
|
|
26
|
+
const projectUtils_1 = require("../projectUtils");
|
|
27
|
+
const utils_1 = require("../utils");
|
|
16
28
|
const projectConfig_1 = require("../functions/projectConfig");
|
|
17
29
|
const experiments = require("../experiments");
|
|
18
30
|
const logger_1 = require("../logger");
|
|
@@ -20,17 +32,19 @@ const prompt_1 = require("../prompt");
|
|
|
20
32
|
const spawn_1 = require("../init/spawn");
|
|
21
33
|
const templates_1 = require("../templates");
|
|
22
34
|
const supported = require("../deploy/functions/runtimes/supported");
|
|
35
|
+
const env_1 = require("../functions/env");
|
|
23
36
|
const self = require("./functions-kits-install");
|
|
24
37
|
const PACKAGE_NO_LINTING_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/package.nolint.json");
|
|
25
38
|
const TSCONFIG_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/tsconfig.json");
|
|
26
39
|
const GITIGNORE_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/_gitignore");
|
|
27
40
|
const INDEX_KIT_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/index-kit.ts");
|
|
28
41
|
const INDEX_KIT_MIGRATION_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/index-kit-migration.ts");
|
|
29
|
-
|
|
42
|
+
exports.TEMPLATES = {
|
|
30
43
|
installation: INDEX_KIT_TEMPLATE,
|
|
31
44
|
migration: INDEX_KIT_MIGRATION_TEMPLATE,
|
|
32
45
|
};
|
|
33
|
-
|
|
46
|
+
exports.DEFAULT_TEMPLATE = "installation";
|
|
47
|
+
exports.FUNCTION_KITS_DIR = "function-kits";
|
|
34
48
|
function generateUniqueId(baseId, existingIds) {
|
|
35
49
|
if (!existingIds.has(baseId)) {
|
|
36
50
|
return baseId;
|
|
@@ -87,63 +101,13 @@ async function checkPackageHasShrinkwrap(rawPkgName) {
|
|
|
87
101
|
}
|
|
88
102
|
return false;
|
|
89
103
|
}
|
|
90
|
-
|
|
91
|
-
.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
throw new error_1.FirebaseError("Not in a Firebase project directory (firebase.json not found).");
|
|
98
|
-
}
|
|
99
|
-
const templateType = options.template || "installation";
|
|
100
|
-
if (!(templateType in TEMPLATES)) {
|
|
101
|
-
throw new error_1.FirebaseError(`Invalid template '${templateType}'. Template must be 'installation' or 'migration'.`);
|
|
102
|
-
}
|
|
103
|
-
const rawPkgName = options.npm_package;
|
|
104
|
-
if (!rawPkgName) {
|
|
105
|
-
throw new error_1.FirebaseError("set the --npm_package option to a valid NPM package and try again.");
|
|
106
|
-
}
|
|
107
|
-
const { packageName, version } = parseNpmPackageSpecifier(rawPkgName);
|
|
108
|
-
validateNpmPackageName(packageName);
|
|
109
|
-
const isThirdParty = isThirdPartyPackage(packageName);
|
|
110
|
-
if (isThirdParty) {
|
|
111
|
-
logger_1.logger.warn(clc.yellow(`Warning: Package ${clc.bold(packageName)} is a third-party kit (outside the @firebase-functions-kits scope).`));
|
|
112
|
-
}
|
|
113
|
-
const hasShrinkwrap = await self.checkPackageHasShrinkwrap(rawPkgName);
|
|
114
|
-
if (!hasShrinkwrap) {
|
|
115
|
-
logger_1.logger.warn(clc.yellow(`Warning: Package ${clc.bold(packageName)} does not have an npm-shrinkwrap.json file. npm-shrinkwrap guarantees that you deploy the same version of dependencies that the publisher tested against. Since this kit does not have an npm-shrinkwrap, it is possible that deploys or updates may introduce bugs or vulnerabilities in newer dependency versions that the publisher did not test against.`));
|
|
116
|
-
}
|
|
117
|
-
if (isThirdParty || !hasShrinkwrap) {
|
|
118
|
-
let confirmMessage;
|
|
119
|
-
if (isThirdParty && !hasShrinkwrap) {
|
|
120
|
-
confirmMessage = `Are you sure you want to install the third-party kit ${packageName} without locked dependencies?`;
|
|
121
|
-
}
|
|
122
|
-
else if (isThirdParty) {
|
|
123
|
-
confirmMessage = `Are you sure you want to install the third-party kit ${packageName}?`;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
confirmMessage = `Are you sure you want to install ${packageName} without locked dependencies?`;
|
|
127
|
-
}
|
|
128
|
-
const confirmInstallation = await (0, prompt_1.confirm)({
|
|
129
|
-
message: confirmMessage,
|
|
130
|
-
default: false,
|
|
131
|
-
nonInteractive: options.nonInteractive,
|
|
132
|
-
});
|
|
133
|
-
if (!confirmInstallation) {
|
|
134
|
-
throw new error_1.FirebaseError("Installation cancelled.");
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
let existingFunctions = [];
|
|
138
|
-
const configFunctions = options.config.src.functions;
|
|
139
|
-
if (configFunctions && (!Array.isArray(configFunctions) || configFunctions.length > 0)) {
|
|
140
|
-
try {
|
|
141
|
-
existingFunctions = (0, projectConfig_1.normalizeAndValidate)(configFunctions);
|
|
142
|
-
}
|
|
143
|
-
catch (err) {
|
|
144
|
-
throw new error_1.FirebaseError(`Invalid existing functions configuration: ${(0, error_1.getErrMsg)(err)}`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
104
|
+
function isKitConfiguredForProject(config, kit, projectId, projectAlias) {
|
|
105
|
+
return Object.values(kit.instances || {}).some((configDir) => (0, env_1.hasProjectEnv)(config.path(configDir), projectId, projectAlias));
|
|
106
|
+
}
|
|
107
|
+
function extractExistingFunctionsInfo(configFunctions) {
|
|
108
|
+
const existingFunctions = configFunctions && (!Array.isArray(configFunctions) || configFunctions.length > 0)
|
|
109
|
+
? (0, projectConfig_1.normalizeAndValidate)(configFunctions)
|
|
110
|
+
: [];
|
|
147
111
|
const existingKitIds = new Set();
|
|
148
112
|
const existingCodebases = new Set();
|
|
149
113
|
const existingInstanceIds = new Set();
|
|
@@ -162,35 +126,20 @@ exports.command = new command_1.Command("functions:kits:install")
|
|
|
162
126
|
existingCodebases.add(c.codebase);
|
|
163
127
|
}
|
|
164
128
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
(0, projectConfig_1.validateKit)(val);
|
|
174
|
-
}
|
|
175
|
-
catch (err) {
|
|
176
|
-
return (0, error_1.getErrMsg)(err);
|
|
177
|
-
}
|
|
178
|
-
if (existingKitIds.has(val)) {
|
|
179
|
-
return `functions.kit must be unique but '${val}' was used more than once.`;
|
|
180
|
-
}
|
|
181
|
-
return true;
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
(0, projectConfig_1.validateKit)(kitId);
|
|
185
|
-
if (existingKitIds.has(kitId)) {
|
|
186
|
-
throw new error_1.FirebaseError(`functions.kit must be unique but '${kitId}' was used more than once.`);
|
|
187
|
-
}
|
|
129
|
+
return {
|
|
130
|
+
existingFunctions,
|
|
131
|
+
existingKitIds,
|
|
132
|
+
existingCodebases,
|
|
133
|
+
existingInstanceIds,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async function promptKitInstanceId(baseKitId, existingInstanceIds, existingCodebases, nonInteractive) {
|
|
188
137
|
const instanceCollisions = new Set([...existingInstanceIds, ...existingCodebases]);
|
|
189
|
-
const defaultInstanceId = generateUniqueId(
|
|
138
|
+
const defaultInstanceId = generateUniqueId(baseKitId, instanceCollisions);
|
|
190
139
|
const instanceId = await (0, prompt_1.input)({
|
|
191
140
|
message: "What would you like to name this instance?",
|
|
192
141
|
default: defaultInstanceId,
|
|
193
|
-
nonInteractive
|
|
142
|
+
nonInteractive,
|
|
194
143
|
validate: (val) => {
|
|
195
144
|
try {
|
|
196
145
|
(0, projectConfig_1.validateKitInstanceId)(val);
|
|
@@ -214,14 +163,134 @@ exports.command = new command_1.Command("functions:kits:install")
|
|
|
214
163
|
if (existingCodebases.has(instanceId)) {
|
|
215
164
|
throw new error_1.FirebaseError(`functions codebase name and kit instance ID must be mutually exclusive, but '${instanceId}' was used as both a codebase name and a kit instance ID.`);
|
|
216
165
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
166
|
+
return instanceId;
|
|
167
|
+
}
|
|
168
|
+
async function promptKitId(packageName, existingKitIds, nonInteractive) {
|
|
169
|
+
const baseKitId = sanitizePackageNameToKitName(packageName);
|
|
170
|
+
const defaultKitId = generateUniqueId(baseKitId, existingKitIds);
|
|
171
|
+
const kitId = await (0, prompt_1.input)({
|
|
172
|
+
message: "What would you like to name this kit?",
|
|
173
|
+
default: defaultKitId,
|
|
174
|
+
nonInteractive,
|
|
175
|
+
validate: (val) => {
|
|
176
|
+
try {
|
|
177
|
+
(0, projectConfig_1.validateKit)(val);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
return (0, error_1.getErrMsg)(err);
|
|
181
|
+
}
|
|
182
|
+
if (existingKitIds.has(val)) {
|
|
183
|
+
return `functions.kit must be unique but '${val}' was used more than once.`;
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
(0, projectConfig_1.validateKit)(kitId);
|
|
189
|
+
if (existingKitIds.has(kitId)) {
|
|
190
|
+
throw new error_1.FirebaseError(`functions.kit must be unique but '${kitId}' was used more than once.`);
|
|
191
|
+
}
|
|
192
|
+
return kitId;
|
|
193
|
+
}
|
|
194
|
+
async function promptSecurityConfirmation(rawPkgName, packageName, nonInteractive) {
|
|
195
|
+
const isThirdParty = isThirdPartyPackage(packageName);
|
|
196
|
+
if (isThirdParty) {
|
|
197
|
+
(0, utils_1.logLabeledWarning)("functions", `Package ${clc.bold(packageName)} is a third-party kit (outside the @firebase-functions-kits scope).`);
|
|
198
|
+
}
|
|
199
|
+
const hasShrinkwrap = await self.checkPackageHasShrinkwrap(rawPkgName);
|
|
200
|
+
if (!hasShrinkwrap) {
|
|
201
|
+
(0, utils_1.logLabeledWarning)("functions", `Package ${clc.bold(packageName)} does not have an npm-shrinkwrap.json file. npm-shrinkwrap guarantees that you deploy the same version of dependencies that the publisher tested against. Since this kit does not have an npm-shrinkwrap, it is possible that deploys or updates may introduce bugs or vulnerabilities in newer dependency versions that the publisher did not test against.`);
|
|
202
|
+
}
|
|
203
|
+
if (isThirdParty || !hasShrinkwrap) {
|
|
204
|
+
let confirmMessage;
|
|
205
|
+
if (isThirdParty && !hasShrinkwrap) {
|
|
206
|
+
confirmMessage = `Are you sure you want to install the third-party kit ${packageName} without locked dependencies?`;
|
|
207
|
+
}
|
|
208
|
+
else if (isThirdParty) {
|
|
209
|
+
confirmMessage = `Are you sure you want to install the third-party kit ${packageName}?`;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
confirmMessage = `Are you sure you want to install ${packageName} without locked dependencies?`;
|
|
213
|
+
}
|
|
214
|
+
const confirmInstallation = await (0, prompt_1.confirm)({
|
|
215
|
+
message: confirmMessage,
|
|
216
|
+
default: false,
|
|
217
|
+
nonInteractive,
|
|
218
|
+
});
|
|
219
|
+
if (!confirmInstallation) {
|
|
220
|
+
throw new error_1.FirebaseError("Installation cancelled.");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return isThirdParty;
|
|
224
|
+
}
|
|
225
|
+
async function addInstanceToExistingKit(options, existingKit, existingFunctionsInfo) {
|
|
226
|
+
const instanceId = await promptKitInstanceId(existingKit.kit, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive);
|
|
227
|
+
const configDirPath = path.join(exports.FUNCTION_KITS_DIR, existingKit.kit, `config-${instanceId}`);
|
|
220
228
|
const absConfigDirPath = options.config.path(configDirPath);
|
|
221
|
-
await fs.ensureDir(absSourcePath);
|
|
222
229
|
await fs.ensureDir(absConfigDirPath);
|
|
230
|
+
existingKit.instances[instanceId] = configDirPath;
|
|
231
|
+
options.config.writeProjectFile("firebase.json", options.config.src);
|
|
232
|
+
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully added to kit ${clc.bold(existingKit.kit)}.`);
|
|
233
|
+
}
|
|
234
|
+
async function promptExistingInstanceForProject(options, existingKit) {
|
|
235
|
+
const instanceIds = Object.keys(existingKit.instances);
|
|
236
|
+
if (instanceIds.length === 0) {
|
|
237
|
+
throw new error_1.FirebaseError(`Kit '${existingKit.kit}' has no instances configured.`);
|
|
238
|
+
}
|
|
239
|
+
let selectedInstanceId = "<instance-name>";
|
|
240
|
+
if (instanceIds.length === 1) {
|
|
241
|
+
selectedInstanceId = instanceIds[0];
|
|
242
|
+
}
|
|
243
|
+
else if (!options.nonInteractive) {
|
|
244
|
+
selectedInstanceId = await (0, prompt_1.select)({
|
|
245
|
+
message: "Which instance would you like to configure for this project?",
|
|
246
|
+
choices: instanceIds.map((id) => ({ name: id, value: id })),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const targetProject = (0, projectUtils_1.getProjectId)(options) || options.project || "<project-name>";
|
|
250
|
+
(0, utils_1.logLabeledBullet)("functions", `To create a new instance in this project, deploy the instance dedicated to this project using\n` +
|
|
251
|
+
clc.bold(`firebase deploy --only functions:${selectedInstanceId} --project ${targetProject}`));
|
|
252
|
+
}
|
|
253
|
+
async function addKitInstanceOrConfigureProject(options, existingKit, existingFunctionsInfo) {
|
|
254
|
+
const projectId = (0, projectUtils_1.getProjectId)(options);
|
|
255
|
+
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
256
|
+
? options.project
|
|
257
|
+
: undefined;
|
|
258
|
+
const isConfiguredForProject = isKitConfiguredForProject(options.config, existingKit, projectId, projectAlias);
|
|
259
|
+
let action;
|
|
260
|
+
if (!isConfiguredForProject && !options.nonInteractive) {
|
|
261
|
+
const existingInstances = Object.keys(existingKit.instances || {}).join(", ");
|
|
262
|
+
action = await (0, prompt_1.select)({
|
|
263
|
+
message: `The following instances already exist, but are not configured for this project: ${existingInstances}. What would you like to do?`,
|
|
264
|
+
choices: [
|
|
265
|
+
{
|
|
266
|
+
name: "Add an instance to the existing kit",
|
|
267
|
+
value: "addInstance",
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: "Configure an existing instance for this project",
|
|
271
|
+
value: "addEnv",
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
if (isConfiguredForProject) {
|
|
278
|
+
(0, utils_1.logLabeledBullet)("functions", `This package is already installed as kit ${existingKit.kit}, creating a new instance.`);
|
|
279
|
+
}
|
|
280
|
+
action = "addInstance";
|
|
281
|
+
}
|
|
282
|
+
if (action === "addInstance") {
|
|
283
|
+
await addInstanceToExistingKit(options, existingKit, existingFunctionsInfo);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (action === "addEnv") {
|
|
287
|
+
await promptExistingInstanceForProject(options, existingKit);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
async function writeKitPackageJson(config, sourcePath, kitId, packageName, version) {
|
|
223
292
|
const relPackageJsonPath = path.join(sourcePath, "package.json");
|
|
224
|
-
const absPackageJsonPath =
|
|
293
|
+
const absPackageJsonPath = config.path(relPackageJsonPath);
|
|
225
294
|
let pkgJson = {};
|
|
226
295
|
if (await fs.pathExists(absPackageJsonPath)) {
|
|
227
296
|
try {
|
|
@@ -244,31 +313,49 @@ exports.command = new command_1.Command("functions:kits:install")
|
|
|
244
313
|
pkgJson.name = `${kitId}-wrapper`;
|
|
245
314
|
pkgJson.dependencies = pkgJson.dependencies || {};
|
|
246
315
|
pkgJson.dependencies[packageName] = version || "latest";
|
|
247
|
-
await
|
|
248
|
-
|
|
249
|
-
|
|
316
|
+
await config.askWriteProjectFile(relPackageJsonPath, pkgJson);
|
|
317
|
+
}
|
|
318
|
+
async function writeKitIndexTs(config, sourcePath, packageName, templateType) {
|
|
250
319
|
const relIndexTsPath = path.join(sourcePath, "src", "index.ts");
|
|
251
|
-
const absIndexTsPath =
|
|
320
|
+
const absIndexTsPath = config.path(relIndexTsPath);
|
|
252
321
|
if (!(await fs.pathExists(absIndexTsPath))) {
|
|
253
|
-
const template = templateType
|
|
322
|
+
const template = exports.TEMPLATES[templateType];
|
|
254
323
|
const indexContent = template.replace("{{PACKAGE_NAME}}", packageName);
|
|
255
|
-
await
|
|
324
|
+
await config.askWriteProjectFile(relIndexTsPath, indexContent);
|
|
256
325
|
}
|
|
326
|
+
}
|
|
327
|
+
async function scaffoldKitFiles(config, kitId, instanceId, packageName, version, templateType = exports.DEFAULT_TEMPLATE) {
|
|
328
|
+
const sourcePath = path.join(exports.FUNCTION_KITS_DIR, kitId, "source");
|
|
329
|
+
const configDirPath = path.join(exports.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
330
|
+
const absSourcePath = config.path(sourcePath);
|
|
331
|
+
const absConfigDirPath = config.path(configDirPath);
|
|
332
|
+
await fs.ensureDir(absSourcePath);
|
|
333
|
+
await fs.ensureDir(absConfigDirPath);
|
|
334
|
+
await writeKitPackageJson(config, sourcePath, kitId, packageName, version);
|
|
335
|
+
await config.askWriteProjectFile(path.join(sourcePath, "tsconfig.json"), TSCONFIG_TEMPLATE);
|
|
336
|
+
await config.askWriteProjectFile(path.join(sourcePath, ".gitignore"), GITIGNORE_TEMPLATE);
|
|
337
|
+
await writeKitIndexTs(config, sourcePath, packageName, templateType);
|
|
338
|
+
return { sourcePath, configDirPath, absSourcePath };
|
|
339
|
+
}
|
|
340
|
+
async function buildAndInstallKit(absSourcePath, isThirdParty) {
|
|
257
341
|
const installArgs = isThirdParty ? ["install", "--ignore-scripts"] : ["install"];
|
|
258
|
-
|
|
342
|
+
(0, utils_1.logLabeledBullet)("functions", `Running npm ${installArgs.join(" ")}...`);
|
|
259
343
|
try {
|
|
260
344
|
await (0, spawn_1.wrapSpawn)("npm", installArgs, absSourcePath);
|
|
261
345
|
}
|
|
262
346
|
catch (err) {
|
|
263
347
|
throw new error_1.FirebaseError(`NPM install failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
264
348
|
}
|
|
265
|
-
|
|
349
|
+
(0, utils_1.logLabeledBullet)("functions", "Building TypeScript source...");
|
|
266
350
|
try {
|
|
267
351
|
await (0, spawn_1.wrapSpawn)("npm", ["run", "build"], absSourcePath);
|
|
268
352
|
}
|
|
269
353
|
catch (err) {
|
|
270
354
|
throw new error_1.FirebaseError(`TypeScript build failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
271
355
|
}
|
|
356
|
+
}
|
|
357
|
+
function addKitToConfig(config, kitId, instanceId, packageName, sourcePath, configDirPath) {
|
|
358
|
+
const configSrc = config.src;
|
|
272
359
|
const newKitConfig = {
|
|
273
360
|
kit: kitId,
|
|
274
361
|
sourcePackage: {
|
|
@@ -280,15 +367,51 @@ exports.command = new command_1.Command("functions:kits:install")
|
|
|
280
367
|
},
|
|
281
368
|
predeploy: ['npm --prefix "$RESOURCE_DIR" run build'],
|
|
282
369
|
};
|
|
283
|
-
|
|
284
|
-
|
|
370
|
+
const functionsRaw = configSrc.functions;
|
|
371
|
+
if (!functionsRaw) {
|
|
372
|
+
configSrc.functions = [newKitConfig];
|
|
285
373
|
}
|
|
286
|
-
else if (Array.isArray(
|
|
287
|
-
|
|
374
|
+
else if (Array.isArray(functionsRaw)) {
|
|
375
|
+
functionsRaw.push(newKitConfig);
|
|
288
376
|
}
|
|
289
377
|
else {
|
|
290
|
-
|
|
378
|
+
configSrc.functions = [functionsRaw, newKitConfig];
|
|
291
379
|
}
|
|
292
|
-
|
|
293
|
-
|
|
380
|
+
config.writeProjectFile("firebase.json", configSrc);
|
|
381
|
+
}
|
|
382
|
+
exports.command = new command_1.Command("functions:kits:install")
|
|
383
|
+
.description("install a function kit into your project")
|
|
384
|
+
.option("--npm_package <package>", "NPM package name or specifier to install as a function kit")
|
|
385
|
+
.option(`--template [${Object.keys(exports.TEMPLATES).join("|")}]`, "template to use for the kit index file", exports.DEFAULT_TEMPLATE)
|
|
386
|
+
.action(async (options) => {
|
|
387
|
+
experiments.assertEnabled("kits", "install a function kit");
|
|
388
|
+
if (!options.config) {
|
|
389
|
+
throw new error_1.FirebaseError("Not in a Firebase project directory (firebase.json not found).");
|
|
390
|
+
}
|
|
391
|
+
const templateType = (options.template || exports.DEFAULT_TEMPLATE);
|
|
392
|
+
if (!(templateType in exports.TEMPLATES)) {
|
|
393
|
+
const validTemplates = Object.keys(exports.TEMPLATES)
|
|
394
|
+
.map((t) => `'${t}'`)
|
|
395
|
+
.join(" or ");
|
|
396
|
+
throw new error_1.FirebaseError(`Invalid template '${templateType}'. Template must be ${validTemplates}.`);
|
|
397
|
+
}
|
|
398
|
+
const rawPkgName = options.npm_package;
|
|
399
|
+
if (!rawPkgName) {
|
|
400
|
+
throw new error_1.FirebaseError("set the --npm_package option to a valid NPM package and try again.");
|
|
401
|
+
}
|
|
402
|
+
const { packageName, version } = parseNpmPackageSpecifier(rawPkgName);
|
|
403
|
+
validateNpmPackageName(packageName);
|
|
404
|
+
const existingFunctionsInfo = extractExistingFunctionsInfo(options.config.src.functions);
|
|
405
|
+
const existingKit = existingFunctionsInfo.existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) && c.sourcePackage?.name === packageName);
|
|
406
|
+
if (existingKit) {
|
|
407
|
+
await addKitInstanceOrConfigureProject(options, existingKit, existingFunctionsInfo);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const isThirdParty = await promptSecurityConfirmation(rawPkgName, packageName, options.nonInteractive);
|
|
411
|
+
const kitId = await promptKitId(packageName, existingFunctionsInfo.existingKitIds, options.nonInteractive);
|
|
412
|
+
const instanceId = await promptKitInstanceId(kitId, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive);
|
|
413
|
+
const { sourcePath, configDirPath, absSourcePath } = await scaffoldKitFiles(options.config, kitId, instanceId, packageName, version, templateType);
|
|
414
|
+
await buildAndInstallKit(absSourcePath, isThirdParty);
|
|
415
|
+
addKitToConfig(options.config, kitId, instanceId, packageName, sourcePath, configDirPath);
|
|
416
|
+
(0, utils_1.logLabeledSuccess)("functions", `Function kit ${clc.bold(kitId)} successfully installed.`);
|
|
294
417
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const requireConfig_1 = require("../requireConfig");
|
|
5
|
+
const command_1 = require("../command");
|
|
6
|
+
const config_1 = require("../functions/kits/config");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const logger_1 = require("../logger");
|
|
9
|
+
const Table = require("cli-table3");
|
|
10
|
+
exports.command = new command_1.Command("functions:kits:list")
|
|
11
|
+
.description("list all the kits that are installed in your firebase.json")
|
|
12
|
+
.before(requireConfig_1.requireConfig)
|
|
13
|
+
.action((options) => {
|
|
14
|
+
const firebaseConfig = options.config;
|
|
15
|
+
const validatedConfig = firebaseConfig.src;
|
|
16
|
+
const kitConfigs = (0, config_1.listKitConfigs)(validatedConfig);
|
|
17
|
+
if (kitConfigs.length < 1) {
|
|
18
|
+
(0, utils_1.logLabeledBullet)("functions", `there are no kits in firebase.json`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const table = new Table({ head: ["Kit", "Instances"], style: { head: ["yellow"] } });
|
|
22
|
+
for (const kitConfig of kitConfigs) {
|
|
23
|
+
const instanceIds = Object.keys(kitConfig.instances);
|
|
24
|
+
table.push([kitConfig.kit, instanceIds.join(", ")]);
|
|
25
|
+
}
|
|
26
|
+
logger_1.logger.info(table.toString());
|
|
27
|
+
});
|
package/lib/commands/index.js
CHANGED
|
@@ -188,6 +188,7 @@ function load(client) {
|
|
|
188
188
|
if (experiments.isEnabled("kits")) {
|
|
189
189
|
client.functions.kits = {};
|
|
190
190
|
client.functions.kits.install = loadCommand("functions-kits-install");
|
|
191
|
+
client.functions.kits.list = loadCommand("functions-kits-list");
|
|
191
192
|
}
|
|
192
193
|
client.help = loadCommand("help");
|
|
193
194
|
client.hosting = {};
|
|
@@ -13,6 +13,7 @@ exports.getConnector = getConnector;
|
|
|
13
13
|
exports.deleteConnector = deleteConnector;
|
|
14
14
|
exports.listConnectors = listConnectors;
|
|
15
15
|
exports.upsertConnector = upsertConnector;
|
|
16
|
+
exports.executeSchemaMigration = executeSchemaMigration;
|
|
16
17
|
const api_1 = require("../api");
|
|
17
18
|
const apiv2_1 = require("../apiv2");
|
|
18
19
|
const operationPoller = require("../operation-poller");
|
|
@@ -167,3 +168,13 @@ async function upsertConnector(connector) {
|
|
|
167
168
|
});
|
|
168
169
|
return pollRes;
|
|
169
170
|
}
|
|
171
|
+
async function executeSchemaMigration(serviceName, diffs) {
|
|
172
|
+
const client = dataconnectClient();
|
|
173
|
+
const op = await client.post(`${serviceName}/schemas/main:migrate`, { diffs });
|
|
174
|
+
await operationPoller.pollOperation({
|
|
175
|
+
apiOrigin: (0, api_1.dataconnectOrigin)(),
|
|
176
|
+
apiVersion: DATACONNECT_API_VERSION,
|
|
177
|
+
operationResourceName: op.body.name,
|
|
178
|
+
masterTimeout: 300000,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
@@ -6,7 +6,9 @@ exports.upsertSecondarySchema = upsertSecondarySchema;
|
|
|
6
6
|
exports.grantRoleToUserInSchema = grantRoleToUserInSchema;
|
|
7
7
|
exports.getIdentifiers = getIdentifiers;
|
|
8
8
|
exports.serviceNameFromSchema = serviceNameFromSchema;
|
|
9
|
+
exports.handleIncompatibleSchemaError = handleIncompatibleSchemaError;
|
|
9
10
|
exports.ensureServiceIsConnectedToCloudSql = ensureServiceIsConnectedToCloudSql;
|
|
11
|
+
const experiments = require("../experiments");
|
|
10
12
|
const clc = require("colorette");
|
|
11
13
|
const sql_formatter_1 = require("sql-formatter");
|
|
12
14
|
const types_1 = require("./types");
|
|
@@ -169,6 +171,7 @@ async function migrateSchema(args) {
|
|
|
169
171
|
databaseId,
|
|
170
172
|
instanceId,
|
|
171
173
|
schemaName,
|
|
174
|
+
schema,
|
|
172
175
|
incompatibleSchemaError: incompatible,
|
|
173
176
|
choice: migrationMode,
|
|
174
177
|
});
|
|
@@ -204,6 +207,7 @@ async function migrateSchema(args) {
|
|
|
204
207
|
databaseId,
|
|
205
208
|
instanceId,
|
|
206
209
|
schemaName,
|
|
210
|
+
schema,
|
|
207
211
|
incompatibleSchemaError: incompatible,
|
|
208
212
|
choice: migrationMode,
|
|
209
213
|
});
|
|
@@ -303,7 +307,7 @@ function suggestedCommand(serviceName, invalidConnectorNames) {
|
|
|
303
307
|
return `firebase deploy --only ${onlys}`;
|
|
304
308
|
}
|
|
305
309
|
async function handleIncompatibleSchemaError(args) {
|
|
306
|
-
const { incompatibleSchemaError, options, instanceId, databaseId, schemaName, choice } = args;
|
|
310
|
+
const { schema, incompatibleSchemaError, options, instanceId, databaseId, schemaName, choice } = args;
|
|
307
311
|
const commandsToExecute = incompatibleSchemaError.diffs.filter((d) => {
|
|
308
312
|
switch (choice) {
|
|
309
313
|
case "all":
|
|
@@ -342,10 +346,17 @@ async function handleIncompatibleSchemaError(args) {
|
|
|
342
346
|
await (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, commandsToExecuteBySuperUser.map((d) => d.sql), false);
|
|
343
347
|
}
|
|
344
348
|
if (commandsToExecuteByOwner.length) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
+
if (experiments.isEnabled("fdcapimigration")) {
|
|
350
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `[EXPERIMENTAL] Delegating SQL execution to FDC Backend...`);
|
|
351
|
+
const serviceName = serviceNameFromSchema(schema);
|
|
352
|
+
await (0, client_1.executeSchemaMigration)(serviceName, commandsToExecuteByOwner);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
await (0, connect_1.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [
|
|
356
|
+
`SET ROLE "${(0, permissions_1.firebaseowner)(databaseId, schemaName)}"`,
|
|
357
|
+
...commandsToExecuteByOwner.map((d) => d.sql),
|
|
358
|
+
], false);
|
|
359
|
+
}
|
|
349
360
|
return incompatibleSchemaError.diffs;
|
|
350
361
|
}
|
|
351
362
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleSecretParams = handleSecretParams;
|
|
4
4
|
exports.checkSpecForSecrets = checkSpecForSecrets;
|
|
5
|
+
exports.transferSecretToKits = transferSecretToKits;
|
|
5
6
|
const clc = require("colorette");
|
|
6
7
|
const secretUtils = require("../../extensions/secretsUtils");
|
|
7
8
|
const secretManager = require("../../gcp/secretManager");
|
|
@@ -11,6 +12,7 @@ const types_1 = require("../../extensions/types");
|
|
|
11
12
|
const error_1 = require("../../error");
|
|
12
13
|
const logger_1 = require("../../logger");
|
|
13
14
|
const utils_1 = require("../../utils");
|
|
15
|
+
const secretManager_1 = require("../../gcp/secretManager");
|
|
14
16
|
async function handleSecretParams(payload, have, nonInteractive) {
|
|
15
17
|
for (const i of payload.instancesToCreate ?? []) {
|
|
16
18
|
if (await checkSpecForSecrets(i)) {
|
|
@@ -138,6 +140,22 @@ async function getSecretInfo(projectId, secretName, version) {
|
|
|
138
140
|
}
|
|
139
141
|
return secretInfo;
|
|
140
142
|
}
|
|
143
|
+
async function transferSecretToKits(projectId, secretName) {
|
|
144
|
+
const newLabels = {};
|
|
145
|
+
try {
|
|
146
|
+
const have = await secretManager.getSecret(projectId, secretName);
|
|
147
|
+
for (const [labelKey, labelValue] of Object.entries(have.labels)) {
|
|
148
|
+
if (labelKey !== secretUtils.SECRET_LABEL) {
|
|
149
|
+
newLabels[labelKey] = labelValue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
throw new error_1.FirebaseError(`Error when retrieving current state of migrating secret ${projectId}/${secretName}: ${err instanceof Error ? err.message : String(err)}`, { original: err instanceof Error ? err : undefined });
|
|
155
|
+
}
|
|
156
|
+
newLabels[secretManager_1.FIREBASE_MANAGED] = "functions";
|
|
157
|
+
return secretManager.patchSecret(projectId, secretName, newLabels);
|
|
158
|
+
}
|
|
141
159
|
async function promptForCreateSecret(args) {
|
|
142
160
|
logger_1.logger.info(`${clc.bold(args.instanceId)}: Secret ${args.projectId}/${args.secretName} doesn't exist yet.`);
|
|
143
161
|
if (args.nonInteractive) {
|
|
@@ -11,6 +11,8 @@ exports.targetCodebases = targetCodebases;
|
|
|
11
11
|
exports.groupEndpointsByCodebase = groupEndpointsByCodebase;
|
|
12
12
|
exports.isCodebaseFiltered = isCodebaseFiltered;
|
|
13
13
|
exports.isEndpointFiltered = isEndpointFiltered;
|
|
14
|
+
exports.parseDeleteFilters = parseDeleteFilters;
|
|
15
|
+
exports.detectCodebaseAndIdCollisions = detectCodebaseAndIdCollisions;
|
|
14
16
|
const backend = require("./backend");
|
|
15
17
|
const projectConfig_1 = require("../../functions/projectConfig");
|
|
16
18
|
const functional_1 = require("../../functional");
|
|
@@ -21,31 +23,24 @@ function endpointMatchesAnyFilter(endpoint, filters) {
|
|
|
21
23
|
return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
|
|
22
24
|
}
|
|
23
25
|
function endpointMatchesFilter(endpoint, filter) {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
+
if (filter.codebase) {
|
|
27
|
+
const endpointCodebase = endpoint.codebase || projectConfig_1.DEFAULT_CODEBASE;
|
|
28
|
+
if (endpointCodebase !== filter.codebase) {
|
|
26
29
|
return false;
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
|
-
if (!filter.idChunks) {
|
|
32
|
+
if (!filter.idChunks || filter.idChunks.length === 0) {
|
|
30
33
|
return true;
|
|
31
34
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
for (let i = 0; i < filter.idChunks.length; i += 1) {
|
|
37
|
-
if (idChunks[i] !== filter.idChunks[i]) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
35
|
+
const filterPrefix = filter.idChunks.join("-");
|
|
36
|
+
return endpoint.id === filterPrefix || endpoint.id.startsWith(`${filterPrefix}-`);
|
|
42
37
|
}
|
|
43
|
-
function getCodebasesFromConfig(config) {
|
|
38
|
+
function getCodebasesFromConfig(config = []) {
|
|
44
39
|
return [
|
|
45
40
|
...new Set(config.flatMap((c) => ((0, projectConfig_1.isKitConfig)(c) ? Object.keys(c.instances) : [c.codebase]))),
|
|
46
41
|
];
|
|
47
42
|
}
|
|
48
|
-
function parseFunctionSelector(selector, config) {
|
|
43
|
+
function parseFunctionSelector(selector, config = []) {
|
|
49
44
|
const fragments = selector.split(":");
|
|
50
45
|
const target = fragments[0];
|
|
51
46
|
const codebaseNames = getCodebasesFromConfig(config);
|
|
@@ -145,3 +140,32 @@ function isCodebaseFiltered(codebase, filters) {
|
|
|
145
140
|
function isEndpointFiltered(endpoint, filters) {
|
|
146
141
|
return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
|
|
147
142
|
}
|
|
143
|
+
function parseDeleteFilters(filters, activeCodebases) {
|
|
144
|
+
const liveCodebasesConfig = activeCodebases.map((codebase) => ({ source: "", codebase }));
|
|
145
|
+
return filters.flatMap((f) => {
|
|
146
|
+
const parsed = parseFunctionSelector(f, liveCodebasesConfig);
|
|
147
|
+
return parsed.map((filter) => !f.includes(":") && filter.codebase === projectConfig_1.DEFAULT_CODEBASE && filter.idChunks
|
|
148
|
+
? { idChunks: filter.idChunks }
|
|
149
|
+
: filter);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function detectCodebaseAndIdCollisions(filters, activeCodebases, allEndpoints, defaultCodebase = projectConfig_1.DEFAULT_CODEBASE) {
|
|
153
|
+
const collisions = [];
|
|
154
|
+
for (const f of filters) {
|
|
155
|
+
if (f.includes(":") || !activeCodebases.includes(f)) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const matchingEndpoints = allEndpoints.filter((ep) => ep.id === f || ep.id.startsWith(`${f}-`));
|
|
159
|
+
if (matchingEndpoints.length > 0) {
|
|
160
|
+
const ep = matchingEndpoints[0];
|
|
161
|
+
const prefix = ep.codebase || defaultCodebase;
|
|
162
|
+
collisions.push({
|
|
163
|
+
filter: f,
|
|
164
|
+
codebase: prefix,
|
|
165
|
+
functionLabel: getFunctionLabel(ep),
|
|
166
|
+
workaroundCommand: `firebase functions:delete ${prefix}:${f}`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return collisions;
|
|
171
|
+
}
|