Skip to content

Commit 1aa1865

Browse files
authored
Update CloudEvent types (#1089)
* Updates to exported CloudEvent Types. This commit makes several updates to the exported CloudEvent types: * Billing types include a notificationType * [Link](https://github.com/googleapis/google-cloudevents/blob/main/proto/google/events/firebase/firebasealerts/v1/cloud_event_payload.proto#L132-L133) * Crashlytics have more documentation on fields * Storage has an exported `StorageEvent` which includes the bucket. * Storage function api references `StorageEvent` to better match to expected output. * Fixed NPE issue for Storage without Config * Updated more signatures to optionally expect a bucket.
1 parent 0bac53d commit 1aa1865

File tree

5 files changed

+84
-25
lines changed

5 files changed

+84
-25
lines changed

src/v2/providers/alerts/alerts.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ import * as options from '../../options';
66
* The CloudEvent data emitted by Firebase Alerts.
77
*/
88
export interface FirebaseAlertData<T = any> {
9+
/** Time that the event has created. */
910
createTime: string;
11+
/** Time that the event has ended. Optional, only present for ongoing alerts. */
1012
endTime: string;
13+
/** Payload of the event, which includes the details of the specific alert. */
1114
payload: T;
1215
}
1316

1417
interface WithAlertTypeAndApp {
18+
/** The type of the alerts that got triggered. */
1519
alertType: string;
20+
/**
21+
* The Firebase App ID that’s associated with the alert. This is optional,
22+
* and only present when the alert is targeting at a specific Firebase App.
23+
*/
1624
appId?: string;
1725
}
1826
/**

src/v2/providers/alerts/appDistribution.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export interface NewTesterDevicePayload {
1515
}
1616

1717
interface WithAlertTypeAndApp {
18+
/** The type of the alerts that got triggered. */
1819
alertType: string;
20+
/** The Firebase App ID that’s associated with the alert. */
1921
appId: string;
2022
}
2123
/**

src/v2/providers/alerts/billing.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import * as options from '../../options';
88
*/
99
export interface PlanUpdatePayload {
1010
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.BillingPlanUpdatePayload';
11+
/** A Firebase billing plan. */
1112
billingPlan: string;
13+
/** The email address of the person that triggered billing plan change */
1214
principalEmail: string;
15+
/** The type of the notification, e.g. upgrade, downgrade */
16+
notificationType: string;
1317
}
1418

1519
/**
@@ -18,10 +22,14 @@ export interface PlanUpdatePayload {
1822
*/
1923
export interface PlanAutomatedUpdatePayload {
2024
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.BillingPlanAutomatedUpdatePayload';
25+
/** A Firebase billing plan. */
2126
billingPlan: string;
27+
/** The type of the notification, e.g. upgrade, downgrade */
28+
notificationType: string;
2229
}
2330

2431
interface WithAlertType {
32+
/** The type of the alerts that got triggered. */
2533
alertType: string;
2634
}
2735
/**

src/v2/providers/alerts/crashlytics.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface Issue {
1616
*/
1717
export interface NewFatalIssuePayload {
1818
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewFatalIssuePayload';
19+
/** Basic information of the Crashlytics issue */
1920
issue: Issue;
2021
}
2122

@@ -25,6 +26,7 @@ export interface NewFatalIssuePayload {
2526
*/
2627
export interface NewNonfatalIssuePayload {
2728
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewNonfatalIssuePayload';
29+
/** Basic information of the Crashlytics issue */
2830
issue: Issue;
2931
}
3032

@@ -34,16 +36,26 @@ export interface NewNonfatalIssuePayload {
3436
*/
3537
export interface RegressionAlertPayload {
3638
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsRegressionAlertPayload';
39+
/** The type of the Crashlytics issue, e.g. new fatal, new nonfatal, ANR */
3740
type: string;
41+
/** Basic information of the Crashlytics issue */
3842
issue: Issue;
43+
/**
44+
* The time that the Crashlytics issues was most recently resolved before it
45+
* began to reoccur.
46+
*/
3947
resolveTime: string;
4048
}
4149

4250
/** Generic crashlytics trending issue interface */
4351
interface TrendingIssueDetails {
52+
/** The type of the Crashlytics issue, e.g. new fatal, new nonfatal, ANR */
4453
type: string;
54+
/** Basic information of the Crashlytics issue */
4555
issue: Issue;
56+
/** The number of crashes that occurred with the issue */
4657
eventCount: number;
58+
/** The number of distinct users that were affected by the issue */
4759
userCount: number;
4860
}
4961

@@ -53,7 +65,12 @@ interface TrendingIssueDetails {
5365
*/
5466
export interface StabilityDigestPayload {
5567
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsStabilityDigestPayload';
68+
/**
69+
* The date that the digest gets created. Issues in the digest should have the
70+
* same date as the digest date
71+
*/
5672
digestDate: string;
73+
/** A stability digest containing several trending Crashlytics issues */
5774
trendingIssues: TrendingIssueDetails[];
5875
}
5976

@@ -63,10 +80,24 @@ export interface StabilityDigestPayload {
6380
*/
6481
export interface VelocityAlertPayload {
6582
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsVelocityAlertPayload';
83+
/** Basic information of the Crashlytics issue */
6684
issue: Issue;
85+
/** The time that the Crashlytics issue gets created */
6786
createTime: string;
87+
/**
88+
* The number of user sessions for the given app version that had this
89+
* specific crash issue in the time period used to trigger the velocity alert.
90+
*/
6891
crashCount: number;
92+
/**
93+
* The percentage of user sessions for the given app version that had this
94+
* specific crash issue in the time period used to trigger the velocity alert.
95+
*/
6996
crashPercentage: number;
97+
/**
98+
* The first app version where this issue was seen, and not necessarily the
99+
* version that has triggered the alert.
100+
*/
70101
firstVersion: string;
71102
}
72103

@@ -76,11 +107,14 @@ export interface VelocityAlertPayload {
76107
*/
77108
export interface NewAnrIssuePayload {
78109
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.CrashlyticsNewAnrIssuePayload';
110+
/** Basic information of the Crashlytics issue */
79111
issue: Issue;
80112
}
81113

82114
interface WithAlertTypeAndApp {
115+
/** The type of the alerts that got triggered. */
83116
alertType: string;
117+
/** The Firebase App ID that’s associated with the alert. */
84118
appId: string;
85119
}
86120
/**

src/v2/providers/storage.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ export interface CustomerEncryption {
174174
keySha256?: string;
175175
}
176176

177+
interface WithBucket {
178+
/** The name of the bucket containing this object. */
179+
bucket: string;
180+
}
181+
182+
export type StorageEvent = CloudEvent<StorageObjectData, WithBucket>;
183+
177184
/** @internal */
178185
export const archivedEvent = 'google.cloud.storage.object.v1.archived';
179186
/** @internal */
@@ -191,100 +198,100 @@ export interface StorageOptions extends options.EventHandlerOptions {
191198

192199
/** Handle a storage object archived */
193200
export function onObjectArchived(
194-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
201+
handler: (event: StorageEvent) => any | Promise<any>
195202
): CloudFunction<StorageObjectData>;
196203

197204
export function onObjectArchived(
198205
bucket: string,
199-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
206+
handler: (event: StorageEvent) => any | Promise<any>
200207
): CloudFunction<StorageObjectData>;
201208

202209
export function onObjectArchived(
203210
opts: StorageOptions,
204-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
211+
handler: (event: StorageEvent) => any | Promise<any>
205212
): CloudFunction<StorageObjectData>;
206213

207214
export function onObjectArchived(
208215
buketOrOptsOrHandler:
209216
| string
210217
| StorageOptions
211-
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>),
212-
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
218+
| ((event: StorageEvent) => any | Promise<any>),
219+
handler?: (event: StorageEvent) => any | Promise<any>
213220
): CloudFunction<StorageObjectData> {
214221
return onOperation(archivedEvent, buketOrOptsOrHandler, handler);
215222
}
216223

217224
/** Handle a storage object finalized */
218225
export function onObjectFinalized(
219-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
226+
handler: (event: StorageEvent) => any | Promise<any>
220227
): CloudFunction<StorageObjectData>;
221228

222229
export function onObjectFinalized(
223230
bucket: string,
224-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
231+
handler: (event: StorageEvent) => any | Promise<any>
225232
): CloudFunction<StorageObjectData>;
226233

227234
export function onObjectFinalized(
228235
opts: StorageOptions,
229-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
236+
handler: (event: StorageEvent) => any | Promise<any>
230237
): CloudFunction<StorageObjectData>;
231238

232239
export function onObjectFinalized(
233240
buketOrOptsOrHandler:
234241
| string
235242
| StorageOptions
236-
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>),
237-
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
243+
| ((event: StorageEvent) => any | Promise<any>),
244+
handler?: (event: StorageEvent) => any | Promise<any>
238245
): CloudFunction<StorageObjectData> {
239246
return onOperation(finalizedEvent, buketOrOptsOrHandler, handler);
240247
}
241248

242249
/** Handle a storage object deleted */
243250
export function onObjectDeleted(
244-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
251+
handler: (event: StorageEvent) => any | Promise<any>
245252
): CloudFunction<StorageObjectData>;
246253

247254
export function onObjectDeleted(
248255
bucket: string,
249-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
256+
handler: (event: StorageEvent) => any | Promise<any>
250257
): CloudFunction<StorageObjectData>;
251258

252259
export function onObjectDeleted(
253260
opts: StorageOptions,
254-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
261+
handler: (event: StorageEvent) => any | Promise<any>
255262
): CloudFunction<StorageObjectData>;
256263

257264
export function onObjectDeleted(
258265
buketOrOptsOrHandler:
259266
| string
260267
| StorageOptions
261-
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>),
262-
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
268+
| ((event: StorageEvent) => any | Promise<any>),
269+
handler?: (event: StorageEvent) => any | Promise<any>
263270
): CloudFunction<StorageObjectData> {
264271
return onOperation(deletedEvent, buketOrOptsOrHandler, handler);
265272
}
266273

267274
/** Handle a storage object metadata updated */
268275
export function onObjectMetadataUpdated(
269-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
276+
handler: (event: StorageEvent) => any | Promise<any>
270277
): CloudFunction<StorageObjectData>;
271278

272279
export function onObjectMetadataUpdated(
273280
bucket: string,
274-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
281+
handler: (event: StorageEvent) => any | Promise<any>
275282
): CloudFunction<StorageObjectData>;
276283

277284
export function onObjectMetadataUpdated(
278285
opts: StorageOptions,
279-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
286+
handler: (event: StorageEvent) => any | Promise<any>
280287
): CloudFunction<StorageObjectData>;
281288

282289
export function onObjectMetadataUpdated(
283290
buketOrOptsOrHandler:
284291
| string
285292
| StorageOptions
286-
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>),
287-
handler?: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
293+
| ((event: StorageEvent) => any | Promise<any>),
294+
handler?: (event: StorageEvent) => any | Promise<any>
288295
): CloudFunction<StorageObjectData> {
289296
return onOperation(metadataUpdatedEvent, buketOrOptsOrHandler, handler);
290297
}
@@ -295,12 +302,12 @@ export function onOperation(
295302
bucketOrOptsOrHandler:
296303
| string
297304
| StorageOptions
298-
| ((event: CloudEvent<StorageObjectData>) => any | Promise<any>),
299-
handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>
305+
| ((event: StorageEvent) => any | Promise<any>),
306+
handler: (event: StorageEvent) => any | Promise<any>
300307
): CloudFunction<StorageObjectData> {
301308
if (typeof bucketOrOptsOrHandler === 'function') {
302309
handler = bucketOrOptsOrHandler as (
303-
event: CloudEvent<StorageObjectData>
310+
event: StorageEvent
304311
) => any | Promise<any>;
305312
bucketOrOptsOrHandler = {};
306313
}
@@ -310,7 +317,7 @@ export function onOperation(
310317
);
311318

312319
const func = (raw: CloudEvent<unknown>) => {
313-
return handler(raw as CloudEvent<StorageObjectData>);
320+
return handler(raw as StorageEvent);
314321
};
315322

316323
func.run = handler;
@@ -382,7 +389,7 @@ export function getOptsAndBucket(
382389
bucket = bucketOrOpts;
383390
opts = {};
384391
} else {
385-
bucket = bucketOrOpts.bucket || firebaseConfig().storageBucket;
392+
bucket = bucketOrOpts.bucket || firebaseConfig()?.storageBucket;
386393
opts = { ...bucketOrOpts };
387394
delete (opts as any).bucket;
388395
}

0 commit comments

Comments
 (0)