very-express 0.10.2 → 0.11.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 very-express might be problematic. Click here for more details.
- package/.tmp/_body.txt +1 -0
- package/.tmp/_idx.txt +1 -0
- package/.tmp/_token.txt +1 -0
- package/.tmp/check-a/app/.vex/meta.json +216 -0
- package/.tmp/check-a/app/Dockerfile +20 -0
- package/.tmp/check-a/app/README.md +39 -0
- package/.tmp/check-a/app/public/css/style.css +8 -0
- package/.tmp/check-a/app/public/js/deleteaccount.js +80 -0
- package/.tmp/check-a/app/public/js/login.js +59 -0
- package/.tmp/check-a/app/public/js/logincallback.js +19 -0
- package/.tmp/check-a/app/public/js/mytokens.js +11 -0
- package/.tmp/check-a/app/public/js/refreshtokens.js +23 -0
- package/.tmp/check-a/app/scripts/build.js +39 -0
- package/.tmp/check-a/app/scripts/oacg-fix.js +83 -0
- package/.tmp/check-a/app/tsconfig.json +30 -0
- package/.tmp/check-a/schemas/Project.json +41 -0
- package/.tmp/check-a/schemas/Session.json +49 -0
- package/.tmp/check-a/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/check-a/vex.config.json +26 -0
- package/.tmp/check-b/app/.env +41 -0
- package/.tmp/check-b/app/.vex/meta.json +219 -0
- package/.tmp/check-b/app/Dockerfile +20 -0
- package/.tmp/check-b/app/README.md +39 -0
- package/.tmp/check-b/app/package.json +51 -0
- package/.tmp/check-b/app/public/css/style.css +8 -0
- package/.tmp/check-b/app/public/js/deleteaccount.js +80 -0
- package/.tmp/check-b/app/public/js/login.js +59 -0
- package/.tmp/check-b/app/public/js/logincallback.js +19 -0
- package/.tmp/check-b/app/public/js/mytokens.js +11 -0
- package/.tmp/check-b/app/public/js/refreshtokens.js +23 -0
- package/.tmp/check-b/app/scripts/build.js +39 -0
- package/.tmp/check-b/app/scripts/oacg-fix.js +83 -0
- package/.tmp/check-b/app/tsconfig.json +30 -0
- package/.tmp/check-b/app/tsoa.json +32 -0
- package/.tmp/check-b/schemas/Project.json +41 -0
- package/.tmp/check-b/vex.config.json +30 -0
- package/.tmp/check-c/app/.env +41 -0
- package/.tmp/check-c/app/.vex/meta.json +231 -0
- package/.tmp/check-c/app/Dockerfile +20 -0
- package/.tmp/check-c/app/README.md +39 -0
- package/.tmp/check-c/app/package.json +51 -0
- package/.tmp/check-c/app/public/css/style.css +8 -0
- package/.tmp/check-c/app/public/js/deleteaccount.js +80 -0
- package/.tmp/check-c/app/public/js/login.js +59 -0
- package/.tmp/check-c/app/public/js/logincallback.js +19 -0
- package/.tmp/check-c/app/public/js/mytokens.js +11 -0
- package/.tmp/check-c/app/public/js/refreshtokens.js +23 -0
- package/.tmp/check-c/app/scripts/build.js +39 -0
- package/.tmp/check-c/app/scripts/oacg-fix.js +83 -0
- package/.tmp/check-c/app/tsconfig.json +30 -0
- package/.tmp/check-c/app/tsoa.json +32 -0
- package/.tmp/check-c/schemas/Project.json +41 -0
- package/.tmp/check-c/schemas/User.json +81 -0
- package/.tmp/check-c/vex.config.json +30 -0
- package/.tmp/demo-project/vex.config.json +43 -0
- package/.tmp/demo-project2/vex.config.json +43 -0
- package/.tmp/demo-schemas/Client.json +65 -0
- package/.tmp/demo-schemas/FnbOrder.json +33 -0
- package/.tmp/demo-schemas/Job.json +86 -0
- package/.tmp/demo-schemas/KernelEvent.json +29 -0
- package/.tmp/demo-schemas/Package.json +77 -0
- package/.tmp/demo-schemas/Session.json +49 -0
- package/.tmp/demo-schemas/Tenant.json +22 -0
- package/.tmp/demo-schemas/User.json +81 -0
- package/.tmp/demo-schemas/UserAuthProfiles.json +54 -0
- package/.tmp/demo-schemas/UserContact.json +76 -0
- package/.tmp/demo-schemas/UserRole.json +40 -0
- package/.tmp/demo-schemas/UserTenant.json +39 -0
- package/.tmp/demo-schemas2/Client.json +65 -0
- package/.tmp/demo-schemas2/FnbOrder.json +33 -0
- package/.tmp/demo-schemas2/Job.json +86 -0
- package/.tmp/demo-schemas2/KernelEvent.json +29 -0
- package/.tmp/demo-schemas2/Package.json +77 -0
- package/.tmp/demo-schemas2/Session.json +49 -0
- package/.tmp/demo-schemas2/Tenant.json +22 -0
- package/.tmp/demo-schemas2/User.json +81 -0
- package/.tmp/demo-schemas2/UserAuthProfiles.json +54 -0
- package/.tmp/demo-schemas2/UserContact.json +76 -0
- package/.tmp/demo-schemas2/UserRole.json +40 -0
- package/.tmp/demo-schemas2/UserTenant.json +39 -0
- package/.tmp/e2e-db.url +1 -0
- package/.tmp/nouser/out/.env +41 -0
- package/.tmp/nouser/out/.vex/meta.json +323 -0
- package/.tmp/nouser/out/Dockerfile +20 -0
- package/.tmp/nouser/out/README.md +39 -0
- package/.tmp/nouser/out/package.json +51 -0
- package/.tmp/nouser/out/public/css/style.css +8 -0
- package/.tmp/nouser/out/public/js/deleteaccount.js +80 -0
- package/.tmp/nouser/out/public/js/login.js +59 -0
- package/.tmp/nouser/out/public/js/logincallback.js +19 -0
- package/.tmp/nouser/out/public/js/mytokens.js +11 -0
- package/.tmp/nouser/out/public/js/refreshtokens.js +23 -0
- package/.tmp/nouser/out/scripts/build.js +39 -0
- package/.tmp/nouser/out/scripts/oacg-fix.js +83 -0
- package/.tmp/nouser/out/tsconfig.json +30 -0
- package/.tmp/nouser/out/tsoa.json +32 -0
- package/.tmp/nouser/schemas/Project.json +41 -0
- package/.tmp/nouser/schemas/Session.json +49 -0
- package/.tmp/nouser/schemas/User.json +81 -0
- package/.tmp/nouser/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/nouser/schemas/UserTenant.json +39 -0
- package/.tmp/nouser/vex.config.json +34 -0
- package/.tmp/npm-test-after-fix.log +217 -0
- package/.tmp/npm-test-final.log +165 -0
- package/.tmp/npm-test-final2.log +163 -0
- package/.tmp/npm-test-recheck.log +192 -0
- package/.tmp/npm-test-update.log +164 -0
- package/.tmp/npm-test.log +166 -0
- package/.tmp/output-build-after-fix.log +8 -0
- package/.tmp/output-build-baseline.log +8 -0
- package/.tmp/output-build-canonical.log +8 -0
- package/.tmp/output-build-final2.log +8 -0
- package/.tmp/output-build-reapply.log +8 -0
- package/.tmp/output-build.log +8 -0
- package/.tmp/output.env.bak +34 -0
- package/.tmp/probe_body.txt +1 -0
- package/.tmp/provision-e2e-db.js +41 -0
- package/.tmp/retry-nodestroy.log +18 -0
- package/.tmp/retry-recovery-final2.log +8 -0
- package/.tmp/retry-recovery-reapply.log +8 -0
- package/.tmp/retry-recovery.js +38 -0
- package/.tmp/run-e2e-single.js +21 -0
- package/.tmp/run-e2e.js +18 -0
- package/.tmp/verify-noauth/app/.env +41 -0
- package/.tmp/verify-noauth/app/.vex/meta.json +333 -0
- package/.tmp/verify-noauth/app/Dockerfile +20 -0
- package/.tmp/verify-noauth/app/README.md +39 -0
- package/.tmp/verify-noauth/app/package.json +51 -0
- package/.tmp/verify-noauth/app/public/css/style.css +8 -0
- package/.tmp/verify-noauth/app/public/js/deleteaccount.js +80 -0
- package/.tmp/verify-noauth/app/public/js/login.js +59 -0
- package/.tmp/verify-noauth/app/public/js/logincallback.js +19 -0
- package/.tmp/verify-noauth/app/public/js/mytokens.js +11 -0
- package/.tmp/verify-noauth/app/public/js/refreshtokens.js +23 -0
- package/.tmp/verify-noauth/app/scripts/build.js +39 -0
- package/.tmp/verify-noauth/app/scripts/oacg-fix.js +83 -0
- package/.tmp/verify-noauth/app/tsconfig.json +30 -0
- package/.tmp/verify-noauth/app/tsoa.json +32 -0
- package/.tmp/verify-noauth/schemas/Project.json +41 -0
- package/.tmp/verify-noauth/schemas/Session.json +49 -0
- package/.tmp/verify-noauth/schemas/User.json +81 -0
- package/.tmp/verify-noauth/schemas/UserAuthProfiles.json +54 -0
- package/.tmp/verify-noauth/schemas/UserTenant.json +39 -0
- package/.tmp/verify-noauth/vex.config.json +33 -0
- package/.tmp/verify-noauth-rbac/app/.env +41 -0
- package/.tmp/verify-noauth-rbac/app/.vex/meta.json +273 -0
- package/.tmp/verify-noauth-rbac/app/Dockerfile +20 -0
- package/.tmp/verify-noauth-rbac/app/README.md +39 -0
- package/.tmp/verify-noauth-rbac/app/package.json +51 -0
- package/.tmp/verify-noauth-rbac/app/public/css/style.css +8 -0
- package/.tmp/verify-noauth-rbac/app/public/js/deleteaccount.js +80 -0
- package/.tmp/verify-noauth-rbac/app/public/js/login.js +59 -0
- package/.tmp/verify-noauth-rbac/app/public/js/logincallback.js +19 -0
- package/.tmp/verify-noauth-rbac/app/public/js/mytokens.js +11 -0
- package/.tmp/verify-noauth-rbac/app/public/js/refreshtokens.js +23 -0
- package/.tmp/verify-noauth-rbac/app/scripts/build.js +39 -0
- package/.tmp/verify-noauth-rbac/app/scripts/oacg-fix.js +83 -0
- package/.tmp/verify-noauth-rbac/app/tsconfig.json +30 -0
- package/.tmp/verify-noauth-rbac/app/tsoa.json +32 -0
- package/.tmp/verify-noauth-rbac/schemas/Project.json +41 -0
- package/.tmp/verify-noauth-rbac/schemas/User.json +81 -0
- package/.tmp/verify-noauth-rbac/schemas/UserRole.json +38 -0
- package/.tmp/verify-noauth-rbac/vex.config.json +36 -0
- package/.tmp/verify.sh +103 -0
- package/.tmp/verify2.sh +103 -0
- package/.tmp/vex-gen-after-fix.log +221 -0
- package/.tmp/vex-gen-baseline.log +221 -0
- package/.tmp/vex-gen-canonical.log +221 -0
- package/.tmp/vex-gen-final.log +220 -0
- package/.tmp/vex-gen-final2.log +221 -0
- package/.tmp/vex-gen-reapply.log +221 -0
- package/.tmp/vex-gen.log +220 -0
- package/.tmp/vex-run-after-fix.log +3 -0
- package/.tmp/vex-run-baseline.log +11 -0
- package/.tmp/vex-run-before-fix.log +11 -0
- package/.tmp/vex-run-canonical.log +3 -0
- package/.tmp/vex-run-final2.log +3 -0
- package/.tmp/vex-run.log +3 -0
- package/.tmp/vo/app/.env +41 -0
- package/.tmp/vo/app/.vex/meta.json +231 -0
- package/.tmp/vo/app/Dockerfile +20 -0
- package/.tmp/vo/app/README.md +39 -0
- package/.tmp/vo/app/package.json +51 -0
- package/.tmp/vo/app/public/css/style.css +8 -0
- package/.tmp/vo/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo/app/public/js/login.js +59 -0
- package/.tmp/vo/app/public/js/logincallback.js +19 -0
- package/.tmp/vo/app/public/js/mytokens.js +11 -0
- package/.tmp/vo/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo/app/scripts/build.js +39 -0
- package/.tmp/vo/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo/app/tsconfig.json +30 -0
- package/.tmp/vo/app/tsoa.json +32 -0
- package/.tmp/vo/schemas/Project.json +41 -0
- package/.tmp/vo/vex.config.json +33 -0
- package/.tmp/vo-bad1/app/.env +41 -0
- package/.tmp/vo-bad1/app/.vex/meta.json +237 -0
- package/.tmp/vo-bad1/app/Dockerfile +20 -0
- package/.tmp/vo-bad1/app/README.md +39 -0
- package/.tmp/vo-bad1/app/package.json +51 -0
- package/.tmp/vo-bad1/app/public/css/style.css +8 -0
- package/.tmp/vo-bad1/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo-bad1/app/public/js/login.js +59 -0
- package/.tmp/vo-bad1/app/public/js/logincallback.js +19 -0
- package/.tmp/vo-bad1/app/public/js/mytokens.js +11 -0
- package/.tmp/vo-bad1/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo-bad1/app/scripts/build.js +39 -0
- package/.tmp/vo-bad1/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo-bad1/app/tsconfig.json +30 -0
- package/.tmp/vo-bad1/app/tsoa.json +32 -0
- package/.tmp/vo-bad1/schemas/Project.json +41 -0
- package/.tmp/vo-bad1/vex.config.json +33 -0
- package/.tmp/vo-bad2/app/.env +41 -0
- package/.tmp/vo-bad2/app/.vex/meta.json +237 -0
- package/.tmp/vo-bad2/app/Dockerfile +20 -0
- package/.tmp/vo-bad2/app/README.md +39 -0
- package/.tmp/vo-bad2/app/package.json +51 -0
- package/.tmp/vo-bad2/app/public/css/style.css +8 -0
- package/.tmp/vo-bad2/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo-bad2/app/public/js/login.js +59 -0
- package/.tmp/vo-bad2/app/public/js/logincallback.js +19 -0
- package/.tmp/vo-bad2/app/public/js/mytokens.js +11 -0
- package/.tmp/vo-bad2/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo-bad2/app/scripts/build.js +39 -0
- package/.tmp/vo-bad2/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo-bad2/app/tsconfig.json +30 -0
- package/.tmp/vo-bad2/app/tsoa.json +32 -0
- package/.tmp/vo-bad2/schemas/Project.json +41 -0
- package/.tmp/vo-bad2/vex.config.json +39 -0
- package/.tmp/vo-bad3/app/.env +41 -0
- package/.tmp/vo-bad3/app/.vex/meta.json +237 -0
- package/.tmp/vo-bad3/app/Dockerfile +20 -0
- package/.tmp/vo-bad3/app/README.md +39 -0
- package/.tmp/vo-bad3/app/package.json +51 -0
- package/.tmp/vo-bad3/app/public/css/style.css +8 -0
- package/.tmp/vo-bad3/app/public/js/deleteaccount.js +80 -0
- package/.tmp/vo-bad3/app/public/js/login.js +59 -0
- package/.tmp/vo-bad3/app/public/js/logincallback.js +19 -0
- package/.tmp/vo-bad3/app/public/js/mytokens.js +11 -0
- package/.tmp/vo-bad3/app/public/js/refreshtokens.js +23 -0
- package/.tmp/vo-bad3/app/scripts/build.js +39 -0
- package/.tmp/vo-bad3/app/scripts/oacg-fix.js +83 -0
- package/.tmp/vo-bad3/app/tsconfig.json +30 -0
- package/.tmp/vo-bad3/app/tsoa.json +32 -0
- package/.tmp/vo-bad3/schemas/Project.json +41 -0
- package/.tmp/vo-bad3/vex.config.json +33 -0
- package/dist/index.js +1156 -698
- package/dist/templates/_middlewares/UserContext.ts +1 -1
- package/dist/templates/_routes/FirebaseAuthUI.gen.ts +2 -2
- package/dist/templates/_routes/{LoginUI.ts → StarterUI.ts} +122 -8
- package/dist/templates/_utils/hash.ts +9 -4
- package/dist/templates/tenantJsonSchema/Tenant.json +22 -0
- package/docs/appGenerated/auth.md +50 -0
- package/docs/architecture/databaseTargets.md +23 -2
- package/docs/architecture/templates.md +7 -0
- package/docs/features/accountDeletion.md +5 -4
- package/docs/features/auditFields.md +2 -2
- package/docs/features/tenantIsolation.md +108 -15
- package/docs/releaseNote/v0-10-3.md +61 -0
- package/docs/releaseNote/v0-10-4.md +102 -0
- package/docs/releaseNote/v0-11-0.md +82 -0
- package/docs/vexJsonSchema.md +34 -1
- package/package.json +1 -1
- package/vex.config.json +6 -1
- package/dist/templates/_services/VexDbConnector.ts +0 -188
- package/dist/templates/_tenant/TenantScopeContext.ts +0 -56
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// copy openapiDir to tsconfig's outDir
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
async function loadStripJsonComments() {
|
|
7
|
+
const { default: stripJsonComments } = await import('strip-json-comments');
|
|
8
|
+
return stripJsonComments;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
// Load strip-json-comments dynamically
|
|
13
|
+
const stripJsonComments = await loadStripJsonComments();
|
|
14
|
+
|
|
15
|
+
const openapiDir = "src/openapi";
|
|
16
|
+
const tsconfigPath = "tsconfig.json"
|
|
17
|
+
|
|
18
|
+
// 1. read tsconfig.json to get outDir
|
|
19
|
+
const tsconfigContent = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
20
|
+
const tsconfig = JSON.parse(stripJsonComments(tsconfigContent));
|
|
21
|
+
const outDir = tsconfig.compilerOptions.outDir;
|
|
22
|
+
|
|
23
|
+
// 2. copy ./openapi to outDir
|
|
24
|
+
const outDirOpenapi = path.resolve(outDir, 'openapi');
|
|
25
|
+
if (!fs.existsSync(outDirOpenapi)) {
|
|
26
|
+
fs.mkdirSync(outDirOpenapi, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
fs.readdirSync(openapiDir).forEach((file) => {
|
|
29
|
+
fs.copyFileSync(path.resolve(openapiDir, file), path.resolve(outDirOpenapi, file));
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// Execute the main function
|
|
35
|
+
main()
|
|
36
|
+
.catch(err => {
|
|
37
|
+
console.error(err);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Fix openapi-generated filter types to allow primitives, based on swagger schema info.
|
|
4
|
+
|
|
5
|
+
import { readdirSync, readFileSync, writeFileSync } from 'fs';
|
|
6
|
+
import { join, dirname } from 'path';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
|
|
9
|
+
const __dir = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const modelsDir = join(__dir, '../src/api-client/models');
|
|
11
|
+
const swaggerPath = join(__dir, '../../api/src/openapi/swagger.json');
|
|
12
|
+
|
|
13
|
+
const swagger = JSON.parse(readFileSync(swaggerPath, 'utf8'));
|
|
14
|
+
const schemas = swagger?.components?.schemas ?? {};
|
|
15
|
+
|
|
16
|
+
function primitiveTypeFromSwaggerProp(prop) {
|
|
17
|
+
if (!prop?.anyOf) return null;
|
|
18
|
+
const primitive = prop.anyOf.find(s => s.type && !s['$ref']);
|
|
19
|
+
if (!primitive) return null;
|
|
20
|
+
if (primitive.type === 'boolean') return 'boolean';
|
|
21
|
+
if (primitive.type === 'number' || primitive.type === 'integer') return 'number';
|
|
22
|
+
return 'string';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function primitiveTypeFromTsTypeName(tsType, swaggerEntityName, fieldKey) {
|
|
26
|
+
if (tsType === 'FieldFilterBoolean') return 'boolean';
|
|
27
|
+
if (tsType === 'FieldFilterNumber') return 'number';
|
|
28
|
+
if (tsType === 'FieldFilterString') return 'string';
|
|
29
|
+
if (/^FieldFilter[A-Z]/.test(tsType)) return 'string';
|
|
30
|
+
if (swaggerEntityName && fieldKey && schemas[swaggerEntityName]?.properties) {
|
|
31
|
+
const swaggerKey = fieldKey === 'id' ? '_id' : fieldKey;
|
|
32
|
+
const prop = schemas[swaggerEntityName].properties[swaggerKey];
|
|
33
|
+
if (prop) return primitiveTypeFromSwaggerProp(prop);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Field-level: FieldFilterBoolean, FilterAreaActive, FilterAreaCountryCode, etc.
|
|
39
|
+
const FIELD_FILTER_RE = /^(FieldFilter[A-Z]|Filter[A-Z][a-z]+[A-Z])[a-zA-Z]*\.ts$/;
|
|
40
|
+
// Top-level aggregates: FilterArea, FilterClient, FilterJob, etc.
|
|
41
|
+
const TOP_FILTER_RE = /^Filter([A-Z][a-zA-Z]+)\.ts$/;
|
|
42
|
+
|
|
43
|
+
const NULL_CHECK = ' if (value == null) {\n return value;\n }';
|
|
44
|
+
const PRIMITIVE_GUARD = '\n // patch: pass primitives unchanged\n if (typeof value !== \'object\') return value;';
|
|
45
|
+
|
|
46
|
+
let stats = { fieldPatched: 0, topPatched: 0, skipped: 0 };
|
|
47
|
+
|
|
48
|
+
// Pass 1: patch field-level ToJSONTyped / FromJSONTyped
|
|
49
|
+
for (const file of readdirSync(modelsDir)) {
|
|
50
|
+
if (!FIELD_FILTER_RE.test(file)) continue;
|
|
51
|
+
const filePath = join(modelsDir, file);
|
|
52
|
+
let src = readFileSync(filePath, 'utf8');
|
|
53
|
+
if (src.includes('// patch:') || !src.includes(NULL_CHECK)) { stats.skipped++; continue; }
|
|
54
|
+
src = src.replaceAll(NULL_CHECK, NULL_CHECK + PRIMITIVE_GUARD);
|
|
55
|
+
writeFileSync(filePath, src, 'utf8');
|
|
56
|
+
console.log('[patch] field v ' + file);
|
|
57
|
+
stats.fieldPatched++;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Pass 2: patch top-level filter interface property types
|
|
61
|
+
for (const file of readdirSync(modelsDir)) {
|
|
62
|
+
const match = TOP_FILTER_RE.exec(file);
|
|
63
|
+
if (!match) continue;
|
|
64
|
+
const filePath = join(modelsDir, file);
|
|
65
|
+
let src = readFileSync(filePath, 'utf8');
|
|
66
|
+
if (src.includes('// patch:')) { stats.skipped++; continue; }
|
|
67
|
+
const swaggerEntityName = file.replace('.ts', '');
|
|
68
|
+
// Match: ` fieldName?: SomeType;` — skip $or/$and lines
|
|
69
|
+
const PROP_RE = /^( {4}(?!\$or|\$and)(\w+)\?:\s*)([A-Za-z]+)(;)$/gm;
|
|
70
|
+
let modified = false;
|
|
71
|
+
const patched = src.replace(PROP_RE, (line, prefix, fieldKey, tsType, semi) => {
|
|
72
|
+
const primitive = primitiveTypeFromTsTypeName(tsType, swaggerEntityName, fieldKey);
|
|
73
|
+
if (!primitive || line.includes(' | ' + primitive)) return line;
|
|
74
|
+
modified = true;
|
|
75
|
+
return prefix + tsType + ' | ' + primitive + semi;
|
|
76
|
+
});
|
|
77
|
+
if (!modified) { stats.skipped++; continue; }
|
|
78
|
+
writeFileSync(filePath, patched, 'utf8');
|
|
79
|
+
console.log('[patch] top v ' + file);
|
|
80
|
+
stats.topPatched++;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log('\n[patch-filter-types] Done. Field: ' + stats.fieldPatched + ', Top: ' + stats.topPatched + ', Skipped: ' + stats.skipped);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"paths": {
|
|
7
|
+
"@": ["src"],
|
|
8
|
+
"@/*": ["src/*"]
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
/* Language and Environment */
|
|
12
|
+
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
13
|
+
|
|
14
|
+
/* Modules */
|
|
15
|
+
"module": "commonjs",
|
|
16
|
+
|
|
17
|
+
/* Emit */
|
|
18
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
19
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
20
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
21
|
+
"allowArbitraryExtensions": true, /* Allow arbitrary file extensions. */
|
|
22
|
+
|
|
23
|
+
/* Type Checking */
|
|
24
|
+
"experimentalDecorators": true, /* Enable experimental support for TC39 stage 2+ decorators. */
|
|
25
|
+
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations. */
|
|
26
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
27
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"entryFile": "src/server.ts",
|
|
3
|
+
"noImplicitAdditionalProperties": "throw-on-extras",
|
|
4
|
+
"controllerPathGlobs": [
|
|
5
|
+
"src/system/_controllers/**Controller.gen.ts",
|
|
6
|
+
"!src/system/_controllers/SessionController.gen.ts"
|
|
7
|
+
],
|
|
8
|
+
"spec": {
|
|
9
|
+
"outputDirectory": "src/openapi",
|
|
10
|
+
"specVersion": 3,
|
|
11
|
+
"basePath": "/api",
|
|
12
|
+
"securityDefinitions": {
|
|
13
|
+
"BearerAuth": {
|
|
14
|
+
"type": "http",
|
|
15
|
+
"scheme": "bearer",
|
|
16
|
+
"bearerFormat": "JWT"
|
|
17
|
+
},
|
|
18
|
+
"AuthIndex": {
|
|
19
|
+
"type": "apiKey",
|
|
20
|
+
"in": "header",
|
|
21
|
+
"name": "X-Auth-Index"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"routes": {
|
|
26
|
+
"routesDir": "src/system/_routes",
|
|
27
|
+
"routesFileName": "tsoa_routes.ts",
|
|
28
|
+
"basePath": "/api",
|
|
29
|
+
"middleware": "express",
|
|
30
|
+
"authenticationModule": "src/system/_middlewares/tsoaAuthentication.gen.ts"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"x-documentConfig": {
|
|
4
|
+
"documentName": "Project",
|
|
5
|
+
"isolation": [
|
|
6
|
+
{
|
|
7
|
+
"field": "tenantId",
|
|
8
|
+
"source": "user.tenantId",
|
|
9
|
+
"onMissing": "deny"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"restApi": {
|
|
13
|
+
"methods": [
|
|
14
|
+
"get",
|
|
15
|
+
"getList",
|
|
16
|
+
"post",
|
|
17
|
+
"patch",
|
|
18
|
+
"delete"
|
|
19
|
+
],
|
|
20
|
+
"joinWhitelist": [],
|
|
21
|
+
"noRelations": true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"required": [
|
|
25
|
+
"title"
|
|
26
|
+
],
|
|
27
|
+
"properties": {
|
|
28
|
+
"_id": {
|
|
29
|
+
"type": "string",
|
|
30
|
+
"x-format": "PrimaryUUID",
|
|
31
|
+
"index": true
|
|
32
|
+
},
|
|
33
|
+
"tenantId": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"index": true
|
|
36
|
+
},
|
|
37
|
+
"title": {
|
|
38
|
+
"type": "string"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"x-documentConfig": {
|
|
4
|
+
"documentName": "User",
|
|
5
|
+
"dataIsolation": {
|
|
6
|
+
"field": "_id"
|
|
7
|
+
},
|
|
8
|
+
"restApi": {
|
|
9
|
+
"methods": [
|
|
10
|
+
"get",
|
|
11
|
+
"patch"
|
|
12
|
+
],
|
|
13
|
+
"noRelations": true,
|
|
14
|
+
"joinWhitelist": []
|
|
15
|
+
},
|
|
16
|
+
"isolate": {
|
|
17
|
+
"user": false
|
|
18
|
+
},
|
|
19
|
+
"uniqueIndex": [
|
|
20
|
+
[
|
|
21
|
+
"email"
|
|
22
|
+
]
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"properties": {
|
|
26
|
+
"_id": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"x-format": "PrimaryUUID",
|
|
29
|
+
"x-vexData": "userId",
|
|
30
|
+
"index": true
|
|
31
|
+
},
|
|
32
|
+
"email": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"format": "email",
|
|
35
|
+
"index": true
|
|
36
|
+
},
|
|
37
|
+
"name": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"maxLength": 64,
|
|
40
|
+
"required": true
|
|
41
|
+
},
|
|
42
|
+
"active": {
|
|
43
|
+
"type": "boolean",
|
|
44
|
+
"default": true,
|
|
45
|
+
"required": true
|
|
46
|
+
},
|
|
47
|
+
"locale": {
|
|
48
|
+
"type": "string",
|
|
49
|
+
"maxLength": 8
|
|
50
|
+
},
|
|
51
|
+
"profileErrors": {
|
|
52
|
+
"type": "string"
|
|
53
|
+
},
|
|
54
|
+
"createdAt": {
|
|
55
|
+
"type": "string",
|
|
56
|
+
"x-format": "Timestamp",
|
|
57
|
+
"default": "onCreateTimestamp"
|
|
58
|
+
},
|
|
59
|
+
"updatedAt": {
|
|
60
|
+
"type": "string",
|
|
61
|
+
"x-format": "Timestamp",
|
|
62
|
+
"default": "onUpdateTimestamp"
|
|
63
|
+
},
|
|
64
|
+
"updatedBy": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"x-format": "UUID",
|
|
67
|
+
"default": "onUpdateUserId"
|
|
68
|
+
},
|
|
69
|
+
"deleted": {
|
|
70
|
+
"type": "boolean",
|
|
71
|
+
"default": false,
|
|
72
|
+
"x-vexData": "softDelete",
|
|
73
|
+
"description": "Soft-delete marker. Framework-managed; never client-writable. Hides the row from every ordinary query unless app.showSoftDeleted is on."
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": [
|
|
77
|
+
"name",
|
|
78
|
+
"active",
|
|
79
|
+
"deleted"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"x-documentConfig": {
|
|
4
|
+
"documentName": "UserRole",
|
|
5
|
+
"restApi": {
|
|
6
|
+
"methods": [],
|
|
7
|
+
"joinWhitelist": []
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"properties": {
|
|
11
|
+
"_id": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"x-format": "Primary"
|
|
14
|
+
},
|
|
15
|
+
"userId": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"index": true,
|
|
18
|
+
"x-foreignKey": {
|
|
19
|
+
"schemaName": "User",
|
|
20
|
+
"fieldName": "_id",
|
|
21
|
+
"relationType": "many-to-one"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"role": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"x-vexData": "role",
|
|
27
|
+
"index": true,
|
|
28
|
+
"enum": [
|
|
29
|
+
"member"
|
|
30
|
+
],
|
|
31
|
+
"x-format": "enum"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"required": [
|
|
35
|
+
"userId",
|
|
36
|
+
"role"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"jsonSchemaDir": "./schemas",
|
|
3
|
+
"rootDir": "./app",
|
|
4
|
+
"dbType": "sql",
|
|
5
|
+
"app": {
|
|
6
|
+
"enableSwagger": true,
|
|
7
|
+
"useUserSchema": true,
|
|
8
|
+
"useObjectID": true,
|
|
9
|
+
"allowApiCreateUpdate_id": false
|
|
10
|
+
},
|
|
11
|
+
"auth": {
|
|
12
|
+
"localAuth": false,
|
|
13
|
+
"useHttpOnlyCookieToken": false,
|
|
14
|
+
"oauthProviders": {
|
|
15
|
+
"google": false,
|
|
16
|
+
"github": false
|
|
17
|
+
},
|
|
18
|
+
"firebase": false
|
|
19
|
+
},
|
|
20
|
+
"generator": {
|
|
21
|
+
"commitBeforeGenerate": false
|
|
22
|
+
},
|
|
23
|
+
"useRBAC": {
|
|
24
|
+
"roles": [
|
|
25
|
+
"member"
|
|
26
|
+
],
|
|
27
|
+
"default": "member"
|
|
28
|
+
},
|
|
29
|
+
"tenant": {
|
|
30
|
+
"enable": true,
|
|
31
|
+
"IsolationMode": "preSelect"
|
|
32
|
+
},
|
|
33
|
+
"srcDir": "./app/src",
|
|
34
|
+
"sysDir": "./app/src/system",
|
|
35
|
+
"openapiDir": "./app/src/openapi"
|
|
36
|
+
}
|
package/.tmp/verify.sh
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 启动生成的应用,走一遍 注册 -> 登录 -> 换 token -> 写入 fnb.fnbOrder / kernel.kernelevent 的验证。
|
|
3
|
+
# 用法: bash .tmp/verify.sh [app_dir] (默认 /home/justin/Documents/VeryExpress/output)
|
|
4
|
+
set -u
|
|
5
|
+
APP_DIR="${1:-/home/justin/Documents/VeryExpress/output}"
|
|
6
|
+
BASE="http://127.0.0.1:3000"
|
|
7
|
+
EMAIL="vex-schema-check@example.test"
|
|
8
|
+
PASSWORD="VexCheck123!"
|
|
9
|
+
TMP="/home/justin/Documents/VeryExpress/.tmp"
|
|
10
|
+
|
|
11
|
+
cd "$APP_DIR" || exit 1
|
|
12
|
+
|
|
13
|
+
if ! curl -s -m 2 -o /dev/null "$BASE/hello" ; then
|
|
14
|
+
echo "== start server =="
|
|
15
|
+
setsid node dist/server.js > "$TMP/vex-run.log" 2>&1 < /dev/null &
|
|
16
|
+
for _ in $(seq 1 40); do sleep 1; grep -q "TypeORM DataSource initialized" "$TMP/vex-run.log" && break; done
|
|
17
|
+
tail -3 "$TMP/vex-run.log"
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
call() { # method path [extra curl args...]
|
|
21
|
+
local m="$1" p="$2"; shift 2
|
|
22
|
+
curl -s -m 10 -o "$TMP/_body.txt" -w '%{http_code}' -X "$m" "$@" "$BASE$p"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
echo "== register =="
|
|
26
|
+
echo -n "POST /api/auth/register -> "
|
|
27
|
+
call POST /api/auth/register -H 'Content-Type: application/json' -d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}"
|
|
28
|
+
echo " "; head -c 200 "$TMP/_body.txt"; echo
|
|
29
|
+
|
|
30
|
+
echo "== local login =="
|
|
31
|
+
echo -n "POST /api/auth/local -> "
|
|
32
|
+
call POST /api/auth/local -H 'Content-Type: application/json' -d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}"
|
|
33
|
+
echo " "; head -c 200 "$TMP/_body.txt"; echo
|
|
34
|
+
CODE=$(node -e 'const fs=require("fs");const b=JSON.parse(fs.readFileSync(process.argv[1],"utf8")||"{}");const u=b?.result?.url||"";const m=/code=([^&]+)/.exec(u);process.stdout.write(m?m[1]:"")' "$TMP/_body.txt")
|
|
35
|
+
echo "session code: ${CODE:-<none>}"
|
|
36
|
+
|
|
37
|
+
echo "== token =="
|
|
38
|
+
echo -n "POST /api/auth/token?code= -> "
|
|
39
|
+
call POST "/api/auth/token?code=$CODE"
|
|
40
|
+
echo " "
|
|
41
|
+
node -e '
|
|
42
|
+
const fs=require("fs");
|
|
43
|
+
const b=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));
|
|
44
|
+
const t=b?.result?.accessToken, i=b?.result?.accessTokenIndex;
|
|
45
|
+
if(t) fs.writeFileSync(process.argv[2], t), fs.writeFileSync(process.argv[3], String(i));
|
|
46
|
+
console.log("accessTokenIndex:", i, "token chars:", (t||"").length);
|
|
47
|
+
' "$TMP/_body.txt" "$TMP/_token.txt" "$TMP/_idx.txt"
|
|
48
|
+
TOKEN=$(cat "$TMP/_token.txt" 2>/dev/null || true)
|
|
49
|
+
IDX=$(cat "$TMP/_idx.txt" 2>/dev/null || true)
|
|
50
|
+
AUTH=(-H "Authorization: Bearer $TOKEN" -H "X-Auth-Index: $IDX" -H 'Content-Type: application/json')
|
|
51
|
+
|
|
52
|
+
# tenant.enable=true: the data routes refuse a token without a tenant claim. Creating the tenant
|
|
53
|
+
# returns a new token that carries `tenantId`.
|
|
54
|
+
echo "== tenant =="
|
|
55
|
+
echo -n "POST /api/tenant/create -> "
|
|
56
|
+
call POST /api/tenant/create "${AUTH[@]}" -d '{"name":"vex-schema-check"}'
|
|
57
|
+
echo " "; head -c 200 "$TMP/_body.txt"; echo
|
|
58
|
+
node -e '
|
|
59
|
+
const fs=require("fs");
|
|
60
|
+
let b={};
|
|
61
|
+
try{b=JSON.parse(fs.readFileSync(process.argv[1],"utf8"))}catch(e){}
|
|
62
|
+
const t=b?.result?.accessToken, i=b?.result?.accessTokenIndex;
|
|
63
|
+
if(t){fs.writeFileSync(process.argv[2],t);fs.writeFileSync(process.argv[3],String(i));console.log("tenanted token index:",i)}
|
|
64
|
+
else console.log("no new token (tenant may already exist)");
|
|
65
|
+
' "$TMP/_body.txt" "$TMP/_token.txt" "$TMP/_idx.txt"
|
|
66
|
+
TOKEN=$(cat "$TMP/_token.txt" 2>/dev/null || true)
|
|
67
|
+
IDX=$(cat "$TMP/_idx.txt" 2>/dev/null || true)
|
|
68
|
+
AUTH=(-H "Authorization: Bearer $TOKEN" -H "X-Auth-Index: $IDX" -H 'Content-Type: application/json')
|
|
69
|
+
|
|
70
|
+
echo "== write into fnb.fnbOrder =="
|
|
71
|
+
echo -n "POST /api/fnborder -> "
|
|
72
|
+
call POST /api/fnborder "${AUTH[@]}" -d '{"tableNo":"A12","total":38.5}'
|
|
73
|
+
echo " "; head -c 300 "$TMP/_body.txt"; echo
|
|
74
|
+
FNB_ID=$(node -e 'const fs=require("fs");try{const b=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));process.stdout.write(String(b?.result?._id||""))}catch(e){}' "$TMP/_body.txt")
|
|
75
|
+
|
|
76
|
+
echo "== write into kernel.kernelEvent =="
|
|
77
|
+
echo -n "POST /api/kernelevent -> "
|
|
78
|
+
call POST /api/kernelevent "${AUTH[@]}" -d '{"name":"schema-check"}'
|
|
79
|
+
echo " "; head -c 300 "$TMP/_body.txt"; echo
|
|
80
|
+
|
|
81
|
+
echo "== read back through the API =="
|
|
82
|
+
if [ -n "${FNB_ID:-}" ]; then
|
|
83
|
+
echo -n "GET /api/fnborder/$FNB_ID -> "
|
|
84
|
+
call GET "/api/fnborder/$FNB_ID" "${AUTH[@]}"
|
|
85
|
+
echo " "; head -c 300 "$TMP/_body.txt"; echo
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
echo "== information_schema =="
|
|
89
|
+
node -e '
|
|
90
|
+
const {Client}=require("pg"); require("dotenv").config({path:".env"});
|
|
91
|
+
const c=new Client({connectionString:process.env.SQL_URI});
|
|
92
|
+
c.connect().then(async()=>{
|
|
93
|
+
const s=await c.query("select schema_name from information_schema.schemata where schema_name in ($1,$2)",["fnb","kernel"]);
|
|
94
|
+
const t=await c.query("select table_schema, table_name from information_schema.tables where table_schema in ($1,$2) order by 1,2",["fnb","kernel"]);
|
|
95
|
+
const r=await c.query("select _id, \"tableNo\", total from fnb.\"fnborder\" order by \"tableNo\" limit 3");
|
|
96
|
+
const k=await c.query("select _id, name from kernel.\"kernelevent\" order by name desc limit 3");
|
|
97
|
+
console.log("schemas:", s.rows.map(x=>x.schema_name).join(","));
|
|
98
|
+
console.log("tables:", JSON.stringify(t.rows));
|
|
99
|
+
console.log("fnb.fnbOrder rows:", JSON.stringify(r.rows));
|
|
100
|
+
console.log("kernel.kernelEvent rows:", JSON.stringify(k.rows));
|
|
101
|
+
await c.end();
|
|
102
|
+
}).catch(e=>{console.error("SQL FAIL:", e.message);});
|
|
103
|
+
'
|
package/.tmp/verify2.sh
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 启动生成的应用,走一遍 注册 -> 登录 -> 换 token -> 写入 fnb.fnbOrder / kernel.kernelevent 的验证。
|
|
3
|
+
# 用法: bash .tmp/verify.sh [app_dir] (默认 /home/justin/Documents/VeryExpress/output)
|
|
4
|
+
set -u
|
|
5
|
+
APP_DIR="${1:-/home/justin/Documents/VeryExpress/output}"
|
|
6
|
+
BASE="http://127.0.0.1:3000"
|
|
7
|
+
EMAIL="vex-schema-check@example.test"
|
|
8
|
+
PASSWORD="VexCheck123!"
|
|
9
|
+
TMP="/home/justin/Documents/VeryExpress/.tmp"
|
|
10
|
+
|
|
11
|
+
cd "$APP_DIR" || exit 1
|
|
12
|
+
|
|
13
|
+
if ! curl -s -m 2 -o /dev/null "$BASE/hello" ; then
|
|
14
|
+
echo "== start server =="
|
|
15
|
+
setsid node dist/server.js > "$TMP/vex-run.log" 2>&1 < /dev/null &
|
|
16
|
+
for _ in $(seq 1 40); do sleep 1; grep -q "TypeORM DataSource initialized" "$TMP/vex-run.log" && break; done
|
|
17
|
+
tail -3 "$TMP/vex-run.log"
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
call() { # method path [extra curl args...]
|
|
21
|
+
local m="$1" p="$2"; shift 2
|
|
22
|
+
curl -s -m 10 -o "$TMP/_body.txt" -w '%{http_code}' -X "$m" "$@" "$BASE$p"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
echo "== register =="
|
|
26
|
+
echo -n "POST /api/auth/register -> "
|
|
27
|
+
call POST /api/auth/register -H 'Content-Type: application/json' -d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}"
|
|
28
|
+
echo " "; head -c 200 "$TMP/_body.txt"; echo
|
|
29
|
+
|
|
30
|
+
echo "== local login =="
|
|
31
|
+
echo -n "POST /api/auth/local -> "
|
|
32
|
+
call POST /api/auth/local -H 'Content-Type: application/json' -d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}"
|
|
33
|
+
echo " "; head -c 200 "$TMP/_body.txt"; echo
|
|
34
|
+
CODE=$(node -e 'const fs=require("fs");const b=JSON.parse(fs.readFileSync(process.argv[1],"utf8")||"{}");const u=b?.result?.url||"";const m=/code=([^&]+)/.exec(u);process.stdout.write(m?m[1]:"")' "$TMP/_body.txt")
|
|
35
|
+
echo "session code: ${CODE:-<none>}"
|
|
36
|
+
|
|
37
|
+
echo "== token =="
|
|
38
|
+
echo -n "POST /api/auth/token?code= -> "
|
|
39
|
+
call POST "/api/auth/token?code=$CODE"
|
|
40
|
+
echo " "
|
|
41
|
+
node -e '
|
|
42
|
+
const fs=require("fs");
|
|
43
|
+
const b=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));
|
|
44
|
+
const t=b?.result?.accessToken, i=b?.result?.accessTokenIndex;
|
|
45
|
+
if(t) fs.writeFileSync(process.argv[2], t), fs.writeFileSync(process.argv[3], String(i));
|
|
46
|
+
console.log("accessTokenIndex:", i, "token chars:", (t||"").length);
|
|
47
|
+
' "$TMP/_body.txt" "$TMP/_token.txt" "$TMP/_idx.txt"
|
|
48
|
+
TOKEN=$(cat "$TMP/_token.txt" 2>/dev/null || true)
|
|
49
|
+
IDX=$(cat "$TMP/_idx.txt" 2>/dev/null || true)
|
|
50
|
+
AUTH=(-H "Authorization: Bearer $TOKEN" -H "X-Auth-Index: $IDX" -H 'Content-Type: application/json')
|
|
51
|
+
|
|
52
|
+
# tenant.enable=true: the data routes refuse a token without a tenant claim. Creating the tenant
|
|
53
|
+
# returns a new token that carries `tenantId`.
|
|
54
|
+
echo "== tenant =="
|
|
55
|
+
echo -n "POST /api/tenant/create -> "
|
|
56
|
+
call POST /api/tenant/create "${AUTH[@]}" -d '{"name":"vex-schema-check"}'
|
|
57
|
+
echo " "; head -c 200 "$TMP/_body.txt"; echo
|
|
58
|
+
node -e '
|
|
59
|
+
const fs=require("fs");
|
|
60
|
+
let b={};
|
|
61
|
+
try{b=JSON.parse(fs.readFileSync(process.argv[1],"utf8"))}catch(e){}
|
|
62
|
+
const t=b?.result?.accessToken, i=b?.result?.accessTokenIndex;
|
|
63
|
+
if(t){fs.writeFileSync(process.argv[2],t);fs.writeFileSync(process.argv[3],String(i));console.log("tenanted token index:",i)}
|
|
64
|
+
else console.log("no new token (tenant may already exist)");
|
|
65
|
+
' "$TMP/_body.txt" "$TMP/_token.txt" "$TMP/_idx.txt"
|
|
66
|
+
TOKEN=$(cat "$TMP/_token.txt" 2>/dev/null || true)
|
|
67
|
+
IDX=$(cat "$TMP/_idx.txt" 2>/dev/null || true)
|
|
68
|
+
AUTH=(-H "Authorization: Bearer $TOKEN" -H "X-Auth-Index: $IDX" -H 'Content-Type: application/json')
|
|
69
|
+
|
|
70
|
+
echo "== write into fnb.fnbOrder =="
|
|
71
|
+
echo -n "POST /api/fnborder -> "
|
|
72
|
+
call POST /api/fnborder "${AUTH[@]}" -d '{"tableNo":"A12","total":38.5}'
|
|
73
|
+
echo " "; head -c 300 "$TMP/_body.txt"; echo
|
|
74
|
+
FNB_ID=$(node -e 'const fs=require("fs");try{const b=JSON.parse(fs.readFileSync(process.argv[1],"utf8"));process.stdout.write(String(b?.result?._id||""))}catch(e){}' "$TMP/_body.txt")
|
|
75
|
+
|
|
76
|
+
echo "== write into kernel.kernelEvent =="
|
|
77
|
+
echo -n "POST /api/kernelevent -> "
|
|
78
|
+
call POST /api/kernelevent "${AUTH[@]}" -d '{"name":"schema-check"}'
|
|
79
|
+
echo " "; head -c 300 "$TMP/_body.txt"; echo
|
|
80
|
+
|
|
81
|
+
echo "== read back through the API =="
|
|
82
|
+
if [ -n "${FNB_ID:-}" ]; then
|
|
83
|
+
echo -n "GET /api/fnborder/$FNB_ID -> "
|
|
84
|
+
call GET "/api/fnborder/$FNB_ID" "${AUTH[@]}"
|
|
85
|
+
echo " "; head -c 300 "$TMP/_body.txt"; echo
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
echo "== information_schema =="
|
|
89
|
+
node -e '
|
|
90
|
+
const {Client}=require("pg"); require("dotenv").config({path:".env"});
|
|
91
|
+
const c=new Client({connectionString:process.env.SQL_URI});
|
|
92
|
+
c.connect().then(async()=>{
|
|
93
|
+
const s=await c.query("select schema_name from information_schema.schemata where schema_name in ($1,$2)",["fnb","kernel"]);
|
|
94
|
+
const t=await c.query("select table_schema, table_name from information_schema.tables where table_schema in ($1,$2) order by 1,2",["fnb","kernel"]);
|
|
95
|
+
const r=await c.query("select _id, \"tableNo\", total from fnb.\"fnborder\" order by \"tableNo\" limit 3");
|
|
96
|
+
const k=await c.query("select _id, name from kernel.\"kernelevent\" order by name desc limit 3");
|
|
97
|
+
console.log("schemas:", s.rows.map(x=>x.schema_name).join(","));
|
|
98
|
+
console.log("tables:", JSON.stringify(t.rows));
|
|
99
|
+
console.log("fnb.fnbOrder rows:", JSON.stringify(r.rows));
|
|
100
|
+
console.log("kernel.kernelEvent rows:", JSON.stringify(k.rows));
|
|
101
|
+
await c.end();
|
|
102
|
+
}).catch(e=>{console.error("SQL FAIL:", e.message);});
|
|
103
|
+
'
|