@crmcom/self-service-sdk 2.1.2
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/account.js +144 -0
- package/authentication.js +475 -0
- package/communications.js +94 -0
- package/community.js +327 -0
- package/config.js +302 -0
- package/connectx.js +92 -0
- package/contacts.js +1109 -0
- package/dataUtil.js +2186 -0
- package/eventListener.js +41 -0
- package/httpBackOfficeUtil.js +396 -0
- package/httpJCCUtil.js +61 -0
- package/httpUtil.js +863 -0
- package/index.d.ts +527 -0
- package/index.js +24 -0
- package/jcccards.js +112 -0
- package/logger.js +40 -0
- package/mobilepass.js +64 -0
- package/orders.js +732 -0
- package/organisations.js +141 -0
- package/package.json +63 -0
- package/payment.js +338 -0
- package/paymentgateway.js +26 -0
- package/payouts.js +33 -0
- package/resultUtil.js +86 -0
- package/rewards.js +409 -0
- package/servicerequest.js +235 -0
- package/subscriptions.js +406 -0
- package/wallet.js +478 -0
package/subscriptions.js
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { httpUtil } from './httpUtil'
|
|
2
|
+
import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
|
|
3
|
+
import { getData } from '../../utils/common';
|
|
4
|
+
import { logger } from './logger';
|
|
5
|
+
export const subscriptions = {
|
|
6
|
+
getListContactServices,
|
|
7
|
+
updateServices,
|
|
8
|
+
getProductsTier,
|
|
9
|
+
onServiceDelivery,
|
|
10
|
+
onEstimateBilling,
|
|
11
|
+
onUpdateServiceWithBody,
|
|
12
|
+
updateSubscription,
|
|
13
|
+
getServiceRescommendation,
|
|
14
|
+
getSubscriptionAction,
|
|
15
|
+
getListSubscriptions,
|
|
16
|
+
getListContactDevices,
|
|
17
|
+
getListContactSharedDevices,
|
|
18
|
+
updateDevice,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function getListSubscriptions({
|
|
22
|
+
page = 1,
|
|
23
|
+
size = 100,
|
|
24
|
+
include_terms,
|
|
25
|
+
include_billing_info,
|
|
26
|
+
} = {}) {
|
|
27
|
+
try {
|
|
28
|
+
let id = httpUtil.getSession().sub;
|
|
29
|
+
let response = await httpUtil.get({
|
|
30
|
+
resourcePath: "/v2/contacts/" + id + "/subscriptions",
|
|
31
|
+
queryParams: {
|
|
32
|
+
page,
|
|
33
|
+
size,
|
|
34
|
+
include_terms,
|
|
35
|
+
include_billing_info,
|
|
36
|
+
},
|
|
37
|
+
withAccessToken: true,
|
|
38
|
+
});
|
|
39
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
40
|
+
return createCommonResult(response);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
logger.error("Exception getListSubscriptions:", e);
|
|
43
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function getListContactDevices({
|
|
48
|
+
order,
|
|
49
|
+
owned_by_contact,
|
|
50
|
+
page=1,
|
|
51
|
+
search_value,
|
|
52
|
+
serial_number,
|
|
53
|
+
size=20,
|
|
54
|
+
sort,
|
|
55
|
+
include_custom_fields,
|
|
56
|
+
include_subscription,
|
|
57
|
+
include_characteristics
|
|
58
|
+
}={}) {
|
|
59
|
+
try {
|
|
60
|
+
let id = httpUtil.getSession().sub;
|
|
61
|
+
let response = await httpUtil.get({
|
|
62
|
+
resourcePath: "/v2/contacts/" + id + "/devices",
|
|
63
|
+
queryParams: {
|
|
64
|
+
order,
|
|
65
|
+
owned_by_contact,
|
|
66
|
+
page,
|
|
67
|
+
search_value,
|
|
68
|
+
serial_number,
|
|
69
|
+
size,
|
|
70
|
+
sort,
|
|
71
|
+
include_custom_fields,
|
|
72
|
+
include_subscription,
|
|
73
|
+
include_characteristics
|
|
74
|
+
},
|
|
75
|
+
withAccessToken: true,
|
|
76
|
+
logOutIfSessionInvalid: false
|
|
77
|
+
});
|
|
78
|
+
return createCommonResult(response);
|
|
79
|
+
} catch (e) {
|
|
80
|
+
logger.error("Exception addDevice:", e);
|
|
81
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function getListContactSharedDevices({
|
|
86
|
+
order,
|
|
87
|
+
page=1,
|
|
88
|
+
search_value,
|
|
89
|
+
serial_number,
|
|
90
|
+
size=20,
|
|
91
|
+
sort,
|
|
92
|
+
include_total,
|
|
93
|
+
include_custom_fields,
|
|
94
|
+
include_subscription,
|
|
95
|
+
include_characteristics
|
|
96
|
+
}={}) {
|
|
97
|
+
try {
|
|
98
|
+
let id = httpUtil.getSession().sub;
|
|
99
|
+
let response = await httpUtil.get({
|
|
100
|
+
resourcePath: "/v2/contacts/" + id + "/communities/devices",
|
|
101
|
+
queryParams: {
|
|
102
|
+
order,
|
|
103
|
+
page,
|
|
104
|
+
search_value,
|
|
105
|
+
serial_number,
|
|
106
|
+
size,
|
|
107
|
+
sort,
|
|
108
|
+
include_total,
|
|
109
|
+
include_custom_fields,
|
|
110
|
+
include_subscription,
|
|
111
|
+
include_characteristics
|
|
112
|
+
},
|
|
113
|
+
withAccessToken: true,
|
|
114
|
+
logOutIfSessionInvalid: false
|
|
115
|
+
});
|
|
116
|
+
return createCommonResult(response);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
logger.error("Exception addDevice:", e);
|
|
119
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function updateDevice(body = {}, id) {
|
|
124
|
+
try {
|
|
125
|
+
let response = await httpUtil.put({
|
|
126
|
+
resourcePath: "/v2/devices/" + id,
|
|
127
|
+
body: body,
|
|
128
|
+
withAccessToken: true,
|
|
129
|
+
});
|
|
130
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
131
|
+
return createCommonResult(response);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
logger.error("Exception updateServices:", e);
|
|
134
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
async function getListContactServices({
|
|
141
|
+
sort,
|
|
142
|
+
order,
|
|
143
|
+
page = 1,
|
|
144
|
+
size = 20,
|
|
145
|
+
classification,
|
|
146
|
+
include_future_info,
|
|
147
|
+
include_order_info,
|
|
148
|
+
include_subscription = true,
|
|
149
|
+
include_total,
|
|
150
|
+
subscription_id
|
|
151
|
+
} = {}) {
|
|
152
|
+
try {
|
|
153
|
+
let id = httpUtil.getSession().sub;
|
|
154
|
+
let response = await httpUtil.get({
|
|
155
|
+
resourcePath: "/v2/contacts/" + id + "/services",
|
|
156
|
+
queryParams: {
|
|
157
|
+
sort,
|
|
158
|
+
order,
|
|
159
|
+
page,
|
|
160
|
+
size,
|
|
161
|
+
classification,
|
|
162
|
+
include_future_info,
|
|
163
|
+
include_order_info,
|
|
164
|
+
include_subscription,
|
|
165
|
+
include_total,
|
|
166
|
+
subscription_id
|
|
167
|
+
},
|
|
168
|
+
withAccessToken: true,
|
|
169
|
+
});
|
|
170
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
171
|
+
return createCommonResult(response);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
logger.error("Exception getListContactServices:", e);
|
|
174
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function updateServices({
|
|
179
|
+
action,
|
|
180
|
+
category_id,
|
|
181
|
+
scheduled_date,
|
|
182
|
+
use_proposed_date,
|
|
183
|
+
number_of_days,
|
|
184
|
+
quantity,
|
|
185
|
+
renewal_opt_in,
|
|
186
|
+
price_terms_id,
|
|
187
|
+
extend_contract,
|
|
188
|
+
change_to_service,
|
|
189
|
+
components,
|
|
190
|
+
trial_end_date,
|
|
191
|
+
enabled_devices
|
|
192
|
+
} = {}, id) {
|
|
193
|
+
try {
|
|
194
|
+
let response = await httpUtil.post({
|
|
195
|
+
resourcePath: "/v2/services/" + id,
|
|
196
|
+
body: {
|
|
197
|
+
action,
|
|
198
|
+
category_id,
|
|
199
|
+
scheduled_date,
|
|
200
|
+
use_proposed_date,
|
|
201
|
+
number_of_days,
|
|
202
|
+
quantity,
|
|
203
|
+
renewal_opt_in,
|
|
204
|
+
price_terms_id,
|
|
205
|
+
extend_contract,
|
|
206
|
+
change_to_service,
|
|
207
|
+
components,
|
|
208
|
+
trial_end_date,
|
|
209
|
+
enabled_devices
|
|
210
|
+
},
|
|
211
|
+
withAccessToken: true,
|
|
212
|
+
});
|
|
213
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
214
|
+
return createCommonResult(response);
|
|
215
|
+
} catch (e) {
|
|
216
|
+
logger.error("Exception updateServices:", e);
|
|
217
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function getProductsTier({
|
|
222
|
+
prodId,
|
|
223
|
+
change_type,
|
|
224
|
+
page = 1,
|
|
225
|
+
size = 10,
|
|
226
|
+
contact_id,
|
|
227
|
+
}) {
|
|
228
|
+
try {
|
|
229
|
+
//console.log('API: ', contact)
|
|
230
|
+
if (!contact_id) contact_id = await httpUtil.getSession().sub;
|
|
231
|
+
let response = await httpUtil.get({
|
|
232
|
+
resourcePath: '/v2/products/' + prodId + '/tiering',
|
|
233
|
+
withAccessToken: true,
|
|
234
|
+
queryParams: {
|
|
235
|
+
page,
|
|
236
|
+
size,
|
|
237
|
+
change_type,
|
|
238
|
+
contact_id,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
242
|
+
return createCommonResult(response);
|
|
243
|
+
} catch (e) {
|
|
244
|
+
logger.error('Exception getProductsTier:', e);
|
|
245
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async function onServiceDelivery({
|
|
250
|
+
action,
|
|
251
|
+
services_to_change,
|
|
252
|
+
subscription_id = null,
|
|
253
|
+
}) {
|
|
254
|
+
try {
|
|
255
|
+
let id = httpUtil.getSession().sub;
|
|
256
|
+
let response = await httpUtil.post({
|
|
257
|
+
resourcePath: "/v2/estimates/service_delivery",
|
|
258
|
+
body: {
|
|
259
|
+
action: action,
|
|
260
|
+
services_to_change: services_to_change,
|
|
261
|
+
contact_id: id,
|
|
262
|
+
subscription_id: subscription_id,
|
|
263
|
+
},
|
|
264
|
+
withAccessToken: true,
|
|
265
|
+
});
|
|
266
|
+
if (response.code == "OK")
|
|
267
|
+
return createResult(ErrorCodes.OK, response.data);
|
|
268
|
+
else {
|
|
269
|
+
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
270
|
+
}
|
|
271
|
+
} catch (e) {
|
|
272
|
+
logger.error("Exception onServiceDelivery:", e);
|
|
273
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async function onEstimateBilling({
|
|
278
|
+
account_id,
|
|
279
|
+
upcoming_billing_cycles = 1,
|
|
280
|
+
subscription_id,
|
|
281
|
+
}) {
|
|
282
|
+
try {
|
|
283
|
+
let id = httpUtil.getSession().sub;
|
|
284
|
+
let response = await httpUtil.post({
|
|
285
|
+
resourcePath: "/v2/estimates/billing",
|
|
286
|
+
body: {
|
|
287
|
+
contact_id: id,
|
|
288
|
+
account_id: account_id,
|
|
289
|
+
subscription_id: subscription_id,
|
|
290
|
+
upcoming_billing_cycles : upcoming_billing_cycles
|
|
291
|
+
},
|
|
292
|
+
withAccessToken: true,
|
|
293
|
+
});
|
|
294
|
+
if (response.code == "OK")
|
|
295
|
+
return createResult(ErrorCodes.OK, response.data);
|
|
296
|
+
else {
|
|
297
|
+
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
298
|
+
}
|
|
299
|
+
} catch (e) {
|
|
300
|
+
logger.error("Exception onServiceDelivery:", e);
|
|
301
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
async function onUpdateServiceWithBody(service_id, body) {
|
|
307
|
+
try {
|
|
308
|
+
let response = await httpUtil.put({
|
|
309
|
+
resourcePath: "/v2/services/" + service_id,
|
|
310
|
+
body: body,
|
|
311
|
+
withAccessToken: false,
|
|
312
|
+
});
|
|
313
|
+
if (response.code == "OK")
|
|
314
|
+
return createResult(ErrorCodes.OK, response.data);
|
|
315
|
+
else {
|
|
316
|
+
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
317
|
+
}
|
|
318
|
+
} catch (e) {
|
|
319
|
+
logger.error("Exception onUpdateServiceWithBody:", e);
|
|
320
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async function updateSubscription({
|
|
325
|
+
action,
|
|
326
|
+
payment_method_id,
|
|
327
|
+
billing_day,
|
|
328
|
+
funding_source,
|
|
329
|
+
} = {}, id) {
|
|
330
|
+
try {
|
|
331
|
+
let response = await httpUtil.put({
|
|
332
|
+
resourcePath: "/v2/subscriptions/" + id,
|
|
333
|
+
body: {
|
|
334
|
+
action,
|
|
335
|
+
payment_method_id,
|
|
336
|
+
billing_day,
|
|
337
|
+
funding_source,
|
|
338
|
+
},
|
|
339
|
+
withAccessToken: true,
|
|
340
|
+
});
|
|
341
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
342
|
+
return createCommonResult(response);
|
|
343
|
+
} catch (e) {
|
|
344
|
+
logger.error("Exception updateSubscription:", e);
|
|
345
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function getServiceRescommendation({
|
|
350
|
+
account_id,
|
|
351
|
+
contact_id,
|
|
352
|
+
include_components,
|
|
353
|
+
include_creatives,
|
|
354
|
+
include_total,
|
|
355
|
+
order,
|
|
356
|
+
organisation_id,
|
|
357
|
+
page,
|
|
358
|
+
service_id,
|
|
359
|
+
size = 10,
|
|
360
|
+
sort,
|
|
361
|
+
subscription_id
|
|
362
|
+
}) {
|
|
363
|
+
try {
|
|
364
|
+
//console.log('API: ', contact)
|
|
365
|
+
if (!contact_id) contact_id = await httpUtil.getSession().sub;
|
|
366
|
+
let response = await httpUtil.get({
|
|
367
|
+
resourcePath: '/v2/services/recommendation',
|
|
368
|
+
withAccessToken: true,
|
|
369
|
+
queryParams: {
|
|
370
|
+
account_id,
|
|
371
|
+
contact_id,
|
|
372
|
+
include_components,
|
|
373
|
+
include_creatives,
|
|
374
|
+
include_total,
|
|
375
|
+
order,
|
|
376
|
+
organisation_id,
|
|
377
|
+
page,
|
|
378
|
+
service_id,
|
|
379
|
+
size,
|
|
380
|
+
sort,
|
|
381
|
+
subscription_id,
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
385
|
+
return createCommonResult(response);
|
|
386
|
+
} catch (e) {
|
|
387
|
+
logger.error('Exception getServiceRescommendation:', e);
|
|
388
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async function getSubscriptionAction({
|
|
393
|
+
action_id,
|
|
394
|
+
}) {
|
|
395
|
+
try {
|
|
396
|
+
let response = await httpUtil.get({
|
|
397
|
+
resourcePath: '/v2/subscriptions/actions/' + action_id,
|
|
398
|
+
withAccessToken: true,
|
|
399
|
+
});
|
|
400
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
401
|
+
return createCommonResult(response);
|
|
402
|
+
} catch (e) {
|
|
403
|
+
logger.error('Exception getSubscriptionAction:', e);
|
|
404
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
405
|
+
}
|
|
406
|
+
}
|