UNPKG

17.3 kBTypeScriptView Raw
1/**
2 * Cloud functions to handle Crashlytics events from Firebase Alerts.
3 * @packageDocumentation
4 */
5import { ResetValue } from "../../../common/options";
6import { Expression } from "../../../params";
7import { CloudEvent, CloudFunction } from "../../core";
8import { FirebaseAlertData } from "./alerts";
9import * as options from "../../options";
10import { SecretParam } from "../../../params/types";
11/** Generic Crashlytics issue interface */
12export interface Issue {
13 /** The ID of the Crashlytics issue */
14 id: string;
15 /** The title of the Crashlytics issue */
16 title: string;
17 /** The subtitle of the Crashlytics issue */
18 subtitle: string;
19 /** The application version of the Crashlytics issue */
20 appVersion: string;
21}
22/**
23 * The internal payload object for a new fatal issue.
24 * Payload is wrapped inside a `FirebaseAlertData` object.
25 */
26export interface NewFatalIssuePayload {
27 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewFatalIssuePayload";
28 /** Basic information of the Crashlytics issue */
29 issue: Issue;
30}
31/**
32 * The internal payload object for a new non-fatal issue.
33 * Payload is wrapped inside a `FirebaseAlertData` object.
34 */
35export interface NewNonfatalIssuePayload {
36 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewNonfatalIssuePayload";
37 /** Basic information of the Crashlytics issue */
38 issue: Issue;
39}
40/**
41 * The internal payload object for a regression alert.
42 * Payload is wrapped inside a `FirebaseAlertData` object.
43 */
44export interface RegressionAlertPayload {
45 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsRegressionAlertPayload";
46 /** The type of the Crashlytics issue, e.g. new fatal, new nonfatal, ANR */
47 type: string;
48 /** Basic information of the Crashlytics issue */
49 issue: Issue;
50 /**
51 * The time that the Crashlytics issues was most recently resolved before it
52 * began to reoccur.
53 */
54 resolveTime: string;
55}
56/** Generic Crashlytics trending issue interface */
57export interface TrendingIssueDetails {
58 /** The type of the Crashlytics issue, e.g. new fatal, new nonfatal, ANR */
59 type: string;
60 /** Basic information of the Crashlytics issue */
61 issue: Issue;
62 /** The number of crashes that occurred with the issue */
63 eventCount: number;
64 /** The number of distinct users that were affected by the issue */
65 userCount: number;
66}
67/**
68 * The internal payload object for a stability digest.
69 * Payload is wrapped inside a `FirebaseAlertData` object.
70 */
71export interface StabilityDigestPayload {
72 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsStabilityDigestPayload";
73 /**
74 * The date that the digest gets created. Issues in the digest should have the
75 * same date as the digest date
76 */
77 digestDate: string;
78 /** A stability digest containing several trending Crashlytics issues */
79 trendingIssues: TrendingIssueDetails[];
80}
81/**
82 * The internal payload object for a velocity alert.
83 * Payload is wrapped inside a `FirebaseAlertData` object.
84 */
85export interface VelocityAlertPayload {
86 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsVelocityAlertPayload";
87 /** Basic information of the Crashlytics issue */
88 issue: Issue;
89 /** The time that the Crashlytics issue gets created */
90 createTime: string;
91 /**
92 * The number of user sessions for the given app version that had this
93 * specific crash issue in the time period used to trigger the velocity alert.
94 */
95 crashCount: number;
96 /**
97 * The percentage of user sessions for the given app version that had this
98 * specific crash issue in the time period used to trigger the velocity alert.
99 */
100 crashPercentage: number;
101 /**
102 * The first app version where this issue was seen, and not necessarily the
103 * version that has triggered the alert.
104 */
105 firstVersion: string;
106}
107/**
108 * The internal payload object for a new Application Not Responding issue.
109 * Payload is wrapped inside a `FirebaseAlertData` object.
110 */
111export interface NewAnrIssuePayload {
112 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewAnrIssuePayload";
113 /** Basic information of the Crashlytics issue */
114 issue: Issue;
115}
116/**
117 * A custom CloudEvent for Firebase Alerts (with custom extension attributes).
118 * @typeParam T - the data type for Crashlytics alerts that is wrapped in a `FirebaseAlertData` object.
119 */
120export interface CrashlyticsEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
121 /** The type of the alerts that got triggered. */
122 alertType: string;
123 /** The Firebase App ID that’s associated with the alert. */
124 appId: string;
125}
126/**
127 * Configuration for Crashlytics functions.
128 */
129export interface CrashlyticsOptions extends options.EventHandlerOptions {
130 /** Scope the function to trigger on a specific application. */
131 appId?: string;
132 /**
133 * If true, do not deploy or emulate this function.
134 */
135 omit?: boolean | Expression<boolean>;
136 /**
137 * Region where functions should be deployed.
138 */
139 region?: options.SupportedRegion | string | Expression<string> | ResetValue;
140 /**
141 * Amount of memory to allocate to a function.
142 */
143 memory?: options.MemoryOption | Expression<number> | ResetValue;
144 /**
145 * Timeout for the function in seconds, possible values are 0 to 540.
146 * HTTPS functions can specify a higher timeout.
147 *
148 * @remarks
149 * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
150 * function depends on the type of function: Event handling functions have a
151 * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
152 * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
153 * timeout of 1,800s (30 minutes)
154 */
155 timeoutSeconds?: number | Expression<number> | ResetValue;
156 /**
157 * Min number of actual instances to be running at a given time.
158 *
159 * @remarks
160 * Instances will be billed for memory allocation and 10% of CPU allocation
161 * while idle.
162 */
163 minInstances?: number | Expression<number> | ResetValue;
164 /**
165 * Max number of instances to be running in parallel.
166 */
167 maxInstances?: number | Expression<number> | ResetValue;
168 /**
169 * Number of requests a function can serve at once.
170 *
171 * @remarks
172 * Can only be applied to functions running on Cloud Functions v2.
173 * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
174 * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
175 * The maximum value for concurrency is 1,000.
176 */
177 concurrency?: number | Expression<number> | ResetValue;
178 /**
179 * Fractional number of CPUs to allocate to a function.
180 *
181 * @remarks
182 * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
183 * This is different from the defaults when using the gcloud utility and is different from
184 * the fixed amount assigned in Google Cloud Functions generation 1.
185 * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
186 * to the value "gcf_gen1"
187 */
188 cpu?: number | "gcf_gen1";
189 /**
190 * Connect cloud function to specified VPC connector.
191 */
192 vpcConnector?: string | Expression<string> | ResetValue;
193 /**
194 * Egress settings for VPC connector.
195 */
196 vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
197 /**
198 * Specific service account for the function to run as.
199 */
200 serviceAccount?: string | Expression<string> | ResetValue;
201 /**
202 * Ingress settings which control where this function can be called from.
203 */
204 ingressSettings?: options.IngressSetting | ResetValue;
205 /**
206 * User labels to set on the function.
207 */
208 labels?: Record<string, string>;
209 secrets?: (string | SecretParam)[];
210 /** Whether failed executions should be delivered again. */
211 retry?: boolean | Expression<boolean> | ResetValue;
212}
213/**
214 * Declares a function that can handle a new fatal issue published to Crashlytics.
215 * @param handler - Event handler that is triggered when a new fatal issue is published to Crashlytics.
216 * @returns A function that you can export and deploy.
217 */
218export declare function onNewFatalIssuePublished(handler: (event: CrashlyticsEvent<NewFatalIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewFatalIssuePayload>>;
219/**
220 * Declares a function that can handle a new fatal issue published to Crashlytics.
221 * @param appId - A specific application the handler will trigger on.
222 * @param handler - Event handler that is triggered when a new fatal issue is published to Crashlytics.
223 * @returns A function that you can export and deploy.
224 */
225export declare function onNewFatalIssuePublished(appId: string, handler: (event: CrashlyticsEvent<NewFatalIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewFatalIssuePayload>>;
226/**
227 * Declares a function that can handle a new fatal issue published to Crashlytics.
228 * @param opts - Options that can be set on the function.
229 * @param handler - Event handler that is triggered when a new fatal issue is published to Crashlytics.
230 * @returns A function that you can export and deploy.
231 */
232export declare function onNewFatalIssuePublished(opts: CrashlyticsOptions, handler: (event: CrashlyticsEvent<NewFatalIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewFatalIssuePayload>>;
233/**
234 * Declares a function that can handle a new non-fatal issue published to Crashlytics.
235 * @param handler - Event handler that is triggered when a new fatal issue is published to Crashlytics.
236 * @returns A function that you can export and deploy.
237 */
238export declare function onNewNonfatalIssuePublished(handler: (event: CrashlyticsEvent<NewNonfatalIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewNonfatalIssuePayload>>;
239/**
240 * Declares a function that can handle a new non-fatal issue published to Crashlytics.
241 * @param appId - A specific application the handler will trigger on.
242 * @param handler - Event handler that is triggered when a new non-fatal issue is published to Crashlytics.
243 * @returns A function that you can export and deploy.
244 */
245export declare function onNewNonfatalIssuePublished(appId: string, handler: (event: CrashlyticsEvent<NewNonfatalIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewNonfatalIssuePayload>>;
246/**
247 * Declares a function that can handle a new non-fatal issue published to Crashlytics.
248 * @param opts - Options that can be set on the function.
249 * @param handler - Event handler that is triggered when a new non-fatal issue is published to Crashlytics.
250 * @returns A function that you can export and deploy.
251 */
252export declare function onNewNonfatalIssuePublished(opts: CrashlyticsOptions, handler: (event: CrashlyticsEvent<NewNonfatalIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewNonfatalIssuePayload>>;
253/**
254 * Declares a function that can handle a regression alert published to Crashlytics.
255 * @param handler - Event handler that is triggered when a regression alert is published to Crashlytics.
256 * @returns A function that you can export and deploy.
257 */
258export declare function onRegressionAlertPublished(handler: (event: CrashlyticsEvent<RegressionAlertPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<RegressionAlertPayload>>;
259/**
260 * Declares a function that can handle a regression alert published to Crashlytics.
261 * @param appId - A specific application the handler will trigger on.
262 * @param handler - Event handler that is triggered when a regression alert is published to Crashlytics.
263 * @returns A function that you can export and deploy.
264
265 */
266export declare function onRegressionAlertPublished(appId: string, handler: (event: CrashlyticsEvent<RegressionAlertPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<RegressionAlertPayload>>;
267/**
268 * Declares a function that can handle a regression alert published to Crashlytics.
269 * @param opts - Options that can be set on the function.
270 * @param handler - Event handler that is triggered when a regression alert is published to Crashlytics.
271 * @returns A function that you can export and deploy.
272
273 */
274export declare function onRegressionAlertPublished(opts: CrashlyticsOptions, handler: (event: CrashlyticsEvent<RegressionAlertPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<RegressionAlertPayload>>;
275/**
276 * Declares a function that can handle a stability digest published to Crashlytics.
277 * @param handler - Event handler that is triggered when a stability digest is published to Crashlytics.
278 * @returns A function that you can export and deploy.
279 */
280export declare function onStabilityDigestPublished(handler: (event: CrashlyticsEvent<StabilityDigestPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<StabilityDigestPayload>>;
281/**
282 * Declares a function that can handle a stability digest published to Crashlytics.
283 * @param appId - A specific application the handler will trigger on.
284 * @param handler - Event handler that is triggered when a stability digest is published to Crashlytics.
285 * @returns A function that you can export and deploy.
286
287 */
288export declare function onStabilityDigestPublished(appId: string, handler: (event: CrashlyticsEvent<StabilityDigestPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<StabilityDigestPayload>>;
289/**
290 * Declares a function that can handle a stability digest published to Crashlytics.
291 * @param opts - Options that can be set on the function.
292 * @param handler - Event handler that is triggered when a stability digest is published to Crashlytics.
293 * @returns A function that you can export and deploy.
294
295 */
296export declare function onStabilityDigestPublished(opts: CrashlyticsOptions, handler: (event: CrashlyticsEvent<StabilityDigestPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<StabilityDigestPayload>>;
297/**
298 * Declares a function that can handle a velocity alert published to Crashlytics.
299 * @param handler - Event handler that is triggered when a velocity alert is published to Crashlytics.
300 * @returns A function that you can export and deploy.
301 */
302export declare function onVelocityAlertPublished(handler: (event: CrashlyticsEvent<VelocityAlertPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<VelocityAlertPayload>>;
303/**
304 * Declares a function that can handle a velocity alert published to Crashlytics.
305 * @param appId - A specific application the handler will trigger on.
306 * @param handler - Event handler that is triggered when a velocity alert is published to Crashlytics.
307 * @returns A function that you can export and deploy.
308 */
309export declare function onVelocityAlertPublished(appId: string, handler: (event: CrashlyticsEvent<VelocityAlertPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<VelocityAlertPayload>>;
310/**
311 * Declares a function that can handle a velocity alert published to Crashlytics.
312 * @param opts - Options that can be set on the function.
313 * @param handler - Event handler that is triggered when a velocity alert is published to Crashlytics.
314 * @returns A function that you can export and deploy.
315 */
316export declare function onVelocityAlertPublished(opts: CrashlyticsOptions, handler: (event: CrashlyticsEvent<VelocityAlertPayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<VelocityAlertPayload>>;
317/**
318 * Declares a function that can handle a new Application Not Responding issue published to Crashlytics.
319 * @param handler - Event handler that is triggered when a new Application Not Responding issue is published to Crashlytics.
320 * @returns A function that you can export and deploy.
321 */
322export declare function onNewAnrIssuePublished(handler: (event: CrashlyticsEvent<NewAnrIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewAnrIssuePayload>>;
323/**
324 * Declares a function that can handle a new Application Not Responding issue published to Crashlytics.
325 * @param appId - A specific application the handler will trigger on.
326 * @param handler - Event handler that is triggered when a new Application Not Responding issue is published to Crashlytics.
327 * @returns A function that you can export and deploy.
328
329 */
330export declare function onNewAnrIssuePublished(appId: string, handler: (event: CrashlyticsEvent<NewAnrIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewAnrIssuePayload>>;
331/**
332 * Declares a function that can handle a new Application Not Responding issue published to Crashlytics.
333 * @param opts - Options that can be set on the function.
334 * @param handler - Event handler that is triggered when a new Application Not Responding issue is published to Crashlytics.
335 * @returns A function that you can export and deploy.
336
337 */
338export declare function onNewAnrIssuePublished(opts: CrashlyticsOptions, handler: (event: CrashlyticsEvent<NewAnrIssuePayload>) => any | Promise<any>): CloudFunction<CrashlyticsEvent<NewAnrIssuePayload>>;