LogoLogo
Developer HubGitHubContact Us
  • Welcome!
  • Olive Helps
    • Platform
      • How Olive Helps Works
      • Installation
      • Account Creation
      • Distributing Olive Helps
    • FAQs
      • General Loop FAQs
      • Loop Development FAQs
      • Olive Helps User FAQs
      • Security / IT FAQs
    • Data Security
      • User Data
      • Antivirus and Firewalls
  • Loop Development Kit
    • Your First Loop
      • Become a Loop Author
      • Creating a Loop
      • Build Your Loop
      • Local Loop Installation
      • Restarting Local Loops
    • Troubleshooting
    • Loop Security
      • Permissions
      • Environment Permissions
    • Loop Publication
      • Loop Approval Checklist
    • Loop Analytics Library
    • Examples
  • Documentation
  • Interfaces
  • Type Alias
  • Enumerations
  • Whisper Components
    • Base Attributes
    • Autocomplete
    • Box
    • Breadcrumb
    • Button
    • Chart
    • CollapseBox
    • Grid
    • Checkbox
    • Date Time
    • Divider
    • DropZone
    • Email
    • Icon
    • List Pair
    • Link
    • Pagination
    • Number
    • Markdown
    • Message
    • Password
    • Progress
    • Radio
    • Rating
    • RichTextEditor
    • Section Title
    • Select
    • Text Input
    • Telephone
    • Typography
  • APTITUDES
    • What are Aptitudes?
    • Browser
    • Clipboard
    • Config
    • Cursor
      • Screen Scaling Behavior
    • Document
    • Filesystem
    • Keyboard
    • Network
    • Process
    • Screen
    • Search
      • Index
    • System
    • UI
      • Loop UI Handlers
    • User
      • JWT
    • Vault
    • Whisper
      • Whisper Updates
      • JSX Whispers
    • Window
      • Screen Scaling Behavior
  • Release Notes
    • What's New
      • Olive Helps v0.55.0
      • Olive Helps v0.54.1
      • Olive Helps v0.53.1
      • Olive Helps v0.51.2
      • LDK v4.0.0
      • Olive Helps v0.50.3
      • Olive Helps v0.49.5
      • LDK v 3.18.0
      • Olive Helps v0.47.2
      • Olive Helps v0.46.2
      • LDK v 3.17.0
      • Olive Helps v0.45.4
      • Olive Helps v0.44.2
      • Olive Helps v0.43.1
      • Olive Helps v0.42.1
      • Olive Helps v0.41.4
      • Olive Helps v0.40.2
      • Olive Helps v0.39.4 & LDK v3.16.0
      • Olive Helps v0.38.8 & LDK v3.15.0
      • Olive Helps v0.36.5
      • Olive Helps v0.36.4
    • Archive
      • Olive Helps v0.36.3 & LDK v3.14.0
      • Olive Helps v0.34.4
      • LDK v3.13.0
      • Olive Helps v0.32.2 & LDK v3.12.0
      • Olive Helps v0.31.2 & LDK v3.11.0
      • Olive Helps v0.30.2 & LDK v3.10.0
      • Olive Helps v0.29.4
      • Olive Helps v0.29.3 & LDK v3.9.0
      • Olive Helps v0.28.3 & LDK v3.8.0
      • Olive Helps v0.27.7
      • Olive Helps v0.27.5
      • Olive Helps v.027.4
      • Olive Helps v0.27.2 & LDK v3.7.0
      • Olive Helps v0.25.3 & LDK v3.5.1
      • Olive Helps v0.24.6 & LDK v3.4.0
      • Olive Helps v0.23.2 & LDK v3.3.0
      • Olive Helps v0.22.3 & LDK v3.2.0
Powered by GitBook
On this page

Was this helpful?

  1. APTITUDES

Network

The Network aptitude provides the ability make HTTP requests, set up a web socket connection, and encode and decode Uint8Arrays.

Requests/connections made using this method must be made to https resources.

Requests/connections made to http resources are only allowed for 127.0.0.1/localhost when running as a local loop.

decode

Converts the passed inUint8Array object into a string.

import { network } from '@oliveai/ldk';

// You won't often define a Uint8Array manually, rather you would
// get it back as the result from a network or filesystem call
const uintArray = new Uint8Array([70, 111, 111]);

network.decode(uint8Array).then((stringValue) => {
    // Would output to the console "Foo"
    console.log(stringValue);
}

encode

Converts the passed in string into a Uint8Array.

import { network } from '@oliveai/ldk';

const testString = 'Foo';

network.encode(testString).then((uintValue) => {
    // Would output to the console "[70, 111, 111]"
    console.log(uintValue.toString());
};

httpRequest

Generates a network request to an API. Returns the response from the API. The domain that the request is going to needs to be specified in the permissions block.

import { network } from '@oliveai/ldk';

// Must go to a https address or specific IP.
const url = 'https://some.api.com';

// Standard HTTP request methods
const method = 'GET';

// Optional parameter. Headers for the request are given as 
// a Record<string, string[]> object.
const headers = {
    'some-required-header': ['Foo', 'Bar'],
};

// Optional parameter. The encoded value of the body of the HTTP request
const body = new Uint8Array([70, 111, 111]);

// Optional parameter. The time in milliseconds to await a response from 
// the API before automatically failing the request
const timeoutMs = 5000;

network.httpRequest({
    url,
    method,
    headers,
    body,
    timeoutMs,
}).then((httpResponse) => {
    // The response from the server returns back a statusCode, body, 
    // and headers. 200 should mean the call was successful.
    if (httpResponse.statusCode === 200) {
        // The body is encoded as a Uint8Array and needs to be decoded
        // in order to interpret it
        network.decode(httpResponse.body).then((decodedValue) => {
            console.log(decodedValue);
        });
    }
});

webSocketConnect

Establishes a web socket connection to the specified server. Unless you have set up the API to be a web socket connection, httpRequest() would usually be what you want.

import { network } from '@oliveai/ldk';

// Must go to a secure address or specific IP.
const url = 'wss://some.api.com';

// Optional parameter. Headers for the request are given as 
// a Record<string, string[]> object.
const headers = {
    'some-required-header': ['Foo', 'Bar'],
};

// Optional parameter. Indicates whether the web socket server 
// uses compression or not
const useCompression = false;

// Optional parameter. Describes the subprotocols used by the server
const subprotocols = ['value1', 'value2'];

network.webSocketConnect({
    url,
    headers,
    useCompression,
    subprotocols,
}).then((socket) => {
    // The return from this promise is an object of the type Socket.
    // Sockets have several different functions that allow bidirectional
    // communication between it and the server. All functions are also
    // promises that can be chained.
    socket.setCloseHandler((error, code, text) => {
        // Configure how to handle close...
    });
    
    socket.setMessageHandler((error, message) => {
        // Configure how to handle different messages received...
    });
    
    socket.setPongHandler((error, msg) => {
        // Configure how to handle the message received after pinging 
        // the server...
    });
    
    socket.writeMessage(message).then(() => {
        // Write a message back to the server...
    });
    
    socket.ping(); // Ping the server, which should respond with a pongD
    
    socket.close(); // Close the socket connection
});

Developers will often have their own set of APIs that they will want to access with information that has been entered by a user of Olive Helps. Let's say that you are one such developer, and you have an API that returns information based on a date range that the user enters in through a Whisper.

import { network } from '@oliveai/ldk';

const callApi = (minDate, maxDate) => {
    network.httpRequest({
        url: `https://my.test.api/test-route?min=${minDate}&max=${maxDate}`,
        method: 'GET',
    }).then((httpResponse) => {
        // Check the response to see if it was successful
        if (httpResponse.status === 200) {
            // If successful, then we can use the data we received.
            network.decode(httpResponse.body).then((stringValue) => {
                const data = JSON.parse(stringValue);
                // Do what your loop needs to do with the data it received,
                // whether that be displaying it back to the user or doing
                // further calculations based on the information received.
            });
        } else {
            console.error('Something went wrong');
        }
    });
};

To use the Network Aptitude, use the following permissions outline in your package.json under the ldk object.

...
"ldk": {
  "permissions": {
    "network": {
      "urlDomains": [
        {
          "value": "string"
        },
        ...
      ]
    },
    ...
  }
},
...

Each value should only include the domain (no scheme or path), and the only supported wildcard is if it starts with *.. If you do not specify a domain your Loop attempts to access, Olive Helps will reject the request. This is done to ensure a user feels confident that a Loop isn't sending or getting information to something unexpected.

Updating the network permissions requires uninstalling/reinstalling the local loop for the permission changes to take effect. This will be fixed in a future release.

Examples

{
  "ldk": {
    "permissions": {
      "network": {
        "urlDomains": [
          {
            "value": "your.api.com"
          },
          {
             "value": "127.0.0.1"
          },
          {
             "value": "*.domain.com"
          }
        ]
      }
    }
  }
}
PreviousKeyboardNextProcess

Last updated 3 years ago

Was this helpful?

Please see our page for more information.

Permissions