@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,233 @@
1
+ import { addNebulaEventListener, getNebulaNativeModule, isProtocolResponse, NEBULA_MINI_APP_MESSAGE_EVENT, NEBULA_PAGE_LIFECYCLE_EVENT, } from './nebulaNative';
2
+ let currentMiniAppId = null;
3
+ let miniAppProtocolListening = false;
4
+ const pendingProtocolRequests = new Map();
5
+ export function compareCapabilityVersions(left, right) {
6
+ const leftParts = left.split('.').map(part => Number(part) || 0);
7
+ const rightParts = right.split('.').map(part => Number(part) || 0);
8
+ const maxLength = Math.max(leftParts.length, rightParts.length);
9
+ for (let index = 0; index < maxLength; index += 1) {
10
+ const leftPart = leftParts[index] ?? 0;
11
+ const rightPart = rightParts[index] ?? 0;
12
+ if (leftPart > rightPart) {
13
+ return 1;
14
+ }
15
+ if (leftPart < rightPart) {
16
+ return -1;
17
+ }
18
+ }
19
+ return 0;
20
+ }
21
+ function createProtocolRequestId() {
22
+ return `nebula-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
23
+ }
24
+ function ensureMiniAppProtocolListener() {
25
+ if (miniAppProtocolListening) {
26
+ return;
27
+ }
28
+ const unsubscribe = addNebulaEventListener(NEBULA_MINI_APP_MESSAGE_EVENT, (event) => {
29
+ const message = event.message;
30
+ if (!isProtocolResponse(message)) {
31
+ return;
32
+ }
33
+ const pending = pendingProtocolRequests.get(message.requestId);
34
+ if (!pending) {
35
+ console.warn('[NebulaMiniAppAPI] missing pending request', {
36
+ kind: message.kind,
37
+ requestId: message.requestId,
38
+ pendingRequestIds: Array.from(pendingProtocolRequests.keys()),
39
+ });
40
+ return;
41
+ }
42
+ clearTimeout(pending.timeoutId);
43
+ pendingProtocolRequests.delete(message.requestId);
44
+ if (message.kind === 'capabilities') {
45
+ pending.resolve(message.data);
46
+ return;
47
+ }
48
+ if (message.kind === 'apiDescriptions') {
49
+ pending.resolve(message.data);
50
+ return;
51
+ }
52
+ if (message.kind === 'invokeResult') {
53
+ pending.resolve(message.result);
54
+ }
55
+ });
56
+ if (!unsubscribe) {
57
+ return;
58
+ }
59
+ miniAppProtocolListening = true;
60
+ }
61
+ export class Miniapp {
62
+ static bootstrap(appId) {
63
+ if (typeof appId === 'string' && appId.length > 0) {
64
+ currentMiniAppId = appId;
65
+ globalThis.__nebulaCurrentAppId = appId;
66
+ }
67
+ }
68
+ static async navigateTo(url) {
69
+ return getNebulaNativeModule().navigateTo(currentMiniAppId || '', url);
70
+ }
71
+ static async redirectTo(url) {
72
+ return getNebulaNativeModule().redirectTo(currentMiniAppId || '', url);
73
+ }
74
+ static async reLaunch(url) {
75
+ return getNebulaNativeModule().reLaunch(currentMiniAppId || '', url);
76
+ }
77
+ static async navigateBack(delta = 1) {
78
+ return getNebulaNativeModule().navigateBack(currentMiniAppId || '', delta);
79
+ }
80
+ static async setPageStyle(style) {
81
+ return getNebulaNativeModule().setPageStyle(currentMiniAppId || '', style);
82
+ }
83
+ static async setNavigationBarTitle(title) {
84
+ return this.setPageStyle({ navigationBarTitleText: title });
85
+ }
86
+ static async setNavigationBarColor(options) {
87
+ return this.setPageStyle({
88
+ navigationBarBackgroundColor: options.backgroundColor,
89
+ navigationBarTextColor: options.frontColor,
90
+ });
91
+ }
92
+ static getDeviceInfo() {
93
+ return getNebulaNativeModule().getDeviceInfo();
94
+ }
95
+ static getAppId() {
96
+ return currentMiniAppId;
97
+ }
98
+ static getSandboxPath() {
99
+ return `/Documents/MiniApps/${currentMiniAppId || ''}`;
100
+ }
101
+ static async showToast(title) {
102
+ return getNebulaNativeModule().showToast(title);
103
+ }
104
+ static async postMessageToHost(message) {
105
+ return getNebulaNativeModule().postMessageToHost(currentMiniAppId || '', message);
106
+ }
107
+ static async bringHostToFront() {
108
+ return getNebulaNativeModule().bringHostToFront();
109
+ }
110
+ static async restoreMiniApp(token) {
111
+ return getNebulaNativeModule().restoreMiniApp(token);
112
+ }
113
+ static async presentHostModal(moduleName, props = {}) {
114
+ return getNebulaNativeModule().presentHostModal(moduleName, props);
115
+ }
116
+ static async dismissHostModal() {
117
+ return getNebulaNativeModule().dismissHostModal();
118
+ }
119
+ static async invokeHostApi(apiName, payload = {}, version = '1.0.0', timeoutMs = 15000) {
120
+ ensureMiniAppProtocolListener();
121
+ return new Promise((resolve, reject) => {
122
+ const requestId = createProtocolRequestId();
123
+ const timeoutId = timeoutMs > 0
124
+ ? setTimeout(() => {
125
+ console.warn('[NebulaMiniAppAPI] invokeHostApi timeout', {
126
+ apiName,
127
+ requestId,
128
+ pendingRequestIds: Array.from(pendingProtocolRequests.keys()),
129
+ });
130
+ pendingProtocolRequests.delete(requestId);
131
+ reject(new Error(`Timed out waiting for host API: ${apiName}`));
132
+ }, timeoutMs)
133
+ : setTimeout(() => { }, 2147483647);
134
+ pendingProtocolRequests.set(requestId, {
135
+ resolve,
136
+ reject,
137
+ timeoutId,
138
+ });
139
+ this.postMessageToHost({
140
+ __nebulaProtocol: 'api.v1',
141
+ kind: 'invoke',
142
+ requestId,
143
+ api: apiName,
144
+ version,
145
+ payload,
146
+ }).catch(error => {
147
+ clearTimeout(timeoutId);
148
+ pendingProtocolRequests.delete(requestId);
149
+ console.error('[NebulaMiniAppAPI] invokeHostApi postMessageToHost failed', {
150
+ apiName,
151
+ requestId,
152
+ error,
153
+ });
154
+ reject(error);
155
+ });
156
+ });
157
+ }
158
+ static async getCapabilities() {
159
+ ensureMiniAppProtocolListener();
160
+ return new Promise((resolve, reject) => {
161
+ const requestId = createProtocolRequestId();
162
+ const timeoutId = setTimeout(() => {
163
+ pendingProtocolRequests.delete(requestId);
164
+ reject(new Error('Timed out waiting for host capabilities'));
165
+ }, 15000);
166
+ pendingProtocolRequests.set(requestId, {
167
+ resolve,
168
+ reject,
169
+ timeoutId,
170
+ });
171
+ this.postMessageToHost({
172
+ __nebulaProtocol: 'api.v1',
173
+ kind: 'getCapabilities',
174
+ requestId,
175
+ }).catch(error => {
176
+ clearTimeout(timeoutId);
177
+ pendingProtocolRequests.delete(requestId);
178
+ reject(error);
179
+ });
180
+ });
181
+ }
182
+ static async isSupported(apiName, minimumVersion) {
183
+ const { capabilities } = await this.getCapabilities();
184
+ const capability = capabilities[apiName];
185
+ if (!capability?.supported) {
186
+ return false;
187
+ }
188
+ if (!minimumVersion) {
189
+ return true;
190
+ }
191
+ return compareCapabilityVersions(capability.version, minimumVersion) >= 0;
192
+ }
193
+ static async getHostApiDescriptions(timeoutMs = 15000) {
194
+ ensureMiniAppProtocolListener();
195
+ return new Promise((resolve, reject) => {
196
+ const requestId = createProtocolRequestId();
197
+ const timeoutId = setTimeout(() => {
198
+ pendingProtocolRequests.delete(requestId);
199
+ reject(new Error('Timed out waiting for host API descriptions'));
200
+ }, timeoutMs);
201
+ pendingProtocolRequests.set(requestId, {
202
+ resolve,
203
+ reject,
204
+ timeoutId,
205
+ });
206
+ this.postMessageToHost({
207
+ __nebulaProtocol: 'api.v1',
208
+ kind: 'getApiDescriptions',
209
+ requestId,
210
+ }).catch(error => {
211
+ clearTimeout(timeoutId);
212
+ pendingProtocolRequests.delete(requestId);
213
+ reject(error);
214
+ });
215
+ });
216
+ }
217
+ static onHostMessage(listener) {
218
+ const unsubscribe = addNebulaEventListener(NEBULA_MINI_APP_MESSAGE_EVENT, listener);
219
+ if (!unsubscribe) {
220
+ console.warn('[Nebula] Native event emitter unavailable for host messages');
221
+ return () => { };
222
+ }
223
+ return unsubscribe;
224
+ }
225
+ static onPageLifecycle(listener) {
226
+ const unsubscribe = addNebulaEventListener(NEBULA_PAGE_LIFECYCLE_EVENT, listener);
227
+ if (!unsubscribe) {
228
+ console.warn('[Nebula] Native event emitter unavailable for page lifecycle events');
229
+ return () => { };
230
+ }
231
+ return unsubscribe;
232
+ }
233
+ }
@@ -0,0 +1,12 @@
1
+ import { NativeEventEmitter } from 'react-native';
2
+ import type { BridgeMessage, NebulaNativeModuleType, NebulaProtocolRequest, NebulaProtocolResponse } from './nebulaTypes';
3
+ export declare const nebulaEventEmitter: NativeEventEmitter;
4
+ export declare const NEBULA_HOST_MESSAGE_EVENT = "NebulaHostMessage";
5
+ export declare const NEBULA_MINI_APP_MESSAGE_EVENT = "NebulaMiniAppMessage";
6
+ export declare const NEBULA_PAGE_LIFECYCLE_EVENT = "NebulaPageLifecycle";
7
+ export declare const NEBULA_INTERNAL_MINIAPP_LOADING_MODULE = "NebulaInternalMiniappLoading";
8
+ export declare const PAGE_RESERVED_PROP_KEYS: Set<string>;
9
+ export declare function getNebulaNativeModule(): NebulaNativeModuleType;
10
+ export declare function addNebulaEventListener<TEvent = BridgeMessage>(eventName: string, listener: (event: TEvent) => void): (() => void) | null;
11
+ export declare function isProtocolRequest(message: Record<string, unknown>): message is NebulaProtocolRequest;
12
+ export declare function isProtocolResponse(message: Record<string, unknown>): message is NebulaProtocolResponse;
@@ -0,0 +1,49 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+ import NebulaNativeModuleSpec from './specs/NativeNebulaModule';
4
+ const turboNebulaNativeModule = NebulaNativeModuleSpec ??
5
+ TurboModuleRegistry.get('NebulaNativeModule');
6
+ const { NebulaNativeModule: legacyNebulaNativeModule } = NativeModules;
7
+ const NebulaNativeModule = turboNebulaNativeModule ?? legacyNebulaNativeModule;
8
+ export const nebulaEventEmitter = legacyNebulaNativeModule
9
+ ? new NativeEventEmitter(legacyNebulaNativeModule)
10
+ : null;
11
+ export const NEBULA_HOST_MESSAGE_EVENT = 'NebulaHostMessage';
12
+ export const NEBULA_MINI_APP_MESSAGE_EVENT = 'NebulaMiniAppMessage';
13
+ export const NEBULA_PAGE_LIFECYCLE_EVENT = 'NebulaPageLifecycle';
14
+ export const NEBULA_INTERNAL_MINIAPP_LOADING_MODULE = 'NebulaInternalMiniappLoading';
15
+ export const PAGE_RESERVED_PROP_KEYS = new Set([
16
+ 'appId',
17
+ 'instanceId',
18
+ 'sandboxPath',
19
+ 'title',
20
+ '__pageConfig',
21
+ '__routePath',
22
+ '__routeUrl',
23
+ ]);
24
+ if (!NebulaNativeModule) {
25
+ console.warn('[Nebula] NebulaNativeModule not found. Make sure Nebula framework is integrated.');
26
+ }
27
+ export function getNebulaNativeModule() {
28
+ if (!NebulaNativeModule) {
29
+ throw new Error('[Nebula] NebulaNativeModule not available');
30
+ }
31
+ return NebulaNativeModule;
32
+ }
33
+ export function addNebulaEventListener(eventName, listener) {
34
+ if (!nebulaEventEmitter) {
35
+ return null;
36
+ }
37
+ const sub = nebulaEventEmitter.addListener(eventName, listener);
38
+ return () => sub.remove();
39
+ }
40
+ export function isProtocolRequest(message) {
41
+ return (message.__nebulaProtocol === 'api.v1' &&
42
+ typeof message.kind === 'string' &&
43
+ typeof message.requestId === 'string');
44
+ }
45
+ export function isProtocolResponse(message) {
46
+ return (message.__nebulaProtocol === 'api.v1' &&
47
+ typeof message.kind === 'string' &&
48
+ typeof message.requestId === 'string');
49
+ }
@@ -0,0 +1,232 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { TurboModule } from 'react-native';
3
+ import type { NebulaPageStyle } from './specs/NativeNebulaModule';
4
+ export type { MiniAppUpdateStrategy } from './specs/NativeNebulaModule';
5
+ export type { NebulaPageStyle } from './specs/NativeNebulaModule';
6
+ export type { NebulaCapabilitiesResult as NebulaNativeCapabilitiesResult, NebulaCapabilityMap as NebulaNativeCapabilityMap, } from './specs/NativeNebulaModule';
7
+ export type MiniAppResult = {
8
+ success: boolean;
9
+ appId: string;
10
+ mode?: string;
11
+ };
12
+ export type InstalledMiniAppsResult = {
13
+ apps: string[];
14
+ };
15
+ export type InstalledMiniAppInfo = {
16
+ appId: string;
17
+ mode?: string | null;
18
+ bundlePath?: string | null;
19
+ sourceUrl?: string | null;
20
+ version?: string | null;
21
+ updateStrategy?: 'auto' | 'manual' | null;
22
+ };
23
+ export type InstalledMiniAppInfoResult = {
24
+ installed: boolean;
25
+ app?: InstalledMiniAppInfo | null;
26
+ };
27
+ export type MiniAppUpdateInfo = {
28
+ appId: string;
29
+ currentVersion?: string | null;
30
+ latestVersion?: string | null;
31
+ hasUpdate: boolean;
32
+ updateStrategy: 'auto' | 'manual';
33
+ mode?: string | null;
34
+ sourceUrl?: string | null;
35
+ };
36
+ export type MiniAppVersionType = 'release' | 'experience';
37
+ export type MiniappLoadingStatus = 'installing' | 'loading' | 'ready' | 'error';
38
+ export type MiniappLoadingExtraData = Record<string, unknown>;
39
+ export type MiniappLoadingProps = {
40
+ appId: string;
41
+ mode: 'development' | 'production';
42
+ status: MiniappLoadingStatus;
43
+ title?: string | null;
44
+ icon?: ReactNode;
45
+ extraData?: MiniappLoadingExtraData | null;
46
+ errorMessage?: string | null;
47
+ };
48
+ export type MiniappLoadingResolveContext = {
49
+ appId: string;
50
+ mode: 'development' | 'production';
51
+ status: MiniappLoadingStatus;
52
+ title?: string | null;
53
+ icon?: ReactNode;
54
+ extraData?: MiniappLoadingExtraData | null;
55
+ errorMessage?: string | null;
56
+ installedInfo?: InstalledMiniAppInfo | null;
57
+ };
58
+ export type MiniappLoadingResolvedProps = Partial<Pick<MiniappLoadingProps, 'title' | 'icon' | 'extraData'>>;
59
+ export type ServerBaseURLResult = {
60
+ serverBaseURL?: string | null;
61
+ };
62
+ export type MiniappLoadingDelayResult = {
63
+ delayMs: number;
64
+ };
65
+ export type NavigationResult = {
66
+ errMsg: string;
67
+ };
68
+ export type HostVisibilityResult = {
69
+ success: boolean;
70
+ token?: string | null;
71
+ };
72
+ export type RegisteredMiniAppManifest = {
73
+ entryPagePath?: string;
74
+ pageConfigs?: Record<string, NebulaPageStyle>;
75
+ pages: Record<string, string>;
76
+ updateStrategy?: 'auto' | 'manual';
77
+ version?: string;
78
+ window?: NebulaPageStyle;
79
+ };
80
+ export type BridgeMessage = {
81
+ appId: string;
82
+ message: Record<string, unknown>;
83
+ timestamp?: number;
84
+ };
85
+ export type NebulaApiError = {
86
+ code: string;
87
+ message: string;
88
+ details?: Record<string, unknown>;
89
+ };
90
+ export type NebulaApiInvokeResult<T = unknown> = {
91
+ ok: true;
92
+ data: T;
93
+ } | {
94
+ ok: false;
95
+ error: NebulaApiError;
96
+ };
97
+ export type NebulaHostCapabilityDescriptor = {
98
+ supported: boolean;
99
+ version: string;
100
+ };
101
+ export type NebulaHostCapabilityMap = Record<string, NebulaHostCapabilityDescriptor>;
102
+ export type NebulaApiFieldDescriptor = {
103
+ name: string;
104
+ type: string;
105
+ required?: boolean;
106
+ description: string;
107
+ };
108
+ export type NebulaApiExampleDescriptor = {
109
+ title: string;
110
+ code: string;
111
+ };
112
+ export type NebulaHostApiDescription = {
113
+ summary: string;
114
+ description?: string;
115
+ params?: NebulaApiFieldDescriptor[];
116
+ returns?: {
117
+ type: string;
118
+ description: string;
119
+ };
120
+ tags?: string[];
121
+ examples?: NebulaApiExampleDescriptor[];
122
+ };
123
+ export type NebulaHostApiDescriptionMap = Record<string, NebulaHostApiDescription>;
124
+ export type NebulaProtocolRequest = {
125
+ __nebulaProtocol: 'api.v1';
126
+ kind: 'getCapabilities';
127
+ requestId: string;
128
+ } | {
129
+ __nebulaProtocol: 'api.v1';
130
+ kind: 'getApiDescriptions';
131
+ requestId: string;
132
+ } | {
133
+ __nebulaProtocol: 'api.v1';
134
+ kind: 'invoke';
135
+ requestId: string;
136
+ api: string;
137
+ version?: string;
138
+ payload?: Record<string, unknown>;
139
+ };
140
+ export type NebulaProtocolResponse = {
141
+ __nebulaProtocol: 'api.v1';
142
+ kind: 'capabilities';
143
+ requestId: string;
144
+ data: {
145
+ bridgeVersion: string;
146
+ capabilities: NebulaHostCapabilityMap;
147
+ };
148
+ } | {
149
+ __nebulaProtocol: 'api.v1';
150
+ kind: 'apiDescriptions';
151
+ requestId: string;
152
+ data: NebulaHostApiDescriptionMap;
153
+ } | {
154
+ __nebulaProtocol: 'api.v1';
155
+ kind: 'invokeResult';
156
+ requestId: string;
157
+ result: NebulaApiInvokeResult;
158
+ };
159
+ export type NebulaHostApiContext = {
160
+ appId: string;
161
+ requestId: string;
162
+ version?: string;
163
+ };
164
+ export type NebulaHostApiHandler = {
165
+ version: string;
166
+ supported?: boolean | (() => boolean | Promise<boolean>);
167
+ description?: NebulaHostApiDescription;
168
+ handle: (payload: Record<string, unknown>, context: NebulaHostApiContext) => Promise<NebulaApiInvokeResult> | NebulaApiInvokeResult;
169
+ };
170
+ export type PendingProtocolRequest = {
171
+ reject: (reason?: unknown) => void;
172
+ resolve: (value: any) => void;
173
+ timeoutId: ReturnType<typeof setTimeout>;
174
+ };
175
+ export type PageLifecycleEvent = {
176
+ appId: string;
177
+ instanceId: string;
178
+ routePath?: string;
179
+ type: 'show' | 'hide' | 'unload' | 'ready';
180
+ };
181
+ export type MiniAppPageContextValue = {
182
+ appId: string | null;
183
+ instanceId: string | null;
184
+ params: Record<string, unknown>;
185
+ routePath: string;
186
+ routeUrl: string;
187
+ pageStyle: Record<string, unknown>;
188
+ };
189
+ export type NebulaNativeModuleType = TurboModule & {
190
+ openMiniApp: (appId: string, initialProps: Record<string, unknown>) => Promise<MiniAppResult>;
191
+ openMiniAppWithBundleURL: (appId: string, bundleURL: string, connectToURLMetroServer: boolean, initialProps: Record<string, unknown>) => Promise<MiniAppResult>;
192
+ preloadMiniApp: (appId: string) => Promise<MiniAppResult>;
193
+ preloadMiniAppWithBundleURL: (appId: string, bundleURL: string, connectToURLMetroServer: boolean) => Promise<MiniAppResult>;
194
+ installMiniApp: (appId: string, bundleURL: string) => Promise<MiniAppResult>;
195
+ installMiniAppWithBundleURL: (appId: string, bundleURL: string, connectToURLMetroServer: boolean) => Promise<MiniAppResult>;
196
+ installMiniAppFromURLs: (appId: string, bundleURL: string, manifestURL: string, assetsURL: string, connectToURLMetroServer: boolean) => Promise<MiniAppResult>;
197
+ closeMiniApp: (appId: string) => Promise<MiniAppResult>;
198
+ uninstallMiniApp: (appId: string) => Promise<MiniAppResult>;
199
+ getCapabilities: () => Promise<{
200
+ bridgeVersion: string;
201
+ capabilities: Record<string, string>;
202
+ }>;
203
+ getServerBaseURL: () => Promise<ServerBaseURLResult>;
204
+ setServerBaseURL: (serverBaseURL?: string | null) => Promise<ServerBaseURLResult>;
205
+ setMiniappLoadingDelay: (delayMs?: number | null) => Promise<MiniappLoadingDelayResult>;
206
+ setMiniappLoadingEnterContentDelay: (delayMs?: number | null) => Promise<MiniappLoadingDelayResult>;
207
+ registerRoutes: (appId: string, routes: Record<string, string>) => Promise<{
208
+ success: boolean;
209
+ appId: string;
210
+ count: number;
211
+ }>;
212
+ registerManifest: (appId: string, manifest: RegisteredMiniAppManifest) => Promise<{
213
+ success: boolean;
214
+ appId: string;
215
+ count: number;
216
+ }>;
217
+ postMessageToHost: (appId: string, message: Record<string, unknown>) => Promise<NavigationResult>;
218
+ postMessageToMiniApp: (appId: string, message: Record<string, unknown>) => Promise<NavigationResult>;
219
+ bringHostToFront: () => Promise<HostVisibilityResult>;
220
+ restoreMiniApp: (token?: string | null) => Promise<HostVisibilityResult>;
221
+ presentHostModal: (moduleName: string, props: Record<string, unknown>) => Promise<NavigationResult>;
222
+ dismissHostModal: () => Promise<NavigationResult>;
223
+ getInstalledMiniApps: () => Promise<InstalledMiniAppsResult>;
224
+ getInstalledMiniAppInfo: (appId: string) => Promise<InstalledMiniAppInfoResult>;
225
+ navigateTo: (appId: string, url: string) => Promise<NavigationResult>;
226
+ redirectTo: (appId: string, url: string) => Promise<NavigationResult>;
227
+ reLaunch: (appId: string, url: string) => Promise<NavigationResult>;
228
+ navigateBack: (appId: string, delta: number) => Promise<NavigationResult>;
229
+ setPageStyle: (appId: string, style: NebulaPageStyle) => Promise<NavigationResult>;
230
+ showToast: (title: string) => Promise<NavigationResult>;
231
+ getDeviceInfo: () => Record<string, unknown>;
232
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ export type MiniAppPageConfig = {
2
+ route?: string;
3
+ backgroundColor?: string;
4
+ navigationBarBackgroundColor?: string;
5
+ navigationBarTextColor?: string;
6
+ navigationBarTitleText?: string;
7
+ navigationStyle?: 'default' | 'custom';
8
+ visualEffectInBackground?: 'blur' | 'none';
9
+ };
10
+ export declare function definePageConfig<T extends MiniAppPageConfig>(config: T): T;
@@ -0,0 +1,3 @@
1
+ export function definePageConfig(config) {
2
+ return config;
3
+ }
@@ -0,0 +1,86 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export type MiniAppUpdateStrategy = 'auto' | 'manual';
4
+ export type MiniAppResult = {
5
+ success: boolean;
6
+ appId: string;
7
+ mode?: string;
8
+ };
9
+ export type InstalledMiniAppsResult = {
10
+ apps: string[];
11
+ };
12
+ export type InstalledMiniAppInfo = {
13
+ appId: string;
14
+ mode?: string | null;
15
+ bundlePath?: string | null;
16
+ sourceUrl?: string | null;
17
+ version?: string | null;
18
+ updateStrategy?: MiniAppUpdateStrategy | null;
19
+ };
20
+ export type InstalledMiniAppInfoResult = {
21
+ installed: boolean;
22
+ app?: InstalledMiniAppInfo | null;
23
+ };
24
+ export type ServerBaseURLResult = {
25
+ serverBaseURL?: string | null;
26
+ };
27
+ export type MiniappLoadingDelayResult = {
28
+ delayMs: number;
29
+ };
30
+ export type NebulaCapabilityMap = {
31
+ [capabilityName: string]: string;
32
+ };
33
+ export type NebulaCapabilitiesResult = {
34
+ bridgeVersion: string;
35
+ capabilities: NebulaCapabilityMap;
36
+ };
37
+ export type NavigationResult = {
38
+ errMsg: string;
39
+ };
40
+ export type HostVisibilityResult = {
41
+ success: boolean;
42
+ token?: string | null;
43
+ };
44
+ export type NebulaPageStyle = {
45
+ backgroundColor?: string;
46
+ navigationBarBackgroundColor?: string;
47
+ navigationBarTextColor?: string;
48
+ navigationBarTitleText?: string;
49
+ navigationStyle?: 'default' | 'custom';
50
+ visualEffectInBackground?: 'blur' | 'none';
51
+ };
52
+ export interface Spec extends TurboModule {
53
+ openMiniApp(appId: string, initialProps: UnsafeObject): Promise<MiniAppResult>;
54
+ openMiniAppWithBundleURL(appId: string, bundleURL: string, connectToURLMetroServer: boolean, initialProps: UnsafeObject): Promise<MiniAppResult>;
55
+ preloadMiniApp(appId: string): Promise<MiniAppResult>;
56
+ preloadMiniAppWithBundleURL(appId: string, bundleURL: string, connectToURLMetroServer: boolean): Promise<MiniAppResult>;
57
+ installMiniApp(appId: string, bundleURL: string): Promise<MiniAppResult>;
58
+ installMiniAppWithBundleURL(appId: string, bundleURL: string, connectToURLMetroServer: boolean): Promise<MiniAppResult>;
59
+ installMiniAppFromURLs(appId: string, bundleURL: string, manifestURL: string, assetsURL: string, connectToURLMetroServer: boolean): Promise<MiniAppResult>;
60
+ closeMiniApp(appId: string): Promise<MiniAppResult>;
61
+ uninstallMiniApp(appId: string): Promise<MiniAppResult>;
62
+ getCapabilities(): Promise<NebulaCapabilitiesResult>;
63
+ getServerBaseURL(): Promise<ServerBaseURLResult>;
64
+ setServerBaseURL(serverBaseURL?: string | null): Promise<ServerBaseURLResult>;
65
+ setMiniappLoadingDelay(delayMs?: number | null): Promise<MiniappLoadingDelayResult>;
66
+ setMiniappLoadingEnterContentDelay(delayMs?: number | null): Promise<MiniappLoadingDelayResult>;
67
+ getInstalledMiniApps(): Promise<InstalledMiniAppsResult>;
68
+ getInstalledMiniAppInfo(appId: string): Promise<InstalledMiniAppInfoResult>;
69
+ registerRoutes(appId: string, routes: UnsafeObject): Promise<UnsafeObject>;
70
+ registerManifest(appId: string, manifest: UnsafeObject): Promise<UnsafeObject>;
71
+ postMessageToHost(appId: string, message: UnsafeObject): Promise<NavigationResult>;
72
+ postMessageToMiniApp(appId: string, message: UnsafeObject): Promise<NavigationResult>;
73
+ bringHostToFront(): Promise<HostVisibilityResult>;
74
+ restoreMiniApp(token?: string | null): Promise<HostVisibilityResult>;
75
+ presentHostModal(moduleName: string, props: UnsafeObject): Promise<NavigationResult>;
76
+ dismissHostModal(): Promise<NavigationResult>;
77
+ navigateTo(appId: string, url: string): Promise<NavigationResult>;
78
+ redirectTo(appId: string, url: string): Promise<NavigationResult>;
79
+ reLaunch(appId: string, url: string): Promise<NavigationResult>;
80
+ navigateBack(appId: string, delta: number): Promise<NavigationResult>;
81
+ setPageStyle(appId: string, style: UnsafeObject): Promise<NavigationResult>;
82
+ showToast(title: string): Promise<NavigationResult>;
83
+ getDeviceInfo(): UnsafeObject;
84
+ }
85
+ declare const _default: Spec;
86
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ export default TurboModuleRegistry.get('NebulaNativeModule');
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@nebula-rn/sdk",
3
+ "version": "0.0.1",
4
+ "description": "Nebula Mini-App Framework - JavaScript/TypeScript client SDK",
5
+ "author": "Hector Zhuang",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Hector-Zhuang/nebula.git",
10
+ "directory": "packages/nebula-sdk"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Hector-Zhuang/nebula/issues"
14
+ },
15
+ "homepage": "https://github.com/Hector-Zhuang/nebula/tree/main/packages/nebula-sdk#readme",
16
+ "keywords": ["nebula", "superapp", "miniapp", "react-native"],
17
+ "main": "./dist/index.js",
18
+ "react-native": "./src/index.ts",
19
+ "source": "./src/index.ts",
20
+ "types": "./dist/index.d.ts",
21
+ "files": ["dist", "src", "README.md"],
22
+ "publishConfig": { "access": "public" },
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "lint": "eslint src --ext .ts,.tsx",
26
+ "prepack": "npm run build"
27
+ },
28
+ "codegenConfig": {
29
+ "name": "NebulaSpecs",
30
+ "type": "modules",
31
+ "jsSrcsDir": "src/specs",
32
+ "android": {
33
+ "javaPackageName": "com.superapp.specs"
34
+ }
35
+ },
36
+ "peerDependencies": {
37
+ "react": ">=19",
38
+ "react-native": ">=0.83"
39
+ }
40
+ }