@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.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/workers/worker-script.js +1 -1
- package/dist/cjs/workers/worker-script.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/workers/worker-script.js +1 -1
- package/dist/esm/workers/worker-script.js.map +1 -1
- package/dist/formats/bru/index.d.ts +20 -0
- package/dist/formats/bru/index.d.ts.map +1 -0
- package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts +57 -0
- package/dist/formats/bru/tests/fixtures/oauth2-additional-params.d.ts.map +1 -0
- package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts +2 -0
- package/dist/formats/bru/tests/oauth2-additional-params.spec.d.ts.map +1 -0
- package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts +2 -0
- package/dist/formats/bru/tests/request-parse-and-redact-body-data.spec.d.ts.map +1 -0
- package/dist/{esm/formats → formats}/bru/utils/oauth2-additional-params.d.ts +1 -0
- package/dist/formats/bru/utils/oauth2-additional-params.d.ts.map +1 -0
- package/dist/{cjs/workers/formats → formats}/bru/utils/request-parse-and-redact-body-data.d.ts +1 -0
- package/dist/formats/bru/utils/request-parse-and-redact-body-data.d.ts.map +1 -0
- package/dist/formats/yml/common/actions.d.ts +14 -0
- package/dist/formats/yml/common/actions.d.ts.map +1 -0
- package/dist/formats/yml/common/assertions.d.ts +5 -0
- package/dist/formats/yml/common/assertions.d.ts.map +1 -0
- package/dist/formats/yml/common/auth-oauth2.d.ts +5 -0
- package/dist/formats/yml/common/auth-oauth2.d.ts.map +1 -0
- package/dist/formats/yml/common/auth.d.ts +5 -0
- package/dist/formats/yml/common/auth.d.ts.map +1 -0
- package/dist/formats/yml/common/body.d.ts +5 -0
- package/dist/formats/yml/common/body.d.ts.map +1 -0
- package/dist/formats/yml/common/headers.d.ts +7 -0
- package/dist/formats/yml/common/headers.d.ts.map +1 -0
- package/dist/formats/yml/common/params.d.ts +5 -0
- package/dist/formats/yml/common/params.d.ts.map +1 -0
- package/dist/formats/yml/common/scripts.d.ts +14 -0
- package/dist/formats/yml/common/scripts.d.ts.map +1 -0
- package/dist/formats/yml/common/variables.d.ts +17 -0
- package/dist/formats/yml/common/variables.d.ts.map +1 -0
- package/dist/formats/yml/index.d.ts +10 -0
- package/dist/formats/yml/index.d.ts.map +1 -0
- package/dist/formats/yml/items/parseGraphQLRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseGraphQLRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/parseGrpcRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseGrpcRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/parseHttpRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseHttpRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/parseScript.d.ts +5 -0
- package/dist/formats/yml/items/parseScript.d.ts.map +1 -0
- package/dist/formats/yml/items/parseWebsocketRequest.d.ts +5 -0
- package/dist/formats/yml/items/parseWebsocketRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyGraphQLRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyGrpcRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyGrpcRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyHttpRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyHttpRequest.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyScript.d.ts +4 -0
- package/dist/formats/yml/items/stringifyScript.d.ts.map +1 -0
- package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts +4 -0
- package/dist/formats/yml/items/stringifyWebsocketRequest.d.ts.map +1 -0
- package/dist/formats/yml/parseCollection.d.ts +8 -0
- package/dist/formats/yml/parseCollection.d.ts.map +1 -0
- package/dist/formats/yml/parseEnvironment.d.ts +4 -0
- package/dist/formats/yml/parseEnvironment.d.ts.map +1 -0
- package/dist/formats/yml/parseFolder.d.ts +4 -0
- package/dist/formats/yml/parseFolder.d.ts.map +1 -0
- package/dist/formats/yml/parseItem.d.ts +4 -0
- package/dist/formats/yml/parseItem.d.ts.map +1 -0
- package/dist/formats/yml/stringifyCollection.d.ts +3 -0
- package/dist/formats/yml/stringifyCollection.d.ts.map +1 -0
- package/dist/formats/yml/stringifyEnvironment.d.ts +4 -0
- package/dist/formats/yml/stringifyEnvironment.d.ts.map +1 -0
- package/dist/formats/yml/stringifyFolder.d.ts +4 -0
- package/dist/formats/yml/stringifyFolder.d.ts.map +1 -0
- package/dist/formats/yml/stringifyItem.d.ts +4 -0
- package/dist/formats/yml/stringifyItem.d.ts.map +1 -0
- package/dist/formats/yml/utils.d.ts +3 -0
- package/dist/formats/yml/utils.d.ts.map +1 -0
- package/dist/{cjs/workers/index.d.ts → index.d.ts} +13 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/{esm/workers → workers}/WorkerQueue/index.d.ts +1 -0
- package/dist/workers/WorkerQueue/index.d.ts.map +1 -0
- package/dist/workers/index.d.ts +12 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/worker-script.d.ts +2 -0
- package/dist/workers/worker-script.d.ts.map +1 -0
- package/package.json +12 -6
- package/src/formats/bru/index.ts +103 -11
- package/src/formats/bru/tests/oauth2-additional-params.spec.js +1 -1
- package/src/formats/bru/utils/oauth2-additional-params.ts +17 -18
- package/src/formats/bru/utils/request-parse-and-redact-body-data.ts +13 -13
- package/src/formats/yml/common/actions.ts +78 -0
- package/src/formats/yml/common/assertions.ts +146 -0
- package/src/formats/yml/common/auth-oauth2.ts +555 -0
- package/src/formats/yml/common/auth.ts +245 -0
- package/src/formats/yml/common/body.ts +238 -0
- package/src/formats/yml/common/headers.ts +58 -0
- package/src/formats/yml/common/params.ts +57 -0
- package/src/formats/yml/common/scripts.ts +64 -0
- package/src/formats/yml/common/variables.ts +68 -0
- package/src/formats/yml/index.ts +20 -0
- package/src/formats/yml/items/parseGraphQLRequest.ts +137 -0
- package/src/formats/yml/items/parseGrpcRequest.ts +116 -0
- package/src/formats/yml/items/parseHttpRequest.ts +195 -0
- package/src/formats/yml/items/parseScript.ts +25 -0
- package/src/formats/yml/items/parseWebsocketRequest.ts +106 -0
- package/src/formats/yml/items/stringifyGraphQLRequest.ts +168 -0
- package/src/formats/yml/items/stringifyGrpcRequest.ts +137 -0
- package/src/formats/yml/items/stringifyHttpRequest.ts +221 -0
- package/src/formats/yml/items/stringifyScript.ts +22 -0
- package/src/formats/yml/items/stringifyWebsocketRequest.ts +114 -0
- package/src/formats/yml/parseCollection.ts +198 -0
- package/src/formats/yml/parseEnvironment.ts +56 -0
- package/src/formats/yml/parseFolder.ts +88 -0
- package/src/formats/yml/parseItem.ts +102 -0
- package/src/formats/yml/stringifyCollection.ts +230 -0
- package/src/formats/yml/stringifyEnvironment.ts +64 -0
- package/src/formats/yml/stringifyFolder.ts +96 -0
- package/src/formats/yml/stringifyItem.ts +37 -0
- package/src/formats/yml/utils.ts +38 -0
- package/src/index.ts +57 -27
- package/src/types/bruno-lang.d.ts +1 -1
- package/src/types.ts +5 -124
- package/src/utils/index.ts +15 -0
- package/src/workers/WorkerQueue/index.ts +10 -10
- package/src/workers/index.ts +20 -20
- package/src/workers/worker-script.ts +20 -6
- package/dist/cjs/formats/bru/index.d.ts +0 -6
- package/dist/cjs/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
- package/dist/cjs/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
- package/dist/cjs/index.d.ts +0 -16
- package/dist/cjs/types.d.ts +0 -142
- package/dist/cjs/workers/WorkerQueue/index.d.ts +0 -26
- package/dist/cjs/workers/formats/bru/index.d.ts +0 -6
- package/dist/cjs/workers/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
- package/dist/cjs/workers/types.d.ts +0 -142
- package/dist/cjs/workers/worker-script.d.ts +0 -1
- package/dist/cjs/workers/workers/WorkerQueue/index.d.ts +0 -26
- package/dist/cjs/workers/workers/index.d.ts +0 -10
- package/dist/cjs/workers/workers/worker-script.d.ts +0 -1
- package/dist/esm/formats/bru/index.d.ts +0 -6
- package/dist/esm/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
- package/dist/esm/index.d.ts +0 -16
- package/dist/esm/types.d.ts +0 -142
- package/dist/esm/workers/formats/bru/index.d.ts +0 -6
- package/dist/esm/workers/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
- package/dist/esm/workers/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
- package/dist/esm/workers/index.d.ts +0 -16
- package/dist/esm/workers/types.d.ts +0 -142
- package/dist/esm/workers/worker-script.d.ts +0 -1
- package/dist/esm/workers/workers/WorkerQueue/index.d.ts +0 -26
- package/dist/esm/workers/workers/index.d.ts +0 -10
- package/dist/esm/workers/workers/worker-script.d.ts +0 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Variable } from '@opencollection/types/common/variables';
|
|
2
|
+
import { FolderRequest as BrunoFolderRequest } from '@usebruno/schema-types/collection/folder';
|
|
3
|
+
import { Variable as BrunoVariable, Variables as BrunoVariables } from '@usebruno/schema-types/common/variables';
|
|
4
|
+
import { uuid } from '../../../utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Convert Bruno pre-request variables to OpenCollection variables format.
|
|
8
|
+
* Note: Post-response variables are now converted to actions (see actions.ts).
|
|
9
|
+
*/
|
|
10
|
+
export const toOpenCollectionVariables = (variables: BrunoFolderRequest['vars'] | BrunoVariables | null | undefined): Variable[] | undefined => {
|
|
11
|
+
// Handle folder variables (has req/res structure) - only use req vars
|
|
12
|
+
const hasReqRes = variables && 'req' in variables;
|
|
13
|
+
const reqVars = hasReqRes ? variables.req : variables as BrunoVariables;
|
|
14
|
+
|
|
15
|
+
const reqVarsArray = Array.isArray(reqVars) ? reqVars : [];
|
|
16
|
+
|
|
17
|
+
if (!reqVarsArray.length) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ocVariables: Variable[] = reqVarsArray.map((v: BrunoVariable): Variable => {
|
|
22
|
+
const variable: Variable = {
|
|
23
|
+
name: v.name || '',
|
|
24
|
+
value: v.value || ''
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
if (v?.description?.trim().length) {
|
|
28
|
+
variable.description = v.description;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (v.enabled === false) {
|
|
32
|
+
variable.disabled = true;
|
|
33
|
+
}
|
|
34
|
+
return variable;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return ocVariables.length > 0 ? ocVariables : undefined;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Convert OpenCollection variables to Bruno pre-request variables format.
|
|
42
|
+
* Note: Post-response variables come from actions (see actions.ts).
|
|
43
|
+
*/
|
|
44
|
+
export const toBrunoVariables = (variables: Variable[] | null | undefined): { req: BrunoVariables; res: BrunoVariables } => {
|
|
45
|
+
if (!variables?.length) {
|
|
46
|
+
return { req: [], res: [] };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const reqVars: BrunoVariables = [];
|
|
50
|
+
|
|
51
|
+
variables.forEach((v: Variable) => {
|
|
52
|
+
const variable: BrunoVariable = {
|
|
53
|
+
uid: uuid(),
|
|
54
|
+
name: v.name || '',
|
|
55
|
+
value: v.value as string || '',
|
|
56
|
+
enabled: v.disabled !== true,
|
|
57
|
+
local: false
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (v.description) {
|
|
61
|
+
variable.description = typeof v.description === 'string' ? v.description : (v.description as any)?.content || '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
reqVars.push(variable);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return { req: reqVars, res: [] };
|
|
68
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import parseYmlItem from './parseItem';
|
|
2
|
+
import parseYmlFolder from './parseFolder';
|
|
3
|
+
import parseYmlCollection from './parseCollection';
|
|
4
|
+
import parseYmlEnvironment from './parseEnvironment';
|
|
5
|
+
|
|
6
|
+
import stringifyYmlItem from './stringifyItem';
|
|
7
|
+
import stringifyYmlFolder from './stringifyFolder';
|
|
8
|
+
import stringifyYmlCollection from './stringifyCollection';
|
|
9
|
+
import stringifyYmlEnvironment from './stringifyEnvironment';
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
parseYmlItem,
|
|
13
|
+
parseYmlFolder,
|
|
14
|
+
parseYmlCollection,
|
|
15
|
+
parseYmlEnvironment,
|
|
16
|
+
stringifyYmlItem,
|
|
17
|
+
stringifyYmlFolder,
|
|
18
|
+
stringifyYmlCollection,
|
|
19
|
+
stringifyYmlEnvironment
|
|
20
|
+
};
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Item as BrunoItem, HttpItemSettings as BrunoHttpItemSettings } from '@usebruno/schema-types/collection/item';
|
|
2
|
+
import type { HttpRequest as BrunoHttpRequest } from '@usebruno/schema-types/requests/http';
|
|
3
|
+
import type { GraphQLRequest, GraphQLRequestSettings, GraphQLBody } from '@opencollection/types/requests/graphql';
|
|
4
|
+
import { toBrunoAuth } from '../common/auth';
|
|
5
|
+
import { toBrunoHttpHeaders } from '../common/headers';
|
|
6
|
+
import { toBrunoParams } from '../common/params';
|
|
7
|
+
import { toBrunoVariables } from '../common/variables';
|
|
8
|
+
import { toBrunoPostResponseVariables } from '../common/actions';
|
|
9
|
+
import { toBrunoScripts } from '../common/scripts';
|
|
10
|
+
import { toBrunoAssertions } from '../common/assertions';
|
|
11
|
+
import { uuid } from '../../../utils';
|
|
12
|
+
|
|
13
|
+
const parseGraphQLRequest = (ocRequest: GraphQLRequest): BrunoItem => {
|
|
14
|
+
const info = ocRequest.info;
|
|
15
|
+
const graphql = ocRequest.graphql;
|
|
16
|
+
const runtime = ocRequest.runtime;
|
|
17
|
+
|
|
18
|
+
const brunoRequest: BrunoHttpRequest = {
|
|
19
|
+
url: graphql?.url || '',
|
|
20
|
+
method: graphql?.method || 'POST',
|
|
21
|
+
headers: toBrunoHttpHeaders(graphql?.headers) || [],
|
|
22
|
+
params: toBrunoParams(graphql?.params) || [],
|
|
23
|
+
auth: toBrunoAuth(graphql?.auth),
|
|
24
|
+
body: {
|
|
25
|
+
mode: 'graphql',
|
|
26
|
+
json: null,
|
|
27
|
+
text: null,
|
|
28
|
+
xml: null,
|
|
29
|
+
sparql: null,
|
|
30
|
+
formUrlEncoded: [],
|
|
31
|
+
multipartForm: [],
|
|
32
|
+
graphql: {
|
|
33
|
+
query: (graphql?.body as GraphQLBody)?.query || '',
|
|
34
|
+
variables: (graphql?.body as GraphQLBody)?.variables || ''
|
|
35
|
+
},
|
|
36
|
+
file: []
|
|
37
|
+
},
|
|
38
|
+
script: {
|
|
39
|
+
req: null,
|
|
40
|
+
res: null
|
|
41
|
+
},
|
|
42
|
+
vars: {
|
|
43
|
+
req: [],
|
|
44
|
+
res: []
|
|
45
|
+
},
|
|
46
|
+
assertions: [],
|
|
47
|
+
tests: null,
|
|
48
|
+
docs: null
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// scripts
|
|
52
|
+
const scripts = toBrunoScripts(runtime?.scripts);
|
|
53
|
+
if (scripts?.script && brunoRequest.script) {
|
|
54
|
+
if (scripts.script.req) {
|
|
55
|
+
brunoRequest.script.req = scripts.script.req;
|
|
56
|
+
}
|
|
57
|
+
if (scripts.script.res) {
|
|
58
|
+
brunoRequest.script.res = scripts.script.res;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (scripts?.tests) {
|
|
62
|
+
brunoRequest.tests = scripts.tests;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// variables (pre-request from variables, post-response from actions)
|
|
66
|
+
const variables = toBrunoVariables(runtime?.variables);
|
|
67
|
+
const postResponseVars = toBrunoPostResponseVariables(runtime?.actions);
|
|
68
|
+
brunoRequest.vars = {
|
|
69
|
+
req: variables.req,
|
|
70
|
+
res: postResponseVars
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// assertions
|
|
74
|
+
const assertions = toBrunoAssertions(runtime?.assertions);
|
|
75
|
+
if (assertions) {
|
|
76
|
+
brunoRequest.assertions = assertions;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// docs
|
|
80
|
+
if (ocRequest.docs) {
|
|
81
|
+
brunoRequest.docs = ocRequest.docs;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// bruno item
|
|
85
|
+
const brunoItem: BrunoItem = {
|
|
86
|
+
uid: uuid(),
|
|
87
|
+
type: 'graphql-request',
|
|
88
|
+
seq: info?.seq || 1,
|
|
89
|
+
name: info?.name || 'Untitled Request',
|
|
90
|
+
tags: info?.tags || [],
|
|
91
|
+
request: brunoRequest,
|
|
92
|
+
settings: null,
|
|
93
|
+
fileContent: null,
|
|
94
|
+
root: null,
|
|
95
|
+
items: [],
|
|
96
|
+
examples: [],
|
|
97
|
+
filename: null,
|
|
98
|
+
pathname: null
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// settings
|
|
102
|
+
if (ocRequest.settings) {
|
|
103
|
+
const settings: BrunoHttpItemSettings = {};
|
|
104
|
+
|
|
105
|
+
if (typeof ocRequest.settings.encodeUrl === 'boolean') {
|
|
106
|
+
settings.encodeUrl = ocRequest.settings.encodeUrl;
|
|
107
|
+
} else {
|
|
108
|
+
settings.encodeUrl = true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (typeof ocRequest.settings.timeout === 'number') {
|
|
112
|
+
settings.timeout = ocRequest.settings.timeout;
|
|
113
|
+
} else if (ocRequest.settings.timeout === 'inherit') {
|
|
114
|
+
settings.timeout = 'inherit';
|
|
115
|
+
} else {
|
|
116
|
+
settings.timeout = 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (typeof ocRequest.settings.followRedirects === 'boolean') {
|
|
120
|
+
settings.followRedirects = ocRequest.settings.followRedirects;
|
|
121
|
+
} else {
|
|
122
|
+
settings.followRedirects = true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (typeof ocRequest.settings.maxRedirects === 'number') {
|
|
126
|
+
settings.maxRedirects = ocRequest.settings.maxRedirects;
|
|
127
|
+
} else {
|
|
128
|
+
settings.maxRedirects = 5;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
brunoItem.settings = settings;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return brunoItem;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export default parseGraphQLRequest;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Item as BrunoItem } from '@usebruno/schema-types/collection/item';
|
|
2
|
+
import type { GrpcRequest as BrunoGrpcRequest } from '@usebruno/schema-types/requests/grpc';
|
|
3
|
+
import type { GrpcRequest, GrpcMetadata } from '@opencollection/types/requests/grpc';
|
|
4
|
+
import type { KeyValue as BrunoKeyValue } from '@usebruno/schema-types/common/key-value';
|
|
5
|
+
import { toBrunoAuth } from '../common/auth';
|
|
6
|
+
import { toBrunoVariables } from '../common/variables';
|
|
7
|
+
import { toBrunoScripts } from '../common/scripts';
|
|
8
|
+
import { toBrunoAssertions } from '../common/assertions';
|
|
9
|
+
import { isNonEmptyString, uuid } from '../../../utils';
|
|
10
|
+
|
|
11
|
+
const toBrunoGrpcMetadata = (metadata: GrpcMetadata[] | null | undefined): BrunoKeyValue[] | undefined => {
|
|
12
|
+
if (!metadata?.length) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const brunoMetadata = metadata.map((meta: GrpcMetadata): BrunoKeyValue => {
|
|
17
|
+
const brunoMeta: BrunoKeyValue = {
|
|
18
|
+
uid: uuid(),
|
|
19
|
+
name: meta.name || '',
|
|
20
|
+
value: meta.value || '',
|
|
21
|
+
enabled: meta.disabled !== true
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return brunoMeta;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return brunoMetadata.length ? brunoMetadata : undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const parseGrpcRequest = (ocRequest: GrpcRequest): BrunoItem => {
|
|
31
|
+
const info = ocRequest.info;
|
|
32
|
+
const grpc = ocRequest.grpc;
|
|
33
|
+
const runtime = ocRequest.runtime;
|
|
34
|
+
|
|
35
|
+
const brunoRequest: BrunoGrpcRequest = {
|
|
36
|
+
url: grpc?.url || '',
|
|
37
|
+
method: grpc?.method || '',
|
|
38
|
+
methodType: grpc?.methodType || '',
|
|
39
|
+
protoPath: grpc?.protoFilePath || null,
|
|
40
|
+
headers: toBrunoGrpcMetadata(grpc?.metadata) || [],
|
|
41
|
+
auth: toBrunoAuth(grpc?.auth),
|
|
42
|
+
body: {
|
|
43
|
+
mode: 'grpc',
|
|
44
|
+
grpc: []
|
|
45
|
+
},
|
|
46
|
+
script: {
|
|
47
|
+
req: null,
|
|
48
|
+
res: null
|
|
49
|
+
},
|
|
50
|
+
vars: {
|
|
51
|
+
req: [],
|
|
52
|
+
res: []
|
|
53
|
+
},
|
|
54
|
+
assertions: [],
|
|
55
|
+
tests: null,
|
|
56
|
+
docs: null
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// message
|
|
60
|
+
if (isNonEmptyString(grpc?.message)) {
|
|
61
|
+
brunoRequest.body.grpc = [{
|
|
62
|
+
name: '',
|
|
63
|
+
content: grpc?.message as string
|
|
64
|
+
}];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// scripts
|
|
68
|
+
const scripts = toBrunoScripts(runtime?.scripts);
|
|
69
|
+
if (scripts?.script && brunoRequest.script) {
|
|
70
|
+
if (scripts.script.req) {
|
|
71
|
+
brunoRequest.script.req = scripts.script.req;
|
|
72
|
+
}
|
|
73
|
+
if (scripts.script.res) {
|
|
74
|
+
brunoRequest.script.res = scripts.script.res;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (scripts?.tests) {
|
|
78
|
+
brunoRequest.tests = scripts.tests;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// variables
|
|
82
|
+
const variables = toBrunoVariables(runtime?.variables);
|
|
83
|
+
brunoRequest.vars = variables;
|
|
84
|
+
|
|
85
|
+
// assertions
|
|
86
|
+
const assertions = toBrunoAssertions(runtime?.assertions);
|
|
87
|
+
if (assertions) {
|
|
88
|
+
brunoRequest.assertions = assertions;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// docs
|
|
92
|
+
if (ocRequest.docs) {
|
|
93
|
+
brunoRequest.docs = ocRequest.docs;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// bruno item
|
|
97
|
+
const brunoItem: BrunoItem = {
|
|
98
|
+
uid: uuid(),
|
|
99
|
+
type: 'grpc-request',
|
|
100
|
+
seq: info?.seq || 1,
|
|
101
|
+
name: info?.name || 'Untitled Request',
|
|
102
|
+
tags: info?.tags || [],
|
|
103
|
+
request: brunoRequest,
|
|
104
|
+
settings: {},
|
|
105
|
+
fileContent: null,
|
|
106
|
+
root: null,
|
|
107
|
+
items: [],
|
|
108
|
+
examples: [],
|
|
109
|
+
filename: null,
|
|
110
|
+
pathname: null
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return brunoItem;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default parseGrpcRequest;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { Item as BrunoItem, HttpItemSettings as BrunoHttpItemSettings } from '@usebruno/schema-types/collection/item';
|
|
2
|
+
import type { HttpRequest as BrunoHttpRequest } from '@usebruno/schema-types/requests/http';
|
|
3
|
+
import type { HttpRequest, HttpRequestBody } from '@opencollection/types/requests/http';
|
|
4
|
+
import { toBrunoAuth } from '../common/auth';
|
|
5
|
+
import { toBrunoHttpHeaders } from '../common/headers';
|
|
6
|
+
import { toBrunoParams } from '../common/params';
|
|
7
|
+
import { toBrunoBody } from '../common/body';
|
|
8
|
+
import { toBrunoVariables } from '../common/variables';
|
|
9
|
+
import { toBrunoPostResponseVariables } from '../common/actions';
|
|
10
|
+
import { toBrunoScripts } from '../common/scripts';
|
|
11
|
+
import { toBrunoAssertions } from '../common/assertions';
|
|
12
|
+
import { uuid } from '../../../utils';
|
|
13
|
+
|
|
14
|
+
const parseHttpRequest = (ocRequest: HttpRequest): BrunoItem => {
|
|
15
|
+
const info = ocRequest.info;
|
|
16
|
+
const http = ocRequest.http;
|
|
17
|
+
const runtime = ocRequest.runtime;
|
|
18
|
+
|
|
19
|
+
const brunoRequest: BrunoHttpRequest = {
|
|
20
|
+
url: http?.url || '',
|
|
21
|
+
method: http?.method || 'GET',
|
|
22
|
+
headers: toBrunoHttpHeaders(http?.headers) || [],
|
|
23
|
+
params: toBrunoParams(http?.params) || [],
|
|
24
|
+
auth: toBrunoAuth(http?.auth),
|
|
25
|
+
body: toBrunoBody(http?.body as HttpRequestBody) || {
|
|
26
|
+
mode: 'none',
|
|
27
|
+
json: null,
|
|
28
|
+
text: null,
|
|
29
|
+
xml: null,
|
|
30
|
+
sparql: null,
|
|
31
|
+
formUrlEncoded: [],
|
|
32
|
+
multipartForm: [],
|
|
33
|
+
graphql: null,
|
|
34
|
+
file: []
|
|
35
|
+
},
|
|
36
|
+
script: {
|
|
37
|
+
req: null,
|
|
38
|
+
res: null
|
|
39
|
+
},
|
|
40
|
+
vars: {
|
|
41
|
+
req: [],
|
|
42
|
+
res: []
|
|
43
|
+
},
|
|
44
|
+
assertions: [],
|
|
45
|
+
tests: null,
|
|
46
|
+
docs: null
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// scripts
|
|
50
|
+
const scripts = toBrunoScripts(runtime?.scripts);
|
|
51
|
+
if (scripts?.script && brunoRequest.script) {
|
|
52
|
+
if (scripts.script.req) {
|
|
53
|
+
brunoRequest.script.req = scripts.script.req;
|
|
54
|
+
}
|
|
55
|
+
if (scripts.script.res) {
|
|
56
|
+
brunoRequest.script.res = scripts.script.res;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (scripts?.tests) {
|
|
60
|
+
brunoRequest.tests = scripts.tests;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// variables (pre-request from variables, post-response from actions)
|
|
64
|
+
const variables = toBrunoVariables(runtime?.variables);
|
|
65
|
+
const postResponseVars = toBrunoPostResponseVariables(runtime?.actions);
|
|
66
|
+
brunoRequest.vars = {
|
|
67
|
+
req: variables.req,
|
|
68
|
+
res: postResponseVars
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// assertions
|
|
72
|
+
const assertions = toBrunoAssertions(runtime?.assertions);
|
|
73
|
+
if (assertions) {
|
|
74
|
+
brunoRequest.assertions = assertions;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// docs
|
|
78
|
+
if (ocRequest.docs) {
|
|
79
|
+
brunoRequest.docs = ocRequest.docs;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// bruno item
|
|
83
|
+
const brunoItem: BrunoItem = {
|
|
84
|
+
uid: uuid(),
|
|
85
|
+
type: 'http-request',
|
|
86
|
+
seq: info?.seq || 1,
|
|
87
|
+
name: info?.name || 'Untitled Request',
|
|
88
|
+
tags: info?.tags || [],
|
|
89
|
+
request: brunoRequest,
|
|
90
|
+
settings: null,
|
|
91
|
+
fileContent: null,
|
|
92
|
+
root: null,
|
|
93
|
+
items: [],
|
|
94
|
+
examples: [],
|
|
95
|
+
filename: null,
|
|
96
|
+
pathname: null
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// settings
|
|
100
|
+
if (ocRequest.settings) {
|
|
101
|
+
const settings: BrunoHttpItemSettings = {};
|
|
102
|
+
|
|
103
|
+
if (typeof ocRequest.settings.encodeUrl === 'boolean') {
|
|
104
|
+
settings.encodeUrl = ocRequest.settings.encodeUrl;
|
|
105
|
+
} else {
|
|
106
|
+
settings.encodeUrl = true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (typeof ocRequest.settings.timeout === 'number') {
|
|
110
|
+
settings.timeout = ocRequest.settings.timeout;
|
|
111
|
+
} else if (ocRequest.settings.timeout === 'inherit') {
|
|
112
|
+
settings.timeout = 'inherit';
|
|
113
|
+
} else {
|
|
114
|
+
settings.timeout = 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (typeof ocRequest.settings.followRedirects === 'boolean') {
|
|
118
|
+
settings.followRedirects = ocRequest.settings.followRedirects;
|
|
119
|
+
} else {
|
|
120
|
+
settings.followRedirects = true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (typeof ocRequest.settings.maxRedirects === 'number') {
|
|
124
|
+
settings.maxRedirects = ocRequest.settings.maxRedirects;
|
|
125
|
+
} else {
|
|
126
|
+
settings.maxRedirects = 5;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
brunoItem.settings = settings;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// examples
|
|
133
|
+
if (ocRequest.examples?.length) {
|
|
134
|
+
brunoItem.examples = ocRequest.examples.map((example) => {
|
|
135
|
+
const brunoExample: any = {
|
|
136
|
+
uid: uuid(),
|
|
137
|
+
itemUid: uuid(),
|
|
138
|
+
name: example.name || 'Untitled Example',
|
|
139
|
+
type: 'http-request',
|
|
140
|
+
request: null,
|
|
141
|
+
response: null
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (example.description) {
|
|
145
|
+
if (typeof example.description === 'string' && example.description.trim().length) {
|
|
146
|
+
brunoExample.description = example.description;
|
|
147
|
+
} else if (typeof example.description === 'object' && example.description.content?.trim().length) {
|
|
148
|
+
brunoExample.description = example.description.content;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (example.request) {
|
|
153
|
+
brunoExample.request = {
|
|
154
|
+
url: example.request.url || '',
|
|
155
|
+
method: example.request.method || 'GET',
|
|
156
|
+
headers: toBrunoHttpHeaders(example.request.headers) || [],
|
|
157
|
+
params: toBrunoParams(example.request.params) || [],
|
|
158
|
+
body: toBrunoBody(example.request.body) || {
|
|
159
|
+
mode: 'none',
|
|
160
|
+
json: null,
|
|
161
|
+
text: null,
|
|
162
|
+
xml: null,
|
|
163
|
+
sparql: null,
|
|
164
|
+
formUrlEncoded: null,
|
|
165
|
+
multipartForm: null,
|
|
166
|
+
graphql: null,
|
|
167
|
+
file: null
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (example.response) {
|
|
173
|
+
brunoExample.response = {
|
|
174
|
+
status: example.response.status !== undefined ? String(example.response.status) : null,
|
|
175
|
+
statusText: example.response.statusText || null,
|
|
176
|
+
headers: toBrunoHttpHeaders(example.response.headers) || [],
|
|
177
|
+
body: null
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
if (example.response.body) {
|
|
181
|
+
brunoExample.response.body = {
|
|
182
|
+
type: example.response.body.type || 'text',
|
|
183
|
+
content: example.response.body.data || ''
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return brunoExample;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return brunoItem;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export default parseHttpRequest;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Item as BrunoItem } from '@usebruno/schema-types/collection/item';
|
|
2
|
+
import type { ScriptFile } from '@opencollection/types/collection/item';
|
|
3
|
+
import { uuid } from '../../../utils';
|
|
4
|
+
|
|
5
|
+
const parseScript = (ocScript: ScriptFile): BrunoItem => {
|
|
6
|
+
const brunoItem: BrunoItem = {
|
|
7
|
+
uid: uuid(),
|
|
8
|
+
type: 'js',
|
|
9
|
+
seq: 1,
|
|
10
|
+
name: 'Script',
|
|
11
|
+
tags: [],
|
|
12
|
+
request: null,
|
|
13
|
+
settings: null,
|
|
14
|
+
fileContent: ocScript.script || '',
|
|
15
|
+
root: null,
|
|
16
|
+
items: [],
|
|
17
|
+
examples: [],
|
|
18
|
+
filename: null,
|
|
19
|
+
pathname: null
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return brunoItem;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default parseScript;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Item as BrunoItem } from '@usebruno/schema-types/collection/item';
|
|
2
|
+
import type { WebSocketRequest as BrunoWebSocketRequest } from '@usebruno/schema-types/requests/websocket';
|
|
3
|
+
import type { WebSocketRequest, WebSocketMessage } from '@opencollection/types/requests/websocket';
|
|
4
|
+
import { toBrunoAuth } from '../common/auth';
|
|
5
|
+
import { toBrunoHttpHeaders } from '../common/headers';
|
|
6
|
+
import { toBrunoVariables } from '../common/variables';
|
|
7
|
+
import { toBrunoScripts } from '../common/scripts';
|
|
8
|
+
import { uuid } from '../../../utils';
|
|
9
|
+
|
|
10
|
+
const parseWebsocketRequest = (ocRequest: WebSocketRequest): BrunoItem => {
|
|
11
|
+
const info = ocRequest.info;
|
|
12
|
+
const websocket = ocRequest.websocket;
|
|
13
|
+
const runtime = ocRequest.runtime;
|
|
14
|
+
|
|
15
|
+
const brunoRequest: BrunoWebSocketRequest = {
|
|
16
|
+
url: websocket?.url || '',
|
|
17
|
+
headers: toBrunoHttpHeaders(websocket?.headers) || [],
|
|
18
|
+
auth: toBrunoAuth(websocket?.auth),
|
|
19
|
+
body: {
|
|
20
|
+
mode: 'ws',
|
|
21
|
+
ws: []
|
|
22
|
+
},
|
|
23
|
+
script: {
|
|
24
|
+
req: null,
|
|
25
|
+
res: null
|
|
26
|
+
},
|
|
27
|
+
vars: {
|
|
28
|
+
req: [],
|
|
29
|
+
res: []
|
|
30
|
+
},
|
|
31
|
+
assertions: [],
|
|
32
|
+
tests: null,
|
|
33
|
+
docs: null
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// message
|
|
37
|
+
if (websocket?.message) {
|
|
38
|
+
const message = websocket.message as WebSocketMessage;
|
|
39
|
+
if (message.data?.trim().length) {
|
|
40
|
+
brunoRequest.body.ws = [{
|
|
41
|
+
name: '',
|
|
42
|
+
type: message.type || 'text',
|
|
43
|
+
content: message.data
|
|
44
|
+
}];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// scripts
|
|
49
|
+
const scripts = toBrunoScripts(runtime?.scripts);
|
|
50
|
+
if (scripts?.script && brunoRequest.script) {
|
|
51
|
+
if (scripts.script.req) {
|
|
52
|
+
brunoRequest.script.req = scripts.script.req;
|
|
53
|
+
}
|
|
54
|
+
if (scripts.script.res) {
|
|
55
|
+
brunoRequest.script.res = scripts.script.res;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (scripts?.tests) {
|
|
59
|
+
brunoRequest.tests = scripts.tests;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// variables
|
|
63
|
+
const variables = toBrunoVariables(runtime?.variables);
|
|
64
|
+
brunoRequest.vars = variables;
|
|
65
|
+
|
|
66
|
+
// docs
|
|
67
|
+
if (ocRequest.docs) {
|
|
68
|
+
brunoRequest.docs = ocRequest.docs;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// settings
|
|
72
|
+
const wsSettings: Record<string, number> = {
|
|
73
|
+
timeout: 0,
|
|
74
|
+
keepAliveInterval: 0
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
if (ocRequest.settings) {
|
|
78
|
+
if (typeof ocRequest.settings.timeout === 'number') {
|
|
79
|
+
wsSettings.timeout = ocRequest.settings.timeout;
|
|
80
|
+
}
|
|
81
|
+
if (typeof ocRequest.settings.keepAliveInterval === 'number') {
|
|
82
|
+
wsSettings.keepAliveInterval = ocRequest.settings.keepAliveInterval;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// bruno item
|
|
87
|
+
const brunoItem: BrunoItem = {
|
|
88
|
+
uid: uuid(),
|
|
89
|
+
type: 'ws-request',
|
|
90
|
+
seq: info?.seq || 1,
|
|
91
|
+
name: info?.name || 'Untitled Request',
|
|
92
|
+
tags: info?.tags || [],
|
|
93
|
+
request: brunoRequest,
|
|
94
|
+
settings: wsSettings as any,
|
|
95
|
+
fileContent: null,
|
|
96
|
+
root: null,
|
|
97
|
+
items: [],
|
|
98
|
+
examples: [],
|
|
99
|
+
filename: null,
|
|
100
|
+
pathname: null
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return brunoItem;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export default parseWebsocketRequest;
|