Skip to content

Commit 0a5d420

Browse files
authored
feat(frontier)!: move CreatePlan and UpdatePlan to AdminService and add ListAllPlans (#496)
* feat(frontier)!: move CreatePlan and UpdatePlan to AdminService and add ListAllPlans * feat(frontier): validate plan state enum and non-negative credits and trial days * feat(frontier): add UpdatePlanRequestBody and require non-empty plan state * fix(frontier): use inactive not disabled for plan state, document update semantics
1 parent 91eaffc commit 0a5d420

2 files changed

Lines changed: 100 additions & 49 deletions

File tree

raystack/frontier/v1beta1/admin.proto

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ service AdminService {
117117

118118
rpc ListAllBillingAccounts(ListAllBillingAccountsRequest) returns (ListAllBillingAccountsResponse) {}
119119

120+
// Plans
121+
rpc CreatePlan(CreatePlanRequest) returns (CreatePlanResponse) {}
122+
123+
rpc UpdatePlan(UpdatePlanRequest) returns (UpdatePlanResponse) {}
124+
125+
// ListAllPlans returns every plan, including inactive ones, unlike
126+
// FrontierService.ListPlans which returns active plans only.
127+
rpc ListAllPlans(ListAllPlansRequest) returns (ListAllPlansResponse) {}
128+
120129
// Usage
121130
rpc RevertBillingUsage(RevertBillingUsageRequest) returns (RevertBillingUsageResponse) {}
122131

@@ -429,6 +438,97 @@ message ListAllBillingAccountsResponse {
429438
repeated BillingAccount billing_accounts = 1;
430439
}
431440

441+
message PlanRequestBody {
442+
string name = 1;
443+
string title = 2;
444+
string description = 3;
445+
446+
repeated Product products = 4;
447+
// known intervals are "day", "week", "month", and "year"
448+
string interval = 5 [(buf.validate.field).string = {
449+
in: [
450+
"day",
451+
"week",
452+
"month",
453+
"year"
454+
]
455+
}];
456+
int64 on_start_credits = 6 [(buf.validate.field).int64 = {gte: 0}];
457+
int64 trial_days = 7 [(buf.validate.field).int64 = {gte: 0}];
458+
459+
// known states are "active" and "inactive"
460+
string state = 8 [(buf.validate.field).string = {
461+
in: [
462+
"active",
463+
"inactive"
464+
]
465+
}];
466+
467+
google.protobuf.Struct metadata = 20;
468+
}
469+
470+
message CreatePlanRequest {
471+
// Plan to create
472+
PlanRequestBody body = 1 [(buf.validate.field).required = true];
473+
}
474+
475+
message CreatePlanResponse {
476+
// Created plan
477+
Plan plan = 1;
478+
}
479+
480+
// UpdatePlanRequestBody carries the plan fields UpdatePlan writes. It has no
481+
// name, interval, or products because UpdatePlan does not change those; a
482+
// plan's products are managed through CreatePlan's upsert. UpdatePlan is a full
483+
// write of these fields: an omitted field is cleared, not left unchanged.
484+
message UpdatePlanRequestBody {
485+
string title = 1;
486+
string description = 2;
487+
int64 on_start_credits = 3 [(buf.validate.field).int64 = {gte: 0}];
488+
int64 trial_days = 4 [(buf.validate.field).int64 = {gte: 0}];
489+
490+
// known states are "active" and "inactive"
491+
string state = 5 [(buf.validate.field).string = {
492+
in: [
493+
"active",
494+
"inactive"
495+
]
496+
}];
497+
498+
google.protobuf.Struct metadata = 20;
499+
}
500+
501+
message UpdatePlanRequest {
502+
// ID or name of the plan to update
503+
string id = 1 [(buf.validate.field).string.min_len = 1];
504+
// field 2 held a PlanRequestBody before UpdatePlan moved to its own body type
505+
reserved 2;
506+
// Plan fields to write
507+
UpdatePlanRequestBody body = 3 [(buf.validate.field).required = true];
508+
}
509+
510+
message UpdatePlanResponse {
511+
// Updated plan
512+
Plan plan = 1;
513+
}
514+
515+
message ListAllPlansRequest {
516+
// filter by plan state. an empty value returns plans in every state
517+
string state = 1 [(buf.validate.field) = {
518+
ignore: IGNORE_IF_ZERO_VALUE
519+
string: {
520+
in: [
521+
"active",
522+
"inactive"
523+
]
524+
}
525+
}];
526+
}
527+
528+
message ListAllPlansResponse {
529+
repeated Plan plans = 1;
530+
}
531+
432532
message RevertBillingUsageRequest {
433533
string org_id = 1;
434534
// DEPRECATED

raystack/frontier/v1beta1/frontier.proto

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,10 @@ service FrontierService {
339339
rpc ListFeatures(ListFeaturesRequest) returns (ListFeaturesResponse) {}
340340

341341
// Plans
342-
rpc CreatePlan(CreatePlanRequest) returns (CreatePlanResponse) {}
343-
344342
rpc ListPlans(ListPlansRequest) returns (ListPlansResponse) {}
345343

346344
rpc GetPlan(GetPlanRequest) returns (GetPlanResponse) {}
347345

348-
rpc UpdatePlan(UpdatePlanRequest) returns (UpdatePlanResponse) {}
349-
350346
// Checkout
351347
rpc CreateCheckout(CreateCheckoutRequest) returns (CreateCheckoutResponse) {}
352348

@@ -864,39 +860,6 @@ message ListFeaturesResponse {
864860
repeated Feature features = 1;
865861
}
866862

867-
message PlanRequestBody {
868-
string name = 1;
869-
string title = 2;
870-
string description = 3;
871-
872-
repeated Product products = 4;
873-
// known intervals are "day", "week", "month", and "year"
874-
string interval = 5 [(buf.validate.field).string = {
875-
in: [
876-
"day",
877-
"week",
878-
"month",
879-
"year"
880-
]
881-
}];
882-
int64 on_start_credits = 6;
883-
int64 trial_days = 7;
884-
885-
string state = 8;
886-
887-
google.protobuf.Struct metadata = 20;
888-
}
889-
890-
message CreatePlanRequest {
891-
// Plan to create
892-
PlanRequestBody body = 1 [(buf.validate.field).required = true];
893-
}
894-
895-
message CreatePlanResponse {
896-
// Created plan
897-
Plan plan = 1;
898-
}
899-
900863
message GetPlanRequest {
901864
// ID of the plan to get
902865
string id = 1 [(buf.validate.field).string.min_len = 1];
@@ -907,18 +870,6 @@ message GetPlanResponse {
907870
Plan plan = 1;
908871
}
909872

910-
message UpdatePlanRequest {
911-
// ID of the plan to update
912-
string id = 1 [(buf.validate.field).string.min_len = 1];
913-
// Plan to update
914-
PlanRequestBody body = 2;
915-
}
916-
917-
message UpdatePlanResponse {
918-
// Updated plan
919-
Plan plan = 1;
920-
}
921-
922873
message ListInvoicesRequest {
923874
string org_id = 1 [(buf.validate.field).string.min_len = 3];
924875
reserved 2;

0 commit comments

Comments
 (0)