react-native-authsignal 0.2.0 → 0.2.2
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.
- package/{LICENSE → LICENSE.md} +3 -2
- package/README.md +1 -21
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/authsignal/react/AuthsignalPasskeyModule.java +14 -2
- package/android/src/main/java/com/authsignal/react/AuthsignalPushModule.java +34 -8
- package/ios/AuthsignalPasskeyModule.swift +34 -7
- package/ios/AuthsignalPushModule.swift +94 -24
- package/lib/commonjs/index.js +24 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/passkey.js +44 -8
- package/lib/commonjs/passkey.js.map +1 -1
- package/lib/commonjs/push.js +84 -6
- package/lib/commonjs/push.js.map +1 -1
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/index.js +9 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/passkey.js +44 -8
- package/lib/module/passkey.js.map +1 -1
- package/lib/module/push.js +84 -6
- package/lib/module/push.js.map +1 -1
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/passkey.d.ts +6 -3
- package/lib/typescript/passkey.d.ts.map +1 -1
- package/lib/typescript/push.d.ts +9 -6
- package/lib/typescript/push.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +20 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/package.json +6 -2
- package/react-native-authsignal.podspec +1 -1
- package/src/index.tsx +8 -2
- package/src/passkey.ts +44 -10
- package/src/push.ts +88 -15
- package/src/types.ts +20 -0
package/src/push.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { NativeModules } from 'react-native';
|
|
2
2
|
import { LINKING_ERROR } from './error';
|
|
3
|
+
import type { AuthsignalResponse } from './types';
|
|
3
4
|
|
|
4
5
|
interface ConstructorArgs {
|
|
5
6
|
tenantID: string;
|
|
6
7
|
baseURL: string;
|
|
8
|
+
enableLogging: boolean;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
interface PushCredential {
|
|
@@ -28,48 +30,119 @@ const AuthsignalPushModule = NativeModules.AuthsignalPushModule
|
|
|
28
30
|
export class AuthsignalPush {
|
|
29
31
|
tenantID: string;
|
|
30
32
|
baseURL: string;
|
|
33
|
+
enableLogging: boolean;
|
|
31
34
|
|
|
32
|
-
constructor({ tenantID, baseURL }: ConstructorArgs) {
|
|
35
|
+
constructor({ tenantID, baseURL, enableLogging }: ConstructorArgs) {
|
|
33
36
|
this.tenantID = tenantID;
|
|
34
37
|
this.baseURL = baseURL;
|
|
38
|
+
this.enableLogging = enableLogging;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
async getCredential(): Promise<PushCredential
|
|
41
|
+
async getCredential(): Promise<AuthsignalResponse<PushCredential>> {
|
|
38
42
|
await this.ensureModuleIsInitialized();
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
try {
|
|
45
|
+
const data = await AuthsignalPushModule.getCredential();
|
|
46
|
+
|
|
47
|
+
return { data };
|
|
48
|
+
} catch (ex) {
|
|
49
|
+
if (this.enableLogging) {
|
|
50
|
+
console.log(ex);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (ex instanceof Error) {
|
|
54
|
+
return { error: ex.message };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
throw ex;
|
|
58
|
+
}
|
|
41
59
|
}
|
|
42
60
|
|
|
43
|
-
async addCredential(token: string): Promise<boolean
|
|
61
|
+
async addCredential(token: string): Promise<AuthsignalResponse<boolean>> {
|
|
44
62
|
await this.ensureModuleIsInitialized();
|
|
45
63
|
|
|
46
|
-
|
|
64
|
+
try {
|
|
65
|
+
const data = await AuthsignalPushModule.addCredential(token);
|
|
66
|
+
|
|
67
|
+
return { data };
|
|
68
|
+
} catch (ex) {
|
|
69
|
+
if (this.enableLogging) {
|
|
70
|
+
console.log(ex);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (ex instanceof Error) {
|
|
74
|
+
return { error: ex.message };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
throw ex;
|
|
78
|
+
}
|
|
47
79
|
}
|
|
48
80
|
|
|
49
|
-
async removeCredential(): Promise<boolean
|
|
81
|
+
async removeCredential(): Promise<AuthsignalResponse<boolean>> {
|
|
50
82
|
await this.ensureModuleIsInitialized();
|
|
51
83
|
|
|
52
|
-
|
|
84
|
+
try {
|
|
85
|
+
const data = await AuthsignalPushModule.removeCredential();
|
|
86
|
+
return { data };
|
|
87
|
+
} catch (ex) {
|
|
88
|
+
if (this.enableLogging) {
|
|
89
|
+
console.log(ex);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (ex instanceof Error) {
|
|
93
|
+
return { error: ex.message };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
throw ex;
|
|
97
|
+
}
|
|
53
98
|
}
|
|
54
99
|
|
|
55
|
-
async getChallenge(): Promise<string
|
|
100
|
+
async getChallenge(): Promise<AuthsignalResponse<string>> {
|
|
56
101
|
await this.ensureModuleIsInitialized();
|
|
57
102
|
|
|
58
|
-
|
|
103
|
+
try {
|
|
104
|
+
const data = await AuthsignalPushModule.getChallenge();
|
|
105
|
+
|
|
106
|
+
return { data };
|
|
107
|
+
} catch (ex) {
|
|
108
|
+
if (this.enableLogging) {
|
|
109
|
+
console.log(ex);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (ex instanceof Error) {
|
|
113
|
+
return { error: ex.message };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
throw ex;
|
|
117
|
+
}
|
|
59
118
|
}
|
|
60
119
|
|
|
61
120
|
async updateChallenge(
|
|
62
121
|
challengeId: string,
|
|
63
122
|
approved: boolean,
|
|
64
123
|
verificationCode: string | null
|
|
65
|
-
): Promise<boolean
|
|
124
|
+
): Promise<AuthsignalResponse<boolean>> {
|
|
66
125
|
await this.ensureModuleIsInitialized();
|
|
67
126
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
127
|
+
try {
|
|
128
|
+
const data = await NativeModules.updateChallenge(
|
|
129
|
+
challengeId,
|
|
130
|
+
approved,
|
|
131
|
+
verificationCode
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
return { data };
|
|
135
|
+
} catch (ex) {
|
|
136
|
+
if (this.enableLogging) {
|
|
137
|
+
console.log(ex);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (ex instanceof Error) {
|
|
141
|
+
return { error: ex.message };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
throw ex;
|
|
145
|
+
}
|
|
73
146
|
}
|
|
74
147
|
|
|
75
148
|
private async ensureModuleIsInitialized() {
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface AuthsignalResponse<T> {
|
|
2
|
+
data?: T;
|
|
3
|
+
error?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface TokenPayload {
|
|
7
|
+
aud: string;
|
|
8
|
+
exp: number;
|
|
9
|
+
iat: number;
|
|
10
|
+
other: {
|
|
11
|
+
actionCode: string;
|
|
12
|
+
idempotencyKey: string;
|
|
13
|
+
publishableKey: string;
|
|
14
|
+
tenantId: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
username: string;
|
|
17
|
+
};
|
|
18
|
+
scope?: string;
|
|
19
|
+
sub: string;
|
|
20
|
+
}
|