@revturbine/sdk 0.11.19 → 0.11.21

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
@@ -27720,6 +27720,52 @@ type PlaybookOption = {
27720
27720
  exportedConfig: RevTurbineConfig;
27721
27721
  };
27722
27722
 
27723
+ /**
27724
+ * Effective entitlements — the ONE answer every SDK runtime uses (D-61,
27725
+ * Kent 2026-10-06).
27726
+ *
27727
+ * The shared evaluator (`deriveLocalEntitlementFromConfiguredRules`) decides
27728
+ * each entitlement from the Playbook + user context. An app may then enrich
27729
+ * that answer with its own data ("Entitlement Mirroring"): grants on
27730
+ * `UserContext.entitlements` and/or an app-registered entitlement provider.
27731
+ * The two are merged with a configurable precedence — provider level
27732
+ * (`precedence`, default `'app'`) with optional per-field overrides.
27733
+ *
27734
+ * Browser and server SDKs run this same function on the same inputs: the
27735
+ * browser result shapes interaction, the server result verifies it.
27736
+ *
27737
+ * An entitlement handle neither the Playbook nor the app knows is DENIED
27738
+ * (`entitlement_not_in_playbook`) and flagged `unknownHandle`, so the runtime
27739
+ * can warn and report it.
27740
+ */
27741
+
27742
+ /** Which side wins a merge: the app's own data, or the Playbook evaluation. */
27743
+ type EntitlementSource = 'app' | 'playbook';
27744
+ /** Fields that can be given their own precedence. `status` carries `allowed` and `reason` with it. */
27745
+ type EntitlementMergeField = 'status' | 'limit' | 'used' | 'remaining';
27746
+ interface EntitlementMergeOptions {
27747
+ /** Provider-level precedence. Default `'app'`: app-supplied data wins. */
27748
+ precedence?: EntitlementSource;
27749
+ /** Per-field overrides of `precedence`. */
27750
+ fields?: Partial<Record<EntitlementMergeField, EntitlementSource>>;
27751
+ }
27752
+ /** A mirrored grant on `UserContext.entitlements`: a boolean, or a grant-shaped record. */
27753
+ type MirroredEntitlement = boolean | {
27754
+ status?: string;
27755
+ allowed?: boolean;
27756
+ limit?: number;
27757
+ used?: number;
27758
+ remaining?: number;
27759
+ reason?: string;
27760
+ };
27761
+ /** The trial facts reverse-trial grants depend on (`UserTrialStatus` subset). */
27762
+ interface ReverseTrialView {
27763
+ in_trial?: boolean;
27764
+ trial_type?: string;
27765
+ /** The user's BASE plan while on a reverse trial. */
27766
+ plan_handle?: string;
27767
+ }
27768
+
27723
27769
  /**
27724
27770
  * User context lifecycle — pure functions for building, merging,
27725
27771
  * and deriving targeting state from user context + RevTurbineConfig.
@@ -27742,7 +27788,12 @@ interface UserContextSnapshot {
27742
27788
  */
27743
27789
  plan?: string | UserPlanContext;
27744
27790
  custom?: Record<string, JsonValue>;
27745
- entitlements?: Record<string, boolean>;
27791
+ /**
27792
+ * App-supplied entitlement data keyed by handle — a boolean or a grant
27793
+ * (D-61 Entitlement Mirroring). Merged with the Playbook evaluation by the
27794
+ * effective-entitlement core; flattened into segment traits as a boolean.
27795
+ */
27796
+ entitlements?: Record<string, MirroredEntitlement>;
27746
27797
  usage?: Record<string, UserUsageEntry>;
27747
27798
  personalization?: Record<string, JsonValue>;
27748
27799
  /** Canonical experiment-handle to variant-handle assignments. */
@@ -28023,6 +28074,13 @@ interface EntitlementUsageEntry {
28023
28074
  reset_date?: string;
28024
28075
  }
28025
28076
  interface EntitlementProviderState {
28077
+ /**
28078
+ * D-61: `'playbook_default'` marks entries the static adapter fills with a
28079
+ * blanket default policy. Those are NOT app data and never override the
28080
+ * Playbook evaluation; entries from any other provider are app-mirrored
28081
+ * data and merge with it per the runtime's precedence.
28082
+ */
28083
+ origin?: 'playbook_default';
28026
28084
  /**
28027
28085
  * All entitlement results keyed by entitlement handle.
28028
28086
  * Each entry carries status ('allowed' | 'limited' | 'denied') so the
@@ -28496,7 +28554,7 @@ interface DecisionEngineOptions {
28496
28554
  enableCapsEnforcement?: boolean;
28497
28555
  /** Enable category pipeline for local-mode priority ordering. Default: false. */
28498
28556
  enableCategoryPipelineLocalMode?: boolean;
28499
- /** Default entitlement policy when no provider or entry found. Default: 'allow'. */
28557
+ /** Default entitlement policy when no provider or entry found. Default: 'deny' (fail closed, D-61). */
28500
28558
  defaultEntitlementPolicy?: 'allow' | 'deny';
28501
28559
  }
28502
28560
  interface EntitlementCheckResult {
@@ -29391,6 +29449,20 @@ interface LocalRuntimeOptionsBase {
29391
29449
  impressionStore?: ImpressionHistoryStore;
29392
29450
  /** Decision engine behavior flags. */
29393
29451
  engineOptions?: DecisionEngineOptions;
29452
+ /**
29453
+ * D-61 Entitlement Mirroring: the user context's own entitlement data
29454
+ * (`UserContext.entitlements`), merged with the Playbook evaluation.
29455
+ */
29456
+ userEntitlements?: Record<string, MirroredEntitlement>;
29457
+ /** D-61: the user's trial status, so reverse-trial grants evaluate exactly as in the browser. */
29458
+ trialStatus?: ReverseTrialView;
29459
+ /** D-61: how app-supplied entitlement data merges with the Playbook result. Default: app wins. */
29460
+ entitlementMerge?: EntitlementMergeOptions;
29461
+ /**
29462
+ * Called once per entitlement handle that neither the Playbook nor the app
29463
+ * knows (it is denied). The runtime also logs a warning. Wire telemetry here.
29464
+ */
29465
+ onUnknownEntitlement?: (handle: string) => void;
29394
29466
  /** Interaction tracker options. */
29395
29467
  interactionOptions?: Partial<Pick<InteractionTrackerOptions, 'defaultDismissCooldownMs' | 'defaultRemindLaterMs'>>;
29396
29468
  }
@@ -29411,6 +29483,11 @@ declare class LocalRuntime {
29411
29483
  readonly impressionHistory: ImpressionHistory;
29412
29484
  private readonly playbook;
29413
29485
  private readonly registeredPlacements;
29486
+ private readonly userEntitlements;
29487
+ private readonly trialStatus;
29488
+ private readonly entitlementMerge;
29489
+ private readonly onUnknownEntitlement;
29490
+ private readonly reportedUnknownEntitlements;
29414
29491
  private userId;
29415
29492
  constructor(options: LocalRuntimeOptions);
29416
29493
  /**
@@ -29448,7 +29525,12 @@ declare class LocalRuntime {
29448
29525
  */
29449
29526
  getPlacement(config: RevTurbinePlacementRequestConfig$1): Promise<RevTurbinePlacementDecision | null>;
29450
29527
  /**
29451
- * Check entitlement access locally using RevTurbineConfig rules.
29528
+ * Check entitlement access locally (D-61): the shared evaluator decides
29529
+ * from the Playbook + user context, then app-mirrored data (user-context
29530
+ * grants and any app entitlement provider) merges per the runtime's
29531
+ * precedence (default: app wins). The browser SDK runs the same function on
29532
+ * the same inputs, so the server verifies exactly what the browser showed.
29533
+ * An entitlement nobody knows is denied, warned and reported.
29452
29534
  */
29453
29535
  checkEntitlement(handle: string, context?: RevTurbineEntitlementContext): Promise<EntitlementResult>;
29454
29536
  /**
@@ -29511,7 +29593,11 @@ declare class LocalRuntime {
29511
29593
  */
29512
29594
  private slotRecordForConfig;
29513
29595
  private buildPlacementResolver;
29514
- private deriveEntitlementFromConfig;
29596
+ /** Evaluator inputs from the resolved providers — the same facts the browser SDK uses. */
29597
+ private effectiveBase;
29598
+ /** App-mirrored data per handle: user-context grants plus non-default provider entries. */
29599
+ private appInputsByHandle;
29600
+ private reportUnknownEntitlement;
29515
29601
  }
29516
29602
 
29517
29603
  /**
@@ -31009,8 +31095,14 @@ interface RevTurbineUserContext extends Omit<UserContextInput, 'custom' | 'entit
31009
31095
  context_hash?: UserContextInput['context_hash'];
31010
31096
  /** Customer-defined fields for segmentation and personalization. */
31011
31097
  custom?: SdkTraits;
31012
- /** Feature entitlements granted by plan + entitlement rules. */
31013
- entitlements?: Record<string, boolean>;
31098
+ /**
31099
+ * App-supplied entitlement data, keyed by handle — a boolean or a grant
31100
+ * (`status`, `limit`, `used`). This is Entitlement Mirroring (D-61): it
31101
+ * merges with the Playbook evaluation, and by default the app's data wins.
31102
+ * Browser-supplied data shapes the UI only; the server re-check on the
31103
+ * same inputs stays authoritative for paid actions.
31104
+ */
31105
+ entitlements?: UserContextInput['entitlements'];
31014
31106
  /** Usage entries derived from credits / usage_limit entitlements, keyed by handle. */
31015
31107
  usage?: UserContextInput['usage'];
31016
31108
  /**
@@ -31493,6 +31585,14 @@ interface RevTurbineInitOptions {
31493
31585
  * Playbook.
31494
31586
  */
31495
31587
  placementBehavior?: Partial<RevTurbinePlacementBehaviorFlags>;
31588
+ /**
31589
+ * How app-supplied entitlement data (`userContext.entitlements`, an app
31590
+ * entitlement provider) merges with the Playbook evaluation (D-61).
31591
+ * Provider-level `precedence` defaults to `'app'`; `fields` overrides it
31592
+ * per field (`status`, `limit`, `used`, `remaining`). Use the same value
31593
+ * on your server SDK so verification matches.
31594
+ */
31595
+ entitlementMerge?: EntitlementMergeOptions;
31496
31596
  extension?: {
31497
31597
  enabled?: boolean;
31498
31598
  };
@@ -31614,6 +31714,11 @@ interface RevTurbineEventBatchingOptions {
31614
31714
  }
31615
31715
  interface RevTurbineLocalRuntimeData {
31616
31716
  placementDecisionsByPlacementId?: Record<string, RevTurbinePlacementDecision>;
31717
+ /**
31718
+ * @deprecated Ignored since 0.11.21 (D-39 / BL-0379): `getPlacement` is a
31719
+ * pure function of the user context and `localRuntime.playbook`, so
31720
+ * pre-decided outputs are never consulted. Removed in 0.12.0.
31721
+ */
31617
31722
  placementsByLookupKey?: Record<string, PlacementOutput | null>;
31618
31723
  entitlementByHandle?: Record<string, EntitlementResult>;
31619
31724
  userContextByUserId?: Record<string, UserTargetingContext>;
@@ -32267,6 +32372,16 @@ declare class RevTurbineCustomerSdk {
32267
32372
  private readonly policy;
32268
32373
  private readonly extensionEnabled;
32269
32374
  private readonly placementBehaviorOverrides;
32375
+ private readonly entitlementMerge;
32376
+ /** Entries from an app-registered entitlement provider (D-61 mirroring), from the last provider resolution. */
32377
+ private appProviderEntitlements;
32378
+ /** Plan from an app-registered plan provider (D-61) — wins over the user-context plan, as on the server. */
32379
+ private appProviderPlanHandle;
32380
+ /** Usage from an app entitlement provider (D-61), fed into the evaluation as on the server. */
32381
+ private appProviderUsage;
32382
+ /** Segment membership from an app segment provider (D-61), as a server runtime sees it. */
32383
+ private appProviderSegments;
32384
+ private readonly reportedUnknownEntitlements;
32270
32385
  private derivedPlacementBehaviorMemo;
32271
32386
  private readonly providerFailureSlotBehavior;
32272
32387
  private readonly uiPathResolvers;
@@ -32381,7 +32496,6 @@ declare class RevTurbineCustomerSdk {
32381
32496
  private pendingConversionPlan?;
32382
32497
  private usageBalances;
32383
32498
  private localDecisionsByPlacementId;
32384
- private localPlacementsByLookupKey;
32385
32499
  private localEntitlementsByHandle;
32386
32500
  private localUserContextsByUserId;
32387
32501
  /**
@@ -32682,12 +32796,6 @@ declare class RevTurbineCustomerSdk {
32682
32796
  */
32683
32797
  private hasEndpointOverride;
32684
32798
  private endpointFor;
32685
- private localPlacementLookupKey;
32686
- private localLookupMatchesConfig;
32687
- private localOutputMatchesConfig;
32688
- private applyCategoryConflictSuppression;
32689
- private resolveLocalPlacementFromCandidates;
32690
- private localPlacementForConfig;
32691
32799
  /**
32692
32800
  * The `placement_slots[]` entry the loaded Playbook authors for a request.
32693
32801
  *
@@ -32765,6 +32873,14 @@ declare class RevTurbineCustomerSdk {
32765
32873
  */
32766
32874
  private candidateCapGate;
32767
32875
  private recordPresentationCapRules;
32876
+ /**
32877
+ * D-60 + D-61: the resolver's gates read the SAME effective entitlements
32878
+ * `checkEntitlement` returns — the shared evaluation merged with
32879
+ * app-mirrored data — for every handle the Playbook, the user context or an
32880
+ * app provider knows. A gate slot's reported `entitlement_status` still
32881
+ * wins inside the resolver.
32882
+ */
32883
+ private withSlotEntitlementStatus;
32768
32884
  private slotIdForRecord;
32769
32885
  private hydratePresentationCaps;
32770
32886
  private persistPresentationCaps;
@@ -32941,22 +33057,25 @@ declare class RevTurbineCustomerSdk {
32941
33057
  * @public
32942
33058
  */
32943
33059
  setApiBranding(branding: BrandingConfig | undefined): void;
33060
+ /**
33061
+ * The effective entitlement (D-61): the shared core evaluator decides from
33062
+ * the Playbook + user context, then app-mirrored data merges per
33063
+ * `entitlementMerge` (default: app wins). The server SDKs run the same
33064
+ * function on the same inputs, so a server re-check verifies exactly this.
33065
+ * An entitlement nobody knows is denied, warned once and reported.
33066
+ */
32944
33067
  private deriveLocalEntitlementFromConfiguredRules;
32945
33068
  /**
32946
- * Inline adapter — given a UserTrialStatus + the tenant's
32947
- * reverse_trial_rules from RevTurbineConfig, derive the inputs that
32948
- * close plan 43 TASK-2. Returns undefined fields when the user
32949
- * isn't on an active reverse trial, when no rule matches, or when
32950
- * the rule has no entitlements_during_trial[].
32951
- *
32952
- * Why inline (not calling scaffold's deriveReverseTrialGrants):
32953
- * the scaffold helper takes a `TrialInstance` (DB-side state) and
32954
- * matches by `rule_id`. The SDK only holds `UserTrialStatus` (the
32955
- * transient runtime shape) and doesn't see the rule_id. We match
32956
- * by `fallback_plan_id === plan_handle` instead — that's the
32957
- * single configured rule the user can be on per spec §2.4.2.
33069
+ * D-61: snapshot what the app's own providers say — plan, entitlement
33070
+ * entries, usage — so the browser evaluates on exactly the inputs a server
33071
+ * runtime with the same providers would. A static adapter's blanket
33072
+ * defaults are not app data.
32958
33073
  */
32959
- private resolveReverseTrialGrants;
33074
+ private captureAppProviderState;
33075
+ /** D-61: resolve the app's providers before an entitlement check (cached per provider TTL). */
33076
+ private refreshAppProviderState;
33077
+ /** D-61: an unknown entitlement handle is denied; say so once, locally and in telemetry. */
33078
+ private reportUnknownEntitlement;
32960
33079
  /**
32961
33080
  * Return the SDK-resolved targeting snapshot for the active user.
32962
33081
  *