Move sending intern requests from client to server

Summary: This diff moves send intern request from the browser to the server. The reason to make this change is that making such requests from a browser environment causes CORS restrictions to kick in.

Reviewed By: nikoant

Differential Revision: D32835449

fbshipit-source-id: e8e92e51ca963aa50b3c859bb61c2381171e85ae
This commit is contained in:
Michel Weststrate
2021-12-08 04:25:28 -08:00
committed by Facebook GitHub Bot
parent ad4a55f263
commit 943d535e86
18 changed files with 180 additions and 96 deletions

View File

@@ -42,7 +42,6 @@ export {
getStringFromErrorLike,
getErrorFromErrorLike,
} from './utils/errors';
export * from './user-session';
export * from './GK';
export * from './clientUtils';
export * from './settings';

View File

@@ -191,6 +191,39 @@ export type FlipperServerCommands = {
name: string,
) => Promise<FlipperDoctor.HealthcheckResult>;
'open-file': (path: string) => Promise<void>;
'intern-graph-post': (
endpoint: string,
formFields: Record<string, any>,
fileFields: Record<string, GraphFileUpload>,
options: {
timeout?: number;
internGraphUrl?: string;
},
) => Promise<GraphResponse>;
'intern-graph-get': (
endpoint: string,
params: Record<string, any>,
options: {
timeout?: number;
internGraphUrl?: string;
},
) => Promise<GraphResponse>;
'intern-upload-scribe-logs': (
messages: {category: string; message: string}[],
) => Promise<void>;
};
export type GraphResponse = {
status: number;
data: any;
headers: Record<string, any>;
};
export type GraphFileUpload = {
path?: string;
contents?: string;
filename?: string;
contentType?: string;
};
/**

View File

@@ -1,41 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/**
* APIs need to integration with Facebook services.
*/
export type UserSessionManager = {
internGraphPOSTAPIRequest: typeof internGraphPOSTAPIRequest;
};
let instance: UserSessionManager | undefined = undefined;
function getInstance(): UserSessionManager {
if (!instance) {
throw new Error('UserSessionManager not available or implemented');
}
return instance;
}
export function setUserSessionManagerInstance(i: UserSessionManager) {
instance = i;
}
export async function internGraphPOSTAPIRequest(
_endpoint: string,
_formFields: {
[key: string]: any;
} = {},
_internGraphUrl?: string,
_timeout?: number,
): Promise<any> {
// eslint-disable-next-line
return getInstance().internGraphPOSTAPIRequest.apply(null, arguments as any);
}