@unito/integration-sdk 1.7.0 → 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.
@@ -1421,6 +1421,14 @@ class Provider {
1421
1421
  throw this.handleError(500, `Invalid JSON schema response`, options);
1422
1422
  }
1423
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
+ }
1424
1432
  else {
1425
1433
  throw this.handleError(500, 'Unsupported Content-Type', options);
1426
1434
  }
@@ -314,6 +314,14 @@ export class Provider {
314
314
  throw this.handleError(500, `Invalid JSON schema response`, options);
315
315
  }
316
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
+ }
317
325
  else {
318
326
  throw this.handleError(500, 'Unsupported Content-Type', options);
319
327
  }
@@ -108,6 +108,35 @@ describe('Provider', () => {
108
108
  ]);
109
109
  assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
110
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
+ });
111
140
  it('should return the raw response body if specified', async (context) => {
112
141
  const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
113
142
  status: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unito/integration-sdk",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Integration SDK",
5
5
  "type": "module",
6
6
  "types": "dist/src/index.d.ts",
@@ -430,6 +430,12 @@ export class Provider {
430
430
  } catch (err) {
431
431
  throw this.handleError(500, `Invalid JSON schema response`, options);
432
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
+ }
433
439
  } else {
434
440
  throw this.handleError(500, 'Unsupported Content-Type', options);
435
441
  }
@@ -129,6 +129,41 @@ describe('Provider', () => {
129
129
  assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
130
130
  });
131
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
+
132
167
  it('should return the raw response body if specified', async context => {
133
168
  const response = new Response(`IMAGINE A HUGE PAYLOAD`, {
134
169
  status: 200,