@mobtechi/sdk-core
v1.1.2
Published
Framework-agnostic core logic and API client for the MobTechi platform
Readme
@mobtechi/sdk-core
The official, framework-agnostic core logic and API client for the MobTechi platform. This library provides a robust foundation for interacting with MobTechi services, including authentication, subscriptions, analytics, and ads.
Installation
npm install @mobtechi/sdk-coreor
yarn add @mobtechi/sdk-coreGetting Started
The SDK exposes a MobTechi class that automatically wires up the underlying API client, analytics tracker, and entitlement engine.
import { MobTechi, MemoryStorageProvider } from '@mobtechi/sdk-core';
const mobtechi = new MobTechi({
baseUrl: 'https://api.mobtechi.com', // Replace with your environment URL
appId: 'your-app-id',
orgId: 'your-org-id', // Optional
storage: new MemoryStorageProvider(), // Replace with localStorage/AsyncStorage provider for persistence
tokenKey: 'mobtechi_auth_token'
});
// Access components
const apiClient = mobtechi.api;
const entitlements = mobtechi.entitlements;
const analytics = mobtechi.analytics;Core Features & Modules
1. Authentication
Handles user identity, login, OTP verification, and token management automatically. Token is seamlessly injected into subsequent API calls.
// 1. Identify User
await mobtechi.api.identify({ identifier: '[email protected]', app_id: '...', org_id: '...' });
// 2. Login (Send OTP or Password)
await mobtechi.login({ identifier: '[email protected]', app_id: '...', org_id: '...' });
// 3. Verify OTP (Automatically sets the access token upon success)
await mobtechi.verifyOtp({ identifier: '[email protected]', code: '123456', app_id: '...', org_id: '...' });
// 4. Logout (Clears local token and resets entitlements)
await mobtechi.logout();2. Entitlements & Subscriptions
Manage user access to premium features based on their active subscription.
// Sync entitlements from the server
const payload = await mobtechi.syncEntitlements('your-app-id');
// Check feature access synchronously after syncing
if (mobtechi.entitlements.hasFeature('premium_analytics')) {
// Grant access
}
// Check premium status
const isPremium = mobtechi.entitlements.isPremiumUser();Direct API methods for subscriptions are available on the api client:
api.getPlans()api.getSubscriptionStatus()api.getEntitlements()api.createOrder()api.createSubscription()api.createTopUp()
3. Ads Config
Fetch user-specific or app-specific ad configurations and claim rewards.
// Get Ad configs
const adsConfig = await mobtechi.api.getAdsConfig('your-org-id', 'your-app-key');
// Claim rewards
await mobtechi.api.claimReward({ orgId: '...', appKey: '...', rewardType: '...' });Advanced Usage
Custom Storage Provider
By default, @mobtechi/sdk-core uses a MemoryStorageProvider which loses tokens upon app restart or page refresh. To persist sessions (e.g., in React Native or web), implement the StorageProvider interface:
import { StorageProvider } from '@mobtechi/sdk-core';
class LocalStorageProvider implements StorageProvider {
async getItem(key: string): Promise<string | null> {
return localStorage.getItem(key);
}
async setItem(key: string, value: string): Promise<void> {
localStorage.setItem(key, value);
}
async removeItem(key: string): Promise<void> {
localStorage.removeItem(key);
}
}
// Use it during initialization
const mobtechi = new MobTechi({
baseUrl: 'https://api.mobtechi.com',
appId: 'your-app-id',
storage: new LocalStorageProvider(),
});Generic API Requests
The api object provides generic HTTP methods (get, post, put, patch, delete) that automatically attach the authorization token and required app/org headers.
const response = await mobtechi.api.get('/custom/endpoint');
console.log(response.data);License
MIT
