Added an optional api key argument to the invoke function of the anki-connect package.
This can be used when the "apiKey" property is set in the Anki-Connect config file.
Removed JSON.Stringify from invoke function when posting, as axios.post serializes the payload object to json internally [1][2].
Some explanation for the type of the API key, which may seem strange:
export type ApiKey =
| string
| number
| boolean
| null
| { [key: string]: ApiKey }
| ApiKey[];
Apparently, the Anki-Connect addon allows any value that is a valid json value to be used as an api key.
So for example, even a nested object can be used as an api key in the Anki-Connect configuration.
As long as the "key" property in the body of the request matches the structure and values of the "apiKey" property in the config, the request will be authorized.
I do think it's a little strange that the api key can be anything other than a string, but since Anki-Connect does allow it to be other types I think the behavior should be reflected by the type of the api key.
Added an optional api key argument to the
invoke
function of the anki-connect package. This can be used when the"apiKey"
property is set in the Anki-Connect config file.Removed
JSON.Stringify
frominvoke
function when posting, asaxios.post
serializes the payload object to json internally [1] [2].Some explanation for the type of the API key, which may seem strange:
Apparently, the Anki-Connect addon allows any value that is a valid json value to be used as an api key. So for example, even a nested object can be used as an api key in the Anki-Connect configuration.
Example partial config.json:
As long as the
"key"
property in the body of the request matches the structure and values of the"apiKey"
property in the config, the request will be authorized.Example request body:
I do think it's a little strange that the api key can be anything other than a string, but since Anki-Connect does allow it to be other types I think the behavior should be reflected by the type of the api key.