@dimo-network/data-sdk 1.2.2 → 1.2.4
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/.github/workflows/npm-publish.yml +12 -4
- package/README.md +63 -45
- package/dist/api/Method.d.ts +1 -1
- package/dist/api/functions/{getToken.d.ts → getDeveloperJwt.d.ts} +1 -1
- package/dist/api/functions/{getToken.js → getDeveloperJwt.js} +1 -1
- package/dist/api/functions/getVehicleJwt.d.ts +7 -0
- package/dist/api/functions/getVehicleJwt.js +23 -0
- package/dist/api/functions/index.d.ts +3 -2
- package/dist/api/functions/index.js +3 -2
- package/dist/api/resources/Auth/index.js +2 -2
- package/dist/api/resources/TokenExchange/index.js +4 -0
- package/dist/constants.d.ts +4 -1
- package/dist/constants.js +3 -0
- package/dist/dimo.js +1 -1
- package/dist/environments/index.d.ts +0 -6
- package/dist/environments/index.js +0 -6
- package/dist/graphql/Query.d.ts +1 -1
- package/dist/graphql/Query.js +7 -8
- package/dist/graphql/functions/getVehiclePrivileges.d.ts +6 -0
- package/dist/graphql/functions/getVehiclePrivileges.js +46 -0
- package/dist/graphql/functions/index.d.ts +2 -1
- package/dist/graphql/functions/index.js +2 -1
- package/dist/graphql/resources/Identity/index.d.ts +0 -1
- package/dist/graphql/resources/Identity/index.js +53 -78
- package/dist/graphql/util/paginate.d.ts +9 -0
- package/dist/graphql/util/paginate.js +37 -0
- package/dist/index.cjs +144416 -0
- package/dist/util/decodeJwt.d.ts +1 -0
- package/dist/util/decodeJwt.js +11 -0
- package/dist/util/decodePermissions.d.ts +1 -0
- package/dist/util/decodePermissions.js +12 -0
- package/dist/util/index.d.ts +8 -0
- package/dist/util/index.js +7 -0
- package/package.json +20 -3
- package/rollup.config.js +28 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { DimoConstants } from '../../constants';
|
|
2
|
+
const pageSize = DimoConstants.Query.PAGE_SIZE;
|
|
3
|
+
export const paginate = async (fetchPage) => {
|
|
4
|
+
let after = null;
|
|
5
|
+
let result = [];
|
|
6
|
+
let totalCount = null;
|
|
7
|
+
let page = 0;
|
|
8
|
+
while (true) {
|
|
9
|
+
const response = await fetchPage(after ?? undefined);
|
|
10
|
+
const { nodes, pageInfo, totalCount: responseTotalCount } = response;
|
|
11
|
+
if (!nodes || !nodes.nodes) {
|
|
12
|
+
console.error('Invalid response: nodes is undefined or null', response);
|
|
13
|
+
throw new Error('Unexpected API response format');
|
|
14
|
+
}
|
|
15
|
+
// Capture totalCount from the first request
|
|
16
|
+
if (totalCount === null) {
|
|
17
|
+
totalCount = responseTotalCount ?? null; // Ensure fallback if totalCount is missing
|
|
18
|
+
if (totalCount === null) {
|
|
19
|
+
console.warn('Warning: totalCount is null. Defaulting to single page execution.');
|
|
20
|
+
totalCount = pageSize; // Assume at least one page if totalCount is unknown
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
result.push(...nodes.nodes);
|
|
24
|
+
page++;
|
|
25
|
+
const totalPages = Math.ceil(totalCount / pageSize);
|
|
26
|
+
if (page >= totalPages || nodes.nodes.length < pageSize) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
// Update the cursor
|
|
30
|
+
after = pageInfo.endCursor ?? null;
|
|
31
|
+
if (after === null && page < totalPages) {
|
|
32
|
+
console.warn(`Expected more pages (${page}/${totalPages}), but endCursor is null. Stopping pagination.`);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
};
|