UNPKG

3.82 kBTypeScriptView Raw
1import { CloudEvent, CloudFunction } from "../../core";
2import { EventHandlerOptions } from "../../options";
3import { FirebaseAlertData } from "./alerts";
4/**
5 * The internal payload object for a performance threshold alert.
6 * Payload is wrapped inside a {@link FirebaseAlertData} object.
7 */
8export interface ThresholdAlertPayload {
9 /** Name of the trace or network request this alert is for (e.g. my_custom_trace, firebase.com/api/123) */
10 eventName: string;
11 /** The resource type this alert is for (i.e. trace, network request, screen rendering, etc.) */
12 eventType: string;
13 /** The metric type this alert is for (i.e. success rate, response time, duration, etc.) */
14 metricType: string;
15 /** The number of events checked for this alert condition */
16 numSamples: number;
17 /** The threshold value of the alert condition without units (e.g. "75", "2.1") */
18 thresholdValue: number;
19 /** The unit for the alert threshold (e.g. "percent", "seconds") */
20 thresholdUnit: string;
21 /** The percentile of the alert condition, can be 0 if percentile is not applicable to the alert condition and omitted; range: [1, 100] */
22 conditionPercentile?: number;
23 /** The app version this alert was triggered for, can be omitted if the alert is for a network request (because the alert was checked against data from all versions of app) or a web app (where the app is versionless) */
24 appVersion?: string;
25 /** The value that violated the alert condition (e.g. "76.5", "3") */
26 violationValue: number;
27 /** The unit for the violation value (e.g. "percent", "seconds") */
28 violationUnit: string;
29 /** The link to Fireconsole to investigate more into this alert */
30 investigateUri: string;
31}
32/**
33 * A custom CloudEvent for Firebase Alerts (with custom extension attributes).
34 * @typeParam T - the data type for performance alerts that is wrapped in a `FirebaseAlertData` object.
35 */
36export interface PerformanceEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
37 /** The type of the alerts that got triggered. */
38 alertType: string;
39 /** The Firebase App ID that’s associated with the alert. */
40 appId: string;
41}
42/**
43 * Configuration for app distribution functions.
44 */
45export interface PerformanceOptions extends EventHandlerOptions {
46 /** Scope the function to trigger on a specific application. */
47 appId?: string;
48}
49/**
50 * Declares a function that can handle receiving performance threshold alerts.
51 * @param handler - Event handler which is run every time a threshold alert is received.
52 * @returns A function that you can export and deploy.
53 */
54export declare function onThresholdAlertPublished(handler: (event: PerformanceEvent<ThresholdAlertPayload>) => any | Promise<any>): CloudFunction<PerformanceEvent<ThresholdAlertPayload>>;
55/**
56 * Declares a function that can handle receiving performance threshold alerts.
57 * @param appId - A specific application the handler will trigger on.
58 * @param handler - Event handler which is run every time a threshold alert is received.
59 * @returns A function that you can export and deploy.
60 */
61export declare function onThresholdAlertPublished(appId: string, handler: (event: PerformanceEvent<ThresholdAlertPayload>) => any | Promise<any>): CloudFunction<PerformanceEvent<ThresholdAlertPayload>>;
62/**
63 * Declares a function that can handle receiving performance threshold alerts.
64 * @param opts - Options that can be set on the function.
65 * @param handler - Event handler which is run every time a threshold alert is received.
66 * @returns A function that you can export and deploy.
67 */
68export declare function onThresholdAlertPublished(opts: PerformanceOptions, handler: (event: PerformanceEvent<ThresholdAlertPayload>) => any | Promise<any>): CloudFunction<PerformanceEvent<ThresholdAlertPayload>>;