Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vault-storage

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vault-storage - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

18

build.js

@@ -31,14 +31,2 @@ // Importing required modules

// Function to clean a directory
function cleanDir(dir) {
// Get the absolute path of the directory
const dirPath = path.join(__dirname, dir);
// If the directory exists, remove it
if (fs.existsSync(dirPath)) {
fs.rmSync(dirPath, { recursive: true, force: true });
}
// Ensure the directory exists
ensureDir(dirPath);
}
// Function to ensure a directory exists

@@ -63,6 +51,2 @@ function ensureDir(dirPath) {

// Clean the 'dist' and 'typings' directories
cleanDir('./dist');
cleanDir('./typings');
// Prepare build options for each TypeScript file

@@ -78,3 +62,3 @@ const buildOptions = entryPoints.map(entryPoint => {

format: 'esm',
sourcemap: true,
sourcemap: debug,
outfile: `dist/${fileName}.js`,

@@ -81,0 +65,0 @@ };

3

dist/index.js

@@ -1,2 +0,1 @@

var l={get(n,e){return typeof n[e]=="function"?n[e].bind(n):e in n?n[e]:n.getItem(e)},set(n,e,t){return n.setItem(e,t)},deleteProperty(n,e){return n.removeItem(e)}},u=l;var i="readonly",a="readwrite",d="store",o=class{dbName="vault";db=null;constructor(e,t=!1){if(this.dbName=e||this.dbName,!t)return new Proxy(this,u)}async setItem(e,t){return this.do(a,r=>r.put({key:e,value:t}))}async getItem(e){return this.do(i,t=>t.get(e)).then(t=>t?.value??null)}async removeItem(e){return this.do(a,t=>t.delete(e))}async clear(){return this.do(a,e=>e.clear())}async keys(){return this.do(i,e=>e.getAllKeys())}async length(){return this.do(i,e=>e.count())}async init(){return new Promise((e,t)=>{let r=indexedDB.open(this.dbName,1);r.onupgradeneeded=s=>{s.target.result.createObjectStore(d,{keyPath:"key"})},r.onsuccess=()=>{this.db=r.result,e()},r.onerror=s=>t(s)})}async do(e,t){this.db||await this.init();let r=this.db.transaction(d,e),s=t(r.objectStore(d));return new Promise((c,y)=>{s.onsuccess=()=>c(e===i?s.result:void 0),s.onerror=()=>y(s.error)})}};var m=new o,f=m;export{f as default};
//# sourceMappingURL=index.js.map
var l={get(r,e){return typeof r[e]=="function"?r[e].bind(r):e in r?r[e]:r.getItem(e)},set(r,e,t){return r.setItem(e,t)},deleteProperty(r,e){return r.removeItem(e)}},c=l;var i="readonly",a="readwrite",d="store",o=class{dbName="vault";db=null;constructor(e,t=!1){if(this.dbName=e||this.dbName,!t)return new Proxy(this,c)}async setItem(e,t){return this.do(a,n=>n.put({key:e,value:t}))}async getItem(e){return this.do(i,t=>t.get(e)).then(t=>t?.value??null)}async removeItem(e){return this.do(a,t=>t.delete(e))}async clear(){return this.do(a,e=>e.clear())}async keys(){return this.do(i,e=>e.getAllKeys())}async length(){return this.do(i,e=>e.count())}async init(){return new Promise((e,t)=>{let n=indexedDB.open(this.dbName,1);n.onupgradeneeded=s=>{s.target.result.createObjectStore(d,{keyPath:"key"})},n.onsuccess=()=>{this.db=n.result,e()},n.onerror=s=>t(s)})}async do(e,t){this.db||await this.init();let n=this.db.transaction(d,e),s=t(n.objectStore(d));return new Promise((u,y)=>{s.onsuccess=()=>u(e===i?s.result:void 0),s.onerror=()=>y(s.error)})}};var m=new o,g=m;export{g as default};
{
"name": "vault-storage",
"description": "Vault, a micro yet robust browser storage library",
"version": "1.1.0",
"version": "1.1.1",
"author": "ManiarTech®️ - Mohamed Aamir Maniar",

@@ -36,7 +36,17 @@ "license": "MIT",

"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "types/index.d.ts",
"exports": {
".": "./dist/index.js",
"./vault": "./dist/vault.js",
"./secured-vault": "./dist/secured-vault.js",
"./types": "./types/index.d.ts",
"./types/vault": "./types/vault.d.ts",
"./types/secured-vault": "./types/secured-vault.d.ts"
},
"scripts": {
"test": "karma start karma.conf.js",
"clean": "rimraf dist types",
"build:types": "tsc",
"build": "node ./build.js && npm run build:types",
"build:vault": "node ./build.js && npm run build:types",
"build": "npm run clean && npm run build:vault && npm run build:types",
"watch": "node ./build.js --watch --debug"

@@ -56,2 +66,3 @@ },

"karma-typescript": "^5.5.4",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",

@@ -58,0 +69,0 @@ "typescript": "^5.3.3"

@@ -14,3 +14,3 @@ # vault

- Less than a KB (minified and gzipped), unsecured vault
- Aroound 1.5 KB (minified and gzipped), secured vault
- Around a KB (minified and gzipped), secured vault
- **Multiple Stores Support**: Supports multiple stores with single api.

@@ -17,0 +17,0 @@ - **Encrypted Vault**: Provides a secure storage for sensitive data.

import Vault from './vault';
/**
* The default vault instance.
* The default vault storage instance that provides a convenient way to use the
* Vault without having to instantiate it manually. This instance is created
* by default when the module is imported.
*
* @type {Vault}
*/

@@ -6,0 +10,0 @@ const vault = new Vault();

import proxyHandler from "./proxy-handler"
import Vault from "./vault"
import Vault from "./vault"
type EncKeySalt = { password: string, salt: string }
type FuncEncKeySalt = (key: string) => Promise<EncKeySalt>
type EncConfig = EncKeySalt | FuncEncKeySalt | null
/**
* Credential type containing the password and salt used for encryption and
* decryption of SecureVault data.
*
* @typedef {Object} EncCredential
* @property {string} password - The encrypted password
* @property {string} salt - The salt used for encryption
*/
type EncCredential = { password: string, salt: string }
/**
* Function that returns a Promise which resolves to Credentials used for
* encryption and decryption of SecureVault data.
*
* @typedef {function} FuncEncCredential
* @param {string} key - The key used for encryption
* @returns {Promise<EncCredential>} A Promise that resolves to an Encrypted Credential
*/
type FuncEncCredential = (key: string) => Promise<EncCredential>
/**
* Configuration used for encryption and decryption of SecureVault data. If may
* be a static object that contains the password and salt, or a function that
* returns a Promise which resolves to credentials used for encryption.
*
* @typedef {Object} EncConfig
* @property {EncCredential | FuncEncCredential | null} - The encrypted configuration can be an Encrypted Credential, a function that returns a Promise which resolves to an Encrypted Credential, or null
*/
type EncConfig = EncCredential | FuncEncCredential | null
class SecuredVault extends Vault {

@@ -9,0 +35,0 @@ encConfig:EncConfig

@@ -14,12 +14,23 @@ import proxyHandler from "./proxy-handler";

* - You can store large amounts of data, not just 5MB.
* @property {string} dbName - The name of the database.
* @property {IDBDatabase|null} db - The database instance.
*/
export default class Vault {
dbName = 'vault';
db: IDBDatabase | null = null;
protected dbName = 'vault';
protected db: IDBDatabase | null = null;
// Fake custom properties support. Custom properties are stored in the
// indexdb as key/value pairs. This is a workaround to allow custom
// properties to be set and retrieved as if they were native properties.
/**
* Fake custom properties support. Custom properties are stored in the
* indexdb as key/value pairs. This is a workaround to allow custom
* properties to be set and retrieved as if they were native properties.
* @property {any} key - The key of the custom property.
*/
[key: string]: any;
/**
* The constructor for the Vault class.
* @param {string} [dbName] - The name of the database.
* @param {boolean} [isParent=false] - A flag to indicate if this instance is a parent.
*/
constructor(dbName?: string, isParent: boolean = false) {

@@ -31,10 +42,44 @@ this.dbName = dbName || this.dbName;

/**
* Set an item in the database.
* @param {string} key - The key of the item.
* @param {any} value - The value of the item.
* @returns {Promise<void>}
*/
async setItem(key: string, value: any): Promise<void> { return this.do(rw, (s:any) => s.put({ key, value })) }
/**
* Get an item from the database.
* @param {string} key - The key of the item.
* @returns {Promise<any>} - The value of the item.
*/
async getItem(key: string): Promise<any> { return this.do(r, (s: any) => s.get(key)).then((r:any) => r?.value ?? null) }
/**
* Remove an item from the database.
* @param {string} key - The key of the item.
* @returns {Promise<void>}
*/
async removeItem(key: string):Promise<void> { return this.do(rw, (s:any) => s.delete(key)) }
/**
* Clear the database.
* @returns {Promise<void>}
*/
async clear(): Promise<void> { return this.do(rw, (s:any) => s.clear()) }
/**
* Get all keys in the database.
* @returns {Promise<string[]>} - An array of keys.
*/
async keys(): Promise<string[]> { return this.do(r, (s:any) => s.getAllKeys()) }
/**
* Get the number of items in the database.
* @returns {Promise<number>} - The number of items.
*/
async length(): Promise<number> { return this.do(r, (s:any) => s.count()) }
async init(): Promise<void> {
// Initialize the database and return a promise.
protected async init(): Promise<void> {
return new Promise((resolve, reject) => {

@@ -50,3 +95,5 @@ const request = indexedDB.open(this.dbName, 1)

async do(operationType: IDBTransactionMode, operation: (store: IDBObjectStore) => IDBRequest): Promise<any> {
// Execute a transaction and return a promise.
protected async do(operationType: IDBTransactionMode, operation: (store: IDBObjectStore) => IDBRequest): Promise<any> {
if (!this.db) await this.init()

@@ -61,3 +108,2 @@ const transaction = this.db!.transaction(s, operationType);

}
}
}
{
"compilerOptions": {
/* Projects */
"incremental": true,
/* Language and Environment */
"target": "ESNext",
"lib": ["ESNext", "DOM"],
/* Modules */

@@ -16,3 +14,3 @@ "module": "ESNext",

"emitDeclarationOnly": true,
"outDir": "./dist",
"outDir": "./types",
"removeComments": false,

@@ -25,5 +23,7 @@ "esModuleInterop": true,

},
"include": [
"src/**/*.ts"
],
"exclude": [

@@ -30,0 +30,0 @@ "node_modules", // Exclude the node_modules directory

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