@buildable/messages
Advanced tools
| export declare class BuildableError extends Error { | ||
| code: number; | ||
| type: string; | ||
| data: any; | ||
| constructor({ message, code, type, data }: { | ||
| message: string; | ||
| code: number; | ||
| type: string; | ||
| data: any; | ||
| }); | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.BuildableError = void 0; | ||
| class BuildableError extends Error { | ||
| constructor({ message, code, type, data }) { | ||
| super(message); | ||
| this.code = code; | ||
| this.type = type; | ||
| this.data = data; | ||
| } | ||
| } | ||
| exports.BuildableError = BuildableError; |
| export class BuildableError extends Error { | ||
| code: number | ||
| type: string | ||
| data: any | ||
| constructor({ message, code, type, data } : { message: string, code: number, type: string, data: any }) { | ||
| super(message) | ||
| this.code = code | ||
| this.type = type | ||
| this.data = data | ||
| } | ||
| } |
+7
-17
@@ -8,7 +8,3 @@ "use strict"; | ||
| const utils_1 = require("../utils"); | ||
| const errorsMap = { | ||
| '401': 'You are not authorized to make this request.', | ||
| emit: 'There was an error trying to emit this event', | ||
| default: 'An error has occurred' | ||
| }; | ||
| const errors_1 = require("../errors"); | ||
| const baseURL = process.env.BLD_EVENTS_BASE_URL || 'https://events.buildable.dev'; | ||
@@ -94,8 +90,3 @@ const emitPath = "/emit"; | ||
| try { | ||
| output = await handler({ | ||
| headers, | ||
| query, | ||
| payload, | ||
| event | ||
| }); | ||
| output = await handler((0, utils_1.getTransactionInput)(event)); | ||
| } | ||
@@ -149,3 +140,3 @@ catch (e) { | ||
| emit: async (event, payload = {}) => { | ||
| var _a, _b, _c; | ||
| var _a, _b; | ||
| if (!event) { | ||
@@ -160,9 +151,7 @@ throw Error('Need to provide an `event name`'); | ||
| const res = await axios_1.default.post(baseURL + emitPath, data, options); | ||
| // todo: check actual response data | ||
| return !!(res === null || res === void 0 ? void 0 : res.data); | ||
| } | ||
| catch (ex) { | ||
| const resCode = (_b = (_a = ex === null || ex === void 0 ? void 0 : ex.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 'emit'; | ||
| const msg = (_c = errorsMap[resCode]) !== null && _c !== void 0 ? _c : errorsMap.default; | ||
| throw Error(msg); | ||
| catch (e) { | ||
| const error = ((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.data) ? new errors_1.BuildableError((_b = e === null || e === void 0 ? void 0 : e.response) === null || _b === void 0 ? void 0 : _b.data) : e; | ||
| throw error; | ||
| } | ||
@@ -199,2 +188,3 @@ }, | ||
| listeners[id].interval = runTransactions({ eventName, txKey, since: options.since, platform: options.platform, label: options.label }); | ||
| console.log("listening to:", fullEventName); | ||
| return { eventName, handler, txKey, options, id }; | ||
@@ -201,0 +191,0 @@ }, |
| export declare const sleep: (n: number) => Promise<unknown>; | ||
| export declare const stringify: (v: any) => any; | ||
| export declare const getTransactionInput: (event?: any) => any; |
+16
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.stringify = exports.sleep = void 0; | ||
| exports.getTransactionInput = exports.stringify = exports.sleep = void 0; | ||
| const sleep = (n) => new Promise(res => setTimeout(res, n)); | ||
@@ -8,1 +8,16 @@ exports.sleep = sleep; | ||
| exports.stringify = stringify; | ||
| const getTransactionInput = (event = {}) => { | ||
| const { payload = "{}", headers = "{}", query = "{}" } = event; | ||
| let input = {}; | ||
| try { | ||
| input.payload = JSON.parse(payload); | ||
| input.headers = JSON.parse(headers); | ||
| input.query = JSON.parse(query); | ||
| return { ...input, event }; | ||
| } | ||
| catch (e) { | ||
| console.error("Error parsing transaction input", e, "event: ", event); | ||
| return { payload, headers, query, event }; | ||
| } | ||
| }; | ||
| exports.getTransactionInput = getTransactionInput; |
+1
-1
| { | ||
| "name": "@buildable/messages", | ||
| "version": "1.0.2", | ||
| "version": "1.0.4", | ||
| "description": "A fully managed messaging service that lets you easily exchange event data across any app or resource.", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
+9
-1
@@ -66,4 +66,8 @@ # `@buildable/messages` | ||
| ### What is a transaction? | ||
| A transaction is an action that can be triggered when a message is received. A message can have multiple transactions. Each transaction has a unique transaction key (`txKey`) per message. | ||
| A transaction is an action that can be triggered when a message is received. A message can have multiple transactions. Each transaction has: | ||
| 1. An input value | ||
| 2. An output value | ||
| 3. A unique transaction key (`txKey`) per message | ||
| There are two cases for transacting on messages: | ||
@@ -84,2 +88,4 @@ | ||
| console.log("Receieved message with payload: ", payload); | ||
| // Any value returned here will be set as the transaction's output | ||
| }); | ||
@@ -102,2 +108,4 @@ ``` | ||
| console.log("Receieved message with payload: ", payload); | ||
| // Any value returned here will be set as the transaction's output | ||
| }, { | ||
@@ -104,0 +112,0 @@ platform: "stripe", // Platform name |
+17
-1
| export const sleep = (n: number) => new Promise(res => setTimeout(res, n)) | ||
| export const stringify = (v: any) => v && typeof v === "object" ? JSON.stringify(v) : v | ||
| export const stringify = (v: any) => v && typeof v === "object" ? JSON.stringify(v) : v | ||
| export const getTransactionInput = (event: any = {}) => { | ||
| const { payload = "{}", headers = "{}", query = "{}" } = event | ||
| let input: any = {} | ||
| try { | ||
| input.payload = JSON.parse(payload) | ||
| input.headers = JSON.parse(headers) | ||
| input.query = JSON.parse(query) | ||
| return { ...input, event } | ||
| } catch(e) { | ||
| console.error("Error parsing transaction input", e, "event: ", event) | ||
| return { payload, headers, query, event } | ||
| } | ||
| } |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
20722
9.68%11
37.5%288
22.03%174
4.82%0
-100%