Skip to main content

Remix

info

We have a guide explaining how to integrate Composer Core with Remix: Remix CX Framework Guide

AtamaClient(fetcher, componentTypeActions, logger, cache)

The AtamaClient constructor accepts the following arguments:

ParameterTypeDefaultRequired?Description
fetcherFetcher-YesAn instance of a fetcher
componentTypeActionsComponentTypeActions-NoRead/Write action configuration. See Action Configuration below.
loggerobject-NoA logger object to hook into the AtamaClient logs. See Logger
cacheobject-NoA cache object to customize caching behavior. See Cache below.

AtamaClient#loadPaths(args, pathOrPaths)

Load all paths defined in pathOrPaths and return as soon as a path resolves ("200").

ParameterTypeDefaultRequired?Description
argsDataFunctionArgs-YesA remix loader function object. Remix loader documentation, Interface definition
pathOrPathsArray<Request | string>-YesAn array of strings or Request object where a string represents a path to load. The Request object is coming from a loaderArgs.request and is a Request instance

Either throws a Response (404 / 500) or returns a CXExperience.

AtamaClient#loader(args, pathOverride)

Load the given path.

ParameterTypeDefaultRequired?Description
argsDataFunctionArgs-YesA remix loader function object. Remix loader documentation, Interface definition
pathOverridestring-NoAn optional path to load instead of whatever is coming in through loaderArgs.request

AtamaClient#action(args, pathOverride)

Run an action based on the current path and form data passed in.

ParameterTypeDefaultRequired?Description
argsDataFunctionArgs-YesA remix loader function object. Remix loader documentation, Interface definition
pathOverridestring-NoAn optional path to load instead of whatever is coming in through loaderArgs.request

The FormData must include at least the following key/value pairs:

KeyTypeDefaultRequired?Description
actionKeystring-YesThe key of the action on the component type. This is required to understand which action to run.
componentTypestring-YesThe component type this action is supposed to run on.

Returns a JSON response.

Action Configuration

The action configuration is an object to list the resolver methods for each component type, separated by "read" and "write" actions.

Example configuration

const actionConfig = {
read: {
cart: {
"get-cart": {
input: () => {},
output: () => {},
}
}
},
write: {
"product-detail": {
"add-to-cart": {
input: () => {},
output: () => {},
}
},
}
}
ParameterTypeDefaultRequired?Description
readRecord<string, Record<string, ActionDefinition>>-NoAn object of component types and their respective action resolvers.
writeRecord<string, Record<string, ActionDefinition>>-NoAn object of component types and their respective action resolvers.

The ActionDefinition is defined like this:

ParameterTypeDefaultRequired?Description
input(data: any, dataFnArgs: DataFunctionArgs) => Promise<object>-YesA method that accepts the action input data and potentially transforms it. It's either a pass-through or a modification of the input data.
write(data: any, request: Request, inputResult: any) => Promise<object | [object, ResponseInit]>-YesA method that accepts the Action Business Capability response and either passes it through or modifies it based on the request and the result of the input method.

Cache

Remix leaves caching up to the developer. Because we're fetching experiences that we can consider cachable we provide a simple hook to implement whatever caching is desirable for the specific solution.

ParameterTypeDefaultRequired?Description
get(key: string) => Promise<any>-YesA method that accepts a key (which is a path in our case) and returns the cached data.
set(key: string, value: any) => void-YesA method that accepts a key (which is a path in our case) and a value (the experience data) and stores the data somewhere.
has(key: string) => boolean-YesA method that accepts a key (which is a path in our case) and checks the cache for the given path.