firebase-tools 15.28.2 → 15.28.3-feat-firebase-debug-path.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 +4 -1
- package/lib/bin/mcp.js +8 -3
- package/lib/commands/ext-export.js +34 -13
- package/lib/commands/ext-migrate.js +3 -0
- package/lib/commands/functions-delete.js +6 -67
- package/lib/commands/functions-kits-install.js +3 -0
- package/lib/commands/functions-kits-uninstall.js +5 -71
- 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 +80 -0
- package/lib/emulator/types.js +3 -1
- package/lib/extensions/askUserForParam.js +9 -8
- package/lib/extensions/export.js +46 -9
- package/lib/extensions/extensionsHelper.js +28 -0
- package/lib/extensions/migrate.js +121 -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 +238 -68
- package/lib/gcp/apikeys.js +89 -0
- package/lib/gcp/storage.js +3 -2
- package/lib/logger.js +83 -9
- 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 +1 -0
- 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/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/templates/init/functions/typescript/index-kit-migration.ts +20 -2
|
@@ -7,7 +7,7 @@ exports.validateNpmPackageName = validateNpmPackageName;
|
|
|
7
7
|
exports.sanitizePackageNameToKitName = sanitizePackageNameToKitName;
|
|
8
8
|
exports.isThirdPartyPackage = isThirdPartyPackage;
|
|
9
9
|
exports.checkPackageHasShrinkwrap = checkPackageHasShrinkwrap;
|
|
10
|
-
exports.
|
|
10
|
+
exports.getUnconfiguredInstancesForProject = getUnconfiguredInstancesForProject;
|
|
11
11
|
exports.extractExistingFunctionsInfo = extractExistingFunctionsInfo;
|
|
12
12
|
exports.promptKitInstanceId = promptKitInstanceId;
|
|
13
13
|
exports.promptKitId = promptKitId;
|
|
@@ -25,6 +25,7 @@ exports.addInstanceToKitConfig = addInstanceToKitConfig;
|
|
|
25
25
|
exports.scaffoldKit = scaffoldKit;
|
|
26
26
|
exports.addInstanceToKit = addInstanceToKit;
|
|
27
27
|
exports.discoverKitBuild = discoverKitBuild;
|
|
28
|
+
exports.promptAndWriteKitParams = promptAndWriteKitParams;
|
|
28
29
|
exports.printKitFirstDeployReport = printKitFirstDeployReport;
|
|
29
30
|
exports.addKitInstanceOrConfigureProject = addKitInstanceOrConfigureProject;
|
|
30
31
|
exports.findExistingKit = findExistingKit;
|
|
@@ -46,7 +47,13 @@ const templates_1 = require("../../templates");
|
|
|
46
47
|
const supported = require("../../deploy/functions/runtimes/supported");
|
|
47
48
|
const runtimes = require("../../deploy/functions/runtimes");
|
|
48
49
|
const build = require("../../deploy/functions/build");
|
|
50
|
+
const params = require("../../deploy/functions/params");
|
|
51
|
+
const experiments = require("../../experiments");
|
|
49
52
|
const iam = require("../../gcp/iam");
|
|
53
|
+
const functionsEnv = require("../env");
|
|
54
|
+
const functionsConfig = require("../../functionsConfig");
|
|
55
|
+
const prepare_1 = require("../../deploy/functions/prepare");
|
|
56
|
+
const utils_2 = require("../../utils");
|
|
50
57
|
const env_1 = require("../env");
|
|
51
58
|
const env_2 = require("./env");
|
|
52
59
|
exports.TEMPLATES = {
|
|
@@ -56,7 +63,7 @@ exports.TEMPLATES = {
|
|
|
56
63
|
exports.DEFAULT_TEMPLATE = "installation";
|
|
57
64
|
exports.FUNCTION_KITS_DIR = "function-kits";
|
|
58
65
|
function generateUniqueId(baseId, existingIds) {
|
|
59
|
-
if (!existingIds.
|
|
66
|
+
if (!existingIds.includes(baseId)) {
|
|
60
67
|
return baseId;
|
|
61
68
|
}
|
|
62
69
|
const prefix = baseId.slice(0, 35);
|
|
@@ -64,32 +71,39 @@ function generateUniqueId(baseId, existingIds) {
|
|
|
64
71
|
do {
|
|
65
72
|
const randomSuffix = crypto.randomBytes(2).toString("hex");
|
|
66
73
|
candidate = `${prefix}-${randomSuffix}`;
|
|
67
|
-
} while (existingIds.
|
|
74
|
+
} while (existingIds.includes(candidate));
|
|
68
75
|
return candidate;
|
|
69
76
|
}
|
|
70
77
|
function parseNpmPackageSpecifier(rawPkg) {
|
|
71
78
|
const lastAt = rawPkg.lastIndexOf("@");
|
|
72
79
|
if (lastAt > 0) {
|
|
80
|
+
const version = rawPkg.substring(lastAt + 1);
|
|
73
81
|
return {
|
|
74
82
|
packageName: rawPkg.substring(0, lastAt),
|
|
75
|
-
version
|
|
83
|
+
...(version ? { version } : {}),
|
|
76
84
|
};
|
|
77
85
|
}
|
|
78
86
|
return { packageName: rawPkg };
|
|
79
87
|
}
|
|
80
|
-
function validateNpmPackageName(
|
|
88
|
+
function validateNpmPackageName(packageNameOrSpecifier) {
|
|
89
|
+
const { packageName, version } = parseNpmPackageSpecifier(packageNameOrSpecifier);
|
|
81
90
|
const npmPackageRegex = /^(?:@[a-z0-9_.-]+\/[a-z0-9_.-]+|[a-z0-9_.-]+)$/i;
|
|
82
|
-
if (!packageName ||
|
|
83
|
-
|
|
91
|
+
if (!packageName ||
|
|
92
|
+
packageName.length > 214 ||
|
|
93
|
+
!npmPackageRegex.test(packageName) ||
|
|
94
|
+
(packageNameOrSpecifier.lastIndexOf("@") > 0 && !version)) {
|
|
95
|
+
throw new error_1.FirebaseError(`Invalid NPM package name '${packageNameOrSpecifier}'. Package names must be valid npm package specifiers (e.g. 'my-kit' or '@scope/my-kit').`);
|
|
84
96
|
}
|
|
85
97
|
}
|
|
86
|
-
function sanitizePackageNameToKitName(
|
|
98
|
+
function sanitizePackageNameToKitName(packageNameOrSpecifier) {
|
|
99
|
+
const { packageName } = parseNpmPackageSpecifier(packageNameOrSpecifier);
|
|
87
100
|
const parts = packageName.split("/");
|
|
88
101
|
const nameWithoutScope = parts[parts.length - 1] || packageName;
|
|
89
102
|
const sanitized = nameWithoutScope.toLowerCase().replace(/[^a-z0-9_-]/g, "");
|
|
90
103
|
return sanitized.slice(0, 40);
|
|
91
104
|
}
|
|
92
|
-
function isThirdPartyPackage(
|
|
105
|
+
function isThirdPartyPackage(packageNameOrSpecifier) {
|
|
106
|
+
const { packageName } = parseNpmPackageSpecifier(packageNameOrSpecifier);
|
|
93
107
|
return !packageName.startsWith("@firebase-function-kits/");
|
|
94
108
|
}
|
|
95
109
|
async function checkPackageHasShrinkwrap(rawPkgName) {
|
|
@@ -111,29 +125,29 @@ async function checkPackageHasShrinkwrap(rawPkgName) {
|
|
|
111
125
|
}
|
|
112
126
|
return false;
|
|
113
127
|
}
|
|
114
|
-
function
|
|
115
|
-
return Object.
|
|
128
|
+
function getUnconfiguredInstancesForProject(config, kit, projectId, projectAlias) {
|
|
129
|
+
return Object.entries(kit.instances || {})
|
|
130
|
+
.filter(([, configDir]) => !(0, env_1.hasProjectEnv)(config.path(configDir), projectId, projectAlias))
|
|
131
|
+
.map(([instanceId]) => instanceId);
|
|
116
132
|
}
|
|
117
133
|
function extractExistingFunctionsInfo(configFunctions) {
|
|
118
134
|
const existingFunctions = configFunctions && (!Array.isArray(configFunctions) || configFunctions.length > 0)
|
|
119
135
|
? (0, projectConfig_1.normalizeAndValidate)(configFunctions)
|
|
120
136
|
: [];
|
|
121
|
-
const existingKitIds =
|
|
122
|
-
const existingCodebases =
|
|
123
|
-
const existingInstanceIds =
|
|
137
|
+
const existingKitIds = [];
|
|
138
|
+
const existingCodebases = [];
|
|
139
|
+
const existingInstanceIds = [];
|
|
124
140
|
for (const c of existingFunctions) {
|
|
125
141
|
if ((0, projectConfig_1.isKitConfig)(c)) {
|
|
126
142
|
if (c.kit) {
|
|
127
|
-
existingKitIds.
|
|
143
|
+
existingKitIds.push(c.kit);
|
|
128
144
|
}
|
|
129
145
|
if (c.instances) {
|
|
130
|
-
|
|
131
|
-
existingInstanceIds.add(instId);
|
|
132
|
-
}
|
|
146
|
+
existingInstanceIds.push(...Object.keys(c.instances));
|
|
133
147
|
}
|
|
134
148
|
}
|
|
135
149
|
else if (c.codebase) {
|
|
136
|
-
existingCodebases.
|
|
150
|
+
existingCodebases.push(c.codebase);
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
153
|
return {
|
|
@@ -144,14 +158,14 @@ function extractExistingFunctionsInfo(configFunctions) {
|
|
|
144
158
|
};
|
|
145
159
|
}
|
|
146
160
|
async function promptKitInstanceId(baseKitId, existingInstanceIds, existingCodebases, nonInteractive, customInstanceId) {
|
|
147
|
-
const instanceCollisions =
|
|
161
|
+
const instanceCollisions = [...existingInstanceIds, ...existingCodebases];
|
|
148
162
|
const defaultInstanceId = generateUniqueId(baseKitId, instanceCollisions);
|
|
149
163
|
if (customInstanceId) {
|
|
150
164
|
(0, projectConfig_1.validateKitInstanceId)(customInstanceId);
|
|
151
|
-
if (existingInstanceIds.
|
|
165
|
+
if (existingInstanceIds.includes(customInstanceId)) {
|
|
152
166
|
throw new error_1.FirebaseError(`functions kit instance ID must be unique across all kits, but '${customInstanceId}' was used more than once.`);
|
|
153
167
|
}
|
|
154
|
-
if (existingCodebases.
|
|
168
|
+
if (existingCodebases.includes(customInstanceId)) {
|
|
155
169
|
throw new error_1.FirebaseError(`functions codebase name and kit instance ID must be mutually exclusive, but '${customInstanceId}' was used as both a codebase name and a kit instance ID.`);
|
|
156
170
|
}
|
|
157
171
|
return customInstanceId;
|
|
@@ -167,20 +181,20 @@ async function promptKitInstanceId(baseKitId, existingInstanceIds, existingCodeb
|
|
|
167
181
|
catch (err) {
|
|
168
182
|
return (0, error_1.getErrMsg)(err);
|
|
169
183
|
}
|
|
170
|
-
if (existingInstanceIds.
|
|
184
|
+
if (existingInstanceIds.includes(val)) {
|
|
171
185
|
return `functions kit instance ID must be unique across all kits, but '${val}' was used more than once.`;
|
|
172
186
|
}
|
|
173
|
-
if (existingCodebases.
|
|
187
|
+
if (existingCodebases.includes(val)) {
|
|
174
188
|
return `functions codebase name and kit instance ID must be mutually exclusive, but '${val}' was used as both a codebase name and a kit instance ID.`;
|
|
175
189
|
}
|
|
176
190
|
return true;
|
|
177
191
|
},
|
|
178
192
|
});
|
|
179
193
|
(0, projectConfig_1.validateKitInstanceId)(instanceId);
|
|
180
|
-
if (existingInstanceIds.
|
|
194
|
+
if (existingInstanceIds.includes(instanceId)) {
|
|
181
195
|
throw new error_1.FirebaseError(`functions kit instance ID must be unique across all kits, but '${instanceId}' was used more than once.`);
|
|
182
196
|
}
|
|
183
|
-
if (existingCodebases.
|
|
197
|
+
if (existingCodebases.includes(instanceId)) {
|
|
184
198
|
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.`);
|
|
185
199
|
}
|
|
186
200
|
return instanceId;
|
|
@@ -190,7 +204,7 @@ async function promptKitId(packageName, existingKitIds, nonInteractive, customKi
|
|
|
190
204
|
const defaultKitId = generateUniqueId(baseKitId, existingKitIds);
|
|
191
205
|
if (customKitId) {
|
|
192
206
|
(0, projectConfig_1.validateKit)(customKitId);
|
|
193
|
-
if (existingKitIds.
|
|
207
|
+
if (existingKitIds.includes(customKitId)) {
|
|
194
208
|
throw new error_1.FirebaseError(`functions.kit must be unique but '${customKitId}' was used more than once.`);
|
|
195
209
|
}
|
|
196
210
|
return customKitId;
|
|
@@ -206,14 +220,14 @@ async function promptKitId(packageName, existingKitIds, nonInteractive, customKi
|
|
|
206
220
|
catch (err) {
|
|
207
221
|
return (0, error_1.getErrMsg)(err);
|
|
208
222
|
}
|
|
209
|
-
if (existingKitIds.
|
|
223
|
+
if (existingKitIds.includes(val)) {
|
|
210
224
|
return `functions.kit must be unique but '${val}' was used more than once.`;
|
|
211
225
|
}
|
|
212
226
|
return true;
|
|
213
227
|
},
|
|
214
228
|
});
|
|
215
229
|
(0, projectConfig_1.validateKit)(kitId);
|
|
216
|
-
if (existingKitIds.
|
|
230
|
+
if (existingKitIds.includes(kitId)) {
|
|
217
231
|
throw new error_1.FirebaseError(`functions.kit must be unique but '${kitId}' was used more than once.`);
|
|
218
232
|
}
|
|
219
233
|
return kitId;
|
|
@@ -249,25 +263,33 @@ async function promptSecurityConfirmation(rawPkgName, packageName, nonInteractiv
|
|
|
249
263
|
}
|
|
250
264
|
return isThirdParty;
|
|
251
265
|
}
|
|
252
|
-
async function promptExistingInstanceForProject(options
|
|
253
|
-
const
|
|
254
|
-
if (
|
|
255
|
-
throw new error_1.FirebaseError(`Kit '${existingKit.kit}' has no instances configured.`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
+
async function promptExistingInstanceForProject(options) {
|
|
267
|
+
const allInstanceIds = Object.keys(options.existingKit.instances || {});
|
|
268
|
+
if (allInstanceIds.length === 0) {
|
|
269
|
+
throw new error_1.FirebaseError(`Kit '${options.existingKit.kit}' has no instances configured.`);
|
|
270
|
+
}
|
|
271
|
+
if (options.instanceId) {
|
|
272
|
+
if (!allInstanceIds.includes(options.instanceId)) {
|
|
273
|
+
throw new error_1.FirebaseError(`Instance '${options.instanceId}' does not exist in kit '${options.existingKit.kit}'. Available instances: ${allInstanceIds.join(", ")}`);
|
|
274
|
+
}
|
|
275
|
+
if (!options.unconfiguredInstanceIds.includes(options.instanceId)) {
|
|
276
|
+
throw new error_1.FirebaseError(`Instance '${options.instanceId}' is already configured for this project.`);
|
|
277
|
+
}
|
|
278
|
+
return options.instanceId;
|
|
279
|
+
}
|
|
280
|
+
if (options.unconfiguredInstanceIds.length === 0) {
|
|
281
|
+
throw new error_1.FirebaseError(`Kit '${options.existingKit.kit}' has no unconfigured instances for this project.`);
|
|
266
282
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
clc.bold(
|
|
270
|
-
|
|
283
|
+
if (options.unconfiguredInstanceIds.length === 1) {
|
|
284
|
+
const instanceId = options.unconfiguredInstanceIds[0];
|
|
285
|
+
(0, utils_1.logLabeledBullet)("functions", `${clc.bold(instanceId)} is the only instance without a configuration. Configuring...`);
|
|
286
|
+
return instanceId;
|
|
287
|
+
}
|
|
288
|
+
return (0, prompt_1.select)({
|
|
289
|
+
message: "Which instance would you like to configure for this project?",
|
|
290
|
+
choices: options.unconfiguredInstanceIds,
|
|
291
|
+
nonInteractive: options.nonInteractive,
|
|
292
|
+
});
|
|
271
293
|
}
|
|
272
294
|
async function writeKitPackageJson(config, sourcePath, kitId) {
|
|
273
295
|
const relPackageJsonPath = path.join(sourcePath, "package.json");
|
|
@@ -489,11 +511,44 @@ async function discoverKitBuild(options, absSourcePath) {
|
|
|
489
511
|
const runtimeDelegate = await runtimes.getRuntimeDelegate(delegateContext);
|
|
490
512
|
return runtimeDelegate.discoverBuild({}, {});
|
|
491
513
|
}
|
|
492
|
-
async function
|
|
514
|
+
async function promptAndWriteKitParams(options) {
|
|
515
|
+
if (!options.params || options.params.length === 0) {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
if (!options.projectId) {
|
|
519
|
+
logger_1.logger.debug("Skipping functions kit parameter prompt: no active project ID.");
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
const userEnvOpt = {
|
|
523
|
+
configDir: options.absConfigDirPath,
|
|
524
|
+
functionsSource: options.absSourcePath,
|
|
525
|
+
projectDir: options.config.projectDir,
|
|
526
|
+
projectId: options.projectId,
|
|
527
|
+
projectAlias: options.projectAlias,
|
|
528
|
+
};
|
|
529
|
+
const rawUserEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
530
|
+
const { userEnvs, secretRefs } = (0, prepare_1.partitionUserEnvs)(rawUserEnvs);
|
|
531
|
+
let firebaseConfig = { projectId: options.projectId };
|
|
532
|
+
try {
|
|
533
|
+
firebaseConfig = await functionsConfig.getFirebaseConfig({ projectId: options.projectId });
|
|
534
|
+
}
|
|
535
|
+
catch (err) {
|
|
536
|
+
logger_1.logger.debug(`Could not fetch Firebase config for project ${options.projectId}: ${(0, error_1.getErrMsg)(err)}`);
|
|
537
|
+
}
|
|
538
|
+
const typedUserEnvs = build.envWithTypes(options.params, userEnvs);
|
|
539
|
+
const { paramValues: resolvedEnvs, secretRefs: resolvedSecretRefs } = await params.resolveParams(options.params, firebaseConfig, typedUserEnvs, options.instanceId, options.nonInteractive, options.force);
|
|
540
|
+
functionsEnv.writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt);
|
|
541
|
+
if (experiments.isEnabled("secretEnvParams")) {
|
|
542
|
+
functionsEnv.writeResolvedSecretRefs(resolvedSecretRefs, secretRefs, userEnvOpt);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
async function printKitFirstDeployReport(options) {
|
|
493
546
|
let discoveredBuild;
|
|
494
|
-
const prefix = (0, projectConfig_1.addKitPrefix)(instanceId);
|
|
547
|
+
const prefix = (0, projectConfig_1.addKitPrefix)(options.instanceId);
|
|
495
548
|
try {
|
|
496
|
-
discoveredBuild =
|
|
549
|
+
discoveredBuild = options.preDiscoveredBuild
|
|
550
|
+
? (0, utils_2.cloneDeep)(options.preDiscoveredBuild)
|
|
551
|
+
: await discoverKitBuild(options, options.absSourcePath);
|
|
497
552
|
build.applyPrefix(discoveredBuild, prefix);
|
|
498
553
|
}
|
|
499
554
|
catch (err) {
|
|
@@ -547,12 +602,22 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
547
602
|
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
548
603
|
? options.project
|
|
549
604
|
: undefined;
|
|
550
|
-
const
|
|
605
|
+
const unconfiguredInstances = getUnconfiguredInstancesForProject(options.config, existingKit, projectId, projectAlias);
|
|
606
|
+
const isConfiguredForProject = Object.keys(existingKit.instances || {}).length > 0 && unconfiguredInstances.length === 0;
|
|
551
607
|
let action;
|
|
552
|
-
if (
|
|
553
|
-
|
|
608
|
+
if (options.instanceId && existingKit.instances && options.instanceId in existingKit.instances) {
|
|
609
|
+
if (!unconfiguredInstances.includes(options.instanceId)) {
|
|
610
|
+
throw new error_1.FirebaseError(`Instance '${options.instanceId}' is already configured for this project.`);
|
|
611
|
+
}
|
|
612
|
+
action = "addEnv";
|
|
613
|
+
}
|
|
614
|
+
else if (options.instanceId) {
|
|
615
|
+
action = "addInstance";
|
|
616
|
+
}
|
|
617
|
+
else if (unconfiguredInstances.length > 0 && !options.nonInteractive) {
|
|
618
|
+
const unconfiguredInstancesList = unconfiguredInstances.join(", ");
|
|
554
619
|
action = await (0, prompt_1.select)({
|
|
555
|
-
message: `The following instances already exist, but are not configured for this project: ${
|
|
620
|
+
message: `The following instances already exist, but are not configured for this project: ${unconfiguredInstancesList}. What would you like to do?`,
|
|
556
621
|
choices: [
|
|
557
622
|
{
|
|
558
623
|
name: "Add an instance to the existing kit",
|
|
@@ -571,29 +636,97 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
571
636
|
}
|
|
572
637
|
action = "addInstance";
|
|
573
638
|
}
|
|
639
|
+
let resultAction;
|
|
640
|
+
let instanceId;
|
|
641
|
+
let configDirPath;
|
|
642
|
+
let absConfigDirPath;
|
|
574
643
|
if (action === "addInstance") {
|
|
575
|
-
|
|
644
|
+
resultAction = "addedInstance";
|
|
645
|
+
instanceId = await promptKitInstanceId(existingKit.kit, existingFunctionsInfo.existingInstanceIds, existingFunctionsInfo.existingCodebases, options.nonInteractive, options.instanceId);
|
|
576
646
|
const result = await addInstanceToKit({
|
|
577
647
|
config: options.config,
|
|
578
648
|
kitId: existingKit.kit,
|
|
579
649
|
instanceId,
|
|
580
650
|
seedEnv: options.seedEnv,
|
|
581
651
|
});
|
|
652
|
+
configDirPath = result.configDirPath;
|
|
653
|
+
absConfigDirPath = result.absConfigDirPath;
|
|
654
|
+
}
|
|
655
|
+
else if (action === "addEnv") {
|
|
656
|
+
resultAction = "configuredEnv";
|
|
657
|
+
instanceId = await promptExistingInstanceForProject({
|
|
658
|
+
...options,
|
|
659
|
+
existingKit,
|
|
660
|
+
unconfiguredInstanceIds: unconfiguredInstances,
|
|
661
|
+
});
|
|
662
|
+
configDirPath = existingKit.instances[instanceId];
|
|
663
|
+
if (!configDirPath) {
|
|
664
|
+
throw new error_1.FirebaseError(`Configuration directory for instance '${instanceId}' not found in kit '${existingKit.kit}'.`);
|
|
665
|
+
}
|
|
666
|
+
absConfigDirPath = options.config.path(configDirPath);
|
|
667
|
+
if (options.seedEnv?.envs && Object.keys(options.seedEnv.envs).length > 0) {
|
|
668
|
+
await fs.ensureDir(absConfigDirPath);
|
|
669
|
+
(0, env_2.seedKitInstanceEnv)({
|
|
670
|
+
configDir: absConfigDirPath,
|
|
671
|
+
functionsSource: options.config.path(existingKit.source),
|
|
672
|
+
projectDir: options.config.projectDir,
|
|
673
|
+
projectId: options.seedEnv.projectId,
|
|
674
|
+
projectAlias: options.seedEnv.projectAlias,
|
|
675
|
+
envs: options.seedEnv.envs,
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
throw new error_1.FirebaseError(`Unexpected action '${String(action)}' for kit installation.`);
|
|
681
|
+
}
|
|
682
|
+
if (projectId) {
|
|
683
|
+
fs.ensureFileSync(path.join(absConfigDirPath, `.env.${projectId}`));
|
|
684
|
+
}
|
|
685
|
+
const absSourcePath = options.config.path(existingKit.source);
|
|
686
|
+
let discoveredBuild;
|
|
687
|
+
const shouldConfigure = options.configure !== false;
|
|
688
|
+
if (shouldConfigure) {
|
|
689
|
+
try {
|
|
690
|
+
discoveredBuild = await discoverKitBuild(options, absSourcePath);
|
|
691
|
+
}
|
|
692
|
+
catch (err) {
|
|
693
|
+
logger_1.logger.debug(`Could not discover kit build for params prompting: ${(0, error_1.getErrMsg)(err)}`);
|
|
694
|
+
}
|
|
695
|
+
if (discoveredBuild?.params && discoveredBuild.params.length > 0) {
|
|
696
|
+
await promptAndWriteKitParams({
|
|
697
|
+
config: options.config,
|
|
698
|
+
projectId,
|
|
699
|
+
projectAlias,
|
|
700
|
+
absConfigDirPath,
|
|
701
|
+
absSourcePath,
|
|
702
|
+
instanceId,
|
|
703
|
+
nonInteractive: options.nonInteractive,
|
|
704
|
+
force: options.force,
|
|
705
|
+
params: discoveredBuild.params,
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
if (action === "addInstance") {
|
|
582
710
|
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully added to kit ${clc.bold(existingKit.kit)}.`);
|
|
583
|
-
await printKitFirstDeployReport(options, instanceId, options.config.path(existingKit.source));
|
|
584
|
-
return {
|
|
585
|
-
action: "addedInstance",
|
|
586
|
-
kitId: existingKit.kit,
|
|
587
|
-
instanceId,
|
|
588
|
-
sourcePath: existingKit.source,
|
|
589
|
-
configDirPath: result.configDirPath,
|
|
590
|
-
};
|
|
591
711
|
}
|
|
592
|
-
|
|
712
|
+
else if (action === "addEnv") {
|
|
713
|
+
const projectDisplay = projectId || options.project || "project";
|
|
714
|
+
(0, utils_1.logLabeledSuccess)("functions", `Function kit instance ${clc.bold(instanceId)} successfully configured for ${clc.bold(projectDisplay)}.`);
|
|
715
|
+
}
|
|
716
|
+
await printKitFirstDeployReport({
|
|
717
|
+
config: options.config,
|
|
718
|
+
project: options.project,
|
|
719
|
+
projectId: options.projectId,
|
|
720
|
+
instanceId,
|
|
721
|
+
absSourcePath,
|
|
722
|
+
preDiscoveredBuild: discoveredBuild,
|
|
723
|
+
});
|
|
593
724
|
return {
|
|
594
|
-
action:
|
|
725
|
+
action: resultAction,
|
|
595
726
|
kitId: existingKit.kit,
|
|
596
|
-
instanceId
|
|
727
|
+
instanceId,
|
|
728
|
+
sourcePath: existingKit.source,
|
|
729
|
+
configDirPath,
|
|
597
730
|
};
|
|
598
731
|
}
|
|
599
732
|
function findExistingKit(existingFunctions, options) {
|
|
@@ -623,8 +756,8 @@ async function resolvePackageSource(options) {
|
|
|
623
756
|
if (!rawPkgName) {
|
|
624
757
|
throw new error_1.FirebaseError("Set the --package option to a valid NPM package and try again.");
|
|
625
758
|
}
|
|
759
|
+
validateNpmPackageName(rawPkgName);
|
|
626
760
|
const { packageName } = parseNpmPackageSpecifier(rawPkgName);
|
|
627
|
-
validateNpmPackageName(packageName);
|
|
628
761
|
const isThirdParty = await promptSecurityConfirmation(rawPkgName, packageName, options.nonInteractive);
|
|
629
762
|
return {
|
|
630
763
|
defaultKitName: packageName,
|
|
@@ -689,6 +822,36 @@ async function installKitOrInstance(options) {
|
|
|
689
822
|
});
|
|
690
823
|
}
|
|
691
824
|
await source.buildAndInstall(absSourcePath);
|
|
825
|
+
const projectId = (0, projectUtils_1.getProjectId)(options) || options.projectId;
|
|
826
|
+
const projectAlias = options.rc?.hasProjects && options.project && options.rc.hasProjectAlias(options.project)
|
|
827
|
+
? options.project
|
|
828
|
+
: undefined;
|
|
829
|
+
if (projectId) {
|
|
830
|
+
fs.ensureFileSync(path.join(absConfigDirPath, `.env.${projectId}`));
|
|
831
|
+
}
|
|
832
|
+
let discoveredBuild;
|
|
833
|
+
const shouldConfigure = options.configure !== false;
|
|
834
|
+
if (shouldConfigure) {
|
|
835
|
+
try {
|
|
836
|
+
discoveredBuild = await discoverKitBuild(options, absSourcePath);
|
|
837
|
+
}
|
|
838
|
+
catch (err) {
|
|
839
|
+
logger_1.logger.debug(`Could not discover kit build for params prompting: ${(0, error_1.getErrMsg)(err)}`);
|
|
840
|
+
}
|
|
841
|
+
if (discoveredBuild?.params && discoveredBuild.params.length > 0) {
|
|
842
|
+
await promptAndWriteKitParams({
|
|
843
|
+
config: options.config,
|
|
844
|
+
projectId,
|
|
845
|
+
projectAlias,
|
|
846
|
+
absConfigDirPath,
|
|
847
|
+
absSourcePath,
|
|
848
|
+
instanceId,
|
|
849
|
+
nonInteractive: options.nonInteractive,
|
|
850
|
+
force: options.force,
|
|
851
|
+
params: discoveredBuild.params,
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
}
|
|
692
855
|
addKitToConfig(options.config, {
|
|
693
856
|
kitId,
|
|
694
857
|
instanceId,
|
|
@@ -698,7 +861,14 @@ async function installKitOrInstance(options) {
|
|
|
698
861
|
hasBuildScript: source.hasBuildScript,
|
|
699
862
|
});
|
|
700
863
|
(0, utils_1.logLabeledSuccess)("functions", `Function kit ${clc.bold(kitId)} successfully installed.`);
|
|
701
|
-
await printKitFirstDeployReport(
|
|
864
|
+
await printKitFirstDeployReport({
|
|
865
|
+
config: options.config,
|
|
866
|
+
project: options.project,
|
|
867
|
+
projectId: options.projectId,
|
|
868
|
+
instanceId,
|
|
869
|
+
absSourcePath,
|
|
870
|
+
preDiscoveredBuild: discoveredBuild,
|
|
871
|
+
});
|
|
702
872
|
return {
|
|
703
873
|
action: "installedKit",
|
|
704
874
|
kitId,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateAppApiKeyRestriction = updateAppApiKeyRestriction;
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const operation_poller_1 = require("../operation-poller");
|
|
8
|
+
const API_VERSION = "v2";
|
|
9
|
+
const CREDENTIALS_CONSOLE_URL = "https://console.cloud.google.com/apis/credentials";
|
|
10
|
+
const client = new apiv2_1.Client({
|
|
11
|
+
urlPrefix: (0, api_1.apiKeysOrigin)(),
|
|
12
|
+
auth: true,
|
|
13
|
+
apiVersion: API_VERSION,
|
|
14
|
+
});
|
|
15
|
+
async function updateAppApiKeyRestriction(options) {
|
|
16
|
+
const { apiKey, service } = options;
|
|
17
|
+
const keyResourceName = await lookupKeyResourceName(apiKey);
|
|
18
|
+
const key = await getKey(keyResourceName);
|
|
19
|
+
await ensureServiceInKeyRestrictions(key, service);
|
|
20
|
+
}
|
|
21
|
+
async function lookupKeyResourceName(apiKeyString) {
|
|
22
|
+
try {
|
|
23
|
+
const res = await client.get("/keys:lookupKey", {
|
|
24
|
+
queryParams: { keyString: apiKeyString },
|
|
25
|
+
});
|
|
26
|
+
return res.body.name;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
if ((0, error_1.getErrStatus)(err) === 403) {
|
|
30
|
+
throw new error_1.FirebaseError(`Permission denied when looking up API key.\n\n` +
|
|
31
|
+
`To resolve this, ensure your account has the right permissions on the project in the Google Cloud Console:\n\n` +
|
|
32
|
+
` ${CREDENTIALS_CONSOLE_URL}`, { original: err instanceof Error ? err : undefined, status: 403 });
|
|
33
|
+
}
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function getKey(keyResourceName) {
|
|
38
|
+
try {
|
|
39
|
+
const res = await client.get(keyResourceName);
|
|
40
|
+
return res.body;
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
if ((0, error_1.getErrStatus)(err) === 403) {
|
|
44
|
+
throw new error_1.FirebaseError(`Permission denied when retrieving API key ${keyResourceName}.\n\n` +
|
|
45
|
+
`To resolve this, ensure your account has the right permissions on the project in the Google Cloud Console:\n\n` +
|
|
46
|
+
` ${CREDENTIALS_CONSOLE_URL}`, { original: err instanceof Error ? err : undefined, status: 403 });
|
|
47
|
+
}
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function ensureServiceInKeyRestrictions(key, service) {
|
|
52
|
+
if (!key.restrictions?.apiTargets || key.restrictions.apiTargets.length === 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const alreadyAllowed = key.restrictions.apiTargets.some((target) => target.service === service);
|
|
56
|
+
if (alreadyAllowed) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const updatedRestrictions = {
|
|
60
|
+
...key.restrictions,
|
|
61
|
+
apiTargets: [...key.restrictions.apiTargets, { service }],
|
|
62
|
+
};
|
|
63
|
+
await updateKeyRestrictions({
|
|
64
|
+
...key,
|
|
65
|
+
restrictions: updatedRestrictions,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function updateKeyRestrictions(key) {
|
|
69
|
+
const queryParams = { updateMask: "restrictions" };
|
|
70
|
+
try {
|
|
71
|
+
const res = await client.patch(key.name, key, {
|
|
72
|
+
queryParams,
|
|
73
|
+
});
|
|
74
|
+
await (0, operation_poller_1.pollOperation)({
|
|
75
|
+
apiOrigin: (0, api_1.apiKeysOrigin)(),
|
|
76
|
+
apiVersion: API_VERSION,
|
|
77
|
+
operationResourceName: res.body.name,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if ((0, error_1.getErrStatus)(err) === 403) {
|
|
82
|
+
const keyIdentifier = key.displayName ? `${key.displayName} (${key.name})` : key.name;
|
|
83
|
+
throw new error_1.FirebaseError(`Permission denied when updating API key ${keyIdentifier}.\n\n` +
|
|
84
|
+
`To resolve this, ensure your account has the right permissions on the project in the Google Cloud Console:\n\n` +
|
|
85
|
+
` ${CREDENTIALS_CONSOLE_URL}`, { original: err instanceof Error ? err : undefined, status: 403 });
|
|
86
|
+
}
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
package/lib/gcp/storage.js
CHANGED
|
@@ -72,7 +72,7 @@ async function upload(source, uploadUrl, extraHeaders, ignoreQuotaProject) {
|
|
|
72
72
|
generation: res.response.headers.get("x-goog-generation"),
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
async function uploadObject(source, bucketName, contentType) {
|
|
75
|
+
async function uploadObject(source, bucketName, contentType, maxSizeBytes) {
|
|
76
76
|
switch (contentType) {
|
|
77
77
|
case ContentType.TAR:
|
|
78
78
|
if (!source.file.endsWith(".tar.gz")) {
|
|
@@ -86,12 +86,13 @@ async function uploadObject(source, bucketName, contentType) {
|
|
|
86
86
|
}
|
|
87
87
|
const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
|
|
88
88
|
const location = `/${bucketName}/${path.basename(source.file)}`;
|
|
89
|
+
const rangeHeader = maxSizeBytes !== undefined ? `0,${maxSizeBytes}` : "0,123289600";
|
|
89
90
|
const res = await localAPIClient.request({
|
|
90
91
|
method: "PUT",
|
|
91
92
|
path: location,
|
|
92
93
|
headers: {
|
|
93
94
|
"Content-Type": contentType === ContentType.TAR ? "application/octet-stream" : "application/zip",
|
|
94
|
-
"x-goog-content-length-range":
|
|
95
|
+
"x-goog-content-length-range": rangeHeader,
|
|
95
96
|
},
|
|
96
97
|
body: source.stream,
|
|
97
98
|
});
|