@taskon/core
v0.0.1-beta.1
Published
TaskOn Core Library
Downloads
199
Readme
@taskon/core
TaskOn Core Library - Client and API modules for TaskOn Widget.
Installation
npm install @taskon/core
# or
pnpm add @taskon/core
# or
yarn add @taskon/coreQuick Start
import { createTaskOnClient, createUserApi } from '@taskon/core';
// 1. Create client
const client = createTaskOnClient({
apiKey: 'your-api-key',
});
// 2. User login
const user = createUserApi(client);
const { token, is_new_user } = await user.loginWithEmail({
sns_id: '[email protected]',
sign: 'signature',
timestamp: Date.now(),
});
// 3. Set user token
client.setUserToken(token);
// 4. Get user info
const info = await user.getInfo();API Reference
createTaskOnClient(config)
Create a TaskOn client instance.
import { createTaskOnClient } from '@taskon/core';
const client = createTaskOnClient({
apiKey: 'your-api-key', // required - API Key for authentication (X-API-Key header)
baseURL: 'https://custom-api.example.com', // optional, default: https://white-label-api.taskon.xyz
timeout: 30000, // optional, default: 30000ms
});Config Options
| Option | Type | Required | Description |
|--------|------|----------|-------------|
| apiKey | string | ✓ | API Key for authentication (X-API-Key header) |
| baseURL | string | | API base URL |
| timeout | number | | Request timeout in ms |
Client Properties & Methods
| Property/Method | Description |
|-----------------|-------------|
| setUserToken(token) | Set user token (C-side user authorization) |
| getUserToken() | Get current user token |
| request(options) | Make a POST request |
HTTP Headers
X-API-Key: xxx # B-side project authorization
Authorization: Bearer xxx # C-side user authorizationcreateUserApi(client)
Create user API module for user authentication.
import { createTaskOnClient, createUserApi, ApiError } from '@taskon/core';
const client = createTaskOnClient({
apiKey: 'your-api-key',
});
const user = createUserApi(client);Login Methods
Email Login
const { token, is_new_user } = await user.loginWithEmail({
sns_id: '[email protected]', // Email address
sign: 'signature', // Signature
timestamp: Date.now(), // Timestamp
sns_type: 'Email', // Optional, defaults to 'Email'
user_name: 'username', // Optional
join_invite_code: 'invite-code', // Optional
});
client.setUserToken(token);EVM Wallet Login
const { token, is_new_user } = await user.loginWithEvm({
address: '0x...', // Wallet address
sign: '0x...', // Signature
timestamp: Date.now(), // Timestamp
chain: 'evm', // Optional, defaults to 'evm'
user_name: 'username', // Optional
join_invite_code: 'invite-code', // Optional
});
client.setUserToken(token);Solana Wallet Login
const { token, is_new_user } = await user.loginWithSolana({
login_request: {
address: '...', // Wallet address
nonce: '...', // Challenge nonce
sig: '...', // Signature
chain_type: 'solana', // Chain type
pubkey: '...', // Optional public key
domain: '...', // Optional domain
timestamp: Date.now(), // Optional timestamp
},
invite_code: 'invite-code', // Optional
});
client.setUserToken(token);SNS Login (Twitter, Discord, Telegram, etc.)
const { token, is_new_user } = await user.loginWithSns({
type: 'Twitter', // SNS type
token: 'oauth-access-token', // OAuth token
invite_code: 'invite-code', // Optional
verify_code: '123456', // Optional (for email)
tg_data: { ... }, // Optional (for Telegram)
});
client.setUserToken(token);Other Methods
| Method | Returns | Description |
|--------|---------|-------------|
| getInfo() | Promise<UserInfo> | Get current user info |
ApiError
Custom error class for API errors.
import { ApiError } from '@taskon/core';
try {
await user.loginWithEmail({
sns_id: '[email protected]',
sign: 'signature',
timestamp: Date.now(),
});
} catch (err) {
if (err instanceof ApiError) {
console.log(err.code); // Error code, e.g., 'INVALID_EMAIL'
console.log(err.message); // Error message
console.log(err.data); // Additional error data
}
}Types
// Client
export type {
TaskOnClientConfig,
RequestOptions,
TaskOnClient,
TaskOnResponse,
} from '@taskon/core';
// User
export type {
UserApi,
UserInfo,
LoginResult,
EmailLoginParams,
EvmLoginParams,
SolanaLoginParams,
SnsLoginParams,
ChainType,
AddressLoginRequest,
TgData,
} from '@taskon/core';TypeScript Support
This package is written in TypeScript with full type definitions included.
Browser and Node.js Support
- Node.js: >= 18.0.0
- Browser: Modern browsers (ES2020+)
License
MIT
