How shadowlion/transactapi-js works
Project type and purpose
• This is an open-source JavaScript/TypeScript SDK (library) that wraps the TransactAPI REST endpoints provided by North Capital Private Securities (NCPS).
• Its purpose is to expose each Transact API endpoint as a simple function call (e.g., getAccount, createTrade) with strong TypeScript types, mock‐based testing, and easy installation via npm/pnpm/yarn.
File structure
• Top‐level files:
• Configuration: .eslintrc, .prettierrc, tsconfig.json
• CI pipelines: .github/workflows/*.yml
• Build/test: jest.config.ts, package.json, pnpm-lock.yaml
• Documentation: README.md, CONTRIBUTE.md, example-doc.pdf
• src/ directory:
• base.ts – core HTTP client builder
• index.ts – aggregator that exports all endpoint modules
• One subfolder per endpoint (e.g., src/getAccount, src/createTrade), each containing:
– index.ts: main function
– types.ts: request/response interfaces
– enums.ts (where applicable)
– index.spec.ts: Jest unit tests using mocks
• Patterns:
• Single‐responsibility for each endpoint
• Shared base HTTP client
• Central export for package entry point
README for additional insights
• Clarifies it’s a community‐maintained wrapper (not official)
• Emphasizes use of mocks for tests (no real NCPS credentials needed during development)
• Shows usage examples in CJS, ES6, and TypeScript
a. Main components
1. SDK Entry Point (index.ts)
2. Endpoint Modules (each folder under src/)
3. Core HTTP Client (base.ts)
4. Type Definitions (types.ts, enums.ts)
5. Test Suite (Jest + mocks)
6. CI/CD (GitHub Actions workflows)
7. External Service (NCPS TransactAPI)
8. Package Manager / Registry (npm / pnpm)
b. Relationships and interactions
• The SDK Entry Point re-exports each Endpoint Module.
• Each Endpoint Module imports the Core HTTP Client and its own types.
• When a user calls an endpoint function, it invokes the Core HTTP Client to make an HTTP request to the TransactAPI.
• The Core HTTP Client attaches clientID & developerAPIKey headers and serializes payloads.
• Responses flow back through the endpoint function to the user.
• During development, Jest tests invoke endpoint modules but intercept HTTP calls with mocks.
• CI workflows run lint, type checks, and unit tests on push/PR.
• On publish, package.json metadata + index.ts define the library’s entry points, and pnpm/npm publishes to the registry.
c. Architectural patterns and design principles
• Modular design – one folder per endpoint
• DRY – shared Core HTTP client logic in base.ts
• Strong typing – all payloads/responses in types.ts
• Test isolation – mocks for every endpoint
• CI/CD ensures code quality and test coverage
d. Relevant technologies
• Node.js + TypeScript
• Jest for unit testing
• ESLint & Prettier for code style
• GitHub Actions for CI/CD
• pnpm (lockfile), npm registry
• Components as labeled rectangles:
• Blue: SDK code (Entry Point, Endpoint Modules, Core Client)
• Green: Type definitions
• Orange: Test Suite / Mocks
• Purple: CI/CD
• From “User Application” to “SDK Entry Point” to “Endpoint Module” to “Core HTTP Client” to “TransactAPI”
• From “Endpoint Module” to “types.ts/enums.ts” for payload schemas
• From “CI/CD” to lint, test, build jobs
• From “Build Output” to “npm registry” (publish)
• Rectangles for code modules