@mobtechi/sdk-core 1.0.0
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/index.d.mts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +28 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Types for MobTechi SDK
|
|
3
|
+
*/
|
|
4
|
+
interface AuthDto {
|
|
5
|
+
email?: string;
|
|
6
|
+
mobile?: string;
|
|
7
|
+
}
|
|
8
|
+
interface VerifyOtpDto {
|
|
9
|
+
email?: string;
|
|
10
|
+
mobile?: string;
|
|
11
|
+
otp: string;
|
|
12
|
+
}
|
|
13
|
+
interface MobTechiUser {
|
|
14
|
+
id: string;
|
|
15
|
+
email: string;
|
|
16
|
+
mobile: string | null;
|
|
17
|
+
name: string | null;
|
|
18
|
+
first_name: string | null;
|
|
19
|
+
last_name: string | null;
|
|
20
|
+
image: string | null;
|
|
21
|
+
user_name: string | null;
|
|
22
|
+
dob: string | null;
|
|
23
|
+
preferences: Record<string, any> | null;
|
|
24
|
+
full_name: string | null;
|
|
25
|
+
org_id: string | null;
|
|
26
|
+
is_premium?: boolean;
|
|
27
|
+
has_ads?: boolean;
|
|
28
|
+
flags?: Record<string, any>;
|
|
29
|
+
ad_config?: Record<string, any>;
|
|
30
|
+
wallet?: Record<string, any> | null;
|
|
31
|
+
}
|
|
32
|
+
interface AuthState {
|
|
33
|
+
is_loaded: boolean;
|
|
34
|
+
is_signed_in: boolean;
|
|
35
|
+
user_id: string | null;
|
|
36
|
+
user: MobTechiUser | null;
|
|
37
|
+
}
|
|
38
|
+
interface SubscriptionPlan {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
price: number;
|
|
43
|
+
currency: string;
|
|
44
|
+
interval: 'month' | 'year' | 'lifetime' | string;
|
|
45
|
+
features: string[];
|
|
46
|
+
credits: number;
|
|
47
|
+
isFree: boolean;
|
|
48
|
+
discountPct: number | string;
|
|
49
|
+
originalPriceINR: number;
|
|
50
|
+
native_product_id?: string;
|
|
51
|
+
}
|
|
52
|
+
interface SubscriptionTopup {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
credits: number;
|
|
56
|
+
priceINR: number;
|
|
57
|
+
originalPriceINR: number;
|
|
58
|
+
native_product_id?: string;
|
|
59
|
+
}
|
|
60
|
+
interface Entitlement {
|
|
61
|
+
id: string;
|
|
62
|
+
active: boolean;
|
|
63
|
+
tier: string;
|
|
64
|
+
expires_at?: string;
|
|
65
|
+
granted_features?: string[];
|
|
66
|
+
}
|
|
67
|
+
interface PlanComparison {
|
|
68
|
+
feature: string;
|
|
69
|
+
FREE: string | boolean;
|
|
70
|
+
LITE: string | boolean;
|
|
71
|
+
PRO: string | boolean;
|
|
72
|
+
}
|
|
73
|
+
type SubscriptionEnvironment = 'expo' | 'capacitor' | 'web';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pluggable Storage Layer Abstraction
|
|
77
|
+
*/
|
|
78
|
+
interface StorageProvider {
|
|
79
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
80
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
81
|
+
removeItem(key: string): void | Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Built-in memory fallback for environments with no local storage or configuration context.
|
|
85
|
+
*/
|
|
86
|
+
declare class MemoryStorageProvider implements StorageProvider {
|
|
87
|
+
private store;
|
|
88
|
+
getItem(key: string): string | null;
|
|
89
|
+
setItem(key: string, value: string): void;
|
|
90
|
+
removeItem(key: string): void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface MobTechiClientOptions {
|
|
94
|
+
baseUrl: string;
|
|
95
|
+
appId?: string;
|
|
96
|
+
orgId?: string;
|
|
97
|
+
storage?: StorageProvider;
|
|
98
|
+
tokenKey?: string;
|
|
99
|
+
}
|
|
100
|
+
declare class MobTechiClient {
|
|
101
|
+
private client;
|
|
102
|
+
private baseUrl;
|
|
103
|
+
storage: StorageProvider;
|
|
104
|
+
private tokenKey;
|
|
105
|
+
private currentToken;
|
|
106
|
+
appId?: string;
|
|
107
|
+
orgId?: string;
|
|
108
|
+
constructor(optionsOrBaseUrl: MobTechiClientOptions | string, appId?: string, orgId?: string, storage?: StorageProvider, tokenKey?: string);
|
|
109
|
+
setToken(token: string | null): Promise<void>;
|
|
110
|
+
getToken(): Promise<string | null>;
|
|
111
|
+
get<T = any>(path: string, config?: any): Promise<{
|
|
112
|
+
data: T;
|
|
113
|
+
status: number;
|
|
114
|
+
}>;
|
|
115
|
+
post<T = any>(path: string, data?: any, config?: any): Promise<{
|
|
116
|
+
data: T;
|
|
117
|
+
status: number;
|
|
118
|
+
}>;
|
|
119
|
+
put<T = any>(path: string, data?: any, config?: any): Promise<{
|
|
120
|
+
data: T;
|
|
121
|
+
status: number;
|
|
122
|
+
}>;
|
|
123
|
+
patch<T = any>(path: string, data?: any, config?: any): Promise<{
|
|
124
|
+
data: T;
|
|
125
|
+
status: number;
|
|
126
|
+
}>;
|
|
127
|
+
delete<T = any>(path: string, config?: any): Promise<{
|
|
128
|
+
data: T;
|
|
129
|
+
status: number;
|
|
130
|
+
}>;
|
|
131
|
+
identify(payload: AuthDto & {
|
|
132
|
+
app_id: string;
|
|
133
|
+
org_id: string;
|
|
134
|
+
}): Promise<any>;
|
|
135
|
+
login(payload: AuthDto & {
|
|
136
|
+
app_id: string;
|
|
137
|
+
org_id: string;
|
|
138
|
+
}): Promise<{
|
|
139
|
+
status: number;
|
|
140
|
+
data: any;
|
|
141
|
+
}>;
|
|
142
|
+
register(payload: any): Promise<any>;
|
|
143
|
+
verifyOtp(payload: VerifyOtpDto & {
|
|
144
|
+
app_id: string;
|
|
145
|
+
org_id: string;
|
|
146
|
+
}): Promise<{
|
|
147
|
+
status: number;
|
|
148
|
+
data: any;
|
|
149
|
+
}>;
|
|
150
|
+
validateToken(token: string): Promise<any>;
|
|
151
|
+
refreshToken(refresh_token: string): Promise<any>;
|
|
152
|
+
logout(token: string): Promise<void>;
|
|
153
|
+
updateProfile(payload: any, token?: string): Promise<any>;
|
|
154
|
+
getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string): Promise<any>;
|
|
155
|
+
getSubscriptionStatus(appKey: string, token?: string): Promise<any>;
|
|
156
|
+
getEntitlements(appKey: string): Promise<any>;
|
|
157
|
+
createOrder(payload: {
|
|
158
|
+
planId: string;
|
|
159
|
+
orgId: string;
|
|
160
|
+
appKey: string;
|
|
161
|
+
}, token?: string): Promise<any>;
|
|
162
|
+
createSubscription(appKey: string, payload: {
|
|
163
|
+
tier: string;
|
|
164
|
+
}): Promise<any>;
|
|
165
|
+
createTopUp(appKey: string, payload: {
|
|
166
|
+
credits: number;
|
|
167
|
+
}): Promise<any>;
|
|
168
|
+
getAdsConfig(orgId: string, appKey: string): Promise<any>;
|
|
169
|
+
claimReward(payload: {
|
|
170
|
+
orgId: string;
|
|
171
|
+
appKey: string;
|
|
172
|
+
rewardType: string;
|
|
173
|
+
}): Promise<any>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare class EntitlementEngine {
|
|
177
|
+
private entitlements;
|
|
178
|
+
private isPremiumFlag;
|
|
179
|
+
/**
|
|
180
|
+
* Update the current entitlements state.
|
|
181
|
+
*/
|
|
182
|
+
setState(isPremiumFlag: boolean, entitlements?: Entitlement[]): void;
|
|
183
|
+
/**
|
|
184
|
+
* Check premium status based on active entitlements or isPremium flag.
|
|
185
|
+
*/
|
|
186
|
+
checkPremium(): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Verify if a specific feature is enabled.
|
|
189
|
+
*/
|
|
190
|
+
hasFeature(feature: string): boolean;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type MobTechiEvent = 'signup' | 'onboarding_completed' | 'first_code_execution' | 'lesson_completed' | 'paywall_viewed' | 'subscription_started' | 'feature_used' | 'premium_feature_attempted' | 'streak_updated' | 'session_started' | 'auth_success';
|
|
194
|
+
interface AnalyticsEventPayload {
|
|
195
|
+
event_name: MobTechiEvent | string;
|
|
196
|
+
payload?: Record<string, any>;
|
|
197
|
+
is_error?: boolean;
|
|
198
|
+
stack_trace?: string;
|
|
199
|
+
metadata?: Record<string, any>;
|
|
200
|
+
platform?: string;
|
|
201
|
+
}
|
|
202
|
+
declare class AnalyticsTracker {
|
|
203
|
+
private readonly api;
|
|
204
|
+
private readonly appId;
|
|
205
|
+
constructor(api: MobTechiClient, appId: string);
|
|
206
|
+
private sessionEvents;
|
|
207
|
+
/**
|
|
208
|
+
* Check if the event should be deduplicated
|
|
209
|
+
*/
|
|
210
|
+
private shouldDeduplicate;
|
|
211
|
+
/**
|
|
212
|
+
* Mark the event as tracked to prevent future duplicates
|
|
213
|
+
*/
|
|
214
|
+
private markTracked;
|
|
215
|
+
/**
|
|
216
|
+
* Track a standard product/business event (non-blocking, fire-and-forget)
|
|
217
|
+
*/
|
|
218
|
+
track(eventName: MobTechiEvent, payload?: Record<string, any>): void;
|
|
219
|
+
/**
|
|
220
|
+
* Track an error or exception (non-blocking, fire-and-forget)
|
|
221
|
+
*/
|
|
222
|
+
trackError(eventName: string, error: Error, metadata?: Record<string, any>): void;
|
|
223
|
+
private capture;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
declare class MobTechi {
|
|
227
|
+
api: MobTechiClient;
|
|
228
|
+
entitlements: EntitlementEngine;
|
|
229
|
+
analytics: AnalyticsTracker;
|
|
230
|
+
constructor(options: MobTechiClientOptions);
|
|
231
|
+
/**
|
|
232
|
+
* Auth helpers to standardize the flow and auto-configure internal state
|
|
233
|
+
*/
|
|
234
|
+
login(payload: AuthDto & {
|
|
235
|
+
app_id: string;
|
|
236
|
+
org_id: string;
|
|
237
|
+
}): Promise<{
|
|
238
|
+
status: number;
|
|
239
|
+
data: any;
|
|
240
|
+
}>;
|
|
241
|
+
verifyOtp(payload: VerifyOtpDto & {
|
|
242
|
+
app_id: string;
|
|
243
|
+
org_id: string;
|
|
244
|
+
}): Promise<{
|
|
245
|
+
status: number;
|
|
246
|
+
data: any;
|
|
247
|
+
}>;
|
|
248
|
+
logout(): Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* Synchronize the current user's subscription and entitlements state
|
|
251
|
+
*/
|
|
252
|
+
syncEntitlements(appId: string): Promise<any>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export { type AnalyticsEventPayload, AnalyticsTracker, type AuthDto, type AuthState, type Entitlement, EntitlementEngine, MemoryStorageProvider, MobTechi, MobTechiClient, type MobTechiClientOptions, type MobTechiEvent, type MobTechiUser, type PlanComparison, type StorageProvider, type SubscriptionEnvironment, type SubscriptionPlan, type SubscriptionTopup, type VerifyOtpDto };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Types for MobTechi SDK
|
|
3
|
+
*/
|
|
4
|
+
interface AuthDto {
|
|
5
|
+
email?: string;
|
|
6
|
+
mobile?: string;
|
|
7
|
+
}
|
|
8
|
+
interface VerifyOtpDto {
|
|
9
|
+
email?: string;
|
|
10
|
+
mobile?: string;
|
|
11
|
+
otp: string;
|
|
12
|
+
}
|
|
13
|
+
interface MobTechiUser {
|
|
14
|
+
id: string;
|
|
15
|
+
email: string;
|
|
16
|
+
mobile: string | null;
|
|
17
|
+
name: string | null;
|
|
18
|
+
first_name: string | null;
|
|
19
|
+
last_name: string | null;
|
|
20
|
+
image: string | null;
|
|
21
|
+
user_name: string | null;
|
|
22
|
+
dob: string | null;
|
|
23
|
+
preferences: Record<string, any> | null;
|
|
24
|
+
full_name: string | null;
|
|
25
|
+
org_id: string | null;
|
|
26
|
+
is_premium?: boolean;
|
|
27
|
+
has_ads?: boolean;
|
|
28
|
+
flags?: Record<string, any>;
|
|
29
|
+
ad_config?: Record<string, any>;
|
|
30
|
+
wallet?: Record<string, any> | null;
|
|
31
|
+
}
|
|
32
|
+
interface AuthState {
|
|
33
|
+
is_loaded: boolean;
|
|
34
|
+
is_signed_in: boolean;
|
|
35
|
+
user_id: string | null;
|
|
36
|
+
user: MobTechiUser | null;
|
|
37
|
+
}
|
|
38
|
+
interface SubscriptionPlan {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
price: number;
|
|
43
|
+
currency: string;
|
|
44
|
+
interval: 'month' | 'year' | 'lifetime' | string;
|
|
45
|
+
features: string[];
|
|
46
|
+
credits: number;
|
|
47
|
+
isFree: boolean;
|
|
48
|
+
discountPct: number | string;
|
|
49
|
+
originalPriceINR: number;
|
|
50
|
+
native_product_id?: string;
|
|
51
|
+
}
|
|
52
|
+
interface SubscriptionTopup {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
credits: number;
|
|
56
|
+
priceINR: number;
|
|
57
|
+
originalPriceINR: number;
|
|
58
|
+
native_product_id?: string;
|
|
59
|
+
}
|
|
60
|
+
interface Entitlement {
|
|
61
|
+
id: string;
|
|
62
|
+
active: boolean;
|
|
63
|
+
tier: string;
|
|
64
|
+
expires_at?: string;
|
|
65
|
+
granted_features?: string[];
|
|
66
|
+
}
|
|
67
|
+
interface PlanComparison {
|
|
68
|
+
feature: string;
|
|
69
|
+
FREE: string | boolean;
|
|
70
|
+
LITE: string | boolean;
|
|
71
|
+
PRO: string | boolean;
|
|
72
|
+
}
|
|
73
|
+
type SubscriptionEnvironment = 'expo' | 'capacitor' | 'web';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pluggable Storage Layer Abstraction
|
|
77
|
+
*/
|
|
78
|
+
interface StorageProvider {
|
|
79
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
80
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
81
|
+
removeItem(key: string): void | Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Built-in memory fallback for environments with no local storage or configuration context.
|
|
85
|
+
*/
|
|
86
|
+
declare class MemoryStorageProvider implements StorageProvider {
|
|
87
|
+
private store;
|
|
88
|
+
getItem(key: string): string | null;
|
|
89
|
+
setItem(key: string, value: string): void;
|
|
90
|
+
removeItem(key: string): void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface MobTechiClientOptions {
|
|
94
|
+
baseUrl: string;
|
|
95
|
+
appId?: string;
|
|
96
|
+
orgId?: string;
|
|
97
|
+
storage?: StorageProvider;
|
|
98
|
+
tokenKey?: string;
|
|
99
|
+
}
|
|
100
|
+
declare class MobTechiClient {
|
|
101
|
+
private client;
|
|
102
|
+
private baseUrl;
|
|
103
|
+
storage: StorageProvider;
|
|
104
|
+
private tokenKey;
|
|
105
|
+
private currentToken;
|
|
106
|
+
appId?: string;
|
|
107
|
+
orgId?: string;
|
|
108
|
+
constructor(optionsOrBaseUrl: MobTechiClientOptions | string, appId?: string, orgId?: string, storage?: StorageProvider, tokenKey?: string);
|
|
109
|
+
setToken(token: string | null): Promise<void>;
|
|
110
|
+
getToken(): Promise<string | null>;
|
|
111
|
+
get<T = any>(path: string, config?: any): Promise<{
|
|
112
|
+
data: T;
|
|
113
|
+
status: number;
|
|
114
|
+
}>;
|
|
115
|
+
post<T = any>(path: string, data?: any, config?: any): Promise<{
|
|
116
|
+
data: T;
|
|
117
|
+
status: number;
|
|
118
|
+
}>;
|
|
119
|
+
put<T = any>(path: string, data?: any, config?: any): Promise<{
|
|
120
|
+
data: T;
|
|
121
|
+
status: number;
|
|
122
|
+
}>;
|
|
123
|
+
patch<T = any>(path: string, data?: any, config?: any): Promise<{
|
|
124
|
+
data: T;
|
|
125
|
+
status: number;
|
|
126
|
+
}>;
|
|
127
|
+
delete<T = any>(path: string, config?: any): Promise<{
|
|
128
|
+
data: T;
|
|
129
|
+
status: number;
|
|
130
|
+
}>;
|
|
131
|
+
identify(payload: AuthDto & {
|
|
132
|
+
app_id: string;
|
|
133
|
+
org_id: string;
|
|
134
|
+
}): Promise<any>;
|
|
135
|
+
login(payload: AuthDto & {
|
|
136
|
+
app_id: string;
|
|
137
|
+
org_id: string;
|
|
138
|
+
}): Promise<{
|
|
139
|
+
status: number;
|
|
140
|
+
data: any;
|
|
141
|
+
}>;
|
|
142
|
+
register(payload: any): Promise<any>;
|
|
143
|
+
verifyOtp(payload: VerifyOtpDto & {
|
|
144
|
+
app_id: string;
|
|
145
|
+
org_id: string;
|
|
146
|
+
}): Promise<{
|
|
147
|
+
status: number;
|
|
148
|
+
data: any;
|
|
149
|
+
}>;
|
|
150
|
+
validateToken(token: string): Promise<any>;
|
|
151
|
+
refreshToken(refresh_token: string): Promise<any>;
|
|
152
|
+
logout(token: string): Promise<void>;
|
|
153
|
+
updateProfile(payload: any, token?: string): Promise<any>;
|
|
154
|
+
getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string): Promise<any>;
|
|
155
|
+
getSubscriptionStatus(appKey: string, token?: string): Promise<any>;
|
|
156
|
+
getEntitlements(appKey: string): Promise<any>;
|
|
157
|
+
createOrder(payload: {
|
|
158
|
+
planId: string;
|
|
159
|
+
orgId: string;
|
|
160
|
+
appKey: string;
|
|
161
|
+
}, token?: string): Promise<any>;
|
|
162
|
+
createSubscription(appKey: string, payload: {
|
|
163
|
+
tier: string;
|
|
164
|
+
}): Promise<any>;
|
|
165
|
+
createTopUp(appKey: string, payload: {
|
|
166
|
+
credits: number;
|
|
167
|
+
}): Promise<any>;
|
|
168
|
+
getAdsConfig(orgId: string, appKey: string): Promise<any>;
|
|
169
|
+
claimReward(payload: {
|
|
170
|
+
orgId: string;
|
|
171
|
+
appKey: string;
|
|
172
|
+
rewardType: string;
|
|
173
|
+
}): Promise<any>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare class EntitlementEngine {
|
|
177
|
+
private entitlements;
|
|
178
|
+
private isPremiumFlag;
|
|
179
|
+
/**
|
|
180
|
+
* Update the current entitlements state.
|
|
181
|
+
*/
|
|
182
|
+
setState(isPremiumFlag: boolean, entitlements?: Entitlement[]): void;
|
|
183
|
+
/**
|
|
184
|
+
* Check premium status based on active entitlements or isPremium flag.
|
|
185
|
+
*/
|
|
186
|
+
checkPremium(): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Verify if a specific feature is enabled.
|
|
189
|
+
*/
|
|
190
|
+
hasFeature(feature: string): boolean;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type MobTechiEvent = 'signup' | 'onboarding_completed' | 'first_code_execution' | 'lesson_completed' | 'paywall_viewed' | 'subscription_started' | 'feature_used' | 'premium_feature_attempted' | 'streak_updated' | 'session_started' | 'auth_success';
|
|
194
|
+
interface AnalyticsEventPayload {
|
|
195
|
+
event_name: MobTechiEvent | string;
|
|
196
|
+
payload?: Record<string, any>;
|
|
197
|
+
is_error?: boolean;
|
|
198
|
+
stack_trace?: string;
|
|
199
|
+
metadata?: Record<string, any>;
|
|
200
|
+
platform?: string;
|
|
201
|
+
}
|
|
202
|
+
declare class AnalyticsTracker {
|
|
203
|
+
private readonly api;
|
|
204
|
+
private readonly appId;
|
|
205
|
+
constructor(api: MobTechiClient, appId: string);
|
|
206
|
+
private sessionEvents;
|
|
207
|
+
/**
|
|
208
|
+
* Check if the event should be deduplicated
|
|
209
|
+
*/
|
|
210
|
+
private shouldDeduplicate;
|
|
211
|
+
/**
|
|
212
|
+
* Mark the event as tracked to prevent future duplicates
|
|
213
|
+
*/
|
|
214
|
+
private markTracked;
|
|
215
|
+
/**
|
|
216
|
+
* Track a standard product/business event (non-blocking, fire-and-forget)
|
|
217
|
+
*/
|
|
218
|
+
track(eventName: MobTechiEvent, payload?: Record<string, any>): void;
|
|
219
|
+
/**
|
|
220
|
+
* Track an error or exception (non-blocking, fire-and-forget)
|
|
221
|
+
*/
|
|
222
|
+
trackError(eventName: string, error: Error, metadata?: Record<string, any>): void;
|
|
223
|
+
private capture;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
declare class MobTechi {
|
|
227
|
+
api: MobTechiClient;
|
|
228
|
+
entitlements: EntitlementEngine;
|
|
229
|
+
analytics: AnalyticsTracker;
|
|
230
|
+
constructor(options: MobTechiClientOptions);
|
|
231
|
+
/**
|
|
232
|
+
* Auth helpers to standardize the flow and auto-configure internal state
|
|
233
|
+
*/
|
|
234
|
+
login(payload: AuthDto & {
|
|
235
|
+
app_id: string;
|
|
236
|
+
org_id: string;
|
|
237
|
+
}): Promise<{
|
|
238
|
+
status: number;
|
|
239
|
+
data: any;
|
|
240
|
+
}>;
|
|
241
|
+
verifyOtp(payload: VerifyOtpDto & {
|
|
242
|
+
app_id: string;
|
|
243
|
+
org_id: string;
|
|
244
|
+
}): Promise<{
|
|
245
|
+
status: number;
|
|
246
|
+
data: any;
|
|
247
|
+
}>;
|
|
248
|
+
logout(): Promise<void>;
|
|
249
|
+
/**
|
|
250
|
+
* Synchronize the current user's subscription and entitlements state
|
|
251
|
+
*/
|
|
252
|
+
syncEntitlements(appId: string): Promise<any>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export { type AnalyticsEventPayload, AnalyticsTracker, type AuthDto, type AuthState, type Entitlement, EntitlementEngine, MemoryStorageProvider, MobTechi, MobTechiClient, type MobTechiClientOptions, type MobTechiEvent, type MobTechiUser, type PlanComparison, type StorageProvider, type SubscriptionEnvironment, type SubscriptionPlan, type SubscriptionTopup, type VerifyOtpDto };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var T=Object.create;var p=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var x=(r,t)=>{for(var e in t)p(r,e,{get:t[e],enumerable:!0})},b=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of v(t))!P.call(r,i)&&i!==e&&p(r,i,{get:()=>t[i],enumerable:!(s=_(t,i))||s.enumerable});return r};var E=(r,t,e)=>(e=r!=null?T(I(r)):{},b(t||!r||!r.__esModule?p(e,"default",{value:r,enumerable:!0}):e,r)),$=r=>b(p({},"__esModule",{value:!0}),r);var A={};x(A,{AnalyticsTracker:()=>l,EntitlementEngine:()=>u,MemoryStorageProvider:()=>o,MobTechi:()=>y,MobTechiClient:()=>c});module.exports=$(A);var o=class{store={};getItem(t){return this.store[t]||null}setItem(t,e){this.store[t]=e}removeItem(t){delete this.store[t]}};var k=E(require("axios"));var c=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,m){let d,a=e,n=s,g=i,f=m;typeof t=="object"&&t!==null?(d=t.baseUrl,a=t.appId,n=t.orgId,g=t.storage,f=t.tokenKey):d=t,this.baseUrl=d,this.appId=a,this.orgId=n,this.storage=g||new o,this.tokenKey=f||"mobtechi_auth_token",this.client=k.default.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...a&&{"x-app-id":a},...n&&{"x-org-id":n}}}),this.client.interceptors.request.use(async h=>{if(!this.currentToken){let w=await this.storage.getItem(this.tokenKey);w&&(this.currentToken=w)}return this.currentToken&&h.headers&&(h.headers.Authorization=`Bearer ${this.currentToken}`),h})}async setToken(t){this.currentToken=t,t?await this.storage.setItem(this.tokenKey,t):await this.storage.removeItem(this.tokenKey)}async getToken(){return this.currentToken||(this.currentToken=await this.storage.getItem(this.tokenKey)),this.currentToken}async get(t,e){let s=await this.client.get(t,e);return{data:s.data,status:s.status}}async post(t,e,s){let i=await this.client.post(t,e,s);return{data:i.data,status:i.status}}async put(t,e,s){let i=await this.client.put(t,e,s);return{data:i.data,status:i.status}}async patch(t,e,s){let i=await this.client.patch(t,e,s);return{data:i.data,status:i.status}}async delete(t,e){let s=await this.client.delete(t,e);return{data:s.data,status:s.status}}async identify(t){return(await this.client.post("/auth/identify",t)).data}async login(t){let e=await this.client.post("/auth/login",t);return{status:e.status,data:e.data}}async register(t){return(await this.client.post("/auth/register",t)).data}async verifyOtp(t){let e=await this.client.post("/auth/otp_verify",t);return{status:e.status,data:e.data}}async validateToken(t){return(await this.client.get("/auth/validate",{headers:{Authorization:`Bearer ${t}`}})).data}async refreshToken(t){return(await this.client.post("/auth/refresh",{refresh_token:t})).data}async logout(t){await this.client.delete("/auth/logout",{headers:{Authorization:`Bearer ${t}`}})}async updateProfile(t,e){let s=e?{Authorization:`Bearer ${e}`}:{};return(await this.client.put("/user/update-profile",t,{headers:s})).data}async getPlans(t,e){let s=t||this.orgId||"",i=e||this.appId||"";if(t&&!(a=>a?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(a):!1)(t)){i=t;let a=e||"",n=a?`?user_id=${a}`:"";return(await this.client.get(`/${i}/subscriptions/plans${n}`)).data}return(await this.client.get(`/user/subscription/plans?orgId=${s}&appKey=${i}`)).data}async getSubscriptionStatus(t,e){return(await this.client.get(`/user/subscription/status?appId=${t}`)).data}async getEntitlements(t){return(await this.client.get(`/${t}/subscriptions/entitlements`)).data}async createOrder(t,e){return(await this.client.post("/user/subscription/create-order",t)).data}async createSubscription(t,e){return(await this.client.post(`/${t}/subscriptions/create`,e)).data}async createTopUp(t,e){return(await this.client.post(`/${t}/subscriptions/topup`,e)).data}async getAdsConfig(t,e){return(await this.client.get(`/user/ads/config?orgId=${t}&appKey=${e}`)).data}async claimReward(t){return(await this.client.post("/user/rewards/ad-claim",t)).data}};var u=class{entitlements=[];isPremiumFlag=!1;setState(t,e=[]){this.isPremiumFlag=t,this.entitlements=e}checkPremium(){return this.isPremiumFlag?!0:this.entitlements.some(t=>t.active&&t.tier!=="FREE")}hasFeature(t){return this.isPremiumFlag?!0:this.entitlements.some(e=>e.active&&e.granted_features&&e.granted_features.includes(t))}};var l=class{constructor(t,e){this.api=t;this.appId=e}api;appId;sessionEvents=new Set;async shouldDeduplicate(t){if(t==="onboarding_completed"||t==="first_code_execution"){let e=`mt_dedup_${t}`;return await this.api.storage.getItem(e)==="true"}return t==="paywall_viewed"?this.sessionEvents.has(t):!1}async markTracked(t){if(t==="onboarding_completed"||t==="first_code_execution"){let e=`mt_dedup_${t}`;await this.api.storage.setItem(e,"true")}else t==="paywall_viewed"&&this.sessionEvents.add(t)}track(t,e){(async()=>{await this.shouldDeduplicate(t)||(await this.markTracked(t),await this.capture({event_name:t,payload:e}))})().catch(s=>{console.warn(`[MobTechi Analytics] failed async track for ${t}`,s)})}trackError(t,e,s){(async()=>{await this.capture({event_name:t,is_error:!0,stack_trace:e.stack,metadata:s})})().catch(i=>{console.warn(`[MobTechi Analytics] failed async trackError for ${t}`,i)})}async capture(t){try{await this.api.post("/analytics/capture",{app_id:this.appId,...t})}catch{console.warn(`[MobTechi Analytics] Failed to track event: ${t.event_name}`)}}};var y=class{api;entitlements;analytics;constructor(t){this.api=new c(t),this.entitlements=new u,this.analytics=new l(this.api,t.appId||"unknown")}async login(t){return await this.api.login(t)}async verifyOtp(t){let e=await this.api.verifyOtp(t);return e.data&&e.data.token&&await this.api.setToken(e.data.token),e}async logout(){let t=await this.api.getToken();if(t)try{await this.api.logout(t)}catch{}await this.api.setToken(null),this.entitlements.setState(!1,[])}async syncEntitlements(t){try{let e=await this.api.getEntitlements(t);if(e){let s=!!e.isPremium,i=e.features||[];this.entitlements.setState(s,i)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}};0&&(module.exports={AnalyticsTracker,EntitlementEngine,MemoryStorageProvider,MobTechi,MobTechiClient});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=class{store={};getItem(t){return this.store[t]||null}setItem(t,e){this.store[t]=e}removeItem(t){delete this.store[t]}};import w from"axios";var u=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,h){let o,r=e,a=s,p=i,y=h;typeof t=="object"&&t!==null?(o=t.baseUrl,r=t.appId,a=t.orgId,p=t.storage,y=t.tokenKey):o=t,this.baseUrl=o,this.appId=r,this.orgId=a,this.storage=p||new c,this.tokenKey=y||"mobtechi_auth_token",this.client=w.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...r&&{"x-app-id":r},...a&&{"x-org-id":a}}}),this.client.interceptors.request.use(async g=>{if(!this.currentToken){let m=await this.storage.getItem(this.tokenKey);m&&(this.currentToken=m)}return this.currentToken&&g.headers&&(g.headers.Authorization=`Bearer ${this.currentToken}`),g})}async setToken(t){this.currentToken=t,t?await this.storage.setItem(this.tokenKey,t):await this.storage.removeItem(this.tokenKey)}async getToken(){return this.currentToken||(this.currentToken=await this.storage.getItem(this.tokenKey)),this.currentToken}async get(t,e){let s=await this.client.get(t,e);return{data:s.data,status:s.status}}async post(t,e,s){let i=await this.client.post(t,e,s);return{data:i.data,status:i.status}}async put(t,e,s){let i=await this.client.put(t,e,s);return{data:i.data,status:i.status}}async patch(t,e,s){let i=await this.client.patch(t,e,s);return{data:i.data,status:i.status}}async delete(t,e){let s=await this.client.delete(t,e);return{data:s.data,status:s.status}}async identify(t){return(await this.client.post("/auth/identify",t)).data}async login(t){let e=await this.client.post("/auth/login",t);return{status:e.status,data:e.data}}async register(t){return(await this.client.post("/auth/register",t)).data}async verifyOtp(t){let e=await this.client.post("/auth/otp_verify",t);return{status:e.status,data:e.data}}async validateToken(t){return(await this.client.get("/auth/validate",{headers:{Authorization:`Bearer ${t}`}})).data}async refreshToken(t){return(await this.client.post("/auth/refresh",{refresh_token:t})).data}async logout(t){await this.client.delete("/auth/logout",{headers:{Authorization:`Bearer ${t}`}})}async updateProfile(t,e){let s=e?{Authorization:`Bearer ${e}`}:{};return(await this.client.put("/user/update-profile",t,{headers:s})).data}async getPlans(t,e){let s=t||this.orgId||"",i=e||this.appId||"";if(t&&!(r=>r?/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(r):!1)(t)){i=t;let r=e||"",a=r?`?user_id=${r}`:"";return(await this.client.get(`/${i}/subscriptions/plans${a}`)).data}return(await this.client.get(`/user/subscription/plans?orgId=${s}&appKey=${i}`)).data}async getSubscriptionStatus(t,e){return(await this.client.get(`/user/subscription/status?appId=${t}`)).data}async getEntitlements(t){return(await this.client.get(`/${t}/subscriptions/entitlements`)).data}async createOrder(t,e){return(await this.client.post("/user/subscription/create-order",t)).data}async createSubscription(t,e){return(await this.client.post(`/${t}/subscriptions/create`,e)).data}async createTopUp(t,e){return(await this.client.post(`/${t}/subscriptions/topup`,e)).data}async getAdsConfig(t,e){return(await this.client.get(`/user/ads/config?orgId=${t}&appKey=${e}`)).data}async claimReward(t){return(await this.client.post("/user/rewards/ad-claim",t)).data}};var l=class{entitlements=[];isPremiumFlag=!1;setState(t,e=[]){this.isPremiumFlag=t,this.entitlements=e}checkPremium(){return this.isPremiumFlag?!0:this.entitlements.some(t=>t.active&&t.tier!=="FREE")}hasFeature(t){return this.isPremiumFlag?!0:this.entitlements.some(e=>e.active&&e.granted_features&&e.granted_features.includes(t))}};var d=class{constructor(t,e){this.api=t;this.appId=e}api;appId;sessionEvents=new Set;async shouldDeduplicate(t){if(t==="onboarding_completed"||t==="first_code_execution"){let e=`mt_dedup_${t}`;return await this.api.storage.getItem(e)==="true"}return t==="paywall_viewed"?this.sessionEvents.has(t):!1}async markTracked(t){if(t==="onboarding_completed"||t==="first_code_execution"){let e=`mt_dedup_${t}`;await this.api.storage.setItem(e,"true")}else t==="paywall_viewed"&&this.sessionEvents.add(t)}track(t,e){(async()=>{await this.shouldDeduplicate(t)||(await this.markTracked(t),await this.capture({event_name:t,payload:e}))})().catch(s=>{console.warn(`[MobTechi Analytics] failed async track for ${t}`,s)})}trackError(t,e,s){(async()=>{await this.capture({event_name:t,is_error:!0,stack_trace:e.stack,metadata:s})})().catch(i=>{console.warn(`[MobTechi Analytics] failed async trackError for ${t}`,i)})}async capture(t){try{await this.api.post("/analytics/capture",{app_id:this.appId,...t})}catch{console.warn(`[MobTechi Analytics] Failed to track event: ${t.event_name}`)}}};var f=class{api;entitlements;analytics;constructor(t){this.api=new u(t),this.entitlements=new l,this.analytics=new d(this.api,t.appId||"unknown")}async login(t){return await this.api.login(t)}async verifyOtp(t){let e=await this.api.verifyOtp(t);return e.data&&e.data.token&&await this.api.setToken(e.data.token),e}async logout(){let t=await this.api.getToken();if(t)try{await this.api.logout(t)}catch{}await this.api.setToken(null),this.entitlements.setState(!1,[])}async syncEntitlements(t){try{let e=await this.api.getEntitlements(t);if(e){let s=!!e.isPremium,i=e.features||[];this.entitlements.setState(s,i)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}};export{d as AnalyticsTracker,l as EntitlementEngine,c as MemoryStorageProvider,f as MobTechi,u as MobTechiClient};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mobtechi/sdk-core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Framework-agnostic core logic and API client for the MobTechi platform",
|
|
5
|
+
"author": "MobTechi",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --minify",
|
|
18
|
+
"dev": "tsup src/index.ts --format cjs,esm --watch --dts",
|
|
19
|
+
"prepublishOnly": "npm run build"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"axios": "^1.6.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "^8.0.0",
|
|
26
|
+
"typescript": "^5.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|