Build on ouicu
SDK
Share a port and put sites up from Node: in scripts, CI and test runs.
Install
npm install @ouicu/sdkNode 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:
- the
apiKeyoption, OUICU_API_KEY,- the key
ouicu loginsaved.
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.appIt 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:
| Status | Meaning |
|---|---|
| 401 | A key that doesn't work, or none. |
| 403 | Not on your plan, or a suspended account. |
| 404 | No such share or site. |
| 409 | A name that is taken. |
| 413 | Too large. |
| 429 | Too many requests, or the month's data is used up. |
| 0 | ouicu 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
| Option | Environment | Default |
|---|---|---|
apiKey | OUICU_API_KEY | the key ouicu login saved |
bin | OUICU_BIN | ouicu on your PATH |