diff --git a/.changeset/chilled-radios-cover.md b/.changeset/chilled-radios-cover.md new file mode 100644 index 000000000..a3eb00abb --- /dev/null +++ b/.changeset/chilled-radios-cover.md @@ -0,0 +1,9 @@ +--- +"@logto/cli": patch +--- + +fix fetch official connector list CLI command error + +Due to changes in the npm registry API (`https://registry.npmjs.org/-/v1/search`) that our CLI add official connector depends on, the new API behavior returns irrelevant search results. + +We need to manually filter out these irrelevant results to avoid potential infinite loops, where each loop triggers an API call, eventually hitting a rate limit and resulting in a status code 429. diff --git a/packages/cli/src/commands/connector/utils.ts b/packages/cli/src/commands/connector/utils.ts index 06c36cbc7..1e0d8cb85 100644 --- a/packages/cli/src/commands/connector/utils.ts +++ b/packages/cli/src/commands/connector/utils.ts @@ -168,26 +168,25 @@ export const fetchOfficialConnectorList = async (includingCloudConnectors = fals const packages: PackageMeta[] = []; + const excludeList = ['mock', 'kit', ...conditionalArray(!includingCloudConnectors && 'logto')]; + + // The API called by `fetchList` performs a 'fuzzy' search based on the `text` parameter, which will yield many irrelevant results. We need to filter out these irrelevant results (using `name.startsWith(officialConnectorPrefix)` for filtering). // Disable lint rules for business need // eslint-disable-next-line @silverhand/fp/no-let, @silverhand/fp/no-mutation for (let page = 0; ; ++page) { // eslint-disable-next-line no-await-in-loop - const { objects } = await fetchList(page * 20, 20); + const { objects: rawObjects } = await fetchList(page * 20, 20); - const excludeList = ['mock', 'kit', ...conditionalArray(!includingCloudConnectors && 'logto')]; + const objects = rawObjects.filter( + ({ package: { name, scope } }) => + name.startsWith(officialConnectorPrefix) && + excludeList.every( + (excluded) => !name.slice(officialConnectorPrefix.length).startsWith(excluded) + ) + ); // eslint-disable-next-line @silverhand/fp/no-mutating-methods - packages.push( - ...objects - .filter( - ({ package: { name, scope } }) => - scope === 'logto' && - excludeList.every( - (excluded) => !name.slice(officialConnectorPrefix.length).startsWith(excluded) - ) - ) - .map(({ package: data }) => data) - ); + packages.push(...objects.map(({ package: data }) => data)); if (objects.length < 20) { break;