@revturbine/sdk 0.11.5 → 0.11.6

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/dist/index.d.ts CHANGED
@@ -17171,11 +17171,14 @@ interface RevTurbineTreatmentInteractionInput {
17171
17171
  * `PlacementOutput.rule_id` — projected onto the `placement_interaction`
17172
17172
  * clickstream payload as `rule_handle` (BL-0182).
17173
17173
  *
17174
- * Unlike its neighbours this does NOT reach the wire
17175
- * `TreatmentInteractionInputSchema` / `placement_presentations`: that path is
17176
- * column-shaped and would need a datasource migration. The clickstream
17177
- * carries payload fields inside a JSON column, so the rule slice for
17178
- * interactions is readable the moment producers send it.
17174
+ * It reaches the wire `TreatmentInteractionInputSchema` too, as of BL-0200.
17175
+ * It deliberately did not under BL-0182: that path is column-shaped and the
17176
+ * rule would have needed a datasource migration, while the clickstream
17177
+ * carries payload fields inside a JSON column and was readable at once.
17178
+ * `placement_exposure_attribution.rule_handle` exists now (web ledger 015),
17179
+ * so the base exposure row records the rule the exposure was DECIDED by
17180
+ * rather than waiting for attribution to reconstruct one when a conversion
17181
+ * lands — which is what makes presentation-grain rule cuts servable.
17179
17182
  *
17180
17183
  * Omitted, never sent empty, when no decision is in scope — a bare
17181
17184
  * `trackTreatmentInteraction` caller supplies no rule, and absence is what
@@ -21339,6 +21342,12 @@ declare class RevTurbineCustomerSdk {
21339
21342
  * redundant segment re-evaluation.
21340
21343
  */
21341
21344
  private lastServerContextHash?;
21345
+ /**
21346
+ * The plan move an optimistic `convert()` made ahead of the server (BL-0004),
21347
+ * held only until a `client-context` read stops reporting the old plan. See
21348
+ * {@link dropStalePostConversionPlan}.
21349
+ */
21350
+ private pendingConversionPlan?;
21342
21351
  private usageBalances;
21343
21352
  private localDecisionsByPlacementId;
21344
21353
  private localPlacementsByLookupKey;
@@ -22483,12 +22492,16 @@ declare class RevTurbineCustomerSdk {
22483
22492
  /** Map the client-safe context response into a UserContext patch (plan 157). */
22484
22493
  private mapClientSafeContext;
22485
22494
  /**
22486
- * Apply a server-derived UserContext patch (plan 157) — mirrors setUserContext
22487
- * but accepts a partial. The patch's RevTurbine-authoritative fields (trial,
22488
- * billing signals) overlay the held context; undefined fields are skipped by
22489
- * the merge, so app-set values are never nulled.
22495
+ * Apply a UserContext patch — mirrors setUserContext but accepts a partial.
22496
+ * RevTurbine-authoritative fields (trial, billing signals, server plan)
22497
+ * overlay the held context; undefined fields are skipped by the merge, so
22498
+ * app-set values are never nulled.
22499
+ *
22500
+ * Two callers: the server client-context fetch (plan 157) and the optimistic
22501
+ * post-conversion plan move (BL-0004). Both notify subscribers, which is what
22502
+ * makes mounted slots and gates re-resolve.
22490
22503
  */
22491
- private applyServerContextPatch;
22504
+ private applyUserContextPatch;
22492
22505
  /**
22493
22506
  * Record that a placement was rendered to the user. Plan 43 TASK-9.
22494
22507
  *
@@ -22665,13 +22678,73 @@ declare class RevTurbineCustomerSdk {
22665
22678
  */
22666
22679
  snooze(outputId: string, seconds?: number): Promise<void>;
22667
22680
  /**
22668
- * Record a confirmed CTA completion and retire the decision's placement
22669
- * permanently — future calls to `getPlacementDecision` for it will not
22670
- * return it again.
22681
+ * Record a confirmed CTA completion, then reload the UserContext so every
22682
+ * mounted surface re-decides against the plan the user just converted to.
22683
+ *
22684
+ * Conversion is **not** a suppression: it writes no cooldown and no permanent
22685
+ * retirement (spec §"interaction" table; Kent's plan 254 D-9 ruling). What
22686
+ * makes a converted upgrade banner leave the screen is the user no longer
22687
+ * matching it — so a conversion that did not refresh the context left the
22688
+ * placement mounted until something else happened to re-resolve it. Kent,
22689
+ * 2026-09-25 (BL-0004): *"Converting should trigger a reloading of UserContext
22690
+ * with the new plan/billing state the user has converted to."*
22691
+ *
22692
+ * Ordering, and why it is this way round:
22693
+ *
22694
+ * 1. The interaction is recorded (analytics + attribution), as before.
22695
+ * 2. **Optimistically**, locally: when the converted output's CTA names a
22696
+ * target plan (`cta_path.plan_handle`), the held context moves to that plan
22697
+ * immediately. Billing truth arrives by Stripe webhook, so
22698
+ * `GET /api/sdk/client-context` can still report the OLD plan for seconds
22699
+ * after a successful checkout — waiting for it would leave the upgrade
22700
+ * prompt on screen exactly when the user has just paid.
22701
+ * 3. Subscribers are notified either way — a conversion whose CTA names no
22702
+ * plan still re-decides mounted slots and re-checks mounted gates, which is
22703
+ * what turns a plan change the host applied itself into a re-render.
22704
+ * 4. **Then** the server refresh (`fetchClientContext()`), which overlays the
22705
+ * RevTurbine-authoritative trial / billing-health / plan fields and
22706
+ * notifies again if it changed anything. It is best-effort and never
22707
+ * throws, so awaiting it cannot fail a conversion; with no client-session
22708
+ * minter configured it is a no-op and the optimistic state stands.
22709
+ *
22710
+ * Mounted `PlacementController`s re-decide and mounted `EntitlementGate`s
22711
+ * re-check through their `watchUserContext()` subscriptions — which the React
22712
+ * bindings attach for you. Re-resolution emits the normal lifecycle events
22713
+ * once per final decision; the transient states emit nothing.
22714
+ * `PlacementController.ctaComplete()` is unchanged and remains the
22715
+ * component-level path.
22671
22716
  *
22672
22717
  * @public
22673
22718
  */
22674
22719
  convert(outputId: string): Promise<void>;
22720
+ /**
22721
+ * The BL-0004 post-conversion context reload: optimistic local plan move,
22722
+ * then the server refresh. See {@link convert} for the ordering rationale.
22723
+ */
22724
+ private reloadUserContextAfterConversion;
22725
+ /**
22726
+ * Keep a stale server plan from undoing an optimistic conversion (BL-0004).
22727
+ *
22728
+ * Billing truth arrives by Stripe webhook, so a `client-context` read that
22729
+ * races the webhook reports the PRE-conversion plan — and the server plan
22730
+ * deliberately overlays the app-supplied one (plan 179 TASK-1), so applying
22731
+ * that read verbatim would put the upgrade prompt straight back on screen
22732
+ * seconds after the user paid.
22733
+ *
22734
+ * So while a conversion is pending, a server plan equal to the plan converted
22735
+ * AWAY from is dropped — only the plan fields, never the trial or billing-health
22736
+ * signals, which are authoritative regardless. Any other value (the new plan,
22737
+ * or a third one the user was moved to out-of-band) clears the pending state
22738
+ * and applies, so this can suppress at most the one value it was created for
22739
+ * and cannot outlive the lag it exists to cover.
22740
+ */
22741
+ private dropStalePostConversionPlan;
22742
+ /**
22743
+ * The display name the loaded Playbook gives a plan handle, else the handle.
22744
+ * Keeps an optimistic plan move from putting a raw handle in front of a user
22745
+ * when the Playbook already knows the plan's name.
22746
+ */
22747
+ private planNameForHandle;
22675
22748
  /**
22676
22749
  * Emit a canonical trigger event. There is no in-SDK consumer that matches
22677
22750
  * on trigger names — the shipped behavior is ingest to `events_clickstream`
@@ -23135,12 +23208,41 @@ declare class PlacementController {
23135
23208
  private _awaitingConfig;
23136
23209
  private _configRetries;
23137
23210
  private _playbookUnsubscribe;
23211
+ private _userContextUnsubscribe;
23138
23212
  constructor(sdk: RevTurbineCustomerSdk, options: PlacementControllerOptions);
23139
23213
  /**
23140
- * Stop listening for Playbook loads. Idempotent; call it when the owning
23141
- * component unmounts (`usePlacement` does).
23214
+ * Stop listening for Playbook loads and user-context changes. Idempotent; call
23215
+ * it when the owning component unmounts (`usePlacement` does).
23142
23216
  */
23143
23217
  dispose(): void;
23218
+ /**
23219
+ * Drop only the Playbook-load subscription — the within-load-cycle teardown
23220
+ * (BL-0177). A mounted controller keeps watching the user context (BL-0004).
23221
+ */
23222
+ private unsubscribePlaybook;
23223
+ /**
23224
+ * Re-decide whenever the user context changes (BL-0004).
23225
+ *
23226
+ * The counterpart to {@link EntitlementGate.watchUserContext}, and the reason
23227
+ * `sdk.convert()` now removes a converted placement in place: conversion writes
23228
+ * no suppression — eligibility is a function of the user's CURRENT plan and
23229
+ * targeting — so the only thing that can take a converted upgrade banner off
23230
+ * screen is a re-decide against the reloaded context. Without this the
23231
+ * placement stayed mounted until something else happened to re-resolve it, and
23232
+ * the host had to call `refresh()` itself or use the component's
23233
+ * `ctaComplete()` (the limitation plan 236 TASK-13 recorded).
23234
+ *
23235
+ * Only re-decides a controller that has already resolved something: before the
23236
+ * first `load()` there is nothing on screen to be stale, and firing then would
23237
+ * turn every startup `identify()` into a duplicate decision.
23238
+ *
23239
+ * Calls `load()` rather than `refresh()` on purpose — `refresh()` clears
23240
+ * impression/exposure tracking, so a context change would re-credit a
23241
+ * presentation the user never saw again.
23242
+ *
23243
+ * Returns an unsubscribe function; {@link dispose} also drops it.
23244
+ */
23245
+ watchUserContext(): () => void;
23144
23246
  /**
23145
23247
  * Is this decision a race against a Playbook load rather than a verdict?
23146
23248
  *
@@ -23358,12 +23460,18 @@ declare class EntitlementGate {
23358
23460
  private _awaitedResult;
23359
23461
  private _configRetries;
23360
23462
  private _playbookUnsubscribe;
23463
+ private _userContextUnsubscribe;
23361
23464
  constructor(sdk: RevTurbineCustomerSdk, options: EntitlementGateOptions);
23362
23465
  /**
23363
- * Stop listening for Playbook loads. Idempotent; call it when the owning
23364
- * component unmounts (`useEntitlement` does).
23466
+ * Stop listening for Playbook loads and user-context changes. Idempotent; call
23467
+ * it when the owning component unmounts (`useEntitlement` does).
23365
23468
  */
23366
23469
  dispose(): void;
23470
+ /**
23471
+ * Drop only the Playbook-load subscription — the within-check-cycle teardown
23472
+ * (BL-0179). A mounted gate keeps watching the user context (BL-0004).
23473
+ */
23474
+ private unsubscribePlaybook;
23367
23475
  /** Current state snapshot. */
23368
23476
  get state(): EntitlementGateState;
23369
23477
  /** Convenience: `true` when the entitlement is allowed. */
@@ -23463,8 +23571,13 @@ declare class EntitlementGate {
23463
23571
  * `check()` there is nothing on screen to be stale, and firing then would
23464
23572
  * turn every `identify()` at startup into a redundant evaluation.
23465
23573
  *
23574
+ * `sdk.convert()` reloads the UserContext (BL-0004), so this is also what
23575
+ * flips a mounted `useCan` gate to allowed after a conversion.
23576
+ *
23466
23577
  * Returns an unsubscribe function. Call it when the gate is discarded —
23467
23578
  * without that, a gate outlives its consumer and keeps re-checking.
23579
+ * Idempotent: a second call returns the first subscription rather than
23580
+ * orphaning it, and {@link dispose} drops it too.
23468
23581
  */
23469
23582
  watchUserContext(): () => void;
23470
23583
  private notify;