Socket
Socket
Sign inDemoInstall

@furystack/rest-service

Package Overview
Dependencies
Maintainers
1
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@furystack/rest-service - npm Package Compare versions

Comparing version 2.3.7 to 3.0.0

dist/request-action-implementation.d.ts

2

dist/actions/error-action.d.ts

@@ -1,2 +0,2 @@

import { RequestAction } from '@furystack/rest';
import { RequestAction } from '../request-action-implementation';
/**

@@ -3,0 +3,0 @@ * Action for unhandled (500) errors

@@ -5,4 +5,5 @@ "use strict";

const rest_1 = require("@furystack/rest");
const rest_2 = require("@furystack/rest");
const core_1 = require("@furystack/core");
const request_action_implementation_1 = require("../request-action-implementation");
const schema_validator_1 = require("../schema-validator");
/**

@@ -14,6 +15,9 @@ * Action for unhandled (500) errors

const body = await getBody();
const errorCode = body instanceof rest_2.RequestError ? body.responseCode : body instanceof core_1.AuthorizationError ? 403 : 500;
return rest_1.JsonResult({ message: body.message, url: request.url, stack: body.stack }, errorCode);
if (body instanceof schema_validator_1.SchemaValidationError) {
return request_action_implementation_1.JsonResult({ message: body.message, stack: body.stack, errors: body.errors }, 400);
}
const errorCode = body instanceof rest_1.RequestError ? body.responseCode : body instanceof core_1.AuthorizationError ? 403 : 500;
return request_action_implementation_1.JsonResult({ message: body.message, url: request.url, stack: body.stack }, errorCode);
};
exports.ErrorAction = ErrorAction;
//# sourceMappingURL=error-action.js.map

@@ -1,3 +0,3 @@

import { RequestAction } from '@furystack/rest';
import { User } from '@furystack/core';
import { RequestAction } from '../request-action-implementation';
/**

@@ -4,0 +4,0 @@ * Action that returns the current authenticated user

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetCurrentUser = void 0;
const rest_1 = require("@furystack/rest");
const authenticate_1 = require("../authenticate");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -13,4 +13,4 @@ * Action that returns the current authenticated user

const user = await injector.getCurrentUser();
return rest_1.JsonResult(user);
return request_action_implementation_1.JsonResult(user);
});
//# sourceMappingURL=get-current-user.js.map

@@ -1,2 +0,2 @@

import { RequestAction } from '@furystack/rest';
import { RequestAction } from '../request-action-implementation';
/**

@@ -3,0 +3,0 @@ * Action that returns if the current user is authenticated

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IsAuthenticated = void 0;
const rest_1 = require("@furystack/rest");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -14,5 +14,5 @@ * Action that returns if the current user is authenticated

const isAuthenticated = await injector.isAuthenticated();
return rest_1.JsonResult({ isAuthenticated });
return request_action_implementation_1.JsonResult({ isAuthenticated });
};
exports.IsAuthenticated = IsAuthenticated;
//# sourceMappingURL=is-authenticated.js.map

@@ -1,4 +0,4 @@

import { RequestAction } from '@furystack/rest';
import '../injector-extensions';
import { User } from '@furystack/core';
import { RequestAction } from '../request-action-implementation';
/**

@@ -5,0 +5,0 @@ * Action that logs in the current user

@@ -5,5 +5,5 @@ "use strict";

const http_user_context_1 = require("../http-user-context");
require("../injector-extensions");
const rest_1 = require("@furystack/rest");
require("../injector-extensions");
const rest_2 = require("@furystack/rest");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -14,3 +14,3 @@ * Action that logs in the current user

*/
const LoginAction = async ({ injector, getBody, response, }) => {
const LoginAction = async ({ injector, getBody, response }) => {
const userContext = injector.getInstance(http_user_context_1.HttpUserContext);

@@ -21,6 +21,6 @@ const body = await getBody();

await userContext.cookieLogin(user, response);
return rest_1.JsonResult(user, 200);
return request_action_implementation_1.JsonResult(user, 200);
}
catch (error) {
throw new rest_2.RequestError('Login Failed', 400);
throw new rest_1.RequestError('Login Failed', 400);
}

@@ -27,0 +27,0 @@ };

@@ -1,2 +0,2 @@

import { RequestAction } from '@furystack/rest';
import { RequestAction } from '../request-action-implementation';
/**

@@ -11,3 +11,5 @@ * Action that logs out the current user

*/
export declare const LogoutAction: RequestAction<{}>;
export declare const LogoutAction: RequestAction<{
result: unknown;
}>;
//# sourceMappingURL=logout.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

const http_user_context_1 = require("../http-user-context");
const rest_1 = require("@furystack/rest");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -18,5 +18,5 @@ * Action that logs out the current user

await injector.getInstance(http_user_context_1.HttpUserContext).cookieLogout(request, response);
return rest_1.EmptyResult();
return request_action_implementation_1.EmptyResult();
};
exports.LogoutAction = LogoutAction;
//# sourceMappingURL=logout.js.map

@@ -1,2 +0,2 @@

import { RequestAction } from '@furystack/rest';
import { RequestAction } from '../request-action-implementation';
/**

@@ -3,0 +3,0 @@ * @returns The standard Not Found action result

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotFoundAction = void 0;
const rest_1 = require("@furystack/rest");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -9,3 +9,3 @@ * @returns The standard Not Found action result

const NotFoundAction = async () => {
return rest_1.JsonResult({
return request_action_implementation_1.JsonResult({
error: 'Content not found',

@@ -12,0 +12,0 @@ }, 404);

import { Disposable } from '@furystack/utils';
import { RequestAction, RestApi } from '@furystack/rest';
import { RestApi } from '@furystack/rest';
import { Injector } from '@furystack/inject';

@@ -7,4 +7,12 @@ import { ServerManager, OnRequest } from './server-manager';

import './server-response-extensions';
import { RequestAction } from './request-action-implementation';
export declare type RestApiImplementation<T extends RestApi> = {
[TMethod in keyof T]: {
[TUrl in keyof T[TMethod]]: T[TMethod][TUrl] extends {
result: unknown;
} ? RequestAction<T[TMethod][TUrl]> : never;
};
};
export interface ImplementApiOptions<T extends RestApi> {
api: T;
api: RestApiImplementation<T>;
injector: Injector;

@@ -11,0 +19,0 @@ hostName?: string;

@@ -6,2 +6,3 @@ "use strict";

const utils_1 = require("@furystack/utils");
const rest_1 = require("@furystack/rest");
const inject_1 = require("@furystack/inject");

@@ -96,9 +97,4 @@ const server_manager_1 = require("./server-manager");

getBody: () => utils.readPostBody(req),
getQuery: () => {
return [...fullUrl.searchParams.keys()].reduce((last, current) => {
const currentValue = fullUrl.searchParams.get(current);
last[current] = deserializeQueryParams ? deserializeQueryParams(currentValue) : currentValue;
return last;
}, {});
},
headers: req.headers,
getQuery: () => deserializeQueryParams ? deserializeQueryParams(fullUrl.search) : rest_1.deserializeQueryString(fullUrl.search),
getUrlParams: () => {

@@ -105,0 +101,0 @@ if (!req.url || !regex) {

@@ -1,3 +0,5 @@

import { RequestAction, RequestActionOptions } from '@furystack/rest';
export declare const Authenticate: () => <T extends RequestActionOptions>(action: RequestAction<T>) => RequestAction<T>;
import { RequestAction } from './request-action-implementation';
export declare const Authenticate: () => <T extends {
result: unknown;
}>(action: RequestAction<T>) => RequestAction<T>;
//# sourceMappingURL=authenticate.d.ts.map

@@ -5,4 +5,4 @@ "use strict";

const utils_1 = require("@furystack/utils");
const rest_1 = require("@furystack/rest");
const http_user_context_1 = require("./http-user-context");
const request_action_implementation_1 = require("./request-action-implementation");
const Authenticate = () => (action) => {

@@ -13,7 +13,7 @@ return async (args) => {

await utils_1.sleepAsync(Math.random() * 1000);
return rest_1.JsonResult({ error: 'unauthorized' }, 401, args.injector.getInstance(http_user_context_1.HttpUserContext).authentication.enableBasicAuth
return request_action_implementation_1.JsonResult({ error: 'unauthorized' }, 401, args.injector.getInstance(http_user_context_1.HttpUserContext).authentication.enableBasicAuth
? { 'WWW-Authenticate': 'Basic' }
: {});
}
return await action(args);
return (await action(args));
};

@@ -20,0 +20,0 @@ };

@@ -6,5 +6,5 @@ "use strict";

const http_user_context_1 = require("./http-user-context");
const rest_1 = require("@furystack/rest");
const authenticate_1 = require("./authenticate");
const core_1 = require("@furystack/core");
const request_action_implementation_1 = require("./request-action-implementation");
describe('Authenticate', () => {

@@ -20,3 +20,3 @@ const response = {};

}, http_user_context_1.HttpUserContext);
const exampleAuthenticatedAction = jest.fn(async (_args) => rest_1.EmptyResult());
const exampleAuthenticatedAction = jest.fn(async (_args) => request_action_implementation_1.EmptyResult());
const authorized = authenticate_1.Authenticate()(exampleAuthenticatedAction);

@@ -38,3 +38,3 @@ const result = await authorized({ injector: i, request, response });

}, http_user_context_1.HttpUserContext);
const exampleAuthenticatedAction = jest.fn(async (_args) => rest_1.EmptyResult());
const exampleAuthenticatedAction = jest.fn(async (_args) => request_action_implementation_1.EmptyResult());
const authorized = authenticate_1.Authenticate()(exampleAuthenticatedAction);

@@ -52,3 +52,3 @@ const result = await authorized({ injector: i, request, response });

i.setExplicitInstance({ isAuthenticated: isAuthenticatedAction, getCurrentUser: async () => Promise.reject(':(') }, core_1.IdentityContext);
const exampleAuthenticatedAction = jest.fn(async (_args) => rest_1.EmptyResult());
const exampleAuthenticatedAction = jest.fn(async (_args) => request_action_implementation_1.EmptyResult());
const authorized = authenticate_1.Authenticate()(exampleAuthenticatedAction);

@@ -55,0 +55,0 @@ const params = { injector: i, body: undefined, query: undefined, request, response };

@@ -1,3 +0,5 @@

import { RequestAction, RequestActionOptions } from '@furystack/rest';
export declare const Authorize: (...roles: string[]) => <T extends RequestActionOptions>(action: RequestAction<T>) => RequestAction<T>;
import { RequestAction } from './request-action-implementation';
export declare const Authorize: (...roles: string[]) => <T extends {
result: unknown;
}>(action: RequestAction<T>) => RequestAction<T>;
//# sourceMappingURL=authorize.d.ts.map

@@ -5,3 +5,3 @@ "use strict";

const utils_1 = require("@furystack/utils");
const rest_1 = require("@furystack/rest");
const request_action_implementation_1 = require("./request-action-implementation");
const Authorize = (...roles) => (action) => {

@@ -13,9 +13,9 @@ return async (options) => {

await utils_1.sleepAsync(Math.random() * 1000);
return rest_1.JsonResult({ error: 'forbidden' }, 403);
return request_action_implementation_1.JsonResult({ error: 'forbidden' }, 403);
}
}
catch (error) {
return rest_1.JsonResult({ error: 'forbidden' }, 403);
return request_action_implementation_1.JsonResult({ error: 'forbidden' }, 403);
}
return await action(options);
return (await action(options));
};

@@ -22,0 +22,0 @@ };

@@ -7,3 +7,3 @@ "use strict";

const authorize_1 = require("./authorize");
const rest_1 = require("@furystack/rest");
const request_action_implementation_1 = require("./request-action-implementation");
describe('Authorize', () => {

@@ -16,3 +16,3 @@ const response = {};

i.setExplicitInstance({ isAuthorized: isAuthorizedAction, getCurrentUser: () => Promise.reject(':(') }, core_1.IdentityContext);
const exampleAuthorizedAction = jest.fn(async (_args) => rest_1.EmptyResult());
const exampleAuthorizedAction = jest.fn(async (_args) => request_action_implementation_1.EmptyResult());
const authorized = authorize_1.Authorize('Role1')(exampleAuthorizedAction);

@@ -32,3 +32,3 @@ const result = await authorized({ injector: i, request, response });

}, core_1.IdentityContext);
const exampleAuthorizedAction = jest.fn(async (_args) => rest_1.EmptyResult());
const exampleAuthorizedAction = jest.fn(async (_args) => request_action_implementation_1.EmptyResult());
const authorized = authorize_1.Authorize('Role2')(exampleAuthorizedAction);

@@ -48,3 +48,3 @@ const result = await authorized({ injector: i, request, response });

}, core_1.IdentityContext);
const exampleAuthorizedAction = jest.fn(async (_args) => rest_1.EmptyResult());
const exampleAuthorizedAction = jest.fn(async (_args) => request_action_implementation_1.EmptyResult());
const authorized = authorize_1.Authorize('Role1')(exampleAuthorizedAction);

@@ -51,0 +51,0 @@ const params = { injector: i, body: undefined, query: undefined, request, response };

import { Constructable } from '@furystack/inject';
import { DeleteEndpoint } from '@furystack/rest';
import '@furystack/repository';
import { RequestAction } from '../request-action-implementation';
/**

@@ -12,8 +14,3 @@ * Creates a DELETE endpoint for removing entities

model: Constructable<T>;
}) => import("@furystack/rest").RequestAction<{
urlParams: {
id: T[keyof T];
};
result: {};
}>;
}) => RequestAction<DeleteEndpoint<T>>;
//# sourceMappingURL=create-delete-endpoint.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDeleteEndpoint = void 0;
const rest_1 = require("@furystack/rest");
require("@furystack/repository");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -18,3 +18,3 @@ * Creates a DELETE endpoint for removing entities

await dataSet.remove(injector, id);
return rest_1.JsonResult({}, 204);
return request_action_implementation_1.JsonResult({}, 204);
};

@@ -21,0 +21,0 @@ return endpoint;

import { Constructable } from '@furystack/inject';
import { GetCollectionEndpoint } from '@furystack/rest';
import '@furystack/repository';
import { RequestAction } from '../request-action-implementation';
/**

@@ -12,8 +14,3 @@ * Creates a GetCollection endpoint for the given model. The model should have a Repository DataSet

model: Constructable<T>;
}) => import("@furystack/rest").RequestAction<{
query: {
findOptions?: import("@furystack/core").FindOptions<T, (keyof T)[]> | undefined;
};
result: import("@furystack/rest").GetCollectionResult<T, keyof T>;
}>;
}) => RequestAction<GetCollectionEndpoint<T>>;
//# sourceMappingURL=create-get-collection-endpoint.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createGetCollectionEndpoint = void 0;
const rest_1 = require("@furystack/rest");
require("@furystack/repository");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -20,3 +20,3 @@ * Creates a GetCollection endpoint for the given model. The model should have a Repository DataSet

const [entries, count] = await Promise.all([entriesPromise, countPromise]);
return rest_1.JsonResult({ entries, count });
return request_action_implementation_1.JsonResult({ entries, count });
};

@@ -23,0 +23,0 @@ return endpoint;

@@ -9,2 +9,3 @@ "use strict";

const create_get_collection_endpoint_1 = require("./create-get-collection-endpoint");
const rest_1 = require("@furystack/rest");
const addMockEntities = async (i) => await i

@@ -41,3 +42,2 @@ .getDataSetFor(utils_2.MockClass)

port: 1113,
deserializeQueryParams: utils_2.deserialize,
api: {

@@ -53,3 +53,3 @@ GET: {

const orderedEntities = await i.getDataSetFor(utils_2.MockClass).find(i, findOptions);
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?findOptions=${utils_2.serialize(findOptions)}`, {
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?${rest_1.serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -68,3 +68,2 @@ });

port: 1113,
deserializeQueryParams: utils_2.deserialize,
api: {

@@ -83,3 +82,3 @@ GET: {

expect(filteredEntities).not.toContainEqual({ id: 'mock2', value: '3' });
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?findOptions=${utils_2.serialize(findOptions)}`, {
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?${rest_1.serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -98,3 +97,2 @@ });

port: 1113,
deserializeQueryParams: utils_2.deserialize,
api: {

@@ -113,3 +111,3 @@ GET: {

selectedEntities.forEach((e) => expect(e.value).toBeUndefined());
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?findOptions=${utils_2.serialize(findOptions)}`, {
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?${rest_1.serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -128,3 +126,2 @@ });

port: 1113,
deserializeQueryParams: utils_2.deserialize,
api: {

@@ -145,3 +142,3 @@ GET: {

expect(topSkipEntities).not.toContainEqual({ id: 'mock4', value: '1' });
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?findOptions=${utils_2.serialize(findOptions)}`, {
const response = await got_1.default(`http://127.0.0.1:1113/api/entities?${rest_1.serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -148,0 +145,0 @@ });

import { Constructable } from '@furystack/inject';
import { GetEntityEndpoint } from '@furystack/rest';
import '@furystack/repository';
import { RequestAction } from '../request-action-implementation';
/**

@@ -12,11 +14,3 @@ * Creates a simple Get Entity endpoint for a specified model.

model: Constructable<T>;
}) => import("@furystack/rest").RequestAction<{
query: {
select: (keyof T)[] | undefined;
};
urlParams: {
id: T[keyof T];
};
result: import("@furystack/core").PartialResult<T, any>;
}>;
}) => RequestAction<GetEntityEndpoint<T>>;
//# sourceMappingURL=create-get-entity-endpoint.d.ts.map

@@ -6,2 +6,3 @@ "use strict";

require("@furystack/repository");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -23,3 +24,3 @@ * Creates a simple Get Entity endpoint for a specified model.

}
return rest_1.JsonResult(entry);
return request_action_implementation_1.JsonResult(entry);
};

@@ -26,0 +27,0 @@ return endpoint;

@@ -6,2 +6,3 @@ "use strict";

const inject_1 = require("@furystack/inject");
const rest_1 = require("@furystack/rest");
const got_1 = tslib_1.__importDefault(require("got"));

@@ -34,3 +35,2 @@ const utils_2 = require("./utils");

root: '/api',
deserializeQueryParams: utils_2.deserialize,
port: 1114,

@@ -45,3 +45,5 @@ api: {

await i.getDataSetFor(utils_2.MockClass).add(i, mockEntity);
const response = await got_1.default(`http://127.0.0.1:1114/api/mock?select=${utils_2.serialize(['id'])}`, { method: 'GET' });
const response = await got_1.default(`http://127.0.0.1:1114/api/mock?${rest_1.serializeToQueryString({ select: ['id'] })}`, {
method: 'GET',
});
expect(JSON.parse(response.body)).toStrictEqual({ id: mockEntity.id });

@@ -55,3 +57,2 @@ });

root: '/api',
deserializeQueryParams: utils_2.deserialize,
port: 1115,

@@ -58,0 +59,0 @@ api: {

import { Constructable } from '@furystack/inject';
import { PatchEndpoint } from '@furystack/rest';
import '@furystack/repository';
import '../incoming-message-extensions';
import { RequestAction } from '../request-action-implementation';
/**

@@ -13,9 +15,3 @@ * Creates a PATCH endpoint for updating entities

model: Constructable<T>;
}) => import("@furystack/rest").RequestAction<{
body: T;
urlParams: {
id: T[keyof T];
};
result: {};
}>;
}) => RequestAction<PatchEndpoint<T>>;
//# sourceMappingURL=create-patch-endpoint.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPatchEndpoint = void 0;
const rest_1 = require("@furystack/rest");
require("@furystack/repository");
require("../incoming-message-extensions");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -20,3 +20,3 @@ * Creates a PATCH endpoint for updating entities

await dataSet.update(injector, id, patchData);
return rest_1.JsonResult({});
return request_action_implementation_1.JsonResult({});
};

@@ -23,0 +23,0 @@ return endpoint;

import { Constructable } from '@furystack/inject';
import { PostEndpoint } from '@furystack/rest';
import '@furystack/repository';
import '../incoming-message-extensions';
import { RequestAction } from '../request-action-implementation';
/**

@@ -13,6 +15,3 @@ * Creates a POST endpoint for updating entities

model: Constructable<T>;
}) => import("@furystack/rest").RequestAction<{
body: import("@furystack/core").WithOptionalId<T, keyof T>;
result: T;
}>;
}) => RequestAction<PostEndpoint<T>>;
//# sourceMappingURL=create-post-endpoint.d.ts.map

@@ -7,2 +7,3 @@ "use strict";

require("../incoming-message-extensions");
const request_action_implementation_1 = require("../request-action-implementation");
/**

@@ -23,3 +24,3 @@ * Creates a POST endpoint for updating entities

}
return rest_1.JsonResult(created[0], 201);
return request_action_implementation_1.JsonResult(created[0], 201);
};

@@ -26,0 +27,0 @@ return endpoint;

@@ -8,5 +8,3 @@ import { Injector } from '@furystack/inject';

}
export declare const serialize: <T>(entity: T) => string;
export declare const deserialize: <T>(entity: string) => T;
export declare const setupContext: (i: Injector) => void;
//# sourceMappingURL=utils.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupContext = exports.deserialize = exports.serialize = exports.MockClass = void 0;
exports.setupContext = exports.MockClass = void 0;
const core_1 = require("@furystack/core");

@@ -11,6 +11,2 @@ const default_session_1 = require("../models/default-session");

exports.MockClass = MockClass;
const serialize = (entity) => encodeURIComponent(JSON.stringify(entity));
exports.serialize = serialize;
const deserialize = (entity) => JSON.parse(decodeURIComponent(entity));
exports.deserialize = deserialize;
const setupContext = (i) => {

@@ -17,0 +13,0 @@ i.setupStores((b) => b

import { IncomingMessage, ServerResponse } from 'http';
import { PhysicalStore, User, StoreManager } from '@furystack/core';
import { User, StoreManager } from '@furystack/core';
import { HttpAuthenticationSettings } from './http-authentication-settings';

@@ -9,9 +9,7 @@ /**

readonly authentication: HttpAuthenticationSettings<User>;
users: PhysicalStore<User & {
private readonly storeManager;
getUserStore: () => import("@furystack/core").PhysicalStore<User & {
password: string;
}>;
sessions: PhysicalStore<{
sessionId: string;
username: string;
}>;
getSessionStore: () => import("@furystack/core").PhysicalStore<import(".").DefaultSession>;
private user?;

@@ -18,0 +16,0 @@ /**

@@ -15,4 +15,5 @@ "use strict";

this.authentication = authentication;
this.users = authentication.getUserStore(storeManager);
this.sessions = authentication.getSessionStore(storeManager);
this.storeManager = storeManager;
this.getUserStore = () => this.authentication.getUserStore(this.storeManager);
this.getSessionStore = () => this.authentication.getSessionStore(this.storeManager);
}

@@ -59,3 +60,3 @@ /**

password.length &&
(await this.users.find({
(await this.getUserStore().find({
filter: {

@@ -107,5 +108,5 @@ username: { $eq: userName },

if (sessionId) {
const [session] = await this.sessions.find({ filter: { sessionId: { $eq: sessionId } }, top: 2 });
const [session] = await this.getSessionStore().find({ filter: { sessionId: { $eq: sessionId } }, top: 2 });
if (session) {
const userResult = await this.users.find({
const userResult = await this.getUserStore().find({
filter: {

@@ -133,3 +134,3 @@ username: { $eq: session.username },

const sessionId = uuid_1.v1();
await this.sessions.add({ sessionId, username: user.username });
await this.getSessionStore().add({ sessionId, username: user.username });
serverResponse.setHeader('Set-Cookie', `${this.authentication.cookieName}=${sessionId}; Path=/; HttpOnly`);

@@ -141,3 +142,3 @@ return user;

if (sessionId) {
await this.sessions.remove(sessionId);
await this.getSessionStore().remove(sessionId);
response.setHeader('Set-Cookie', `${this.authentication.cookieName}=; Path=/; HttpOnly`);

@@ -149,5 +150,6 @@ }

inject_1.Injectable({ lifetime: 'scoped' }),
tslib_1.__metadata("design:paramtypes", [http_authentication_settings_1.HttpAuthenticationSettings, core_1.StoreManager])
tslib_1.__metadata("design:paramtypes", [http_authentication_settings_1.HttpAuthenticationSettings,
core_1.StoreManager])
], HttpUserContext);
exports.HttpUserContext = HttpUserContext;
//# sourceMappingURL=http-user-context.js.map

@@ -236,3 +236,3 @@ "use strict";

const setHeader = jest.fn();
ctx.sessions.add = jest.fn(async () => {
ctx.getSessionStore().add = jest.fn(async () => {
return {};

@@ -243,3 +243,3 @@ });

expect(setHeader).toBeCalled();
expect(ctx.sessions.add).toBeCalled();
expect(ctx.getSessionStore().add).toBeCalled();
});

@@ -254,7 +254,7 @@ });

const setHeader = jest.fn();
ctx.sessions.add = jest.fn(async () => {
ctx.getSessionStore().add = jest.fn(async () => {
return {};
});
ctx.authenticateRequest = jest.fn(async () => testUser);
ctx.sessions.remove = jest.fn(async () => undefined);
ctx.getSessionStore().remove = jest.fn(async () => undefined);
ctx.getSessionIdFromRequest = () => 'example-session-id';

@@ -265,3 +265,3 @@ response.setHeader = jest.fn(() => undefined);

expect(response.setHeader).toBeCalledWith('Set-Cookie', 'fss=; Path=/; HttpOnly');
expect(ctx.sessions.remove).toBeCalled();
expect(ctx.getSessionStore().remove).toBeCalled();
});

@@ -268,0 +268,0 @@ });

@@ -14,2 +14,4 @@ import './injector-extensions';

export * from './endpoint-generators';
export * from './schema-validator';
export * from './request-action-implementation';
//# sourceMappingURL=index.d.ts.map

@@ -17,2 +17,4 @@ "use strict";

tslib_1.__exportStar(require("./endpoint-generators"), exports);
tslib_1.__exportStar(require("./schema-validator"), exports);
tslib_1.__exportStar(require("./request-action-implementation"), exports);
//# sourceMappingURL=index.js.map

@@ -8,6 +8,6 @@ "use strict";

const actions_1 = require("./actions");
const rest_1 = require("@furystack/rest");
const core_1 = require("@furystack/core");
const default_session_1 = require("./models/default-session");
const got_1 = tslib_1.__importDefault(require("got"));
const request_action_implementation_1 = require("./request-action-implementation");
const port = 19090;

@@ -37,4 +37,4 @@ const hostName = 'localhost';

'/isAuthenticated': actions_1.IsAuthenticated,
'/testQuery': async (options) => rest_1.JsonResult({ param1Value: options.getQuery().param1 }),
'/testUrlParams/:urlParam': async (options) => rest_1.JsonResult({ urlParamValue: options.getUrlParams().urlParam }),
'/testQuery': async (options) => request_action_implementation_1.JsonResult({ param1Value: options.getQuery().param1 }),
'/testUrlParams/:urlParam': async (options) => request_action_implementation_1.JsonResult({ urlParamValue: options.getUrlParams().urlParam }),
},

@@ -46,3 +46,3 @@ POST: {

const body = await options.getBody();
return rest_1.JsonResult({ bodyValue: body.value });
return request_action_implementation_1.JsonResult({ bodyValue: body.value });
},

@@ -49,0 +49,0 @@ },

@@ -1,2 +0,2 @@

import { ActionResult } from '@furystack/rest';
import { ActionResult } from './request-action-implementation';
export interface SendJsonOptions<T> {

@@ -3,0 +3,0 @@ statusCode?: number;

@@ -5,4 +5,4 @@ "use strict";

const http_1 = require("http");
const rest_1 = require("@furystack/rest");
require("./server-response-extensions");
const request_action_implementation_1 = require("./request-action-implementation");
describe('ServerResponse extensions', () => {

@@ -25,3 +25,3 @@ describe('sendActionResult', () => {

};
msg.sendActionResult(rest_1.JsonResult(jsonValue));
msg.sendActionResult(request_action_implementation_1.JsonResult(jsonValue));
});

@@ -38,3 +38,3 @@ it('Should send the plain TEXT response with the correct Content Type header and default status', (done) => {

};
msg.sendActionResult(rest_1.PlainTextResult(textValue));
msg.sendActionResult(request_action_implementation_1.PlainTextResult(textValue));
});

@@ -46,3 +46,3 @@ it('Should skip sending on BypassResult', () => {

msg.end = jest.fn();
msg.sendActionResult(rest_1.BypassResult());
msg.sendActionResult(request_action_implementation_1.BypassResult());
expect(msg.writeHead).not.toBeCalled();

@@ -49,0 +49,0 @@ expect(msg.end).not.toBeCalled();

{
"name": "@furystack/rest-service",
"version": "2.3.7",
"version": "3.0.0",
"description": "Repository implementation for FuryStack",

@@ -34,8 +34,10 @@ "main": "dist/index.js",

"dependencies": {
"@furystack/core": "^9.1.21",
"@furystack/inject": "^4.0.49",
"@furystack/logging": "^2.0.56",
"@furystack/repository": "^4.0.11",
"@furystack/rest": "^1.3.7",
"@furystack/utils": "^1.2.19",
"@furystack/core": "^9.1.22",
"@furystack/inject": "^4.0.50",
"@furystack/logging": "^2.0.57",
"@furystack/repository": "^4.0.12",
"@furystack/rest": "^2.0.0",
"@furystack/utils": "^1.2.20",
"ajv": "^7.1.1",
"ajv-formats": "^1.5.1",
"hash.js": "^1.1.7",

@@ -49,3 +51,3 @@ "path-to-regexp": "^6.2.0",

"@types/jest": "^26.0.20",
"@types/node": "^14.14.25",
"@types/node": "^14.14.28",
"@types/uuid": "^8.0.0",

@@ -55,3 +57,3 @@ "got": "^11.8.1"

"typings": "./dist/index.d.ts",
"gitHead": "244f9664bf70eb0a74a9e6f280e16f8e2c93ecf2"
"gitHead": "24502ef573887f7fe7db61d5e6f79967a6c45723"
}

@@ -1,4 +0,5 @@

import { RequestAction, JsonResult } from '@furystack/rest'
import { RequestError } from '@furystack/rest'
import { AuthorizationError } from '@furystack/core'
import { JsonResult, RequestAction } from '../request-action-implementation'
import { SchemaValidationError } from '../schema-validator'

@@ -15,2 +16,7 @@ /**

const body = await getBody()
if (body instanceof SchemaValidationError) {
return JsonResult({ message: body.message, stack: body.stack, errors: body.errors }, 400)
}
const errorCode = body instanceof RequestError ? body.responseCode : body instanceof AuthorizationError ? 403 : 500

@@ -17,0 +23,0 @@

@@ -1,4 +0,4 @@

import { RequestAction, JsonResult } from '@furystack/rest'
import { User } from '@furystack/core'
import { Authenticate } from '../authenticate'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -5,0 +5,0 @@ /**

@@ -13,3 +13,3 @@ import { Injector } from '@furystack/inject'

i.setExplicitInstance({ isAuthenticated: async () => true }, IdentityContext)
const result = await IsAuthenticated({ injector: i, request, response })
const result = await IsAuthenticated({ injector: i, request, response } as any)
expect(result.statusCode).toBe(200)

@@ -16,0 +16,0 @@ expect(result.chunk).toEqual({ isAuthenticated: true })

@@ -1,2 +0,2 @@

import { RequestAction, JsonResult } from '@furystack/rest'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -3,0 +3,0 @@ /**

@@ -27,3 +27,3 @@ import { IncomingMessage, ServerResponse } from 'http'

getBody: async () => ({ username: 'testuser', password: 'alma' }),
})
} as any)
expect(result.chunk).toEqual(testUser)

@@ -30,0 +30,0 @@ expect(result.statusCode).toBe(200)

import { HttpUserContext } from '../http-user-context'
import { RequestAction, JsonResult } from '@furystack/rest'
import '../injector-extensions'
import { User } from '@furystack/core'
import { RequestError } from '@furystack/rest'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -13,7 +13,6 @@ /**

export const LoginAction: RequestAction<{ result: User; body: { username: string; password: string } }> = async ({
injector,
getBody,
response,
}) => {
export const LoginAction: RequestAction<{
result: User
body: { username: string; password: string }
}> = async ({ injector, getBody, response }) => {
const userContext = injector.getInstance(HttpUserContext)

@@ -20,0 +19,0 @@ const body = await getBody()

import { HttpUserContext } from '../http-user-context'
import { RequestAction, EmptyResult } from '@furystack/rest'
import { EmptyResult, RequestAction } from '../request-action-implementation'

@@ -13,5 +13,5 @@ /**

*/
export const LogoutAction: RequestAction<{}> = async ({ injector, request, response }) => {
export const LogoutAction: RequestAction<{ result: unknown }> = async ({ injector, request, response }) => {
await injector.getInstance(HttpUserContext).cookieLogout(request, response)
return EmptyResult()
}

@@ -1,2 +0,2 @@

import { RequestAction, JsonResult } from '@furystack/rest'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -3,0 +3,0 @@ /**

import { Disposable, PathHelper, usingAsync } from '@furystack/utils'
import { RequestAction, RestApi } from '@furystack/rest'
import { deserializeQueryString, RestApi } from '@furystack/rest'
import { Injectable, Injector } from '@furystack/inject'

@@ -13,5 +13,12 @@ import { ServerManager, OnRequest } from './server-manager'

import { HttpUserContext } from './http-user-context'
import { RequestAction } from './request-action-implementation'
export type RestApiImplementation<T extends RestApi> = {
[TMethod in keyof T]: {
[TUrl in keyof T[TMethod]]: T[TMethod][TUrl] extends { result: unknown } ? RequestAction<T[TMethod][TUrl]> : never
}
}
export interface ImplementApiOptions<T extends RestApi> {
api: T
api: RestApiImplementation<T>
injector: Injector

@@ -50,7 +57,7 @@ hostName?: string

private getSuportedMethods<T extends RestApi>(api: T): string[] {
private getSuportedMethods<T extends RestApi>(api: RestApiImplementation<T>): string[] {
return Object.keys(api) as any
}
private compileApi<T extends RestApi>(api: T, root: string) {
private compileApi<T extends RestApi>(api: RestApiImplementation<T>, root: string) {
const compiledApi = {} as CompiledApi

@@ -125,3 +132,3 @@ this.getSuportedMethods(api).forEach((method) => {

| {
action: RequestAction<{ body: {}; result: {}; query: {}; urlParams: {} }>
action: RequestAction<{ body: {}; result: {}; query: {}; url: {}; headers: {} }>
regex: RegExp

@@ -144,3 +151,3 @@ fullPath: string

fullUrl: URL
action: RequestAction<{ body: {}; result: {}; query: {}; urlParams: {} }>
action: RequestAction<{ body: {}; result: {}; query: {}; url: {}; headers: {} }>
regex: RegExp

@@ -166,9 +173,5 @@ fullPath: string

getBody: () => utils.readPostBody<any>(req),
getQuery: () => {
return [...fullUrl.searchParams.keys()].reduce((last, current) => {
const currentValue = fullUrl.searchParams.get(current) as string
;(last as any)[current] = deserializeQueryParams ? deserializeQueryParams(currentValue) : currentValue
return last
}, {})
},
headers: req.headers,
getQuery: () =>
deserializeQueryParams ? deserializeQueryParams(fullUrl.search) : deserializeQueryString(fullUrl.search),
getUrlParams: () => {

@@ -175,0 +178,0 @@ if (!req.url || !regex) {

@@ -5,6 +5,6 @@ import { IncomingMessage } from 'http'

import { HttpUserContext } from './http-user-context'
import { EmptyResult } from '@furystack/rest'
import { Authenticate } from './authenticate'
import { ServerResponse } from 'http'
import { IdentityContext } from '@furystack/core'
import { EmptyResult } from './request-action-implementation'

@@ -11,0 +11,0 @@ describe('Authenticate', () => {

import { sleepAsync } from '@furystack/utils'
import { JsonResult, RequestAction, RequestOptions, ActionResult, RequestActionOptions } from '@furystack/rest'
import { HttpUserContext } from './http-user-context'
import { ActionResult, JsonResult, RequestAction, RequestActionOptions } from './request-action-implementation'
export const Authenticate = () => <T extends RequestActionOptions>(action: RequestAction<T>): RequestAction<T> => {
return async (args: RequestOptions<T['query'], T['body'], T['urlParams']>): Promise<ActionResult<T>> => {
export const Authenticate = () => <T extends { result: unknown }>(action: RequestAction<T>): RequestAction<T> => {
return async (args: RequestActionOptions<T>): Promise<ActionResult<T>> => {
const authenticated = await args.injector.isAuthenticated()

@@ -18,4 +18,4 @@ if (!authenticated) {

}
return await action(args)
return (await action(args)) as any
}
}

@@ -6,4 +6,4 @@ import { IncomingMessage } from 'http'

import { Authorize } from './authorize'
import { EmptyResult } from '@furystack/rest'
import { ServerResponse } from 'http'
import { EmptyResult } from './request-action-implementation'

@@ -10,0 +10,0 @@ describe('Authorize', () => {

import { sleepAsync } from '@furystack/utils'
import { JsonResult, RequestAction, RequestOptions, RequestActionOptions, ActionResult } from '@furystack/rest'
import { ActionResult, JsonResult, RequestAction, RequestActionOptions } from './request-action-implementation'
export const Authorize = (...roles: string[]) => <T extends RequestActionOptions>(
export const Authorize = (...roles: string[]) => <T extends { result: unknown }>(
action: RequestAction<T>,
): RequestAction<T> => {
return async (options: RequestOptions<T['query'], T['body'], T['urlParams']>): Promise<ActionResult<T>> => {
return async (options: RequestActionOptions<T>): Promise<ActionResult<T>> => {
try {

@@ -17,4 +17,4 @@ const authorized = await options.injector.isAuthorized(...roles)

}
return await action(options)
return (await action(options)) as any
}
}
import { Constructable } from '@furystack/inject'
import { DeleteEndpoint, JsonResult } from '@furystack/rest'
import { DeleteEndpoint } from '@furystack/rest'
import '@furystack/repository'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -13,3 +14,3 @@ /**

export const createDeleteEndpoint = <T extends object>(options: { model: Constructable<T> }) => {
const endpoint: DeleteEndpoint<T> = async ({ injector, getUrlParams }) => {
const endpoint: RequestAction<DeleteEndpoint<T>> = async ({ injector, getUrlParams }) => {
const { id } = getUrlParams()

@@ -16,0 +17,0 @@ const dataSet = injector.getDataSetFor(options.model)

import { usingAsync } from '@furystack/utils'
import { Injector } from '@furystack/inject'
import got from 'got'
import { MockClass, setupContext, deserialize, serialize } from './utils'
import { MockClass, setupContext } from './utils'
import { createGetCollectionEndpoint } from './create-get-collection-endpoint'
import { GetCollectionEndpoint, GetCollectionResult } from '@furystack/rest'
import { GetCollectionEndpoint, GetCollectionResult, serializeToQueryString } from '@furystack/rest'
import { FindOptions } from '@furystack/core'

@@ -51,3 +51,2 @@

port: 1113,
deserializeQueryParams: deserialize,
api: {

@@ -63,3 +62,3 @@ GET: {

const orderedEntities = await i.getDataSetFor(MockClass).find(i, findOptions)
const response = await got(`http://127.0.0.1:1113/api/entities?findOptions=${serialize(findOptions)}`, {
const response = await got(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -79,3 +78,2 @@ })

port: 1113,
deserializeQueryParams: deserialize,
api: {

@@ -97,3 +95,3 @@ GET: {

const response = await got(`http://127.0.0.1:1113/api/entities?findOptions=${serialize(findOptions)}`, {
const response = await got(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -113,3 +111,2 @@ })

port: 1113,
deserializeQueryParams: deserialize,
api: {

@@ -131,3 +128,3 @@ GET: {

const response = await got(`http://127.0.0.1:1113/api/entities?findOptions=${serialize(findOptions)}`, {
const response = await got(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -147,3 +144,2 @@ })

port: 1113,
deserializeQueryParams: deserialize,
api: {

@@ -167,3 +163,3 @@ GET: {

const response = await got(`http://127.0.0.1:1113/api/entities?findOptions=${serialize(findOptions)}`, {
const response = await got(`http://127.0.0.1:1113/api/entities?${serializeToQueryString({ findOptions })}`, {
method: 'GET',

@@ -170,0 +166,0 @@ })

import { Constructable } from '@furystack/inject'
import { JsonResult, GetCollectionEndpoint } from '@furystack/rest'
import { GetCollectionEndpoint } from '@furystack/rest'
import '@furystack/repository'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -13,3 +14,3 @@ /**

export const createGetCollectionEndpoint = <T>(options: { model: Constructable<T> }) => {
const endpoint: GetCollectionEndpoint<T> = async ({ injector, getQuery }) => {
const endpoint: RequestAction<GetCollectionEndpoint<T>> = async ({ injector, getQuery }) => {
const { findOptions } = getQuery()

@@ -16,0 +17,0 @@ const dataSet = injector.getDataSetFor(options.model)

import { usingAsync } from '@furystack/utils'
import { Injector } from '@furystack/inject'
import { GetEntityEndpoint } from '@furystack/rest'
import { GetEntityEndpoint, serializeToQueryString } from '@furystack/rest'
import got, { HTTPError } from 'got'
import { MockClass, setupContext, deserialize, serialize } from './utils'
import { MockClass, setupContext } from './utils'
import { createGetEntityEndpoint } from './create-get-entity-endpoint'

@@ -34,3 +34,2 @@

root: '/api',
deserializeQueryParams: deserialize,
port: 1114,

@@ -46,3 +45,5 @@ api: {

const response = await got(`http://127.0.0.1:1114/api/mock?select=${serialize(['id'])}`, { method: 'GET' })
const response = await got(`http://127.0.0.1:1114/api/mock?${serializeToQueryString({ select: ['id'] })}`, {
method: 'GET',
})
expect(JSON.parse(response.body)).toStrictEqual({ id: mockEntity.id })

@@ -57,3 +58,2 @@ })

root: '/api',
deserializeQueryParams: deserialize,
port: 1115,

@@ -60,0 +60,0 @@ api: {

import { Constructable } from '@furystack/inject'
import { JsonResult, RequestError, GetEntityEndpoint } from '@furystack/rest'
import { RequestError, GetEntityEndpoint } from '@furystack/rest'
import '@furystack/repository'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -13,3 +14,3 @@ /**

export const createGetEntityEndpoint = <T>(options: { model: Constructable<T> }) => {
const endpoint: GetEntityEndpoint<T> = async ({ injector, getUrlParams, getQuery }) => {
const endpoint: RequestAction<GetEntityEndpoint<T>> = async ({ injector, getUrlParams, getQuery }) => {
const { id } = getUrlParams()

@@ -16,0 +17,0 @@ const { select } = getQuery()

import { Constructable } from '@furystack/inject'
import { JsonResult, PatchEndpoint } from '@furystack/rest'
import { PatchEndpoint } from '@furystack/rest'
import '@furystack/repository'
import '../incoming-message-extensions'
import { JsonResult, RequestAction } from '../request-action-implementation'

@@ -14,3 +15,3 @@ /**

export const createPatchEndpoint = <T extends object>(options: { model: Constructable<T> }) => {
const endpoint: PatchEndpoint<T> = async ({ injector, request, getUrlParams }) => {
const endpoint: RequestAction<PatchEndpoint<T>> = async ({ injector, request, getUrlParams }) => {
const { id } = getUrlParams()

@@ -17,0 +18,0 @@ const patchData = await request.readPostBody<T>()

import { Constructable } from '@furystack/inject'
import { JsonResult, RequestError, PostEndpoint } from '@furystack/rest'
import { RequestError, PostEndpoint } from '@furystack/rest'
import '@furystack/repository'
import '../incoming-message-extensions'
import { JsonResult, RequestAction } from '../request-action-implementation'
/**

@@ -13,3 +14,3 @@ * Creates a POST endpoint for updating entities

export const createPostEndpoint = <T extends object>(options: { model: Constructable<T> }) => {
const endpoint: PostEndpoint<T> = async ({ injector, request }) => {
const endpoint: RequestAction<PostEndpoint<T>> = async ({ injector, request }) => {
const entityToCreate = await request.readPostBody<T>()

@@ -16,0 +17,0 @@ const dataSet = injector.getDataSetFor(options.model)

@@ -12,6 +12,2 @@ import { Injector } from '@furystack/inject'

export const serialize = <T>(entity: T): string => encodeURIComponent(JSON.stringify(entity))
export const deserialize = <T>(entity: string): T => JSON.parse(decodeURIComponent(entity))
export const setupContext = (i: Injector) => {

@@ -18,0 +14,0 @@ i.setupStores((b) =>

@@ -268,3 +268,3 @@ import { IncomingMessage, ServerResponse } from 'http'

const setHeader = jest.fn()
ctx.sessions.add = jest.fn(async () => {
ctx.getSessionStore().add = jest.fn(async () => {
return {} as any

@@ -275,3 +275,3 @@ })

expect(setHeader).toBeCalled()
expect(ctx.sessions.add).toBeCalled()
expect(ctx.getSessionStore().add).toBeCalled()
})

@@ -287,7 +287,7 @@ })

const setHeader = jest.fn()
ctx.sessions.add = jest.fn(async () => {
ctx.getSessionStore().add = jest.fn(async () => {
return {} as any
})
ctx.authenticateRequest = jest.fn(async () => testUser)
ctx.sessions.remove = jest.fn(async () => undefined)
ctx.getSessionStore().remove = jest.fn(async () => undefined)
ctx.getSessionIdFromRequest = () => 'example-session-id'

@@ -298,3 +298,3 @@ response.setHeader = jest.fn(() => undefined)

expect(response.setHeader).toBeCalledWith('Set-Cookie', 'fss=; Path=/; HttpOnly')
expect(ctx.sessions.remove).toBeCalled()
expect(ctx.getSessionStore().remove).toBeCalled()
})

@@ -301,0 +301,0 @@ })

import { IncomingMessage, ServerResponse } from 'http'
import { PhysicalStore, User, StoreManager } from '@furystack/core'
import { User, StoreManager } from '@furystack/core'
import { Injectable } from '@furystack/inject'

@@ -12,8 +12,5 @@ import { v1 } from 'uuid'

export class HttpUserContext {
public users: PhysicalStore<User & { password: string }>
public getUserStore = () => this.authentication.getUserStore(this.storeManager)
public sessions!: PhysicalStore<{
sessionId: string
username: string
}>
public getSessionStore = () => this.authentication.getSessionStore(this.storeManager)

@@ -64,3 +61,3 @@ private user?: User

password.length &&
(await this.users.find({
(await this.getUserStore().find({
filter: {

@@ -116,5 +113,5 @@ username: { $eq: userName },

if (sessionId) {
const [session] = await this.sessions.find({ filter: { sessionId: { $eq: sessionId } }, top: 2 })
const [session] = await this.getSessionStore().find({ filter: { sessionId: { $eq: sessionId } }, top: 2 })
if (session) {
const userResult = await this.users.find({
const userResult = await this.getUserStore().find({
filter: {

@@ -144,3 +141,3 @@ username: { $eq: session.username },

const sessionId = v1()
await this.sessions.add({ sessionId, username: user.username })
await this.getSessionStore().add({ sessionId, username: user.username })
serverResponse.setHeader('Set-Cookie', `${this.authentication.cookieName}=${sessionId}; Path=/; HttpOnly`)

@@ -153,3 +150,3 @@ return user

if (sessionId) {
await this.sessions.remove(sessionId)
await this.getSessionStore().remove(sessionId)
response.setHeader('Set-Cookie', `${this.authentication.cookieName}=; Path=/; HttpOnly`)

@@ -159,6 +156,6 @@ }

constructor(public readonly authentication: HttpAuthenticationSettings<User>, storeManager: StoreManager) {
this.users = authentication.getUserStore(storeManager)
this.sessions = authentication.getSessionStore(storeManager)
}
constructor(
public readonly authentication: HttpAuthenticationSettings<User>,
private readonly storeManager: StoreManager,
) {}
}

@@ -14,1 +14,3 @@ import './injector-extensions'

export * from './endpoint-generators'
export * from './schema-validator'
export * from './request-action-implementation'

@@ -5,18 +5,19 @@ import { Injector } from '@furystack/inject'

import { GetCurrentUser, IsAuthenticated, LoginAction, LogoutAction } from './actions'
import { JsonResult, RestApi, RequestAction } from '@furystack/rest'
import { RestApi } from '@furystack/rest'
import { User, InMemoryStore } from '@furystack/core'
import { DefaultSession } from './models/default-session'
import got from 'got'
import { JsonResult } from './request-action-implementation'
interface IntegrationTestApi extends RestApi {
GET: {
'/isAuthenticated': RequestAction<{ result: { isAuthenticated: boolean } }>
'/currentUser': RequestAction<{ result: User }>
'/testQuery': RequestAction<{ query: { param1: string }; result: { param1Value: string } }>
'/testUrlParams/:urlParam': RequestAction<{ urlParams: { urlParam: string }; result: { urlParamValue: string } }>
'/isAuthenticated': { result: { isAuthenticated: boolean } }
'/currentUser': { result: User }
'/testQuery': { query: { param1: string }; result: { param1Value: string } }
'/testUrlParams/:urlParam': { url: { urlParam: string }; result: { urlParamValue: string } }
}
POST: {
'/login': RequestAction<{ result: User; body: { username: string; password: string } }>
'/logout': RequestAction<{}>
'/testPostBody': RequestAction<{ body: { value: string }; result: { bodyValue: string } }>
'/login': { result: User; body: { username: string; password: string } }
'/logout': { result: unknown }
'/testPostBody': { body: { value: string }; result: { bodyValue: string } }
}

@@ -23,0 +24,0 @@ }

import { Socket } from 'net'
import { IncomingMessage, ServerResponse } from 'http'
import { BypassResult, JsonResult, PlainTextResult } from '@furystack/rest'
import './server-response-extensions'
import { BypassResult, JsonResult, PlainTextResult } from './request-action-implementation'

@@ -6,0 +6,0 @@ describe('ServerResponse extensions', () => {

import http from 'http'
import { ActionResult } from '@furystack/rest'
import { ActionResult } from './request-action-implementation'

@@ -4,0 +4,0 @@ export interface SendJsonOptions<T> {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc