Skip to content

Commit f0cc289

Browse files
authored
[3.1.1] Log invalid data when JSON parse fails (#136)
Log invalid data when JSON parse fails
1 parent cbafef7 commit f0cc289

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 3.1.1 - November 1, 2024
4+
5+
- Logs invalid JSON for lifecycle events
6+
37
## 3.1.0 - October 25, 2024
48

59
Upgrades Swift dependency to

modules/@shopify/checkout-sheet-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@shopify/checkout-sheet-kit",
33
"license": "MIT",
4-
"version": "3.1.0",
4+
"version": "3.1.1",
55
"main": "lib/commonjs/index.js",
66
"types": "src/index.ts",
77
"source": "src/index.ts",

modules/@shopify/checkout-sheet-kit/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
100100
switch (event) {
101101
case 'pixel':
102102
eventCallback = this.interceptEventEmission(
103+
'pixel',
103104
callback,
104105
this.parseCustomPixelData,
105106
);
106107
break;
107108
case 'completed':
108-
eventCallback = this.interceptEventEmission(callback);
109+
eventCallback = this.interceptEventEmission('completed', callback);
109110
break;
110111
case 'error':
111112
eventCallback = this.interceptEventEmission(
113+
'error',
112114
callback,
113115
this.parseCheckoutError,
114116
);
@@ -169,6 +171,7 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
169171
* Event data can be sent back as either a parsed Event object or a JSON string.
170172
*/
171173
private interceptEventEmission(
174+
event: CheckoutEvent,
172175
callback: CheckoutEventCallback,
173176
transformData?: (data: any) => any,
174177
): (eventData: string | typeof callback) => void {
@@ -181,20 +184,20 @@ class ShopifyCheckoutSheet implements ShopifyCheckoutSheetKit {
181184
callback(parsed);
182185
} catch (error) {
183186
const parseError = new LifecycleEventParseError(
184-
'Failed to parse event data: Invalid JSON',
187+
`Failed to parse "${event}" event data: Invalid JSON`,
185188
{
186189
cause: 'Invalid JSON',
187190
},
188191
);
189192
// eslint-disable-next-line no-console
190-
console.error(parseError);
193+
console.error(parseError, eventData);
191194
}
192195
} else if (eventData && typeof eventData === 'object') {
193196
callback(transformData?.(eventData) ?? eventData);
194197
}
195198
} catch (error) {
196199
const parseError = new LifecycleEventParseError(
197-
'Failed to parse event data',
200+
`Failed to parse "${event}" event data`,
198201
{
199202
cause: 'Unknown',
200203
},

modules/@shopify/checkout-sheet-kit/tests/index.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,12 @@ describe('ShopifyCheckoutSheetKit', () => {
265265
'pixel',
266266
expect.any(Function),
267267
);
268-
eventEmitter.emit('pixel', '{"someAttribute": 123');
269-
expect(mock).toHaveBeenCalledWith(expect.any(LifecycleEventParseError));
268+
const invalidData = '{"someAttribute": 123';
269+
eventEmitter.emit('pixel', invalidData);
270+
expect(mock).toHaveBeenCalledWith(
271+
expect.any(LifecycleEventParseError),
272+
invalidData,
273+
);
270274
});
271275
});
272276

@@ -322,8 +326,12 @@ describe('ShopifyCheckoutSheetKit', () => {
322326
'completed',
323327
expect.any(Function),
324328
);
325-
eventEmitter.emit('completed', 'INVALID JSON');
326-
expect(mock).toHaveBeenCalledWith(expect.any(LifecycleEventParseError));
329+
const invalidData = 'INVALID JSON';
330+
eventEmitter.emit('completed', invalidData);
331+
expect(mock).toHaveBeenCalledWith(
332+
expect.any(LifecycleEventParseError),
333+
invalidData,
334+
);
327335
});
328336
});
329337

sample/ios/Podfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,7 @@ PODS:
12611261
- Yoga
12621262
- ShopifyCheckoutSheetKit (3.1.1)
12631263
- SocketRocket (0.7.0)
1264+
- SwiftLint (0.57.0)
12641265
- Yoga (0.0.0)
12651266

12661267
DEPENDENCIES:
@@ -1327,12 +1328,14 @@ DEPENDENCIES:
13271328
- RNScreens (from `../node_modules/react-native-screens`)
13281329
- "RNShopifyCheckoutSheetKit (from `../../modules/@shopify/checkout-sheet-kit`)"
13291330
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
1331+
- SwiftLint
13301332
- Yoga (from `../../node_modules/react-native/ReactCommon/yoga`)
13311333

13321334
SPEC REPOS:
13331335
trunk:
13341336
- ShopifyCheckoutSheetKit
13351337
- SocketRocket
1338+
- SwiftLint
13361339

13371340
EXTERNAL SOURCES:
13381341
boost:
@@ -1525,8 +1528,9 @@ SPEC CHECKSUMS:
15251528
RNVectorIcons: 50ea777efffdd991a22e968aa312d75da7ff46c3
15261529
ShopifyCheckoutSheetKit: fe309799b18b8d554f28c3f075d6d57d4811c9ab
15271530
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
1531+
SwiftLint: eb47480d47c982481592c195c221d11013a679cc
15281532
Yoga: 348f8b538c3ed4423eb58a8e5730feec50bce372
15291533

1530-
PODFILE CHECKSUM: 4a9ceecdcfb54884b51163a7e4438cd49c73c8d9
1534+
PODFILE CHECKSUM: 9efd19a381198fb46f36acf3d269233039fb9dc5
15311535

15321536
COCOAPODS: 1.15.2

0 commit comments

Comments
 (0)