ovsx 0.10.2 → 0.10.3

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/lib/create-namespace-options.d.ts +17 -0
  3. package/lib/create-namespace-options.d.ts.map +1 -0
  4. package/lib/create-namespace-options.js +12 -0
  5. package/lib/create-namespace-options.js.map +1 -0
  6. package/lib/create-namespace.d.ts +1 -7
  7. package/lib/create-namespace.d.ts.map +1 -1
  8. package/lib/create-namespace.js +2 -1
  9. package/lib/create-namespace.js.map +1 -1
  10. package/lib/get-options.d.ts +33 -0
  11. package/lib/get-options.d.ts.map +1 -0
  12. package/lib/get-options.js +12 -0
  13. package/lib/get-options.js.map +1 -0
  14. package/lib/get.d.ts +1 -23
  15. package/lib/get.d.ts.map +1 -1
  16. package/lib/get.js +2 -2
  17. package/lib/get.js.map +1 -1
  18. package/lib/index.d.ts +8 -0
  19. package/lib/index.d.ts.map +1 -1
  20. package/lib/index.js +8 -0
  21. package/lib/index.js.map +1 -1
  22. package/lib/login-options.d.ts +17 -0
  23. package/lib/login-options.d.ts.map +1 -0
  24. package/lib/login-options.js +3 -0
  25. package/lib/login-options.js.map +1 -0
  26. package/lib/login.d.ts +1 -7
  27. package/lib/login.d.ts.map +1 -1
  28. package/lib/login.js +2 -1
  29. package/lib/login.js.map +1 -1
  30. package/lib/logout.d.ts.map +1 -1
  31. package/lib/logout.js +9 -0
  32. package/lib/logout.js.map +1 -1
  33. package/lib/pat.d.ts +16 -0
  34. package/lib/pat.d.ts.map +1 -0
  35. package/lib/pat.js +39 -0
  36. package/lib/pat.js.map +1 -0
  37. package/lib/publish-options.d.ts +56 -0
  38. package/lib/publish-options.d.ts.map +1 -0
  39. package/lib/publish-options.js +3 -0
  40. package/lib/publish-options.js.map +1 -0
  41. package/lib/publish.d.ts +1 -47
  42. package/lib/publish.d.ts.map +1 -1
  43. package/lib/publish.js +2 -1
  44. package/lib/publish.js.map +1 -1
  45. package/lib/registry-options.d.ts +36 -0
  46. package/lib/registry-options.d.ts.map +1 -0
  47. package/lib/registry-options.js +12 -0
  48. package/lib/registry-options.js.map +1 -0
  49. package/lib/registry.d.ts +1 -26
  50. package/lib/registry.d.ts.map +1 -1
  51. package/lib/registry.js +9 -11
  52. package/lib/registry.js.map +1 -1
  53. package/lib/store.d.ts.map +1 -1
  54. package/lib/store.js +9 -0
  55. package/lib/store.js.map +1 -1
  56. package/lib/util.d.ts +2 -6
  57. package/lib/util.d.ts.map +1 -1
  58. package/lib/util.js +11 -38
  59. package/lib/util.js.map +1 -1
  60. package/lib/verify-pat-options.d.ts +17 -0
  61. package/lib/verify-pat-options.d.ts.map +1 -0
  62. package/lib/verify-pat-options.js +12 -0
  63. package/lib/verify-pat-options.js.map +1 -0
  64. package/lib/verify-pat.d.ts +1 -8
  65. package/lib/verify-pat.d.ts.map +1 -1
  66. package/lib/verify-pat.js +3 -14
  67. package/lib/verify-pat.js.map +1 -1
  68. package/lib/version.d.ts +1 -1
  69. package/lib/version.js +1 -1
  70. package/lib/zip.d.ts +0 -1
  71. package/lib/zip.d.ts.map +1 -1
  72. package/lib/zip.js +24 -24
  73. package/lib/zip.js.map +1 -1
  74. package/package.json +4 -4
  75. package/src/create-namespace-options.ts +18 -0
  76. package/src/create-namespace.ts +4 -9
  77. package/src/get-options.ts +34 -0
  78. package/src/get.ts +5 -27
  79. package/src/index.ts +8 -0
  80. package/src/login-options.ts +17 -0
  81. package/src/login.ts +3 -9
  82. package/src/logout.ts +9 -0
  83. package/src/pat.ts +52 -0
  84. package/src/publish-options.ts +61 -0
  85. package/src/publish.ts +21 -70
  86. package/src/registry-options.ts +36 -0
  87. package/src/registry.ts +16 -44
  88. package/src/store.ts +9 -0
  89. package/src/util.ts +14 -47
  90. package/src/verify-pat-options.ts +18 -0
  91. package/src/verify-pat.ts +3 -20
  92. package/src/version.ts +1 -1
  93. package/src/zip.ts +26 -31
package/src/registry.ts CHANGED
@@ -12,7 +12,8 @@ import * as http from 'http';
12
12
  import * as fs from 'fs';
13
13
  import * as querystring from 'querystring';
14
14
  import * as followRedirects from 'follow-redirects';
15
- import { statusError } from './util';
15
+ import { RegistryOptions } from './registry-options';
16
+ import { rejectError, statusError } from './util';
16
17
 
17
18
  export const DEFAULT_URL = 'https://open-vsx.org';
18
19
  export const DEFAULT_NAMESPACE_SIZE = 1024;
@@ -53,17 +54,17 @@ export class Registry {
53
54
  'Content-Type': 'application/json'
54
55
  }, this.maxNamespaceSize);
55
56
  } catch (err) {
56
- return Promise.reject(err);
57
+ return rejectError(err);
57
58
  }
58
59
  }
59
60
 
60
61
  verifyPat(namespace: string, pat: string): Promise<Response> {
61
- try {
62
- const query: { [key: string]: string } = { token: pat };
63
- return this.getJson(this.getUrl(`api/${namespace}/verify-pat`, query));
64
- } catch (err) {
65
- return Promise.reject(err);
66
- }
62
+ try {
63
+ const query: { [key: string]: string } = { token: pat };
64
+ return this.getJson(this.getUrl(`api/${namespace}/verify-pat`, query));
65
+ } catch (err) {
66
+ return rejectError(err);
67
+ }
67
68
  }
68
69
 
69
70
  publish(file: string, pat: string): Promise<Extension> {
@@ -74,7 +75,7 @@ export class Registry {
74
75
  'Content-Type': 'application/octet-stream'
75
76
  }, this.maxPublishSize);
76
77
  } catch (err) {
77
- return Promise.reject(err);
78
+ return rejectError(err);
78
79
  }
79
80
  }
80
81
 
@@ -86,7 +87,7 @@ export class Registry {
86
87
  }
87
88
  return this.getJson(this.getUrl(path));
88
89
  } catch (err) {
89
- return Promise.reject(err);
90
+ return rejectError(err);
90
91
  }
91
92
  }
92
93
 
@@ -105,11 +106,11 @@ export class Registry {
105
106
  });
106
107
  response.pipe(stream);
107
108
  });
108
- stream.on('error', err => {
109
+ stream.on('error', (err: Error) => {
109
110
  request.abort();
110
111
  reject(err);
111
112
  });
112
- request.on('error', err => {
113
+ request.on('error', (err: Error) => {
113
114
  stream.close();
114
115
  reject(err);
115
116
  });
@@ -144,11 +145,11 @@ export class Registry {
144
145
  const requestOptions = this.getRequestOptions('POST', headers, maxBodyLength);
145
146
  const request = this.getProtocol(url)
146
147
  .request(url, requestOptions, this.getJsonResponse<T>(resolve, reject));
147
- stream.on('error', err => {
148
+ stream.on('error', (err: Error) => {
148
149
  request.abort();
149
150
  reject(err);
150
151
  });
151
- request.on('error', err => {
152
+ request.on('error', (err: Error) => {
152
153
  stream.close();
153
154
  reject(err);
154
155
  });
@@ -171,9 +172,7 @@ export class Registry {
171
172
 
172
173
  private getRequestOptions(method?: string, headers?: http.OutgoingHttpHeaders, maxBodyLength?: number): http.RequestOptions {
173
174
  if (this.username && this.password) {
174
- if (!headers) {
175
- headers = {};
176
- }
175
+ headers ??= {};
177
176
  const credentials = Buffer.from(this.username + ':' + this.password).toString('base64');
178
177
  headers['Authorization'] = 'Basic ' + credentials;
179
178
  }
@@ -219,33 +218,6 @@ export class Registry {
219
218
 
220
219
  }
221
220
 
222
- export interface RegistryOptions {
223
- /**
224
- * The base URL of the registry API.
225
- */
226
- registryUrl?: string;
227
- /**
228
- * Personal access token.
229
- */
230
- pat?: string;
231
- /**
232
- * User name for basic authentication.
233
- */
234
- username?: string;
235
- /**
236
- * Password for basic authentication.
237
- */
238
- password?: string;
239
- /**
240
- * Maximal request body size for creating namespaces.
241
- */
242
- maxNamespaceSize?: number;
243
- /**
244
- * Maximal request body size for publishing.
245
- */
246
- maxPublishSize?: number;
247
- }
248
-
249
221
  export interface Response {
250
222
  success?: string;
251
223
  warning?: string;
package/src/store.ts CHANGED
@@ -1,3 +1,12 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2024 Precies. Software and others
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ********************************************************************************/
1
10
  import * as fs from 'fs';
2
11
  import * as path from 'path';
3
12
  import { homedir } from 'os';
package/src/util.ts CHANGED
@@ -13,27 +13,15 @@ import * as path from 'path';
13
13
  import * as tmp from 'tmp';
14
14
  import * as http from 'http';
15
15
  import * as readline from 'readline';
16
- import { RegistryOptions } from './registry';
17
- import { VerifyPatOptions, doVerifyPat } from './verify-pat';
18
- import { PublishOptions } from './publish';
19
- import { openDefaultStore } from './store';
20
- import { CreateNamespaceOptions } from './create-namespace';
16
+ import { RegistryOptions } from './registry-options';
21
17
 
22
18
  export { promisify } from 'util';
23
19
 
24
20
  export function addEnvOptions(options: RegistryOptions): void {
25
- if (!options.registryUrl) {
26
- options.registryUrl = process.env.OVSX_REGISTRY_URL;
27
- }
28
- if (!options.pat) {
29
- options.pat = process.env.OVSX_PAT;
30
- }
31
- if (!options.username) {
32
- options.username = process.env.OVSX_USERNAME;
33
- }
34
- if (!options.password) {
35
- options.password = process.env.OVSX_PASSWORD;
36
- }
21
+ options.registryUrl ??= process.env.OVSX_REGISTRY_URL;
22
+ options.pat ??= process.env.OVSX_PAT;
23
+ options.username ??= process.env.OVSX_USERNAME;
24
+ options.password ??= process.env.OVSX_PASSWORD;
37
25
  }
38
26
 
39
27
  export function matchExtensionId(id: string): RegExpExecArray | null {
@@ -51,7 +39,7 @@ export function makeDirs(path: fs.PathLike): Promise<void> {
51
39
  if (fs.existsSync(path)) {
52
40
  resolve();
53
41
  } else {
54
- fs.mkdir(path, { recursive: true }, err => {
42
+ fs.mkdir(path, { recursive: true }, (err: NodeJS.ErrnoException | null) => {
55
43
  if (err)
56
44
  reject(err);
57
45
  else
@@ -63,7 +51,7 @@ export function makeDirs(path: fs.PathLike): Promise<void> {
63
51
 
64
52
  export function createTempFile(options: tmp.TmpNameOptions): Promise<string> {
65
53
  return new Promise((resolve, reject) => {
66
- tmp.tmpName(options, (err, name) => {
54
+ tmp.tmpName(options, (err: Error | null, name: string) => {
67
55
  if (err)
68
56
  reject(err);
69
57
  else
@@ -72,6 +60,11 @@ export function createTempFile(options: tmp.TmpNameOptions): Promise<string> {
72
60
  });
73
61
  }
74
62
 
63
+ export function rejectError(err: any) {
64
+ const reason = err instanceof Error ? err : new Error(String(err));
65
+ return Promise.reject(reason);
66
+ }
67
+
75
68
  export function handleError(debug?: boolean, additionalMessage?: string, exit: boolean = true): (reason: any) => void {
76
69
  return reason => {
77
70
  if (reason instanceof Error && !debug) {
@@ -105,7 +98,7 @@ export function readFile(name: string, packagePath?: string, encoding: BufferEnc
105
98
  fs.readFile(
106
99
  path.join(packagePath ?? process.cwd(), name),
107
100
  { encoding },
108
- (err, content) => {
101
+ (err: NodeJS.ErrnoException | null, content: string) => {
109
102
  if (err) {
110
103
  reject(err);
111
104
  } else {
@@ -139,7 +132,7 @@ export function writeFile(name: string, content: string, packagePath?: string, e
139
132
  path.join(packagePath ?? process.cwd(), name),
140
133
  content,
141
134
  { encoding },
142
- err => {
135
+ (err: NodeJS.ErrnoException | null) => {
143
136
  if (err) {
144
137
  reject(err);
145
138
  } else {
@@ -186,30 +179,4 @@ export async function getUserChoice<R extends string>(text: string, values: R[],
186
179
  }
187
180
  }
188
181
  return defaultValue;
189
- }
190
-
191
- export async function requestPAT(namespace: string, options: CreateNamespaceOptions | PublishOptions | VerifyPatOptions, verify: boolean = true): Promise<string> {
192
- const pat = await getUserInput(`Personal Access Token for namespace '${namespace}':`);
193
- if (verify) {
194
- await doVerifyPat({ ...options, namespace, pat });
195
- }
196
-
197
- return pat;
198
- }
199
-
200
- export async function getPAT(namespace: string, options: CreateNamespaceOptions | PublishOptions | VerifyPatOptions, verify: boolean = true): Promise<string> {
201
- if (options?.pat) {
202
- return options.pat;
203
- }
204
-
205
- const store = await openDefaultStore();
206
- let pat = store.get(namespace);
207
- if (pat) {
208
- return pat;
209
- }
210
-
211
- pat = await requestPAT(namespace, options, verify);
212
- await store.add(namespace, pat);
213
-
214
- return pat;
215
182
  }
@@ -0,0 +1,18 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 Anibal Solon and others
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ********************************************************************************/
10
+
11
+ import { RegistryOptions } from './registry-options';
12
+
13
+ export interface VerifyPatOptions extends RegistryOptions {
14
+ /**
15
+ * Name of the namespace.
16
+ */
17
+ namespace?: string
18
+ }
package/src/verify-pat.ts CHANGED
@@ -8,8 +8,9 @@
8
8
  * SPDX-License-Identifier: EPL-2.0
9
9
  ********************************************************************************/
10
10
 
11
- import { Registry, RegistryOptions } from './registry';
12
- import { readManifest, addEnvOptions, getPAT } from './util';
11
+ import { getPAT, doVerifyPat } from './pat';
12
+ import { readManifest, addEnvOptions } from './util';
13
+ import { VerifyPatOptions } from './verify-pat-options';
13
14
 
14
15
  /**
15
16
  * Validates that a Personal Access Token can publish to a namespace.
@@ -35,21 +36,3 @@ export async function verifyPat(options: VerifyPatOptions): Promise<void> {
35
36
  options.pat = await getPAT(options.namespace, options, false);
36
37
  await doVerifyPat(options);
37
38
  }
38
-
39
- export async function doVerifyPat(options: VerifyPatOptions) {
40
- const registry = new Registry(options);
41
- const namespace = options.namespace as string;
42
- const pat = options.pat as string;
43
- const result = await registry.verifyPat(namespace, pat);
44
- if (result.error) {
45
- throw new Error(result.error);
46
- }
47
- console.log(`\ud83d\ude80 PAT valid to publish at ${namespace}`);
48
- }
49
-
50
- export interface VerifyPatOptions extends RegistryOptions {
51
- /**
52
- * Name of the namespace.
53
- */
54
- namespace?: string
55
- }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "0.10.2";
1
+ export const LIB_VERSION = "0.10.3";
package/src/zip.ts CHANGED
@@ -1,4 +1,13 @@
1
- import { Entry, open, ZipFile } from 'yauzl';
1
+ /********************************************************************************
2
+ * Copyright (c) 2024 Precies. Software and others
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ********************************************************************************/
10
+ import * as yauzl from 'yauzl-promise';
2
11
  import { Readable } from 'stream';
3
12
  import { Manifest } from './util';
4
13
 
@@ -11,37 +20,23 @@ async function bufferStream(stream: Readable): Promise<Buffer> {
11
20
  });
12
21
  }
13
22
 
14
- export async function readZip(packagePath: string, filter: (name: string) => boolean): Promise<Map<string, Buffer>> {
15
- const zipfile = await new Promise<ZipFile>((resolve, reject) =>
16
- open(packagePath, { lazyEntries: true }, (err, zipfile) => (err ? reject(err) : resolve(zipfile)))
17
- );
18
-
19
- return await new Promise((resolve, reject) => {
20
- const result = new Map<string, Buffer>();
21
-
22
- zipfile.once('close', () => resolve(result));
23
-
24
- zipfile.readEntry();
25
- zipfile.on('entry', (entry: Entry) => {
26
- const name = entry.fileName.toLowerCase();
27
-
23
+ async function readZip(packagePath: string, filter: (name: string) => boolean): Promise<Map<string, Buffer>> {
24
+ const result = new Map<string, Buffer>();
25
+ const zipfile = await yauzl.open(packagePath);
26
+ try {
27
+ for await (const entry of zipfile) {
28
+ const name = entry.filename.toLowerCase();
28
29
  if (filter(name)) {
29
- zipfile.openReadStream(entry, (err, stream) => {
30
- if (err) {
31
- zipfile.close();
32
- return reject(err);
33
- }
34
-
35
- bufferStream(stream).then(buffer => {
36
- result.set(name, buffer);
37
- zipfile.readEntry();
38
- });
39
- });
40
- } else {
41
- zipfile.readEntry();
30
+ const stream = await zipfile.openReadStream(entry);
31
+ const buffer = await bufferStream(stream);
32
+ result.set(name, buffer);
42
33
  }
43
- });
44
- });
34
+ }
35
+ } finally {
36
+ await zipfile.close();
37
+ }
38
+
39
+ return result;
45
40
  }
46
41
 
47
42
  export async function readVSIXPackage(packagePath: string): Promise<Manifest> {
@@ -51,5 +46,5 @@ export async function readVSIXPackage(packagePath: string): Promise<Manifest> {
51
46
  throw new Error('Manifest not found.');
52
47
  }
53
48
 
54
- return JSON.parse(rawManifest.toString('utf8')) as Manifest;
49
+ return JSON.parse(rawManifest.toString('utf8')) as Manifest;
55
50
  }