-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Secure Storage #347
Merged
Merged
Add Secure Storage #347
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { CordovaInstance, Plugin } from './plugin'; | ||
|
||
declare var cordova: any; | ||
|
||
/** | ||
* @name Secure Storage | ||
* @description | ||
* This plugin gets, sets and removes key,value pairs from a device's secure storage. | ||
* | ||
* Requires Cordova plugin: `cordova-plugin-secure-storage`. For more info, please see the [Cordova Secure Storage docs](https://github.com/Crypho/cordova-plugin-secure-storage). | ||
* | ||
* @usage | ||
* | ||
* ```typescript | ||
* import { SecureStorage } from 'ionic-native'; | ||
* | ||
* let secureStorage: SecureStorage = new SecureStorage(); | ||
* secureStorage.create('my_store_name') | ||
* .then( | ||
* () => console.log('Success'), | ||
* error => console.log(error); | ||
* ); | ||
* | ||
* secureStorage.get('myitem') | ||
* .then( | ||
* data => console.log(data), | ||
* error => console.log(error) | ||
* ); | ||
* | ||
* secureStorage.set('myitem', 'myvalue') | ||
* .then( | ||
* data => console.log(data), | ||
* error => console.log(error) | ||
* ); | ||
* | ||
* secureStorage.remove('myitem') | ||
* .then( | ||
* data => console.log(data), | ||
* error => console.log(error) | ||
* ); | ||
* ``` | ||
*/ | ||
@Plugin({ | ||
plugin: 'cordova-plugin-secure-storage', | ||
pluginRef: 'plugins.securestorage', | ||
repo: 'https://github.com/Crypho/cordova-plugin-secure-storage', | ||
platforms: ['Android', 'iOS', 'Windows Phone', 'Browser'] | ||
}) | ||
export class SecureStorage { | ||
|
||
private _objectInstance: any; | ||
|
||
constructor() {} | ||
|
||
/** | ||
* Creates a namespaced storage. | ||
* @param store {string} | ||
*/ | ||
create(store: string): Promise<any> { | ||
return new Promise((res, rej) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What types of this parameters are? Shouldn't be declare as eg. |
||
this._objectInstance = new cordova.plugins.SecureStorage(res, rej, store); | ||
}); | ||
} | ||
|
||
/** | ||
* Gets a stored item | ||
* @param reference {string} | ||
*/ | ||
@CordovaInstance({ | ||
callbackOrder: 'reverse' | ||
}) | ||
get(reference: string): Promise<any> { return; } | ||
|
||
/** | ||
* Stores a value | ||
* @param reference {string} | ||
* @param value {string} | ||
*/ | ||
@CordovaInstance({ | ||
callbackOrder: 'reverse' | ||
}) | ||
set(reference: string, value: string): Promise<any> { return; } | ||
|
||
/** | ||
* Removes a single stored item | ||
* @param reference {string} | ||
*/ | ||
@CordovaInstance({ | ||
callbackOrder: 'reverse' | ||
}) | ||
remove(reference: string): Promise<any> { return; } | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to write
_
prefix because typescript knows that this is a private member. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcinwadon This is how I designed the
CordovaInstance
decorator to work. To change this we would have to modify the other plugins. We can keep this for now and maybe modify all the plugins later.