@engage_so/core 1.4.0 → 1.5.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/index.js +24 -24
- package/package.json +2 -2
package/index.js
CHANGED
@@ -77,12 +77,12 @@ const identify = async (o) => {
|
|
77
77
|
if (o.email && !/^\S+@\S+$/.test(o.email)) {
|
78
78
|
throw new EngageError('Email invalid.')
|
79
79
|
}
|
80
|
-
const allowed = ['id', 'email', 'number', 'created_at', 'device_token', 'device_platform', 'first_name', 'last_name']
|
80
|
+
const allowed = ['id', 'is_account', 'email', 'number', 'created_at', 'device_token', 'device_platform', 'first_name', 'last_name']
|
81
81
|
const params = {
|
82
82
|
meta: {}
|
83
83
|
}
|
84
84
|
for (const k in o) {
|
85
|
-
if (allowed.
|
85
|
+
if (allowed.includes(k)) {
|
86
86
|
params[k] = o[k]
|
87
87
|
} else {
|
88
88
|
params.meta[k] = o[k]
|
@@ -102,13 +102,13 @@ const addAttribute = async (uid, data) => {
|
|
102
102
|
if (!Object.keys(data).length) {
|
103
103
|
throw new EngageError('Attributes missing.')
|
104
104
|
}
|
105
|
-
const notMeta = ['created_at', 'number', 'device_token', 'device_platform', 'email', 'first_name', 'last_name']
|
105
|
+
const notMeta = ['created_at', 'is_account', 'number', 'device_token', 'device_platform', 'email', 'first_name', 'last_name']
|
106
106
|
const params = { meta: {} }
|
107
107
|
for (const k in data) {
|
108
|
-
if (notMeta.
|
109
|
-
params.meta[k] = data[k]
|
110
|
-
} else {
|
108
|
+
if (notMeta.includes(k)) {
|
111
109
|
params[k] = data[k]
|
110
|
+
} else {
|
111
|
+
params.meta[k] = data[k]
|
112
112
|
}
|
113
113
|
}
|
114
114
|
|
@@ -136,12 +136,12 @@ const track = async (uid, data) => {
|
|
136
136
|
return _request(`${root}/users/${uid}/events`, data, 'POST')
|
137
137
|
}
|
138
138
|
|
139
|
-
const
|
139
|
+
const addToAccount = async (uid, gid, role) => {
|
140
140
|
if (!uid) {
|
141
141
|
throw new EngageError('User id missing.')
|
142
142
|
}
|
143
143
|
if (!gid) {
|
144
|
-
throw new EngageError('
|
144
|
+
throw new EngageError('Account id missing.')
|
145
145
|
}
|
146
146
|
if (role && typeof role !== 'string') {
|
147
147
|
throw new EngageError('Role should be a text.')
|
@@ -152,42 +152,42 @@ const addToGroup = async (uid, gid, role) => {
|
|
152
152
|
if (role) {
|
153
153
|
g.role = role
|
154
154
|
}
|
155
|
-
return _request(`${root}/users/${uid}/
|
155
|
+
return _request(`${root}/users/${uid}/accounts`, { accounts: [g] }, 'POST')
|
156
156
|
}
|
157
|
-
const
|
157
|
+
const removeFromAccount = async (uid, gid) => {
|
158
158
|
if (!uid) {
|
159
159
|
throw new EngageError('User id missing.')
|
160
160
|
}
|
161
161
|
if (!gid) {
|
162
|
-
throw new EngageError('
|
162
|
+
throw new EngageError('Account id missing.')
|
163
163
|
}
|
164
|
-
return _request(`${root}/users/${uid}/
|
164
|
+
return _request(`${root}/users/${uid}/accounts/${gid}`, null, 'DELETE')
|
165
165
|
}
|
166
166
|
|
167
|
-
const
|
167
|
+
const changeAccountRole = async (uid, gid, role) => {
|
168
168
|
if (!uid) {
|
169
169
|
throw new EngageError('User id missing.')
|
170
170
|
}
|
171
171
|
if (!gid) {
|
172
|
-
throw new EngageError('
|
172
|
+
throw new EngageError('Account id missing.')
|
173
173
|
}
|
174
174
|
if (!role) {
|
175
175
|
throw new EngageError('New role missing.')
|
176
176
|
}
|
177
|
-
return _request(`${root}/users/${uid}/
|
177
|
+
return _request(`${root}/users/${uid}/accounts/${gid}`, { role }, 'PUT')
|
178
178
|
}
|
179
179
|
|
180
|
-
const
|
180
|
+
const convertToCustomer = async (uid) => {
|
181
181
|
if (!uid) {
|
182
182
|
throw new EngageError('User id missing.')
|
183
183
|
}
|
184
|
-
return _request(`${root}/users/${uid}/convert`, { type: '
|
184
|
+
return _request(`${root}/users/${uid}/convert`, { type: 'customer' }, 'POST')
|
185
185
|
}
|
186
|
-
const
|
186
|
+
const convertToAccount = async (uid) => {
|
187
187
|
if (!uid) {
|
188
188
|
throw new EngageError('User id missing.')
|
189
189
|
}
|
190
|
-
return _request(`${root}/users/${uid}/convert`, { type: '
|
190
|
+
return _request(`${root}/users/${uid}/convert`, { type: 'account' }, 'POST')
|
191
191
|
}
|
192
192
|
|
193
193
|
module.exports = {
|
@@ -196,9 +196,9 @@ module.exports = {
|
|
196
196
|
addAttribute,
|
197
197
|
track,
|
198
198
|
request,
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
199
|
+
addToAccount,
|
200
|
+
removeFromAccount,
|
201
|
+
changeAccountRole,
|
202
|
+
convertToCustomer,
|
203
|
+
convertToAccount
|
204
204
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@engage_so/core",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.5.0",
|
4
4
|
"description": "Event driven customer segmentation and targeted engagement.",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -18,5 +18,5 @@
|
|
18
18
|
"devDependencies": {
|
19
19
|
"jest": "^26.4.2"
|
20
20
|
},
|
21
|
-
"gitHead": "
|
21
|
+
"gitHead": "16373af376360be8a4e71aeff74c86648d37072a"
|
22
22
|
}
|