@appboxo/web-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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +141 -0
  3. package/dist/constants.d.ts +60 -0
  4. package/dist/constants.d.ts.map +1 -0
  5. package/dist/constants.js +65 -0
  6. package/dist/constants.js.map +1 -0
  7. package/dist/handlers/customEventHandler.d.ts +16 -0
  8. package/dist/handlers/customEventHandler.d.ts.map +1 -0
  9. package/dist/handlers/customEventHandler.js +27 -0
  10. package/dist/handlers/customEventHandler.js.map +1 -0
  11. package/dist/handlers/initDataHandler.d.ts +16 -0
  12. package/dist/handlers/initDataHandler.d.ts.map +1 -0
  13. package/dist/handlers/initDataHandler.js +29 -0
  14. package/dist/handlers/initDataHandler.js.map +1 -0
  15. package/dist/handlers/loginHandler.d.ts +25 -0
  16. package/dist/handlers/loginHandler.d.ts.map +1 -0
  17. package/dist/handlers/loginHandler.js +50 -0
  18. package/dist/handlers/loginHandler.js.map +1 -0
  19. package/dist/handlers/paymentHandler.d.ts +15 -0
  20. package/dist/handlers/paymentHandler.d.ts.map +1 -0
  21. package/dist/handlers/paymentHandler.js +34 -0
  22. package/dist/handlers/paymentHandler.js.map +1 -0
  23. package/dist/index.d.ts +104 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +252 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/types.d.ts +138 -0
  28. package/dist/types.d.ts.map +1 -0
  29. package/dist/types.js +18 -0
  30. package/dist/types.js.map +1 -0
  31. package/dist/utils/authHelper.d.ts +30 -0
  32. package/dist/utils/authHelper.d.ts.map +1 -0
  33. package/dist/utils/authHelper.js +83 -0
  34. package/dist/utils/authHelper.js.map +1 -0
  35. package/dist/utils/index.d.ts +20 -0
  36. package/dist/utils/index.d.ts.map +1 -0
  37. package/dist/utils/index.js +20 -0
  38. package/dist/utils/index.js.map +1 -0
  39. package/dist/utils/messageHelpers.d.ts +34 -0
  40. package/dist/utils/messageHelpers.d.ts.map +1 -0
  41. package/dist/utils/messageHelpers.js +62 -0
  42. package/dist/utils/messageHelpers.js.map +1 -0
  43. package/dist/utils/networkService.d.ts +35 -0
  44. package/dist/utils/networkService.d.ts.map +1 -0
  45. package/dist/utils/networkService.js +106 -0
  46. package/dist/utils/networkService.js.map +1 -0
  47. package/dist/utils/paymentHelper.d.ts +13 -0
  48. package/dist/utils/paymentHelper.d.ts.map +1 -0
  49. package/dist/utils/paymentHelper.js +31 -0
  50. package/dist/utils/paymentHelper.js.map +1 -0
  51. package/dist/utils/validationHelpers.d.ts +33 -0
  52. package/dist/utils/validationHelpers.d.ts.map +1 -0
  53. package/dist/utils/validationHelpers.js +54 -0
  54. package/dist/utils/validationHelpers.js.map +1 -0
  55. package/package.json +50 -0
package/dist/index.js ADDED
@@ -0,0 +1,252 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Boxo pte. ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { DEFAULT_CONFIG, ALLOWED_ORIGINS, EVENT_TYPES } from './constants';
18
+ import { createErrorResponse } from './utils/messageHelpers';
19
+ import { isValidOrigin, isValidMiniappEvent } from './utils/validationHelpers';
20
+ import { handleLoginEvent } from './handlers/loginHandler';
21
+ import { handlePaymentEvent } from './handlers/paymentHandler';
22
+ import { handleInitDataEvent } from './handlers/initDataHandler';
23
+ import { handleCustomEvent } from './handlers/customEventHandler';
24
+ /**
25
+ * Appboxo Web SDK for Desktop
26
+ * Handles communication between Desktop App and miniapps
27
+ */
28
+ class AppboxoWebSDK {
29
+ constructor(config) {
30
+ this.iframeRef = null;
31
+ this.eventHandlers = new Map();
32
+ this.lifecycleHandlers = new Map();
33
+ this.requestResolvers = new Map();
34
+ this.baseUrl = '';
35
+ this.isInitialized = false;
36
+ this.authCode = null; // Explicitly set auth code
37
+ this.config = {
38
+ baseUrl: DEFAULT_CONFIG.baseUrl,
39
+ sandboxMode: DEFAULT_CONFIG.sandboxMode,
40
+ debug: DEFAULT_CONFIG.debug,
41
+ ...config
42
+ };
43
+ this.log('AppboxoWebSDK initialized', this.config);
44
+ }
45
+ /**
46
+ * Initialize the SDK and start listening for events
47
+ */
48
+ initialize() {
49
+ if (this.isInitialized) {
50
+ this.log('SDK already initialized');
51
+ return;
52
+ }
53
+ this.setupEventListeners();
54
+ this.isInitialized = true;
55
+ this.log('SDK initialized successfully');
56
+ }
57
+ /**
58
+ * Set the iframe reference for miniapp communication
59
+ */
60
+ setIframe(iframe) {
61
+ this.iframeRef = iframe;
62
+ this.log('Iframe reference set', iframe.src);
63
+ }
64
+ /**
65
+ * Mount miniapp to container (helper method)
66
+ * Creates iframe, sets reference, and initializes SDK
67
+ *
68
+ * @param config Configuration object with container, url, and optional styles
69
+ * @returns The created iframe element
70
+ */
71
+ mount(config) {
72
+ // Get container element
73
+ const container = typeof config.container === 'string'
74
+ ? document.getElementById(config.container) || document.querySelector(config.container)
75
+ : config.container;
76
+ if (!container) {
77
+ throw new Error('Container element not found');
78
+ }
79
+ // Create iframe
80
+ const iframe = document.createElement('iframe');
81
+ iframe.src = config.url;
82
+ iframe.className = config.className || '';
83
+ iframe.style.width = config.width || '100%';
84
+ iframe.style.height = config.height || '600px';
85
+ iframe.style.border = 'none';
86
+ iframe.setAttribute('title', 'Miniapp');
87
+ // Append to container
88
+ container.appendChild(iframe);
89
+ // Set reference and initialize
90
+ this.setIframe(iframe);
91
+ this.initialize();
92
+ this.log('Miniapp mounted successfully', { url: config.url });
93
+ return iframe;
94
+ }
95
+ /**
96
+ * Register custom event handler
97
+ */
98
+ onEvent(eventType, handler) {
99
+ this.eventHandlers.set(eventType, handler);
100
+ this.log(`Event handler registered for: ${eventType}`);
101
+ }
102
+ /**
103
+ * Remove event handler
104
+ */
105
+ offEvent(eventType) {
106
+ this.eventHandlers.delete(eventType);
107
+ this.log(`Event handler removed for: ${eventType}`);
108
+ }
109
+ /**
110
+ * Register callback for when login completes
111
+ */
112
+ onLoginComplete(callback) {
113
+ this.lifecycleHandlers.set('login-complete', callback);
114
+ }
115
+ /**
116
+ * Register callback for when payment completes
117
+ */
118
+ onPaymentComplete(callback) {
119
+ this.lifecycleHandlers.set('payment-complete', callback);
120
+ }
121
+ /**
122
+ * Set auth code explicitly (like React Native SDK pattern)
123
+ */
124
+ setAuthCode(authCode) {
125
+ this.authCode = authCode;
126
+ this.log('Auth code set explicitly', authCode);
127
+ }
128
+ /**
129
+ * Setup event listeners for miniapp communication
130
+ */
131
+ setupEventListeners() {
132
+ window.addEventListener('message', this.handleMiniappEvent.bind(this));
133
+ this.log('Event listeners setup complete');
134
+ }
135
+ /**
136
+ * Handle incoming events from miniapp
137
+ */
138
+ handleMiniappEvent(event) {
139
+ // Security check - only accept events from expected origin
140
+ const allOrigins = [
141
+ ...ALLOWED_ORIGINS.production,
142
+ ...ALLOWED_ORIGINS.development,
143
+ ];
144
+ if (!isValidOrigin(event.origin, allOrigins, this.config.debug)) {
145
+ this.log('Invalid origin, ignoring event', event.origin);
146
+ return;
147
+ }
148
+ // Validate event type
149
+ if (!isValidMiniappEvent(event)) {
150
+ return;
151
+ }
152
+ const data = event.data;
153
+ this.log('Received miniapp event', data);
154
+ const { handler, params, request_id } = data;
155
+ // Extract request_id from params if not in top-level
156
+ const requestId = request_id || params?.request_id;
157
+ switch (handler) {
158
+ case EVENT_TYPES.LOGIN:
159
+ handleLoginEvent(params, requestId, {
160
+ config: this.config,
161
+ authCode: this.authCode,
162
+ onGetAuthCode: this.config.onGetAuthCode,
163
+ lifecycleHandlers: this.lifecycleHandlers,
164
+ log: this.log.bind(this),
165
+ sendResponseToMiniapp: this.sendResponseToMiniapp.bind(this),
166
+ sendErrorResponse: this.sendErrorResponse.bind(this)
167
+ });
168
+ break;
169
+ case EVENT_TYPES.PAYMENT:
170
+ handlePaymentEvent(params, requestId, {
171
+ log: this.log.bind(this),
172
+ sendResponseToMiniapp: this.sendResponseToMiniapp.bind(this),
173
+ sendErrorResponse: this.sendErrorResponse.bind(this)
174
+ });
175
+ break;
176
+ case EVENT_TYPES.INIT_DATA:
177
+ handleInitDataEvent(params, requestId, {
178
+ config: this.config,
179
+ log: this.log.bind(this),
180
+ sendResponseToMiniapp: this.sendResponseToMiniapp.bind(this),
181
+ sendErrorResponse: this.sendErrorResponse.bind(this)
182
+ });
183
+ break;
184
+ case EVENT_TYPES.CUSTOM:
185
+ handleCustomEvent(params, requestId, {
186
+ eventHandlers: this.eventHandlers,
187
+ log: this.log.bind(this),
188
+ sendResponseToMiniapp: this.sendResponseToMiniapp.bind(this),
189
+ sendErrorResponse: this.sendErrorResponse.bind(this)
190
+ });
191
+ break;
192
+ default:
193
+ this.log(`Unhandled event: ${handler}`, params);
194
+ this.sendErrorResponse(handler, 'Unsupported event type', requestId);
195
+ }
196
+ }
197
+ /**
198
+ * Send response back to miniapp
199
+ */
200
+ sendResponseToMiniapp(response) {
201
+ if (!this.iframeRef?.contentWindow) {
202
+ this.log('No iframe reference, cannot send response', response);
203
+ return;
204
+ }
205
+ this.log('Iframe details:', {
206
+ src: this.iframeRef.src,
207
+ readyState: this.iframeRef.contentDocument?.readyState,
208
+ contentWindow: !!this.iframeRef.contentWindow
209
+ });
210
+ this.log('Posting message to iframe contentWindow with response:', JSON.stringify(response, null, 2));
211
+ this.iframeRef.contentWindow.postMessage(response, '*');
212
+ this.log('Response sent to miniapp', response);
213
+ // Also log to parent window to verify message is dispatched
214
+ console.log('[SDK Debug] postMessage dispatched to:', this.iframeRef.src);
215
+ }
216
+ /**
217
+ * Send error response to miniapp
218
+ */
219
+ sendErrorResponse(eventType, error, requestId) {
220
+ const errorResponse = createErrorResponse(eventType, error, requestId);
221
+ this.sendResponseToMiniapp(errorResponse);
222
+ }
223
+ /**
224
+ * Logging utility
225
+ */
226
+ log(message, data) {
227
+ if (this.config.debug) {
228
+ console.log(`[AppboxoWebSDK] ${message}`, data);
229
+ }
230
+ }
231
+ /**
232
+ * Cleanup resources
233
+ */
234
+ destroy() {
235
+ window.removeEventListener('message', this.handleMiniappEvent.bind(this));
236
+ this.eventHandlers.clear();
237
+ this.lifecycleHandlers.clear();
238
+ this.requestResolvers.clear();
239
+ this.iframeRef = null;
240
+ this.isInitialized = false;
241
+ this.log('SDK destroyed');
242
+ }
243
+ }
244
+ // Named export (preferred)
245
+ export { AppboxoWebSDK };
246
+ // Default export (for backward compatibility)
247
+ export default AppboxoWebSDK;
248
+ // Re-export utilities
249
+ export * from './utils';
250
+ // Re-export constants
251
+ export * from './constants';
252
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAe,MAAM,aAAa,CAAC;AACxF,OAAO,EAAsB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAmBlE;;;GAGG;AACH,MAAM,aAAa;IAUjB,YAAY,MAAiB;QARrB,cAAS,GAA6B,IAAI,CAAC;QAC3C,kBAAa,GAAoC,IAAI,GAA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ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export interface RequestIdProp {
18
+ request_id?: number | string;
19
+ }
20
+ export interface ErrorDataClientError {
21
+ error_code: number;
22
+ error_reason: string;
23
+ error_description?: string;
24
+ }
25
+ export interface ErrorDataAPIError {
26
+ error_code: number;
27
+ error_msg: string;
28
+ request_params: string[];
29
+ }
30
+ export interface ErrorDataAuthError {
31
+ error_code: number;
32
+ error_reason: string;
33
+ error_description?: string[];
34
+ }
35
+ export type ErrorData = {
36
+ error_type: "client_error";
37
+ error_data: ErrorDataClientError;
38
+ request_id?: number | string;
39
+ } | {
40
+ error_type: "api_error";
41
+ error_data: ErrorDataAPIError;
42
+ request_id?: number | string;
43
+ } | {
44
+ error_type: "auth_error";
45
+ error_data: ErrorDataAuthError;
46
+ request_id?: number | string;
47
+ };
48
+ export interface LoginRequest {
49
+ confirmModalText: string;
50
+ }
51
+ export interface PaymentRequest {
52
+ amount: number;
53
+ miniappOrderId: string;
54
+ transactionToken: string;
55
+ currency: string;
56
+ extraParams?: any;
57
+ }
58
+ export interface InitDataRequest {
59
+ app_id: string;
60
+ client_id: string;
61
+ payload: string;
62
+ data?: {
63
+ [key: string]: any;
64
+ };
65
+ }
66
+ export interface LoginResponse {
67
+ token: string;
68
+ refresh_token?: string;
69
+ }
70
+ export interface PaymentResponse {
71
+ status: 'success' | 'failed' | 'cancelled';
72
+ hostappOrderId?: string;
73
+ transactionToken: string;
74
+ error?: string;
75
+ }
76
+ export interface InitDataResponse {
77
+ app_id: string;
78
+ client_id: string;
79
+ payload: string;
80
+ data: {
81
+ [key: string]: any;
82
+ };
83
+ token?: string;
84
+ refresh_token?: string;
85
+ sandbox_mode?: boolean;
86
+ }
87
+ export interface MiniappEvent {
88
+ handler: string;
89
+ params: any;
90
+ type: 'appboxo-js-sdk';
91
+ sdkVersion: string;
92
+ request_id?: number | string;
93
+ }
94
+ export interface HostAppResponse {
95
+ type: 'appboxo-host-response';
96
+ handler: string;
97
+ data: any;
98
+ request_id?: number | string;
99
+ }
100
+ export interface SDKConfig {
101
+ clientId: string;
102
+ appId: string;
103
+ userId?: string;
104
+ baseUrl?: string;
105
+ sandboxMode?: boolean;
106
+ debug?: boolean;
107
+ /**
108
+ * Callback to get auth_code from Desktop App backend
109
+ * This should connect to Desktop App's backend to get the auth_code for current user session
110
+ */
111
+ onGetAuthCode?: () => Promise<string>;
112
+ }
113
+ export type LoginEventHandler = (params: LoginRequest) => Promise<LoginResponse>;
114
+ export type PaymentEventHandler = (params: PaymentRequest) => Promise<PaymentResponse>;
115
+ export type InitDataEventHandler = (params: InitDataRequest) => Promise<InitDataResponse>;
116
+ export type CustomEventHandler = (type: string, payload: any) => Promise<any>;
117
+ export type LifecycleEventHandler = (success: boolean, data?: any) => void;
118
+ export interface PromiseController {
119
+ resolve: (value: any) => void;
120
+ reject: (reason: any) => void;
121
+ }
122
+ export interface FinomLoginCredentials {
123
+ username: string;
124
+ password: string;
125
+ payload: string;
126
+ }
127
+ export interface FinomAuthTokens {
128
+ access_token: string;
129
+ refresh_token: string;
130
+ expires_in: number;
131
+ }
132
+ export interface FinomPaymentResult {
133
+ orderId: string;
134
+ status: 'success' | 'failed';
135
+ transactionId?: string;
136
+ error?: string;
137
+ }
138
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,MAAM,GA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
+ * Copyright 2025 Boxo pte. ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Authentication Helper
3
+ * Handles auth code generation and token exchange
4
+ */
5
+ import type { SDKConfig } from '../types';
6
+ export interface AuthTokens {
7
+ token: string;
8
+ refresh_token?: string;
9
+ }
10
+ export interface AuthHelperConfig {
11
+ config: SDKConfig;
12
+ authCode: string | null;
13
+ onGetAuthCode?: () => Promise<string>;
14
+ log: (message: string, data?: any) => void;
15
+ }
16
+ /**
17
+ * Generate auth code from Desktop App session
18
+ *
19
+ * Priority order:
20
+ * 1. Explicitly set auth code
21
+ * 2. Callback to get from backend
22
+ * 3. Mock auth code (fallback for testing)
23
+ */
24
+ export declare function generateAuthCode(config: AuthHelperConfig): Promise<string>;
25
+ /**
26
+ * Exchange authorization code for authentication tokens
27
+ * Implements OAuth 2.0 authorization code flow
28
+ */
29
+ export declare function exchangeAuthCodeForTokens(authCode: string, config: AuthHelperConfig): Promise<AuthTokens>;
30
+ //# sourceMappingURL=authHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authHelper.d.ts","sourceRoot":"","sources":["../../src/utils/authHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,UAAU,CAAC;AAGxD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAuBhF;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,UAAU,CAAC,CAiDrB"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Authentication Helper
3
+ * Handles auth code generation and token exchange
4
+ */
5
+ import { NetworkService } from './networkService';
6
+ /**
7
+ * Generate auth code from Desktop App session
8
+ *
9
+ * Priority order:
10
+ * 1. Explicitly set auth code
11
+ * 2. Callback to get from backend
12
+ * 3. Mock auth code (fallback for testing)
13
+ */
14
+ export async function generateAuthCode(config) {
15
+ // Priority 1: Explicitly set auth code
16
+ if (config.authCode) {
17
+ config.log('Using explicitly set auth_code', config.authCode);
18
+ return config.authCode;
19
+ }
20
+ // Priority 2: Callback to get auth_code from Desktop App backend
21
+ if (config.onGetAuthCode) {
22
+ try {
23
+ const authCode = await config.onGetAuthCode();
24
+ config.log('Received auth_code from Desktop App backend', authCode);
25
+ return authCode;
26
+ }
27
+ catch (error) {
28
+ config.log('Failed to get auth_code from backend', error);
29
+ throw error;
30
+ }
31
+ }
32
+ // Priority 3: Fallback to generated mock auth code for testing
33
+ const authCode = `mock_auth_code_${Date.now()}_${Math.random().toString(36).substring(7)}`;
34
+ config.log('Generated mock auth code (fallback for testing)', authCode);
35
+ return authCode;
36
+ }
37
+ /**
38
+ * Exchange authorization code for authentication tokens
39
+ * Implements OAuth 2.0 authorization code flow
40
+ */
41
+ export async function exchangeAuthCodeForTokens(authCode, config) {
42
+ try {
43
+ config.log('Exchanging auth_code for tokens', authCode);
44
+ // Create network service instance
45
+ const networkService = new NetworkService({
46
+ baseUrl: config.config.baseUrl || 'https://dashboard.appboxo.com/api/v1',
47
+ log: config.log
48
+ });
49
+ // Call Boxo Platform API to exchange auth_code for auth_token
50
+ const requestPayload = {
51
+ auth_code: authCode,
52
+ client_id: config.config.clientId,
53
+ app_id: config.config.appId
54
+ };
55
+ // Add user_reference if provided (matches Android SDK behavior)
56
+ if (config.config.userId) {
57
+ requestPayload.user_reference = config.config.userId;
58
+ }
59
+ const response = await networkService.post('/authorize/', requestPayload);
60
+ if (!networkService.isSuccess(response)) {
61
+ config.log('Boxo Platform request failed', {
62
+ status: response.status,
63
+ data: response.data
64
+ });
65
+ throw new Error('Authentication failed');
66
+ }
67
+ const data = response.data;
68
+ config.log('Boxo Platform response', data);
69
+ return {
70
+ token: data.auth_token || data.token,
71
+ refresh_token: data.refresh_token
72
+ };
73
+ }
74
+ catch (error) {
75
+ config.log('Failed to exchange auth code for tokens', error);
76
+ // If the error is due to invalid JSON (HTML response), log it separately
77
+ if (error instanceof SyntaxError) {
78
+ config.log('Boxo Platform API endpoint may not be configured yet. Response is HTML instead of JSON.');
79
+ }
80
+ throw new Error('Authentication failed');
81
+ }
82
+ }
83
+ //# sourceMappingURL=authHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authHelper.js","sourceRoot":"","sources":["../../src/utils/authHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAclD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAwB;IAC7D,uCAAuC;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.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from './messageHelpers';
18
+ export * from './validationHelpers';
19
+ export * from './networkService';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Boxo pte. ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from './messageHelpers';
18
+ export * from './validationHelpers';
19
+ export * from './networkService';
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Boxo pte. ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { MiniappEvent, HostAppResponse } from '../types';
18
+ /**
19
+ * Create a message to send to miniapp
20
+ */
21
+ export declare function createMiniappMessage(handler: string, params: any, requestId?: string | number): MiniappEvent;
22
+ /**
23
+ * Create a response to send back to miniapp
24
+ *
25
+ * Note: js-sdk expects the response in a specific format:
26
+ * - For login: data should contain { token, refresh_token } (not wrapped in payload)
27
+ * - request_id should be inside the data field
28
+ */
29
+ export declare function createHostResponse(handler: string, data: any, requestId?: string | number): HostAppResponse;
30
+ /**
31
+ * Create error response
32
+ */
33
+ export declare function createErrorResponse(handler: string, error: any, requestId?: string | number): HostAppResponse;
34
+ //# sourceMappingURL=messageHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/messageHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,GAAG,EACX,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAC1B,YAAY,CAQd;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,GAAG,EACT,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAC1B,eAAe,CAUjB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,GAAG,EACV,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAC1B,eAAe,CAcjB"}