@innvoid/getmarket-sdk 0.2.3 → 0.2.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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/index.ts","../../src/core/errors.ts","../../src/core/http.ts","../../src/middlewares/requestId.ts","../../src/core/internalHttp.ts"],"sourcesContent":["// sdk/src/core/index.ts\n\nexport * from \"./errors\";\nexport * from \"./http\";\nexport * from \"./internalHttp\";\n","export type ClientErrorCode =\n | \"UPSTREAM_TIMEOUT\"\n | \"UPSTREAM_UNAVAILABLE\"\n | \"UPSTREAM_BAD_RESPONSE\"\n | \"UPSTREAM_NOT_FOUND\"\n | \"UPSTREAM_UNAUTHORIZED\"\n | \"UPSTREAM_FORBIDDEN\"\n | \"UPSTREAM_UNKNOWN\";\n\nexport class UpstreamError extends Error {\n public code: ClientErrorCode;\n public status?: number;\n public details?: any;\n\n constructor(message: string, code: ClientErrorCode, status?: number, details?: any) {\n super(message);\n this.name = \"UpstreamError\";\n this.code = code;\n this.status = status;\n this.details = details;\n }\n}\n\nexport function mapAxiosToUpstreamError(err: any, svc: string): UpstreamError {\n const status = err?.response?.status;\n const data = err?.response?.data;\n const isTimeout = err?.code === \"ECONNABORTED\" || String(err?.message || \"\").includes(\"timeout\");\n\n if (isTimeout) {\n return new UpstreamError(`[${svc}] timeout`, \"UPSTREAM_TIMEOUT\", 504, {cause: err?.message});\n }\n if (!err?.response) {\n return new UpstreamError(`[${svc}] unavailable`, \"UPSTREAM_UNAVAILABLE\", 503, {cause: err?.message});\n }\n if (status === 404) return new UpstreamError(`[${svc}] not found`, \"UPSTREAM_NOT_FOUND\", 404, data);\n if (status === 401) return new UpstreamError(`[${svc}] unauthorized`, \"UPSTREAM_UNAUTHORIZED\", 401, data);\n if (status === 403) return new UpstreamError(`[${svc}] forbidden`, \"UPSTREAM_FORBIDDEN\", 403, data);\n if (status >= 400 && status < 600) {\n return new UpstreamError(`[${svc}] bad response`, \"UPSTREAM_BAD_RESPONSE\", status, data);\n }\n return new UpstreamError(`[${svc}] unknown error`, \"UPSTREAM_UNKNOWN\", status, data);\n}\n","// packages/sdk/src/core/http.ts\nimport axios, {AxiosInstance, AxiosRequestConfig} from \"axios\";\nimport {REQUEST_ID_HEADER} from \"../middlewares/requestId\";\n\nexport type HttpClientOpts = {\n baseURL: string;\n timeoutMs?: number;\n};\n\n/**\n * Headers compatibles con múltiples versiones de axios.\n * En axios antiguo, `headers` suele ser `any`, así que mantenemos tolerancia.\n */\nexport type AnyHeaders = NonNullable<AxiosRequestConfig[\"headers\"]> | Record<string, string>;\n\n/**\n * Agrega x-request-id a headers (sin pisar otros headers).\n */\nexport function withRequestId(headers: AnyHeaders | undefined, requestId?: string | null): AnyHeaders {\n const h: Record<string, any> =\n headers && typeof headers === \"object\"\n ? {...(headers as any)}\n : {};\n\n const rid = (requestId || \"\").trim();\n if (rid) h[REQUEST_ID_HEADER] = rid;\n\n return h as AnyHeaders;\n}\n\n/**\n * Helper para construir config de axios con requestId\n * (SIN genéricos para compat con axios typings antiguos).\n */\nexport function withRequestIdConfig(\n config: AxiosRequestConfig = {},\n requestId?: string | null\n): AxiosRequestConfig {\n return {\n ...config,\n headers: withRequestId((config as any).headers, requestId) as any,\n };\n}\n\nexport function createHttpClient(opts: HttpClientOpts): AxiosInstance {\n return axios.create({\n baseURL: opts.baseURL,\n timeout: opts.timeoutMs ?? 4000,\n headers: {\"Content-Type\": \"application/json\"},\n });\n}\n","// middlewares/requestId.ts\nimport type {Request, Response, NextFunction} from \"express\";\nimport {randomUUID, randomBytes} from \"crypto\";\n\nexport const REQUEST_ID_HEADER = \"x-request-id\";\nexport const REQUEST_ID_HEADER_ALT = \"x-requestid\";\nexport const RESPONSE_REQUEST_ID_HEADER = \"X-Request-Id\";\n\n// Si quieres IDs más cortos (opcional). Por defecto usamos UUID.\nfunction nanoidLike(len = 21) {\n return randomBytes(16).toString(\"base64url\").slice(0, len);\n}\n\nexport default function requestId(req: Request, res: Response, next: NextFunction) {\n const headerId = (req.headers[REQUEST_ID_HEADER] || req.headers[REQUEST_ID_HEADER_ALT]) as\n | string\n | undefined;\n\n // ✅ estándar único: usa UUID (o cambia a nanoidLike() si prefieres corto)\n const id = headerId?.trim() || randomUUID();\n\n // ✅ estándar único (no legacy)\n (req as any).requestId = id;\n res.locals.requestId = id;\n\n // ✅ respuesta\n res.setHeader(RESPONSE_REQUEST_ID_HEADER, id);\n\n next();\n}\n","// clients/internalHttp.ts\n\ntype RetryPolicy = {\n retries: number;\n baseDelayMs: number;\n retryOnStatuses: number[];\n retryOnNetworkErrors: boolean;\n};\n\ntype InternalHttpOptions = {\n baseUrl: string;\n apiKey?: string; // x-internal-api-key\n timeoutMs?: number;\n retry?: Partial<RetryPolicy>;\n};\n\nconst DEFAULT_RETRY: RetryPolicy = {\n retries: 1,\n baseDelayMs: 150,\n retryOnStatuses: [429, 502, 503, 504],\n retryOnNetworkErrors: true,\n};\n\nfunction sleep(ms: number) {\n return new Promise((r) => setTimeout(r, ms));\n}\n\nfunction safeJsonStringify(v: any) {\n try {\n return JSON.stringify(v);\n } catch {\n return String(v);\n }\n}\n\nfunction toHeaders(init?: HeadersInit): Headers {\n return new Headers(init || {});\n}\n\nfunction isJsonContentType(contentType: string | null): boolean {\n if (!contentType) return false;\n const ct = contentType.toLowerCase();\n return ct.includes(\"application/json\") || ct.includes(\"+json\");\n}\n\nfunction isAbortError(e: any): boolean {\n return e?.name === \"AbortError\";\n}\n\nfunction withJitter(ms: number): number {\n // jitter +-20%\n const jitter = ms * 0.2;\n const delta = (Math.random() * 2 - 1) * jitter;\n return Math.max(0, Math.floor(ms + delta));\n}\n\nexport class InternalHttp {\n private readonly baseUrl: string;\n private readonly apiKey: string | undefined;\n private readonly timeoutMs: number;\n private retry: RetryPolicy;\n\n constructor(opts: InternalHttpOptions) {\n this.baseUrl = opts.baseUrl.replace(/\\/+$/, \"\");\n this.apiKey = opts.apiKey;\n\n // ✅ Default más seguro para internas (evita cascadas)\n this.timeoutMs = opts.timeoutMs ?? 4000;\n\n this.retry = {...DEFAULT_RETRY, ...(opts.retry || {})};\n }\n\n async request<T>(\n path: string,\n init: RequestInit & {\n requestId?: string;\n idempotencyKey?: string;\n headers?: HeadersInit;\n } = {}\n ): Promise<T> {\n const url = `${this.baseUrl}${path.startsWith(\"/\") ? \"\" : \"/\"}${path}`;\n\n const baseHeaders = toHeaders(init.headers);\n\n if (!baseHeaders.has(\"Content-Type\")) baseHeaders.set(\"Content-Type\", \"application/json\");\n if (this.apiKey) baseHeaders.set(\"x-internal-api-key\", this.apiKey);\n\n if (init.requestId) baseHeaders.set(\"x-request-id\", init.requestId);\n if (init.idempotencyKey) baseHeaders.set(\"Idempotency-Key\", init.idempotencyKey);\n\n const {headers: _ignored, ...restInit} = init;\n\n const doFetchOnce = async () => {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), this.timeoutMs);\n\n try {\n const res = await fetch(url, {\n ...restInit,\n headers: baseHeaders,\n signal: controller.signal,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n const err: any = new Error(\n `HTTP ${res.status} ${res.statusText}${text ? ` - ${text}` : \"\"}`\n );\n err.status = res.status;\n err.body = text;\n throw err;\n }\n\n if (res.status === 204) return undefined as unknown as T;\n\n const contentType = res.headers.get(\"content-type\");\n if (isJsonContentType(contentType)) {\n return (await res.json()) as T;\n }\n\n const text = await res.text().catch(() => \"\");\n return text as unknown as T;\n } finally {\n clearTimeout(timeout);\n }\n };\n\n let attempt = 0;\n\n while (true) {\n try {\n return await doFetchOnce();\n } catch (e: any) {\n attempt++;\n\n const status = e?.status;\n const retryableStatus = !!status && this.retry.retryOnStatuses.includes(status);\n\n const retryableNetwork =\n this.retry.retryOnNetworkErrors &&\n (isAbortError(e) || !status); // sin status suele ser red/dns/timeout\n\n const isRetryable = retryableStatus || retryableNetwork;\n\n if (!isRetryable || attempt > this.retry.retries) {\n console.error(\n `[InternalHttp] request failed: ${url} attempt=${attempt} status=${status ?? \"n/a\"} err=${e?.message\n } body=${safeJsonStringify(e?.body)}`\n );\n throw e;\n }\n\n const backoff = withJitter(this.retry.baseDelayMs * attempt);\n await sleep(backoff);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EAEP,YAAY,SAAiB,MAAuB,QAAiB,SAAe;AAChF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACnB;AACJ;AAEO,SAAS,wBAAwB,KAAU,KAA4B;AAC1E,QAAM,SAAS,KAAK,UAAU;AAC9B,QAAM,OAAO,KAAK,UAAU;AAC5B,QAAM,YAAY,KAAK,SAAS,kBAAkB,OAAO,KAAK,WAAW,EAAE,EAAE,SAAS,SAAS;AAE/F,MAAI,WAAW;AACX,WAAO,IAAI,cAAc,IAAI,GAAG,aAAa,oBAAoB,KAAK,EAAC,OAAO,KAAK,QAAO,CAAC;AAAA,EAC/F;AACA,MAAI,CAAC,KAAK,UAAU;AAChB,WAAO,IAAI,cAAc,IAAI,GAAG,iBAAiB,wBAAwB,KAAK,EAAC,OAAO,KAAK,QAAO,CAAC;AAAA,EACvG;AACA,MAAI,WAAW,IAAK,QAAO,IAAI,cAAc,IAAI,GAAG,eAAe,sBAAsB,KAAK,IAAI;AAClG,MAAI,WAAW,IAAK,QAAO,IAAI,cAAc,IAAI,GAAG,kBAAkB,yBAAyB,KAAK,IAAI;AACxG,MAAI,WAAW,IAAK,QAAO,IAAI,cAAc,IAAI,GAAG,eAAe,sBAAsB,KAAK,IAAI;AAClG,MAAI,UAAU,OAAO,SAAS,KAAK;AAC/B,WAAO,IAAI,cAAc,IAAI,GAAG,kBAAkB,yBAAyB,QA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/core/http.ts","../../src/core/internalHttp.ts"],"sourcesContent":["// sdk/src/core/index.ts\n\nexport * from \"./errors\";\nexport * from \"./http\";\nexport * from \"./internalHttp\";\n","export type ClientErrorCode =\n | \"UPSTREAM_TIMEOUT\"\n | \"UPSTREAM_UNAVAILABLE\"\n | \"UPSTREAM_BAD_RESPONSE\"\n | \"UPSTREAM_NOT_FOUND\"\n | \"UPSTREAM_UNAUTHORIZED\"\n | \"UPSTREAM_FORBIDDEN\"\n | \"UPSTREAM_UNKNOWN\";\n\nexport class UpstreamError extends Error {\n public code: ClientErrorCode;\n public status?: number;\n public details?: any;\n\n constructor(message: string, code: ClientErrorCode, status?: number, details?: any) {\n super(message);\n this.name = \"UpstreamError\";\n this.code = code;\n this.status = status;\n this.details = details;\n }\n}\n\nexport function mapAxiosToUpstreamError(err: any, svc: string): UpstreamError {\n const status = err?.response?.status;\n const data = err?.response?.data;\n const isTimeout = err?.code === \"ECONNABORTED\" || String(err?.message || \"\").includes(\"timeout\");\n\n if (isTimeout) {\n return new UpstreamError(`[${svc}] timeout`, \"UPSTREAM_TIMEOUT\", 504, {cause: err?.message});\n }\n if (!err?.response) {\n return new UpstreamError(`[${svc}] unavailable`, \"UPSTREAM_UNAVAILABLE\", 503, {cause: err?.message});\n }\n if (status === 404) return new UpstreamError(`[${svc}] not found`, \"UPSTREAM_NOT_FOUND\", 404, data);\n if (status === 401) return new UpstreamError(`[${svc}] unauthorized`, \"UPSTREAM_UNAUTHORIZED\", 401, data);\n if (status === 403) return new UpstreamError(`[${svc}] forbidden`, \"UPSTREAM_FORBIDDEN\", 403, data);\n if (status >= 400 && status < 600) {\n return new UpstreamError(`[${svc}] bad response`, \"UPSTREAM_BAD_RESPONSE\", status, data);\n }\n return new UpstreamError(`[${svc}] unknown error`, \"UPSTREAM_UNKNOWN\", status, data);\n}\n","// sdk/src/core/http.ts\nimport axios, {AxiosInstance, AxiosRequestConfig} from \"axios\";\n\nexport type HttpClient = AxiosInstance;\n\nexport type HttpClientOpts = {\n baseURL: string;\n timeoutMs?: number;\n headers?: Record<string, string>;\n};\n\nexport function createHttpClient(opts: HttpClientOpts): HttpClient {\n return axios.create({\n baseURL: opts.baseURL.replace(/\\/+$/, \"\"),\n timeout: opts.timeoutMs ?? 8000,\n headers: opts.headers ?? {},\n } satisfies AxiosRequestConfig);\n}\n","// clients/internalHttp.ts\n\ntype RetryPolicy = {\n retries: number;\n baseDelayMs: number;\n retryOnStatuses: number[];\n retryOnNetworkErrors: boolean;\n};\n\ntype InternalHttpOptions = {\n baseUrl: string;\n apiKey?: string; // x-internal-api-key\n timeoutMs?: number;\n retry?: Partial<RetryPolicy>;\n};\n\nconst DEFAULT_RETRY: RetryPolicy = {\n retries: 1,\n baseDelayMs: 150,\n retryOnStatuses: [429, 502, 503, 504],\n retryOnNetworkErrors: true,\n};\n\nfunction sleep(ms: number) {\n return new Promise((r) => setTimeout(r, ms));\n}\n\nfunction safeJsonStringify(v: any) {\n try {\n return JSON.stringify(v);\n } catch {\n return String(v);\n }\n}\n\nfunction toHeaders(init?: HeadersInit): Headers {\n return new Headers(init || {});\n}\n\nfunction isJsonContentType(contentType: string | null): boolean {\n if (!contentType) return false;\n const ct = contentType.toLowerCase();\n return ct.includes(\"application/json\") || ct.includes(\"+json\");\n}\n\nfunction isAbortError(e: any): boolean {\n return e?.name === \"AbortError\";\n}\n\nfunction withJitter(ms: number): number {\n // jitter +-20%\n const jitter = ms * 0.2;\n const delta = (Math.random() * 2 - 1) * jitter;\n return Math.max(0, Math.floor(ms + delta));\n}\n\nexport class InternalHttp {\n private readonly baseUrl: string;\n private readonly apiKey: string | undefined;\n private readonly timeoutMs: number;\n private retry: RetryPolicy;\n\n constructor(opts: InternalHttpOptions) {\n this.baseUrl = opts.baseUrl.replace(/\\/+$/, \"\");\n this.apiKey = opts.apiKey;\n\n // ✅ Default más seguro para internas (evita cascadas)\n this.timeoutMs = opts.timeoutMs ?? 4000;\n\n this.retry = {...DEFAULT_RETRY, ...(opts.retry || {})};\n }\n\n async request<T>(\n path: string,\n init: RequestInit & {\n requestId?: string;\n idempotencyKey?: string;\n headers?: HeadersInit;\n } = {}\n ): Promise<T> {\n const url = `${this.baseUrl}${path.startsWith(\"/\") ? \"\" : \"/\"}${path}`;\n\n const baseHeaders = toHeaders(init.headers);\n\n if (!baseHeaders.has(\"Content-Type\")) baseHeaders.set(\"Content-Type\", \"application/json\");\n if (this.apiKey) baseHeaders.set(\"x-internal-api-key\", this.apiKey);\n\n if (init.requestId) baseHeaders.set(\"x-request-id\", init.requestId);\n if (init.idempotencyKey) baseHeaders.set(\"Idempotency-Key\", init.idempotencyKey);\n\n const {headers: _ignored, ...restInit} = init;\n\n const doFetchOnce = async () => {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), this.timeoutMs);\n\n try {\n const res = await fetch(url, {\n ...restInit,\n headers: baseHeaders,\n signal: controller.signal,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n const err: any = new Error(\n `HTTP ${res.status} ${res.statusText}${text ? ` - ${text}` : \"\"}`\n );\n err.status = res.status;\n err.body = text;\n throw err;\n }\n\n if (res.status === 204) return undefined as unknown as T;\n\n const contentType = res.headers.get(\"content-type\");\n if (isJsonContentType(contentType)) {\n return (await res.json()) as T;\n }\n\n const text = await res.text().catch(() => \"\");\n return text as unknown as T;\n } finally {\n clearTimeout(timeout);\n }\n };\n\n let attempt = 0;\n\n while (true) {\n try {\n return await doFetchOnce();\n } catch (e: any) {\n attempt++;\n\n const status = e?.status;\n const retryableStatus = !!status && this.retry.retryOnStatuses.includes(status);\n\n const retryableNetwork =\n this.retry.retryOnNetworkErrors &&\n (isAbortError(e) || !status); // sin status suele ser red/dns/timeout\n\n const isRetryable = retryableStatus || retryableNetwork;\n\n if (!isRetryable || attempt > this.retry.retries) {\n console.error(\n `[InternalHttp] request failed: ${url} attempt=${attempt} status=${status ?? \"n/a\"} err=${e?.message\n } body=${safeJsonStringify(e?.body)}`\n );\n throw e;\n }\n\n const backoff =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A,cAAM,OAAO,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,EAAE;AAC5C,eAAO;AAAA,MACX,UAAE;AACE,qBAAa,OAAO;AAAA,MACxB;AAAA,IACJ;AAEA,QAAI,UAAU;AAEd,WAAO,MAAM;AACT,UAAI;AACA,eAAO,MAAM,YAAY;AAAA,MAC7B,SAAS,GAAQ;AACb;AAEA,cAAM,SAAS,GAAG;AAClB,cAAM,kBAAkB,CAAC,CAAC,UAAU,KAAK,MAAM,gBAAgB,SAAS,MAAM;AAE9E,cAAM,mBACF,KAAK,MAAM,yBACV,aAAa,CAAC,KAAK,CAAC;AAEzB,cAAM,cAAc,mBAAmB;AAEvC,YAAI,CAAC,eAAe,UAAU,KAAK,MAAM,SAAS;AAC9C,kBAAQ;AAAA,YACJ,kCAAkC,GAAG,YAAY,OAAO,WAAW,UAAU,KAAK,QAAQ,GAAG,OAC7F,SAAS,kBAAkB,GAAG,IAAI,CAAC;AAAA,UACvC;AACA,gBAAM;AAAA,QACV;AAEA,cAAM,UAAU,WAAW,KAAK,MAAM,cAAc,OAAO;AAC3D,cAAM,MAAM,OAAO;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["axios","text"]}
@@ -1,4 +1,4 @@
1
- import { AxiosRequestConfig, AxiosInstance } from 'axios';
1
+ import { AxiosInstance } from 'axios';
2
2
 
3
3
  type ClientErrorCode = "UPSTREAM_TIMEOUT" | "UPSTREAM_UNAVAILABLE" | "UPSTREAM_BAD_RESPONSE" | "UPSTREAM_NOT_FOUND" | "UPSTREAM_UNAUTHORIZED" | "UPSTREAM_FORBIDDEN" | "UPSTREAM_UNKNOWN";
4
4
  declare class UpstreamError extends Error {
@@ -9,25 +9,13 @@ declare class UpstreamError extends Error {
9
9
  }
10
10
  declare function mapAxiosToUpstreamError(err: any, svc: string): UpstreamError;
11
11
 
12
+ type HttpClient = AxiosInstance;
12
13
  type HttpClientOpts = {
13
14
  baseURL: string;
14
15
  timeoutMs?: number;
16
+ headers?: Record<string, string>;
15
17
  };
16
- /**
17
- * Headers compatibles con múltiples versiones de axios.
18
- * En axios antiguo, `headers` suele ser `any`, así que mantenemos tolerancia.
19
- */
20
- type AnyHeaders = NonNullable<AxiosRequestConfig["headers"]> | Record<string, string>;
21
- /**
22
- * Agrega x-request-id a headers (sin pisar otros headers).
23
- */
24
- declare function withRequestId(headers: AnyHeaders | undefined, requestId?: string | null): AnyHeaders;
25
- /**
26
- * Helper para construir config de axios con requestId
27
- * (SIN genéricos para compat con axios typings antiguos).
28
- */
29
- declare function withRequestIdConfig(config?: AxiosRequestConfig, requestId?: string | null): AxiosRequestConfig;
30
- declare function createHttpClient(opts: HttpClientOpts): AxiosInstance;
18
+ declare function createHttpClient(opts: HttpClientOpts): HttpClient;
31
19
 
32
20
  type RetryPolicy = {
33
21
  retries: number;
@@ -54,4 +42,4 @@ declare class InternalHttp {
54
42
  }): Promise<T>;
55
43
  }
56
44
 
57
- export { type AnyHeaders, type ClientErrorCode, type HttpClientOpts, InternalHttp, UpstreamError, createHttpClient, mapAxiosToUpstreamError, withRequestId, withRequestIdConfig };
45
+ export { type ClientErrorCode, type HttpClient, type HttpClientOpts, InternalHttp, UpstreamError, createHttpClient, mapAxiosToUpstreamError };
@@ -1,4 +1,4 @@
1
- import { AxiosRequestConfig, AxiosInstance } from 'axios';
1
+ import { AxiosInstance } from 'axios';
2
2
 
3
3
  type ClientErrorCode = "UPSTREAM_TIMEOUT" | "UPSTREAM_UNAVAILABLE" | "UPSTREAM_BAD_RESPONSE" | "UPSTREAM_NOT_FOUND" | "UPSTREAM_UNAUTHORIZED" | "UPSTREAM_FORBIDDEN" | "UPSTREAM_UNKNOWN";
4
4
  declare class UpstreamError extends Error {
@@ -9,25 +9,13 @@ declare class UpstreamError extends Error {
9
9
  }
10
10
  declare function mapAxiosToUpstreamError(err: any, svc: string): UpstreamError;
11
11
 
12
+ type HttpClient = AxiosInstance;
12
13
  type HttpClientOpts = {
13
14
  baseURL: string;
14
15
  timeoutMs?: number;
16
+ headers?: Record<string, string>;
15
17
  };
16
- /**
17
- * Headers compatibles con múltiples versiones de axios.
18
- * En axios antiguo, `headers` suele ser `any`, así que mantenemos tolerancia.
19
- */
20
- type AnyHeaders = NonNullable<AxiosRequestConfig["headers"]> | Record<string, string>;
21
- /**
22
- * Agrega x-request-id a headers (sin pisar otros headers).
23
- */
24
- declare function withRequestId(headers: AnyHeaders | undefined, requestId?: string | null): AnyHeaders;
25
- /**
26
- * Helper para construir config de axios con requestId
27
- * (SIN genéricos para compat con axios typings antiguos).
28
- */
29
- declare function withRequestIdConfig(config?: AxiosRequestConfig, requestId?: string | null): AxiosRequestConfig;
30
- declare function createHttpClient(opts: HttpClientOpts): AxiosInstance;
18
+ declare function createHttpClient(opts: HttpClientOpts): HttpClient;
31
19
 
32
20
  type RetryPolicy = {
33
21
  retries: number;
@@ -54,4 +42,4 @@ declare class InternalHttp {
54
42
  }): Promise<T>;
55
43
  }
56
44
 
57
- export { type AnyHeaders, type ClientErrorCode, type HttpClientOpts, InternalHttp, UpstreamError, createHttpClient, mapAxiosToUpstreamError, withRequestId, withRequestIdConfig };
45
+ export { type ClientErrorCode, type HttpClient, type HttpClientOpts, InternalHttp, UpstreamError, createHttpClient, mapAxiosToUpstreamError };
@@ -2,17 +2,12 @@ import {
2
2
  InternalHttp,
3
3
  UpstreamError,
4
4
  createHttpClient,
5
- mapAxiosToUpstreamError,
6
- withRequestId,
7
- withRequestIdConfig
8
- } from "../chunk-OSYBK5AN.js";
9
- import "../chunk-KJ64O2EG.js";
5
+ mapAxiosToUpstreamError
6
+ } from "../chunk-5S2JP7PR.js";
10
7
  export {
11
8
  InternalHttp,
12
9
  UpstreamError,
13
10
  createHttpClient,
14
- mapAxiosToUpstreamError,
15
- withRequestId,
16
- withRequestIdConfig
11
+ mapAxiosToUpstreamError
17
12
  };
18
13
  //# sourceMappingURL=index.js.map
package/dist/index.cjs CHANGED
@@ -59,13 +59,17 @@ __export(src_exports, {
59
59
  createInternalHttpClient: () => createInternalHttpClient,
60
60
  createMdClient: () => createMdClient,
61
61
  createMediaClient: () => createMediaClient,
62
+ createMkpClient: () => createMkpClient,
62
63
  createPlatformClient: () => createPlatformClient,
63
64
  createResClient: () => createResClient,
64
65
  getOrSet: () => getOrSet,
65
66
  getRequestContextFromHeaders: () => getRequestContextFromHeaders,
66
67
  getTwoLevelCache: () => getTwoLevelCache,
67
68
  internalAuth: () => internalAuth,
69
+ isUid: () => isUid,
68
70
  mapAxiosToUpstreamError: () => mapAxiosToUpstreamError,
71
+ newUid: () => newUid,
72
+ newUidV4: () => newUidV4,
69
73
  parseHeaders: () => parseHeaders,
70
74
  readRs256PublicKey: () => readRs256PublicKey,
71
75
  readServiceEnv: () => readServiceEnv,
@@ -77,9 +81,7 @@ __export(src_exports, {
77
81
  requireRolesOrAnyPermission: () => requireRolesOrAnyPermission,
78
82
  sendError: () => sendError,
79
83
  sendOk: () => sendOk,
80
- verifyBackendJwtRS256: () => verifyBackendJwtRS256,
81
- withRequestId: () => withRequestId,
82
- withRequestIdConfig: () => withRequestIdConfig
84
+ verifyBackendJwtRS256: () => verifyBackendJwtRS256
83
85
  });
84
86
  module.exports = __toCommonJS(src_exports);
85
87
 
@@ -404,39 +406,11 @@ function mapAxiosToUpstreamError(err, svc) {
404
406
 
405
407
  // src/core/http.ts
406
408
  var import_axios = __toESM(require("axios"), 1);
407
-
408
- // src/middlewares/requestId.ts
409
- var import_crypto = require("crypto");
410
- var REQUEST_ID_HEADER = "x-request-id";
411
- var REQUEST_ID_HEADER_ALT = "x-requestid";
412
- var RESPONSE_REQUEST_ID_HEADER = "X-Request-Id";
413
- function requestId(req, res, next) {
414
- const headerId = req.headers[REQUEST_ID_HEADER] || req.headers[REQUEST_ID_HEADER_ALT];
415
- const id = headerId?.trim() || (0, import_crypto.randomUUID)();
416
- req.requestId = id;
417
- res.locals.requestId = id;
418
- res.setHeader(RESPONSE_REQUEST_ID_HEADER, id);
419
- next();
420
- }
421
-
422
- // src/core/http.ts
423
- function withRequestId(headers, requestId2) {
424
- const h2 = headers && typeof headers === "object" ? { ...headers } : {};
425
- const rid = (requestId2 || "").trim();
426
- if (rid) h2[REQUEST_ID_HEADER] = rid;
427
- return h2;
428
- }
429
- function withRequestIdConfig(config = {}, requestId2) {
430
- return {
431
- ...config,
432
- headers: withRequestId(config.headers, requestId2)
433
- };
434
- }
435
409
  function createHttpClient(opts) {
436
410
  return import_axios.default.create({
437
- baseURL: opts.baseURL,
438
- timeout: opts.timeoutMs ?? 4e3,
439
- headers: { "Content-Type": "application/json" }
411
+ baseURL: opts.baseURL.replace(/\/+$/, ""),
412
+ timeout: opts.timeoutMs ?? 8e3,
413
+ headers: opts.headers ?? {}
440
414
  });
441
415
  }
442
416
 
@@ -579,6 +553,20 @@ function parseHeaders(req, _res, next) {
579
553
  next();
580
554
  }
581
555
 
556
+ // src/middlewares/requestId.ts
557
+ var import_crypto = require("crypto");
558
+ var REQUEST_ID_HEADER = "x-request-id";
559
+ var REQUEST_ID_HEADER_ALT = "x-requestid";
560
+ var RESPONSE_REQUEST_ID_HEADER = "X-Request-Id";
561
+ function requestId(req, res, next) {
562
+ const headerId = req.headers[REQUEST_ID_HEADER] || req.headers[REQUEST_ID_HEADER_ALT];
563
+ const id = headerId?.trim() || (0, import_crypto.randomUUID)();
564
+ req.requestId = id;
565
+ res.locals.requestId = id;
566
+ res.setHeader(RESPONSE_REQUEST_ID_HEADER, id);
567
+ next();
568
+ }
569
+
582
570
  // src/middlewares/internalAuth.ts
583
571
  var import_fs = __toESM(require("fs"), 1);
584
572
  var import_crypto2 = __toESM(require("crypto"), 1);
@@ -1528,14 +1516,96 @@ function createMdClient() {
1528
1516
  // src/clients/fisClient.ts
1529
1517
  function createFisClient() {
1530
1518
  const env = readServiceEnv("FIS", { apiPrefix: "/internal/v1" });
1519
+ const http = createHttpClient({
1520
+ baseURL: `${env.baseURL}${env.apiPrefix}`,
1521
+ timeoutMs: 8e3
1522
+ });
1531
1523
  const taxes = createBulkRefsClient({
1532
1524
  namespace: "fis:tax",
1533
1525
  baseURL: env.baseURL,
1534
1526
  apiPrefix: env.apiPrefix,
1535
1527
  path: "/refs/taxes"
1536
1528
  });
1529
+ const documents = createBulkRefsClient({
1530
+ namespace: "fis:document",
1531
+ baseURL: env.baseURL,
1532
+ apiPrefix: env.apiPrefix,
1533
+ path: "/refs/documents"
1534
+ });
1535
+ const submissions = createBulkRefsClient({
1536
+ namespace: "fis:submission",
1537
+ baseURL: env.baseURL,
1538
+ apiPrefix: env.apiPrefix,
1539
+ path: "/refs/submissions"
1540
+ });
1537
1541
  return {
1538
- taxesRefs: (uids, opts) => taxes.bulkRefs(uids, opts)
1542
+ // -----------------------------------------------------------------------
1543
+ // Bulk refs
1544
+ // -----------------------------------------------------------------------
1545
+ taxesRefs: (uids, opts) => taxes.bulkRefs(uids, opts),
1546
+ documentsRefs: (uids, opts) => documents.bulkRefs(uids, opts),
1547
+ submissionsRefs: (uids, opts) => submissions.bulkRefs(uids, opts),
1548
+ // -----------------------------------------------------------------------
1549
+ // Fiscal calculation / build / lifecycle
1550
+ // -----------------------------------------------------------------------
1551
+ calculate: async (body) => {
1552
+ const { data } = await http.post("/calculate", body);
1553
+ return data;
1554
+ },
1555
+ buildDocument: async (body) => {
1556
+ const { data } = await http.post("/documents/build", body);
1557
+ return data;
1558
+ },
1559
+ signDocument: async (body) => {
1560
+ const { data } = await http.post("/documents/sign", body);
1561
+ return data;
1562
+ },
1563
+ submitDocument: async (body) => {
1564
+ const { data } = await http.post("/documents/submit", body);
1565
+ return data;
1566
+ },
1567
+ cancelDocument: async (body) => {
1568
+ const { data } = await http.post("/documents/cancel", body);
1569
+ return data;
1570
+ },
1571
+ // -----------------------------------------------------------------------
1572
+ // Folios / series
1573
+ // -----------------------------------------------------------------------
1574
+ reserveFolio: async (body) => {
1575
+ const { data } = await http.post("/folios/reserve", body);
1576
+ return data;
1577
+ },
1578
+ consumeFolio: async (body) => {
1579
+ const { data } = await http.post("/folios/consume", body);
1580
+ return data;
1581
+ },
1582
+ // -----------------------------------------------------------------------
1583
+ // Queries / detail
1584
+ // -----------------------------------------------------------------------
1585
+ queryDocuments: async (params) => {
1586
+ const { data } = await http.get("/documents", { params });
1587
+ return data;
1588
+ },
1589
+ getDocumentByUid: async (uid) => {
1590
+ const { data } = await http.get(`/documents/${uid}`);
1591
+ return data;
1592
+ },
1593
+ getSnapshotByUid: async (uid) => {
1594
+ const { data } = await http.get(`/snapshots/${uid}`);
1595
+ return data;
1596
+ },
1597
+ getSubmissionByUid: async (uid) => {
1598
+ const { data } = await http.get(`/submissions/${uid}`);
1599
+ return data;
1600
+ },
1601
+ getStatusEventsByDocumentUid: async (documentUid) => {
1602
+ const { data } = await http.get(`/documents/${documentUid}/status-events`);
1603
+ return data;
1604
+ },
1605
+ retrySubmission: async (body) => {
1606
+ const { data } = await http.post("/submissions/retry", body);
1607
+ return data;
1608
+ }
1539
1609
  };
1540
1610
  }
1541
1611
 
@@ -1552,6 +1622,46 @@ function createMediaClient() {
1552
1622
  filesRefs: (uids, opts) => files.bulkRefs(uids, opts)
1553
1623
  };
1554
1624
  }
1625
+
1626
+ // src/clients/mkpClient.ts
1627
+ function createMkpClient() {
1628
+ const env = readServiceEnv("MKP", { apiPrefix: "/internal/v1" });
1629
+ const publications = createBulkRefsClient({
1630
+ namespace: "mkp:publication",
1631
+ baseURL: env.baseURL,
1632
+ apiPrefix: env.apiPrefix,
1633
+ path: "/refs/publications"
1634
+ });
1635
+ const events = createBulkRefsClient({
1636
+ namespace: "mkp:event",
1637
+ baseURL: env.baseURL,
1638
+ apiPrefix: env.apiPrefix,
1639
+ path: "/refs/events"
1640
+ });
1641
+ const promotions = createBulkRefsClient({
1642
+ namespace: "mkp:promotion",
1643
+ baseURL: env.baseURL,
1644
+ apiPrefix: env.apiPrefix,
1645
+ path: "/refs/promotions"
1646
+ });
1647
+ return {
1648
+ publicationsRefs: (uids, opts) => publications.bulkRefs(uids, opts),
1649
+ eventsRefs: (uids, opts) => events.bulkRefs(uids, opts),
1650
+ promotionsRefs: (uids, opts) => promotions.bulkRefs(uids, opts)
1651
+ };
1652
+ }
1653
+
1654
+ // src/common/ids.ts
1655
+ var import_uuid = require("uuid");
1656
+ function newUid() {
1657
+ return (0, import_uuid.v7)();
1658
+ }
1659
+ function newUidV4() {
1660
+ return (0, import_uuid.v4)();
1661
+ }
1662
+ function isUid(value) {
1663
+ return (0, import_uuid.validate)(value) && ((0, import_uuid.version)(value) === 7 || (0, import_uuid.version)(value) === 4);
1664
+ }
1555
1665
  // Annotate the CommonJS export names for ESM import in node:
1556
1666
  0 && (module.exports = {
1557
1667
  HEADER_AUTHORIZATION,
@@ -1583,13 +1693,17 @@ function createMediaClient() {
1583
1693
  createInternalHttpClient,
1584
1694
  createMdClient,
1585
1695
  createMediaClient,
1696
+ createMkpClient,
1586
1697
  createPlatformClient,
1587
1698
  createResClient,
1588
1699
  getOrSet,
1589
1700
  getRequestContextFromHeaders,
1590
1701
  getTwoLevelCache,
1591
1702
  internalAuth,
1703
+ isUid,
1592
1704
  mapAxiosToUpstreamError,
1705
+ newUid,
1706
+ newUidV4,
1593
1707
  parseHeaders,
1594
1708
  readRs256PublicKey,
1595
1709
  readServiceEnv,
@@ -1601,8 +1715,6 @@ function createMediaClient() {
1601
1715
  requireRolesOrAnyPermission,
1602
1716
  sendError,
1603
1717
  sendOk,
1604
- verifyBackendJwtRS256,
1605
- withRequestId,
1606
- withRequestIdConfig
1718
+ verifyBackendJwtRS256
1607
1719
  });
1608
1720
  //# sourceMappingURL=index.cjs.map