@codefresh-io/authenticated-entity
Advanced tools
Comparing version 2.11.2 to 2.13.0
const _ = require('lodash'); | ||
const { AGENT } = require('./Types'); | ||
const Types = require('./Types'); | ||
const Entity = require('./Entity'); | ||
@@ -12,5 +12,3 @@ | ||
class Agent extends Entity { | ||
constructor(data) { | ||
const accountName = _.get(data, 'account.name'); | ||
@@ -33,6 +31,7 @@ if (!accountName) { | ||
super({ | ||
type: AGENT, | ||
type: Types.AGENT, | ||
...data | ||
}); | ||
} | ||
getActiveAccount() { | ||
@@ -39,0 +38,0 @@ return _.get(this, '_entity.account', {}); |
const _ = require('lodash'); | ||
const Entity = require('./Entity'); | ||
const { ENGINE } = require('./Types'); | ||
const Types = require('./Types'); | ||
@@ -13,3 +13,2 @@ const Errors = { | ||
class Engine extends Entity { | ||
constructor(data) { | ||
@@ -39,3 +38,3 @@ const accountName = _.get(data, 'account.name'); | ||
super({ | ||
type: ENGINE, | ||
type: Types.ENGINE, | ||
...data, | ||
@@ -53,7 +52,2 @@ }); | ||
// eslint-disable-next-line class-methods-use-this | ||
isAccountAdmin() { | ||
return false; | ||
} | ||
isValidAccount(id) { | ||
@@ -65,3 +59,2 @@ return _.isEqual(_.get(this, '_entity.account._id'), id); | ||
return this.toJson(); | ||
} | ||
@@ -68,0 +61,0 @@ } |
@@ -9,3 +9,2 @@ const _ = require('lodash'); | ||
class Entity { | ||
constructor(data) { | ||
@@ -67,22 +66,32 @@ if (!data.type) { | ||
isSystemEntity() { | ||
return this._entity.type === Types.SYSTEM; | ||
return this.getType() === Types.SYSTEM; | ||
} | ||
isEngineEntity() { | ||
return this._entity.type === Types.ENGINE; | ||
return this.getType() === Types.ENGINE; | ||
} | ||
isRuntimeEnvironmentEntity() { | ||
return this._entity.type === Types.RUNTIME_ENVIRONMENT; | ||
return this.getType() === Types.RUNTIME_ENVIRONMENT; | ||
} | ||
isUserEntity() { | ||
return this._entity.type === Types.USER; | ||
return this.getType() === Types.USER; | ||
} | ||
isAgentEntity() { | ||
return this._entity.type === Types.AGENT; | ||
return this.getType() === Types.AGENT; | ||
} | ||
isServiceAccountEntity() { | ||
return this.getType() === Types.SERVICE_ACCOUNT; | ||
} | ||
// eslint-disable-next-line class-methods-use-this | ||
isAccountAdmin() { | ||
return false; // default implementation - should be overridden if needed | ||
} | ||
getName() { | ||
return _.get(this, '_entity.name', this._entity.type); | ||
return _.get(this, '_entity.name', this.getType()); | ||
} | ||
@@ -158,3 +167,3 @@ | ||
} | ||
if (!this.isSystemEntity() && this.getActiveAccount().id === accountId) { | ||
if (!this.isSystemEntity() && this.getActiveAccountId() === accountId) { | ||
accountId = undefined; | ||
@@ -188,3 +197,2 @@ } | ||
evaluateFeatureFlag(feature, accountId) { //eslint-disable-line | ||
@@ -196,3 +204,3 @@ return Promise.resolve() | ||
} | ||
if (!this.isSystemEntity() && this.getActiveAccount().id === accountId) { | ||
if (!this.isSystemEntity() && this.getActiveAccountId() === accountId) { | ||
accountId = undefined; | ||
@@ -222,4 +230,3 @@ } | ||
}, | ||
}) | ||
.then(res => res.body); | ||
}).then(res => res.body); | ||
}); | ||
@@ -251,2 +258,12 @@ } | ||
getActiveAccountId() { | ||
const account = this.getActiveAccount(); | ||
return _.get(account, '_id') || _.get(account, 'id'); | ||
} | ||
getFeaturesOfActiveAccount() { | ||
const activeAccount = this.getActiveAccount(); | ||
return _.get(activeAccount, 'features'); | ||
} | ||
_getPartialJson() { | ||
@@ -253,0 +270,0 @@ return { |
const _ = require('lodash'); | ||
const Types = require('./Types'); | ||
const User = require('./User'); | ||
const ServiceAccount = require('./ServiceAccount'); | ||
const System = require('./System'); | ||
@@ -28,19 +29,21 @@ const RuntimeEnvironment = require('./RuntimeEnvironment'); | ||
if (parsedJsonEntity.type === Types.USER) { | ||
return new User(parsedJsonEntity); | ||
} else if (parsedJsonEntity.type === Types.SYSTEM) { | ||
return new System(parsedJsonEntity.serviceName); | ||
} else if (parsedJsonEntity.type === Types.RUNTIME_ENVIRONMENT) { | ||
return new RuntimeEnvironment(parsedJsonEntity); | ||
} else if (parsedJsonEntity.type === Types.ENGINE) { | ||
return new Engine(parsedJsonEntity); | ||
} else if (parsedJsonEntity.type === Types.AGENT) { | ||
return new Agent(parsedJsonEntity); | ||
} else if (!parsedJsonEntity.type) { | ||
parsedJsonEntity.type = Types.USER; | ||
return new User(parsedJsonEntity); | ||
switch (parsedJsonEntity.type) { | ||
case Types.USER: | ||
return new User(parsedJsonEntity); | ||
case Types.SYSTEM: | ||
return new System(parsedJsonEntity.serviceName); | ||
case Types.RUNTIME_ENVIRONMENT: | ||
return new RuntimeEnvironment(parsedJsonEntity); | ||
case Types.ENGINE: | ||
return new Engine(parsedJsonEntity); | ||
case Types.AGENT: | ||
return new Agent(parsedJsonEntity); | ||
case Types.SERVICE_ACCOUNT: | ||
return new ServiceAccount(parsedJsonEntity); | ||
case undefined: | ||
parsedJsonEntity.type = Types.USER; | ||
return new User(parsedJsonEntity); | ||
default: | ||
throw new Error(`constructFromEncodedString failed. Given encoded entity type: ${parsedJsonEntity.type} is not supported`); | ||
} | ||
throw new Error(`constructFromEncodedString failed. Given encoded entity type: ${parsedJsonEntity.type} is not supported`); | ||
}; | ||
@@ -51,2 +54,3 @@ | ||
User, | ||
ServiceAccount, | ||
RuntimeEnvironment, | ||
@@ -53,0 +57,0 @@ System, |
const _ = require('lodash'); | ||
const Entity = require('./Entity'); | ||
const { RUNTIME_ENVIRONMENT } = require('./Types'); | ||
const Types = require('./Types'); | ||
@@ -12,3 +12,2 @@ const Errors = { | ||
class RuntimeEnvironment extends Entity { | ||
constructor(data) { | ||
@@ -33,3 +32,3 @@ const accountName = _.get(data, 'account.name'); | ||
super({ | ||
type: RUNTIME_ENVIRONMENT, | ||
type: Types.RUNTIME_ENVIRONMENT, | ||
...data, | ||
@@ -43,7 +42,2 @@ }); | ||
// eslint-disable-next-line class-methods-use-this | ||
isAccountAdmin() { | ||
return false; | ||
} | ||
getName() { | ||
@@ -50,0 +44,0 @@ return _.get(this, '_entity.name', ''); |
const Entity = require('./Entity'); | ||
const Types = require('./Types'); | ||
@@ -8,3 +9,2 @@ /** | ||
class System extends Entity { | ||
constructor(serviceName) { | ||
@@ -16,3 +16,3 @@ if (!serviceName) { | ||
super({ | ||
type: 'system', | ||
type: Types.SYSTEM, | ||
serviceName | ||
@@ -19,0 +19,0 @@ }); |
const TYPES = { | ||
USER: 'user', | ||
SERVICE_ACCOUNT: 'service-account', | ||
SYSTEM: 'system', | ||
@@ -4,0 +5,0 @@ RUNTIME_ENVIRONMENT: 'runtime-environment', |
const _ = require('lodash'); | ||
const Entity = require('./Entity'); | ||
const Types = require('./Types'); | ||
const { getInternalRequestLogic, paymentsService } = require('./internalRequest'); | ||
@@ -24,3 +25,2 @@ | ||
class User extends Entity { | ||
/** | ||
@@ -38,9 +38,6 @@ * Use this static method to create new User entity from given user model | ||
const data = { | ||
type: 'user', | ||
type: Types.USER, | ||
name: user.userName, | ||
_id: userId, | ||
accounts: user.account | ||
.map((account) => { | ||
return this.extractAccountData(account, userId); | ||
}) | ||
accounts: user.account.map(account => this.extractAccountData(account, userId)) | ||
}; | ||
@@ -114,4 +111,4 @@ | ||
return this.getFeatures(account); | ||
} | ||
} | ||
getPlanByAccountId(accountId) { // eslint-disable-line | ||
@@ -123,4 +120,4 @@ const request = getInternalRequestLogic(); | ||
requestOptions: { | ||
method: 'GET', | ||
}, | ||
method: 'GET' | ||
} | ||
}) | ||
@@ -134,2 +131,3 @@ .then(res => res.body) | ||
} | ||
getUserId() { | ||
@@ -143,2 +141,10 @@ return this._entity._id; | ||
get id() { // alias for consistency with service-account entity | ||
return this.getUserId(); | ||
} | ||
get name() { // alias for consistency with service-account entity | ||
return this.getUserName(); | ||
} | ||
_getPartialJson() { | ||
@@ -148,3 +154,3 @@ return Object.assign(super._getPartialJson(), { | ||
name: this.getUserName(), | ||
activeAccount: this.getActiveAccount(), | ||
activeAccount: this.getActiveAccount() | ||
}); | ||
@@ -151,0 +157,0 @@ } |
{ | ||
"name": "@codefresh-io/authenticated-entity", | ||
"version": "2.11.2", | ||
"version": "2.13.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
174202
24
1781