Skip to content

Deno library for uploading & publishing extensions and themes to the Chrome Web Store

License

Notifications You must be signed in to change notification settings

getoslash/chrome-webstore-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chrome Web Store API Client

deno version GitHub Release Deno.land Release codecov Open in Visual Studio Code

cwa is a easy-to-use 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
  1. To debug this module or to get detailed logs, set the environment variable DEBUG to cwa:*. For example, if you're a *Nix user, use the command —
DEBUG=cwa:* vr run test

Make a release

  1. Create a tag.
git tag v0.0.0 -s -a -m "Release v0.0.0"
  1. Push the tag to Github.
git push --tags
  1. Find the newly created tag on the Tags page and Edit the release to include the changelog.
  2. 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.

FOSSA Status

About

Deno library for uploading & publishing extensions and themes to the Chrome Web Store

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published