@mediarithmics/plugins-nodejs-sdk
Version:
This is the mediarithmics nodejs to help plugin developers bootstrapping their plugin without having to deal with most of the plugin boilerplate
102 lines (101 loc) • 4.86 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import express from 'express';
import cache from 'memory-cache';
import rp from 'request-promise-native';
import winston from 'winston';
import { Compartment, DataListResponse, SimpleResponse } from '../../';
import { Datamart } from '../../api/core/datamart/Datamart';
import { AdLayoutProperty, AssetFileProperty, AssetFolderProperty, BooleanProperty, DataFileProperty, DoubleProperty, IntProperty, NativeDataProperty, NativeImageProperty, NativeTitleProperty, PluginProperty, PropertyType, StringProperty, UrlProperty } from '../../api/core/plugin/PluginPropertyInterface';
import { Index, Option } from '../../utils';
export interface InitUpdateResponse {
status: ResponseStatusCode;
msg?: string;
}
export interface LogLevelUpdateResponse {
status: ResponseStatusCode;
msg?: string;
}
export interface Credentials {
authentication_token: string;
worker_id: string;
}
export type ResponseStatusCode = 'ok' | 'error';
export interface ResponseError {
name: string;
response: {
statusCode: number;
statusMessage: string;
body: unknown;
};
}
export declare class ResourceNotFoundError extends Error {
constructor(message: string);
}
export declare class PropertiesWrapper {
readonly values: Array<PluginProperty>;
readonly normalized: Index<PluginProperty>;
constructor(values: Array<PluginProperty>);
get: (key: string) => Option<PluginProperty>;
ofType: (typeName: PropertyType) => Option<PluginProperty>;
findAssetFileProperty: (key?: string) => Option<AssetFileProperty>;
findAssetFolderProperty: (key?: string) => Option<AssetFolderProperty>;
findDataFileProperty: (key?: string) => Option<DataFileProperty>;
findUrlProperty: (key?: string) => Option<UrlProperty>;
findStringProperty: (key?: string) => Option<StringProperty>;
findAdLayoutProperty: (key?: string) => Option<AdLayoutProperty>;
findBooleanProperty: (key?: string) => Option<BooleanProperty>;
findDoubleProperty: (key?: string) => Option<DoubleProperty>;
findIntProperty: (key?: string) => Option<IntProperty>;
findNativeDataProperty: (key?: string) => Option<NativeDataProperty>;
findNativeTitleProperty: (key?: string) => Option<NativeTitleProperty>;
findNativeImageProperty: (key?: string) => Option<NativeImageProperty>;
}
export declare abstract class BasePlugin<CacheValue = unknown> {
multiThread: boolean;
INSTANCE_CONTEXT_CACHE_EXPIRATION: number;
pluginCache: cache.CacheClass<string, Promise<CacheValue>>;
gatewayHost: string;
gatewayPort: number;
outboundPlatformUrl: string;
app: express.Application;
logger: winston.Logger;
credentials: Credentials;
_transport: rp.RequestPromiseAPI;
enableThrottling: boolean;
constructor(enableThrottling?: boolean);
getInstanceContextCacheExpiration(): number;
onLogLevelUpdate(level: string): void;
fetchDataFile(uri: string): Promise<Buffer>;
fetchConfigurationFileOptional(fileName: string): Promise<Buffer | undefined>;
fetchConfigurationFile(fileName: string): Promise<Buffer>;
upsertConfigurationFile(fileName: string, fileContent: Buffer): Promise<SimpleResponse>;
requestGatewayHelper<T>(method: string, uri: string, body?: unknown, qs?: unknown, isJson?: boolean, isBinary?: boolean): Promise<T>;
requestPublicMicsApiHelper<T>(apiToken: string, options: rp.OptionsWithUri): Promise<T>;
fetchDatamarts(apiToken: string, organisationId: string): Promise<DataListResponse<Datamart>>;
fetchDatamartCompartments(apiToken: string, datamartId: string): Promise<DataListResponse<Compartment>>;
onInitRequest(creds: Credentials): void;
start(): void;
protected httpIsReady(): string;
protected onLogLevelUpdateHandler(req: express.Request, res: express.Response): express.Response<any, Record<string, any>> | undefined;
protected onLogLevelRequest(req: express.Request, res: express.Response): void;
protected onStatusRequest(req: express.Request, res: express.Response): void;
protected asyncMiddleware: (fn: (req: express.Request, res: express.Response, next: express.NextFunction) => unknown) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
protected setErrorHandler(): void;
private initLogLevelUpdateRoute;
private initLogLevelGetRoute;
private initStatusRoute;
private initInitRoute;
getMetadata(): {
runtime: string;
runtime_version: string;
group_id: string | undefined;
artifact_id: string | undefined;
plugin_type: string | undefined;
plugin_version: string | undefined;
plugin_build: string | undefined;
dependencies: any;
};
private initMetadataRoute;
}