@contractspec/lib.contracts 1.49.0 → 1.51.0
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/app-config/contracts.d.ts +51 -51
- package/dist/app-config/events.d.ts +27 -27
- package/dist/app-config/lifecycle-contracts.d.ts +55 -55
- package/dist/app-config/runtime.d.ts +1 -1
- package/dist/app-config/spec.d.ts +1 -1
- package/dist/capabilities/capabilities.d.ts +64 -5
- package/dist/capabilities/capabilities.js +125 -0
- package/dist/capabilities/context.d.ts +88 -0
- package/dist/capabilities/context.js +87 -0
- package/dist/capabilities/docs/capabilities.docblock.js +191 -2
- package/dist/capabilities/guards.d.ts +110 -0
- package/dist/capabilities/guards.js +146 -0
- package/dist/capabilities/index.d.ts +4 -1
- package/dist/capabilities/index.js +4 -1
- package/dist/capabilities/validation.d.ts +76 -0
- package/dist/capabilities/validation.js +141 -0
- package/dist/client/react/feature-render.d.ts +2 -2
- package/dist/data-views/runtime.d.ts +1 -1
- package/dist/events.d.ts +79 -13
- package/dist/events.js +33 -3
- package/dist/examples/schema.d.ts +10 -10
- package/dist/experiments/spec.d.ts +7 -4
- package/dist/features/install.d.ts +4 -4
- package/dist/features/types.d.ts +28 -32
- package/dist/index.d.ts +21 -12
- package/dist/index.js +12 -3
- package/dist/install.d.ts +1 -1
- package/dist/integrations/openbanking/contracts/accounts.d.ts +67 -67
- package/dist/integrations/openbanking/contracts/balances.d.ts +35 -35
- package/dist/integrations/openbanking/contracts/transactions.d.ts +49 -49
- package/dist/integrations/openbanking/models.d.ts +55 -55
- package/dist/integrations/operations.d.ts +103 -103
- package/dist/integrations/spec.d.ts +1 -1
- package/dist/knowledge/operations.d.ts +67 -67
- package/dist/llm/exporters.d.ts +2 -2
- package/dist/markdown.d.ts +1 -1
- package/dist/onboarding-base.d.ts +29 -29
- package/dist/operations/operation.d.ts +6 -0
- package/dist/ownership.d.ts +133 -8
- package/dist/ownership.js +25 -0
- package/dist/policy/context.d.ts +237 -0
- package/dist/policy/context.js +227 -0
- package/dist/policy/guards.d.ts +145 -0
- package/dist/policy/guards.js +254 -0
- package/dist/policy/index.d.ts +12 -1
- package/dist/policy/index.js +11 -1
- package/dist/policy/spec.d.ts +7 -4
- package/dist/policy/validation.d.ts +67 -0
- package/dist/policy/validation.js +307 -0
- package/dist/presentations/presentations.d.ts +6 -0
- package/dist/tests/spec.d.ts +17 -12
- package/dist/themes.d.ts +7 -4
- package/dist/translations/index.d.ts +6 -0
- package/dist/translations/index.js +5 -0
- package/dist/translations/registry.d.ts +144 -0
- package/dist/translations/registry.js +223 -0
- package/dist/translations/spec.d.ts +126 -0
- package/dist/translations/spec.js +31 -0
- package/dist/translations/validation.d.ts +85 -0
- package/dist/translations/validation.js +328 -0
- package/dist/types.d.ts +140 -14
- package/dist/versioning/index.d.ts +2 -1
- package/dist/versioning/index.js +2 -1
- package/dist/versioning/refs.d.ts +179 -0
- package/dist/versioning/refs.js +161 -0
- package/dist/workflow/context.d.ts +191 -0
- package/dist/workflow/context.js +227 -0
- package/dist/workflow/index.d.ts +4 -2
- package/dist/workflow/index.js +4 -2
- package/dist/workflow/spec.d.ts +1 -1
- package/dist/workflow/validation.d.ts +64 -2
- package/dist/workflow/validation.js +194 -1
- package/package.json +19 -6
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
import { OperationSpec } from "../operations/operation.js";
|
|
2
|
-
import { OperationSpecRegistry } from "../operations/registry.js";
|
|
3
2
|
import "../operations/index.js";
|
|
3
|
+
import { OperationSpecRegistry } from "../operations/registry.js";
|
|
4
4
|
import { EventSpecMeta } from "../events.js";
|
|
5
5
|
import "../index.js";
|
|
6
|
-
import * as
|
|
6
|
+
import * as _contractspec_lib_schema74 from "@contractspec/lib.schema";
|
|
7
7
|
import { SchemaModel } from "@contractspec/lib.schema";
|
|
8
8
|
|
|
9
9
|
//#region src/app-config/lifecycle-contracts.d.ts
|
|
10
10
|
declare const CreateTenantConfigDraftCommand: OperationSpec<SchemaModel<{
|
|
11
11
|
tenantId: {
|
|
12
|
-
type:
|
|
12
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
13
13
|
isOptional: false;
|
|
14
14
|
};
|
|
15
15
|
appId: {
|
|
16
|
-
type:
|
|
16
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
17
17
|
isOptional: false;
|
|
18
18
|
};
|
|
19
19
|
blueprintName: {
|
|
20
|
-
type:
|
|
20
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
21
21
|
isOptional: false;
|
|
22
22
|
};
|
|
23
23
|
blueprintVersion: {
|
|
24
|
-
type:
|
|
24
|
+
type: _contractspec_lib_schema74.FieldType<number, number>;
|
|
25
25
|
isOptional: false;
|
|
26
26
|
};
|
|
27
27
|
environment: {
|
|
28
|
-
type:
|
|
28
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
29
29
|
isOptional: true;
|
|
30
30
|
};
|
|
31
31
|
fromVersion: {
|
|
32
|
-
type:
|
|
32
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
33
33
|
isOptional: true;
|
|
34
34
|
};
|
|
35
35
|
createdBy: {
|
|
36
|
-
type:
|
|
36
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
37
37
|
isOptional: false;
|
|
38
38
|
};
|
|
39
39
|
}>, SchemaModel<{
|
|
40
40
|
version: {
|
|
41
|
-
type:
|
|
41
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
42
42
|
isOptional: false;
|
|
43
43
|
};
|
|
44
44
|
status: {
|
|
45
|
-
type:
|
|
45
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
46
46
|
isOptional: false;
|
|
47
47
|
};
|
|
48
48
|
createdAt: {
|
|
49
|
-
type:
|
|
49
|
+
type: _contractspec_lib_schema74.FieldType<Date, string>;
|
|
50
50
|
isOptional: false;
|
|
51
51
|
};
|
|
52
52
|
}>, {
|
|
@@ -55,32 +55,32 @@ declare const CreateTenantConfigDraftCommand: OperationSpec<SchemaModel<{
|
|
|
55
55
|
}[]>;
|
|
56
56
|
declare const PromoteTenantConfigToPreviewCommand: OperationSpec<SchemaModel<{
|
|
57
57
|
tenantId: {
|
|
58
|
-
type:
|
|
58
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
59
59
|
isOptional: false;
|
|
60
60
|
};
|
|
61
61
|
appId: {
|
|
62
|
-
type:
|
|
62
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
63
63
|
isOptional: false;
|
|
64
64
|
};
|
|
65
65
|
version: {
|
|
66
|
-
type:
|
|
66
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
67
67
|
isOptional: false;
|
|
68
68
|
};
|
|
69
69
|
promotedBy: {
|
|
70
|
-
type:
|
|
70
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
71
71
|
isOptional: false;
|
|
72
72
|
};
|
|
73
73
|
}>, SchemaModel<{
|
|
74
74
|
version: {
|
|
75
|
-
type:
|
|
75
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
76
76
|
isOptional: false;
|
|
77
77
|
};
|
|
78
78
|
status: {
|
|
79
|
-
type:
|
|
79
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
80
80
|
isOptional: false;
|
|
81
81
|
};
|
|
82
82
|
warnings: {
|
|
83
|
-
type:
|
|
83
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
84
84
|
isOptional: true;
|
|
85
85
|
isArray: true;
|
|
86
86
|
};
|
|
@@ -90,44 +90,44 @@ declare const PromoteTenantConfigToPreviewCommand: OperationSpec<SchemaModel<{
|
|
|
90
90
|
}[]>;
|
|
91
91
|
declare const PublishTenantConfigCommand: OperationSpec<SchemaModel<{
|
|
92
92
|
tenantId: {
|
|
93
|
-
type:
|
|
93
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
94
94
|
isOptional: false;
|
|
95
95
|
};
|
|
96
96
|
appId: {
|
|
97
|
-
type:
|
|
97
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
98
98
|
isOptional: false;
|
|
99
99
|
};
|
|
100
100
|
version: {
|
|
101
|
-
type:
|
|
101
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
102
102
|
isOptional: false;
|
|
103
103
|
};
|
|
104
104
|
environment: {
|
|
105
|
-
type:
|
|
105
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
106
106
|
isOptional: true;
|
|
107
107
|
};
|
|
108
108
|
publishedBy: {
|
|
109
|
-
type:
|
|
109
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
110
110
|
isOptional: false;
|
|
111
111
|
};
|
|
112
112
|
changeSummary: {
|
|
113
|
-
type:
|
|
113
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
114
114
|
isOptional: true;
|
|
115
115
|
};
|
|
116
116
|
}>, SchemaModel<{
|
|
117
117
|
version: {
|
|
118
|
-
type:
|
|
118
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
119
119
|
isOptional: false;
|
|
120
120
|
};
|
|
121
121
|
status: {
|
|
122
|
-
type:
|
|
122
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
123
123
|
isOptional: false;
|
|
124
124
|
};
|
|
125
125
|
previousVersion: {
|
|
126
|
-
type:
|
|
126
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
127
127
|
isOptional: true;
|
|
128
128
|
};
|
|
129
129
|
publishedAt: {
|
|
130
|
-
type:
|
|
130
|
+
type: _contractspec_lib_schema74.FieldType<Date, string>;
|
|
131
131
|
isOptional: false;
|
|
132
132
|
};
|
|
133
133
|
}>, {
|
|
@@ -136,40 +136,40 @@ declare const PublishTenantConfigCommand: OperationSpec<SchemaModel<{
|
|
|
136
136
|
}[]>;
|
|
137
137
|
declare const RollbackTenantConfigCommand: OperationSpec<SchemaModel<{
|
|
138
138
|
tenantId: {
|
|
139
|
-
type:
|
|
139
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
140
140
|
isOptional: false;
|
|
141
141
|
};
|
|
142
142
|
appId: {
|
|
143
|
-
type:
|
|
143
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
144
144
|
isOptional: false;
|
|
145
145
|
};
|
|
146
146
|
toVersion: {
|
|
147
|
-
type:
|
|
147
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
148
148
|
isOptional: false;
|
|
149
149
|
};
|
|
150
150
|
environment: {
|
|
151
|
-
type:
|
|
151
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
152
152
|
isOptional: true;
|
|
153
153
|
};
|
|
154
154
|
rolledBackBy: {
|
|
155
|
-
type:
|
|
155
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
156
156
|
isOptional: false;
|
|
157
157
|
};
|
|
158
158
|
reason: {
|
|
159
|
-
type:
|
|
159
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
160
160
|
isOptional: false;
|
|
161
161
|
};
|
|
162
162
|
}>, SchemaModel<{
|
|
163
163
|
newVersion: {
|
|
164
|
-
type:
|
|
164
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
165
165
|
isOptional: false;
|
|
166
166
|
};
|
|
167
167
|
status: {
|
|
168
|
-
type:
|
|
168
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
169
169
|
isOptional: false;
|
|
170
170
|
};
|
|
171
171
|
rolledBackFrom: {
|
|
172
|
-
type:
|
|
172
|
+
type: _contractspec_lib_schema74.FieldType<number, number>;
|
|
173
173
|
isOptional: false;
|
|
174
174
|
};
|
|
175
175
|
}>, {
|
|
@@ -178,22 +178,22 @@ declare const RollbackTenantConfigCommand: OperationSpec<SchemaModel<{
|
|
|
178
178
|
}[]>;
|
|
179
179
|
declare const ListTenantConfigVersionsQuery: OperationSpec<SchemaModel<{
|
|
180
180
|
tenantId: {
|
|
181
|
-
type:
|
|
181
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
182
182
|
isOptional: false;
|
|
183
183
|
};
|
|
184
184
|
appId: {
|
|
185
|
-
type:
|
|
185
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
186
186
|
isOptional: false;
|
|
187
187
|
};
|
|
188
188
|
}>, SchemaModel<{
|
|
189
189
|
versions: {
|
|
190
190
|
type: SchemaModel<{
|
|
191
191
|
meta: {
|
|
192
|
-
type:
|
|
192
|
+
type: _contractspec_lib_schema74.FieldType<Record<string, unknown>, Record<string, unknown>>;
|
|
193
193
|
isOptional: false;
|
|
194
194
|
};
|
|
195
195
|
config: {
|
|
196
|
-
type:
|
|
196
|
+
type: _contractspec_lib_schema74.FieldType<Record<string, unknown>, Record<string, unknown>>;
|
|
197
197
|
isOptional: false;
|
|
198
198
|
};
|
|
199
199
|
}>;
|
|
@@ -203,35 +203,35 @@ declare const ListTenantConfigVersionsQuery: OperationSpec<SchemaModel<{
|
|
|
203
203
|
transitions: {
|
|
204
204
|
type: SchemaModel<{
|
|
205
205
|
tenantId: {
|
|
206
|
-
type:
|
|
206
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
207
207
|
isOptional: false;
|
|
208
208
|
};
|
|
209
209
|
appId: {
|
|
210
|
-
type:
|
|
210
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
211
211
|
isOptional: false;
|
|
212
212
|
};
|
|
213
213
|
fromStatus: {
|
|
214
|
-
type:
|
|
214
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
215
215
|
isOptional: false;
|
|
216
216
|
};
|
|
217
217
|
toStatus: {
|
|
218
|
-
type:
|
|
218
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
219
219
|
isOptional: false;
|
|
220
220
|
};
|
|
221
221
|
version: {
|
|
222
|
-
type:
|
|
222
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
223
223
|
isOptional: false;
|
|
224
224
|
};
|
|
225
225
|
timestamp: {
|
|
226
|
-
type:
|
|
226
|
+
type: _contractspec_lib_schema74.FieldType<Date, string>;
|
|
227
227
|
isOptional: false;
|
|
228
228
|
};
|
|
229
229
|
actor: {
|
|
230
|
-
type:
|
|
230
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
231
231
|
isOptional: false;
|
|
232
232
|
};
|
|
233
233
|
reason: {
|
|
234
|
-
type:
|
|
234
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
235
235
|
isOptional: true;
|
|
236
236
|
};
|
|
237
237
|
}>;
|
|
@@ -241,26 +241,26 @@ declare const ListTenantConfigVersionsQuery: OperationSpec<SchemaModel<{
|
|
|
241
241
|
}>, undefined>;
|
|
242
242
|
declare const GetTenantConfigVersionQuery: OperationSpec<SchemaModel<{
|
|
243
243
|
tenantId: {
|
|
244
|
-
type:
|
|
244
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
245
245
|
isOptional: false;
|
|
246
246
|
};
|
|
247
247
|
appId: {
|
|
248
|
-
type:
|
|
248
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
249
249
|
isOptional: false;
|
|
250
250
|
};
|
|
251
251
|
version: {
|
|
252
|
-
type:
|
|
252
|
+
type: _contractspec_lib_schema74.FieldType<string, string>;
|
|
253
253
|
isOptional: false;
|
|
254
254
|
};
|
|
255
255
|
}>, SchemaModel<{
|
|
256
256
|
version: {
|
|
257
257
|
type: SchemaModel<{
|
|
258
258
|
meta: {
|
|
259
|
-
type:
|
|
259
|
+
type: _contractspec_lib_schema74.FieldType<Record<string, unknown>, Record<string, unknown>>;
|
|
260
260
|
isOptional: false;
|
|
261
261
|
};
|
|
262
262
|
config: {
|
|
263
|
-
type:
|
|
263
|
+
type: _contractspec_lib_schema74.FieldType<Record<string, unknown>, Record<string, unknown>>;
|
|
264
264
|
isOptional: false;
|
|
265
265
|
};
|
|
266
266
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { CapabilityRef, CapabilityRegistry, CapabilitySpec } from "../capabilities/capabilities.js";
|
|
1
2
|
import { PolicyRef, PolicySpec } from "../policy/spec.js";
|
|
2
3
|
import { TelemetryRegistry, TelemetrySpec } from "../telemetry/spec.js";
|
|
3
|
-
import { CapabilityRef, CapabilityRegistry, CapabilitySpec } from "../capabilities/capabilities.js";
|
|
4
4
|
import "../capabilities/index.js";
|
|
5
5
|
import { ExperimentRef, ExperimentRegistry, ExperimentSpec } from "../experiments/spec.js";
|
|
6
6
|
import { FeatureModuleSpec, FeatureRef } from "../features/types.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { CapabilityRef } from "../capabilities/capabilities.js";
|
|
1
2
|
import { OwnerShipMeta } from "../ownership.js";
|
|
2
3
|
import { PolicyRef } from "../policy/spec.js";
|
|
3
|
-
import { CapabilityRef } from "../capabilities/capabilities.js";
|
|
4
4
|
import "../capabilities/index.js";
|
|
5
5
|
import { ExperimentRef } from "../experiments/spec.js";
|
|
6
6
|
import { FeatureModuleSpec, FeatureRef } from "../features/types.js";
|
|
@@ -1,39 +1,98 @@
|
|
|
1
|
+
import { VersionedSpecRef } from "../versioning/refs.js";
|
|
1
2
|
import { OwnerShipMeta } from "../ownership.js";
|
|
2
3
|
|
|
3
4
|
//#region src/capabilities/capabilities.d.ts
|
|
5
|
+
/** Classification of capability types. */
|
|
4
6
|
type CapabilityKind = 'api' | 'event' | 'data' | 'ui' | 'integration';
|
|
7
|
+
/** Surfaces where capabilities can be exposed or consumed. */
|
|
5
8
|
type CapabilitySurface = 'operation' | 'event' | 'workflow' | 'presentation' | 'resource';
|
|
9
|
+
/**
|
|
10
|
+
* Reference to a capability on a specific surface.
|
|
11
|
+
* Extends VersionedSpecRef with surface and description context.
|
|
12
|
+
*/
|
|
6
13
|
interface CapabilitySurfaceRef {
|
|
14
|
+
/** The surface type where this capability is exposed. */
|
|
7
15
|
surface: CapabilitySurface;
|
|
16
|
+
/** Unique key identifying the spec on that surface (e.g., operation key). */
|
|
8
17
|
key: string;
|
|
9
|
-
version
|
|
18
|
+
/** Semantic version of the spec on that surface. */
|
|
19
|
+
version?: string;
|
|
20
|
+
/** Optional description of what this capability provides. */
|
|
10
21
|
description?: string;
|
|
11
22
|
}
|
|
23
|
+
/** Metadata for a capability spec, extending ownership with kind. */
|
|
12
24
|
interface CapabilityMeta extends OwnerShipMeta {
|
|
25
|
+
/** The kind/category of this capability. */
|
|
13
26
|
kind: CapabilityKind;
|
|
14
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Requirement for a capability dependency.
|
|
30
|
+
* Used to declare what capabilities a spec needs.
|
|
31
|
+
*/
|
|
15
32
|
interface CapabilityRequirement {
|
|
33
|
+
/** Unique key of the required capability. */
|
|
16
34
|
key: string;
|
|
35
|
+
/** Optional specific version required. */
|
|
17
36
|
version?: string;
|
|
37
|
+
/** Optional kind filter for the requirement. */
|
|
18
38
|
kind?: CapabilityKind;
|
|
39
|
+
/** If true, the requirement is optional and won't block if missing. */
|
|
19
40
|
optional?: boolean;
|
|
41
|
+
/** Human-readable reason why this capability is required. */
|
|
20
42
|
reason?: string;
|
|
21
43
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Reference to a capability spec.
|
|
46
|
+
* Uses key and version to identify a specific capability.
|
|
47
|
+
*/
|
|
48
|
+
type CapabilityRef = VersionedSpecRef;
|
|
26
49
|
interface CapabilitySpec {
|
|
27
50
|
meta: CapabilityMeta;
|
|
51
|
+
/** Capabilities this capability extends (inherits requirements from). */
|
|
52
|
+
extends?: CapabilityRef;
|
|
53
|
+
/** Surfaces (operations, events, presentations, etc.) this capability provides. */
|
|
28
54
|
provides?: CapabilitySurfaceRef[];
|
|
55
|
+
/** Capabilities that must be present for this capability to function. */
|
|
29
56
|
requires?: CapabilityRequirement[];
|
|
30
57
|
}
|
|
31
58
|
declare class CapabilityRegistry {
|
|
32
59
|
private readonly items;
|
|
60
|
+
/** Reverse index: surface key -> capability key (built lazily) */
|
|
61
|
+
private surfaceIndex;
|
|
33
62
|
register(spec: CapabilitySpec): this;
|
|
34
63
|
list(): CapabilitySpec[];
|
|
35
64
|
get(key: string, version?: string): CapabilitySpec | undefined;
|
|
36
65
|
satisfies(requirement: CapabilityRequirement, additional?: CapabilityRef[] | undefined): boolean;
|
|
66
|
+
/** Build reverse index from surface specs to capabilities. */
|
|
67
|
+
private buildSurfaceIndex;
|
|
68
|
+
/** Get all operation keys provided by a capability. */
|
|
69
|
+
getOperationsFor(capabilityKey: string, version?: string): string[];
|
|
70
|
+
/** Get all event keys provided by a capability. */
|
|
71
|
+
getEventsFor(capabilityKey: string, version?: string): string[];
|
|
72
|
+
/** Get all presentation keys provided by a capability. */
|
|
73
|
+
getPresentationsFor(capabilityKey: string, version?: string): string[];
|
|
74
|
+
/** Get all workflow keys provided by a capability. */
|
|
75
|
+
getWorkflowsFor(capabilityKey: string, version?: string): string[];
|
|
76
|
+
/** Get all resource keys provided by a capability. */
|
|
77
|
+
getResourcesFor(capabilityKey: string, version?: string): string[];
|
|
78
|
+
/** Get capability refs that provide a specific operation. */
|
|
79
|
+
getCapabilitiesForOperation(operationKey: string): CapabilityRef[];
|
|
80
|
+
/** Get capability refs that provide a specific event. */
|
|
81
|
+
getCapabilitiesForEvent(eventKey: string): CapabilityRef[];
|
|
82
|
+
/** Get capability refs that provide a specific presentation. */
|
|
83
|
+
getCapabilitiesForPresentation(presentationKey: string): CapabilityRef[];
|
|
84
|
+
/** Get the ancestor chain for a capability (from immediate parent to root). */
|
|
85
|
+
getAncestors(capabilityKey: string, version?: string): CapabilitySpec[];
|
|
86
|
+
/**
|
|
87
|
+
* Get effective requirements for a capability, including inherited ones.
|
|
88
|
+
* Requirements from ancestors are included, with child requirements taking
|
|
89
|
+
* precedence over parent requirements for the same key.
|
|
90
|
+
*/
|
|
91
|
+
getEffectiveRequirements(capabilityKey: string, version?: string): CapabilityRequirement[];
|
|
92
|
+
/**
|
|
93
|
+
* Get all surfaces provided by a capability, including inherited ones.
|
|
94
|
+
*/
|
|
95
|
+
getEffectiveSurfaces(capabilityKey: string, version?: string): CapabilitySurfaceRef[];
|
|
37
96
|
}
|
|
38
97
|
declare function capabilityKey(spec: CapabilitySpec): string;
|
|
39
98
|
declare function defineCapability(spec: CapabilitySpec): CapabilitySpec;
|
|
@@ -4,10 +4,13 @@ import { compareVersions } from "compare-versions";
|
|
|
4
4
|
const capKey = (key, version) => `${key}.v${version}`;
|
|
5
5
|
var CapabilityRegistry = class {
|
|
6
6
|
items = /* @__PURE__ */ new Map();
|
|
7
|
+
/** Reverse index: surface key -> capability key (built lazily) */
|
|
8
|
+
surfaceIndex = null;
|
|
7
9
|
register(spec) {
|
|
8
10
|
const key = capKey(spec.meta.key, spec.meta.version);
|
|
9
11
|
if (this.items.has(key)) throw new Error(`Duplicate capability ${key}`);
|
|
10
12
|
this.items.set(key, spec);
|
|
13
|
+
this.surfaceIndex = null;
|
|
11
14
|
return this;
|
|
12
15
|
}
|
|
13
16
|
list() {
|
|
@@ -31,6 +34,128 @@ var CapabilityRegistry = class {
|
|
|
31
34
|
if (requirement.version != null && spec.meta.version !== requirement.version) return false;
|
|
32
35
|
return true;
|
|
33
36
|
}
|
|
37
|
+
/** Build reverse index from surface specs to capabilities. */
|
|
38
|
+
buildSurfaceIndex() {
|
|
39
|
+
if (this.surfaceIndex) return this.surfaceIndex;
|
|
40
|
+
this.surfaceIndex = /* @__PURE__ */ new Map();
|
|
41
|
+
for (const spec of this.items.values()) {
|
|
42
|
+
const capabilityKey$1 = capKey(spec.meta.key, spec.meta.version);
|
|
43
|
+
for (const surface of spec.provides ?? []) {
|
|
44
|
+
const surfaceKey = `${surface.surface}:${surface.key}`;
|
|
45
|
+
if (!this.surfaceIndex.has(surfaceKey)) this.surfaceIndex.set(surfaceKey, /* @__PURE__ */ new Set());
|
|
46
|
+
this.surfaceIndex.get(surfaceKey)?.add(capabilityKey$1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return this.surfaceIndex;
|
|
50
|
+
}
|
|
51
|
+
/** Get all operation keys provided by a capability. */
|
|
52
|
+
getOperationsFor(capabilityKey$1, version) {
|
|
53
|
+
const spec = this.get(capabilityKey$1, version);
|
|
54
|
+
if (!spec) return [];
|
|
55
|
+
return spec.provides?.filter((s) => s.surface === "operation").map((s) => s.key) ?? [];
|
|
56
|
+
}
|
|
57
|
+
/** Get all event keys provided by a capability. */
|
|
58
|
+
getEventsFor(capabilityKey$1, version) {
|
|
59
|
+
const spec = this.get(capabilityKey$1, version);
|
|
60
|
+
if (!spec) return [];
|
|
61
|
+
return spec.provides?.filter((s) => s.surface === "event").map((s) => s.key) ?? [];
|
|
62
|
+
}
|
|
63
|
+
/** Get all presentation keys provided by a capability. */
|
|
64
|
+
getPresentationsFor(capabilityKey$1, version) {
|
|
65
|
+
const spec = this.get(capabilityKey$1, version);
|
|
66
|
+
if (!spec) return [];
|
|
67
|
+
return spec.provides?.filter((s) => s.surface === "presentation").map((s) => s.key) ?? [];
|
|
68
|
+
}
|
|
69
|
+
/** Get all workflow keys provided by a capability. */
|
|
70
|
+
getWorkflowsFor(capabilityKey$1, version) {
|
|
71
|
+
const spec = this.get(capabilityKey$1, version);
|
|
72
|
+
if (!spec) return [];
|
|
73
|
+
return spec.provides?.filter((s) => s.surface === "workflow").map((s) => s.key) ?? [];
|
|
74
|
+
}
|
|
75
|
+
/** Get all resource keys provided by a capability. */
|
|
76
|
+
getResourcesFor(capabilityKey$1, version) {
|
|
77
|
+
const spec = this.get(capabilityKey$1, version);
|
|
78
|
+
if (!spec) return [];
|
|
79
|
+
return spec.provides?.filter((s) => s.surface === "resource").map((s) => s.key) ?? [];
|
|
80
|
+
}
|
|
81
|
+
/** Get capability refs that provide a specific operation. */
|
|
82
|
+
getCapabilitiesForOperation(operationKey) {
|
|
83
|
+
const capKeys = this.buildSurfaceIndex().get(`operation:${operationKey}`);
|
|
84
|
+
if (!capKeys) return [];
|
|
85
|
+
return [...capKeys].map((k) => {
|
|
86
|
+
const spec = this.items.get(k);
|
|
87
|
+
return {
|
|
88
|
+
key: spec?.meta.key ?? "",
|
|
89
|
+
version: spec?.meta.version ?? ""
|
|
90
|
+
};
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** Get capability refs that provide a specific event. */
|
|
94
|
+
getCapabilitiesForEvent(eventKey) {
|
|
95
|
+
const capKeys = this.buildSurfaceIndex().get(`event:${eventKey}`);
|
|
96
|
+
if (!capKeys) return [];
|
|
97
|
+
return [...capKeys].map((k) => {
|
|
98
|
+
const spec = this.items.get(k);
|
|
99
|
+
return {
|
|
100
|
+
key: spec?.meta.key ?? "",
|
|
101
|
+
version: spec?.meta.version ?? ""
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Get capability refs that provide a specific presentation. */
|
|
106
|
+
getCapabilitiesForPresentation(presentationKey) {
|
|
107
|
+
const capKeys = this.buildSurfaceIndex().get(`presentation:${presentationKey}`);
|
|
108
|
+
if (!capKeys) return [];
|
|
109
|
+
return [...capKeys].map((k) => {
|
|
110
|
+
const spec = this.items.get(k);
|
|
111
|
+
return {
|
|
112
|
+
key: spec?.meta.key ?? "",
|
|
113
|
+
version: spec?.meta.version ?? ""
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** Get the ancestor chain for a capability (from immediate parent to root). */
|
|
118
|
+
getAncestors(capabilityKey$1, version) {
|
|
119
|
+
const ancestors = [];
|
|
120
|
+
const visited = /* @__PURE__ */ new Set();
|
|
121
|
+
let current = this.get(capabilityKey$1, version);
|
|
122
|
+
while (current?.extends) {
|
|
123
|
+
const parentKey = capKey(current.extends.key, current.extends.version);
|
|
124
|
+
if (visited.has(parentKey)) break;
|
|
125
|
+
visited.add(parentKey);
|
|
126
|
+
const parent = this.get(current.extends.key, current.extends.version);
|
|
127
|
+
if (!parent) break;
|
|
128
|
+
ancestors.push(parent);
|
|
129
|
+
current = parent;
|
|
130
|
+
}
|
|
131
|
+
return ancestors;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get effective requirements for a capability, including inherited ones.
|
|
135
|
+
* Requirements from ancestors are included, with child requirements taking
|
|
136
|
+
* precedence over parent requirements for the same key.
|
|
137
|
+
*/
|
|
138
|
+
getEffectiveRequirements(capabilityKey$1, version) {
|
|
139
|
+
const spec = this.get(capabilityKey$1, version);
|
|
140
|
+
if (!spec) return [];
|
|
141
|
+
const ancestors = this.getAncestors(capabilityKey$1, version);
|
|
142
|
+
const requirementMap = /* @__PURE__ */ new Map();
|
|
143
|
+
for (const ancestor of [...ancestors].reverse()) for (const req of ancestor.requires ?? []) requirementMap.set(req.key, req);
|
|
144
|
+
for (const req of spec.requires ?? []) requirementMap.set(req.key, req);
|
|
145
|
+
return [...requirementMap.values()];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get all surfaces provided by a capability, including inherited ones.
|
|
149
|
+
*/
|
|
150
|
+
getEffectiveSurfaces(capabilityKey$1, version) {
|
|
151
|
+
const spec = this.get(capabilityKey$1, version);
|
|
152
|
+
if (!spec) return [];
|
|
153
|
+
const ancestors = this.getAncestors(capabilityKey$1, version);
|
|
154
|
+
const surfaces = [];
|
|
155
|
+
for (const ancestor of [...ancestors].reverse()) surfaces.push(...ancestor.provides ?? []);
|
|
156
|
+
surfaces.push(...spec.provides ?? []);
|
|
157
|
+
return surfaces;
|
|
158
|
+
}
|
|
34
159
|
};
|
|
35
160
|
function matchesRequirement(ref, requirement) {
|
|
36
161
|
if (ref.key !== requirement.key) return false;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CapabilityRef } from "./capabilities.js";
|
|
2
|
+
|
|
3
|
+
//#region src/capabilities/context.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Error thrown when a required capability is missing.
|
|
7
|
+
*/
|
|
8
|
+
declare class CapabilityMissingError extends Error {
|
|
9
|
+
readonly capabilityKey: string;
|
|
10
|
+
readonly requiredVersion?: string;
|
|
11
|
+
constructor(capabilityKey: string, requiredVersion?: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Runtime context for checking capability access.
|
|
15
|
+
*
|
|
16
|
+
* Created from a list of enabled capabilities (e.g., from user subscription,
|
|
17
|
+
* tenant config, or feature flags). Provides methods to check and require
|
|
18
|
+
* capabilities at runtime.
|
|
19
|
+
*/
|
|
20
|
+
interface CapabilityContext {
|
|
21
|
+
/** Set of enabled capability keys (without version). */
|
|
22
|
+
readonly capabilities: ReadonlySet<string>;
|
|
23
|
+
/** Map of capability key to version for version-specific checks. */
|
|
24
|
+
readonly capabilityVersions: ReadonlyMap<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a capability is enabled.
|
|
27
|
+
* @param key - Capability key to check
|
|
28
|
+
* @param version - Optional specific version to require
|
|
29
|
+
* @returns True if capability is enabled
|
|
30
|
+
*/
|
|
31
|
+
hasCapability(key: string, version?: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Require a capability, throwing if not enabled.
|
|
34
|
+
* @param key - Capability key to require
|
|
35
|
+
* @param version - Optional specific version to require
|
|
36
|
+
* @throws {CapabilityMissingError} If capability is not enabled
|
|
37
|
+
*/
|
|
38
|
+
requireCapability(key: string, version?: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Check if all specified capabilities are enabled.
|
|
41
|
+
* @param keys - Array of capability keys to check
|
|
42
|
+
* @returns True if all capabilities are enabled
|
|
43
|
+
*/
|
|
44
|
+
hasAllCapabilities(keys: string[]): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if any of the specified capabilities are enabled.
|
|
47
|
+
* @param keys - Array of capability keys to check
|
|
48
|
+
* @returns True if at least one capability is enabled
|
|
49
|
+
*/
|
|
50
|
+
hasAnyCapability(keys: string[]): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get enabled capabilities matching a pattern.
|
|
53
|
+
* @param pattern - Glob-like pattern (supports * wildcard)
|
|
54
|
+
* @returns Array of matching capability keys
|
|
55
|
+
*/
|
|
56
|
+
getMatchingCapabilities(pattern: string): string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a capability context from enabled capabilities.
|
|
60
|
+
*
|
|
61
|
+
* @param enabledCapabilities - Array of capability refs that are enabled
|
|
62
|
+
* @returns CapabilityContext for checking/requiring capabilities
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* // From user subscription capabilities
|
|
67
|
+
* const userCaps = await getUserCapabilities(userId);
|
|
68
|
+
* const ctx = createCapabilityContext(userCaps);
|
|
69
|
+
*
|
|
70
|
+
* // In handler
|
|
71
|
+
* ctx.requireCapability('premium-features');
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
declare function createCapabilityContext(enabledCapabilities: CapabilityRef[]): CapabilityContext;
|
|
75
|
+
/**
|
|
76
|
+
* Creates an empty capability context (no capabilities enabled).
|
|
77
|
+
* Useful for anonymous users or testing.
|
|
78
|
+
*/
|
|
79
|
+
declare function createEmptyCapabilityContext(): CapabilityContext;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a capability context with all capabilities enabled (bypass).
|
|
82
|
+
* Useful for admin users or internal services.
|
|
83
|
+
*
|
|
84
|
+
* @param allCapabilities - Array of all capability refs to enable
|
|
85
|
+
*/
|
|
86
|
+
declare function createBypassCapabilityContext(allCapabilities: CapabilityRef[]): CapabilityContext;
|
|
87
|
+
//#endregion
|
|
88
|
+
export { CapabilityContext, CapabilityMissingError, createBypassCapabilityContext, createCapabilityContext, createEmptyCapabilityContext };
|