🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

session-context

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

session-context - npm Package Compare versions

Comparing version

to
0.0.5

1

dist/cjs/index.d.ts

@@ -5,1 +5,2 @@ import { AsyncLocalStorage } from 'node:async_hooks';

export declare const runSession: <R, TArgs extends unknown[]>(callback: (...args: TArgs) => R, ...args: TArgs) => R;
export declare const setProcessEnv: (env: unknown) => void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runSession = exports.getSessionContext = exports.createSessionContext = void 0;
exports.setProcessEnv = exports.runSession = exports.getSessionContext = exports.createSessionContext = void 0;
const node_async_hooks_1 = require("node:async_hooks");

@@ -16,5 +16,8 @@ const global = globalThis;

if (!store) {
throw new Error('Global store is not initialized');
throw new Error('Session context is not initialized');
}
return store;
if (!store.appContext) {
store.appContext = {};
}
return store.appContext;
};

@@ -27,2 +30,17 @@ exports.getSessionContext = getSessionContext;

exports.runSession = runSession;
const setProcessEnv = (env) => {
const store = global.__context.getStore();
if (!store) {
throw new Error('Session context is not initialized');
}
store.env = env;
if (!Object.getOwnPropertyDescriptor(process, 'env')?.get) {
Object.defineProperty(process, 'env', {
get() {
return store.env;
},
});
}
};
exports.setProcessEnv = setProcessEnv;
//# sourceMappingURL=index.js.map

@@ -5,1 +5,2 @@ import { AsyncLocalStorage } from 'node:async_hooks';

export declare const runSession: <R, TArgs extends unknown[]>(callback: (...args: TArgs) => R, ...args: TArgs) => R;
export declare const setProcessEnv: (env: unknown) => void;

@@ -12,5 +12,8 @@ import { AsyncLocalStorage } from 'node:async_hooks';

if (!store) {
throw new Error('Global store is not initialized');
throw new Error('Session context is not initialized');
}
return store;
if (!store.appContext) {
store.appContext = {};
}
return store.appContext;
};

@@ -21,2 +24,16 @@ export const runSession = (callback, ...args) => {

};
export const setProcessEnv = (env) => {
const store = global.__context.getStore();
if (!store) {
throw new Error('Session context is not initialized');
}
store.env = env;
if (!Object.getOwnPropertyDescriptor(process, 'env')?.get) {
Object.defineProperty(process, 'env', {
get() {
return store.env;
},
});
}
};
//# sourceMappingURL=index.js.map

2

package.json
{
"name": "session-context",
"version": "0.0.4",
"version": "0.0.5",
"main": "./dist/cjs/index.js",

@@ -5,0 +5,0 @@ "types": "./dist/cjs/index.d.ts",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet