@apia/api 1.0.4 → 2.0.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.
Files changed (37) hide show
  1. package/dist/ApiaApiContext.js +15 -0
  2. package/dist/ApiaApiContext.js.map +1 -0
  3. package/dist/ApiaApiHandler.d.ts +62 -0
  4. package/dist/ApiaApiHandler.d.ts.map +1 -0
  5. package/dist/ApiaApiHandler.js +374 -0
  6. package/dist/ApiaApiHandler.js.map +1 -0
  7. package/dist/apiaApi.d.ts +156 -0
  8. package/dist/apiaApi.d.ts.map +1 -0
  9. package/dist/apiaApi.js +458 -0
  10. package/dist/apiaApi.js.map +1 -0
  11. package/dist/buttons/ApiaApiButtonsContainer.js +129 -0
  12. package/dist/buttons/ApiaApiButtonsContainer.js.map +1 -0
  13. package/dist/fields/ApiaApiCheckbox.js +39 -0
  14. package/dist/fields/ApiaApiCheckbox.js.map +1 -0
  15. package/dist/fields/ApiaApiFieldsContainer.js +213 -0
  16. package/dist/fields/ApiaApiFieldsContainer.js.map +1 -0
  17. package/dist/fields/ApiaApiFileInput.js +34 -0
  18. package/dist/fields/ApiaApiFileInput.js.map +1 -0
  19. package/dist/fields/ApiaApiInput.d.ts +20 -0
  20. package/dist/fields/ApiaApiInput.d.ts.map +1 -0
  21. package/dist/fields/ApiaApiInput.js +110 -0
  22. package/dist/fields/ApiaApiInput.js.map +1 -0
  23. package/dist/fields/ApiaApiRadio.js +43 -0
  24. package/dist/fields/ApiaApiRadio.js.map +1 -0
  25. package/dist/fields/ApiaApiSelect.js +64 -0
  26. package/dist/fields/ApiaApiSelect.js.map +1 -0
  27. package/dist/fields/ApiaApiTextArea.js +50 -0
  28. package/dist/fields/ApiaApiTextArea.js.map +1 -0
  29. package/dist/index.d.ts +5 -255
  30. package/dist/index.js +4 -1771
  31. package/dist/index.js.map +1 -1
  32. package/dist/types.d.ts +39 -0
  33. package/dist/types.d.ts.map +1 -0
  34. package/package.json +23 -36
  35. package/LICENSE.md +0 -21
  36. package/README.md +0 -26
  37. package/cleanDist.json +0 -3
@@ -0,0 +1,50 @@
1
+ import { jsx } from '@apia/theme/jsx-runtime';
2
+ import { classToValidate, classToValidationFunction, Textarea } from '@apia/validations';
3
+ import React__default from 'react';
4
+
5
+ const ApiaApiTextArea = (props) => {
6
+ const element = React__default.useMemo(() => props.element, [props.element]);
7
+ const className = React__default.useMemo(
8
+ () => element.class ? `handler__textarea ${element.class}` : "handler__textarea",
9
+ [element.class]
10
+ );
11
+ const validationRules = React__default.useMemo(
12
+ () => ({
13
+ required: element.mandatory,
14
+ maxLength: element.maxlength ? Number(element.maxlength) : void 0,
15
+ pattern: element.regExp,
16
+ patternMessage: element.regExpMessage,
17
+ ...classToValidate(element.class)
18
+ }),
19
+ [
20
+ element.class,
21
+ element.mandatory,
22
+ element.maxlength,
23
+ element.regExp,
24
+ element.regExpMessage
25
+ ]
26
+ );
27
+ const validationFunction = React__default.useMemo(
28
+ () => classToValidationFunction(element.class),
29
+ [element.class]
30
+ );
31
+ return /* @__PURE__ */ jsx(
32
+ Textarea,
33
+ {
34
+ className,
35
+ name: element.id || element.name,
36
+ label: element.text,
37
+ title: element.title || element.text,
38
+ value: element.value,
39
+ readOnly: element.readonly,
40
+ disabled: element.disabled,
41
+ validationFunction,
42
+ validationRules,
43
+ onChange: element.onChange
44
+ }
45
+ );
46
+ };
47
+ ApiaApiTextArea.displayName = "ApiaApiTextArea";
48
+
49
+ export { ApiaApiTextArea };
50
+ //# sourceMappingURL=ApiaApiTextArea.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiaApiTextArea.js","sources":["../../src/fields/ApiaApiTextArea.tsx"],"sourcesContent":["import {\n classToValidate,\n classToValidationFunction,\n Textarea,\n} from '@apia/validations';\nimport React from 'react';\nimport { TApiaApiField } from '../ApiaApiHandler';\n\nexport const ApiaApiTextArea = (props: TApiaApiField) => {\n const element = React.useMemo(() => props.element, [props.element]);\n\n const className = React.useMemo(\n () =>\n element.class\n ? `handler__textarea ${element.class}`\n : 'handler__textarea',\n [element.class],\n );\n const validationRules = React.useMemo(\n () => ({\n required: element.mandatory,\n maxLength: element.maxlength ? Number(element.maxlength) : undefined,\n pattern: element.regExp,\n patternMessage: element.regExpMessage,\n ...classToValidate(element.class),\n }),\n [\n element.class,\n element.mandatory,\n element.maxlength,\n element.regExp,\n element.regExpMessage,\n ],\n );\n const validationFunction = React.useMemo(\n () => classToValidationFunction(element.class),\n [element.class],\n );\n\n return (\n <Textarea\n className={className}\n name={element.id || element.name}\n label={element.text}\n title={element.title || element.text}\n value={element.value}\n readOnly={element.readonly}\n disabled={element.disabled}\n validationFunction={validationFunction}\n validationRules={validationRules}\n onChange={element.onChange}\n />\n );\n};\n\nApiaApiTextArea.displayName = 'ApiaApiTextArea';\n"],"names":["React"],"mappings":";;;;AAQa,MAAA,eAAA,GAAkB,CAAC,KAAyB,KAAA;AACvD,EAAM,MAAA,OAAA,GAAUA,eAAM,OAAQ,CAAA,MAAM,MAAM,OAAS,EAAA,CAAC,KAAM,CAAA,OAAO,CAAC,CAAA,CAAA;AAElE,EAAA,MAAM,YAAYA,cAAM,CAAA,OAAA;AAAA,IACtB,MACE,OAAQ,CAAA,KAAA,GACJ,CAAqB,kBAAA,EAAA,OAAA,CAAQ,KAAK,CAClC,CAAA,GAAA,mBAAA;AAAA,IACN,CAAC,QAAQ,KAAK,CAAA;AAAA,GAChB,CAAA;AACA,EAAA,MAAM,kBAAkBA,cAAM,CAAA,OAAA;AAAA,IAC5B,OAAO;AAAA,MACL,UAAU,OAAQ,CAAA,SAAA;AAAA,MAClB,WAAW,OAAQ,CAAA,SAAA,GAAY,MAAO,CAAA,OAAA,CAAQ,SAAS,CAAI,GAAA,KAAA,CAAA;AAAA,MAC3D,SAAS,OAAQ,CAAA,MAAA;AAAA,MACjB,gBAAgB,OAAQ,CAAA,aAAA;AAAA,MACxB,GAAG,eAAgB,CAAA,OAAA,CAAQ,KAAK,CAAA;AAAA,KAClC,CAAA;AAAA,IACA;AAAA,MACE,OAAQ,CAAA,KAAA;AAAA,MACR,OAAQ,CAAA,SAAA;AAAA,MACR,OAAQ,CAAA,SAAA;AAAA,MACR,OAAQ,CAAA,MAAA;AAAA,MACR,OAAQ,CAAA,aAAA;AAAA,KACV;AAAA,GACF,CAAA;AACA,EAAA,MAAM,qBAAqBA,cAAM,CAAA,OAAA;AAAA,IAC/B,MAAM,yBAA0B,CAAA,OAAA,CAAQ,KAAK,CAAA;AAAA,IAC7C,CAAC,QAAQ,KAAK,CAAA;AAAA,GAChB,CAAA;AAEA,EACE,uBAAA,GAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,SAAA;AAAA,MACA,IAAA,EAAM,OAAQ,CAAA,EAAA,IAAM,OAAQ,CAAA,IAAA;AAAA,MAC5B,OAAO,OAAQ,CAAA,IAAA;AAAA,MACf,KAAA,EAAO,OAAQ,CAAA,KAAA,IAAS,OAAQ,CAAA,IAAA;AAAA,MAChC,OAAO,OAAQ,CAAA,KAAA;AAAA,MACf,UAAU,OAAQ,CAAA,QAAA;AAAA,MAClB,UAAU,OAAQ,CAAA,QAAA;AAAA,MAClB,kBAAA;AAAA,MACA,eAAA;AAAA,MACA,UAAU,OAAQ,CAAA,QAAA;AAAA,KAAA;AAAA,GACpB,CAAA;AAEJ,EAAA;AAEA,eAAA,CAAgB,WAAc,GAAA,iBAAA;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,255 +1,5 @@
1
- import * as React from 'react';
2
- import React__default from 'react';
3
- import { AxiosResponse, AxiosRequestConfig } from 'axios';
4
- import { TModify, TApiaLoad, TApiaFormElement } from '@apia/util';
5
- import { TNotificationMessage, notify } from '@apia/notifications';
6
- import { TModal } from '@apia/components';
7
- import QueryString from 'qs';
8
-
9
- declare function getConfig<LoadType>(outerBehaveConfig?: IApiaApiRequestConfig<LoadType>): IApiaApiRequestConfig<unknown> & IApiaApiRequestConfig<LoadType> & Partial<IApiaApiRequestConfig<unknown>>;
10
- type TApiaApiAxiosResponse<LoadType> = AxiosResponse<LoadType | null> & {
11
- hasError: boolean;
12
- hasMessages: boolean;
13
- };
14
- /**
15
- * IMPORTANT!! The ApiaApi is programmed under the slogan that
16
- * **should never throw an exception**. **Errors** coming from
17
- * connectivity or exceptions on the server **will be handled
18
- * automatically** by ApiaApi, using the notification system
19
- * of the application. It is possible to determine in what context they should
20
- * be thrown those exceptions (global, main, modal) using the
21
- * alertsCategory configuration properties **(see errorsHandling.md)**.
22
- *
23
- * @param url String, the url you want to call
24
- * @param config interface IApiaApiRequestConfig<DataType>;
25
- *
26
- * @throws Nothing
27
- *
28
- * @example
29
- *
30
- * ApiaApi.post<ResponseType>('url...', {
31
- axiosConfig?: AxiosRequestConfig;
32
-
33
- // Configuración de postData
34
- postData? unknown;
35
- postDataTreatement?: 'stringify' | undefined;
36
-
37
- // Configuración de queryString
38
- queryData?: string | Record<string, unknown>;
39
- stringifyOptions?: QueryString.IStringifyOptions;
40
-
41
- // Response validator,
42
- // If it returns true, everything continues correctly
43
- // If it returns false, the ApiaApi throws a standard error.
44
- // If it returns string, ApiaApi throws the error returned in the string.
45
- validateResponse?: (
46
- response: AxiosResponse<DataType | null>,
47
- ) => boolean | string;
48
-
49
- // Configuración de alertas
50
- alertsImportance?: TAlertImportance;
51
-
52
- // Configuración de ApiaApiHandler, falta documentar
53
- handleLoad?: boolean;
54
- eventsHandler?: IEventsHandler;
55
-
56
- // other configuration
57
- colors?: TColors;
58
- debug?: boolean;
59
- }
60
- * @returns The type of the return value depends on the type passed when calling the function. If there was an error it returns null.
61
- */
62
- declare function post<LoadType extends Record<string, unknown> = Record<string, unknown>, DataType = unknown>(url: string | TModify<IApiaApiRequestConfig<LoadType>, {
63
- postData?: DataType;
64
- postDataTreatement?: 'stringify';
65
- }>, config?: TModify<IApiaApiRequestConfig<LoadType>, {
66
- postData?: DataType;
67
- postDataTreatement?: 'stringify';
68
- }>): TApiaApiResult<LoadType>;
69
- declare function post<LoadType extends Record<string, unknown> = Record<string, unknown>, DataType = unknown>(config: TModify<IApiaApiRequestConfig<LoadType>, {
70
- postData?: DataType;
71
- postDataTreatement?: 'stringify';
72
- }>): TApiaApiResult<LoadType>;
73
- /**
74
- * IMPORTANTE!! El ApiaApi está programado bajo la consigna de que
75
- * **no debe tirar núnca una excepción**. **Los errores** provenientes
76
- * de la conectividad o de excepciones en el servidor **serán manejados
77
- * automáticamente** por el ApiaApi utilizando el sistema de notificaciones
78
- * de la aplicación. Es posible determinar en qué contexto deben
79
- * ser lanzadas esas excepciones (global, main, modal) utilizando las
80
- * propiedades de configuración alertsCategory **(ver errorsHandling.md)**.
81
- *
82
- * @param url String, el url al que se desea llamar
83
- * @param config interface IApiaApiRequestConfig<DataType>;
84
- *
85
- * @throws Nothing
86
- *
87
- * @example
88
- *
89
- * ApiaApi.get<TipoDeRespuesta>('url...', {
90
- axiosConfig?: AxiosRequestConfig;
91
-
92
- // Configuración de queryString
93
- queryData?: string | Record<string, unknown>;
94
- stringifyOptions?: QueryString.IStringifyOptions;
95
-
96
- // Validador de respuesta,
97
- // Si devuelve true, todo sigue correctamente
98
- // Si devuelve false, el ApiaApi tira un error estándar.
99
- // Si devuelve string, el ApiaApi tira el error devuelto en el string.
100
- validateResponse?: (
101
- response: AxiosResponse<DataType | null>,
102
- ) => boolean | string;
103
-
104
- // Configuración de alertas
105
- alertsImportance?: TAlertImportance;
106
-
107
- // Configuración de ApiaApiHandler, falta documentar
108
- handleLoad?: boolean;
109
- eventsHandler?: IEventsHandler;
110
-
111
- // Otra configuración
112
- colors?: TColors;
113
- debug?: boolean;
114
- }
115
- * @returns El tipo del valor devuelto depende del tipo pasado al llamar a la función. Si hubo un error devuelve null
116
- */
117
- declare function get<LoadType extends Record<string, unknown> = Record<string, unknown>>(url: string | IApiaApiRequestConfig<LoadType>, config?: IApiaApiRequestConfig<LoadType>): TApiaApiResult<LoadType>;
118
- declare function get<LoadType extends Record<string, unknown> = Record<string, unknown>>(config: IApiaApiRequestConfig<LoadType>): TApiaApiResult<LoadType>;
119
- declare const ApiaApi: {
120
- get: typeof get;
121
- getConfig: typeof getConfig;
122
- post: typeof post;
123
- };
124
- /**
125
- * Creates an url based on the general requirements of Apia.
126
- * If the ajaxUrl property is not passed, it will use the
127
- * window.URL_REQUEST_AJAX. Its use is very simple, just pass the objects you
128
- * want to appear in the query string.
129
- *
130
- * @example makeApiaUrl({
131
- * ajaxUrl: 'the.endpoint.you.want',
132
- * queryString: 'an=existent&query=string',
133
- * action: 'theAction',
134
- * anotherProp: 15
135
- * })
136
- *
137
- * @returns the well formed url, in the example, the response url is:
138
- * /context/the.endpoint.you.want?an=existent&query=string&anotherProp=15&tabId=...&tokenId=...&action=theAction
139
- */
140
- declare function makeApiaUrl(props?: {
141
- action?: string;
142
- ajaxUrl?: string;
143
- queryString?: string;
144
- stringifyOptions?: QueryString.IStringifyOptions;
145
- tabId?: string | number;
146
- preventAsXmlParameter?: boolean;
147
- avoidTabId?: boolean;
148
- [key: string]: unknown;
149
- }): string;
150
- declare global {
151
- interface Window {
152
- TAB_ID_REQUEST: string;
153
- CONTEXT: string;
154
- URL_REQUEST_AJAX: string;
155
- }
156
- }
157
-
158
- interface TColors {
159
- exception?: string;
160
- alert?: string;
161
- message?: string;
162
- }
163
- type TApiaApiResult<LoadType> = Promise<TApiaApiAxiosResponse<(LoadType & TNotificationMessage) | null> | null>;
164
- interface IApiaApiConsoleConfig {
165
- colors?: TColors;
166
- debug?: boolean;
167
- }
168
- type TSetModalProps = (configuration: THandleConfiguration, formDefinition?: TApiaLoad) => TModal | null;
169
- interface IApiaApiRequestConfig<DataType> extends IApiaApiConsoleConfig {
170
- axiosConfig?: AxiosRequestConfig;
171
- modalConfiguration?: IModalConfig;
172
- handleLoad?: boolean;
173
- setModalProps?: TSetModalProps;
174
- /**
175
- * Algunas veces las funciones llamadas por una acción en el servidor
176
- * tienen el mismo nombre siendo en realidad funciones distintas. Para
177
- * corregir este problema es posible pasar un path relativo al directorio
178
- * apiaApi/methods
179
- */
180
- methodsPath?: string;
181
- notificationsCategory?: string;
182
- queryData?: string | Record<string, unknown>;
183
- stringifyOptions?: QueryString.IStringifyOptions;
184
- validateResponse?: (response: AxiosResponse<DataType | null>) => Promise<boolean | string> | boolean | string;
185
- }
186
-
187
- type TMethod = {
188
- name: string;
189
- props: {
190
- attributes?: Record<string, unknown>;
191
- currentUrl?: string;
192
- funCall?: string;
193
- inlineArguments?: string[];
194
- messages?: unknown;
195
- };
196
- };
197
- type TApiaApiMethodHandler = {
198
- alert: typeof notify;
199
- close: () => void;
200
- configuration?: THandleConfiguration;
201
- formDefinition: TApiaLoad;
202
- setModalProps?: (configuration: THandleConfiguration, formDefinition?: TApiaLoad) => TModal | null;
203
- reset: () => void;
204
- setError: typeof notify;
205
- setMessage: (message: Record<string, unknown>) => unknown;
206
- setState: React.Dispatch<React.SetStateAction<IApiaApiHandlerState>>;
207
- state: IApiaApiHandlerState;
208
- setValue: (name: string, value: string) => void;
209
- };
210
- type TApiaApiMethod = (handler: TApiaApiMethodHandler, props: TMethod['props']) => Promise<void> | void;
211
- type TApiaApiField = TApiaApiMethodHandler & {
212
- element: TModify<TApiaFormElement, {
213
- onChange: React.ChangeEventHandler;
214
- }>;
215
- };
216
- type TStoredApiaApiMethod = (props?: TMethod['props']) => unknown;
217
- /**
218
- * Este método permite cargar en forma asíncrona un método que se encuentre
219
- * dentro del directorio /api/methods
220
- */
221
- declare function getFunction(name: string, handler: TApiaApiMethodHandler): Promise<TStoredApiaApiMethod | undefined>;
222
- interface IModalConfig {
223
- modalTitle?: string;
224
- onClose?: () => void;
225
- onMessage?: (message: Record<string, unknown>) => unknown;
226
- onMessageClose?: () => unknown;
227
- onSubmitted?: (handler: TApiaApiMethodHandler, response: AxiosResponse<Record<string, unknown> | null> | null) => unknown;
228
- }
229
- type THandleConfiguration = Partial<Pick<IApiaApiRequestConfig<unknown>, 'modalConfiguration' | 'methodsPath' | 'setModalProps'>>;
230
- interface IApiaApiHandlerState {
231
- disabled: boolean;
232
- isLoading: boolean;
233
- isMultipart: boolean;
234
- progress: number;
235
- errors: Record<string, string>;
236
- windowIndex: number;
237
- }
238
- declare const ApiaApiHandler: React.MemoExoticComponent<() => React.JSX.Element>;
239
-
240
- declare global {
241
- interface Window {
242
- SALT: string;
243
- IV: string;
244
- PASSPHRASE: string;
245
- KEY_SIZE: number;
246
- ITERATION_COUNT: string;
247
- }
248
- }
249
- /**
250
- * Permite cargar en forma asíncrona un modal que se encuentre dentro del
251
- * directorio /api/modals
252
- * */
253
- declare const getModal: (path: string) => React__default.LazyExoticComponent<React__default.ComponentType<TApiaApiField>>;
254
-
255
- export { ApiaApi, ApiaApiHandler, IApiaApiRequestConfig, TApiaApiAxiosResponse, TApiaApiMethod, TApiaApiResult, getFunction, getModal, makeApiaUrl };
1
+ export { ApiaApiHandler, TApiaApiMethod, getFunction } from './ApiaApiHandler.js';
2
+ export { default as ApiaApi, TApiaApiAxiosResponse, makeApiaUrl } from './apiaApi.js';
3
+ export { IApiaApiRequestConfig, TApiaApiResult } from './types.js';
4
+ export { getModal } from './fields/ApiaApiInput.js';
5
+ //# sourceMappingURL=index.d.ts.map