@workglow/task-graph 0.2.31 → 0.2.32

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.
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ *
6
+ * IEntitlementProfile — runtime-environment view of an entitlement system.
7
+ * Extends IEntitlementEnforcer with a single-key request API, change-event
8
+ * subscription, surface introspection, and disposal. Profiles delegate
9
+ * signal observation to a pluggable IEntitlementSignalSource.
10
+ */
11
+ import type { EntitlementDenial, IEntitlementEnforcer } from "./EntitlementEnforcer";
12
+ import type { EntitlementPolicy } from "./EntitlementPolicy";
13
+ import type { IEntitlementResolver } from "./EntitlementResolver";
14
+ import type { EntitlementGrant, TaskEntitlement } from "./TaskEntitlements";
15
+ /**
16
+ * A signal emitted by an external source telling profiles that a permission
17
+ * may have changed.
18
+ *
19
+ * - `revoke`: a previously granted entitlement may now be denied.
20
+ * - `grant`: a previously denied entitlement may now be granted.
21
+ * - `reload`: the underlying policy may have changed in arbitrary ways;
22
+ * profiles should re-evaluate every entitlement they have been queried
23
+ * about.
24
+ */
25
+ export type EntitlementSignal = {
26
+ readonly kind: "revoke";
27
+ readonly entitlement: TaskEntitlement;
28
+ } | {
29
+ readonly kind: "grant";
30
+ readonly entitlement: TaskEntitlement;
31
+ } | {
32
+ readonly kind: "reload";
33
+ };
34
+ /**
35
+ * Pluggable port that produces signals about external permission changes.
36
+ * Built-in profiles default to `STATIC_SIGNAL_SOURCE`. Downstream packages
37
+ * (e.g. workflow-builder Electron) provide implementations that wrap
38
+ * platform events.
39
+ */
40
+ export interface IEntitlementSignalSource {
41
+ /**
42
+ * Register a listener for signals. The returned function unsubscribes.
43
+ * Implementations must make the unsubscribe idempotent.
44
+ */
45
+ subscribe(listener: (signal: EntitlementSignal) => void): () => void;
46
+ }
47
+ /** Frozen no-op signal source. Never emits; subscribe returns a no-op unsub. */
48
+ export declare const STATIC_SIGNAL_SOURCE: IEntitlementSignalSource;
49
+ /**
50
+ * Result of `requestEntitlement(required)`. Discriminated union on `outcome`.
51
+ *
52
+ * Optional entitlements always map to `outcome: "granted"` regardless of the
53
+ * underlying policy verdict — matching the rule that optional entitlements
54
+ * are filtered out of `IEntitlementEnforcer.checkAll`.
55
+ *
56
+ * `"ask"` policy verdicts are resolved internally via the registered
57
+ * `IEntitlementResolver` before this function returns; callers only ever
58
+ * see `"granted"` or `"denied"`.
59
+ */
60
+ export type EntitlementRequestResult = {
61
+ readonly outcome: "granted";
62
+ readonly entitlement: TaskEntitlement;
63
+ } | {
64
+ readonly outcome: "denied";
65
+ readonly denial: EntitlementDenial;
66
+ };
67
+ /**
68
+ * Emitted by an `IEntitlementProfile` when a previously-observed entitlement
69
+ * verdict transitions. Profiles only emit events for entitlements whose
70
+ * verdict actually flipped between two queries.
71
+ */
72
+ export type EntitlementChangeEvent = {
73
+ readonly kind: "revoked" | "granted";
74
+ readonly entitlement: TaskEntitlement;
75
+ };
76
+ /**
77
+ * Runtime-environment view of an entitlement system.
78
+ *
79
+ * Extends `IEntitlementEnforcer` with:
80
+ * - `name`: free-form identifier for diagnostics.
81
+ * - `surface()`: maximum set of entitlements this profile may grant.
82
+ * - `requestEntitlement()`: single-key request returning a discriminated verdict.
83
+ * - `subscribe()`: observe change events from the bound signal source.
84
+ * - `dispose()`: idempotent teardown including signal-source unsubscribe.
85
+ */
86
+ export interface IEntitlementProfile extends IEntitlementEnforcer {
87
+ /** Free-form identifier (e.g. "browser", "desktop", "server"). */
88
+ readonly name: string;
89
+ /**
90
+ * The maximum set of grants this profile may issue.
91
+ *
92
+ * Implementations MAY return a live view of the underlying policy's
93
+ * grant array — callers must not mutate the returned array. Treat the
94
+ * return value as `Readonly<readonly EntitlementGrant[]>` even though
95
+ * `Object.freeze` is not guaranteed.
96
+ */
97
+ surface(): readonly EntitlementGrant[];
98
+ /** Single-key request. See `EntitlementRequestResult`. */
99
+ requestEntitlement(required: TaskEntitlement): Promise<EntitlementRequestResult>;
100
+ /** Subscribe to change events. The returned unsubscribe must be idempotent. */
101
+ subscribe(listener: (event: EntitlementChangeEvent) => void): () => void;
102
+ /** Idempotent teardown. */
103
+ dispose(): Promise<void>;
104
+ }
105
+ export interface CreateProfileOptions {
106
+ readonly resolver?: IEntitlementResolver;
107
+ /** Defaults to `STATIC_SIGNAL_SOURCE`. */
108
+ readonly signalSource?: IEntitlementSignalSource;
109
+ }
110
+ /**
111
+ * Build an `IEntitlementProfile` from a policy.
112
+ *
113
+ * Wraps `createPolicyEnforcer` and adds:
114
+ * - `surface()` returning the policy's grants
115
+ * - `requestEntitlement()` reusing `checkAll` for a single entitlement
116
+ * - signal-source subscription with verdict-flip change events
117
+ * - idempotent `dispose()`
118
+ *
119
+ * The "previously queried" set used to scope `reload` events is private to
120
+ * the profile and cleared on `dispose`.
121
+ */
122
+ export declare function createPolicyProfile(name: string, policy: EntitlementPolicy, options?: CreateProfileOptions): IEntitlementProfile;
123
+ /**
124
+ * Service token for registering an `IEntitlementProfile`.
125
+ *
126
+ * Distinct from `ENTITLEMENT_ENFORCER`: a profile exposes a richer surface
127
+ * (subscribe + dispose + surface). `ServiceRegistry` resolves by token
128
+ * identity, so a registration under `ENTITLEMENT_PROFILE` is NOT
129
+ * automatically visible to consumers resolving `ENTITLEMENT_ENFORCER`.
130
+ *
131
+ * Because `IEntitlementProfile extends IEntitlementEnforcer`, the same
132
+ * profile instance can be registered under both tokens if both consumer
133
+ * styles need to resolve it.
134
+ */
135
+ export declare const ENTITLEMENT_PROFILE: import("@workglow/util").ServiceToken<IEntitlementProfile>;
136
+ //# sourceMappingURL=EntitlementProfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntitlementProfile.d.ts","sourceRoot":"","sources":["../../src/task/EntitlementProfile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAA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kE;IAClE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;;OAOG;IACH,OAAO,IAAI,SAAS,gBAAgB,EAAE,CAAC;IACvC,0DAA0D;IAC1D,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACjF,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACzE,2BAA2B;IAC3B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAMD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IACzC,0CAA0C;IAC1C,QAAQ,CAAC,YAAY,CAAC,EAAE,wBAAwB,CAAC;CAClD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,oBAAyB,GACjC,mBAAmB,CAiHrB;AAMD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,4DAE/B,CAAC"}
@@ -7,9 +7,8 @@
7
7
  * The library has no concept of Electron, brands, or deployment targets —
8
8
  * only capability profiles expressed as entitlement policies.
9
9
  */
10
- import { type IEntitlementEnforcer } from "./EntitlementEnforcer";
10
+ import { type CreateProfileOptions, type IEntitlementProfile } from "./EntitlementProfile";
11
11
  import type { EntitlementPolicy } from "./EntitlementPolicy";
12
- import type { IEntitlementResolver } from "./EntitlementResolver";
13
12
  import type { EntitlementGrant } from "./TaskEntitlements";
14
13
  /**
15
14
  * Browser environment grants.
@@ -41,13 +40,14 @@ export type EntitlementProfile = "browser" | "desktop" | "server";
41
40
  */
42
41
  export declare function createProfilePolicy(profile: EntitlementProfile): EntitlementPolicy;
43
42
  /**
44
- * Creates an entitlement enforcer for the given runtime profile.
45
- * Tasks requiring entitlements not in the profile will be denied.
43
+ * Creates an entitlement profile for the given runtime profile.
44
+ * The profile's grants become the policy's grant rules.
45
+ * Deny and ask arrays are empty by default — callers can extend the returned profile.
46
46
  *
47
47
  * @param profile - The runtime profile to use
48
- * @param resolver - Optional resolver for handling "ask" verdicts
48
+ * @param options - Optional resolver (for "ask" verdicts) and signal source
49
49
  */
50
- export declare function createProfileEnforcer(profile: EntitlementProfile, resolver?: IEntitlementResolver): IEntitlementEnforcer;
50
+ export declare function createProfileEnforcer(profile: EntitlementProfile, options?: CreateProfileOptions): IEntitlementProfile;
51
51
  /**
52
52
  * Returns the grant list for a given profile.
53
53
  * Useful for inspection or combining with additional grants.
@@ -1 +1 @@
1
- {"version":3,"file":"EntitlementProfiles.d.ts","sourceRoot":"","sources":["../../src/task/EntitlementProfiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAwB,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAO3D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EASrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EAUrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,gBAAgB,EAGpD,CAAC;AAMF,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAQlE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAElF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,CAAC,EAAE,oBAAoB,GAC9B,oBAAoB,CAEtB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,SAAS,gBAAgB,EAAE,CAEzF"}
1
+ {"version":3,"file":"EntitlementProfiles.d.ts","sourceRoot":"","sources":["../../src/task/EntitlementProfiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAO3D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EASrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,gBAAgB,EAUrD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,SAAS,gBAAgB,EAGpD,CAAC;AAMF,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAC;AAQlE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAElF;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,mBAAmB,CAErB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,kBAAkB,GAAG,SAAS,gBAAgB,EAAE,CAEzF"}
@@ -7,6 +7,7 @@ export * from "./ConditionalTask";
7
7
  export * from "./ConditionUtils";
8
8
  export * from "./EntitlementEnforcer";
9
9
  export * from "./EntitlementPolicy";
10
+ export * from "./EntitlementProfile";
10
11
  export * from "./EntitlementProfiles";
11
12
  export * from "./EntitlementResolver";
12
13
  export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AC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workglow/task-graph",
3
3
  "type": "module",
4
- "version": "0.2.31",
4
+ "version": "0.2.32",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/workglow-dev/workglow.git",
@@ -51,9 +51,9 @@
51
51
  "access": "public"
52
52
  },
53
53
  "peerDependencies": {
54
- "@workglow/job-queue": "0.2.31",
55
- "@workglow/storage": "0.2.31",
56
- "@workglow/util": "0.2.31"
54
+ "@workglow/job-queue": "0.2.32",
55
+ "@workglow/storage": "0.2.32",
56
+ "@workglow/util": "0.2.32"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "@workglow/job-queue": {
@@ -67,8 +67,8 @@
67
67
  }
68
68
  },
69
69
  "devDependencies": {
70
- "@workglow/job-queue": "0.2.31",
71
- "@workglow/storage": "0.2.31",
72
- "@workglow/util": "0.2.31"
70
+ "@workglow/job-queue": "0.2.32",
71
+ "@workglow/storage": "0.2.32",
72
+ "@workglow/util": "0.2.32"
73
73
  }
74
74
  }