@revturbine/sdk 0.2.84 → 0.2.85
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/headless.d.ts +138 -2
- package/dist/headless.js +2 -2
- package/dist/headless.js.map +1 -1
- package/dist/index.d.ts +157 -18
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +5334 -0
- package/dist/server.js +3 -0
- package/dist/server.js.map +1 -0
- package/dist/types/web-sdk/headless.d.ts +1 -0
- package/dist/types/web-sdk/headless.d.ts.map +1 -1
- package/dist/types/web-sdk/providers/basic-experiment-provider.d.ts +71 -0
- package/dist/types/web-sdk/providers/basic-experiment-provider.d.ts.map +1 -0
- package/dist/types/web-sdk/providers/index.d.ts +3 -1
- package/dist/types/web-sdk/providers/index.d.ts.map +1 -1
- package/dist/types/web-sdk/providers/types.d.ts +1 -1
- package/dist/types/web-sdk/providers/types.d.ts.map +1 -1
- package/dist/types/web-sdk/react/useEntitlement.d.ts +11 -12
- package/dist/types/web-sdk/react/useEntitlement.d.ts.map +1 -1
- package/dist/types/web-sdk/react/usePlacement.d.ts +12 -6
- package/dist/types/web-sdk/react/usePlacement.d.ts.map +1 -1
- package/dist/types/web-sdk/server/index.d.ts +173 -0
- package/dist/types/web-sdk/server/index.d.ts.map +1 -0
- package/dist/types/web-sdk/views.d.ts +65 -0
- package/dist/types/web-sdk/views.d.ts.map +1 -0
- package/package.json +5 -1
|
@@ -42,6 +42,7 @@ export { PlacementController, EntitlementGate, SdkSession, initRevTurbine, entit
|
|
|
42
42
|
export type { ChangeListener, PlacementControllerOptions, PlacementControllerState, EntitlementGateOptions, EntitlementGateState, SdkSessionOptions, } from './controllers';
|
|
43
43
|
export { createRevTurbineApiClient, ApiError as RevTurbineApiError, } from './api-client';
|
|
44
44
|
export type { RevTurbineApiClient, RevTurbineApiClientConfig, paths as RevTurbineApiPaths, } from './api-client';
|
|
45
|
+
export type { EntitlementView, PlacementView } from './views';
|
|
45
46
|
export { isServer, isBrowser } from './env';
|
|
46
47
|
export { InMemoryStorage, BrowserStorage, resolvePersistentStorage, resolveSessionStorage, } from './storage';
|
|
47
48
|
export type { RevTurbineStorage } from './storage';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless.d.ts","sourceRoot":"","sources":["../../../headless.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,cAAc,aAAa,CAAC;AAG5B,OAAO,EACL,8BAA8B,GAC/B,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,cAAc,EACd,0BAA0B,EAC1B,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAG3B,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,YAAY,EAAE,cAAc,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAiC5F,OAAO,EACL,kCAAkC,EAClC,uBAAuB,EACvB,8BAA8B,EAC9B,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,cAAc,EACd,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,cAAc,EACd,0BAA0B,EAC1B,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,yBAAyB,EACzB,QAAQ,IAAI,kBAAkB,GAC/B,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,m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
|
+
* Deliberately basic, and deliberately opt-in: nothing registers this for you.
|
|
5
|
+
* A customer with their own experimentation tool registers an adapter that
|
|
6
|
+
* reads *their* assignments instead and loses nothing — the third-party path is
|
|
7
|
+
* first-class, not a fallback. RevTurbine does not own the split.
|
|
8
|
+
*
|
|
9
|
+
* Weights live here, in SDK code, rather than in the Playbook. Assignment is
|
|
10
|
+
* the provider's job, so the config that drives it is client-side
|
|
11
|
+
* configuration, not authored monetization config.
|
|
12
|
+
*/
|
|
13
|
+
import type { ExperimentProvider } from '@revt-eng/core';
|
|
14
|
+
/** One experiment's arms, and optionally how much of the population sees it. */
|
|
15
|
+
export interface BasicBucketerExperiment {
|
|
16
|
+
/**
|
|
17
|
+
* Either an equal split across the listed variant handles, or explicit
|
|
18
|
+
* relative weights. Weights need not sum to anything in particular — they are
|
|
19
|
+
* normalized — so `{ control: 1, variant_b: 3 }` is a 25/75 split.
|
|
20
|
+
*
|
|
21
|
+
* A variant weighted 0 (or negative) is excluded rather than made
|
|
22
|
+
* unreachable-but-present, so removing an arm and zeroing it behave the same.
|
|
23
|
+
*/
|
|
24
|
+
variants: readonly string[] | Readonly<Record<string, number>>;
|
|
25
|
+
/**
|
|
26
|
+
* Fraction of subjects enrolled at all, 0..1. Default 1 (everyone).
|
|
27
|
+
*
|
|
28
|
+
* A subject outside it is reported as NOT ENROLLED — the experiment is simply
|
|
29
|
+
* absent from the assignment map, which is distinct from being assigned to a
|
|
30
|
+
* control arm. That distinction is the whole point of a holdout: control is a
|
|
31
|
+
* measured arm, unenrolled is not in the experiment.
|
|
32
|
+
*/
|
|
33
|
+
exposure?: number;
|
|
34
|
+
}
|
|
35
|
+
export interface BasicBucketerOptions {
|
|
36
|
+
/** Keyed by experiment handle — the canonical, version-stable identifier. */
|
|
37
|
+
experiments: Readonly<Record<string, BasicBucketerExperiment>>;
|
|
38
|
+
/**
|
|
39
|
+
* The subject to bucket on. A function is re-read on every resolve, so a
|
|
40
|
+
* later `setUserContext` takes effect; a bare string pins one subject.
|
|
41
|
+
*
|
|
42
|
+
* With no stable subject there is no assignment: bucketing an anonymous or
|
|
43
|
+
* empty id would hand the same person a different arm on the next load and
|
|
44
|
+
* silently poison the results. Absent beats wrong.
|
|
45
|
+
*/
|
|
46
|
+
subject: string | (() => string | undefined | null);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Assign one subject to one experiment, or `undefined` for not-enrolled.
|
|
50
|
+
*
|
|
51
|
+
* Exported for testing and for callers who want the decision without the
|
|
52
|
+
* provider wrapper. Pure: same inputs always give the same arm, with no
|
|
53
|
+
* storage, no clock and no randomness involved.
|
|
54
|
+
*/
|
|
55
|
+
export declare function bucketSubject(subject: string, experimentHandle: string, experiment: BasicBucketerExperiment): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Build the built-in bucketer. Register it explicitly to switch it on:
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* initRevTurbine({
|
|
61
|
+
* domainProviders: [
|
|
62
|
+
* createBasicExperimentProvider({
|
|
63
|
+
* subject: () => currentUserId,
|
|
64
|
+
* experiments: { pricing_test: { variants: ['control', 'variant_b'] } },
|
|
65
|
+
* }),
|
|
66
|
+
* ],
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function createBasicExperimentProvider(options: BasicBucketerOptions): ExperimentProvider;
|
|
71
|
+
//# sourceMappingURL=basic-experiment-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-experiment-provider.d.ts","sourceRoot":"","sources":["../../../../providers/basic-experiment-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAA2B,MAAM,gBAAgB,CAAC;AAElF,gFAAgF;AAChF,MAAM,WAAW,uBAAuB;IACtC;;;;;;;OAOG;IACH,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/D;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,6EAA6E;IAC7E,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAC/D;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;CACrD;AAsCD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,uBAAuB,GAClC,MAAM,GAAG,SAAS,CAyBpB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,oBAAoB,GAC5B,kBAAkB,CAmBpB"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export type { DomainProviderName, DomainProvider, AnyDomainProvider, ResolvedProviderContext, ResolvedDomainType, TraitsNamespace, PlanProvider, PlanProviderState, EntitlementProvider, EntitlementProviderState, EntitlementUsageEntry, SegmentProvider, SegmentProviderState, ContentProvider, ContentProviderState, MessageBlockSnapshot, PlacementPayloadSnapshot, RuleProvider, RuleProviderState, EntitlementRuleSnapshot, PlanRuleSnapshot, TraitsProvider, TraitsProviderState, TrialStatusTraits, TrialStatusProvider, UsageTraits, UsageTraitsProvider, ThemeProvider, ThemeProviderState, EventConsumer, EventConsumerProvider, EventConsumerProviderState, CtaHandler, CtaHandlerMap, CtaHandlerProvider, CtaHandlerProviderState, } from './types';
|
|
1
|
+
export type { DomainProviderName, DomainProvider, AnyDomainProvider, ResolvedProviderContext, ResolvedDomainType, TraitsNamespace, PlanProvider, PlanProviderState, EntitlementProvider, EntitlementProviderState, EntitlementUsageEntry, SegmentProvider, SegmentProviderState, ExperimentProvider, ExperimentProviderState, ContentProvider, ContentProviderState, MessageBlockSnapshot, PlacementPayloadSnapshot, RuleProvider, RuleProviderState, EntitlementRuleSnapshot, PlanRuleSnapshot, TraitsProvider, TraitsProviderState, TrialStatusTraits, TrialStatusProvider, UsageTraits, UsageTraitsProvider, ThemeProvider, ThemeProviderState, EventConsumer, EventConsumerProvider, EventConsumerProviderState, CtaHandler, CtaHandlerMap, CtaHandlerProvider, CtaHandlerProviderState, } from './types';
|
|
2
2
|
export { DomainProviderRegistry } from './registry';
|
|
3
3
|
export { ServerUserContextProvider, SERVER_TRAITS_DOMAIN, } from './server-user-context-provider';
|
|
4
4
|
export type { ServerUserContextSnapshot } from './server-user-context-provider';
|
|
5
|
+
export { createBasicExperimentProvider, bucketSubject, } from './basic-experiment-provider';
|
|
6
|
+
export type { BasicBucketerOptions, BasicBucketerExperiment, } from './basic-experiment-provider';
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../providers/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAElB,eAAe,EAEf,YAAY,EACZ,iBAAiB,EAEjB,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EAErB,eAAe,EACf,oBAAoB,EAEpB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EAExB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAEhB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EAEnB,aAAa,EACb,kBAAkB,EAElB,aAAa,EACb,qBAAqB,EACrB,0BAA0B,EAE1B,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAKpD,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../providers/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAElB,eAAe,EAEf,YAAY,EACZ,iBAAiB,EAEjB,mBAAmB,EACnB,wBAAwB,EACxB,qBAAqB,EAErB,eAAe,EACf,oBAAoB,EAEpB,kBAAkB,EAClB,uBAAuB,EAEvB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EAExB,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAEhB,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EAEnB,aAAa,EACb,kBAAkB,EAElB,aAAa,EACb,qBAAqB,EACrB,0BAA0B,EAE1B,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAKpD,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAKhF,OAAO,EACL,6BAA6B,EAC7B,aAAa,GACd,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC"}
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This file maintains backward compatibility for web-sdk consumers.
|
|
5
5
|
* All canonical type definitions live in core/providers/types.ts.
|
|
6
6
|
*/
|
|
7
|
-
export type { TraitsNamespace, DomainProviderName, DomainProvider, PlanProviderState, PlanProvider, EntitlementUsageEntry, EntitlementProviderState, EntitlementProvider, SegmentProviderState, SegmentProvider, MessageBlockSnapshot, PlacementPayloadSnapshot, ContentProviderState, ContentProvider, EntitlementRuleSnapshot, PlanRuleSnapshot, RuleProviderState, RuleProvider, TraitsProviderState, TraitsProvider, TrialStatusTraits, TrialStatusProvider, UsageTraits, UsageTraitsProvider, ThemeProviderState, ThemeProvider, EventConsumer, EventConsumerProviderState, EventConsumerProvider, CtaHandler, CtaHandlerMap, CtaHandlerProviderState, CtaHandlerProvider, ResolvedProviderContext, AnyDomainProvider, ResolvedDomainType, } from '@revt-eng/core';
|
|
7
|
+
export type { TraitsNamespace, DomainProviderName, DomainProvider, PlanProviderState, PlanProvider, EntitlementUsageEntry, EntitlementProviderState, EntitlementProvider, SegmentProviderState, SegmentProvider, ExperimentProviderState, ExperimentProvider, MessageBlockSnapshot, PlacementPayloadSnapshot, ContentProviderState, ContentProvider, EntitlementRuleSnapshot, PlanRuleSnapshot, RuleProviderState, RuleProvider, TraitsProviderState, TraitsProvider, TrialStatusTraits, TrialStatusProvider, UsageTraits, UsageTraitsProvider, ThemeProviderState, ThemeProvider, EventConsumer, EventConsumerProviderState, EventConsumerProvider, CtaHandler, CtaHandlerMap, CtaHandlerProviderState, CtaHandlerProvider, ResolvedProviderContext, AnyDomainProvider, ResolvedDomainType, } from '@revt-eng/core';
|
|
8
8
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../providers/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../providers/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,aAAa,EACb,0BAA0B,EAC1B,qBAAqB,EACrB,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RevTurbineEntitlementContext, RevTurbinePlacementRequestConfig } from '../customer-side';
|
|
2
|
+
import type { EntitlementView } from '../views';
|
|
2
3
|
export interface UseEntitlementOptions {
|
|
3
4
|
/** The entitlement handle to check (e.g. 'brand_kit', 'mp4_download'). */
|
|
4
5
|
handle: string;
|
|
@@ -17,21 +18,19 @@ export interface UseEntitlementOptions {
|
|
|
17
18
|
*/
|
|
18
19
|
gatePlacementRequest?: Omit<RevTurbinePlacementRequestConfig, 'entitlementHandle'>;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The client-side entitlement result: the resolved decision
|
|
23
|
+
* ({@link EntitlementView}) plus the lifecycle a hook resolves it through.
|
|
24
|
+
*
|
|
25
|
+
* The lifecycle half is what makes this distinct from the server shape. A
|
|
26
|
+
* server caller awaits its decision and therefore has no loading state and
|
|
27
|
+
* nothing to re-run mid-render.
|
|
28
|
+
*/
|
|
29
|
+
export interface UseEntitlementResult extends EntitlementView {
|
|
21
30
|
/** Whether the entitlement check is in progress. */
|
|
22
31
|
isLoading: boolean;
|
|
23
32
|
/** Error message if the check failed. */
|
|
24
33
|
error: string | null;
|
|
25
|
-
/** The entitlement result from the SDK. `null` until resolved. */
|
|
26
|
-
result: EntitlementResult | null;
|
|
27
|
-
/** Convenience: `true` when the entitlement is allowed. */
|
|
28
|
-
allowed: boolean;
|
|
29
|
-
/** Convenience: `true` when usage is limited (partially exhausted). */
|
|
30
|
-
limited: boolean;
|
|
31
|
-
/** Convenience: `true` when the entitlement is denied. */
|
|
32
|
-
denied: boolean;
|
|
33
|
-
/** Resolved gated placement when `denied` and `autoGate` are active. */
|
|
34
|
-
gatedPlacement: PlacementOutput | null;
|
|
35
34
|
/** Re-run the entitlement check. */
|
|
36
35
|
recheck: () => Promise<void>;
|
|
37
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntitlement.d.ts","sourceRoot":"","sources":["../../../../react/useEntitlement.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useEntitlement.d.ts","sourceRoot":"","sources":["../../../../react/useEntitlement.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,4BAA4B,EAC5B,gCAAgC,EACjC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMhD,MAAM,WAAW,qBAAqB;IACpC,0EAA0E;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,OAAO,CAAC,EAAE,4BAA4B,CAAC;IACvC,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,gCAAgC,EAAE,mBAAmB,CAAC,CAAC;CACpF;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,oDAAoD;IACpD,SAAS,EAAE,OAAO,CAAC;IACnB,yCAAyC;IACzC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,oCAAoC;IACpC,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,OAAO,EACP,SAAgB,EAChB,QAAgB,EAChB,oBAAoB,GACrB,EAAE,qBAAqB,GAAG,oBAAoB,CAqD9C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type RevTurbinePlacementConfig, type RevTurbineSurfaceSlotConfig, type
|
|
1
|
+
import { type RevTurbinePlacementConfig, type RevTurbineSurfaceSlotConfig, type RevTurbinePlacementDecisionOverrides, type RevTurbineContextMode } from '../customer-side';
|
|
2
|
+
import type { PlacementView } from '../views';
|
|
2
3
|
import type { PlacementExposureMode } from '../controllers';
|
|
3
4
|
import { type ExposureBasis } from '../telemetry';
|
|
4
5
|
/**
|
|
@@ -41,13 +42,18 @@ export type UsePlacementOptions = {
|
|
|
41
42
|
/**
|
|
42
43
|
* Result returned by the {@link usePlacement} hook.
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
/**
|
|
46
|
+
* The client-side placement result: the resolved decision
|
|
47
|
+
* ({@link PlacementView}) plus the lifecycle and interaction surface a hook
|
|
48
|
+
* adds on top.
|
|
49
|
+
*
|
|
50
|
+
* Everything beyond {@link PlacementView} is inherently client-side — a loading
|
|
51
|
+
* state, interaction callbacks, and viewport-exposure wiring have no meaning to
|
|
52
|
+
* a server caller that awaits a decision and renders once.
|
|
53
|
+
*/
|
|
54
|
+
export type UsePlacementResult = PlacementView & {
|
|
45
55
|
isLoading: boolean;
|
|
46
56
|
error: string;
|
|
47
|
-
placementId: string;
|
|
48
|
-
visible: boolean;
|
|
49
|
-
decision: RevTurbinePlacementDecision | null;
|
|
50
|
-
content: RevTurbinePlacementContent['content'] | null;
|
|
51
57
|
refresh: () => Promise<void>;
|
|
52
58
|
dismiss: (cooldownMs?: number) => Promise<void>;
|
|
53
59
|
snooze: (seconds?: number) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePlacement.d.ts","sourceRoot":"","sources":["../../../../react/usePlacement.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,KAAK,
|
|
1
|
+
{"version":3,"file":"usePlacement.d.ts","sourceRoot":"","sources":["../../../../react/usePlacement.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,2BAA2B,EAChC,KAAK,oCAAoC,EACzC,KAAK,qBAAqB,EAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAGnE;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,2DAA2D;IAC3D,SAAS,CAAC,EAAE,yBAAyB,CAAC;IACtC,yEAAyE;IACzE,WAAW,CAAC,EAAE,2BAA2B,CAAC;IAC1C,oEAAoE;IACpE,MAAM,CAAC,EAAE,M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;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,WAAW,EACX,MAAM,EACN,WAAoB,EACpB,SAAS,EACT,MAAM,EACN,KAAK,EACL,QAAe,EACf,mBAAmB,EACnB,iBAAiB,GAClB,EAAE,mBAAmB,GAAG,kBAAkB,CA4G1C"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @revt-eng/web-sdk/server
|
|
3
|
+
*
|
|
4
|
+
* Server-side entitlement and placement decisions for React Server Components
|
|
5
|
+
* (plan 186 TASK-3).
|
|
6
|
+
*
|
|
7
|
+
* A React hook cannot run in a Server Component: every module under `react/`
|
|
8
|
+
* opens with `'use client'`, so importing one from the server graph yields an
|
|
9
|
+
* opaque client reference rather than a callable. This module is the server
|
|
10
|
+
* half — the same decisions, awaited instead of subscribed to.
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* // app/page.tsx — a Server Component, no 'use client'
|
|
14
|
+
* const rt = createServerClient({ tenantId, playbook });
|
|
15
|
+
* const { denied } = await getEntitlement(rt, 'brand_kit', { user: { id: userId } });
|
|
16
|
+
* return denied ? <UpgradePrompt /> : <BrandKitEditor />;
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Three properties are deliberate and load-bearing:
|
|
20
|
+
*
|
|
21
|
+
* - **Local by default.** An RSC tree re-renders per request, so a network hop
|
|
22
|
+
* per decision is a latency tax the client SDK never paid. With a `playbook`
|
|
23
|
+
* the decision resolves in-process and keeps working when the control plane
|
|
24
|
+
* is unreachable. Remote is available by explicit configuration.
|
|
25
|
+
* - **Fail closed.** Any evaluation failure resolves denied / not-visible and
|
|
26
|
+
* never throws into the render tree — a control-plane outage must not turn
|
|
27
|
+
* into an error boundary, and must never accidentally grant paid access.
|
|
28
|
+
* - **No lifecycle fields.** The returned {@link EntitlementView} carries no
|
|
29
|
+
* `isLoading` and no `recheck`: the value is awaited, so it is always
|
|
30
|
+
* decided and there is nothing to re-run mid-render. Synthesizing them would
|
|
31
|
+
* be a lie the type system then endorses.
|
|
32
|
+
*
|
|
33
|
+
* The credential passed here — a long-lived `server` api-token — must never
|
|
34
|
+
* reach the browser. It is accepted only by {@link createServerClient}, is
|
|
35
|
+
* never placed on a returned value, and never appears in the hydration payload
|
|
36
|
+
* handed to `RevTurbineProvider`.
|
|
37
|
+
*
|
|
38
|
+
* Plan: docs/dev-lifecycle/inprogress/186-server-rendering-sdk-and-api-token-management.md
|
|
39
|
+
*/
|
|
40
|
+
import { type ConfigArtifact } from '../config-artifact';
|
|
41
|
+
import type { EntitlementView, PlacementView } from '../views';
|
|
42
|
+
import type { RevTurbineEntitlementContext } from '../customer-side';
|
|
43
|
+
/**
|
|
44
|
+
* The end user a server-side decision is evaluated for.
|
|
45
|
+
*
|
|
46
|
+
* There is no ambient user on the server — a Server Component has no provider
|
|
47
|
+
* to read from — so the caller states it explicitly. Plan 186 TASK-4 adds an
|
|
48
|
+
* optional request-scoped form that supplies this implicitly.
|
|
49
|
+
*/
|
|
50
|
+
export interface ServerUser {
|
|
51
|
+
/** The end-user identifier decisions are evaluated for. */
|
|
52
|
+
id: string;
|
|
53
|
+
/** The user's current plan handle, used to resolve entitlement rules. */
|
|
54
|
+
planHandle?: string;
|
|
55
|
+
/** Targeting traits for segment evaluation. */
|
|
56
|
+
traits?: Record<string, string | number | boolean>;
|
|
57
|
+
}
|
|
58
|
+
/** How a {@link RevTurbineServerClient} reaches its decisions. */
|
|
59
|
+
export type ServerTransport = 'local' | 'remote';
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for {@link createServerClient}.
|
|
62
|
+
*
|
|
63
|
+
* Supply a `playbook` for local mode (the default). Supply `endpoint` +
|
|
64
|
+
* `apiToken` for remote mode, which is selected automatically when no playbook
|
|
65
|
+
* is present and can be forced with `transport: 'remote'`.
|
|
66
|
+
*/
|
|
67
|
+
export interface ServerClientOptions {
|
|
68
|
+
/** Tenant the decisions belong to. */
|
|
69
|
+
tenantId: string;
|
|
70
|
+
/**
|
|
71
|
+
* The bundled Playbook. Its presence selects local mode, where decisions
|
|
72
|
+
* resolve in-process with no network call.
|
|
73
|
+
*/
|
|
74
|
+
playbook?: ConfigArtifact;
|
|
75
|
+
/** Target environment for Playbooks that predate environment stamping. */
|
|
76
|
+
environmentId?: string;
|
|
77
|
+
/**
|
|
78
|
+
* A long-lived `server` api-token, for remote mode.
|
|
79
|
+
*
|
|
80
|
+
* Server-only. Never return it to the browser, never place it in props, and
|
|
81
|
+
* never embed it in a hydration payload.
|
|
82
|
+
*/
|
|
83
|
+
apiToken?: string;
|
|
84
|
+
/** Control-plane origin, for remote mode. */
|
|
85
|
+
endpoint?: string;
|
|
86
|
+
/** Force a transport. Defaults to `'local'` whenever a `playbook` is given. */
|
|
87
|
+
transport?: ServerTransport;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A server-side decision client.
|
|
91
|
+
*
|
|
92
|
+
* Create one per process (or per request) with {@link createServerClient} and
|
|
93
|
+
* pass it to {@link getEntitlement} / {@link getPlacement}. Holds no per-user
|
|
94
|
+
* state, so it is safe to share across concurrent requests.
|
|
95
|
+
*/
|
|
96
|
+
export declare class RevTurbineServerClient {
|
|
97
|
+
#private;
|
|
98
|
+
/** Tenant the decisions belong to. */
|
|
99
|
+
readonly tenantId: string;
|
|
100
|
+
/** How this client reaches its decisions. */
|
|
101
|
+
readonly transport: ServerTransport;
|
|
102
|
+
constructor(options: ServerClientOptions);
|
|
103
|
+
/**
|
|
104
|
+
* A runtime bound to one user.
|
|
105
|
+
*
|
|
106
|
+
* Built per call rather than once per client: `LocalRuntime` takes its
|
|
107
|
+
* `userId` at construction and `createStaticProviders` resolves entitlement
|
|
108
|
+
* rules against a specific `planHandle`, so a shared instance would evaluate
|
|
109
|
+
* every request against whichever user built it. (This is also why the
|
|
110
|
+
* existing `LocalEvaluationServer`, whose runtime is constructed once with
|
|
111
|
+
* `userId: '__server__'`, cannot answer a per-user entitlement question.)
|
|
112
|
+
* Plan 186 TASK-4 memoizes this per request via React `cache()`.
|
|
113
|
+
*/
|
|
114
|
+
private runtimeFor;
|
|
115
|
+
/** @internal Resolve one entitlement, fail-closed. */
|
|
116
|
+
_entitlement(handle: string, user: ServerUser, context?: RevTurbineEntitlementContext): Promise<EntitlementView>;
|
|
117
|
+
/** @internal Resolve one placement, fail-closed. */
|
|
118
|
+
_placement(placementId: string, user: ServerUser): Promise<PlacementView>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create a server-side decision client.
|
|
122
|
+
*
|
|
123
|
+
* @param options - Transport and tenant configuration. A `playbook` selects
|
|
124
|
+
* local mode; `endpoint` + `apiToken` select remote.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import playbook from '../revturbine.playbook.json';
|
|
129
|
+
* export const rt = createServerClient({ tenantId: 'tn_acme', playbook });
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare function createServerClient(options: ServerClientOptions): RevTurbineServerClient;
|
|
133
|
+
/**
|
|
134
|
+
* Resolve one entitlement for one user, from a Server Component.
|
|
135
|
+
*
|
|
136
|
+
* Never throws: an evaluation failure resolves denied, so a control-plane
|
|
137
|
+
* outage cannot become an error boundary and cannot accidentally grant access.
|
|
138
|
+
*
|
|
139
|
+
* Gate paid UI on `denied` rather than on `!allowed` — a `limited` result still
|
|
140
|
+
* grants access when the evaluator permits it.
|
|
141
|
+
*
|
|
142
|
+
* @param client - From {@link createServerClient}.
|
|
143
|
+
* @param handle - The entitlement handle, e.g. `'brand_kit'`.
|
|
144
|
+
* @param input - The user to evaluate for, and optional usage context.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```tsx
|
|
148
|
+
* const { denied } = await getEntitlement(rt, 'brand_kit', { user: { id: userId } });
|
|
149
|
+
* if (denied) return <UpgradePrompt />;
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function getEntitlement(client: RevTurbineServerClient, handle: string, input: {
|
|
153
|
+
user: ServerUser;
|
|
154
|
+
context?: RevTurbineEntitlementContext;
|
|
155
|
+
}): Promise<EntitlementView>;
|
|
156
|
+
/**
|
|
157
|
+
* Resolve one placement decision for one user, from a Server Component.
|
|
158
|
+
*
|
|
159
|
+
* Never throws: an evaluation failure resolves not-visible, so a failed
|
|
160
|
+
* decision hides the surface rather than breaking the page.
|
|
161
|
+
*
|
|
162
|
+
* The result carries no interaction callbacks — `dismiss`, `ctaClick` and
|
|
163
|
+
* viewport exposure are inherently client-side. Render the decision on the
|
|
164
|
+
* server and let a client component own the interactions.
|
|
165
|
+
*
|
|
166
|
+
* @param client - From {@link createServerClient}.
|
|
167
|
+
* @param input - The placement to resolve and the user to resolve it for.
|
|
168
|
+
*/
|
|
169
|
+
export declare function getPlacement(client: RevTurbineServerClient, input: {
|
|
170
|
+
placementId: string;
|
|
171
|
+
user: ServerUser;
|
|
172
|
+
}): Promise<PlacementView>;
|
|
173
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAKH,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,KAAK,EAEV,4BAA4B,EAE7B,MAAM,kBAAkB,CAAC;AAE1B;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAA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AAO,CAAC,eAAe,CAAC,CAE1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,sBAAsB,EAC9B,KAAK,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAC/C,OAAO,CAAC,aAAa,CAAC,CAExB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @revt-eng/web-sdk/views
|
|
3
|
+
*
|
|
4
|
+
* The decision shapes a caller reads, independent of *how* the decision was
|
|
5
|
+
* obtained (plan 186 TASK-1).
|
|
6
|
+
*
|
|
7
|
+
* A React hook resolves a decision over time, so its result carries lifecycle
|
|
8
|
+
* fields — `isLoading`, `error`, a re-run callback. A server-rendered caller
|
|
9
|
+
* awaits the decision, so it has none of those: by the time it holds a value,
|
|
10
|
+
* the value is final. What both share is the decision itself, and that shared
|
|
11
|
+
* part lives here.
|
|
12
|
+
*
|
|
13
|
+
* This module deliberately contains **types only and no runtime imports**, and
|
|
14
|
+
* deliberately sits outside `react/`. Every module under `react/` opens with
|
|
15
|
+
* `'use client'`, so a React Server Component importing one receives an opaque
|
|
16
|
+
* client reference rather than a usable value — the server binding could not
|
|
17
|
+
* reuse these shapes if they stayed there.
|
|
18
|
+
*
|
|
19
|
+
* Plan: docs/dev-lifecycle/inprogress/186-server-rendering-sdk-and-api-token-management.md
|
|
20
|
+
*/
|
|
21
|
+
import type { EntitlementResult, PlacementOutput, RevTurbinePlacementContent, RevTurbinePlacementDecision } from './customer-side';
|
|
22
|
+
/**
|
|
23
|
+
* A resolved entitlement decision.
|
|
24
|
+
*
|
|
25
|
+
* The three booleans are conveniences over {@link EntitlementView.result} and
|
|
26
|
+
* are mutually exclusive once resolved. Note that `allowed` and `limited` are
|
|
27
|
+
* not opposites: a `limited` result still grants access when the evaluator
|
|
28
|
+
* permits it, so gate paywall UI on `denied`, never on `!allowed`.
|
|
29
|
+
*
|
|
30
|
+
* Callers that need to distinguish "denied" from "not yet decided" want the
|
|
31
|
+
* client-side {@link UseEntitlementResult}, whose `isLoading` carries that
|
|
32
|
+
* distinction. On the server the question does not arise — the value is awaited,
|
|
33
|
+
* so it is always decided.
|
|
34
|
+
*/
|
|
35
|
+
export interface EntitlementView {
|
|
36
|
+
/** The full entitlement result from the evaluator. `null` until resolved. */
|
|
37
|
+
result: EntitlementResult | null;
|
|
38
|
+
/** `true` when the entitlement is allowed outright. */
|
|
39
|
+
allowed: boolean;
|
|
40
|
+
/** `true` when access is granted but the balance is approaching its limit. */
|
|
41
|
+
limited: boolean;
|
|
42
|
+
/** `true` when the entitlement is denied. */
|
|
43
|
+
denied: boolean;
|
|
44
|
+
/** The upgrade surface to render on denial, when one was resolved. */
|
|
45
|
+
gatedPlacement: PlacementOutput | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A resolved placement decision.
|
|
49
|
+
*
|
|
50
|
+
* Carries what to render and whether to render it — not how to interact with
|
|
51
|
+
* it. Interaction callbacks (`dismiss`, `ctaClick`, …) and viewport-exposure
|
|
52
|
+
* wiring are inherently client-side and live on
|
|
53
|
+
* {@link UsePlacementResult} instead.
|
|
54
|
+
*/
|
|
55
|
+
export interface PlacementView {
|
|
56
|
+
/** The resolved placement identifier. */
|
|
57
|
+
placementId: string;
|
|
58
|
+
/** Whether the placement should be rendered. */
|
|
59
|
+
visible: boolean;
|
|
60
|
+
/** The full decision from the engine. `null` until resolved. */
|
|
61
|
+
decision: RevTurbinePlacementDecision | null;
|
|
62
|
+
/** Resolved content with personalization tokens expanded. `null` until resolved. */
|
|
63
|
+
content: RevTurbinePlacementContent['content'] | null;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=views.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.d.ts","sourceRoot":"","sources":["../../../views.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,0BAA0B,EAC1B,2BAA2B,EAC5B,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjC,uDAAuD;IACvD,OAAO,EAAE,OAAO,CAAC;IACjB,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,6CAA6C;IAC7C,MAAM,EAAE,OAAO,CAAC;IAChB,sEAAsE;IACtE,cAAc,EAAE,eAAe,GAAG,IAAI,CAAC;CACxC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,OAAO,EAAE,OAAO,CAAC;IACjB,gEAAgE;IAChE,QAAQ,EAAE,2BAA2B,GAAG,IAAI,CAAC;IAC7C,oFAAoF;IACpF,OAAO,EAAE,0BAA0B,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;CACvD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revturbine/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.85",
|
|
4
4
|
"description": "RevTurbine customer-facing SDK — placement decisioning, entitlement checks, and usage tracking.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.12.0",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"import": "./dist/headless.js",
|
|
17
17
|
"types": "./dist/headless.d.ts"
|
|
18
18
|
},
|
|
19
|
+
"./server": {
|
|
20
|
+
"import": "./dist/server.js",
|
|
21
|
+
"types": "./dist/server.d.ts"
|
|
22
|
+
},
|
|
19
23
|
"./source": "./index.ts",
|
|
20
24
|
"./source/headless": "./headless.ts"
|
|
21
25
|
},
|