Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@metronlabs/rx-form-data
Advanced tools
Minimal, Reactive Form data handling
npm install --save @metronlabs/rx-form-data
// using ES6 modules
import RxFormData from "@metronlabs/rx-form-data";
// using CommonJS modules
const RxFormData = require("@metronlabs/rx-form-data");
The UMD build is also available on unpkg:
<script src="https://unpkg.com/@metronlabs/rx-form-data/lib/index.umd.js"></script>
You can find the library on window.RxFormData
.
import RxFormData from "@metronlabs/rx-form-data";
const { subscribe, register, dispatch, ACTION_TYPE } = RxFormData(
"some-form-id",
// form submission handler. This is required.
(formvalues, formvalidation, formdata) => {
// do some custom logic before XHR/AJAX calls... formdata is an HTML5 FormData object of the `some-form-id` form element
console.log(
"ON SUBMIT HANDLER CALLED",
formvalues,
formvalidation,
formdata
);
return Promise.resolve([formvalues]);
}
);
//Registers all the input fields on the `some-form-id` form element
dispatch(ACTION_TYPE.REGISTER_ALL);
//Alternatively, you can choose which fields to register
//That can be done this way ...
dispatch(ATION_TYPE.REGISTER, ["some-field-x", "some-field-y"]);
// OR, this way
const unregister = register(["some-field-x", "some-field-y"]);
// ^ advantage of the latter is that you get the 'unregister' function;
//For validation, add some decoders.
//A decoder has a name/label, a bunch of predicates with formvalues as input, and (static or computed) error messages
dispatch(ACTION_TYPE.ADD_DECODERS, [
{
name: "validation-for-some-field-x",
use: [
(formvalues) => {
//...some logic
return true; // if returned value is not 'true' <=> validation failed!
}
],
messages: ["Input is invalid"] // this can also be a function (context) => string | string[]
}
]);
const unsubscribe = subscribe((formvalues, formvalidation) => {
//formvalues includes data for all the currently registered fields
//formvalidation is derived from formvalues and the registered decoders...
console.info("FORM DATA SUBSCRIBER", formvalues, formvalidation);
});
// You can have more than one subscriber (...just dont go crazy with it; all things in moderation and all)
const unsubscribe2 = subscribe((formvalues, formvalidation) => {
console.info("FORM DATA SUBSCRIBER II", formvalues, formvalidation);
});
// some time later... when y'er done
setTimeout(() => {
unsubscribe();
unsubscribe2();
}, 2 * 60 * 1000);
setTimeout(() => {
// clean up: unmounts all form element listners, dettaches all subscribers, clears registered fields & decoders...
dispatch(ACTION_TYPE.DESTROY);
}, 3 * 60 * 1000);
Scan the type declarations (@types
folder) for some insights on implementation details:
RxFormData
Main package function. Use this to create an RxFormData instance.const { subscribe, register, dispatch, ACTION_TYPE } = RxFormData(
"...",
// Form submission handler...
// Keep in mind, you are fully responsible for how to handle this event.
// All this library does is give you enough information to know what to do
// The formdata parameter is the FormData object of the form element at the moment a submission is triggered
(formvalues, formvalidation, formdata) => {...}
);
subscribe
Sets up subscriptions to form values and form validation updates. Takes a function as an argument. const unsubscribe = subscribe((formvalues, formvalidation) => {...});
//when subscription is no longer needed...
unsubscribe()
register
Registers form field elements. Accepts a list of field names or regex expressions that are meant to match one or multiple field names.const unregister = register(["username", "email", /^password.*/]);
//when you no longer care about the fields...
unregister();
//Or to keep these fields in the form values
unregister(true);
dispatch
& ACTION_TYPE
Utilities to interface with the RxFormData instance//List of available actions
{
REGISTER: "REGISTER_FIELDS",
REGISTER_ALL: "REGISTER_ALL_FIELDS",
UNREGISTER: "UNREGISTER_FIELDS",
UNREGISTER_ALL: "UNREGISTER_ALL_FIELDS",
ADD_DECODERS: "ADD_DECODERS",
REMOVE_DECODERS: "REMOVE_DECODERS",
CLEAR_DECODERS: "CLEAR_DECODERS",
DESTROY: "DESTROY_PROGRAM"
};
dispatch(ACTION_TYPE.REGISTER, payload: Array<string | RegExp>);
dispatch(ACTION_TYPE.REGISTER_ALL); // registers all fields currently on the form elment
dispatch(ACTION_TYPE.UNREGISTER, payload: Array<string | RegExp>); // keepvalues is set to false by default
dispatch(ACTION_TYPE.UNREGISTER, payload: { use: payload: Array<string | RegExp>, keepvalues: boolean });
dispatch(ACTION_TYPE.UNREGISTER_ALL, keepvalues?: boolean);
dispatch(ACTION_TYPE.ADD_DECODERS, payload: Array<{
/** this is used as key on the formvalidaiton object */
name: string;
/** predicate functions (i.e validators) */
use: Array<(formvalues: Readonly<Record<string, ...>>) => boolean>;
/** error messages for validation failure(s) */
messages: string[] | (context: Record<string, unknown>) => string | string[];
}>);
dispatch(ACTION_TYPE.REMOVE_DECODERS, payload: Array<string | RegExp>);
dispatch(ACTION_TYPE.CLEAR_DECODERS); // clears all registered decoders
dispatch(ACTION_TYPE.DESTROY); // basically renders RxFormData inert
First off, thanks for taking the time to contribute! Now, take a moment to be sure your contributions make sense to everyone else.
Found a problem? Want a new feature? First of all see if your issue or idea has already been reported. If not, just open a new clear and descriptive issue.
Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.
git clone https://github.com/<your-username>/@metronlabs/rx-form-data
cd @metronlabs/rx-form-data
git checkout -b features/my-new-feature
npm install
git commit -am 'Add some feature'
git push origin features/my-new-feature
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice aTd this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Framework agnostic reactive form data streaming
We found that @metronlabs/rx-form-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.