@unito/integration-sdk 1.0.21 → 1.0.23
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/src/errors.js +3 -0
- package/dist/src/httpErrors.d.ts +8 -0
- package/dist/src/httpErrors.js +11 -1
- package/dist/src/index.cjs +23 -6
- package/dist/src/integration.js +8 -5
- package/dist/test/errors.test.js +1 -0
- package/package.json +1 -1
- package/src/errors.ts +2 -0
- package/src/httpErrors.ts +12 -1
- package/src/integration.ts +9 -5
- package/test/errors.test.ts +1 -0
package/dist/src/errors.js
CHANGED
|
@@ -28,6 +28,9 @@ export function buildHttpError(responseStatus, message) {
|
|
|
28
28
|
else if (responseStatus === 422) {
|
|
29
29
|
httpError = new HttpErrors.UnprocessableEntityError(message);
|
|
30
30
|
}
|
|
31
|
+
else if (responseStatus === 423) {
|
|
32
|
+
httpError = new HttpErrors.ProviderInstanceLockedError(message);
|
|
33
|
+
}
|
|
31
34
|
else if (responseStatus === 429) {
|
|
32
35
|
httpError = new HttpErrors.RateLimitExceededError(message);
|
|
33
36
|
}
|
package/dist/src/httpErrors.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ export declare class TimeoutError extends HttpError {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Used to generate a 410 Resource Gone.
|
|
38
|
+
*
|
|
39
|
+
* @deprecated Use ProviderInstanceLockedError instead when the provider instance is locked or unavailable.
|
|
38
40
|
*/
|
|
39
41
|
export declare class ResourceGoneError extends HttpError {
|
|
40
42
|
constructor(message?: string);
|
|
@@ -45,6 +47,12 @@ export declare class ResourceGoneError extends HttpError {
|
|
|
45
47
|
export declare class UnprocessableEntityError extends HttpError {
|
|
46
48
|
constructor(message?: string);
|
|
47
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Used to generate a 423 Provider Instance Locked.
|
|
52
|
+
*/
|
|
53
|
+
export declare class ProviderInstanceLockedError extends HttpError {
|
|
54
|
+
constructor(message?: string);
|
|
55
|
+
}
|
|
48
56
|
/**
|
|
49
57
|
* Used to generate a 429 Rate Limit Exceeded. Usually used when an operation triggers or would trigger a rate limit
|
|
50
58
|
* error on the provider's side.
|
package/dist/src/httpErrors.js
CHANGED
|
@@ -47,10 +47,12 @@ export class TimeoutError extends HttpError {
|
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Used to generate a 410 Resource Gone.
|
|
50
|
+
*
|
|
51
|
+
* @deprecated Use ProviderInstanceLockedError instead when the provider instance is locked or unavailable.
|
|
50
52
|
*/
|
|
51
53
|
export class ResourceGoneError extends HttpError {
|
|
52
54
|
constructor(message) {
|
|
53
|
-
super(message || 'Resource
|
|
55
|
+
super(message || 'Resource Gone', 410);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
@@ -61,6 +63,14 @@ export class UnprocessableEntityError extends HttpError {
|
|
|
61
63
|
super(message || 'Unprocessable Entity', 422);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Used to generate a 423 Provider Instance Locked.
|
|
68
|
+
*/
|
|
69
|
+
export class ProviderInstanceLockedError extends HttpError {
|
|
70
|
+
constructor(message) {
|
|
71
|
+
super(message || 'Provider instance locked or unavailable', 423);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
64
74
|
/**
|
|
65
75
|
* Used to generate a 429 Rate Limit Exceeded. Usually used when an operation triggers or would trigger a rate limit
|
|
66
76
|
* error on the provider's side.
|
package/dist/src/index.cjs
CHANGED
|
@@ -280,10 +280,12 @@ class TimeoutError extends HttpError {
|
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
282
282
|
* Used to generate a 410 Resource Gone.
|
|
283
|
+
*
|
|
284
|
+
* @deprecated Use ProviderInstanceLockedError instead when the provider instance is locked or unavailable.
|
|
283
285
|
*/
|
|
284
286
|
class ResourceGoneError extends HttpError {
|
|
285
287
|
constructor(message) {
|
|
286
|
-
super(message || 'Resource
|
|
288
|
+
super(message || 'Resource Gone', 410);
|
|
287
289
|
}
|
|
288
290
|
}
|
|
289
291
|
/**
|
|
@@ -294,6 +296,14 @@ class UnprocessableEntityError extends HttpError {
|
|
|
294
296
|
super(message || 'Unprocessable Entity', 422);
|
|
295
297
|
}
|
|
296
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Used to generate a 423 Provider Instance Locked.
|
|
301
|
+
*/
|
|
302
|
+
class ProviderInstanceLockedError extends HttpError {
|
|
303
|
+
constructor(message) {
|
|
304
|
+
super(message || 'Provider instance locked or unavailable', 423);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
297
307
|
/**
|
|
298
308
|
* Used to generate a 429 Rate Limit Exceeded. Usually used when an operation triggers or would trigger a rate limit
|
|
299
309
|
* error on the provider's side.
|
|
@@ -309,6 +319,7 @@ var httpErrors = /*#__PURE__*/Object.freeze({
|
|
|
309
319
|
BadRequestError: BadRequestError,
|
|
310
320
|
HttpError: HttpError,
|
|
311
321
|
NotFoundError: NotFoundError,
|
|
322
|
+
ProviderInstanceLockedError: ProviderInstanceLockedError,
|
|
312
323
|
RateLimitExceededError: RateLimitExceededError,
|
|
313
324
|
ResourceGoneError: ResourceGoneError,
|
|
314
325
|
TimeoutError: TimeoutError,
|
|
@@ -345,6 +356,9 @@ function buildHttpError(responseStatus, message) {
|
|
|
345
356
|
else if (responseStatus === 422) {
|
|
346
357
|
httpError = new UnprocessableEntityError(message);
|
|
347
358
|
}
|
|
359
|
+
else if (responseStatus === 423) {
|
|
360
|
+
httpError = new ProviderInstanceLockedError(message);
|
|
361
|
+
}
|
|
348
362
|
else if (responseStatus === 429) {
|
|
349
363
|
httpError = new RateLimitExceededError(message);
|
|
350
364
|
}
|
|
@@ -983,14 +997,10 @@ class Integration {
|
|
|
983
997
|
app.use(express.json());
|
|
984
998
|
// Must be one of the first handlers (to catch all the errors).
|
|
985
999
|
app.use(middleware$2);
|
|
1000
|
+
// Instantiate internal middlewares.
|
|
986
1001
|
app.use(middleware);
|
|
987
1002
|
app.use(middleware$a);
|
|
988
1003
|
app.use(middleware$9);
|
|
989
|
-
app.use(middleware$8);
|
|
990
|
-
app.use(middleware$6);
|
|
991
|
-
app.use(middleware$5);
|
|
992
|
-
app.use(middleware$4);
|
|
993
|
-
app.use(middleware$7);
|
|
994
1004
|
// Making sure we log all incoming requests (except to '/health'), prior any processing.
|
|
995
1005
|
app.use((req, res, next) => {
|
|
996
1006
|
if (req.originalUrl !== '/health') {
|
|
@@ -998,6 +1008,13 @@ class Integration {
|
|
|
998
1008
|
}
|
|
999
1009
|
next();
|
|
1000
1010
|
});
|
|
1011
|
+
// Instantiate application middlewares. These can throw, so they have an implicit dependency on the internal
|
|
1012
|
+
// middlewares such as the logger, the correlationId, and the error handling.
|
|
1013
|
+
app.use(middleware$8);
|
|
1014
|
+
app.use(middleware$6);
|
|
1015
|
+
app.use(middleware$5);
|
|
1016
|
+
app.use(middleware$4);
|
|
1017
|
+
app.use(middleware$7);
|
|
1001
1018
|
// Load handlers as needed.
|
|
1002
1019
|
if (this.handlers.length) {
|
|
1003
1020
|
for (const handler of this.handlers) {
|
package/dist/src/integration.js
CHANGED
|
@@ -114,14 +114,10 @@ export default class Integration {
|
|
|
114
114
|
app.use(express.json());
|
|
115
115
|
// Must be one of the first handlers (to catch all the errors).
|
|
116
116
|
app.use(finishMiddleware);
|
|
117
|
+
// Instantiate internal middlewares.
|
|
117
118
|
app.use(requestStartTimeMiddleware);
|
|
118
119
|
app.use(correlationIdMiddleware);
|
|
119
120
|
app.use(loggerMiddleware);
|
|
120
|
-
app.use(credentialsMiddleware);
|
|
121
|
-
app.use(secretsMiddleware);
|
|
122
|
-
app.use(filtersMiddleware);
|
|
123
|
-
app.use(selectsMiddleware);
|
|
124
|
-
app.use(signalMiddleware);
|
|
125
121
|
// Making sure we log all incoming requests (except to '/health'), prior any processing.
|
|
126
122
|
app.use((req, res, next) => {
|
|
127
123
|
if (req.originalUrl !== '/health') {
|
|
@@ -129,6 +125,13 @@ export default class Integration {
|
|
|
129
125
|
}
|
|
130
126
|
next();
|
|
131
127
|
});
|
|
128
|
+
// Instantiate application middlewares. These can throw, so they have an implicit dependency on the internal
|
|
129
|
+
// middlewares such as the logger, the correlationId, and the error handling.
|
|
130
|
+
app.use(credentialsMiddleware);
|
|
131
|
+
app.use(secretsMiddleware);
|
|
132
|
+
app.use(filtersMiddleware);
|
|
133
|
+
app.use(selectsMiddleware);
|
|
134
|
+
app.use(signalMiddleware);
|
|
132
135
|
// Load handlers as needed.
|
|
133
136
|
if (this.handlers.length) {
|
|
134
137
|
for (const handler of this.handlers) {
|
package/dist/test/errors.test.js
CHANGED
|
@@ -10,6 +10,7 @@ describe('handleErrorResponse', () => {
|
|
|
10
10
|
assert.ok(errors.buildHttpError(408, 'timeout') instanceof httpErrors.TimeoutError);
|
|
11
11
|
assert.ok(errors.buildHttpError(410, 'resource gone') instanceof httpErrors.ResourceGoneError);
|
|
12
12
|
assert.ok(errors.buildHttpError(422, 'unprocessable entity') instanceof httpErrors.UnprocessableEntityError);
|
|
13
|
+
assert.ok(errors.buildHttpError(423, 'resource gone') instanceof httpErrors.ProviderInstanceLockedError);
|
|
13
14
|
assert.ok(errors.buildHttpError(429, 'rate limit exceeded') instanceof httpErrors.RateLimitExceededError);
|
|
14
15
|
assert.ok(errors.buildHttpError(500, 'internal server error') instanceof httpErrors.HttpError);
|
|
15
16
|
});
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -23,6 +23,8 @@ export function buildHttpError(responseStatus: number, message: string): HttpErr
|
|
|
23
23
|
httpError = new HttpErrors.ResourceGoneError(message);
|
|
24
24
|
} else if (responseStatus === 422) {
|
|
25
25
|
httpError = new HttpErrors.UnprocessableEntityError(message);
|
|
26
|
+
} else if (responseStatus === 423) {
|
|
27
|
+
httpError = new HttpErrors.ProviderInstanceLockedError(message);
|
|
26
28
|
} else if (responseStatus === 429) {
|
|
27
29
|
httpError = new HttpErrors.RateLimitExceededError(message);
|
|
28
30
|
} else {
|
package/src/httpErrors.ts
CHANGED
|
@@ -53,10 +53,12 @@ export class TimeoutError extends HttpError {
|
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Used to generate a 410 Resource Gone.
|
|
56
|
+
*
|
|
57
|
+
* @deprecated Use ProviderInstanceLockedError instead when the provider instance is locked or unavailable.
|
|
56
58
|
*/
|
|
57
59
|
export class ResourceGoneError extends HttpError {
|
|
58
60
|
constructor(message?: string) {
|
|
59
|
-
super(message || 'Resource
|
|
61
|
+
super(message || 'Resource Gone', 410);
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -69,6 +71,15 @@ export class UnprocessableEntityError extends HttpError {
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Used to generate a 423 Provider Instance Locked.
|
|
76
|
+
*/
|
|
77
|
+
export class ProviderInstanceLockedError extends HttpError {
|
|
78
|
+
constructor(message?: string) {
|
|
79
|
+
super(message || 'Provider instance locked or unavailable', 423);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
/**
|
|
73
84
|
* Used to generate a 429 Rate Limit Exceeded. Usually used when an operation triggers or would trigger a rate limit
|
|
74
85
|
* error on the provider's side.
|
package/src/integration.ts
CHANGED
|
@@ -130,14 +130,10 @@ export default class Integration {
|
|
|
130
130
|
// Must be one of the first handlers (to catch all the errors).
|
|
131
131
|
app.use(finishMiddleware);
|
|
132
132
|
|
|
133
|
+
// Instantiate internal middlewares.
|
|
133
134
|
app.use(requestStartTimeMiddleware);
|
|
134
135
|
app.use(correlationIdMiddleware);
|
|
135
136
|
app.use(loggerMiddleware);
|
|
136
|
-
app.use(credentialsMiddleware);
|
|
137
|
-
app.use(secretsMiddleware);
|
|
138
|
-
app.use(filtersMiddleware);
|
|
139
|
-
app.use(selectsMiddleware);
|
|
140
|
-
app.use(signalMiddleware);
|
|
141
137
|
|
|
142
138
|
// Making sure we log all incoming requests (except to '/health'), prior any processing.
|
|
143
139
|
app.use((req, res, next) => {
|
|
@@ -147,6 +143,14 @@ export default class Integration {
|
|
|
147
143
|
next();
|
|
148
144
|
});
|
|
149
145
|
|
|
146
|
+
// Instantiate application middlewares. These can throw, so they have an implicit dependency on the internal
|
|
147
|
+
// middlewares such as the logger, the correlationId, and the error handling.
|
|
148
|
+
app.use(credentialsMiddleware);
|
|
149
|
+
app.use(secretsMiddleware);
|
|
150
|
+
app.use(filtersMiddleware);
|
|
151
|
+
app.use(selectsMiddleware);
|
|
152
|
+
app.use(signalMiddleware);
|
|
153
|
+
|
|
150
154
|
// Load handlers as needed.
|
|
151
155
|
if (this.handlers.length) {
|
|
152
156
|
for (const handler of this.handlers) {
|
package/test/errors.test.ts
CHANGED
|
@@ -11,6 +11,7 @@ describe('handleErrorResponse', () => {
|
|
|
11
11
|
assert.ok(errors.buildHttpError(408, 'timeout') instanceof httpErrors.TimeoutError);
|
|
12
12
|
assert.ok(errors.buildHttpError(410, 'resource gone') instanceof httpErrors.ResourceGoneError);
|
|
13
13
|
assert.ok(errors.buildHttpError(422, 'unprocessable entity') instanceof httpErrors.UnprocessableEntityError);
|
|
14
|
+
assert.ok(errors.buildHttpError(423, 'resource gone') instanceof httpErrors.ProviderInstanceLockedError);
|
|
14
15
|
assert.ok(errors.buildHttpError(429, 'rate limit exceeded') instanceof httpErrors.RateLimitExceededError);
|
|
15
16
|
assert.ok(errors.buildHttpError(500, 'internal server error') instanceof httpErrors.HttpError);
|
|
16
17
|
});
|