Skip to content

Add support for strict=1 parameter in import API for enhanced validation #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 25, 2025

This PR implements support for the strict=1 parameter in Mixpanel's import API to enable enhanced validation as recommended in the official documentation.

Features Added

Global Strict Configuration

Enable strict validation for all import requests:

// During initialization
const mixpanel = Mixpanel.init('token', { secret: 'secret', strict: true });

// Or after initialization
mixpanel.set_config({ strict: true });

Method-Level Strict Options

Enable strict validation for individual requests:

// For single event import
mixpanel.import('event_name', new Date(), { distinct_id: 'user123' }, { strict: true });

// For batch import
mixpanel.import_batch(events, { strict: true }, callback);

Benefits

When strict=1 is enabled, the import API will:

  • Validate all supplied events before processing
  • Return detailed error information (400 status) if validation fails
  • Still ingest events that pass validation when others fail
  • Provide $insert_ids of invalid events for debugging

This is especially valuable in production environments for identifying and debugging event formatting issues.

Implementation Details

  • Added strict option to DEFAULT_CONFIG with default value false
  • Modified send_request to append strict=1 query parameter for import endpoints
  • Updated import() and import_batch() methods to accept strict options
  • Enhanced TypeScript definitions with new ImportOptions interface
  • Maintained full backward compatibility with existing API signatures

Testing

  • All existing tests continue to pass (178 total)
  • Added comprehensive test coverage for new functionality
  • Verified backward compatibility with all existing usage patterns
  • Tested both global and method-level strict configurations

Fixes #233.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.mixpanel.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /tmp/test_strict_functionality.js (dns block)
    • Triggering command: node /tmp/test_backward_compatibility.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Support for strict=1 parameter in import api to support validation Add support for strict=1 parameter in import API for enhanced validation Jun 25, 2025
@Copilot Copilot AI requested a review from austinpray-mixpanel June 25, 2025 00:49
Copilot finished work on behalf of austinpray-mixpanel June 25, 2025 00:49
@austinpray-mixpanel
Copy link
Member

@tdumitrescu not bad at first glance

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.

Support for strict=1 parameter in import api to support validation
2 participants