Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@asyncapi/optimizer
Advanced tools
AsyncAPI offers many ways to reuse certain parts of the document like messages or schemas definitions or references to external files, not to even mention the traits. Purpose of AsyncAPI Optimizer is to enable different ways to optimize AsyncAPI files. It is a library that can be used in UIs and CLIs.
git clone https://github.com/asyncapi/optimizer.git
npm i
npm run example
. You can open examples/index.js
modify it or add your own AsyncAPI document for optimization.import { Optimizer } from '@asyncapi/optimizer'
import type { Report } from '@asyncapi/optimizer'
const yaml = `
asyncapi: 3.0.0
info:
title: Example Service
version: 1.0.0
description: Example Service.
servers:
production:
host: 'test.mosquitto.org:{port}'
protocol: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
operations:
user/deleteAccount.subscribe:
action: send
channel:
$ref: '#/channels/commentLikedChannel'
channels:
commentLikedChannel:
address: comment/liked
messages:
commentLikedMessage:
description: Message that is being sent when a comment has been liked by someone.
payload:
type: object
title: commentLikedPayload
properties:
commentId:
type: string
description: an id object
x-origin: ./schemas.yaml#/schemas/idSchema
x-origin: ./schemas.yaml#/schemas/commentLikedSchema
x-origin: ./messages.yaml#/messages/commentLikedMessage
x-origin: ./channels.yaml#/channels/commentLikedChannel`
const optimizer = new Optimizer(yaml)
const report: Report = await optimizer.getReport()
/*
the report value will be:
{
removeComponents: [],
reuseComponents: [],
moveAllToComponents: [
{
path: 'channels.commentLikedChannel.messages.commentLikedMessage.payload.properties.commentId',
action: 'move',
target: 'components.schemas.idSchema'
},
{
path: 'channels.commentLikedChannel.messages.commentLikedMessage.payload',
action: 'move',
target: 'components.schemas.commentLikedSchema'
},
{
path: 'channels.commentLikedChannel.messages.commentLikedMessage',
action: 'move',
target: 'components.messages.commentLikedMessage'
},
{
path: 'operations.user/deleteAccount.subscribe',
action: 'move',
target: 'components.operations.subscribe'
},
{
path: 'channels.commentLikedChannel',
action: 'move',
target: 'components.channels.commentLikedChannel'
},
{
path: 'servers.production',
action: 'move',
target: 'components.servers.production'
}
],
moveDuplicatesToComponents: []
}
*/
const optimizedDocument = optimizer.getOptimizedDocument({
output: 'YAML',
rules: {
reuseComponents: true,
removeComponents: true,
moveAllToComponents: true,
moveDuplicatesToComponents: false,
},
disableOptimizationFor: {
schema: false,
},
})
/*
the optimizedDocument value will be:
asyncapi: 3.0.0
info:
title: Example Service
version: 1.0.0
description: Example Service.
servers:
production:
$ref: '#/components/servers/production'
operations:
user/deleteAccount.subscribe:
action: send
channel:
$ref: '#/channels/commentLikedChannel'
user/deleteAccount:
subscribe:
$ref: '#/components/operations/subscribe'
channels:
commentLikedChannel:
$ref: '#/components/channels/commentLikedChannel'
components:
schemas:
idSchema:
type: string
description: an id object
x-origin: ./schemas.yaml#/schemas/idSchema
commentLikedSchema:
type: object
title: commentLikedPayload
properties:
commentId:
$ref: '#/components/schemas/idSchema'
x-origin: ./schemas.yaml#/schemas/commentLikedSchema
messages:
commentLikedMessage:
description: Message that is being sent when a comment has been liked by someone.
payload:
$ref: '#/components/schemas/commentLikedSchema'
x-origin: ./messages.yaml#/messages/commentLikedMessage
operations: {}
channels:
commentLikedChannel:
address: comment/liked
messages:
commentLikedMessage:
$ref: '#/components/messages/commentLikedMessage'
x-origin: ./channels.yaml#/channels/commentLikedChannel
servers:
production:
host: test.mosquitto.org:{port}
protocol: mqtt
description: Test broker
variables:
port:
description: Secure connection (TLS) is available through port 8883.
default: '1883'
enum:
- '1883'
- '8883'
*/
For using the optimizer to optimize file you just need to import the Optimizer
class. Use its two methods to get the report (getReport()
) and get the optimized document (getOptimizedDocument()
).
See API documentation for more example and full API reference information.
FAQs
This library will optimize the AsyncAPI specification file.
The npm package @asyncapi/optimizer receives a total of 16,721 weekly downloads. As such, @asyncapi/optimizer popularity was classified as popular.
We found that @asyncapi/optimizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.