@contractspec/lib.contracts 0.0.0-canary-20260119225944 → 0.0.0-canary-20260202053150
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 → app-config.contracts.d.ts} +52 -52
- package/dist/app-config/{contracts.js → app-config.contracts.js} +1 -1
- package/dist/app-config/lifecycle-contracts.d.ts +55 -55
- package/dist/app-config/runtime.d.ts +4 -4
- package/dist/app-config/spec.d.ts +2 -2
- 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/data-views.d.ts +2 -1
- package/dist/data-views/index.d.ts +2 -1
- package/dist/data-views/registry.d.ts +1 -1
- package/dist/data-views/report/contractVerificationTable.d.ts +10 -0
- package/dist/data-views/report/contractVerificationTable.js +95 -0
- package/dist/data-views/runtime.d.ts +2 -2
- package/dist/data-views/spec.d.ts +2 -8
- package/dist/data-views/types.d.ts +1 -1
- package/dist/docs/capabilities/documentationSystem.capability.d.ts +7 -0
- package/dist/docs/capabilities/documentationSystem.capability.js +71 -0
- package/dist/docs/capabilities/index.d.ts +2 -0
- package/dist/docs/capabilities/index.js +3 -0
- package/dist/docs/commands/docsGenerate.command.d.ts +95 -0
- package/dist/docs/commands/docsGenerate.command.js +142 -0
- package/dist/docs/commands/docsPublish.command.d.ts +64 -0
- package/dist/docs/commands/docsPublish.command.js +107 -0
- package/dist/docs/commands/index.d.ts +3 -0
- package/dist/docs/commands/index.js +4 -0
- package/dist/docs/constants.d.ts +7 -0
- package/dist/docs/constants.js +10 -0
- package/dist/docs/contracts.d.ts +442 -0
- package/dist/docs/contracts.js +58 -0
- package/dist/docs/ensure-docblocks.d.ts +1 -0
- package/dist/docs/ensure-docblocks.js +1 -0
- package/dist/docs/events/docsGenerated.event.d.ts +62 -0
- package/dist/docs/events/docsGenerated.event.js +53 -0
- package/dist/docs/events/docsPublished.event.d.ts +70 -0
- package/dist/docs/events/docsPublished.event.js +57 -0
- package/dist/docs/events/index.d.ts +3 -0
- package/dist/docs/events/index.js +4 -0
- package/dist/docs/forms/docsSearch.form.d.ts +22 -0
- package/dist/docs/forms/docsSearch.form.js +113 -0
- package/dist/docs/forms/index.d.ts +2 -0
- package/dist/docs/forms/index.js +3 -0
- package/dist/docs/index.d.ts +23 -2
- package/dist/docs/index.js +25 -1
- package/dist/docs/presentations/docsLayout.presentation.d.ts +7 -0
- package/dist/docs/presentations/docsLayout.presentation.js +35 -0
- package/dist/docs/presentations/docsReferencePage.presentation.d.ts +7 -0
- package/dist/docs/presentations/docsReferencePage.presentation.js +35 -0
- package/dist/docs/presentations/index.d.ts +3 -0
- package/dist/docs/presentations/index.js +4 -0
- package/dist/docs/queries/contractReference.query.d.ts +217 -0
- package/dist/docs/queries/contractReference.query.js +125 -0
- package/dist/docs/queries/docsIndex.query.d.ts +272 -0
- package/dist/docs/queries/docsIndex.query.js +133 -0
- package/dist/docs/queries/index.d.ts +3 -0
- package/dist/docs/queries/index.js +4 -0
- package/dist/docs/tech/cli.docblock.js +10 -0
- package/dist/docs/tech/docs-system.docblock.d.ts +1 -0
- package/dist/docs/tech/docs-system.docblock.js +128 -0
- package/dist/docs/tech/report-verification-table.docblock.d.ts +1 -0
- package/dist/docs/tech/report-verification-table.docblock.js +50 -0
- package/dist/docs/views/contractReference.dataView.d.ts +7 -0
- package/dist/docs/views/contractReference.dataView.js +80 -0
- package/dist/docs/views/docsIndex.dataView.d.ts +7 -0
- package/dist/docs/views/docsIndex.dataView.js +136 -0
- package/dist/docs/views/exampleCatalog.dataView.d.ts +7 -0
- package/dist/docs/views/exampleCatalog.dataView.js +91 -0
- package/dist/docs/views/index.d.ts +4 -0
- package/dist/docs/views/index.js +5 -0
- package/dist/events.d.ts +80 -14
- package/dist/events.js +33 -3
- package/dist/examples/schema.d.ts +12 -12
- package/dist/examples/types.d.ts +1 -1
- package/dist/experiments/spec.d.ts +9 -6
- package/dist/features/index.d.ts +2 -2
- package/dist/features/install.d.ts +4 -4
- package/dist/features/types.d.ts +28 -32
- package/dist/forms/forms.d.ts +1 -1
- package/dist/index.d.ts +60 -31
- package/dist/index.js +32 -4
- 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 +2 -2
- package/dist/jsonschema.d.ts +1 -1
- package/dist/knowledge/operations.d.ts +67 -67
- package/dist/knowledge/spec.d.ts +1 -1
- package/dist/llm/exporters.d.ts +4 -4
- package/dist/llm/types.d.ts +1 -1
- package/dist/markdown.d.ts +2 -2
- package/dist/operations/index.d.ts +4 -1
- package/dist/operations/index.js +4 -1
- package/dist/operations/operation.d.ts +8 -2
- package/dist/operations/registry.d.ts +1 -1
- package/dist/operations/report/getContractVerificationStatus.d.ts +75 -0
- package/dist/operations/report/getContractVerificationStatus.js +96 -0
- package/dist/operations/report/index.d.ts +13 -0
- package/dist/operations/report/index.js +45 -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/presentations/registry.d.ts +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/serialization/index.d.ts +3 -0
- package/dist/serialization/index.js +3 -0
- package/dist/serialization/serializers.d.ts +40 -0
- package/dist/serialization/serializers.js +148 -0
- package/dist/serialization/types.d.ts +103 -0
- package/dist/serialization/types.js +0 -0
- package/dist/server/rest-elysia.d.ts +1 -1
- package/dist/server/rest-express.d.ts +1 -1
- package/dist/server/rest-generic.d.ts +1 -1
- package/dist/server/rest-next-app.d.ts +1 -1
- package/dist/server/rest-next-mcp.d.ts +1 -1
- package/dist/server/rest-next-pages.d.ts +1 -1
- package/dist/telemetry/spec.d.ts +1 -1
- package/dist/telemetry/tracker.d.ts +3 -2
- package/dist/tests/runner.d.ts +1 -1
- package/dist/tests/spec.d.ts +17 -12
- package/dist/themes.d.ts +8 -5
- 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 +142 -16
- 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 +6 -3
- package/dist/workflow/index.js +4 -2
- package/dist/workflow/spec.d.ts +4 -11
- package/dist/workflow/validation.d.ts +64 -2
- package/dist/workflow/validation.js +194 -1
- package/dist/workspace-config/contractsrc-schema.d.ts +3 -3
- package/dist/workspace-config/contractsrc-schema.js +1 -0
- package/dist/workspace-config/contractsrc-types.d.ts +7 -8
- package/dist/workspace-config/index.d.ts +2 -2
- package/package.json +52 -9
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { installOp } from "../../install.js";
|
|
2
|
+
import { ContractVerificationStatusModel, GetContractVerificationStatusInput, GetContractVerificationStatusOutput, GetContractVerificationStatusQuery } from "./getContractVerificationStatus.js";
|
|
3
|
+
import { ContractVerificationTableDataView } from "../../data-views/report/contractVerificationTable.js";
|
|
4
|
+
|
|
5
|
+
//#region src/operations/report/index.ts
|
|
6
|
+
const getContractVerificationStatusHandler = async (input, _ctx) => {
|
|
7
|
+
try {
|
|
8
|
+
const cmdStdout = await Bun.spawn([
|
|
9
|
+
"contractspec",
|
|
10
|
+
"impl",
|
|
11
|
+
"status",
|
|
12
|
+
"--format",
|
|
13
|
+
"json",
|
|
14
|
+
"--all"
|
|
15
|
+
], { cwd: input.projectPath }).stdout;
|
|
16
|
+
const output = await Bun.readableStreamToText(cmdStdout);
|
|
17
|
+
if (!output) return { contracts: [] };
|
|
18
|
+
const cliOutput = JSON.parse(output);
|
|
19
|
+
const contracts = [];
|
|
20
|
+
for (const spec of cliOutput.results || []) {
|
|
21
|
+
const contract = {
|
|
22
|
+
name: spec.specKey,
|
|
23
|
+
lastVerifiedSha: spec.specHash,
|
|
24
|
+
lastVerifiedDate: spec.specHash ? (/* @__PURE__ */ new Date()).toISOString() : void 0,
|
|
25
|
+
surfaces: spec.implementations.filter((impl) => impl.exists).map((impl) => impl.type),
|
|
26
|
+
driftMismatches: spec.implementations.filter((impl) => !impl.exists).length
|
|
27
|
+
};
|
|
28
|
+
contracts.push(contract);
|
|
29
|
+
}
|
|
30
|
+
return { contracts };
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Failed to get contract verification status:", error);
|
|
33
|
+
return { contracts: [] };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Register report-related operation contracts in the given registry.
|
|
38
|
+
*/
|
|
39
|
+
function registerReportContracts(registry) {
|
|
40
|
+
installOp(registry, GetContractVerificationStatusQuery, getContractVerificationStatusHandler);
|
|
41
|
+
return registry;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { ContractVerificationStatusModel, ContractVerificationTableDataView, GetContractVerificationStatusInput, GetContractVerificationStatusOutput, GetContractVerificationStatusQuery, getContractVerificationStatusHandler, registerReportContracts };
|
package/dist/ownership.d.ts
CHANGED
|
@@ -2,82 +2,207 @@ import { DocId } from "./docs/registry.js";
|
|
|
2
2
|
import "./docs/index.js";
|
|
3
3
|
|
|
4
4
|
//#region src/ownership.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Lifecycle stability stages for specs.
|
|
8
|
+
*
|
|
9
|
+
* Specs progress through these stages as they mature:
|
|
10
|
+
* - `idea`: Initial concept, not implemented
|
|
11
|
+
* - `in_creation`: Currently being built
|
|
12
|
+
* - `experimental`: Working but may change significantly
|
|
13
|
+
* - `beta`: Feature-complete, seeking feedback
|
|
14
|
+
* - `stable`: Production-ready, breaking changes require major version bump
|
|
15
|
+
* - `deprecated`: Scheduled for removal, use alternatives
|
|
16
|
+
*/
|
|
5
17
|
declare const StabilityEnum: {
|
|
18
|
+
/** Initial concept, not yet implemented. */
|
|
6
19
|
readonly Idea: "idea";
|
|
20
|
+
/** Currently being built, not ready for use. */
|
|
7
21
|
readonly InCreation: "in_creation";
|
|
22
|
+
/** Working but unstable, may change significantly. */
|
|
8
23
|
readonly Experimental: "experimental";
|
|
24
|
+
/** Feature-complete, seeking feedback before stabilization. */
|
|
9
25
|
readonly Beta: "beta";
|
|
26
|
+
/** Production-ready, follows semantic versioning. */
|
|
10
27
|
readonly Stable: "stable";
|
|
28
|
+
/** Scheduled for removal, use alternatives. */
|
|
11
29
|
readonly Deprecated: "deprecated";
|
|
12
30
|
};
|
|
31
|
+
/** Stability level for a spec's lifecycle stage. */
|
|
13
32
|
type Stability = (typeof StabilityEnum)[keyof typeof StabilityEnum];
|
|
33
|
+
/**
|
|
34
|
+
* Curated owner identifiers for business/product ownership.
|
|
35
|
+
*
|
|
36
|
+
* Used for CODEOWNERS, on-call routing, and approval workflows.
|
|
37
|
+
* Custom owner strings are also allowed for flexibility.
|
|
38
|
+
*/
|
|
14
39
|
declare const OwnersEnum: {
|
|
40
|
+
/** Core platform team. */
|
|
15
41
|
readonly PlatformCore: "platform.core";
|
|
42
|
+
/** Sigil/auth team. */
|
|
16
43
|
readonly PlatformSigil: "platform.sigil";
|
|
44
|
+
/** Marketplace team. */
|
|
17
45
|
readonly PlatformMarketplace: "platform.marketplace";
|
|
46
|
+
/** Messaging/notifications team. */
|
|
18
47
|
readonly PlatformMessaging: "platform.messaging";
|
|
48
|
+
/** Content/CMS team. */
|
|
19
49
|
readonly PlatformContent: "platform.content";
|
|
50
|
+
/** Feature flags team. */
|
|
20
51
|
readonly PlatformFeatureFlags: "platform.featureflags";
|
|
52
|
+
/** Finance/billing team. */
|
|
21
53
|
readonly PlatformFinance: "platform.finance";
|
|
22
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Owner identifier for a spec.
|
|
57
|
+
* Can be a predefined OwnersEnum value or any custom string.
|
|
58
|
+
*/
|
|
23
59
|
type Owner = (typeof OwnersEnum)[keyof typeof OwnersEnum] | (string & {});
|
|
60
|
+
/** @deprecated Use OwnersEnum instead. */
|
|
24
61
|
declare const Owners: {
|
|
62
|
+
/** Core platform team. */
|
|
25
63
|
readonly PlatformCore: "platform.core";
|
|
64
|
+
/** Sigil/auth team. */
|
|
26
65
|
readonly PlatformSigil: "platform.sigil";
|
|
66
|
+
/** Marketplace team. */
|
|
27
67
|
readonly PlatformMarketplace: "platform.marketplace";
|
|
68
|
+
/** Messaging/notifications team. */
|
|
28
69
|
readonly PlatformMessaging: "platform.messaging";
|
|
70
|
+
/** Content/CMS team. */
|
|
29
71
|
readonly PlatformContent: "platform.content";
|
|
72
|
+
/** Feature flags team. */
|
|
30
73
|
readonly PlatformFeatureFlags: "platform.featureflags";
|
|
74
|
+
/** Finance/billing team. */
|
|
31
75
|
readonly PlatformFinance: "platform.finance";
|
|
32
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Common tags for categorizing specs.
|
|
79
|
+
*
|
|
80
|
+
* Used for search, grouping, and documentation navigation.
|
|
81
|
+
* Custom tag strings are also allowed for flexibility.
|
|
82
|
+
*/
|
|
33
83
|
declare const TagsEnum: {
|
|
84
|
+
/** Spots/locations domain. */
|
|
34
85
|
readonly Spots: "spots";
|
|
86
|
+
/** Collectivity/community domain. */
|
|
35
87
|
readonly Collectivity: "collectivity";
|
|
88
|
+
/** Marketplace domain. */
|
|
36
89
|
readonly Marketplace: "marketplace";
|
|
90
|
+
/** Seller-related features. */
|
|
37
91
|
readonly Sellers: "sellers";
|
|
92
|
+
/** Authentication features. */
|
|
38
93
|
readonly Auth: "auth";
|
|
94
|
+
/** Login flows. */
|
|
39
95
|
readonly Login: "login";
|
|
96
|
+
/** Signup flows. */
|
|
40
97
|
readonly Signup: "signup";
|
|
98
|
+
/** Onboarding/guides. */
|
|
41
99
|
readonly Guide: "guide";
|
|
100
|
+
/** Documentation. */
|
|
42
101
|
readonly Docs: "docs";
|
|
102
|
+
/** Internationalization. */
|
|
43
103
|
readonly I18n: "i18n";
|
|
104
|
+
/** Incident management. */
|
|
44
105
|
readonly Incident: "incident";
|
|
106
|
+
/** Automation/workflows. */
|
|
45
107
|
readonly Automation: "automation";
|
|
108
|
+
/** Code hygiene/maintenance. */
|
|
46
109
|
readonly Hygiene: "hygiene";
|
|
47
110
|
};
|
|
111
|
+
/**
|
|
112
|
+
* Tag for categorizing a spec.
|
|
113
|
+
* Can be a predefined TagsEnum value or any custom string.
|
|
114
|
+
*/
|
|
48
115
|
type Tag = (typeof TagsEnum)[keyof typeof TagsEnum] | (string & {});
|
|
116
|
+
/** @deprecated Use TagsEnum instead. */
|
|
49
117
|
declare const Tags: {
|
|
118
|
+
/** Spots/locations domain. */
|
|
50
119
|
readonly Spots: "spots";
|
|
120
|
+
/** Collectivity/community domain. */
|
|
51
121
|
readonly Collectivity: "collectivity";
|
|
122
|
+
/** Marketplace domain. */
|
|
52
123
|
readonly Marketplace: "marketplace";
|
|
124
|
+
/** Seller-related features. */
|
|
53
125
|
readonly Sellers: "sellers";
|
|
126
|
+
/** Authentication features. */
|
|
54
127
|
readonly Auth: "auth";
|
|
128
|
+
/** Login flows. */
|
|
55
129
|
readonly Login: "login";
|
|
130
|
+
/** Signup flows. */
|
|
56
131
|
readonly Signup: "signup";
|
|
132
|
+
/** Onboarding/guides. */
|
|
57
133
|
readonly Guide: "guide";
|
|
134
|
+
/** Documentation. */
|
|
58
135
|
readonly Docs: "docs";
|
|
136
|
+
/** Internationalization. */
|
|
59
137
|
readonly I18n: "i18n";
|
|
138
|
+
/** Incident management. */
|
|
60
139
|
readonly Incident: "incident";
|
|
140
|
+
/** Automation/workflows. */
|
|
61
141
|
readonly Automation: "automation";
|
|
142
|
+
/** Code hygiene/maintenance. */
|
|
62
143
|
readonly Hygiene: "hygiene";
|
|
63
144
|
};
|
|
145
|
+
/**
|
|
146
|
+
* Common metadata interface for all ContractSpec specifications.
|
|
147
|
+
*
|
|
148
|
+
* Every spec type (operations, events, presentations, etc.) extends this
|
|
149
|
+
* interface to provide consistent ownership, versioning, and discoverability.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const meta: OwnerShipMeta = {
|
|
154
|
+
* key: 'auth.login',
|
|
155
|
+
* version: '1.0.0',
|
|
156
|
+
* description: 'Authenticates a user with email and password',
|
|
157
|
+
* stability: StabilityEnum.Stable,
|
|
158
|
+
* owners: [OwnersEnum.PlatformSigil],
|
|
159
|
+
* tags: [TagsEnum.Auth, TagsEnum.Login],
|
|
160
|
+
* };
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
64
163
|
interface OwnerShipMeta {
|
|
65
|
-
/**
|
|
164
|
+
/**
|
|
165
|
+
* Semantic version string (e.g., "1.0.0").
|
|
166
|
+
* Bump for breaking changes according to semver rules.
|
|
167
|
+
*/
|
|
66
168
|
version: string;
|
|
67
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* Fully-qualified spec key (e.g., "sigil.beginSignup", "user.created").
|
|
171
|
+
* Must be unique within the spec type.
|
|
172
|
+
*/
|
|
68
173
|
key: string;
|
|
69
|
-
/**
|
|
174
|
+
/**
|
|
175
|
+
* Human-friendly title (e.g., "Begin Signup").
|
|
176
|
+
* Used in documentation and UI.
|
|
177
|
+
*/
|
|
70
178
|
title?: string;
|
|
71
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Short human-friendly summary of what this spec does.
|
|
181
|
+
* Should be concise (1-2 sentences).
|
|
182
|
+
*/
|
|
72
183
|
description: string;
|
|
184
|
+
/**
|
|
185
|
+
* Business domain this spec belongs to (e.g., "auth", "marketplace").
|
|
186
|
+
* Used for grouping and discovery.
|
|
187
|
+
*/
|
|
73
188
|
domain?: string;
|
|
74
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* Lifecycle stability marker.
|
|
191
|
+
* Indicates maturity level and change expectations.
|
|
192
|
+
*/
|
|
75
193
|
stability: Stability;
|
|
76
|
-
/**
|
|
194
|
+
/**
|
|
195
|
+
* Team/individual owners responsible for this spec.
|
|
196
|
+
* Used for CODEOWNERS, on-call routing, and approvals.
|
|
197
|
+
*/
|
|
77
198
|
owners: Owner[];
|
|
78
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Tags for search, grouping, and documentation navigation.
|
|
201
|
+
*/
|
|
79
202
|
tags: Tag[];
|
|
80
|
-
/**
|
|
203
|
+
/**
|
|
204
|
+
* Associated DocBlock identifiers for documentation linkage.
|
|
205
|
+
*/
|
|
81
206
|
docId?: DocId[];
|
|
82
207
|
}
|
|
83
208
|
//#endregion
|
package/dist/ownership.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
//#region src/ownership.ts
|
|
2
|
+
/**
|
|
3
|
+
* Lifecycle stability stages for specs.
|
|
4
|
+
*
|
|
5
|
+
* Specs progress through these stages as they mature:
|
|
6
|
+
* - `idea`: Initial concept, not implemented
|
|
7
|
+
* - `in_creation`: Currently being built
|
|
8
|
+
* - `experimental`: Working but may change significantly
|
|
9
|
+
* - `beta`: Feature-complete, seeking feedback
|
|
10
|
+
* - `stable`: Production-ready, breaking changes require major version bump
|
|
11
|
+
* - `deprecated`: Scheduled for removal, use alternatives
|
|
12
|
+
*/
|
|
2
13
|
const StabilityEnum = {
|
|
3
14
|
Idea: "idea",
|
|
4
15
|
InCreation: "in_creation",
|
|
@@ -7,6 +18,12 @@ const StabilityEnum = {
|
|
|
7
18
|
Stable: "stable",
|
|
8
19
|
Deprecated: "deprecated"
|
|
9
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Curated owner identifiers for business/product ownership.
|
|
23
|
+
*
|
|
24
|
+
* Used for CODEOWNERS, on-call routing, and approval workflows.
|
|
25
|
+
* Custom owner strings are also allowed for flexibility.
|
|
26
|
+
*/
|
|
10
27
|
const OwnersEnum = {
|
|
11
28
|
PlatformCore: "platform.core",
|
|
12
29
|
PlatformSigil: "platform.sigil",
|
|
@@ -16,7 +33,14 @@ const OwnersEnum = {
|
|
|
16
33
|
PlatformFeatureFlags: "platform.featureflags",
|
|
17
34
|
PlatformFinance: "platform.finance"
|
|
18
35
|
};
|
|
36
|
+
/** @deprecated Use OwnersEnum instead. */
|
|
19
37
|
const Owners = OwnersEnum;
|
|
38
|
+
/**
|
|
39
|
+
* Common tags for categorizing specs.
|
|
40
|
+
*
|
|
41
|
+
* Used for search, grouping, and documentation navigation.
|
|
42
|
+
* Custom tag strings are also allowed for flexibility.
|
|
43
|
+
*/
|
|
20
44
|
const TagsEnum = {
|
|
21
45
|
Spots: "spots",
|
|
22
46
|
Collectivity: "collectivity",
|
|
@@ -32,6 +56,7 @@ const TagsEnum = {
|
|
|
32
56
|
Automation: "automation",
|
|
33
57
|
Hygiene: "hygiene"
|
|
34
58
|
};
|
|
59
|
+
/** @deprecated Use TagsEnum instead. */
|
|
35
60
|
const Tags = TagsEnum;
|
|
36
61
|
|
|
37
62
|
//#endregion
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
//#region src/policy/context.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Runtime policy context for opt-in policy enforcement.
|
|
4
|
+
*
|
|
5
|
+
* Provides a context object that can be used to check if a user/tenant
|
|
6
|
+
* has specific roles, permissions, and attributes at runtime.
|
|
7
|
+
*
|
|
8
|
+
* @module policy/context
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { createPolicyContext } from '@contractspec/lib.contracts';
|
|
13
|
+
*
|
|
14
|
+
* // Create context from user's roles and permissions
|
|
15
|
+
* const ctx = createPolicyContext({
|
|
16
|
+
* id: 'user-123',
|
|
17
|
+
* tenantId: 'tenant-456',
|
|
18
|
+
* roles: ['admin', 'editor'],
|
|
19
|
+
* permissions: ['read:articles', 'write:articles'],
|
|
20
|
+
* attributes: { department: 'engineering' },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Check roles and permissions
|
|
24
|
+
* if (ctx.hasRole('admin')) {
|
|
25
|
+
* // User has admin role
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* // Audit access attempts
|
|
29
|
+
* ctx.auditAccess('article.update', 'allowed');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Error thrown when a policy violation occurs.
|
|
34
|
+
*/
|
|
35
|
+
declare class PolicyViolationError extends Error {
|
|
36
|
+
readonly violationType: PolicyViolationType;
|
|
37
|
+
readonly details: PolicyViolationDetails;
|
|
38
|
+
constructor(type: PolicyViolationType, details: PolicyViolationDetails);
|
|
39
|
+
}
|
|
40
|
+
type PolicyViolationType = 'missing_role' | 'missing_permission' | 'missing_attribute' | 'rate_limit_exceeded' | 'consent_required' | 'access_denied';
|
|
41
|
+
interface PolicyViolationDetails {
|
|
42
|
+
operation?: string;
|
|
43
|
+
requiredRole?: string;
|
|
44
|
+
requiredPermission?: string;
|
|
45
|
+
requiredAttribute?: {
|
|
46
|
+
key: string;
|
|
47
|
+
expected: unknown;
|
|
48
|
+
};
|
|
49
|
+
rateLimitKey?: string;
|
|
50
|
+
consentIds?: string[];
|
|
51
|
+
reason?: string;
|
|
52
|
+
}
|
|
53
|
+
interface RateLimitResult {
|
|
54
|
+
allowed: boolean;
|
|
55
|
+
remaining: number;
|
|
56
|
+
resetAt?: Date;
|
|
57
|
+
retryAfterMs?: number;
|
|
58
|
+
}
|
|
59
|
+
interface RateLimitState {
|
|
60
|
+
key: string;
|
|
61
|
+
count: number;
|
|
62
|
+
windowStart: number;
|
|
63
|
+
windowMs: number;
|
|
64
|
+
limit: number;
|
|
65
|
+
}
|
|
66
|
+
interface AuditEntry {
|
|
67
|
+
timestamp: Date;
|
|
68
|
+
operation: string;
|
|
69
|
+
result: 'allowed' | 'denied';
|
|
70
|
+
reason?: string;
|
|
71
|
+
userId?: string;
|
|
72
|
+
tenantId?: string;
|
|
73
|
+
attributes?: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
type AuditHandler = (entry: AuditEntry) => void | Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* User information for policy evaluation.
|
|
78
|
+
*/
|
|
79
|
+
interface PolicyUser {
|
|
80
|
+
/** Unique user identifier. */
|
|
81
|
+
id: string;
|
|
82
|
+
/** Optional tenant/organization ID for multi-tenant contexts. */
|
|
83
|
+
tenantId?: string;
|
|
84
|
+
/** Roles assigned to the user. */
|
|
85
|
+
roles: string[];
|
|
86
|
+
/** Permissions granted to the user. */
|
|
87
|
+
permissions: string[];
|
|
88
|
+
/** Additional attributes for ABAC evaluation. */
|
|
89
|
+
attributes: Record<string, unknown>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Runtime context for checking policy access.
|
|
93
|
+
*
|
|
94
|
+
* Created from user information (roles, permissions, attributes).
|
|
95
|
+
* Provides methods to check and require policy compliance at runtime.
|
|
96
|
+
*/
|
|
97
|
+
interface PolicyContext {
|
|
98
|
+
/** The user for this context. */
|
|
99
|
+
readonly user: PolicyUser;
|
|
100
|
+
/** Set of user roles. */
|
|
101
|
+
readonly roles: ReadonlySet<string>;
|
|
102
|
+
/** Set of user permissions. */
|
|
103
|
+
readonly permissions: ReadonlySet<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Check if user has a specific role.
|
|
106
|
+
* @param role - Role to check
|
|
107
|
+
* @returns True if user has the role
|
|
108
|
+
*/
|
|
109
|
+
hasRole(role: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Check if user has any of the specified roles.
|
|
112
|
+
* @param roles - Roles to check
|
|
113
|
+
* @returns True if user has at least one role
|
|
114
|
+
*/
|
|
115
|
+
hasAnyRole(roles: string[]): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Check if user has all of the specified roles.
|
|
118
|
+
* @param roles - Roles to check
|
|
119
|
+
* @returns True if user has all roles
|
|
120
|
+
*/
|
|
121
|
+
hasAllRoles(roles: string[]): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Require a role, throwing if not present.
|
|
124
|
+
* @param role - Role to require
|
|
125
|
+
* @throws {PolicyViolationError} If role is missing
|
|
126
|
+
*/
|
|
127
|
+
requireRole(role: string): void;
|
|
128
|
+
/**
|
|
129
|
+
* Check if user has a specific permission.
|
|
130
|
+
* @param permission - Permission to check
|
|
131
|
+
* @returns True if user has the permission
|
|
132
|
+
*/
|
|
133
|
+
hasPermission(permission: string): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Check if user has any of the specified permissions.
|
|
136
|
+
* @param permissions - Permissions to check
|
|
137
|
+
* @returns True if user has at least one permission
|
|
138
|
+
*/
|
|
139
|
+
hasAnyPermission(permissions: string[]): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Check if user has all of the specified permissions.
|
|
142
|
+
* @param permissions - Permissions to check
|
|
143
|
+
* @returns True if user has all permissions
|
|
144
|
+
*/
|
|
145
|
+
hasAllPermissions(permissions: string[]): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Require a permission, throwing if not present.
|
|
148
|
+
* @param permission - Permission to require
|
|
149
|
+
* @throws {PolicyViolationError} If permission is missing
|
|
150
|
+
*/
|
|
151
|
+
requirePermission(permission: string): void;
|
|
152
|
+
/**
|
|
153
|
+
* Get a user attribute value.
|
|
154
|
+
* @param key - Attribute key
|
|
155
|
+
* @returns Attribute value or undefined
|
|
156
|
+
*/
|
|
157
|
+
getAttribute<T = unknown>(key: string): T | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Check if an attribute matches an expected value.
|
|
160
|
+
* @param key - Attribute key
|
|
161
|
+
* @param expected - Expected value
|
|
162
|
+
* @returns True if attribute equals expected value
|
|
163
|
+
*/
|
|
164
|
+
checkAttribute(key: string, expected: unknown): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Check if an attribute is one of the allowed values.
|
|
167
|
+
* @param key - Attribute key
|
|
168
|
+
* @param allowedValues - Array of allowed values
|
|
169
|
+
* @returns True if attribute is in allowed values
|
|
170
|
+
*/
|
|
171
|
+
checkAttributeOneOf(key: string, allowedValues: unknown[]): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Check rate limit for a key.
|
|
174
|
+
* @param key - Rate limit key (e.g., operation name)
|
|
175
|
+
* @returns Rate limit result
|
|
176
|
+
*/
|
|
177
|
+
checkRateLimit(key: string): RateLimitResult;
|
|
178
|
+
/**
|
|
179
|
+
* Consume rate limit for a key (increment counter).
|
|
180
|
+
* @param key - Rate limit key
|
|
181
|
+
* @param cost - Cost of the operation (default: 1)
|
|
182
|
+
* @returns Rate limit result after consumption
|
|
183
|
+
*/
|
|
184
|
+
consumeRateLimit(key: string, cost?: number): RateLimitResult;
|
|
185
|
+
/**
|
|
186
|
+
* Record an access attempt for audit purposes.
|
|
187
|
+
* @param operation - Operation being accessed
|
|
188
|
+
* @param result - Whether access was allowed or denied
|
|
189
|
+
* @param reason - Optional reason for the decision
|
|
190
|
+
*/
|
|
191
|
+
auditAccess(operation: string, result: 'allowed' | 'denied', reason?: string): void;
|
|
192
|
+
}
|
|
193
|
+
interface PolicyContextOptions {
|
|
194
|
+
/** Rate limit configurations by key. */
|
|
195
|
+
rateLimits?: Record<string, {
|
|
196
|
+
limit: number;
|
|
197
|
+
windowMs: number;
|
|
198
|
+
}>;
|
|
199
|
+
/** Handler for audit entries. */
|
|
200
|
+
auditHandler?: AuditHandler;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Creates a policy context from user information.
|
|
204
|
+
*
|
|
205
|
+
* @param user - User information for policy evaluation
|
|
206
|
+
* @param options - Additional context options
|
|
207
|
+
* @returns PolicyContext for checking/requiring policy compliance
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const ctx = createPolicyContext({
|
|
212
|
+
* id: 'user-123',
|
|
213
|
+
* roles: ['editor'],
|
|
214
|
+
* permissions: ['read:articles'],
|
|
215
|
+
* attributes: { department: 'marketing' },
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* ctx.requireRole('editor');
|
|
219
|
+
* ctx.requirePermission('read:articles');
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
declare function createPolicyContext(user: PolicyUser, options?: PolicyContextOptions): PolicyContext;
|
|
223
|
+
/**
|
|
224
|
+
* Creates an empty policy context (no roles/permissions).
|
|
225
|
+
* Useful for anonymous users or testing.
|
|
226
|
+
*/
|
|
227
|
+
declare function createAnonymousPolicyContext(options?: PolicyContextOptions): PolicyContext;
|
|
228
|
+
/**
|
|
229
|
+
* Creates a bypass policy context with all roles/permissions.
|
|
230
|
+
* Useful for admin users or internal services.
|
|
231
|
+
*
|
|
232
|
+
* @param allRoles - All roles to grant
|
|
233
|
+
* @param allPermissions - All permissions to grant
|
|
234
|
+
*/
|
|
235
|
+
declare function createBypassPolicyContext(allRoles: string[], allPermissions: string[], options?: PolicyContextOptions): PolicyContext;
|
|
236
|
+
//#endregion
|
|
237
|
+
export { AuditEntry, AuditHandler, PolicyContext, PolicyContextOptions, PolicyUser, PolicyViolationDetails, PolicyViolationError, PolicyViolationType, RateLimitResult, RateLimitState, createAnonymousPolicyContext, createBypassPolicyContext, createPolicyContext };
|