@trackunit/filters-graphql-hook 0.0.343 → 0.0.345

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/index.cjs.js CHANGED
@@ -6,6 +6,7 @@ var filtersFilterBar = require('@trackunit/filters-filter-bar');
6
6
  var sharedUtils = require('@trackunit/shared-utils');
7
7
  var reactCoreHooks = require('@trackunit/react-core-hooks');
8
8
  var react = require('react');
9
+ var zod = require('zod');
9
10
 
10
11
  var defaultTranslations = {
11
12
 
@@ -318,11 +319,13 @@ const useActiveAssetFilters = (filters) => {
318
319
  return {};
319
320
  }
320
321
  const followExist = filters.followed === "ALL" ? undefined : true;
322
+ const parsedBoundingBox = boundingBoxSchema.optional().safeParse(filters.boundingBox);
323
+ const parsedServiceBooked = booleanArraySchema.safeParse(filters.serviceBooked);
321
324
  return {
322
325
  assetIds: stringArrayOrUndefined(filters.assetIds),
323
326
  searchQuery: typeof filters.search === "string" && filters.search !== "" ? filters.search : undefined,
324
327
  activities: fixTypes(filters.activity, assetActivityState),
325
- boundingBox: isBoundingBox(filters.boundingBox) ? filters.boundingBox : undefined,
328
+ boundingBox: parsedBoundingBox.success ? parsedBoundingBox.data : undefined,
326
329
  brands: stringArrayOrUndefined(filters.brands),
327
330
  types: stringArrayOrUndefined(filters.types),
328
331
  criticalities: fixTypes(filters.criticality, assetCriticalityState),
@@ -335,7 +338,7 @@ const useActiveAssetFilters = (filters) => {
335
338
  metadataCompleteness: ((_b = valueNameArrayOrUndefined(filters.metadataCompleteness)) === null || _b === void 0 ? void 0 : _b[0]) === "ALL"
336
339
  ? undefined
337
340
  : (_c = fixTypes(valueNameArrayOrUndefined(filters.metadataCompleteness), metadataCompleteness)) === null || _c === void 0 ? void 0 : _c[0],
338
- serviceBooked: filters.serviceBooked,
341
+ serviceBooked: parsedServiceBooked.success ? parsedServiceBooked.data : undefined,
339
342
  servicePlanAssignments: fixTypes(filters.servicePlanStatus, servicePlanStatus),
340
343
  servicePlanIds: valueNameArrayOrUndefined(filters.servicePlan),
341
344
  servicePlanStatuses: fixTypes(filters.serviceStatus, servicePlanStatus),
@@ -356,12 +359,14 @@ const useActiveAssetFilters = (filters) => {
356
359
  }, [filters, customFields, systemOfMeasurement]);
357
360
  return filter;
358
361
  };
359
- const isBoundingBox = (value) => {
360
- return value
361
- ? // eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
362
- typeof value === "object" && Object.keys(value).includes("nw") && Object.keys(value).includes("se")
363
- : false;
364
- };
362
+ const latitudeSchema = zod.z.number().min(-90).max(90);
363
+ const longitudeSchema = zod.z.number().min(-180).max(180);
364
+ const coordinateSchema = zod.z.object({ latitude: latitudeSchema, longitude: longitudeSchema });
365
+ const boundingBoxSchema = zod.z.object({
366
+ nw: coordinateSchema,
367
+ se: coordinateSchema,
368
+ });
369
+ const booleanArraySchema = zod.z.array(zod.z.boolean());
365
370
 
366
371
  /**
367
372
  * This hook is used to convert the sorting state from the AssetSortingContext to the AssetSortInput used by the GraphQL API
package/index.esm.js CHANGED
@@ -4,6 +4,7 @@ import { isStringArrayFilterValue, isMinMaxFilterValue, isDateRangeValue, isBool
4
4
  import { truthy } from '@trackunit/shared-utils';
5
5
  import { useCurrentUserSystemOfMeasurement, useAssetSorting } from '@trackunit/react-core-hooks';
6
6
  import { useMemo } from 'react';
7
+ import { z } from 'zod';
7
8
 
8
9
  var defaultTranslations = {
9
10
 
@@ -316,11 +317,13 @@ const useActiveAssetFilters = (filters) => {
316
317
  return {};
317
318
  }
318
319
  const followExist = filters.followed === "ALL" ? undefined : true;
320
+ const parsedBoundingBox = boundingBoxSchema.optional().safeParse(filters.boundingBox);
321
+ const parsedServiceBooked = booleanArraySchema.safeParse(filters.serviceBooked);
319
322
  return {
320
323
  assetIds: stringArrayOrUndefined(filters.assetIds),
321
324
  searchQuery: typeof filters.search === "string" && filters.search !== "" ? filters.search : undefined,
322
325
  activities: fixTypes(filters.activity, assetActivityState),
323
- boundingBox: isBoundingBox(filters.boundingBox) ? filters.boundingBox : undefined,
326
+ boundingBox: parsedBoundingBox.success ? parsedBoundingBox.data : undefined,
324
327
  brands: stringArrayOrUndefined(filters.brands),
325
328
  types: stringArrayOrUndefined(filters.types),
326
329
  criticalities: fixTypes(filters.criticality, assetCriticalityState),
@@ -333,7 +336,7 @@ const useActiveAssetFilters = (filters) => {
333
336
  metadataCompleteness: ((_b = valueNameArrayOrUndefined(filters.metadataCompleteness)) === null || _b === void 0 ? void 0 : _b[0]) === "ALL"
334
337
  ? undefined
335
338
  : (_c = fixTypes(valueNameArrayOrUndefined(filters.metadataCompleteness), metadataCompleteness)) === null || _c === void 0 ? void 0 : _c[0],
336
- serviceBooked: filters.serviceBooked,
339
+ serviceBooked: parsedServiceBooked.success ? parsedServiceBooked.data : undefined,
337
340
  servicePlanAssignments: fixTypes(filters.servicePlanStatus, servicePlanStatus),
338
341
  servicePlanIds: valueNameArrayOrUndefined(filters.servicePlan),
339
342
  servicePlanStatuses: fixTypes(filters.serviceStatus, servicePlanStatus),
@@ -354,12 +357,14 @@ const useActiveAssetFilters = (filters) => {
354
357
  }, [filters, customFields, systemOfMeasurement]);
355
358
  return filter;
356
359
  };
357
- const isBoundingBox = (value) => {
358
- return value
359
- ? // eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
360
- typeof value === "object" && Object.keys(value).includes("nw") && Object.keys(value).includes("se")
361
- : false;
362
- };
360
+ const latitudeSchema = z.number().min(-90).max(90);
361
+ const longitudeSchema = z.number().min(-180).max(180);
362
+ const coordinateSchema = z.object({ latitude: latitudeSchema, longitude: longitudeSchema });
363
+ const boundingBoxSchema = z.object({
364
+ nw: coordinateSchema,
365
+ se: coordinateSchema,
366
+ });
367
+ const booleanArraySchema = z.array(z.boolean());
363
368
 
364
369
  /**
365
370
  * This hook is used to convert the sorting state from the AssetSortingContext to the AssetSortInput used by the GraphQL API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/filters-graphql-hook",
3
- "version": "0.0.343",
3
+ "version": "0.0.345",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -19,7 +19,8 @@
19
19
  "graphql": "^15.8.0",
20
20
  "@apollo/client": "3.10.4",
21
21
  "@trackunit/react-core-contexts-test": "*",
22
- "@trackunit/iris-app-api": "*"
22
+ "@trackunit/iris-app-api": "*",
23
+ "zod": "3.22.4"
23
24
  },
24
25
  "module": "./index.esm.js",
25
26
  "main": "./index.cjs.js",