@hivedev/hivesdk 1.0.3 → 1.0.7
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/Common/Constants.js +33 -3
- package/Common/Utility/ConvertEnumerationKeyToTitleCase.js +5 -0
- package/Common/Utility/Delay.js +5 -0
- package/Common/Utility/ExtractIpFromUrl.js +9 -4
- package/Common/Utility/GenerateRandomId.js +6 -0
- package/Common/Utility/GetSha512Hash.js +5 -0
- package/Common/Utility/NormalizeIp.js +9 -0
- package/Common/Utility/Sha256.js +10 -1
- package/Database/DatabaseConnector.js +109 -0
- package/Server/Classes/HiveServerGlobals.js +20 -0
- package/Server/InitServer.js +16 -0
- package/Server/Utility/DecryptDataWithPassword.js +6 -0
- package/Server/Utility/DecryptFileWithPassword.js +6 -0
- package/Server/Utility/EncryptFileWithPassword.js +7 -0
- package/Server/Utility/ExtractConfigurationForService.js +17 -5
- package/Server/Utility/FindService.js +84 -0
- package/Server/Utility/GetAppdataDirectory.js +2 -1
- package/Server/Utility/IsRequestOriginatingFromService.js +48 -49
- package/Server/Utility/LoadConfiguration.js +27 -14
- package/Server/Utility/RegisterService.js +60 -0
- package/Server/Utility/SendMail.js +3 -3
- package/Server/Utility/SetupPassword.js +4 -2
- package/Server/server.js +26 -0
- package/build-server.js +11 -0
- package/dist/server/index.js +2 -11453
- package/hive-server.js +337 -0
- package/package.json +13 -16
- package/Client/Utility/DisableAllButtons.js +0 -4
- package/Client/Utility/GenerateUUID.js +0 -23
- package/Client/Utility/GetDeviceId.js +0 -21
- package/Client/Utility/IsInApp.js +0 -4
- package/Client/Utility/SetupAppUsage.js +0 -65
- package/Common/Utility/GetDirectoryName.js +0 -8
- package/server.js +0 -3
- /package/{client.js → hive-client.js} +0 -0
package/hive-server.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
// Server/Utility/SendMail.js
|
|
2
|
+
import nodemailer from "nodemailer";
|
|
3
|
+
async function sendMail(sender, receiver, subject, html) {
|
|
4
|
+
const transporter = nodemailer.createTransport({
|
|
5
|
+
host: "smtp.gmail.com",
|
|
6
|
+
port: 587,
|
|
7
|
+
secure: false,
|
|
8
|
+
auth: {
|
|
9
|
+
user: "fatbeluuga@gmail.com",
|
|
10
|
+
pass: process.env.SMTP_PASSWORD
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const mailOptions = {
|
|
14
|
+
from: sender,
|
|
15
|
+
to: receiver,
|
|
16
|
+
subject,
|
|
17
|
+
html
|
|
18
|
+
};
|
|
19
|
+
try {
|
|
20
|
+
const info = await transporter.sendMail(mailOptions);
|
|
21
|
+
console.log("Email sent:", info.response);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error("Error:", error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Server/Utility/DecryptFileWithPassword.js
|
|
28
|
+
import { promises as fs } from "fs";
|
|
29
|
+
|
|
30
|
+
// Server/Utility/DecryptDataWithPassword.js
|
|
31
|
+
import crypto from "crypto";
|
|
32
|
+
async function decryptDataWithPassword(data, password) {
|
|
33
|
+
const iv = data.subarray(0, 16);
|
|
34
|
+
const encrypted = data.subarray(16);
|
|
35
|
+
const key = crypto.scryptSync(password, "salt", 32);
|
|
36
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", key, iv);
|
|
37
|
+
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
38
|
+
return decrypted.toString("utf8");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Server/Utility/DecryptFileWithPassword.js
|
|
42
|
+
async function decryptFileWithPassword(fullPath, password) {
|
|
43
|
+
const payload = await fs.readFile(fullPath);
|
|
44
|
+
try {
|
|
45
|
+
return await decryptDataWithPassword(payload, password);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Server/Utility/GetAppdataDirectory.js
|
|
52
|
+
import path from "path";
|
|
53
|
+
import fs2 from "fs";
|
|
54
|
+
|
|
55
|
+
// Common/Constants.js
|
|
56
|
+
var _serviceName = null;
|
|
57
|
+
var serviceNameSet = false;
|
|
58
|
+
var serviceName = new Proxy(
|
|
59
|
+
{},
|
|
60
|
+
{
|
|
61
|
+
get() {
|
|
62
|
+
if (!_serviceName) {
|
|
63
|
+
throw new Error("Service name not set. Call setServiceName() first.");
|
|
64
|
+
}
|
|
65
|
+
return _serviceName;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
function setServiceName(name) {
|
|
70
|
+
if (typeof name !== "string") {
|
|
71
|
+
throw new Error("Service name must be a string.");
|
|
72
|
+
}
|
|
73
|
+
_serviceName = name;
|
|
74
|
+
serviceNameSet = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Server/Utility/GetAppdataDirectory.js
|
|
78
|
+
function getAppDataDirectory() {
|
|
79
|
+
const baseDir = process.env.APPDATA || (process.platform === "darwin" ? path.join(process.env.HOME, "Library", "Application Support") : path.join(process.env.HOME, ".config"));
|
|
80
|
+
const hiveDir = path.join(baseDir, serviceName);
|
|
81
|
+
fs2.mkdirSync(hiveDir, { recursive: true });
|
|
82
|
+
return hiveDir.replace(/\\/g, "/");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Database/DatabaseConnector.js
|
|
86
|
+
import { MongoClient } from "mongodb";
|
|
87
|
+
var DatabaseConnector = class _DatabaseConnector {
|
|
88
|
+
static #databaseUrl = "mongodb://127.0.0.1:27017";
|
|
89
|
+
static #databaseName = "untitled";
|
|
90
|
+
static #username = "";
|
|
91
|
+
static #password = "";
|
|
92
|
+
static #mongoClient = null;
|
|
93
|
+
static #bConfigured = false;
|
|
94
|
+
static databaseObject = null;
|
|
95
|
+
/**
|
|
96
|
+
* Connects to the MongoDB database.
|
|
97
|
+
* If the database configuration is not set, it will call loadConfiguration() to load the configuration.
|
|
98
|
+
* If the database configuration is still not set after calling loadConfiguration(), it will return false.
|
|
99
|
+
* If the MongoClient object is not set, it will create a new MongoClient object with the database URL and credentials.
|
|
100
|
+
* It will then try to connect to the database using the MongoClient object.
|
|
101
|
+
* If the connection is successful, it will set the databaseObject to the database object returned by the MongoClient.
|
|
102
|
+
* If the connection fails, it will log an error message and return false.
|
|
103
|
+
* @returns {boolean} True if the connection is successful, false otherwise.
|
|
104
|
+
*/
|
|
105
|
+
static async connect() {
|
|
106
|
+
if (!_DatabaseConnector.#bConfigured) {
|
|
107
|
+
await loadConfiguration();
|
|
108
|
+
if (!_DatabaseConnector.#bConfigured) {
|
|
109
|
+
console.log("Database configuration is not set! Please provide database credentials first.");
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!_DatabaseConnector.#mongoClient) {
|
|
114
|
+
_DatabaseConnector.#mongoClient = new MongoClient(
|
|
115
|
+
_DatabaseConnector.#databaseUrl,
|
|
116
|
+
{
|
|
117
|
+
auth: { username: _DatabaseConnector.#username, password: _DatabaseConnector.#password }
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
await _DatabaseConnector.#mongoClient.connect();
|
|
123
|
+
_DatabaseConnector.databaseObject = _DatabaseConnector.#mongoClient.db(_DatabaseConnector.#databaseName);
|
|
124
|
+
return true;
|
|
125
|
+
} catch (exception) {
|
|
126
|
+
console.log("Error connecting to database");
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Disconnects from the MongoDB database.
|
|
132
|
+
* If the MongoClient object is not set, it does nothing.
|
|
133
|
+
* If the MongoClient object is set, it closes the connection to the database.
|
|
134
|
+
* It then sets the MongoClient object and the database object to null.
|
|
135
|
+
* Finally, it logs a message to the console indicating that the disconnection was successful.
|
|
136
|
+
*/
|
|
137
|
+
static async disconnect() {
|
|
138
|
+
if (_DatabaseConnector.#mongoClient) {
|
|
139
|
+
await _DatabaseConnector.#mongoClient.close();
|
|
140
|
+
}
|
|
141
|
+
_DatabaseConnector.#mongoClient = null;
|
|
142
|
+
_DatabaseConnector.databaseObject = null;
|
|
143
|
+
console.log("Disconnected from database");
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Sets the database credentials for the DatabaseConnector
|
|
147
|
+
* @param {Object} obj - contains the database host, username, password, and name
|
|
148
|
+
* @param {string} obj.host - The host of the database
|
|
149
|
+
* @param {string} obj.username - The username of the database
|
|
150
|
+
* @param {string} obj.password - The password of the database
|
|
151
|
+
* @param {string} obj.name - The name of the database
|
|
152
|
+
* @throws {Error} - If any of the database credentials are not set
|
|
153
|
+
*/
|
|
154
|
+
static setCredentials({ host, username, password, name }) {
|
|
155
|
+
if (host) _DatabaseConnector.#databaseUrl = "mongodb://" + host + ":27017";
|
|
156
|
+
else throw new Error("Database host not set!");
|
|
157
|
+
if (username) _DatabaseConnector.#username = username;
|
|
158
|
+
else throw new Error("Database username not set!");
|
|
159
|
+
if (password) _DatabaseConnector.#password = password;
|
|
160
|
+
else throw new Error("Database password not set!");
|
|
161
|
+
if (name) _DatabaseConnector.#databaseName = name;
|
|
162
|
+
else throw new Error("Database name not set!");
|
|
163
|
+
_DatabaseConnector.#bConfigured = true;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var DatabaseConnector_default = DatabaseConnector;
|
|
167
|
+
|
|
168
|
+
// Server/Utility/LoadConfiguration.js
|
|
169
|
+
import path2 from "path";
|
|
170
|
+
import fs3 from "fs";
|
|
171
|
+
async function loadConfiguration() {
|
|
172
|
+
let firebaseAdminCredentials = "";
|
|
173
|
+
let databaseCredentials = "";
|
|
174
|
+
let permissions = "";
|
|
175
|
+
let smtpCredentials = "";
|
|
176
|
+
const firebaseAdminCredentialsPath = path2.join(getAppDataDirectory(), "firebase_admin_credentials.dat");
|
|
177
|
+
const databaseCredentialsPath = path2.join(getAppDataDirectory(), "database_credentials.dat");
|
|
178
|
+
const permissionsPath = path2.join(getAppDataDirectory(), "permissions.dat");
|
|
179
|
+
const smtpCredentialsPath = path2.join(getAppDataDirectory(), "smtp_credentials.dat");
|
|
180
|
+
if (fs3.existsSync(firebaseAdminCredentialsPath)) {
|
|
181
|
+
firebaseAdminCredentials = await decryptFileWithPassword(path2.join(getAppDataDirectory(), "firebase_admin_credentials.dat"), process.env.SERVER_PASSWORD);
|
|
182
|
+
}
|
|
183
|
+
if (fs3.existsSync(databaseCredentialsPath)) {
|
|
184
|
+
databaseCredentials = await decryptFileWithPassword(path2.join(getAppDataDirectory(), "database_credentials.dat"), process.env.SERVER_PASSWORD);
|
|
185
|
+
}
|
|
186
|
+
if (fs3.existsSync(permissionsPath)) {
|
|
187
|
+
permissions = await decryptFileWithPassword(path2.join(getAppDataDirectory(), "permissions.dat"), process.env.SERVER_PASSWORD);
|
|
188
|
+
}
|
|
189
|
+
if (fs3.existsSync(smtpCredentialsPath)) {
|
|
190
|
+
smtpCredentials = await decryptFileWithPassword(path2.join(getAppDataDirectory(), "smtp_credentials.dat"), process.env.SERVER_PASSWORD);
|
|
191
|
+
}
|
|
192
|
+
process.env.FIREBASE_ADMIN_CREDENTIALS = firebaseAdminCredentials;
|
|
193
|
+
process.env.DATABASE_CREDENTIALS = databaseCredentials;
|
|
194
|
+
process.env.PERMISSIONS = permissions;
|
|
195
|
+
process.env.SMTP_CREDENTIALS = smtpCredentials;
|
|
196
|
+
try {
|
|
197
|
+
const smtpCredentialsObject = JSON.parse(smtpCredentials);
|
|
198
|
+
process.env.SMTP_PASSWORD = smtpCredentialsObject.password || "";
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.error(e);
|
|
201
|
+
}
|
|
202
|
+
if (databaseCredentials) {
|
|
203
|
+
databaseCredentials = JSON.parse(databaseCredentials);
|
|
204
|
+
const hivePortalDatabaseCredentials = databaseCredentials[serviceName];
|
|
205
|
+
DatabaseConnector_default.setCredentials(
|
|
206
|
+
{
|
|
207
|
+
host: hivePortalDatabaseCredentials.host || "127.0.0.1",
|
|
208
|
+
username: hivePortalDatabaseCredentials.username || "",
|
|
209
|
+
password: hivePortalDatabaseCredentials.password || "",
|
|
210
|
+
name: hivePortalDatabaseCredentials.name || "hive"
|
|
211
|
+
}
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Server/Utility/EncryptFileWithPassword.js
|
|
217
|
+
import { promises as fs4 } from "fs";
|
|
218
|
+
import path3 from "path";
|
|
219
|
+
|
|
220
|
+
// Server/Utility/EncryptDataWithPassword.js
|
|
221
|
+
import crypto2 from "crypto";
|
|
222
|
+
async function encryptDataWithPassword(data, password) {
|
|
223
|
+
const key = crypto2.scryptSync(password, "salt", 32);
|
|
224
|
+
const iv = crypto2.randomBytes(16);
|
|
225
|
+
const cipher = crypto2.createCipheriv("aes-256-cbc", key, iv);
|
|
226
|
+
const encrypted = Buffer.concat([cipher.update(data, "utf8"), cipher.final()]);
|
|
227
|
+
return Buffer.concat([iv, encrypted]);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Server/Utility/EncryptFileWithPassword.js
|
|
231
|
+
async function encryptAndStoreFile(data, fullPath, password) {
|
|
232
|
+
const payload = await encryptDataWithPassword(data, password);
|
|
233
|
+
const dir = path3.dirname(fullPath);
|
|
234
|
+
await fs4.mkdir(dir, { recursive: true });
|
|
235
|
+
await fs4.writeFile(fullPath, payload);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Server/Utility/ExtractConfigurationForService.js
|
|
239
|
+
function extractConfigurationForService() {
|
|
240
|
+
const firebaseAdminCredentials = process.env.FIREBASE_ADMIN_CREDENTIALS ? JSON.parse(process.env.FIREBASE_ADMIN_CREDENTIALS) : null;
|
|
241
|
+
const databaseCredentials = process.env.DATABASE_CREDENTIALS ? JSON.parse(process.env.databaseCredentials) : null;
|
|
242
|
+
const permissions = process.env.PERMISSIONS ? JSON.parse(process.env.PERMISSIONS) : null;
|
|
243
|
+
const smtpCredentials = process.env.SMTP_CREDENTIALS ? JSON.parse(process.env.SMTP_CREDENTIALS) : null;
|
|
244
|
+
const databaseCredentialsForService = databaseCredentials[serviceName] ? databaseCredentials[serviceName] : null;
|
|
245
|
+
return { firebaseAdminCredentials, databaseCredentials: databaseCredentialsForService, permissions, smtpCredentials };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Server/Utility/GetHostIp.js
|
|
249
|
+
import os from "os";
|
|
250
|
+
function getHostIp() {
|
|
251
|
+
const interfaces = os.networkInterfaces();
|
|
252
|
+
for (const devName in interfaces) {
|
|
253
|
+
const iface = interfaces[devName];
|
|
254
|
+
for (let i = 0; i < iface.length; i++) {
|
|
255
|
+
const alias = iface[i];
|
|
256
|
+
if (alias.family === "IPv4" && alias.address !== "127.0.0.1" && !alias.internal) {
|
|
257
|
+
return alias.address;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Server/Utility/PromptPassword.js
|
|
264
|
+
import readline from "readline";
|
|
265
|
+
async function promptPassword(promptText = "Enter password: ") {
|
|
266
|
+
return new Promise((resolve) => {
|
|
267
|
+
const rl = readline.createInterface(
|
|
268
|
+
{
|
|
269
|
+
input: process.stdin,
|
|
270
|
+
output: process.stdout
|
|
271
|
+
}
|
|
272
|
+
);
|
|
273
|
+
rl.question(promptText, (answer) => {
|
|
274
|
+
rl.close();
|
|
275
|
+
process.stdout.write("\n");
|
|
276
|
+
resolve(answer);
|
|
277
|
+
});
|
|
278
|
+
rl._writeToOutput = () => {
|
|
279
|
+
};
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Server/Utility/SetupPassword.js
|
|
284
|
+
import fs5 from "fs";
|
|
285
|
+
import path4 from "path";
|
|
286
|
+
|
|
287
|
+
// Common/Utility/GetSha512Hash.js
|
|
288
|
+
import { createHash } from "crypto";
|
|
289
|
+
function getSha512Hash(text) {
|
|
290
|
+
return createHash("sha512").update(text).digest("hex");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Server/Utility/SetupPassword.js
|
|
294
|
+
async function setupPassword() {
|
|
295
|
+
const appDataDirectory = getAppDataDirectory();
|
|
296
|
+
const passwordFilePath = path4.join(appDataDirectory, "password.dat");
|
|
297
|
+
let correctPassword = null;
|
|
298
|
+
if (!fs5.existsSync(passwordFilePath)) {
|
|
299
|
+
while (true) {
|
|
300
|
+
const password = await promptPassword("Create a password: ");
|
|
301
|
+
const confirm = await promptPassword("Confirm password: ");
|
|
302
|
+
if (password === confirm) {
|
|
303
|
+
correctPassword = password;
|
|
304
|
+
const hashedPassword = getSha512Hash(password);
|
|
305
|
+
await encryptAndStoreFile(hashedPassword, passwordFilePath, password);
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
console.log("Passwords do not match! Try again!");
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
while (true) {
|
|
312
|
+
const password = await promptPassword("Enter your password: ");
|
|
313
|
+
const storedPasswordHash = await decryptFileWithPassword(passwordFilePath, password);
|
|
314
|
+
if (storedPasswordHash !== getSha512Hash(password)) {
|
|
315
|
+
console.log("Incorrect password! Please try again.");
|
|
316
|
+
} else {
|
|
317
|
+
correctPassword = password;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
process.env.SERVER_PASSWORD = correctPassword;
|
|
323
|
+
return correctPassword;
|
|
324
|
+
}
|
|
325
|
+
export {
|
|
326
|
+
decryptFileWithPassword,
|
|
327
|
+
encryptAndStoreFile,
|
|
328
|
+
extractConfigurationForService,
|
|
329
|
+
getAppDataDirectory,
|
|
330
|
+
getHostIp,
|
|
331
|
+
loadConfiguration,
|
|
332
|
+
promptPassword,
|
|
333
|
+
sendMail,
|
|
334
|
+
serviceName,
|
|
335
|
+
setServiceName,
|
|
336
|
+
setupPassword
|
|
337
|
+
};
|
package/package.json
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hivedev/hivesdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
|
-
"scripts":
|
|
8
|
-
{
|
|
7
|
+
"scripts": {
|
|
9
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
9
|
"build": "npm run build:esm && npm run build:cjs",
|
|
11
|
-
"buildserver:esm": "
|
|
12
|
-
"buildserver:cjs": "esbuild server.js --bundle --format=cjs --outfile=
|
|
10
|
+
"buildserver:esm": "node build-server.js",
|
|
11
|
+
"buildserver:cjs": "esbuild server.js --bundle --format=cjs --outfile=hive-server.cjs",
|
|
13
12
|
"buildclient:esm": "esbuild index.js --bundle --format=esm --outfile=dist/index.js"
|
|
14
13
|
},
|
|
15
|
-
"exports":
|
|
16
|
-
|
|
17
|
-
"./client"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"./server"
|
|
22
|
-
|
|
23
|
-
"import": "./dist/server/index.js",
|
|
24
|
-
"require": "./dist/server/index.cjs"
|
|
25
|
-
}
|
|
14
|
+
"exports": {
|
|
15
|
+
"./client": {
|
|
16
|
+
"import": "./dist/client.js"
|
|
17
|
+
},
|
|
18
|
+
"./server": {
|
|
19
|
+
"import": "./dist/server/index.js",
|
|
20
|
+
"require": "./dist/server/index.cjs"
|
|
21
|
+
}
|
|
26
22
|
},
|
|
27
23
|
"keywords": [],
|
|
28
24
|
"author": "Sourav K",
|
|
@@ -36,6 +32,7 @@
|
|
|
36
32
|
"esbuild": "^0.25.10"
|
|
37
33
|
},
|
|
38
34
|
"dependencies": {
|
|
35
|
+
"mongodb": "^6.20.0",
|
|
39
36
|
"nodemailer": "^7.0.6"
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function generateUUID()
|
|
2
|
-
{
|
|
3
|
-
let d = new Date().getTime();
|
|
4
|
-
let d2 = (performance && performance.now && (performance.now() * 1000)) || 0;
|
|
5
|
-
|
|
6
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c)
|
|
7
|
-
{
|
|
8
|
-
let r = Math.random() * 16;
|
|
9
|
-
|
|
10
|
-
if (d > 0)
|
|
11
|
-
{
|
|
12
|
-
r = (d + r) % 16 | 0;
|
|
13
|
-
d = Math.floor(d / 16);
|
|
14
|
-
}
|
|
15
|
-
else
|
|
16
|
-
{
|
|
17
|
-
r = (d2 + r) % 16 | 0;
|
|
18
|
-
d2 = Math.floor(d2 / 16);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return (c === "x" ? r : (r & 0x3 | 0x8)).toString(16);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { sha256 } from "../../Common/Utility/Sha256.js";
|
|
2
|
-
import { generateUUID } from "./GenerateUUID.js";
|
|
3
|
-
|
|
4
|
-
export async function getDeviceId()
|
|
5
|
-
{
|
|
6
|
-
let uuid = localStorage.getItem("deviceId");
|
|
7
|
-
|
|
8
|
-
if (!uuid)
|
|
9
|
-
{
|
|
10
|
-
uuid = generateUUID();
|
|
11
|
-
localStorage.setItem("deviceId", uuid);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
15
|
-
const language = navigator.language;
|
|
16
|
-
const userAgent = navigator.userAgent;
|
|
17
|
-
|
|
18
|
-
const rawId = `${uuid}|${timezone}|${language}|${userAgent}`;
|
|
19
|
-
|
|
20
|
-
return sha256(rawId);
|
|
21
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { appWebViewInteractions } from "../../Common/Enumerations/AppWebViewInteractions.js";
|
|
2
|
-
import { isInApp } from "./IsInApp.js";
|
|
3
|
-
|
|
4
|
-
export function setupAppUsage()
|
|
5
|
-
{
|
|
6
|
-
document.cookie = "usesCookies=true; path=/";
|
|
7
|
-
|
|
8
|
-
if(isInApp())
|
|
9
|
-
{
|
|
10
|
-
window.fallbackOpen = window.open;
|
|
11
|
-
|
|
12
|
-
window.open = (url, name, features)=>
|
|
13
|
-
{
|
|
14
|
-
const iframe = document.createElement("iframe");
|
|
15
|
-
iframe.src = url;
|
|
16
|
-
iframe.style.position = "fixed";
|
|
17
|
-
iframe.style.display = "block";
|
|
18
|
-
iframe.style.height = "100vh";
|
|
19
|
-
iframe.style.width = "100vw";
|
|
20
|
-
iframe.style.top = "0px";
|
|
21
|
-
iframe.style.left = "0px";
|
|
22
|
-
iframe.style.border = "none";
|
|
23
|
-
iframe.style.zIndex = "10000"
|
|
24
|
-
document.body.appendChild(iframe);
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
close: ()=>
|
|
28
|
-
{
|
|
29
|
-
iframe.remove();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
document.querySelectorAll("img").forEach(img =>
|
|
36
|
-
{
|
|
37
|
-
if(img.getAttribute("src") && !img.src.startsWith("http"))
|
|
38
|
-
{
|
|
39
|
-
img.src = new URL(img.getAttribute("src"), window.location.origin).href;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
window.addEventListener("message", (event)=>
|
|
44
|
-
{
|
|
45
|
-
try
|
|
46
|
-
{
|
|
47
|
-
|
|
48
|
-
const messageObject = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
|
|
49
|
-
|
|
50
|
-
switch(messageObject.interaction)
|
|
51
|
-
{
|
|
52
|
-
case appWebViewInteractions.BACK_PRESSED:
|
|
53
|
-
{
|
|
54
|
-
window.history.back();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
catch(error)
|
|
60
|
-
{
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
package/server.js
DELETED
|
File without changes
|