Skip to content

Commit

Permalink
Merge pull request #439 from firebase/next
Browse files Browse the repository at this point in the history
Node.js 10 Release
  • Loading branch information
laurenzlong committed Sep 1, 2020
2 parents 7469c4a + 80965a6 commit b9b4d6f
Show file tree
Hide file tree
Showing 108 changed files with 1,228 additions and 1,677 deletions.
4 changes: 4 additions & 0 deletions auth-mailchimp-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.1.1

feature - Update Cloud Functions runtime to Node.js 10.

## Version 0.1.0

Initial release of the _Sync with Mailchimp_ extension.
14 changes: 6 additions & 8 deletions auth-mailchimp-sync/PREINSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ Make sure that you've set up [Firebase Authentication](https://firebase.google.c
You must also have a Mailchimp account before installing this extension.

#### Billing

This extension uses other Firebase or Google Cloud Platform services which may have associated charges:

- Firebase Realtime Database
- Cloud Functions

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)

To install an extension, your project must be on the [Blaze (pay as you go) plan](https://firebase.google.com/pricing)

- 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).
- This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service’s free tier:
- Cloud Functions (Node.js 10+ runtime. See [FAQs](https://firebase.google.com/support/faq#expandable-24))

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

52 changes: 0 additions & 52 deletions auth-mailchimp-sync/README.md

This file was deleted.

4 changes: 3 additions & 1 deletion auth-mailchimp-sync/extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

name: auth-mailchimp-sync
version: 0.1.0
version: 0.1.1
specVersion: v1beta

displayName: Sync with Mailchimp
Expand Down Expand Up @@ -49,6 +49,7 @@ resources:
then automatically adds the new user to your specified MailChimp audience.
properties:
location: ${LOCATION}
runtime: nodejs10
eventTrigger:
eventType: providers/firebase.auth/eventTypes/user.create
resource: projects/${PROJECT_ID}
Expand All @@ -61,6 +62,7 @@ resources:
MailChimp audience.
properties:
location: ${LOCATION}
runtime: nodejs10
eventTrigger:
eventType: providers/firebase.auth/eventTypes/user.delete
resource: projects/${PROJECT_ID}
Expand Down
52 changes: 0 additions & 52 deletions auth-mailchimp-sync/functions/README.md
Original file line number Diff line number Diff line change
@@ -1,52 +0,0 @@
# Sync with Mailchimp

**Description**: Adds new users from Firebase Authentication to a specified Mailchimp audience.



**Details**: Use this extension to add new users to an existing [Mailchimp](https://mailchimp.com) audience.

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.

**Note:** To use this extension, you need to manage your users with Firebase Authentication.

This extension uses Mailchimp, so you'll need to supply your Mailchimp API Key and Audience ID when installing this extension.

#### Additional setup

Make sure that you've set up [Firebase Authentication](https://firebase.google.com/docs/auth) to manage your users.

You must also have a Mailchimp account before installing this extension.

#### Billing

This extension uses other Firebase or Google Cloud Platform services which may have associated charges:

- Firebase Realtime Database
- Cloud Functions

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)

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





**Configuration Parameters:**

* Cloud Functions location: Where do you want to deploy the functions created for this extension?

* 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/).

* 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`).

* 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.



**Cloud Functions:**

* **addUserToList:** Listens for new user accounts (as managed by Firebase Authentication), then automatically adds the new user to your specified MailChimp audience.

* **removeUserFromList:** Listens for existing user accounts to be deleted (as managed by Firebase Authentication), then automatically removes them from your specified MailChimp audience.
5 changes: 3 additions & 2 deletions auth-mailchimp-sync/functions/__tests__/functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const consoleLogSpy = jest.spyOn(console, "log").mockImplementation();
const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
const { logger } = require("firebase-functions");

const consoleLogSpy = jest.spyOn(logger, "log").mockImplementation();

import functionsConfig from "../src/config";
import { obfuscatedConfig } from "../src/logs";
Expand Down
21 changes: 6 additions & 15 deletions auth-mailchimp-sync/functions/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeUserFromList = exports.addUserToList = void 0;
const crypto = require("crypto");
Expand All @@ -39,7 +30,7 @@ try {
catch (err) {
logs.initError(err);
}
exports.addUserToList = functions.handler.auth.user.onCreate((user) => __awaiter(void 0, void 0, void 0, function* () {
exports.addUserToList = functions.handler.auth.user.onCreate(async (user) => {
logs.start();
if (!mailchimp) {
logs.mailchimpNotInitialized();
Expand All @@ -52,7 +43,7 @@ exports.addUserToList = functions.handler.auth.user.onCreate((user) => __awaiter
}
try {
logs.userAdding(uid, config_1.default.mailchimpAudienceId);
const results = yield mailchimp.post(`/lists/${config_1.default.mailchimpAudienceId}/members`, {
const results = await mailchimp.post(`/lists/${config_1.default.mailchimpAudienceId}/members`, {
email_address: email,
status: config_1.default.mailchimpContactStatus,
});
Expand All @@ -62,8 +53,8 @@ exports.addUserToList = functions.handler.auth.user.onCreate((user) => __awaiter
catch (err) {
logs.errorAddUser(err);
}
}));
exports.removeUserFromList = functions.handler.auth.user.onDelete((user) => __awaiter(void 0, void 0, void 0, function* () {
});
exports.removeUserFromList = functions.handler.auth.user.onDelete(async (user) => {
logs.start();
if (!mailchimp) {
logs.mailchimpNotInitialized();
Expand All @@ -80,11 +71,11 @@ exports.removeUserFromList = functions.handler.auth.user.onDelete((user) => __aw
.update(email)
.digest("hex");
logs.userRemoving(uid, hashed, config_1.default.mailchimpAudienceId);
yield mailchimp.delete(`/lists/${config_1.default.mailchimpAudienceId}/members/${hashed}`);
await mailchimp.delete(`/lists/${config_1.default.mailchimpAudienceId}/members/${hashed}`);
logs.userRemoved(uid, hashed, config_1.default.mailchimpAudienceId);
logs.complete();
}
catch (err) {
logs.errorRemoveUser(err);
}
}));
});
30 changes: 17 additions & 13 deletions auth-mailchimp-sync/functions/lib/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,45 @@
*/
Object.defineProperty(exports, "__esModule", { value: true });
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;
const firebase_functions_1 = require("firebase-functions");
const config_1 = require("./config");
exports.obfuscatedConfig = Object.assign(Object.assign({}, config_1.default), { mailchimpApiKey: "<omitted>" });
exports.obfuscatedConfig = {
...config_1.default,
mailchimpApiKey: "<omitted>",
};
exports.complete = () => {
console.log("Completed execution of extension");
firebase_functions_1.logger.log("Completed execution of extension");
};
exports.errorAddUser = (err) => {
console.error("Error when adding user to Mailchimp audience", err);
firebase_functions_1.logger.error("Error when adding user to Mailchimp audience", err);
};
exports.errorRemoveUser = (err) => {
console.error("Error when removing user from Mailchimp audience", err);
firebase_functions_1.logger.error("Error when removing user from Mailchimp audience", err);
};
exports.init = () => {
console.log("Initializing extension with configuration", exports.obfuscatedConfig);
firebase_functions_1.logger.log("Initializing extension with configuration", exports.obfuscatedConfig);
};
exports.initError = (err) => {
console.error("Error when initializing extension", err);
firebase_functions_1.logger.error("Error when initializing extension", err);
};
exports.mailchimpNotInitialized = () => {
console.error("Mailchimp was not initialized correctly, check for errors in the logs");
firebase_functions_1.logger.error("Mailchimp was not initialized correctly, check for errors in the logs");
};
exports.start = () => {
console.log("Started execution of extension with configuration", exports.obfuscatedConfig);
firebase_functions_1.logger.log("Started execution of extension with configuration", exports.obfuscatedConfig);
};
exports.userAdded = (userId, audienceId, mailchimpId, status) => {
console.log(`Added user: ${userId} with status '${status}' to Mailchimp audience: ${audienceId} with Mailchimp ID: ${mailchimpId}`);
firebase_functions_1.logger.log(`Added user: ${userId} with status '${status}' to Mailchimp audience: ${audienceId} with Mailchimp ID: ${mailchimpId}`);
};
exports.userAdding = (userId, audienceId) => {
console.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
firebase_functions_1.logger.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
};
exports.userNoEmail = () => {
console.log("User does not have an email");
firebase_functions_1.logger.log("User does not have an email");
};
exports.userRemoved = (userId, hashedEmail, audienceId) => {
console.log(`Removed user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
firebase_functions_1.logger.log(`Removed user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
};
exports.userRemoving = (userId, hashedEmail, audienceId) => {
console.log(`Removing user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
firebase_functions_1.logger.log(`Removing user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`);
};
25 changes: 13 additions & 12 deletions auth-mailchimp-sync/functions/src/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { logger } from "firebase-functions";
import config from "./config";

export const obfuscatedConfig = {
Expand All @@ -22,33 +23,33 @@ export const obfuscatedConfig = {
};

export const complete = () => {
console.log("Completed execution of extension");
logger.log("Completed execution of extension");
};

export const errorAddUser = (err: Error) => {
console.error("Error when adding user to Mailchimp audience", err);
logger.error("Error when adding user to Mailchimp audience", err);
};

export const errorRemoveUser = (err: Error) => {
console.error("Error when removing user from Mailchimp audience", err);
logger.error("Error when removing user from Mailchimp audience", err);
};

export const init = () => {
console.log("Initializing extension with configuration", obfuscatedConfig);
logger.log("Initializing extension with configuration", obfuscatedConfig);
};

export const initError = (err: Error) => {
console.error("Error when initializing extension", err);
logger.error("Error when initializing extension", err);
};

export const mailchimpNotInitialized = () => {
console.error(
logger.error(
"Mailchimp was not initialized correctly, check for errors in the logs"
);
};

export const start = () => {
console.log(
logger.log(
"Started execution of extension with configuration",
obfuscatedConfig
);
Expand All @@ -60,25 +61,25 @@ export const userAdded = (
mailchimpId: string,
status: string
) => {
console.log(
logger.log(
`Added user: ${userId} with status '${status}' to Mailchimp audience: ${audienceId} with Mailchimp ID: ${mailchimpId}`
);
};

export const userAdding = (userId: string, audienceId: string) => {
console.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
logger.log(`Adding user: ${userId} to Mailchimp audience: ${audienceId}`);
};

export const userNoEmail = () => {
console.log("User does not have an email");
logger.log("User does not have an email");
};

export const userRemoved = (
userId: string,
hashedEmail: string,
audienceId: string
) => {
console.log(
logger.log(
`Removed user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`
);
};
Expand All @@ -88,7 +89,7 @@ export const userRemoving = (
hashedEmail: string,
audienceId: string
) => {
console.log(
logger.log(
`Removing user: ${userId} with hashed email: ${hashedEmail} from Mailchimp audience: ${audienceId}`
);
};
3 changes: 2 additions & 1 deletion auth-mailchimp-sync/functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "lib"
"outDir": "lib",
"target": "es2018"
},
"include": ["src"]
}
5 changes: 3 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ codecov:

coverage:
precision: 2
round: down
range: "40...100"
round: up
range: "35...100"

status:
project:
default: true
patch: off

comment:
layout: "reach, diff, files"
Expand Down
Loading

0 comments on commit b9b4d6f

Please sign in to comment.