@schematichq/schematic-typescript-node 1.6.0 → 1.6.2
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 +51 -28
- package/dist/api/resources/credits/client/requests/AcquireCreditLeaseRequestBody.d.ts +1 -0
- package/dist/api/resources/credits/client/requests/ExtendCreditLeaseRequestBody.d.ts +3 -0
- package/dist/api/resources/entitlements/client/requests/CreateBillingLinkedPlanEntitlementRequestBody.d.ts +4 -0
- package/dist/api/resources/entitlements/client/requests/CreatePlanEntitlementRequestBody.d.ts +4 -0
- package/dist/api/resources/entitlements/client/requests/UpdatePlanEntitlementRequestBody.d.ts +4 -0
- package/dist/api/resources/features/client/requests/CheckAndReserveFlagRequestBody.d.ts +4 -2
- 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/BillingArrearsCadence.d.ts +1 -0
- package/dist/api/types/BillingCreditGrantReason.d.ts +3 -0
- package/dist/api/types/BillingCreditResponseData.d.ts +1 -0
- package/dist/api/types/BillingPlanCreditGrantBillingMode.d.ts +5 -0
- package/dist/api/types/BillingPlanCreditGrantPriceTierResponseData.d.ts +10 -0
- package/dist/api/types/BillingPlanCreditGrantResponseData.d.ts +12 -0
- package/dist/api/types/CompanyPlanCreditGrantView.d.ts +3 -0
- package/dist/api/types/CreateBillingPlanCreditGrantRequestBody.d.ts +11 -1
- package/dist/api/types/CreateEntitlementInBundleRequestBody.d.ts +4 -0
- package/dist/api/types/CreditEventLedgerResponseData.d.ts +1 -0
- package/dist/api/types/CreditGrantPriceTierRequestBody.d.ts +8 -0
- package/dist/api/types/CreditTransferReason.d.ts +7 -0
- package/dist/api/types/PlanCreditGrantView.d.ts +3 -0
- package/dist/api/types/PlanEntitlementResponseData.d.ts +4 -0
- package/dist/api/types/PlanVersionMigrationResponseData.d.ts +2 -0
- package/dist/api/types/UpdateBillingPlanCreditGrantRequestBody.d.ts +11 -1
- package/dist/api/types/UsageBasedEntitlementRequestBody.d.ts +4 -0
- package/dist/api/types/index.d.ts +4 -0
- package/dist/cache/redis.d.ts +11 -0
- package/dist/credits/check.d.ts +10 -5
- package/dist/credits/index.d.ts +4 -4
- package/dist/credits/lease-manager.d.ts +74 -2
- package/dist/credits/lease-store.d.ts +27 -11
- package/dist/credits/redis-lease-store.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 +37 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -10
- package/dist/serialization/resources/credits/client/requests/ExtendCreditLeaseRequestBody.d.ts +1 -0
- package/dist/serialization/resources/entitlements/client/requests/CreateBillingLinkedPlanEntitlementRequestBody.d.ts +4 -0
- package/dist/serialization/resources/entitlements/client/requests/CreatePlanEntitlementRequestBody.d.ts +4 -0
- package/dist/serialization/resources/entitlements/client/requests/UpdatePlanEntitlementRequestBody.d.ts +4 -0
- package/dist/serialization/resources/features/client/requests/CheckAndReserveFlagRequestBody.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/BillingArrearsCadence.d.ts +1 -1
- package/dist/serialization/types/BillingCreditGrantReason.d.ts +1 -1
- package/dist/serialization/types/BillingCreditResponseData.d.ts +2 -0
- package/dist/serialization/types/BillingPlanCreditGrantBillingMode.d.ts +7 -0
- package/dist/serialization/types/BillingPlanCreditGrantPriceTierResponseData.d.ts +12 -0
- package/dist/serialization/types/BillingPlanCreditGrantResponseData.d.ts +10 -0
- package/dist/serialization/types/CompanyPlanCreditGrantView.d.ts +5 -0
- package/dist/serialization/types/CreateBillingPlanCreditGrantRequestBody.d.ts +8 -0
- package/dist/serialization/types/CreateEntitlementInBundleRequestBody.d.ts +4 -0
- package/dist/serialization/types/CreditEventLedgerResponseData.d.ts +2 -0
- package/dist/serialization/types/CreditGrantPriceTierRequestBody.d.ts +11 -0
- package/dist/serialization/types/CreditTransferReason.d.ts +7 -0
- package/dist/serialization/types/PlanCreditGrantView.d.ts +5 -0
- package/dist/serialization/types/PlanEntitlementResponseData.d.ts +4 -0
- package/dist/serialization/types/PlanVersionMigrationResponseData.d.ts +2 -0
- package/dist/serialization/types/UpdateBillingPlanCreditGrantRequestBody.d.ts +8 -0
- package/dist/serialization/types/UsageBasedEntitlementRequestBody.d.ts +4 -0
- package/dist/serialization/types/index.d.ts +4 -0
- package/dist/wrapper.d.ts +91 -26
- package/package.json +5 -1
package/dist/wrapper.d.ts
CHANGED
|
@@ -55,36 +55,51 @@ export interface SchematicOptions {
|
|
|
55
55
|
/** The default maximum time to wait for a response in milliseconds */
|
|
56
56
|
timeoutMs?: number;
|
|
57
57
|
/**
|
|
58
|
-
* Enable
|
|
59
|
-
*
|
|
58
|
+
* Enable credit reservation behavior on `check` / `trackWithReservation`.
|
|
59
|
+
* Omit to keep the SDK credit-unaware.
|
|
60
60
|
*
|
|
61
|
-
*
|
|
62
|
-
* SDK has
|
|
63
|
-
*
|
|
61
|
+
* Client mode (local leases) requires DataStream (or replicator mode) so
|
|
62
|
+
* the SDK has the cached flag + company state it needs to gate locally
|
|
63
|
+
* against the lease balance. Without DataStream the SDK gates in server
|
|
64
|
+
* mode instead — one `check-and-reserve` API call per check. See
|
|
65
|
+
* `CreditLeaseConfig.mode`.
|
|
64
66
|
*/
|
|
65
67
|
creditLeases?: CreditLeaseConfig;
|
|
66
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Options for a single flag check.
|
|
71
|
+
*
|
|
72
|
+
* `creditCost`, `usage` and `eventUsage` are preflight inputs: they ask
|
|
73
|
+
* "would this action be allowed?" rather than "is it allowed now". They apply
|
|
74
|
+
* on every evaluation path, forwarded to the WASM rules engine's
|
|
75
|
+
* `checkFlagWithOptions` when the flag is evaluated locally (DataStream) and
|
|
76
|
+
* sent as the request body's `preflight` when it is evaluated over the REST
|
|
77
|
+
* API. The engine picks the most specific knob for each condition it
|
|
78
|
+
* evaluates. No reservation is issued; for lease-backed gating use `check()`.
|
|
79
|
+
*/
|
|
67
80
|
export interface CheckFlagOptions {
|
|
68
81
|
/** Default value to return on error. Can be a boolean or a function returning a boolean. If not provided, uses configured flag defaults */
|
|
69
82
|
defaultValue?: boolean | (() => boolean);
|
|
70
83
|
/** The maximum time to wait for a response in milliseconds */
|
|
71
84
|
timeoutMs?: number;
|
|
72
85
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* (DataStream); the REST fallback path does not support preflight and
|
|
77
|
-
* ignores these. No reservation is issued — for lease-backed gating use
|
|
78
|
-
* `check()` instead.
|
|
86
|
+
* Pre-computed cost of the action, keyed by credit id. Highest precedence
|
|
87
|
+
* for credit-balance gates. A cost of zero means the action is free, not
|
|
88
|
+
* that the input is absent.
|
|
79
89
|
*/
|
|
80
|
-
/** Pre-computed per-credit-id cost. Highest precedence for credit-balance gates. */
|
|
81
90
|
creditCost?: Record<string, number>;
|
|
82
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Quantity applied to whatever numeric condition is being evaluated. Zero
|
|
93
|
+
* has no effect. Both the REST request body and the local (WASM) engine
|
|
94
|
+
* take an integer, so a fraction rounds up rather than letting the check
|
|
95
|
+
* pass on less usage than the action is about to record.
|
|
96
|
+
*/
|
|
83
97
|
usage?: number;
|
|
84
98
|
/**
|
|
85
99
|
* Simulated quantity scoped to a specific event subtype. Preferred over
|
|
86
100
|
* `usage` when the subtype is known. Deliberately singular: one check
|
|
87
|
-
* preflights one action.
|
|
101
|
+
* preflights one action. `quantity` rounds up the same way `usage` does,
|
|
102
|
+
* and zero has no effect.
|
|
88
103
|
*/
|
|
89
104
|
eventUsage?: {
|
|
90
105
|
eventSubtype: string;
|
|
@@ -145,6 +160,10 @@ export declare class SchematicClient extends BaseClient {
|
|
|
145
160
|
private reservations?;
|
|
146
161
|
private leaseBackendShared;
|
|
147
162
|
private prewarmResolveTimeoutMs;
|
|
163
|
+
private creditLeaseMode?;
|
|
164
|
+
private serverReservationTTL;
|
|
165
|
+
private closing;
|
|
166
|
+
private readonly pendingPrewarms;
|
|
148
167
|
/**
|
|
149
168
|
* Creates a new instance of the SchematicClient
|
|
150
169
|
* @param opts - Configuration options for the client
|
|
@@ -154,6 +173,23 @@ export declare class SchematicClient extends BaseClient {
|
|
|
154
173
|
* Returns whether DataStream is enabled and available
|
|
155
174
|
*/
|
|
156
175
|
private useDataStream;
|
|
176
|
+
/**
|
|
177
|
+
* Whether the configured mode wants the local lease plumbing (stores,
|
|
178
|
+
* manager, sweeper). Read during construction, after the DataStream client
|
|
179
|
+
* has been wired, so `auto` can resolve against it.
|
|
180
|
+
*/
|
|
181
|
+
private creditLeaseModeUsesLeases;
|
|
182
|
+
/**
|
|
183
|
+
* Which reservation mode a `check()` with `usage` resolves to right now.
|
|
184
|
+
* `undefined` means no credit gating at all — `creditLeases` isn't
|
|
185
|
+
* configured, or the client is offline.
|
|
186
|
+
*
|
|
187
|
+
* `auto` is resolved per check rather than once at startup so a DataStream
|
|
188
|
+
* that failed to start after construction (its `start()` rejection clears
|
|
189
|
+
* `datastreamClient`) falls to server mode instead of silently dropping
|
|
190
|
+
* every check to a plain, ungated flag check.
|
|
191
|
+
*/
|
|
192
|
+
private effectiveLeaseMode;
|
|
157
193
|
/**
|
|
158
194
|
* Checks the value of a feature flag for the given evaluation context
|
|
159
195
|
* @param evalCtx - The context (company and/or user) for evaluating the feature flag
|
|
@@ -201,6 +237,11 @@ export declare class SchematicClient extends BaseClient {
|
|
|
201
237
|
* are still drawing on — doing so would refund the grant server-side and
|
|
202
238
|
* pull the balance out from under them. Shared leases reclaim themselves:
|
|
203
239
|
* they expire (client- and server-side) or are fully consumed.
|
|
240
|
+
*
|
|
241
|
+
* Lease work already in flight is waited out before the release, so an
|
|
242
|
+
* acquire that lands mid-shutdown is one the release can see. The wait and
|
|
243
|
+
* the release share one `SHUTDOWN_DRAIN_TIMEOUT_MS` budget, so close()
|
|
244
|
+
* stays bounded however slow the store or the wire is.
|
|
204
245
|
* @returns Promise that resolves when everything has been stopped
|
|
205
246
|
*/
|
|
206
247
|
close(): Promise<void>;
|
|
@@ -218,10 +259,10 @@ export declare class SchematicClient extends BaseClient {
|
|
|
218
259
|
*/
|
|
219
260
|
prewarm(evalCtx: api.CheckFlagRequestBody, creditTypeIds: string[]): Promise<void>;
|
|
220
261
|
/**
|
|
221
|
-
* Like `resolveCompanyId` but
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* surfaced within `prewarmResolveTimeoutMs
|
|
262
|
+
* Like `resolveCompanyId` but, on a cache miss, actively fetches the
|
|
263
|
+
* company over the datastream, warming the cache as a side effect. Returns
|
|
264
|
+
* the resolved id, the `comp_`-prefixed id the keys carry if the company
|
|
265
|
+
* never surfaced within `prewarmResolveTimeoutMs`, or undefined.
|
|
225
266
|
*
|
|
226
267
|
* `identify` does not push a company into the datastream cache — companies
|
|
227
268
|
* are only streamed in response to a request. So we call `getCompany`
|
|
@@ -232,19 +273,24 @@ export declare class SchematicClient extends BaseClient {
|
|
|
232
273
|
*/
|
|
233
274
|
private resolveCompanyIdWithWait;
|
|
234
275
|
/**
|
|
235
|
-
*
|
|
276
|
+
* Credit-aware feature check. When `creditLeases` is configured and the
|
|
236
277
|
* caller passes `usage` (optionally qualified by `eventSubtype`), this
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
278
|
+
* gates the check against the company's credit balance and returns a
|
|
279
|
+
* reservation handle on success — pass that handle to
|
|
280
|
+
* `trackWithReservation` when the work completes.
|
|
281
|
+
*
|
|
282
|
+
* In client mode (DataStream enabled) the hold is carved out of a local
|
|
283
|
+
* lease and the flag is evaluated by the WASM engine. In server mode it is
|
|
284
|
+
* a single `check-and-reserve` API call that evaluates the flag and takes
|
|
285
|
+
* the hold server-side. `creditLeases.mode` picks; the default (`auto`)
|
|
286
|
+
* uses client mode when DataStream is enabled and server mode otherwise.
|
|
240
287
|
*
|
|
241
288
|
* When `creditLeases` is not configured (or `usage` is omitted) this falls
|
|
242
289
|
* through to a plain flag check and returns `{allowed: value}` with no
|
|
243
290
|
* reservation, byte-compatible with `checkFlag` semantics. The caller's
|
|
244
291
|
* preflight (`usage` / `eventSubtype`) is still threaded through the plain
|
|
245
|
-
* check, so
|
|
246
|
-
*
|
|
247
|
-
* REST fallback ignores preflight.
|
|
292
|
+
* check, so every evaluation path (datastream, replicator, REST) gates on
|
|
293
|
+
* the post-call balance — just without a reservation.
|
|
248
294
|
*/
|
|
249
295
|
check(evalCtx: api.CheckFlagRequestBody, key: string, options?: CheckOptions): Promise<CheckResult>;
|
|
250
296
|
/**
|
|
@@ -255,6 +301,10 @@ export declare class SchematicClient extends BaseClient {
|
|
|
255
301
|
* `actualQuantity × consumption_rate` from the company's real credit
|
|
256
302
|
* balance.
|
|
257
303
|
*
|
|
304
|
+
* A server-mode handle has no local hold to refund: the Track event carries
|
|
305
|
+
* the reservation id, and the server settles the hold (refunding the
|
|
306
|
+
* unspent slice) when it processes the event.
|
|
307
|
+
*
|
|
258
308
|
* If the work outlived the reservation's TTL and the sweeper already
|
|
259
309
|
* returned the hold to the lease, the local refund has happened but the
|
|
260
310
|
* usage must still be billed — so we emit the Track anyway (a "recovery"
|
|
@@ -269,7 +319,15 @@ export declare class SchematicClient extends BaseClient {
|
|
|
269
319
|
* accidental second `trackWithReservation`, collapses to a single billed
|
|
270
320
|
* event — across pods and process restarts, not just within one process.
|
|
271
321
|
*/
|
|
272
|
-
trackWithReservation(reservation: Reservation, actualQuantity: number, options?: TrackWithReservationOptions): Promise<void>;
|
|
322
|
+
trackWithReservation(reservation: Reservation | undefined, actualQuantity: number, options?: TrackWithReservationOptions): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* The Schematic company id for an evaluation context, resolved in the
|
|
325
|
+
* server's order: every supplied key/value pair is an ordinary entity key
|
|
326
|
+
* and gets looked up first; only when nothing matches is a value read as
|
|
327
|
+
* the company's own id, by its `comp_` prefix rather than by the name of
|
|
328
|
+
* the key it sits under. An account is free to define a key called `id`
|
|
329
|
+
* holding its own identifier, so the name alone settles nothing.
|
|
330
|
+
*/
|
|
273
331
|
private resolveCompanyId;
|
|
274
332
|
/**
|
|
275
333
|
* Send a non-blocking event to create or update companies and users.
|
|
@@ -286,6 +344,13 @@ export declare class SchematicClient extends BaseClient {
|
|
|
286
344
|
* @throws Will log error if event enqueueing fails
|
|
287
345
|
*/
|
|
288
346
|
track(body: api.EventBodyTrack, options?: TrackOptions): Promise<void>;
|
|
347
|
+
/**
|
|
348
|
+
* Enqueue a track event, optimistically bumping the cached company metric
|
|
349
|
+
* with it unless `updateMetrics` says not to. The bump is a local
|
|
350
|
+
* prediction of what the stream will push back, so it belongs only to an
|
|
351
|
+
* event that records usage the server has not already counted.
|
|
352
|
+
*/
|
|
353
|
+
private emitTrack;
|
|
289
354
|
/**
|
|
290
355
|
* Sets the default value for a specific feature flag
|
|
291
356
|
* @param flag - The feature flag identifier
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematichq/schematic-typescript-node",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
"crypto": false,
|
|
58
58
|
"timers": false
|
|
59
59
|
},
|
|
60
|
+
"resolutions": {
|
|
61
|
+
"sharp": "^0.35.4",
|
|
62
|
+
"undici": "7.29.0"
|
|
63
|
+
},
|
|
60
64
|
"packageManager": "yarn@1.22.22",
|
|
61
65
|
"engines": {
|
|
62
66
|
"node": ">=18.0.0"
|