firebase-tools 11.0.0 → 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.
@@ -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 = `projects/${project}/databases/(default)/collectionGroups/-/indexes`;
116
- const res = await api.request("GET", `/v1/${url}`, {
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 = `${parent}/fields?filter=indexConfig.usesAncestorConfig=false`;
139
- const res = await api.request("GET", `/v1/${url}`, {
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 = `projects/${project}/databases/(default)/collectionGroups/${spec.collectionGroup}/fields/${spec.fieldPath}`;
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 api.request("PATCH", `/v1/${url}`, {
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 api.request("PATCH", "/v1/" + url + "?updateMask=indexConfig", {
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 = `projects/${project}/databases/(default)/collectionGroups/${index.collectionGroup}/indexes`;
286
- return api.request("POST", "/v1/" + url, {
287
- auth: true,
288
- data: {
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 api.request("DELETE", "/v1/" + url, {
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;
@@ -62,10 +62,8 @@ async function uploadObject(source, bucketName) {
62
62
  }
63
63
  exports.uploadObject = uploadObject;
64
64
  function deleteObject(location) {
65
- return api_1.default.request("DELETE", location, {
66
- auth: true,
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 lodash_1 = require("lodash");
3
+ const apiv2_1 = require("../apiv2");
4
+ const api_1 = require("../api");
4
5
  const proxy_1 = require("./proxy");
5
- const projectUtils_1 = require("../projectUtils");
6
+ const error_1 = require("../error");
6
7
  const logger_1 = require("../logger");
7
- const api_1 = require("../api");
8
+ const projectUtils_1 = require("../projectUtils");
8
9
  const cloudRunCache = {};
9
- function getCloudRunUrl(rewrite, projectId) {
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 = `/v1/projects/${projectId}/locations/${rewrite.run.region || "us-central1"}/services/${rewrite.run.serviceId}`;
15
- logger_1.logger.info(`[hosting] Looking up Cloud Run service "${path}" for its URL`);
16
- return (0, api_1.request)("GET", path, { origin: api_1.cloudRunApiOrigin, auth: true })
17
- .then((res) => {
18
- const url = (0, lodash_1.get)(res, "body.status.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
- return Promise.reject("Cloud Run URL doesn't exist in response.");
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
- .catch((err) => {
26
- const errInfo = `error looking up URL for Cloud Run service: ${err}`;
27
- return Promise.reject(errInfo);
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 response = await api.request("GET", "/.settings/rules.json", {
21
- auth: true,
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) {
@@ -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 api = require("../api");
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
- const APP_LIST_PAGE_SIZE = 100;
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 api.request("POST", `/v1beta1/projects/${projectId}/iosApps`, {
45
- auth: true,
46
- origin: api.firebaseApiOrigin,
46
+ const response = await apiClient.request({
47
+ method: "POST",
48
+ path: `/projects/${projectId}/iosApps`,
47
49
  timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
48
- data: options,
50
+ body: options,
49
51
  });
50
52
  const appData = await (0, operation_poller_1.pollOperation)({
51
53
  pollerName: "Create iOS app Poller",
52
- apiOrigin: api.firebaseApiOrigin,
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 api.request("POST", `/v1beta1/projects/${projectId}/androidApps`, {
67
- auth: true,
68
- origin: api.firebaseApiOrigin,
68
+ const response = await apiClient.request({
69
+ method: "POST",
70
+ path: `/projects/${projectId}/androidApps`,
69
71
  timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
70
- data: options,
72
+ body: options,
71
73
  });
72
74
  const appData = await (0, operation_poller_1.pollOperation)({
73
75
  pollerName: "Create Android app Poller",
74
- apiOrigin: api.firebaseApiOrigin,
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 api.request("POST", `/v1beta1/projects/${projectId}/webApps`, {
92
- auth: true,
93
- origin: api.firebaseApiOrigin,
93
+ const response = await apiClient.request({
94
+ method: "POST",
95
+ path: `/projects/${projectId}/webApps`,
94
96
  timeout: CREATE_APP_API_REQUEST_TIMEOUT_MILLIS,
95
- data: options,
97
+ body: options,
96
98
  });
97
99
  const appData = await (0, operation_poller_1.pollOperation)({
98
100
  pollerName: "Create Web app Poller",
99
- apiOrigin: api.firebaseApiOrigin,
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 `/v1beta1/projects/${projectId}${resourceSuffix}`;
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 pageTokenQueryString = nextPageToken ? `&pageToken=${nextPageToken}` : "";
137
- const response = await api.request("GET", getListAppsResourceString(projectId, platform) +
138
- `?pageSize=${pageSize}${pageTokenQueryString}`, {
139
- auth: true,
140
- origin: api.firebaseApiOrigin,
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 `/v1beta1/projects/-/${platformResource}/${appId}/config`;
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 api.request("GET", getAppConfigResourceString(appId, platform), {
202
- auth: true,
203
- origin: api.firebaseApiOrigin,
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 api.request("GET", `/v1beta1/projects/${projectId}/androidApps/${appId}/sha`, {
221
- auth: true,
222
- origin: api.firebaseApiOrigin,
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 api.request("POST", `/v1beta1/projects/${projectId}/androidApps/${appId}/sha`, {
242
- auth: true,
243
- origin: api.firebaseApiOrigin,
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 api.request("DELETE", `/v1beta1/projects/${projectId}/androidApps/${appId}/sha/${shaId}`, {
262
- auth: true,
263
- origin: api.firebaseApiOrigin,
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 api = require("../api");
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
- const error_1 = require("../error");
8
- const constants_1 = require("../emulator/constants");
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 api.request("GET", `/${MGMT_API_VERSION}/projects/${projectId}/locations/-/instances/${instanceName}`, {
41
- auth: true,
42
- origin: api.rtdbManagementOrigin,
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
- return utils.reject(`Failed to get instance details for instance: ${instanceName}. See firebase-debug.log for more details.`, {
61
- code: 2,
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 api.request("POST", `/${MGMT_API_VERSION}/projects/${projectId}/locations/${location}/instances?databaseId=${instanceName}`, {
70
- auth: true,
71
- origin: api.rtdbManagementOrigin,
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 api.request("POST", `/${MGMT_API_VERSION}/projects/${projectId}/locations/${location}/instances?databaseId=${instanceName}&validateOnly=true`, {
95
- auth: true,
96
- origin: api.rtdbManagementOrigin,
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 pageTokenQueryString = nextPageToken ? `&pageToken=${nextPageToken}` : "";
145
- const response = await api.request("GET", `/${MGMT_API_VERSION}/projects/${projectId}/locations/${location}/instances?pageSize=${pageSize}${pageTokenQueryString}`, {
146
- auth: true,
147
- origin: api.rtdbManagementOrigin,
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 response = await api.request("POST", "/v1/projects", {
176
- auth: true,
177
- origin: api.resourceManagerOrigin,
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 api.request("POST", `/v1beta1/projects/${projectId}:addFirebase`, {
208
- auth: true,
209
- origin: api.firebaseApiOrigin,
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/rtdb.js CHANGED
@@ -1,33 +1,35 @@
1
1
  "use strict";
2
- var api = require("./api");
3
- var { FirebaseError } = require("./error");
4
- var utils = require("./utils");
5
- const { populateInstanceDetails } = require("./management/database");
6
- const { realtimeOriginOrCustomUrl } = require("./database/api");
7
- exports.updateRules = function (projectId, instance, src, options) {
8
- options = options || {};
9
- var path = ".settings/rules.json";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateRules = void 0;
4
+ const apiv2_1 = require("./apiv2");
5
+ const database_1 = require("./management/database");
6
+ const error_1 = require("./error");
7
+ const api_1 = require("./database/api");
8
+ const utils = require("./utils");
9
+ async function updateRules(projectId, instance, src, options = {}) {
10
+ const queryParams = {};
10
11
  if (options.dryRun) {
11
- path += "?dryRun=true";
12
+ queryParams.dryRun = "true";
12
13
  }
13
- var downstreamOptions = { instance: instance, project: projectId };
14
- return populateInstanceDetails(downstreamOptions)
15
- .then(function () {
16
- const origin = utils.getDatabaseUrl(realtimeOriginOrCustomUrl(downstreamOptions.instanceDetails.databaseUrl), instance, "");
17
- return api.request("PUT", path, {
18
- origin: origin,
19
- auth: true,
20
- data: src,
21
- json: false,
22
- resolveOnHTTPError: true,
23
- });
24
- })
25
- .then(function (response) {
26
- if (response.status === 400) {
27
- throw new FirebaseError("Syntax error in database rules:\n\n" + JSON.parse(response.body).error);
28
- }
29
- else if (response.status > 400) {
30
- throw new FirebaseError("Unexpected error while deploying database rules.", { exit: 2 });
31
- }
14
+ const downstreamOptions = { instance: instance, project: projectId };
15
+ await (0, database_1.populateInstanceDetails)(downstreamOptions);
16
+ if (!downstreamOptions.instanceDetails) {
17
+ throw new error_1.FirebaseError(`Could not get instance details`, { exit: 2 });
18
+ }
19
+ const origin = utils.getDatabaseUrl((0, api_1.realtimeOriginOrCustomUrl)(downstreamOptions.instanceDetails.databaseUrl), instance, "");
20
+ const client = new apiv2_1.Client({ urlPrefix: origin });
21
+ const response = await client.request({
22
+ method: "PUT",
23
+ path: ".settings/rules.json",
24
+ queryParams,
25
+ body: src,
26
+ resolveOnHTTPError: true,
32
27
  });
33
- };
28
+ if (response.status === 400) {
29
+ throw new error_1.FirebaseError(`Syntax error in database rules:\n\n${response.body.error}`);
30
+ }
31
+ else if (response.status > 400) {
32
+ throw new error_1.FirebaseError("Unexpected error while deploying database rules.", { exit: 2 });
33
+ }
34
+ }
35
+ exports.updateRules = updateRules;