@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,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mimeTypes = void 0;
4
- exports.respondWithGzip = respondWithGzip;
5
- exports.startHttpServer = startHttpServer;
6
- exports.startWsServer = startWsServer;
7
- const http = require("http");
8
- const zlib = require("zlib");
9
- const SocketServer = require('simple-websocket/server.js');
10
- exports.mimeTypes = {
11
- '.html': 'text/html',
12
- '.js': 'text/javascript',
13
- '.css': 'text/css',
14
- '.json': 'application/json',
15
- '.png': 'image/png',
16
- '.jpg': 'image/jpg',
17
- '.gif': 'image/gif',
18
- '.svg': 'image/svg+xml',
19
- '.wav': 'audio/wav',
20
- '.mp4': 'video/mp4',
21
- '.woff': 'application/font-woff',
22
- '.ttf': 'application/font-ttf',
23
- '.eot': 'application/vnd.ms-fontobject',
24
- '.otf': 'application/font-otf',
25
- '.wasm': 'application/wasm',
26
- };
27
- // credits: https://stackoverflow.com/a/9238214/1749888
28
- function respondWithGzip(contents, request, response, headers = {}, code = 200) {
29
- let compressedStream;
30
- const acceptEncoding = request.headers['accept-encoding'] || '';
31
- if (acceptEncoding.match(/\bdeflate\b/)) {
32
- response.writeHead(code, { ...headers, 'content-encoding': 'deflate' });
33
- compressedStream = zlib.createDeflate();
34
- }
35
- else if (acceptEncoding.match(/\bgzip\b/)) {
36
- response.writeHead(code, { ...headers, 'content-encoding': 'gzip' });
37
- compressedStream = zlib.createGzip();
38
- }
39
- else {
40
- response.writeHead(code, headers);
41
- if (typeof contents === 'string' || Buffer.isBuffer(contents)) {
42
- response.write(contents);
43
- response.end();
44
- }
45
- else if (response !== undefined) {
46
- contents.pipe(response);
47
- }
48
- return;
49
- }
50
- if (typeof contents === 'string' || Buffer.isBuffer(contents)) {
51
- compressedStream.write(contents);
52
- compressedStream.pipe(response);
53
- compressedStream.end();
54
- }
55
- else {
56
- contents.pipe(compressedStream).pipe(response);
57
- }
58
- }
59
- function startHttpServer(port, host, handler) {
60
- return http.createServer(handler).listen(port, host);
61
- }
62
- function startWsServer(port, host) {
63
- const socketServer = new SocketServer({ port, host, clientTracking: true });
64
- socketServer.on('connection', (socket) => {
65
- socket.on('data', (data) => {
66
- const message = JSON.parse(data);
67
- switch (message.type) {
68
- case 'ping':
69
- socket.send('{"type": "pong"}');
70
- break;
71
- default:
72
- // nope
73
- }
74
- });
75
- });
76
- socketServer.broadcast = (message) => {
77
- socketServer._server.clients.forEach((client) => {
78
- if (client.readyState === 1) {
79
- // OPEN
80
- client.send(message);
81
- }
82
- });
83
- };
84
- return socketServer;
85
- }
@@ -1,44 +0,0 @@
1
- import { handlePush as handleCMSPush } from '../reunite/commands/push';
2
- import type { Config, Region } from '@redocly/openapi-core';
3
- import type { CommandArgs } from '../wrapper';
4
- import type { VerifyConfigOptions } from '../types';
5
- export declare const DESTINATION_REGEX: RegExp;
6
- export type PushOptions = {
7
- api?: string;
8
- destination?: string;
9
- branchName?: string;
10
- upsert?: boolean;
11
- 'job-id'?: string;
12
- 'batch-size'?: number;
13
- region?: Region;
14
- 'skip-decorator'?: string[];
15
- public?: boolean;
16
- files?: string[];
17
- organization?: string;
18
- } & VerifyConfigOptions;
19
- export declare function commonPushHandler({ project, 'mount-path': mountPath, }: {
20
- project?: string;
21
- 'mount-path'?: string;
22
- }): typeof handleCMSPush | (({ argv: { apis, branch, "batch-id": batchId, "job-id": jobId, ...rest }, config, version, }: CommandArgs<BarePushArgs & {
23
- "batch-id"?: string;
24
- }>) => Promise<void>);
25
- export declare function handlePush({ argv, config }: CommandArgs<PushOptions>): Promise<void>;
26
- export declare function getDestinationProps(destination: string | undefined, organization: string | undefined): {
27
- organizationId: string | undefined;
28
- name: string | undefined;
29
- version: string | undefined;
30
- };
31
- type BarePushArgs = Omit<PushOptions, 'destination' | 'branchName'> & {
32
- apis?: string[];
33
- branch?: string;
34
- destination?: string;
35
- };
36
- export declare const transformPush: (callback: typeof handlePush) => ({ argv: { apis, branch, "batch-id": batchId, "job-id": jobId, ...rest }, config, version, }: CommandArgs<BarePushArgs & {
37
- "batch-id"?: string;
38
- }>) => Promise<void>;
39
- export declare function getApiRoot({ name, version, config: { apis }, }: {
40
- name: string;
41
- version: string;
42
- config: Config;
43
- }): string;
44
- export {};
@@ -1,301 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformPush = exports.DESTINATION_REGEX = void 0;
4
- exports.commonPushHandler = commonPushHandler;
5
- exports.handlePush = handlePush;
6
- exports.getDestinationProps = getDestinationProps;
7
- exports.getApiRoot = getApiRoot;
8
- const fs = require("fs");
9
- const path = require("path");
10
- const perf_hooks_1 = require("perf_hooks");
11
- const colorette_1 = require("colorette");
12
- const crypto_1 = require("crypto");
13
- const openapi_core_1 = require("@redocly/openapi-core");
14
- const utils_1 = require("@redocly/openapi-core/lib/utils");
15
- const miscellaneous_1 = require("../utils/miscellaneous");
16
- const auth_1 = require("./auth");
17
- const push_1 = require("../reunite/commands/push");
18
- const api_client_1 = require("../reunite/api/api-client");
19
- const DEFAULT_VERSION = 'latest';
20
- exports.DESTINATION_REGEX =
21
- // eslint-disable-next-line no-useless-escape
22
- /^(@(?<organizationId>[\w\-\s]+)\/)?(?<name>[^@]*)@(?<version>[\w\.\-]+)$/;
23
- function commonPushHandler({ project, 'mount-path': mountPath, }) {
24
- if (project && mountPath) {
25
- return push_1.handlePush;
26
- }
27
- return (0, exports.transformPush)(handlePush);
28
- }
29
- async function handlePush({ argv, config }) {
30
- const client = new openapi_core_1.RedoclyClient(config.region);
31
- const isAuthorized = await client.isAuthorizedWithRedoclyByRegion();
32
- if (!isAuthorized) {
33
- try {
34
- const clientToken = await (0, auth_1.promptClientToken)(client.domain);
35
- await client.login(clientToken);
36
- }
37
- catch (e) {
38
- (0, miscellaneous_1.exitWithError)(e);
39
- }
40
- }
41
- const startedAt = perf_hooks_1.performance.now();
42
- const { destination, branchName, upsert } = argv;
43
- const jobId = argv['job-id'];
44
- const batchSize = argv['batch-size'];
45
- if (destination && !exports.DESTINATION_REGEX.test(destination)) {
46
- (0, miscellaneous_1.exitWithError)(`Destination argument value is not valid, please use the right format: ${(0, colorette_1.yellow)('<api-name@api-version>')}.`);
47
- }
48
- const destinationProps = getDestinationProps(destination, config.organization);
49
- const organizationId = argv.organization || destinationProps.organizationId;
50
- const { name, version } = destinationProps;
51
- if (!organizationId) {
52
- return (0, miscellaneous_1.exitWithError)(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
53
- }
54
- const api = argv.api || (name && version && getApiRoot({ name, version, config }));
55
- if (name && version && !api) {
56
- (0, miscellaneous_1.exitWithError)(`No api found that matches ${(0, colorette_1.blue)(`${name}@${version}`)}. Please make sure you have provided the correct data in the config file.`);
57
- }
58
- // Ensure that a destination for the api is provided.
59
- if (!name && api) {
60
- return (0, miscellaneous_1.exitWithError)(`No destination provided, please use --destination option to provide destination.`);
61
- }
62
- if (jobId && !jobId.trim()) {
63
- (0, miscellaneous_1.exitWithError)(`The ${(0, colorette_1.blue)(`job-id`)} option value is not valid, please avoid using an empty string.`);
64
- }
65
- if (batchSize && batchSize < 2) {
66
- (0, miscellaneous_1.exitWithError)(`The ${(0, colorette_1.blue)(`batch-size`)} option value is not valid, please use the integer bigger than 1.`);
67
- }
68
- const apis = api ? { [`${name}@${version}`]: { root: api } } : config.apis;
69
- if (!Object.keys(apis).length) {
70
- (0, miscellaneous_1.exitWithError)(`Api not found. Please make sure you have provided the correct data in the config file.`);
71
- }
72
- for (const [apiNameAndVersion, { root: api }] of Object.entries(apis)) {
73
- const resolvedConfig = (0, openapi_core_1.getMergedConfig)(config, apiNameAndVersion);
74
- resolvedConfig.styleguide.skipDecorators(argv['skip-decorator']);
75
- const [name, version = DEFAULT_VERSION] = apiNameAndVersion.split('@');
76
- const encodedName = encodeURIComponent(name);
77
- try {
78
- let rootFilePath = '';
79
- const filePaths = [];
80
- const filesToUpload = await collectFilesToUpload(api, resolvedConfig);
81
- const filesHash = hashFiles(filesToUpload.files);
82
- process.stdout.write(`Uploading ${filesToUpload.files.length} ${(0, utils_1.pluralize)('file', filesToUpload.files.length)}:\n`);
83
- let uploaded = 0;
84
- for (const file of filesToUpload.files) {
85
- const { signedUploadUrl, filePath } = await client.registryApi.prepareFileUpload({
86
- organizationId,
87
- name: encodedName,
88
- version,
89
- filesHash,
90
- filename: file.keyOnS3,
91
- isUpsert: upsert,
92
- });
93
- if (file.filePath === filesToUpload.root) {
94
- rootFilePath = filePath;
95
- }
96
- filePaths.push(filePath);
97
- process.stdout.write(`Uploading ${file.contents ? 'bundle for ' : ''}${(0, colorette_1.blue)(file.filePath)}...`);
98
- const uploadResponse = await uploadFileToS3(signedUploadUrl, file.contents || file.filePath);
99
- const fileCounter = `(${++uploaded}/${filesToUpload.files.length})`;
100
- if (!uploadResponse.ok) {
101
- (0, miscellaneous_1.exitWithError)(`✗ ${fileCounter}\nFile upload failed.`);
102
- }
103
- process.stdout.write((0, colorette_1.green)(`✓ ${fileCounter}\n`));
104
- }
105
- process.stdout.write('\n');
106
- await client.registryApi.pushApi({
107
- organizationId,
108
- name: encodedName,
109
- version,
110
- rootFilePath,
111
- filePaths,
112
- branch: branchName,
113
- isUpsert: upsert,
114
- isPublic: argv['public'],
115
- batchId: jobId,
116
- batchSize: batchSize,
117
- });
118
- }
119
- catch (error) {
120
- if (error.message === 'ORGANIZATION_NOT_FOUND') {
121
- (0, miscellaneous_1.exitWithError)(`Organization ${(0, colorette_1.blue)(organizationId)} not found.`);
122
- }
123
- if (error.message === 'API_VERSION_NOT_FOUND') {
124
- (0, miscellaneous_1.exitWithError)(`The definition version ${(0, colorette_1.blue)(`${name}@${version}`)} does not exist in organization ${(0, colorette_1.blue)(organizationId)}!\n${(0, colorette_1.yellow)('Suggestion:')} please use ${(0, colorette_1.blue)('-u')} or ${(0, colorette_1.blue)('--upsert')} to create definition.`);
125
- }
126
- throw error;
127
- }
128
- process.stdout.write(`Definition: ${(0, colorette_1.blue)(api)} is successfully pushed to Redocly API Registry.\n`);
129
- }
130
- (0, miscellaneous_1.printExecutionTime)('push', startedAt, api || `apis in organization ${organizationId}`);
131
- }
132
- function getFilesList(dir, files) {
133
- files = files || [];
134
- const filesAndDirs = fs.readdirSync(dir);
135
- for (const name of filesAndDirs) {
136
- if (fs.statSync(path.join(dir, name)).isDirectory()) {
137
- files = getFilesList(path.join(dir, name), files);
138
- }
139
- else {
140
- const currentPath = dir + '/' + name;
141
- files.push(currentPath);
142
- }
143
- }
144
- return files;
145
- }
146
- async function collectFilesToUpload(api, config) {
147
- const files = [];
148
- const [{ path: apiPath }] = await (0, miscellaneous_1.getFallbackApisOrExit)([api], config);
149
- process.stdout.write('Bundling definition\n');
150
- const { bundle: openapiBundle, problems } = await (0, openapi_core_1.bundle)({
151
- config,
152
- ref: apiPath,
153
- skipRedoclyRegistryRefs: true,
154
- });
155
- const fileTotals = (0, openapi_core_1.getTotals)(problems);
156
- if (fileTotals.errors === 0) {
157
- process.stdout.write(`Created a bundle for ${(0, colorette_1.blue)(api)} ${fileTotals.warnings > 0 ? 'with warnings' : ''}\n`);
158
- }
159
- else {
160
- (0, miscellaneous_1.exitWithError)(`Failed to create a bundle for ${(0, colorette_1.blue)(api)}.`);
161
- }
162
- const fileExt = path.extname(apiPath).split('.').pop();
163
- files.push(getFileEntry(apiPath, (0, miscellaneous_1.dumpBundle)(openapiBundle.parsed, fileExt)));
164
- if (fs.existsSync('package.json')) {
165
- files.push(getFileEntry('package.json'));
166
- }
167
- if (fs.existsSync(openapi_core_1.IGNORE_FILE)) {
168
- files.push(getFileEntry(openapi_core_1.IGNORE_FILE));
169
- }
170
- if (config.configFile) {
171
- // All config file paths including the root one
172
- files.push(...[...new Set(config.styleguide.extendPaths)].map((f) => getFileEntry(f)));
173
- if (config.theme?.openapi?.htmlTemplate) {
174
- const dir = getFolder(config.theme.openapi.htmlTemplate);
175
- const fileList = getFilesList(dir, []);
176
- files.push(...fileList.map((f) => getFileEntry(f)));
177
- }
178
- const pluginFiles = new Set();
179
- for (const plugin of config.styleguide.pluginPaths) {
180
- if (typeof plugin !== 'string')
181
- continue;
182
- const fileList = getFilesList(getFolder(plugin), []);
183
- fileList.forEach((f) => pluginFiles.add(f));
184
- }
185
- files.push(...filterPluginFilesByExt(Array.from(pluginFiles)).map((f) => getFileEntry(f)));
186
- }
187
- if (config.files) {
188
- const otherFiles = new Set();
189
- for (const file of config.files) {
190
- if (fs.statSync(file).isDirectory()) {
191
- const fileList = getFilesList(file, []);
192
- fileList.forEach((f) => otherFiles.add(f));
193
- }
194
- else {
195
- otherFiles.add(file);
196
- }
197
- }
198
- files.push(...Array.from(otherFiles).map((f) => getFileEntry(f)));
199
- }
200
- return {
201
- files,
202
- root: path.resolve(apiPath),
203
- };
204
- function filterPluginFilesByExt(files) {
205
- return files.filter((file) => {
206
- const fileExt = path.extname(file).toLowerCase();
207
- return fileExt === '.js' || fileExt === '.ts' || fileExt === '.mjs' || fileExt === 'json';
208
- });
209
- }
210
- function getFileEntry(filename, contents) {
211
- return {
212
- filePath: path.resolve(filename),
213
- keyOnS3: config.configFile
214
- ? (0, openapi_core_1.slash)(path.relative(path.dirname(config.configFile), filename))
215
- : (0, openapi_core_1.slash)(path.basename(filename)),
216
- contents: (contents && Buffer.from(contents, 'utf-8')) || undefined,
217
- };
218
- }
219
- }
220
- function getFolder(filePath) {
221
- return path.resolve(path.dirname(filePath));
222
- }
223
- function hashFiles(filePaths) {
224
- const sum = (0, crypto_1.createHash)('sha256');
225
- filePaths.forEach((file) => sum.update(fs.readFileSync(file.filePath)));
226
- return sum.digest('hex');
227
- }
228
- function parseDestination(destination) {
229
- return destination?.match(exports.DESTINATION_REGEX)?.groups;
230
- }
231
- function getDestinationProps(destination, organization) {
232
- const groups = destination && parseDestination(destination);
233
- if (groups) {
234
- return {
235
- organizationId: groups.organizationId || organization,
236
- name: groups.name,
237
- version: groups.version,
238
- };
239
- }
240
- else {
241
- return { organizationId: organization, name: undefined, version: undefined };
242
- }
243
- }
244
- const transformPush = (callback) => ({ argv: { apis, branch, 'batch-id': batchId, 'job-id': jobId, ...rest }, config, version, }) => {
245
- const [maybeApiOrDestination, maybeDestination, maybeBranchName] = apis || [];
246
- if (batchId) {
247
- process.stderr.write((0, colorette_1.yellow)(`The ${(0, colorette_1.red)('batch-id')} option is deprecated. Please use ${(0, colorette_1.green)('job-id')} instead.\n\n`));
248
- }
249
- if (maybeBranchName) {
250
- process.stderr.write((0, colorette_1.yellow)('Deprecation warning: Do not use the third parameter as a branch name. Please use a separate --branch option instead.\n\n'));
251
- }
252
- let apiFile, destination;
253
- if (maybeDestination) {
254
- process.stderr.write((0, colorette_1.yellow)('Deprecation warning: Do not use the second parameter as a destination. Please use a separate --destination and --organization instead.\n\n'));
255
- apiFile = maybeApiOrDestination;
256
- destination = maybeDestination;
257
- }
258
- else if (maybeApiOrDestination && exports.DESTINATION_REGEX.test(maybeApiOrDestination)) {
259
- process.stderr.write((0, colorette_1.yellow)('Deprecation warning: Do not use the first parameter as a destination. Please use a separate --destination and --organization options instead.\n\n'));
260
- destination = maybeApiOrDestination;
261
- }
262
- else if (maybeApiOrDestination && !exports.DESTINATION_REGEX.test(maybeApiOrDestination)) {
263
- apiFile = maybeApiOrDestination;
264
- }
265
- return callback({
266
- argv: {
267
- ...rest,
268
- destination: rest.destination ?? destination,
269
- api: apiFile,
270
- branchName: branch ?? maybeBranchName,
271
- 'job-id': jobId || batchId,
272
- },
273
- config,
274
- version,
275
- });
276
- };
277
- exports.transformPush = transformPush;
278
- function getApiRoot({ name, version, config: { apis }, }) {
279
- const api = apis?.[`${name}@${version}`] || (version === DEFAULT_VERSION && apis?.[name]);
280
- return api?.root;
281
- }
282
- async function uploadFileToS3(url, filePathOrBuffer) {
283
- const fileSizeInBytes = typeof filePathOrBuffer === 'string'
284
- ? fs.statSync(filePathOrBuffer).size
285
- : filePathOrBuffer.byteLength;
286
- const readStream = typeof filePathOrBuffer === 'string' ? fs.createReadStream(filePathOrBuffer) : filePathOrBuffer;
287
- const requestOptions = {
288
- method: 'PUT',
289
- headers: {
290
- 'Content-Length': fileSizeInBytes.toString(),
291
- },
292
- body: Buffer.isBuffer(readStream)
293
- ? new Blob([readStream])
294
- : new Blob([await (0, api_client_1.streamToBuffer)(readStream)]),
295
- };
296
- const proxyAgent = (0, openapi_core_1.getProxyAgent)();
297
- if (proxyAgent) {
298
- requestOptions.dispatcher = proxyAgent;
299
- }
300
- return fetch(url, requestOptions);
301
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_1 = require("../index");
4
- const path = require("path");
5
- const openapiCore = require("@redocly/openapi-core");
6
- const colorette_1 = require("colorette");
7
- const miscellaneous_1 = require("../../../utils/__mocks__/miscellaneous");
8
- const utils = require('../../../utils/miscellaneous');
9
- jest.mock('../../../utils/miscellaneous', () => ({
10
- ...jest.requireActual('../../../utils/miscellaneous'),
11
- writeToFileByExtension: jest.fn(),
12
- }));
13
- jest.mock('@redocly/openapi-core', () => ({
14
- ...jest.requireActual('@redocly/openapi-core'),
15
- isRef: jest.fn(),
16
- }));
17
- describe('#split', () => {
18
- const openapiDir = 'test';
19
- const componentsFiles = {};
20
- it('should split the file and show the success message', async () => {
21
- const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/spec.json';
22
- jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
23
- await (0, index_1.handleSplit)({
24
- argv: {
25
- api: filePath,
26
- outDir: openapiDir,
27
- separator: '_',
28
- },
29
- config: (0, miscellaneous_1.loadConfigAndHandleErrors)(),
30
- version: 'cli-version',
31
- });
32
- expect(process.stderr.write).toBeCalledTimes(2);
33
- expect(process.stderr.write.mock.calls[0][0]).toBe(`🪓 Document: ${(0, colorette_1.blue)(filePath)} ${(0, colorette_1.green)('is successfully split')}
34
- and all related files are saved to the directory: ${(0, colorette_1.blue)(openapiDir)} \n`);
35
- expect(process.stderr.write.mock.calls[1][0]).toContain(`${filePath}: split processed in <test>ms`);
36
- });
37
- it('should use the correct separator', async () => {
38
- const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/spec.json';
39
- jest.spyOn(utils, 'pathToFilename').mockImplementation(() => 'newFilePath');
40
- await (0, index_1.handleSplit)({
41
- argv: {
42
- api: filePath,
43
- outDir: openapiDir,
44
- separator: '_',
45
- },
46
- config: (0, miscellaneous_1.loadConfigAndHandleErrors)(),
47
- version: 'cli-version',
48
- });
49
- expect(utils.pathToFilename).toBeCalledWith(expect.anything(), '_');
50
- utils.pathToFilename.mockRestore();
51
- });
52
- it('should have correct path with paths', () => {
53
- const openapi = require('./fixtures/spec.json');
54
- jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'paths/test.yaml');
55
- jest.spyOn(path, 'relative').mockImplementation(() => 'paths/test.yaml');
56
- (0, index_1.iteratePathItems)(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles, '_', undefined, 'yaml');
57
- expect(openapiCore.slash).toHaveBeenCalledWith('paths/test.yaml');
58
- expect(path.relative).toHaveBeenCalledWith('test', 'test/paths/test.yaml');
59
- });
60
- it('should have correct path with webhooks', () => {
61
- const openapi = require('./fixtures/webhooks.json');
62
- jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'webhooks/test.yaml');
63
- jest.spyOn(path, 'relative').mockImplementation(() => 'webhooks/test.yaml');
64
- (0, index_1.iteratePathItems)(openapi.webhooks, openapiDir, path.join(openapiDir, 'webhooks'), componentsFiles, 'webhook_', undefined, 'yaml');
65
- expect(openapiCore.slash).toHaveBeenCalledWith('webhooks/test.yaml');
66
- expect(path.relative).toHaveBeenCalledWith('test', 'test/webhooks/test.yaml');
67
- });
68
- it('should have correct path with x-webhooks', () => {
69
- const openapi = require('./fixtures/spec.json');
70
- jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'webhooks/test.yaml');
71
- jest.spyOn(path, 'relative').mockImplementation(() => 'webhooks/test.yaml');
72
- (0, index_1.iteratePathItems)(openapi['x-webhooks'], openapiDir, path.join(openapiDir, 'webhooks'), componentsFiles, 'webhook_', undefined, 'yaml');
73
- expect(openapiCore.slash).toHaveBeenCalledWith('webhooks/test.yaml');
74
- expect(path.relative).toHaveBeenCalledWith('test', 'test/webhooks/test.yaml');
75
- });
76
- it('should create correct folder name for code samples', async () => {
77
- const openapi = require('./fixtures/samples.json');
78
- const fs = require('fs');
79
- jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { });
80
- jest.spyOn(utils, 'escapeLanguageName');
81
- (0, index_1.iteratePathItems)(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles, '_', undefined, 'yaml');
82
- expect(utils.escapeLanguageName).nthCalledWith(1, 'C#');
83
- expect(utils.escapeLanguageName).nthReturnedWith(1, 'C_sharp');
84
- expect(utils.escapeLanguageName).nthCalledWith(2, 'C/AL');
85
- expect(utils.escapeLanguageName).nthReturnedWith(2, 'C_AL');
86
- expect(utils.escapeLanguageName).nthCalledWith(3, 'Visual Basic');
87
- expect(utils.escapeLanguageName).nthReturnedWith(3, 'VisualBasic');
88
- expect(utils.escapeLanguageName).toBeCalledTimes(3);
89
- utils.escapeLanguageName.mockRestore();
90
- });
91
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const api_keys_1 = require("../api-keys");
4
- const fs = require("fs");
5
- describe('getApiKeys()', () => {
6
- afterEach(() => {
7
- jest.resetAllMocks();
8
- });
9
- it('should return api key from environment variable', () => {
10
- process.env.REDOCLY_AUTHORIZATION = 'test-api-key';
11
- expect((0, api_keys_1.getApiKeys)('test-domain')).toEqual('test-api-key');
12
- });
13
- it('should return api key from credentials file', () => {
14
- process.env.REDOCLY_AUTHORIZATION = '';
15
- jest.spyOn(fs, 'existsSync').mockReturnValue(true);
16
- jest.spyOn(fs, 'readFileSync').mockReturnValue(JSON.stringify({
17
- ['test-domain']: 'test-api-key-from-credentials-file',
18
- }));
19
- expect((0, api_keys_1.getApiKeys)('test-domain')).toEqual('test-api-key-from-credentials-file');
20
- });
21
- it('should throw an error if no api key provided', () => {
22
- process.env.REDOCLY_AUTHORIZATION = '';
23
- jest.spyOn(fs, 'existsSync').mockReturnValue(false);
24
- expect(() => (0, api_keys_1.getApiKeys)('test-domain')).toThrowError('No api key provided, please use environment variable REDOCLY_AUTHORIZATION.');
25
- });
26
- });
@@ -1 +0,0 @@
1
- export {};