Skip to Content
dropshelf

In-page JavaScript API

Every method and object of dropshelf.js, the module a drop's page loads to know its visitor, store data, accept uploaded assets and read company data.

This page lists everything dropshelf.js offers a drop's own page: its methods, arguments, answers and errors. For tasks and worked examples, read Build on the drop platform.

Loading the module

Every drop host serves the module at /_dropshelf/dropshelf.js on the drop's own address. It is a plain ES module with no dependencies. A page imports its default export from a module script:

<script type="module">
  import dropshelf from '/_dropshelf/dropshelf.js';

  const me = await dropshelf.me();
  document.querySelector('h1').textContent = `Hi ${me.name}`;
</script>

The module also exports DropshelfError by name:

import dropshelf, { DropshelfError } from '/_dropshelf/dropshelf.js';

The path /_dropshelf/ is reserved on every drop host, and no deploy can place files under it. Every request the module sends is same-origin and carries the visitor's own sign-in.

The dropshelf object

The default export holds the following:

MemberArgumentsReturnsNeeds
me(opts?)opts.signal, an AbortSignalPromise<Me>Nothing
users(ids)An array of member idsPromise<Record<string, Person>>Nothing
db.collection(name)A collection nameCollectionplatform.db.enabled
assetsThe AssetsApi objectplatform.assets.enabled
limits(opts?)opts.signalPromise<Limits>Nothing
connect(source)A connector source's nameConnectionconnectors.enabled

The Needs column names the instance setting an admin turns on, described in Turn on optional features. While a feature is off, its routes answer 404. A page checks the switches in platform on GET /api/v1/instance, or reads dropshelf.limits(), which leaves out a feature that is off.

Errors

Every refusal rejects with a DropshelfError, which extends Error:

FieldTypeDescription
statusnumberThe HTTP status, or 0 for a network error during an upload with progress.
titlestringA short title for the refusal.
detailstringWhat to change, when there is something to change. Read it first.
reasonstringSet by subscribe and sync only: unauthenticated or refused.
codestringSet by connect(...).run only: a short name for the refusal, listed under Query errors.
messagestringThe title and the detail together.

An aborted call rejects with the signal's reason, as fetch does. A visitor who may not open the drop gets a 404 on every route.

Visitors

me

dropshelf.me() answers the signed-in member opening the drop, or the owner of the token the request carries:

FieldTypeDescription
idstringThe member's id.
emailstringThe member's email address.
namestringThe member's name.
picturestringThe identity provider's picture URL. Absent when there is none.
avatarUrlstring or nullThe member's uploaded avatar, served by the drop host, or null.
adminbooleanWhether the member is an admin on this instance.
canEditbooleanWhether the member may change what other members stored in this drop: its owner, an editor or an admin.

The dashboard shows avatarUrl ?? picture as the member's picture. No other identity provider claims are exposed.

canEdit is the same decision the drop host makes when a member changes or deletes another member's document or asset. It is read when the page calls me(), and the drop host still decides every change when it is made.

users

dropshelf.users(ids) answers { name, picture?, avatarUrl } for each id, keyed by id. Unknown ids are left out. The module sends up to 100 ids per request and caches answers for the page's lifetime.

Documents

Collection

dropshelf.db.collection(name) returns a Collection. A name matches [a-z0-9][a-z0-9_-]{0,63}, and an invalid name throws at once. A Collection has these methods:

MethodArgumentsReturns
create(data, opts?)A JSON object; opts.id to choose the id; opts.signalPromise<Doc>, the new document
get(id, opts?)A document id; opts.signalPromise<Doc>
patch(id, merge, opts?)A document id; an object of fields to set, with null removing a field; opts.signalPromise<Doc>
put(id, data, opts?)A document id; the whole new document; opts.signalPromise<Doc>, created or replaced
delete(id, opts?)A document id; opts.signalPromise<null>
list(params?)ListParamsPromise<{ items: Doc[], next: string | null }>
all(params?)ListParams without afterPromise<Doc[]>, every page
subscribe(opts?)SubscribeOptionsA function that stops the stream
sync(opts)SyncOptionsA function that stops syncing

Doc

A document is the JSON object you stored, plus six fields the server sets:

FieldTypeDescription
idstringMatches [A-Za-z0-9][A-Za-z0-9_-]{0,127}.
revnumberGoes up with every write.
createdBystringThe id of the member who created it.
updatedBystringThe id of the member who wrote it last.
createdAtstringRFC 3339 time, in UTC.
updatedAtstringRFC 3339 time, in UTC.

A body that names one of these six fields is refused with a 400. An id that is a member's id belongs to that member: only they may create a document under it.

Anyone who can open the drop can read and create documents. Only a document's creator, the drop's owner, an editor or an admin can change or delete it. In a shared collection anyone who can open the drop can, except for a document under another member's own id. The drop's owner or an editor shares a collection with dropshelf db share <collection>. The data belongs to the drop, not to a version, so publishing or rolling back keeps it.

ListParams

list and all take these parameters:

ParameterTypeDefaultDescription
wherearraynoneUp to 8 conditions, each [field, op, value].
orderBystringcreatedAtA top-level field, rev, createdAt or updatedAt.
orderstringascasc or desc.
limitnumber501 to 200 per page. all uses 200.
afterstringnoneThe previous page's next, with the same query.
signalAbortSignalnoneAborts the call.

The ops are eq, ne, gt, gte, lt, lte and in. in takes an array of up to 100 values. A condition names a top-level field or one of the six server fields, and a missing field equals null.

subscribe

subscribe(opts) opens a live stream of the collection's changes. The page shares one stream for each collection and filter.

OptionTypeDescription
wherearrayConditions, as for list.
onReady(seq) => voidThe stream is live.
onChange(doc) => voidA document's current state after a write.
onDelete(id) => voidA document was deleted. The id may be one the page never saw.
onReset() => voidThe stream lost track. List the collection again.
onError(err) => voidAn error. A reason of unauthenticated or refused ends the stream.

The stream reconnects on its own after a dropped connection, with backoff up to 30 seconds.

sync

sync(opts) keeps a full copy of the collection, or of its filtered part, and calls onChange with every document after each change.

OptionTypeDescription
wherearrayConditions, as for list.
orderBystringThe field that orders the documents onChange receives, as for list. A document that arrives later takes its place in that order.
orderstringasc or desc.
onChange(items) => voidRequired. The current documents.
onError(err) => voidAn error. Syncing stops after an unauthenticated or refused error.

Each synced collection holds one connection. Browsers allow about six HTTP/1.1 connections per host, so keep the number of streams small.

Document errors

A document call can reject with these statuses:

StatusMeaning
400An invalid collection name, id, filter, cursor or limit, malformed JSON, or a body naming a server field.
403The visitor may not change this document, or the id is another member's.
404No such document, or the instance has the drop database off.
409create named an id that exists.
413The document is larger than the instance allows, 64 KB by default.
422The body is not a JSON object.
429Too many writes this minute, 300 per member by default. Wait Retry-After seconds.
501Live streams are not available on this server.
503The store could not answer, or the server holds as many streams as it may. Retry after Retry-After.
507A storage limit is full: documents or bytes per drop, or documents per member.

The instance's document limits are under platform.db.limits on GET /api/v1/instance. The limits reference lists the defaults.

Uploaded assets

AssetsApi

dropshelf.assets has these methods:

MethodArgumentsReturns
upload(file, opts?)A File or Blob; opts.name to override its name; opts.onProgress(fraction); opts.signalPromise<Asset>
list(params?)params.createdBy, a member id; params.limit, 1 to 100, default 50; params.after; params.signalPromise<{ items: Asset[], next: string | null }>
all(params?)params.createdBy; params.signalPromise<Asset[]>, every page
info(id, opts?)An asset id; opts.signalPromise<Asset>
delete(id, opts?)An asset id; opts.signalPromise<null>
url(id)An asset idThe asset's relative URL, a string

upload sends the file itself as the request body. It reads dropshelf.limits() first, so a file that is too large, or a drop that is full, rejects before a byte is sent. It sends at most two uploads at a time from one page, and later calls wait their turn.

Asset

An asset answers these fields:

FieldTypeDescription
idstringThe asset's id. Keep it in a document to find the asset again.
urlstringA relative URL, which works on the drop's address and its version previews.
namestringThe file name.
typestringThe media type.
sizenumberThe size in bytes.
createdBystringThe id of the member who uploaded it.
createdAtstringRFC 3339 time, in UTC.

Anyone who can open the drop can upload, list and open assets. The uploader, the drop's owner, an editor or an admin can delete one. PNG, JPEG, GIF, WebP and AVIF images, audio and video open in the page. Every other asset, SVG, HTML and PDF included, downloads when opened in a tab.

Asset errors

An asset call can reject with these statuses:

StatusMeaning
0A network error during an upload with onProgress.
400The body ended early, or an invalid limit or cursor.
403The visitor may not delete this asset.
404No such asset, or the instance has uploaded assets off.
409The upload took longer than the server holds its place. Upload it again.
413The file is larger than maxFileBytes, 25 MB by default.
429Too many uploads at once, or too many uploads and deletes this minute, 30 per member by default.
503The server is taking as many uploads as it can, or could not store the file. Retry after Retry-After.
507The drop's assets would exceed maxBytes, 500 MB by default.

Limits

dropshelf.limits() answers this drop's limits and usage. A feature that is off is left out:

FieldTypeDescription
db.maxBytesnumberThe most bytes of documents the drop may hold.
db.usedBytesnumberThe bytes of documents the drop holds.
assets.maxFileBytesnumberThe largest one asset may be.
assets.maxBytesnumberThe most bytes of assets the drop may hold.
assets.usedBytesnumberThe bytes of assets the drop holds.

Company data

Connection

dropshelf.connect(source) returns a Connection for a connector source. Its one method runs a query the drop declares in _dropshelf/queries.yaml:

MethodArgumentsReturns
run(name, params?, opts?)The query's name; an object of parameter values; opts.signalPromise<QueryResult>, or Promise<CallResult> for a tool call

Parameters travel in the query string. A value of undefined or null is left out, and the query's default applies. The page never sends SQL or names a tool. Company data in a drop explains the queries file, and Use an MCP server's data in a drop explains tool calls.

QueryResult

A query answers these fields:

FieldTypeDescription
columnsarrayEach column as { name, type }.
rowsarrayEach row as an array of values, in column order.
fetchedAtstringWhen the source was read, in RFC 3339.
cachedUntilstringWhen the cached answer expires, in RFC 3339.
objects()functionThe rows as objects keyed by column name.

Column types are string, int, number, bool, date, timestamp, json and bytes, which arrives as base64. Every decimal, and every integer beyond JavaScript's safe range, arrives as a string so no digit is lost.

CallResult

A query that calls an MCP server's tool answers these fields:

FieldTypeDescription
resultanyWhat the tool returned: its structured content, or its text, parsed when the text is JSON.
accessstringWhose access ran the call: viewer for the visitor's own, none for a server that asks nobody to sign in.
fetchedAtstringWhen the server was called, in RFC 3339.
cachedUntilstringWhen the cached answer expires, in RFC 3339.
objects()functionThe result, when it is a list of objects. Otherwise it throws a TypeError.

In TypeScript, name the type on the call: run<CallResult>('open_tickets').

Query errors

run can reject with these statuses:

StatusMeaning
400A parameter is missing or has the wrong type. detail names it.
403The query may not run for visitors. detail says why.
404This version of the drop has no such query, or the instance has connectors off.
422The answer has too many rows or is too large. Aggregate or add a LIMIT.
429The drop ran too many queries this minute, 120 by default. Retry after Retry-After.
502The source failed.
503The source is answering as many queries as it may. Retry after Retry-After.
504The query ran longer than the source allows.

The error's code field names the refusal, so a page can tell them apart without reading the text:

CodeStatusMeaning
bad_parameter400A parameter is missing or has the wrong type.
pending403The query waits for an admin.
denied403An admin denied the query.
blocked403The access the query runs with no longer covers it, or its source does not allow the tool it calls.
connect_required403The visitor is not connected to the MCP server the call runs on.
reconnect_required403The visitor must sign in to the MCP server again.
too_large422The answer has too many rows or is too large.
rate_limited429The drop ran too many queries this minute.
source_failed502The source could not be reached or failed.
tool_error502The MCP server's tool reported an error.
busy503The source is answering as many queries as it may.
timeout504The query ran longer than the source allows.

Rules the drop host enforces

  • Requests under /_dropshelf/ must come from the drop's own page. A request from another origin, a write whose Origin is not the drop's, or a write whose body is not application/json is refused. An asset upload, whose body is the file, is the exception.
  • There is no CORS on /_dropshelf/, so another drop cannot call it.
  • On a version preview, such as v3--team-lunch, only the drop's owner, editors and admins reach the platform. They read and write the same data as the live drop.
  • A personal access token works on a drop host too, attributed to the token's owner.

Last updated .

On this page