@engage_so/core 1.1.0 → 1.3.4
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/index.js +22 -10
- package/package.json +4 -3
package/index.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
const fetch = require('cross-fetch')
|
2
|
+
const Buffer = require('buffer/').Buffer
|
2
3
|
const EngageError = require('./error')
|
3
4
|
const root = 'https://api.engage.so'
|
4
5
|
if (typeof btoa === 'undefined') {
|
@@ -12,7 +13,7 @@ const options = {
|
|
12
13
|
secret: ''
|
13
14
|
}
|
14
15
|
|
15
|
-
async function
|
16
|
+
async function _request (url, params, method) {
|
16
17
|
try {
|
17
18
|
const response = await fetch(url, {
|
18
19
|
method,
|
@@ -37,6 +38,12 @@ async function request (url, params, method) {
|
|
37
38
|
}
|
38
39
|
}
|
39
40
|
|
41
|
+
// Alias of _request method
|
42
|
+
// Same with _request for now but can later have modifications
|
43
|
+
const request = (url, params, method) => {
|
44
|
+
return _request(`${root}${url}`, params, method)
|
45
|
+
}
|
46
|
+
|
40
47
|
const init = (o) => {
|
41
48
|
if (!o) {
|
42
49
|
throw new EngageError('You need to pass in your API key')
|
@@ -59,23 +66,27 @@ const init = (o) => {
|
|
59
66
|
|
60
67
|
const identify = async (o) => {
|
61
68
|
if (!o) {
|
62
|
-
throw new EngageError('You need to pass an object with at least an id and email')
|
69
|
+
throw new EngageError('You need to pass an object with at least an id and email.')
|
63
70
|
}
|
64
71
|
if (!o.id) {
|
65
|
-
throw new EngageError('ID missing')
|
72
|
+
throw new EngageError('ID missing.')
|
66
73
|
}
|
67
|
-
if (
|
68
|
-
throw new EngageError('Email
|
74
|
+
if (o.email && !/^\S+@\S+$/.test(o.email)) {
|
75
|
+
throw new EngageError('Email invalid.')
|
69
76
|
}
|
70
77
|
const allowed = ['id', 'email', 'number', 'created_at', 'device_token', 'device_platform', 'first_name', 'last_name']
|
71
|
-
const params = {
|
78
|
+
const params = {
|
79
|
+
meta: {}
|
80
|
+
}
|
72
81
|
Object.keys(o).map(k => {
|
73
82
|
if (allowed.indexOf(k) !== -1) {
|
74
83
|
params[k] = o[k]
|
84
|
+
} else {
|
85
|
+
params.meta[k] = o[k]
|
75
86
|
}
|
76
87
|
})
|
77
88
|
|
78
|
-
return
|
89
|
+
return _request(`${root}/users/${o.id}`, params, 'PUT')
|
79
90
|
}
|
80
91
|
|
81
92
|
const addAttribute = async (uid, data) => {
|
@@ -98,7 +109,7 @@ const addAttribute = async (uid, data) => {
|
|
98
109
|
}
|
99
110
|
})
|
100
111
|
|
101
|
-
return
|
112
|
+
return _request(`${root}/users/${uid}`, params, 'PUT')
|
102
113
|
}
|
103
114
|
|
104
115
|
const track = async (uid, data) => {
|
@@ -119,12 +130,13 @@ const track = async (uid, data) => {
|
|
119
130
|
}
|
120
131
|
}
|
121
132
|
|
122
|
-
return
|
133
|
+
return _request(`${root}/users/${uid}/events`, data, 'POST')
|
123
134
|
}
|
124
135
|
|
125
136
|
module.exports = {
|
126
137
|
init,
|
127
138
|
identify,
|
128
139
|
addAttribute,
|
129
|
-
track
|
140
|
+
track,
|
141
|
+
request
|
130
142
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@engage_so/core",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.4",
|
4
4
|
"description": "Event driven customer segmentation and targeted engagement.",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -12,10 +12,11 @@
|
|
12
12
|
"author": "Engage",
|
13
13
|
"license": "MIT",
|
14
14
|
"dependencies": {
|
15
|
-
"
|
15
|
+
"buffer": "^6.0.3",
|
16
|
+
"cross-fetch": "^3.1.5"
|
16
17
|
},
|
17
18
|
"devDependencies": {
|
18
19
|
"jest": "^26.4.2"
|
19
20
|
},
|
20
|
-
"gitHead": "
|
21
|
+
"gitHead": "b288998ee988a348358f0a39c3747d1049d37dbd"
|
21
22
|
}
|