1.0.78 • Published 5 months ago

konnect-app-plugin v1.0.78

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

konnect-app-plugin

App Konnect API documentation for third party apps.

Installation

npm i konnect-app-plugin

or

yarn add konnect-app-plugin

Usage

Importing the Module

const { init } = require('konnect-app-plugin');

Initialize the API Configuration

Call the init function to set the base URL for the API:

async init(){
    const url = 'sample url'
    try{
      const result = await init(url);
      console.log('Success')
    }catch (error){
      console.error('Login failed:', error);
      this.errorToast(JSON.stringify(error));
    }
  } 

Available Functions

getToken(endpoint, body)

Fetches an access token and updates the Authorization header.

  • Parameters:
    • endpoint (string): The endpoint for the token request.
    • body (object): The request payload.
  • Returns: A Promise resolving to the API response.

updateCallBack(endpoint, body)

Sends a PUT request to update data.

  • Parameters:
    • endpoint (string): The API endpoint.
    • body (object): The request payload.
  • Returns: A Promise resolving to the API response.

getCallback(endpoint)

Sends a GET request to fetch data.

  • Parameters:
    • endpoint (string): The API endpoint.
  • Returns: A Promise resolving to the API response.

registerCallback(endpoint, body)

Sends a POST request to register data.

  • Parameters:
    • endpoint (string): The API endpoint.
    • body (object): The request payload.
  • Returns: A Promise resolving to the API response.

getBalance(endpoint)

Fetches the balance using a GET request.

  • Parameters:
    • endpoint (string): The API endpoint.
  • Returns: A Promise resolving to the API response.

uploadDocument(endpoint, body)

Uploads a document using a POST request.

  • Parameters:
    • endpoint (string): The API endpoint.
    • body (object): The request payload.
  • Returns: A Promise resolving to the API response.

createCWA(endpoint, body)

Creates a CWA (Custom Web Application) using a POST request.

  • Parameters:
    • endpoint (string): The API endpoint.
    • body (object): The request payload.
  • Returns: A Promise resolving to the API response.

updateCWA(endpoint, body)

Updates a CWA using a PUT request.

  • Parameters:
    • endpoint (string): The API endpoint.
    • body (object): The request payload.
  • Returns: A Promise resolving to the API response.

getDocumentType(endpoint)

Fetches document types using a GET request.

  • Parameters:
    • endpoint (string): The API endpoint.
  • Returns: A Promise resolving to the API response.

Example Usage

declare var require: any;
const {
  getToken,
  registerCallback,
  init
} = require('konnect-app-plugin');


 async init(){
    const url = 'sample url'
    try{
      const result = await init(url);
      console.log('Success')
    }catch (error){
      console.error('Login failed:', error);
      this.errorToast(JSON.stringify(error));
    }
  } 

 async getToken() {
    const endpoint = 'sample endpoint'
    const body = {
      USERNAME: 'sample username',
      PASSWORD: 'sample password',
    };
    try {
      const result = await getToken(endpoint,body);     
      console.log('result',result);
    } catch (error) {
      console.error('Login failed:', error);
    }
  }



async registerCallback() {
    const endpoint='sample endpoint'
    const body = {
      body: 'sample body',
    };
    try {
      const result = await registerCallback(endpoint,body);
      console.log('registerCallback', result);

    } catch (error) {
      console.error('registerCallback failed:', error);
    }
  }

Error Handling

All functions handle errors by logging them to the console and rejecting the Promise with an error message. The error message includes the response data if available, or the error message otherwise.

License

This project is licensed under the MIT License. See the ISC file for details.

1.0.73

8 months ago

1.0.72

8 months ago

1.0.71

8 months ago

1.0.77

5 months ago

1.0.76

5 months ago

1.0.75

5 months ago

1.0.74

6 months ago

1.0.78

5 months ago

1.0.69

8 months ago

1.0.68

8 months ago

1.0.67

8 months ago

1.0.70

8 months ago

1.0.66

9 months ago

1.0.65

9 months ago

1.0.64

9 months ago

1.0.63

9 months ago

1.0.62

9 months ago

1.0.61

9 months ago

1.0.60

9 months ago

1.0.59

9 months ago

1.0.58

9 months ago

1.0.57

9 months ago

1.0.56

9 months ago

1.0.55

9 months ago

1.0.54

9 months ago

1.0.53

9 months ago

1.0.52

9 months ago

1.0.51

9 months ago

1.0.50

9 months ago

1.0.49

9 months ago

1.0.48

9 months ago

1.0.47

9 months ago

1.0.46

9 months ago

1.0.45

9 months ago

1.0.44

9 months ago

1.0.43

9 months ago

1.0.42

9 months ago

1.0.41

9 months ago

1.0.40

9 months ago

1.0.39

9 months ago

1.0.38

9 months ago

1.0.37

9 months ago

1.0.36

9 months ago

1.0.35

9 months ago