import { EvaEndpoint } from "./endpoint.js"; import { IEvaServiceDefinition } from "@springtree/eva-services-core"; import { Options } from "ky"; /** * Constructor arguments for EVA service * * @export * @interface IEvaServiceArguments */ export interface IEvaServiceArguments { /** * Optional flag to disable interceptors * This is an advanced feature that will more then likely never be set */ disableInterceptors?: boolean; } /** * The additional options to use for an EVA Service call * These can be used to override any defaults * * @export * @interface IEvaServiceCallOptions */ export interface IEvaServiceCallOptions { /** * Used to override the default service timeout */ timeout?: number; /** * The authentication token to use for this service call */ authenticationToken?: string; /** * A specific application token to use for this service call * By default the current application token from the settings will be used. * The setting will be updated whenever a new EVA-App-Token is returned. */ applicationToken?: string; /** * Each service call is provided with a unique context. * You can provide a value if you do not want an auto-generated one */ serviceContext?: string; /** * If an EVA Service is called in a chain this identifier can be added to * to the headers to identify the collection of services */ chainContext?: string; /** * If the call was made using en EvaContext instance this will contain the * unique instance identifier. Can not be overridden by the caller. */ contextInstanceID?: string; /** * Can be used by clients to set the current station ID header value * This should always reflect the ID from the currently used station from * the `ListStationsForOrganization` response. Added for legal reasons * Is usually set using the service settings but can be overridden per call * using this setting */ currentStationID?: string; /** * Can be used to set the `EVA-Requested-OrganizationUnitID` header. * This is used to select a specific organization unit when making calls without * a specific user token by ID. */ requestedOrganizationUnitID?: string; /** * Can be used to set the `EVA-Requested-OrganizationUnit-Query` header. * This is used to select a specific organization unit when making calls without * a specific user token using an exact match query on name and backend id. */ requestedOrganizationUnitQuery?: { Name: string; BackendID: string; }; /** * Can be used to completely omit the requested organization unit id header. * This is useful when making calls that should not be tied to a specific * organization unit while still wanting to use the core setting to set a default */ omitOrganizationUnitId?: boolean; /** * Can be used to set the `EVA-IDs-Mode` header which can be used to let the EVA * backend to use external identifiers instead of EVA identifiers for * things like products. * Is usually set using the service settings but can be overridden per call * using this setting */ backendIdMode?: string; /** * Used to populate the `EVA-IDs-BackendSystemID` header which can be sent * along with the `EVA-IDs-Mode` header to enable response metadata to help * with mapping identifiers between EVA and an external system */ backendIdSystemID?: string; /** * Used to populate the `EVA-Elevation-Token` header which can be used to * validate calls that require an additional authorization check from another * user */ elevationToken?: string; /** * Used to populate the `EVA-Trust-Token` header which is used when logging in with JWT tokens and a local watchtower * to elevate the trust level of logged in users. Should be used with SvcLogin calls * * @type {string} */ trustToken?: string; /** * Adds custom headers to the request */ headers?: { [key: string]: string; }; /** * Used to pass an outside request abort signal to the service request. * If supplied the `.abort()` method will no longer do function as the external * abort signalr will be used instead. */ abortSignal?: AbortSignal; /** * Used to set the `Accept-Language` header per call. * Defaults to the springtree/eva-sdk-core-settings language setting if not provided. * Language is a locale such as 'nl_NL' or 'en_US' */ language?: string; } /** * A service error response for the EVA backend * * @export * @interface IEvaServiceError */ export interface IEvaServiceError { status: number; data: unknown; message: string; } /** * Helper method to get the JSON body from a fetch response * * @param {Response} response * @returns {(Promise)} */ export declare const safeGetResponseJSON: (response: Response) => Promise; /** * Helper method to create a stable md5 hash for a JSON object * * @param {Record} jsonData * @returns {string} */ export declare const safeStableJSONHash: (jsonData?: Record) => string; /** * The EVA Service implementation * * @export * @class EvaService * @template REQ * @template RES */ export declare class EvaService { data: SVC; readonly endpoint: EvaEndpoint; /** * The name of the EVA Service being called * * @private */ private serviceName; /** * The current abort controller for the fetch request * * @private */ private abortController?; /** * The applied default options for the call * * @private */ private defaultOptions; /** * Stops the current service call */ abort(): void; /** * The fetch response object */ fetchResponse?: Response; /** * Creates an instance of EvaService * pre-configured with default EVA headers and options * * @param {SVC} data The service definition that will be used to make the call and receive the result * @param {EvaEndpoint} endpoint The EVA endpoint to use for the call * @param {IEvaServiceArguments} [args] Optional arguments for instantiating the service call */ constructor(data: SVC, endpoint: EvaEndpoint, args?: IEvaServiceArguments); /** * Sets the request payload * * @param {SVC['request']} request */ setRequest(request: SVC["request"]): void; /** * Convenience method to create a Fetch API request for manually calling a * service. This can be useful for SSR implementations. * * NOTE: Manual fetch calls will not log EVA warnings or check for content errors * * See: https://springtreesolutions.github.io/eva-sdk-repo/#/services/endpoint?id=eva-warning * See: https://springtreesolutions.github.io/eva-sdk-repo/#/services/endpoint?id=eva-response-error * * @param {IEvaServiceCallOptions} [options] */ buildFetchRequest(options?: IEvaServiceCallOptions): Request; /** * Call the EVA backend service with the current value of `this.data.request` * as the payload. The response will be set on `this.data.response` and the * full response will be available on `this.fullResponse`. * Unless otherwise configured in the constructor all active interceptors will * be used on the request and response as required. * * @returns {Promise} */ call(options?: IEvaServiceCallOptions): Promise; /** * Helper method to prepare the Fetch options for a service call */ prepareCallOptions(options?: IEvaServiceCallOptions): { requestUrl: string; config: Options; }; } //# sourceMappingURL=service.d.ts.map