@mobtechi/sdk-core 1.1.1 → 1.1.2

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 CHANGED
@@ -151,7 +151,7 @@ declare class MobTechiClient {
151
151
  refreshToken(refresh_token: string): Promise<any>;
152
152
  logout(token: string): Promise<void>;
153
153
  updateProfile(payload: any, token?: string): Promise<any>;
154
- getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string): Promise<any>;
154
+ getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string, token?: string): Promise<any>;
155
155
  getSubscriptionStatus(appKey: string, token?: string): Promise<any>;
156
156
  getEntitlements(appKey: string): Promise<any>;
157
157
  createOrder(payload: {
package/dist/index.d.ts CHANGED
@@ -151,7 +151,7 @@ declare class MobTechiClient {
151
151
  refreshToken(refresh_token: string): Promise<any>;
152
152
  logout(token: string): Promise<void>;
153
153
  updateProfile(payload: any, token?: string): Promise<any>;
154
- getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string): Promise<any>;
154
+ getPlans(orgIdOrAppKey?: string, appKeyOrUserId?: string, token?: string): Promise<any>;
155
155
  getSubscriptionStatus(appKey: string, token?: string): Promise<any>;
156
156
  getEntitlements(appKey: string): Promise<any>;
157
157
  createOrder(payload: {
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var _=Object.create;var p=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var E=(r,t)=>{for(var e in t)p(r,e,{get:t[e],enumerable:!0})},T=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of I(t))!x.call(r,i)&&i!==e&&p(r,i,{get:()=>t[i],enumerable:!(s=v(t,i))||s.enumerable});return r};var $=(r,t,e)=>(e=r!=null?_(P(r)):{},T(t||!r||!r.__esModule?p(e,"default",{value:r,enumerable:!0}):e,r)),A=r=>T(p({},"__esModule",{value:!0}),r);var S={};E(S,{AnalyticsTracker:()=>l,EntitlementEngine:()=>u,MemoryStorageProvider:()=>o,MobTechi:()=>y,MobTechiClient:()=>c,MobTechiSDK:()=>g});module.exports=A(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 k=$(require("axios"));var c=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,f){let d,a=e,n=s,h=i,w=f;typeof t=="object"&&t!==null?(d=t.baseUrl,a=t.appId,n=t.orgId,h=t.storage,w=t.tokenKey):d=t,this.baseUrl=d,this.appId=a,this.orgId=n,this.storage=h||new o,this.tokenKey=w||"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 m=>{if(!this.currentToken){let b=await this.storage.getItem(this.tokenKey);b&&(this.currentToken=b)}return this.currentToken&&m.headers&&(m.headers.Authorization=`Bearer ${this.currentToken}`),m})}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),g.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},g={_isPremium:!1,setPremiumUser:r=>{g._isPremium=r},isPremiumUser:()=>g._isPremium};0&&(module.exports={AnalyticsTracker,EntitlementEngine,MemoryStorageProvider,MobTechi,MobTechiClient,MobTechiSDK});
1
+ "use strict";var k=Object.create;var y=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var $=(r,t)=>{for(var e in t)y(r,e,{get:t[e],enumerable:!0})},T=(r,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of I(t))!x.call(r,i)&&i!==e&&y(r,i,{get:()=>t[i],enumerable:!(s=v(t,i))||s.enumerable});return r};var E=(r,t,e)=>(e=r!=null?k(P(r)):{},T(t||!r||!r.__esModule?y(e,"default",{value:r,enumerable:!0}):e,r)),A=r=>T(y({},"__esModule",{value:!0}),r);var S={};$(S,{AnalyticsTracker:()=>p,EntitlementEngine:()=>d,MemoryStorageProvider:()=>u,MobTechi:()=>w,MobTechiClient:()=>l,MobTechiSDK:()=>f});module.exports=A(S);var u=class{store={};getItem(t){return this.store[t]||null}setItem(t,e){this.store[t]=e}removeItem(t){delete this.store[t]}};var _=E(require("axios"));var l=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,o){let g,n=e,c=s,a=i,h=o;typeof t=="object"&&t!==null?(g=t.baseUrl,n=t.appId,c=t.orgId,a=t.storage,h=t.tokenKey):g=t,this.baseUrl=g,this.appId=n,this.orgId=c,this.storage=a||new u,this.tokenKey=h||"mobtechi_auth_token",this.client=_.default.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...n&&{"x-app-id":n},...c&&{"x-org-id":c}}}),this.client.interceptors.request.use(async m=>{if(!this.currentToken){let b=await this.storage.getItem(this.tokenKey);b&&(this.currentToken=b)}return this.currentToken&&m.headers&&(m.headers.Authorization=`Bearer ${this.currentToken}`),m})}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||"",o=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)){o=t;let a=e||"",h=a?`?user_id=${a}`:"";return(await this.client.get(`/${o}/subscriptions/plans${h}`)).data}let n=s?{headers:{Authorization:`Bearer ${s}`}}:{};return(await this.client.get(`/user/subscription/plans?orgId=${i}&appKey=${o}`,n)).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 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 p=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 w=class{api;entitlements;analytics;constructor(t){this.api=new l(t),this.entitlements=new d,this.analytics=new p(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),f.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},f={_isPremium:!1,setPremiumUser:r=>{f._isPremium=r},isPremiumUser:()=>f._isPremium};0&&(module.exports={AnalyticsTracker,EntitlementEngine,MemoryStorageProvider,MobTechi,MobTechiClient,MobTechiSDK});
package/dist/index.mjs CHANGED
@@ -1 +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 b from"axios";var u=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,m){let o,r=e,n=s,p=i,y=m;typeof t=="object"&&t!==null?(o=t.baseUrl,r=t.appId,n=t.orgId,p=t.storage,y=t.tokenKey):o=t,this.baseUrl=o,this.appId=r,this.orgId=n,this.storage=p||new c,this.tokenKey=y||"mobtechi_auth_token",this.client=b.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...r&&{"x-app-id":r},...n&&{"x-org-id":n}}}),this.client.interceptors.request.use(async g=>{if(!this.currentToken){let f=await this.storage.getItem(this.tokenKey);f&&(this.currentToken=f)}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||"",n=r?`?user_id=${r}`:"";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 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 w=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),h.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},h={_isPremium:!1,setPremiumUser:a=>{h._isPremium=a},isPremiumUser:()=>h._isPremium};export{d as AnalyticsTracker,l as EntitlementEngine,c as MemoryStorageProvider,w as MobTechi,u as MobTechiClient,h as MobTechiSDK};
1
+ var p=class{store={};getItem(t){return this.store[t]||null}setItem(t,e){this.store[t]=e}removeItem(t){delete this.store[t]}};import b from"axios";var g=class{client;baseUrl;storage;tokenKey;currentToken=null;appId;orgId;constructor(t,e,s,i,o){let u,n=e,c=s,r=i,l=o;typeof t=="object"&&t!==null?(u=t.baseUrl,n=t.appId,c=t.orgId,r=t.storage,l=t.tokenKey):u=t,this.baseUrl=u,this.appId=n,this.orgId=c,this.storage=r||new p,this.tokenKey=l||"mobtechi_auth_token",this.client=b.create({baseURL:this.baseUrl,headers:{"Content-Type":"application/json",...n&&{"x-app-id":n},...c&&{"x-org-id":c}}}),this.client.interceptors.request.use(async d=>{if(!this.currentToken){let f=await this.storage.getItem(this.tokenKey);f&&(this.currentToken=f)}return this.currentToken&&d.headers&&(d.headers.Authorization=`Bearer ${this.currentToken}`),d})}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||"",o=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)){o=t;let r=e||"",l=r?`?user_id=${r}`:"";return(await this.client.get(`/${o}/subscriptions/plans${l}`)).data}let n=s?{headers:{Authorization:`Bearer ${s}`}}:{};return(await this.client.get(`/user/subscription/plans?orgId=${i}&appKey=${o}`,n)).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 h=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 m=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 w=class{api;entitlements;analytics;constructor(t){this.api=new g(t),this.entitlements=new h,this.analytics=new m(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),y.setPremiumUser(s)}return e}catch(e){throw console.error("Failed to sync entitlements",e),e}}},y={_isPremium:!1,setPremiumUser:a=>{y._isPremium=a},isPremiumUser:()=>y._isPremium};export{m as AnalyticsTracker,h as EntitlementEngine,p as MemoryStorageProvider,w as MobTechi,g as MobTechiClient,y as MobTechiSDK};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobtechi/sdk-core",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Framework-agnostic core logic and API client for the MobTechi platform",
5
5
  "author": "MobTechi",
6
6
  "license": "MIT",