@equicord/publish-browser-extension 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,10 +1,10 @@
1
- import { d as chromeStatus, n as submit, t as init, u as chromeSetDeployPercentage } from "./init-CB96xhAw.js";
1
+ import { d as chromeStatus, n as submit, t as init, u as chromeSetDeployPercentage } from "./init-D2uZ1oqE.js";
2
2
  import { cac } from "cac";
3
3
  import { consola as consola$1 } from "consola";
4
4
  import { config } from "dotenv";
5
5
 
6
6
  //#region package.json
7
- var version = "4.0.3";
7
+ var version = "4.0.4";
8
8
 
9
9
  //#endregion
10
10
  //#region src/cli.ts
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { a as FirefoxAddonStoreOptions, c as EdgeAddonStoreOptions, d as chromeStatus, f as ChromeWebStore, i as FirefoxAddonStore, l as EdgeApi, m as CwsApi, n as submit, o as AddonsApi, p as ChromeWebStoreOptions, r as InlineConfig, s as EdgeAddonStore, t as init, u as chromeSetDeployPercentage } from "./init-CB96xhAw.js";
1
+ import { a as FirefoxAddonStoreOptions, c as EdgeAddonStoreOptions, d as chromeStatus, f as ChromeWebStore, i as FirefoxAddonStore, l as EdgeApi, m as CwsApi, n as submit, o as AddonsApi, p as ChromeWebStoreOptions, r as InlineConfig, s as EdgeAddonStore, t as init, u as chromeSetDeployPercentage } from "./init-D2uZ1oqE.js";
2
2
 
3
3
  export { AddonsApi, ChromeWebStore, ChromeWebStoreOptions, CwsApi, EdgeAddonStore, EdgeAddonStoreOptions, EdgeApi, FirefoxAddonStore, FirefoxAddonStoreOptions, InlineConfig, chromeSetDeployPercentage, chromeStatus, init, submit };
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { Listr } from "listr2";
3
- import { createFetch } from "ofetch";
3
+ import { createFetch, ofetch } from "ofetch";
4
4
  import { z } from "zod/v4";
5
5
  import fs, { copyFile, readFile, writeFile } from "node:fs/promises";
6
6
  import consola, { consola as consola$1 } from "consola";
@@ -9,7 +9,6 @@ import { FormData } from "formdata-node";
9
9
  import { fileFromPath } from "formdata-node/file-from-path";
10
10
  import { FormDataEncoder } from "form-data-encoder";
11
11
  import { Readable } from "node:stream";
12
- import http from "http";
13
12
 
14
13
  //#region rolldown:runtime
15
14
  var __create = Object.create;
@@ -39,7 +38,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
39
38
 
40
39
  //#endregion
41
40
  //#region src/utils/fetch.ts
42
- const fetch$1 = createFetch({ defaults: { onResponseError: (ctx) => {
41
+ const fetch = createFetch({ defaults: { onResponseError: (ctx) => {
43
42
  console.log("Request:", ctx.request);
44
43
  console.log("Response:", JSON.stringify(ctx.response, null, 2));
45
44
  } } });
@@ -71,7 +70,7 @@ var CwsApi = class {
71
70
  }
72
71
  async uploadZip(params) {
73
72
  const Authorization = this.getAuthHeader(params.token);
74
- return fetch$1(this.uploadEndpoint(params.extensionId), {
73
+ return fetch(this.uploadEndpoint(params.extensionId), {
75
74
  method: "POST",
76
75
  body: Bun.file(params.zipFile),
77
76
  headers: {
@@ -86,7 +85,7 @@ var CwsApi = class {
86
85
  if (params.publishType) body.publishType = params.publishType;
87
86
  if (params.deployPercentage != null) body.deployInfos = [{ deployPercentage: params.deployPercentage }];
88
87
  if (params.skipReview != null) body.skipReview = params.skipReview;
89
- return fetch$1(this.publishEndpoint(params.extensionId), {
88
+ return fetch(this.publishEndpoint(params.extensionId), {
90
89
  method: "POST",
91
90
  headers: {
92
91
  Authorization,
@@ -97,21 +96,21 @@ var CwsApi = class {
97
96
  }
98
97
  async fetchStatus(params) {
99
98
  const Authorization = this.getAuthHeader(params.token);
100
- return fetch$1(this.fetchStatusEndpoint(params.extensionId), {
99
+ return fetch(this.fetchStatusEndpoint(params.extensionId), {
101
100
  method: "GET",
102
101
  headers: { Authorization }
103
102
  });
104
103
  }
105
104
  async cancelSubmission(params) {
106
105
  const Authorization = this.getAuthHeader(params.token);
107
- await fetch$1(this.cancelSubmissionEndpoint(params.extensionId), {
106
+ await fetch(this.cancelSubmissionEndpoint(params.extensionId), {
108
107
  method: "POST",
109
108
  headers: { Authorization }
110
109
  });
111
110
  }
112
111
  async setPublishedDeployPercentage(params) {
113
112
  const Authorization = this.getAuthHeader(params.token);
114
- await fetch$1(this.setDeployPercentageEndpoint(params.extensionId), {
113
+ await fetch(this.setDeployPercentageEndpoint(params.extensionId), {
115
114
  method: "POST",
116
115
  headers: {
117
116
  Authorization,
@@ -121,7 +120,7 @@ var CwsApi = class {
121
120
  });
122
121
  }
123
122
  getToken() {
124
- return fetch$1(this.tokenEndpoint(), {
123
+ return fetch(this.tokenEndpoint(), {
125
124
  method: "POST",
126
125
  body: JSON.stringify({
127
126
  client_id: this.options.clientId,
@@ -256,7 +255,7 @@ var EdgeApi = class {
256
255
  async uploadDraft(params) {
257
256
  const endpoint = `https://api.addons.microsoftedge.microsoft.com/v1/products/${params.productId}/submissions/draft/package`;
258
257
  const file = fs$1.createReadStream(params.zipFile);
259
- const operationId = (await fetch$1.raw(endpoint, {
258
+ const operationId = (await fetch.raw(endpoint, {
260
259
  method: "POST",
261
260
  body: file,
262
261
  headers: {
@@ -271,14 +270,14 @@ var EdgeApi = class {
271
270
  * Docs: https://learn.microsoft.com/en-us/microsoft-edge/extensions-chromium/publish/api/using-addons-api#checking-the-status-of-a-package-upload
272
271
  */
273
272
  uploadDraftOperation(params) {
274
- return fetch$1(`https://api.addons.microsoftedge.microsoft.com/v1/products/${params.productId}/submissions/draft/package/operations/${params.operationId}`, { headers: this.getAuthHeaders(params.token) });
273
+ return fetch(`https://api.addons.microsoftedge.microsoft.com/v1/products/${params.productId}/submissions/draft/package/operations/${params.operationId}`, { headers: this.getAuthHeaders(params.token) });
275
274
  }
276
275
  /**
277
276
  * Docs: https://learn.microsoft.com/en-us/microsoft-edge/extensions-chromium/publish/api/using-addons-api#publishing-the-submission
278
277
  */
279
278
  async publish(params) {
280
279
  const endpoint = `https://api.addons.microsoftedge.microsoft.com/v1/products/${params.productId}/submissions`;
281
- const res = await fetch$1.raw(endpoint, {
280
+ const res = await fetch.raw(endpoint, {
282
281
  method: "POST",
283
282
  body: JSON.stringify({}),
284
283
  headers: this.getAuthHeaders(params.token)
@@ -3836,7 +3835,7 @@ var AddonsApi = class {
3836
3835
  * Docs: https://addons-server.readthedocs.io/en/latest/topics/api/addons.html#detail
3837
3836
  */
3838
3837
  details(params) {
3839
- return fetch$1(this.addonDetailEndpoint(params.extensionId).href, { headers: { Authorization: this.getAuthHeader() } });
3838
+ return fetch(this.addonDetailEndpoint(params.extensionId).href, { headers: { Authorization: this.getAuthHeader() } });
3840
3839
  }
3841
3840
  /**
3842
3841
  * Docs: https://addons-server.readthedocs.io/en/latest/topics/api/addons.html#upload-create
@@ -3847,7 +3846,7 @@ var AddonsApi = class {
3847
3846
  form.set("channel", params.channel);
3848
3847
  form.set("upload", await fileFromPath(params.file));
3849
3848
  const encoder = new FormDataEncoder(form);
3850
- return await fetch$1(endpoint.href, {
3849
+ return await fetch(endpoint.href, {
3851
3850
  method: "POST",
3852
3851
  body: Readable.from(encoder),
3853
3852
  headers: {
@@ -3860,7 +3859,7 @@ var AddonsApi = class {
3860
3859
  * Docs: https://addons-server.readthedocs.io/en/latest/topics/api/addons.html#upload-detail
3861
3860
  */
3862
3861
  uploadDetail(params) {
3863
- return fetch$1(this.addonsUploadDetailsEndpoint(params.uuid).href, { headers: { Authorization: this.getAuthHeader() } });
3862
+ return fetch(this.addonsUploadDetailsEndpoint(params.uuid).href, { headers: { Authorization: this.getAuthHeader() } });
3864
3863
  }
3865
3864
  async versionCreate(params) {
3866
3865
  const endpoint = this.addonVersionCreateEndpoint(params.extensionId);
@@ -3869,7 +3868,7 @@ var AddonsApi = class {
3869
3868
  if (params.sourceFile) form.set("source", await fileFromPath(params.sourceFile));
3870
3869
  else form.set("source", "");
3871
3870
  const encoder = new FormDataEncoder(form);
3872
- return await fetch$1(endpoint.href, {
3871
+ return await fetch(endpoint.href, {
3873
3872
  method: "POST",
3874
3873
  body: Readable.from(encoder),
3875
3874
  headers: {
@@ -4122,44 +4121,6 @@ async function submit(config) {
4122
4121
  //#endregion
4123
4122
  //#region src/init.ts
4124
4123
  const envFile = ".env.submit";
4125
- async function generateRefreshTokenViaOAuth(clientId, clientSecret) {
4126
- let resolveCode;
4127
- const codePromise = new Promise((resolve) => resolveCode = resolve);
4128
- const server = http.createServer((req, res) => {
4129
- const code$1 = new URL(req.url || "", `http://localhost`).searchParams.get("code");
4130
- if (code$1) {
4131
- resolveCode(code$1);
4132
- res.writeHead(200, { "Content-Type": "text/html" });
4133
- res.end("Success! You can close this tab. <script>window.close()<\/script>");
4134
- server.close();
4135
- } else {
4136
- res.writeHead(400);
4137
- res.end("No code found");
4138
- }
4139
- });
4140
- server.listen(0, () => {
4141
- const redirectUri = `http://127.0.0.1:${server.address().port}`;
4142
- const authUrl = new URL("https://accounts.google.com/o/oauth2/auth");
4143
- authUrl.searchParams.set("response_type", "code");
4144
- authUrl.searchParams.set("access_type", "offline");
4145
- authUrl.searchParams.set("client_id", clientId);
4146
- authUrl.searchParams.set("scope", "https://www.googleapis.com/auth/chromewebstore");
4147
- authUrl.searchParams.set("redirect_uri", redirectUri);
4148
- console.log("Open this URL in your browser to authorize:");
4149
- console.log(authUrl.href);
4150
- });
4151
- const code = await codePromise;
4152
- return (await (await fetch("https://accounts.google.com/o/oauth2/token", {
4153
- method: "POST",
4154
- body: new URLSearchParams({
4155
- client_id: clientId,
4156
- client_secret: clientSecret,
4157
- code,
4158
- grant_type: "authorization_code",
4159
- redirect_uri: `http://127.0.0.1:${server.address().port}`
4160
- })
4161
- })).json()).refresh_token;
4162
- }
4163
4124
  async function init(config) {
4164
4125
  consola$1.info(`Initialize or update an existing \`${envFile}\` file.`);
4165
4126
  const previousConfig = resolveConfig(config);
@@ -4223,7 +4184,22 @@ async function initChrome(previousOptions) {
4223
4184
  const clientSecret = await prompt("Enter your client secret:", { type: "text" }, previousOptions?.clientSecret);
4224
4185
  entries.push(["CHROME_CLIENT_SECRET", clientSecret]);
4225
4186
  if (await prompt("Generate new refresh token?", { type: "confirm" })) {
4226
- const refreshToken = await generateRefreshTokenViaOAuth(clientId, clientSecret);
4187
+ const authCodeUrl = `https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/chromewebstore&client_id=${clientId}&redirect_uri=urn:ietf:wg:oauth:2.0:oob`;
4188
+ consola$1.log(authCodeUrl);
4189
+ const authCode = await consola$1.prompt("Open the above URL, login, and enter the auth code:", {
4190
+ type: "text",
4191
+ required: true
4192
+ });
4193
+ const data = new URLSearchParams();
4194
+ data.set("client_id", clientId);
4195
+ data.set("client_secret", clientSecret);
4196
+ data.set("code", authCode);
4197
+ data.set("grant_type", "authorization_code");
4198
+ data.set("redirect_uri", "urn:ietf:wg:oauth:2.0:oob");
4199
+ const refreshToken = (await ofetch(`https://accounts.google.com/o/oauth2/token`, {
4200
+ method: "POST",
4201
+ body: data
4202
+ })).refresh_token;
4227
4203
  consola$1.info(`Refresh token: \`${refreshToken}\``);
4228
4204
  entries.push(["CHROME_REFRESH_TOKEN", refreshToken]);
4229
4205
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@equicord/publish-browser-extension",
3
3
  "description": "Easily publish web extensions to their stores",
4
- "version": "4.0.3",
4
+ "version": "4.0.4",
5
5
  "packageManager": "bun@1.3.4",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -24,7 +24,6 @@
24
24
  "dotenv": "^17.2.3",
25
25
  "form-data-encoder": "^4.1.0",
26
26
  "formdata-node": "^6.0.3",
27
- "http": "^0.0.1-security",
28
27
  "listr2": "^8.3.3",
29
28
  "ofetch": "^1.4.1",
30
29
  "zod": "^3.25.76 || ^4.0.0"