Skip to content

Update everything!#13

Merged
joepurdy merged 9 commits intocustomerio:masterfrom
hashicorp:master
Mar 19, 2018
Merged

Update everything!#13
joepurdy merged 9 commits intocustomerio:masterfrom
hashicorp:master

Conversation

@jescalan
Copy link
Copy Markdown
Contributor

@jescalan jescalan commented Feb 22, 2018

Hey friends,

So I rewrote this library almost completely. I know this is exactly the type of PR that I don't particularly enjoy seeing myself, but I felt like it was justified for a couple reasons:

  • The dependencies hadn't been touched in 4+ years
  • The API surface area was incomplete, and missing several officially supported methods
  • Javascript has changed and got a lot better in the last couple of years

Here's what I did:

  • Modernized all the javascript to es6. Prototype classes turned into real classes, external dependency promises to native promises, _this = this eliminated through arrow functions, all code formatted using prettier, etc.
  • Brought all dependencies up to date, made sure that no test dependencies were in the normal dependencies section (there was one big one previously).
  • Rewrote the tests using ava instead of mocha. Ava has a very strong integration with the nyc package for test coverage, is a little smaller and more clear, and doesn't pipe in a bunch of globals that you need to guess. The tests themselves are effectively the same despite this.
  • Added support for anonymous event tracking and the triggerBroadcast endpoint, and added test coverage for these as well
  • Eliminated a lot of repeated or useless code and generally decreased the footprint by a lot.

All tests are passing, test coverage has been improved, and I'm hoping you guys will accept this. I would be happy to maintain it to the best of my ability as things change - I know that I will be relying on this code for my job regardless, so it's a good fit.

Thank you for making an awesome email platform, and sending over much love from HashiCorp 💖

Also, this closes #12, and incorporates the suggestion

Copy link
Copy Markdown
Contributor

@alvincrespo alvincrespo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty amazing! I don't work at Customer.io anymore, but as the original author of this library - this should totally be approved.

Thanks for making this happen - you rock!

Comment thread README.md
@@ -1,13 +1,13 @@
[![Build Status](https://travis-ci.org/alvincrespo/ember-cli-customerio.svg)](https://travis-ci.org/alvincrespo/ember-cli-customerio)
[![Build Status](https://travis-ci.org/customerio/customerio-node.svg)](https://travis-ci.org/customerio/customerio-node)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

Comment thread README.md

```
npm install --save customerio-node
npm i customerio-node
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be updated to yarn instead of npm?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so - npm is still the default so probably best to leave it. Although of course yarn will work as well!

Comment thread lib/index.js
return typeof id === 'object'
? this.request.post(`${root}/events`, id)
: this.request.post(`${root}/customers/${id}/events`, data)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's worth making to methods: trackAsObject and trackAsId. I always worry about checking against types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we could definitely separate them into different methods. I'd probably go with track and trackAnonymous or something like this. This API is a little bit smoother though, and I can't really think of an instance where someone would pass an object as the id and not expect something to go horribly wrong.

I'm open to either though tbh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anonymous event tracking isn't exposed well by our API libraries. The Ruby library is the only one to have a method for anonymous event tracking today.

I'm in favor of being explicit in separating these API calls into their own methods, track and trackAnonymous. This is more inline with our approach with the Ruby lib and our API documentation which separates anonymous events into their own resource.

Comment thread package.json
"directories": {
"test": "tests"
"version": "0.2.0",
"author": "Alvin Crespo",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be CustomerIO?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️I can change it to this if you want!

Comment thread package.json
"type": "git",
"url": "https://github.com/customerio/customerio-node.git"
"devDependencies": {
"ava": "^0.25.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😃

@jescalan
Copy link
Copy Markdown
Contributor Author

@alvincrespo 👬 💖

@jescalan
Copy link
Copy Markdown
Contributor Author

Hey also, I feel like we should probably ask @liamdon if he would mind giving us the primary customer.io namespace, especially if this one is hosted/maintained by the company itself.

Copy link
Copy Markdown
Contributor

@joepurdy joepurdy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much @jescalan for giving our node library some much needed TLC! 😍

I've left a couple comments for you to review, but we're also going to have one of our front end engineers review this PR since they're more well versed in JS. 😀

Comment thread lib/index.js
return typeof id === 'object'
? this.request.post(`${root}/events`, id)
: this.request.post(`${root}/customers/${id}/events`, data)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anonymous event tracking isn't exposed well by our API libraries. The Ruby library is the only one to have a method for anonymous event tracking today.

I'm in favor of being explicit in separating these API calls into their own methods, track and trackAnonymous. This is more inline with our approach with the Ruby lib and our API documentation which separates anonymous events into their own resource.

Comment thread lib/index.js Outdated
}

triggerBroadcast(id, data, recipients) {
return this.request.post(`${root}/campaigns/${id}/triggers`, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't actually work for triggered broadcasts because they use a different API endpoint. https://api.customer.io/v1/api/campaigns/${id}/triggers instead of https://track.customer.io/api/v1/campaigns/${id}/triggers

For now only track.customer.io API methods are in the libraries because we're still determining the best path forward to supporting the two distinct APIs we provide.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'll update this now, and will also separate the track method in the way you described. I considered this initially, but decided to go the way I did because it's the same endpoint, and it was a little smoother of an interface. But the rationale you have there makes perfect sense and I'll change it over.

@liamdon
Copy link
Copy Markdown

liamdon commented Mar 13, 2018

Hey guys! Great to see all this activity on the library. I would definitely like to give you the npm namespace. What's the best way to do this? Could I add someone as an owner on npm to make the required changes?

Comment thread lib/index.js Outdated
const Request = require('./request')
const root = 'https://track.customer.io/api/v1'
const trackRoot = 'https://track.customer.io/api/v1'
const apiRoot = 'https://api.customer.io/v1'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So close!

You just need to add /api to change the apiRoot to 'https://api.customer.io/v1/api' here and in test/index.js. Beyond that the changes look spectacular. 🤩

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, don't know how I missed that one. Fix incoming!

Comment thread lib/index.js Outdated
const Request = require('./request')
const root = 'https://track.customer.io/api/v1'
const trackRoot = 'https://track.customer.io/api/v1'
const apiRoot = 'https://api.customer.io/api/v1'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not quite right, it's a bit confusing because the order of api/v1/ gets flipped on the apiRoot endpoint. So instead of 'https://api.customer.io/api/v1' it should be 'https://api.customer.io/v1/api'.

In your defense when I originally added triggered broadcasts to our API documentation I also mixed up the order about five or six times before getting it right. 😂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahah good lord, who was responsible for this decision?! oook one more update coming soon

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ook let's see if this round did it!

Copy link
Copy Markdown
Contributor

@kevinkucharczyk kevinkucharczyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, thank you soo much for this amazing PR! Looks great to me 🙂

@joepurdy
Copy link
Copy Markdown
Contributor

@jescalan We're going to merge this PR and bump the minor version on Monday. 🍾

@liamdon Thanks for the offer to transition the customer.io namespace to us, however we discussed it internally and decided to keep the package names as they are today to avoid introducing pain for any current users of customer.io package that aren't locking their version safely.

@jescalan
Copy link
Copy Markdown
Contributor Author

🙌 🎉

@joepurdy joepurdy merged commit acfe410 into customerio:master Mar 19, 2018
@jescalan
Copy link
Copy Markdown
Contributor Author

Excited to see this land! Could you do me a favor and let me know when it has been released to NPM, just so I can update our code from using the fork to the official? 🥇

@joepurdy
Copy link
Copy Markdown
Contributor

fyi @jescalan v0.3.0 has landed!

🙌🎉😤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants