Instructions for AI assistants

# Happs: instructions for AI assistants

Happs hosts static websites: HTML, CSS, JavaScript, images, fonts and other
files that a browser downloads. Nothing runs on the server, so PHP, Python,
Node.js and other server-side code will not work.

With an access token you can publish and manage the sites of the person who
gave it to you, using the HTTP API described here.


## 1. The access token

- The person creates the token at https://happs.vip/tokens and gives it to
  you. It starts with "happs_".
- Send it in every request, in this header:
      Authorization: Bearer happs_...
- Treat it like a password. Never show it in full in your output, and never
  put it in files, commits, logs or websites. The examples below read it from
  the environment variable HAPPS_TOKEN:
      export HAPPS_TOKEN='happs_...'          (bash)
      $env:HAPPS_TOKEN = 'happs_...'          (PowerShell)


## 2. Rules

- A site is a set of static files with index.html at its top level.
- One upload: at most 200 MB and 10000 files, also after unpacking a zip.
- The person's plan limits how many sites and how much storage they can
  have: on the Free plan 2 sites and 200.0 MB, on the VIP plan
  10 sites and 2.0 GB. GET /api/v1/account shows the person's own
  plan, limits and usage (section 4). The plans are described at
  https://happs.vip/pricing; the person chooses theirs on the dashboard.
- At most one NEW site per minute, because the site's address contains the
  minute it was created. Replacing an existing site has no such limit.
- Some features can be part of the VIP plan only: password lock, a custom
  happi.lol address, switching a site off, custom domains and creating access
  tokens. "features" in
  GET /api/v1/account says which ones the person may use. When a feature
  becomes VIP only, what they already set up keeps working (except custom
  domains), and undoing it (unlocking, switching a site back on) is always
  allowed.
- Traffic (the data sent to visitors of the person's sites) is counted per
  calendar month (UTC) and shared by all of their sites: on the Free plan
  2.0 GB a month, on the VIP plan 10.0 GB.
  When it is used up, all of the person's sites are paused until the 1st
  of the next month: visitors see a "traffic allowance used up" page
  (status 503) instead of the sites. "pausedForTraffic" in the answers below
  says so. Uploading and changing sites still works while they are paused.
  The person can buy extra traffic for the current month on their dashboard
  (https://happs.vip/dashboard) when "features.trafficPacks" is true; it
  brings the sites back straight away. You cannot buy it for them.
- A new site gets an address like https://2611221435-abcd.happi.lol
  (time in UTC, then the person's 4-letter usercode). Replacing a site keeps
  its address.
- The person can give a site a more meaningful address, such as
  https://games-abcd.happi.lol (see "Change a site's address" below).
  A site always keeps its "name" (2611221435-abcd), which you use in
  API paths; its "address" and "url" are what visitors use.
- When you update a project you published before, replace that site instead
  of creating a new one, so the address stays the same.


## 3. Prepare the upload: a zip file

Put the site's files in a zip file, with index.html at the top of the zip, or
inside a single top-level folder (that folder level is removed).

    cd my-site && zip -r ../my-site.zip . && cd ..                  (bash)
    Compress-Archive -Path my-site\* -DestinationPath my-site.zip   (PowerShell)

- If the project has a build step (for example "npm run build"), zip the
  build output folder (often dist/ or build/), not the source.
- Leave out anything that is not part of the website: .env files, keys and
  other secrets, .git, node_modules, server code.
- File names are case-sensitive on the server: link to "Logo.png" only if the
  file is called exactly that.


## 4. The API

Base address: https://happs.vip/api/v1
Answers are JSON. Errors are {"error": "<message for the person>"} with an
HTTP status code (see section 5).


### The person's plan, limits and usage

    curl -s -H "Authorization: Bearer $HAPPS_TOKEN" https://happs.vip/api/v1/account

200: {"usercode", "plan" ("free", or "paid" for the VIP plan), "planProvidedByHapps",
"subscriptionStatus", "customDomainsIncluded", "pausedForTraffic",
"canUseAddressWithoutUsercode", "features": {"passwordLock", "customAddress",
"disableSite", "customDomains", "accessTokens", "trafficPacks"} (true when the
person may use it),
"limits": {"maximumSites", "maximumStorageBytes", "monthlyTrafficBytes"},
"usage": {"siteCount", "storageBytes", "trafficBytesThisMonth",
"trafficPacksBytesThisMonth"},
"uploadLimits": {"maximumUploadBytes", "maximumFilesPerUpload",
"minutesBetweenNewSites"}}
A limit of null means there is no limit. "trafficBytesThisMonth" counts all
of the person's sites this calendar month, including sites deleted since.
"monthlyTrafficBytes" is this month's allowance, including the extra
traffic the person bought for this month ("trafficPacksBytesThisMonth").
Check this before a large upload or before adding a custom domain. If the
person needs more, send them to https://happs.vip/pricing; you cannot
change the plan.


### List sites

    curl -s -H "Authorization: Bearer $HAPPS_TOKEN" https://happs.vip/api/v1/sites

200: {"sites": [{"name", "address", "url", "originalName", "sizeBytes",
"fileCount", "createdAt", "updatedAt", "enabled", "locked", "password"
(locked sites only), "suspended", "trafficBytesThisMonth", "pausedForTraffic",
"domains": [...]}],
"usage": {"plan", "siteCount", "maximumSites", "storageBytes",
"maximumStorageBytes", "trafficBytesThisMonth", "monthlyTrafficBytes"}}
(null: no limit)


### Get one site

    curl -s -H "Authorization: Bearer $HAPPS_TOKEN" https://happs.vip/api/v1/sites/SITE_NAME

200: one site, as in the list.


### Create a new site from a zip file

    curl -s -H "Authorization: Bearer $HAPPS_TOKEN" -F "zip=@my-site.zip" https://happs.vip/api/v1/sites

201: {"siteName": "2611221435-abcd", "url": "https://2611221435-abcd.happi.lol"}
Tell the person the url.


### Replace a site (new files, same address)

    curl -s -X PUT -H "Authorization: Bearer $HAPPS_TOKEN" -F "zip=@my-site.zip" https://happs.vip/api/v1/sites/SITE_NAME

200: {"siteName", "url"}. Until the new files have been checked, the old
version stays online; if the upload is refused, nothing changes.


### Change a site's settings

    curl -s -X PATCH -H "Authorization: Bearer $HAPPS_TOKEN" -H "Content-Type: application/json" \
         -d '{"enabled": false}' https://happs.vip/api/v1/sites/SITE_NAME

Fields (send only those to change):
- "enabled": false closes the site (visitors see a "temporarily closed"
  page); true opens it again.
- "locked": true with "password": "..." (4 to 128 characters) locks the
  site; visitors must enter the password.
- "locked": false removes the password.
A locked site's password cannot be changed directly: send {"locked": false},
then {"locked": true, "password": "<new password>"}.
200: the site, as in the list.


### Change a site's address

    curl -s -X PATCH -H "Authorization: Bearer $HAPPS_TOKEN" -H "Content-Type: application/json" \
         -d '{"address": "games"}' https://happs.vip/api/v1/sites/SITE_NAME

This gives the site the address games-<usercode>.happi.lol, for example
https://games-abcd.happi.lol. "address" is the part before the usercode:
lowercase letters, digits and single hyphens, up to 40 characters, with at
least one letter. If "canUseAddressWithoutUsercode" in GET /api/v1/account is
true, you may also send {"address": "games", "withoutUsercode": true} for
https://games.happi.lol.
- The old address stops working at once, so ask the person first: links
  they shared will break. Custom domains keep working.
- Replacing the site keeps the new address; deleting the site frees it.
- 409 means another site already uses the address. It is never taken
  over: suggest a different address. 400 means the address breaks the rules
  above; 403 means "withoutUsercode" is not allowed for this person.
200: the site, as in the list, with its new "address" and "url".


### Delete a site

    curl -s -X DELETE -H "Authorization: Bearer $HAPPS_TOKEN" https://happs.vip/api/v1/sites/SITE_NAME

200: {"deleted": "SITE_NAME"}. This cannot be undone: only delete a site when
the person asked you to.


### Custom domains (the person's own domain, such as www.example.com)

Custom domains may be part of the VIP plan only. If "features.customDomains"
in GET /api/v1/account is false, adding or verifying a domain is refused with
403, and domains added earlier do not show the site.
("customDomainsIncluded" says the same.)

Add a domain:

    curl -s -X POST -H "Authorization: Bearer $HAPPS_TOKEN" -H "Content-Type: application/json" \
         -d '{"domain": "www.example.com"}' https://happs.vip/api/v1/sites/SITE_NAME/domains

201: {"domain", "url", "verified": false, "dnsRecords": [{"purpose", "type",
"name", "value"}, ...]}
The person must add these DNS records where their domain's DNS is managed.
Give them the records exactly; the site's Domains page on the dashboard has a
step-by-step guide.

Verify it, once the records are in place:

    curl -s -X POST -H "Authorization: Bearer $HAPPS_TOKEN" https://happs.vip/api/v1/sites/SITE_NAME/domains/www.example.com/verify

200: {"domain", "url", "verified": true, "pointsToServer": true or false}.
400 means the TXT record was not found yet: DNS changes take from a few
minutes to a few hours, so try again later. "pointsToServer": false means the
second record (CNAME or A) is still missing.

List: GET https://happs.vip/api/v1/sites/SITE_NAME/domains
Remove: DELETE https://happs.vip/api/v1/sites/SITE_NAME/domains/www.example.com


## 5. Errors

400  The request is wrong: bad JSON, not a zip file, an unsafe file path,
     an unusable password... Read "error", fix the request, try again.
401  The token is missing, wrong, expired or revoked. Ask the person for a
     new token; do not try the same one again.
403  The account is suspended, the site is suspended, the person has
     reached their plan's site limit, or the feature (for example password
     lock or custom domains) is part of the VIP plan only. Tell the person; when a bigger plan would help, the answer
     also has "pricingUrl", the page that describes the plans.
404  The site does not exist or belongs to someone else, the domain is not
     linked to the site, or the address is wrong.
409  The site is already locked (unlock it first), or the domain is already
     linked to another site.
413  Too large: the upload, the unpacked zip, or the person's total storage
     (then with "pricingUrl", as for 403).
429  Too many requests. For a new site: wait until the next minute (the
     Retry-After header gives the seconds), then try again. After many wrong
     tokens: wait as long as Retry-After says.
500  Something went wrong on the server. Try again a little later.


## 6. What you cannot do

- Create access tokens, or use the admin pages: only the person can, on the
  dashboard.
- Pay for anything: upgrading to the VIP plan and buying extra traffic
  happen only on the dashboard, done by the person.
- Run code on the server.


## 7. Good practice

- After an upload, fetch the site's url to check that it works, then tell
  the person its address.
- Never upload secrets or personal data the person did not ask you to publish.