11import ora from 'ora' ;
22import { selectFromList , throwError } from './utils' ;
33import { APP_DEF_ENV_KEY } from './constants' ;
4- import { ClientAPI } from 'contentful-management' ;
4+ import { AppDefinition , ClientAPI } from 'contentful-management' ;
55
66export interface Definition {
7- name : string ,
8- value : string ,
7+ name : string ;
8+ value : string ;
99}
1010
1111async function fetchDefinitions ( client : ClientAPI , orgId : string ) : Promise < Definition [ ] > {
1212 try {
1313 const organization = await client . getOrganization ( orgId ) ;
14- const definitions = await organization . getAppDefinitions ( ) ;
15- return definitions . items . map ( ( def ) => ( {
14+
15+ const batchedAppDefinitions : AppDefinition [ ] = [ ] ;
16+ let skip = 0 ;
17+ let totalNumOfAppDefinitions = 0 ;
18+
19+ while ( skip === 0 || batchedAppDefinitions . length < totalNumOfAppDefinitions ) {
20+ const appDefinitionsResponse = await organization . getAppDefinitions ( { skip, limit : 100 } ) ;
21+
22+ totalNumOfAppDefinitions = appDefinitionsResponse . total ;
23+ batchedAppDefinitions . push ( ...appDefinitionsResponse . items ) ;
24+
25+ skip += 100 ;
26+ }
27+
28+ return batchedAppDefinitions . map ( ( def ) => ( {
1629 name : def . name ,
1730 value : def . sys . id ,
1831 } ) ) ;
@@ -32,7 +45,11 @@ export async function selectDefinition(client: ClientAPI, orgId: string): Promis
3245 return await selectFromList ( definitions as Definition [ ] , 'Select an app:' , APP_DEF_ENV_KEY ) ;
3346}
3447
35- export async function getDefinitionById ( client : ClientAPI , orgId : string , defId : string ) : Promise < Definition > {
48+ export async function getDefinitionById (
49+ client : ClientAPI ,
50+ orgId : string ,
51+ defId : string
52+ ) : Promise < Definition > {
3653 try {
3754 const organization = await client . getOrganization ( orgId ) ;
3855 const definition = await organization . getAppDefinition ( defId ) ;
0 commit comments