rejoiner 2.10.3 → 2.11.1
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 +22 -2
- package/lib/rejoiner.js +7 -4
- package/package.json +1 -1
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
|
}
|
|
@@ -14,8 +14,28 @@ const customerEndpoint = (client) => {
|
|
|
14
14
|
cancel: (email) => postEmail(`${endpoint}/cancel/`, email),
|
|
15
15
|
unsubscribe: (email) => postEmail(`${endpoint}/unsubscribe/`, email),
|
|
16
16
|
optIn: (email) => postEmail(`${endpoint}/opt_in/`, email),
|
|
17
|
-
get: (email) =>
|
|
18
|
-
|
|
17
|
+
get: (email) => {
|
|
18
|
+
switch (client.apiVersion) {
|
|
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.apiVersion}`)
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
update: (data) => {
|
|
30
|
+
switch (client.apiVersion) {
|
|
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.apiVersion}`)
|
|
37
|
+
}
|
|
38
|
+
},
|
|
19
39
|
}
|
|
20
40
|
}
|
|
21
41
|
|
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}`,
|
package/package.json
CHANGED