Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@janiscommerce/api-session
Advanced tools
Changelog
[3.4.0] - 2023-03-20
currency
and currencyDisplay
Readme
A session manager for APIs
npm install @janiscommerce/api-session
The package exports two classes ApiSession and ApiSessionError.
constructor(authorizationData, client)
Creates an APISession with the authorizationData
provided or the client
for direct injection.
authorizationData
is an optional object with the following (also optional) properties: { userId, clientId, clientCode, profileId, permissions, hasAccessToAllLocations, locations, warehousesIds }client
is an optional object for client injection without performing any DB getsvalidateLocation(locationId)
Validate if the location given is valid for the session. It validates against the locations
and the hasAccessToAllLocations
boolean.
Returns Boolean.
validateWarehouse(warehouseId)
. Since 3.3.0Validate if the warehouse given is valid for the session. It validates against the warehousesIds
and the hasAccessToAllLocations
boolean.
Returns Boolean.
ApiSession has the following getters:
code
, symbol
. Default: symbol
. Since 3.4.0getInstance()
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.The package uses the Client Model in our service for getting the clients. For more information see @janiscommerce/model
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, 'some-param', 'some-other-param');
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'
FAQs
A session manager for APIs
The npm package @janiscommerce/api-session receives a total of 494 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.