Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
promoted-nodejs-client
Advanced tools
Readme
A Node.js client for Promoted APIs.
We recommend creating a PromotedClient in a separate file so (1) it can be shared between files and (2) hides some of the configuration.
PromotedClient avoids having direct dependencies to certain implementation details so we can support customization and keep the binary small.
promotedClient.js
import { logOnError, newPromotedClient, throwOnError } from 'promoted-nodejs-client';
import { v5 as uuid } from 'uuid';
import axios from 'axios';
const axiosApiClient = <Req, Res>(url: string, apiKey: string, timeout: number) => (request: Req): Promise<Res> =>
axios.post(
url,
request,
{
headers: {
"x-api-key": apiKey,
},
timeout: 3000,
});
// These values will vary depending on dev vs prod.
const deliveryApi = 'https://....com/...';
const deliveryApiKey = 'AbCSomeRLongString1';
const deliveryTimeoutMillis = 250;
const metricsApi = 'https://....com/...';
const metricsApiKey = 'AbCSomeRLongString2';
const metricsTimeoutMillis = 3000;
// NextJS example. Throw in dev. Console log in prod.
const throwError =
process?.env?.NODE_ENV !== 'production' ||
(typeof location !== "undefined" && location?.hostname === "localhost");
export const promotedClient = newPromotedClient({
handleError: throwError ? throwOnError : logOnError;
deliveryClient: axiosApiClient(deliveryApi, deliveryApiKey, deliveryTimeoutMillis),
metricsClient: axiosApiClient(metricsApi, metricsApiKey, metricsTimeoutMillis),
uuid,
deliveryTimeoutMillis,
metricsTimeoutMillis,
});
Let's say the previous code looks like this:
static async getProducts(req: any, res: Response) {
const products = ...; // Logic to get products from DB, apply filtering, etc.
sendSuccessToClient(res, { products });
}
We would modify to something like this:
static async getProducts(req: any, res: Response) {
const products = ...;
const response = await promotedClient.deliver({
request: {
userInfo: {
logUserId: req.logUserId,
},
useCase: 'FEED',
sessionId: req.sessionId,
viewId: req.viewId,
insertion: products.map(product => ({
contentId: product.id,
properties: {
struct: {
product,
},
},
})),
},
});
// Change the result Product list to use the values in the returned Insertions.
sendSuccessToClient(res, {
products: response.insertion.map(insertion => insertion.properties.struct),
});
await response.finishAfterResponse();
}
There are a bunch of additional options.
Uses
npm run finish
npm run build
npm run size
npm run lint
npm test
or npm test
If you want to test local changes in an actual deployment, use npm link
.
npm run updateLink
.npm link promoted-nodejs-client
.When you update promoted-nodejs-client
, run npm run updateLink
.
When you want to undo, use npm unlink
in promoted-nodejs-client/dist
and npm unlink promoted-nodejs-client
in the client directory.
We use a GitHub action that runs semantic-release to determine how to update versions. Just do a normal code review and this should work. Depending on the message prefixes (e.g. feat:
, fix:
, clean:
, docs:
), it'll update the version appropriately.
The base of this repository is a combination of the following repos:
FAQs
Logging utility for browser-side Typescript that logs Promoted events to our Metrics Snowplow-compatible API
We found that promoted-nodejs-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.