@schematichq/schematic-typescript-node 1.6.1 → 1.6.3

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.
Files changed (82) hide show
  1. package/README.md +2 -0
  2. package/dist/api/resources/billing/client/requests/CreateInvoiceRequestBody.d.ts +1 -0
  3. package/dist/api/resources/credits/client/requests/AcquireCreditLeaseRequestBody.d.ts +1 -0
  4. package/dist/api/resources/credits/client/requests/ExtendCreditLeaseRequestBody.d.ts +3 -0
  5. package/dist/api/resources/entitlements/client/requests/CreateBillingLinkedPlanEntitlementRequestBody.d.ts +5 -1
  6. package/dist/api/resources/entitlements/client/requests/CreatePlanEntitlementRequestBody.d.ts +5 -1
  7. package/dist/api/resources/entitlements/client/requests/UpdatePlanEntitlementRequestBody.d.ts +5 -1
  8. package/dist/api/resources/features/client/requests/CheckAndReserveFlagRequestBody.d.ts +4 -2
  9. package/dist/api/types/BillingArrearsCadence.d.ts +1 -0
  10. package/dist/api/types/BillingCreditGrantReason.d.ts +3 -0
  11. package/dist/api/types/BillingCreditResponseData.d.ts +1 -0
  12. package/dist/api/types/BillingPlanCreditGrantBillingMode.d.ts +5 -0
  13. package/dist/api/types/BillingPlanCreditGrantPriceTierResponseData.d.ts +10 -0
  14. package/dist/api/types/BillingPlanCreditGrantResponseData.d.ts +12 -0
  15. package/dist/api/types/ChangeSubscriptionInternalRequestBody.d.ts +2 -0
  16. package/dist/api/types/ChangeSubscriptionRequestBody.d.ts +2 -0
  17. package/dist/api/types/CompanyFeatureUsageExportMetadataVisibleColumnsItem.d.ts +1 -0
  18. package/dist/api/types/CompanyPlanCreditGrantView.d.ts +3 -0
  19. package/dist/api/types/CreateBillingPlanCreditGrantRequestBody.d.ts +11 -1
  20. package/dist/api/types/CreateEntitlementInBundleRequestBody.d.ts +5 -1
  21. package/dist/api/types/CreditEventLedgerResponseData.d.ts +2 -0
  22. package/dist/api/types/CreditGrantPriceTierRequestBody.d.ts +8 -0
  23. package/dist/api/types/CreditTransferReason.d.ts +7 -0
  24. package/dist/api/types/InvoiceRequestBody.d.ts +1 -0
  25. package/dist/api/types/InvoiceResponseData.d.ts +2 -0
  26. package/dist/api/types/ManagePlanRequest.d.ts +2 -0
  27. package/dist/api/types/PlanCreditGrantView.d.ts +3 -0
  28. package/dist/api/types/PlanEntitlementResponseData.d.ts +5 -1
  29. package/dist/api/types/PreviewSubscriptionFinanceResponseData.d.ts +2 -0
  30. package/dist/api/types/RulesengineComparableOperator.d.ts +11 -0
  31. package/dist/api/types/RulesengineCondition.d.ts +1 -1
  32. package/dist/api/types/UpcomingInvoiceResponseData.d.ts +2 -0
  33. package/dist/api/types/UpdateBillingPlanCreditGrantRequestBody.d.ts +11 -1
  34. package/dist/api/types/UsageBasedEntitlementRequestBody.d.ts +5 -1
  35. package/dist/api/types/UsageBasedEntitlementResponseData.d.ts +1 -1
  36. package/dist/api/types/index.d.ts +5 -0
  37. package/dist/cache/redis.d.ts +11 -0
  38. package/dist/credits/check.d.ts +10 -5
  39. package/dist/credits/index.d.ts +3 -3
  40. package/dist/credits/lease-manager.d.ts +74 -2
  41. package/dist/credits/lease-store.d.ts +27 -11
  42. package/dist/credits/redis-lease-store.d.ts +2 -2
  43. package/dist/credits/types.d.ts +1 -0
  44. package/dist/index.js +12 -10
  45. package/dist/serialization/resources/billing/client/requests/CreateInvoiceRequestBody.d.ts +1 -0
  46. package/dist/serialization/resources/credits/client/requests/ExtendCreditLeaseRequestBody.d.ts +1 -0
  47. package/dist/serialization/resources/entitlements/client/requests/CreateBillingLinkedPlanEntitlementRequestBody.d.ts +4 -0
  48. package/dist/serialization/resources/entitlements/client/requests/CreatePlanEntitlementRequestBody.d.ts +4 -0
  49. package/dist/serialization/resources/entitlements/client/requests/UpdatePlanEntitlementRequestBody.d.ts +4 -0
  50. package/dist/serialization/resources/features/client/requests/CheckAndReserveFlagRequestBody.d.ts +1 -0
  51. package/dist/serialization/types/BillingArrearsCadence.d.ts +1 -1
  52. package/dist/serialization/types/BillingCreditGrantReason.d.ts +1 -1
  53. package/dist/serialization/types/BillingCreditResponseData.d.ts +2 -0
  54. package/dist/serialization/types/BillingPlanCreditGrantBillingMode.d.ts +7 -0
  55. package/dist/serialization/types/BillingPlanCreditGrantPriceTierResponseData.d.ts +12 -0
  56. package/dist/serialization/types/BillingPlanCreditGrantResponseData.d.ts +10 -0
  57. package/dist/serialization/types/ChangeSubscriptionInternalRequestBody.d.ts +1 -0
  58. package/dist/serialization/types/ChangeSubscriptionRequestBody.d.ts +1 -0
  59. package/dist/serialization/types/CompanyFeatureUsageExportMetadataVisibleColumnsItem.d.ts +1 -1
  60. package/dist/serialization/types/CompanyPlanCreditGrantView.d.ts +5 -0
  61. package/dist/serialization/types/CreateBillingPlanCreditGrantRequestBody.d.ts +8 -0
  62. package/dist/serialization/types/CreateEntitlementInBundleRequestBody.d.ts +4 -0
  63. package/dist/serialization/types/CreditEventLedgerResponseData.d.ts +3 -0
  64. package/dist/serialization/types/CreditGrantPriceTierRequestBody.d.ts +11 -0
  65. package/dist/serialization/types/CreditTransferReason.d.ts +7 -0
  66. package/dist/serialization/types/InvoiceRequestBody.d.ts +1 -0
  67. package/dist/serialization/types/InvoiceResponseData.d.ts +1 -0
  68. package/dist/serialization/types/ManagePlanRequest.d.ts +1 -0
  69. package/dist/serialization/types/PlanCreditGrantView.d.ts +5 -0
  70. package/dist/serialization/types/PlanEntitlementResponseData.d.ts +4 -0
  71. package/dist/serialization/types/PreviewSubscriptionFinanceResponseData.d.ts +1 -0
  72. package/dist/serialization/types/RulesengineComparableOperator.d.ts +7 -0
  73. package/dist/serialization/types/RulesengineCondition.d.ts +2 -2
  74. package/dist/serialization/types/UpcomingInvoiceResponseData.d.ts +1 -0
  75. package/dist/serialization/types/UpdateBillingPlanCreditGrantRequestBody.d.ts +8 -0
  76. package/dist/serialization/types/UsageBasedEntitlementRequestBody.d.ts +4 -0
  77. package/dist/serialization/types/index.d.ts +5 -0
  78. package/dist/wasm/rulesengine.d.ts +1 -0
  79. package/dist/wasm/rulesengine.js +34 -4
  80. package/dist/wasm/rulesengine_bg.wasm.d.ts +2 -0
  81. package/dist/wrapper.d.ts +50 -16
  82. package/package.json +3 -3
@@ -5,6 +5,7 @@ export const __wbg_rulesenginejs_free: (a: number, b: number) => void;
5
5
  export const alloc: (a: number) => number;
6
6
  export const checkFlag: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
7
7
  export const checkFlagCombined: (a: number, b: number) => number;
8
+ export const checkFlagsCombined: (a: number, b: number) => number;
8
9
  export const dealloc: (a: number, b: number) => void;
9
10
  export const getCurrentMetricPeriodStartForCalendarMetricPeriod: (a: number) => bigint;
10
11
  export const getCurrentMetricPeriodStartForCompanyBillingSubscription: (a: number, b: number) => bigint;
@@ -15,6 +16,7 @@ export const getResultJsonLength: () => number;
15
16
  export const get_version_key_wasm: () => number;
16
17
  export const rulesenginejs_checkFlag: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
17
18
  export const rulesenginejs_checkFlagWithOptions: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number, number, number];
19
+ export const rulesenginejs_checkFlags: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
18
20
  export const rulesenginejs_getVersionKey: (a: number) => [number, number];
19
21
  export const rulesenginejs_new: () => number;
20
22
  export const setCurrentTimeMillis: (a: bigint) => void;
package/dist/wrapper.d.ts CHANGED
@@ -66,27 +66,40 @@ export interface SchematicOptions {
66
66
  */
67
67
  creditLeases?: CreditLeaseConfig;
68
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
+ */
69
80
  export interface CheckFlagOptions {
70
81
  /** Default value to return on error. Can be a boolean or a function returning a boolean. If not provided, uses configured flag defaults */
71
82
  defaultValue?: boolean | (() => boolean);
72
83
  /** The maximum time to wait for a response in milliseconds */
73
84
  timeoutMs?: number;
74
85
  /**
75
- * Preflight inputs forwarded to the WASM rules engine's
76
- * `checkFlagWithOptions`. The engine picks the most specific knob for each
77
- * condition it evaluates. Only applied when the flag is evaluated locally
78
- * (DataStream); the REST fallback path does not support preflight and
79
- * ignores these. No reservation is issued — for lease-backed gating use
80
- * `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.
81
89
  */
82
- /** Pre-computed per-credit-id cost. Highest precedence for credit-balance gates. */
83
90
  creditCost?: Record<string, number>;
84
- /** Single integer quantity applied to whatever numeric condition is being evaluated. */
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
+ */
85
97
  usage?: number;
86
98
  /**
87
99
  * Simulated quantity scoped to a specific event subtype. Preferred over
88
100
  * `usage` when the subtype is known. Deliberately singular: one check
89
- * preflights one action.
101
+ * preflights one action. `quantity` rounds up the same way `usage` does,
102
+ * and zero has no effect.
90
103
  */
91
104
  eventUsage?: {
92
105
  eventSubtype: string;
@@ -149,6 +162,8 @@ export declare class SchematicClient extends BaseClient {
149
162
  private prewarmResolveTimeoutMs;
150
163
  private creditLeaseMode?;
151
164
  private serverReservationTTL;
165
+ private closing;
166
+ private readonly pendingPrewarms;
152
167
  /**
153
168
  * Creates a new instance of the SchematicClient
154
169
  * @param opts - Configuration options for the client
@@ -222,6 +237,11 @@ export declare class SchematicClient extends BaseClient {
222
237
  * are still drawing on — doing so would refund the grant server-side and
223
238
  * pull the balance out from under them. Shared leases reclaim themselves:
224
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.
225
245
  * @returns Promise that resolves when everything has been stopped
226
246
  */
227
247
  close(): Promise<void>;
@@ -239,10 +259,10 @@ export declare class SchematicClient extends BaseClient {
239
259
  */
240
260
  prewarm(evalCtx: api.CheckFlagRequestBody, creditTypeIds: string[]): Promise<void>;
241
261
  /**
242
- * Like `resolveCompanyId` but actively fetches the company over the
243
- * datastream when only secondary keys are supplied, warming the cache as a
244
- * side effect. Returns the resolved id, or undefined if the company never
245
- * 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.
246
266
  *
247
267
  * `identify` does not push a company into the datastream cache — companies
248
268
  * are only streamed in response to a request. So we call `getCompany`
@@ -269,9 +289,8 @@ export declare class SchematicClient extends BaseClient {
269
289
  * through to a plain flag check and returns `{allowed: value}` with no
270
290
  * reservation, byte-compatible with `checkFlag` semantics. The caller's
271
291
  * preflight (`usage` / `eventSubtype`) is still threaded through the plain
272
- * check, so any client-side evaluation path (datastream, replicator)
273
- * gates on the post-call balance — just without a reservation. Only the
274
- * REST fallback ignores preflight.
292
+ * check, so every evaluation path (datastream, replicator, REST) gates on
293
+ * the post-call balance — just without a reservation.
275
294
  */
276
295
  check(evalCtx: api.CheckFlagRequestBody, key: string, options?: CheckOptions): Promise<CheckResult>;
277
296
  /**
@@ -301,6 +320,14 @@ export declare class SchematicClient extends BaseClient {
301
320
  * event — across pods and process restarts, not just within one process.
302
321
  */
303
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
+ */
304
331
  private resolveCompanyId;
305
332
  /**
306
333
  * Send a non-blocking event to create or update companies and users.
@@ -317,6 +344,13 @@ export declare class SchematicClient extends BaseClient {
317
344
  * @throws Will log error if event enqueueing fails
318
345
  */
319
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;
320
354
  /**
321
355
  * Sets the default value for a specific feature flag
322
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.1",
3
+ "version": "1.6.3",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -59,7 +59,7 @@
59
59
  },
60
60
  "resolutions": {
61
61
  "sharp": "^0.35.4",
62
- "undici": "7.29.0"
62
+ "undici": "7.29.1"
63
63
  },
64
64
  "packageManager": "yarn@1.22.22",
65
65
  "engines": {
@@ -69,7 +69,7 @@
69
69
  "license": "MIT",
70
70
  "resolutions": {
71
71
  "sharp": "^0.35.4",
72
- "undici": "7.29.0"
72
+ "undici": "7.29.1"
73
73
  },
74
74
  "files": [
75
75
  "dist/**/*.js",