@zintrust/core 0.9.6 → 1.5.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/package.json +8 -22
- package/src/cli/commands/EnvKeyGenerateCommand.js +1 -1
- package/src/cli/scaffolding/GovernanceScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/GovernanceScaffolder.js +3 -32
- package/src/cli/scaffolding/ProjectScaffolder.d.ts.map +1 -1
- package/src/cli/scaffolding/ProjectScaffolder.js +2 -38
- package/src/cli/scaffolding/ScaffoldingVersionUtils.d.ts +1 -0
- package/src/cli/scaffolding/ScaffoldingVersionUtils.d.ts.map +1 -1
- package/src/cli/scaffolding/ScaffoldingVersionUtils.js +1 -0
- package/src/index.js +3 -3
- package/src/templates/project/basic/routes/storage.ts.tpl +25 -0
- package/src/tools/http/Http.d.ts.map +1 -1
- package/src/tools/http/Http.js +97 -25
- package/src/zintrust.plugins.d.ts +3 -6
- package/src/zintrust.plugins.d.ts.map +1 -1
- package/src/zintrust.plugins.js +3 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Production-grade TypeScript backend framework for JavaScript",
|
|
5
5
|
"homepage": "https://zintrust.com",
|
|
6
6
|
"repository": {
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"axios": "^1.15.0",
|
|
74
74
|
"@eslint/plugin-kit": "^0.7.1",
|
|
75
75
|
"follow-redirects": "^1.16.0",
|
|
76
|
-
"@tootallnate/once": "
|
|
76
|
+
"@tootallnate/once": "3.0.1",
|
|
77
77
|
"node-forge": "^1.4.0",
|
|
78
|
-
"fast-xml-parser": "
|
|
78
|
+
"fast-xml-parser": "5.7.1",
|
|
79
79
|
"brace-expansion": "^5.0.5",
|
|
80
80
|
"picomatch": "^4.0.4",
|
|
81
81
|
"cross-spawn": "^7.0.5",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"rollup": "^4.59.0",
|
|
85
85
|
"vite": "^8.0.5",
|
|
86
86
|
"flatted": "^3.4.2",
|
|
87
|
-
"uuid": "
|
|
87
|
+
"uuid": "14.0.0",
|
|
88
88
|
"@actions/github": {
|
|
89
89
|
"undici": "^6.24.0"
|
|
90
90
|
},
|
|
@@ -94,24 +94,10 @@
|
|
|
94
94
|
"miniflare": {
|
|
95
95
|
"undici": "^7.24.4"
|
|
96
96
|
},
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
"fast-xml-parser": "^5.7.1"
|
|
102
|
-
},
|
|
103
|
-
"@google-cloud/storage": {
|
|
104
|
-
"uuid": "^14.0.0"
|
|
105
|
-
},
|
|
106
|
-
"@google-cloud/storage@7.19.0": {
|
|
107
|
-
"uuid": "^14.0.0"
|
|
108
|
-
},
|
|
109
|
-
"gaxios": {
|
|
110
|
-
"uuid": "^14.0.0"
|
|
111
|
-
},
|
|
112
|
-
"teeny-request": {
|
|
113
|
-
"uuid": "^14.0.0"
|
|
114
|
-
}
|
|
97
|
+
"http-proxy-agent": "7.0.2",
|
|
98
|
+
"retry-request": "8.0.2",
|
|
99
|
+
"gaxios": "7.1.4",
|
|
100
|
+
"teeny-request": "10.1.2"
|
|
115
101
|
},
|
|
116
102
|
"bin": {
|
|
117
103
|
"zintrust": "bin/zintrust.js",
|
|
@@ -78,7 +78,7 @@ export const EnvKeyGenerateCommand = Object.freeze({
|
|
|
78
78
|
}
|
|
79
79
|
envContent = upsertEnvValue(envContent, envKey, key);
|
|
80
80
|
await fs.writeFile(envPath, envContent);
|
|
81
|
-
Logger.info(`${envKey} set successfully
|
|
81
|
+
Logger.info(`${envKey} set successfully.`);
|
|
82
82
|
}
|
|
83
83
|
catch (error) {
|
|
84
84
|
Logger.error(`Failed to update ${envKey} in .env`, error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GovernanceScaffolder.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/GovernanceScaffolder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"GovernanceScaffolder.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/GovernanceScaffolder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAoBH,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC,CAAC;AAEH,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC;IAC9C,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC,CAAC;AAkSH,eAAO,MAAM,oBAAoB;0BAEhB,MAAM,YACV,yBAAyB,GACjC,OAAO,CAAC,wBAAwB,CAAC;EA+DpC,CAAC;AAEH,eAAe,oBAAoB,CAAC"}
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* - Architecture tests (Vitest)
|
|
7
7
|
*/
|
|
8
8
|
import { FileGenerator } from '../scaffolding/FileGenerator.js';
|
|
9
|
-
import {
|
|
10
|
-
import { VersionChecker } from '../services/VersionChecker.js';
|
|
9
|
+
import { PINNED_GOVERNANCE_SCAFFOLDER_VERSION } from '../scaffolding/ScaffoldingVersionUtils.js';
|
|
11
10
|
import { SpawnUtil } from '../utils/spawn.js';
|
|
12
11
|
import { resolvePackageManager } from '../../common/index.js';
|
|
13
12
|
import { Logger } from '../../config/logger.js';
|
|
@@ -51,41 +50,13 @@ const ensureDevDependency = (devDependencies, name, version) => {
|
|
|
51
50
|
devDependencies[name] = version;
|
|
52
51
|
}
|
|
53
52
|
};
|
|
54
|
-
const getBundledGovernanceVersion = () => {
|
|
55
|
-
try {
|
|
56
|
-
const pkgUrl = new URL('../../../packages/governance/package.json', import.meta.url);
|
|
57
|
-
const raw = FileGenerator.readFile(pkgUrl.toString());
|
|
58
|
-
const parsed = JSON.parse(raw);
|
|
59
|
-
return typeof parsed.version === 'string' && parsed.version.trim() !== ''
|
|
60
|
-
? toCompatibleGovernanceVersion(parsed.version)
|
|
61
|
-
: undefined;
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
53
|
const inferGovernanceVersion = (pkg) => {
|
|
68
54
|
const devDeps = getStringRecord(pkg.devDependencies);
|
|
69
55
|
const existingGovernance = devDeps?.['@zintrust/governance'];
|
|
70
56
|
if (typeof existingGovernance === 'string' && existingGovernance.trim() !== '') {
|
|
71
57
|
return existingGovernance;
|
|
72
58
|
}
|
|
73
|
-
|
|
74
|
-
const core = deps?.['@zintrust/core'];
|
|
75
|
-
const bundledGovernanceVersion = getBundledGovernanceVersion();
|
|
76
|
-
if (typeof core === 'string' && core.trim() !== '') {
|
|
77
|
-
if (bundledGovernanceVersion !== undefined) {
|
|
78
|
-
return bundledGovernanceVersion;
|
|
79
|
-
}
|
|
80
|
-
if (extractMajorMinorVersion(core) !== undefined) {
|
|
81
|
-
return toCompatibleGovernanceVersion(core);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const currentVersion = VersionChecker.getCurrentVersion().trim();
|
|
85
|
-
if (currentVersion !== '' && currentVersion !== '0.0.0') {
|
|
86
|
-
return bundledGovernanceVersion ?? toCompatibleGovernanceVersion(currentVersion);
|
|
87
|
-
}
|
|
88
|
-
return bundledGovernanceVersion ?? '^0.4.0';
|
|
59
|
+
return PINNED_GOVERNANCE_SCAFFOLDER_VERSION;
|
|
89
60
|
};
|
|
90
61
|
const writeEslintConfig = (projectRoot) => {
|
|
91
62
|
const eslintConfigPath = path.join(projectRoot, 'eslint.config.mjs');
|
|
@@ -159,7 +130,7 @@ const extractImportSpecifiers = (source: string, filePath: string): ImportHit[]
|
|
|
159
130
|
const visit = (node: ts.Node) => {
|
|
160
131
|
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
161
132
|
const moduleSpecifier = node.moduleSpecifier;
|
|
162
|
-
|
|
133
|
+
// extractMajorMinorVersion,
|
|
163
134
|
addHit(moduleSpecifier.text, moduleSpecifier.getStart(sourceFile));
|
|
164
135
|
}
|
|
165
136
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectScaffolder.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/ProjectScaffolder.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"ProjectScaffolder.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/ProjectScaffolder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAEpD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,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,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { EnvFileBackfill } from '../env/EnvFileBackfill.js';
|
|
6
6
|
import { EnvData } from '../scaffolding/env.js';
|
|
7
|
-
import {
|
|
7
|
+
import { PINNED_GOVERNANCE_SCAFFOLDER_VERSION } from '../scaffolding/ScaffoldingVersionUtils.js';
|
|
8
8
|
import { Logger } from '../../config/logger.js';
|
|
9
9
|
import { ErrorFactory } from '../../exceptions/ZintrustError.js';
|
|
10
10
|
import { isNonEmptyString } from '../../helper/index.js';
|
|
@@ -13,15 +13,6 @@ import fs from '../../node-singletons/fs.js';
|
|
|
13
13
|
import * as path from '../../node-singletons/path.js';
|
|
14
14
|
import { fileURLToPath } from '../../node-singletons/url.js';
|
|
15
15
|
import { execFileSync } from 'node:child_process';
|
|
16
|
-
const readBundledGovernancePackage = () => {
|
|
17
|
-
try {
|
|
18
|
-
const packageUrl = new URL('../../../packages/governance/package.json', import.meta.url);
|
|
19
|
-
return JSON.parse(fs.readFileSync(packageUrl, 'utf-8'));
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
16
|
const SAFE_PATH = '/usr/local/bin:/usr/bin:/bin';
|
|
26
17
|
const NPM_VIEW_TIMEOUT_MS = 1500;
|
|
27
18
|
const publishedVersionCache = new Map();
|
|
@@ -78,22 +69,6 @@ const loadPublishedNpmVersion = (packageName) => {
|
|
|
78
69
|
return undefined;
|
|
79
70
|
}
|
|
80
71
|
};
|
|
81
|
-
const loadBundledPublishedCoreVersion = () => {
|
|
82
|
-
const bundledGovernancePackage = readBundledGovernancePackage();
|
|
83
|
-
const peerDependencies = bundledGovernancePackage?.peerDependencies;
|
|
84
|
-
if (typeof peerDependencies !== 'object' || peerDependencies === null) {
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
const corePeerRange = peerDependencies['@zintrust/core'];
|
|
88
|
-
if (typeof corePeerRange !== 'string' || corePeerRange.trim() === '') {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
const publishedLineVersion = extractMajorMinorVersion(corePeerRange);
|
|
92
|
-
if (publishedLineVersion === undefined) {
|
|
93
|
-
return '0.9.2';
|
|
94
|
-
}
|
|
95
|
-
return `${publishedLineVersion.major}.${publishedLineVersion.minor}.2`;
|
|
96
|
-
};
|
|
97
72
|
const toCompatibleCoreDependencyRange = (version) => `^${version}`;
|
|
98
73
|
const loadScaffoldCoreVersion = () => {
|
|
99
74
|
const publishedVersion = loadPublishedNpmVersion('@zintrust/core');
|
|
@@ -102,17 +77,6 @@ const loadScaffoldCoreVersion = () => {
|
|
|
102
77
|
}
|
|
103
78
|
return '*';
|
|
104
79
|
};
|
|
105
|
-
const loadGovernanceVersion = () => {
|
|
106
|
-
const publishedVersion = loadPublishedNpmVersion('@zintrust/governance');
|
|
107
|
-
if (typeof publishedVersion === 'string') {
|
|
108
|
-
return publishedVersion;
|
|
109
|
-
}
|
|
110
|
-
const bundledPublishedCoreVersion = loadBundledPublishedCoreVersion();
|
|
111
|
-
if (typeof bundledPublishedCoreVersion === 'string') {
|
|
112
|
-
return bundledPublishedCoreVersion;
|
|
113
|
-
}
|
|
114
|
-
return '0.9.2';
|
|
115
|
-
};
|
|
116
80
|
const createDirectories = (projectPath, directories) => {
|
|
117
81
|
let count = 0;
|
|
118
82
|
if (!fs.existsSync(projectPath)) {
|
|
@@ -569,7 +533,7 @@ const prepareContext = (state, options) => {
|
|
|
569
533
|
.slice(0, 14);
|
|
570
534
|
state.variables = {
|
|
571
535
|
coreVersion: loadScaffoldCoreVersion(),
|
|
572
|
-
governanceVersion:
|
|
536
|
+
governanceVersion: PINNED_GOVERNANCE_SCAFFOLDER_VERSION,
|
|
573
537
|
projectName: options.name,
|
|
574
538
|
projectSlug: options.name,
|
|
575
539
|
author: options.author ?? 'Your Name',
|
|
@@ -2,5 +2,6 @@ export declare const extractMajorMinorVersion: (value: string) => {
|
|
|
2
2
|
major: string;
|
|
3
3
|
minor: string;
|
|
4
4
|
} | undefined;
|
|
5
|
+
export declare const PINNED_GOVERNANCE_SCAFFOLDER_VERSION = "^1.2.0";
|
|
5
6
|
export declare const toCompatibleGovernanceVersion: (value: string, fallback?: string) => string;
|
|
6
7
|
//# sourceMappingURL=ScaffoldingVersionUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScaffoldingVersionUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/ScaffoldingVersionUtils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,GACnC,OAAO,MAAM,KACZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SA6BrC,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,OAAO,MAAM,EAAE,iBAAmB,KAAG,MAKlF,CAAC"}
|
|
1
|
+
{"version":3,"file":"ScaffoldingVersionUtils.d.ts","sourceRoot":"","sources":["../../../../src/cli/scaffolding/ScaffoldingVersionUtils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,GACnC,OAAO,MAAM,KACZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SA6BrC,CAAC;AAEF,eAAO,MAAM,oCAAoC,WAAW,CAAC;AAE7D,eAAO,MAAM,6BAA6B,GAAI,OAAO,MAAM,EAAE,iBAAmB,KAAG,MAKlF,CAAC"}
|
|
@@ -26,6 +26,7 @@ export const extractMajorMinorVersion = (value) => {
|
|
|
26
26
|
return undefined;
|
|
27
27
|
return { major, minor };
|
|
28
28
|
};
|
|
29
|
+
export const PINNED_GOVERNANCE_SCAFFOLDER_VERSION = '^1.2.0';
|
|
29
30
|
export const toCompatibleGovernanceVersion = (value, fallback = '^1.0.0') => {
|
|
30
31
|
const parsed = extractMajorMinorVersion(value);
|
|
31
32
|
if (parsed === undefined)
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @zintrust/core
|
|
2
|
+
* @zintrust/core v1.5.0
|
|
3
3
|
*
|
|
4
4
|
* ZinTrust Framework - Production-Grade TypeScript Backend
|
|
5
5
|
* Built for performance, type safety, and exceptional developer experience
|
|
6
6
|
*
|
|
7
7
|
* Build Information:
|
|
8
|
-
* Built: 2026-04-
|
|
8
|
+
* Built: 2026-04-24T13:03:41.812Z
|
|
9
9
|
* Node: >=20.0.0
|
|
10
10
|
* License: MIT
|
|
11
11
|
*
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Available at runtime for debugging and health checks
|
|
22
22
|
*/
|
|
23
23
|
export const ZINTRUST_VERSION = '0.1.41';
|
|
24
|
-
export const ZINTRUST_BUILD_DATE = '2026-04-
|
|
24
|
+
export const ZINTRUST_BUILD_DATE = '2026-04-24T13:03:41.779Z'; // Replaced during build
|
|
25
25
|
export { Application } from './boot/Application.js';
|
|
26
26
|
export { AwsSigV4 } from './common/index.js';
|
|
27
27
|
export { SignedRequest } from './security/SignedRequest.js';
|
|
@@ -8,6 +8,31 @@ import {
|
|
|
8
8
|
} from '@zintrust/core';
|
|
9
9
|
|
|
10
10
|
export function registerStorageRoutes(router: IRouter): void {
|
|
11
|
+
// Public file serving: /storage/<path>
|
|
12
|
+
Router.get(router, '/storage/:path*', async (req, res) => {
|
|
13
|
+
const raw = req.getParam('path') ?? '';
|
|
14
|
+
const key = typeof raw === 'string' ? decodeURIComponent(raw).replaceAll('\\\u005C', '/') : '';
|
|
15
|
+
|
|
16
|
+
if (key.trim() === '') {
|
|
17
|
+
res.setStatus(400).json({ message: 'Missing path' });
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Respect private folder convention: do not expose keys under `private/`
|
|
22
|
+
if (key.startsWith('private/') || key === 'private') {
|
|
23
|
+
res.setStatus(404).json({ message: 'Not Found' });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const contents = await Storage.get('local', key);
|
|
29
|
+
res.setHeader(HTTP_HEADERS.CONTENT_TYPE, 'application/octet-stream');
|
|
30
|
+
res.setStatus(200).send(contents);
|
|
31
|
+
} catch {
|
|
32
|
+
res.setStatus(404).json({ message: 'Not Found' });
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
11
36
|
Router.get(router, '/storage/download', async (req, res) => {
|
|
12
37
|
const tokenRaw = req.getQueryParam('token');
|
|
13
38
|
const token = typeof tokenRaw === 'string' ? tokenRaw : '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../../../src/tools/http/Http.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAAsB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAElF,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,MAAM,eAAe,GACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,MAAM,GACN,WAAW,GACX,eAAe,GACf,IAAI,GACJ,QAAQ,GACR,eAAe,CAAC;AAEpB,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC;IAC3C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,KAAK,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;CAChG,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC;IACtD,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,YAAY,CAAC;IAC3D,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,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/Http.js
CHANGED
|
@@ -80,6 +80,56 @@ const normalizeBodyInit = (body) => {
|
|
|
80
80
|
}
|
|
81
81
|
return body;
|
|
82
82
|
};
|
|
83
|
+
const hasAuthorizationHeader = (headers) => {
|
|
84
|
+
return Object.keys(headers).some((name) => name.toLowerCase() === 'authorization');
|
|
85
|
+
};
|
|
86
|
+
const decodeCredentialComponent = (value) => {
|
|
87
|
+
try {
|
|
88
|
+
return decodeURIComponent(value);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const encodeBase64Utf8 = (value) => {
|
|
95
|
+
if (typeof Buffer !== 'undefined') {
|
|
96
|
+
return Buffer.from(value, 'utf8').toString('base64');
|
|
97
|
+
}
|
|
98
|
+
if (typeof globalThis.btoa === 'function') {
|
|
99
|
+
const bytes = new TextEncoder().encode(value);
|
|
100
|
+
let binary = '';
|
|
101
|
+
for (const byte of bytes) {
|
|
102
|
+
binary += String.fromCodePoint(byte);
|
|
103
|
+
}
|
|
104
|
+
return globalThis.btoa(binary);
|
|
105
|
+
}
|
|
106
|
+
throw ErrorFactory.createTryCatchError('HTTP basic auth encoding is unavailable');
|
|
107
|
+
};
|
|
108
|
+
const normalizeCredentialUrl = (url, headers) => {
|
|
109
|
+
let parsed;
|
|
110
|
+
try {
|
|
111
|
+
parsed = new URL(url);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return { url, headers };
|
|
115
|
+
}
|
|
116
|
+
const username = parsed.username;
|
|
117
|
+
const password = parsed.password;
|
|
118
|
+
if (username === '' && password === '') {
|
|
119
|
+
return { url, headers };
|
|
120
|
+
}
|
|
121
|
+
const nextHeaders = { ...headers };
|
|
122
|
+
if (!hasAuthorizationHeader(nextHeaders)) {
|
|
123
|
+
const credentials = encodeBase64Utf8(`${decodeCredentialComponent(username)}:${decodeCredentialComponent(password)}`);
|
|
124
|
+
nextHeaders['Authorization'] = `Basic ${credentials}`;
|
|
125
|
+
}
|
|
126
|
+
parsed.username = '';
|
|
127
|
+
parsed.password = '';
|
|
128
|
+
return {
|
|
129
|
+
url: parsed.toString(),
|
|
130
|
+
headers: nextHeaders,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
83
133
|
const serializeFormBody = (body) => {
|
|
84
134
|
if (body === null || body === undefined)
|
|
85
135
|
return body;
|
|
@@ -153,8 +203,8 @@ const captureTraceResponseBody = async (response) => {
|
|
|
153
203
|
* Perform the actual request for a given state. Separated to keep the builder small
|
|
154
204
|
*/
|
|
155
205
|
async function performRequest(state) {
|
|
156
|
-
const { response, bodyText, durationMs } = await performRequestRaw(state);
|
|
157
|
-
Logger.debug(`HTTP ${
|
|
206
|
+
const { response, bodyText, durationMs, effectiveState } = await performRequestRaw(state);
|
|
207
|
+
Logger.debug(`HTTP ${effectiveState.method} ${effectiveState.url}`, {
|
|
158
208
|
status: response.status,
|
|
159
209
|
duration: `${durationMs}ms`,
|
|
160
210
|
size: bodyText.length,
|
|
@@ -162,31 +212,45 @@ async function performRequest(state) {
|
|
|
162
212
|
return createHttpResponse(response, bodyText);
|
|
163
213
|
}
|
|
164
214
|
async function performRequestRaw(state) {
|
|
165
|
-
const { response, durationMs, requestBody } = await performFetch(state);
|
|
215
|
+
const { response, durationMs, requestBody, effectiveState } = await performFetch(state);
|
|
166
216
|
const bodyText = await response.text();
|
|
167
|
-
emitHttpClientTrace({
|
|
168
|
-
|
|
217
|
+
emitHttpClientTrace({
|
|
218
|
+
state: effectiveState,
|
|
219
|
+
requestBody,
|
|
220
|
+
response,
|
|
221
|
+
responseBody: bodyText,
|
|
222
|
+
durationMs,
|
|
223
|
+
});
|
|
224
|
+
return { response, bodyText, durationMs, requestBody, effectiveState };
|
|
169
225
|
}
|
|
170
226
|
async function performFetch(state) {
|
|
171
227
|
const timeout = state.timeout ?? Env.getInt('HTTP_TIMEOUT', 30000);
|
|
172
228
|
const controller = new AbortController();
|
|
229
|
+
const normalizedTarget = normalizeCredentialUrl(state.url, state.headers);
|
|
230
|
+
const effectiveState = normalizedTarget.url === state.url && normalizedTarget.headers === state.headers
|
|
231
|
+
? state
|
|
232
|
+
: {
|
|
233
|
+
...state,
|
|
234
|
+
url: normalizedTarget.url,
|
|
235
|
+
headers: normalizedTarget.headers,
|
|
236
|
+
};
|
|
173
237
|
let timeoutId;
|
|
174
238
|
if (timeout > 0) {
|
|
175
239
|
timeoutId = globalThis.setTimeout(() => controller.abort(), timeout);
|
|
176
240
|
}
|
|
177
241
|
const buildInit = () => {
|
|
178
242
|
if (OpenTelemetry.isEnabled()) {
|
|
179
|
-
OpenTelemetry.injectTraceHeaders(
|
|
243
|
+
OpenTelemetry.injectTraceHeaders(effectiveState.headers);
|
|
180
244
|
}
|
|
181
|
-
const requestBody = serializeRequestBody(
|
|
245
|
+
const requestBody = serializeRequestBody(effectiveState);
|
|
182
246
|
const init = {
|
|
183
|
-
method:
|
|
184
|
-
headers:
|
|
247
|
+
method: effectiveState.method,
|
|
248
|
+
headers: effectiveState.headers,
|
|
185
249
|
signal: controller.signal,
|
|
186
250
|
};
|
|
187
251
|
if (requestBody !== undefined &&
|
|
188
252
|
requestBody !== null &&
|
|
189
|
-
['POST', 'PUT', 'PATCH', 'DELETE'].includes(
|
|
253
|
+
['POST', 'PUT', 'PATCH', 'DELETE'].includes(effectiveState.method)) {
|
|
190
254
|
init.body = requestBody;
|
|
191
255
|
}
|
|
192
256
|
return { init, requestBody };
|
|
@@ -194,28 +258,28 @@ async function performFetch(state) {
|
|
|
194
258
|
const startTime = Date.now();
|
|
195
259
|
try {
|
|
196
260
|
const { init, requestBody } = buildInit();
|
|
197
|
-
const response = await globalThis.fetch(
|
|
261
|
+
const response = await globalThis.fetch(effectiveState.url, init);
|
|
198
262
|
const duration = Date.now() - startTime;
|
|
199
|
-
return { response, durationMs: duration, requestBody };
|
|
263
|
+
return { response, durationMs: duration, requestBody, effectiveState };
|
|
200
264
|
}
|
|
201
265
|
catch (error) {
|
|
202
266
|
const duration = Date.now() - startTime;
|
|
203
267
|
emitHttpClientTrace({
|
|
204
|
-
state,
|
|
205
|
-
requestBody: serializeRequestBody(
|
|
268
|
+
state: effectiveState,
|
|
269
|
+
requestBody: serializeRequestBody(effectiveState),
|
|
206
270
|
durationMs: duration,
|
|
207
271
|
error: error instanceof Error ? error.message : String(error),
|
|
208
272
|
});
|
|
209
273
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
210
274
|
throw ErrorFactory.createConnectionError(`HTTP request timeout after ${timeout}ms`, {
|
|
211
|
-
url:
|
|
212
|
-
method:
|
|
275
|
+
url: effectiveState.url,
|
|
276
|
+
method: effectiveState.method,
|
|
213
277
|
timeout,
|
|
214
278
|
});
|
|
215
279
|
}
|
|
216
280
|
throw ErrorFactory.createTryCatchError(`HTTP request failed: ${error.message}`, {
|
|
217
|
-
url:
|
|
218
|
-
method:
|
|
281
|
+
url: effectiveState.url,
|
|
282
|
+
method: effectiveState.method,
|
|
219
283
|
error: error instanceof Error ? error.message : String(error),
|
|
220
284
|
});
|
|
221
285
|
}
|
|
@@ -225,6 +289,18 @@ async function performFetch(state) {
|
|
|
225
289
|
}
|
|
226
290
|
}
|
|
227
291
|
}
|
|
292
|
+
async function performFetchWithTrace(state) {
|
|
293
|
+
const result = await performFetch(state);
|
|
294
|
+
const responseBody = await captureTraceResponseBody(result.response);
|
|
295
|
+
emitHttpClientTrace({
|
|
296
|
+
state: result.effectiveState,
|
|
297
|
+
requestBody: result.requestBody,
|
|
298
|
+
response: result.response,
|
|
299
|
+
responseBody,
|
|
300
|
+
durationMs: result.durationMs,
|
|
301
|
+
});
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
228
304
|
/**
|
|
229
305
|
* Create request builder with fluent API
|
|
230
306
|
*/
|
|
@@ -251,7 +327,7 @@ function createRequestBuilder(method, url, initialBody) {
|
|
|
251
327
|
return self;
|
|
252
328
|
},
|
|
253
329
|
withBasicAuth(username, password) {
|
|
254
|
-
const credentials =
|
|
330
|
+
const credentials = encodeBase64Utf8(`${username}:${password}`);
|
|
255
331
|
state.headers['Authorization'] = `Basic ${credentials}`;
|
|
256
332
|
return self;
|
|
257
333
|
},
|
|
@@ -281,15 +357,11 @@ function createRequestBuilder(method, url, initialBody) {
|
|
|
281
357
|
return performRequest(state);
|
|
282
358
|
},
|
|
283
359
|
async sendRaw() {
|
|
284
|
-
const { response
|
|
285
|
-
const responseBody = await captureTraceResponseBody(response);
|
|
286
|
-
emitHttpClientTrace({ state, requestBody, response, responseBody, durationMs });
|
|
360
|
+
const { response } = await performFetchWithTrace(state);
|
|
287
361
|
return response;
|
|
288
362
|
},
|
|
289
363
|
async sendStream() {
|
|
290
|
-
const { response
|
|
291
|
-
const responseBody = await captureTraceResponseBody(response);
|
|
292
|
-
emitHttpClientTrace({ state, requestBody, response, responseBody, durationMs });
|
|
364
|
+
const { response } = await performFetchWithTrace(state);
|
|
293
365
|
return { response, stream: response.body };
|
|
294
366
|
},
|
|
295
367
|
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* side-effect imports (e.g. `@zintrust/db-sqlite/register`) that register
|
|
6
|
-
* optional adapters/drivers into core registries.
|
|
7
|
-
*
|
|
2
|
+
* Auto-generated fallback module.
|
|
3
|
+
* This file is created by scripts/ensure-worker-plugins.mjs when missing.
|
|
4
|
+
* It allows optional runtime plugin imports to resolve in CI/scaffolded setups.
|
|
8
5
|
*/
|
|
9
6
|
export type {};
|
|
10
7
|
export declare const __zintrustGeneratedPluginStub = "zintrust.plugins.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zintrust.plugins.d.ts","sourceRoot":"","sources":["../../src/zintrust.plugins.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"zintrust.plugins.d.ts","sourceRoot":"","sources":["../../src/zintrust.plugins.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,YAAY,EAAE,CAAC;AAgBf,eAAO,MAAM,6BAA6B,wBAAwB,CAAC;;AACnE,wBAAkB"}
|
package/src/zintrust.plugins.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* side-effect imports (e.g. `@zintrust/db-sqlite/register`) that register
|
|
6
|
-
* optional adapters/drivers into core registries.
|
|
7
|
-
*
|
|
2
|
+
* Auto-generated fallback module.
|
|
3
|
+
* This file is created by scripts/ensure-worker-plugins.mjs when missing.
|
|
4
|
+
* It allows optional runtime plugin imports to resolve in CI/scaffolded setups.
|
|
8
5
|
*/
|
|
9
6
|
import * as TraceRuntime from './runtime/plugins/trace-runtime.js';
|
|
10
7
|
globalThis.__zintrust_system_trace_plugin_requested__ = true;
|