@simitgroup/simpleapp-generator 2.0.0-e-alpha → 2.0.0-g-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.
Files changed (38) hide show
  1. package/ReleaseNote.md +13 -0
  2. package/dist/buildinschemas/index.d.ts +2 -0
  3. package/dist/buildinschemas/index.d.ts.map +1 -1
  4. package/dist/buildinschemas/index.js +5 -3
  5. package/dist/buildinschemas/index.js.map +1 -1
  6. package/dist/buildinschemas/webhook.js +1 -1
  7. package/dist/generate.js +1 -1
  8. package/dist/generate.js.map +1 -1
  9. package/package.json +1 -1
  10. package/src/buildinschemas/index.ts +2 -2
  11. package/src/buildinschemas/{webhook.ts.backup → webhook.ts} +1 -1
  12. package/src/generate.ts +1 -1
  13. package/templates/basic/nest/module.ts.eta +2 -2
  14. package/templates/basic/nest/service.ts.eta +2 -2
  15. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.module.ts.eta +15 -7
  16. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.schema.ts.eta +41 -42
  17. package/templates/nest/src/simple-app/.core/features/document-no-format/document-no-format.service.ts.eta +11 -11
  18. package/templates/nest/src/simple-app/.core/features/log/log.controller.ts.eta +42 -0
  19. package/templates/nest/src/simple-app/.core/features/log/log.module.ts.eta +11 -8
  20. package/templates/nest/src/simple-app/.core/features/log/log.service.ts.eta +48 -13
  21. package/templates/nest/src/simple-app/.core/features/log/schemas/document-event.schema.ts.eta +23 -1
  22. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager-policy.service.ts.eta +13 -6
  23. package/templates/nest/src/simple-app/.core/features/mini-app/mini-app-manager/mini-app-manager.service.ts.eta +5 -2
  24. package/templates/nest/src/simple-app/.core/features/policy/policy.service.ts.eta +6 -5
  25. package/templates/nest/src/simple-app/.core/features/profile/profile.service.ts.eta +3 -1
  26. package/templates/nest/src/simple-app/.core/features/queue/queue-base/queue-base.consumer.ts.eta +7 -5
  27. package/templates/nest/src/simple-app/.core/features/simple-app-core-features.module.ts.eta +3 -3
  28. package/templates/nest/src/simple-app/.core/features/user-context/user.context.ts.eta +11 -0
  29. package/templates/nest/src/simple-app/.core/features/webhook/schemas/webhook.schema.ts.eta +36 -36
  30. package/templates/nest/src/simple-app/.core/framework/base/simple-app.service.ts.eta +188 -165
  31. package/templates/nest/src/simple-app/mini-apps/mini-apps.module.ts._eta +14 -0
  32. package/templates/nest/src/simple-app/simple-app.module.ts.eta +5 -1
  33. package/templates/nuxt/components/form/FormDocnoformat.vue._eta +78 -17
  34. package/templates/nuxt/components/renderer/RendererDocHistories.vue._eta +90 -50
  35. package/templates/nuxt/components/user/UserTenantPicker.vue._eta +6 -1
  36. package/templates/nuxt/composables/docformat.generate.ts.eta +2 -2
  37. package/templates/nuxt/plugins/19.simpleapp-mini-app-store.ts.eta +2 -2
  38. /package/src/buildinschemas/{documentnoformat.ts.backup → documentnoformat.ts} +0 -0
@@ -17,6 +17,36 @@ export class SimpleAppLogService {
17
17
  // addEvent(data: any) {
18
18
  // console.log('Add event into db:', data);
19
19
  // }
20
+ //
21
+ async searchDocumentEvent(appUser: UserContext, documentName: string, id: string) {
22
+ const data = await this.doc.aggregate([
23
+ { $match: { documentName: documentName, documentId: id } },
24
+ {
25
+ $lookup: {
26
+ from: 'user',
27
+ as: 'user',
28
+ localField: 'createdBy',
29
+ foreignField: 'uid',
30
+ pipeline: [{ $match: { tenantId: appUser.getTenantId() } }, { $project: { fullName: 1 } }],
31
+ },
32
+ },
33
+ { $unwind: '$user' },
34
+ {
35
+ $project: {
36
+ _id: 1,
37
+ fullName: '$user.fullName',
38
+ eventType: 1,
39
+ createdBy: 1,
40
+ created: 1,
41
+ eventData: 1,
42
+ },
43
+ },
44
+ { $sort: { created: 1 } },
45
+ ]);
46
+ // find({documentName:documentName,documentId:id},null,{session:appUser.getDBSession()})
47
+
48
+ return data;
49
+ }
20
50
  async addEvent(appUser: UserContext, documentName: string, id: string, eventType: string, data: any) {
21
51
  const eventdata: DocumentEvent = {
22
52
  _id: crypto.randomUUID(),
@@ -24,13 +54,13 @@ export class SimpleAppLogService {
24
54
  documentId: id,
25
55
  eventType: eventType,
26
56
  eventData: data,
27
- created:'',
28
- createdBy:'',
57
+ created: '',
58
+ createdBy: '',
29
59
  updated: '',
30
- updatedBy:'',
31
- tenantId:0,
32
- orgId:0,
33
- branchId:0,
60
+ updatedBy: '',
61
+ tenantId: 0,
62
+ orgId: 0,
63
+ branchId: 0,
34
64
  };
35
65
  Object.assign(eventdata, appUser.getCreateFilter());
36
66
  // console.log('add event', documentName, id, eventType);
@@ -51,18 +81,23 @@ export class SimpleAppLogService {
51
81
  documentId: data.id,
52
82
  eventType: eventType,
53
83
  eventData: data,
54
- created:'',
55
- createdBy:'',
84
+ created: '',
85
+ createdBy: '',
56
86
  updated: '',
57
- updatedBy:'',
58
- tenantId:0,
59
- orgId:0,
60
- branchId:0,
87
+ updatedBy: '',
88
+ tenantId: 0,
89
+ orgId: 0,
90
+ branchId: 0,
61
91
  };
62
92
  Object.assign(eventdata, appUser.getCreateFilter());
63
93
  alldata.push(eventdata);
64
94
  }
65
95
  const dbsession = appUser.getDBSession();
66
- this.doc.insertMany(alldata, { session: dbsession });
96
+ try{
97
+ await this.doc.insertMany(alldata, { session: dbsession });
98
+ }catch(e){
99
+ throw e
100
+ }
101
+
67
102
  }
68
103
  }
@@ -3,6 +3,28 @@ import { Field, ObjectType, ID } from '@nestjs/graphql';
3
3
  import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
4
4
  import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
5
5
 
6
+ @ObjectType()
7
+ export class DocumentEventListItem {
8
+ @Field()
9
+ @ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
10
+ _id: string;
11
+ @Field()
12
+ @ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
13
+ eventType: string;
14
+ @Field()
15
+ @ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
16
+ created: string;
17
+ @Field()
18
+ @ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
19
+ createdBy: string;
20
+ @Field()
21
+ @ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
22
+ fullName: string;
23
+ @Field(()=>GraphQLJSON)
24
+ @ApiProperty({ type: ()=>Object, required: false, format: 'uuid', default: '' })
25
+ eventData: any;
26
+ }
27
+
6
28
  @ObjectType()
7
29
  @Schema()
8
30
  export class DocumentEvent {
@@ -50,7 +72,7 @@ export class DocumentEvent {
50
72
  @Field()
51
73
  @ApiProperty({ type: 'string', required: false, example: ['create', 'delete'], default: '' })
52
74
  eventType: string;
53
- @Prop({type: ()=>Object})
75
+ @Prop({ type: () => Object })
54
76
  @Field(() => GraphQLJSON)
55
77
  @ApiProperty({ type: () => Object, required: false, default: {} })
56
78
  eventData: Object;
@@ -5,7 +5,7 @@ import { PolicyService } from 'src/simple-app/.core/features/policy/policy.servi
5
5
  import { Role } from 'src/simple-app/.core/features/auth/role-guard/roles.enum';
6
6
  import { UserContext } from 'src/simple-app/.core/features/user-context/user.context';
7
7
  import { MiniApp } from '../dto';
8
-
8
+ import * as plans from 'src/simple-app/features/subscription/license/plans'
9
9
  @Injectable()
10
10
  export class MiniAppManagerPolicyService {
11
11
  readonly _RELEASED_STATUSES = [MiniAppStatusEnum.PUBLISHED];
@@ -30,11 +30,18 @@ export class MiniAppManagerPolicyService {
30
30
 
31
31
  hasRequiredPlan(appUser: UserContext, miniApp: MiniApp) {
32
32
  const currentPlan = appUser.tenantInfo.package;
33
- const requiredPlans = miniApp.access.requiredPlans ?? [];
34
-
35
- if (_.isEmpty(requiredPlans)) return true;
36
-
37
- return requiredPlans.includes(currentPlan);
33
+ // const requiredPlans = miniApp.access.requiredPlans ?? [];
34
+
35
+ if(plans[currentPlan]){
36
+ const plansetting = plans[currentPlan]()
37
+ return plansetting?.features?.advance?.features?.miniApp ?? false
38
+
39
+ }else{
40
+ return false
41
+ }
42
+ // if (_.isEmpty(requiredPlans)) return true;
43
+
44
+ // return requiredPlans.includes(currentPlan);
38
45
  }
39
46
 
40
47
  isMiniAppRealeased(status: MiniAppStatusEnum) {
@@ -9,7 +9,7 @@ import { MiniAppInstallationService } from 'src/simple-app/.core/resources/mini-
9
9
  import _ from 'lodash';
10
10
  import { MiniAppManagerPolicyService } from './mini-app-manager-policy.service';
11
11
  import { MiniAppError } from './mini-app-manager.error';
12
-
12
+ import * as plans from 'src/simple-app/features/subscription/license/plans'
13
13
  @Injectable()
14
14
  export class MiniAppManagerService {
15
15
  constructor(
@@ -82,7 +82,7 @@ export class MiniAppManagerService {
82
82
  });
83
83
 
84
84
  const permissions = this.getMiniAppActionAccess(appUser);
85
-
85
+
86
86
  const installedMiniApps = miniAppInstallations.map((installation) => {
87
87
  const miniApp = miniApps.find((miniApp) => miniApp._id === installation.miniApp._id);
88
88
  if (!miniApp) {
@@ -176,6 +176,9 @@ export class MiniAppManagerService {
176
176
  }
177
177
 
178
178
  private getMiniAppActionAccess(appUser: UserContext) {
179
+ const currentPlan = appUser.tenantInfo.package;
180
+ const planSetting = plans[currentPlan]()
181
+
179
182
  return {
180
183
  hasMiniAppFeature: this.policyService.hasFeature(appUser),
181
184
  canInstall: this.policyService.canInstall(appUser),
@@ -1,7 +1,7 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { Role } from 'src/simple-app/.core/features/auth/role-guard/roles.enum';
3
3
  import { UserContext } from 'src/simple-app/.core/features/user-context/user.context';
4
-
4
+ import * as plans from 'src/simple-app/features/subscription/license/plans'
5
5
  @Injectable()
6
6
  export class PolicyService {
7
7
  private readonly _HIGH_PRIVILEGE_ROLES = [Role.SuperAdmin, Role.SuperUser, Role.TenantOwner];
@@ -27,11 +27,12 @@ export class PolicyService {
27
27
  * - plans/pro.ts
28
28
  * - plans/enterprise.ts
29
29
  */
30
- hasFeature(appUser: UserContext, feature: keyof typeof this._FEATURES): boolean {
31
- const appPackage = appUser.tenantInfo.package
30
+ hasFeature(appUser: UserContext, feature: keyof typeof this._FEATURES): boolean {
31
+ const appPackage = appUser.tenantInfo.package;
32
32
  const allowedPlans = this._FEATURES[feature];
33
-
34
- return allowedPlans.includes(appPackage);
33
+ const planSetting = plans[appPackage]();
34
+ const allowed = planSetting.features?.advance?.features[feature] ?? false;
35
+ return allowed
35
36
  }
36
37
 
37
38
  can(appUser: UserContext, role: Role) {
@@ -50,11 +50,13 @@ export class ProfileService {
50
50
  this.logger.verbose(`get userprofile for ${appuser.getUid()} for tenantId ${accessTenantId}`, 'getProfile');
51
51
  const userinfo: UserContextInfo = await appuser.getUserInfo();
52
52
 
53
- if (userinfo._id == '') {
53
+ if (!userinfo._id) {
54
54
  this.logger.warn('unknown _id for ', appuser.getUid());
55
55
 
56
56
  let newprofile;
57
+
57
58
  if (accessTenantId == 0) {
59
+
58
60
  newprofile = await this.createUserProfile(appuser);
59
61
  newprofile['time'] = new Date().toISOString();
60
62
  return newprofile;
@@ -31,12 +31,11 @@ export abstract class BaseQueueConsumer extends WorkerHost {
31
31
  async startSession(appUser: UserContext) {
32
32
  const session = await this.connection.startSession();
33
33
  appUser.setDBSession(session);
34
- appUser.getDBSession().startTransaction({ readPreference: 'primary' });
35
34
  }
36
35
 
37
36
  async process(job: Job) {
38
37
  // console.log("process job", job.data)
39
- const { userContext, payload } = job.data
38
+ const { userContext, payload } = job.data;
40
39
 
41
40
  const appUser = this.createUserContext(userContext.user);
42
41
  await this.startSession(appUser);
@@ -46,13 +45,16 @@ export abstract class BaseQueueConsumer extends WorkerHost {
46
45
  // this.queueUserContext.assign(userContext);
47
46
 
48
47
  await this.dispatch(appUser, job, payload);
49
-
50
- await appUser.getDBSession().commitTransaction();
48
+ if(appUser.getDBSession().inTransaction()) {
49
+ await appUser.getDBSession().commitTransaction();
50
+ }
51
51
  return {
52
52
  success: true,
53
53
  };
54
54
  } catch (e) {
55
- await appUser.getDBSession().abortTransaction();
55
+ if(appUser.getDBSession().inTransaction()) {
56
+ await appUser.getDBSession().abortTransaction();
57
+ }
56
58
  throw e;
57
59
  } finally {
58
60
  appUser.getDBSession().endSession();
@@ -7,7 +7,7 @@
7
7
  import { Module } from '@nestjs/common';
8
8
 
9
9
  import { SimpleAppAuthModule } from './auth/auth.module';
10
- import { DocumentNoFormatModule } from './document-no-format/document-no-format.module';
10
+ import { SimpleAppDocumentNoFormatModule } from './document-no-format/document-no-format.module';
11
11
  import { SimpleAppForeignKeyModule } from './foreign-key/foreign-key.module';
12
12
  import { SimpleAppLogModule } from './log/log.module';
13
13
  import { MaintenanceModule } from './maintenance/maintenance.module';
@@ -22,7 +22,7 @@ import { AutoIncreamentModule } from './auto-increament/auto-increament.module';
22
22
  imports: [
23
23
  AutoIncreamentModule,
24
24
  SimpleAppAuthModule,
25
- DocumentNoFormatModule,
25
+ SimpleAppDocumentNoFormatModule,
26
26
  SimpleAppForeignKeyModule,
27
27
  SimpleAppLogModule,
28
28
  MaintenanceModule,
@@ -37,7 +37,7 @@ import { AutoIncreamentModule } from './auto-increament/auto-increament.module';
37
37
  exports: [
38
38
  AutoIncreamentModule,
39
39
  SimpleAppAuthModule,
40
- DocumentNoFormatModule,
40
+ SimpleAppDocumentNoFormatModule,
41
41
  SimpleAppForeignKeyModule,
42
42
  SimpleAppLogModule,
43
43
  MaintenanceModule,
@@ -1000,6 +1000,17 @@ export class UserContext extends UserContextInfo {
1000
1000
  return miniAppInstallation;
1001
1001
  }
1002
1002
 
1003
+ async findInstalledMiniAppCode(miniAppCode: string) {
1004
+ const miniAppInstallation = await this.miniAppInstallationModel.findOne({
1005
+ 'miniApp.code': miniAppCode,
1006
+ isActive: true,
1007
+ tenantId: this.tenantId,
1008
+ orgId: this.orgId,
1009
+ branchId: this.branchId,
1010
+ });
1011
+ return miniAppInstallation.miniApp;
1012
+ }
1013
+
1003
1014
  async setUserProfileFromDB() {
1004
1015
  // const userProfile = await this.obtainProfileFromDB();
1005
1016
  // if (userProfile) {
@@ -9,132 +9,132 @@ import { Field, ObjectType, ID } from '@nestjs/graphql';
9
9
  import GraphQLJSON, { GraphQLJSONObject } from 'graphql-type-json';
10
10
  import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
11
11
 
12
- @ObjectType()
12
+ // @ObjectType()
13
13
  @Schema({ collection: 'webhook' })
14
14
  export class WebhookBasicAuth {
15
15
  @Prop()
16
- @Field()
16
+ // @Field()
17
17
  @ApiProperty({ type: 'string', required: false, default: '' })
18
18
  user: string;
19
19
  @Prop()
20
- @Field()
20
+ // @Field()
21
21
  @ApiProperty({ type: 'string', required: false, default: '' })
22
22
  password: string;
23
23
  }
24
24
 
25
- @ObjectType()
25
+ // @ObjectType()
26
26
  @Schema()
27
27
  export class WebhookHeaders {
28
28
  @Prop()
29
- @Field()
29
+ // @Field()
30
30
  @ApiProperty({ type: 'string', required: false, default: '' })
31
31
  name: string;
32
32
  @Prop()
33
- @Field()
33
+ // @Field()
34
34
  @ApiProperty({ type: 'string', required: false, default: '' })
35
35
  value: string;
36
36
  @Prop()
37
- @Field()
37
+ // @Field()
38
38
  @ApiProperty({ type: 'string', required: false, description: 'iso8601 dataempty mean new record', default: '' })
39
39
  created: string;
40
40
  @Prop()
41
- @Field()
41
+ // @Field()
42
42
  @ApiProperty({ type: 'string', required: false, description: 'iso8601 or empty', default: '' })
43
43
  updated: string;
44
44
  @Prop()
45
- @Field()
45
+ // @Field()
46
46
  @ApiProperty({ type: 'string', required: false, default: '' })
47
47
  createdBy: string;
48
48
  @Prop()
49
- @Field()
49
+ // @Field()
50
50
  @ApiProperty({ type: 'string', required: false, default: '' })
51
51
  updatedBy: string;
52
52
  @Prop()
53
- @Field()
53
+ // @Field()
54
54
  @ApiProperty({ type: 'string', required: false, default: '' })
55
55
  _id: string;
56
56
  }
57
57
 
58
- @ObjectType()
58
+ // @ObjectType()
59
59
  @Schema()
60
60
  export class Webhook {
61
61
  @Prop()
62
- @Field()
62
+ // @Field()
63
63
  @ApiProperty({ type: 'string', required: false, format: 'uuid', default: '' })
64
64
  _id?: string;
65
65
  @Prop()
66
- @Field()
66
+ // @Field()
67
67
  @ApiProperty({ type: 'string', required: false, default: '' })
68
68
  created?: string;
69
69
  @Prop()
70
- @Field()
70
+ // @Field()
71
71
  @ApiProperty({ type: 'string', required: false, default: '' })
72
72
  updated?: string;
73
73
  @Prop()
74
- @Field()
74
+ // @Field()
75
75
  @ApiProperty({ type: 'string', required: false, default: '' })
76
76
  createdBy?: string;
77
77
  @Prop()
78
- @Field()
78
+ // @Field()
79
79
  @ApiProperty({ type: 'string', required: false, default: '' })
80
80
  updatedBy?: string;
81
81
  @Prop()
82
- @Field()
82
+ // @Field()
83
83
  @ApiProperty({ type: 'number', required: false, default: 1 })
84
84
  tenantId?: number;
85
85
  @Prop()
86
- @Field()
86
+ // @Field()
87
87
  @ApiProperty({ type: 'number', required: false, default: 1 })
88
88
  orgId?: number;
89
89
  @Prop()
90
- @Field()
90
+ // @Field()
91
91
  @ApiProperty({ type: 'number', required: false, default: 1 })
92
92
  branchId?: number;
93
93
  @Prop()
94
- @Field()
94
+ // @Field()
95
95
  @ApiProperty({ type: 'string', required: true, default: '' })
96
96
  title: string;
97
97
  @Prop()
98
- @Field()
98
+ // @Field()
99
99
  @ApiProperty({ type: 'string', required: true, format: 'uri', default: '' })
100
100
  url: string;
101
101
  @Prop()
102
- @Field()
102
+ // @Field()
103
103
  @ApiProperty({ type: 'string', required: false, default: '' })
104
104
  requestMethod: string;
105
105
  @Prop()
106
- @Field()
106
+ // @Field()
107
107
  @ApiProperty({ type: 'string', required: false, description: 'apikey authentication use none + headers props', default: '' })
108
108
  authentication?: string;
109
109
  @Prop()
110
- @Field()
110
+ // @Field()
111
111
  @ApiProperty({ type: 'string', required: false, format: 'text', default: '' })
112
112
  description?: string;
113
113
  @Prop()
114
- @Field()
114
+ // @Field()
115
115
  @ApiProperty({ type: 'string', required: false, description: 'POST,PUT body template', format: 'text', default: '*' })
116
116
  body: string;
117
117
  @Prop()
118
- @Field()
118
+ // @Field()
119
119
  @ApiProperty({ type: 'boolean', required: false, default: true })
120
120
  active: boolean;
121
121
  @Prop()
122
- @Field()
122
+ // @Field()
123
123
  @ApiProperty({ type: 'string', required: false, default: '' })
124
124
  resourceName: string;
125
125
  @Prop()
126
- @Field()
126
+ // @Field()
127
127
  @ApiProperty({ type: 'string', required: false, default: '' })
128
128
  eventType: string;
129
129
  @Prop()
130
- @Field()
130
+ // @Field()
131
131
  @ApiProperty({ type: 'string', required: false, description: 'temporary support realtime and roll-back-when-failed, 2nd way way throw error and roll back data if webhook failed.)', default: '' })
132
132
  jobType: string;
133
133
  @Prop()
134
- @Field()
134
+ // @Field()
135
135
  @ApiProperty({ type: 'number', required: false, description: 'retries how many time when webhook failed', default: 0 })
136
136
  retryAttemps: number;
137
- @Field()
137
+ // @Field()
138
138
  @ApiProperty({ type: () => WebhookBasicAuth, required: false })
139
139
  basicAuth?: WebhookBasicAuth;
140
140
  @Prop()
@@ -144,21 +144,21 @@ export class Webhook {
144
144
  }
145
145
 
146
146
  /***************************************** Start Auto Complete *****************************************/
147
- @ObjectType()
147
+ // @ObjectType()
148
148
  @Schema()
149
149
  export class WebhookAutoComplete {
150
150
  @Prop()
151
- @Field()
151
+ // @Field()
152
152
  @ApiProperty({ type: 'string', required: true, default: '' })
153
153
  _id: string;
154
154
 
155
155
  @Prop()
156
- @Field()
156
+ // @Field()
157
157
  @ApiProperty({ type: 'string', required: true, default: '' })
158
158
  code: string;
159
159
 
160
160
  @Prop()
161
- @Field()
161
+ // @Field()
162
162
  @ApiProperty({ type: 'string', required: true, default: '' })
163
163
  label: string;
164
164
  }