@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,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const openapi_core_1 = require("@redocly/openapi-core");
4
- const push_1 = require("../../commands/push");
5
- const auth_1 = require("../../commands/auth");
6
- const config_1 = require("../fixtures/config");
7
- const node_stream_1 = require("node:stream");
8
- // Mock fs operations
9
- jest.mock('fs', () => ({
10
- ...jest.requireActual('fs'),
11
- createReadStream: () => {
12
- const readable = new node_stream_1.Readable();
13
- readable.push('test data');
14
- readable.push(null);
15
- return readable;
16
- },
17
- statSync: () => ({ size: 9 }),
18
- readFileSync: () => Buffer.from('test data'),
19
- existsSync: () => false,
20
- readdirSync: () => [],
21
- }));
22
- openapi_core_1.getMergedConfig.mockImplementation((config) => config);
23
- // Mock OpenAPI core
24
- jest.mock('@redocly/openapi-core');
25
- jest.mock('../../commands/auth');
26
- jest.mock('../../utils/miscellaneous');
27
- const mockPromptClientToken = auth_1.promptClientToken;
28
- describe('push-with-region', () => {
29
- const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
30
- redoclyClient.isAuthorizedWithRedoclyByRegion = jest.fn().mockResolvedValue(false);
31
- const originalFetch = fetch;
32
- beforeAll(() => {
33
- // Mock global fetch
34
- global.fetch = jest.fn(() => Promise.resolve({
35
- ok: true,
36
- status: 200,
37
- json: () => Promise.resolve({}),
38
- headers: new Headers(),
39
- statusText: 'OK',
40
- redirected: false,
41
- type: 'default',
42
- url: '',
43
- clone: () => ({}),
44
- body: new ReadableStream(),
45
- bodyUsed: false,
46
- arrayBuffer: async () => new ArrayBuffer(0),
47
- blob: async () => new Blob(),
48
- formData: async () => new FormData(),
49
- text: async () => '',
50
- }));
51
- });
52
- afterAll(() => {
53
- global.fetch = originalFetch;
54
- });
55
- beforeEach(() => {
56
- jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
57
- });
58
- it('should call login with default domain when region is US', async () => {
59
- redoclyClient.domain = 'redocly.com';
60
- await (0, push_1.handlePush)({
61
- argv: {
62
- upsert: true,
63
- api: 'spec.json',
64
- destination: '@org/my-api@1.0.0',
65
- branchName: 'test',
66
- },
67
- config: config_1.ConfigFixture,
68
- version: 'cli-version',
69
- });
70
- expect(mockPromptClientToken).toBeCalledTimes(1);
71
- expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
72
- });
73
- it('should call login with EU domain when region is EU', async () => {
74
- redoclyClient.domain = 'eu.redocly.com';
75
- // Update config for EU region
76
- const euConfig = { ...config_1.ConfigFixture, region: 'eu' };
77
- await (0, push_1.handlePush)({
78
- argv: {
79
- upsert: true,
80
- api: 'spec.json',
81
- destination: '@org/my-api@1.0.0',
82
- branchName: 'test',
83
- },
84
- config: euConfig,
85
- version: 'cli-version',
86
- });
87
- expect(mockPromptClientToken).toBeCalledTimes(1);
88
- expect(mockPromptClientToken).toHaveBeenCalledWith(redoclyClient.domain);
89
- });
90
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,496 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs = require("fs");
4
- const openapi_core_1 = require("@redocly/openapi-core");
5
- const miscellaneous_1 = require("../../utils/miscellaneous");
6
- const push_1 = require("../../commands/push");
7
- const config_1 = require("../fixtures/config");
8
- const colorette_1 = require("colorette");
9
- const node_stream_1 = require("node:stream");
10
- // Mock fs operations
11
- jest.mock('fs', () => ({
12
- ...jest.requireActual('fs'),
13
- createReadStream: jest.fn(() => {
14
- const readable = new node_stream_1.Readable();
15
- readable.push('test data');
16
- readable.push(null);
17
- return readable;
18
- }),
19
- statSync: jest.fn(() => ({ isDirectory: () => false, size: 10 })),
20
- readFileSync: jest.fn(() => Buffer.from('test data')),
21
- existsSync: jest.fn(() => false),
22
- readdirSync: jest.fn(() => []),
23
- }));
24
- jest.mock('@redocly/openapi-core');
25
- jest.mock('../../utils/miscellaneous');
26
- // Mock fetch
27
- const mockFetch = jest.fn(() => Promise.resolve({
28
- ok: true,
29
- status: 200,
30
- json: () => Promise.resolve({}),
31
- headers: new Headers(),
32
- statusText: 'OK',
33
- redirected: false,
34
- type: 'default',
35
- url: '',
36
- clone: () => ({}),
37
- body: null,
38
- bodyUsed: false,
39
- arrayBuffer: async () => new ArrayBuffer(0),
40
- blob: async () => new Blob(),
41
- formData: async () => new FormData(),
42
- text: async () => '',
43
- }));
44
- const originalFetch = global.fetch;
45
- openapi_core_1.getMergedConfig.mockImplementation((config) => config);
46
- describe('push', () => {
47
- const redoclyClient = require('@redocly/openapi-core').__redoclyClient;
48
- beforeAll(() => {
49
- global.fetch = mockFetch;
50
- });
51
- beforeEach(() => {
52
- jest.spyOn(process.stdout, 'write').mockImplementation(() => true);
53
- });
54
- afterAll(() => {
55
- global.fetch = originalFetch;
56
- });
57
- it('pushes definition', async () => {
58
- await (0, push_1.handlePush)({
59
- argv: {
60
- upsert: true,
61
- api: 'spec.json',
62
- destination: '@org/my-api@1.0.0',
63
- branchName: 'test',
64
- public: true,
65
- 'job-id': '123',
66
- 'batch-size': 2,
67
- },
68
- config: config_1.ConfigFixture,
69
- version: 'cli-version',
70
- });
71
- expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(1);
72
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
73
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
74
- branch: 'test',
75
- filePaths: ['filePath'],
76
- isUpsert: true,
77
- isPublic: true,
78
- name: 'my-api',
79
- organizationId: 'org',
80
- rootFilePath: 'filePath',
81
- version: '1.0.0',
82
- batchId: '123',
83
- batchSize: 2,
84
- });
85
- });
86
- it('fails if jobId value is an empty string', async () => {
87
- await (0, push_1.handlePush)({
88
- argv: {
89
- upsert: true,
90
- api: 'spec.json',
91
- destination: '@org/my-api@1.0.0',
92
- branchName: 'test',
93
- public: true,
94
- 'job-id': ' ',
95
- 'batch-size': 2,
96
- },
97
- config: config_1.ConfigFixture,
98
- version: 'cli-version',
99
- });
100
- expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
101
- });
102
- it('fails if batchSize value is less than 2', async () => {
103
- await (0, push_1.handlePush)({
104
- argv: {
105
- upsert: true,
106
- api: 'spec.json',
107
- destination: '@org/my-api@1.0.0',
108
- branchName: 'test',
109
- public: true,
110
- 'job-id': '123',
111
- 'batch-size': 1,
112
- },
113
- config: config_1.ConfigFixture,
114
- version: 'cli-version',
115
- });
116
- expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
117
- });
118
- it('push with --files', async () => {
119
- const mockConfig = { ...config_1.ConfigFixture, files: ['./resouces/1.md', './resouces/2.md'] };
120
- fs.statSync.mockImplementation(() => {
121
- return { isDirectory: () => false, size: 10 };
122
- });
123
- await (0, push_1.handlePush)({
124
- argv: {
125
- upsert: true,
126
- api: 'spec.json',
127
- destination: '@org/my-api@1.0.0',
128
- public: true,
129
- files: ['./resouces/1.md', './resouces/2.md'],
130
- },
131
- config: mockConfig,
132
- version: 'cli-version',
133
- });
134
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
135
- filePaths: ['filePath', 'filePath', 'filePath'],
136
- isUpsert: true,
137
- isPublic: true,
138
- name: 'my-api',
139
- organizationId: 'org',
140
- rootFilePath: 'filePath',
141
- version: '1.0.0',
142
- });
143
- expect(redoclyClient.registryApi.prepareFileUpload).toBeCalledTimes(3);
144
- });
145
- it('push should fail if organization not provided', async () => {
146
- await (0, push_1.handlePush)({
147
- argv: {
148
- upsert: true,
149
- api: 'spec.json',
150
- destination: 'test@v1',
151
- branchName: 'test',
152
- public: true,
153
- 'job-id': '123',
154
- 'batch-size': 2,
155
- },
156
- config: config_1.ConfigFixture,
157
- version: 'cli-version',
158
- });
159
- expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
160
- expect(miscellaneous_1.exitWithError).toBeCalledWith(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
161
- });
162
- it('push should work with organization in config', async () => {
163
- const mockConfig = { ...config_1.ConfigFixture, organization: 'test_org' };
164
- await (0, push_1.handlePush)({
165
- argv: {
166
- upsert: true,
167
- api: 'spec.json',
168
- destination: 'my-api@1.0.0',
169
- branchName: 'test',
170
- public: true,
171
- 'job-id': '123',
172
- 'batch-size': 2,
173
- },
174
- config: mockConfig,
175
- version: 'cli-version',
176
- });
177
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
178
- expect(redoclyClient.registryApi.pushApi).toHaveBeenLastCalledWith({
179
- branch: 'test',
180
- filePaths: ['filePath'],
181
- isUpsert: true,
182
- isPublic: true,
183
- name: 'my-api',
184
- organizationId: 'test_org',
185
- rootFilePath: 'filePath',
186
- version: '1.0.0',
187
- batchId: '123',
188
- batchSize: 2,
189
- });
190
- });
191
- it('push should work if destination not provided but api in config is provided', async () => {
192
- const mockConfig = {
193
- ...config_1.ConfigFixture,
194
- organization: 'test_org',
195
- apis: { 'my-api@1.0.0': { root: 'path' } },
196
- };
197
- await (0, push_1.handlePush)({
198
- argv: {
199
- upsert: true,
200
- branchName: 'test',
201
- public: true,
202
- 'job-id': '123',
203
- 'batch-size': 2,
204
- },
205
- config: mockConfig,
206
- version: 'cli-version',
207
- });
208
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
209
- });
210
- it('push should fail if apis not provided', async () => {
211
- const mockConfig = { organization: 'test_org', apis: {} };
212
- await (0, push_1.handlePush)({
213
- argv: {
214
- upsert: true,
215
- branchName: 'test',
216
- public: true,
217
- 'job-id': '123',
218
- 'batch-size': 2,
219
- },
220
- config: mockConfig,
221
- version: 'cli-version',
222
- });
223
- expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
224
- expect(miscellaneous_1.exitWithError).toHaveBeenLastCalledWith('Api not found. Please make sure you have provided the correct data in the config file.');
225
- });
226
- it('push should fail if destination not provided', async () => {
227
- const mockConfig = { organization: 'test_org', apis: {} };
228
- await (0, push_1.handlePush)({
229
- argv: {
230
- upsert: true,
231
- api: 'api.yaml',
232
- branchName: 'test',
233
- public: true,
234
- 'job-id': '123',
235
- 'batch-size': 2,
236
- },
237
- config: mockConfig,
238
- version: 'cli-version',
239
- });
240
- expect(miscellaneous_1.exitWithError).toBeCalledTimes(1);
241
- expect(miscellaneous_1.exitWithError).toHaveBeenLastCalledWith('No destination provided, please use --destination option to provide destination.');
242
- });
243
- it('push should fail if destination format is not valid', async () => {
244
- const mockConfig = { organization: 'test_org', apis: {} };
245
- await (0, push_1.handlePush)({
246
- argv: {
247
- upsert: true,
248
- destination: 'name/v1',
249
- branchName: 'test',
250
- public: true,
251
- 'job-id': '123',
252
- 'batch-size': 2,
253
- },
254
- config: mockConfig,
255
- version: 'cli-version',
256
- });
257
- expect(miscellaneous_1.exitWithError).toHaveBeenCalledWith(`Destination argument value is not valid, please use the right format: ${(0, colorette_1.yellow)('<api-name@api-version>')}.`);
258
- });
259
- it('push should work and encode name with spaces', async () => {
260
- const encodeURIComponentSpy = jest.spyOn(global, 'encodeURIComponent');
261
- const mockConfig = {
262
- ...config_1.ConfigFixture,
263
- organization: 'test_org',
264
- apis: { 'my test api@v1': { root: 'path' } },
265
- };
266
- await (0, push_1.handlePush)({
267
- argv: {
268
- upsert: true,
269
- destination: 'my test api@v1',
270
- branchName: 'test',
271
- public: true,
272
- 'job-id': '123',
273
- 'batch-size': 2,
274
- },
275
- config: mockConfig,
276
- version: 'cli-version',
277
- });
278
- expect(encodeURIComponentSpy).toHaveReturnedWith('my%20test%20api');
279
- expect(redoclyClient.registryApi.pushApi).toBeCalledTimes(1);
280
- });
281
- });
282
- describe('transformPush', () => {
283
- it('should adapt the existing syntax', () => {
284
- const cb = jest.fn();
285
- (0, push_1.transformPush)(cb)({
286
- argv: {
287
- apis: ['openapi.yaml', '@testing_org/main@v1'],
288
- },
289
- config: {},
290
- version: 'cli-version',
291
- });
292
- expect(cb).toBeCalledWith({
293
- argv: {
294
- api: 'openapi.yaml',
295
- destination: '@testing_org/main@v1',
296
- },
297
- config: {},
298
- version: 'cli-version',
299
- });
300
- });
301
- it('should adapt the existing syntax (including branchName)', () => {
302
- const cb = jest.fn();
303
- (0, push_1.transformPush)(cb)({
304
- argv: {
305
- apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
306
- },
307
- config: {},
308
- version: 'cli-version',
309
- });
310
- expect(cb).toBeCalledWith({
311
- argv: {
312
- api: 'openapi.yaml',
313
- destination: '@testing_org/main@v1',
314
- branchName: 'other',
315
- },
316
- config: {},
317
- version: 'cli-version',
318
- });
319
- });
320
- it('should use --branch option firstly', () => {
321
- const cb = jest.fn();
322
- (0, push_1.transformPush)(cb)({
323
- argv: {
324
- apis: ['openapi.yaml', '@testing_org/main@v1', 'other'],
325
- branch: 'priority-branch',
326
- },
327
- config: {},
328
- version: 'cli-version',
329
- });
330
- expect(cb).toBeCalledWith({
331
- argv: {
332
- api: 'openapi.yaml',
333
- destination: '@testing_org/main@v1',
334
- branchName: 'priority-branch',
335
- },
336
- config: {},
337
- version: 'cli-version',
338
- });
339
- });
340
- it('should work for a destination only', () => {
341
- const cb = jest.fn();
342
- (0, push_1.transformPush)(cb)({
343
- argv: {
344
- apis: ['main@v1'],
345
- },
346
- config: {},
347
- version: 'cli-version',
348
- });
349
- expect(cb).toBeCalledWith({
350
- argv: {
351
- destination: 'main@v1',
352
- },
353
- config: {},
354
- version: 'cli-version',
355
- });
356
- });
357
- it('should work for a api only', () => {
358
- const cb = jest.fn();
359
- (0, push_1.transformPush)(cb)({
360
- argv: {
361
- apis: ['test.yaml'],
362
- },
363
- config: {},
364
- version: 'cli-version',
365
- });
366
- expect(cb).toBeCalledWith({
367
- argv: {
368
- api: 'test.yaml',
369
- },
370
- config: {},
371
- version: 'cli-version',
372
- });
373
- });
374
- it('should use destination from option', () => {
375
- const cb = jest.fn();
376
- (0, push_1.transformPush)(cb)({
377
- argv: {
378
- apis: ['test.yaml', 'test@v1'],
379
- destination: 'main@v1',
380
- },
381
- config: {},
382
- version: 'cli-version',
383
- });
384
- expect(cb).toBeCalledWith({
385
- argv: {
386
- destination: 'main@v1',
387
- api: 'test.yaml',
388
- },
389
- config: {},
390
- version: 'cli-version',
391
- });
392
- });
393
- it('should use --job-id option firstly', () => {
394
- const cb = jest.fn();
395
- (0, push_1.transformPush)(cb)({
396
- argv: {
397
- 'batch-id': 'b-123',
398
- 'job-id': 'j-123',
399
- apis: ['test'],
400
- branch: 'test',
401
- destination: 'main@v1',
402
- },
403
- config: {},
404
- version: 'cli-version',
405
- });
406
- expect(cb).toBeCalledWith({
407
- argv: {
408
- 'job-id': 'j-123',
409
- api: 'test',
410
- branchName: 'test',
411
- destination: 'main@v1',
412
- },
413
- config: {},
414
- version: 'cli-version',
415
- });
416
- });
417
- it('should accept no arguments at all', () => {
418
- const cb = jest.fn();
419
- (0, push_1.transformPush)(cb)({ argv: {}, config: {}, version: 'cli-version' });
420
- expect(cb).toBeCalledWith({ argv: {}, config: {}, version: 'cli-version' });
421
- });
422
- });
423
- describe('getDestinationProps', () => {
424
- it('should get valid destination props for the full destination syntax', () => {
425
- expect((0, push_1.getDestinationProps)('@testing_org/main@v1', 'org-from-config')).toEqual({
426
- organizationId: 'testing_org',
427
- name: 'main',
428
- version: 'v1',
429
- });
430
- });
431
- it('should fallback the organizationId from a config for the short destination syntax', () => {
432
- expect((0, push_1.getDestinationProps)('main@v1', 'org-from-config')).toEqual({
433
- organizationId: 'org-from-config',
434
- name: 'main',
435
- version: 'v1',
436
- });
437
- });
438
- it('should fallback the organizationId from a config if no destination provided', () => {
439
- expect((0, push_1.getDestinationProps)(undefined, 'org-from-config')).toEqual({
440
- organizationId: 'org-from-config',
441
- });
442
- });
443
- it('should return empty organizationId if there is no one found', () => {
444
- expect((0, push_1.getDestinationProps)('main@v1', undefined)).toEqual({
445
- organizationId: undefined,
446
- name: 'main',
447
- version: 'v1',
448
- });
449
- });
450
- it('should return organizationId from destination string', () => {
451
- expect((0, push_1.getDestinationProps)('@test-org/main@main-v1', undefined)).toEqual({
452
- organizationId: 'test-org',
453
- name: 'main',
454
- version: 'main-v1',
455
- });
456
- });
457
- it('should return organizationId, version and empty name from destination string', () => {
458
- expect((0, push_1.getDestinationProps)('@test_org/@main_v1', undefined)).toEqual({
459
- organizationId: 'test_org',
460
- name: '',
461
- version: 'main_v1',
462
- });
463
- });
464
- it('should validate organizationId with space and version with dot', () => {
465
- expect((0, push_1.getDestinationProps)('@test org/simple_name@main.v1', undefined)).toEqual({
466
- organizationId: 'test org',
467
- name: 'simple_name',
468
- version: 'main.v1',
469
- });
470
- });
471
- it('should not work with "@" in destination name', () => {
472
- expect((0, push_1.getDestinationProps)('@test org/simple@name@main.v1', undefined)).toEqual({
473
- organizationId: undefined,
474
- name: undefined,
475
- version: undefined,
476
- });
477
- });
478
- });
479
- describe('getApiRoot', () => {
480
- let config = {
481
- apis: {
482
- 'main@v1': {
483
- root: 'openapi.yaml',
484
- },
485
- main: {
486
- root: 'latest.yaml',
487
- },
488
- },
489
- };
490
- it('should resolve the correct api for a valid name & version', () => {
491
- expect((0, push_1.getApiRoot)({ name: 'main', version: 'v1', config })).toEqual('openapi.yaml');
492
- });
493
- it('should resolve the latest version of api if there is no matching version', () => {
494
- expect((0, push_1.getApiRoot)({ name: 'main', version: 'latest', config })).toEqual('latest.yaml');
495
- });
496
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const abort_controller_1 = require("abort-controller");
4
- const fetch_with_timeout_1 = require("../utils/fetch-with-timeout");
5
- const openapi_core_1 = require("@redocly/openapi-core");
6
- const https_proxy_agent_1 = require("https-proxy-agent");
7
- jest.mock('@redocly/openapi-core');
8
- const signalInstance = new abort_controller_1.default().signal;
9
- const mockFetch = jest.fn(() => Promise.resolve({
10
- ok: true,
11
- status: 200,
12
- json: () => Promise.resolve({}),
13
- headers: new Headers(),
14
- statusText: 'OK',
15
- redirected: false,
16
- type: 'default',
17
- url: '',
18
- clone: () => ({}),
19
- body: null,
20
- bodyUsed: false,
21
- arrayBuffer: async () => new ArrayBuffer(0),
22
- blob: async () => new Blob(),
23
- formData: async () => new FormData(),
24
- text: async () => '',
25
- signal: signalInstance,
26
- dispatcher: undefined,
27
- }));
28
- const originalFetch = global.fetch;
29
- global.fetch = mockFetch;
30
- describe('fetchWithTimeout', () => {
31
- beforeAll(() => {
32
- // @ts-ignore
33
- global.setTimeout = jest.fn();
34
- global.clearTimeout = jest.fn();
35
- });
36
- beforeEach(() => {
37
- openapi_core_1.getProxyAgent.mockReturnValueOnce(undefined);
38
- });
39
- afterAll(() => {
40
- global.fetch = originalFetch;
41
- });
42
- it('should call fetch with signal', async () => {
43
- await (0, fetch_with_timeout_1.default)('url', { timeout: 1000 });
44
- expect(global.setTimeout).toHaveBeenCalledTimes(1);
45
- expect(global.fetch).toHaveBeenCalledWith('url', expect.objectContaining({
46
- signal: expect.any(AbortSignal),
47
- dispatcher: undefined,
48
- }));
49
- expect(global.clearTimeout).toHaveBeenCalledTimes(1);
50
- });
51
- it('should call fetch with proxy agent', async () => {
52
- openapi_core_1.getProxyAgent.mockRestore();
53
- const proxyAgent = new https_proxy_agent_1.HttpsProxyAgent('http://localhost');
54
- openapi_core_1.getProxyAgent.mockReturnValueOnce(proxyAgent);
55
- await (0, fetch_with_timeout_1.default)('url');
56
- expect(global.fetch).toHaveBeenCalledWith('url', { dispatcher: proxyAgent });
57
- });
58
- it('should call fetch without signal when timeout is not passed', async () => {
59
- await (0, fetch_with_timeout_1.default)('url');
60
- expect(global.setTimeout).not.toHaveBeenCalled();
61
- expect(global.fetch).toHaveBeenCalledWith('url', { agent: undefined });
62
- expect(global.clearTimeout).not.toHaveBeenCalled();
63
- });
64
- });
@@ -1,21 +0,0 @@
1
- export declare const ConfigFixture: {
2
- configFile: null;
3
- styleguide: {
4
- addIgnore: jest.Mock<any, any>;
5
- skipRules: jest.Mock<any, any>;
6
- skipPreprocessors: jest.Mock<any, any>;
7
- saveIgnore: jest.Mock<any, any>;
8
- skipDecorators: jest.Mock<any, any>;
9
- ignore: null;
10
- decorators: {
11
- oas2: {};
12
- oas3_0: {};
13
- oas3_1: {};
14
- };
15
- preprocessors: {
16
- oas2: {};
17
- oas3_0: {};
18
- oas3_1: {};
19
- };
20
- };
21
- };