diff --git a/README.md b/README.md index f74a8b8d..3bc3492b 100644 --- a/README.md +++ b/README.md @@ -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) }, }); ``` diff --git a/src/credits/types.ts b/src/credits/types.ts index 25117015..1284e7e9 100644 --- a/src/credits/types.ts +++ b/src/credits/types.ts @@ -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; @@ -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 diff --git a/tests/unit/wrapper.test.ts b/tests/unit/wrapper.test.ts index 4902d00d..85be2a30 100644 --- a/tests/unit/wrapper.test.ts +++ b/tests/unit/wrapper.test.ts @@ -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; @@ -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,