@mobtechi/sdk-core 1.1.3 → 1.1.4

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 CHANGED
@@ -22,7 +22,6 @@ import { MobTechi, MemoryStorageProvider } from '@mobtechi/sdk-core';
22
22
  const mobtechi = new MobTechi({
23
23
  baseUrl: 'https://api.mobtechi.com', // Replace with your environment URL
24
24
  appId: 'your-app-id',
25
- orgId: 'your-org-id', // Optional
26
25
  storage: new MemoryStorageProvider(), // Replace with localStorage/AsyncStorage provider for persistence
27
26
  tokenKey: 'mobtechi_auth_token'
28
27
  });
@@ -40,13 +39,13 @@ Handles user identity, login, OTP verification, and token management automatical
40
39
 
41
40
  ```typescript
42
41
  // 1. Identify User
43
- await mobtechi.api.identify({ identifier: 'user@example.com', app_id: '...', org_id: '...' });
42
+ await mobtechi.api.identify({ identifier: 'user@example.com', app_id: '...'});
44
43
 
45
44
  // 2. Login (Send OTP or Password)
46
- await mobtechi.login({ identifier: 'user@example.com', app_id: '...', org_id: '...' });
45
+ await mobtechi.login({ identifier: 'user@example.com', app_id: '...' });
47
46
 
48
47
  // 3. Verify OTP (Automatically sets the access token upon success)
49
- await mobtechi.verifyOtp({ identifier: 'user@example.com', code: '123456', app_id: '...', org_id: '...' });
48
+ await mobtechi.verifyOtp({ identifier: 'user@example.com', code: '123456', app_id: '...' });
50
49
 
51
50
  // 4. Logout (Clears local token and resets entitlements)
52
51
  await mobtechi.logout();
@@ -84,7 +83,7 @@ Fetch user-specific or app-specific ad configurations and claim rewards.
84
83
  const adsConfig = await mobtechi.api.getAdsConfig('your-org-id', 'your-app-key');
85
84
 
86
85
  // Claim rewards
87
- await mobtechi.api.claimReward({ orgId: '...', appKey: '...', rewardType: '...' });
86
+ await mobtechi.api.claimReward({ appKey: '...', rewardType: '...' });
88
87
  ```
89
88
 
90
89
  ## Advanced Usage
package/dist/index.d.mts CHANGED
@@ -22,7 +22,6 @@ interface MobTechiUser {
22
22
  dob: string | null;
23
23
  preferences: Record<string, any> | null;
24
24
  full_name: string | null;
25
- org_id: string | null;
26
25
  is_premium?: boolean;
27
26
  has_ads?: boolean;
28
27
  flags?: Record<string, any>;
@@ -93,7 +92,6 @@ declare class MemoryStorageProvider implements StorageProvider {
93
92
  interface MobTechiClientOptions {
94
93
  baseUrl: string;
95
94
  appId?: string;
96
- orgId?: string;
97
95
  storage?: StorageProvider;
98
96
  tokenKey?: string;
99
97
  }
@@ -104,8 +102,7 @@ declare class MobTechiClient {
104
102
  private tokenKey;
105
103
  private currentToken;
106
104
  appId?: string;
107
- orgId?: string;
108
- constructor(optionsOrBaseUrl: MobTechiClientOptions | string, appId?: string, orgId?: string, storage?: StorageProvider, tokenKey?: string);
105
+ constructor(optionsOrBaseUrl: MobTechiClientOptions | string, appId?: string, storage?: StorageProvider, tokenKey?: string);
109
106
  setToken(token: string | null): Promise<void>;
110
107
  getToken(): Promise<string | null>;
111
108
  get<T = any>(path: string, config?: any): Promise<{
@@ -130,11 +127,9 @@ declare class MobTechiClient {
130
127
  }>;
131
128
  identify(payload: AuthDto & {
132
129
  app_id: string;
133
- org_id: string;
134
130
  }): Promise<any>;
135
131
  login(payload: AuthDto & {
136
132
  app_id: string;
137
- org_id: string;
138
133
  }): Promise<{
139
134
  status: number;
140
135
  data: any;
@@ -142,7 +137,6 @@ declare class MobTechiClient {
142
137
  register(payload: any): Promise<any>;
143
138
  verifyOtp(payload: VerifyOtpDto & {
144
139
  app_id: string;
145
- org_id: string;
146
140
  }): Promise<{
147
141
  status: number;
148
142
  data: any;
@@ -151,12 +145,11 @@ declare class MobTechiClient {
151
145
  refreshToken(refresh_token: string): Promise<any>;
152
146
  logout(token: string): Promise<void>;
153
147
  updateProfile(payload: any, token?: string): Promise<any>;
154
- getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string, token?: string): Promise<any>;
148
+ getPlans(appKey?: string, token?: string): Promise<any>;
155
149
  getSubscriptionStatus(appKey: string, token?: string): Promise<any>;
156
150
  getEntitlements(appKey: string): Promise<any>;
157
151
  createOrder(payload: {
158
152
  planId: string;
159
- orgId: string;
160
153
  appKey: string;
161
154
  }, token?: string): Promise<any>;
162
155
  createSubscription(appKey: string, payload: {
@@ -165,9 +158,8 @@ declare class MobTechiClient {
165
158
  createTopUp(appKey: string, payload: {
166
159
  credits: number;
167
160
  }): Promise<any>;
168
- getAdsConfig(orgId: string, appKey: string): Promise<any>;
161
+ getAdsConfig(appKey: string): Promise<any>;
169
162
  claimReward(payload: {
170
- orgId: string;
171
163
  appKey: string;
172
164
  rewardType: string;
173
165
  }): Promise<any>;
@@ -233,14 +225,12 @@ declare class MobTechi {
233
225
  */
234
226
  login(payload: AuthDto & {
235
227
  app_id: string;
236
- org_id: string;
237
228
  }): Promise<{
238
229
  status: number;
239
230
  data: any;
240
231
  }>;
241
232
  verifyOtp(payload: VerifyOtpDto & {
242
233
  app_id: string;
243
- org_id: string;
244
234
  }): Promise<{
245
235
  status: number;
246
236
  data: any;
package/dist/index.d.ts CHANGED
@@ -22,7 +22,6 @@ interface MobTechiUser {
22
22
  dob: string | null;
23
23
  preferences: Record<string, any> | null;
24
24
  full_name: string | null;
25
- org_id: string | null;
26
25
  is_premium?: boolean;
27
26
  has_ads?: boolean;
28
27
  flags?: Record<string, any>;
@@ -93,7 +92,6 @@ declare class MemoryStorageProvider implements StorageProvider {
93
92
  interface MobTechiClientOptions {
94
93
  baseUrl: string;
95
94
  appId?: string;
96
- orgId?: string;
97
95
  storage?: StorageProvider;
98
96
  tokenKey?: string;
99
97
  }
@@ -104,8 +102,7 @@ declare class MobTechiClient {
104
102
  private tokenKey;
105
103
  private currentToken;
106
104
  appId?: string;
107
- orgId?: string;
108
- constructor(optionsOrBaseUrl: MobTechiClientOptions | string, appId?: string, orgId?: string, storage?: StorageProvider, tokenKey?: string);
105
+ constructor(optionsOrBaseUrl: MobTechiClientOptions | string, appId?: string, storage?: StorageProvider, tokenKey?: string);
109
106
  setToken(token: string | null): Promise<void>;
110
107
  getToken(): Promise<string | null>;
111
108
  get<T = any>(path: string, config?: any): Promise<{
@@ -130,11 +127,9 @@ declare class MobTechiClient {
130
127
  }>;
131
128
  identify(payload: AuthDto & {
132
129
  app_id: string;
133
- org_id: string;
134
130
  }): Promise<any>;
135
131
  login(payload: AuthDto & {
136
132
  app_id: string;
137
- org_id: string;
138
133
  }): Promise<{
139
134
  status: number;
140
135
  data: any;
@@ -142,7 +137,6 @@ declare class MobTechiClient {
142
137
  register(payload: any): Promise<any>;
143
138
  verifyOtp(payload: VerifyOtpDto & {
144
139
  app_id: string;
145
- org_id: string;
146
140
  }): Promise<{
147
141
  status: number;
148
142
  data: any;
@@ -151,12 +145,11 @@ declare class MobTechiClient {
151
145
  refreshToken(refresh_token: string): Promise<any>;
152
146
  logout(token: string): Promise<void>;
153
147
  updateProfile(payload: any, token?: string): Promise<any>;
154
- getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string, token?: string): Promise<any>;
148
+ getPlans(appKey?: string, token?: string): Promise<any>;
155
149
  getSubscriptionStatus(appKey: string, token?: string): Promise<any>;
156
150
  getEntitlements(appKey: string): Promise<any>;
157
151
  createOrder(payload: {
158
152
  planId: string;
159
- orgId: string;
160
153
  appKey: string;
161
154
  }, token?: string): Promise<any>;
162
155
  createSubscription(appKey: string, payload: {
@@ -165,9 +158,8 @@ declare class MobTechiClient {
165
158
  createTopUp(appKey: string, payload: {
166
159
  credits: number;
167
160
  }): Promise<any>;
168
- getAdsConfig(orgId: string, appKey: string): Promise<any>;
161
+ getAdsConfig(appKey: string): Promise<any>;
169
162
  claimReward(payload: {
170
- orgId: string;
171
163
  appKey: string;
172
164
  rewardType: string;
173
165
  }): Promise<any>;
@@ -233,14 +225,12 @@ declare class MobTechi {
233
225
  */
234
226
  login(payload: AuthDto & {
235
227
  app_id: string;
236
- org_id: string;
237
228
  }): Promise<{
238
229
  status: number;
239
230
  data: any;
240
231
  }>;
241
232
  verifyOtp(payload: VerifyOtpDto & {
242
233
  app_id: string;
243
- org_id: string;
244
234
  }): Promise<{
245
235
  status: number;
246
236
  data: any;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var v=Object.create;var w=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var A=(r,t)=>{for(var e in t)w(r,e,{get:t[e],enumerable:!0})},_=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of P(t))!$.call(r,i)&&i!==e&&w(r,i,{get:()=>t[i],enumerable:!(s=I(t,i))||s.enumerable});return r};var E=(r,t,e)=>(e=r!=null?v(x(r)):{},_(t||!r||!r.__esModule?w(e,"default",{value:r,enumerable:!0}):e,r)),S=r=>_(w({},"__esModule",{value:!0}),r);var D={};A(D,{AnalyticsTracker:()=>h,EntitlementEngine:()=>g,MemoryStorageProvider:()=>d,MobTechi:()=>T,MobTechiClient:()=>p,MobTechiSDK:()=>b});module.exports=S(D);var d=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 p=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,u){let m,o=e,l=s,a=i,y=u;typeof t=="object"&&t!==null?(m=t.baseUrl,o=t.appId,l=t.orgId,a=t.storage,y=t.tokenKey):m=t,this.baseUrl=m,this.appId=o,this.orgId=l,this.storage=a||new d,this.tokenKey=y||"mobtechi_auth_token",this.client=k.default.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...o&&{"x-app-id":o},...l&&{"x-org-id":l}}}),this.client.interceptors.request.use(async n=>{if(!this.currentToken){let c=await this.storage.getItem(this.tokenKey);c&&(this.currentToken=c)}return this.currentToken&&n.headers&&(n.headers.Authorization=`Bearer ${this.currentToken}`),this.currentToken==="guest_access_token"&&(n.adapter=async()=>{let c=n.url||"",f={};return c.includes("/subscription/status")?f={isPremium:!0,tier:"premium",expiresAt:new Date(Date.now()+31536e6).toISOString()}:c.includes("/subscription/plans")?f=[{id:"plan_1",name:"Premium Guest",price:0}]:c.includes("/ads/config")&&(f={enabled:!1}),{data:f,status:200,statusText:"OK",headers:{},config:n,request:{}}}),n})}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,s){let i=t||this.orgId||"",u=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)){u=t;let a=e||"",y=a?`?user_id=${a}`:"";return(await this.client.get(`/${u}/subscriptions/plans${y}`)).data}let o=s?{headers:{Authorization:`Bearer ${s}`}}:{};return(await this.client.get(`/user/subscription/plans?orgId=${i}&appKey=${u}`,o)).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 g=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 h=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 T=class{api;entitlements;analytics;constructor(t){this.api=new p(t),this.entitlements=new g,this.analytics=new h(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),b.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},b={_isPremium:!1,setPremiumUser:r=>{b._isPremium=r},isPremiumUser:()=>b._isPremium};0&&(module.exports={AnalyticsTracker,EntitlementEngine,MemoryStorageProvider,MobTechi,MobTechiClient,MobTechiSDK});
1
+ "use strict";var k=Object.create;var g=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var x=(i,t)=>{for(var e in t)g(i,e,{get:t[e],enumerable:!0})},b=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of v(t))!I.call(i,r)&&r!==e&&g(i,r,{get:()=>t[r],enumerable:!(s=_(t,r))||s.enumerable});return i};var A=(i,t,e)=>(e=i!=null?k(P(i)):{},b(t||!i||!i.__esModule?g(e,"default",{value:i,enumerable:!0}):e,i)),E=i=>b(g({},"__esModule",{value:!0}),i);var S={};x(S,{AnalyticsTracker:()=>l,EntitlementEngine:()=>u,MemoryStorageProvider:()=>o,MobTechi:()=>y,MobTechiClient:()=>c,MobTechiSDK:()=>m});module.exports=E(S);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 T=A(require("axios"));var c=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;constructor(t,e,s,r){let p,d=e,f=s,w=r;typeof t=="object"&&t!==null?(p=t.baseUrl,d=t.appId,f=t.storage,w=t.tokenKey):p=t,this.baseUrl=p,this.appId=d,this.storage=f||new o,this.tokenKey=w||"mobtechi_auth_token",this.client=T.default.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...d&&{"x-app-id":d}}}),this.client.interceptors.request.use(async a=>{if(!this.currentToken){let n=await this.storage.getItem(this.tokenKey);n&&(this.currentToken=n)}return this.currentToken&&a.headers&&(a.headers.Authorization=`Bearer ${this.currentToken}`),this.currentToken==="guest_access_token"&&(a.adapter=async()=>{let n=a.url||"",h={};return n.includes("/subscription/status")?h={isPremium:!0,tier:"premium",expiresAt:new Date(Date.now()+31536e6).toISOString()}:n.includes("/subscription/plans")?h=[{id:"plan_1",name:"Premium Guest",price:0}]:n.includes("/ads/config")&&(h={enabled:!1}),{data:h,status:200,statusText:"OK",headers:{},config:a,request:{}}}),a})}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 r=await this.client.post(t,e,s);return{data:r.data,status:r.status}}async put(t,e,s){let r=await this.client.put(t,e,s);return{data:r.data,status:r.status}}async patch(t,e,s){let r=await this.client.patch(t,e,s);return{data:r.data,status:r.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.appId||"",r=e?{headers:{Authorization:`Bearer ${e}`}}:{};return(await this.client.get(`/user/subscription/plans?appKey=${s}`,r)).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){return(await this.client.get(`/user/ads/config?appKey=${t}`)).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(r=>{console.warn(`[MobTechi Analytics] failed async trackError for ${t}`,r)})}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,r=e.features||[];this.entitlements.setState(s,r),m.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},m={_isPremium:!1,setPremiumUser:i=>{m._isPremium=i},isPremiumUser:()=>m._isPremium};0&&(module.exports={AnalyticsTracker,EntitlementEngine,MemoryStorageProvider,MobTechi,MobTechiClient,MobTechiSDK});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var h=class{store={};getItem(t){return this.store[t]||null}setItem(t,e){this.store[t]=e}removeItem(t){delete this.store[t]}};import T from"axios";var m=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,u){let d,o=e,l=s,r=i,p=u;typeof t=="object"&&t!==null?(d=t.baseUrl,o=t.appId,l=t.orgId,r=t.storage,p=t.tokenKey):d=t,this.baseUrl=d,this.appId=o,this.orgId=l,this.storage=r||new h,this.tokenKey=p||"mobtechi_auth_token",this.client=T.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...o&&{"x-app-id":o},...l&&{"x-org-id":l}}}),this.client.interceptors.request.use(async a=>{if(!this.currentToken){let c=await this.storage.getItem(this.tokenKey);c&&(this.currentToken=c)}return this.currentToken&&a.headers&&(a.headers.Authorization=`Bearer ${this.currentToken}`),this.currentToken==="guest_access_token"&&(a.adapter=async()=>{let c=a.url||"",g={};return c.includes("/subscription/status")?g={isPremium:!0,tier:"premium",expiresAt:new Date(Date.now()+31536e6).toISOString()}:c.includes("/subscription/plans")?g=[{id:"plan_1",name:"Premium Guest",price:0}]:c.includes("/ads/config")&&(g={enabled:!1}),{data:g,status:200,statusText:"OK",headers:{},config:a,request:{}}}),a})}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,s){let i=t||this.orgId||"",u=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)){u=t;let r=e||"",p=r?`?user_id=${r}`:"";return(await this.client.get(`/${u}/subscriptions/plans${p}`)).data}let o=s?{headers:{Authorization:`Bearer ${s}`}}:{};return(await this.client.get(`/user/subscription/plans?orgId=${i}&appKey=${u}`,o)).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 y=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 f=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 b=class{api;entitlements;analytics;constructor(t){this.api=new m(t),this.entitlements=new y,this.analytics=new f(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),w.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},w={_isPremium:!1,setPremiumUser:n=>{w._isPremium=n},isPremiumUser:()=>w._isPremium};export{f as AnalyticsTracker,y as EntitlementEngine,h as MemoryStorageProvider,b as MobTechi,m as MobTechiClient,w as MobTechiSDK};
1
+ var l=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 p=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;constructor(t,e,s,r){let o,c=e,m=s,y=r;typeof t=="object"&&t!==null?(o=t.baseUrl,c=t.appId,m=t.storage,y=t.tokenKey):o=t,this.baseUrl=o,this.appId=c,this.storage=m||new l,this.tokenKey=y||"mobtechi_auth_token",this.client=w.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...c&&{"x-app-id":c}}}),this.client.interceptors.request.use(async a=>{if(!this.currentToken){let n=await this.storage.getItem(this.tokenKey);n&&(this.currentToken=n)}return this.currentToken&&a.headers&&(a.headers.Authorization=`Bearer ${this.currentToken}`),this.currentToken==="guest_access_token"&&(a.adapter=async()=>{let n=a.url||"",u={};return n.includes("/subscription/status")?u={isPremium:!0,tier:"premium",expiresAt:new Date(Date.now()+31536e6).toISOString()}:n.includes("/subscription/plans")?u=[{id:"plan_1",name:"Premium Guest",price:0}]:n.includes("/ads/config")&&(u={enabled:!1}),{data:u,status:200,statusText:"OK",headers:{},config:a,request:{}}}),a})}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 r=await this.client.post(t,e,s);return{data:r.data,status:r.status}}async put(t,e,s){let r=await this.client.put(t,e,s);return{data:r.data,status:r.status}}async patch(t,e,s){let r=await this.client.patch(t,e,s);return{data:r.data,status:r.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.appId||"",r=e?{headers:{Authorization:`Bearer ${e}`}}:{};return(await this.client.get(`/user/subscription/plans?appKey=${s}`,r)).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){return(await this.client.get(`/user/ads/config?appKey=${t}`)).data}async claimReward(t){return(await this.client.post("/user/rewards/ad-claim",t)).data}};var d=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 h=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(r=>{console.warn(`[MobTechi Analytics] failed async trackError for ${t}`,r)})}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 p(t),this.entitlements=new d,this.analytics=new h(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,r=e.features||[];this.entitlements.setState(s,r),g.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},g={_isPremium:!1,setPremiumUser:i=>{g._isPremium=i},isPremiumUser:()=>g._isPremium};export{h as AnalyticsTracker,d as EntitlementEngine,l as MemoryStorageProvider,f as MobTechi,p as MobTechiClient,g as MobTechiSDK};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobtechi/sdk-core",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Framework-agnostic core logic and API client for the MobTechi platform",
5
5
  "author": "MobTechi",
6
6
  "license": "MIT",