@wise/dynamic-flow-client 3.11.2-experimental-7d4fc19 → 3.11.2-experimental-26093dd
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.
|
@@ -14,21 +14,18 @@ export var makeHttpClient = function (baseUrl, additionalHeaders) {
|
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
15
15
|
return function (input, init) {
|
|
16
16
|
var resource = applyBaseUrl(input, baseUrl || '');
|
|
17
|
-
|
|
18
|
-
var requestHeaders = requestInit.headers;
|
|
19
|
-
return fetch(resource, requestInit).then(function (response) {
|
|
20
|
-
if (response.status === 415) {
|
|
21
|
-
// eslint-disable-next-line no-console
|
|
22
|
-
console.warn("DF request to ".concat(String(resource), " failed with status 415. Request headers: ").concat(stringifyHeadersInit(requestHeaders)));
|
|
23
|
-
}
|
|
24
|
-
return response;
|
|
25
|
-
});
|
|
17
|
+
return fetch(resource, mergeRequestInit(init !== null && init !== void 0 ? init : {}, { headers: additionalHeaders }));
|
|
26
18
|
};
|
|
27
19
|
};
|
|
28
20
|
var applyBaseUrl = function (input, baseUrl) {
|
|
29
21
|
return typeof input === 'string' && isRelativePath(input) ? baseUrl + input : input;
|
|
30
22
|
};
|
|
31
|
-
export var mergeRequestInit = function (init, additionalInit) { return (__assign(__assign(__assign({}, init), additionalInit), {
|
|
23
|
+
export var mergeRequestInit = function (init, additionalInit) { return (__assign(__assign(__assign({}, init), additionalInit), {
|
|
24
|
+
// initHeaders takes priority over additionalHeaders, so must come last!
|
|
25
|
+
// DF Core knows what content-type it's requesting (often JSON, sometimes images)
|
|
26
|
+
// so we should trust the init headers instead of the additionalInit headers from
|
|
27
|
+
// when the httpClient is created.
|
|
28
|
+
headers: mergeHeaders(additionalInit === null || additionalInit === void 0 ? void 0 : additionalInit.headers, init === null || init === void 0 ? void 0 : init.headers) })); };
|
|
32
29
|
var mergeHeaders = function () {
|
|
33
30
|
var headersInits = [];
|
|
34
31
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -36,19 +33,3 @@ var mergeHeaders = function () {
|
|
|
36
33
|
}
|
|
37
34
|
return headersInits.reduce(function (acc, headers) { return (__assign(__assign({}, acc), Object.fromEntries(new Headers(headers).entries()))); }, {});
|
|
38
35
|
};
|
|
39
|
-
var stringifyHeadersInit = function (headersInit) {
|
|
40
|
-
if (headersInit === undefined) {
|
|
41
|
-
return 'undefined';
|
|
42
|
-
}
|
|
43
|
-
if (headersInit === null) {
|
|
44
|
-
return 'null';
|
|
45
|
-
}
|
|
46
|
-
if (headersInit instanceof Headers) {
|
|
47
|
-
var entries = Array.from(headersInit.entries());
|
|
48
|
-
return "(Headers instance) ".concat(JSON.stringify(entries));
|
|
49
|
-
}
|
|
50
|
-
if (Array.isArray(headersInit)) {
|
|
51
|
-
return "(Array) ".concat(JSON.stringify(headersInit));
|
|
52
|
-
}
|
|
53
|
-
return "(Object) ".concat(JSON.stringify(headersInit));
|
|
54
|
-
};
|
|
@@ -4,7 +4,7 @@ describe('makeHttpClient', function () {
|
|
|
4
4
|
var spyFetch;
|
|
5
5
|
beforeEach(function () {
|
|
6
6
|
originalFetch = global.fetch;
|
|
7
|
-
spyFetch = jest.spyOn(global, 'fetch').
|
|
7
|
+
spyFetch = jest.spyOn(global, 'fetch').mockImplementation();
|
|
8
8
|
});
|
|
9
9
|
afterEach(function () {
|
|
10
10
|
global.fetch = originalFetch;
|
|
@@ -125,6 +125,32 @@ describe('mergeRequestInit', function () {
|
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
|
+
it('merges the two objects and the headers, prioritising the init headers in case they match', function () {
|
|
129
|
+
var result = mergeRequestInit({ headers: { 'Content-Type': 'application/json' } }, { headers: { 'Content-Type': 'application/json,application/json' } });
|
|
130
|
+
expect(result.headers).toMatchObject({
|
|
131
|
+
'content-type': 'application/json',
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe('when called with RequestInits with Headers instances', function () {
|
|
135
|
+
it('merges the two objects and the headers, prioritising the init headers in case they match', function () {
|
|
136
|
+
var result = mergeRequestInit({ headers: new Headers([['Content-Type', 'application/json']]) }, {
|
|
137
|
+
headers: new Headers([['Content-Type', 'application/json,application/json']]),
|
|
138
|
+
});
|
|
139
|
+
expect(result.headers).toMatchObject({
|
|
140
|
+
'content-type': 'application/json',
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe('when called with RequestInits with Array headers', function () {
|
|
145
|
+
it('merges the two objects and the headers, prioritising the init headers in case they match', function () {
|
|
146
|
+
var result = mergeRequestInit({ headers: [['Content-Type', 'application/json']] }, {
|
|
147
|
+
headers: [['Content-Type', 'application/json,application/json']],
|
|
148
|
+
});
|
|
149
|
+
expect(result.headers).toMatchObject({
|
|
150
|
+
'content-type': 'application/json',
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
128
154
|
describe('when called with undefined as a first argument', function () {
|
|
129
155
|
it('returns the second argument and empty headers', function () {
|
|
130
156
|
var result = mergeRequestInit(undefined, { method: 'POST' });
|
|
@@ -88,7 +88,7 @@ var DynamicFlowComponent = function (_a) {
|
|
|
88
88
|
var url = action.url, _b = action.method, method = _b === void 0 ? 'POST' : _b;
|
|
89
89
|
return httpClient(url !== null && url !== void 0 ? url : '', {
|
|
90
90
|
method: method,
|
|
91
|
-
headers: __assign({}, (etag ? { 'If-None-Match': etag } : {})),
|
|
91
|
+
headers: __assign({ 'Content-Type': 'application/json' }, (etag ? { 'If-None-Match': etag } : {})),
|
|
92
92
|
body: method === 'GET' ? undefined : JSON.stringify(data),
|
|
93
93
|
});
|
|
94
94
|
}, [httpClient]);
|
package/build/main.js
CHANGED
|
@@ -312,42 +312,21 @@ var makeHttpClient = (baseUrl, additionalHeaders) => (
|
|
|
312
312
|
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
313
313
|
(input, init) => {
|
|
314
314
|
const resource = applyBaseUrl(input, baseUrl || "");
|
|
315
|
-
|
|
316
|
-
const requestHeaders = requestInit.headers;
|
|
317
|
-
return fetch(resource, requestInit).then((response) => {
|
|
318
|
-
if (response.status === 415) {
|
|
319
|
-
console.warn(
|
|
320
|
-
`DF request to ${String(resource)} failed with status 415. Request headers: ${stringifyHeadersInit(requestHeaders)}`
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
return response;
|
|
324
|
-
});
|
|
315
|
+
return fetch(resource, mergeRequestInit(init != null ? init : {}, { headers: additionalHeaders }));
|
|
325
316
|
}
|
|
326
317
|
);
|
|
327
318
|
var applyBaseUrl = (input, baseUrl) => typeof input === "string" && isRelativePath(input) ? baseUrl + input : input;
|
|
328
319
|
var mergeRequestInit = (init, additionalInit) => __spreadProps(__spreadValues(__spreadValues({}, init), additionalInit), {
|
|
329
|
-
|
|
320
|
+
// initHeaders takes priority over additionalHeaders, so must come last!
|
|
321
|
+
// DF Core knows what content-type it's requesting (often JSON, sometimes images)
|
|
322
|
+
// so we should trust the init headers instead of the additionalInit headers from
|
|
323
|
+
// when the httpClient is created.
|
|
324
|
+
headers: mergeHeaders(additionalInit == null ? void 0 : additionalInit.headers, init == null ? void 0 : init.headers)
|
|
330
325
|
});
|
|
331
326
|
var mergeHeaders = (...headersInits) => headersInits.reduce(
|
|
332
327
|
(acc, headers2) => __spreadValues(__spreadValues({}, acc), Object.fromEntries(new Headers(headers2).entries())),
|
|
333
328
|
{}
|
|
334
329
|
);
|
|
335
|
-
var stringifyHeadersInit = (headersInit) => {
|
|
336
|
-
if (headersInit === void 0) {
|
|
337
|
-
return "undefined";
|
|
338
|
-
}
|
|
339
|
-
if (headersInit === null) {
|
|
340
|
-
return "null";
|
|
341
|
-
}
|
|
342
|
-
if (headersInit instanceof Headers) {
|
|
343
|
-
const entries = Array.from(headersInit.entries());
|
|
344
|
-
return `(Headers instance) ${JSON.stringify(entries)}`;
|
|
345
|
-
}
|
|
346
|
-
if (Array.isArray(headersInit)) {
|
|
347
|
-
return `(Array) ${JSON.stringify(headersInit)}`;
|
|
348
|
-
}
|
|
349
|
-
return `(Object) ${JSON.stringify(headersInit)}`;
|
|
350
|
-
};
|
|
351
330
|
|
|
352
331
|
// src/i18n/de.json
|
|
353
332
|
var de_default = {
|
|
@@ -19051,7 +19030,9 @@ var DynamicFlowComponent = ({
|
|
|
19051
19030
|
const { url, method = "POST" } = action;
|
|
19052
19031
|
return httpClient(url != null ? url : "", {
|
|
19053
19032
|
method,
|
|
19054
|
-
headers: __spreadValues({
|
|
19033
|
+
headers: __spreadValues({
|
|
19034
|
+
"Content-Type": "application/json"
|
|
19035
|
+
}, etag2 ? { "If-None-Match": etag2 } : {}),
|
|
19055
19036
|
body: method === "GET" ? void 0 : JSON.stringify(data)
|
|
19056
19037
|
});
|
|
19057
19038
|
},
|