@furystack/rest-service
Advanced tools
Comparing version 7.0.11 to 7.0.12
@@ -21,6 +21,4 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
import { HttpUserContext } from './http-user-context.js'; | ||
export let ApiManager = class ApiManager { | ||
constructor() { | ||
this.apis = new Map(); | ||
} | ||
let ApiManager = class ApiManager { | ||
apis = new Map(); | ||
dispose() { | ||
@@ -145,2 +143,3 @@ this.apis.clear(); | ||
} | ||
serverManager; | ||
}; | ||
@@ -154,2 +153,3 @@ __decorate([ | ||
], ApiManager); | ||
export { ApiManager }; | ||
//# sourceMappingURL=api-manager.js.map |
@@ -7,2 +7,4 @@ import { addStore, InMemoryStore, User } from '@furystack/core'; | ||
export class MockClass { | ||
id; | ||
value; | ||
} | ||
@@ -9,0 +11,0 @@ export const setupContext = (i) => { |
@@ -13,10 +13,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
*/ | ||
export let HttpAuthenticationSettings = class HttpAuthenticationSettings { | ||
constructor() { | ||
this.model = User; | ||
this.getUserStore = (sm) => sm.getStoreFor(User, 'username'); | ||
this.getSessionStore = (sm) => sm.getStoreFor(DefaultSession, 'sessionId'); | ||
this.cookieName = 'fss'; | ||
this.enableBasicAuth = true; | ||
} | ||
let HttpAuthenticationSettings = class HttpAuthenticationSettings { | ||
model = User; | ||
getUserStore = (sm) => sm.getStoreFor(User, 'username'); | ||
getSessionStore = (sm) => sm.getStoreFor(DefaultSession, 'sessionId'); | ||
cookieName = 'fss'; | ||
enableBasicAuth = true; | ||
}; | ||
@@ -26,2 +24,3 @@ HttpAuthenticationSettings = __decorate([ | ||
], HttpAuthenticationSettings); | ||
export { HttpAuthenticationSettings }; | ||
//# sourceMappingURL=http-authentication-settings.js.map |
@@ -18,23 +18,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
*/ | ||
export let HttpUserContext = class HttpUserContext { | ||
constructor() { | ||
this.getUserStore = () => this.authentication.getUserStore(this.storeManager); | ||
this.getSessionStore = () => this.authentication.getSessionStore(this.storeManager); | ||
this.getUserByName = async (userName) => { | ||
const userStore = this.getUserStore(); | ||
const users = await userStore.find({ filter: { username: { $eq: userName } }, top: 2 }); | ||
if (users.length !== 1) { | ||
throw new UnauthenticatedError(); | ||
} | ||
return users[0]; | ||
}; | ||
this.getSessionById = async (sessionId) => { | ||
const sessionStore = this.getSessionStore(); | ||
const sessions = await sessionStore.find({ filter: { sessionId: { $eq: sessionId } }, top: 2 }); | ||
if (sessions.length !== 1) { | ||
throw new UnauthenticatedError(); | ||
} | ||
return sessions[0]; | ||
}; | ||
} | ||
let HttpUserContext = class HttpUserContext { | ||
getUserStore = () => this.authentication.getUserStore(this.storeManager); | ||
getSessionStore = () => this.authentication.getSessionStore(this.storeManager); | ||
getUserByName = async (userName) => { | ||
const userStore = this.getUserStore(); | ||
const users = await userStore.find({ filter: { username: { $eq: userName } }, top: 2 }); | ||
if (users.length !== 1) { | ||
throw new UnauthenticatedError(); | ||
} | ||
return users[0]; | ||
}; | ||
getSessionById = async (sessionId) => { | ||
const sessionStore = this.getSessionStore(); | ||
const sessions = await sessionStore.find({ filter: { sessionId: { $eq: sessionId } }, top: 2 }); | ||
if (sessions.length !== 1) { | ||
throw new UnauthenticatedError(); | ||
} | ||
return sessions[0]; | ||
}; | ||
user; | ||
/** | ||
@@ -152,2 +151,5 @@ * @param request The request to be authenticated | ||
} | ||
authentication; | ||
storeManager; | ||
authenticator; | ||
}; | ||
@@ -169,2 +171,3 @@ __decorate([ | ||
], HttpUserContext); | ||
export { HttpUserContext }; | ||
//# sourceMappingURL=http-user-context.js.map |
@@ -5,3 +5,11 @@ /** | ||
export class DefaultSession { | ||
/** | ||
* The generated session identifier | ||
*/ | ||
sessionId; | ||
/** | ||
* The user's login name for the session | ||
*/ | ||
username; | ||
} | ||
//# sourceMappingURL=default-session.js.map |
@@ -6,2 +6,3 @@ import { RequestError } from '@furystack/rest'; | ||
export class SchemaValidationError extends RequestError { | ||
errors; | ||
constructor(errors) { | ||
@@ -8,0 +9,0 @@ super('Schema Validation failed', 400); |
@@ -6,5 +6,4 @@ import type { Options } from 'ajv'; | ||
private readonly schema; | ||
private readonly ajvOptions?; | ||
private readonly ajv; | ||
constructor(schema: TSchema, ajvOptions?: Options | undefined); | ||
constructor(schema: TSchema, ajvOptions?: Options); | ||
/** | ||
@@ -11,0 +10,0 @@ * @param data The object to validate |
@@ -5,8 +5,9 @@ import Ajv from 'ajv'; | ||
export class SchemaValidator { | ||
schema; | ||
ajv; | ||
constructor(schema, ajvOptions) { | ||
this.schema = schema; | ||
this.ajvOptions = ajvOptions; | ||
this.ajv = new Ajv.default({ | ||
allErrors: true, | ||
...this.ajvOptions, | ||
...ajvOptions, | ||
}); | ||
@@ -13,0 +14,0 @@ useFormats.default(this.ajv); |
@@ -11,13 +11,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
import { Lock } from 'semaphore-async-await'; | ||
export let ServerManager = ServerManager_1 = class ServerManager { | ||
constructor() { | ||
this.servers = new Map(); | ||
this.openedSockets = new Set(); | ||
this.listenLock = new Lock(); | ||
this.getHostUrl = (options) => `http://${options.hostName || ServerManager_1.DEFAULT_HOST}:${options.port}`; | ||
this.onConnection = (socket) => { | ||
this.openedSockets.add(socket); | ||
socket.once('close', () => this.openedSockets.delete(socket)); | ||
}; | ||
} | ||
let ServerManager = class ServerManager { | ||
static { ServerManager_1 = this; } | ||
static DEFAULT_HOST = 'localhost'; | ||
servers = new Map(); | ||
openedSockets = new Set(); | ||
listenLock = new Lock(); | ||
getHostUrl = (options) => `http://${options.hostName || ServerManager_1.DEFAULT_HOST}:${options.port}`; | ||
onConnection = (socket) => { | ||
this.openedSockets.add(socket); | ||
socket.once('close', () => this.openedSockets.delete(socket)); | ||
}; | ||
async dispose() { | ||
@@ -69,6 +69,6 @@ try { | ||
}; | ||
ServerManager.DEFAULT_HOST = 'localhost'; | ||
ServerManager = ServerManager_1 = __decorate([ | ||
Injectable({ lifetime: 'singleton' }) | ||
], ServerManager); | ||
export { ServerManager }; | ||
//# sourceMappingURL=server-manager.js.map |
@@ -16,28 +16,4 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
import { ServerManager } from './server-manager.js'; | ||
export let StaticServerManager = class StaticServerManager { | ||
constructor() { | ||
this.shouldExec = (baseUrl) => ({ req }) => req.url && | ||
req.method?.toUpperCase() === 'GET' && | ||
(req.url === baseUrl || req.url.startsWith(baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`)) | ||
? true | ||
: false; | ||
this.onRequest = ({ path, baseUrl, fallback, headers, }) => { | ||
return async ({ req, res }) => { | ||
const filePath = req.url.substring(baseUrl.length - 1).replaceAll('/', sep); | ||
const fullPath = normalize(join(path, filePath)); | ||
try { | ||
await this.sendFile({ fullPath, res, headers }); | ||
} | ||
catch (error) { | ||
if (fallback) { | ||
await this.sendFile({ fullPath: normalize(join(path, fallback)), res, headers }); | ||
} | ||
else { | ||
res.writeHead(404, { 'Content-Type': 'text/plain' }); | ||
res.end('Not found'); | ||
} | ||
} | ||
}; | ||
}; | ||
} | ||
let StaticServerManager = class StaticServerManager { | ||
serverManager; | ||
async sendFile({ fullPath, headers, res, }) { | ||
@@ -54,2 +30,25 @@ const { size } = await stat(fullPath); | ||
} | ||
shouldExec = (baseUrl) => ({ req }) => req.url && | ||
req.method?.toUpperCase() === 'GET' && | ||
(req.url === baseUrl || req.url.startsWith(baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`)) | ||
? true | ||
: false; | ||
onRequest = ({ path, baseUrl, fallback, headers, }) => { | ||
return async ({ req, res }) => { | ||
const filePath = req.url.substring(baseUrl.length - 1).replaceAll('/', sep); | ||
const fullPath = normalize(join(path, filePath)); | ||
try { | ||
await this.sendFile({ fullPath, res, headers }); | ||
} | ||
catch (error) { | ||
if (fallback) { | ||
await this.sendFile({ fullPath: normalize(join(path, fallback)), res, headers }); | ||
} | ||
else { | ||
res.writeHead(404, { 'Content-Type': 'text/plain' }); | ||
res.end('Not found'); | ||
} | ||
} | ||
}; | ||
}; | ||
async addStaticSite(options) { | ||
@@ -70,2 +69,3 @@ const server = await this.serverManager.getOrCreate({ hostName: options.hostName, port: options.port }); | ||
], StaticServerManager); | ||
export { StaticServerManager }; | ||
//# sourceMappingURL=static-server-manager.js.map |
@@ -11,3 +11,3 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
*/ | ||
export let Utils = class Utils { | ||
let Utils = class Utils { | ||
async readPostBodyRaw(incomingMessage) { | ||
@@ -70,2 +70,3 @@ if (!incomingMessage.readable) { | ||
], Utils); | ||
export { Utils }; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@furystack/rest-service", | ||
"version": "7.0.11", | ||
"version": "7.0.12", | ||
"description": "Repository implementation for FuryStack", | ||
@@ -40,8 +40,8 @@ "type": "module", | ||
"dependencies": { | ||
"@furystack/core": "^12.0.9", | ||
"@furystack/inject": "^8.0.8", | ||
"@furystack/repository": "^7.0.9", | ||
"@furystack/rest": "^5.0.10", | ||
"@furystack/security": "^3.0.9", | ||
"@furystack/utils": "^4.0.8", | ||
"@furystack/core": "^12.0.10", | ||
"@furystack/inject": "^8.1.0", | ||
"@furystack/repository": "^7.0.10", | ||
"@furystack/rest": "^5.0.11", | ||
"@furystack/security": "^3.0.10", | ||
"@furystack/utils": "^4.0.9", | ||
"ajv": "^8.12.0", | ||
@@ -53,8 +53,8 @@ "ajv-formats": "^2.1.1", | ||
"devDependencies": { | ||
"@furystack/rest-client-fetch": "^5.0.10", | ||
"@types/node": "^20.5.3", | ||
"typescript": "^5.1.6", | ||
"vitest": "^0.34.2" | ||
"@furystack/rest-client-fetch": "^5.0.11", | ||
"@types/node": "^20.5.6", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.3" | ||
}, | ||
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321" | ||
} |
@@ -7,10 +7,11 @@ import type { ErrorObject, Options } from 'ajv' | ||
export class SchemaValidator<TSchema extends { definitions: {} }> { | ||
private readonly ajv = new Ajv.default({ | ||
allErrors: true, | ||
...this.ajvOptions, | ||
}) | ||
private readonly ajv: Ajv.default | ||
constructor( | ||
private readonly schema: TSchema, | ||
private readonly ajvOptions?: Options, | ||
ajvOptions?: Options, | ||
) { | ||
this.ajv = new Ajv.default({ | ||
allErrors: true, | ||
...ajvOptions, | ||
}) | ||
useFormats.default(this.ajv) | ||
@@ -17,0 +18,0 @@ } |
@@ -13,3 +13,3 @@ import { Injector } from '@furystack/inject' | ||
*/ | ||
function* getPort(initialPort = 1234) { | ||
function* portGenerator(initialPort = 1234) { | ||
let port = initialPort | ||
@@ -23,5 +23,5 @@ | ||
const getPort = () => portGenerator().next().value | ||
describe('StaticServerManager', () => { | ||
const portGenerator = getPort() | ||
describe('Top level routing', () => { | ||
@@ -31,3 +31,3 @@ it('Should return a 404 without fallback', async () => { | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
await staticServerManager.addStaticSite({ | ||
@@ -51,3 +51,3 @@ baseUrl: '/', | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -74,3 +74,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -97,3 +97,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -119,3 +119,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -139,3 +139,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -165,3 +165,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -186,3 +186,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -205,3 +205,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -223,3 +223,3 @@ await staticServerManager.addStaticSite({ | ||
const staticServerManager = injector.getInstance(StaticServerManager) | ||
const port = portGenerator.next().value | ||
const port = getPort() | ||
@@ -226,0 +226,0 @@ await staticServerManager.addStaticSite({ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7881
385419
Updated@furystack/core@^12.0.10
Updated@furystack/inject@^8.1.0
Updated@furystack/rest@^5.0.11
Updated@furystack/security@^3.0.10
Updated@furystack/utils@^4.0.9