Skip to content

Commit

Permalink
fix: fix fetch official connector CLI error (#6862)
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe authored Dec 9, 2024
1 parent 51c9c52 commit 2178589
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
9 changes: 9 additions & 0 deletions .changeset/chilled-radios-cover.md
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 12 additions & 13 deletions packages/cli/src/commands/connector/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,26 @@ 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 excludeList = ['mock', 'kit', ...conditionalArray(!includingCloudConnectors && 'logto')];
const { objects: rawObjects } = await fetchList(page * 20, 20);

// 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)
)
const objects = rawObjects.filter(
({ package: { name, scope } }) =>
name.startsWith(officialConnectorPrefix) &&
excludeList.every(
(excluded) => !name.slice(officialConnectorPrefix.length).startsWith(excluded)
)
.map(({ package: data }) => data)
);

// eslint-disable-next-line @silverhand/fp/no-mutating-methods
packages.push(...objects.map(({ package: data }) => data));

if (objects.length < 20) {
break;
}
Expand Down

0 comments on commit 2178589

Please sign in to comment.