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:
parent
51c9c52a61
commit
2178589507
2 changed files with 21 additions and 13 deletions
9
.changeset/chilled-radios-cover.md
Normal file
9
.changeset/chilled-radios-cover.md
Normal 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.
|
|
@ -168,26 +168,25 @@ export const fetchOfficialConnectorList = async (includingCloudConnectors = fals
|
||||||
|
|
||||||
const packages: PackageMeta[] = [];
|
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
|
// Disable lint rules for business need
|
||||||
// eslint-disable-next-line @silverhand/fp/no-let, @silverhand/fp/no-mutation
|
// eslint-disable-next-line @silverhand/fp/no-let, @silverhand/fp/no-mutation
|
||||||
for (let page = 0; ; ++page) {
|
for (let page = 0; ; ++page) {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// 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
|
// eslint-disable-next-line @silverhand/fp/no-mutating-methods
|
||||||
packages.push(
|
packages.push(...objects.map(({ package: data }) => data));
|
||||||
...objects
|
|
||||||
.filter(
|
|
||||||
({ package: { name, scope } }) =>
|
|
||||||
scope === 'logto' &&
|
|
||||||
excludeList.every(
|
|
||||||
(excluded) => !name.slice(officialConnectorPrefix.length).startsWith(excluded)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.map(({ package: data }) => data)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (objects.length < 20) {
|
if (objects.length < 20) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue