New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hattip/session

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hattip/session - npm Package Compare versions

Comparing version 0.0.37 to 0.0.38

2

dist/index.d.ts

@@ -143,2 +143,2 @@ import { RequestContext } from '@hattip/compose';

export { Awaitable, EncryptedCookieStore, KvSessionStore, RedisSessionStore, Session, SessionData, SessionOptions, SessionSerializationOptions, SessionStore, SignedCookieStore, SimpleCookieStore, UnsafeMemorySessionStore, session };
export { type Awaitable, EncryptedCookieStore, KvSessionStore, RedisSessionStore, type Session, type SessionData, type SessionOptions, type SessionSerializationOptions, type SessionStore, SignedCookieStore, SimpleCookieStore, UnsafeMemorySessionStore, session };

@@ -1,20 +0,1 @@

var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
// src/index.ts

@@ -24,9 +5,9 @@ import "@hattip/cookie";

// src/crypto.ts
var { Buffer: Buffer2 } = globalThis;
var { Buffer } = globalThis;
function fromBase64(input) {
input = input.replace(/-/g, "+").replace(/_/g, "/");
return typeof atob === "function" ? Uint8Array.from(atob(input), (c) => c.charCodeAt(0)) : Buffer2.from(input, "base64");
return typeof atob === "function" ? Uint8Array.from(atob(input), (c) => c.charCodeAt(0)) : Buffer.from(input, "base64");
}
function toBase64(input) {
return (typeof btoa === "function" ? btoa(String.fromCharCode(...input)) : Buffer2.from(input).toString("base64")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
return (typeof btoa === "function" ? btoa(String.fromCharCode(...input)) : Buffer.from(input).toString("base64")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
}

@@ -206,11 +187,10 @@ async function signatureKeyFromSecret(secret) {

// src/unsafe-memory-store.ts
var _generateId, _store;
var UnsafeMemorySessionStore = class {
#generateId;
#store = /* @__PURE__ */ new Map();
constructor(generateId = () => randomUUID()) {
__privateAdd(this, _generateId, void 0);
__privateAdd(this, _store, /* @__PURE__ */ new Map());
__privateSet(this, _generateId, generateId);
this.#generateId = generateId;
}
async load(id) {
const [data, expires] = __privateGet(this, _store).get(id) ?? [void 0, void 0];
const [data, expires] = this.#store.get(id) ?? [void 0, void 0];
if (expires && expires.getTime() < Date.now()) {

@@ -223,4 +203,4 @@ await this.destroy(id);

async save(id, data, maxAge) {
const newId = id ?? await __privateGet(this, _generateId).call(this);
__privateGet(this, _store).set(newId, [
const newId = id ?? await this.#generateId();
this.#store.set(newId, [
data,

@@ -232,7 +212,5 @@ maxAge ? new Date(Date.now() + maxAge) : void 0

async destroy(id) {
__privateGet(this, _store).delete(id);
this.#store.delete(id);
}
};
_generateId = new WeakMap();
_store = new WeakMap();

@@ -261,8 +239,7 @@ // src/simple-cookie-store.ts

// src/signed-cookie-store.ts
var _keys;
var SignedCookieStore = class extends SimpleCookieStore {
#keys;
constructor(keys, serializationOptions = {}) {
super(serializationOptions);
__privateAdd(this, _keys, void 0);
__privateSet(this, _keys, keys);
this.#keys = keys;
}

@@ -284,18 +261,16 @@ static async generateKeysFromSecrets(secrets) {

async load(id) {
const data = await verify(id, __privateGet(this, _keys));
const data = await verify(id, this.#keys);
return data ? this._parse(data) : null;
}
save(_id, data, maxAge) {
return sign(this._stringify(data), __privateGet(this, _keys)[0], maxAge);
return sign(this._stringify(data), this.#keys[0], maxAge);
}
};
_keys = new WeakMap();
// src/encrypted-cookie-store.ts
var _keys2;
var EncryptedCookieStore = class extends SimpleCookieStore {
#keys;
constructor(keys, serializationOptions = {}) {
super(serializationOptions);
__privateAdd(this, _keys2, void 0);
__privateSet(this, _keys2, keys);
this.#keys = keys;
}

@@ -313,20 +288,18 @@ static async generateKeysFromBase64(base64) {

async load(id) {
const data = await decrypt(id, __privateGet(this, _keys2));
const data = await decrypt(id, this.#keys);
return data ? this._parse(data) : null;
}
save(_id, data, maxAge) {
return encrypt(this._stringify(data), __privateGet(this, _keys2)[0], maxAge);
return encrypt(this._stringify(data), this.#keys[0], maxAge);
}
};
_keys2 = new WeakMap();
// src/redis-store.ts
var _getClient, _generateId2, _validateId, _stringify, _parse;
var RedisSessionStore = class {
#getClient;
#generateId;
#validateId;
#stringify;
#parse;
constructor(options) {
__privateAdd(this, _getClient, void 0);
__privateAdd(this, _generateId2, void 0);
__privateAdd(this, _validateId, void 0);
__privateAdd(this, _stringify, void 0);
__privateAdd(this, _parse, void 0);
const {

@@ -338,14 +311,14 @@ getClient,

} = options;
__privateSet(this, _getClient, getClient);
__privateSet(this, _generateId2, generateId);
__privateSet(this, _validateId, validateId);
this.#getClient = getClient;
this.#generateId = generateId;
this.#validateId = validateId;
const { stringify = JSON.stringify, parse = JSON.parse } = serializationOptions;
__privateSet(this, _stringify, stringify);
__privateSet(this, _parse, parse);
this.#stringify = stringify;
this.#parse = parse;
}
async load(id, ctx) {
if (!id || !await __privateGet(this, _validateId).call(this, id)) {
if (!id || !await this.#validateId(id)) {
return null;
}
const client = await __privateGet(this, _getClient).call(this, ctx);
const client = await this.#getClient(ctx);
const value = await new Promise((resolve, reject) => {

@@ -360,13 +333,13 @@ client.get(id, (err, reply) => {

});
return value && __privateGet(this, _parse).call(this, value);
return value && this.#parse(value);
}
async save(id, data, maxAge, ctx) {
if (!id || !await __privateGet(this, _validateId).call(this, id)) {
id = await __privateGet(this, _generateId2).call(this);
if (!id || !await this.#validateId(id)) {
id = await this.#generateId();
}
const client = await __privateGet(this, _getClient).call(this, ctx);
const client = await this.#getClient(ctx);
await new Promise((resolve, reject) => {
client.set(
id,
__privateGet(this, _stringify).call(this, data),
this.#stringify(data),
"EX",

@@ -386,3 +359,3 @@ maxAge / 1e3,

async destroy(id, ctx) {
const client = await __privateGet(this, _getClient).call(this, ctx);
const client = await this.#getClient(ctx);
await new Promise((resolve, reject) => {

@@ -399,17 +372,11 @@ client.del(id, (err, reply) => {

};
_getClient = new WeakMap();
_generateId2 = new WeakMap();
_validateId = new WeakMap();
_stringify = new WeakMap();
_parse = new WeakMap();
// src/kv-store.ts
var _getStore, _generateId3, _validateId2, _stringify2, _parse2;
var KvSessionStore = class {
#getStore;
#generateId;
#validateId;
#stringify;
#parse;
constructor(options) {
__privateAdd(this, _getStore, void 0);
__privateAdd(this, _generateId3, void 0);
__privateAdd(this, _validateId2, void 0);
__privateAdd(this, _stringify2, void 0);
__privateAdd(this, _parse2, void 0);
const {

@@ -421,23 +388,23 @@ getStore,

} = options;
__privateSet(this, _getStore, getStore);
__privateSet(this, _generateId3, generateId);
__privateSet(this, _validateId2, validateId);
this.#getStore = getStore;
this.#generateId = generateId;
this.#validateId = validateId;
const { stringify = JSON.stringify, parse = JSON.parse } = serializationOptions;
__privateSet(this, _stringify2, stringify);
__privateSet(this, _parse2, parse);
this.#stringify = stringify;
this.#parse = parse;
}
async load(id, ctx) {
if (!id || !await __privateGet(this, _validateId2).call(this, id)) {
if (!id || !await this.#validateId(id)) {
return null;
}
const store = await __privateGet(this, _getStore).call(this, ctx);
const store = await this.#getStore(ctx);
const value = await store.get(id);
return value && __privateGet(this, _parse2).call(this, value);
return value && this.#parse(value);
}
async save(id, data, maxAge, ctx) {
if (!id || !await __privateGet(this, _validateId2).call(this, id)) {
id = await __privateGet(this, _generateId3).call(this);
if (!id || !await this.#validateId(id)) {
id = await this.#generateId();
}
const store = await __privateGet(this, _getStore).call(this, ctx);
await store.put(id, __privateGet(this, _stringify2).call(this, data), {
const store = await this.#getStore(ctx);
await store.put(id, this.#stringify(data), {
expirationTtl: Math.max(maxAge / 1e3, 60)

@@ -448,11 +415,6 @@ });

async destroy(id, ctx) {
const store = await __privateGet(this, _getStore).call(this, ctx);
const store = await this.#getStore(ctx);
await store.delete(id);
}
};
_getStore = new WeakMap();
_generateId3 = new WeakMap();
_validateId2 = new WeakMap();
_stringify2 = new WeakMap();
_parse2 = new WeakMap();

@@ -475,3 +437,3 @@ // src/index.ts

} = options;
const maxAge = ((cookieOptions == null ? void 0 : cookieOptions.maxAge) ? cookieOptions.maxAge * 1e3 : void 0) ?? ((cookieOptions == null ? void 0 : cookieOptions.expires) ? cookieOptions.expires.getTime() - Date.now() : 5 * 60 * 1e3);
const maxAge = (cookieOptions?.maxAge ? cookieOptions.maxAge * 1e3 : void 0) ?? (cookieOptions?.expires ? cookieOptions.expires.getTime() - Date.now() : 5 * 60 * 1e3);
return async (ctx) => {

@@ -478,0 +440,0 @@ const sessionId = getSessionId(ctx);

{
"name": "@hattip/session",
"version": "0.0.37",
"version": "0.0.38",
"type": "module",

@@ -23,19 +23,19 @@ "description": "Session management for HatTip",

"dependencies": {
"@hattip/compose": "0.0.37",
"@hattip/cookie": "0.0.37",
"@hattip/core": "0.0.37"
"@hattip/compose": "0.0.38",
"@hattip/cookie": "0.0.38",
"@hattip/core": "0.0.38"
},
"devDependencies": {
"@cyco130/eslint-config": "^3.3.2",
"@cyco130/eslint-config": "^3.5.0",
"@miniflare/kv": "^2.14.1",
"@miniflare/storage-memory": "^2.14.1",
"@types/node": "^20.5.7",
"@types/redis-mock": "^0.17.1",
"eslint": "^8.48.0",
"publint": "^0.2.2",
"@types/node": "^20.10.6",
"@types/redis-mock": "^0.17.3",
"eslint": "^8.56.0",
"publint": "^0.2.7",
"redis-mock": "^0.56.3",
"tsup": "^7.2.0",
"typescript": "^5.2.2",
"vitest": "^0.34.3",
"@hattip/polyfills": "0.0.37"
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"vitest": "^1.1.0",
"@hattip/polyfills": "0.0.38"
},

@@ -42,0 +42,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc