@campnetwork/origin 0.0.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.
- package/LICENSE +21 -0
- package/README.md +1007 -0
- package/dist/core.cjs +448 -0
- package/dist/core.d.ts +503 -0
- package/dist/core.esm.d.ts +503 -0
- package/dist/core.esm.js +446 -0
- package/dist/react/components/Tooltip.d.ts +17 -0
- package/dist/react/index.esm.d.ts +194 -0
- package/dist/react/index.esm.js +2406 -0
- package/package.json +73 -0
package/dist/core.esm.js
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import t from"axios";import{custom as e,createWalletClient as i,createPublicClient as n,http as r,getAbiItem as o,encodeFunctionData as s}from"viem";import{toAccount as a}from"viem/accounts";import{createSiweMessage as d}from"viem/siwe";
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */function c(t,e,i,n){return new(i||(i=Promise))((function(r,o){function s(t){try{d(n.next(t))}catch(t){o(t)}}function a(t){try{d(n.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}d((n=n.apply(t,e||[])).next())}))}function h(t,e,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(t):n?n.value:e.get(t)}function u(t,e,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(t,i):r?r.value=i:e.set(t,i),i}"function"==typeof SuppressedError&&SuppressedError;class l extends Error{constructor(t,e){super(t),this.name="APIError",this.statusCode=e||500,Error.captureStackTrace(this,this.constructor)}toJSON(){return{error:this.name,message:this.message,statusCode:this.statusCode||500}}}
|
|
17
|
+
/**
|
|
18
|
+
* Makes a GET request to the given URL with the provided headers.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} url - The URL to send the GET request to.
|
|
21
|
+
* @param {object} headers - The headers to include in the request.
|
|
22
|
+
* @returns {Promise<object>} - The response data.
|
|
23
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
24
|
+
*/function f(e){return c(this,arguments,void 0,(function*(e,i={}){try{return(yield t.get(e,{headers:i})).data}catch(t){if(t.response)throw new l(t.response.data.message||"API request failed",t.response.status);throw new l("Network error or server is unavailable",500)}}))}
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a query string from an object of query parameters.
|
|
27
|
+
*
|
|
28
|
+
* @param {object} params - An object representing query parameters.
|
|
29
|
+
* @returns {string} - The encoded query string.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Builds a complete URL with query parameters.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} baseURL - The base URL of the endpoint.
|
|
35
|
+
* @param {object} params - An object representing query parameters.
|
|
36
|
+
* @returns {string} - The complete URL with query string.
|
|
37
|
+
*/
|
|
38
|
+
function w(t,e={}){const i=function(t={}){return Object.keys(t).map((e=>`${encodeURIComponent(e)}=${encodeURIComponent(t[e])}`)).join("&")}(e);return i?`${t}?${i}`:t}const p="https://wv2h4to5qa.execute-api.us-east-2.amazonaws.com/dev/twitter",m="https://wv2h4to5qa.execute-api.us-east-2.amazonaws.com/dev/spotify";
|
|
39
|
+
/**
|
|
40
|
+
* The TwitterAPI class.
|
|
41
|
+
* @class
|
|
42
|
+
* @classdesc The TwitterAPI class is used to interact with the Twitter API.
|
|
43
|
+
*/
|
|
44
|
+
class v{
|
|
45
|
+
/**
|
|
46
|
+
* Constructor for the TwitterAPI class.
|
|
47
|
+
* @param {object} options - The options object.
|
|
48
|
+
* @param {string} options.apiKey - The API key. (Needed for data fetching)
|
|
49
|
+
*/
|
|
50
|
+
constructor({apiKey:t}){this.apiKey=t}
|
|
51
|
+
/**
|
|
52
|
+
* Fetch Twitter user details by username.
|
|
53
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
54
|
+
* @returns {Promise<object>} - The user details.
|
|
55
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
56
|
+
*/fetchUserByUsername(t){return c(this,void 0,void 0,(function*(){const e=w(`${p}/user`,{twitterUserName:t});return this._fetchDataWithAuth(e)}))}
|
|
57
|
+
/**
|
|
58
|
+
* Fetch tweets by Twitter username.
|
|
59
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
60
|
+
* @param {number} page - The page number.
|
|
61
|
+
* @param {number} limit - The number of items per page.
|
|
62
|
+
* @returns {Promise<object>} - The tweets.
|
|
63
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
64
|
+
*/fetchTweetsByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/tweets`,{twitterUserName:t,page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
65
|
+
/**
|
|
66
|
+
* Fetch followers by Twitter username.
|
|
67
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
68
|
+
* @param {number} page - The page number.
|
|
69
|
+
* @param {number} limit - The number of items per page.
|
|
70
|
+
* @returns {Promise<object>} - The followers.
|
|
71
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
72
|
+
*/fetchFollowersByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/followers`,{twitterUserName:t,page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
73
|
+
/**
|
|
74
|
+
* Fetch following by Twitter username.
|
|
75
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
76
|
+
* @param {number} page - The page number.
|
|
77
|
+
* @param {number} limit - The number of items per page.
|
|
78
|
+
* @returns {Promise<object>} - The following.
|
|
79
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
80
|
+
*/fetchFollowingByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/following`,{twitterUserName:t,page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
81
|
+
/**
|
|
82
|
+
* Fetch tweet by tweet ID.
|
|
83
|
+
* @param {string} tweetId - The tweet ID.
|
|
84
|
+
* @returns {Promise<object>} - The tweet.
|
|
85
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
86
|
+
*/fetchTweetById(t){return c(this,void 0,void 0,(function*(){const e=w(`${p}/getTweetById`,{tweetId:t});return this._fetchDataWithAuth(e)}))}
|
|
87
|
+
/**
|
|
88
|
+
* Fetch user by wallet address.
|
|
89
|
+
* @param {string} walletAddress - The wallet address.
|
|
90
|
+
* @param {number} page - The page number.
|
|
91
|
+
* @param {number} limit - The number of items per page.
|
|
92
|
+
* @returns {Promise<object>} - The user data.
|
|
93
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
94
|
+
*/fetchUserByWalletAddress(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/wallet-twitter-data`,{walletAddress:t,page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
95
|
+
/**
|
|
96
|
+
* Fetch reposted tweets by Twitter username.
|
|
97
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
98
|
+
* @param {number} page - The page number.
|
|
99
|
+
* @param {number} limit - The number of items per page.
|
|
100
|
+
* @returns {Promise<object>} - The reposted tweets.
|
|
101
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
102
|
+
*/fetchRepostedByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/reposted`,{twitterUserName:t,page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch replies by Twitter username.
|
|
105
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
106
|
+
* @param {number} page - The page number.
|
|
107
|
+
* @param {number} limit - The number of items per page.
|
|
108
|
+
* @returns {Promise<object>} - The replies.
|
|
109
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
110
|
+
*/fetchRepliesByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/replies`,{twitterUserName:t,page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
111
|
+
/**
|
|
112
|
+
* Fetch likes by Twitter username.
|
|
113
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
114
|
+
* @param {number} page - The page number.
|
|
115
|
+
* @param {number} limit - The number of items per page.
|
|
116
|
+
* @returns {Promise<object>} - The likes.
|
|
117
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
118
|
+
*/fetchLikesByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/event/likes/${t}`,{page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
119
|
+
/**
|
|
120
|
+
* Fetch follows by Twitter username.
|
|
121
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
122
|
+
* @param {number} page - The page number.
|
|
123
|
+
* @param {number} limit - The number of items per page.
|
|
124
|
+
* @returns {Promise<object>} - The follows.
|
|
125
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
126
|
+
*/fetchFollowsByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/event/follows/${t}`,{page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
127
|
+
/**
|
|
128
|
+
* Fetch viewed tweets by Twitter username.
|
|
129
|
+
* @param {string} twitterUserName - The Twitter username.
|
|
130
|
+
* @param {number} page - The page number.
|
|
131
|
+
* @param {number} limit - The number of items per page.
|
|
132
|
+
* @returns {Promise<object>} - The viewed tweets.
|
|
133
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
134
|
+
*/fetchViewedTweetsByUsername(t){return c(this,arguments,void 0,(function*(t,e=1,i=10){const n=w(`${p}/event/viewed-tweets/${t}`,{page:e,limit:i});return this._fetchDataWithAuth(n)}))}
|
|
135
|
+
/**
|
|
136
|
+
* Private method to fetch data with authorization header.
|
|
137
|
+
* @param {string} url - The URL to fetch.
|
|
138
|
+
* @returns {Promise<object>} - The response data.
|
|
139
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
140
|
+
*/_fetchDataWithAuth(t){return c(this,void 0,void 0,(function*(){if(!this.apiKey)throw new l("API key is required for fetching data",401);try{return yield f(t,{"x-api-key":this.apiKey})}catch(t){throw new l(t.message,t.statusCode)}}))}}
|
|
141
|
+
/**
|
|
142
|
+
* The SpotifyAPI class.
|
|
143
|
+
* @class
|
|
144
|
+
*/class y{
|
|
145
|
+
/**
|
|
146
|
+
* Constructor for the SpotifyAPI class.
|
|
147
|
+
* @constructor
|
|
148
|
+
* @param {SpotifyAPIOptions} options - The Spotify API options.
|
|
149
|
+
* @param {string} options.apiKey - The Spotify API key.
|
|
150
|
+
* @throws {Error} - Throws an error if the API key is not provided.
|
|
151
|
+
*/
|
|
152
|
+
constructor(t){this.apiKey=t.apiKey}
|
|
153
|
+
/**
|
|
154
|
+
* Fetch the user's saved tracks by Spotify user ID.
|
|
155
|
+
* @param {string} spotifyId - The user's Spotify ID.
|
|
156
|
+
* @returns {Promise<object>} - The saved tracks.
|
|
157
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
158
|
+
*/fetchSavedTracksById(t){return c(this,void 0,void 0,(function*(){const e=w(`${m}/save-tracks`,{spotifyId:t});return this._fetchDataWithAuth(e)}))}
|
|
159
|
+
/**
|
|
160
|
+
* Fetch the played tracks of a user by Spotify ID.
|
|
161
|
+
* @param {string} spotifyId - The user's Spotify ID.
|
|
162
|
+
* @returns {Promise<object>} - The played tracks.
|
|
163
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
164
|
+
*/fetchPlayedTracksById(t){return c(this,void 0,void 0,(function*(){const e=w(`${m}/played-tracks`,{spotifyId:t});return this._fetchDataWithAuth(e)}))}
|
|
165
|
+
/**
|
|
166
|
+
* Fetch the user's saved albums by Spotify user ID.
|
|
167
|
+
* @param {string} spotifyId - The user's Spotify ID.
|
|
168
|
+
* @returns {Promise<object>} - The saved albums.
|
|
169
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
170
|
+
*/fetchSavedAlbumsById(t){return c(this,void 0,void 0,(function*(){const e=w(`${m}/saved-albums`,{spotifyId:t});return this._fetchDataWithAuth(e)}))}
|
|
171
|
+
/**
|
|
172
|
+
* Fetch the user's saved playlists by Spotify user ID.
|
|
173
|
+
* @param {string} spotifyId - The user's Spotify ID.
|
|
174
|
+
* @returns {Promise<object>} - The saved playlists.
|
|
175
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
176
|
+
*/fetchSavedPlaylistsById(t){return c(this,void 0,void 0,(function*(){const e=w(`${m}/saved-playlists`,{spotifyId:t});return this._fetchDataWithAuth(e)}))}
|
|
177
|
+
/**
|
|
178
|
+
* Fetch the tracks of an album by album ID.
|
|
179
|
+
* @param {string} spotifyId - The Spotify ID of the user.
|
|
180
|
+
* @param {string} albumId - The album ID.
|
|
181
|
+
* @returns {Promise<object>} - The tracks in the album.
|
|
182
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
183
|
+
*/fetchTracksInAlbum(t,e){return c(this,void 0,void 0,(function*(){const i=w(`${m}/album/tracks`,{spotifyId:t,albumId:e});return this._fetchDataWithAuth(i)}))}
|
|
184
|
+
/**
|
|
185
|
+
* Fetch the tracks in a playlist by playlist ID.
|
|
186
|
+
* @param {string} spotifyId - The Spotify ID of the user.
|
|
187
|
+
* @param {string} playlistId - The playlist ID.
|
|
188
|
+
* @returns {Promise<object>} - The tracks in the playlist.
|
|
189
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
190
|
+
*/fetchTracksInPlaylist(t,e){return c(this,void 0,void 0,(function*(){const i=w(`${m}/playlist/tracks`,{spotifyId:t,playlistId:e});return this._fetchDataWithAuth(i)}))}
|
|
191
|
+
/**
|
|
192
|
+
* Fetch the user's Spotify data by wallet address.
|
|
193
|
+
* @param {string} walletAddress - The wallet address.
|
|
194
|
+
* @returns {Promise<object>} - The user's Spotify data.
|
|
195
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
196
|
+
*/fetchUserByWalletAddress(t){return c(this,void 0,void 0,(function*(){const e=w(`${m}/wallet-spotify-data`,{walletAddress:t});return this._fetchDataWithAuth(e)}))}
|
|
197
|
+
/**
|
|
198
|
+
* Private method to fetch data with authorization header.
|
|
199
|
+
* @param {string} url - The URL to fetch.
|
|
200
|
+
* @returns {Promise<object>} - The response data.
|
|
201
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
202
|
+
*/_fetchDataWithAuth(t){return c(this,void 0,void 0,(function*(){if(!this.apiKey)throw new l("API key is required for fetching data",401);try{return yield f(t,{"x-api-key":this.apiKey})}catch(t){throw new l(t.message,t.statusCode)}}))}}const g={id:123420001114,name:"Basecamp",nativeCurrency:{decimals:18,name:"Camp",symbol:"CAMP"},rpcUrls:{default:{http:["https://rpc-campnetwork.xyz","https://rpc.basecamp.t.raas.gelato.cloud"]}},blockExplorers:{default:{name:"Explorer",url:"https://basecamp.cloud.blockscout.com/"}}};
|
|
203
|
+
// @ts-ignore
|
|
204
|
+
let I=null,A=null;const k=(t,n="window.ethereum",r)=>{var o;if(!t&&!I)return console.warn("Provider is required to create a client."),null;if(!I||I.transport.name!==n&&t||r!==(null===(o=I.account)||void 0===o?void 0:o.address)&&t){const o={chain:g,transport:e(t,{name:n})};r&&(o.account=a(r)),I=i(o)}return I},T=()=>(A||(A=n({chain:g,transport:r()})),A);var b="Connect with Camp Network",$="https://wv2h4to5qa.execute-api.us-east-2.amazonaws.com/dev",E="https://ackee-production-01bd.up.railway.app",S={USER_CONNECTED:"ed42542d-b676-4112-b6d9-6db98048b2e0",USER_DISCONNECTED:"20af31ac-e602-442e-9e0e-b589f4dd4016",TWITTER_LINKED:"7fbea086-90ef-4679-ba69-f47f9255b34c",DISCORD_LINKED:"d73f5ae3-a8e8-48f2-8532-85e0c7780d6a",SPOTIFY_LINKED:"fc1788b4-c984-42c8-96f4-c87f6bb0b8f7",TIKTOK_LINKED:"4a2ffdd3-f0e9-4784-8b49-ff76ec1c0a6a",TELEGRAM_LINKED:"9006bc5d-bcc9-4d01-a860-4f1a201e8e47"};let j=[];const C=()=>j,O=t=>{function e(e){j.some((t=>t.info.uuid===e.detail.info.uuid))||(j=[...j,e.detail],t(j))}if("undefined"!=typeof window)return window.addEventListener("eip6963:announceProvider",e),window.dispatchEvent(new Event("eip6963:requestProvider")),()=>window.removeEventListener("eip6963:announceProvider",e)};var U,N,D,_,P,W,B,x,q,L,R,F,K,z;
|
|
205
|
+
/**
|
|
206
|
+
* The Origin class
|
|
207
|
+
* Handles the upload of files to Origin, as well as querying the user's stats
|
|
208
|
+
*/class J{constructor(t){U.set(this,(t=>c(this,void 0,void 0,(function*(){const e=yield fetch(`${$}/auth/origin/upload-url`,{method:"POST",body:JSON.stringify({name:t.name,type:t.type}),headers:{Authorization:`Bearer ${this.jwt}`}}),i=yield e.json();return i.isError?i.message:i.data})))),N.set(this,((t,e)=>c(this,void 0,void 0,(function*(){(yield fetch(`${$}/auth/origin/update-status`,{method:"PATCH",body:JSON.stringify({status:e,fileKey:t}),headers:{Authorization:`Bearer ${this.jwt}`,"Content-Type":"application/json"}})).ok||console.error("Failed to update origin status")})))),this.uploadFile=(t,e)=>c(this,void 0,void 0,(function*(){const i=yield h(this,U,"f").call(this,t);if(i){try{yield((t,e,i)=>new Promise(((n,r)=>{const o=new XMLHttpRequest;o.open("PUT",e,!0),o.upload.onprogress=t=>{if(t.lengthComputable){const e=t.loaded/t.total*100;i(e)}},o.onload=()=>{o.status>=200&&o.status<300?n(o.response):r(o.statusText)},o.onerror=()=>r(o.statusText),o.send(t)})))(t,i.url,(null==e?void 0:e.progressCallback)||(()=>{}))}catch(t){throw yield h(this,N,"f").call(this,i.key,"failed"),new Error("Failed to upload file: "+t)}yield h(this,N,"f").call(this,i.key,"success")}else console.error("Failed to generate upload URL")})),this.getOriginUploads=()=>c(this,void 0,void 0,(function*(){const t=yield fetch(`${$}/auth/origin/files`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`}});if(!t.ok)return console.error("Failed to get origin uploads"),null;return(yield t.json()).data})),this.jwt=t}
|
|
209
|
+
/**
|
|
210
|
+
* Get the user's Origin stats (multiplier, consent, usage, etc.).
|
|
211
|
+
* @returns {Promise<OriginUsageReturnType>} A promise that resolves with the user's Origin stats.
|
|
212
|
+
*/getOriginUsage(){return c(this,void 0,void 0,(function*(){const t=yield fetch(`${$}/auth/origin/usage`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,
|
|
213
|
+
// "x-client-id": this.clientId,
|
|
214
|
+
"Content-Type":"application/json"}}).then((t=>t.json()));if(!t.isError&&t.data.user)return t;throw new l(t.message||"Failed to fetch Origin usage")}))}
|
|
215
|
+
/**
|
|
216
|
+
* Set the user's consent for Origin usage.
|
|
217
|
+
* @param {boolean} consent The user's consent.
|
|
218
|
+
* @returns {Promise<void>}
|
|
219
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the consent is not provided.
|
|
220
|
+
*/setOriginConsent(t){return c(this,void 0,void 0,(function*(){if(void 0===t)throw new l("Consent is required");const e=yield fetch(`${$}/auth/origin/status`,{method:"PATCH",headers:{Authorization:`Bearer ${this.jwt}`,
|
|
221
|
+
// "x-client-id": this.clientId,
|
|
222
|
+
"Content-Type":"application/json"},body:JSON.stringify({active:t})}).then((t=>t.json()));if(e.isError)throw new l(e.message||"Failed to set Origin consent")}))}
|
|
223
|
+
/**
|
|
224
|
+
* Set the user's Origin multiplier.
|
|
225
|
+
* @param {number} multiplier The user's Origin multiplier.
|
|
226
|
+
* @returns {Promise<void>}
|
|
227
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the multiplier is not provided.
|
|
228
|
+
*/setOriginMultiplier(t){return c(this,void 0,void 0,(function*(){if(void 0===t)throw new l("Multiplier is required");const e=yield fetch(`${$}/auth/origin/multiplier`,{method:"PATCH",headers:{Authorization:`Bearer ${this.jwt}`,
|
|
229
|
+
// "x-client-id": this.clientId,
|
|
230
|
+
"Content-Type":"application/json"},body:JSON.stringify({multiplier:t})}).then((t=>t.json()));if(e.isError)throw new l(e.message||"Failed to set Origin multiplier")}))}}U=new WeakMap,N=new WeakMap;
|
|
231
|
+
/**
|
|
232
|
+
* The Auth class.
|
|
233
|
+
* @class
|
|
234
|
+
* @classdesc The Auth class is used to authenticate the user.
|
|
235
|
+
*/
|
|
236
|
+
class M{
|
|
237
|
+
/**
|
|
238
|
+
* Constructor for the Auth class.
|
|
239
|
+
* @param {object} options The options object.
|
|
240
|
+
* @param {string} options.clientId The client ID.
|
|
241
|
+
* @param {string|object} options.redirectUri The redirect URI used for oauth. Leave empty if you want to use the current URL. If you want different redirect URIs for different socials, pass an object with the socials as keys and the redirect URIs as values.
|
|
242
|
+
* @param {boolean} [options.allowAnalytics=true] Whether to allow analytics to be sent.
|
|
243
|
+
* @param {object} [options.ackeeInstance] The Ackee instance.
|
|
244
|
+
* @throws {APIError} - Throws an error if the clientId is not provided.
|
|
245
|
+
*/
|
|
246
|
+
constructor({clientId:t,redirectUri:e,allowAnalytics:i=!0,ackeeInstance:n}){if(D.add(this),_.set(this,void 0),P.set(this,void 0),!t)throw new Error("clientId is required");this.viem=null,
|
|
247
|
+
// if (typeof window !== "undefined") {
|
|
248
|
+
// if (window.ethereum) this.viem = getClient(window.ethereum);
|
|
249
|
+
// }
|
|
250
|
+
this.redirectUri=(t=>{const e=["twitter","discord","spotify"];return"object"==typeof t?e.reduce(((e,i)=>(e[i]=t[i]||("undefined"!=typeof window?window.location.href:""),e)),{}):"string"==typeof t?e.reduce(((e,i)=>(e[i]=t,e)),{}):t?{}:e.reduce(((t,e)=>(t[e]="undefined"!=typeof window?window.location.href:"",t)),{})})(e),n&&u(this,P,n,"f"),i&&!h(this,P,"f")&&"undefined"!=typeof window&&u(this,P,nt(E,{detailed:!1,ignoreLocalhost:!0,ignoreOwnVisits:!1}),"f"),this.clientId=t,this.isAuthenticated=!1,this.jwt=null,this.origin=null,this.walletAddress=null,this.userId=null,u(this,_,{},"f"),O((t=>{h(this,D,"m",W).call(this,"providers",t)})),h(this,D,"m",B).call(this)}
|
|
251
|
+
/**
|
|
252
|
+
* Subscribe to an event. Possible events are "state", "provider", "providers", and "viem".
|
|
253
|
+
* @param {("state"|"provider"|"providers"|"viem")} event The event.
|
|
254
|
+
* @param {function} callback The callback function.
|
|
255
|
+
* @returns {void}
|
|
256
|
+
* @example
|
|
257
|
+
* auth.on("state", (state) => {
|
|
258
|
+
* console.log(state);
|
|
259
|
+
* });
|
|
260
|
+
*/on(t,e){h(this,_,"f")[t]||(h(this,_,"f")[t]=[]),h(this,_,"f")[t].push(e),"providers"===t&&e(C())}
|
|
261
|
+
/**
|
|
262
|
+
* Set the loading state.
|
|
263
|
+
* @param {boolean} loading The loading state.
|
|
264
|
+
* @returns {void}
|
|
265
|
+
*/setLoading(t){h(this,D,"m",W).call(this,"state",t?"loading":this.isAuthenticated?"authenticated":"unauthenticated")}
|
|
266
|
+
/**
|
|
267
|
+
* Set the provider. This is useful for setting the provider when the user selects a provider from the UI or when dApp wishes to use a specific provider.
|
|
268
|
+
* @param {object} options The options object. Includes the provider and the provider info.
|
|
269
|
+
* @returns {void}
|
|
270
|
+
* @throws {APIError} - Throws an error if the provider is not provided.
|
|
271
|
+
*/setProvider({provider:t,info:e,address:i}){if(!t)throw new l("provider is required");
|
|
272
|
+
// const addr = provider.selectedAddress || provider.accounts[0];
|
|
273
|
+
// TOFIX: the address can be the leftover address, make sure it resets after disconnection
|
|
274
|
+
this.viem=k(t,e.name,i),h(this,D,"m",W).call(this,"viem",this.viem),h(this,D,"m",W).call(this,"provider",{provider:t,info:e})}
|
|
275
|
+
/**
|
|
276
|
+
* Set the wallet address. This is useful for edge cases where the provider can't return the wallet address. Don't use this unless you know what you're doing.
|
|
277
|
+
* @param {string} walletAddress The wallet address.
|
|
278
|
+
* @returns {void}
|
|
279
|
+
*/setWalletAddress(t){this.walletAddress=t}
|
|
280
|
+
/**
|
|
281
|
+
* Disconnect the user.
|
|
282
|
+
* @returns {Promise<void>}
|
|
283
|
+
*/disconnect(){return c(this,void 0,void 0,(function*(){this.isAuthenticated&&(this.isAuthenticated=!1,this.walletAddress=null,this.userId=null,this.jwt=null,this.origin=null,localStorage.removeItem("camp-sdk:wallet-address"),localStorage.removeItem("camp-sdk:user-id"),localStorage.removeItem("camp-sdk:jwt"),h(this,D,"m",W).call(this,"state","unauthenticated"),yield h(this,D,"m",F).call(this,S.USER_DISCONNECTED,"User Disconnected"))}))}
|
|
284
|
+
/**
|
|
285
|
+
* Connect the user's wallet and sign the message.
|
|
286
|
+
* @returns {Promise<{ success: boolean; message: string; walletAddress: string }>} A promise that resolves with the authentication result.
|
|
287
|
+
* @throws {APIError} - Throws an error if the user cannot be authenticated.
|
|
288
|
+
*/connect(){return c(this,void 0,void 0,(function*(){h(this,D,"m",W).call(this,"state","loading");try{this.walletAddress||(yield h(this,D,"m",x).call(this));const t=yield h(this,D,"m",q).call(this),e=h(this,D,"m",R).call(this,t),i=yield this.viem.signMessage({account:this.walletAddress,message:e}),n=yield h(this,D,"m",L).call(this,e,i);if(n.success)return this.isAuthenticated=!0,this.userId=n.userId,this.jwt=n.token,this.origin=new J(this.jwt),localStorage.setItem("camp-sdk:jwt",this.jwt),localStorage.setItem("camp-sdk:wallet-address",this.walletAddress),localStorage.setItem("camp-sdk:user-id",this.userId),h(this,D,"m",W).call(this,"state","authenticated"),yield h(this,D,"m",F).call(this,S.USER_CONNECTED,"User Connected"),{success:!0,message:"Successfully authenticated",walletAddress:this.walletAddress};throw this.isAuthenticated=!1,h(this,D,"m",W).call(this,"state","unauthenticated"),new l("Failed to authenticate")}catch(t){throw this.isAuthenticated=!1,h(this,D,"m",W).call(this,"state","unauthenticated"),new l(t)}}))}
|
|
289
|
+
// ORIGIN
|
|
290
|
+
/**
|
|
291
|
+
* Get the user's linked social accounts.
|
|
292
|
+
* @returns {Promise<Record<string, boolean>>} A promise that resolves with the user's linked social accounts.
|
|
293
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated or if the request fails.
|
|
294
|
+
* @example
|
|
295
|
+
* const auth = new Auth({ clientId: "your-client-id" });
|
|
296
|
+
* const socials = await auth.getLinkedSocials();
|
|
297
|
+
* console.log(socials);
|
|
298
|
+
*/
|
|
299
|
+
getLinkedSocials(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");const t=yield fetch(`${$}/auth/client-user/connections-sdk`,{method:"GET",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"}}).then((t=>t.json()));if(t.isError)throw new l(t.message||"Failed to fetch connections");{const e={};return Object.keys(t.data.data).forEach((i=>{e[i.split("User")[0]]=t.data.data[i]})),e}}))}
|
|
300
|
+
/**
|
|
301
|
+
* Link the user's Twitter account.
|
|
302
|
+
* @returns {Promise<void>}
|
|
303
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
304
|
+
*/linkTwitter(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");
|
|
305
|
+
// await this.#sendAnalyticsEvent(
|
|
306
|
+
// constants.ACKEE_EVENTS.TWITTER_LINKED,
|
|
307
|
+
// "Twitter Linked"
|
|
308
|
+
// );
|
|
309
|
+
window.location.href=`${$}/twitter/connect?clientId=${this.clientId}&userId=${this.userId}&redirect_url=${this.redirectUri.twitter}`}))}
|
|
310
|
+
/**
|
|
311
|
+
* Link the user's Discord account.
|
|
312
|
+
* @returns {Promise<void>}
|
|
313
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
314
|
+
*/linkDiscord(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");
|
|
315
|
+
// await this.#sendAnalyticsEvent(
|
|
316
|
+
// constants.ACKEE_EVENTS.DISCORD_LINKED,
|
|
317
|
+
// "Discord Linked"
|
|
318
|
+
// );
|
|
319
|
+
window.location.href=`${$}/discord/connect?clientId=${this.clientId}&userId=${this.userId}&redirect_url=${this.redirectUri.discord}`}))}
|
|
320
|
+
/**
|
|
321
|
+
* Link the user's Spotify account.
|
|
322
|
+
* @returns {Promise<void>}
|
|
323
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
324
|
+
*/linkSpotify(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");
|
|
325
|
+
// await this.#sendAnalyticsEvent(
|
|
326
|
+
// constants.ACKEE_EVENTS.SPOTIFY_LINKED,
|
|
327
|
+
// "Spotify Linked"
|
|
328
|
+
// );
|
|
329
|
+
window.location.href=`${$}/spotify/connect?clientId=${this.clientId}&userId=${this.userId}&redirect_url=${this.redirectUri.spotify}`}))}
|
|
330
|
+
/**
|
|
331
|
+
* Link the user's TikTok account.
|
|
332
|
+
* @param {string} handle The user's TikTok handle.
|
|
333
|
+
* @returns {Promise<any>} A promise that resolves with the TikTok account data.
|
|
334
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated.
|
|
335
|
+
*/linkTikTok(t){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");const e=yield fetch(`${$}/tiktok/connect-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({userHandle:t,clientId:this.clientId,userId:this.userId})}).then((t=>t.json()));if(e.isError)throw"Request failed with status code 502"===e.message?new l("TikTok service is currently unavailable, try again later"):new l(e.message||"Failed to link TikTok account");return h(this,D,"m",F).call(this,S.TIKTOK_LINKED,"TikTok Linked"),e.data}))}
|
|
336
|
+
/**
|
|
337
|
+
* Send an OTP to the user's Telegram account.
|
|
338
|
+
* @param {string} phoneNumber The user's phone number.
|
|
339
|
+
* @returns {Promise<any>} A promise that resolves with the OTP data.
|
|
340
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated.
|
|
341
|
+
*/sendTelegramOTP(t){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");if(!t)throw new l("Phone number is required");yield this.unlinkTelegram();const e=yield fetch(`${$}/telegram/sendOTP-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({phone:t})}).then((t=>t.json()));if(e.isError)throw new l(e.message||"Failed to send Telegram OTP");return e.data}))}
|
|
342
|
+
/**
|
|
343
|
+
* Link the user's Telegram account.
|
|
344
|
+
* @param {string} phoneNumber The user's phone number.
|
|
345
|
+
* @param {string} otp The OTP.
|
|
346
|
+
* @param {string} phoneCodeHash The phone code hash.
|
|
347
|
+
* @returns {Promise<object>} A promise that resolves with the Telegram account data.
|
|
348
|
+
* @throws {APIError|Error} - Throws an error if the user is not authenticated. Also throws an error if the phone number, OTP, and phone code hash are not provided.
|
|
349
|
+
*/linkTelegram(t,e,i){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");if(!t||!e||!i)throw new l("Phone number, OTP, and phone code hash are required");const n=yield fetch(`${$}/telegram/signIn-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({phone:t,code:e,phone_code_hash:i,userId:this.userId,clientId:this.clientId})}).then((t=>t.json()));if(n.isError)throw new l(n.message||"Failed to link Telegram account");return h(this,D,"m",F).call(this,S.TELEGRAM_LINKED,"Telegram Linked"),n.data}))}
|
|
350
|
+
/**
|
|
351
|
+
* Unlink the user's Twitter account.
|
|
352
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
353
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
354
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
355
|
+
*/unlinkTwitter(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new Error("User needs to be authenticated");const t=yield fetch(`${$}/twitter/disconnect-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({id:this.userId})}).then((t=>t.json()));if(t.isError)throw new l(t.message||"Failed to unlink Twitter account");return t.data}))}
|
|
356
|
+
/**
|
|
357
|
+
* Unlink the user's Discord account.
|
|
358
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
359
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
360
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
361
|
+
*/unlinkDiscord(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new l("User needs to be authenticated");const t=yield fetch(`${$}/discord/disconnect-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({id:this.userId})}).then((t=>t.json()));if(t.isError)throw new l(t.message||"Failed to unlink Discord account");return t.data}))}
|
|
362
|
+
/**
|
|
363
|
+
* Unlink the user's Spotify account.
|
|
364
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
365
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
366
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
367
|
+
*/unlinkSpotify(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new l("User needs to be authenticated");const t=yield fetch(`${$}/spotify/disconnect-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({id:this.userId})}).then((t=>t.json()));if(t.isError)throw new l(t.message||"Failed to unlink Spotify account");return t.data}))}
|
|
368
|
+
/**
|
|
369
|
+
* Unlink the user's TikTok account.
|
|
370
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
371
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
372
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
373
|
+
*/unlinkTikTok(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new l("User needs to be authenticated");const t=yield fetch(`${$}/tiktok/disconnect-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({userId:this.userId})}).then((t=>t.json()));if(t.isError)throw new l(t.message||"Failed to unlink TikTok account");return t.data}))}
|
|
374
|
+
/**
|
|
375
|
+
* Unlink the user's Telegram account.
|
|
376
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
377
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
378
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
379
|
+
*/unlinkTelegram(){return c(this,void 0,void 0,(function*(){if(!this.isAuthenticated)throw new l("User needs to be authenticated");const t=yield fetch(`${$}/telegram/disconnect-sdk`,{method:"POST",redirect:"follow",headers:{Authorization:`Bearer ${this.jwt}`,"x-client-id":this.clientId,"Content-Type":"application/json"},body:JSON.stringify({userId:this.userId})}).then((t=>t.json()));if(t.isError)throw new l(t.message||"Failed to unlink Telegram account");return t.data}))}
|
|
380
|
+
/**
|
|
381
|
+
* Call a contract method.
|
|
382
|
+
* @param {string} contractAddress The contract address.
|
|
383
|
+
* @param {Abi} abi The contract ABI.
|
|
384
|
+
* @param {string} methodName The method name.
|
|
385
|
+
* @param {any[]} params The method parameters.
|
|
386
|
+
* @param {CallOptions} [options] The call options.
|
|
387
|
+
* @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
|
|
388
|
+
* @throws {Error} - Throws an error if the wallet client is not connected or if the method is not a view function.
|
|
389
|
+
*/callContractMethod(t,e,i,n){return c(this,arguments,void 0,(function*(t,e,i,n,r={}){const a=o({abi:e,name:i}),d=a&&"stateMutability"in a&&("view"===a.stateMutability||"pure"===a.stateMutability);if(!d&&!this.viem)throw new Error("WalletClient not connected.");if(d){const r=T();return(yield r.readContract({address:t,abi:e,functionName:i,args:n}))||null}{const[o]=yield this.viem.getAddresses(),a=s({abi:e,functionName:i,args:n});yield h(this,D,"m",z).call(this,g);const d=yield this.viem.sendTransaction({to:t,data:a,account:o,value:r.value,gas:r.gas});if(r.waitForReceipt){return yield h(this,D,"m",K).call(this,d)}return d}}))}}_=new WeakMap,P=new WeakMap,D=new WeakSet,W=function(t,e){h(this,_,"f")[t]&&h(this,_,"f")[t].forEach((t=>t(e)))},B=function(t){return c(this,void 0,void 0,(function*(){var e,i;if("undefined"==typeof localStorage)return;const n=null===localStorage||void 0===localStorage?void 0:localStorage.getItem("camp-sdk:wallet-address"),r=null===localStorage||void 0===localStorage?void 0:localStorage.getItem("camp-sdk:user-id"),o=null===localStorage||void 0===localStorage?void 0:localStorage.getItem("camp-sdk:jwt");if(n&&r&&o){this.walletAddress=n,this.userId=r,this.jwt=o,this.origin=new J(this.jwt),this.isAuthenticated=!0;let s=t;if(!s){const t=null!==(e=C())&&void 0!==e?e:[];for(const e of t)try{if((null===(i=(yield e.provider.request({method:"eth_accounts"}))[0])||void 0===i?void 0:i.toLowerCase())===n.toLowerCase()){s=e.provider;break}}catch(t){console.warn("Failed to fetch accounts from provider:",t)}}s&&(this.viem=k(s,(new Date).getTime().toString(),n),h(this,D,"m",W).call(this,"viem",this.viem))}else this.isAuthenticated=!1}))},x=function(){return c(this,void 0,void 0,(function*(){try{const[t]=yield this.viem.requestAddresses();return this.walletAddress=t,t}catch(t){throw new l(t)}}))},q=function(){return c(this,void 0,void 0,(function*(){try{const t=yield fetch(`${$}/auth/client-user/nonce`,{method:"POST",headers:{"Content-Type":"application/json","x-client-id":this.clientId},body:JSON.stringify({walletAddress:this.walletAddress})}),e=yield t.json();return 200!==t.status?Promise.reject(e.message||"Failed to fetch nonce"):e.data}catch(t){throw new Error(t)}}))},L=function(t,e){return c(this,void 0,void 0,(function*(){try{const i=yield fetch(`${$}/auth/client-user/verify`,{method:"POST",headers:{"Content-Type":"application/json","x-client-id":this.clientId},body:JSON.stringify({message:t,signature:e,walletAddress:this.walletAddress})}),n=yield i.json(),r=n.data.split(".")[1],o=JSON.parse(atob(r));return{success:!n.isError,userId:o.id,token:n.data}}catch(t){throw new l(t)}}))},R=function(t){return d({domain:window.location.host,address:this.walletAddress,statement:b,uri:window.location.origin,version:"1",chainId:this.viem.chain.id,nonce:t})},F=function(t,e){return c(this,arguments,void 0,(function*(t,e,i=1){h(this,P,"f")&&(yield((t,e,i,n)=>c(void 0,void 0,void 0,(function*(){return new Promise(((r,o)=>{if("undefined"!=typeof window&&t)try{t.action(e,{key:i,value:n},(t=>{r(t)}))}catch(t){console.error(t),o(t)}else o(new Error("Unable to send analytics event. If you are using the library, you can ignore this error."))}))})))(h(this,P,"f"),t,e,i))}))},K=function(t){return c(this,void 0,void 0,(function*(){if(!this.viem)throw new Error("WalletClient not connected.");for(;;){const e=yield this.viem.request({method:"eth_getTransactionReceipt",params:[t]});if(e&&e.blockNumber)return e;yield new Promise((t=>setTimeout(t,1e3)))}}))},z=function(t){return c(this,void 0,void 0,(function*(){
|
|
390
|
+
// return;
|
|
391
|
+
if(!this.viem)throw new Error("WalletClient not connected.");let e=yield this.viem.request({method:"eth_chainId",params:[]});if("string"==typeof e&&(e=parseInt(e,16)),e!==t.id)try{yield this.viem.request({method:"wallet_switchEthereumChain",params:[{chainId:"0x"+BigInt(t.id).toString(16)}]})}catch(e){
|
|
392
|
+
// Unrecognized chain
|
|
393
|
+
if(4902!==e.code)throw e;yield this.viem.request({method:"wallet_addEthereumChain",params:[{chainId:"0x"+BigInt(t.id).toString(16),chainName:t.name,rpcUrls:t.rpcUrls.default.http,nativeCurrency:t.nativeCurrency}]}),yield this.viem.request({method:"wallet_switchEthereumChain",params:[{chainId:"0x"+BigInt(t.id).toString(16)}]})}}))};
|
|
394
|
+
/**
|
|
395
|
+
The MIT License (MIT)
|
|
396
|
+
|
|
397
|
+
Copyright (c) Tobias Reich
|
|
398
|
+
|
|
399
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
400
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
401
|
+
in the Software without restriction, including without limitation the rights
|
|
402
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
403
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
404
|
+
furnished to do so, subject to the following conditions:
|
|
405
|
+
|
|
406
|
+
The above copyright notice and this permission notice shall be included in
|
|
407
|
+
all copies or substantial portions of the Software.
|
|
408
|
+
|
|
409
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
410
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
411
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
412
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
413
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
414
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
415
|
+
THE SOFTWARE.
|
|
416
|
+
*/
|
|
417
|
+
const H="undefined"!=typeof window,G=H?null===window||void 0===window?void 0:window.navigator:{userAgent:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",language:"en",languages:[],platform:"",vendor:"",maxTouchPoints:0,hardwareConcurrency:0,deviceMemory:0},V=H?null===window||void 0===window?void 0:window.location:{href:"",protocol:"",host:"",hostname:"",port:"",pathname:"",search:"",hash:""},X=function(t){return"88888888-8888-8888-8888-888888888888"===t},Y=function(){return"hidden"===document.visibilityState},Q=function(){const t=(V.search.split("source=")[1]||"").split("&")[0];return""===t?void 0:t},Z=function(t=!1){var e;const i={siteLocation:null===(e=null===window||void 0===window?void 0:window.location)||void 0===e?void 0:e.href,siteReferrer:document.referrer,source:Q()},n={siteLanguage:G?((null==G?void 0:G.language)||(null==G?void 0:G.language)||"").substr(0,2):"",screenWidth:screen.width,screenHeight:screen.height,screenColorDepth:screen.colorDepth,browserWidth:null===window||void 0===window?void 0:window.outerWidth,browserHeight:null===window||void 0===window?void 0:window.outerHeight};return Object.assign(Object.assign({},i),!0===t?n:{})},tt=function(t){return{query:"\n\t\t\tmutation updateRecord($recordId: ID!) {\n\t\t\t\tupdateRecord(id: $recordId) {\n\t\t\t\t\tsuccess\n\t\t\t\t}\n\t\t\t}\n\t\t",variables:{recordId:t}}},et=function(t,e,i,n){const r=new XMLHttpRequest;r.open("POST",t),r.onload=()=>{if(200!==r.status)throw new Error("Server returned with an unhandled status");let t=null;try{t=JSON.parse(r.responseText)}catch(t){throw new Error("Failed to parse response from server")}if(null!=t.errors)throw new Error(t.errors[0].message);if("function"==typeof n)return n(t)},r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),
|
|
418
|
+
// xhr.withCredentials = opts.ignoreOwnVisits ?? false;
|
|
419
|
+
r.withCredentials=!1,r.send(JSON.stringify(e))},it=function(){const t=document.querySelector("[data-ackee-domain-id]");if(null==t)return;const e=t.getAttribute("data-ackee-server")||"",i=t.getAttribute("data-ackee-domain-id")||"",n=t.getAttribute("data-ackee-opts")||"{}";nt(e,JSON.parse(n)).record(i)},nt=function(t,e){e=function(t={}){
|
|
420
|
+
// Create new object to avoid changes by reference
|
|
421
|
+
const e={};
|
|
422
|
+
// Defaults to false
|
|
423
|
+
return e.detailed=!0===t.detailed,
|
|
424
|
+
// Defaults to true
|
|
425
|
+
e.ignoreLocalhost=!1!==t.ignoreLocalhost,
|
|
426
|
+
// Defaults to true
|
|
427
|
+
e.ignoreOwnVisits=!1!==t.ignoreOwnVisits,e}(e);const i=function(t){const e="/"===t.substr(-1);return t+(!0===e?"":"/")+"api"}(t),n=()=>{},r={record:()=>({stop:n}),updateRecord:()=>({stop:n}),action:n,updateAction:n};if(!0===e.ignoreLocalhost&&!0==(""===(o=V.hostname)||"localhost"===o||"127.0.0.1"===o||"::1"===o)&&!0===H)
|
|
428
|
+
// console.warn("Ackee ignores you because you are on localhost");
|
|
429
|
+
return r;var o,s;if(!0===(s=G?G.userAgent:"",/bot|crawler|spider|crawling/i.test(s)))
|
|
430
|
+
// console.warn("Ackee ignores you because you are a bot");
|
|
431
|
+
return r;
|
|
432
|
+
// Creates a new record on the server and updates the record
|
|
433
|
+
// very x seconds to track the duration of the visit. Tries to use
|
|
434
|
+
// the default attributes when there're no custom attributes defined.
|
|
435
|
+
// Return the real instance
|
|
436
|
+
return{record:(t,n=Z(e.detailed),r)=>{
|
|
437
|
+
// Function to stop updating the record
|
|
438
|
+
let o=!1;return et(i,function(t,e){return{query:"\n\t\t\tmutation createRecord($domainId: ID!, $input: CreateRecordInput!) {\n\t\t\t\tcreateRecord(domainId: $domainId, input: $input) {\n\t\t\t\t\tpayload {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t",variables:{domainId:t,input:e}}}(t,n),0,(t=>{const e=t.data.createRecord.payload.id;if(!0===X(e))
|
|
439
|
+
// return console.warn("Ackee ignores you because this is your own site");
|
|
440
|
+
return;const n=setInterval((()=>{!0!==o?!0!==Y()&&et(i,tt(e)):clearInterval(n)}),15e3);return"function"==typeof r?r(e):void 0})),{stop:()=>{o=!0}}},updateRecord:t=>{
|
|
441
|
+
// Function to stop updating the record
|
|
442
|
+
let e=!1;const n=()=>{e=!0};if(!0===X(t))
|
|
443
|
+
// console.warn("Ackee ignores you because this is your own site");
|
|
444
|
+
return{stop:n};const r=setInterval((()=>{!0!==e?!0!==Y()&&et(i,tt(t)):clearInterval(r)}),15e3);return{stop:n}},action:(t,e,n)=>{et(i,function(t,e){return{query:"\n\t\t\tmutation createAction($eventId: ID!, $input: CreateActionInput!) {\n\t\t\t\tcreateAction(eventId: $eventId, input: $input) {\n\t\t\t\t\tpayload {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t",variables:{eventId:t,input:e}}}(t,e),0,(t=>{const e=t.data.createAction.payload.id;if(!0!==X(e))return"function"==typeof n?n(e):void 0}))},updateAction:(t,e)=>{!0!==X(t)&&et(i,function(t,e){return{query:"\n\t\t\tmutation updateAction($actionId: ID!, $input: UpdateActionInput!) {\n\t\t\t\tupdateAction(id: $actionId, input: $input) {\n\t\t\t\t\tsuccess\n\t\t\t\t}\n\t\t\t}\n\t\t",variables:{actionId:t,input:e}}}(t,e))}}};
|
|
445
|
+
// Only run Ackee automatically when executed in a browser environment
|
|
446
|
+
!0===H&&it();var rt=Object.freeze({__proto__:null,attributes:Z,create:nt,detect:it});export{rt as Ackee,M as Auth,y as SpotifyAPI,v as TwitterAPI};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { JSX, ReactNode, CSSProperties } from "react";
|
|
2
|
+
interface TooltipProps {
|
|
3
|
+
content: string | ReactNode;
|
|
4
|
+
position?: "top" | "bottom" | "left" | "right";
|
|
5
|
+
backgroundColor?: string;
|
|
6
|
+
textColor?: string;
|
|
7
|
+
containerStyle?: CSSProperties;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Tooltip component to wrap other components and display a tooltip on hover.
|
|
12
|
+
* Uses portals to render the tooltip outside of its parent container.
|
|
13
|
+
* @param {TooltipProps} props The props for the Tooltip component.
|
|
14
|
+
* @returns {JSX.Element} The Tooltip component.
|
|
15
|
+
*/
|
|
16
|
+
declare const Tooltip: ({ content, position, backgroundColor, textColor, containerStyle, children, }: TooltipProps) => JSX.Element;
|
|
17
|
+
export default Tooltip;
|