Updater documentation

Shareable now offers a built-in way to keep your scripts up to date, and to notify your users when you publish a new update for your script.

How does it work

The updater is disabled by default for all scripts, but an author can enable it at any time in a script's page. Enabling the updater for a script means that an API endpoint will be available for your script: from this url anyone can retrieve the latest version of your script, alongside with release notes and a download link for a quick and easy update.

How to use the updater for my script

Using the updater is simple:

// Your script

    const updaterModule = importModule("semver") // @FifiTheBulldog's updater module: check below for download

    const version = "1.1" // The current installed version
    const id = 1 // Your script's shareable id
    let request = await new Request("https://shareable.vercel.app/api/updater?id=" + id)
    let json = await request.loadJSON()

    const checkForUpdates = updaterModule(version, json.version)
    
    if(checkForUpdates == true){
        log("Update available!")
        Safari.open(json.download_link)  
    }else if(checkForUpdates == null){
        log("Up to date!")
    }else if(checkForUpdates == false){
        log("Rollback available!")
    }

Updater module

This module, that needs to be installed as a Scriptable script, makes possible to use semantic versioning (like 2.0.3): you can download it on GitHub at this link

All credits to FifiTheBulldog for this script.

The API is public, so anyone can write their own approach

Shareable's updater api is public, so you can write your own updater module: here's some informations that may be useful.

    
        // URL
        const baseUrl = "https://shareable.vercel.app/api/updater" // takes id as a parameter
        const url = "https://shareable.vercel.app/api/updater?id=1"
    
    
        // Response is a JSON object
        isUpdaterEnabled: Boolean
        version: String
        release_notes: String
        download_link: String // url that redirects to script's page after starting the download of the script 
    

If the updater is not enabled for a script, the API will return an error string.

Contributing

If you found an error in the docs or have an idea for something new, open an issue on GitHub.




Shareable 2022 ©
Join the Scriptable community on Discord