Add for-await for better Vercel integration reliability

This commit is contained in:
Tuan Dang
2023-02-23 20:21:17 +07:00
parent fcb1f5a51b
commit 783174adc6
+7 -11
View File
@@ -577,7 +577,7 @@ const syncSecretsVercel = async ({
.map(async (secret: VercelSecret) => {
if (secret.type === 'encrypted') {
// case: secret is encrypted -> need to decrypt
return (await axios.get(
const decryptedSecret = (await axios.get(
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
{
params,
@@ -587,6 +587,8 @@ const syncSecretsVercel = async ({
}
}
)).data;
return decryptedSecret;
}
return secret;
@@ -654,12 +656,9 @@ const syncSecretsVercel = async ({
);
}
// Sync/push updated secrets
if (updateSecrets.length > 0) {
updateSecrets.forEach(async (secret: VercelSecret) => {
const { id, ...updatedSecret } = secret;
for await (const secret of updateSecrets) {
if (secret.type !== 'sensitive') {
const { id, ...updatedSecret } = secret;
await axios.patch(
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
updatedSecret,
@@ -672,12 +671,9 @@ const syncSecretsVercel = async ({
}
);
}
});
}
// Delete secrets
if (deleteSecrets.length > 0) {
deleteSecrets.forEach(async (secret: VercelSecret) => {
for await (const secret of deleteSecrets) {
await axios.delete(
`${INTEGRATION_VERCEL_API_URL}/v9/projects/${integration.app}/env/${secret.id}`,
{
@@ -688,8 +684,8 @@ const syncSecretsVercel = async ({
},
}
);
});
}
} catch (err) {
Sentry.setUser(null);
Sentry.captureException(err);