Skip to content

Commit 12f51f7

Browse files
committed
feat: Make BaseBlockingOptions and use it with new email and sms triggers
1 parent 6ba3a04 commit 12f51f7

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

samples/identity/functions/main.py

+14
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,17 @@ def beforeusersignedin(
3939
return identity_fn.BeforeSignInResponse(session_claims={"emoji": "🐕"})
4040

4141
return None
42+
43+
44+
@identity_fn.before_email_sent()
45+
def beforeemailsent(
46+
event: identity_fn.AuthBlockingEvent
47+
) -> identity_fn.BeforeEmailSentResponse | None:
48+
print(event)
49+
return None
50+
51+
52+
@identity_fn.before_sms_sent()
53+
def beforesmssent(event: identity_fn.AuthBlockingEvent) -> identity_fn.BeforeSmsSentResponse | None:
54+
print(event)
55+
return None
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Not published yet,
22
# firebase-functions-python >= 0.0.1
33
# so we use a relative path during development:
4-
./../../../
4+
# ./../../../
55
# Or switch to git ref for deployment testing:
6-
# git+https://github.com/firebase/firebase-functions-python.git@main#egg=firebase-functions
6+
git+https://github.com/firebase/firebase-functions-python.git@feat/before_email_sms_sent_blocking_fn#egg=firebase-functions
77

88
firebase-admin >= 6.0.1

src/firebase_functions/identity_fn.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def before_user_created_wrapped(request: _Request) -> _Response:
489489
return before_user_created_decorator
490490

491491

492-
@_util.copy_func_kwargs(_options.BlockingOptions)
492+
@_util.copy_func_kwargs(_options.BaseBlockingOptions)
493493
def before_email_sent(
494494
**kwargs,
495495
) -> _typing.Callable[[BeforeEmailSentCallable], BeforeEmailSentCallable]:
@@ -509,14 +509,14 @@ def example(
509509
pass
510510
511511
:param \\*\\*kwargs: Options.
512-
:type \\*\\*kwargs: as :exc:`firebase_functions.options.BlockingOptions`
512+
:type \\*\\*kwargs: as :exc:`firebase_functions.options.BaseBlockingOptions`
513513
:rtype: :exc:`typing.Callable`
514514
\\[ \\[ :exc:`firebase_functions.identity_fn.AuthBlockingEvent` \\],
515515
:exc:`firebase_functions.identity_fn.BeforeEmailSentResponse` \\| `None` \\]
516516
A function that takes a AuthBlockingEvent and optionally returns
517517
BeforeEmailSentResponse.
518518
"""
519-
options = _options.BlockingOptions(**kwargs)
519+
options = _options.BaseBlockingOptions(**kwargs)
520520

521521
def before_email_sent_decorator(func: BeforeEmailSentCallable):
522522
from firebase_functions.private._identity_fn_event_types import event_type_before_email_sent
@@ -546,7 +546,7 @@ def before_email_sent_wrapped(request: _Request) -> _Response:
546546
return before_email_sent_decorator
547547

548548

549-
@_util.copy_func_kwargs(_options.BlockingOptions)
549+
@_util.copy_func_kwargs(_options.BaseBlockingOptions)
550550
def before_sms_sent(
551551
**kwargs,
552552
) -> _typing.Callable[[BeforeSmsSentCallable], BeforeSmsSentCallable]:
@@ -564,13 +564,13 @@ def example(event: identity_fn.AuthBlockingEvent) -> identity_fn.BeforeSmsSentRe
564564
pass
565565
566566
:param \\*\\*kwargs: Options.
567-
:type \\*\\*kwargs: as :exc:`firebase_functions.options.BlockingOptions`
567+
:type \\*\\*kwargs: as :exc:`firebase_functions.options.BaseBlockingOptions`
568568
:rtype: :exc:`typing.Callable`
569569
\\[ \\[ :exc:`firebase_functions.identity_fn.AuthBlockingEvent` \\],
570570
:exc:`firebase_functions.identity_fn.BeforeSmsSentResponse` \\| `None` \\]
571571
A function that takes a AuthBlockingEvent and optionally returns BeforeSmsSentResponse.
572572
"""
573-
options = _options.BlockingOptions(**kwargs)
573+
options = _options.BaseBlockingOptions(**kwargs)
574574

575575
def before_sms_sent_decorator(func: BeforeSmsSentCallable):
576576
from firebase_functions.private._identity_fn_event_types import event_type_before_sms_sent

src/firebase_functions/options.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -969,27 +969,12 @@ def _endpoint(
969969

970970

971971
@_dataclasses.dataclass(frozen=True, kw_only=True)
972-
class BlockingOptions(RuntimeOptions):
972+
class BaseBlockingOptions(RuntimeOptions):
973973
"""
974-
Options that can be set on an Auth Blocking trigger.
974+
Base class for options that can be set on an Auth Blocking trigger.
975975
Internal use only.
976976
"""
977977

978-
id_token: bool | None = None
979-
"""
980-
Pass the ID Token credential to the function.
981-
"""
982-
983-
access_token: bool | None = None
984-
"""
985-
Pass the access token credential to the function.
986-
"""
987-
988-
refresh_token: bool | None = None
989-
"""
990-
Pass the refresh token credential to the function.
991-
"""
992-
993978
def _endpoint(
994979
self,
995980
**kwargs,
@@ -1034,6 +1019,29 @@ def _required_apis(self) -> list[_manifest.ManifestRequiredApi]:
10341019
]
10351020

10361021

1022+
@_dataclasses.dataclass(frozen=True, kw_only=True)
1023+
class BlockingOptions(BaseBlockingOptions):
1024+
"""
1025+
Options that can be set on an Auth Blocking trigger.
1026+
Internal use only.
1027+
"""
1028+
1029+
id_token: bool | None = None
1030+
"""
1031+
Pass the ID Token credential to the function.
1032+
"""
1033+
1034+
access_token: bool | None = None
1035+
"""
1036+
Pass the access token credential to the function.
1037+
"""
1038+
1039+
refresh_token: bool | None = None
1040+
"""
1041+
Pass the refresh token credential to the function.
1042+
"""
1043+
1044+
10371045
@_dataclasses.dataclass(frozen=True, kw_only=True)
10381046
class FirestoreOptions(RuntimeOptions):
10391047
"""

0 commit comments

Comments
 (0)