Skip to content

Commit bed132d

Browse files
committed
pagination
1 parent a72a45c commit bed132d

2 files changed

Lines changed: 37 additions & 19 deletions

File tree

‎src/appmixer/wiz/auth.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ module.exports = {
1919

2020
accountNameFromProfileInfo: context => {
2121

22-
return `${context.clientId.substring(0, 10)} ...`;
22+
const name = context.clientId;
23+
const threshold = 10;
24+
if (name.length > threshold) {
25+
return name.slice(0, 3) + '....' + name.slice(-3);
26+
}
27+
return name;
2328
},
2429

2530
validate: async context => {

‎src/appmixer/wiz/core/FindCloudResources/FindCloudResources.js‎

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const itemSchemaWithTitles = {
100100
module.exports = {
101101

102102
// docs: https://win.wiz.io/reference/pull-cloud-resources
103-
async receive(context) {
103+
async receive(context) {
104104

105105
const { outputType, filter, limit = 10 } = context.messages.in.content;
106106

@@ -116,28 +116,41 @@ module.exports = {
116116
throw new context.CancelError('Invalid Input: Filter', e);
117117
}
118118
}
119-
const { data } = await lib.makeApiCall({
120-
context,
121-
method: 'POST',
122-
data: {
123-
query,
124-
variables: {
125-
first: limit,
126-
filterBy
119+
120+
let records = [];
121+
let nextPageToken = null;
122+
let totalRecordsCount = 0;
123+
const PAGE_SIZE = 5;
124+
125+
do {
126+
const { data } = await lib.makeApiCall({
127+
context,
128+
method: 'POST',
129+
data: {
130+
query,
131+
variables: {
132+
first: Math.min(PAGE_SIZE, limit - totalRecordsCount),
133+
after: nextPageToken,
134+
filterBy
135+
}
127136
}
137+
});
138+
139+
if (data.errors) {
140+
throw new context.CancelError(data.errors);
128141
}
129-
});
130142

131-
if (data.errors) {
132-
throw new context.CancelError(data.errors);
133-
}
143+
const { pageInfo, nodes: pageRecords } = data.data.cloudResources;
134144

135-
context.log({ stage: 'response', data });
145+
if (pageRecords.length === 0) {
146+
return context.sendJson({ filter: filterBy }, 'notFound');
147+
}
136148

137-
if (data.data.cloudResources.nodes.length === 0) {
138-
return context.sendJson({ filter: filterBy }, 'notFound');
139-
}
149+
records = records.concat(pageRecords);
150+
totalRecordsCount += pageRecords.length;
151+
nextPageToken = pageInfo.endCursor;
152+
} while (nextPageToken && totalRecordsCount < limit);
140153

141-
return lib.sendArrayOutput({ context, records: data.data.cloudResources.nodes, outputType });
154+
return lib.sendArrayOutput({ context, records, outputType });
142155
}
143156
};

0 commit comments

Comments
 (0)