@things-factory/operato-board 6.0.52 → 6.0.54

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.
@@ -14,6 +14,7 @@ export class MenuTools extends connect(store)(LitElement) {
14
14
  type: String,
15
15
  reflect: true
16
16
  },
17
+ editable: Boolean,
17
18
  context: Object
18
19
  }
19
20
  }
@@ -98,6 +99,8 @@ export class MenuTools extends connect(store)(LitElement) {
98
99
  <div><ox-i18n msgid="label.player"></ox-i18n></div>
99
100
  </a>
100
101
  </li>
102
+ ${this.editable
103
+ ? html`
101
104
  <li>
102
105
  <a href="font-list" ?active=${this.page == 'font-list'}>
103
106
  <mwc-icon>font_download</mwc-icon>
@@ -123,6 +126,9 @@ export class MenuTools extends connect(store)(LitElement) {
123
126
  </a>
124
127
  </li>
125
128
  </ul>
129
+ `
130
+ : html``}
131
+ </ul>
126
132
  `
127
133
  : html``
128
134
  }
@@ -131,6 +137,7 @@ export class MenuTools extends connect(store)(LitElement) {
131
137
  this.page = state.route.page
132
138
  this.width = state.layout.width
133
139
  this.context = state.route.context
140
+ this.editable = state.permissions?.boardPermissions?.includes('Modeller')
134
141
  }
135
142
  }
136
143
 
@@ -8,14 +8,14 @@ tslib_1.__exportStar(require("./subscribers"), exports);
8
8
  tslib_1.__exportStar(require("./service"), exports);
9
9
  require("./routes");
10
10
  process.on('bootstrap-module-start', async ({ app, config, client }) => {
11
- console.log('%%%%%%%%%%%%%%%% SCENARIO ENGINE - BEGIN %%%%%%%%%%%%%%%%');
12
11
  try {
13
12
  await integration_base_1.ConnectionManager.ready();
14
13
  await integration_base_1.ScenarioEngine.loadAll();
14
+ console.log('[operato-board:bootstrap] Scenario Engine has just started.');
15
15
  }
16
16
  catch (ex) {
17
17
  integration_base_1.ConnectionManager.logger.error(ex);
18
+ console.log('[operato-board:bootstrap] Just has failed to start Scenario Engine.');
18
19
  }
19
- console.log('%%%%%%%%%%%%%%%% SCENARIO ENGINE - END %%%%%%%%%%%%%%%%');
20
20
  });
21
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,uEAAoF;AAEpF,uDAA4B;AAC5B,wDAA6B;AAC7B,wDAA6B;AAC7B,oDAAyB;AAEzB,oBAAiB;AAEjB,OAAO,CAAC,EAAE,CAAC,wBAA+B,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAO,EAAE,EAAE;IACjF,OAAO,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAA;IACxE,IAAI;QACF,MAAM,oCAAiB,CAAC,KAAK,EAAE,CAAA;QAC/B,MAAM,iCAAc,CAAC,OAAO,EAAE,CAAA;KAC/B;IAAC,OAAO,EAAE,EAAE;QACX,oCAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;KACnC;IACD,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAA;AACxE,CAAC,CAAC,CAAA","sourcesContent":["import { ConnectionManager, ScenarioEngine } from '@things-factory/integration-base'\n\nexport * from './migrations'\nexport * from './middlewares'\nexport * from './subscribers'\nexport * from './service'\n\nimport './routes'\n\nprocess.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {\n console.log('%%%%%%%%%%%%%%%% SCENARIO ENGINE - BEGIN %%%%%%%%%%%%%%%%')\n try {\n await ConnectionManager.ready()\n await ScenarioEngine.loadAll()\n } catch (ex) {\n ConnectionManager.logger.error(ex)\n }\n console.log('%%%%%%%%%%%%%%%% SCENARIO ENGINE - END %%%%%%%%%%%%%%%%')\n})\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,uEAAoF;AAEpF,uDAA4B;AAC5B,wDAA6B;AAC7B,wDAA6B;AAC7B,oDAAyB;AAEzB,oBAAiB;AAEjB,OAAO,CAAC,EAAE,CAAC,wBAA+B,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAO,EAAE,EAAE;IACjF,IAAI;QACF,MAAM,oCAAiB,CAAC,KAAK,EAAE,CAAA;QAC/B,MAAM,iCAAc,CAAC,OAAO,EAAE,CAAA;QAE9B,OAAO,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAA;KAC3E;IAAC,OAAO,EAAE,EAAE;QACX,oCAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAClC,OAAO,CAAC,GAAG,CAAC,qEAAqE,CAAC,CAAA;KACnF;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { ConnectionManager, ScenarioEngine } from '@things-factory/integration-base'\n\nexport * from './migrations'\nexport * from './middlewares'\nexport * from './subscribers'\nexport * from './service'\n\nimport './routes'\n\nprocess.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {\n try {\n await ConnectionManager.ready()\n await ScenarioEngine.loadAll()\n\n console.log('[operato-board:bootstrap] Scenario Engine has just started.')\n } catch (ex) {\n ConnectionManager.logger.error(ex)\n console.log('[operato-board:bootstrap] Just has failed to start Scenario Engine.')\n }\n})\n"]}
@@ -9,10 +9,22 @@ const shell_1 = require("@things-factory/shell");
9
9
  const license_error_1 = require("../../errors/license-error");
10
10
  const domain_secret_1 = require("../domain-secret/domain-secret");
11
11
  const board_secret_1 = require("./board-secret");
12
+ const auth_base_1 = require("@things-factory/auth-base");
12
13
  const crypto = require('crypto');
13
14
  let BoardResolver = class BoardResolver {
14
- boardPermissions(context) {
15
- return ((0, operato_license_checker_1.getPermission)('Permissions For Board Usage') || 'Modeller, Viewer').split(',').map(p => p.trim());
15
+ async boardPermissions(context) {
16
+ const { user, domain } = context.state;
17
+ const licensedPermissions = ((0, operato_license_checker_1.getPermission)('Permissions For Board Usage') || 'Modeller, Viewer')
18
+ .split(',')
19
+ .map(p => p.trim());
20
+ var permissions = [];
21
+ licensedPermissions.includes('Modeller') &&
22
+ (await auth_base_1.User.hasPrivilege('mutation', 'board', domain, user)) &&
23
+ permissions.push('Modeller');
24
+ licensedPermissions.includes('Viewer') &&
25
+ (await auth_base_1.User.hasPrivilege('query', 'board', domain, user)) &&
26
+ permissions.push('Viewer');
27
+ return permissions;
16
28
  }
17
29
  async board(id, context) {
18
30
  const { domain } = context.state;
@@ -125,9 +137,10 @@ tslib_1.__decorate([
125
137
  tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
126
138
  tslib_1.__metadata("design:type", Function),
127
139
  tslib_1.__metadata("design:paramtypes", [Object]),
128
- tslib_1.__metadata("design:returntype", Array)
140
+ tslib_1.__metadata("design:returntype", Promise)
129
141
  ], BoardResolver.prototype, "boardPermissions", null);
130
142
  tslib_1.__decorate([
143
+ (0, type_graphql_1.Directive)('@privilege(category: "board", privilege: "query")'),
131
144
  (0, type_graphql_1.Query)(returns => board_service_1.Board, { description: 'To fetch a board' }),
132
145
  tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
133
146
  tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
@@ -1 +1 @@
1
- {"version":3,"file":"board-resolver.js","sourceRoot":"","sources":["../../../server/service/board-secret/board-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAAwD;AAExD,iEAAqD;AACrD,qFAAiG;AACjG,iDAAqD;AAErD,8DAAyD;AACzD,kEAA6D;AAC7D,iDAA4C;AAE5C,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGzB,IAAM,aAAa,GAAnB,MAAM,aAAa;IAExB,gBAAgB,CAAQ,OAAwB;QAC9C,OAAO,CAAC,IAAA,uCAAa,EAAC,6BAA6B,CAAC,IAAI,kBAAkB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;IAC3G,CAAC;IAGK,AAAN,KAAK,CAAC,KAAK,CAAY,EAAU,EAAS,OAAwB;QAChE,MAAM,EA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AE;wBACf,IAAI,IAAI,GAAG,IAAA,qCAAW,EAAC,EAAE,KAAK,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;wBACzD,IAAI,WAAW,CAAC,MAAM,KAAK,IAAI,EAAE;4BAC/B,MAAM,IAAI,4BAAY,CAAC;gCACrB,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,4BAAY,CAAC,WAAW,CAAC,kBAAkB,CAAC;6BAClE,CAAC,CAAA;yBACH;qBACF;yBAAM;wBACL,MAAM,IAAI,4BAAY,CAAC;4BACrB,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,4BAAY,CAAC,WAAW,CAAC,kBAAkB,CAAC;yBAClE,CAAC,CAAA;qBACH;iBACF;aACF;SACF;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF,CAAA;AAlHC;IAAC,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;IACrD,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;qDAEtB;AAGK;IADL,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,qBAAK,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAChD,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0CA2GxC;AAlHU,aAAa;IADzB,IAAA,uBAAQ,EAAC,qBAAK,CAAC;GACH,aAAa,CAmHzB;AAnHY,sCAAa","sourcesContent":["import { Arg, Ctx, Query, Resolver } from 'type-graphql'\n\nimport { Board } from '@things-factory/board-service'\nimport { checkTarget, doSomething, getPermission } from '@things-factory/operato-license-checker'\nimport { getRepository } from '@things-factory/shell'\n\nimport { LicenseError } from '../../errors/license-error'\nimport { DomainSecret } from '../domain-secret/domain-secret'\nimport { BoardSecret } from './board-secret'\n\nconst crypto = require('crypto')\n\n@Resolver(Board)\nexport class BoardResolver {\n @Query(returns => [String], { description: 'Board Usage Permissions' })\n boardPermissions(@Ctx() context: ResolverContext): string[] {\n return (getPermission('Permissions For Board Usage') || 'Modeller, Viewer').split(',').map(p => p.trim())\n }\n\n @Query(returns => Board, { description: 'To fetch a board' })\n async board(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Board> {\n const { domain } = context.state\n\n var board = await getRepository(Board).findOne({\n where: { domain: { id: domain.id }, id }\n })\n if (domain) {\n // 1. check domainSecret is over limit quantity or not\n var count =\n (await getRepository(DomainSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(DomainSecret, 'secret')\n .where('id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var domainSecret: DomainSecret = await getRepository(DomainSecret).findOne({\n where: { domain: { id: domain.id } }\n })\n // 2. if there's no domainSecret then create it\n if (!domainSecret) {\n var domainSecret: DomainSecret = new DomainSecret()\n domainSecret.id = crypto.randomUUID()\n domainSecret.domain = domain\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n domainSecret.secret = hash\n\n await getRepository(DomainSecret).save(domainSecret)\n // 3. if there's domainSecret then check it\n } else {\n var domainRepo = getRepository(DomainSecret)\n var domainSecret: DomainSecret = await domainRepo.findOne({\n where: { domain: { id: domain.id } }\n })\n if (domainSecret) {\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n if (domainSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n if (board) {\n // 1. check boardSecret is over limit quantity or not\n var count =\n (await getRepository(BoardSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(BoardSecret, 'secret')\n .where('domain_id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var boardSecret: BoardSecret = await getRepository(BoardSecret).findOne({\n where: { targetId: id }\n })\n // 2. if there's no boardSecret then create it\n if (!boardSecret) {\n var boardSecret: BoardSecret = new BoardSecret()\n boardSecret.id = crypto.randomUUID()\n boardSecret.targetId = id\n boardSecret.targetType = 'board'\n boardSecret.domain = domain\n\n var hash = doSomething({ secId: boardSecret.id, id: id })\n boardSecret.secret = hash\n\n await getRepository(BoardSecret).save(boardSecret)\n // 3. if there's boardSecret then check it\n } else {\n var repogitory = getRepository(BoardSecret)\n var boardSecret: BoardSecret = await repogitory.findOne({\n where: { targetId: id }\n })\n if (boardSecret) {\n var hash = doSomething({ secId: boardSecret.id, id: id })\n if (boardSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n\n return board\n }\n}\n"]}
1
+ {"version":3,"file":"board-resolver.js","sourceRoot":"","sources":["../../../server/service/board-secret/board-resolver.ts"],"names":[],"mappings":";;;;AAAA,+CAAmE;AAEnE,iEAAqD;AACrD,qFAAiG;AACjG,iDAAqD;AAErD,8DAAyD;AACzD,kEAA6D;AAC7D,iDAA4C;AAC5C,yDAAgD;AAEhD,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;AAGzB,IAAM,aAAa,GAAnB,MAAM,aAAa;IAElB,AAAN,KAAK,CAAC,gBAAgB,CAAQ,OAAwB;QACpD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAEtC,MAAM,mBAAmB,GAAG,CAAC,IAAA,uCAAa,EAAC,6BAA6B,CAAC,IAAI,k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CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;IAC/C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;qDAkB5B;AAIK;IAFL,IAAA,wBAAS,EAAC,mDAAmD,CAAC;IAC9D,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,qBAAK,EAAE,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IAChD,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0CA2GxC;AAnIU,aAAa;IADzB,IAAA,uBAAQ,EAAC,qBAAK,CAAC;GACH,aAAa,CAoIzB;AApIY,sCAAa","sourcesContent":["import { Arg, Ctx, Directive, Query, Resolver } from 'type-graphql'\n\nimport { Board } from '@things-factory/board-service'\nimport { checkTarget, doSomething, getPermission } from '@things-factory/operato-license-checker'\nimport { getRepository } from '@things-factory/shell'\n\nimport { LicenseError } from '../../errors/license-error'\nimport { DomainSecret } from '../domain-secret/domain-secret'\nimport { BoardSecret } from './board-secret'\nimport { User } from '@things-factory/auth-base'\n\nconst crypto = require('crypto')\n\n@Resolver(Board)\nexport class BoardResolver {\n @Query(returns => [String], { description: 'Board Usage Permissions' })\n async boardPermissions(@Ctx() context: ResolverContext): Promise<string[]> {\n const { user, domain } = context.state\n\n const licensedPermissions = (getPermission('Permissions For Board Usage') || 'Modeller, Viewer')\n .split(',')\n .map(p => p.trim())\n\n var permissions = []\n\n licensedPermissions.includes('Modeller') &&\n (await User.hasPrivilege('mutation', 'board', domain, user)) &&\n permissions.push('Modeller')\n\n licensedPermissions.includes('Viewer') &&\n (await User.hasPrivilege('query', 'board', domain, user)) &&\n permissions.push('Viewer')\n\n return permissions\n }\n\n @Directive('@privilege(category: \"board\", privilege: \"query\")')\n @Query(returns => Board, { description: 'To fetch a board' })\n async board(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Board> {\n const { domain } = context.state\n\n var board = await getRepository(Board).findOne({\n where: { domain: { id: domain.id }, id }\n })\n if (domain) {\n // 1. check domainSecret is over limit quantity or not\n var count =\n (await getRepository(DomainSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(DomainSecret, 'secret')\n .where('id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var domainSecret: DomainSecret = await getRepository(DomainSecret).findOne({\n where: { domain: { id: domain.id } }\n })\n // 2. if there's no domainSecret then create it\n if (!domainSecret) {\n var domainSecret: DomainSecret = new DomainSecret()\n domainSecret.id = crypto.randomUUID()\n domainSecret.domain = domain\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n domainSecret.secret = hash\n\n await getRepository(DomainSecret).save(domainSecret)\n // 3. if there's domainSecret then check it\n } else {\n var domainRepo = getRepository(DomainSecret)\n var domainSecret: DomainSecret = await domainRepo.findOne({\n where: { domain: { id: domain.id } }\n })\n if (domainSecret) {\n var hash = doSomething({ secId: domainSecret.id, id: domain.id })\n if (domainSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n if (board) {\n // 1. check boardSecret is over limit quantity or not\n var count =\n (await getRepository(BoardSecret)\n .manager.createQueryBuilder()\n .select('board')\n .from(BoardSecret, 'secret')\n .where('domain_id = :domainId', { domainId: domain.id })\n .getCount()) + 1\n\n if (!checkTarget(count)) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.OVER_LIMIT)\n })\n } else {\n var boardSecret: BoardSecret = await getRepository(BoardSecret).findOne({\n where: { targetId: id }\n })\n // 2. if there's no boardSecret then create it\n if (!boardSecret) {\n var boardSecret: BoardSecret = new BoardSecret()\n boardSecret.id = crypto.randomUUID()\n boardSecret.targetId = id\n boardSecret.targetType = 'board'\n boardSecret.domain = domain\n\n var hash = doSomething({ secId: boardSecret.id, id: id })\n boardSecret.secret = hash\n\n await getRepository(BoardSecret).save(boardSecret)\n // 3. if there's boardSecret then check it\n } else {\n var repogitory = getRepository(BoardSecret)\n var boardSecret: BoardSecret = await repogitory.findOne({\n where: { targetId: id }\n })\n if (boardSecret) {\n var hash = doSomething({ secId: boardSecret.id, id: id })\n if (boardSecret.secret !== hash) {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n } else {\n throw new LicenseError({\n errorCode: context.t(LicenseError.ERROR_CODES.VERIFICATION_ERROR)\n })\n }\n }\n }\n }\n\n return board\n }\n}\n"]}