@unito/integration-sdk 1.0.7 → 1.0.9
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 +12 -1
- package/dist/src/integration.js +5 -0
- package/dist/src/resources/provider.js +7 -1
- package/dist/test/resources/provider.test.js +27 -0
- package/package.json +1 -1
- package/src/integration.ts +7 -0
- package/src/resources/provider.ts +7 -1
- package/test/resources/provider.test.ts +31 -0
package/dist/src/index.cjs
CHANGED
|
@@ -919,6 +919,11 @@ class Integration {
|
|
|
919
919
|
app.use(middleware$5);
|
|
920
920
|
app.use(middleware$4);
|
|
921
921
|
app.use(middleware$6);
|
|
922
|
+
// Making sure we log all incomming requests, prior to any processing.
|
|
923
|
+
app.use((req, res, next) => {
|
|
924
|
+
res.locals.logger.info(`Initializing request for ${req.originalUrl}`);
|
|
925
|
+
next();
|
|
926
|
+
});
|
|
922
927
|
// Load handlers as needed.
|
|
923
928
|
if (this.handlers.length) {
|
|
924
929
|
for (const handler of this.handlers) {
|
|
@@ -1093,7 +1098,13 @@ class Provider {
|
|
|
1093
1098
|
}
|
|
1094
1099
|
async fetchWrapper(endpoint, body, options) {
|
|
1095
1100
|
const { url: providerUrl, headers: providerHeaders } = this.prepareRequest(options);
|
|
1096
|
-
let absoluteUrl
|
|
1101
|
+
let absoluteUrl;
|
|
1102
|
+
if (/^https?:\/\//.test(endpoint)) {
|
|
1103
|
+
absoluteUrl = endpoint;
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
absoluteUrl = [providerUrl, endpoint.charAt(0) === '/' ? endpoint.substring(1) : endpoint].join('/');
|
|
1107
|
+
}
|
|
1097
1108
|
if (options.queryParams) {
|
|
1098
1109
|
absoluteUrl = `${absoluteUrl}?${new URLSearchParams(options.queryParams)}`;
|
|
1099
1110
|
}
|
package/dist/src/integration.js
CHANGED
|
@@ -120,6 +120,11 @@ export default class Integration {
|
|
|
120
120
|
app.use(secretsMiddleware);
|
|
121
121
|
app.use(selectsMiddleware);
|
|
122
122
|
app.use(signalMiddleware);
|
|
123
|
+
// Making sure we log all incomming requests, prior to any processing.
|
|
124
|
+
app.use((req, res, next) => {
|
|
125
|
+
res.locals.logger.info(`Initializing request for ${req.originalUrl}`);
|
|
126
|
+
next();
|
|
127
|
+
});
|
|
123
128
|
// Load handlers as needed.
|
|
124
129
|
if (this.handlers.length) {
|
|
125
130
|
for (const handler of this.handlers) {
|
|
@@ -150,7 +150,13 @@ export class Provider {
|
|
|
150
150
|
}
|
|
151
151
|
async fetchWrapper(endpoint, body, options) {
|
|
152
152
|
const { url: providerUrl, headers: providerHeaders } = this.prepareRequest(options);
|
|
153
|
-
let absoluteUrl
|
|
153
|
+
let absoluteUrl;
|
|
154
|
+
if (/^https?:\/\//.test(endpoint)) {
|
|
155
|
+
absoluteUrl = endpoint;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
absoluteUrl = [providerUrl, endpoint.charAt(0) === '/' ? endpoint.substring(1) : endpoint].join('/');
|
|
159
|
+
}
|
|
154
160
|
if (options.queryParams) {
|
|
155
161
|
absoluteUrl = `${absoluteUrl}?${new URLSearchParams(options.queryParams)}`;
|
|
156
162
|
}
|
|
@@ -50,6 +50,33 @@ describe('Provider', () => {
|
|
|
50
50
|
]);
|
|
51
51
|
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
52
52
|
});
|
|
53
|
+
it('gets an endpoint which is an absolute url', async (context) => {
|
|
54
|
+
const response = new Response('{"data": "value"}', {
|
|
55
|
+
status: 200,
|
|
56
|
+
headers: { 'Content-Type': 'application/json' },
|
|
57
|
+
});
|
|
58
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
59
|
+
const actualResponse = await provider.get('https://my-cdn.my-domain.com/file.png', {
|
|
60
|
+
credentials: { apiKey: 'apikey#1111' },
|
|
61
|
+
logger: logger,
|
|
62
|
+
signal: new AbortController().signal,
|
|
63
|
+
});
|
|
64
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
65
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
66
|
+
'https://my-cdn.my-domain.com/file.png',
|
|
67
|
+
{
|
|
68
|
+
method: 'GET',
|
|
69
|
+
body: null,
|
|
70
|
+
signal: new AbortController().signal,
|
|
71
|
+
headers: {
|
|
72
|
+
Accept: 'application/json',
|
|
73
|
+
'X-Custom-Provider-Header': 'value',
|
|
74
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
79
|
+
});
|
|
53
80
|
it('post with url encoded body', async (context) => {
|
|
54
81
|
const response = new Response('{"data": "value"}', {
|
|
55
82
|
status: 201,
|
package/package.json
CHANGED
package/src/integration.ts
CHANGED
|
@@ -137,6 +137,13 @@ export default class Integration {
|
|
|
137
137
|
app.use(selectsMiddleware);
|
|
138
138
|
app.use(signalMiddleware);
|
|
139
139
|
|
|
140
|
+
// Making sure we log all incomming requests, prior to any processing.
|
|
141
|
+
app.use((req, res, next) => {
|
|
142
|
+
res.locals.logger.info(`Initializing request for ${req.originalUrl}`);
|
|
143
|
+
|
|
144
|
+
next();
|
|
145
|
+
});
|
|
146
|
+
|
|
140
147
|
// Load handlers as needed.
|
|
141
148
|
if (this.handlers.length) {
|
|
142
149
|
for (const handler of this.handlers) {
|
|
@@ -224,7 +224,13 @@ export class Provider {
|
|
|
224
224
|
): Promise<Response<T>> {
|
|
225
225
|
const { url: providerUrl, headers: providerHeaders } = this.prepareRequest(options);
|
|
226
226
|
|
|
227
|
-
let absoluteUrl
|
|
227
|
+
let absoluteUrl;
|
|
228
|
+
|
|
229
|
+
if (/^https?:\/\//.test(endpoint)) {
|
|
230
|
+
absoluteUrl = endpoint;
|
|
231
|
+
} else {
|
|
232
|
+
absoluteUrl = [providerUrl, endpoint.charAt(0) === '/' ? endpoint.substring(1) : endpoint].join('/');
|
|
233
|
+
}
|
|
228
234
|
|
|
229
235
|
if (options.queryParams) {
|
|
230
236
|
absoluteUrl = `${absoluteUrl}?${new URLSearchParams(options.queryParams)}`;
|
|
@@ -59,6 +59,37 @@ describe('Provider', () => {
|
|
|
59
59
|
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
it('gets an endpoint which is an absolute url', async context => {
|
|
63
|
+
const response = new Response('{"data": "value"}', {
|
|
64
|
+
status: 200,
|
|
65
|
+
headers: { 'Content-Type': 'application/json' },
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const fetchMock = context.mock.method(global, 'fetch', () => Promise.resolve(response));
|
|
69
|
+
|
|
70
|
+
const actualResponse = await provider.get('https://my-cdn.my-domain.com/file.png', {
|
|
71
|
+
credentials: { apiKey: 'apikey#1111' },
|
|
72
|
+
logger: logger,
|
|
73
|
+
signal: new AbortController().signal,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
assert.equal(fetchMock.mock.calls.length, 1);
|
|
77
|
+
assert.deepEqual(fetchMock.mock.calls[0]?.arguments, [
|
|
78
|
+
'https://my-cdn.my-domain.com/file.png',
|
|
79
|
+
{
|
|
80
|
+
method: 'GET',
|
|
81
|
+
body: null,
|
|
82
|
+
signal: new AbortController().signal,
|
|
83
|
+
headers: {
|
|
84
|
+
Accept: 'application/json',
|
|
85
|
+
'X-Custom-Provider-Header': 'value',
|
|
86
|
+
'X-Provider-Credential-Header': 'apikey#1111',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
]);
|
|
90
|
+
assert.deepEqual(actualResponse, { status: 200, headers: response.headers, body: { data: 'value' } });
|
|
91
|
+
});
|
|
92
|
+
|
|
62
93
|
it('post with url encoded body', async context => {
|
|
63
94
|
const response = new Response('{"data": "value"}', {
|
|
64
95
|
status: 201,
|