Skip to content

Commit

Permalink
Finish env var endpoints and add resolveEnvVars hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ericallam authored and matt-aitken committed May 23, 2024
1 parent 39deaa5 commit fb2aea1
Show file tree
Hide file tree
Showing 23 changed files with 998 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const Variable = z.object({
type Variable = z.infer<typeof Variable>;

const schema = z.object({
overwrite: z.preprocess((i) => {
override: z.preprocess((i) => {
if (i === "true") return true;
if (i === "false") return false;
return;
Expand Down Expand Up @@ -256,18 +256,18 @@ export default function Page() {
type="submit"
variant="primary/small"
disabled={isLoading}
name="overwrite"
name="override"
value="false"
>
{isLoading ? "Saving" : "Save"}
</Button>
<Button
variant="secondary/small"
disabled={isLoading}
name="overwrite"
name="override"
value="true"
>
{isLoading ? "Overwriting" : "Overwrite"}
{isLoading ? "Overriding" : "Override"}
</Button>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function action({ params, request }: ActionFunctionArgs) {
const body = await parseImportBody(request);

const result = await repository.create(environment.project.id, {
overwrite: body.overwrite === true ? true : false,
override: typeof body.override === "boolean" ? body.override : false,
environmentIds: [environment.id],
variables: Object.entries(body.variables).map(([key, value]) => ({
key,
Expand All @@ -59,14 +59,14 @@ async function parseImportBody(request: Request): Promise<ImportEnvironmentVaria
const formData = await request.formData();

const file = formData.get("variables");
const overwrite = formData.get("overwrite") === "true";
const override = formData.get("override") === "true";

if (file instanceof File) {
const buffer = await file.arrayBuffer();

const variables = parse(Buffer.from(buffer));

return { variables, overwrite };
return { variables, override };
} else {
throw json({ error: "Invalid file" }, { status: 400 });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export async function action({ params, request }: ActionFunctionArgs) {
const repository = new EnvironmentVariablesRepository();

const result = await repository.create(environment.project.id, {
overwrite: true,
override: true,
environmentIds: [environment.id],
variables: [
{
Expand Down Expand Up @@ -82,5 +82,5 @@ export async function loader({ params, request }: LoaderFunctionArgs) {

const variables = await repository.getEnvironment(environment.project.id, environment.id, true);

return json(variables);
return json(variables.map((variable) => ({ name: variable.key, value: variable.value })));
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class EnvironmentVariablesRepository implements Repository {
async create(
projectId: string,
options: {
overwrite: boolean;
override: boolean;
environmentIds: string[];
variables: {
key: string;
Expand Down Expand Up @@ -102,7 +102,7 @@ export class EnvironmentVariablesRepository implements Repository {
}

//check if any of them exist in an environment we're setting
if (!options.overwrite) {
if (!options.override) {
const existingVariableKeys: { key: string; environments: RuntimeEnvironmentType[] }[] = [];
for (const variable of values) {
const existingVariable = project.environmentVariables.find((v) => v.key === variable.key);
Expand All @@ -122,7 +122,7 @@ export class EnvironmentVariablesRepository implements Repository {
if (existingVariableKeys.length > 0) {
return {
success: false as const,
error: `Some of the variables are already set for these environments. Set overwrite to true to overwrite them.`,
error: `Some of the variables are already set for these environments. Set override to true to override them.`,
variableErrors: existingVariableKeys.map((val) => ({
key: val.key,
error: `Variable already set in ${val.environments
Expand Down
6 changes: 6 additions & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"v3 (Developer Preview)",
"v2"
],
"api": {
"playground": {
"mode": "hide"
},
"maintainOrder": true
},
"logo": {
"dark": "/logo/dark.png",
"light": "/logo/light.png",
Expand Down
Loading

0 comments on commit fb2aea1

Please sign in to comment.