Skip to content

Commit d277573

Browse files
committed
Add InAppFeedbackPayload and onNewInAppFeedbackPublished().
1 parent 2990313 commit d277573

File tree

3 files changed

+191
-0
lines changed

3 files changed

+191
-0
lines changed

spec/v2/providers/alerts/appDistribution.spec.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,92 @@ describe('appDistribution', () => {
9797
});
9898
});
9999

100+
describe('onInAppfeedbackPublished', () => {
101+
it('should create a function with alertType & appId', () => {
102+
const func = appDistribution.onInAppFeedbackPublished(
103+
APPID,
104+
myHandler
105+
);
106+
107+
expect(func.__endpoint).to.deep.equal({
108+
platform: 'gcfv2',
109+
labels: {},
110+
eventTrigger: {
111+
eventType: alerts.eventType,
112+
eventFilters: {
113+
...APP_EVENT_FILTER,
114+
alerttype: appDistribution.inAppFeedbackAlert,
115+
},
116+
retry: false,
117+
},
118+
});
119+
});
120+
121+
it('should create a function with opts', () => {
122+
const func = appDistribution.onInAppFeedbackPublished(
123+
{ ...FULL_OPTIONS },
124+
myHandler
125+
);
126+
127+
expect(func.__endpoint).to.deep.equal({
128+
...FULL_ENDPOINT,
129+
eventTrigger: {
130+
eventType: alerts.eventType,
131+
eventFilters: {
132+
alerttype: appDistribution.inAppFeedbackAlert,
133+
},
134+
retry: false,
135+
},
136+
});
137+
});
138+
139+
it('should create a function with appid in opts', () => {
140+
const func = appDistribution.onInAppFeedbackPublished(
141+
{ ...FULL_OPTIONS, appId: APPID },
142+
myHandler
143+
);
144+
145+
expect(func.__endpoint).to.deep.equal({
146+
...FULL_ENDPOINT,
147+
eventTrigger: {
148+
eventType: alerts.eventType,
149+
eventFilters: {
150+
...APP_EVENT_FILTER,
151+
alerttype: appDistribution.inAppFeedbackAlert,
152+
},
153+
retry: false,
154+
},
155+
});
156+
});
157+
158+
it('should create a function without opts or appId', () => {
159+
const func = appDistribution.onInAppFeedbackPublished(myHandler);
160+
161+
expect(func.__endpoint).to.deep.equal({
162+
platform: 'gcfv2',
163+
labels: {},
164+
eventTrigger: {
165+
eventType: alerts.eventType,
166+
eventFilters: {
167+
alerttype: appDistribution.inAppFeedbackAlert,
168+
},
169+
retry: false,
170+
},
171+
});
172+
});
173+
174+
it('should create a function with a run method', () => {
175+
const func = appDistribution.onInAppFeedbackPublished(
176+
APPID,
177+
(event) => event
178+
);
179+
180+
const res = func.run('input' as any);
181+
182+
expect(res).to.equal('input');
183+
});
184+
});
185+
100186
describe('getOptsAndApp', () => {
101187
it('should parse a string', () => {
102188
const [opts, appId] = appDistribution.getOptsAndApp(APPID);

src/v2/providers/alerts/alerts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type AlertType =
6868
| 'billing.planUpdate'
6969
| 'billing.automatedPlanUpdate'
7070
| 'appDistribution.newTesterIosDevice'
71+
| 'appDistribution.inAppFeedback'
7172
| string;
7273

7374
/**

src/v2/providers/alerts/appDistribution.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ export interface NewTesterDevicePayload {
4545
testerDeviceIdentifier: string;
4646
}
4747

48+
/**
49+
* The internal payload object for receiving in-app feedback from a tester.
50+
* Payload is wrapped inside a `FirebaseAlertData` object.
51+
*/
52+
export interface InAppFeedbackPayload {
53+
['@type']: 'type.googleapis.com/google.events.firebase.firebasealerts.v1.AppDistroInAppFeedbackPayload';
54+
/** Resource name. Format: `projects/{project_number}/apps/{app_id}/releases/{release_id}/feedbackReports/{feedback_id}` */
55+
feedbackReport: string;
56+
/** Name of the tester */
57+
testerName?: string;
58+
/** Email of the tester */
59+
testerEmail: string;
60+
/**
61+
* Display version of the release. For an Android release, the display version
62+
* is the `versionName`. For an iOS release, the display version is the
63+
* `CFBundleShortVersionString`.
64+
*/
65+
displayVersion: string;
66+
/**
67+
* Build version of the release. For an Android release, the build version
68+
* is the `versionCode`. For an iOS release, the build version is the
69+
* `CFBundleVersion`.
70+
*/
71+
buildVersion: string;
72+
/** Text entered by the tester */
73+
text: string;
74+
/** URIs to download screenshot(s) */
75+
screenshotUris?: string[];
76+
}
77+
4878
/**
4979
* A custom CloudEvent for Firebase Alerts (with custom extension attributes).
5080
* @typeParam T - the data type for app distribution alerts that is wrapped in a `FirebaseAlertData` object.
@@ -59,6 +89,7 @@ export interface AppDistributionEvent<T>
5989

6090
/** @internal */
6191
export const newTesterIosDeviceAlert = 'appDistribution.newTesterIosDevice';
92+
export const inAppFeedbackAlert = 'appDistribution.inAppFeedback';
6293

6394
/**
6495
* Configuration for app distribution functions.
@@ -234,6 +265,79 @@ export function onNewTesterIosDevicePublished(
234265
return func;
235266
}
236267

268+
/**
269+
* Declares a function that can handle receiving new in-app feedback from a tester.
270+
* @param handler - Event handler which is run every time new feedback is received.
271+
* @returns A function that you can export and deploy.
272+
*/
273+
export function onInAppFeedbackPublished(
274+
handler: (
275+
event: AppDistributionEvent<InAppFeedbackPayload>
276+
) => any | Promise<any>
277+
): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
278+
279+
/**
280+
* Declares a function that can handle receiving new in-app feedback from a tester.
281+
* @param appId - A specific application the handler will trigger on.
282+
* @param handler - Event handler which is run every time new feedback is received.
283+
* @returns A function that you can export and deploy.
284+
*/
285+
export function onInAppFeedbackPublished(
286+
appId: string,
287+
handler: (
288+
event: AppDistributionEvent<InAppFeedbackPayload>
289+
) => any | Promise<any>
290+
): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
291+
292+
/**
293+
* Declares a function that can handle receiving new in-app feedback from a tester.
294+
* @param opts - Options that can be set on the function.
295+
* @param handler - Event handler which is run every time new feedback is received.
296+
* @returns A function that you can export and deploy.
297+
*/
298+
export function onInAppFeedbackPublished(
299+
opts: AppDistributionOptions,
300+
handler: (
301+
event: AppDistributionEvent<InAppFeedbackPayload>
302+
) => any | Promise<any>
303+
): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
304+
305+
/**
306+
* Declares a function that can handle receiving new in-app feedback from a tester.
307+
* @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
308+
* @param handler - Event handler which is run every time new feedback is received.
309+
* @returns A function that you can export and deploy.
310+
*/
311+
export function onInAppFeedbackPublished(
312+
appIdOrOptsOrHandler:
313+
| string
314+
| AppDistributionOptions
315+
| ((
316+
event: AppDistributionEvent<InAppFeedbackPayload>
317+
) => any | Promise<any>),
318+
handler?: (
319+
event: AppDistributionEvent<InAppFeedbackPayload>
320+
) => any | Promise<any>
321+
): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>> {
322+
if (typeof appIdOrOptsOrHandler === 'function') {
323+
handler = appIdOrOptsOrHandler as (
324+
event: AppDistributionEvent<InAppFeedbackPayload>
325+
) => any | Promise<any>;
326+
appIdOrOptsOrHandler = {};
327+
}
328+
329+
const [opts, appId] = getOptsAndApp(appIdOrOptsOrHandler);
330+
331+
const func = (raw: CloudEvent<unknown>) => {
332+
return handler(raw as AppDistributionEvent<InAppFeedbackPayload>);
333+
};
334+
335+
func.run = handler;
336+
func.__endpoint = getEndpointAnnotation(opts, inAppFeedbackAlert, appId);
337+
338+
return func;
339+
}
340+
237341
/**
238342
* Helper function to parse the function opts and appId.
239343
* @internal

0 commit comments

Comments
 (0)