Skip to content

Commit 5f01ad3

Browse files
add CommandTemplate type (#217)
1 parent 223b480 commit 5f01ad3

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

packages/data-sdk/src/devices/Device.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import { TelemetryResult } from "../model/TelemetryResult";
3232
import { isRtcPeer } from "../utils/isRtcPeer";
3333
import { BaseDevice } from "./BaseDevice";
3434
import {
35-
Command,
3635
ConfigurationDocument,
36+
ICommandTemplate,
3737
IStartRealtimeConnectionOptions,
3838
TelemetryStream,
3939
} from "./device.types";
@@ -362,7 +362,9 @@ export class Device extends BaseDevice {
362362
return false;
363363
}
364364

365-
async getAvailableCommands(includeDisabled = true): Promise<Command[]> {
365+
async getAvailableCommands(
366+
includeDisabled = true
367+
): Promise<ICommandTemplate[]> {
366368
const result = await fetch(
367369
`${FORMANT_API_URL}/v1/admin/command-templates/`,
368370
{
@@ -374,24 +376,12 @@ export class Device extends BaseDevice {
374376
}
375377
);
376378
const commands = await result.json();
377-
return commands.items
378-
.map((i: any) => ({
379-
name: i.name,
380-
id: i.id,
381-
command: i.command,
382-
description: i.description,
383-
parameterEnabled: i.parameterEnabled,
384-
parameterValue: i.parameterValue,
385-
parameterMeta: i.parameterMeta,
386-
enabled: i.enabled,
387-
tags: i.tags,
388-
}))
389-
.filter((i: any) => {
390-
if (includeDisabled) {
391-
return true;
392-
}
393-
return i.enabled;
394-
});
379+
return commands.items.filter((i: ICommandTemplate) => {
380+
if (includeDisabled) {
381+
return true;
382+
}
383+
return i.enabled;
384+
});
395385
}
396386

397387
async sendCommand(

packages/data-sdk/src/devices/device.types.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { IRtcStreamPayload, RtcStreamType } from "@formant/realtime-sdk";
2+
import { IDictionary } from "../model/IDictionary";
3+
import { IFilter } from "../model/IFilter";
4+
import { IScopeFilter } from "../model/IScopeFilter";
5+
import { ITaggedEntity } from "../model/ITaggedEntity";
26
import { ITags } from "../model/ITags";
3-
import { Uuid } from "../model/Uuid";
47
import { SessionType } from "../model/SessionType";
8+
import { Uuid } from "../model/Uuid";
59

610
export interface ConfigurationDocument {
711
tags: ITags;
@@ -27,6 +31,36 @@ export interface ConfigurationDocument {
2731
adapters?: IAdapterConfiguration[];
2832
application?: { configurationMap: { [key: string]: string } };
2933
}
34+
export interface ICommandDeliverySettings {
35+
// command is dropped after it expires (defaults to defaultCommandTtlMs)
36+
ttlMs?: number;
37+
// `false` (default) for fire-and-forget (at most once delivery)
38+
// `true` for at least once delivery
39+
retryable?: boolean;
40+
41+
// TODO?
42+
// maxRetries?: number;
43+
// retryDelayMs?: number;
44+
// parallelExecution?: boolean;
45+
// maxPendingCommands?: number;
46+
}
47+
48+
export interface ICommandTemplate extends ITaggedEntity {
49+
organizationId?: Uuid;
50+
name: string;
51+
command: string;
52+
description?: string;
53+
parameterEnabled: boolean;
54+
allowParameterOverride?: boolean;
55+
parameterValue?: string | null;
56+
parameterMeta?: IDictionary;
57+
deviceScope?: IScopeFilter;
58+
enabled?: boolean;
59+
deviceFilter: IFilter | null;
60+
lambdaUri?: string | null;
61+
deliverySettings?: ICommandDeliverySettings;
62+
schema?: string | null;
63+
}
3064

3165
export interface Command {
3266
id: string;

packages/data-sdk/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type {
3131
Command,
3232
ConfigurationDocument,
3333
IAdapterConfiguration,
34+
ICommandTemplate,
3435
IJointState,
3536
IStartRealtimeConnectionOptions,
3637
RealtimeAudioStream,

0 commit comments

Comments
 (0)