|
| 1 | +import { flipCauseOption } from "effect/Cause"; |
1 | 2 | import { PrismaClient, prisma } from "~/db.server"; |
2 | 3 | import { Project } from "~/models/project.server"; |
3 | 4 | import { User } from "~/models/user.server"; |
@@ -48,6 +49,7 @@ export class EnvironmentVariablesPresenter { |
48 | 49 | key: true, |
49 | 50 | }, |
50 | 51 | }, |
| 52 | + isSecret: true, |
51 | 53 | }, |
52 | 54 | }, |
53 | 55 | }, |
@@ -82,34 +84,41 @@ export class EnvironmentVariablesPresenter { |
82 | 84 | }, |
83 | 85 | }); |
84 | 86 |
|
85 | | - const sortedEnvironments = sortEnvironments(filterOrphanedEnvironments(environments)); |
| 87 | + const sortedEnvironments = sortEnvironments(filterOrphanedEnvironments(environments)).filter( |
| 88 | + (e) => e.orgMember?.userId === userId || e.orgMember === null |
| 89 | + ); |
86 | 90 |
|
87 | 91 | const repository = new EnvironmentVariablesRepository(this.#prismaClient); |
88 | 92 | const variables = await repository.getProject(project.id); |
89 | 93 |
|
90 | 94 | return { |
91 | | - environmentVariables: environmentVariables.map((environmentVariable) => { |
| 95 | + environmentVariables: environmentVariables.flatMap((environmentVariable) => { |
92 | 96 | const variable = variables.find((v) => v.key === environmentVariable.key); |
93 | 97 |
|
94 | | - return { |
95 | | - id: environmentVariable.id, |
96 | | - key: environmentVariable.key, |
97 | | - values: sortedEnvironments.reduce((previous, env) => { |
98 | | - const val = variable?.values.find((v) => v.environment.id === env.id); |
99 | | - previous[env.id] = { |
100 | | - value: val?.value, |
| 98 | + return sortedEnvironments.flatMap((env) => { |
| 99 | + const val = variable?.values.find((v) => v.environment.id === env.id); |
| 100 | + const isSecret = |
| 101 | + environmentVariable.values.find((v) => v.environmentId === env.id)?.isSecret ?? false; |
| 102 | + |
| 103 | + if (!val) { |
| 104 | + return []; |
| 105 | + } |
| 106 | + |
| 107 | + return [ |
| 108 | + { |
| 109 | + id: environmentVariable.id, |
| 110 | + key: environmentVariable.key, |
101 | 111 | environment: { type: env.type, id: env.id }, |
102 | | - }; |
103 | | - return { ...previous }; |
104 | | - }, {} as Record<string, { value: string | undefined; environment: { type: string; id: string } }>), |
105 | | - }; |
| 112 | + value: val.value, |
| 113 | + isSecret, |
| 114 | + }, |
| 115 | + ]; |
| 116 | + }); |
106 | 117 | }), |
107 | | - environments: sortedEnvironments |
108 | | - .filter((e) => e.orgMember?.userId === userId || e.orgMember === null) |
109 | | - .map((environment) => ({ |
110 | | - id: environment.id, |
111 | | - type: environment.type, |
112 | | - })), |
| 118 | + environments: sortedEnvironments.map((environment) => ({ |
| 119 | + id: environment.id, |
| 120 | + type: environment.type, |
| 121 | + })), |
113 | 122 | hasStaging: environments.some((environment) => environment.type === "STAGING"), |
114 | 123 | }; |
115 | 124 | } |
|
0 commit comments