Skip to content
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

Add proper typing for cdn/links endpoint and include_dates parameter #911

Merged
merged 1 commit into from
Dec 23, 2024

Conversation

edodusi
Copy link
Contributor

@edodusi edodusi commented Dec 23, 2024

Pull request type

Fixes: #909

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Other (please describe):

How to test this PR

  1. Install dependencies and run tests:
pnpm install
pnpm test
  1. Try using the cdn/links endpoint with TypeScript:
const { data } = await storyblokApi.get('cdn/links', {
  version: 'draft',
  include_dates: 1
});
// TypeScript should properly recognize all fields including dates
console.log(data.links['some-uuid'].created_at);
  1. Verify that other endpoints still work as expected with their original types.

What is the new behavior?

  • Added proper typing for cdn/links endpoint parameters through ISbLinksParams interface
  • Added ISbLinkWithDates interface to include date fields when include_dates is set
  • Implemented function overloads for the get method to provide correct typing based on the endpoint
  • Added comprehensive test suite covering various edge cases and scenarios
  • TypeScript now correctly validates:
    • The include_dates parameter for cdn/links endpoint
    • Date fields (created_at, updated_at, published_at) when include_dates is used
    • Proper return types for both cdn/links and other endpoints

Other information

This PR fixes the typing issues with the cdn/links endpoint while maintaining backward compatibility with existing code. All changes are type-level only, with no runtime behavior modifications.

@bevanmw
Copy link

bevanmw commented Dec 23, 2024

Awesome! Thanks @edodusi

@edodusi edodusi merged commit 060dd69 into main Dec 23, 2024
6 checks passed
@edodusi edodusi deleted the fix/missing-types-for-fetching-links branch December 23, 2024 15:00
Copy link

🎉 This PR is included in version 6.10.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix [PR] Fixes a bug released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing types for fetching links query params
3 participants