@awarevue/api-types 1.0.74 → 1.0.76

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.
@@ -17,7 +17,8 @@ export declare const sAlarmAutomationCriteria: z.ZodObject<{
17
17
  export declare const sAlarmAutomationMetadata: z.ZodObject<{
18
18
  behavior: z.ZodEnum<["ignore", "trigger-always", "trigger-when-armed"]>;
19
19
  level: z.ZodEnum<["by-device", "by-type"]>;
20
- eventKind: z.ZodOptional<z.ZodString>;
20
+ eventKind: z.ZodString;
21
+ eventVariant: z.ZodNullable<z.ZodString>;
21
22
  eventCriteria: z.ZodArray<z.ZodObject<{
22
23
  field: z.ZodString;
23
24
  value: z.ZodUnknown;
@@ -31,39 +32,57 @@ export declare const sAlarmAutomationMetadata: z.ZodObject<{
31
32
  }, "strip", z.ZodTypeAny, {
32
33
  behavior: "ignore" | "trigger-always" | "trigger-when-armed";
33
34
  level: "by-device" | "by-type";
35
+ eventKind: string;
36
+ eventVariant: string | null;
34
37
  eventCriteria: {
35
38
  field: string;
36
39
  value?: unknown;
37
40
  }[];
38
- eventKind?: string | undefined;
39
41
  }, {
40
42
  behavior: "ignore" | "trigger-always" | "trigger-when-armed";
41
43
  level: "by-device" | "by-type";
44
+ eventKind: string;
45
+ eventVariant: string | null;
42
46
  eventCriteria: {
43
47
  field: string;
44
48
  value?: unknown;
45
49
  }[];
46
- eventKind?: string | undefined;
47
50
  }>;
48
51
  export type AlarmBehavior = z.infer<typeof sAlarmBehavior>;
49
52
  export type AlarmAutomationLevel = z.infer<typeof sAlarmAutomationLevel>;
50
53
  export type AlarmAutomationMetadata = z.infer<typeof sAlarmAutomationMetadata>;
54
+ export type AlarmAutomationCriteria = z.infer<typeof sAlarmAutomationCriteria>;
51
55
  export declare const isAlarmAutomationMetadata: (metadata: unknown) => metadata is AlarmAutomationMetadata;
52
- export declare const formatByDeviceAutomationCode: (eventKind: DeviceEvent["kind"], deviceId: string) => string;
53
- export declare const formatByTypeAutomationCode: (eventKind: DeviceEvent["kind"], deviceType: DeviceType) => string;
56
+ export declare const formatByDeviceAutomationCode: (eventKind: DeviceEvent["kind"], deviceId: string, variant?: string | null) => string;
57
+ export declare const formatByTypeAutomationCode: (eventKind: DeviceEvent["kind"], deviceType: DeviceType, variant?: string | null) => string;
54
58
  export declare const isByDeviceAutomationCode: (code: string) => boolean;
55
59
  export declare const isByTypeAutomationCode: (code: string) => boolean;
56
60
  export type ParsedByDeviceAutomationCode = {
57
61
  type: 'by-device';
58
62
  value: string;
59
63
  eventKind: DeviceEvent['kind'];
64
+ eventVariant: string | null;
60
65
  };
61
66
  export type ParsedByTypeAutomationCode = {
62
67
  type: 'by-type';
63
68
  value: DeviceType;
64
69
  eventKind: DeviceEvent['kind'];
70
+ eventVariant: string | null;
65
71
  };
66
72
  export type ParsedAlarmAutomationCode = ParsedByDeviceAutomationCode | ParsedByTypeAutomationCode;
67
73
  export declare const parseAlarmAutomationCode: (code: string) => ParsedAlarmAutomationCode | null;
68
74
  export declare const createAlarmRuleBody: (eventKind: DeviceEvent["kind"], behavior: AlarmBehavior, deviceType: DeviceType, eventCriteria: AlarmAutomationMetadata["eventCriteria"], deviceId?: string) => AutomationRuleBody;
69
75
  export declare const resolveAlarmExclusivityGroup: (deviceType: DeviceType) => string;
76
+ export type DeviceEventVariant = {
77
+ name: string;
78
+ label: string;
79
+ criteria: AlarmAutomationCriteria[];
80
+ };
81
+ export declare const alarmEventVariants: {
82
+ 'door-access': DeviceEventVariant[];
83
+ 'object-detection-started': DeviceEventVariant[];
84
+ 'object-detection-ended': never[];
85
+ 'object-detection-updated': never[];
86
+ 'scene-updated': never[];
87
+ 'scene-ended': never[];
88
+ };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveAlarmExclusivityGroup = exports.createAlarmRuleBody = exports.parseAlarmAutomationCode = exports.isByTypeAutomationCode = exports.isByDeviceAutomationCode = exports.formatByTypeAutomationCode = exports.formatByDeviceAutomationCode = exports.isAlarmAutomationMetadata = exports.sAlarmAutomationMetadata = exports.sAlarmAutomationCriteria = exports.sAlarmAutomationLevel = exports.sAlarmBehavior = void 0;
3
+ exports.alarmEventVariants = exports.resolveAlarmExclusivityGroup = exports.createAlarmRuleBody = exports.parseAlarmAutomationCode = exports.isByTypeAutomationCode = exports.isByDeviceAutomationCode = exports.formatByTypeAutomationCode = exports.formatByDeviceAutomationCode = exports.isAlarmAutomationMetadata = exports.sAlarmAutomationMetadata = exports.sAlarmAutomationCriteria = exports.sAlarmAutomationLevel = exports.sAlarmBehavior = void 0;
4
4
  const zod_1 = require("zod");
5
+ const world_objects_1 = require("./world-objects");
5
6
  exports.sAlarmBehavior = zod_1.z.enum([
6
7
  'ignore',
7
8
  'trigger-always',
@@ -15,7 +16,11 @@ exports.sAlarmAutomationCriteria = zod_1.z.object({
15
16
  exports.sAlarmAutomationMetadata = zod_1.z.object({
16
17
  behavior: exports.sAlarmBehavior,
17
18
  level: exports.sAlarmAutomationLevel,
18
- eventKind: zod_1.z.string().optional().describe('The kind of event to match'),
19
+ eventKind: zod_1.z.string().describe('The kind of event to match'),
20
+ eventVariant: zod_1.z
21
+ .string()
22
+ .nullable()
23
+ .describe('Optional variant for specific device events'),
19
24
  eventCriteria: zod_1.z.array(exports.sAlarmAutomationCriteria),
20
25
  });
21
26
  const isAlarmAutomationMetadata = (metadata) => {
@@ -29,12 +34,12 @@ exports.isAlarmAutomationMetadata = isAlarmAutomationMetadata;
29
34
  // Alarm assigns automation rules with code that is either:
30
35
  // [by-event]:[event-kind]
31
36
  // [by-device]:[device-id]
32
- const formatByDeviceAutomationCode = (eventKind, deviceId) => {
33
- return `by-device:${deviceId}:${eventKind}`;
37
+ const formatByDeviceAutomationCode = (eventKind, deviceId, variant = null) => {
38
+ return `by-device:${deviceId}:${eventKind}${variant ? `:${variant}` : ''}`;
34
39
  };
35
40
  exports.formatByDeviceAutomationCode = formatByDeviceAutomationCode;
36
- const formatByTypeAutomationCode = (eventKind, deviceType) => {
37
- return `by-type:${deviceType}:${eventKind}`;
41
+ const formatByTypeAutomationCode = (eventKind, deviceType, variant = null) => {
42
+ return `by-type:${deviceType}:${eventKind}${variant ? `:${variant}` : ''}`;
38
43
  };
39
44
  exports.formatByTypeAutomationCode = formatByTypeAutomationCode;
40
45
  const isByDeviceAutomationCode = (code) => {
@@ -48,60 +53,51 @@ exports.isByTypeAutomationCode = isByTypeAutomationCode;
48
53
  const parseAlarmAutomationCode = (code) => {
49
54
  if ((0, exports.isByDeviceAutomationCode)(code)) {
50
55
  const parts = code.replace('by-device:', '').split(':');
51
- if (parts.length !== 2) {
56
+ if (parts.length < 2) {
52
57
  return null; // Invalid format
53
58
  }
54
59
  return {
55
60
  type: 'by-device',
56
61
  value: parts[0], // deviceId
57
62
  eventKind: parts[1], // eventKind
63
+ eventVariant: parts[2] || null, // Optional variant for specific device events
58
64
  };
59
65
  }
60
66
  if ((0, exports.isByTypeAutomationCode)(code)) {
61
67
  const parts = code.replace('by-type:', '').split(':');
62
- if (parts.length !== 2) {
68
+ if (parts.length < 2) {
63
69
  return null; // Invalid format
64
70
  }
65
71
  return {
66
72
  type: 'by-type',
67
73
  value: parts[0], // deviceType
68
74
  eventKind: parts[1], // eventKind
75
+ eventVariant: parts[2] || null, // Optional variant for specific device events
69
76
  };
70
77
  }
71
78
  return null;
72
79
  };
73
80
  exports.parseAlarmAutomationCode = parseAlarmAutomationCode;
74
- // {
75
- // "displayName": "Trigger alarm on force-open door events",
76
- // "enabled": true,
77
- // "body": {
78
- // "onEvent": "door-force",
79
- // "commands": [
80
- // {
81
- // "command": "alarm.set-trigger",
82
- // "target": "target.type ==\"alarm\"",
83
- // "params": {
84
- // "event": "{{event}}",
85
- // "onlyIfArmed": "{{device.provider ==\"paxton\"}}"
86
- // }
87
- // }
88
- // ]
89
- // }
90
- // }
91
- const encodeComparison = (value) => {
81
+ const encodeValue = (value) => {
92
82
  if (typeof value === 'string') {
93
- return `== ${JSON.stringify(value)}`;
83
+ return `${JSON.stringify(value)}`;
94
84
  }
95
85
  if (typeof value === 'number' || typeof value === 'boolean') {
96
- return `== ${String(value)}`;
86
+ return `${String(value)}`;
97
87
  }
98
88
  if (Array.isArray(value)) {
99
- return `in (${value.map(encodeComparison).join(', ')})`;
89
+ return `(${value.map(encodeValue).join(', ')})`;
100
90
  }
101
91
  if (value === null) {
102
- return '== null';
92
+ return 'null';
103
93
  }
104
- throw new Error(`Unsupported value type for comparison: ${typeof value}`);
94
+ throw new Error(`Unsupported value type for: ${typeof value}`);
95
+ };
96
+ const encodeComparison = (value) => {
97
+ if (Array.isArray(value)) {
98
+ return `in ${encodeValue(value)}`;
99
+ }
100
+ return `== ${encodeValue(value)}`;
105
101
  };
106
102
  const createAlarmRuleBody = (eventKind, behavior, deviceType, eventCriteria, deviceId) => {
107
103
  let runIf = 'source.type == "' + deviceType + '"';
@@ -131,3 +127,32 @@ const createAlarmRuleBody = (eventKind, behavior, deviceType, eventCriteria, dev
131
127
  exports.createAlarmRuleBody = createAlarmRuleBody;
132
128
  const resolveAlarmExclusivityGroup = (deviceType) => `alarm-${deviceType}`;
133
129
  exports.resolveAlarmExclusivityGroup = resolveAlarmExclusivityGroup;
130
+ const sorted = (specs) => {
131
+ return specs.sort((a, b) => a.label.localeCompare(b.label));
132
+ };
133
+ exports.alarmEventVariants = {
134
+ 'door-access': sorted([
135
+ {
136
+ name: 'allowed',
137
+ label: 'Door Access Granted',
138
+ criteria: [{ field: 'allowed', value: true }],
139
+ },
140
+ {
141
+ name: 'denied',
142
+ label: 'Door Access Denied',
143
+ criteria: [{ field: 'allowed', value: false }],
144
+ },
145
+ ]),
146
+ 'object-detection-started': sorted([
147
+ // TODO - add criteria for object detection started
148
+ ...world_objects_1.worldObjects.map((object) => ({
149
+ name: object.id,
150
+ label: `${object.label} Detected`,
151
+ criteria: [{ field: 'objectKind', value: object.id }],
152
+ })),
153
+ ]),
154
+ 'object-detection-ended': [],
155
+ 'object-detection-updated': [],
156
+ 'scene-updated': [],
157
+ 'scene-ended': [],
158
+ };
package/dist/index.d.ts CHANGED
@@ -30,3 +30,4 @@ export * from './agent-communication';
30
30
  export * from './cast';
31
31
  export * from './security-level';
32
32
  export * from './token-conversion';
33
+ export * from './world-objects';
package/dist/index.js CHANGED
@@ -46,3 +46,4 @@ __exportStar(require("./agent-communication"), exports);
46
46
  __exportStar(require("./cast"), exports);
47
47
  __exportStar(require("./security-level"), exports);
48
48
  __exportStar(require("./token-conversion"), exports);
49
+ __exportStar(require("./world-objects"), exports);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awarevue/api-types",
3
- "version": "1.0.74",
3
+ "version": "1.0.76",
4
4
  "description": "Common types between backend, agent(s) and frontend(s)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const sWorldObject: z.ZodObject<{
3
+ id: z.ZodString;
4
+ label: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ id: string;
7
+ label: string;
8
+ }, {
9
+ id: string;
10
+ label: string;
11
+ }>;
12
+ export type WorldObject = z.infer<typeof sWorldObject>;
13
+ export declare const worldObjects: WorldObject[];
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.worldObjects = exports.sWorldObject = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.sWorldObject = zod_1.z.object({
6
+ id: zod_1.z.string().describe('The unique identifier of the world object'),
7
+ label: zod_1.z.string().describe('The label of the world object'),
8
+ });
9
+ exports.worldObjects = [
10
+ {
11
+ id: 'person',
12
+ label: 'Person',
13
+ },
14
+ {
15
+ id: 'backpack',
16
+ label: 'Backpack',
17
+ },
18
+ {
19
+ id: 'cell-phone',
20
+ label: 'Cell Phone',
21
+ },
22
+ {
23
+ id: 'handbag',
24
+ label: 'Handbag',
25
+ },
26
+ {
27
+ id: 'laptop',
28
+ label: 'Laptop',
29
+ },
30
+ {
31
+ id: 'bicycle',
32
+ label: 'Bicycle',
33
+ },
34
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awarevue/api-types",
3
- "version": "1.0.74",
3
+ "version": "1.0.76",
4
4
  "description": "Common types between backend, agent(s) and frontend(s)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",