Skip to content

Commit

Permalink
feat(frontier): add product behavior validation (#338)
Browse files Browse the repository at this point in the history
Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma authored Feb 16, 2024
1 parent d5ffada commit 2320f67
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
33 changes: 17 additions & 16 deletions raystack/frontier/v1beta1/frontier.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ message GetBillingAccountResponse {

message UpdateBillingAccountRequest {
// ID of the billing account to update
string id = 1 [(validate.rules).string.min_len = 1];
string id = 1 [(validate.rules).string.uuid = true];

string org_id = 2 [(validate.rules).string.min_len = 1];

Expand All @@ -1725,7 +1725,7 @@ message ListBillingAccountsResponse {

message DeleteBillingAccountRequest {
// ID of the billing account to delete
string id = 1 [(validate.rules).string.min_len = 1];
string id = 1 [(validate.rules).string.uuid = true];

string org_id = 2 [(validate.rules).string.min_len = 1];
}
Expand All @@ -1734,7 +1734,7 @@ message DeleteBillingAccountResponse {}

message GetBillingBalanceRequest {
// ID of the billing account to get the balance for
string id = 1 [(validate.rules).string.min_len = 1];
string id = 1 [(validate.rules).string.uuid = true];

string org_id = 2 [(validate.rules).string.min_len = 1];
}
Expand All @@ -1747,7 +1747,7 @@ message GetBillingBalanceResponse {
message CreateBillingUsageRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to update the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];

// Usage to create
repeated Usage usages = 3;
Expand All @@ -1771,7 +1771,7 @@ message ListBillingTransactionsResponse {
message GetSubscriptionRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to get the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];
// ID of the subscription to get
string id = 3 [(validate.rules).string.min_len = 1];
}
Expand All @@ -1783,7 +1783,7 @@ message GetSubscriptionResponse {
message ListSubscriptionsRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to list subscriptions for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];

// Filter subscriptions by state
string state = 3;
Expand All @@ -1798,7 +1798,7 @@ message ListSubscriptionsResponse {
message UpdateSubscriptionRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to update the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];
// ID of the subscription to update
string id = 3 [(validate.rules).string.min_len = 1];

Expand All @@ -1813,7 +1813,7 @@ message UpdateSubscriptionResponse {
message ChangeSubscriptionRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to update the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];
// ID of the subscription to update
string id = 3 [(validate.rules).string.min_len = 1];

Expand All @@ -1829,7 +1829,7 @@ message ChangeSubscriptionResponse {
message CancelSubscriptionRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to update the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];
// ID of the subscription to cancel
string id = 3 [(validate.rules).string.min_len = 1];

Expand All @@ -1848,7 +1848,7 @@ message ListPlansResponse {
message CheckFeatureEntitlementRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to update the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];

// feature or product name
string feature = 3 [(validate.rules).string.min_len = 1];
Expand All @@ -1861,7 +1861,7 @@ message CheckFeatureEntitlementResponse {
message CreateCheckoutRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to update the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];

string success_url = 3;
string cancel_url = 4;
Expand All @@ -1882,7 +1882,7 @@ message CreateCheckoutResponse {
message ListCheckoutsRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to update the subscription for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];
}

message ListCheckoutsResponse {
Expand All @@ -1898,7 +1898,7 @@ message ProductRequestBody {
string description = 3;
string plan_id = 4;
repeated Price prices = 5;
string behavior = 8;
string behavior = 8 [(validate.rules).string = {ignore_empty: true, in: ["basic", "credits", "per_seat"]}];
repeated Feature features = 9;
Product.BehaviorConfig behavior_config = 10;

Expand Down Expand Up @@ -1957,7 +1957,8 @@ message PlanRequestBody {
string description = 3;

repeated Product products = 4;
string interval = 5; // known intervals are "day", "week", "month", and "year"
// known intervals are "day", "week", "month", and "year"
string interval = 5 [(validate.rules).string = {in: ["day", "week", "month", "year"]}];
int64 on_start_credits = 6;
int64 trial_days = 7;

Expand Down Expand Up @@ -1999,7 +2000,7 @@ message UpdatePlanResponse {
message ListInvoicesRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to list invoices for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];
}

message ListInvoicesResponse {
Expand All @@ -2010,7 +2011,7 @@ message ListInvoicesResponse {
message GetUpcomingInvoiceRequest {
string org_id = 1 [(validate.rules).string.min_len = 3];
// ID of the billing account to get the upcoming invoice for
string billing_id = 2 [(validate.rules).string.min_len = 1];
string billing_id = 2 [(validate.rules).string.uuid = true];
}

message GetUpcomingInvoiceResponse {
Expand Down
17 changes: 10 additions & 7 deletions raystack/frontier/v1beta1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ message Plan {
string title = 3;
string description = 4;
repeated Product products = 5;
string interval = 6; // known intervals are "day", "week", "month", and "year"
// known intervals are "day", "week", "month", and "year"
string interval = 6 [(validate.rules).string = {in: ["day", "week", "month", "year"]}];
int64 on_start_credits = 7;
int64 trial_days = 8;

Expand All @@ -658,7 +659,7 @@ message Product {
string state = 6;

repeated Price prices = 7;
string behavior = 9;
string behavior = 9 [(validate.rules).string = {ignore_empty: true, in: ["basic", "credits", "per_seat"]}];
repeated Feature features = 10;
BehaviorConfig behavior_config = 11;

Expand All @@ -682,20 +683,22 @@ message Price {
string product_id = 2;
string provider_id = 3;
string name = 4;
string interval = 6; // known intervals are "day", "week", "month", and "year"

// known intervals are "day", "week", "month", and "year"
string interval = 6 [(validate.rules).string = {in: ["day", "week", "month", "year"]}];

// usage_type known types are "licensed" and "metered"
string usage_type = 7;
string usage_type = 7 [(validate.rules).string = {ignore_empty: true, in: ["licensed", "metered"]}];
// billing_scheme known schemes are "tiered" and "flat"
string billing_scheme = 8;
string billing_scheme = 8 [(validate.rules).string = {ignore_empty: true, in: ["tiered", "flat"]}];
string state = 9;
// currency like "usd", "eur", "gbp"
string currency = 10;
int64 amount = 11;
// metered_aggregate known aggregations are "sum", "last_during_period" and "max"
string metered_aggregate = 13;
string metered_aggregate = 13 [(validate.rules).string = {ignore_empty: true, in: ["sum", "max", "last_during_period"]}];
// tier_mode known modes are "graduated" and "volume"
string tier_mode = 14;
string tier_mode = 14 [(validate.rules).string = {ignore_empty: true, in: ["graduated", "volume"]}];

google.protobuf.Struct metadata = 20;
google.protobuf.Timestamp created_at = 21;
Expand Down

0 comments on commit 2320f67

Please sign in to comment.