Standalone SDK client
Use the SDK services without web components or browser storage.
Use @unidy.io/sdk/standalone when you want the typed SDK services without custom elements or automatic browser authentication storage. It uses standard JavaScript and fetch; your environment supplies networking and the customer session.
Create a client for the customer context
import { createStandaloneClient } from '@unidy.io/sdk/standalone';
// Call this inside the authenticated request/session boundary.
// readCurrentCustomerToken must read only this customer's stored credentials.
export function createCustomerClient(
readCurrentCustomerToken: () => Promise<string | null>,
) {
return createStandaloneClient({
baseUrl: 'https://login.example.com',
apiKey: 'YOUR_SDK_CLIENT_KEY',
deps: {
getIdToken: readCurrentCustomerToken,
getLocale: () => 'en',
},
});
}
export async function loadProfile(
readCurrentCustomerToken: () => Promise<string | null>,
) {
const client = createCustomerClient(readCurrentCustomerToken);
const [error, data] = await client.profile.get();
if (error !== null) {
return { ok: false as const, error };
}
return { ok: true as const, profile: data };
}Do not share a mutable customer token in a process-global client. A server handles multiple customers concurrently: bind token access to the current authenticated request or create a separate client per customer session. Never cache one customer's profile as public data.
Own authentication and storage explicitly
The core client supplies services, not an automatic session manager. Implement sign-in and registration, store credentials using your platform's protected session storage, serialize token rotation, and return a valid current token from getIdToken. Use the credential lifecycle for expiry and logout requirements.
The React package's createStandaloneClient is a different wrapper: it bridges browser auth storage, shared refresh and credentialed fetch. Import from @unidy.io/sdk-react when following the React guide; import from @unidy.io/sdk/standalone when you intentionally own those dependencies.
Handle service results
Service methods return tuples such as [null, data] on success or [errorCode, details] on failure. Branch on errorCode === null, not on data truthiness. Some methods include diagnostic response information as a third element. Newsletter bulk operations can carry partial success inside an error result, so inspect the operation's result type.
import type { StandaloneUnidyClient } from '@unidy.io/sdk/standalone';
export async function startSignIn(client: StandaloneUnidyClient, email: string) {
const [error, state] = await client.auth.createSignIn({ payload: { email } });
if (error !== null) {
// Map the typed error to your UI; do not log credentials or response tokens.
return { ok: false as const, error };
}
// This is a sign-in state, not yet an authenticated profile.
return { ok: true as const, state };
}Services include auth, profile, newsletters, services, oauth, tickets, ticketTransfers, subscriptions and transactions. Consult the installed package's declarations for each argument and response. You can also inject a logger and error reporter through deps; redact sensitive request and response data before forwarding it.
Platform checks
The standalone import does not require a DOM or inject browser storage. Browser CORS still applies when it runs in a browser. Cookie restoration needs explicit platform support for cookies; a server's fetch is not automatically a customer's browser cookie jar. WebAuthn and social redirects need platform-specific UI even when the HTTP service itself is portable.