@wise/dynamic-flow-client-internal 0.2.0-beta-1a74ba.3 → 0.2.0
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/README.md +3 -3
- package/package.json +24 -24
- package/build/stories/DynamicFlow.story.d.ts +0 -1
- package/build/stories/DynamicFlow.story.js +0 -30
- package/build/stories/EditableDynamicFlow.d.ts +0 -5
- package/build/stories/EditableDynamicFlow.js +0 -62
- package/build/stories/fixtureFetcher.d.ts +0 -3
- package/build/stories/fixtureFetcher.js +0 -116
package/README.md
CHANGED
|
@@ -24,15 +24,15 @@ pnpm install @wise/dynamic-flow-client-internal
|
|
|
24
24
|
```
|
|
25
25
|
# yarn
|
|
26
26
|
yarn add prop-types react react-dom react-intl
|
|
27
|
-
yarn add @transferwise/components @transferwise/formatting @transferwise/icons @transferwise/neptune-css
|
|
27
|
+
yarn add @transferwise/components @transferwise/formatting @transferwise/icons @transferwise/neptune-css
|
|
28
28
|
|
|
29
29
|
# npm
|
|
30
30
|
npm install prop-types react react-dom react-intl
|
|
31
|
-
npm install @transferwise/components @transferwise/formatting @transferwise/icons @transferwise/neptune-css
|
|
31
|
+
npm install @transferwise/components @transferwise/formatting @transferwise/icons @transferwise/neptune-css
|
|
32
32
|
|
|
33
33
|
# pnpm
|
|
34
34
|
pnpm install prop-types react react-dom react-intl
|
|
35
|
-
pnpm install @transferwise/components @transferwise/formatting @transferwise/icons @transferwise/neptune-css
|
|
35
|
+
pnpm install @transferwise/components @transferwise/formatting @transferwise/icons @transferwise/neptune-css
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
**Note:** Keep in mind that some of these dependencies have their own peer dependencies. Don't forget to install those, for instance: `@transferwise/components` needs `@wise/art` and `@wise/components-theming`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wise/dynamic-flow-client-internal",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Dynamic Flow web client for Wise",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -16,20 +16,6 @@
|
|
|
16
16
|
"fullname": "transferwise/dynamic-flow",
|
|
17
17
|
"url": "git+https://github.com/transferwise/dynamic-flow.git"
|
|
18
18
|
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"dev": "storybook dev -p 3005",
|
|
21
|
-
"build": "npm-run-all build:*",
|
|
22
|
-
"build:ts": "tsc --build ./tsconfig.build.json",
|
|
23
|
-
"build:css": "postcss src/main.css -o build/main.css",
|
|
24
|
-
"test": "pnpm test:once",
|
|
25
|
-
"test:once": "jest --config jest.config.js --env=jsdom",
|
|
26
|
-
"test:coverage": "jest --config jest.config.js --env=jsdom --coverage",
|
|
27
|
-
"test:watch": "pnpm test:once --watch",
|
|
28
|
-
"lint": "npm-run-all lint:ts lint:css",
|
|
29
|
-
"lint:ts": "eslint 'src/**/*.{js,jsx,ts,tsx}' --quiet",
|
|
30
|
-
"lint:css": "stylelint --allow-empty-input './src/**/*.css'",
|
|
31
|
-
"build-storybook": "storybook build -c .storybook"
|
|
32
|
-
},
|
|
33
19
|
"devDependencies": {
|
|
34
20
|
"@babel/core": "7.20.12",
|
|
35
21
|
"@babel/plugin-syntax-flow": "7.18.6",
|
|
@@ -51,18 +37,18 @@
|
|
|
51
37
|
"@testing-library/react": "14.0.0",
|
|
52
38
|
"@testing-library/react-hooks": "8.0.1",
|
|
53
39
|
"@testing-library/user-event": "13.2.1",
|
|
54
|
-
"@transferwise/components": "
|
|
40
|
+
"@transferwise/components": "45.3.0",
|
|
55
41
|
"@transferwise/eslint-config": "8.0.1",
|
|
56
42
|
"@transferwise/formatting": "^2.10.0",
|
|
57
|
-
"@transferwise/icons": "3.
|
|
58
|
-
"@transferwise/neptune-css": "14.3.
|
|
59
|
-
"@transferwise/neptune-tokens": "8.
|
|
43
|
+
"@transferwise/icons": "3.6.0",
|
|
44
|
+
"@transferwise/neptune-css": "14.3.49",
|
|
45
|
+
"@transferwise/neptune-tokens": "8.5.0",
|
|
60
46
|
"@types/jest": "29.4.0",
|
|
61
47
|
"@types/react": "18",
|
|
62
48
|
"@types/react-dom": "18",
|
|
63
49
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
64
|
-
"@wise/art": "2.
|
|
65
|
-
"@wise/components-theming": "^0.7.
|
|
50
|
+
"@wise/art": "2.3.3",
|
|
51
|
+
"@wise/components-theming": "^0.7.5",
|
|
66
52
|
"babel-jest": "29.5.0",
|
|
67
53
|
"currency-flags": "4.0.7",
|
|
68
54
|
"eslint": "8.36.0",
|
|
@@ -93,7 +79,21 @@
|
|
|
93
79
|
"react-intl": "^6"
|
|
94
80
|
},
|
|
95
81
|
"dependencies": {
|
|
96
|
-
"@wise/dynamic-flow-client": "^0.
|
|
82
|
+
"@wise/dynamic-flow-client": "^0.3.0"
|
|
97
83
|
},
|
|
98
|
-
"prettier": "@transferwise/eslint-config/.prettierrc.js"
|
|
99
|
-
|
|
84
|
+
"prettier": "@transferwise/eslint-config/.prettierrc.js",
|
|
85
|
+
"scripts": {
|
|
86
|
+
"dev": "storybook dev -p 3005",
|
|
87
|
+
"build": "npm-run-all build:*",
|
|
88
|
+
"build:ts": "tsc --build ./tsconfig.build.json",
|
|
89
|
+
"build:css": "postcss src/main.css -o build/main.css",
|
|
90
|
+
"test": "pnpm test:once",
|
|
91
|
+
"test:once": "jest --config jest.config.js --env=jsdom",
|
|
92
|
+
"test:coverage": "jest --config jest.config.js --env=jsdom --coverage",
|
|
93
|
+
"test:watch": "pnpm test:once --watch",
|
|
94
|
+
"lint": "npm-run-all lint:ts lint:css",
|
|
95
|
+
"lint:ts": "eslint 'src/**/*.{js,jsx,ts,tsx}' --quiet",
|
|
96
|
+
"lint:css": "stylelint --allow-empty-input './src/**/*.css'",
|
|
97
|
+
"build-storybook": "storybook build -c .storybook"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getObjectKeys: <T>(object: T) => (keyof T)[];
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { action } from '@storybook/addon-actions';
|
|
3
|
-
import { storiesOf } from '@storybook/react';
|
|
4
|
-
import { fixtures } from '@wise/dynamic-flow-client';
|
|
5
|
-
import { DynamicFlow } from '../index';
|
|
6
|
-
import EditableDynamicFlow from './EditableDynamicFlow';
|
|
7
|
-
import { fixtureFetcher } from './fixtureFetcher';
|
|
8
|
-
export var getObjectKeys = Object.keys;
|
|
9
|
-
var storyMap = {};
|
|
10
|
-
var allStepNames = getObjectKeys(fixtures.steps);
|
|
11
|
-
allStepNames.forEach(function (stepName) {
|
|
12
|
-
var _a;
|
|
13
|
-
var label = (_a = fixtures.steps[stepName].key) !== null && _a !== void 0 ? _a : stepName;
|
|
14
|
-
var _b = label.split('/'), group = _b[0], name = _b[1];
|
|
15
|
-
if (!storyMap[group]) {
|
|
16
|
-
storyMap[group] = storiesOf("Dynamic Flow/".concat(group), module);
|
|
17
|
-
}
|
|
18
|
-
storyMap[group].add(name, function () { return (_jsx(DynamicFlow, { flowId: "storybook", initialAction: { method: 'GET', url: "/steps/".concat(stepName) }, fetcher: fixtureFetcher, loaderConfig: { size: 'xl', initial: true, submission: false }, onComplete: action('onComplete'), onStepChange: action('onStepChange'), onError: action('onError'), onEvent: action('onEvent'), onLog: action('onLog') }, stepName)); });
|
|
19
|
-
});
|
|
20
|
-
var editable = storiesOf("Dynamic Flow/Editable", module);
|
|
21
|
-
editable.add('Dynamic Flow', EditableDynamicFlow, {
|
|
22
|
-
argTypes: {
|
|
23
|
-
initialStepName: {
|
|
24
|
-
label: 'Initial Step',
|
|
25
|
-
control: 'select',
|
|
26
|
-
options: Object.keys(fixtures.steps)
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
args: { initialStepName: Object.keys(fixtures)[0] }
|
|
30
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
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, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
/* eslint-disable react/forbid-dom-props */
|
|
14
|
-
import { action } from '@storybook/addon-actions';
|
|
15
|
-
import { fixtures } from '@wise/dynamic-flow-client';
|
|
16
|
-
import { useState } from 'react';
|
|
17
|
-
import { DynamicFlow } from '../index';
|
|
18
|
-
import { fixtureFetcher } from './fixtureFetcher';
|
|
19
|
-
var EditableDynamicFlow = function (_a) {
|
|
20
|
-
var _b = _a.initialStepName, initialStepName = _b === void 0 ? '' : _b;
|
|
21
|
-
var selectedStep = fixtures.steps[initialStepName] || {};
|
|
22
|
-
var selectedInitialStep = JSON.stringify(selectedStep, null, 2);
|
|
23
|
-
return _jsx(InteractiveDemo, { selectedInitialStep: selectedInitialStep }, selectedInitialStep);
|
|
24
|
-
};
|
|
25
|
-
var InteractiveDemo = function (_a) {
|
|
26
|
-
var selectedInitialStep = _a.selectedInitialStep;
|
|
27
|
-
var _b = useState(selectedInitialStep), initialStep = _b[0], setInitialStep = _b[1];
|
|
28
|
-
var onTextAreaChange = function (event) {
|
|
29
|
-
setInitialStep(event.target.value);
|
|
30
|
-
};
|
|
31
|
-
return (_jsxs("div", __assign({ style: { display: 'flex', gap: '1em' } }, { children: [_jsxs("div", __assign({ style: { flexBasis: '50%' } }, { children: [_jsx("h3", { children: "Editable Demo" }), _jsxs("p", { children: ["You can select an initial step from the drop down in the controls panel.", _jsx("br", {}), "You can edit the JSON below and see the result on the right."] }), _jsx("textarea", { wrap: "off", rows: 40, style: { fontFamily: 'monospace', fontSize: '0.9em', width: '100%' }, value: initialStep, onChange: onTextAreaChange })] })), _jsx("div", __assign({ style: { flexBasis: '50%' } }, { children: _jsx(DynamicFlow, { flowId: "storybook", initialStep: safeParseStepJson(initialStep), fetcher: fixtureFetcher, onComplete: action('onComplete'), onStepChange: action('onStepChange'), onError: action('onError'), onEvent: action('onEvent'), onLog: action('onLog') }, initialStep) }))] })));
|
|
32
|
-
};
|
|
33
|
-
function safeParseStepJson(jsonStep) {
|
|
34
|
-
try {
|
|
35
|
-
return JSON.parse(jsonStep);
|
|
36
|
-
}
|
|
37
|
-
catch (_a) {
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
console.warn('JSON parsing error');
|
|
40
|
-
return {
|
|
41
|
-
type: 'final',
|
|
42
|
-
layout: [
|
|
43
|
-
{
|
|
44
|
-
type: 'box',
|
|
45
|
-
width: 'lg',
|
|
46
|
-
components: [
|
|
47
|
-
{
|
|
48
|
-
type: 'alert',
|
|
49
|
-
markdown: "**Error parsing JSON.**",
|
|
50
|
-
context: 'warning'
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
type: 'paragraph',
|
|
54
|
-
text: " Invalid syntax or missing elements are preventing the JSON code you entered from being parsed. Carefully review and edit the code for errors such as missing commas or brackets."
|
|
55
|
-
},
|
|
56
|
-
]
|
|
57
|
-
},
|
|
58
|
-
]
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export default EditableDynamicFlow;
|
|
@@ -1,116 +0,0 @@
|
|
|
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 { fixtures } from '@wise/dynamic-flow-client';
|
|
50
|
-
import { getObjectKeys } from './DynamicFlow.story';
|
|
51
|
-
var isObject = function (val) {
|
|
52
|
-
return typeof val === 'object' && val !== null;
|
|
53
|
-
};
|
|
54
|
-
export var fixtureFetcher = function (input, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
-
var url;
|
|
56
|
-
return __generator(this, function (_a) {
|
|
57
|
-
action('fixtureFetcher')(input, init);
|
|
58
|
-
url = getURL(input);
|
|
59
|
-
if (url.pathname.startsWith('/steps/')) {
|
|
60
|
-
return [2 /*return*/, respondWithFixture(fixtures.steps, url, init)];
|
|
61
|
-
}
|
|
62
|
-
if (url.pathname.startsWith('/responses/')) {
|
|
63
|
-
return [2 /*return*/, respondWithFixture(fixtures.responses, url, init)];
|
|
64
|
-
}
|
|
65
|
-
if (url.pathname.startsWith('/validate')) {
|
|
66
|
-
return [2 /*return*/, new Response(JSON.stringify({ message: 'Validation-async OK' }))];
|
|
67
|
-
}
|
|
68
|
-
return [2 /*return*/, new Response(null, { status: 404 })];
|
|
69
|
-
});
|
|
70
|
-
}); };
|
|
71
|
-
var getURL = function (input) {
|
|
72
|
-
if (input instanceof URL) {
|
|
73
|
-
return input;
|
|
74
|
-
}
|
|
75
|
-
if (input instanceof Request) {
|
|
76
|
-
return new URL(input.url, 'http://foo');
|
|
77
|
-
}
|
|
78
|
-
return new URL(input, 'http://foo');
|
|
79
|
-
};
|
|
80
|
-
var respondWithFixture = function (fixtures, url, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
-
var fixtureNames, name, fixture, body;
|
|
82
|
-
var _a;
|
|
83
|
-
return __generator(this, function (_b) {
|
|
84
|
-
switch (_b.label) {
|
|
85
|
-
case 0:
|
|
86
|
-
fixtureNames = getObjectKeys(fixtures);
|
|
87
|
-
name = url.pathname
|
|
88
|
-
.split('/')
|
|
89
|
-
.filter(function (part) { return !!part; })
|
|
90
|
-
.pop();
|
|
91
|
-
if (!fixtureNames.includes(name !== null && name !== void 0 ? name : '')) return [3 /*break*/, 3];
|
|
92
|
-
fixture = fixtures[name];
|
|
93
|
-
if (!url.searchParams.has('delay')) return [3 /*break*/, 2];
|
|
94
|
-
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, Number(url.searchParams.get('delay'))); })];
|
|
95
|
-
case 1:
|
|
96
|
-
_b.sent();
|
|
97
|
-
_b.label = 2;
|
|
98
|
-
case 2:
|
|
99
|
-
// by convention if the url contains a "refresh"query parameterm we use the payload as model
|
|
100
|
-
if (url.searchParams.has('refresh') &&
|
|
101
|
-
(init === null || init === void 0 ? void 0 : init.body) &&
|
|
102
|
-
typeof init.body === 'string' &&
|
|
103
|
-
isObject(fixture)) {
|
|
104
|
-
body = JSON.parse(init.body);
|
|
105
|
-
return [2 /*return*/, new Response(JSON.stringify(__assign(__assign({}, fixture), { model: __assign(__assign({}, ((_a = fixture.model) !== null && _a !== void 0 ? _a : {})), body) })))];
|
|
106
|
-
}
|
|
107
|
-
if (url.pathname.includes('exit')) {
|
|
108
|
-
return [2 /*return*/, new Response(JSON.stringify(fixture), { headers: { 'X-DF-Exit': 'true' } })];
|
|
109
|
-
}
|
|
110
|
-
return [2 /*return*/, new Response(JSON.stringify(fixture))];
|
|
111
|
-
case 3:
|
|
112
|
-
action('ERROR 404')(url);
|
|
113
|
-
return [2 /*return*/, new Response(null, { status: 404 })];
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}); };
|