@appzung/react-native-code-push
Version:
React Native plugin for the CodePush service
34 lines (33 loc) • 1.1 kB
JavaScript
import { LogLevel } from "../../enums/LogLevel.enum.js";
import { version } from "../version.js";
import { fetchRetry } from "./fetchRetry.js";
import { log } from "./log.js";
export const requestFetchAdapter = {
async request(method, url, requestBody) {
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-CodePush-Plugin-Name': '@appzung/react-native-code-push',
'X-CodePush-Plugin-Version': version
};
if (requestBody && typeof requestBody === 'object') {
requestBody = JSON.stringify(requestBody);
}
const requestId = Math.round(Math.random() * 10000);
log(LogLevel.DEBUG, `[${requestId}] Will fetch ${method} ${url}`);
const response = await fetchRetry(url, {
method,
headers,
body: requestBody
});
const statusCode = response.status;
log(LogLevel.DEBUG, `[${requestId}] Done fetching with status code ${statusCode}`);
const body = await response.text();
return {
statusCode,
body
};
}
};
//# sourceMappingURL=requestFetchAdapter.js.map
;