UNPKG

8.68 kBTypeScriptView Raw
1/**
2 * Cloud functions to handle Firebase App Distribution 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/**
12 * The internal payload object for adding a new tester device to app distribution.
13 * Payload is wrapped inside a `FirebaseAlertData` object.
14 */
15export interface NewTesterDevicePayload {
16 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.AppDistroNewTesterIosDevicePayload";
17 /** Name of the tester */
18 testerName: string;
19 /** Email of the tester */
20 testerEmail: string;
21 /** The device model name */
22 testerDeviceModelName: string;
23 /** The device ID */
24 testerDeviceIdentifier: string;
25}
26/**
27 * The internal payload object for receiving in-app feedback from a tester.
28 * Payload is wrapped inside a `FirebaseAlertData` object.
29 */
30export interface InAppFeedbackPayload {
31 ["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.AppDistroInAppFeedbackPayload";
32 /** Resource name. Format: `projects/{project_number}/apps/{app_id}/releases/{release_id}/feedbackReports/{feedback_id}` */
33 feedbackReport: string;
34 /** Deep link back to the Firebase console. */
35 feedbackConsoleUri: string;
36 /** Name of the tester */
37 testerName?: string;
38 /** Email of the tester */
39 testerEmail: string;
40 /**
41 * Version consisting of `versionName` and `versionCode` for Android and
42 * `CFBundleShortVersionString` and `CFBundleVersion` for iOS.
43 */
44 appVersion: string;
45 /** Text entered by the tester */
46 text: string;
47 /** URI to download screenshot. This URI is fast expiring. */
48 screenshotUri?: string;
49}
50/**
51 * A custom CloudEvent for Firebase Alerts (with custom extension attributes).
52 * @typeParam T - the data type for app distribution alerts that is wrapped in a `FirebaseAlertData` object.
53 */
54export interface AppDistributionEvent<T> extends CloudEvent<FirebaseAlertData<T>> {
55 /** The type of the alerts that got triggered. */
56 alertType: string;
57 /** The Firebase App ID that’s associated with the alert. */
58 appId: string;
59}
60/**
61 * Configuration for app distribution functions.
62 */
63export interface AppDistributionOptions extends options.EventHandlerOptions {
64 /** Scope the function to trigger on a specific application. */
65 appId?: string;
66 /**
67 * If true, do not deploy or emulate this function.
68 */
69 omit?: boolean | Expression<boolean>;
70 /**
71 * Region where functions should be deployed.
72 */
73 region?: options.SupportedRegion | string | Expression<string> | ResetValue;
74 /**
75 * Amount of memory to allocate to a function.
76 */
77 memory?: options.MemoryOption | Expression<number> | ResetValue;
78 /**
79 * Timeout for the function in seconds, possible values are 0 to 540.
80 * HTTPS functions can specify a higher timeout.
81 *
82 * @remarks
83 * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
84 * function depends on the type of function: Event handling functions have a
85 * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
86 * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
87 * timeout of 1,800s (30 minutes)
88 */
89 timeoutSeconds?: number | Expression<number> | ResetValue;
90 /**
91 * Min number of actual instances to be running at a given time.
92 *
93 * @remarks
94 * Instances will be billed for memory allocation and 10% of CPU allocation
95 * while idle.
96 */
97 minInstances?: number | Expression<number> | ResetValue;
98 /**
99 * Max number of instances to be running in parallel.
100 */
101 maxInstances?: number | Expression<number> | ResetValue;
102 /**
103 * Number of requests a function can serve at once.
104 *
105 * @remarks
106 * Can only be applied to functions running on Cloud Functions v2.
107 * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
108 * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
109 * The maximum value for concurrency is 1,000.
110 */
111 concurrency?: number | Expression<number> | ResetValue;
112 /**
113 * Fractional number of CPUs to allocate to a function.
114 *
115 * @remarks
116 * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
117 * This is different from the defaults when using the gcloud utility and is different from
118 * the fixed amount assigned in Google Cloud Functions generation 1.
119 * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
120 * to the value "gcf_gen1"
121 */
122 cpu?: number | "gcf_gen1";
123 /**
124 * Connect cloud function to specified VPC connector.
125 */
126 vpcConnector?: string | Expression<string> | ResetValue;
127 /**
128 * Egress settings for VPC connector.
129 */
130 vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
131 /**
132 * Specific service account for the function to run as.
133 */
134 serviceAccount?: string | Expression<string> | ResetValue;
135 /**
136 * Ingress settings which control where this function can be called from.
137 */
138 ingressSettings?: options.IngressSetting | ResetValue;
139 /**
140 * User labels to set on the function.
141 */
142 labels?: Record<string, string>;
143 secrets?: (string | SecretParam)[];
144 /** Whether failed executions should be delivered again. */
145 retry?: boolean | Expression<boolean> | ResetValue;
146}
147/**
148 * Declares a function that can handle adding a new tester iOS device.
149 * @param handler - Event handler which is run every time a new tester iOS device is added.
150 * @returns A function that you can export and deploy.
151 */
152export declare function onNewTesterIosDevicePublished(handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<NewTesterDevicePayload>>;
153/**
154 * Declares a function that can handle adding a new tester iOS device.
155 * @param appId - A specific application the handler will trigger on.
156 * @param handler - Event handler which is run every time a new tester iOS device is added.
157 * @returns A function that you can export and deploy.
158 */
159export declare function onNewTesterIosDevicePublished(appId: string, handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<NewTesterDevicePayload>>;
160/**
161 * Declares a function that can handle adding a new tester iOS device.
162 * @param opts - Options that can be set on the function.
163 * @param handler - Event handler which is run every time a new tester iOS device is added.
164 * @returns A function that you can export and deploy.
165 */
166export declare function onNewTesterIosDevicePublished(opts: AppDistributionOptions, handler: (event: AppDistributionEvent<NewTesterDevicePayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<NewTesterDevicePayload>>;
167/**
168 * Declares a function that can handle receiving new in-app feedback from a tester.
169 * @param handler - Event handler which is run every time new feedback is received.
170 * @returns A function that you can export and deploy.
171 */
172export declare function onInAppFeedbackPublished(handler: (event: AppDistributionEvent<InAppFeedbackPayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
173/**
174 * Declares a function that can handle receiving new in-app feedback from a tester.
175 * @param appId - A specific application the handler will trigger on.
176 * @param handler - Event handler which is run every time new feedback is received.
177 * @returns A function that you can export and deploy.
178 */
179export declare function onInAppFeedbackPublished(appId: string, handler: (event: AppDistributionEvent<InAppFeedbackPayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
180/**
181 * Declares a function that can handle receiving new in-app feedback from a tester.
182 * @param opts - Options that can be set on the function.
183 * @param handler - Event handler which is run every time new feedback is received.
184 * @returns A function that you can export and deploy.
185 */
186export declare function onInAppFeedbackPublished(opts: AppDistributionOptions, handler: (event: AppDistributionEvent<InAppFeedbackPayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;