Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mcma/api

Package Overview
Dependencies
Maintainers
3
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mcma/api - npm Package Compare versions

Comparing version 0.15.0 to 0.16.0

6

dist/lib/http/mcma-api-controller.js

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

class McmaApiController {
routes;
constructor(routes) {

@@ -22,3 +23,2 @@ this.routes = routes;

async handleRequest(requestContext) {
var _a;
const request = requestContext.request;

@@ -31,3 +31,3 @@ const response = requestContext.response;

let requestBodyOK = true;
if (request.body && typeof request.body === "string" && ((_a = request.headers[Object.keys(request.headers).find(h => h.toLowerCase() === "content-type")]) === null || _a === void 0 ? void 0 : _a.toLowerCase().startsWith("application/json"))) {
if (request.body && typeof request.body === "string" && request.headers[Object.keys(request.headers).find(h => h.toLowerCase() === "content-type")]?.toLowerCase().startsWith("application/json")) {
try {

@@ -132,3 +132,3 @@ request.body = JSON.parse(request.body, core_1.Utils.reviver);

const logger = requestContext.getLogger();
logger === null || logger === void 0 ? void 0 : logger.error(error);
logger?.error(error);
response.statusCode = http_statuses_1.HttpStatusCode.InternalServerError;

@@ -135,0 +135,0 @@ response.headers = getDefaultResponseHeaders();

@@ -7,16 +7,21 @@ "use strict";

class McmaApiError extends core_1.McmaObject {
timestamp;
status;
error;
path;
message;
constructor(properties) {
super("ApiError", properties);
super("ApiError");
this.timestamp = core_1.Utils.ensureValidDateOrUndefined(properties.timestamp) ?? new Date();
this.status = properties.status;
if (!this.error) {
this.error = (0, http_statuses_1.getStatusError)(properties.status);
}
this.path = properties.path;
this.message = properties.message;
core_1.Utils.checkProperty(this, "status", "number", true);
core_1.Utils.checkProperty(this, "path", "string", true);
core_1.Utils.checkProperty(this, "message", "string", false);
this.timestamp = core_1.Utils.ensureValidDateOrUndefined(this.timestamp);
if (!this.timestamp) {
this.timestamp = new Date();
}
if (!this.error) {
this.error = (0, http_statuses_1.getStatusError)(this.status);
}
}
}
exports.McmaApiError = McmaApiError;

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

class McmaApiRequestConfig {
id;
path;
httpMethod;
headers;
pathVariables;
queryStringParameters;
body;
}
exports.McmaApiRequestConfig = McmaApiRequestConfig;

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

class McmaApiRequestContext {
request;
loggerProvider;
configVariables;
response = new mcma_api_response_1.McmaApiResponse();
constructor(request, loggerProvider, configVariables) {

@@ -14,3 +18,2 @@ this.request = request;

this.configVariables = configVariables;
this.response = new mcma_api_response_1.McmaApiResponse();
}

@@ -48,3 +51,2 @@ hasRequestBody() {

getTracker() {
var _a, _b, _c, _d;
// try to get the tracker from the headers or query string first

@@ -61,13 +63,12 @@ const headerOrQueryParam = (this.request && this.request.headers && this.request.headers[client_1.McmaHeaders.tracker]) ||

catch (e) {
(_b = (_a = this.loggerProvider) === null || _a === void 0 ? void 0 : _a.get(this.request.id)) === null || _b === void 0 ? void 0 : _b.warn(`Failed to convert text in header or query param 'mcmaTracker' to an McmaTracker object. Error: ${e}`);
this.loggerProvider?.get(this.request.id)?.warn(`Failed to convert text in header or query param 'mcmaTracker' to an McmaTracker object. Error: ${e}`);
}
}
// if we didn't find it in the header or query string, try the body
return (_d = (_c = this.request) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.tracker;
return this.request?.body?.tracker;
}
getLogger() {
var _a;
return (_a = this.loggerProvider) === null || _a === void 0 ? void 0 : _a.get(this.request.id, this.getTracker());
return this.loggerProvider?.get(this.request.id, this.getTracker());
}
}
exports.McmaApiRequestContext = McmaApiRequestContext;

@@ -7,13 +7,12 @@ "use strict";

constructor(config) {
var _a, _b, _c, _d, _e, _f, _g;
super();
this.id = (_a = config === null || config === void 0 ? void 0 : config.id) !== null && _a !== void 0 ? _a : null;
this.path = (_b = config === null || config === void 0 ? void 0 : config.path) !== null && _b !== void 0 ? _b : null;
this.httpMethod = (_c = config === null || config === void 0 ? void 0 : config.httpMethod) !== null && _c !== void 0 ? _c : null;
this.headers = (_d = config === null || config === void 0 ? void 0 : config.headers) !== null && _d !== void 0 ? _d : {};
this.pathVariables = (_e = config === null || config === void 0 ? void 0 : config.pathVariables) !== null && _e !== void 0 ? _e : {};
this.queryStringParameters = (_f = config === null || config === void 0 ? void 0 : config.queryStringParameters) !== null && _f !== void 0 ? _f : {};
this.body = (_g = config === null || config === void 0 ? void 0 : config.body) !== null && _g !== void 0 ? _g : null;
this.id = config?.id ?? null;
this.path = config?.path ?? null;
this.httpMethod = config?.httpMethod ?? null;
this.headers = config?.headers ?? {};
this.pathVariables = config?.pathVariables ?? {};
this.queryStringParameters = config?.queryStringParameters ?? {};
this.body = config?.body ?? null;
}
}
exports.McmaApiRequest = McmaApiRequest;

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

class McmaApiResponse {
constructor() {
this.statusCode = 0;
this.errorMessage = null;
this.headers = {};
}
statusCode = 0;
errorMessage = null;
headers = {};
body;
}
exports.McmaApiResponse = McmaApiResponse;

@@ -10,5 +10,4 @@ import { McmaResource } from "@mcma/core";

onCompleted: (requestContext: McmaApiRequestContext, resource: T) => Promise<void>;
handler: (requestContext: McmaApiRequestContext) => Promise<void>;
constructor(dbTableProvider: DocumentDatabaseTableProvider, root: string);
private defaultHandler;
}

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

class DefaultCreateRoute extends route_1.McmaApiRoute {
dbTableProvider;
root;
onStarted;
onCompleted;
constructor(dbTableProvider, root) {
super("POST", root, requestContext => this.handler(requestContext));
super("POST", root, requestContext => this.defaultHandler(requestContext));
this.dbTableProvider = dbTableProvider;
this.root = root;
this.handler = reqCtx => this.defaultHandler(reqCtx);
}

@@ -17,0 +20,0 @@ async defaultHandler(requestContext) {

@@ -10,5 +10,4 @@ import { McmaResource } from "@mcma/core";

onCompleted: (requestContext: McmaApiRequestContext, resource: T) => Promise<void>;
handler: (requestContext: McmaApiRequestContext) => Promise<void>;
constructor(dbTableProvider: DocumentDatabaseTableProvider, root: string);
private defaultHandler;
}

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

class DefaultDeleteRoute extends route_1.McmaApiRoute {
dbTableProvider;
root;
onStarted;
onCompleted;
constructor(dbTableProvider, root) {
super("DELETE", root + "/{id}", requestContext => this.handler(requestContext));
super("DELETE", root + "/{id}", requestContext => this.defaultHandler(requestContext));
this.dbTableProvider = dbTableProvider;
this.root = root;
this.handler = reqCtx => this.defaultHandler(reqCtx);
}

@@ -14,0 +17,0 @@ async defaultHandler(requestContext) {

@@ -10,5 +10,4 @@ import { McmaResource } from "@mcma/core";

onCompleted: (requestContext: McmaApiRequestContext, resource: T) => Promise<void>;
handler: (requestContext: McmaApiRequestContext) => Promise<void>;
constructor(dbTableProvider: DocumentDatabaseTableProvider, root: string);
private defaultHandler;
}

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

class DefaultGetRoute extends route_1.McmaApiRoute {
dbTableProvider;
root;
onStarted;
onCompleted;
constructor(dbTableProvider, root) {
super("GET", root + "/{id}", requestContext => this.handler(requestContext));
super("GET", root + "/{id}", requestContext => this.defaultHandler(requestContext));
this.dbTableProvider = dbTableProvider;
this.root = root;
this.handler = reqCtx => this.defaultHandler(reqCtx);
}

@@ -14,0 +17,0 @@ async defaultHandler(requestContext) {

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

class DefaultJobRouteCollection extends default_route_collection_1.DefaultRouteCollection {
dbTableProvider;
workerInvoker;
constructor(dbTableProvider, workerInvoker, root) {

@@ -14,0 +16,0 @@ super(dbTableProvider, core_1.JobAssignment, root);

@@ -15,3 +15,2 @@ import { McmaResource } from "@mcma/core";

onCompleted: (requestContext: McmaApiRequestContext, queryResults: QueryResults<T>) => Promise<void>;
handleRequest: (requestContext: McmaApiRequestContext) => Promise<void>;
private customQueryFactories;

@@ -18,0 +17,0 @@ constructor(dbTableProvider: DocumentDatabaseTableProvider, root: string);

@@ -7,9 +7,13 @@ "use strict";

class DefaultQueryRoute extends route_1.McmaApiRoute {
dbTableProvider;
root;
onStarted;
buildQuery;
onCompleted;
customQueryFactories = [];
constructor(dbTableProvider, root) {
super("GET", root, requestContext => this.handleRequest(requestContext));
super("GET", root, requestContext => this.defaultHandleRequest(requestContext));
this.dbTableProvider = dbTableProvider;
this.root = root;
this.customQueryFactories = [];
this.buildQuery = reqCtx => this.defaultBuildQuery(reqCtx);
this.handleRequest = reqCtx => this.defaultHandleRequest(reqCtx);
}

@@ -21,5 +25,4 @@ addCustomQuery(factory) {

defaultBuildQuery(requestContext) {
var _a;
const customQueryFactory = this.customQueryFactories.find(x => x.isMatch(requestContext));
return (_a = customQueryFactory === null || customQueryFactory === void 0 ? void 0 : customQueryFactory.create(requestContext)) !== null && _a !== void 0 ? _a : buildStandardQuery(requestContext);
return customQueryFactory?.create(requestContext) ?? buildStandardQuery(requestContext);
}

@@ -26,0 +29,0 @@ async defaultHandleRequest(requestContext) {

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

class DefaultRouteCollection extends route_collection_1.McmaApiRouteCollection {
query;
create;
get;
update;
delete;
constructor(dbTableProvider, resourceType, root) {

@@ -15,0 +20,0 @@ super();

@@ -10,5 +10,4 @@ import { McmaResource } from "@mcma/core";

onCompleted: (requestContext: McmaApiRequestContext, resource: T) => Promise<void>;
handler: (requestContext: McmaApiRequestContext) => Promise<void>;
constructor(dbTableProvider: DocumentDatabaseTableProvider, root: string);
private defaultHandler;
}

@@ -9,7 +9,10 @@ "use strict";

class DefaultUpdateRoute extends route_1.McmaApiRoute {
dbTableProvider;
root;
onStarted;
onCompleted;
constructor(dbTableProvider, root) {
super("PUT", root + "/{id}", requestContext => this.handler(requestContext));
super("PUT", root + "/{id}", requestContext => this.defaultHandler(requestContext));
this.dbTableProvider = dbTableProvider;
this.root = root;
this.handler = reqCtx => this.defaultHandler(reqCtx);
}

@@ -16,0 +19,0 @@ async defaultHandler(requestContext) {

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

class McmaApiRouteCollection {
routes = [];
constructor(routes) {
this.routes = [];
if (routes) {

@@ -11,0 +11,0 @@ this.addRoutes(routes);

import { McmaApiRequestContext } from "../http/mcma-api-request-context";
export declare type McmaApiRouteHandler = (requestContext: McmaApiRequestContext) => Promise<void>;
export type McmaApiRouteHandler = (requestContext: McmaApiRequestContext) => Promise<void>;

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

class McmaApiRoute {
httpMethod;
path;
handler;
template;
constructor(httpMethod, path, handler) {

@@ -8,0 +12,0 @@ this.httpMethod = httpMethod;

{
"name": "@mcma/api",
"version": "0.15.0",
"version": "0.16.0",
"description": "Node module for building APIs based on the EBU MCMA framework",
"engines": {
"node": "^16.0.0"
"node": "^18.0.0"
},

@@ -37,20 +37,20 @@ "type": "commonjs",

"uri-templates": "^0.2.0",
"uuid": "^7.0.3"
"uuid": "^9.0.0"
},
"peerDependencies": {
"@mcma/client": "0.15.0",
"@mcma/core": "0.15.0",
"@mcma/data": "0.15.0",
"@mcma/worker-invoker": "0.15.0"
"@mcma/client": "0.16.0",
"@mcma/core": "0.16.0",
"@mcma/data": "0.16.0",
"@mcma/worker-invoker": "0.16.0"
},
"devDependencies": {
"@mcma/client": "0.15.0",
"@mcma/core": "0.15.0",
"@mcma/data": "0.15.0",
"@mcma/worker-invoker": "0.15.0",
"@types/node": "^16.11.60",
"@mcma/client": "0.16.0",
"@mcma/core": "0.16.0",
"@mcma/data": "0.16.0",
"@mcma/worker-invoker": "0.16.0",
"@types/node": "^18.15.10",
"@types/pluralize": "0.0.29",
"@types/uuid": "^7.0.3",
"@types/uuid": "^9.0.1",
"jasmine": "^3.2.0"
}
}
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