@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.
Files changed (54) hide show
  1. package/dist-cjs/auth/index.js +13 -0
  2. package/dist-cjs/aws/aws_lambda_helper.js +49 -0
  3. package/dist-cjs/aws/aws_s3_helper.js +1 -0
  4. package/dist-cjs/aws/data_models.js +2 -0
  5. package/dist-cjs/aws/index.js +4 -0
  6. package/dist-cjs/commander/index.jsx +63 -67
  7. package/dist-cjs/contents/index.jsx +32 -0
  8. package/dist-cjs/files/index.js +27 -0
  9. package/dist-cjs/graphql/index.js +217 -0
  10. package/dist-cjs/images/index.js +10 -2
  11. package/dist-cjs/index.js +8 -0
  12. package/dist-cjs/json/index.js +135 -0
  13. package/dist-cjs/redirect/index.js +15 -0
  14. package/dist-cjs/renderer/index.jsx +66 -0
  15. package/dist-cjs/resolvers/index.js +35 -0
  16. package/dist-cjs/transform/index.js +40 -0
  17. package/dist-cjs/validate/index.js +44 -0
  18. package/dist-es/auth/index.js +11 -0
  19. package/dist-es/aws/aws_lambda_helper.js +41 -0
  20. package/dist-es/aws/aws_s3_helper.js +1 -0
  21. package/dist-es/aws/data_models.js +1 -0
  22. package/dist-es/aws/index.js +1 -0
  23. package/dist-es/commander/index.jsx +59 -63
  24. package/dist-es/contents/index.jsx +31 -0
  25. package/dist-es/files/index.js +22 -0
  26. package/dist-es/graphql/index.js +235 -0
  27. package/dist-es/images/index.js +9 -1
  28. package/dist-es/index.js +8 -0
  29. package/dist-es/json/index.js +125 -0
  30. package/dist-es/redirect/index.js +12 -0
  31. package/dist-es/renderer/index.jsx +60 -0
  32. package/dist-es/resolvers/index.js +31 -0
  33. package/dist-es/transform/index.js +35 -0
  34. package/dist-es/validate/index.js +37 -0
  35. package/dist-types/auth/index.d.ts +2 -0
  36. package/dist-types/aws/aws_lambda_helper.d.ts +5 -0
  37. package/dist-types/aws/aws_s3_helper.d.ts +0 -0
  38. package/dist-types/aws/data_models.d.ts +21 -0
  39. package/dist-types/aws/index.d.ts +1 -0
  40. package/dist-types/contents/index.d.ts +3 -0
  41. package/dist-types/files/index.d.ts +2 -0
  42. package/dist-types/graphql/index.d.ts +38 -0
  43. package/dist-types/images/index.d.ts +4 -1
  44. package/dist-types/index.d.ts +8 -0
  45. package/dist-types/json/index.d.ts +7 -0
  46. package/dist-types/redirect/index.d.ts +2 -0
  47. package/dist-types/renderer/index.d.ts +9 -0
  48. package/dist-types/resolvers/index.d.ts +11 -0
  49. package/dist-types/transform/index.d.ts +2 -0
  50. package/dist-types/validate/index.d.ts +4 -0
  51. package/package.json +6 -1
  52. package/dist-cjs/images/image_loader.js +0 -13
  53. package/dist-es/images/image_loader.js +0 -9
  54. package/dist-types/images/image_loader.d.ts +0 -4
@@ -0,0 +1,125 @@
1
+ import { isArrayValid, isObjectValid, isStringValid } from '../';
2
+ export const getJToken = (jToken, jsonPath, defaultValue) => {
3
+ if (isObjectValid(jToken) === false)
4
+ return defaultValue;
5
+ jsonPath = jsonPath.replace(/\[(\w+)\]/g, '.$1');
6
+ jsonPath = jsonPath.replace(/^\./, '');
7
+ let isContinueLoop = true, currentToken, jsonPathParts = jsonPath.split('.');
8
+ try {
9
+ for (let i = 0, n = jsonPathParts.length; isContinueLoop && i < n; ++i) {
10
+ currentToken = jsonPathParts[i];
11
+ if (typeof jToken === 'string') {
12
+ jToken = JSON.parse(jToken);
13
+ }
14
+ if (currentToken in jToken) {
15
+ jToken = jToken[currentToken];
16
+ }
17
+ else {
18
+ jToken = defaultValue;
19
+ isContinueLoop = false;
20
+ }
21
+ }
22
+ }
23
+ catch (e) {
24
+ jToken = 'No Value Found';
25
+ }
26
+ return jToken;
27
+ };
28
+ export const getJPart = (j, jsonPath, defaultValue) => {
29
+ if (j == null)
30
+ return defaultValue;
31
+ jsonPath = jsonPath.replace(/\[(\w+)\]/g, '.$1');
32
+ jsonPath = jsonPath.replace(/^\./, '');
33
+ let _isArrayValid = false, _isStringValid = false, currentPathPart, pathParts = jsonPath.split('.'), isLoop = true;
34
+ for (let i = 0, n = pathParts.length; isLoop && i < n; ++i) {
35
+ currentPathPart = pathParts[i];
36
+ _isStringValid = isStringValid(j);
37
+ _isArrayValid = isArrayValid(j);
38
+ if (_isStringValid === true || _isArrayValid === true) {
39
+ if (_isStringValid === true) {
40
+ j = JSON.parse(j);
41
+ }
42
+ else {
43
+ j = j.reduce((acc, cur, idx, src) => {
44
+ const innerJ = getJPart(cur, pathParts.slice(i).join('.'), defaultValue);
45
+ if (isArrayValid(innerJ)) {
46
+ acc.push(...innerJ);
47
+ }
48
+ else {
49
+ acc.push(innerJ);
50
+ }
51
+ return acc;
52
+ }, []);
53
+ isLoop = false;
54
+ }
55
+ }
56
+ else {
57
+ if (j[currentPathPart] != null && currentPathPart in j) {
58
+ j = j[currentPathPart];
59
+ }
60
+ else {
61
+ j = defaultValue;
62
+ isLoop = false;
63
+ }
64
+ }
65
+ }
66
+ return j;
67
+ };
68
+ export const isHasKey = (array, key) => {
69
+ let rv = false, isContinueLoop = true, current_keys;
70
+ for (let i = 0; i < array.length && isContinueLoop; ++i) {
71
+ current_keys = Object.keys(array[i]);
72
+ if ((current_keys || []).indexOf(key) > -1) {
73
+ rv = true;
74
+ isContinueLoop = false;
75
+ }
76
+ }
77
+ return rv;
78
+ };
79
+ export const isJson = (obj) => {
80
+ let objAsString;
81
+ try {
82
+ objAsString = JSON.stringify(obj);
83
+ }
84
+ catch (e) {
85
+ objAsString = null;
86
+ }
87
+ if (!objAsString || isStringValid(objAsString) === false)
88
+ return false;
89
+ const rv = objAsString?.indexOf('{') === 0 && objAsString?.indexOf('}') === objAsString?.length - 1;
90
+ return rv;
91
+ };
92
+ export const isNested = (obj) => {
93
+ const rv = Object.keys(obj).some((key) => {
94
+ return obj[key] && typeof obj[key] === 'object';
95
+ });
96
+ return rv;
97
+ };
98
+ export const isResultValid = (jResult) => {
99
+ if (isObjectValid(jResult) === false)
100
+ return false;
101
+ const rv = getJPart(jResult, 'ok', 0);
102
+ return !!rv;
103
+ };
104
+ export const setJToken = (jEntity, fieldPathsAndValues) => {
105
+ let jCurrentToken, currentPath, pathParts, fieldName;
106
+ for (let i = 0; i < fieldPathsAndValues.length; ++i) {
107
+ currentPath = fieldPathsAndValues[i]['json_path'];
108
+ if (isStringValid(currentPath)) {
109
+ fieldName = currentPath;
110
+ pathParts = currentPath.split('.');
111
+ if (isArrayValid(pathParts)) {
112
+ fieldName = pathParts[pathParts.length - 1];
113
+ pathParts = pathParts.splice(0, Math.max(0, pathParts.length - 1));
114
+ if (isArrayValid(pathParts)) {
115
+ currentPath = pathParts.join('.');
116
+ }
117
+ }
118
+ jCurrentToken = getJPart(jEntity, currentPath, null);
119
+ if (isObjectValid(jCurrentToken) || isJson(jCurrentToken) === false) {
120
+ jCurrentToken = jEntity;
121
+ }
122
+ jCurrentToken[fieldName] = fieldPathsAndValues[i]['value'];
123
+ }
124
+ }
125
+ };
@@ -0,0 +1,12 @@
1
+ import Router from 'next/router';
2
+ const redirect = (context, target) => {
3
+ if (context.res) {
4
+ console.log('SERVER RESPONSE :', context.res);
5
+ context.res.writeHead(303, { Location: target });
6
+ context.res.end();
7
+ }
8
+ else {
9
+ Router.replace(target);
10
+ }
11
+ };
12
+ export default redirect;
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import { Typography, Link } from '@mui/material';
3
+ import { FxChip, FxShowMore } from '@fixefy/fixefy-ui-components';
4
+ import { ComponentTypes, getJPart, titleCase, getStringValueByValueType } from '../';
5
+ export const parseValue = ({ value, structure, onClick }) => {
6
+ const { extended, name, type, title } = structure;
7
+ const path = extended && extended.title_path;
8
+ let theTruth;
9
+ if (path) {
10
+ theTruth = getJPart(value, path, undefined);
11
+ }
12
+ const _value = theTruth === undefined || theTruth === null ? value[name] : theTruth;
13
+ if (_value === undefined || _value === null) {
14
+ return getValueComponentByComponentValue({
15
+ value: 'No Value Found',
16
+ });
17
+ }
18
+ let rv = getStringValueByValueType({ value: _value, name });
19
+ rv = getValueComponentByComponentValue({
20
+ value: rv,
21
+ name,
22
+ title,
23
+ type,
24
+ onClick: (e) => onClick(e, _value),
25
+ });
26
+ return rv;
27
+ };
28
+ export const getValueComponentByComponentValue = ({ value, name, title, type, onClick }) => {
29
+ let rv = null;
30
+ switch (type) {
31
+ case ComponentTypes.Chip:
32
+ rv = <FxChip size="small" key={`${name}-Chip-3003`} style={{ marginBottom: '5px' }} status={value.toLowerCase()} label={value}/>;
33
+ break;
34
+ case ComponentTypes.ClickableLabel:
35
+ rv = (<Typography key={`${name}-Link-2002`} sx={{
36
+ marginBottom: '5px',
37
+ fontSize: '14px',
38
+ textDecoration: 'underline',
39
+ cursor: 'pointer',
40
+ }} variant="body1">
41
+ <Link onClick={onClick}>{titleCase(value)}</Link>
42
+ </Typography>);
43
+ break;
44
+ case ComponentTypes.Label:
45
+ if (Array.isArray(value) && value?.length > 1) {
46
+ rv = (<FxShowMore items={value} label={title ?? ''}>
47
+ <Typography key={`${name}-Label-1000`} lineHeight={'20px'} sx={{ fontSize: '14px' }} variant="body1">
48
+ {titleCase(value[0])}
49
+ </Typography>
50
+ </FxShowMore>);
51
+ }
52
+ break;
53
+ default:
54
+ rv = (<Typography key={`${name}-Label-1000`} lineHeight={'20px'} sx={{ fontSize: '14px' }} variant="body1">
55
+ {titleCase(value)}
56
+ </Typography>);
57
+ break;
58
+ }
59
+ return rv;
60
+ };
@@ -0,0 +1,31 @@
1
+ import gql from 'graphql-tag';
2
+ const CURRENT_PAGE_QUERY = gql `
3
+ query CURRENT_PAGE_QUERY {
4
+ currentPage @client {
5
+ name
6
+ path
7
+ }
8
+ }
9
+ `;
10
+ export const resolvers = {
11
+ Mutation: {
12
+ changePage(_, args, { cache }) {
13
+ console.log(_, args, cache);
14
+ const { currentPage } = cache.readQuery({
15
+ query: CURRENT_PAGE_QUERY,
16
+ });
17
+ if (args.to !== currentPage.name) {
18
+ const data = {
19
+ currentPage: {
20
+ name: args.to,
21
+ path: '/' + args.to,
22
+ __typename: 'currentPage',
23
+ },
24
+ };
25
+ cache.writeQuery({ query: CURRENT_PAGE_QUERY, data });
26
+ return data;
27
+ }
28
+ return null;
29
+ },
30
+ },
31
+ };
@@ -0,0 +1,35 @@
1
+ import csvtojson from 'csvtojson';
2
+ import xlsToJson from 'convert-excel-to-json';
3
+ import 'regenerator-runtime/runtime.js';
4
+ const defaultOptions = {
5
+ columns: true,
6
+ skip_empty_lines: true,
7
+ quote: '"',
8
+ ltrim: true,
9
+ rtrim: true,
10
+ delimiter: ',',
11
+ };
12
+ export const transform = async ({ data, data_type, options = defaultOptions }) => {
13
+ let rv = data;
14
+ data_type = data_type.substring(data_type.lastIndexOf('/') + 1, data_type.length + 1).toLowerCase();
15
+ switch (data_type) {
16
+ case 'csv':
17
+ rv = await _csvToJson({ csv: data, options });
18
+ rv = JSON.stringify(rv).trim();
19
+ break;
20
+ case 'xls':
21
+ rv = _xlsToJson({ xls: data });
22
+ break;
23
+ case 'xml':
24
+ break;
25
+ }
26
+ return rv;
27
+ };
28
+ const _csvToJson = async ({ csv, options = defaultOptions }) => {
29
+ const rv = await csvtojson(options).fromString(csv);
30
+ return rv;
31
+ };
32
+ const _xlsToJson = ({ xls }) => {
33
+ const rv = xlsToJson({ source: xls });
34
+ return rv;
35
+ };
@@ -0,0 +1,37 @@
1
+ export const isArrayValid = (arr, minLength = 1, maxLength = 0) => {
2
+ let rv = Object.prototype.toString.call(arr) == '[object Array]' && isObjectValid(arr) && arr.length >= minLength;
3
+ if (maxLength > 0) {
4
+ rv = rv && arr.length <= maxLength;
5
+ }
6
+ return rv;
7
+ };
8
+ export const isObjectValid = (obj, isCheckKeys = false) => {
9
+ let rv = typeof obj !== 'undefined' && obj !== null;
10
+ if (isCheckKeys) {
11
+ rv = rv && Object.keys(obj).length > 0;
12
+ }
13
+ return rv;
14
+ };
15
+ export const isStringValid = (str, minLength = null, maxLength = null, isValidateType = true) => {
16
+ if (str == null)
17
+ return false;
18
+ if (isValidateType && typeof str !== 'string')
19
+ return false;
20
+ if (str.toString().length == 0)
21
+ return false;
22
+ if (minLength && isNaN(minLength) === false && minLength > 0) {
23
+ return str.toString().length >= minLength;
24
+ }
25
+ if (maxLength && isNaN(maxLength) === false && maxLength > 0) {
26
+ return str.toString().length <= maxLength;
27
+ }
28
+ return true;
29
+ };
30
+ export const isObjectId = (value) => {
31
+ if (isStringValid(value) === false)
32
+ return false;
33
+ const regex = /^[0-9a-fA-F]{24}$/;
34
+ const matches = regex.exec(value);
35
+ const rv = matches != null && isArrayValid(matches);
36
+ return rv;
37
+ };
@@ -0,0 +1,2 @@
1
+ export declare const attachAuth: (ctx: any, headers: any) => any;
2
+ export declare const getToken: (ctx: any) => string;
@@ -0,0 +1,5 @@
1
+ import AWS from 'aws-sdk';
2
+ export declare const getLambda: (args: any) => AWS.Lambda;
3
+ export declare const getLambdaParams: (args: any) => AWS.Lambda.InvocationRequest;
4
+ export declare const generateMappings: (args: unknown) => Promise<any>;
5
+ export declare const getLambdaResult: (args: any) => any;
File without changes
@@ -0,0 +1,21 @@
1
+ export interface GenerateMappingsInput {
2
+ authorization: string;
3
+ file_name: string;
4
+ function_name: string;
5
+ raw: Array<unknown>;
6
+ ws: string;
7
+ }
8
+ export interface ListObjectOutput {
9
+ description?: string | undefined;
10
+ name?: string | undefined;
11
+ report?: string | undefined;
12
+ size?: number | undefined;
13
+ title?: string | undefined;
14
+ updated_at?: number | undefined;
15
+ updated_by?: string | undefined;
16
+ url?: string | undefined;
17
+ }
18
+ export interface SignedUrl {
19
+ name: string;
20
+ url: string;
21
+ }
@@ -0,0 +1 @@
1
+ export * from './aws_lambda_helper';
@@ -0,0 +1,3 @@
1
+ export declare const parseInput: ({ client, fetcher, control, structure, droppedItem, state, onInputChange, classes, args, ...rest }: {
2
+ [x: string]: any;
3
+ }) => any;
@@ -0,0 +1,2 @@
1
+ export declare const convertFileSize: (fileSize: number) => string | undefined;
2
+ export declare const convertFileTypeToIcon: (fileType: string) => "uploader/file_type_csv.svg" | "uploader/file_type_xml.svg" | "uploader/file_type_json.svg" | "uploader/file_type_xls.svg";
@@ -0,0 +1,38 @@
1
+ export declare const operationTypes: {
2
+ MUTATIONS: {
3
+ CREATE: string;
4
+ DELETE: string;
5
+ UPDATE: string;
6
+ ACTION: string;
7
+ };
8
+ QUERIES: string;
9
+ SUBSCRIPTIONS: string;
10
+ };
11
+ export declare const draggableTypes: {
12
+ ACTION: string;
13
+ ENTITY: string;
14
+ FRAGMENT: string;
15
+ VARIABLES: string;
16
+ };
17
+ export declare const getFields: ({ arg }: {
18
+ arg: any;
19
+ }) => any;
20
+ export declare const getFieldsStringified: ({ arg }: {
21
+ arg: any;
22
+ }) => string[];
23
+ export declare const getTypeKind: (object: any) => any;
24
+ export declare const getTypeName: (object: any) => any;
25
+ export declare const getOperationObjectFromSchema: ({ operationName, schema }: {
26
+ operationName: string;
27
+ schema: any;
28
+ }) => any[];
29
+ export declare const getOperationTypeForMutation: ({ operationName }: {
30
+ operationName: string;
31
+ }) => string;
32
+ export declare const getVariablesKeys: ({ variables, operationType }: {
33
+ variables: any;
34
+ operationType: string;
35
+ }) => string[] | undefined;
36
+ export declare const insertNewVariable: ({ operationName, schema, key, value, _variables, action, ctx }: any) => void;
37
+ export declare const isArgMandatory: (arg: any) => boolean;
38
+ export declare const parseInputDataToDataObject: ({ key, value, parent, method, list, state, ...rest }: any) => any;
@@ -1 +1,4 @@
1
- export { imageLoader } from "./image_loader";
1
+ export declare const imageLoader: ({ src, root }: {
2
+ src: any;
3
+ root: any;
4
+ }) => string;
@@ -1,6 +1,14 @@
1
+ export * from './auth';
2
+ export * from './aws';
1
3
  export * from './commander';
2
4
  export * from './constants';
5
+ export * from './contents';
6
+ export * from './graphql';
3
7
  export * from './headers';
4
8
  export * from './images';
9
+ export * from './json';
5
10
  export * from './page_context';
11
+ export * from './redirect';
12
+ export * from './renderer';
6
13
  export * from './types';
14
+ export * from './validate';
@@ -0,0 +1,7 @@
1
+ export declare const getJToken: (jToken: any, jsonPath: string, defaultValue?: any) => any;
2
+ export declare const getJPart: (j: any, jsonPath: string, defaultValue: any) => any;
3
+ export declare const isHasKey: <T>(array: T[], key: string) => boolean;
4
+ export declare const isJson: (obj: any) => boolean;
5
+ export declare const isNested: (obj: any) => any;
6
+ export declare const isResultValid: (jResult: any) => boolean;
7
+ export declare const setJToken: (jEntity: any, fieldPathsAndValues: Array<any>) => void;
@@ -0,0 +1,2 @@
1
+ declare const redirect: (context: any, target: any) => void;
2
+ export default redirect;
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export declare const parseValue: ({ value, structure, onClick }: any) => any;
3
+ export declare const getValueComponentByComponentValue: ({ value, name, title, type, onClick }: {
4
+ value?: any;
5
+ name?: String | undefined;
6
+ title?: string | undefined;
7
+ type?: any;
8
+ onClick?: any;
9
+ }) => React.JSX.Element | null;
@@ -0,0 +1,11 @@
1
+ export declare const resolvers: {
2
+ Mutation: {
3
+ changePage(_: any, args: any, { cache }: any): {
4
+ currentPage: {
5
+ name: any;
6
+ path: string;
7
+ __typename: string;
8
+ };
9
+ } | null;
10
+ };
11
+ };
@@ -0,0 +1,2 @@
1
+ import 'regenerator-runtime/runtime.js';
2
+ export declare const transform: ({ data, data_type, options }: any) => Promise<any>;
@@ -0,0 +1,4 @@
1
+ export declare const isArrayValid: (arr: Array<any>, minLength?: number, maxLength?: number) => boolean;
2
+ export declare const isObjectValid: (obj: any, isCheckKeys?: boolean) => boolean;
3
+ export declare const isStringValid: (str: string, minLength?: number | null, maxLength?: number | null, isValidateType?: boolean) => boolean;
4
+ export declare const isObjectId: (value: string) => boolean;
package/package.json CHANGED
@@ -4,16 +4,21 @@
4
4
  "fs": false
5
5
  },
6
6
  "dependencies": {
7
+ "@fixefy/fixefy-ui-components": "^0.0.8",
7
8
  "@mui/material": "^5.14.11",
8
9
  "@mui/styled-engine": "^5.14.11",
9
10
  "@mui/styles": "^5.14.11",
11
+ "aws-sdk": "^2.1467.0",
12
+ "convert-excel-to-json": "^1.7.0",
10
13
  "nookies": "^2.5.2",
11
14
  "react": "^18.2.0",
12
15
  "react-dom": "^18.2.0"
13
16
  },
14
17
  "devDependencies": {
15
18
  "@svgr/webpack": "^8.1.0",
19
+ "@types/convert-excel-to-json": "^1.7.2",
16
20
  "@types/node": "^20.7.1",
21
+ "@types/nookies": "^2.0.3",
17
22
  "@types/react": "^18.2.23",
18
23
  "@typescript-eslint/eslint-plugin": "^6.7.3",
19
24
  "@typescript-eslint/parser": "^6.7.3",
@@ -57,5 +62,5 @@
57
62
  }
58
63
  },
59
64
  "types": "./dist-types/index.d.ts",
60
- "version": "0.0.6"
65
+ "version": "0.0.7"
61
66
  }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.imageLoader = void 0;
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;
@@ -1,9 +0,0 @@
1
- export const imageLoader = ({ src, root }) => {
2
- const transformedSrc = src.split('/');
3
- transformedSrc.splice(transformedSrc.length - 1, 1, transformedSrc[transformedSrc.length - 1]
4
- .split(/(?=[A-Z])/)
5
- .join('_')
6
- .toLowerCase());
7
- const url = transformedSrc.join('/');
8
- return `${root}${url}`;
9
- };
@@ -1,4 +0,0 @@
1
- export declare const imageLoader: ({ src, root }: {
2
- src: any;
3
- root: any;
4
- }) => string;