Skip to content

fix(case-helpers): preserve custom_data keys at any nesting depth - #226

Open
TabishRiazBajwa wants to merge 1 commit into
PaddleHQ:mainfrom
TabishRiazBajwa:fix/preserve-custom-data-keys-in-simulation-payloads
Open

fix(case-helpers): preserve custom_data keys at any nesting depth#226
TabishRiazBajwa wants to merge 1 commit into
PaddleHQ:mainfrom
TabishRiazBajwa:fix/preserve-custom-data-keys-in-simulation-payloads

Conversation

@TabishRiazBajwa

Copy link
Copy Markdown

Problem

convertToSnakeCase in src/internal/api/case-helpers.ts has a carve-out that preserves customData contents when it appears as a top-level key on the request body. This works correctly for paddle.subscriptions.create(), paddle.transactions.create(), etc.

However, when creating a simulation via paddle.simulations.create(), customData is nested inside payload.data — not at the top level. The existing guard never fires, so all camelCase keys inside customData get silently converted to snake_case before being sent to the Paddle API.

Result: simulation webhooks deliver { tenant_id: "abc" } instead of { tenantId: "abc" }, breaking any webhook handler that reads theoriginal keys — and producing a silent data corruption that's hard to debug.

Fix

Move the customData preservation logic into decamelizeKeys so it applies at any depth of the object tree, not just the top level. When the recursive walk encounters an object key named customData, it copies the value as-is (snake-cased key, original value) instead of recursing into it.

Testing

  • Added a unit test covering convertToSnakeCase with customData nested inside a simulation payload.data object.
  • Verified existing top-level customData tests still pass.

Fixes #220

convertToSnakeCase only guarded customData at the top level of the request body. Simulation payloads nest customData inside payload.data,
so its keys were silently snake_cased before being sent to the API,
breaking webhook handlers that expected the original camelCase keys.

Make the customData carve-out depth-insensitive by checking for the key
recursively during decamelization, not just at the top level.

Fixes PaddleHQ#220
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: convertToSnakeCase recursively converts keys inside custom_data on simulation payloads

1 participant