1 | import { Request, Response } from "express";
|
2 | import { DeploymentOptions, FailurePolicy, Schedule } from "./function-configuration";
|
3 | export { Request, Response };
|
4 | import { ManifestEndpoint, ManifestRequiredAPI } from "../runtime/manifest";
|
5 | export { Change } from "../common/change";
|
6 | /**
|
7 | * Wire format for an event.
|
8 | */
|
9 | export interface Event {
|
10 | /**
|
11 | * Wire format for an event context.
|
12 | */
|
13 | context: {
|
14 | eventId: string;
|
15 | timestamp: string;
|
16 | eventType: string;
|
17 | resource: Resource;
|
18 | domain?: string;
|
19 | auth?: {
|
20 | variable?: {
|
21 | uid?: string;
|
22 | token?: string;
|
23 | };
|
24 | admin: boolean;
|
25 | };
|
26 | };
|
27 | /**
|
28 | * Event data over wire.
|
29 | */
|
30 | data: any;
|
31 | }
|
32 | /**
|
33 | * The context in which an event occurred.
|
34 | *
|
35 | * @remarks
|
36 | * An EventContext describes:
|
37 | * - The time an event occurred.
|
38 | * - A unique identifier of the event.
|
39 | * - The resource on which the event occurred, if applicable.
|
40 | * - Authorization of the request that triggered the event, if applicable and
|
41 | * available.
|
42 | */
|
43 | export interface EventContext<Params = Record<string, string>> {
|
44 | /**
|
45 | * Authentication information for the user that triggered the function.
|
46 | *
|
47 | * @remarks
|
48 | * This object contains `uid` and `token` properties for authenticated users.
|
49 | * For more detail including token keys, see the
|
50 | * {@link https://firebase.google.com/docs/reference/rules/rules#properties | security rules reference}.
|
51 | *
|
52 | * This field is only populated for Realtime Database triggers and Callable
|
53 | * functions. For an unauthenticated user, this field is null. For Firebase
|
54 | * admin users and event types that do not provide user information, this field
|
55 | * does not exist.
|
56 | */
|
57 | auth?: {
|
58 | token: object;
|
59 | uid: string;
|
60 | };
|
61 | /**
|
62 | * The level of permissions for a user.
|
63 | *
|
64 | * @remarks
|
65 | * Valid values are:
|
66 | *
|
67 | * - `ADMIN`: Developer user or user authenticated via a service account.
|
68 | *
|
69 | * - `USER`: Known user.
|
70 | *
|
71 | * - `UNAUTHENTICATED`: Unauthenticated action
|
72 | *
|
73 | * - `null`: For event types that do not provide user information (all except
|
74 | * Realtime Database).
|
75 | */
|
76 | authType?: "ADMIN" | "USER" | "UNAUTHENTICATED";
|
77 | /**
|
78 | * The event’s unique identifier.
|
79 | */
|
80 | eventId: string;
|
81 | /**
|
82 | * Type of event.
|
83 | *
|
84 | * @remarks
|
85 | * Possible values are:
|
86 | *
|
87 | * - `google.analytics.event.log`
|
88 | *
|
89 | * - `google.firebase.auth.user.create`
|
90 | *
|
91 | * - `google.firebase.auth.user.delete`
|
92 | *
|
93 | * - `google.firebase.database.ref.write`
|
94 | *
|
95 | * - `google.firebase.database.ref.create`
|
96 | *
|
97 | * - `google.firebase.database.ref.update`
|
98 | *
|
99 | * - `google.firebase.database.ref.delete`
|
100 | *
|
101 | * - `google.firestore.document.write`
|
102 | *
|
103 | * - `google.firestore.document.create`
|
104 | *
|
105 | * - `google.firestore.document.update`
|
106 | *
|
107 | * - `google.firestore.document.delete`
|
108 | *
|
109 | * - `google.pubsub.topic.publish`
|
110 | *
|
111 | * - `google.firebase.remoteconfig.update`
|
112 | *
|
113 | * - `google.storage.object.finalize`
|
114 | *
|
115 | * - `google.storage.object.archive`
|
116 | *
|
117 | * - `google.storage.object.delete`
|
118 | *
|
119 | * - `google.storage.object.metadataUpdate`
|
120 | *
|
121 | * - `google.testing.testMatrix.complete`
|
122 | */
|
123 | eventType: string;
|
124 | /**
|
125 | * An object containing the values of the wildcards in the `path` parameter
|
126 | * provided to the {@link fireabase-functions.v1.database#ref | `ref()`} method for a Realtime Database trigger.
|
127 | */
|
128 | params: Params;
|
129 | /**
|
130 | * The resource that emitted the event.
|
131 | *
|
132 | * @remarks
|
133 | * Valid values are:
|
134 | *
|
135 | * Analytics: `projects/<projectId>/events/<analyticsEventType>`
|
136 | *
|
137 | * Realtime Database: `projects/_/instances/<databaseInstance>/refs/<databasePath>`
|
138 | *
|
139 | * Storage: `projects/_/buckets/<bucketName>/objects/<fileName>#<generation>`
|
140 | *
|
141 | * Authentication: `projects/<projectId>`
|
142 | *
|
143 | * Pub/Sub: `projects/<projectId>/topics/<topicName>`
|
144 | *
|
145 | * Because Realtime Database instances and Cloud Storage buckets are globally
|
146 | * unique and not tied to the project, their resources start with `projects/_`.
|
147 | * Underscore is not a valid project name.
|
148 | */
|
149 | resource: Resource;
|
150 | /**
|
151 | * Timestamp for the event as an {@link https://www.ietf.org/rfc/rfc3339.txt | RFC 3339} string.
|
152 | */
|
153 | timestamp: string;
|
154 | }
|
155 | /**
|
156 | * Resource is a standard format for defining a resource
|
157 | * (google.rpc.context.AttributeContext.Resource). In Cloud Functions, it is the
|
158 | * resource that triggered the function - such as a storage bucket.
|
159 | */
|
160 | export interface Resource {
|
161 | /** The name of the service that this resource belongs to. */
|
162 | service: string;
|
163 | /**
|
164 | * The stable identifier (name) of a resource on the service.
|
165 | * A resource can be logically identified as "//{resource.service}/{resource.name}"
|
166 | */
|
167 | name: string;
|
168 | /**
|
169 | * The type of the resource. The syntax is platform-specific because different platforms define their resources differently.
|
170 | * For Google APIs, the type format must be "{service}/{kind}"
|
171 | */
|
172 | type?: string;
|
173 | /** Map of Resource's labels. */
|
174 | labels?: {
|
175 | [tag: string]: string;
|
176 | };
|
177 | }
|
178 | /**
|
179 | * TriggerAnnotion is used internally by the firebase CLI to understand what
|
180 | * type of Cloud Function to deploy.
|
181 | */
|
182 | interface TriggerAnnotation {
|
183 | availableMemoryMb?: number;
|
184 | blockingTrigger?: {
|
185 | eventType: string;
|
186 | options?: Record<string, unknown>;
|
187 | };
|
188 | eventTrigger?: {
|
189 | eventType: string;
|
190 | resource: string;
|
191 | service: string;
|
192 | };
|
193 | failurePolicy?: FailurePolicy;
|
194 | httpsTrigger?: {
|
195 | invoker?: string[];
|
196 | };
|
197 | labels?: {
|
198 | [key: string]: string;
|
199 | };
|
200 | regions?: string[];
|
201 | schedule?: Schedule;
|
202 | timeout?: string;
|
203 | vpcConnector?: string;
|
204 | vpcConnectorEgressSettings?: string;
|
205 | serviceAccountEmail?: string;
|
206 | ingressSettings?: string;
|
207 | secrets?: string[];
|
208 | }
|
209 | /**
|
210 | * A Runnable has a `run` method which directly invokes the user-defined
|
211 | * function - useful for unit testing.
|
212 | */
|
213 | export interface Runnable<T> {
|
214 | /** Directly invoke the user defined function. */
|
215 | run: (data: T, context: any) => PromiseLike<any> | any;
|
216 | }
|
217 | /**
|
218 | * The function type for HTTPS triggers. This should be exported from your
|
219 | * JavaScript file to define a Cloud Function.
|
220 | *
|
221 | * @remarks
|
222 | * This type is a special JavaScript function which takes Express
|
223 | * {@link https://expressjs.com/en/api.html#req | `Request` } and
|
224 | * {@link https://expressjs.com/en/api.html#res | `Response` } objects as its only
|
225 | * arguments.
|
226 | */
|
227 | export interface HttpsFunction {
|
228 | (req: Request, resp: Response): void | Promise<void>;
|
229 | /** @alpha */
|
230 | __trigger: TriggerAnnotation;
|
231 | /** @alpha */
|
232 | __endpoint: ManifestEndpoint;
|
233 | /** @alpha */
|
234 | __requiredAPIs?: ManifestRequiredAPI[];
|
235 | }
|
236 | /**
|
237 | * The function type for Auth Blocking triggers.
|
238 | *
|
239 | * @remarks
|
240 | * This type is a special JavaScript function for Auth Blocking triggers which takes Express
|
241 | * {@link https://expressjs.com/en/api.html#req | `Request` } and
|
242 | * {@link https://expressjs.com/en/api.html#res | `Response` } objects as its only
|
243 | * arguments.
|
244 | */
|
245 | export interface BlockingFunction {
|
246 | /** @public */
|
247 | (req: Request, resp: Response): void | Promise<void>;
|
248 | /** @alpha */
|
249 | __trigger: TriggerAnnotation;
|
250 | /** @alpha */
|
251 | __endpoint: ManifestEndpoint;
|
252 | /** @alpha */
|
253 | __requiredAPIs?: ManifestRequiredAPI[];
|
254 | }
|
255 | /**
|
256 | * The function type for all non-HTTPS triggers. This should be exported
|
257 | * from your JavaScript file to define a Cloud Function.
|
258 | *
|
259 | * This type is a special JavaScript function which takes a templated
|
260 | * `Event` object as its only argument.
|
261 | */
|
262 | export interface CloudFunction<T> extends Runnable<T> {
|
263 | (input: any, context?: any): PromiseLike<any> | any;
|
264 | /** @alpha */
|
265 | __trigger: TriggerAnnotation;
|
266 | /** @alpha */
|
267 | __endpoint: ManifestEndpoint;
|
268 | /** @alpha */
|
269 | __requiredAPIs?: ManifestRequiredAPI[];
|
270 | }
|
271 | /** @hidden */
|
272 | export declare function optionsToTrigger(options: DeploymentOptions): any;
|
273 | export declare function optionsToEndpoint(options: DeploymentOptions): ManifestEndpoint;
|