@unito/integration-sdk 1.6.1 → 1.8.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/src/index.cjs
CHANGED
|
@@ -1413,6 +1413,22 @@ class Provider {
|
|
|
1413
1413
|
// Accept text based content types
|
|
1414
1414
|
body = (await response.text());
|
|
1415
1415
|
}
|
|
1416
|
+
else if (headers.Accept?.includes('application/schema+json')) {
|
|
1417
|
+
try {
|
|
1418
|
+
body = response.body ? await response.json() : undefined;
|
|
1419
|
+
}
|
|
1420
|
+
catch (err) {
|
|
1421
|
+
throw this.handleError(500, `Invalid JSON schema response`, options);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
else if (headers.Accept?.includes('application/swagger+json')) {
|
|
1425
|
+
try {
|
|
1426
|
+
body = response.body ? await response.json() : undefined;
|
|
1427
|
+
}
|
|
1428
|
+
catch (err) {
|
|
1429
|
+
throw this.handleError(500, `Invalid JSON swagger response`, options);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1416
1432
|
else {
|
|
1417
1433
|
throw this.handleError(500, 'Unsupported Content-Type', options);
|
|
1418
1434
|
}
|
|
@@ -306,6 +306,22 @@ export class Provider {
|
|
|
306
306
|
// Accept text based content types
|
|
307
307
|
body = (await response.text());
|
|
308
308
|
}
|
|
309
|
+
else if (headers.Accept?.includes('application/schema+json')) {
|
|
310
|
+
try {
|
|
311
|
+
body = response.body ? await response.json() : undefined;
|
|
312
|
+
}
|
|
313
|
+
catch (err) {
|
|
314
|
+
throw this.handleError(500, `Invalid JSON schema response`, options);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else if (headers.Accept?.includes('application/swagger+json')) {
|
|
318
|
+
try {
|
|
319
|
+
body = response.body ? await response.json() : undefined;
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
throw this.handleError(500, `Invalid JSON swagger response`, options);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
309
325
|
else {
|
|
310
326
|
throw this.handleError(500, 'Unsupported Content-Type', options);
|
|
311
327
|
}
|
|
@@ -79,6 +79,64 @@ describe('Provider', () => {
|
|
|
79
79
|
]);
|
|
80
80
|
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: '' });
|
|
81
81
|
});
|
|
82
|
+
it('should accept application/schema+json type response', async (context) => {
|
|
83
|
+
const response = new Response('{"data": "value"}', {
|
|
84
|
+
status: 200,
|
|
85
|
+
headers: { 'Content-Type': 'application/schema+json; charset=UTF-8' },
|
|
86
|
+
});
|
|
87
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
88
|
+
const actualResponse = await provider.get('/endpoint', {
|
|
89
|
+
credentials: { apiKey: 'apikey#1111' },
|
|
90
|
+
logger: logger,
|
|
91
|
+
signal: new AbortController().signal,
|
|
92
|
+
additionnalheaders: { 'X-Additional-Header': 'value1', Accept: 'application/schema+json; charset=UTF-8' },
|
|
93
|
+
});
|
|
94
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
95
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
96
|
+
'www.myApi.com/endpoint',
|
|
97
|
+
{
|
|
98
|
+
method: 'GET',
|
|
99
|
+
body: null,
|
|
100
|
+
signal: new AbortController().signal,
|
|
101
|
+
headers: {
|
|
102
|
+
Accept: 'application/schema+json; charset=UTF-8',
|
|
103
|
+
'X-Custom-Provider-Header': 'value',
|
|
104
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
105
|
+
'X-Additional-Header': 'value1',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
]);
|
|
109
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
110
|
+
});
|
|
111
|
+
it('should accept application/swagger+json type response', async (context) => {
|
|
112
|
+
const response = new Response('{"data": "value"}', {
|
|
113
|
+
status: 200,
|
|
114
|
+
headers: { 'Content-Type': 'application/swagger+json; charset=UTF-8' },
|
|
115
|
+
});
|
|
116
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
117
|
+
const actualResponse = await provider.get('/endpoint', {
|
|
118
|
+
credentials: { apiKey: 'apikey#1111' },
|
|
119
|
+
logger: logger,
|
|
120
|
+
signal: new AbortController().signal,
|
|
121
|
+
additionnalheaders: { 'X-Additional-Header': 'value1', Accept: 'application/swagger+json; charset=UTF-8' },
|
|
122
|
+
});
|
|
123
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
124
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
125
|
+
'www.myApi.com/endpoint',
|
|
126
|
+
{
|
|
127
|
+
method: 'GET',
|
|
128
|
+
body: null,
|
|
129
|
+
signal: new AbortController().signal,
|
|
130
|
+
headers: {
|
|
131
|
+
Accept: 'application/swagger+json; charset=UTF-8',
|
|
132
|
+
'X-Custom-Provider-Header': 'value',
|
|
133
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
134
|
+
'X-Additional-Header': 'value1',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
]);
|
|
138
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
139
|
+
});
|
|
82
140
|
it('should return the raw response body if specified', async (context) => {
|
|
83
141
|
const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
|
|
84
142
|
status: 200,
|
package/package.json
CHANGED
|
@@ -424,6 +424,18 @@ export class Provider {
|
|
|
424
424
|
} else if (headers.Accept?.includes('text/html')) {
|
|
425
425
|
// Accept text based content types
|
|
426
426
|
body = (await response.text()) as T;
|
|
427
|
+
} else if (headers.Accept?.includes('application/schema+json')) {
|
|
428
|
+
try {
|
|
429
|
+
body = response.body ? await response.json() : undefined;
|
|
430
|
+
} catch (err) {
|
|
431
|
+
throw this.handleError(500, `Invalid JSON schema response`, options);
|
|
432
|
+
}
|
|
433
|
+
} else if (headers.Accept?.includes('application/swagger+json')) {
|
|
434
|
+
try {
|
|
435
|
+
body = response.body ? await response.json() : undefined;
|
|
436
|
+
} catch (err) {
|
|
437
|
+
throw this.handleError(500, `Invalid JSON swagger response`, options);
|
|
438
|
+
}
|
|
427
439
|
} else {
|
|
428
440
|
throw this.handleError(500, 'Unsupported Content-Type', options);
|
|
429
441
|
}
|
|
@@ -94,6 +94,76 @@ describe('Provider', () => {
|
|
|
94
94
|
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: '' });
|
|
95
95
|
});
|
|
96
96
|
|
|
97
|
+
it('should accept application/schema+json type response', async context => {
|
|
98
|
+
const response = new Response('{"data": "value"}', {
|
|
99
|
+
status: 200,
|
|
100
|
+
headers: { 'Content-Type': 'application/schema+json; charset=UTF-8' },
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
104
|
+
|
|
105
|
+
const actualResponse = await provider.get('/endpoint', {
|
|
106
|
+
credentials: { apiKey: 'apikey#1111' },
|
|
107
|
+
logger: logger,
|
|
108
|
+
signal: new AbortController().signal,
|
|
109
|
+
additionnalheaders: { 'X-Additional-Header': 'value1', Accept: 'application/schema+json; charset=UTF-8' },
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
113
|
+
|
|
114
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
115
|
+
'www.myApi.com/endpoint',
|
|
116
|
+
{
|
|
117
|
+
method: 'GET',
|
|
118
|
+
body: null,
|
|
119
|
+
signal: new AbortController().signal,
|
|
120
|
+
headers: {
|
|
121
|
+
Accept: 'application/schema+json; charset=UTF-8',
|
|
122
|
+
'X-Custom-Provider-Header': 'value',
|
|
123
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
124
|
+
'X-Additional-Header': 'value1',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
]);
|
|
128
|
+
|
|
129
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should accept application/swagger+json type response', async context => {
|
|
133
|
+
const response = new Response('{"data": "value"}', {
|
|
134
|
+
status: 200,
|
|
135
|
+
headers: { 'Content-Type': 'application/swagger+json; charset=UTF-8' },
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
139
|
+
|
|
140
|
+
const actualResponse = await provider.get('/endpoint', {
|
|
141
|
+
credentials: { apiKey: 'apikey#1111' },
|
|
142
|
+
logger: logger,
|
|
143
|
+
signal: new AbortController().signal,
|
|
144
|
+
additionnalheaders: { 'X-Additional-Header': 'value1', Accept: 'application/swagger+json; charset=UTF-8' },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
148
|
+
|
|
149
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
150
|
+
'www.myApi.com/endpoint',
|
|
151
|
+
{
|
|
152
|
+
method: 'GET',
|
|
153
|
+
body: null,
|
|
154
|
+
signal: new AbortController().signal,
|
|
155
|
+
headers: {
|
|
156
|
+
Accept: 'application/swagger+json; charset=UTF-8',
|
|
157
|
+
'X-Custom-Provider-Header': 'value',
|
|
158
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
159
|
+
'X-Additional-Header': 'value1',
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
]);
|
|
163
|
+
|
|
164
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
165
|
+
});
|
|
166
|
+
|
|
97
167
|
it('should return the raw response body if specified', async context => {
|
|
98
168
|
const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
|
|
99
169
|
status: 200,
|