Skip to content

Module exposing means to communicate with Kite API using NodeJS or browsers APIs

License

Notifications You must be signed in to change notification settings

kiteco/kite-api-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kite API

Build Status codecov

.STATES

An object containing the constant values of the various states of kited

State Value Alias
UNSUPPORTED 0
UNINSTALLED 1
NOT_RUNNING 2 INSTALLED
NOT_REACHABLE 3 RUNNING
UNLOGGED 4 REACHABLE
NOT_WHITELISTED 5 AUTHENTICATED
WHITELISTED 6  

.editorConfig

The editorConfig object is provided as a way for an editor to store information across instances and session. It can be setup with different concrete stores that implements the various solutions to store the data.

By default it is setup with a MemoryStore that just stores everything in memory (it thus won't persist across session nor instances).

The available stores are:

  • MemoryStore: Used as a placeholder, it is also useful in tests.
  • FileStore: Stores everything on a file at the path specified during creation
  • LocalStore: When running in a browser environment this store allows you to use the localStorage as a way to store the config data. The store takes a key which will be used to access the data in the local storage object.

The object exposes two main functions, get and set that both returns a promise when invoked.

Storage is done using JSON format, and the path argument in both methods resolves to a real object in that JSON structure. However, stores implementation only have to deal with strings, the whole serialization/parsing is handled by the editor config object.

KiteAPI.editorConfig.set('path.to.some.data', 'data')
.then(() => KiteAPI.editorConfig.get('path.to.some.data'))
.then(data => {
  console.log(data)
  // output: data
  // store data: { path: { to: { some: 'data' }} }
})

.toggleRequestDebug()

This function is both a proxy to the KiteConnector method of the same name as well as calling the corresponding function on the Account object.

.onDidDetectWhitelistedPath(listener)

Registers a listener to the did-detect-whitelisted-path event and will be notified when a request for an editor API responds with a 200. The listener will be invoked with the path that have been detected as whitelisted.

The function returns a disposable object to unregister the listener from this event.

const disposable = KiteAPI.onDidDetectWhitelistedPath(path => {
  // path is whitelisted
})

disposable.dispose(); // the listener will no longer receive events

.onDidDetectNonWhitelistedPath(listener)

Registers a listener to the did-detect-non-whitelisted-path event and will be notified when a request for an editor API responds with a 403. The listener will be invoked with the path that have been detected as not whitelisted.

The function returns a disposable object to unregister the listener from this event.

const disposable = KiteAPI.onDidDetectNonWhitelistedPath(path => {
  // path is not whitelisted
})

disposable.dispose(); // the listener will no longer receive events

.requestJSON(options, data, timeout)

Makes a request to Kite using KiteConnector.request and automatically parses the JSON response when the status code was 200.

KiteAPI.requestJSON({path}).then(data => {
  // data is the result of JSON.parse on the response text
})

.isKiteLocal()

Makes a GET request to Kite at the endpoint /clientapi/iskitelocal. Responds with a boolean resolving Promise to true in the case of a 200 status code, false otherwise

KiteAPI.isKiteLocal().then(isLocal => {
  // do stuff related to kite-locality
})

.setKiteSetting(key, value)

Makes a POST request to Kite at the endpoint /clientapi/settings/${key}, where the body is set to value. It automatically parses the JSON response when the status code is 200

KiteAPI.setKiteSetting('some_setting_name', 'a_value')

.getKiteSetting(key)

Makes a GET request to Kite at the endpoint /clientapi/settings/${key}. It automatically parses the JSON response when the status code is 200

KiteAPI.getKiteSetting('some_setting').then(settingValue => {
  // do something with settingValue
})

.canAuthenticateUser()

Returns a promise that resolves if a user can be authenticated. A user can be authenticated if Kite is reachable and if the user is not already logged into Kite.

KiteAPI.canAuthenticateUser().then(() => {
  // user can be authenticated
})

.authenticateUser(email, password)

Makes a request to authenticate the user through Kite and returns a promise that will resolve if the authentication succeeds.

KiteAPI.authenticateUser('john@doe.com', 'password')
.then(() => {
  // User is logged in
})
.catch(err => {
  // authentication failed
})

.authenticateSessionID(key)

Makes a request to authenticate a user using a session id and returns a promise that will resolve if the authentication succeeds. This function can be used to authenticate a user in Kite whose account have been created using kite.com API.

KiteAPI.authenticateSessionID('session-id')
.then(() => {
  // User is logged in
})
.catch(err => {
  // authentication failed
})

.isPathWhitelisted(path)

Returns a promise that resolves if the path is part of the whitelist, otherwise the promise will be rejected.

When calling that function, depending on the outcome, a did-detect-whitelisted-path or did-detect-non-whitelisted-path event will be dispatched.

KiteAPI.isPathWhitelisted(path)
.then(() => {
  // path is whitelisted
})
.catch(err => {
  // path is not whitelisted or an error occurred
  // err contains the details of the failure
})

.canWhitelistPath(path)

Returns a promise that resolves if the path can be whitelisted. A path can be whitelisted if it's not already part of the whitelist and if the projectdir endpoint responds with a 200.

In case of success, the promise resolves with the path returned by the projectdir endpoint.

KiteAPI.canWhitelistPath(path).then(projectDir => {
  // projectDir can be sent to the whitelist endpoint
})

.whitelistPath(path)

Makes a request to the whitelist endpoint and returns a promise that resolves if the path have been successfully whitelisted.

KiteAPI.whitelistPath(path).then(() => {
  // path is now whitelisted
})

.blacklistPath(path, noAction)

Makes a request to the blacklist endpoint and returns a promise that resolves if the path have been successfully blacklisted. The noAction parameters will allow to set the closed_whitelist_notification_without_action value in the request, it defaults to false.

KiteAPI.blacklistPath(path).then(() => {
  // path is now blacklisted
})

.getSupportedLanguages()

Makes a request to the languages endpoint and returns a promise that resolves with an array of the supported languages.

KiteAPI.getSupportedLanguages().then(languages => {
  // do something with languages
})

.getOnboardingFilePath()

Makes a request to the onboarding_file endpoint and returns a promise that resolves with a filepath string.

KiteAPI.getOnboardingFilePath().then(path => {
  // do something with path
})

.getHoverDataAtPosition(filename, source, position, editor)

.getReportDataAtPosition(filename, source, position, editor)

.getSymbolReportDataForId(id)

.getValueReportDataForId(id)

.getMembersDataForId(id)

.getUsagesDataForValueId(id)

.getUsageDataForId(id)

.getExampleDataForId(id)

.getUserAccountInfo()

.isFileAuthorized(filename)

.shouldOfferWhitelist(filename)

.shouldNotify(filename)

.projectDirForFile(filename)

.getStatus(filename)

.getCompletions(payload)

.getSignaturesAtPosition(filename, source, position, editor)

.getAutocorrectData(filename, source, editorMeta)

.getAutocorrectModelInfo(version, editorMeta)

.getOsName()

.postSaveValidationData(filename, source, editorMeta)

.postAutocorrectFeedbackData(response, feedback, editorMeta)

.postAutocorrectHashMismatchData(response, requestStartTime, editorMeta)

.sendFeatureMetric(name)

.featureRequested(name, editor)

.featureFulfilled(name, editor)

.featureApplied(name, editor)

.Account

.initClient(hostname, port)
.disposeClient()
.toggleRequestDebug()
.checkEmail(data)
.createAccount(data, callback)
.login(data, callback)
.resetPassword(data, callback)

Delegated methods

.arch()

A proxy to the KiteConnector.arch method.

.canInstallKite()

A proxy to the KiteConnector.canInstallKite method.

.canRunKite()

A proxy to the KiteConnector.canRunKite method.

.canRunKiteEnterprise()

A proxy to the KiteConnector.canRunKiteEnterprise. method

.checkHealth()

A proxy to the KiteConnector.checkHealth method.

.downloadKite(url, options)

A proxy to the KiteConnector.downloadKite method.

.downloadKiteRelease(options)

A proxy to the KiteConnector.downloadKiteRelease. method

.hasBothKiteInstalled()

A proxy to the KiteConnector.hasBothKiteInstalled. method

.hasManyKiteEnterpriseInstallation()

A proxy to the KiteConnector.hasManyKiteEnterpriseInstallation method.

.hasManyKiteInstallation()

A proxy to the KiteConnector.hasManyKiteInstallation method.

.installKite(options)

A proxy to the KiteConnector.installKite method.

.isAdmin()

A proxy to the KiteConnector.isAdmin method.

.isKiteEnterpriseInstalled()

A proxy to the KiteConnector.isKiteEnterpriseInstalled method.

.isKiteEnterpriseRunning()

A proxy to the KiteConnector.isKiteEnterpriseRunning method.

.isKiteInstalled()

A proxy to the KiteConnector.isKiteInstalled method.

.isKiteReachable()

A proxy to the KiteConnector.isKiteReachable method.

.isKiteRunning()

A proxy to the KiteConnector.isKiteRunning method.

.isKiteSupported()

A proxy to the KiteConnector.isKiteSupported method.

.isOSSupported()

A proxy to the KiteConnector.isOSSupported method.

.isOSVersionSupported()

A proxy to the KiteConnector.isOSVersionSupported. method

.isUserAuthenticated()

A proxy to the KiteConnector.isUserAuthenticated. method

.onDidFailRequest(listener)

A proxy to the KiteConnector.onDidFailRequest method.

.request(options, data, timeout)

A proxy to the KiteConnector.request method.

.runKiteWithCopilot()

A proxy to the KiteConnector.runKiteWithCopilot method.

.runKite()

A proxy to the KiteConnector.runKite method.

.runKiteAndWait()

A proxy to the KiteConnector.runKiteAndWait method.

.runKiteEnterprise()

A proxy to the KiteConnector.runKiteEnterprise method.

.runKiteEnterpriseAndWait()

A proxy to the KiteConnector.runKiteEnterpriseAndWait method.

.toggleRequestDebug()

A proxy to the KiteConnector.toggleRequestDebug method.

.waitForKite(attempts, interval)

A proxy to the KiteConnector.waitForKite method.

About

Module exposing means to communicate with Kite API using NodeJS or browsers APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published