@routr/common 2.0.8-alpha.13 → 2.0.8-alpha.15
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.
- package/dist/connect/api/client.d.ts +3 -0
- package/dist/connect/api/client.js +154 -0
- package/dist/connect/api/index.d.ts +2 -0
- package/dist/connect/api/index.js +36 -0
- package/dist/connect/api/types.d.ts +55 -0
- package/dist/connect/api/types.js +2 -0
- package/dist/connect/config.d.ts +109 -0
- package/dist/connect/config.js +2 -0
- package/dist/connect/converters.d.ts +10 -0
- package/dist/connect/converters.js +176 -0
- package/dist/connect/grpc_client.d.ts +8 -1
- package/dist/connect/grpc_client.js +44 -6
- package/dist/connect/index.d.ts +3 -1
- package/dist/connect/index.js +3 -1
- package/dist/connect/protos/acl.proto +117 -0
- package/dist/connect/protos/agents.proto +154 -0
- package/dist/connect/protos/credentials.proto +116 -0
- package/dist/connect/protos/domains.proto +150 -0
- package/dist/connect/protos/numbers.proto +184 -0
- package/dist/connect/protos/peers.proto +166 -0
- package/dist/connect/protos/trunks.proto +186 -0
- package/dist/connect/schemas/acl.d.ts +61 -0
- package/dist/connect/schemas/acl.js +80 -0
- package/dist/connect/schemas/agent.d.ts +60 -0
- package/dist/connect/schemas/agent.js +79 -0
- package/dist/connect/schemas/crendentials.d.ts +55 -0
- package/dist/connect/schemas/crendentials.js +74 -0
- package/dist/connect/schemas/domain.d.ts +73 -0
- package/dist/connect/schemas/domain.js +92 -0
- package/dist/connect/schemas/index.d.ts +1 -0
- package/dist/connect/schemas/index.js +35 -0
- package/dist/connect/schemas/number.d.ts +78 -0
- package/dist/connect/schemas/number.js +97 -0
- package/dist/connect/schemas/peer.d.ts +68 -0
- package/dist/connect/schemas/peer.js +87 -0
- package/dist/connect/schemas/trunk.d.ts +116 -0
- package/dist/connect/schemas/trunk.js +135 -0
- package/dist/connect/schemas/validators.d.ts +2 -0
- package/dist/connect/schemas/validators.js +43 -0
- package/dist/connect/types.d.ts +74 -25
- package/dist/connect/types.js +7 -30
- package/dist/errors.d.ts +35 -1
- package/dist/errors.js +51 -5
- package/dist/helper.d.ts +1 -0
- package/dist/helper.js +11 -3
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -5
- package/dist/protos/common.proto +0 -2
- package/dist/protos/location.proto +3 -2
- package/dist/service.d.ts +2 -2
- package/dist/service.js +1 -1
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
- package/dist/connect/data_api.d.ts +0 -11
- package/dist/connect/data_api.js +0 -91
- package/dist/protos/resources.proto +0 -108
package/dist/errors.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ServiceUnavailableError = exports.
|
|
26
|
+
exports.BadRequestError = exports.ResourceNotFoundError = exports.UnimplementedError = exports.ServiceUnavailableError = exports.ServiceDefinitionNotFoundError = void 0;
|
|
27
27
|
/*
|
|
28
28
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
29
|
* http://github.com/fonoster/routr
|
|
@@ -46,7 +46,7 @@ const grpc = __importStar(require("@grpc/grpc-js"));
|
|
|
46
46
|
/**
|
|
47
47
|
* Error thrown if the definition for a service is not found.
|
|
48
48
|
*/
|
|
49
|
-
class
|
|
49
|
+
class ServiceDefinitionNotFoundError extends Error {
|
|
50
50
|
/**
|
|
51
51
|
* Constructs a new ServiceDefinitionNotFound error.
|
|
52
52
|
*
|
|
@@ -54,12 +54,12 @@ class ServiceDefinitionNotFound extends Error {
|
|
|
54
54
|
* @param {string} version - The version of the service definition.
|
|
55
55
|
*/
|
|
56
56
|
constructor(name, version) {
|
|
57
|
-
super(`
|
|
57
|
+
super(`service definition for ${name}/${version} not found`);
|
|
58
58
|
// Set the prototype explicitly.
|
|
59
|
-
Object.setPrototypeOf(this,
|
|
59
|
+
Object.setPrototypeOf(this, ServiceDefinitionNotFoundError.prototype);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
exports.
|
|
62
|
+
exports.ServiceDefinitionNotFoundError = ServiceDefinitionNotFoundError;
|
|
63
63
|
/**
|
|
64
64
|
* Error thrown if the service is not available.
|
|
65
65
|
*/
|
|
@@ -76,3 +76,49 @@ class ServiceUnavailableError extends Error {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
exports.ServiceUnavailableError = ServiceUnavailableError;
|
|
79
|
+
/**
|
|
80
|
+
* Thrown for unimplemented handlers.
|
|
81
|
+
*/
|
|
82
|
+
class UnimplementedError extends Error {
|
|
83
|
+
/**
|
|
84
|
+
* Creates an instance of UnimplementedError.
|
|
85
|
+
*/
|
|
86
|
+
constructor() {
|
|
87
|
+
super("this operation is not supported/enabled in this data api implementation.");
|
|
88
|
+
this.code = grpc.status.UNIMPLEMENTED;
|
|
89
|
+
Object.setPrototypeOf(this, UnimplementedError.prototype);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.UnimplementedError = UnimplementedError;
|
|
93
|
+
/**
|
|
94
|
+
* Thrown if the resource is not found.
|
|
95
|
+
*/
|
|
96
|
+
class ResourceNotFoundError extends Error {
|
|
97
|
+
/**
|
|
98
|
+
* Creates an instance of UnimplementedError.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} ref - the reference of the resource
|
|
101
|
+
*/
|
|
102
|
+
constructor(ref) {
|
|
103
|
+
super(`resource not found: ${ref}`);
|
|
104
|
+
this.code = grpc.status.NOT_FOUND;
|
|
105
|
+
Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.ResourceNotFoundError = ResourceNotFoundError;
|
|
109
|
+
/**
|
|
110
|
+
* Thrown if the request is invalid.
|
|
111
|
+
*/
|
|
112
|
+
class BadRequestError extends Error {
|
|
113
|
+
/**
|
|
114
|
+
* Creates an instance of UnimplementedError.
|
|
115
|
+
*
|
|
116
|
+
* @param {string} message - optional message with the error. Defaults to "bad request."
|
|
117
|
+
*/
|
|
118
|
+
constructor(message) {
|
|
119
|
+
super(message !== null && message !== void 0 ? message : "bad request");
|
|
120
|
+
this.code = grpc.status.INVALID_ARGUMENT;
|
|
121
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.BadRequestError = BadRequestError;
|
package/dist/helper.d.ts
CHANGED
|
@@ -26,3 +26,4 @@ export declare const getListeningPoint: (listeningPoints: NetInterface[], transp
|
|
|
26
26
|
* @throws {Error} If the file is empty.
|
|
27
27
|
*/
|
|
28
28
|
export declare const readConfigFile: (path: string) => Record<string, any>;
|
|
29
|
+
export declare const toPascaleCase: (str: string) => string;
|
package/dist/helper.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.readConfigFile = exports.getListeningPoint = exports.deepCopy = void 0;
|
|
29
|
+
exports.toPascaleCase = exports.readConfigFile = exports.getListeningPoint = exports.deepCopy = void 0;
|
|
30
30
|
/*
|
|
31
31
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
32
32
|
* http://github.com/fonoster/routr
|
|
@@ -45,10 +45,10 @@ exports.readConfigFile = exports.getListeningPoint = exports.deepCopy = void 0;
|
|
|
45
45
|
* See the License for the specific language governing permissions and
|
|
46
46
|
* limitations under the License.
|
|
47
47
|
*/
|
|
48
|
-
const types_1 = require("./types");
|
|
49
|
-
const fs_1 = __importDefault(require("fs"));
|
|
50
48
|
const yaml = __importStar(require("js-yaml"));
|
|
51
49
|
const toml = __importStar(require("toml"));
|
|
50
|
+
const fs_1 = __importDefault(require("fs"));
|
|
51
|
+
const types_1 = require("./types");
|
|
52
52
|
/**
|
|
53
53
|
* Makes a deep copy of an object.
|
|
54
54
|
*
|
|
@@ -124,3 +124,11 @@ const readConfigFile = (path) => {
|
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
exports.readConfigFile = readConfigFile;
|
|
127
|
+
const toPascaleCase = (str) => {
|
|
128
|
+
return str
|
|
129
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
|
|
130
|
+
return index === 0 ? word.toUpperCase() : word.toUpperCase();
|
|
131
|
+
})
|
|
132
|
+
.replace(/\s+/g, "");
|
|
133
|
+
};
|
|
134
|
+
exports.toPascaleCase = toPascaleCase;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { ServiceUnavailableError } from "./errors";
|
|
2
1
|
import createService, { getObjectProto, LOCATION_OBJECT_PROTO, PROCESSOR_OBJECT_PROTO } from "./service";
|
|
3
2
|
import { HeaderModifier, MessageRequest, MessageResponse, Method, NetInterface, ObjectProto, ProcessorConfig, Route, ServiceInfo, Transport } from "./types";
|
|
4
|
-
export { createService, getObjectProto, HeaderModifier, Route,
|
|
3
|
+
export { createService, getObjectProto, HeaderModifier, Route, Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO };
|
|
4
|
+
export * as Auth from "./auth";
|
|
5
5
|
export * as Redis from "./redis";
|
|
6
|
-
export * as CommonTypes from "./types";
|
|
7
6
|
export * as Helper from "./helper";
|
|
8
7
|
export * as IpUtils from "./ip_utils";
|
|
9
8
|
export * as Tracer from "./tracer";
|
|
10
9
|
export * as Assertions from "./assertions";
|
|
11
10
|
export * as CommonConnect from "./connect";
|
|
12
11
|
export * as CommonRequester from "./requester";
|
|
13
|
-
export * as
|
|
12
|
+
export * as CommonTypes from "./types";
|
|
13
|
+
export * as CommonErrors from "./errors";
|
|
14
|
+
export * as ConnectSchemas from "./connect/schemas";
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.ConnectSchemas = exports.CommonErrors = exports.CommonTypes = exports.CommonRequester = exports.CommonConnect = exports.Assertions = exports.Tracer = exports.IpUtils = exports.Helper = exports.Redis = exports.Auth = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.Method = exports.Transport = exports.getObjectProto = exports.createService = void 0;
|
|
27
27
|
/*
|
|
28
28
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
29
|
* http://github.com/fonoster/routr
|
|
@@ -42,8 +42,6 @@ exports.Auth = exports.CommonRequester = exports.CommonConnect = exports.Asserti
|
|
|
42
42
|
* See the License for the specific language governing permissions and
|
|
43
43
|
* limitations under the License.
|
|
44
44
|
*/
|
|
45
|
-
const errors_1 = require("./errors");
|
|
46
|
-
Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return errors_1.ServiceUnavailableError; } });
|
|
47
45
|
const service_1 = __importStar(require("./service"));
|
|
48
46
|
exports.createService = service_1.default;
|
|
49
47
|
Object.defineProperty(exports, "getObjectProto", { enumerable: true, get: function () { return service_1.getObjectProto; } });
|
|
@@ -52,12 +50,14 @@ Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get
|
|
|
52
50
|
const types_1 = require("./types");
|
|
53
51
|
Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return types_1.Method; } });
|
|
54
52
|
Object.defineProperty(exports, "Transport", { enumerable: true, get: function () { return types_1.Transport; } });
|
|
53
|
+
exports.Auth = __importStar(require("./auth"));
|
|
55
54
|
exports.Redis = __importStar(require("./redis"));
|
|
56
|
-
exports.CommonTypes = __importStar(require("./types"));
|
|
57
55
|
exports.Helper = __importStar(require("./helper"));
|
|
58
56
|
exports.IpUtils = __importStar(require("./ip_utils"));
|
|
59
57
|
exports.Tracer = __importStar(require("./tracer"));
|
|
60
58
|
exports.Assertions = __importStar(require("./assertions"));
|
|
61
59
|
exports.CommonConnect = __importStar(require("./connect"));
|
|
62
60
|
exports.CommonRequester = __importStar(require("./requester"));
|
|
63
|
-
exports.
|
|
61
|
+
exports.CommonTypes = __importStar(require("./types"));
|
|
62
|
+
exports.CommonErrors = __importStar(require("./errors"));
|
|
63
|
+
exports.ConnectSchemas = __importStar(require("./connect/schemas"));
|
package/dist/protos/common.proto
CHANGED
|
@@ -25,13 +25,14 @@ option java_package = "io.routr.location";
|
|
|
25
25
|
option java_outer_classname = "LocationProto";
|
|
26
26
|
option objc_class_prefix = "LC";
|
|
27
27
|
|
|
28
|
+
import "google/protobuf/empty.proto";
|
|
28
29
|
import "common.proto";
|
|
29
30
|
import "processor.proto";
|
|
30
31
|
|
|
31
32
|
service Location {
|
|
32
|
-
rpc AddRoute (AddRouteRequest) returns (
|
|
33
|
+
rpc AddRoute (AddRouteRequest) returns (.google.protobuf.Empty) {}
|
|
33
34
|
rpc FindRoutes (FindRoutesRequest) returns (FindRoutesResponse) {}
|
|
34
|
-
rpc RemoveRoutes (RemoveRoutesRequest) returns (
|
|
35
|
+
rpc RemoveRoutes (RemoveRoutesRequest) returns (.google.protobuf.Empty) {}
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// A binding created by an actual endpoint (Softphone, PBX, Conference System, etc.)
|
package/dist/service.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ObjectProto, ServiceInfo } from "./types";
|
|
2
|
-
import {
|
|
2
|
+
import { ServiceDefinitionNotFoundError } from "./errors";
|
|
3
3
|
export declare const PROCESSOR_OBJECT_PROTO: unknown;
|
|
4
4
|
export declare const LOCATION_OBJECT_PROTO: unknown;
|
|
5
5
|
/**
|
|
@@ -8,7 +8,7 @@ export declare const LOCATION_OBJECT_PROTO: unknown;
|
|
|
8
8
|
* @param {ObjectProt} objectProto - The object proto to load.
|
|
9
9
|
* @return {A} The proto definition.
|
|
10
10
|
*/
|
|
11
|
-
export declare function getObjectProto<A>(objectProto: ObjectProto): A |
|
|
11
|
+
export declare function getObjectProto<A>(objectProto: ObjectProto): A | ServiceDefinitionNotFoundError;
|
|
12
12
|
/**
|
|
13
13
|
* Creates a new service using the given service definition.
|
|
14
14
|
*
|
package/dist/service.js
CHANGED
|
@@ -62,7 +62,7 @@ function getObjectProto(objectProto) {
|
|
|
62
62
|
const objProto = (_b = (_a = grpc.loadPackageDefinition(definitions)) === null || _a === void 0 ? void 0 : _a.fonoster) === null || _b === void 0 ? void 0 : _b.routr[objectProto.name];
|
|
63
63
|
return (objProto === null || objProto === void 0 ? void 0 : objProto[objectProto.version])
|
|
64
64
|
? objProto[objectProto.version]
|
|
65
|
-
: new errors_1.
|
|
65
|
+
: new errors_1.ServiceDefinitionNotFoundError(objectProto.name, objectProto.version);
|
|
66
66
|
}
|
|
67
67
|
exports.getObjectProto = getObjectProto;
|
|
68
68
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ServiceDefinition } from "@grpc/proto-loader";
|
|
2
|
+
import { JsonArray, JsonValue, Struct } from "pb-util/build";
|
|
3
|
+
export type JsonData = Record<string, string | number | boolean | JsonValue | JsonArray | Struct>;
|
|
2
4
|
export declare enum Method {
|
|
3
5
|
UNKNOWN = "UNKNOWN",
|
|
4
6
|
REGISTER = "REGISTER",
|
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.15",
|
|
4
4
|
"description": "Common package",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
12
12
|
"build": "tsc -b tsconfig.json",
|
|
13
|
-
"postbuild": "
|
|
13
|
+
"postbuild": "cp -a src/protos dist/protos && cp -a src/connect/protos dist/connect/protos"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@fonoster/logger": "0.3.18",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/js-yaml": "^4.0.5"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "713d176551252a157b5a7693ef8dba4e3e798dea"
|
|
54
54
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FindParameters, Resource } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Data API for the Connect module.
|
|
4
|
-
*
|
|
5
|
-
* @param {string} apiAddr - The address of the API server
|
|
6
|
-
* @return {Promise<Resource[]>}
|
|
7
|
-
*/
|
|
8
|
-
export declare function dataAPI(apiAddr: string): {
|
|
9
|
-
get: (ref: string) => Promise<Resource>;
|
|
10
|
-
findBy: (request: FindParameters) => Promise<Resource[]>;
|
|
11
|
-
};
|
package/dist/connect/data_api.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.dataAPI = void 0;
|
|
27
|
-
/*
|
|
28
|
-
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
|
-
* http://github.com/fonoster/routr
|
|
30
|
-
*
|
|
31
|
-
* This file is part of Routr
|
|
32
|
-
*
|
|
33
|
-
* Licensed under the MIT License (the "License");
|
|
34
|
-
* you may not use this file except in compliance with
|
|
35
|
-
* the License. You may obtain a copy of the License at
|
|
36
|
-
*
|
|
37
|
-
* https://opensource.org/licenses/MIT
|
|
38
|
-
*
|
|
39
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
-
* See the License for the specific language governing permissions and
|
|
43
|
-
* limitations under the License.
|
|
44
|
-
*/
|
|
45
|
-
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
46
|
-
const protobufUtil = __importStar(require("pb-util"));
|
|
47
|
-
const errors_1 = require("../errors");
|
|
48
|
-
const grpc_client_1 = require("./grpc_client");
|
|
49
|
-
const jsonToStruct = protobufUtil.struct.encode;
|
|
50
|
-
const jsonFromStruct = protobufUtil.struct.decode;
|
|
51
|
-
/**
|
|
52
|
-
* Data API for the Connect module.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} apiAddr - The address of the API server
|
|
55
|
-
* @return {Promise<Resource[]>}
|
|
56
|
-
*/
|
|
57
|
-
function dataAPI(apiAddr) {
|
|
58
|
-
const client = new grpc_client_1.RESOURCES_PROTO.v2draft1.Resources(apiAddr, grpc.credentials.createInsecure());
|
|
59
|
-
return {
|
|
60
|
-
get: (ref) => new Promise((resolve, reject) => {
|
|
61
|
-
client.get({ ref }, (err, response) => {
|
|
62
|
-
if (err) {
|
|
63
|
-
return err.code === grpc.status.UNAVAILABLE
|
|
64
|
-
? reject(new errors_1.ServiceUnavailableError(`api server at ${apiAddr} is unavailable`))
|
|
65
|
-
: reject(err);
|
|
66
|
-
}
|
|
67
|
-
// Convert back to Json
|
|
68
|
-
response.spec = jsonFromStruct(response.spec);
|
|
69
|
-
resolve(response);
|
|
70
|
-
});
|
|
71
|
-
}),
|
|
72
|
-
findBy: (request) => new Promise((resolve, reject) => {
|
|
73
|
-
request.parameters = jsonToStruct(request.parameters);
|
|
74
|
-
client.findBy(request, (err, response) => {
|
|
75
|
-
var _a;
|
|
76
|
-
if (err) {
|
|
77
|
-
return err.code === grpc.status.UNAVAILABLE
|
|
78
|
-
? reject(new errors_1.ServiceUnavailableError(`api server at ${apiAddr} is unavailable`))
|
|
79
|
-
: reject(err);
|
|
80
|
-
}
|
|
81
|
-
const res = (_a = response === null || response === void 0 ? void 0 : response.resources) === null || _a === void 0 ? void 0 : _a.map((resource) => {
|
|
82
|
-
// Convert back to Json
|
|
83
|
-
resource.spec = jsonFromStruct(resource.spec);
|
|
84
|
-
return resource;
|
|
85
|
-
});
|
|
86
|
-
resolve(res);
|
|
87
|
-
});
|
|
88
|
-
})
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
exports.dataAPI = dataAPI;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// TODO: Show a link to were this proto was downloaded from
|
|
2
|
-
syntax = "proto3";
|
|
3
|
-
|
|
4
|
-
package fonoster.routr.resources.v2draft1;
|
|
5
|
-
|
|
6
|
-
import "google/protobuf/struct.proto";
|
|
7
|
-
|
|
8
|
-
// Resources service
|
|
9
|
-
service Resources {
|
|
10
|
-
rpc Create (CreateRequest) returns (Resource) {}
|
|
11
|
-
rpc Update (UpdateRequest) returns (Resource) {}
|
|
12
|
-
rpc Get (GetRequest) returns (Resource) {}
|
|
13
|
-
rpc Delete (DeleteRequest) returns (Empty) {}
|
|
14
|
-
rpc List (ListRequest) returns (ListResponse) {}
|
|
15
|
-
rpc FindBy (FindByRequest) returns (FindByResponse) {}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
message Metadata {
|
|
19
|
-
// The resource's name
|
|
20
|
-
string name = 1;
|
|
21
|
-
// Created at
|
|
22
|
-
int32 create_time = 2;
|
|
23
|
-
// Updated at
|
|
24
|
-
int32 update_time = 3;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
message Resource {
|
|
28
|
-
// The resource's api version
|
|
29
|
-
string apiVersion = 1;
|
|
30
|
-
// The resource's kind
|
|
31
|
-
string kind = 2;
|
|
32
|
-
// The resource's unique identifier
|
|
33
|
-
string ref = 3;
|
|
34
|
-
// The resource's metadata
|
|
35
|
-
Metadata metadata = 4;
|
|
36
|
-
// The resource's data
|
|
37
|
-
.google.protobuf.Struct spec = 5;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
message CreateRequest {
|
|
41
|
-
Metadata metadata = 1;
|
|
42
|
-
.google.protobuf.Struct spec = 2;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
message UpdateRequest {
|
|
46
|
-
Metadata metadata = 1;
|
|
47
|
-
.google.protobuf.Struct spec = 2;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
message DeleteRequest {
|
|
51
|
-
string ref = 1;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
message GetRequest {
|
|
55
|
-
string ref = 1;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
message ListRequest {
|
|
59
|
-
// The maximum number of items in the list
|
|
60
|
-
int32 page_size = 1;
|
|
61
|
-
|
|
62
|
-
// The next_page_token value returned from the previous request, if any
|
|
63
|
-
string page_token = 2;
|
|
64
|
-
|
|
65
|
-
// The filter to apply to the list
|
|
66
|
-
string filter = 3;
|
|
67
|
-
|
|
68
|
-
// The type of resource to list
|
|
69
|
-
string kind = 4;
|
|
70
|
-
|
|
71
|
-
// Level of detail of the individual entities (reserved)
|
|
72
|
-
View view = 5;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
message ListResponse {
|
|
76
|
-
// List of Resources
|
|
77
|
-
repeated Resource resources = 1;
|
|
78
|
-
|
|
79
|
-
// Token to retrieve the next page of results, or empty if there are no more results in the list
|
|
80
|
-
string next_page_token = 2;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
message FindByRequest {
|
|
84
|
-
// The type of resource to find
|
|
85
|
-
string kind = 1;
|
|
86
|
-
|
|
87
|
-
// Search criteria for the request
|
|
88
|
-
string criteria = 2;
|
|
89
|
-
|
|
90
|
-
// Parameters to apply in combination with the search criteria
|
|
91
|
-
.google.protobuf.Struct parameters = 3;
|
|
92
|
-
|
|
93
|
-
// Level of detail of the individual entities (reserved)
|
|
94
|
-
View view = 4;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
message FindByResponse {
|
|
98
|
-
// List of Resources
|
|
99
|
-
repeated Resource resources = 1;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
enum View {
|
|
103
|
-
BASIC = 0;
|
|
104
|
-
STANDARD = 1;
|
|
105
|
-
FULL = 2;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
message Empty {}
|