0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix: fix fetch official connector CLI error (#6862)

This commit is contained in:
Darcy Ye 2024-12-09 18:58:57 +08:00 committed by GitHub
parent 51c9c52a61
commit 2178589507
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 13 deletions

View file

@ -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.

View file

@ -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;