@unito/integration-sdk 2.3.8 → 2.3.10
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 +4 -1
- package/dist/src/integration.js +1 -1
- package/dist/src/resources/provider.js +3 -0
- package/dist/test/resources/provider.test.js +27 -0
- package/package.json +1 -1
- package/src/integration.ts +2 -2
- package/src/resources/provider.ts +2 -0
- package/test/resources/provider.test.ts +31 -0
package/dist/src/index.cjs
CHANGED
|
@@ -1152,9 +1152,9 @@ class Integration {
|
|
|
1152
1152
|
const app = express();
|
|
1153
1153
|
// Parse query strings with https://github.com/ljharb/qs.
|
|
1154
1154
|
app.set('query parser', 'simple');
|
|
1155
|
-
app.use(express.json());
|
|
1156
1155
|
// Must be one of the first handlers (to catch all the errors).
|
|
1157
1156
|
app.use(onFinish);
|
|
1157
|
+
app.use(express.json({ limit: '1mb', type: 'application/json' }));
|
|
1158
1158
|
// Instantiate internal middlewares.
|
|
1159
1159
|
app.use(start);
|
|
1160
1160
|
app.use(extractCorrelationId);
|
|
@@ -1471,6 +1471,9 @@ class Provider {
|
|
|
1471
1471
|
if (/^https?:\/\//.test(endpoint)) {
|
|
1472
1472
|
absoluteUrl = endpoint;
|
|
1473
1473
|
}
|
|
1474
|
+
else if (endpoint === '') {
|
|
1475
|
+
absoluteUrl = providerUrl;
|
|
1476
|
+
}
|
|
1474
1477
|
else {
|
|
1475
1478
|
absoluteUrl = [providerUrl, endpoint.charAt(0) === '/' ? endpoint.substring(1) : endpoint].join('/');
|
|
1476
1479
|
}
|
package/dist/src/integration.js
CHANGED
|
@@ -114,9 +114,9 @@ export default class Integration {
|
|
|
114
114
|
const app = express();
|
|
115
115
|
// Parse query strings with https://github.com/ljharb/qs.
|
|
116
116
|
app.set('query parser', 'simple');
|
|
117
|
-
app.use(express.json());
|
|
118
117
|
// Must be one of the first handlers (to catch all the errors).
|
|
119
118
|
app.use(finishMiddleware);
|
|
119
|
+
app.use(express.json({ limit: '1mb', type: 'application/json' }));
|
|
120
120
|
// Instantiate internal middlewares.
|
|
121
121
|
app.use(startMiddleware);
|
|
122
122
|
app.use(correlationIdMiddleware);
|
|
@@ -260,6 +260,9 @@ export class Provider {
|
|
|
260
260
|
if (/^https?:\/\//.test(endpoint)) {
|
|
261
261
|
absoluteUrl = endpoint;
|
|
262
262
|
}
|
|
263
|
+
else if (endpoint === '') {
|
|
264
|
+
absoluteUrl = providerUrl;
|
|
265
|
+
}
|
|
263
266
|
else {
|
|
264
267
|
absoluteUrl = [providerUrl, endpoint.charAt(0) === '/' ? endpoint.substring(1) : endpoint].join('/');
|
|
265
268
|
}
|
|
@@ -212,6 +212,33 @@ describe('Provider', () => {
|
|
|
212
212
|
]);
|
|
213
213
|
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
214
214
|
});
|
|
215
|
+
it('gets on provider url', async (context) => {
|
|
216
|
+
const response = new Response('{"data": "value"}', {
|
|
217
|
+
status: 200,
|
|
218
|
+
headers: { 'Content-Type': 'application/json' },
|
|
219
|
+
});
|
|
220
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
221
|
+
const actualResponse = await provider.get('', {
|
|
222
|
+
credentials: { apiKey: 'apikey#1111', unitoCredentialId: '123' },
|
|
223
|
+
logger: logger,
|
|
224
|
+
signal: new AbortController().signal,
|
|
225
|
+
});
|
|
226
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
227
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
228
|
+
'www.myApi.com',
|
|
229
|
+
{
|
|
230
|
+
method: 'GET',
|
|
231
|
+
body: null,
|
|
232
|
+
signal: new AbortController().signal,
|
|
233
|
+
headers: {
|
|
234
|
+
Accept: 'application/json',
|
|
235
|
+
'X-Custom-Provider-Header': 'value',
|
|
236
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
]);
|
|
240
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
241
|
+
});
|
|
215
242
|
it('post with url encoded body', async (context) => {
|
|
216
243
|
const response = new Response('{"data": "value"}', {
|
|
217
244
|
status: 201,
|
package/package.json
CHANGED
package/src/integration.ts
CHANGED
|
@@ -128,11 +128,11 @@ export default class Integration {
|
|
|
128
128
|
// Parse query strings with https://github.com/ljharb/qs.
|
|
129
129
|
app.set('query parser', 'simple');
|
|
130
130
|
|
|
131
|
-
app.use(express.json());
|
|
132
|
-
|
|
133
131
|
// Must be one of the first handlers (to catch all the errors).
|
|
134
132
|
app.use(finishMiddleware);
|
|
135
133
|
|
|
134
|
+
app.use(express.json({ limit: '1mb', type: 'application/json' }));
|
|
135
|
+
|
|
136
136
|
// Instantiate internal middlewares.
|
|
137
137
|
app.use(startMiddleware);
|
|
138
138
|
app.use(correlationIdMiddleware);
|
|
@@ -362,6 +362,8 @@ export class Provider {
|
|
|
362
362
|
|
|
363
363
|
if (/^https?:\/\//.test(endpoint)) {
|
|
364
364
|
absoluteUrl = endpoint;
|
|
365
|
+
} else if (endpoint === '') {
|
|
366
|
+
absoluteUrl = providerUrl;
|
|
365
367
|
} else {
|
|
366
368
|
absoluteUrl = [providerUrl, endpoint.charAt(0) === '/' ? endpoint.substring(1) : endpoint].join('/');
|
|
367
369
|
}
|
|
@@ -253,6 +253,37 @@ describe('Provider', () => {
|
|
|
253
253
|
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
+
it('gets on provider url', async context => {
|
|
257
|
+
const response = new Response('{"data": "value"}', {
|
|
258
|
+
status: 200,
|
|
259
|
+
headers: { 'Content-Type': 'application/json' },
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
263
|
+
|
|
264
|
+
const actualResponse = await provider.get('', {
|
|
265
|
+
credentials: { apiKey: 'apikey#1111', unitoCredentialId: '123' },
|
|
266
|
+
logger: logger,
|
|
267
|
+
signal: new AbortController().signal,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
271
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
272
|
+
'www.myApi.com',
|
|
273
|
+
{
|
|
274
|
+
method: 'GET',
|
|
275
|
+
body: null,
|
|
276
|
+
signal: new AbortController().signal,
|
|
277
|
+
headers: {
|
|
278
|
+
Accept: 'application/json',
|
|
279
|
+
'X-Custom-Provider-Header': 'value',
|
|
280
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
]);
|
|
284
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
285
|
+
});
|
|
286
|
+
|
|
256
287
|
it('post with url encoded body', async context => {
|
|
257
288
|
const response = new Response('{"data": "value"}', {
|
|
258
289
|
status: 201,
|