32 lines
1.0 KiB
Markdown
32 lines
1.0 KiB
Markdown
|
|
# Modules
|
||
|
|
|
||
|
|
Source: `src/domains/ModulesDomain.ts`. Calls an installed module function as
|
||
|
|
the signed-in player through `POST /sdk/v1/modules/{module}/{fn}`.
|
||
|
|
|
||
|
|
```ts
|
||
|
|
client.modules.call(module: string, fn: string, args?: unknown): Promise<CallModuleFunctionClientResponse>
|
||
|
|
// CallModuleFunctionClientResponse = { result?: unknown }
|
||
|
|
```
|
||
|
|
|
||
|
|
```ts
|
||
|
|
const { result } = await client.modules.call('my_module', 'hello', { name: 'Bob' });
|
||
|
|
```
|
||
|
|
|
||
|
|
`args` is sent as `{ args }`. The response carries only `result`; console
|
||
|
|
output and the kernel call log stay on the platform dry run.
|
||
|
|
|
||
|
|
A business error raised by the module rejects with `RudderHttpError`
|
||
|
|
(`status` 422, body `{ error, code, requestId }`) whose `code` is the
|
||
|
|
module's own open string code; there are no generated constants for it. A
|
||
|
|
trap is a 500 and a timeout a 504, both without details.
|
||
|
|
|
||
|
|
```ts
|
||
|
|
try {
|
||
|
|
await client.modules.call('my_module', 'hello');
|
||
|
|
} catch (error) {
|
||
|
|
if (error instanceof RudderHttpError && error.status === 422) {
|
||
|
|
console.warn(error.code); // module-defined
|
||
|
|
}
|
||
|
|
}
|
||
|
|
```
|