@things-factory/operato-board 6.0.69 → 6.0.70
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.
|
@@ -140,7 +140,7 @@ tslib_1.__decorate([
|
|
|
140
140
|
tslib_1.__metadata("design:returntype", Promise)
|
|
141
141
|
], BoardResolver.prototype, "boardPermissions", null);
|
|
142
142
|
tslib_1.__decorate([
|
|
143
|
-
(0, type_graphql_1.Directive)('@privilege(category: "board", privilege: "query")'),
|
|
143
|
+
(0, type_graphql_1.Directive)('@privilege(category: "board", privilege: "query", domainOwnerGranted: true)'),
|
|
144
144
|
(0, type_graphql_1.Query)(returns => board_service_1.Board, { description: 'To fetch a board' }),
|
|
145
145
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
146
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,+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,kBAAkB,CAAC;aAC7F,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAErB,IAAI,WAAW,GAAG,EAAE,CAAA;QAEpB,mBA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AC9D,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"]}
|
|
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,kBAAkB,CAAC;aAC7F,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QAErB,IAAI,WAAW,GAAG,EAAE,CAAA;QAEpB,mBAAmB,CAAC,QAAQ,CAAC,UAAU,CAAC;YACtC,CAAC,MAAM,gBAAI,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YAC5D,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAE9B,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC;YACpC,CAAC,MAAM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,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\", domainOwnerGranted: true)')\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"]}
|