@pgds/api-interface 1.2.5
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/README.md +410 -0
- package/client/FairtrailClient.d.ts +38 -0
- package/client/FairtrailClient.js +219 -0
- package/client/FairtrailClient.js.map +1 -0
- package/client/HttpClient.d.ts +36 -0
- package/client/HttpClient.js +360 -0
- package/client/HttpClient.js.map +1 -0
- package/client/index.d.ts +3 -0
- package/client/index.js +8 -0
- package/client/index.js.map +1 -0
- package/constants/index.d.ts +8 -0
- package/constants/index.js +13 -0
- package/constants/index.js.map +1 -0
- package/errors/index.d.ts +1 -0
- package/errors/index.js +72 -0
- package/errors/index.js.map +1 -0
- package/index.d.ts +7 -0
- package/index.js +23 -0
- package/lib/auth/mustbeConfig.d.ts +13 -0
- package/lib/auth/mustbeConfig.js +167 -0
- package/lib/auth/mustbeConfig.js.map +1 -0
- package/lib/constants/constants.d.ts +3 -0
- package/lib/constants/constants.js +8 -0
- package/lib/constants/constants.js.map +1 -0
- package/lib/index.d.ts +255 -0
- package/lib/index.js +462 -0
- package/lib/index.js.map +1 -0
- package/lib/models/Http.d.ts +62 -0
- package/lib/models/Http.js +3 -0
- package/lib/models/Http.js.map +1 -0
- package/lib/models/ReqUser.d.ts +10 -0
- package/lib/models/ReqUser.js +3 -0
- package/lib/models/ReqUser.js.map +1 -0
- package/lib/server/server.d.ts +13 -0
- package/lib/server/server.js +154 -0
- package/lib/server/server.js.map +1 -0
- package/lib/utils/asyncHooks.d.ts +28 -0
- package/lib/utils/asyncHooks.js +99 -0
- package/lib/utils/asyncHooks.js.map +1 -0
- package/lib/utils/jsonSchemaUtils.d.ts +14 -0
- package/lib/utils/jsonSchemaUtils.js +187 -0
- package/lib/utils/jsonSchemaUtils.js.map +1 -0
- package/lib/utils/logger.d.ts +5 -0
- package/lib/utils/logger.js +33 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/urlUtils.d.ts +1 -0
- package/lib/utils/urlUtils.js +14 -0
- package/lib/utils/urlUtils.js.map +1 -0
- package/package.json +104 -0
- package/types/hiot.d.ts +368 -0
- package/types/mustbe/config/activities.d.ts +11 -0
- package/types/mustbe/config/index.d.ts +77 -0
- package/types/mustbe/config/parameter-map.d.ts +8 -0
- package/types/mustbe/config/route-helpers.d.ts +17 -0
- package/types/mustbe/config/user-identity.d.ts +7 -0
- package/types/mustbe/core.d.ts +23 -0
- package/types/mustbe/identities/userIdentity.d.ts +10 -0
- package/types/mustbe/index.d.ts +6 -0
- package/types/mustbe/principals/index.d.ts +10 -0
- package/types/mustbe/registry.d.ts +11 -0
- package/types/mustbe/routeHelpers/index.d.ts +20 -0
- package/types/mustbe/verifier/index.d.ts +10 -0
- package/utils/index.d.ts +13 -0
- package/utils/index.js +32 -0
- package/utils/index.js.map +1 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
47
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
50
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
51
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
52
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
56
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
57
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
58
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
59
|
+
function step(op) {
|
|
60
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
62
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
63
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
64
|
+
switch (op[0]) {
|
|
65
|
+
case 0: case 1: t = op; break;
|
|
66
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
67
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
68
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
69
|
+
default:
|
|
70
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
71
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
72
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
73
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
74
|
+
if (t[2]) _.ops.pop();
|
|
75
|
+
_.trys.pop(); continue;
|
|
76
|
+
}
|
|
77
|
+
op = body.call(thisArg, _);
|
|
78
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
83
|
+
var t = {};
|
|
84
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
85
|
+
t[p] = s[p];
|
|
86
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
87
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
88
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
89
|
+
t[p[i]] = s[p[i]];
|
|
90
|
+
}
|
|
91
|
+
return t;
|
|
92
|
+
};
|
|
93
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
94
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
95
|
+
if (ar || !(i in from)) {
|
|
96
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
97
|
+
ar[i] = from[i];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
101
|
+
};
|
|
102
|
+
var _a;
|
|
103
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
104
|
+
exports.endpointMetadata = exports.Method = void 0;
|
|
105
|
+
exports.get = get;
|
|
106
|
+
exports.post = post;
|
|
107
|
+
exports.put = put;
|
|
108
|
+
exports.patch = patch;
|
|
109
|
+
exports.del = del;
|
|
110
|
+
exports.internal = internal;
|
|
111
|
+
exports.getApiOptions = getApiOptions;
|
|
112
|
+
exports.setupApiInterface = setupApiInterface;
|
|
113
|
+
exports.setupInterfaceLegacy = setupInterfaceLegacy;
|
|
114
|
+
exports.getServiceName = getServiceName;
|
|
115
|
+
var axios_1 = require("axios");
|
|
116
|
+
var fs = __importStar(require("fs/promises"));
|
|
117
|
+
var restifyErrors = __importStar(require("restify-errors"));
|
|
118
|
+
var mustbeConfig_1 = require("./auth/mustbeConfig");
|
|
119
|
+
var constants_1 = require("./constants/constants");
|
|
120
|
+
var server_1 = require("./server/server");
|
|
121
|
+
var asyncHooks_1 = require("./utils/asyncHooks");
|
|
122
|
+
var jsonSchemaUtils_1 = require("./utils/jsonSchemaUtils");
|
|
123
|
+
var logger_1 = __importStar(require("./utils/logger"));
|
|
124
|
+
var urlUtils_1 = require("./utils/urlUtils");
|
|
125
|
+
// the above module as ts types
|
|
126
|
+
var mustbe = require("mustbe");
|
|
127
|
+
var serverLogger;
|
|
128
|
+
var Method;
|
|
129
|
+
(function (Method) {
|
|
130
|
+
Method["Post"] = "post";
|
|
131
|
+
Method["Get"] = "get";
|
|
132
|
+
Method["Put"] = "put";
|
|
133
|
+
Method["Patch"] = "patch";
|
|
134
|
+
Method["Del"] = "del";
|
|
135
|
+
Method["Head"] = "head";
|
|
136
|
+
Method["Options"] = "options";
|
|
137
|
+
})(Method || (exports.Method = Method = {}));
|
|
138
|
+
function get(options) {
|
|
139
|
+
return registerEndpoint(__assign(__assign({}, options), { method: Method.Get }));
|
|
140
|
+
}
|
|
141
|
+
function post(options) {
|
|
142
|
+
return registerEndpoint(__assign(__assign({}, options), { method: Method.Post }));
|
|
143
|
+
}
|
|
144
|
+
function put(options) {
|
|
145
|
+
return registerEndpoint(__assign(__assign({}, options), { method: Method.Put }));
|
|
146
|
+
}
|
|
147
|
+
function patch(options) {
|
|
148
|
+
return registerEndpoint(__assign(__assign({}, options), { method: Method.Patch }));
|
|
149
|
+
}
|
|
150
|
+
function del(options) {
|
|
151
|
+
return registerEndpoint(__assign(__assign({}, options), { method: Method.Del }));
|
|
152
|
+
}
|
|
153
|
+
function registerInternal(options) {
|
|
154
|
+
return registerEndpoint(__assign(__assign({}, options), { internal: true }));
|
|
155
|
+
}
|
|
156
|
+
/** Internal endpoints are not available through the API
|
|
157
|
+
* @deprecated Use internal.get, internal.post, internal.put, internal.patch, internal.del instead
|
|
158
|
+
*/
|
|
159
|
+
function internal(options) {
|
|
160
|
+
return registerInternal(options);
|
|
161
|
+
}
|
|
162
|
+
/** Internal endpoints are not available through the API */
|
|
163
|
+
internal.get = function (options) { return registerInternal(__assign(__assign({}, options), { method: Method.Get })); };
|
|
164
|
+
/** Internal endpoints are not available through the API */
|
|
165
|
+
internal.post = function (options) {
|
|
166
|
+
return registerInternal(__assign(__assign({}, options), { method: Method.Post }));
|
|
167
|
+
};
|
|
168
|
+
/** Internal endpoints are not available through the API */
|
|
169
|
+
internal.put = function (options) { return registerInternal(__assign(__assign({}, options), { method: Method.Put })); };
|
|
170
|
+
/** Internal endpoints are not available through the API */
|
|
171
|
+
internal.patch = function (options) {
|
|
172
|
+
return registerInternal(__assign(__assign({}, options), { method: Method.Patch }));
|
|
173
|
+
};
|
|
174
|
+
/** Internal endpoints are not available through the API */
|
|
175
|
+
internal.del = function (options) { return registerInternal(__assign(__assign({}, options), { method: Method.Del })); };
|
|
176
|
+
exports.endpointMetadata = (_a = {},
|
|
177
|
+
_a[Method.Post] = {},
|
|
178
|
+
_a[Method.Get] = {},
|
|
179
|
+
_a[Method.Put] = {},
|
|
180
|
+
_a[Method.Patch] = {},
|
|
181
|
+
_a[Method.Del] = {},
|
|
182
|
+
_a[Method.Head] = {},
|
|
183
|
+
_a.options = {},
|
|
184
|
+
_a);
|
|
185
|
+
function registerMetadataEndpoint() {
|
|
186
|
+
var _this = this;
|
|
187
|
+
var metadataEndpoint = registerEndpoint({
|
|
188
|
+
path: "/".concat(apiOptions.serviceName, "/metadata"),
|
|
189
|
+
method: Method.Get,
|
|
190
|
+
addToMetadata: false,
|
|
191
|
+
version: "",
|
|
192
|
+
requestHandler: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
// prepare metadata here so that we get schemas and not just ids in the response
|
|
195
|
+
return [2 /*return*/, {
|
|
196
|
+
body: exports.endpointMetadata,
|
|
197
|
+
}];
|
|
198
|
+
});
|
|
199
|
+
}); },
|
|
200
|
+
});
|
|
201
|
+
metadataEndpoint();
|
|
202
|
+
}
|
|
203
|
+
function registerEndpoint(options) {
|
|
204
|
+
var _this = this;
|
|
205
|
+
var _a;
|
|
206
|
+
var requestHandler = options.requestHandler, opts = options.opts, _b = options.addToMetadata, addToMetadata = _b === void 0 ? true : _b, metadata = __rest(options, ["requestHandler", "opts", "addToMetadata"]);
|
|
207
|
+
if (addToMetadata) {
|
|
208
|
+
exports.endpointMetadata[options.method][options.path] = metadata;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* @param legacyServer only required for legacy mode
|
|
212
|
+
*/
|
|
213
|
+
var fn = function (legacyServer) {
|
|
214
|
+
var _a;
|
|
215
|
+
var _b;
|
|
216
|
+
if (apiOptions.legacyMode && !legacyServer) {
|
|
217
|
+
throw new Error("Passing in server to the endpoint is required when running in legacy mode");
|
|
218
|
+
}
|
|
219
|
+
serverLogger.info("Registering endpoint: ".concat(options.method.toUpperCase(), " ").concat(options.path));
|
|
220
|
+
var routeHelpers = mustbe.routeHelpers();
|
|
221
|
+
var routeOptions = {
|
|
222
|
+
path: (0, urlUtils_1.route)((_b = options.version) !== null && _b !== void 0 ? _b : apiVersion, options.path, options.internal),
|
|
223
|
+
};
|
|
224
|
+
if (options.opts) {
|
|
225
|
+
routeOptions = __assign(__assign({}, routeOptions), options.opts);
|
|
226
|
+
}
|
|
227
|
+
var requestHandlers = [];
|
|
228
|
+
if (options.authenticated) {
|
|
229
|
+
requestHandlers.push(routeHelpers.authenticated());
|
|
230
|
+
}
|
|
231
|
+
if (options.authorized) {
|
|
232
|
+
var activities = Array.isArray(options.authorized) ? options.authorized : [options.authorized];
|
|
233
|
+
requestHandlers.push(routeHelpers.authorized(activities));
|
|
234
|
+
}
|
|
235
|
+
if (options.requestHandlers) {
|
|
236
|
+
requestHandlers.push.apply(requestHandlers, options.requestHandlers);
|
|
237
|
+
}
|
|
238
|
+
if (options.urlParamsSchema) {
|
|
239
|
+
requestHandlers.push(getSchemaValidationHandler(options.urlParamsSchema, jsonSchemaUtils_1.RequestKey.Params));
|
|
240
|
+
}
|
|
241
|
+
if (options.requestSchema) {
|
|
242
|
+
requestHandlers.push(getSchemaValidationHandler(options.requestSchema, jsonSchemaUtils_1.RequestKey.Body));
|
|
243
|
+
}
|
|
244
|
+
if (options.querySchema) {
|
|
245
|
+
requestHandlers.push(getSchemaValidationHandler(options.querySchema, jsonSchemaUtils_1.RequestKey.Query));
|
|
246
|
+
}
|
|
247
|
+
var responseSchemas = [];
|
|
248
|
+
if (constants_1.CI) {
|
|
249
|
+
responseSchemas = (0, jsonSchemaUtils_1.prepareResponseSchemas)(options);
|
|
250
|
+
}
|
|
251
|
+
requestHandlers.push(function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
252
|
+
var err_1;
|
|
253
|
+
var _this = this;
|
|
254
|
+
return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
256
|
+
case 0:
|
|
257
|
+
_a.trys.push([0, 2, , 3]);
|
|
258
|
+
return [4 /*yield*/, (0, asyncHooks_1.runWithRequestContext)(req, function () { return __awaiter(_this, void 0, void 0, function () {
|
|
259
|
+
var response, header;
|
|
260
|
+
var _a;
|
|
261
|
+
return __generator(this, function (_b) {
|
|
262
|
+
switch (_b.label) {
|
|
263
|
+
case 0: return [4 /*yield*/, options.requestHandler(req, res, next)];
|
|
264
|
+
case 1:
|
|
265
|
+
response = _b.sent();
|
|
266
|
+
if (response) {
|
|
267
|
+
res.statusCode = (_a = response.status) !== null && _a !== void 0 ? _a : 200;
|
|
268
|
+
if (response.headers) {
|
|
269
|
+
for (header in response.headers) {
|
|
270
|
+
res.header(header, response.headers[header]);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (response.body) {
|
|
274
|
+
if (constants_1.CI && !!responseSchemas.length) {
|
|
275
|
+
(0, jsonSchemaUtils_1.validateResponseBody)(responseSchemas, response.body);
|
|
276
|
+
}
|
|
277
|
+
res.json(response.body);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
res.end();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return [2 /*return*/];
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}); })];
|
|
287
|
+
case 1:
|
|
288
|
+
_a.sent();
|
|
289
|
+
return [3 /*break*/, 3];
|
|
290
|
+
case 2:
|
|
291
|
+
err_1 = _a.sent();
|
|
292
|
+
return [2 /*return*/, handleErrors(err_1, next)];
|
|
293
|
+
case 3: return [2 /*return*/];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}); });
|
|
297
|
+
var pendingRoute = {
|
|
298
|
+
method: options.method,
|
|
299
|
+
opts: routeOptions,
|
|
300
|
+
handlers: requestHandlers,
|
|
301
|
+
};
|
|
302
|
+
// @ts-ignore
|
|
303
|
+
(_a = (legacyServer !== null && legacyServer !== void 0 ? legacyServer : server_1.server))[pendingRoute.method].apply(_a, __spreadArray([pendingRoute.opts], pendingRoute.handlers, false));
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Makes it possible to access the requestHandler through the exported function.
|
|
307
|
+
* If you need to test the function separately, without starting the server
|
|
308
|
+
*/
|
|
309
|
+
fn.requestHandler = options.requestHandler;
|
|
310
|
+
/** Endpoint's full path (including any version number and internal prefix) */
|
|
311
|
+
fn.PATH = (0, urlUtils_1.route)((_a = options.version) !== null && _a !== void 0 ? _a : apiVersion, options.path, options.internal);
|
|
312
|
+
/** Unregister the endpoint (mostly used for testing) */
|
|
313
|
+
fn.unregister = function () {
|
|
314
|
+
var _a;
|
|
315
|
+
var route = Object.entries(server_1.server.router.getRoutes()).find(function (_a) {
|
|
316
|
+
var _key = _a[0], route = _a[1];
|
|
317
|
+
return route.spec.path === fn.PATH;
|
|
318
|
+
});
|
|
319
|
+
var routeName = (_a = route === null || route === void 0 ? void 0 : route[1]) === null || _a === void 0 ? void 0 : _a.name;
|
|
320
|
+
if (routeName) {
|
|
321
|
+
server_1.server.router.unmount(routeName);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
return fn;
|
|
325
|
+
}
|
|
326
|
+
function handleErrors(err, next) {
|
|
327
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
328
|
+
try {
|
|
329
|
+
if (constants_1.CI) {
|
|
330
|
+
console.log(require("util").inspect(err, null, null, true));
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
logger_1.default.error(err);
|
|
334
|
+
}
|
|
335
|
+
if (err instanceof restifyErrors.HttpError) {
|
|
336
|
+
return next(err);
|
|
337
|
+
}
|
|
338
|
+
if ((0, axios_1.isAxiosError)(err)) {
|
|
339
|
+
var status = ((_a = err.response) === null || _a === void 0 ? void 0 : _a.status) || 500;
|
|
340
|
+
var message = ((_c = (_b = err.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.message) || err.message;
|
|
341
|
+
return next(new restifyErrors.HttpError({
|
|
342
|
+
statusCode: status,
|
|
343
|
+
message: message,
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
var statusCode = err.statusCode ||
|
|
347
|
+
err.status ||
|
|
348
|
+
((_d = err.body) === null || _d === void 0 ? void 0 : _d.statusCode) ||
|
|
349
|
+
((_e = err.body) === null || _e === void 0 ? void 0 : _e.status) ||
|
|
350
|
+
((_f = err.message) === null || _f === void 0 ? void 0 : _f.statusCode) ||
|
|
351
|
+
((_g = err.message) === null || _g === void 0 ? void 0 : _g.status) ||
|
|
352
|
+
(typeof err.message === "string" && ((_h = err.message.match(/\b([45]\d{2})\b/)) === null || _h === void 0 ? void 0 : _h[1])) ||
|
|
353
|
+
500;
|
|
354
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
355
|
+
return next(restifyErrors.makeErrFromCode(statusCode, err.message));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
catch (err) { }
|
|
359
|
+
/* Last resort */
|
|
360
|
+
return next(new restifyErrors.InternalServerError(err));
|
|
361
|
+
}
|
|
362
|
+
function getSchemaValidationHandler(schema, requestKey) {
|
|
363
|
+
if (typeof schema === "string") {
|
|
364
|
+
schema = (0, jsonSchemaUtils_1.getSchema)(schema);
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
var validatedSchema = (0, jsonSchemaUtils_1.jsonSchemaValidationMiddleware)(schema, requestKey);
|
|
368
|
+
return validatedSchema;
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
console.error(err);
|
|
372
|
+
throw err;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
var apiVersion = "v1";
|
|
376
|
+
var apiOptions = {};
|
|
377
|
+
function getApiOptions() {
|
|
378
|
+
return apiOptions;
|
|
379
|
+
}
|
|
380
|
+
function setupApiInterface(options) {
|
|
381
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
382
|
+
var opts;
|
|
383
|
+
return __generator(this, function (_a) {
|
|
384
|
+
switch (_a.label) {
|
|
385
|
+
case 0:
|
|
386
|
+
opts = __assign(__assign({}, options), { legacyMode: false });
|
|
387
|
+
return [4 /*yield*/, setup(opts)];
|
|
388
|
+
case 1: return [2 /*return*/, (_a.sent())];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Legacy option to enable legacy mode where the server is started with hiot-restify5.
|
|
395
|
+
* Should only be used (as a temporary solution) where the new server setup is not possible without a complete refactor
|
|
396
|
+
*/
|
|
397
|
+
function setupInterfaceLegacy(options) {
|
|
398
|
+
var _this = this;
|
|
399
|
+
var opts = __assign(__assign({}, options), { legacyMode: true });
|
|
400
|
+
return function (locator) { return __awaiter(_this, void 0, void 0, function () {
|
|
401
|
+
return __generator(this, function (_a) {
|
|
402
|
+
switch (_a.label) {
|
|
403
|
+
case 0: return [4 /*yield*/, setup(opts)];
|
|
404
|
+
case 1:
|
|
405
|
+
_a.sent();
|
|
406
|
+
return [2 /*return*/, locator];
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
}); };
|
|
410
|
+
}
|
|
411
|
+
var serviceName = "";
|
|
412
|
+
function getServiceName() {
|
|
413
|
+
return serviceName;
|
|
414
|
+
}
|
|
415
|
+
function setup(options) {
|
|
416
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
417
|
+
var inApiVersion, port, serviceLogLevel, inServiceName, typescript, onUncaughtException, schemaBasePath, _a, shouldRegisterMetadataEndpoint, legacyMode, maxParamLength, files, err_2, server_2;
|
|
418
|
+
return __generator(this, function (_b) {
|
|
419
|
+
switch (_b.label) {
|
|
420
|
+
case 0:
|
|
421
|
+
apiOptions = options;
|
|
422
|
+
inApiVersion = options.apiVersion, port = options.port, serviceLogLevel = options.serviceLogLevel, inServiceName = options.serviceName, typescript = options.typescript, onUncaughtException = options.onUncaughtException, schemaBasePath = options.schemaBasePath, _a = options.registerMetadataEndpoint, shouldRegisterMetadataEndpoint = _a === void 0 ? true : _a, legacyMode = options.legacyMode, maxParamLength = options.maxParamLength;
|
|
423
|
+
apiVersion = inApiVersion;
|
|
424
|
+
serviceName = inServiceName;
|
|
425
|
+
if (!(typescript &&
|
|
426
|
+
/** This check is only applicable during tests, so it's only run once */
|
|
427
|
+
jsonSchemaUtils_1.schemaCache.size === 0)) return [3 /*break*/, 4];
|
|
428
|
+
_b.label = 1;
|
|
429
|
+
case 1:
|
|
430
|
+
_b.trys.push([1, 3, , 4]);
|
|
431
|
+
return [4 /*yield*/, fs.readdir(schemaBasePath !== null && schemaBasePath !== void 0 ? schemaBasePath : constants_1.SCHEMA_BASE_PATH)];
|
|
432
|
+
case 2:
|
|
433
|
+
files = _b.sent();
|
|
434
|
+
(0, jsonSchemaUtils_1.getSchemas)(files.map(function (file) { return file.replace(".ts", ""); }));
|
|
435
|
+
return [3 /*break*/, 4];
|
|
436
|
+
case 3:
|
|
437
|
+
err_2 = _b.sent();
|
|
438
|
+
if (err_2.code === "ENOENT") {
|
|
439
|
+
console.warn("".concat(constants_1.SCHEMA_BASE_PATH, " not found. If service has no schemas, this is expected: ").concat(err_2.message, ". "));
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
throw err_2;
|
|
443
|
+
}
|
|
444
|
+
return [3 /*break*/, 4];
|
|
445
|
+
case 4:
|
|
446
|
+
(0, logger_1.setupLogger)(serviceName, serviceLogLevel);
|
|
447
|
+
serverLogger = (0, logger_1.createLogger)("".concat(serviceName, ":hiot-api-interface:server"));
|
|
448
|
+
if (!!legacyMode) return [3 /*break*/, 6];
|
|
449
|
+
(0, mustbeConfig_1.configureMustBe)();
|
|
450
|
+
return [4 /*yield*/, (0, server_1.startServer)({ serviceName: serviceName, port: port, onUncaughtException: onUncaughtException, maxParamLength: maxParamLength })];
|
|
451
|
+
case 5:
|
|
452
|
+
server_2 = _b.sent();
|
|
453
|
+
if (shouldRegisterMetadataEndpoint) {
|
|
454
|
+
registerMetadataEndpoint();
|
|
455
|
+
}
|
|
456
|
+
return [2 /*return*/, server_2];
|
|
457
|
+
case 6: return [2 /*return*/];
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,kBAKC;AAED,oBAKC;AAED,kBAKC;AAED,sBAKC;AAED,kBAKC;AAYD,4BAEC;AAgXD,sCAEC;AAED,8CAOC;AAMD,oDAaC;AAID,wCAEC;AApfD,+BAAqC;AAErC,8CAAkC;AAGlC,4DAAgD;AAEhD,oDAAsD;AACtD,mDAA6D;AAE7D,0CAAsD;AACtD,iDAA2D;AAC3D,2DAQiC;AACjC,uDAAmE;AACnE,6CAAyC;AASzC,+BAA+B;AAE/B,IAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjC,IAAI,YAAoB,CAAC;AAEzB,IAAY,MAQX;AAR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as RestifyRequest, Response as RestifyResponse, Next as RestifyNext } from "restify";
|
|
3
|
+
export interface Request<BodyParams = Record<string, any>, UrlParams = Record<string, string>, QueryParams = any> extends RestifyRequest {
|
|
4
|
+
body: BodyParams;
|
|
5
|
+
params: UrlParams;
|
|
6
|
+
user: ReqUser;
|
|
7
|
+
query: QueryParams;
|
|
8
|
+
}
|
|
9
|
+
export interface Next extends RestifyNext {
|
|
10
|
+
(err?: any): void;
|
|
11
|
+
}
|
|
12
|
+
export interface Response<Body = Record<string, any>> extends RestifyResponse {
|
|
13
|
+
/**
|
|
14
|
+
* short hand method for:
|
|
15
|
+
* res.contentType = 'json';
|
|
16
|
+
* res.send({hello: 'world'});
|
|
17
|
+
* @param code http status code
|
|
18
|
+
* @param body value to json.stringify
|
|
19
|
+
* @param [headers] headers to set on the response
|
|
20
|
+
*/
|
|
21
|
+
json(code: number, body: Body, headers?: {
|
|
22
|
+
[header: string]: string;
|
|
23
|
+
}): any;
|
|
24
|
+
/**
|
|
25
|
+
* short hand method for:
|
|
26
|
+
* res.contentType = 'json';
|
|
27
|
+
* res.send({hello: 'world'});
|
|
28
|
+
* @param code http status code
|
|
29
|
+
*/
|
|
30
|
+
json(code: number): any;
|
|
31
|
+
/**
|
|
32
|
+
* short hand method for:
|
|
33
|
+
* res.contentType = 'json';
|
|
34
|
+
* res.send({hello: 'world'});
|
|
35
|
+
* @param body value to json.stringify
|
|
36
|
+
* @param [headers] headers to set on the response
|
|
37
|
+
*/
|
|
38
|
+
json(body: Body, headers?: {
|
|
39
|
+
[header: string]: string;
|
|
40
|
+
}): any;
|
|
41
|
+
/**
|
|
42
|
+
* sends the response object. pass through to internal __send that uses a
|
|
43
|
+
* formatter based on the content-type header.
|
|
44
|
+
* @param [code] http status code
|
|
45
|
+
* @param [body] the content to send
|
|
46
|
+
* @param [headers] any add'l headers to set
|
|
47
|
+
* @returns the response object
|
|
48
|
+
*/
|
|
49
|
+
send(code?: number, body?: Body, headers?: {
|
|
50
|
+
[header: string]: string;
|
|
51
|
+
}): any;
|
|
52
|
+
/**
|
|
53
|
+
* sends the response object. pass through to internal __send that uses a
|
|
54
|
+
* formatter based on the content-type header.
|
|
55
|
+
* @param [body] the content to send
|
|
56
|
+
* @param [headers] any add'l headers to set
|
|
57
|
+
* @returns the response object
|
|
58
|
+
*/
|
|
59
|
+
send(body?: Body, headers?: {
|
|
60
|
+
[header: string]: string;
|
|
61
|
+
}): any;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Http.js","sourceRoot":"","sources":["Http.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ReqUser {
|
|
2
|
+
userId: string;
|
|
3
|
+
activities: Record<string, boolean>;
|
|
4
|
+
/** The organization id of the user */
|
|
5
|
+
organizationId: string;
|
|
6
|
+
/** Child organizations withing the organization hierarchy */
|
|
7
|
+
childOrganizationIds: string[];
|
|
8
|
+
/** The user account currently active for this login */
|
|
9
|
+
activeLogin: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReqUser.js","sourceRoot":"","sources":["ReqUser.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Server } from "restify";
|
|
2
|
+
interface ServerOptions {
|
|
3
|
+
serviceName: string;
|
|
4
|
+
port: number;
|
|
5
|
+
onUncaughtException?: (err: Error) => void;
|
|
6
|
+
/** Legacy option to register routes the old way */
|
|
7
|
+
routes?: (server: Server) => void;
|
|
8
|
+
maxParamLength?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare const server: Server;
|
|
11
|
+
export declare const closeServer: () => any;
|
|
12
|
+
export declare function startServer({ serviceName, port, onUncaughtException, maxParamLength }: ServerOptions): Promise<Server>;
|
|
13
|
+
export {};
|