2
0

♻️ Use at function instead of dangerous direct lookup array index

This commit is contained in:
Baptiste Arnaud
2024-03-04 14:14:06 +01:00
parent a043c3e4b9
commit 4ca613e83a
6 changed files with 37 additions and 31 deletions

View File

@ -19,5 +19,5 @@ export const getFirstEdgeId = ({
return event.outgoingEdgeId
}
if (typebot.version === '6') return typebot.events[0].outgoingEdgeId
return typebot.groups[0].blocks[0].outgoingEdgeId
return typebot.groups.at(0)?.blocks.at(0)?.outgoingEdgeId
}

View File

@ -7,10 +7,10 @@ export const getBlockById = (
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
for (
let blockIndex = 0;
blockIndex < groups[groupIndex].blocks.length;
blockIndex < (groups.at(groupIndex)?.blocks?.length ?? 0);
blockIndex++
) {
if (groups[groupIndex].blocks[blockIndex].id === blockId) {
if (groups.at(groupIndex)?.blocks?.at(blockIndex)?.id === blockId) {
return {
block: groups[groupIndex].blocks[blockIndex],
group: groups[groupIndex],