@haakco/custd-react 3.71.2 → 3.72.0

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/README.md CHANGED
@@ -14,7 +14,7 @@ function or existing `UseQueryResult`. The session helpers wrap a core
14
14
  ## Install
15
15
 
16
16
  ```bash
17
- pnpm add @haakco/custd-sdk@^3.71.2 @haakco/custd-react@^3.71.2
17
+ pnpm add @haakco/custd-sdk@^3.72.0 @haakco/custd-react@^3.72.0
18
18
  ```
19
19
 
20
20
  Use the same released version for both packages; both are public on npmjs. These examples were verified on
package/dist/index.d.ts CHANGED
@@ -32,6 +32,7 @@ export { ConvergenceStory, type ConvergenceStoryLabels, type ConvergenceStoryPro
32
32
  export { ForecastChart, type ForecastChartLabels, type ForecastChartProps } from "./forecast-chart.js";
33
33
  export type { ArrivalHistogramBin, ArrivalHistogramData, ChartFormatters, ConvergenceEstimate, ForecastChartData, ForecastEarlierRun, ForecastInterval, ForecastPoint, ForecastPosteriorLine, } from "./forecast-types.js";
34
34
  export { CUSTD_HOSTED_APP_LOADING, CustdHostedAppProvider, type CustdHostedAppProviderProps, type CustdHostedAppState, useCustdHostedApp, } from "./hosted-app.js";
35
+ export { machineAccessQueryKeys, useEffectiveMachineAccess, useMachineAccess, useMachineAccessOverride, useUpdateMachineAccess, useUpdateMachineAccessOverride, } from "./machine-access.js";
35
36
  export { MeasureNextPanel, type MeasureNextPanelLabels, type MeasureNextPanelProps, } from "./measure-next-panel.js";
36
37
  export { ModelCalculator, type ModelCalculatorInput, type ModelCalculatorLabels, type ModelCalculatorProps, type ModelCalculatorRequest, type ModelCalculatorResult, } from "./model-calculator.js";
37
38
  export { downloadSummaryCsv } from "./model-csv.js";
package/dist/index.js CHANGED
@@ -56,6 +56,7 @@ export { ArrivalHistogram, } from "./arrival-histogram.js";
56
56
  export { ConvergenceStory } from "./convergence-story.js";
57
57
  export { ForecastChart } from "./forecast-chart.js";
58
58
  export { CUSTD_HOSTED_APP_LOADING, CustdHostedAppProvider, useCustdHostedApp, } from "./hosted-app.js";
59
+ export { machineAccessQueryKeys, useEffectiveMachineAccess, useMachineAccess, useMachineAccessOverride, useUpdateMachineAccess, useUpdateMachineAccessOverride, } from "./machine-access.js";
59
60
  export { MeasureNextPanel, } from "./measure-next-panel.js";
60
61
  export { ModelCalculator, } from "./model-calculator.js";
61
62
  export { downloadSummaryCsv } from "./model-csv.js";
@@ -0,0 +1,21 @@
1
+ import type { MachineAccessAdminClient, MachineAccessCompanyPolicy, MachineAccessCompanyUpdateRequest, MachineAccessEffective, MachineAccessMachinePolicy, MachineAccessMachineUpdateRequest } from "@haakco/custd-sdk";
2
+ import { type UseMutationResult, type UseQueryResult } from "@tanstack/react-query";
3
+ /**
4
+ * Query keys of the machine access reads, so an app can invalidate them after a change it made
5
+ * elsewhere. `effective()` covers every machine's effective access.
6
+ */
7
+ export declare const machineAccessQueryKeys: {
8
+ company: (companySlug?: string) => readonly ["custd", "machine-access", "company", string];
9
+ override: (clientId: string) => readonly ["custd", "machine-access", "override", string];
10
+ effective: (clientId?: string) => readonly ["custd", "machine-access", "effective"] | readonly ["custd", "machine-access", "effective", string];
11
+ };
12
+ /** The company's machine access policy. A tenant administrator omits companySlug. */
13
+ export declare function useMachineAccess(client: MachineAccessAdminClient, companySlug?: string): UseQueryResult<MachineAccessCompanyPolicy, Error>;
14
+ /** Changes the company policy; every machine's effective access is read again after it. */
15
+ export declare function useUpdateMachineAccess(client: MachineAccessAdminClient, companySlug?: string): UseMutationResult<MachineAccessCompanyPolicy, Error, MachineAccessCompanyUpdateRequest>;
16
+ /** One machine's per-area override. */
17
+ export declare function useMachineAccessOverride(client: MachineAccessAdminClient, clientId: string): UseQueryResult<MachineAccessMachinePolicy, Error>;
18
+ /** Changes one machine's override; that machine's effective access is read again after it. */
19
+ export declare function useUpdateMachineAccessOverride(client: MachineAccessAdminClient, clientId: string): UseMutationResult<MachineAccessMachinePolicy, Error, MachineAccessMachineUpdateRequest>;
20
+ /** What one machine may do in each area and which setting decided it. */
21
+ export declare function useEffectiveMachineAccess(client: MachineAccessAdminClient, clientId: string): UseQueryResult<MachineAccessEffective, Error>;
@@ -0,0 +1,57 @@
1
+ import { useMutation, useQuery, useQueryClient, } from "@tanstack/react-query";
2
+ /**
3
+ * Query keys of the machine access reads, so an app can invalidate them after a change it made
4
+ * elsewhere. `effective()` covers every machine's effective access.
5
+ */
6
+ export const machineAccessQueryKeys = {
7
+ company: (companySlug = "") => ["custd", "machine-access", "company", companySlug],
8
+ override: (clientId) => ["custd", "machine-access", "override", clientId],
9
+ effective: (clientId) => clientId === undefined
10
+ ? ["custd", "machine-access", "effective"]
11
+ : ["custd", "machine-access", "effective", clientId],
12
+ };
13
+ /** The company's machine access policy. A tenant administrator omits companySlug. */
14
+ export function useMachineAccess(client, companySlug) {
15
+ return useQuery({
16
+ queryKey: machineAccessQueryKeys.company(companySlug),
17
+ queryFn: ({ signal }) => client.get(companySlug, { signal }),
18
+ });
19
+ }
20
+ /** Changes the company policy; every machine's effective access is read again after it. */
21
+ export function useUpdateMachineAccess(client, companySlug) {
22
+ const queryClient = useQueryClient();
23
+ return useMutation({
24
+ mutationFn: (body) => client.update(body, companySlug),
25
+ onSuccess: async (saved) => {
26
+ queryClient.setQueryData(machineAccessQueryKeys.company(companySlug), saved);
27
+ await queryClient.invalidateQueries({ queryKey: machineAccessQueryKeys.effective() });
28
+ },
29
+ });
30
+ }
31
+ /** One machine's per-area override. */
32
+ export function useMachineAccessOverride(client, clientId) {
33
+ return useQuery({
34
+ queryKey: machineAccessQueryKeys.override(clientId),
35
+ queryFn: ({ signal }) => client.getOverride(clientId, { signal }),
36
+ enabled: clientId !== "",
37
+ });
38
+ }
39
+ /** Changes one machine's override; that machine's effective access is read again after it. */
40
+ export function useUpdateMachineAccessOverride(client, clientId) {
41
+ const queryClient = useQueryClient();
42
+ return useMutation({
43
+ mutationFn: (body) => client.updateOverride(clientId, body),
44
+ onSuccess: async (saved) => {
45
+ queryClient.setQueryData(machineAccessQueryKeys.override(clientId), saved);
46
+ await queryClient.invalidateQueries({ queryKey: machineAccessQueryKeys.effective(clientId) });
47
+ },
48
+ });
49
+ }
50
+ /** What one machine may do in each area and which setting decided it. */
51
+ export function useEffectiveMachineAccess(client, clientId) {
52
+ return useQuery({
53
+ queryKey: machineAccessQueryKeys.effective(clientId),
54
+ queryFn: ({ signal }) => client.getEffective(clientId, { signal }),
55
+ enabled: clientId !== "",
56
+ });
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haakco/custd-react",
3
- "version": "3.71.2",
3
+ "version": "3.72.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24 <27"
@@ -29,7 +29,7 @@
29
29
  "test": "vitest run src"
30
30
  },
31
31
  "peerDependencies": {
32
- "@haakco/custd-sdk": ">=3.64.8 <4",
32
+ "@haakco/custd-sdk": ">=3.72.0 <4",
33
33
  "@tanstack/react-query": ">=5 <6",
34
34
  "react": ">=18 <20"
35
35
  },