@usebruno/filestore 0.5.0 → 0.7.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 (161) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/workers/worker-script.js +1 -1
  4. package/dist/cjs/workers/worker-script.js.map +1 -1
  5. package/dist/constants.d.ts +3 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/esm/index.js +1 -1
  8. package/dist/esm/index.js.map +1 -1
  9. package/dist/esm/workers/worker-script.js +1 -1
  10. package/dist/esm/workers/worker-script.js.map +1 -1
  11. package/dist/formats/bru/index.d.ts +20 -0
  12. package/dist/formats/bru/index.d.ts.map +1 -0
  13. package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts +57 -0
  14. package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts.map +1 -0
  15. package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts +2 -0
  16. package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts.map +1 -0
  17. package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts +2 -0
  18. package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts.map +1 -0
  19. package/dist/{cjs/workers/formats → formats}/bru/utils/oauth2-additional-params.d.ts +1 -0
  20. package/dist/formats/bru/utils/oauth2-additional-params.d.ts.map +1 -0
  21. package/dist/{esm/formats → formats}/bru/utils/request-parse-and-redact-body-data.d.ts +1 -0
  22. package/dist/formats/bru/utils/request-parse-and-redact-body-data.d.ts.map +1 -0
  23. package/dist/formats/yml/common/actions.d.ts +14 -0
  24. package/dist/formats/yml/common/actions.d.ts.map +1 -0
  25. package/dist/formats/yml/common/assertions.d.ts +5 -0
  26. package/dist/formats/yml/common/assertions.d.ts.map +1 -0
  27. package/dist/formats/yml/common/auth-oauth2.d.ts +5 -0
  28. package/dist/formats/yml/common/auth-oauth2.d.ts.map +1 -0
  29. package/dist/formats/yml/common/auth.d.ts +5 -0
  30. package/dist/formats/yml/common/auth.d.ts.map +1 -0
  31. package/dist/formats/yml/common/body.d.ts +5 -0
  32. package/dist/formats/yml/common/body.d.ts.map +1 -0
  33. package/dist/formats/yml/common/headers.d.ts +7 -0
  34. package/dist/formats/yml/common/headers.d.ts.map +1 -0
  35. package/dist/formats/yml/common/params.d.ts +5 -0
  36. package/dist/formats/yml/common/params.d.ts.map +1 -0
  37. package/dist/formats/yml/common/scripts.d.ts +14 -0
  38. package/dist/formats/yml/common/scripts.d.ts.map +1 -0
  39. package/dist/formats/yml/common/variables.d.ts +17 -0
  40. package/dist/formats/yml/common/variables.d.ts.map +1 -0
  41. package/dist/formats/yml/index.d.ts +10 -0
  42. package/dist/formats/yml/index.d.ts.map +1 -0
  43. package/dist/formats/yml/items/parseGraphQLRequest.d.ts +5 -0
  44. package/dist/formats/yml/items/parseGraphQLRequest.d.ts.map +1 -0
  45. package/dist/formats/yml/items/parseGrpcRequest.d.ts +5 -0
  46. package/dist/formats/yml/items/parseGrpcRequest.d.ts.map +1 -0
  47. package/dist/formats/yml/items/parseHttpRequest.d.ts +5 -0
  48. package/dist/formats/yml/items/parseHttpRequest.d.ts.map +1 -0
  49. package/dist/formats/yml/items/parseScript.d.ts +5 -0
  50. package/dist/formats/yml/items/parseScript.d.ts.map +1 -0
  51. package/dist/formats/yml/items/parseWebsocketRequest.d.ts +5 -0
  52. package/dist/formats/yml/items/parseWebsocketRequest.d.ts.map +1 -0
  53. package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts +4 -0
  54. package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts.map +1 -0
  55. package/dist/formats/yml/items/stringifyGrpcRequest.d.ts +4 -0
  56. package/dist/formats/yml/items/stringifyGrpcRequest.d.ts.map +1 -0
  57. package/dist/formats/yml/items/stringifyHttpRequest.d.ts +4 -0
  58. package/dist/formats/yml/items/stringifyHttpRequest.d.ts.map +1 -0
  59. package/dist/formats/yml/items/stringifyScript.d.ts +4 -0
  60. package/dist/formats/yml/items/stringifyScript.d.ts.map +1 -0
  61. package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts +4 -0
  62. package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts.map +1 -0
  63. package/dist/formats/yml/parseCollection.d.ts +8 -0
  64. package/dist/formats/yml/parseCollection.d.ts.map +1 -0
  65. package/dist/formats/yml/parseEnvironment.d.ts +4 -0
  66. package/dist/formats/yml/parseEnvironment.d.ts.map +1 -0
  67. package/dist/formats/yml/parseFolder.d.ts +4 -0
  68. package/dist/formats/yml/parseFolder.d.ts.map +1 -0
  69. package/dist/formats/yml/parseItem.d.ts +4 -0
  70. package/dist/formats/yml/parseItem.d.ts.map +1 -0
  71. package/dist/formats/yml/stringifyCollection.d.ts +3 -0
  72. package/dist/formats/yml/stringifyCollection.d.ts.map +1 -0
  73. package/dist/formats/yml/stringifyEnvironment.d.ts +4 -0
  74. package/dist/formats/yml/stringifyEnvironment.d.ts.map +1 -0
  75. package/dist/formats/yml/stringifyFolder.d.ts +4 -0
  76. package/dist/formats/yml/stringifyFolder.d.ts.map +1 -0
  77. package/dist/formats/yml/stringifyItem.d.ts +4 -0
  78. package/dist/formats/yml/stringifyItem.d.ts.map +1 -0
  79. package/dist/formats/yml/utils.d.ts +3 -0
  80. package/dist/formats/yml/utils.d.ts.map +1 -0
  81. package/dist/index.d.ts +24 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/types.d.ts +19 -0
  84. package/dist/types.d.ts.map +1 -0
  85. package/dist/utils/index.d.ts +6 -0
  86. package/dist/utils/index.d.ts.map +1 -0
  87. package/dist/{esm/workers → workers}/WorkerQueue/index.d.ts +1 -0
  88. package/dist/workers/WorkerQueue/index.d.ts.map +1 -0
  89. package/dist/workers/index.d.ts +12 -0
  90. package/dist/workers/index.d.ts.map +1 -0
  91. package/dist/workers/worker-script.d.ts +2 -0
  92. package/dist/workers/worker-script.d.ts.map +1 -0
  93. package/package.json +12 -6
  94. package/src/constants.ts +3 -0
  95. package/src/formats/bru/index.ts +9 -9
  96. package/src/formats/bru/tests/oauth2-additional-params.spec.js +1 -1
  97. package/src/formats/bru/utils/oauth2-additional-params.ts +17 -18
  98. package/src/formats/bru/utils/request-parse-and-redact-body-data.ts +13 -13
  99. package/src/formats/yml/common/actions.ts +78 -0
  100. package/src/formats/yml/common/assertions.ts +146 -0
  101. package/src/formats/yml/common/auth-oauth2.ts +555 -0
  102. package/src/formats/yml/common/auth.ts +245 -0
  103. package/src/formats/yml/common/body.ts +238 -0
  104. package/src/formats/yml/common/headers.ts +58 -0
  105. package/src/formats/yml/common/params.ts +57 -0
  106. package/src/formats/yml/common/scripts.ts +64 -0
  107. package/src/formats/yml/common/variables.ts +68 -0
  108. package/src/formats/yml/index.ts +20 -0
  109. package/src/formats/yml/items/parseGraphQLRequest.ts +137 -0
  110. package/src/formats/yml/items/parseGrpcRequest.ts +116 -0
  111. package/src/formats/yml/items/parseHttpRequest.ts +195 -0
  112. package/src/formats/yml/items/parseScript.ts +25 -0
  113. package/src/formats/yml/items/parseWebsocketRequest.ts +107 -0
  114. package/src/formats/yml/items/stringifyGraphQLRequest.ts +168 -0
  115. package/src/formats/yml/items/stringifyGrpcRequest.ts +137 -0
  116. package/src/formats/yml/items/stringifyHttpRequest.ts +222 -0
  117. package/src/formats/yml/items/stringifyScript.ts +22 -0
  118. package/src/formats/yml/items/stringifyWebsocketRequest.ts +114 -0
  119. package/src/formats/yml/parseCollection.ts +220 -0
  120. package/src/formats/yml/parseEnvironment.ts +57 -0
  121. package/src/formats/yml/parseFolder.ts +93 -0
  122. package/src/formats/yml/parseItem.ts +102 -0
  123. package/src/formats/yml/stringifyCollection.ts +264 -0
  124. package/src/formats/yml/stringifyEnvironment.ts +67 -0
  125. package/src/formats/yml/stringifyFolder.ts +107 -0
  126. package/src/formats/yml/stringifyItem.ts +37 -0
  127. package/src/formats/yml/utils.ts +38 -0
  128. package/src/index.ts +64 -32
  129. package/src/types/bruno-lang.d.ts +1 -1
  130. package/src/types.ts +5 -124
  131. package/src/utils/index.ts +25 -0
  132. package/src/workers/WorkerQueue/index.ts +10 -10
  133. package/src/workers/index.ts +21 -20
  134. package/src/workers/worker-script.ts +21 -6
  135. package/dist/cjs/formats/bru/index.d.ts +0 -19
  136. package/dist/cjs/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
  137. package/dist/cjs/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
  138. package/dist/cjs/index.d.ts +0 -16
  139. package/dist/cjs/types.d.ts +0 -142
  140. package/dist/cjs/workers/WorkerQueue/index.d.ts +0 -26
  141. package/dist/cjs/workers/formats/bru/index.d.ts +0 -19
  142. package/dist/cjs/workers/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
  143. package/dist/cjs/workers/index.d.ts +0 -16
  144. package/dist/cjs/workers/types.d.ts +0 -142
  145. package/dist/cjs/workers/worker-script.d.ts +0 -1
  146. package/dist/cjs/workers/workers/WorkerQueue/index.d.ts +0 -26
  147. package/dist/cjs/workers/workers/index.d.ts +0 -10
  148. package/dist/cjs/workers/workers/worker-script.d.ts +0 -1
  149. package/dist/esm/formats/bru/index.d.ts +0 -19
  150. package/dist/esm/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
  151. package/dist/esm/index.d.ts +0 -16
  152. package/dist/esm/types.d.ts +0 -142
  153. package/dist/esm/workers/formats/bru/index.d.ts +0 -19
  154. package/dist/esm/workers/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
  155. package/dist/esm/workers/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
  156. package/dist/esm/workers/index.d.ts +0 -16
  157. package/dist/esm/workers/types.d.ts +0 -142
  158. package/dist/esm/workers/worker-script.d.ts +0 -1
  159. package/dist/esm/workers/workers/WorkerQueue/index.d.ts +0 -26
  160. package/dist/esm/workers/workers/index.d.ts +0 -10
  161. package/dist/esm/workers/workers/worker-script.d.ts +0 -1
@@ -0,0 +1,220 @@
1
+ import type { OpenCollection } from '@opencollection/types';
2
+ import type { FolderRoot } from '@usebruno/schema-types/collection/folder';
3
+ import { parseYml } from './utils';
4
+ import { toBrunoAuth } from './common/auth';
5
+ import { toBrunoHttpHeaders } from './common/headers';
6
+ import { toBrunoVariables } from './common/variables';
7
+ import { toBrunoPostResponseVariables } from './common/actions';
8
+ import { toBrunoScripts } from './common/scripts';
9
+ import { ensureString } from '../../utils';
10
+
11
+ interface ParsedCollection {
12
+ collectionRoot: FolderRoot;
13
+ brunoConfig: Record<string, any>;
14
+ }
15
+
16
+ const parseCollection = (ymlString: string): ParsedCollection => {
17
+ try {
18
+ const oc: OpenCollection = parseYml(ymlString);
19
+
20
+ // bruno config
21
+ const brunoConfig: Record<string, any> = {
22
+ opencollection: oc.opencollection || '1.0.0',
23
+ name: ensureString(oc.info?.name, 'Untitled Collection'),
24
+ type: 'collection',
25
+ ignore: []
26
+ };
27
+
28
+ const brunoExtension = (oc.extensions as any)?.bruno;
29
+ if (brunoExtension?.ignore && Array.isArray(brunoExtension.ignore)) {
30
+ brunoConfig.ignore = brunoExtension.ignore;
31
+ }
32
+
33
+ // presets
34
+ if (brunoExtension?.presets) {
35
+ const presets = brunoExtension.presets as any;
36
+ if (presets.request) {
37
+ brunoConfig.presets = {
38
+ requestType: presets.request.type || [],
39
+ requestUrl: presets.request.url || []
40
+ };
41
+ }
42
+ }
43
+
44
+ // bruno-specific script extensions
45
+ const brunoExtensions = oc.extensions?.bruno as any;
46
+ if (Array.isArray(brunoExtensions?.scripts?.additionalContextRoots)) {
47
+ const sanitizedRoots = brunoExtensions.scripts.additionalContextRoots
48
+ .filter((item: any) => typeof item === 'string');
49
+
50
+ if (sanitizedRoots.length > 0) {
51
+ brunoConfig.scripts = {
52
+ ...brunoConfig.scripts,
53
+ additionalContextRoots: sanitizedRoots
54
+ };
55
+ }
56
+ }
57
+
58
+ // protobuf
59
+ if (oc.config?.protobuf) {
60
+ brunoConfig.protobuf = {
61
+ protofFiles: oc.config.protobuf.protoFiles?.map((protoFile: any) => ({
62
+ path: protoFile.path
63
+ })) || [],
64
+ importPaths: oc.config.protobuf.importPaths?.map((importPath: any) => ({
65
+ path: importPath.path,
66
+ disabled: importPath.disabled || false
67
+ })) || []
68
+ };
69
+ }
70
+
71
+ // proxy - only support newer format
72
+ // Default: inherit from global preferences
73
+ brunoConfig.proxy = {
74
+ inherit: true,
75
+ config: {
76
+ protocol: 'http',
77
+ hostname: '',
78
+ port: '',
79
+ auth: {
80
+ username: '',
81
+ password: ''
82
+ },
83
+ bypassProxy: ''
84
+ }
85
+ };
86
+
87
+ if (oc.config?.proxy && typeof oc.config.proxy === 'object') {
88
+ // Validate newer format: must have 'inherit' and 'config' properties
89
+ const proxyConfig = oc.config.proxy as any;
90
+
91
+ if ('inherit' in proxyConfig && typeof proxyConfig.inherit === 'boolean' && proxyConfig.config && typeof proxyConfig.config === 'object') {
92
+ // Valid newer format
93
+ brunoConfig.proxy = {
94
+ inherit: proxyConfig.inherit,
95
+ config: {
96
+ protocol: proxyConfig.config.protocol || 'http',
97
+ hostname: proxyConfig.config.hostname || '',
98
+ port: proxyConfig.config.port || '',
99
+ auth: {
100
+ username: proxyConfig.config.auth?.username || '',
101
+ password: proxyConfig.config.auth?.password || ''
102
+ },
103
+ bypassProxy: proxyConfig.config.bypassProxy || ''
104
+ }
105
+ };
106
+
107
+ // Handle optional disabled field
108
+ if (proxyConfig.disabled === true) {
109
+ brunoConfig.proxy.disabled = true;
110
+ }
111
+
112
+ // Handle optional auth.disabled field
113
+ if (proxyConfig.config.auth?.disabled === true) {
114
+ brunoConfig.proxy.config.auth.disabled = true;
115
+ }
116
+ }
117
+ // If not in newer format, use default (inherit: true)
118
+ }
119
+
120
+ // client certificates
121
+ if (oc.config?.clientCertificates?.length) {
122
+ brunoConfig.clientCertificates = {
123
+ certs: oc.config.clientCertificates.map((cert: any) => {
124
+ if (cert.type === 'pem') {
125
+ return {
126
+ domain: cert.domain,
127
+ type: 'cert',
128
+ certFilePath: cert.certificateFilePath,
129
+ keyFilePath: cert.privateKeyFilePath,
130
+ passphrase: cert.passphrase || ''
131
+ };
132
+ } else if (cert.type === 'pkcs12') {
133
+ return {
134
+ domain: cert.domain,
135
+ type: 'pfx',
136
+ pfxFilePath: cert.pkcs12FilePath,
137
+ passphrase: cert.passphrase || ''
138
+ };
139
+ }
140
+ return null;
141
+ }).filter((cert: any) => cert !== null)
142
+ };
143
+ }
144
+
145
+ // collection root
146
+ const collectionRoot: FolderRoot = {
147
+ meta: null,
148
+ request: null,
149
+ docs: null
150
+ };
151
+
152
+ // request defaults
153
+ if (oc.request) {
154
+ collectionRoot.request = {
155
+ headers: null,
156
+ auth: null,
157
+ script: {
158
+ req: null,
159
+ res: null
160
+ },
161
+ vars: {
162
+ req: [],
163
+ res: []
164
+ },
165
+ tests: null
166
+ };
167
+
168
+ // headers
169
+ const headers = toBrunoHttpHeaders(oc.request.headers);
170
+ collectionRoot.request.headers = headers || [];
171
+
172
+ // auth
173
+ const auth = toBrunoAuth(oc.request.auth);
174
+ if (auth) {
175
+ collectionRoot.request.auth = auth;
176
+ }
177
+
178
+ // variables
179
+ const variables = toBrunoVariables(oc.request.variables);
180
+ const postResponseVars = toBrunoPostResponseVariables((oc.request as any).actions);
181
+ collectionRoot.request.vars = {
182
+ req: variables.req,
183
+ res: postResponseVars
184
+ };
185
+
186
+ // scripts
187
+ const scripts = toBrunoScripts(oc.request.scripts);
188
+ if (scripts?.script && collectionRoot.request.script) {
189
+ if (scripts.script.req) {
190
+ collectionRoot.request.script.req = scripts.script.req;
191
+ }
192
+ if (scripts.script.res) {
193
+ collectionRoot.request.script.res = scripts.script.res;
194
+ }
195
+ }
196
+ if (scripts?.tests) {
197
+ collectionRoot.request.tests = scripts.tests;
198
+ }
199
+ }
200
+
201
+ // docs
202
+ if (oc.docs) {
203
+ if (typeof oc.docs === 'string') {
204
+ collectionRoot.docs = oc.docs;
205
+ } else if (typeof oc.docs === 'object' && oc.docs.content) {
206
+ collectionRoot.docs = oc.docs.content;
207
+ }
208
+ }
209
+
210
+ return {
211
+ collectionRoot,
212
+ brunoConfig
213
+ };
214
+ } catch (error) {
215
+ console.error('Error parsing collection:', error);
216
+ throw error;
217
+ }
218
+ };
219
+
220
+ export default parseCollection;
@@ -0,0 +1,57 @@
1
+ import type { Environment as BrunoEnvironment, EnvironmentVariable as BrunoEnvironmentVariable } from '@usebruno/schema-types/collection/environment';
2
+ import type { Environment } from '@opencollection/types/config/environments';
3
+ import type { Variable, SecretVariable } from '@opencollection/types/common/variables';
4
+ import { parseYml } from './utils';
5
+ import { uuid, ensureString } from '../../utils';
6
+
7
+ const isSecretVariable = (v: Variable | SecretVariable): v is SecretVariable => {
8
+ return 'secret' in v && v.secret === true;
9
+ };
10
+
11
+ const toBrunoEnvironmentVariables = (variables: (Variable | SecretVariable)[] | null | undefined): BrunoEnvironmentVariable[] => {
12
+ if (!variables?.length) {
13
+ return [];
14
+ }
15
+
16
+ return variables.map((v): BrunoEnvironmentVariable => {
17
+ if (isSecretVariable(v)) {
18
+ return {
19
+ uid: uuid(),
20
+ name: ensureString(v.name),
21
+ value: '',
22
+ type: 'text',
23
+ enabled: v.disabled !== true,
24
+ secret: true
25
+ };
26
+ }
27
+ const variable: BrunoEnvironmentVariable = {
28
+ uid: uuid(),
29
+ name: ensureString(v.name),
30
+ value: ensureString(v.value),
31
+ type: 'text',
32
+ enabled: v.disabled !== true,
33
+ secret: false
34
+ };
35
+ return variable;
36
+ });
37
+ };
38
+
39
+ const parseEnvironment = (ymlString: string): BrunoEnvironment => {
40
+ try {
41
+ const ocEnvironment: Environment = parseYml(ymlString);
42
+
43
+ const brunoEnvironment: BrunoEnvironment = {
44
+ uid: uuid(),
45
+ name: ensureString(ocEnvironment.name, 'Untitled Environment'),
46
+ variables: toBrunoEnvironmentVariables(ocEnvironment.variables),
47
+ color: ocEnvironment.color || null
48
+ };
49
+
50
+ return brunoEnvironment;
51
+ } catch (error) {
52
+ console.error('Error parsing environment:', error);
53
+ throw error;
54
+ }
55
+ };
56
+
57
+ export default parseEnvironment;
@@ -0,0 +1,93 @@
1
+ import type { FolderRoot } from '@usebruno/schema-types/collection/folder';
2
+ import type { Folder } from '@opencollection/types/collection/item';
3
+ import { parseYml } from './utils';
4
+ import { toBrunoAuth } from './common/auth';
5
+ import { toBrunoHttpHeaders } from './common/headers';
6
+ import { toBrunoVariables } from './common/variables';
7
+ import { toBrunoPostResponseVariables } from './common/actions';
8
+ import { toBrunoScripts } from './common/scripts';
9
+ import { ensureString } from '../../utils';
10
+
11
+ const parseFolder = (ymlString: string): FolderRoot => {
12
+ try {
13
+ const ocFolder: Folder = parseYml(ymlString);
14
+
15
+ const info = ocFolder.info;
16
+
17
+ const folderRoot: FolderRoot = {
18
+ meta: {
19
+ name: ensureString(info?.name, 'Untitled Folder'),
20
+ seq: info?.seq || 1
21
+ },
22
+ request: null,
23
+ docs: null
24
+ };
25
+
26
+ // request defaults
27
+ if (ocFolder.request) {
28
+ folderRoot.request = {
29
+ headers: [],
30
+ auth: null,
31
+ script: {
32
+ req: null,
33
+ res: null
34
+ },
35
+ vars: {
36
+ req: [],
37
+ res: []
38
+ },
39
+ tests: null
40
+ };
41
+
42
+ // headers
43
+ const headers = toBrunoHttpHeaders(ocFolder.request.headers);
44
+ if (headers) {
45
+ folderRoot.request.headers = headers;
46
+ }
47
+
48
+ // auth
49
+ const auth = toBrunoAuth(ocFolder.request.auth);
50
+ if (auth) {
51
+ folderRoot.request.auth = auth;
52
+ }
53
+
54
+ // variables
55
+ const variables = toBrunoVariables(ocFolder.request.variables);
56
+ const postResponseVars = toBrunoPostResponseVariables((ocFolder.request as any).actions);
57
+ folderRoot.request.vars = {
58
+ req: variables.req,
59
+ res: postResponseVars
60
+ };
61
+
62
+ // scripts
63
+ const scripts = toBrunoScripts(ocFolder.request.scripts);
64
+ if (scripts?.script && folderRoot.request.script) {
65
+ if (scripts.script.req) {
66
+ folderRoot.request.script.req = scripts.script.req;
67
+ }
68
+ if (scripts.script.res) {
69
+ folderRoot.request.script.res = scripts.script.res;
70
+ }
71
+ }
72
+ if (scripts?.tests) {
73
+ folderRoot.request.tests = scripts.tests;
74
+ }
75
+ }
76
+
77
+ // docs (now at root level)
78
+ if (ocFolder.docs) {
79
+ if (typeof ocFolder.docs === 'string' && ocFolder.docs.trim().length) {
80
+ folderRoot.docs = ocFolder.docs;
81
+ } else if (typeof ocFolder.docs === 'object' && ocFolder.docs.content?.trim().length) {
82
+ folderRoot.docs = ocFolder.docs.content;
83
+ }
84
+ }
85
+
86
+ return folderRoot;
87
+ } catch (error) {
88
+ console.error('Error parsing folder:', error);
89
+ throw error;
90
+ }
91
+ };
92
+
93
+ export default parseFolder;
@@ -0,0 +1,102 @@
1
+ import type { Item as BrunoItem } from '@usebruno/schema-types/collection/item';
2
+ import type { Item, ScriptFile } from '@opencollection/types/collection/item';
3
+ import type { HttpRequest } from '@opencollection/types/requests/http';
4
+ import type { GraphQLRequest } from '@opencollection/types/requests/graphql';
5
+ import type { GrpcRequest } from '@opencollection/types/requests/grpc';
6
+ import type { WebSocketRequest } from '@opencollection/types/requests/websocket';
7
+ import { parseYml } from './utils';
8
+ import parseHttpRequest from './items/parseHttpRequest';
9
+ import parseGraphQLRequest from './items/parseGraphQLRequest';
10
+ import parseGrpcRequest from './items/parseGrpcRequest';
11
+ import parseWebsocketRequest from './items/parseWebsocketRequest';
12
+ import parseScript from './items/parseScript';
13
+
14
+ // Helper to get the type from an item (now in info block)
15
+ const getItemType = (item: Item): string | undefined => {
16
+ if ('info' in item && item.info && 'type' in item.info) {
17
+ return item.info.type;
18
+ }
19
+ // For ScriptFile which still has type at root
20
+ if ('type' in item) {
21
+ return (item as ScriptFile).type;
22
+ }
23
+ return undefined;
24
+ };
25
+
26
+ /**
27
+ * In v3.0.0-rc1 release auth was present under runtime property for all requests
28
+ * This has now been moved to the respective request properties
29
+ * This backward compatibility has been put in place for folks who tried out our early preview
30
+ * Should be safe to remove this in 3 months. Delete after 5 Apr 2026
31
+ */
32
+ const ensureAuthV3Rc1BackwardsCompatibility = (parsedItemYml: any): any => {
33
+ const itemType = parsedItemYml?.info?.type;
34
+
35
+ switch (itemType) {
36
+ case 'http':
37
+ if (parsedItemYml.runtime?.auth && !parsedItemYml.http?.auth) {
38
+ parsedItemYml.http.auth = parsedItemYml.runtime.auth;
39
+ }
40
+ break;
41
+ case 'graphql':
42
+ if (parsedItemYml.runtime?.auth && !parsedItemYml.graphql?.auth) {
43
+ parsedItemYml.graphql.auth = parsedItemYml.runtime.auth;
44
+ }
45
+ break;
46
+ case 'grpc':
47
+ if (parsedItemYml.runtime?.auth && !parsedItemYml.grpc?.auth) {
48
+ parsedItemYml.grpc.auth = parsedItemYml.runtime.auth;
49
+ }
50
+ break;
51
+ case 'websocket':
52
+ if (parsedItemYml.runtime?.auth && !parsedItemYml.websocket?.auth) {
53
+ parsedItemYml.websocket.auth = parsedItemYml.runtime.auth;
54
+ }
55
+ break;
56
+ default:
57
+ break;
58
+ }
59
+
60
+ return parsedItemYml;
61
+ };
62
+
63
+ const parseItem = (ymlString: string): BrunoItem => {
64
+ try {
65
+ const parsedYml = parseYml(ymlString);
66
+
67
+ const ocItem: Item = ensureAuthV3Rc1BackwardsCompatibility(parsedYml);
68
+ const itemType = getItemType(ocItem);
69
+
70
+ if (!ocItem || !itemType) {
71
+ throw new Error('Invalid item: missing type');
72
+ }
73
+
74
+ switch (itemType) {
75
+ case 'http':
76
+ return parseHttpRequest(ocItem as HttpRequest);
77
+
78
+ case 'graphql':
79
+ return parseGraphQLRequest(ocItem as GraphQLRequest);
80
+
81
+ case 'grpc':
82
+ return parseGrpcRequest(ocItem as GrpcRequest);
83
+
84
+ case 'websocket':
85
+ return parseWebsocketRequest(ocItem as WebSocketRequest);
86
+
87
+ case 'script':
88
+ return parseScript(ocItem as ScriptFile);
89
+
90
+ case 'folder':
91
+ throw new Error('Folder items should be handled separately using parseFolder');
92
+
93
+ default:
94
+ throw new Error(`Unsupported item type: ${itemType}`);
95
+ }
96
+ } catch (error) {
97
+ console.error('Error parsing item:', error);
98
+ throw error;
99
+ }
100
+ };
101
+
102
+ export default parseItem;