@appolabs/sdk 1.0.0

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,263 @@
1
+ /**
2
+ * Categorized error codes for bridge failures
3
+ */
4
+ declare enum AppoErrorCode {
5
+ NOT_NATIVE = "NOT_NATIVE",
6
+ TIMEOUT = "TIMEOUT",
7
+ NATIVE_ERROR = "NATIVE_ERROR",
8
+ BRIDGE_UNAVAILABLE = "BRIDGE_UNAVAILABLE"
9
+ }
10
+ /**
11
+ * Structured error with code and optional detail for programmatic handling
12
+ */
13
+ declare class AppoError extends Error {
14
+ readonly code: AppoErrorCode;
15
+ readonly detail?: string;
16
+ constructor(code: AppoErrorCode, message: string, detail?: string);
17
+ }
18
+ /**
19
+ * Log severity levels for bridge activity observation
20
+ */
21
+ type AppoLogLevel = 'debug' | 'warn' | 'error';
22
+ /**
23
+ * Callback for observing bridge activity without SDK emitting console output
24
+ */
25
+ interface AppoLogger {
26
+ (level: AppoLogLevel, message: string, data?: unknown): void;
27
+ }
28
+ /**
29
+ * Permission status returned by native APIs
30
+ */
31
+ type PermissionStatus = 'granted' | 'denied' | 'undetermined';
32
+ /**
33
+ * Push notification message received from native
34
+ */
35
+ interface PushMessage {
36
+ title: string;
37
+ body: string;
38
+ data?: Record<string, unknown>;
39
+ }
40
+ /**
41
+ * Push notification response when user taps a notification
42
+ */
43
+ interface PushResponse {
44
+ title: string;
45
+ body: string;
46
+ data?: Record<string, unknown>;
47
+ actionIdentifier: string;
48
+ }
49
+ /**
50
+ * Result from camera capture
51
+ */
52
+ interface CameraResult {
53
+ uri: string;
54
+ base64?: string;
55
+ width: number;
56
+ height: number;
57
+ }
58
+ /**
59
+ * Geographic position
60
+ */
61
+ interface Position {
62
+ latitude: number;
63
+ longitude: number;
64
+ altitude?: number;
65
+ accuracy?: number;
66
+ timestamp: number;
67
+ }
68
+ /**
69
+ * Options for native share sheet
70
+ */
71
+ interface ShareOptions {
72
+ title?: string;
73
+ message?: string;
74
+ url?: string;
75
+ }
76
+ /**
77
+ * Result from share action
78
+ */
79
+ interface ShareResult {
80
+ success: boolean;
81
+ action?: string;
82
+ }
83
+ /**
84
+ * Network connectivity status
85
+ */
86
+ interface NetworkStatus {
87
+ isConnected: boolean;
88
+ type: 'wifi' | 'cellular' | 'none' | 'unknown';
89
+ }
90
+ /**
91
+ * Device information
92
+ */
93
+ interface DeviceInfo {
94
+ platform: 'ios' | 'android';
95
+ osVersion: string;
96
+ appVersion: string;
97
+ deviceId: string;
98
+ deviceName: string;
99
+ isTablet: boolean;
100
+ }
101
+ /**
102
+ * Haptic feedback intensity levels
103
+ */
104
+ type HapticImpactStyle = 'light' | 'medium' | 'heavy';
105
+ /**
106
+ * Haptic notification types
107
+ */
108
+ type HapticNotificationType = 'success' | 'warning' | 'error';
109
+ /**
110
+ * Push notifications API
111
+ */
112
+ interface PushApi {
113
+ requestPermission(): Promise<PermissionStatus>;
114
+ getToken(): Promise<string | null>;
115
+ onMessage(callback: (message: PushMessage) => void): () => void;
116
+ onResponse(callback: (response: PushResponse) => void): () => void;
117
+ }
118
+ /**
119
+ * Biometric authentication API
120
+ */
121
+ interface BiometricsApi {
122
+ isAvailable(): Promise<boolean>;
123
+ authenticate(reason: string): Promise<boolean>;
124
+ }
125
+ /**
126
+ * Camera API
127
+ */
128
+ interface CameraApi {
129
+ requestPermission(): Promise<PermissionStatus>;
130
+ takePicture(): Promise<CameraResult>;
131
+ }
132
+ /**
133
+ * Location/GPS API
134
+ */
135
+ interface LocationApi {
136
+ requestPermission(): Promise<PermissionStatus>;
137
+ getCurrentPosition(): Promise<Position>;
138
+ }
139
+ /**
140
+ * Haptic feedback API
141
+ */
142
+ interface HapticsApi {
143
+ impact(style: HapticImpactStyle): void;
144
+ notification(type: HapticNotificationType): void;
145
+ }
146
+ /**
147
+ * Secure storage API
148
+ */
149
+ interface StorageApi {
150
+ get(key: string): Promise<string | null>;
151
+ set(key: string, value: string): Promise<void>;
152
+ delete(key: string): Promise<void>;
153
+ }
154
+ /**
155
+ * Native share sheet API
156
+ */
157
+ interface ShareApi {
158
+ open(options: ShareOptions): Promise<ShareResult>;
159
+ }
160
+ /**
161
+ * Network status API
162
+ */
163
+ interface NetworkApi {
164
+ getStatus(): Promise<NetworkStatus>;
165
+ onChange(callback: (status: NetworkStatus) => void): () => void;
166
+ }
167
+ /**
168
+ * Device info API
169
+ */
170
+ interface DeviceApi {
171
+ getInfo(): Promise<DeviceInfo>;
172
+ }
173
+ /**
174
+ * Main Appo SDK interface
175
+ */
176
+ interface Appo {
177
+ /** Whether running inside a native Appo app */
178
+ isNative: boolean;
179
+ /** SDK version */
180
+ version: string;
181
+ /** Push notifications */
182
+ push: PushApi;
183
+ /** Biometric authentication (Face ID / Touch ID) */
184
+ biometrics: BiometricsApi;
185
+ /** Camera access */
186
+ camera: CameraApi;
187
+ /** GPS/Geolocation */
188
+ location: LocationApi;
189
+ /** Haptic feedback */
190
+ haptics: HapticsApi;
191
+ /** Secure storage */
192
+ storage: StorageApi;
193
+ /** Native share sheet */
194
+ share: ShareApi;
195
+ /** Network connectivity */
196
+ network: NetworkApi;
197
+ /** Device information */
198
+ device: DeviceApi;
199
+ }
200
+ /**
201
+ * Internal response format from native
202
+ */
203
+ interface BridgeResponse {
204
+ id: string;
205
+ success: boolean;
206
+ data?: unknown;
207
+ error?: string;
208
+ }
209
+ /**
210
+ * Event broadcast from native layer
211
+ */
212
+ interface BridgeEvent {
213
+ event: string;
214
+ data: unknown;
215
+ }
216
+ /**
217
+ * Type guard for BridgeResponse envelope validation
218
+ */
219
+ declare function isBridgeResponse(data: unknown): data is BridgeResponse;
220
+ /**
221
+ * Type guard for BridgeEvent validation
222
+ */
223
+ declare function isBridgeEvent(data: unknown): data is BridgeEvent;
224
+ declare global {
225
+ interface Window {
226
+ appo?: Appo;
227
+ ReactNativeWebView?: {
228
+ postMessage(message: string): void;
229
+ };
230
+ }
231
+ }
232
+
233
+ declare const VERSION: string;
234
+
235
+ /**
236
+ * Registers a callback to observe bridge activity. Pass `null` to disable.
237
+ * The SDK produces no console output by default.
238
+ * @param fn - Logger callback receiving level, message, and optional data, or `null` to disable.
239
+ */
240
+ declare function setLogger(fn: AppoLogger | null): void;
241
+
242
+ /**
243
+ * @module @appolabs/sdk
244
+ *
245
+ * JavaScript bridge SDK for native app features in React Native WebViews.
246
+ * Provides a unified API surface with automatic browser fallbacks.
247
+ */
248
+
249
+ /**
250
+ * Initializes the Appo SDK and attaches it to `window.appo`.
251
+ * Returns the existing instance if already initialized.
252
+ * @returns The singleton Appo SDK instance.
253
+ * @throws {Error} If called outside a browser environment (no `window`).
254
+ */
255
+ declare function initAppo(): Appo;
256
+ /**
257
+ * Gets the Appo SDK instance, initializing it on first call.
258
+ * Subsequent calls return the same singleton instance.
259
+ * @returns The singleton Appo SDK instance.
260
+ */
261
+ declare function getAppo(): Appo;
262
+
263
+ export { type Appo, AppoError, AppoErrorCode, type AppoLogLevel, type AppoLogger, type BiometricsApi, type BridgeEvent, type BridgeResponse, type CameraApi, type CameraResult, type DeviceApi, type DeviceInfo, type HapticImpactStyle, type HapticNotificationType, type HapticsApi, type LocationApi, type NetworkApi, type NetworkStatus, type PermissionStatus, type Position, type PushApi, type PushMessage, type PushResponse, type ShareApi, type ShareOptions, type ShareResult, type StorageApi, VERSION, getAppo as default, getAppo, initAppo, isBridgeEvent, isBridgeResponse, setLogger };
@@ -0,0 +1,263 @@
1
+ /**
2
+ * Categorized error codes for bridge failures
3
+ */
4
+ declare enum AppoErrorCode {
5
+ NOT_NATIVE = "NOT_NATIVE",
6
+ TIMEOUT = "TIMEOUT",
7
+ NATIVE_ERROR = "NATIVE_ERROR",
8
+ BRIDGE_UNAVAILABLE = "BRIDGE_UNAVAILABLE"
9
+ }
10
+ /**
11
+ * Structured error with code and optional detail for programmatic handling
12
+ */
13
+ declare class AppoError extends Error {
14
+ readonly code: AppoErrorCode;
15
+ readonly detail?: string;
16
+ constructor(code: AppoErrorCode, message: string, detail?: string);
17
+ }
18
+ /**
19
+ * Log severity levels for bridge activity observation
20
+ */
21
+ type AppoLogLevel = 'debug' | 'warn' | 'error';
22
+ /**
23
+ * Callback for observing bridge activity without SDK emitting console output
24
+ */
25
+ interface AppoLogger {
26
+ (level: AppoLogLevel, message: string, data?: unknown): void;
27
+ }
28
+ /**
29
+ * Permission status returned by native APIs
30
+ */
31
+ type PermissionStatus = 'granted' | 'denied' | 'undetermined';
32
+ /**
33
+ * Push notification message received from native
34
+ */
35
+ interface PushMessage {
36
+ title: string;
37
+ body: string;
38
+ data?: Record<string, unknown>;
39
+ }
40
+ /**
41
+ * Push notification response when user taps a notification
42
+ */
43
+ interface PushResponse {
44
+ title: string;
45
+ body: string;
46
+ data?: Record<string, unknown>;
47
+ actionIdentifier: string;
48
+ }
49
+ /**
50
+ * Result from camera capture
51
+ */
52
+ interface CameraResult {
53
+ uri: string;
54
+ base64?: string;
55
+ width: number;
56
+ height: number;
57
+ }
58
+ /**
59
+ * Geographic position
60
+ */
61
+ interface Position {
62
+ latitude: number;
63
+ longitude: number;
64
+ altitude?: number;
65
+ accuracy?: number;
66
+ timestamp: number;
67
+ }
68
+ /**
69
+ * Options for native share sheet
70
+ */
71
+ interface ShareOptions {
72
+ title?: string;
73
+ message?: string;
74
+ url?: string;
75
+ }
76
+ /**
77
+ * Result from share action
78
+ */
79
+ interface ShareResult {
80
+ success: boolean;
81
+ action?: string;
82
+ }
83
+ /**
84
+ * Network connectivity status
85
+ */
86
+ interface NetworkStatus {
87
+ isConnected: boolean;
88
+ type: 'wifi' | 'cellular' | 'none' | 'unknown';
89
+ }
90
+ /**
91
+ * Device information
92
+ */
93
+ interface DeviceInfo {
94
+ platform: 'ios' | 'android';
95
+ osVersion: string;
96
+ appVersion: string;
97
+ deviceId: string;
98
+ deviceName: string;
99
+ isTablet: boolean;
100
+ }
101
+ /**
102
+ * Haptic feedback intensity levels
103
+ */
104
+ type HapticImpactStyle = 'light' | 'medium' | 'heavy';
105
+ /**
106
+ * Haptic notification types
107
+ */
108
+ type HapticNotificationType = 'success' | 'warning' | 'error';
109
+ /**
110
+ * Push notifications API
111
+ */
112
+ interface PushApi {
113
+ requestPermission(): Promise<PermissionStatus>;
114
+ getToken(): Promise<string | null>;
115
+ onMessage(callback: (message: PushMessage) => void): () => void;
116
+ onResponse(callback: (response: PushResponse) => void): () => void;
117
+ }
118
+ /**
119
+ * Biometric authentication API
120
+ */
121
+ interface BiometricsApi {
122
+ isAvailable(): Promise<boolean>;
123
+ authenticate(reason: string): Promise<boolean>;
124
+ }
125
+ /**
126
+ * Camera API
127
+ */
128
+ interface CameraApi {
129
+ requestPermission(): Promise<PermissionStatus>;
130
+ takePicture(): Promise<CameraResult>;
131
+ }
132
+ /**
133
+ * Location/GPS API
134
+ */
135
+ interface LocationApi {
136
+ requestPermission(): Promise<PermissionStatus>;
137
+ getCurrentPosition(): Promise<Position>;
138
+ }
139
+ /**
140
+ * Haptic feedback API
141
+ */
142
+ interface HapticsApi {
143
+ impact(style: HapticImpactStyle): void;
144
+ notification(type: HapticNotificationType): void;
145
+ }
146
+ /**
147
+ * Secure storage API
148
+ */
149
+ interface StorageApi {
150
+ get(key: string): Promise<string | null>;
151
+ set(key: string, value: string): Promise<void>;
152
+ delete(key: string): Promise<void>;
153
+ }
154
+ /**
155
+ * Native share sheet API
156
+ */
157
+ interface ShareApi {
158
+ open(options: ShareOptions): Promise<ShareResult>;
159
+ }
160
+ /**
161
+ * Network status API
162
+ */
163
+ interface NetworkApi {
164
+ getStatus(): Promise<NetworkStatus>;
165
+ onChange(callback: (status: NetworkStatus) => void): () => void;
166
+ }
167
+ /**
168
+ * Device info API
169
+ */
170
+ interface DeviceApi {
171
+ getInfo(): Promise<DeviceInfo>;
172
+ }
173
+ /**
174
+ * Main Appo SDK interface
175
+ */
176
+ interface Appo {
177
+ /** Whether running inside a native Appo app */
178
+ isNative: boolean;
179
+ /** SDK version */
180
+ version: string;
181
+ /** Push notifications */
182
+ push: PushApi;
183
+ /** Biometric authentication (Face ID / Touch ID) */
184
+ biometrics: BiometricsApi;
185
+ /** Camera access */
186
+ camera: CameraApi;
187
+ /** GPS/Geolocation */
188
+ location: LocationApi;
189
+ /** Haptic feedback */
190
+ haptics: HapticsApi;
191
+ /** Secure storage */
192
+ storage: StorageApi;
193
+ /** Native share sheet */
194
+ share: ShareApi;
195
+ /** Network connectivity */
196
+ network: NetworkApi;
197
+ /** Device information */
198
+ device: DeviceApi;
199
+ }
200
+ /**
201
+ * Internal response format from native
202
+ */
203
+ interface BridgeResponse {
204
+ id: string;
205
+ success: boolean;
206
+ data?: unknown;
207
+ error?: string;
208
+ }
209
+ /**
210
+ * Event broadcast from native layer
211
+ */
212
+ interface BridgeEvent {
213
+ event: string;
214
+ data: unknown;
215
+ }
216
+ /**
217
+ * Type guard for BridgeResponse envelope validation
218
+ */
219
+ declare function isBridgeResponse(data: unknown): data is BridgeResponse;
220
+ /**
221
+ * Type guard for BridgeEvent validation
222
+ */
223
+ declare function isBridgeEvent(data: unknown): data is BridgeEvent;
224
+ declare global {
225
+ interface Window {
226
+ appo?: Appo;
227
+ ReactNativeWebView?: {
228
+ postMessage(message: string): void;
229
+ };
230
+ }
231
+ }
232
+
233
+ declare const VERSION: string;
234
+
235
+ /**
236
+ * Registers a callback to observe bridge activity. Pass `null` to disable.
237
+ * The SDK produces no console output by default.
238
+ * @param fn - Logger callback receiving level, message, and optional data, or `null` to disable.
239
+ */
240
+ declare function setLogger(fn: AppoLogger | null): void;
241
+
242
+ /**
243
+ * @module @appolabs/sdk
244
+ *
245
+ * JavaScript bridge SDK for native app features in React Native WebViews.
246
+ * Provides a unified API surface with automatic browser fallbacks.
247
+ */
248
+
249
+ /**
250
+ * Initializes the Appo SDK and attaches it to `window.appo`.
251
+ * Returns the existing instance if already initialized.
252
+ * @returns The singleton Appo SDK instance.
253
+ * @throws {Error} If called outside a browser environment (no `window`).
254
+ */
255
+ declare function initAppo(): Appo;
256
+ /**
257
+ * Gets the Appo SDK instance, initializing it on first call.
258
+ * Subsequent calls return the same singleton instance.
259
+ * @returns The singleton Appo SDK instance.
260
+ */
261
+ declare function getAppo(): Appo;
262
+
263
+ export { type Appo, AppoError, AppoErrorCode, type AppoLogLevel, type AppoLogger, type BiometricsApi, type BridgeEvent, type BridgeResponse, type CameraApi, type CameraResult, type DeviceApi, type DeviceInfo, type HapticImpactStyle, type HapticNotificationType, type HapticsApi, type LocationApi, type NetworkApi, type NetworkStatus, type PermissionStatus, type Position, type PushApi, type PushMessage, type PushResponse, type ShareApi, type ShareOptions, type ShareResult, type StorageApi, VERSION, getAppo as default, getAppo, initAppo, isBridgeEvent, isBridgeResponse, setLogger };