@heroku/buildpack-registry 1.0.1 → 1.0.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/README.md CHANGED
@@ -1,2 +1,13 @@
1
1
  # buildpack-registry.js
2
+
2
3
  Node.js/TypeScript library for interacting with the [Heroku Buildpack Registry](https://devcenter.heroku.com/articles/buildpack-registry).
4
+
5
+ ## Related
6
+
7
+ If you are looking for the heroku CLI plugin:
8
+
9
+ ```
10
+ $ heroku plugins:install @heroku-cli/plugin-buildpack-registry
11
+ ```
12
+
13
+ It is at a different (private) repo [`@heroku-cli/plugin-buildpack-registry`](https://github.com/heroku/plugin-buildpack-registry). That plugin uses this library to interact with the buildpack registry.
@@ -1,10 +1,10 @@
1
1
  import { Headers, Response } from 'node-fetch';
2
2
  export { Response } from 'node-fetch';
3
- export declare type IBody = {
3
+ export type IBody = {
4
4
  [property: string]: string;
5
5
  };
6
- export declare type RevisionStatus = 'pending' | 'published' | 'failed';
7
- export declare type RevisionBody = {
6
+ export type RevisionStatus = 'pending' | 'published' | 'failed';
7
+ export type RevisionBody = {
8
8
  id: string;
9
9
  buildpack_id: string;
10
10
  published_by_email?: string;
@@ -19,13 +19,13 @@ export declare type RevisionBody = {
19
19
  published_by_id: string;
20
20
  license: string;
21
21
  };
22
- export declare type ReadmeBody = {
22
+ export type ReadmeBody = {
23
23
  content?: string;
24
24
  encoding?: string;
25
25
  sha?: string;
26
26
  };
27
- export declare type Category = 'languages' | 'tools' | 'packages';
28
- export declare type BuildpackBody = {
27
+ export type Category = 'languages' | 'tools' | 'packages';
28
+ export type BuildpackBody = {
29
29
  id: string;
30
30
  name: string;
31
31
  created_at: Date;
@@ -57,7 +57,7 @@ export declare type BuildpackBody = {
57
57
  };
58
58
  };
59
59
  };
60
- export declare type HeaderOptions = {
60
+ export type HeaderOptions = {
61
61
  token?: string;
62
62
  secondFactor?: string;
63
63
  };
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const node_fetch_1 = require("node-fetch");
3
+ exports.BuildpackRegistryApi = exports.Response = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fetch_1 = tslib_1.__importStar(require("node-fetch"));
4
6
  var node_fetch_2 = require("node-fetch");
5
- exports.Response = node_fetch_2.Response;
7
+ Object.defineProperty(exports, "Response", { enumerable: true, get: function () { return node_fetch_2.Response; } });
6
8
  class BuildpackRegistryApi {
7
9
  static url() {
8
10
  if (process.env.HEROKU_BUILDPACK_REGISTRY_URL === undefined) {
@@ -16,7 +18,7 @@ class BuildpackRegistryApi {
16
18
  return new BuildpackRegistryApi();
17
19
  }
18
20
  headers(options = {}) {
19
- let defaultHeaders = {
21
+ const defaultHeaders = {
20
22
  Accept: 'application/vnd.heroku+json; version=3.buildpack-registry',
21
23
  'Content-Type': 'application/json'
22
24
  };
@@ -27,25 +29,25 @@ class BuildpackRegistryApi {
27
29
  defaultHeaders['Heroku-Two-Factor-Code'] = options.secondFactor;
28
30
  }
29
31
  if (process.env.HEROKU_HEADERS) {
30
- let herokuHeaders = JSON.parse(process.env.HEROKU_HEADERS);
31
- return new node_fetch_1.Headers(Object.assign({}, defaultHeaders, { herokuHeaders }));
32
+ const herokuHeaders = JSON.parse(process.env.HEROKU_HEADERS);
33
+ return new node_fetch_1.Headers(Object.assign(Object.assign({}, defaultHeaders), { herokuHeaders }));
32
34
  }
33
35
  else {
34
36
  return new node_fetch_1.Headers(defaultHeaders);
35
37
  }
36
38
  }
37
39
  async post(path, body, headers) {
38
- let options = {
40
+ const options = {
39
41
  method: 'POST',
40
42
  headers: headers ? headers : this.headers(),
41
43
  };
42
44
  if (body) {
43
45
  options.body = JSON.stringify(body);
44
46
  }
45
- return node_fetch_1.default(`${BuildpackRegistryApi.url()}${path}`, options);
47
+ return (0, node_fetch_1.default)(`${BuildpackRegistryApi.url()}${path}`, options);
46
48
  }
47
49
  async get(path) {
48
- return node_fetch_1.default(`${BuildpackRegistryApi.url()}${path}`, {
50
+ return (0, node_fetch_1.default)(`${BuildpackRegistryApi.url()}${path}`, {
49
51
  headers: this.headers()
50
52
  });
51
53
  }
@@ -1,16 +1,16 @@
1
1
  import { Result } from 'true-myth';
2
2
  import { BuildpackBody, BuildpackRegistryApi as Api, Category, ReadmeBody, Response, RevisionBody, RevisionStatus } from './buildpack-registry-api';
3
3
  export { BuildpackBody, Category, ReadmeBody, RevisionBody, RevisionStatus };
4
- export declare type BuildpackSlugResult = {
4
+ export type BuildpackSlugResult = {
5
5
  result: boolean;
6
6
  error?: string;
7
7
  };
8
- export declare type ResponseError = {
8
+ export type ResponseError = {
9
9
  status: number;
10
10
  path: string;
11
11
  description: string;
12
12
  };
13
- export declare type InfoData = {
13
+ export type InfoData = {
14
14
  license: string;
15
15
  category?: string;
16
16
  description: string;
@@ -31,6 +31,6 @@ export declare class BuildpackRegistry {
31
31
  revisionInfo(buildpack: string, revision_id: string): Promise<Result<RevisionBody, ResponseError>>;
32
32
  buildpackExists(buildpack: string): Promise<Response>;
33
33
  listVersions(buildpack: string): Promise<Result<RevisionBody[], ResponseError>>;
34
- delay(ms: number): Promise<{}>;
34
+ delay(ms: number): Promise<unknown>;
35
35
  waitForRelease(buildpack_id: string, revision_id: string): Promise<RevisionStatus>;
36
36
  }
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuildpackRegistry = void 0;
3
4
  const true_myth_1 = require("true-myth");
4
5
  const buildpack_registry_api_1 = require("./buildpack-registry-api");
5
6
  const BUILDPACK_FORMATTING_MESSAGE = "To specify a buildpack, please format it like the following: namespace/name (e.g. heroku/ruby). Also names can only contain letters, numbers, '_', and '-'.";
6
7
  class BuildpackRegistry {
7
8
  static isValidBuildpackSlug(buildpack) {
8
- let nameParts = buildpack.split('/');
9
+ const nameParts = buildpack.split('/');
9
10
  if (nameParts.length === 2 && nameParts[0].length > 0 && nameParts[1].length > 0 && /^[a-z0-9][a-z0-9_\-]*$/i.exec(nameParts[1])) {
10
11
  return true_myth_1.Result.ok(true);
11
12
  }
@@ -17,10 +18,10 @@ class BuildpackRegistry {
17
18
  this.api = buildpack_registry_api_1.BuildpackRegistryApi.create();
18
19
  }
19
20
  async requiresTwoFactor(buildpack) {
20
- let path = `/buildpacks/${encodeURIComponent(buildpack)}`;
21
- let response = await this.api.get(path);
21
+ const path = `/buildpacks/${encodeURIComponent(buildpack)}`;
22
+ const response = await this.api.get(path);
22
23
  if (response.status === 200) {
23
- let body = await response.json();
24
+ const body = await response.json();
24
25
  return true_myth_1.Result.ok(body.two_factor_authentication);
25
26
  }
26
27
  else {
@@ -32,13 +33,13 @@ class BuildpackRegistry {
32
33
  }
33
34
  }
34
35
  async publish(buildpack, ref, token, secondFactor) {
35
- let options = { token };
36
+ const options = { token };
36
37
  if (secondFactor !== undefined) {
37
38
  options.secondFactor = secondFactor;
38
39
  }
39
- let path = `/buildpacks/${encodeURIComponent(buildpack)}/revisions`;
40
- let response = await this.api.post(path, { ref }, this.api.headers(options));
41
- if (response.status === 200) {
40
+ const path = `/buildpacks/${encodeURIComponent(buildpack)}/revisions`;
41
+ const response = await this.api.post(path, { ref }, this.api.headers(options));
42
+ if (response.status >= 200 && response.status < 300) {
42
43
  return true_myth_1.Result.ok(await response.json());
43
44
  }
44
45
  else {
@@ -50,12 +51,12 @@ class BuildpackRegistry {
50
51
  }
51
52
  }
52
53
  async rollback(buildpack, token, secondFactor) {
53
- let options = { token };
54
+ const options = { token };
54
55
  if (secondFactor !== undefined) {
55
56
  options.secondFactor = secondFactor;
56
57
  }
57
- let path = `/buildpacks/${encodeURIComponent(buildpack)}/actions/rollback`;
58
- let response = await this.api.post(path, undefined, this.api.headers(options));
58
+ const path = `/buildpacks/${encodeURIComponent(buildpack)}/actions/rollback`;
59
+ const response = await this.api.post(path, undefined, this.api.headers(options));
59
60
  if (response.status === 200) {
60
61
  return true_myth_1.Result.ok(await response.json());
61
62
  }
@@ -84,8 +85,8 @@ class BuildpackRegistry {
84
85
  if (queryParams.length > 0) {
85
86
  queryString = `?${queryParams.join('&')}`;
86
87
  }
87
- let path = `/buildpacks${queryString}`;
88
- let response = await this.api.get(path);
88
+ const path = `/buildpacks${queryString}`;
89
+ const response = await this.api.get(path);
89
90
  if (response.status === 200) {
90
91
  return true_myth_1.Result.ok(await response.json());
91
92
  }
@@ -107,13 +108,13 @@ class BuildpackRegistry {
107
108
  description: await response.text(),
108
109
  });
109
110
  }
110
- let bp_body = await response.json();
111
- let result = await this.listVersions(buildpack);
111
+ const bp_body = await response.json();
112
+ const result = await this.listVersions(buildpack);
112
113
  if (result.isErr()) {
113
114
  return true_myth_1.Result.err(result.unsafelyUnwrapErr());
114
115
  }
115
- let revisions = result.unsafelyUnwrap();
116
- let revision = revisions.sort((a, b) => {
116
+ const revisions = result.unsafelyUnwrap();
117
+ const revision = revisions.sort((a, b) => {
117
118
  return a.release > b.release ? -1 : 1;
118
119
  })[0];
119
120
  path = `/buildpacks/${encodeURIComponent(buildpack)}/readme`;
@@ -125,8 +126,8 @@ class BuildpackRegistry {
125
126
  description: await response.text()
126
127
  });
127
128
  }
128
- let readme = await response.json();
129
- let data = {
129
+ const readme = await response.json();
130
+ const data = {
130
131
  description: bp_body.description,
131
132
  category: bp_body.category,
132
133
  license: revision.license
@@ -152,12 +153,12 @@ class BuildpackRegistry {
152
153
  return true_myth_1.Result.ok(data);
153
154
  }
154
155
  async archive(buildpack, token, secondFactor) {
155
- let options = { token };
156
+ const options = { token };
156
157
  if (secondFactor !== undefined) {
157
158
  options.secondFactor = secondFactor;
158
159
  }
159
- let path = `/buildpacks/${encodeURIComponent(buildpack)}/actions/archive`;
160
- let response = await this.api.post(path, undefined, this.api.headers(options));
160
+ const path = `/buildpacks/${encodeURIComponent(buildpack)}/actions/archive`;
161
+ const response = await this.api.post(path, undefined, this.api.headers(options));
161
162
  if (response.status === 200) {
162
163
  return true_myth_1.Result.ok(await response.json());
163
164
  }
@@ -170,8 +171,8 @@ class BuildpackRegistry {
170
171
  }
171
172
  }
172
173
  async revisionInfo(buildpack, revision_id) {
173
- let path = `/buildpacks/${encodeURIComponent(buildpack)}/revisions/${encodeURIComponent(revision_id)}`;
174
- let response = await this.api.get(path);
174
+ const path = `/buildpacks/${encodeURIComponent(buildpack)}/revisions/${encodeURIComponent(revision_id)}`;
175
+ const response = await this.api.get(path);
175
176
  if (response.status === 200) {
176
177
  return true_myth_1.Result.ok(await response.json());
177
178
  }
@@ -187,8 +188,8 @@ class BuildpackRegistry {
187
188
  return this.api.get(`/buildpacks/${encodeURIComponent(buildpack)}`);
188
189
  }
189
190
  async listVersions(buildpack) {
190
- let path = `/buildpacks/${encodeURIComponent(buildpack)}/revisions`;
191
- let response = await this.api.get(path);
191
+ const path = `/buildpacks/${encodeURIComponent(buildpack)}/revisions`;
192
+ const response = await this.api.get(path);
192
193
  if (response.status === 200) {
193
194
  return true_myth_1.Result.ok(await response.json());
194
195
  }
@@ -201,20 +202,17 @@ class BuildpackRegistry {
201
202
  }
202
203
  }
203
204
  async delay(ms) {
204
- // Disable lint is Temporary
205
- // until this issue is resolved https://github.com/Microsoft/tslint-microsoft-contrib/issues/355#issuecomment-407209401
206
- // tslint:disable-next-line no-string-based-set-timeout
207
205
  return new Promise(resolve => setTimeout(resolve, ms));
208
206
  }
209
207
  async waitForRelease(buildpack_id, revision_id) {
210
208
  let status = 'failed';
211
209
  let status_count = 0;
212
- let running = true;
210
+ const running = true;
213
211
  while (running) {
214
212
  status_count += 1;
215
- let result = await this.revisionInfo(buildpack_id, revision_id);
213
+ const result = await this.revisionInfo(buildpack_id, revision_id);
216
214
  if (result.isOk()) {
217
- let revision = result.unsafelyUnwrap();
215
+ const revision = result.unsafelyUnwrap();
218
216
  status = revision.status;
219
217
  if (status !== 'pending') {
220
218
  break;
@@ -1,2 +1,2 @@
1
1
  export { BuildpackBody, BuildpackRegistry, BuildpackSlugResult, Category, InfoData, ReadmeBody, ResponseError, RevisionBody, RevisionStatus, } from './buildpack-registry';
2
- export { Fixture } from './test/helpers/fixture';
2
+ export { Fixture } from '../test/helpers/fixture';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Fixture = exports.BuildpackRegistry = void 0;
4
+ var buildpack_registry_1 = require("./buildpack-registry");
5
+ Object.defineProperty(exports, "BuildpackRegistry", { enumerable: true, get: function () { return buildpack_registry_1.BuildpackRegistry; } });
6
+ var fixture_1 = require("../test/helpers/fixture");
7
+ Object.defineProperty(exports, "Fixture", { enumerable: true, get: function () { return fixture_1.Fixture; } });
@@ -1,4 +1,4 @@
1
- import { BuildpackBody, ReadmeBody, RevisionBody } from '../../buildpack-registry';
1
+ import { BuildpackBody, ReadmeBody, RevisionBody } from '../../src/buildpack-registry-api';
2
2
  export declare namespace Fixture {
3
3
  function buildpack(options?: Partial<BuildpackBody>): BuildpackBody;
4
4
  function revision(options?: Partial<RevisionBody>): RevisionBody;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Fixture = void 0;
3
4
  var Fixture;
4
5
  (function (Fixture) {
5
6
  function buildpack(options) {
6
- let base = {
7
+ const base = {
7
8
  id: '3ef8f543-b953-4a26-b410-8807d1b45eb1',
8
9
  name: 'scala',
9
10
  created_at: new Date(),
@@ -33,7 +34,7 @@ var Fixture;
33
34
  }
34
35
  };
35
36
  if (options) {
36
- return Object.assign({}, base, options);
37
+ return Object.assign(Object.assign({}, base), options);
37
38
  }
38
39
  else {
39
40
  return base;
@@ -41,7 +42,7 @@ var Fixture;
41
42
  }
42
43
  Fixture.buildpack = buildpack;
43
44
  function revision(options) {
44
- let base = {
45
+ const base = {
45
46
  id: '8de70dbe-e862-4d51-b906-123ef3bf2fc5',
46
47
  buildpack_id: '71a3c00a-d6c7-4393-94c5-d5d71531720e',
47
48
  published_by_email: undefined,
@@ -57,7 +58,7 @@ var Fixture;
57
58
  license: 'MIT'
58
59
  };
59
60
  if (options) {
60
- return Object.assign({}, base, options);
61
+ return Object.assign(Object.assign({}, base), options);
61
62
  }
62
63
  else {
63
64
  return base;
@@ -65,17 +66,17 @@ var Fixture;
65
66
  }
66
67
  Fixture.revision = revision;
67
68
  function readme(options) {
68
- let base = {
69
+ const base = {
69
70
  content: 'IyBIZXJva3UgRXhlYyBCdWlsZHBhY2sKClRoaXMgaXMgYSBbSGVyb2t1IEJ1\naWxkcGFja10oaHR0cHM6Ly9kZXZjZW50ZXIuaGVyb2t1LmNvbS9hcnRpY2xl\ncy9idWlsZHBhY2tzKQp0aGF0IHdvcmtzIHdpdGggdGhlIFtIZXJva3UgRXhl\nY10oaHR0cHM6Ly9kZXZjZW50ZXIuaGVyb2t1LmNvbS9hcnRpY2xlcy9oZXJv\na3UtZXhlYykgZmVhdHVyZS4K\n',
70
71
  encoding: 'base64',
71
72
  sha: 'a5e1e5f5eb76095087b32b31caf5ccaee0c2cae6'
72
73
  };
73
74
  if (options) {
74
- return Object.assign({}, base, options);
75
+ return Object.assign(Object.assign({}, base), options);
75
76
  }
76
77
  else {
77
78
  return base;
78
79
  }
79
80
  }
80
81
  Fixture.readme = readme;
81
- })(Fixture = exports.Fixture || (exports.Fixture = {}));
82
+ })(Fixture || (exports.Fixture = Fixture = {}));
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@heroku/buildpack-registry",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Node.js/TypeScript library for interfacing with the Heroku Buildpack Registry",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "prepare": "tsc",
9
- "test": "nyc mocha --forbid-only \"test/**/*.test.ts\"",
10
- "posttest": "tsc -p test --noEmit && tslint -p test -t stylish"
9
+ "lint": "eslint .",
10
+ "test": "vitest run --coverage",
11
+ "posttest": "tsc -p test --noEmit && npm run lint"
11
12
  },
12
13
  "repository": {
13
14
  "type": "git",
@@ -20,24 +21,21 @@
20
21
  },
21
22
  "homepage": "https://github.com/heroku/buildpack-registry.js#readme",
22
23
  "devDependencies": {
23
- "@types/chai": "^4.1.4",
24
- "@types/mocha": "^5.2.5",
25
- "@types/nock": "^9.3.0",
26
- "@types/node": "^10.7.1",
24
+ "@types/node": "^20.14.8",
27
25
  "@types/node-fetch": "^2.1.2",
28
- "mocha": "^5",
29
- "nock": "^9.2.6",
30
- "nyc": "^11",
31
- "ts-node": "^6",
32
- "tslint": "^5.11.0",
33
- "typescript": "^2.8"
26
+ "@vitest/coverage-v8": "^4.0.0",
27
+ "eslint": "^9.0.0",
28
+ "nock": "^13.3",
29
+ "typescript": "^5.7",
30
+ "typescript-eslint": "^8.0.0",
31
+ "vitest": "^4.0.0"
34
32
  },
35
33
  "dependencies": {
36
34
  "node-fetch": "^2.2.0",
37
35
  "true-myth": "^2.0.0"
38
36
  },
39
37
  "engines": {
40
- "node": ">= 8.0.0"
38
+ "node": ">= 20"
41
39
  },
42
40
  "files": [
43
41
  "/dist"
package/dist/index.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var buildpack_registry_1 = require("./buildpack-registry");
4
- exports.BuildpackRegistry = buildpack_registry_1.BuildpackRegistry;
5
- var fixture_1 = require("./test/helpers/fixture");
6
- exports.Fixture = fixture_1.Fixture;