Skip to content

Commit b9b4d6f

Browse files
authored
Merge pull request #439 from firebase/next
Node.js 10 Release
2 parents 7469c4a + 80965a6 commit b9b4d6f

File tree

108 files changed

+1228
-1677
lines changed

Some content is hidden

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

108 files changed

+1228
-1677
lines changed

auth-mailchimp-sync/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 0.1.1
2+
3+
feature - Update Cloud Functions runtime to Node.js 10.
4+
15
## Version 0.1.0
26

37
Initial release of the _Sync with Mailchimp_ extension.

auth-mailchimp-sync/PREINSTALL.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ Make sure that you've set up [Firebase Authentication](https://firebase.google.c
1313
You must also have a Mailchimp account before installing this extension.
1414

1515
#### Billing
16-
17-
This extension uses other Firebase or Google Cloud Platform services which may have associated charges:
18-
19-
- Firebase Realtime Database
20-
- Cloud Functions
21-
22-
When you use Firebase Extensions, you're only charged for the underlying resources that you use. A paid-tier billing plan is only required if the extension uses a service that requires a paid-tier plan, for example calling to a Google Cloud Platform API or making outbound network requests to non-Google services. All Firebase services offer a free tier of usage. [Learn more about Firebase billing.](https://firebase.google.com/pricing)
16+
17+
To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)
18+
19+
- You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used).
20+
- This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service’s free tier:
21+
- Cloud Functions (Node.js 10+ runtime. See [FAQs](https://firebase.google.com/support/faq#expandable-24))
2322

2423
Usage of this extension also requires you to have a Mailchimp account. You are responsible for any associated costs with your usage of Mailchimp.
25-

auth-mailchimp-sync/README.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

auth-mailchimp-sync/extension.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
name: auth-mailchimp-sync
16-
version: 0.1.0
16+
version: 0.1.1
1717
specVersion: v1beta
1818

1919
displayName: Sync with Mailchimp
@@ -49,6 +49,7 @@ resources:
4949
then automatically adds the new user to your specified MailChimp audience.
5050
properties:
5151
location: ${LOCATION}
52+
runtime: nodejs10
5253
eventTrigger:
5354
eventType: providers/firebase.auth/eventTypes/user.create
5455
resource: projects/${PROJECT_ID}
@@ -61,6 +62,7 @@ resources:
6162
MailChimp audience.
6263
properties:
6364
location: ${LOCATION}
65+
runtime: nodejs10
6466
eventTrigger:
6567
eventType: providers/firebase.auth/eventTypes/user.delete
6668
resource: projects/${PROJECT_ID}
Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +0,0 @@
1-
# Sync with Mailchimp
2-
3-
**Description**: Adds new users from Firebase Authentication to a specified Mailchimp audience.
4-
5-
6-
7-
**Details**: Use this extension to add new users to an existing [Mailchimp](https://mailchimp.com) audience.
8-
9-
This extension adds the email address of each new user to your specified Mailchimp audience. Also, if the user deletes their user account for your app, this extension removes the user from the Mailchimp audience.
10-
11-
**Note:** To use this extension, you need to manage your users with Firebase Authentication.
12-
13-
This extension uses Mailchimp, so you'll need to supply your Mailchimp API Key and Audience ID when installing this extension.
14-
15-
#### Additional setup
16-
17-
Make sure that you've set up [Firebase Authentication](https://firebase.google.com/docs/auth) to manage your users.
18-
19-
You must also have a Mailchimp account before installing this extension.
20-
21-
#### Billing
22-
23-
This extension uses other Firebase or Google Cloud Platform services which may have associated charges:
24-
25-
- Firebase Realtime Database
26-
- Cloud Functions
27-
28-
When you use Firebase Extensions, you're only charged for the underlying resources that you use. A paid-tier billing plan is only required if the extension uses a service that requires a paid-tier plan, for example calling to a Google Cloud Platform API or making outbound network requests to non-Google services. All Firebase services offer a free tier of usage. [Learn more about Firebase billing.](https://firebase.google.com/pricing)
29-
30-
Usage of this extension also requires you to have a Mailchimp account. You are responsible for any associated costs with your usage of Mailchimp.
31-
32-
33-
34-
35-
36-
**Configuration Parameters:**
37-
38-
* Cloud Functions location: Where do you want to deploy the functions created for this extension?
39-
40-
* Mailchimp API key: What is your Mailchimp API key? To obtain a Mailchimp API key, go to your [Mailchimp account](https://admin.mailchimp.com/account/api/).
41-
42-
* Audience ID: What is the Mailchimp Audience ID to which you want to subscribe new users? To find your Audience ID: visit https://admin.mailchimp.com/lists, click on the desired audience or create a new audience, then select **Settings**. Look for **Audience ID** (for example, `27735fc60a`).
43-
44-
* Contact status: When the extension adds a new user to the Mailchimp audience, what is their initial status? This value can be `subscribed` or `pending`. `subscribed` means the user can receive campaigns; `pending` means the user still needs to opt-in to receive campaigns.
45-
46-
47-
48-
**Cloud Functions:**
49-
50-
* **addUserToList:** Listens for new user accounts (as managed by Firebase Authentication), then automatically adds the new user to your specified MailChimp audience.
51-
52-
* **removeUserFromList:** Listens for existing user accounts to be deleted (as managed by Firebase Authentication), then automatically removes them from your specified MailChimp audience.

auth-mailchimp-sync/functions/__tests__/functions.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
2-
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
1+
const { logger } = require("firebase-functions");
2+
3+
const consoleLogSpy = jest.spyOn(logger, "log").mockImplementation();
34

45
import functionsConfig from "../src/config";
56
import { obfuscatedConfig } from "../src/logs";

auth-mailchimp-sync/functions/lib/index.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19-
return new (P || (P = Promise))(function (resolve, reject) {
20-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23-
step((generator = generator.apply(thisArg, _arguments || [])).next());
24-
});
25-
};
2617
Object.defineProperty(exports, "__esModule", { value: true });
2718
exports.removeUserFromList = exports.addUserToList = void 0;
2819
const crypto = require("crypto");
@@ -39,7 +30,7 @@ try {
3930
catch (err) {
4031
logs.initError(err);
4132
}
42-
exports.addUserToList = functions.handler.auth.user.onCreate((user) => __awaiter(void 0, void 0, void 0, function* () {
33+
exports.addUserToList = functions.handler.auth.user.onCreate(async (user) => {
4334
logs.start();
4435
if (!mailchimp) {
4536
logs.mailchimpNotInitialized();
@@ -52,7 +43,7 @@ exports.addUserToList = functions.handler.auth.user.onCreate((user) => __awaiter
5243
}
5344
try {
5445
logs.userAdding(uid, config_1.default.mailchimpAudienceId);
55-
const results = yield mailchimp.post(`/lists/${config_1.default.mailchimpAudienceId}/members`, {
46+
const results = await mailchimp.post(`/lists/${config_1.default.mailchimpAudienceId}/members`, {
5647
email_address: email,
5748
status: config_1.default.mailchimpContactStatus,
5849
});
@@ -62,8 +53,8 @@ exports.addUserToList = functions.handler.auth.user.onCreate((user) => __awaiter
6253
catch (err) {
6354
logs.errorAddUser(err);
6455
}
65-
}));
66-
exports.removeUserFromList = functions.handler.auth.user.onDelete((user) => __awaiter(void 0, void 0, void 0, function* () {
56+
});
57+
exports.removeUserFromList = functions.handler.auth.user.onDelete(async (user) => {
6758
logs.start();
6859
if (!mailchimp) {
6960
logs.mailchimpNotInitialized();
@@ -80,11 +71,11 @@ exports.removeUserFromList = functions.handler.auth.user.onDelete((user) => __aw
8071
.update(email)
8172
.digest("hex");
8273
logs.userRemoving(uid, hashed, config_1.default.mailchimpAudienceId);
83-
yield mailchimp.delete(`/lists/${config_1.default.mailchimpAudienceId}/members/${hashed}`);
74+
await mailchimp.delete(`/lists/${config_1.default.mailchimpAudienceId}/members/${hashed}`);
8475
logs.userRemoved(uid, hashed, config_1.default.mailchimpAudienceId);
8576
logs.complete();
8677
}
8778
catch (err) {
8879
logs.errorRemoveUser(err);
8980
}
90-
}));
81+
});

auth-mailchimp-sync/functions/lib/logs.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,45 @@
1616
*/
1717
Object.defineProperty(exports, "__esModule", { value: true });
1818
exports.userRemoving = exports.userRemoved = exports.userNoEmail = exports.userAdding = exports.userAdded = exports.start = exports.mailchimpNotInitialized = exports.initError = exports.init = exports.errorRemoveUser = exports.errorAddUser = exports.complete = exports.obfuscatedConfig = void 0;
19+
const firebase_functions_1 = require("firebase-functions");
1920
const config_1 = require("./config");
20-
exports.obfuscatedConfig = Object.assign(Object.assign({}, config_1.default), { mailchimpApiKey: "<omitted>" });
21+
exports.obfuscatedConfig = {
22+
...config_1.default,
23+
mailchimpApiKey: "<omitted>",
24+
};
2125
exports.complete = () => {
22-
console.log("Completed execution of extension");
26+
firebase_functions_1.logger.log("Completed execution of extension");
2327
};
2428
exports.errorAddUser = (err) => {
25-
console.error("Error when adding user to Mailchimp audience", err);
29+
firebase_functions_1.logger.error("Error when adding user to Mailchimp audience", err);
2630
};
2731
exports.errorRemoveUser = (err) => {
28-
console.error("Error when removing user from Mailchimp audience", err);
32+
firebase_functions_1.logger.error("Error when removing user from Mailchimp audience", err);
2933
};
3034
exports.init = () => {
31-
console.log("Initializing extension with configuration", exports.obfuscatedConfig);
35+
firebase_functions_1.logger.log("Initializing extension with configuration", exports.obfuscatedConfig);
3236
};
3337
exports.initError = (err) => {
34-
console.error("Error when initializing extension", err);
38+
firebase_functions_1.logger.error("Error when initializing extension", err);
3539
};
3640
exports.mailchimpNotInitialized = () => {
37-
console.error("Mailchimp was not initialized correctly, check for errors in the logs");
41+
firebase_functions_1.logger.error("Mailchimp was not initialized correctly, check for errors in the logs");
3842
};
3943
exports.start = () => {
40-
console.log("Started execution of extension with configuration", exports.obfuscatedConfig);
44+
firebase_functions_1.logger.log("Started execution of extension with configuration", exports.obfuscatedConfig);
4145
};
4246
exports.userAdded = (userId, audienceId, mailchimpId, status) => {
43-
console.log(`Added user: ${userId} with status '${status}' to Mailchimp audience: ${audienceId} with Mailchimp ID: ${mailchimpId}`);
47+
firebase_functions_1.logger.log(`Added user: ${userId} with status '${status}' to Mailchimp audience: ${audienceId} with Mailchimp ID: ${mailchimpId}`);
4448
};
4549
exports.userAdding = (userId, audienceId) => {
46-
console.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
50+
firebase_functions_1.logger.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
4751
};
4852
exports.userNoEmail = () => {
49-
console.log("User does not have an email");
53+
firebase_functions_1.logger.log("User does not have an email");
5054
};
5155
exports.userRemoved = (userId, hashedEmail, audienceId) => {
52-
console.log(`Removed user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
56+
firebase_functions_1.logger.log(`Removed user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
5357
};
5458
exports.userRemoving = (userId, hashedEmail, audienceId) => {
55-
console.log(`Removing user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
59+
firebase_functions_1.logger.log(`Removing user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
5660
};

auth-mailchimp-sync/functions/src/logs.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { logger } from "firebase-functions";
1718
import config from "./config";
1819

1920
export const obfuscatedConfig = {
@@ -22,33 +23,33 @@ export const obfuscatedConfig = {
2223
};
2324

2425
export const complete = () => {
25-
console.log("Completed execution of extension");
26+
logger.log("Completed execution of extension");
2627
};
2728

2829
export const errorAddUser = (err: Error) => {
29-
console.error("Error when adding user to Mailchimp audience", err);
30+
logger.error("Error when adding user to Mailchimp audience", err);
3031
};
3132

3233
export const errorRemoveUser = (err: Error) => {
33-
console.error("Error when removing user from Mailchimp audience", err);
34+
logger.error("Error when removing user from Mailchimp audience", err);
3435
};
3536

3637
export const init = () => {
37-
console.log("Initializing extension with configuration", obfuscatedConfig);
38+
logger.log("Initializing extension with configuration", obfuscatedConfig);
3839
};
3940

4041
export const initError = (err: Error) => {
41-
console.error("Error when initializing extension", err);
42+
logger.error("Error when initializing extension", err);
4243
};
4344

4445
export const mailchimpNotInitialized = () => {
45-
console.error(
46+
logger.error(
4647
"Mailchimp was not initialized correctly, check for errors in the logs"
4748
);
4849
};
4950

5051
export const start = () => {
51-
console.log(
52+
logger.log(
5253
"Started execution of extension with configuration",
5354
obfuscatedConfig
5455
);
@@ -60,25 +61,25 @@ export const userAdded = (
6061
mailchimpId: string,
6162
status: string
6263
) => {
63-
console.log(
64+
logger.log(
6465
`Added user: ${userId} with status '${status}' to Mailchimp audience: ${audienceId} with Mailchimp ID: ${mailchimpId}`
6566
);
6667
};
6768

6869
export const userAdding = (userId: string, audienceId: string) => {
69-
console.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
70+
logger.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
7071
};
7172

7273
export const userNoEmail = () => {
73-
console.log("User does not have an email");
74+
logger.log("User does not have an email");
7475
};
7576

7677
export const userRemoved = (
7778
userId: string,
7879
hashedEmail: string,
7980
audienceId: string
8081
) => {
81-
console.log(
82+
logger.log(
8283
`Removed user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`
8384
);
8485
};
@@ -88,7 +89,7 @@ export const userRemoving = (
8889
hashedEmail: string,
8990
audienceId: string
9091
) => {
91-
console.log(
92+
logger.log(
9293
`Removing user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`
9394
);
9495
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "lib"
4+
"outDir": "lib",
5+
"target": "es2018"
56
},
67
"include": ["src"]
78
}

codecov.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ codecov:
33

44
coverage:
55
precision: 2
6-
round: down
7-
range: "40...100"
6+
round: up
7+
range: "35...100"
88

99
status:
1010
project:
1111
default: true
12+
patch: off
1213

1314
comment:
1415
layout: "reach, diff, files"

0 commit comments

Comments
 (0)