@lokalise/fastify-extras
Version:
Opinionated set of fastify plugins, commonly used in Lokalise
57 lines (56 loc) • 1.94 kB
TypeScript
import type { BaseEvent, NodeOptions, Plugin } from '@amplitude/analytics-types';
import type { FastifyPluginCallback, FastifyReply, FastifyRequest } from 'fastify';
import { Amplitude } from './Amplitude.js';
declare module 'fastify' {
interface FastifyInstance {
amplitude: Amplitude;
}
}
/**
* Callback used to create the events that will be used to automatically
* track the API usage
*/
export type CreateApiTrackingEventFn = (req: FastifyRequest, res: FastifyReply) => BaseEvent | null;
/**
* Configuration to set up the Amplitude Plugin.
*
* @property {boolean} isEnabled Flag to enable or disable the plugin.
*
* @property {string} apiKey Amplitude api key, please get it from your
* Amplitude project
*
* @property {NodeOptions} Amplitude configuration, please check
* [this](https://amplitude.github.io/Amplitude-TypeScript/modules/_amplitude_analytics_node.Types.html#NodeOptions)
* to learn more.
*
* @property {CreateApiTrackingEventFn} apiUsageTracking Callback used to create
* the event that will be sent automatically to track the API usage. If not
* specified the API usage track will be disabled.
*
* @property {Plugin[]} plugins Allow to extend plugin behavior by, for example,
* modifying event properties. Please check
* [this](https://www.docs.developers.amplitude.com/data/sdks/typescript-node/#plugins)
* to see how it works
*/
export interface AmplitudeConfig {
isEnabled: boolean;
apiKey?: string;
options?: NodeOptions;
apiUsageTracking?: CreateApiTrackingEventFn;
plugins?: Plugin[];
}
/**
* Use this method to register the amplitude plugin on your fastify instance.
*
* Example of usage:
* ```ts
* await app.register(amplitudePlugin, {
* isEnabled: true,
* apiKey: 'dummy-api-key',
* options: {
* serverZone: 'EU',
* },
* })
* ```
*/
export declare const amplitudePlugin: FastifyPluginCallback<AmplitudeConfig>;