@routr/common 2.0.8-alpha.16 → 2.0.8-alpha.17
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.
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { APIClient, DataAPIOptions, ServiceAPI, ServiceAPIOptions } from "./types";
|
|
2
2
|
export declare function apiClient(options: DataAPIOptions): APIClient;
|
|
3
|
-
export declare function serviceAPI(options: ServiceAPIOptions): ServiceAPI
|
|
3
|
+
export declare function serviceAPI<R>(options: ServiceAPIOptions): ServiceAPI<R>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as grpc from "@grpc/grpc-js";
|
|
2
2
|
import { JsonData } from "../../types";
|
|
3
|
-
import { Kind } from "../types";
|
|
3
|
+
import { AccessControlList, Agent, Credentials, Domain, INumber, Kind, Peer, Trunk } from "../types";
|
|
4
4
|
export interface DataAPIOptions {
|
|
5
5
|
apiAddr: string;
|
|
6
6
|
credentials?: grpc.ChannelCredentials;
|
|
@@ -26,30 +26,24 @@ export interface FindByResponse<R> {
|
|
|
26
26
|
items: R[];
|
|
27
27
|
}
|
|
28
28
|
export type APIClient = {
|
|
29
|
-
agents: ServiceAPI
|
|
30
|
-
domains: ServiceAPI
|
|
31
|
-
trunks: ServiceAPI
|
|
32
|
-
credentials: ServiceAPI
|
|
33
|
-
acl: ServiceAPI
|
|
34
|
-
peers: ServiceAPI
|
|
35
|
-
numbers: ServiceAPI
|
|
29
|
+
agents: ServiceAPI<Agent>;
|
|
30
|
+
domains: ServiceAPI<Domain>;
|
|
31
|
+
trunks: ServiceAPI<Trunk>;
|
|
32
|
+
credentials: ServiceAPI<Credentials>;
|
|
33
|
+
acl: ServiceAPI<AccessControlList>;
|
|
34
|
+
peers: ServiceAPI<Peer>;
|
|
35
|
+
numbers: ServiceAPI<INumber>;
|
|
36
36
|
};
|
|
37
|
-
export type ServiceAPI
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
update: <R
|
|
42
|
-
|
|
43
|
-
}>(request: JsonData) => Promise<R>;
|
|
44
|
-
get: <R extends {
|
|
45
|
-
extended?: JsonData;
|
|
46
|
-
}>(ref: string) => Promise<R>;
|
|
37
|
+
export type ServiceAPI<R extends {
|
|
38
|
+
extended?: JsonData;
|
|
39
|
+
}> = {
|
|
40
|
+
create: (request: JsonData) => Promise<R>;
|
|
41
|
+
update: (request: JsonData) => Promise<R>;
|
|
42
|
+
get: (ref: string) => Promise<R>;
|
|
47
43
|
del: (ref: string) => Promise<void>;
|
|
48
|
-
list:
|
|
49
|
-
extended?: JsonData;
|
|
50
|
-
}>(request: {
|
|
44
|
+
list: (request: {
|
|
51
45
|
pageSize: number;
|
|
52
46
|
pageToken: string;
|
|
53
47
|
}) => Promise<ListResponse<R>>;
|
|
54
|
-
findBy:
|
|
48
|
+
findBy: (request: FindByRequest) => Promise<FindByResponse<R>>;
|
|
55
49
|
};
|
package/dist/connect/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transport } from "../types";
|
|
1
|
+
import { Privacy, Transport } from "../types";
|
|
2
2
|
import { Kind } from "./types";
|
|
3
3
|
export interface ConfigBase {
|
|
4
4
|
apiVersion: string;
|
|
@@ -22,7 +22,7 @@ export interface AgentConfig extends ConfigBase {
|
|
|
22
22
|
username: string;
|
|
23
23
|
domainRef: string;
|
|
24
24
|
credentialsRef: string;
|
|
25
|
-
privacy:
|
|
25
|
+
privacy: Privacy;
|
|
26
26
|
enabled: boolean;
|
|
27
27
|
};
|
|
28
28
|
}
|
|
@@ -21,7 +21,8 @@ exports.convertACLConfigToACL = exports.convertCredentialsConfigToCredentials =
|
|
|
21
21
|
*/
|
|
22
22
|
/* eslint-disable require-jsdoc */
|
|
23
23
|
const logger_1 = require("@fonoster/logger");
|
|
24
|
-
const types_1 = require("
|
|
24
|
+
const types_1 = require("../types");
|
|
25
|
+
const types_2 = require("./types");
|
|
25
26
|
const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
|
|
26
27
|
const findByRef = (ref, list) => {
|
|
27
28
|
const resource = list.find((r) => r.ref === ref);
|
|
@@ -33,32 +34,33 @@ const findByRef = (ref, list) => {
|
|
|
33
34
|
};
|
|
34
35
|
const getConverter = (kind) => {
|
|
35
36
|
switch (kind) {
|
|
36
|
-
case
|
|
37
|
+
case types_2.Kind.AGENT:
|
|
37
38
|
return convertAgentConfigToAgent;
|
|
38
|
-
case
|
|
39
|
+
case types_2.Kind.DOMAIN:
|
|
39
40
|
return convertDomainConfigToDomain;
|
|
40
|
-
case
|
|
41
|
+
case types_2.Kind.PEER:
|
|
41
42
|
return convertPeerConfigToPeer;
|
|
42
|
-
case
|
|
43
|
+
case types_2.Kind.NUMBER:
|
|
43
44
|
return convertNumberConfigToNumber;
|
|
44
|
-
case
|
|
45
|
+
case types_2.Kind.TRUNK:
|
|
45
46
|
return convertTrunkConfigToTrunk;
|
|
46
|
-
case
|
|
47
|
+
case types_2.Kind.CREDENTIALS:
|
|
47
48
|
return convertCredentialsConfigToCredentials;
|
|
48
|
-
case
|
|
49
|
+
case types_2.Kind.ACL:
|
|
49
50
|
return convertACLConfigToACL;
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
exports.getConverter = getConverter;
|
|
53
54
|
function convertAgentConfigToAgent(config, list) {
|
|
54
|
-
|
|
55
|
+
var _a, _b;
|
|
56
|
+
if (config.kind !== types_2.Kind.AGENT)
|
|
55
57
|
throw new Error("invalid resource type `Agent`");
|
|
56
58
|
return {
|
|
57
59
|
apiVersion: config.apiVersion,
|
|
58
60
|
ref: config.ref,
|
|
59
61
|
name: config.metadata.name,
|
|
60
62
|
username: config.spec.username,
|
|
61
|
-
privacy: config.spec.privacy,
|
|
63
|
+
privacy: (_b = (_a = config.spec.privacy) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : types_1.Privacy.NONE,
|
|
62
64
|
enabled: config.spec.enabled,
|
|
63
65
|
domain: findByRef(config.spec.domainRef, list),
|
|
64
66
|
credentials: findByRef(config.spec.credentialsRef, list)
|
|
@@ -67,7 +69,7 @@ function convertAgentConfigToAgent(config, list) {
|
|
|
67
69
|
exports.convertAgentConfigToAgent = convertAgentConfigToAgent;
|
|
68
70
|
function convertDomainConfigToDomain(config, list) {
|
|
69
71
|
var _a;
|
|
70
|
-
if (config.kind !==
|
|
72
|
+
if (config.kind !== types_2.Kind.DOMAIN)
|
|
71
73
|
throw new Error("invalid resource type `Domain`");
|
|
72
74
|
const egressPolicies = (_a = config.spec.context.egressPolicies) === null || _a === void 0 ? void 0 : _a.map((policy) => {
|
|
73
75
|
return {
|
|
@@ -86,7 +88,7 @@ function convertDomainConfigToDomain(config, list) {
|
|
|
86
88
|
}
|
|
87
89
|
exports.convertDomainConfigToDomain = convertDomainConfigToDomain;
|
|
88
90
|
function convertPeerConfigToPeer(config, list) {
|
|
89
|
-
if (config.kind !==
|
|
91
|
+
if (config.kind !== types_2.Kind.PEER)
|
|
90
92
|
throw new Error("invalid resource type `Peer`");
|
|
91
93
|
return {
|
|
92
94
|
apiVersion: config.apiVersion,
|
|
@@ -101,7 +103,7 @@ function convertPeerConfigToPeer(config, list) {
|
|
|
101
103
|
}
|
|
102
104
|
exports.convertPeerConfigToPeer = convertPeerConfigToPeer;
|
|
103
105
|
function convertNumberConfigToNumber(config, list) {
|
|
104
|
-
if (config.kind !==
|
|
106
|
+
if (config.kind !== types_2.Kind.NUMBER)
|
|
105
107
|
throw new Error("invalid resource type `Number`");
|
|
106
108
|
const metadata = config.metadata;
|
|
107
109
|
const location = config.spec.location;
|
|
@@ -122,7 +124,7 @@ function convertNumberConfigToNumber(config, list) {
|
|
|
122
124
|
exports.convertNumberConfigToNumber = convertNumberConfigToNumber;
|
|
123
125
|
function convertTrunkConfigToTrunk(config, list) {
|
|
124
126
|
var _a;
|
|
125
|
-
if (config.kind !==
|
|
127
|
+
if (config.kind !== types_2.Kind.TRUNK)
|
|
126
128
|
throw new Error("invalid resource type `Trunk`");
|
|
127
129
|
const inbound = config.spec.inbound;
|
|
128
130
|
const outbound = config.spec.outbound;
|
|
@@ -150,7 +152,7 @@ function convertTrunkConfigToTrunk(config, list) {
|
|
|
150
152
|
}
|
|
151
153
|
exports.convertTrunkConfigToTrunk = convertTrunkConfigToTrunk;
|
|
152
154
|
function convertCredentialsConfigToCredentials(config) {
|
|
153
|
-
if (config.kind !==
|
|
155
|
+
if (config.kind !== types_2.Kind.CREDENTIALS)
|
|
154
156
|
throw new Error("invalid resource type `Credentials`");
|
|
155
157
|
return {
|
|
156
158
|
apiVersion: config.apiVersion,
|
|
@@ -163,7 +165,7 @@ function convertCredentialsConfigToCredentials(config) {
|
|
|
163
165
|
exports.convertCredentialsConfigToCredentials = convertCredentialsConfigToCredentials;
|
|
164
166
|
function convertACLConfigToACL(config) {
|
|
165
167
|
var _a, _b, _c, _d;
|
|
166
|
-
if (config.kind !==
|
|
168
|
+
if (config.kind !== types_2.Kind.ACL)
|
|
167
169
|
throw new Error("invalid resource type `AccessControlList`");
|
|
168
170
|
return {
|
|
169
171
|
apiVersion: config.apiVersion,
|
|
@@ -41,6 +41,11 @@ service Agents {
|
|
|
41
41
|
rpc FindBy (FindByRequest) returns (FindByResponse) {}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
enum Privacy {
|
|
45
|
+
PRIVATE = 0;
|
|
46
|
+
NONE = 1;
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
// The message for the Agent resource
|
|
45
50
|
message Agent {
|
|
46
51
|
// The API version of the Agent
|
|
@@ -52,7 +57,7 @@ message Agent {
|
|
|
52
57
|
// The username of the Agent
|
|
53
58
|
string username = 4;
|
|
54
59
|
// The password of the Agent
|
|
55
|
-
|
|
60
|
+
Privacy privacy = 5;
|
|
56
61
|
// The enabled status of the Agent
|
|
57
62
|
bool enabled = 6;
|
|
58
63
|
// The created_at timestamp of the Agent
|
|
@@ -76,13 +81,13 @@ message CreateAgentRequest {
|
|
|
76
81
|
// The username of the Agent
|
|
77
82
|
string username = 3;
|
|
78
83
|
// The password of the Agent
|
|
79
|
-
|
|
84
|
+
Privacy privacy = 4;
|
|
80
85
|
// The enabled status of the Agent
|
|
81
86
|
bool enabled = 5;
|
|
82
87
|
// The domain of the Agent
|
|
83
|
-
|
|
88
|
+
fonoster.routr.connect.domains.v2draft1.Domain domain = 6;
|
|
84
89
|
// The credentials of the Agent
|
|
85
|
-
|
|
90
|
+
fonoster.routr.connect.credentials.v2draft1.Credentials credentials = 7;
|
|
86
91
|
// The extended attributes of the Agent
|
|
87
92
|
.google.protobuf.Struct extended = 8;
|
|
88
93
|
}
|
|
@@ -98,7 +103,7 @@ message UpdateAgentRequest {
|
|
|
98
103
|
// The username of the Agent
|
|
99
104
|
string username = 4;
|
|
100
105
|
// The privacy settings of the Agent
|
|
101
|
-
|
|
106
|
+
Privacy privacy = 5;
|
|
102
107
|
// The enabled status of the Agent
|
|
103
108
|
bool enabled = 6;
|
|
104
109
|
// The domain of the Agent
|
package/dist/connect/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonData, Transport } from "../types";
|
|
1
|
+
import { JsonData, Privacy, Transport } from "../types";
|
|
2
2
|
export declare enum Kind {
|
|
3
3
|
AGENT = "agent",
|
|
4
4
|
PEER = "peer",
|
|
@@ -13,7 +13,7 @@ export declare enum APIVersion {
|
|
|
13
13
|
V2DRAFT1 = "v2draft1",
|
|
14
14
|
V2 = "v2"
|
|
15
15
|
}
|
|
16
|
-
export interface
|
|
16
|
+
export interface BaseConnectModel {
|
|
17
17
|
apiVersion: string;
|
|
18
18
|
ref: string;
|
|
19
19
|
name: string;
|
|
@@ -21,11 +21,11 @@ export interface RoutrResourceBase {
|
|
|
21
21
|
updatedAt?: Date;
|
|
22
22
|
extended?: JsonData;
|
|
23
23
|
}
|
|
24
|
-
export interface AccessControlList extends
|
|
24
|
+
export interface AccessControlList extends BaseConnectModel {
|
|
25
25
|
allow: string[];
|
|
26
26
|
deny: string[];
|
|
27
27
|
}
|
|
28
|
-
export interface Domain extends
|
|
28
|
+
export interface Domain extends BaseConnectModel {
|
|
29
29
|
domainUri: string;
|
|
30
30
|
accessControlList: AccessControlList;
|
|
31
31
|
egressPolicies: EgressPolicy[];
|
|
@@ -34,18 +34,18 @@ export interface EgressPolicy {
|
|
|
34
34
|
number: INumber;
|
|
35
35
|
rule: string;
|
|
36
36
|
}
|
|
37
|
-
export interface Agent extends
|
|
37
|
+
export interface Agent extends BaseConnectModel {
|
|
38
38
|
username: string;
|
|
39
|
-
privacy:
|
|
39
|
+
privacy: Privacy;
|
|
40
40
|
enabled: boolean;
|
|
41
41
|
domain?: Domain;
|
|
42
42
|
credentials?: Credentials;
|
|
43
43
|
}
|
|
44
|
-
export interface Credentials extends
|
|
44
|
+
export interface Credentials extends BaseConnectModel {
|
|
45
45
|
username: string;
|
|
46
46
|
password: string;
|
|
47
47
|
}
|
|
48
|
-
export interface INumber extends
|
|
48
|
+
export interface INumber extends BaseConnectModel {
|
|
49
49
|
telUrl: string;
|
|
50
50
|
aorLink: string;
|
|
51
51
|
city: string;
|
|
@@ -58,7 +58,7 @@ export interface INumber extends RoutrResourceBase {
|
|
|
58
58
|
}[];
|
|
59
59
|
trunk?: Trunk;
|
|
60
60
|
}
|
|
61
|
-
export interface Trunk extends
|
|
61
|
+
export interface Trunk extends BaseConnectModel {
|
|
62
62
|
sendRegister: boolean;
|
|
63
63
|
inboundUri: string;
|
|
64
64
|
accessControlList?: AccessControlList;
|
|
@@ -75,7 +75,7 @@ export interface TrunkURI {
|
|
|
75
75
|
priority: number;
|
|
76
76
|
enabled: boolean;
|
|
77
77
|
}
|
|
78
|
-
export interface Peer extends
|
|
78
|
+
export interface Peer extends BaseConnectModel {
|
|
79
79
|
username: string;
|
|
80
80
|
aor: string;
|
|
81
81
|
contactAddr: string;
|
|
@@ -83,5 +83,5 @@ export interface Peer extends RoutrResourceBase {
|
|
|
83
83
|
accessControlList?: AccessControlList;
|
|
84
84
|
credentials?: Credentials;
|
|
85
85
|
}
|
|
86
|
-
export type
|
|
86
|
+
export type ConnectModel = Agent | Peer | INumber | Trunk | Domain | Credentials | AccessControlList;
|
|
87
87
|
export type RoutableResourceUnion = Agent | Peer | INumber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/common",
|
|
3
|
-
"version": "2.0.8-alpha.
|
|
3
|
+
"version": "2.0.8-alpha.17",
|
|
4
4
|
"description": "Common package",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
25
25
|
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
26
26
|
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
27
|
-
"ajv": "^
|
|
27
|
+
"ajv": "^6.12.6",
|
|
28
28
|
"fp-ts": "^2.11.8",
|
|
29
29
|
"ip-utils": "^2.4.0",
|
|
30
30
|
"js-yaml": "^4.1.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/js-yaml": "^4.0.5"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "58f2415a0c32ab860a254a6fac0c1d3de8718dfb"
|
|
55
55
|
}
|