[feature] add option to disable converting ISO strings to dates #635
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new load option -
disableAutoISOConversions
. This turns off the automatic conversion of event fields where any strings that appear as an ISO8601 string (including just dates, e.g.YYYY-MM-DD
) becomeDate
objects.Background
Through
@segment/facade
, any events passed to classic integrations had any ISO strings converted to Dates. I suspect this was intentional behavior because the way we cloned events (JSON.parse(JSON.stringify(event))
) converted Dates to ISO8601 strings, so facade was converting them back to dates.However, some users want their ISO strings to be passed to integrations as is, especially when the string represents a calendar date and not a time.
PR details
@segment/facade
supports turning off this conversion by settingtraverse
to false, so the new option ultimately sets thetraverse
flag.I also changed how we clone events so that users can still specify a property as a
Date
object and have that carried over to the cloned event regardless of the new setting. It looks like analytics.js classic also did a deep clone of the event instead of ourJSON.parse(JSON.stringify(event))
trick, so this shouldn't cause any unintended consequences.I made this field default to
false
, meaning users need to opt-in to this new behavior. I made it opt-in to prevent potentially impacting user-defined destination middleware.[x] I've included a changeset (psst. run
yarn changeset
. Read about changesets here).