The `castle-api-client` package functions as the official JavaScript/TypeScript client for interacting with the `ghost-server` API. It implements a custom JSON RPC-like protocol, making HTTP POST requests to a single endpoint (`/api`) with a JSON body containing `method` and `args` fields. This design enables a unified and simplified communication interface. The client is highly versatile, supporting a broad spectrum of JavaScript environments, including Node.js, modern web browsers, Electron applications, and React Native projects. Its primary function is centered around user identity and authentication, relying on deep integration with Expo user accounts. This strategic reliance streamlines authentication workflows for Expo-centric applications. A key differentiator for `castle-api-client` is its architectural independence: it was specifically developed to decouple `ghost-server` from larger, more monolithic web stacks, allowing for faster development cycles and greater agility in evolving its features. This client is currently at stable version 7.0.0. While no specific release cadence is publicly detailed, its design emphasizes responsiveness to evolving needs, offering a lightweight and efficient solution for secure, cross-platform communication within the Expo ecosystem, particularly beneficial for projects needing robust login and identity management without entanglement in complex legacy systems.
npm install castle-api-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the Ghost API client, performing a hypothetical login using an Expo token, and subsequently fetching user profile information via the generic `call` method, handling potential errors.
Review the package's GitHub releases or documentation for migration instructions between major versions. Update import paths, method calls, and client configuration as required.
Plan authentication strategy to align with Expo user accounts where possible. For alternative identity providers, consider implementing a custom authentication layer that translates into the `ghost-server` protocol or using a different API client.
Consult the `ghost-server` README or API documentation to understand the precise `method` names and the structure of `args` objects for each available operation before making calls.
Always use environment variables (e.g., `process.env.GHOST_API_URL`) to configure the `serverUrl` option when initializing `GhostApiClient`. This enables flexible deployment to different environments.
Ensure `new GhostApiClient(...)` has been successfully executed before attempting to call any methods on the `client` object. Verify that `client` variable holds the instantiated `GhostApiClient`.
Verify that `EXPO_AUTH_TOKEN` (or the equivalent credential) is correctly set and passed to the client or the specific authentication method. Renew expired tokens if necessary.
Double-check the `serverUrl` provided to the `GhostApiClient` constructor. Confirm the `ghost-server` is running correctly and that no network proxies or firewalls are interfering with the JSON response. Inspect the raw HTTP response body if possible.
Ensure that the first argument to `client.call` is an object that explicitly includes a `method` property with a valid, non-empty string value corresponding to an existing server method (e.g., `{ method: 'user.getProfile', args: {...} }`).No dependency data recorded yet.