Skip to content

Commit 26fc166

Browse files
Accounts service (#65)
* Update checkout action * Accounts service
1 parent b3a1f6d commit 26fc166

6 files changed

Lines changed: 183 additions & 64 deletions

File tree

‎.github/workflows/buf.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
steps:
2222
- name: Checkout code
23-
uses: actions/checkout@v6
23+
uses: actions/checkout@v7
2424
- name: Buf build/lint/format/breaking/push
2525
uses: bufbuild/buf-action@v1
2626
with:

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/bufbuild/buf
3-
rev: v1.71.0
3+
rev: v1.72.0
44
hooks:
55
- id: buf-lint
66
- id: buf-format
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Public API for resolving account details associated with an authenticated request.
2+
3+
edition = "2023";
4+
5+
package accounts.v1alpha1;
6+
7+
import "buf/validate/validate.proto";
8+
9+
option features.field_presence = IMPLICIT;
10+
11+
// GetAccountDetailsRequest requests details about the account associated with the calling credential.
12+
message GetAccountDetailsRequest {}
13+
14+
// AccountDetails is a minimal view of the account associated with an authenticated request.
15+
message AccountDetails {
16+
string user_name = 1;
17+
string email = 2;
18+
string organization_name = 3;
19+
string organization_slug = 4;
20+
// The authentication method used to authenticate the request.
21+
AuthenticationMethod active_authentication_method = 5;
22+
}
23+
24+
// AuthenticationMethod describes the credential used to authenticate the request.
25+
message AuthenticationMethod {
26+
option (buf.validate.message).oneof = {
27+
fields: [
28+
"api_key",
29+
"jwt"
30+
]
31+
required: true
32+
};
33+
option (buf.validate.message).cel = {
34+
id: "authentication_method.type_matches_details"
35+
message: "authentication method type must match its details"
36+
expression: "(this.type == 1 && has(this.api_key)) || (this.type == 2 && has(this.jwt))"
37+
};
38+
39+
// Type identifies the kind of credential used to authenticate the request.
40+
enum Type {
41+
TYPE_UNSPECIFIED = 0;
42+
TYPE_API_KEY = 1;
43+
TYPE_JWT = 2;
44+
}
45+
46+
Type type = 1 [(buf.validate.field).enum = {
47+
defined_only: true
48+
not_in: [0]
49+
}];
50+
APIKeyDetails api_key = 2;
51+
JWTDetails jwt = 3;
52+
}
53+
54+
// APIKeyDetails describes the API key used for the request without exposing its secret or internal identifier.
55+
message APIKeyDetails {
56+
string name = 1;
57+
string description = 2;
58+
// The non-secret identifier embedded in the API key.
59+
string public_identifier = 3;
60+
}
61+
62+
// JWTDetails describes the verified JWT without exposing the token or subject and session identifiers.
63+
message JWTDetails {
64+
// The verified issuer. For Clerk-authenticated requests, this is the Clerk issuer URL.
65+
string issuer = 1 [(buf.validate.field).string = {
66+
min_len: 1
67+
uri: true
68+
}];
69+
}
70+
71+
// AccountService exposes information about the account associated with an authenticated request.
72+
service AccountService {
73+
// GetAccountDetails resolves the calling credential to its effective account details.
74+
// Requests without valid authentication fail with UNAUTHENTICATED.
75+
rpc GetAccountDetails(GetAccountDetailsRequest) returns (AccountDetails) {}
76+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
}

‎apis/authentication/v1alpha1/authentication.proto‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

‎buf.lock‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
version: v2
33
deps:
44
- name: buf.build/bufbuild/protovalidate
5-
commit: 50325440f8f24053b047484a6bf60b76
6-
digest: b5:74cb6f5c0853c3c10aafc701614194bbd63326bdb8ef4068214454b8894b03ba4113e04b3a33a8321cdf05336e37db4dc14a5e2495db8462566914f36086ba31
5+
commit: 435963d1631043e694e56e6bcc3c79c3
6+
digest: b5:f4ea07ad2dd94bd7243562f9908b9fb104feef8076040c89d9f7c1dedc074de4d4ce2b997686ef4400f3eccb765a7cfc20ed4acdd70b9a3699351245c61dba97
77
- name: buf.build/googleapis/googleapis
88
commit: c17df5b2beca46928cc87d5656bd5343
99
digest: b5:648a01e0170d4512dea7d564016165decd1ed6e34bef79fe54753e51ad7e27545709ad9157d7551270147d551155c595a2fb0bf5bb33b1c83040ddbce915c604

0 commit comments

Comments
 (0)