@schematichq/schematic-typescript-node 1.5.13 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -28
- package/dist/api/resources/credits/client/Client.d.ts +41 -5
- package/dist/api/resources/credits/client/requests/ReserveCreditsRequestBody.d.ts +18 -0
- package/dist/api/resources/credits/client/requests/index.d.ts +1 -0
- package/dist/api/resources/credits/types/ReleaseCreditReservationResponse.d.ts +6 -0
- package/dist/api/resources/credits/types/ReserveCreditsResponse.d.ts +6 -0
- package/dist/api/resources/credits/types/index.d.ts +2 -0
- package/dist/api/resources/features/client/Client.d.ts +18 -0
- package/dist/api/resources/features/client/requests/CheckAndReserveFlagRequestBody.d.ts +15 -0
- package/dist/api/resources/features/client/requests/index.d.ts +1 -0
- package/dist/api/resources/features/types/CheckAndReserveFlagResponse.d.ts +6 -0
- package/dist/api/resources/features/types/index.d.ts +1 -0
- package/dist/api/resources/planmigrations/client/Client.d.ts +4 -2
- package/dist/api/resources/planmigrations/client/requests/CountMigrationsRequest.d.ts +3 -1
- package/dist/api/resources/planmigrations/client/requests/ListMigrationsRequest.d.ts +3 -1
- package/dist/api/resources/planmigrations/types/CountMigrationsParams.d.ts +1 -0
- package/dist/api/resources/planmigrations/types/ListMigrationsParams.d.ts +1 -0
- package/dist/api/resources/plans/client/Client.d.ts +4 -0
- package/dist/api/resources/plans/client/requests/CountPlansRequest.d.ts +6 -0
- package/dist/api/resources/plans/client/requests/ListPlansRequest.d.ts +6 -0
- package/dist/api/resources/plans/types/CountPlansParams.d.ts +4 -0
- package/dist/api/resources/plans/types/ListPlansParams.d.ts +4 -0
- package/dist/api/types/CheckAndReserveFlagResponseData.d.ts +35 -0
- package/dist/api/types/CreditReservationResponseData.d.ts +15 -0
- package/dist/api/types/CreditUsageReason.d.ts +2 -0
- package/dist/api/types/EventBodyTrack.d.ts +2 -0
- package/dist/api/types/EventDetailResponseData.d.ts +1 -0
- package/dist/api/types/EventResponseData.d.ts +1 -0
- package/dist/api/types/FlagCheckReservationResponseData.d.ts +15 -0
- package/dist/api/types/PlanVersionMigrationResponseData.d.ts +2 -0
- package/dist/api/types/index.d.ts +3 -1
- package/dist/credits/index.d.ts +2 -2
- package/dist/credits/server-check.d.ts +40 -0
- package/dist/credits/track.d.ts +1 -1
- package/dist/credits/types.d.ts +36 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -9
- package/dist/serialization/resources/credits/client/requests/ReserveCreditsRequestBody.d.ts +13 -0
- package/dist/serialization/resources/credits/client/requests/index.d.ts +1 -0
- package/dist/serialization/resources/credits/types/ReleaseCreditReservationResponse.d.ts +11 -0
- package/dist/serialization/resources/credits/types/ReserveCreditsResponse.d.ts +11 -0
- package/dist/serialization/resources/credits/types/index.d.ts +2 -0
- package/dist/serialization/resources/features/client/requests/CheckAndReserveFlagRequestBody.d.ts +14 -0
- package/dist/serialization/resources/features/client/requests/index.d.ts +1 -0
- package/dist/serialization/resources/features/types/CheckAndReserveFlagResponse.d.ts +11 -0
- package/dist/serialization/resources/features/types/index.d.ts +1 -0
- package/dist/serialization/resources/planmigrations/types/CountMigrationsParams.d.ts +1 -0
- package/dist/serialization/resources/planmigrations/types/ListMigrationsParams.d.ts +1 -0
- package/dist/serialization/resources/plans/types/CountPlansParams.d.ts +2 -0
- package/dist/serialization/resources/plans/types/ListPlansParams.d.ts +2 -0
- package/dist/serialization/types/CheckAndReserveFlagResponseData.d.ts +28 -0
- package/dist/serialization/types/CreditReservationResponseData.d.ts +17 -0
- package/dist/serialization/types/CreditUsageReason.d.ts +1 -1
- package/dist/serialization/types/EventBodyTrack.d.ts +1 -0
- package/dist/serialization/types/EventDetailResponseData.d.ts +1 -0
- package/dist/serialization/types/EventResponseData.d.ts +1 -0
- package/dist/serialization/types/FlagCheckReservationResponseData.d.ts +16 -0
- package/dist/serialization/types/PlanVersionMigrationResponseData.d.ts +2 -0
- package/dist/serialization/types/index.d.ts +3 -1
- package/dist/wrapper.d.ts +41 -10
- package/package.json +9 -1
- package/dist/api/types/ReleaseCreditLeaseRequestBody.d.ts +0 -1
- package/dist/serialization/types/ReleaseCreditLeaseRequestBody.d.ts +0 -7
|
@@ -79,6 +79,7 @@ export * from "./CatalogResponseData";
|
|
|
79
79
|
export * from "./ChangeSubscriptionInternalRequestBody";
|
|
80
80
|
export * from "./ChangeSubscriptionRequestBody";
|
|
81
81
|
export * from "./ChargeType";
|
|
82
|
+
export * from "./CheckAndReserveFlagResponseData";
|
|
82
83
|
export * from "./CheckFlagRequestBody";
|
|
83
84
|
export * from "./CheckFlagResponseData";
|
|
84
85
|
export * from "./CheckFlagsBulkResponseData";
|
|
@@ -169,6 +170,7 @@ export * from "./CreditGrantDetail";
|
|
|
169
170
|
export * from "./CreditGrantExpiryRequestBody";
|
|
170
171
|
export * from "./CreditGrantSortOrder";
|
|
171
172
|
export * from "./CreditLeaseResponseData";
|
|
173
|
+
export * from "./CreditReservationResponseData";
|
|
172
174
|
export * from "./CreditSpendPolicyResponseData";
|
|
173
175
|
export * from "./CreditSpendPolicyScope";
|
|
174
176
|
export * from "./CreditsAutoTopupCompanySummary";
|
|
@@ -251,6 +253,7 @@ export * from "./FeatureUsageLegacyResponseData";
|
|
|
251
253
|
export * from "./FeatureUsageResponseData";
|
|
252
254
|
export * from "./FeatureUsageTimeSeriesResponseData";
|
|
253
255
|
export * from "./FeatureView";
|
|
256
|
+
export * from "./FlagCheckReservationResponseData";
|
|
254
257
|
export * from "./FlagDetailResponseData";
|
|
255
258
|
export * from "./FlagInPlanResponseData";
|
|
256
259
|
export * from "./FlagResponseData";
|
|
@@ -360,7 +363,6 @@ export * from "./PublicPlansResponseData";
|
|
|
360
363
|
export * from "./QuickstartResp";
|
|
361
364
|
export * from "./RawEventBatchResponseData";
|
|
362
365
|
export * from "./RawEventResponseData";
|
|
363
|
-
export * from "./ReleaseCreditLeaseRequestBody";
|
|
364
366
|
export * from "./Rule";
|
|
365
367
|
export * from "./RuleConditionDetailResponseData";
|
|
366
368
|
export * from "./RuleConditionGroupDetailResponseData";
|
package/dist/credits/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export { ReservationStore, type IReservationStore } from "./reservation-store";
|
|
|
3
3
|
export { CreditLeaseManager } from "./lease-manager";
|
|
4
4
|
export { RedisLeaseStore } from "./redis-lease-store";
|
|
5
5
|
export { RedisReservationStore } from "./redis-reservation-store";
|
|
6
|
-
export { DEFAULT_LEASE_DURATION_MS, DEFAULT_LEASE_SIZE, DEFAULT_LOW_WATER_MARK, DEFAULT_PREWARM_POLL_INTERVAL_MS, DEFAULT_PREWARM_RESOLVE_TIMEOUT_MS, DEFAULT_RESERVATION_TTL_MS, DEFAULT_SWEEP_INTERVAL_MS, } from "./types";
|
|
7
|
-
export type { CreditLeaseConfig, ResolvedLeaseConfig, Reservation, CheckOptions, CheckResult, OnAcquireFailure, TrackWithReservationOptions, } from "./types";
|
|
6
|
+
export { DEFAULT_LEASE_DURATION_MS, DEFAULT_LEASE_SIZE, DEFAULT_LOW_WATER_MARK, DEFAULT_PREWARM_POLL_INTERVAL_MS, DEFAULT_PREWARM_RESOLVE_TIMEOUT_MS, DEFAULT_RESERVATION_TTL_MS, DEFAULT_SWEEP_INTERVAL_MS, MAX_RESERVATION_TTL_MS, RESERVATION_TTL_SKEW_ALLOWANCE_MS, } from "./types";
|
|
7
|
+
export type { CreditLeaseConfig, CreditLeaseMode, ResolvedLeaseConfig, Reservation, CheckOptions, CheckResult, OnAcquireFailure, TrackWithReservationOptions, } from "./types";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type * as api from "../api";
|
|
2
|
+
import type { CreditsClient } from "../api/resources/credits/client/Client";
|
|
3
|
+
import type { FeaturesClient } from "../api/resources/features/client/Client";
|
|
4
|
+
import type { Logger } from "../logger";
|
|
5
|
+
import type { CheckOptions, CheckResult } from "./types";
|
|
6
|
+
/** Everything `checkWithServerReservation` needs to satisfy a server-mode check. */
|
|
7
|
+
export interface ServerCheckDeps {
|
|
8
|
+
features: FeaturesClient;
|
|
9
|
+
credits: CreditsClient;
|
|
10
|
+
logger: Logger;
|
|
11
|
+
/** How far out to set the hold's `expiresAt` (ms). */
|
|
12
|
+
reservationTTL: number;
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the caller's default for this flag — `options.defaultValue` when
|
|
15
|
+
* set, otherwise the client-level flag default. Used by the fail-open
|
|
16
|
+
* branch, which has no local engine to re-run.
|
|
17
|
+
*/
|
|
18
|
+
getDefault: () => boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Drives a single `client.check` with `usage` set, in server mode.
|
|
22
|
+
*
|
|
23
|
+
* One `POST /flags/{key}/check-and-reserve` call does everything the client
|
|
24
|
+
* path spreads across a lease acquire, a local reserve, and a WASM eval: the
|
|
25
|
+
* server evaluates the flag against the company's real balance, applies the
|
|
26
|
+
* preflight cost, and takes the hold — all in the same round-trip. There is no
|
|
27
|
+
* lease, no local store, and no rules engine involved.
|
|
28
|
+
*
|
|
29
|
+
* The failure contract differs from client mode in one place. `fail-open` there
|
|
30
|
+
* means "re-run the engine with the credit balance assumed sufficient", so plan
|
|
31
|
+
* targeting and every non-credit condition still apply. Server mode has no
|
|
32
|
+
* local engine to re-run — the call that would have answered is the one that
|
|
33
|
+
* failed — so `fail-open` returns the caller's default value
|
|
34
|
+
* (`options.defaultValue`, else the client's configured flag default) instead.
|
|
35
|
+
* `fail-closed` denies, same as client mode.
|
|
36
|
+
*
|
|
37
|
+
* No `flag_check` event is enqueued here: the server logs the flag check for
|
|
38
|
+
* check-and-reserve itself, the same way the REST `checkFlag` path does.
|
|
39
|
+
*/
|
|
40
|
+
export declare function checkWithServerReservation(deps: ServerCheckDeps, key: string, evalCtx: api.CheckFlagRequestBody, options: CheckOptions, fallback: () => Promise<CheckResult>): Promise<CheckResult>;
|
package/dist/credits/track.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { IReservationStore } from "./reservation-store";
|
|
|
3
3
|
import type { Reservation, TrackWithReservationOptions } from "./types";
|
|
4
4
|
/** Outcome of consuming a reservation and building its Track event. */
|
|
5
5
|
export interface ReservationConsumeResult {
|
|
6
|
-
/** The Track event to emit. Always carries the `leaseId
|
|
6
|
+
/** The Track event to emit. Always carries the `leaseId` (client mode) or the `reservationId` (server mode). */
|
|
7
7
|
track: api.EventBodyTrack;
|
|
8
8
|
/**
|
|
9
9
|
* `true` when the reservation was still live and `consume` debited/refunded
|
package/dist/credits/types.d.ts
CHANGED
|
@@ -13,23 +13,46 @@ import type { RedisClient } from "../cache/redis";
|
|
|
13
13
|
export type OnAcquireFailure = "fail-open" | "fail-closed";
|
|
14
14
|
export declare const DEFAULT_LEASE_DURATION_MS: number;
|
|
15
15
|
export declare const DEFAULT_RESERVATION_TTL_MS: number;
|
|
16
|
+
export declare const MAX_RESERVATION_TTL_MS: number;
|
|
17
|
+
export declare const RESERVATION_TTL_SKEW_ALLOWANCE_MS: number;
|
|
16
18
|
export declare const DEFAULT_LEASE_SIZE: number;
|
|
17
19
|
export declare const DEFAULT_LOW_WATER_MARK: number;
|
|
18
20
|
export declare const DEFAULT_SWEEP_INTERVAL_MS: number;
|
|
19
21
|
export declare const DEFAULT_PREWARM_RESOLVE_TIMEOUT_MS: number;
|
|
20
22
|
export declare const DEFAULT_PREWARM_POLL_INTERVAL_MS: number;
|
|
23
|
+
/**
|
|
24
|
+
* Where a credit hold lives for a `check()` that passes `usage`.
|
|
25
|
+
* - `client`: local leases over DataStream — the SDK acquires a tranche of
|
|
26
|
+
* credits up front and carves reservations out of it locally (today's
|
|
27
|
+
* behavior). Requires DataStream (or replicator mode), and a shared Redis
|
|
28
|
+
* backend to gate across pods.
|
|
29
|
+
* - `server`: one `check-and-reserve` API call per check — the server
|
|
30
|
+
* evaluates the flag and takes the hold in the same round-trip. No
|
|
31
|
+
* DataStream, no Redis, no local stores.
|
|
32
|
+
* - `auto` (default): `client` when DataStream is enabled, `server` otherwise.
|
|
33
|
+
*/
|
|
34
|
+
export type CreditLeaseMode = "client" | "server" | "auto";
|
|
21
35
|
/**
|
|
22
36
|
* Configuration block enabling client-side lease + reservation behavior on
|
|
23
37
|
* `client.check` / `client.trackWithReservation`. Omit to keep the SDK
|
|
24
38
|
* lease-unaware (`check` falls back to a plain flag check).
|
|
25
39
|
*/
|
|
26
40
|
export interface CreditLeaseConfig {
|
|
41
|
+
/**
|
|
42
|
+
* Where the credit hold lives. Default `auto` — client mode when
|
|
43
|
+
* DataStream is enabled, server mode otherwise. See `CreditLeaseMode`.
|
|
44
|
+
*/
|
|
45
|
+
mode?: CreditLeaseMode;
|
|
27
46
|
/** Default lease duration in milliseconds. Default `DEFAULT_LEASE_DURATION_MS` (5 minutes). */
|
|
28
47
|
defaultLeaseDuration?: number;
|
|
29
48
|
/**
|
|
30
49
|
* Default reservation TTL in milliseconds. Default `DEFAULT_RESERVATION_TTL_MS`
|
|
31
|
-
* (60 seconds).
|
|
32
|
-
*
|
|
50
|
+
* (60 seconds). In server mode it is capped at `MAX_RESERVATION_TTL_MS`
|
|
51
|
+
* (1 hour) less `RESERVATION_TTL_SKEW_ALLOWANCE_MS`, since an hour out is
|
|
52
|
+
* the furthest the API will hold credits and it measures that against its
|
|
53
|
+
* own clock. Size this above the
|
|
54
|
+
* longest expected gap between `check()` and `trackWithReservation()`: a
|
|
55
|
+
* settle arriving after the TTL still bills
|
|
33
56
|
* the server but doesn't re-debit the local lease (its hold was already
|
|
34
57
|
* swept back), so the local balance reads high until the lease rolls over.
|
|
35
58
|
*/
|
|
@@ -71,7 +94,7 @@ export interface CreditLeaseConfig {
|
|
|
71
94
|
*/
|
|
72
95
|
redisKeyPrefix?: string;
|
|
73
96
|
/** Per-credit-type overrides (keyed by credit type ID). */
|
|
74
|
-
overrides?: Record<string, Partial<Omit<CreditLeaseConfig, "overrides" | "sweepIntervalMs" | "redisClient" | "redisKeyPrefix">>>;
|
|
97
|
+
overrides?: Record<string, Partial<Omit<CreditLeaseConfig, "overrides" | "mode" | "sweepIntervalMs" | "redisClient" | "redisKeyPrefix">>>;
|
|
75
98
|
}
|
|
76
99
|
/** Resolved config for a single credit type after applying defaults + overrides. */
|
|
77
100
|
export interface ResolvedLeaseConfig {
|
|
@@ -84,8 +107,17 @@ export interface ResolvedLeaseConfig {
|
|
|
84
107
|
export interface Reservation {
|
|
85
108
|
/** Opaque reservation ID. */
|
|
86
109
|
id: string;
|
|
87
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Underlying lease ID this reservation draws from. In server mode there is
|
|
112
|
+
* no lease — this mirrors `id` so the field stays populated.
|
|
113
|
+
*/
|
|
88
114
|
leaseId: string;
|
|
115
|
+
/**
|
|
116
|
+
* Where the hold lives. `server` means the API holds the credits and the
|
|
117
|
+
* settling Track event routes by `reservation_id`; absent (or `client`)
|
|
118
|
+
* means the hold is a local carve-out of a lease.
|
|
119
|
+
*/
|
|
120
|
+
mode?: "client" | "server";
|
|
89
121
|
/** Company that owns the lease. */
|
|
90
122
|
companyId: string;
|
|
91
123
|
/** Credit type the reservation reserves against. */
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export { ConsoleLogger, LogLevel, type Logger } from "./logger";
|
|
|
6
6
|
export { SchematicEnvironment } from "./environments";
|
|
7
7
|
export { SchematicError, SchematicTimeoutError } from "./errors";
|
|
8
8
|
export { RulesEngineClient } from "./rules-engine";
|
|
9
|
-
export type { CheckOptions, CheckResult, CreditLeaseConfig, OnAcquireFailure, Reservation, TrackWithReservationOptions, } from "./credits";
|
|
9
|
+
export type { CheckOptions, CheckResult, CreditLeaseConfig, CreditLeaseMode, OnAcquireFailure, Reservation, TrackWithReservationOptions, } from "./credits";
|
|
10
10
|
export { verifyWebhookSignature, verifySignature, computeSignature, computeHexSignature, WebhookSignatureError, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER } from "./webhooks";
|