Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ Server mode needs only a TTL:
const client = new SchematicClient({
apiKey: process.env.SCHEMATIC_API_KEY,
creditLeases: {
defaultReservationTTL: 60 * 1000, // how long the server holds the credits if no track settles them (ms, max 1 hour)
defaultReservationTTL: 60 * 1000, // how long the server holds the credits if no track settles them (ms, max 24 hours)
},
});
```
Expand Down
8 changes: 4 additions & 4 deletions src/credits/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export type OnAcquireFailure = "fail-open" | "fail-closed";
// below stay accurate even if a consumer overrides only a subset of fields.
export const DEFAULT_LEASE_DURATION_MS: number = 5 * 60 * 1000;
export const DEFAULT_RESERVATION_TTL_MS: number = 60 * 1000;
// The API rejects a hold whose `expiresAt` is more than an hour out, so a
// The API rejects a hold whose `expiresAt` is more than 24 hours out, so a
// larger reservation TTL would fail every server-mode check. The SDK clamps to
// this instead.
export const MAX_RESERVATION_TTL_MS: number = 60 * 60 * 1000;
// The API measures that hour against its own clock while the SDK computes
export const MAX_RESERVATION_TTL_MS: number = 24 * 60 * 60 * 1000;
// The API measures that limit against its own clock while the SDK computes
// `expiresAt` against the caller's, so a client running ahead would be rejected
// at exactly the cap. Hold this much back from it.
export const RESERVATION_TTL_SKEW_ALLOWANCE_MS: number = 60 * 1000;
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface CreditLeaseConfig {
/**
* Default reservation TTL in milliseconds. Default `DEFAULT_RESERVATION_TTL_MS`
* (60 seconds). In server mode it is capped at `MAX_RESERVATION_TTL_MS`
* (1 hour) less `RESERVATION_TTL_SKEW_ALLOWANCE_MS`, since an hour out is
* (24 hours) less `RESERVATION_TTL_SKEW_ALLOWANCE_MS`, since 24 hours out is
* the furthest the API will hold credits and it measures that against its
* own clock. Size this above the
* longest expected gap between `check()` and `trackWithReservation()`: a
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ describe("SchematicClient wrapper - server-mode credit reservations", () => {
const client = new SchematicClient({
apiKey: "test-key",
logger: mockLogger,
creditLeases: { mode: "server", defaultReservationTTL: 4 * 60 * 60 * 1000 },
creditLeases: { mode: "server", defaultReservationTTL: 25 * 60 * 60 * 1000 },
});

const maxTTL = MAX_RESERVATION_TTL_MS - RESERVATION_TTL_SKEW_ALLOWANCE_MS;
Expand All @@ -1134,7 +1134,7 @@ describe("SchematicClient wrapper - server-mode credit reservations", () => {
});

it("leaves the TTL alone in client mode, where the API never sees it", async () => {
const ttl = 2 * 60 * 60 * 1000;
const ttl = 25 * 60 * 60 * 1000;
const client = new SchematicClient({
apiKey: "test-key",
logger: mockLogger,
Expand Down
Loading