Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

customerio-node

Package Overview
Dependencies
Maintainers
4
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

customerio-node - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

4

CHANGELOG.md

@@ -6,2 +6,6 @@ # Changelog

## [2.0.0]
### Changed
- (Breaking) Move triggerBroadcast method from Track to API class ([#46](https://github.com/customerio/customerio-node/pull/46))
## [1.1.0]

@@ -8,0 +12,0 @@ ### Added

@@ -5,2 +5,18 @@ const Request = require('./request');

const BROADCASTS_ALLOWED_RECIPIENT_FIELDS = {
ids: ['ids', 'id_ignore_missing'],
emails: ['emails', 'email_ignore_missing', 'email_add_duplicates'],
per_user_data: ['per_user_data', 'id_ignore_missing', 'email_ignore_missing', 'email_add_duplicates'],
data_file_url: ['data_file_url', 'id_ignore_missing', 'email_ignore_missing', 'email_add_duplicates'],
};
const filterRecipientsDataForField = (recipients, field) => {
return BROADCASTS_ALLOWED_RECIPIENT_FIELDS[field].reduce((obj, field) => {
if (!!recipients[field]) {
obj[field] = recipients[field];
}
return obj;
}, {});
};
class APIClient {

@@ -26,2 +42,18 @@ constructor(appKey, defaults = {}) {

}
triggerBroadcast(id, data, recipients) {
let payload = {};
let customRecipientField = Object.keys(BROADCASTS_ALLOWED_RECIPIENT_FIELDS).find(field => recipients[field]);
if (customRecipientField) {
payload = Object.assign({ data }, filterRecipientsDataForField(recipients, customRecipientField));
} else {
payload = {
data,
recipients,
};
}
return this.request.post(`${this.apiRoot}/api/campaigns/${id}/triggers`, payload);
}
}

@@ -28,0 +60,0 @@

2

lib/api/requests.js

@@ -1,3 +0,1 @@

const fs = require('fs');
const REQUIRED_FIELDS = Object.freeze(['to', 'identifiers']);

@@ -4,0 +2,0 @@ const OPTIONAL_FIELDS = Object.freeze([

@@ -5,18 +5,2 @@ const Request = require('./request');

const BROADCASTS_ALLOWED_RECIPIENT_FIELDS = {
ids: ['ids', 'id_ignore_missing'],
emails: ['emails', 'email_ignore_missing', 'email_add_duplicates'],
per_user_data: ['per_user_data', 'id_ignore_missing', 'email_ignore_missing', 'email_add_duplicates'],
data_file_url: ['data_file_url', 'id_ignore_missing', 'email_ignore_missing', 'email_add_duplicates'],
};
const filterRecipientsDataForField = (recipients, field) => {
return BROADCASTS_ALLOWED_RECIPIENT_FIELDS[field].reduce((obj, field) => {
if (!!recipients[field]) {
obj[field] = recipients[field];
}
return obj;
}, {});
};
class MissingParamError extends Error {

@@ -134,18 +118,2 @@ constructor(param) {

}
triggerBroadcast(id, data, recipients) {
let payload = {};
let customRecipientField = Object.keys(BROADCASTS_ALLOWED_RECIPIENT_FIELDS).find((field) => recipients[field]);
if (customRecipientField) {
payload = Object.assign({ data }, filterRecipientsDataForField(recipients, customRecipientField));
} else {
payload = {
data,
recipients,
};
}
return this.request.post(`${this.apiRoot}/api/campaigns/${id}/triggers`, payload);
}
};
{
"name": "customerio-node",
"description": "A node client for the Customer.io event API. http://customer.io",
"version": "1.1.0",
"version": "2.0.0",
"author": "Customer.io (https://customer.io)",

@@ -6,0 +6,0 @@ "contributors": [

@@ -1,2 +0,2 @@

# Customerio [![CircleCI](https://circleci.com/gh/customerio/customerio-node.svg?style=svg)](https://circleci.com/gh/customerio/customerio-node)
# Customerio [![test](https://github.com/customerio/customerio-node/actions/workflows/main.yml/badge.svg)](https://github.com/customerio/customerio-node/actions/workflows/main.yml)

@@ -25,3 +25,3 @@ A node client for the Customer.io [REST API](https://learn.customer.io/api/).

Your account `region` is optional. If you do not specify your region, we assume that your account is based in the US (`RegionUS`). If your account is based in the EU and you do not provide the correct region, we'll route requests from the US to `RegionEU` accordingly, however this may cause data to be logged in the US.
Your account `region` is optional. If you do not specify your region, we assume that your account is based in the US (`RegionUS`). If your account is based in the EU and you do not provide the correct region, we'll route requests from the US to `RegionEU` accordingly, however this may cause data to be logged in the US.

@@ -142,25 +142,2 @@ Optionally you can pass `defaults` as an object that will be passed to the underlying request instance. A list of the possible options are listed [here](https://github.com/request/request#requestoptions-callback).

### cio.triggerBroadcast(campaign_id, data, recipients)
Trigger an email broadcast using the email campaign's id. You can also optionally pass along custom data that will be merged with the liquid template, and additional conditions to filter recipients.
```
cio.triggerBroadcast(1, { name: 'foo'}, { segment: { id: 7 }});
```
You can also use emails or ids to select recipients, and pass optional API parameters such as `email_ignore_missing`.
```
cio.triggerBroadcast(1, { name: 'foo'}, { emails: ['example@emails.com'], email_ignore_missing: true }
);
```
[You can learn more about the recipient fields available here](https://customer.io/docs/api/#apicorecampaignscampaigns_trigger).
#### Options
* **id**: String (required)
* **data**: Object (optional)
* **recipients**: Object (optional)
### cio.addDevice(id, device_id, platform, data)

@@ -228,5 +205,5 @@ Add a device to send push notifications.

* `transactional_message_id`: the ID of the transactional message you want to send, or the `body`, `from`, and `subject` of a new message.
* `to`: the email address of your recipients
* `to`: the email address of your recipients
* an `identifiers` object containing the `id` of your recipient. If the `id` does not exist, Customer.io will create it.
* a `message_data` object containing properties that you want reference in your message using Liquid.
* a `message_data` object containing properties that you want reference in your message using Liquid.
* You can also send attachments with your message. Use `attach` to encode attachments.

@@ -265,2 +242,25 @@

### api.triggerBroadcast(campaign_id, data, recipients)
Trigger an email broadcast using the email campaign's id. You can also optionally pass along custom data that will be merged with the liquid template, and additional conditions to filter recipients.
```
api.triggerBroadcast(1, { name: 'foo'}, { segment: { id: 7 }});
```
You can also use emails or ids to select recipients, and pass optional API parameters such as `email_ignore_missing`.
```
api.triggerBroadcast(1, { name: 'foo'}, { emails: ['example@emails.com'], email_ignore_missing: true }
);
```
[You can learn more about the available recipient fields here](https://customer.io/docs/api/#operation/triggerBroadcast).
#### Options
* **id**: String (required)
* **data**: Object (optional)
* **recipients**: Object (optional)
## Further examples

@@ -267,0 +267,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc