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,34 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.askInstallDependencies = void 0;
|
|
4
|
+
const spawn = require("cross-spawn");
|
|
5
|
+
const logger_1 = require("../../../logger");
|
|
6
|
+
const prompt_1 = require("../../../prompt");
|
|
7
|
+
function askInstallDependencies(setup, config) {
|
|
8
|
+
return (0, prompt_1.prompt)(setup, [
|
|
7
9
|
{
|
|
8
10
|
name: "npm",
|
|
9
11
|
type: "confirm",
|
|
10
12
|
message: "Do you want to install dependencies with npm now?",
|
|
11
13
|
default: true,
|
|
12
14
|
},
|
|
13
|
-
]).then(
|
|
15
|
+
]).then(() => {
|
|
14
16
|
if (setup.npm) {
|
|
15
|
-
return new Promise(
|
|
16
|
-
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
const installer = spawn("npm", ["install"], {
|
|
17
19
|
cwd: config.projectDir + "/functions",
|
|
18
20
|
stdio: "inherit",
|
|
19
21
|
});
|
|
20
|
-
installer.on("error",
|
|
21
|
-
logger.debug(err.stack);
|
|
22
|
+
installer.on("error", (err) => {
|
|
23
|
+
logger_1.logger.debug(err.stack);
|
|
22
24
|
});
|
|
23
|
-
installer.on("close",
|
|
25
|
+
installer.on("close", (code) => {
|
|
24
26
|
if (code === 0) {
|
|
25
27
|
return resolve();
|
|
26
28
|
}
|
|
27
|
-
logger.info();
|
|
28
|
-
logger.error("NPM install failed, continuing with Firebase initialization...");
|
|
29
|
+
logger_1.logger.info();
|
|
30
|
+
logger_1.logger.error("NPM install failed, continuing with Firebase initialization...");
|
|
29
31
|
return resolve();
|
|
30
32
|
});
|
|
31
33
|
});
|
|
32
34
|
}
|
|
33
35
|
});
|
|
34
|
-
}
|
|
36
|
+
}
|
|
37
|
+
exports.askInstallDependencies = askInstallDependencies;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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/typescript/");
|
|
10
|
+
const PACKAGE_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.lint.json"), "utf8");
|
|
11
|
+
const PACKAGE_NO_LINTING_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "package.nolint.json"), "utf8");
|
|
12
|
+
const ESLINT_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_eslintrc"), "utf8");
|
|
13
|
+
const TSCONFIG_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "tsconfig.json"), "utf8");
|
|
14
|
+
const TSCONFIG_DEV_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "tsconfig.dev.json"), "utf8");
|
|
15
|
+
const INDEX_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "index.ts"), "utf8");
|
|
16
|
+
const GITIGNORE_TEMPLATE = fs.readFileSync(path.join(TEMPLATE_ROOT, "_gitignore"), "utf8");
|
|
17
|
+
function setup(setup, config) {
|
|
18
|
+
return (0, prompt_1.prompt)(setup.functions, [
|
|
17
19
|
{
|
|
18
20
|
name: "lint",
|
|
19
21
|
type: "confirm",
|
|
@@ -21,7 +23,7 @@ module.exports = function (setup, config) {
|
|
|
21
23
|
default: true,
|
|
22
24
|
},
|
|
23
25
|
])
|
|
24
|
-
.then(
|
|
26
|
+
.then(() => {
|
|
25
27
|
if (setup.functions.lint) {
|
|
26
28
|
_.set(setup, "config.functions.predeploy", [
|
|
27
29
|
'npm --prefix "$RESOURCE_DIR" run lint',
|
|
@@ -29,28 +31,29 @@ module.exports = function (setup, config) {
|
|
|
29
31
|
]);
|
|
30
32
|
return config
|
|
31
33
|
.askWriteProjectFile("functions/package.json", PACKAGE_LINTING_TEMPLATE)
|
|
32
|
-
.then(
|
|
34
|
+
.then(() => {
|
|
33
35
|
return config.askWriteProjectFile("functions/.eslintrc.js", ESLINT_TEMPLATE);
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
_.set(setup, "config.functions.predeploy", 'npm --prefix "$RESOURCE_DIR" run build');
|
|
37
39
|
return config.askWriteProjectFile("functions/package.json", PACKAGE_NO_LINTING_TEMPLATE);
|
|
38
40
|
})
|
|
39
|
-
.then(
|
|
41
|
+
.then(() => {
|
|
40
42
|
return config.askWriteProjectFile("functions/tsconfig.json", TSCONFIG_TEMPLATE);
|
|
41
43
|
})
|
|
42
|
-
.then(
|
|
44
|
+
.then(() => {
|
|
43
45
|
if (setup.functions.lint) {
|
|
44
46
|
return config.askWriteProjectFile("functions/tsconfig.dev.json", TSCONFIG_DEV_TEMPLATE);
|
|
45
47
|
}
|
|
46
48
|
})
|
|
47
|
-
.then(
|
|
49
|
+
.then(() => {
|
|
48
50
|
return config.askWriteProjectFile("functions/src/index.ts", INDEX_TEMPLATE);
|
|
49
51
|
})
|
|
50
|
-
.then(
|
|
52
|
+
.then(() => {
|
|
51
53
|
return config.askWriteProjectFile("functions/.gitignore", GITIGNORE_TEMPLATE);
|
|
52
54
|
})
|
|
53
|
-
.then(
|
|
54
|
-
return
|
|
55
|
+
.then(() => {
|
|
56
|
+
return (0, npm_dependencies_1.askInstallDependencies)(setup.functions, config);
|
|
55
57
|
});
|
|
56
|
-
}
|
|
58
|
+
}
|
|
59
|
+
exports.setup = setup;
|
|
@@ -7,7 +7,7 @@ const yaml = require("js-yaml");
|
|
|
7
7
|
const js_yaml_1 = require("js-yaml");
|
|
8
8
|
const ora = require("ora");
|
|
9
9
|
const path = require("path");
|
|
10
|
-
const
|
|
10
|
+
const libsodium = require("libsodium-wrappers");
|
|
11
11
|
const auth_1 = require("../../../auth");
|
|
12
12
|
const fsutils_1 = require("../../../fsutils");
|
|
13
13
|
const iam_1 = require("../../../gcp/iam");
|
|
@@ -60,7 +60,7 @@ async function initGitHub(setup, config, options) {
|
|
|
60
60
|
const spinnerSecrets = ora(`Uploading service account secrets to repository: ${repo}`);
|
|
61
61
|
spinnerSecrets.start();
|
|
62
62
|
const encryptedServiceAccountJSON = encryptServiceAccountJSON(serviceAccountJSON, key);
|
|
63
|
-
await uploadSecretToGitHub(repo, ghAccessToken, encryptedServiceAccountJSON, keyId, githubSecretName);
|
|
63
|
+
await uploadSecretToGitHub(repo, ghAccessToken, await encryptedServiceAccountJSON, keyId, githubSecretName);
|
|
64
64
|
spinnerSecrets.stop();
|
|
65
65
|
(0, utils_1.logSuccess)(`Uploaded service account JSON to GitHub as secret ${(0, cli_color_1.bold)(githubSecretName)}.`);
|
|
66
66
|
(0, utils_1.logBullet)(`You can manage your secrets at https://github.com/${repo}/settings/secrets.`);
|
|
@@ -374,9 +374,10 @@ async function createServiceAccountAndKey(options, repo, accountId) {
|
|
|
374
374
|
const serviceAccountJSON = buf.toString();
|
|
375
375
|
return serviceAccountJSON;
|
|
376
376
|
}
|
|
377
|
-
function encryptServiceAccountJSON(serviceAccountJSON, key) {
|
|
377
|
+
async function encryptServiceAccountJSON(serviceAccountJSON, key) {
|
|
378
378
|
const messageBytes = Buffer.from(serviceAccountJSON);
|
|
379
379
|
const keyBytes = Buffer.from(key, "base64");
|
|
380
|
-
|
|
380
|
+
await libsodium.ready;
|
|
381
|
+
const encryptedBytes = libsodium.crypto_box_seal(messageBytes, keyBytes);
|
|
381
382
|
return Buffer.from(encryptedBytes).toString("base64");
|
|
382
383
|
}
|
package/lib/loadCJSON.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadCJSON = void 0;
|
|
4
|
+
const error_1 = require("./error");
|
|
5
|
+
const cjson = require("cjson");
|
|
6
|
+
function loadCJSON(path) {
|
|
5
7
|
try {
|
|
6
8
|
return cjson.load(path);
|
|
7
9
|
}
|
|
8
10
|
catch (e) {
|
|
9
11
|
if (e.code === "ENOENT") {
|
|
10
|
-
throw new FirebaseError(
|
|
12
|
+
throw new error_1.FirebaseError(`File ${path} does not exist`);
|
|
11
13
|
}
|
|
12
|
-
throw new FirebaseError(
|
|
14
|
+
throw new error_1.FirebaseError(`Parse Error in ${path}:\n\n${e.message}`);
|
|
13
15
|
}
|
|
14
|
-
}
|
|
16
|
+
}
|
|
17
|
+
exports.loadCJSON = loadCJSON;
|
package/lib/logError.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logError = void 0;
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const clc = require("cli-color");
|
|
6
|
+
function logError(error) {
|
|
5
7
|
if (error.children && error.children.length) {
|
|
6
|
-
logger.error(clc.bold.red("Error:"), clc.underline(error.message) + ":");
|
|
7
|
-
error.children.forEach(
|
|
8
|
-
|
|
8
|
+
logger_1.logger.error(clc.bold.red("Error:"), clc.underline(error.message) + ":");
|
|
9
|
+
error.children.forEach((child) => {
|
|
10
|
+
let out = "- ";
|
|
9
11
|
if (child.name) {
|
|
10
12
|
out += clc.bold(child.name) + " ";
|
|
11
13
|
}
|
|
12
14
|
out += child.message;
|
|
13
|
-
logger.error(out);
|
|
15
|
+
logger_1.logger.error(out);
|
|
14
16
|
});
|
|
15
17
|
}
|
|
16
18
|
else {
|
|
17
19
|
if (error.original) {
|
|
18
|
-
logger.debug(error.original.stack);
|
|
20
|
+
logger_1.logger.debug(error.original.stack);
|
|
19
21
|
}
|
|
20
|
-
logger.error();
|
|
21
|
-
logger.error(clc.bold.red("Error:"), error.message);
|
|
22
|
+
logger_1.logger.error();
|
|
23
|
+
logger_1.logger.error(clc.bold.red("Error:"), error.message);
|
|
22
24
|
}
|
|
23
25
|
if (error.context) {
|
|
24
|
-
logger.debug("Error Context:", JSON.stringify(error.context, undefined, 2));
|
|
26
|
+
logger_1.logger.debug("Error Context:", JSON.stringify(error.context, undefined, 2));
|
|
25
27
|
}
|
|
26
|
-
}
|
|
28
|
+
}
|
|
29
|
+
exports.logError = logError;
|
package/lib/management/apps.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteAppAndroidSha = exports.createAppAndroidSha = exports.listAppAndroidSha = exports.getAppConfig = exports.getAppConfigFile = exports.listFirebaseApps = exports.createWebApp = exports.createAndroidApp = exports.createIosApp = exports.getAppPlatform = exports.ShaCertificateType = exports.AppPlatform = void 0;
|
|
3
|
+
exports.deleteAppAndroidSha = exports.createAppAndroidSha = exports.listAppAndroidSha = exports.getAppConfig = exports.getAppConfigFile = exports.listFirebaseApps = exports.createWebApp = exports.createAndroidApp = exports.createIosApp = exports.getAppPlatform = exports.ShaCertificateType = exports.AppPlatform = exports.APP_LIST_PAGE_SIZE = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
|
-
const
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
6
|
+
const api_1 = require("../api");
|
|
6
7
|
const error_1 = require("../error");
|
|
7
8
|
const logger_1 = require("../logger");
|
|
8
9
|
const operation_poller_1 = require("../operation-poller");
|
|
9
10
|
const TIMEOUT_MILLIS = 30000;
|
|
10
|
-
|
|
11
|
+
exports.APP_LIST_PAGE_SIZE = 100;
|
|
11
12
|
const CREATE_APP_API_REQUEST_TIMEOUT_MILLIS = 15000;
|
|
12
13
|
const WEB_CONFIG_FILE_NAME = "google-config.js";
|
|
13
14
|
var AppPlatform;
|
|
@@ -39,17 +40,18 @@ function getAppPlatform(platform) {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
exports.getAppPlatform = getAppPlatform;
|
|
43
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.firebaseApiOrigin, apiVersion: "v1beta1" });
|
|
42
44
|
async function createIosApp(projectId, options) {
|
|
43
45
|
try {
|
|
44
|
-
const response = await
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
const response = await apiClient.request({
|
|
47
|
+
method: "POST",
|
|
48
|
+
path: `/projects/${projectId}/iosApps`,
|
|
47
49
|
timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
|
|
48
|
-
|
|
50
|
+
body: options,
|
|
49
51
|
});
|
|
50
52
|
const appData = await (0, operation_poller_1.pollOperation)({
|
|
51
53
|
pollerName: "Create iOS app Poller",
|
|
52
|
-
apiOrigin:
|
|
54
|
+
apiOrigin: api_1.firebaseApiOrigin,
|
|
53
55
|
apiVersion: "v1beta1",
|
|
54
56
|
operationResourceName: response.body.name,
|
|
55
57
|
});
|
|
@@ -63,15 +65,15 @@ async function createIosApp(projectId, options) {
|
|
|
63
65
|
exports.createIosApp = createIosApp;
|
|
64
66
|
async function createAndroidApp(projectId, options) {
|
|
65
67
|
try {
|
|
66
|
-
const response = await
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
const response = await apiClient.request({
|
|
69
|
+
method: "POST",
|
|
70
|
+
path: `/projects/${projectId}/androidApps`,
|
|
69
71
|
timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
|
|
70
|
-
|
|
72
|
+
body: options,
|
|
71
73
|
});
|
|
72
74
|
const appData = await (0, operation_poller_1.pollOperation)({
|
|
73
75
|
pollerName: "Create Android app Poller",
|
|
74
|
-
apiOrigin:
|
|
76
|
+
apiOrigin: api_1.firebaseApiOrigin,
|
|
75
77
|
apiVersion: "v1beta1",
|
|
76
78
|
operationResourceName: response.body.name,
|
|
77
79
|
});
|
|
@@ -88,15 +90,15 @@ async function createAndroidApp(projectId, options) {
|
|
|
88
90
|
exports.createAndroidApp = createAndroidApp;
|
|
89
91
|
async function createWebApp(projectId, options) {
|
|
90
92
|
try {
|
|
91
|
-
const response = await
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
const response = await apiClient.request({
|
|
94
|
+
method: "POST",
|
|
95
|
+
path: `/projects/${projectId}/webApps`,
|
|
94
96
|
timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
|
|
95
|
-
|
|
97
|
+
body: options,
|
|
96
98
|
});
|
|
97
99
|
const appData = await (0, operation_poller_1.pollOperation)({
|
|
98
100
|
pollerName: "Create Web app Poller",
|
|
99
|
-
apiOrigin:
|
|
101
|
+
apiOrigin: api_1.firebaseApiOrigin,
|
|
100
102
|
apiVersion: "v1beta1",
|
|
101
103
|
operationResourceName: response.body.name,
|
|
102
104
|
});
|
|
@@ -126,18 +128,21 @@ function getListAppsResourceString(projectId, platform) {
|
|
|
126
128
|
default:
|
|
127
129
|
throw new error_1.FirebaseError("Unexpected platform. Only support iOS, Android and Web apps");
|
|
128
130
|
}
|
|
129
|
-
return `/
|
|
131
|
+
return `/projects/${projectId}${resourceSuffix}`;
|
|
130
132
|
}
|
|
131
|
-
async function listFirebaseApps(projectId, platform, pageSize = APP_LIST_PAGE_SIZE) {
|
|
133
|
+
async function listFirebaseApps(projectId, platform, pageSize = exports.APP_LIST_PAGE_SIZE) {
|
|
132
134
|
const apps = [];
|
|
133
135
|
try {
|
|
134
|
-
let nextPageToken
|
|
136
|
+
let nextPageToken;
|
|
135
137
|
do {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const queryParams = { pageSize };
|
|
139
|
+
if (nextPageToken) {
|
|
140
|
+
queryParams.pageToken = nextPageToken;
|
|
141
|
+
}
|
|
142
|
+
const response = await apiClient.request({
|
|
143
|
+
method: "GET",
|
|
144
|
+
path: getListAppsResourceString(projectId, platform),
|
|
145
|
+
queryParams,
|
|
141
146
|
timeout: TIMEOUT_MILLIS,
|
|
142
147
|
});
|
|
143
148
|
if (response.body.apps) {
|
|
@@ -173,7 +178,7 @@ function getAppConfigResourceString(appId, platform) {
|
|
|
173
178
|
default:
|
|
174
179
|
throw new error_1.FirebaseError("Unexpected app platform");
|
|
175
180
|
}
|
|
176
|
-
return `/
|
|
181
|
+
return `/projects/-/${platformResource}/${appId}/config`;
|
|
177
182
|
}
|
|
178
183
|
function parseConfigFromResponse(responseBody, platform) {
|
|
179
184
|
if (platform === AppPlatform.WEB) {
|
|
@@ -196,13 +201,13 @@ function getAppConfigFile(config, platform) {
|
|
|
196
201
|
}
|
|
197
202
|
exports.getAppConfigFile = getAppConfigFile;
|
|
198
203
|
async function getAppConfig(appId, platform) {
|
|
199
|
-
let response;
|
|
200
204
|
try {
|
|
201
|
-
response = await
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
const response = await apiClient.request({
|
|
206
|
+
method: "GET",
|
|
207
|
+
path: getAppConfigResourceString(appId, platform),
|
|
204
208
|
timeout: TIMEOUT_MILLIS,
|
|
205
209
|
});
|
|
210
|
+
return response.body;
|
|
206
211
|
}
|
|
207
212
|
catch (err) {
|
|
208
213
|
logger_1.logger.debug(err.message);
|
|
@@ -211,15 +216,15 @@ async function getAppConfig(appId, platform) {
|
|
|
211
216
|
original: err,
|
|
212
217
|
});
|
|
213
218
|
}
|
|
214
|
-
return response.body;
|
|
215
219
|
}
|
|
216
220
|
exports.getAppConfig = getAppConfig;
|
|
217
221
|
async function listAppAndroidSha(projectId, appId) {
|
|
218
222
|
const shaCertificates = [];
|
|
219
223
|
try {
|
|
220
|
-
const response = await
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
const response = await apiClient.request({
|
|
225
|
+
method: "GET",
|
|
226
|
+
path: `/projects/${projectId}/androidApps/${appId}/sha`,
|
|
227
|
+
timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
|
|
223
228
|
});
|
|
224
229
|
if (response.body.certificates) {
|
|
225
230
|
shaCertificates.push(...response.body.certificates);
|
|
@@ -238,11 +243,11 @@ async function listAppAndroidSha(projectId, appId) {
|
|
|
238
243
|
exports.listAppAndroidSha = listAppAndroidSha;
|
|
239
244
|
async function createAppAndroidSha(projectId, appId, options) {
|
|
240
245
|
try {
|
|
241
|
-
const response = await
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
const response = await apiClient.request({
|
|
247
|
+
method: "POST",
|
|
248
|
+
path: `/projects/${projectId}/androidApps/${appId}/sha`,
|
|
249
|
+
body: options,
|
|
244
250
|
timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
|
|
245
|
-
data: options,
|
|
246
251
|
});
|
|
247
252
|
const shaCertificate = response.body;
|
|
248
253
|
return shaCertificate;
|
|
@@ -258,11 +263,10 @@ async function createAppAndroidSha(projectId, appId, options) {
|
|
|
258
263
|
exports.createAppAndroidSha = createAppAndroidSha;
|
|
259
264
|
async function deleteAppAndroidSha(projectId, appId, shaId) {
|
|
260
265
|
try {
|
|
261
|
-
await
|
|
262
|
-
|
|
263
|
-
|
|
266
|
+
await apiClient.request({
|
|
267
|
+
method: "DELETE",
|
|
268
|
+
path: `/projects/${projectId}/androidApps/${appId}/sha/${shaId}`,
|
|
264
269
|
timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
|
|
265
|
-
data: null,
|
|
266
270
|
});
|
|
267
271
|
}
|
|
268
272
|
catch (err) {
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listDatabaseInstances = exports.parseDatabaseLocation = exports.checkInstanceNameAvailable = exports.createInstance = exports.getDatabaseInstanceDetails = exports.populateInstanceDetails = exports.DatabaseLocation = exports.DatabaseInstanceState = exports.DatabaseInstanceType = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.listDatabaseInstances = exports.parseDatabaseLocation = exports.checkInstanceNameAvailable = exports.createInstance = exports.getDatabaseInstanceDetails = exports.populateInstanceDetails = exports.DatabaseLocation = exports.DatabaseInstanceState = exports.DatabaseInstanceType = exports.APP_LIST_PAGE_SIZE = exports.MGMT_API_VERSION = void 0;
|
|
4
|
+
const apiv2_1 = require("../apiv2");
|
|
5
|
+
const constants_1 = require("../emulator/constants");
|
|
6
|
+
const error_1 = require("../error");
|
|
5
7
|
const logger_1 = require("../logger");
|
|
8
|
+
const api_1 = require("../api");
|
|
6
9
|
const utils = require("../utils");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const MGMT_API_VERSION = "v1beta";
|
|
10
|
+
exports.MGMT_API_VERSION = "v1beta";
|
|
11
|
+
exports.APP_LIST_PAGE_SIZE = 100;
|
|
10
12
|
const TIMEOUT_MILLIS = 10000;
|
|
11
|
-
const APP_LIST_PAGE_SIZE = 100;
|
|
12
13
|
const INSTANCE_RESOURCE_NAME_REGEX = /projects\/([^/]+?)\/locations\/([^/]+?)\/instances\/([^/]*)/;
|
|
13
14
|
var DatabaseInstanceType;
|
|
14
15
|
(function (DatabaseInstanceType) {
|
|
@@ -30,6 +31,7 @@ var DatabaseLocation;
|
|
|
30
31
|
DatabaseLocation["ASIA_SOUTHEAST1"] = "asia-southeast1";
|
|
31
32
|
DatabaseLocation["ANY"] = "-";
|
|
32
33
|
})(DatabaseLocation = exports.DatabaseLocation || (exports.DatabaseLocation = {}));
|
|
34
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.rtdbManagementOrigin, apiVersion: exports.MGMT_API_VERSION });
|
|
33
35
|
async function populateInstanceDetails(options) {
|
|
34
36
|
options.instanceDetails = await getDatabaseInstanceDetails(options.project, options.instance);
|
|
35
37
|
return Promise.resolve();
|
|
@@ -37,9 +39,9 @@ async function populateInstanceDetails(options) {
|
|
|
37
39
|
exports.populateInstanceDetails = populateInstanceDetails;
|
|
38
40
|
async function getDatabaseInstanceDetails(projectId, instanceName) {
|
|
39
41
|
try {
|
|
40
|
-
const response = await
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
const response = await apiClient.request({
|
|
43
|
+
method: "GET",
|
|
44
|
+
path: `/projects/${projectId}/locations/-/instances/${instanceName}`,
|
|
43
45
|
timeout: TIMEOUT_MILLIS,
|
|
44
46
|
});
|
|
45
47
|
return convertDatabaseInstance(response.body);
|
|
@@ -57,8 +59,8 @@ async function getDatabaseInstanceDetails(projectId, instanceName) {
|
|
|
57
59
|
state: DatabaseInstanceState.ACTIVE,
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
throw new error_1.FirebaseError(`Failed to get instance details for instance: ${instanceName}. See firebase-debug.log for more details.`, {
|
|
63
|
+
exit: 2,
|
|
62
64
|
original: err,
|
|
63
65
|
});
|
|
64
66
|
}
|
|
@@ -66,13 +68,12 @@ async function getDatabaseInstanceDetails(projectId, instanceName) {
|
|
|
66
68
|
exports.getDatabaseInstanceDetails = getDatabaseInstanceDetails;
|
|
67
69
|
async function createInstance(projectId, instanceName, location, databaseType) {
|
|
68
70
|
try {
|
|
69
|
-
const response = await
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
const response = await apiClient.request({
|
|
72
|
+
method: "POST",
|
|
73
|
+
path: `/projects/${projectId}/locations/${location}/instances`,
|
|
74
|
+
queryParams: { databaseId: instanceName },
|
|
75
|
+
body: { type: databaseType },
|
|
72
76
|
timeout: TIMEOUT_MILLIS,
|
|
73
|
-
data: {
|
|
74
|
-
type: databaseType,
|
|
75
|
-
},
|
|
76
77
|
});
|
|
77
78
|
return convertDatabaseInstance(response.body);
|
|
78
79
|
}
|
|
@@ -91,17 +92,14 @@ async function checkInstanceNameAvailable(projectId, instanceName, databaseType,
|
|
|
91
92
|
location = DatabaseLocation.US_CENTRAL1;
|
|
92
93
|
}
|
|
93
94
|
try {
|
|
94
|
-
await
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
await apiClient.request({
|
|
96
|
+
method: "POST",
|
|
97
|
+
path: `/projects/${projectId}/locations/${location}/instances`,
|
|
98
|
+
queryParams: { databaseId: instanceName, validateOnly: "true" },
|
|
99
|
+
body: { type: databaseType },
|
|
97
100
|
timeout: TIMEOUT_MILLIS,
|
|
98
|
-
data: {
|
|
99
|
-
type: databaseType,
|
|
100
|
-
},
|
|
101
101
|
});
|
|
102
|
-
return {
|
|
103
|
-
available: true,
|
|
104
|
-
};
|
|
102
|
+
return { available: true };
|
|
105
103
|
}
|
|
106
104
|
catch (err) {
|
|
107
105
|
logger_1.logger.debug(`Invalid Realtime Database instance name: ${instanceName}.${err.message ? " " + err.message : ""}`);
|
|
@@ -136,15 +134,19 @@ function parseDatabaseLocation(location, defaultLocation) {
|
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
exports.parseDatabaseLocation = parseDatabaseLocation;
|
|
139
|
-
async function listDatabaseInstances(projectId, location, pageSize = APP_LIST_PAGE_SIZE) {
|
|
137
|
+
async function listDatabaseInstances(projectId, location, pageSize = exports.APP_LIST_PAGE_SIZE) {
|
|
140
138
|
const instances = [];
|
|
141
139
|
try {
|
|
142
140
|
let nextPageToken = "";
|
|
143
141
|
do {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
const queryParams = { pageSize };
|
|
143
|
+
if (nextPageToken) {
|
|
144
|
+
queryParams.pageToken = nextPageToken;
|
|
145
|
+
}
|
|
146
|
+
const response = await apiClient.request({
|
|
147
|
+
method: "GET",
|
|
148
|
+
path: `/projects/${projectId}/locations/${location}/instances`,
|
|
149
|
+
queryParams,
|
|
148
150
|
timeout: TIMEOUT_MILLIS,
|
|
149
151
|
});
|
|
150
152
|
if (response.body.instances) {
|
|
@@ -172,11 +172,17 @@ async function promptAvailableProjectId() {
|
|
|
172
172
|
exports.promptAvailableProjectId = promptAvailableProjectId;
|
|
173
173
|
async function createCloudProject(projectId, options) {
|
|
174
174
|
try {
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
const client = new apiv2_1.Client({ urlPrefix: api.resourceManagerOrigin, apiVersion: "v1" });
|
|
176
|
+
const data = {
|
|
177
|
+
projectId,
|
|
178
|
+
name: options.displayName || projectId,
|
|
179
|
+
parent: options.parentResource,
|
|
180
|
+
};
|
|
181
|
+
const response = await client.request({
|
|
182
|
+
method: "POST",
|
|
183
|
+
path: "/projects",
|
|
184
|
+
body: data,
|
|
178
185
|
timeout: CREATE_PROJECT_API_REQUEST_TIMEOUT_MILLIS,
|
|
179
|
-
data: { projectId, name: options.displayName || projectId, parent: options.parentResource },
|
|
180
186
|
});
|
|
181
187
|
const projectInfo = await (0, operation_poller_1.pollOperation)({
|
|
182
188
|
pollerName: "Project Creation Poller",
|
|
@@ -204,9 +210,9 @@ async function createCloudProject(projectId, options) {
|
|
|
204
210
|
exports.createCloudProject = createCloudProject;
|
|
205
211
|
async function addFirebaseToCloudProject(projectId) {
|
|
206
212
|
try {
|
|
207
|
-
const response = await
|
|
208
|
-
|
|
209
|
-
|
|
213
|
+
const response = await firebaseAPIClient.request({
|
|
214
|
+
method: "POST",
|
|
215
|
+
path: `/projects/${projectId}:addFirebase`,
|
|
210
216
|
timeout: CREATE_PROJECT_API_REQUEST_TIMEOUT_MILLIS,
|
|
211
217
|
});
|
|
212
218
|
const projectInfo = await (0, operation_poller_1.pollOperation)({
|
package/lib/parseBoltRules.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseBoltRules = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const spawn = require("cross-spawn");
|
|
6
|
+
const clc = require("cli-color");
|
|
7
|
+
const _ = require("lodash");
|
|
8
|
+
const error_1 = require("./error");
|
|
9
|
+
function parseBoltRules(filename) {
|
|
10
|
+
const ruleSrc = fs.readFileSync(filename, "utf8");
|
|
11
|
+
const result = spawn.sync("npx", ["--no-install", "firebase-bolt"], {
|
|
10
12
|
input: ruleSrc,
|
|
11
13
|
timeout: 10000,
|
|
12
14
|
encoding: "utf-8",
|
|
13
15
|
});
|
|
14
16
|
if (result.error && _.get(result.error, "code") === "ENOENT") {
|
|
15
|
-
throw new FirebaseError("Bolt not installed, run " + clc.bold("npm install -g firebase-bolt")
|
|
16
|
-
exit: 1,
|
|
17
|
-
});
|
|
17
|
+
throw new error_1.FirebaseError("Bolt not installed, run " + clc.bold("npm install -g firebase-bolt"));
|
|
18
18
|
}
|
|
19
19
|
else if (result.error) {
|
|
20
|
-
throw new FirebaseError("Unexpected error parsing Bolt rules file", {
|
|
20
|
+
throw new error_1.FirebaseError("Unexpected error parsing Bolt rules file", {
|
|
21
21
|
exit: 2,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
else if (result.status != null && result.status > 0) {
|
|
25
|
-
throw new FirebaseError(result.stderr.toString(), { exit: 1 });
|
|
25
|
+
throw new error_1.FirebaseError(result.stderr.toString(), { exit: 1 });
|
|
26
26
|
}
|
|
27
27
|
return result.stdout;
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
|
+
exports.parseBoltRules = parseBoltRules;
|