@egintegrations/auth-services 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ import * as SecureStore from 'expo-secure-store';
2
+
3
+ export interface SecureKeyStoreConfig {
4
+ keyPrefix?: string;
5
+ }
6
+
7
+ export class SecureKeyStore {
8
+ private keyPrefix: string;
9
+
10
+ constructor(config: SecureKeyStoreConfig = {}) {
11
+ this.keyPrefix = config.keyPrefix || 'secure_key_';
12
+ }
13
+
14
+ private getFullKey(key: string): string {
15
+ return `${this.keyPrefix}${key}`;
16
+ }
17
+
18
+ async get(key: string): Promise<string | null> {
19
+ return await SecureStore.getItemAsync(this.getFullKey(key));
20
+ }
21
+
22
+ async set(key: string, value: string): Promise<void> {
23
+ await SecureStore.setItemAsync(this.getFullKey(key), value);
24
+ }
25
+
26
+ async delete(key: string): Promise<void> {
27
+ await SecureStore.deleteItemAsync(this.getFullKey(key));
28
+ }
29
+
30
+ async has(key: string): Promise<boolean> {
31
+ const value = await this.get(key);
32
+ return !!value;
33
+ }
34
+
35
+ async clear(keys?: string[]): Promise<void> {
36
+ if (keys) {
37
+ await Promise.all(keys.map((key) => this.delete(key)));
38
+ }
39
+ }
40
+ }
41
+
42
+ // Convenience functions for simple use cases
43
+ export async function getSecureKey(key: string): Promise<string | null> {
44
+ return await SecureStore.getItemAsync(key);
45
+ }
46
+
47
+ export async function setSecureKey(key: string, value: string): Promise<void> {
48
+ await SecureStore.setItemAsync(key, value);
49
+ }
50
+
51
+ export async function deleteSecureKey(key: string): Promise<void> {
52
+ await SecureStore.deleteItemAsync(key);
53
+ }
54
+
55
+ export async function hasSecureKey(key: string): Promise<boolean> {
56
+ const value = await getSecureKey(key);
57
+ return !!value;
58
+ }
@@ -0,0 +1,61 @@
1
+ import * as SecureStore from 'expo-secure-store';
2
+
3
+ export interface TokenManagerConfig {
4
+ storageKey?: string;
5
+ }
6
+
7
+ export class TokenManager {
8
+ private storageKey: string;
9
+
10
+ constructor(config: TokenManagerConfig = {}) {
11
+ this.storageKey = config.storageKey || 'auth_token';
12
+ }
13
+
14
+ async getToken(): Promise<string | null> {
15
+ return await SecureStore.getItemAsync(this.storageKey);
16
+ }
17
+
18
+ async saveToken(token: string): Promise<void> {
19
+ await SecureStore.setItemAsync(this.storageKey, token);
20
+ }
21
+
22
+ async clearToken(): Promise<void> {
23
+ await SecureStore.deleteItemAsync(this.storageKey);
24
+ }
25
+
26
+ async hasToken(): Promise<boolean> {
27
+ const token = await this.getToken();
28
+ return !!token;
29
+ }
30
+ }
31
+
32
+ // Convenience class for single token use case
33
+ export class SingletonTokenManager {
34
+ private static instance: TokenManager | null = null;
35
+ private static defaultKey = 'auth_token';
36
+
37
+ private constructor() {}
38
+
39
+ static getInstance(storageKey?: string): TokenManager {
40
+ if (!this.instance) {
41
+ this.instance = new TokenManager({ storageKey: storageKey || this.defaultKey });
42
+ }
43
+ return this.instance;
44
+ }
45
+
46
+ static async getToken(): Promise<string | null> {
47
+ return this.getInstance().getToken();
48
+ }
49
+
50
+ static async saveToken(token: string): Promise<void> {
51
+ return this.getInstance().saveToken(token);
52
+ }
53
+
54
+ static async clearToken(): Promise<void> {
55
+ return this.getInstance().clearToken();
56
+ }
57
+
58
+ static async hasToken(): Promise<boolean> {
59
+ return this.getInstance().hasToken();
60
+ }
61
+ }
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ export {
2
+ TokenManager,
3
+ SingletonTokenManager,
4
+ TokenManagerConfig,
5
+ } from './TokenManager';
6
+
7
+ export {
8
+ BiometricAuth,
9
+ BiometricAuthConfig,
10
+ BiometricType,
11
+ } from './BiometricAuth';
12
+
13
+ export {
14
+ SecureKeyStore,
15
+ SecureKeyStoreConfig,
16
+ getSecureKey,
17
+ setSecureKey,
18
+ deleteSecureKey,
19
+ hasSecureKey,
20
+ } from './SecureKeyStore';