@timbra-ec/types 0.1.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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-lint.log +5 -0
- package/.turbo/turbo-typecheck.log +5 -0
- package/dist/client.d.ts +29 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +9 -0
- package/dist/client.js.map +1 -0
- package/dist/ice.d.ts +17 -0
- package/dist/ice.d.ts.map +1 -0
- package/dist/ice.js +63 -0
- package/dist/ice.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/invoice.d.ts +129 -0
- package/dist/invoice.d.ts.map +1 -0
- package/dist/invoice.js +36 -0
- package/dist/invoice.js.map +1 -0
- package/dist/product.d.ts +20 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +2 -0
- package/dist/product.js.map +1 -0
- package/dist/schemas/client.schema.d.ts +34 -0
- package/dist/schemas/client.schema.d.ts.map +1 -0
- package/dist/schemas/client.schema.js +13 -0
- package/dist/schemas/client.schema.js.map +1 -0
- package/dist/schemas/invoice.schema.d.ts +204 -0
- package/dist/schemas/invoice.schema.d.ts.map +1 -0
- package/dist/schemas/invoice.schema.js +44 -0
- package/dist/schemas/invoice.schema.js.map +1 -0
- package/dist/sri.d.ts +46 -0
- package/dist/sri.d.ts.map +1 -0
- package/dist/sri.js +21 -0
- package/dist/sri.js.map +1 -0
- package/dist/user.d.ts +40 -0
- package/dist/user.d.ts.map +1 -0
- package/dist/user.js +2 -0
- package/dist/user.js.map +1 -0
- package/package.json +32 -0
- package/src/client.ts +30 -0
- package/src/ice.ts +71 -0
- package/src/index.ts +15 -0
- package/src/invoice.ts +137 -0
- package/src/product.ts +16 -0
- package/src/schemas/client.schema.ts +15 -0
- package/src/schemas/invoice.schema.ts +56 -0
- package/src/sri.ts +54 -0
- package/src/user.ts +43 -0
- package/tsconfig.json +8 -0
package/src/product.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Product or service in a business catalog */
|
|
2
|
+
export interface Product {
|
|
3
|
+
id: string
|
|
4
|
+
organizationId: string
|
|
5
|
+
codigoPrincipal: string
|
|
6
|
+
descripcion: string
|
|
7
|
+
precioUnitario: number
|
|
8
|
+
codigoPorcentajeIva: string // '0', '2', '3', '4', '5', '8' — SRI Ficha Tecnica v2.30 Tabla 17
|
|
9
|
+
detallesAdicionales?: { nombre: string; valor: string }[]
|
|
10
|
+
iceCodigoPorcentaje?: string
|
|
11
|
+
iceTarifa?: number
|
|
12
|
+
activo: boolean
|
|
13
|
+
lastUsedAt?: string
|
|
14
|
+
createdAt: string
|
|
15
|
+
updatedAt: string
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
export const createClientSchema = z.object({
|
|
4
|
+
tipoIdentificacion: z.enum(['04', '05', '06', '07', '08']),
|
|
5
|
+
identificacion: z.string().min(1).max(20),
|
|
6
|
+
razonSocial: z.string().min(1).max(300),
|
|
7
|
+
nombreComercial: z.string().max(300).optional(),
|
|
8
|
+
direccion: z.string().max(300).optional(),
|
|
9
|
+
email: z.string().email(),
|
|
10
|
+
telefono: z.string().max(20).optional(),
|
|
11
|
+
tags: z.array(z.string()).optional(),
|
|
12
|
+
notes: z.string().max(500).optional(),
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export type CreateClientInput = z.infer<typeof createClientSchema>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
export const invoiceItemSchema = z.object({
|
|
4
|
+
codigoPrincipal: z.string().max(25),
|
|
5
|
+
descripcion: z.string().min(1).max(300),
|
|
6
|
+
cantidad: z.number().positive(),
|
|
7
|
+
precioUnitario: z.number().nonnegative(),
|
|
8
|
+
descuento: z.number().nonnegative().default(0),
|
|
9
|
+
codigoPorcentajeIva: z.enum(['0', '2', '3', '4', '5', '8']),
|
|
10
|
+
iceCodigoPorcentaje: z.string().max(4).optional(),
|
|
11
|
+
iceTarifa: z.number().nonnegative().optional(),
|
|
12
|
+
detallesAdicionales: z
|
|
13
|
+
.array(z.object({ nombre: z.string().min(1).max(100), valor: z.string().min(1).max(300) }))
|
|
14
|
+
.max(3)
|
|
15
|
+
.optional(),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
/** Valid SRI payment method codes — Ficha Tecnica v2.30, Formas de Pago Vigentes */
|
|
19
|
+
export const SRI_PAYMENT_CODES = ['01', '15', '16', '17', '18', '19', '20', '21'] as const
|
|
20
|
+
|
|
21
|
+
export type SriPaymentCode = (typeof SRI_PAYMENT_CODES)[number]
|
|
22
|
+
|
|
23
|
+
export const paymentDetailSchema = z.object({
|
|
24
|
+
formaPago: z.enum(SRI_PAYMENT_CODES),
|
|
25
|
+
total: z.number().positive(),
|
|
26
|
+
plazo: z.number().nonnegative().optional(),
|
|
27
|
+
unidadTiempo: z.string().optional(),
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
export const createInvoiceSchema = z.object({
|
|
31
|
+
// Buyer
|
|
32
|
+
tipoIdentificacionComprador: z.enum(['04', '05', '06', '07', '08']),
|
|
33
|
+
identificacionComprador: z.string().min(1).max(20),
|
|
34
|
+
razonSocialComprador: z.string().min(1).max(300),
|
|
35
|
+
emailComprador: z.string().email().optional(),
|
|
36
|
+
telefonoComprador: z.string().optional(),
|
|
37
|
+
|
|
38
|
+
// Date
|
|
39
|
+
fechaEmision: z.string().regex(/^\d{2}\/\d{2}\/\d{4}$/, 'Format: dd/MM/yyyy'),
|
|
40
|
+
|
|
41
|
+
// Items
|
|
42
|
+
items: z.array(invoiceItemSchema).min(1),
|
|
43
|
+
|
|
44
|
+
// Payment
|
|
45
|
+
pagos: z.array(paymentDetailSchema).min(1),
|
|
46
|
+
|
|
47
|
+
// Optional
|
|
48
|
+
propina: z.number().nonnegative().default(0),
|
|
49
|
+
infoAdicional: z.record(z.string()).optional(),
|
|
50
|
+
|
|
51
|
+
// Delivery preferences
|
|
52
|
+
sendEmail: z.boolean().default(true),
|
|
53
|
+
sendWhatsApp: z.boolean().default(false),
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
export type CreateInvoiceInput = z.infer<typeof createInvoiceSchema>
|
package/src/sri.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { SriAuthStatus } from './invoice'
|
|
2
|
+
|
|
3
|
+
/** SRI SOAP reception response */
|
|
4
|
+
export interface SriRecepcionResponse {
|
|
5
|
+
estado: 'RECIBIDA' | 'DEVUELTA'
|
|
6
|
+
comprobantes: {
|
|
7
|
+
claveAcceso: string
|
|
8
|
+
mensajes: SriMensaje[]
|
|
9
|
+
}[]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** SRI SOAP authorization response */
|
|
13
|
+
export interface SriAutorizacionResponse {
|
|
14
|
+
estado: SriAuthStatus
|
|
15
|
+
numeroAutorizacion: string
|
|
16
|
+
fechaAutorizacion: string
|
|
17
|
+
ambiente: string
|
|
18
|
+
comprobante: string // the authorized XML as string
|
|
19
|
+
mensajes: SriMensaje[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** SRI error/warning message */
|
|
23
|
+
export interface SriMensaje {
|
|
24
|
+
identificador: string
|
|
25
|
+
mensaje: string
|
|
26
|
+
informacionAdicional?: string
|
|
27
|
+
tipo: 'ERROR' | 'ADVERTENCIA' | 'INFORMATIVO'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Common SRI error codes */
|
|
31
|
+
export const SRI_ERROR_CODES = {
|
|
32
|
+
CLAVE_REGISTRADA: '35',
|
|
33
|
+
FECHA_NO_CORRESPONDE: '43',
|
|
34
|
+
RUC_INACTIVO: '46',
|
|
35
|
+
TOTAL_INCORRECTO: '65',
|
|
36
|
+
CERTIFICADO_INVALIDO: '70',
|
|
37
|
+
FIRMA_NO_VALIDA: '72',
|
|
38
|
+
} as const
|
|
39
|
+
|
|
40
|
+
/** SRI environment URLs */
|
|
41
|
+
export const SRI_URLS = {
|
|
42
|
+
TEST: {
|
|
43
|
+
RECEPCION:
|
|
44
|
+
'https://celcer.sri.gob.ec/comprobantes-electronicos-ws/RecepcionComprobantesOffline?wsdl',
|
|
45
|
+
AUTORIZACION:
|
|
46
|
+
'https://celcer.sri.gob.ec/comprobantes-electronicos-ws/AutorizacionComprobantesOffline?wsdl',
|
|
47
|
+
},
|
|
48
|
+
PRODUCTION: {
|
|
49
|
+
RECEPCION:
|
|
50
|
+
'https://cel.sri.gob.ec/comprobantes-electronicos-ws/RecepcionComprobantesOffline?wsdl',
|
|
51
|
+
AUTORIZACION:
|
|
52
|
+
'https://cel.sri.gob.ec/comprobantes-electronicos-ws/AutorizacionComprobantesOffline?wsdl',
|
|
53
|
+
},
|
|
54
|
+
} as const
|
package/src/user.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** User roles in the system */
|
|
2
|
+
export type UserRole = 'owner' | 'accountant' | 'employee'
|
|
3
|
+
|
|
4
|
+
/** RIMPE regime type */
|
|
5
|
+
export type RimpeRegime = 'emprendedor' | 'negocio_popular' | null
|
|
6
|
+
|
|
7
|
+
/** Organization (a business entity with a RUC) */
|
|
8
|
+
export interface Organization {
|
|
9
|
+
id: string
|
|
10
|
+
ruc: string
|
|
11
|
+
razonSocial: string
|
|
12
|
+
nombreComercial?: string
|
|
13
|
+
direccionMatriz: string
|
|
14
|
+
estab: string // default '001'
|
|
15
|
+
ptoEmi: string // default '001'
|
|
16
|
+
obligadoContabilidad: boolean
|
|
17
|
+
regimenRimpe: RimpeRegime
|
|
18
|
+
ambiente: '1' | '2' // 1=pruebas, 2=produccion
|
|
19
|
+
preciosIncluyenIva: boolean
|
|
20
|
+
contactEmail?: string
|
|
21
|
+
logoUrl?: string
|
|
22
|
+
createdAt: string
|
|
23
|
+
updatedAt: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Organization membership (user <-> org relationship) */
|
|
27
|
+
export interface OrgMember {
|
|
28
|
+
id: string
|
|
29
|
+
userId: string
|
|
30
|
+
organizationId: string
|
|
31
|
+
role: UserRole
|
|
32
|
+
createdAt: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** User profile */
|
|
36
|
+
export interface UserProfile {
|
|
37
|
+
id: string
|
|
38
|
+
email: string
|
|
39
|
+
nombreCompleto: string
|
|
40
|
+
telefono?: string
|
|
41
|
+
createdAt: string
|
|
42
|
+
updatedAt: string
|
|
43
|
+
}
|