@@ -25,11 +25,13 @@ import * as _ from 'lodash';
2525import { DeploymentOptions , Schedule } from './function-configuration' ;
2626export { Request , Response } ;
2727
28+ /** @hidden */
2829const WILDCARD_REGEX = new RegExp ( '{[^/{}]*}' , 'g' ) ;
2930
3031/**
31- * Wire format for an event.
3232 * @hidden
33+ *
34+ * Wire format for an event.
3335 */
3436export interface Event {
3537 context : {
@@ -53,38 +55,89 @@ export interface Event {
5355 */
5456export interface EventContext {
5557 /**
56- * Firebase auth variable for the user whose action triggered the function.
57- * Field will be null for unauthenticated users, and will not exist for admin
58- * users. Only available for database functions.
58+ * Authentication information for the user that triggered the function.
59+ * This object contains `uid` and `token` properties for authenticated users.
60+ * For more detail including token keys, see the
61+ * [security rules reference](/docs/firestore/reference/security/#properties).
62+ *
63+ * This field is only populated for Realtime Database triggers and Callable
64+ * functions. For an unauthenticated user, this field is null. For Firebase
65+ * admin users and event types that do not provide user information, this field
66+ * does not exist.
5967 */
6068 auth ?: {
6169 token : object ;
6270 uid : string ;
6371 } ;
72+
6473 /**
65- * Type of authentication for the triggering action. Only available for
66- * database functions.
74+ * The level of permissions for a user. Valid values are:
75+ *
76+ * * `ADMIN` Developer user or user authenticated via a service account.
77+ * * `USER` Known user.
78+ * * `UNAUTHENTICATED` Unauthenticated action
79+ * * `null` For event types that do not provide user information (all except
80+ * Realtime Database).
6781 */
6882 authType ?: 'ADMIN' | 'USER' | 'UNAUTHENTICATED' ;
83+
6984 /**
70- * ID of the event
85+ * The event’s unique identifier.
7186 */
7287 eventId : string ;
88+
7389 /**
74- * Type of event
90+ * Type of event. Valid values are:
91+ *
92+ * * `providers/google.firebase.analytics/eventTypes/event.log`
93+ * * `providers/firebase.auth/eventTypes/user.create`
94+ * * `providers/firebase.auth/eventTypes/user.delete`
95+ * * `providers/firebase.crashlytics/eventTypes/issue.new`
96+ * * `providers/firebase.crashlytics/eventTypes/issue.regressed`
97+ * * `providers/firebase.crashlytics/eventTypes/issue.velocityAlert`
98+ * * `providers/google.firebase.database/eventTypes/ref.write`
99+ * * `providers/google.firebase.database/eventTypes/ref.create`
100+ * * `providers/google.firebase.database/eventTypes/ref.update`
101+ * * `providers/google.firebase.database/eventTypes/ref.delete`
102+ * * `providers/cloud.firestore/eventTypes/document.write`
103+ * * `providers/cloud.firestore/eventTypes/document.create`
104+ * * `providers/cloud.firestore/eventTypes/document.update`
105+ * * `providers/cloud.firestore/eventTypes/document.delete`
106+ * * `google.pubsub.topic.publish`
107+ * * `google.storage.object.finalize`
108+ * * `google.storage.object.archive`
109+ * * `google.storage.object.delete`
110+ * * `google.storage.object.metadataUpdate`
111+ * * `google.firebase.remoteconfig.update`
75112 */
76113 eventType : string ;
114+
77115 /**
78- * Key-value pairs that represent the values of wildcards in a database
79- * reference. Cannot be accessed while inside the handler namespace.
116+ * An object containing the values of the wildcards in the `path` parameter
117+ * provided to the [`ref()`](functions.database#.ref) method for a Realtime
118+ * Database trigger. Cannot be accessed while inside the handler namespace.
80119 */
81120 params : { [ option : string ] : any } ;
121+
82122 /**
83- * Resource that triggered the event
123+ * The resource that emitted the event. Valid values are:
124+ *
125+ * * Analytics — `projects/<projectId>/events/<analyticsEventType>`
126+ * * Realtime Database —
127+ `projects/_/instances/<databaseInstance>/refs/<databasePath>`
128+ * * Storage —
129+ `projects/_/buckets/<bucketName>/objects/<fileName>#<generation>`
130+ * * Authentication — `projects/<projectId>`
131+ * * Pub/Sub — `projects/<projectId>/topics/<topicName>`
132+ *
133+ * Because Realtime Database instances and Cloud Storage buckets are globally
134+ * unique and not tied to the project, their resources start with `projects/_`.
135+ * Underscore is not a valid project name.
84136 */
85137 resource : Resource ;
86138 /**
87- * Timestamp for when the event ocurred (ISO 8601 string)
139+ * Timestamp for the event as an
140+ * [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) string.
88141 */
89142 timestamp : string ;
90143}
@@ -180,6 +233,7 @@ export interface Resource {
180233}
181234
182235/**
236+ * @hidden
183237 * TriggerAnnotated is used internally by the firebase CLI to understand what
184238 * type of Cloud Function to deploy.
185239 */
@@ -208,17 +262,23 @@ export interface Runnable<T> {
208262}
209263
210264/**
211- * An HttpsFunction is both an object that exports its trigger definitions at
212- * __trigger and can be called as a function that takes an express.js Request
213- * and Response object.
265+ * The Cloud Function type for HTTPS triggers. This should be exported from your
266+ * JavaScript file to define a Cloud Function.
267+ *
268+ * This type is a special JavaScript function which takes Express
269+ * [`Request`](https://expressjs.com/en/api.html#req) and
270+ * [`Response`](https://expressjs.com/en/api.html#res) objects as its only
271+ * arguments.
214272 */
215273export type HttpsFunction = TriggerAnnotated &
216274 ( ( req : Request , resp : Response ) => void ) ;
217275
218276/**
219- * A CloudFunction is both an object that exports its trigger definitions at
220- * __trigger and can be called as a function using the raw JS API for Google
221- * Cloud Functions.
277+ * The Cloud Function type for all non-HTTPS triggers. This should be exported
278+ * from your JavaScript file to define a Cloud Function.
279+ *
280+ * This type is a special JavaScript function which takes a templated
281+ * `Event` object as its only argument.
222282 */
223283export type CloudFunction < T > = Runnable < T > &
224284 TriggerAnnotated &
@@ -346,6 +406,7 @@ export function makeCloudFunction<EventData>({
346406 return cloudFunction ;
347407}
348408
409+ /** @hidden */
349410function _makeParams (
350411 context : EventContext ,
351412 triggerResourceGetter : ( ) => string
@@ -373,6 +434,7 @@ function _makeParams(
373434 return params ;
374435}
375436
437+ /** @hidden */
376438function _makeAuth ( event : Event , authType : string ) {
377439 if ( authType === 'UNAUTHENTICATED' ) {
378440 return null ;
@@ -383,6 +445,7 @@ function _makeAuth(event: Event, authType: string) {
383445 } ;
384446}
385447
448+ /** @hidden */
386449function _detectAuthType ( event : Event ) {
387450 if ( _ . get ( event , 'context.auth.admin' ) ) {
388451 return 'ADMIN' ;
@@ -393,6 +456,7 @@ function _detectAuthType(event: Event) {
393456 return 'UNAUTHENTICATED' ;
394457}
395458
459+ /** @hidden */
396460export function optionsToTrigger ( options : DeploymentOptions ) {
397461 const trigger : any = { } ;
398462 if ( options . regions ) {
0 commit comments