@usebruno/filestore 0.4.0 → 0.6.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 (157) 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/esm/index.js +1 -1
  6. package/dist/esm/index.js.map +1 -1
  7. package/dist/esm/workers/worker-script.js +1 -1
  8. package/dist/esm/workers/worker-script.js.map +1 -1
  9. package/dist/formats/bru/index.d.ts +20 -0
  10. package/dist/formats/bru/index.d.ts.map +1 -0
  11. package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts +57 -0
  12. package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts.map +1 -0
  13. package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts +2 -0
  14. package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts.map +1 -0
  15. package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts +2 -0
  16. package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts.map +1 -0
  17. package/dist/{esm/formats → formats}/bru/utils/oauth2-additional-params.d.ts +1 -0
  18. package/dist/formats/bru/utils/oauth2-additional-params.d.ts.map +1 -0
  19. package/dist/{cjs/workers/formats → formats}/bru/utils/request-parse-and-redact-body-data.d.ts +1 -0
  20. package/dist/formats/bru/utils/request-parse-and-redact-body-data.d.ts.map +1 -0
  21. package/dist/formats/yml/common/actions.d.ts +14 -0
  22. package/dist/formats/yml/common/actions.d.ts.map +1 -0
  23. package/dist/formats/yml/common/assertions.d.ts +5 -0
  24. package/dist/formats/yml/common/assertions.d.ts.map +1 -0
  25. package/dist/formats/yml/common/auth-oauth2.d.ts +5 -0
  26. package/dist/formats/yml/common/auth-oauth2.d.ts.map +1 -0
  27. package/dist/formats/yml/common/auth.d.ts +5 -0
  28. package/dist/formats/yml/common/auth.d.ts.map +1 -0
  29. package/dist/formats/yml/common/body.d.ts +5 -0
  30. package/dist/formats/yml/common/body.d.ts.map +1 -0
  31. package/dist/formats/yml/common/headers.d.ts +7 -0
  32. package/dist/formats/yml/common/headers.d.ts.map +1 -0
  33. package/dist/formats/yml/common/params.d.ts +5 -0
  34. package/dist/formats/yml/common/params.d.ts.map +1 -0
  35. package/dist/formats/yml/common/scripts.d.ts +14 -0
  36. package/dist/formats/yml/common/scripts.d.ts.map +1 -0
  37. package/dist/formats/yml/common/variables.d.ts +17 -0
  38. package/dist/formats/yml/common/variables.d.ts.map +1 -0
  39. package/dist/formats/yml/index.d.ts +10 -0
  40. package/dist/formats/yml/index.d.ts.map +1 -0
  41. package/dist/formats/yml/items/parseGraphQLRequest.d.ts +5 -0
  42. package/dist/formats/yml/items/parseGraphQLRequest.d.ts.map +1 -0
  43. package/dist/formats/yml/items/parseGrpcRequest.d.ts +5 -0
  44. package/dist/formats/yml/items/parseGrpcRequest.d.ts.map +1 -0
  45. package/dist/formats/yml/items/parseHttpRequest.d.ts +5 -0
  46. package/dist/formats/yml/items/parseHttpRequest.d.ts.map +1 -0
  47. package/dist/formats/yml/items/parseScript.d.ts +5 -0
  48. package/dist/formats/yml/items/parseScript.d.ts.map +1 -0
  49. package/dist/formats/yml/items/parseWebsocketRequest.d.ts +5 -0
  50. package/dist/formats/yml/items/parseWebsocketRequest.d.ts.map +1 -0
  51. package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts +4 -0
  52. package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts.map +1 -0
  53. package/dist/formats/yml/items/stringifyGrpcRequest.d.ts +4 -0
  54. package/dist/formats/yml/items/stringifyGrpcRequest.d.ts.map +1 -0
  55. package/dist/formats/yml/items/stringifyHttpRequest.d.ts +4 -0
  56. package/dist/formats/yml/items/stringifyHttpRequest.d.ts.map +1 -0
  57. package/dist/formats/yml/items/stringifyScript.d.ts +4 -0
  58. package/dist/formats/yml/items/stringifyScript.d.ts.map +1 -0
  59. package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts +4 -0
  60. package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts.map +1 -0
  61. package/dist/formats/yml/parseCollection.d.ts +8 -0
  62. package/dist/formats/yml/parseCollection.d.ts.map +1 -0
  63. package/dist/formats/yml/parseEnvironment.d.ts +4 -0
  64. package/dist/formats/yml/parseEnvironment.d.ts.map +1 -0
  65. package/dist/formats/yml/parseFolder.d.ts +4 -0
  66. package/dist/formats/yml/parseFolder.d.ts.map +1 -0
  67. package/dist/formats/yml/parseItem.d.ts +4 -0
  68. package/dist/formats/yml/parseItem.d.ts.map +1 -0
  69. package/dist/formats/yml/stringifyCollection.d.ts +3 -0
  70. package/dist/formats/yml/stringifyCollection.d.ts.map +1 -0
  71. package/dist/formats/yml/stringifyEnvironment.d.ts +4 -0
  72. package/dist/formats/yml/stringifyEnvironment.d.ts.map +1 -0
  73. package/dist/formats/yml/stringifyFolder.d.ts +4 -0
  74. package/dist/formats/yml/stringifyFolder.d.ts.map +1 -0
  75. package/dist/formats/yml/stringifyItem.d.ts +4 -0
  76. package/dist/formats/yml/stringifyItem.d.ts.map +1 -0
  77. package/dist/formats/yml/utils.d.ts +3 -0
  78. package/dist/formats/yml/utils.d.ts.map +1 -0
  79. package/dist/{cjs/workers/index.d.ts → index.d.ts} +13 -6
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/types.d.ts +19 -0
  82. package/dist/types.d.ts.map +1 -0
  83. package/dist/utils/index.d.ts +5 -0
  84. package/dist/utils/index.d.ts.map +1 -0
  85. package/dist/{esm/workers → workers}/WorkerQueue/index.d.ts +1 -0
  86. package/dist/workers/WorkerQueue/index.d.ts.map +1 -0
  87. package/dist/workers/index.d.ts +12 -0
  88. package/dist/workers/index.d.ts.map +1 -0
  89. package/dist/workers/worker-script.d.ts +2 -0
  90. package/dist/workers/worker-script.d.ts.map +1 -0
  91. package/package.json +12 -6
  92. package/src/formats/bru/index.ts +103 -11
  93. package/src/formats/bru/tests/oauth2-additional-params.spec.js +1 -1
  94. package/src/formats/bru/utils/oauth2-additional-params.ts +17 -18
  95. package/src/formats/bru/utils/request-parse-and-redact-body-data.ts +13 -13
  96. package/src/formats/yml/common/actions.ts +78 -0
  97. package/src/formats/yml/common/assertions.ts +146 -0
  98. package/src/formats/yml/common/auth-oauth2.ts +555 -0
  99. package/src/formats/yml/common/auth.ts +245 -0
  100. package/src/formats/yml/common/body.ts +238 -0
  101. package/src/formats/yml/common/headers.ts +58 -0
  102. package/src/formats/yml/common/params.ts +57 -0
  103. package/src/formats/yml/common/scripts.ts +64 -0
  104. package/src/formats/yml/common/variables.ts +68 -0
  105. package/src/formats/yml/index.ts +20 -0
  106. package/src/formats/yml/items/parseGraphQLRequest.ts +137 -0
  107. package/src/formats/yml/items/parseGrpcRequest.ts +116 -0
  108. package/src/formats/yml/items/parseHttpRequest.ts +195 -0
  109. package/src/formats/yml/items/parseScript.ts +25 -0
  110. package/src/formats/yml/items/parseWebsocketRequest.ts +106 -0
  111. package/src/formats/yml/items/stringifyGraphQLRequest.ts +168 -0
  112. package/src/formats/yml/items/stringifyGrpcRequest.ts +137 -0
  113. package/src/formats/yml/items/stringifyHttpRequest.ts +221 -0
  114. package/src/formats/yml/items/stringifyScript.ts +22 -0
  115. package/src/formats/yml/items/stringifyWebsocketRequest.ts +114 -0
  116. package/src/formats/yml/parseCollection.ts +198 -0
  117. package/src/formats/yml/parseEnvironment.ts +56 -0
  118. package/src/formats/yml/parseFolder.ts +88 -0
  119. package/src/formats/yml/parseItem.ts +102 -0
  120. package/src/formats/yml/stringifyCollection.ts +230 -0
  121. package/src/formats/yml/stringifyEnvironment.ts +64 -0
  122. package/src/formats/yml/stringifyFolder.ts +96 -0
  123. package/src/formats/yml/stringifyItem.ts +37 -0
  124. package/src/formats/yml/utils.ts +38 -0
  125. package/src/index.ts +57 -27
  126. package/src/types/bruno-lang.d.ts +1 -1
  127. package/src/types.ts +5 -124
  128. package/src/utils/index.ts +15 -0
  129. package/src/workers/WorkerQueue/index.ts +10 -10
  130. package/src/workers/index.ts +20 -20
  131. package/src/workers/worker-script.ts +20 -6
  132. package/dist/cjs/formats/bru/index.d.ts +0 -6
  133. package/dist/cjs/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
  134. package/dist/cjs/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
  135. package/dist/cjs/index.d.ts +0 -16
  136. package/dist/cjs/types.d.ts +0 -142
  137. package/dist/cjs/workers/WorkerQueue/index.d.ts +0 -26
  138. package/dist/cjs/workers/formats/bru/index.d.ts +0 -6
  139. package/dist/cjs/workers/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
  140. package/dist/cjs/workers/types.d.ts +0 -142
  141. package/dist/cjs/workers/worker-script.d.ts +0 -1
  142. package/dist/cjs/workers/workers/WorkerQueue/index.d.ts +0 -26
  143. package/dist/cjs/workers/workers/index.d.ts +0 -10
  144. package/dist/cjs/workers/workers/worker-script.d.ts +0 -1
  145. package/dist/esm/formats/bru/index.d.ts +0 -6
  146. package/dist/esm/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
  147. package/dist/esm/index.d.ts +0 -16
  148. package/dist/esm/types.d.ts +0 -142
  149. package/dist/esm/workers/formats/bru/index.d.ts +0 -6
  150. package/dist/esm/workers/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
  151. package/dist/esm/workers/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
  152. package/dist/esm/workers/index.d.ts +0 -16
  153. package/dist/esm/workers/types.d.ts +0 -142
  154. package/dist/esm/workers/worker-script.d.ts +0 -1
  155. package/dist/esm/workers/workers/WorkerQueue/index.d.ts +0 -26
  156. package/dist/esm/workers/workers/index.d.ts +0 -10
  157. package/dist/esm/workers/workers/worker-script.d.ts +0 -1
@@ -0,0 +1,245 @@
1
+ import type {
2
+ Auth,
3
+ AuthApiKey,
4
+ AuthAwsV4,
5
+ AuthBasic,
6
+ AuthBearer,
7
+ AuthDigest,
8
+ AuthNTLM,
9
+ AuthWsse
10
+ } from '@opencollection/types/common/auth';
11
+ import type { Auth as BrunoAuth } from '@usebruno/schema-types/common/auth';
12
+ import { isString } from '../../../utils';
13
+ import { toOpenCollectionOAuth2, toBrunoOAuth2 } from './auth-oauth2';
14
+
15
+ const buildAwsV4Auth = (config?: BrunoAuth['awsv4']): AuthAwsV4 => {
16
+ const auth: AuthAwsV4 = { type: 'awsv4' };
17
+
18
+ if (!config) {
19
+ return auth;
20
+ }
21
+
22
+ if (isString(config.accessKeyId)) auth.accessKeyId = config.accessKeyId;
23
+ if (isString(config.secretAccessKey)) auth.secretAccessKey = config.secretAccessKey;
24
+ if (isString(config.sessionToken)) auth.sessionToken = config.sessionToken;
25
+ if (isString(config.service)) auth.service = config.service;
26
+ if (isString(config.region)) auth.region = config.region;
27
+ if (isString(config.profileName)) auth.profileName = config.profileName;
28
+
29
+ return auth;
30
+ };
31
+
32
+ const buildBasicAuth = (config?: BrunoAuth['basic']): AuthBasic => {
33
+ const auth: AuthBasic = { type: 'basic' };
34
+
35
+ if (!config) {
36
+ return auth;
37
+ }
38
+
39
+ if (isString(config.username)) auth.username = config.username;
40
+ if (isString(config.password)) auth.password = config.password;
41
+
42
+ return auth;
43
+ };
44
+
45
+ const buildBearerAuth = (config?: BrunoAuth['bearer']): AuthBearer => {
46
+ const auth: AuthBearer = { type: 'bearer' };
47
+
48
+ if (!config) {
49
+ return auth;
50
+ }
51
+
52
+ if (isString(config.token)) auth.token = config.token;
53
+
54
+ return auth;
55
+ };
56
+
57
+ const buildDigestAuth = (config?: BrunoAuth['digest']): AuthDigest => {
58
+ const auth: AuthDigest = { type: 'digest' };
59
+
60
+ if (!config) {
61
+ return auth;
62
+ }
63
+
64
+ if (isString(config.username)) auth.username = config.username;
65
+ if (isString(config.password)) auth.password = config.password;
66
+
67
+ return auth;
68
+ };
69
+
70
+ const buildNtlmAuth = (config?: BrunoAuth['ntlm']): AuthNTLM => {
71
+ const auth: AuthNTLM = { type: 'ntlm' };
72
+
73
+ if (!config) {
74
+ return auth;
75
+ }
76
+
77
+ if (isString(config.username)) auth.username = config.username;
78
+ if (isString(config.password)) auth.password = config.password;
79
+ if (isString(config.domain)) auth.domain = config.domain;
80
+
81
+ return auth;
82
+ };
83
+
84
+ const buildWsseAuth = (config?: BrunoAuth['wsse']): AuthWsse => {
85
+ const auth: AuthWsse = { type: 'wsse' };
86
+
87
+ if (!config) {
88
+ return auth;
89
+ }
90
+
91
+ if (isString(config.username)) auth.username = config.username;
92
+ if (isString(config.password)) auth.password = config.password;
93
+
94
+ return auth;
95
+ };
96
+
97
+ const buildApiKeyAuth = (config?: BrunoAuth['apikey']): AuthApiKey => {
98
+ const auth: AuthApiKey = { type: 'apikey' };
99
+
100
+ if (!config) {
101
+ return auth;
102
+ }
103
+
104
+ if (isString(config.key)) auth.key = config.key;
105
+ if (isString(config.value)) auth.value = config.value;
106
+
107
+ if (isString(config.placement)) {
108
+ if (config.placement === 'header') {
109
+ auth.placement = 'header';
110
+ } else if (config.placement === 'queryparams') {
111
+ auth.placement = 'query';
112
+ }
113
+ }
114
+
115
+ return auth;
116
+ };
117
+
118
+ export const toOpenCollectionAuth = (auth?: BrunoAuth | null): Auth | undefined => {
119
+ if (!auth || auth.mode === 'none') {
120
+ return undefined;
121
+ }
122
+
123
+ if (auth.mode === 'inherit') {
124
+ return 'inherit';
125
+ }
126
+
127
+ switch (auth.mode) {
128
+ case 'awsv4':
129
+ return buildAwsV4Auth(auth.awsv4);
130
+ case 'basic':
131
+ return buildBasicAuth(auth.basic);
132
+ case 'bearer':
133
+ return buildBearerAuth(auth.bearer);
134
+ case 'digest':
135
+ return buildDigestAuth(auth.digest);
136
+ case 'ntlm':
137
+ return buildNtlmAuth(auth.ntlm);
138
+ case 'wsse':
139
+ return buildWsseAuth(auth.wsse);
140
+ case 'apikey':
141
+ return buildApiKeyAuth(auth.apikey);
142
+ case 'oauth2':
143
+ return toOpenCollectionOAuth2(auth.oauth2);
144
+ default:
145
+ console.warn(`toOpenCollectionAuth failed: Unsupported auth mode "${auth.mode}".`);
146
+ return undefined;
147
+ }
148
+ };
149
+
150
+ export const toBrunoAuth = (auth: Auth | null | undefined): BrunoAuth | null => {
151
+ const brunoAuth: BrunoAuth = {
152
+ mode: 'none',
153
+ awsv4: null,
154
+ basic: null,
155
+ bearer: null,
156
+ digest: null,
157
+ ntlm: null,
158
+ oauth2: null,
159
+ wsse: null,
160
+ apikey: null
161
+ };
162
+
163
+ if (!auth) {
164
+ return brunoAuth;
165
+ }
166
+
167
+ if (auth === 'inherit') {
168
+ brunoAuth.mode = 'inherit';
169
+ return brunoAuth;
170
+ }
171
+
172
+ switch (auth.type) {
173
+ case 'awsv4':
174
+ brunoAuth.mode = 'awsv4';
175
+ brunoAuth.awsv4 = {
176
+ accessKeyId: auth.accessKeyId || null,
177
+ secretAccessKey: auth.secretAccessKey || null,
178
+ sessionToken: auth.sessionToken || null,
179
+ service: auth.service || null,
180
+ region: auth.region || null,
181
+ profileName: auth.profileName || null
182
+ };
183
+ break;
184
+
185
+ case 'basic':
186
+ brunoAuth.mode = 'basic';
187
+ brunoAuth.basic = {
188
+ username: auth.username || null,
189
+ password: auth.password || null
190
+ };
191
+ break;
192
+
193
+ case 'bearer':
194
+ brunoAuth.mode = 'bearer';
195
+ brunoAuth.bearer = {
196
+ token: auth.token || ''
197
+ };
198
+ break;
199
+
200
+ case 'digest':
201
+ brunoAuth.mode = 'digest';
202
+ brunoAuth.digest = {
203
+ username: auth.username || null,
204
+ password: auth.password || null
205
+ };
206
+ break;
207
+
208
+ case 'ntlm':
209
+ brunoAuth.mode = 'ntlm';
210
+ brunoAuth.ntlm = {
211
+ username: auth.username || null,
212
+ password: auth.password || null,
213
+ domain: auth.domain || null
214
+ };
215
+ break;
216
+
217
+ case 'wsse':
218
+ brunoAuth.mode = 'wsse';
219
+ brunoAuth.wsse = {
220
+ username: auth.username || null,
221
+ password: auth.password || null
222
+ };
223
+ break;
224
+
225
+ case 'apikey':
226
+ brunoAuth.mode = 'apikey';
227
+ brunoAuth.apikey = {
228
+ key: auth.key || null,
229
+ value: auth.value || null,
230
+ placement: auth.placement === 'query' ? 'queryparams' : (auth.placement === 'header' ? 'header' : null)
231
+ };
232
+ break;
233
+
234
+ case 'oauth2':
235
+ brunoAuth.mode = 'oauth2';
236
+ brunoAuth.oauth2 = toBrunoOAuth2(auth);
237
+ break;
238
+
239
+ default:
240
+ console.warn('toBrunoAuth failed: Unsupported auth type');
241
+ break;
242
+ }
243
+
244
+ return brunoAuth;
245
+ };
@@ -0,0 +1,238 @@
1
+ import type { HttpRequestBody as BrunoHttpRequestBody } from '@usebruno/schema-types/requests/http';
2
+ import type {
3
+ HttpRequestBody,
4
+ RawBody,
5
+ FormUrlEncodedBody,
6
+ FormUrlEncodedEntry,
7
+ MultipartFormBody,
8
+ MultipartFormEntry,
9
+ FileBody,
10
+ FileBodyEntry
11
+ } from '@opencollection/types/requests/http';
12
+ import type { KeyValue as BrunoKeyValue } from '@usebruno/schema-types/common/key-value';
13
+ import { uuid } from '../../../utils';
14
+
15
+ export const toOpenCollectionBody = (body: BrunoHttpRequestBody | null | undefined): HttpRequestBody | undefined => {
16
+ if (!body) {
17
+ return undefined;
18
+ }
19
+
20
+ switch (body.mode) {
21
+ case 'none':
22
+ return undefined;
23
+
24
+ case 'json':
25
+ const rawBody: RawBody = {
26
+ type: 'json',
27
+ data: body.json || ''
28
+ };
29
+ return rawBody;
30
+
31
+ case 'text':
32
+ const textBody: RawBody = {
33
+ type: 'text',
34
+ data: body.text || ''
35
+ };
36
+ return textBody;
37
+
38
+ case 'xml':
39
+ const xmlBody: RawBody = {
40
+ type: 'xml',
41
+ data: body.xml || ''
42
+ };
43
+ return xmlBody;
44
+
45
+ case 'sparql':
46
+ const sparqlBody: RawBody = {
47
+ type: 'sparql',
48
+ data: body.sparql || ''
49
+ };
50
+ return sparqlBody;
51
+
52
+ case 'formUrlEncoded':
53
+ const formEntries: FormUrlEncodedEntry[] = body.formUrlEncoded?.map((entry: BrunoKeyValue): FormUrlEncodedEntry => {
54
+ const formEntry: FormUrlEncodedEntry = {
55
+ name: entry.name || '',
56
+ value: entry.value || ''
57
+ };
58
+
59
+ if (entry?.description?.trim().length) {
60
+ formEntry.description = entry.description;
61
+ }
62
+
63
+ if (entry.enabled === false) {
64
+ formEntry.disabled = true;
65
+ }
66
+
67
+ return formEntry;
68
+ }) || [];
69
+
70
+ const formBody: FormUrlEncodedBody = {
71
+ type: 'form-urlencoded',
72
+ ...(formEntries.length > 0 && { data: formEntries })
73
+ } as FormUrlEncodedBody;
74
+ return formBody;
75
+
76
+ case 'multipartForm':
77
+ const multipartEntries: MultipartFormEntry[] = body.multipartForm?.map((entry): MultipartFormEntry => {
78
+ const multipartEntry: MultipartFormEntry = {
79
+ name: entry.name || '',
80
+ type: entry.type,
81
+ value: entry.value || (entry.type === 'file' ? [] : '')
82
+ };
83
+
84
+ if (entry?.contentType?.trim().length) {
85
+ multipartEntry.contentType = entry.contentType;
86
+ }
87
+
88
+ if (entry?.description?.trim().length) {
89
+ multipartEntry.description = entry.description;
90
+ }
91
+
92
+ if (entry.enabled === false) {
93
+ multipartEntry.disabled = true;
94
+ }
95
+
96
+ return multipartEntry;
97
+ }) || [];
98
+
99
+ const multipartBody: MultipartFormBody = {
100
+ type: 'multipart-form',
101
+ ...(multipartEntries.length > 0 && { data: multipartEntries })
102
+ } as MultipartFormBody;
103
+ return multipartBody;
104
+
105
+ case 'file':
106
+ const fileEntries: FileBodyEntry[] = body.file?.map((file): FileBodyEntry => {
107
+ return {
108
+ filePath: file.filePath || '',
109
+ contentType: file.contentType || '',
110
+ selected: file.selected ?? false
111
+ };
112
+ }) || [];
113
+
114
+ const fileBody: FileBody = {
115
+ type: 'file',
116
+ ...(fileEntries.length > 0 && { data: fileEntries })
117
+ } as FileBody;
118
+ return fileBody;
119
+
120
+ case 'graphql':
121
+ // GraphQL body is handled separately in GraphQL request stringify
122
+ return undefined;
123
+
124
+ default:
125
+ return undefined;
126
+ }
127
+ };
128
+
129
+ export const toBrunoBody = (body: HttpRequestBody | null | undefined): BrunoHttpRequestBody | undefined => {
130
+ if (!body) {
131
+ return {
132
+ mode: 'none',
133
+ json: null,
134
+ text: null,
135
+ xml: null,
136
+ sparql: null,
137
+ formUrlEncoded: [],
138
+ multipartForm: [],
139
+ graphql: null,
140
+ file: []
141
+ };
142
+ }
143
+
144
+ const brunoBody: BrunoHttpRequestBody = {
145
+ mode: 'none',
146
+ json: null,
147
+ text: null,
148
+ xml: null,
149
+ sparql: null,
150
+ formUrlEncoded: [],
151
+ multipartForm: [],
152
+ graphql: null,
153
+ file: []
154
+ };
155
+
156
+ switch (body.type) {
157
+ case 'json':
158
+ brunoBody.mode = 'json';
159
+ brunoBody.json = body.data || '';
160
+ break;
161
+
162
+ case 'text':
163
+ brunoBody.mode = 'text';
164
+ brunoBody.text = body.data || '';
165
+ break;
166
+
167
+ case 'xml':
168
+ brunoBody.mode = 'xml';
169
+ brunoBody.xml = body.data || '';
170
+ break;
171
+
172
+ case 'sparql':
173
+ brunoBody.mode = 'sparql';
174
+ brunoBody.sparql = body.data || '';
175
+ break;
176
+
177
+ case 'form-urlencoded':
178
+ brunoBody.mode = 'formUrlEncoded';
179
+ brunoBody.formUrlEncoded = body.data?.map((entry): BrunoKeyValue => {
180
+ const formEntry: BrunoKeyValue = {
181
+ uid: uuid(),
182
+ name: entry.name || '',
183
+ value: entry.value || '',
184
+ enabled: entry.disabled !== true
185
+ };
186
+
187
+ if (entry.description) {
188
+ if (typeof entry.description === 'string' && entry.description.trim().length) {
189
+ formEntry.description = entry.description;
190
+ } else if (typeof entry.description === 'object' && entry.description.content?.trim().length) {
191
+ formEntry.description = entry.description.content;
192
+ }
193
+ }
194
+
195
+ return formEntry;
196
+ }) || [];
197
+ break;
198
+
199
+ case 'multipart-form':
200
+ brunoBody.mode = 'multipartForm';
201
+ brunoBody.multipartForm = body.data?.map((entry): any => {
202
+ const multipartEntry: any = {
203
+ uid: uuid(),
204
+ type: entry.type,
205
+ name: entry.name || '',
206
+ value: entry.value || (entry.type === 'file' ? [] : ''),
207
+ contentType: entry.contentType || null,
208
+ enabled: entry.disabled !== true
209
+ };
210
+
211
+ if (entry.description) {
212
+ if (typeof entry.description === 'string' && entry.description.trim().length) {
213
+ multipartEntry.description = entry.description;
214
+ } else if (typeof entry.description === 'object' && entry.description.content?.trim().length) {
215
+ multipartEntry.description = entry.description.content;
216
+ }
217
+ }
218
+
219
+ return multipartEntry;
220
+ }) || [];
221
+ break;
222
+
223
+ case 'file':
224
+ brunoBody.mode = 'file';
225
+ brunoBody.file = body.data?.map((file): any => ({
226
+ uid: uuid(),
227
+ filePath: file.filePath || '',
228
+ contentType: file.contentType || '',
229
+ selected: file.selected ?? false
230
+ })) || [];
231
+ break;
232
+
233
+ default:
234
+ break;
235
+ }
236
+
237
+ return brunoBody;
238
+ };
@@ -0,0 +1,58 @@
1
+ import type { FolderRequest as BrunoFolderRequest } from '@usebruno/schema-types/collection/folder';
2
+ import type { KeyValue as BrunoKeyValue } from '@usebruno/schema-types/common/key-value';
3
+ import type { HttpRequestHeader, HttpResponseHeader } from '@opencollection/types/requests/http';
4
+ import { uuid } from '../../../utils';
5
+
6
+ export const toOpenCollectionHttpHeaders = (headers: BrunoFolderRequest['headers']): HttpRequestHeader[] | undefined => {
7
+ if (!headers?.length) {
8
+ return undefined;
9
+ }
10
+
11
+ const ocHeaders = headers.map((header: BrunoKeyValue): HttpRequestHeader => {
12
+ const httpHeader: HttpRequestHeader = {
13
+ name: header.name || '',
14
+ value: header.value || ''
15
+ };
16
+ if (header?.description?.trim().length) {
17
+ httpHeader.description = header.description;
18
+ }
19
+ if (header.enabled === false) {
20
+ httpHeader.disabled = true;
21
+ }
22
+ return httpHeader;
23
+ });
24
+
25
+ return ocHeaders.length ? ocHeaders : undefined;
26
+ };
27
+
28
+ export const toOpenCollectionResponseHeaders = (headers: BrunoFolderRequest['headers']): HttpResponseHeader[] | undefined => {
29
+ if (!headers?.length) {
30
+ return undefined;
31
+ }
32
+
33
+ const ocHeaders = headers.map((header: BrunoKeyValue): HttpResponseHeader => ({
34
+ name: header.name || '',
35
+ value: header.value || ''
36
+ }));
37
+
38
+ return ocHeaders.length ? ocHeaders : undefined;
39
+ };
40
+
41
+ export const toBrunoHttpHeaders = (headers: HttpRequestHeader[] | HttpResponseHeader[] | null | undefined): BrunoKeyValue[] | undefined => {
42
+ if (!headers?.length) {
43
+ return undefined;
44
+ }
45
+
46
+ const brunoHeaders = headers.map((header): BrunoKeyValue => {
47
+ const brunoHeader: BrunoKeyValue = {
48
+ uid: uuid(),
49
+ name: header.name || '',
50
+ value: header.value || '',
51
+ enabled: ('disabled' in header) ? header.disabled !== true : true
52
+ };
53
+
54
+ return brunoHeader;
55
+ });
56
+
57
+ return brunoHeaders.length ? brunoHeaders : undefined;
58
+ };
@@ -0,0 +1,57 @@
1
+ import type { HttpRequestParam as BrunoHttpRequestParam } from '@usebruno/schema-types/requests/http';
2
+ import type { HttpRequestParam } from '@opencollection/types/requests/http';
3
+ import { uuid } from '../../../utils';
4
+
5
+ export const toOpenCollectionParams = (params: BrunoHttpRequestParam[] | null | undefined): HttpRequestParam[] | undefined => {
6
+ if (!params?.length) {
7
+ return undefined;
8
+ }
9
+
10
+ const ocParams = params.map((param: BrunoHttpRequestParam): HttpRequestParam => {
11
+ const ocParam: HttpRequestParam = {
12
+ name: param.name || '',
13
+ value: param.value || '',
14
+ type: param.type
15
+ };
16
+
17
+ if (param?.description?.trim().length) {
18
+ ocParam.description = param.description;
19
+ }
20
+
21
+ if (param.enabled === false) {
22
+ ocParam.disabled = true;
23
+ }
24
+
25
+ return ocParam;
26
+ });
27
+
28
+ return ocParams.length ? ocParams : undefined;
29
+ };
30
+
31
+ export const toBrunoParams = (params: HttpRequestParam[] | null | undefined): BrunoHttpRequestParam[] | undefined => {
32
+ if (!params?.length) {
33
+ return undefined;
34
+ }
35
+
36
+ const brunoParams = params.map((param: HttpRequestParam): BrunoHttpRequestParam => {
37
+ const brunoParam: BrunoHttpRequestParam = {
38
+ uid: uuid(),
39
+ name: param.name || '',
40
+ value: param.value || '',
41
+ type: param.type,
42
+ enabled: param.disabled !== true
43
+ };
44
+
45
+ if (param.description) {
46
+ if (typeof param.description === 'string' && param.description.trim().length) {
47
+ brunoParam.description = param.description;
48
+ } else if (typeof param.description === 'object' && param.description.content?.trim().length) {
49
+ brunoParam.description = param.description.content;
50
+ }
51
+ }
52
+
53
+ return brunoParam;
54
+ });
55
+
56
+ return brunoParams.length ? brunoParams : undefined;
57
+ };
@@ -0,0 +1,64 @@
1
+ import type { Scripts, Script } from '@opencollection/types/common/scripts';
2
+ import type { FolderRequest as BrunoFolderRequest } from '@usebruno/schema-types/collection/folder';
3
+ import type { HttpRequest as BrunoHttpRequest } from '@usebruno/schema-types/requests/http';
4
+ import type { WebSocketRequest as BrunoWebSocketRequest } from '@usebruno/schema-types/requests/websocket';
5
+ import type { GrpcRequest as BrunoGrpcRequest } from '@usebruno/schema-types/requests/grpc';
6
+
7
+ export const toOpenCollectionScripts = (request: BrunoFolderRequest | BrunoHttpRequest | BrunoWebSocketRequest | BrunoGrpcRequest | null | undefined): Scripts | undefined => {
8
+ const ocScripts: Scripts = [];
9
+
10
+ if (request?.script?.req?.trim().length) {
11
+ ocScripts.push({
12
+ type: 'before-request',
13
+ code: request.script.req.trim()
14
+ });
15
+ }
16
+ if (request?.script?.res?.trim().length) {
17
+ ocScripts.push({
18
+ type: 'after-response',
19
+ code: request.script.res.trim()
20
+ });
21
+ }
22
+ if (request?.tests?.trim().length) {
23
+ ocScripts.push({
24
+ type: 'tests',
25
+ code: request.tests.trim()
26
+ });
27
+ }
28
+
29
+ return ocScripts.length > 0 ? ocScripts : undefined;
30
+ };
31
+
32
+ export const toBrunoScripts = (scripts: Scripts | null | undefined): {
33
+ script?: { req?: string; res?: string };
34
+ tests?: string;
35
+ } | undefined => {
36
+ if (!scripts || !Array.isArray(scripts) || scripts.length === 0) {
37
+ return undefined;
38
+ }
39
+
40
+ const brunoScripts: {
41
+ script?: { req?: string; res?: string };
42
+ tests?: string;
43
+ } = {};
44
+
45
+ for (const script of scripts) {
46
+ if (script.type === 'before-request' && script.code) {
47
+ if (!brunoScripts.script) {
48
+ brunoScripts.script = {};
49
+ }
50
+ brunoScripts.script.req = script.code;
51
+ }
52
+ if (script.type === 'after-response' && script.code) {
53
+ if (!brunoScripts.script) {
54
+ brunoScripts.script = {};
55
+ }
56
+ brunoScripts.script.res = script.code;
57
+ }
58
+ if (script.type === 'tests' && script.code) {
59
+ brunoScripts.tests = script.code;
60
+ }
61
+ }
62
+
63
+ return Object.keys(brunoScripts).length > 0 ? brunoScripts : undefined;
64
+ };