@plainkey/vue 0.5.2 → 0.6.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/dist/index.d.ts +18 -36
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -100
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import * as _plainkey_types0 from "@plainkey/types";
|
|
2
|
+
import { UserIdentifier } from "@plainkey/types";
|
|
3
3
|
|
|
4
4
|
//#region src/usePlainkey/index.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
registeredCredential: Ref<{
|
|
21
|
-
id: string;
|
|
22
|
-
webAuthnId: string;
|
|
23
|
-
} | null, {
|
|
24
|
-
id: string;
|
|
25
|
-
webAuthnId: string;
|
|
26
|
-
} | null>;
|
|
27
|
-
registeredResponse: Ref<RegistrationCompleteResponse | null, RegistrationCompleteResponse | null>;
|
|
28
|
-
addCredential: (addCredentialParams: AddCredentialParams) => Promise<UserCredentialCompleteResponse | ErrorResponse>;
|
|
29
|
-
isAddingCredential: Ref<boolean, boolean>;
|
|
30
|
-
addCredentialError: Ref<string | null, string | null>;
|
|
31
|
-
addCredentialSuccess: Ref<boolean, boolean>;
|
|
32
|
-
addedCredentialResponse: Ref<UserCredentialCompleteResponse | null, UserCredentialCompleteResponse | null>;
|
|
33
|
-
login: (loginParams: LoginParams) => Promise<LoginCompleteResponse>;
|
|
34
|
-
isLoggingIn: Ref<boolean, boolean>;
|
|
35
|
-
loginError: Ref<string | null, string | null>;
|
|
36
|
-
loginSuccess: Ref<boolean, boolean>;
|
|
37
|
-
loggedInResponse: Ref<LoginCompleteResponse | null, LoginCompleteResponse | null>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param projectId - Your PlainKey project ID. You can find it in the PlainKey admin dashboard.
|
|
9
|
+
* @param baseUrl - Set by default to https://api.plainkey.io/api. Change only for development purposes.
|
|
10
|
+
*
|
|
11
|
+
* Docs: https://plainkey.io/docs
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const { login, createUserWithPasskey, addPasskey } = usePlainKey("projectId")
|
|
15
|
+
*/
|
|
16
|
+
declare function usePlainKey(projectId: string, baseUrl?: string): {
|
|
17
|
+
authenticate: (userIdentifier: UserIdentifier) => Promise<_plainkey_types0.AuthenticateResult>;
|
|
18
|
+
createUserWithPasskey: (userName?: string) => Promise<_plainkey_types0.CreateUserWithPasskeyResult>;
|
|
19
|
+
addPasskey: (userToken: string, userIdentifier: UserIdentifier) => Promise<_plainkey_types0.AddPasskeyResult>;
|
|
38
20
|
};
|
|
39
21
|
//#endregion
|
|
40
|
-
export {
|
|
22
|
+
export { usePlainKey };
|
|
41
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/usePlainkey/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/usePlainkey/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAaA;;;;;;;AA+BuE,iBA/BvD,WAAA,CA+BuD,SAAA,EAAA,MAAA,EAAA,OAAA,CAAA,EAAA,MAAA,CAAA,EAAA;EAAA,YAAA,EAAA,CAAA,cAAA,EAtB/B,cAsB+B,EAAA,GAtBjB,OAsBiB,CAtBjB,gBAAA,CAAA,kBAAA,CAsBiB;EAAA,qBAAA,EAAA,CAAA,QAAA,CAAA,EAAA,MAAA,EAAA,GAZrB,OAYqB,CAtBjB,gBAAA,CAUJ,2BAAA,CAYqB;kDAAd,mBAAc,QAAA,gBAAA,CAAA,gBAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,111 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PlainKeyClient } from "@plainkey/browser";
|
|
1
|
+
import { PlainKey } from "@plainkey/browser";
|
|
3
2
|
|
|
4
3
|
//#region src/usePlainkey/index.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
isRegistering.value = true;
|
|
27
|
-
registerError.value = null;
|
|
28
|
-
registerSuccess.value = false;
|
|
29
|
-
registeredCredential.value = null;
|
|
30
|
-
const registrationResult = await plainKeyClient.Registration({ userName: registerParams?.userName });
|
|
31
|
-
registerSuccess.value = registrationResult.success;
|
|
32
|
-
registeredCredential.value = registrationResult.credential;
|
|
33
|
-
registeredResponse.value = registrationResult;
|
|
34
|
-
return registrationResult;
|
|
35
|
-
} catch (err) {
|
|
36
|
-
registerError.value = err instanceof Error ? err.message : "Registration failed";
|
|
37
|
-
return { error: registerError.value };
|
|
38
|
-
} finally {
|
|
39
|
-
isRegistering.value = false;
|
|
40
|
-
}
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param projectId - Your PlainKey project ID. You can find it in the PlainKey admin dashboard.
|
|
7
|
+
* @param baseUrl - Set by default to https://api.plainkey.io/api. Change only for development purposes.
|
|
8
|
+
*
|
|
9
|
+
* Docs: https://plainkey.io/docs
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const { login, createUserWithPasskey, addPasskey } = usePlainKey("projectId")
|
|
13
|
+
*/
|
|
14
|
+
function usePlainKey(projectId, baseUrl) {
|
|
15
|
+
const plainKey = new PlainKey(projectId, baseUrl);
|
|
16
|
+
/**
|
|
17
|
+
* Authenticates a user. Can be used for login, verification, 2FA, etc.
|
|
18
|
+
* Will require user interaction to authenticate.
|
|
19
|
+
*
|
|
20
|
+
* @param userIdentifier - An object with either the user's PlainKey User ID or their userName.
|
|
21
|
+
*/
|
|
22
|
+
function authenticate(userIdentifier) {
|
|
23
|
+
return plainKey.authenticate(userIdentifier);
|
|
41
24
|
}
|
|
42
25
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
26
|
+
* Registration of a new user with a passkey. Will require user interaction to create a passkey.
|
|
27
|
+
*
|
|
28
|
+
* @param userName - A stable unique identifier for the user, like an email address or username.
|
|
29
|
+
* Can be empty for usernameless login.
|
|
45
30
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
isAddingCredential.value = true;
|
|
49
|
-
addCredentialError.value = null;
|
|
50
|
-
addCredentialSuccess.value = false;
|
|
51
|
-
addedCredentialResponse.value = null;
|
|
52
|
-
const credentialResult = await plainKeyClient.AddCredential({
|
|
53
|
-
userIdentifier: addCredentialParams.userIdentifier,
|
|
54
|
-
userToken: addCredentialParams.userToken
|
|
55
|
-
});
|
|
56
|
-
addCredentialSuccess.value = credentialResult.success;
|
|
57
|
-
addedCredentialResponse.value = credentialResult;
|
|
58
|
-
return credentialResult;
|
|
59
|
-
} catch (err) {
|
|
60
|
-
addCredentialError.value = err instanceof Error ? err.message : "Add credential failed";
|
|
61
|
-
return { error: addCredentialError.value };
|
|
62
|
-
} finally {
|
|
63
|
-
isAddingCredential.value = false;
|
|
64
|
-
}
|
|
31
|
+
function createUserWithPasskey(userName) {
|
|
32
|
+
return plainKey.createUserWithPasskey(userName);
|
|
65
33
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
} catch (err) {
|
|
77
|
-
loginError.value = err instanceof Error ? err.message : "Login failed";
|
|
78
|
-
return {
|
|
79
|
-
verified: false,
|
|
80
|
-
user: { id: "" },
|
|
81
|
-
token: {
|
|
82
|
-
token: "",
|
|
83
|
-
expiresInSeconds: 0,
|
|
84
|
-
tokenType: ""
|
|
85
|
-
},
|
|
86
|
-
session: void 0
|
|
87
|
-
};
|
|
88
|
-
} finally {
|
|
89
|
-
isLoggingIn.value = false;
|
|
90
|
-
}
|
|
34
|
+
/**
|
|
35
|
+
* Adds a passkey to an existing user. Will require user interaction to create a passkey.
|
|
36
|
+
*
|
|
37
|
+
* @param userToken - The user authentication token, obtained from login.
|
|
38
|
+
* Do NOT store it in local storage, database, etc. Always keep it in memory.
|
|
39
|
+
*
|
|
40
|
+
* @param userIdentifier - An object with either the user's PlainKey User ID or their userName.
|
|
41
|
+
*/
|
|
42
|
+
function addPasskey(userToken, userIdentifier) {
|
|
43
|
+
return plainKey.addPasskey(userToken, userIdentifier);
|
|
91
44
|
}
|
|
92
45
|
return {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
registerSuccess,
|
|
97
|
-
registeredCredential,
|
|
98
|
-
registeredResponse,
|
|
99
|
-
addCredential,
|
|
100
|
-
isAddingCredential,
|
|
101
|
-
addCredentialError,
|
|
102
|
-
addCredentialSuccess,
|
|
103
|
-
addedCredentialResponse,
|
|
104
|
-
login,
|
|
105
|
-
isLoggingIn,
|
|
106
|
-
loginError,
|
|
107
|
-
loginSuccess,
|
|
108
|
-
loggedInResponse
|
|
46
|
+
authenticate,
|
|
47
|
+
createUserWithPasskey,
|
|
48
|
+
addPasskey
|
|
109
49
|
};
|
|
110
50
|
}
|
|
111
51
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/usePlainkey/index.ts"],"sourcesContent":["import { PlainKey } from \"@plainkey/browser\"\nimport { UserIdentifier } from \"@plainkey/types\"\n\n/**\n *\n * @param projectId - Your PlainKey project ID. You can find it in the PlainKey admin dashboard.\n * @param baseUrl - Set by default to https://api.plainkey.io/api. Change only for development purposes.\n *\n * Docs: https://plainkey.io/docs\n *\n * @example\n * const { login, createUserWithPasskey, addPasskey } = usePlainKey(\"projectId\")\n */\nexport function usePlainKey(projectId: string, baseUrl?: string) {\n const plainKey = new PlainKey(projectId, baseUrl)\n\n /**\n * Authenticates a user. Can be used for login, verification, 2FA, etc.\n * Will require user interaction to authenticate.\n *\n * @param userIdentifier - An object with either the user's PlainKey User ID or their userName.\n */\n function authenticate(userIdentifier: UserIdentifier) {\n return plainKey.authenticate(userIdentifier)\n }\n\n /**\n * Registration of a new user with a passkey. Will require user interaction to create a passkey.\n *\n * @param userName - A stable unique identifier for the user, like an email address or username.\n * Can be empty for usernameless login.\n */\n function createUserWithPasskey(userName?: string) {\n return plainKey.createUserWithPasskey(userName)\n }\n\n /**\n * Adds a passkey to an existing user. Will require user interaction to create a passkey.\n *\n * @param userToken - The user authentication token, obtained from login.\n * Do NOT store it in local storage, database, etc. Always keep it in memory.\n *\n * @param userIdentifier - An object with either the user's PlainKey User ID or their userName.\n */\n function addPasskey(userToken: string, userIdentifier: UserIdentifier) {\n return plainKey.addPasskey(userToken, userIdentifier)\n }\n\n return {\n authenticate,\n createUserWithPasskey,\n addPasskey\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,YAAY,WAAmB,SAAkB;CAC/D,MAAM,WAAW,IAAI,SAAS,WAAW,QAAQ;;;;;;;CAQjD,SAAS,aAAa,gBAAgC;AACpD,SAAO,SAAS,aAAa,eAAe;;;;;;;;CAS9C,SAAS,sBAAsB,UAAmB;AAChD,SAAO,SAAS,sBAAsB,SAAS;;;;;;;;;;CAWjD,SAAS,WAAW,WAAmB,gBAAgC;AACrE,SAAO,SAAS,WAAW,WAAW,eAAe;;AAGvD,QAAO;EACL;EACA;EACA;EACD"}
|