@pitcher/cli-scripts 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/publishApp.js +41 -4
- package/package.json +1 -1
package/dist/src/publishApp.js
CHANGED
|
@@ -6,16 +6,53 @@ import path from "path";
|
|
|
6
6
|
import FormData from "form-data";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
async function fetchAllInstances(baseUrl, apiKey) {
|
|
9
|
+
const pageSize = 100;
|
|
10
|
+
const maxPages = 1000;
|
|
9
11
|
try {
|
|
10
|
-
|
|
12
|
+
console.log("Fetching instances page 1 to determine total count...");
|
|
13
|
+
const firstResponse = await axios.get(`${baseUrl}/api/v1/instances`, {
|
|
11
14
|
headers: {
|
|
12
15
|
accept: "application/json",
|
|
13
16
|
"x-api-key": apiKey,
|
|
14
17
|
},
|
|
18
|
+
params: {
|
|
19
|
+
page_size: pageSize,
|
|
20
|
+
page: 1,
|
|
21
|
+
},
|
|
15
22
|
});
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
const firstData = firstResponse.data;
|
|
24
|
+
const firstInstances = firstData.results || [];
|
|
25
|
+
if (firstInstances.length === 0) {
|
|
26
|
+
console.log("No instances found");
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const totalCount = firstData.count || firstInstances.length;
|
|
30
|
+
const totalPages = Math.min(Math.ceil(totalCount / pageSize), maxPages);
|
|
31
|
+
console.log(`Found ${totalCount} instance(s) across ${totalPages} page(s)`);
|
|
32
|
+
if (totalPages === 1) {
|
|
33
|
+
console.log(`✓ Fetched ${firstInstances.length} total instance(s) from API`);
|
|
34
|
+
return firstInstances;
|
|
35
|
+
}
|
|
36
|
+
const remainingPageNumbers = Array.from({ length: totalPages - 1 }, (_, i) => i + 2);
|
|
37
|
+
console.log(`Fetching remaining ${totalPages - 1} pages in parallel...`);
|
|
38
|
+
const remainingPagePromises = remainingPageNumbers.map((page) => axios.get(`${baseUrl}/api/v1/instances`, {
|
|
39
|
+
headers: {
|
|
40
|
+
accept: "application/json",
|
|
41
|
+
"x-api-key": apiKey,
|
|
42
|
+
},
|
|
43
|
+
params: {
|
|
44
|
+
page_size: pageSize,
|
|
45
|
+
page: page,
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
const remainingResponses = await Promise.all(remainingPagePromises);
|
|
49
|
+
const remainingInstances = remainingResponses.flatMap((response) => response.data.results || []);
|
|
50
|
+
const allInstances = [...firstInstances, ...remainingInstances];
|
|
51
|
+
if (totalPages >= maxPages) {
|
|
52
|
+
console.warn(`⚠ Warning: Reached maximum page limit (${maxPages}). There may be more instances.`);
|
|
53
|
+
}
|
|
54
|
+
console.log(`✓ Fetched ${allInstances.length} total instance(s) from API`);
|
|
55
|
+
return allInstances;
|
|
19
56
|
}
|
|
20
57
|
catch (error) {
|
|
21
58
|
const axiosError = error;
|