@atmyapp/core
The client for any JavaScript runtime. Every option, method and export.
Open with AI
npm install @atmyapp/coreWorks in Node 18+, edge runtimes and browsers. For a walkthrough, start with Connect any JavaScript website.
createAtMyAppClient(options)
Section titled “createAtMyAppClient(options)”import { createAtMyAppClient } from "@atmyapp/core";import schema from "../atmyapp.schema";
const ama = createAtMyAppClient({ baseUrl: process.env.ATMYAPP_API_URL!, apiKey: process.env.ATMYAPP_API_KEY!, schema, errorPolicy: "throw",});Core never reads environment variables or the URL on its own; pass values in.
| Option | Default | Meaning |
|---|---|---|
baseUrl |
required | Project API URL: https://edge.atmyapp.com/v0/projects/<id> |
apiKey |
required | Public API key from Settings → API keys |
schema |
— | Your schema. Enables storage.getValue, typed results and form validation. |
errorPolicy |
"quiet-empty" |
"throw": failed reads throw. "quiet-empty": they log a warning and return empty values. |
previewKey |
— | Show drafts for this preview session. Create a client per request. |
mode |
"client" |
"client": reads may be cached up to 60 s. "priority": skip caches (heavier usage). |
locale |
— | Default language for translated content. |
strictPreview |
false |
Treat an approximate collection preview as a failed read. |
onPreviewApproximate |
console warning | Called when a collection preview is approximate. |
plugins |
["asset-object"] |
Collection response plugins. Replacing the list drops the default. |
customFetch |
global fetch |
Your own fetch, for logging, retries or tests. |
clientMode |
"online" |
"with-fallback" or "local" read from a local snapshot. See Offline snapshots. |
ama.storage
Section titled “ama.storage”Documents, and files defined with defineFile / defineImage. Guide: Documents and media.
| Method | Returns |
|---|---|
getValue(name, options?) |
The document’s fields, or { url } for an asset. Requires schema. |
get(name, options?) |
A wrapper: { data, … } for documents, { src, … } for images |
getFromPath(path, options?) |
The stored value at a path, untyped |
getStaticUrl(path, options?) |
A public URL for a stored file |
name is a definition name or its path ("home" or "home.json"). Options: previewKey, locale.
ama.collections
Section titled “ama.collections”Guide: Collections.
| Method | Returns |
|---|---|
list(name, options?) |
Entries (newest first, at most 50) |
first(name, options?) |
The first matching entry, or null |
getById(name, id, options?) |
One entry, or null |
getManyByIds(name, ids, options?) |
Entries in the order of ids (up to 50) |
listRaw(name, options?) |
The raw response: { success, data: { entries, total } } |
| Option | Meaning |
|---|---|
filter |
A filter built with CollectionsFilter (F.eq, F.gt, F.gte, F.lt, F.lte, F.in, F.and, F.or) |
order |
"created" | "updated" | "id", optionally .asc / .desc. Default created.desc. |
limit, offset |
Page size (max 50) and start |
range |
[first, last], an alternative to limit / offset |
format |
"data" (default), "raw", "dictionary" or "dataWithMeta" |
previewKey, locale, plugins, strictPreview |
Per-call versions of the client options |
import { CollectionsFilter as F } from "@atmyapp/core";
const { rows, total } = await ama.collections.list("posts", { filter: F.and(F.eq("category", "news"), F.gte("created", new Date("2026-01-01"))), order: "created.desc", limit: 10, format: "dataWithMeta",});ama.submissions
Section titled “ama.submissions”Guide: Forms on any website.
submit(name, data, options?)sends typed data orFormDataand resolves to a result. On success it’s{ ok: true, submissionId, duplicate?, report? }. Otherwise it’s{ ok: false, error, report? }, whereerroris aSubmissionErrorwithcode,fields,status,retryAfterandretryable. Problems a visitor can cause never throw. Options:idempotencyKey: generated when omitted. Retries reuse it, so a submission is stored once.retry: automatic retries after a lost connection or brief outage (default 2, orfalse).validate: check against the schema first (default true when the client has one).captchaToken: a token from a widget you render yourself.test: test mode, which keeps the submission as a 24-hour test and returns a stepreport.onUploadProgress: upload progress in browsers.signal: cancels the request.
validate(name, data)runs the schema’s field checks locally and returns{ ok: true, checked }or{ ok: false, fields }.getFormParams(name, { returnTo? })returns{ action, method, encType }for an HTML form.getFormUrl(name, options?)returns just the stable public form address.getTypeStatus(name)returnsacceptingResponses,captcha({ provider, siteKey, version? }or null),honeypotandformUrl.isAcceptingResponses(name)checks whether the form is open.
Related exports:
captchaWidget(captcha)returns how to render any provider’s widget:scriptSrc,className,tokenFieldandinvisible(reCAPTCHA v3, where you callgrecaptcha.executeon submit). Example.SubmissionErroris the error class on failed results;SubmissionErrorCode,SubmissionFieldErrorCodeandSubmissionFieldErrorstype itscodeandfields.SUBMISSION_HONEYPOT_FIELD(_ama_hp) andSUBMISSION_RENDERED_AT_FIELD(_ama_t) name the spam-protection fields for forms you render yourself.
@atmyapp/core/forms
Section titled “@atmyapp/core/forms”A separate, dependency-free entry for browsers. It needs no API key.
enhanceSubmissionForm(form, options?)enhances one HTML form. Options:captcha: the form’s captcha fromgetTypeStatus; its widget and script are added unless the form already has one.honeypot: add the spam trap when missing (default true).messages:sending,success,network,fields(the lead-in before field problems) andfieldCodes(text per field error code).onSuccess(result): returnfalseto skip the default success handling (message, reset,returnTo).onError(error): receives theSubmissionError.
enhanceSubmissionForms(selector?, options?)enhances every form matching the selector (defaultform[data-atmyapp-form]).
Both return a cleanup function. Limits and codes: Form limits and errors.
ama.systemConfig
Section titled “ama.systemConfig”const { config } = await ama.systemConfig.get<Metadata>({ systemKey: "website.metadata" });Returns { systemKey, path, config, … } for Settings → Website settings. Pass config to resolveWebsiteMetadata(page, config, defaults, pageUrl, siteUrl) to get final head tags. In Astro, AtMyAppHead does this. See Website settings.
ama.localization
Section titled “ama.localization”For projects with translations:
| Method | Returns |
|---|---|
getStorageLocales(path) |
Languages of a document and how complete each is |
getCollectionLocales(name) |
Per-language counts for a collection |
getCollectionEntryLocales(name, id) |
Languages of one entry |
Each returns { defaultLocale, locales }. A locale’s status is missing, incomplete, current or outdated.
ama.diagnostics
Section titled “ama.diagnostics”ama.diagnostics.report() checks the configuration, key and preview without reading content. createDiagnosticsHandler(factory) serves the report from a route. See Verify an integration.
ama.analytics
Section titled “ama.analytics”trackEvent(name) and trackCustomEvent(name, data) send events to AtMyApp’s experimental content analytics. They resolve to true or false and never throw. This API may change.
Offline snapshots
Section titled “Offline snapshots”The client can read a local copy of the project’s content instead of the API:
clientMode |
Reads |
|---|---|
"online" (default) |
The API |
"with-fallback" |
The API, and the published local copy when the API is slow or unreachable |
"local" |
Only the local copy, including the drafts in the active space |
Make the copy with atmyapp content pull. It’s stored in .ama/content, includes translations, and gives your code the same shapes as the API: images arrive as { url, alt }, from their published URLs unless you pulled with --media.
Set ATMYAPP_CLIENT_MODE=local to switch a dev server to the local copy without changing code; the variable overrides clientMode. With @atmyapp/astro, local mode needs no API key, and the dev server reloads when the copy changes. Images and files from the local copy, including $file drafts, are served by the dev server at /__atmyapp/content/, because browsers don’t load file:// URLs from a web page. With another framework, serve .ama/content yourself and set ATMYAPP_LOCAL_ASSET_BASE to its URL path; otherwise the client returns file:// URLs, which only work outside a browser.
Spaces. Drafts live in a space, .ama/content/<space>/, which holds only the documents and entries it changes. Local mode shows the space named by ATMYAPP_SPACE, then localStorage.space, then .ama/content/.current, then default, over the published copy. with-fallback never shows drafts, so a live site can’t serve unpublished content.
Use atmyapp space create <name> and atmyapp space use <name> to work in a space. Local mode applies deletions from the same space, including deletions of individual translations. See the CLI workflow.
| Option | Default | Meaning |
|---|---|---|
localStorage.path |
.ama/content, then .ama/local |
Local content folder, relative to the working directory (Node only). .ama/local holds older snapshots from atmyapp snapshot download. |
localStorage.space |
see above | Space whose drafts local mode shows |
localStorage.timeoutMs |
5000 |
How long to wait for the API before falling back |
localDataSource |
— | Your own reader (readFile, readJson, listCollection, optional getStaticUrl), for browsers or custom storage. Each method also receives { locale, publishedOnly }. |
Never use fallback to hide a failing preview: an editor would see stale content.
Schema exports
Section titled “Schema exports”Core re-exports everything from @atmyapp/structure: defineSchema, s, validators, inference types and more.
| Type | Meaning |
|---|---|
AtMyAppClient<Schema> |
The client returned by createAtMyAppClient |
AtMyAppClientOptions |
Its options |
CollectionsListOptions, CollectionsFilterExpr |
Collection query options |
SubmissionResult, SubmissionTypeStatus, SubmissionCaptcha |
Form results and settings |
InferSubmission<"contact", typeof schema> |
The values a form accepts (from @atmyapp/structure) |
Local mode applies the selected space’s saved translations to the source using the schema’s array identities. After editing a merged translation with the CLI, use atmyapp content save to make it visible in the local SDK.
