// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Chrome Web Store API Client for Deno * ==================================== * * The Chrome Web Store API provides access to data about apps and extensions, as well as developer tools for managing them. * * Docs: https://developer.chrome.com/docs/webstore/api * Source: https://googleapis.deno.dev/v1/chromewebstore:v2.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; /** * The Chrome Web Store API provides access to data about apps and extensions, * as well as developer tools for managing them. */ export class ChromeWebStore { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://chromewebstore.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Upload a new package to an existing item. * * @param name Required. Name of the item to upload the new package to in the form `publishers/{publisherId}/items/{itemId}` */ async mediaUpload(name: string, req: UploadItemPackageRequest): Promise { const url = new URL(`${this.#baseUrl}v2/${ name }:upload`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as UploadItemPackageResponse; } /** * Cancel the current active submission of an item if present. This can be * used to cancel the review of a pending submission. * * @param name Required. Name of the item to cancel the submission of in the form `publishers/{publisherId}/items/{itemId}` */ async publishersItemsCancelSubmission(name: string, req: CancelSubmissionRequest): Promise { const url = new URL(`${this.#baseUrl}v2/${ name }:cancelSubmission`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as CancelSubmissionResponse; } /** * Fetch the status of an item. * * @param name Required. Name of the item to retrieve the status of in the form `publishers/{publisherId}/items/{itemId}` */ async publishersItemsFetchStatus(name: string): Promise { const url = new URL(`${this.#baseUrl}v2/${ name }:fetchStatus`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as FetchItemStatusResponse; } /** * Submit the item to be published in the store. The item will be submitted * for review unless `skip_review` is set to true, or the item is staged from * a previous submission with `publish_type` set to `STAGED_PUBLISH`. * * @param name Required. Name of the item in the form `publishers/{publisherId}/items/{itemId}` */ async publishersItemsPublish(name: string, req: PublishItemRequest): Promise { const url = new URL(`${this.#baseUrl}v2/${ name }:publish`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as PublishItemResponse; } /** * Set a higher target deploy percentage for the item's published revision. * This will be updated without the item being submitted for review. This is * only available to items with over 10,000 seven-day active users. * * @param name Required. Name of the item to update the published revision of in the form `publishers/{publisherId}/items/{itemId}` */ async publishersItemsSetPublishedDeployPercentage(name: string, req: SetPublishedDeployPercentageRequest): Promise { const url = new URL(`${this.#baseUrl}v2/${ name }:setPublishedDeployPercentage`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as SetPublishedDeployPercentageResponse; } } /** * Request message for CancelSubmission. */ export interface CancelSubmissionRequest { } /** * Response message for `CancelSubmission`. */ export interface CancelSubmissionResponse { } /** * Deployment information for a specific release channel. Used in requests to * update deployment parameters. */ export interface DeployInfo { /** * Required. The current deploy percentage for the release channel * (nonnegative number between 0 and 100). */ deployPercentage?: number; } /** * Deployment information for a specific release channel */ export interface DistributionChannel { /** * The extension version provided in the manifest of the uploaded package. */ crxVersion?: string; /** * The current deploy percentage for the release channel (nonnegative number * between 0 and 100). */ deployPercentage?: number; } /** * Response message for `FetchItemStatus`. */ export interface FetchItemStatusResponse { /** * Output only. The ID of the item. */ readonly itemId?: string; /** * Output only. The state of the last async upload for an item. Only set when * there has been an async upload for the item in the past 24 hours. */ readonly lastAsyncUploadState?: | "UPLOAD_STATE_UNSPECIFIED" | "SUCCEEDED" | "IN_PROGRESS" | "FAILED" | "NOT_FOUND"; /** * The name of the requested item. */ name?: string; /** * The public key of the item, which may be generated by the store. */ publicKey?: string; /** * Output only. Status of the current published revision of the item. Will be * unset if the item is not published. */ readonly publishedItemRevisionStatus?: ItemRevisionStatus; /** * Status of the item revision submitted to be published. Will be unset if * the item has not been submitted for publishing since the last successful * publish. */ submittedItemRevisionStatus?: ItemRevisionStatus; /** * If true, the item has been taken down for a policy violation. Check the * developer dashboard for details. */ takenDown?: boolean; /** * If true, the item has been warned for a policy violation and will be taken * down if not resolved. Check the developer dashboard for details. */ warned?: boolean; } /** * Details on the status of an item revision. */ export interface ItemRevisionStatus { /** * Details on the package of the item */ distributionChannels?: DistributionChannel[]; /** * Output only. Current state of the item */ readonly state?: | "ITEM_STATE_UNSPECIFIED" | "PENDING_REVIEW" | "STAGED" | "PUBLISHED" | "PUBLISHED_TO_TESTERS" | "REJECTED" | "CANCELLED"; } /** * Request message for PublishItem. */ export interface PublishItemRequest { /** * Optional. Additional deploy information including the desired initial * percentage rollout. Defaults to the current value saved in the developer * dashboard if unset. */ deployInfos?: DeployInfo[]; /** * Optional. Use this to control if the item is published immediately on * approval or staged for publishing in the future. Defaults to * `DEFAULT_PUBLISH` if unset. */ publishType?: | "PUBLISH_TYPE_UNSPECIFIED" | "DEFAULT_PUBLISH" | "STAGED_PUBLISH"; /** * Optional. Whether to attempt to skip item review. The API will validate if * the item qualifies and return a validation error if the item requires * review. Defaults to `false` if unset. */ skipReview?: boolean; } /** * Response message for `PublishItem`. */ export interface PublishItemResponse { /** * Output only. The ID of the item. */ readonly itemId?: string; /** * The name of the item that was submitted */ name?: string; /** * Output only. The current state of the submission. */ readonly state?: | "ITEM_STATE_UNSPECIFIED" | "PENDING_REVIEW" | "STAGED" | "PUBLISHED" | "PUBLISHED_TO_TESTERS" | "REJECTED" | "CANCELLED"; } /** * Request message for SetPublishedDeployPercentage. */ export interface SetPublishedDeployPercentageRequest { /** * Required. Unscaled percentage value for the publised revision (nonnegative * number between 0 and 100). It must be larger than the existing target * percentage. */ deployPercentage?: number; } /** * Response message for `SetPublishedDeployPercentage`. */ export interface SetPublishedDeployPercentageResponse { } /** * Request message for UploadItemPackage. */ export interface UploadItemPackageRequest { } /** * Response message for `UploadItemPackage`. */ export interface UploadItemPackageResponse { /** * The extension version provided in the manifest of the uploaded package. * This will not be set if the upload is still in progress (`upload_state` is * `UPLOAD_IN_PROGRESS`). */ crxVersion?: string; /** * Output only. The ID of the item the package was uploaded to. */ readonly itemId?: string; /** * The name of the item the package was uploaded to. */ name?: string; /** * Output only. The state of the upload. If `upload_state` is * `UPLOAD_IN_PROGRESS`, you can poll for updates using the fetchStatus * method. */ readonly uploadState?: | "UPLOAD_STATE_UNSPECIFIED" | "SUCCEEDED" | "IN_PROGRESS" | "FAILED" | "NOT_FOUND"; }