UNPKG

1.83 kBJavaScriptView Raw
1/***************************************************************************************
2 * (c) 2017 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 ****************************************************************************************/
12
13const request = require('request-promise-native');
14const getReactorHeaders = require('./getReactorHeaders');
15const handleResponseError = require('./handleResponseError');
16const logVerboseHeader = require('./logVerboseHeader');
17
18module.exports = async (
19 envConfig,
20 accessToken,
21 extensionPackageManifest,
22 argv
23) => {
24 const options = {
25 method: 'GET',
26 url: `${envConfig.extensionPackages}`,
27 qs: {
28 'page[size]': 1,
29 'page[number]': 1,
30 'filter[name]': `EQ ${extensionPackageManifest.name}`,
31 'filter[platform]': `EQ ${extensionPackageManifest.platform}`,
32 'filter[availability]': 'EQ development'
33 },
34 headers: getReactorHeaders(accessToken),
35 transform: JSON.parse
36 };
37
38 if (argv.verbose) {
39 logVerboseHeader('Retrieving extension package from server');
40 }
41
42 let body;
43
44 try {
45 body = await request(options);
46 } catch (error) {
47 handleResponseError(error, 'Error detecting whether extension package exists on server.');
48 }
49
50 return body.data.length ? body.data[0] : null;
51};