No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.serviceForEndpoint = exports.noopProjectBindings = exports.noop = void 0;
  4. const backend = require("../backend");
  5. const auth_1 = require("./auth");
  6. const storage_1 = require("./storage");
  7. const firebaseAlerts_1 = require("./firebaseAlerts");
  8. const database_1 = require("./database");
  9. const remoteConfig_1 = require("./remoteConfig");
  10. const testLab_1 = require("./testLab");
  11. const noop = () => Promise.resolve();
  12. exports.noop = noop;
  13. const noopProjectBindings = () => Promise.resolve([]);
  14. exports.noopProjectBindings = noopProjectBindings;
  15. const noOpService = {
  16. name: "noop",
  17. api: "",
  18. ensureTriggerRegion: exports.noop,
  19. validateTrigger: exports.noop,
  20. registerTrigger: exports.noop,
  21. unregisterTrigger: exports.noop,
  22. };
  23. const pubSubService = {
  24. name: "pubsub",
  25. api: "pubsub.googleapis.com",
  26. requiredProjectBindings: exports.noopProjectBindings,
  27. ensureTriggerRegion: exports.noop,
  28. validateTrigger: exports.noop,
  29. registerTrigger: exports.noop,
  30. unregisterTrigger: exports.noop,
  31. };
  32. const storageService = {
  33. name: "storage",
  34. api: "storage.googleapis.com",
  35. requiredProjectBindings: storage_1.obtainStorageBindings,
  36. ensureTriggerRegion: storage_1.ensureStorageTriggerRegion,
  37. validateTrigger: exports.noop,
  38. registerTrigger: exports.noop,
  39. unregisterTrigger: exports.noop,
  40. };
  41. const firebaseAlertsService = {
  42. name: "firebasealerts",
  43. api: "firebasealerts.googleapis.com",
  44. requiredProjectBindings: exports.noopProjectBindings,
  45. ensureTriggerRegion: firebaseAlerts_1.ensureFirebaseAlertsTriggerRegion,
  46. validateTrigger: exports.noop,
  47. registerTrigger: exports.noop,
  48. unregisterTrigger: exports.noop,
  49. };
  50. const authBlockingService = new auth_1.AuthBlockingService();
  51. const databaseService = {
  52. name: "database",
  53. api: "firebasedatabase.googleapis.com",
  54. requiredProjectBindings: exports.noopProjectBindings,
  55. ensureTriggerRegion: database_1.ensureDatabaseTriggerRegion,
  56. validateTrigger: exports.noop,
  57. registerTrigger: exports.noop,
  58. unregisterTrigger: exports.noop,
  59. };
  60. const remoteConfigService = {
  61. name: "remoteconfig",
  62. api: "firebaseremoteconfig.googleapis.com",
  63. requiredProjectBindings: exports.noopProjectBindings,
  64. ensureTriggerRegion: remoteConfig_1.ensureRemoteConfigTriggerRegion,
  65. validateTrigger: exports.noop,
  66. registerTrigger: exports.noop,
  67. unregisterTrigger: exports.noop,
  68. };
  69. const testLabService = {
  70. name: "testlab",
  71. api: "testing.googleapis.com",
  72. requiredProjectBindings: exports.noopProjectBindings,
  73. ensureTriggerRegion: testLab_1.ensureTestLabTriggerRegion,
  74. validateTrigger: exports.noop,
  75. registerTrigger: exports.noop,
  76. unregisterTrigger: exports.noop,
  77. };
  78. const EVENT_SERVICE_MAPPING = {
  79. "google.cloud.pubsub.topic.v1.messagePublished": pubSubService,
  80. "google.cloud.storage.object.v1.finalized": storageService,
  81. "google.cloud.storage.object.v1.archived": storageService,
  82. "google.cloud.storage.object.v1.deleted": storageService,
  83. "google.cloud.storage.object.v1.metadataUpdated": storageService,
  84. "google.firebase.firebasealerts.alerts.v1.published": firebaseAlertsService,
  85. "providers/cloud.auth/eventTypes/user.beforeCreate": authBlockingService,
  86. "providers/cloud.auth/eventTypes/user.beforeSignIn": authBlockingService,
  87. "google.firebase.database.ref.v1.written": databaseService,
  88. "google.firebase.database.ref.v1.created": databaseService,
  89. "google.firebase.database.ref.v1.updated": databaseService,
  90. "google.firebase.database.ref.v1.deleted": databaseService,
  91. "google.firebase.remoteconfig.remoteConfig.v1.updated": remoteConfigService,
  92. "google.firebase.testlab.testMatrix.v1.completed": testLabService,
  93. };
  94. function serviceForEndpoint(endpoint) {
  95. if (backend.isEventTriggered(endpoint)) {
  96. return EVENT_SERVICE_MAPPING[endpoint.eventTrigger.eventType] || noOpService;
  97. }
  98. if (backend.isBlockingTriggered(endpoint)) {
  99. return EVENT_SERVICE_MAPPING[endpoint.blockingTrigger.eventType] || noOpService;
  100. }
  101. return noOpService;
  102. }
  103. exports.serviceForEndpoint = serviceForEndpoint;