@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.
Files changed (35) hide show
  1. package/.github/workflows/npm-publish.yml +12 -4
  2. package/README.md +63 -45
  3. package/dist/api/Method.d.ts +1 -1
  4. package/dist/api/functions/{getToken.d.ts → getDeveloperJwt.d.ts} +1 -1
  5. package/dist/api/functions/{getToken.js → getDeveloperJwt.js} +1 -1
  6. package/dist/api/functions/getVehicleJwt.d.ts +7 -0
  7. package/dist/api/functions/getVehicleJwt.js +23 -0
  8. package/dist/api/functions/index.d.ts +3 -2
  9. package/dist/api/functions/index.js +3 -2
  10. package/dist/api/resources/Auth/index.js +2 -2
  11. package/dist/api/resources/TokenExchange/index.js +4 -0
  12. package/dist/constants.d.ts +4 -1
  13. package/dist/constants.js +3 -0
  14. package/dist/dimo.js +1 -1
  15. package/dist/environments/index.d.ts +0 -6
  16. package/dist/environments/index.js +0 -6
  17. package/dist/graphql/Query.d.ts +1 -1
  18. package/dist/graphql/Query.js +7 -8
  19. package/dist/graphql/functions/getVehiclePrivileges.d.ts +6 -0
  20. package/dist/graphql/functions/getVehiclePrivileges.js +46 -0
  21. package/dist/graphql/functions/index.d.ts +2 -1
  22. package/dist/graphql/functions/index.js +2 -1
  23. package/dist/graphql/resources/Identity/index.d.ts +0 -1
  24. package/dist/graphql/resources/Identity/index.js +53 -78
  25. package/dist/graphql/util/paginate.d.ts +9 -0
  26. package/dist/graphql/util/paginate.js +37 -0
  27. package/dist/index.cjs +144416 -0
  28. package/dist/util/decodeJwt.d.ts +1 -0
  29. package/dist/util/decodeJwt.js +11 -0
  30. package/dist/util/decodePermissions.d.ts +1 -0
  31. package/dist/util/decodePermissions.js +12 -0
  32. package/dist/util/index.d.ts +8 -0
  33. package/dist/util/index.js +7 -0
  34. package/package.json +20 -3
  35. 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
+ };