@simitgroup/simpleapp-generator 2.0.1-c-alpha → 2.0.1-e-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 CHANGED
@@ -1,3 +1,11 @@
1
+ [2.0.1e-alpha]
2
+
3
+ 1. Fix developer portal cannot create app
4
+
5
+ [2.0.1d-alpha]
6
+
7
+ 1. Compulsory index tenantId for mongodb sharding
8
+
1
9
  [2.0.1c-alpha]
2
10
 
3
11
  1. Reopen searchWithRelation code
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.1c-alpha",
3
+ "version": "2.0.1e-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@ export const <%= capitalizeFirstLetter(it.typename) %>MongoSchema = SchemaFactor
8
8
  .pre('save', function(next) {
9
9
  this.increment();
10
10
  return next();
11
- })
11
+ }) .index({ 'tenantId': 1 })
12
12
 
13
13
  <% const config = it.jsonschema['x-simpleapp-config']%>
14
14
  <% if(config['uniqueKey']) {%>
@@ -1,16 +1,16 @@
1
- import { BadRequestException, Injectable, InternalServerErrorException } from '@nestjs/common';
1
+ import { Injectable, InternalServerErrorException } from '@nestjs/common';
2
2
  import { MiniAppManagerEnvDevelopmentService } from '../mini-app-manager/mini-app-manager-env-development.service';
3
3
  import { UserService } from '@resources/user/user.service';
4
4
  import { PermissionService } from '@resources/permission/permission.service';
5
5
  import { UserContext } from 'src/simple-app/_core/features/user-context/user.context';
6
6
  import { MiniApp } from '@resources/mini-app/mini-app.schema';
7
- import { User } from '@resources/user/user.schema';
7
+ import { User } from '@resources/user/user.schema';
8
8
  import _ from 'lodash';
9
9
  import { MiniAppError } from '../mini-app-manager/mini-app-manager.error';
10
10
  import { MiniAppManagerEnvEnum } from '../mini-app-manager/mini-app-manager.enum';
11
11
  import { InjectModel } from '@nestjs/mongoose';
12
12
  import { Model } from 'mongoose';
13
- import { DeveloperPortalService } from './developer-portal.service';
13
+ import { TenantLicenseEnum } from '@resources/tenant/tenant.enum';
14
14
 
15
15
  @Injectable()
16
16
  export class DeveloperPortalEnvDevelopmentService {
@@ -36,9 +36,8 @@ export class DeveloperPortalEnvDevelopmentService {
36
36
 
37
37
  async publish(appUser: UserContext, developerPortalAppId: string, dto: MiniApp) {
38
38
  this.assertDemoCompanyDefined();
39
-
40
39
  appUser.setAsStaticUser(dto.author.uid, dto.author.email, dto.author.name, dto.author.email, process.env.DEMO_COMPANY_XORG);
41
- // appUser.setPackage('enterprise'); // else cannot install mini app
40
+ appUser.setLicense(TenantLicenseEnum.ENTERPRISE); // else cannot install mini app
42
41
 
43
42
  const miniApp = await this.findMiniApp(developerPortalAppId, MiniAppManagerEnvEnum.DEV);
44
43
  if (!miniApp) {
@@ -76,12 +75,12 @@ export class DeveloperPortalEnvDevelopmentService {
76
75
  const users = await this.userService.search(appUser, {
77
76
  email: appUser.getEmail(),
78
77
  });
79
-
80
78
  if (users && users.length > 0) {
81
79
  return;
82
80
  }
83
81
 
84
82
  const user = await this.createUserRecordInDemoCompany(appUser, demoCompany);
83
+ appUser.setId(user._id);
85
84
  await this.assignPermissionToDemoDeveloper(appUser, demoCompany, user);
86
85
  }
87
86
 
@@ -94,7 +94,7 @@ export class ProfileService {
94
94
  const countryName = timezonedata['name'];
95
95
  const currencyCode = countryToCurrency[countryCode];
96
96
 
97
- appuser.getDBSession().startTransaction();
97
+ appuser.getDBSession().startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
98
98
  const tenantdata: Tenant = {
99
99
  tenantId: 1,
100
100
  tenantName: tenantName,
@@ -29,6 +29,7 @@ import { ModifiedRecords } from '../../framework/schemas';
29
29
  import { Role } from '../auth/role-guard/roles.enum';
30
30
  import { Environment } from '@core-features/maintenance/schemas';
31
31
  import * as rolegroups from '../auth/role-guard/roles.group';
32
+ import { TenantLicenseEnum } from '@resources/tenant/tenant.enum';
32
33
 
33
34
  // import systemWebHooks from '../../webhooks';
34
35
  @Injectable({ scope: Scope.REQUEST })
@@ -141,7 +142,7 @@ export class UserContext extends UserContextInfo {
141
142
  ) {
142
143
  super();
143
144
  }
144
- getEnvironment = ()=> this.systemEnvironment
145
+ getEnvironment = () => this.systemEnvironment;
145
146
  setDBSession = (dbsession: ClientSession) => {
146
147
  this.dbsession = dbsession;
147
148
  };
@@ -204,6 +205,18 @@ export class UserContext extends UserContextInfo {
204
205
 
205
206
  getMiniApiTokenInfo = () => this.miniApiTokenInfo;
206
207
 
208
+ setId = (id: string) => {
209
+ this._id = id;
210
+ };
211
+
212
+ setLicense = (license: TenantLicenseEnum) => {
213
+ if (!this.tenantInfo) {
214
+ this.tenantInfo = {} as any;
215
+ }
216
+
217
+ this.tenantInfo.license = license;
218
+ };
219
+
207
220
  setMiniApiToken = (token: string) => {
208
221
  this.miniApiToken = token;
209
222
  };
@@ -526,7 +539,7 @@ export class UserContext extends UserContextInfo {
526
539
  webhook: false,
527
540
  support: false,
528
541
  };
529
- this.roles = userProfile['roles'] ?? [Role.Everyone, Role.User,Role.CustomField_search,Role.QueueJob_search];
542
+ this.roles = userProfile['roles'] ?? [Role.Everyone, Role.User, Role.CustomField_search, Role.QueueJob_search];
530
543
 
531
544
  if (this.tenantInfo?.owner?.uid === this.uid) {
532
545
  this.roles.push(Role.TenantOwner);
@@ -1099,7 +1112,7 @@ export class UserContext extends UserContextInfo {
1099
1112
  if (this.isRealmAdmin() && !this.roles.includes(Role.SuperAdmin)) {
1100
1113
  this.roles.push(Role.SuperAdmin);
1101
1114
  }
1102
- this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
1115
+ // this.logger.verbose(`User ${this.uid} have _id (${this.getId()}), groups (${this.groups.join(',')}) and roles (${this.getRoles().join(',')}).`);
1103
1116
  }
1104
1117
 
1105
1118
  // getAppIntegration = () => this.appintegration;
@@ -357,106 +357,7 @@ export class SimpleAppService<T extends SchemaFields> {
357
357
  }
358
358
  }
359
359
 
360
- // seems no use, and confusing
361
- // async createManyWithId(appuser: UserContext, datas: T[]) {
362
- // if (Array.isArray(datas)) {
363
- // for (let i = 0; i < datas.length; i++) {
364
- // const data = datas[i];
365
- // let isolationFilter: any = { ...appuser.getCreateFilterWithId() };
366
- // isolationFilter = this.polishIsolationFilter(isolationFilter, data);
367
-
368
- // Object.assign(data, isolationFilter);
369
- // this.reCalculateValue(data);
370
- // await this.validateData(appuser, data);
371
- // this.applyNestedDateTime(appuser, data, 'create');
372
- // }
373
-
374
- // const dbsession = appuser.getDBSession();
375
- // if (dbsession && !dbsession.inTransaction()) {
376
- // dbsession.startTransaction({ readPreference: 'primary' });
377
- // }
378
-
379
- // const result = await this.doc.insertMany(datas, { session: dbsession });
380
- // await this.addManyAuditEvents(appuser, this.documentName, 'createMany', datas);
381
- // for (let i = 0; i < datas.length; i++) {
382
- // appuser.addInsertedRecordId(this.documentName, datas[i]._id);
383
- // }
384
- // return result;
385
- // } else {
386
- // throw new BadRequestException(this.getDocumentType() + ': create many only support array');
387
- // }
388
- // }
389
-
390
- /**
391
- * create many from array with hooks (temporary used for generate sample data only)
392
- * @param appuser
393
- * @param datas
394
- */
395
- //seems nobody use. also confusing
396
- // async createManyWithHook(appuser: UserContext, datas: T[]) {
397
- // if (Array.isArray(datas)) {
398
- // for (let i = 0; i < datas.length; i++) {
399
- // const data = datas[i];
400
-
401
- // let result;
402
- // const dbsession = appuser.getDBSession();
403
- // if (dbsession && !dbsession.inTransaction()) {
404
- // dbsession.startTransaction({ readPreference: 'primary' });
405
- // }
406
-
407
- // if (this.withDocNumberFormat && !data[this.documentIdentityCode]) {
408
- // await this.genNewDocNo(appuser, data);
409
- // }
410
-
411
- // let isolationFilter: any = { ...appuser.getCreateFilterWithId() };
412
- // isolationFilter = this.polishIsolationFilter(isolationFilter, data);
413
-
414
- // Object.assign(data, isolationFilter);
415
- // this.reCalculateValue(data);
416
- // await this.validateData(appuser, data);
417
- // this.applyNestedDateTime(appuser, data, 'create');
418
-
419
- // //new way of hook
420
- // await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
421
-
422
- // const newdoc = new this.doc(data);
423
-
424
- // try {
425
- // result = await newdoc.save({ session: dbsession });
426
- // await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
427
- // appuser.addInsertedRecordId(this.documentName, result._id);
428
- // } catch (err) {
429
- // this.logger.error(err);
430
- // throw new ProcessErrorException('ERR_CREATE_MANY',err.message,{
431
- // err:err
432
- // })
433
- // // const processdata = await this.runEvent(appuser, 'processdata.processError', {
434
- // // err: err,
435
- // // });
436
-
437
- // // if (!processdata) {
438
- // // throw new InternalServerErrorException(err);
439
- // // } else {
440
- // // throw new CustomException(processdata.code, processdata.msg);
441
- // // }
442
- // }
443
-
444
- // try {
445
- // //new way of hook
446
- // await this.runEvent(appuser, this.setHookName('afterCreate'), { data: data }, false);
447
- // await this.callWebhook(appuser, 'create', result);
448
-
449
- // // return result as T;
450
- // } catch (err) {
451
- // throw new InternalServerErrorException(`createHook ${this.documentType} error: ${JSON.stringify(err)}`, `${this.documentType} createHook error`);
452
- // }
453
- // }
454
- // } else {
455
- // throw new BadRequestException(this.getDocumentType() + ': create many only support array');
456
- // }
457
- // return 'ok';
458
- // }
459
-
360
+
460
361
  /**
461
362
  * create many from array, for performance reason it submit all item in 1 go, so it won't implement hooks
462
363
  * @param appuser
@@ -476,7 +377,7 @@ export class SimpleAppService<T extends SchemaFields> {
476
377
  }
477
378
  const dbsession = appuser.getDBSession();
478
379
  if (dbsession && !dbsession.inTransaction()) {
479
- dbsession.startTransaction({ readPreference: 'primary' });
380
+ dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
480
381
  }
481
382
 
482
383
  try {
@@ -495,71 +396,6 @@ export class SimpleAppService<T extends SchemaFields> {
495
396
  }
496
397
  }
497
398
 
498
- //seems nobody use, also confusing
499
- // async createWithId(appuser: UserContext, data: T) {
500
- // let result;
501
-
502
- // if (!data._id) {
503
- // data._id = crypto.randomUUID();
504
- // }
505
- // const dbsession = appuser.getDBSession();
506
- // if (dbsession && !dbsession.inTransaction()) {
507
- // dbsession.startTransaction({ readPreference: 'primary' });
508
- // }
509
-
510
- // this.logger.debug('this.withDocNumberFormat :' + this.withDocNumberFormat + ' && ' + '!data[this.documentIdentityCode] ==' + !data[this.documentIdentityCode]);
511
- // if (this.withDocNumberFormat && !data[this.documentIdentityCode]) {
512
- // await this.genNewDocNo(appuser, data);
513
- // }
514
-
515
- // let isolationFilter: any = { ...appuser.getCreateFilterWithId() };
516
- // isolationFilter = this.polishIsolationFilter(isolationFilter, data);
517
-
518
- // this.logger.debug('isolationFilter', 'SimpleAppService');
519
- // this.logger.debug(isolationFilter, 'SimpleAppService');
520
- // this.logger.debug('Create data before isolation', 'SimpleAppService');
521
- // this.logger.debug(data, 'SimpleAppService');
522
- // Object.assign(data, isolationFilter);
523
- // this.reCalculateValue(data);
524
- // await this.validateData(appuser, data);
525
- // this.logger.debug(data, `after create validation`);
526
- // this.applyNestedDateTime(appuser, data, 'create');
527
-
528
- // //new way of hook
529
-
530
- // await this.runEvent(appuser, this.setHookName('beforeCreate'), { data: data }, false);
531
-
532
- // this.logger.debug(data, `Create Record ${this.documentName}`);
533
- // const newdoc = new this.doc(data);
534
- // await this.identifyForeignKeys(appuser, data);
535
- // try {
536
- // result = await newdoc.save({ session: dbsession });
537
- // await this.addAuditEvent(appuser, this.documentName, result._id, 'create', data);
538
- // appuser.addInsertedRecordId(this.documentName, result._id);
539
- // } catch (err) {
540
- // this.logger.error(err);
541
- // const processdata = await this.runEvent(appuser, 'processdata.processError', {
542
- // err: err,
543
- // });
544
-
545
- // if (!processdata) {
546
- // throw new InternalServerErrorException(err);
547
- // } else {
548
- // throw new CustomException(processdata.code, processdata.msg);
549
- // }
550
- // }
551
-
552
- // try {
553
- // //new way of hook
554
- // await this.runEvent(appuser, this.setHookName('afterCreate'), { data: result }, false);
555
-
556
- // await this.callWebhook(appuser, 'create', result);
557
- // return result as T;
558
- // } catch (err) {
559
- // throw new InternalServerErrorException(`createHook ${this.documentType} error: ${JSON.stringify(err)}`, `${this.documentType} createHook error`);
560
- // }
561
- // }
562
-
563
399
  async create(appuser: UserContext, data: T, noStartTransaction: boolean = false) {
564
400
  let result;
565
401
 
@@ -568,7 +404,7 @@ export class SimpleAppService<T extends SchemaFields> {
568
404
  }
569
405
  const dbsession = appuser.getDBSession();
570
406
  if (dbsession && !dbsession.inTransaction() && !noStartTransaction) {
571
- dbsession.startTransaction({ readPreference: 'primary' });
407
+ dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
572
408
  }
573
409
 
574
410
  this.logger.debug('this.withDocNumberFormat :' + this.withDocNumberFormat + ' && ' + '!data[this.documentIdentityCode] ==' + !data[this.documentIdentityCode]);
@@ -714,7 +550,7 @@ export class SimpleAppService<T extends SchemaFields> {
714
550
  }
715
551
  const dbsession = appuser.getDBSession();
716
552
  if (dbsession && !dbsession.inTransaction()) {
717
- dbsession.startTransaction({ readPreference: 'primary' });
553
+ dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
718
554
  }
719
555
 
720
556
  let dependency;
@@ -793,7 +629,7 @@ export class SimpleAppService<T extends SchemaFields> {
793
629
 
794
630
  const dbsession = appuser.getDBSession();
795
631
  if (dbsession && !dbsession.inTransaction() && !noStartTransaction) {
796
- dbsession.startTransaction({ readPreference: 'primary' });
632
+ dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
797
633
  }
798
634
  // try {
799
635
  Object.assign(data, appuser.getUpdateFilter());
@@ -852,7 +688,7 @@ export class SimpleAppService<T extends SchemaFields> {
852
688
 
853
689
  const dbsession = appuser.getDBSession();
854
690
  if (dbsession && !dbsession.inTransaction()) {
855
- dbsession.startTransaction({ readPreference: 'primary' });
691
+ dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
856
692
  }
857
693
  // try {
858
694
  // Object.assign(data, appuser.getUpdateFilter());
@@ -908,7 +744,7 @@ export class SimpleAppService<T extends SchemaFields> {
908
744
  await this.runEvent(appuser, this.setHookName('beforePatch'), { id: id, patchData: data, prevData: existingdata }, false);
909
745
  const dbsession = appuser.getDBSession();
910
746
  if (dbsession && !dbsession.inTransaction()) {
911
- dbsession.startTransaction({ readPreference: 'primary' });
747
+ dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
912
748
  }
913
749
  // try {
914
750
  Object.assign(data, appuser.getUpdateFilter());
@@ -963,7 +799,7 @@ export class SimpleAppService<T extends SchemaFields> {
963
799
  // Get DB Session
964
800
  const dbsession = appuser.getDBSession();
965
801
  if (dbsession && !dbsession.inTransaction()) {
966
- dbsession.startTransaction({ readPreference: 'primary' });
802
+ dbsession.startTransaction({readConcern:{level:"snapshot"},writeConcern:{w:"majority"}, readPreference: 'primary' });
967
803
  }
968
804
 
969
805
  const result = await this.doc.updateMany(isolationFilter, { $set: patch }, { session: dbsession });