Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Replace Promise.all with for-await Vercel getting envars

Tuan Dang3fef6e484978
diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts
index 760cd64978..718da12994 100644
--- a/backend/src/integrations/sync.ts
+++ b/backend/src/integrations/sync.ts
@@ -558,44 +558,80 @@ const syncSecretsVercel = async ({
: {}),
};
- const res = (
- await Promise.all(
- (
- await axios.get(
- `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
+ // const res = (
+ // await Promise.all(
+ // (
+ // await axios.get(
+ // `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
+ // {
+ // params,
+ // headers: {
+ // Authorization: `Bearer ${accessToken}`,
+ // 'Accept-Encoding': 'application/json'
+ // }
+ // }
+ // ))
+ // .data
+ // .envs
+ // .filter((secret: VercelSecret) => secret.target.includes(integration.targetEnvironment))
+ // .map(async (secret: VercelSecret) => {
+ // if (secret.type === 'encrypted') {
+ // // case: secret is encrypted -> need to decrypt
+ // const decryptedSecret = (await axios.get(
+ // `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
+ // {
+ // params,
+ // headers: {
+ // Authorization: `Bearer ${accessToken}`,
+ // 'Accept-Encoding': 'application/json'
+ // }
+ // }
+ // )).data;
+
+ // return decryptedSecret;
+ // }
+
+ // return secret;
+ // }))).reduce((obj: any, secret: any) => ({
+ // ...obj,
+ // [secret.key]: secret
+ // }), {});
+
+ const vercelSecrets: VercelSecret[] = (await axios.get(
+ `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env`,
+ {
+ params,
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ 'Accept-Encoding': 'application/json'
+ }
+ }
+ ))
+ .data
+ .envs
+ .filter((secret: VercelSecret) => secret.target.includes(integration.targetEnvironment));
+
+ const res: { [key: string]: VercelSecret } = {};
+
+ for await (const vercelSecret of vercelSecrets) {
+ if (vercelSecret.type === 'encrypted') {
+ // case: secret is encrypted -> need to decrypt
+ const decryptedSecret = (await axios.get(
+ `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${vercelSecret.id}`,
{
params,
headers: {
Authorization: `Bearer ${accessToken}`,
'Accept-Encoding': 'application/json'
}
- }
- ))
- .data
- .envs
- .filter((secret: VercelSecret) => secret.target.includes(integration.targetEnvironment))
- .map(async (secret: VercelSecret) => {
- if (secret.type === 'encrypted') {
- // case: secret is encrypted -> need to decrypt
- const decryptedSecret = (await axios.get(
- `${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
- {
- params,
- headers: {
- Authorization: `Bearer ${accessToken}`,
- 'Accept-Encoding': 'application/json'
- }
- }
- )).data;
-
- return decryptedSecret;
- }
+ }
+ )).data;
- return secret;
- }))).reduce((obj: any, secret: any) => ({
- ...obj,
- [secret.key]: secret
- }), {});
+ res[vercelSecret.key] = decryptedSecret;
+ } else {
+ res[vercelSecret.key] = vercelSecret;
+ }
+ }
const updateSecrets: VercelSecret[] = [];
const deleteSecrets: VercelSecret[] = [];