@simitgroup/simpleapp-generator 1.5.0-alpha → 1.5.1-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/README.md CHANGED
@@ -13,7 +13,7 @@ SimpleApp generator is a typescript code generator for convert jsonschemas becom
13
13
  e. formulas of specific fields
14
14
  f. data types and validations
15
15
  7. build in enterprise functionality included:
16
- a. document numbering [60%]
16
+ a. document numbering [x]
17
17
  b. authentication and authorization [x]
18
18
  c. data modification audit trail []
19
19
  d. SSO [x]
@@ -26,6 +26,7 @@ SimpleApp generator is a typescript code generator for convert jsonschemas becom
26
26
  c. fill in minimal source code in generated listener to run whole bpmn process
27
27
  d. build in integrate between both frontend and backend
28
28
  e. declare workflow in jsonschema
29
+ 9. graphql
29
30
 
30
31
  # Documentation
31
32
  1. [jsonschemas](./docs/jsonschema.md)
@@ -39,6 +40,7 @@ SimpleApp generator is a typescript code generator for convert jsonschemas becom
39
40
  9. Additional Api & define api schema
40
41
  10.SimpleAppInputs
41
42
  11.Role Base Access Control
43
+ 12.graphql
42
44
 
43
45
 
44
46
  # Quick start
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "1.5.0-alpha",
3
+ "version": "1.5.1-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -5,7 +5,7 @@
5
5
  * Author: Ks Tan
6
6
  */
7
7
  import { ApiProperty } from '@nestjs/swagger';
8
- import { Field, ObjectType } from '@nestjs/graphql';
8
+ import { Field, ObjectType,ID } from '@nestjs/graphql';
9
9
 
10
10
  <%Object.keys(it.models).forEach(function(name) { %>
11
11
  <% let schema = it.models[name].model %>
@@ -210,7 +210,8 @@ export class <%= it.typename %>Controller extends SimpleAppAbstractController<
210
210
  <%}%>
211
211
  ){
212
212
 
213
- return await this.service.run<%=capitalizeFirstLetter(api.action)%>(appuser,<% if(api.entryPoint && api.entryPoint.includes(':')) {%>
213
+
214
+ const res:<%= getFieldType('type',api.responseType)%> = await this.service.run<%=capitalizeFirstLetter(api.action)%>(appuser,<% if(api.entryPoint && api.entryPoint.includes(':')) {%>
214
215
  <%let subpath = api.entryPoint.split('/')%>
215
216
  <% for(let a=0;a<subpath.length;a++){%>
216
217
  <%const partstr = subpath[a]%>
@@ -229,7 +230,7 @@ export class <%= it.typename %>Controller extends SimpleAppAbstractController<
229
230
  data,
230
231
  <%}%>
231
232
  )
232
-
233
+ return res
233
234
 
234
235
  }
235
236
  <%}%>
@@ -29,6 +29,7 @@ import { TenantMiddleware } from './simpleapp/generate/commons/middlewares/tenan
29
29
  import { AppController } from './app.controller';
30
30
  import { AppService } from './app.service';
31
31
  import {GenerateModule} from './simpleapp/simpleapp.module'
32
+ import { CloudApiModule } from './cloudapi/cloudapi.module';
32
33
  import { UserMongoSchema } from './simpleapp/generate/models/user.model';
33
34
  import { PermissionMongoSchema } from './simpleapp/generate/models/perm.model';
34
35
  import { ApiEventMongoSchema } from './simpleapp/generate/models/apievent.model';
@@ -75,6 +76,7 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
75
76
  tokenValidation: TokenValidation.ONLINE,
76
77
  }),
77
78
  GenerateModule,
79
+ CloudApiModule,
78
80
  MongooseModule.forFeature([
79
81
  { name: 'User', schema: UserMongoSchema },
80
82
  { name: 'Permission', schema: PermissionMongoSchema },
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. It is changable
3
+ * --remove-this-line-to-prevent-override--
4
+ * last change 2024-04-19
5
+ * Author: Ks Tan
6
+ */
7
+ import { Module } from '@nestjs/common';
8
+ import { CloudApiService } from './cloudapi.service';
9
+ @Module({
10
+ imports: [],
11
+ controllers: [],
12
+ providers: [CloudApiService],
13
+ exports: [CloudApiService],
14
+ })
15
+ export class CloudApiModule {}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. It is changable
3
+ * --remove-this-line-to-prevent-override--
4
+ * last change 2024-04-19
5
+ * Author: Ks Tan
6
+ */
7
+ import { Injectable, InternalServerErrorException } from '@nestjs/common';
8
+ import { UserContext } from 'src/simpleapp/generate/commons/user.context';
9
+
10
+ @Injectable()
11
+ export class CloudApiService {
12
+ constructor() {}
13
+
14
+
15
+ }
@@ -14,7 +14,21 @@ export class ForeignKey {
14
14
  label: string;
15
15
  }
16
16
 
17
-
17
+ @ObjectType()
18
+ export class CodeLabelValue {
19
+ @ApiProperty({ type: 'string'})
20
+ @Field()
21
+ _id: string;
22
+ @ApiProperty({ type: 'string' })
23
+ @Field()
24
+ code: string
25
+ @ApiProperty({ type: 'string' })
26
+ @Field()
27
+ label: string
28
+ @ApiProperty({ type: Number, required: false, default: 0 })
29
+ @Field()
30
+ value: number
31
+ }
18
32
  export class UserAllPermissionsBranches {
19
33
  @ApiProperty({ type: 'string', required: true, default: '',})
20
34
  permId: string;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator.
3
+ * DONT CHANGE THIS FILE !!
4
+ * MODIFICATION OVERRIDE BY GENERATEOR
5
+ * last change 2024-03-19
6
+ * Author: Ks Tan
7
+ */
8
+ import { Injectable, Logger } from '@nestjs/common';
9
+ import { InjectModel } from '@nestjs/mongoose';
10
+ import { Model } from 'mongoose';
11
+ import { UserContext } from 'src/simpleapp/generate/commons/user.context';
12
+ import { User } from 'src/simpleapp/services/user.service';
13
+ import { Permission } from 'src/simpleapp/services/perm.service';
14
+
15
+ @Injectable()
16
+ export class SimpleAppRobotUserService {
17
+ private systemAccessToken: string;
18
+ private setToken = (token:string) => this.systemAccessToken = token
19
+ private getToken = ()=>this.systemAccessToken
20
+ private expired: string;
21
+ logger = new Logger();
22
+ @InjectModel('User') private readonly usermodel: Model<User>;
23
+ @InjectModel('Permission') private readonly permmodel: Model<Permission>;
24
+
25
+ constructor() {
26
+ this.init();
27
+ // console.log('init SimpleAppRobotUserService');
28
+ }
29
+
30
+ async init() {
31
+ await this.refreshSystemToken();
32
+ }
33
+ async refreshSystemToken() {
34
+ enum GrantType {
35
+ 'client_credentials' = 'client_credentials',
36
+ 'password' = 'password',
37
+ }
38
+
39
+ type KeycloakAuthModel = {
40
+ client_id: string;
41
+ client_secret: string;
42
+ username: string;
43
+ password: string;
44
+ grant_type: GrantType;
45
+ };
46
+
47
+ const keycloakdata: KeycloakAuthModel = {
48
+ client_id: process.env.OAUTH2_CLIENTID,
49
+ client_secret: process.env.OAUTH2_CLIENTSECRET,
50
+ username: process.env.OAUTH2_CLOUDAPI_USER,
51
+ password: process.env.OAUTH2_CLOUDAPI_PASSWORD,
52
+ grant_type: GrantType.password,
53
+ };
54
+ const body = new URLSearchParams(keycloakdata);
55
+
56
+ const mybody = new FormData();
57
+ mybody.append('grant_type', 'password');
58
+ mybody.append('client_id', process.env.OAUTH2_CLIENTID);
59
+ mybody.append('client_secret', process.env.OAUTH2_CLIENTSECRET);
60
+ mybody.append('username', process.env.OAUTH2_CLOUDAPI_USER);
61
+ mybody.append('password', process.env.OAUTH2_CLOUDAPI_PASSWORD);
62
+
63
+ const ssoendpoint = `${process.env.OAUTH2_CONFIGURL}/protocol/openid-connect/token`;
64
+
65
+ const tokens = await fetch(ssoendpoint, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/x-www-form-urlencoded',
69
+ },
70
+ body: body.toString(),
71
+ })
72
+ .then((response) => {
73
+ return response.json();
74
+ })
75
+ .then((data) => {
76
+ return data;
77
+ });
78
+
79
+ this.setToken(tokens.access_token)
80
+ // console.log("access token ",this.getToken())
81
+ const nextrefresh = tokens.expires_in * 0.8;
82
+ const appuser = this.prepareAppUser(undefined);
83
+
84
+
85
+ setTimeout(async () => {
86
+ await this.refreshSystemToken();
87
+ }, nextrefresh * 1000);
88
+ }
89
+
90
+ prepareAppUser(data: any) {
91
+ const appuser = new UserContext(this.usermodel, this.permmodel);
92
+ appuser.setAsStaticUser(
93
+ '00000000-0000-0000-0000-000000000000',
94
+ 'robot',
95
+ 'Robot',
96
+ 'robot@a.org',
97
+ );
98
+
99
+ const tenantId = data?.tenantId ?? 0;
100
+ const orgId = data?.orgId ?? 0;
101
+ const branchId = data?.branchId ?? 0;
102
+
103
+ appuser.setXorg(appuser.generateXorg(tenantId, orgId, branchId));
104
+ appuser.setUserToken(this.getToken());
105
+ // console.log(
106
+ // 'return user ' + appuser.getUname(),
107
+ // appuser.getXorg(),
108
+ // appuser.getUserToken().length,
109
+ // );
110
+ return appuser;
111
+ }
112
+ }
@@ -44,7 +44,7 @@ export class UserContext {
44
44
  protected uname: string = '';
45
45
  protected email: string = '';
46
46
  protected fullname: string = '';
47
- protected xOrg: string = '';
47
+ protected xOrg: string = '';
48
48
  protected tenantId: number = 0;
49
49
  protected orgId: number = 0;
50
50
  protected orgRecordId: string = '';
@@ -252,6 +252,7 @@ export class UserContext {
252
252
  return undefined;
253
253
  }
254
254
  };
255
+ getUserToken = () => this.token
255
256
  setUserToken = async (tokenstr: string) => {
256
257
  //define token info
257
258
  const tokeninfo = jwt.decode(tokenstr);
@@ -363,7 +364,9 @@ export class UserContext {
363
364
  this.orgId = orgId;
364
365
  this.branchId = branchId;
365
366
  }
367
+ getXorg = () =>this.xOrg
366
368
  setXorg = (xorg) => {
369
+ this.xOrg = xorg
367
370
  try {
368
371
  const decodedText: string = Base64URL.decodeText(xorg);
369
372
  const x = decodedText.includes('/')
@@ -4,5 +4,4 @@ export * from './<%= d['doctype']%>.type'
4
4
  <%}%>
5
5
  export * from './simpleapp.type'
6
6
  export * from './workflow.type'
7
-
8
7
  export * from '../../types';
@@ -0,0 +1,191 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator. Every
3
+ * MODIFICATION OVERRIDE BY GENERATEOR
4
+ * last change 2024-02-23
5
+ * Author: Ks Tan
6
+ */
7
+ import { JSONSchema7,JSONSchema7Type,JSONSchema7Version, JSONSchema7TypeName,JSONSchema7Definition } from 'json-schema';
8
+ export type DocumentStatus = {
9
+ status:string //'CO', 'V', 'CL', 'D' and etc
10
+ statusName:string
11
+ readOnly:boolean
12
+ actions: string[] //api name ['confirm','revert','close','void' and etc]
13
+ }
14
+ export enum RESTMethods {'post'='post','get'='get', 'delete'='delete','put'='put', 'patch'='patch'}
15
+ export type DocumentApi = {
16
+ action:string //api action name
17
+ entryPoint:string //api entry point example:':id', ':id/confirm'
18
+ queryPara?:string[] //what query parameter wish to accept, example: ['description','date']
19
+ requiredRole?: string[] // what special user role wish to allow for this api, example: ['SuperUser']
20
+ workflowSetting?: {bpmn:string} //optional property, once define code gen connect the bpmn workflow
21
+ method:RESTMethods
22
+ schema?:string //any schema/type name in types & apischemas
23
+ responseType?:string //any schema/type name for response
24
+ description:string //description of api
25
+ }
26
+ export enum IsolationType {"none"="none" , "tenant"="tenant","org"="org", "branch"="branch"}
27
+ // export type ImportLibs = {"lib":string,"as":string}
28
+ export type Formula = {
29
+ jsonPath:string //example: "$.subtotal","$.details[*]"
30
+ formula:string //example "jslib.getDocumentSubTotal(@F{$.details})"
31
+ }
32
+ export type SchemaConfig = {
33
+ isolationType: IsolationType
34
+ requiredRoles?:string[]
35
+ pageType?: string
36
+ uniqueKey?:string
37
+ uniqueKeys?:string[][]
38
+ documentTitle?:string
39
+ generateDocumentNumber?:boolean
40
+ documentDate?:string
41
+ allStatus?:DocumentStatus[]
42
+ additionalApis?:DocumentApi[]
43
+ additionalAutoCompleteFields ?: string[]
44
+ // libs?:ImportLibs[] // both process class and frontend client class will import same lib
45
+ formulas?: Formula[]
46
+ documentType: string
47
+ documentName: string
48
+ collectionName?: string
49
+ foreignKeys?:MyForeignKey,
50
+ }
51
+ export type MyForeignKey = {
52
+ [collectionname:string]:string[]
53
+ }
54
+
55
+ export type SchemaType = {
56
+ type:string
57
+ definitions?:SimpleAppJSONSchema7
58
+ required?:string[]
59
+
60
+ "x-simpleapp-config":SchemaConfig
61
+ properties: SchemaFields
62
+ }
63
+
64
+
65
+ export type SchemaFields = {
66
+ _id: SimpleAppJSONSchema7
67
+ tenantId: SimpleAppJSONSchema7
68
+ orgId: SimpleAppJSONSchema7
69
+ branchId: SimpleAppJSONSchema7
70
+ created: SimpleAppJSONSchema7
71
+ updated: SimpleAppJSONSchema7
72
+ createdBy: SimpleAppJSONSchema7
73
+ updatedBy: SimpleAppJSONSchema7
74
+ [key:string]:SimpleAppJSONSchema7 | SimpleAppJSONSchema7[] | undefined
75
+
76
+ }
77
+
78
+
79
+
80
+ // modified from jsonschemas
81
+ export type SimpleAppJSONSchema7Definition = SimpleAppJSONSchema7 | boolean;
82
+ export interface SimpleAppJSONSchema7 {
83
+
84
+ 'x-foreignkey' ?:string
85
+ $id?: string | undefined;
86
+ $ref?: string | undefined;
87
+ $schema?: JSONSchema7Version | undefined;
88
+ $comment?: string | undefined;
89
+
90
+ /**
91
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
92
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
93
+ */
94
+ $defs?: {
95
+ [key: string]: JSONSchema7Definition;
96
+ } | undefined;
97
+
98
+ /**
99
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
100
+ */
101
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
102
+ enum?: JSONSchema7Type[] | undefined;
103
+ const?: JSONSchema7Type | undefined;
104
+
105
+ /**
106
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
107
+ */
108
+ multipleOf?: number | undefined;
109
+ maximum?: number | undefined;
110
+ exclusiveMaximum?: number | undefined;
111
+ minimum?: number | undefined;
112
+ exclusiveMinimum?: number | undefined;
113
+
114
+ /**
115
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
116
+ */
117
+ maxLength?: number | undefined;
118
+ minLength?: number | undefined;
119
+ pattern?: string | undefined;
120
+
121
+ /**
122
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
123
+ */
124
+ items?: SimpleAppJSONSchema7Definition | SimpleAppJSONSchema7Definition[] | undefined;
125
+ additionalItems?: JSONSchema7Definition | undefined;
126
+ maxItems?: number | undefined;
127
+ minItems?: number | undefined;
128
+ uniqueItems?: boolean | undefined;
129
+ contains?: SimpleAppJSONSchema7Definition | undefined;
130
+
131
+ /**
132
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
133
+ */
134
+ maxProperties?: number | undefined;
135
+ minProperties?: number | undefined;
136
+ required?: string[] | undefined;
137
+ properties?: {
138
+ [key: string]: SimpleAppJSONSchema7Definition;
139
+ } | undefined;
140
+ patternProperties?: {
141
+ [key: string]: SimpleAppJSONSchema7Definition;
142
+ } | undefined;
143
+ additionalProperties?: SimpleAppJSONSchema7Definition | undefined;
144
+ dependencies?: {
145
+ [key: string]: SimpleAppJSONSchema7Definition | string[];
146
+ } | undefined;
147
+ propertyNames?: SimpleAppJSONSchema7Definition | undefined;
148
+
149
+ /**
150
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
151
+ */
152
+ if?: SimpleAppJSONSchema7Definition | undefined;
153
+ then?: SimpleAppJSONSchema7Definition | undefined;
154
+ else?: SimpleAppJSONSchema7Definition | undefined;
155
+
156
+ /**
157
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
158
+ */
159
+ allOf?: SimpleAppJSONSchema7Definition[] | undefined;
160
+ anyOf?: SimpleAppJSONSchema7Definition[] | undefined;
161
+ oneOf?: SimpleAppJSONSchema7Definition[] | undefined;
162
+ not?: SimpleAppJSONSchema7Definition | undefined;
163
+
164
+ /**
165
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
166
+ */
167
+ format?: string | undefined;
168
+
169
+ /**
170
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
171
+ */
172
+ contentMediaType?: string | undefined;
173
+ contentEncoding?: string | undefined;
174
+
175
+ /**
176
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
177
+ */
178
+ definitions?: {
179
+ [key: string]: JSONSchema7Definition;
180
+ } | undefined;
181
+
182
+ /**
183
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
184
+ */
185
+ title?: string | undefined;
186
+ description?: string | undefined;
187
+ default?: JSONSchema7Type | undefined;
188
+ readOnly?: boolean | undefined;
189
+ writeOnly?: boolean | undefined;
190
+ examples?: JSONSchema7Type | undefined;
191
+ }
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * This file was automatically generated by simpleapp generator. Every
3
3
  * MODIFICATION OVERRIDE BY GENERATEOR
4
- * last change 2024-01-25
4
+ * last change 2024-04-18
5
5
  * Author: Ks Tan
6
6
  */
7
- import { UserContext } from '../commons/user.context'
8
-
7
+ import { UserContext } from '../commons/user.context';
8
+ import { JSONSchema7,JSONSchema7Type,JSONSchema7Version, JSONSchema7TypeName,JSONSchema7Definition } from 'json-schema';
9
9
 
10
10
  export type ModifiedCollection = {
11
11
  [key: string]: string[];
@@ -43,9 +43,18 @@ export type DefaultHooks<T> = {
43
43
  afterValidation?: (appuser: UserContext, data: T) => Promise<void>;
44
44
  beforeCreate?: (appuser: UserContext, data: T) => Promise<void>;
45
45
  afterCreate?: (appuser: UserContext, data: T) => Promise<void>;
46
- beforeUpdate?: (appuser: UserContext, id: string, data: T, existingdata:T) => Promise<void>;
46
+ beforeUpdate?: (
47
+ appuser: UserContext,
48
+ id: string,
49
+ data: T,
50
+ existingdata: T,
51
+ ) => Promise<void>;
47
52
  afterUpdate?: (appuser: UserContext, id: string, data: T) => Promise<void>;
48
- beforeDelete?: (appuser: UserContext, id: string,deletedata:T) => Promise<void>;
53
+ beforeDelete?: (
54
+ appuser: UserContext,
55
+ id: string,
56
+ deletedata: T,
57
+ ) => Promise<void>;
49
58
  afterDelete?: (
50
59
  appuser: UserContext,
51
60
  result: DeleteResultType<T>,
@@ -88,3 +97,189 @@ export type DeleteResultType<T> = {
88
97
  deletedCount: number;
89
98
  };
90
99
  };
100
+
101
+
102
+ export type DocumentStatus = {
103
+ status:string //'CO', 'V', 'CL', 'D' and etc
104
+ statusName:string
105
+ readOnly:boolean
106
+ actions: string[] //api name ['confirm','revert','close','void' and etc]
107
+ }
108
+ export enum RESTMethods {'post'='post','get'='get', 'delete'='delete','put'='put', 'patch'='patch'}
109
+ export type DocumentApi = {
110
+ action:string //api action name
111
+ entryPoint:string //api entry point example:':id', ':id/confirm'
112
+ queryPara?:string[] //what query parameter wish to accept, example: ['description','date']
113
+ requiredRole?: string[] // what special user role wish to allow for this api, example: ['SuperUser']
114
+ workflowSetting?: {bpmn:string} //optional property, once define code gen connect the bpmn workflow
115
+ method:RESTMethods
116
+ schema?:string //any schema/type name in types & apischemas
117
+ responseType?:string //any schema/type name for response
118
+ description:string //description of api
119
+ }
120
+ //export enum IsolationType {"none"="none" , "tenant"="tenant","org"="org", "branch"="branch"}
121
+ // export type ImportLibs = {"lib":string,"as":string}
122
+ export type Formula = {
123
+ jsonPath:string //example: "$.subtotal","$.details[*]"
124
+ formula:string //example "jslib.getDocumentSubTotal(@F{$.details})"
125
+ }
126
+ export type SchemaConfig = {
127
+ isolationType: IsolationType
128
+ requiredRoles?:string[]
129
+ pageType?: string
130
+ uniqueKey?:string
131
+ uniqueKeys?:string[][]
132
+ documentTitle?:string
133
+ generateDocumentNumber?:boolean
134
+ documentDate?:string
135
+ allStatus?:DocumentStatus[]
136
+ additionalApis?:DocumentApi[]
137
+ additionalAutoCompleteFields ?: string[]
138
+ // libs?:ImportLibs[] // both process class and frontend client class will import same lib
139
+ formulas?: Formula[]
140
+ documentType: string
141
+ documentName: string
142
+ collectionName?: string
143
+ foreignKeys?:MyForeignKey,
144
+ }
145
+ export type MyForeignKey = {
146
+ [collectionname:string]:string[]
147
+ }
148
+
149
+ export type SchemaType = {
150
+ type:string
151
+ definitions?:SimpleAppJSONSchema7
152
+ required?:string[]
153
+
154
+ "x-simpleapp-config":SchemaConfig
155
+ properties: SchemaFields
156
+ }
157
+
158
+
159
+ export type SchemaFields = {
160
+ _id: SimpleAppJSONSchema7
161
+ tenantId: SimpleAppJSONSchema7
162
+ orgId: SimpleAppJSONSchema7
163
+ branchId: SimpleAppJSONSchema7
164
+ created: SimpleAppJSONSchema7
165
+ updated: SimpleAppJSONSchema7
166
+ createdBy: SimpleAppJSONSchema7
167
+ updatedBy: SimpleAppJSONSchema7
168
+ [key:string]:SimpleAppJSONSchema7 | SimpleAppJSONSchema7[] | undefined
169
+
170
+ }
171
+
172
+
173
+
174
+ // modified from jsonschemas
175
+ export type SimpleAppJSONSchema7Definition = SimpleAppJSONSchema7 | boolean;
176
+ export interface SimpleAppJSONSchema7 {
177
+
178
+ 'x-foreignkey' ?:string
179
+ $id?: string | undefined;
180
+ $ref?: string | undefined;
181
+ $schema?: JSONSchema7Version | undefined;
182
+ $comment?: string | undefined;
183
+
184
+ /**
185
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
186
+ * @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
187
+ */
188
+ $defs?: {
189
+ [key: string]: JSONSchema7Definition;
190
+ } | undefined;
191
+
192
+ /**
193
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
194
+ */
195
+ type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
196
+ enum?: JSONSchema7Type[] | undefined;
197
+ const?: JSONSchema7Type | undefined;
198
+
199
+ /**
200
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
201
+ */
202
+ multipleOf?: number | undefined;
203
+ maximum?: number | undefined;
204
+ exclusiveMaximum?: number | undefined;
205
+ minimum?: number | undefined;
206
+ exclusiveMinimum?: number | undefined;
207
+
208
+ /**
209
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
210
+ */
211
+ maxLength?: number | undefined;
212
+ minLength?: number | undefined;
213
+ pattern?: string | undefined;
214
+
215
+ /**
216
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
217
+ */
218
+ items?: SimpleAppJSONSchema7Definition | SimpleAppJSONSchema7Definition[] | undefined;
219
+ additionalItems?: JSONSchema7Definition | undefined;
220
+ maxItems?: number | undefined;
221
+ minItems?: number | undefined;
222
+ uniqueItems?: boolean | undefined;
223
+ contains?: SimpleAppJSONSchema7Definition | undefined;
224
+
225
+ /**
226
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
227
+ */
228
+ maxProperties?: number | undefined;
229
+ minProperties?: number | undefined;
230
+ required?: string[] | undefined;
231
+ properties?: {
232
+ [key: string]: SimpleAppJSONSchema7Definition;
233
+ } | undefined;
234
+ patternProperties?: {
235
+ [key: string]: SimpleAppJSONSchema7Definition;
236
+ } | undefined;
237
+ additionalProperties?: SimpleAppJSONSchema7Definition | undefined;
238
+ dependencies?: {
239
+ [key: string]: SimpleAppJSONSchema7Definition | string[];
240
+ } | undefined;
241
+ propertyNames?: SimpleAppJSONSchema7Definition | undefined;
242
+
243
+ /**
244
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
245
+ */
246
+ if?: SimpleAppJSONSchema7Definition | undefined;
247
+ then?: SimpleAppJSONSchema7Definition | undefined;
248
+ else?: SimpleAppJSONSchema7Definition | undefined;
249
+
250
+ /**
251
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
252
+ */
253
+ allOf?: SimpleAppJSONSchema7Definition[] | undefined;
254
+ anyOf?: SimpleAppJSONSchema7Definition[] | undefined;
255
+ oneOf?: SimpleAppJSONSchema7Definition[] | undefined;
256
+ not?: SimpleAppJSONSchema7Definition | undefined;
257
+
258
+ /**
259
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
260
+ */
261
+ format?: string | undefined;
262
+
263
+ /**
264
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
265
+ */
266
+ contentMediaType?: string | undefined;
267
+ contentEncoding?: string | undefined;
268
+
269
+ /**
270
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
271
+ */
272
+ definitions?: {
273
+ [key: string]: JSONSchema7Definition;
274
+ } | undefined;
275
+
276
+ /**
277
+ * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
278
+ */
279
+ title?: string | undefined;
280
+ description?: string | undefined;
281
+ default?: JSONSchema7Type | undefined;
282
+ readOnly?: boolean | undefined;
283
+ writeOnly?: boolean | undefined;
284
+ examples?: JSONSchema7Type | undefined;
285
+ }
@@ -20,7 +20,7 @@ let _this: WorkflowConfig; //we need another variable to access WorkflowConfig
20
20
  class MyDataStore extends DataStore {
21
21
  constructor(bpmnserver) {
22
22
  super(bpmnserver);
23
- console.log('this.dbConfiguration ', this.db);
23
+ //console.log('this.dbConfiguration ', this.db);
24
24
  }
25
25
  }
26
26
 
@@ -1,7 +1,8 @@
1
+ import { error } from 'console';
1
2
  /**
2
3
  * This file was automatically generated by simpleapp generator. Every
3
4
  * MODIFICATION OVERRIDE BY GENERATEOR
4
- * last change 2024-04-15
5
+ * last change 2024-04-19
5
6
  * Author: Ks Tan
6
7
  */
7
8
  import { WorkflowConfig } from './workflow.config';
@@ -30,6 +31,7 @@ import {
30
31
  Logger as bpmnlogger,
31
32
  BPMN_TYPE,
32
33
  EXECUTION_EVENT,
34
+ ILogger,
33
35
  } from 'bpmn-server';
34
36
  // import { configuration } from './configuration';
35
37
  import { UserContext } from '../commons/user.context';
@@ -48,7 +50,23 @@ export class WorkflowService {
48
50
  private workflowconfig: WorkflowConfig,
49
51
  private eventEmitter: EventEmitter2,
50
52
  ) {
51
- this.bpmnServer = new BPMNServer(this.workflowconfig.getConfig());
53
+ const config = this.workflowconfig.getConfig()
54
+ class HiddenLogger implements ILogger{
55
+ setOptions(){}
56
+ clear(){}
57
+ get(){ return [] as any[]}
58
+ debug(){}
59
+ warn(){}
60
+ info(){}
61
+ reportError(err:any){
62
+ console.log("report Error:",err )
63
+ }
64
+ async save(filename:any){}
65
+ log(){}
66
+ error(err: any){console.log("Error:",err )
67
+ }
68
+ }
69
+ this.bpmnServer = new BPMNServer(config, new HiddenLogger());
52
70
  this.bpmnServer.listener.on(
53
71
  'all',
54
72
  async (event) => await this.applyEventListener(event),
@@ -326,19 +344,19 @@ export class WorkflowService {
326
344
  ) {
327
345
  //run as event, it wont have transaction
328
346
  appuser.setDBSession(undefined);
329
-
330
- if (!data ) data = {}
331
-
347
+
348
+ if (!data) data = {};
349
+
332
350
  //sometimes data is Mongoose object instead of pure data, need serialize and deserialize to remove that
333
- data=JSON.parse(JSON.stringify(data))
334
-
351
+ data = JSON.parse(JSON.stringify(data));
352
+
335
353
  try {
336
354
  // console.log('startWorkflow started: ', workflowName);
337
-
355
+
338
356
  data.tenantId = appuser.getTenantId();
339
357
  data.orgId = appuser.getOrgId();
340
358
  data.branchId = appuser.getBranchId();
341
-
359
+
342
360
  const result = await this.bpmnServer.engine.start(
343
361
  workflowName,
344
362
  data,
@@ -8,7 +8,7 @@ import { Module } from '@nestjs/common';
8
8
  import { MongooseModule } from '@nestjs/mongoose';
9
9
  import {DocNumberFormatGenerator} from './generate/commons/docnogenerator.service'
10
10
  import { AuditTrail } from './generate/commons/audittrail.service';
11
-
11
+ import { CloudApiModule } from 'src/cloudapi/cloudapi.module';
12
12
  // auto import modules
13
13
  <% for(let i=0;i<it.modules.length; i++){ %>
14
14
  <% let obj = it.modules[i]%>
@@ -24,6 +24,7 @@ import { WorkflowDelegate } from './generate/workflow/workflow.delegate';
24
24
  import { WorkflowConfig } from './generate/workflow/workflow.config';
25
25
  import { WorkflowService } from './generate/workflow/workflow.service';
26
26
  import { WorkflowUserService } from './generate/workflow/workflow.userservice';
27
+ import { SimpleAppRobotUserService } from './generate/commons/robotuser.service';
27
28
  <%for(let i=0; i<it.allbpmn.length;i++){%>
28
29
  <%let bpmn = it.allbpmn[i]%>
29
30
  import { <%=capitalizeFirstLetter(bpmn)%>ListenerService } from 'src/simpleapp/workflows/listeners/<%=bpmn%>.listener';
@@ -37,6 +38,7 @@ import { <%=capitalizeFirstLetter(bpmn)%>ListenerService } from 'src/simpleapp/w
37
38
 
38
39
  @Module({
39
40
  imports: [
41
+ CloudApiModule,
40
42
  MongooseModule.forFeature([
41
43
  <% for(let i=0;i<it.modules.length; i++){ %>
42
44
  <% let obj = it.modules[i]%>
@@ -46,6 +48,7 @@ import { <%=capitalizeFirstLetter(bpmn)%>ListenerService } from 'src/simpleapp/w
46
48
  ],
47
49
  controllers: [<% for(let i=0;i<it.modules.length; i++){ %><%= it.modules[i].docname %>Controller,<%}%> ProfileController,WorkflowController],
48
50
  providers: [
51
+ SimpleAppRobotUserService,
49
52
  AuditTrail,DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %>
50
53
  <%= it.modules[i].docname %>Service,
51
54
  <%= it.modules[i].docname %>Resolver,
@@ -55,7 +58,7 @@ import { <%=capitalizeFirstLetter(bpmn)%>ListenerService } from 'src/simpleapp/w
55
58
  <%=capitalizeFirstLetter(bpmn)%>ListenerService,
56
59
  <%}%>
57
60
  ],
58
- exports:[AuditTrail,DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %>
61
+ exports:[SimpleAppRobotUserService,AuditTrail,DocNumberFormatGenerator,<% for(let i=0;i<it.modules.length; i++){ %>
59
62
  <%= it.modules[i].docname %>Service,
60
63
  <%= it.modules[i].docname %>Resolver,
61
64
  <%}%> ProfileService,WorkflowDelegate,WorkflowConfig,WorkflowService,WorkflowUserService,]
@@ -11,6 +11,12 @@ export type ForeignKey = {
11
11
  [key:string]:any
12
12
  };
13
13
 
14
+ export type CodeLabelValue = {
15
+ _id: string
16
+ code: string
17
+ label: string
18
+ value: number
19
+ }
14
20
  export type UserPermission = {
15
21
  permId: string;
16
22
  branchId: number
@@ -0,0 +1,31 @@
1
+ /**
2
+ * This file was automatically generated by simpleapp generator.
3
+ * DONT CHANGE THIS FILE !!
4
+ * MODIFICATION OVERRIDE BY GENERATEOR
5
+ * last change 2024-03-19
6
+ * Author: Ks Tan
7
+ */
8
+ import { Inject, Injectable, Logger } from '@nestjs/common';
9
+ import { InjectModel } from '@nestjs/mongoose';
10
+ import { Model } from 'mongoose';
11
+ import { UserContext } from 'src/simpleapp/generate/commons/user.context';
12
+ import { User } from 'src/simpleapp/services/user.service';
13
+ import { Permission } from 'src/simpleapp/services/perm.service';
14
+ import { SimpleAppRobotUserService } from 'src/simpleapp/generate/commons/robotuser.service';
15
+
16
+ @Injectable()
17
+ export class SimpleAppListenerService {
18
+ private systemAccessToken: string;
19
+ private expired: string;
20
+ logger = new Logger();
21
+ @InjectModel('User') private readonly usermodel: Model<User>;
22
+ @InjectModel('Permission') private readonly permmodel: Model<Permission>;
23
+ @Inject(SimpleAppRobotUserService)
24
+ private robotuser:SimpleAppRobotUserService;
25
+
26
+ constructor() {}
27
+
28
+ prepareAppUser(data: any) {
29
+ return this.robotuser.prepareAppUser(data)
30
+ }
31
+ }
@@ -21,7 +21,7 @@ const CustomTailwind = usePassThrough(
21
21
  // buttonContainer:{class:'hidden'},
22
22
  },
23
23
  card:{
24
- root:{class:'bg-white dark:bg-gray-800 shadow p-4 rounded-2xl'},
24
+ root:{class:'bg-white dark:bg-gray-800 shadow p-2 rounded-2xl'},
25
25
  // title:{class:''},
26
26
  // header:{class:''}
27
27
  },
@@ -13,14 +13,14 @@ export const setGraphqlServer=()=>{
13
13
  uri: `${useRuntimeConfig().public.API_URL}/${getCurrentXorg()}/graphql`,
14
14
  })
15
15
  apolloclient.setLink(newlink)
16
- // apolloclient.defaultOptions={
16
+ apolloclient.defaultOptions={
17
17
 
18
- // query:{
19
- // fetchPolicy: 'no-cache',
20
- // errorPolicy: 'all'
21
- // }
22
- // }
18
+ query:{
19
+ fetchPolicy: 'no-cache',
20
+ errorPolicy: 'all'
21
+ }
22
+ }
23
23
 
24
24
  }
25
25
 
26
- export const graphquery=async(qqlstr: typeof gql) =>(await useAsyncQuery(qqlstr)).data
26
+ export const graphquery=async<T>(qqlstr: typeof gql) =>(await useAsyncQuery<T>(qqlstr)).data
@@ -1,26 +0,0 @@
1
- /**
2
- * This file was automatically generated by simpleapp generator during initialization. It is changable.
3
- * --remove-this-line-to-prevent-override--
4
- * last change 2024-02-22
5
- * author: Ks Tan
6
- */
7
- import { Injectable,Logger } from "@nestjs/common";
8
- import { InjectModel } from "@nestjs/mongoose";
9
- import { Model } from "mongoose";
10
- import { UserContext } from "src/simpleapp/generate/commons/user.context";
11
- import { User } from "src/simpleapp/services/user.service";
12
- import { Permission } from "src/simpleapp/services/perm.service";
13
-
14
- @Injectable()
15
- export class SimpleAppListenerService {
16
- logger = new Logger()
17
- @InjectModel('User') private readonly usermodel: Model<User>
18
- @InjectModel('Permission') private readonly permmodel: Model<Permission>
19
-
20
- prepareAppUser(data:any){
21
- const appuser = new UserContext(this.usermodel, this.permmodel);
22
- appuser.setAsStaticUser('000-00-00-00','bpmn','bpmn workflow user', 'bpmn@bpmn.org')
23
- appuser.setCurrentTenant(data.tenantId??0,data.orgId??0,data.branchId??0)
24
- return appuser
25
- }
26
- }