@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.
- 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/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- 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/{cjs/workers/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/{esm/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/index.d.ts +24 -0
- 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 +6 -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/constants.ts +3 -0
- package/src/formats/bru/index.ts +9 -9
- 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 +107 -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 +222 -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 +220 -0
- package/src/formats/yml/parseEnvironment.ts +57 -0
- package/src/formats/yml/parseFolder.ts +93 -0
- package/src/formats/yml/parseItem.ts +102 -0
- package/src/formats/yml/stringifyCollection.ts +264 -0
- package/src/formats/yml/stringifyEnvironment.ts +67 -0
- package/src/formats/yml/stringifyFolder.ts +107 -0
- package/src/formats/yml/stringifyItem.ts +37 -0
- package/src/formats/yml/utils.ts +38 -0
- package/src/index.ts +64 -32
- package/src/types/bruno-lang.d.ts +1 -1
- package/src/types.ts +5 -124
- package/src/utils/index.ts +25 -0
- package/src/workers/WorkerQueue/index.ts +10 -10
- package/src/workers/index.ts +21 -20
- package/src/workers/worker-script.ts +21 -6
- package/dist/cjs/formats/bru/index.d.ts +0 -19
- 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 -19
- package/dist/cjs/workers/formats/bru/utils/request-parse-and-redact-body-data.d.ts +0 -9
- package/dist/cjs/workers/index.d.ts +0 -16
- 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 -19
- package/dist/esm/formats/bru/utils/oauth2-additional-params.d.ts +0 -38
- 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 -19
- 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,168 @@
|
|
|
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, GraphQLRequestInfo, GraphQLRequestDetails, GraphQLRequestRuntime } from '@opencollection/types/requests/graphql';
|
|
4
|
+
import type { Auth } from '@opencollection/types/common/auth';
|
|
5
|
+
import type { Scripts } from '@opencollection/types/common/scripts';
|
|
6
|
+
import type { Variable } from '@opencollection/types/common/variables';
|
|
7
|
+
import type { Assertion } from '@opencollection/types/common/assertions';
|
|
8
|
+
import type { Action } from '@opencollection/types/common/actions';
|
|
9
|
+
import type { HttpRequestParam, HttpRequestHeader } from '@opencollection/types/requests/http';
|
|
10
|
+
import { stringifyYml } from '../utils';
|
|
11
|
+
import { isNonEmptyString, isNumber } from '../../../utils';
|
|
12
|
+
import { toOpenCollectionAuth } from '../common/auth';
|
|
13
|
+
import { toOpenCollectionHttpHeaders } from '../common/headers';
|
|
14
|
+
import { toOpenCollectionParams } from '../common/params';
|
|
15
|
+
import { toOpenCollectionVariables } from '../common/variables';
|
|
16
|
+
import { toOpenCollectionActions } from '../common/actions';
|
|
17
|
+
import { toOpenCollectionScripts } from '../common/scripts';
|
|
18
|
+
import { toOpenCollectionAssertions } from '../common/assertions';
|
|
19
|
+
|
|
20
|
+
const stringifyGraphQLRequest = (item: BrunoItem): string => {
|
|
21
|
+
try {
|
|
22
|
+
const ocRequest: GraphQLRequest = {};
|
|
23
|
+
const brunoRequest = item.request as BrunoHttpRequest;
|
|
24
|
+
|
|
25
|
+
// info block
|
|
26
|
+
const info: GraphQLRequestInfo = {
|
|
27
|
+
name: isNonEmptyString(item.name) ? item.name : 'Untitled Request',
|
|
28
|
+
type: 'graphql'
|
|
29
|
+
};
|
|
30
|
+
if (item.seq) {
|
|
31
|
+
info.seq = item.seq;
|
|
32
|
+
}
|
|
33
|
+
if (item.tags?.length) {
|
|
34
|
+
info.tags = item.tags;
|
|
35
|
+
}
|
|
36
|
+
ocRequest.info = info;
|
|
37
|
+
|
|
38
|
+
// graphql block
|
|
39
|
+
const graphql: GraphQLRequestDetails = {
|
|
40
|
+
method: isNonEmptyString(brunoRequest.method) ? brunoRequest.method : 'POST',
|
|
41
|
+
url: isNonEmptyString(brunoRequest.url) ? brunoRequest.url : ''
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// headers
|
|
45
|
+
const headers: HttpRequestHeader[] | undefined = toOpenCollectionHttpHeaders(brunoRequest.headers);
|
|
46
|
+
if (headers) {
|
|
47
|
+
graphql.headers = headers;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// params
|
|
51
|
+
const params: HttpRequestParam[] | undefined = toOpenCollectionParams(brunoRequest.params);
|
|
52
|
+
if (params) {
|
|
53
|
+
graphql.params = params;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// body
|
|
57
|
+
if (brunoRequest.body?.mode === 'graphql' && brunoRequest.body.graphql) {
|
|
58
|
+
const graphqlBody: GraphQLBody = {};
|
|
59
|
+
let hasBody = false;
|
|
60
|
+
|
|
61
|
+
if (isNonEmptyString(brunoRequest.body.graphql.query)) {
|
|
62
|
+
graphqlBody.query = brunoRequest.body.graphql.query;
|
|
63
|
+
hasBody = true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isNonEmptyString(brunoRequest.body.graphql.variables)) {
|
|
67
|
+
graphqlBody.variables = brunoRequest.body.graphql.variables;
|
|
68
|
+
hasBody = true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (hasBody) {
|
|
72
|
+
graphql.body = graphqlBody;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// auth (in graphql block, not runtime)
|
|
77
|
+
const auth: Auth | undefined = toOpenCollectionAuth(brunoRequest.auth);
|
|
78
|
+
if (auth) {
|
|
79
|
+
graphql.auth = auth;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
ocRequest.graphql = graphql;
|
|
83
|
+
|
|
84
|
+
// runtime block
|
|
85
|
+
const runtime: GraphQLRequestRuntime = {};
|
|
86
|
+
let hasRuntime = false;
|
|
87
|
+
|
|
88
|
+
// variables
|
|
89
|
+
const variables: Variable[] | undefined = toOpenCollectionVariables(brunoRequest.vars);
|
|
90
|
+
if (variables) {
|
|
91
|
+
runtime.variables = variables;
|
|
92
|
+
hasRuntime = true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// scripts
|
|
96
|
+
const scripts: Scripts | undefined = toOpenCollectionScripts(brunoRequest);
|
|
97
|
+
if (scripts) {
|
|
98
|
+
runtime.scripts = scripts;
|
|
99
|
+
hasRuntime = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// assertions
|
|
103
|
+
const assertions: Assertion[] | undefined = toOpenCollectionAssertions(brunoRequest.assertions);
|
|
104
|
+
if (assertions) {
|
|
105
|
+
runtime.assertions = assertions;
|
|
106
|
+
hasRuntime = true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// actions (from post-response variables)
|
|
110
|
+
const resVars = brunoRequest.vars?.res;
|
|
111
|
+
const actions: Action[] | undefined = toOpenCollectionActions(resVars);
|
|
112
|
+
if (actions) {
|
|
113
|
+
runtime.actions = actions;
|
|
114
|
+
hasRuntime = true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (hasRuntime) {
|
|
118
|
+
ocRequest.runtime = runtime;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// settings
|
|
122
|
+
const httpSettings = item.settings as BrunoHttpItemSettings | undefined;
|
|
123
|
+
const settings: GraphQLRequestSettings = {};
|
|
124
|
+
if (httpSettings?.encodeUrl === true) {
|
|
125
|
+
settings.encodeUrl = true;
|
|
126
|
+
} else if (httpSettings?.encodeUrl === false) {
|
|
127
|
+
settings.encodeUrl = false;
|
|
128
|
+
} else {
|
|
129
|
+
settings.encodeUrl = true;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const timeout = httpSettings?.timeout;
|
|
133
|
+
if (isNumber(timeout)) {
|
|
134
|
+
settings.timeout = timeout;
|
|
135
|
+
} else {
|
|
136
|
+
settings.timeout = 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (httpSettings?.followRedirects === true) {
|
|
140
|
+
settings.followRedirects = true;
|
|
141
|
+
} else if (httpSettings?.followRedirects === false) {
|
|
142
|
+
settings.followRedirects = false;
|
|
143
|
+
} else {
|
|
144
|
+
settings.followRedirects = true;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const maxRedirects = httpSettings?.maxRedirects;
|
|
148
|
+
if (isNumber(maxRedirects)) {
|
|
149
|
+
settings.maxRedirects = maxRedirects;
|
|
150
|
+
} else {
|
|
151
|
+
settings.maxRedirects = 5;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
ocRequest.settings = settings;
|
|
155
|
+
|
|
156
|
+
// docs
|
|
157
|
+
if (isNonEmptyString(brunoRequest.docs)) {
|
|
158
|
+
ocRequest.docs = brunoRequest.docs;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return stringifyYml(ocRequest);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.error('Error stringifying GraphQL request:', error);
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export default stringifyGraphQLRequest;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { Item as BrunoItem } from '@usebruno/schema-types/collection/item';
|
|
2
|
+
import type { KeyValue as BrunoKeyValue } from '@usebruno/schema-types/common/key-value';
|
|
3
|
+
import type { GrpcRequest as BrunoGrpcRequest } from '@usebruno/schema-types/requests/grpc';
|
|
4
|
+
import type { GrpcRequest, GrpcMetadata, GrpcMessage, GrpcRequestInfo, GrpcRequestDetails, GrpcRequestRuntime } from '@opencollection/types/requests/grpc';
|
|
5
|
+
import type { Auth } from '@opencollection/types/common/auth';
|
|
6
|
+
import type { Scripts } from '@opencollection/types/common/scripts';
|
|
7
|
+
import type { Variable } from '@opencollection/types/common/variables';
|
|
8
|
+
import type { Assertion } from '@opencollection/types/common/assertions';
|
|
9
|
+
import { stringifyYml } from '../utils';
|
|
10
|
+
import { isNonEmptyString } from '../../../utils';
|
|
11
|
+
import { toOpenCollectionAuth } from '../common/auth';
|
|
12
|
+
import { toOpenCollectionVariables } from '../common/variables';
|
|
13
|
+
import { toOpenCollectionScripts } from '../common/scripts';
|
|
14
|
+
import { toOpenCollectionAssertions } from '../common/assertions';
|
|
15
|
+
|
|
16
|
+
const stringifyGrpcRequest = (item: BrunoItem): string => {
|
|
17
|
+
try {
|
|
18
|
+
const ocRequest: GrpcRequest = {};
|
|
19
|
+
const brunoRequest = item.request as BrunoGrpcRequest;
|
|
20
|
+
|
|
21
|
+
// info block
|
|
22
|
+
const info: GrpcRequestInfo = {
|
|
23
|
+
name: isNonEmptyString(item.name) ? item.name : 'Untitled Request',
|
|
24
|
+
type: 'grpc'
|
|
25
|
+
};
|
|
26
|
+
if (item.seq) {
|
|
27
|
+
info.seq = item.seq;
|
|
28
|
+
}
|
|
29
|
+
if (item.tags?.length) {
|
|
30
|
+
info.tags = item.tags;
|
|
31
|
+
}
|
|
32
|
+
ocRequest.info = info;
|
|
33
|
+
|
|
34
|
+
// grpc block
|
|
35
|
+
const grpc: GrpcRequestDetails = {
|
|
36
|
+
url: isNonEmptyString(brunoRequest.url) ? brunoRequest.url : '',
|
|
37
|
+
method: isNonEmptyString(brunoRequest.method) ? brunoRequest.method : ''
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// method type
|
|
41
|
+
if (brunoRequest.methodType) {
|
|
42
|
+
grpc.methodType = brunoRequest.methodType;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// proto file path
|
|
46
|
+
if (isNonEmptyString(brunoRequest.protoPath)) {
|
|
47
|
+
grpc.protoFilePath = brunoRequest.protoPath;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// metadata
|
|
51
|
+
if (brunoRequest.headers?.length) {
|
|
52
|
+
const metadata: GrpcMetadata[] = brunoRequest.headers.map((header: BrunoKeyValue) => {
|
|
53
|
+
const metadataItem: GrpcMetadata = {
|
|
54
|
+
name: header.name || '',
|
|
55
|
+
value: header.value || ''
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (header?.description?.trim().length) {
|
|
59
|
+
metadataItem.description = header.description;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (header.enabled === false) {
|
|
63
|
+
metadataItem.disabled = true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return metadataItem;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (metadata.length) {
|
|
70
|
+
grpc.metadata = metadata;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// message
|
|
75
|
+
if (brunoRequest.body?.mode === 'grpc' && brunoRequest.body.grpc?.length) {
|
|
76
|
+
const messages = brunoRequest.body.grpc;
|
|
77
|
+
|
|
78
|
+
// todo: bruno app supports only one message for now
|
|
79
|
+
// update this when bruno app supports multiple messages
|
|
80
|
+
if (messages.length) {
|
|
81
|
+
const message: GrpcMessage = messages[0].content || '';
|
|
82
|
+
if (message.trim().length) {
|
|
83
|
+
grpc.message = message;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// auth
|
|
89
|
+
const auth: Auth | undefined = toOpenCollectionAuth(brunoRequest.auth);
|
|
90
|
+
if (auth) {
|
|
91
|
+
grpc.auth = auth;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
ocRequest.grpc = grpc;
|
|
95
|
+
|
|
96
|
+
// runtime block
|
|
97
|
+
const runtime: GrpcRequestRuntime = {};
|
|
98
|
+
let hasRuntime = false;
|
|
99
|
+
|
|
100
|
+
// variables
|
|
101
|
+
const variables: Variable[] | undefined = toOpenCollectionVariables(brunoRequest.vars);
|
|
102
|
+
if (variables) {
|
|
103
|
+
runtime.variables = variables;
|
|
104
|
+
hasRuntime = true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// scripts
|
|
108
|
+
const scripts: Scripts | undefined = toOpenCollectionScripts(brunoRequest);
|
|
109
|
+
if (scripts) {
|
|
110
|
+
runtime.scripts = scripts;
|
|
111
|
+
hasRuntime = true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// assertions
|
|
115
|
+
const assertions: Assertion[] | undefined = toOpenCollectionAssertions(brunoRequest.assertions);
|
|
116
|
+
if (assertions) {
|
|
117
|
+
runtime.assertions = assertions;
|
|
118
|
+
hasRuntime = true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (hasRuntime) {
|
|
122
|
+
ocRequest.runtime = runtime;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// docs
|
|
126
|
+
if (isNonEmptyString(brunoRequest.docs)) {
|
|
127
|
+
ocRequest.docs = brunoRequest.docs;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return stringifyYml(ocRequest);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.error('Error stringifying gRPC request:', error);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export default stringifyGrpcRequest;
|
|
@@ -0,0 +1,222 @@
|
|
|
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, HttpRequestSettings, HttpRequestExample, HttpRequestInfo, HttpRequestDetails, HttpRequestRuntime, HttpRequestHeader } from '@opencollection/types/requests/http';
|
|
4
|
+
import type { Auth } from '@opencollection/types/common/auth';
|
|
5
|
+
import type { Scripts } from '@opencollection/types/common/scripts';
|
|
6
|
+
import type { Variable } from '@opencollection/types/common/variables';
|
|
7
|
+
import type { Assertion } from '@opencollection/types/common/assertions';
|
|
8
|
+
import type { Action } from '@opencollection/types/common/actions';
|
|
9
|
+
import type { HttpRequestParam, HttpRequestBody } from '@opencollection/types/requests/http';
|
|
10
|
+
import { stringifyYml } from '../utils';
|
|
11
|
+
import { toOpenCollectionAuth } from '../common/auth';
|
|
12
|
+
import { toOpenCollectionHttpHeaders, toOpenCollectionResponseHeaders } from '../common/headers';
|
|
13
|
+
import { toOpenCollectionParams } from '../common/params';
|
|
14
|
+
import { toOpenCollectionBody } from '../common/body';
|
|
15
|
+
import { toOpenCollectionVariables } from '../common/variables';
|
|
16
|
+
import { toOpenCollectionActions } from '../common/actions';
|
|
17
|
+
import { toOpenCollectionScripts } from '../common/scripts';
|
|
18
|
+
import { toOpenCollectionAssertions } from '../common/assertions';
|
|
19
|
+
import { isNumber, isNonEmptyString } from '../../../utils';
|
|
20
|
+
|
|
21
|
+
const stringifyHttpRequest = (item: BrunoItem): string => {
|
|
22
|
+
try {
|
|
23
|
+
const ocRequest: HttpRequest = {};
|
|
24
|
+
const brunoRequest = item.request as BrunoHttpRequest;
|
|
25
|
+
|
|
26
|
+
// info block
|
|
27
|
+
const info: HttpRequestInfo = {
|
|
28
|
+
name: isNonEmptyString(item.name) ? item.name : 'Untitled Request',
|
|
29
|
+
type: 'http'
|
|
30
|
+
};
|
|
31
|
+
if (item.seq) {
|
|
32
|
+
info.seq = item.seq;
|
|
33
|
+
}
|
|
34
|
+
if (item.tags?.length) {
|
|
35
|
+
info.tags = item.tags;
|
|
36
|
+
}
|
|
37
|
+
ocRequest.info = info;
|
|
38
|
+
|
|
39
|
+
// http block
|
|
40
|
+
const http: HttpRequestDetails = {
|
|
41
|
+
method: isNonEmptyString(brunoRequest.method) ? brunoRequest.method : 'GET',
|
|
42
|
+
url: isNonEmptyString(brunoRequest.url) ? brunoRequest.url : ''
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// headers
|
|
46
|
+
const headers: HttpRequestHeader[] | undefined = toOpenCollectionHttpHeaders(brunoRequest.headers);
|
|
47
|
+
if (headers) {
|
|
48
|
+
http.headers = headers;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// params
|
|
52
|
+
const params: HttpRequestParam[] | undefined = toOpenCollectionParams(brunoRequest.params);
|
|
53
|
+
if (params) {
|
|
54
|
+
http.params = params;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// body
|
|
58
|
+
const body: HttpRequestBody | undefined = toOpenCollectionBody(brunoRequest.body);
|
|
59
|
+
if (body) {
|
|
60
|
+
http.body = body;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// auth
|
|
64
|
+
const auth: Auth | undefined = toOpenCollectionAuth(brunoRequest.auth);
|
|
65
|
+
if (auth) {
|
|
66
|
+
http.auth = auth;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
ocRequest.http = http;
|
|
70
|
+
|
|
71
|
+
// runtime block
|
|
72
|
+
const runtime: HttpRequestRuntime = {};
|
|
73
|
+
let hasRuntime = false;
|
|
74
|
+
|
|
75
|
+
// variables
|
|
76
|
+
const variables: Variable[] | undefined = toOpenCollectionVariables(brunoRequest.vars);
|
|
77
|
+
if (variables) {
|
|
78
|
+
runtime.variables = variables;
|
|
79
|
+
hasRuntime = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// scripts
|
|
83
|
+
const scripts: Scripts | undefined = toOpenCollectionScripts(brunoRequest);
|
|
84
|
+
if (scripts) {
|
|
85
|
+
runtime.scripts = scripts;
|
|
86
|
+
hasRuntime = true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// assertions
|
|
90
|
+
const assertions: Assertion[] | undefined = toOpenCollectionAssertions(brunoRequest.assertions);
|
|
91
|
+
if (assertions) {
|
|
92
|
+
runtime.assertions = assertions;
|
|
93
|
+
hasRuntime = true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// actions (from post-response variables)
|
|
97
|
+
const resVars = brunoRequest.vars?.res;
|
|
98
|
+
const actions: Action[] | undefined = toOpenCollectionActions(resVars);
|
|
99
|
+
if (actions) {
|
|
100
|
+
runtime.actions = actions;
|
|
101
|
+
hasRuntime = true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (hasRuntime) {
|
|
105
|
+
ocRequest.runtime = runtime;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// settings
|
|
109
|
+
const httpSettings = item.settings as BrunoHttpItemSettings | undefined;
|
|
110
|
+
const settings: HttpRequestSettings = {};
|
|
111
|
+
if (httpSettings?.encodeUrl === true) {
|
|
112
|
+
settings.encodeUrl = true;
|
|
113
|
+
} else if (httpSettings?.encodeUrl === false) {
|
|
114
|
+
settings.encodeUrl = false;
|
|
115
|
+
} else {
|
|
116
|
+
settings.encodeUrl = true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const timeout = httpSettings?.timeout;
|
|
120
|
+
if (isNumber(timeout)) {
|
|
121
|
+
settings.timeout = timeout;
|
|
122
|
+
} else {
|
|
123
|
+
settings.timeout = 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (httpSettings?.followRedirects === true) {
|
|
127
|
+
settings.followRedirects = true;
|
|
128
|
+
} else if (httpSettings?.followRedirects === false) {
|
|
129
|
+
settings.followRedirects = false;
|
|
130
|
+
} else {
|
|
131
|
+
settings.followRedirects = true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const maxRedirects = httpSettings?.maxRedirects;
|
|
135
|
+
if (isNumber(maxRedirects)) {
|
|
136
|
+
settings.maxRedirects = maxRedirects;
|
|
137
|
+
} else {
|
|
138
|
+
settings.maxRedirects = 5;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
ocRequest.settings = settings;
|
|
142
|
+
|
|
143
|
+
// examples
|
|
144
|
+
if (item.examples?.length) {
|
|
145
|
+
const examples: HttpRequestExample[] = item.examples.map((example) => {
|
|
146
|
+
const ocExample: HttpRequestExample = {};
|
|
147
|
+
ocExample.name = example?.name || 'Untitled Example';
|
|
148
|
+
|
|
149
|
+
if (isNonEmptyString(example.description)) {
|
|
150
|
+
ocExample.description = example.description;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (example.request) {
|
|
154
|
+
ocExample.request = {};
|
|
155
|
+
ocExample.request.url = example.request.url || '';
|
|
156
|
+
ocExample.request.method = example.request.method || 'GET';
|
|
157
|
+
|
|
158
|
+
const exampleHeaders = toOpenCollectionHttpHeaders(example.request.headers);
|
|
159
|
+
if (exampleHeaders) {
|
|
160
|
+
ocExample.request.headers = exampleHeaders;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const exampleParams = toOpenCollectionParams(example.request.params);
|
|
164
|
+
if (exampleParams) {
|
|
165
|
+
ocExample.request.params = exampleParams;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const exampleBody = toOpenCollectionBody(example.request.body);
|
|
169
|
+
if (exampleBody !== undefined) {
|
|
170
|
+
ocExample.request.body = exampleBody;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (example.response) {
|
|
175
|
+
ocExample.response = {};
|
|
176
|
+
|
|
177
|
+
const statusNum = Number(example.response.status);
|
|
178
|
+
if (Number.isInteger(statusNum) && statusNum > 0) {
|
|
179
|
+
ocExample.response.status = statusNum;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isNonEmptyString(example.response.statusText)) {
|
|
183
|
+
ocExample.response.statusText = example.response.statusText;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const responseHeaders = toOpenCollectionResponseHeaders(example.response.headers);
|
|
187
|
+
if (responseHeaders) {
|
|
188
|
+
ocExample.response.headers = responseHeaders;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (example.response.body && example.response.body.type && example.response.body.content !== undefined) {
|
|
192
|
+
const content = example.response.body.content;
|
|
193
|
+
const contentString = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
|
194
|
+
|
|
195
|
+
ocExample.response.body = {
|
|
196
|
+
type: example.response.body.type as 'json' | 'text' | 'xml' | 'html' | 'binary',
|
|
197
|
+
data: contentString
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return ocExample;
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (examples?.length) {
|
|
206
|
+
ocRequest.examples = examples;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// docs
|
|
211
|
+
if (isNonEmptyString(brunoRequest.docs)) {
|
|
212
|
+
ocRequest.docs = brunoRequest.docs;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return stringifyYml(ocRequest);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.error('Error stringifying HTTP request:', error);
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export default stringifyHttpRequest;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Item as BrunoItem } from '@usebruno/schema-types/collection/item';
|
|
2
|
+
import type { ScriptFile } from '@opencollection/types/collection/item';
|
|
3
|
+
import { stringifyYml } from '../utils';
|
|
4
|
+
|
|
5
|
+
const stringifyScript = (item: BrunoItem): string => {
|
|
6
|
+
try {
|
|
7
|
+
const ocScript: ScriptFile = {
|
|
8
|
+
type: 'script'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
if (item.fileContent?.trim().length) {
|
|
12
|
+
ocScript.script = item.fileContent;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return stringifyYml(ocScript);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.error('Error stringifying script:', error);
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default stringifyScript;
|
|
@@ -0,0 +1,114 @@
|
|
|
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, WebSocketRequestInfo, WebSocketRequestDetails, WebSocketRequestRuntime } from '@opencollection/types/requests/websocket';
|
|
4
|
+
import type { Auth } from '@opencollection/types/common/auth';
|
|
5
|
+
import type { Scripts } from '@opencollection/types/common/scripts';
|
|
6
|
+
import type { Variable } from '@opencollection/types/common/variables';
|
|
7
|
+
import type { HttpRequestHeader } from '@opencollection/types/requests/http';
|
|
8
|
+
import { stringifyYml } from '../utils';
|
|
9
|
+
import { isNonEmptyString } from '../../../utils';
|
|
10
|
+
import { toOpenCollectionAuth } from '../common/auth';
|
|
11
|
+
import { toOpenCollectionHttpHeaders } from '../common/headers';
|
|
12
|
+
import { toOpenCollectionVariables } from '../common/variables';
|
|
13
|
+
import { toOpenCollectionScripts } from '../common/scripts';
|
|
14
|
+
|
|
15
|
+
const stringifyWebsocketRequest = (item: BrunoItem): string => {
|
|
16
|
+
try {
|
|
17
|
+
const ocRequest: WebSocketRequest = {};
|
|
18
|
+
const brunoRequest = item.request as BrunoWebSocketRequest;
|
|
19
|
+
|
|
20
|
+
// info block
|
|
21
|
+
const info: WebSocketRequestInfo = {
|
|
22
|
+
name: isNonEmptyString(item.name) ? item.name : 'Untitled Request',
|
|
23
|
+
type: 'websocket'
|
|
24
|
+
};
|
|
25
|
+
if (item.seq) {
|
|
26
|
+
info.seq = item.seq;
|
|
27
|
+
}
|
|
28
|
+
if (item.tags?.length) {
|
|
29
|
+
info.tags = item.tags;
|
|
30
|
+
}
|
|
31
|
+
ocRequest.info = info;
|
|
32
|
+
|
|
33
|
+
// websocket block
|
|
34
|
+
const websocket: WebSocketRequestDetails = {
|
|
35
|
+
url: isNonEmptyString(brunoRequest.url) ? brunoRequest.url : ''
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// headers
|
|
39
|
+
const headers: HttpRequestHeader[] | undefined = toOpenCollectionHttpHeaders(brunoRequest.headers);
|
|
40
|
+
if (headers) {
|
|
41
|
+
websocket.headers = headers;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// message
|
|
45
|
+
if (brunoRequest.body?.mode === 'ws' && brunoRequest.body.ws?.length) {
|
|
46
|
+
const messages = brunoRequest.body.ws;
|
|
47
|
+
|
|
48
|
+
// todo: bruno app supports only one message for now
|
|
49
|
+
// update this when bruno app supports multiple messages
|
|
50
|
+
if (messages.length) {
|
|
51
|
+
const msg = messages[0];
|
|
52
|
+
const message: WebSocketMessage = {
|
|
53
|
+
type: (msg.type as 'text' | 'json' | 'xml' | 'binary') || 'text',
|
|
54
|
+
data: msg.content || ''
|
|
55
|
+
};
|
|
56
|
+
if (message.data.trim().length) {
|
|
57
|
+
websocket.message = message;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// auth
|
|
63
|
+
const auth: Auth | undefined = toOpenCollectionAuth(brunoRequest.auth);
|
|
64
|
+
if (auth) {
|
|
65
|
+
websocket.auth = auth;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
ocRequest.websocket = websocket;
|
|
69
|
+
|
|
70
|
+
// runtime block
|
|
71
|
+
const runtime: WebSocketRequestRuntime = {};
|
|
72
|
+
let hasRuntime = false;
|
|
73
|
+
|
|
74
|
+
// variables
|
|
75
|
+
const variables: Variable[] | undefined = toOpenCollectionVariables(brunoRequest.vars);
|
|
76
|
+
if (variables) {
|
|
77
|
+
runtime.variables = variables;
|
|
78
|
+
hasRuntime = true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// scripts
|
|
82
|
+
const scripts: Scripts | undefined = toOpenCollectionScripts(brunoRequest);
|
|
83
|
+
if (scripts) {
|
|
84
|
+
runtime.scripts = scripts;
|
|
85
|
+
hasRuntime = true;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (hasRuntime) {
|
|
89
|
+
ocRequest.runtime = runtime;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// settings
|
|
93
|
+
const wsSettings = item.settings as Record<string, number | string | undefined> | undefined;
|
|
94
|
+
if (wsSettings) {
|
|
95
|
+
ocRequest.settings = {};
|
|
96
|
+
const timeout = Number(wsSettings.timeout);
|
|
97
|
+
ocRequest.settings.timeout = !isNaN(timeout) ? timeout : 0;
|
|
98
|
+
const keepAliveInterval = Number(wsSettings.keepAliveInterval);
|
|
99
|
+
ocRequest.settings.keepAliveInterval = !isNaN(keepAliveInterval) ? keepAliveInterval : 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// docs
|
|
103
|
+
if (isNonEmptyString(brunoRequest.docs)) {
|
|
104
|
+
ocRequest.docs = brunoRequest.docs;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return stringifyYml(ocRequest);
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error('Error stringifying WebSocket request:', error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export default stringifyWebsocketRequest;
|