1.1.0 • Published 1 month ago

prospector-js-sdk v1.1.0

Weekly downloads
26
License
MIT
Repository
-
Last release
1 month ago

Prospector JavaScript Client Library (Experimental)

Install

$ npm install --save prospector-js-sdk superagent

Usage

Importing

The prospector-js-sdk package is static; nothing needs to be constructed.

import * as sdk from 'prospector-js-sdk'

Base URL

All API functions allow you to specify the baseUrl of the request. However, to avoid having to pass that every time, you can call setBaseUrl to statically set the base URL for every API call.

sdk.setBaseUrl('http://localhost:3000/api/v1') // Use the applicable base url for your environment

You can always override this by explicitly passing baseUrl to the API function.

Token strategies

Automatic (recommended)

By default, prospector-js-sdk will first look for a token query parameter in the URL, then it will look for a token cookie. If neither are found, it will throw an error.

// Make a call with default automatic token management.
const { json: editor } = await sdk.getEditor({ editorId })

Provide your own token

Every API function also allows you to explicitly provide a token. This will override the automatic token management.

// Make a call with a token you manage.
const { json: editor } = await sdk.getEditor({ token: someToken, editorId })

Set your own automatic strategy

If the default token management strategy doesn't suit your application, you can provide your own. prospector-js-sdk will then use that to retrieve tokens for API calls.

sdk.setTokenStrategy = async () => {
  // Obtain a Prospector token by whatever means you need.
  return someToken
}

// Then you don't need to provide a token.
const { json: editor } = await sdk.getEditor({ editorId })

If you would like to use the default token management strategy but the details of your application differ, you can wrap the manageToken function and provide overrides.

sdk.setTokenStrategy = () => {
  return sdk.manageToken({
    baseUrl: 'some-other-base-url',
    paramName: 'jwt',
    tokenName: 'jwt',
    path: '/super/special/cookie/path'
  })
}

const { json: editor } = await sdk.getEditor({ editorId })

Deployment

An alpha release is automatically created when opening a PR into dev.

Releases are found on NPM.

1.1.0

1 month ago

1.0.4-alpha.37.0

1 month ago

1.0.4-alpha.38.0

1 month ago

1.0.4-alpha.36.0

2 months ago

1.0.4-alpha.35.0

2 months ago

1.0.4-alpha.31.0

2 months ago

1.0.4-alpha.30.0

2 months ago

1.0.4-alpha.32.0

2 months ago

1.0.4-alpha.34.0

2 months ago

1.0.4-alpha.27.0

2 months ago

1.0.4-alpha.29.0

2 months ago

1.0.4-alpha.28.0

2 months ago

1.0.4-alpha.25.0

2 months ago

1.0.4-alpha.26.0

2 months ago

1.0.4-alpha.21.0

2 months ago

1.0.4-alpha.23.0

2 months ago

1.0.4-alpha.24.0

2 months ago

1.0.4-alpha.20.0

2 months ago

1.0.4-alpha.22.0

2 months ago

1.0.4-alpha.18.0

2 months ago

1.0.4-alpha.17.0

2 months ago

1.0.4-alpha.13.0

2 months ago

1.0.4-alpha.16.0

2 months ago

1.0.4-alpha.15.0

2 months ago

1.0.4-alpha.12.0

2 months ago

1.0.4-next.8.0

5 months ago

1.0.4-next.9.0

5 months ago

1.0.4-alpha.10.0

5 months ago

1.0.4-alpha.11.0

5 months ago

1.0.4-next.0

5 months ago

1.0.2

1 year ago

1.0.1

1 year ago

0.3.17

1 year ago

0.3.16

1 year ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

1.0.3

12 months ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

3 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago