Back to Arky

Account

Operator sign-in with email codes, sessions, account tokens, and the account itself

An account is a person who works in Arky: a store owner, a team member or a platform administrator. It is a sign-in email; store access comes from memberships. Storefront customers are a separate identity and never get accounts.

import type { EpochMilliseconds } from "arky-sdk";

interface Account {
	id: string;
	email: string;
	status: { type: "active" } | { type: "deleting" };
	test_stores: number;
	created_at: EpochMilliseconds;
	updated_at: EpochMilliseconds;
}

test_stores counts the test stores the account owns, one still being deleted included.

Sign In With A Code

POST /v1/auth/code
SDK: sdk.account.auth.requestCode()
POST /v1/auth/verify
SDK: sdk.account.auth.verify()
POST /v1/stores/{store_id}/auth/code
SDK: sdk.account.auth.requestCode({ session_id, store_id, language })
POST /v1/stores/{store_id}/auth/verify
SDK: sdk.account.auth.verify({ store_id })
import { createAdmin } from "arky-sdk/admin";

const sdk = createAdmin({ apiUrl: "https://api.arky.io" });

const pending = await sdk.account.auth.requestCode({ session_id: crypto.randomUUID(), email: "[email protected]" });
await sdk.account.auth.verify({ session_id: pending.session_id, code: "123456" });

const me = await sdk.account.getMe();

The Arky sign-in code is one of Arky’s own emails, sent through Arky’s own Resend account from Arky’s address. The first accepted code for an email creates its account. requestCode carries the pending session’s session_id, a UUID v4 the app picks once per “send code” press and sends again on a retry: the same id and email while that code is open answer the same pending session and send no second code, and the same id with another email, through the other sign-in or after its code was used is refused with 409 GENERAL.CONFLICT. A code lasts ten minutes. An address gets at most one new code a minute in each sign-in (409 ACCOUNT_SIGN_IN.CODE_RECENT), after five wrong tries every try for that address is refused until the code expires (409 ACCOUNT_SIGN_IN.ATTEMPTS_EXHAUSTED), and a wrong or expired code, or none waiting, is refused with 409 ACCOUNT_SIGN_IN.CODE_INVALID.

With store_id, requestCode and verify sign in through a store’s own login page: the code goes out as the store’s own store_admin_sign_in email, from the store’s sender, in the language the request names (one of the store’s). The request is refused at once with 409 STORE_SIGN_IN.UNAVAILABLE, leaving no pending session or email, while the store has no store_admin_sign_in email selected, its email sending is paused or its Arky plan has no access; Arky’s own sign-in still works then. A store that is closing refuses them. The session a store’s sign-in opens works only in that store, with the account’s role there: other stores, platform administration, creating a store, accepting another store’s invite and deleting the account refuse it with 403 ACCOUNT.ARKY_SIGN_IN_REQUIRED, and a platform administrator signed in that way has no platform powers. Arky’s own sign-in opens every store the account works in. The Admin client keeps the session and refreshes it. Transferring a store, closing a live store, making an account token, adding or removing a platform administrator and deleting an account that holds a platform-administrator grant need a sign-in within the last 15 minutes.

Sessions

GET /v1/accounts/me/sessions
SDK: sdk.account.session.find()
DELETE /v1/accounts/me/sessions/{id}
SDK: sdk.account.session.revoke()

A session is pending_verification (with its failed attempts and expiry), active, superseded or revoked. One session is one sign-in; finished sessions are removed after 30 days. Its scope is { type: "arky" } for Arky’s own sign-in or { type: "store", store_id } for a store’s, set by the sign-in that sent its code and kept by every refresh. A store session lists and revokes only that store’s sessions of the account, itself included, so signing out keeps working. Closing a store removes its store sessions, pending codes included, and refreshing one is then refused with 403 GENERAL.UNAUTHORIZED, as an unknown refresh token is; the account’s Arky sessions stay.

Account Tokens

POST /v1/accounts/me/tokens
SDK: sdk.account.token.create()
GET /v1/accounts/me/tokens
SDK: sdk.account.token.find()
POST /v1/accounts/me/tokens/{id}/revoke
SDK: sdk.account.token.revoke()
DELETE /v1/accounts/me/tokens/{id}?expected_updated_at=
SDK: sdk.account.token.delete()
const made = await sdk.account.token.create({
	id: crypto.randomUUID(),
	name: "CI",
	stores: { type: "test_stores" },
	permissions: [{ type: "admin" }],
	expires_at: null,
});
if (made.type === "secret_created") console.log(made.value);

const ci = createAdmin({ apiUrl: "https://api.arky.io", accountToken: process.env.ARKY_API_TOKEN });

An account token (arky_at_...) lets a script, a CI job or an agent act as the account without signing in. It works where the account’s session works, apart from what the list below names, and acts as the account: history records the account with the token that acted. Only an Arky sign-in made within the last 15 minutes makes one. Its value is answered once, in secret_created; Arky keeps only its hash and the token_hint, the value’s first 16 characters, so you can tell which token a secret holds. The same create again answers existing without the value, and the same id with anything else is refused with 409 GENERAL.CONFLICT.

  • stores is where it works: all, every store where the account is an active member, and it makes stores; only with store_ids, at most 100 stores the account is an active member of, each once, and it makes none; or test_stores, which makes, reaches and closes test stores and never makes or reaches a live one. A store outside them is refused with 403 ACCOUNT_TOKEN.STORE_NOT_COVERED. A deleted store leaves every only list, and a token whose last store it was is deleted. Through a token, sdk.account.getMe() works, and the account’s stores and memberships list only the stores it reaches.
  • permissions are admin alone or the role permissions it needs, each once (orders, payments and customers with their access, fulfillment and inventory with locations: { type: "everywhere" }). In each store it does only what both its permissions and the account’s roles there allow, and it stops working in a store as soon as the account’s membership there ends.
  • expires_at is required: a later moment, or null for never.
  • A token has no platform powers and is never a recent sign-in. Platform routes, the account’s tokens and sessions, accepting an invite and deleting the account refuse it with 403 ACCOUNT.ARKY_SIGN_IN_REQUIRED, and transferring a store and closing a live one with 403 ACCOUNT.RECENT_SIGN_IN_REQUIRED. The owner’s token holding admin closes a test store.
  • Revoking takes effect at once and keeps the token listed as revoked; only a revoked token can be deleted (409 ACCOUNT_TOKEN.ACTIVE otherwise). Tokens are never edited: to rotate one, make a new one, deploy it, then revoke the old one. An account holds at most 50, revoked ones included until they are deleted (409 ACCOUNT_TOKEN.LIMIT).
  • A revoked or expired token, and every token of an account that is being deleted, answers 401. Calls through a token count against its own quota of about 10,000 a minute, not its client address.

Account

GET /v1/accounts/me
SDK: sdk.account.getMe()
GET /v1/accounts/search
SDK: sdk.account.find()
DELETE /v1/accounts
SDK: sdk.account.delete()

Deleting your account marks it deleting; one cleanup step then removes its sessions, its account tokens, its memberships and any platform administrator grant, and then the account. Its account tokens answer 401 from the moment it is marked. An account that owns an active store can’t be deleted: transfer or close the store first; a store that is being closed doesn’t stop it. The last platform administrator’s account can’t be deleted. Only an Arky sign-in deletes the account: a store session or an account token is refused with 403 ACCOUNT.ARKY_SIGN_IN_REQUIRED, and an account that holds a platform-administrator grant also needs a sign-in within the last 15 minutes (403 ACCOUNT.RECENT_SIGN_IN_REQUIRED).

Note

Platform administrators are their own record; see Platform.