@unito/integration-sdk 1.8.0 → 1.8.2

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.
@@ -1061,7 +1061,7 @@ class Integration {
1061
1061
  // Express Server initialization
1062
1062
  const app = express();
1063
1063
  // Parse query strings with https://github.com/ljharb/qs.
1064
- app.set('query parser', 'extended');
1064
+ app.set('query parser', 'simple');
1065
1065
  app.use(express.json());
1066
1066
  // Must be one of the first handlers (to catch all the errors).
1067
1067
  app.use(onFinish);
@@ -1393,11 +1393,11 @@ class Provider {
1393
1393
  // When we expect octet-stream, we accept any Content-Type the provider sends us, we just want to stream it
1394
1394
  body = response.body;
1395
1395
  }
1396
- else if (headers.Accept === 'application/json') {
1396
+ else if (headers.Accept?.match(/application\/.*json/)) {
1397
1397
  // Validate that the response content type is at least similar to what we expect
1398
1398
  // (Provider's response Content-Type might be more specific, e.g. application/json;charset=utf-8)
1399
1399
  // Default to application/json if no Content-Type header is provided
1400
- if (responseContentType && !responseContentType.includes('application/json')) {
1400
+ if (responseContentType && !responseContentType.match(/application\/.*json/)) {
1401
1401
  const textResult = await response.text();
1402
1402
  throw this.handleError(500, `Unsupported content-type, expected 'application/json' but got '${responseContentType}'.
1403
1403
  Original response (${response.status}): "${textResult}"`, options);
@@ -1413,22 +1413,6 @@ 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
- }
1432
1416
  else {
1433
1417
  throw this.handleError(500, 'Unsupported Content-Type', options);
1434
1418
  }
@@ -111,7 +111,7 @@ export default class Integration {
111
111
  // Express Server initialization
112
112
  const app = express();
113
113
  // Parse query strings with https://github.com/ljharb/qs.
114
- app.set('query parser', 'extended');
114
+ app.set('query parser', 'simple');
115
115
  app.use(express.json());
116
116
  // Must be one of the first handlers (to catch all the errors).
117
117
  app.use(finishMiddleware);
@@ -286,11 +286,11 @@ export class Provider {
286
286
  // When we expect octet-stream, we accept any Content-Type the provider sends us, we just want to stream it
287
287
  body = response.body;
288
288
  }
289
- else if (headers.Accept === 'application/json') {
289
+ else if (headers.Accept?.match(/application\/.*json/)) {
290
290
  // Validate that the response content type is at least similar to what we expect
291
291
  // (Provider's response Content-Type might be more specific, e.g. application/json;charset=utf-8)
292
292
  // Default to application/json if no Content-Type header is provided
293
- if (responseContentType && !responseContentType.includes('application/json')) {
293
+ if (responseContentType && !responseContentType.match(/application\/.*json/)) {
294
294
  const textResult = await response.text();
295
295
  throw this.handleError(500, `Unsupported content-type, expected 'application/json' but got '${responseContentType}'.
296
296
  Original response (${response.status}): "${textResult}"`, options);
@@ -306,22 +306,6 @@ 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
- }
325
309
  else {
326
310
  throw this.handleError(500, 'Unsupported Content-Type', options);
327
311
  }
@@ -137,6 +137,35 @@ describe('Provider', () => {
137
137
  ]);
138
138
  assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
139
139
  });
140
+ it('should accept application/vnd.oracle.resource+json type response', async (context) => {
141
+ const response = new Response('{"data": "value"}', {
142
+ status: 200,
143
+ headers: { 'Content-Type': 'application/vnd.oracle.resource+json; type=collection; charset=UTF-8' },
144
+ });
145
+ const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
146
+ const actualResponse = await provider.get('/endpoint', {
147
+ credentials: { apiKey: 'apikey#1111' },
148
+ logger: logger,
149
+ signal: new AbortController().signal,
150
+ additionnalheaders: { 'X-Additional-Header': 'value1' },
151
+ });
152
+ assert.equal(fetchMock.mock.calls.length, 1);
153
+ assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
154
+ 'www.myApi.com/endpoint',
155
+ {
156
+ method: 'GET',
157
+ body: null,
158
+ signal: new AbortController().signal,
159
+ headers: {
160
+ Accept: 'application/json',
161
+ 'X-Custom-Provider-Header': 'value',
162
+ 'X-Provider-Credential-Header': 'apikey#1111',
163
+ 'X-Additional-Header': 'value1',
164
+ },
165
+ },
166
+ ]);
167
+ assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
168
+ });
140
169
  it('should return the raw response body if specified', async (context) => {
141
170
  const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
142
171
  status: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -124,7 +124,7 @@ export default class Integration {
124
124
  const app: express.Application = express();
125
125
 
126
126
  // Parse query strings with https://github.com/ljharb/qs.
127
- app.set('query parser', 'extended');
127
+ app.set('query parser', 'simple');
128
128
 
129
129
  app.use(express.json());
130
130
 
@@ -402,11 +402,11 @@ export class Provider {
402
402
  if (options.rawBody || headers.Accept === 'application/octet-stream') {
403
403
  // When we expect octet-stream, we accept any Content-Type the provider sends us, we just want to stream it
404
404
  body = response.body as T;
405
- } else if (headers.Accept === 'application/json') {
405
+ } else if (headers.Accept?.match(/application\/.*json/)) {
406
406
  // Validate that the response content type is at least similar to what we expect
407
407
  // (Provider's response Content-Type might be more specific, e.g. application/json;charset=utf-8)
408
408
  // Default to application/json if no Content-Type header is provided
409
- if (responseContentType && !responseContentType.includes('application/json')) {
409
+ if (responseContentType && !responseContentType.match(/application\/.*json/)) {
410
410
  const textResult = await response.text();
411
411
  throw this.handleError(
412
412
  500,
@@ -424,18 +424,6 @@ 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
- }
439
427
  } else {
440
428
  throw this.handleError(500, 'Unsupported Content-Type', options);
441
429
  }
@@ -164,6 +164,41 @@ describe('Provider', () => {
164
164
  assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
165
165
  });
166
166
 
167
+ it('should accept application/vnd.oracle.resource+json type response', async context => {
168
+ const response = new Response('{"data": "value"}', {
169
+ status: 200,
170
+ headers: { 'Content-Type': 'application/vnd.oracle.resource+json; type=collection; charset=UTF-8' },
171
+ });
172
+
173
+ const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
174
+
175
+ const actualResponse = await provider.get('/endpoint', {
176
+ credentials: { apiKey: 'apikey#1111' },
177
+ logger: logger,
178
+ signal: new AbortController().signal,
179
+ additionnalheaders: { 'X-Additional-Header': 'value1' },
180
+ });
181
+
182
+ assert.equal(fetchMock.mock.calls.length, 1);
183
+
184
+ assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
185
+ 'www.myApi.com/endpoint',
186
+ {
187
+ method: 'GET',
188
+ body: null,
189
+ signal: new AbortController().signal,
190
+ headers: {
191
+ Accept: 'application/json',
192
+ 'X-Custom-Provider-Header': 'value',
193
+ 'X-Provider-Credential-Header': 'apikey#1111',
194
+ 'X-Additional-Header': 'value1',
195
+ },
196
+ },
197
+ ]);
198
+
199
+ assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
200
+ });
201
+
167
202
  it('should return the raw response body if specified', async context => {
168
203
  const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
169
204
  status: 200,