eas-cli
Version:
EAS command line tool
105 lines (104 loc) • 3.32 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEASUpdateURL = exports.getExpoWebsiteBaseUrl = exports.getExpoApiBaseUrl = exports.ApiV2Client = void 0;
const tslib_1 = require("tslib");
const ApiV2Error_1 = require("./ApiV2Error");
const fetch_1 = tslib_1.__importStar(require("./fetch"));
class ApiV2Client {
authInfo;
constructor(authInfo) {
this.authInfo = authInfo;
}
async putAsync(path, options) {
return await this.requestAsync(path, { method: 'PUT', body: JSON.stringify(options.body) });
}
async postAsync(path, options) {
return await this.requestAsync(path, { method: 'POST', body: JSON.stringify(options.body) });
}
async deleteAsync(path) {
return await this.requestAsync(path, { method: 'DELETE' });
}
async getAsync(path) {
return await this.requestAsync(path, { method: 'GET' });
}
getAuthHeaders() {
const token = this.authInfo.accessToken;
if (token) {
return { authorization: `Bearer ${token}` };
}
const sessionSecret = this.authInfo.sessionSecret;
if (sessionSecret) {
return { 'expo-session': sessionSecret };
}
return {};
}
async requestAsync(path, options) {
try {
const response = await (0, fetch_1.default)(`${getExpoApiBaseUrl()}/v2/${path}`, {
...options,
headers: {
'Content-Type': 'application/json',
...this.getAuthHeaders(),
},
});
return await response.json();
}
catch (err) {
await ApiV2Client.handleApiErrorAsync(err);
}
}
static async handleApiErrorAsync(err) {
if (err instanceof fetch_1.RequestError) {
let result;
try {
result = (await err.response.json());
}
catch {
throw new Error(`Malformed api response: ${await err.response.text()}`);
}
if (result.errors?.length) {
throw new ApiV2Error_1.ApiV2Error(result.errors[0]);
}
}
else {
throw err;
}
}
}
exports.ApiV2Client = ApiV2Client;
function getExpoApiBaseUrl() {
if (process.env.EXPO_STAGING) {
return `https://staging-api.expo.dev`;
}
else if (process.env.EXPO_LOCAL) {
return `http://127.0.0.1:3000`;
}
else {
return `https://api.expo.dev`;
}
}
exports.getExpoApiBaseUrl = getExpoApiBaseUrl;
function getExpoWebsiteBaseUrl() {
if (process.env.EXPO_STAGING) {
return `https://staging.expo.dev`;
}
else if (process.env.EXPO_LOCAL) {
return `http://expo.test`;
}
else {
return `https://expo.dev`;
}
}
exports.getExpoWebsiteBaseUrl = getExpoWebsiteBaseUrl;
function getEASUpdateURL(projectId) {
if (process.env.EXPO_STAGING) {
return new URL(projectId, `https://staging-u.expo.dev`).href;
}
else if (process.env.EXPO_LOCAL) {
return new URL(`expo-updates/${projectId}`, `http://127.0.0.1:3000`).href;
}
else {
return new URL(projectId, `https://u.expo.dev`).href;
}
}
exports.getEASUpdateURL = getEASUpdateURL;
;