chenlijun99 / autoanki

Set of tools and libraries that streamline the learning experience with Anki.
MIT License
38 stars 8 forks source link

feat(anki-connect): add api key argument to invoke function #12

Closed Pedro-Bronsveld closed 1 year ago

Pedro-Bronsveld commented 1 year ago

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.

Example partial config.json:

{
    "apiKey": {
        "prop1": {
            "nested": 1234,
            "nested_list": [1,2,3,4]
        }
    }
}

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:

{
    "key": {
        "prop1": {
            "nested": 1234,
            "nested_list": [1,2,3,4]
        }
    },
    "action": "...",
    "version": 6
}

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.

chenlijun99 commented 1 year ago

Hi. Thanks for the PR. The new version of @autoanki/anki-connect (0.1.4) has been published.