Skip to content

Commit 842257b

Browse files
authored
Merge pull request #67 from invertase/alerts
feat: add support for alerts
2 parents d129208 + 8a785f4 commit 842257b

File tree

16 files changed

+1876
-0
lines changed

16 files changed

+1876
-0
lines changed

docs/generate.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ fi
8484
TITLE="Firebase Python SDK for Cloud Functions"
8585
PY_MODULES='firebase_functions
8686
firebase_functions.core
87+
firebase_functions.alerts_fn
88+
firebase_functions.alerts.app_distribution_fn
89+
firebase_functions.alerts.billing_fn
90+
firebase_functions.alerts.crashlytics_fn
91+
firebase_functions.alerts.performance_fn
8792
firebase_functions.db_fn
8893
firebase_functions.eventarc_fn
8994
firebase_functions.firestore_fn

samples/basic_alerts/.firebaserc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "python-functions-testing"
4+
}
5+
}

samples/basic_alerts/.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
firebase-debug.log*
8+
firebase-debug.*.log*
9+
10+
# Firebase cache
11+
.firebase/
12+
13+
# Firebase config
14+
15+
# Uncomment this if you'd like others to create their own Firebase project.
16+
# For a team working on the same Firebase project(s), it is recommended to leave
17+
# it commented so all members can deploy to the same project(s) in .firebaserc.
18+
# .firebaserc
19+
20+
# Runtime data
21+
pids
22+
*.pid
23+
*.seed
24+
*.pid.lock
25+
26+
# Directory for instrumented libs generated by jscoverage/JSCover
27+
lib-cov
28+
29+
# Coverage directory used by tools like istanbul
30+
coverage
31+
32+
# nyc test coverage
33+
.nyc_output
34+
35+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
36+
.grunt
37+
38+
# Bower dependency directory (https://bower.io/)
39+
bower_components
40+
41+
# node-waf configuration
42+
.lock-wscript
43+
44+
# Compiled binary addons (http://nodejs.org/api/addons.html)
45+
build/Release
46+
47+
# Dependency directories
48+
node_modules/
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Optional REPL history
57+
.node_repl_history
58+
59+
# Output of 'npm pack'
60+
*.tgz
61+
62+
# Yarn Integrity file
63+
.yarn-integrity
64+
65+
# dotenv environment variables file
66+
.env

samples/basic_alerts/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Required to avoid a 'duplicate modules' mypy error
2+
# in monorepos that have multiple main.py files.
3+
# https://github.com/python/mypy/issues/4008

samples/basic_alerts/firebase.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"functions": [
3+
{
4+
"source": "functions",
5+
"codebase": "default",
6+
"ignore": [
7+
"venv"
8+
]
9+
}
10+
]
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pyenv
2+
.python-version
3+
4+
# Installer logs
5+
pip-log.txt
6+
pip-delete-this-directory.txt
7+
8+
# Environments
9+
.env
10+
.venv
11+
venv/
12+
venv.bak/
13+
__pycache__
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""Cloud function samples for Firebase Alerts."""
2+
3+
from firebase_functions import alerts_fn
4+
from firebase_functions.alerts import app_distribution_fn
5+
from firebase_functions.alerts import billing_fn
6+
from firebase_functions.alerts import crashlytics_fn
7+
from firebase_functions.alerts import performance_fn
8+
9+
10+
@alerts_fn.on_alert_published(alert_type=alerts_fn.AlertType.BILLING_PLAN_UPDATE
11+
)
12+
def onalertpublished(
13+
alert: alerts_fn.AlertEvent[alerts_fn.FirebaseAlertData[
14+
billing_fn.PlanUpdatePayload]]
15+
) -> None:
16+
print(alert)
17+
18+
19+
@app_distribution_fn.on_in_app_feedback_published()
20+
def appdistributioninappfeedback(
21+
alert: app_distribution_fn.InAppFeedbackEvent) -> None:
22+
print(alert)
23+
24+
25+
@app_distribution_fn.on_new_tester_ios_device_published()
26+
def appdistributionnewrelease(
27+
alert: app_distribution_fn.NewTesterDeviceEvent) -> None:
28+
print(alert)
29+
30+
31+
@billing_fn.on_plan_automated_update_published()
32+
def billingautomatedplanupdate(
33+
alert: billing_fn.BillingPlanAutomatedUpdateEvent) -> None:
34+
print(alert)
35+
36+
37+
@billing_fn.on_plan_update_published()
38+
def billingplanupdate(alert: billing_fn.BillingPlanUpdateEvent) -> None:
39+
print(alert)
40+
41+
42+
@crashlytics_fn.on_new_fatal_issue_published()
43+
def crashlyticsnewfatalissue(
44+
alert: crashlytics_fn.CrashlyticsNewFatalIssueEvent) -> None:
45+
print(alert)
46+
47+
48+
@crashlytics_fn.on_new_nonfatal_issue_published()
49+
def crashlyticsnewnonfatalissue(
50+
alert: crashlytics_fn.CrashlyticsNewNonfatalIssueEvent) -> None:
51+
print(alert)
52+
53+
54+
@crashlytics_fn.on_new_anr_issue_published()
55+
def crashlyticsnewanrissue(
56+
alert: crashlytics_fn.CrashlyticsNewAnrIssueEvent) -> None:
57+
print(alert)
58+
59+
60+
@crashlytics_fn.on_regression_alert_published()
61+
def crashlyticsregression(
62+
alert: crashlytics_fn.CrashlyticsRegressionAlertEvent) -> None:
63+
print(alert)
64+
65+
66+
@crashlytics_fn.on_stability_digest_published()
67+
def crashlyticsstabilitydigest(
68+
alert: crashlytics_fn.CrashlyticsStabilityDigestEvent) -> None:
69+
print(alert)
70+
71+
72+
@crashlytics_fn.on_velocity_alert_published()
73+
def crashlyticsvelocity(
74+
alert: crashlytics_fn.CrashlyticsVelocityAlertEvent) -> None:
75+
print(alert)
76+
77+
78+
@performance_fn.on_threshold_alert_published()
79+
def performancethreshold(
80+
alert: performance_fn.PerformanceThresholdAlertEvent) -> None:
81+
print(alert)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Not published yet,
2+
# firebase-functions-python >= 0.0.1
3+
# so we use a relative path during development:
4+
./../../../
5+
# Or switch to git ref for deployment testing:
6+
# git+https://github.com/firebase/firebase-functions-python.git@main#egg=firebase-functions
7+
8+
firebase-admin >= 6.0.1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""
15+
Cloud functions to handle events from Firebase Alerts.
16+
Subpackages give stronger typing to specific services which
17+
notify users via Firebase Alerts.
18+
"""
19+
20+
import dataclasses as _dataclasses
21+
import datetime as _dt
22+
import typing as _typing
23+
24+
from firebase_functions.core import T
25+
26+
27+
@_dataclasses.dataclass(frozen=True)
28+
class FirebaseAlertData(_typing.Generic[T]):
29+
"""
30+
The CloudEvent data emitted by Firebase Alerts.
31+
"""
32+
33+
create_time: _dt.datetime
34+
"""
35+
The time the alert was created.
36+
"""
37+
38+
end_time: _dt.datetime | None
39+
"""
40+
The time the alert ended. This is only set for alerts that have ended.
41+
"""
42+
43+
payload: T
44+
"""
45+
Payload of the event, which includes the details of the specific alert.
46+
"""

0 commit comments

Comments
 (0)