Skip to content

Commit

Permalink
A few areas of polish: (#124)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
inlined authored Mar 4, 2017
1 parent ad2c924 commit b160721
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 121 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ spec
# TODO(rjh) add back once testing isn't just a joke
testing
lib/testing.*
*.tgz
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "firebase-functions",
"version": "0.5.1-rc1",
"description": "Node helpers for Firebase Functions.",
"description": "Firebase SDK for Cloud Functions",
"main": "lib/index.js",
"scripts": {
"build": "node_modules/.bin/tsc",
"build:pack": "npm prune --production && rm -rf lib && npm install typescript && node_modules/.bin/tsc && npm pack && npm install",
"build": "node_modules/.bin/tsc -p tsconfig.release.json",
"build:pack": "npm prune --production && rm -rf lib && npm install typescript && node_modules/.bin/tsc -p tsconfig.release.json && npm pack && npm install",
"lint": "node_modules/.bin/tslint src/{**/*,*}.ts spec/{**/*,*}.ts",
"pretest": "node_modules/.bin/tsc -p tsconfig.spec.json && cp -r spec/fixtures .tmp/spec",
"test": "npm run lint && mocha .tmp/spec/index.spec.js",
"posttest": "rm -rf .tmp"
"pretest": "node_modules/.bin/tsc && cp -r spec/fixtures .tmp/spec",
"test": "mocha .tmp/spec/index.spec.js",
"posttest": "npm run lint && rm -rf .tmp"
},
"repository": {
"type": "git",
"url": "git+https://github.com/firebase/firebase-functions.git"
},
"keywords": [
"firebase",
"functions"
"functions",
"google",
"cloud"
],
"author": "Firebase Team",
"license": "MIT",
Expand All @@ -35,7 +37,7 @@
"@types/sinon": "^1.16.29",
"chai": "^3.5.0",
"chai-as-promised": "^5.2.0",
"firebase-admin": "^4.1.1",
"firebase-admin": "^4.1.2",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"mock-require": "^2.0.1",
Expand All @@ -45,7 +47,7 @@
"typescript": "^2.0.3"
},
"peerDependencies": {
"firebase-admin": "^4.1.1"
"firebase-admin": "^4.1.2"
},
"dependencies": {
"@types/express": "^4.0.33",
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ export function makeCloudFunction<EventData>({
typedEvent.params = event.params || {};
return handler(typedEvent);
}).then(result => {
if (after) { after(event); };
if (after) { after(event); }
return result;
}, err => {
if (after) { after(event); };
if (after) { after(event); }
return Promise.reject(err);
});
};
Expand Down
198 changes: 99 additions & 99 deletions src/providers/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import { makeCloudFunction, CloudFunction, Event } from '../cloud-functions';
import * as _ from 'lodash';

/** @internal */
export const provider = 'google.firebase.analytics';

/** Handle events sent to Firebase Analytics. */
export function event(analyticsEventType: string) {
return new AnalyticsEventBuilder(
Expand Down Expand Up @@ -50,8 +53,102 @@ export class AnalyticsEventBuilder {
}
}

/** @internal */
export const provider = 'google.firebase.analytics';
/** A collection of information about a Firebase Analytics event that was logged for a specific user. */
export class AnalyticsEvent {
/** The date on which the event.was logged.
* (YYYYMMDD format in the registered timezone of your app.)
*/
reportingDate: string;

/** The name of the event. */
name: string;

/** A repeated record of the parameters associated with the event.
* Note: this value is cast to its most appropriate type, which due to the nature of JavaScript's number
* handling might entail a loss of precision in case of very large integers.
*/
params: { [key: string]: any };

/** UTC client time when the event happened. */
logTime: string;

/** UTC client time when the previous event happened. */
previousLogTime?: string;

/** Value param in USD. */
valueInUSD?: number;

/** User related dimensions. */
user?: UserDimensions;

/** @internal */
constructor(wireFormat: any) {
this.params = {}; // In case of absent field, show empty (not absent) map.
if (wireFormat.eventDim && wireFormat.eventDim.length > 0) {
// If there's an eventDim, there'll always be exactly one.
let eventDim = wireFormat.eventDim[0];
copyField(eventDim, this, 'name');
copyField(eventDim, this, 'params', p => _.mapValues(p, unwrapValue));
copyFieldTo(eventDim, this, 'valueInUsd', 'valueInUSD');
copyFieldTo(eventDim, this, 'date', 'reportingDate');
copyTimestampToString(eventDim, this, 'timestampMicros', 'logTime');
copyTimestampToString(eventDim, this, 'previousTimestampMicros', 'previousLogTime');
}
copyFieldTo(wireFormat, this, 'userDim', 'user', dim => new UserDimensions(dim));
}
}

/** A collection of information about the user who triggered these events. */
export class UserDimensions {
/* tslint:disable:max-line-length */
/** The user ID set via the setUserId API.
* https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.html#setUserId(java.lang.String)
* https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#/c:objc(cs)FIRAnalytics(cm)setUserID
*/
userId?: string;
/* tslint:enable:max-line-length */

/** The time (in UTC) at which the user first opened the app. */
firstOpenTime?: string;

/** A repeated record of user properties set with the setUserProperty API.
* https://firebase.google.com/docs/analytics/android/properties
*/
userProperties: { [key: string]: UserPropertyValue };

/** Device information. */
deviceInfo: DeviceInfo;

/** User's geographic information. */
geoInfo: GeoInfo;

/** App information. */
appInfo?: AppInfo;

/** Information about the marketing campaign which acquired the user. */
trafficSource?: TrafficSource;

/** Information regarding the bundle in which these events were uploaded. */
bundleInfo: ExportBundleInfo;

/** Lifetime Value revenue of this user, in USD. */
ltvInUSD?: number;

/** @internal */
constructor(wireFormat: any) {
// These are interfaces or primitives, no transformation needed.
copyFields(wireFormat, this, ['userId', 'deviceInfo', 'geoInfo', 'appInfo', 'trafficSource']);

// The following fields do need transformations of some sort.
copyTimestampToString(wireFormat, this, 'firstOpenTimestampMicros', 'firstOpenTime');
this.userProperties = {}; // With no entries in the wire format, present an empty (as opposed to absent) map.
copyField(wireFormat, this, 'userProperties', r => _.mapValues(r, p => new UserPropertyValue(p)));
copyField(wireFormat, this, 'bundleInfo', r => new ExportBundleInfo(r));
if (wireFormat.ltvInfo && wireFormat.ltvInfo.currency === 'USD') {
this.ltvInUSD = wireFormat.ltvInfo.revenue;
}
}
}

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

/** A collection of information about the user who triggered these events. */
export class UserDimensions {
/* tslint:disable:max-line-length */
/** The user ID set via the setUserId API.
* https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.html#setUserId(java.lang.String)
* https://firebase.google.com/docs/reference/ios/firebaseanalytics/api/reference/Classes/FIRAnalytics#/c:objc(cs)FIRAnalytics(cm)setUserID
*/
userId?: string;
/* tslint:enable:max-line-length */

/** The time (in UTC) at which the user first opened the app. */
firstOpenTime?: string;

/** A repeated record of user properties set with the setUserProperty API.
* https://firebase.google.com/docs/analytics/android/properties
*/
userProperties: { [key: string]: UserPropertyValue };

/** Device information. */
deviceInfo: DeviceInfo;

/** User's geographic information. */
geoInfo: GeoInfo;

/** App information. */
appInfo?: AppInfo;

/** Information about the marketing campaign which acquired the user. */
trafficSource?: TrafficSource;

/** Information regarding the bundle in which these events were uploaded. */
bundleInfo: ExportBundleInfo;

/** Lifetime Value revenue of this user, in USD. */
ltvInUSD?: number;

/** @internal */
constructor(wireFormat: any) {
// These are interfaces or primitives, no transformation needed.
copyFields(wireFormat, this, ['userId', 'deviceInfo', 'geoInfo', 'appInfo', 'trafficSource']);

// The following fields do need transformations of some sort.
copyTimestampToString(wireFormat, this, 'firstOpenTimestampMicros', 'firstOpenTime');
this.userProperties = {}; // With no entries in the wire format, present an empty (as opposed to absent) map.
copyField(wireFormat, this, 'userProperties', r => _.mapValues(r, p => new UserPropertyValue(p)));
copyField(wireFormat, this, 'bundleInfo', r => new ExportBundleInfo(r));
if (wireFormat.ltvInfo && wireFormat.ltvInfo.currency === 'USD') {
this.ltvInUSD = wireFormat.ltvInfo.revenue;
}
}
}

/** A collection of information about a Firebase Analytics event that was logged for a specific user. */
export class AnalyticsEvent {
/** The date on which the event.was logged.
* (YYYYMMDD format in the registered timezone of your app.)
*/
reportingDate: string;

/** The name of the event. */
name: string;

/** A repeated record of the parameters associated with the event.
* Note: this value is cast to its most appropriate type, which due to the nature of JavaScript's number
* handling might entail a loss of precision in case of very large integers.
*/
params: { [key: string]: any };

/** UTC client time when the event happened. */
logTime: string;

/** UTC client time when the previous event happened. */
previousLogTime?: string;

/** Value param in USD. */
valueInUSD?: number;

/** User related dimensions. */
user?: UserDimensions;

/** @internal */
constructor(wireFormat: any) {
this.params = {}; // In case of absent field, show empty (not absent) map.
if (wireFormat.eventDim && wireFormat.eventDim.length > 0) {
// If there's an eventDim, there'll always be exactly one.
let eventDim = wireFormat.eventDim[0];
copyField(eventDim, this, 'name');
copyField(eventDim, this, 'params', p => _.mapValues(p, unwrapValue));
copyFieldTo(eventDim, this, 'valueInUsd', 'valueInUSD');
copyFieldTo(eventDim, this, 'date', 'reportingDate');
copyTimestampToString(eventDim, this, 'timestampMicros', 'logTime');
copyTimestampToString(eventDim, this, 'previousTimestampMicros', 'previousLogTime');
}
copyFieldTo(wireFormat, this, 'userDim', 'user', dim => new UserDimensions(dim));
}
}

function copyFieldTo<T, K extends keyof T>(
from: any, to: T, fromField: string, toField: K, transform = _.identity): void {
if (from[fromField] !== undefined) {
Expand Down
11 changes: 5 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"compilerOptions": {
"declaration": true,
"lib": ["es6", "es2015.promise"],
"module": "commonjs",
"noImplicitAny": false,
"outDir": "lib",
"stripInternal": true,
"outDir": ".tmp",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
]
},
"files": [
"src/index.ts",
"src/testing.ts"
"include": [
"src/**/*.ts",
"spec/**/*.ts"
]
}
11 changes: 6 additions & 5 deletions tsconfig.spec.json → tsconfig.release.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"compilerOptions": {
"declaration": true,
"lib": ["es6", "es2015.promise"],
"module": "commonjs",
"noImplicitAny": false,
"outDir": ".tmp",
"sourceMap": true,
"outDir": "lib",
"stripInternal": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
]
},
"include": [
"src/**/*.ts",
"spec/**/*.ts"
"files": [
"src/index.ts",
"src/testing.ts"
]
}

0 comments on commit b160721

Please sign in to comment.