@unito/integration-sdk 1.6.1 → 1.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.
@@ -1413,6 +1413,14 @@ 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
+ }
1416
1424
  else {
1417
1425
  throw this.handleError(500, 'Unsupported Content-Type', options);
1418
1426
  }
@@ -306,6 +306,14 @@ 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
+ }
309
317
  else {
310
318
  throw this.handleError(500, 'Unsupported Content-Type', options);
311
319
  }
@@ -79,6 +79,35 @@ 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
+ });
82
111
  it('should return the raw response body if specified', async (context) => {
83
112
  const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
84
113
  status: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -424,6 +424,12 @@ 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
+ }
427
433
  } else {
428
434
  throw this.handleError(500, 'Unsupported Content-Type', options);
429
435
  }
@@ -94,6 +94,41 @@ 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
+
97
132
  it('should return the raw response body if specified', async context => {
98
133
  const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
99
134
  status: 200,