@startsimpli/api 0.5.19 → 0.5.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,155 @@
1
+ /** Vault API client — environments, secrets, access keys, audit (startsim-d30.3.1).
2
+
3
+ Mirrors the other @startsimpli/api wrappers. The client auto-transforms
4
+ snake_case <-> camelCase, so types here are camelCase. Secret values are
5
+ write-only on create/update and only returned by `revealSecret`.
6
+ */
7
+
8
+ import type { PaginatedResponse } from '../types';
9
+ import type { ApiClient } from './api-client';
10
+
11
+ const E = {
12
+ environments: 'api/v1/vault/environments',
13
+ environment: (slug: string) => `api/v1/vault/environments/${slug}`,
14
+ secrets: (slug: string) => `api/v1/vault/environments/${slug}/secrets`,
15
+ secret: (slug: string, id: string) => `api/v1/vault/environments/${slug}/secrets/${id}`,
16
+ reveal: (slug: string, id: string) => `api/v1/vault/environments/${slug}/secrets/${id}/reveal`,
17
+ accessKeys: (slug: string) => `api/v1/vault/environments/${slug}/access-keys`,
18
+ accessKey: (slug: string, id: string) => `api/v1/vault/environments/${slug}/access-keys/${id}`,
19
+ audit: (slug: string) => `api/v1/vault/environments/${slug}/audit`,
20
+ };
21
+
22
+ export interface VaultEnvironment {
23
+ id: string;
24
+ slug: string;
25
+ name: string;
26
+ description: string;
27
+ secretCount: number;
28
+ createdAt: string;
29
+ updatedAt: string;
30
+ }
31
+
32
+ export interface VaultEnvironmentInput {
33
+ slug: string;
34
+ name: string;
35
+ description?: string;
36
+ }
37
+
38
+ export interface VaultSecret {
39
+ id: string;
40
+ key: string;
41
+ hasValue: boolean;
42
+ valueType: string;
43
+ metadata: Record<string, unknown>;
44
+ lastRotatedAt: string | null;
45
+ createdAt: string;
46
+ updatedAt: string;
47
+ }
48
+
49
+ export interface VaultSecretInput {
50
+ key: string;
51
+ value?: string;
52
+ valueType?: string;
53
+ metadata?: Record<string, unknown>;
54
+ }
55
+
56
+ export interface VaultSecretReveal {
57
+ key: string;
58
+ value: string;
59
+ }
60
+
61
+ export interface VaultAccessKey {
62
+ id: string;
63
+ name: string;
64
+ prefix: string;
65
+ scopes: string[];
66
+ isActive: boolean;
67
+ lastUsedAt: string | null;
68
+ expiresAt: string | null;
69
+ createdAt: string;
70
+ }
71
+
72
+ /** Returned only by createAccessKey — carries the raw key, shown exactly once. */
73
+ export interface VaultAccessKeyCreated extends VaultAccessKey {
74
+ key: string;
75
+ }
76
+
77
+ export interface VaultAccessKeyInput {
78
+ name: string;
79
+ scopes?: string[];
80
+ expiresAt?: string | null;
81
+ }
82
+
83
+ export interface VaultAuditEntry {
84
+ id: string;
85
+ action: string;
86
+ secretKey: string | null;
87
+ actorEmail: string | null;
88
+ accessKeyName: string | null;
89
+ ipAddress: string | null;
90
+ metadata: Record<string, unknown>;
91
+ createdAt: string;
92
+ }
93
+
94
+ export interface VaultListParams {
95
+ page?: number;
96
+ pageSize?: number;
97
+ search?: string;
98
+ ordering?: string;
99
+ // Index signature so this satisfies the client's query-params type.
100
+ [key: string]: unknown;
101
+ }
102
+
103
+ export class VaultApi {
104
+ constructor(private client: ApiClient) {}
105
+
106
+ // --- Environments ---
107
+ listEnvironments(params?: VaultListParams): Promise<PaginatedResponse<VaultEnvironment>> {
108
+ return this.client.fetch.get<PaginatedResponse<VaultEnvironment>>(E.environments, { params });
109
+ }
110
+ getEnvironment(slug: string): Promise<VaultEnvironment> {
111
+ return this.client.fetch.get<VaultEnvironment>(E.environment(slug));
112
+ }
113
+ createEnvironment(data: VaultEnvironmentInput): Promise<VaultEnvironment> {
114
+ return this.client.fetch.post<VaultEnvironment>(E.environments, data);
115
+ }
116
+ updateEnvironment(slug: string, data: Partial<VaultEnvironmentInput>): Promise<VaultEnvironment> {
117
+ return this.client.fetch.patch<VaultEnvironment>(E.environment(slug), data);
118
+ }
119
+ deleteEnvironment(slug: string): Promise<void> {
120
+ return this.client.fetch.delete<void>(E.environment(slug));
121
+ }
122
+
123
+ // --- Secrets (value write-only; reveal is separate + audited) ---
124
+ listSecrets(slug: string, params?: VaultListParams): Promise<PaginatedResponse<VaultSecret>> {
125
+ return this.client.fetch.get<PaginatedResponse<VaultSecret>>(E.secrets(slug), { params });
126
+ }
127
+ createSecret(slug: string, data: VaultSecretInput): Promise<VaultSecret> {
128
+ return this.client.fetch.post<VaultSecret>(E.secrets(slug), data);
129
+ }
130
+ updateSecret(slug: string, id: string, data: Partial<VaultSecretInput>): Promise<VaultSecret> {
131
+ return this.client.fetch.patch<VaultSecret>(E.secret(slug, id), data);
132
+ }
133
+ deleteSecret(slug: string, id: string): Promise<void> {
134
+ return this.client.fetch.delete<void>(E.secret(slug, id));
135
+ }
136
+ revealSecret(slug: string, id: string): Promise<VaultSecretReveal> {
137
+ return this.client.fetch.get<VaultSecretReveal>(E.reveal(slug, id));
138
+ }
139
+
140
+ // --- Access keys ---
141
+ listAccessKeys(slug: string, params?: VaultListParams): Promise<PaginatedResponse<VaultAccessKey>> {
142
+ return this.client.fetch.get<PaginatedResponse<VaultAccessKey>>(E.accessKeys(slug), { params });
143
+ }
144
+ createAccessKey(slug: string, data: VaultAccessKeyInput): Promise<VaultAccessKeyCreated> {
145
+ return this.client.fetch.post<VaultAccessKeyCreated>(E.accessKeys(slug), data);
146
+ }
147
+ deleteAccessKey(slug: string, id: string): Promise<void> {
148
+ return this.client.fetch.delete<void>(E.accessKey(slug, id));
149
+ }
150
+
151
+ // --- Audit ---
152
+ listAudit(slug: string, params?: VaultListParams): Promise<PaginatedResponse<VaultAuditEntry>> {
153
+ return this.client.fetch.get<PaginatedResponse<VaultAuditEntry>>(E.audit(slug), { params });
154
+ }
155
+ }
package/src/types/api.ts CHANGED
@@ -15,6 +15,12 @@ export interface ApiError {
15
15
  errors?: Record<string, string[]>;
16
16
  status?: number;
17
17
  statusText?: string;
18
+ /** Machine-readable code from the standardized response (limit_reached,
19
+ * no_company, …). Set when the backend uses apps.core.exceptions. */
20
+ code?: string;
21
+ /** Extra structured context attached to the error (e.g. limit_reached
22
+ * carries { feature_key, limit, current }). */
23
+ details?: Record<string, unknown>;
18
24
  }
19
25
 
20
26
  export interface PaginationParams {