ovsx 0.5.0 → 0.5.2

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/lib/registry.d.ts CHANGED
@@ -1,131 +1,131 @@
1
- /********************************************************************************
2
- * Copyright (c) 2019 TypeFox 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
- /// <reference types="node" />
11
- import * as http from 'http';
12
- export declare const DEFAULT_URL = "https://open-vsx.org";
13
- export declare const DEFAULT_NAMESPACE_SIZE = 1024;
14
- export declare const DEFAULT_PUBLISH_SIZE: number;
15
- export declare class Registry {
16
- readonly url: string;
17
- readonly maxNamespaceSize: number;
18
- readonly maxPublishSize: number;
19
- readonly username?: string;
20
- readonly password?: string;
21
- constructor(options?: RegistryOptions);
22
- get requiresLicense(): boolean;
23
- createNamespace(name: string, pat: string): Promise<Response>;
24
- publish(file: string, pat: string): Promise<Extension>;
25
- getMetadata(namespace: string, extension: string, target?: string): Promise<Extension>;
26
- download(file: string, url: URL): Promise<void>;
27
- getJson<T extends Response>(url: URL): Promise<T>;
28
- post<T extends Response>(content: string | Buffer | Uint8Array, url: URL, headers?: http.OutgoingHttpHeaders, maxBodyLength?: number): Promise<T>;
29
- postFile<T extends Response>(file: string, url: URL, headers?: http.OutgoingHttpHeaders, maxBodyLength?: number): Promise<T>;
30
- private getUrl;
31
- private getProtocol;
32
- private getRequestOptions;
33
- private getJsonResponse;
34
- }
35
- export interface RegistryOptions {
36
- /**
37
- * The base URL of the registry API.
38
- */
39
- registryUrl?: string;
40
- /**
41
- * Personal access token.
42
- */
43
- pat?: string;
44
- /**
45
- * User name for basic authentication.
46
- */
47
- username?: string;
48
- /**
49
- * Password for basic authentication.
50
- */
51
- password?: string;
52
- /**
53
- * Maximal request body size for creating namespaces.
54
- */
55
- maxNamespaceSize?: number;
56
- /**
57
- * Maximal request body size for publishing.
58
- */
59
- maxPublishSize?: number;
60
- }
61
- export interface Response {
62
- success?: string;
63
- warning?: string;
64
- error?: string;
65
- }
66
- export interface Extension extends Response {
67
- namespaceUrl: string;
68
- reviewsUrl: string;
69
- files: {
70
- [type: string]: string;
71
- };
72
- name: string;
73
- namespace: string;
74
- version: string;
75
- targetPlatform: string;
76
- publishedBy: UserData;
77
- verified: boolean;
78
- allVersions: {
79
- [version: string]: string;
80
- };
81
- averageRating?: number;
82
- downloadCount: number;
83
- reviewCount: number;
84
- versionAlias: string[];
85
- timestamp: string;
86
- preview?: boolean;
87
- displayName?: string;
88
- description?: string;
89
- engines?: {
90
- [engine: string]: string;
91
- };
92
- categories?: string[];
93
- tags?: string[];
94
- license?: string;
95
- homepage?: string;
96
- repository?: string;
97
- bugs?: string;
98
- markdown?: string;
99
- galleryColor?: string;
100
- galleryTheme?: string;
101
- qna?: string;
102
- badges?: Badge[];
103
- dependencies?: ExtensionReference[];
104
- bundledExtensions?: ExtensionReference[];
105
- }
106
- export interface UserData {
107
- loginName: string;
108
- fullName?: string;
109
- avatarUrl?: string;
110
- homepage?: string;
111
- }
112
- export interface Badge {
113
- url: string;
114
- href: string;
115
- description: string;
116
- }
117
- export interface ExtensionReference {
118
- url: string;
119
- namespace: string;
120
- extension: string;
121
- version?: string;
122
- }
123
- export interface ErrorResponse {
124
- error: string;
125
- message: string;
126
- status: number;
127
- path?: string;
128
- timestamp?: string;
129
- trace?: string;
130
- }
1
+ /********************************************************************************
2
+ * Copyright (c) 2019 TypeFox 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
+ /// <reference types="node" />
11
+ import * as http from 'http';
12
+ export declare const DEFAULT_URL = "https://open-vsx.org";
13
+ export declare const DEFAULT_NAMESPACE_SIZE = 1024;
14
+ export declare const DEFAULT_PUBLISH_SIZE: number;
15
+ export declare class Registry {
16
+ readonly url: string;
17
+ readonly maxNamespaceSize: number;
18
+ readonly maxPublishSize: number;
19
+ readonly username?: string;
20
+ readonly password?: string;
21
+ constructor(options?: RegistryOptions);
22
+ get requiresLicense(): boolean;
23
+ createNamespace(name: string, pat: string): Promise<Response>;
24
+ publish(file: string, pat: string): Promise<Extension>;
25
+ getMetadata(namespace: string, extension: string, target?: string): Promise<Extension>;
26
+ download(file: string, url: URL): Promise<void>;
27
+ getJson<T extends Response>(url: URL): Promise<T>;
28
+ post<T extends Response>(content: string | Buffer | Uint8Array, url: URL, headers?: http.OutgoingHttpHeaders, maxBodyLength?: number): Promise<T>;
29
+ postFile<T extends Response>(file: string, url: URL, headers?: http.OutgoingHttpHeaders, maxBodyLength?: number): Promise<T>;
30
+ private getUrl;
31
+ private getProtocol;
32
+ private getRequestOptions;
33
+ private getJsonResponse;
34
+ }
35
+ export interface RegistryOptions {
36
+ /**
37
+ * The base URL of the registry API.
38
+ */
39
+ registryUrl?: string;
40
+ /**
41
+ * Personal access token.
42
+ */
43
+ pat?: string;
44
+ /**
45
+ * User name for basic authentication.
46
+ */
47
+ username?: string;
48
+ /**
49
+ * Password for basic authentication.
50
+ */
51
+ password?: string;
52
+ /**
53
+ * Maximal request body size for creating namespaces.
54
+ */
55
+ maxNamespaceSize?: number;
56
+ /**
57
+ * Maximal request body size for publishing.
58
+ */
59
+ maxPublishSize?: number;
60
+ }
61
+ export interface Response {
62
+ success?: string;
63
+ warning?: string;
64
+ error?: string;
65
+ }
66
+ export interface Extension extends Response {
67
+ namespaceUrl: string;
68
+ reviewsUrl: string;
69
+ files: {
70
+ [type: string]: string;
71
+ };
72
+ name: string;
73
+ namespace: string;
74
+ version: string;
75
+ targetPlatform: string;
76
+ publishedBy: UserData;
77
+ verified: boolean;
78
+ allVersions: {
79
+ [version: string]: string;
80
+ };
81
+ averageRating?: number;
82
+ downloadCount: number;
83
+ reviewCount: number;
84
+ versionAlias: string[];
85
+ timestamp: string;
86
+ preview?: boolean;
87
+ displayName?: string;
88
+ description?: string;
89
+ engines?: {
90
+ [engine: string]: string;
91
+ };
92
+ categories?: string[];
93
+ tags?: string[];
94
+ license?: string;
95
+ homepage?: string;
96
+ repository?: string;
97
+ bugs?: string;
98
+ markdown?: string;
99
+ galleryColor?: string;
100
+ galleryTheme?: string;
101
+ qna?: string;
102
+ badges?: Badge[];
103
+ dependencies?: ExtensionReference[];
104
+ bundledExtensions?: ExtensionReference[];
105
+ }
106
+ export interface UserData {
107
+ loginName: string;
108
+ fullName?: string;
109
+ avatarUrl?: string;
110
+ homepage?: string;
111
+ }
112
+ export interface Badge {
113
+ url: string;
114
+ href: string;
115
+ description: string;
116
+ }
117
+ export interface ExtensionReference {
118
+ url: string;
119
+ namespace: string;
120
+ extension: string;
121
+ version?: string;
122
+ }
123
+ export interface ErrorResponse {
124
+ error: string;
125
+ message: string;
126
+ status: number;
127
+ path?: string;
128
+ timestamp?: string;
129
+ trace?: string;
130
+ }
131
131
  //# sourceMappingURL=registry.d.ts.map
package/lib/registry.js CHANGED
@@ -1,202 +1,202 @@
1
- "use strict";
2
- /********************************************************************************
3
- * Copyright (c) 2019 TypeFox and others
4
- *
5
- * This program and the accompanying materials are made available under the
6
- * terms of the Eclipse Public License v. 2.0 which is available at
7
- * http://www.eclipse.org/legal/epl-2.0.
8
- *
9
- * SPDX-License-Identifier: EPL-2.0
10
- ********************************************************************************/
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const fs = require("fs");
13
- const querystring = require("querystring");
14
- const followRedirects = require("follow-redirects");
15
- const util_1 = require("./util");
16
- exports.DEFAULT_URL = 'https://open-vsx.org';
17
- exports.DEFAULT_NAMESPACE_SIZE = 1024;
18
- exports.DEFAULT_PUBLISH_SIZE = 512 * 1024 * 1024;
19
- class Registry {
20
- constructor(options = {}) {
21
- if (options.registryUrl && options.registryUrl.endsWith('/'))
22
- this.url = options.registryUrl.substring(0, options.registryUrl.length - 1);
23
- else if (options.registryUrl)
24
- this.url = options.registryUrl;
25
- else
26
- this.url = exports.DEFAULT_URL;
27
- this.maxNamespaceSize = options.maxNamespaceSize || exports.DEFAULT_NAMESPACE_SIZE;
28
- this.maxPublishSize = options.maxPublishSize || exports.DEFAULT_PUBLISH_SIZE;
29
- this.username = options.username;
30
- this.password = options.password;
31
- }
32
- get requiresLicense() {
33
- const url = new URL(this.url);
34
- return url.hostname === 'open-vsx.org' || url.hostname.endsWith('.open-vsx.org');
35
- }
36
- createNamespace(name, pat) {
37
- try {
38
- const query = { token: pat };
39
- const url = this.getUrl('api/-/namespace/create', query);
40
- const namespace = { name };
41
- return this.post(JSON.stringify(namespace), url, {
42
- 'Content-Type': 'application/json'
43
- }, this.maxNamespaceSize);
44
- }
45
- catch (err) {
46
- return Promise.reject(err);
47
- }
48
- }
49
- publish(file, pat) {
50
- try {
51
- const query = { token: pat };
52
- const url = this.getUrl('api/-/publish', query);
53
- return this.postFile(file, url, {
54
- 'Content-Type': 'application/octet-stream'
55
- }, this.maxPublishSize);
56
- }
57
- catch (err) {
58
- return Promise.reject(err);
59
- }
60
- }
61
- getMetadata(namespace, extension, target) {
62
- try {
63
- let path = `api/${encodeURIComponent(namespace)}/${encodeURIComponent(extension)}`;
64
- if (target) {
65
- path += `/${encodeURIComponent(target)}`;
66
- }
67
- return this.getJson(this.getUrl(path));
68
- }
69
- catch (err) {
70
- return Promise.reject(err);
71
- }
72
- }
73
- download(file, url) {
74
- return new Promise((resolve, reject) => {
75
- const stream = fs.createWriteStream(file);
76
- const requestOptions = this.getRequestOptions();
77
- const request = this.getProtocol(url)
78
- .request(url, requestOptions, response => {
79
- response.on('end', () => {
80
- if (response.statusCode !== undefined && (response.statusCode < 200 || response.statusCode > 299)) {
81
- reject(util_1.statusError(response));
82
- }
83
- else {
84
- resolve();
85
- }
86
- });
87
- response.pipe(stream);
88
- });
89
- stream.on('error', err => {
90
- request.abort();
91
- reject(err);
92
- });
93
- request.on('error', err => {
94
- stream.close();
95
- reject(err);
96
- });
97
- request.end();
98
- });
99
- }
100
- getJson(url) {
101
- return new Promise((resolve, reject) => {
102
- const requestOptions = this.getRequestOptions();
103
- const request = this.getProtocol(url)
104
- .request(url, requestOptions, this.getJsonResponse(resolve, reject));
105
- request.on('error', reject);
106
- request.end();
107
- });
108
- }
109
- post(content, url, headers, maxBodyLength) {
110
- return new Promise((resolve, reject) => {
111
- const requestOptions = this.getRequestOptions('POST', headers, maxBodyLength);
112
- const request = this.getProtocol(url)
113
- .request(url, requestOptions, this.getJsonResponse(resolve, reject));
114
- request.on('error', reject);
115
- request.write(content);
116
- request.end();
117
- });
118
- }
119
- postFile(file, url, headers, maxBodyLength) {
120
- return new Promise((resolve, reject) => {
121
- const stream = fs.createReadStream(file);
122
- const requestOptions = this.getRequestOptions('POST', headers, maxBodyLength);
123
- const request = this.getProtocol(url)
124
- .request(url, requestOptions, this.getJsonResponse(resolve, reject));
125
- stream.on('error', err => {
126
- request.abort();
127
- reject(err);
128
- });
129
- request.on('error', err => {
130
- stream.close();
131
- reject(err);
132
- });
133
- stream.on('open', () => stream.pipe(request));
134
- });
135
- }
136
- getUrl(path, query) {
137
- const url = new URL(this.url);
138
- url.pathname += path;
139
- if (query) {
140
- url.search = querystring.stringify(query);
141
- }
142
- return url;
143
- }
144
- getProtocol(url) {
145
- if (url.protocol === 'https:')
146
- return followRedirects.https;
147
- else
148
- return followRedirects.http;
149
- }
150
- getRequestOptions(method, headers, maxBodyLength) {
151
- if (this.username && this.password) {
152
- if (!headers) {
153
- headers = {};
154
- }
155
- const credentials = Buffer.from(this.username + ':' + this.password).toString('base64');
156
- headers['Authorization'] = 'Basic ' + credentials;
157
- }
158
- return {
159
- method,
160
- headers,
161
- maxBodyLength
162
- };
163
- }
164
- getJsonResponse(resolve, reject) {
165
- return response => {
166
- response.setEncoding('UTF-8');
167
- let json = '';
168
- response.on('data', chunk => json += chunk);
169
- response.on('end', () => {
170
- if (response.statusCode !== undefined && (response.statusCode < 200 || response.statusCode > 299)) {
171
- if (json.startsWith('{')) {
172
- try {
173
- const parsed = JSON.parse(json);
174
- const message = parsed.message || parsed.error;
175
- if (message) {
176
- reject(new Error(message));
177
- return;
178
- }
179
- }
180
- catch (err) {
181
- // Ignore the error and reject with response status
182
- }
183
- }
184
- reject(util_1.statusError(response));
185
- }
186
- else if (json.startsWith('<!DOCTYPE html>')) {
187
- reject(json);
188
- }
189
- else {
190
- try {
191
- resolve(JSON.parse(json));
192
- }
193
- catch (err) {
194
- reject(err);
195
- }
196
- }
197
- });
198
- };
199
- }
200
- }
201
- exports.Registry = Registry;
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2019 TypeFox and others
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * SPDX-License-Identifier: EPL-2.0
10
+ ********************************************************************************/
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const fs = require("fs");
13
+ const querystring = require("querystring");
14
+ const followRedirects = require("follow-redirects");
15
+ const util_1 = require("./util");
16
+ exports.DEFAULT_URL = 'https://open-vsx.org';
17
+ exports.DEFAULT_NAMESPACE_SIZE = 1024;
18
+ exports.DEFAULT_PUBLISH_SIZE = 512 * 1024 * 1024;
19
+ class Registry {
20
+ constructor(options = {}) {
21
+ if (options.registryUrl && options.registryUrl.endsWith('/'))
22
+ this.url = options.registryUrl.substring(0, options.registryUrl.length - 1);
23
+ else if (options.registryUrl)
24
+ this.url = options.registryUrl;
25
+ else
26
+ this.url = exports.DEFAULT_URL;
27
+ this.maxNamespaceSize = options.maxNamespaceSize || exports.DEFAULT_NAMESPACE_SIZE;
28
+ this.maxPublishSize = options.maxPublishSize || exports.DEFAULT_PUBLISH_SIZE;
29
+ this.username = options.username;
30
+ this.password = options.password;
31
+ }
32
+ get requiresLicense() {
33
+ const url = new URL(this.url);
34
+ return url.hostname === 'open-vsx.org' || url.hostname.endsWith('.open-vsx.org');
35
+ }
36
+ createNamespace(name, pat) {
37
+ try {
38
+ const query = { token: pat };
39
+ const url = this.getUrl('api/-/namespace/create', query);
40
+ const namespace = { name };
41
+ return this.post(JSON.stringify(namespace), url, {
42
+ 'Content-Type': 'application/json'
43
+ }, this.maxNamespaceSize);
44
+ }
45
+ catch (err) {
46
+ return Promise.reject(err);
47
+ }
48
+ }
49
+ publish(file, pat) {
50
+ try {
51
+ const query = { token: pat };
52
+ const url = this.getUrl('api/-/publish', query);
53
+ return this.postFile(file, url, {
54
+ 'Content-Type': 'application/octet-stream'
55
+ }, this.maxPublishSize);
56
+ }
57
+ catch (err) {
58
+ return Promise.reject(err);
59
+ }
60
+ }
61
+ getMetadata(namespace, extension, target) {
62
+ try {
63
+ let path = `api/${encodeURIComponent(namespace)}/${encodeURIComponent(extension)}`;
64
+ if (target) {
65
+ path += `/${encodeURIComponent(target)}`;
66
+ }
67
+ return this.getJson(this.getUrl(path));
68
+ }
69
+ catch (err) {
70
+ return Promise.reject(err);
71
+ }
72
+ }
73
+ download(file, url) {
74
+ return new Promise((resolve, reject) => {
75
+ const stream = fs.createWriteStream(file);
76
+ const requestOptions = this.getRequestOptions();
77
+ const request = this.getProtocol(url)
78
+ .request(url, requestOptions, response => {
79
+ response.on('end', () => {
80
+ if (response.statusCode !== undefined && (response.statusCode < 200 || response.statusCode > 299)) {
81
+ reject(util_1.statusError(response));
82
+ }
83
+ else {
84
+ resolve();
85
+ }
86
+ });
87
+ response.pipe(stream);
88
+ });
89
+ stream.on('error', err => {
90
+ request.abort();
91
+ reject(err);
92
+ });
93
+ request.on('error', err => {
94
+ stream.close();
95
+ reject(err);
96
+ });
97
+ request.end();
98
+ });
99
+ }
100
+ getJson(url) {
101
+ return new Promise((resolve, reject) => {
102
+ const requestOptions = this.getRequestOptions();
103
+ const request = this.getProtocol(url)
104
+ .request(url, requestOptions, this.getJsonResponse(resolve, reject));
105
+ request.on('error', reject);
106
+ request.end();
107
+ });
108
+ }
109
+ post(content, url, headers, maxBodyLength) {
110
+ return new Promise((resolve, reject) => {
111
+ const requestOptions = this.getRequestOptions('POST', headers, maxBodyLength);
112
+ const request = this.getProtocol(url)
113
+ .request(url, requestOptions, this.getJsonResponse(resolve, reject));
114
+ request.on('error', reject);
115
+ request.write(content);
116
+ request.end();
117
+ });
118
+ }
119
+ postFile(file, url, headers, maxBodyLength) {
120
+ return new Promise((resolve, reject) => {
121
+ const stream = fs.createReadStream(file);
122
+ const requestOptions = this.getRequestOptions('POST', headers, maxBodyLength);
123
+ const request = this.getProtocol(url)
124
+ .request(url, requestOptions, this.getJsonResponse(resolve, reject));
125
+ stream.on('error', err => {
126
+ request.abort();
127
+ reject(err);
128
+ });
129
+ request.on('error', err => {
130
+ stream.close();
131
+ reject(err);
132
+ });
133
+ stream.on('open', () => stream.pipe(request));
134
+ });
135
+ }
136
+ getUrl(path, query) {
137
+ const url = new URL(this.url);
138
+ url.pathname += path;
139
+ if (query) {
140
+ url.search = querystring.stringify(query);
141
+ }
142
+ return url;
143
+ }
144
+ getProtocol(url) {
145
+ if (url.protocol === 'https:')
146
+ return followRedirects.https;
147
+ else
148
+ return followRedirects.http;
149
+ }
150
+ getRequestOptions(method, headers, maxBodyLength) {
151
+ if (this.username && this.password) {
152
+ if (!headers) {
153
+ headers = {};
154
+ }
155
+ const credentials = Buffer.from(this.username + ':' + this.password).toString('base64');
156
+ headers['Authorization'] = 'Basic ' + credentials;
157
+ }
158
+ return {
159
+ method,
160
+ headers,
161
+ maxBodyLength
162
+ };
163
+ }
164
+ getJsonResponse(resolve, reject) {
165
+ return response => {
166
+ response.setEncoding('UTF-8');
167
+ let json = '';
168
+ response.on('data', chunk => json += chunk);
169
+ response.on('end', () => {
170
+ if (response.statusCode !== undefined && (response.statusCode < 200 || response.statusCode > 299)) {
171
+ if (json.startsWith('{')) {
172
+ try {
173
+ const parsed = JSON.parse(json);
174
+ const message = parsed.message || parsed.error;
175
+ if (message) {
176
+ reject(new Error(message));
177
+ return;
178
+ }
179
+ }
180
+ catch (err) {
181
+ // Ignore the error and reject with response status
182
+ }
183
+ }
184
+ reject(util_1.statusError(response));
185
+ }
186
+ else if (json.startsWith('<!DOCTYPE html>')) {
187
+ reject(json);
188
+ }
189
+ else {
190
+ try {
191
+ resolve(JSON.parse(json));
192
+ }
193
+ catch (err) {
194
+ reject(err);
195
+ }
196
+ }
197
+ });
198
+ };
199
+ }
200
+ }
201
+ exports.Registry = Registry;
202
202
  //# sourceMappingURL=registry.js.map