Skip to content

Comments

feat: Zod-based Configuration extending Crawlee's new approach#551

Open
B4nan wants to merge 5 commits intov4from
feat/zod-configuration
Open

feat: Zod-based Configuration extending Crawlee's new approach#551
B4nan wants to merge 5 commits intov4from
feat/zod-configuration

Conversation

@B4nan
Copy link
Member

@B4nan B4nan commented Feb 4, 2026

Summary

Refactors the Configuration class to use Zod-based field definitions, extending Crawlee's new Configuration class cleanly without monkey patching.

  • Uses crawleeConfigFields spread with Apify-specific overrides and additions
  • Each field defines schema and env var aliases in one place
  • Supports multiple env var aliases per field (e.g., ACTOR_ID, APIFY_ACTOR_ID)
  • Removes all monkey patching of CoreConfiguration
  • Adds zod as direct dependency

Before (with monkey patching)

// Old approach - monkey patching CoreConfiguration
CoreConfiguration.getGlobalConfig = Configuration.getGlobalConfig;
CoreConfiguration.ENV_MAP = Configuration.ENV_MAP;
CoreConfiguration.INTEGER_VARS = Configuration.INTEGER_VARS;
CoreConfiguration.BOOLEAN_VARS = Configuration.BOOLEAN_VARS;
CoreConfiguration.DEFAULTS = Configuration.DEFAULTS;

After (clean extension)

export const apifyConfigFields = {
    ...crawleeConfigFields,
    
    // Override with additional env var aliases
    defaultDatasetId: field(z.string().default('default'), {
        env: ['ACTOR_DEFAULT_DATASET_ID', 'APIFY_DEFAULT_DATASET_ID', 'CRAWLEE_DEFAULT_DATASET_ID'],
    }),
    
    // Add new Apify-specific fields
    token: field(z.string().optional(), { env: 'APIFY_TOKEN' }),
    actorId: field(z.string().optional(), { env: ['ACTOR_ID', 'APIFY_ACTOR_ID'] }),
};

export class Configuration extends CrawleeConfiguration<ApifyConfigFields, ...> {
    static override fields = apifyConfigFields;
}

Dependencies

Requires: apify/crawlee#3387

Test plan

  • Type checking passes (after Crawlee PR is merged/published)
  • Full test suite
  • E2E tests

🤖 Generated with Claude Code

B4nan and others added 5 commits February 4, 2026 17:05
Refactors the Configuration class to use Zod-based field definitions,
extending Crawlee's new Configuration class cleanly without monkey patching.

Key changes:
- Uses `crawleeConfigFields` spread with Apify-specific overrides and additions
- Each field defines schema and env var aliases in one place
- Supports multiple env var aliases per field (e.g., ACTOR_ID, APIFY_ACTOR_ID)
- Removes all monkey patching of CoreConfiguration
- Adds zod as direct dependency

Example field definition:
```ts
actorId: field(z.string().optional(), {
    env: ['ACTOR_ID', 'APIFY_ACTOR_ID'],
}),
```

Requires: apify/crawlee#3387

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Uses the new `extendField()` helper from Crawlee to extend base fields
with additional env var mappings without repeating the CRAWLEE_* ones.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Updates to use CrawleeConfiguration.extendField() static method instead
of standalone extendField import.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant