@furystack/rest-service 4.0.19
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/LICENSE +339 -0
- package/README.md +219 -0
- package/dist/actions/error-action.d.ts +14 -0
- package/dist/actions/error-action.d.ts.map +1 -0
- package/dist/actions/error-action.js +29 -0
- package/dist/actions/error-action.js.map +1 -0
- package/dist/actions/error-action.spec.d.ts +2 -0
- package/dist/actions/error-action.spec.d.ts.map +1 -0
- package/dist/actions/error-action.spec.js +51 -0
- package/dist/actions/error-action.spec.js.map +1 -0
- package/dist/actions/get-current-user.d.ts +11 -0
- package/dist/actions/get-current-user.d.ts.map +1 -0
- package/dist/actions/get-current-user.js +15 -0
- package/dist/actions/get-current-user.js.map +1 -0
- package/dist/actions/get-current-user.spec.d.ts +2 -0
- package/dist/actions/get-current-user.spec.d.ts.map +1 -0
- package/dist/actions/get-current-user.spec.js +20 -0
- package/dist/actions/get-current-user.spec.js.map +1 -0
- package/dist/actions/index.d.ts +7 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +10 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/is-authenticated.d.ts +14 -0
- package/dist/actions/is-authenticated.d.ts.map +1 -0
- package/dist/actions/is-authenticated.js +17 -0
- package/dist/actions/is-authenticated.js.map +1 -0
- package/dist/actions/is-authenticated.spec.d.ts +2 -0
- package/dist/actions/is-authenticated.spec.d.ts.map +1 -0
- package/dist/actions/is-authenticated.spec.js +19 -0
- package/dist/actions/is-authenticated.spec.js.map +1 -0
- package/dist/actions/login-action.spec.d.ts +2 -0
- package/dist/actions/login-action.spec.d.ts.map +1 -0
- package/dist/actions/login-action.spec.js +35 -0
- package/dist/actions/login-action.spec.js.map +1 -0
- package/dist/actions/login.d.ts +16 -0
- package/dist/actions/login.d.ts.map +1 -0
- package/dist/actions/login.js +26 -0
- package/dist/actions/login.js.map +1 -0
- package/dist/actions/logout-action.spec.d.ts +2 -0
- package/dist/actions/logout-action.spec.d.ts.map +1 -0
- package/dist/actions/logout-action.spec.js +23 -0
- package/dist/actions/logout-action.spec.js.map +1 -0
- package/dist/actions/logout.d.ts +14 -0
- package/dist/actions/logout.d.ts.map +1 -0
- package/dist/actions/logout.js +20 -0
- package/dist/actions/logout.js.map +1 -0
- package/dist/actions/not-found-action.d.ts +10 -0
- package/dist/actions/not-found-action.d.ts.map +1 -0
- package/dist/actions/not-found-action.js +14 -0
- package/dist/actions/not-found-action.js.map +1 -0
- package/dist/actions/not-found-action.spec.d.ts +2 -0
- package/dist/actions/not-found-action.spec.d.ts.map +1 -0
- package/dist/actions/not-found-action.spec.js +17 -0
- package/dist/actions/not-found-action.spec.js.map +1 -0
- package/dist/add-cors-header.spec.d.ts +2 -0
- package/dist/add-cors-header.spec.d.ts.map +1 -0
- package/dist/add-cors-header.spec.js +99 -0
- package/dist/add-cors-header.spec.js.map +1 -0
- package/dist/api-manager.d.ts +61 -0
- package/dist/api-manager.d.ts.map +1 -0
- package/dist/api-manager.js +144 -0
- package/dist/api-manager.js.map +1 -0
- package/dist/authenticate.d.ts +5 -0
- package/dist/authenticate.d.ts.map +1 -0
- package/dist/authenticate.js +20 -0
- package/dist/authenticate.js.map +1 -0
- package/dist/authenticate.spec.d.ts +2 -0
- package/dist/authenticate.spec.d.ts.map +1 -0
- package/dist/authenticate.spec.js +59 -0
- package/dist/authenticate.spec.js.map +1 -0
- package/dist/authorize.d.ts +5 -0
- package/dist/authorize.d.ts.map +1 -0
- package/dist/authorize.js +22 -0
- package/dist/authorize.js.map +1 -0
- package/dist/authorize.spec.d.ts +2 -0
- package/dist/authorize.spec.d.ts.map +1 -0
- package/dist/authorize.spec.js +55 -0
- package/dist/authorize.spec.js.map +1 -0
- package/dist/endpoint-generators/create-delete-endpoint.d.ts +17 -0
- package/dist/endpoint-generators/create-delete-endpoint.d.ts.map +1 -0
- package/dist/endpoint-generators/create-delete-endpoint.js +24 -0
- package/dist/endpoint-generators/create-delete-endpoint.js.map +1 -0
- package/dist/endpoint-generators/create-delete-endpoint.spec.d.ts +2 -0
- package/dist/endpoint-generators/create-delete-endpoint.spec.d.ts.map +1 -0
- package/dist/endpoint-generators/create-delete-endpoint.spec.js +33 -0
- package/dist/endpoint-generators/create-delete-endpoint.spec.js.map +1 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.d.ts +17 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.js +26 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.js.map +1 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.d.ts +2 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.d.ts.map +1 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js +143 -0
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.d.ts +17 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.js +29 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.js.map +1 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.d.ts +2 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.d.ts.map +1 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js +74 -0
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -0
- package/dist/endpoint-generators/create-patch-endpoint.d.ts +18 -0
- package/dist/endpoint-generators/create-patch-endpoint.d.ts.map +1 -0
- package/dist/endpoint-generators/create-patch-endpoint.js +26 -0
- package/dist/endpoint-generators/create-patch-endpoint.js.map +1 -0
- package/dist/endpoint-generators/create-patch-endpoint.spec.d.ts +2 -0
- package/dist/endpoint-generators/create-patch-endpoint.spec.d.ts.map +1 -0
- package/dist/endpoint-generators/create-patch-endpoint.spec.js +36 -0
- package/dist/endpoint-generators/create-patch-endpoint.spec.js.map +1 -0
- package/dist/endpoint-generators/create-post-endpoint.d.ts +18 -0
- package/dist/endpoint-generators/create-post-endpoint.d.ts.map +1 -0
- package/dist/endpoint-generators/create-post-endpoint.js +29 -0
- package/dist/endpoint-generators/create-post-endpoint.js.map +1 -0
- package/dist/endpoint-generators/create-post-endpoint.spec.d.ts +2 -0
- package/dist/endpoint-generators/create-post-endpoint.spec.d.ts.map +1 -0
- package/dist/endpoint-generators/create-post-endpoint.spec.js +34 -0
- package/dist/endpoint-generators/create-post-endpoint.spec.js.map +1 -0
- package/dist/endpoint-generators/index.d.ts +6 -0
- package/dist/endpoint-generators/index.d.ts.map +1 -0
- package/dist/endpoint-generators/index.js +9 -0
- package/dist/endpoint-generators/index.js.map +1 -0
- package/dist/endpoint-generators/utils.d.ts +9 -0
- package/dist/endpoint-generators/utils.d.ts.map +1 -0
- package/dist/endpoint-generators/utils.js +27 -0
- package/dist/endpoint-generators/utils.js.map +1 -0
- package/dist/http-authentication-settings.d.ts +17 -0
- package/dist/http-authentication-settings.d.ts.map +1 -0
- package/dist/http-authentication-settings.js +26 -0
- package/dist/http-authentication-settings.js.map +1 -0
- package/dist/http-user-context.d.ts +54 -0
- package/dist/http-user-context.d.ts.map +1 -0
- package/dist/http-user-context.js +153 -0
- package/dist/http-user-context.js.map +1 -0
- package/dist/http-user-context.spec.d.ts +4 -0
- package/dist/http-user-context.spec.d.ts.map +1 -0
- package/dist/http-user-context.spec.js +267 -0
- package/dist/http-user-context.spec.js.map +1 -0
- package/dist/incoming-message-extensions.d.ts +8 -0
- package/dist/incoming-message-extensions.d.ts.map +1 -0
- package/dist/incoming-message-extensions.js +14 -0
- package/dist/incoming-message-extensions.js.map +1 -0
- package/dist/incoming-message-extensions.spec.d.ts +2 -0
- package/dist/incoming-message-extensions.spec.d.ts.map +1 -0
- package/dist/incoming-message-extensions.spec.js +39 -0
- package/dist/incoming-message-extensions.spec.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/injector-extensions.d.ts +21 -0
- package/dist/injector-extensions.d.ts.map +1 -0
- package/dist/injector-extensions.js +14 -0
- package/dist/injector-extensions.js.map +1 -0
- package/dist/injector-extensions.spec.d.ts +2 -0
- package/dist/injector-extensions.spec.d.ts.map +1 -0
- package/dist/injector-extensions.spec.js +19 -0
- package/dist/injector-extensions.spec.js.map +1 -0
- package/dist/models/cors-options.d.ts +22 -0
- package/dist/models/cors-options.d.ts.map +1 -0
- package/dist/models/cors-options.js +3 -0
- package/dist/models/cors-options.js.map +1 -0
- package/dist/models/default-session.d.ts +14 -0
- package/dist/models/default-session.d.ts.map +1 -0
- package/dist/models/default-session.js +10 -0
- package/dist/models/default-session.js.map +1 -0
- package/dist/request-action-implementation.d.ts +54 -0
- package/dist/request-action-implementation.d.ts.map +1 -0
- package/dist/request-action-implementation.js +42 -0
- package/dist/request-action-implementation.js.map +1 -0
- package/dist/rest-service.integration.spec.d.ts +2 -0
- package/dist/rest-service.integration.spec.d.ts.map +1 -0
- package/dist/rest-service.integration.spec.js +129 -0
- package/dist/rest-service.integration.spec.js.map +1 -0
- package/dist/rest.integration.test.d.ts +58 -0
- package/dist/rest.integration.test.d.ts.map +1 -0
- package/dist/rest.integration.test.js +94 -0
- package/dist/rest.integration.test.js.map +1 -0
- package/dist/schema-validator/index.d.ts +3 -0
- package/dist/schema-validator/index.d.ts.map +1 -0
- package/dist/schema-validator/index.js +6 -0
- package/dist/schema-validator/index.js.map +1 -0
- package/dist/schema-validator/schema-validation-error.d.ts +10 -0
- package/dist/schema-validator/schema-validation-error.d.ts.map +1 -0
- package/dist/schema-validator/schema-validation-error.js +15 -0
- package/dist/schema-validator/schema-validation-error.js.map +1 -0
- package/dist/schema-validator/schema-validator.d.ts +20 -0
- package/dist/schema-validator/schema-validator.d.ts.map +1 -0
- package/dist/schema-validator/schema-validator.js +36 -0
- package/dist/schema-validator/schema-validator.js.map +1 -0
- package/dist/schema-validator/schema-validator.test.d.ts +2 -0
- package/dist/schema-validator/schema-validator.test.d.ts.map +1 -0
- package/dist/schema-validator/schema-validator.test.js +62 -0
- package/dist/schema-validator/schema-validator.test.js.map +1 -0
- package/dist/schema-validator/validate-examples.d.ts +37 -0
- package/dist/schema-validator/validate-examples.d.ts.map +1 -0
- package/dist/schema-validator/validate-examples.js +29 -0
- package/dist/schema-validator/validate-examples.js.map +1 -0
- package/dist/server-manager.d.ts +30 -0
- package/dist/server-manager.d.ts.map +1 -0
- package/dist/server-manager.js +71 -0
- package/dist/server-manager.js.map +1 -0
- package/dist/server-response-extensions.d.ts +21 -0
- package/dist/server-response-extensions.d.ts.map +1 -0
- package/dist/server-response-extensions.js +15 -0
- package/dist/server-response-extensions.js.map +1 -0
- package/dist/server-response-extensions.spec.d.ts +2 -0
- package/dist/server-response-extensions.spec.d.ts.map +1 -0
- package/dist/server-response-extensions.spec.js +49 -0
- package/dist/server-response-extensions.spec.js.map +1 -0
- package/dist/utils.d.ts +24 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +66 -0
- package/dist/utils.js.map +1 -0
- package/dist/validate.d.ts +18 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.integration.schema.d.ts +69 -0
- package/dist/validate.integration.schema.d.ts.map +1 -0
- package/dist/validate.integration.schema.js +3 -0
- package/dist/validate.integration.schema.js.map +1 -0
- package/dist/validate.integration.spec.d.ts +13 -0
- package/dist/validate.integration.spec.d.ts.map +1 -0
- package/dist/validate.integration.spec.js +223 -0
- package/dist/validate.integration.spec.js.map +1 -0
- package/dist/validate.integration.spec.schema.json +749 -0
- package/dist/validate.js +49 -0
- package/dist/validate.js.map +1 -0
- package/package.json +56 -0
- package/src/actions/error-action.spec.ts +54 -0
- package/src/actions/error-action.ts +34 -0
- package/src/actions/get-current-user.spec.ts +23 -0
- package/src/actions/get-current-user.ts +15 -0
- package/src/actions/index.ts +6 -0
- package/src/actions/is-authenticated.spec.ts +18 -0
- package/src/actions/is-authenticated.ts +13 -0
- package/src/actions/login-action.spec.ts +41 -0
- package/src/actions/login.ts +26 -0
- package/src/actions/logout-action.spec.ts +27 -0
- package/src/actions/logout.ts +16 -0
- package/src/actions/not-found-action.spec.ts +17 -0
- package/src/actions/not-found-action.ts +13 -0
- package/src/add-cors-header.spec.ts +133 -0
- package/src/api-manager.ts +222 -0
- package/src/authenticate.spec.ts +78 -0
- package/src/authenticate.ts +22 -0
- package/src/authorize.spec.ts +69 -0
- package/src/authorize.ts +19 -0
- package/src/endpoint-generators/create-delete-endpoint.spec.ts +34 -0
- package/src/endpoint-generators/create-delete-endpoint.ts +25 -0
- package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +164 -0
- package/src/endpoint-generators/create-get-collection-endpoint.ts +28 -0
- package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +75 -0
- package/src/endpoint-generators/create-get-entity-endpoint.ts +29 -0
- package/src/endpoint-generators/create-patch-endpoint.spec.ts +36 -0
- package/src/endpoint-generators/create-patch-endpoint.ts +27 -0
- package/src/endpoint-generators/create-post-endpoint.spec.ts +32 -0
- package/src/endpoint-generators/create-post-endpoint.ts +30 -0
- package/src/endpoint-generators/index.ts +5 -0
- package/src/endpoint-generators/utils.ts +34 -0
- package/src/http-authentication-settings.ts +23 -0
- package/src/http-user-context.spec.ts +299 -0
- package/src/http-user-context.ts +160 -0
- package/src/incoming-message-extensions.spec.ts +41 -0
- package/src/incoming-message-extensions.ts +19 -0
- package/src/index.ts +16 -0
- package/src/injector-extensions.spec.ts +19 -0
- package/src/injector-extensions.ts +35 -0
- package/src/models/cors-options.ts +21 -0
- package/src/models/default-session.ts +14 -0
- package/src/request-action-implementation.ts +70 -0
- package/src/rest-service.integration.spec.ts +166 -0
- package/src/rest.integration.test.ts +112 -0
- package/src/schema-validator/index.ts +2 -0
- package/src/schema-validator/schema-validation-error.ts +11 -0
- package/src/schema-validator/schema-validator.test.ts +72 -0
- package/src/schema-validator/schema-validator.ts +31 -0
- package/src/schema-validator/validate-examples.ts +38 -0
- package/src/server-manager.ts +88 -0
- package/src/server-response-extensions.spec.ts +53 -0
- package/src/server-response-extensions.ts +30 -0
- package/src/utils.ts +65 -0
- package/src/validate.integration.schema.ts +50 -0
- package/src/validate.integration.spec.schema.json +779 -0
- package/src/validate.integration.spec.ts +218 -0
- package/src/validate.ts +60 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestAction } from '../request-action-implementation';
|
|
2
|
+
/**
|
|
3
|
+
* Action for unhandled (500) errors
|
|
4
|
+
* Returns a serialized error instance in JSON format.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ErrorAction: RequestAction<{
|
|
7
|
+
body: unknown;
|
|
8
|
+
result: {
|
|
9
|
+
message: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
stack?: string;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=error-action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-action.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAG5E;;;GAGG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAC1D,CAoBA,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorAction = void 0;
|
|
4
|
+
const rest_1 = require("@furystack/rest");
|
|
5
|
+
const core_1 = require("@furystack/core");
|
|
6
|
+
const request_action_implementation_1 = require("../request-action-implementation");
|
|
7
|
+
const schema_validator_1 = require("../schema-validator");
|
|
8
|
+
/**
|
|
9
|
+
* Action for unhandled (500) errors
|
|
10
|
+
* Returns a serialized error instance in JSON format.
|
|
11
|
+
*/
|
|
12
|
+
const ErrorAction = async ({ getBody, request }) => {
|
|
13
|
+
const body = await getBody();
|
|
14
|
+
if (body instanceof schema_validator_1.SchemaValidationError) {
|
|
15
|
+
return (0, request_action_implementation_1.JsonResult)({ message: body.message, stack: body.stack, errors: body.errors }, 400);
|
|
16
|
+
}
|
|
17
|
+
if (body instanceof rest_1.RequestError) {
|
|
18
|
+
return (0, request_action_implementation_1.JsonResult)({ message: body.message, url: request.url, stack: body.stack }, body.responseCode);
|
|
19
|
+
}
|
|
20
|
+
if (body instanceof core_1.AuthorizationError) {
|
|
21
|
+
return (0, request_action_implementation_1.JsonResult)({ message: body.message, url: request.url, stack: body.stack }, 403);
|
|
22
|
+
}
|
|
23
|
+
if (body instanceof Error) {
|
|
24
|
+
return (0, request_action_implementation_1.JsonResult)({ message: body.message, url: request.url, stack: body.stack }, 500);
|
|
25
|
+
}
|
|
26
|
+
return (0, request_action_implementation_1.JsonResult)({ message: 'An unexpected error happened' }, 500);
|
|
27
|
+
};
|
|
28
|
+
exports.ErrorAction = ErrorAction;
|
|
29
|
+
//# sourceMappingURL=error-action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-action.js","sourceRoot":"","sources":["../../src/actions/error-action.ts"],"names":[],"mappings":";;;AAAA,0CAA8C;AAC9C,0CAAoD;AACpD,oFAA4E;AAC5E,0DAA2D;AAE3D;;;GAGG;AAEI,MAAM,WAAW,GAGnB,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE;IAClC,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE,CAAA;IAE5B,IAAI,IAAI,YAAY,wCAAqB,EAAE;QACzC,OAAO,IAAA,0CAAU,EAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,CAAA;KAC1F;IAED,IAAI,IAAI,YAAY,mBAAY,EAAE;QAChC,OAAO,IAAA,0CAAU,EAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;KACrG;IAED,IAAI,IAAI,YAAY,yBAAkB,EAAE;QACtC,OAAO,IAAA,0CAAU,EAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,CAAA;KACvF;IAED,IAAI,IAAI,YAAY,KAAK,EAAE;QACzB,OAAO,IAAA,0CAAU,EAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,CAAA;KACvF;IAED,OAAO,IAAA,0CAAU,EAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,EAAE,GAAG,CAAC,CAAA;AACrE,CAAC,CAAA;AAvBY,QAAA,WAAW,eAuBvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-action.spec.d.ts","sourceRoot":"","sources":["../../src/actions/error-action.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const inject_1 = require("@furystack/inject");
|
|
4
|
+
const utils_1 = require("@furystack/utils");
|
|
5
|
+
const error_action_1 = require("./error-action");
|
|
6
|
+
const rest_1 = require("@furystack/rest");
|
|
7
|
+
const core_1 = require("@furystack/core");
|
|
8
|
+
describe('ErrorAction tests', () => {
|
|
9
|
+
const request = { url: 'https://google.com' };
|
|
10
|
+
const response = {};
|
|
11
|
+
it('returns the error in the standard format', async () => {
|
|
12
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
13
|
+
const result = await (0, error_action_1.ErrorAction)({
|
|
14
|
+
injector: i,
|
|
15
|
+
getBody: async () => new Error('Something went wrong'),
|
|
16
|
+
request,
|
|
17
|
+
response,
|
|
18
|
+
});
|
|
19
|
+
expect(result.statusCode).toBe(500);
|
|
20
|
+
expect(result.chunk.message).toBe('Something went wrong');
|
|
21
|
+
expect(result.chunk.url).toBe('https://google.com');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it('returns the error code from request errors', async () => {
|
|
25
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
26
|
+
const result = await (0, error_action_1.ErrorAction)({
|
|
27
|
+
request,
|
|
28
|
+
response,
|
|
29
|
+
injector: i,
|
|
30
|
+
getBody: async () => new rest_1.RequestError('Something went wrong', 401),
|
|
31
|
+
});
|
|
32
|
+
expect(result.statusCode).toBe(401);
|
|
33
|
+
expect(result.chunk.message).toBe('Something went wrong');
|
|
34
|
+
expect(result.chunk.url).toBe('https://google.com');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it('returns the 403 for authorization errors', async () => {
|
|
38
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
39
|
+
const result = await (0, error_action_1.ErrorAction)({
|
|
40
|
+
request,
|
|
41
|
+
response,
|
|
42
|
+
injector: i,
|
|
43
|
+
getBody: async () => new core_1.AuthorizationError('Something went wrong'),
|
|
44
|
+
});
|
|
45
|
+
expect(result.statusCode).toBe(403);
|
|
46
|
+
expect(result.chunk.message).toBe('Something went wrong');
|
|
47
|
+
expect(result.chunk.url).toBe('https://google.com');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
//# sourceMappingURL=error-action.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-action.spec.js","sourceRoot":"","sources":["../../src/actions/error-action.spec.ts"],"names":[],"mappings":";;AAAA,8CAA4C;AAC5C,4CAA6C;AAC7C,iDAA4C;AAE5C,0CAA8C;AAC9C,0CAAoD;AAGpD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAqB,CAAA;IAChE,MAAM,QAAQ,GAAG,EAAoB,CAAA;IAErC,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAW,EAAC;gBAC/B,QAAQ,EAAE,CAAC;gBACX,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC;gBACtD,OAAO;gBACP,QAAQ;aACT,CAAC,CAAA;YACF,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;YACzD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAW,EAAC;gBAC/B,OAAO;gBACP,QAAQ;gBACR,QAAQ,EAAE,CAAC;gBACX,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,mBAAY,CAAC,sBAAsB,EAAE,GAAG,CAAC;aACnE,CAAC,CAAA;YACF,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;YACzD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,KAAK,IAAI,EAAE;QACxD,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,IAAA,0BAAW,EAAC;gBAC/B,OAAO;gBACP,QAAQ;gBACR,QAAQ,EAAE,CAAC;gBACX,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,yBAAkB,CAAC,sBAAsB,CAAC;aACpE,CAAC,CAAA;YACF,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;YACzD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { User } from '@furystack/core';
|
|
2
|
+
import { RequestAction } from '../request-action-implementation';
|
|
3
|
+
/**
|
|
4
|
+
* Action that returns the current authenticated user
|
|
5
|
+
*
|
|
6
|
+
* @param injector The injector from the current stack
|
|
7
|
+
*/
|
|
8
|
+
export declare const GetCurrentUser: RequestAction<{
|
|
9
|
+
result: User;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=get-current-user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../src/actions/get-current-user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAc,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAE5E;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,aAAa,CAAC;IACzC,MAAM,EAAE,IAAI,CAAA;CACb,CAGC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetCurrentUser = void 0;
|
|
4
|
+
const authenticate_1 = require("../authenticate");
|
|
5
|
+
const request_action_implementation_1 = require("../request-action-implementation");
|
|
6
|
+
/**
|
|
7
|
+
* Action that returns the current authenticated user
|
|
8
|
+
*
|
|
9
|
+
* @param injector The injector from the current stack
|
|
10
|
+
*/
|
|
11
|
+
exports.GetCurrentUser = (0, authenticate_1.Authenticate)()(async ({ injector }) => {
|
|
12
|
+
const user = await injector.getCurrentUser();
|
|
13
|
+
return (0, request_action_implementation_1.JsonResult)(user);
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=get-current-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-current-user.js","sourceRoot":"","sources":["../../src/actions/get-current-user.ts"],"names":[],"mappings":";;;AACA,kDAA8C;AAC9C,oFAA4E;AAE5E;;;;GAIG;AACU,QAAA,cAAc,GAEtB,IAAA,2BAAY,GAAE,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IACzC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,cAAc,EAAE,CAAA;IAC5C,OAAO,IAAA,0CAAU,EAAC,IAAI,CAAC,CAAA;AACzB,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-current-user.spec.d.ts","sourceRoot":"","sources":["../../src/actions/get-current-user.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const inject_1 = require("@furystack/inject");
|
|
4
|
+
const utils_1 = require("@furystack/utils");
|
|
5
|
+
const get_current_user_1 = require("./get-current-user");
|
|
6
|
+
const core_1 = require("@furystack/core");
|
|
7
|
+
describe('getCurrentUser', () => {
|
|
8
|
+
const request = { url: 'https://google.com' };
|
|
9
|
+
const response = {};
|
|
10
|
+
it('exec', async () => {
|
|
11
|
+
const testUser = { Name: 'Userke' };
|
|
12
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
13
|
+
i.setExplicitInstance({ getCurrentUser: async () => testUser, isAuthenticated: async () => true }, core_1.IdentityContext);
|
|
14
|
+
const result = await (0, get_current_user_1.GetCurrentUser)({ injector: i, request, response });
|
|
15
|
+
expect(result.statusCode).toBe(200);
|
|
16
|
+
expect(result.chunk).toEqual(testUser);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=get-current-user.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-current-user.spec.js","sourceRoot":"","sources":["../../src/actions/get-current-user.spec.ts"],"names":[],"mappings":";;AAAA,8CAA4C;AAC5C,4CAA6C;AAC7C,yDAAmD;AAEnD,0CAAiD;AAEjD,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAqB,CAAA;IAChE,MAAM,QAAQ,GAAG,EAAoB,CAAA;IAErC,EAAE,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;QACpB,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;QACnC,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,CAAC,CAAC,mBAAmB,CACnB,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,CAAC,QAAQ,EAAE,eAAe,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,EAC3E,sBAAe,CAChB,CAAA;YACD,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAc,EAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAA;YACvE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,oBAAoB,CAAA;AAClC,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
(0, tslib_1.__exportStar)(require("./error-action"), exports);
|
|
5
|
+
(0, tslib_1.__exportStar)(require("./get-current-user"), exports);
|
|
6
|
+
(0, tslib_1.__exportStar)(require("./is-authenticated"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./login"), exports);
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./logout"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./not-found-action"), exports);
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;AAAA,8DAA8B;AAC9B,kEAAkC;AAClC,kEAAkC;AAClC,uDAAuB;AACvB,wDAAwB;AACxB,kEAAkC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestAction } from '../request-action-implementation';
|
|
2
|
+
/**
|
|
3
|
+
* Action that returns if the current user is authenticated
|
|
4
|
+
*
|
|
5
|
+
* @param options The options for the Custom Action
|
|
6
|
+
* @param options.injector The Injector from the current context
|
|
7
|
+
* @returns A standard authentication result
|
|
8
|
+
*/
|
|
9
|
+
export declare const IsAuthenticated: RequestAction<{
|
|
10
|
+
result: {
|
|
11
|
+
isAuthenticated: boolean;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=is-authenticated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-authenticated.d.ts","sourceRoot":"","sources":["../../src/actions/is-authenticated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAE5E;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE;QAAE,eAAe,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAGnF,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IsAuthenticated = void 0;
|
|
4
|
+
const request_action_implementation_1 = require("../request-action-implementation");
|
|
5
|
+
/**
|
|
6
|
+
* Action that returns if the current user is authenticated
|
|
7
|
+
*
|
|
8
|
+
* @param options The options for the Custom Action
|
|
9
|
+
* @param options.injector The Injector from the current context
|
|
10
|
+
* @returns A standard authentication result
|
|
11
|
+
*/
|
|
12
|
+
const IsAuthenticated = async ({ injector }) => {
|
|
13
|
+
const isAuthenticated = await injector.isAuthenticated();
|
|
14
|
+
return (0, request_action_implementation_1.JsonResult)({ isAuthenticated });
|
|
15
|
+
};
|
|
16
|
+
exports.IsAuthenticated = IsAuthenticated;
|
|
17
|
+
//# sourceMappingURL=is-authenticated.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-authenticated.js","sourceRoot":"","sources":["../../src/actions/is-authenticated.ts"],"names":[],"mappings":";;;AAAA,oFAA4E;AAE5E;;;;;;GAMG;AACI,MAAM,eAAe,GAA4D,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7G,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAC,eAAe,EAAE,CAAA;IACxD,OAAO,IAAA,0CAAU,EAAC,EAAE,eAAe,EAAE,CAAC,CAAA;AACxC,CAAC,CAAA;AAHY,QAAA,eAAe,mBAG3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-authenticated.spec.d.ts","sourceRoot":"","sources":["../../src/actions/is-authenticated.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const inject_1 = require("@furystack/inject");
|
|
4
|
+
const utils_1 = require("@furystack/utils");
|
|
5
|
+
const is_authenticated_1 = require("./is-authenticated");
|
|
6
|
+
const core_1 = require("@furystack/core");
|
|
7
|
+
describe('isAuthenticated', () => {
|
|
8
|
+
const request = { url: 'https://google.com' };
|
|
9
|
+
const response = {};
|
|
10
|
+
it('exec', async () => {
|
|
11
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
12
|
+
i.setExplicitInstance({ isAuthenticated: async () => true }, core_1.IdentityContext);
|
|
13
|
+
const result = await (0, is_authenticated_1.IsAuthenticated)({ injector: i, request, response });
|
|
14
|
+
expect(result.statusCode).toBe(200);
|
|
15
|
+
expect(result.chunk).toEqual({ isAuthenticated: true });
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=is-authenticated.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-authenticated.spec.js","sourceRoot":"","sources":["../../src/actions/is-authenticated.spec.ts"],"names":[],"mappings":";;AAAA,8CAA4C;AAC5C,4CAA6C;AAC7C,yDAAoD;AAEpD,0CAAiD;AAEjD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAqB,CAAA;IAChE,MAAM,QAAQ,GAAG,EAAoB,CAAA;IACrC,EAAE,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;QACpB,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,CAAC,CAAC,mBAAmB,CAAC,EAAE,eAAe,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,sBAAe,CAAC,CAAA;YAC7E,MAAM,MAAM,GAAG,MAAM,IAAA,kCAAe,EAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAS,CAAC,CAAA;YAC/E,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-action.spec.d.ts","sourceRoot":"","sources":["../../src/actions/login-action.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const inject_1 = require("@furystack/inject");
|
|
4
|
+
const utils_1 = require("@furystack/utils");
|
|
5
|
+
const login_1 = require("./login");
|
|
6
|
+
const http_user_context_1 = require("../http-user-context");
|
|
7
|
+
describe('LoginAction', () => {
|
|
8
|
+
const request = { url: 'https://google.com' };
|
|
9
|
+
const response = {};
|
|
10
|
+
it('Returns the provided user with 200 on success', async () => {
|
|
11
|
+
const testUser = { Name: 'Userke' };
|
|
12
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
13
|
+
i.setExplicitInstance({
|
|
14
|
+
authenticateUser: jest.fn(async () => testUser),
|
|
15
|
+
cookieLogin: jest.fn(async () => testUser),
|
|
16
|
+
authentication: {},
|
|
17
|
+
}, http_user_context_1.HttpUserContext);
|
|
18
|
+
const result = await (0, login_1.LoginAction)({
|
|
19
|
+
request,
|
|
20
|
+
response,
|
|
21
|
+
injector: i,
|
|
22
|
+
getBody: async () => ({ username: 'testuser', password: 'alma' }),
|
|
23
|
+
});
|
|
24
|
+
expect(result.chunk).toEqual(testUser);
|
|
25
|
+
expect(result.statusCode).toBe(200);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
it('Returns throw error with 400 on fail', async () => {
|
|
29
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
30
|
+
i.setExplicitInstance({ cookieLogin: async () => Promise.reject(':(') }, http_user_context_1.HttpUserContext);
|
|
31
|
+
await expect((0, login_1.LoginAction)({ request, response, injector: i, getBody: async () => ({ username: '', password: '' }) })).rejects.toThrowError('Login Failed');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=login-action.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-action.spec.js","sourceRoot":"","sources":["../../src/actions/login-action.spec.ts"],"names":[],"mappings":";;AACA,8CAA4C;AAC5C,4CAA6C;AAC7C,mCAAqC;AACrC,4DAAsD;AAEtD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAqB,CAAA;IAChE,MAAM,QAAQ,GAAG,EAAoB,CAAA;IAErC,EAAE,CAAC,+CAA+C,EAAE,KAAK,IAAI,EAAE;QAC7D,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;QACnC,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,CAAC,CAAC,mBAAmB,CACnB;gBACE,gBAAgB,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC;gBAC/C,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,QAAQ,CAAC;gBAC1C,cAAc,EAAE,EAAE;aACnB,EACD,mCAAe,CAChB,CAAA;YACD,MAAM,MAAM,GAAG,MAAM,IAAA,mBAAW,EAAC;gBAC/B,OAAO;gBACP,QAAQ;gBACR,QAAQ,EAAE,CAAC;gBACX,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;aAC3D,CAAC,CAAA;YACT,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YACtC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,CAAC,CAAC,mBAAmB,CAAC,EAAE,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,mCAAe,CAAC,CAAA;YACzF,MAAM,MAAM,CACV,IAAA,mBAAW,EAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CACvG,CAAC,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;QACxC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import '../injector-extensions';
|
|
2
|
+
import { User } from '@furystack/core';
|
|
3
|
+
import { RequestAction } from '../request-action-implementation';
|
|
4
|
+
/**
|
|
5
|
+
* Action that logs in the current user
|
|
6
|
+
* Should be called with a JSON Post body with ``username`` and ``password`` fields.
|
|
7
|
+
* Returns the current user instance
|
|
8
|
+
*/
|
|
9
|
+
export declare const LoginAction: RequestAction<{
|
|
10
|
+
result: User;
|
|
11
|
+
body: {
|
|
12
|
+
username: string;
|
|
13
|
+
password: string;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":"AACA,OAAO,wBAAwB,CAAA;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEtC,OAAO,EAAc,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAE5E;;;;GAIG;AAEH,eAAO,MAAM,WAAW,EAAE,aAAa,CAAC;IACtC,MAAM,EAAE,IAAI,CAAA;IACZ,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC7C,CAUA,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoginAction = void 0;
|
|
4
|
+
const http_user_context_1 = require("../http-user-context");
|
|
5
|
+
require("../injector-extensions");
|
|
6
|
+
const rest_1 = require("@furystack/rest");
|
|
7
|
+
const request_action_implementation_1 = require("../request-action-implementation");
|
|
8
|
+
/**
|
|
9
|
+
* Action that logs in the current user
|
|
10
|
+
* Should be called with a JSON Post body with ``username`` and ``password`` fields.
|
|
11
|
+
* Returns the current user instance
|
|
12
|
+
*/
|
|
13
|
+
const LoginAction = async ({ injector, getBody, response }) => {
|
|
14
|
+
const userContext = injector.getInstance(http_user_context_1.HttpUserContext);
|
|
15
|
+
const body = await getBody();
|
|
16
|
+
try {
|
|
17
|
+
const user = await userContext.authenticateUser(body.username, body.password);
|
|
18
|
+
await userContext.cookieLogin(user, response);
|
|
19
|
+
return (0, request_action_implementation_1.JsonResult)(user, 200);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
throw new rest_1.RequestError('Login Failed', 400);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.LoginAction = LoginAction;
|
|
26
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/actions/login.ts"],"names":[],"mappings":";;;AAAA,4DAAsD;AACtD,kCAA+B;AAE/B,0CAA8C;AAC9C,oFAA4E;AAE5E;;;;GAIG;AAEI,MAAM,WAAW,GAGnB,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;IAC7C,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,mCAAe,CAAC,CAAA;IACzD,MAAM,IAAI,GAAG,MAAM,OAAO,EAAE,CAAA;IAC5B,IAAI;QACF,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC7E,MAAM,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QAC7C,OAAO,IAAA,0CAAU,EAAC,IAAI,EAAE,GAAG,CAAC,CAAA;KAC7B;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,IAAI,mBAAY,CAAC,cAAc,EAAE,GAAG,CAAC,CAAA;KAC5C;AACH,CAAC,CAAA;AAbY,QAAA,WAAW,eAavB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout-action.spec.d.ts","sourceRoot":"","sources":["../../src/actions/logout-action.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const inject_1 = require("@furystack/inject");
|
|
4
|
+
const utils_1 = require("@furystack/utils");
|
|
5
|
+
const http_user_context_1 = require("../http-user-context");
|
|
6
|
+
const logout_1 = require("./logout");
|
|
7
|
+
describe('LogoutAction', () => {
|
|
8
|
+
const request = { url: 'https://google.com' };
|
|
9
|
+
const response = {};
|
|
10
|
+
it('exec', async () => {
|
|
11
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
12
|
+
const cookieLogout = jest.fn(async () => true);
|
|
13
|
+
i.setExplicitInstance({
|
|
14
|
+
cookieLogout,
|
|
15
|
+
}, http_user_context_1.HttpUserContext);
|
|
16
|
+
const result = await (0, logout_1.LogoutAction)({ request, response, injector: i });
|
|
17
|
+
expect(result.statusCode).toBe(200);
|
|
18
|
+
expect(result.chunk).toBe(undefined);
|
|
19
|
+
expect(cookieLogout).toBeCalled();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=logout-action.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout-action.spec.js","sourceRoot":"","sources":["../../src/actions/logout-action.spec.ts"],"names":[],"mappings":";;AAAA,8CAA4C;AAC5C,4CAA6C;AAC7C,4DAAsD;AACtD,qCAAuC;AAGvC,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,MAAM,OAAO,GAAG,EAAE,GAAG,EAAE,oBAAoB,EAAqB,CAAA;IAChE,MAAM,QAAQ,GAAG,EAAoB,CAAA;IAErC,EAAE,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE;QACpB,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,CAAA;YAC9C,CAAC,CAAC,mBAAmB,CACnB;gBACE,YAAY;aACb,EACD,mCAAe,CAChB,CAAA;YAED,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAY,EAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAS,CAAC,CAAA;YAC5E,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YACpC,MAAM,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAA;QACnC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestAction } from '../request-action-implementation';
|
|
2
|
+
/**
|
|
3
|
+
* Action that logs out the current user
|
|
4
|
+
*
|
|
5
|
+
* @param root0 The Options object
|
|
6
|
+
* @param root0.injector The injector from the context
|
|
7
|
+
* @param root0.request The current Request object
|
|
8
|
+
* @param root0.response The Response object
|
|
9
|
+
* @returns An empty result that indicates the success
|
|
10
|
+
*/
|
|
11
|
+
export declare const LogoutAction: RequestAction<{
|
|
12
|
+
result: unknown;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=logout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/actions/logout.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAE7E;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAG3D,CAAA"}
|