@cloudparse/up-miniapps-sdk 0.1.5 → 0.1.6
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.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.d.mts +6 -12
- package/dist/index.d.ts +6 -12
- package/dist/index.js +53 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var MiniAppSDK=(()=>{var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var h=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of y(e))!T.call(n,r)&&r!==t&&c(n,r,{get:()=>e[r],enumerable:!(i=m(e,r))||i.enumerable});return n};var E=n=>I(c({},"__esModule",{value:!0}),n);var O={};h(O,{MiniAppSDK:()=>d,UIEvent:()=>b,default:()=>w,sdk:()=>l});var a=class{callbacks=new Map;eventListeners=new Map;constructor(){if(typeof window<"u"){let e=Object.freeze({onNativeMessage:t=>this.handleNativeMessage(t)});Object.defineProperty(window,"__MiniAppBridge",{value:e,writable:!1
|
|
1
|
+
"use strict";var MiniAppSDK=(()=>{var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var h=(n,e)=>{for(var t in e)c(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of y(e))!T.call(n,r)&&r!==t&&c(n,r,{get:()=>e[r],enumerable:!(i=m(e,r))||i.enumerable});return n};var E=n=>I(c({},"__esModule",{value:!0}),n);var O={};h(O,{MiniAppSDK:()=>d,UIEvent:()=>b,default:()=>w,sdk:()=>l});var a=class{callbacks=new Map;eventListeners=new Map;constructor(){if(typeof window<"u"){let e=Object.freeze({onNativeMessage:t=>this.handleNativeMessage(t)});Object.defineProperty(window,"__MiniAppBridge",{configurable:!1,value:e,writable:!1}),window.addEventListener("message",t=>{if(t.data)try{let i=typeof t.data=="string"?JSON.parse(t.data):t.data;i&&typeof i=="object"&&(i.callbackId||i.event)&&this.handleNativeMessage(i)}catch{}})}}on(e,t){let i=this.eventListeners.get(e);return i||(i=[],this.eventListeners.set(e,i)),i.push(t),()=>this.off(e,t)}off(e,t){let i=this.eventListeners.get(e);i&&this.eventListeners.set(e,i.filter(r=>r!==t))}send(e,t,i=3e4){return new Promise((r,o)=>{let s=`${e}_${Date.now()}_${Math.random().toString(36).substring(2,9)}`,u=setTimeout(()=>{this.callbacks.has(s)&&(this.callbacks.delete(s),o(new Error(`Bridge request timeout: ${e}`)))},i);this.callbacks.set(s,{reject:o,resolve:r,timeout:u});let f={callbackId:s,payload:t,type:e},g=window;g.ReactNativeWebView?.postMessage?g.ReactNativeWebView.postMessage(JSON.stringify(f)):(clearTimeout(u),this.callbacks.delete(s),o(new Error("Bridge not available")))})}handleNativeMessage(e){if(!e||typeof e!="object")return;let t=e.callbackId;if(t&&typeof t=="string"){let r=this.callbacks.get(t);if(r){clearTimeout(r.timeout);let{resolve:o,reject:s}=r;e.success===!1||e.error?s(e.error||"Unknown error"):o(e.value??e.payload??e),this.callbacks.delete(t);return}}let i=e.event;if(i&&typeof i=="string"){let r=this.eventListeners.get(i);if(r)for(let o of r)try{o(e.payload||e.value)}catch(s){console.error(`Error in event listener for ${i}:`,s)}}}};function p(n){let e=Object.getOwnPropertyNames(n);for(let t of e){let i=n[t];i&&typeof i=="object"&&!Object.isFrozen(i)&&!(i instanceof a)&&p(i)}return Object.freeze(n)}var d=class{bridge;storage=Object.freeze({get:e=>this.bridge.send("STORAGE_GET",{key:e}),getAll:()=>this.bridge.send("STORAGE_GET_ALL"),set:(e,t)=>this.bridge.send("STORAGE_SET",{key:e,value:t})});secureStore=Object.freeze({get:e=>this.bridge.send("SECURE_GET",{key:e}),set:(e,t)=>this.bridge.send("SECURE_SET",{key:e,value:t})});database=Object.freeze({getUserData:()=>this.bridge.send("DATABASE_GET_USER_DATA"),setUserData:e=>this.bridge.send("DATABASE_SET_USER_DATA",{data:e})});location=Object.freeze({getCurrentPosition:()=>this.bridge.send("GET_LOCATION")});user=Object.freeze({getProfile:e=>this.bridge.send("GET_USER_PROFILE",{fields:e})});permission=Object.freeze({request:((e,t)=>this.bridge.send("REQUEST_PERMISSION",{fields:t,type:e}))});payment=Object.freeze({request:e=>this.bridge.send("PAYMENT_REQUEST",e)});activity=Object.freeze({start:(e,t,i)=>this.bridge.send("START_ACTIVITY",{id:e,status:i,title:t})});haptic=Object.freeze({trigger:e=>this.bridge.send("TRIGGER_HAPTIC",{style:e})});network=Object.freeze({request:e=>this.bridge.send("NETWORK_REQUEST",e)});fidelity=Object.freeze({getFidelityBalance:()=>this.bridge.send("GET_FIDELITY_BALANCE"),getFidelityHistory:e=>this.bridge.send("GET_FIDELITY_HISTORY",e),spendFPoints:e=>this.bridge.send("SPEND_FPOINTS",{intentUuid:e})});ui=Object.freeze({exit:()=>this.bridge.send("EXIT"),setScrollConfig:e=>this.bridge.send("SET_SCROLL_CONFIG",e)});debug=Object.freeze({log:(...e)=>this.bridge.send("DEBUG_LOG",{message:e})});constructor(){this.bridge=new a,this.initialize=this.initialize.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this)}initialize(e){return this.bridge.send("INITIALIZE",e)}on(e,t){return this.bridge.on(e,t)}off(e,t){this.bridge.off(e,t)}},l=p(new d);var b=(t=>(t.TOP_SCROLL_MORE="TOP_SCROLL_MORE",t.BOTTOM_SCROLL_MORE="BOTTOM_SCROLL_MORE",t))(b||{});var w=l;return E(O);})();
|
|
2
2
|
//# sourceMappingURL=index.browser.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/bridge.ts","../src/sdk.ts","../src/types/types.ts"],"sourcesContent":["export { MiniAppSDK, sdk } from \"@miniapps-sdk/sdk\";\nexport * from \"@miniapps-sdk/types\";\n\nimport { sdk } from \"@miniapps-sdk/sdk\";\nexport default sdk;\n","import type { IBridgeEnvelope } from \"@miniapps-sdk/types\";\n\n/**\n * The Bridge handles low-level communication between the Mini-App WebView\n * and the Native Host Shell (iOS/Android).\n *\n * It manages asynchronous request-response cycles via callbacks and\n * supports subscription to pushed events from the native environment.\n */\nexport class Bridge {\n private callbacks = new Map<\n string,\n {\n resolve: (val: unknown) => void;\n reject: (err: unknown) => void;\n timeout: ReturnType<typeof setTimeout>;\n }\n >();\n private eventListeners = new Map<string, ((data: unknown) => void)[]>();\n\n /**\n * Registers a global listener for messages coming from the native shell.\n * Also listens for standard browser `message` events to support multiple\n * communication channels (e.g., React Native WebView postMessage).\n */\n constructor() {\n if (typeof window !== \"undefined\") {\n const bridgeReceiver = Object.freeze({\n onNativeMessage: (envelope: IBridgeEnvelope) =>\n this.handleNativeMessage(envelope),\n });\n\n // Use defineProperty to prevent re-assignment or deletion of the bridge\n Object.defineProperty(window, \"__MiniAppBridge\", {\n value: bridgeReceiver,\n writable: false,\n configurable: false,\n });\n\n window.addEventListener(\"message\", (event) => {\n // SECURITY: Filter events. If inside a mobile shell, the origin of native postMessage\n // varies by platform (e.g., file://, or specific app schemes).\n // For production, this should be restricted to the expected host origin.\n if (!event.data) return;\n\n try {\n const data =\n typeof event.data === \"string\"\n ? JSON.parse(event.data)\n : event.data;\n\n // SECURITY: Basic envelope validation\n if (data && typeof data === \"object\" && (data.callbackId || data.event)) {\n this.handleNativeMessage(data);\n }\n } catch (_e) {\n // Ignore non-JSON or malformed messages\n }\n });\n }\n }\n\n /**\n * Internal handler for all incoming messages from the native shell.\n * Matches incoming payloads to either pending callbacks or event listeners.\n *\n * @internal\n * @param envelope The message envelope received from native code.\n */\n private handleNativeMessage(envelope: IBridgeEnvelope) {\n if (!envelope || typeof envelope !== \"object\") return;\n\n // 1. Handle Response Callbacks\n const callbackId = envelope.callbackId;\n if (callbackId && typeof callbackId === \"string\") {\n const callback = this.callbacks.get(callbackId);\n if (callback) {\n clearTimeout(callback.timeout);\n const { resolve, reject } = callback;\n\n if (envelope.success === false || envelope.error) {\n reject(envelope.error || \"Unknown error\");\n } else {\n resolve(envelope.value ?? envelope.payload ?? envelope);\n }\n\n this.callbacks.delete(callbackId);\n return;\n }\n }\n\n // 2. Handle Pushed Events\n const eventName = envelope.event;\n if (eventName && typeof eventName === \"string\") {\n const listeners = this.eventListeners.get(eventName);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(envelope.payload || envelope.value);\n } catch (e) {\n console.error(`Error in event listener for ${eventName}:`, e);\n }\n }\n }\n }\n }\n\n /**\n * Subscribes to a pushed event from the native shell.\n *\n * @param event The event name to listen for.\n * @param callback Function to execute when the event occurs.\n * @returns An unsubscription function.\n */\n public on(event: string, callback: (data: unknown) => void) {\n let listeners = this.eventListeners.get(event);\n if (!listeners) {\n listeners = [];\n this.eventListeners.set(event, listeners);\n }\n listeners.push(callback);\n return () => this.off(event, callback);\n }\n\n /**\n * Unsubscribes a specific callback from an event.\n *\n * @param event The event name.\n * @param callback The callback function to remove.\n */\n public off(event: string, callback: (data: unknown) => void) {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n this.eventListeners.set(\n event,\n listeners.filter((cb) => cb !== callback),\n );\n }\n\n /**\n * Sends a message to the native shell and waits for a response.\n *\n * @template T The expected response type.\n * @param type The action type (e.g., \"GET_LOCATION\").\n * @param payload Data associated with the action.\n * @param timeoutMs Time in milliseconds to wait for a response before rejecting.\n * @returns A promise that resolves with the native response.\n */\n public send<T = unknown>(\n type: string,\n payload?: unknown,\n timeoutMs = 30000,\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n const callbackId = `${type}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n\n const timeout = setTimeout(() => {\n if (this.callbacks.has(callbackId)) {\n this.callbacks.delete(callbackId);\n reject(new Error(`Bridge request timeout: ${type}`));\n }\n }, timeoutMs);\n\n this.callbacks.set(callbackId, {\n reject,\n resolve: resolve as (val: unknown) => void,\n timeout,\n });\n\n const message = {\n callbackId,\n payload,\n type,\n };\n\n const win = window as unknown as {\n ReactNativeWebView?: { postMessage: (msg: string) => void };\n };\n\n if (win.ReactNativeWebView?.postMessage) {\n win.ReactNativeWebView.postMessage(JSON.stringify(message));\n } else {\n clearTimeout(timeout);\n this.callbacks.delete(callbackId);\n reject(new Error(\"Bridge not available\"));\n }\n });\n }\n}\n","import { Bridge } from \"@miniapps-sdk/bridge\";\nimport type {\n HapticStyleType,\n IFidelityBalance,\n IFidelityHistoryParams,\n IFidelityTransaction,\n IInitializationOptions,\n IInitializationResponse,\n ILocationData,\n INetworkOptions,\n INetworkResponse,\n IPaymentRequest,\n IUserProfile,\n ScrollConfig,\n SDKEvent,\n} from \"@miniapps-sdk/types/types\";\n\n/**\n * Deep freezes an object and its nested properties.\n * @param obj The object to freeze.\n * @returns The frozen object.\n */\nfunction deepFreeze<T extends object>(obj: T): T {\n // Retrieve the property names defined on obj\n const propNames = Object.getOwnPropertyNames(obj);\n\n // Freeze properties before freezing self\n for (const name of propNames) {\n const value = (obj as Record<string, unknown>)[name];\n\n if (\n value &&\n typeof value === \"object\" &&\n !Object.isFrozen(value) &&\n // Skip freezing of native objects or circular refs if any (though not expected here)\n !(value instanceof Bridge)\n ) {\n deepFreeze(value as object);\n }\n }\n\n return Object.freeze(obj);\n}\n\n/**\n * Main SDK for UP Mini-Apps.\n * Provides access to native device features, storage, identity, and shell UI.\n */\nexport class MiniAppSDK {\n private bridge: Bridge;\n\n constructor() {\n this.bridge = new Bridge();\n\n // Bind methods to this instance to preserve context if pulled out\n this.initialize = this.initialize.bind(this);\n this.on = this.on.bind(this);\n this.off = this.off.bind(this);\n }\n\n /**\n * The starting point for the Mini-App. Must be called before any other SDK methods.\n * @param options The options to provide to the shell app\n */\n public initialize(\n options: IInitializationOptions,\n ): Promise<IInitializationResponse> {\n return this.bridge.send(\"INITIALIZE\", options);\n }\n\n /**\n * Local SQLite Storage.\n * Data is persisted on the device and is isolated per Mini-App.\n */\n public readonly storage = Object.freeze({\n /** Retrieves a value by key. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"STORAGE_GET\", { key }),\n /** Retrieves all key-value pairs stored for this Mini-App. */\n getAll: (): Promise<Record<string, string>> =>\n this.bridge.send(\"STORAGE_GET_ALL\"),\n /** Sets a value for a specific key. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"STORAGE_SET\", { key, value }),\n });\n\n /**\n * Hardware-level Secure Storage.\n * Data is stored in the device's secure enclave (Keychain/Keystore) and is isolated per Mini-App.\n */\n public readonly secureStore = Object.freeze({\n /** Retrieves a value by key from secure storage. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"SECURE_GET\", { key }),\n /** Sets a value for a specific key in secure storage. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"SECURE_SET\", { key, value }),\n });\n\n /**\n * Database Storage.\n * Access to user-app specific persistent database storage.\n */\n public readonly database = Object.freeze({\n /** Retrieves the user data stored in the backend database. */\n getUserData: <T = unknown>(): Promise<T> =>\n this.bridge.send<T>(\"DATABASE_GET_USER_DATA\"),\n /** Updates the user data stored in the backend database. */\n setUserData: <T = unknown>(data: T): Promise<void> =>\n this.bridge.send<void>(\"DATABASE_SET_USER_DATA\", { data }),\n });\n\n /**\n * Device Location services.\n */\n public readonly location = Object.freeze({\n /** Retrieves the current GPS position of the device. */\n getCurrentPosition: (): Promise<ILocationData> =>\n this.bridge.send(\"GET_LOCATION\"),\n });\n\n /**\n * Identity & Profile management.\n */\n public readonly user = Object.freeze({\n /**\n * Fetch user profile data.\n * @param fields Optional list of specific fields to retrieve (e.g., ['fullName', 'username']).\n */\n getProfile: <T extends keyof IUserProfile>(\n fields?: T[],\n ): Promise<Partial<IUserProfile>> =>\n this.bridge.send(\"GET_USER_PROFILE\", { fields }),\n });\n\n /**\n * Explicit Permission Management.\n * Allows requesting access to sensitive device features or user data.\n */\n public readonly permission = Object.freeze({\n /**\n * Explicitly request access to sensitive data.\n * @param type The type of permission to request ('location' or 'profile').\n * @param fields If requesting 'profile', the specific fields required.\n */\n request: ((type: \"location\" | \"profile\", fields?: string[]) => {\n return this.bridge.send(\"REQUEST_PERMISSION\", { fields, type });\n }) as {\n (type: \"location\"): Promise<boolean>;\n (type: \"profile\", fields: (keyof IUserProfile)[]): Promise<boolean>;\n },\n });\n\n /**\n * Payments integration.\n */\n public readonly payment = Object.freeze({\n /**\n * Triggers the native payment flow.\n * @param payload Amount, currency, and itemized list for the payment.\n */\n request: (\n payload: IPaymentRequest,\n ): Promise<{ success: true; transactionId: string }> =>\n this.bridge.send(\"PAYMENT_REQUEST\", payload),\n });\n\n /**\n * Live Activities & Notifications.\n * Allows the Mini-App to display real-time updates in the host shell.\n */\n public readonly activity = Object.freeze({\n /**\n * Starts a new live activity.\n * @param id Unique identifier for the activity.\n * @param title Display title for the activity.\n * @param status Initial status message.\n */\n start: (id: string, title: string, status: string): Promise<void> =>\n this.bridge.send(\"START_ACTIVITY\", { id, status, title }),\n });\n\n /**\n * Haptic feedback.\n */\n public readonly haptic = Object.freeze({\n /**\n * Triggers a haptic vibration on the device.\n * @param style The style of haptic feedback (e.g., 'light', 'medium', 'heavy', 'success', 'warning', 'error').\n */\n trigger: (style: HapticStyleType): Promise<void> =>\n this.bridge.send(\"TRIGGER_HAPTIC\", { style }),\n });\n\n /**\n * Network Proxy.\n * Allows the Mini-App to make network requests through the host shell to bypass CORS or use host-level authentication.\n */\n public readonly network = Object.freeze({\n /**\n * Performs a network request via the host shell.\n * @param options Request method, URL, headers, and body.\n */\n request: (options: INetworkOptions): Promise<INetworkResponse> =>\n this.bridge.send(\"NETWORK_REQUEST\", options),\n });\n\n /**\n * Fidelity & Rewards program integration.\n */\n public readonly fidelity = Object.freeze({\n /** Returns current fidelity balance. */\n getFidelityBalance: (): Promise<IFidelityBalance> =>\n this.bridge.send(\"GET_FIDELITY_BALANCE\"),\n /**\n * Retrieves fidelity transaction history.\n * @param params Filtering and pagination parameters.\n */\n getFidelityHistory: (\n params?: IFidelityHistoryParams,\n ): Promise<IFidelityTransaction[]> =>\n this.bridge.send(\"GET_FIDELITY_HISTORY\", params),\n /**\n * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.\n * @param intentUuid UUID generated by your backend for the transaction.\n */\n spendFPoints: (\n intentUuid: string,\n ): Promise<{ success: boolean; transactionId: string }> =>\n this.bridge.send(\"SPEND_FPOINTS\", { intentUuid }),\n });\n\n /**\n * UI and Navigation controls.\n */\n public readonly ui = Object.freeze({\n /** Closes the Mini-App and returns to the host shell. */\n exit: (): Promise<void> => this.bridge.send(\"EXIT\"),\n /**\n * Configures native scroll behaviors like Pull-to-Refresh and Infinite Scroll.\n * @param config Scroll configuration for top/bottom detection.\n */\n setScrollConfig: (config: ScrollConfig): Promise<void> =>\n this.bridge.send(\"SET_SCROLL_CONFIG\", config),\n });\n\n /**\n * Debug controls\n */\n public readonly debug = Object.freeze({\n /**\n * Log to the shell app\n * @param message\n */\n log: (...message: unknown[]) => this.bridge.send(\"DEBUG_LOG\", { message }),\n });\n\n /**\n * Registers a callback for a specific event from the native shell.\n * @param event The name of the event to listen for.\n * @param callback The function to execute when the event is triggered.\n * @returns A function to unregister the listener.\n */\n public on(event: SDKEvent, callback: (data: unknown) => void) {\n return this.bridge.on(event as string, callback);\n }\n\n /**\n * Unregisters a previously registered event listener.\n * @param event The name of the event.\n * @param callback The callback function to remove.\n */\n public off(event: SDKEvent, callback: (data: unknown) => void) {\n this.bridge.off(event as string, callback);\n }\n}\n\n/**\n * Singleton instance of the MiniAppSDK.\n * Frozen to prevent tampering.\n */\nexport const sdk = deepFreeze(new MiniAppSDK());\n","/**\n * UP Mini-App SDK Types\n */\n\n/**\n * Represents the user's profile information.\n */\nexport interface IUserProfile {\n /** Unique identifier for the user. */\n uuid: string;\n /** Full legal name of the user. */\n fullName: string;\n /** Primary email address. */\n email: string;\n /** Chosen username within the UP ecosystem. */\n username: string;\n /** ISO country code (e.g., \"FR\", \"US\"). */\n countryCode: string;\n /** Phone number without country code. */\n localNumber: string;\n}\n\n/**\n * Geographic location data.\n */\nexport interface ILocationData {\n coords: {\n /** Latitude in decimal degrees. */\n latitude: number;\n /** Longitude in decimal degrees. */\n longitude: number;\n /** Altitude in meters above the WGS 84 reference ellipsoid, or null if not available. */\n altitude: number | null;\n /** Accuracy of the latitude and longitude properties in meters. */\n accuracy: number | null;\n /** Accuracy of the altitude property in meters. */\n altitudeAccuracy: number | null;\n /** The direction in which the device is traveling, in degrees (0-360). */\n heading: number | null;\n /** The velocity of the device in meters per second. */\n speed: number | null;\n };\n /** The time at which the location was retrieved (Unix timestamp). */\n timestamp: number;\n}\n\n/**\n * Request payload for triggering a payment flow.\n */\nexport interface IPaymentRequest {\n /** The specific amount to charge. */\n amount: number;\n /** ISO currency code (e.g., \"EUR\", \"USD\"). */\n currency: string;\n /** Total amount including taxes/fees. */\n total: number;\n /** Itemized breakdown of the purchase. */\n items: Array<{\n /** Name or description of the item. */\n item: string;\n /** Price per unit. */\n price?: number;\n /** Number of units. */\n quantity?: number;\n }>;\n}\n\n/**\n * Style of haptic feedback.\n */\nexport type HapticStyleType =\n | \"light\"\n | \"medium\"\n | \"heavy\"\n | \"rigid\"\n | \"soft\"\n | \"success\"\n | \"warning\"\n | \"error\";\n\n/**\n * Network Proxy Types\n */\n\n/**\n * The HTTP method to use as request method\n */\nexport type NetworkMethodType = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\n/**\n * Configuration for network proxy requests.\n */\nexport interface INetworkOptions {\n /** Full URL for the request. */\n url: string;\n /** HTTP method to use. */\n method: NetworkMethodType;\n /** Request body for POST/PUT/PATCH. */\n body?: unknown;\n /** Custom HTTP headers. */\n headers?: Record<string, string>;\n}\n\n/**\n * Response from a network proxy request.\n */\nexport interface INetworkResponse<T = unknown> {\n /** HTTP status code. */\n status: number;\n /** Response data payload. */\n data: T;\n /** Response headers. */\n headers: Headers;\n}\n\n/**\n * Fidelity & Rewards Types\n */\n\n/**\n * Fidelity program balance information.\n */\nexport interface IFidelityBalance {\n /** Current point or currency balance. */\n balance: number;\n /** Name or symbol of the fidelity currency (e.g., \"FPoints\"). */\n currency: string;\n}\n\n/**\n * Parameters for retrieving fidelity transaction history.\n */\nexport interface IFidelityHistoryParams {\n /** Maximum number of records to return. */\n limit?: number;\n\n /** Cursor for pagination; null for the first page. */\n cursor?: string | null;\n}\n\n/** Type of transaction: credit (add) or debit (remove). */\nexport type FidelityTransactionTypeType = \"credit\" | \"debit\";\n\n/**\n * A single fidelity program transaction.\n */\nexport interface IFidelityTransaction {\n /** Unique identifier for the transaction. */\n id: string;\n /** Amount of the transaction. */\n amount: number;\n /** Human-readable description. */\n description: string;\n /** ISO 8601 date string. */\n date: string;\n /** Type of transaction */\n type: FidelityTransactionTypeType;\n}\n\n/**\n * The initialization options required to set up the Mini-App SDK.\n */\nexport type IInitializationOptions = {};\n\n/**\n * The post initialization response\n */\nexport interface IInitializationResponse<\n Env extends Record<string, unknown> = Record<string, unknown>,\n UserData extends Record<string, unknown> = Record<string, unknown>,\n Params extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** The name of the mini app */\n name: string;\n /** The uuid of the mini app */\n uuid: string;\n /** The description of the mini app */\n description: string;\n /** The authors of the mini app */\n authors?: string;\n /** The current version in the registry */\n version?: string;\n /** The scoped profile based on the requested fields during initialization or the getUserProfile call */\n profile: Partial<IUserProfile | null>;\n /** The environment variables defined for the mini app in the shell's backend */\n env: Env;\n /** The user data passed during the initialization or the setUserData call */\n userData: UserData;\n /** The params passed during the initialization */\n params: Params;\n}\n\n/**\n * Events emitted by the UI module.\n */\nexport enum UIEvent {\n /** Triggered when the user performs a native \"Pull-to-Refresh\". */\n TOP_SCROLL_MORE = \"TOP_SCROLL_MORE\",\n /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */\n BOTTOM_SCROLL_MORE = \"BOTTOM_SCROLL_MORE\",\n}\n\n/**\n * Union type for all SDK events, allowing for both known enums and custom strings.\n * The (string & {}) pattern preserves IntelliSense for enum members.\n */\nexport type SDKEvent = UIEvent | (string & {});\n\n/**\n * Configuration for native scroll interactions managed by the Host Shell.\n */\nexport interface ScrollConfig {\n /** Configuration for Pull-to-Refresh (Top). */\n topScrollMore?: {\n /** Show/hide the native RefreshControl. */\n enabled: boolean;\n /** Set to true to show the loading spinner, false to hide it. */\n refreshing?: boolean;\n };\n /** Configuration for Infinite Scroll (Bottom). */\n bottomScrollMore?: {\n /** Enable/disable bottom scroll detection. */\n enabled: boolean;\n /** If false, detection stops and the indicator is hidden. */\n hasMore?: boolean;\n /** Set to true to show the bottom ActivityIndicator. */\n loadingMore?: boolean;\n };\n}\n"],"mappings":"8bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,EAAA,YAAAC,EAAA,QAAAC,ICSO,IAAMC,EAAN,KAAa,CACV,UAAY,IAAI,IAQhB,eAAiB,IAAI,IAO7B,aAAc,CACZ,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMC,EAAiB,OAAO,OAAO,CACnC,gBAAkBC,GAChB,KAAK,oBAAoBA,CAAQ,CACrC,CAAC,EAGD,OAAO,eAAe,OAAQ,kBAAmB,CAC/C,MAAOD,EACP,SAAU,GACV,aAAc,EAChB,CAAC,EAED,OAAO,iBAAiB,UAAYE,GAAU,CAI5C,GAAKA,EAAM,KAEX,GAAI,CACF,IAAMC,EACJ,OAAOD,EAAM,MAAS,SAClB,KAAK,MAAMA,EAAM,IAAI,EACrBA,EAAM,KAGRC,GAAQ,OAAOA,GAAS,WAAaA,EAAK,YAAcA,EAAK,QAC/D,KAAK,oBAAoBA,CAAI,CAEjC,MAAa,CAEb,CACF,CAAC,CACH,CACF,CASQ,oBAAoBF,EAA2B,CACrD,GAAI,CAACA,GAAY,OAAOA,GAAa,SAAU,OAG/C,IAAM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AAK,OAAO,KAAK,sBAAsB,EAKzC,mBACEU,GAEA,KAAK,OAAO,KAAK,uBAAwBA,CAAM,EAKjD,aACEC,GAEA,KAAK,OAAO,KAAK,gBAAiB,CAAE,WAAAA,CAAW,CAAC,CACpD,CAAC,EAKe,GAAK,OAAO,OAAO,CAEjC,KAAM,IAAqB,KAAK,OAAO,KAAK,MAAM,EAKlD,gBAAkBC,GAChB,KAAK,OAAO,KAAK,oBAAqBA,CAAM,CAChD,CAAC,EAKe,MAAQ,OAAO,OAAO,CAKpC,IAAK,IAAIC,IAAuB,KAAK,OAAO,KAAK,YAAa,CAAE,QAAAA,CAAQ,CAAC,CAC3E,CAAC,EAQM,GAAGC,EAAiBC,EAAmC,CAC5D,OAAO,KAAK,OAAO,GAAGD,EAAiBC,CAAQ,CACjD,CAOO,IAAID,EAAiBC,EAAmC,CAC7D,KAAK,OAAO,IAAID,EAAiBC,CAAQ,CAC3C,CACF,EAMaC,EAAMvB,EAAW,IAAIM,CAAY,ECtFvC,IAAKkB,OAEVA,EAAA,gBAAkB,kBAElBA,EAAA,mBAAqB,qBAJXA,OAAA,IH/LZ,IAAOC,EAAQC","names":["index_exports","__export","MiniAppSDK","UIEvent","index_default","sdk","Bridge","bridgeReceiver","envelope","event","data","callbackId","callback","resolve","reject","eventName","listeners","listener","e","cb","type","payload","timeoutMs","timeout","message","win","deepFreeze","obj","propNames","name","value","Bridge","MiniAppSDK","options","key","data","fields","type","payload","id","title","status","style","params","intentUuid","config","message","event","callback","sdk","UIEvent","index_default","sdk"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/bridge.ts","../src/sdk.ts","../src/types/types.ts"],"sourcesContent":["export { MiniAppSDK, sdk } from \"@miniapps-sdk/sdk\";\nexport * from \"@miniapps-sdk/types\";\n\nimport { sdk } from \"@miniapps-sdk/sdk\";\n\nexport default sdk;\n","import type { IBridgeEnvelope } from \"@miniapps-sdk/types\";\n\n/**\n * The Bridge handles low-level communication between the Mini-App WebView\n * and the Native Host Shell (iOS/Android).\n *\n * It manages asynchronous request-response cycles via callbacks and\n * supports subscription to pushed events from the native environment.\n */\nexport class Bridge {\n private callbacks = new Map<\n string,\n {\n resolve: (val: unknown) => void;\n reject: (err: unknown) => void;\n timeout: ReturnType<typeof setTimeout>;\n }\n >();\n private eventListeners = new Map<string, ((data: unknown) => void)[]>();\n\n /**\n * Registers a global listener for messages coming from the native shell.\n * Also listens for standard browser `message` events to support multiple\n * communication channels (e.g., React Native WebView postMessage).\n */\n constructor() {\n if (typeof window !== \"undefined\") {\n const bridgeReceiver = Object.freeze({\n onNativeMessage: (envelope: IBridgeEnvelope) =>\n this.handleNativeMessage(envelope),\n });\n\n // Use defineProperty to prevent re-assignment or deletion of the bridge\n Object.defineProperty(window, \"__MiniAppBridge\", {\n configurable: false,\n value: bridgeReceiver,\n writable: false,\n });\n\n window.addEventListener(\"message\", (event) => {\n // SECURITY: Filter events. If inside a mobile shell, the origin of native postMessage\n // varies by platform (e.g., file://, or specific app schemes).\n // For production, this should be restricted to the expected host origin.\n if (!event.data) return;\n\n try {\n const data =\n typeof event.data === \"string\"\n ? JSON.parse(event.data)\n : event.data;\n\n // SECURITY: Basic envelope validation\n if (\n data &&\n typeof data === \"object\" &&\n (data.callbackId || data.event)\n ) {\n this.handleNativeMessage(data);\n }\n } catch (_e) {\n // Ignore non-JSON or malformed messages\n }\n });\n }\n }\n\n /**\n * Subscribes to a pushed event from the native shell.\n *\n * @param event The event name to listen for.\n * @param callback Function to execute when the event occurs.\n * @returns An unsubscription function.\n */\n public on(event: string, callback: (data: unknown) => void) {\n let listeners = this.eventListeners.get(event);\n if (!listeners) {\n listeners = [];\n this.eventListeners.set(event, listeners);\n }\n listeners.push(callback);\n return () => this.off(event, callback);\n }\n\n /**\n * Unsubscribes a specific callback from an event.\n *\n * @param event The event name.\n * @param callback The callback function to remove.\n */\n public off(event: string, callback: (data: unknown) => void) {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n this.eventListeners.set(\n event,\n listeners.filter((cb) => cb !== callback),\n );\n }\n\n /**\n * Sends a message to the native shell and waits for a response.\n *\n * @template T The expected response type.\n * @param type The action type (e.g., \"GET_LOCATION\").\n * @param payload Data associated with the action.\n * @param timeoutMs Time in milliseconds to wait for a response before rejecting.\n * @returns A promise that resolves with the native response.\n */\n public send<T = unknown>(\n type: string,\n payload?: unknown,\n timeoutMs = 30000,\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n const callbackId = `${type}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n\n const timeout = setTimeout(() => {\n if (this.callbacks.has(callbackId)) {\n this.callbacks.delete(callbackId);\n reject(new Error(`Bridge request timeout: ${type}`));\n }\n }, timeoutMs);\n\n this.callbacks.set(callbackId, {\n reject,\n resolve: resolve as (val: unknown) => void,\n timeout,\n });\n\n const message = {\n callbackId,\n payload,\n type,\n };\n\n const win = window as unknown as {\n ReactNativeWebView?: { postMessage: (msg: string) => void };\n };\n\n if (win.ReactNativeWebView?.postMessage) {\n win.ReactNativeWebView.postMessage(JSON.stringify(message));\n } else {\n clearTimeout(timeout);\n this.callbacks.delete(callbackId);\n reject(new Error(\"Bridge not available\"));\n }\n });\n }\n\n /**\n * Internal handler for all incoming messages from the native shell.\n * Matches incoming payloads to either pending callbacks or event listeners.\n *\n * @internal\n * @param envelope The message envelope received from native code.\n */\n private handleNativeMessage(envelope: IBridgeEnvelope) {\n if (!envelope || typeof envelope !== \"object\") return;\n\n // 1. Handle Response Callbacks\n const callbackId = envelope.callbackId;\n if (callbackId && typeof callbackId === \"string\") {\n const callback = this.callbacks.get(callbackId);\n if (callback) {\n clearTimeout(callback.timeout);\n const { resolve, reject } = callback;\n\n if (envelope.success === false || envelope.error) {\n reject(envelope.error || \"Unknown error\");\n } else {\n resolve(envelope.value ?? envelope.payload ?? envelope);\n }\n\n this.callbacks.delete(callbackId);\n return;\n }\n }\n\n // 2. Handle Pushed Events\n const eventName = envelope.event;\n if (eventName && typeof eventName === \"string\") {\n const listeners = this.eventListeners.get(eventName);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(envelope.payload || envelope.value);\n } catch (e) {\n console.error(`Error in event listener for ${eventName}:`, e);\n }\n }\n }\n }\n }\n}\n","import { Bridge } from \"@miniapps-sdk/bridge\";\nimport type {\n HapticStyleType,\n IFidelityBalance,\n IFidelityHistoryParams,\n IFidelityTransaction,\n IInitializationOptions,\n IInitializationResponse,\n ILocationData,\n INetworkOptions,\n INetworkResponse,\n IPaymentRequest,\n IUserProfile,\n ScrollConfig,\n SDKEvent,\n} from \"@miniapps-sdk/types/types\";\n\n/**\n * Deep freezes an object and its nested properties.\n * @param obj The object to freeze.\n * @returns The frozen object.\n */\nfunction deepFreeze<T extends object>(obj: T): T {\n // Retrieve the property names defined on obj\n const propNames = Object.getOwnPropertyNames(obj);\n\n // Freeze properties before freezing self\n for (const name of propNames) {\n const value = (obj as Record<string, unknown>)[name];\n\n if (\n value &&\n typeof value === \"object\" &&\n !Object.isFrozen(value) &&\n // Skip freezing of native objects or circular refs if any (though not expected here)\n !(value instanceof Bridge)\n ) {\n deepFreeze(value as object);\n }\n }\n\n return Object.freeze(obj);\n}\n\n/**\n * Main SDK for UP Mini-Apps.\n * Provides access to native device features, storage, identity, and shell UI.\n */\nexport class MiniAppSDK {\n private bridge: Bridge;\n /**\n * Local SQLite Storage.\n * Data is persisted on the device and is isolated per Mini-App.\n */\n public readonly storage = Object.freeze({\n /** Retrieves a value by key. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"STORAGE_GET\", { key }),\n /** Retrieves all key-value pairs stored for this Mini-App. */\n getAll: (): Promise<Record<string, string>> =>\n this.bridge.send(\"STORAGE_GET_ALL\"),\n /** Sets a value for a specific key. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"STORAGE_SET\", { key, value }),\n });\n /**\n * Hardware-level Secure Storage.\n * Data is stored in the device's secure enclave (Keychain/Keystore) and is isolated per Mini-App.\n */\n public readonly secureStore = Object.freeze({\n /** Retrieves a value by key from secure storage. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"SECURE_GET\", { key }),\n /** Sets a value for a specific key in secure storage. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"SECURE_SET\", { key, value }),\n });\n /**\n * Database Storage.\n * Access to user-app specific persistent database storage.\n */\n public readonly database = Object.freeze({\n /** Retrieves the user data stored in the backend database. */\n getUserData: <T = unknown>(): Promise<T> =>\n this.bridge.send<T>(\"DATABASE_GET_USER_DATA\"),\n /** Updates the user data stored in the backend database. */\n setUserData: <T = unknown>(data: T): Promise<void> =>\n this.bridge.send<void>(\"DATABASE_SET_USER_DATA\", { data }),\n });\n /**\n * Device Location services.\n */\n public readonly location = Object.freeze({\n /** Retrieves the current GPS position of the device. */\n getCurrentPosition: (): Promise<ILocationData> =>\n this.bridge.send(\"GET_LOCATION\"),\n });\n /**\n * Identity & Profile management.\n */\n public readonly user = Object.freeze({\n /**\n * Fetch user profile data.\n * @param fields Optional list of specific fields to retrieve (e.g., ['fullName', 'username']).\n */\n getProfile: <T extends keyof IUserProfile>(\n fields?: T[],\n ): Promise<Partial<IUserProfile>> =>\n this.bridge.send(\"GET_USER_PROFILE\", { fields }),\n });\n /**\n * Explicit Permission Management.\n * Allows requesting access to sensitive device features or user data.\n */\n public readonly permission = Object.freeze({\n /**\n * Explicitly request access to sensitive data.\n * @param type The type of permission to request ('location' or 'profile').\n * @param fields If requesting 'profile', the specific fields required.\n */\n request: ((type: \"location\" | \"profile\", fields?: string[]) => {\n return this.bridge.send(\"REQUEST_PERMISSION\", { fields, type });\n }) as {\n (type: \"location\"): Promise<boolean>;\n (type: \"profile\", fields: (keyof IUserProfile)[]): Promise<boolean>;\n },\n });\n /**\n * Payments integration.\n */\n public readonly payment = Object.freeze({\n /**\n * Triggers the native payment flow.\n * @param payload Amount, currency, and itemized list for the payment.\n */\n request: (\n payload: IPaymentRequest,\n ): Promise<{ success: true; transactionId: string }> =>\n this.bridge.send(\"PAYMENT_REQUEST\", payload),\n });\n /**\n * Live Activities & Notifications.\n * Allows the Mini-App to display real-time updates in the host shell.\n */\n public readonly activity = Object.freeze({\n /**\n * Starts a new live activity.\n * @param id Unique identifier for the activity.\n * @param title Display title for the activity.\n * @param status Initial status message.\n */\n start: (id: string, title: string, status: string): Promise<void> =>\n this.bridge.send(\"START_ACTIVITY\", { id, status, title }),\n });\n /**\n * Haptic feedback.\n */\n public readonly haptic = Object.freeze({\n /**\n * Triggers a haptic vibration on the device.\n * @param style The style of haptic feedback (e.g., 'light', 'medium', 'heavy', 'success', 'warning', 'error').\n */\n trigger: (style: HapticStyleType): Promise<void> =>\n this.bridge.send(\"TRIGGER_HAPTIC\", { style }),\n });\n /**\n * Network Proxy.\n * Allows the Mini-App to make network requests through the host shell to bypass CORS or use host-level authentication.\n */\n public readonly network = Object.freeze({\n /**\n * Performs a network request via the host shell.\n * @param options Request method, URL, headers, and body.\n */\n request: (options: INetworkOptions): Promise<INetworkResponse> =>\n this.bridge.send(\"NETWORK_REQUEST\", options),\n });\n /**\n * Fidelity & Rewards program integration.\n */\n public readonly fidelity = Object.freeze({\n /** Returns current fidelity balance. */\n getFidelityBalance: (): Promise<IFidelityBalance> =>\n this.bridge.send(\"GET_FIDELITY_BALANCE\"),\n /**\n * Retrieves fidelity transaction history.\n * @param params Filtering and pagination parameters.\n */\n getFidelityHistory: (\n params?: IFidelityHistoryParams,\n ): Promise<IFidelityTransaction[]> =>\n this.bridge.send(\"GET_FIDELITY_HISTORY\", params),\n /**\n * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.\n * @param intentUuid UUID generated by your backend for the transaction.\n */\n spendFPoints: (\n intentUuid: string,\n ): Promise<{ success: boolean; transactionId: string }> =>\n this.bridge.send(\"SPEND_FPOINTS\", { intentUuid }),\n });\n /**\n * UI and Navigation controls.\n */\n public readonly ui = Object.freeze({\n /** Closes the Mini-App and returns to the host shell. */\n exit: (): Promise<void> => this.bridge.send(\"EXIT\"),\n /**\n * Configures native scroll behaviors like Pull-to-Refresh and Infinite Scroll.\n * @param config Scroll configuration for top/bottom detection.\n */\n setScrollConfig: (config: ScrollConfig): Promise<void> =>\n this.bridge.send(\"SET_SCROLL_CONFIG\", config),\n });\n /**\n * Debug controls\n */\n public readonly debug = Object.freeze({\n /**\n * Log to the shell app\n * @param message\n */\n log: (...message: unknown[]) => this.bridge.send(\"DEBUG_LOG\", { message }),\n });\n\n constructor() {\n this.bridge = new Bridge();\n\n // Bind methods to this instance to preserve context if pulled out\n this.initialize = this.initialize.bind(this);\n this.on = this.on.bind(this);\n this.off = this.off.bind(this);\n }\n\n /**\n * The starting point for the Mini-App. Must be called before any other SDK methods.\n * @param options The options to provide to the shell app\n */\n public initialize(\n options: IInitializationOptions,\n ): Promise<IInitializationResponse> {\n return this.bridge.send(\"INITIALIZE\", options);\n }\n\n /**\n * Registers a callback for a specific event from the native shell.\n * @param event The name of the event to listen for.\n * @param callback The function to execute when the event is triggered.\n * @returns A function to unregister the listener.\n */\n public on(event: SDKEvent, callback: (data: unknown) => void) {\n return this.bridge.on(event as string, callback);\n }\n\n /**\n * Unregisters a previously registered event listener.\n * @param event The name of the event.\n * @param callback The callback function to remove.\n */\n public off(event: SDKEvent, callback: (data: unknown) => void) {\n this.bridge.off(event as string, callback);\n }\n}\n\n/**\n * Singleton instance of the MiniAppSDK.\n * Frozen to prevent tampering.\n */\nexport const sdk = deepFreeze(new MiniAppSDK());\n","/**\n * UP Mini-App SDK Types\n */\n\n/**\n * Represents the user's profile information.\n */\nexport interface IUserProfile {\n /** Unique identifier for the user. */\n uuid: string;\n /** Full legal name of the user. */\n fullName: string;\n /** Primary email address. */\n email: string;\n /** Chosen username within the UP ecosystem. */\n username: string;\n /** ISO country code (e.g., \"FR\", \"US\"). */\n countryCode: string;\n /** Phone number without country code. */\n localNumber: string;\n}\n\n/**\n * Geographic location data.\n */\nexport interface ILocationData {\n coords: {\n /** Latitude in decimal degrees. */\n latitude: number;\n /** Longitude in decimal degrees. */\n longitude: number;\n /** Altitude in meters above the WGS 84 reference ellipsoid, or null if not available. */\n altitude: number | null;\n /** Accuracy of the latitude and longitude properties in meters. */\n accuracy: number | null;\n /** Accuracy of the altitude property in meters. */\n altitudeAccuracy: number | null;\n /** The direction in which the device is traveling, in degrees (0-360). */\n heading: number | null;\n /** The velocity of the device in meters per second. */\n speed: number | null;\n };\n /** The time at which the location was retrieved (Unix timestamp). */\n timestamp: number;\n}\n\n/**\n * Request payload for triggering a payment flow.\n */\nexport interface IPaymentRequest {\n /** The specific amount to charge. */\n amount: number;\n /** ISO currency code (e.g., \"EUR\", \"USD\"). */\n currency: string;\n /** Total amount including taxes/fees. */\n total: number;\n /** Itemized breakdown of the purchase. */\n items: Array<{\n /** Name or description of the item. */\n item: string;\n /** Price per unit. */\n price?: number;\n /** Number of units. */\n quantity?: number;\n }>;\n}\n\n/**\n * Style of haptic feedback.\n */\nexport type HapticStyleType =\n | \"light\"\n | \"medium\"\n | \"heavy\"\n | \"rigid\"\n | \"soft\"\n | \"success\"\n | \"warning\"\n | \"error\";\n\n/**\n * Network Proxy Types\n */\n\n/**\n * The HTTP method to use as request method\n */\nexport type NetworkMethodType = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\n/**\n * Configuration for network proxy requests.\n */\nexport interface INetworkOptions {\n /** Full URL for the request. */\n url: string;\n /** HTTP method to use. */\n method: NetworkMethodType;\n /** Request body for POST/PUT/PATCH. */\n body?: unknown;\n /** Custom HTTP headers. */\n headers?: Record<string, string>;\n}\n\n/**\n * Response from a network proxy request.\n */\nexport interface INetworkResponse<T = unknown> {\n /** HTTP status code. */\n status: number;\n /** Response data payload. */\n data: T;\n /** Response headers. */\n headers: Headers;\n}\n\n/**\n * Fidelity & Rewards Types\n */\n\n/**\n * Fidelity program balance information.\n */\nexport interface IFidelityBalance {\n /** Current point or currency balance. */\n balance: number;\n /** Name or symbol of the fidelity currency (e.g., \"FPoints\"). */\n currency: string;\n}\n\n/**\n * Parameters for retrieving fidelity transaction history.\n */\nexport interface IFidelityHistoryParams {\n /** Maximum number of records to return. */\n limit?: number;\n\n /** Cursor for pagination; null for the first page. */\n cursor?: string | null;\n}\n\n/** Type of transaction: credit (add) or debit (remove). */\nexport type FidelityTransactionTypeType = \"credit\" | \"debit\";\n\n/**\n * A single fidelity program transaction.\n */\nexport interface IFidelityTransaction {\n /** Unique identifier for the transaction. */\n id: string;\n /** Amount of the transaction. */\n amount: number;\n /** Human-readable description. */\n description: string;\n /** ISO 8601 date string. */\n date: string;\n /** Type of transaction */\n type: FidelityTransactionTypeType;\n}\n\n/**\n * The initialization options required to set up the Mini-App SDK.\n */\nexport type IInitializationOptions = {};\n\n/**\n * The post initialization response\n */\nexport interface IInitializationResponse<\n Env extends Record<string, unknown> = Record<string, unknown>,\n UserData extends Record<string, unknown> = Record<string, unknown>,\n Params extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** The name of the mini app */\n name: string;\n /** The uuid of the mini app */\n uuid: string;\n /** The description of the mini app */\n description: string;\n /** The authors of the mini app */\n authors?: string;\n /** The current version in the registry */\n version?: string;\n /** The scoped profile based on the requested fields during initialization or the getUserProfile call */\n profile: Partial<IUserProfile | null>;\n /** The environment variables defined for the mini app in the shell's backend */\n env: Env;\n /** The user data passed during the initialization or the setUserData call */\n userData: UserData;\n /** The params passed during the initialization */\n params: Params;\n}\n\n/**\n * Events emitted by the UI module.\n */\nexport enum UIEvent {\n /** Triggered when the user performs a native \"Pull-to-Refresh\". */\n TOP_SCROLL_MORE = \"TOP_SCROLL_MORE\",\n /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */\n BOTTOM_SCROLL_MORE = \"BOTTOM_SCROLL_MORE\",\n}\n\n/**\n * Union type for all SDK events, allowing for both known enums and custom strings.\n * The (string & {}) pattern preserves IntelliSense for enum members.\n */\nexport type SDKEvent = UIEvent | (string & {});\n\n/**\n * Configuration for native scroll interactions managed by the Host Shell.\n */\nexport interface ScrollConfig {\n /** Configuration for Pull-to-Refresh (Top). */\n topScrollMore?: {\n /** Show/hide the native RefreshControl. */\n enabled: boolean;\n /** Set to true to show the loading spinner, false to hide it. */\n refreshing?: boolean;\n };\n /** Configuration for Infinite Scroll (Bottom). */\n bottomScrollMore?: {\n /** Enable/disable bottom scroll detection. */\n enabled: boolean;\n /** If false, detection stops and the indicator is hidden. */\n hasMore?: boolean;\n /** Set to true to show the bottom ActivityIndicator. */\n loadingMore?: boolean;\n };\n}\n"],"mappings":"8bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,EAAA,YAAAC,EAAA,YAAAC,EAAA,QAAAC,ICSO,IAAMC,EAAN,KAAa,CACV,UAAY,IAAI,IAQhB,eAAiB,IAAI,IAO7B,aAAc,CACZ,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMC,EAAiB,OAAO,OAAO,CACnC,gBAAkBC,GAChB,KAAK,oBAAoBA,CAAQ,CACrC,CAAC,EAGD,OAAO,eAAe,OAAQ,kBAAmB,CAC/C,aAAc,GACd,MAAOD,EACP,SAAU,EACZ,CAAC,EAED,OAAO,iBAAiB,UAAYE,GAAU,CAI5C,GAAKA,EAAM,KAEX,GAAI,CACF,IAAMC,EACJ,OAAOD,EAAM,MAAS,SAClB,KAAK,MAAMA,EAAM,IAAI,EACrBA,EAAM,KAIVC,GACA,OAAOA,GAAS,WACfA,EAAK,YAAcA,EAAK,QAEzB,KAAK,oBAAoBA,CAAI,CAEjC,MAAa,CAEb,CACF,CAAC,CACH,CACF,CASO,GAAGD,EAAeE,EAAmC,CAC1D,IAAIC,EAAY,KAAK,eAAe,IAAIH,CAAK,EAC7C,OAAKG,IACHA,EAAY,CAAC,EACb,KAAK,eAAe,IAAIH,EAAOG,CAAS,GAE1CA,EAAU,KAAKD,CAAQ,EAChB,IAAM,KAAK,IAAIF,EAAOE,CAAQ,CACvC,CAQO,IAAIF,EAAeE,EAAmC,CAC3D,IAAMC,EAAY,KAAK,eAAe,IAAIH,CAAK,EAC1CG,GACL,KAAK,eAAe,IAClBH,EACAG,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IAAI,EAC3C,KAAK,GAAK,KAAK,GAAG,KAAK,IAAI,EAC3B,KAAK,IAAM,KAAK,IAAI,KAAK,IAAI,CAC/B,CAMO,WACLW,EACkC,CAClC,OAAO,KAAK,OAAO,KAAK,aAAcA,CAAO,CAC/C,CAQO,GAAGK,EAAiBC,EAAmC,CAC5D,OAAO,KAAK,OAAO,GAAGD,EAAiBC,CAAQ,CACjD,CAOO,IAAID,EAAiBC,EAAmC,CAC7D,KAAK,OAAO,IAAID,EAAiBC,CAAQ,CAC3C,CACF,EAMaC,EAAMvB,EAAW,IAAIM,CAAY,ECzEvC,IAAKkB,OAEVA,EAAA,gBAAkB,kBAElBA,EAAA,mBAAqB,qBAJXA,OAAA,IH9LZ,IAAOC,EAAQC","names":["index_exports","__export","MiniAppSDK","UIEvent","index_default","sdk","Bridge","bridgeReceiver","envelope","event","data","callback","listeners","cb","type","payload","timeoutMs","resolve","reject","callbackId","timeout","message","win","eventName","listener","e","deepFreeze","obj","propNames","name","value","Bridge","MiniAppSDK","key","data","fields","type","payload","id","title","status","style","options","params","intentUuid","config","message","event","callback","sdk","UIEvent","index_default","sdk"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -203,12 +203,6 @@ interface ScrollConfig {
|
|
|
203
203
|
*/
|
|
204
204
|
declare class MiniAppSDK {
|
|
205
205
|
private bridge;
|
|
206
|
-
constructor();
|
|
207
|
-
/**
|
|
208
|
-
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
209
|
-
* @param options The options to provide to the shell app
|
|
210
|
-
*/
|
|
211
|
-
initialize(options: IInitializationOptions): Promise<IInitializationResponse>;
|
|
212
206
|
/**
|
|
213
207
|
* Local SQLite Storage.
|
|
214
208
|
* Data is persisted on the device and is isolated per Mini-App.
|
|
@@ -362,6 +356,12 @@ declare class MiniAppSDK {
|
|
|
362
356
|
*/
|
|
363
357
|
log: (...message: unknown[]) => Promise<unknown>;
|
|
364
358
|
}>;
|
|
359
|
+
constructor();
|
|
360
|
+
/**
|
|
361
|
+
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
362
|
+
* @param options The options to provide to the shell app
|
|
363
|
+
*/
|
|
364
|
+
initialize(options: IInitializationOptions): Promise<IInitializationResponse>;
|
|
365
365
|
/**
|
|
366
366
|
* Registers a callback for a specific event from the native shell.
|
|
367
367
|
* @param event The name of the event to listen for.
|
|
@@ -465,12 +465,6 @@ type BridgeMessageType = {
|
|
|
465
465
|
fields?: string[];
|
|
466
466
|
};
|
|
467
467
|
callbackId: string;
|
|
468
|
-
} | {
|
|
469
|
-
type: "GET_IDENTITY_TOKEN";
|
|
470
|
-
payload?: {
|
|
471
|
-
scopes?: string[];
|
|
472
|
-
};
|
|
473
|
-
callbackId: string;
|
|
474
468
|
} | {
|
|
475
469
|
type: "SPEND_FPOINTS";
|
|
476
470
|
payload: {
|
package/dist/index.d.ts
CHANGED
|
@@ -203,12 +203,6 @@ interface ScrollConfig {
|
|
|
203
203
|
*/
|
|
204
204
|
declare class MiniAppSDK {
|
|
205
205
|
private bridge;
|
|
206
|
-
constructor();
|
|
207
|
-
/**
|
|
208
|
-
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
209
|
-
* @param options The options to provide to the shell app
|
|
210
|
-
*/
|
|
211
|
-
initialize(options: IInitializationOptions): Promise<IInitializationResponse>;
|
|
212
206
|
/**
|
|
213
207
|
* Local SQLite Storage.
|
|
214
208
|
* Data is persisted on the device and is isolated per Mini-App.
|
|
@@ -362,6 +356,12 @@ declare class MiniAppSDK {
|
|
|
362
356
|
*/
|
|
363
357
|
log: (...message: unknown[]) => Promise<unknown>;
|
|
364
358
|
}>;
|
|
359
|
+
constructor();
|
|
360
|
+
/**
|
|
361
|
+
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
362
|
+
* @param options The options to provide to the shell app
|
|
363
|
+
*/
|
|
364
|
+
initialize(options: IInitializationOptions): Promise<IInitializationResponse>;
|
|
365
365
|
/**
|
|
366
366
|
* Registers a callback for a specific event from the native shell.
|
|
367
367
|
* @param event The name of the event to listen for.
|
|
@@ -465,12 +465,6 @@ type BridgeMessageType = {
|
|
|
465
465
|
fields?: string[];
|
|
466
466
|
};
|
|
467
467
|
callbackId: string;
|
|
468
|
-
} | {
|
|
469
|
-
type: "GET_IDENTITY_TOKEN";
|
|
470
|
-
payload?: {
|
|
471
|
-
scopes?: string[];
|
|
472
|
-
};
|
|
473
|
-
callbackId: string;
|
|
474
468
|
} | {
|
|
475
469
|
type: "SPEND_FPOINTS";
|
|
476
470
|
payload: {
|
package/dist/index.js
CHANGED
|
@@ -42,9 +42,9 @@ var Bridge = class {
|
|
|
42
42
|
onNativeMessage: (envelope) => this.handleNativeMessage(envelope)
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(window, "__MiniAppBridge", {
|
|
45
|
+
configurable: false,
|
|
45
46
|
value: bridgeReceiver,
|
|
46
|
-
writable: false
|
|
47
|
-
configurable: false
|
|
47
|
+
writable: false
|
|
48
48
|
});
|
|
49
49
|
window.addEventListener("message", (event) => {
|
|
50
50
|
if (!event.data) return;
|
|
@@ -58,44 +58,6 @@ var Bridge = class {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Internal handler for all incoming messages from the native shell.
|
|
63
|
-
* Matches incoming payloads to either pending callbacks or event listeners.
|
|
64
|
-
*
|
|
65
|
-
* @internal
|
|
66
|
-
* @param envelope The message envelope received from native code.
|
|
67
|
-
*/
|
|
68
|
-
handleNativeMessage(envelope) {
|
|
69
|
-
if (!envelope || typeof envelope !== "object") return;
|
|
70
|
-
const callbackId = envelope.callbackId;
|
|
71
|
-
if (callbackId && typeof callbackId === "string") {
|
|
72
|
-
const callback = this.callbacks.get(callbackId);
|
|
73
|
-
if (callback) {
|
|
74
|
-
clearTimeout(callback.timeout);
|
|
75
|
-
const { resolve, reject } = callback;
|
|
76
|
-
if (envelope.success === false || envelope.error) {
|
|
77
|
-
reject(envelope.error || "Unknown error");
|
|
78
|
-
} else {
|
|
79
|
-
resolve(envelope.value ?? envelope.payload ?? envelope);
|
|
80
|
-
}
|
|
81
|
-
this.callbacks.delete(callbackId);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const eventName = envelope.event;
|
|
86
|
-
if (eventName && typeof eventName === "string") {
|
|
87
|
-
const listeners = this.eventListeners.get(eventName);
|
|
88
|
-
if (listeners) {
|
|
89
|
-
for (const listener of listeners) {
|
|
90
|
-
try {
|
|
91
|
-
listener(envelope.payload || envelope.value);
|
|
92
|
-
} catch (e) {
|
|
93
|
-
console.error(`Error in event listener for ${eventName}:`, e);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
61
|
/**
|
|
100
62
|
* Subscribes to a pushed event from the native shell.
|
|
101
63
|
*
|
|
@@ -164,6 +126,44 @@ var Bridge = class {
|
|
|
164
126
|
}
|
|
165
127
|
});
|
|
166
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Internal handler for all incoming messages from the native shell.
|
|
131
|
+
* Matches incoming payloads to either pending callbacks or event listeners.
|
|
132
|
+
*
|
|
133
|
+
* @internal
|
|
134
|
+
* @param envelope The message envelope received from native code.
|
|
135
|
+
*/
|
|
136
|
+
handleNativeMessage(envelope) {
|
|
137
|
+
if (!envelope || typeof envelope !== "object") return;
|
|
138
|
+
const callbackId = envelope.callbackId;
|
|
139
|
+
if (callbackId && typeof callbackId === "string") {
|
|
140
|
+
const callback = this.callbacks.get(callbackId);
|
|
141
|
+
if (callback) {
|
|
142
|
+
clearTimeout(callback.timeout);
|
|
143
|
+
const { resolve, reject } = callback;
|
|
144
|
+
if (envelope.success === false || envelope.error) {
|
|
145
|
+
reject(envelope.error || "Unknown error");
|
|
146
|
+
} else {
|
|
147
|
+
resolve(envelope.value ?? envelope.payload ?? envelope);
|
|
148
|
+
}
|
|
149
|
+
this.callbacks.delete(callbackId);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const eventName = envelope.event;
|
|
154
|
+
if (eventName && typeof eventName === "string") {
|
|
155
|
+
const listeners = this.eventListeners.get(eventName);
|
|
156
|
+
if (listeners) {
|
|
157
|
+
for (const listener of listeners) {
|
|
158
|
+
try {
|
|
159
|
+
listener(envelope.payload || envelope.value);
|
|
160
|
+
} catch (e) {
|
|
161
|
+
console.error(`Error in event listener for ${eventName}:`, e);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
// src/sdk.ts
|
|
@@ -180,19 +180,6 @@ function deepFreeze(obj) {
|
|
|
180
180
|
}
|
|
181
181
|
var MiniAppSDK = class {
|
|
182
182
|
bridge;
|
|
183
|
-
constructor() {
|
|
184
|
-
this.bridge = new Bridge();
|
|
185
|
-
this.initialize = this.initialize.bind(this);
|
|
186
|
-
this.on = this.on.bind(this);
|
|
187
|
-
this.off = this.off.bind(this);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
191
|
-
* @param options The options to provide to the shell app
|
|
192
|
-
*/
|
|
193
|
-
initialize(options) {
|
|
194
|
-
return this.bridge.send("INITIALIZE", options);
|
|
195
|
-
}
|
|
196
183
|
/**
|
|
197
184
|
* Local SQLite Storage.
|
|
198
185
|
* Data is persisted on the device and is isolated per Mini-App.
|
|
@@ -339,6 +326,19 @@ var MiniAppSDK = class {
|
|
|
339
326
|
*/
|
|
340
327
|
log: (...message) => this.bridge.send("DEBUG_LOG", { message })
|
|
341
328
|
});
|
|
329
|
+
constructor() {
|
|
330
|
+
this.bridge = new Bridge();
|
|
331
|
+
this.initialize = this.initialize.bind(this);
|
|
332
|
+
this.on = this.on.bind(this);
|
|
333
|
+
this.off = this.off.bind(this);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
337
|
+
* @param options The options to provide to the shell app
|
|
338
|
+
*/
|
|
339
|
+
initialize(options) {
|
|
340
|
+
return this.bridge.send("INITIALIZE", options);
|
|
341
|
+
}
|
|
342
342
|
/**
|
|
343
343
|
* Registers a callback for a specific event from the native shell.
|
|
344
344
|
* @param event The name of the event to listen for.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/bridge.ts","../src/sdk.ts","../src/types/types.ts"],"sourcesContent":["export { MiniAppSDK, sdk } from \"@miniapps-sdk/sdk\";\nexport * from \"@miniapps-sdk/types\";\n\nimport { sdk } from \"@miniapps-sdk/sdk\";\nexport default sdk;\n","import type { IBridgeEnvelope } from \"@miniapps-sdk/types\";\n\n/**\n * The Bridge handles low-level communication between the Mini-App WebView\n * and the Native Host Shell (iOS/Android).\n *\n * It manages asynchronous request-response cycles via callbacks and\n * supports subscription to pushed events from the native environment.\n */\nexport class Bridge {\n private callbacks = new Map<\n string,\n {\n resolve: (val: unknown) => void;\n reject: (err: unknown) => void;\n timeout: ReturnType<typeof setTimeout>;\n }\n >();\n private eventListeners = new Map<string, ((data: unknown) => void)[]>();\n\n /**\n * Registers a global listener for messages coming from the native shell.\n * Also listens for standard browser `message` events to support multiple\n * communication channels (e.g., React Native WebView postMessage).\n */\n constructor() {\n if (typeof window !== \"undefined\") {\n const bridgeReceiver = Object.freeze({\n onNativeMessage: (envelope: IBridgeEnvelope) =>\n this.handleNativeMessage(envelope),\n });\n\n // Use defineProperty to prevent re-assignment or deletion of the bridge\n Object.defineProperty(window, \"__MiniAppBridge\", {\n value: bridgeReceiver,\n writable: false,\n configurable: false,\n });\n\n window.addEventListener(\"message\", (event) => {\n // SECURITY: Filter events. If inside a mobile shell, the origin of native postMessage\n // varies by platform (e.g., file://, or specific app schemes).\n // For production, this should be restricted to the expected host origin.\n if (!event.data) return;\n\n try {\n const data =\n typeof event.data === \"string\"\n ? JSON.parse(event.data)\n : event.data;\n\n // SECURITY: Basic envelope validation\n if (data && typeof data === \"object\" && (data.callbackId || data.event)) {\n this.handleNativeMessage(data);\n }\n } catch (_e) {\n // Ignore non-JSON or malformed messages\n }\n });\n }\n }\n\n /**\n * Internal handler for all incoming messages from the native shell.\n * Matches incoming payloads to either pending callbacks or event listeners.\n *\n * @internal\n * @param envelope The message envelope received from native code.\n */\n private handleNativeMessage(envelope: IBridgeEnvelope) {\n if (!envelope || typeof envelope !== \"object\") return;\n\n // 1. Handle Response Callbacks\n const callbackId = envelope.callbackId;\n if (callbackId && typeof callbackId === \"string\") {\n const callback = this.callbacks.get(callbackId);\n if (callback) {\n clearTimeout(callback.timeout);\n const { resolve, reject } = callback;\n\n if (envelope.success === false || envelope.error) {\n reject(envelope.error || \"Unknown error\");\n } else {\n resolve(envelope.value ?? envelope.payload ?? envelope);\n }\n\n this.callbacks.delete(callbackId);\n return;\n }\n }\n\n // 2. Handle Pushed Events\n const eventName = envelope.event;\n if (eventName && typeof eventName === \"string\") {\n const listeners = this.eventListeners.get(eventName);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(envelope.payload || envelope.value);\n } catch (e) {\n console.error(`Error in event listener for ${eventName}:`, e);\n }\n }\n }\n }\n }\n\n /**\n * Subscribes to a pushed event from the native shell.\n *\n * @param event The event name to listen for.\n * @param callback Function to execute when the event occurs.\n * @returns An unsubscription function.\n */\n public on(event: string, callback: (data: unknown) => void) {\n let listeners = this.eventListeners.get(event);\n if (!listeners) {\n listeners = [];\n this.eventListeners.set(event, listeners);\n }\n listeners.push(callback);\n return () => this.off(event, callback);\n }\n\n /**\n * Unsubscribes a specific callback from an event.\n *\n * @param event The event name.\n * @param callback The callback function to remove.\n */\n public off(event: string, callback: (data: unknown) => void) {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n this.eventListeners.set(\n event,\n listeners.filter((cb) => cb !== callback),\n );\n }\n\n /**\n * Sends a message to the native shell and waits for a response.\n *\n * @template T The expected response type.\n * @param type The action type (e.g., \"GET_LOCATION\").\n * @param payload Data associated with the action.\n * @param timeoutMs Time in milliseconds to wait for a response before rejecting.\n * @returns A promise that resolves with the native response.\n */\n public send<T = unknown>(\n type: string,\n payload?: unknown,\n timeoutMs = 30000,\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n const callbackId = `${type}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n\n const timeout = setTimeout(() => {\n if (this.callbacks.has(callbackId)) {\n this.callbacks.delete(callbackId);\n reject(new Error(`Bridge request timeout: ${type}`));\n }\n }, timeoutMs);\n\n this.callbacks.set(callbackId, {\n reject,\n resolve: resolve as (val: unknown) => void,\n timeout,\n });\n\n const message = {\n callbackId,\n payload,\n type,\n };\n\n const win = window as unknown as {\n ReactNativeWebView?: { postMessage: (msg: string) => void };\n };\n\n if (win.ReactNativeWebView?.postMessage) {\n win.ReactNativeWebView.postMessage(JSON.stringify(message));\n } else {\n clearTimeout(timeout);\n this.callbacks.delete(callbackId);\n reject(new Error(\"Bridge not available\"));\n }\n });\n }\n}\n","import { Bridge } from \"@miniapps-sdk/bridge\";\nimport type {\n HapticStyleType,\n IFidelityBalance,\n IFidelityHistoryParams,\n IFidelityTransaction,\n IInitializationOptions,\n IInitializationResponse,\n ILocationData,\n INetworkOptions,\n INetworkResponse,\n IPaymentRequest,\n IUserProfile,\n ScrollConfig,\n SDKEvent,\n} from \"@miniapps-sdk/types/types\";\n\n/**\n * Deep freezes an object and its nested properties.\n * @param obj The object to freeze.\n * @returns The frozen object.\n */\nfunction deepFreeze<T extends object>(obj: T): T {\n // Retrieve the property names defined on obj\n const propNames = Object.getOwnPropertyNames(obj);\n\n // Freeze properties before freezing self\n for (const name of propNames) {\n const value = (obj as Record<string, unknown>)[name];\n\n if (\n value &&\n typeof value === \"object\" &&\n !Object.isFrozen(value) &&\n // Skip freezing of native objects or circular refs if any (though not expected here)\n !(value instanceof Bridge)\n ) {\n deepFreeze(value as object);\n }\n }\n\n return Object.freeze(obj);\n}\n\n/**\n * Main SDK for UP Mini-Apps.\n * Provides access to native device features, storage, identity, and shell UI.\n */\nexport class MiniAppSDK {\n private bridge: Bridge;\n\n constructor() {\n this.bridge = new Bridge();\n\n // Bind methods to this instance to preserve context if pulled out\n this.initialize = this.initialize.bind(this);\n this.on = this.on.bind(this);\n this.off = this.off.bind(this);\n }\n\n /**\n * The starting point for the Mini-App. Must be called before any other SDK methods.\n * @param options The options to provide to the shell app\n */\n public initialize(\n options: IInitializationOptions,\n ): Promise<IInitializationResponse> {\n return this.bridge.send(\"INITIALIZE\", options);\n }\n\n /**\n * Local SQLite Storage.\n * Data is persisted on the device and is isolated per Mini-App.\n */\n public readonly storage = Object.freeze({\n /** Retrieves a value by key. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"STORAGE_GET\", { key }),\n /** Retrieves all key-value pairs stored for this Mini-App. */\n getAll: (): Promise<Record<string, string>> =>\n this.bridge.send(\"STORAGE_GET_ALL\"),\n /** Sets a value for a specific key. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"STORAGE_SET\", { key, value }),\n });\n\n /**\n * Hardware-level Secure Storage.\n * Data is stored in the device's secure enclave (Keychain/Keystore) and is isolated per Mini-App.\n */\n public readonly secureStore = Object.freeze({\n /** Retrieves a value by key from secure storage. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"SECURE_GET\", { key }),\n /** Sets a value for a specific key in secure storage. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"SECURE_SET\", { key, value }),\n });\n\n /**\n * Database Storage.\n * Access to user-app specific persistent database storage.\n */\n public readonly database = Object.freeze({\n /** Retrieves the user data stored in the backend database. */\n getUserData: <T = unknown>(): Promise<T> =>\n this.bridge.send<T>(\"DATABASE_GET_USER_DATA\"),\n /** Updates the user data stored in the backend database. */\n setUserData: <T = unknown>(data: T): Promise<void> =>\n this.bridge.send<void>(\"DATABASE_SET_USER_DATA\", { data }),\n });\n\n /**\n * Device Location services.\n */\n public readonly location = Object.freeze({\n /** Retrieves the current GPS position of the device. */\n getCurrentPosition: (): Promise<ILocationData> =>\n this.bridge.send(\"GET_LOCATION\"),\n });\n\n /**\n * Identity & Profile management.\n */\n public readonly user = Object.freeze({\n /**\n * Fetch user profile data.\n * @param fields Optional list of specific fields to retrieve (e.g., ['fullName', 'username']).\n */\n getProfile: <T extends keyof IUserProfile>(\n fields?: T[],\n ): Promise<Partial<IUserProfile>> =>\n this.bridge.send(\"GET_USER_PROFILE\", { fields }),\n });\n\n /**\n * Explicit Permission Management.\n * Allows requesting access to sensitive device features or user data.\n */\n public readonly permission = Object.freeze({\n /**\n * Explicitly request access to sensitive data.\n * @param type The type of permission to request ('location' or 'profile').\n * @param fields If requesting 'profile', the specific fields required.\n */\n request: ((type: \"location\" | \"profile\", fields?: string[]) => {\n return this.bridge.send(\"REQUEST_PERMISSION\", { fields, type });\n }) as {\n (type: \"location\"): Promise<boolean>;\n (type: \"profile\", fields: (keyof IUserProfile)[]): Promise<boolean>;\n },\n });\n\n /**\n * Payments integration.\n */\n public readonly payment = Object.freeze({\n /**\n * Triggers the native payment flow.\n * @param payload Amount, currency, and itemized list for the payment.\n */\n request: (\n payload: IPaymentRequest,\n ): Promise<{ success: true; transactionId: string }> =>\n this.bridge.send(\"PAYMENT_REQUEST\", payload),\n });\n\n /**\n * Live Activities & Notifications.\n * Allows the Mini-App to display real-time updates in the host shell.\n */\n public readonly activity = Object.freeze({\n /**\n * Starts a new live activity.\n * @param id Unique identifier for the activity.\n * @param title Display title for the activity.\n * @param status Initial status message.\n */\n start: (id: string, title: string, status: string): Promise<void> =>\n this.bridge.send(\"START_ACTIVITY\", { id, status, title }),\n });\n\n /**\n * Haptic feedback.\n */\n public readonly haptic = Object.freeze({\n /**\n * Triggers a haptic vibration on the device.\n * @param style The style of haptic feedback (e.g., 'light', 'medium', 'heavy', 'success', 'warning', 'error').\n */\n trigger: (style: HapticStyleType): Promise<void> =>\n this.bridge.send(\"TRIGGER_HAPTIC\", { style }),\n });\n\n /**\n * Network Proxy.\n * Allows the Mini-App to make network requests through the host shell to bypass CORS or use host-level authentication.\n */\n public readonly network = Object.freeze({\n /**\n * Performs a network request via the host shell.\n * @param options Request method, URL, headers, and body.\n */\n request: (options: INetworkOptions): Promise<INetworkResponse> =>\n this.bridge.send(\"NETWORK_REQUEST\", options),\n });\n\n /**\n * Fidelity & Rewards program integration.\n */\n public readonly fidelity = Object.freeze({\n /** Returns current fidelity balance. */\n getFidelityBalance: (): Promise<IFidelityBalance> =>\n this.bridge.send(\"GET_FIDELITY_BALANCE\"),\n /**\n * Retrieves fidelity transaction history.\n * @param params Filtering and pagination parameters.\n */\n getFidelityHistory: (\n params?: IFidelityHistoryParams,\n ): Promise<IFidelityTransaction[]> =>\n this.bridge.send(\"GET_FIDELITY_HISTORY\", params),\n /**\n * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.\n * @param intentUuid UUID generated by your backend for the transaction.\n */\n spendFPoints: (\n intentUuid: string,\n ): Promise<{ success: boolean; transactionId: string }> =>\n this.bridge.send(\"SPEND_FPOINTS\", { intentUuid }),\n });\n\n /**\n * UI and Navigation controls.\n */\n public readonly ui = Object.freeze({\n /** Closes the Mini-App and returns to the host shell. */\n exit: (): Promise<void> => this.bridge.send(\"EXIT\"),\n /**\n * Configures native scroll behaviors like Pull-to-Refresh and Infinite Scroll.\n * @param config Scroll configuration for top/bottom detection.\n */\n setScrollConfig: (config: ScrollConfig): Promise<void> =>\n this.bridge.send(\"SET_SCROLL_CONFIG\", config),\n });\n\n /**\n * Debug controls\n */\n public readonly debug = Object.freeze({\n /**\n * Log to the shell app\n * @param message\n */\n log: (...message: unknown[]) => this.bridge.send(\"DEBUG_LOG\", { message }),\n });\n\n /**\n * Registers a callback for a specific event from the native shell.\n * @param event The name of the event to listen for.\n * @param callback The function to execute when the event is triggered.\n * @returns A function to unregister the listener.\n */\n public on(event: SDKEvent, callback: (data: unknown) => void) {\n return this.bridge.on(event as string, callback);\n }\n\n /**\n * Unregisters a previously registered event listener.\n * @param event The name of the event.\n * @param callback The callback function to remove.\n */\n public off(event: SDKEvent, callback: (data: unknown) => void) {\n this.bridge.off(event as string, callback);\n }\n}\n\n/**\n * Singleton instance of the MiniAppSDK.\n * Frozen to prevent tampering.\n */\nexport const sdk = deepFreeze(new MiniAppSDK());\n","/**\n * UP Mini-App SDK Types\n */\n\n/**\n * Represents the user's profile information.\n */\nexport interface IUserProfile {\n /** Unique identifier for the user. */\n uuid: string;\n /** Full legal name of the user. */\n fullName: string;\n /** Primary email address. */\n email: string;\n /** Chosen username within the UP ecosystem. */\n username: string;\n /** ISO country code (e.g., \"FR\", \"US\"). */\n countryCode: string;\n /** Phone number without country code. */\n localNumber: string;\n}\n\n/**\n * Geographic location data.\n */\nexport interface ILocationData {\n coords: {\n /** Latitude in decimal degrees. */\n latitude: number;\n /** Longitude in decimal degrees. */\n longitude: number;\n /** Altitude in meters above the WGS 84 reference ellipsoid, or null if not available. */\n altitude: number | null;\n /** Accuracy of the latitude and longitude properties in meters. */\n accuracy: number | null;\n /** Accuracy of the altitude property in meters. */\n altitudeAccuracy: number | null;\n /** The direction in which the device is traveling, in degrees (0-360). */\n heading: number | null;\n /** The velocity of the device in meters per second. */\n speed: number | null;\n };\n /** The time at which the location was retrieved (Unix timestamp). */\n timestamp: number;\n}\n\n/**\n * Request payload for triggering a payment flow.\n */\nexport interface IPaymentRequest {\n /** The specific amount to charge. */\n amount: number;\n /** ISO currency code (e.g., \"EUR\", \"USD\"). */\n currency: string;\n /** Total amount including taxes/fees. */\n total: number;\n /** Itemized breakdown of the purchase. */\n items: Array<{\n /** Name or description of the item. */\n item: string;\n /** Price per unit. */\n price?: number;\n /** Number of units. */\n quantity?: number;\n }>;\n}\n\n/**\n * Style of haptic feedback.\n */\nexport type HapticStyleType =\n | \"light\"\n | \"medium\"\n | \"heavy\"\n | \"rigid\"\n | \"soft\"\n | \"success\"\n | \"warning\"\n | \"error\";\n\n/**\n * Network Proxy Types\n */\n\n/**\n * The HTTP method to use as request method\n */\nexport type NetworkMethodType = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\n/**\n * Configuration for network proxy requests.\n */\nexport interface INetworkOptions {\n /** Full URL for the request. */\n url: string;\n /** HTTP method to use. */\n method: NetworkMethodType;\n /** Request body for POST/PUT/PATCH. */\n body?: unknown;\n /** Custom HTTP headers. */\n headers?: Record<string, string>;\n}\n\n/**\n * Response from a network proxy request.\n */\nexport interface INetworkResponse<T = unknown> {\n /** HTTP status code. */\n status: number;\n /** Response data payload. */\n data: T;\n /** Response headers. */\n headers: Headers;\n}\n\n/**\n * Fidelity & Rewards Types\n */\n\n/**\n * Fidelity program balance information.\n */\nexport interface IFidelityBalance {\n /** Current point or currency balance. */\n balance: number;\n /** Name or symbol of the fidelity currency (e.g., \"FPoints\"). */\n currency: string;\n}\n\n/**\n * Parameters for retrieving fidelity transaction history.\n */\nexport interface IFidelityHistoryParams {\n /** Maximum number of records to return. */\n limit?: number;\n\n /** Cursor for pagination; null for the first page. */\n cursor?: string | null;\n}\n\n/** Type of transaction: credit (add) or debit (remove). */\nexport type FidelityTransactionTypeType = \"credit\" | \"debit\";\n\n/**\n * A single fidelity program transaction.\n */\nexport interface IFidelityTransaction {\n /** Unique identifier for the transaction. */\n id: string;\n /** Amount of the transaction. */\n amount: number;\n /** Human-readable description. */\n description: string;\n /** ISO 8601 date string. */\n date: string;\n /** Type of transaction */\n type: FidelityTransactionTypeType;\n}\n\n/**\n * The initialization options required to set up the Mini-App SDK.\n */\nexport type IInitializationOptions = {};\n\n/**\n * The post initialization response\n */\nexport interface IInitializationResponse<\n Env extends Record<string, unknown> = Record<string, unknown>,\n UserData extends Record<string, unknown> = Record<string, unknown>,\n Params extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** The name of the mini app */\n name: string;\n /** The uuid of the mini app */\n uuid: string;\n /** The description of the mini app */\n description: string;\n /** The authors of the mini app */\n authors?: string;\n /** The current version in the registry */\n version?: string;\n /** The scoped profile based on the requested fields during initialization or the getUserProfile call */\n profile: Partial<IUserProfile | null>;\n /** The environment variables defined for the mini app in the shell's backend */\n env: Env;\n /** The user data passed during the initialization or the setUserData call */\n userData: UserData;\n /** The params passed during the initialization */\n params: Params;\n}\n\n/**\n * Events emitted by the UI module.\n */\nexport enum UIEvent {\n /** Triggered when the user performs a native \"Pull-to-Refresh\". */\n TOP_SCROLL_MORE = \"TOP_SCROLL_MORE\",\n /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */\n BOTTOM_SCROLL_MORE = \"BOTTOM_SCROLL_MORE\",\n}\n\n/**\n * Union type for all SDK events, allowing for both known enums and custom strings.\n * The (string & {}) pattern preserves IntelliSense for enum members.\n */\nexport type SDKEvent = UIEvent | (string & {});\n\n/**\n * Configuration for native scroll interactions managed by the Host Shell.\n */\nexport interface ScrollConfig {\n /** Configuration for Pull-to-Refresh (Top). */\n topScrollMore?: {\n /** Show/hide the native RefreshControl. */\n enabled: boolean;\n /** Set to true to show the loading spinner, false to hide it. */\n refreshing?: boolean;\n };\n /** Configuration for Infinite Scroll (Bottom). */\n bottomScrollMore?: {\n /** Enable/disable bottom scroll detection. */\n enabled: boolean;\n /** If false, detection stops and the indicator is hidden. */\n hasMore?: boolean;\n /** Set to true to show the bottom ActivityIndicator. */\n loadingMore?: boolean;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,SAAN,MAAa;AAAA,EACV,YAAY,oBAAI,IAOtB;AAAA,EACM,iBAAiB,oBAAI,IAAyC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtE,cAAc;AACZ,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,iBAAiB,OAAO,OAAO;AAAA,QACnC,iBAAiB,CAAC,aAChB,KAAK,oBAAoB,QAAQ;AAAA,MACrC,CAAC;AAGD,aAAO,eAAe,QAAQ,mBAAmB;AAAA,QAC/C,OAAO;AAAA,QACP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K,UAAL,kBAAKA,aAAL;AAEL,EAAAA,SAAA,qBAAkB;AAElB,EAAAA,SAAA,wBAAqB;AAJX,SAAAA;AAAA,GAAA;;;AH/LZ,IAAO,gBAAQ;","names":["UIEvent"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/bridge.ts","../src/sdk.ts","../src/types/types.ts"],"sourcesContent":["export { MiniAppSDK, sdk } from \"@miniapps-sdk/sdk\";\nexport * from \"@miniapps-sdk/types\";\n\nimport { sdk } from \"@miniapps-sdk/sdk\";\n\nexport default sdk;\n","import type { IBridgeEnvelope } from \"@miniapps-sdk/types\";\n\n/**\n * The Bridge handles low-level communication between the Mini-App WebView\n * and the Native Host Shell (iOS/Android).\n *\n * It manages asynchronous request-response cycles via callbacks and\n * supports subscription to pushed events from the native environment.\n */\nexport class Bridge {\n private callbacks = new Map<\n string,\n {\n resolve: (val: unknown) => void;\n reject: (err: unknown) => void;\n timeout: ReturnType<typeof setTimeout>;\n }\n >();\n private eventListeners = new Map<string, ((data: unknown) => void)[]>();\n\n /**\n * Registers a global listener for messages coming from the native shell.\n * Also listens for standard browser `message` events to support multiple\n * communication channels (e.g., React Native WebView postMessage).\n */\n constructor() {\n if (typeof window !== \"undefined\") {\n const bridgeReceiver = Object.freeze({\n onNativeMessage: (envelope: IBridgeEnvelope) =>\n this.handleNativeMessage(envelope),\n });\n\n // Use defineProperty to prevent re-assignment or deletion of the bridge\n Object.defineProperty(window, \"__MiniAppBridge\", {\n configurable: false,\n value: bridgeReceiver,\n writable: false,\n });\n\n window.addEventListener(\"message\", (event) => {\n // SECURITY: Filter events. If inside a mobile shell, the origin of native postMessage\n // varies by platform (e.g., file://, or specific app schemes).\n // For production, this should be restricted to the expected host origin.\n if (!event.data) return;\n\n try {\n const data =\n typeof event.data === \"string\"\n ? JSON.parse(event.data)\n : event.data;\n\n // SECURITY: Basic envelope validation\n if (\n data &&\n typeof data === \"object\" &&\n (data.callbackId || data.event)\n ) {\n this.handleNativeMessage(data);\n }\n } catch (_e) {\n // Ignore non-JSON or malformed messages\n }\n });\n }\n }\n\n /**\n * Subscribes to a pushed event from the native shell.\n *\n * @param event The event name to listen for.\n * @param callback Function to execute when the event occurs.\n * @returns An unsubscription function.\n */\n public on(event: string, callback: (data: unknown) => void) {\n let listeners = this.eventListeners.get(event);\n if (!listeners) {\n listeners = [];\n this.eventListeners.set(event, listeners);\n }\n listeners.push(callback);\n return () => this.off(event, callback);\n }\n\n /**\n * Unsubscribes a specific callback from an event.\n *\n * @param event The event name.\n * @param callback The callback function to remove.\n */\n public off(event: string, callback: (data: unknown) => void) {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n this.eventListeners.set(\n event,\n listeners.filter((cb) => cb !== callback),\n );\n }\n\n /**\n * Sends a message to the native shell and waits for a response.\n *\n * @template T The expected response type.\n * @param type The action type (e.g., \"GET_LOCATION\").\n * @param payload Data associated with the action.\n * @param timeoutMs Time in milliseconds to wait for a response before rejecting.\n * @returns A promise that resolves with the native response.\n */\n public send<T = unknown>(\n type: string,\n payload?: unknown,\n timeoutMs = 30000,\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n const callbackId = `${type}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n\n const timeout = setTimeout(() => {\n if (this.callbacks.has(callbackId)) {\n this.callbacks.delete(callbackId);\n reject(new Error(`Bridge request timeout: ${type}`));\n }\n }, timeoutMs);\n\n this.callbacks.set(callbackId, {\n reject,\n resolve: resolve as (val: unknown) => void,\n timeout,\n });\n\n const message = {\n callbackId,\n payload,\n type,\n };\n\n const win = window as unknown as {\n ReactNativeWebView?: { postMessage: (msg: string) => void };\n };\n\n if (win.ReactNativeWebView?.postMessage) {\n win.ReactNativeWebView.postMessage(JSON.stringify(message));\n } else {\n clearTimeout(timeout);\n this.callbacks.delete(callbackId);\n reject(new Error(\"Bridge not available\"));\n }\n });\n }\n\n /**\n * Internal handler for all incoming messages from the native shell.\n * Matches incoming payloads to either pending callbacks or event listeners.\n *\n * @internal\n * @param envelope The message envelope received from native code.\n */\n private handleNativeMessage(envelope: IBridgeEnvelope) {\n if (!envelope || typeof envelope !== \"object\") return;\n\n // 1. Handle Response Callbacks\n const callbackId = envelope.callbackId;\n if (callbackId && typeof callbackId === \"string\") {\n const callback = this.callbacks.get(callbackId);\n if (callback) {\n clearTimeout(callback.timeout);\n const { resolve, reject } = callback;\n\n if (envelope.success === false || envelope.error) {\n reject(envelope.error || \"Unknown error\");\n } else {\n resolve(envelope.value ?? envelope.payload ?? envelope);\n }\n\n this.callbacks.delete(callbackId);\n return;\n }\n }\n\n // 2. Handle Pushed Events\n const eventName = envelope.event;\n if (eventName && typeof eventName === \"string\") {\n const listeners = this.eventListeners.get(eventName);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(envelope.payload || envelope.value);\n } catch (e) {\n console.error(`Error in event listener for ${eventName}:`, e);\n }\n }\n }\n }\n }\n}\n","import { Bridge } from \"@miniapps-sdk/bridge\";\nimport type {\n HapticStyleType,\n IFidelityBalance,\n IFidelityHistoryParams,\n IFidelityTransaction,\n IInitializationOptions,\n IInitializationResponse,\n ILocationData,\n INetworkOptions,\n INetworkResponse,\n IPaymentRequest,\n IUserProfile,\n ScrollConfig,\n SDKEvent,\n} from \"@miniapps-sdk/types/types\";\n\n/**\n * Deep freezes an object and its nested properties.\n * @param obj The object to freeze.\n * @returns The frozen object.\n */\nfunction deepFreeze<T extends object>(obj: T): T {\n // Retrieve the property names defined on obj\n const propNames = Object.getOwnPropertyNames(obj);\n\n // Freeze properties before freezing self\n for (const name of propNames) {\n const value = (obj as Record<string, unknown>)[name];\n\n if (\n value &&\n typeof value === \"object\" &&\n !Object.isFrozen(value) &&\n // Skip freezing of native objects or circular refs if any (though not expected here)\n !(value instanceof Bridge)\n ) {\n deepFreeze(value as object);\n }\n }\n\n return Object.freeze(obj);\n}\n\n/**\n * Main SDK for UP Mini-Apps.\n * Provides access to native device features, storage, identity, and shell UI.\n */\nexport class MiniAppSDK {\n private bridge: Bridge;\n /**\n * Local SQLite Storage.\n * Data is persisted on the device and is isolated per Mini-App.\n */\n public readonly storage = Object.freeze({\n /** Retrieves a value by key. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"STORAGE_GET\", { key }),\n /** Retrieves all key-value pairs stored for this Mini-App. */\n getAll: (): Promise<Record<string, string>> =>\n this.bridge.send(\"STORAGE_GET_ALL\"),\n /** Sets a value for a specific key. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"STORAGE_SET\", { key, value }),\n });\n /**\n * Hardware-level Secure Storage.\n * Data is stored in the device's secure enclave (Keychain/Keystore) and is isolated per Mini-App.\n */\n public readonly secureStore = Object.freeze({\n /** Retrieves a value by key from secure storage. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"SECURE_GET\", { key }),\n /** Sets a value for a specific key in secure storage. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"SECURE_SET\", { key, value }),\n });\n /**\n * Database Storage.\n * Access to user-app specific persistent database storage.\n */\n public readonly database = Object.freeze({\n /** Retrieves the user data stored in the backend database. */\n getUserData: <T = unknown>(): Promise<T> =>\n this.bridge.send<T>(\"DATABASE_GET_USER_DATA\"),\n /** Updates the user data stored in the backend database. */\n setUserData: <T = unknown>(data: T): Promise<void> =>\n this.bridge.send<void>(\"DATABASE_SET_USER_DATA\", { data }),\n });\n /**\n * Device Location services.\n */\n public readonly location = Object.freeze({\n /** Retrieves the current GPS position of the device. */\n getCurrentPosition: (): Promise<ILocationData> =>\n this.bridge.send(\"GET_LOCATION\"),\n });\n /**\n * Identity & Profile management.\n */\n public readonly user = Object.freeze({\n /**\n * Fetch user profile data.\n * @param fields Optional list of specific fields to retrieve (e.g., ['fullName', 'username']).\n */\n getProfile: <T extends keyof IUserProfile>(\n fields?: T[],\n ): Promise<Partial<IUserProfile>> =>\n this.bridge.send(\"GET_USER_PROFILE\", { fields }),\n });\n /**\n * Explicit Permission Management.\n * Allows requesting access to sensitive device features or user data.\n */\n public readonly permission = Object.freeze({\n /**\n * Explicitly request access to sensitive data.\n * @param type The type of permission to request ('location' or 'profile').\n * @param fields If requesting 'profile', the specific fields required.\n */\n request: ((type: \"location\" | \"profile\", fields?: string[]) => {\n return this.bridge.send(\"REQUEST_PERMISSION\", { fields, type });\n }) as {\n (type: \"location\"): Promise<boolean>;\n (type: \"profile\", fields: (keyof IUserProfile)[]): Promise<boolean>;\n },\n });\n /**\n * Payments integration.\n */\n public readonly payment = Object.freeze({\n /**\n * Triggers the native payment flow.\n * @param payload Amount, currency, and itemized list for the payment.\n */\n request: (\n payload: IPaymentRequest,\n ): Promise<{ success: true; transactionId: string }> =>\n this.bridge.send(\"PAYMENT_REQUEST\", payload),\n });\n /**\n * Live Activities & Notifications.\n * Allows the Mini-App to display real-time updates in the host shell.\n */\n public readonly activity = Object.freeze({\n /**\n * Starts a new live activity.\n * @param id Unique identifier for the activity.\n * @param title Display title for the activity.\n * @param status Initial status message.\n */\n start: (id: string, title: string, status: string): Promise<void> =>\n this.bridge.send(\"START_ACTIVITY\", { id, status, title }),\n });\n /**\n * Haptic feedback.\n */\n public readonly haptic = Object.freeze({\n /**\n * Triggers a haptic vibration on the device.\n * @param style The style of haptic feedback (e.g., 'light', 'medium', 'heavy', 'success', 'warning', 'error').\n */\n trigger: (style: HapticStyleType): Promise<void> =>\n this.bridge.send(\"TRIGGER_HAPTIC\", { style }),\n });\n /**\n * Network Proxy.\n * Allows the Mini-App to make network requests through the host shell to bypass CORS or use host-level authentication.\n */\n public readonly network = Object.freeze({\n /**\n * Performs a network request via the host shell.\n * @param options Request method, URL, headers, and body.\n */\n request: (options: INetworkOptions): Promise<INetworkResponse> =>\n this.bridge.send(\"NETWORK_REQUEST\", options),\n });\n /**\n * Fidelity & Rewards program integration.\n */\n public readonly fidelity = Object.freeze({\n /** Returns current fidelity balance. */\n getFidelityBalance: (): Promise<IFidelityBalance> =>\n this.bridge.send(\"GET_FIDELITY_BALANCE\"),\n /**\n * Retrieves fidelity transaction history.\n * @param params Filtering and pagination parameters.\n */\n getFidelityHistory: (\n params?: IFidelityHistoryParams,\n ): Promise<IFidelityTransaction[]> =>\n this.bridge.send(\"GET_FIDELITY_HISTORY\", params),\n /**\n * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.\n * @param intentUuid UUID generated by your backend for the transaction.\n */\n spendFPoints: (\n intentUuid: string,\n ): Promise<{ success: boolean; transactionId: string }> =>\n this.bridge.send(\"SPEND_FPOINTS\", { intentUuid }),\n });\n /**\n * UI and Navigation controls.\n */\n public readonly ui = Object.freeze({\n /** Closes the Mini-App and returns to the host shell. */\n exit: (): Promise<void> => this.bridge.send(\"EXIT\"),\n /**\n * Configures native scroll behaviors like Pull-to-Refresh and Infinite Scroll.\n * @param config Scroll configuration for top/bottom detection.\n */\n setScrollConfig: (config: ScrollConfig): Promise<void> =>\n this.bridge.send(\"SET_SCROLL_CONFIG\", config),\n });\n /**\n * Debug controls\n */\n public readonly debug = Object.freeze({\n /**\n * Log to the shell app\n * @param message\n */\n log: (...message: unknown[]) => this.bridge.send(\"DEBUG_LOG\", { message }),\n });\n\n constructor() {\n this.bridge = new Bridge();\n\n // Bind methods to this instance to preserve context if pulled out\n this.initialize = this.initialize.bind(this);\n this.on = this.on.bind(this);\n this.off = this.off.bind(this);\n }\n\n /**\n * The starting point for the Mini-App. Must be called before any other SDK methods.\n * @param options The options to provide to the shell app\n */\n public initialize(\n options: IInitializationOptions,\n ): Promise<IInitializationResponse> {\n return this.bridge.send(\"INITIALIZE\", options);\n }\n\n /**\n * Registers a callback for a specific event from the native shell.\n * @param event The name of the event to listen for.\n * @param callback The function to execute when the event is triggered.\n * @returns A function to unregister the listener.\n */\n public on(event: SDKEvent, callback: (data: unknown) => void) {\n return this.bridge.on(event as string, callback);\n }\n\n /**\n * Unregisters a previously registered event listener.\n * @param event The name of the event.\n * @param callback The callback function to remove.\n */\n public off(event: SDKEvent, callback: (data: unknown) => void) {\n this.bridge.off(event as string, callback);\n }\n}\n\n/**\n * Singleton instance of the MiniAppSDK.\n * Frozen to prevent tampering.\n */\nexport const sdk = deepFreeze(new MiniAppSDK());\n","/**\n * UP Mini-App SDK Types\n */\n\n/**\n * Represents the user's profile information.\n */\nexport interface IUserProfile {\n /** Unique identifier for the user. */\n uuid: string;\n /** Full legal name of the user. */\n fullName: string;\n /** Primary email address. */\n email: string;\n /** Chosen username within the UP ecosystem. */\n username: string;\n /** ISO country code (e.g., \"FR\", \"US\"). */\n countryCode: string;\n /** Phone number without country code. */\n localNumber: string;\n}\n\n/**\n * Geographic location data.\n */\nexport interface ILocationData {\n coords: {\n /** Latitude in decimal degrees. */\n latitude: number;\n /** Longitude in decimal degrees. */\n longitude: number;\n /** Altitude in meters above the WGS 84 reference ellipsoid, or null if not available. */\n altitude: number | null;\n /** Accuracy of the latitude and longitude properties in meters. */\n accuracy: number | null;\n /** Accuracy of the altitude property in meters. */\n altitudeAccuracy: number | null;\n /** The direction in which the device is traveling, in degrees (0-360). */\n heading: number | null;\n /** The velocity of the device in meters per second. */\n speed: number | null;\n };\n /** The time at which the location was retrieved (Unix timestamp). */\n timestamp: number;\n}\n\n/**\n * Request payload for triggering a payment flow.\n */\nexport interface IPaymentRequest {\n /** The specific amount to charge. */\n amount: number;\n /** ISO currency code (e.g., \"EUR\", \"USD\"). */\n currency: string;\n /** Total amount including taxes/fees. */\n total: number;\n /** Itemized breakdown of the purchase. */\n items: Array<{\n /** Name or description of the item. */\n item: string;\n /** Price per unit. */\n price?: number;\n /** Number of units. */\n quantity?: number;\n }>;\n}\n\n/**\n * Style of haptic feedback.\n */\nexport type HapticStyleType =\n | \"light\"\n | \"medium\"\n | \"heavy\"\n | \"rigid\"\n | \"soft\"\n | \"success\"\n | \"warning\"\n | \"error\";\n\n/**\n * Network Proxy Types\n */\n\n/**\n * The HTTP method to use as request method\n */\nexport type NetworkMethodType = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\n/**\n * Configuration for network proxy requests.\n */\nexport interface INetworkOptions {\n /** Full URL for the request. */\n url: string;\n /** HTTP method to use. */\n method: NetworkMethodType;\n /** Request body for POST/PUT/PATCH. */\n body?: unknown;\n /** Custom HTTP headers. */\n headers?: Record<string, string>;\n}\n\n/**\n * Response from a network proxy request.\n */\nexport interface INetworkResponse<T = unknown> {\n /** HTTP status code. */\n status: number;\n /** Response data payload. */\n data: T;\n /** Response headers. */\n headers: Headers;\n}\n\n/**\n * Fidelity & Rewards Types\n */\n\n/**\n * Fidelity program balance information.\n */\nexport interface IFidelityBalance {\n /** Current point or currency balance. */\n balance: number;\n /** Name or symbol of the fidelity currency (e.g., \"FPoints\"). */\n currency: string;\n}\n\n/**\n * Parameters for retrieving fidelity transaction history.\n */\nexport interface IFidelityHistoryParams {\n /** Maximum number of records to return. */\n limit?: number;\n\n /** Cursor for pagination; null for the first page. */\n cursor?: string | null;\n}\n\n/** Type of transaction: credit (add) or debit (remove). */\nexport type FidelityTransactionTypeType = \"credit\" | \"debit\";\n\n/**\n * A single fidelity program transaction.\n */\nexport interface IFidelityTransaction {\n /** Unique identifier for the transaction. */\n id: string;\n /** Amount of the transaction. */\n amount: number;\n /** Human-readable description. */\n description: string;\n /** ISO 8601 date string. */\n date: string;\n /** Type of transaction */\n type: FidelityTransactionTypeType;\n}\n\n/**\n * The initialization options required to set up the Mini-App SDK.\n */\nexport type IInitializationOptions = {};\n\n/**\n * The post initialization response\n */\nexport interface IInitializationResponse<\n Env extends Record<string, unknown> = Record<string, unknown>,\n UserData extends Record<string, unknown> = Record<string, unknown>,\n Params extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** The name of the mini app */\n name: string;\n /** The uuid of the mini app */\n uuid: string;\n /** The description of the mini app */\n description: string;\n /** The authors of the mini app */\n authors?: string;\n /** The current version in the registry */\n version?: string;\n /** The scoped profile based on the requested fields during initialization or the getUserProfile call */\n profile: Partial<IUserProfile | null>;\n /** The environment variables defined for the mini app in the shell's backend */\n env: Env;\n /** The user data passed during the initialization or the setUserData call */\n userData: UserData;\n /** The params passed during the initialization */\n params: Params;\n}\n\n/**\n * Events emitted by the UI module.\n */\nexport enum UIEvent {\n /** Triggered when the user performs a native \"Pull-to-Refresh\". */\n TOP_SCROLL_MORE = \"TOP_SCROLL_MORE\",\n /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */\n BOTTOM_SCROLL_MORE = \"BOTTOM_SCROLL_MORE\",\n}\n\n/**\n * Union type for all SDK events, allowing for both known enums and custom strings.\n * The (string & {}) pattern preserves IntelliSense for enum members.\n */\nexport type SDKEvent = UIEvent | (string & {});\n\n/**\n * Configuration for native scroll interactions managed by the Host Shell.\n */\nexport interface ScrollConfig {\n /** Configuration for Pull-to-Refresh (Top). */\n topScrollMore?: {\n /** Show/hide the native RefreshControl. */\n enabled: boolean;\n /** Set to true to show the loading spinner, false to hide it. */\n refreshing?: boolean;\n };\n /** Configuration for Infinite Scroll (Bottom). */\n bottomScrollMore?: {\n /** Enable/disable bottom scroll detection. */\n enabled: boolean;\n /** If false, detection stops and the indicator is hidden. */\n hasMore?: boolean;\n /** Set to true to show the bottom ActivityIndicator. */\n loadingMore?: boolean;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,SAAN,MAAa;AAAA,EACV,YAAY,oBAAI,IAOtB;AAAA,EACM,iBAAiB,oBAAI,IAAyC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtE,cAAc;AACZ,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,iBAAiB,OAAO,OAAO;AAAA,QACnC,iBAAiB,CAAC,aAChB,KAAK,oBAAoB,QAAQ;AAAA,MACrC,CAAC;AAGD,aAAO,eAAe,QAAQ,mBAAmB;AAAA,QAC/C,cAAc;AAAA,QACd,OAAO;AAAA,QACP,UAAU;AAAA,MACZ,CAAC;AAED,aAAO,iBAAiB,WAAW,CAAC,UAAU;AAI5C,YAAI,CAAC,MAAM,KAAM;AAEjB,YAAI;AACF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IEvent"]}
|
package/dist/index.mjs
CHANGED
|
@@ -13,9 +13,9 @@ var Bridge = class {
|
|
|
13
13
|
onNativeMessage: (envelope) => this.handleNativeMessage(envelope)
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(window, "__MiniAppBridge", {
|
|
16
|
+
configurable: false,
|
|
16
17
|
value: bridgeReceiver,
|
|
17
|
-
writable: false
|
|
18
|
-
configurable: false
|
|
18
|
+
writable: false
|
|
19
19
|
});
|
|
20
20
|
window.addEventListener("message", (event) => {
|
|
21
21
|
if (!event.data) return;
|
|
@@ -29,44 +29,6 @@ var Bridge = class {
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Internal handler for all incoming messages from the native shell.
|
|
34
|
-
* Matches incoming payloads to either pending callbacks or event listeners.
|
|
35
|
-
*
|
|
36
|
-
* @internal
|
|
37
|
-
* @param envelope The message envelope received from native code.
|
|
38
|
-
*/
|
|
39
|
-
handleNativeMessage(envelope) {
|
|
40
|
-
if (!envelope || typeof envelope !== "object") return;
|
|
41
|
-
const callbackId = envelope.callbackId;
|
|
42
|
-
if (callbackId && typeof callbackId === "string") {
|
|
43
|
-
const callback = this.callbacks.get(callbackId);
|
|
44
|
-
if (callback) {
|
|
45
|
-
clearTimeout(callback.timeout);
|
|
46
|
-
const { resolve, reject } = callback;
|
|
47
|
-
if (envelope.success === false || envelope.error) {
|
|
48
|
-
reject(envelope.error || "Unknown error");
|
|
49
|
-
} else {
|
|
50
|
-
resolve(envelope.value ?? envelope.payload ?? envelope);
|
|
51
|
-
}
|
|
52
|
-
this.callbacks.delete(callbackId);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const eventName = envelope.event;
|
|
57
|
-
if (eventName && typeof eventName === "string") {
|
|
58
|
-
const listeners = this.eventListeners.get(eventName);
|
|
59
|
-
if (listeners) {
|
|
60
|
-
for (const listener of listeners) {
|
|
61
|
-
try {
|
|
62
|
-
listener(envelope.payload || envelope.value);
|
|
63
|
-
} catch (e) {
|
|
64
|
-
console.error(`Error in event listener for ${eventName}:`, e);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
32
|
/**
|
|
71
33
|
* Subscribes to a pushed event from the native shell.
|
|
72
34
|
*
|
|
@@ -135,6 +97,44 @@ var Bridge = class {
|
|
|
135
97
|
}
|
|
136
98
|
});
|
|
137
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Internal handler for all incoming messages from the native shell.
|
|
102
|
+
* Matches incoming payloads to either pending callbacks or event listeners.
|
|
103
|
+
*
|
|
104
|
+
* @internal
|
|
105
|
+
* @param envelope The message envelope received from native code.
|
|
106
|
+
*/
|
|
107
|
+
handleNativeMessage(envelope) {
|
|
108
|
+
if (!envelope || typeof envelope !== "object") return;
|
|
109
|
+
const callbackId = envelope.callbackId;
|
|
110
|
+
if (callbackId && typeof callbackId === "string") {
|
|
111
|
+
const callback = this.callbacks.get(callbackId);
|
|
112
|
+
if (callback) {
|
|
113
|
+
clearTimeout(callback.timeout);
|
|
114
|
+
const { resolve, reject } = callback;
|
|
115
|
+
if (envelope.success === false || envelope.error) {
|
|
116
|
+
reject(envelope.error || "Unknown error");
|
|
117
|
+
} else {
|
|
118
|
+
resolve(envelope.value ?? envelope.payload ?? envelope);
|
|
119
|
+
}
|
|
120
|
+
this.callbacks.delete(callbackId);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const eventName = envelope.event;
|
|
125
|
+
if (eventName && typeof eventName === "string") {
|
|
126
|
+
const listeners = this.eventListeners.get(eventName);
|
|
127
|
+
if (listeners) {
|
|
128
|
+
for (const listener of listeners) {
|
|
129
|
+
try {
|
|
130
|
+
listener(envelope.payload || envelope.value);
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.error(`Error in event listener for ${eventName}:`, e);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
// src/sdk.ts
|
|
@@ -151,19 +151,6 @@ function deepFreeze(obj) {
|
|
|
151
151
|
}
|
|
152
152
|
var MiniAppSDK = class {
|
|
153
153
|
bridge;
|
|
154
|
-
constructor() {
|
|
155
|
-
this.bridge = new Bridge();
|
|
156
|
-
this.initialize = this.initialize.bind(this);
|
|
157
|
-
this.on = this.on.bind(this);
|
|
158
|
-
this.off = this.off.bind(this);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
162
|
-
* @param options The options to provide to the shell app
|
|
163
|
-
*/
|
|
164
|
-
initialize(options) {
|
|
165
|
-
return this.bridge.send("INITIALIZE", options);
|
|
166
|
-
}
|
|
167
154
|
/**
|
|
168
155
|
* Local SQLite Storage.
|
|
169
156
|
* Data is persisted on the device and is isolated per Mini-App.
|
|
@@ -310,6 +297,19 @@ var MiniAppSDK = class {
|
|
|
310
297
|
*/
|
|
311
298
|
log: (...message) => this.bridge.send("DEBUG_LOG", { message })
|
|
312
299
|
});
|
|
300
|
+
constructor() {
|
|
301
|
+
this.bridge = new Bridge();
|
|
302
|
+
this.initialize = this.initialize.bind(this);
|
|
303
|
+
this.on = this.on.bind(this);
|
|
304
|
+
this.off = this.off.bind(this);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The starting point for the Mini-App. Must be called before any other SDK methods.
|
|
308
|
+
* @param options The options to provide to the shell app
|
|
309
|
+
*/
|
|
310
|
+
initialize(options) {
|
|
311
|
+
return this.bridge.send("INITIALIZE", options);
|
|
312
|
+
}
|
|
313
313
|
/**
|
|
314
314
|
* Registers a callback for a specific event from the native shell.
|
|
315
315
|
* @param event The name of the event to listen for.
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bridge.ts","../src/sdk.ts","../src/types/types.ts","../src/index.ts"],"sourcesContent":["import type { IBridgeEnvelope } from \"@miniapps-sdk/types\";\n\n/**\n * The Bridge handles low-level communication between the Mini-App WebView\n * and the Native Host Shell (iOS/Android).\n *\n * It manages asynchronous request-response cycles via callbacks and\n * supports subscription to pushed events from the native environment.\n */\nexport class Bridge {\n private callbacks = new Map<\n string,\n {\n resolve: (val: unknown) => void;\n reject: (err: unknown) => void;\n timeout: ReturnType<typeof setTimeout>;\n }\n >();\n private eventListeners = new Map<string, ((data: unknown) => void)[]>();\n\n /**\n * Registers a global listener for messages coming from the native shell.\n * Also listens for standard browser `message` events to support multiple\n * communication channels (e.g., React Native WebView postMessage).\n */\n constructor() {\n if (typeof window !== \"undefined\") {\n const bridgeReceiver = Object.freeze({\n onNativeMessage: (envelope: IBridgeEnvelope) =>\n this.handleNativeMessage(envelope),\n });\n\n // Use defineProperty to prevent re-assignment or deletion of the bridge\n Object.defineProperty(window, \"__MiniAppBridge\", {\n value: bridgeReceiver,\n writable: false,\n configurable: false,\n });\n\n window.addEventListener(\"message\", (event) => {\n // SECURITY: Filter events. If inside a mobile shell, the origin of native postMessage\n // varies by platform (e.g., file://, or specific app schemes).\n // For production, this should be restricted to the expected host origin.\n if (!event.data) return;\n\n try {\n const data =\n typeof event.data === \"string\"\n ? JSON.parse(event.data)\n : event.data;\n\n // SECURITY: Basic envelope validation\n if (data && typeof data === \"object\" && (data.callbackId || data.event)) {\n this.handleNativeMessage(data);\n }\n } catch (_e) {\n // Ignore non-JSON or malformed messages\n }\n });\n }\n }\n\n /**\n * Internal handler for all incoming messages from the native shell.\n * Matches incoming payloads to either pending callbacks or event listeners.\n *\n * @internal\n * @param envelope The message envelope received from native code.\n */\n private handleNativeMessage(envelope: IBridgeEnvelope) {\n if (!envelope || typeof envelope !== \"object\") return;\n\n // 1. Handle Response Callbacks\n const callbackId = envelope.callbackId;\n if (callbackId && typeof callbackId === \"string\") {\n const callback = this.callbacks.get(callbackId);\n if (callback) {\n clearTimeout(callback.timeout);\n const { resolve, reject } = callback;\n\n if (envelope.success === false || envelope.error) {\n reject(envelope.error || \"Unknown error\");\n } else {\n resolve(envelope.value ?? envelope.payload ?? envelope);\n }\n\n this.callbacks.delete(callbackId);\n return;\n }\n }\n\n // 2. Handle Pushed Events\n const eventName = envelope.event;\n if (eventName && typeof eventName === \"string\") {\n const listeners = this.eventListeners.get(eventName);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(envelope.payload || envelope.value);\n } catch (e) {\n console.error(`Error in event listener for ${eventName}:`, e);\n }\n }\n }\n }\n }\n\n /**\n * Subscribes to a pushed event from the native shell.\n *\n * @param event The event name to listen for.\n * @param callback Function to execute when the event occurs.\n * @returns An unsubscription function.\n */\n public on(event: string, callback: (data: unknown) => void) {\n let listeners = this.eventListeners.get(event);\n if (!listeners) {\n listeners = [];\n this.eventListeners.set(event, listeners);\n }\n listeners.push(callback);\n return () => this.off(event, callback);\n }\n\n /**\n * Unsubscribes a specific callback from an event.\n *\n * @param event The event name.\n * @param callback The callback function to remove.\n */\n public off(event: string, callback: (data: unknown) => void) {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n this.eventListeners.set(\n event,\n listeners.filter((cb) => cb !== callback),\n );\n }\n\n /**\n * Sends a message to the native shell and waits for a response.\n *\n * @template T The expected response type.\n * @param type The action type (e.g., \"GET_LOCATION\").\n * @param payload Data associated with the action.\n * @param timeoutMs Time in milliseconds to wait for a response before rejecting.\n * @returns A promise that resolves with the native response.\n */\n public send<T = unknown>(\n type: string,\n payload?: unknown,\n timeoutMs = 30000,\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n const callbackId = `${type}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n\n const timeout = setTimeout(() => {\n if (this.callbacks.has(callbackId)) {\n this.callbacks.delete(callbackId);\n reject(new Error(`Bridge request timeout: ${type}`));\n }\n }, timeoutMs);\n\n this.callbacks.set(callbackId, {\n reject,\n resolve: resolve as (val: unknown) => void,\n timeout,\n });\n\n const message = {\n callbackId,\n payload,\n type,\n };\n\n const win = window as unknown as {\n ReactNativeWebView?: { postMessage: (msg: string) => void };\n };\n\n if (win.ReactNativeWebView?.postMessage) {\n win.ReactNativeWebView.postMessage(JSON.stringify(message));\n } else {\n clearTimeout(timeout);\n this.callbacks.delete(callbackId);\n reject(new Error(\"Bridge not available\"));\n }\n });\n }\n}\n","import { Bridge } from \"@miniapps-sdk/bridge\";\nimport type {\n HapticStyleType,\n IFidelityBalance,\n IFidelityHistoryParams,\n IFidelityTransaction,\n IInitializationOptions,\n IInitializationResponse,\n ILocationData,\n INetworkOptions,\n INetworkResponse,\n IPaymentRequest,\n IUserProfile,\n ScrollConfig,\n SDKEvent,\n} from \"@miniapps-sdk/types/types\";\n\n/**\n * Deep freezes an object and its nested properties.\n * @param obj The object to freeze.\n * @returns The frozen object.\n */\nfunction deepFreeze<T extends object>(obj: T): T {\n // Retrieve the property names defined on obj\n const propNames = Object.getOwnPropertyNames(obj);\n\n // Freeze properties before freezing self\n for (const name of propNames) {\n const value = (obj as Record<string, unknown>)[name];\n\n if (\n value &&\n typeof value === \"object\" &&\n !Object.isFrozen(value) &&\n // Skip freezing of native objects or circular refs if any (though not expected here)\n !(value instanceof Bridge)\n ) {\n deepFreeze(value as object);\n }\n }\n\n return Object.freeze(obj);\n}\n\n/**\n * Main SDK for UP Mini-Apps.\n * Provides access to native device features, storage, identity, and shell UI.\n */\nexport class MiniAppSDK {\n private bridge: Bridge;\n\n constructor() {\n this.bridge = new Bridge();\n\n // Bind methods to this instance to preserve context if pulled out\n this.initialize = this.initialize.bind(this);\n this.on = this.on.bind(this);\n this.off = this.off.bind(this);\n }\n\n /**\n * The starting point for the Mini-App. Must be called before any other SDK methods.\n * @param options The options to provide to the shell app\n */\n public initialize(\n options: IInitializationOptions,\n ): Promise<IInitializationResponse> {\n return this.bridge.send(\"INITIALIZE\", options);\n }\n\n /**\n * Local SQLite Storage.\n * Data is persisted on the device and is isolated per Mini-App.\n */\n public readonly storage = Object.freeze({\n /** Retrieves a value by key. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"STORAGE_GET\", { key }),\n /** Retrieves all key-value pairs stored for this Mini-App. */\n getAll: (): Promise<Record<string, string>> =>\n this.bridge.send(\"STORAGE_GET_ALL\"),\n /** Sets a value for a specific key. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"STORAGE_SET\", { key, value }),\n });\n\n /**\n * Hardware-level Secure Storage.\n * Data is stored in the device's secure enclave (Keychain/Keystore) and is isolated per Mini-App.\n */\n public readonly secureStore = Object.freeze({\n /** Retrieves a value by key from secure storage. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"SECURE_GET\", { key }),\n /** Sets a value for a specific key in secure storage. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"SECURE_SET\", { key, value }),\n });\n\n /**\n * Database Storage.\n * Access to user-app specific persistent database storage.\n */\n public readonly database = Object.freeze({\n /** Retrieves the user data stored in the backend database. */\n getUserData: <T = unknown>(): Promise<T> =>\n this.bridge.send<T>(\"DATABASE_GET_USER_DATA\"),\n /** Updates the user data stored in the backend database. */\n setUserData: <T = unknown>(data: T): Promise<void> =>\n this.bridge.send<void>(\"DATABASE_SET_USER_DATA\", { data }),\n });\n\n /**\n * Device Location services.\n */\n public readonly location = Object.freeze({\n /** Retrieves the current GPS position of the device. */\n getCurrentPosition: (): Promise<ILocationData> =>\n this.bridge.send(\"GET_LOCATION\"),\n });\n\n /**\n * Identity & Profile management.\n */\n public readonly user = Object.freeze({\n /**\n * Fetch user profile data.\n * @param fields Optional list of specific fields to retrieve (e.g., ['fullName', 'username']).\n */\n getProfile: <T extends keyof IUserProfile>(\n fields?: T[],\n ): Promise<Partial<IUserProfile>> =>\n this.bridge.send(\"GET_USER_PROFILE\", { fields }),\n });\n\n /**\n * Explicit Permission Management.\n * Allows requesting access to sensitive device features or user data.\n */\n public readonly permission = Object.freeze({\n /**\n * Explicitly request access to sensitive data.\n * @param type The type of permission to request ('location' or 'profile').\n * @param fields If requesting 'profile', the specific fields required.\n */\n request: ((type: \"location\" | \"profile\", fields?: string[]) => {\n return this.bridge.send(\"REQUEST_PERMISSION\", { fields, type });\n }) as {\n (type: \"location\"): Promise<boolean>;\n (type: \"profile\", fields: (keyof IUserProfile)[]): Promise<boolean>;\n },\n });\n\n /**\n * Payments integration.\n */\n public readonly payment = Object.freeze({\n /**\n * Triggers the native payment flow.\n * @param payload Amount, currency, and itemized list for the payment.\n */\n request: (\n payload: IPaymentRequest,\n ): Promise<{ success: true; transactionId: string }> =>\n this.bridge.send(\"PAYMENT_REQUEST\", payload),\n });\n\n /**\n * Live Activities & Notifications.\n * Allows the Mini-App to display real-time updates in the host shell.\n */\n public readonly activity = Object.freeze({\n /**\n * Starts a new live activity.\n * @param id Unique identifier for the activity.\n * @param title Display title for the activity.\n * @param status Initial status message.\n */\n start: (id: string, title: string, status: string): Promise<void> =>\n this.bridge.send(\"START_ACTIVITY\", { id, status, title }),\n });\n\n /**\n * Haptic feedback.\n */\n public readonly haptic = Object.freeze({\n /**\n * Triggers a haptic vibration on the device.\n * @param style The style of haptic feedback (e.g., 'light', 'medium', 'heavy', 'success', 'warning', 'error').\n */\n trigger: (style: HapticStyleType): Promise<void> =>\n this.bridge.send(\"TRIGGER_HAPTIC\", { style }),\n });\n\n /**\n * Network Proxy.\n * Allows the Mini-App to make network requests through the host shell to bypass CORS or use host-level authentication.\n */\n public readonly network = Object.freeze({\n /**\n * Performs a network request via the host shell.\n * @param options Request method, URL, headers, and body.\n */\n request: (options: INetworkOptions): Promise<INetworkResponse> =>\n this.bridge.send(\"NETWORK_REQUEST\", options),\n });\n\n /**\n * Fidelity & Rewards program integration.\n */\n public readonly fidelity = Object.freeze({\n /** Returns current fidelity balance. */\n getFidelityBalance: (): Promise<IFidelityBalance> =>\n this.bridge.send(\"GET_FIDELITY_BALANCE\"),\n /**\n * Retrieves fidelity transaction history.\n * @param params Filtering and pagination parameters.\n */\n getFidelityHistory: (\n params?: IFidelityHistoryParams,\n ): Promise<IFidelityTransaction[]> =>\n this.bridge.send(\"GET_FIDELITY_HISTORY\", params),\n /**\n * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.\n * @param intentUuid UUID generated by your backend for the transaction.\n */\n spendFPoints: (\n intentUuid: string,\n ): Promise<{ success: boolean; transactionId: string }> =>\n this.bridge.send(\"SPEND_FPOINTS\", { intentUuid }),\n });\n\n /**\n * UI and Navigation controls.\n */\n public readonly ui = Object.freeze({\n /** Closes the Mini-App and returns to the host shell. */\n exit: (): Promise<void> => this.bridge.send(\"EXIT\"),\n /**\n * Configures native scroll behaviors like Pull-to-Refresh and Infinite Scroll.\n * @param config Scroll configuration for top/bottom detection.\n */\n setScrollConfig: (config: ScrollConfig): Promise<void> =>\n this.bridge.send(\"SET_SCROLL_CONFIG\", config),\n });\n\n /**\n * Debug controls\n */\n public readonly debug = Object.freeze({\n /**\n * Log to the shell app\n * @param message\n */\n log: (...message: unknown[]) => this.bridge.send(\"DEBUG_LOG\", { message }),\n });\n\n /**\n * Registers a callback for a specific event from the native shell.\n * @param event The name of the event to listen for.\n * @param callback The function to execute when the event is triggered.\n * @returns A function to unregister the listener.\n */\n public on(event: SDKEvent, callback: (data: unknown) => void) {\n return this.bridge.on(event as string, callback);\n }\n\n /**\n * Unregisters a previously registered event listener.\n * @param event The name of the event.\n * @param callback The callback function to remove.\n */\n public off(event: SDKEvent, callback: (data: unknown) => void) {\n this.bridge.off(event as string, callback);\n }\n}\n\n/**\n * Singleton instance of the MiniAppSDK.\n * Frozen to prevent tampering.\n */\nexport const sdk = deepFreeze(new MiniAppSDK());\n","/**\n * UP Mini-App SDK Types\n */\n\n/**\n * Represents the user's profile information.\n */\nexport interface IUserProfile {\n /** Unique identifier for the user. */\n uuid: string;\n /** Full legal name of the user. */\n fullName: string;\n /** Primary email address. */\n email: string;\n /** Chosen username within the UP ecosystem. */\n username: string;\n /** ISO country code (e.g., \"FR\", \"US\"). */\n countryCode: string;\n /** Phone number without country code. */\n localNumber: string;\n}\n\n/**\n * Geographic location data.\n */\nexport interface ILocationData {\n coords: {\n /** Latitude in decimal degrees. */\n latitude: number;\n /** Longitude in decimal degrees. */\n longitude: number;\n /** Altitude in meters above the WGS 84 reference ellipsoid, or null if not available. */\n altitude: number | null;\n /** Accuracy of the latitude and longitude properties in meters. */\n accuracy: number | null;\n /** Accuracy of the altitude property in meters. */\n altitudeAccuracy: number | null;\n /** The direction in which the device is traveling, in degrees (0-360). */\n heading: number | null;\n /** The velocity of the device in meters per second. */\n speed: number | null;\n };\n /** The time at which the location was retrieved (Unix timestamp). */\n timestamp: number;\n}\n\n/**\n * Request payload for triggering a payment flow.\n */\nexport interface IPaymentRequest {\n /** The specific amount to charge. */\n amount: number;\n /** ISO currency code (e.g., \"EUR\", \"USD\"). */\n currency: string;\n /** Total amount including taxes/fees. */\n total: number;\n /** Itemized breakdown of the purchase. */\n items: Array<{\n /** Name or description of the item. */\n item: string;\n /** Price per unit. */\n price?: number;\n /** Number of units. */\n quantity?: number;\n }>;\n}\n\n/**\n * Style of haptic feedback.\n */\nexport type HapticStyleType =\n | \"light\"\n | \"medium\"\n | \"heavy\"\n | \"rigid\"\n | \"soft\"\n | \"success\"\n | \"warning\"\n | \"error\";\n\n/**\n * Network Proxy Types\n */\n\n/**\n * The HTTP method to use as request method\n */\nexport type NetworkMethodType = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\n/**\n * Configuration for network proxy requests.\n */\nexport interface INetworkOptions {\n /** Full URL for the request. */\n url: string;\n /** HTTP method to use. */\n method: NetworkMethodType;\n /** Request body for POST/PUT/PATCH. */\n body?: unknown;\n /** Custom HTTP headers. */\n headers?: Record<string, string>;\n}\n\n/**\n * Response from a network proxy request.\n */\nexport interface INetworkResponse<T = unknown> {\n /** HTTP status code. */\n status: number;\n /** Response data payload. */\n data: T;\n /** Response headers. */\n headers: Headers;\n}\n\n/**\n * Fidelity & Rewards Types\n */\n\n/**\n * Fidelity program balance information.\n */\nexport interface IFidelityBalance {\n /** Current point or currency balance. */\n balance: number;\n /** Name or symbol of the fidelity currency (e.g., \"FPoints\"). */\n currency: string;\n}\n\n/**\n * Parameters for retrieving fidelity transaction history.\n */\nexport interface IFidelityHistoryParams {\n /** Maximum number of records to return. */\n limit?: number;\n\n /** Cursor for pagination; null for the first page. */\n cursor?: string | null;\n}\n\n/** Type of transaction: credit (add) or debit (remove). */\nexport type FidelityTransactionTypeType = \"credit\" | \"debit\";\n\n/**\n * A single fidelity program transaction.\n */\nexport interface IFidelityTransaction {\n /** Unique identifier for the transaction. */\n id: string;\n /** Amount of the transaction. */\n amount: number;\n /** Human-readable description. */\n description: string;\n /** ISO 8601 date string. */\n date: string;\n /** Type of transaction */\n type: FidelityTransactionTypeType;\n}\n\n/**\n * The initialization options required to set up the Mini-App SDK.\n */\nexport type IInitializationOptions = {};\n\n/**\n * The post initialization response\n */\nexport interface IInitializationResponse<\n Env extends Record<string, unknown> = Record<string, unknown>,\n UserData extends Record<string, unknown> = Record<string, unknown>,\n Params extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** The name of the mini app */\n name: string;\n /** The uuid of the mini app */\n uuid: string;\n /** The description of the mini app */\n description: string;\n /** The authors of the mini app */\n authors?: string;\n /** The current version in the registry */\n version?: string;\n /** The scoped profile based on the requested fields during initialization or the getUserProfile call */\n profile: Partial<IUserProfile | null>;\n /** The environment variables defined for the mini app in the shell's backend */\n env: Env;\n /** The user data passed during the initialization or the setUserData call */\n userData: UserData;\n /** The params passed during the initialization */\n params: Params;\n}\n\n/**\n * Events emitted by the UI module.\n */\nexport enum UIEvent {\n /** Triggered when the user performs a native \"Pull-to-Refresh\". */\n TOP_SCROLL_MORE = \"TOP_SCROLL_MORE\",\n /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */\n BOTTOM_SCROLL_MORE = \"BOTTOM_SCROLL_MORE\",\n}\n\n/**\n * Union type for all SDK events, allowing for both known enums and custom strings.\n * The (string & {}) pattern preserves IntelliSense for enum members.\n */\nexport type SDKEvent = UIEvent | (string & {});\n\n/**\n * Configuration for native scroll interactions managed by the Host Shell.\n */\nexport interface ScrollConfig {\n /** Configuration for Pull-to-Refresh (Top). */\n topScrollMore?: {\n /** Show/hide the native RefreshControl. */\n enabled: boolean;\n /** Set to true to show the loading spinner, false to hide it. */\n refreshing?: boolean;\n };\n /** Configuration for Infinite Scroll (Bottom). */\n bottomScrollMore?: {\n /** Enable/disable bottom scroll detection. */\n enabled: boolean;\n /** If false, detection stops and the indicator is hidden. */\n hasMore?: boolean;\n /** Set to true to show the bottom ActivityIndicator. */\n loadingMore?: boolean;\n };\n}\n","export { MiniAppSDK, sdk } from \"@miniapps-sdk/sdk\";\nexport * from \"@miniapps-sdk/types\";\n\nimport { sdk } from \"@miniapps-sdk/sdk\";\nexport default sdk;\n"],"mappings":";AASO,IAAM,SAAN,MAAa;AAAA,EACV,YAAY,oBAAI,IAOtB;AAAA,EACM,iBAAiB,oBAAI,IAAyC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtE,cAAc;AACZ,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,iBAAiB,OAAO,OAAO;AAAA,QACnC,iBAAiB,CAAC,aAChB,KAAK,oBAAoB,QAAQ;AAAA,MACrC,CAAC;AAGD,aAAO,eAAe,QAAQ,mBAAmB;AAAA,QAC/C,OAAO;AAAA,QACP,UAAU;AAAA,QACV,cAAc;AAAA,MAChB,CAAC;AAED,aAAO,iBAAiB,WAAW,CAAC,UAAU;AAI5C,YAAI,CAAC,MAAM,KAAM;AAEjB,YAAI;AACF,gBAAM,OACJ,OAAO,MAAM,SAAS,WAClB,KAAK,MAAM,MAAM,IAAI,IACrB,MAAM;AAGZ,cAAI,QAAQ,OAAO,SAAS,aAAa,KAAK,cAAc,KAAK,QAAQ;AACvE,iBAAK,oBAAoB,IAAI;AAAA,UAC/B;AAAA,QACF,SAAS,IAAI;AAAA,QAEb;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AA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B,CAClB,WAEA,KAAK,OAAO,KAAK,wBAAwB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,IAKjD,cAAc,CACZ,eAEA,KAAK,OAAO,KAAK,iBAAiB,EAAE,WAAW,CAAC;AAAA,EACpD,CAAC;AAAA;AAAA;AAAA;AAAA,EAKe,KAAK,OAAO,OAAO;AAAA;AAAA,IAEjC,MAAM,MAAqB,KAAK,OAAO,KAAK,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,IAKlD,iBAAiB,CAAC,WAChB,KAAK,OAAO,KAAK,qBAAqB,MAAM;AAAA,EAChD,CAAC;AAAA;AAAA;AAAA;AAAA,EAKe,QAAQ,OAAO,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,IAKpC,KAAK,IAAI,YAAuB,KAAK,OAAO,KAAK,aAAa,EAAE,QAAQ,CAAC;AAAA,EAC3E,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQM,GAAG,OAAiB,UAAmC;AAC5D,WAAO,KAAK,OAAO,GAAG,OAAiB,QAAQ;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,IAAI,OAAiB,UAAmC;AAC7D,SAAK,OAAO,IAAI,OAAiB,QAAQ;AAAA,EAC3C;AACF;AAMO,IAAM,MAAM,WAAW,IAAI,WAAW,CAAC;;;ACtFvC,IAAK,UAAL,kBAAKA,aAAL;AAEL,EAAAA,SAAA,qBAAkB;AAElB,EAAAA,SAAA,wBAAqB;AAJX,SAAAA;AAAA,GAAA;;;AC/LZ,IAAO,gBAAQ;","names":["UIEvent"]}
|
|
1
|
+
{"version":3,"sources":["../src/bridge.ts","../src/sdk.ts","../src/types/types.ts","../src/index.ts"],"sourcesContent":["import type { IBridgeEnvelope } from \"@miniapps-sdk/types\";\n\n/**\n * The Bridge handles low-level communication between the Mini-App WebView\n * and the Native Host Shell (iOS/Android).\n *\n * It manages asynchronous request-response cycles via callbacks and\n * supports subscription to pushed events from the native environment.\n */\nexport class Bridge {\n private callbacks = new Map<\n string,\n {\n resolve: (val: unknown) => void;\n reject: (err: unknown) => void;\n timeout: ReturnType<typeof setTimeout>;\n }\n >();\n private eventListeners = new Map<string, ((data: unknown) => void)[]>();\n\n /**\n * Registers a global listener for messages coming from the native shell.\n * Also listens for standard browser `message` events to support multiple\n * communication channels (e.g., React Native WebView postMessage).\n */\n constructor() {\n if (typeof window !== \"undefined\") {\n const bridgeReceiver = Object.freeze({\n onNativeMessage: (envelope: IBridgeEnvelope) =>\n this.handleNativeMessage(envelope),\n });\n\n // Use defineProperty to prevent re-assignment or deletion of the bridge\n Object.defineProperty(window, \"__MiniAppBridge\", {\n configurable: false,\n value: bridgeReceiver,\n writable: false,\n });\n\n window.addEventListener(\"message\", (event) => {\n // SECURITY: Filter events. If inside a mobile shell, the origin of native postMessage\n // varies by platform (e.g., file://, or specific app schemes).\n // For production, this should be restricted to the expected host origin.\n if (!event.data) return;\n\n try {\n const data =\n typeof event.data === \"string\"\n ? JSON.parse(event.data)\n : event.data;\n\n // SECURITY: Basic envelope validation\n if (\n data &&\n typeof data === \"object\" &&\n (data.callbackId || data.event)\n ) {\n this.handleNativeMessage(data);\n }\n } catch (_e) {\n // Ignore non-JSON or malformed messages\n }\n });\n }\n }\n\n /**\n * Subscribes to a pushed event from the native shell.\n *\n * @param event The event name to listen for.\n * @param callback Function to execute when the event occurs.\n * @returns An unsubscription function.\n */\n public on(event: string, callback: (data: unknown) => void) {\n let listeners = this.eventListeners.get(event);\n if (!listeners) {\n listeners = [];\n this.eventListeners.set(event, listeners);\n }\n listeners.push(callback);\n return () => this.off(event, callback);\n }\n\n /**\n * Unsubscribes a specific callback from an event.\n *\n * @param event The event name.\n * @param callback The callback function to remove.\n */\n public off(event: string, callback: (data: unknown) => void) {\n const listeners = this.eventListeners.get(event);\n if (!listeners) return;\n this.eventListeners.set(\n event,\n listeners.filter((cb) => cb !== callback),\n );\n }\n\n /**\n * Sends a message to the native shell and waits for a response.\n *\n * @template T The expected response type.\n * @param type The action type (e.g., \"GET_LOCATION\").\n * @param payload Data associated with the action.\n * @param timeoutMs Time in milliseconds to wait for a response before rejecting.\n * @returns A promise that resolves with the native response.\n */\n public send<T = unknown>(\n type: string,\n payload?: unknown,\n timeoutMs = 30000,\n ): Promise<T> {\n return new Promise((resolve, reject) => {\n const callbackId = `${type}_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n\n const timeout = setTimeout(() => {\n if (this.callbacks.has(callbackId)) {\n this.callbacks.delete(callbackId);\n reject(new Error(`Bridge request timeout: ${type}`));\n }\n }, timeoutMs);\n\n this.callbacks.set(callbackId, {\n reject,\n resolve: resolve as (val: unknown) => void,\n timeout,\n });\n\n const message = {\n callbackId,\n payload,\n type,\n };\n\n const win = window as unknown as {\n ReactNativeWebView?: { postMessage: (msg: string) => void };\n };\n\n if (win.ReactNativeWebView?.postMessage) {\n win.ReactNativeWebView.postMessage(JSON.stringify(message));\n } else {\n clearTimeout(timeout);\n this.callbacks.delete(callbackId);\n reject(new Error(\"Bridge not available\"));\n }\n });\n }\n\n /**\n * Internal handler for all incoming messages from the native shell.\n * Matches incoming payloads to either pending callbacks or event listeners.\n *\n * @internal\n * @param envelope The message envelope received from native code.\n */\n private handleNativeMessage(envelope: IBridgeEnvelope) {\n if (!envelope || typeof envelope !== \"object\") return;\n\n // 1. Handle Response Callbacks\n const callbackId = envelope.callbackId;\n if (callbackId && typeof callbackId === \"string\") {\n const callback = this.callbacks.get(callbackId);\n if (callback) {\n clearTimeout(callback.timeout);\n const { resolve, reject } = callback;\n\n if (envelope.success === false || envelope.error) {\n reject(envelope.error || \"Unknown error\");\n } else {\n resolve(envelope.value ?? envelope.payload ?? envelope);\n }\n\n this.callbacks.delete(callbackId);\n return;\n }\n }\n\n // 2. Handle Pushed Events\n const eventName = envelope.event;\n if (eventName && typeof eventName === \"string\") {\n const listeners = this.eventListeners.get(eventName);\n if (listeners) {\n for (const listener of listeners) {\n try {\n listener(envelope.payload || envelope.value);\n } catch (e) {\n console.error(`Error in event listener for ${eventName}:`, e);\n }\n }\n }\n }\n }\n}\n","import { Bridge } from \"@miniapps-sdk/bridge\";\nimport type {\n HapticStyleType,\n IFidelityBalance,\n IFidelityHistoryParams,\n IFidelityTransaction,\n IInitializationOptions,\n IInitializationResponse,\n ILocationData,\n INetworkOptions,\n INetworkResponse,\n IPaymentRequest,\n IUserProfile,\n ScrollConfig,\n SDKEvent,\n} from \"@miniapps-sdk/types/types\";\n\n/**\n * Deep freezes an object and its nested properties.\n * @param obj The object to freeze.\n * @returns The frozen object.\n */\nfunction deepFreeze<T extends object>(obj: T): T {\n // Retrieve the property names defined on obj\n const propNames = Object.getOwnPropertyNames(obj);\n\n // Freeze properties before freezing self\n for (const name of propNames) {\n const value = (obj as Record<string, unknown>)[name];\n\n if (\n value &&\n typeof value === \"object\" &&\n !Object.isFrozen(value) &&\n // Skip freezing of native objects or circular refs if any (though not expected here)\n !(value instanceof Bridge)\n ) {\n deepFreeze(value as object);\n }\n }\n\n return Object.freeze(obj);\n}\n\n/**\n * Main SDK for UP Mini-Apps.\n * Provides access to native device features, storage, identity, and shell UI.\n */\nexport class MiniAppSDK {\n private bridge: Bridge;\n /**\n * Local SQLite Storage.\n * Data is persisted on the device and is isolated per Mini-App.\n */\n public readonly storage = Object.freeze({\n /** Retrieves a value by key. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"STORAGE_GET\", { key }),\n /** Retrieves all key-value pairs stored for this Mini-App. */\n getAll: (): Promise<Record<string, string>> =>\n this.bridge.send(\"STORAGE_GET_ALL\"),\n /** Sets a value for a specific key. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"STORAGE_SET\", { key, value }),\n });\n /**\n * Hardware-level Secure Storage.\n * Data is stored in the device's secure enclave (Keychain/Keystore) and is isolated per Mini-App.\n */\n public readonly secureStore = Object.freeze({\n /** Retrieves a value by key from secure storage. */\n get: (key: string): Promise<string | null> =>\n this.bridge.send(\"SECURE_GET\", { key }),\n /** Sets a value for a specific key in secure storage. */\n set: (key: string, value: string): Promise<void> =>\n this.bridge.send(\"SECURE_SET\", { key, value }),\n });\n /**\n * Database Storage.\n * Access to user-app specific persistent database storage.\n */\n public readonly database = Object.freeze({\n /** Retrieves the user data stored in the backend database. */\n getUserData: <T = unknown>(): Promise<T> =>\n this.bridge.send<T>(\"DATABASE_GET_USER_DATA\"),\n /** Updates the user data stored in the backend database. */\n setUserData: <T = unknown>(data: T): Promise<void> =>\n this.bridge.send<void>(\"DATABASE_SET_USER_DATA\", { data }),\n });\n /**\n * Device Location services.\n */\n public readonly location = Object.freeze({\n /** Retrieves the current GPS position of the device. */\n getCurrentPosition: (): Promise<ILocationData> =>\n this.bridge.send(\"GET_LOCATION\"),\n });\n /**\n * Identity & Profile management.\n */\n public readonly user = Object.freeze({\n /**\n * Fetch user profile data.\n * @param fields Optional list of specific fields to retrieve (e.g., ['fullName', 'username']).\n */\n getProfile: <T extends keyof IUserProfile>(\n fields?: T[],\n ): Promise<Partial<IUserProfile>> =>\n this.bridge.send(\"GET_USER_PROFILE\", { fields }),\n });\n /**\n * Explicit Permission Management.\n * Allows requesting access to sensitive device features or user data.\n */\n public readonly permission = Object.freeze({\n /**\n * Explicitly request access to sensitive data.\n * @param type The type of permission to request ('location' or 'profile').\n * @param fields If requesting 'profile', the specific fields required.\n */\n request: ((type: \"location\" | \"profile\", fields?: string[]) => {\n return this.bridge.send(\"REQUEST_PERMISSION\", { fields, type });\n }) as {\n (type: \"location\"): Promise<boolean>;\n (type: \"profile\", fields: (keyof IUserProfile)[]): Promise<boolean>;\n },\n });\n /**\n * Payments integration.\n */\n public readonly payment = Object.freeze({\n /**\n * Triggers the native payment flow.\n * @param payload Amount, currency, and itemized list for the payment.\n */\n request: (\n payload: IPaymentRequest,\n ): Promise<{ success: true; transactionId: string }> =>\n this.bridge.send(\"PAYMENT_REQUEST\", payload),\n });\n /**\n * Live Activities & Notifications.\n * Allows the Mini-App to display real-time updates in the host shell.\n */\n public readonly activity = Object.freeze({\n /**\n * Starts a new live activity.\n * @param id Unique identifier for the activity.\n * @param title Display title for the activity.\n * @param status Initial status message.\n */\n start: (id: string, title: string, status: string): Promise<void> =>\n this.bridge.send(\"START_ACTIVITY\", { id, status, title }),\n });\n /**\n * Haptic feedback.\n */\n public readonly haptic = Object.freeze({\n /**\n * Triggers a haptic vibration on the device.\n * @param style The style of haptic feedback (e.g., 'light', 'medium', 'heavy', 'success', 'warning', 'error').\n */\n trigger: (style: HapticStyleType): Promise<void> =>\n this.bridge.send(\"TRIGGER_HAPTIC\", { style }),\n });\n /**\n * Network Proxy.\n * Allows the Mini-App to make network requests through the host shell to bypass CORS or use host-level authentication.\n */\n public readonly network = Object.freeze({\n /**\n * Performs a network request via the host shell.\n * @param options Request method, URL, headers, and body.\n */\n request: (options: INetworkOptions): Promise<INetworkResponse> =>\n this.bridge.send(\"NETWORK_REQUEST\", options),\n });\n /**\n * Fidelity & Rewards program integration.\n */\n public readonly fidelity = Object.freeze({\n /** Returns current fidelity balance. */\n getFidelityBalance: (): Promise<IFidelityBalance> =>\n this.bridge.send(\"GET_FIDELITY_BALANCE\"),\n /**\n * Retrieves fidelity transaction history.\n * @param params Filtering and pagination parameters.\n */\n getFidelityHistory: (\n params?: IFidelityHistoryParams,\n ): Promise<IFidelityTransaction[]> =>\n this.bridge.send(\"GET_FIDELITY_HISTORY\", params),\n /**\n * Authorize spending fidelity points (FPoints) via Two-Phase Authorization.\n * @param intentUuid UUID generated by your backend for the transaction.\n */\n spendFPoints: (\n intentUuid: string,\n ): Promise<{ success: boolean; transactionId: string }> =>\n this.bridge.send(\"SPEND_FPOINTS\", { intentUuid }),\n });\n /**\n * UI and Navigation controls.\n */\n public readonly ui = Object.freeze({\n /** Closes the Mini-App and returns to the host shell. */\n exit: (): Promise<void> => this.bridge.send(\"EXIT\"),\n /**\n * Configures native scroll behaviors like Pull-to-Refresh and Infinite Scroll.\n * @param config Scroll configuration for top/bottom detection.\n */\n setScrollConfig: (config: ScrollConfig): Promise<void> =>\n this.bridge.send(\"SET_SCROLL_CONFIG\", config),\n });\n /**\n * Debug controls\n */\n public readonly debug = Object.freeze({\n /**\n * Log to the shell app\n * @param message\n */\n log: (...message: unknown[]) => this.bridge.send(\"DEBUG_LOG\", { message }),\n });\n\n constructor() {\n this.bridge = new Bridge();\n\n // Bind methods to this instance to preserve context if pulled out\n this.initialize = this.initialize.bind(this);\n this.on = this.on.bind(this);\n this.off = this.off.bind(this);\n }\n\n /**\n * The starting point for the Mini-App. Must be called before any other SDK methods.\n * @param options The options to provide to the shell app\n */\n public initialize(\n options: IInitializationOptions,\n ): Promise<IInitializationResponse> {\n return this.bridge.send(\"INITIALIZE\", options);\n }\n\n /**\n * Registers a callback for a specific event from the native shell.\n * @param event The name of the event to listen for.\n * @param callback The function to execute when the event is triggered.\n * @returns A function to unregister the listener.\n */\n public on(event: SDKEvent, callback: (data: unknown) => void) {\n return this.bridge.on(event as string, callback);\n }\n\n /**\n * Unregisters a previously registered event listener.\n * @param event The name of the event.\n * @param callback The callback function to remove.\n */\n public off(event: SDKEvent, callback: (data: unknown) => void) {\n this.bridge.off(event as string, callback);\n }\n}\n\n/**\n * Singleton instance of the MiniAppSDK.\n * Frozen to prevent tampering.\n */\nexport const sdk = deepFreeze(new MiniAppSDK());\n","/**\n * UP Mini-App SDK Types\n */\n\n/**\n * Represents the user's profile information.\n */\nexport interface IUserProfile {\n /** Unique identifier for the user. */\n uuid: string;\n /** Full legal name of the user. */\n fullName: string;\n /** Primary email address. */\n email: string;\n /** Chosen username within the UP ecosystem. */\n username: string;\n /** ISO country code (e.g., \"FR\", \"US\"). */\n countryCode: string;\n /** Phone number without country code. */\n localNumber: string;\n}\n\n/**\n * Geographic location data.\n */\nexport interface ILocationData {\n coords: {\n /** Latitude in decimal degrees. */\n latitude: number;\n /** Longitude in decimal degrees. */\n longitude: number;\n /** Altitude in meters above the WGS 84 reference ellipsoid, or null if not available. */\n altitude: number | null;\n /** Accuracy of the latitude and longitude properties in meters. */\n accuracy: number | null;\n /** Accuracy of the altitude property in meters. */\n altitudeAccuracy: number | null;\n /** The direction in which the device is traveling, in degrees (0-360). */\n heading: number | null;\n /** The velocity of the device in meters per second. */\n speed: number | null;\n };\n /** The time at which the location was retrieved (Unix timestamp). */\n timestamp: number;\n}\n\n/**\n * Request payload for triggering a payment flow.\n */\nexport interface IPaymentRequest {\n /** The specific amount to charge. */\n amount: number;\n /** ISO currency code (e.g., \"EUR\", \"USD\"). */\n currency: string;\n /** Total amount including taxes/fees. */\n total: number;\n /** Itemized breakdown of the purchase. */\n items: Array<{\n /** Name or description of the item. */\n item: string;\n /** Price per unit. */\n price?: number;\n /** Number of units. */\n quantity?: number;\n }>;\n}\n\n/**\n * Style of haptic feedback.\n */\nexport type HapticStyleType =\n | \"light\"\n | \"medium\"\n | \"heavy\"\n | \"rigid\"\n | \"soft\"\n | \"success\"\n | \"warning\"\n | \"error\";\n\n/**\n * Network Proxy Types\n */\n\n/**\n * The HTTP method to use as request method\n */\nexport type NetworkMethodType = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\n\n/**\n * Configuration for network proxy requests.\n */\nexport interface INetworkOptions {\n /** Full URL for the request. */\n url: string;\n /** HTTP method to use. */\n method: NetworkMethodType;\n /** Request body for POST/PUT/PATCH. */\n body?: unknown;\n /** Custom HTTP headers. */\n headers?: Record<string, string>;\n}\n\n/**\n * Response from a network proxy request.\n */\nexport interface INetworkResponse<T = unknown> {\n /** HTTP status code. */\n status: number;\n /** Response data payload. */\n data: T;\n /** Response headers. */\n headers: Headers;\n}\n\n/**\n * Fidelity & Rewards Types\n */\n\n/**\n * Fidelity program balance information.\n */\nexport interface IFidelityBalance {\n /** Current point or currency balance. */\n balance: number;\n /** Name or symbol of the fidelity currency (e.g., \"FPoints\"). */\n currency: string;\n}\n\n/**\n * Parameters for retrieving fidelity transaction history.\n */\nexport interface IFidelityHistoryParams {\n /** Maximum number of records to return. */\n limit?: number;\n\n /** Cursor for pagination; null for the first page. */\n cursor?: string | null;\n}\n\n/** Type of transaction: credit (add) or debit (remove). */\nexport type FidelityTransactionTypeType = \"credit\" | \"debit\";\n\n/**\n * A single fidelity program transaction.\n */\nexport interface IFidelityTransaction {\n /** Unique identifier for the transaction. */\n id: string;\n /** Amount of the transaction. */\n amount: number;\n /** Human-readable description. */\n description: string;\n /** ISO 8601 date string. */\n date: string;\n /** Type of transaction */\n type: FidelityTransactionTypeType;\n}\n\n/**\n * The initialization options required to set up the Mini-App SDK.\n */\nexport type IInitializationOptions = {};\n\n/**\n * The post initialization response\n */\nexport interface IInitializationResponse<\n Env extends Record<string, unknown> = Record<string, unknown>,\n UserData extends Record<string, unknown> = Record<string, unknown>,\n Params extends Record<string, unknown> = Record<string, unknown>,\n> {\n /** The name of the mini app */\n name: string;\n /** The uuid of the mini app */\n uuid: string;\n /** The description of the mini app */\n description: string;\n /** The authors of the mini app */\n authors?: string;\n /** The current version in the registry */\n version?: string;\n /** The scoped profile based on the requested fields during initialization or the getUserProfile call */\n profile: Partial<IUserProfile | null>;\n /** The environment variables defined for the mini app in the shell's backend */\n env: Env;\n /** The user data passed during the initialization or the setUserData call */\n userData: UserData;\n /** The params passed during the initialization */\n params: Params;\n}\n\n/**\n * Events emitted by the UI module.\n */\nexport enum UIEvent {\n /** Triggered when the user performs a native \"Pull-to-Refresh\". */\n TOP_SCROLL_MORE = \"TOP_SCROLL_MORE\",\n /** Triggered when the user scrolls near the bottom of the page (within 200px threshold). */\n BOTTOM_SCROLL_MORE = \"BOTTOM_SCROLL_MORE\",\n}\n\n/**\n * Union type for all SDK events, allowing for both known enums and custom strings.\n * The (string & {}) pattern preserves IntelliSense for enum members.\n */\nexport type SDKEvent = UIEvent | (string & {});\n\n/**\n * Configuration for native scroll interactions managed by the Host Shell.\n */\nexport interface ScrollConfig {\n /** Configuration for Pull-to-Refresh (Top). */\n topScrollMore?: {\n /** Show/hide the native RefreshControl. */\n enabled: boolean;\n /** Set to true to show the loading spinner, false to hide it. */\n refreshing?: boolean;\n };\n /** Configuration for Infinite Scroll (Bottom). */\n bottomScrollMore?: {\n /** Enable/disable bottom scroll detection. */\n enabled: boolean;\n /** If false, detection stops and the indicator is hidden. */\n hasMore?: boolean;\n /** Set to true to show the bottom ActivityIndicator. */\n loadingMore?: boolean;\n };\n}\n","export { MiniAppSDK, sdk } from \"@miniapps-sdk/sdk\";\nexport * from \"@miniapps-sdk/types\";\n\nimport { sdk } from \"@miniapps-sdk/sdk\";\n\nexport default sdk;\n"],"mappings":";AASO,IAAM,SAAN,MAAa;AAAA,EACV,YAAY,oBAAI,IAOtB;AAAA,EACM,iBAAiB,oBAAI,IAAyC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtE,cAAc;AACZ,QAAI,OAAO,WAAW,aAAa;AACjC,YAAM,iBAAiB,OAAO,OAAO;AAAA,QACnC,iBAAiB,CAAC,aAChB,KAAK,oBAAoB,QAAQ;AAAA,MACrC,CAAC;AAGD,aAAO,eAAe,QAAQ,mBAAmB;AAAA,QAC/C,cAAc;AAAA,QACd,OAAO;AAAA,QACP,UAAU;AAAA,MACZ,CAAC;AAED,aAAO,iBAAiB,WAAW,CAAC,UAAU;AAI5C,YAAI,CAAC,MAAM,KAAM;AAEjB,YAAI;AACF,gBAAM,OACJ,OAAO,MAAM,SAAS,WAClB,KAAK,MAAM,MAAM,IAAI,IACrB,MAAM;AAGZ,cACE,QACA,OAAO,SAAS,aACf,KAAK,cAAc,KAAK,QACzB;AACA,iBAAK,oBAAoB,IAAI;AAAA,UAC/B;AAAA,QACF,SAAS,IAAI;AAAA,QAEb;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,GAAG,OAAe,UAAmC;AAC1D,QAAI,YAAY,KAAK,eAAe,IAAI,KAAK;AAC7C,QAAI,CAAC,WAAW;AACd,kBAAY,CAAC;AACb,WAAK,eAAe,IAAI,OAAO,SAAS;AAAA,IAC1C;AACA,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