Skip to content

Commit

Permalink
feat: Support chrome's new deployPercentage and reviewExemption options
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Aug 22, 2024
1 parent 8e83b44 commit cb529e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/chrome/chrome-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { createFetch } from 'ofetch';
import { FormData } from 'formdata-node';
import { fileFromPath } from 'formdata-node/file-from-path';
import consola from 'consola';
import { fetch } from '../utils/fetch';

export interface CwsApiOptions {
Expand Down Expand Up @@ -61,12 +59,24 @@ export class CwsApi {
extensionId: string;
publishTarget: 'default' | 'trustedTesters';
token: CwsTokenDetails;
deployPercentage?: number;
reviewExemption?: boolean;
}) {
const Authorization = await this.getAuthHeader(params.token);

const endpoint = this.publishEndpoint(params.extensionId);
if (params.publishTarget)
endpoint.searchParams.append('publishTarget', params.publishTarget);
if (params.deployPercentage != null)
endpoint.searchParams.set(
'deployPercentage',
String(params.deployPercentage),
);
if (params.reviewExemption != null)
endpoint.searchParams.set(
'reviewExemption',
String(params.reviewExemption),
);

await fetch(endpoint.href, {
method: 'POST',
Expand Down
2 changes: 2 additions & 0 deletions src/chrome/chrome-web-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const ChromeWebStoreOptions = z.object({
clientSecret: z.string().min(1),
refreshToken: z.string().min(1),
publishTarget: z.enum(['default', 'trustedTesters']).default('default'),
deployPercentage: z.number().int().min(1).max(100).optional(),
reviewExemption: z.boolean().default(false),
skipSubmitReview: z.boolean().default(false),
});
export type ChromeWebStoreOptions = z.infer<typeof ChromeWebStoreOptions>;
Expand Down
13 changes: 13 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export function resolveConfig(
config.chrome?.publishTarget ??
stringEnv('CHROME_PUBLISH_TARGET') ??
'default',
deployPercentage:
config.chrome?.deployPercentage ??
intEnv('CHROME_DEPLOY_PERCENTAGE'),
reviewExemption:
config.chrome?.reviewExemption ??
booleanEnv('CHROME_REVIEW_EXEMPTION') ??
false,
skipSubmitReview:
config.chrome?.skipSubmitReview ??
booleanEnv('CHROME_SKIP_SUBMIT_REVIEW') ??
Expand Down Expand Up @@ -109,6 +116,10 @@ function stringEnv<T extends string = string>(
return !process.env[name] ? undefined : (process.env[name] as T);
}

function intEnv(name: keyof CustomEnv): number | undefined {
return !process.env[name] ? undefined : parseInt(process.env[name]!);
}

export const InlineConfig = z.object({
/**
* When true, just check authentication, don't upload any zip files or submit any updates.
Expand Down Expand Up @@ -142,9 +153,11 @@ interface CustomEnv {

CHROME_CLIENT_ID: string | undefined;
CHROME_CLIENT_SECRET: string | undefined;
CHROME_DEPLOY_PERCENTAGE: string | undefined;
CHROME_EXTENSION_ID: string | undefined;
CHROME_PUBLISH_TARGET: string | undefined;
CHROME_REFRESH_TOKEN: string | undefined;
CHROME_REVIEW_EXEMPTION: string | undefined;
CHROME_SKIP_SUBMIT_REVIEW: string | undefined;
CHROME_ZIP: string | undefined;

Expand Down

0 comments on commit cb529e2

Please sign in to comment.