Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Added `functions.list_functions` as a MCP tool (#9369)
- Added AI Logic to `firebase init` CLI command and `firebase_init` MCP tool. (#9185)
- Improved error messages for Firebase AI Logic provisioning during 'firebase init' (#9377)
- Adds 2nd gen Firebase Data Connect triggers to firebase deploy (#9394).
48 changes: 48 additions & 0 deletions src/deploy/functions/services/dataconnect.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { expect } from "chai";
import { Endpoint } from "../backend";
import * as dataconnect from "./dataconnect";

const projectNumber = "123456789";

const endpoint: Endpoint = {
id: "endpoint",
region: "us-central1",
project: projectNumber,
eventTrigger: {
retry: false,
eventType: "google.firebase.dataconnect.connector.v1.mutationExecuted",
eventFilters: {},
eventFilterPathPatterns: {},
},
entryPoint: "endpoint",
platform: "gcfv2",
runtime: "nodejs16",
};

describe("ensureDatabaseTriggerRegion", () => {
it("should set the trigger location to the function region", async () => {
const ep = { ...endpoint };

await dataconnect.ensureDataConnectTriggerRegion(ep);

expect(ep.eventTrigger.region).to.eq("us-central1");
});

it("should not error if the trigger location is already set correctly", async () => {
const ep = { ...endpoint };
ep.eventTrigger.region = "us-central1";

await dataconnect.ensureDataConnectTriggerRegion(ep);

expect(ep.eventTrigger.region).to.eq("us-central1");
});

it("should error if the trigger location is set incorrectly", () => {
const ep = { ...endpoint };
ep.eventTrigger.region = "us-west1";

expect(() => dataconnect.ensureDataConnectTriggerRegion(ep)).to.throw(
"The Firebase Data Connect trigger location must match the function region.",
);
});
});
20 changes: 20 additions & 0 deletions src/deploy/functions/services/dataconnect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as backend from "../backend";
import { FirebaseError } from "../../../error";

/**
* Sets a Firebase Data Connect event trigger's region to the function region.
* @param endpoint the database endpoint
*/
export function ensureDataConnectTriggerRegion(
endpoint: backend.Endpoint & backend.EventTriggered,
): Promise<void> {
if (!endpoint.eventTrigger.region) {
endpoint.eventTrigger.region = endpoint.region;
}
if (endpoint.eventTrigger.region !== endpoint.region) {
throw new FirebaseError(
"The Firebase Data Connect trigger location must match the function region.",
);
}
return Promise.resolve();
}
16 changes: 15 additions & 1 deletion src/deploy/functions/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { ensureRemoteConfigTriggerRegion } from "./remoteConfig";
import { ensureTestLabTriggerRegion } from "./testLab";
import { ensureFirestoreTriggerRegion } from "./firestore";
import { ensureDataConnectTriggerRegion } from "./dataconnect";

/** A standard void No Op */
export const noop = (): Promise<void> => Promise.resolve();
Expand All @@ -25,7 +26,8 @@
| "database"
| "remoteconfig"
| "testlab"
| "firestore";
| "firestore"
| "dataconnect";

/** A service interface for the underlying GCP event services */
export interface Service {
Expand All @@ -45,7 +47,7 @@
name: "noop",
api: "",
ensureTriggerRegion: noop,
validateTrigger: noop,

Check warning on line 50 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -56,7 +58,7 @@
api: "pubsub.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: noop,
validateTrigger: noop,

Check warning on line 61 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -67,7 +69,7 @@
api: "storage.googleapis.com",
requiredProjectBindings: obtainStorageBindings,
ensureTriggerRegion: ensureStorageTriggerRegion,
validateTrigger: noop,

Check warning on line 72 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -78,7 +80,7 @@
api: "firebasealerts.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureFirebaseAlertsTriggerRegion,
validateTrigger: noop,

Check warning on line 83 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -92,7 +94,7 @@
api: "firebasedatabase.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureDatabaseTriggerRegion,
validateTrigger: noop,

Check warning on line 97 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -103,7 +105,7 @@
api: "firebaseremoteconfig.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureRemoteConfigTriggerRegion,
validateTrigger: noop,

Check warning on line 108 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -114,7 +116,7 @@
api: "testing.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureTestLabTriggerRegion,
validateTrigger: noop,

Check warning on line 119 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};
Expand All @@ -125,11 +127,22 @@
api: "firestore.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureFirestoreTriggerRegion,
validateTrigger: noop,

Check warning on line 130 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};

/** A Firebase Data Connect service object */
const dataconnectService: Service = {
name: "dataconnect",
api: "firebasedataconnect.googleapis.com",
requiredProjectBindings: noopProjectBindings,
ensureTriggerRegion: ensureDataConnectTriggerRegion,
validateTrigger: noop,

Check warning on line 141 in src/deploy/functions/services/index.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promise-returning function provided to property where a void return was expected
registerTrigger: noop,
unregisterTrigger: noop,
};

/** Mapping from event type string to service object */
const EVENT_SERVICE_MAPPING: Record<events.Event, Service> = {
"google.cloud.pubsub.topic.v1.messagePublished": pubSubService,
Expand All @@ -156,6 +169,7 @@
"google.cloud.firestore.document.v1.created.withAuthContext": firestoreService,
"google.cloud.firestore.document.v1.updated.withAuthContext": firestoreService,
"google.cloud.firestore.document.v1.deleted.withAuthContext": firestoreService,
"google.firebase.dataconnect.connector.v1.mutationExecuted": dataconnectService,
};

/**
Expand Down
5 changes: 4 additions & 1 deletion src/functions/events/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const FIRESTORE_EVENTS = [

export const FIREALERTS_EVENT = "google.firebase.firebasealerts.alerts.v1.published";

export const DATACONNECT_EVENT = "google.firebase.dataconnect.connector.v1.mutationExecuted";

export type Event =
| typeof PUBSUB_PUBLISH_EVENT
| (typeof STORAGE_EVENTS)[number]
Expand All @@ -41,7 +43,8 @@ export type Event =
| typeof REMOTE_CONFIG_EVENT
| typeof TEST_LAB_EVENT
| (typeof FIRESTORE_EVENTS)[number]
| typeof FIREALERTS_EVENT;
| typeof FIREALERTS_EVENT
| typeof DATACONNECT_EVENT;

// Why can't auth context be removed? This is map was added to correct a bug where a regex
// allowed any non-auth type to be converted to any auth type, but we should follow up for why
Expand Down
Loading