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

@saasly/backend-events

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saasly/backend-events - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

5

package.json
{
"name": "@saasly/backend-events",
"version": "1.0.0",
"version": "1.0.1",
"description": "",

@@ -17,3 +17,2 @@ "main": "src/index.ts",

"devDependencies": {
"aws-sdk": "^2.1209.0",
"@tsconfig/recommended": "^1.0.1",

@@ -23,2 +22,3 @@ "@types/aws-lambda": "^8.10.101",

"@types/node": "^18.7.8",
"aws-sdk": "^2.1209.0",
"jest": "^29.0.2",

@@ -28,2 +28,3 @@ "nodemon": "^2.0.19",

"ts-node": "^10.9.1",
"tslib": "^2.4.0",
"typescript": "4.8.2"

@@ -30,0 +31,0 @@ },

2

src/extras/getConnection.ts
import * as AWS from "aws-sdk";
import { DocumentClient } from "aws-sdk/lib/dynamodb/document_client";
let client = null;
let client: DocumentClient | null = null;

@@ -6,0 +6,0 @@ export interface InterfaceOptions {

@@ -7,7 +7,7 @@ import httpStatusCodeEnum from "./httpStatusCodeEnum";

eventName: string;
statusAtMs: number;
data?: any;
dataStatus?: httpStatusCodeEnum;
statusAtMs?: number;
createdAtMs: number;
resolvedAtMs?: number;
}

@@ -1,16 +0,11 @@

import * as getId from "get-short-id";
import getConnection from "./extras/getConnection";
import ItemInterface from "./extras/ItemInterface";
export interface InterfaceResultSuccess {
httpStatus: number;
result: {
Item: ItemInterface;
};
}
const getId = require("get-short-id");
export interface InterfaceResultError {
export interface InterfaceResult {
httpStatus: number;
result: {
error: string;
error?: string;
Item?: ItemInterface;
};

@@ -25,3 +20,3 @@ }

idempotentId,
}: InterfacePayload): Promise<InterfaceResultSuccess | InterfaceResultError> {
}: InterfacePayload): Promise<InterfaceResult> {
let db = getConnection({});

@@ -31,9 +26,8 @@

let result = null;
let httpStatus = 200;
let eventResult = null;
try {
result = await db
let queryResult = await db
.query({
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME,
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME || "",
Limit: 1,

@@ -48,22 +42,42 @@ ConsistentRead: true,

if (typeof result?.Items?.[0]?.idempotentId === "undefined") {
httpStatus = 404;
result = {
error: "Not found",
if (typeof queryResult?.Items?.[0]?.idempotentId === "undefined") {
eventResult = {
httpStatus: 404,
result: { error: "Not found" },
};
} else {
httpStatus = 200;
result = {
Item: result.Items[0],
};
eventResult = {
httpStatus: 200,
result: {
Item: {
idempotentId: queryResult.Items[0].idempotentId as string,
status: queryResult.Items[0].status as "pending" | "resolved",
eventName: queryResult.Items[0].eventName as string,
createdAtMs: queryResult.Items[0].createdAtMs as number,
statusAtMs: queryResult.Items[0].statusAtMs as number,
},
},
} as InterfaceResult;
if (
queryResult.Items[0].data &&
typeof eventResult?.result?.Item === "object"
) {
eventResult.result.Item.data = queryResult.Items[0].data;
eventResult.result.Item.dataStatus = queryResult.Items[0].dataStatus;
eventResult.result.Item.resolvedAtMs =
queryResult.Items[0].resolvedAtMs;
}
}
} catch (e: any) {
httpStatus = 500;
console.error(`#202224910427719 error: `, e.message);
result = {
error: e.message,
eventResult = {
httpStatus: 500,
result: {
error: e.message as string,
},
};
}
return { httpStatus, result };
return eventResult;
}
import getConnection from "./extras/getConnection";
import ItemInterface from "./extras/ItemInterface";
export interface InterfaceResultSuccess {
export interface InterfaceResult {
httpStatus: number;
result: {
Count: number;
ScannedCount: number;
Items: ItemInterface[];
error?: string;
Count?: number;
ScannedCount?: number;
Items?: ItemInterface[];
};
}
export interface InterfaceResultError {
httpStatus: number;
result: {
error: string;
};
}
export default async function getNextResolvedEvents({

@@ -26,12 +20,11 @@ Limit,

LastEvaluatedKey?: { [key: string]: any };
}): Promise<InterfaceResultSuccess | InterfaceResultError> {
}): Promise<InterfaceResult> {
let db = getConnection({});
let httpStatus = 200;
let result;
let eventResult;
try {
result = await db
let queryResult = await db
.query({
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME,
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME || "",
ExclusiveStartKey: LastEvaluatedKey,

@@ -45,11 +38,21 @@ IndexName: "status",

.promise();
eventResult = {
httpStatus: 200,
result: {
Items: queryResult.Items as ItemInterface[],
ScannedCount: queryResult.ScannedCount,
Count: queryResult.Count,
},
} as InterfaceResult;
} catch (e: any) {
httpStatus = 500;
console.error(`#2022249135015806 error: `, e.message);
result = {
error: e.message,
eventResult = {
httpStatus: 500,
result: {
error: e.message,
},
};
}
return { httpStatus, result };
return eventResult;
}

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

import * as getId from "get-short-id";
import getConnection from "./extras/getConnection";

@@ -6,10 +5,7 @@ import httpStatusCodeEnum from "./extras/httpStatusCodeEnum";

export interface InterfaceResultSuccess {
httpStatus: number;
result: ItemInterface;
}
const getId = require("get-short-id");
export interface InterfaceResultError {
export interface InterfaceResult {
httpStatus: number;
result: { error: string };
result: { error: string } | ItemInterface;
}

@@ -33,3 +29,3 @@

resolvedAtMs,
}: Payload): Promise<InterfaceResultSuccess | InterfaceResultError> {
}: Payload): Promise<InterfaceResult> {
let db = getConnection({});

@@ -44,3 +40,3 @@

let Item: ItemInterface = {
idempotentId,
idempotentId: idempotentId as string,
status: "pending",

@@ -64,3 +60,3 @@ statusAtMs: createdAtMs,

.put({
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME,
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME || "",
Item,

@@ -67,0 +63,0 @@ ConditionExpression: "attribute_not_exists(idempotentId)",

@@ -1,18 +0,16 @@

import * as getId from "get-short-id";
import getConnection from "./extras/getConnection";
import httpStatusCodeEnum from "./extras/httpStatusCodeEnum";
export interface InterfaceResultSuccess {
httpStatus: number;
result: {
success: true;
idempotentId: string;
createdAtMs: number;
resolvedAtMs: number;
};
}
const getId = require("get-short-id");
export interface InterfaceResultError {
export interface InterfaceResult {
httpStatus: number;
result: { error: string };
result:
| { error: string }
| {
success: true;
idempotentId: string;
createdAtMs: number;
resolvedAtMs: number;
};
}

@@ -34,3 +32,3 @@

resolvedAtMs,
}: InterfacePayload): Promise<InterfaceResultSuccess | InterfaceResultError> {
}: InterfacePayload): Promise<InterfaceResult> {
let db = getConnection({});

@@ -41,4 +39,3 @@

let result = null;
let httpStatus = 200;
let eventResult = null;

@@ -48,3 +45,3 @@ try {

.update({
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME,
TableName: process.env.EVENTS_MANAGER_DYNAMO_TABLE_NAME || "",
Key: {

@@ -69,18 +66,30 @@ idempotentId,

.promise();
result = { success: true, idempotentId, createdAtMs, resolvedAtMs };
eventResult = {
httpStatus: 200,
result: {
success: true,
idempotentId,
createdAtMs,
resolvedAtMs,
},
};
} catch (e: any) {
if (e.message === "The conditional request failed") {
result = {
error: "Result already set or event not found",
eventResult = {
httpStatus: 400,
result: {
error: "Result already set or event not found",
},
};
httpStatus = 400;
} else {
httpStatus = 500;
eventResult = {
httpStatus: 500,
result: {
error: e.message,
},
};
console.error(`#2022249105648116 error: `, e.message);
result = {
error: e.message,
};
}
}
return { httpStatus, result };
return eventResult as InterfaceResult;
}
{
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"target": "es6",
"module": "commonjs",

@@ -6,0 +5,0 @@ "moduleResolution": "node",

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