@autofleet/zehut
v4.14.0
Published
manage user's identity
Maintainers
Keywords
Readme
AutoFleet Zehut
This package handles authorization and authentication for AutoFleet services.
Links
See authorization docs here.
V4 migration
Outbreak v2
When upgrading from V3 to V4, the tracing system has been de-duped to use outbreak v2.
Historically, zehut and outbreak both added a layer of async_hooks, which each had a context that could store data.
The 2 had a nearly identical API, but did not communicate with each other, nor did they share data.
This version removes the trace added by zehut and only uses the outbreak one. This means that the context of the trace is now spread onto the headers of any outgoing HTTP request.
In order to allow keeping data in the context, without having outbreak add it to the headers, a new context has been added to the outbreak traces - nonHeaderContext.
Using the getUser function will keep working regularly, but reading anything else from the context will work only if you read from the correct context.
- const { context } = zehut.getCurrentPayload();
- const user = context?.get('userObject');
+ const user = zehut.getUser();If you need to read any other data from the context, you should now read and write to nonHeaderContext, unless you wish for the values to be sent through to the headers of any outgoing request/response.
const currentTrace = zehut.getCurrentPayload();
-const dataFromContext = currentTrace?.context?.get('DATA_FROM_CONTEXT');
+const dataFromContext = currentTrace?.nonHeaderContext?.get('DATA_FROM_CONTEXT');Logger
The tracing mechanism has been updated to reduce boilerplate code.
Now, when calling the enableTracing function, you can now pass in the instance of the logger, and drop the call for logger.addContextMiddleware.
-zehut.enableTracing();
-
-logger.addContextMiddleware(() => ({
- traceId: zehut.outbreak.getCurrentContext()?.context?.get('x-trace-id'),
-}));
+zehut.enableTracing({ logger });