Skip to content

Conversation

@anonvt
Copy link
Contributor

@anonvt anonvt commented Oct 23, 2025

The SDK allows an auction to have 3 triggers, but the API allows at most two.

Adde compile time validation to ensure correct formation.

Copy link
Contributor

@jbergstroem jbergstroem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left feedback. Also.. tests.

@anonvt anonvt changed the title fix: coerce auction from 3 to 2 triggers fix: enforce limit of 2 auction trigers at compile time Oct 23, 2025
@anonvt anonvt changed the title fix: enforce limit of 2 auction trigers at compile time fix: enforce limit of 2 auction triggers at compile time Oct 23, 2025
@anonvt anonvt requested a review from jbergstroem October 23, 2025 20:14
@anonvt
Copy link
Contributor Author

anonvt commented Oct 23, 2025

@jbergstroem changed to compile time validation, we'll need to version bump though.
Also, not 100% sure on how to make a meaningful compile time test

@@ -0,0 +1,59 @@
/**
* Compile-time validation tests for auction constraints
* This file should compile without errors if the type system is working correctly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we then test invalid combinations?

Copy link
Contributor Author

@anonvt anonvt Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// @ts-expect-error can be an exit
I've changed the interface to accept the wrong combination and it fails (it expects an error, there's no error, so the annotation fails the "test")

auctions: [{ type: "banners", slots: 1, slotId: "slot123", category: { id: "cat123" } }],
};

const _invalid3TriggersAuction: Auction = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this allow any error, not just the error we're looking for? Are we sure this is the right path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added which specific error we're looking for 👍

@jbergstroem
Copy link
Contributor

Can we simplify your types? The permutations looks complicated. How about something like:

type CategoryType =
  | AuctionSingleCategory
  | AuctionMultipleCategories
  | AuctionDisjunctiveCategories;

type AuctionConstraints =
  | { category: CategoryType; products: AuctionProduct; searchQuery?: never }
  | { category: CategoryType; products?: never; searchQuery: string }
  | { category?: never; products: AuctionProduct; searchQuery: string }
  | { category: CategoryType; products?: never; searchQuery?: never }
  | { category?: never; products: AuctionProduct; searchQuery?: never }
  | { category?: never; products?: never; searchQuery: string }
  | { category?: never; products?: never; searchQuery?: never };

type AuctionBase = AuctionBaseFields & AuctionConstraints;

interface SponsoredListingAuction extends Omit<AuctionBase, "type"> {
  type: "listings";
}

interface BannerAuction extends Omit<AuctionBase, "type"> {
  device?: DeviceType;
  slotId: string;
  type: "banners";
}

export interface Auction {
  auctions: (SponsoredListingAuction | BannerAuction)[];
}

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.

3 participants