firebase-tools 10.9.1 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -9
- package/lib/appdistribution/client.js +16 -25
- package/lib/commands/apps-sdkconfig.js +6 -2
- package/lib/commands/ext-configure.js +54 -119
- package/lib/commands/ext-dev-emulators-exec.js +11 -6
- package/lib/commands/ext-dev-emulators-start.js +10 -26
- package/lib/commands/ext-install.js +12 -197
- package/lib/commands/ext-uninstall.js +7 -91
- package/lib/commands/ext-update.js +65 -224
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +8 -9
- package/lib/deploy/remoteconfig/functions.js +18 -14
- package/lib/emulator/commandUtils.js +1 -1
- package/lib/emulator/controller.js +2 -2
- package/lib/emulator/databaseEmulator.js +7 -5
- 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/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/gcp/storage.js +2 -4
- package/lib/hosting/cloudRunProxy.js +19 -15
- package/lib/init/features/database.js +3 -5
- package/lib/management/apps.js +47 -43
- package/lib/management/database.js +33 -31
- package/lib/management/projects.js +13 -7
- package/lib/rtdb.js +31 -29
- package/npm-shrinkwrap.json +982 -511
- package/package.json +16 -19
- package/standalone/package.json +1 -1
|
@@ -11,14 +11,12 @@ const jwt = require("jsonwebtoken");
|
|
|
11
11
|
const cors = require("cors");
|
|
12
12
|
const url_1 = require("url");
|
|
13
13
|
const events_1 = require("events");
|
|
14
|
-
const api = require("../api");
|
|
15
14
|
const logger_1 = require("../logger");
|
|
16
15
|
const track_1 = require("../track");
|
|
17
16
|
const constants_1 = require("./constants");
|
|
18
17
|
const types_1 = require("./types");
|
|
19
18
|
const chokidar = require("chokidar");
|
|
20
19
|
const spawn = require("cross-spawn");
|
|
21
|
-
const child_process_1 = require("child_process");
|
|
22
20
|
const functionsEmulatorShared_1 = require("./functionsEmulatorShared");
|
|
23
21
|
const registry_1 = require("./registry");
|
|
24
22
|
const emulatorLogger_1 = require("./emulatorLogger");
|
|
@@ -35,6 +33,7 @@ const runtimes = require("../deploy/functions/runtimes");
|
|
|
35
33
|
const backend = require("../deploy/functions/backend");
|
|
36
34
|
const functionsEnv = require("../functions/env");
|
|
37
35
|
const v1_1 = require("../functions/events/v1");
|
|
36
|
+
const apiv2_1 = require("../apiv2");
|
|
38
37
|
const EVENT_INVOKE = "functions:invoke";
|
|
39
38
|
const DATABASE_PATH_PATTERN = new RegExp("^projects/[^/]+/instances/([^/]+)/refs(/.*)$");
|
|
40
39
|
class FunctionsEmulator {
|
|
@@ -383,15 +382,12 @@ class FunctionsEmulator {
|
|
|
383
382
|
}
|
|
384
383
|
const path = `/identitytoolkit.googleapis.com/v2/projects/${this.getProjectId()}/config?updateMask=blockingFunctions`;
|
|
385
384
|
try {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
blockingFunctions: this.blockingFunctionsConfig,
|
|
393
|
-
},
|
|
394
|
-
json: true,
|
|
385
|
+
const client = new apiv2_1.Client({
|
|
386
|
+
urlPrefix: `http://${registry_1.EmulatorRegistry.getInfoHostString(authEmu.getInfo())}`,
|
|
387
|
+
auth: false,
|
|
388
|
+
});
|
|
389
|
+
await client.patch(path, { blockingFunctions: this.blockingFunctionsConfig }, {
|
|
390
|
+
headers: { Authorization: "Bearer owner" },
|
|
395
391
|
});
|
|
396
392
|
}
|
|
397
393
|
catch (err) {
|
|
@@ -399,15 +395,15 @@ class FunctionsEmulator {
|
|
|
399
395
|
throw err;
|
|
400
396
|
}
|
|
401
397
|
}
|
|
402
|
-
addRealtimeDatabaseTrigger(projectId, key, eventTrigger) {
|
|
398
|
+
async addRealtimeDatabaseTrigger(projectId, key, eventTrigger) {
|
|
403
399
|
const databaseEmu = registry_1.EmulatorRegistry.get(types_1.Emulators.DATABASE);
|
|
404
400
|
if (!databaseEmu) {
|
|
405
|
-
return
|
|
401
|
+
return false;
|
|
406
402
|
}
|
|
407
403
|
const result = DATABASE_PATH_PATTERN.exec(eventTrigger.resource);
|
|
408
404
|
if (result === null || result.length !== 3) {
|
|
409
405
|
this.logger.log("WARN", `Event function "${key}" has malformed "resource" member. ` + `${eventTrigger.resource}`);
|
|
410
|
-
|
|
406
|
+
throw new error_1.FirebaseError(`Event function ${key} has malformed resource member`);
|
|
411
407
|
}
|
|
412
408
|
const instance = result[1];
|
|
413
409
|
const bundle = JSON.stringify({
|
|
@@ -424,24 +420,20 @@ class FunctionsEmulator {
|
|
|
424
420
|
else {
|
|
425
421
|
this.logger.log("WARN", `No project in use. Registering function for sentinel namespace '${constants_1.Constants.DEFAULT_DATABASE_EMULATOR_NAMESPACE}'`);
|
|
426
422
|
}
|
|
427
|
-
|
|
428
|
-
.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
})
|
|
436
|
-
.then(() => {
|
|
437
|
-
return true;
|
|
438
|
-
})
|
|
439
|
-
.catch((err) => {
|
|
423
|
+
const client = new apiv2_1.Client({
|
|
424
|
+
urlPrefix: `http://${registry_1.EmulatorRegistry.getInfoHostString(databaseEmu.getInfo())}`,
|
|
425
|
+
auth: false,
|
|
426
|
+
});
|
|
427
|
+
try {
|
|
428
|
+
await client.post(setTriggersPath, bundle, { headers: { Authorization: "Bearer owner" } });
|
|
429
|
+
}
|
|
430
|
+
catch (err) {
|
|
440
431
|
this.logger.log("WARN", "Error adding Realtime Database function: " + err);
|
|
441
432
|
throw err;
|
|
442
|
-
}
|
|
433
|
+
}
|
|
434
|
+
return true;
|
|
443
435
|
}
|
|
444
|
-
addFirestoreTrigger(projectId, key, eventTrigger) {
|
|
436
|
+
async addFirestoreTrigger(projectId, key, eventTrigger) {
|
|
445
437
|
const firestoreEmu = registry_1.EmulatorRegistry.get(types_1.Emulators.FIRESTORE);
|
|
446
438
|
if (!firestoreEmu) {
|
|
447
439
|
return Promise.resolve(false);
|
|
@@ -450,19 +442,18 @@ class FunctionsEmulator {
|
|
|
450
442
|
eventTrigger: Object.assign(Object.assign({}, eventTrigger), { service: "firestore.googleapis.com" }),
|
|
451
443
|
});
|
|
452
444
|
logger_1.logger.debug(`addFirestoreTrigger`, JSON.stringify(bundle));
|
|
453
|
-
|
|
454
|
-
.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
})
|
|
462
|
-
.catch((err) => {
|
|
445
|
+
const client = new apiv2_1.Client({
|
|
446
|
+
urlPrefix: `http://${registry_1.EmulatorRegistry.getInfoHostString(firestoreEmu.getInfo())}`,
|
|
447
|
+
auth: false,
|
|
448
|
+
});
|
|
449
|
+
try {
|
|
450
|
+
await client.put(`/emulator/v1/projects/${projectId}/triggers/${key}`, bundle);
|
|
451
|
+
}
|
|
452
|
+
catch (err) {
|
|
463
453
|
this.logger.log("WARN", "Error adding firestore function: " + err);
|
|
464
454
|
throw err;
|
|
465
|
-
}
|
|
455
|
+
}
|
|
456
|
+
return true;
|
|
466
457
|
}
|
|
467
458
|
async addPubsubTrigger(triggerName, key, eventTrigger, signatureType, schedule) {
|
|
468
459
|
const pubsubEmulator = registry_1.EmulatorRegistry.get(types_1.Emulators.PUBSUB);
|
|
@@ -605,7 +596,7 @@ class FunctionsEmulator {
|
|
|
605
596
|
let localMajorVersion = "0";
|
|
606
597
|
const localNodePath = path.join(backend.functionsDir, "node_modules/.bin/node");
|
|
607
598
|
try {
|
|
608
|
-
const localNodeOutput =
|
|
599
|
+
const localNodeOutput = spawn.sync(localNodePath, ["--version"]).stdout.toString();
|
|
609
600
|
localMajorVersion = localNodeOutput.slice(1).split(".")[0];
|
|
610
601
|
}
|
|
611
602
|
catch (err) {
|
|
@@ -618,7 +609,13 @@ class FunctionsEmulator {
|
|
|
618
609
|
this.logger.logLabeled("SUCCESS", "functions", `Using node@${requestedMajorVersion} from host.`);
|
|
619
610
|
}
|
|
620
611
|
else {
|
|
621
|
-
|
|
612
|
+
if (process.env.FIREPIT_VERSION) {
|
|
613
|
+
this.logger.log("WARN", `You've requested "node" version "${requestedMajorVersion}", but the standalone Firebase CLI comes with bundled Node "${hostMajorVersion}".`);
|
|
614
|
+
this.logger.log("INFO", `To use a different Node.js version, consider removing the standalone Firebase CLI and switching to "firebase-tools" on npm.`);
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
this.logger.log("WARN", `Your requested "node" version "${requestedMajorVersion}" doesn't match your global version "${hostMajorVersion}". Using node@${hostMajorVersion} from host.`);
|
|
618
|
+
}
|
|
622
619
|
}
|
|
623
620
|
return process.execPath;
|
|
624
621
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmulatorHubClient = void 0;
|
|
4
|
-
const api = require("../api");
|
|
5
4
|
const hub_1 = require("./hub");
|
|
6
5
|
const error_1 = require("../error");
|
|
6
|
+
const apiv2_1 = require("../apiv2");
|
|
7
7
|
class EmulatorHubClient {
|
|
8
8
|
constructor(projectId) {
|
|
9
9
|
this.projectId = projectId;
|
|
@@ -12,29 +12,18 @@ class EmulatorHubClient {
|
|
|
12
12
|
foundHub() {
|
|
13
13
|
return this.locator !== undefined;
|
|
14
14
|
}
|
|
15
|
-
getStatus() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
15
|
+
async getStatus() {
|
|
16
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: this.origin, auth: false });
|
|
17
|
+
await apiClient.get("/");
|
|
19
18
|
}
|
|
20
|
-
getEmulators() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
json: true,
|
|
25
|
-
})
|
|
26
|
-
.then((res) => {
|
|
27
|
-
return res.body;
|
|
28
|
-
});
|
|
19
|
+
async getEmulators() {
|
|
20
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: this.origin, auth: false });
|
|
21
|
+
const res = await apiClient.get(hub_1.EmulatorHub.PATH_EMULATORS);
|
|
22
|
+
return res.body;
|
|
29
23
|
}
|
|
30
|
-
postExport(path) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
json: true,
|
|
34
|
-
data: {
|
|
35
|
-
path,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
24
|
+
async postExport(path) {
|
|
25
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: this.origin, auth: false });
|
|
26
|
+
await apiClient.post(hub_1.EmulatorHub.PATH_EXPORT, { path });
|
|
38
27
|
}
|
|
39
28
|
get origin() {
|
|
40
29
|
const locator = this.assertLocator();
|
|
@@ -5,7 +5,6 @@ const path = require("path");
|
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const fse = require("fs-extra");
|
|
7
7
|
const http = require("http");
|
|
8
|
-
const api = require("../api");
|
|
9
8
|
const logger_1 = require("../logger");
|
|
10
9
|
const types_1 = require("./types");
|
|
11
10
|
const registry_1 = require("./registry");
|
|
@@ -13,6 +12,7 @@ const error_1 = require("../error");
|
|
|
13
12
|
const hub_1 = require("./hub");
|
|
14
13
|
const downloadableEmulators_1 = require("./downloadableEmulators");
|
|
15
14
|
const rimraf = require("rimraf");
|
|
15
|
+
const apiv2_1 = require("../apiv2");
|
|
16
16
|
class HubExport {
|
|
17
17
|
constructor(projectId, exportPath) {
|
|
18
18
|
this.projectId = projectId;
|
|
@@ -80,24 +80,27 @@ class HubExport {
|
|
|
80
80
|
export_directory: this.tmpDir,
|
|
81
81
|
export_name: metadata.firestore.path,
|
|
82
82
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
json: true,
|
|
86
|
-
data: firestoreExportBody,
|
|
87
|
-
});
|
|
83
|
+
const client = new apiv2_1.Client({ urlPrefix: firestoreHost, auth: false });
|
|
84
|
+
await client.post(`/emulator/v1/projects/${this.projectId}:export`, firestoreExportBody);
|
|
88
85
|
}
|
|
89
86
|
async exportDatabase(metadata) {
|
|
90
87
|
const databaseEmulator = registry_1.EmulatorRegistry.get(types_1.Emulators.DATABASE);
|
|
91
88
|
const databaseAddr = `http://${registry_1.EmulatorRegistry.getInfoHostString(databaseEmulator.getInfo())}`;
|
|
92
|
-
const
|
|
93
|
-
const
|
|
89
|
+
const client = new apiv2_1.Client({ urlPrefix: databaseAddr, auth: true });
|
|
90
|
+
const inspectURL = `/.inspect/databases.json`;
|
|
91
|
+
const inspectRes = await client.get(inspectURL, {
|
|
92
|
+
queryParams: { ns: this.projectId },
|
|
93
|
+
});
|
|
94
94
|
const namespaces = inspectRes.body.map((instance) => instance.name);
|
|
95
95
|
const namespacesToExport = [];
|
|
96
96
|
for (const ns of namespaces) {
|
|
97
|
-
const checkDataPath = `/.json
|
|
98
|
-
const checkDataRes = await
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
const checkDataPath = `/.json`;
|
|
98
|
+
const checkDataRes = await client.get(checkDataPath, {
|
|
99
|
+
queryParams: {
|
|
100
|
+
ns,
|
|
101
|
+
shallow: "true",
|
|
102
|
+
limitToFirst: 1,
|
|
103
|
+
},
|
|
101
104
|
});
|
|
102
105
|
if (checkDataRes.body !== null) {
|
|
103
106
|
namespacesToExport.push(ns);
|
|
@@ -162,11 +165,18 @@ class HubExport {
|
|
|
162
165
|
const storageExportBody = {
|
|
163
166
|
path: storageExportPath,
|
|
164
167
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
const client = new apiv2_1.Client({ urlPrefix: storageHost, auth: false });
|
|
169
|
+
const res = await client.request({
|
|
170
|
+
method: "POST",
|
|
171
|
+
path: "/internal/export",
|
|
172
|
+
headers: { "Content-Type": "application/json" },
|
|
173
|
+
body: storageExportBody,
|
|
174
|
+
responseType: "stream",
|
|
175
|
+
resolveOnHTTPError: true,
|
|
169
176
|
});
|
|
177
|
+
if (res.status >= 400) {
|
|
178
|
+
throw new error_1.FirebaseError(`Failed to export storage: ${await res.response.text()}`);
|
|
179
|
+
}
|
|
170
180
|
}
|
|
171
181
|
}
|
|
172
182
|
exports.HubExport = HubExport;
|
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.waitForPortClosed = exports.checkPortOpen = exports.findAvailablePort = exports.suggestUnrestricted = exports.isRestricted = void 0;
|
|
4
4
|
const pf = require("portfinder");
|
|
5
5
|
const tcpport = require("tcp-port-used");
|
|
6
|
+
const dns = require("dns");
|
|
6
7
|
const error_1 = require("../error");
|
|
7
8
|
const logger_1 = require("../logger");
|
|
9
|
+
dns.setDefaultResultOrder("ipv4first");
|
|
8
10
|
const RESTRICTED_PORTS = [
|
|
9
11
|
1,
|
|
10
12
|
7,
|
|
@@ -25,6 +25,9 @@ function crc32c(bytes) {
|
|
|
25
25
|
}
|
|
26
26
|
exports.crc32c = crc32c;
|
|
27
27
|
function crc32cToString(crc32cValue) {
|
|
28
|
+
if (typeof crc32cValue === "string") {
|
|
29
|
+
crc32cValue = Number(crc32cValue);
|
|
30
|
+
}
|
|
28
31
|
return "----" + Buffer.from([crc32cValue]).toString("base64");
|
|
29
32
|
}
|
|
30
33
|
exports.crc32cToString = crc32cToString;
|
|
@@ -115,7 +115,7 @@ class StorageRulesRuntime {
|
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
117
|
(_b = this._childprocess.stdout) === null || _b === void 0 ? void 0 : _b.on("data", (buf) => {
|
|
118
|
-
const serializedRuntimeActionResponse = buf.toString("
|
|
118
|
+
const serializedRuntimeActionResponse = buf.toString("utf-8").trim();
|
|
119
119
|
if (serializedRuntimeActionResponse !== "") {
|
|
120
120
|
let rap;
|
|
121
121
|
try {
|
|
@@ -31,6 +31,7 @@ const utils_2 = require("../utils");
|
|
|
31
31
|
const changelog_1 = require("./changelog");
|
|
32
32
|
const getProjectNumber_1 = require("../getProjectNumber");
|
|
33
33
|
const constants_1 = require("../emulator/constants");
|
|
34
|
+
const planner_1 = require("../deploy/extensions/planner");
|
|
34
35
|
var SpecParamType;
|
|
35
36
|
(function (SpecParamType) {
|
|
36
37
|
SpecParamType["SELECT"] = "select";
|
|
@@ -529,15 +530,13 @@ async function diagnoseAndFixProject(options) {
|
|
|
529
530
|
}
|
|
530
531
|
}
|
|
531
532
|
exports.diagnoseAndFixProject = diagnoseAndFixProject;
|
|
532
|
-
function canonicalizeRefInput(extensionName) {
|
|
533
|
+
async function canonicalizeRefInput(extensionName) {
|
|
533
534
|
if (extensionName.split("/").length < 2) {
|
|
534
535
|
const [extensionID, version] = extensionName.split("@");
|
|
535
536
|
extensionName = `firebase/${extensionID}@${version || "latest"}`;
|
|
536
537
|
}
|
|
537
538
|
const ref = refs.parse(extensionName);
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
return extensionName;
|
|
539
|
+
ref.version = await (0, planner_1.resolveVersion)(ref);
|
|
540
|
+
return refs.toExtensionVersionRef(ref);
|
|
542
541
|
}
|
|
543
542
|
exports.canonicalizeRefInput = canonicalizeRefInput;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.showPostDeprecationNotice = exports.readInstanceParam = exports.getInstanceRef = exports.getInstanceTarget = exports.instanceExists = exports.loadConfig = exports.removeFromManifest = exports.writeLocalSecrets = exports.writeToManifest = exports.ENV_DIRECTORY = void 0;
|
|
4
4
|
const clc = require("cli-color");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const refs = require("./refs");
|
|
@@ -181,16 +181,10 @@ function readParamsFile(projectDir, fileName) {
|
|
|
181
181
|
const params = (0, paramHelper_1.readEnvFile)(paramPath);
|
|
182
182
|
return params;
|
|
183
183
|
}
|
|
184
|
-
function
|
|
185
|
-
utils.
|
|
184
|
+
function showPostDeprecationNotice() {
|
|
185
|
+
utils.logLabeledBullet(extensionsHelper_1.logPrefix, "The behavior of ext:install, ext:update, ext:configure, and ext:uninstall has changed in firebase-tools@11.0.0. " +
|
|
186
186
|
"Instead of deploying extensions directly, " +
|
|
187
187
|
"changes to extension instances will be written to firebase.json and ./extensions/*.env. " +
|
|
188
|
-
`Then ${clc.bold("firebase deploy (--only extensions)")} will deploy the changes to your Firebase project.
|
|
189
|
-
`To access this behavior now, pass the ${clc.bold("--local")} flag.`);
|
|
188
|
+
`Then ${clc.bold("firebase deploy (--only extensions)")} will deploy the changes to your Firebase project. See https://firebase.google.com/docs/extensions/manifest for more details.`);
|
|
190
189
|
}
|
|
191
|
-
exports.
|
|
192
|
-
function showPreviewWarning() {
|
|
193
|
-
utils.logLabeledWarning(extensionsHelper_1.logPrefix, `See these changes in your Firebase Emulator by running "firebase emulators:start". ` +
|
|
194
|
-
`Run ${clc.bold("firebase deploy (--only extensions)")} to deploy the changes to your Firebase project. `);
|
|
195
|
-
}
|
|
196
|
-
exports.showPreviewWarning = showPreviewWarning;
|
|
190
|
+
exports.showPostDeprecationNotice = showPostDeprecationNotice;
|
|
@@ -8,7 +8,7 @@ const ajv = new Ajv();
|
|
|
8
8
|
let _VALIDATOR = undefined;
|
|
9
9
|
function getValidator() {
|
|
10
10
|
if (!_VALIDATOR) {
|
|
11
|
-
const schemaStr = fs.readFileSync(path.resolve(__dirname, "../schema/firebase-config.json"), "
|
|
11
|
+
const schemaStr = fs.readFileSync(path.resolve(__dirname, "../schema/firebase-config.json"), "utf-8");
|
|
12
12
|
const schema = JSON.parse(schemaStr);
|
|
13
13
|
_VALIDATOR = ajv.compile(schema);
|
|
14
14
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkDatabaseType = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
6
7
|
async function checkDatabaseType(projectId) {
|
|
7
8
|
try {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
origin: api.appengineOrigin,
|
|
11
|
-
});
|
|
9
|
+
const client = new apiv2_1.Client({ urlPrefix: api_1.appengineOrigin, apiVersion: "v1" });
|
|
10
|
+
const resp = await client.get(`/apps/${projectId}`);
|
|
12
11
|
return resp.body.databaseType;
|
|
13
12
|
}
|
|
14
13
|
catch (err) {
|
package/lib/firestore/indexes.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FirestoreIndexes = void 0;
|
|
4
4
|
const clc = require("cli-color");
|
|
5
|
-
const api = require("../api");
|
|
6
5
|
const logger_1 = require("../logger");
|
|
7
6
|
const utils = require("../utils");
|
|
8
7
|
const validator = require("./validator");
|
|
@@ -10,7 +9,12 @@ const API = require("./indexes-api");
|
|
|
10
9
|
const sort = require("./indexes-sort");
|
|
11
10
|
const util = require("./util");
|
|
12
11
|
const prompt_1 = require("../prompt");
|
|
12
|
+
const api_1 = require("../api");
|
|
13
|
+
const apiv2_1 = require("../apiv2");
|
|
13
14
|
class FirestoreIndexes {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.apiClient = new apiv2_1.Client({ urlPrefix: api_1.firestoreOrigin, apiVersion: "v1" });
|
|
17
|
+
}
|
|
14
18
|
async deploy(options, indexes, fieldOverrides) {
|
|
15
19
|
const spec = this.upgradeOldSpec({
|
|
16
20
|
indexes,
|
|
@@ -112,11 +116,8 @@ class FirestoreIndexes {
|
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
async listIndexes(project) {
|
|
115
|
-
const url =
|
|
116
|
-
const res = await
|
|
117
|
-
auth: true,
|
|
118
|
-
origin: api.firestoreOrigin,
|
|
119
|
-
});
|
|
119
|
+
const url = `/projects/${project}/databases/(default)/collectionGroups/-/indexes`;
|
|
120
|
+
const res = await this.apiClient.get(url);
|
|
120
121
|
const indexes = res.body.indexes;
|
|
121
122
|
if (!indexes) {
|
|
122
123
|
return [];
|
|
@@ -135,11 +136,8 @@ class FirestoreIndexes {
|
|
|
135
136
|
}
|
|
136
137
|
async listFieldOverrides(project) {
|
|
137
138
|
const parent = `projects/${project}/databases/(default)/collectionGroups/-`;
|
|
138
|
-
const url =
|
|
139
|
-
const res = await
|
|
140
|
-
auth: true,
|
|
141
|
-
origin: api.firestoreOrigin,
|
|
142
|
-
});
|
|
139
|
+
const url = `/${parent}/fields?filter=indexConfig.usesAncestorConfig=false`;
|
|
140
|
+
const res = await this.apiClient.get(url);
|
|
143
141
|
const fields = res.body.fields;
|
|
144
142
|
if (!fields) {
|
|
145
143
|
return [];
|
|
@@ -248,7 +246,7 @@ class FirestoreIndexes {
|
|
|
248
246
|
});
|
|
249
247
|
}
|
|
250
248
|
async patchField(project, spec) {
|
|
251
|
-
const url =
|
|
249
|
+
const url = `/projects/${project}/databases/(default)/collectionGroups/${spec.collectionGroup}/fields/${spec.fieldPath}`;
|
|
252
250
|
const indexes = spec.indexes.map((index) => {
|
|
253
251
|
return {
|
|
254
252
|
queryScope: index.queryScope,
|
|
@@ -266,38 +264,23 @@ class FirestoreIndexes {
|
|
|
266
264
|
indexes,
|
|
267
265
|
},
|
|
268
266
|
};
|
|
269
|
-
await
|
|
270
|
-
auth: true,
|
|
271
|
-
origin: api.firestoreOrigin,
|
|
272
|
-
data,
|
|
273
|
-
});
|
|
267
|
+
await this.apiClient.patch(url, data);
|
|
274
268
|
}
|
|
275
269
|
deleteField(field) {
|
|
276
270
|
const url = field.name;
|
|
277
271
|
const data = {};
|
|
278
|
-
return
|
|
279
|
-
auth: true,
|
|
280
|
-
origin: api.firestoreOrigin,
|
|
281
|
-
data,
|
|
282
|
-
});
|
|
272
|
+
return this.apiClient.patch(`/${url}`, data, { queryParams: { updateMask: "indexConfig" } });
|
|
283
273
|
}
|
|
284
274
|
createIndex(project, index) {
|
|
285
|
-
const url =
|
|
286
|
-
return
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
fields: index.fields,
|
|
290
|
-
queryScope: index.queryScope,
|
|
291
|
-
},
|
|
292
|
-
origin: api.firestoreOrigin,
|
|
275
|
+
const url = `/projects/${project}/databases/(default)/collectionGroups/${index.collectionGroup}/indexes`;
|
|
276
|
+
return this.apiClient.post(url, {
|
|
277
|
+
fields: index.fields,
|
|
278
|
+
queryScope: index.queryScope,
|
|
293
279
|
});
|
|
294
280
|
}
|
|
295
281
|
deleteIndex(index) {
|
|
296
282
|
const url = index.name;
|
|
297
|
-
return
|
|
298
|
-
auth: true,
|
|
299
|
-
origin: api.firestoreOrigin,
|
|
300
|
-
});
|
|
283
|
+
return this.apiClient.delete(`/${url}`);
|
|
301
284
|
}
|
|
302
285
|
indexMatchesSpec(index, spec) {
|
|
303
286
|
const collection = util.parseIndexName(index.name).collectionGroupId;
|
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) => {
|
|
@@ -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,15 +11,14 @@ 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
|
-
origin: instanceDetails.databaseUrl,
|
|
23
|
-
});
|
|
20
|
+
const client = new apiv2_1.Client({ urlPrefix: instanceDetails.databaseUrl });
|
|
21
|
+
const response = await client.get("/.settings/rules.json");
|
|
24
22
|
return response.body;
|
|
25
23
|
}
|
|
26
24
|
function writeDBRules(rules, logMessagePrefix, filename, config) {
|