@proveanything/smartlinks 1.0.11 → 1.0.12
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/api/auth.d.ts +31 -0
- package/dist/api/auth.js +38 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/http.d.ts +4 -0
- package/dist/http.js +6 -0
- package/dist/types/attestation.d.ts +6 -5
- package/package.json +1 -1
- package/src/api/auth.ts +26 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type LoginResponse = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
email: string;
|
|
5
|
+
bearerToken: string;
|
|
6
|
+
account: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
type VerifyTokenResponse = {
|
|
9
|
+
valid: boolean;
|
|
10
|
+
id?: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
account?: Record<string, any>;
|
|
14
|
+
};
|
|
15
|
+
export declare namespace auth {
|
|
16
|
+
/**
|
|
17
|
+
* Login with email and password.
|
|
18
|
+
* Sets the bearerToken for subsequent API calls.
|
|
19
|
+
*/
|
|
20
|
+
function login(email: string, password: string): Promise<LoginResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Logout (clears bearerToken for future API calls).
|
|
23
|
+
*/
|
|
24
|
+
function logout(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Verifies the current bearerToken (or a provided token).
|
|
27
|
+
* Returns user/account info if valid.
|
|
28
|
+
*/
|
|
29
|
+
function verifyToken(token?: string): Promise<VerifyTokenResponse>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
package/dist/api/auth.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { post, setBearerToken, getApiHeaders } from "../http";
|
|
2
|
+
export var auth;
|
|
3
|
+
(function (auth) {
|
|
4
|
+
/**
|
|
5
|
+
* Login with email and password.
|
|
6
|
+
* Sets the bearerToken for subsequent API calls.
|
|
7
|
+
*/
|
|
8
|
+
async function login(email, password) {
|
|
9
|
+
const res = await post("/public/auth/login", { email, password });
|
|
10
|
+
setBearerToken(res.bearerToken);
|
|
11
|
+
return res;
|
|
12
|
+
}
|
|
13
|
+
auth.login = login;
|
|
14
|
+
/**
|
|
15
|
+
* Logout (clears bearerToken for future API calls).
|
|
16
|
+
*/
|
|
17
|
+
function logout() {
|
|
18
|
+
setBearerToken(undefined);
|
|
19
|
+
}
|
|
20
|
+
auth.logout = logout;
|
|
21
|
+
/**
|
|
22
|
+
* Verifies the current bearerToken (or a provided token).
|
|
23
|
+
* Returns user/account info if valid.
|
|
24
|
+
*/
|
|
25
|
+
async function verifyToken(token) {
|
|
26
|
+
// Use the provided token, or the one from getApiHeaders
|
|
27
|
+
const headers = Object.assign({}, getApiHeaders());
|
|
28
|
+
if (token) {
|
|
29
|
+
headers["AUTHORIZATION"] = `Bearer ${token}`;
|
|
30
|
+
}
|
|
31
|
+
const result = await post("/public/auth/verify", {}, headers);
|
|
32
|
+
if (token && result.valid) {
|
|
33
|
+
setBearerToken(token);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
auth.verifyToken = verifyToken;
|
|
38
|
+
})(auth || (auth = {}));
|
package/dist/api/index.d.ts
CHANGED
package/dist/api/index.js
CHANGED
package/dist/http.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export declare function initializeApi(options: {
|
|
|
10
10
|
apiKey?: string;
|
|
11
11
|
bearerToken?: string;
|
|
12
12
|
}): void;
|
|
13
|
+
/**
|
|
14
|
+
* Allows setting the bearerToken at runtime (e.g. after login/logout).
|
|
15
|
+
*/
|
|
16
|
+
export declare function setBearerToken(token: string | undefined): void;
|
|
13
17
|
/**
|
|
14
18
|
* Internal helper that performs a GET request to \`\${baseURL}\${path}\`,
|
|
15
19
|
* injecting headers for apiKey or bearerToken if present.
|
package/dist/http.js
CHANGED
|
@@ -17,6 +17,12 @@ export function initializeApi(options) {
|
|
|
17
17
|
apiKey = options.apiKey;
|
|
18
18
|
bearerToken = options.bearerToken;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Allows setting the bearerToken at runtime (e.g. after login/logout).
|
|
22
|
+
*/
|
|
23
|
+
export function setBearerToken(token) {
|
|
24
|
+
bearerToken = token;
|
|
25
|
+
}
|
|
20
26
|
/**
|
|
21
27
|
* Internal helper that performs a GET request to \`\${baseURL}\${path}\`,
|
|
22
28
|
* injecting headers for apiKey or bearerToken if present.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export interface AttestationResponse {
|
|
2
2
|
id: string;
|
|
3
|
-
proofId: string;
|
|
4
3
|
createdAt: string;
|
|
5
4
|
updatedAt: string;
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
public: Record<string, any>;
|
|
6
|
+
private: Record<string, any>;
|
|
7
|
+
proof: Record<string, any>;
|
|
8
8
|
}
|
|
9
9
|
export interface AttestationCreateRequest {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
public: Record<string, any>;
|
|
11
|
+
private: Record<string, any>;
|
|
12
|
+
proof: Record<string, any>;
|
|
12
13
|
}
|
|
13
14
|
export interface AttestationUpdateRequest {
|
|
14
15
|
type?: string;
|
package/package.json
CHANGED
package/src/api/auth.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { post, setBearerToken } from "../http"
|
|
1
|
+
import { post, setBearerToken, getApiHeaders } from "../http"
|
|
2
2
|
|
|
3
3
|
type LoginResponse = {
|
|
4
4
|
id: string
|
|
@@ -8,6 +8,14 @@ type LoginResponse = {
|
|
|
8
8
|
account: Record<string, any>
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
type VerifyTokenResponse = {
|
|
12
|
+
valid: boolean
|
|
13
|
+
id?: string
|
|
14
|
+
name?: string
|
|
15
|
+
email?: string
|
|
16
|
+
account?: Record<string, any>
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
export namespace auth {
|
|
12
20
|
/**
|
|
13
21
|
* Login with email and password.
|
|
@@ -25,4 +33,21 @@ export namespace auth {
|
|
|
25
33
|
export function logout(): void {
|
|
26
34
|
setBearerToken(undefined)
|
|
27
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Verifies the current bearerToken (or a provided token).
|
|
39
|
+
* Returns user/account info if valid.
|
|
40
|
+
*/
|
|
41
|
+
export async function verifyToken(token?: string): Promise<VerifyTokenResponse> {
|
|
42
|
+
// Use the provided token, or the one from getApiHeaders
|
|
43
|
+
const headers = { ...getApiHeaders() }
|
|
44
|
+
if (token) {
|
|
45
|
+
headers["AUTHORIZATION"] = `Bearer ${token}`
|
|
46
|
+
}
|
|
47
|
+
const result = await post<VerifyTokenResponse>("/public/auth/verify", {}, headers)
|
|
48
|
+
if (token && result.valid) {
|
|
49
|
+
setBearerToken(token)
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
28
53
|
}
|