@fixefy/fixefy-ui-utils 0.0.6 → 0.0.7
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-cjs/auth/index.js +13 -0
- package/dist-cjs/aws/aws_lambda_helper.js +49 -0
- package/dist-cjs/aws/aws_s3_helper.js +1 -0
- package/dist-cjs/aws/data_models.js +2 -0
- package/dist-cjs/aws/index.js +4 -0
- package/dist-cjs/commander/index.jsx +63 -67
- package/dist-cjs/contents/index.jsx +32 -0
- package/dist-cjs/files/index.js +27 -0
- package/dist-cjs/graphql/index.js +217 -0
- package/dist-cjs/images/index.js +10 -2
- package/dist-cjs/index.js +8 -0
- package/dist-cjs/json/index.js +135 -0
- package/dist-cjs/redirect/index.js +15 -0
- package/dist-cjs/renderer/index.jsx +66 -0
- package/dist-cjs/resolvers/index.js +35 -0
- package/dist-cjs/transform/index.js +40 -0
- package/dist-cjs/validate/index.js +44 -0
- package/dist-es/auth/index.js +11 -0
- package/dist-es/aws/aws_lambda_helper.js +41 -0
- package/dist-es/aws/aws_s3_helper.js +1 -0
- package/dist-es/aws/data_models.js +1 -0
- package/dist-es/aws/index.js +1 -0
- package/dist-es/commander/index.jsx +59 -63
- package/dist-es/contents/index.jsx +31 -0
- package/dist-es/files/index.js +22 -0
- package/dist-es/graphql/index.js +235 -0
- package/dist-es/images/index.js +9 -1
- package/dist-es/index.js +8 -0
- package/dist-es/json/index.js +125 -0
- package/dist-es/redirect/index.js +12 -0
- package/dist-es/renderer/index.jsx +60 -0
- package/dist-es/resolvers/index.js +31 -0
- package/dist-es/transform/index.js +35 -0
- package/dist-es/validate/index.js +37 -0
- package/dist-types/auth/index.d.ts +2 -0
- package/dist-types/aws/aws_lambda_helper.d.ts +5 -0
- package/dist-types/aws/aws_s3_helper.d.ts +0 -0
- package/dist-types/aws/data_models.d.ts +21 -0
- package/dist-types/aws/index.d.ts +1 -0
- package/dist-types/contents/index.d.ts +3 -0
- package/dist-types/files/index.d.ts +2 -0
- package/dist-types/graphql/index.d.ts +38 -0
- package/dist-types/images/index.d.ts +4 -1
- package/dist-types/index.d.ts +8 -0
- package/dist-types/json/index.d.ts +7 -0
- package/dist-types/redirect/index.d.ts +2 -0
- package/dist-types/renderer/index.d.ts +9 -0
- package/dist-types/resolvers/index.d.ts +11 -0
- package/dist-types/transform/index.d.ts +2 -0
- package/dist-types/validate/index.d.ts +4 -0
- package/package.json +6 -1
- package/dist-cjs/images/image_loader.js +0 -13
- package/dist-es/images/image_loader.js +0 -9
- package/dist-types/images/image_loader.d.ts +0 -4
package/dist-cjs/images/index.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.imageLoader = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const imageLoader = ({ src, root }) => {
|
|
5
|
+
const transformedSrc = src.split('/');
|
|
6
|
+
transformedSrc.splice(transformedSrc.length - 1, 1, transformedSrc[transformedSrc.length - 1]
|
|
7
|
+
.split(/(?=[A-Z])/)
|
|
8
|
+
.join('_')
|
|
9
|
+
.toLowerCase());
|
|
10
|
+
const url = transformedSrc.join('/');
|
|
11
|
+
return `${root}${url}`;
|
|
12
|
+
};
|
|
13
|
+
exports.imageLoader = imageLoader;
|
package/dist-cjs/index.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./auth"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./aws"), exports);
|
|
4
6
|
tslib_1.__exportStar(require("./commander"), exports);
|
|
5
7
|
tslib_1.__exportStar(require("./constants"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./contents"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./graphql"), exports);
|
|
6
10
|
tslib_1.__exportStar(require("./headers"), exports);
|
|
7
11
|
tslib_1.__exportStar(require("./images"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./json"), exports);
|
|
8
13
|
tslib_1.__exportStar(require("./page_context"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./redirect"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./renderer"), exports);
|
|
9
16
|
tslib_1.__exportStar(require("./types"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./validate"), exports);
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setJToken = exports.isResultValid = exports.isNested = exports.isJson = exports.isHasKey = exports.getJPart = exports.getJToken = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
const getJToken = (jToken, jsonPath, defaultValue) => {
|
|
6
|
+
if ((0, __1.isObjectValid)(jToken) === false)
|
|
7
|
+
return defaultValue;
|
|
8
|
+
jsonPath = jsonPath.replace(/\[(\w+)\]/g, '.$1');
|
|
9
|
+
jsonPath = jsonPath.replace(/^\./, '');
|
|
10
|
+
let isContinueLoop = true, currentToken, jsonPathParts = jsonPath.split('.');
|
|
11
|
+
try {
|
|
12
|
+
for (let i = 0, n = jsonPathParts.length; isContinueLoop && i < n; ++i) {
|
|
13
|
+
currentToken = jsonPathParts[i];
|
|
14
|
+
if (typeof jToken === 'string') {
|
|
15
|
+
jToken = JSON.parse(jToken);
|
|
16
|
+
}
|
|
17
|
+
if (currentToken in jToken) {
|
|
18
|
+
jToken = jToken[currentToken];
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
jToken = defaultValue;
|
|
22
|
+
isContinueLoop = false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
jToken = 'No Value Found';
|
|
28
|
+
}
|
|
29
|
+
return jToken;
|
|
30
|
+
};
|
|
31
|
+
exports.getJToken = getJToken;
|
|
32
|
+
const getJPart = (j, jsonPath, defaultValue) => {
|
|
33
|
+
if (j == null)
|
|
34
|
+
return defaultValue;
|
|
35
|
+
jsonPath = jsonPath.replace(/\[(\w+)\]/g, '.$1');
|
|
36
|
+
jsonPath = jsonPath.replace(/^\./, '');
|
|
37
|
+
let _isArrayValid = false, _isStringValid = false, currentPathPart, pathParts = jsonPath.split('.'), isLoop = true;
|
|
38
|
+
for (let i = 0, n = pathParts.length; isLoop && i < n; ++i) {
|
|
39
|
+
currentPathPart = pathParts[i];
|
|
40
|
+
_isStringValid = (0, __1.isStringValid)(j);
|
|
41
|
+
_isArrayValid = (0, __1.isArrayValid)(j);
|
|
42
|
+
if (_isStringValid === true || _isArrayValid === true) {
|
|
43
|
+
if (_isStringValid === true) {
|
|
44
|
+
j = JSON.parse(j);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
j = j.reduce((acc, cur, idx, src) => {
|
|
48
|
+
const innerJ = (0, exports.getJPart)(cur, pathParts.slice(i).join('.'), defaultValue);
|
|
49
|
+
if ((0, __1.isArrayValid)(innerJ)) {
|
|
50
|
+
acc.push(...innerJ);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
acc.push(innerJ);
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
}, []);
|
|
57
|
+
isLoop = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (j[currentPathPart] != null && currentPathPart in j) {
|
|
62
|
+
j = j[currentPathPart];
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
j = defaultValue;
|
|
66
|
+
isLoop = false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return j;
|
|
71
|
+
};
|
|
72
|
+
exports.getJPart = getJPart;
|
|
73
|
+
const isHasKey = (array, key) => {
|
|
74
|
+
let rv = false, isContinueLoop = true, current_keys;
|
|
75
|
+
for (let i = 0; i < array.length && isContinueLoop; ++i) {
|
|
76
|
+
current_keys = Object.keys(array[i]);
|
|
77
|
+
if ((current_keys || []).indexOf(key) > -1) {
|
|
78
|
+
rv = true;
|
|
79
|
+
isContinueLoop = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return rv;
|
|
83
|
+
};
|
|
84
|
+
exports.isHasKey = isHasKey;
|
|
85
|
+
const isJson = (obj) => {
|
|
86
|
+
let objAsString;
|
|
87
|
+
try {
|
|
88
|
+
objAsString = JSON.stringify(obj);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
objAsString = null;
|
|
92
|
+
}
|
|
93
|
+
if (!objAsString || (0, __1.isStringValid)(objAsString) === false)
|
|
94
|
+
return false;
|
|
95
|
+
const rv = (objAsString === null || objAsString === void 0 ? void 0 : objAsString.indexOf('{')) === 0 && (objAsString === null || objAsString === void 0 ? void 0 : objAsString.indexOf('}')) === (objAsString === null || objAsString === void 0 ? void 0 : objAsString.length) - 1;
|
|
96
|
+
return rv;
|
|
97
|
+
};
|
|
98
|
+
exports.isJson = isJson;
|
|
99
|
+
const isNested = (obj) => {
|
|
100
|
+
const rv = Object.keys(obj).some((key) => {
|
|
101
|
+
return obj[key] && typeof obj[key] === 'object';
|
|
102
|
+
});
|
|
103
|
+
return rv;
|
|
104
|
+
};
|
|
105
|
+
exports.isNested = isNested;
|
|
106
|
+
const isResultValid = (jResult) => {
|
|
107
|
+
if ((0, __1.isObjectValid)(jResult) === false)
|
|
108
|
+
return false;
|
|
109
|
+
const rv = (0, exports.getJPart)(jResult, 'ok', 0);
|
|
110
|
+
return !!rv;
|
|
111
|
+
};
|
|
112
|
+
exports.isResultValid = isResultValid;
|
|
113
|
+
const setJToken = (jEntity, fieldPathsAndValues) => {
|
|
114
|
+
let jCurrentToken, currentPath, pathParts, fieldName;
|
|
115
|
+
for (let i = 0; i < fieldPathsAndValues.length; ++i) {
|
|
116
|
+
currentPath = fieldPathsAndValues[i]['json_path'];
|
|
117
|
+
if ((0, __1.isStringValid)(currentPath)) {
|
|
118
|
+
fieldName = currentPath;
|
|
119
|
+
pathParts = currentPath.split('.');
|
|
120
|
+
if ((0, __1.isArrayValid)(pathParts)) {
|
|
121
|
+
fieldName = pathParts[pathParts.length - 1];
|
|
122
|
+
pathParts = pathParts.splice(0, Math.max(0, pathParts.length - 1));
|
|
123
|
+
if ((0, __1.isArrayValid)(pathParts)) {
|
|
124
|
+
currentPath = pathParts.join('.');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
jCurrentToken = (0, exports.getJPart)(jEntity, currentPath, null);
|
|
128
|
+
if ((0, __1.isObjectValid)(jCurrentToken) || (0, exports.isJson)(jCurrentToken) === false) {
|
|
129
|
+
jCurrentToken = jEntity;
|
|
130
|
+
}
|
|
131
|
+
jCurrentToken[fieldName] = fieldPathsAndValues[i]['value'];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
exports.setJToken = setJToken;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const router_1 = tslib_1.__importDefault(require("next/router"));
|
|
5
|
+
const redirect = (context, target) => {
|
|
6
|
+
if (context.res) {
|
|
7
|
+
console.log('SERVER RESPONSE :', context.res);
|
|
8
|
+
context.res.writeHead(303, { Location: target });
|
|
9
|
+
context.res.end();
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
router_1.default.replace(target);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.default = redirect;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValueComponentByComponentValue = exports.parseValue = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const material_1 = require("@mui/material");
|
|
7
|
+
const fixefy_ui_components_1 = require("@fixefy/fixefy-ui-components");
|
|
8
|
+
const __1 = require("../");
|
|
9
|
+
const parseValue = ({ value, structure, onClick }) => {
|
|
10
|
+
const { extended, name, type, title } = structure;
|
|
11
|
+
const path = extended && extended.title_path;
|
|
12
|
+
let theTruth;
|
|
13
|
+
if (path) {
|
|
14
|
+
theTruth = (0, __1.getJPart)(value, path, undefined);
|
|
15
|
+
}
|
|
16
|
+
const _value = theTruth === undefined || theTruth === null ? value[name] : theTruth;
|
|
17
|
+
if (_value === undefined || _value === null) {
|
|
18
|
+
return (0, exports.getValueComponentByComponentValue)({
|
|
19
|
+
value: 'No Value Found',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
let rv = (0, __1.getStringValueByValueType)({ value: _value, name });
|
|
23
|
+
rv = (0, exports.getValueComponentByComponentValue)({
|
|
24
|
+
value: rv,
|
|
25
|
+
name,
|
|
26
|
+
title,
|
|
27
|
+
type,
|
|
28
|
+
onClick: (e) => onClick(e, _value),
|
|
29
|
+
});
|
|
30
|
+
return rv;
|
|
31
|
+
};
|
|
32
|
+
exports.parseValue = parseValue;
|
|
33
|
+
const getValueComponentByComponentValue = ({ value, name, title, type, onClick }) => {
|
|
34
|
+
let rv = null;
|
|
35
|
+
switch (type) {
|
|
36
|
+
case __1.ComponentTypes.Chip:
|
|
37
|
+
rv = <fixefy_ui_components_1.FxChip size="small" key={`${name}-Chip-3003`} style={{ marginBottom: '5px' }} status={value.toLowerCase()} label={value}/>;
|
|
38
|
+
break;
|
|
39
|
+
case __1.ComponentTypes.ClickableLabel:
|
|
40
|
+
rv = (<material_1.Typography key={`${name}-Link-2002`} sx={{
|
|
41
|
+
marginBottom: '5px',
|
|
42
|
+
fontSize: '14px',
|
|
43
|
+
textDecoration: 'underline',
|
|
44
|
+
cursor: 'pointer',
|
|
45
|
+
}} variant="body1">
|
|
46
|
+
<material_1.Link onClick={onClick}>{(0, __1.titleCase)(value)}</material_1.Link>
|
|
47
|
+
</material_1.Typography>);
|
|
48
|
+
break;
|
|
49
|
+
case __1.ComponentTypes.Label:
|
|
50
|
+
if (Array.isArray(value) && (value === null || value === void 0 ? void 0 : value.length) > 1) {
|
|
51
|
+
rv = (<fixefy_ui_components_1.FxShowMore items={value} label={title !== null && title !== void 0 ? title : ''}>
|
|
52
|
+
<material_1.Typography key={`${name}-Label-1000`} lineHeight={'20px'} sx={{ fontSize: '14px' }} variant="body1">
|
|
53
|
+
{(0, __1.titleCase)(value[0])}
|
|
54
|
+
</material_1.Typography>
|
|
55
|
+
</fixefy_ui_components_1.FxShowMore>);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
rv = (<material_1.Typography key={`${name}-Label-1000`} lineHeight={'20px'} sx={{ fontSize: '14px' }} variant="body1">
|
|
60
|
+
{(0, __1.titleCase)(value)}
|
|
61
|
+
</material_1.Typography>);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
return rv;
|
|
65
|
+
};
|
|
66
|
+
exports.getValueComponentByComponentValue = getValueComponentByComponentValue;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvers = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
|
|
6
|
+
const CURRENT_PAGE_QUERY = (0, graphql_tag_1.default) `
|
|
7
|
+
query CURRENT_PAGE_QUERY {
|
|
8
|
+
currentPage @client {
|
|
9
|
+
name
|
|
10
|
+
path
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
exports.resolvers = {
|
|
15
|
+
Mutation: {
|
|
16
|
+
changePage(_, args, { cache }) {
|
|
17
|
+
console.log(_, args, cache);
|
|
18
|
+
const { currentPage } = cache.readQuery({
|
|
19
|
+
query: CURRENT_PAGE_QUERY,
|
|
20
|
+
});
|
|
21
|
+
if (args.to !== currentPage.name) {
|
|
22
|
+
const data = {
|
|
23
|
+
currentPage: {
|
|
24
|
+
name: args.to,
|
|
25
|
+
path: '/' + args.to,
|
|
26
|
+
__typename: 'currentPage',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
cache.writeQuery({ query: CURRENT_PAGE_QUERY, data });
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transform = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const csvtojson_1 = tslib_1.__importDefault(require("csvtojson"));
|
|
6
|
+
const convert_excel_to_json_1 = tslib_1.__importDefault(require("convert-excel-to-json"));
|
|
7
|
+
require("regenerator-runtime/runtime.js");
|
|
8
|
+
const defaultOptions = {
|
|
9
|
+
columns: true,
|
|
10
|
+
skip_empty_lines: true,
|
|
11
|
+
quote: '"',
|
|
12
|
+
ltrim: true,
|
|
13
|
+
rtrim: true,
|
|
14
|
+
delimiter: ',',
|
|
15
|
+
};
|
|
16
|
+
const transform = ({ data, data_type, options = defaultOptions }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
let rv = data;
|
|
18
|
+
data_type = data_type.substring(data_type.lastIndexOf('/') + 1, data_type.length + 1).toLowerCase();
|
|
19
|
+
switch (data_type) {
|
|
20
|
+
case 'csv':
|
|
21
|
+
rv = yield _csvToJson({ csv: data, options });
|
|
22
|
+
rv = JSON.stringify(rv).trim();
|
|
23
|
+
break;
|
|
24
|
+
case 'xls':
|
|
25
|
+
rv = _xlsToJson({ xls: data });
|
|
26
|
+
break;
|
|
27
|
+
case 'xml':
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
return rv;
|
|
31
|
+
});
|
|
32
|
+
exports.transform = transform;
|
|
33
|
+
const _csvToJson = ({ csv, options = defaultOptions }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const rv = yield (0, csvtojson_1.default)(options).fromString(csv);
|
|
35
|
+
return rv;
|
|
36
|
+
});
|
|
37
|
+
const _xlsToJson = ({ xls }) => {
|
|
38
|
+
const rv = (0, convert_excel_to_json_1.default)({ source: xls });
|
|
39
|
+
return rv;
|
|
40
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isObjectId = exports.isStringValid = exports.isObjectValid = exports.isArrayValid = void 0;
|
|
4
|
+
const isArrayValid = (arr, minLength = 1, maxLength = 0) => {
|
|
5
|
+
let rv = Object.prototype.toString.call(arr) == '[object Array]' && (0, exports.isObjectValid)(arr) && arr.length >= minLength;
|
|
6
|
+
if (maxLength > 0) {
|
|
7
|
+
rv = rv && arr.length <= maxLength;
|
|
8
|
+
}
|
|
9
|
+
return rv;
|
|
10
|
+
};
|
|
11
|
+
exports.isArrayValid = isArrayValid;
|
|
12
|
+
const isObjectValid = (obj, isCheckKeys = false) => {
|
|
13
|
+
let rv = typeof obj !== 'undefined' && obj !== null;
|
|
14
|
+
if (isCheckKeys) {
|
|
15
|
+
rv = rv && Object.keys(obj).length > 0;
|
|
16
|
+
}
|
|
17
|
+
return rv;
|
|
18
|
+
};
|
|
19
|
+
exports.isObjectValid = isObjectValid;
|
|
20
|
+
const isStringValid = (str, minLength = null, maxLength = null, isValidateType = true) => {
|
|
21
|
+
if (str == null)
|
|
22
|
+
return false;
|
|
23
|
+
if (isValidateType && typeof str !== 'string')
|
|
24
|
+
return false;
|
|
25
|
+
if (str.toString().length == 0)
|
|
26
|
+
return false;
|
|
27
|
+
if (minLength && isNaN(minLength) === false && minLength > 0) {
|
|
28
|
+
return str.toString().length >= minLength;
|
|
29
|
+
}
|
|
30
|
+
if (maxLength && isNaN(maxLength) === false && maxLength > 0) {
|
|
31
|
+
return str.toString().length <= maxLength;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
exports.isStringValid = isStringValid;
|
|
36
|
+
const isObjectId = (value) => {
|
|
37
|
+
if ((0, exports.isStringValid)(value) === false)
|
|
38
|
+
return false;
|
|
39
|
+
const regex = /^[0-9a-fA-F]{24}$/;
|
|
40
|
+
const matches = regex.exec(value);
|
|
41
|
+
const rv = matches != null && (0, exports.isArrayValid)(matches);
|
|
42
|
+
return rv;
|
|
43
|
+
};
|
|
44
|
+
exports.isObjectId = isObjectId;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { parseCookies } from 'nookies';
|
|
2
|
+
export const attachAuth = (ctx, headers) => {
|
|
3
|
+
const token = getToken(ctx);
|
|
4
|
+
return {
|
|
5
|
+
...headers,
|
|
6
|
+
authorization: `Bearer ${token}`,
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export const getToken = (ctx) => {
|
|
10
|
+
return parseCookies(ctx)['token'];
|
|
11
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import AWS from 'aws-sdk';
|
|
2
|
+
export const getLambda = (args) => {
|
|
3
|
+
const { key, region, secret } = args, lambdaCredentials = new AWS.Credentials({ accessKeyId: key, secretAccessKey: secret }), rv = new AWS.Lambda({ credentials: lambdaCredentials, region, maxRetries: 0, httpOptions: { connectTimeout: 30000, timeout: 300000 } });
|
|
4
|
+
return rv;
|
|
5
|
+
};
|
|
6
|
+
export const getLambdaParams = (args) => {
|
|
7
|
+
const { authorization, file_name, function_name: functionName, raw, ws } = args, clientContextObj = { authorization, file_name, ws }, clientContext = '';
|
|
8
|
+
const rv = {
|
|
9
|
+
ClientContext: clientContext,
|
|
10
|
+
FunctionName: functionName,
|
|
11
|
+
InvocationType: 'RequestResponse',
|
|
12
|
+
Payload: '',
|
|
13
|
+
};
|
|
14
|
+
return rv;
|
|
15
|
+
};
|
|
16
|
+
export const generateMappings = async (args) => {
|
|
17
|
+
const params = getLambdaParams(args);
|
|
18
|
+
const lambda = getLambda(args);
|
|
19
|
+
const p = new Promise((resolve, reject) => {
|
|
20
|
+
lambda.invoke(params, (err, data) => {
|
|
21
|
+
if (err) {
|
|
22
|
+
reject(err);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
resolve(data);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
const result = await p;
|
|
30
|
+
const rv = getLambdaResult({ result });
|
|
31
|
+
return rv;
|
|
32
|
+
};
|
|
33
|
+
export const getLambdaResult = (args) => {
|
|
34
|
+
const { result: { ExecutedVersion: executedVersion, FunctionError: functionError, LogResult: logResult, Payload: payload, StatusCode: statusCode }, } = args;
|
|
35
|
+
let rv = { execute_version: executedVersion, function_error: functionError, log_result: logResult, status_code: statusCode };
|
|
36
|
+
if (payload != null) {
|
|
37
|
+
const payloadObject = JSON.parse(payload);
|
|
38
|
+
rv = { ...rv, body: payloadObject, error: payloadObject.errorMessage };
|
|
39
|
+
}
|
|
40
|
+
return rv;
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './aws_lambda_helper';
|