How to get Alfresco (ACS) group users using alfresco-js-api

Using groupsApi

async function getGroupUserList(groupId) => {
  const groupResult = await alfrescoApi.core.groupsApi.getGroupMembers(groupId);
  console.log(groupId + ', # users: ' + groupResult.list.entries.length);
  return groupResult.list.entries;
}

Using Search PATH

async function getGroupUserList(groupId) {  
  const query = `PATH:'/sys:system/sys:authorities/cm:GROUP_${groupId}/*'`;
  const groupResult = await search(query);
  console.log(groupId + ', # users: ' + groupResult.list.entries.length);
  return groupResult.list.entries;
}

Using Search ANCESTOR

async function getGroupUserList(groupId) {
    const authoritiesParentNode = await this.searchAndExpectOneNode(`PATH:'/sys:system/sys:authorities/cm:GROUP_${groupId}'`);
    const query = `ANCESTOR:'workspace://SpacesStore/${authoritiesParentNode.entry.id}'`;
    const searchResult = await this.search(query);
    const groupResult = searchResult.list.entries.filter(oneNode => oneNode.entry.nodeType === 'cm:person');
    console.log('# users: ' + groupResult.length);
    return groupResult;
}

As follows, there are some methods required to support the previous methods

const AlfrescoApi = require('alfresco-js-api-node');
const alfrescoApi = new AlfrescoApi({hostEcm: 'your-host'});

// make sure to login on alfresco to use the API

async function searchAndExpectOneNode(query, displayError) => {
    const searchResult = this.search(query);
  
    if (searchResult.list.entries.length > 1) {
      if (displayError) {
        console.error('found multiple elements with query', query);
      
      } else if (searchResult.list.entries.length === 1) {
        return searchResult.list.entries[0];
        
      } else {
        return null;
      }
    }
}

function search(query, size = 500, skipCount = 0) => {
  // adding cm:name:* forces alfresco to use Solr, to make sure we retrieve totalItems
  return alfrescoApi.search.searchApi.search(getQueryBody(query + ' AND cm:name:*', size, skipCount));
}

function getQueryBody(query, size = 500, skipCount = 0) {
  return {
    query: {
      query: query
    },
    include: ['properties'],
    paging: {
      maxItems: size,
      skipCount: skipCount
    }
  };
}