UNPKG

1.07 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const superagent = require("superagent");
4exports.DEFAULT_HOST = 'https://api.ionicjs.com';
5function extractDetails(ctx) {
6 const host = ctx.env.get('IONIC_API_HOST', exports.DEFAULT_HOST);
7 const token = ctx.env.require('IONIC_AUTH_TOKEN');
8 return { host, token };
9}
10exports.extractDetails = extractDetails;
11async function getAndroidCredentials(ctx, appId, profileTag) {
12 const { host, token } = extractDetails(ctx);
13 const url = `${host}/apps/${appId}/profiles/${profileTag}/credentials/android`;
14 const req = superagent.get(url).set('Authorization', `Bearer ${token}`);
15 return tryRequest(ctx, req, `Error retrieving app signing credentials.`);
16}
17exports.getAndroidCredentials = getAndroidCredentials;
18async function tryRequest(ctx, req, errorMsg) {
19 try {
20 const res = await req;
21 return res.body;
22 }
23 catch (e) {
24 ctx.serverlog.error(e);
25 if (errorMsg) {
26 ctx.userlog.error(errorMsg);
27 }
28 throw e;
29 }
30}