@elaraai/e3-cloud-client
v1.1.22
Published
HTTP client library for the e3 cloud API
Readme
@elaraai/e3-cloud-client
HTTP client library for the e3 cloud API: what e3's own API client
(@elaraai/e3-api-client) doesn't cover — users and roles, schedules, task
configs, secrets, record history and backups, feedback, apps, releases and
staging, Files, rack delegation, and which releases a deployment runs.
Installation
npm install @elaraai/e3-cloud-clientUsage
import { whoami, repoUsers, addUser, removeUser, ApiError } from '@elaraai/e3-cloud-client';
import { variant } from '@elaraai/east';
const options = { token: 'my-access-token' };
// Get current user
const me = await whoami('https://e3.example.com', options);
console.log(`Logged in as ${me.sub}, admin: ${me.isAdmin}`);
// List users on a repo
const users = await repoUsers('https://e3.example.com', 'my-repo', options);
// Add a user holding business roles
const newUser = await addUser(
'https://e3.example.com',
'my-repo',
{ email: '[email protected]', role: variant('user', { roles: ['Rostering'] }) },
options
);
// Remove a user
await removeUser('https://e3.example.com', 'my-repo', 'user-id', options);API
whoami(url, options): Promise<WhoamiResponse>
Get current user info.
platformVersions(url, options): Promise<PlatformVersions | null>
What a deployment runs (GET /api/platform, anyone signed in): its e3 cloud
release (e3Cloud, none where its deploy named none), the e3 release its
platform and runners run (e3), and each next e3 an app's bundle is staged
for in the repositories the caller manages (staged); null from a
deployment that predates it. e3 refuses a package a newer e3 exported, so a
project can tell here, before a deploy fails, whether it fits.
e3-cloud whoami <server> prints it.
repoUsers(url, repo, options): Promise<RepoUser[]>
List the people of a repository (owner or admin).
addUser(url, repo, request, options): Promise<RepoUser>
Add a person to a repository, or change their role: an owner, or a user holding business roles the repository has (or the built-in All apps). 400 bad_request for a role it does not have.
Business roles
| Function | Answers |
|---|---|
| listRoles(url, repo, options) | A repository's roles, by name (owner or admin) |
| getRole(url, repo, name, options) | One; 404 not_found |
| putRole(url, repo, role, options) | Writes it whole, made or replaced, and answers it as stored; 400 invalid_name or bad_request (an app twice, no page, a page an app does not have). An app not deployed yet may be granted |
| deleteRole(url, repo, name, options) | Removes it, idempotently; 409 role_in_use while anyone holds it |
| myAccess(url, options) | What the caller's roles grant: each app, with its pages, in the repositories it is no owner of |
removeUser(url, repo, userId, options): Promise<void>
Remove a user from a repository.
The deployment's people (admin)
| Function | Answers |
|---|---|
| listAdminUsers(url, options) | Every person: the directory's users, the pending invitations, each one's memberships and last sign-in (Admin › Users) |
| lookupPeople(url, { subs?, emails? }, options) | The people of the given subjects and emails the directory holds (PersonList: each one's sub, email, name and whether they may sign in), each once: what a page needs to name who did something, never the whole directory. At most PEOPLE_LOOKUP_MAX (100) keys |
| disableUser(url, sub, options), enableUser(url, sub, options) | Blocks or restores a person's sign-in; never the caller's own |
listCompute(url, repo, workspace, options): Promise<ComputeConfigMap>
List all compute configs for a workspace.
getCompute(url, repo, workspace, taskName, options): Promise<ComputeSize>
Get the compute size for a task.
setCompute(url, repo, workspace, taskName, size, options): Promise<ComputeSize>
Set the compute size for a task.
setComputeBatch(url, repo, workspace, configs, options): Promise<ComputeConfigMap>
Batch set compute configs for a workspace.
removeCompute(url, repo, workspace, taskName, options): Promise<void>
Remove the compute config for a task.
listTimeout(url, repo, workspace, options): Promise<TimeoutConfigMap>
List all timeout configs for a workspace.
getTimeout(url, repo, workspace, taskName, options): Promise<TaskTimeout>
Get the timeout for a task. Returns the effective default (15m for serverless, 1440m for sized) if not explicitly set.
setTimeout(url, repo, workspace, taskName, timeout, options): Promise<TaskTimeout>
Set the timeout for a task.
setTimeoutBatch(url, repo, workspace, configs, options): Promise<TimeoutConfigMap>
Batch set timeout configs for a workspace.
removeTimeoutBatch(url, repo, workspace, taskNames, options): Promise<TimeoutConfigMap>
Remove several tasks' timeouts in one request (POST …/task-configs/timeout/remove); answers those left. A compute config is removed in a batch by setting the task serverless (setComputeBatch).
removeTimeout(url, repo, workspace, taskName, options): Promise<void>
Remove the timeout config for a task.
listTaskConfigs(url, repo, workspace, options): Promise<TaskConfigs>
List all task configs (compute + timeout) for a workspace.
repositorySettings(url, repo, options): Promise<RepositorySettings>
Every workspace of a repository's settings in one request (owner or admin):
each one's task configs, task and function delegations, dataflow width (as
getWidth answers it), feedback switch and last run's summary
(WorkspaceSettings, by workspace).
Feedback
Notes users send about a part of a workspace's pages (FB-<number>). Owners,
admins, and users in a workspace they are granted an app of send and read
their own; owners and admins read every note, close and reopen them, and turn
feedback on or off.
| Function | Answers |
|---|---|
| getFeedbackSettings(url, repo, ws, options) | { enabled } |
| putFeedbackSettings(url, repo, ws, enabled, options) | { enabled } (owner or admin) |
| addFeedback(url, repo, ws, request, options) | { id, number }; feedback_disabled while off, bad_request past a limit |
| listMyFeedback(url, repo, ws, options, { status?, limit?, cursor? }) | FeedbackMine: the caller's own summaries, newest first, and next |
| listFeedback(url, repo, ws, options, { status?, limit?, cursor? }) | FeedbackList: the workspace's notes, whole, next and counts (owner or admin) |
| getFeedback(url, repo, ws, number, options, { status? }) | FeedbackNote (owner or admin, or its sender); not_found |
| feedbackScreenshotUrl(url, repo, ws, number, options, { status? }) | a URL good for 15 minutes, fetched without the API's auth |
| closeFeedback(url, repo, ws, number, options), reopenFeedback(…) | FeedbackNote, moved (owner or admin) |
status is 'open' (the default for lists) or 'closed'; passing it to a
note's reads saves the server a read. The Feedback* types and the limits
(FEEDBACK_*, feedbackId) are re-exported from @elaraai/e3-cloud-types.
Apps
Pages and menus deployed to a workspace, each its own deployable, built with
@elaraai/e3-cloud-ui. Owners and admins read every app, and a user the apps
their business roles grant; owners and admins upload, deploy, list versions
and remove.
| Function | Answers |
|---|---|
| appList(url, repo, ws, options) | the workspace's apps (AppSummary[]), each its current version |
| appGet(url, repo, ws, app, options) | AppSummary; not_found |
| appVersions(url, repo, ws, app, options, { limit?, cursor? }) | AppVersionPage: kept versions, newest first, and next |
| appUpload(url, repo, ws, app, bytes, options) | the source a deploy names: asks where the app object's bytes go and PUTs them there |
| appDeploy(url, repo, ws, app, { source, forPlatform, dryRun }, options) | AppDeployResponse: refused (every problem), checked, live or staged |
| appsDeploy(url, repo, ws, { apps, forPlatform, dryRun }, options) | the same, for several apps together |
| appRemove(url, repo, ws, app, options) | { name, users }: users is empty (a business role's grant of the app is kept, and gives it again if it is deployed again) |
| appHoldPackage(url, repo, ws, app, zip, options, { force? }) | HeldPackage (owner or admin): uploads a package zip exported by the e3 the platform moves to next, and the platform holds it untouched, outside the repository's e3 store, until its move imports it; it reads only the zip's directory, its release entry and its ref, and answers that ref (name, version, hash, release) with held, false when the repository holds that package already. bad_request for a zip that is no package zip, package_version_conflict for another package at a version the repository holds, workspace_protected unless an admin forces it. Nothing stages on a held package yet |
| appDeployWait(url, repo, ws, job, options, { onProgress?, signal?, refresh?, deadlineMs? }) | WorkspaceDeployResult: waits for the deploy job an app deployed with its package started (deploying), polling e3's GET …/deploy/:id (100 ms, backing off to 1 s, and to 5 s once the job has run a minute); refresh gives each poll its request options afresh (a token refreshed as it expires, for a deploy that outlives it); deadlineMs stops waiting (the job runs on); its apps are live once it completes; throws when the deploy fails, and the apps stay as they were |
| myAppList(url, options) | AppList: the apps you can open across the repositories you belong to — every app of each repository you own but a staging workspace's, and the apps your business roles grant — by repository, workspace and name; the console's sidebar lists them, myAccess says which pages |
| repositoryAppList(url, repo, options) | RepositoryApps (owner or admin): the repository's apps in every workspace, each its current version and any staged bundle, with the e3 the platform runs (platform): an app built with another e3 and with no bundle staged for it needs a rebuild |
| myAppRebuilds(url, options) | AppRebuilds: the apps that need a rebuild in the repositories you manage (every repository, for an admin; those you own, else), each built with another e3 than the platform runs with no bundle built with it staged, by repository, workspace and name, with the e3 the platform runs (platform); a platform deploy is refused while one has no build for the e3 it deploys |
| adminAppList(url, options, { limit?, cursor? }) | AdminAppPage (admin): a page of the deployment's apps by repository, workspace and name, next, the e3 the platform runs (platform), and when each of the page's workspaces was last released to (lastReleases) |
A deploy throws ApiError with package_missing (import the package, then
deploy), package_version_conflict, package_deploy_unavailable (a server
that deploys no package with its apps), package_differs, app_conflict or
workspace_busy. An app built against another package than its workspace
runs answers deploying: the package deploys first, keeping the inputs
people set, and the app goes live as the job completes. appProblemText, appProblemLines and appProblemsText
print the problems; the App* types and limits are re-exported from
@elaraai/e3-cloud-types.
Staging, releases and history
A workspace's staging, another workspace of its repository that releases to
it, protects it: its package and apps then change only by a release from
its staging, or a rollback. A protected workspace refuses an app deploy or
removal (workspace_protected, naming its staging) unless an admin forces it
(appDeploy's force, appRemove's { force: true }; anyone else asking is
forbidden), and its history records each forced change.
| Function | Answers |
|---|---|
| addStaging(url, repo, live, { name, start, plan }, options) | AddStagingResponse (owner or admin): planned or added, the plan (what it starts as: a copy of live, made or replacing a workspace of the name whole, or as_is; what a copy replaces; what it protects); staging_conflict when either is linked already, not_found, workspace_busy |
| stopStaging(url, repo, live, options) | StagingLink (admins alone): the staging and the workspace it no longer protects; nothing is deleted |
| releaseWorkspace(url, repo, target, { from, carry, removeApps, plan }, options) | ReleaseResponse (owner or admin; from must be the target's staging, else not_staging): planned, refused (its problems and checks in the plan; nothing_to_release when it would change nothing), released (its apps switched) or releasing ({job, plan}, the deploy job appDeployWait waits on); the plan's undoes names the changes forced onto the target since its last release, and each app's stagedFor the next e3's bundle it stages or clears |
| rollbackWorkspace(url, repo, ws, { to, plan }, options) | the same, for an entry of the workspace's history: the one to names, or (none) the newest completed one that differs from what it runs |
| workspaceHistory(url, repo, ws, options, { limit?, before? }) | WorkspaceHistoryPage: entries newest first, and next |
| repositoryHistory(url, repo, options) | RepositoryHistory (owner or admin): every workspace with a history, in brief, by name: its newest entry, its newest under way and its newest completed change (WorkspaceHistorySummary), in one request |
| workspaceHistoryEntry(url, repo, ws, id, options) | WorkspaceHistoryEntry |
| getReleaseSettings(url, repo, ws, options) | where a workspace releases to, when it is a staging |
| getRepositoryReleaseSettings(url, repo, options) | RepositoryReleaseSettings: each staging, and the workspace it protects |
A release throws ApiError with not_found, not_staging, workspace_busy
(retry once the deploy, copy, removal or run that holds the target ends),
source_changed, app_conflict, entry_not_completed, entry_not_a_change
(a rollback to an entry that changed only a protection) or
package_deploy_unavailable. releaseProblemText and
releasePlanRefusalLines print a plan's problems; the Release* types and
RELEASE_CARRY_MAX are re-exported from @elaraai/e3-cloud-types.
Files
A workspace's Files (owners and admins): the inputs a solution fills from
files, and its records seeded or fed from them, declared with
@elaraai/e3-cloud-files. A deployed workspace keeps the files in storage of
its own, named by a path relative to the workspace (upload/), never by the
bucket that holds it: a declared source bound to nothing reads the folder of
its name there. A binding may name a bucket of your own instead
(s3://bucket/prefix/), one the deployment grants the repository.
| Function | Answers |
|---|---|
| getFiles(url, repo, ws, options) | FilesWorkspace: the declarations, the bindings (each declared source's, own storage by its path: one bound to nothing reads <source>/) and last sync, what each mapping holds (and whether its record is pending), the buckets the deployment grants the repository besides own storage (granted), and the sync under way |
| deployFiles(url, repo, ws, manifest, options, { dryRun?, force? }) | deployed (with the targets the next sync takes again whole), checked (a dry run) or refused with every problem; workspace_protected for a protected workspace, unforced |
| bindFilesSource(url, repo, ws, binding, options) | binding.url a path of the workspace's own storage, relative to it (upload/, ./, ../production/upload/), or s3://bucket/prefix/ of a bucket the deployment grants: bound (with the targets that took files where it was, which the next sync takes again whole) or refused |
| startFilesSync(url, repo, ws, { dryRun?, targets?, reset? }, options) | started with the sync's id, or running with the one under way |
| getFilesSync(url, repo, ws, id, options), filesSyncWait(url, repo, ws, id, options, { onProgress?, signal?, refresh?, deadlineMs? }) | FilesSyncJob: where the sync is and its report per target; the wait polls it to its end (250 ms, backing off to 2 s, and to 5 s once it has run a minute) |
| planFilesPush(url, repo, ws, { files, as }, options) | FilesPushPlan: per file put (its target, source, key, and how to upload it: single, multipart or external), unchanged or refused (filesPushRefusalText), and the bindings the puts go to (own storage by its path); at most 1,000 files |
| uploadFilesPush(url, repo, ws, plan, put, bytes, options, refresh?) | Uploads one put through the platform: single as one PUT with the plan's headers, multipart part by part, completed under the object's key (the binding's prefix, a path of own storage taken for the workspace as ownStoragePrefix takes it, then the plan's key); throws for external (your own credentials; into own storage, a server that signs no upload) |
| completeFilesPush(url, repo, ws, { key, uploadId, parts }, options) | A multipart upload's completion (uploadFilesPush makes it): { etag } |
A push offers each file with its name, size, SHA-256 and beast2 header type.
A workspace's dataset is offered as the file of its value: its
dataset names its workspace, its name and the hash of the value read, its
bytes are the value as e3 dataset get -f beast2 writes it, and it is
matched to the file or latest mapping filling the input or record of its
name (a latest's key <name>.beast2 under its prefix); its signed put
carries where it came from (e3-dataset, e3-dataset-hash), which the
seed's or feed's history names. bytes is a FilesPushBytes:
size: the bytes the plan was given;read(start): the bytes fromstartto the end, read afresh each time;ranged: whether a read may start anywhere for nothing. A file on disk is, so a multipart upload sends four parts at a time, each read from its own start; a dataset's value streams from its repository (ranged: false), its parts sent one after another from one read, a part sent again read again from its start, the value never held whole.
A source that throws as its bytes end (a dataset a run wrote again while it
was read) is raised as it is: its last bytes are sent only once it has
ended, so no request of other bytes than the planned ones is ever whole, and
its upload is never completed. e3-cloud files push does all of this, then
syncs the targets put.
Error Handling
All API functions throw on failure. Two error types are re-exported from @elaraai/e3-api-client:
ApiError— Application-level errors (e.g.,forbidden,not_found,user_not_found)AuthError— 401 Unauthorized (token expired or invalid)
import { whoami, ApiError, AuthError } from '@elaraai/e3-cloud-client';
try {
const me = await whoami(url, options);
console.log('User:', me.sub);
} catch (error) {
if (error instanceof AuthError) {
console.error('Not authenticated');
} else if (error instanceof ApiError) {
console.error('Error:', error.code, error.message);
}
}License
BSL 1.1. Production use needs a commercial license from Elara AI Pty Ltd. Each release becomes AGPL-3.0 four years after it is released.
