@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
@@ -0,0 +1,62 @@
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 { SDK_MESSAGE_TYPE, SDK_VERSION } from '../constants';
18
+ /**
19
+ * Create a message to send to miniapp
20
+ */
21
+ export function createMiniappMessage(handler, params, requestId) {
22
+ return {
23
+ type: SDK_MESSAGE_TYPE,
24
+ handler,
25
+ params,
26
+ sdkVersion: SDK_VERSION,
27
+ request_id: requestId,
28
+ };
29
+ }
30
+ /**
31
+ * Create a response to send back to miniapp
32
+ *
33
+ * Note: js-sdk expects the response in a specific format:
34
+ * - For login: data should contain { token, refresh_token } (not wrapped in payload)
35
+ * - request_id should be inside the data field
36
+ */
37
+ export function createHostResponse(handler, data, requestId) {
38
+ return {
39
+ type: 'appboxo-host-response',
40
+ handler,
41
+ data: {
42
+ ...data,
43
+ request_id: requestId,
44
+ },
45
+ request_id: requestId,
46
+ };
47
+ }
48
+ /**
49
+ * Create error response
50
+ */
51
+ export function createErrorResponse(handler, error, requestId) {
52
+ return createHostResponse(handler, {
53
+ error_type: 'client_error',
54
+ error_data: {
55
+ error_code: 500,
56
+ error_reason: error?.message || 'Unknown error',
57
+ error_description: error?.toString(),
58
+ },
59
+ request_id: requestId,
60
+ }, requestId);
61
+ }
62
+ //# sourceMappingURL=messageHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messageHelpers.js","sourceRoot":"","sources":["../../src/utils/messageHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG7D;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,MAAW,EACX,SAA2B;IAE3B,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,OAAO;QACP,MAAM;QACN,UAAU,EAAE,WAAW;QACvB,UAAU,EAAE,SAAS;KACtB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAe,EACf,IAAS,EACT,SAA2B;IAE3B,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,OAAO;QACP,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,UAAU,EAAE,SAAS;SACtB;QACD,UAAU,EAAE,SAAS;KACtB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAAe,EACf,KAAU,EACV,SAA2B;IAE3B,OAAO,kBAAkB,CACvB,OAAO,EACP;QACE,UAAU,EAAE,cAAc;QAC1B,UAAU,EAAE;YACV,UAAU,EAAE,GAAG;YACf,YAAY,EAAE,KAAK,EAAE,OAAO,IAAI,eAAe;YAC/C,iBAAiB,EAAE,KAAK,EAAE,QAAQ,EAAE;SACrC;QACD,UAAU,EAAE,SAAS;KACtB,EACD,SAAS,CACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Network Service
3
+ * Provides unified API communication layer
4
+ */
5
+ export interface NetworkServiceConfig {
6
+ baseUrl: string;
7
+ log?: (message: string, data?: any) => void;
8
+ timeout?: number;
9
+ }
10
+ export interface ApiResponse<T = any> {
11
+ data: T;
12
+ status: number;
13
+ ok: boolean;
14
+ }
15
+ export declare class NetworkService {
16
+ private config;
17
+ constructor(config: NetworkServiceConfig);
18
+ /**
19
+ * Make a POST request to the Boxo Platform API
20
+ */
21
+ post<T = any>(endpoint: string, data: Record<string, any>, options?: RequestInit): Promise<ApiResponse<T>>;
22
+ /**
23
+ * Make a GET request to the Boxo Platform API
24
+ */
25
+ get<T = any>(endpoint: string, params?: Record<string, string>, options?: RequestInit): Promise<ApiResponse<T>>;
26
+ /**
27
+ * Parse response body
28
+ */
29
+ private parseResponse;
30
+ /**
31
+ * Check if response is successful
32
+ */
33
+ isSuccess(response: ApiResponse): boolean;
34
+ }
35
+ //# sourceMappingURL=networkService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networkService.d.ts","sourceRoot":"","sources":["../../src/utils/networkService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;CACb;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAuB;gBAEzB,MAAM,EAAE,oBAAoB;IAIxC;;OAEG;IACG,IAAI,CAAC,CAAC,GAAG,GAAG,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAmC1B;;OAEG;IACG,GAAG,CAAC,CAAC,GAAG,GAAG,EACf,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAoC1B;;OAEG;YACW,aAAa;IAwB3B;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO;CAG1C"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Network Service
3
+ * Provides unified API communication layer
4
+ */
5
+ export class NetworkService {
6
+ constructor(config) {
7
+ this.config = config;
8
+ }
9
+ /**
10
+ * Make a POST request to the Boxo Platform API
11
+ */
12
+ async post(endpoint, data, options) {
13
+ const url = `${this.config.baseUrl}${endpoint}`;
14
+ this.config.log?.('Making API request', { url, endpoint, data });
15
+ try {
16
+ const response = await fetch(url, {
17
+ method: 'POST',
18
+ headers: {
19
+ 'Content-Type': 'application/json',
20
+ ...options?.headers,
21
+ },
22
+ body: JSON.stringify(data),
23
+ ...options,
24
+ });
25
+ const responseData = await this.parseResponse(response);
26
+ this.config.log?.('API response received', {
27
+ endpoint,
28
+ status: response.status,
29
+ ok: response.ok
30
+ });
31
+ return {
32
+ data: responseData,
33
+ status: response.status,
34
+ ok: response.ok,
35
+ };
36
+ }
37
+ catch (error) {
38
+ this.config.log?.('API request failed', { endpoint, error });
39
+ throw error;
40
+ }
41
+ }
42
+ /**
43
+ * Make a GET request to the Boxo Platform API
44
+ */
45
+ async get(endpoint, params, options) {
46
+ const url = params
47
+ ? `${this.config.baseUrl}${endpoint}?${new URLSearchParams(params).toString()}`
48
+ : `${this.config.baseUrl}${endpoint}`;
49
+ this.config.log?.('Making API request', { url, endpoint, params });
50
+ try {
51
+ const response = await fetch(url, {
52
+ method: 'GET',
53
+ headers: {
54
+ 'Content-Type': 'application/json',
55
+ ...options?.headers,
56
+ },
57
+ ...options,
58
+ });
59
+ const responseData = await this.parseResponse(response);
60
+ this.config.log?.('API response received', {
61
+ endpoint,
62
+ status: response.status,
63
+ ok: response.ok
64
+ });
65
+ return {
66
+ data: responseData,
67
+ status: response.status,
68
+ ok: response.ok,
69
+ };
70
+ }
71
+ catch (error) {
72
+ this.config.log?.('API request failed', { endpoint, error });
73
+ throw error;
74
+ }
75
+ }
76
+ /**
77
+ * Parse response body
78
+ */
79
+ async parseResponse(response) {
80
+ const contentType = response.headers.get('content-type');
81
+ // Handle non-JSON responses (e.g., HTML error pages)
82
+ if (!contentType || !contentType.includes('application/json')) {
83
+ const text = await response.text();
84
+ this.config.log?.('Non-JSON response received', { contentType, text });
85
+ if (!response.ok) {
86
+ throw new Error(`API request failed: ${response.status} ${response.statusText}`);
87
+ }
88
+ // Return empty object if successful but not JSON
89
+ return {};
90
+ }
91
+ try {
92
+ return await response.json();
93
+ }
94
+ catch (error) {
95
+ this.config.log?.('Failed to parse JSON response', { error });
96
+ throw new Error('Invalid JSON response from server');
97
+ }
98
+ }
99
+ /**
100
+ * Check if response is successful
101
+ */
102
+ isSuccess(response) {
103
+ return response.ok && response.status >= 200 && response.status < 300;
104
+ }
105
+ }
106
+ //# sourceMappingURL=networkService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"networkService.js","sourceRoot":"","sources":["../../src/utils/networkService.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,MAAM,OAAO,cAAc;IAGzB,YAAY,MAA4B;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;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D,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,4BAA4B,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YAEvE,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YACnF,CAAC;YAED,iDAAiD;YACjD,OAAO,EAAO,CAAC;QACjB,CAAC;QAED,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,QAAqB;QAC7B,OAAO,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC;IACxE,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Payment Helper
3
+ * Handles payment processing through Finom
4
+ */
5
+ import type { PaymentRequest, FinomPaymentResult } from '../types';
6
+ export interface PaymentHelperConfig {
7
+ log: (message: string, data?: any) => void;
8
+ }
9
+ /**
10
+ * Process payment through Finom
11
+ */
12
+ export declare function processFinomPayment(params: PaymentRequest, config: PaymentHelperConfig): Promise<FinomPaymentResult>;
13
+ //# sourceMappingURL=paymentHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentHelper.d.ts","sourceRoot":"","sources":["../../src/utils/paymentHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnE,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CAC5C;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAuB7B"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Payment Helper
3
+ * Handles payment processing through Finom
4
+ */
5
+ /**
6
+ * Process payment through Finom
7
+ */
8
+ export async function processFinomPayment(params, config) {
9
+ try {
10
+ // This should integrate with Finom's payment system
11
+ // For now, simulate payment processing
12
+ config.log('Processing Finom payment', params);
13
+ // Simulate payment processing delay
14
+ await new Promise(resolve => setTimeout(resolve, 2000));
15
+ // Mock successful payment
16
+ return {
17
+ orderId: `finom_${Date.now()}`,
18
+ status: 'success',
19
+ transactionId: `txn_${Date.now()}`
20
+ };
21
+ }
22
+ catch (error) {
23
+ config.log('Payment processing failed', error);
24
+ return {
25
+ orderId: `finom_${Date.now()}`,
26
+ status: 'failed',
27
+ error: error?.message || 'Payment failed'
28
+ };
29
+ }
30
+ }
31
+ //# sourceMappingURL=paymentHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paymentHelper.js","sourceRoot":"","sources":["../../src/utils/paymentHelper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAsB,EACtB,MAA2B;IAE3B,IAAI,CAAC;QACH,oDAAoD;QACpD,uCAAuC;QACvC,MAAM,CAAC,GAAG,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAAC;QAE/C,oCAAoC;QACpC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QAExD,0BAA0B;QAC1B,OAAO;YACL,OAAO,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,EAAE;YAC9B,MAAM,EAAE,SAAS;YACjB,aAAa,EAAE,OAAO,IAAI,CAAC,GAAG,EAAE,EAAE;SACnC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,GAAG,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO;YACL,OAAO,EAAE,SAAS,IAAI,CAAC,GAAG,EAAE,EAAE;YAC9B,MAAM,EAAE,QAAQ;YAChB,KAAK,EAAG,KAAe,EAAE,OAAO,IAAI,gBAAgB;SACrD,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,33 @@
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
+ /**
18
+ * Validate origin for security
19
+ */
20
+ export declare function isValidOrigin(origin: string, allowedOrigins: readonly string[], debug?: boolean): boolean;
21
+ /**
22
+ * Validate if event is from miniapp
23
+ */
24
+ export declare function isValidMiniappEvent(event: MessageEvent): boolean;
25
+ /**
26
+ * Assert that a value is not null/undefined
27
+ */
28
+ export declare function assert(condition: any, message: string): asserts condition;
29
+ /**
30
+ * Safe JSON parse with error handling
31
+ */
32
+ export declare function safeJsonParse<T>(json: string, fallback: T): T;
33
+ //# sourceMappingURL=validationHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/validationHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,SAAS,MAAM,EAAE,EACjC,KAAK,GAAE,OAAe,GACrB,OAAO,CAQT;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAGhE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAIzE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAM7D"}
@@ -0,0 +1,54 @@
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
+ /**
18
+ * Validate origin for security
19
+ */
20
+ export function isValidOrigin(origin, allowedOrigins, debug = false) {
21
+ // In debug mode, allow all origins
22
+ if (debug) {
23
+ return true;
24
+ }
25
+ // Check if origin is in allowed list
26
+ return allowedOrigins.includes(origin);
27
+ }
28
+ /**
29
+ * Validate if event is from miniapp
30
+ */
31
+ export function isValidMiniappEvent(event) {
32
+ const data = event.data;
33
+ return data?.type === 'appboxo-js-sdk';
34
+ }
35
+ /**
36
+ * Assert that a value is not null/undefined
37
+ */
38
+ export function assert(condition, message) {
39
+ if (!condition) {
40
+ throw new Error(`Assertion failed: ${message}`);
41
+ }
42
+ }
43
+ /**
44
+ * Safe JSON parse with error handling
45
+ */
46
+ export function safeJsonParse(json, fallback) {
47
+ try {
48
+ return JSON.parse(json);
49
+ }
50
+ catch {
51
+ return fallback;
52
+ }
53
+ }
54
+ //# sourceMappingURL=validationHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationHelpers.js","sourceRoot":"","sources":["../../src/utils/validationHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAc,EACd,cAAiC,EACjC,QAAiB,KAAK;IAEtB,mCAAmC;IACnC,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qCAAqC;IACrC,OAAO,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAmB;IACrD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAoB,CAAC;IACxC,OAAO,IAAI,EAAE,IAAI,KAAK,gBAAgB,CAAC;AACzC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,SAAc,EAAE,OAAe;IACpD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAI,IAAY,EAAE,QAAW;IACxD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@appboxo/web-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Boxo Desktop Host App SDK for handling miniapp events",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "dev": "tsc --watch",
10
+ "test": "jest",
11
+ "lint": "eslint src/**/*.ts",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "keywords": [
15
+ "boxo",
16
+ "appboxo",
17
+ "desktop",
18
+ "host-app",
19
+ "sdk",
20
+ "miniapp"
21
+ ],
22
+ "author": "Boxo Team",
23
+ "license": "MIT",
24
+ "devDependencies": {
25
+ "@types/jest": "^29.5.0",
26
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
27
+ "@typescript-eslint/parser": "^6.0.0",
28
+ "eslint": "^8.0.0",
29
+ "jest": "^29.5.0",
30
+ "jest-environment-jsdom": "^30.2.0",
31
+ "ts-jest": "^29.1.0",
32
+ "typescript": "^5.0.0"
33
+ },
34
+ "dependencies": {
35
+ "axios": "^1.6.0"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "!dist/__tests__/**",
40
+ "!dist/setupTests.*",
41
+ "!dist/**/*.test.*",
42
+ "README.md",
43
+ "LICENSE"
44
+ ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/memoriaXII/b-sdk.git"
48
+ },
49
+ "homepage": "https://github.com/memoriaXII/b-sdk#readme"
50
+ }