@unito/integration-sdk 1.0.8 → 1.0.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
CHANGED
|
@@ -1098,7 +1098,13 @@ class Provider {
|
|
|
1098
1098
|
}
|
|
1099
1099
|
async fetchWrapper(endpoint, body, options) {
|
|
1100
1100
|
const { url: providerUrl, headers: providerHeaders } = this.prepareRequest(options);
|
|
1101
|
-
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
|
+
}
|
|
1102
1108
|
if (options.queryParams) {
|
|
1103
1109
|
absoluteUrl = `${absoluteUrl}?${new URLSearchParams(options.queryParams)}`;
|
|
1104
1110
|
}
|
|
@@ -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
|
@@ -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,
|