@eik/cli 3.0.0-next.2 → 3.1.0

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 (94) hide show
  1. package/CHANGELOG.md +152 -9
  2. package/classes/alias.js +49 -22
  3. package/classes/index.js +47 -23
  4. package/classes/integrity.js +27 -16
  5. package/classes/login.js +21 -7
  6. package/classes/meta.js +20 -12
  7. package/classes/ping.js +20 -9
  8. package/classes/publish/map.js +33 -10
  9. package/classes/publish/package/index.js +54 -17
  10. package/classes/publish/package/tasks/check-bundle-sizes.js +7 -11
  11. package/classes/publish/package/tasks/check-if-already-published.js +8 -11
  12. package/classes/publish/package/tasks/cleanup.js +7 -9
  13. package/classes/publish/package/tasks/create-temp-directory.js +5 -9
  14. package/classes/publish/package/tasks/create-zip-file.js +6 -11
  15. package/classes/publish/package/tasks/dry-run.js +4 -8
  16. package/classes/publish/package/tasks/save-metafile.js +5 -7
  17. package/classes/publish/package/tasks/task.js +3 -5
  18. package/classes/publish/package/tasks/upload-files.js +16 -17
  19. package/classes/publish/package/tasks/validate-input.js +4 -8
  20. package/classes/version.js +38 -21
  21. package/commands/alias.js +51 -71
  22. package/commands/index.js +27 -0
  23. package/commands/init.js +69 -52
  24. package/commands/integrity.js +15 -32
  25. package/commands/login.js +23 -35
  26. package/commands/map-alias.js +95 -0
  27. package/commands/map.js +90 -0
  28. package/commands/meta.js +12 -29
  29. package/commands/npm-alias.js +90 -0
  30. package/commands/package-alias.js +102 -0
  31. package/commands/ping.js +11 -21
  32. package/commands/publish.js +82 -138
  33. package/commands/version.js +16 -33
  34. package/formatters/alias.js +8 -14
  35. package/formatters/artifact.js +8 -8
  36. package/formatters/file.js +3 -10
  37. package/formatters/index.js +5 -5
  38. package/formatters/version.js +5 -12
  39. package/index.js +53 -12
  40. package/package.json +49 -52
  41. package/readme.md +16 -4
  42. package/types/classes/alias.d.ts +60 -0
  43. package/types/classes/index.d.ts +37 -0
  44. package/types/classes/integrity.d.ts +35 -0
  45. package/types/classes/login.d.ts +25 -0
  46. package/types/classes/meta.d.ts +28 -0
  47. package/types/classes/ping.d.ts +23 -0
  48. package/types/classes/publish/map.d.ts +51 -0
  49. package/types/classes/publish/package/index.d.ts +94 -0
  50. package/types/classes/publish/package/tasks/check-bundle-sizes.d.ts +4 -0
  51. package/types/classes/publish/package/tasks/check-if-already-published.d.ts +4 -0
  52. package/types/classes/publish/package/tasks/cleanup.d.ts +4 -0
  53. package/types/classes/publish/package/tasks/create-temp-directory.d.ts +4 -0
  54. package/types/classes/publish/package/tasks/create-zip-file.d.ts +4 -0
  55. package/types/classes/publish/package/tasks/dry-run.d.ts +7 -0
  56. package/types/classes/publish/package/tasks/save-metafile.d.ts +4 -0
  57. package/types/classes/publish/package/tasks/task.d.ts +8 -0
  58. package/types/classes/publish/package/tasks/upload-files.d.ts +4 -0
  59. package/types/classes/publish/package/tasks/validate-input.d.ts +4 -0
  60. package/types/classes/version.d.ts +43 -0
  61. package/types/utils/hash/compare.d.ts +2 -0
  62. package/types/utils/hash/file.d.ts +2 -0
  63. package/types/utils/hash/files.d.ts +2 -0
  64. package/types/utils/hash/index.d.ts +9 -0
  65. package/types/utils/http/index.d.ts +12 -0
  66. package/types/utils/http/integrity.d.ts +2 -0
  67. package/types/utils/http/latest-version.d.ts +2 -0
  68. package/types/utils/http/request.d.ts +33 -0
  69. package/types/utils/http/versions.d.ts +5 -0
  70. package/types/utils/index.d.ts +6 -0
  71. package/types/utils/json/index.d.ts +9 -0
  72. package/types/utils/json/read.d.ts +5 -0
  73. package/types/utils/json/write-eik.d.ts +5 -0
  74. package/types/utils/json/write.d.ts +5 -0
  75. package/types/utils/logger.d.ts +33 -0
  76. package/types/utils/type-title.d.ts +2 -0
  77. package/utils/hash/compare.js +1 -3
  78. package/utils/hash/file.js +3 -5
  79. package/utils/hash/files.js +4 -6
  80. package/utils/hash/index.js +4 -4
  81. package/utils/http/index.js +6 -5
  82. package/utils/http/integrity.js +2 -5
  83. package/utils/http/latest-version.js +2 -5
  84. package/utils/http/request.js +25 -19
  85. package/utils/http/versions.js +2 -5
  86. package/utils/index.js +5 -4
  87. package/utils/json/index.js +4 -4
  88. package/utils/json/read.js +5 -7
  89. package/utils/json/write-eik.js +4 -6
  90. package/utils/json/write.js +4 -6
  91. package/utils/logger.js +2 -5
  92. package/utils/type-title.js +1 -1
  93. package/utils/get-cwd.js +0 -14
  94. package/utils/type-slug.js +0 -4
package/CHANGELOG.md CHANGED
@@ -1,29 +1,172 @@
1
- # [3.0.0-next.2](https://github.com/eik-lib/cli/compare/v3.0.0-next.1...v3.0.0-next.2) (2022-08-17)
1
+ # [3.1.0](https://github.com/eik-lib/cli/compare/v3.0.2...v3.1.0) (2024-08-15)
2
+
3
+
4
+ ### Features
5
+
6
+ * add support for image namespace publishing and aliasing ([a1a7e4c](https://github.com/eik-lib/cli/commit/a1a7e4c676cc45d30c63f4e522771298947dc47d))
7
+
8
+ ## [3.0.2](https://github.com/eik-lib/cli/compare/v3.0.1...v3.0.2) (2024-08-14)
2
9
 
3
10
 
4
11
  ### Bug Fixes
5
12
 
6
- * incorrect version number displayed on alias when updating with a cache layer infront ([8c468d6](https://github.com/eik-lib/cli/commit/8c468d670f6f10f25ae4decdab7a6950a1093d6a))
13
+ * include semantic release plugins from common package ([ac9e5a1](https://github.com/eik-lib/cli/commit/ac9e5a1ebd7dfda2ab77625f2c8c8c5dee5f8c31))
7
14
 
15
+ # [3.0.0](https://github.com/eik-lib/cli/compare/v2.0.39...v3.0.0) (2024-08-12)
8
16
 
9
- ### Features
10
17
 
11
- * **!:** new alias command for all types of packages ([e482880](https://github.com/eik-lib/cli/commit/e48288002e9e8942f71d8f8dd0583395152aff49))
18
+ ### Bug Fixes
12
19
 
20
+ * include type definitions for programatic API ([96d6079](https://github.com/eik-lib/cli/commit/96d6079145198f5df3cd353952e9bac4d530031d))
21
+ * add jsdoc for publish commands as well ([a2b51c8](https://github.com/eik-lib/cli/commit/a2b51c86fe10ab84aa21e07151007fdc723e36c4))
22
+ * update boxen, chalk and ora ([73a200f](https://github.com/eik-lib/cli/commit/73a200f20a59edc69abc5fb3d8760fbf2630b0c1))
23
+ * update date-fns ([0b32270](https://github.com/eik-lib/cli/commit/0b322700cd62e73052eef42016658931c27202c2))
24
+ * update Eik common to v4.0.0 ([1078484](https://github.com/eik-lib/cli/commit/107848440a11eac4cc5b49a33fb172bffe43e1d9))
25
+ * update gzip-size ([6075766](https://github.com/eik-lib/cli/commit/6075766b9a3c60f91b7d64374e9396b87fb9294c))
26
+ * update make-dir ([8d9c939](https://github.com/eik-lib/cli/commit/8d9c939449e0adfd8bed33d517f8e219d6790a74))
27
+ * update rimraf ([3e40b11](https://github.com/eik-lib/cli/commit/3e40b11b527c722f4ecf51872f0b09d82eef034b))
28
+ * update ssri package ([944426a](https://github.com/eik-lib/cli/commit/944426add01481af20232410b3d86fc983b73da8))
29
+ * update tar package ([41c8227](https://github.com/eik-lib/cli/commit/41c8227578b166682c00c6dd841bcb972f475433))
30
+ * update to Eik common v4.0.1 ([fb69c35](https://github.com/eik-lib/cli/commit/fb69c35c085266571d2352a60ebe9c9783e21d46))
13
31
 
14
- ### BREAKING CHANGES
15
32
 
16
- * **!:** New alias command that is to be used for creating package, npm and import map aliases. Old alias commands have been removed.
33
+ ### chore
17
34
 
18
- # [3.0.0-next.1](https://github.com/eik-lib/cli/compare/v2.0.22...v3.0.0-next.1) (2022-08-17)
35
+ * convert codebase to ESM ([f3c4c74](https://github.com/eik-lib/cli/commit/f3c4c746cc3ac283d0f8e493682af34086831f51))
19
36
 
20
37
 
21
- * feat(publish)!: include map publishing in "publish" command ([7968274](https://github.com/eik-lib/cli/commit/796827442b28bb9852af63137275535fae737c21))
38
+ ### Features
22
39
 
40
+ * add `eik alias` command as an eventual replacement for the 3 existing alias commands ([ff4a27c](https://github.com/eik-lib/cli/commit/ff4a27cc8e46f55321a6c814d23a111737eba29d))
41
+ * add `eik --version` and `eik -v` to list eik cli version ([5ddd162](https://github.com/eik-lib/cli/commit/5ddd16245a3285d9ebd002aa35d96557d50c2bd5))
42
+ * init reads name and version from `package.json` ([6effb76](https://github.com/eik-lib/cli/commit/6effb768a7c2ec5110d935201960d9d872abff48))
43
+ * support specifying a config file using `--config` or `-c` cli flags ([a78b9de](https://github.com/eik-lib/cli/commit/a78b9de9f8f8e7e64bcdf24e649e0c27ea6eec1f))
23
44
 
24
45
  ### BREAKING CHANGES
25
46
 
26
- * the map command has been removed in favour of a single publish command
47
+ * remove `eik v` alias ([80ac9b6](https://github.com/eik-lib/cli/commit/80ac9b62a2cc7d53fd4e5dbbbd983efc490214bd))
48
+ * JavaScript API is now ESM only and no longer supports CJS
49
+
50
+
51
+ ## [2.0.39](https://github.com/eik-lib/cli/compare/v2.0.38...v2.0.39) (2024-07-29)
52
+
53
+
54
+ ### Bug Fixes
55
+
56
+ * **deps:** update dependency semver to v7.6.3 ([7c6f254](https://github.com/eik-lib/cli/commit/7c6f254e6ff37529d250dcc8dcbedac719dd5cff))
57
+
58
+ ## [2.0.38](https://github.com/eik-lib/cli/compare/v2.0.37...v2.0.38) (2024-05-13)
59
+
60
+
61
+ ### Bug Fixes
62
+
63
+ * include message from base error for unexpected status codes ([#549](https://github.com/eik-lib/cli/issues/549)) ([d5637df](https://github.com/eik-lib/cli/commit/d5637dff5acca4bc8f2cc91799c9c96555e9bf1b))
64
+
65
+ ## [2.0.37](https://github.com/eik-lib/cli/compare/v2.0.36...v2.0.37) (2024-05-06)
66
+
67
+
68
+ ### Bug Fixes
69
+
70
+ * **deps:** update dependency abslog to v2.4.4 ([e05835c](https://github.com/eik-lib/cli/commit/e05835c9b934ff8bf91b2092083b9da2ef9d2994))
71
+
72
+ ## [2.0.36](https://github.com/eik-lib/cli/compare/v2.0.35...v2.0.36) (2024-04-29)
73
+
74
+
75
+ ### Bug Fixes
76
+
77
+ * **deps:** update dependency abslog to v2.4.2 ([429a659](https://github.com/eik-lib/cli/commit/429a659ece9e50ddd766ac9bceb3fdf98e01060c))
78
+
79
+ ## [2.0.35](https://github.com/eik-lib/cli/compare/v2.0.34...v2.0.35) (2024-04-23)
80
+
81
+
82
+ ### Bug Fixes
83
+
84
+ * update dependencies ([f269dfe](https://github.com/eik-lib/cli/commit/f269dfec6bf6321287b137c309e6f09430c7d3bb))
85
+
86
+ ## [2.0.34](https://github.com/eik-lib/cli/compare/v2.0.33...v2.0.34) (2024-04-11)
87
+
88
+
89
+ ### Bug Fixes
90
+
91
+ * **deps:** update dependency tar to v6.2.1 [security] ([3fef73f](https://github.com/eik-lib/cli/commit/3fef73f7be1ea32339fc5a632e3840899d096b78))
92
+
93
+ ## [2.0.33](https://github.com/eik-lib/cli/compare/v2.0.32...v2.0.33) (2024-02-12)
94
+
95
+
96
+ ### Bug Fixes
97
+
98
+ * **deps:** update dependency semver to v7.6.0 ([ca54c17](https://github.com/eik-lib/cli/commit/ca54c174f54e0a321090a7bf0c7256555f4fe2c4))
99
+
100
+ ## [2.0.32](https://github.com/eik-lib/cli/compare/v2.0.31...v2.0.32) (2024-02-05)
101
+
102
+
103
+ ### Bug Fixes
104
+
105
+ * **deps:** update dependency yargs to v17.7.2 ([d283d0e](https://github.com/eik-lib/cli/commit/d283d0e0a28036f2c012a498ea8a62e40bd3a6a8))
106
+
107
+ ## [2.0.31](https://github.com/eik-lib/cli/compare/v2.0.30...v2.0.31) (2024-02-05)
108
+
109
+
110
+ ### Bug Fixes
111
+
112
+ * **deps:** update dependency tar to v6.2.0 ([f1b98e4](https://github.com/eik-lib/cli/commit/f1b98e40035749b6d9a6e39906b99ed7e8e571d5))
113
+
114
+ ## [2.0.30](https://github.com/eik-lib/cli/compare/v2.0.29...v2.0.30) (2024-02-05)
115
+
116
+
117
+ ### Bug Fixes
118
+
119
+ * **deps:** update dependency node-fetch to v2.7.0 ([cb4f52d](https://github.com/eik-lib/cli/commit/cb4f52dc003d507ba66447e77a15f621d43dcaf0))
120
+
121
+ ## [2.0.29](https://github.com/eik-lib/cli/compare/v2.0.28...v2.0.29) (2024-01-29)
122
+
123
+
124
+ ### Bug Fixes
125
+
126
+ * **deps:** update dependency date-fns to v2.30.0 ([2411b57](https://github.com/eik-lib/cli/commit/2411b574dd776aef52f58e6d3fda91d684b68d9b))
127
+
128
+ ## [2.0.28](https://github.com/eik-lib/cli/compare/v2.0.27...v2.0.28) (2024-01-29)
129
+
130
+
131
+ ### Bug Fixes
132
+
133
+ * **deps:** replace dependency read-pkg-up with read-package-up ([480c0cd](https://github.com/eik-lib/cli/commit/480c0cd06eab6293c6fd7cf3092b03096fb06d3f))
134
+
135
+ ## [2.0.27](https://github.com/eik-lib/cli/compare/v2.0.26...v2.0.27) (2024-01-22)
136
+
137
+
138
+ ### Bug Fixes
139
+
140
+ * **deps:** update dependency semver to v7.5.4 ([71b807a](https://github.com/eik-lib/cli/commit/71b807aa80961aa6d3257963323c36938d611bfd))
141
+
142
+ ## [2.0.26](https://github.com/eik-lib/cli/compare/v2.0.25...v2.0.26) (2024-01-22)
143
+
144
+
145
+ ### Bug Fixes
146
+
147
+ * **deps:** update dependency glob to v7.2.3 ([6e2df77](https://github.com/eik-lib/cli/commit/6e2df7700d72f10a5cc252a968ba70f5ee6fc131))
148
+
149
+ ## [2.0.25](https://github.com/eik-lib/cli/compare/v2.0.24...v2.0.25) (2024-01-20)
150
+
151
+
152
+ ### Bug Fixes
153
+
154
+ * **deps:** update dependency yargs-parser to v21.1.1 ([1c9810a](https://github.com/eik-lib/cli/commit/1c9810a3f4fd614420826a40e1abe0d362e1067a))
155
+
156
+ ## [2.0.24](https://github.com/eik-lib/cli/compare/v2.0.23...v2.0.24) (2024-01-19)
157
+
158
+
159
+ ### Bug Fixes
160
+
161
+ * **deps:** update dependency semver to v7.5.2 [security] ([cfbd1fa](https://github.com/eik-lib/cli/commit/cfbd1fa2d8b9996a41b7acdec6b9b3d274ff25bf))
162
+
163
+ ## [2.0.23](https://github.com/eik-lib/cli/compare/v2.0.22...v2.0.23) (2024-01-19)
164
+
165
+
166
+ ### Bug Fixes
167
+
168
+ * log a more helpful 404 ([763ffda](https://github.com/eik-lib/cli/commit/763ffda93b5247acc7af328094ecd634d1b25b51))
169
+ * print which server you're logging into ([6ec8333](https://github.com/eik-lib/cli/commit/6ec8333eb8bc6c9b535aeb55d1f2226e093286b5))
27
170
 
28
171
  ## [2.0.22](https://github.com/eik-lib/cli/compare/v2.0.21...v2.0.22) (2022-01-28)
29
172
 
package/classes/alias.js CHANGED
@@ -1,17 +1,39 @@
1
- 'use strict';
1
+ import assert from 'assert';
2
+ import abslog from 'abslog';
3
+ import { join } from 'path';
4
+ import { schemas, validators } from '@eik/common';
5
+ import { request } from '../utils/http/index.js';
6
+ import { typeSlug } from '../utils/index.js';
2
7
 
3
- const assert = require('assert');
4
- const abslog = require('abslog');
5
- const { join } = require('path');
8
+ /**
9
+ * @typedef {object} AliasOptions
10
+ * @property {import('abslog').AbstractLoggerOptions} [logger]
11
+ * @property {string} server
12
+ * @property {"package" | "npm" | "map"} [type="package"]
13
+ * @property {string} name
14
+ * @property {string} version
15
+ * @property {string} alias
16
+ * @property {string} token
17
+ */
6
18
 
7
- const validators = require('@eik/common-validators');
8
- const schemas = require('@eik/common-schemas');
19
+ /**
20
+ * @typedef {object} AliasResult
21
+ * @property {string} server
22
+ * @property {string} type
23
+ * @property {string} name
24
+ * @property {string} alias
25
+ * @property {string} version
26
+ * @property {boolean} update
27
+ * @property {string[]} files
28
+ * @property {string} org
29
+ * @property {string} integrity
30
+ */
9
31
 
10
- const { typeSlug } = require('@eik/common-utils');
11
- const { request } = require('../utils/http');
12
-
13
- module.exports = class Alias {
14
- constructor({ logger, server, token, type, name, version, alias } = {}) {
32
+ export default class Alias {
33
+ /**
34
+ * @param {AliasOptions} options
35
+ */
36
+ constructor({ logger, server, token, type, name, version, alias }) {
15
37
  this.log = abslog(logger);
16
38
  this.server = server;
17
39
  this.token = token;
@@ -21,6 +43,9 @@ module.exports = class Alias {
21
43
  this.version = version;
22
44
  }
23
45
 
46
+ /**
47
+ * @returns {Promise<AliasResult>}
48
+ */
24
49
  async run() {
25
50
  const data = {
26
51
  server: this.server,
@@ -46,22 +71,22 @@ module.exports = class Alias {
46
71
  );
47
72
 
48
73
  this.log.debug(
49
- `Requesting creation of ${this.type} alias "v${this.alias}" for ${this.name} v${this.version}`,
74
+ `Requesting creation of ${this.type} alias "v${this.alias}" for ${this.name} v${this.version} on ${this.server}`,
50
75
  );
76
+
77
+ const pathname = join(this.type, this.name, `v${this.alias}`);
51
78
  try {
52
79
  const { message } = await request({
53
80
  host: this.server,
54
81
  method: 'PUT',
55
- pathname: join(this.type, this.name, `v${this.alias}`),
82
+ pathname,
56
83
  data: { version: this.version },
57
84
  token: this.token,
58
85
  });
59
86
 
60
87
  data.org = message.org || '';
61
88
  data.integrity = message.integrity || '';
62
- // We'll use message.version when the cache has been properly purged
63
- // data.version = message.version || this.version;
64
- data.version = this.version;
89
+ data.version = message.version || this.version;
65
90
  data.name = message.name || this.name;
66
91
  data.files = message.files || [];
67
92
 
@@ -70,20 +95,22 @@ module.exports = class Alias {
70
95
  let status = err.statusCode;
71
96
 
72
97
  if (status === 409) {
98
+ this.log.debug(
99
+ 'Alias already exists on server, performing update',
100
+ );
101
+
73
102
  try {
74
103
  const { message: msg } = await request({
75
104
  host: this.server,
76
105
  method: 'POST',
77
- pathname: join(this.type, this.name, `v${this.alias}`),
106
+ pathname,
78
107
  data: { version: this.version },
79
108
  token: this.token,
80
109
  });
81
110
 
82
111
  data.org = msg.org || '';
83
112
  data.integrity = msg.integrity || '';
84
- // We'll use msg.version when the cache has been properly purged
85
- // data.version = msg.version || this.version;
86
- data.version = this.version;
113
+ data.version = msg.version || this.version;
87
114
  data.name = msg.name || this.name;
88
115
  data.files = msg.files || [];
89
116
  data.update = true;
@@ -103,7 +130,7 @@ module.exports = class Alias {
103
130
  throw new Error('Client unauthorized with server');
104
131
  case 404:
105
132
  throw new Error(
106
- 'The server was unable to locate the required resource',
133
+ `The server was unable to locate ${pathname}. Ensure you have the correct package type (eik package-alias vs eik npm-alias), name and that the version exists on the server.`,
107
134
  );
108
135
  case 409:
109
136
  throw new Error(
@@ -122,4 +149,4 @@ module.exports = class Alias {
122
149
  }
123
150
  }
124
151
  }
125
- };
152
+ }
package/classes/index.js CHANGED
@@ -1,44 +1,68 @@
1
- 'use strict';
2
-
3
- const Ping = require('./ping');
4
- const Alias = require('./alias');
5
- const Meta = require('./meta');
6
- const Login = require('./login');
7
- const PublishMap = require('./publish/map');
8
- const PublishPackage = require('./publish/package/index');
9
- const Integrity = require('./integrity');
10
- const Version = require('./version');
11
-
12
- module.exports = {
13
- ping(opts) {
14
- return new Ping(opts).run();
15
- },
1
+ import Ping from './ping.js';
2
+ import Alias from './alias.js';
3
+ import Meta from './meta.js';
4
+ import Login from './login.js';
5
+ import PublishMap from './publish/map.js';
6
+ import PublishPackage from './publish/package/index.js';
7
+ import Integrity from './integrity.js';
8
+ import Version from './version.js';
16
9
 
10
+ export default {
11
+ /**
12
+ * @param {import('./alias.js').AliasOptions} opts
13
+ */
17
14
  alias(opts) {
18
15
  return new Alias(opts).run();
19
16
  },
20
17
 
21
- meta(opts) {
22
- return new Meta(opts).run();
18
+ /**
19
+ * @param {import('./integrity.js').IntegrityOptions} opts
20
+ */
21
+ integrity(opts) {
22
+ return new Integrity(opts).run();
23
23
  },
24
24
 
25
+ /**
26
+ * Log in using a key to get a Bearer token for use with other commands.
27
+ *
28
+ * @param {import('./login.js').LoginOptions} opts
29
+ */
25
30
  login(opts) {
26
31
  return new Login(opts).run();
27
32
  },
28
33
 
29
- integrity(opts) {
30
- return new Integrity(opts).run();
34
+ /**
35
+ * @param {import('./publish/map.js').PublishMapOptions} opts
36
+ */
37
+ map(opts) {
38
+ return new PublishMap(opts).run();
31
39
  },
32
40
 
33
- version(opts) {
34
- return new Version(opts).run();
41
+ /**
42
+ * @param {import('./meta.js').MetaOptions} opts
43
+ */
44
+ meta(opts) {
45
+ return new Meta(opts).run();
35
46
  },
36
47
 
48
+ /**
49
+ * @param {import('./ping.js').PingOptions} opts
50
+ */
51
+ ping(opts) {
52
+ return new Ping(opts).run();
53
+ },
54
+
55
+ /**
56
+ * @param {import('./publish/package/index.js').PublishOptions} opts
57
+ */
37
58
  publish(opts) {
38
59
  return new PublishPackage(opts).run();
39
60
  },
40
61
 
41
- map(opts) {
42
- return new PublishMap(opts).run();
62
+ /**
63
+ * @param {import('./version.js').VersionOptions} opts
64
+ */
65
+ version(opts) {
66
+ return new Version(opts).run();
43
67
  },
44
68
  };
@@ -1,17 +1,26 @@
1
- /* eslint-disable no-await-in-loop */
2
- /* eslint-disable no-plusplus */
3
-
4
- 'use strict';
5
-
6
- const abslog = require('abslog');
7
- const { join } = require('path');
8
-
9
- const schemas = require('@eik/common-schemas');
10
-
11
- const { typeSlug } = require('@eik/common-utils');
12
- const fetch = require('node-fetch');
13
-
14
- module.exports = class Integrity {
1
+ import abslog from 'abslog';
2
+ import { join } from 'path';
3
+ import eik from '@eik/common';
4
+ import { typeSlug } from '../utils/index.js';
5
+
6
+ const { schemas } = eik;
7
+
8
+ /**
9
+ * @typedef {object} IntegrityOptions
10
+ * @property {import('abslog').AbstractLoggerOptions} [logger]
11
+ * @property {string} server
12
+ * @property {"package" | "npm" | "map"} [type="package"]
13
+ * @property {string} name
14
+ * @property {string} version
15
+ * @property {string} [cwd]
16
+ * @property {boolean} [debug]
17
+ */
18
+
19
+ export default class Integrity {
20
+ /**
21
+ *
22
+ * @param {IntegrityOptions} options
23
+ */
15
24
  constructor({
16
25
  logger,
17
26
  name,
@@ -20,7 +29,7 @@ module.exports = class Integrity {
20
29
  type,
21
30
  debug = false,
22
31
  cwd = process.cwd(),
23
- } = {}) {
32
+ }) {
24
33
  this.log = abslog(logger);
25
34
  this.server = server;
26
35
  this.name = name;
@@ -48,6 +57,7 @@ module.exports = class Integrity {
48
57
 
49
58
  this.log.debug(` ==> debug: ${this.debug}`);
50
59
  if (typeof this.debug !== 'boolean') {
60
+ // @ts-expect-error
51
61
  throw new schemas.ValidationError(
52
62
  `Parameter "debug" is not valid`,
53
63
  );
@@ -55,6 +65,7 @@ module.exports = class Integrity {
55
65
 
56
66
  this.log.debug(` ==> cwd: ${this.cwd}`);
57
67
  if (typeof this.cwd !== 'string') {
68
+ // @ts-expect-error
58
69
  throw new schemas.ValidationError(
59
70
  `Parameter "cwd" is not valid`,
60
71
  );
@@ -99,4 +110,4 @@ module.exports = class Integrity {
99
110
  );
100
111
  }
101
112
  }
102
- };
113
+ }
package/classes/login.js CHANGED
@@ -1,22 +1,36 @@
1
- 'use strict';
1
+ import abslog from 'abslog';
2
+ import eik from '@eik/common';
3
+ import { request } from '../utils/http/index.js';
2
4
 
3
- const abslog = require('abslog');
4
- const schemas = require('@eik/common-schemas');
5
- const { request } = require('../utils/http');
5
+ const { schemas } = eik;
6
6
 
7
- module.exports = class Login {
8
- constructor({ logger, server, key } = {}) {
7
+ /**
8
+ * @typedef {object} LoginOptions
9
+ * @property {import('abslog').AbstractLoggerOptions} [logger]
10
+ * @property {string} server
11
+ * @property {string} key
12
+ */
13
+
14
+ export default class Login {
15
+ /**
16
+ * @param {LoginOptions} options
17
+ */
18
+ constructor({ logger, server, key }) {
9
19
  this.log = abslog(logger);
10
20
  this.server = server;
11
21
  this.key = key;
12
22
  }
13
23
 
24
+ /**
25
+ * @returns {Promise<string | false>} Bearer token, or false if login fails
26
+ */
14
27
  async run() {
15
28
  this.log.debug('Validating input');
16
29
 
17
30
  try {
18
31
  schemas.assert.server(this.server);
19
32
  if (!this.key || typeof !this.key === 'string') {
33
+ // @ts-expect-error
20
34
  throw new schemas.ValidationError('"key" must be a string');
21
35
  }
22
36
  } catch (err) {
@@ -46,4 +60,4 @@ module.exports = class Login {
46
60
  }
47
61
  }
48
62
  }
49
- };
63
+ }
package/classes/meta.js CHANGED
@@ -1,23 +1,31 @@
1
- /* eslint-disable no-await-in-loop */
2
- /* eslint-disable no-plusplus */
3
-
4
- 'use strict';
5
-
6
- const abslog = require('abslog');
7
- const { join } = require('path');
8
- const schemas = require('@eik/common-schemas');
9
- const fetch = require('node-fetch');
1
+ import abslog from 'abslog';
2
+ import { join } from 'path';
3
+ import { schemas } from '@eik/common';
10
4
 
11
5
  const types = ['pkg', 'map', 'npm'];
12
6
 
13
- module.exports = class Meta {
14
- constructor({ logger, server, name, version } = {}) {
7
+ /**
8
+ * @typedef {object} MetaOptions
9
+ * @property {import('abslog').AbstractLoggerOptions} [logger]
10
+ * @property {string} server
11
+ * @property {string} name
12
+ * @property {string} version
13
+ */
14
+
15
+ export default class Meta {
16
+ /**
17
+ * @param {MetaOptions} options
18
+ */
19
+ constructor({ logger, server, name, version }) {
15
20
  this.log = abslog(logger);
16
21
  this.server = server;
17
22
  this.name = name;
18
23
  this.version = version;
19
24
  }
20
25
 
26
+ /**
27
+ * @returns {Promise<unknown | false>}
28
+ */
21
29
  async run() {
22
30
  this.log.debug('Validating input');
23
31
 
@@ -90,4 +98,4 @@ module.exports = class Meta {
90
98
  return false;
91
99
  }
92
100
  }
93
- };
101
+ }
package/classes/ping.js CHANGED
@@ -1,15 +1,25 @@
1
- 'use strict';
2
-
3
- const fetch = require('node-fetch');
4
- const abslog = require('abslog');
5
- const schemas = require('@eik/common-schemas');
6
-
7
- module.exports = class Ping {
1
+ import abslog from 'abslog';
2
+ import { schemas } from '@eik/common';
3
+
4
+ /**
5
+ * @typedef {object} PingOptions
6
+ * @property {string} [server]
7
+ * @property {import('abslog').AbstractLoggerOptions} [logger]
8
+ */
9
+
10
+ export default class Ping {
11
+ /**
12
+ * @param {PingOptions} options
13
+ */
8
14
  constructor({ logger, server } = {}) {
9
15
  this.log = abslog(logger);
10
16
  this.server = server;
11
17
  }
12
18
 
19
+ /**
20
+ * Run the ping command
21
+ * @returns {Promise<boolean>}
22
+ */
13
23
  async run() {
14
24
  this.log.debug('Validating input');
15
25
 
@@ -22,10 +32,11 @@ module.exports = class Ping {
22
32
 
23
33
  this.log.debug('Requesting ping from server');
24
34
  try {
25
- const result = await fetch(this.server);
35
+ const result = await fetch(/** @type {string}*/ (this.server));
26
36
 
27
37
  if (!result.ok) {
28
38
  const err = new Error('Ping unsuccessful');
39
+ // @ts-expect-error
29
40
  err.statusCode = result.status;
30
41
  throw err;
31
42
  }
@@ -48,4 +59,4 @@ module.exports = class Ping {
48
59
  }
49
60
  }
50
61
  }
51
- };
62
+ }