Skip to content

Instantly share code, notes, and snippets.

@TheNoim
Created July 22, 2017 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheNoim/9b32a8fdcec9e986e664d6b02f4315af to your computer and use it in GitHub Desktop.
Save TheNoim/9b32a8fdcec9e986e664d6b02f4315af to your computer and use it in GitHub Desktop.
Secure Storage Promise Wrapper
export default class SecureStorage {
/**
*
* @param {string} app
* @returns {SecureStorage}
*/
constructor(app) {
const self = this;
this.ready = new Promise((resolve, reject) => {
self.ss = new cordova.plugins.SecureStorage(() => {
resolve(self);
}, reject, app);
});
this.set = this.set.bind(this);
this.get = this.get.bind(this);
this.remove = this.remove.bind(this);
this.keys = this.keys.bind(this);
this.clear = this.clear.bind(this);
return this;
}
/**
*
* @param {string} key
* @param {string} value
* @returns {Promise.<string>}
*/
set(key, value) {
const self = this;
return new Promise((resolve, reject) => {
self.ss.set(resolve, reject, key, value);
});
}
/**
*
* @param {string} key
* @returns {Promise.<any>}
*/
get(key) {
const self = this;
return new Promise((resolve, reject) => {
self.ss.get(resolve, reject, key);
});
}
/**
*
* @param {string} key
* @returns {Promise.<any>}
*/
remove(key) {
const self = this;
return new Promise((resolve, reject) => {
self.ss.remove(resolve, reject, key);
});
}
/**
*
* @returns {Promise.<Array[any]>}
*/
keys() {
const self = this;
return new Promise((resolve, reject) => {
self.ss.keys(resolve, reject);
});
}
/**
*
* @returns {Promise}
*/
clear() {
const self = this;
return new Promise((resolve, reject) => {
self.ss.clear(resolve, reject);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment