typed-chrome-webstore-api
Advanced tools
Comparing version 0.2.2 to 0.3.2
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -10,16 +13,15 @@ if (mod && mod.__esModule) return mod; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const got = __importStar(require("got")); | ||
const axios_1 = __importDefault(require("axios")); | ||
const consts = __importStar(require("./consts")); | ||
async function fetchToken(clientId, clientSecret, refreshToken) { | ||
const result = await got.post(consts.urls.refreshTokenPost(), { | ||
body: { | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
refresh_token: refreshToken, | ||
grant_type: 'refresh_token', | ||
}, | ||
json: true, | ||
const result = await axios_1.default.post(consts.urls.refreshTokenPost(), { | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
refresh_token: refreshToken, | ||
grant_type: 'refresh_token', | ||
}, { | ||
responseType: 'json', | ||
}); | ||
return result.body.access_token; | ||
return result.data.access_token; | ||
} | ||
exports.fetchToken = fetchToken; |
@@ -6,11 +6,7 @@ "use strict"; | ||
*/ | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const got = __importStar(require("got")); | ||
const axios_1 = __importDefault(require("axios")); | ||
var DownloadCrx; | ||
@@ -70,16 +66,9 @@ (function (DownloadCrx) { | ||
async function downloadCrx(extensionId, prodVersion = '72.0.3626.121', acceptFormat = [CrxAcceptFormat.CRX2, CrxAcceptFormat.CRX3], platform) { | ||
return new Promise((resolve, reject) => { | ||
got | ||
.stream(getUrl(extensionId, prodVersion, acceptFormat, platform), { throwHttpErrors: false }) | ||
.once('response', response => { | ||
if (response.statusCode === 200) { | ||
resolve(response); | ||
} | ||
else { | ||
reject(new Error(`Server answered with ${response.statusCode} ${response.statusMessage}`)); | ||
} | ||
}); | ||
const response = await axios_1.default.get(getUrl(extensionId, prodVersion, acceptFormat, platform), { | ||
responseType: 'stream', | ||
validateStatus: status => status === 200 | ||
}); | ||
return response.data; | ||
} | ||
DownloadCrx.downloadCrx = downloadCrx; | ||
})(DownloadCrx = exports.DownloadCrx || (exports.DownloadCrx = {})); |
/// <reference types="node" /> | ||
import { AxiosInstance, AxiosRequestConfig } from 'axios'; | ||
import { Readable } from 'stream'; | ||
@@ -6,3 +7,4 @@ import * as consts from './consts'; | ||
protected _token: string; | ||
constructor(token: string); | ||
protected readonly _client: AxiosInstance; | ||
constructor(token: string, axiosConfig?: AxiosRequestConfig); | ||
setToken(token: string): void; | ||
@@ -9,0 +11,0 @@ upload(readStream: Buffer | Readable, appId?: string): Promise<consts.IWebstoreResource>; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -10,8 +13,9 @@ if (mod && mod.__esModule) return mod; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const got = __importStar(require("got")); | ||
const axios_1 = __importDefault(require("axios")); | ||
const consts = __importStar(require("./consts")); | ||
// noinspection JSUnusedGlobalSymbols | ||
class WebstoreApi { | ||
constructor(token) { | ||
constructor(token, axiosConfig) { | ||
this._token = token; | ||
this._client = axios_1.default.create(axiosConfig); | ||
} | ||
@@ -25,28 +29,30 @@ // noinspection JSUnusedGlobalSymbols | ||
const url = appId ? consts.urls.uploadPut(appId) : consts.urls.uploadPost(); | ||
const action = appId ? got.put.bind(got) : got.post.bind(got); | ||
const result = await action(url, { | ||
const result = await this._client.request({ | ||
url, | ||
method: appId ? 'PUT' : 'POST', | ||
headers: this.getHeaders(), | ||
body: readStream | ||
responseType: 'json', | ||
data: readStream | ||
}); | ||
return JSON.parse(result.body); | ||
return result.data; | ||
} | ||
// noinspection JSUnusedGlobalSymbols | ||
async getUpload(appId) { | ||
const result = await got.get(consts.urls.uploadGet(appId), { | ||
const result = await this._client.get(consts.urls.uploadGet(appId), { | ||
headers: this.getHeaders(), | ||
json: true, | ||
responseType: 'json', | ||
}); | ||
return result.body; | ||
return result.data; | ||
} | ||
// noinspection JSUnusedGlobalSymbols | ||
async publish(appId, target = consts.PublishTarget.DEFAULT) { | ||
const result = await got.post(consts.urls.publishPost(appId, target), { | ||
headers: this.getHeaders(), | ||
json: true, | ||
const result = await this._client.post(consts.urls.publishPost(appId, target), undefined, { | ||
responseType: 'json', | ||
headers: this.getHeaders() | ||
}); | ||
return result.body; | ||
return result.data; | ||
} | ||
getHeaders() { | ||
return { | ||
Authorization: `Bearer ${this._token}`, | ||
'Authorization': `Bearer ${this._token}`, | ||
'x-goog-api-version': '2', | ||
@@ -53,0 +59,0 @@ }; |
{ | ||
"name": "typed-chrome-webstore-api", | ||
"version": "0.2.2", | ||
"version": "0.3.2", | ||
"description": "Typed Chrome Webstore API to upload/publish extensions", | ||
@@ -31,6 +31,7 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"got": "^9.6.0" | ||
"axios": "^0.18.0" | ||
}, | ||
"devDependencies": { | ||
"@types/got": "^9.4.1", | ||
"@types/node": "^11.11.3", | ||
"@types/axios": "^0.14.0", | ||
"prettier": "^1.16.3", | ||
@@ -37,0 +38,0 @@ "tslint": "^5.12.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19413
6
364
+ Addedaxios@^0.18.0
+ Addedaxios@0.18.1(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
+ Addedis-buffer@2.0.5(transitive)
- Removedgot@^9.6.0
- Removed@sindresorhus/is@0.14.0(transitive)
- Removed@szmarczak/http-timer@1.1.2(transitive)
- Removedcacheable-request@6.1.0(transitive)
- Removedclone-response@1.0.3(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removeddefer-to-connect@1.1.3(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedget-stream@4.1.05.2.0(transitive)
- Removedgot@9.6.0(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedjson-buffer@3.0.0(transitive)
- Removedkeyv@3.1.0(transitive)
- Removedlowercase-keys@1.0.12.0.0(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removednormalize-url@4.5.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-cancelable@1.1.0(transitive)
- Removedprepend-http@2.0.0(transitive)
- Removedpump@3.0.2(transitive)
- Removedresponselike@1.0.2(transitive)
- Removedto-readable-stream@1.0.0(transitive)
- Removedurl-parse-lax@3.0.0(transitive)
- Removedwrappy@1.0.2(transitive)