@prsm/entitle 2.1.1 → 2.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prsm/entitle",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Plan-based entitlements and feature gating, resolved at runtime, backed by postgres",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,8 +11,8 @@ import ms from "@prsm/ms"
11
11
  * A per-subject override layered on top of the subject's plan. Shallow-merges
12
12
  * over the plan, so you only specify what differs (the enterprise customer who
13
13
  * negotiated more seats, or got one feature switched on).
14
- * @property {Record<string, boolean>} [features]
15
- * @property {Record<string, number|null>} [limits]
14
+ * @property {Record<string, boolean>} [features] - feature flags to override for this subject; merged over the plan's features, so include only the ones that differ
15
+ * @property {Record<string, number|null>} [limits] - limit ceilings to override for this subject; merged over the plan's limits, so include only the ones that differ (`null` means unlimited)
16
16
  */
17
17
 
18
18
  /**
@@ -29,9 +29,9 @@ import ms from "@prsm/ms"
29
29
 
30
30
  /**
31
31
  * @typedef {Object} Effective
32
- * @property {string} plan - the effective plan name
33
- * @property {Record<string, boolean>} features
34
- * @property {Record<string, number|null>} limits
32
+ * @property {string} plan - the effective plan name (the default plan if the subject is unassigned)
33
+ * @property {Record<string, boolean>} features - the resolved feature flags, after applying the subject's override on top of the plan
34
+ * @property {Record<string, number|null>} limits - the resolved limit ceilings, after applying the subject's override on top of the plan (`null` means unlimited)
35
35
  */
36
36
 
37
37
  /**
@@ -202,7 +202,7 @@ export function createEntitlements(options = {}) {
202
202
 
203
203
  /**
204
204
  * Assign a subject to a plan. Takes effect immediately.
205
- * @param {string} subject
205
+ * @param {string} subject - the subject identifier (whatever id you key entitlements by, such as an account or user id)
206
206
  * @param {string} plan - a key of the plan catalog
207
207
  */
208
208
  async assign(subject, plan) {
@@ -216,7 +216,7 @@ export function createEntitlements(options = {}) {
216
216
  * Remove a subject's plan assignment, reverting them to the default plan.
217
217
  * Distinct from assigning the default plan explicitly: an unassigned subject
218
218
  * follows `defaultPlan` if it later changes.
219
- * @param {string} subject
219
+ * @param {string} subject - the subject identifier whose assignment is removed
220
220
  */
221
221
  async unassign(subject) {
222
222
  if (!subject) throw new Error("unassign requires a `subject`")
@@ -230,8 +230,8 @@ export function createEntitlements(options = {}) {
230
230
  * accumulate: overriding `seats`, then later overriding `sso`, leaves both in
231
231
  * place, and overriding a key again updates just that key. Use clearOverride
232
232
  * to remove overrides. Takes effect immediately.
233
- * @param {string} subject
234
- * @param {Override} data
233
+ * @param {string} subject - the subject identifier to override
234
+ * @param {Override} data - the features and/or limits to override; merged into any existing override
235
235
  */
236
236
  async override(subject, data) {
237
237
  if (!subject) throw new Error("override requires a `subject`")
@@ -244,8 +244,8 @@ export function createEntitlements(options = {}) {
244
244
  * Remove overrides for a subject. With no `keys`, removes the entire override
245
245
  * and the subject falls back to plain plan entitlements. With `keys`, removes
246
246
  * only those override entries (reverting them to the plan) and keeps the rest.
247
- * @param {string} subject
248
- * @param {{ features?: string[], limits?: string[] }} [keys]
247
+ * @param {string} subject - the subject identifier whose override is cleared
248
+ * @param {{ features?: string[], limits?: string[] }} [keys] - the specific feature and limit keys to revert; omit to clear the entire override
249
249
  */
250
250
  async clearOverride(subject, keys) {
251
251
  if (!subject) throw new Error("clearOverride requires a `subject`")
@@ -259,7 +259,7 @@ export function createEntitlements(options = {}) {
259
259
 
260
260
  /**
261
261
  * The subject's effective plan name (the default plan if unassigned).
262
- * @param {string} subject
262
+ * @param {string} subject - the subject identifier to resolve
263
263
  * @returns {Promise<string>}
264
264
  */
265
265
  async plan(subject) {
@@ -270,8 +270,8 @@ export function createEntitlements(options = {}) {
270
270
  * Whether a capability flag is granted to the subject. Throws on a feature
271
271
  * key outside the declared/derived universe, so typos surface instead of
272
272
  * silently returning false.
273
- * @param {string} subject
274
- * @param {string} feature
273
+ * @param {string} subject - the subject identifier to resolve
274
+ * @param {string} feature - the feature key to check; must be in the declared/derived feature universe
275
275
  * @returns {Promise<boolean>}
276
276
  */
277
277
  async can(subject, feature) {
@@ -288,8 +288,8 @@ export function createEntitlements(options = {}) {
288
288
  * subject's plan does not grant - never silently unlimited. Throws on a key
289
289
  * outside the declared/derived universe. This is the static ceiling; it does
290
290
  * not read usage.
291
- * @param {string} subject
292
- * @param {string} key
291
+ * @param {string} subject - the subject identifier to resolve
292
+ * @param {string} key - the limit key to resolve; must be in the declared/derived limit universe
293
293
  * @returns {Promise<number|null>}
294
294
  */
295
295
  limit(subject, key) {
@@ -301,7 +301,7 @@ export function createEntitlements(options = {}) {
301
301
  * reads current usage from the meter for the metric of the same name. This is
302
302
  * the composition seam: entitle supplies the limit, meter supplies the usage.
303
303
  * Requires a `meter` to have been passed to `createEntitlements`.
304
- * @param {string} subject
304
+ * @param {string} subject - the subject identifier; must match the id usage is recorded under in the meter
305
305
  * @param {string} key - a limit key that is also a meter metric
306
306
  * @param {{ period?: any, range?: any }} [usageQuery] - forwarded to `meter.usage`
307
307
  * @returns {Promise<CheckResult>}
@@ -328,7 +328,7 @@ export function createEntitlements(options = {}) {
328
328
 
329
329
  /**
330
330
  * The subject's full effective entitlements, for a settings or billing page.
331
- * @param {string} subject
331
+ * @param {string} subject - the subject identifier to resolve
332
332
  * @returns {Promise<Effective>}
333
333
  */
334
334
  async describe(subject) {
@@ -11,7 +11,7 @@ export function createEntitlements(options?: EntitlementsOptions): {
11
11
  setup(): any;
12
12
  /**
13
13
  * Assign a subject to a plan. Takes effect immediately.
14
- * @param {string} subject
14
+ * @param {string} subject - the subject identifier (whatever id you key entitlements by, such as an account or user id)
15
15
  * @param {string} plan - a key of the plan catalog
16
16
  */
17
17
  assign(subject: string, plan: string): Promise<void>;
@@ -19,7 +19,7 @@ export function createEntitlements(options?: EntitlementsOptions): {
19
19
  * Remove a subject's plan assignment, reverting them to the default plan.
20
20
  * Distinct from assigning the default plan explicitly: an unassigned subject
21
21
  * follows `defaultPlan` if it later changes.
22
- * @param {string} subject
22
+ * @param {string} subject - the subject identifier whose assignment is removed
23
23
  */
24
24
  unassign(subject: string): Promise<void>;
25
25
  /**
@@ -28,16 +28,16 @@ export function createEntitlements(options?: EntitlementsOptions): {
28
28
  * accumulate: overriding `seats`, then later overriding `sso`, leaves both in
29
29
  * place, and overriding a key again updates just that key. Use clearOverride
30
30
  * to remove overrides. Takes effect immediately.
31
- * @param {string} subject
32
- * @param {Override} data
31
+ * @param {string} subject - the subject identifier to override
32
+ * @param {Override} data - the features and/or limits to override; merged into any existing override
33
33
  */
34
34
  override(subject: string, data: Override): Promise<void>;
35
35
  /**
36
36
  * Remove overrides for a subject. With no `keys`, removes the entire override
37
37
  * and the subject falls back to plain plan entitlements. With `keys`, removes
38
38
  * only those override entries (reverting them to the plan) and keeps the rest.
39
- * @param {string} subject
40
- * @param {{ features?: string[], limits?: string[] }} [keys]
39
+ * @param {string} subject - the subject identifier whose override is cleared
40
+ * @param {{ features?: string[], limits?: string[] }} [keys] - the specific feature and limit keys to revert; omit to clear the entire override
41
41
  */
42
42
  clearOverride(subject: string, keys?: {
43
43
  features?: string[];
@@ -45,7 +45,7 @@ export function createEntitlements(options?: EntitlementsOptions): {
45
45
  }): Promise<void>;
46
46
  /**
47
47
  * The subject's effective plan name (the default plan if unassigned).
48
- * @param {string} subject
48
+ * @param {string} subject - the subject identifier to resolve
49
49
  * @returns {Promise<string>}
50
50
  */
51
51
  plan(subject: string): Promise<string>;
@@ -53,8 +53,8 @@ export function createEntitlements(options?: EntitlementsOptions): {
53
53
  * Whether a capability flag is granted to the subject. Throws on a feature
54
54
  * key outside the declared/derived universe, so typos surface instead of
55
55
  * silently returning false.
56
- * @param {string} subject
57
- * @param {string} feature
56
+ * @param {string} subject - the subject identifier to resolve
57
+ * @param {string} feature - the feature key to check; must be in the declared/derived feature universe
58
58
  * @returns {Promise<boolean>}
59
59
  */
60
60
  can(subject: string, feature: string): Promise<boolean>;
@@ -64,8 +64,8 @@ export function createEntitlements(options?: EntitlementsOptions): {
64
64
  * subject's plan does not grant - never silently unlimited. Throws on a key
65
65
  * outside the declared/derived universe. This is the static ceiling; it does
66
66
  * not read usage.
67
- * @param {string} subject
68
- * @param {string} key
67
+ * @param {string} subject - the subject identifier to resolve
68
+ * @param {string} key - the limit key to resolve; must be in the declared/derived limit universe
69
69
  * @returns {Promise<number|null>}
70
70
  */
71
71
  limit(subject: string, key: string): Promise<number | null>;
@@ -74,7 +74,7 @@ export function createEntitlements(options?: EntitlementsOptions): {
74
74
  * reads current usage from the meter for the metric of the same name. This is
75
75
  * the composition seam: entitle supplies the limit, meter supplies the usage.
76
76
  * Requires a `meter` to have been passed to `createEntitlements`.
77
- * @param {string} subject
77
+ * @param {string} subject - the subject identifier; must match the id usage is recorded under in the meter
78
78
  * @param {string} key - a limit key that is also a meter metric
79
79
  * @param {{ period?: any, range?: any }} [usageQuery] - forwarded to `meter.usage`
80
80
  * @returns {Promise<CheckResult>}
@@ -85,7 +85,7 @@ export function createEntitlements(options?: EntitlementsOptions): {
85
85
  }): Promise<CheckResult>;
86
86
  /**
87
87
  * The subject's full effective entitlements, for a settings or billing page.
88
- * @param {string} subject
88
+ * @param {string} subject - the subject identifier to resolve
89
89
  * @returns {Promise<Effective>}
90
90
  */
91
91
  describe(subject: string): Promise<Effective>;
@@ -108,7 +108,13 @@ export type Plan = {
108
108
  * negotiated more seats, or got one feature switched on).
109
109
  */
110
110
  export type Override = {
111
+ /**
112
+ * - feature flags to override for this subject; merged over the plan's features, so include only the ones that differ
113
+ */
111
114
  features?: Record<string, boolean>;
115
+ /**
116
+ * - limit ceilings to override for this subject; merged over the plan's limits, so include only the ones that differ (`null` means unlimited)
117
+ */
112
118
  limits?: Record<string, number | null>;
113
119
  };
114
120
  export type EntitlementsOptions = {
@@ -151,10 +157,16 @@ export type EntitlementsOptions = {
151
157
  };
152
158
  export type Effective = {
153
159
  /**
154
- * - the effective plan name
160
+ * - the effective plan name (the default plan if the subject is unassigned)
155
161
  */
156
162
  plan: string;
163
+ /**
164
+ * - the resolved feature flags, after applying the subject's override on top of the plan
165
+ */
157
166
  features: Record<string, boolean>;
167
+ /**
168
+ * - the resolved limit ceilings, after applying the subject's override on top of the plan (`null` means unlimited)
169
+ */
158
170
  limits: Record<string, number | null>;
159
171
  };
160
172
  export type CheckResult = {