forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxep0215.ts
114 lines (105 loc) · 3.41 KB
/
xep0215.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// ====================================================================
// XEP-0215: External Service Discovery
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0215.html
// Version: 0.6 (2014-02-27)
// ====================================================================
import {
attribute,
booleanAttribute,
childAttribute,
childBooleanAttribute,
childDateAttribute,
childIntegerAttribute,
dateAttribute,
DefinitionOptions,
integerAttribute
} from '../jxt';
import { NS_DISCO_EXTERNAL_1, NS_DISCO_EXTERNAL_2 } from '../Namespaces';
import { DataForm } from './';
export interface ExternalService {
action?: 'add' | 'remove' | 'modify';
expires?: Date;
host?: string;
name?: string;
password?: string;
port?: number;
restricted?: boolean;
transport?: string;
type?: string;
username?: string;
form?: DataForm;
}
export interface ExternalServiceList {
version?: '1' | '2';
type?: string;
services?: ExternalService[];
}
export interface ExternalServiceCredentials extends ExternalService {
version?: '1' | '2';
}
declare module './' {
export interface IQPayload {
externalServices?: ExternalServiceList;
externalServiceCredentials?: ExternalServiceCredentials;
}
}
const versions = {
'2': NS_DISCO_EXTERNAL_2,
'1': NS_DISCO_EXTERNAL_1
};
const Protocol: DefinitionOptions[] = [];
for (const [version, namespace] of Object.entries(versions)) {
Protocol.push(
{
aliases: ['iq.externalServiceCredentials'],
defaultType: '2',
element: 'credentials',
fields: {
expires: childDateAttribute(null, 'service', 'expires'),
host: childAttribute(null, 'service', 'host'),
name: childAttribute(null, 'service', 'name'),
password: childAttribute(null, 'service', 'password'),
port: childIntegerAttribute(null, 'service', 'port'),
restricted: childBooleanAttribute(null, 'service', 'restricted'),
transport: childAttribute(null, 'service', 'transport'),
type: childAttribute(null, 'service', 'type'),
username: childAttribute(null, 'service', 'username')
},
namespace,
type: version,
typeField: 'version'
},
{
aliases: ['iq.externalServices'],
defaultType: '2',
element: 'services',
fields: {
type: attribute('type')
},
namespace,
type: version,
typeField: 'version'
},
{
aliases: [{ path: 'iq.externalServices.services', multiple: true }],
defaultType: '2',
element: 'service',
fields: {
expires: dateAttribute('expires'),
host: attribute('host'),
name: attribute('name'),
password: attribute('password'),
port: integerAttribute('port'),
restricted: booleanAttribute('restricted'),
transport: attribute('transport'),
type: attribute('type'),
username: attribute('username')
},
namespace,
type: version,
typeField: 'version'
}
);
}
export default Protocol;