shori-sdk-ts 1.1.3 → 1.1.5

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 (64) hide show
  1. package/package.json +1 -1
  2. package/.env +0 -7
  3. package/src/auth/AuthService.ts +0 -61
  4. package/src/auth/TokenProvider.ts +0 -62
  5. package/src/client/ShoriClient.ts +0 -104
  6. package/src/client/ShoriClientBuilder.ts +0 -138
  7. package/src/config/ShoriConfig.ts +0 -45
  8. package/src/config/ShoriEnvironment.ts +0 -39
  9. package/src/exception/ShoriException.ts +0 -43
  10. package/src/http/HttpExecutor.ts +0 -274
  11. package/src/index.ts +0 -67
  12. package/src/modules/caso/caseCommentModule.ts +0 -88
  13. package/src/modules/caso/caseFileTypologyModule.ts +0 -140
  14. package/src/modules/caso/caseFilesModule.ts +0 -168
  15. package/src/modules/caso/caseModule.ts +0 -182
  16. package/src/modules/caso/caseStateModule.ts +0 -51
  17. package/src/modules/caso/caseTypeModule.ts +0 -69
  18. package/src/modules/caso/dto/request/addCommentRequest.ts +0 -150
  19. package/src/modules/caso/dto/request/casoCreateRequest.ts +0 -258
  20. package/src/modules/caso/dto/request/casoFileUpdateRequest.ts +0 -20
  21. package/src/modules/caso/dto/request/casoUpdateRequest.ts +0 -251
  22. package/src/modules/caso/dto/request/getAttachmentFilesRequest.ts +0 -250
  23. package/src/modules/caso/dto/request/nextStateRequest.ts +0 -17
  24. package/src/modules/caso/dto/request/paginationRequest.ts +0 -206
  25. package/src/modules/caso/dto/response/actionResponse.ts +0 -9
  26. package/src/modules/caso/dto/response/addCommentResponse.ts +0 -4
  27. package/src/modules/caso/dto/response/caseDataFieldResponse.ts +0 -38
  28. package/src/modules/caso/dto/response/caseFileSearchResult.ts +0 -8
  29. package/src/modules/caso/dto/response/caseSearchResult.ts +0 -13
  30. package/src/modules/caso/dto/response/casoCreateResponse.ts +0 -21
  31. package/src/modules/caso/dto/response/casoFileSearchResponse.ts +0 -20
  32. package/src/modules/caso/dto/response/casoResponse.ts +0 -85
  33. package/src/modules/caso/dto/response/casoSearchResponse.ts +0 -95
  34. package/src/modules/caso/dto/response/casoTypePrimaryLevelWorkingStateResponse.ts +0 -16
  35. package/src/modules/caso/dto/response/commentResponse.ts +0 -12
  36. package/src/modules/caso/dto/response/commentSearchResult.ts +0 -11
  37. package/src/modules/caso/dto/response/fileCategoryResponse.ts +0 -6
  38. package/src/modules/caso/dto/response/formResponse.ts +0 -26
  39. package/src/modules/caso/dto/response/groupLevelLabelResponse.ts +0 -4
  40. package/src/modules/caso/dto/response/permissionResponse.ts +0 -11
  41. package/src/modules/caso/dto/response/priorityResponse.ts +0 -10
  42. package/src/modules/caso/dto/response/productResponse.ts +0 -64
  43. package/src/modules/caso/dto/response/translationResponse.ts +0 -5
  44. package/src/modules/caso/dto/response/typologyResponse.ts +0 -12
  45. package/src/modules/caso/filter/caseFilter.ts +0 -339
  46. package/src/modules/caso/filter/commentFilter.ts +0 -191
  47. package/src/modules/caso/filter/filterOperator.ts +0 -77
  48. package/src/modules/caso/filter/primaryLevelFilter.ts +0 -236
  49. package/src/modules/caso/filter/secondaryLevelFilter.ts +0 -271
  50. package/src/modules/caso/filter/sortDirection.ts +0 -5
  51. package/src/modules/repo/dto/downloadRequests.ts +0 -45
  52. package/src/modules/repo/dto/uploadDocumentRequest.ts +0 -43
  53. package/src/modules/repo/repoDocumentModule.ts +0 -94
  54. package/src/modules/repo/repoDownloadModule.ts +0 -120
  55. package/src/modules/repo/repoModule.ts +0 -74
  56. package/src/tests/case-comment.integration.test.ts +0 -74
  57. package/src/tests/case-search.integration.test.ts +0 -130
  58. package/src/utils/shoriUtil.ts +0 -58
  59. package/tsconfig.cjs.json +0 -8
  60. package/tsconfig.esm.json +0 -7
  61. package/tsconfig.json +0 -18
  62. package/tsconfig.types.json +0 -8
  63. package/vite-env.d.ts +0 -13
  64. package/vitest.config.ts +0 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shori-sdk-ts",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "SDK TypeScript para integrar aplicaciones JS/TS con la plataforma Shori BPM de NTT DATA",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
package/.env DELETED
@@ -1,7 +0,0 @@
1
- # Copia este archivo a .env y rellena con tus credenciales reales
2
- # .env está en .gitignore — nunca se commitea
3
-
4
- VITE_SHORI_PORTAL_ID=0306444E-38B1-403D-8753-EC9C2BC43215
5
- VITE_SHORI_TENANT_ID=80ff134a-cae2-4a4a-92b9-a109bdee1183
6
- VITE_SHORI_API_KEY=B5577FB9-75DF-440C-831D-E42958AD1A79
7
- VITE_SHORI_ENVIRONMENT=UAT
@@ -1,61 +0,0 @@
1
- import type { ShoriConfig } from "../config/ShoriConfig.js";
2
-
3
- /** Respuesta del endpoint de autenticación. */
4
- interface AuthResponse {
5
- token: string;
6
- }
7
-
8
- /**
9
- * Servicio de autenticación con Shori.
10
- * Obtiene el Bearer token usando la X-ApiKey.
11
- * Equivalente a AuthService.java
12
- */
13
- export class AuthService {
14
- private readonly config: ShoriConfig;
15
-
16
- constructor(config: ShoriConfig) {
17
- this.config = config;
18
- }
19
-
20
- /**
21
- * Obtiene el token Bearer desde el endpoint de autenticación.
22
- * Usa X-ApiKey — nunca Bearer token.
23
- */
24
- async authenticate(): Promise<string> {
25
- const url = `${this.config.identifyUrl}/v3/authentication`;
26
-
27
- const controller = new AbortController();
28
- const timerId = setTimeout(() => controller.abort(), this.config.timeoutMs);
29
-
30
- try {
31
- const headers = new Headers();
32
- headers.append("X-ApiKey", String(this.config.apiKey));
33
- headers.append("X-TenantID", String(this.config.tenantId));
34
- headers.append("Portal", String(this.config.portalId));
35
- const response = await fetch(url, {
36
- method: "GET",
37
- headers: headers,
38
- signal: controller.signal,
39
- });
40
- if (!response.ok) {
41
- const body = await response.text().catch(() => "");
42
- throw new Error(
43
- `Error de autenticación HTTP ${response.status}: ${body}`,
44
- );
45
- }
46
-
47
- const data = (await response.json()) as AuthResponse;
48
- return data.token;
49
- } catch (err) {
50
- console.error(err);
51
- if (err instanceof Error && err.name === "AbortError") {
52
- throw new Error(
53
- `Timeout de autenticación (${this.config.timeoutMs}ms)`,
54
- );
55
- }
56
- throw err;
57
- } finally {
58
- clearTimeout(timerId);
59
- }
60
- }
61
- }
@@ -1,62 +0,0 @@
1
- import type { AuthService } from "./AuthService.js";
2
-
3
- /**
4
- * Proveedor de tokens Bearer con lazy-loading y renovación automática.
5
- *
6
- * Equivalente a TokenProvider.java.
7
- * En JS no hay threads, pero sí hay concurrencia async — si múltiples
8
- * requests se ejecutan en paralelo y el token expira, solo uno refresca
9
- * y los demás reutilizan el resultado gracias al Promise compartido.
10
- */
11
- export class TokenProvider {
12
- private token: string | null = null;
13
- /** Promise en vuelo para evitar múltiples refreshes simultáneos */
14
- private refreshPromise: Promise<string> | null = null;
15
- private readonly authService: AuthService;
16
-
17
- constructor(authService: AuthService) {
18
- this.authService = authService;
19
- }
20
-
21
- /**
22
- * Obtiene el token Bearer vigente.
23
- * Si no hay token, autentica de forma lazy.
24
- * Si hay una autenticación en curso, espera a la misma (no lanza una segunda).
25
- */
26
- async getToken(): Promise<string> {
27
- if (this.token) return this.token;
28
- return this.refresh();
29
- }
30
-
31
- /**
32
- * Invalida el token actual y fuerza una nueva autenticación.
33
- * Si ya hay un refresh en curso, espera ese mismo (no duplica la llamada).
34
- */
35
- async invalidateAndRefresh(): Promise<string> {
36
- this.token = null;
37
- return this.refresh();
38
- }
39
-
40
- private async refresh(): Promise<string> {
41
- // Si ya hay un refresh en curso, compartir el mismo Promise
42
- if (this.refreshPromise) return this.refreshPromise;
43
-
44
- this.refreshPromise = this.authService
45
- .authenticate()
46
- .then((newToken) => {
47
- this.token = newToken;
48
- return newToken;
49
- })
50
- .finally(() => {
51
- this.refreshPromise = null;
52
- });
53
-
54
- return this.refreshPromise;
55
- }
56
-
57
- /** Limpia el token cacheado (útil en tests o al cerrar el cliente) */
58
- clear(): void {
59
- this.token = null;
60
- this.refreshPromise = null;
61
- }
62
- }
@@ -1,104 +0,0 @@
1
- import type { ShoriConfig } from "../config/ShoriConfig.js";
2
- import type { HttpExecutor } from "../http/HttpExecutor.js";
3
- import type { RepoModule } from "../modules/repo/repoModule.js";
4
- import type { CaseModule } from "../modules/caso/caseModule.js";
5
-
6
- /**
7
- * Punto de entrada principal del SDK de Shori para TypeScript/JavaScript.
8
- *
9
- * Compatible con Node.js 18+, React, Next.js, NestJS, Express y cualquier
10
- * entorno que soporte fetch nativo.
11
- *
12
- * @example
13
- * ```ts
14
- * import { ShoriClientBuilder, ShoriEnvironment } from "@nttdata/shori-api-client";
15
- *
16
- * const client = new ShoriClientBuilder()
17
- * .environment(ShoriEnvironment.PROD)
18
- * .portalId("mi-portal-id")
19
- * .tenantId("mi-tenant-id")
20
- * .apiKey("mi-api-key")
21
- * .build();
22
- * ```
23
- */
24
- export class ShoriClient {
25
- /** Configuración activa del cliente */
26
- readonly config: ShoriConfig;
27
-
28
- /** @internal — usado por los módulos de negocio */
29
- readonly _httpExecutor: HttpExecutor;
30
-
31
- private readonly _repoModule: RepoModule;
32
- private readonly _caseModule: CaseModule;
33
-
34
- /** @internal — usar ShoriClientBuilder para crear instancias */
35
- constructor(
36
- config: ShoriConfig,
37
- httpExecutor: HttpExecutor,
38
- repoModule: RepoModule,
39
- caseModule: CaseModule,
40
- ) {
41
- this.config = config;
42
- this._httpExecutor = httpExecutor;
43
- this._repoModule = repoModule;
44
- this._caseModule = caseModule;
45
- }
46
-
47
- /**
48
- * Accede al módulo de Repositorio de Documentos.
49
- *
50
- * Permite subir, descargar y eliminar documentos del repositorio de Shori.
51
- *
52
- * @example
53
- * ```ts
54
- * // Subir
55
- * const docId = await client.repo().document().upload({ file, casoId, casoTypeId });
56
- *
57
- * // Descargar
58
- * const blob = await client.repo().download().byDocument({ documentId: docId });
59
- *
60
- * // Exportar como PDF
61
- * const pdf = await client.repo().download().exportDocument({ documentId: docId });
62
- * ```
63
- */
64
- repo(): RepoModule {
65
- return this._repoModule;
66
- }
67
-
68
- /**
69
- * Accede al módulo de Casos.
70
- *
71
- * Permite crear, buscar, actualizar casos y acceder a sub-módulos
72
- * especializados para estados, comentarios y tipos de caso.
73
- *
74
- * @example
75
- * ```ts
76
- * // Crear un caso.
77
- * const result = await client.caso().create({ casoTypeId, formId, priority });
78
- *
79
- * // Buscar con auto-paginación
80
- * const todos = await client.caso().searchAll(
81
- * new CaseFilter().casoTypeId(FilterOperator.EQ, "tipo-uuid")
82
- * .workingSubStateId(FilterOperator.IN, ...openStateIds)
83
- * );
84
- *
85
- * // Sub-módulos
86
- * client.caso().state() // avanzar estado
87
- * client.caso().comment() // comentarios
88
- * client.caso().casoType() // tipos de caso
89
- * ```
90
- */
91
- caso(): CaseModule {
92
- return this._caseModule;
93
- }
94
-
95
- /**
96
- * Libera los recursos asociados al cliente.
97
- *
98
- * En JS/TS no hay pool que cerrar — este método existe por
99
- * paridad de API con el SDK Java y para compatibilidad futura.
100
- */
101
- close(): void {
102
- // No-op en TS: fetch nativo no mantiene conexiones persistentes
103
- }
104
- }
@@ -1,138 +0,0 @@
1
- import { ShoriConfig } from "../config/ShoriConfig.js";
2
- import { ShoriEnvironment } from "../config/ShoriEnvironment.js";
3
- import { AuthService } from "../auth/AuthService.js";
4
- import { TokenProvider } from "../auth/TokenProvider.js";
5
- import { HttpExecutor } from "../http/HttpExecutor.js";
6
- import { ShoriClient } from "./ShoriClient.js";
7
- import { ValidationException } from "../exception/ShoriException.js";
8
- import { RepoModule } from "../modules/repo/repoModule.js";
9
- import { CaseModule } from "../modules/caso/caseModule.js";
10
-
11
- /**
12
- * Builder fluido para construir instancias de ShoriClient.
13
- *
14
- * Equivalente a ShoriClientBuilder.java — misma API, mismo comportamiento.
15
- *
16
- * @example
17
- * ```ts
18
- * // Uso básico
19
- * const client = new ShoriClientBuilder()
20
- * .environment(ShoriEnvironment.PROD)
21
- * .portalId("mi-portal-id")
22
- * .tenantId("mi-tenant-id")
23
- * .apiKey("mi-api-key")
24
- * .build();
25
- *
26
- * // Uso en Next.js / NestJS (archivo de configuración)
27
- * export const shoriClient = new ShoriClientBuilder()
28
- * .environment(ShoriEnvironment.PROD)
29
- * .portalId(process.env.SHORI_PORTAL_ID!)
30
- * .tenantId(process.env.SHORI_TENANT_ID!)
31
- * .apiKey(process.env.SHORI_API_KEY!)
32
- * .build();
33
- * ```
34
- */
35
- export class ShoriClientBuilder {
36
- private _environment?: ShoriEnvironment;
37
- private _portalId?: string;
38
- private _tenantId?: string;
39
- private _apiKey?: string;
40
- private _timeoutMs: number = 30_000;
41
-
42
- /**
43
- * Establece el ambiente de Shori.
44
- * @param environment DEV | UAT | PROD
45
- */
46
- environment(environment: ShoriEnvironment): this {
47
- this._environment = environment;
48
- return this;
49
- }
50
-
51
- /**
52
- * Establece el ID del portal de Shori.
53
- * @param portalId UUID del portal (ej: "0306444E-38B1-403D-8753-EC9C2BC43215")
54
- */
55
- portalId(portalId: string): this {
56
- this._portalId = portalId;
57
- return this;
58
- }
59
-
60
- /**
61
- * Establece el ID del tenant de Shori.
62
- * @param tenantId UUID del tenant (ej: "80ff134a-cae2-4a4a-92b9-a109bdee1183")
63
- */
64
- tenantId(tenantId: string): this {
65
- this._tenantId = tenantId;
66
- return this;
67
- }
68
-
69
- /**
70
- * Establece la API Key para autenticación.
71
- * @param apiKey Clave de API proporcionada por Shori
72
- */
73
- apiKey(apiKey: string): this {
74
- this._apiKey = apiKey;
75
- return this;
76
- }
77
-
78
- /**
79
- * Establece el timeout de los requests en milisegundos.
80
- * @param timeoutMs Milisegundos. Por defecto: 30000 (30s)
81
- */
82
- timeoutMs(timeoutMs: number): this {
83
- if (timeoutMs <= 0) {
84
- throw new ValidationException("El timeout debe ser mayor a 0 ms");
85
- }
86
- this._timeoutMs = timeoutMs;
87
- return this;
88
- }
89
-
90
- /**
91
- * Valida la configuración y construye la instancia de ShoriClient.
92
- *
93
- * @returns ShoriClient completamente inicializado
94
- * @throws ValidationException si falta algún parámetro requerido
95
- */
96
- build(): ShoriClient {
97
- this.validate();
98
-
99
- const config = new ShoriConfig({
100
- environment: this._environment!,
101
- portalId: this._portalId!,
102
- tenantId: this._tenantId!,
103
- apiKey: this._apiKey!,
104
- timeoutMs: this._timeoutMs,
105
- });
106
-
107
- const authService = new AuthService(config);
108
- const tokenProvider = new TokenProvider(authService);
109
- const httpExecutor = new HttpExecutor(config, tokenProvider);
110
- const repoModule = new RepoModule(config, httpExecutor);
111
- const caseModule = new CaseModule(config, httpExecutor, repoModule);
112
-
113
- return new ShoriClient(config, httpExecutor, repoModule, caseModule);
114
- }
115
-
116
- private validate(): void {
117
- if (!this._environment) {
118
- throw new ValidationException(
119
- "El ambiente es requerido. Usa .environment(ShoriEnvironment.DEV | UAT | PROD)",
120
- );
121
- }
122
- if (!this._portalId?.trim()) {
123
- throw new ValidationException(
124
- 'El Portal ID es requerido. Usa .portalId("tu-portal-id")',
125
- );
126
- }
127
- if (!this._tenantId?.trim()) {
128
- throw new ValidationException(
129
- 'El Tenant ID es requerido. Usa .tenantId("tu-tenant-id")',
130
- );
131
- }
132
- if (!this._apiKey?.trim()) {
133
- throw new ValidationException(
134
- 'La API Key es requerida. Usa .apiKey("tu-api-key")',
135
- );
136
- }
137
- }
138
- }
@@ -1,45 +0,0 @@
1
- import { ShoriEnvironment, getEnvironmentUrls } from "./ShoriEnvironment.js";
2
-
3
- /**
4
- * Configuración inmutable del SDK de Shori.
5
- * Equivalente a ShoriConfig.java
6
- */
7
- export interface ShoriConfigOptions {
8
- /** Ambiente de Shori (DEV, UAT, PROD) */
9
- environment: ShoriEnvironment;
10
- /** ID del portal */
11
- portalId: string;
12
- /** ID del tenant */
13
- tenantId: string;
14
- /** API Key para autenticación */
15
- apiKey: string;
16
- /** Timeout de los requests en milisegundos. Por defecto: 30000 (30s) */
17
- timeoutMs?: number;
18
- }
19
-
20
- /**
21
- * Configuración resuelta con URLs calculadas
22
- */
23
- export class ShoriConfig {
24
- readonly environment: ShoriEnvironment;
25
- readonly portalId: string;
26
- readonly tenantId: string;
27
- readonly apiKey: string;
28
- readonly timeoutMs: number;
29
- readonly caseUrl: string;
30
- readonly identifyUrl: string;
31
- readonly repoUrl: string;
32
-
33
- constructor(options: ShoriConfigOptions) {
34
- this.environment = options.environment;
35
- this.portalId = options.portalId;
36
- this.tenantId = options.tenantId;
37
- this.apiKey = options.apiKey;
38
- this.timeoutMs = options.timeoutMs ?? 30_000;
39
-
40
- const urls = getEnvironmentUrls(options.environment);
41
- this.caseUrl = urls.caseUrl;
42
- this.identifyUrl = urls.identifyUrl;
43
- this.repoUrl = urls.repoUrl;
44
- }
45
- }
@@ -1,39 +0,0 @@
1
- /**
2
- * Ambientes pre-configurados de Shori con sus URLs correspondientes.
3
- * Equivalente a ShoriEnvironment.java
4
- */
5
- export enum ShoriEnvironment {
6
- /** Ambiente de desarrollo */
7
- DEV = "DEV",
8
- /** Ambiente de UAT (User Acceptance Testing) */
9
- UAT = "UAT",
10
- /** Ambiente de producción */
11
- PROD = "PROD",
12
- }
13
-
14
- /** URLs base por ambiente */
15
- export const SHORI_ENVIRONMENT_URLS: Record<
16
- ShoriEnvironment,
17
- { caseUrl: string; identifyUrl: string; repoUrl: string }
18
- > = {
19
- [ShoriEnvironment.DEV]: {
20
- caseUrl: "https://shori-caso-uat.clonika.com",
21
- identifyUrl: "https://shori-identify-uat.clonika.com",
22
- repoUrl: "https://shori-repo-uat.clonika.com",
23
- },
24
- [ShoriEnvironment.UAT]: {
25
- caseUrl: "https://shori-caso-uat.clonika.com",
26
- identifyUrl: "https://shori-identify-uat.clonika.com",
27
- repoUrl: "https://shori-repo-uat.clonika.com",
28
- },
29
- [ShoriEnvironment.PROD]: {
30
- caseUrl: "https://shori-caso.clonika.com",
31
- identifyUrl: "https://shori-identify.clonika.com",
32
- repoUrl: "https://shori-repo.clonika.com",
33
- },
34
- };
35
-
36
- /** Obtiene las URLs del ambiente dado */
37
- export function getEnvironmentUrls(env: ShoriEnvironment) {
38
- return SHORI_ENVIRONMENT_URLS[env];
39
- }
@@ -1,43 +0,0 @@
1
- /** Excepción base del SDK de Shori */
2
- export class ShoriException extends Error {
3
- readonly cause?: unknown;
4
- constructor(message: string, cause?: unknown) {
5
- super(message);
6
- this.name = "ShoriException";
7
- this.cause = cause;
8
- }
9
- }
10
-
11
- /** Error HTTP del API (4xx, 5xx) */
12
- export class ApiException extends ShoriException {
13
- readonly statusCode: number;
14
- constructor(message: string, statusCode: number, cause?: unknown) {
15
- super(message, cause);
16
- this.name = "ApiException";
17
- this.statusCode = statusCode;
18
- }
19
- }
20
-
21
- /** Error de autenticación */
22
- export class AuthenticationException extends ShoriException {
23
- constructor(message: string, cause?: unknown) {
24
- super(message, cause);
25
- this.name = "AuthenticationException";
26
- }
27
- }
28
-
29
- /** Recurso no encontrado (HTTP 404) */
30
- export class ResourceNotFoundException extends ShoriException {
31
- constructor(message: string) {
32
- super(message);
33
- this.name = "ResourceNotFoundException";
34
- }
35
- }
36
-
37
- /** Parámetro inválido en el SDK */
38
- export class ValidationException extends ShoriException {
39
- constructor(message: string) {
40
- super(message);
41
- this.name = "ValidationException";
42
- }
43
- }