-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconsts.js
More file actions
50 lines (43 loc) · 1.37 KB
/
consts.js
File metadata and controls
50 lines (43 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const seedrandom = require("seedrandom");
const { logDebug } = require("./loggerApi");
const pluginStatuses = ["on", "off", "obsolete"];
const bearerToken = "Bearer SecretToken";
const basicAuth = "Basic dXNlcjpwYXNz"; // user:pass
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
function formatErrorResponse(message, details = undefined, id = undefined) {
const body = { error: { message: message, details: details }, id };
logDebug("formatErrorResponse:", body);
return body;
}
function getRandomIdBasedOnDay(length = 32) {
var result = "";
var charactersLength = characters.length;
const generator = seedrandom(formatYmd(new Date()));
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(generator() * charactersLength));
}
return result;
}
function getRandomIntBasedOnDay() {
const generator = seedrandom(formatYmd(new Date()));
const randomValue = generator();
return randomValue.toString().replace(".", "");
}
function tomorrow() {
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
return formatYmd(tomorrow);
}
const formatYmd = (date) => date.toISOString().slice(0, 10);
module.exports = {
getRandomIntBasedOnDay,
getRandomIdBasedOnDay,
formatYmd,
tomorrow,
pluginStatuses,
bearerToken,
basicAuth,
formatErrorResponse,
};