Skip to content

Commit 2f678fb

Browse files
author
Nicolas Garnier
committed
Changing all existing samples for v1.0.0 launch
Change-Id: I96ead147c6469cd6b48211e5590d0af576d2c520
1 parent 200716b commit 2f678fb

File tree

95 files changed

+642
-703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+642
-703
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
lerna-debug.log
66
*~
77
service-account-credentials.json
8+
**/package-lock.json

Diff for: assistant-say-number/functions/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Firebase Functions",
44
"dependencies": {
55
"actions-on-google": "^1.0.7",
6-
"firebase-admin": "^4.0.5",
7-
"firebase-functions": "^0.5.1"
6+
"firebase-admin": "~5.9.0",
7+
"firebase-functions": "^1.0.0"
88
},
99
"devDependencies": {
1010
"eslint": "^4.13.1",
@@ -17,5 +17,6 @@
1717
"start": "npm run shell",
1818
"deploy": "firebase deploy --only functions",
1919
"logs": "firebase functions:log"
20-
}
20+
},
21+
"private": true
2122
}

Diff for: authenticated-json-api/functions/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818

1919
const functions = require('firebase-functions');
2020
const admin = require('firebase-admin');
21-
const Language = require('@google-cloud/language');
21+
admin.initializeApp();
22+
const language = require('@google-cloud/language');
23+
const client = new language.LanguageServiceClient();
2224
const express = require('express');
23-
2425
const app = express();
25-
const language = new Language({projectId: process.env.GCLOUD_PROJECT});
2626

27-
admin.initializeApp(functions.config().firebase);
2827

2928
// Express middleware that validates Firebase ID Tokens passed in the Authorization HTTP header.
3029
// The Firebase ID token needs to be passed as a Bearer token in the Authorization HTTP header like this:
@@ -52,8 +51,8 @@ app.use(authenticate);
5251
app.post('/messages', (req, res) => {
5352
const message = req.body.message;
5453

55-
language.detectSentiment(message).then((results) => {
56-
const category = categorizeScore(results[0].score);
54+
client.analyzeSentiment({document: message}).then((results) => {
55+
const category = categorizeScore(results[0].documentSentiment.score);
5756
const data = {message: message, sentiment: results, category: category};
5857
return admin.database().ref(`/users/${req.user.uid}/messages`).push(data);
5958
}).then((snapshot) => {

Diff for: authenticated-json-api/functions/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "functions",
33
"description": "Cloud Functions for Firebase",
44
"dependencies": {
5-
"@google-cloud/language": "^0.10.3",
5+
"@google-cloud/language": "^1.1.0",
66
"express": "^4.15.2",
7-
"firebase-admin": "~4.1.2",
8-
"firebase-functions": "^0.5"
7+
"firebase-admin": "~5.9.0",
8+
"firebase-functions": "^1.0.0"
99
},
1010
"private": true,
1111
"devDependencies": {

Diff for: authorized-https-endpoint/functions/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
const functions = require('firebase-functions');
1919
const admin = require('firebase-admin');
20-
admin.initializeApp(functions.config().firebase);
20+
admin.initializeApp();
2121
const express = require('express');
2222
const cookieParser = require('cookie-parser')();
2323
const cors = require('cors')({origin: true});

Diff for: authorized-https-endpoint/functions/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"cookie-parser": "^1.4.3",
66
"cors": "^2.8.1",
77
"express": "^4.14.1",
8-
"firebase-admin": "^5.6.0",
9-
"firebase-functions": "^0.8.0"
8+
"firebase-admin": "~5.9.0",
9+
"firebase-functions": "^1.0.0"
1010
},
1111
"devDependencies": {
1212
"eslint": "^4.13.1",
@@ -19,5 +19,6 @@
1919
"start": "npm run shell",
2020
"deploy": "firebase deploy --only functions",
2121
"logs": "firebase functions:log"
22-
}
22+
},
23+
"private": true
2324
}

Diff for: bigquery-import/functions/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Import data to BigQuery Firebase Functions sample",
44
"dependencies": {
55
"@google-cloud/bigquery": "^0.6.0",
6-
"firebase-admin": "^4.1.1",
7-
"firebase-functions": "^0.5.1"
6+
"firebase-admin": "~5.9.0",
7+
"firebase-functions": "^1.0.0"
88
},
99
"devDependencies": {
1010
"eslint": "^4.13.1",
@@ -17,5 +17,6 @@
1717
"start": "npm run shell",
1818
"deploy": "firebase deploy --only functions",
1919
"logs": "firebase functions:log"
20-
}
20+
},
21+
"private": true
2122
}

Diff for: child-count/functions/index.js

+27-29
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,39 @@
1717

1818
const functions = require('firebase-functions');
1919
const admin = require('firebase-admin');
20-
admin.initializeApp(functions.config().firebase);
20+
admin.initializeApp();
2121

2222
// Keeps track of the length of the 'likes' child list in a separate property.
23-
exports.countlikechange = functions.database.ref('/posts/{postid}/likes/{likeid}').onWrite((event) => {
24-
const collectionRef = event.data.ref.parent;
25-
const countRef = collectionRef.parent.child('likes_count');
23+
exports.countlikechange = functions.database.ref('/posts/{postid}/likes/{likeid}').onWrite(
24+
(change) => {
25+
const collectionRef = change.after.ref.parent;
26+
const countRef = collectionRef.parent.child('likes_count');
2627

27-
let increment;
28-
if (event.data.exists() && !event.data.previous.exists()) {
29-
increment = 1;
30-
} else if (!event.data.exists() && event.data.previous.exists()) {
31-
increment = -1;
32-
} else {
33-
return null;
34-
}
28+
let increment;
29+
if (change.after.exists() && !change.after.previous.exists()) {
30+
increment = 1;
31+
} else if (!change.after.exists() && change.after.previous.exists()) {
32+
increment = -1;
33+
} else {
34+
return null;
35+
}
3536

36-
// Return the promise from countRef.transaction() so our function
37-
// waits for this async event to complete before it exits.
38-
return countRef.transaction((current) => {
39-
return (current || 0) + increment;
40-
}).then(() => {
41-
return console.log('Counter updated.');
42-
});
43-
});
37+
// Return the promise from countRef.transaction() so our function
38+
// waits for this async event to complete before it exits.
39+
return countRef.transaction((current) => {
40+
return (current || 0) + increment;
41+
}).then(() => {
42+
return console.log('Counter updated.');
43+
});
44+
});
4445

4546
// If the number of likes gets deleted, recount the number of likes
46-
exports.recountlikes = functions.database.ref('/posts/{postid}/likes_count').onWrite((event) => {
47-
if (!event.data.exists()) {
48-
const counterRef = event.data.ref;
49-
const collectionRef = counterRef.parent.child('likes');
47+
exports.recountlikes = functions.database.ref('/posts/{postid}/likes_count').onDelete((snap) => {
48+
const counterRef = snap.ref;
49+
const collectionRef = counterRef.parent.child('likes');
5050

51-
// Return the promise from counterRef.set() so our function
52-
// waits for this async event to complete before it exits.
53-
return collectionRef.once('value')
51+
// Return the promise from counterRef.set() so our function
52+
// waits for this async event to complete before it exits.
53+
return collectionRef.once('value')
5454
.then((messagesData) => counterRef.set(messagesData.numChildren()));
55-
}
56-
return null;
5755
});

Diff for: child-count/functions/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "child-count-functions",
33
"description": "Count Child nodes Firebase Functions sample",
44
"dependencies": {
5-
"firebase-admin": "^4.1.1",
6-
"firebase-functions": "^0.5.1"
5+
"firebase-admin": "~5.9.0",
6+
"firebase-functions": "^1.0.0"
77
},
88
"devDependencies": {
99
"eslint": "^4.13.1",
@@ -16,5 +16,6 @@
1616
"start": "npm run shell",
1717
"deploy": "firebase deploy --only functions",
1818
"logs": "firebase functions:log"
19-
}
19+
},
20+
"private": true
2021
}

Diff for: convert-images/functions/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ const JPEG_EXTENSION = '.jpg';
3030
* When an image is uploaded in the Storage bucket it is converted to JPEG automatically using
3131
* ImageMagick.
3232
*/
33-
exports.imageToJPG = functions.storage.object().onChange((event) => {
34-
const object = event.data;
33+
exports.imageToJPG = functions.storage.object().onFinalize((object) => {
3534
const filePath = object.name;
3635
const baseFileName = path.basename(filePath, path.extname(filePath));
3736
const fileDir = path.dirname(filePath);

Diff for: convert-images/functions/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"dependencies": {
55
"@google-cloud/storage": "^0.4.0",
66
"child-process-promise": "^2.2.0",
7-
"firebase-admin": "^4.1.1",
8-
"firebase-functions": "^0.5.1",
97
"mkdirp": "^0.5.1",
10-
"mkdirp-promise": "^4.0.0"
8+
"mkdirp-promise": "^4.0.0",
9+
"firebase-admin": "~5.9.0",
10+
"firebase-functions": "^1.0.0"
1111
},
1212
"devDependencies": {
1313
"eslint": "^4.13.1",
@@ -20,5 +20,6 @@
2020
"start": "npm run shell",
2121
"deploy": "firebase deploy --only functions",
2222
"logs": "firebase functions:log"
23-
}
23+
},
24+
"private": true
2425
}

Diff for: coupon-on-purchase/functions/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
const functions = require('firebase-functions');
1919
const admin = require('firebase-admin');
20-
admin.initializeApp(functions.config().firebase);
20+
admin.initializeApp();
2121

2222
// [START all]
2323
/**
@@ -27,9 +27,9 @@ admin.initializeApp(functions.config().firebase);
2727
exports.sendCouponOnPurchase = functions.analytics.event('in_app_purchase').onLog((event) => {
2828
// [END trigger]
2929
// [START attributes]
30-
const user = event.data.user;
30+
const user = event.user;
3131
const uid = user.userId; // The user ID set via the setUserId API.
32-
const purchaseValue = event.data.valueInUSD; // Amount of the purchase in USD.
32+
const purchaseValue = event.valueInUSD; // Amount of the purchase in USD.
3333
const userLanguage = user.deviceInfo.userDefaultLanguage; // The user language in language-country format.
3434
// [END attributes]
3535

Diff for: coupon-on-purchase/functions/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "coupon-on-crash-functions",
33
"description": "Send a coupon via FCM to your users who have experienced a crash.",
44
"dependencies": {
5-
"firebase-admin": "^4.1.2",
6-
"firebase-functions": "^0.5.1"
5+
"firebase-admin": "~5.9.0",
6+
"firebase-functions": "^1.0.0"
77
},
88
"devDependencies": {
99
"eslint": "^4.13.1",
@@ -16,5 +16,6 @@
1616
"start": "npm run shell",
1717
"deploy": "firebase deploy --only functions",
1818
"logs": "firebase functions:log"
19-
}
19+
},
20+
"private": true
2021
}

Diff for: crashlytics-integration/email-notifier/functions/index.js

+27-33
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ const sendgridMail = require('@sendgrid/mail');
2121
// Authentication for the SendGrid account
2222
sendgridMail.setApiKey(functions.config().sendgrid.api_key);
2323

24-
exports.sendOnNewIssue = functions.crashlytics.issue().onNewDetected((event) => {
25-
const data = event.data;
26-
27-
const issueId = data.issueId;
28-
const issueTitle = data.issueTitle;
29-
const appName = data.appInfo.appName;
30-
const appId = data.appInfo.appId;
31-
const appPlatform = data.appInfo.appPlatform;
32-
const latestAppVersion = data.appInfo.latestAppVersion;
33-
const createTime = data.createTime;
24+
exports.sendOnNewIssue = functions.crashlytics.issue().onNew((issue) => {
25+
const issueId = issue.issueId;
26+
const issueTitle = issue.issueTitle;
27+
const appName = issue.appInfo.appName;
28+
const appId = issue.appInfo.appId;
29+
const appPlatform = issue.appInfo.appPlatform;
30+
const latestAppVersion = issue.appInfo.latestAppVersion;
31+
const createTime = issue.createTime;
3432

3533
const emailDetails = {
3634
to: functions.config().email.destination_email,
@@ -53,17 +51,15 @@ exports.sendOnNewIssue = functions.crashlytics.issue().onNewDetected((event) =>
5351
});
5452
});
5553

56-
exports.sendOnRegressedIssue = functions.crashlytics.issue().onRegressed((event) => {
57-
const data = event.data;
58-
59-
const issueId = data.issueId;
60-
const issueTitle = data.issueTitle;
61-
const appName = data.appInfo.appName;
62-
const appId = data.appInfo.appId;
63-
const appPlatform = data.appInfo.appPlatform;
64-
const latestAppVersion = data.appInfo.latestAppVersion;
65-
const createTime = data.createTime;
66-
const resolvedTime = data.resolvedTime;
54+
exports.sendOnRegressedIssue = functions.crashlytics.issue().onRegressed((issue) => {
55+
const issueId = issue.issueId;
56+
const issueTitle = issue.issueTitle;
57+
const appName = issue.appInfo.appName;
58+
const appId = issue.appInfo.appId;
59+
const appPlatform = issue.appInfo.appPlatform;
60+
const latestAppVersion = issue.appInfo.latestAppVersion;
61+
const createTime = issue.createTime;
62+
const resolvedTime = issue.resolvedTime;
6763

6864
const emailDetails = {
6965
to: functions.config().email.destination_email,
@@ -87,18 +83,16 @@ exports.sendOnRegressedIssue = functions.crashlytics.issue().onRegressed((event)
8783
});
8884
});
8985

90-
exports.sendOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert((event) => {
91-
const data = event.data;
92-
93-
const issueId = data.issueId;
94-
const issueTitle = data.issueTitle;
95-
const appName = data.appInfo.appName;
96-
const appId = data.appInfo.appId;
97-
const appPlatform = data.appInfo.appPlatform;
98-
const latestAppVersion = data.appInfo.latestAppVersion;
99-
const createTime = data.createTime;
100-
const crashPercentage = data.velocityAlert.crashPercentage;
101-
const crashes = data.velocityAlert.crashes;
86+
exports.sendOnVelocityAlert = functions.crashlytics.issue().onVelocityAlert((issue) => {
87+
const issueId = issue.issueId;
88+
const issueTitle = issue.issueTitle;
89+
const appName = issue.appInfo.appName;
90+
const appId = issue.appInfo.appId;
91+
const appPlatform = issue.appInfo.appPlatform;
92+
const latestAppVersion = issue.appInfo.latestAppVersion;
93+
const createTime = issue.createTime;
94+
const crashPercentage = issue.velocityAlert.crashPercentage;
95+
const crashes = issue.velocityAlert.crashes;
10296

10397
const emailDetails = {
10498
to: functions.config().email.destination_email,

Diff for: crashlytics-integration/email-notifier/functions/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"description": "Cloud Functions for Firebase",
44
"dependencies": {
55
"@sendgrid/mail": "6.1.4",
6-
"firebase-admin": "^5.4.2",
7-
"firebase-functions": "^0.7.2"
6+
"firebase-admin": "~5.9.0",
7+
"firebase-functions": "^1.0.0"
88
},
99
"private": true,
1010
"devDependencies": {

0 commit comments

Comments
 (0)