Customers
Anonymous and verified customers, sessions, sign-in codes and email changes, suppressions, and notes
A customer is one person on one store’s website. Every visitor is a customer: a browser’s first write (a cart, a chat, a form or a tracked action) creates an anonymous customer, and it becomes verified only when a sign-in code proves an email. Storefront sessions are a visitor’s browser session or an email-authenticated one. Platform accounts are a separate operator identity.
import type { Block, CustomerAddress, EpochMilliseconds } from "arky-sdk";
interface Customer {
id: string;
store_id: string;
type:
| { type: "anonymous" }
| {
type: "verified";
contact: { email: string; language: string };
addresses: CustomerAddress[];
default_shipping_address_id: string | null;
default_billing_address_id: string | null;
};
profile: Block[];
blocks: Block[];
created_at: EpochMilliseconds;
updated_at: EpochMilliseconds;
}
- An email is proof, not profile data. An email someone typed but never proved is never stored
on a customer: it stays on the order, form submission or conversation where it was typed. Nobody
can write an email onto a customer or sign one in, staff and the API included; only an accepted
code does. A verified email is unique in the store. A verified customer’s
contactis the proven email with the language its emails go in. - Only a verified customer has an address book, of up to 100 addresses; each default points into it.
profileholds details the signed-in customer reads and edits;blocksholds details only staff and the API see, such as imported data.- An anonymous customer can browse, keep a cart, check out products and bookings as a guest, chat, send forms and be tracked. Only a verified customer can hold a package member, own a saved card, hold a company membership, be named in package access or a promotion, buy a package line, use a signed-in-only promotion or accept an offer.
Storefront Customer Flow
/v1/storefront/customer/identify arky.customer.identify() /v1/storefront/customer/request-code arky.customer.requestCode() /v1/storefront/customer/verify arky.customer.verify() /v1/storefront/customer/me/change-email arky.customer.changeEmail() /v1/storefront/customer/refresh arky.customer.refresh() /v1/storefront/customer/logout arky.customer.logout() /v1/storefront/customer/me arky.customer.getMe() /v1/storefront/customer/me arky.customer.updateMe() /v1/storefront/customer/me/unsubscribe arky.customer.unsubscribe() /v1/storefront/customer/me/resubscribe arky.customer.resubscribe() import { initialize } from "arky-sdk/storefront";
import { createOrderToken } from "arky-sdk/utils";
const arky = initialize("arky_pk_...", {
locale: "en",
createVisitorIdentity: () => ({
customer_id: crypto.randomUUID(),
session_id: crypto.randomUUID(),
}),
createSessionId: () => crypto.randomUUID(),
createId: () => crypto.randomUUID(),
createOrderToken,
});
const requested = await arky.customer.requestCode({
contact: { email: "[email protected]", language: "en" },
});
await arky.customer.verify({ code: "123456" });
const me = await arky.customer.getMe();
console.log(me.customer.type, me.email_unsubscribed);
identifystarts a visitor session with a new anonymous customer, under ids the storefront picks. The SDK calls it the first time a stateful call needs a session and reuses that session afterwards. When the answer to that first identify is lost, Arky refuses the same ids with409, and the SDK identifies again with new ones. A visitor session lasts until 365 days after it was last used.requestCodetakes thecontactthe code goes to: the email and the language of the code email, one of the store’s languages (409 CUSTOMER.LANGUAGE_NOT_SUPPORTEDotherwise). It sends the store’scustomer_sign_inemail. The code email’s id comes from the app’screateId, or theidyou pass. A retry after a lost answer for the same contact reuses it, so one email goes out; a request after an answer, such as “send another code”, gets a new one. A request is refused at once while the store has nocustomer_sign_inemail selected or its email sending is paused (409 CUSTOMER_SIGN_IN.UNAVAILABLE) or its sending address can’t send (409 EMAIL_ADDRESS.NOT_SENDING). The code email is written in the contact’s language, or in the template’s default language when it has none; signing in never changes a verified customer’s saved contact. A code lasts ten minutes; an address gets at most one new code a minute (409 CUSTOMER_SIGN_IN.CODE_RECENT), and after five wrong tries every try for that address is refused until the code expires (409 CUSTOMER_SIGN_IN.ATTEMPTS_EXHAUSTED). Once a code is accepted, its wrong tries stop counting. With a bot check on the key, send the provider’s token asbot_check_token.verifychecks the code and makes a new email-authenticated session under an id from the app’screateSessionId. A wrong or expired code, or none waiting, is refused with409 CUSTOMER_SIGN_IN.CODE_INVALIDand counts as a wrong try. If no verified customer has the email, the anonymous customer becomes verified and keeps its id. If another customer already has it, everything the anonymous customer owns (its carts, orders, conversations, form submissions, actions) moves to that customer and the session continues as them. Either way, company invites for the email become active.refreshswaps the refresh token for a new signed-in session, under thesession_idthe app picks, with new access and refresh tokens. The SDK refreshes on its own with an id fromcreateSessionId. Only Arky’s own refusal of that refresh (401 GENERAL.UNAUTHENTICATEDor403 GENERAL.UNAUTHORIZEDin Arky’s error body) clears the session and reports the sign-out; any other failed refresh, such as a proxy’s 401 or 403, a 429, a 5xx or a lost answer, fails that request and keeps the session.updateMecarriesexpected_updated_atand changes the signed-in customer’s ownprofile, saved addresses (the whole list), default addresses andlanguage, the language their emails are written in. A newly chosen language must be one of the store’s (409 CUSTOMER.LANGUAGE_NOT_SUPPORTED); sending the current one, even one the store has since removed, changes nothing. A storefront profile write keeps the record links the profile already holds but can’t add amedia,entry,formorproductblock (409 CUSTOMER.PROFILE_REFERENCE_TEAM_ONLY); staff and account tokens can. It never changes the email.
Changing The Email
On a signed-in session, requestCode starts an email change instead of a sign-in, and the code
goes to the new address:
await arky.customer.requestCode({
contact: { email: "[email protected]", language: "en" },
});
const me = await arky.customer.changeEmail({ code: "654321" });
- The code goes out as the store’s
customer_email_verificationemail. The request is refused while another verified customer holds the new address (409 CUSTOMER.EMAIL_TAKEN), when it names the customer’s current address (409 CUSTOMER.EMAIL_UNCHANGED), and while the store has nocustomer_email_verificationor noemail_changedemail selected (409 CUSTOMER_SIGN_IN.UNAVAILABLE). changeEmailproves the code. The session stays signed in, the requested contact becomes the customer’s verified contact, and the customer’s other signed-in sessions end. Nothing merges, but company invites for the new address become active.- The previous verified contact gets the store’s
email_changedemail, in its own language. - A
refreshkeeps a pending change: it moves to the new session with its wrong tries, and the code still completes it there.
Unsubscribing
unsubscribe records the store’s unsubscribe for the signed-in customer’s verified address, so
broadcasts stop reaching it; resubscribe lifts it. email_unsubscribed on getMe says whether one
is in place. The storefront can’t lift a staff block, a bounce or a complaint.
The arky_pk_... publishable key identifies the store and is safe in browser code. Visitor,
access and refresh tokens are returned only when they are issued; the SDK keeps them in its own
storage. Never put an account token in storefront code.
Admin Customers
/v1/stores/{store_id}/customers sdk.customers.find() /v1/stores/{store_id}/customers sdk.customers.create() /v1/stores/{store_id}/customers/{id} sdk.customers.get() /v1/stores/{store_id}/customers/{id} sdk.customers.update() /v1/stores/{store_id}/customers/{id}/erase sdk.customers.erase() /v1/stores/{store_id}/customers/{id}/merge sdk.customers.merge() /v1/stores/{store_id}/customers/import/preview sdk.customers.previewImport() /v1/stores/{store_id}/customers/import sdk.customers.import() const customer = await sdk.customers.create({
store_id: storeId,
id: crypto.randomUUID(),
profile: [{ id: crypto.randomUUID(), key: "first_name", type: "text", value: "Ana" }],
blocks: [{ id: crypto.randomUUID(), key: "phone", type: "text", value: "+49 30 000000" }],
});
- Staff and the API create anonymous customers, for a phone or walk-in order or an import. An
import puts the old details, such as email, name and phone, into
profileorblocks; an email there is plain data that signs nobody in and never receives broadcasts. Each import row names its customer id: a row whose id already names the same imported customer answersexistingand changes nothing, so an import repeated with the same ids makes no copy. Each row answerscreated(createin a preview),existingorfailedwith the error answer it got (error,status_code,validation_errors); a request holds 1 to 1,000 rows in production. findlists verified customers and anonymous customers with at least one order (shown by their latest order’s contact), with theirhas_cart,has_customer_actionandhas_orderfacts, and filters bytype, text and those facts. The text also matches that latest order contact’s email, names and phone, so a guest is found by the contact the list shows.updatechangesprofile,blocksand a verified customer’s addresses and defaults; an omitted field stays as it is.merge({ store_id, id, target_customer_id, expected_updated_at })moves the customer named byidinto a verified target, for example one person with two emails: its orders, carts, conversations, form submissions, actions, experiment assignments, returns, notes,profileandblocks(the target’s value wins on the same key), its package members, saved cards, company memberships and addresses. It is refused while both hold a member that isn’t cancelled of the same package or offering, or a membership of the same company. Every session of the merged-away customer ends, and webhooks get onecustomer.mergednaming both.erase({ store_id, id, expected_updated_at })leaves the customer anonymous: its email, address book,profileandblocksare cleared and every session ends. It deletes every cart of the customer that didn’t become an order (expired ones too), its conversations, form submissions, actions, experiment assignments, promotion use counts, saved cards, company memberships and notes, and the package access rows that name it, and it takes the customer out of every promotioncustomercondition; a condition left with no customer matches nobody. Orders and cancelled members keep the bare customer, and email suppressions stay. Each order also keeps, as the record of the sale, the contact email, names and phone and the billing and delivery addresses it was placed with, and its fulfillment jobs keep their delivery addresses: erasing changes none of them, so order search still finds those orders by that contact and the customer list still shows the customer by its latest order’s contact. Staff can still correct an order’s contact. Erasing is refused while the customer holds a member that isn’t cancelled, or a company’s last manager role while others are active.
Sessions
/v1/stores/{store_id}/customers/{customer_id}/sessions sdk.customers.findSessions() /v1/stores/{store_id}/customers/{customer_id}/sessions/{session_id}/revoke sdk.customers.revokeSession() /v1/stores/{store_id}/customers/{customer_id}/sessions/revoke sdk.customers.revokeAllSessions() A session’s type is visitor (with its pending code request, if any) or email_authenticated
(with its pending email change, if any), and its status is active, superseded or revoked.
Admin reads never include tokens, hashes or codes.
Email Suppressions
One “don’t email this address” entry per store, address and type: unsubscribe (the broadcast
unsubscribe link, the storefront or a team member), block (a team member blocked the address),
hard_bounce and complaint (from the store’s Resend reports).
/v1/stores/{store_id}/email-suppressions sdk.customers.emailSuppression.find() /v1/stores/{store_id}/email-suppressions/{id} sdk.customers.emailSuppression.get() /v1/stores/{store_id}/email-suppressions/block sdk.customers.emailSuppression.block() /v1/stores/{store_id}/email-suppressions/record-unsubscribe sdk.customers.emailSuppression.recordUnsubscribe() /v1/stores/{store_id}/email-suppressions/{id}/unblock sdk.customers.emailSuppression.unblock() /v1/stores/{store_id}/email-suppressions/{id}/record-resubscribe sdk.customers.emailSuppression.recordResubscribe() import type { AccountActor, EpochMilliseconds } from "arky-sdk";
interface EmailSuppression {
id: string;
store_id: string;
email: string;
type: "unsubscribe" | "block" | "hard_bounce" | "complaint";
status:
| {
type: "active";
cause:
| { type: "storefront"; customer_session_id: string }
| { type: "unsubscribe_link"; broadcast_id: string }
| { type: "account"; actor: AccountActor; note: string }
| { type: "report" };
}
| {
type: "released";
by: { type: "account"; actor: AccountActor; note: string } | { type: "storefront"; customer_session_id: string };
};
created_at: EpochMilliseconds;
updated_at: EpochMilliseconds;
}
- A block, a hard bounce or a complaint stops every store email to the address except sign-in
codes; an unsubscribe stops broadcasts only, without ending any membership. A new entry changes
no waiting email by itself: Arky checks the address right before each send, so a waiting email to
it ends
not_sentwith the reasonrecipient_suppressed. - A team member blocks or records an unsubscribe with an id the app picks and a note; unblock and
record-resubscribe carry the note and the
expected_updated_atthey read. Releasing a hard bounce or complaint also removes the address from the store’s Resend suppression list. - Opening a broadcast’s unsubscribe link only shows its confirmation; the one-click post records the unsubscribe, so a link scanner unsubscribes nobody.
- A signed-in customer lifts their own unsubscribe with
resubscribe, or by signing up again for a free package they already hold.
Packages
A verified customer, a company or a company location becomes a member of a package by buying it or when the team assigns them. Membership gives club prices, price lists, deliveries or newsletters; it is never a list staff keep by hand.
const memberships = await sdk.eshop.packageMember.find({ store_id: storeId, customer_id: customer.id });
Staff Notes
/v1/stores/{store_id}/customers/{customer_id}/notes sdk.customers.notes.find() /v1/stores/{store_id}/customers/{customer_id}/notes sdk.customers.notes.create() /v1/stores/{store_id}/customers/{customer_id}/notes/{id} sdk.customers.notes.update() /v1/stores/{store_id}/customers/{customer_id}/notes/{id}?expected_updated_at= sdk.customers.notes.delete() const note = await sdk.customers.notes.create({
store_id: storeId,
customer_id: customer.id,
id: crypto.randomUUID(),
body: "Prefers delivery after 14:00.",
});
A Note is { id, store_id, target, body, actor, created_at, updated_at }, where target names a
customer, a company, an order, a form submission or a conversation. A note holds at most 2,000
characters and a record at most 500 notes. Customers never see notes. Only the author edits a note;
the author or an admin deletes it, with the expected_updated_at they read.
Timeline And Events
Each customer’s timeline is their customer actions: the storefront’s own action keys, and the moments Arky records itself (cart items added and removed, orders placed, forms submitted, support conversations started, handed to the team and resolved, and package members activated, cancelled and switched).
Webhooks: customer.verified (when an email is first proven), customer.updated,
customer.merged and customer.erased. A new anonymous customer posts nothing.