|
| 1 | +import "../shared/index.tsp"; |
| 2 | +import "../common/pagination.tsp"; |
| 3 | +import "../customers/customer.tsp"; |
| 4 | + |
| 5 | +namespace Governance; |
| 6 | + |
| 7 | +/** |
| 8 | + * List of customer identifiers to evaluate access for. |
| 9 | + */ |
| 10 | +@friendlyName("GovernanceQueryRequestCustomers") |
| 11 | +model GovernanceQueryRequestCustomers { |
| 12 | + /** |
| 13 | + * Each entry can be a customer `key` or a usage-attribution subject `key`. |
| 14 | + * Identifiers that cannot be resolved to a customer are reported in the response |
| 15 | + * `errors` array. |
| 16 | + */ |
| 17 | + @summary("Customer keys and usage-attribution subjects") |
| 18 | + @minItems(1) |
| 19 | + @maxItems(100) |
| 20 | + keys: string[]; |
| 21 | +} |
| 22 | + |
| 23 | +/** |
| 24 | + * Optional list of feature keys to evaluate access for. If omitted, all features |
| 25 | + * available in the organization are returned. Providing this list is recommended |
| 26 | + * to reduce the response size and the load on the backend services. |
| 27 | + */ |
| 28 | +@friendlyName("GovernanceQueryRequestFeatures") |
| 29 | +model GovernanceQueryRequestFeatures { |
| 30 | + /** |
| 31 | + * List of feature keys to evaluate access for. |
| 32 | + */ |
| 33 | + @summary("Feature Keys") |
| 34 | + @minItems(1) |
| 35 | + @maxItems(100) |
| 36 | + keys: string[]; |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * Query to evaluate feature access for a list of customers. |
| 41 | + */ |
| 42 | +@friendlyName("GovernanceQueryRequest") |
| 43 | +model GovernanceQueryRequest { |
| 44 | + /** |
| 45 | + * Whether to include credit balance availability for each resolved customer. When |
| 46 | + * true, each feature evaluation includes credit balance checks. |
| 47 | + * |
| 48 | + * Defaults to `false`. |
| 49 | + */ |
| 50 | + @summary("Include credits") |
| 51 | + include_credits?: boolean = false; |
| 52 | + |
| 53 | + #suppress "@openmeter/api-spec-aip/doc-decorator" "-" |
| 54 | + @summary("Customer") |
| 55 | + customer: GovernanceQueryRequestCustomers; |
| 56 | + |
| 57 | + #suppress "@openmeter/api-spec-aip/doc-decorator" "-" |
| 58 | + @summary("Feature") |
| 59 | + feature?: GovernanceQueryRequestFeatures; |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * Response of the governance query. |
| 64 | + */ |
| 65 | +@friendlyName("GovernanceQueryResponse") |
| 66 | +model GovernanceQueryResponse { |
| 67 | + /** |
| 68 | + * Access evaluation results, one entry per resolved customer. |
| 69 | + */ |
| 70 | + @visibility(Lifecycle.Read) |
| 71 | + @summary("Data") |
| 72 | + data: GovernanceQueryResult[]; |
| 73 | + |
| 74 | + /** |
| 75 | + * Partial errors encountered while processing the request. |
| 76 | + */ |
| 77 | + @visibility(Lifecycle.Read) |
| 78 | + @summary("Errors") |
| 79 | + errors: GovernanceQueryError[]; |
| 80 | + |
| 81 | + /** |
| 82 | + * Pagination metadata. The endpoint may return a partial response if the full |
| 83 | + * response would exceed server-side limits. |
| 84 | + */ |
| 85 | + @visibility(Lifecycle.Read) |
| 86 | + @summary("Meta") |
| 87 | + meta: Common.CursorMeta; |
| 88 | +} |
| 89 | + |
| 90 | +/** |
| 91 | + * Access evaluation result for a single resolved customer. |
| 92 | + */ |
| 93 | +@friendlyName("GovernanceQueryResult") |
| 94 | +model GovernanceQueryResult { |
| 95 | + /** |
| 96 | + * The list of identifiers from the request that resolved to this customer. Each |
| 97 | + * entry is either the customer `key` or one of its usage-attribution subject |
| 98 | + * `key`s. |
| 99 | + * |
| 100 | + * Duplicate or aliased identifiers that resolve to the same customer collapse to a |
| 101 | + * single result entry, with every requested identifier listed here. |
| 102 | + */ |
| 103 | + @visibility(Lifecycle.Read) |
| 104 | + @summary("Matched identifiers") |
| 105 | + matched: string[]; |
| 106 | + |
| 107 | + /** |
| 108 | + * The customer the matched identifiers resolved to. |
| 109 | + */ |
| 110 | + @visibility(Lifecycle.Read) |
| 111 | + @summary("Customer") |
| 112 | + customer: Customers.Customer; |
| 113 | + |
| 114 | + /** |
| 115 | + * Map of features with their access status. |
| 116 | + * |
| 117 | + * Map keys are the feature keys requested in `feature.keys`, or every feature |
| 118 | + * `key` available in the organization when the feature filter was omitted. |
| 119 | + */ |
| 120 | + @visibility(Lifecycle.Read) |
| 121 | + @summary("Features") |
| 122 | + features: Record<GovernanceFeatureAccess>; |
| 123 | + |
| 124 | + /** |
| 125 | + * Timestamp of the most recent change to the customer's access state reflected in |
| 126 | + * this result. |
| 127 | + */ |
| 128 | + @visibility(Lifecycle.Read) |
| 129 | + @summary("Updated at") |
| 130 | + updated_at: Shared.DateTime; |
| 131 | +} |
| 132 | + |
| 133 | +/** |
| 134 | + * Access status for a single feature. |
| 135 | + */ |
| 136 | +@friendlyName("GovernanceFeatureAccess") |
| 137 | +model GovernanceFeatureAccess { |
| 138 | + /** |
| 139 | + * Whether the customer currently has access to the feature. |
| 140 | + * |
| 141 | + * `true` for boolean and static entitlements that are available, and for metered |
| 142 | + * entitlements with remaining balance. `false` when the feature is unavailable, |
| 143 | + * the usage limit has been reached, or (when applicable) credits have been |
| 144 | + * exhausted. |
| 145 | + */ |
| 146 | + @visibility(Lifecycle.Read) |
| 147 | + @summary("Has access") |
| 148 | + has_access: boolean; |
| 149 | + |
| 150 | + /** |
| 151 | + * Optional reason when the customer does not have access to the feature. Populated |
| 152 | + * when `has_access` is `false`. |
| 153 | + */ |
| 154 | + @visibility(Lifecycle.Read) |
| 155 | + @summary("Reason") |
| 156 | + reason?: GovernanceFeatureAccessReason; |
| 157 | +} |
| 158 | + |
| 159 | +/** |
| 160 | + * Reason a feature is not accessible to a customer. |
| 161 | + */ |
| 162 | +@friendlyName("GovernanceFeatureAccessReason") |
| 163 | +model GovernanceFeatureAccessReason |
| 164 | + is Shared.BaseError<GovernanceFeatureAccessReasonCode>; |
| 165 | + |
| 166 | +/** |
| 167 | + * Machine-readable reason code for denied feature access. |
| 168 | + */ |
| 169 | +@friendlyName("GovernanceFeatureAccessReasonCode") |
| 170 | +enum GovernanceFeatureAccessReasonCode { |
| 171 | + /** |
| 172 | + * Default zero value. Reserved for forward compatibility. |
| 173 | + */ |
| 174 | + Unknown: "unknown", |
| 175 | + |
| 176 | + /** |
| 177 | + * The customer has reached the metered usage limit for the feature |
| 178 | + * within the current usage period. |
| 179 | + */ |
| 180 | + UsageLimitReached: "usage_limit_reached", |
| 181 | + |
| 182 | + /** |
| 183 | + * The feature is not available to the customer. |
| 184 | + */ |
| 185 | + FeatureUnavailable: "feature_unavailable", |
| 186 | + |
| 187 | + /** |
| 188 | + * The feature `key` referenced by the request is not configured in the |
| 189 | + * organization. |
| 190 | + */ |
| 191 | + FeatureNotFound: "feature_not_found", |
| 192 | + |
| 193 | + /** |
| 194 | + * The customer has no available prepaid credit balance. |
| 195 | + */ |
| 196 | + NoCreditAvailable: "no_credit_available", |
| 197 | +} |
| 198 | + |
| 199 | +/** |
| 200 | + * Query error within a partially successful governance query response. |
| 201 | + */ |
| 202 | +@friendlyName("GovernanceQueryError") |
| 203 | +model GovernanceQueryError is Shared.BaseError<GovernanceQueryErrorCode> { |
| 204 | + /** |
| 205 | + * The customer identifier from the request that produced this error. |
| 206 | + */ |
| 207 | + @visibility(Lifecycle.Read) |
| 208 | + @summary("Customer identifier") |
| 209 | + customer?: string; |
| 210 | +} |
| 211 | + |
| 212 | +/** |
| 213 | + * Error code for a governance query failure. |
| 214 | + */ |
| 215 | +@friendlyName("GovernanceQueryErrorCode") |
| 216 | +enum GovernanceQueryErrorCode { |
| 217 | + /** |
| 218 | + * Default zero value. Reserved for forward compatibility. |
| 219 | + */ |
| 220 | + Unknown: "unknown", |
| 221 | + |
| 222 | + /** |
| 223 | + * The provided identifier could not be resolved to any customer |
| 224 | + * (neither by customer `key` nor by a usage-attribution subject `key`). |
| 225 | + */ |
| 226 | + CustomerNotFound: "customer_not_found", |
| 227 | +} |
0 commit comments