@pear-protocol/core-sdk 1.16.0 → 1.17.1

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.
@@ -11,18 +11,47 @@ declare class Auth {
11
11
  /**
12
12
  * Begin linking an X account. Send the browser to the returned `authorizeUrl`;
13
13
  * X redirects back to the backend callback, which finishes the link.
14
+ *
15
+ * Pass `returnTo` as the page the user is on - normally `location.href` - and the
16
+ * callback returns them there with the outcome on the query string.
14
17
  */
15
- startXLink(headers?: ClientHeaders): Promise<{
18
+ startXLink(body?: HttpTypes.StartXLinkRequest, headers?: ClientHeaders): Promise<{
16
19
  authorizeUrl: string;
17
20
  }>;
18
21
  /**
19
22
  * Begin signing in with X. Send the browser to the returned `authorizeUrl`; X redirects
20
- * back to the backend callback, which signs in the Pear account that has this X account
23
+ * back to the backend callback, which settles the Pear account that has this X account
21
24
  * connected. It never creates one - connect X from a signed-in session first.
25
+ *
26
+ * Pass `returnTo` as the page the user is on - normally `location.href` - and the
27
+ * callback returns them there with the outcome on the query string.
28
+ *
29
+ * `handoffChallenge` is the base64url SHA-256 of a random 32-byte verifier this browser
30
+ * keeps. Store the verifier under the returned `handoffId`; the return URL names that id
31
+ * in `x_handoff` and carries the ticket in its fragment, and `exchangeXLogin` below
32
+ * trades the two for a session. Nothing signs the user in until that call.
22
33
  */
23
- startXLogin(headers?: ClientHeaders): Promise<{
34
+ startXLogin(body: HttpTypes.StartXLoginRequest, headers?: ClientHeaders): Promise<{
24
35
  authorizeUrl: string;
25
36
  }>;
37
+ /**
38
+ * Redeem a finished X sign-in for a session.
39
+ *
40
+ * Read `x_ticket` from the return URL's fragment and the verifier you filed under the
41
+ * `x_handoff` query parameter, then call this. Returns the same token pair every other
42
+ * login returns and sets the session cookies, so it serves bearer and cookie clients
43
+ * alike. The ticket is single-use and expires in 60 seconds.
44
+ */
45
+ exchangeXLogin(body: HttpTypes.ExchangeXLoginRequest, headers?: ClientHeaders): Promise<{
46
+ accessToken: string;
47
+ refreshToken: string;
48
+ user: {
49
+ id: string;
50
+ role: "basic" | "pro";
51
+ providerId: string | null;
52
+ loginMethod: "email" | "evm_wallet" | "oauth" | "x";
53
+ };
54
+ }>;
26
55
  /**
27
56
  * Unlink the authenticated user's X account. Removes the public handle immediately.
28
57
  */
@@ -1,4 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
3
  class Auth {
4
+ static {
5
+ __name(this, "Auth");
6
+ }
2
7
  client;
3
8
  constructor(client) {
4
9
  this.client = client;
@@ -18,29 +23,57 @@ class Auth {
18
23
  });
19
24
  }
20
25
  /**
21
- * Begin linking an X account. Send the browser to the returned `authorizeUrl`;
22
- * X redirects back to the backend callback, which finishes the link.
23
- */
24
- async startXLink(headers) {
26
+ * Begin linking an X account. Send the browser to the returned `authorizeUrl`;
27
+ * X redirects back to the backend callback, which finishes the link.
28
+ *
29
+ * Pass `returnTo` as the page the user is on - normally `location.href` - and the
30
+ * callback returns them there with the outcome on the query string.
31
+ */
32
+ async startXLink(body = {}, headers) {
25
33
  return await this.client.fetch(`/auth/link/x/start`, {
26
34
  method: "POST",
27
- headers
35
+ headers,
36
+ body
28
37
  });
29
38
  }
30
39
  /**
31
- * Begin signing in with X. Send the browser to the returned `authorizeUrl`; X redirects
32
- * back to the backend callback, which signs in the Pear account that has this X account
33
- * connected. It never creates one - connect X from a signed-in session first.
34
- */
35
- async startXLogin(headers) {
40
+ * Begin signing in with X. Send the browser to the returned `authorizeUrl`; X redirects
41
+ * back to the backend callback, which settles the Pear account that has this X account
42
+ * connected. It never creates one - connect X from a signed-in session first.
43
+ *
44
+ * Pass `returnTo` as the page the user is on - normally `location.href` - and the
45
+ * callback returns them there with the outcome on the query string.
46
+ *
47
+ * `handoffChallenge` is the base64url SHA-256 of a random 32-byte verifier this browser
48
+ * keeps. Store the verifier under the returned `handoffId`; the return URL names that id
49
+ * in `x_handoff` and carries the ticket in its fragment, and `exchangeXLogin` below
50
+ * trades the two for a session. Nothing signs the user in until that call.
51
+ */
52
+ async startXLogin(body, headers) {
36
53
  return await this.client.fetch(`/auth/login/x/start`, {
37
54
  method: "POST",
38
- headers
55
+ headers,
56
+ body
57
+ });
58
+ }
59
+ /**
60
+ * Redeem a finished X sign-in for a session.
61
+ *
62
+ * Read `x_ticket` from the return URL's fragment and the verifier you filed under the
63
+ * `x_handoff` query parameter, then call this. Returns the same token pair every other
64
+ * login returns and sets the session cookies, so it serves bearer and cookie clients
65
+ * alike. The ticket is single-use and expires in 60 seconds.
66
+ */
67
+ async exchangeXLogin(body, headers) {
68
+ return await this.client.fetch(`/auth/login/x/exchange`, {
69
+ method: "POST",
70
+ headers,
71
+ body
39
72
  });
40
73
  }
41
74
  /**
42
- * Unlink the authenticated user's X account. Removes the public handle immediately.
43
- */
75
+ * Unlink the authenticated user's X account. Removes the public handle immediately.
76
+ */
44
77
  async disconnectX(headers) {
45
78
  return await this.client.fetch(`/auth/link/x`, {
46
79
  method: "DELETE",