comprodls-sdk 2.22.1 → 2.23.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/comprodls.js CHANGED
@@ -45,6 +45,7 @@ var integrations = require('./services/integrations');
45
45
  var validations = require('./token/validations');
46
46
  var drive = require('./services/drive');
47
47
  var taxonomy = require('./services/taxonomy');
48
+ var rules = require('./services/rules');
48
49
 
49
50
 
50
51
  /*********************************
@@ -146,3 +147,4 @@ comproDLS.prototype.Workflows = workflows;
146
147
  comproDLS.prototype.Integrations = integrations;
147
148
  comproDLS.prototype.Drive = drive;
148
149
  comproDLS.prototype.Taxonomy = taxonomy;
150
+ comproDLS.prototype.Rules = rules;
@@ -316,3 +316,10 @@ exports.TAXONOMY_API_URLS = {
316
316
  associateTagsWithEntity: '/org/{orgId}/taxonomy/associate-tags-with-entity',
317
317
  tags: '/org/{orgId}/context/{context}/taxonomy/{taxonomyId}/tags'
318
318
  };
319
+
320
+ exports.RULES_API_URLS = {
321
+ rules: '/org/{orgId}/context/{context}/rule_type/{ruleType}/rules',
322
+ particularRule: '/org/{orgId}/context/{context}/rule_type/{ruleType}/rules/{ruleId}',
323
+ updateRuleDisplay: '/org/{orgId}/context/{context}/rule_type/{ruleType}/rules/{ruleId}/update-rule-display',
324
+ getUserRule: '/org/{orgId}/context/{context}/rule_type/{ruleType}/users/{userId}/rules'
325
+ };
@@ -0,0 +1,465 @@
1
+ /*************************************************************************
2
+ *
3
+ * COMPRO CONFIDENTIAL
4
+ * __________________
5
+ *
6
+ * [2015] - [2020] Compro Technologies Private Limited
7
+ * All Rights Reserved.
8
+ *
9
+ * NOTICE: All information contained herein is, and remains
10
+ * the property of Compro Technologies Private Limited. The
11
+ * intellectual and technical concepts contained herein are
12
+ * proprietary to Compro Technologies Private Limited and may
13
+ * be covered by U.S. and Foreign Patents, patents in process,
14
+ * and are protected by trade secret or copyright law.
15
+ *
16
+ * Dissemination of this information or reproduction of this material
17
+ * is strictly forbidden unless prior written permission is obtained
18
+ * from Compro Technologies Pvt. Ltd..
19
+ ***************************************************************************/
20
+
21
+ /***********************************************************
22
+ * comproDLS SDK Rules API Adaptor
23
+ * Functions for calling Rules API.
24
+ ************************************************************/
25
+
26
+ var q = require('q');
27
+ var request = require('superagent');
28
+ var helpers = require('../../helpers');
29
+
30
+ var DLSError = helpers.errors.DLSError;
31
+
32
+ /*********************************
33
+ * Setting Up Module Entry Point
34
+ **********************************/
35
+ module.exports = rules;
36
+ //Rules Adaptor Contsructor
37
+ function rules() {
38
+ return {
39
+ getRules: getRules.bind(this),
40
+ getParticularRule: getParticularRule.bind(this),
41
+ getUserRule: getUserRule.bind(this),
42
+ updateRuleDisplay: updateRuleDisplay.bind(this),
43
+ createRule: createRule.bind(this),
44
+ updateRule: updateRule.bind(this),
45
+ deleteRule: deleteRule.bind(this)
46
+ };
47
+ }
48
+
49
+ /*********************************
50
+ * Public Function definitions
51
+ **********************************/
52
+
53
+ /**
54
+ * options = {
55
+ * context: '', // Mandatory
56
+ * ruleType: '', // Mandatory
57
+ * cursor: '' // Optional
58
+ * }
59
+ */
60
+ function getRules(options) {
61
+ var self = this;
62
+
63
+ //Initializing promise
64
+ var dfd = q.defer();
65
+
66
+ //Validations
67
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
68
+ if (err) {
69
+ dfd.reject(err);
70
+ } else {
71
+ if (options && options.context && options.ruleType) {
72
+ //Passed all validations, Contruct API url
73
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.rules;
74
+ url = helpers.api.constructAPIUrl(url, {
75
+ orgId: self.orgId,
76
+ context: encodeURIComponent(options.context),
77
+ ruleType: options.ruleType
78
+ });
79
+
80
+ //Setup request with URL and Params
81
+ var queryParam = { cursor: options.cursor };
82
+
83
+ var requestAPI = request.get(url)
84
+ .set('Content-Type', 'application/json')
85
+ .set('Accept', 'application/json')
86
+ .query(queryParam);
87
+
88
+ if (self.traceid) {
89
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
90
+ }
91
+
92
+ //Setup token in Authorization header
93
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
94
+
95
+ requestAPI.end(function (err, response) {
96
+ if (err) {
97
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
98
+ dfd.reject(err);
99
+ } else {
100
+ dfd.resolve(response.body);
101
+ }
102
+ });
103
+ } else {
104
+ err = {};
105
+ err.message = err.description = 'context or ruleType not found in request options.';
106
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
107
+ dfd.reject(err);
108
+ }
109
+ }
110
+ return dfd.promise;
111
+ }
112
+
113
+ /**
114
+ * options = {
115
+ * context: '', // Mandatory
116
+ * ruleType: '', // Mandatory
117
+ * ruleId: '' // Mandatory
118
+ * }
119
+ */
120
+ function getParticularRule(options) {
121
+ var self = this;
122
+
123
+ //Initializing promise
124
+ var dfd = q.defer();
125
+
126
+ //Validations
127
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
128
+ if (err) {
129
+ dfd.reject(err);
130
+ } else {
131
+ if (options && options.context && options.ruleType && options.ruleId) {
132
+ //Passed all validations, Contruct API url
133
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
134
+ url = helpers.api.constructAPIUrl(url, {
135
+ orgId: self.orgId,
136
+ context: encodeURIComponent(options.context),
137
+ ruleType: options.ruleType,
138
+ ruleId: options.ruleId
139
+ });
140
+
141
+ //Setup request with URL and Params
142
+ var requestAPI = request.get(url);
143
+
144
+ if (self.traceid) {
145
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
146
+ }
147
+
148
+ //Setup token in Authorization header
149
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
150
+
151
+ requestAPI.end(function (err, response) {
152
+ if (err) {
153
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
154
+ dfd.reject(err);
155
+ } else {
156
+ dfd.resolve(response.body);
157
+ }
158
+ });
159
+ } else {
160
+ err = {};
161
+ err.message = err.description = 'context or ruleType or ruleId not found' +
162
+ ' in request options.';
163
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
164
+ dfd.reject(err);
165
+ }
166
+ }
167
+ return dfd.promise;
168
+ }
169
+
170
+ /**
171
+ * options = {
172
+ * orgId: '', // Mandatory
173
+ * context: '', // Mandatory
174
+ * ruleType: '', // Mandatory
175
+ * userId: '', // Mandatory
176
+ * mergeGlobalRules:'' // Optional
177
+ * }
178
+ */
179
+ function getUserRule(options) {
180
+ var self = this;
181
+
182
+ //Initializing promise
183
+ var dfd = q.defer();
184
+
185
+ if (options && options.orgId && options.context && options.ruleType && options.userId) {
186
+ //Passed all validations, Contruct API url
187
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.getUserRule;
188
+ url = helpers.api.constructAPIUrl(url, {
189
+ orgId: self.orgId,
190
+ context: encodeURIComponent(options.context),
191
+ ruleType: options.ruleType,
192
+ userId: options.userId
193
+ });
194
+
195
+ //Setup request with URL and Params
196
+ var queryParam = { mergeGlobalRules: options.mergeGlobalRules };
197
+
198
+ var requestAPI = request.get(url)
199
+ .set('Content-Type', 'application/json')
200
+ .set('Accept', 'application/json')
201
+ .query(queryParam);
202
+
203
+ if (self.traceid) {
204
+ requestAPI.set('X-Amzn-Trace-Id', self.traceid);
205
+ }
206
+
207
+ //Setup token in Authorization header
208
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
209
+
210
+ requestAPI.end(function (err, response) {
211
+ if (err) {
212
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, err);
213
+ dfd.reject(err);
214
+ } else {
215
+ dfd.resolve(response.body);
216
+ }
217
+ });
218
+ } else {
219
+ var err = {};
220
+ err.message = err.description = 'Mandatory params - orgId or context or ruleType or userId ' +
221
+ 'not found in request options.';
222
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
223
+ dfd.reject(err);
224
+ }
225
+
226
+ return dfd.promise;
227
+ }
228
+
229
+ /**
230
+ * options = {
231
+ * context: '', // Mandatory
232
+ * ruleType: '', // Mandatory
233
+ * ruleId: '', // Mandatory
234
+ * body: {
235
+ * rule_display: '' // Mandatory
236
+ * }
237
+ * }
238
+ */
239
+ function updateRuleDisplay(options) {
240
+ var self = this;
241
+ // Initializing promise
242
+ var dfd = q.defer();
243
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
244
+ if (err) { dfd.reject(err); }
245
+ else {
246
+ if (options && options.context && options.ruleType && options.ruleId &&
247
+ options.body && options.body.rule_display) {
248
+ // Passed all validations, Contruct API url
249
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.updateRuleDisplay;
250
+ url = helpers.api.constructAPIUrl(url, {
251
+ orgId: self.orgId,
252
+ context: encodeURIComponent(options.context),
253
+ ruleType: options.ruleType,
254
+ ruleId: options.ruleId
255
+ });
256
+
257
+ // Setup request with URL and Params
258
+ var requestAPI = request.put(url)
259
+ .set('Content-Type', 'application/json')
260
+ .set('Accept', 'application/json')
261
+ .send(options.body);
262
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
263
+
264
+ //Setup token in Authorization header
265
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
266
+
267
+ requestAPI.end(function (error, response) {
268
+ if (error) {
269
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
270
+ dfd.reject(err);
271
+ }
272
+ else { dfd.resolve(response.body); }
273
+ });
274
+ } else {
275
+ err = {};
276
+ err.message = err.description = 'Mandatory params - context or ruleType or ruleId ' +
277
+ 'or body.rule_display not found in request options.';
278
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
279
+ dfd.reject(err);
280
+ }
281
+ }
282
+ return dfd.promise;
283
+ }
284
+
285
+ /**
286
+ * options = {
287
+ * context: '', // Mandatory
288
+ * ruleType: '', // Mandatory
289
+ * body: {
290
+ * ruleid: '', // Mandatory
291
+ * scope: '', // Mandatory
292
+ * entities: [ // Min. length 1
293
+ * {
294
+ * id:'', // eg. item code
295
+ * type:'' // eg. item/folder/product
296
+ * },
297
+ * ...],
298
+ * user: ['extuserid1','extuserid2', ...],
299
+ * rule_data_individual: {},
300
+ * rule_data_common: {},
301
+ * rule_display: {}
302
+ * }
303
+ * }
304
+ */
305
+ function createRule(options) {
306
+ var self = this;
307
+ // Initializing promise
308
+ var dfd = q.defer();
309
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
310
+ if (err) { dfd.reject(err); }
311
+ else {
312
+ if (options && options.context && options.ruleType && options.body) {
313
+ // Passed all validations, Contruct API url
314
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.rules;
315
+ url = helpers.api.constructAPIUrl(url, {
316
+ orgId: self.orgId,
317
+ context: encodeURIComponent(options.context),
318
+ ruleType: options.ruleType
319
+ });
320
+
321
+ // Setup request with URL and Params
322
+ var requestAPI = request.post(url)
323
+ .set('Content-Type', 'application/json')
324
+ .set('Accept', 'application/json')
325
+ .send(options.body);
326
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
327
+
328
+ //Setup token in Authorization header
329
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
330
+
331
+ requestAPI.end(function (error, response) {
332
+ if (error) {
333
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
334
+ dfd.reject(err);
335
+ }
336
+ else { dfd.resolve(response.body); }
337
+ });
338
+ } else {
339
+ err = {};
340
+ err.message = err.description = 'Mandatory params - context or ruleType or body' +
341
+ ' not found in request options.';
342
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
343
+ dfd.reject(err);
344
+ }
345
+ }
346
+ return dfd.promise;
347
+ }
348
+
349
+ /**
350
+ * options = {
351
+ * context: '', // Mandatory
352
+ * ruleType: '', // Mandatory
353
+ * ruleId: '', // Mandatory
354
+ * body: {
355
+ * scope: '', // Mandatory
356
+ * entities: [ // Min. length 1
357
+ * {
358
+ * id:'', // eg. item code
359
+ * type:'' // eg. item/folder/product
360
+ * },
361
+ * ...],
362
+ * user: ['extuserid1','extuserid2', ...],
363
+ * rule_data_individual: {}, // Optional
364
+ * rule_data_common: {} // Optional
365
+ * }
366
+ * }
367
+ */
368
+ function updateRule(options) {
369
+ var self = this;
370
+ // Initializing promise
371
+ var dfd = q.defer();
372
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
373
+ if (err) { dfd.reject(err); }
374
+ else {
375
+ if (options && options.context && options.ruleType && options.ruleId && options.body) {
376
+ // Passed all validations, Contruct API url
377
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
378
+ url = helpers.api.constructAPIUrl(url, {
379
+ orgId: self.orgId,
380
+ context: encodeURIComponent(options.context),
381
+ ruleType: options.ruleType,
382
+ ruleId: options.ruleId
383
+ });
384
+
385
+ // Setup request with URL and Params
386
+ var requestAPI = request.put(url)
387
+ .set('Content-Type', 'application/json')
388
+ .set('Accept', 'application/json')
389
+ .send(options.body);
390
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
391
+
392
+ //Setup token in Authorization header
393
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
394
+
395
+ requestAPI.end(function (error, response) {
396
+ if (error) {
397
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
398
+ dfd.reject(err);
399
+ }
400
+ else { dfd.resolve(response.body); }
401
+ });
402
+ } else {
403
+ err = {};
404
+ err.message = err.description = 'Mandatory params - context or ruleType or ruleId or body ' +
405
+ 'not found in request options.';
406
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
407
+ dfd.reject(err);
408
+ }
409
+ }
410
+ return dfd.promise;
411
+ }
412
+
413
+ /**
414
+ * options = {
415
+ * context: '', // Mandatory
416
+ * ruleType: '', // Mandatory
417
+ * ruleId: '' // Mandatory
418
+ * }
419
+ */
420
+ function deleteRule(options) {
421
+ var self = this;
422
+ // Initializing promise
423
+ var dfd = q.defer();
424
+
425
+ var err = helpers.validations.isAuthenticated(self.orgId, self.token);
426
+ if (err) { dfd.reject(err); }
427
+ else {
428
+ if (options && options.context && options.ruleType && options.ruleId) {
429
+ // Passed all validations, Contruct API url
430
+ var url = self.config.DEFAULT_HOSTS.AUTH + self.config.RULES_API_URLS.particularRule;
431
+ url = helpers.api.constructAPIUrl(url, {
432
+ orgId: self.orgId,
433
+ context: encodeURIComponent(options.context),
434
+ ruleType: options.ruleType,
435
+ ruleId: options.ruleId
436
+ });
437
+
438
+ // Setup request with URL and Params
439
+ var requestAPI = request.delete(url);
440
+
441
+ //Setup token in Authorization header
442
+ requestAPI = helpers.api.setupAPIToken(requestAPI, self.token);
443
+ if (self.traceid) { requestAPI.set('X-Amzn-Trace-Id', self.traceid); }
444
+
445
+ requestAPI.end(function (error, response) {
446
+ if (error) {
447
+ err = {};
448
+ err = new DLSError(helpers.errors.ERROR_TYPES.API_ERROR, error);
449
+ dfd.reject(err);
450
+ }
451
+ else {
452
+ dfd.resolve(response.body);
453
+ }
454
+ });
455
+ }
456
+ else {
457
+ err = {};
458
+ err.message = err.description = 'Mandatory params - context or ruleType or ruleId not found' +
459
+ ' in request options.';
460
+ err = new DLSError(helpers.errors.ERROR_TYPES.SDK_ERROR, err);
461
+ dfd.reject(err);
462
+ }
463
+ }
464
+ return dfd.promise;
465
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "comprodls-sdk",
3
3
  "description": "comproDLS SDK for JavaScript",
4
- "version": "2.22.1",
4
+ "version": "2.23.0",
5
5
  "author": {
6
6
  "name": "Compro Technologies Private Limited",
7
7
  "url": "http://www.comprotechnologies.com/"
@@ -1,24 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
-
8
- {
9
- "type": "node",
10
- "request": "launch",
11
- "name": "Launch Program",
12
- "program": "${file}",
13
- "outputCapture": "std",
14
- "env": {
15
-
16
- "REALM": "global",
17
- "ENVIRONMENT": "development",
18
- "ACCOUNT": "compro",
19
- "REALM_DYNAMODB_DATA_ACCESS_KEY_ID": "AKIAYIHNXSALTHL6OTF3",
20
- "REALM_DYNAMODB_DATA_SECRET_ACCESS_KEY": "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"
21
- }
22
- }
23
- ]
24
- }