@ssddo/ecf-react 0.1.4 → 0.2.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.
- package/README.md +27 -1
- package/dist/index.d.mts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +21 -0
- package/dist/index.mjs +20 -0
- package/package.json +21 -1
package/README.md
CHANGED
|
@@ -205,6 +205,32 @@ Crea un cliente tipado de React Query para la API de ECF DGII.
|
|
|
205
205
|
- `$api` - El cliente openapi-react-query con `useQuery`, `useMutation`, `useSuspenseQuery`, etc.
|
|
206
206
|
- `fetchClient` - El cliente openapi-fetch subyacente para uso fuera de React.
|
|
207
207
|
|
|
208
|
+
### `createEcfFrontendReactClient(config)`
|
|
209
|
+
|
|
210
|
+
Crea un cliente de solo lectura restringido a endpoints GET. No expone `useMutation`. Diseñado para el frontend donde solo se consultan ECFs con un token de solo lectura.
|
|
211
|
+
|
|
212
|
+
**Opciones de configuración:** mismas que `createEcfReactClient`.
|
|
213
|
+
|
|
214
|
+
**Retorna:** `{ $api, fetchClient }`
|
|
215
|
+
|
|
216
|
+
- `$api` - Cliente con solo `useQuery`, `useSuspenseQuery`, y `queryOptions` (sin `useMutation`)
|
|
217
|
+
- `fetchClient` - El cliente openapi-fetch subyacente (restringido a paths GET)
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
import { createEcfFrontendReactClient } from '@ssddo/ecf-react';
|
|
221
|
+
|
|
222
|
+
const { $api } = createEcfFrontendReactClient({
|
|
223
|
+
apiKey: token,
|
|
224
|
+
environment: 'prod',
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// ✅ Funciona — endpoint GET
|
|
228
|
+
$api.useQuery('get', '/ecf/{rnc}/{encf}', { params: { path: { rnc, encf } } });
|
|
229
|
+
|
|
230
|
+
// ❌ Error de tipo — useMutation no está disponible
|
|
231
|
+
// $api.useMutation('post', '/ecf/31');
|
|
232
|
+
```
|
|
233
|
+
|
|
208
234
|
## Arquitectura Backend / Frontend
|
|
209
235
|
|
|
210
236
|
El SDK de React está diseñado para el lado del **frontend** de la arquitectura recomendada:
|
|
@@ -219,7 +245,7 @@ El SDK de React está diseñado para el lado del **frontend** de la arquitectura
|
|
|
219
245
|
// y lo renueva automáticamente cuando expira o recibe un 401
|
|
220
246
|
const ecfToken = useEcfToken();
|
|
221
247
|
|
|
222
|
-
const { $api } =
|
|
248
|
+
const { $api } = createEcfFrontendReactClient({
|
|
223
249
|
apiKey: ecfToken, // solo lectura, con alcance al tenant/RNC
|
|
224
250
|
environment: 'prod',
|
|
225
251
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -6852,5 +6852,26 @@ declare function createEcfReactClient(config: EcfReactClientConfig): {
|
|
|
6852
6852
|
$api: openapi_react_query.OpenapiQueryClient<paths, `${string}/${string}`>;
|
|
6853
6853
|
fetchClient: openapi_fetch.Client<paths, `${string}/${string}`>;
|
|
6854
6854
|
};
|
|
6855
|
+
type PathsWithGet = {
|
|
6856
|
+
[K in keyof paths as paths[K] extends {
|
|
6857
|
+
get: unknown;
|
|
6858
|
+
} ? K : never]: paths[K];
|
|
6859
|
+
};
|
|
6860
|
+
type ReadOnlyPaths = {
|
|
6861
|
+
[K in keyof PathsWithGet]: Pick<PathsWithGet[K], 'get' | 'parameters'> & {
|
|
6862
|
+
put?: never;
|
|
6863
|
+
post?: never;
|
|
6864
|
+
delete?: never;
|
|
6865
|
+
patch?: never;
|
|
6866
|
+
};
|
|
6867
|
+
};
|
|
6868
|
+
declare function createEcfFrontendReactClient(config: EcfReactClientConfig): {
|
|
6869
|
+
$api: {
|
|
6870
|
+
useQuery: openapi_react_query.UseQueryMethod<ReadOnlyPaths, `${string}/${string}`>;
|
|
6871
|
+
useSuspenseQuery: openapi_react_query.UseSuspenseQueryMethod<ReadOnlyPaths, `${string}/${string}`>;
|
|
6872
|
+
queryOptions: openapi_react_query.QueryOptionsFunction<ReadOnlyPaths, `${string}/${string}`>;
|
|
6873
|
+
};
|
|
6874
|
+
fetchClient: openapi_fetch.Client<ReadOnlyPaths, `${string}/${string}`>;
|
|
6875
|
+
};
|
|
6855
6876
|
|
|
6856
|
-
export { type EcfReactClientConfig, type Environment, type components, createEcfReactClient, type operations, type paths };
|
|
6877
|
+
export { type EcfReactClientConfig, type Environment, type components, createEcfFrontendReactClient, createEcfReactClient, type operations, type paths };
|
package/dist/index.d.ts
CHANGED
|
@@ -6852,5 +6852,26 @@ declare function createEcfReactClient(config: EcfReactClientConfig): {
|
|
|
6852
6852
|
$api: openapi_react_query.OpenapiQueryClient<paths, `${string}/${string}`>;
|
|
6853
6853
|
fetchClient: openapi_fetch.Client<paths, `${string}/${string}`>;
|
|
6854
6854
|
};
|
|
6855
|
+
type PathsWithGet = {
|
|
6856
|
+
[K in keyof paths as paths[K] extends {
|
|
6857
|
+
get: unknown;
|
|
6858
|
+
} ? K : never]: paths[K];
|
|
6859
|
+
};
|
|
6860
|
+
type ReadOnlyPaths = {
|
|
6861
|
+
[K in keyof PathsWithGet]: Pick<PathsWithGet[K], 'get' | 'parameters'> & {
|
|
6862
|
+
put?: never;
|
|
6863
|
+
post?: never;
|
|
6864
|
+
delete?: never;
|
|
6865
|
+
patch?: never;
|
|
6866
|
+
};
|
|
6867
|
+
};
|
|
6868
|
+
declare function createEcfFrontendReactClient(config: EcfReactClientConfig): {
|
|
6869
|
+
$api: {
|
|
6870
|
+
useQuery: openapi_react_query.UseQueryMethod<ReadOnlyPaths, `${string}/${string}`>;
|
|
6871
|
+
useSuspenseQuery: openapi_react_query.UseSuspenseQueryMethod<ReadOnlyPaths, `${string}/${string}`>;
|
|
6872
|
+
queryOptions: openapi_react_query.QueryOptionsFunction<ReadOnlyPaths, `${string}/${string}`>;
|
|
6873
|
+
};
|
|
6874
|
+
fetchClient: openapi_fetch.Client<ReadOnlyPaths, `${string}/${string}`>;
|
|
6875
|
+
};
|
|
6855
6876
|
|
|
6856
|
-
export { type EcfReactClientConfig, type Environment, type components, createEcfReactClient, type operations, type paths };
|
|
6877
|
+
export { type EcfReactClientConfig, type Environment, type components, createEcfFrontendReactClient, createEcfReactClient, type operations, type paths };
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
createEcfFrontendReactClient: () => createEcfFrontendReactClient,
|
|
33
34
|
createEcfReactClient: () => createEcfReactClient
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -56,7 +57,27 @@ function createEcfReactClient(config) {
|
|
|
56
57
|
const $api = (0, import_openapi_react_query.default)(fetchClient);
|
|
57
58
|
return { $api, fetchClient };
|
|
58
59
|
}
|
|
60
|
+
function createEcfFrontendReactClient(config) {
|
|
61
|
+
const baseUrl = config.baseUrl ?? ENVIRONMENT_URLS[config.environment ?? "test"];
|
|
62
|
+
const fetchClient = (0, import_openapi_fetch.default)({
|
|
63
|
+
baseUrl
|
|
64
|
+
});
|
|
65
|
+
fetchClient.use({
|
|
66
|
+
async onRequest({ request }) {
|
|
67
|
+
request.headers.set("Authorization", `Bearer ${config.apiKey}`);
|
|
68
|
+
return request;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const fullApi = (0, import_openapi_react_query.default)(fetchClient);
|
|
72
|
+
const $api = {
|
|
73
|
+
useQuery: fullApi.useQuery,
|
|
74
|
+
useSuspenseQuery: fullApi.useSuspenseQuery,
|
|
75
|
+
queryOptions: fullApi.queryOptions
|
|
76
|
+
};
|
|
77
|
+
return { $api, fetchClient };
|
|
78
|
+
}
|
|
59
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
60
80
|
0 && (module.exports = {
|
|
81
|
+
createEcfFrontendReactClient,
|
|
61
82
|
createEcfReactClient
|
|
62
83
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -20,6 +20,26 @@ function createEcfReactClient(config) {
|
|
|
20
20
|
const $api = createClient(fetchClient);
|
|
21
21
|
return { $api, fetchClient };
|
|
22
22
|
}
|
|
23
|
+
function createEcfFrontendReactClient(config) {
|
|
24
|
+
const baseUrl = config.baseUrl ?? ENVIRONMENT_URLS[config.environment ?? "test"];
|
|
25
|
+
const fetchClient = createFetchClient({
|
|
26
|
+
baseUrl
|
|
27
|
+
});
|
|
28
|
+
fetchClient.use({
|
|
29
|
+
async onRequest({ request }) {
|
|
30
|
+
request.headers.set("Authorization", `Bearer ${config.apiKey}`);
|
|
31
|
+
return request;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const fullApi = createClient(fetchClient);
|
|
35
|
+
const $api = {
|
|
36
|
+
useQuery: fullApi.useQuery,
|
|
37
|
+
useSuspenseQuery: fullApi.useSuspenseQuery,
|
|
38
|
+
queryOptions: fullApi.queryOptions
|
|
39
|
+
};
|
|
40
|
+
return { $api, fetchClient };
|
|
41
|
+
}
|
|
23
42
|
export {
|
|
43
|
+
createEcfFrontendReactClient,
|
|
24
44
|
createEcfReactClient
|
|
25
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ssddo/ecf-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Hooks de React Query para la API de ECF DGII (comprobantes fiscales electrónicos de República Dominicana)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -46,10 +46,30 @@
|
|
|
46
46
|
"tsup": "^8.3.0",
|
|
47
47
|
"typescript": "^5.7.0"
|
|
48
48
|
},
|
|
49
|
+
"author": {
|
|
50
|
+
"name": "SSD Smart Software Development SRL",
|
|
51
|
+
"email": "contacto@ssd.com.do",
|
|
52
|
+
"url": "https://ssd.com.do"
|
|
53
|
+
},
|
|
49
54
|
"repository": {
|
|
50
55
|
"type": "git",
|
|
51
56
|
"url": "https://github.com/SSD-Smart-Software-Development-SRL/ecf_dgii",
|
|
52
57
|
"directory": "react"
|
|
53
58
|
},
|
|
59
|
+
"homepage": "https://github.com/SSD-Smart-Software-Development-SRL/ecf_dgii/tree/main/react#readme",
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/SSD-Smart-Software-Development-SRL/ecf_dgii/issues"
|
|
62
|
+
},
|
|
63
|
+
"keywords": [
|
|
64
|
+
"ecf",
|
|
65
|
+
"dgii",
|
|
66
|
+
"factura-electronica",
|
|
67
|
+
"comprobante-fiscal",
|
|
68
|
+
"republica-dominicana",
|
|
69
|
+
"react",
|
|
70
|
+
"react-query",
|
|
71
|
+
"openapi",
|
|
72
|
+
"ssd"
|
|
73
|
+
],
|
|
54
74
|
"license": "MIT"
|
|
55
75
|
}
|