feat(identity): name, lifetime and last-used on personal API tokens
This commit is contained in:
1 parent
e5cb0ac00b
commit
04ce0f9056
23 files changed
+449
-99
No files matched your search
@@ -28,6 +28,9 @@ type PersonalToken struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
CreatedAt *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
|
||||
ExpiresAt *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=expires_at,json=expiresAt,proto3" json:"expires_at,omitempty"` // unset: never expires
|
||||
LastUsedAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=last_used_at,json=lastUsedAt,proto3" json:"last_used_at,omitempty"` // unset: never used
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -76,9 +79,32 @@ func (x *PersonalToken) GetCreatedAt() *timestamppb.Timestamp {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *PersonalToken) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *PersonalToken) GetExpiresAt() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.ExpiresAt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *PersonalToken) GetLastUsedAt() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.LastUsedAt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AddPersonalTokenRequest struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
ExpiresAt *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=expires_at,json=expiresAt,proto3" json:"expires_at,omitempty"` // unset: never expires
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -120,6 +146,20 @@ func (x *AddPersonalTokenRequest) GetId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AddPersonalTokenRequest) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *AddPersonalTokenRequest) GetExpiresAt() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.ExpiresAt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AddPersonalTokenResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
@@ -1936,13 +1976,21 @@ var File_state_v1_account_proto protoreflect.FileDescriptor
|
||||
|
||||
const file_state_v1_account_proto_rawDesc = "" +
|
||||
"\n" +
|
||||
"\x16state/v1/account.proto\x12\bstate.v1\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x14state/v1/types.proto\"Z\n" +
|
||||
"\x16state/v1/account.proto\x12\bstate.v1\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x14state/v1/types.proto\"\xe7\x01\n" +
|
||||
"\rPersonalToken\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\tR\x02id\x129\n" +
|
||||
"\n" +
|
||||
"created_at\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\")\n" +
|
||||
"created_at\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\tcreatedAt\x12\x12\n" +
|
||||
"\x04name\x18\x03 \x01(\tR\x04name\x129\n" +
|
||||
"\n" +
|
||||
"expires_at\x18\x04 \x01(\v2\x1a.google.protobuf.TimestampR\texpiresAt\x12<\n" +
|
||||
"\flast_used_at\x18\x05 \x01(\v2\x1a.google.protobuf.TimestampR\n" +
|
||||
"lastUsedAt\"x\n" +
|
||||
"\x17AddPersonalTokenRequest\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\tR\x02id\"\x1a\n" +
|
||||
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
|
||||
"\x04name\x18\x02 \x01(\tR\x04name\x129\n" +
|
||||
"\n" +
|
||||
"expires_at\x18\x03 \x01(\v2\x1a.google.protobuf.TimestampR\texpiresAt\"\x1a\n" +
|
||||
"\x18AddPersonalTokenResponse\"\x1b\n" +
|
||||
"\x19ListPersonalTokensRequest\"M\n" +
|
||||
"\x1aListPersonalTokensResponse\x12/\n" +
|
||||
@@ -2124,62 +2172,65 @@ var file_state_v1_account_proto_goTypes = []any{
|
||||
}
|
||||
var file_state_v1_account_proto_depIdxs = []int32{
|
||||
41, // 0: state.v1.PersonalToken.created_at:type_name -> google.protobuf.Timestamp
|
||||
0, // 1: state.v1.ListPersonalTokensResponse.tokens:type_name -> state.v1.PersonalToken
|
||||
42, // 2: state.v1.RegisterAccountResponse.identity:type_name -> state.v1.Identity
|
||||
42, // 3: state.v1.SignInAccountResponse.identity:type_name -> state.v1.Identity
|
||||
41, // 4: state.v1.SignInAccountResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
42, // 5: state.v1.ResolveAccountSessionResponse.identity:type_name -> state.v1.Identity
|
||||
19, // 6: state.v1.GetAuthenticationSettingsResponse.settings:type_name -> state.v1.AuthenticationSettings
|
||||
19, // 7: state.v1.SaveAuthenticationSettingsRequest.settings:type_name -> state.v1.AuthenticationSettings
|
||||
42, // 8: state.v1.FinishPasskeyResponse.identity:type_name -> state.v1.Identity
|
||||
41, // 9: state.v1.FinishPasskeyResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
28, // 10: state.v1.ListPasskeysResponse.passkeys:type_name -> state.v1.Passkey
|
||||
41, // 11: state.v1.OpenAccountSessionRequest.expires_at:type_name -> google.protobuf.Timestamp
|
||||
42, // 12: state.v1.OpenAccountSessionResponse.identity:type_name -> state.v1.Identity
|
||||
41, // 13: state.v1.OpenAccountSessionResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
20, // 14: state.v1.AccountService.GetAuthenticationSettings:input_type -> state.v1.GetAuthenticationSettingsRequest
|
||||
22, // 15: state.v1.AccountService.SaveAuthenticationSettings:input_type -> state.v1.SaveAuthenticationSettingsRequest
|
||||
24, // 16: state.v1.AccountService.BeginPasskey:input_type -> state.v1.BeginPasskeyRequest
|
||||
26, // 17: state.v1.AccountService.FinishPasskey:input_type -> state.v1.FinishPasskeyRequest
|
||||
29, // 18: state.v1.AccountService.ListPasskeys:input_type -> state.v1.ListPasskeysRequest
|
||||
31, // 19: state.v1.AccountService.DeletePasskey:input_type -> state.v1.DeletePasskeyRequest
|
||||
33, // 20: state.v1.AccountService.OpenAccountSession:input_type -> state.v1.OpenAccountSessionRequest
|
||||
35, // 21: state.v1.AccountService.RequireFreshAccountSession:input_type -> state.v1.RequireFreshAccountSessionRequest
|
||||
37, // 22: state.v1.AccountService.CreateAccountRecovery:input_type -> state.v1.CreateAccountRecoveryRequest
|
||||
39, // 23: state.v1.AccountService.RecoverAccount:input_type -> state.v1.RecoverAccountRequest
|
||||
7, // 24: state.v1.AccountService.AccountSetup:input_type -> state.v1.AccountSetupRequest
|
||||
9, // 25: state.v1.AccountService.RegisterAccount:input_type -> state.v1.RegisterAccountRequest
|
||||
11, // 26: state.v1.AccountService.SignInAccount:input_type -> state.v1.SignInAccountRequest
|
||||
13, // 27: state.v1.AccountService.ResolveAccountSession:input_type -> state.v1.ResolveAccountSessionRequest
|
||||
15, // 28: state.v1.AccountService.SignOutAccount:input_type -> state.v1.SignOutAccountRequest
|
||||
17, // 29: state.v1.AccountService.ChangeAccountPassword:input_type -> state.v1.ChangeAccountPasswordRequest
|
||||
1, // 30: state.v1.AccountService.AddPersonalToken:input_type -> state.v1.AddPersonalTokenRequest
|
||||
3, // 31: state.v1.AccountService.ListPersonalTokens:input_type -> state.v1.ListPersonalTokensRequest
|
||||
5, // 32: state.v1.AccountService.RevokePersonalToken:input_type -> state.v1.RevokePersonalTokenRequest
|
||||
21, // 33: state.v1.AccountService.GetAuthenticationSettings:output_type -> state.v1.GetAuthenticationSettingsResponse
|
||||
23, // 34: state.v1.AccountService.SaveAuthenticationSettings:output_type -> state.v1.SaveAuthenticationSettingsResponse
|
||||
25, // 35: state.v1.AccountService.BeginPasskey:output_type -> state.v1.BeginPasskeyResponse
|
||||
27, // 36: state.v1.AccountService.FinishPasskey:output_type -> state.v1.FinishPasskeyResponse
|
||||
30, // 37: state.v1.AccountService.ListPasskeys:output_type -> state.v1.ListPasskeysResponse
|
||||
32, // 38: state.v1.AccountService.DeletePasskey:output_type -> state.v1.DeletePasskeyResponse
|
||||
34, // 39: state.v1.AccountService.OpenAccountSession:output_type -> state.v1.OpenAccountSessionResponse
|
||||
36, // 40: state.v1.AccountService.RequireFreshAccountSession:output_type -> state.v1.RequireFreshAccountSessionResponse
|
||||
38, // 41: state.v1.AccountService.CreateAccountRecovery:output_type -> state.v1.CreateAccountRecoveryResponse
|
||||
40, // 42: state.v1.AccountService.RecoverAccount:output_type -> state.v1.RecoverAccountResponse
|
||||
8, // 43: state.v1.AccountService.AccountSetup:output_type -> state.v1.AccountSetupResponse
|
||||
10, // 44: state.v1.AccountService.RegisterAccount:output_type -> state.v1.RegisterAccountResponse
|
||||
12, // 45: state.v1.AccountService.SignInAccount:output_type -> state.v1.SignInAccountResponse
|
||||
14, // 46: state.v1.AccountService.ResolveAccountSession:output_type -> state.v1.ResolveAccountSessionResponse
|
||||
16, // 47: state.v1.AccountService.SignOutAccount:output_type -> state.v1.SignOutAccountResponse
|
||||
18, // 48: state.v1.AccountService.ChangeAccountPassword:output_type -> state.v1.ChangeAccountPasswordResponse
|
||||
2, // 49: state.v1.AccountService.AddPersonalToken:output_type -> state.v1.AddPersonalTokenResponse
|
||||
4, // 50: state.v1.AccountService.ListPersonalTokens:output_type -> state.v1.ListPersonalTokensResponse
|
||||
6, // 51: state.v1.AccountService.RevokePersonalToken:output_type -> state.v1.RevokePersonalTokenResponse
|
||||
33, // [33:52] is the sub-list for method output_type
|
||||
14, // [14:33] is the sub-list for method input_type
|
||||
14, // [14:14] is the sub-list for extension type_name
|
||||
14, // [14:14] is the sub-list for extension extendee
|
||||
0, // [0:14] is the sub-list for field type_name
|
||||
41, // 1: state.v1.PersonalToken.expires_at:type_name -> google.protobuf.Timestamp
|
||||
41, // 2: state.v1.PersonalToken.last_used_at:type_name -> google.protobuf.Timestamp
|
||||
41, // 3: state.v1.AddPersonalTokenRequest.expires_at:type_name -> google.protobuf.Timestamp
|
||||
0, // 4: state.v1.ListPersonalTokensResponse.tokens:type_name -> state.v1.PersonalToken
|
||||
42, // 5: state.v1.RegisterAccountResponse.identity:type_name -> state.v1.Identity
|
||||
42, // 6: state.v1.SignInAccountResponse.identity:type_name -> state.v1.Identity
|
||||
41, // 7: state.v1.SignInAccountResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
42, // 8: state.v1.ResolveAccountSessionResponse.identity:type_name -> state.v1.Identity
|
||||
19, // 9: state.v1.GetAuthenticationSettingsResponse.settings:type_name -> state.v1.AuthenticationSettings
|
||||
19, // 10: state.v1.SaveAuthenticationSettingsRequest.settings:type_name -> state.v1.AuthenticationSettings
|
||||
42, // 11: state.v1.FinishPasskeyResponse.identity:type_name -> state.v1.Identity
|
||||
41, // 12: state.v1.FinishPasskeyResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
28, // 13: state.v1.ListPasskeysResponse.passkeys:type_name -> state.v1.Passkey
|
||||
41, // 14: state.v1.OpenAccountSessionRequest.expires_at:type_name -> google.protobuf.Timestamp
|
||||
42, // 15: state.v1.OpenAccountSessionResponse.identity:type_name -> state.v1.Identity
|
||||
41, // 16: state.v1.OpenAccountSessionResponse.expires_at:type_name -> google.protobuf.Timestamp
|
||||
20, // 17: state.v1.AccountService.GetAuthenticationSettings:input_type -> state.v1.GetAuthenticationSettingsRequest
|
||||
22, // 18: state.v1.AccountService.SaveAuthenticationSettings:input_type -> state.v1.SaveAuthenticationSettingsRequest
|
||||
24, // 19: state.v1.AccountService.BeginPasskey:input_type -> state.v1.BeginPasskeyRequest
|
||||
26, // 20: state.v1.AccountService.FinishPasskey:input_type -> state.v1.FinishPasskeyRequest
|
||||
29, // 21: state.v1.AccountService.ListPasskeys:input_type -> state.v1.ListPasskeysRequest
|
||||
31, // 22: state.v1.AccountService.DeletePasskey:input_type -> state.v1.DeletePasskeyRequest
|
||||
33, // 23: state.v1.AccountService.OpenAccountSession:input_type -> state.v1.OpenAccountSessionRequest
|
||||
35, // 24: state.v1.AccountService.RequireFreshAccountSession:input_type -> state.v1.RequireFreshAccountSessionRequest
|
||||
37, // 25: state.v1.AccountService.CreateAccountRecovery:input_type -> state.v1.CreateAccountRecoveryRequest
|
||||
39, // 26: state.v1.AccountService.RecoverAccount:input_type -> state.v1.RecoverAccountRequest
|
||||
7, // 27: state.v1.AccountService.AccountSetup:input_type -> state.v1.AccountSetupRequest
|
||||
9, // 28: state.v1.AccountService.RegisterAccount:input_type -> state.v1.RegisterAccountRequest
|
||||
11, // 29: state.v1.AccountService.SignInAccount:input_type -> state.v1.SignInAccountRequest
|
||||
13, // 30: state.v1.AccountService.ResolveAccountSession:input_type -> state.v1.ResolveAccountSessionRequest
|
||||
15, // 31: state.v1.AccountService.SignOutAccount:input_type -> state.v1.SignOutAccountRequest
|
||||
17, // 32: state.v1.AccountService.ChangeAccountPassword:input_type -> state.v1.ChangeAccountPasswordRequest
|
||||
1, // 33: state.v1.AccountService.AddPersonalToken:input_type -> state.v1.AddPersonalTokenRequest
|
||||
3, // 34: state.v1.AccountService.ListPersonalTokens:input_type -> state.v1.ListPersonalTokensRequest
|
||||
5, // 35: state.v1.AccountService.RevokePersonalToken:input_type -> state.v1.RevokePersonalTokenRequest
|
||||
21, // 36: state.v1.AccountService.GetAuthenticationSettings:output_type -> state.v1.GetAuthenticationSettingsResponse
|
||||
23, // 37: state.v1.AccountService.SaveAuthenticationSettings:output_type -> state.v1.SaveAuthenticationSettingsResponse
|
||||
25, // 38: state.v1.AccountService.BeginPasskey:output_type -> state.v1.BeginPasskeyResponse
|
||||
27, // 39: state.v1.AccountService.FinishPasskey:output_type -> state.v1.FinishPasskeyResponse
|
||||
30, // 40: state.v1.AccountService.ListPasskeys:output_type -> state.v1.ListPasskeysResponse
|
||||
32, // 41: state.v1.AccountService.DeletePasskey:output_type -> state.v1.DeletePasskeyResponse
|
||||
34, // 42: state.v1.AccountService.OpenAccountSession:output_type -> state.v1.OpenAccountSessionResponse
|
||||
36, // 43: state.v1.AccountService.RequireFreshAccountSession:output_type -> state.v1.RequireFreshAccountSessionResponse
|
||||
38, // 44: state.v1.AccountService.CreateAccountRecovery:output_type -> state.v1.CreateAccountRecoveryResponse
|
||||
40, // 45: state.v1.AccountService.RecoverAccount:output_type -> state.v1.RecoverAccountResponse
|
||||
8, // 46: state.v1.AccountService.AccountSetup:output_type -> state.v1.AccountSetupResponse
|
||||
10, // 47: state.v1.AccountService.RegisterAccount:output_type -> state.v1.RegisterAccountResponse
|
||||
12, // 48: state.v1.AccountService.SignInAccount:output_type -> state.v1.SignInAccountResponse
|
||||
14, // 49: state.v1.AccountService.ResolveAccountSession:output_type -> state.v1.ResolveAccountSessionResponse
|
||||
16, // 50: state.v1.AccountService.SignOutAccount:output_type -> state.v1.SignOutAccountResponse
|
||||
18, // 51: state.v1.AccountService.ChangeAccountPassword:output_type -> state.v1.ChangeAccountPasswordResponse
|
||||
2, // 52: state.v1.AccountService.AddPersonalToken:output_type -> state.v1.AddPersonalTokenResponse
|
||||
4, // 53: state.v1.AccountService.ListPersonalTokens:output_type -> state.v1.ListPersonalTokensResponse
|
||||
6, // 54: state.v1.AccountService.RevokePersonalToken:output_type -> state.v1.RevokePersonalTokenResponse
|
||||
36, // [36:55] is the sub-list for method output_type
|
||||
17, // [17:36] is the sub-list for method input_type
|
||||
17, // [17:17] is the sub-list for extension type_name
|
||||
17, // [17:17] is the sub-list for extension extendee
|
||||
0, // [0:17] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_state_v1_account_proto_init() }
|
||||
|
||||
@@ -37,23 +37,49 @@ func PersonalTokenSubject(raw string) (Subject, bool) {
|
||||
}
|
||||
|
||||
// PersonalToken is one token as its owner sees it: the subject it binds as,
|
||||
// which identifies it without revealing it, and when it was made.
|
||||
// which identifies it without revealing it, its name, and its lifetime. A nil
|
||||
// ExpiresAt never lapses; a nil LastUsedAt has never authenticated.
|
||||
type PersonalToken struct {
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ExpiresAt *time.Time `json:"expires_at"`
|
||||
LastUsedAt *time.Time `json:"last_used_at"`
|
||||
}
|
||||
|
||||
// lastUsedGranularity bounds how often authentication writes a token's last use.
|
||||
const lastUsedGranularity = time.Minute
|
||||
|
||||
// PersonalTokenStore is the store side of personal tokens, for one identity.
|
||||
type PersonalTokenStore interface {
|
||||
BindSubject(context.Context, IdentityID, Subject, Audit) error
|
||||
BindPersonalToken(ctx context.Context, id IdentityID, subject Subject, name string, expiresAt *time.Time, audit Audit) error
|
||||
SubjectsOf(ctx context.Context, id IdentityID, issuer string) ([]PersonalToken, error)
|
||||
UnbindSubject(context.Context, IdentityID, Subject, Audit) error
|
||||
PersonalTokenOf(context.Context, Subject) (PersonalToken, error)
|
||||
TouchPersonalToken(context.Context, Subject, time.Time) error
|
||||
}
|
||||
|
||||
// UsePersonalToken admits a presented token: an expired token is ErrNotFound,
|
||||
// exactly as an unknown one, and a successful use is recorded at most once a
|
||||
// minute.
|
||||
func UsePersonalToken(ctx context.Context, store PersonalTokenStore, subject Subject, now time.Time) error {
|
||||
token, err := store.PersonalTokenOf(ctx, subject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if token.ExpiresAt != nil && !now.Before(*token.ExpiresAt) {
|
||||
return ErrNotFound
|
||||
}
|
||||
if token.LastUsedAt == nil || now.Sub(*token.LastUsedAt) >= lastUsedGranularity {
|
||||
return store.TouchPersonalToken(ctx, subject, now)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PersonalTokens is personal tokens as a remote caller sees them: the State
|
||||
// Store acts on the caller's own principal, so no method names an identity.
|
||||
type PersonalTokens interface {
|
||||
AddPersonalToken(ctx context.Context, subject Subject) error
|
||||
AddPersonalToken(ctx context.Context, subject Subject, name string, expiresAt *time.Time) error
|
||||
ListPersonalTokens(ctx context.Context) ([]PersonalToken, error)
|
||||
RevokePersonalToken(ctx context.Context, id string) error
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package identity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type tokenFake struct {
|
||||
PersonalTokenStore
|
||||
token PersonalToken
|
||||
touched int
|
||||
}
|
||||
|
||||
func (f *tokenFake) PersonalTokenOf(context.Context, Subject) (PersonalToken, error) {
|
||||
return f.token, nil
|
||||
}
|
||||
|
||||
func (f *tokenFake) TouchPersonalToken(context.Context, Subject, time.Time) error {
|
||||
f.touched++
|
||||
return nil
|
||||
}
|
||||
|
||||
// TestUsePersonalToken pins that an expired token is refused and that last use
|
||||
// is written at most once a minute.
|
||||
func TestUsePersonalToken(t *testing.T) {
|
||||
now := time.Date(2026, 10, 27, 12, 0, 0, 0, time.UTC)
|
||||
at := func(d time.Duration) *time.Time { v := now.Add(d); return &v }
|
||||
tests := []struct {
|
||||
name string
|
||||
token PersonalToken
|
||||
wantErr error
|
||||
wantTouched int
|
||||
}{
|
||||
{"valid", PersonalToken{ExpiresAt: at(time.Hour)}, nil, 1},
|
||||
{"expired", PersonalToken{ExpiresAt: at(-time.Second)}, ErrNotFound, 0},
|
||||
{"expires now", PersonalToken{ExpiresAt: at(0)}, ErrNotFound, 0},
|
||||
{"no expiry", PersonalToken{}, nil, 1},
|
||||
{"used seconds ago", PersonalToken{LastUsedAt: at(-10 * time.Second)}, nil, 0},
|
||||
{"used minutes ago", PersonalToken{LastUsedAt: at(-2 * time.Minute)}, nil, 1},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
f := &tokenFake{token: tt.token}
|
||||
err := UsePersonalToken(context.Background(), f, Subject{}, now)
|
||||
if !errors.Is(err, tt.wantErr) || f.touched != tt.wantTouched {
|
||||
t.Fatalf("err %v touched %d, want %v and %d", err, f.touched, tt.wantErr, tt.wantTouched)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -310,6 +310,16 @@ func (s *Store) ClaimSubject(ctx context.Context, placeholder, subject identity.
|
||||
// BindSubject binds an identity to the provider subject that asserts it,
|
||||
// moving any prior binding for that subject.
|
||||
func (s *Store) BindSubject(ctx context.Context, id identity.IdentityID, subject identity.Subject, audit identity.Audit) error {
|
||||
return s.bindSubject(ctx, id, subject, "", nil, audit)
|
||||
}
|
||||
|
||||
// BindPersonalToken binds a personal token's subject with the name and expiry
|
||||
// its owner chose; a nil expiry never lapses.
|
||||
func (s *Store) BindPersonalToken(ctx context.Context, id identity.IdentityID, subject identity.Subject, name string, expiresAt *time.Time, audit identity.Audit) error {
|
||||
return s.bindSubject(ctx, id, subject, name, expiresAt, audit)
|
||||
}
|
||||
|
||||
func (s *Store) bindSubject(ctx context.Context, id identity.IdentityID, subject identity.Subject, name string, expiresAt *time.Time, audit identity.Audit) error {
|
||||
if err := subject.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -339,6 +349,7 @@ func (s *Store) BindSubject(ctx context.Context, id identity.IdentityID, subject
|
||||
|
||||
if err := q.UpsertIdentitySubject(ctx, postgresdb.UpsertIdentitySubjectParams{
|
||||
Issuer: subject.Issuer, Subject: subject.Subject, IdentityID: string(id), BoundAt: now,
|
||||
Name: name, ExpiresAt: timestamptzOf(expiresAt),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -360,11 +371,34 @@ func (s *Store) SubjectsOf(ctx context.Context, id identity.IdentityID, issuer s
|
||||
}
|
||||
out := make([]identity.PersonalToken, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
out = append(out, identity.PersonalToken{ID: row.Subject, CreatedAt: row.BoundAt})
|
||||
out = append(out, identity.PersonalToken{
|
||||
ID: row.Subject, Name: row.Name, CreatedAt: row.BoundAt, ExpiresAt: timePtr(row.ExpiresAt), LastUsedAt: timePtr(row.LastUsedAt),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// PersonalTokenOf returns one token's lifetime and last use, whoever owns it.
|
||||
func (s *Store) PersonalTokenOf(ctx context.Context, subject identity.Subject) (identity.PersonalToken, error) {
|
||||
row, err := postgresdb.New(s.pool).GetIdentitySubjectUse(ctx, postgresdb.GetIdentitySubjectUseParams{Issuer: subject.Issuer, Subject: subject.Subject})
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return identity.PersonalToken{}, identity.ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return identity.PersonalToken{}, err
|
||||
}
|
||||
return identity.PersonalToken{
|
||||
ID: row.Subject, Name: row.Name, CreatedAt: row.BoundAt, ExpiresAt: timePtr(row.ExpiresAt), LastUsedAt: timePtr(row.LastUsedAt),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TouchPersonalToken records when a token last authenticated.
|
||||
func (s *Store) TouchPersonalToken(ctx context.Context, subject identity.Subject, at time.Time) error {
|
||||
return postgresdb.New(s.pool).TouchIdentitySubject(ctx, postgresdb.TouchIdentitySubjectParams{
|
||||
Issuer: subject.Issuer, Subject: subject.Subject, LastUsedAt: timestamptzOf(&at),
|
||||
})
|
||||
}
|
||||
|
||||
// UnbindSubject removes one of an identity's bindings; a binding the
|
||||
// identity does not hold is ErrNotFound, so no caller can remove another's.
|
||||
func (s *Store) UnbindSubject(ctx context.Context, id identity.IdentityID, subject identity.Subject, audit identity.Audit) error {
|
||||
@@ -435,3 +469,18 @@ func (s *Store) BootstrapIdentities(ctx context.Context, legacyNames []string) e
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func timestamptzOf(t *time.Time) pgtype.Timestamptz {
|
||||
if t == nil {
|
||||
return pgtype.Timestamptz{}
|
||||
}
|
||||
return pgtype.Timestamptz{Time: *t, Valid: true}
|
||||
}
|
||||
|
||||
func timePtr(t pgtype.Timestamptz) *time.Time {
|
||||
if !t.Valid {
|
||||
return nil
|
||||
}
|
||||
v := t.Time
|
||||
return &v
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE identity_subjects
|
||||
ADD COLUMN name text NOT NULL DEFAULT '',
|
||||
ADD COLUMN expires_at timestamptz,
|
||||
ADD COLUMN last_used_at timestamptz;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE identity_subjects
|
||||
DROP COLUMN last_used_at,
|
||||
DROP COLUMN expires_at,
|
||||
DROP COLUMN name;
|
||||
@@ -77,6 +77,37 @@ func (q *Queries) GetIdentity(ctx context.Context, id string) (Identity, error)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getIdentitySubjectUse = `-- name: GetIdentitySubjectUse :one
|
||||
SELECT subject, bound_at, name, expires_at, last_used_at FROM identity_subjects
|
||||
WHERE issuer = $1 AND subject = $2
|
||||
`
|
||||
|
||||
type GetIdentitySubjectUseParams struct {
|
||||
Issuer string
|
||||
Subject string
|
||||
}
|
||||
|
||||
type GetIdentitySubjectUseRow struct {
|
||||
Subject string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) GetIdentitySubjectUse(ctx context.Context, arg GetIdentitySubjectUseParams) (GetIdentitySubjectUseRow, error) {
|
||||
row := q.db.QueryRow(ctx, getIdentitySubjectUse, arg.Issuer, arg.Subject)
|
||||
var i GetIdentitySubjectUseRow
|
||||
err := row.Scan(
|
||||
&i.Subject,
|
||||
&i.BoundAt,
|
||||
&i.Name,
|
||||
&i.ExpiresAt,
|
||||
&i.LastUsedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getVisibleIdentity = `-- name: GetVisibleIdentity :one
|
||||
SELECT id, kind, display_name, lifecycle, version, created_at, updated_at
|
||||
FROM identities WHERE id = $1 AND ($2::text IS NULL
|
||||
@@ -259,7 +290,7 @@ func (q *Queries) ListIdentities(ctx context.Context, scopeOrg pgtype.Text) ([]I
|
||||
}
|
||||
|
||||
const listIdentitySubjects = `-- name: ListIdentitySubjects :many
|
||||
SELECT subject, bound_at FROM identity_subjects
|
||||
SELECT subject, bound_at, name, expires_at, last_used_at FROM identity_subjects
|
||||
WHERE identity_id = $1 AND issuer = $2
|
||||
ORDER BY bound_at DESC
|
||||
`
|
||||
@@ -270,8 +301,11 @@ type ListIdentitySubjectsParams struct {
|
||||
}
|
||||
|
||||
type ListIdentitySubjectsRow struct {
|
||||
Subject string
|
||||
BoundAt time.Time
|
||||
Subject string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) ListIdentitySubjects(ctx context.Context, arg ListIdentitySubjectsParams) ([]ListIdentitySubjectsRow, error) {
|
||||
@@ -283,7 +317,13 @@ func (q *Queries) ListIdentitySubjects(ctx context.Context, arg ListIdentitySubj
|
||||
var items []ListIdentitySubjectsRow
|
||||
for rows.Next() {
|
||||
var i ListIdentitySubjectsRow
|
||||
if err := rows.Scan(&i.Subject, &i.BoundAt); err != nil {
|
||||
if err := rows.Scan(
|
||||
&i.Subject,
|
||||
&i.BoundAt,
|
||||
&i.Name,
|
||||
&i.ExpiresAt,
|
||||
&i.LastUsedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
@@ -348,6 +388,21 @@ func (q *Queries) ResolveIdentitySubject(ctx context.Context, arg ResolveIdentit
|
||||
return i, err
|
||||
}
|
||||
|
||||
const touchIdentitySubject = `-- name: TouchIdentitySubject :exec
|
||||
UPDATE identity_subjects SET last_used_at = $3 WHERE issuer = $1 AND subject = $2
|
||||
`
|
||||
|
||||
type TouchIdentitySubjectParams struct {
|
||||
Issuer string
|
||||
Subject string
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) TouchIdentitySubject(ctx context.Context, arg TouchIdentitySubjectParams) error {
|
||||
_, err := q.db.Exec(ctx, touchIdentitySubject, arg.Issuer, arg.Subject, arg.LastUsedAt)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateIdentity = `-- name: UpdateIdentity :execrows
|
||||
UPDATE identities SET display_name = $2, lifecycle = $3, version = $4, updated_at = $5
|
||||
WHERE id = $1 AND version = $6
|
||||
@@ -392,9 +447,10 @@ func (q *Queries) UpdateTaskIdentity(ctx context.Context, arg UpdateTaskIdentity
|
||||
}
|
||||
|
||||
const upsertIdentitySubject = `-- name: UpsertIdentitySubject :exec
|
||||
INSERT INTO identity_subjects (issuer, subject, identity_id, bound_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (issuer, subject) DO UPDATE SET identity_id = excluded.identity_id, bound_at = excluded.bound_at
|
||||
INSERT INTO identity_subjects (issuer, subject, identity_id, bound_at, name, expires_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (issuer, subject) DO UPDATE SET identity_id = excluded.identity_id, bound_at = excluded.bound_at,
|
||||
name = excluded.name, expires_at = excluded.expires_at
|
||||
`
|
||||
|
||||
type UpsertIdentitySubjectParams struct {
|
||||
@@ -402,6 +458,8 @@ type UpsertIdentitySubjectParams struct {
|
||||
Subject string
|
||||
IdentityID string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertIdentitySubject(ctx context.Context, arg UpsertIdentitySubjectParams) error {
|
||||
@@ -410,6 +468,8 @@ func (q *Queries) UpsertIdentitySubject(ctx context.Context, arg UpsertIdentityS
|
||||
arg.Subject,
|
||||
arg.IdentityID,
|
||||
arg.BoundAt,
|
||||
arg.Name,
|
||||
arg.ExpiresAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -266,6 +266,9 @@ type IdentitySubject struct {
|
||||
Subject string
|
||||
IdentityID string
|
||||
BoundAt time.Time
|
||||
Name string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
LastUsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type InstalledPackage struct {
|
||||
|
||||
@@ -73,17 +73,25 @@ WHERE issuer = @issuer AND subject = @placeholder
|
||||
RETURNING identity_id;
|
||||
|
||||
-- name: UpsertIdentitySubject :exec
|
||||
INSERT INTO identity_subjects (issuer, subject, identity_id, bound_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT (issuer, subject) DO UPDATE SET identity_id = excluded.identity_id, bound_at = excluded.bound_at;
|
||||
INSERT INTO identity_subjects (issuer, subject, identity_id, bound_at, name, expires_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (issuer, subject) DO UPDATE SET identity_id = excluded.identity_id, bound_at = excluded.bound_at,
|
||||
name = excluded.name, expires_at = excluded.expires_at;
|
||||
|
||||
-- name: UpdateTaskIdentity :exec
|
||||
UPDATE tasks SET identity = $1 WHERE identity = $2;
|
||||
|
||||
-- name: ListIdentitySubjects :many
|
||||
SELECT subject, bound_at FROM identity_subjects
|
||||
SELECT subject, bound_at, name, expires_at, last_used_at FROM identity_subjects
|
||||
WHERE identity_id = $1 AND issuer = $2
|
||||
ORDER BY bound_at DESC;
|
||||
|
||||
-- name: GetIdentitySubjectUse :one
|
||||
SELECT subject, bound_at, name, expires_at, last_used_at FROM identity_subjects
|
||||
WHERE issuer = $1 AND subject = $2;
|
||||
|
||||
-- name: TouchIdentitySubject :exec
|
||||
UPDATE identity_subjects SET last_used_at = $3 WHERE issuer = $1 AND subject = $2;
|
||||
|
||||
-- name: DeleteIdentitySubject :execrows
|
||||
DELETE FROM identity_subjects WHERE identity_id = $1 AND issuer = $2 AND subject = $3;
|
||||
@@ -3,6 +3,7 @@ package staterpc
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -74,7 +75,13 @@ func (s *identityServer) ResolveIdentitySubject(ctx context.Context, request *pb
|
||||
if s.deps.SubjectBindings == nil {
|
||||
return nil, status.Error(codes.Unavailable, "identity subject bindings unavailable")
|
||||
}
|
||||
value, err := s.deps.SubjectBindings.ResolveSubject(ctx, identity.Subject{Issuer: request.Issuer, Subject: request.Subject})
|
||||
subject := identity.Subject{Issuer: request.Issuer, Subject: request.Subject}
|
||||
if subject.Issuer == identity.PersonalTokenIssuer && s.deps.PersonalTokens != nil {
|
||||
if err := identity.UsePersonalToken(ctx, s.deps.PersonalTokens, subject, time.Now()); err != nil {
|
||||
return nil, identityStatus(err)
|
||||
}
|
||||
}
|
||||
value, err := s.deps.SubjectBindings.ResolveSubject(ctx, subject)
|
||||
if err != nil {
|
||||
return nil, identityStatus(err)
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
@@ -47,7 +49,7 @@ func (s *accountServer) AddPersonalToken(ctx context.Context, r *pb.AddPersonalT
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.deps.PersonalTokens.BindSubject(ctx, owner, subject, tokenAudit(ctx, owner, r.GetId())); err != nil {
|
||||
if err := s.deps.PersonalTokens.BindPersonalToken(ctx, owner, subject, r.GetName(), optionalTime(r.GetExpiresAt()), tokenAudit(ctx, owner, r.GetId())); err != nil {
|
||||
return nil, identityStatus(err)
|
||||
}
|
||||
return &pb.AddPersonalTokenResponse{}, nil
|
||||
@@ -64,7 +66,10 @@ func (s *accountServer) ListPersonalTokens(ctx context.Context, _ *pb.ListPerson
|
||||
}
|
||||
out := make([]*pb.PersonalToken, 0, len(tokens))
|
||||
for _, t := range tokens {
|
||||
out = append(out, &pb.PersonalToken{Id: t.ID, CreatedAt: timestamp(t.CreatedAt)})
|
||||
out = append(out, &pb.PersonalToken{
|
||||
Id: t.ID, Name: t.Name, CreatedAt: timestamp(t.CreatedAt),
|
||||
ExpiresAt: optionalTimestamp(t.ExpiresAt), LastUsedAt: optionalTimestamp(t.LastUsedAt),
|
||||
})
|
||||
}
|
||||
return &pb.ListPersonalTokensResponse{Tokens: out}, nil
|
||||
}
|
||||
@@ -84,8 +89,8 @@ func (s *accountServer) RevokePersonalToken(ctx context.Context, r *pb.RevokePer
|
||||
return &pb.RevokePersonalTokenResponse{}, nil
|
||||
}
|
||||
|
||||
func (c *Client) AddPersonalToken(ctx context.Context, subject identity.Subject) error {
|
||||
_, err := c.account.AddPersonalToken(ctx, &pb.AddPersonalTokenRequest{Id: subject.Subject})
|
||||
func (c *Client) AddPersonalToken(ctx context.Context, subject identity.Subject, name string, expiresAt *time.Time) error {
|
||||
_, err := c.account.AddPersonalToken(ctx, &pb.AddPersonalTokenRequest{Id: subject.Subject, Name: name, ExpiresAt: optionalTimestamp(expiresAt)})
|
||||
return identityClientError(err)
|
||||
}
|
||||
|
||||
@@ -96,7 +101,10 @@ func (c *Client) ListPersonalTokens(ctx context.Context) ([]identity.PersonalTok
|
||||
}
|
||||
out := make([]identity.PersonalToken, 0, len(r.GetTokens()))
|
||||
for _, t := range r.GetTokens() {
|
||||
out = append(out, identity.PersonalToken{ID: t.GetId(), CreatedAt: timeValue(t.GetCreatedAt())})
|
||||
out = append(out, identity.PersonalToken{
|
||||
ID: t.GetId(), Name: t.GetName(), CreatedAt: timeValue(t.GetCreatedAt()),
|
||||
ExpiresAt: optionalTime(t.GetExpiresAt()), LastUsedAt: optionalTime(t.GetLastUsedAt()),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -105,3 +113,18 @@ func (c *Client) RevokePersonalToken(ctx context.Context, id string) error {
|
||||
_, err := c.account.RevokePersonalToken(ctx, &pb.RevokePersonalTokenRequest{Id: id})
|
||||
return identityClientError(err)
|
||||
}
|
||||
|
||||
func optionalTimestamp(t *time.Time) *timestamppb.Timestamp {
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
return timestamppb.New(*t)
|
||||
}
|
||||
|
||||
func optionalTime(t *timestamppb.Timestamp) *time.Time {
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
v := t.AsTime()
|
||||
return &v
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
@@ -15,7 +16,7 @@ type tokenCalls struct {
|
||||
owner identity.IdentityID
|
||||
}
|
||||
|
||||
func (t *tokenCalls) BindSubject(_ context.Context, id identity.IdentityID, _ identity.Subject, _ identity.Audit) error {
|
||||
func (t *tokenCalls) BindPersonalToken(_ context.Context, id identity.IdentityID, _ identity.Subject, _ string, _ *time.Time, _ identity.Audit) error {
|
||||
t.owner = id
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
)
|
||||
|
||||
const maxTokenNameLength = 40
|
||||
|
||||
// Personal API tokens belong to the signed-in person; the State Store acts
|
||||
// on the principal the request carries, so these handlers name no one.
|
||||
|
||||
@@ -35,12 +41,35 @@ func (s *Server) handlePersonalTokenCreate(w http.ResponseWriter, r *http.Reques
|
||||
if !s.personalTokensReady(w, r) {
|
||||
return
|
||||
}
|
||||
var body struct {
|
||||
Name string `json:"name"`
|
||||
Days int `json:"days"`
|
||||
}
|
||||
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 4<<10)).Decode(&body); err != nil {
|
||||
http.Error(w, "invalid request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
name := strings.TrimSpace(body.Name)
|
||||
if name == "" || utf8.RuneCountInString(name) > maxTokenNameLength {
|
||||
http.Error(w, "Name a token in up to 40 characters.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
var expiresAt *time.Time
|
||||
switch body.Days {
|
||||
case 0:
|
||||
case 7, 30, 90:
|
||||
t := time.Now().UTC().AddDate(0, 0, body.Days)
|
||||
expiresAt = &t
|
||||
default:
|
||||
http.Error(w, "Lifetime is 7, 30 or 90 days, or none.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
raw, subject, err := identity.NewPersonalToken()
|
||||
if err != nil {
|
||||
http.Error(w, "cannot create token", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err := s.PersonalTokens.AddPersonalToken(r.Context(), subject); err != nil {
|
||||
if err := s.PersonalTokens.AddPersonalToken(r.Context(), subject, name, expiresAt); err != nil {
|
||||
writeIdentityError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
@@ -65,7 +66,7 @@ type recordingTokens struct{ owner identity.IdentityID }
|
||||
|
||||
// AddPersonalToken mirrors the State Store's rule: only a signed-in person's
|
||||
// principal may own a personal token.
|
||||
func (t *recordingTokens) AddPersonalToken(ctx context.Context, _ identity.Subject) error {
|
||||
func (t *recordingTokens) AddPersonalToken(ctx context.Context, _ identity.Subject, _ string, _ *time.Time) error {
|
||||
p, ok := access.PrincipalFromContext(ctx)
|
||||
if !ok || p.IdentityID == identity.SystemID || p.Role("") != org.RoleOwner {
|
||||
return identity.ErrInvalid
|
||||
@@ -120,7 +121,7 @@ func TestSharedTokenOperatorPostsPersonalToken(t *testing.T) {
|
||||
}
|
||||
handler := s.requireToken(s.authorize(http.HandlerFunc(s.handlePersonalTokenCreate)))
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/api/tokens", nil)
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/api/tokens", strings.NewReader(`{"name":"ci","days":30}`))
|
||||
req.Header.Set("Authorization", "Bearer shared")
|
||||
handler.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusCreated {
|
||||
|
||||
@@ -34,8 +34,15 @@ service AccountService {
|
||||
message PersonalToken {
|
||||
string id = 1;
|
||||
google.protobuf.Timestamp created_at = 2;
|
||||
string name = 3;
|
||||
google.protobuf.Timestamp expires_at = 4; // unset: never expires
|
||||
google.protobuf.Timestamp last_used_at = 5; // unset: never used
|
||||
}
|
||||
message AddPersonalTokenRequest {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
google.protobuf.Timestamp expires_at = 3; // unset: never expires
|
||||
}
|
||||
message AddPersonalTokenRequest { string id = 1; }
|
||||
message AddPersonalTokenResponse {}
|
||||
message ListPersonalTokensRequest {}
|
||||
message ListPersonalTokensResponse { repeated PersonalToken tokens = 1; }
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
import{A as e,C as t,Ct as n,D as r,M as i,S as a,Tt as o,Xt as s,_t as c,b as l,dt as u,ir as d,jn as f,k as p,l as m,t as h,x as g,xn as _,y as v}from"./PageHeader.js";import{N as y,d as b,ot as x,r as S,u as C}from"./createLucideIcon.js";import{t as w}from"./input.js";import{A as T,Ct as E,Tt as D,at as O,c as k,gt as A,ht as j,it as M,ot as N,q as P,rt as F,vt as I,wt as L}from"./index.js";var R={key:0,class:`text-fg-subtle`},z={key:1,role:`alert`,class:`mb-3 text-danger`},B={key:2,class:`mb-3 rounded-lg border border-border p-3`},V={class:`flex gap-2`},H={key:3,class:`text-fg-subtle`},U={class:`flex-1 truncate text-xs`},W={class:`text-xs text-fg-subtle`},G=i({__name:`PersonalTokensCard`,setup(i){let o=_(!1),h=_([]),v=_(``),b=_(``),x=_(!1);async function C(e){x.value=!0;try{await e(),b.value=``}catch(e){b.value=String(e.message||e)}finally{x.value=!1}}let E=()=>C(async()=>{let e=await S.tokens();o.value=e?.available??!1,h.value=e?.tokens??[]}),D=()=>C(async()=>{v.value=(await S.createToken())?.token??``,await E()}),O=()=>navigator.clipboard.writeText(v.value),k=e=>C(async()=>{await S.revokeToken(e),await E()});return u(E),(i,u)=>(c(),g(f(T),{title:`API tokens`},r({default:s(()=>[!o.value&&!x.value&&!b.value?(c(),t(`p`,R,`Personal tokens need a signed-in person.`)):a(``,!0),b.value?(c(),t(`p`,z,d(b.value),1)):a(``,!0),v.value?(c(),t(`div`,B,[u[3]||=l(`p`,{class:`mb-2 text-xs`},`Copy this token now. It cannot be shown again.`,-1),l(`div`,V,[e(f(w),{"model-value":v.value,readonly:``,"aria-label":`New token`,onFocus:u[0]||=e=>e.target.select()},null,8,[`model-value`]),e(f(y),{variant:`outline`,size:`sm`,"aria-label":`Copy token`,onClick:O},{default:s(()=>[e(f(I))]),_:1}),e(f(y),{variant:`ghost`,size:`sm`,"aria-label":`Dismiss`,onClick:u[1]||=e=>v.value=``},{default:s(()=>[e(f(j))]),_:1})])])):a(``,!0),o.value&&!h.value.length&&!x.value&&!b.value?(c(),t(`p`,H,`No tokens yet.`)):a(``,!0),h.value.length?(c(),g(f(F),{key:4,"aria-label":`API tokens`},{default:s(()=>[(c(!0),t(m,null,n(h.value,t=>(c(),g(f(N),{key:t.id,as:`li`,variant:`outline`,size:`xs`},{default:s(()=>[l(`code`,U,d(t.id.slice(0,12)),1),l(`span`,W,[e(f(P),{at:t.created_at},null,8,[`at`])]),e(f(y),{variant:`ghost`,size:`sm`,class:`text-danger`,disabled:x.value,onClick:e=>k(t.id)},{default:s(()=>[...u[4]||=[p(`Revoke`,-1)]]),_:1},8,[`disabled`,`onClick`])]),_:2},1024))),128))]),_:1})):a(``,!0)]),_:2},[o.value?{name:`action`,fn:s(()=>[e(f(y),{size:`sm`,disabled:x.value,onClick:D},{default:s(()=>[e(f(A),{"data-icon":`inline-start`}),u[2]||=p(`New token`,-1)]),_:1},8,[`disabled`])]),key:`0`}:void 0]),1024))}}),K={class:`mx-auto max-w-[80ch]`},q={class:`text-sm text-fg-muted`},J={class:`truncate`},Y={key:2,class:`text-fg-muted`},X={key:0,class:`break-all rounded-md border border-border p-3 font-mono`,role:`status`},Z={class:`flex justify-end border-t border-border pt-3`},Q=i({__name:`AccountPage`,setup(r){let i=_(``),A=()=>W(async()=>{i.value=(await S.recoveryCode()).code}),j=L(),P=_([]),I=_(``),R=_(!1),z=_(``),B=_(``),V=_(``),H=v(()=>E(j.status?.public_url??``));async function U(){try{P.value=(await S.passkeys()).passkeys}catch(e){I.value=String(e.message||e)}}u(U);async function W(e){R.value=!0,I.value=``;try{await e()}catch(e){I.value=String(e.message||e)}finally{R.value=!1}}let Q=()=>W(async()=>{await D(!0,z.value),z.value=``,await U()}),$=e=>W(async()=>{await S.deletePasskey(e),await U()}),ee=()=>W(async()=>{await S.changePassword(B.value,V.value),B.value=V.value=``,window.location.assign(`/`)});return(r,u)=>{let _=o(`RouterLink`);return c(),t(`div`,K,[e(h,{title:`Your account`},{default:s(()=>[l(`span`,q,d(f(j).status?.user?.display_name),1)]),_:1}),r.$route.query.welcome?(c(),g(f(b),{key:0,class:`mb-4`},{default:s(()=>[u[5]||=p(`Your organisation and admin account are ready. Add a passkey below, `,-1),e(_,{class:`underline`,to:`/org/members`},{default:s(()=>[...u[3]||=[p(`add members`,-1)]]),_:1}),u[6]||=p(`, or `,-1),e(_,{class:`underline`,to:`/settings/authentication`},{default:s(()=>[...u[4]||=[p(`configure OIDC`,-1)]]),_:1}),u[7]||=p(`.`,-1)]),_:1})):a(``,!0),I.value?(c(),g(f(b),{key:1,variant:`destructive`,class:`mb-4`},{default:s(()=>[e(f(C),null,{default:s(()=>[p(d(I.value)+` `,1),u[8]||=l(`a`,{class:`underline`,href:`/?reauth=1`},`Sign in again`,-1)]),_:1})]),_:1})):a(``,!0),e(f(T),{title:`Passkeys`},{default:s(()=>[P.value.length?(c(),g(f(F),{key:0,class:`mb-3`},{default:s(()=>[(c(!0),t(m,null,n(P.value,t=>(c(),g(f(N),{key:t.id,as:`li`,variant:`outline`,size:`xs`},{default:s(()=>[e(f(M),{class:`min-w-0 truncate`},{default:s(()=>[l(`span`,J,d(t.name),1)]),_:2},1024),e(f(O),null,{default:s(()=>[e(f(y),{variant:`ghost`,size:`sm`,class:`text-danger`,disabled:R.value,onClick:e=>$(t.id)},{default:s(()=>[...u[9]||=[p(`Remove`,-1)]]),_:1},8,[`disabled`,`onClick`])]),_:2},1024)]),_:2},1024))),128))]),_:1})):a(``,!0),H.value?(c(),t(`form`,{key:1,class:`flex flex-wrap gap-2`,onSubmit:x(Q,[`prevent`])},[e(f(w),{modelValue:z.value,"onUpdate:modelValLine truncated
|
||||
import{A as e,C as t,Ct as n,D as r,M as i,Qt as a,S as o,Tt as s,Xt as c,_t as l,b as u,dt as d,er as f,ir as p,jn as m,k as h,l as g,n as _,pn as v,rt as y,t as b,wt as x,x as S,xn as C,y as w}from"./PageHeader.js";import{N as T,d as E,nt as D,ot as O,r as k,u as A,w as j}from"./createLucideIcon.js";import{p as M,t as N}from"./input.js";import{A as P,Et as F,Tt as I,at as L,c as R,gt as z,ht as B,it as V,ot as H,q as U,rt as W,vt as G,wt as K,yt as q}from"./index.js";var J=[`data-size`],Y=[`data-size`],X=i({inheritAttrs:!1,__name:`NativeSelect`,props:{modelValue:{},class:{type:[Boolean,null,String,Object,Array]},size:{}},emits:[`update:modelValue`],setup(n,{emit:r}){let i=n,o=M(i,`modelValue`,r,{passive:!0,defaultValue:``}),s=j(i,`class`,`size`);return(n,r)=>(l(),t(`div`,{class:f(m(_)(`group/native-select relative w-fit has-[select:disabled]:opacity-50`,i.class)),"data-slot":`native-select-wrapper`,"data-size":i.size??`default`},[a(u(`select`,y({...n.$attrs,...m(s)},{"onUpdate:modelValue":r[0]||=e=>v(o)?o.value=e:null,"data-slot":`native-select`,class:`border-input placeholder:text-fg-muted selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 h-9 w-full min-w-0 appearance-none rounded-lg border bg-card py-1 pr-8 pl-2.5 text-sm transition-colors select-none focus-visible:ring-3 aria-invalid:ring-3 data-[size=sm]:h-8 data-[size=sm]:rounded-[min(var(--radius-md),10px)] data-[size=sm]:py-0.5 outline-none disabled:pointer-events-none disabled:cursor-not-allowed`,"data-size":i.size??`default`}),[x(n.$slots,`default`)],16,Y),[[D,m(o)]]),e(m(q),{class:`text-fg-muted top-1/2 right-2.5 size-4 -translate-y-1/2 pointer-events-none absolute select-none`,"aria-hidden":`true`,"data-slot":`native-select-icon`})],10,J))}}),Z=i({__name:`NativeSelectOption`,props:{class:{type:[Boolean,null,String,Object,Array]}},setup(e){let n=e;return(e,r)=>(l(),t(`option`,{"data-slot":`native-select-option`,class:f(m(_)(`bg-[Canvas] text-[CanvasText]`,n.class))},[x(e.$slots,`default`)],2))}}),Q={key:0,class:`text-fg-subtle`},$={key:1,role:`alert`,class:`mb-3 text-danger`},ee={key:2,class:`mb-3 rounded-lg border border-border p-3`},te={class:`flex gap-2`},ne={key:3,class:`text-fg-subtle`},re={class:`flex-1 truncate text-sm`},ie={class:`text-xs text-fg-subtle`},ae={class:`text-xs text-fg-subtle`},oe={class:`text-xs text-fg-subtle`},se=i({__name:`PersonalTokensCard`,setup(i){let a=[{days:7,label:`7 days`},{days:30,label:`30 days`},{days:90,label:`90 days`},{days:0,label:`No expiry`}],s=C(!1),f=C([]),_=C(``),v=C(``),y=C(!1),b=C(``),x=C(30);async function w(e){y.value=!0;try{await e(),v.value=``}catch(e){v.value=String(e.message||e)}finally{y.value=!1}}let E=()=>w(async()=>{let e=await k.tokens();s.value=e?.available??!1,f.value=e?.tokens??[]}),D=()=>w(async()=>{_.value=(await k.createToken(b.value.trim(),Number(x.value)))?.token??``,b.value=``,await E()}),A=()=>navigator.clipboard.writeText(_.value),j=e=>w(async()=>{await k.revokeToken(e),await E()});return d(E),(i,d)=>(l(),S(m(P),{title:`API tokens`},r({default:c(()=>[!s.value&&!y.value&&!v.value?(l(),t(`p`,Q,`Personal tokens need a signed-in person.`)):o(``,!0),v.value?(l(),t(`p`,$,p(v.value),1)):o(``,!0),_.value?(l(),t(`div`,ee,[d[5]||=u(`p`,{class:`mb-2 text-xs`},`Copy this token now. It cannot be shown again.`,-1),u(`div`,te,[e(m(N),{"model-value":_.value,readonly:``,"aria-label":`New token`,onFocus:d[2]||=e=>e.target.select()},null,8,[`model-value`]),e(m(T),{variant:`outline`,size:`sm`,"aria-label":`Copy token`,onClick:A},{default:c(()=>[e(m(G))]),_:1}),e(m(T),{variant:`ghost`,size:`sm`,"aria-label":`Dismiss`,onClick:d[3]||=e=>_.value=``},{default:c(()=>[e(m(B))]),_:1})])])):o(``,!0),s.value&&!f.value.length&&!y.value&&!v.value?(l(),t(`p`,ne,`No tokens yet.`)):o(``,!0),f.value.length?(l(),S(m(W),{key:4,"aria-label":`API tokens`},{default:c(()=>[(l(!0),t(g,null,n(f.value,n=>(l(),S(m(H),{key:n.id,as:`li`,variant:`outline`,size:`xs`},{default:c(()=>[u(`span`,re,p(n.name||n.id.slice(0,12)),1),u(`span`,ie,[d[6]||=h(`Created `,-1),e(m(U),{at:n.created_at},null,8,[`at`])]),u(`span`,ae,[d[7]||=h(`Expires `,-1),n.expires_at?(l(),S(m(U),{key:0,at:n.expires_at},null,8,[`at`])):(l(),t(g,{key:1},[h(`Never`)],64))]),u(`span`,oe,[d[8]||=h(`Last used `,-1),n.last_used_at?(l(),S(m(U),{key:0,at:n.last_used_at},null,8,[`at`])):(l(),t(g,{key:1},[h(`Never`)],64))]),e(m(T),{variant:`ghost`,size:`sm`,class:`text-danger`,disabled:y.value,onClick:e=>j(n.id)},{default:c(()=>[...d[9]||=[h(`Revoke`,-1)]]),_:1},8,[`disabled`,`onClick`])]),_:2},1024))),128))]),_:1})):o(``,!0)]),_:2},[s.value?{name:`action`,fn:c(()=>[u(`form`,{class:`flex items-center gap-2`,onSubmit:O(D,[`prevent`])},[e(m(N),{modelValue:b.value,"onUpdate:modelValue":d[0]||=e=>b.value=e,class:`w-40`,maxlength:`40`,rLine truncated
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
import{A as e,C as t,M as n,S as r,Xt as i,_t as a,b as o,dt as s,ir as c,jn as l,k as u,t as d,x as f,xn as p,y as m}from"./PageHeader.js";import{N as h,d as g,ot as _,r as v,u as y}from"./createLucideIcon.js";import{t as b}from"./input.js";import{A as x,c as S,nt as C,yt as w}from"./index.js";var T={class:`flex items-center justify-end gap-2 border-t border-border pt-3`},E=n({__name:`AuthenticationPage`,setup(n){let E=p({public_url:``,oidc_issuer:``,oidc_audience:``,oidc_client_id:``}),D=p(!1),O=p(``),k=p(!1),A=p(!1);s(async()=>{try{E.value=await v.authentication(),D.value=!0}catch(e){O.value=String(e.message||e)}});let j=m(()=>`${E.value.public_url.replace(/\/$/,``)}/oauth2/callback`);async function M(){k.value=!0,O.value=``,A.value=!1;try{await v.saveAuthentication(E.value),A.value=!0}catch(e){O.value=String(e.message||e)}finally{k.value=!1}}return(n,s)=>(a(),t(`div`,null,[e(d,{title:`Authentication`}),O.value?(a(),f(l(g),{key:0,variant:`destructive`,class:`mb-4`},{default:i(()=>[e(l(y),null,{default:i(()=>[u(c(O.value)+` `,1),s[4]||=o(`a`,{class:`underline`,href:`/?reauth=1`},`Sign in again`,-1)]),_:1})]),_:1})):r(``,!0),D.value?(a(),t(`form`,{key:1,onSubmit:_(M,[`prevent`])},[e(l(x),{title:`Instance URL`},{default:i(()=>[e(l(S),{label:`Public address`,for:`instance-url`,hint:`Passkeys require HTTPS and a domain name, or localhost. Once passkeys are enrolled, their domain is fixed.`},{default:i(()=>[e(l(b),{id:`instance-url`,modelValue:E.value.public_url,"onUpdate:modelValue":s[0]||=e=>E.value.public_url=e,type:`url`,required:``},null,8,[`modelValue`])]),_:1})]),_:1}),e(l(x),{title:`OpenID Connect`},{default:i(()=>[e(l(S),{label:`Issuer URL`,for:`oidc-issuer`},{default:i(()=>[e(l(b),{id:`oidc-issuer`,modelValue:E.value.oidc_issuer,"onUpdate:modelValue":s[1]||=e=>E.value.oidc_issuer=e,type:`url`,placeholder:`https://identity.example.com`},null,8,[`modelValue`])]),_:1}),e(l(S),{label:`Client ID`,for:`oidc-client`},{default:i(()=>[e(l(b),{id:`oidc-client`,modelValue:E.value.oidc_client_id,"onUpdate:modelValue":s[2]||=e=>E.value.oidc_client_id=e},null,8,[`modelValue`])]),_:1}),e(l(S),{label:`Access token audience`,for:`oidc-audience`},{default:i(()=>[e(l(b),{id:`oidc-audience`,modelValue:E.value.oidc_audience,"onUpdate:modelValue":s[3]||=e=>E.value.oidc_audience=e},null,8,[`modelValue`])]),_:1}),e(l(S),{label:`Redirect URI`,hint:`Add permitted people in Organisation → Members.`},{default:i(()=>[e(C,{code:j.value},null,8,[`code`])]),_:1}),o(`div`,T,[A.value?(a(),f(l(w),{key:0,role:`status`,"aria-label":`Saved`,class:`size-4 text-fg-muted`})):r(``,!0),e(l(h),{type:`submit`,disabled:k.value},{default:i(()=>[...s[5]||=[u(`Save`,-1)]]),_:1},8,[`disabled`])])]),_:1})],32)):r(``,!0)]))}});export{E as default};
|
||||
import{A as e,C as t,M as n,S as r,Xt as i,_t as a,b as o,dt as s,ir as c,jn as l,k as u,t as d,x as f,xn as p,y as m}from"./PageHeader.js";import{N as h,d as g,ot as _,r as v,u as y}from"./createLucideIcon.js";import{t as b}from"./input.js";import{A as x,bt as S,c as C,nt as w}from"./index.js";var T={class:`flex items-center justify-end gap-2 border-t border-border pt-3`},E=n({__name:`AuthenticationPage`,setup(n){let E=p({public_url:``,oidc_issuer:``,oidc_audience:``,oidc_client_id:``}),D=p(!1),O=p(``),k=p(!1),A=p(!1);s(async()=>{try{E.value=await v.authentication(),D.value=!0}catch(e){O.value=String(e.message||e)}});let j=m(()=>`${E.value.public_url.replace(/\/$/,``)}/oauth2/callback`);async function M(){k.value=!0,O.value=``,A.value=!1;try{await v.saveAuthentication(E.value),A.value=!0}catch(e){O.value=String(e.message||e)}finally{k.value=!1}}return(n,s)=>(a(),t(`div`,null,[e(d,{title:`Authentication`}),O.value?(a(),f(l(g),{key:0,variant:`destructive`,class:`mb-4`},{default:i(()=>[e(l(y),null,{default:i(()=>[u(c(O.value)+` `,1),s[4]||=o(`a`,{class:`underline`,href:`/?reauth=1`},`Sign in again`,-1)]),_:1})]),_:1})):r(``,!0),D.value?(a(),t(`form`,{key:1,onSubmit:_(M,[`prevent`])},[e(l(x),{title:`Instance URL`},{default:i(()=>[e(l(C),{label:`Public address`,for:`instance-url`,hint:`Passkeys require HTTPS and a domain name, or localhost. Once passkeys are enrolled, their domain is fixed.`},{default:i(()=>[e(l(b),{id:`instance-url`,modelValue:E.value.public_url,"onUpdate:modelValue":s[0]||=e=>E.value.public_url=e,type:`url`,required:``},null,8,[`modelValue`])]),_:1})]),_:1}),e(l(x),{title:`OpenID Connect`},{default:i(()=>[e(l(C),{label:`Issuer URL`,for:`oidc-issuer`},{default:i(()=>[e(l(b),{id:`oidc-issuer`,modelValue:E.value.oidc_issuer,"onUpdate:modelValue":s[1]||=e=>E.value.oidc_issuer=e,type:`url`,placeholder:`https://identity.example.com`},null,8,[`modelValue`])]),_:1}),e(l(C),{label:`Client ID`,for:`oidc-client`},{default:i(()=>[e(l(b),{id:`oidc-client`,modelValue:E.value.oidc_client_id,"onUpdate:modelValue":s[2]||=e=>E.value.oidc_client_id=e},null,8,[`modelValue`])]),_:1}),e(l(C),{label:`Access token audience`,for:`oidc-audience`},{default:i(()=>[e(l(b),{id:`oidc-audience`,modelValue:E.value.oidc_audience,"onUpdate:modelValue":s[3]||=e=>E.value.oidc_audience=e},null,8,[`modelValue`])]),_:1}),e(l(C),{label:`Redirect URI`,hint:`Add permitted people in Organisation → Members.`},{default:i(()=>[e(w,{code:j.value},null,8,[`code`])]),_:1}),o(`div`,T,[A.value?(a(),f(l(S),{key:0,role:`status`,"aria-label":`Saved`,class:`size-4 text-fg-muted`})):r(``,!0),e(l(h),{type:`submit`,disabled:k.value},{default:i(()=>[...s[5]||=[u(`Save`,-1)]]),_:1},8,[`disabled`])])]),_:1})],32)):r(``,!0)]))}});export{E as default};
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
import{t as e}from"./badge.js";import{A as t,C as n,Ct as r,M as i,S as a,Xt as o,_t as s,b as c,dt as l,ir as u,jn as d,k as f,l as p,st as m,t as h,x as g,xn as _}from"./PageHeader.js";import{N as v,d as y,l as b,n as x,r as S,u as C}from"./createLucideIcon.js";import{A as w,C as T,D as E,E as D,Et as O,O as k,T as A,Y as j,Z as M,a as N,dt as ee,et as P,ft as F,lt as I,mt as L,o as R,pt as z,q as B,tt as V,ut as H,w as U}from"./index.js";function W(e,t=Date.now()){if(!e.captured)return`unconfigured`;if(!e.expires_at)return`ready`;let n=Date.parse(e.expires_at);return Number.isNaN(n)?`ready`:n<=t?`expired`:n-t<=18e5?`expiring`:`ready`}function G(e,t,n=80,r=24){let i=t.protocol===`https:`?`wss:`:`ws:`,a=new URLSearchParams({profile:e,cols:String(n),rows:String(r)}).toString();return`${i}//${t.host}/api/harness/terminal?${a}`}var K={class:`flex h-full min-h-0 flex-col gap-2`},q={key:0,class:`text-sm text-fg-muted`,role:`status`},J=i({__name:`SetupTerminal`,props:{profile:{}},setup(e){let t=e,r=_(null),i=_(`connecting`),o=null,u=null,d=null,h=null;function g(){try{d?.fit()}catch{}}return l(()=>{let e=r.value;if(!e)return;o=new R({convertEol:!0,cursorBlink:!0,fontFamily:`'IBM Plex Mono', ui-monospace, monospace`,fontSize:13,theme:{background:`#0b0f14`,foreground:`#e6edf3`,cursor:`#e6edf3`,selectionBackground:`#264f78`}}),d=new N,o.loadAddon(d),o.open(e),g(),o.focus();let n=new WebSocket(G(t.profile,window.location,o?.cols??80,o?.rows??24));u=n,n.binaryType=`arraybuffer`,n.onopen=()=>{i.value=`open`},n.onmessage=e=>{o&&(typeof e.data==`string`?o.write(e.data):o.write(new Uint8Array(e.data)))},n.onerror=()=>{i.value=`failed`},n.onclose=()=>{i.value=`closed`},o.onData(e=>{n.readyState===WebSocket.OPEN&&n.send(e)}),h=new ResizeObserver(g),h.observe(e)}),m(()=>{h?.disconnect(),h=null,u?.close(),u=null,o?.dispose(),o=null,d=null}),(e,t)=>(s(),n(`div`,K,[i.value===`open`?a(``,!0):(s(),n(`p`,q,[i.value===`connecting`?(s(),n(p,{key:0},[f(`Connecting…`)],64)):i.value===`closed`?(s(),n(p,{key:1},[f(`The terminal session ended.`)],64)):(s(),n(p,{key:2},[f(`Could not open the setup terminal.`)],64))])),c(`div`,{ref_key:`host`,ref:r,class:`min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-[#0b0f14] p-2`},null,512)]))}}),Y={key:1,class:`flex flex-col gap-2`},X={class:`flex flex-wrap items-end gap-3`},Z={class:`flex flex-col gap-1 text-sm`},Q={class:`h-96`},$=i({__name:`HarnessPage`,setup(i){let m=_(null),N=_(!0),R=_(null),G=_(!1),K=_(``),q=_(!1),$={ready:{label:`Ready`,variant:`ok`},expiring:{label:`Expiring soon`,variant:`warn`},expired:{label:`Expired`,variant:`danger`},unconfigured:{label:`Not set up`,variant:`idle`}};l(te);async function te(){N.value=!0,R.value=null,G.value=!1;try{let e=await S.harnessBindings();m.value={terminal:e.terminal,bindings:e.bindings??[],profiles:e.profiles??[]},K.value=m.value.profiles[0]??``}catch(e){let t=e instanceof x?e.status:void 0;t===501||t===503?G.value=!0:R.value=e instanceof Error?e.message:String(e),m.value=null}finally{N.value=!1}}function ne(){m.value?.terminal&&K.value&&(q.value=!0)}function re(e){return e.scopes?.length?e.scopes.join(`, `):`–`}return(i,l)=>(s(),n(`div`,null,[t(h,{title:`Harness`}),R.value?(s(),g(d(y),{key:0,variant:`destructive`,class:`mb-4`},{default:o(()=>[t(d(b),null,{default:o(()=>[...l[1]||=[f(`Could not load the harness`,-1)]]),_:1}),t(d(C),null,{default:o(()=>[f(u(R.value),1)]),_:1})]),_:1})):a(``,!0),N.value?(s(),n(`div`,Y,[t(d(V),{class:`h-24 w-full`}),t(d(V),{class:`h-40 w-full`})])):G.value?(s(),g(d(P),{key:2},{default:o(()=>[t(d(M),null,{default:o(()=>[t(d(j),null,{default:o(()=>[...l[2]||=[f(`Harness bindings are not configured`,-1)]]),_:1})]),_:1})]),_:1})):m.value?(s(),n(p,{key:3},[m.value.terminal?(s(),g(d(w),{key:1},{default:o(()=>[c(`div`,X,[c(`div`,Z,[t(d(O),{for:`harness-profile`,class:`text-fg-muted`},{default:o(()=>[...l[5]||=[f(`Profile`,-1)]]),_:1}),t(d(L),{modelValue:K.value,"onUpdate:modelValue":l[0]||=e=>K.value=e,disabled:!m.value.profiles.length},{default:o(()=>[t(d(H),{id:`harness-profile`,size:`sm`,class:`min-w-48`},{default:o(()=>[t(d(I),{placeholder:`No profiles configured`})]),_:1}),t(d(z),null,{default:o(()=>[t(d(F),null,{default:o(()=>[(s(!0),n(p,null,r(m.value.profiles,e=>(s(),g(d(ee),{key:e,value:e},{default:o(()=>[f(u(e),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1})]),_:1},8,[`modelValue`,`disabled`])]),t(d(v),{disabled:!K.value,onClick:ne},{default:o(()=>[...l[6]||=[f(`Open setup terminal`,-1)]]),_:1},8,[`disabled`])])]),_:1})):(s(),g(d(y),{key:0,class:`mb-4`},{default:o(()=>[t(d(b),null,{default:o(()=>[...l[3]||=[f(`Setup terminal unavailable`,-1)]]),_:1}),t(d(C),null,{default:o(()=>[...l[4]||=[f(`Start the daemon with a container runtime and a harness token to log in to a CLI from here.`,-1)]]),_:1})]),_:1})),q.value&&K.value?(s(),g(d(w),{key:2},{default:o(()=>[c(`div`,Q,[t(J,{profile:K.value},null,8,[`profile`])])]),_:1})):a(``,!0),t(d(w),null,{default:o(()=>[t(d(k),null,{default:o(()=>[t(d(T)Line truncated
|
||||
import{t as e}from"./badge.js";import{A as t,C as n,Ct as r,M as i,S as a,Xt as o,_t as s,b as c,dt as l,ir as u,jn as d,k as f,l as p,st as m,t as h,x as g,xn as _}from"./PageHeader.js";import{N as v,d as y,l as b,n as x,r as S,u as C}from"./createLucideIcon.js";import{A as w,C as T,D as E,Dt as D,E as O,O as k,T as A,Y as j,Z as M,a as N,dt as ee,et as P,ft as F,lt as I,mt as L,o as R,pt as z,q as B,tt as V,ut as H,w as U}from"./index.js";function W(e,t=Date.now()){if(!e.captured)return`unconfigured`;if(!e.expires_at)return`ready`;let n=Date.parse(e.expires_at);return Number.isNaN(n)?`ready`:n<=t?`expired`:n-t<=18e5?`expiring`:`ready`}function G(e,t,n=80,r=24){let i=t.protocol===`https:`?`wss:`:`ws:`,a=new URLSearchParams({profile:e,cols:String(n),rows:String(r)}).toString();return`${i}//${t.host}/api/harness/terminal?${a}`}var K={class:`flex h-full min-h-0 flex-col gap-2`},q={key:0,class:`text-sm text-fg-muted`,role:`status`},J=i({__name:`SetupTerminal`,props:{profile:{}},setup(e){let t=e,r=_(null),i=_(`connecting`),o=null,u=null,d=null,h=null;function g(){try{d?.fit()}catch{}}return l(()=>{let e=r.value;if(!e)return;o=new R({convertEol:!0,cursorBlink:!0,fontFamily:`'IBM Plex Mono', ui-monospace, monospace`,fontSize:13,theme:{background:`#0b0f14`,foreground:`#e6edf3`,cursor:`#e6edf3`,selectionBackground:`#264f78`}}),d=new N,o.loadAddon(d),o.open(e),g(),o.focus();let n=new WebSocket(G(t.profile,window.location,o?.cols??80,o?.rows??24));u=n,n.binaryType=`arraybuffer`,n.onopen=()=>{i.value=`open`},n.onmessage=e=>{o&&(typeof e.data==`string`?o.write(e.data):o.write(new Uint8Array(e.data)))},n.onerror=()=>{i.value=`failed`},n.onclose=()=>{i.value=`closed`},o.onData(e=>{n.readyState===WebSocket.OPEN&&n.send(e)}),h=new ResizeObserver(g),h.observe(e)}),m(()=>{h?.disconnect(),h=null,u?.close(),u=null,o?.dispose(),o=null,d=null}),(e,t)=>(s(),n(`div`,K,[i.value===`open`?a(``,!0):(s(),n(`p`,q,[i.value===`connecting`?(s(),n(p,{key:0},[f(`Connecting…`)],64)):i.value===`closed`?(s(),n(p,{key:1},[f(`The terminal session ended.`)],64)):(s(),n(p,{key:2},[f(`Could not open the setup terminal.`)],64))])),c(`div`,{ref_key:`host`,ref:r,class:`min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-[#0b0f14] p-2`},null,512)]))}}),Y={key:1,class:`flex flex-col gap-2`},X={class:`flex flex-wrap items-end gap-3`},Z={class:`flex flex-col gap-1 text-sm`},Q={class:`h-96`},$=i({__name:`HarnessPage`,setup(i){let m=_(null),N=_(!0),R=_(null),G=_(!1),K=_(``),q=_(!1),$={ready:{label:`Ready`,variant:`ok`},expiring:{label:`Expiring soon`,variant:`warn`},expired:{label:`Expired`,variant:`danger`},unconfigured:{label:`Not set up`,variant:`idle`}};l(te);async function te(){N.value=!0,R.value=null,G.value=!1;try{let e=await S.harnessBindings();m.value={terminal:e.terminal,bindings:e.bindings??[],profiles:e.profiles??[]},K.value=m.value.profiles[0]??``}catch(e){let t=e instanceof x?e.status:void 0;t===501||t===503?G.value=!0:R.value=e instanceof Error?e.message:String(e),m.value=null}finally{N.value=!1}}function ne(){m.value?.terminal&&K.value&&(q.value=!0)}function re(e){return e.scopes?.length?e.scopes.join(`, `):`–`}return(i,l)=>(s(),n(`div`,null,[t(h,{title:`Harness`}),R.value?(s(),g(d(y),{key:0,variant:`destructive`,class:`mb-4`},{default:o(()=>[t(d(b),null,{default:o(()=>[...l[1]||=[f(`Could not load the harness`,-1)]]),_:1}),t(d(C),null,{default:o(()=>[f(u(R.value),1)]),_:1})]),_:1})):a(``,!0),N.value?(s(),n(`div`,Y,[t(d(V),{class:`h-24 w-full`}),t(d(V),{class:`h-40 w-full`})])):G.value?(s(),g(d(P),{key:2},{default:o(()=>[t(d(M),null,{default:o(()=>[t(d(j),null,{default:o(()=>[...l[2]||=[f(`Harness bindings are not configured`,-1)]]),_:1})]),_:1})]),_:1})):m.value?(s(),n(p,{key:3},[m.value.terminal?(s(),g(d(w),{key:1},{default:o(()=>[c(`div`,X,[c(`div`,Z,[t(d(D),{for:`harness-profile`,class:`text-fg-muted`},{default:o(()=>[...l[5]||=[f(`Profile`,-1)]]),_:1}),t(d(L),{modelValue:K.value,"onUpdate:modelValue":l[0]||=e=>K.value=e,disabled:!m.value.profiles.length},{default:o(()=>[t(d(H),{id:`harness-profile`,size:`sm`,class:`min-w-48`},{default:o(()=>[t(d(I),{placeholder:`No profiles configured`})]),_:1}),t(d(z),null,{default:o(()=>[t(d(F),null,{default:o(()=>[(s(!0),n(p,null,r(m.value.profiles,e=>(s(),g(d(ee),{key:e,value:e},{default:o(()=>[f(u(e),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1})]),_:1},8,[`modelValue`,`disabled`])]),t(d(v),{disabled:!K.value,onClick:ne},{default:o(()=>[...l[6]||=[f(`Open setup terminal`,-1)]]),_:1},8,[`disabled`])])]),_:1})):(s(),g(d(y),{key:0,class:`mb-4`},{default:o(()=>[t(d(b),null,{default:o(()=>[...l[3]||=[f(`Setup terminal unavailable`,-1)]]),_:1}),t(d(C),null,{default:o(()=>[...l[4]||=[f(`Start the daemon with a container runtime and a harness token to log in to a CLI from here.`,-1)]]),_:1})]),_:1})),q.value&&K.value?(s(),g(d(w),{key:2},{default:o(()=>[c(`div`,Q,[t(J,{profile:K.value},null,8,[`profile`])])]),_:1})):a(``,!0),t(d(w),null,{default:o(()=>[t(d(k),null,{default:o(()=>[t(d(T)Line truncated
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
import{t as e}from"./badge.js";import{A as t,C as n,Ct as r,Gt as i,M as a,S as o,Tt as s,Xt as c,_t as l,b as u,ht as d,ir as f,jn as p,k as m,l as h,t as g,x as _,xn as v,y}from"./PageHeader.js";import{N as b,d as x,r as S,u as C}from"./createLucideIcon.js";import{A as w,Dt as T,Y as E,Z as D,_t as O,d as k,et as A,n as j,q as M,r as N,tt as P,xt as F}from"./index.js";var I={key:0,class:`space-y-2`},L={class:`tabular-nums text-fg-muted`},R={class:`block max-w-md break-words whitespace-normal text-danger`},z={class:`flex flex-wrap gap-2`},B=a({__name:`ScheduleRunsPage`,setup(a){let B=T(),V=y(()=>String(B.params.id??``)),H=v(null),U=v(null),W=v(``);async function G(){let e=V.value;try{let[t,n]=await Promise.all([S.schedules(),S.scheduleRuns(e)]);if(e!==V.value)return;H.value=t.schedules?.find(t=>t.id===e)??null,U.value=n.runs??[],W.value=``}catch(t){e===V.value&&(W.value=t instanceof Error?t.message:String(t))}}i(V,()=>{U.value=null,G()},{immediate:!0});let K=setInterval(()=>void G(),15e3);d(()=>clearInterval(K));async function q(){W.value=``;try{await S.scheduleRunNow(V.value),await G()}catch(e){W.value=e instanceof Error?e.message:String(e)}}let J=[{id:`scheduled`,label:`Scheduled`,fixed:!0,sort:e=>e.scheduled_for},{id:`started`,label:`Started`},{id:`duration`,label:`Duration`},{id:`result`,label:`Result`,sort:e=>e.result},{id:`error`,label:`Error`},{id:`tasks`,label:`Tasks`}];return(i,a)=>{let d=s(`RouterLink`);return l(),n(`div`,null,[t(g,{title:H.value?.name||`Schedule runs`},{default:c(()=>[t(p(b),{variant:`ghost`,size:`sm`,"as-child":``},{default:c(()=>[t(d,{to:`/org/schedules`},{default:c(()=>[t(p(F),{"data-icon":`inline-start`}),a[0]||=m(`Schedules`,-1)]),_:1})]),_:1}),t(p(b),{size:`sm`,disabled:!H.value,onClick:q},{default:c(()=>[t(p(O),{"data-icon":`inline-start`}),a[1]||=m(`Run now`,-1)]),_:1},8,[`disabled`])]),_:1},8,[`title`]),W.value?(l(),_(p(x),{key:0,variant:`destructive`,class:`mb-4`},{default:c(()=>[t(p(C),null,{default:c(()=>[m(f(W.value),1)]),_:1})]),_:1})):o(``,!0),t(p(w),null,{default:c(()=>[!U.value&&!W.value?(l(),n(`div`,I,[t(p(P),{class:`h-8 w-full`}),t(p(P),{class:`h-8 w-full`})])):U.value?(l(),_(p(k),{key:1,columns:J,rows:U.value,"row-key":e=>String(e.id),"storage-key":`schedule-runs`,"initial-sort":{id:`scheduled`,desc:!0}},{empty:c(()=>[t(p(A),null,{default:c(()=>[t(p(D),null,{default:c(()=>[t(p(E),null,{default:c(()=>[...a[2]||=[m(`No runs yet`,-1)]]),_:1})]),_:1})]),_:1})]),"cell-scheduled":c(({row:e})=>[t(p(M),{at:e.scheduled_for,absolute:``},null,8,[`at`])]),"cell-started":c(({row:e})=>[t(p(M),{at:e.started,absolute:``},null,8,[`at`])]),"cell-duration":c(({row:e})=>[u(`span`,L,f(p(N)(e)||`–`),1)]),"cell-result":c(({row:n})=>[t(p(e),{variant:p(j)[n.result]??`idle`},{default:c(()=>[m(f(n.result),1)]),_:2},1032,[`variant`])]),"cell-error":c(({row:e})=>[u(`span`,R,f(e.error),1)]),"cell-tasks":c(({row:e})=>[u(`span`,z,[(l(!0),n(h,null,r(e.task_ids??[],e=>(l(),_(d,{key:e,to:`/tasks/${e}`,class:`font-mono hover:underline`},{default:c(()=>[m(`#`+f(e),1)]),_:2},1032,[`to`]))),128))])]),_:1},8,[`rows`,`row-key`])):o(``,!0)]),_:1})])}}});export{B as default};
|
||||
import{t as e}from"./badge.js";import{A as t,C as n,Ct as r,Gt as i,M as a,S as o,Tt as s,Xt as c,_t as l,b as u,ht as d,ir as f,jn as p,k as m,l as h,t as g,x as _,xn as v,y}from"./PageHeader.js";import{N as b,d as x,r as S,u as C}from"./createLucideIcon.js";import{A as w,Ot as T,St as E,Y as D,Z as O,_t as k,d as A,et as j,n as M,q as N,r as P,tt as F}from"./index.js";var I={key:0,class:`space-y-2`},L={class:`tabular-nums text-fg-muted`},R={class:`block max-w-md break-words whitespace-normal text-danger`},z={class:`flex flex-wrap gap-2`},B=a({__name:`ScheduleRunsPage`,setup(a){let B=T(),V=y(()=>String(B.params.id??``)),H=v(null),U=v(null),W=v(``);async function G(){let e=V.value;try{let[t,n]=await Promise.all([S.schedules(),S.scheduleRuns(e)]);if(e!==V.value)return;H.value=t.schedules?.find(t=>t.id===e)??null,U.value=n.runs??[],W.value=``}catch(t){e===V.value&&(W.value=t instanceof Error?t.message:String(t))}}i(V,()=>{U.value=null,G()},{immediate:!0});let K=setInterval(()=>void G(),15e3);d(()=>clearInterval(K));async function q(){W.value=``;try{await S.scheduleRunNow(V.value),await G()}catch(e){W.value=e instanceof Error?e.message:String(e)}}let J=[{id:`scheduled`,label:`Scheduled`,fixed:!0,sort:e=>e.scheduled_for},{id:`started`,label:`Started`},{id:`duration`,label:`Duration`},{id:`result`,label:`Result`,sort:e=>e.result},{id:`error`,label:`Error`},{id:`tasks`,label:`Tasks`}];return(i,a)=>{let d=s(`RouterLink`);return l(),n(`div`,null,[t(g,{title:H.value?.name||`Schedule runs`},{default:c(()=>[t(p(b),{variant:`ghost`,size:`sm`,"as-child":``},{default:c(()=>[t(d,{to:`/org/schedules`},{default:c(()=>[t(p(E),{"data-icon":`inline-start`}),a[0]||=m(`Schedules`,-1)]),_:1})]),_:1}),t(p(b),{size:`sm`,disabled:!H.value,onClick:q},{default:c(()=>[t(p(k),{"data-icon":`inline-start`}),a[1]||=m(`Run now`,-1)]),_:1},8,[`disabled`])]),_:1},8,[`title`]),W.value?(l(),_(p(x),{key:0,variant:`destructive`,class:`mb-4`},{default:c(()=>[t(p(C),null,{default:c(()=>[m(f(W.value),1)]),_:1})]),_:1})):o(``,!0),t(p(w),null,{default:c(()=>[!U.value&&!W.value?(l(),n(`div`,I,[t(p(F),{class:`h-8 w-full`}),t(p(F),{class:`h-8 w-full`})])):U.value?(l(),_(p(A),{key:1,columns:J,rows:U.value,"row-key":e=>String(e.id),"storage-key":`schedule-runs`,"initial-sort":{id:`scheduled`,desc:!0}},{empty:c(()=>[t(p(j),null,{default:c(()=>[t(p(O),null,{default:c(()=>[t(p(D),null,{default:c(()=>[...a[2]||=[m(`No runs yet`,-1)]]),_:1})]),_:1})]),_:1})]),"cell-scheduled":c(({row:e})=>[t(p(N),{at:e.scheduled_for,absolute:``},null,8,[`at`])]),"cell-started":c(({row:e})=>[t(p(N),{at:e.started,absolute:``},null,8,[`at`])]),"cell-duration":c(({row:e})=>[u(`span`,L,f(p(P)(e)||`–`),1)]),"cell-result":c(({row:n})=>[t(p(e),{variant:p(M)[n.result]??`idle`},{default:c(()=>[m(f(n.result),1)]),_:2},1032,[`variant`])]),"cell-error":c(({row:e})=>[u(`span`,R,f(e.error),1)]),"cell-tasks":c(({row:e})=>[u(`span`,z,[(l(!0),n(h,null,r(e.task_ids??[],e=>(l(),_(d,{key:e,to:`/tasks/${e}`,class:`font-mono hover:underline`},{default:c(()=>[m(`#`+f(e),1)]),_:2},1032,[`to`]))),128))])]),_:1},8,[`rows`,`row-key`])):o(``,!0)]),_:1})])}}});export{B as default};
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
import{t as e}from"./badge.js";import{A as t,C as n,Ct as r,M as ee,S as i,Tt as te,Xt as a,_t as o,b as s,dt as c,ht as l,ir as u,jn as d,k as f,l as p,t as ne,x as m,xn as h,y as g}from"./PageHeader.js";import{N as _,d as v,r as y,u as b}from"./createLucideIcon.js";import{r as re}from"./pinia.js";import{$ as ie,A as x,B as S,F as ae,G as oe,H as se,I as ce,J as le,K as ue,L as C,M as de,N as fe,P as pe,R as w,S as me,St as he,U as ge,V as T,W as _e,X as ve,Y as ye,Z as be,_ as xe,b as Se,bt as Ce,d as we,et as Te,f as Ee,g as E,gt as D,h as De,i as Oe,j as ke,m as O,p as Ae,q as k,r as je,s as Me,t as Ne,tt as A,u as j,v as Pe,x as Fe,y as Ie}from"./index.js";var Le={key:1,class:`space-y-2`},Re={class:`flex items-center gap-2`},ze={class:`truncate`},Be={class:`text-fg-muted`},Ve=[`title`],He={key:1,class:`text-fg-subtle`},Ue={class:`tabular-nums text-fg-muted`},M={key:1,class:`text-fg-subtle`},We={class:`flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1`},Ge={class:`flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1`},Ke={class:`flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1`},N=`schedule-settings`,P=ee({__name:`SchedulesPage`,setup(ee){let P=h(null),F=h(``),I=h(``),L;async function R(){try{let e=await y.schedules();P.value=e.schedules??[],F.value=``}catch(e){F.value=e instanceof Error?e.message:String(e)}}c(()=>{R(),L=setInterval(()=>void R(),3e4)}),l(()=>clearInterval(L));let z=ue(),{catalog:qe}=re(z);c(z.load);let B=g(()=>oe(qe.value,`schedules`)),V=g(()=>z.formFor(N)),H=g(()=>z.draftValue(N)),U=g(()=>z.pageErrorFor(N)),Je=g(()=>H.value?.time_zone||`UTC`),Ye=he(),Xe=e=>le(new Date(e),Ye.timeZone),Ze=e=>Oe(e.timing,Je.value,Xe),W=e=>e.owner.name||e.owner.id||e.owner.kind,Qe=[{id:`enabled`,label:`Enabled`,fixed:!0,class:`w-0`},{id:`name`,label:`Name`,fixed:!0,sort:e=>e.name.toLowerCase()},{id:`owner`,label:`Owner`,sort:W},{id:`interval`,label:`Interval`},{id:`last`,label:`Last Run`,sort:e=>e.last_run?.scheduled_for??``},{id:`duration`,label:`Last Duration`},{id:`next`,label:`Next Run`,sort:e=>e.next_run??``}];function G(e){if(!P.value)return;let t=P.value.findIndex(t=>t.id===e.id);t<0?P.value.push(e):P.value[t]=e}async function K(e){I.value=``;try{await e()}catch(e){I.value=e instanceof Error?e.message:String(e)}}let $e=(e,t)=>K(async()=>G(await y.scheduleSave(e.id,{...e,enabled:t}))),et=e=>K(async()=>{await y.scheduleRunNow(e.id),await R()}),q=h(null),J=h(``),Y=h(!1);function X(e,t){q.value=e,J.value=t,Y.value=!0}function Z(){return{id:crypto.randomUUID(),name:``,owner:{kind:`instance`},enabled:!0,built_in:!1,timing:{kind:`interval`,interval:`24h0m0s`}}}let Q=()=>X(Z(),`New schedule`),tt=e=>X({...Z(),name:`${e.name} copy`,timing:{...e.timing},enabled:!1},`Duplicate schedule`),$=h(null),nt=()=>K(async()=>{let e=$.value;$.value=null,e&&(await y.scheduleDelete(e.id),P.value=P.value?.filter(t=>t.id!==e.id)??null)});return(ee,c)=>{let l=te(`RouterLink`);return o(),n(`div`,null,[t(ne,{title:`Schedules`},{default:a(()=>[t(ge,{kinds:B.value.map(e=>e.kind)},null,8,[`kinds`]),t(d(_),{size:`sm`,disabled:!P.value,onClick:Q},{default:a(()=>[t(d(D),{"data-icon":`inline-start`}),c[2]||=f(`Add schedule`,-1)]),_:1},8,[`disabled`])]),_:1}),(o(!0),n(p,null,r(B.value,e=>(o(),m(_e,{key:e.kind,kind:e.kind,class:`mb-4`},null,8,[`kind`]))),128)),I.value?(o(),m(d(v),{key:0,variant:`destructive`,class:`mb-4`},{default:a(()=>[t(d(b),null,{default:a(()=>[f(u(I.value),1)]),_:1})]),_:1})):i(``,!0),t(d(x),null,{default:a(()=>[F.value?(o(),m(d(v),{key:0,variant:`destructive`},{default:a(()=>[t(d(b),null,{default:a(()=>[f(u(F.value),1)]),_:1})]),_:1})):P.value?(o(),m(d(we),{key:2,columns:Qe,rows:P.value,"row-key":e=>e.id,"storage-key":`schedules`,"initial-sort":{id:`name`,desc:!1}},{empty:a(()=>[t(d(Te),null,{default:a(()=>[t(d(ve),{variant:`icon`},{default:a(()=>[t(d(Ce))]),_:1}),t(d(be),null,{default:a(()=>[t(d(ye),null,{default:a(()=>[...c[3]||=[f(`No schedules yet`,-1)]]),_:1})]),_:1}),t(d(ie),null,{default:a(()=>[t(d(_),{size:`sm`,onClick:Q},{default:a(()=>[t(d(D),{"data-icon":`inline-start`}),c[4]||=f(`Add schedule`,-1)]),_:1})]),_:1})]),_:1})]),"cell-enabled":a(({row:e})=>[t(d(ke),{"model-value":e.enabled,"aria-label":`${e.name} enabled`,"onUpdate:modelValue":t=>$e(e,t)},null,8,[`model-value`,`aria-label`,`onUpdate:modelValue`])]),"cell-name":a(({row:t})=>[s(`span`,Re,[s(`span`,ze,u(t.name),1),t.built_in?(o(),m(d(e),{key:0,variant:`outline`},{default:a(()=>[...c[5]||=[f(`Built-in`,-1)]]),_:1})):i(``,!0)])]),"cell-owner":a(({row:e})=>[s(`span`,Be,u(W(e)),1)]),"cell-interval":a(({row:e})=>[s(`span`,{title:e.timing.kind===`cron`?e.timing.cron:void 0},u(Ze(e)),9,Ve)]),"cell-last":a(({row:r})=>[r.last_run?(o(),m(l,{key:0,to:`/org/schedules/${encodeURIComponent(r.id)}/runs`,class:`inline-flex items-center gap-2 hover:underline`},{default:a(()=>[t(d(k),{at:r.last_run.started||r.last_run.scheduled_for},null,8,[`at`]),r.last_run.result===`failed`?(o(),m(d(e),{key:0,variant:`danger`,title:r.Line truncated
|
||||
import{t as e}from"./badge.js";import{A as t,C as n,Ct as r,M as ee,S as i,Tt as te,Xt as a,_t as o,b as s,dt as c,ht as l,ir as u,jn as d,k as f,l as p,t as ne,x as m,xn as h,y as g}from"./PageHeader.js";import{N as _,d as v,r as y,u as b}from"./createLucideIcon.js";import{r as re}from"./pinia.js";import{$ as ie,A as x,B as S,Ct as ae,F as oe,G as se,H as ce,I as le,J as ue,K as de,L as C,M as fe,N as pe,P as w,R as me,S as he,U as ge,V as T,W as _e,X as ve,Y as ye,Z as be,_ as xe,b as Se,d as Ce,et as we,f as Te,g as Ee,gt as E,h as D,i as De,j as Oe,m as O,p as ke,q as k,r as Ae,s as je,t as Me,tt as A,u as j,v as Ne,x as Pe,xt as Fe,y as Ie}from"./index.js";var Le={key:1,class:`space-y-2`},Re={class:`flex items-center gap-2`},ze={class:`truncate`},Be={class:`text-fg-muted`},Ve=[`title`],He={key:1,class:`text-fg-subtle`},Ue={class:`tabular-nums text-fg-muted`},M={key:1,class:`text-fg-subtle`},We={class:`flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1`},Ge={class:`flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1`},Ke={class:`flex min-w-0 flex-wrap items-center gap-3 @md/field-group:flex-1`},N=`schedule-settings`,P=ee({__name:`SchedulesPage`,setup(ee){let P=h(null),F=h(``),I=h(``),L;async function R(){try{let e=await y.schedules();P.value=e.schedules??[],F.value=``}catch(e){F.value=e instanceof Error?e.message:String(e)}}c(()=>{R(),L=setInterval(()=>void R(),3e4)}),l(()=>clearInterval(L));let z=de(),{catalog:qe}=re(z);c(z.load);let B=g(()=>se(qe.value,`schedules`)),V=g(()=>z.formFor(N)),H=g(()=>z.draftValue(N)),U=g(()=>z.pageErrorFor(N)),Je=g(()=>H.value?.time_zone||`UTC`),Ye=ae(),Xe=e=>ue(new Date(e),Ye.timeZone),Ze=e=>De(e.timing,Je.value,Xe),W=e=>e.owner.name||e.owner.id||e.owner.kind,Qe=[{id:`enabled`,label:`Enabled`,fixed:!0,class:`w-0`},{id:`name`,label:`Name`,fixed:!0,sort:e=>e.name.toLowerCase()},{id:`owner`,label:`Owner`,sort:W},{id:`interval`,label:`Interval`},{id:`last`,label:`Last Run`,sort:e=>e.last_run?.scheduled_for??``},{id:`duration`,label:`Last Duration`},{id:`next`,label:`Next Run`,sort:e=>e.next_run??``}];function G(e){if(!P.value)return;let t=P.value.findIndex(t=>t.id===e.id);t<0?P.value.push(e):P.value[t]=e}async function K(e){I.value=``;try{await e()}catch(e){I.value=e instanceof Error?e.message:String(e)}}let $e=(e,t)=>K(async()=>G(await y.scheduleSave(e.id,{...e,enabled:t}))),et=e=>K(async()=>{await y.scheduleRunNow(e.id),await R()}),q=h(null),J=h(``),Y=h(!1);function X(e,t){q.value=e,J.value=t,Y.value=!0}function Z(){return{id:crypto.randomUUID(),name:``,owner:{kind:`instance`},enabled:!0,built_in:!1,timing:{kind:`interval`,interval:`24h0m0s`}}}let Q=()=>X(Z(),`New schedule`),tt=e=>X({...Z(),name:`${e.name} copy`,timing:{...e.timing},enabled:!1},`Duplicate schedule`),$=h(null),nt=()=>K(async()=>{let e=$.value;$.value=null,e&&(await y.scheduleDelete(e.id),P.value=P.value?.filter(t=>t.id!==e.id)??null)});return(ee,c)=>{let l=te(`RouterLink`);return o(),n(`div`,null,[t(ne,{title:`Schedules`},{default:a(()=>[t(ge,{kinds:B.value.map(e=>e.kind)},null,8,[`kinds`]),t(d(_),{size:`sm`,disabled:!P.value,onClick:Q},{default:a(()=>[t(d(E),{"data-icon":`inline-start`}),c[2]||=f(`Add schedule`,-1)]),_:1},8,[`disabled`])]),_:1}),(o(!0),n(p,null,r(B.value,e=>(o(),m(_e,{key:e.kind,kind:e.kind,class:`mb-4`},null,8,[`kind`]))),128)),I.value?(o(),m(d(v),{key:0,variant:`destructive`,class:`mb-4`},{default:a(()=>[t(d(b),null,{default:a(()=>[f(u(I.value),1)]),_:1})]),_:1})):i(``,!0),t(d(x),null,{default:a(()=>[F.value?(o(),m(d(v),{key:0,variant:`destructive`},{default:a(()=>[t(d(b),null,{default:a(()=>[f(u(F.value),1)]),_:1})]),_:1})):P.value?(o(),m(d(Ce),{key:2,columns:Qe,rows:P.value,"row-key":e=>e.id,"storage-key":`schedules`,"initial-sort":{id:`name`,desc:!1}},{empty:a(()=>[t(d(we),null,{default:a(()=>[t(d(ve),{variant:`icon`},{default:a(()=>[t(d(Fe))]),_:1}),t(d(be),null,{default:a(()=>[t(d(ye),null,{default:a(()=>[...c[3]||=[f(`No schedules yet`,-1)]]),_:1})]),_:1}),t(d(ie),null,{default:a(()=>[t(d(_),{size:`sm`,onClick:Q},{default:a(()=>[t(d(E),{"data-icon":`inline-start`}),c[4]||=f(`Add schedule`,-1)]),_:1})]),_:1})]),_:1})]),"cell-enabled":a(({row:e})=>[t(d(Oe),{"model-value":e.enabled,"aria-label":`${e.name} enabled`,"onUpdate:modelValue":t=>$e(e,t)},null,8,[`model-value`,`aria-label`,`onUpdate:modelValue`])]),"cell-name":a(({row:t})=>[s(`span`,Re,[s(`span`,ze,u(t.name),1),t.built_in?(o(),m(d(e),{key:0,variant:`outline`},{default:a(()=>[...c[5]||=[f(`Built-in`,-1)]]),_:1})):i(``,!0)])]),"cell-owner":a(({row:e})=>[s(`span`,Be,u(W(e)),1)]),"cell-interval":a(({row:e})=>[s(`span`,{title:e.timing.kind===`cron`?e.timing.cron:void 0},u(Ze(e)),9,Ve)]),"cell-last":a(({row:r})=>[r.last_run?(o(),m(l,{key:0,to:`/org/schedules/${encodeURIComponent(r.id)}/runs`,class:`inline-flex items-center gap-2 hover:underline`},{default:a(()=>[t(d(k),{at:r.last_run.started||r.last_run.scheduled_for},null,8,[`at`]),r.last_run.result===`failed`?(o(),m(d(e),{key:0,variant:`danger`,title:r.Line truncated
|
||||
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
import{$n as e,A as t,B as n,Bn as r,C as i,Cn as a,Dn as o,E as s,En as c,Fn as l,G as u,Gn as d,Gt as f,Hn as p,Ht as m,In as h,Jn as g,Kn as ee,Ln as _,M as v,Mn as y,Nn as te,On as ne,Ot as b,Pn as x,Qn as S,Rn as C,U as w,Un as re,V as ie,Vn as T,Wn as ae,Xn as oe,Xt as se,Yn as E,Z as ce,Zn as D,_t as O,a as le,an as ue,bn as de,cn as fe,ct as pe,d as me,dt as he,er as k,g as ge,gn as _e,gt as ve,ht as ye,i as be,it as xe,jn as A,jt as Se,kn as Ce,l as we,n as Te,o as Ee,or as De,pn as Oe,qn as j,r as ke,rt as Ae,tr as je,v as Me,w as Ne,wn as Pe,wt as Fe,x as Ie,xn as Le,xt as Re,y as ze,yn as Be,zn as Ve}from"./PageHeader.js";var He=void 0,Ue=typeof window<`u`&&window.trustedTypes;if(Ue)try{He=Ue.createPolicy(`vue`,{createHTML:e=>e})}catch{}var We=He?e=>He.createHTML(e):e=>e,Ge=`http://www.w3.org/2000/svg`,Ke=`http://www.w3.org/1998/Math/MathML`,M=typeof document<`u`?document:null,qe=M&&M.createElement(`template`),Je={insert:(e,t,n)=>{t.insertBefore(e,n||null)},remove:e=>{let t=e.parentNode;t&&t.removeChild(e)},createElement:(e,t,n,r)=>{let i=t===`svg`?M.createElementNS(Ge,e):t===`mathml`?M.createElementNS(Ke,e):n?M.createElement(e,{is:n}):M.createElement(e);return e===`select`&&r&&r.multiple!=null&&i.setAttribute(`multiple`,r.multiple),i},createText:e=>M.createTextNode(e),createComment:e=>M.createComment(e),setText:(e,t)=>{e.nodeValue=t},setElementText:(e,t)=>{e.textContent=t},parentNode:e=>e.parentNode,nextSibling:e=>e.nextSibling,querySelector:e=>M.querySelector(e),setScopeId(e,t){e.setAttribute(t,``)},insertStaticContent(e,t,n,r,i,a){let o=n?n.previousSibling:t.lastChild;if(i&&(i===a||i.nextSibling))for(;t.insertBefore(i.cloneNode(!0),n),i!==a&&(i=i.nextSibling););else{qe.innerHTML=We(r===`svg`?`<svg>${e}</svg>`:r===`mathml`?`<math>${e}</math>`:e);let i=qe.content;if(r===`svg`||r===`mathml`){let e=i.firstChild;for(;e.firstChild;)i.appendChild(e.firstChild);i.removeChild(e)}t.insertBefore(i,n)}return[o?o.nextSibling:t.firstChild,n?n.previousSibling:t.lastChild]}},N=`transition`,P=`animation`,F=Symbol(`_vtc`),Ye={name:String,type:String,css:{type:Boolean,default:!0},duration:[String,Number,Object],enterFromClass:String,enterActiveClass:String,enterToClass:String,appearFromClass:String,appearActiveClass:String,appearToClass:String,leaveFromClass:String,leaveActiveClass:String,leaveToClass:String},Xe=h({},le,Ye),Ze=(e=>(e.displayName=`Transition`,e.props=Xe,e))((e,{slots:t})=>w(be,$e(e),t)),I=(e,t=[])=>{T(e)?e.forEach(e=>e(...t)):e&&e(...t)},Qe=e=>e?T(e)?e.some(e=>e.length>1):e.length>1:!1;function $e(e){let t={};for(let n in e)n in Ye||(t[n]=e[n]);if(e.css===!1)return t;let{name:n=`v`,type:r,duration:i,enterFromClass:a=`${n}-enter-from`,enterActiveClass:o=`${n}-enter-active`,enterToClass:s=`${n}-enter-to`,appearFromClass:c=a,appearActiveClass:l=o,appearToClass:u=s,leaveFromClass:d=`${n}-leave-from`,leaveActiveClass:f=`${n}-leave-active`,leaveToClass:p=`${n}-leave-to`}=e,m=et(i),g=m&&m[0],ee=m&&m[1],{onBeforeEnter:_,onEnter:v,onEnterCancelled:y,onLeave:te,onLeaveCancelled:ne,onBeforeAppear:b=_,onAppear:x=v,onAppearCancelled:S=y}=t,C=(e,t,n,r)=>{e._enterCancelled=r,R(e,t?u:s),R(e,t?l:o),n&&n()},w=(e,t)=>{e._isLeaving=!1,R(e,d),R(e,p),R(e,f),t&&t()},re=e=>(t,n)=>{let i=e?x:v,o=()=>C(t,e,n);I(i,[t,o]),nt(()=>{R(t,e?c:a),L(t,e?u:s),Qe(i)||it(t,r,g,o)})};return h(t,{onBeforeEnter(e){I(_,[e]),L(e,a),L(e,o)},onBeforeAppear(e){I(b,[e]),L(e,c),L(e,l)},onEnter:re(!1),onAppear:re(!0),onLeave(e,t){e._isLeaving=!0;let n=()=>w(e,t);L(e,d),e._enterCancelled?(L(e,f),ct(e)):(ct(e),L(e,f)),nt(()=>{e._isLeaving&&(R(e,d),L(e,p),Qe(te)||it(e,r,ee,n))}),I(te,[e,n])},onEnterCancelled(e){C(e,!1,void 0,!0),I(y,[e])},onAppearCancelled(e){C(e,!0,void 0,!0),I(S,[e])},onLeaveCancelled(e){w(e),I(ne,[e])}})}function et(e){if(e==null)return null;if(ae(e))return[tt(e.enter),tt(e.leave)];{let t=tt(e);return[t,t]}}function tt(e){return De(e)}function L(e,t){t.split(/\s+/).forEach(t=>t&&e.classList.add(t)),(e[F]||(e[F]=new Set)).add(t)}function R(e,t){t.split(/\s+/).forEach(t=>t&&e.classList.remove(t));let n=e[F];n&&(n.delete(t),n.size||(e[F]=void 0))}function nt(e){requestAnimationFrame(()=>{requestAnimationFrame(e)})}var rt=0;function it(e,t,n,r){let i=e._endId=++rt,a=()=>{i===e._endId&&r()};if(n!=null)return setTimeout(a,n);let{type:o,timeout:s,propCount:c}=at(e,t);if(!o)return r();let l=o+`end`,u=0,d=()=>{e.removeEventListener(l,f),a()},f=t=>{t.target===e&&++u>=c&&d()};setTimeout(()=>{u<c&&d()},s+1),e.addEventListener(l,f)}function at(e,t){let n=window.getComputedStyle(e),r=e=>(n[e]||``).split(`, `),i=r(`${N}Delay`),a=r(`${N}Duration`),o=ot(i,a),s=r(`${P}Delay`),c=r(`${P}Duration`),l=ot(s,c),u=null,d=0,f=0;t===N?o>0&&(u=N,d=o,f=a.length):t===P?l>0&&(u=P,d=l,f=c.length):(d=Math.max(o,l),u=d>0?o>l?N:P:null,f=u?u===N?a.length:c.length:0);let p=u===N&&/\b(?:transform|all)(?:,|$)/.test(r(`${N}Property`).toString());return{type:u,timeout:d,propCount:f,hasTransform:p}}function ot(e,t){for(;e.length<t.length;)e=e.concat(e);return Math.maLine truncated
|
||||
`))),e[J]=q(i);let a=r||i.props&&i.props.type===`number`;W(e,t?`change`:`input`,t=>{t.target.composing||e[J](un(e.value,n,a))}),(n||a)&&W(e,`change`,()=>{e.value=un(e.value,n,a)}),t||(W(e,`compositionstart`,sn),W(e,`compositionend`,cn),W(e,`change`,cn))},mounted(e,{value:t,modifiers:{trim:n,number:r}}){let i=t??``,a=e[ln];delete e[ln],a!==void 0&&(e.type===`text`||e.type===`textarea`)&&e.value!==a?e[J](un(e.value,n,r)):e.value=i},beforeUpdate(t,{value:n,oldValue:r,modifiers:{lazy:i,trim:a,number:o}},s){if(t[J]=q(s),t.composing)return;let c=(o||t.type===`number`)&&!/^0\d/.test(t.value)?e(t.value):t.value,l=n??``;if(c===l)return;let u=t.getRootNode();(u instanceof Document||u instanceof ShadowRoot)&&u.activeElement===t&&t.type!==`range`&&(i&&n===r||a&&t.value.trim()===l)||(t.value=l)}},fn={deep:!0,created(e,t,n){e[J]=q(n),W(e,`change`,()=>{let t=e._modelValue,n=Y(e),r=e.checked,i=e[J];if(T(t)){let e=S(t,n),a=e!==-1;if(r&&!a)i(t.concat(n));else if(!r&&a){let n=[...t];n.splice(e,1),i(n)}}else if(j(t)){let e=new Set(t);r?e.add(n):e.delete(n),i(e)}else i(vn(e,r))})},mounted:pn,beforeUpdate(e,t,n){e[J]=q(n),pn(e,t,n)}};function pn(e,{value:t,oldValue:n},r){e._modelValue=t;let i;if(T(t))i=S(t,r.props.value)>-1;else if(j(t))i=t.has(r.props.value);else{if(t===n)return;i=D(t,vn(e,!0))}e.checked!==i&&(e.checked=i)}var mn={created(e,{value:t},n){e.checked=D(t,n.props.value),e[J]=q(n),W(e,`change`,()=>{e[J](Y(e))})},beforeUpdate(e,{value:t,oldValue:n},r){e[J]=q(r),t!==n&&(e.checked=D(t,r.props.value))}},hn={deep:!0,created(t,{value:n,modifiers:{number:r}},i){t._modelValue=n,W(t,`change`,()=>{let n=Array.prototype.filter.call(t.options,e=>e.selected).map(t=>r?e(Y(t)):Y(t)),i=t.multiple,a=i?j(t._modelValue)?new Set(n):n:n[0],o=t._pendingValue=[i,i?T(a)?n.slice():n:a];try{t[J](a)}finally{xe(()=>{t._pendingValue===o&&(t._pendingValue=void 0)})}}),t[J]=q(i)},mounted(e,{value:t}){_n(e,t)},beforeUpdate(e,{value:t},n){e._modelValue=t,e[J]=q(n)},updated(e,{value:t}){let n=e._pendingValue;e._pendingValue=void 0,n&&n[0]===e.multiple&&gn(t,n[1],n[0])||_n(e,t)}};function gn(e,t,n){if(!n||T(e))return D(e,t);if(j(e)){if(e.size!==t.length)return!1;for(let n of t)if(!e.has(n))return!1;return!0}return!1}function _n(e,t){let n=e.multiple,r=T(t);if(!n||r||j(t)){for(let i=0,a=e.options.length;i<a;i++){let a=e.options[i],o=Y(a);if(n){if(r){let e=typeof o;a.selected=e===`string`||e===`number`?t.some(e=>String(e)===String(o)):S(t,o)>-1}else a.selected=t.has(o)}else if(D(Y(a),t)){e.selectedIndex!==i&&(e.selectedIndex=i);return}}!n&&e.selectedIndex!==-1&&(e.selectedIndex=-1)}}function Y(e){return`_value`in e?e._value:e.value}function vn(e,t){let n=t?`_trueValue`:`_falseValue`;return n in e?e[n]:t}var yn={created(e,t,n){xn(e,t,n,null,`created`)},mounted(e,t,n){xn(e,t,n,null,`mounted`)},beforeUpdate(e,t,n,r){xn(e,t,n,r,`beforeUpdate`)},updated(e,t,n,r){xn(e,t,n,r,`updated`)}};function bn(e,t){switch(e){case`SELECT`:return hn;case`TEXTAREA`:return dn;default:switch(t){case`checkbox`:return fn;case`radio`:return mn;default:return dn}}}function xn(e,t,n,r,i){let a=bn(e.tagName,n.props&&n.props.type)[i];a&&a(e,t,n,r)}function Sn(){dn.getSSRProps=({value:e})=>({value:e}),mn.getSSRProps=({value:e},t)=>{if(t.props&&D(t.props.value,e))return{checked:!0}},fn.getSSRProps=({value:e},t)=>{if(T(e)){if(t.props&&S(e,t.props.value)>-1)return{checked:!0}}else if(j(e)){if(t.props&&e.has(t.props.value))return{checked:!0}}else if(e)return{checked:!0}},yn.getSSRProps=(e,t)=>{if(typeof t.type!=`string`)return;let n=bn(t.type.toUpperCase(),t.props&&t.props.type);if(n.getSSRProps)return n.getSSRProps(e,t)}}var Cn=[`ctrl`,`shift`,`alt`,`meta`],wn={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>`button`in e&&e.button!==0,middle:e=>`button`in e&&e.button!==1,right:e=>`button`in e&&e.button!==2,exact:(e,t)=>Cn.some(n=>e[`${n}Key`]&&!t.includes(n))},Tn=(e,t)=>{if(!e)return e;let n=e._withMods||={},r=t.join(`.`);return n[r]||(n[r]=((n,...r)=>{for(let e=0;e<t.length;e++){let r=wn[t[e]];if(r&&r(n,t))return}return e(n,...r)}))},En={esc:`escape`,space:` `,up:`arrow-up`,left:`arrow-left`,right:`arrow-right`,down:`arrow-down`,delete:`backspace`},Dn=(e,t)=>{let n=e._withKeys||={},r=t.join(`.`);return n[r]||(n[r]=(n=>{if(!(`key`in n))return;let r=C(n.key);if(t.some(e=>e===r||En[e]===r))return e(n)}))},On=h({patchProp:It},Je),kn,An=!1;function jn(){return kn||=s(On)}function Mn(){return kn=An?kn:Ne(On),An=!0,kn}var Nn=((...e)=>{jn().render(...e)}),Pn=((...e)=>{Mn().hydrate(...e)}),Fn=((...e)=>{let t=jn().createApp(...e),{mount:n}=t;return t.mount=e=>{let r=Rn(e);if(!r)return;let i=t._component;p(i)||i.render||i.template||(i.template=r.innerHTML),r.nodeType===1&&(r.textContent=``);let a=n(r,!1,Ln(r));return r instanceof Element&&(r.removeAttribute(`v-cloak`),r.setAttribute(`data-v-app`,``)),a},t}),In=((...e)=>{let t=Mn().createApp(...e),{mount:n}=t;return t.m
Line truncated
|
||||
`)[0].slice(0,200)}catch{}return`${e.status} ${e.statusText}`}var Fr;function Ir(e){Fr=e}var Lr=class extends Error{status;constructor(e,t){super(e),this.name=`ApiError`,this.status=t}};function Rr(e){let t=e instanceof Lr?e.status:void 0,n=e instanceof Error&&e.message?e.message:`Action failed`;return t===401?{kind:`session-expired`,message:n}:t!==void 0&&t>=400&&t<500?{kind:`refused`,message:n}:{kind:`broken`,message:n}}async function zr(e,t){let n=await fetch(e,t);if(Fr?.(n.status===401),!n.ok)throw new Lr(await Pr(n),n.status);return n}async function Q(e,t={}){let{method:n=`GET`,body:r,timeoutMs:i=Nr,parse:a=!0}=t,o={Accept:`application/json`},s={method:n,headers:o,signal:AbortSignal.timeout(i)};n!==`GET`&&(o[`Content-Type`]=`application/json`,o[`X-Archie-CSRF`]=`1`),r!==void 0&&(s.body=JSON.stringify(r));let c=await zr(e,s);return a?await c.json():void 0}var Br={recoveryCode:()=>Q(`/api/account/recovery`,{method:`POST`,body:{}}),recoverAccount:(e,t,n)=>Q(`/api/auth/recover`,{method:`POST`,body:{email:e,code:t,password:n},parse:!1}),authStatus:()=>Q(`/api/auth/status`),setupAccount:e=>Q(`/api/auth/setup`,{method:`POST`,body:e}),signIn:(e,t)=>Q(`/api/auth/login`,{method:`POST`,body:{email:e,password:t}}),signOut:()=>Q(`/api/auth/logout`,{method:`POST`,body:{},parse:!1}),createAccount:e=>Q(`/api/accounts`,{method:`POST`,body:e}),changePassword:(e,t)=>Q(`/api/account/password`,{method:`POST`,body:{current_password:e,new_password:t},parse:!1}),authentication:()=>Q(`/api/authentication`),saveAuthentication:e=>Q(`/api/authentication`,{method:`PUT`,body:e,parse:!1}),tokens:()=>Q(`/api/tokens`),createToken:()=>Q(`/api/tokens`,{method:`POST`,body:{}}),revokeToken:e=>Q(`/api/tokens/${encodeURIComponent(e)}`,{method:`DELETE`,body:{},parse:!1}),passkeys:()=>Q(`/api/account/passkeys`),deletePasskey:e=>Q(`/api/account/passkeys/${encodeURIComponent(e)}`,{method:`DELETE`,body:{},parse:!1}),beginPasskey:e=>Q(e?`/api/account/passkeys/begin`:`/api/auth/passkey/begin`,{method:`POST`,body:{}}),finishPasskey:(e,t,n)=>Q(e?`/api/account/passkeys/finish`:`/api/auth/passkey/finish`,{method:`POST`,body:{credential:t,name:n}}),secretEngines:()=>Q(`/api/secret-engines`),checkSecret:e=>Q(`/api/secret-references/check`,{method:`POST`,body:e}),health:()=>Q(`/health/detailed`),services:()=>Q(`/api/services`),policies:()=>Q(`/api/access/policies`),putPolicy:e=>Q(`/api/access/policies`,{method:`PUT`,body:e}),deletePolicy:e=>Q(`/api/access/policies`,{method:`DELETE`,body:e,parse:!1}),schedules:()=>Q(`/api/schedules`),scheduleSave:(e,t)=>Q(`/api/schedules/${encodeURIComponent(e)}`,{method:`PUT`,body:t}),scheduleDelete:e=>Q(`/api/schedules/${encodeURIComponent(e)}`,{method:`DELETE`,parse:!1}),scheduleRunNow:e=>Q(`/api/schedules/${encodeURIComponent(e)}/runs`,{method:`POST`,body:{}}),scheduleRuns:e=>Q(`/api/schedules/${encodeURIComponent(e)}/runs`),orgs:()=>Q(`/api/orgs`),orgSelect:e=>Q(`/api/orgs/current`,{method:`PUT`,body:{id:e},parse:!1}),orgCreate:e=>Q(`/api/orgs`,{method:`POST`,body:e}),org:e=>Q(`/api/orgs/${encodeURIComponent(e)}`),orgWorkspaces:e=>Q(`/api/orgs/${encodeURIComponent(e)}/workspaces`),createOrgWorkspace:(e,t)=>Q(`/api/orgs/${encodeURIComponent(e)}/workspaces`,{method:`POST`,body:t}),orgAgents:e=>Q(`/api/orgs/${encodeURIComponent(e)}/agents`),orgMembers:e=>Q(`/api/orgs/${encodeURIComponent(e)}/members`),addOrgMember:(e,t)=>Q(`/api/orgs/${encodeURIComponent(e)}/members`,{method:`POST`,body:t}),setOrgMember:(e,t,n)=>Q(`/api/orgs/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,{method:`PUT`,body:n}),removeOrgMember:(e,t,n)=>Q(`/api/orgs/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`+Z({workspace:n}),{method:`DELETE`,parse:!1}),assignOrgAgent:(e,t)=>Q(`/api/orgs/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}`,{method:`PUT`}),alerts:()=>Q(`/api/alerts`),dismissAlert:e=>Q(`/api/alerts/${e}/dismiss`,{method:`POST`,parse:!1}),identities:()=>Q(`/api/identities`),identityCreate:e=>Q(`/api/identities`,{method:`POST`,body:e}),identityCommand:(e,t,n)=>Q(`/api/identities/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`POST`,body:n}),summary:()=>Q(`/api/summary`),tasks:()=>Q(`/api/tasks`),taskPage:async e=>{let t=await zr(`/api/tasks`+Z(e),{headers:{Accept:`application/json`},signal:AbortSignal.timeout(Nr)});return{tasks:await t.json(),next:t.headers.get(`X-Next-Cursor`)}},taskMeta:()=>Q(`/api/task-meta`),task:e=>Q(`/api/tasks/${encodeURIComponent(e)}`),taskAttempts:e=>Q(`/api/tasks/${encodeURIComponent(e)}/attempts`),taskChanges:(e,t)=>Q(`/api/tasks/${encodeURIComponent(e)}/changes`+Z(t)),taskDebug:(e,t)=>Q(`/api/tasks/${encodeURIComponent(e)}/debug`+Z(t)),taskAction:(e,t,n)=>Q(`/api/tasks/${encodeURIComponent(e)}/action`,{method:`POST`,body:{action:t,...n}}),setup:()=>Q(`/api/setup`),capabilities:()=>Q(`/api/capabilities`),workflows:()=>Q(`/api/workflows`),workflowEnabled:(e,t)=>Q(`/api/workflows/${encodeURIComponent(e)}/enabled`,{method:`PUT`,body:{enabled:t},parse:!1}),checkRepository:e=
Line truncated
|
||||
`)[0].slice(0,200)}catch{}return`${e.status} ${e.statusText}`}var Fr;function Ir(e){Fr=e}var Lr=class extends Error{status;constructor(e,t){super(e),this.name=`ApiError`,this.status=t}};function Rr(e){let t=e instanceof Lr?e.status:void 0,n=e instanceof Error&&e.message?e.message:`Action failed`;return t===401?{kind:`session-expired`,message:n}:t!==void 0&&t>=400&&t<500?{kind:`refused`,message:n}:{kind:`broken`,message:n}}async function zr(e,t){let n=await fetch(e,t);if(Fr?.(n.status===401),!n.ok)throw new Lr(await Pr(n),n.status);return n}async function Q(e,t={}){let{method:n=`GET`,body:r,timeoutMs:i=Nr,parse:a=!0}=t,o={Accept:`application/json`},s={method:n,headers:o,signal:AbortSignal.timeout(i)};n!==`GET`&&(o[`Content-Type`]=`application/json`,o[`X-Archie-CSRF`]=`1`),r!==void 0&&(s.body=JSON.stringify(r));let c=await zr(e,s);return a?await c.json():void 0}var Br={recoveryCode:()=>Q(`/api/account/recovery`,{method:`POST`,body:{}}),recoverAccount:(e,t,n)=>Q(`/api/auth/recover`,{method:`POST`,body:{email:e,code:t,password:n},parse:!1}),authStatus:()=>Q(`/api/auth/status`),setupAccount:e=>Q(`/api/auth/setup`,{method:`POST`,body:e}),signIn:(e,t)=>Q(`/api/auth/login`,{method:`POST`,body:{email:e,password:t}}),signOut:()=>Q(`/api/auth/logout`,{method:`POST`,body:{},parse:!1}),createAccount:e=>Q(`/api/accounts`,{method:`POST`,body:e}),changePassword:(e,t)=>Q(`/api/account/password`,{method:`POST`,body:{current_password:e,new_password:t},parse:!1}),authentication:()=>Q(`/api/authentication`),saveAuthentication:e=>Q(`/api/authentication`,{method:`PUT`,body:e,parse:!1}),tokens:()=>Q(`/api/tokens`),createToken:(e,t)=>Q(`/api/tokens`,{method:`POST`,body:{name:e,days:t}}),revokeToken:e=>Q(`/api/tokens/${encodeURIComponent(e)}`,{method:`DELETE`,body:{},parse:!1}),passkeys:()=>Q(`/api/account/passkeys`),deletePasskey:e=>Q(`/api/account/passkeys/${encodeURIComponent(e)}`,{method:`DELETE`,body:{},parse:!1}),beginPasskey:e=>Q(e?`/api/account/passkeys/begin`:`/api/auth/passkey/begin`,{method:`POST`,body:{}}),finishPasskey:(e,t,n)=>Q(e?`/api/account/passkeys/finish`:`/api/auth/passkey/finish`,{method:`POST`,body:{credential:t,name:n}}),secretEngines:()=>Q(`/api/secret-engines`),checkSecret:e=>Q(`/api/secret-references/check`,{method:`POST`,body:e}),health:()=>Q(`/health/detailed`),services:()=>Q(`/api/services`),policies:()=>Q(`/api/access/policies`),putPolicy:e=>Q(`/api/access/policies`,{method:`PUT`,body:e}),deletePolicy:e=>Q(`/api/access/policies`,{method:`DELETE`,body:e,parse:!1}),schedules:()=>Q(`/api/schedules`),scheduleSave:(e,t)=>Q(`/api/schedules/${encodeURIComponent(e)}`,{method:`PUT`,body:t}),scheduleDelete:e=>Q(`/api/schedules/${encodeURIComponent(e)}`,{method:`DELETE`,parse:!1}),scheduleRunNow:e=>Q(`/api/schedules/${encodeURIComponent(e)}/runs`,{method:`POST`,body:{}}),scheduleRuns:e=>Q(`/api/schedules/${encodeURIComponent(e)}/runs`),orgs:()=>Q(`/api/orgs`),orgSelect:e=>Q(`/api/orgs/current`,{method:`PUT`,body:{id:e},parse:!1}),orgCreate:e=>Q(`/api/orgs`,{method:`POST`,body:e}),org:e=>Q(`/api/orgs/${encodeURIComponent(e)}`),orgWorkspaces:e=>Q(`/api/orgs/${encodeURIComponent(e)}/workspaces`),createOrgWorkspace:(e,t)=>Q(`/api/orgs/${encodeURIComponent(e)}/workspaces`,{method:`POST`,body:t}),orgAgents:e=>Q(`/api/orgs/${encodeURIComponent(e)}/agents`),orgMembers:e=>Q(`/api/orgs/${encodeURIComponent(e)}/members`),addOrgMember:(e,t)=>Q(`/api/orgs/${encodeURIComponent(e)}/members`,{method:`POST`,body:t}),setOrgMember:(e,t,n)=>Q(`/api/orgs/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,{method:`PUT`,body:n}),removeOrgMember:(e,t,n)=>Q(`/api/orgs/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`+Z({workspace:n}),{method:`DELETE`,parse:!1}),assignOrgAgent:(e,t)=>Q(`/api/orgs/${encodeURIComponent(e)}/agents/${encodeURIComponent(t)}`,{method:`PUT`}),alerts:()=>Q(`/api/alerts`),dismissAlert:e=>Q(`/api/alerts/${e}/dismiss`,{method:`POST`,parse:!1}),identities:()=>Q(`/api/identities`),identityCreate:e=>Q(`/api/identities`,{method:`POST`,body:e}),identityCommand:(e,t,n)=>Q(`/api/identities/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`POST`,body:n}),summary:()=>Q(`/api/summary`),tasks:()=>Q(`/api/tasks`),taskPage:async e=>{let t=await zr(`/api/tasks`+Z(e),{headers:{Accept:`application/json`},signal:AbortSignal.timeout(Nr)});return{tasks:await t.json(),next:t.headers.get(`X-Next-Cursor`)}},taskMeta:()=>Q(`/api/task-meta`),task:e=>Q(`/api/tasks/${encodeURIComponent(e)}`),taskAttempts:e=>Q(`/api/tasks/${encodeURIComponent(e)}/attempts`),taskChanges:(e,t)=>Q(`/api/tasks/${encodeURIComponent(e)}/changes`+Z(t)),taskDebug:(e,t)=>Q(`/api/tasks/${encodeURIComponent(e)}/debug`+Z(t)),taskAction:(e,t,n)=>Q(`/api/tasks/${encodeURIComponent(e)}/action`,{method:`POST`,body:{action:t,...n}}),setup:()=>Q(`/api/setup`),capabilities:()=>Q(`/api/capabilities`),workflows:()=>Q(`/api/workflows`),workflowEnabled:(e,t)=>Q(`/api/workflows/${encodeURIComponent(e)}/enabled`,{method:`PUT`,body:{enabled:t},parse:!1}),ch
Line truncated
|
||||
Vendored
+1
-1
@@ -322,4 +322,4 @@ Edge: ${e}`,EDGE_NOT_FOUND:e=>`Edge not found
|
||||
Edge: ${e}`,USEVUEFLOW_OPTIONS:()=>`The options parameter is deprecated and will be removed in the next major version. Please use the id parameter instead`},T7=class extends Error{constructor(e,...t){super(w7[e]?.call(w7,...t)),this.name=`VueFlowError`,this.code=e,this.args=t}};function E7(e){return`clientX`in e}function Wce(e){return`sourceEvent`in e}function D7(e,t){let n=E7(e),r,i;return n?(r=e.clientX,i=e.clientY):`touches`in e&&e.touches.length>0?(r=e.touches[0].clientX,i=e.touches[0].clientY):`changedTouches`in e&&e.changedTouches.length>0?(r=e.changedTouches[0].clientX,i=e.changedTouches[0].clientY):(r=0,i=0),{x:r-(t?.left??0),y:i-(t?.top??0)}}var O7=()=>typeof navigator<`u`&&(navigator==null?void 0:navigator.userAgent)?.indexOf(`Mac`)>=0;function Gce(e){return{width:e.dimensions?.width??e.width??0,height:e.dimensions?.height??e.height??0}}function k7(e,t=[1,1]){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}var Kce=()=>!0;function A7(e){e?.classList.remove(`valid`,`connecting`,`vue-flow__handle-valid`,`vue-flow__handle-connecting`)}function qce(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())L5(i,I5(e))>0&&r.push(e);return r}var Jce=250;function Yce(e,t,n,r){let i=[],a=1/0,o=qce(e,n,t+Jce);for(let n of o){let o=[...n.handleBounds?.source??[],...n.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=x7(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function j7(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=Kce},u,d,f,p){let m=a===`target`,h=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y:_}=D7(e),v=o.elementFromPoint(g,_),y=v?.classList.contains(`${s}-flow__handle`)?v:h,b={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){let e=M7(void 0,y),t=y.getAttribute(`data-nodeid`),a=y.getAttribute(`data-handleid`),o=y.classList.contains(`connectable`),s=y.classList.contains(`connectableend`);if(!t||!e)return b;let c={source:m?t:r,sourceHandle:m?a:i,target:m?r:t,targetHandle:m?i:a};b.connection=c,b.isValid=o&&s&&(n===E5.Strict?m&&e===`source`||!m&&e===`target`:t!==r||a!==i)&&l(c,{nodes:d,edges:u,sourceNode:f(c.source),targetNode:f(c.target)}),b.toHandle=N7(t,e,a,p,n,!0)}return b}function M7(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function Xce(e,t){let n=null;return t?n=`valid`:e&&!t&&(n=`invalid`),n}function Zce(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}function N7(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===E5.Strict?o.handleBounds?.[t]:[...o.handleBounds?.source??[],...o.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...x7(o,c,c.position,!0)}:c}var P7={[C5.Left]:C5.Right,[C5.Right]:C5.Left,[C5.Top]:C5.Bottom,[C5.Bottom]:C5.Top},Qce=[`production`,`prod`];function F7(e,...t){I7()&&console.warn(`[Vue Flow]: ${e}`,...t)}function I7(){return!Qce.includes(`production`)}function L7(e,t,n,r,i){let a=t.querySelectorAll(`.vue-flow__handle.${e}`);return a?.length?Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...R5(t)}}):null}function R7(e,t,n,r,i,a=!1,o){i.value=!1,e.selected?(a||e.selected&&t)&&(r([e]),ze(()=>{o.blur()})):n([e])}function z7(e){return V(e)!==void 0}function $ce(e,t,n,r){if(!e||!e.source||!e.target)return n(new T7(C7.EDGE_INVALID,e?.id??`[ID UNKNOWN]`)),!1;let i;return i=H5(e)?e:{...e,id:J5(e)},i=K5(i,void 0,r),!Mce(i,t)&&i}function ele(e,t,n,r,i){if(!t.source||!t.target)return i(new T7(C7.EDGE_INVALID,e.id)),!1;if(!n)return i(new T7(C7.EDGE_NOT_FOUND,e.id)),!1;let{id:a,...o}=e;return{...o,id:r?J5(t):a,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle}}function B7(e,t,n){let r={},i=[];for(let a=0;a<e.length;++a){let o=e[a];if(!U5(o)){n(new T7(C7.NODE_INVALID,o?.id));continue}let s=kce(o,t(o.id),o.parentNode);o.parentNode&&(r[o.parentNode]=!0),i[a]=s}for(let e of i){let a=t(e.parentNode)||i.find(t=>t.id===e.parentNode);e.parentNode&&!a&&n(new T7(C7.NODE_MISSING_PARENT,e.id,e.parentNode)),(e.parentNode||r[e.id])&&(r[e.id]&&(e.isParent=!0),a&&(a.isParent=!0))}return i}function V7(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function H7(e,t,n){e.clear();for(let t of n){let{source:n,target:r,sourceHandle:i=null,targetHandle:a=null}=t,o={edgeId:t.id,source:n,target:r,sourceHandle:i,targetHandle:a},s=`${n}-${i}--${r}-${a}`;V7(`sourcLine truncated
|
||||
`)},B(e.data.summary||e.data.detail),9,Hue)):F(``,!0),e.data.when||e.data.retry||e.data.continues?(L(),j(`div`,Uue,[e.data.when?(L(),j(`span`,{key:0,class:`flex max-w-full min-w-0 items-center gap-0.5 rounded bg-secondary px-1 font-mono`,title:`Runs only when ${e.data.when}`},[A(V(Xl),{class:`size-3 shrink-0`,"aria-hidden":`true`}),R(`span`,Gue,B(e.data.when),1)],8,Wue)):F(``,!0),e.data.retry?(L(),j(`span`,{key:1,class:`flex items-center gap-0.5 rounded bg-secondary px-1`,title:`Up to ${e.data.retry} attempts`},[A(V(xu),{class:`size-3`,"aria-hidden":`true`}),H(`×`+B(e.data.retry),1)],8,Kue)):F(``,!0),e.data.continues?(L(),j(`span`,que,[A(V(ju),{class:`size-3`,"aria-hidden":`true`}),r[10]||=H(`continues`,-1)])):F(``,!0)])):F(``,!0),e.data.run?.error?(L(),j(`p`,{key:4,class:`mt-1 line-clamp-2 text-caption text-danger`,title:e.data.run.error},B(e.data.run.error),9,Jue)):F(``,!0)],64))]),A(it,{"enter-from-class":`opacity-0 -translate-y-1`,"enter-active-class":`transition duration-200`,"leave-to-class":`opacity-0`,"leave-active-class":`transition duration-100`},{default:I(()=>[e.data.expanded?(L(),j(`div`,{key:0,class:`nodrag nopan nowheel cursor-auto border-t border-border`,onClick:r[6]||=_t(()=>{},[`stop`])},[K(t.$slots,`default`)])):F(``,!0)]),_:3}),A(V(i9),{type:`source`,position:V(C5).Bottom},null,8,[`position`]),A(V(i9),{id:`data-out`,type:`source`,position:V(C5).Right,class:`!opacity-0`},null,8,[`position`]),e.data.type===`switch`?(L(),q(V(i9),{key:1,id:`otherwise`,type:`source`,position:V(C5).Right,class:`!opacity-0`},null,8,[`position`])):F(``,!0)],2))}}),Xue={class:`pointer-events-none size-full rounded-xl border border-dashed border-border bg-muted/30`},Zue={class:`flex items-center gap-1 px-2.5 pt-1.5 text-caption text-fg-subtle`},Que={key:0},$ue={key:1,class:`font-mono`},ede=P({__name:`LaneNode`,props:{data:{}},setup(e){return(t,n)=>(L(),j(`div`,Xue,[R(`div`,Zue,[e.data.lane===`switch`?(L(),j(U,{key:0},[A(V(Mu),{class:`size-3`,"aria-hidden":`true`}),e.data.title==="default"?(L(),j(`span`,Que,`otherwise`)):(L(),j(`span`,$ue,`= `+B(e.data.title),1))],64)):(L(),j(U,{key:1},[A(V(Ql),{class:`size-3`,"aria-hidden":`true`}),H(B(e.data.title),1)],64))])]))}}),tde={class:`flex shrink-0 items-center justify-center gap-1 border-t border-border bg-card p-1`},O9=240,nde=416,k9=-140,rde=72,ide=.9,A9=P({__name:`WorkflowCanvas`,props:{yaml:{},stages:{},open:{},triggers:{},types:{},readonly:{type:Boolean},restartable:{type:Boolean},marks:{},problems:{},title:{},summary:{}},emits:[`toggle`,`insert`,`duplicate`,`move`,`remove`,`rename`,`restart`],setup(e,{emit:t}){let n=e,r=t,i=Y(()=>!!n.types?.length&&!n.readonly),a=Y(()=>[...n.types??[],`parallel`,`switch`]),o=Y(()=>a.value.filter(e=>[`agent.run`,`workflow.call`].includes(e))),s=e=>e&&T0(e)?o.value:a.value,c=e=>e.kind===`step`?JSON.stringify(e.path??null):e.kind,l=J(null),u=J(null),d=aee(`(max-width: 767px)`),f=Y(()=>{let e=W0(t2(n.yaml),n.stages??[]);return n.types?.length?{nodes:[{id:`workflow`,type:`step`,position:{x:0,y:k9},data:{kind:`workflow`,key:`workflow`,title:n.title||`Workflow`,type:``,detail:n.summary??``}},...e.nodes],edges:[{id:`flow-workflow-start`,source:`workflow`,target:`start`,kind:`flow`},...e.edges]}:e}),p=Y(()=>f.value.nodes.filter(e=>e.data.path?.length===2).length),m=J({}),h=J({}),g=Y(()=>f.value.nodes.find(e=>e.type===`step`&&c(e.data)===n.open));function _(e,t){m.value={...m.value,[e]:t},g.value?.id!==e&&(h.value={...h.value,[e]:t})}let v=Y(()=>{let e=d.value?void 0:g.value?.id;return e&&m.value[e]?Math.max(0,m.value[e]-(h.value[e]??m.value[e])):0}),y=uee(),b=ree(v,{duration:Y(()=>y.value===`reduce`?0:200)}),x=Y(()=>{let e=new Map;for(let t of f.value.nodes){if(t.type!==`step`)continue;let n=(t.id===g.value?.id?h.value[t.id]:void 0)??m.value[t.id];n!==void 0&&e.set(t.position.y,Math.max(e.get(t.position.y)??-72,n-rde))}return[...e]}),S=e=>x.value.reduce((t,[n,r])=>n<e?t+r:t,0);function C(e){let t=e.data,a=c(t),o=t.path,s={triggers:t.kind===`start`?n.triggers??[]:t.triggers,expanded:!d.value&&a===n.open,editable:i.value,problem:o?n.problems?.[a]:void 0,onResize:t=>_(e.id,t)};return n.types?.length&&(s.onToggle=()=>r(`toggle`,a)),i.value&&o&&(s.onRename=e=>r(`rename`,o,e),s.onDuplicate=()=>r(`duplicate`,o),s.onRemove=()=>r(`remove`,o)),{...e,data:{...t,...s}}}let w=e=>{let t=g.value;return d.value||!t||!e.style?.width?!1:e.position.x<=t.position.x&&e.position.x+parseFloat(String(e.style.width))>=t.position.x+O9};function ee(e){let t=g.value;if(d.value||!t)return 0;if(e.id===t.id||w(e))return-88;let n=t.position.x+O9/2,r=e.style?.width?parseFloat(String(e.style.width)):e.type===`step`?O9:32,i=e.position.x+r/2;return Math.abs(i-n)<O9/2?0:i<n?-88:88}let T=Y(()=>{let e=g.value;return f.value.nodes.map(t=>{let a=t;t.type===`add`?t={...t,data:{...t.data,types:s(t.data.insertAfter),editable:i.value,onInsert:e=>r(`insert`,t.data.insertAfter,e)}}:t.type===`step`&&(t=C(t));let o=n.marks?.[t.id];o&&(t={...t,data:{...t.data,mark:o}});let c=t.position.
Line truncated
|
||||
`),r=t.split(`
|
||||
`),i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;e--)for(let t=r.length-1;t>=0;t--)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({kind:`same`,text:n[o++]}),s++):i[o+1][s]>=i[o][s+1]?a.push({kind:`del`,text:n[o++]}):a.push({kind:`add`,text:r[s++]});for(;o<n.length;)a.push({kind:`del`,text:n[o++]});for(;s<r.length;)a.push({kind:`add`,text:r[s++]});return a}function j9(e){let t=y0(e).toJS(),n=new Map;for(let r of t2(e).nodes){let{kind:e,path:i,stage:a,occurrence:o}=r.data;if(r.type!==`step`||e!==`step`||!i||a===void 0)continue;let s=t;for(let e of i)s=s?.[e];n.set(`${a}#${o??0}`,{node:r.id,signature:JSON.stringify(s??null)})}return n}function M9(e,t,n){let r=j9(e),i=j9(t),a={};for(let[e,t]of r){let r=i.get(e);r?r.signature!==t.signature&&(a[t.node]=`changed`):a[t.node]=n}return a}var lde={class:`flex flex-col gap-3 md:grid md:h-[calc(100dvh-17rem)] md:min-h-[26rem] md:grid-cols-[18rem_1fr]`},ude=[`aria-current`,`onClick`],dde={class:`flex items-center gap-2 text-sm`},fde={class:`font-mono text-xs text-fg-subtle`},pde=[`title`],mde={key:0,class:`px-3 py-2 text-sm text-fg-muted`},hde={key:1,class:`flex min-h-0 flex-col gap-2`},gde={class:`flex items-center gap-2 max-md:flex-wrap`},_de={key:0,class:`rounded-lg border border-border p-4 text-sm text-fg-muted`},vde={key:1,class:`min-h-0 flex-1 overflow-auto rounded-lg border border-border pt-2 pb-[calc(0.5rem+var(--code-overscroll))] font-mono text-label leading-6`},yde={class:`inline-block w-4 select-none text-fg-subtle`},bde={key:2,class:`grid min-h-0 flex-1 gap-3 max-md:flex-none md:grid-cols-2`},xde={class:`flex min-h-0 flex-col gap-1`},Sde={class:`text-caption font-medium uppercase text-fg-muted`},Cde={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},wde={class:`flex min-h-0 flex-col gap-1`},Tde={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},Ede=P({__name:`WorkflowHistory`,props:Ue({revisions:{},current:{},error:{}},{selected:{default:0},selectedModifiers:{},mode:{default:`yaml`},modeModifiers:{}}),emits:Ue([`restore`],[`update:selected`,`update:mode`]),setup(e,{emit:t}){let n=e,r=t,i=Te(e,`selected`),a=Te(e,`mode`);N(()=>n.revisions,e=>{e.some(e=>e.version===i.value)||(i.value=(e.find(e=>e.yaml!==n.current)??e[0])?.version??0)},{immediate:!0});let o=Y(()=>n.revisions.find(e=>e.version===i.value)),s=Y(()=>o.value?.yaml??null),c=Y(()=>s.value===null?[]:cde(s.value,n.current)),l=Y(()=>s.value!==null&&s.value===n.current),u=Y(()=>s.value===null?{}:M9(s.value,n.current,`removed`)),d=Y(()=>s.value===null?{}:M9(n.current,s.value,`added`)),f={added:`default`,edited:`secondary`,removed:`destructive`};return(t,n)=>(L(),j(`div`,lde,[R(`ol`,{class:z(V(W)(`min-h-0 divide-y divide-border overflow-y-auto rounded-lg border border-border`,e.revisions.length&&`max-md:hidden`)),"aria-label":`Revisions`},[(L(!0),j(U,null,M(e.revisions,e=>(L(),j(`li`,{key:e.version},[R(`button`,{type:`button`,class:z([`block w-full px-3 py-2 text-left hover:bg-secondary`,e.version===i.value&&`bg-secondary`]),"aria-current":e.version===i.value,onClick:t=>i.value=e.version},[R(`span`,dde,[R(`span`,fde,`v`+B(e.version),1),A(V(O),{variant:f[e.change]},{default:I(()=>[H(B(e.change),1)]),_:2},1032,[`variant`])]),R(`span`,{class:`mt-0.5 block truncate text-xs text-fg-muted`,title:e.at},[H(B(e.actor||`unknown`)+` · `+B(e.source||`unknown`)+` · `,1),A(V(Tw),{at:e.at},null,8,[`at`])],8,pde)],10,ude)]))),128)),e.revisions.length?F(``,!0):(L(),j(`li`,mde,B(e.error||`No recorded changes`),1))],2),e.revisions.length?(L(),q(V(Wu),{key:0,"model-value":String(i.value),"onUpdate:modelValue":n[0]||=e=>i.value=Number(e)},{default:I(()=>[A(V(Ju),{class:`w-full md:hidden`,"aria-label":`Revision`},{default:I(()=>[A(V(Yu))]),_:1}),A(V(Gu),null,{default:I(()=>[(L(!0),j(U,null,M(e.revisions,e=>(L(),q(V(qu),{key:e.version,value:String(e.version)},{default:I(()=>[H(`v`+B(e.version)+` · `+B(e.change)+` · `+B(e.actor||`unknown`)+` · `+B(V(bw)(e.at)),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1},8,[`model-value`])):F(``,!0),o.value?(L(),j(`div`,hde,[R(`div`,gde,[A(V(zk),{modelValue:a.value,"onUpdate:modelValue":n[1]||=e=>a.value=e},{default:I(()=>[A(V(Vk),null,{default:I(()=>[A(V(Hk),{value:`yaml`},{default:I(()=>[...n[3]||=[H(`YAML`,-1)]]),_:1}),A(V(Hk),{value:`canvas`},{default:I(()=>[...n[4]||=[H(`Canvas`,-1)]]),_:1})]),_:1})]),_:1},8,[`modelValue`]),A(V(X),{type:`button`,size:`sm`,variant:`outline`,class:`ml-auto`,disabled:s.value===null||l.value,title:s.value===null?`Workflow removed`:void 0,onClick:n[2]||=e=>r(`restore`,s.value)},{default:I(()=>[A(V(Cu),{"data-icon":`inline-start`}),n[5]||=H(` Restore this version`,-1)]),_:1},8,[`disabled`,`title`])]),s.value===null?(L(),j(`p`,_de,`Workflow removed in this revision.`)):a.value===`yaml`?(L(),j(`pre`,vde,[R(`code`,null,[(L(!0),j(U,null,M(c.value,(e,t)=>(L(),j(`span`,{key:t,class:z([`block min-h-6 px-3 whitespace-pre-wrap`,{"bg-o
Line truncated
|
||||
`),i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;e--)for(let t=r.length-1;t>=0;t--)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({kind:`same`,text:n[o++]}),s++):i[o+1][s]>=i[o][s+1]?a.push({kind:`del`,text:n[o++]}):a.push({kind:`add`,text:r[s++]});for(;o<n.length;)a.push({kind:`del`,text:n[o++]});for(;s<r.length;)a.push({kind:`add`,text:r[s++]});return a}function j9(e){let t=y0(e).toJS(),n=new Map;for(let r of t2(e).nodes){let{kind:e,path:i,stage:a,occurrence:o}=r.data;if(r.type!==`step`||e!==`step`||!i||a===void 0)continue;let s=t;for(let e of i)s=s?.[e];n.set(`${a}#${o??0}`,{node:r.id,signature:JSON.stringify(s??null)})}return n}function M9(e,t,n){let r=j9(e),i=j9(t),a={};for(let[e,t]of r){let r=i.get(e);r?r.signature!==t.signature&&(a[t.node]=`changed`):a[t.node]=n}return a}var lde={class:`flex flex-col gap-3 md:grid md:h-[calc(100dvh-17rem)] md:min-h-[26rem] md:grid-cols-[18rem_1fr]`},ude=[`aria-current`,`onClick`],dde={class:`flex items-center gap-2 text-sm`},fde={class:`font-mono text-xs text-fg-subtle`},pde=[`title`],mde={key:0,class:`px-3 py-2 text-sm text-fg-muted`},hde={key:1,class:`flex min-h-0 flex-col gap-2`},gde={class:`flex items-center gap-2 max-md:flex-wrap`},_de={key:0,class:`rounded-lg border border-border p-4 text-sm text-fg-muted`},vde={key:1,class:`min-h-0 flex-1 overflow-auto rounded-lg border border-border pt-2 pb-[calc(0.5rem+var(--code-overscroll))] font-mono text-label leading-6`},yde={class:`inline-block w-4 select-none text-fg-subtle`},bde={key:2,class:`grid min-h-0 flex-1 gap-3 max-md:flex-none md:grid-cols-2`},xde={class:`flex min-h-0 flex-col gap-1`},Sde={class:`text-caption font-medium uppercase text-fg-muted`},Cde={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},wde={class:`flex min-h-0 flex-col gap-1`},Tde={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},Ede=P({__name:`WorkflowHistory`,props:Ue({revisions:{},current:{},error:{}},{selected:{default:0},selectedModifiers:{},mode:{default:`yaml`},modeModifiers:{}}),emits:Ue([`restore`],[`update:selected`,`update:mode`]),setup(e,{emit:t}){let n=e,r=t,i=Te(e,`selected`),a=Te(e,`mode`);N(()=>n.revisions,e=>{e.some(e=>e.version===i.value)||(i.value=(e.find(e=>e.yaml!==n.current)??e[0])?.version??0)},{immediate:!0});let o=Y(()=>n.revisions.find(e=>e.version===i.value)),s=Y(()=>o.value?.yaml??null),c=Y(()=>s.value===null?[]:cde(s.value,n.current)),l=Y(()=>s.value!==null&&s.value===n.current),u=Y(()=>s.value===null?{}:M9(s.value,n.current,`removed`)),d=Y(()=>s.value===null?{}:M9(n.current,s.value,`added`)),f={added:`default`,edited:`secondary`,removed:`destructive`};return(t,n)=>(L(),j(`div`,lde,[R(`ol`,{class:z(V(W)(`min-h-0 divide-y divide-border overflow-y-auto rounded-lg border border-border`,e.revisions.length&&`max-md:hidden`)),"aria-label":`Revisions`},[(L(!0),j(U,null,M(e.revisions,e=>(L(),j(`li`,{key:e.version},[R(`button`,{type:`button`,class:z([`block w-full px-3 py-2 text-left hover:bg-secondary`,e.version===i.value&&`bg-secondary`]),"aria-current":e.version===i.value,onClick:t=>i.value=e.version},[R(`span`,dde,[R(`span`,fde,`v`+B(e.version),1),A(V(O),{variant:f[e.change]},{default:I(()=>[H(B(e.change),1)]),_:2},1032,[`variant`])]),R(`span`,{class:`mt-0.5 block truncate text-xs text-fg-muted`,title:e.at},[H(B(e.actor||`unknown`)+` · `+B(e.source||`unknown`)+` · `,1),A(V(Tw),{at:e.at},null,8,[`at`])],8,pde)],10,ude)]))),128)),e.revisions.length?F(``,!0):(L(),j(`li`,mde,B(e.error||`No recorded changes`),1))],2),e.revisions.length?(L(),q(V(Wu),{key:0,"model-value":String(i.value),"onUpdate:modelValue":n[0]||=e=>i.value=Number(e)},{default:I(()=>[A(V(Ju),{class:`w-full md:hidden`,"aria-label":`Revision`},{default:I(()=>[A(V(Yu))]),_:1}),A(V(Gu),null,{default:I(()=>[(L(!0),j(U,null,M(e.revisions,e=>(L(),q(V(qu),{key:e.version,value:String(e.version)},{default:I(()=>[H(`v`+B(e.version)+` · `+B(e.change)+` · `+B(e.actor||`unknown`)+` · `+B(V(bw)(e.at)),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1},8,[`model-value`])):F(``,!0),o.value?(L(),j(`div`,hde,[R(`div`,gde,[A(V(zk),{modelValue:a.value,"onUpdate:modelValue":n[1]||=e=>a.value=e},{default:I(()=>[A(V(Vk),null,{default:I(()=>[A(V(Hk),{value:`yaml`},{default:I(()=>[...n[3]||=[H(`YAML`,-1)]]),_:1}),A(V(Hk),{value:`canvas`},{default:I(()=>[...n[4]||=[H(`Canvas`,-1)]]),_:1})]),_:1})]),_:1},8,[`modelValue`]),A(V(X),{type:`button`,size:`sm`,variant:`outline`,class:`ml-auto`,disabled:s.value===null||l.value,title:s.value===null?`Workflow removed`:void 0,onClick:n[2]||=e=>r(`restore`,s.value)},{default:I(()=>[A(V(Cu),{"data-icon":`inline-start`}),n[5]||=H(` Restore this version`,-1)]),_:1},8,[`disabled`,`title`])]),s.value===null?(L(),j(`p`,_de,`Workflow removed in this revision.`)):a.value===`yaml`?(L(),j(`pre`,vde,[R(`code`,null,[(L(!0),j(U,null,M(c.value,(e,t)=>(L(),j(`span`,{key:t,class:z([`block min-h-6 px-3 whitespace-pre-wrap`,{"bg-o
Line truncated
|
||||
@@ -5,20 +5,33 @@ import { Copy, Plus, X } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
|
||||
import { api } from "@/lib/api";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
|
||||
interface PersonalToken {
|
||||
id: string;
|
||||
name: string;
|
||||
created_at: string;
|
||||
expires_at: string | null;
|
||||
last_used_at: string | null;
|
||||
}
|
||||
|
||||
const lifetimes = [
|
||||
{ days: 7, label: "7 days" },
|
||||
{ days: 30, label: "30 days" },
|
||||
{ days: 90, label: "90 days" },
|
||||
{ days: 0, label: "No expiry" },
|
||||
];
|
||||
|
||||
const available = ref(false);
|
||||
const tokens = ref<PersonalToken[]>([]);
|
||||
const created = ref("");
|
||||
const error = ref("");
|
||||
const busy = ref(false);
|
||||
const name = ref("");
|
||||
const days = ref(30);
|
||||
|
||||
async function run(action: () => Promise<void>): Promise<void> {
|
||||
busy.value = true;
|
||||
@@ -41,7 +54,8 @@ const load = () =>
|
||||
|
||||
const create = () =>
|
||||
run(async () => {
|
||||
created.value = (await api.createToken())?.token ?? "";
|
||||
created.value = (await api.createToken(name.value.trim(), Number(days.value)))?.token ?? "";
|
||||
name.value = "";
|
||||
await load();
|
||||
});
|
||||
|
||||
@@ -59,7 +73,13 @@ onMounted(load);
|
||||
<template>
|
||||
<Section title="API tokens">
|
||||
<template v-if="available" #action>
|
||||
<Button size="sm" :disabled="busy" @click="create"><Plus data-icon="inline-start" />New token</Button>
|
||||
<form class="flex items-center gap-2" @submit.prevent="create">
|
||||
<Input v-model="name" class="w-40" maxlength="40" required placeholder="Name" aria-label="Token name" />
|
||||
<NativeSelect v-model="days" size="sm" aria-label="Lifetime">
|
||||
<NativeSelectOption v-for="option in lifetimes" :key="option.days" :value="option.days">{{ option.label }}</NativeSelectOption>
|
||||
</NativeSelect>
|
||||
<Button type="submit" size="sm" :disabled="busy || !name.trim()"><Plus data-icon="inline-start" />New token</Button>
|
||||
</form>
|
||||
</template>
|
||||
<p v-if="!available && !busy && !error" class="text-fg-subtle">Personal tokens need a signed-in person.</p>
|
||||
<p v-if="error" role="alert" class="mb-3 text-danger">{{ error }}</p>
|
||||
@@ -74,8 +94,10 @@ onMounted(load);
|
||||
<p v-if="available && !tokens.length && !busy && !error" class="text-fg-subtle">No tokens yet.</p>
|
||||
<ItemGroup v-if="tokens.length" aria-label="API tokens">
|
||||
<Item v-for="token in tokens" :key="token.id" as="li" variant="outline" size="xs">
|
||||
<code class="flex-1 truncate text-xs">{{ token.id.slice(0, 12) }}</code>
|
||||
<span class="text-xs text-fg-subtle"><Timestamp :at="token.created_at" /></span>
|
||||
<span class="flex-1 truncate text-sm">{{ token.name || token.id.slice(0, 12) }}</span>
|
||||
<span class="text-xs text-fg-subtle">Created <Timestamp :at="token.created_at" /></span>
|
||||
<span class="text-xs text-fg-subtle">Expires <Timestamp v-if="token.expires_at" :at="token.expires_at" /><template v-else>Never</template></span>
|
||||
<span class="text-xs text-fg-subtle">Last used <Timestamp v-if="token.last_used_at" :at="token.last_used_at" /><template v-else>Never</template></span>
|
||||
<Button variant="ghost" size="sm" class="text-danger" :disabled="busy" @click="revoke(token.id)">Revoke</Button>
|
||||
</Item>
|
||||
</ItemGroup>
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ export const api = {
|
||||
authentication: <T = unknown>() => request<T>("/api/authentication"),
|
||||
saveAuthentication: (body: unknown) => request<void>("/api/authentication",{method:"PUT",body,parse:false}),
|
||||
tokens: <T = unknown>() => request<T>("/api/tokens"),
|
||||
createToken: () => request<{token:string}>("/api/tokens",{method:"POST",body:{}}),
|
||||
createToken: (name:string,days:number) => request<{token:string}>("/api/tokens",{method:"POST",body:{name,days}}),
|
||||
revokeToken: (id:string) => request<void>(`/api/tokens/${encodeURIComponent(id)}`,{method:"DELETE",body:{},parse:false}),
|
||||
passkeys: () => request<{passkeys:{id:string;name:string}[]}>("/api/account/passkeys"),
|
||||
deletePasskey: (id:string) => request<void>(`/api/account/passkeys/${encodeURIComponent(id)}`,{method:"DELETE",body:{},parse:false}),
|
||||
|
||||
Reference in new issue
Block a user