
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@greenlabs/ppx-spice
Advanced tools
A ReScript PPX, which generates JSON (de)serializers.
Spice
is originated from
Spice melange
in the novel, DuneThis PPX is highly influenced by Decco and developed with forking the source codes of Decco. Spice has implemented all the features of Decco@1.5.0 and additional useful features for the (polymorphic) variant of its own.
To parse the JSON data, Decco is being heavily used in many projects. But, there's a restriction to parse the JSON string into a (polymorphic) variant with the Decco. The JSON data should be formed in an array. It is obvious at some point. But generally, we face the string data which needs to be parsed into the variant in most use cases.
Whenever it is needed to parse the response in Json, the custom encoder/decoder functions are needed to parse the Json string into the (polymorphic) variant with Decco. But you don't need to write it with the Spice as long as you add @spice.as
in (polymorphic) variants.
with Decco
@decco
type status = WAITING | PROCESSING | SUCCESS | FAIL
let encoderStatus = v =>
switch v {
| WAITING => "waiting"
| PROCESSING => "processing"
| SUCCESS => "success"
| FAIL => "fail"
}->Js.Json.string
let decoderStatus = json => {
switch json |> Js.Json.classify {
| Js.Json.JSONString(str) =>
switch str {
| "waiting" => WAITING->Ok
| "processing" => PROCESSING->Ok
| "success" => SUCCESS->Ok
| "fail" => FAIL->Ok
| _ => Error({Decco.path: "", message: "Expected JSONString", value: json})
}
| _ => Error({Decco.path: "", message: "Expected JSONString", value: json})
}
}
let codecStatus: Decco.codec<status> = (encoderStatus, decoderStatus)
@decco
type data = {
status: @decco.codec(codecStatus) status,
}
with Spice
@spice
type status =
| @spice.as("waiting") WAITING
| @spice.as("processing") PROCESSING
| @spice.as("success") SUCCESS
| @spice.as("fail") FAIL
@spice
type data = {
status: status,
}
There are many cases to parse and stringify the string data into (polymorphic) variants. Furthermore, the Unicode string needs to be handled with a variant. Currently, pattern matching is not working for the Unicode string in ReScript, the Spice is using if ... then ... else
to compare the Unicode string in case of adding @spice.as
attribute.
@spice
type t = | @spice.as(`하나`) One | @spice.as(`second`) Two
// automatically generated
let t_encode = ...
// automatically generated
let t_decode = ...
let encoded = One->t_encode // Js.Json.JSONString(`하나`)
let decoded = Js.Json.string(`second`)->t_decode // Belt.Result.Ok(Two)
@spice
type t = {
@spice.key("spice-label") label: string,
@spice.key("spice-value") value: int,
}
let sample = Js.Dict.empty()
sample->Js.Dict.set("spice-label", Js.Json.string("sample"))
sample->Js.Dict.set("spice-value", Js.Json.number(1.0))
let sampleJson = sample->Js.Json.object_
let sampleRecord: t = {
label: "sample",
value: 1,
}
let encoded = sampleRecord->Records.t_encode // sampleJson
let decoded = sampleJson->Records.t_decode // Belt.Result.Ok(sampleRecord)
yarn add -D @greenlabs/ppx-spice
// bsconfig.json
"bs-dependencies": [
"@greenlabs/ppx-spice"
],
"ppx-flags": [
...,
"@greenlabs/ppx-spice/ppx"
],
cd src
esy install
(make sure in /src directory)
esy build
cd test
(install dependencies)
yarn
(build --watch)
yarn res:clean && yarn res:watch
(run test --watch)
yarn test:watch
opam switch create spice 4.12.1
opam install dune ppxlib ocaml-lsp-server ocamlformat ocp-indent
dune build
cd test
(install dependencies)
yarn
(build --watch)
yarn res:clean && yarn res:watch
(run test --watch)
yarn test:watch
FAQs
ReScript PPX which generate JSON (de)serializer
The npm package @greenlabs/ppx-spice receives a total of 556 weekly downloads. As such, @greenlabs/ppx-spice popularity was classified as not popular.
We found that @greenlabs/ppx-spice demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.