forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xep0050.ts
100 lines (94 loc) · 2.54 KB
/
xep0050.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// ====================================================================
// XEP-0050: Ad-Hoc Commands
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0050.html
// Version: 1.2.2 (2016-12-03)
// ====================================================================
import {
addAlias,
attribute,
childBoolean,
childEnum,
DefinitionOptions,
extendStanzaError,
text
} from '../jxt';
import { NS_ADHOC_COMMANDS, NS_DATAFORM } from '../Namespaces';
import { DataForm } from './';
declare module './' {
export interface IQPayload {
command?: AdHocCommand;
}
export interface StanzaError {
commandError?: AdhocCommandError;
}
}
export type AdhocCommandError =
| 'bad-action'
| 'bad-locale'
| 'bad-payload'
| 'bad-sessionid'
| 'malformed-action'
| 'session-expired';
export interface AdHocCommand {
sid?: string;
node?: string;
status?: 'canceled' | 'executing' | 'completed';
action?: 'execute' | 'cancel' | 'complete' | 'next' | 'prev';
availableActions?: {
execute: string;
next?: boolean;
prev?: boolean;
complete?: boolean;
};
notes?: Array<{
type?: 'info' | 'warn' | 'error';
value?: string;
}>;
form?: DataForm;
}
const Protocol: DefinitionOptions[] = [
addAlias(NS_DATAFORM, 'x', ['iq.command.form']),
extendStanzaError({
commandError: childEnum(NS_ADHOC_COMMANDS, [
'bad-action',
'bad-locale',
'bad-payload',
'bad-sessionid',
'malformed-action',
'session-expired'
])
}),
{
element: 'command',
fields: {
action: attribute('action'),
node: attribute('node'),
sid: attribute('sessionid'),
status: attribute('status')
},
namespace: NS_ADHOC_COMMANDS,
path: 'iq.command'
},
{
element: 'actions',
fields: {
complete: childBoolean(null, 'complete'),
execute: attribute('execute'),
next: childBoolean(null, 'next'),
prev: childBoolean(null, 'prev')
},
namespace: NS_ADHOC_COMMANDS,
path: 'iq.command.availableActions'
},
{
aliases: [{ path: 'iq.command.notes', multiple: true }],
element: 'note',
fields: {
type: attribute('type'),
value: text()
},
namespace: NS_ADHOC_COMMANDS
}
];
export default Protocol;