ztechno_core 0.0.84 → 0.0.86
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/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/scripts/docker-update.d.ts +20 -0
- package/lib/scripts/docker-update.js +87 -0
- package/lib/scripts/encrypt.d.ts +1 -0
- package/lib/scripts/encrypt.js +4 -0
- package/package.json +2 -1
package/lib/index.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ import { ZTranslateService } from './translate_service';
|
|
|
6
6
|
import { ZUserService } from './user_service';
|
|
7
7
|
export { middleware } from './express';
|
|
8
8
|
export * from './typings';
|
|
9
|
+
export * from './scripts/docker-update';
|
|
9
10
|
export { ZEngineBase, ZCryptoService, ZMailService, ZSQLService, ZTranslateService, ZUserService };
|
package/lib/index.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
2
|
+
/**
|
|
3
|
+
* Update a remote Docker container via the V2 Secure API
|
|
4
|
+
* @param packagename - The package/image name
|
|
5
|
+
* @param port - The port number
|
|
6
|
+
* @param c - Optional logger
|
|
7
|
+
* @returns Promise resolving to success status and message
|
|
8
|
+
*/
|
|
9
|
+
export declare function updateDocker(
|
|
10
|
+
packagename: string,
|
|
11
|
+
port: string | number,
|
|
12
|
+
c?: {
|
|
13
|
+
log: any;
|
|
14
|
+
error: any;
|
|
15
|
+
},
|
|
16
|
+
): Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
message?: string;
|
|
19
|
+
err?: string;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault =
|
|
3
|
+
(this && this.__importDefault) ||
|
|
4
|
+
function (mod) {
|
|
5
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
8
|
+
exports.updateDocker = void 0;
|
|
9
|
+
require('dotenv/config');
|
|
10
|
+
const http_1 = __importDefault(require('http'));
|
|
11
|
+
const crypto_1 = __importDefault(require('crypto'));
|
|
12
|
+
const crypto_service_1 = require('../crypto_service');
|
|
13
|
+
/**
|
|
14
|
+
* Update a remote Docker container via the V2 Secure API
|
|
15
|
+
* @param packagename - The package/image name
|
|
16
|
+
* @param port - The port number
|
|
17
|
+
* @param c - Optional logger
|
|
18
|
+
* @returns Promise resolving to success status and message
|
|
19
|
+
*/
|
|
20
|
+
function updateDocker(packagename, port, c) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const secretKey = process.env.ZTECHNO_API_SECRET;
|
|
23
|
+
if (!secretKey) {
|
|
24
|
+
c.log('\x1b[31m✗ Error: ZTECHNO_API_SECRET environment variable not set\x1b[0m');
|
|
25
|
+
return reject(new Error('ZTECHNO_API_SECRET environment variable not set'));
|
|
26
|
+
}
|
|
27
|
+
// Generate timestamp and signature
|
|
28
|
+
const timestamp = Date.now().toString();
|
|
29
|
+
const payload = timestamp + packagename + port + '';
|
|
30
|
+
const signature = crypto_1.default.createHmac('sha256', secretKey).update(payload).digest('hex');
|
|
31
|
+
c?.log('\x1b[32m' + `[Updating Remote Docker via V2 Secure API]`);
|
|
32
|
+
const options = {
|
|
33
|
+
hostname: crypto_service_1.ZCryptoService.decrypt({
|
|
34
|
+
iv: '00d1df14932d0e6b5d064cceb037f586',
|
|
35
|
+
encryptedData: '05b9d826539fe2cbdf7d7ecccfe57635',
|
|
36
|
+
}),
|
|
37
|
+
port: 7998,
|
|
38
|
+
path: `/v2/images/${packagename}/update?port=${port}`,
|
|
39
|
+
method: 'GET',
|
|
40
|
+
headers: {
|
|
41
|
+
'x-timestamp': timestamp,
|
|
42
|
+
'x-signature': signature,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const req = http_1.default.request(options, (res) => {
|
|
46
|
+
let data = '';
|
|
47
|
+
res.on('data', (chunk) => {
|
|
48
|
+
data += chunk;
|
|
49
|
+
});
|
|
50
|
+
res.on('end', () => {
|
|
51
|
+
try {
|
|
52
|
+
const response = JSON.parse(data);
|
|
53
|
+
c?.log('\x1b[36mStatus Code:', res.statusCode, '\x1b[0m');
|
|
54
|
+
c?.log('\x1b[34mResponse:', JSON.stringify(response, null, 2), '\x1b[0m');
|
|
55
|
+
if (response.success) {
|
|
56
|
+
c?.log('\x1b[32m✓', response.message, '\x1b[0m');
|
|
57
|
+
resolve(response);
|
|
58
|
+
} else {
|
|
59
|
+
c?.log('\x1b[31m✗ Error:', response.err, '\x1b[0m');
|
|
60
|
+
resolve(response);
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
c?.log('\x1b[31mFailed to parse response:', data, '\x1b[0m');
|
|
64
|
+
c?.error(err);
|
|
65
|
+
reject(err);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
req.on('error', (err) => {
|
|
70
|
+
c?.log('\x1b[31m✗ Request failed:', err.message, '\x1b[0m');
|
|
71
|
+
reject(err);
|
|
72
|
+
});
|
|
73
|
+
req.end();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.updateDocker = updateDocker;
|
|
77
|
+
// Run if executed directly (node docker-update.js or npm run docker-update)
|
|
78
|
+
if (require.main === module) {
|
|
79
|
+
const arg = process.argv.slice(2)[0];
|
|
80
|
+
if (!arg || !arg.includes(':')) {
|
|
81
|
+
throw new Error('\x1b[31m✗ Usage: node docker-update.js <packagename>:<port>\x1b[0m');
|
|
82
|
+
// process.exit(1)
|
|
83
|
+
}
|
|
84
|
+
const [packagename, port] = arg.split(':');
|
|
85
|
+
updateDocker(packagename, port, console).catch(() => process.exit(1));
|
|
86
|
+
}
|
|
87
|
+
module.exports = { updateDocker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ztechno_core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.86",
|
|
4
4
|
"description": "Core files for ztechno framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@types/express": "^5.0.0",
|
|
42
42
|
"dom-parser": "^1.1.5",
|
|
43
|
+
"dotenv": "^17.2.3",
|
|
43
44
|
"mysql": "^2.18.1",
|
|
44
45
|
"nodemailer": "^6.8.0",
|
|
45
46
|
"translate": "^1.4.1"
|