
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@janiscommerce/api-session
Advanced tools
A session manager for APIs
npm install @janiscommerce/api-session
The package exports two classes ApiSession and ApiSessionError.
constructor(authorizationData) Receives an object with the following (optional) properties: { userId, clientId, clientCode, profileId, permissions }
validateLocation(locationId) Validate if the location given is valid for the session. Returns Boolean.
ApiSession has the following getters:
getInstance()
method injected. The properties depend on your client internal structure. The client is injected with a getInstance()
method to propagate the session to other instances.:warning::skull: Since version 2.0.0 stores and hasAccessToAllStores getters have been removed . Also the method validateStore(storeId). Now it supports locations with locations and hasAccessToAllLocations getters and also the method validateLocation(locationId) :skull::warning:
The package has some configurable parameters, which are loaded using @janiscommerce/settings
Setting | Description | Default value |
---|---|---|
clients.databaseKey | Indicates the DB key to use to fetch a session's client | 'core' |
clients.table | Indicates the table to use to fetch a session's client | 'clients' |
clients.identifierField | Indicates the field to use as a filter to fetch a session's client | 'code' |
const { ApiSession, ApiSessionError } = require('@janiscommerce/api-session');
const { ApiSession } = require('@janiscommerce/api-session');
const SomeModel = require('../models/some-model');
const session = new ApiSession({
userId: 1,
userIsDev: false,
clientId: 2,
clientCode: 'janis',
profileId: 5,
permissions: [
'catalog:product:read',
'catalog:product:write'
],
locations: ['location-1'],
hasAccessToAllLocations: false
});
console.log(`Session created for user ${session.userId} on client ${session.clientCode}.`);
const sessionInjectedModel = session.getSessionInstance(SomeModel);
console.log(`Session is propagated for user ${sessionInjectedModel.session.userId} on client ${sessionInjectedModel.session.clientCode}.`);
const client = await sessionInjectedModel.session.client;
console.log(client);
// Outputs your client object
const hasAccess = session.validateLocation('location-1');
console.log(`Session has access to location 1: ${hasAccess}`);
// Outputs 'Session has access to location 1: true'
[2.0.0] - 2020-06-11
locations
and hasAccessToAllLocations
gettersvalidateLocation
methodstores
and hasAccessToAllStores
gettersvalidateStore
methodFAQs
A session manager for APIs
The npm package @janiscommerce/api-session receives a total of 360 weekly downloads. As such, @janiscommerce/api-session popularity was classified as not popular.
We found that @janiscommerce/api-session demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.