@wise/dynamic-flow-client-internal 2.9.2 → 2.9.3
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 +18 -0
- package/build/index.js +4 -0
- package/build/main.js +485 -482
- package/build/main.min.js +1 -1
- package/build/stories/DynamicFlow.story.js +29 -0
- package/build/stories/fixtureHttpClient.js +119 -0
- package/build/test-utils/NeptuneProviders.js +23 -0
- package/build/test-utils/rtl-utils.js +20 -0
- package/package.json +2 -2
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { action } from '@storybook/addon-actions';
|
|
14
|
+
import { storiesOf } from '@storybook/react';
|
|
15
|
+
import { layouts, features, examples, schemas } from '@wise/dynamic-flow-fixtures';
|
|
16
|
+
import { DynamicFlow } from '../index';
|
|
17
|
+
import { fixtureHttpClient, getObjectKeys } from './fixtureHttpClient';
|
|
18
|
+
var fixtures = __assign(__assign(__assign(__assign({}, examples), schemas), layouts), features);
|
|
19
|
+
var storyMap = {};
|
|
20
|
+
var allStepNames = getObjectKeys(fixtures);
|
|
21
|
+
allStepNames.forEach(function (stepName) {
|
|
22
|
+
var _a;
|
|
23
|
+
var label = fixtures[stepName].id;
|
|
24
|
+
if (label) {
|
|
25
|
+
var _b = label.split('/'), group = _b[0], name_1 = _b[1];
|
|
26
|
+
storyMap[group] || (storyMap[group] = storiesOf("Dynamic Flow/".concat(group), module));
|
|
27
|
+
(_a = storyMap[group]) === null || _a === void 0 ? void 0 : _a.add(name_1, function () { return (_jsx(DynamicFlow, { flowId: "storybook", initialAction: { method: 'GET', url: "/steps/".concat(stepName) }, customFetch: fixtureHttpClient, loaderConfig: { size: 'xl', initial: true, submission: false }, onCompletion: action('onCompletion'), onError: action('onError'), onEvent: action('onEvent'), onLog: action('onLog') }, stepName)); });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
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 { action } from '@storybook/addon-actions';
|
|
49
|
+
import { layouts, features, examples, schemas, responses } from '@wise/dynamic-flow-fixtures';
|
|
50
|
+
export var getObjectKeys = Object.keys;
|
|
51
|
+
var fixtures = __assign(__assign(__assign(__assign({}, examples), schemas), layouts), features);
|
|
52
|
+
var isObject = function (val) {
|
|
53
|
+
return typeof val === 'object' && val !== null;
|
|
54
|
+
};
|
|
55
|
+
export var fixtureHttpClient = function (input, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
56
|
+
var url;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
action('httpClient')(input, init);
|
|
59
|
+
url = getURL(input);
|
|
60
|
+
if (url.pathname.startsWith('/steps/')) {
|
|
61
|
+
return [2 /*return*/, respondWithFixture(fixtures, url, init)];
|
|
62
|
+
}
|
|
63
|
+
if (url.pathname.startsWith('/responses/')) {
|
|
64
|
+
return [2 /*return*/, respondWithFixture(responses, url, init)];
|
|
65
|
+
}
|
|
66
|
+
if (url.pathname.startsWith('/validate')) {
|
|
67
|
+
return [2 /*return*/, new Response(JSON.stringify({ message: 'Validation-async OK' }))];
|
|
68
|
+
}
|
|
69
|
+
return [2 /*return*/, new Response(null, { status: 404 })];
|
|
70
|
+
});
|
|
71
|
+
}); };
|
|
72
|
+
var getURL = function (input) {
|
|
73
|
+
if (input instanceof URL) {
|
|
74
|
+
return input;
|
|
75
|
+
}
|
|
76
|
+
if (input instanceof Request) {
|
|
77
|
+
return new URL(input.url, 'http://foo');
|
|
78
|
+
}
|
|
79
|
+
return new URL(input, 'http://foo');
|
|
80
|
+
};
|
|
81
|
+
var respondWithFixture = function (fixtureList, url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
82
|
+
var fixtureNames, name, fixture, body;
|
|
83
|
+
var _a;
|
|
84
|
+
return __generator(this, function (_b) {
|
|
85
|
+
switch (_b.label) {
|
|
86
|
+
case 0:
|
|
87
|
+
fixtureNames = getObjectKeys(fixtureList);
|
|
88
|
+
name = url.pathname
|
|
89
|
+
.split('/')
|
|
90
|
+
.filter(function (part) { return Boolean(part); })
|
|
91
|
+
.pop();
|
|
92
|
+
if (!fixtureNames.includes(name !== null && name !== void 0 ? name : '')) return [3 /*break*/, 3];
|
|
93
|
+
fixture = fixtureList[name];
|
|
94
|
+
if (!url.searchParams.has('delay')) return [3 /*break*/, 2];
|
|
95
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
96
|
+
setTimeout(resolve, Number(url.searchParams.get('delay')));
|
|
97
|
+
})];
|
|
98
|
+
case 1:
|
|
99
|
+
_b.sent();
|
|
100
|
+
_b.label = 2;
|
|
101
|
+
case 2:
|
|
102
|
+
// by convention if the url contains a "refresh"query parameterm we use the payload as model
|
|
103
|
+
if (url.searchParams.has('refresh') &&
|
|
104
|
+
(init === null || init === void 0 ? void 0 : init.body) &&
|
|
105
|
+
typeof init.body === 'string' &&
|
|
106
|
+
isObject(fixture)) {
|
|
107
|
+
body = JSON.parse(init.body);
|
|
108
|
+
return [2 /*return*/, new Response(JSON.stringify(__assign(__assign({}, fixture), { model: __assign(__assign({}, ((_a = fixture.model) !== null && _a !== void 0 ? _a : {})), body) })))];
|
|
109
|
+
}
|
|
110
|
+
if (url.pathname.includes('exit')) {
|
|
111
|
+
return [2 /*return*/, new Response(JSON.stringify(fixture), { headers: { 'X-DF-Exit': 'true' } })];
|
|
112
|
+
}
|
|
113
|
+
return [2 /*return*/, new Response(JSON.stringify(fixture))];
|
|
114
|
+
case 3:
|
|
115
|
+
action('ERROR 404')(url);
|
|
116
|
+
return [2 /*return*/, new Response(null, { status: 404 })];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}); };
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { Provider as ComponentProvider, DEFAULT_LANG, DEFAULT_LOCALE, SnackbarProvider, translations as componentTranslations, getLangFromLocale, } from '@transferwise/components';
|
|
14
|
+
import { ThemeProvider } from '@wise/components-theming';
|
|
15
|
+
import { translations } from '@wise/dynamic-flow-client';
|
|
16
|
+
var locale = DEFAULT_LOCALE;
|
|
17
|
+
var lang = getLangFromLocale(locale) || DEFAULT_LANG;
|
|
18
|
+
var messages = __assign(__assign({}, componentTranslations[lang]), translations[lang]);
|
|
19
|
+
function NeptuneProviders(_a) {
|
|
20
|
+
var children = _a.children;
|
|
21
|
+
return (_jsx(ThemeProvider, __assign({ theme: "personal", screenMode: "light" }, { children: _jsx(SnackbarProvider, { children: _jsx(ComponentProvider, __assign({ i18n: { locale: locale, messages: messages } }, { children: children })) }) })));
|
|
22
|
+
}
|
|
23
|
+
export default NeptuneProviders;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { render } from '@testing-library/react';
|
|
14
|
+
import NeptuneProviders from './NeptuneProviders';
|
|
15
|
+
export var renderWithProviders = function (children, options) {
|
|
16
|
+
var renderedResult = render(_jsx(NeptuneProviders, { children: children }), options);
|
|
17
|
+
return __assign(__assign({}, renderedResult), { rerender: function (ui, renderOptions) {
|
|
18
|
+
return renderWithProviders(ui, __assign({ container: renderedResult.container }, renderOptions));
|
|
19
|
+
} });
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/dynamic-flow-client-internal",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.3",
|
|
4
4
|
"description": "Dynamic Flow web client for Wise",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./build/main.min.js",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"react-intl": "^6"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@wise/dynamic-flow-client": "2.9.
|
|
82
|
+
"@wise/dynamic-flow-client": "2.9.3"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
85
|
"dev": "storybook dev -p 3005",
|