Package Exports
- @okutrade/account-api
- @okutrade/account-api/auth
- @okutrade/account-api/bridge
- @okutrade/account-api/canoe
- @okutrade/account-api/login
- @okutrade/account-api/loginEmail
- @okutrade/account-api/orders
- @okutrade/account-api/preferences
- @okutrade/account-api/quest
- @okutrade/account-api/rewards
- @okutrade/account-api/search
- @okutrade/account-api/specialOrders
- @okutrade/account-api/swapHistory
- @okutrade/account-api/telemetry
- @okutrade/account-api/tokens
- @okutrade/account-api/v2/experience
- @okutrade/account-api/wallet
- @okutrade/account-api/xp
Readme
@oku/account-client
TypeScript client for the OKU Account API built with Connect-ES.
Installation
npm install @oku/account-client @connectrpc/connect @connectrpc/connect-webUsage
Basic Setup
import { createClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import { AuthService, TokensService } from "@oku/account-client";
// Create a transport
const transport = createConnectTransport({
baseUrl: "https://api.oku.trade/connect", // Replace with your API endpoint
});
// Create clients for the services you need
const authClient = createClient(AuthService, transport);
const tokensClient = createClient(TokensService, transport);Authentication
import { AuthService } from "@oku/account-client";
const authClient = createClient(AuthService, transport);
// Validate a JWT token
const response = await authClient.validateToken({
token: "your-jwt-token-here"
});
if (response.isValid) {
console.log("Token is valid for user:", response.userId);
}Token Search
import { SearchService } from "@oku/account-client";
const searchClient = createClient(SearchService, transport);
// Search for tokens
const tokens = await searchClient.searchTokens({
query: "USDC",
chainIds: [1, 10, 137], // Ethereum, Optimism, Polygon
limit: 10
});
console.log("Found tokens:", tokens.tokens);Swap History
import { SwapHistoryService } from "@oku/account-client";
const historyClient = createClient(SwapHistoryService, transport);
// Get swap history for an address
const history = await historyClient.getSwapHistory({
addresses: [{ address: "0x742d35Cc6634C0532925a3b8D000AD5B5f1F4543" }],
chainIds: [1, 10],
limit: 50
});
console.log("Swap history:", history.trades);Special Orders
import { SpecialOrdersService } from "@oku/account-client";
const ordersClient = createClient(SpecialOrdersService, transport);
// Get unified order history across chains
const orders = await ordersClient.unifiedHistory({
addresses: [{ address: "0x742d35Cc6634C0532925a3b8D000AD5B5f1F4543" }],
chainIds: [1, 10, 137]
});
console.log("Order history:", orders.orders);Available Services
- AuthService - Authentication and authorization
- BridgeService - Cross-chain bridge operations
- CanoeService - Quote tracking for swaps and bridges
- LoginService - Wallet-based authentication
- OrdersService - Order management
- PreferencesService - User preferences
- RewardsService - Rewards and points system
- SearchService - Token and pool search
- SpecialOrdersService - Unified order history
- SwapHistoryService - Trading history
- TelemetryService - Analytics and telemetry
- TokensService - Token information and metadata
- WalletService - Wallet management
Modular Imports
You can import specific services to reduce bundle size:
// Import specific services
import { AuthService } from "@oku/account-client/auth";
import { TokensService } from "@oku/account-client/tokens";
import { SearchService } from "@oku/account-client/search";
// Or import types only
import type {
SearchTokensRequest,
SearchTokensResponse
} from "@oku/account-client";Error Handling
Connect-ES provides structured error handling:
import { ConnectError } from "@connectrpc/connect";
try {
const response = await authClient.validateToken({ token: "invalid" });
} catch (error) {
if (error instanceof ConnectError) {
console.error("API Error:", error.code, error.message);
console.error("Details:", error.details);
}
}TypeScript Support
This package provides full TypeScript support with generated types for all request/response messages and service interfaces.
import type {
ValidateTokenRequest,
ValidateTokenResponse,
SearchTokensRequest,
TokenResult
} from "@oku/account-client";
// All types are fully typed and have IntelliSense supportDevelopment
To build the package:
npm run buildTo run type checking:
npm run typecheckLicense
MIT