@campnetwork/origin 0.0.1 → 0.0.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/core.cjs +54 -108
- package/dist/core.d.ts +1 -75
- package/dist/core.esm.d.ts +1 -75
- package/dist/core.esm.js +61 -115
- package/dist/react/index.esm.d.ts +232 -2
- package/dist/react/index.esm.js +1130 -449
- package/package.json +1 -1
|
@@ -1,7 +1,237 @@
|
|
|
1
1
|
import React, { JSX } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Abi } from 'viem';
|
|
3
3
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
4
4
|
|
|
5
|
+
interface OriginUsageReturnType {
|
|
6
|
+
user: {
|
|
7
|
+
multiplier: number;
|
|
8
|
+
points: number;
|
|
9
|
+
active: boolean;
|
|
10
|
+
};
|
|
11
|
+
teams: Array<any>;
|
|
12
|
+
dataSources: Array<any>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The Origin class
|
|
16
|
+
* Handles the upload of files to Origin, as well as querying the user's stats
|
|
17
|
+
*/
|
|
18
|
+
declare class Origin {
|
|
19
|
+
#private;
|
|
20
|
+
private jwt;
|
|
21
|
+
constructor(jwt: string);
|
|
22
|
+
uploadFile: (file: File, options?: {
|
|
23
|
+
progressCallback?: (percent: number) => void;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
getOriginUploads: () => Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* Get the user's Origin stats (multiplier, consent, usage, etc.).
|
|
28
|
+
* @returns {Promise<OriginUsageReturnType>} A promise that resolves with the user's Origin stats.
|
|
29
|
+
*/
|
|
30
|
+
getOriginUsage(): Promise<OriginUsageReturnType>;
|
|
31
|
+
/**
|
|
32
|
+
* Set the user's consent for Origin usage.
|
|
33
|
+
* @param {boolean} consent The user's consent.
|
|
34
|
+
* @returns {Promise<void>}
|
|
35
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the consent is not provided.
|
|
36
|
+
*/
|
|
37
|
+
setOriginConsent(consent: boolean): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Set the user's Origin multiplier.
|
|
40
|
+
* @param {number} multiplier The user's Origin multiplier.
|
|
41
|
+
* @returns {Promise<void>}
|
|
42
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated. Also throws an error if the multiplier is not provided.
|
|
43
|
+
*/
|
|
44
|
+
setOriginMultiplier(multiplier: number): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare global {
|
|
48
|
+
interface Window {
|
|
49
|
+
ethereum?: any;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
type CallOptions = {
|
|
53
|
+
value?: bigint;
|
|
54
|
+
gas?: bigint;
|
|
55
|
+
waitForReceipt?: boolean;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The Auth class.
|
|
59
|
+
* @class
|
|
60
|
+
* @classdesc The Auth class is used to authenticate the user.
|
|
61
|
+
*/
|
|
62
|
+
declare class Auth {
|
|
63
|
+
#private;
|
|
64
|
+
redirectUri: Record<string, string>;
|
|
65
|
+
clientId: string;
|
|
66
|
+
isAuthenticated: boolean;
|
|
67
|
+
jwt: string | null;
|
|
68
|
+
walletAddress: string | null;
|
|
69
|
+
userId: string | null;
|
|
70
|
+
viem: any;
|
|
71
|
+
origin: Origin | null;
|
|
72
|
+
/**
|
|
73
|
+
* Constructor for the Auth class.
|
|
74
|
+
* @param {object} options The options object.
|
|
75
|
+
* @param {string} options.clientId The client ID.
|
|
76
|
+
* @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.
|
|
77
|
+
* @param {boolean} [options.allowAnalytics=true] Whether to allow analytics to be sent.
|
|
78
|
+
* @param {object} [options.ackeeInstance] The Ackee instance.
|
|
79
|
+
* @throws {APIError} - Throws an error if the clientId is not provided.
|
|
80
|
+
*/
|
|
81
|
+
constructor({ clientId, redirectUri, allowAnalytics, ackeeInstance, }: {
|
|
82
|
+
clientId: string;
|
|
83
|
+
redirectUri: string | Record<string, string>;
|
|
84
|
+
allowAnalytics?: boolean;
|
|
85
|
+
ackeeInstance?: any;
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Subscribe to an event. Possible events are "state", "provider", "providers", and "viem".
|
|
89
|
+
* @param {("state"|"provider"|"providers"|"viem")} event The event.
|
|
90
|
+
* @param {function} callback The callback function.
|
|
91
|
+
* @returns {void}
|
|
92
|
+
* @example
|
|
93
|
+
* auth.on("state", (state) => {
|
|
94
|
+
* console.log(state);
|
|
95
|
+
* });
|
|
96
|
+
*/
|
|
97
|
+
on(event: "state" | "provider" | "providers" | "viem", callback: Function): void;
|
|
98
|
+
/**
|
|
99
|
+
* Set the loading state.
|
|
100
|
+
* @param {boolean} loading The loading state.
|
|
101
|
+
* @returns {void}
|
|
102
|
+
*/
|
|
103
|
+
setLoading(loading: boolean): void;
|
|
104
|
+
/**
|
|
105
|
+
* 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.
|
|
106
|
+
* @param {object} options The options object. Includes the provider and the provider info.
|
|
107
|
+
* @returns {void}
|
|
108
|
+
* @throws {APIError} - Throws an error if the provider is not provided.
|
|
109
|
+
*/
|
|
110
|
+
setProvider({ provider, info, address, }: {
|
|
111
|
+
provider: any;
|
|
112
|
+
info: any;
|
|
113
|
+
address?: string;
|
|
114
|
+
}): void;
|
|
115
|
+
/**
|
|
116
|
+
* 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.
|
|
117
|
+
* @param {string} walletAddress The wallet address.
|
|
118
|
+
* @returns {void}
|
|
119
|
+
*/
|
|
120
|
+
setWalletAddress(walletAddress: string): void;
|
|
121
|
+
/**
|
|
122
|
+
* Disconnect the user.
|
|
123
|
+
* @returns {Promise<void>}
|
|
124
|
+
*/
|
|
125
|
+
disconnect(): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Connect the user's wallet and sign the message.
|
|
128
|
+
* @returns {Promise<{ success: boolean; message: string; walletAddress: string }>} A promise that resolves with the authentication result.
|
|
129
|
+
* @throws {APIError} - Throws an error if the user cannot be authenticated.
|
|
130
|
+
*/
|
|
131
|
+
connect(): Promise<{
|
|
132
|
+
success: boolean;
|
|
133
|
+
message: string;
|
|
134
|
+
walletAddress: string;
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* Get the user's linked social accounts.
|
|
138
|
+
* @returns {Promise<Record<string, boolean>>} A promise that resolves with the user's linked social accounts.
|
|
139
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated or if the request fails.
|
|
140
|
+
* @example
|
|
141
|
+
* const auth = new Auth({ clientId: "your-client-id" });
|
|
142
|
+
* const socials = await auth.getLinkedSocials();
|
|
143
|
+
* console.log(socials);
|
|
144
|
+
*/
|
|
145
|
+
getLinkedSocials(): Promise<Record<string, boolean>>;
|
|
146
|
+
/**
|
|
147
|
+
* Link the user's Twitter account.
|
|
148
|
+
* @returns {Promise<void>}
|
|
149
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
150
|
+
*/
|
|
151
|
+
linkTwitter(): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Link the user's Discord account.
|
|
154
|
+
* @returns {Promise<void>}
|
|
155
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
156
|
+
*/
|
|
157
|
+
linkDiscord(): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Link the user's Spotify account.
|
|
160
|
+
* @returns {Promise<void>}
|
|
161
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
162
|
+
*/
|
|
163
|
+
linkSpotify(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Link the user's TikTok account.
|
|
166
|
+
* @param {string} handle The user's TikTok handle.
|
|
167
|
+
* @returns {Promise<any>} A promise that resolves with the TikTok account data.
|
|
168
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated.
|
|
169
|
+
*/
|
|
170
|
+
linkTikTok(handle: string): Promise<any>;
|
|
171
|
+
/**
|
|
172
|
+
* Send an OTP to the user's Telegram account.
|
|
173
|
+
* @param {string} phoneNumber The user's phone number.
|
|
174
|
+
* @returns {Promise<any>} A promise that resolves with the OTP data.
|
|
175
|
+
* @throws {Error|APIError} - Throws an error if the user is not authenticated.
|
|
176
|
+
*/
|
|
177
|
+
sendTelegramOTP(phoneNumber: string): Promise<any>;
|
|
178
|
+
/**
|
|
179
|
+
* Link the user's Telegram account.
|
|
180
|
+
* @param {string} phoneNumber The user's phone number.
|
|
181
|
+
* @param {string} otp The OTP.
|
|
182
|
+
* @param {string} phoneCodeHash The phone code hash.
|
|
183
|
+
* @returns {Promise<object>} A promise that resolves with the Telegram account data.
|
|
184
|
+
* @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.
|
|
185
|
+
*/
|
|
186
|
+
linkTelegram(phoneNumber: string, otp: string, phoneCodeHash: string): Promise<any>;
|
|
187
|
+
/**
|
|
188
|
+
* Unlink the user's Twitter account.
|
|
189
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
190
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
191
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
192
|
+
*/
|
|
193
|
+
unlinkTwitter(): Promise<any>;
|
|
194
|
+
/**
|
|
195
|
+
* Unlink the user's Discord account.
|
|
196
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
197
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
198
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
199
|
+
*/
|
|
200
|
+
unlinkDiscord(): Promise<any>;
|
|
201
|
+
/**
|
|
202
|
+
* Unlink the user's Spotify account.
|
|
203
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
204
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
205
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
206
|
+
*/
|
|
207
|
+
unlinkSpotify(): Promise<any>;
|
|
208
|
+
/**
|
|
209
|
+
* Unlink the user's TikTok account.
|
|
210
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
211
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
212
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
213
|
+
*/
|
|
214
|
+
unlinkTikTok(): Promise<any>;
|
|
215
|
+
/**
|
|
216
|
+
* Unlink the user's Telegram account.
|
|
217
|
+
* @returns {Promise<any>} A promise that resolves with the unlink result.
|
|
218
|
+
* @throws {Error} - Throws an error if the user is not authenticated.
|
|
219
|
+
* @throws {APIError} - Throws an error if the request fails.
|
|
220
|
+
*/
|
|
221
|
+
unlinkTelegram(): Promise<any>;
|
|
222
|
+
/**
|
|
223
|
+
* Call a contract method.
|
|
224
|
+
* @param {string} contractAddress The contract address.
|
|
225
|
+
* @param {Abi} abi The contract ABI.
|
|
226
|
+
* @param {string} methodName The method name.
|
|
227
|
+
* @param {any[]} params The method parameters.
|
|
228
|
+
* @param {CallOptions} [options] The call options.
|
|
229
|
+
* @returns {Promise<any>} A promise that resolves with the result of the contract call or transaction hash.
|
|
230
|
+
* @throws {Error} - Throws an error if the wallet client is not connected or if the method is not a view function.
|
|
231
|
+
*/
|
|
232
|
+
callContractMethod(contractAddress: string, abi: Abi, methodName: string, params: any[], options?: CallOptions): Promise<any>;
|
|
233
|
+
}
|
|
234
|
+
|
|
5
235
|
/**
|
|
6
236
|
* CampContext
|
|
7
237
|
* @type {React.Context}
|
|
@@ -13,7 +243,7 @@ import { UseQueryResult } from '@tanstack/react-query';
|
|
|
13
243
|
interface CampContextType {
|
|
14
244
|
clientId: string | null;
|
|
15
245
|
auth: Auth | null;
|
|
16
|
-
setAuth: React.Dispatch<React.SetStateAction<Auth>>;
|
|
246
|
+
setAuth: React.Dispatch<React.SetStateAction<Auth | null>>;
|
|
17
247
|
wagmiAvailable: boolean;
|
|
18
248
|
ackee: any;
|
|
19
249
|
setAckee: any;
|