@nebula-rn/sdk 0.0.1

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.
@@ -0,0 +1,185 @@
1
+ import React from 'react';
2
+ import { AppRegistry } from 'react-native';
3
+ import { NebulaAPI } from './NebulaAPI';
4
+ export function createHostApiFailure(code, message) {
5
+ return {
6
+ ok: false,
7
+ error: {
8
+ code,
9
+ message,
10
+ },
11
+ };
12
+ }
13
+ export function createHostApiSuccess(data) {
14
+ return {
15
+ ok: true,
16
+ data,
17
+ };
18
+ }
19
+ export function createHostModalChannel() {
20
+ let pendingRequest = null;
21
+ const listeners = new Set();
22
+ const notify = () => {
23
+ listeners.forEach(listener => listener(pendingRequest));
24
+ };
25
+ return {
26
+ clear() {
27
+ pendingRequest = null;
28
+ notify();
29
+ },
30
+ getCurrent() {
31
+ return pendingRequest;
32
+ },
33
+ open(request) {
34
+ return new Promise(resolve => {
35
+ pendingRequest = {
36
+ ...request,
37
+ resolve: result => {
38
+ pendingRequest = null;
39
+ notify();
40
+ resolve(result);
41
+ },
42
+ };
43
+ notify();
44
+ });
45
+ },
46
+ settle(result) {
47
+ pendingRequest?.resolve(result);
48
+ },
49
+ subscribe(listener) {
50
+ listeners.add(listener);
51
+ listener(pendingRequest);
52
+ return () => {
53
+ listeners.delete(listener);
54
+ };
55
+ },
56
+ };
57
+ }
58
+ function getHostModalModuleName(apiName) {
59
+ const normalizedName = apiName.replace(/[^a-zA-Z0-9_]+/g, '_');
60
+ return `NebulaHostModal_${normalizedName}`;
61
+ }
62
+ function createHostModalApiHandler({ apiName, channel, createRequest, modalProps, onBeforeOpen, version = '1.0', description, }) {
63
+ const modalModuleName = getHostModalModuleName(apiName);
64
+ let requestInFlight = false;
65
+ return {
66
+ version,
67
+ description,
68
+ handle: async (payload) => {
69
+ if (requestInFlight) {
70
+ return createHostApiFailure('SCAN_FAILED', `${apiName}:fail another request is already in progress`);
71
+ }
72
+ const typedPayload = payload;
73
+ requestInFlight = true;
74
+ try {
75
+ const precheckResult = onBeforeOpen
76
+ ? await onBeforeOpen(typedPayload)
77
+ : null;
78
+ if (precheckResult) {
79
+ return precheckResult;
80
+ }
81
+ const request = createRequest(typedPayload);
82
+ const resultPromise = channel.open(request);
83
+ const resolvedModalProps = typeof modalProps === 'function'
84
+ ? modalProps(typedPayload, request)
85
+ : (modalProps ?? {});
86
+ await NebulaAPI.presentHostModal(modalModuleName, {
87
+ __transparentBackground: true,
88
+ ...resolvedModalProps,
89
+ });
90
+ return await resultPromise;
91
+ }
92
+ catch (error) {
93
+ channel.settle(createHostApiFailure('SCAN_FAILED', `${apiName}:fail host modal flow interrupted`));
94
+ return createHostApiFailure('SCAN_FAILED', error instanceof Error
95
+ ? error.message
96
+ : `${apiName}:fail unable to present host modal`);
97
+ }
98
+ finally {
99
+ requestInFlight = false;
100
+ }
101
+ },
102
+ cleanup: () => {
103
+ requestInFlight = false;
104
+ },
105
+ };
106
+ }
107
+ export function registerHostModalApi({ apiName, component, channel, createRequest, modalProps, onBeforeOpen, onUnmountErrorMessage, version = '1.0', description, }) {
108
+ const modalModuleName = getHostModalModuleName(apiName);
109
+ AppRegistry.registerComponent(modalModuleName, () => component);
110
+ const handler = createHostModalApiHandler({
111
+ apiName,
112
+ channel,
113
+ createRequest,
114
+ modalProps,
115
+ onBeforeOpen,
116
+ version,
117
+ description,
118
+ });
119
+ NebulaAPI.registerApiHandler(apiName, {
120
+ version: handler.version,
121
+ description: handler.description,
122
+ handle: handler.handle,
123
+ });
124
+ return () => {
125
+ NebulaAPI.unregisterApiHandler(apiName);
126
+ handler.cleanup();
127
+ channel.settle(createHostApiFailure('SCAN_FAILED', onUnmountErrorMessage ??
128
+ `${apiName}:fail host modal was unmounted before completion`));
129
+ NebulaAPI.dismissHostModal().catch(() => { });
130
+ };
131
+ }
132
+ export function createHostApiFeature({ apiName, supported, version = '1.0', description, handle, }) {
133
+ return {
134
+ name: apiName,
135
+ description,
136
+ register() {
137
+ NebulaAPI.registerApiHandler(apiName, {
138
+ version,
139
+ supported,
140
+ description,
141
+ handle,
142
+ });
143
+ return () => {
144
+ NebulaAPI.unregisterApiHandler(apiName);
145
+ };
146
+ },
147
+ };
148
+ }
149
+ export function createMockHostApiFeature({ apiName, version = '1.0.0', description, delayMs = 0, result, error, }) {
150
+ return createHostApiFeature({
151
+ apiName,
152
+ version,
153
+ description,
154
+ handle: async (payload) => {
155
+ if (delayMs > 0) {
156
+ await new Promise(resolve => setTimeout(resolve, delayMs));
157
+ }
158
+ if (error) {
159
+ const resolvedError = typeof error === 'function' ? await error(payload) : error;
160
+ return createHostApiFailure(resolvedError.code, resolvedError.message);
161
+ }
162
+ const resolvedResult = typeof result === 'function' ? await result(payload) : result;
163
+ return createHostApiSuccess(typeof resolvedResult === 'undefined' ? null : resolvedResult);
164
+ },
165
+ });
166
+ }
167
+ export function createHostModalApiFeature(options) {
168
+ return {
169
+ name: options.apiName,
170
+ description: options.description,
171
+ register() {
172
+ return registerHostModalApi(options);
173
+ },
174
+ };
175
+ }
176
+ export function createHostModalApiBridge(options) {
177
+ return function HostModalApiBridge() {
178
+ React.useEffect(() => registerHostModalApi(options), []);
179
+ return null;
180
+ };
181
+ }
182
+ export function registerHostModalComponent(moduleName, component) {
183
+ AppRegistry.registerComponent(moduleName, () => component);
184
+ return moduleName;
185
+ }
@@ -0,0 +1,9 @@
1
+ import type { NebulaHostApiDescriptionMap, NebulaHostApiHandler, NebulaHostCapabilityMap, NebulaProtocolResponse } from './nebulaTypes';
2
+ export declare function resolveHostCapabilities(): Promise<NebulaHostCapabilityMap>;
3
+ export declare function resolveHostApiDescriptions(): NebulaHostApiDescriptionMap;
4
+ export declare function startHostApiServer(postMessageToMiniApp: (appId: string, message: NebulaProtocolResponse) => Promise<{
5
+ errMsg: string;
6
+ }>): void;
7
+ export declare function stopHostApiServer(): void;
8
+ export declare function registerHostApiHandler(apiName: string, handler: NebulaHostApiHandler): void;
9
+ export declare function unregisterHostApiHandler(apiName: string): void;
@@ -0,0 +1,153 @@
1
+ import { addNebulaEventListener, isProtocolRequest, NEBULA_HOST_MESSAGE_EVENT, } from './nebulaNative';
2
+ const hostApiRegistry = new Map();
3
+ let hostApiServerStarted = false;
4
+ let hostApiServerUnsubscribe = null;
5
+ export async function resolveHostCapabilities() {
6
+ const entries = await Promise.all(Array.from(hostApiRegistry.entries()).map(async ([apiName, handler]) => {
7
+ const supported = typeof handler.supported === 'function'
8
+ ? await handler.supported()
9
+ : (handler.supported ?? true);
10
+ return [
11
+ apiName,
12
+ {
13
+ version: handler.version,
14
+ supported,
15
+ },
16
+ ];
17
+ }));
18
+ return entries.reduce((capabilities, entry) => {
19
+ capabilities[entry[0]] = entry[1];
20
+ return capabilities;
21
+ }, {});
22
+ }
23
+ export function resolveHostApiDescriptions() {
24
+ return Array.from(hostApiRegistry.entries()).reduce((descriptions, [apiName, handler]) => {
25
+ if (handler.description) {
26
+ descriptions[apiName] = handler.description;
27
+ }
28
+ return descriptions;
29
+ }, {});
30
+ }
31
+ export function startHostApiServer(postMessageToMiniApp) {
32
+ if (hostApiServerStarted) {
33
+ return;
34
+ }
35
+ const unsubscribe = addNebulaEventListener(NEBULA_HOST_MESSAGE_EVENT, event => {
36
+ const message = event.message;
37
+ if (!isProtocolRequest(message)) {
38
+ return;
39
+ }
40
+ const reply = async (response) => {
41
+ await postMessageToMiniApp(event.appId, response);
42
+ };
43
+ if (message.kind === 'getCapabilities') {
44
+ resolveHostCapabilities()
45
+ .then(capabilities => reply({
46
+ __nebulaProtocol: 'api.v1',
47
+ kind: 'capabilities',
48
+ requestId: message.requestId,
49
+ data: {
50
+ bridgeVersion: '1.0.0',
51
+ capabilities,
52
+ },
53
+ }))
54
+ .catch(error => {
55
+ console.error('[Nebula] Failed to resolve host capabilities', error);
56
+ });
57
+ return;
58
+ }
59
+ if (message.kind === 'getApiDescriptions') {
60
+ reply({
61
+ __nebulaProtocol: 'api.v1',
62
+ kind: 'apiDescriptions',
63
+ requestId: message.requestId,
64
+ data: resolveHostApiDescriptions(),
65
+ }).catch(error => {
66
+ console.error('[Nebula] Failed to resolve host API descriptions', error);
67
+ });
68
+ return;
69
+ }
70
+ if (message.kind !== 'invoke') {
71
+ return;
72
+ }
73
+ const handler = hostApiRegistry.get(message.api);
74
+ if (!handler) {
75
+ reply({
76
+ __nebulaProtocol: 'api.v1',
77
+ kind: 'invokeResult',
78
+ requestId: message.requestId,
79
+ result: {
80
+ ok: false,
81
+ error: {
82
+ code: 'UNSUPPORTED_API',
83
+ message: `${message.api} is not supported by the current host`,
84
+ },
85
+ },
86
+ }).catch(error => {
87
+ console.error('[Nebula] Failed to send unsupported API reply', error);
88
+ });
89
+ return;
90
+ }
91
+ const resolveSupported = async () => typeof handler.supported === 'function'
92
+ ? handler.supported()
93
+ : (handler.supported ?? true);
94
+ Promise.resolve(resolveSupported())
95
+ .then(async (supported) => {
96
+ if (!supported) {
97
+ await reply({
98
+ __nebulaProtocol: 'api.v1',
99
+ kind: 'invokeResult',
100
+ requestId: message.requestId,
101
+ result: {
102
+ ok: false,
103
+ error: {
104
+ code: 'UNSUPPORTED_API',
105
+ message: `${message.api} is not supported by the current host`,
106
+ },
107
+ },
108
+ });
109
+ return;
110
+ }
111
+ const result = await handler.handle(message.payload ?? {}, {
112
+ appId: event.appId,
113
+ requestId: message.requestId,
114
+ version: message.version,
115
+ });
116
+ await reply({
117
+ __nebulaProtocol: 'api.v1',
118
+ kind: 'invokeResult',
119
+ requestId: message.requestId,
120
+ result,
121
+ });
122
+ })
123
+ .catch(async (error) => {
124
+ await reply({
125
+ __nebulaProtocol: 'api.v1',
126
+ kind: 'invokeResult',
127
+ requestId: message.requestId,
128
+ result: {
129
+ ok: false,
130
+ error: {
131
+ code: 'INTERNAL_ERROR',
132
+ message: error instanceof Error
133
+ ? error.message
134
+ : 'Unexpected host error',
135
+ },
136
+ },
137
+ });
138
+ });
139
+ });
140
+ hostApiServerUnsubscribe = unsubscribe ?? null;
141
+ hostApiServerStarted = true;
142
+ }
143
+ export function stopHostApiServer() {
144
+ hostApiServerUnsubscribe?.();
145
+ hostApiServerUnsubscribe = null;
146
+ hostApiServerStarted = false;
147
+ }
148
+ export function registerHostApiHandler(apiName, handler) {
149
+ hostApiRegistry.set(apiName, handler);
150
+ }
151
+ export function unregisterHostApiHandler(apiName) {
152
+ hostApiRegistry.delete(apiName);
153
+ }
@@ -0,0 +1,6 @@
1
+ export { NebulaAPI, Miniapp, createMiniAppPage, usePageOnHide, usePageOnLoad, usePageOnReady, usePageOnShow, usePageOnUnload, } from './NebulaAPI';
2
+ export { createHostApiFeature, createMockHostApiFeature, createHostApiFailure, createHostApiSuccess, createHostModalApiFeature, registerHostModalApi, createHostModalApiBridge, createHostModalChannel, registerHostModalComponent, } from './hostApi';
3
+ export type { HostModalChannel, CreateMockHostApiOptions, NebulaHostFeature, RegisterHostApiOptions, RegisterHostModalApiOptions, } from './hostApi';
4
+ export { definePageConfig } from './pageConfig';
5
+ export type { NebulaApiExampleDescriptor, NebulaApiFieldDescriptor, MiniappLoadingProps, MiniappLoadingStatus, MiniAppUpdateInfo, MiniAppUpdateStrategy, MiniAppVersionType, NebulaApiError, NebulaApiInvokeResult, NebulaHostApiDescription, NebulaHostApiDescriptionMap, NebulaHostApiHandler, NebulaHostCapabilityDescriptor, NebulaHostCapabilityMap, NebulaNativeCapabilitiesResult, NebulaNativeCapabilityMap, NebulaPageStyle, } from './NebulaAPI';
6
+ export type { MiniAppPageConfig } from './pageConfig';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { NebulaAPI, Miniapp, createMiniAppPage, usePageOnHide, usePageOnLoad, usePageOnReady, usePageOnShow, usePageOnUnload, } from './NebulaAPI';
2
+ export { createHostApiFeature, createMockHostApiFeature, createHostApiFailure, createHostApiSuccess, createHostModalApiFeature, registerHostModalApi, createHostModalApiBridge, createHostModalChannel, registerHostModalComponent, } from './hostApi';
3
+ export { definePageConfig } from './pageConfig';
@@ -0,0 +1,18 @@
1
+ import type { InstalledMiniAppInfo, MiniappLoadingProps, MiniappLoadingResolveContext, MiniappLoadingResolvedProps, MiniappLoadingStatus } from './nebulaTypes';
2
+ type MiniappLoadingState = {
3
+ appId: string | null;
4
+ mode: 'development' | 'production';
5
+ status: MiniappLoadingStatus;
6
+ title?: string | null;
7
+ icon?: MiniappLoadingProps['icon'];
8
+ extraData?: MiniappLoadingProps['extraData'];
9
+ installedInfo?: InstalledMiniAppInfo | null;
10
+ errorMessage?: string | null;
11
+ visible: boolean;
12
+ };
13
+ export declare function configureMiniappLoadingComponent(component: React.ComponentType<MiniappLoadingProps> | null, resolveProps?: ((context: MiniappLoadingResolveContext) => MiniappLoadingResolvedProps) | null, delayMs?: number | null): void;
14
+ export declare function setMiniappLoadingState(nextState: Partial<MiniappLoadingState>): void;
15
+ export declare function hideMiniappLoading(appId?: string | null): void;
16
+ export declare function getMiniappLoadingDelayMs(): number;
17
+ export declare function ensureInternalMiniappLoadingComponentRegistered(): void;
18
+ export {};
@@ -0,0 +1,103 @@
1
+ import { AppRegistry } from 'react-native';
2
+ import { NEBULA_INTERNAL_MINIAPP_LOADING_MODULE } from './nebulaNative';
3
+ import { createElement, useEffect, useState } from 'react';
4
+ let miniappLoadingDelayMs = 0;
5
+ let internalMiniappLoadingRegistered = false;
6
+ let miniappLoadingComponent = null;
7
+ let miniappLoadingResolveProps = null;
8
+ let miniappLoadingState = {
9
+ appId: null,
10
+ mode: 'production',
11
+ status: 'loading',
12
+ title: null,
13
+ icon: null,
14
+ extraData: null,
15
+ installedInfo: null,
16
+ errorMessage: null,
17
+ visible: false,
18
+ };
19
+ const miniappLoadingListeners = new Set();
20
+ function emitMiniappLoadingState() {
21
+ miniappLoadingListeners.forEach(listener => listener());
22
+ }
23
+ export function configureMiniappLoadingComponent(component, resolveProps, delayMs) {
24
+ miniappLoadingComponent = component;
25
+ miniappLoadingResolveProps = resolveProps ?? null;
26
+ miniappLoadingDelayMs =
27
+ typeof delayMs === 'number' && Number.isFinite(delayMs)
28
+ ? Math.max(0, Math.round(delayMs))
29
+ : 0;
30
+ }
31
+ export function setMiniappLoadingState(nextState) {
32
+ miniappLoadingState = {
33
+ ...miniappLoadingState,
34
+ ...nextState,
35
+ };
36
+ emitMiniappLoadingState();
37
+ }
38
+ export function hideMiniappLoading(appId) {
39
+ if (appId &&
40
+ miniappLoadingState.appId &&
41
+ miniappLoadingState.appId !== appId) {
42
+ return;
43
+ }
44
+ setMiniappLoadingState({
45
+ visible: false,
46
+ status: 'ready',
47
+ title: null,
48
+ icon: null,
49
+ extraData: null,
50
+ installedInfo: null,
51
+ errorMessage: null,
52
+ });
53
+ }
54
+ export function getMiniappLoadingDelayMs() {
55
+ return miniappLoadingDelayMs;
56
+ }
57
+ export function ensureInternalMiniappLoadingComponentRegistered() {
58
+ if (internalMiniappLoadingRegistered) {
59
+ return;
60
+ }
61
+ AppRegistry.registerComponent(NEBULA_INTERNAL_MINIAPP_LOADING_MODULE, () => {
62
+ const NebulaInternalMiniappLoading = () => {
63
+ const [, forceUpdate] = useState(0);
64
+ useEffect(() => {
65
+ const listener = () => forceUpdate(value => value + 1);
66
+ miniappLoadingListeners.add(listener);
67
+ return () => {
68
+ miniappLoadingListeners.delete(listener);
69
+ };
70
+ }, []);
71
+ if (!miniappLoadingState.visible || !miniappLoadingState.appId) {
72
+ return null;
73
+ }
74
+ const Component = miniappLoadingComponent;
75
+ if (!Component) {
76
+ return null;
77
+ }
78
+ const resolvedProps = miniappLoadingResolveProps
79
+ ? miniappLoadingResolveProps({
80
+ appId: miniappLoadingState.appId,
81
+ mode: miniappLoadingState.mode,
82
+ status: miniappLoadingState.status,
83
+ title: miniappLoadingState.title,
84
+ icon: miniappLoadingState.icon,
85
+ extraData: miniappLoadingState.extraData,
86
+ errorMessage: miniappLoadingState.errorMessage,
87
+ installedInfo: miniappLoadingState.installedInfo,
88
+ })
89
+ : null;
90
+ return createElement(Component, {
91
+ appId: miniappLoadingState.appId,
92
+ mode: miniappLoadingState.mode,
93
+ status: miniappLoadingState.status,
94
+ title: resolvedProps?.title ?? miniappLoadingState.title,
95
+ icon: resolvedProps?.icon ?? miniappLoadingState.icon,
96
+ extraData: resolvedProps?.extraData ?? miniappLoadingState.extraData,
97
+ errorMessage: miniappLoadingState.errorMessage,
98
+ });
99
+ };
100
+ return NebulaInternalMiniappLoading;
101
+ });
102
+ internalMiniappLoadingRegistered = true;
103
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ export declare function createMiniAppPage<P extends Record<string, unknown>>(Component: React.ComponentType<P>): React.ComponentType<P>;
3
+ export declare function usePageOnLoad(callback: (params: Record<string, unknown>) => void): void;
4
+ export declare function usePageOnShow(callback: () => void): void;
5
+ export declare function usePageOnReady(callback: () => void): void;
6
+ export declare function usePageOnHide(callback: () => void): void;
7
+ export declare function usePageOnUnload(callback: () => void): void;
@@ -0,0 +1,93 @@
1
+ import React, { useContext, useEffect, useRef } from 'react';
2
+ import { PAGE_RESERVED_PROP_KEYS } from './nebulaNative';
3
+ import { Miniapp } from './miniappRuntime';
4
+ const MiniAppPageContext = React.createContext(null);
5
+ function extractPageParams(props) {
6
+ const params = {};
7
+ for (const key in props) {
8
+ if (Object.prototype.hasOwnProperty.call(props, key) &&
9
+ !PAGE_RESERVED_PROP_KEYS.has(key)) {
10
+ params[key] = props[key];
11
+ }
12
+ }
13
+ return params;
14
+ }
15
+ function usePageLifecycleSubscription(eventType, callback) {
16
+ const pageContext = useContext(MiniAppPageContext);
17
+ const callbackRef = useRef(callback);
18
+ callbackRef.current = callback;
19
+ useEffect(() => {
20
+ if (!pageContext?.instanceId) {
21
+ return;
22
+ }
23
+ return Miniapp.onPageLifecycle(event => {
24
+ if (event.type === eventType &&
25
+ event.instanceId === pageContext.instanceId) {
26
+ callbackRef.current();
27
+ }
28
+ });
29
+ }, [eventType, pageContext?.instanceId]);
30
+ }
31
+ export function createMiniAppPage(Component) {
32
+ return function NebulaMiniAppPage(props) {
33
+ const appId = typeof props.appId === 'string' && props.appId.length > 0
34
+ ? props.appId
35
+ : null;
36
+ useEffect(() => {
37
+ Miniapp.bootstrap(appId);
38
+ }, [appId]);
39
+ const pageContext = {
40
+ appId,
41
+ instanceId: typeof props.instanceId === 'string' && props.instanceId.length > 0
42
+ ? props.instanceId
43
+ : null,
44
+ params: extractPageParams(props),
45
+ routePath: typeof props.__routePath === 'string' ? props.__routePath : '/',
46
+ routeUrl: typeof props.__routeUrl === 'string' ? props.__routeUrl : '',
47
+ pageStyle: props.__pageConfig &&
48
+ typeof props.__pageConfig === 'object' &&
49
+ !Array.isArray(props.__pageConfig)
50
+ ? props.__pageConfig
51
+ : {},
52
+ };
53
+ return React.createElement(MiniAppPageContext.Provider, { value: pageContext }, React.createElement(Component, props));
54
+ };
55
+ }
56
+ export function usePageOnLoad(callback) {
57
+ const pageContext = useContext(MiniAppPageContext);
58
+ const callbackRef = useRef(callback);
59
+ callbackRef.current = callback;
60
+ useEffect(() => {
61
+ callbackRef.current(pageContext?.params ?? {});
62
+ }, [pageContext?.instanceId]);
63
+ }
64
+ export function usePageOnShow(callback) {
65
+ const callbackRef = useRef(callback);
66
+ callbackRef.current = callback;
67
+ useEffect(() => {
68
+ callbackRef.current();
69
+ }, []);
70
+ usePageLifecycleSubscription('show', callback);
71
+ }
72
+ export function usePageOnReady(callback) {
73
+ const callbackRef = useRef(callback);
74
+ callbackRef.current = callback;
75
+ useEffect(() => {
76
+ const frame = requestAnimationFrame(() => {
77
+ callbackRef.current();
78
+ });
79
+ return () => cancelAnimationFrame(frame);
80
+ }, []);
81
+ }
82
+ export function usePageOnHide(callback) {
83
+ usePageLifecycleSubscription('hide', callback);
84
+ }
85
+ export function usePageOnUnload(callback) {
86
+ const callbackRef = useRef(callback);
87
+ callbackRef.current = callback;
88
+ useEffect(() => {
89
+ return () => {
90
+ callbackRef.current();
91
+ };
92
+ }, []);
93
+ }
@@ -0,0 +1,33 @@
1
+ import type { BridgeMessage, HostVisibilityResult, NavigationResult, NebulaApiInvokeResult, NebulaHostApiDescriptionMap, NebulaHostCapabilityMap, NebulaPageStyle, PageLifecycleEvent } from './nebulaTypes';
2
+ export declare function compareCapabilityVersions(left: string, right: string): number;
3
+ export declare class Miniapp {
4
+ static bootstrap(appId?: string | null): void;
5
+ static navigateTo(url: string): Promise<NavigationResult>;
6
+ static redirectTo(url: string): Promise<NavigationResult>;
7
+ static reLaunch(url: string): Promise<NavigationResult>;
8
+ static navigateBack(delta?: number): Promise<NavigationResult>;
9
+ static setPageStyle(style: NebulaPageStyle): Promise<NavigationResult>;
10
+ static setNavigationBarTitle(title: string): Promise<NavigationResult>;
11
+ static setNavigationBarColor(options: {
12
+ backgroundColor?: string;
13
+ frontColor?: string;
14
+ }): Promise<NavigationResult>;
15
+ static getDeviceInfo(): unknown;
16
+ static getAppId(): string | null;
17
+ static getSandboxPath(): string;
18
+ static showToast(title: string): Promise<NavigationResult>;
19
+ static postMessageToHost(message: Record<string, unknown>): Promise<NavigationResult>;
20
+ static bringHostToFront(): Promise<HostVisibilityResult>;
21
+ static restoreMiniApp(token?: string | null): Promise<HostVisibilityResult>;
22
+ static presentHostModal(moduleName: string, props?: Record<string, unknown>): Promise<NavigationResult>;
23
+ static dismissHostModal(): Promise<NavigationResult>;
24
+ static invokeHostApi<TData = unknown>(apiName: string, payload?: Record<string, unknown>, version?: string, timeoutMs?: number): Promise<NebulaApiInvokeResult<TData>>;
25
+ static getCapabilities(): Promise<{
26
+ bridgeVersion: string;
27
+ capabilities: NebulaHostCapabilityMap;
28
+ }>;
29
+ static isSupported(apiName: string, minimumVersion?: string): Promise<boolean>;
30
+ static getHostApiDescriptions(timeoutMs?: number): Promise<NebulaHostApiDescriptionMap>;
31
+ static onHostMessage(listener: (event: BridgeMessage) => void): () => void;
32
+ static onPageLifecycle(listener: (event: PageLifecycleEvent) => void): () => void;
33
+ }