Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

rtdb.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  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 = {};
  11. if (options.dryRun) {
  12. queryParams.dryRun = "true";
  13. }
  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,
  27. });
  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;