docs(changeset): feat(error-manager): implement centralized error reporting system
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { Button, Checkbox, Divider, Group, Stack, TagsInput, TextInput } from '@mantine/core';
|
||||
import { useLocalStorage } from '@mantine/hooks';
|
||||
import { useRef, useState } from 'react';
|
||||
@@ -22,9 +23,20 @@ export const GridlerGoAPIExampleEventlog = () => {
|
||||
const [selectRow, setSelectRow] = useState<string | undefined>('');
|
||||
const [values, setValues] = useState<Array<Record<string, any>>>([]);
|
||||
const [search, setSearch] = useState<string>('');
|
||||
const [formProps, setFormProps] = useState<{ onChange?: any; onClose?: any; opened: boolean; request: any; title?: string; values: any; } | null>({
|
||||
onChange: (_request: string, data: any) => { ref.current?.refresh({ value: data }); },
|
||||
onClose: () => { setFormProps((cv) => ({ ...cv, opened: false, request: null, values: null })) },
|
||||
const [formProps, setFormProps] = useState<{
|
||||
onChange?: any;
|
||||
onClose?: any;
|
||||
opened: boolean;
|
||||
request: any;
|
||||
title?: string;
|
||||
values: any;
|
||||
} | null>({
|
||||
onChange: (_request: string, data: any) => {
|
||||
ref.current?.refresh({ value: data });
|
||||
},
|
||||
onClose: () => {
|
||||
setFormProps((cv) => ({ ...cv, opened: false, request: null, values: null }));
|
||||
},
|
||||
opened: false,
|
||||
request: null,
|
||||
values: null,
|
||||
@@ -33,7 +45,8 @@ export const GridlerGoAPIExampleEventlog = () => {
|
||||
const columns: GridlerColumns = [
|
||||
{
|
||||
Cell: (row) => {
|
||||
const process = `${row?.cql2?.length > 0
|
||||
const process = `${
|
||||
row?.cql2?.length > 0
|
||||
? '🔖'
|
||||
: row?.cql1?.length > 0
|
||||
? '📕'
|
||||
@@ -42,7 +55,7 @@ export const GridlerGoAPIExampleEventlog = () => {
|
||||
: row?.status === 2
|
||||
? '🔒'
|
||||
: '⚙️'
|
||||
} ${String(row?.id_process ?? '0')}`;
|
||||
} ${String(row?.id_process ?? '0')}`;
|
||||
|
||||
return {
|
||||
data: process,
|
||||
@@ -139,28 +152,28 @@ export const GridlerGoAPIExampleEventlog = () => {
|
||||
changeOnActiveClick={true}
|
||||
descriptionField={'process'}
|
||||
onRequestForm={(request, data) => {
|
||||
setFormProps((cv)=> {
|
||||
return {...cv, opened: true, request: request as any, values: data as any}
|
||||
})
|
||||
setFormProps((cv) => {
|
||||
return { ...cv, opened: true, request: request as any, values: data as any };
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Gridler>
|
||||
<FormerDialog
|
||||
former={{
|
||||
request: formProps?.request ?? "insert",
|
||||
values: formProps?.values,
|
||||
}}
|
||||
onClose={formProps?.onClose}
|
||||
opened={formProps?.opened ?? false}
|
||||
title={formProps?.title ?? 'Process Form'}
|
||||
>
|
||||
<Stack>
|
||||
<TextInputCtrl label="Process Name" name="process" />
|
||||
<NumberInputCtrl label="Sequence" name="sequence" />
|
||||
<InlineWrapper label="Type" promptWidth={200}>
|
||||
<NativeSelectCtrl data={["trigger","function","view"]} name="type"/>
|
||||
</InlineWrapper>
|
||||
</Stack>
|
||||
<FormerDialog
|
||||
former={{
|
||||
request: formProps?.request ?? 'insert',
|
||||
values: formProps?.values,
|
||||
}}
|
||||
onClose={formProps?.onClose}
|
||||
opened={formProps?.opened ?? false}
|
||||
title={formProps?.title ?? 'Process Form'}
|
||||
>
|
||||
<Stack>
|
||||
<TextInputCtrl label="Process Name" name="process" />
|
||||
<NumberInputCtrl label="Sequence" name="sequence" />
|
||||
<InlineWrapper label="Type" promptWidth={200}>
|
||||
<NativeSelectCtrl data={['trigger', 'function', 'view']} name="type" />
|
||||
</InlineWrapper>
|
||||
</Stack>
|
||||
</FormerDialog>
|
||||
<Divider />
|
||||
<Group>
|
||||
@@ -222,6 +235,6 @@ export const GridlerGoAPIExampleEventlog = () => {
|
||||
Goto 2050
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack >
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
//@ts-nocheck
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
//@ts-nocheck
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
|
||||
|
||||
@@ -1,35 +1,34 @@
|
||||
import {b64EncodeUnicode} from '@warkypublic/artemis-kit/base64'
|
||||
const TOKEN_KEY = 'gridler_golang_restapi_v2_token'
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { b64EncodeUnicode } from '@warkypublic/artemis-kit/base64';
|
||||
const TOKEN_KEY = 'gridler_golang_restapi_v2_token';
|
||||
|
||||
export type APIOptionsType = {
|
||||
autocreate?: boolean
|
||||
autoref?: boolean
|
||||
baseurl?: string
|
||||
getAPIProvider?: () => { provider: string; providerKey: string }
|
||||
getAuthToken?: () => string
|
||||
operations?: Array<FetchAPIOperation>
|
||||
postfix?: string
|
||||
prefix?: string
|
||||
requestTimeoutSec?: number
|
||||
}
|
||||
|
||||
|
||||
autocreate?: boolean;
|
||||
autoref?: boolean;
|
||||
baseurl?: string;
|
||||
getAPIProvider?: () => { provider: string; providerKey: string };
|
||||
getAuthToken?: () => string;
|
||||
operations?: Array<FetchAPIOperation>;
|
||||
postfix?: string;
|
||||
prefix?: string;
|
||||
requestTimeoutSec?: number;
|
||||
};
|
||||
|
||||
export interface APIResponse {
|
||||
errmsg: string
|
||||
payload?: any
|
||||
retval: number
|
||||
errmsg: string;
|
||||
payload?: any;
|
||||
retval: number;
|
||||
}
|
||||
export interface FetchAPIOperation {
|
||||
name?: string
|
||||
op?: string
|
||||
type: GoAPIHeaderTypes //x-fieldfilter
|
||||
value: string
|
||||
name?: string;
|
||||
op?: string;
|
||||
type: GoAPIHeaderTypes; //x-fieldfilter
|
||||
value: string;
|
||||
}
|
||||
/**
|
||||
* @description Types for the Go Rest API headers
|
||||
* @typedef {String} GoAPIEnum
|
||||
*/
|
||||
*/
|
||||
export type GoAPIEnum =
|
||||
| 'advsql'
|
||||
| 'api-key'
|
||||
@@ -42,7 +41,7 @@ export type GoAPIEnum =
|
||||
| 'association_autoupdate'
|
||||
| 'association-update'
|
||||
| 'cql-sel'
|
||||
| 'cursor-backward'// For x cursor-backward header
|
||||
| 'cursor-backward' // For x cursor-backward header
|
||||
| 'cursor-forward' // For x cursor-forward header
|
||||
| 'custom-sql-join'
|
||||
| 'custom-sql-or'
|
||||
@@ -72,28 +71,24 @@ export type GoAPIEnum =
|
||||
| 'simpleapi'
|
||||
| 'skipcache'
|
||||
| 'skipcount'
|
||||
| 'sort'
|
||||
| 'sort';
|
||||
|
||||
export type GoAPIHeaderKeys = `x-${GoAPIEnum}`;
|
||||
|
||||
export type GoAPIHeaderKeys = `x-${GoAPIEnum}`
|
||||
|
||||
|
||||
export type GoAPIHeaderTypes = GoAPIEnum & string
|
||||
|
||||
export type GoAPIHeaderTypes = GoAPIEnum & string;
|
||||
|
||||
export interface GoAPIOperation {
|
||||
name?: string
|
||||
op?: string
|
||||
type: GoAPIHeaderTypes //x-fieldfilter
|
||||
value: string
|
||||
name?: string;
|
||||
op?: string;
|
||||
type: GoAPIHeaderTypes; //x-fieldfilter
|
||||
value: string;
|
||||
}
|
||||
export interface MetaData {
|
||||
limit?: number
|
||||
offset?: number
|
||||
total?: number
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
total?: number;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds an array of objects by encoding specific values and setting headers.
|
||||
*
|
||||
@@ -105,50 +100,49 @@ const buildGoAPIOperation = (
|
||||
ops: Array<FetchAPIOperation>,
|
||||
headers?: Headers
|
||||
): Array<FetchAPIOperation> => {
|
||||
const newops = [...ops.filter((i) => i !== undefined && i.type !== undefined)]
|
||||
const newops = [...ops.filter((i) => i !== undefined && i.type !== undefined)];
|
||||
|
||||
|
||||
for (let i = 0; i < newops.length; i++) {
|
||||
if (!newops[i].name || newops[i].name === '') {
|
||||
newops[i].name = ''
|
||||
newops[i].name = '';
|
||||
}
|
||||
if (newops[i].type === 'files' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
if (newops[i].type === 'advsql' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
|
||||
if (newops[i].type === 'custom-sql-or' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
|
||||
if (newops[i].type === 'custom-sql-join' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
if (newops[i].type === 'not-select-fields' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
if (newops[i].type === 'custom-sql-w' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
if (newops[i].type === 'select-fields' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
if (newops[i].type === 'cql-sel' && !newops[i].value.startsWith('__')) {
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`
|
||||
newops[i].value = `__${b64EncodeUnicode(newops[i].value)}__`;
|
||||
}
|
||||
|
||||
if (headers) {
|
||||
if (!newops || newops.length === 0) {
|
||||
headers.set(`x-limit`, '10')
|
||||
headers.set(`x-limit`, '10');
|
||||
}
|
||||
|
||||
if (newops[i].type === 'association_autoupdate') {
|
||||
headers.set(`association_autoupdate`, newops[i].value ?? '1')
|
||||
headers.set(`association_autoupdate`, newops[i].value ?? '1');
|
||||
}
|
||||
if (newops[i].type === 'association_autocreate') {
|
||||
headers.set(`association_autocreate`, newops[i].value ?? '1')
|
||||
headers.set(`association_autocreate`, newops[i].value ?? '1');
|
||||
}
|
||||
if (
|
||||
newops[i].type === 'searchop' ||
|
||||
@@ -158,20 +152,20 @@ const buildGoAPIOperation = (
|
||||
headers.set(
|
||||
encodeURIComponent(`x-${newops[i].type}-${newops[i].op}-${newops[i].name}`),
|
||||
String(newops[i].value)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
headers.set(
|
||||
encodeURIComponent(
|
||||
`x-${newops[i].type}${newops[i].name && newops[i].name !== '' ? '-' + newops[i].name : ''}`
|
||||
),
|
||||
String(newops[i].value)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newops
|
||||
}
|
||||
return newops;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the headers from an array of FetchAPIOperation objects and returns them as an object.
|
||||
@@ -183,77 +177,75 @@ const GoAPIHeaders = (
|
||||
ops: Array<FetchAPIOperation>,
|
||||
headers?: Headers
|
||||
): { [key: string]: string } => {
|
||||
const head = new Headers()
|
||||
const headerlist: Record<string,string> = {}
|
||||
const head = new Headers();
|
||||
const headerlist: Record<string, string> = {};
|
||||
|
||||
const authToken = getAuthToken?.()
|
||||
const authToken = getAuthToken?.();
|
||||
if (authToken && authToken !== '') {
|
||||
|
||||
head.set('Authorization', `Token ${authToken}`)
|
||||
head.set('Authorization', `Token ${authToken}`);
|
||||
} else {
|
||||
const token = getAuthToken()
|
||||
const token = getAuthToken();
|
||||
if (token) {
|
||||
head.set('Authorization', `Token ${token}`)
|
||||
head.set('Authorization', `Token ${token}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (headers) {
|
||||
headers.forEach((v, k) => {
|
||||
head.set(k, v)
|
||||
})
|
||||
head.set(k, v);
|
||||
});
|
||||
}
|
||||
const distinctOperations: Array<FetchAPIOperation> = []
|
||||
const distinctOperations: Array<FetchAPIOperation> = [];
|
||||
|
||||
for (const value of ops?.filter((val) => !!val) ?? []) {
|
||||
const index = distinctOperations.findIndex(
|
||||
(searchValue) => searchValue.name === value.name && searchValue.type === value.type
|
||||
)
|
||||
);
|
||||
if (index === -1) {
|
||||
distinctOperations.push(value)
|
||||
distinctOperations.push(value);
|
||||
} else {
|
||||
distinctOperations[index] = value
|
||||
distinctOperations[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
buildGoAPIOperation(distinctOperations, head)
|
||||
buildGoAPIOperation(distinctOperations, head);
|
||||
|
||||
head?.forEach((v, k) => {
|
||||
headerlist[k] = v
|
||||
})
|
||||
headerlist[k] = v;
|
||||
});
|
||||
|
||||
if (headers) {
|
||||
for (const key of Object.keys(headerlist)) {
|
||||
headers.set(key, headerlist[key])
|
||||
headers.set(key, headerlist[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return headerlist
|
||||
}
|
||||
return headerlist;
|
||||
};
|
||||
|
||||
const callbacks = {
|
||||
getAuthToken: () => {
|
||||
getAuthToken: () => {
|
||||
if (localStorage) {
|
||||
const token = localStorage.getItem(TOKEN_KEY)
|
||||
if (token) {
|
||||
return token
|
||||
}
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
if (token) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the authentication token from local storage.
|
||||
*
|
||||
* @return {string | undefined} The authentication token if found, otherwise undefined
|
||||
*/
|
||||
const getAuthToken = () => callbacks?.getAuthToken?.()
|
||||
const getAuthToken = () => callbacks?.getAuthToken?.();
|
||||
|
||||
const setAuthTokenCallback = (cb: ()=> string) => {
|
||||
callbacks.getAuthToken = cb
|
||||
return callbacks.getAuthToken
|
||||
}
|
||||
const setAuthTokenCallback = (cb: () => string) => {
|
||||
callbacks.getAuthToken = cb;
|
||||
return callbacks.getAuthToken;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the authentication token in the local storage.
|
||||
@@ -262,9 +254,8 @@ const setAuthTokenCallback = (cb: ()=> string) => {
|
||||
*/
|
||||
const setAuthToken = (token: string) => {
|
||||
if (localStorage) {
|
||||
localStorage.setItem(TOKEN_KEY, token)
|
||||
localStorage.setItem(TOKEN_KEY, token);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export {buildGoAPIOperation,getAuthToken,GoAPIHeaders,setAuthToken,setAuthTokenCallback}
|
||||
export { buildGoAPIOperation, getAuthToken, GoAPIHeaders, setAuthToken, setAuthTokenCallback };
|
||||
|
||||
Reference in New Issue
Block a user