Crypto Data Store is a module to write Objects Javascript in a file with encryption or not.
At the moment this is a experimental module
import DataStore from 'crypto-data-store';
import type { IDataStore, Schema } from 'crypto-data-store';
interface SchemaTable {
url?: string;
token?: string;
}
const schema: Schema<SchemaTable> = {
url: '',
token: '',
};
const dataStore = new DataStore<SchemaTable>({
schema,
fileName: 'db.tmp',
});
dataStore.write({
url: 'https://leydev.com.br',
token: 'beare some-token-for-authentication-here',
});
const fileName = dataStore.getFileName();
const token = dataStore.read('token');
const secret = dataStore.getSecret();
// eslint-disable-next-line no-console
console.log('Nome do arquivo', fileName);
// eslint-disable-next-line no-console
console.log('token de acesso', token);
// eslint-disable-next-line no-console
console.log('Secret key used', secret);
const DataStore = require('crypto-data-store').default;
const schema = {
url: '',
token: '',
};
const dataStore = new DataStore({
schema,
fileName: 'db.tmp',
});
dataStore.write({
url: 'https://leydev.com.br',
token: 'beare some-token-for-authentication-here',
});
const fileName = dataStore.getFileName();
const token = dataStore.read('token');
const secret = dataStore.getSecret();
// eslint-disable-next-line no-console
console.log('Nome do arquivo', fileName);
// eslint-disable-next-line no-console
console.log('token de acesso', token);
// eslint-disable-next-line no-console
console.log('Secret key used', secret);
import DataStore from 'crypto-data-store';
import type { IDataStore, Schema } from 'crypto-data-store';
interface SchemaTable {
url?: string;
token?: string;
}
const schema: Schema<SchemaTable> = {
url: '',
token: '',
};
const dataStore = new DataStore<SchemaTable>({
schema,
fileName: 'db.tmp',
// The key used to encrypt file must be the same to decrypt
secret: 'unZe59gwkY02ahHwUyiFusBnFnwhSIExdLgZhA47A14=:y7rMUbRs1NbX88pqlr6UtA==',
});
const data = dataStore.read('url');
// eslint-disable-next-line no-console
console.log('URL:', data); // output: 'https://leydev.com.br'
const dataStore = new DataStore<SchemaTable>({
schema,
fileName: 'db.tmp',
// To disable encryption on write file
encrypt: false,
});
const dataStore = new DataStore<SchemaTable>({
schema,
fileName: 'db.tmp',
// Change algorithm
algorithm: 'aes-256-cbc' // 'aes-256-cbc' is default
});
import DataStore from 'crypto-data-store';
import type { IDataStore, Schema } from 'crypto-data-store';
interface SchemaTable {
url?: string;
token?: string;
}
const schema: Schema<SchemaTable> = {
url: '',
token: '',
};
const dataStore = new DataStore<SchemaTable>({
schema,
fileName: 'db.tmp',
});
try {
const data = dataStore.read('token');
} catch(error) {
console.error(error) // Instance of DataStoreException
}
.read(key: string)
can show properties of schema without pass generic type.overwrite: true
when instancing class DataStore. Generated using TypeDoc