@unito/integration-sdk 1.0.28 → 1.1.1
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 +4 -1
- package/dist/src/httpErrors.d.ts +6 -0
- package/dist/src/httpErrors.js +8 -0
- package/dist/src/index.cjs +13 -1
- package/dist/src/resources/context.d.ts +1 -1
- package/dist/test/errors.test.js +1 -1
- package/package.json +1 -1
- package/src/errors.ts +3 -1
- package/src/httpErrors.ts +9 -0
- package/src/resources/context.ts +1 -1
- package/test/errors.test.ts +1 -1
package/dist/src/errors.js
CHANGED
|
@@ -13,9 +13,12 @@ export function buildHttpError(responseStatus, message) {
|
|
|
13
13
|
if (responseStatus === 400) {
|
|
14
14
|
httpError = new HttpErrors.BadRequestError(message);
|
|
15
15
|
}
|
|
16
|
-
else if (responseStatus === 401
|
|
16
|
+
else if (responseStatus === 401) {
|
|
17
17
|
httpError = new HttpErrors.UnauthorizedError(message);
|
|
18
18
|
}
|
|
19
|
+
else if (responseStatus === 403) {
|
|
20
|
+
httpError = new HttpErrors.ForbiddenError(message);
|
|
21
|
+
}
|
|
19
22
|
else if (responseStatus === 404) {
|
|
20
23
|
httpError = new HttpErrors.NotFoundError(message);
|
|
21
24
|
}
|
package/dist/src/httpErrors.d.ts
CHANGED
|
@@ -21,6 +21,12 @@ export declare class BadRequestError extends HttpError {
|
|
|
21
21
|
export declare class UnauthorizedError extends HttpError {
|
|
22
22
|
constructor(message?: string);
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Used to generate a 403 Forbidden. Usually used when user lacks sufficient permission to access a ressource.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ForbiddenError extends HttpError {
|
|
28
|
+
constructor(message?: string);
|
|
29
|
+
}
|
|
24
30
|
/**
|
|
25
31
|
* Used to generate a 404 Not Found. Usually used when the requested `Item` is not found.
|
|
26
32
|
*/
|
package/dist/src/httpErrors.js
CHANGED
|
@@ -29,6 +29,14 @@ export class UnauthorizedError extends HttpError {
|
|
|
29
29
|
super(message || 'Unauthorized', 401);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Used to generate a 403 Forbidden. Usually used when user lacks sufficient permission to access a ressource.
|
|
34
|
+
*/
|
|
35
|
+
export class ForbiddenError extends HttpError {
|
|
36
|
+
constructor(message) {
|
|
37
|
+
super(message || 'Forbidden', 403);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
32
40
|
/**
|
|
33
41
|
* Used to generate a 404 Not Found. Usually used when the requested `Item` is not found.
|
|
34
42
|
*/
|
package/dist/src/index.cjs
CHANGED
|
@@ -315,6 +315,14 @@ class UnauthorizedError extends HttpError {
|
|
|
315
315
|
super(message || 'Unauthorized', 401);
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Used to generate a 403 Forbidden. Usually used when user lacks sufficient permission to access a ressource.
|
|
320
|
+
*/
|
|
321
|
+
class ForbiddenError extends HttpError {
|
|
322
|
+
constructor(message) {
|
|
323
|
+
super(message || 'Forbidden', 403);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
318
326
|
/**
|
|
319
327
|
* Used to generate a 404 Not Found. Usually used when the requested `Item` is not found.
|
|
320
328
|
*/
|
|
@@ -370,6 +378,7 @@ class RateLimitExceededError extends HttpError {
|
|
|
370
378
|
var httpErrors = /*#__PURE__*/Object.freeze({
|
|
371
379
|
__proto__: null,
|
|
372
380
|
BadRequestError: BadRequestError,
|
|
381
|
+
ForbiddenError: ForbiddenError,
|
|
373
382
|
HttpError: HttpError,
|
|
374
383
|
NotFoundError: NotFoundError,
|
|
375
384
|
ProviderInstanceLockedError: ProviderInstanceLockedError,
|
|
@@ -394,9 +403,12 @@ function buildHttpError(responseStatus, message) {
|
|
|
394
403
|
if (responseStatus === 400) {
|
|
395
404
|
httpError = new BadRequestError(message);
|
|
396
405
|
}
|
|
397
|
-
else if (responseStatus === 401
|
|
406
|
+
else if (responseStatus === 401) {
|
|
398
407
|
httpError = new UnauthorizedError(message);
|
|
399
408
|
}
|
|
409
|
+
else if (responseStatus === 403) {
|
|
410
|
+
httpError = new ForbiddenError(message);
|
|
411
|
+
}
|
|
400
412
|
else if (responseStatus === 404) {
|
|
401
413
|
httpError = new NotFoundError(message);
|
|
402
414
|
}
|
|
@@ -17,7 +17,7 @@ type UpdateItemBody = API.UpdateItemRequestPayload;
|
|
|
17
17
|
*
|
|
18
18
|
* It contains the parsed request params, query string, credentials, secrets, etc.
|
|
19
19
|
*/
|
|
20
|
-
export type Context<P extends Maybe<Params> = Params
|
|
20
|
+
export type Context<P extends Maybe<Params> = Maybe<Params>, Q extends Maybe<Query> = Maybe<Query>> = {
|
|
21
21
|
/**
|
|
22
22
|
* The parsed credentials associated with the request through the X-Unito-Credentials header.
|
|
23
23
|
*
|
package/dist/test/errors.test.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as httpErrors from '../src/httpErrors.js';
|
|
|
5
5
|
describe('handleErrorResponse', () => {
|
|
6
6
|
it('returns correct httpError given status code', () => {
|
|
7
7
|
assert.ok(errors.buildHttpError(401, 'unauthorized') instanceof httpErrors.UnauthorizedError);
|
|
8
|
-
assert.ok(errors.buildHttpError(403, 'forbidden') instanceof httpErrors.
|
|
8
|
+
assert.ok(errors.buildHttpError(403, 'forbidden') instanceof httpErrors.ForbiddenError);
|
|
9
9
|
assert.ok(errors.buildHttpError(404, 'not found') instanceof httpErrors.NotFoundError);
|
|
10
10
|
assert.ok(errors.buildHttpError(408, 'timeout') instanceof httpErrors.TimeoutError);
|
|
11
11
|
assert.ok(errors.buildHttpError(410, 'resource gone') instanceof httpErrors.ResourceGoneError);
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -13,8 +13,10 @@ export function buildHttpError(responseStatus: number, message: string): HttpErr
|
|
|
13
13
|
let httpError: HttpErrors.HttpError;
|
|
14
14
|
if (responseStatus === 400) {
|
|
15
15
|
httpError = new HttpErrors.BadRequestError(message);
|
|
16
|
-
} else if (responseStatus === 401
|
|
16
|
+
} else if (responseStatus === 401) {
|
|
17
17
|
httpError = new HttpErrors.UnauthorizedError(message);
|
|
18
|
+
} else if (responseStatus === 403) {
|
|
19
|
+
httpError = new HttpErrors.ForbiddenError(message);
|
|
18
20
|
} else if (responseStatus === 404) {
|
|
19
21
|
httpError = new HttpErrors.NotFoundError(message);
|
|
20
22
|
} else if (responseStatus === 408) {
|
package/src/httpErrors.ts
CHANGED
|
@@ -33,6 +33,15 @@ export class UnauthorizedError extends HttpError {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Used to generate a 403 Forbidden. Usually used when user lacks sufficient permission to access a ressource.
|
|
38
|
+
*/
|
|
39
|
+
export class ForbiddenError extends HttpError {
|
|
40
|
+
constructor(message?: string) {
|
|
41
|
+
super(message || 'Forbidden', 403);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
36
45
|
/**
|
|
37
46
|
* Used to generate a 404 Not Found. Usually used when the requested `Item` is not found.
|
|
38
47
|
*/
|
package/src/resources/context.ts
CHANGED
|
@@ -20,7 +20,7 @@ type UpdateItemBody = API.UpdateItemRequestPayload;
|
|
|
20
20
|
*
|
|
21
21
|
* It contains the parsed request params, query string, credentials, secrets, etc.
|
|
22
22
|
*/
|
|
23
|
-
export type Context<P extends Maybe<Params> = Params
|
|
23
|
+
export type Context<P extends Maybe<Params> = Maybe<Params>, Q extends Maybe<Query> = Maybe<Query>> = {
|
|
24
24
|
/**
|
|
25
25
|
* The parsed credentials associated with the request through the X-Unito-Credentials header.
|
|
26
26
|
*
|
package/test/errors.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import * as httpErrors from '../src/httpErrors.js';
|
|
|
6
6
|
describe('handleErrorResponse', () => {
|
|
7
7
|
it('returns correct httpError given status code', () => {
|
|
8
8
|
assert.ok(errors.buildHttpError(401, 'unauthorized') instanceof httpErrors.UnauthorizedError);
|
|
9
|
-
assert.ok(errors.buildHttpError(403, 'forbidden') instanceof httpErrors.
|
|
9
|
+
assert.ok(errors.buildHttpError(403, 'forbidden') instanceof httpErrors.ForbiddenError);
|
|
10
10
|
assert.ok(errors.buildHttpError(404, 'not found') instanceof httpErrors.NotFoundError);
|
|
11
11
|
assert.ok(errors.buildHttpError(408, 'timeout') instanceof httpErrors.TimeoutError);
|
|
12
12
|
assert.ok(errors.buildHttpError(410, 'resource gone') instanceof httpErrors.ResourceGoneError);
|