firebase-tools-with-isolate 15.31.0 → 15.33.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/accountImporter.js +6 -3
- package/lib/api.js +3 -3
- package/lib/apphosting/secrets/index.js +7 -2
- package/lib/command.js +1 -1
- package/lib/commands/apps-create.js +34 -3
- package/lib/commands/auth-import.js +5 -6
- package/lib/commands/functions-kits-uninstall.js +43 -21
- package/lib/commands/functions-lifecycle-list.js +5 -6
- package/lib/commands/hosting-channel-deploy.js +3 -3
- package/lib/commands/hosting-clone.js +60 -29
- package/lib/commands/hosting-disable.js +5 -1
- package/lib/config.js +1 -0
- package/lib/crashlytics/alerts.js +122 -0
- package/lib/crashlytics/onboarding.js +71 -3
- package/lib/crashlytics/sourcemap.js +46 -11
- package/lib/crashlytics/types.js +6 -1
- package/lib/database/import.js +6 -7
- package/lib/deploy/functions/build.js +3 -0
- package/lib/deploy/functions/cel.js +89 -58
- package/lib/deploy/functions/functionsDeployHelper.js +10 -0
- package/lib/deploy/functions/params.js +7 -4
- package/lib/deploy/functions/prepare.js +25 -8
- package/lib/deploy/functions/release/fabricator.js +1 -5
- package/lib/deploy/functions/release/planner.js +3 -2
- package/lib/deploy/functions/validate.js +16 -0
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/deploy/hosting/release.js +2 -2
- package/lib/emulator/auth/operations.js +8 -4
- package/lib/emulator/databaseEmulator.js +7 -3
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/emulatorLogger.js +2 -1
- package/lib/emulator/functionsEmulatorRuntime.js +2 -1
- package/lib/experiments.js +23 -6
- package/lib/extensions/warnings.js +48 -7
- package/lib/frameworks/next/constants.js +20 -12
- package/lib/frameworks/next/index.js +4 -25
- package/lib/frameworks/next/utils.js +28 -0
- package/lib/functions/env.js +4 -2
- package/lib/functions/kits/install.js +17 -1
- package/lib/gcp/artifactregistry.js +20 -0
- package/lib/gcp/cloudmonitoring.js +80 -3
- package/lib/gcp/cloudtasks.js +15 -1
- package/lib/gcp/cloudtrace.js +38 -0
- package/lib/gcp/resourceManager.js +1 -1
- package/lib/gcp/run.js +5 -0
- package/lib/gcp/runv2.js +32 -11
- package/lib/hosting/api.js +15 -15
- package/lib/hosting/runTags.js +1 -1
- package/lib/init/features/auth.js +46 -8
- package/lib/init/features/hosting/index.js +4 -2
- package/lib/management/apps.js +4 -2
- package/lib/management/projects.js +1 -1
- package/lib/mcp/tools/firestore/converter.js +2 -2
- package/lib/mcp/util.js +11 -10
- package/lib/profileReport.js +4 -4
- package/lib/scopes.js +1 -3
- package/lib/streamJson.js +37 -0
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +0 -15
- package/package.json +11 -10
- package/schema/firebase-config.json +41 -0
- package/lib/firestore/checkDatabaseType.js +0 -24
|
@@ -15,10 +15,6 @@ const fs_extra_1 = require("fs-extra");
|
|
|
15
15
|
const url_1 = require("url");
|
|
16
16
|
const semver_1 = require("semver");
|
|
17
17
|
const clc = require("colorette");
|
|
18
|
-
const stream_chain_1 = require("stream-chain");
|
|
19
|
-
const stream_json_1 = require("stream-json");
|
|
20
|
-
const pick_js_1 = require("stream-json/filters/pick.js");
|
|
21
|
-
const stream_object_js_1 = require("stream-json/streamers/stream-object.js");
|
|
22
18
|
const fsutils_1 = require("../../fsutils");
|
|
23
19
|
const prompt_1 = require("../../prompt");
|
|
24
20
|
const error_1 = require("../../error");
|
|
@@ -294,9 +290,12 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir, _, context) {
|
|
|
294
290
|
{
|
|
295
291
|
srcRoute: null,
|
|
296
292
|
initialRevalidateSeconds: false,
|
|
293
|
+
initialExpireSeconds: undefined,
|
|
297
294
|
dataRoute: "",
|
|
298
295
|
experimentalPPR: false,
|
|
296
|
+
renderingMode: undefined,
|
|
299
297
|
prefetchDataRoute: "",
|
|
298
|
+
allowHeader: [],
|
|
300
299
|
},
|
|
301
300
|
];
|
|
302
301
|
}));
|
|
@@ -395,27 +394,7 @@ async function ɵcodegenFunctionsDirectory(sourceDir, destDir, target, context)
|
|
|
395
394
|
if (!esbuild) {
|
|
396
395
|
throw new error_1.FirebaseError(`Failed to load esbuild from path: ${esbuildPath}`);
|
|
397
396
|
}
|
|
398
|
-
const productionDeps = await
|
|
399
|
-
const dependencies = [];
|
|
400
|
-
const npmLs = (0, cross_spawn_1.spawn)("npm", ["ls", "--omit=dev", "--all", "--json=true"], {
|
|
401
|
-
cwd: sourceDir,
|
|
402
|
-
timeout: constants_1.NPM_COMMAND_TIMEOUT_MILLIES,
|
|
403
|
-
});
|
|
404
|
-
const pipeline = (0, stream_chain_1.chain)([
|
|
405
|
-
npmLs.stdout,
|
|
406
|
-
(0, stream_json_1.parser)({ packValues: false, packKeys: true, streamValues: false }),
|
|
407
|
-
(0, pick_js_1.pick)({ filter: "dependencies" }),
|
|
408
|
-
(0, stream_object_js_1.streamObject)(),
|
|
409
|
-
({ key, value }) => [
|
|
410
|
-
key,
|
|
411
|
-
...(0, utils_2.allDependencyNames)(value),
|
|
412
|
-
],
|
|
413
|
-
]);
|
|
414
|
-
pipeline.on("data", (it) => dependencies.push(it));
|
|
415
|
-
pipeline.on("end", () => {
|
|
416
|
-
resolve([...new Set(dependencies)]);
|
|
417
|
-
});
|
|
418
|
-
});
|
|
397
|
+
const productionDeps = await (0, utils_2.getProductionDependencyNames)(sourceDir);
|
|
419
398
|
const esbuildArgs = {
|
|
420
399
|
entryPoints: [(0, path_1.join)(sourceDir, configFile)],
|
|
421
400
|
outfile: (0, path_1.join)(destDir, configFile),
|
|
@@ -18,6 +18,7 @@ exports.isUsingNextImageInServerComponent = isUsingNextImageInServerComponent;
|
|
|
18
18
|
exports.isUsingNextImageInClientComponent = isUsingNextImageInClientComponent;
|
|
19
19
|
exports.isUsingAppDirectory = isUsingAppDirectory;
|
|
20
20
|
exports.allDependencyNames = allDependencyNames;
|
|
21
|
+
exports.getProductionDependencyNames = getProductionDependencyNames;
|
|
21
22
|
exports.getMiddlewareMatcherRegexes = getMiddlewareMatcherRegexes;
|
|
22
23
|
exports.getNonStaticRoutes = getNonStaticRoutes;
|
|
23
24
|
exports.getNonStaticServerComponents = getNonStaticServerComponents;
|
|
@@ -43,6 +44,9 @@ const utils_1 = require("../utils");
|
|
|
43
44
|
const constants_1 = require("./constants");
|
|
44
45
|
const fsutils_1 = require("../../fsutils");
|
|
45
46
|
const utils_2 = require("../../utils");
|
|
47
|
+
const cross_spawn_1 = require("cross-spawn");
|
|
48
|
+
const streamJson_1 = require("../../streamJson");
|
|
49
|
+
const constants_2 = require("../constants");
|
|
46
50
|
const child_process_1 = require("child_process");
|
|
47
51
|
const error_1 = require("../../error");
|
|
48
52
|
exports.I18N_SOURCE = /\/:nextInternalLocale(\([^\)]+\))?/;
|
|
@@ -175,6 +179,30 @@ function allDependencyNames(mod) {
|
|
|
175
179
|
const dependencyNames = Object.keys(mod.dependencies).reduce((acc, it) => [...acc, it, ...allDependencyNames(mod.dependencies[it])], []);
|
|
176
180
|
return dependencyNames;
|
|
177
181
|
}
|
|
182
|
+
async function getProductionDependencyNames(sourceDir) {
|
|
183
|
+
const { chain, many, parser, pick, streamObject } = await (0, streamJson_1.loadStreamJson)();
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
const dependencies = [];
|
|
186
|
+
const npmLs = (0, cross_spawn_1.spawn)("npm", ["ls", "--omit=dev", "--all", "--json=true"], {
|
|
187
|
+
cwd: sourceDir,
|
|
188
|
+
timeout: constants_2.NPM_COMMAND_TIMEOUT_MILLIES,
|
|
189
|
+
});
|
|
190
|
+
npmLs.on("error", reject);
|
|
191
|
+
if (!npmLs.stdout) {
|
|
192
|
+
return reject(new error_1.FirebaseError("Failed to capture npm ls output"));
|
|
193
|
+
}
|
|
194
|
+
const pipeline = chain([
|
|
195
|
+
npmLs.stdout,
|
|
196
|
+
parser({ packValues: false, packKeys: true, streamValues: false }),
|
|
197
|
+
pick({ filter: "dependencies" }),
|
|
198
|
+
streamObject(),
|
|
199
|
+
({ key, value }) => many([key, ...allDependencyNames(value)]),
|
|
200
|
+
]);
|
|
201
|
+
pipeline.on("data", (it) => dependencies.push(it));
|
|
202
|
+
pipeline.on("error", reject);
|
|
203
|
+
pipeline.on("end", () => resolve([...new Set(dependencies)]));
|
|
204
|
+
});
|
|
205
|
+
}
|
|
178
206
|
function getMiddlewareMatcherRegexes(middlewareManifest, functionsConfigManifest) {
|
|
179
207
|
const middlewareObjectValues = Object.values(middlewareManifest.middleware);
|
|
180
208
|
const middlewareMatchers = [];
|
package/lib/functions/env.js
CHANGED
|
@@ -240,9 +240,11 @@ function writeUserEnvs(toWrite, envOpts) {
|
|
|
240
240
|
}
|
|
241
241
|
function checkForDuplicateKeys(isEmulator, keys, fullEnv, envsWithoutLocal) {
|
|
242
242
|
for (const key of keys) {
|
|
243
|
-
const definedInEnv =
|
|
243
|
+
const definedInEnv = Object.prototype.hasOwnProperty.call(fullEnv, key);
|
|
244
244
|
if (definedInEnv) {
|
|
245
|
-
if (envsWithoutLocal &&
|
|
245
|
+
if (envsWithoutLocal &&
|
|
246
|
+
isEmulator &&
|
|
247
|
+
Object.prototype.hasOwnProperty.call(envsWithoutLocal, key)) {
|
|
246
248
|
(0, utils_1.logWarning)(clc.cyan(clc.yellow("functions: ")) +
|
|
247
249
|
`Writing parameter ${key} to emulator-specific config .env.local. This will overwrite your existing definition only when emulating.`);
|
|
248
250
|
continue;
|
|
@@ -4,6 +4,7 @@ exports.FUNCTION_KITS_DIR = exports.DEFAULT_TEMPLATE = exports.TEMPLATES = void
|
|
|
4
4
|
exports.generateUniqueId = generateUniqueId;
|
|
5
5
|
exports.parseNpmPackageSpecifier = parseNpmPackageSpecifier;
|
|
6
6
|
exports.validateNpmPackageName = validateNpmPackageName;
|
|
7
|
+
exports.validateNpmPackageExists = validateNpmPackageExists;
|
|
7
8
|
exports.sanitizePackageNameToKitName = sanitizePackageNameToKitName;
|
|
8
9
|
exports.isThirdPartyPackage = isThirdPartyPackage;
|
|
9
10
|
exports.checkPackageHasShrinkwrap = checkPackageHasShrinkwrap;
|
|
@@ -100,6 +101,18 @@ function validateNpmPackageName(packageNameOrSpecifier) {
|
|
|
100
101
|
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').`);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
104
|
+
async function validateNpmPackageExists(rawPkgName) {
|
|
105
|
+
validateNpmPackageName(rawPkgName);
|
|
106
|
+
try {
|
|
107
|
+
const output = await (0, spawn_1.spawnWithOutput)("npm", ["view", rawPkgName, "version"]);
|
|
108
|
+
if (!output.trim()) {
|
|
109
|
+
throw new Error(`No version found for '${rawPkgName}'`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
throw new error_1.FirebaseError(`NPM package '${rawPkgName}' could not be found in the npm registry. Please verify the package name and version.`, { original: err instanceof Error ? err : undefined });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
103
116
|
function sanitizePackageNameToKitName(packageNameOrSpecifier) {
|
|
104
117
|
const { packageName } = parseNpmPackageSpecifier(packageNameOrSpecifier);
|
|
105
118
|
const parts = packageName.split("/");
|
|
@@ -881,7 +894,7 @@ async function resolvePackageSource(options) {
|
|
|
881
894
|
if (!rawPkgName) {
|
|
882
895
|
throw new error_1.FirebaseError("Set the --package option to a valid NPM package and try again.");
|
|
883
896
|
}
|
|
884
|
-
|
|
897
|
+
await validateNpmPackageExists(rawPkgName);
|
|
885
898
|
const { packageName } = parseNpmPackageSpecifier(rawPkgName);
|
|
886
899
|
const isThirdParty = await promptSecurityConfirmation({
|
|
887
900
|
rawPkgName,
|
|
@@ -930,6 +943,9 @@ async function installKitOrInstance(options) {
|
|
|
930
943
|
if (options.directory && options.template) {
|
|
931
944
|
throw new error_1.FirebaseError("Cannot specify --template with --directory.");
|
|
932
945
|
}
|
|
946
|
+
if (options.package) {
|
|
947
|
+
validateNpmPackageName(options.package);
|
|
948
|
+
}
|
|
933
949
|
const originalFunctions = (0, utils_1.cloneDeep)(options.config.src.functions);
|
|
934
950
|
const createdPaths = [];
|
|
935
951
|
let kitId;
|
|
@@ -5,11 +5,14 @@ exports.ensureApiEnabled = ensureApiEnabled;
|
|
|
5
5
|
exports.deletePackage = deletePackage;
|
|
6
6
|
exports.getRepository = getRepository;
|
|
7
7
|
exports.updateRepository = updateRepository;
|
|
8
|
+
exports.ensureDockerRepository = ensureDockerRepository;
|
|
8
9
|
const apiv2_1 = require("../apiv2");
|
|
9
10
|
const api_1 = require("../api");
|
|
10
11
|
const metaprogramming_1 = require("../metaprogramming");
|
|
11
12
|
const api = require("../ensureApiEnabled");
|
|
12
13
|
const proto = require("./proto");
|
|
14
|
+
const error_1 = require("../error");
|
|
15
|
+
const operation_poller_1 = require("../operation-poller");
|
|
13
16
|
exports.API_VERSION = "v1";
|
|
14
17
|
const client = new apiv2_1.Client({
|
|
15
18
|
urlPrefix: (0, api_1.artifactRegistryDomain)(),
|
|
@@ -39,3 +42,20 @@ async function updateRepository(repo) {
|
|
|
39
42
|
});
|
|
40
43
|
return res.body;
|
|
41
44
|
}
|
|
45
|
+
async function ensureDockerRepository(projectId, location, repositoryId) {
|
|
46
|
+
try {
|
|
47
|
+
await getRepository(`projects/${projectId}/locations/${location}/repositories/${repositoryId}`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if ((0, error_1.getErrStatus)(err) !== 404) {
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const res = await client.post(`/projects/${projectId}/locations/${location}/repositories`, { format: "DOCKER" }, { queryParams: { repositoryId } });
|
|
56
|
+
await (0, operation_poller_1.pollOperation)({
|
|
57
|
+
apiOrigin: (0, api_1.artifactRegistryDomain)(),
|
|
58
|
+
apiVersion: exports.API_VERSION,
|
|
59
|
+
operationResourceName: res.body.name,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValueType = exports.Reducer = exports.MetricKind = exports.Aligner = exports.TimeSeriesView = exports.CLOUD_MONITORING_VERSION = void 0;
|
|
4
4
|
exports.queryTimeSeries = queryTimeSeries;
|
|
5
|
+
exports.listNotificationChannels = listNotificationChannels;
|
|
6
|
+
exports.createNotificationChannel = createNotificationChannel;
|
|
7
|
+
exports.getAlertPolicy = getAlertPolicy;
|
|
8
|
+
exports.updateAlertPolicy = updateAlertPolicy;
|
|
5
9
|
const api_1 = require("../api");
|
|
6
10
|
const apiv2_1 = require("../apiv2");
|
|
7
11
|
const error_1 = require("../error");
|
|
@@ -63,15 +67,88 @@ async function queryTimeSeries(query, project) {
|
|
|
63
67
|
urlPrefix: (0, api_1.cloudMonitoringOrigin)(),
|
|
64
68
|
apiVersion: exports.CLOUD_MONITORING_VERSION,
|
|
65
69
|
});
|
|
70
|
+
const queryParams = {};
|
|
71
|
+
for (const [key, value] of Object.entries(query)) {
|
|
72
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
73
|
+
queryParams[key] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
66
76
|
try {
|
|
67
77
|
const res = await client.get(`/projects/${project}/timeSeries/`, {
|
|
68
|
-
queryParams
|
|
78
|
+
queryParams,
|
|
69
79
|
});
|
|
70
80
|
return res.body.timeSeries;
|
|
71
81
|
}
|
|
72
82
|
catch (err) {
|
|
73
|
-
throw new error_1.FirebaseError(`Failed to get Cloud Monitoring metric: ${err}`, {
|
|
74
|
-
status: err
|
|
83
|
+
throw new error_1.FirebaseError(`Failed to get Cloud Monitoring metric: ${(0, error_1.getErrMsg)(err)}`, {
|
|
84
|
+
status: (0, error_1.getErrStatus)(err),
|
|
85
|
+
original: (0, error_1.getError)(err),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function listNotificationChannels(project, filter) {
|
|
90
|
+
const client = new apiv2_1.Client({
|
|
91
|
+
urlPrefix: (0, api_1.cloudMonitoringOrigin)(),
|
|
92
|
+
apiVersion: exports.CLOUD_MONITORING_VERSION,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
const res = await client.get(`/projects/${project}/notificationChannels`, filter ? { queryParams: { filter } } : {});
|
|
96
|
+
return res.body?.notificationChannels ?? [];
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
throw new error_1.FirebaseError(`Failed to list Cloud Monitoring notification channels: ${(0, error_1.getErrMsg)(err)}`, {
|
|
100
|
+
status: (0, error_1.getErrStatus)(err),
|
|
101
|
+
original: (0, error_1.getError)(err),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function createNotificationChannel(project, channel) {
|
|
106
|
+
const client = new apiv2_1.Client({
|
|
107
|
+
urlPrefix: (0, api_1.cloudMonitoringOrigin)(),
|
|
108
|
+
apiVersion: exports.CLOUD_MONITORING_VERSION,
|
|
109
|
+
});
|
|
110
|
+
try {
|
|
111
|
+
const res = await client.post(`/projects/${project}/notificationChannels`, channel);
|
|
112
|
+
return res.body;
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
throw new error_1.FirebaseError(`Failed to create Cloud Monitoring notification channel: ${(0, error_1.getErrMsg)(err)}`, {
|
|
116
|
+
status: (0, error_1.getErrStatus)(err),
|
|
117
|
+
original: (0, error_1.getError)(err),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function getAlertPolicy(name) {
|
|
122
|
+
const client = new apiv2_1.Client({
|
|
123
|
+
urlPrefix: (0, api_1.cloudMonitoringOrigin)(),
|
|
124
|
+
apiVersion: exports.CLOUD_MONITORING_VERSION,
|
|
125
|
+
});
|
|
126
|
+
const path = name.startsWith("/") ? name : `/${name}`;
|
|
127
|
+
try {
|
|
128
|
+
const res = await client.get(path);
|
|
129
|
+
return res.body;
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
throw new error_1.FirebaseError(`Failed to get Cloud Monitoring alert policy ${name}: ${(0, error_1.getErrMsg)(err)}`, {
|
|
133
|
+
status: (0, error_1.getErrStatus)(err),
|
|
134
|
+
original: (0, error_1.getError)(err),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function updateAlertPolicy(policy, updateMask) {
|
|
139
|
+
const client = new apiv2_1.Client({
|
|
140
|
+
urlPrefix: (0, api_1.cloudMonitoringOrigin)(),
|
|
141
|
+
apiVersion: exports.CLOUD_MONITORING_VERSION,
|
|
142
|
+
});
|
|
143
|
+
const path = policy.name.startsWith("/") ? policy.name : `/${policy.name}`;
|
|
144
|
+
try {
|
|
145
|
+
const res = await client.patch(path, policy, updateMask ? { queryParams: { updateMask } } : {});
|
|
146
|
+
return res.body;
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
throw new error_1.FirebaseError(`Failed to update Cloud Monitoring alert policy ${policy.name}: ${(0, error_1.getErrMsg)(err)}`, {
|
|
150
|
+
status: (0, error_1.getErrStatus)(err),
|
|
151
|
+
original: (0, error_1.getError)(err),
|
|
75
152
|
});
|
|
76
153
|
}
|
|
77
154
|
}
|
package/lib/gcp/cloudtasks.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.createQueue = createQueue;
|
|
|
5
5
|
exports.getQueue = getQueue;
|
|
6
6
|
exports.updateQueue = updateQueue;
|
|
7
7
|
exports.upsertQueue = upsertQueue;
|
|
8
|
+
exports.disableQueue = disableQueue;
|
|
8
9
|
exports.purgeQueue = purgeQueue;
|
|
9
10
|
exports.deleteQueue = deleteQueue;
|
|
10
11
|
exports.enqueueTask = enqueueTask;
|
|
@@ -72,6 +73,19 @@ async function upsertQueue(queue) {
|
|
|
72
73
|
throw err;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
async function disableQueue(name) {
|
|
77
|
+
try {
|
|
78
|
+
await module.exports.getQueue(name);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
const responseError = err;
|
|
82
|
+
if (responseError.context?.response?.statusCode === 404) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
await module.exports.updateQueue({ name, state: "DISABLED" });
|
|
88
|
+
}
|
|
75
89
|
async function purgeQueue(name) {
|
|
76
90
|
await client.post(`${name}:purge`);
|
|
77
91
|
}
|
|
@@ -108,7 +122,7 @@ async function setEnqueuer(name, invoker, assumeEmpty = false) {
|
|
|
108
122
|
const invokerMembers = proto.getInvokerMembers(invoker, project);
|
|
109
123
|
while (true) {
|
|
110
124
|
const policy = {
|
|
111
|
-
bindings: existing.bindings.filter((binding) => binding.role !== ENQUEUER_ROLE),
|
|
125
|
+
bindings: (existing.bindings || []).filter((binding) => binding.role !== ENQUEUER_ROLE),
|
|
112
126
|
etag: existing.etag,
|
|
113
127
|
version: existing.version,
|
|
114
128
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.provisionTraceStorage = provisionTraceStorage;
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const API_VERSION = "v2";
|
|
8
|
+
const getTraceClient = () => new apiv2_1.Client({
|
|
9
|
+
urlPrefix: (0, api_1.cloudTraceOrigin)(),
|
|
10
|
+
auth: true,
|
|
11
|
+
apiVersion: API_VERSION,
|
|
12
|
+
});
|
|
13
|
+
async function provisionTraceStorage(projectId) {
|
|
14
|
+
const TRACE_ID = "33fc0d8c45bb4e5cebb29f047931270d";
|
|
15
|
+
const SPAN_ID = "f8fde40b437488e5";
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const later = new Date(now.getTime() + 1000);
|
|
18
|
+
const payload = {
|
|
19
|
+
name: `projects/${projectId}`,
|
|
20
|
+
spans: [
|
|
21
|
+
{
|
|
22
|
+
name: `projects/${projectId}/traces/${TRACE_ID}/spans/${SPAN_ID}`,
|
|
23
|
+
spanId: SPAN_ID,
|
|
24
|
+
displayName: { value: "/welcome" },
|
|
25
|
+
startTime: now.toISOString(),
|
|
26
|
+
endTime: later.toISOString(),
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
await getTraceClient().post(`/projects/${projectId}/traces:batchWrite`, payload);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
throw new error_1.FirebaseError(`Failed to provision trace storage for project ${projectId}: ${(0, error_1.getErrMsg)(err)}`, {
|
|
35
|
+
original: (0, error_1.getError)(err),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -60,7 +60,7 @@ async function addServiceAccountToRoles(projectId, serviceAccountName, roles, sk
|
|
|
60
60
|
(0, iam_1.mergeBindings)(projectPolicy, requiredBindings);
|
|
61
61
|
return await setIamPolicy(projectId, projectPolicy, "bindings");
|
|
62
62
|
}, {
|
|
63
|
-
retries:
|
|
63
|
+
retries: 7,
|
|
64
64
|
delay: 1000,
|
|
65
65
|
maxDelay: 5000,
|
|
66
66
|
retryPredicate: isRetryableIamError,
|
package/lib/gcp/run.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.getIamPolicy = getIamPolicy;
|
|
|
11
11
|
exports.setInvokerCreate = setInvokerCreate;
|
|
12
12
|
exports.setInvokerUpdate = setInvokerUpdate;
|
|
13
13
|
exports.fetchServiceLogs = fetchServiceLogs;
|
|
14
|
+
exports.listLocations = listLocations;
|
|
14
15
|
const apiv2_1 = require("../apiv2");
|
|
15
16
|
const error_1 = require("../error");
|
|
16
17
|
const api_1 = require("../api");
|
|
@@ -166,3 +167,7 @@ async function fetchServiceLogs(projectId, serviceId) {
|
|
|
166
167
|
});
|
|
167
168
|
}
|
|
168
169
|
}
|
|
170
|
+
async function listLocations(projectId) {
|
|
171
|
+
const res = await client.get(`/projects/${projectId}/locations`);
|
|
172
|
+
return res.body?.locations?.map((l) => l.locationId) ?? [];
|
|
173
|
+
}
|
package/lib/gcp/runv2.js
CHANGED
|
@@ -28,33 +28,52 @@ const client = new apiv2_1.Client({
|
|
|
28
28
|
apiVersion: exports.API_VERSION,
|
|
29
29
|
});
|
|
30
30
|
(0, metaprogramming_1.assertImplements)();
|
|
31
|
+
const PENDING_BUILD_STATUSES = ["STATUS_UNKNOWN", "PENDING", "QUEUED", "WORKING"];
|
|
31
32
|
async function submitBuild(projectId, location, build) {
|
|
32
|
-
const res = await client.post(`/projects/${projectId}/locations/${location}/builds`, build);
|
|
33
|
-
if (res.
|
|
34
|
-
|
|
33
|
+
const res = await client.post(`/projects/${projectId}/locations/${location}/builds:submit`, build);
|
|
34
|
+
if (res.body?.baseImageWarning) {
|
|
35
|
+
logger_1.logger.warn(res.body.baseImageWarning);
|
|
35
36
|
}
|
|
37
|
+
const cloudBuild = res.body?.buildOperation?.metadata?.build;
|
|
38
|
+
if (!cloudBuild) {
|
|
39
|
+
throw new error_1.FirebaseError("Failed to submit build: no build was returned.");
|
|
40
|
+
}
|
|
41
|
+
let status;
|
|
36
42
|
await (0, operation_poller_1.pollOperation)({
|
|
37
43
|
apiOrigin: (0, api_1.cloudbuildOrigin)(),
|
|
38
44
|
apiVersion: "v1",
|
|
39
|
-
operationResourceName:
|
|
45
|
+
operationResourceName: cloudBuild.name,
|
|
46
|
+
masterTimeout: 30 * 60 * 1000,
|
|
47
|
+
maxBackoff: 10000,
|
|
48
|
+
doneFn: (b) => {
|
|
49
|
+
status = b?.status;
|
|
50
|
+
return !b?.status || !PENDING_BUILD_STATUSES.includes(b.status);
|
|
51
|
+
},
|
|
40
52
|
});
|
|
53
|
+
if (status !== "SUCCESS") {
|
|
54
|
+
throw new error_1.FirebaseError(`Cloud Build failed with status ${status ?? "UNKNOWN"}. View the build logs at ${cloudBuild.logUrl ?? ""}`);
|
|
55
|
+
}
|
|
41
56
|
}
|
|
42
|
-
async function updateService(service) {
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
async function updateService(service, opts = {}) {
|
|
58
|
+
let updateMask = opts.updateMask;
|
|
59
|
+
if (!updateMask) {
|
|
60
|
+
updateMask = proto.fieldMasks(service, "labels", "annotations", "tags");
|
|
61
|
+
updateMask.push("template.revision");
|
|
62
|
+
}
|
|
45
63
|
const res = await client.patch(service.name, service, {
|
|
46
64
|
queryParams: {
|
|
47
|
-
updateMask:
|
|
65
|
+
updateMask: updateMask.join(","),
|
|
48
66
|
},
|
|
49
67
|
});
|
|
50
68
|
const svc = await (0, operation_poller_1.pollOperation)({
|
|
51
69
|
apiOrigin: (0, api_1.runOrigin)(),
|
|
52
70
|
apiVersion: exports.API_VERSION,
|
|
53
71
|
operationResourceName: res.body.name,
|
|
72
|
+
masterTimeout: opts.pollTimeoutMs,
|
|
54
73
|
});
|
|
55
74
|
return svc;
|
|
56
75
|
}
|
|
57
|
-
async function createService(projectId, location, serviceId, service) {
|
|
76
|
+
async function createService(projectId, location, serviceId, service, opts = {}) {
|
|
58
77
|
const { name, ...serviceBody } = service;
|
|
59
78
|
const res = await client.post(`/projects/${projectId}/locations/${location}/services`, serviceBody, {
|
|
60
79
|
queryParams: {
|
|
@@ -65,6 +84,7 @@ async function createService(projectId, location, serviceId, service) {
|
|
|
65
84
|
apiOrigin: (0, api_1.runOrigin)(),
|
|
66
85
|
apiVersion: exports.API_VERSION,
|
|
67
86
|
operationResourceName: res.body.name,
|
|
87
|
+
masterTimeout: opts.pollTimeoutMs,
|
|
68
88
|
});
|
|
69
89
|
return svc;
|
|
70
90
|
}
|
|
@@ -82,7 +102,7 @@ async function getService(projectId, location, serviceId) {
|
|
|
82
102
|
const res = await client.get(name);
|
|
83
103
|
return res.body;
|
|
84
104
|
}
|
|
85
|
-
async function listServices(projectId) {
|
|
105
|
+
async function listServices(projectId, functionsOnly = true) {
|
|
86
106
|
const allServices = [];
|
|
87
107
|
let pageToken = undefined;
|
|
88
108
|
do {
|
|
@@ -98,7 +118,8 @@ async function listServices(projectId) {
|
|
|
98
118
|
}
|
|
99
119
|
if (res.body.services) {
|
|
100
120
|
for (const service of res.body.services) {
|
|
101
|
-
if (
|
|
121
|
+
if (!functionsOnly ||
|
|
122
|
+
service.labels?.[exports.CLIENT_NAME_LABEL] === "cloud-functions" ||
|
|
102
123
|
service.labels?.[exports.CLIENT_NAME_LABEL] === "cloudfunctions" ||
|
|
103
124
|
service.labels?.[exports.CLIENT_NAME_LABEL] === "firebase-functions") {
|
|
104
125
|
allServices.push(service);
|
package/lib/hosting/api.js
CHANGED
|
@@ -56,7 +56,7 @@ const apiClient = new apiv2_1.Client({
|
|
|
56
56
|
apiVersion: "v1beta1",
|
|
57
57
|
auth: true,
|
|
58
58
|
});
|
|
59
|
-
async function getChannel(project
|
|
59
|
+
async function getChannel(project, site, channelId) {
|
|
60
60
|
try {
|
|
61
61
|
const res = await apiClient.get(`/projects/${project}/sites/${site}/channels/${channelId}`);
|
|
62
62
|
return res.body;
|
|
@@ -68,7 +68,7 @@ async function getChannel(project = "-", site, channelId) {
|
|
|
68
68
|
throw e;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
async function listChannels(project
|
|
71
|
+
async function listChannels(project, site) {
|
|
72
72
|
const channels = [];
|
|
73
73
|
let nextPageToken = "";
|
|
74
74
|
for (;;) {
|
|
@@ -90,30 +90,30 @@ async function listChannels(project = "-", site) {
|
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
async function createChannel(project
|
|
93
|
+
async function createChannel(project, site, channelId, ttlMillis = expireUtils_1.DEFAULT_DURATION) {
|
|
94
94
|
const res = await apiClient.post(`/projects/${project}/sites/${site}/channels?channelId=${channelId}`, { ttl: `${ttlMillis / 1000}s` });
|
|
95
95
|
return res.body;
|
|
96
96
|
}
|
|
97
|
-
async function updateChannelTtl(project
|
|
97
|
+
async function updateChannelTtl(project, site, channelId, ttlMillis = ONE_WEEK_MS) {
|
|
98
98
|
const res = await apiClient.patch(`/projects/${project}/sites/${site}/channels/${channelId}`, { ttl: `${ttlMillis / 1000}s` }, { queryParams: { updateMask: "ttl" } });
|
|
99
99
|
return res.body;
|
|
100
100
|
}
|
|
101
|
-
async function deleteChannel(project
|
|
101
|
+
async function deleteChannel(project, site, channelId) {
|
|
102
102
|
await apiClient.delete(`/projects/${project}/sites/${site}/channels/${channelId}`);
|
|
103
103
|
}
|
|
104
|
-
async function createVersion(siteId, version) {
|
|
105
|
-
const res = await apiClient.post(
|
|
104
|
+
async function createVersion(project, siteId, version) {
|
|
105
|
+
const res = await apiClient.post(`/projects/${project}/sites/${siteId}/versions`, version);
|
|
106
106
|
return res.body.name;
|
|
107
107
|
}
|
|
108
|
-
async function updateVersion(site, versionId, version) {
|
|
109
|
-
const res = await apiClient.patch(
|
|
108
|
+
async function updateVersion(project, site, versionId, version) {
|
|
109
|
+
const res = await apiClient.patch(`/projects/${project}/sites/${site}/versions/${versionId}`, version, {
|
|
110
110
|
queryParams: {
|
|
111
111
|
updateMask: proto.fieldMasks(version, "labels", "config").join(","),
|
|
112
112
|
},
|
|
113
113
|
});
|
|
114
114
|
return res.body;
|
|
115
115
|
}
|
|
116
|
-
async function listVersions(site) {
|
|
116
|
+
async function listVersions(project, site) {
|
|
117
117
|
let pageToken = undefined;
|
|
118
118
|
const versions = [];
|
|
119
119
|
do {
|
|
@@ -121,7 +121,7 @@ async function listVersions(site) {
|
|
|
121
121
|
if (pageToken) {
|
|
122
122
|
queryParams.pageToken = pageToken;
|
|
123
123
|
}
|
|
124
|
-
const res = await apiClient.get(
|
|
124
|
+
const res = await apiClient.get(`/projects/${project}/sites/${site}/versions`, {
|
|
125
125
|
queryParams,
|
|
126
126
|
});
|
|
127
127
|
versions.push(...(res.body.versions ?? []));
|
|
@@ -129,8 +129,8 @@ async function listVersions(site) {
|
|
|
129
129
|
} while (pageToken);
|
|
130
130
|
return versions;
|
|
131
131
|
}
|
|
132
|
-
async function cloneVersion(site, versionName, finalize = false) {
|
|
133
|
-
const res = await apiClient.post(`/projects
|
|
132
|
+
async function cloneVersion(project, site, versionName, finalize = false) {
|
|
133
|
+
const res = await apiClient.post(`/projects/${project}/sites/${site}/versions:clone`, {
|
|
134
134
|
sourceVersion: versionName,
|
|
135
135
|
finalize,
|
|
136
136
|
});
|
|
@@ -143,8 +143,8 @@ async function cloneVersion(site, versionName, finalize = false) {
|
|
|
143
143
|
});
|
|
144
144
|
return pollRes;
|
|
145
145
|
}
|
|
146
|
-
async function createRelease(site, channel, version, partialRelease) {
|
|
147
|
-
const res = await apiClient.post(`/projects
|
|
146
|
+
async function createRelease(project, site, channel, version, partialRelease) {
|
|
147
|
+
const res = await apiClient.post(`/projects/${project}/sites/${site}/channels/${channel}/releases`, partialRelease, { queryParams: { versionName: version } });
|
|
148
148
|
return res.body;
|
|
149
149
|
}
|
|
150
150
|
async function listSites(project) {
|
package/lib/hosting/runTags.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.TODO_TAG_NAME = "this is an invalid tag name so it cannot be real";
|
|
|
14
14
|
async function gcTagsForServices(project, services) {
|
|
15
15
|
const validTagsByServiceByRegion = {};
|
|
16
16
|
const sites = await api.listSites(project);
|
|
17
|
-
const allVersionsNested = await Promise.all(sites.map((site) => api.listVersions(node_path_1.posix.basename(site.name))));
|
|
17
|
+
const allVersionsNested = await Promise.all(sites.map((site) => api.listVersions(project, node_path_1.posix.basename(site.name))));
|
|
18
18
|
const activeVersions = [...(0, functional_1.flattenArray)(allVersionsNested)].filter((version) => {
|
|
19
19
|
return version.status === "CREATED" || version.status === "FINALIZED";
|
|
20
20
|
});
|