New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@wmfs/tymly

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wmfs/tymly - npm Package Compare versions

Comparing version

to
1.13.0

@@ -0,1 +1,19 @@

# [1.13.0](https://github.com/wmfs/tymly-core/compare/v1.12.1...v1.13.0) (2018-07-27)
### ✨ Features
* Propagate userId from statebox service into storage service so _createdBy and _modifiedBy can ([d490abf](https://github.com/wmfs/tymly-core/commit/d490abf))
* Trying out cls-hooked to see we can use it to propagate the userId through statemachine execut ([909f5c1](https://github.com/wmfs/tymly-core/commit/909f5c1))
### 📦 Code Refactoring
* All restrictd calls now go through processIfAuthorised, including start execution ([85e74db](https://github.com/wmfs/tymly-core/commit/85e74db))
### 🚨 Tests
* Dynamically create tests ([1222c8c](https://github.com/wmfs/tymly-core/commit/1222c8c))
## [1.12.1](https://github.com/wmfs/tymly-core/compare/v1.12.0...v1.12.1) (2018-07-27)

@@ -2,0 +20,0 @@

@@ -6,2 +6,5 @@ 'use strict'

const cls = require('cls-hooked')
const session = cls.createNamespace('statebox')
const ENABLE_RBAC = false

@@ -85,11 +88,9 @@

const [authOk, errExecDesc] = await this.authorisationCheck(
return this.processIfAuthorised(
executionOptions.userId,
stateMachineName,
executionOptions,
'create'
'create',
() => this.statebox.startExecution(input, stateMachineName, executionOptions)
)
return authOk
? this.statebox.startExecution(input, stateMachineName, executionOptions)
: errExecDesc
} // startExecution

@@ -104,3 +105,3 @@

return this.proceedIfAuthorised(
return this.describeAndProcessIfAuthorised(
executionName,

@@ -168,3 +169,3 @@ executionOptions,

updateIfAuthorised (executionName, output, executionOptions, updateFn) {
return this.proceedIfAuthorised(
return this.describeAndProcessIfAuthorised(
executionName,

@@ -177,16 +178,41 @@ executionOptions,

async proceedIfAuthorised (executionName, executionOptions, action, actionFn) {
async describeAndProcessIfAuthorised (executionName, executionOptions, action, actionFn) {
const executionDescription = await this.statebox.describeExecution(executionName, executionOptions)
const [authOk, errExecDesc] = await this.authorisationCheck(
return this.processIfAuthorised(
executionOptions.userId,
executionDescription.stateMachineName,
executionDescription.executionOptions,
action,
actionFn
)
} // describeAndProcessIfAuthorised
async processIfAuthorised (userId, stateMachineName, executionOptions, action, actionFn) {
const [authOk, errExecDesc] = await this.authorisationCheck(
userId,
stateMachineName,
executionOptions,
action
)
return (authOk)
? actionFn()
: errExecDesc
if (!authOk) return errExecDesc
let result = null
session.run(() => {
this.bindCurrentUser(session, userId)
result = actionFn()
})
return result
} // processIfAuthorised
bindCurrentUser (session, userId) {
if (this.services.storage.setCurrentUser) {
session.set('userId', userId)
this.services.storage.setCurrentUser(() => {
return session.get('userId')
}
)
} // if ...
}
authorisationCheck (userId, stateMachineName, executionOptions, action) {

@@ -193,0 +219,0 @@ if (!ENABLE_RBAC) {

@@ -23,4 +23,6 @@ 'use strict'

const CREATED_BY = '_createdBy'
const MODIFIED_BY = '_modifiedBy'
// TODO: This could be a useful module in its own right?
class MemoryModel {

@@ -43,3 +45,3 @@ constructor (modelDefinition, service) {

this.promised = (...args) => promised(this, ...args)
this._modifiedBy = (service && service.currentUser) ? () => service.currentUser() : () => null
this.currentUser = (service && service.currentUser) ? () => service.currentUser() : () => null
}

@@ -78,3 +80,3 @@

// copy.updated = now
copy.createdBy = _this._modifiedBy()
copy[CREATED_BY] = _this.currentUser()
_this.data.push(copy)

@@ -298,3 +300,3 @@

const update = _.cloneDeep(doc)
update.modifiedBy = this._modifiedBy()
update[MODIFIED_BY] = this.currentUser()
this.data[index] = update

@@ -316,3 +318,3 @@ }

}
this.data[index]['modifiedBy'] = this._modifiedBy()
this.data[index][MODIFIED_BY] = this.currentUser()
}

@@ -319,0 +321,0 @@ callback(null)

{
"name": "@wmfs/tymly",
"version": "1.12.1",
"version": "1.13.0",
"description": "A framework for building and sharing workflows in Node.js",

@@ -24,4 +24,6 @@ "author": "West Midlands Fire Service",

"dependencies": {
"@wmfs/statebox": "1.3.1",
"async": "2.6.1",
"boom": "7.2.0",
"cls-hooked": "^4.2.2",
"debug": "3.1.0",

@@ -35,4 +37,4 @@ "dottie": "2.0.0",

"lru-cache": "4.1.3",
"mkdirp": "0.5.1",
"moment": "2.22.2",
"mkdirp": "0.5.1",
"mongodb-extended-json": "1.10.0",

@@ -43,3 +45,2 @@ "nanoid": "1.1.0",

"sprintf-js": "1.1.1",
"@wmfs/statebox": "1.3.1",
"underscore-query": "3.3.2",

@@ -46,0 +47,0 @@ "upath": "1.1.0",

@@ -6,3 +6,3 @@ {

"Type": "Wait",
"Seconds": "10",
"Seconds": "2",
"Next": "Upserting"

@@ -27,3 +27,5 @@ },

"where": {
"employeeNo": "$.employeeNo"
"employeeNo": {
"equals": "$.employeeNo"
}
}

@@ -30,0 +32,0 @@ }

@@ -21,3 +21,5 @@ {

"where": {
"employeeNo": "$.employeeNo"
"employeeNo": {
"equals": "$.employeeNo"
}
}

@@ -24,0 +26,0 @@ }

@@ -6,3 +6,3 @@ {

"Type": "Wait",
"Seconds": "5",
"Seconds": "1",
"Next": "Upserting"

@@ -27,3 +27,5 @@ },

"where": {
"employeeNo": "$.employeeNo"
"employeeNo": {
"equals": "$.employeeNo"
}
}

@@ -30,0 +32,0 @@ }

@@ -691,3 +691,3 @@ /* eslint-env mocha */

'age': 39,
'createdBy': 'test'
'_createdBy': 'test'
}

@@ -724,4 +724,4 @@ )

'age': 39,
'createdBy': 'test',
'modifiedBy': 'modifier'
'_createdBy': 'test',
'_modifiedBy': 'modifier'
}

@@ -728,0 +728,0 @@ )

@@ -13,3 +13,3 @@ /* eslint-env mocha */

this.timeout(process.env.TIMEOUT || 30000)
let tymlyService, statebox
let tymlyService, statebox, storage

@@ -31,2 +31,3 @@ describe('start up', () => {

statebox = tymlyServices.statebox
storage = tymlyServices.storage
done()

@@ -38,80 +39,99 @@ }

let quickMachine
let slowMachine
let verySlowMachine
function testBatch (label, tests) {
describe(label, () => {
describe('fire off state machines', () => {
for (const test of tests) {
it(test.title, async () => {
const execDescription = await statebox.startExecution(
{
person: test.person
},
test.stateMachine,
{
userId: test.userId
}
)
describe('fire off state machines', () => {
it('long wait, upsert and fetch', async () => {
const execDescription = await statebox.startExecution(
{
person: {
'employeeNo': '1002',
'firstName': 'Raymond',
'lastName': 'Chandler'
}
},
LONG_WAIT_AND_UPSERT_STATE_MACHINE,
{ }
)
expect(execDescription.status).to.eql('RUNNING')
expect(execDescription.status).to.eql('RUNNING')
test.execName = execDescription.executionName
})
}
})
verySlowMachine = execDescription.executionName
})
describe('wait for state machines to finish', () => {
tests.reverse()
for (const test of tests) {
it(test.title, async () => {
const executionDescription = await statebox.waitUntilStoppedRunning(test.execName)
it('wait, upsert and fetch', async () => {
const execDescription = await statebox.startExecution(
{
person: {
'employeeNo': '1001',
'firstName': 'Dashiell',
'lastName': 'Hammett'
}
},
WAIT_AND_UPSERT_STATE_MACHINE,
{ }
)
expect(executionDescription.status).to.eql('SUCCEEDED')
expect(executionDescription.ctx.upsertedPerson._createdBy).to.eql(test.userId)
})
}
})
expect(execDescription.status).to.eql('RUNNING')
describe('check execution table', () => {
for (const test of tests) {
it(test.title, async () => {
const execution = await storage.models.tymly_execution.findOne({where: {executionName: {equals: test.execName}}})
slowMachine = execDescription.executionName
expect(execution._createdBy).to.eql(test.userId)
expect(execution._modifiedBy).to.eql(test.userId)
})
}
})
})
} // testBatch
it('upsert and fetch', async () => {
const execDescription = await statebox.startExecution(
{
person: {
'employeeNo': '1000',
'firstName': 'Jim',
'lastName': 'Thompson'
}
const combination = [
{
title: 'long wait, upsert and fetch',
person: {
'employeeNo': '1002',
'firstName': 'Raymond',
'lastName': 'Chandler'
},
stateMachine: LONG_WAIT_AND_UPSERT_STATE_MACHINE,
userId: 'SuperSlow'
},
{
title: 'wait, upsert and fetch',
person: {
'employeeNo': '1001',
'firstName': 'Dashiell',
'lastName': 'Hammett'
},
stateMachine: WAIT_AND_UPSERT_STATE_MACHINE,
userId: 'Slow'
},
{
title: 'upsert and fetch',
person: {
'employeeNo': '1000',
'firstName': 'Jim',
'lastName': 'Thompson'
},
stateMachine: UPSERT_STATE_MACHINE,
userId: 'Speedy'
}
]
const speedyspeedy = [ ]
for (let i = 0; i !== 500; ++i) {
speedyspeedy.push(
{
title: `${i} upsert and fetch`,
person: {
'employeeNo': `${2000 + i}`
},
UPSERT_STATE_MACHINE,
{ }
)
stateMachine: UPSERT_STATE_MACHINE,
userId: `Speedy-${i}`
}
)
}
expect(execDescription.status).to.eql('RUNNING')
testBatch('Different speeds', combination)
testBatch('All quick', speedyspeedy)
quickMachine = execDescription.executionName
})
})
describe('wait for state machines to finish', () => {
it('upsert and fetch', async () => {
const executionDescription = await statebox.waitUntilStoppedRunning(quickMachine)
expect(executionDescription.status).to.eql('SUCCEEDED')
})
it('wait, upsert and fetch', async () => {
const executionDescription = await statebox.waitUntilStoppedRunning(slowMachine)
expect(executionDescription.status).to.eql('SUCCEEDED')
})
it('long wait, upsert and fetch', async () => {
const executionDescription = await statebox.waitUntilStoppedRunning(verySlowMachine)
expect(executionDescription.status).to.eql('SUCCEEDED')
})
})
describe('shutdown', () => {

@@ -118,0 +138,0 @@ it('shutdown Tymly', async () => {

Sorry, the diff of this file is not supported yet