Skip to content

Commit

Permalink
Update readme with dynamic compatibility check example
Browse files Browse the repository at this point in the history
  • Loading branch information
asimons04 committed Mar 14, 2024
1 parent 5829f20 commit b082ed6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ else console.log("Login was unsuccessful");
```
### Compatibility Mode for 0.18.x
If you need to target 0.18.x with this library, you will need to supply `compatible18: true` in the client constructor options.
If you need to target 0.18.x with this library, you will need to supply `compatible18: true` in the client constructor options or call `client.compatible18=true` after initialization.
All this does is extract the JWT from the client's internal headers and add it to the `form` object when making API requests. It will not prevent API calls to unsupported endpoints.
Additionally, it does not backport any type definition differences, so you may have to ignore or fix those in client code. The compatibility mode is simply to allow
Expand All @@ -62,8 +62,15 @@ import {

let site: GetSiteResponse | undefined = undefined

// Create 0.18.x compatible client explicitly
const client = new SublinksClient('sublinks.example.com', {compatible18: true});

// Alternatively, dynamically detect if it needs to use compatibility mode
const client = new SublinksClient('sublinks.example.com');
const site = await client.getSite({useCache: false}); // Don't cache the test lookup
if (site?.version.startsWith('0.18.')) client.compatible18 = true


try {
let { jwt } = await client.login({
username_or_email: 'TestUser',
Expand Down

0 comments on commit b082ed6

Please sign in to comment.