@unito/integration-sdk 1.1.4 → 1.2.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.
@@ -1395,6 +1395,10 @@ class Provider {
1395
1395
  // When we expect octet-stream, we accept any Content-Type the provider sends us, we just want to stream it.
1396
1396
  body = response.body;
1397
1397
  }
1398
+ else if (headers.Accept?.includes('text/html')) {
1399
+ // Accept text based content types
1400
+ body = (await response.text());
1401
+ }
1398
1402
  else {
1399
1403
  throw this.handleError(500, 'Unsupported Content-Type');
1400
1404
  }
@@ -296,6 +296,10 @@ export class Provider {
296
296
  // When we expect octet-stream, we accept any Content-Type the provider sends us, we just want to stream it.
297
297
  body = response.body;
298
298
  }
299
+ else if (headers.Accept?.includes('text/html')) {
300
+ // Accept text based content types
301
+ body = (await response.text());
302
+ }
299
303
  else {
300
304
  throw this.handleError(500, 'Unsupported Content-Type');
301
305
  }
@@ -50,6 +50,35 @@ describe('Provider', () => {
50
50
  ]);
51
51
  assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
52
52
  });
53
+ it('should accept text/html type response', async (context) => {
54
+ const response = new Response('', {
55
+ status: 200,
56
+ headers: { 'Content-Type': 'text/html; charset=UTF-8' },
57
+ });
58
+ const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
59
+ const actualResponse = await provider.get('/endpoint', {
60
+ credentials: { apiKey: 'apikey#1111' },
61
+ logger: logger,
62
+ signal: new AbortController().signal,
63
+ additionnalheaders: { 'X-Additional-Header': 'value1', Accept: 'text/html; charset=UTF-8' },
64
+ });
65
+ assert.equal(fetchMock.mock.calls.length, 1);
66
+ assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
67
+ 'www.myApi.com/endpoint',
68
+ {
69
+ method: 'GET',
70
+ body: null,
71
+ signal: new AbortController().signal,
72
+ headers: {
73
+ Accept: 'text/html; charset=UTF-8',
74
+ 'X-Custom-Provider-Header': 'value',
75
+ 'X-Provider-Credential-Header': 'apikey#1111',
76
+ 'X-Additional-Header': 'value1',
77
+ },
78
+ },
79
+ ]);
80
+ assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: '' });
81
+ });
53
82
  it('gets an endpoint which is an absolute url', async (context) => {
54
83
  const response = new Response('{"data": "value"}', {
55
84
  status: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -400,6 +400,9 @@ export class Provider {
400
400
  } else if (headers.Accept == 'application/octet-stream') {
401
401
  // When we expect octet-stream, we accept any Content-Type the provider sends us, we just want to stream it.
402
402
  body = response.body as T;
403
+ } else if (headers.Accept?.includes('text/html')) {
404
+ // Accept text based content types
405
+ body = (await response.text()) as T;
403
406
  } else {
404
407
  throw this.handleError(500, 'Unsupported Content-Type');
405
408
  }
@@ -59,6 +59,41 @@ describe('Provider', () => {
59
59
  assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
60
60
  });
61
61
 
62
+ it('should accept text/html type response', async context => {
63
+ const response = new Response('', {
64
+ status: 200,
65
+ headers: { 'Content-Type': 'text/html; charset=UTF-8' },
66
+ });
67
+
68
+ const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
69
+
70
+ const actualResponse = await provider.get('/endpoint', {
71
+ credentials: { apiKey: 'apikey#1111' },
72
+ logger: logger,
73
+ signal: new AbortController().signal,
74
+ additionnalheaders: { 'X-Additional-Header': 'value1', Accept: 'text/html; charset=UTF-8' },
75
+ });
76
+
77
+ assert.equal(fetchMock.mock.calls.length, 1);
78
+
79
+ assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
80
+ 'www.myApi.com/endpoint',
81
+ {
82
+ method: 'GET',
83
+ body: null,
84
+ signal: new AbortController().signal,
85
+ headers: {
86
+ Accept: 'text/html; charset=UTF-8',
87
+ 'X-Custom-Provider-Header': 'value',
88
+ 'X-Provider-Credential-Header': 'apikey#1111',
89
+ 'X-Additional-Header': 'value1',
90
+ },
91
+ },
92
+ ]);
93
+
94
+ assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: '' });
95
+ });
96
+
62
97
  it('gets an endpoint which is an absolute url', async context => {
63
98
  const response = new Response('{"data": "value"}', {
64
99
  status: 200,