@revturbine/sdk 0.2.22 → 0.2.24

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.
@@ -16,21 +16,36 @@ export type AccessGateSurfaceSlotProps = {
16
16
  id: string;
17
17
  /** Optional human-readable slot label used for analytics/debugging. */
18
18
  name?: string;
19
+ /**
20
+ * Shorthand entitlement gate — `can="brand_kit"` is equivalent to
21
+ * `check={{ entitlement: 'brand_kit' }}`, mirroring the `useCan('brand_kit')`
22
+ * hook. Merged with `check` when both are supplied. Provide `can` or `check`.
23
+ */
24
+ can?: string;
19
25
  /**
20
26
  * One or more access checks to evaluate before granting access.
21
27
  *
22
28
  * - `{ entitlement: 'brand_kit' }` — check an entitlement handle.
23
29
  * - `{ usage: 'core_credits', threshold: 80 }` — check a usage percentage threshold.
24
30
  *
25
- * When an array is passed, access is denied if **any** check fails.
31
+ * When an array is passed, access is denied if **any** check fails. Optional
32
+ * when `can` is provided.
26
33
  */
27
- check: AccessGateCheck | AccessGateCheck[];
34
+ check?: AccessGateCheck | AccessGateCheck[];
28
35
  /**
29
36
  * Placement to display when access is denied.
30
37
  * The slot fetches the gated placement from the decision engine.
31
38
  * If no placement matches, `deniedFallback` is shown.
32
39
  */
33
40
  deniedFallback?: React.ReactNode;
41
+ /**
42
+ * Rendered instead of `children` when the entitlement is `limited` — access is
43
+ * still granted, the usage/credit balance is just running low. Use it for a soft
44
+ * "running low" state (e.g. the feature plus a warning). When omitted, `limited`
45
+ * renders `children` normally, since a `limited` user is still entitled; pass
46
+ * `null` to render nothing.
47
+ */
48
+ limitedFallback?: React.ReactNode;
34
49
  /** Content to render when access is granted. */
35
50
  children: React.ReactNode;
36
51
  /**
@@ -52,23 +67,31 @@ export type AccessGateSurfaceSlotProps = {
52
67
  style?: React.CSSProperties;
53
68
  };
54
69
  /**
55
- * Access-gate surface slot renders children when entitled, or a gated
56
- * placement when access is denied.
70
+ * Merge the `can` shorthand and the `check` prop into the effective check list:
71
+ * `can="x"` becomes `{ entitlement: 'x' }`, and `check` is appended as-is.
72
+ * Exported for unit testing.
73
+ */
74
+ export declare function resolveGateChecks(can: string | undefined, check: AccessGateCheck | AccessGateCheck[] | undefined): AccessGateCheck[];
75
+ /**
76
+ * Access-gate surface slot — renders children when entitled (allowed *or*
77
+ * `limited`), or a gated placement when access is `denied`.
57
78
  *
58
- * Checks entitlements and/or usage thresholds. On failure, displays the
59
- * configured gated placement (or `deniedFallback` if no placement matches).
60
- * On success, renders `children` unmodified.
79
+ * Checks entitlements and/or usage thresholds. On denial, displays the configured
80
+ * gated placement (or `deniedFallback` if no placement matches). On success,
81
+ * renders `children` — or `limitedFallback` when the entitlement is `limited`.
61
82
  *
62
83
  * @example
63
84
  * ```tsx
64
- * <AccessGateSurfaceSlot
65
- * id="export-gate"
66
- * check={{ entitlement: 'mp4_download' }}
67
- * deniedFallback={<span>Upgrade to export</span>}
68
- * >
85
+ * // `can` shorthand — mirrors useCan('mp4_download')
86
+ * <AccessGateSurfaceSlot id="export-gate" can="mp4_download" deniedFallback={<span>Upgrade to export</span>}>
69
87
  * <ExportButton />
70
88
  * </AccessGateSurfaceSlot>
71
89
  *
90
+ * // soft-warn while still granting access when the balance runs low
91
+ * <AccessGateSurfaceSlot id="credits-gate" can="core_credits" limitedFallback={<LowBalanceNotice />}>
92
+ * <RecordButton />
93
+ * </AccessGateSurfaceSlot>
94
+ *
72
95
  * <AccessGateSurfaceSlot
73
96
  * id="usage-gate"
74
97
  * check={[
@@ -81,7 +104,7 @@ export type AccessGateSurfaceSlotProps = {
81
104
  * </AccessGateSurfaceSlot>
82
105
  * ```
83
106
  */
84
- export declare function AccessGateSurfaceSlot({ id, name, check, children, deniedFallback, surfaceTemplateIds, metadata, onDenied, ...options }: AccessGateSurfaceSlotProps): React.JSX.Element | null;
107
+ export declare function AccessGateSurfaceSlot({ id, name, can, check, children, deniedFallback, limitedFallback, surfaceTemplateIds, metadata, onDenied, ...options }: AccessGateSurfaceSlotProps): React.JSX.Element | null;
85
108
  export declare namespace AccessGateSurfaceSlot {
86
109
  var displayName: string;
87
110
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AccessGateSurfaceSlot.d.ts","sourceRoot":"","sources":["../../../../placements/AccessGateSurfaceSlot.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EACV,qBAAqB,EACrB,4BAA4B,EAC5B,oCAAoC,EAEpC,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAEtE,OAAO,EAAE,0BAA0B,EAAE,CAAC;AAItC,MAAM,MAAM,eAAe,GACvB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,4BAA4B,CAAA;CAAE,GAC/D;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,MAAM,MAAM,0BAA0B,GAAG;IACvC,uDAAuD;IACvD,EAAE,EAAE,MAAM,CAAC;IACX,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,KAAK,EAAE,eAAe,GAAG,eAAe,EAAE,CAAC;IAE3C;;;;OAIG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAEjC,gDAAgD;IAChD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAE1B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,WAAW,CAAC,EAAE,qBAAqB,CAAC;IACpC,SAA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AAM,GAAG,SAAS,EACvB,KAAK,EAAE,eAAe,GAAG,eAAe,EAAE,GAAG,SAAS,GACrD,eAAe,EAAE,CAKnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,EAAE,EACF,IAAI,EACJ,GAAG,EACH,KAAK,EACL,QAAQ,EACR,cAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,GAAG,OAAO,EACX,EAAE,0BAA0B,4BA+E5B;yBA3Fe,qBAAqB"}
@@ -1,22 +1,47 @@
1
1
  import { type UseEntitlementOptions, type UseEntitlementResult } from './useEntitlement';
2
2
  /**
3
- * Verb-parity alias of {@link useEntitlement} — the reactive counterpart to the
4
- * imperative `rt.can(handle)`. Takes the entitlement handle positionally (matching
3
+ * Result of {@link useCan} — the entitlement check reduced to the shape a `can`
4
+ * question actually needs.
5
+ */
6
+ export interface UseCanResult {
7
+ /**
8
+ * `true` when the user may proceed. This is `allowed || limited` (equivalently,
9
+ * not `denied`): a `limited` entitlement still grants access — it just means the
10
+ * usage/credit balance is running low. Fail-open, matching the SDK: `can` is also
11
+ * `true` before the check resolves and if the entitlement service is unreachable.
12
+ * Gate on `!can` to block; never gate on `!allowed` (that would also block
13
+ * `limited` users who are still entitled).
14
+ */
15
+ can: boolean;
16
+ /**
17
+ * `true` when access is granted but the balance is approaching its limit (the
18
+ * "running low" state). Surface a soft warning while still allowing the action.
19
+ */
20
+ limited: boolean;
21
+ /**
22
+ * The full entitlement result (`status`, `reason`, `current_tier`, `placement`,
23
+ * …), or `null` until the check resolves — the escape hatch for details beyond
24
+ * `can` / `limited`.
25
+ */
26
+ result: UseEntitlementResult['result'];
27
+ }
28
+ /**
29
+ * Reactive counterpart to the imperative `rt.can(handle)` — the entitlement check
30
+ * as a `can` question. Takes the entitlement handle positionally (matching
5
31
  * `rt.can('handle')`), plus the same options {@link useEntitlement} accepts, and
6
- * returns the identical reactive result (`allowed` / `denied` / `limited` /
7
- * `result` / `recheck` / …).
32
+ * returns a curated `{ can, limited, result }`.
8
33
  *
9
- * Use this when you want the hook name to read like the `can` verb; it is a thin
10
- * wrapper with no behavioral difference from `useEntitlement({ handle })`.
34
+ * For the full reactive surface (`allowed` / `denied` / `isLoading` / `error` /
35
+ * `gatedPlacement` / `recheck`), use {@link useEntitlement} directly.
11
36
  *
12
37
  * @example
13
38
  * ```tsx
14
- * function BrandKitSection() {
15
- * const { allowed, denied, result } = useCan('brand_kit');
16
- * if (denied) return <UpgradePrompt reason={result?.reason} />;
17
- * return <BrandKitEditor />;
39
+ * function BatchExport() {
40
+ * const { can, limited } = useCan('batch_export');
41
+ * if (!can) return <UpgradePrompt />;
42
+ * return <BatchExportButton warnLowBalance={limited} />;
18
43
  * }
19
44
  * ```
20
45
  */
21
- export declare function useCan(handle: string, options?: Omit<UseEntitlementOptions, 'handle'>): UseEntitlementResult;
46
+ export declare function useCan(handle: string, options?: Omit<UseEntitlementOptions, 'handle'>): UseCanResult;
22
47
  //# sourceMappingURL=useCan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCan.d.ts","sourceRoot":"","sources":["../../../../react/useCan.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEzG;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,GAC9C,oBAAoB,CAEtB"}
1
+ {"version":3,"file":"useCan.d.ts","sourceRoot":"","sources":["../../../../react/useCan.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEzG;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,GAAG,EAAE,OAAO,CAAC;IACb;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,GAC9C,YAAY,CAGd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revturbine/sdk",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
4
4
  "description": "RevTurbine customer-facing SDK — placement decisioning, entitlement checks, and usage tracking.",
5
5
  "type": "module",
6
6
  "exports": {