diff --git a/CHANGELOG.md b/CHANGELOG.md index cf43f820411..e2b9903f655 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1 @@ -- Added new command `dataconnect:sql:shell` which run queries against Data Connect CloudSQL instances (#7778). +- Add support for deploying new blocking triggers. (#6384) diff --git a/src/deploy/functions/services/auth.ts b/src/deploy/functions/services/auth.ts index f38a53fe0e8..09933da65fc 100644 --- a/src/deploy/functions/services/auth.ts +++ b/src/deploy/functions/services/auth.ts @@ -52,7 +52,11 @@ export class AuthBlockingService implements Service { if ( newConfig.triggers?.beforeCreate?.functionUri !== config.triggers?.beforeCreate?.functionUri || - newConfig.triggers?.beforeSignIn?.functionUri !== config.triggers?.beforeSignIn?.functionUri + newConfig.triggers?.beforeSignIn?.functionUri !== + config.triggers?.beforeSignIn?.functionUri || + newConfig.triggers?.beforeSendEmail?.functionUri !== + config.triggers?.beforeSendEmail?.functionUri || + newConfig.triggers?.beforeSendSms?.functionUri !== config.triggers?.beforeSendSms?.functionUri ) { return true; } @@ -82,13 +86,31 @@ export class AuthBlockingService implements Service { functionUri: endpoint.uri!, }, }; - } else { + } else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SIGN_IN_EVENT) { newBlockingConfig.triggers = { ...newBlockingConfig.triggers, beforeSignIn: { functionUri: endpoint.uri!, }, }; + } else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_EMAIL_EVENT) { + newBlockingConfig.triggers = { + ...newBlockingConfig.triggers, + beforeSendEmail: { + functionUri: endpoint.uri!, + }, + }; + } else if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_SEND_SMS_EVENT) { + newBlockingConfig.triggers = { + ...newBlockingConfig.triggers, + beforeSendSms: { + functionUri: endpoint.uri!, + }, + }; + } else { + throw new FirebaseError( + `Received invalid blocking trigger event type ${endpoint.blockingTrigger.eventType}`, + ); } newBlockingConfig.forwardInboundCredentials = { @@ -121,7 +143,9 @@ export class AuthBlockingService implements Service { const blockingConfig = await identityPlatform.getBlockingFunctionsConfig(endpoint.project); if ( endpoint.uri !== blockingConfig.triggers?.beforeCreate?.functionUri && - endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri + endpoint.uri !== blockingConfig.triggers?.beforeSignIn?.functionUri && + endpoint.uri !== blockingConfig.triggers?.beforeSendEmail?.functionUri && + endpoint.uri !== blockingConfig.triggers?.beforeSendSms?.functionUri ) { return; } @@ -135,6 +159,12 @@ export class AuthBlockingService implements Service { if (endpoint.uri === blockingConfig.triggers?.beforeSignIn?.functionUri) { delete blockingConfig.triggers?.beforeSignIn; } + if (endpoint.uri === blockingConfig.triggers?.beforeSendEmail?.functionUri) { + delete blockingConfig.triggers?.beforeSendEmail; + } + if (endpoint.uri === blockingConfig.triggers?.beforeSendSms?.functionUri) { + delete blockingConfig.triggers?.beforeSendSms; + } await identityPlatform.setBlockingFunctionsConfig(endpoint.project, blockingConfig); } diff --git a/src/deploy/functions/services/index.ts b/src/deploy/functions/services/index.ts index c580c6cde2e..b0f60e3092f 100644 --- a/src/deploy/functions/services/index.ts +++ b/src/deploy/functions/services/index.ts @@ -140,6 +140,8 @@ const EVENT_SERVICE_MAPPING: Record = { "google.firebase.firebasealerts.alerts.v1.published": firebaseAlertsService, "providers/cloud.auth/eventTypes/user.beforeCreate": authBlockingService, "providers/cloud.auth/eventTypes/user.beforeSignIn": authBlockingService, + "providers/cloud.auth/eventTypes/user.beforeSendEmail": authBlockingService, + "providers/cloud.auth/eventTypes/user.beforeSendSms": authBlockingService, "google.firebase.database.ref.v1.written": databaseService, "google.firebase.database.ref.v1.created": databaseService, "google.firebase.database.ref.v1.updated": databaseService, diff --git a/src/functions/constants.ts b/src/functions/constants.ts index 99bd2bf716b..744cc1cb429 100644 --- a/src/functions/constants.ts +++ b/src/functions/constants.ts @@ -6,8 +6,13 @@ export const BLOCKING_LABEL = "deployment-blocking"; export const BLOCKING_LABEL_KEY_TO_EVENT: Record = { "before-create": "providers/cloud.auth/eventTypes/user.beforeCreate", "before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn", + "before-send-email": "providers/cloud.auth/eventTypes/user.beforeSendEmail", + "before-send-sms": "providers/cloud.auth/eventTypes/user.beforeSendSms", }; + export const BLOCKING_EVENT_TO_LABEL_KEY: Record<(typeof AUTH_BLOCKING_EVENTS)[number], string> = { "providers/cloud.auth/eventTypes/user.beforeCreate": "before-create", "providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in", + "providers/cloud.auth/eventTypes/user.beforeSendEmail": "before-send-email", + "providers/cloud.auth/eventTypes/user.beforeSendSms": "before-send-sms", }; diff --git a/src/functions/events/v1.ts b/src/functions/events/v1.ts index 0be24c12487..d4f201b2358 100644 --- a/src/functions/events/v1.ts +++ b/src/functions/events/v1.ts @@ -2,6 +2,15 @@ export const BEFORE_CREATE_EVENT = "providers/cloud.auth/eventTypes/user.beforeC export const BEFORE_SIGN_IN_EVENT = "providers/cloud.auth/eventTypes/user.beforeSignIn"; -export const AUTH_BLOCKING_EVENTS = [BEFORE_CREATE_EVENT, BEFORE_SIGN_IN_EVENT] as const; +export const BEFORE_SEND_EMAIL_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendEmail"; + +export const BEFORE_SEND_SMS_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendSms"; + +export const AUTH_BLOCKING_EVENTS = [ + BEFORE_CREATE_EVENT, + BEFORE_SIGN_IN_EVENT, + BEFORE_SEND_EMAIL_EVENT, + BEFORE_SEND_SMS_EVENT, +] as const; export type Event = (typeof AUTH_BLOCKING_EVENTS)[number]; diff --git a/src/gcp/identityPlatform.ts b/src/gcp/identityPlatform.ts index 0be697f0923..a4948a40b85 100644 --- a/src/gcp/identityPlatform.ts +++ b/src/gcp/identityPlatform.ts @@ -41,6 +41,8 @@ export interface BlockingFunctionsConfig { triggers?: { beforeCreate?: BlockingFunctionsEventDetails; beforeSignIn?: BlockingFunctionsEventDetails; + beforeSendEmail?: BlockingFunctionsEventDetails; + beforeSendSms?: BlockingFunctionsEventDetails; }; forwardInboundCredentials?: BlockingFunctionsOptions; }