Skip to content

Commit

Permalink
Add sources params to ctx (#1962)
Browse files Browse the repository at this point in the history
  • Loading branch information
melikhov-dev authored Dec 19, 2024
1 parent 39b8a8f commit 183089f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/@types/nodekit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export interface SharedAppContextParams {
) => Promise<ResolveEntryByLinkComponentResponse>;
};

sources: {
reqBody: Request['body'];
};

getAppLayoutSettings: (req: Request, res: Response, name?: string) => AppLayoutSettings;
landingPageSettings?: LandingPageSettings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,6 @@ export class DataFetcher {
userTargetUriUi = sourceConfig.uiEndpoint + croppedTargetUri;
}

if (sourceConfig.adapter) {
return sourceConfig.adapter({
targetUri: croppedTargetUri,
sourceName,
req,
ctx,
});
}

if (sourceConfig.adapterWithContext) {
return sourceConfig.adapterWithContext({
targetUri: croppedTargetUri,
Expand All @@ -675,7 +666,9 @@ export class DataFetcher {
if (sourceType === 'charts') {
const incomingHeader = originalReqHeaders.xChartsFetcherVia || '';

const scriptName = req.body.params ? '/editor/' + req.body.params.name : req.body.path;
const {reqBody} = ctx.get('sources');

const scriptName = reqBody.params ? '/editor/' + reqBody.params.name : reqBody.path;

if (incomingHeader && !Array.isArray(incomingHeader)) {
const circular = incomingHeader.split(',').some((someScriptName) => {
Expand Down Expand Up @@ -733,7 +726,7 @@ export class DataFetcher {

const sourceAuthorizationHeaders = getSourceAuthorizationHeaders({
req,
chartsEngine,
ctx,
sourceConfig,
subrequestHeaders,
});
Expand Down
15 changes: 0 additions & 15 deletions src/server/components/charts-engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ export type SourceConfig = {
preprocess?: (url: string) => string;
allowedMethods?: ('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE')[];

/**
* @deprecated
**/
adapter?: ({
targetUri,
sourceName,
req,
ctx,
}: {
targetUri: string;
sourceName: string;
req: Request;
ctx: AppContext;
}) => unknown;

adapterWithContext?: ({
targetUri,
sourceName,
Expand Down
6 changes: 3 additions & 3 deletions src/server/registry/units/common/functions-map.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type {Request, Response} from '@gravity-ui/expresskit';
import type {AppContext} from '@gravity-ui/nodekit';

import type {Palette} from '../../../../shared/constants/colors';
import type {GetEntryByKeyResponse} from '../../../../shared/schema';
import {makeFunctionTemplate} from '../../../../shared/utils/makeFunctionTemplate';
import type {ChartsEngine} from '../../../components/charts-engine';
import type {SourceConfig} from '../../../components/charts-engine/types';

export const commonFunctionsMap = {
getAvailablePalettesMap: makeFunctionTemplate<() => Record<string, Palette>>(),
getSourceAuthorizationHeaders:
makeFunctionTemplate<
(args: {
chartsEngine: ChartsEngine;
req: Request;
req?: Request;
ctx: AppContext;
sourceConfig: SourceConfig;
subrequestHeaders: Record<string, string>;
}) => Record<string, string>
Expand Down

0 comments on commit 183089f

Please sign in to comment.