-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathrepository.ts
More file actions
109 lines (96 loc) · 3.25 KB
/
repository.ts
File metadata and controls
109 lines (96 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { RuntimeEnvironmentType } from "@trigger.dev/database";
import { z } from "zod";
export const EnvironmentVariableKey = z
.string()
.nonempty("Key is required")
.regex(/^\w+$/, "Keys can only use alphanumeric characters and underscores");
export const CreateEnvironmentVariables = z.object({
environmentIds: z.array(z.string()),
variables: z.array(z.object({ key: EnvironmentVariableKey, value: z.string() })),
});
export type CreateEnvironmentVariables = z.infer<typeof CreateEnvironmentVariables>;
export type CreateResult =
| {
success: true;
}
| {
success: false;
error: string;
variableErrors?: { key: string; error: string }[];
};
export const EditEnvironmentVariable = z.object({
id: z.string(),
values: z.array(
z.object({
environmentId: z.string(),
value: z.string(),
})
),
keepEmptyValues: z.boolean().optional(),
});
export type EditEnvironmentVariable = z.infer<typeof EditEnvironmentVariable>;
export const DeleteEnvironmentVariable = z.object({
id: z.string(),
environmentId: z.string().optional(),
});
export type DeleteEnvironmentVariable = z.infer<typeof DeleteEnvironmentVariable>;
export const DeleteEnvironmentVariableValue = z.object({
id: z.string(),
environmentId: z.string(),
});
export type DeleteEnvironmentVariableValue = z.infer<typeof DeleteEnvironmentVariableValue>;
export const EditEnvironmentVariableValue = z.object({
id: z.string(),
environmentId: z.string(),
value: z.string(),
isSecret: z.preprocess((val) => val === "true" || val === true, z.boolean()).optional(),
});
export type EditEnvironmentVariableValue = z.infer<typeof EditEnvironmentVariableValue>;
export type Result =
| {
success: true;
}
| {
success: false;
error: string;
};
export type ProjectEnvironmentVariable = {
key: string;
values: {
value: string;
environment: {
id: string;
type: RuntimeEnvironmentType;
};
}[];
};
export type EnvironmentVariable = {
key: string;
value: string;
};
export type EnvironmentVariableWithSecret = EnvironmentVariable & {
isSecret: boolean;
};
export interface Repository {
create(projectId: string, options: CreateEnvironmentVariables): Promise<CreateResult>;
edit(projectId: string, options: EditEnvironmentVariable): Promise<Result>;
editValue(projectId: string, options: EditEnvironmentVariableValue): Promise<Result>;
getProject(projectId: string): Promise<ProjectEnvironmentVariable[]>;
/**
* Get the environment variables for a given environment, it does NOT return values for secret variables
*/
getEnvironmentWithRedactedSecrets(
projectId: string,
environmentId: string
): Promise<EnvironmentVariableWithSecret[]>;
/**
* Get the environment variables for a given environment
*/
getEnvironment(projectId: string, environmentId: string): Promise<EnvironmentVariable[]>;
/**
* Return all env vars, including secret variables with values. Should only be used for executing tasks.
*/
getEnvironmentVariables(projectId: string, environmentId: string): Promise<EnvironmentVariable[]>;
delete(projectId: string, options: DeleteEnvironmentVariable): Promise<Result>;
deleteValue(projectId: string, options: DeleteEnvironmentVariableValue): Promise<Result>;
}