/
index.ts
149 lines (141 loc) · 3.43 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { Injectable } from '@angular/core';
import { CordovaCheck, CordovaInstance, IonicNativePlugin, Plugin, getPromise } from '@ionic-native/core';
/**
* @hidden
*/
export class SecureStorageObject {
constructor(private _objectInstance: any) {}
/**
* Gets a stored item
* @param key {string}
* @returns {Promise<string>}
*/
@CordovaInstance({
callbackOrder: 'reverse'
})
get(key: string): Promise<string> {
return;
}
/**
* Stores a value
* @param key {string}
* @param value {string}
* @returns {Promise<any>}
*/
@CordovaInstance({
callbackOrder: 'reverse'
})
set(key: string, value: string): Promise<any> {
return;
}
/**
* Removes a single stored item
* @param key {string}
* @returns {Promise<string>} returns a promise that resolves with the key that was removed
*/
@CordovaInstance({
callbackOrder: 'reverse'
})
remove(key: string): Promise<string> {
return;
}
/**
* Get all references from the storage.
* @returns {Promise<string[]>} returns a promise that resolves with array of keys storage
*/
@CordovaInstance({
callbackOrder: 'reverse'
})
keys(): Promise<string[]> {
return;
}
/**
* Clear all references from the storage.
* @returns {Promise<any>}
*/
@CordovaInstance({
callbackOrder: 'reverse'
})
clear(): Promise<any> {
return;
}
/**
* Brings up the screen-lock settings
* @returns {Promise<any>}
*/
@CordovaInstance()
secureDevice(): Promise<any> {
return;
}
}
/**
* @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).
*
* The browser platform is supported as a mock only. Key/values are stored unencrypted in localStorage.
*
* @usage
*
* ```typescript
* import { SecureStorage, SecureStorageObject } from '@ionic-native/secure-storage/ngx';
*
* constructor(private secureStorage: SecureStorage) { }
*
* ...
*
* this.secureStorage.create('my_store_name')
* .then((storage: SecureStorageObject) => {
*
* storage.get('key')
* .then(
* data => console.log(data),
* error => console.log(error)
* );
*
* storage.set('key', 'value')
* .then(
* data => console.log(data),
* error => console.log(error)
* );
*
* storage.remove('key')
* .then(
* data => console.log(data),
* error => console.log(error)
* );
*
* });
*
*
* ```
* @classes
* SecureStorageObject
*/
@Plugin({
pluginName: 'SecureStorage',
plugin: 'cordova-plugin-secure-storage-echo',
pluginRef: 'cordova.plugins.SecureStorage',
repo: 'https://github.com/mibrito707/cordova-plugin-secure-storage-echo',
platforms: ['Android', 'Browser', 'iOS', 'Windows']
})
@Injectable()
export class SecureStorage extends IonicNativePlugin {
/**
* Creates a namespaced storage.
* @param store {string}
* @returns {Promise<SecureStorageObject>}
*/
@CordovaCheck()
create(store: string): Promise<SecureStorageObject> {
return getPromise<SecureStorageObject>((res: Function, rej: Function) => {
const instance = new (SecureStorage.getPlugin())(
() => res(new SecureStorageObject(instance)),
rej,
store
);
});
}
}