Skip to content

Commit b9b0c39

Browse files
authored
Merge pull request #5 from FiscalAPI/feat/AddLadingSupport
Added lading support
2 parents 0edbfbc + 3167689 commit b9b0c39

9 files changed

Lines changed: 7465 additions & 543 deletions

File tree

CLAUDE.md

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,66 @@ FiscalAPI SDK for Node.js - Official TypeScript SDK for Mexican electronic invoi
99
## Build Commands
1010

1111
```bash
12-
npm run build # Full build: clean + esm + cjs + types
13-
npm run build:esm # TypeScript to ES Modules (dist/esm)
14-
npm run build:cjs # TypeScript to CommonJS (dist/cjs)
15-
npm run build:types # TypeScript declaration files (dist/types)
12+
npm run build # Full build: clean + cjs + esm + package-json markers
13+
npm run build:esm # TypeScript → ES Modules (dist/esm), then fix-esm-imports.js adds .js extensions
14+
npm run build:cjs # TypeScript → CommonJS (dist/cjs)
1615
npm run clean # Remove dist directory
17-
npm test # Run Jest tests
18-
npm run lint # ESLint on src/**/*.ts
16+
npm test # Run Jest (note: jest not in devDependencies yet)
17+
npm run lint # ESLint on src/**/*.ts (note: eslint not in devDependencies yet)
1918
npm run main # Run examples/main.ts with ts-node
2019
```
2120

21+
There is no `build:types` script — the full `build` script handles CJS + ESM + dual-package markers via `build:package-json` (creates `dist/cjs/package.json` with `"type":"commonjs"` and `dist/esm/package.json` with `"type":"module"`).
22+
2223
## Architecture
2324

24-
**Facade Pattern**: `FiscalapiClient` is the main entry point exposing all services:
25-
- `invoices` - CFDI invoice creation, cancellation, PDF generation
26-
- `products` - Product/service catalog management
27-
- `persons` - Issuer/recipient (emisor/receptor) management
28-
- `taxFiles` - CSD certificate upload
29-
- `catalogs` - SAT catalog queries
30-
- `downloadCatalogs`, `downloadRules`, `downloadRequests` - Bulk XML download
31-
32-
**Directory Structure**:
33-
- `src/abstractions/` - Service interfaces (I*Service)
34-
- `src/services/` - Service implementations extending `BaseFiscalapiService`
35-
- `src/models/` - Data models (Invoice, Person, Product, etc.)
36-
- `src/common/` - Shared DTOs (ApiResponse, PagedList, FiscalapiSettings)
37-
- `src/utils/` - Date formatting (Luxon), Base64 encoding, validation helpers
25+
**Facade Pattern**: `FiscalapiClient` (`src/services/fiscalapi-client.ts`) is the single entry point.
26+
- Static factory: `FiscalapiClient.create(settings)` — validates settings, sets defaults, creates one shared HTTP client
27+
- Private constructor enforces factory usage
28+
- Services exposed as readonly properties: `invoices`, `products`, `persons`, `taxFiles`, `catalogs`, `apiKeys`, `stamps`, `downloadCatalogs`, `downloadRules`, `downloadRequests`
29+
30+
**Service Layer**:
31+
- `BaseFiscalapiService` provides CRUD: `list()`, `getById()`, `create()`, `update()`, `remove()`, `upload()`
32+
- Specialized services add domain methods (e.g., `InvoiceService.cancel()`, `.getPdf()`, `.getXml()`, `.send()`, `.getStatus()`)
33+
- `PersonService` contains nested `EmployeeService` and `EmployerService`
34+
35+
**HTTP Client** (`src/http/`):
36+
- Axios-based with 30s timeout
37+
- Factory caches clients by key `apiKey:tenant:apiUrl`
38+
- Headers: `X-API-KEY`, `X-TENANT-KEY`, `X-TIMEZONE`
39+
- Debug mode enables request/response logging via Axios interceptors and disables SSL certificate verification (`rejectUnauthorized: false`)
3840

3941
**Key Patterns**:
40-
- All services implement interfaces from `abstractions/`
41-
- HTTP client injected via factory pattern
42-
- Dual-package output: ESM + CommonJS + TypeScript declarations
43-
- Date handling uses Luxon with `America/Mexico_City` timezone
44-
- SAT date format: `yyyy-MM-ddTHH:mm:ss`
42+
- All services implement interfaces from `src/abstractions/`
43+
- `ApiResponse<T>` wraps all responses: `{ succeeded, data, message, details, httpStatusCode }`
44+
- Dual-package output: ESM + CJS. Post-build script `scripts/fix-esm-imports.js` adds `.js` extensions to ESM imports for Node.js native module support
45+
- Date handling uses Luxon with `America/Mexico_City` timezone; SAT format: `yyyy-MM-dd'T'HH:mm:ss`
46+
- `src/index.ts` re-exports 100+ types — all public API surface
4547

4648
## Configuration
4749

4850
```typescript
49-
const settings: FiscalapiSettings = {
51+
const client = FiscalapiClient.create({
5052
apiUrl: "https://test.fiscalapi.com", // or https://live.fiscalapi.com
5153
apiKey: "<api_key>",
5254
tenant: "<tenant>",
53-
apiVersion?: "v4", // default
54-
timeZone?: "America/Mexico_City", // default
55-
debug?: false
56-
};
57-
const client = FiscalapiClient.create(settings);
55+
apiVersion: "v4", // default
56+
timeZone: "America/Mexico_City", // default
57+
debug: false // enables logging + disables SSL verification
58+
});
5859
```
5960

6061
## Two Operation Modes
6162

6263
1. **By References**: Send only IDs of pre-configured entities in FiscalAPI dashboard
6364
2. **By Values**: Send complete data in each request (no prior setup needed)
6465

66+
Examples for both modes are in `examples/` (7 files covering invoices, payroll, local taxes, stamps, employee/employer data).
67+
6568
## TypeScript Configuration
6669

67-
Strict mode enabled with all checks: `noImplicitAny`, `strictNullChecks`, `noImplicitReturns`, `noUnusedParameters`. Target ES2018.
70+
Strict mode enabled. Target: **ES2019**. Key flags: `noImplicitAny`, `strictNullChecks`, `noImplicitReturns`, `noUnusedParameters`, `noFallthroughCasesInSwitch`. `noUnusedLocals` is **false**. Three tsconfig files: `tsconfig.base.json` (shared), `tsconfig.esm.json` (ESNext modules → dist/esm), `tsconfig.cjs.json` (CommonJS → dist/cjs).
71+
72+
## CI/CD
73+
74+
GitHub Actions (`.github/workflows/main.yml`): manual trigger only, builds on Node 18, publishes to npm. No tests run before publish.

0 commit comments

Comments
 (0)