-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NodeJS API #287
Comments
Some options on the API: If we have the functions in the format We can expose the operation's properties there, or we can just make that the alias for the So if we expose the properties, we will have chef.base32.from.inputType // => 'string'
chef.base32.from.outputType // => 'byteArray'
chef.base32.from.args // => [...]
etc Which could make the API more self-documenting, for people using it in a REPL interface. BUT it does mean that to run the operation you need chef.base32.from.run(...) Or we just expose the chef.base32.from(...) With both options, we can still be as lenient as possible with input types by wrapping the operation's run function in some type conversion. I think just exposing If we just expose the Also, the @n1474335 thoughts? |
Translating typesI hadn't considered that this would make everything async. In ES7, I don't think it matters a huge amount as I don't really have any solutions to that at the moment. The APINow that I see the API laid out, I'm wondering if we should just go back to the idea of exposing each op separately, rather than trying to bunch them together into related namespaces. This looks quite simple and intuitive to me: chef.fromBase64(...)
chef.toHex(...)
chef.entropy(...)
chef.convertArea(...)
chef.gzip(...) We could export the chef object, but also all the separate operations on their own. That way people can still get the benefits of ES6 tree-shaking if they want it. Exposing the configuration details would be useful, especially the descriptions and arguments. Perhaps we could have a separate lookup function that returns the metadata. We could even have a search function that works in a similar way to the search bar in the web app: chef.info("To Base64")
// => { name: "To Base64", description: "...", inputType: "byteArray", ... }
chef.search("xor")
// => [{ name: "XOR", desc...}, { name: "XOR Brute Force", desc...}, ...] One of the returned properties could even be a reference to the const userStr = getInput("Please enter your search: ");
chef.search(userStr)[0].run(...); |
Are we intending to use Promises for this? |
I think we'll have to if it's async. I'd rather not as they can be confusing to people with limited JavaScript experience, but if one of the possible data types is |
In ES7, it's as simple as this though: await chef.toBase64(...) Granted, you then have to declare your scope as |
@n1474335 I agree with you on the per-operation API. I don't think there's much benefit in grouping operations ( I like the @artemisbot |
We can also support a callback API, adding flexibility. See example (taken from a Google example): /**
* Create and send request to Google API
* @param parameters Parameters used to form request
* @param callback Callback when request finished or error found
*/
export function createAPIRequest(parameters, callback) {
if (callback) {
createAPIRequestAsync(parameters)
.then(r => callback(null, r))
.catch(e => callback(e));
} else {
return createAPIRequestAsync(parameters);
}
} |
Some additional details on library API behaviour: Error handlingExpected errors from operations are currently returned as a string to be outputted in the web UI. Only Unexpected errors are caught by In the web logic, we can throw errors from operations then catch our new Output objects - translating typesWe will expose a translate function on the result = chef.toBase32('input')
file = chef.translate(result, chef.types.LIST_FILE) This is like the type conversion @n1474335 has now added to |
@d98762625 This can probably be closed now, can't it? Just trying to clean some things up. |
Yep, I'll close it. |
Move NodeJS API into it's own issue. First mentioned in PR #284
We should aim to be able to export specific modules from the CyberChef package so that the 200+ operations can be used effectively in other projects.
An example (exact API still open to suggestions):
Also working with commonJS
require
.The text was updated successfully, but these errors were encountered: