rejoiner 2.10.2 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +6 -3
- package/lib/endpoints/customer.js +25 -5
- package/lib/endpoints/journeys.js +8 -7
- package/lib/endpoints/lists.js +3 -3
- package/lib/endpoints/ping.js +1 -1
- package/lib/endpoints/segments.js +1 -1
- package/lib/helpers.js +7 -7
- package/lib/rejoiner.js +8 -5
- package/package.json +7 -7
package/lib/config.js
CHANGED
|
@@ -2,13 +2,16 @@ const VERSION = require('../package.json').version
|
|
|
2
2
|
|
|
3
3
|
const { REJOINER_API_KEY, REJOINER_SITE_ID, REJOINER_WEBHOOK_SECRET } = process.env
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const DEFAULT_API_VERSION = 1
|
|
6
|
+
|
|
7
|
+
const DEFAULT_BASE_URL = 'https://rj2.rejoiner.com/api'
|
|
6
8
|
const REJOINER_BASE_URL = process.env.REJOINER_BASE_URL || DEFAULT_BASE_URL
|
|
7
9
|
|
|
8
10
|
module.exports = {
|
|
9
|
-
|
|
11
|
+
DEFAULT_API_VERSION,
|
|
10
12
|
REJOINER_API_KEY,
|
|
13
|
+
REJOINER_BASE_URL,
|
|
11
14
|
REJOINER_SITE_ID,
|
|
12
15
|
REJOINER_WEBHOOK_SECRET,
|
|
13
|
-
|
|
16
|
+
VERSION,
|
|
14
17
|
}
|
|
@@ -11,11 +11,31 @@ const customerEndpoint = (client) => {
|
|
|
11
11
|
if (always) return dispatchReturnData('post')(`${endpoint}/always_convert/`, data)
|
|
12
12
|
return dispatchReturnData('post')(`${endpoint}/convert/`, data)
|
|
13
13
|
},
|
|
14
|
-
cancel: email => postEmail(`${endpoint}/cancel/`, email),
|
|
15
|
-
unsubscribe: email => postEmail(`${endpoint}/unsubscribe/`, email),
|
|
16
|
-
optIn: email => postEmail(`${endpoint}/opt_in/`, email),
|
|
17
|
-
get: email =>
|
|
18
|
-
|
|
14
|
+
cancel: (email) => postEmail(`${endpoint}/cancel/`, email),
|
|
15
|
+
unsubscribe: (email) => postEmail(`${endpoint}/unsubscribe/`, email),
|
|
16
|
+
optIn: (email) => postEmail(`${endpoint}/opt_in/`, email),
|
|
17
|
+
get: (email) => {
|
|
18
|
+
switch (client.version) {
|
|
19
|
+
case 1:
|
|
20
|
+
return dispatchReturnData('get')(`customers/${email}/`)
|
|
21
|
+
case 2:
|
|
22
|
+
return dispatchReturnData('get')('customers/by_email/', {
|
|
23
|
+
params: { email },
|
|
24
|
+
})
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Invalid API version: ${client.version}`)
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
update: (data) => {
|
|
30
|
+
switch (client.version) {
|
|
31
|
+
case 1:
|
|
32
|
+
return putEmail(`customers/${data.email}/`, data)
|
|
33
|
+
case 2:
|
|
34
|
+
return postEmail('/customers/', data)
|
|
35
|
+
default:
|
|
36
|
+
throw new Error(`Invalid API version: ${client.version}`)
|
|
37
|
+
}
|
|
38
|
+
},
|
|
19
39
|
}
|
|
20
40
|
}
|
|
21
41
|
|
|
@@ -5,8 +5,8 @@ const path = 'journeys'
|
|
|
5
5
|
const journeysEndpoint = (client) => {
|
|
6
6
|
const { dispatchReturnData } = withClient(client)
|
|
7
7
|
|
|
8
|
-
const endpoint = journeyId => ({
|
|
9
|
-
nodes: nodeId => ({
|
|
8
|
+
const endpoint = (journeyId) => ({
|
|
9
|
+
nodes: (nodeId) => ({
|
|
10
10
|
webhook: (email) => {
|
|
11
11
|
const requestPath = `${path}/${journeyId}/nodes/${nodeId}/webhook_event_wait/`
|
|
12
12
|
|
|
@@ -19,11 +19,12 @@ const journeysEndpoint = (client) => {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
if (typeof email === 'object' && typeof email.email === 'string') {
|
|
22
|
-
return dispatchReturnData('post')(requestPath,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
return dispatchReturnData('post')(requestPath, {
|
|
23
|
+
customer_data: {},
|
|
24
|
+
session_data: {},
|
|
25
|
+
...email,
|
|
26
|
+
email: email.email.toLowerCase(),
|
|
27
|
+
})
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
return Promise.reject(new Error('Request is missing required email parameter.'))
|
package/lib/endpoints/lists.js
CHANGED
|
@@ -15,13 +15,13 @@ const listsEndpoint = (client) => {
|
|
|
15
15
|
|
|
16
16
|
return dispatchReturnData('post')(`${endpoint}/`, name)
|
|
17
17
|
},
|
|
18
|
-
contacts: listId => ({
|
|
18
|
+
contacts: (listId) => ({
|
|
19
19
|
get: (page) => {
|
|
20
20
|
const pagination = page ? `?page=${page}` : ''
|
|
21
21
|
return dispatchReturnData('get')(`${endpoint}/${listId}/contacts/${pagination}`)
|
|
22
22
|
},
|
|
23
|
-
add: email => postEmail(`${endpoint}/${listId}/contacts/`, email),
|
|
24
|
-
remove: email => postEmail(`${endpoint}/${listId}/contacts/remove/`, email),
|
|
23
|
+
add: (email) => postEmail(`${endpoint}/${listId}/contacts/`, email),
|
|
24
|
+
remove: (email) => postEmail(`${endpoint}/${listId}/contacts/remove/`, email),
|
|
25
25
|
}),
|
|
26
26
|
}
|
|
27
27
|
}
|
package/lib/endpoints/ping.js
CHANGED
package/lib/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const withClient = (client) => {
|
|
2
|
-
const dispatchReturnData = method => (...args) => client.dispatch[method](...args)
|
|
3
|
-
.then(res => res.data)
|
|
2
|
+
const dispatchReturnData = (method) => (...args) => client.dispatch[method](...args)
|
|
3
|
+
.then((res) => res.data)
|
|
4
4
|
|
|
5
5
|
const withEmail = (method, path, email) => {
|
|
6
6
|
if (typeof email === 'string') {
|
|
@@ -8,11 +8,11 @@ const withClient = (client) => {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
if (typeof email === 'object' && typeof email.email === 'string') {
|
|
11
|
-
return dispatchReturnData(method)(path,
|
|
12
|
-
|
|
13
|
-
email,
|
|
14
|
-
|
|
15
|
-
)
|
|
11
|
+
return dispatchReturnData(method)(path, {
|
|
12
|
+
|
|
13
|
+
...email,
|
|
14
|
+
email: email.email.toLowerCase(),
|
|
15
|
+
})
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
return Promise.reject(new Error('Request is missing required email parameter.'))
|
package/lib/rejoiner.js
CHANGED
|
@@ -5,26 +5,29 @@ const path = require('path')
|
|
|
5
5
|
const merge = require('lodash.merge')
|
|
6
6
|
|
|
7
7
|
const {
|
|
8
|
-
|
|
8
|
+
DEFAULT_API_VERSION,
|
|
9
9
|
REJOINER_API_KEY,
|
|
10
|
+
REJOINER_BASE_URL,
|
|
10
11
|
REJOINER_SITE_ID,
|
|
11
12
|
REJOINER_WEBHOOK_SECRET,
|
|
12
|
-
|
|
13
|
+
VERSION,
|
|
13
14
|
} = require('./config')
|
|
14
15
|
|
|
15
16
|
function Rejoiner2(options) {
|
|
16
17
|
const opts = merge({}, options)
|
|
17
18
|
|
|
19
|
+
this.baseURL = opts.baseURL || REJOINER_BASE_URL
|
|
20
|
+
this.apiVersion = opts.apiVersion || DEFAULT_API_VERSION
|
|
21
|
+
|
|
18
22
|
this.siteId = opts.siteId || REJOINER_SITE_ID
|
|
19
23
|
this.apiKey = opts.apiKey || REJOINER_API_KEY
|
|
20
24
|
this.webhookSecret = opts.webhookSecret || REJOINER_WEBHOOK_SECRET
|
|
21
|
-
this.baseURL = opts.baseURL || REJOINER_BASE_URL
|
|
22
25
|
|
|
23
26
|
if (!this.siteId) throw new Error('Site ID must be configured')
|
|
24
27
|
if (!this.apiKey) throw new Error('API Key must be configured')
|
|
25
28
|
|
|
26
29
|
this.dispatch = axios.create({
|
|
27
|
-
baseURL: `${this.baseURL}/${this.siteId}`,
|
|
30
|
+
baseURL: `${this.baseURL}/v${this.apiVersion}/${this.siteId}`,
|
|
28
31
|
headers: {
|
|
29
32
|
Authorization: `Rejoiner ${this.apiKey}`,
|
|
30
33
|
'User-Agent': `rejoiner2-node/v${VERSION}`,
|
|
@@ -32,7 +35,7 @@ function Rejoiner2(options) {
|
|
|
32
35
|
})
|
|
33
36
|
|
|
34
37
|
fs.readdirSync(path.join(__dirname, 'endpoints'))
|
|
35
|
-
.filter(file => file.indexOf('.') !== 0)
|
|
38
|
+
.filter((file) => file.indexOf('.') !== 0)
|
|
36
39
|
.forEach((file) => {
|
|
37
40
|
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
38
41
|
const endpoint = require(path.join(__dirname, 'endpoints', file))(this)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rejoiner",
|
|
3
3
|
"description": "Rejoiner REST API client wrapper for Node.js",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.11.0",
|
|
5
5
|
"main": "lib/rejoiner.js",
|
|
6
6
|
"author": "Sascha Bratton <sascha@brattonbratton.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "eslint lib --ext .js",
|
|
22
|
-
"test": "
|
|
23
|
-
"precommit": "
|
|
24
|
-
"prepush": "
|
|
22
|
+
"test": "npm run lint",
|
|
23
|
+
"precommit": "npm run test",
|
|
24
|
+
"prepush": "npm run test"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"axios": ">=0.18.1",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"lodash.merge": "^4.6.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"eslint": "^
|
|
33
|
-
"eslint-config-airbnb-base": "^
|
|
32
|
+
"eslint": "^8.16.0",
|
|
33
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
34
34
|
"eslint-plugin-import": "^2.17.2",
|
|
35
|
-
"husky": "^0.
|
|
35
|
+
"husky": "^8.0.1"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=8.3.0"
|