herbsjs / buchu

Use Cases - Uniform, auditable and secure use case library
Other
24 stars 22 forks source link

Session ID - A ID to track execution between use cases #57

Open jhomarolo opened 2 years ago

jhomarolo commented 2 years ago

Is your feature request related to a problem? Please describe. To improve the audit trail, the library should have an ID similar to the use case track id, but for a long track, between use cases.

Describe the solution you'd like Implement a new ID called session ID that is created if is not exist (first run) and send through use cases by request. So when the audit trail executes, we should see a new ID there.

VictorTBX commented 2 years ago

How would this be used since the auditTrail info is attached to an use case? From where could we get this data from?

Wouldn't this make more sense for rest and graphql glues?

dalssoft commented 2 years ago

Having a code sample on how to use (not the implementation) the session ID would be a great start.

jhomarolo commented 2 years ago

I imagine some changes that start inside this library, but that can expand to the entire ecosystem, mainly when it comes to passing the session ID, but for now, I imagine something internal to the application cycle itself (when a use case calls another use case).

Since we don't officially have a feature to explicitly use a use case as a step, I imagined creating a new parameter, not mandatory in the use case request. We can also discuss passing this information through context.

when run uc.auditTrail:


{
    type: 'use case',
    description: 'Add or Update an Item on a to-do List',
    sessionId:  '6545fb7f-f5dd-466a-b466-3330d1d48411',
    transactionId: '9985fb70-f56d-466a-b466-e200d1d4848c',
    elapsedTime: 1981800n, // in nanosecods
    user: { name: 'John', id: '923b8b9a', isAdmin: true },
    authorized: true,
    return: {
        Ok: { item: { id: 100, name: 'Do not forget this', position: 9 } }
    },
    steps: [  ]
}

Inside usecase.js, something like that: https://github.com/herbsjs/buchu/blob/0d661f4fdef43f5ae4962eec478b82eba6f29117/src/usecase.js#L38

        // audit trail
        this._auditTrail = this._mainStep._auditTrail
        this._auditTrail.type = this.type
        this._auditTrail.description = description
        this._auditTrail.transactionId = uuidv4()
        this._auditTrail.sessionId = body.sessionId ?? uuidv4()

or like that:



        //sessionId
        if(body.sessionId ){
            this._auditTrail.sessionId = body.sessionId 
            delete body.sessionId 
        } else {
            this._auditTrail.sessionId =  uuidv4()
        }
BritoDoug commented 2 years ago

I wanna take this issue, can you tag for me @jhomarolo ?

dalssoft commented 2 years ago

Having a code sample on how to use (not the implementation) the session ID would be a great start.

@jhomarolo the question was about the way to call it in a UC, not the implementation.

ex (not a suggestion, just what I would like to analyze):

const response = await usecase.run(request, sessionID)

One more thing: in order for a sessionID to be useful, it must be informed in the transport layer (REST, GraphQL, etc), since this information comes from outside the microservice / domain. Will sessionID have a special treatment for these layers?

BritoDoug commented 2 years ago

@dalssoft I think in a two step work, first I'll implement a sessionID between UC, in another implementation, apply this in a transport layer

BritoDoug commented 2 years ago

Sorry guys, I'll retake that!

jhomarolo commented 2 years ago

Hi @BritoDoug any updates here?

BritoDoug commented 2 years ago

Not yet @jhomarolo but I will send updates this week

jhomarolo commented 1 year ago

@BritoDoug do you still in this issue?