-
Notifications
You must be signed in to change notification settings - Fork 197
feat(api): add governance query operation #4329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7cc5aa0
feat(api): add governance query operation
tothandras f26e34c
chore(api): update API skills and enforce doc formatting
tothandras c99e870
chore: address comments
tothandras e108cf2
chore: update spec
tothandras a99a984
chore: update spec
tothandras 09e4566
chore: fix
tothandras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| import "../shared/index.tsp"; | ||
| import "../common/pagination.tsp"; | ||
| import "../customers/customer.tsp"; | ||
|
|
||
| namespace Governance; | ||
|
|
||
| /** | ||
| * List of customer identifiers to evaluate access for. | ||
| */ | ||
| @friendlyName("GovernanceQueryRequestCustomers") | ||
| model GovernanceQueryRequestCustomers { | ||
| /** | ||
| * Each entry can be a customer `key` or a usage-attribution subject `key`. | ||
| * Identifiers that cannot be resolved to a customer are reported in the response | ||
| * `errors` array. | ||
| */ | ||
| @summary("Customer keys and usage-attribution subjects") | ||
| @minItems(1) | ||
| @maxItems(100) | ||
| keys: string[]; | ||
| } | ||
|
|
||
| /** | ||
| * Optional list of feature keys to evaluate access for. If omitted, all features | ||
| * available in the organization are returned. Providing this list is recommended | ||
| * to reduce the response size and the load on the backend services. | ||
| */ | ||
| @friendlyName("GovernanceQueryRequestFeatures") | ||
| model GovernanceQueryRequestFeatures { | ||
| /** | ||
| * List of feature keys to evaluate access for. | ||
| */ | ||
| @summary("Feature Keys") | ||
| @minItems(1) | ||
| @maxItems(100) | ||
| keys: string[]; | ||
| } | ||
|
|
||
| /** | ||
| * Query to evaluate feature access for a list of customers. | ||
| */ | ||
| @friendlyName("GovernanceQueryRequest") | ||
| model GovernanceQueryRequest { | ||
| /** | ||
| * Whether to include credit balance availability for each resolved customer. When | ||
| * true, each feature evaluation includes credit balance checks. | ||
| * | ||
| * Defaults to `false`. | ||
| */ | ||
| @summary("Include credits") | ||
| include_credits?: boolean = false; | ||
|
|
||
| #suppress "@openmeter/api-spec-aip/doc-decorator" "-" | ||
| @summary("Customer") | ||
| customer: GovernanceQueryRequestCustomers; | ||
|
|
||
| #suppress "@openmeter/api-spec-aip/doc-decorator" "-" | ||
| @summary("Feature") | ||
| feature?: GovernanceQueryRequestFeatures; | ||
| } | ||
|
|
||
| /** | ||
| * Response of the governance query. | ||
| */ | ||
| @friendlyName("GovernanceQueryResponse") | ||
| model GovernanceQueryResponse { | ||
| /** | ||
| * Access evaluation results, one entry per resolved customer. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Data") | ||
| data: GovernanceQueryResult[]; | ||
|
|
||
| /** | ||
| * Partial errors encountered while processing the request. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Errors") | ||
| errors: GovernanceQueryError[]; | ||
|
|
||
| /** | ||
| * Pagination metadata. The endpoint may return a partial response if the full | ||
| * response would exceed server-side limits. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Meta") | ||
| meta: Common.CursorMeta; | ||
| } | ||
|
|
||
| /** | ||
| * Access evaluation result for a single resolved customer. | ||
| */ | ||
| @friendlyName("GovernanceQueryResult") | ||
| model GovernanceQueryResult { | ||
| /** | ||
| * The list of identifiers from the request that resolved to this customer. Each | ||
| * entry is either the customer `key` or one of its usage-attribution subject | ||
| * `key`s. | ||
| * | ||
| * Duplicate or aliased identifiers that resolve to the same customer collapse to a | ||
| * single result entry, with every requested identifier listed here. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Matched identifiers") | ||
| matched: string[]; | ||
|
|
||
| /** | ||
| * The customer the matched identifiers resolved to. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Customer") | ||
| customer: Customers.Customer; | ||
|
|
||
| /** | ||
| * Map of features with their access status. | ||
| * | ||
| * Map keys are the feature keys requested in `feature.keys`, or every feature | ||
| * `key` available in the organization when the feature filter was omitted. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Features") | ||
| features: Record<GovernanceFeatureAccess>; | ||
|
|
||
| /** | ||
| * Timestamp of the most recent change to the customer's access state reflected in | ||
| * this result. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Updated at") | ||
| updated_at: Shared.DateTime; | ||
| } | ||
|
|
||
| /** | ||
| * Access status for a single feature. | ||
| */ | ||
| @friendlyName("GovernanceFeatureAccess") | ||
| model GovernanceFeatureAccess { | ||
|
gergely-kurucz-konghq marked this conversation as resolved.
|
||
| /** | ||
| * Whether the customer currently has access to the feature. | ||
| * | ||
| * `true` for boolean and static entitlements that are available, and for metered | ||
| * entitlements with remaining balance. `false` when the feature is unavailable, | ||
| * the usage limit has been reached, or (when applicable) credits have been | ||
| * exhausted. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Has access") | ||
| has_access: boolean; | ||
|
|
||
| /** | ||
| * Optional reason when the customer does not have access to the feature. Populated | ||
| * when `has_access` is `false`. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Reason") | ||
| reason?: GovernanceFeatureAccessReason; | ||
| } | ||
|
|
||
| /** | ||
| * Reason a feature is not accessible to a customer. | ||
| */ | ||
| @friendlyName("GovernanceFeatureAccessReason") | ||
| model GovernanceFeatureAccessReason | ||
| is Shared.BaseError<GovernanceFeatureAccessReasonCode>; | ||
|
|
||
| /** | ||
| * Machine-readable reason code for denied feature access. | ||
| */ | ||
| @friendlyName("GovernanceFeatureAccessReasonCode") | ||
| enum GovernanceFeatureAccessReasonCode { | ||
| /** | ||
| * Default zero value. Reserved for forward compatibility. | ||
| */ | ||
| Unknown: "unknown", | ||
|
|
||
| /** | ||
| * The customer has reached the metered usage limit for the feature | ||
| * within the current usage period. | ||
| */ | ||
| UsageLimitReached: "usage_limit_reached", | ||
|
|
||
| /** | ||
| * The feature is not available to the customer. | ||
| */ | ||
| FeatureUnavailable: "feature_unavailable", | ||
|
|
||
| /** | ||
| * The feature `key` referenced by the request is not configured in the | ||
| * organization. | ||
| */ | ||
| FeatureNotFound: "feature_not_found", | ||
|
|
||
| /** | ||
| * The customer has no available prepaid credit balance. | ||
|
tothandras marked this conversation as resolved.
|
||
| */ | ||
| NoCreditAvailable: "no_credit_available", | ||
| } | ||
|
|
||
| /** | ||
| * Query error within a partially successful governance query response. | ||
| */ | ||
| @friendlyName("GovernanceQueryError") | ||
| model GovernanceQueryError is Shared.BaseError<GovernanceQueryErrorCode> { | ||
| /** | ||
| * The customer identifier from the request that produced this error. | ||
| */ | ||
| @visibility(Lifecycle.Read) | ||
| @summary("Customer identifier") | ||
| customer?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Error code for a governance query failure. | ||
| */ | ||
| @friendlyName("GovernanceQueryErrorCode") | ||
| enum GovernanceQueryErrorCode { | ||
| /** | ||
| * Default zero value. Reserved for forward compatibility. | ||
| */ | ||
| Unknown: "unknown", | ||
|
|
||
| /** | ||
| * The provided identifier could not be resolved to any customer | ||
| * (neither by customer `key` nor by a usage-attribution subject `key`). | ||
| */ | ||
| CustomerNotFound: "customer_not_found", | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import "./governance.tsp"; | ||
| import "./operations.tsp"; | ||
|
|
||
| namespace Governance; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import "@typespec/http"; | ||
| import "@typespec/rest"; | ||
| import "@typespec/openapi"; | ||
| import "@typespec/openapi3"; | ||
| import "../common/error.tsp"; | ||
| import "../shared/index.tsp"; | ||
| import "./governance.tsp"; | ||
|
|
||
| using TypeSpec.Http; | ||
| using TypeSpec.OpenAPI; | ||
|
|
||
| namespace Governance; | ||
|
|
||
| interface GovernanceOperations { | ||
| /** | ||
| * Query feature access for a list of customers. | ||
| * | ||
| * The endpoint resolves each provided identifier to a customer and returns the | ||
| * access status for the requested features, plus optional credit balance | ||
| * availability. | ||
| * | ||
| * _Designed to be called on a fixed refresh interval and the query response is | ||
| * intended to be cached._ | ||
| */ | ||
| @extension(Shared.UnstableExtension, true) | ||
| @extension(Shared.InternalExtension, true) | ||
| @extension(Shared.PrivateExtension, true) | ||
| @post | ||
| @route("/query") | ||
| @operationId("query-governance-access") | ||
| @summary("Query governance access") | ||
| query( | ||
| ...Common.CursorPaginationQuery, | ||
| @body _: GovernanceQueryRequest, | ||
| ): GovernanceQueryResponse | Common.ErrorResponses; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.