@wise/dynamic-flow-client-internal 3.15.2 → 3.15.3-experimental-9ab778d
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/build/dynamicFlow/DynamicFlow.js +104 -0
- package/build/dynamicFlow/DynamicFlow.test.js +116 -0
- package/build/i18n/index.js +62 -0
- package/build/index.js +5 -0
- package/build/main.min.js +1 -1
- package/build/stories/DynamicFlow.story.js +52 -0
- package/build/stories/DynamicFragment.story.js +132 -0
- package/build/stories/Editable.story.js +70 -0
- package/build/stories/Examples.story.js +29 -0
- package/build/stories/Features.story.js +33 -0
- package/build/stories/utils/DynamicFlowSideBySide.js +30 -0
- package/build/stories/utils/fixtureHttpClient.js +119 -0
- package/build/stories/visual-tests/generated.story.js +216 -0
- package/build/stories/visual-tests/layouts.story.js +108 -0
- package/build/stories/visual-tests/schemas.story.js +84 -0
- package/build/stories/visual-tests/step.story.js +30 -0
- package/build/test-utils/NeptuneProviders.js +23 -0
- package/build/test-utils/rtl-utils.js +20 -0
- package/build/tests/renderers/RadioInputRendererComponent.test.js +76 -0
- package/build/tests/renderers/value-utils.test.js +33 -0
- package/build/types/stories/visual-tests/generated.story.d.ts +39 -0
- package/build/types/stories/visual-tests/layouts.story.d.ts +21 -0
- package/build/types/stories/visual-tests/schemas.story.d.ts +17 -0
- package/build/types/stories/visual-tests/step.story.d.ts +8 -0
- package/package.json +4 -4
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
+
if (ar || !(i in from)) {
|
|
51
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
+
ar[i] = from[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
+
};
|
|
57
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
58
|
+
import { forwardRef, useCallback, useMemo } from 'react';
|
|
59
|
+
import { useIntl } from 'react-intl';
|
|
60
|
+
import { DynamicFlow as DynamicFlowCoreLegacy, DynamicFlowCoreRevamp, DynamicFragmentCore, } from '@wise/dynamic-flow-client';
|
|
61
|
+
import { RendererHttpClientProvider, getWiseRenderers } from '@wise/dynamic-flow-renderers';
|
|
62
|
+
var wiseRenderers = getWiseRenderers();
|
|
63
|
+
export function DynamicFlowLegacy(props) {
|
|
64
|
+
var _a = props.customFetch, customFetch = _a === void 0 ? globalThis.fetch : _a;
|
|
65
|
+
var coreProps = __assign(__assign({}, props), { httpClient: customFetch });
|
|
66
|
+
return _jsx(DynamicFlowCoreLegacy, __assign({}, coreProps));
|
|
67
|
+
}
|
|
68
|
+
export function DynamicFlowRevamp(props) {
|
|
69
|
+
var _a = props.customFetch, customFetch = _a === void 0 ? globalThis.fetch : _a, renderers = props.renderers;
|
|
70
|
+
var httpClient = useWiseHttpClient(customFetch);
|
|
71
|
+
var mergedRenderers = useMemo(function () { return __spreadArray(__spreadArray([], (renderers !== null && renderers !== void 0 ? renderers : []), true), wiseRenderers, true); }, [renderers]);
|
|
72
|
+
var coreProps = __assign(__assign({}, props), { httpClient: httpClient, renderers: mergedRenderers });
|
|
73
|
+
return (_jsx(RendererHttpClientProvider, { httpClient: httpClient, children: _jsx(DynamicFlowCoreRevamp, __assign({}, coreProps)) }));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* DynamicFragment is like DynamicFlowRevamp, but it also accepts a ForwardedRef.
|
|
77
|
+
* This ref conforms to the DynamicFragmentController type, containing two functions: `getValue` and `validate`.
|
|
78
|
+
* @experimental This component may be changed in the future without notice.
|
|
79
|
+
*/
|
|
80
|
+
export var DynamicFragment = forwardRef(function DynamicFragment(props, ref) {
|
|
81
|
+
var _a = props.customFetch, customFetch = _a === void 0 ? globalThis.fetch : _a, renderers = props.renderers;
|
|
82
|
+
var httpClient = useWiseHttpClient(customFetch);
|
|
83
|
+
var mergedRenderers = useMemo(function () { return __spreadArray(__spreadArray([], (renderers !== null && renderers !== void 0 ? renderers : []), true), wiseRenderers, true); }, [renderers]);
|
|
84
|
+
var coreProps = __assign(__assign({}, props), { httpClient: httpClient, renderers: mergedRenderers });
|
|
85
|
+
return (_jsx(RendererHttpClientProvider, { httpClient: httpClient, children: _jsx(DynamicFragmentCore, __assign({}, coreProps, { ref: ref })) }));
|
|
86
|
+
});
|
|
87
|
+
var useWiseHttpClient = function (httpClient) {
|
|
88
|
+
var locale = useIntl().locale;
|
|
89
|
+
return useCallback(function (input_1) {
|
|
90
|
+
var args_1 = [];
|
|
91
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
92
|
+
args_1[_i - 1] = arguments[_i];
|
|
93
|
+
}
|
|
94
|
+
return __awaiter(void 0, __spreadArray([input_1], args_1, true), void 0, function (input, init) {
|
|
95
|
+
var headers;
|
|
96
|
+
if (init === void 0) { init = {}; }
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
headers = new Headers(init.headers);
|
|
99
|
+
headers.set('accept-language', locale);
|
|
100
|
+
return [2 /*return*/, httpClient(input, __assign(__assign({}, init), { credentials: 'include', headers: headers }))];
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}, [httpClient, locale]);
|
|
104
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
49
|
+
import { waitFor } from '@testing-library/react';
|
|
50
|
+
import { renderWithProviders } from '../test-utils/rtl-utils';
|
|
51
|
+
import { DynamicFlowLegacy, DynamicFlowRevamp, DynamicFragment } from './DynamicFlow';
|
|
52
|
+
describe.each([
|
|
53
|
+
{ name: 'DynamicFlowLegacy', DFComponent: DynamicFlowLegacy },
|
|
54
|
+
{ name: 'DynamicFlowRevamp', DFComponent: DynamicFlowRevamp },
|
|
55
|
+
{ name: 'DynamicFragment', DFComponent: DynamicFragment },
|
|
56
|
+
])('Wise-Specific Headers', function (_a) {
|
|
57
|
+
var name = _a.name, DFComponent = _a.DFComponent;
|
|
58
|
+
it("".concat(name, " - makes an initial request with additional RequestInit parameters, as specified in the wise-specific fetcher"), function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
+
var props, customFetch, requestInit, credentials, headers;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
props = {
|
|
64
|
+
flowId: 'test',
|
|
65
|
+
initialAction: { url: '/initial' },
|
|
66
|
+
onCompletion: jest.fn(),
|
|
67
|
+
onError: jest.fn(),
|
|
68
|
+
};
|
|
69
|
+
customFetch = jest.fn();
|
|
70
|
+
renderWithProviders(_jsx(DFComponent, __assign({}, props, { customFetch: customFetch })));
|
|
71
|
+
return [4 /*yield*/, waitFor(function () {
|
|
72
|
+
expect(customFetch).toHaveBeenCalledWith('/initial', expect.anything());
|
|
73
|
+
})];
|
|
74
|
+
case 1:
|
|
75
|
+
_a.sent();
|
|
76
|
+
requestInit = customFetch.mock.calls[0][1];
|
|
77
|
+
credentials = requestInit === null || requestInit === void 0 ? void 0 : requestInit.credentials;
|
|
78
|
+
expect(credentials).toBe('include');
|
|
79
|
+
headers = Array.from(new Headers(requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers).entries());
|
|
80
|
+
expect(headers).toContainEqual(['accept-language', 'en-GB']);
|
|
81
|
+
expect(headers).toContainEqual(['content-type', 'application/json']);
|
|
82
|
+
return [2 /*return*/];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}); });
|
|
86
|
+
});
|
|
87
|
+
describe('DynamicFlowLegacy', function () {
|
|
88
|
+
describe('when initialised with customFetch', function () {
|
|
89
|
+
it('uses the "correct" casing of Content-Type header', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
+
var props, customFetch, requestInit;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
props = {
|
|
95
|
+
flowId: 'test',
|
|
96
|
+
initialAction: { url: '/initial' },
|
|
97
|
+
onCompletion: jest.fn(),
|
|
98
|
+
onError: jest.fn(),
|
|
99
|
+
};
|
|
100
|
+
customFetch = jest.fn();
|
|
101
|
+
renderWithProviders(_jsx(DynamicFlowLegacy, __assign({}, props, { customFetch: customFetch })));
|
|
102
|
+
return [4 /*yield*/, waitFor(function () {
|
|
103
|
+
expect(customFetch).toHaveBeenCalledWith('/initial', expect.anything());
|
|
104
|
+
})];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
requestInit = customFetch.mock.calls[0][1];
|
|
108
|
+
expect(requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers).toMatchObject({
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
});
|
|
111
|
+
return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}); });
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { translations as coreTranslations } from '@wise/dynamic-flow-client';
|
|
22
|
+
import de from './de.json';
|
|
23
|
+
import en from './en.json';
|
|
24
|
+
import es from './es.json';
|
|
25
|
+
import fr from './fr.json';
|
|
26
|
+
import hu from './hu.json';
|
|
27
|
+
import id from './id.json';
|
|
28
|
+
import it from './it.json';
|
|
29
|
+
import ja from './ja.json';
|
|
30
|
+
import pl from './pl.json';
|
|
31
|
+
import pt from './pt.json';
|
|
32
|
+
import ro from './ro.json';
|
|
33
|
+
import ru from './ru.json';
|
|
34
|
+
import th from './th.json';
|
|
35
|
+
import tr from './tr.json';
|
|
36
|
+
import zhCN from './zh_CN.json';
|
|
37
|
+
import zhHK from './zh_HK.json';
|
|
38
|
+
var wiseTranslations = {
|
|
39
|
+
en: en,
|
|
40
|
+
de: de,
|
|
41
|
+
es: es,
|
|
42
|
+
fr: fr,
|
|
43
|
+
hu: hu,
|
|
44
|
+
id: id,
|
|
45
|
+
it: it,
|
|
46
|
+
ja: ja,
|
|
47
|
+
pl: pl,
|
|
48
|
+
pt: pt,
|
|
49
|
+
ro: ro,
|
|
50
|
+
ru: ru,
|
|
51
|
+
th: th,
|
|
52
|
+
tr: tr,
|
|
53
|
+
zh: zhCN,
|
|
54
|
+
'zh-CN': zhCN,
|
|
55
|
+
'zh-HK': zhHK,
|
|
56
|
+
};
|
|
57
|
+
var languages = Array.from(new Set(__spreadArray(__spreadArray([], Object.keys(coreTranslations), true), Object.keys(wiseTranslations), true)));
|
|
58
|
+
var translations = languages.reduce(function (acc, lang) {
|
|
59
|
+
var _a;
|
|
60
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[lang] = __assign(__assign({}, coreTranslations[lang]), wiseTranslations[lang]), _a)));
|
|
61
|
+
}, {});
|
|
62
|
+
export default translations;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { makeHttpClient } from '@wise/dynamic-flow-client';
|
|
2
|
+
export { JsonSchemaForm, isValidSchema } from '@wise/dynamic-flow-client';
|
|
3
|
+
export { default as translations } from './i18n';
|
|
4
|
+
export { DynamicFlowLegacy as DynamicFlow, DynamicFlowLegacy, DynamicFlowRevamp, DynamicFragment, } from './dynamicFlow/DynamicFlow';
|
|
5
|
+
export var makeCustomFetch = makeHttpClient;
|