npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tryretool/retool-embed

v1.3.0

Published

A JavaScript SDK for embedding Retool apps.

Downloads

12,754

Readme

Retool Embed SDK

Easily embed Retool apps into your existing web applications to extend their functionality.

If your Retool applications don't require authentication, you can generate a public link for your source URL. You can also authenticate users into embedded Retool apps by integrating Retool with your identity provider, or generating a secure embed URL through the Retool API.

Installation

Install the SDK via npm:

npm -i --save-dev @tryretool/retool-embed

Quickstart

Embedding a Retool app

To embed a Retool app, use the createRetoolEmbed function.


createRetoolEmbed({
    src: 'https://example.retool.com/embedded/public/5a34f0e4-1e19-45bd-9d0f-9612d42eed17',
});

Configuration options

| Argument | Type | Description | |-------------|---------------------|--------------------------| | src | string (required) | URL of the Retool app | | style | string (optional) | A valid style parameter | | data | Object (optional) | Object to pass from the parent app into Retool. Within your Retool app, use a Parent Window Query to reference keys in the data object. | | onData | function (optional) | Callback executed with data when the embedded Retool application calls parent.postMessage(data) from a JavaScript Query. |

Examples

Public link

const container = document.createElement('div')
app.appendChild(container)

const publicAppUrl = 'https://example.retool.com/embedded/public/5a34f0e4-1e19-45bd-9d0f-9612d42eed17'

embeddedRetool = createRetoolEmbed({
    src: publicAppUrl,
    style: "border: 1px solid blue; height: 100%; width: 100%;",
    data: {dataValue: false},
    onData: (data) => {
        mockFunction(data)
    }
});
container.appendChild(embeddedRetool)

Authenticated Embed URL

const container = document.createElement('div')
app.appendChild(container)

// Client calls your backend, which makes request to Retool for the embed URL.
const getEmbedUrl = async () => {...}

getEmbedUrl().then((retoolEmbedUrl) => {
    embeddedRetool = createRetoolEmbed({
        src: retoolEmbedUrl,
        style: "border: 1px solid blue; height: 100%; width: 100%;",
        data: {dataValue: false},
        onData: (data) => {
            mockFunction(data)
        }
    });
    container.appendChild(embeddedRetool)
});

Full example: Two-way communication between Retool and the embedding application

import { createRetoolEmbed } from "@tryretool/retool-embed";

let embeddedRetool

const advancedRetool = (value) => {
    embeddedRetool.data = {advancedUser: value}
}

let app = document.querySelector('#app')

// advanced user toggle 
const advancedCheckbox = document.createElement('input')
advancedCheckbox.type = 'checkbox'
advancedCheckbox.onclick = () => advancedRetool(advancedCheckbox.checked)
const advancedLabel = document.createElement('label')
advancedLabel.innerText = 'Advanced User'
app.appendChild(advancedCheckbox)
app.appendChild(advancedLabel)

const eventContainer = document.createElement('div')
eventContainer.className = 'eventContainer'
app.appendChild(eventContainer)

// iframe container
let container = document.createElement('div')
container.className = 'iframeContainer'
app.appendChild(container)

// handle event from retool
const handleRetoolClick = (data) => {
    eventContainer.classList.add('active')
    eventContainer.innerText = data
}

// set up retool
const getEmbedUrl = async () => {
    const res = await fetch('http://localhost:8000/generateEmbeddedRetoolURL', 
        {
            method: 'POST',
            headers: {"Content-Type": "application/json"},
            body: JSON.stringify({
                username: 'specialuser',
            }),
        }
    ) 
    return (await res.json()).embedUrl;
}

getEmbedUrl().then((retoolEmbedUrl) => {
    embeddedRetool = createRetoolEmbed({
        src: retoolEmbedUrl,
        style: "border: 1px solid blue; height: 98%; width: 100%;",
        data: {advancedUser: false},
        onData: (data) => {
            handleRetoolClick(data)
        }
    });
    container.appendChild(embeddedRetool)
});

Generating an embed URL

Ensure you generate the embed URL on a secure, authenticated backend server. Follow our documentation for detailed instructions.