From f0cc289e6520f917e0e70902f55edd0990543f1b Mon Sep 17 00:00:00 2001 From: Mark Murray <2034704+markmur@users.noreply.github.com> Date: Fri, 1 Nov 2024 12:38:49 +0000 Subject: [PATCH] [3.1.1] Log invalid data when JSON parse fails (#136) Log invalid data when JSON parse fails --- CHANGELOG.md | 4 ++++ modules/@shopify/checkout-sheet-kit/package.json | 2 +- modules/@shopify/checkout-sheet-kit/src/index.ts | 11 +++++++---- .../checkout-sheet-kit/tests/index.test.ts | 16 ++++++++++++---- sample/ios/Podfile.lock | 6 +++++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c897e9..9540708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 3.1.1 - November 1, 2024 + +- Logs invalid JSON for lifecycle events + ## 3.1.0 - October 25, 2024 Upgrades Swift dependency to diff --git a/modules/@shopify/checkout-sheet-kit/package.json b/modules/@shopify/checkout-sheet-kit/package.json index ceae859..4362c29 100644 --- a/modules/@shopify/checkout-sheet-kit/package.json +++ b/modules/@shopify/checkout-sheet-kit/package.json @@ -1,7 +1,7 @@ { "name": "@shopify/checkout-sheet-kit", "license": "MIT", - "version": "3.1.0", + "version": "3.1.1", "main": "lib/commonjs/index.js", "types": "src/index.ts", "source": "src/index.ts", diff --git a/modules/@shopify/checkout-sheet-kit/src/index.ts b/modules/@shopify/checkout-sheet-kit/src/index.ts index 0416d05..82fee18 100644 --- a/modules/@shopify/checkout-sheet-kit/src/index.ts +++ b/modules/@shopify/checkout-sheet-kit/src/index.ts @@ -100,15 +100,17 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit { switch (event) { case 'pixel': eventCallback = this.interceptEventEmission( + 'pixel', callback, this.parseCustomPixelData, ); break; case 'completed': - eventCallback = this.interceptEventEmission(callback); + eventCallback = this.interceptEventEmission('completed', callback); break; case 'error': eventCallback = this.interceptEventEmission( + 'error', callback, this.parseCheckoutError, ); @@ -169,6 +171,7 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit { * Event data can be sent back as either a parsed Event object or a JSON string. */ private interceptEventEmission( + event: CheckoutEvent, callback: CheckoutEventCallback, transformData?: (data: any) => any, ): (eventData: string | typeof callback) => void { @@ -181,20 +184,20 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit { callback(parsed); } catch (error) { const parseError = new LifecycleEventParseError( - 'Failed to parse event data: Invalid JSON', + `Failed to parse "${event}" event data: Invalid JSON`, { cause: 'Invalid JSON', }, ); // eslint-disable-next-line no-console - console.error(parseError); + console.error(parseError, eventData); } } else if (eventData && typeof eventData === 'object') { callback(transformData?.(eventData) ?? eventData); } } catch (error) { const parseError = new LifecycleEventParseError( - 'Failed to parse event data', + `Failed to parse "${event}" event data`, { cause: 'Unknown', }, diff --git a/modules/@shopify/checkout-sheet-kit/tests/index.test.ts b/modules/@shopify/checkout-sheet-kit/tests/index.test.ts index f1b8b26..72b8f7d 100644 --- a/modules/@shopify/checkout-sheet-kit/tests/index.test.ts +++ b/modules/@shopify/checkout-sheet-kit/tests/index.test.ts @@ -265,8 +265,12 @@ describe('ShopifyCheckoutSheetKit', () => { 'pixel', expect.any(Function), ); - eventEmitter.emit('pixel', '{"someAttribute": 123'); - expect(mock).toHaveBeenCalledWith(expect.any(LifecycleEventParseError)); + const invalidData = '{"someAttribute": 123'; + eventEmitter.emit('pixel', invalidData); + expect(mock).toHaveBeenCalledWith( + expect.any(LifecycleEventParseError), + invalidData, + ); }); }); @@ -322,8 +326,12 @@ describe('ShopifyCheckoutSheetKit', () => { 'completed', expect.any(Function), ); - eventEmitter.emit('completed', 'INVALID JSON'); - expect(mock).toHaveBeenCalledWith(expect.any(LifecycleEventParseError)); + const invalidData = 'INVALID JSON'; + eventEmitter.emit('completed', invalidData); + expect(mock).toHaveBeenCalledWith( + expect.any(LifecycleEventParseError), + invalidData, + ); }); }); diff --git a/sample/ios/Podfile.lock b/sample/ios/Podfile.lock index 07ff12e..8661503 100644 --- a/sample/ios/Podfile.lock +++ b/sample/ios/Podfile.lock @@ -1261,6 +1261,7 @@ PODS: - Yoga - ShopifyCheckoutSheetKit (3.1.1) - SocketRocket (0.7.0) + - SwiftLint (0.57.0) - Yoga (0.0.0) DEPENDENCIES: @@ -1327,12 +1328,14 @@ DEPENDENCIES: - RNScreens (from `../node_modules/react-native-screens`) - "RNShopifyCheckoutSheetKit (from `../../modules/@shopify/checkout-sheet-kit`)" - RNVectorIcons (from `../node_modules/react-native-vector-icons`) + - SwiftLint - Yoga (from `../../node_modules/react-native/ReactCommon/yoga`) SPEC REPOS: trunk: - ShopifyCheckoutSheetKit - SocketRocket + - SwiftLint EXTERNAL SOURCES: boost: @@ -1525,8 +1528,9 @@ SPEC CHECKSUMS: RNVectorIcons: 50ea777efffdd991a22e968aa312d75da7ff46c3 ShopifyCheckoutSheetKit: fe309799b18b8d554f28c3f075d6d57d4811c9ab SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d + SwiftLint: eb47480d47c982481592c195c221d11013a679cc Yoga: 348f8b538c3ed4423eb58a8e5730feec50bce372 -PODFILE CHECKSUM: 4a9ceecdcfb54884b51163a7e4438cd49c73c8d9 +PODFILE CHECKSUM: 9efd19a381198fb46f36acf3d269233039fb9dc5 COCOAPODS: 1.15.2