@taskon/core 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/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # @taskon/core
2
+
3
+ TaskOn Core Library - Client and API modules for TaskOn Widget.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @taskon/core
9
+ # or
10
+ pnpm add @taskon/core
11
+ # or
12
+ yarn add @taskon/core
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { createTaskOnClient, createUserApi } from '@taskon/core';
19
+
20
+ // 1. Create client
21
+ const client = createTaskOnClient({
22
+ apiKey: 'your-api-key',
23
+ });
24
+
25
+ // 2. User login
26
+ const user = createUserApi(client);
27
+ const { token, is_new_user } = await user.loginWithEmail({
28
+ sns_id: 'user@example.com',
29
+ sign: 'signature',
30
+ timestamp: Date.now(),
31
+ });
32
+
33
+ // 3. Set user token
34
+ client.setUserToken(token);
35
+
36
+ // 4. Get user info
37
+ const info = await user.getInfo();
38
+ ```
39
+
40
+ ## API Reference
41
+
42
+ ### createTaskOnClient(config)
43
+
44
+ Create a TaskOn client instance.
45
+
46
+ ```typescript
47
+ import { createTaskOnClient } from '@taskon/core';
48
+
49
+ const client = createTaskOnClient({
50
+ apiKey: 'your-api-key', // required - API Key for authentication (X-API-Key header)
51
+ baseURL: 'https://custom-api.example.com', // optional, default: https://white-label-api.taskon.xyz
52
+ timeout: 30000, // optional, default: 30000ms
53
+ });
54
+ ```
55
+
56
+ #### Config Options
57
+
58
+ | Option | Type | Required | Description |
59
+ |--------|------|----------|-------------|
60
+ | `apiKey` | `string` | ✓ | API Key for authentication (X-API-Key header) |
61
+ | `baseURL` | `string` | | API base URL |
62
+ | `timeout` | `number` | | Request timeout in ms |
63
+
64
+ #### Client Properties & Methods
65
+
66
+ | Property/Method | Description |
67
+ |-----------------|-------------|
68
+ | `setUserToken(token)` | Set user token (C-side user authorization) |
69
+ | `getUserToken()` | Get current user token |
70
+ | `request(options)` | Make a POST request |
71
+
72
+ #### HTTP Headers
73
+
74
+ ```
75
+ X-API-Key: xxx # B-side project authorization
76
+ Authorization: Bearer xxx # C-side user authorization
77
+ ```
78
+
79
+ ---
80
+
81
+ ### createUserApi(client)
82
+
83
+ Create user API module for user authentication.
84
+
85
+ ```typescript
86
+ import { createTaskOnClient, createUserApi, ApiError } from '@taskon/core';
87
+
88
+ const client = createTaskOnClient({
89
+ apiKey: 'your-api-key',
90
+ });
91
+
92
+ const user = createUserApi(client);
93
+ ```
94
+
95
+ #### Login Methods
96
+
97
+ **Email Login**
98
+
99
+ ```typescript
100
+ const { token, is_new_user } = await user.loginWithEmail({
101
+ sns_id: 'user@example.com', // Email address
102
+ sign: 'signature', // Signature
103
+ timestamp: Date.now(), // Timestamp
104
+ sns_type: 'Email', // Optional, defaults to 'Email'
105
+ user_name: 'username', // Optional
106
+ join_invite_code: 'invite-code', // Optional
107
+ });
108
+ client.setUserToken(token);
109
+ ```
110
+
111
+ **EVM Wallet Login**
112
+
113
+ ```typescript
114
+ const { token, is_new_user } = await user.loginWithEvm({
115
+ address: '0x...', // Wallet address
116
+ sign: '0x...', // Signature
117
+ timestamp: Date.now(), // Timestamp
118
+ chain: 'evm', // Optional, defaults to 'evm'
119
+ user_name: 'username', // Optional
120
+ join_invite_code: 'invite-code', // Optional
121
+ });
122
+ client.setUserToken(token);
123
+ ```
124
+
125
+ **Solana Wallet Login**
126
+
127
+ ```typescript
128
+ const { token, is_new_user } = await user.loginWithSolana({
129
+ login_request: {
130
+ address: '...', // Wallet address
131
+ nonce: '...', // Challenge nonce
132
+ sig: '...', // Signature
133
+ chain_type: 'solana', // Chain type
134
+ pubkey: '...', // Optional public key
135
+ domain: '...', // Optional domain
136
+ timestamp: Date.now(), // Optional timestamp
137
+ },
138
+ invite_code: 'invite-code', // Optional
139
+ });
140
+ client.setUserToken(token);
141
+ ```
142
+
143
+ **SNS Login (Twitter, Discord, Telegram, etc.)**
144
+
145
+ ```typescript
146
+ const { token, is_new_user } = await user.loginWithSns({
147
+ type: 'Twitter', // SNS type
148
+ token: 'oauth-access-token', // OAuth token
149
+ invite_code: 'invite-code', // Optional
150
+ verify_code: '123456', // Optional (for email)
151
+ tg_data: { ... }, // Optional (for Telegram)
152
+ });
153
+ client.setUserToken(token);
154
+ ```
155
+
156
+ #### Other Methods
157
+
158
+ | Method | Returns | Description |
159
+ |--------|---------|-------------|
160
+ | `getInfo()` | `Promise<UserInfo>` | Get current user info |
161
+
162
+ ---
163
+
164
+ ### ApiError
165
+
166
+ Custom error class for API errors.
167
+
168
+ ```typescript
169
+ import { ApiError } from '@taskon/core';
170
+
171
+ try {
172
+ await user.loginWithEmail({
173
+ sns_id: 'user@example.com',
174
+ sign: 'signature',
175
+ timestamp: Date.now(),
176
+ });
177
+ } catch (err) {
178
+ if (err instanceof ApiError) {
179
+ console.log(err.code); // Error code, e.g., 'INVALID_EMAIL'
180
+ console.log(err.message); // Error message
181
+ console.log(err.data); // Additional error data
182
+ }
183
+ }
184
+ ```
185
+
186
+ ## Types
187
+
188
+ ```typescript
189
+ // Client
190
+ export type {
191
+ TaskOnClientConfig,
192
+ RequestOptions,
193
+ TaskOnClient,
194
+ TaskOnResponse,
195
+ } from '@taskon/core';
196
+
197
+ // User
198
+ export type {
199
+ UserApi,
200
+ UserInfo,
201
+ LoginResult,
202
+ EmailLoginParams,
203
+ EvmLoginParams,
204
+ SolanaLoginParams,
205
+ SnsLoginParams,
206
+ ChainType,
207
+ AddressLoginRequest,
208
+ TgData,
209
+ } from '@taskon/core';
210
+ ```
211
+
212
+ ## TypeScript Support
213
+
214
+ This package is written in TypeScript with full type definitions included.
215
+
216
+ ## Browser and Node.js Support
217
+
218
+ - **Node.js:** >= 18.0.0
219
+ - **Browser:** Modern browsers (ES2020+)
220
+
221
+ ## License
222
+
223
+ MIT