@simitgroup/simpleapp-generator 1.6.6-j-alpha → 1.6.6-k-alpha
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/ReleaseNote.md +3 -2
- package/dist/buildinschemas/docnoformat.js +6 -6
- package/dist/buildinschemas/docnoformat.js.map +1 -1
- package/dist/buildinschemas/documentevent.js +1 -1
- package/dist/buildinschemas/documentevent.js.map +1 -1
- package/dist/buildinschemas/organization.js +1 -1
- package/dist/buildinschemas/organization.js.map +1 -1
- package/dist/buildinschemas/tenant.js +1 -1
- package/dist/buildinschemas/tenant.js.map +1 -1
- package/dist/buildinschemas/user.js +2 -2
- package/dist/buildinschemas/user.js.map +1 -1
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +2 -0
- package/dist/framework.js.map +1 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +21 -20
- package/dist/generate.js.map +1 -1
- package/dist/processors/jrxmlbuilder.js +3 -3
- package/dist/processors/jrxmlbuilder.js.map +1 -1
- package/dist/processors/jsonschemabuilder.d.ts.map +1 -1
- package/dist/processors/jsonschemabuilder.js +17 -10
- package/dist/processors/jsonschemabuilder.js.map +1 -1
- package/dist/type.d.ts +1 -1
- package/dist/type.d.ts.map +1 -1
- package/package.json +2 -3
- package/reset-install.sh +3 -0
- package/src/buildinschemas/docnoformat.ts +6 -6
- package/src/buildinschemas/documentevent.ts +1 -1
- package/src/buildinschemas/organization.ts +1 -1
- package/src/buildinschemas/tenant.ts +1 -1
- package/src/buildinschemas/user.ts +2 -2
- package/src/framework.ts +2 -1
- package/src/generate.ts +22 -20
- package/src/processors/jrxmlbuilder.ts +3 -3
- package/src/processors/jsonschemabuilder.ts +27 -14
- package/src/type.ts +1 -1
- package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +3 -3
- package/templates/nest/.gitignore.eta +4 -5
- package/templates/nest/src/{app.module.ts.eta → app.module.ts._eta} +2 -2
- package/templates/nest/src/{main.ts.eta → main.ts._eta} +2 -2
- package/templates/nest/src/printapi/printapi.service.ts.eta +7 -8
- package/templates/nest/src/simpleapp/.gitignore.eta +1 -1
- package/templates/nest/src/simpleapp/generate/commons/audittrail.service.ts.eta +2 -2
- package/templates/nest/src/simpleapp/generate/commons/customkeycloa.guard.ts.eta +14 -12
- package/templates/nest/src/simpleapp/generate/commons/customkeycloak.guard.ts.eta +36 -42
- package/templates/nest/src/simpleapp/generate/commons/docnogenerator.service.ts.eta +6 -3
- package/templates/nest/src/simpleapp/generate/commons/encryption.static.ts.eta +56 -61
- package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +65 -88
- package/templates/nest/src/simpleapp/generate/commons/robotuser.service.ts.eta +10 -9
- package/templates/nest/src/simpleapp/generate/commons/roles/roles.guard.ts.eta +10 -3
- package/templates/nest/src/simpleapp/generate/commons/runwebhook.service.ts.eta +41 -39
- package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +439 -293
- package/templates/nest/src/simpleapp/generate/processors/autoinc.processor.ts.eta +20 -5
- package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +437 -40
- package/templates/nest/src/simpleapp/profile/{profile.controller.ts.eta → profile.controller.ts._eta} +2 -2
- package/templates/nest/src/simpleapp/profile/{profile.service.ts.eta → profile.service.ts._eta} +2 -2
- package/templates/nest/src/simpleapp/simpleapp.module.ts.eta +15 -4
- package/templates/nuxt/components/button/ButtonMultiple.vue._eta +1 -1
- package/templates/nuxt/components/calendar/{CalendarByResource.vue.eta → CalendarByResource.vue._eta} +2 -2
- package/templates/nuxt/components/calendar/{CalendarInput.vue.eta → CalendarInput.vue._eta} +2 -2
- package/templates/nuxt/components/calendar/{CalendarSmall.vue.eta → CalendarSmall.vue._eta} +6 -0
- package/templates/nuxt/components/debug/{DebugDocumentData.vue.eta → DebugDocumentData.vue._eta} +2 -2
- package/templates/nuxt/components/form/{FormDocnoformat.vue.eta → FormDocnoformat.vue._eta} +2 -1
- package/templates/nuxt/components/form/user/{FormUserPermission.vue.eta → FormUserPermission.vue._eta} +6 -0
- package/templates/nuxt/components/header/{HeaderBreadcrumb.vue.eta → HeaderBreadcrumb.vue._eta} +2 -2
- package/templates/nuxt/components/header/button/{HeaderButtonProfile.vue.eta → HeaderButtonProfile.vue._eta} +2 -2
- package/templates/nuxt/components/header/button/task/{HeaderButtonTaskList.vue.eta → HeaderButtonTaskList.vue._eta} +2 -2
- package/templates/nuxt/components/image/ImageAvatar.vue.eta +29 -30
- package/templates/nuxt/components/image/ImageOrganization.vue.eta +15 -9
- package/templates/nuxt/components/image/ImageToBase64Uploader.vue.eta +28 -18
- package/templates/nuxt/components/list/{ListDocumentTable.vue.eta → ListDocumentTable.vue._eta} +2 -2
- package/templates/nuxt/components/list/{ListItem.vue.eta → ListItem.vue._eta} +2 -2
- package/templates/nuxt/components/list/{ListMessages.vue.eta → ListMessages.vue._eta} +6 -0
- package/templates/nuxt/components/list/{ListView.vue.eta → ListView.vue._eta} +2 -2
- package/templates/nuxt/components/overlay/{OverlayPanelWithToolBar.vue.eta → OverlayPanelWithToolBar.vue._eta} +2 -2
- package/templates/nuxt/components/overlay/{OverlaySideBarCrud.vue.eta → OverlaySideBarCrud.vue._eta} +2 -2
- package/templates/nuxt/components/overlay/{OverlayViewer.vue.eta → OverlayViewer.vue._eta} +2 -2
- package/templates/nuxt/components/page/{PageDocList.vue.eta → PageDocList.vue._eta} +2 -2
- package/templates/nuxt/components/renderer/{RendererDateTime.vue.eta → RendererDateTime.vue._eta} +2 -2
- package/templates/nuxt/components/renderer/{RendererDocHistories.vue.eta → RendererDocHistories.vue._eta} +6 -0
- package/templates/nuxt/components/renderer/{RendererForeignKey.vue.eta → RendererForeignKey.vue._eta} +2 -2
- package/templates/nuxt/components/renderer/{RendererLink.vue.eta → RendererLink.vue._eta} +2 -2
- package/templates/nuxt/components/renderer/{RendererTime.vue.eta → RendererTime.vue._eta} +2 -2
- package/templates/nuxt/components/renderer/{RendererViewer.vue.eta → RendererViewer.vue._eta} +2 -2
- package/templates/nuxt/components/select/{SelectTemplate.vue.eta → SelectTemplate.vue._eta} +2 -2
- package/templates/nuxt/components/session/{SessionBlock.vue.eta → SessionBlock.vue._eta} +2 -2
- package/templates/nuxt/components/simpleApp/SimpleAppAutocomplete.vue.eta +55 -55
- package/templates/nuxt/components/simpleApp/SimpleAppCalendarInput.vue.eta +13 -11
- package/templates/nuxt/components/simpleApp/SimpleAppChildrenList.vue.eta +6 -3
- package/templates/nuxt/components/simpleApp/SimpleAppDocumentNo.vue.eta +32 -27
- package/templates/nuxt/components/simpleApp/SimpleAppFieldContainer.vue.eta +19 -28
- package/templates/nuxt/components/simpleApp/SimpleAppInput.vue.eta +114 -105
- package/templates/nuxt/components/simpleApp/SimpleAppInputTable.vue.eta +3 -3
- package/templates/nuxt/components/simpleApp/SimpleAppJsonSchemaForm.vue.eta +1 -1
- package/templates/nuxt/components/simpleApp/SimpleAppUserPicker.vue.eta +10 -12
- package/templates/nuxt/components/table/{TableDocuments.vue.eta → TableDocuments.vue._eta} +2 -2
- package/templates/nuxt/components/user/{UserButtonPermissionInfo.vue.eta → UserButtonPermissionInfo.vue._eta} +2 -2
- package/templates/nuxt/components/user/{UserInvitation.vue.eta → UserInvitation.vue._eta} +2 -2
- package/templates/nuxt/components/user/{UserProfileListItem.vue.eta → UserProfileListItem.vue._eta} +2 -2
- package/templates/nuxt/components/user/{UserTenantPicker.vue.eta → UserTenantPicker.vue._eta} +2 -2
- package/templates/nuxt/composables/getOpenApi.generate.ts.eta +11 -3
- package/templates/nuxt/composables/getUserStore.generate.ts.eta +1 -1
- package/templates/nuxt/composables/graphquery.generate.ts.eta +1 -1
- package/templates/nuxt/composables/recently.generate.ts.eta +0 -1
- package/templates/nuxt/composables/stringHelper.generate.ts.eta +5 -2
- package/templates/nuxt/pages/[xorg]/docnoformat/[id].vue.eta +0 -1
- package/templates/nuxt/pages/[xorg]/{docnoformat.vue.eta → docnoformat.vue._eta} +1 -0
- package/templates/nuxt/pages/[xorg]/organization/[id].vue.eta +13 -9
- package/templates/nuxt/pages/[xorg]/organization/new.vue.eta +10 -12
- package/templates/nuxt/pages/[xorg]/{user.vue.eta → user.vue._eta} +2 -2
- package/templates/nuxt/pages/{profile.vue.eta → profile.vue._eta} +2 -2
- package/templates/nuxt/plugins/10.simpleapp-event.ts.eta +6 -0
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +89 -12
- package/templates/nuxt/plugins/40.pusher.ts.eta +6 -9
- package/templates/nuxt/providers/my-provider.ts.eta +1 -1
- package/templates/nuxt/server/api/profile/[...].ts.eta +4 -3
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +8 -4
- package/templates/nuxt/types/schema.ts.eta +1 -1
- package/templates/nuxt/types/user.ts.eta +6 -1
- package/templates/project/jsonschemas/appintegration.json_eta +227 -0
- package/templates/project/sharelibs/validate.ts.eta +1 -1
- package/dist/buildinschemas/message.d.ts +0 -3
- package/dist/buildinschemas/message.d.ts.map +0 -1
- package/dist/buildinschemas/message.js +0 -34
- package/dist/buildinschemas/message.js.map +0 -1
- package/dist/buildinschemas/webhookhistory.d.ts +0 -3
- package/dist/buildinschemas/webhookhistory.d.ts.map +0 -1
- package/dist/buildinschemas/webhookhistory.js +0 -44
- package/dist/buildinschemas/webhookhistory.js.map +0 -1
- package/dist/createproject.js +0 -138
- package/dist/createproject.js.map +0 -1
- package/dist/generate-allow-changebackend.js +0 -305
- package/dist/generate-allow-changebackend.js.map +0 -1
- package/dist/index2.js +0 -118
- package/dist/index2.js.map +0 -1
- package/dist/installdependency.js +0 -20
- package/dist/installdependency.js.map +0 -1
- package/dist/installnest.js +0 -2
- package/dist/installnest.js.map +0 -1
- package/dist/installnuxt.js +0 -2
- package/dist/installnuxt.js.map +0 -1
- package/dist/processors/groupsbuilder.js +0 -2
- package/dist/processors/groupsbuilder.js.map +0 -1
- package/dist/schematype/baseschema.js +0 -25
- package/dist/schematype/baseschema.js.map +0 -1
- package/dist/schematype/default.js +0 -2
- package/dist/schematype/default.js.map +0 -1
- package/dist/schematype/index.js +0 -12
- package/dist/schematype/index.js.map +0 -1
- package/dist/schematype/primarymasterdata.js +0 -38
- package/dist/schematype/primarymasterdata.js.map +0 -1
- package/dist/schematype/simple.js +0 -24
- package/dist/schematype/simple.js.map +0 -1
- package/dist/schematype/simplemasterdata.js +0 -31
- package/dist/schematype/simplemasterdata.js.map +0 -1
- package/dist/schematype/transaction.js +0 -74
- package/dist/schematype/transaction.js.map +0 -1
|
@@ -10,20 +10,22 @@ import { ResourceGuard } from 'nest-keycloak-connect';
|
|
|
10
10
|
|
|
11
11
|
@Injectable()
|
|
12
12
|
export class CustomKeycloakGuard implements CanActivate {
|
|
13
|
-
constructor(
|
|
13
|
+
constructor(
|
|
14
|
+
private reflector: Reflector,
|
|
15
|
+
private resourceGuard: ResourceGuard,
|
|
16
|
+
) {}
|
|
14
17
|
|
|
15
18
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
16
19
|
const request = context.switchToHttp().getRequest();
|
|
17
|
-
|
|
18
20
|
|
|
19
|
-
//graphql no http request, exclude from capability of x-
|
|
20
|
-
if(request?.headers){
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
//graphql no http request, exclude from capability of x-apikey
|
|
22
|
+
if (request?.headers) {
|
|
23
|
+
const apiKey = request.headers['x-apikey'];
|
|
24
|
+
const apiSecret = request.headers['x-apisecret'];
|
|
25
|
+
// validate apikey and apisecret at middleware level, reach here mean approved as robot
|
|
26
|
+
if (apiKey && apiSecret) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
// If API key is not present, fall back to Keycloak authentication
|
|
@@ -35,9 +37,9 @@ export class CustomKeycloakGuard implements CanActivate {
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
private validateApiKey(apiKey: string, apiSecret: string): boolean {
|
|
40
|
+
private validateApiKey(apiKey: string, apiSecret: string): boolean {
|
|
39
41
|
// Implement your API key and secret validation logic here
|
|
40
42
|
// This is just a simple example
|
|
41
43
|
return apiKey === 'your-valid-api-key' && apiSecret === 'your-valid-api-secret';
|
|
42
44
|
}
|
|
43
|
-
}
|
|
45
|
+
}
|
|
@@ -4,48 +4,42 @@
|
|
|
4
4
|
* last change 2024-06-21
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const apiKey = request.headers['x-api-key'];
|
|
29
|
-
const apiSecret = request.headers['x-api-secret'];
|
|
30
|
-
// validate apikey and apisecret at middleware level, reach here mean approved as robot
|
|
31
|
-
if (apiKey && apiSecret) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// If API key is not present, fall back to Keycloak authentication
|
|
37
|
-
try {
|
|
38
|
-
const canActivate = await this.resourceGuard.canActivate(context);
|
|
39
|
-
return canActivate as boolean;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
throw new UnauthorizedException('Invalid API key or Keycloak token');
|
|
7
|
+
import { Injectable, CanActivate, ExecutionContext, UnauthorizedException } from '@nestjs/common';
|
|
8
|
+
import { Reflector } from '@nestjs/core';
|
|
9
|
+
import { ResourceGuard } from 'nest-keycloak-connect';
|
|
10
|
+
|
|
11
|
+
@Injectable()
|
|
12
|
+
export class CustomKeycloakGuard implements CanActivate {
|
|
13
|
+
constructor(
|
|
14
|
+
private reflector: Reflector,
|
|
15
|
+
private resourceGuard: ResourceGuard,
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
19
|
+
const request = context.switchToHttp().getRequest();
|
|
20
|
+
|
|
21
|
+
//graphql no http request, exclude from capability of x-apikey
|
|
22
|
+
if (request?.headers) {
|
|
23
|
+
const apiKey = request.headers['x-apikey'];
|
|
24
|
+
const apiSecret = request.headers['x-apisecret'];
|
|
25
|
+
// validate apikey and apisecret at middleware level, reach here mean approved as robot
|
|
26
|
+
if (apiKey && apiSecret) {
|
|
27
|
+
return true;
|
|
42
28
|
}
|
|
43
29
|
}
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
|
|
31
|
+
// If API key is not present, fall back to Keycloak authentication
|
|
32
|
+
try {
|
|
33
|
+
const canActivate = await this.resourceGuard.canActivate(context);
|
|
34
|
+
return canActivate as boolean;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new UnauthorizedException('Invalid API key or Keycloak token');
|
|
37
|
+
}
|
|
50
38
|
}
|
|
51
|
-
|
|
39
|
+
|
|
40
|
+
// private validateApiKey(apiKey: string, apiSecret: string): boolean {
|
|
41
|
+
// // Implement your API key and secret validation logic here
|
|
42
|
+
// // This is just a simple example
|
|
43
|
+
// return apiKey === 'your-valid-api-key' && apiSecret === 'your-valid-api-secret';
|
|
44
|
+
// }
|
|
45
|
+
}
|
|
@@ -47,12 +47,15 @@ export class DocNumberFormatGenerator {
|
|
|
47
47
|
id: string = '',
|
|
48
48
|
) => {
|
|
49
49
|
doctype = doctype.toUpperCase();
|
|
50
|
-
|
|
50
|
+
const filter = { docNoType: doctype, active: true };
|
|
51
51
|
if (id) {
|
|
52
52
|
filter['_id'] = id;
|
|
53
53
|
}
|
|
54
|
+
//
|
|
54
55
|
Object.assign(filter, appuser.getBranchFilter());
|
|
55
|
-
const result = await this.docformat
|
|
56
|
+
const result = await this.docformat
|
|
57
|
+
.find(filter)
|
|
58
|
+
.session(appuser.getDBSession());
|
|
56
59
|
//search(appuser, filter);
|
|
57
60
|
if (result && result.length > 0) {
|
|
58
61
|
const d: Docnoformat = result[0];
|
|
@@ -79,7 +82,7 @@ export class DocNumberFormatGenerator {
|
|
|
79
82
|
}
|
|
80
83
|
} else {
|
|
81
84
|
throw new BadRequestException(
|
|
82
|
-
`
|
|
85
|
+
`No active document number found for ${doctype}. Please update in Settings > Document Numbering Format`,
|
|
83
86
|
);
|
|
84
87
|
}
|
|
85
88
|
};
|
|
@@ -3,76 +3,71 @@
|
|
|
3
3
|
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
4
|
* last change 2023-10-31
|
|
5
5
|
* Author: Ks Tan
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* this class developed for implement field level encryption, however it still half way and keep here for future enhancement
|
|
8
8
|
* it doesn't effect anything at the moment
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { Injectable } from '@nestjs/common';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
createCipheriv,
|
|
14
|
+
createDecipheriv,
|
|
15
|
+
randomBytes,
|
|
16
|
+
scrypt,
|
|
17
|
+
Cipher,
|
|
18
|
+
Decipher,
|
|
19
|
+
} from 'crypto';
|
|
13
20
|
import { promisify } from 'util';
|
|
14
21
|
|
|
22
|
+
export class Encryption {
|
|
23
|
+
private static instance: Encryption;
|
|
24
|
+
private algorithm = 'aes-256-ctr';
|
|
25
|
+
private iv = randomBytes(16);
|
|
26
|
+
private password = String(process.env.ENRYPTION_KEY);
|
|
15
27
|
|
|
28
|
+
private key: Buffer;
|
|
16
29
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
private key :Buffer
|
|
24
|
-
|
|
25
|
-
constructor(){
|
|
26
|
-
this.init();
|
|
27
|
-
}
|
|
28
|
-
public static getInstance(): Encryption {
|
|
29
|
-
if (!Encryption.instance) {
|
|
30
|
-
Encryption.instance = new Encryption();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return Encryption.instance;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
async init (){
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
console.log("Initialized encryption class")
|
|
30
|
+
constructor() {
|
|
31
|
+
this.init();
|
|
32
|
+
}
|
|
33
|
+
public static getInstance(): Encryption {
|
|
34
|
+
if (!Encryption.instance) {
|
|
35
|
+
Encryption.instance = new Encryption();
|
|
42
36
|
}
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
38
|
+
return Encryption.instance;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async init() {
|
|
42
|
+
// console.log('Initialized encryption class');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getKey = async (salt) => {
|
|
46
|
+
const key = (await promisify(scrypt)(this.password, salt, 32)) as Buffer;
|
|
47
|
+
return key;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
encrypt = async (value: string) => {
|
|
51
|
+
const salt = 'salt';
|
|
52
|
+
const key = await this.getKey(salt);
|
|
53
|
+
const cipher = createCipheriv(this.algorithm, key, this.iv);
|
|
54
|
+
// console.log('Encrypting text ', value, cipher);
|
|
55
|
+
const encryptedText = Buffer.concat([
|
|
56
|
+
cipher.update(value),
|
|
57
|
+
cipher.final(),
|
|
58
|
+
]).toString('hex');
|
|
59
|
+
// console.log('encryptedText', encryptedText);
|
|
60
|
+
return encryptedText;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
decrypt = async (value: string, salt: string) => {
|
|
64
|
+
const key = await this.getKey(salt);
|
|
65
|
+
const decipher = createDecipheriv('aes-256-ctr', key, this.iv);
|
|
66
|
+
const buf = Buffer.from(value);
|
|
67
|
+
const decryptedText = Buffer.concat([
|
|
68
|
+
decipher.update(buf),
|
|
69
|
+
decipher.final(),
|
|
70
|
+
]).toString('hex');
|
|
71
|
+
return decryptedText;
|
|
72
|
+
};
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
@@ -4,135 +4,112 @@
|
|
|
4
4
|
* last change 2024-03-17
|
|
5
5
|
* Author: Ks Tan
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Logger,
|
|
11
|
-
Scope,
|
|
12
|
-
Inject,
|
|
13
|
-
BadRequestException,
|
|
14
|
-
} from '@nestjs/common';
|
|
15
|
-
import { Request, Response, NextFunction } from 'express';
|
|
7
|
+
|
|
8
|
+
import Base64URL from '@darkwolf/base64url';
|
|
9
|
+
import { BadRequestException, Injectable, Logger, NestMiddleware } from '@nestjs/common';
|
|
16
10
|
import { InjectModel } from '@nestjs/mongoose';
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
import { User } from '../../types/user.type';
|
|
11
|
+
import { NextFunction, Request, Response } from 'express';
|
|
12
|
+
import { Model } from 'mongoose';
|
|
20
13
|
import { Permission } from '../../types/perm.type';
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
const Base64URL = require('@darkwolf/base64url');
|
|
24
|
-
// import * as jwt from 'nestjs-jwt'
|
|
25
|
-
|
|
14
|
+
import { User } from '../../types/user.type';
|
|
15
|
+
import { Appintegration } from '../../types/appintegration.type';
|
|
26
16
|
import { UserContext } from '../user.context';
|
|
27
|
-
|
|
17
|
+
|
|
28
18
|
@Injectable()
|
|
29
19
|
export class TenantMiddleware implements NestMiddleware {
|
|
30
|
-
protected
|
|
31
|
-
|
|
32
|
-
protected
|
|
33
|
-
|
|
20
|
+
protected defaultXOrg = Base64URL.encodeText('0-0-0');
|
|
21
|
+
|
|
22
|
+
protected excludeXOrgPaths = ['/profile', '/profile/tenant', '/profile/session'];
|
|
23
|
+
|
|
24
|
+
private readonly logger = new Logger(this.constructor.name);
|
|
25
|
+
|
|
34
26
|
constructor(
|
|
35
|
-
@InjectModel('User') private readonly
|
|
36
|
-
@InjectModel('Permission') private readonly
|
|
27
|
+
@InjectModel('User') private readonly userModel: Model<User>,
|
|
28
|
+
@InjectModel('Permission') private readonly permModel: Model<Permission>,
|
|
29
|
+
@InjectModel('Appintegration') private readonly appModel: Model<Appintegration>,
|
|
37
30
|
) {}
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.logger.verbose('requireXorg = false');
|
|
32
|
+
requireXOrg(baseurl: string): boolean {
|
|
33
|
+
for (let i = 0; i < this.excludeXOrgPaths.length; i++) {
|
|
34
|
+
if (baseurl.includes(this.excludeXOrgPaths[i])) {
|
|
35
|
+
this.logger.verbose('requireXOrg = false');
|
|
44
36
|
return false;
|
|
45
37
|
}
|
|
46
38
|
}
|
|
47
|
-
// console.log("Require xorg")
|
|
48
39
|
return true;
|
|
49
40
|
}
|
|
41
|
+
|
|
50
42
|
async use(req: Request, res: Response, next: NextFunction) {
|
|
51
43
|
if (req.baseUrl == '/oauth2-redirect.html') {
|
|
52
44
|
next();
|
|
53
45
|
return;
|
|
54
46
|
}
|
|
55
|
-
|
|
47
|
+
|
|
48
|
+
let tokenStr: string = req.get('authorization') ?? '';
|
|
49
|
+
tokenStr = tokenStr.replace('Bearer ', '');
|
|
50
|
+
const xOrg = req.get('x-org') ?? this.defaultXOrg;
|
|
51
|
+
|
|
52
|
+
const user = new UserContext(this.userModel, this.permModel, this.appModel);
|
|
56
53
|
|
|
57
54
|
if (req.baseUrl == '/graphql') {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const xorg = req.headers['x-org'] ?? this.defaultxorg;
|
|
61
|
-
if (tokenstr) {
|
|
62
|
-
await u.setCurrentUserInfo(tokenstr, xorg);
|
|
55
|
+
if (tokenStr) {
|
|
56
|
+
await user.setCurrentUserInfo(tokenStr, xOrg);
|
|
63
57
|
}
|
|
64
|
-
req['sessionuser'] =
|
|
58
|
+
req['sessionuser'] = user;
|
|
65
59
|
next();
|
|
66
60
|
return;
|
|
67
61
|
}
|
|
68
|
-
this.logger.debug(`
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
//if APIKEY defined, and there is api key and secret supplied. use robot user
|
|
72
|
-
if(process.env.X_API_KEY &&req.headers['x-api-key'] && req.headers['x-api-secret']){
|
|
73
|
-
|
|
74
|
-
if(req.headers['x-api-key']==process.env.X_API_KEY &&
|
|
75
|
-
req.headers['x-api-secret']==process.env.X_API_SECRET){
|
|
62
|
+
this.logger.debug(`Running TenantMiddleware for ${req.baseUrl}`);
|
|
76
63
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
if(req.headers['x-guest-accesstoken']) {
|
|
85
|
-
u.setGuestToken(<string>req.headers['x-guest-accesstoken']);
|
|
64
|
+
// If X_APIKEY defined, and there is api key and secret supplied. use robot user
|
|
65
|
+
if (process.env.X_APIKEY && req.get('x-apikey') && req.get('x-apisecret')) {
|
|
66
|
+
if (req.get('x-apikey') == process.env.X_APIKEY && req.get('x-apisecret') == process.env.X_APISECRET) {
|
|
67
|
+
user.setAsStaticUser('00000000-0000-0000-0000-000000000000', 'robot', 'Robot', 'robot@a.org', req.get('x-org') ?? this.defaultXOrg);
|
|
68
|
+
if (req.get('x-guest-accesstoken')) {
|
|
69
|
+
user.setGuestToken(req.get('x-guest-accesstoken'));
|
|
86
70
|
}
|
|
87
|
-
req['sessionuser'] =
|
|
71
|
+
req['sessionuser'] = user;
|
|
88
72
|
next();
|
|
89
73
|
return;
|
|
90
|
-
}else{
|
|
91
|
-
this.logger.log('
|
|
92
|
-
throw new BadRequestException('
|
|
74
|
+
} else {
|
|
75
|
+
this.logger.log('Invalid API Key / Secret');
|
|
76
|
+
throw new BadRequestException('Invalid API Key / Secret');
|
|
93
77
|
}
|
|
94
78
|
}
|
|
95
79
|
|
|
96
|
-
if (!req.
|
|
97
|
-
this.logger.log('
|
|
98
|
-
return res.status(401).send('Undefine
|
|
80
|
+
if (!req.get('authorization')) {
|
|
81
|
+
this.logger.log('Undefine Bearer Token');
|
|
82
|
+
return res.status(401).send('Undefine Bearer Token');
|
|
99
83
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
);
|
|
105
|
-
throw new BadRequestException('undefine header string x-org');
|
|
106
|
-
// return res.status(401).send('undefine header string x-org');
|
|
84
|
+
|
|
85
|
+
if (!req.get('x-org') && this.requireXOrg(req.baseUrl)) {
|
|
86
|
+
this.logger.log('Undefine header X-Org and require that at ' + req.baseUrl, 'TenantMiddleware');
|
|
87
|
+
throw new BadRequestException('Undefine header X-Org');
|
|
107
88
|
}
|
|
108
|
-
// const session = await this.connection.startSession();
|
|
109
|
-
// console.log("line 43")
|
|
110
|
-
try {
|
|
111
|
-
let tokenstr: string = req.headers['authorization'];
|
|
112
|
-
tokenstr = tokenstr.replace('Bearer ', '');
|
|
113
89
|
|
|
114
|
-
|
|
115
|
-
await
|
|
116
|
-
if (
|
|
117
|
-
this.logger.log('
|
|
118
|
-
return res.status(401).send('
|
|
90
|
+
try {
|
|
91
|
+
await user.setCurrentUserInfo(tokenStr, xOrg);
|
|
92
|
+
if (user.getId() == '' && this.requireXOrg(req.baseUrl)) {
|
|
93
|
+
this.logger.log('Access deny for user:', req.baseUrl);
|
|
94
|
+
return res.status(401).send('Access deny for user');
|
|
119
95
|
} else {
|
|
120
|
-
if (
|
|
121
|
-
this.logger.verbose(
|
|
122
|
-
`grant new user (${u.getUid()}) access ${req.baseUrl}`,
|
|
123
|
-
);
|
|
96
|
+
if (user.getId() == '') {
|
|
97
|
+
this.logger.verbose(`Grant new user (${user.getUid()}) access ${req.baseUrl}`);
|
|
124
98
|
} else {
|
|
125
|
-
this.logger.verbose(
|
|
126
|
-
`grant user (${u.getId()}) access ${req.baseUrl}`,
|
|
127
|
-
);
|
|
99
|
+
this.logger.verbose(`Grant user (${user.getId()}) access ${req.baseUrl}`);
|
|
128
100
|
}
|
|
129
|
-
req['sessionuser'] =
|
|
130
|
-
this.logger.verbose(
|
|
101
|
+
req['sessionuser'] = user;
|
|
102
|
+
this.logger.verbose('User roles: ' + user.getRoles().join(','));
|
|
131
103
|
|
|
132
104
|
next();
|
|
105
|
+
return;
|
|
133
106
|
}
|
|
134
107
|
} catch (err) {
|
|
135
|
-
|
|
108
|
+
let errorMsg: string = <string>err;
|
|
109
|
+
if (err instanceof Error) {
|
|
110
|
+
errorMsg = 'Code: ' + err.name + ', Msg: ' + err.message;
|
|
111
|
+
}
|
|
112
|
+
this.logger.error('Error set user context: ' + errorMsg);
|
|
136
113
|
throw new BadRequestException(err);
|
|
137
114
|
}
|
|
138
115
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This file was automatically generated by simpleapp generator.
|
|
3
|
-
* DONT CHANGE THIS FILE !!
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
4
3
|
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
5
4
|
* last change 2024-03-19
|
|
6
5
|
* Author: Ks Tan
|
|
@@ -9,8 +8,9 @@ import { Injectable, Logger } from '@nestjs/common';
|
|
|
9
8
|
import { InjectModel } from '@nestjs/mongoose';
|
|
10
9
|
import { Model } from 'mongoose';
|
|
11
10
|
import { UserContext } from 'src/simpleapp/generate/commons/user.context';
|
|
12
|
-
import { User } from 'src/simpleapp/services/user.service';
|
|
13
11
|
import { Permission } from 'src/simpleapp/services/perm.service';
|
|
12
|
+
import { User } from 'src/simpleapp/services/user.service';
|
|
13
|
+
import { Appintegration } from 'src/simpleapp/services/appintegration.service';
|
|
14
14
|
const Base64URL = require('@darkwolf/base64url');
|
|
15
15
|
@Injectable()
|
|
16
16
|
export class SimpleAppRobotUserService {
|
|
@@ -21,6 +21,7 @@ export class SimpleAppRobotUserService {
|
|
|
21
21
|
logger = new Logger();
|
|
22
22
|
@InjectModel('User') private readonly usermodel: Model<User>;
|
|
23
23
|
@InjectModel('Permission') private readonly permmodel: Model<Permission>;
|
|
24
|
+
@InjectModel('Appintegration') private readonly appmodel: Model<Appintegration>;
|
|
24
25
|
|
|
25
26
|
constructor() {
|
|
26
27
|
this.init();
|
|
@@ -77,7 +78,7 @@ export class SimpleAppRobotUserService {
|
|
|
77
78
|
});
|
|
78
79
|
|
|
79
80
|
this.setToken(tokens.access_token);
|
|
80
|
-
console.log(
|
|
81
|
+
// console.log('access token ', this.getToken());
|
|
81
82
|
const nextrefresh = tokens.expires_in * 0.8;
|
|
82
83
|
const appuser = this.prepareAppUser(undefined);
|
|
83
84
|
|
|
@@ -89,23 +90,23 @@ export class SimpleAppRobotUserService {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
prepareAppUser(data: any) {
|
|
92
|
-
console.log(
|
|
93
|
-
const appuser = new UserContext(this.usermodel, this.permmodel);
|
|
93
|
+
// console.log('prepareAppUserprepareAppUser');
|
|
94
|
+
const appuser = new UserContext(this.usermodel, this.permmodel, this.appmodel);
|
|
94
95
|
appuser.setAsStaticUser(
|
|
95
96
|
'00000000-0000-0000-0000-000000000000',
|
|
96
97
|
'robot',
|
|
97
98
|
'Robot',
|
|
98
99
|
'robot@a.org',
|
|
99
|
-
Base64URL.encodeText('0-0-0')
|
|
100
|
+
Base64URL.encodeText('0-0-0'),
|
|
100
101
|
);
|
|
101
102
|
|
|
102
103
|
const tenantId = data?.tenantId ?? 0;
|
|
103
104
|
const orgId = data?.orgId ?? 0;
|
|
104
105
|
const branchId = data?.branchId ?? 0;
|
|
105
106
|
|
|
106
|
-
appuser.
|
|
107
|
+
appuser.setXOrg(appuser.generateXOrg(tenantId, orgId, branchId));
|
|
107
108
|
appuser.setUserToken(this.getToken());
|
|
108
|
-
|
|
109
|
+
|
|
109
110
|
return appuser;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
@@ -24,9 +24,16 @@ export class RolesGuard implements CanActivate {
|
|
|
24
24
|
const requiredRoles = this.reflector.getAllAndOverride<Role[]>(ROLES_KEY, [
|
|
25
25
|
context.getHandler(),
|
|
26
26
|
context.getClass(),
|
|
27
|
-
]);
|
|
27
|
+
]) || [];
|
|
28
|
+
const criticalRoles = [Role.SuperAdmin, Role.SuperUser, Role.TenantOwner];
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
criticalRoles.forEach((role) => {
|
|
31
|
+
if (!requiredRoles.includes(role)) {
|
|
32
|
+
requiredRoles.push(role);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
let sessionuser: UserContext;
|
|
30
37
|
if (context.getType() == 'http') {
|
|
31
38
|
const request = context.switchToHttp().getRequest();
|
|
32
39
|
sessionuser = request['sessionuser'];
|
|
@@ -34,7 +41,7 @@ export class RolesGuard implements CanActivate {
|
|
|
34
41
|
const req = context.getArgs()[2].req;
|
|
35
42
|
sessionuser = req['sessionuser'];
|
|
36
43
|
}
|
|
37
|
-
|
|
44
|
+
|
|
38
45
|
if (!requiredRoles) {
|
|
39
46
|
return true;
|
|
40
47
|
}
|