firebase-tools 10.9.2 → 11.1.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/README.md +15 -9
- package/lib/accountImporter.js +92 -93
- package/lib/api.js +77 -218
- package/lib/apiv2.js +5 -4
- package/lib/appdistribution/client.js +16 -25
- package/lib/auth.js +69 -47
- package/lib/bin/firebase.js +42 -47
- package/lib/checkValidTargetFilters.js +13 -12
- package/lib/commands/appdistribution-distribute.js +2 -1
- package/lib/commands/appdistribution-testers-add.js +2 -1
- package/lib/commands/appdistribution-testers-remove.js +2 -1
- package/lib/commands/apps-android-sha-create.js +2 -1
- package/lib/commands/apps-android-sha-delete.js +2 -1
- package/lib/commands/apps-android-sha-list.js +2 -1
- package/lib/commands/apps-create.js +2 -1
- package/lib/commands/apps-list.js +2 -1
- package/lib/commands/apps-sdkconfig.js +8 -3
- package/lib/commands/auth-export.js +2 -1
- package/lib/commands/auth-import.js +7 -10
- package/lib/commands/crashlytics-symbols-upload.js +2 -1
- package/lib/commands/database-get.js +4 -3
- package/lib/commands/database-instances-create.js +2 -1
- package/lib/commands/database-instances-list.js +3 -3
- package/lib/commands/database-profile.js +2 -1
- package/lib/commands/database-push.js +2 -1
- package/lib/commands/database-remove.js +2 -1
- package/lib/commands/database-rules-canary.js +2 -1
- package/lib/commands/database-rules-get.js +2 -1
- package/lib/commands/database-rules-list.js +2 -1
- package/lib/commands/database-rules-release.js +2 -1
- package/lib/commands/database-rules-stage.js +2 -1
- package/lib/commands/database-set.js +2 -1
- package/lib/commands/database-settings-get.js +2 -1
- package/lib/commands/database-settings-set.js +2 -1
- package/lib/commands/database-update.js +2 -1
- package/lib/commands/deploy.js +23 -21
- package/lib/commands/emulators-exec.js +2 -1
- package/lib/commands/emulators-export.js +2 -1
- package/lib/commands/emulators-start.js +2 -1
- package/lib/commands/experimental-functions-shell.js +10 -8
- package/lib/commands/ext-configure.js +56 -120
- package/lib/commands/ext-dev-deprecate.js +2 -1
- package/lib/commands/ext-dev-emulators-exec.js +13 -7
- package/lib/commands/ext-dev-emulators-start.js +12 -27
- package/lib/commands/ext-dev-extension-delete.js +2 -1
- package/lib/commands/ext-dev-init.js +2 -1
- package/lib/commands/ext-dev-list.js +2 -1
- package/lib/commands/ext-dev-publish.js +2 -1
- package/lib/commands/ext-dev-register.js +2 -1
- package/lib/commands/ext-dev-undeprecate.js +2 -1
- package/lib/commands/ext-dev-unpublish.js +2 -1
- package/lib/commands/ext-dev-usage.js +2 -1
- package/lib/commands/ext-export.js +2 -1
- package/lib/commands/ext-info.js +2 -1
- package/lib/commands/ext-install.js +14 -198
- package/lib/commands/ext-list.js +2 -1
- package/lib/commands/ext-sources-create.js +2 -1
- package/lib/commands/ext-uninstall.js +9 -92
- package/lib/commands/ext-update.js +67 -225
- package/lib/commands/ext.js +2 -1
- package/lib/commands/firestore-delete.js +2 -1
- package/lib/commands/firestore-indexes-list.js +2 -1
- package/lib/commands/functions-config-clone.js +4 -3
- package/lib/commands/functions-config-export.js +2 -1
- package/lib/commands/functions-config-get.js +2 -1
- package/lib/commands/functions-config-set.js +2 -1
- package/lib/commands/functions-config-unset.js +2 -1
- package/lib/commands/functions-delete.js +2 -1
- package/lib/commands/functions-deletegcfartifacts.js +2 -1
- package/lib/commands/functions-list.js +2 -1
- package/lib/commands/functions-log.js +2 -1
- package/lib/commands/functions-secrets-access.js +2 -1
- package/lib/commands/functions-secrets-destroy.js +2 -1
- package/lib/commands/functions-secrets-get.js +2 -1
- package/lib/commands/functions-secrets-prune.js +2 -1
- package/lib/commands/functions-secrets-set.js +2 -1
- package/lib/commands/functions-shell.js +12 -10
- package/lib/commands/help.js +2 -1
- package/lib/commands/hosting-channel-create.js +2 -1
- package/lib/commands/hosting-channel-delete.js +2 -1
- package/lib/commands/hosting-channel-deploy.js +2 -1
- package/lib/commands/hosting-channel-list.js +2 -1
- package/lib/commands/hosting-channel-open.js +2 -1
- package/lib/commands/hosting-clone.js +2 -1
- package/lib/commands/hosting-disable.js +2 -1
- package/lib/commands/hosting-sites-create.js +2 -1
- package/lib/commands/hosting-sites-delete.js +2 -1
- package/lib/commands/hosting-sites-get.js +2 -1
- package/lib/commands/hosting-sites-list.js +2 -1
- package/lib/commands/index.js +23 -13
- package/lib/commands/init.js +47 -43
- package/lib/commands/login-add.js +2 -1
- package/lib/commands/login-ci.js +2 -1
- package/lib/commands/login-list.js +2 -1
- package/lib/commands/login-use.js +2 -1
- package/lib/commands/login.js +2 -1
- package/lib/commands/logout.js +2 -1
- package/lib/commands/open.js +2 -1
- package/lib/commands/projects-addfirebase.js +2 -1
- package/lib/commands/projects-create.js +2 -1
- package/lib/commands/projects-list.js +2 -1
- package/lib/commands/remoteconfig-get.js +2 -1
- package/lib/commands/remoteconfig-rollback.js +2 -1
- package/lib/commands/remoteconfig-versions-list.js +2 -1
- package/lib/commands/serve.js +29 -27
- package/lib/commands/setup-emulators-database.js +2 -1
- package/lib/commands/setup-emulators-firestore.js +2 -1
- package/lib/commands/setup-emulators-pubsub.js +2 -1
- package/lib/commands/setup-emulators-storage.js +2 -1
- package/lib/commands/setup-emulators-ui.js +2 -1
- package/lib/commands/target-apply.js +2 -1
- package/lib/commands/target-clear.js +2 -1
- package/lib/commands/target-remove.js +2 -1
- package/lib/commands/target.js +2 -1
- package/lib/commands/use.js +54 -52
- package/lib/config.js +3 -3
- package/lib/deploy/database/deploy.js +3 -2
- package/lib/deploy/database/index.js +8 -5
- package/lib/deploy/database/prepare.js +22 -19
- package/lib/deploy/database/release.js +12 -9
- package/lib/deploy/firestore/prepare.js +2 -2
- package/lib/deploy/functions/build.js +32 -20
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +187 -54
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +14 -2
- package/lib/deploy/functions/services/database.js +14 -0
- package/lib/deploy/functions/services/index.js +14 -0
- package/lib/deploy/index.js +3 -3
- package/lib/deploy/lifecycleHooks.js +23 -20
- package/lib/deploy/remoteconfig/functions.js +18 -14
- package/lib/deploy/remoteconfig/prepare.js +2 -2
- package/lib/emulator/auth/apiSpec.js +14 -46
- package/lib/emulator/auth/operations.js +6 -29
- package/lib/emulator/auth/state.js +2 -25
- package/lib/emulator/commandUtils.js +1 -1
- package/lib/emulator/controller.js +3 -3
- package/lib/emulator/databaseEmulator.js +9 -7
- package/lib/emulator/downloadableEmulators.js +6 -6
- package/lib/emulator/extensionsEmulator.js +7 -3
- package/lib/emulator/firestoreEmulator.js +10 -12
- package/lib/emulator/functionsEmulator.js +39 -42
- package/lib/emulator/hubClient.js +11 -22
- package/lib/emulator/hubExport.js +26 -16
- package/lib/emulator/portUtils.js +2 -0
- package/lib/emulator/storage/crc.js +3 -0
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/errorOut.js +2 -2
- package/lib/extensions/extensionsHelper.js +4 -5
- package/lib/extensions/manifest.js +5 -11
- package/lib/firebaseConfigValidate.js +1 -1
- package/lib/firestore/checkDatabaseType.js +4 -5
- package/lib/firestore/indexes.js +17 -34
- package/lib/functions/events/v2.js +7 -1
- package/lib/functionsConfigClone.js +43 -41
- package/lib/gcp/cloudfunctionsv2.js +17 -2
- package/lib/gcp/iam.js +1 -1
- package/lib/gcp/index.js +10 -10
- package/lib/gcp/runtimeconfig.js +45 -47
- package/lib/gcp/storage.js +2 -4
- package/lib/hosting/cloudRunProxy.js +19 -15
- package/lib/index.js +29 -28
- package/lib/init/features/database.js +11 -5
- package/lib/init/features/functions/index.js +1 -1
- package/lib/init/features/functions/javascript.js +23 -20
- package/lib/init/features/functions/npm-dependencies.js +17 -14
- package/lib/init/features/functions/typescript.js +27 -24
- package/lib/init/features/hosting/github.js +5 -4
- package/lib/loadCJSON.js +9 -6
- package/lib/logError.js +15 -12
- package/lib/management/apps.js +47 -43
- package/lib/management/database.js +33 -31
- package/lib/management/projects.js +13 -7
- package/lib/parseBoltRules.js +15 -14
- package/lib/profileReport.js +503 -511
- package/lib/profiler.js +4 -4
- package/lib/requireAuth.js +0 -1
- package/lib/responseToError.js +8 -5
- package/lib/rtdb.js +31 -29
- package/lib/scopes.js +9 -9
- package/npm-shrinkwrap.json +1485 -670
- package/package.json +21 -22
- package/standalone/package.json +1 -1
|
@@ -1,68 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionsConfigClone = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const clc = require("cli-color");
|
|
6
|
+
const error_1 = require("./error");
|
|
7
|
+
const functionsConfig = require("./functionsConfig");
|
|
8
|
+
const runtimeconfig = require("./gcp/runtimeconfig");
|
|
9
|
+
function matchPrefix(short, long) {
|
|
8
10
|
if (short.length > long.length) {
|
|
9
11
|
return false;
|
|
10
12
|
}
|
|
11
|
-
return _.reduce(short,
|
|
13
|
+
return _.reduce(short, (accum, x, i) => {
|
|
12
14
|
return accum && x === long[i];
|
|
13
15
|
}, true);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
_.forEach(except,
|
|
16
|
+
}
|
|
17
|
+
function applyExcept(json, except) {
|
|
18
|
+
_.forEach(except, (key) => {
|
|
17
19
|
_.unset(json, key);
|
|
18
20
|
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return runtimeconfig.variables.get(varName).then(
|
|
22
|
-
|
|
21
|
+
}
|
|
22
|
+
function cloneVariable(varName, toProject) {
|
|
23
|
+
return runtimeconfig.variables.get(varName).then((variable) => {
|
|
24
|
+
const id = functionsConfig.varNameToIds(variable.name);
|
|
23
25
|
return runtimeconfig.variables.set(toProject, id.config, id.variable, variable.text);
|
|
24
26
|
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return runtimeconfig.variables.list(configName).then(
|
|
28
|
-
return Promise.all(_.map(variables,
|
|
29
|
-
return
|
|
27
|
+
}
|
|
28
|
+
function cloneConfig(configName, toProject) {
|
|
29
|
+
return runtimeconfig.variables.list(configName).then((variables) => {
|
|
30
|
+
return Promise.all(_.map(variables, (variable) => {
|
|
31
|
+
return cloneVariable(variable.name, toProject);
|
|
30
32
|
}));
|
|
31
33
|
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
}
|
|
35
|
+
async function cloneConfigOrVariable(key, fromProject, toProject) {
|
|
36
|
+
const parts = key.split(".");
|
|
35
37
|
if (_.includes(functionsConfig.RESERVED_NAMESPACES, parts[0])) {
|
|
36
|
-
throw new FirebaseError("Cannot clone reserved namespace " + clc.bold(parts[0]));
|
|
38
|
+
throw new error_1.FirebaseError("Cannot clone reserved namespace " + clc.bold(parts[0]));
|
|
37
39
|
}
|
|
38
|
-
|
|
40
|
+
const configName = _.join(["projects", fromProject, "configs", parts[0]], "/");
|
|
39
41
|
if (parts.length === 1) {
|
|
40
|
-
return
|
|
42
|
+
return cloneConfig(configName, toProject);
|
|
41
43
|
}
|
|
42
|
-
return runtimeconfig.variables.list(configName).then(
|
|
43
|
-
|
|
44
|
-
_.forEach(variables,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
promises.push(
|
|
44
|
+
return runtimeconfig.variables.list(configName).then((variables) => {
|
|
45
|
+
const promises = [];
|
|
46
|
+
_.forEach(variables, (variable) => {
|
|
47
|
+
const varId = functionsConfig.varNameToIds(variable.name).variable;
|
|
48
|
+
const variablePrefixFilter = parts.slice(1);
|
|
49
|
+
if (matchPrefix(variablePrefixFilter, varId.split("/"))) {
|
|
50
|
+
promises.push(cloneVariable(variable.name, toProject));
|
|
49
51
|
}
|
|
50
52
|
});
|
|
51
53
|
return Promise.all(promises);
|
|
52
54
|
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
except = except || [];
|
|
55
|
+
}
|
|
56
|
+
async function functionsConfigClone(fromProject, toProject, only, except = []) {
|
|
56
57
|
if (only) {
|
|
57
|
-
return Promise.all(_.map(only,
|
|
58
|
-
return
|
|
58
|
+
return Promise.all(_.map(only, (key) => {
|
|
59
|
+
return cloneConfigOrVariable(key, fromProject, toProject);
|
|
59
60
|
}));
|
|
60
61
|
}
|
|
61
|
-
return functionsConfig.materializeAll(fromProject).then(
|
|
62
|
+
return functionsConfig.materializeAll(fromProject).then((toClone) => {
|
|
62
63
|
_.unset(toClone, "firebase");
|
|
63
|
-
|
|
64
|
-
return Promise.all(_.map(toClone,
|
|
64
|
+
applyExcept(toClone, except);
|
|
65
|
+
return Promise.all(_.map(toClone, (val, configId) => {
|
|
65
66
|
return functionsConfig.setVariablesRecursive(toProject, configId, "", val);
|
|
66
67
|
}));
|
|
67
68
|
});
|
|
68
|
-
}
|
|
69
|
+
}
|
|
70
|
+
exports.functionsConfigClone = functionsConfigClone;
|
|
@@ -209,6 +209,13 @@ function functionFromEndpoint(endpoint, source) {
|
|
|
209
209
|
for (const [attribute, value] of Object.entries(endpoint.eventTrigger.eventFilters)) {
|
|
210
210
|
gcfFunction.eventTrigger.eventFilters.push({ attribute, value });
|
|
211
211
|
}
|
|
212
|
+
for (const [attribute, value] of Object.entries(endpoint.eventTrigger.eventFilterPathPatterns || {})) {
|
|
213
|
+
gcfFunction.eventTrigger.eventFilters.push({
|
|
214
|
+
attribute,
|
|
215
|
+
value,
|
|
216
|
+
operator: "match-path-pattern",
|
|
217
|
+
});
|
|
218
|
+
}
|
|
212
219
|
}
|
|
213
220
|
proto.renameIfPresent(gcfFunction.eventTrigger, endpoint.eventTrigger, "triggerRegion", "region");
|
|
214
221
|
proto.copyIfPresent(gcfFunction.eventTrigger, endpoint.eventTrigger, "channel");
|
|
@@ -277,8 +284,16 @@ function endpointFromFunction(gcfFunction) {
|
|
|
277
284
|
trigger.eventTrigger.eventFilters.topic = gcfFunction.eventTrigger.pubsubTopic;
|
|
278
285
|
}
|
|
279
286
|
else {
|
|
280
|
-
for (const
|
|
281
|
-
|
|
287
|
+
for (const eventFilter of gcfFunction.eventTrigger.eventFilters || []) {
|
|
288
|
+
if (eventFilter.operator === "match-path-pattern") {
|
|
289
|
+
if (!trigger.eventTrigger.eventFilterPathPatterns) {
|
|
290
|
+
trigger.eventTrigger.eventFilterPathPatterns = {};
|
|
291
|
+
}
|
|
292
|
+
trigger.eventTrigger.eventFilterPathPatterns[eventFilter.attribute] = eventFilter.value;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
trigger.eventTrigger.eventFilters[eventFilter.attribute] = eventFilter.value;
|
|
296
|
+
}
|
|
282
297
|
}
|
|
283
298
|
}
|
|
284
299
|
proto.copyIfPresent(trigger.eventTrigger, gcfFunction.eventTrigger, "channel");
|
package/lib/gcp/iam.js
CHANGED
package/lib/gcp/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rules = exports.storage = exports.pubsub = exports.iam = exports.cloudlogging = exports.cloudscheduler = exports.cloudfunctions = exports.cloudbilling = void 0;
|
|
4
|
+
exports.cloudbilling = require("./cloudbilling");
|
|
5
|
+
exports.cloudfunctions = require("./cloudfunctions");
|
|
6
|
+
exports.cloudscheduler = require("./cloudscheduler");
|
|
7
|
+
exports.cloudlogging = require("./cloudlogging");
|
|
8
|
+
exports.iam = require("./iam");
|
|
9
|
+
exports.pubsub = require("./pubsub");
|
|
10
|
+
exports.storage = require("./storage");
|
|
11
|
+
exports.rules = require("./rules");
|
package/lib/gcp/runtimeconfig.js
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.variables = exports.configs = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const apiv2_1 = require("../apiv2");
|
|
7
|
+
const logger_1 = require("../logger");
|
|
6
8
|
const API_VERSION = "v1beta1";
|
|
7
|
-
const apiClient = new Client({ urlPrefix: runtimeconfigOrigin, apiVersion: API_VERSION });
|
|
8
|
-
function
|
|
9
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.runtimeconfigOrigin, apiVersion: API_VERSION });
|
|
10
|
+
function listConfigs(projectId) {
|
|
9
11
|
return apiClient
|
|
10
12
|
.get(`/projects/${projectId}/configs`, {
|
|
11
13
|
retryCodes: [500, 503],
|
|
12
14
|
})
|
|
13
|
-
.then(
|
|
14
|
-
return resp.body.configs;
|
|
15
|
-
});
|
|
15
|
+
.then((resp) => resp.body.configs);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
17
|
+
function createConfig(projectId, configId) {
|
|
18
|
+
const path = _.join(["projects", projectId, "configs"], "/");
|
|
19
19
|
return apiClient
|
|
20
20
|
.post(`/projects/${projectId}/configs`, {
|
|
21
21
|
name: path + "/" + configId,
|
|
22
22
|
}, {
|
|
23
23
|
retryCodes: [500, 503],
|
|
24
24
|
})
|
|
25
|
-
.catch(
|
|
25
|
+
.catch((err) => {
|
|
26
26
|
if (_.get(err, "context.response.statusCode") === 409) {
|
|
27
27
|
return Promise.resolve();
|
|
28
28
|
}
|
|
29
29
|
return Promise.reject(err);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function deleteConfig(projectId, configId) {
|
|
33
33
|
return apiClient
|
|
34
34
|
.delete(`/projects/${projectId}/configs/${configId}`, {
|
|
35
35
|
retryCodes: [500, 503],
|
|
36
36
|
})
|
|
37
|
-
.catch(
|
|
37
|
+
.catch((err) => {
|
|
38
38
|
if (_.get(err, "context.response.statusCode") === 404) {
|
|
39
|
-
logger.debug("Config already deleted.");
|
|
39
|
+
logger_1.logger.debug("Config already deleted.");
|
|
40
40
|
return Promise.resolve();
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
throw err;
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function listVariables(configPath) {
|
|
46
46
|
return apiClient
|
|
47
47
|
.get(`${configPath}/variables`, {
|
|
48
48
|
retryCodes: [500, 503],
|
|
49
49
|
})
|
|
50
|
-
.then(
|
|
50
|
+
.then((resp) => {
|
|
51
51
|
return Promise.resolve(resp.body.variables);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function getVariable(varPath) {
|
|
55
55
|
return apiClient
|
|
56
56
|
.get(varPath, {
|
|
57
57
|
retryCodes: [500, 503],
|
|
58
58
|
})
|
|
59
|
-
.then(
|
|
59
|
+
.then((resp) => {
|
|
60
60
|
return Promise.resolve(resp.body);
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function createVariable(projectId, configId, varId, value) {
|
|
64
64
|
const path = `/projects/${projectId}/configs/${configId}/variables`;
|
|
65
65
|
return apiClient
|
|
66
66
|
.post(path, {
|
|
@@ -69,16 +69,16 @@ function _createVariable(projectId, configId, varId, value) {
|
|
|
69
69
|
}, {
|
|
70
70
|
retryCodes: [500, 503],
|
|
71
71
|
})
|
|
72
|
-
.catch(
|
|
72
|
+
.catch((err) => {
|
|
73
73
|
if (_.get(err, "context.response.statusCode") === 404) {
|
|
74
|
-
return
|
|
75
|
-
return
|
|
74
|
+
return createConfig(projectId, configId).then(() => {
|
|
75
|
+
return createVariable(projectId, configId, varId, value);
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
return Promise.reject(err);
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function updateVariable(projectId, configId, varId, value) {
|
|
82
82
|
const path = `/projects/${projectId}/configs/${configId}/variables/${varId}`;
|
|
83
83
|
return apiClient.put(path, {
|
|
84
84
|
name: path,
|
|
@@ -87,43 +87,41 @@ function _updateVariable(projectId, configId, varId, value) {
|
|
|
87
87
|
retryCodes: [500, 503],
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
.then(
|
|
94
|
-
return
|
|
90
|
+
function setVariable(projectId, configId, varId, value) {
|
|
91
|
+
const path = _.join(["projects", projectId, "configs", configId, "variables", varId], "/");
|
|
92
|
+
return getVariable(path)
|
|
93
|
+
.then(() => {
|
|
94
|
+
return updateVariable(projectId, configId, varId, value);
|
|
95
95
|
})
|
|
96
|
-
.catch(
|
|
96
|
+
.catch((err) => {
|
|
97
97
|
if (_.get(err, "context.response.statusCode") === 404) {
|
|
98
|
-
return
|
|
98
|
+
return createVariable(projectId, configId, varId, value);
|
|
99
99
|
}
|
|
100
100
|
return Promise.reject(err);
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function deleteVariable(projectId, configId, varId) {
|
|
104
104
|
return apiClient
|
|
105
105
|
.delete(`/projects/${projectId}/configs/${configId}/variables/${varId}`, {
|
|
106
106
|
retryCodes: [500, 503],
|
|
107
107
|
queryParams: { recursive: "true" },
|
|
108
108
|
})
|
|
109
|
-
.catch(
|
|
109
|
+
.catch((err) => {
|
|
110
110
|
if (_.get(err, "context.response.statusCode") === 404) {
|
|
111
|
-
logger.debug("Variable already deleted.");
|
|
111
|
+
logger_1.logger.debug("Variable already deleted.");
|
|
112
112
|
return Promise.resolve();
|
|
113
113
|
}
|
|
114
114
|
return Promise.reject(err);
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
delete: _deleteVariable,
|
|
128
|
-
},
|
|
117
|
+
exports.configs = {
|
|
118
|
+
list: listConfigs,
|
|
119
|
+
create: createConfig,
|
|
120
|
+
delete: deleteConfig,
|
|
121
|
+
};
|
|
122
|
+
exports.variables = {
|
|
123
|
+
list: listVariables,
|
|
124
|
+
get: getVariable,
|
|
125
|
+
set: setVariable,
|
|
126
|
+
delete: deleteVariable,
|
|
129
127
|
};
|
package/lib/gcp/storage.js
CHANGED
|
@@ -62,10 +62,8 @@ async function uploadObject(source, bucketName) {
|
|
|
62
62
|
}
|
|
63
63
|
exports.uploadObject = uploadObject;
|
|
64
64
|
function deleteObject(location) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
origin: api_1.default.storageOrigin,
|
|
68
|
-
});
|
|
65
|
+
const localAPIClient = new apiv2_1.Client({ urlPrefix: api_1.storageOrigin });
|
|
66
|
+
return localAPIClient.delete(location);
|
|
69
67
|
}
|
|
70
68
|
exports.deleteObject = deleteObject;
|
|
71
69
|
async function getBucket(bucketName) {
|
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const apiv2_1 = require("../apiv2");
|
|
4
|
+
const api_1 = require("../api");
|
|
4
5
|
const proxy_1 = require("./proxy");
|
|
5
|
-
const
|
|
6
|
+
const error_1 = require("../error");
|
|
6
7
|
const logger_1 = require("../logger");
|
|
7
|
-
const
|
|
8
|
+
const projectUtils_1 = require("../projectUtils");
|
|
8
9
|
const cloudRunCache = {};
|
|
9
|
-
|
|
10
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.cloudRunApiOrigin, apiVersion: "v1" });
|
|
11
|
+
async function getCloudRunUrl(rewrite, projectId) {
|
|
12
|
+
var _a;
|
|
10
13
|
const alreadyFetched = cloudRunCache[`${rewrite.run.region}/${rewrite.run.serviceId}`];
|
|
11
14
|
if (alreadyFetched) {
|
|
12
15
|
return Promise.resolve(alreadyFetched);
|
|
13
16
|
}
|
|
14
|
-
const path = `/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
const url = (
|
|
17
|
+
const path = `/projects/${projectId}/locations/${rewrite.run.region || "us-central1"}/services/${rewrite.run.serviceId}`;
|
|
18
|
+
try {
|
|
19
|
+
logger_1.logger.info(`[hosting] Looking up Cloud Run service "${path}" for its URL`);
|
|
20
|
+
const res = await apiClient.get(path);
|
|
21
|
+
const url = (_a = res.body.status) === null || _a === void 0 ? void 0 : _a.url;
|
|
19
22
|
if (!url) {
|
|
20
|
-
|
|
23
|
+
throw new error_1.FirebaseError("Cloud Run URL doesn't exist in response.");
|
|
21
24
|
}
|
|
22
25
|
cloudRunCache[`${rewrite.run.region}/${rewrite.run.serviceId}`] = url;
|
|
23
26
|
return url;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new error_1.FirebaseError(`Error looking up URL for Cloud Run service: ${err}`, {
|
|
30
|
+
original: err,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
29
33
|
}
|
|
30
34
|
function default_1(options) {
|
|
31
35
|
return async (rewrite) => {
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
const program = require("commander");
|
|
3
|
+
const clc = require("cli-color");
|
|
4
|
+
const leven = require("leven");
|
|
5
|
+
const logger_1 = require("./logger");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const pkg = require("../package.json");
|
|
8
8
|
program.version(pkg.version);
|
|
9
9
|
program.option("-P, --project <alias_or_project_id>", "the Firebase project to use for this command");
|
|
10
10
|
program.option("--account <email>", "the Google account to use for authorization");
|
|
@@ -14,33 +14,34 @@ program.option("--non-interactive", "error out of the command instead of waiting
|
|
|
14
14
|
program.option("-i, --interactive", "force prompts to be displayed");
|
|
15
15
|
program.option("--debug", "print verbose debug output and keep a debug log file");
|
|
16
16
|
program.option("-c, --config <path>", "path to the firebase.json file to use for configuration");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const client = {
|
|
18
|
+
cli: program,
|
|
19
|
+
logger: require("./logger"),
|
|
20
|
+
errorOut: require("./errorOut").errorOut,
|
|
21
|
+
getCommand: (name) => {
|
|
22
|
+
for (let i = 0; i < client.cli.commands.length; i++) {
|
|
23
|
+
if (client.cli.commands[i]._name === name) {
|
|
24
|
+
return client.cli.commands[i];
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
return;
|
|
28
|
+
},
|
|
28
29
|
};
|
|
29
|
-
require("./commands")(client);
|
|
30
|
+
require("./commands").load(client);
|
|
30
31
|
function suggestCommands(cmd, cmdList) {
|
|
31
|
-
|
|
32
|
+
const suggestion = cmdList.find((c) => {
|
|
32
33
|
return leven(c, cmd) < c.length * 0.4;
|
|
33
34
|
});
|
|
34
35
|
if (suggestion) {
|
|
35
|
-
logger.error();
|
|
36
|
-
logger.error("Did you mean " + clc.bold(suggestion) + "?");
|
|
36
|
+
logger_1.logger.error();
|
|
37
|
+
logger_1.logger.error("Did you mean " + clc.bold(suggestion) + "?");
|
|
37
38
|
return suggestion;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
+
const commandNames = program.commands.map((cmd) => {
|
|
41
42
|
return cmd._name;
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
const RENAMED_COMMANDS = {
|
|
44
45
|
"delete-site": "hosting:disable",
|
|
45
46
|
"disable:hosting": "hosting:disable",
|
|
46
47
|
"data:get": "database:get",
|
|
@@ -52,13 +53,13 @@ var RENAMED_COMMANDS = {
|
|
|
52
53
|
"deploy:database": "deploy --only database",
|
|
53
54
|
"prefs:token": "login:ci",
|
|
54
55
|
};
|
|
55
|
-
program.action(
|
|
56
|
-
setupLoggers();
|
|
57
|
-
|
|
58
|
-
logger.error(clc.bold.red("Error:"), clc.bold(cmd), "is not a Firebase command");
|
|
56
|
+
program.action((_, args) => {
|
|
57
|
+
(0, utils_1.setupLoggers)();
|
|
58
|
+
const cmd = args[0];
|
|
59
|
+
logger_1.logger.error(clc.bold.red("Error:"), clc.bold(cmd), "is not a Firebase command");
|
|
59
60
|
if (RENAMED_COMMANDS[cmd]) {
|
|
60
|
-
logger.error();
|
|
61
|
-
logger.error(clc.bold(cmd) + " has been renamed, please run", clc.bold("firebase " + RENAMED_COMMANDS[cmd]), "instead");
|
|
61
|
+
logger_1.logger.error();
|
|
62
|
+
logger_1.logger.error(clc.bold(cmd) + " has been renamed, please run", clc.bold("firebase " + RENAMED_COMMANDS[cmd]), "instead");
|
|
62
63
|
}
|
|
63
64
|
else {
|
|
64
65
|
if (!suggestCommands(cmd, commandNames)) {
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.doSetup = void 0;
|
|
4
4
|
const clc = require("cli-color");
|
|
5
|
-
const api = require("../../api");
|
|
6
5
|
const prompt_1 = require("../../prompt");
|
|
7
6
|
const logger_1 = require("../../logger");
|
|
8
7
|
const utils = require("../../utils");
|
|
@@ -12,16 +11,23 @@ const ora = require("ora");
|
|
|
12
11
|
const ensureApiEnabled_1 = require("../../ensureApiEnabled");
|
|
13
12
|
const getDefaultDatabaseInstance_1 = require("../../getDefaultDatabaseInstance");
|
|
14
13
|
const error_1 = require("../../error");
|
|
14
|
+
const apiv2_1 = require("../../apiv2");
|
|
15
15
|
const DEFAULT_RULES = JSON.stringify({ rules: { ".read": "auth != null", ".write": "auth != null" } }, null, 2);
|
|
16
16
|
async function getDBRules(instanceDetails) {
|
|
17
17
|
if (!instanceDetails || !instanceDetails.name) {
|
|
18
18
|
return DEFAULT_RULES;
|
|
19
19
|
}
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const client = new apiv2_1.Client({ urlPrefix: instanceDetails.databaseUrl });
|
|
21
|
+
const response = await client.request({
|
|
22
|
+
method: "GET",
|
|
23
|
+
path: "/.settings/rules.json",
|
|
24
|
+
responseType: "stream",
|
|
25
|
+
resolveOnHTTPError: true,
|
|
23
26
|
});
|
|
24
|
-
|
|
27
|
+
if (response.status !== 200) {
|
|
28
|
+
throw new error_1.FirebaseError(`Failed to fetch current rules. Code: ${response.status}`);
|
|
29
|
+
}
|
|
30
|
+
return await response.response.text();
|
|
25
31
|
}
|
|
26
32
|
function writeDBRules(rules, logMessagePrefix, filename, config) {
|
|
27
33
|
config.writeProjectFile(filename, rules);
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setup = void 0;
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const npm_dependencies_1 = require("./npm-dependencies");
|
|
8
|
+
const prompt_1 = require("../../../prompt");
|
|
9
|
+
const TEMPLATE_ROOT = path.resolve(__dirname, "../../../../templates/init/functions/javascript/");
|
|
10
|
+
const INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "index.js"), "utf8");
|
|
11
|
+
const PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.lint.json"), "utf8");
|
|
12
|
+
const PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.nolint.json"), "utf8");
|
|
13
|
+
const ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_eslintrc"), "utf8");
|
|
14
|
+
const GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8");
|
|
15
|
+
function setup(setup, config) {
|
|
16
|
+
return (0, prompt_1.prompt)(setup.functions, [
|
|
15
17
|
{
|
|
16
18
|
name: "lint",
|
|
17
19
|
type: "confirm",
|
|
@@ -19,24 +21,25 @@ module.exports = function (setup, config) {
|
|
|
19
21
|
default: false,
|
|
20
22
|
},
|
|
21
23
|
])
|
|
22
|
-
.then(
|
|
24
|
+
.then(() => {
|
|
23
25
|
if (setup.functions.lint) {
|
|
24
26
|
_.set(setup, "config.functions.predeploy", ['npm --prefix "$RESOURCE_DIR" run lint']);
|
|
25
27
|
return config
|
|
26
28
|
.askWriteProjectFile("functions/package.json", PACKAGE_LINTING_TEMPLATE)
|
|
27
|
-
.then(
|
|
29
|
+
.then(() => {
|
|
28
30
|
config.askWriteProjectFile("functions/.eslintrc.js", ESLINT_TEMPLATE);
|
|
29
31
|
});
|
|
30
32
|
}
|
|
31
33
|
return config.askWriteProjectFile("functions/package.json", PACKAGE_NO_LINTING_TEMPLATE);
|
|
32
34
|
})
|
|
33
|
-
.then(
|
|
35
|
+
.then(() => {
|
|
34
36
|
return config.askWriteProjectFile("functions/index.js", INDEX_TEMPLATE);
|
|
35
37
|
})
|
|
36
|
-
.then(
|
|
38
|
+
.then(() => {
|
|
37
39
|
return config.askWriteProjectFile("functions/.gitignore", GITIGNORE_TEMPLATE);
|
|
38
40
|
})
|
|
39
|
-
.then(
|
|
40
|
-
return
|
|
41
|
+
.then(() => {
|
|
42
|
+
return (0, npm_dependencies_1.askInstallDependencies)(setup.functions, config);
|
|
41
43
|
});
|
|
42
|
-
}
|
|
44
|
+
}
|
|
45
|
+
exports.setup = setup;
|