|
| 1 | +// Public API for reading subscription plan and usage information. |
| 2 | + |
| 3 | +edition = "2023"; |
| 4 | + |
| 5 | +package accounts.v1alpha1; |
| 6 | + |
| 7 | +import "buf/validate/validate.proto"; |
| 8 | +import "google/protobuf/timestamp.proto"; |
| 9 | + |
| 10 | +option features.field_presence = IMPLICIT; |
| 11 | + |
| 12 | +// SubscriptionTier identifies the type of subscription an organization has. |
| 13 | +enum SubscriptionTier { |
| 14 | + SUBSCRIPTION_TIER_UNSPECIFIED = 0; |
| 15 | + SUBSCRIPTION_TIER_FREE = 1; |
| 16 | + SUBSCRIPTION_TIER_PAID = 2; |
| 17 | + SUBSCRIPTION_TIER_CUSTOM = 3; |
| 18 | +} |
| 19 | + |
| 20 | +// BillingCadence is the period in which the base subscription and add-ons are billed. |
| 21 | +enum BillingCadence { |
| 22 | + BILLING_CADENCE_UNSPECIFIED = 0; |
| 23 | + BILLING_CADENCE_MONTHLY = 1; |
| 24 | + BILLING_CADENCE_YEARLY = 2; |
| 25 | +} |
| 26 | + |
| 27 | +// Unit identifies the unit in which a usage metric is measured. |
| 28 | +enum Unit { |
| 29 | + UNIT_UNSPECIFIED = 0; |
| 30 | + UNIT_NO_UNIT = 1; |
| 31 | + UNIT_BYTES = 2; |
| 32 | + UNIT_SECONDS = 3; |
| 33 | +} |
| 34 | + |
| 35 | +// MetricAggregation describes how the current value of a metric was aggregated. |
| 36 | +enum MetricAggregation { |
| 37 | + METRIC_AGGREGATION_UNSPECIFIED = 0; |
| 38 | + METRIC_AGGREGATION_TOTAL = 1; |
| 39 | + METRIC_AGGREGATION_USAGE_PERIOD = 2; |
| 40 | +} |
| 41 | + |
| 42 | +// BillingPeriod describes the time range and anchor of a billing period. |
| 43 | +message BillingPeriod { |
| 44 | + google.protobuf.Timestamp start = 1; |
| 45 | + google.protobuf.Timestamp end = 2; |
| 46 | + google.protobuf.Timestamp anchor = 3; |
| 47 | +} |
| 48 | + |
| 49 | +// Plan describes the active subscription plan of an organization. |
| 50 | +message Plan { |
| 51 | + SubscriptionTier tier = 1; |
| 52 | + repeated string add_ons = 2; |
| 53 | + BillingCadence billing_cadence = 3; |
| 54 | + BillingPeriod subscription_billing_period = 4; |
| 55 | + BillingPeriod usage_billing_period = 5; |
| 56 | + // Set when a canceled subscription remains valid until the given time. |
| 57 | + google.protobuf.Timestamp valid_until = 6; |
| 58 | +} |
| 59 | + |
| 60 | +// UsageRecord is the value of a metric at a specific time. |
| 61 | +message UsageRecord { |
| 62 | + google.protobuf.Timestamp timestamp = 1; |
| 63 | + int64 value = 2; |
| 64 | + int64 cumulative_value = 3; |
| 65 | +} |
| 66 | + |
| 67 | +// UsageHistory contains the historical values and billing periods of a metric. |
| 68 | +message UsageHistory { |
| 69 | + repeated BillingPeriod usage_periods = 1; |
| 70 | + repeated UsageRecord records = 2; |
| 71 | +} |
| 72 | + |
| 73 | +// UsageMetric describes the current and historical consumption of an organization metric. |
| 74 | +message UsageMetric { |
| 75 | + string key = 1; |
| 76 | + Unit unit = 2; |
| 77 | + // Unset when the metric is unlimited. |
| 78 | + int64 limit = 3 [features.field_presence = EXPLICIT]; |
| 79 | + int64 value = 4; |
| 80 | + MetricAggregation aggregation = 5; |
| 81 | + UsageHistory history = 6; |
| 82 | +} |
| 83 | + |
| 84 | +// GetActivePlanRequest requests the active plan of the calling organization. |
| 85 | +message GetActivePlanRequest {} |
| 86 | + |
| 87 | +// GetUsageReportRequest requests current usage and, optionally, historical values. |
| 88 | +message GetUsageReportRequest { |
| 89 | + // The number of history days to return. Zero omits history. |
| 90 | + uint64 history_days = 1 [(buf.validate.field).uint64.lte = 365]; |
| 91 | +} |
| 92 | + |
| 93 | +// UsageReport contains the usage metrics tracked for an organization. |
| 94 | +message UsageReport { |
| 95 | + repeated UsageMetric metrics = 1; |
| 96 | + BillingPeriod usage_period = 2; |
| 97 | +} |
| 98 | + |
| 99 | +// BillingService exposes subscription plan and usage information. |
| 100 | +service BillingService { |
| 101 | + rpc GetActivePlan(GetActivePlanRequest) returns (Plan) {} |
| 102 | + rpc GetUsageReport(GetUsageReportRequest) returns (UsageReport) {} |
| 103 | +} |
0 commit comments