Skip to content

Commit f079884

Browse files
feat(api): api update
1 parent 6c96ecd commit f079884

File tree

6 files changed

+220
-4
lines changed

6 files changed

+220
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 31
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/val-town%2Fval-town-38a705e02e6cf219497b2eb3911847e01ae42d398e2686a2ef11adb09ee02afd.yml
3-
openapi_spec_hash: e6b09dea13b6bba67e427e73f119e985
4-
config_hash: 4098436795cd43823ece8d1b36372f8d
1+
configured_endpoints: 34
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/val-town%2Fval-town-41996c5844501f484547b121d31d2a39df508a40f70364546436e7510c2e48f2.yml
3+
openapi_spec_hash: 6d0b11329858240a5156ead3aaab814f
4+
config_hash: 59532656a00c38929d49b1c1bff2f2dd

api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,16 @@ Methods:
155155

156156
Types:
157157

158+
- <code><a href="./src/resources/vals/environment-variables.ts">EnvironmentVariableCreateResponse</a></code>
159+
- <code><a href="./src/resources/vals/environment-variables.ts">EnvironmentVariableUpdateResponse</a></code>
158160
- <code><a href="./src/resources/vals/environment-variables.ts">EnvironmentVariableListResponse</a></code>
159161

160162
Methods:
161163

164+
- <code title="post /v2/vals/{val_id}/environment_variables">client.vals.environmentVariables.<a href="./src/resources/vals/environment-variables.ts">create</a>(valId, { ...params }) -> EnvironmentVariableCreateResponse</code>
165+
- <code title="put /v2/vals/{val_id}/environment_variables/{key}">client.vals.environmentVariables.<a href="./src/resources/vals/environment-variables.ts">update</a>(valId, key, { ...params }) -> EnvironmentVariableUpdateResponse</code>
162166
- <code title="get /v2/vals/{val_id}/environment_variables">client.vals.environmentVariables.<a href="./src/resources/vals/environment-variables.ts">list</a>(valId, { ...params }) -> EnvironmentVariableListResponsesPageCursorURL</code>
167+
- <code title="delete /v2/vals/{val_id}/environment_variables/{key}">client.vals.environmentVariables.<a href="./src/resources/vals/environment-variables.ts">delete</a>(valId, key) -> void</code>
163168

164169
# Files
165170

src/resources/vals/environment-variables.ts

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,48 @@ import * as Core from '../../core';
55
import { PageCursorURL, type PageCursorURLParams } from '../../pagination';
66

77
export class EnvironmentVariables extends APIResource {
8+
/**
9+
* Create a new environment variable scoped to this project.
10+
*
11+
* @example
12+
* ```ts
13+
* const environmentVariable =
14+
* await client.vals.environmentVariables.create(
15+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
16+
* { key: 'key', value: 'value' },
17+
* );
18+
* ```
19+
*/
20+
create(
21+
valId: string,
22+
body: EnvironmentVariableCreateParams,
23+
options?: Core.RequestOptions,
24+
): Core.APIPromise<EnvironmentVariableCreateResponse> {
25+
return this._client.post(`/v2/vals/${valId}/environment_variables`, { body, ...options });
26+
}
27+
28+
/**
29+
* Update a environment variable scoped to this project.
30+
*
31+
* @example
32+
* ```ts
33+
* const environmentVariable =
34+
* await client.vals.environmentVariables.update(
35+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
36+
* 'key',
37+
* { value: 'value' },
38+
* );
39+
* ```
40+
*/
41+
update(
42+
valId: string,
43+
key: string,
44+
body: EnvironmentVariableUpdateParams,
45+
options?: Core.RequestOptions,
46+
): Core.APIPromise<EnvironmentVariableUpdateResponse> {
47+
return this._client.put(`/v2/vals/${valId}/environment_variables/${key}`, { body, ...options });
48+
}
49+
850
/**
951
* List environment variables defined in this project. This only includes names,
1052
* not values.
@@ -31,10 +73,66 @@ export class EnvironmentVariables extends APIResource {
3173
{ query, ...options },
3274
);
3375
}
76+
77+
/**
78+
* Delete a environment variable scoped to this project.
79+
*
80+
* @example
81+
* ```ts
82+
* await client.vals.environmentVariables.delete(
83+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
84+
* 'key',
85+
* );
86+
* ```
87+
*/
88+
delete(valId: string, key: string, options?: Core.RequestOptions): Core.APIPromise<void> {
89+
return this._client.delete(`/v2/vals/${valId}/environment_variables/${key}`, {
90+
...options,
91+
headers: { Accept: '*/*', ...options?.headers },
92+
});
93+
}
3494
}
3595

3696
export class EnvironmentVariableListResponsesPageCursorURL extends PageCursorURL<EnvironmentVariableListResponse> {}
3797

98+
/**
99+
* An environment variable
100+
*/
101+
export interface EnvironmentVariableCreateResponse {
102+
createdAt: string;
103+
104+
/**
105+
* Optional description of the environment variable
106+
*/
107+
description: string | null;
108+
109+
/**
110+
* Name or key of the environment variable, accessible via Deno.env or process.env
111+
*/
112+
key: string;
113+
114+
updatedAt: string;
115+
}
116+
117+
/**
118+
* An environment variable
119+
*/
120+
export interface EnvironmentVariableUpdateResponse {
121+
createdAt: string;
122+
123+
/**
124+
* Optional description of the environment variable
125+
*/
126+
description: string | null;
127+
128+
/**
129+
* Name or key of the environment variable, accessible via Deno.env or process.env
130+
*/
131+
key: string;
132+
133+
updatedAt: string;
134+
}
135+
38136
/**
39137
* An environment variable
40138
*/
@@ -54,15 +152,48 @@ export interface EnvironmentVariableListResponse {
54152
updatedAt: string;
55153
}
56154

155+
export interface EnvironmentVariableCreateParams {
156+
/**
157+
* Name or key of the environment variable, accessible via Deno.env or process.env
158+
*/
159+
key: string;
160+
161+
/**
162+
* Value of the environment variable.
163+
*/
164+
value: string;
165+
166+
/**
167+
* Optional description of the environment variable
168+
*/
169+
description?: string;
170+
}
171+
172+
export interface EnvironmentVariableUpdateParams {
173+
/**
174+
* Value of the environment variable.
175+
*/
176+
value: string;
177+
178+
/**
179+
* Optional description of the environment variable
180+
*/
181+
description?: string;
182+
}
183+
57184
export interface EnvironmentVariableListParams extends PageCursorURLParams {}
58185

59186
EnvironmentVariables.EnvironmentVariableListResponsesPageCursorURL =
60187
EnvironmentVariableListResponsesPageCursorURL;
61188

62189
export declare namespace EnvironmentVariables {
63190
export {
191+
type EnvironmentVariableCreateResponse as EnvironmentVariableCreateResponse,
192+
type EnvironmentVariableUpdateResponse as EnvironmentVariableUpdateResponse,
64193
type EnvironmentVariableListResponse as EnvironmentVariableListResponse,
65194
EnvironmentVariableListResponsesPageCursorURL as EnvironmentVariableListResponsesPageCursorURL,
195+
type EnvironmentVariableCreateParams as EnvironmentVariableCreateParams,
196+
type EnvironmentVariableUpdateParams as EnvironmentVariableUpdateParams,
66197
type EnvironmentVariableListParams as EnvironmentVariableListParams,
67198
};
68199
}

src/resources/vals/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export {
1212
export {
1313
EnvironmentVariableListResponsesPageCursorURL,
1414
EnvironmentVariables,
15+
type EnvironmentVariableCreateResponse,
16+
type EnvironmentVariableUpdateResponse,
1517
type EnvironmentVariableListResponse,
18+
type EnvironmentVariableCreateParams,
19+
type EnvironmentVariableUpdateParams,
1620
type EnvironmentVariableListParams,
1721
} from './environment-variables';
1822
export {

src/resources/vals/vals.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ import {
1616
} from './branches';
1717
import * as EnvironmentVariablesAPI from './environment-variables';
1818
import {
19+
EnvironmentVariableCreateParams,
20+
EnvironmentVariableCreateResponse,
1921
EnvironmentVariableListParams,
2022
EnvironmentVariableListResponse,
2123
EnvironmentVariableListResponsesPageCursorURL,
24+
EnvironmentVariableUpdateParams,
25+
EnvironmentVariableUpdateResponse,
2226
EnvironmentVariables,
2327
} from './environment-variables';
2428
import * as FilesAPI from './files';
@@ -174,8 +178,12 @@ export declare namespace Vals {
174178

175179
export {
176180
EnvironmentVariables as EnvironmentVariables,
181+
type EnvironmentVariableCreateResponse as EnvironmentVariableCreateResponse,
182+
type EnvironmentVariableUpdateResponse as EnvironmentVariableUpdateResponse,
177183
type EnvironmentVariableListResponse as EnvironmentVariableListResponse,
178184
EnvironmentVariableListResponsesPageCursorURL as EnvironmentVariableListResponsesPageCursorURL,
185+
type EnvironmentVariableCreateParams as EnvironmentVariableCreateParams,
186+
type EnvironmentVariableUpdateParams as EnvironmentVariableUpdateParams,
179187
type EnvironmentVariableListParams as EnvironmentVariableListParams,
180188
};
181189
}

tests/api-resources/vals/environment-variables.test.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,51 @@ const client = new ValTown({
99
});
1010

1111
describe('resource environmentVariables', () => {
12+
test('create: only required params', async () => {
13+
const responsePromise = client.vals.environmentVariables.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
14+
key: 'key',
15+
value: 'value',
16+
});
17+
const rawResponse = await responsePromise.asResponse();
18+
expect(rawResponse).toBeInstanceOf(Response);
19+
const response = await responsePromise;
20+
expect(response).not.toBeInstanceOf(Response);
21+
const dataAndResponse = await responsePromise.withResponse();
22+
expect(dataAndResponse.data).toBe(response);
23+
expect(dataAndResponse.response).toBe(rawResponse);
24+
});
25+
26+
test('create: required and optional params', async () => {
27+
const response = await client.vals.environmentVariables.create('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
28+
key: 'key',
29+
value: 'value',
30+
description: 'description',
31+
});
32+
});
33+
34+
test('update: only required params', async () => {
35+
const responsePromise = client.vals.environmentVariables.update(
36+
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
37+
'key',
38+
{ value: 'value' },
39+
);
40+
const rawResponse = await responsePromise.asResponse();
41+
expect(rawResponse).toBeInstanceOf(Response);
42+
const response = await responsePromise;
43+
expect(response).not.toBeInstanceOf(Response);
44+
const dataAndResponse = await responsePromise.withResponse();
45+
expect(dataAndResponse.data).toBe(response);
46+
expect(dataAndResponse.response).toBe(rawResponse);
47+
});
48+
49+
test('update: required and optional params', async () => {
50+
const response = await client.vals.environmentVariables.update(
51+
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
52+
'key',
53+
{ value: 'value', description: 'description' },
54+
);
55+
});
56+
1257
test('list: only required params', async () => {
1358
const responsePromise = client.vals.environmentVariables.list('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', {
1459
limit: 1,
@@ -29,4 +74,27 @@ describe('resource environmentVariables', () => {
2974
offset: 0,
3075
});
3176
});
77+
78+
test('delete', async () => {
79+
const responsePromise = client.vals.environmentVariables.delete(
80+
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
81+
'key',
82+
);
83+
const rawResponse = await responsePromise.asResponse();
84+
expect(rawResponse).toBeInstanceOf(Response);
85+
const response = await responsePromise;
86+
expect(response).not.toBeInstanceOf(Response);
87+
const dataAndResponse = await responsePromise.withResponse();
88+
expect(dataAndResponse.data).toBe(response);
89+
expect(dataAndResponse.response).toBe(rawResponse);
90+
});
91+
92+
test('delete: request options instead of params are passed correctly', async () => {
93+
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
94+
await expect(
95+
client.vals.environmentVariables.delete('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', 'key', {
96+
path: '/_stainless_unknown_path',
97+
}),
98+
).rejects.toThrow(ValTown.NotFoundError);
99+
});
32100
});

0 commit comments

Comments
 (0)