@redocly/cli 1.34.3 → 2.0.0-next.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 (321) hide show
  1. package/README.md +34 -3
  2. package/bin/cli.js +1 -1
  3. package/lib/auth/device-flow.d.ts +1 -0
  4. package/lib/auth/device-flow.d.ts.map +1 -0
  5. package/lib/auth/device-flow.js +15 -17
  6. package/lib/auth/device-flow.js.map +1 -0
  7. package/lib/auth/oauth-client.d.ts +1 -0
  8. package/lib/auth/oauth-client.d.ts.map +1 -0
  9. package/lib/auth/oauth-client.js +21 -23
  10. package/lib/auth/oauth-client.js.map +1 -0
  11. package/lib/commands/auth.d.ts +3 -5
  12. package/lib/commands/auth.d.ts.map +1 -0
  13. package/lib/commands/auth.js +19 -44
  14. package/lib/commands/auth.js.map +1 -0
  15. package/lib/commands/build-docs/index.d.ts +4 -3
  16. package/lib/commands/build-docs/index.d.ts.map +1 -0
  17. package/lib/commands/build-docs/index.js +23 -24
  18. package/lib/commands/build-docs/index.js.map +1 -0
  19. package/lib/commands/build-docs/types.d.ts +2 -1
  20. package/lib/commands/build-docs/types.d.ts.map +1 -0
  21. package/lib/commands/build-docs/types.js +2 -2
  22. package/lib/commands/build-docs/types.js.map +1 -0
  23. package/lib/commands/build-docs/utils.d.ts +3 -2
  24. package/lib/commands/build-docs/utils.d.ts.map +1 -0
  25. package/lib/commands/build-docs/utils.js +35 -37
  26. package/lib/commands/build-docs/utils.js.map +1 -0
  27. package/lib/commands/bundle.d.ts +6 -3
  28. package/lib/commands/bundle.d.ts.map +1 -0
  29. package/lib/commands/bundle.js +34 -38
  30. package/lib/commands/bundle.js.map +1 -0
  31. package/lib/commands/eject.d.ts +3 -2
  32. package/lib/commands/eject.d.ts.map +1 -0
  33. package/lib/commands/eject.js +11 -13
  34. package/lib/commands/eject.js.map +1 -0
  35. package/lib/commands/join.d.ts +4 -3
  36. package/lib/commands/join.d.ts.map +1 -0
  37. package/lib/commands/join.js +79 -81
  38. package/lib/commands/join.js.map +1 -0
  39. package/lib/commands/lint.d.ts +8 -6
  40. package/lib/commands/lint.d.ts.map +1 -0
  41. package/lib/commands/lint.js +53 -62
  42. package/lib/commands/lint.js.map +1 -0
  43. package/lib/commands/preview-project/constants.d.ts +2 -1
  44. package/lib/commands/preview-project/constants.d.ts.map +1 -0
  45. package/lib/commands/preview-project/constants.js +4 -6
  46. package/lib/commands/preview-project/constants.js.map +1 -0
  47. package/lib/commands/preview-project/index.d.ts +3 -2
  48. package/lib/commands/preview-project/index.d.ts.map +1 -0
  49. package/lib/commands/preview-project/index.js +21 -23
  50. package/lib/commands/preview-project/index.js.map +1 -0
  51. package/lib/commands/preview-project/types.d.ts +3 -2
  52. package/lib/commands/preview-project/types.d.ts.map +1 -0
  53. package/lib/commands/preview-project/types.js +2 -2
  54. package/lib/commands/preview-project/types.js.map +1 -0
  55. package/lib/commands/split/index.d.ts +4 -3
  56. package/lib/commands/split/index.d.ts.map +1 -0
  57. package/lib/commands/split/index.js +53 -57
  58. package/lib/commands/split/index.js.map +1 -0
  59. package/lib/commands/split/types.d.ts +2 -2
  60. package/lib/commands/split/types.d.ts.map +1 -0
  61. package/lib/commands/split/types.js +11 -13
  62. package/lib/commands/split/types.js.map +1 -0
  63. package/lib/commands/stats.d.ts +3 -2
  64. package/lib/commands/stats.d.ts.map +1 -0
  65. package/lib/commands/stats.js +21 -24
  66. package/lib/commands/stats.js.map +1 -0
  67. package/lib/commands/translations.d.ts +3 -2
  68. package/lib/commands/translations.d.ts.map +1 -0
  69. package/lib/commands/translations.js +11 -13
  70. package/lib/commands/translations.js.map +1 -0
  71. package/lib/index.d.ts +2 -1
  72. package/lib/index.d.ts.map +1 -0
  73. package/lib/index.js +109 -239
  74. package/lib/index.js.map +1 -0
  75. package/lib/otel.d.ts +2 -1
  76. package/lib/otel.d.ts.map +1 -0
  77. package/lib/otel.js +22 -23
  78. package/lib/otel.js.map +1 -0
  79. package/lib/reunite/api/api-client.d.ts +4 -3
  80. package/lib/reunite/api/api-client.d.ts.map +1 -0
  81. package/lib/reunite/api/api-client.js +14 -20
  82. package/lib/reunite/api/api-client.js.map +1 -0
  83. package/lib/reunite/api/api-keys.d.ts +2 -1
  84. package/lib/reunite/api/api-keys.d.ts.map +1 -0
  85. package/lib/reunite/api/api-keys.js +4 -20
  86. package/lib/reunite/api/api-keys.js.map +1 -0
  87. package/lib/reunite/api/domains.d.ts +5 -2
  88. package/lib/reunite/api/domains.d.ts.map +1 -0
  89. package/lib/reunite/api/domains.js +6 -15
  90. package/lib/reunite/api/domains.js.map +1 -0
  91. package/lib/reunite/api/index.d.ts +4 -3
  92. package/lib/reunite/api/index.d.ts.map +1 -0
  93. package/lib/reunite/api/index.js +4 -19
  94. package/lib/reunite/api/index.js.map +1 -0
  95. package/lib/reunite/api/types.d.ts +1 -0
  96. package/lib/reunite/api/types.d.ts.map +1 -0
  97. package/lib/reunite/api/types.js +2 -2
  98. package/lib/reunite/api/types.js.map +1 -0
  99. package/lib/reunite/commands/push-status.d.ts +6 -5
  100. package/lib/reunite/commands/push-status.d.ts.map +1 -0
  101. package/lib/reunite/commands/push-status.js +31 -37
  102. package/lib/reunite/commands/push-status.js.map +1 -0
  103. package/lib/reunite/commands/push.d.ts +6 -6
  104. package/lib/reunite/commands/push.d.ts.map +1 -0
  105. package/lib/reunite/commands/push.js +31 -40
  106. package/lib/reunite/commands/push.js.map +1 -0
  107. package/lib/reunite/commands/utils.d.ts +4 -3
  108. package/lib/reunite/commands/utils.d.ts.map +1 -0
  109. package/lib/reunite/commands/utils.js +9 -12
  110. package/lib/reunite/commands/utils.js.map +1 -0
  111. package/lib/reunite/utils.d.ts +1 -0
  112. package/lib/reunite/utils.d.ts.map +1 -0
  113. package/lib/reunite/utils.js +2 -5
  114. package/lib/reunite/utils.js.map +1 -0
  115. package/lib/types.d.ts +15 -27
  116. package/lib/types.d.ts.map +1 -0
  117. package/lib/types.js +2 -5
  118. package/lib/types.js.map +1 -0
  119. package/lib/utils/assert-node-version.d.ts +1 -0
  120. package/lib/utils/assert-node-version.d.ts.map +1 -0
  121. package/lib/utils/assert-node-version.js +8 -10
  122. package/lib/utils/assert-node-version.js.map +1 -0
  123. package/lib/utils/error.d.ts +4 -0
  124. package/lib/utils/error.d.ts.map +1 -0
  125. package/lib/utils/error.js +8 -0
  126. package/lib/utils/error.js.map +1 -0
  127. package/lib/utils/fetch-with-timeout.d.ts +1 -0
  128. package/lib/utils/fetch-with-timeout.d.ts.map +1 -0
  129. package/lib/utils/fetch-with-timeout.js +6 -8
  130. package/lib/utils/fetch-with-timeout.js.map +1 -0
  131. package/lib/utils/{getCommandNameFromArgs.d.ts → get-command-name-from-args.d.ts} +1 -0
  132. package/lib/utils/get-command-name-from-args.d.ts.map +1 -0
  133. package/lib/utils/get-command-name-from-args.js +4 -0
  134. package/lib/utils/get-command-name-from-args.js.map +1 -0
  135. package/lib/utils/js-utils.d.ts +1 -0
  136. package/lib/utils/js-utils.d.ts.map +1 -0
  137. package/lib/utils/js-utils.js +8 -12
  138. package/lib/utils/js-utils.js.map +1 -0
  139. package/lib/utils/miscellaneous.d.ts +9 -48
  140. package/lib/utils/miscellaneous.d.ts.map +1 -0
  141. package/lib/utils/miscellaneous.js +131 -269
  142. package/lib/utils/miscellaneous.js.map +1 -0
  143. package/lib/utils/package.d.ts +2 -0
  144. package/lib/utils/package.d.ts.map +1 -0
  145. package/lib/utils/package.js +4 -0
  146. package/lib/utils/package.js.map +1 -0
  147. package/lib/utils/platform.d.ts +1 -0
  148. package/lib/utils/platform.d.ts.map +1 -0
  149. package/lib/utils/platform.js +5 -9
  150. package/lib/utils/platform.js.map +1 -0
  151. package/lib/utils/proxy-agent.d.ts +3 -0
  152. package/lib/utils/proxy-agent.d.ts.map +1 -0
  153. package/lib/utils/proxy-agent.js +6 -0
  154. package/lib/utils/proxy-agent.js.map +1 -0
  155. package/lib/utils/spinner.d.ts +1 -0
  156. package/lib/utils/spinner.d.ts.map +1 -0
  157. package/lib/utils/spinner.js +8 -10
  158. package/lib/utils/spinner.js.map +1 -0
  159. package/lib/utils/telemetry.d.ts +40 -0
  160. package/lib/utils/telemetry.d.ts.map +1 -0
  161. package/lib/utils/telemetry.js +138 -0
  162. package/lib/utils/telemetry.js.map +1 -0
  163. package/lib/utils/update-version-notifier.d.ts +1 -1
  164. package/lib/utils/update-version-notifier.d.ts.map +1 -0
  165. package/lib/utils/update-version-notifier.js +35 -38
  166. package/lib/utils/update-version-notifier.js.map +1 -0
  167. package/lib/utils/validate-positive-number.d.ts +2 -0
  168. package/lib/utils/validate-positive-number.d.ts.map +1 -0
  169. package/lib/utils/validate-positive-number.js +13 -0
  170. package/lib/utils/validate-positive-number.js.map +1 -0
  171. package/lib/wrapper.d.ts +3 -3
  172. package/lib/wrapper.d.ts.map +1 -0
  173. package/lib/wrapper.js +39 -26
  174. package/lib/wrapper.js.map +1 -0
  175. package/package.json +15 -16
  176. package/CHANGELOG.md +0 -770
  177. package/lib/__mocks__/@redocly/openapi-core.d.ts +0 -99
  178. package/lib/__mocks__/@redocly/openapi-core.js +0 -84
  179. package/lib/__mocks__/documents.d.ts +0 -150
  180. package/lib/__mocks__/documents.js +0 -123
  181. package/lib/__mocks__/fs.d.ts +0 -8
  182. package/lib/__mocks__/fs.js +0 -9
  183. package/lib/__mocks__/perf_hooks.d.ts +0 -3
  184. package/lib/__mocks__/perf_hooks.js +0 -6
  185. package/lib/__mocks__/redoc.d.ts +0 -6
  186. package/lib/__mocks__/redoc.js +0 -5
  187. package/lib/__tests__/commands/build-docs.test.d.ts +0 -1
  188. package/lib/__tests__/commands/build-docs.test.js +0 -54
  189. package/lib/__tests__/commands/bundle.test.d.ts +0 -1
  190. package/lib/__tests__/commands/bundle.test.js +0 -235
  191. package/lib/__tests__/commands/join.test.d.ts +0 -1
  192. package/lib/__tests__/commands/join.test.js +0 -274
  193. package/lib/__tests__/commands/lint.test.d.ts +0 -1
  194. package/lib/__tests__/commands/lint.test.js +0 -149
  195. package/lib/__tests__/commands/push-region.test.d.ts +0 -1
  196. package/lib/__tests__/commands/push-region.test.js +0 -90
  197. package/lib/__tests__/commands/push.test.d.ts +0 -1
  198. package/lib/__tests__/commands/push.test.js +0 -496
  199. package/lib/__tests__/fetch-with-timeout.test.d.ts +0 -1
  200. package/lib/__tests__/fetch-with-timeout.test.js +0 -64
  201. package/lib/__tests__/fixtures/config.d.ts +0 -21
  202. package/lib/__tests__/fixtures/config.js +0 -24
  203. package/lib/__tests__/spinner.test.d.ts +0 -1
  204. package/lib/__tests__/spinner.test.js +0 -43
  205. package/lib/__tests__/utils.test.d.ts +0 -1
  206. package/lib/__tests__/utils.test.js +0 -651
  207. package/lib/__tests__/wrapper.test.d.ts +0 -1
  208. package/lib/__tests__/wrapper.test.js +0 -76
  209. package/lib/auth/__tests__/device-flow.test.d.ts +0 -1
  210. package/lib/auth/__tests__/device-flow.test.js +0 -62
  211. package/lib/auth/__tests__/oauth-client.test.d.ts +0 -1
  212. package/lib/auth/__tests__/oauth-client.test.js +0 -93
  213. package/lib/commands/preview-docs/index.d.ts +0 -12
  214. package/lib/commands/preview-docs/index.js +0 -127
  215. package/lib/commands/preview-docs/preview-server/default.hbs +0 -24
  216. package/lib/commands/preview-docs/preview-server/hot.js +0 -59
  217. package/lib/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  218. package/lib/commands/preview-docs/preview-server/preview-server.d.ts +0 -5
  219. package/lib/commands/preview-docs/preview-server/preview-server.js +0 -113
  220. package/lib/commands/preview-docs/preview-server/server.d.ts +0 -22
  221. package/lib/commands/preview-docs/preview-server/server.js +0 -85
  222. package/lib/commands/push.d.ts +0 -44
  223. package/lib/commands/push.js +0 -301
  224. package/lib/commands/split/__tests__/index.test.d.ts +0 -1
  225. package/lib/commands/split/__tests__/index.test.js +0 -91
  226. package/lib/reunite/api/__tests__/api-keys.test.d.ts +0 -1
  227. package/lib/reunite/api/__tests__/api-keys.test.js +0 -26
  228. package/lib/reunite/api/__tests__/api.client.test.d.ts +0 -1
  229. package/lib/reunite/api/__tests__/api.client.test.js +0 -337
  230. package/lib/reunite/api/__tests__/domains.test.d.ts +0 -1
  231. package/lib/reunite/api/__tests__/domains.test.js +0 -32
  232. package/lib/reunite/commands/__tests__/push-status.test.d.ts +0 -1
  233. package/lib/reunite/commands/__tests__/push-status.test.js +0 -563
  234. package/lib/reunite/commands/__tests__/push.test.d.ts +0 -1
  235. package/lib/reunite/commands/__tests__/push.test.js +0 -315
  236. package/lib/reunite/commands/__tests__/utils.test.d.ts +0 -1
  237. package/lib/reunite/commands/__tests__/utils.test.js +0 -51
  238. package/lib/utils/__mocks__/miscellaneous.d.ts +0 -43
  239. package/lib/utils/__mocks__/miscellaneous.js +0 -24
  240. package/lib/utils/getCommandNameFromArgs.js +0 -6
  241. package/src/__mocks__/@redocly/openapi-core.ts +0 -88
  242. package/src/__mocks__/documents.ts +0 -124
  243. package/src/__mocks__/fs.ts +0 -6
  244. package/src/__mocks__/perf_hooks.ts +0 -3
  245. package/src/__mocks__/redoc.ts +0 -2
  246. package/src/__tests__/commands/build-docs.test.ts +0 -59
  247. package/src/__tests__/commands/bundle.test.ts +0 -285
  248. package/src/__tests__/commands/join.test.ts +0 -334
  249. package/src/__tests__/commands/lint.test.ts +0 -190
  250. package/src/__tests__/commands/push-region.test.ts +0 -104
  251. package/src/__tests__/commands/push.test.ts +0 -553
  252. package/src/__tests__/fetch-with-timeout.test.ts +0 -81
  253. package/src/__tests__/fixtures/config.ts +0 -21
  254. package/src/__tests__/fixtures/openapi.json +0 -0
  255. package/src/__tests__/fixtures/openapi.yaml +0 -0
  256. package/src/__tests__/fixtures/redocly.yaml +0 -0
  257. package/src/__tests__/spinner.test.ts +0 -51
  258. package/src/__tests__/utils.test.ts +0 -781
  259. package/src/__tests__/wrapper.test.ts +0 -91
  260. package/src/auth/__tests__/device-flow.test.ts +0 -73
  261. package/src/auth/__tests__/oauth-client.test.ts +0 -117
  262. package/src/auth/device-flow.ts +0 -175
  263. package/src/auth/oauth-client.ts +0 -111
  264. package/src/commands/auth.ts +0 -66
  265. package/src/commands/build-docs/index.ts +0 -55
  266. package/src/commands/build-docs/template.hbs +0 -23
  267. package/src/commands/build-docs/types.ts +0 -25
  268. package/src/commands/build-docs/utils.ts +0 -110
  269. package/src/commands/bundle.ts +0 -154
  270. package/src/commands/eject.ts +0 -42
  271. package/src/commands/join.ts +0 -794
  272. package/src/commands/lint.ts +0 -169
  273. package/src/commands/preview-docs/index.ts +0 -183
  274. package/src/commands/preview-docs/preview-server/default.hbs +0 -24
  275. package/src/commands/preview-docs/preview-server/hot.js +0 -59
  276. package/src/commands/preview-docs/preview-server/oauth2-redirect.html +0 -21
  277. package/src/commands/preview-docs/preview-server/preview-server.ts +0 -159
  278. package/src/commands/preview-docs/preview-server/server.ts +0 -92
  279. package/src/commands/preview-project/constants.ts +0 -23
  280. package/src/commands/preview-project/index.ts +0 -71
  281. package/src/commands/preview-project/types.ts +0 -12
  282. package/src/commands/push.ts +0 -470
  283. package/src/commands/split/__tests__/fixtures/samples.json +0 -61
  284. package/src/commands/split/__tests__/fixtures/spec.json +0 -70
  285. package/src/commands/split/__tests__/fixtures/webhooks.json +0 -85
  286. package/src/commands/split/__tests__/index.test.ts +0 -156
  287. package/src/commands/split/index.ts +0 -397
  288. package/src/commands/split/types.ts +0 -60
  289. package/src/commands/stats.ts +0 -140
  290. package/src/commands/translations.ts +0 -32
  291. package/src/custom.d.ts +0 -1
  292. package/src/index.ts +0 -970
  293. package/src/otel.ts +0 -59
  294. package/src/reunite/api/__tests__/api-keys.test.ts +0 -37
  295. package/src/reunite/api/__tests__/api.client.test.ts +0 -452
  296. package/src/reunite/api/__tests__/domains.test.ts +0 -41
  297. package/src/reunite/api/api-client.ts +0 -381
  298. package/src/reunite/api/api-keys.ts +0 -26
  299. package/src/reunite/api/domains.ts +0 -23
  300. package/src/reunite/api/index.ts +0 -3
  301. package/src/reunite/api/types.ts +0 -108
  302. package/src/reunite/commands/__tests__/push-status.test.ts +0 -653
  303. package/src/reunite/commands/__tests__/push.test.ts +0 -385
  304. package/src/reunite/commands/__tests__/utils.test.ts +0 -62
  305. package/src/reunite/commands/push-status.ts +0 -325
  306. package/src/reunite/commands/push.ts +0 -235
  307. package/src/reunite/commands/utils.ts +0 -66
  308. package/src/reunite/utils.ts +0 -1
  309. package/src/types.ts +0 -64
  310. package/src/utils/__mocks__/miscellaneous.ts +0 -24
  311. package/src/utils/assert-node-version.ts +0 -19
  312. package/src/utils/fetch-with-timeout.ts +0 -30
  313. package/src/utils/getCommandNameFromArgs.ts +0 -5
  314. package/src/utils/js-utils.ts +0 -24
  315. package/src/utils/miscellaneous.ts +0 -729
  316. package/src/utils/platform.ts +0 -31
  317. package/src/utils/spinner.ts +0 -50
  318. package/src/utils/update-version-notifier.ts +0 -115
  319. package/src/wrapper.ts +0 -77
  320. package/tsconfig.json +0 -9
  321. package/tsconfig.tsbuildinfo +0 -1
@@ -1,92 +0,0 @@
1
- import * as http from 'http';
2
- import * as zlib from 'zlib';
3
-
4
- import type { ReadStream } from 'fs';
5
-
6
- const SocketServer = require('simple-websocket/server.js');
7
-
8
- export const mimeTypes = {
9
- '.html': 'text/html',
10
- '.js': 'text/javascript',
11
- '.css': 'text/css',
12
- '.json': 'application/json',
13
- '.png': 'image/png',
14
- '.jpg': 'image/jpg',
15
- '.gif': 'image/gif',
16
- '.svg': 'image/svg+xml',
17
- '.wav': 'audio/wav',
18
- '.mp4': 'video/mp4',
19
- '.woff': 'application/font-woff',
20
- '.ttf': 'application/font-ttf',
21
- '.eot': 'application/vnd.ms-fontobject',
22
- '.otf': 'application/font-otf',
23
- '.wasm': 'application/wasm',
24
- };
25
-
26
- // credits: https://stackoverflow.com/a/9238214/1749888
27
- export function respondWithGzip(
28
- contents: string | Buffer | ReadStream,
29
- request: http.IncomingMessage,
30
- response: http.ServerResponse,
31
- headers = {},
32
- code = 200
33
- ) {
34
- let compressedStream;
35
- const acceptEncoding = (request.headers['accept-encoding'] as string) || '';
36
- if (acceptEncoding.match(/\bdeflate\b/)) {
37
- response.writeHead(code, { ...headers, 'content-encoding': 'deflate' });
38
- compressedStream = zlib.createDeflate();
39
- } else if (acceptEncoding.match(/\bgzip\b/)) {
40
- response.writeHead(code, { ...headers, 'content-encoding': 'gzip' });
41
- compressedStream = zlib.createGzip();
42
- } else {
43
- response.writeHead(code, headers);
44
- if (typeof contents === 'string' || Buffer.isBuffer(contents)) {
45
- response.write(contents);
46
- response.end();
47
- } else if (response !== undefined) {
48
- contents.pipe(response);
49
- }
50
- return;
51
- }
52
-
53
- if (typeof contents === 'string' || Buffer.isBuffer(contents)) {
54
- compressedStream.write(contents);
55
- compressedStream.pipe(response);
56
- compressedStream.end();
57
- } else {
58
- contents.pipe(compressedStream).pipe(response);
59
- }
60
- }
61
-
62
- export function startHttpServer(port: number, host: string, handler: http.RequestListener) {
63
- return http.createServer(handler).listen(port, host);
64
- }
65
-
66
- export function startWsServer(port: number, host: string) {
67
- const socketServer = new SocketServer({ port, host, clientTracking: true });
68
-
69
- socketServer.on('connection', (socket: any) => {
70
- socket.on('data', (data: string) => {
71
- const message = JSON.parse(data);
72
- switch (message.type) {
73
- case 'ping':
74
- socket.send('{"type": "pong"}');
75
- break;
76
- default:
77
- // nope
78
- }
79
- });
80
- });
81
-
82
- socketServer.broadcast = (message: string) => {
83
- socketServer._server.clients.forEach((client: any) => {
84
- if (client.readyState === 1) {
85
- // OPEN
86
- client.send(message);
87
- }
88
- });
89
- };
90
-
91
- return socketServer;
92
- }
@@ -1,23 +0,0 @@
1
- import type { Product } from './types';
2
-
3
- export const PRODUCT_PACKAGES = {
4
- realm: '@redocly/realm',
5
- 'redoc-revel': '@redocly/redoc-revel',
6
- 'revel-reef': '@redocly/revel-reef',
7
- 'redoc-reef': '@redocly/redoc-reef',
8
- redoc: '@redocly/redoc',
9
- revel: '@redocly/revel',
10
- reef: '@redocly/reef',
11
- };
12
-
13
- export const PRODUCT_NAMES: { [key in Product]: string } = {
14
- redoc: 'Redoc',
15
- revel: 'Revel',
16
- reef: 'Reef',
17
- realm: 'Realm',
18
- 'redoc-revel': 'Redoc + Revel',
19
- 'redoc-reef': 'Redoc + Reef',
20
- 'revel-reef': 'Revel + Reef',
21
- };
22
-
23
- export const PRODUCT_PLANS = ['pro', 'enterprise'] as const;
@@ -1,71 +0,0 @@
1
- import path = require('path');
2
- import { existsSync, readFileSync } from 'fs';
3
- import { spawn } from 'child_process';
4
- import { PRODUCT_NAMES, PRODUCT_PACKAGES } from './constants';
5
- import { getPlatformSpawnArgs } from '../../utils/platform';
6
-
7
- import type { PreviewProjectOptions, Product } from './types';
8
- import type { CommandArgs } from '../../wrapper';
9
-
10
- export const previewProject = async ({ argv }: CommandArgs<PreviewProjectOptions>) => {
11
- const { plan, port } = argv;
12
- const projectDir = argv['project-dir'];
13
-
14
- const product = argv.product || tryGetProductFromPackageJson(projectDir);
15
-
16
- if (!isValidProduct(product)) {
17
- process.stderr.write(`Invalid product ${product}.`);
18
- throw new Error(`Project preview launch failed.`);
19
- }
20
-
21
- const productName = PRODUCT_NAMES[product];
22
- const packageName = PRODUCT_PACKAGES[product];
23
-
24
- process.stdout.write(`\nLaunching preview of ${productName} ${plan} using NPX.\n\n`);
25
- const { npxExecutableName, shell } = getPlatformSpawnArgs();
26
-
27
- const child = spawn(
28
- npxExecutableName,
29
- ['-y', packageName, 'preview', `--plan=${plan}`, `--port=${port || 4000}`],
30
- {
31
- stdio: 'inherit',
32
- cwd: projectDir,
33
- shell,
34
- }
35
- );
36
-
37
- child.on('error', (error) => {
38
- process.stderr.write(`Project preview launch failed: ${error.message}`);
39
- throw new Error(`Project preview launch failed.`);
40
- });
41
- };
42
-
43
- const isValidProduct = (product: string | undefined): product is Product => {
44
- if (!product) {
45
- return false;
46
- }
47
-
48
- return !!PRODUCT_NAMES[product as Product];
49
- };
50
-
51
- const tryGetProductFromPackageJson = (projectDir: string): Product => {
52
- const packageJsonPath = path.join(process.cwd(), projectDir, 'package.json');
53
-
54
- if (existsSync(packageJsonPath)) {
55
- try {
56
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
57
- const packageJsonDeps = packageJson.dependencies || {};
58
-
59
- for (const [product, packageName] of Object.entries(PRODUCT_PACKAGES)) {
60
- if (packageJsonDeps[packageName]) {
61
- process.stdout.write(`\n${packageName} detected in project's 'package.json'`);
62
- return product as Product;
63
- }
64
- }
65
- } catch (error) {
66
- process.stdout.write(`Invalid 'package.json': ${packageJsonPath}. Using Realm.`);
67
- }
68
- }
69
-
70
- return 'realm';
71
- };
@@ -1,12 +0,0 @@
1
- import type { VerifyConfigOptions } from '../../types';
2
- import type { PRODUCT_PACKAGES, PRODUCT_PLANS } from './constants';
3
-
4
- export type Product = keyof typeof PRODUCT_PACKAGES;
5
- export type ProductPlan = typeof PRODUCT_PLANS[number];
6
-
7
- export type PreviewProjectOptions = {
8
- product?: Product | string;
9
- plan: ProductPlan | string;
10
- port?: number;
11
- 'project-dir': string;
12
- } & VerifyConfigOptions;
@@ -1,470 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { performance } from 'perf_hooks';
4
- import { yellow, green, blue, red } from 'colorette';
5
- import { createHash } from 'crypto';
6
- import {
7
- bundle,
8
- RedoclyClient,
9
- IGNORE_FILE,
10
- getTotals,
11
- slash,
12
- getMergedConfig,
13
- getProxyAgent,
14
- } from '@redocly/openapi-core';
15
- import { pluralize } from '@redocly/openapi-core/lib/utils';
16
- import {
17
- exitWithError,
18
- printExecutionTime,
19
- getFallbackApisOrExit,
20
- dumpBundle,
21
- } from '../utils/miscellaneous';
22
- import { promptClientToken } from './auth';
23
- import { handlePush as handleCMSPush } from '../reunite/commands/push';
24
- import { streamToBuffer } from '../reunite/api/api-client';
25
-
26
- import type { Readable } from 'node:stream';
27
- import type { Agent } from 'node:http';
28
- import type { Config, BundleOutputFormat, Region } from '@redocly/openapi-core';
29
- import type { CommandArgs } from '../wrapper';
30
- import type { VerifyConfigOptions } from '../types';
31
-
32
- const DEFAULT_VERSION = 'latest';
33
-
34
- export const DESTINATION_REGEX =
35
- // eslint-disable-next-line no-useless-escape
36
- /^(@(?<organizationId>[\w\-\s]+)\/)?(?<name>[^@]*)@(?<version>[\w\.\-]+)$/;
37
-
38
- export type PushOptions = {
39
- api?: string;
40
- destination?: string;
41
- branchName?: string;
42
- upsert?: boolean;
43
- 'job-id'?: string;
44
- 'batch-size'?: number;
45
- region?: Region;
46
- 'skip-decorator'?: string[];
47
- public?: boolean;
48
- files?: string[];
49
- organization?: string;
50
- } & VerifyConfigOptions;
51
-
52
- export function commonPushHandler({
53
- project,
54
- 'mount-path': mountPath,
55
- }: {
56
- project?: string;
57
- 'mount-path'?: string;
58
- }) {
59
- if (project && mountPath) {
60
- return handleCMSPush;
61
- }
62
- return transformPush(handlePush);
63
- }
64
-
65
- export async function handlePush({ argv, config }: CommandArgs<PushOptions>): Promise<void> {
66
- const client = new RedoclyClient(config.region);
67
- const isAuthorized = await client.isAuthorizedWithRedoclyByRegion();
68
- if (!isAuthorized) {
69
- try {
70
- const clientToken = await promptClientToken(client.domain);
71
- await client.login(clientToken);
72
- } catch (e) {
73
- exitWithError(e);
74
- }
75
- }
76
-
77
- const startedAt = performance.now();
78
- const { destination, branchName, upsert } = argv;
79
-
80
- const jobId = argv['job-id'];
81
- const batchSize = argv['batch-size'];
82
-
83
- if (destination && !DESTINATION_REGEX.test(destination)) {
84
- exitWithError(
85
- `Destination argument value is not valid, please use the right format: ${yellow(
86
- '<api-name@api-version>'
87
- )}.`
88
- );
89
- }
90
-
91
- const destinationProps = getDestinationProps(destination, config.organization);
92
-
93
- const organizationId = argv.organization || destinationProps.organizationId;
94
- const { name, version } = destinationProps;
95
-
96
- if (!organizationId) {
97
- return exitWithError(
98
- `No organization provided, please use --organization option or specify the 'organization' field in the config file.`
99
- );
100
- }
101
-
102
- const api = argv.api || (name && version && getApiRoot({ name, version, config }));
103
-
104
- if (name && version && !api) {
105
- exitWithError(
106
- `No api found that matches ${blue(
107
- `${name}@${version}`
108
- )}. Please make sure you have provided the correct data in the config file.`
109
- );
110
- }
111
-
112
- // Ensure that a destination for the api is provided.
113
- if (!name && api) {
114
- return exitWithError(
115
- `No destination provided, please use --destination option to provide destination.`
116
- );
117
- }
118
-
119
- if (jobId && !jobId.trim()) {
120
- exitWithError(
121
- `The ${blue(`job-id`)} option value is not valid, please avoid using an empty string.`
122
- );
123
- }
124
-
125
- if (batchSize && batchSize < 2) {
126
- exitWithError(
127
- `The ${blue(`batch-size`)} option value is not valid, please use the integer bigger than 1.`
128
- );
129
- }
130
-
131
- const apis = api ? { [`${name}@${version}`]: { root: api } } : config.apis;
132
- if (!Object.keys(apis).length) {
133
- exitWithError(
134
- `Api not found. Please make sure you have provided the correct data in the config file.`
135
- );
136
- }
137
-
138
- for (const [apiNameAndVersion, { root: api }] of Object.entries(apis)) {
139
- const resolvedConfig = getMergedConfig(config, apiNameAndVersion);
140
- resolvedConfig.styleguide.skipDecorators(argv['skip-decorator']);
141
-
142
- const [name, version = DEFAULT_VERSION] = apiNameAndVersion.split('@');
143
- const encodedName = encodeURIComponent(name);
144
- try {
145
- let rootFilePath = '';
146
- const filePaths: string[] = [];
147
- const filesToUpload = await collectFilesToUpload(api, resolvedConfig);
148
- const filesHash = hashFiles(filesToUpload.files);
149
-
150
- process.stdout.write(
151
- `Uploading ${filesToUpload.files.length} ${pluralize(
152
- 'file',
153
- filesToUpload.files.length
154
- )}:\n`
155
- );
156
-
157
- let uploaded = 0;
158
-
159
- for (const file of filesToUpload.files) {
160
- const { signedUploadUrl, filePath } = await client.registryApi.prepareFileUpload({
161
- organizationId,
162
- name: encodedName,
163
- version,
164
- filesHash,
165
- filename: file.keyOnS3,
166
- isUpsert: upsert,
167
- });
168
-
169
- if (file.filePath === filesToUpload.root) {
170
- rootFilePath = filePath;
171
- }
172
-
173
- filePaths.push(filePath);
174
-
175
- process.stdout.write(
176
- `Uploading ${file.contents ? 'bundle for ' : ''}${blue(file.filePath)}...`
177
- );
178
-
179
- const uploadResponse = await uploadFileToS3(
180
- signedUploadUrl,
181
- file.contents || file.filePath
182
- );
183
-
184
- const fileCounter = `(${++uploaded}/${filesToUpload.files.length})`;
185
-
186
- if (!uploadResponse.ok) {
187
- exitWithError(`✗ ${fileCounter}\nFile upload failed.`);
188
- }
189
-
190
- process.stdout.write(green(`✓ ${fileCounter}\n`));
191
- }
192
-
193
- process.stdout.write('\n');
194
-
195
- await client.registryApi.pushApi({
196
- organizationId,
197
- name: encodedName,
198
- version,
199
- rootFilePath,
200
- filePaths,
201
- branch: branchName,
202
- isUpsert: upsert,
203
- isPublic: argv['public'],
204
- batchId: jobId,
205
- batchSize: batchSize,
206
- });
207
- } catch (error) {
208
- if (error.message === 'ORGANIZATION_NOT_FOUND') {
209
- exitWithError(`Organization ${blue(organizationId)} not found.`);
210
- }
211
-
212
- if (error.message === 'API_VERSION_NOT_FOUND') {
213
- exitWithError(
214
- `The definition version ${blue(
215
- `${name}@${version}`
216
- )} does not exist in organization ${blue(organizationId)}!\n${yellow(
217
- 'Suggestion:'
218
- )} please use ${blue('-u')} or ${blue('--upsert')} to create definition.`
219
- );
220
- }
221
-
222
- throw error;
223
- }
224
-
225
- process.stdout.write(
226
- `Definition: ${blue(api!)} is successfully pushed to Redocly API Registry.\n`
227
- );
228
- }
229
- printExecutionTime('push', startedAt, api || `apis in organization ${organizationId}`);
230
- }
231
-
232
- function getFilesList(dir: string, files?: any): string[] {
233
- files = files || [];
234
- const filesAndDirs = fs.readdirSync(dir);
235
- for (const name of filesAndDirs) {
236
- if (fs.statSync(path.join(dir, name)).isDirectory()) {
237
- files = getFilesList(path.join(dir, name), files);
238
- } else {
239
- const currentPath = dir + '/' + name;
240
- files.push(currentPath);
241
- }
242
- }
243
- return files;
244
- }
245
-
246
- async function collectFilesToUpload(api: string, config: Config) {
247
- const files: { filePath: string; keyOnS3: string; contents?: Buffer }[] = [];
248
- const [{ path: apiPath }] = await getFallbackApisOrExit([api], config);
249
-
250
- process.stdout.write('Bundling definition\n');
251
-
252
- const { bundle: openapiBundle, problems } = await bundle({
253
- config,
254
- ref: apiPath,
255
- skipRedoclyRegistryRefs: true,
256
- });
257
-
258
- const fileTotals = getTotals(problems);
259
-
260
- if (fileTotals.errors === 0) {
261
- process.stdout.write(
262
- `Created a bundle for ${blue(api)} ${fileTotals.warnings > 0 ? 'with warnings' : ''}\n`
263
- );
264
- } else {
265
- exitWithError(`Failed to create a bundle for ${blue(api)}.`);
266
- }
267
-
268
- const fileExt = path.extname(apiPath).split('.').pop();
269
- files.push(
270
- getFileEntry(apiPath, dumpBundle(openapiBundle.parsed, fileExt as BundleOutputFormat))
271
- );
272
-
273
- if (fs.existsSync('package.json')) {
274
- files.push(getFileEntry('package.json'));
275
- }
276
- if (fs.existsSync(IGNORE_FILE)) {
277
- files.push(getFileEntry(IGNORE_FILE));
278
- }
279
- if (config.configFile) {
280
- // All config file paths including the root one
281
- files.push(...[...new Set(config.styleguide.extendPaths)].map((f) => getFileEntry(f)));
282
- if (config.theme?.openapi?.htmlTemplate) {
283
- const dir = getFolder(config.theme.openapi.htmlTemplate);
284
- const fileList = getFilesList(dir, []);
285
- files.push(...fileList.map((f) => getFileEntry(f)));
286
- }
287
- const pluginFiles = new Set<string>();
288
- for (const plugin of config.styleguide.pluginPaths) {
289
- if (typeof plugin !== 'string') continue;
290
- const fileList = getFilesList(getFolder(plugin), []);
291
- fileList.forEach((f) => pluginFiles.add(f));
292
- }
293
- files.push(...filterPluginFilesByExt(Array.from(pluginFiles)).map((f) => getFileEntry(f)));
294
- }
295
-
296
- if (config.files) {
297
- const otherFiles = new Set<string>();
298
- for (const file of config.files) {
299
- if (fs.statSync(file).isDirectory()) {
300
- const fileList = getFilesList(file, []);
301
- fileList.forEach((f) => otherFiles.add(f));
302
- } else {
303
- otherFiles.add(file);
304
- }
305
- }
306
- files.push(...Array.from(otherFiles).map((f) => getFileEntry(f)));
307
- }
308
-
309
- return {
310
- files,
311
- root: path.resolve(apiPath),
312
- };
313
-
314
- function filterPluginFilesByExt(files: string[]) {
315
- return files.filter((file: string) => {
316
- const fileExt = path.extname(file).toLowerCase();
317
- return fileExt === '.js' || fileExt === '.ts' || fileExt === '.mjs' || fileExt === 'json';
318
- });
319
- }
320
-
321
- function getFileEntry(filename: string, contents?: string) {
322
- return {
323
- filePath: path.resolve(filename),
324
- keyOnS3: config.configFile
325
- ? slash(path.relative(path.dirname(config.configFile), filename))
326
- : slash(path.basename(filename)),
327
- contents: (contents && Buffer.from(contents, 'utf-8')) || undefined,
328
- };
329
- }
330
- }
331
-
332
- function getFolder(filePath: string) {
333
- return path.resolve(path.dirname(filePath));
334
- }
335
-
336
- function hashFiles(filePaths: { filePath: string }[]) {
337
- const sum = createHash('sha256');
338
- filePaths.forEach((file) => sum.update(fs.readFileSync(file.filePath)));
339
- return sum.digest('hex');
340
- }
341
-
342
- function parseDestination(
343
- destination?: string
344
- ): { organizationId?: string; name?: string; version?: string } | undefined {
345
- return destination?.match(DESTINATION_REGEX)?.groups;
346
- }
347
-
348
- export function getDestinationProps(
349
- destination: string | undefined,
350
- organization: string | undefined
351
- ) {
352
- const groups = destination && parseDestination(destination);
353
- if (groups) {
354
- return {
355
- organizationId: groups.organizationId || organization,
356
- name: groups.name,
357
- version: groups.version,
358
- };
359
- } else {
360
- return { organizationId: organization, name: undefined, version: undefined };
361
- }
362
- }
363
-
364
- type BarePushArgs = Omit<PushOptions, 'destination' | 'branchName'> & {
365
- apis?: string[];
366
- branch?: string;
367
- destination?: string;
368
- };
369
-
370
- export const transformPush =
371
- (callback: typeof handlePush) =>
372
- ({
373
- argv: { apis, branch, 'batch-id': batchId, 'job-id': jobId, ...rest },
374
- config,
375
- version,
376
- }: CommandArgs<BarePushArgs & { 'batch-id'?: string }>) => {
377
- const [maybeApiOrDestination, maybeDestination, maybeBranchName] = apis || [];
378
-
379
- if (batchId) {
380
- process.stderr.write(
381
- yellow(
382
- `The ${red('batch-id')} option is deprecated. Please use ${green('job-id')} instead.\n\n`
383
- )
384
- );
385
- }
386
-
387
- if (maybeBranchName) {
388
- process.stderr.write(
389
- yellow(
390
- 'Deprecation warning: Do not use the third parameter as a branch name. Please use a separate --branch option instead.\n\n'
391
- )
392
- );
393
- }
394
-
395
- let apiFile, destination;
396
- if (maybeDestination) {
397
- process.stderr.write(
398
- yellow(
399
- 'Deprecation warning: Do not use the second parameter as a destination. Please use a separate --destination and --organization instead.\n\n'
400
- )
401
- );
402
- apiFile = maybeApiOrDestination;
403
- destination = maybeDestination;
404
- } else if (maybeApiOrDestination && DESTINATION_REGEX.test(maybeApiOrDestination)) {
405
- process.stderr.write(
406
- yellow(
407
- 'Deprecation warning: Do not use the first parameter as a destination. Please use a separate --destination and --organization options instead.\n\n'
408
- )
409
- );
410
- destination = maybeApiOrDestination;
411
- } else if (maybeApiOrDestination && !DESTINATION_REGEX.test(maybeApiOrDestination)) {
412
- apiFile = maybeApiOrDestination;
413
- }
414
-
415
- return callback({
416
- argv: {
417
- ...rest,
418
- destination: rest.destination ?? destination,
419
- api: apiFile,
420
- branchName: branch ?? maybeBranchName,
421
- 'job-id': jobId || batchId,
422
- },
423
- config,
424
- version,
425
- });
426
- };
427
-
428
- export function getApiRoot({
429
- name,
430
- version,
431
- config: { apis },
432
- }: {
433
- name: string;
434
- version: string;
435
- config: Config;
436
- }): string {
437
- const api = apis?.[`${name}@${version}`] || (version === DEFAULT_VERSION && apis?.[name]);
438
- return api?.root;
439
- }
440
-
441
- async function uploadFileToS3(url: string, filePathOrBuffer: string | Buffer) {
442
- const fileSizeInBytes =
443
- typeof filePathOrBuffer === 'string'
444
- ? fs.statSync(filePathOrBuffer).size
445
- : filePathOrBuffer.byteLength;
446
-
447
- const readStream =
448
- typeof filePathOrBuffer === 'string' ? fs.createReadStream(filePathOrBuffer) : filePathOrBuffer;
449
-
450
- type NodeFetchRequestInit = RequestInit & {
451
- dispatcher?: Agent;
452
- };
453
-
454
- const requestOptions: NodeFetchRequestInit = {
455
- method: 'PUT',
456
- headers: {
457
- 'Content-Length': fileSizeInBytes.toString(),
458
- },
459
- body: Buffer.isBuffer(readStream)
460
- ? new Blob([readStream])
461
- : new Blob([await streamToBuffer(readStream as Readable)]),
462
- };
463
-
464
- const proxyAgent = getProxyAgent();
465
- if (proxyAgent) {
466
- requestOptions.dispatcher = proxyAgent;
467
- }
468
-
469
- return fetch(url, requestOptions);
470
- }