Skip to content

Sentry Serverless types do not work with Firebase background functions #3269

@jsakas

Description

@jsakas

Package + Version

@sentry/serverless

6.2.0

Description

Firebase offers a few extra types of cloud functions that do not implement the same interface as the existing GCPFunction options. It seems like these work as expected but the typings do not allow a typescript project to compile.

Primarily the ones I am most interested today are the Cloud Firestore triggers and Authentication triggers. The remaining can be found in the docs: https://firebase.google.com/docs/functions/firestore-event

Here are some examples:

const thingCreateHandler = (snap, context) => {}

export const thingCreated = functions.firestore
  .document('things/{id}')
  .onCreate(Sentry.GCPFunction.wrapEventFunction(thingCreateHandler))

Argument of type 'EventFunctionWithCallback' is not assignable to parameter of type '(snapshot: QueryDocumentSnapshot, context: EventContext) => any'.ts(2345)

const userCreateHandler = (user, context) => {}

export const userCreate = functions.auth.user().onCreate(
  Sentry.GCPFunction.wrapEventFunction(userCreateHandler)
);

Argument of type 'EventFunctionWithCallback' is not assignable to parameter of type '(user: UserRecord, context: EventContext) => any'.ts(2345)

This is what the interface looks like:

  • Cloud Firestore Triggers:
    /** Respond to all document writes (creates, updates, or deletes). */
    onWrite(handler: (change: Change<DocumentSnapshot>, context: EventContext) => PromiseLike<any> | any): CloudFunction<Change<DocumentSnapshot>>;
    /** Respond only to document updates. */
    onUpdate(handler: (change: Change<QueryDocumentSnapshot>, context: EventContext) => PromiseLike<any> | any): CloudFunction<Change<QueryDocumentSnapshot>>;
    /** Respond only to document creations. */
    onCreate(handler: (snapshot: QueryDocumentSnapshot, context: EventContext) => PromiseLike<any> | any): CloudFunction<QueryDocumentSnapshot>;
    /** Respond only to document deletions. */
    onDelete(handler: (snapshot: QueryDocumentSnapshot, context: EventContext) => PromiseLike<any> | any): CloudFunction<QueryDocumentSnapshot>;
  • Authentication Triggers:
    /** Respond to the creation of a Firebase Auth user. */
    onCreate(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
    /** Respond to the deletion of a Firebase Auth user. */
    onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions