@fixefy/fixefy-ui-utils 0.0.8 → 0.0.10

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 (84) hide show
  1. package/dist-cjs/index.js +39 -17
  2. package/dist-cjs/index.js.map +1 -0
  3. package/{dist-types → dist-cjs/types}/index.d.ts +0 -3
  4. package/{dist-types → dist-cjs/types}/types/index.d.ts +5 -5
  5. package/dist-es/index.js +39 -14
  6. package/dist-es/index.js.map +1 -0
  7. package/dist-es/types/auth/index.d.ts +2 -0
  8. package/dist-es/types/aws/data_models.d.ts +21 -0
  9. package/dist-es/types/commander/index.d.ts +33 -0
  10. package/dist-es/types/constants/index.d.ts +6 -0
  11. package/dist-es/types/files/index.d.ts +2 -0
  12. package/dist-es/types/graphql/index.d.ts +38 -0
  13. package/dist-es/types/headers/index.d.ts +12 -0
  14. package/dist-es/types/images/index.d.ts +4 -0
  15. package/dist-es/types/index.d.ts +11 -0
  16. package/dist-es/types/json/index.d.ts +7 -0
  17. package/dist-es/types/page_context/index.d.ts +248 -0
  18. package/dist-es/types/redirect/index.d.ts +2 -0
  19. package/dist-es/types/resolvers/index.d.ts +11 -0
  20. package/dist-es/types/transform/index.d.ts +2 -0
  21. package/dist-es/types/types/index.d.ts +39 -0
  22. package/dist-es/types/validate/index.d.ts +5 -0
  23. package/package.json +71 -64
  24. package/dist-cjs/auth/index.js +0 -13
  25. package/dist-cjs/aws/aws_lambda_helper.js +0 -49
  26. package/dist-cjs/aws/aws_s3_helper.js +0 -1
  27. package/dist-cjs/aws/data_models.js +0 -2
  28. package/dist-cjs/aws/index.js +0 -4
  29. package/dist-cjs/commander/index.jsx +0 -280
  30. package/dist-cjs/constants/index.js +0 -87
  31. package/dist-cjs/contents/index.jsx +0 -32
  32. package/dist-cjs/files/index.js +0 -27
  33. package/dist-cjs/graphql/index.js +0 -217
  34. package/dist-cjs/headers/index.js +0 -68
  35. package/dist-cjs/images/index.js +0 -13
  36. package/dist-cjs/json/index.js +0 -135
  37. package/dist-cjs/package.json +0 -3
  38. package/dist-cjs/page_context/index.js +0 -494
  39. package/dist-cjs/redirect/index.js +0 -15
  40. package/dist-cjs/renderer/index.jsx +0 -66
  41. package/dist-cjs/resolvers/index.js +0 -35
  42. package/dist-cjs/transform/index.js +0 -40
  43. package/dist-cjs/types/index.js +0 -2
  44. package/dist-cjs/validate/index.js +0 -48
  45. package/dist-es/auth/index.js +0 -11
  46. package/dist-es/aws/aws_lambda_helper.js +0 -41
  47. package/dist-es/aws/aws_s3_helper.js +0 -1
  48. package/dist-es/aws/data_models.js +0 -1
  49. package/dist-es/commander/index.jsx +0 -250
  50. package/dist-es/constants/index.js +0 -84
  51. package/dist-es/contents/index.jsx +0 -31
  52. package/dist-es/files/index.js +0 -22
  53. package/dist-es/graphql/index.js +0 -235
  54. package/dist-es/headers/index.js +0 -57
  55. package/dist-es/images/index.js +0 -9
  56. package/dist-es/json/index.js +0 -125
  57. package/dist-es/package.json +0 -3
  58. package/dist-es/page_context/index.js +0 -511
  59. package/dist-es/redirect/index.js +0 -12
  60. package/dist-es/renderer/index.jsx +0 -60
  61. package/dist-es/resolvers/index.js +0 -31
  62. package/dist-es/transform/index.js +0 -35
  63. package/dist-es/types/index.js +0 -1
  64. package/dist-es/validate/index.js +0 -40
  65. package/dist-types/aws/aws_lambda_helper.d.ts +0 -5
  66. package/dist-types/aws/aws_s3_helper.d.ts +0 -0
  67. package/dist-types/contents/index.d.ts +0 -3
  68. package/dist-types/renderer/index.d.ts +0 -9
  69. /package/{dist-types → dist-cjs/types}/auth/index.d.ts +0 -0
  70. /package/{dist-types → dist-cjs/types}/aws/data_models.d.ts +0 -0
  71. /package/{dist-types → dist-cjs/types}/aws/index.d.ts +0 -0
  72. /package/{dist-types → dist-cjs/types}/commander/index.d.ts +0 -0
  73. /package/{dist-types → dist-cjs/types}/constants/index.d.ts +0 -0
  74. /package/{dist-types → dist-cjs/types}/files/index.d.ts +0 -0
  75. /package/{dist-types → dist-cjs/types}/graphql/index.d.ts +0 -0
  76. /package/{dist-types → dist-cjs/types}/headers/index.d.ts +0 -0
  77. /package/{dist-types → dist-cjs/types}/images/index.d.ts +0 -0
  78. /package/{dist-types → dist-cjs/types}/json/index.d.ts +0 -0
  79. /package/{dist-types → dist-cjs/types}/page_context/index.d.ts +0 -0
  80. /package/{dist-types → dist-cjs/types}/redirect/index.d.ts +0 -0
  81. /package/{dist-types → dist-cjs/types}/resolvers/index.d.ts +0 -0
  82. /package/{dist-types → dist-cjs/types}/transform/index.d.ts +0 -0
  83. /package/{dist-types → dist-cjs/types}/validate/index.d.ts +0 -0
  84. /package/dist-es/{aws/index.js → types/aws/index.d.ts} +0 -0
@@ -1,235 +0,0 @@
1
- import pluralize from 'pluralize';
2
- import { Kind } from 'graphql/language';
3
- export const operationTypes = {
4
- MUTATIONS: {
5
- CREATE: 'mutations.create',
6
- DELETE: 'mutations.delete',
7
- UPDATE: 'mutations.update',
8
- ACTION: 'mutations.action',
9
- },
10
- QUERIES: 'queries',
11
- SUBSCRIPTIONS: 'subscriptions',
12
- };
13
- export const draggableTypes = {
14
- ACTION: 'action',
15
- ENTITY: 'entity',
16
- FRAGMENT: 'fragment',
17
- VARIABLES: 'variables',
18
- };
19
- export const getFields = ({ arg }) => (arg.type.getFields ? arg.type.getFields() : arg.type._nameLookup ? arg.type._nameLookup : arg.type.ofType && arg.type.ofType.getFields ? arg.type.ofType.getFields() : arg.type.ofType && arg.type.ofType.ofType && arg.type.ofType.ofType.getFields ? arg.type.ofType.ofType.getFields() : {});
20
- export const getFieldsStringified = ({ arg }) => (arg.type.getFields ? Object.keys(arg.type.getFields()) : arg.type.getValues ? Object.keys(arg.type.getValues()) : arg.type.ofType && arg.type.ofType.getFields ? Object.keys(arg.type.ofType.getFields()) : []);
21
- export const getTypeKind = (object) => {
22
- return object && object.astNode && object.astNode.type && object.astNode.type.kind ? object.astNode.type.kind : object && object.astNode && object.astNode.kind ? object.astNode.kind : undefined;
23
- };
24
- export const getTypeName = (object) => {
25
- return object && object.type ? (object.type.ofType ? object.type.ofType.name : object && object.type.name && object.type.name) : object.astNode && object.astNode.name;
26
- };
27
- export const getOperationObjectFromSchema = ({ operationName, schema }) => {
28
- const queries = schema.getQueryType().getFields();
29
- const mutations = schema.getMutationType().getFields();
30
- const subscriptions = schema.getSubscriptionType().getFields();
31
- let operationType;
32
- let rv;
33
- if (operationName in mutations) {
34
- operationType = getOperationTypeForMutation({ operationName });
35
- rv = mutations[operationName];
36
- }
37
- else if (operationName in queries) {
38
- operationType = operationTypes.QUERIES;
39
- rv = queries[operationName];
40
- }
41
- else if (operationName in subscriptions) {
42
- operationType = operationTypes.SUBSCRIPTIONS;
43
- rv = subscriptions[operationName];
44
- }
45
- return [rv, operationType];
46
- };
47
- export const getOperationTypeForMutation = ({ operationName }) => {
48
- let operationType;
49
- if (operationName.includes('create')) {
50
- operationType = operationTypes.MUTATIONS.CREATE;
51
- }
52
- else if (operationName.includes('update')) {
53
- operationType = operationTypes.MUTATIONS.UPDATE;
54
- }
55
- else if (operationName.includes('delete')) {
56
- operationType = operationTypes.MUTATIONS.DELETE;
57
- }
58
- else {
59
- operationType = operationTypes.MUTATIONS.ACTION;
60
- }
61
- return operationType;
62
- };
63
- export const getVariablesKeys = ({ variables, operationType }) => {
64
- if (variables && variables != '') {
65
- variables = JSON.parse(variables);
66
- switch (operationType) {
67
- case operationTypes.QUERIES:
68
- const where = variables && variables.where;
69
- return where && typeof where === 'object' ? Object.keys(where) : undefined;
70
- case operationTypes.MUTATIONS.CREATE:
71
- const data = variables && variables['data'];
72
- return data && Array.isArray(data) ? Object.keys(data[0]) : typeof data === 'object' ? Object.keys(data) : undefined;
73
- default:
74
- const obj = (variables && variables['data']) || variables.where;
75
- return obj && Array.isArray(obj) && obj.length > 0 ? Object.keys(obj[0]) : typeof obj === 'object' ? Object.keys(obj) : undefined;
76
- }
77
- }
78
- };
79
- export const insertNewVariable = ({ operationName, schema, key, value, _variables, action, ctx }) => {
80
- const [raw, _] = getOperationObjectFromSchema({ operationName, schema });
81
- Object.keys(_variables).forEach((upper_key) => {
82
- if (raw) {
83
- parseArgs({ raw, _variables, upper_key, key, action, value });
84
- }
85
- else {
86
- throw `No Schema Action - '${operationName} - Go check the schema again'`;
87
- }
88
- });
89
- };
90
- export const isArgMandatory = (arg) => {
91
- const kind = getTypeKind(arg);
92
- const rv = kind === Kind.NON_NULL_TYPE;
93
- return rv;
94
- };
95
- export const parseInputDataToDataObject = ({ key, value, parent, method, list, state, ...rest }) => {
96
- let rv = state;
97
- const type = typeof value;
98
- switch (type) {
99
- case 'string':
100
- case 'number':
101
- case 'boolean':
102
- case 'bigint':
103
- rv = parent
104
- ? {
105
- ...rv,
106
- [parent]: {
107
- ...rv[parent],
108
- [method]: {
109
- ...rv[parent][method],
110
- [key]: value,
111
- },
112
- },
113
- }
114
- : {
115
- ...rv,
116
- [key]: value,
117
- };
118
- break;
119
- case 'object':
120
- rv = parent
121
- ? {
122
- [parent]: {
123
- ...rv[parent],
124
- [method]: {
125
- ...rv[parent][method],
126
- },
127
- },
128
- }
129
- : {
130
- ...rv,
131
- [key]: {
132
- [method]: list ? value.map(({ id }) => ({ id })) : { id: value.id },
133
- },
134
- };
135
- break;
136
- }
137
- return rv;
138
- };
139
- const buildValue = ({ name, value }) => {
140
- let rv;
141
- switch (name) {
142
- case 'Float':
143
- rv = value || 0.0;
144
- break;
145
- case 'Int':
146
- rv = value || 0;
147
- break;
148
- case 'ID':
149
- rv = value || '000000000000000000000000';
150
- break;
151
- case 'String':
152
- rv = value || '';
153
- break;
154
- default:
155
- rv = name.includes('many') ? { connect: [{ id: value || '' }] } : { connect: { id: value || '' } };
156
- break;
157
- }
158
- return rv;
159
- };
160
- const parseArgs = ({ raw, _variables, upper_key, key, action, value }) => {
161
- raw.args.forEach((arg) => {
162
- if (upper_key === arg.name) {
163
- const fields = getFieldsStringified({ arg });
164
- const fields_obj = getFields({ arg });
165
- if (fields.length > 0) {
166
- parseFields({
167
- fields,
168
- fields_obj,
169
- _variables,
170
- upper_key,
171
- key,
172
- action,
173
- value,
174
- });
175
- }
176
- else {
177
- throw `Schema Object/Action Does Not Have Any Fields`;
178
- }
179
- }
180
- });
181
- };
182
- const parseFields = ({ fields, fields_obj, key, _variables, upper_key, value, action }) => {
183
- let _existsInFields = false;
184
- fields.forEach((field) => {
185
- const _key = pluralize(key);
186
- const exists = field.includes(_key.toLowerCase()) || field.includes(key.toLowerCase());
187
- if (exists === true) {
188
- _existsInFields = true;
189
- const kind = getTypeName(fields_obj[field]);
190
- if (action === 'mutation') {
191
- setMutationEntityVariables({
192
- field,
193
- kind,
194
- _variables,
195
- upper_key,
196
- value,
197
- });
198
- }
199
- else {
200
- setQueryEntityVariables({
201
- field,
202
- kind,
203
- _variables,
204
- upper_key,
205
- value,
206
- });
207
- }
208
- }
209
- });
210
- if (_existsInFields === false)
211
- throw `Schema Object/Action Does Not Support - '${key}'`;
212
- };
213
- const setMutationEntityVariables = ({ field, kind, _variables, upper_key, value }) => {
214
- Array.isArray(_variables[upper_key])
215
- ?
216
- (_variables[upper_key] = _variables[upper_key].map((item, i) => ({
217
- ...item,
218
- [field.toLowerCase()]: buildValue({ name: kind, value }),
219
- })))
220
- : (_variables[upper_key] = {
221
- ..._variables[upper_key],
222
- [field.toLowerCase()]: buildValue({ name: kind, value }),
223
- });
224
- };
225
- const setQueryEntityVariables = ({ field, kind, _variables, upper_key, value }) => {
226
- field.includes('some')
227
- ? (_variables[upper_key] = {
228
- ..._variables[upper_key],
229
- [field]: { id_in: [value] },
230
- })
231
- : (_variables[upper_key] = {
232
- ..._variables[upper_key],
233
- [field]: value,
234
- });
235
- };
@@ -1,57 +0,0 @@
1
- import { destroyCookie, parseCookies, setCookie } from 'nookies';
2
- export const defaultHeaders = {
3
- 'bundle-name': '',
4
- cur: {
5
- _id: '5e8c8dfdfca1360007d7b654',
6
- value: '5e8c8dfdfca1360007d7b654',
7
- code: 'usd',
8
- namePlural: 'us dollars',
9
- symbol: '$',
10
- },
11
- hl: 'en',
12
- 'is-explain': true,
13
- 'last-activity': 0,
14
- };
15
- export const getHeaders = (ctx, options = {}) => {
16
- let _headers = parseCookies(ctx)['fixefy:headers'];
17
- _headers = _headers && typeof _headers === 'string' ? JSON.parse(_headers) : typeof _headers === 'object' ? _headers : {};
18
- const headers = {
19
- ...defaultHeaders,
20
- ws: getWorkspace(ctx),
21
- cur: getCurrency(ctx)._id,
22
- 'last-activity': getLastActivity(ctx),
23
- };
24
- return headers;
25
- };
26
- export const setHeaders = (ctx, _headers) => {
27
- typeof _headers === 'string' ? setCookie(ctx, 'fixefy:headers', { ...JSON.parse(_headers) }, { maxAge: 7 * 24 * 60 * 60, path: '/' }) : setCookie(ctx, 'fixefy:headers', { ..._headers }, { maxAge: 7 * 24 * 60 * 60, path: '/' });
28
- };
29
- export const getLastActivity = (ctx) => { };
30
- export const setLastActivity = (ctx) => { };
31
- export const flushLastActivity = (ctx) => { };
32
- export const getWorkspace = (ctx) => {
33
- const rv = parseCookies(ctx)['ws'] ?? defaultHeaders['ws'];
34
- return rv;
35
- };
36
- export const setWorkspace = (ctx, ws) => {
37
- setCookie(ctx, 'ws', ws, { maxAge: 7 * 24 * 60 * 60, path: '/' });
38
- };
39
- export const flushWorkspace = (ctx) => {
40
- destroyCookie(ctx, 'ws', { path: '/' });
41
- };
42
- export const flushAll = (ctx) => {
43
- flushLastActivity(ctx);
44
- flushWorkspace(ctx);
45
- };
46
- export const setCurrency = (ctx, currency) => {
47
- setCookie(ctx, 'cur', JSON.stringify(currency), { maxAge: 7 * 24 * 60 * 60, path: '/' });
48
- };
49
- export const getCurrency = (ctx) => {
50
- const cur = parseCookies(ctx)['cur'] ?? defaultHeaders['cur'];
51
- if (cur) {
52
- if (cur === 'usd' || cur === 'eur') {
53
- setCurrency(ctx, defaultHeaders['cur']);
54
- }
55
- return typeof cur === 'string' ? JSON.parse(cur) : cur;
56
- }
57
- };
@@ -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,125 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }