Skip to content

Commit b160721

Browse files
authored
A few areas of polish: (#124)
1. Swap tsconfig strategy so the test config is primary 2. Bump dependency on firebase-admin 3. Fix linter issue in cloud-functions.ts 4. Fix ordering of code in analytics.ts to be consistent with other providers. 5. Add .tgz to npmignore so we won't inception a releases 6. Update description and keyword for package 1. Swap tsconfig strategy so the test config is primary 2. Bump dependency on firebase-admin 3. Fix linter issue in cloud-functions.ts 4. Fix ordering of code in analytics.ts to be consistent with other providers. 5. Add .tgz to npmignore so we won't inception a releases 6. Update description and keyword for package
1 parent ad2c924 commit b160721

File tree

6 files changed

+124
-121
lines changed

6 files changed

+124
-121
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ spec
1212
# TODO(rjh) add back once testing isn't just a joke
1313
testing
1414
lib/testing.*
15+
*.tgz

package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
{
22
"name": "firebase-functions",
33
"version": "0.5.1-rc1",
4-
"description": "Node helpers for Firebase Functions.",
4+
"description": "Firebase SDK for Cloud Functions",
55
"main": "lib/index.js",
66
"scripts": {
7-
"build": "node_modules/.bin/tsc",
8-
"build:pack": "npm prune --production && rm -rf lib && npm install typescript && node_modules/.bin/tsc && npm pack && npm install",
7+
"build": "node_modules/.bin/tsc -p tsconfig.release.json",
8+
"build:pack": "npm prune --production && rm -rf lib && npm install typescript && node_modules/.bin/tsc -p tsconfig.release.json && npm pack && npm install",
99
"lint": "node_modules/.bin/tslint src/{**/*,*}.ts spec/{**/*,*}.ts",
10-
"pretest": "node_modules/.bin/tsc -p tsconfig.spec.json && cp -r spec/fixtures .tmp/spec",
11-
"test": "npm run lint && mocha .tmp/spec/index.spec.js",
12-
"posttest": "rm -rf .tmp"
10+
"pretest": "node_modules/.bin/tsc && cp -r spec/fixtures .tmp/spec",
11+
"test": "mocha .tmp/spec/index.spec.js",
12+
"posttest": "npm run lint && rm -rf .tmp"
1313
},
1414
"repository": {
1515
"type": "git",
1616
"url": "git+https://github.com/firebase/firebase-functions.git"
1717
},
1818
"keywords": [
1919
"firebase",
20-
"functions"
20+
"functions",
21+
"google",
22+
"cloud"
2123
],
2224
"author": "Firebase Team",
2325
"license": "MIT",
@@ -35,7 +37,7 @@
3537
"@types/sinon": "^1.16.29",
3638
"chai": "^3.5.0",
3739
"chai-as-promised": "^5.2.0",
38-
"firebase-admin": "^4.1.1",
40+
"firebase-admin": "^4.1.2",
3941
"istanbul": "^0.4.2",
4042
"mocha": "^2.4.5",
4143
"mock-require": "^2.0.1",
@@ -45,7 +47,7 @@
4547
"typescript": "^2.0.3"
4648
},
4749
"peerDependencies": {
48-
"firebase-admin": "^4.1.1"
50+
"firebase-admin": "^4.1.2"
4951
},
5052
"dependencies": {
5153
"@types/express": "^4.0.33",

src/cloud-functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ export function makeCloudFunction<EventData>({
9191
typedEvent.params = event.params || {};
9292
return handler(typedEvent);
9393
}).then(result => {
94-
if (after) { after(event); };
94+
if (after) { after(event); }
9595
return result;
9696
}, err => {
97-
if (after) { after(event); };
97+
if (after) { after(event); }
9898
return Promise.reject(err);
9999
});
100100
};

src/providers/analytics.ts

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import { makeCloudFunction, CloudFunction, Event } from '../cloud-functions';
2424
import * as _ from 'lodash';
2525

26+
/** @internal */
27+
export const provider = 'google.firebase.analytics';
28+
2629
/** Handle events sent to Firebase Analytics. */
2730
export function event(analyticsEventType: string) {
2831
return new AnalyticsEventBuilder(
@@ -50,8 +53,102 @@ export class AnalyticsEventBuilder {
5053
}
5154
}
5255

53-
/** @internal */
54-
export const provider = 'google.firebase.analytics';
56+
/** A collection of information about a Firebase Analytics event that was logged for a specific user. */
57+
export class AnalyticsEvent {
58+
/** The date on which the event.was logged.
59+
* (YYYYMMDD format in the registered timezone of your app.)
60+
*/
61+
reportingDate: string;
62+
63+
/** The name of the event. */
64+
name: string;
65+
66+
/** A repeated record of the parameters associated with the event.
67+
* Note: this value is cast to its most appropriate type, which due to the nature of JavaScript's number
68+
* handling might entail a loss of precision in case of very large integers.
69+
*/
70+
params: { [key: string]: any };
71+
72+
/** UTC client time when the event happened. */
73+
logTime: string;
74+
75+
/** UTC client time when the previous event happened. */
76+
previousLogTime?: string;
77+
78+
/** Value param in USD. */
79+
valueInUSD?: number;
80+
81+
/** User related dimensions. */
82+
user?: UserDimensions;
83+
84+
/** @internal */
85+
constructor(wireFormat: any) {
86+
this.params = {}; // In case of absent field, show empty (not absent) map.
87+
if (wireFormat.eventDim && wireFormat.eventDim.length > 0) {
88+
// If there's an eventDim, there'll always be exactly one.
89+
let eventDim = wireFormat.eventDim[0];
90+
copyField(eventDim, this, 'name');
91+
copyField(eventDim, this, 'params', p => _.mapValues(p, unwrapValue));
92+
copyFieldTo(eventDim, this, 'valueInUsd', 'valueInUSD');
93+
copyFieldTo(eventDim, this, 'date', 'reportingDate');
94+
copyTimestampToString(eventDim, this, 'timestampMicros', 'logTime');
95+
copyTimestampToString(eventDim, this, 'previousTimestampMicros', 'previousLogTime');
96+
}
97+
copyFieldTo(wireFormat, this, 'userDim', 'user', dim => new UserDimensions(dim));
98+
}
99+
}
100+
101+
/** A collection of information about the user who triggered these events. */
102+
export class UserDimensions {
103+
/* tslint:disable:max-line-length */
104+
/** The user ID set via the setUserId API.
105+
* https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.html#setUserId(java.lang.String)
106+
* https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#/c:objc(cs)FIRAnalytics(cm)setUserID
107+
*/
108+
userId?: string;
109+
/* tslint:enable:max-line-length */
110+
111+
/** The time (in UTC) at which the user first opened the app. */
112+
firstOpenTime?: string;
113+
114+
/** A repeated record of user properties set with the setUserProperty API.
115+
* https://firebase.google.com/docs/analytics/android/properties
116+
*/
117+
userProperties: { [key: string]: UserPropertyValue };
118+
119+
/** Device information. */
120+
deviceInfo: DeviceInfo;
121+
122+
/** User's geographic information. */
123+
geoInfo: GeoInfo;
124+
125+
/** App information. */
126+
appInfo?: AppInfo;
127+
128+
/** Information about the marketing campaign which acquired the user. */
129+
trafficSource?: TrafficSource;
130+
131+
/** Information regarding the bundle in which these events were uploaded. */
132+
bundleInfo: ExportBundleInfo;
133+
134+
/** Lifetime Value revenue of this user, in USD. */
135+
ltvInUSD?: number;
136+
137+
/** @internal */
138+
constructor(wireFormat: any) {
139+
// These are interfaces or primitives, no transformation needed.
140+
copyFields(wireFormat, this, ['userId', 'deviceInfo', 'geoInfo', 'appInfo', 'trafficSource']);
141+
142+
// The following fields do need transformations of some sort.
143+
copyTimestampToString(wireFormat, this, 'firstOpenTimestampMicros', 'firstOpenTime');
144+
this.userProperties = {}; // With no entries in the wire format, present an empty (as opposed to absent) map.
145+
copyField(wireFormat, this, 'userProperties', r => _.mapValues(r, p => new UserPropertyValue(p)));
146+
copyField(wireFormat, this, 'bundleInfo', r => new ExportBundleInfo(r));
147+
if (wireFormat.ltvInfo && wireFormat.ltvInfo.currency === 'USD') {
148+
this.ltvInUSD = wireFormat.ltvInfo.revenue;
149+
}
150+
}
151+
}
55152

56153
/** Predefined (eg: LTV) or custom properties (eg: birthday) stored on client side and associated with
57154
* subsequent HitBundles.
@@ -183,103 +280,6 @@ export class ExportBundleInfo {
183280
}
184281
}
185282

186-
/** A collection of information about the user who triggered these events. */
187-
export class UserDimensions {
188-
/* tslint:disable:max-line-length */
189-
/** The user ID set via the setUserId API.
190-
* https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.html#setUserId(java.lang.String)
191-
* https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#/c:objc(cs)FIRAnalytics(cm)setUserID
192-
*/
193-
userId?: string;
194-
/* tslint:enable:max-line-length */
195-
196-
/** The time (in UTC) at which the user first opened the app. */
197-
firstOpenTime?: string;
198-
199-
/** A repeated record of user properties set with the setUserProperty API.
200-
* https://firebase.google.com/docs/analytics/android/properties
201-
*/
202-
userProperties: { [key: string]: UserPropertyValue };
203-
204-
/** Device information. */
205-
deviceInfo: DeviceInfo;
206-
207-
/** User's geographic information. */
208-
geoInfo: GeoInfo;
209-
210-
/** App information. */
211-
appInfo?: AppInfo;
212-
213-
/** Information about the marketing campaign which acquired the user. */
214-
trafficSource?: TrafficSource;
215-
216-
/** Information regarding the bundle in which these events were uploaded. */
217-
bundleInfo: ExportBundleInfo;
218-
219-
/** Lifetime Value revenue of this user, in USD. */
220-
ltvInUSD?: number;
221-
222-
/** @internal */
223-
constructor(wireFormat: any) {
224-
// These are interfaces or primitives, no transformation needed.
225-
copyFields(wireFormat, this, ['userId', 'deviceInfo', 'geoInfo', 'appInfo', 'trafficSource']);
226-
227-
// The following fields do need transformations of some sort.
228-
copyTimestampToString(wireFormat, this, 'firstOpenTimestampMicros', 'firstOpenTime');
229-
this.userProperties = {}; // With no entries in the wire format, present an empty (as opposed to absent) map.
230-
copyField(wireFormat, this, 'userProperties', r => _.mapValues(r, p => new UserPropertyValue(p)));
231-
copyField(wireFormat, this, 'bundleInfo', r => new ExportBundleInfo(r));
232-
if (wireFormat.ltvInfo && wireFormat.ltvInfo.currency === 'USD') {
233-
this.ltvInUSD = wireFormat.ltvInfo.revenue;
234-
}
235-
}
236-
}
237-
238-
/** A collection of information about a Firebase Analytics event that was logged for a specific user. */
239-
export class AnalyticsEvent {
240-
/** The date on which the event.was logged.
241-
* (YYYYMMDD format in the registered timezone of your app.)
242-
*/
243-
reportingDate: string;
244-
245-
/** The name of the event. */
246-
name: string;
247-
248-
/** A repeated record of the parameters associated with the event.
249-
* Note: this value is cast to its most appropriate type, which due to the nature of JavaScript's number
250-
* handling might entail a loss of precision in case of very large integers.
251-
*/
252-
params: { [key: string]: any };
253-
254-
/** UTC client time when the event happened. */
255-
logTime: string;
256-
257-
/** UTC client time when the previous event happened. */
258-
previousLogTime?: string;
259-
260-
/** Value param in USD. */
261-
valueInUSD?: number;
262-
263-
/** User related dimensions. */
264-
user?: UserDimensions;
265-
266-
/** @internal */
267-
constructor(wireFormat: any) {
268-
this.params = {}; // In case of absent field, show empty (not absent) map.
269-
if (wireFormat.eventDim && wireFormat.eventDim.length > 0) {
270-
// If there's an eventDim, there'll always be exactly one.
271-
let eventDim = wireFormat.eventDim[0];
272-
copyField(eventDim, this, 'name');
273-
copyField(eventDim, this, 'params', p => _.mapValues(p, unwrapValue));
274-
copyFieldTo(eventDim, this, 'valueInUsd', 'valueInUSD');
275-
copyFieldTo(eventDim, this, 'date', 'reportingDate');
276-
copyTimestampToString(eventDim, this, 'timestampMicros', 'logTime');
277-
copyTimestampToString(eventDim, this, 'previousTimestampMicros', 'previousLogTime');
278-
}
279-
copyFieldTo(wireFormat, this, 'userDim', 'user', dim => new UserDimensions(dim));
280-
}
281-
}
282-
283283
function copyFieldTo<T, K extends keyof T>(
284284
from: any, to: T, fromField: string, toField: K, transform = _.identity): void {
285285
if (from[fromField] !== undefined) {

tsconfig.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{
22
"compilerOptions": {
3-
"declaration": true,
43
"lib": ["es6", "es2015.promise"],
54
"module": "commonjs",
65
"noImplicitAny": false,
7-
"outDir": "lib",
8-
"stripInternal": true,
6+
"outDir": ".tmp",
7+
"sourceMap": true,
98
"target": "es5",
109
"typeRoots": [
1110
"node_modules/@types"
1211
]
1312
},
14-
"files": [
15-
"src/index.ts",
16-
"src/testing.ts"
13+
"include": [
14+
"src/**/*.ts",
15+
"spec/**/*.ts"
1716
]
1817
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"compilerOptions": {
3+
"declaration": true,
34
"lib": ["es6", "es2015.promise"],
45
"module": "commonjs",
56
"noImplicitAny": false,
6-
"outDir": ".tmp",
7-
"sourceMap": true,
7+
"outDir": "lib",
8+
"stripInternal": true,
89
"target": "es5",
910
"typeRoots": [
1011
"node_modules/@types"
1112
]
1213
},
13-
"include": [
14-
"src/**/*.ts",
15-
"spec/**/*.ts"
14+
"files": [
15+
"src/index.ts",
16+
"src/testing.ts"
1617
]
1718
}

0 commit comments

Comments
 (0)