Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sources params to ctx #1962

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading