Skip to the page

Build on ouicu

SDK

Share a port and put sites up from Node: in scripts, CI and test runs.

Install

npm install @ouicu/sdk

Node 20 or later. It has no other dependencies.

Logging in

The SDK uses the same key as the command line tool. In order, it takes:

  1. the apiKey option,
  2. OUICU_API_KEY,
  3. the key ouicu login saved.

For CI, make a key under Account, API keys, and set it as OUICU_API_KEY. To log in from a script the way ouicu login does:

import { Ouicu } from "@ouicu/sdk"; const ouicu = new Ouicu();await ouicu.login({  onCode: ({ userCode, verificationUrl }) =>    console.log(`Approve ${userCode} at ${verificationUrl}`),});

The key is saved where the command line tool keeps it, so the tool is logged in too.

Put a built site up

const site = await ouicu.deploy("./dist", {  name: "studio", // one of your sites to replace, or a reserved name  spa: true, // unknown paths get index.html  onProgress: ({ sent, total }) => console.log(`${sent} of ${total}`),});console.log(site.url); // https://studio.ouicu.app

It works as ouicu deploy does: only files ouicu doesn't have yet are uploaded, and files that aren't part of a web page are left out. site.skipped says which and why, and site.expiresAt says when a Free site goes.

Share a port

const live = await ouicu.share(3000, {  onRequest: ({ method, path, status }) => console.log(method, path, status),});console.log(live.url); // https://quiet-otter-1234.ouicu.app // laterawait live.stop();

This runs the command line tool (ouicu share 3000 --json), which has to be installed, version 0.1.7 or later. share() resolves once the link works, and rejects with ouicu's words if it is refused, say a name that is taken. live.closed settles when the share ends, however it ends, with the reason. Shares still running when your process exits are stopped.

Pass name for a reserved name, and password for a password: it reaches the command line tool through its environment, never its arguments.

Shares, sites and the month's data

await ouicu.whoami(); // { email, name, plan, key }await ouicu.usage(); // { plan, month, bytes, requests, allowanceBytes, resetsAt, over } await ouicu.shares.list(); // live ones first, then the latest endedawait ouicu.shares.stop(id);await ouicu.shares.requests(id); // { available, visitors, requests } await ouicu.sites.list();await ouicu.sites.delete(id);await ouicu.sites.requests(id);

These are the API's answers, as they come.

Errors

Everything ouicu refuses throws an OuicuError with ouicu's own words and the HTTP status:

Error statuses
StatusMeaning
401A key that doesn't work, or none.
403Not on your plan, or a suspended account.
404No such share or site.
409A name that is taken.
413Too large.
429Too many requests, or the month's data is used up.
0ouicu never answered, a folder couldn't be read, or the command line tool failed.
import { OuicuError } from "@ouicu/sdk"; try {  await ouicu.deploy("./dist");} catch (err) {  if (err instanceof OuicuError && err.status === 429) console.log(err.message);  else throw err;}

Settings

SDK settings
OptionEnvironmentDefault
apiKeyOUICU_API_KEYthe key ouicu login saved
binOUICU_BINouicu on your PATH