Chrome Web Store API Client
cwa is a simple Deno library for uploading & publishing your extensions and
themes to the
Chrome Web Store.
If youâre looking for an easy-to-use command-line version of this, check out
cwc.
This draws inspiration heavily from Andrewâs fantastic
chrome-webstore-upload
library (originally written for Node.js) and improves on it by offering a few
more API methods.
Usage
Youâll need Google API client ID, client secret and a refresh token. Learn how to get them.
Once you have them, can you start using the client in your Deno project like this â
import { APIClient } from "https://deno.land/x/cwa@v1.0.0/mod.ts";
const apiClient = new APIClient({
// Note: These values are representative and don't actually work.
id: "akjpoenbamadeeboawhkeljfvhngklfi",
clientId:
"618272284469-5hba9n4sc2hgommup53osq7s7f0k6bp6.apps.googleusercontent.com",
clientSecret: "VwE91L-3_NWEcSlZfPJk6721",
refreshToken:
"1//0dbz-Pw36crhMCgYIPORTGB1SNwF-M2IrETpgP8ebvFCmFUuUXQRxxxIOuKiXE_ZvCLM7EbrHWah3dPOGOUfiBBuzwxjhplWISMB",
});API
uploadNew(stream, token?)
Upload a new item to the Web Store. Use this only when youâre uploading your extension or theme for the very first time.
import { readableStreamFromReader } from "https://deno.land/std@0.100.0/io/mod.ts";
const filePath = "/path/to/your/new/extension.zip";
const fileReader = await Deno.open(filePath, { read: true });
const fileStream = readableStreamFromReader(fileReader);
const uploadResult = await apiClient.uploadNew(fileStream);
console.log(uploadResult);
// {
// "kind": "chromewebstore#item",
// "id": "...",
// "uploadState": "SUCCESS"
// }uploadExisting(stream, token?)
Upload a new version of an existing item to the Web Store. Use this when youâre uploading a newer version of an existing extension or theme.
import { readableStreamFromReader } from "https://deno.land/std@0.104.0/io/mod.ts";
const filePath = "/path/to/your/existing/extension.zip";
const fileReader = await Deno.open(filePath, { read: true });
const fileStream = readableStreamFromReader(fileReader);
const uploadResult = await apiClient.uploadExisting(fileStream);
console.log(uploadResult);
// {
// "kind": "chromewebstore#item",
// "id": "...",
// "uploadState": "SUCCESS"
// }publish(target, token?)
Publish the latest uploaded version of an existing item to the Web Store. By default, this publishes to everyone.
const publishResult = await apiClient.publish();
console.log(publishResult);
// {
// "kind": "chromewebstore#item",
// "item_id": "...",
// "status": ["OK"],
// "statusDetail": ["..."]
// }If youâd like to publish only to your trusted testers, you can set the first
argument to the publish() call.
const publishResult = await apiClient.publish("trustedTesters");
console.log(publishResult);
// {
// "kind": "chromewebstore#item",
// "item_id": "...",
// "status": ["OK"],
// "statusDetail": ["..."]
// }checkUploadStatus(token?)
Find out the upload status of your item on the Chrome Store.
const uploadStatus = await apiClient.checkUploadStatus();
console.log(uploadStatus);
// {
// "kind": "chromewebstore#item",
// "id": "...",
// "uploadState": "FAILURE",
// "itemError": [{
// "error_code": "...",
// "error_detail": "..."
// }]
// }fetchToken()
Fetches an access token; you wonât need it most of the time, but it is available if you need it.
const accessToken = await apiClient.fetchToken();
console.log(accessToken);
// "..."Developer Notes
1.Useful deno shorthand scripts and Git hooks are set up with
velociraptor. You can view a list
of the commands using â
vr- To debug this module or to get detailed logs, set the environment variable
DEBUGtocwa:*. For example, if youâre a *Nix user, use the command â
DEBUG=cwa:* vr run testMake a release
- Create a tag.
git tag v0.0.0 -s -a -m "Release v0.0.0"- Push the tag to Github.
git push --tags- Find the newly created tag on the Tags page and Edit the release to include the changelog.
- Publish the release. This triggers the webhook that auto-published the package to https://deno.land/x/cwa đĽł
License
The code in this project is released under the MIT License.