@docbrasil/api-systemmanager 1.0.89 → 1.0.91
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/api/admin/doctypes.js +76 -76
- package/api/admin/document.js +332 -332
- package/api/admin/form.js +151 -151
- package/api/admin/index.js +46 -46
- package/api/admin/list.js +133 -133
- package/api/admin/message.js +194 -194
- package/api/admin/notification.js +233 -233
- package/api/admin/organization.js +124 -124
- package/api/admin/plugin.js +116 -116
- package/api/admin/policy.js +78 -78
- package/api/admin/processes.js +370 -370
- package/api/admin/task.js +125 -125
- package/api/admin/user.js +185 -185
- package/api/dispatch.js +101 -101
- package/api/general/geoLocation.js +88 -88
- package/api/general/index.js +22 -22
- package/api/login.js +267 -267
- package/api/session.js +85 -85
- package/api/user/datasource.js +144 -144
- package/api/user/document.js +730 -730
- package/api/user/index.js +39 -39
- package/api/user/notification.js +101 -101
- package/api/user/organization.js +230 -230
- package/api/user/process.js +191 -191
- package/api/user/register.js +205 -205
- package/api/user/task.js +201 -201
- package/api/user/task_available.js +135 -135
- package/api/user/user.js +287 -287
- package/api/utils/cypher.js +37 -37
- package/api/utils/promises.js +118 -118
- package/bundleRollup.js +158 -158
- package/dist/bundle.cjs +4875 -4875
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +674 -336
- package/doc.md +653 -653
- package/helper/boom.js +487 -487
- package/helper/cryptojs.js +6067 -6067
- package/index.js +85 -85
- package/package-lock.json +4635 -4635
- package/package.json +68 -68
- package/readme.md +25 -25
- package/tests/admin/document.spec.js +45 -45
- package/tests/admin/form.spec.js +74 -74
- package/tests/admin/list.spec.js +86 -86
- package/tests/admin/message.js +92 -92
- package/tests/admin/notification.spec.js +174 -174
- package/tests/admin/pluginspec..js +71 -71
- package/tests/admin/policy.spec.js +71 -71
- package/tests/admin/processes.spec.js +119 -119
- package/tests/admin/users.spec.js +127 -127
- package/tests/documents.spec.js +164 -164
- package/tests/login.spec.js +91 -91
- package/tests/session.spec..js +58 -58
- package/tests/user/documents.js +164 -164
- package/tests/user/organization.js +122 -122
- package/tests/user/process.js +71 -71
- package/tests/user/user.js +88 -88
package/helper/boom.js
CHANGED
|
@@ -1,487 +1,487 @@
|
|
|
1
|
-
import * _ from 'lodash';
|
|
2
|
-
|
|
3
|
-
const Hoek = {
|
|
4
|
-
clone: message => _.clone(message),
|
|
5
|
-
assert: (condition, ...args) => {
|
|
6
|
-
if (condition) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (args.length === 1 &&
|
|
11
|
-
args[0] instanceof Error) {
|
|
12
|
-
|
|
13
|
-
throw args[0];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
throw new Error(args);
|
|
17
|
-
},
|
|
18
|
-
escapeHeaderAttribute: attribute => {
|
|
19
|
-
return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const internals = {
|
|
25
|
-
codes: new Map([
|
|
26
|
-
[100, 'Continue'],
|
|
27
|
-
[101, 'Switching Protocols'],
|
|
28
|
-
[102, 'Processing'],
|
|
29
|
-
[200, 'OK'],
|
|
30
|
-
[201, 'Created'],
|
|
31
|
-
[202, 'Accepted'],
|
|
32
|
-
[203, 'Non-Authoritative Information'],
|
|
33
|
-
[204, 'No Content'],
|
|
34
|
-
[205, 'Reset Content'],
|
|
35
|
-
[206, 'Partial Content'],
|
|
36
|
-
[207, 'Multi-Status'],
|
|
37
|
-
[300, 'Multiple Choices'],
|
|
38
|
-
[301, 'Moved Permanently'],
|
|
39
|
-
[302, 'Moved Temporarily'],
|
|
40
|
-
[303, 'See Other'],
|
|
41
|
-
[304, 'Not Modified'],
|
|
42
|
-
[305, 'Use Proxy'],
|
|
43
|
-
[307, 'Temporary Redirect'],
|
|
44
|
-
[400, 'Bad Request'],
|
|
45
|
-
[401, 'Unauthorized'],
|
|
46
|
-
[402, 'Payment Required'],
|
|
47
|
-
[403, 'Forbidden'],
|
|
48
|
-
[404, 'Not Found'],
|
|
49
|
-
[405, 'Method Not Allowed'],
|
|
50
|
-
[406, 'Not Acceptable'],
|
|
51
|
-
[407, 'Proxy Authentication Required'],
|
|
52
|
-
[408, 'Request Time-out'],
|
|
53
|
-
[409, 'Conflict'],
|
|
54
|
-
[410, 'Gone'],
|
|
55
|
-
[411, 'Length Required'],
|
|
56
|
-
[412, 'Precondition Failed'],
|
|
57
|
-
[413, 'Request Entity Too Large'],
|
|
58
|
-
[414, 'Request-URI Too Large'],
|
|
59
|
-
[415, 'Unsupported Media Type'],
|
|
60
|
-
[416, 'Requested Range Not Satisfiable'],
|
|
61
|
-
[417, 'Expectation Failed'],
|
|
62
|
-
[418, 'I\'m a teapot'],
|
|
63
|
-
[422, 'Unprocessable Entity'],
|
|
64
|
-
[423, 'Locked'],
|
|
65
|
-
[424, 'Failed Dependency'],
|
|
66
|
-
[425, 'Too Early'],
|
|
67
|
-
[426, 'Upgrade Required'],
|
|
68
|
-
[428, 'Precondition Required'],
|
|
69
|
-
[429, 'Too Many Requests'],
|
|
70
|
-
[431, 'Request Header Fields Too Large'],
|
|
71
|
-
[451, 'Unavailable For Legal Reasons'],
|
|
72
|
-
[500, 'Internal Server Error'],
|
|
73
|
-
[501, 'Not Implemented'],
|
|
74
|
-
[502, 'Bad Gateway'],
|
|
75
|
-
[503, 'Service Unavailable'],
|
|
76
|
-
[504, 'Gateway Time-out'],
|
|
77
|
-
[505, 'HTTP Version Not Supported'],
|
|
78
|
-
[506, 'Variant Also Negotiates'],
|
|
79
|
-
[507, 'Insufficient Storage'],
|
|
80
|
-
[509, 'Bandwidth Limit Exceeded'],
|
|
81
|
-
[510, 'Not Extended'],
|
|
82
|
-
[511, 'Network Authentication Required']
|
|
83
|
-
])
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
exports.Boom = class extends Error {
|
|
88
|
-
|
|
89
|
-
constructor(message, options = {}) {
|
|
90
|
-
|
|
91
|
-
if (message instanceof Error) {
|
|
92
|
-
return exports.boomify(Hoek.clone(message), options);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const { statusCode = 500, data = null, ctor = exports.Boom } = options;
|
|
96
|
-
const error = new Error(message ? message : undefined); // Avoids settings null message
|
|
97
|
-
Error.captureStackTrace(error, ctor); // Filter the stack to our external API
|
|
98
|
-
error.data = data;
|
|
99
|
-
const boom = internals.initialize(error, statusCode);
|
|
100
|
-
|
|
101
|
-
Object.defineProperty(boom, 'typeof', { value: ctor });
|
|
102
|
-
|
|
103
|
-
if (options.decorate) {
|
|
104
|
-
Object.assign(boom, options.decorate);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return boom;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
static [Symbol.hasInstance](instance) {
|
|
111
|
-
|
|
112
|
-
if (this === exports.Boom) {
|
|
113
|
-
return exports.isBoom(instance);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Cannot use 'instanceof' as it creates infinite recursion
|
|
117
|
-
|
|
118
|
-
return this.prototype.isPrototypeOf(instance);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
exports.isBoom = function (err, statusCode) {
|
|
124
|
-
|
|
125
|
-
return err instanceof Error && !!err.isBoom && (!statusCode || err.output.statusCode === statusCode);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
exports.boomify = function (err, options) {
|
|
130
|
-
|
|
131
|
-
Hoek.assert(err instanceof Error, 'Cannot wrap non-Error object');
|
|
132
|
-
|
|
133
|
-
options = options || {};
|
|
134
|
-
|
|
135
|
-
if (options.data !== undefined) {
|
|
136
|
-
err.data = options.data;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (options.decorate) {
|
|
140
|
-
Object.assign(err, options.decorate);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (!err.isBoom) {
|
|
144
|
-
return internals.initialize(err, options.statusCode || 500, options.message);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (options.override === false || // Defaults to true
|
|
148
|
-
!options.statusCode && !options.message) {
|
|
149
|
-
|
|
150
|
-
return err;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return internals.initialize(err, options.statusCode || err.output.statusCode, options.message);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// 4xx Client Errors
|
|
158
|
-
|
|
159
|
-
exports.badRequest = function (message, data) {
|
|
160
|
-
|
|
161
|
-
return new exports.Boom(message, { statusCode: 400, data, ctor: exports.badRequest });
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
exports.unauthorized = function (message, scheme, attributes) { // Or (message, wwwAuthenticate[])
|
|
166
|
-
|
|
167
|
-
const err = new exports.Boom(message, { statusCode: 401, ctor: exports.unauthorized });
|
|
168
|
-
|
|
169
|
-
// function (message)
|
|
170
|
-
|
|
171
|
-
if (!scheme) {
|
|
172
|
-
return err;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// function (message, wwwAuthenticate[])
|
|
176
|
-
|
|
177
|
-
if (typeof scheme !== 'string') {
|
|
178
|
-
err.output.headers['WWW-Authenticate'] = scheme.join(', ');
|
|
179
|
-
return err;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// function (message, scheme, attributes)
|
|
183
|
-
|
|
184
|
-
let wwwAuthenticate = `${scheme}`;
|
|
185
|
-
|
|
186
|
-
if (attributes ||
|
|
187
|
-
message) {
|
|
188
|
-
|
|
189
|
-
err.output.payload.attributes = {};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (attributes) {
|
|
193
|
-
if (typeof attributes === 'string') {
|
|
194
|
-
wwwAuthenticate += ' ' + Hoek.escapeHeaderAttribute(attributes);
|
|
195
|
-
err.output.payload.attributes = attributes;
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
wwwAuthenticate += ' ' + Object.keys(attributes).map((name) => {
|
|
199
|
-
|
|
200
|
-
let value = attributes[name];
|
|
201
|
-
if (value === null ||
|
|
202
|
-
value === undefined) {
|
|
203
|
-
|
|
204
|
-
value = '';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
err.output.payload.attributes[name] = value;
|
|
208
|
-
return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`;
|
|
209
|
-
})
|
|
210
|
-
.join(', ');
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (message) {
|
|
215
|
-
if (attributes) {
|
|
216
|
-
wwwAuthenticate += ',';
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
wwwAuthenticate += ` error="${Hoek.escapeHeaderAttribute(message)}"`;
|
|
220
|
-
err.output.payload.attributes.error = message;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
err.isMissing = true;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
err.output.headers['WWW-Authenticate'] = wwwAuthenticate;
|
|
227
|
-
return err;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
exports.paymentRequired = function (message, data) {
|
|
232
|
-
|
|
233
|
-
return new exports.Boom(message, { statusCode: 402, data, ctor: exports.paymentRequired });
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
exports.forbidden = function (message, data) {
|
|
238
|
-
|
|
239
|
-
return new exports.Boom(message, { statusCode: 403, data, ctor: exports.forbidden });
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
exports.notFound = function (message, data) {
|
|
244
|
-
|
|
245
|
-
return new exports.Boom(message, { statusCode: 404, data, ctor: exports.notFound });
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
exports.methodNotAllowed = function (message, data, allow) {
|
|
250
|
-
|
|
251
|
-
const err = new exports.Boom(message, { statusCode: 405, data, ctor: exports.methodNotAllowed });
|
|
252
|
-
|
|
253
|
-
if (typeof allow === 'string') {
|
|
254
|
-
allow = [allow];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (Array.isArray(allow)) {
|
|
258
|
-
err.output.headers.Allow = allow.join(', ');
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return err;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
exports.notAcceptable = function (message, data) {
|
|
266
|
-
|
|
267
|
-
return new exports.Boom(message, { statusCode: 406, data, ctor: exports.notAcceptable });
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
exports.proxyAuthRequired = function (message, data) {
|
|
272
|
-
|
|
273
|
-
return new exports.Boom(message, { statusCode: 407, data, ctor: exports.proxyAuthRequired });
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
exports.clientTimeout = function (message, data) {
|
|
278
|
-
|
|
279
|
-
return new exports.Boom(message, { statusCode: 408, data, ctor: exports.clientTimeout });
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
exports.conflict = function (message, data) {
|
|
284
|
-
|
|
285
|
-
return new exports.Boom(message, { statusCode: 409, data, ctor: exports.conflict });
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
exports.resourceGone = function (message, data) {
|
|
290
|
-
|
|
291
|
-
return new exports.Boom(message, { statusCode: 410, data, ctor: exports.resourceGone });
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
exports.lengthRequired = function (message, data) {
|
|
296
|
-
|
|
297
|
-
return new exports.Boom(message, { statusCode: 411, data, ctor: exports.lengthRequired });
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
exports.preconditionFailed = function (message, data) {
|
|
302
|
-
|
|
303
|
-
return new exports.Boom(message, { statusCode: 412, data, ctor: exports.preconditionFailed });
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
exports.entityTooLarge = function (message, data) {
|
|
308
|
-
|
|
309
|
-
return new exports.Boom(message, { statusCode: 413, data, ctor: exports.entityTooLarge });
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
exports.uriTooLong = function (message, data) {
|
|
314
|
-
|
|
315
|
-
return new exports.Boom(message, { statusCode: 414, data, ctor: exports.uriTooLong });
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
exports.unsupportedMediaType = function (message, data) {
|
|
320
|
-
|
|
321
|
-
return new exports.Boom(message, { statusCode: 415, data, ctor: exports.unsupportedMediaType });
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
exports.rangeNotSatisfiable = function (message, data) {
|
|
326
|
-
|
|
327
|
-
return new exports.Boom(message, { statusCode: 416, data, ctor: exports.rangeNotSatisfiable });
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
exports.expectationFailed = function (message, data) {
|
|
332
|
-
|
|
333
|
-
return new exports.Boom(message, { statusCode: 417, data, ctor: exports.expectationFailed });
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
exports.teapot = function (message, data) {
|
|
338
|
-
|
|
339
|
-
return new exports.Boom(message, { statusCode: 418, data, ctor: exports.teapot });
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
exports.badData = function (message, data) {
|
|
344
|
-
|
|
345
|
-
return new exports.Boom(message, { statusCode: 422, data, ctor: exports.badData });
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
exports.locked = function (message, data) {
|
|
350
|
-
|
|
351
|
-
return new exports.Boom(message, { statusCode: 423, data, ctor: exports.locked });
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
exports.failedDependency = function (message, data) {
|
|
356
|
-
|
|
357
|
-
return new exports.Boom(message, { statusCode: 424, data, ctor: exports.failedDependency });
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
exports.tooEarly = function (message, data) {
|
|
361
|
-
|
|
362
|
-
return new exports.Boom(message, { statusCode: 425, data, ctor: exports.tooEarly });
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
exports.preconditionRequired = function (message, data) {
|
|
367
|
-
|
|
368
|
-
return new exports.Boom(message, { statusCode: 428, data, ctor: exports.preconditionRequired });
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
exports.tooManyRequests = function (message, data) {
|
|
373
|
-
|
|
374
|
-
return new exports.Boom(message, { statusCode: 429, data, ctor: exports.tooManyRequests });
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
exports.illegal = function (message, data) {
|
|
379
|
-
|
|
380
|
-
return new exports.Boom(message, { statusCode: 451, data, ctor: exports.illegal });
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
// 5xx Server Errors
|
|
385
|
-
|
|
386
|
-
exports.internal = function (message, data, statusCode = 500) {
|
|
387
|
-
|
|
388
|
-
return internals.serverError(message, data, statusCode, exports.internal);
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
exports.notImplemented = function (message, data) {
|
|
393
|
-
|
|
394
|
-
return internals.serverError(message, data, 501, exports.notImplemented);
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
exports.badGateway = function (message, data) {
|
|
399
|
-
|
|
400
|
-
return internals.serverError(message, data, 502, exports.badGateway);
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
exports.serverUnavailable = function (message, data) {
|
|
405
|
-
|
|
406
|
-
return internals.serverError(message, data, 503, exports.serverUnavailable);
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
exports.gatewayTimeout = function (message, data) {
|
|
411
|
-
|
|
412
|
-
return internals.serverError(message, data, 504, exports.gatewayTimeout);
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
exports.badImplementation = function (message, data) {
|
|
417
|
-
|
|
418
|
-
const err = internals.serverError(message, data, 500, exports.badImplementation);
|
|
419
|
-
err.isDeveloperError = true;
|
|
420
|
-
return err;
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
internals.initialize = function (err, statusCode, message) {
|
|
425
|
-
|
|
426
|
-
const numberCode = parseInt(statusCode, 10);
|
|
427
|
-
Hoek.assert(!isNaN(numberCode) && numberCode >= 400, 'First argument must be a number (400+):', statusCode);
|
|
428
|
-
|
|
429
|
-
err.isBoom = true;
|
|
430
|
-
err.isServer = numberCode >= 500;
|
|
431
|
-
|
|
432
|
-
if (!err.hasOwnProperty('data')) {
|
|
433
|
-
err.data = null;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
err.output = {
|
|
437
|
-
statusCode: numberCode,
|
|
438
|
-
payload: {},
|
|
439
|
-
headers: {}
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
Object.defineProperty(err, 'reformat', { value: internals.reformat, configurable: true });
|
|
443
|
-
|
|
444
|
-
if (!message &&
|
|
445
|
-
!err.message) {
|
|
446
|
-
|
|
447
|
-
err.reformat();
|
|
448
|
-
message = err.output.payload.error;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
if (message) {
|
|
452
|
-
const props = Object.getOwnPropertyDescriptor(err, 'message') || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(err), 'message');
|
|
453
|
-
Hoek.assert(!props || props.configurable && !props.get, 'The error is not compatible with boom');
|
|
454
|
-
|
|
455
|
-
err.message = message + (err.message ? ': ' + err.message : '');
|
|
456
|
-
err.output.payload.message = err.message;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
err.reformat();
|
|
460
|
-
return err;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
internals.reformat = function (debug = false) {
|
|
465
|
-
|
|
466
|
-
this.output.payload.statusCode = this.output.statusCode;
|
|
467
|
-
this.output.payload.error = internals.codes.get(this.output.statusCode) || 'Unknown';
|
|
468
|
-
|
|
469
|
-
if (this.output.statusCode === 500 && debug !== true) {
|
|
470
|
-
this.output.payload.message = 'An internal server error occurred'; // Hide actual error from user
|
|
471
|
-
}
|
|
472
|
-
else if (this.message) {
|
|
473
|
-
this.output.payload.message = this.message;
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
internals.serverError = function (message, data, statusCode, ctor) {
|
|
479
|
-
|
|
480
|
-
if (data instanceof Error &&
|
|
481
|
-
!data.isBoom) {
|
|
482
|
-
|
|
483
|
-
return exports.boomify(data, { statusCode, message });
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
return new exports.Boom(message, { statusCode, data, ctor });
|
|
487
|
-
};
|
|
1
|
+
import * _ from 'lodash';
|
|
2
|
+
|
|
3
|
+
const Hoek = {
|
|
4
|
+
clone: message => _.clone(message),
|
|
5
|
+
assert: (condition, ...args) => {
|
|
6
|
+
if (condition) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (args.length === 1 &&
|
|
11
|
+
args[0] instanceof Error) {
|
|
12
|
+
|
|
13
|
+
throw args[0];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new Error(args);
|
|
17
|
+
},
|
|
18
|
+
escapeHeaderAttribute: attribute => {
|
|
19
|
+
return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const internals = {
|
|
25
|
+
codes: new Map([
|
|
26
|
+
[100, 'Continue'],
|
|
27
|
+
[101, 'Switching Protocols'],
|
|
28
|
+
[102, 'Processing'],
|
|
29
|
+
[200, 'OK'],
|
|
30
|
+
[201, 'Created'],
|
|
31
|
+
[202, 'Accepted'],
|
|
32
|
+
[203, 'Non-Authoritative Information'],
|
|
33
|
+
[204, 'No Content'],
|
|
34
|
+
[205, 'Reset Content'],
|
|
35
|
+
[206, 'Partial Content'],
|
|
36
|
+
[207, 'Multi-Status'],
|
|
37
|
+
[300, 'Multiple Choices'],
|
|
38
|
+
[301, 'Moved Permanently'],
|
|
39
|
+
[302, 'Moved Temporarily'],
|
|
40
|
+
[303, 'See Other'],
|
|
41
|
+
[304, 'Not Modified'],
|
|
42
|
+
[305, 'Use Proxy'],
|
|
43
|
+
[307, 'Temporary Redirect'],
|
|
44
|
+
[400, 'Bad Request'],
|
|
45
|
+
[401, 'Unauthorized'],
|
|
46
|
+
[402, 'Payment Required'],
|
|
47
|
+
[403, 'Forbidden'],
|
|
48
|
+
[404, 'Not Found'],
|
|
49
|
+
[405, 'Method Not Allowed'],
|
|
50
|
+
[406, 'Not Acceptable'],
|
|
51
|
+
[407, 'Proxy Authentication Required'],
|
|
52
|
+
[408, 'Request Time-out'],
|
|
53
|
+
[409, 'Conflict'],
|
|
54
|
+
[410, 'Gone'],
|
|
55
|
+
[411, 'Length Required'],
|
|
56
|
+
[412, 'Precondition Failed'],
|
|
57
|
+
[413, 'Request Entity Too Large'],
|
|
58
|
+
[414, 'Request-URI Too Large'],
|
|
59
|
+
[415, 'Unsupported Media Type'],
|
|
60
|
+
[416, 'Requested Range Not Satisfiable'],
|
|
61
|
+
[417, 'Expectation Failed'],
|
|
62
|
+
[418, 'I\'m a teapot'],
|
|
63
|
+
[422, 'Unprocessable Entity'],
|
|
64
|
+
[423, 'Locked'],
|
|
65
|
+
[424, 'Failed Dependency'],
|
|
66
|
+
[425, 'Too Early'],
|
|
67
|
+
[426, 'Upgrade Required'],
|
|
68
|
+
[428, 'Precondition Required'],
|
|
69
|
+
[429, 'Too Many Requests'],
|
|
70
|
+
[431, 'Request Header Fields Too Large'],
|
|
71
|
+
[451, 'Unavailable For Legal Reasons'],
|
|
72
|
+
[500, 'Internal Server Error'],
|
|
73
|
+
[501, 'Not Implemented'],
|
|
74
|
+
[502, 'Bad Gateway'],
|
|
75
|
+
[503, 'Service Unavailable'],
|
|
76
|
+
[504, 'Gateway Time-out'],
|
|
77
|
+
[505, 'HTTP Version Not Supported'],
|
|
78
|
+
[506, 'Variant Also Negotiates'],
|
|
79
|
+
[507, 'Insufficient Storage'],
|
|
80
|
+
[509, 'Bandwidth Limit Exceeded'],
|
|
81
|
+
[510, 'Not Extended'],
|
|
82
|
+
[511, 'Network Authentication Required']
|
|
83
|
+
])
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
exports.Boom = class extends Error {
|
|
88
|
+
|
|
89
|
+
constructor(message, options = {}) {
|
|
90
|
+
|
|
91
|
+
if (message instanceof Error) {
|
|
92
|
+
return exports.boomify(Hoek.clone(message), options);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const { statusCode = 500, data = null, ctor = exports.Boom } = options;
|
|
96
|
+
const error = new Error(message ? message : undefined); // Avoids settings null message
|
|
97
|
+
Error.captureStackTrace(error, ctor); // Filter the stack to our external API
|
|
98
|
+
error.data = data;
|
|
99
|
+
const boom = internals.initialize(error, statusCode);
|
|
100
|
+
|
|
101
|
+
Object.defineProperty(boom, 'typeof', { value: ctor });
|
|
102
|
+
|
|
103
|
+
if (options.decorate) {
|
|
104
|
+
Object.assign(boom, options.decorate);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return boom;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static [Symbol.hasInstance](instance) {
|
|
111
|
+
|
|
112
|
+
if (this === exports.Boom) {
|
|
113
|
+
return exports.isBoom(instance);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Cannot use 'instanceof' as it creates infinite recursion
|
|
117
|
+
|
|
118
|
+
return this.prototype.isPrototypeOf(instance);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
exports.isBoom = function (err, statusCode) {
|
|
124
|
+
|
|
125
|
+
return err instanceof Error && !!err.isBoom && (!statusCode || err.output.statusCode === statusCode);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
exports.boomify = function (err, options) {
|
|
130
|
+
|
|
131
|
+
Hoek.assert(err instanceof Error, 'Cannot wrap non-Error object');
|
|
132
|
+
|
|
133
|
+
options = options || {};
|
|
134
|
+
|
|
135
|
+
if (options.data !== undefined) {
|
|
136
|
+
err.data = options.data;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (options.decorate) {
|
|
140
|
+
Object.assign(err, options.decorate);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (!err.isBoom) {
|
|
144
|
+
return internals.initialize(err, options.statusCode || 500, options.message);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (options.override === false || // Defaults to true
|
|
148
|
+
!options.statusCode && !options.message) {
|
|
149
|
+
|
|
150
|
+
return err;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return internals.initialize(err, options.statusCode || err.output.statusCode, options.message);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
// 4xx Client Errors
|
|
158
|
+
|
|
159
|
+
exports.badRequest = function (message, data) {
|
|
160
|
+
|
|
161
|
+
return new exports.Boom(message, { statusCode: 400, data, ctor: exports.badRequest });
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
exports.unauthorized = function (message, scheme, attributes) { // Or (message, wwwAuthenticate[])
|
|
166
|
+
|
|
167
|
+
const err = new exports.Boom(message, { statusCode: 401, ctor: exports.unauthorized });
|
|
168
|
+
|
|
169
|
+
// function (message)
|
|
170
|
+
|
|
171
|
+
if (!scheme) {
|
|
172
|
+
return err;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// function (message, wwwAuthenticate[])
|
|
176
|
+
|
|
177
|
+
if (typeof scheme !== 'string') {
|
|
178
|
+
err.output.headers['WWW-Authenticate'] = scheme.join(', ');
|
|
179
|
+
return err;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// function (message, scheme, attributes)
|
|
183
|
+
|
|
184
|
+
let wwwAuthenticate = `${scheme}`;
|
|
185
|
+
|
|
186
|
+
if (attributes ||
|
|
187
|
+
message) {
|
|
188
|
+
|
|
189
|
+
err.output.payload.attributes = {};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (attributes) {
|
|
193
|
+
if (typeof attributes === 'string') {
|
|
194
|
+
wwwAuthenticate += ' ' + Hoek.escapeHeaderAttribute(attributes);
|
|
195
|
+
err.output.payload.attributes = attributes;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
wwwAuthenticate += ' ' + Object.keys(attributes).map((name) => {
|
|
199
|
+
|
|
200
|
+
let value = attributes[name];
|
|
201
|
+
if (value === null ||
|
|
202
|
+
value === undefined) {
|
|
203
|
+
|
|
204
|
+
value = '';
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
err.output.payload.attributes[name] = value;
|
|
208
|
+
return `${name}="${Hoek.escapeHeaderAttribute(value.toString())}"`;
|
|
209
|
+
})
|
|
210
|
+
.join(', ');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (message) {
|
|
215
|
+
if (attributes) {
|
|
216
|
+
wwwAuthenticate += ',';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
wwwAuthenticate += ` error="${Hoek.escapeHeaderAttribute(message)}"`;
|
|
220
|
+
err.output.payload.attributes.error = message;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
err.isMissing = true;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
err.output.headers['WWW-Authenticate'] = wwwAuthenticate;
|
|
227
|
+
return err;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
exports.paymentRequired = function (message, data) {
|
|
232
|
+
|
|
233
|
+
return new exports.Boom(message, { statusCode: 402, data, ctor: exports.paymentRequired });
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
exports.forbidden = function (message, data) {
|
|
238
|
+
|
|
239
|
+
return new exports.Boom(message, { statusCode: 403, data, ctor: exports.forbidden });
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
exports.notFound = function (message, data) {
|
|
244
|
+
|
|
245
|
+
return new exports.Boom(message, { statusCode: 404, data, ctor: exports.notFound });
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
exports.methodNotAllowed = function (message, data, allow) {
|
|
250
|
+
|
|
251
|
+
const err = new exports.Boom(message, { statusCode: 405, data, ctor: exports.methodNotAllowed });
|
|
252
|
+
|
|
253
|
+
if (typeof allow === 'string') {
|
|
254
|
+
allow = [allow];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (Array.isArray(allow)) {
|
|
258
|
+
err.output.headers.Allow = allow.join(', ');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return err;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
exports.notAcceptable = function (message, data) {
|
|
266
|
+
|
|
267
|
+
return new exports.Boom(message, { statusCode: 406, data, ctor: exports.notAcceptable });
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
exports.proxyAuthRequired = function (message, data) {
|
|
272
|
+
|
|
273
|
+
return new exports.Boom(message, { statusCode: 407, data, ctor: exports.proxyAuthRequired });
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
exports.clientTimeout = function (message, data) {
|
|
278
|
+
|
|
279
|
+
return new exports.Boom(message, { statusCode: 408, data, ctor: exports.clientTimeout });
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
exports.conflict = function (message, data) {
|
|
284
|
+
|
|
285
|
+
return new exports.Boom(message, { statusCode: 409, data, ctor: exports.conflict });
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
exports.resourceGone = function (message, data) {
|
|
290
|
+
|
|
291
|
+
return new exports.Boom(message, { statusCode: 410, data, ctor: exports.resourceGone });
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
exports.lengthRequired = function (message, data) {
|
|
296
|
+
|
|
297
|
+
return new exports.Boom(message, { statusCode: 411, data, ctor: exports.lengthRequired });
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
exports.preconditionFailed = function (message, data) {
|
|
302
|
+
|
|
303
|
+
return new exports.Boom(message, { statusCode: 412, data, ctor: exports.preconditionFailed });
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
exports.entityTooLarge = function (message, data) {
|
|
308
|
+
|
|
309
|
+
return new exports.Boom(message, { statusCode: 413, data, ctor: exports.entityTooLarge });
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
exports.uriTooLong = function (message, data) {
|
|
314
|
+
|
|
315
|
+
return new exports.Boom(message, { statusCode: 414, data, ctor: exports.uriTooLong });
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
exports.unsupportedMediaType = function (message, data) {
|
|
320
|
+
|
|
321
|
+
return new exports.Boom(message, { statusCode: 415, data, ctor: exports.unsupportedMediaType });
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
exports.rangeNotSatisfiable = function (message, data) {
|
|
326
|
+
|
|
327
|
+
return new exports.Boom(message, { statusCode: 416, data, ctor: exports.rangeNotSatisfiable });
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
exports.expectationFailed = function (message, data) {
|
|
332
|
+
|
|
333
|
+
return new exports.Boom(message, { statusCode: 417, data, ctor: exports.expectationFailed });
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
exports.teapot = function (message, data) {
|
|
338
|
+
|
|
339
|
+
return new exports.Boom(message, { statusCode: 418, data, ctor: exports.teapot });
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
exports.badData = function (message, data) {
|
|
344
|
+
|
|
345
|
+
return new exports.Boom(message, { statusCode: 422, data, ctor: exports.badData });
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
exports.locked = function (message, data) {
|
|
350
|
+
|
|
351
|
+
return new exports.Boom(message, { statusCode: 423, data, ctor: exports.locked });
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
exports.failedDependency = function (message, data) {
|
|
356
|
+
|
|
357
|
+
return new exports.Boom(message, { statusCode: 424, data, ctor: exports.failedDependency });
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
exports.tooEarly = function (message, data) {
|
|
361
|
+
|
|
362
|
+
return new exports.Boom(message, { statusCode: 425, data, ctor: exports.tooEarly });
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
exports.preconditionRequired = function (message, data) {
|
|
367
|
+
|
|
368
|
+
return new exports.Boom(message, { statusCode: 428, data, ctor: exports.preconditionRequired });
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
exports.tooManyRequests = function (message, data) {
|
|
373
|
+
|
|
374
|
+
return new exports.Boom(message, { statusCode: 429, data, ctor: exports.tooManyRequests });
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
exports.illegal = function (message, data) {
|
|
379
|
+
|
|
380
|
+
return new exports.Boom(message, { statusCode: 451, data, ctor: exports.illegal });
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
// 5xx Server Errors
|
|
385
|
+
|
|
386
|
+
exports.internal = function (message, data, statusCode = 500) {
|
|
387
|
+
|
|
388
|
+
return internals.serverError(message, data, statusCode, exports.internal);
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
exports.notImplemented = function (message, data) {
|
|
393
|
+
|
|
394
|
+
return internals.serverError(message, data, 501, exports.notImplemented);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
exports.badGateway = function (message, data) {
|
|
399
|
+
|
|
400
|
+
return internals.serverError(message, data, 502, exports.badGateway);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
exports.serverUnavailable = function (message, data) {
|
|
405
|
+
|
|
406
|
+
return internals.serverError(message, data, 503, exports.serverUnavailable);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
exports.gatewayTimeout = function (message, data) {
|
|
411
|
+
|
|
412
|
+
return internals.serverError(message, data, 504, exports.gatewayTimeout);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
exports.badImplementation = function (message, data) {
|
|
417
|
+
|
|
418
|
+
const err = internals.serverError(message, data, 500, exports.badImplementation);
|
|
419
|
+
err.isDeveloperError = true;
|
|
420
|
+
return err;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
internals.initialize = function (err, statusCode, message) {
|
|
425
|
+
|
|
426
|
+
const numberCode = parseInt(statusCode, 10);
|
|
427
|
+
Hoek.assert(!isNaN(numberCode) && numberCode >= 400, 'First argument must be a number (400+):', statusCode);
|
|
428
|
+
|
|
429
|
+
err.isBoom = true;
|
|
430
|
+
err.isServer = numberCode >= 500;
|
|
431
|
+
|
|
432
|
+
if (!err.hasOwnProperty('data')) {
|
|
433
|
+
err.data = null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
err.output = {
|
|
437
|
+
statusCode: numberCode,
|
|
438
|
+
payload: {},
|
|
439
|
+
headers: {}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
Object.defineProperty(err, 'reformat', { value: internals.reformat, configurable: true });
|
|
443
|
+
|
|
444
|
+
if (!message &&
|
|
445
|
+
!err.message) {
|
|
446
|
+
|
|
447
|
+
err.reformat();
|
|
448
|
+
message = err.output.payload.error;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (message) {
|
|
452
|
+
const props = Object.getOwnPropertyDescriptor(err, 'message') || Object.getOwnPropertyDescriptor(Object.getPrototypeOf(err), 'message');
|
|
453
|
+
Hoek.assert(!props || props.configurable && !props.get, 'The error is not compatible with boom');
|
|
454
|
+
|
|
455
|
+
err.message = message + (err.message ? ': ' + err.message : '');
|
|
456
|
+
err.output.payload.message = err.message;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
err.reformat();
|
|
460
|
+
return err;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
internals.reformat = function (debug = false) {
|
|
465
|
+
|
|
466
|
+
this.output.payload.statusCode = this.output.statusCode;
|
|
467
|
+
this.output.payload.error = internals.codes.get(this.output.statusCode) || 'Unknown';
|
|
468
|
+
|
|
469
|
+
if (this.output.statusCode === 500 && debug !== true) {
|
|
470
|
+
this.output.payload.message = 'An internal server error occurred'; // Hide actual error from user
|
|
471
|
+
}
|
|
472
|
+
else if (this.message) {
|
|
473
|
+
this.output.payload.message = this.message;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
internals.serverError = function (message, data, statusCode, ctor) {
|
|
479
|
+
|
|
480
|
+
if (data instanceof Error &&
|
|
481
|
+
!data.isBoom) {
|
|
482
|
+
|
|
483
|
+
return exports.boomify(data, { statusCode, message });
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return new exports.Boom(message, { statusCode, data, ctor });
|
|
487
|
+
};
|