
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
@apolitical/contracts
Advanced tools
An Nx library and NPM package for defining and interacting with Apolitical API endpoints, designed to streamline development with consistent contracts and robust type safety.
An Nx library and NPM package for defining and interacting with Apolitical API endpoints, designed to streamline development with consistent contracts and robust type safety.
ℹ️Note that @apolitical/contracts
has been recently refactored to follow the RFC for consolidating contracts. Please refer to the RFC for more info on the new structure.
@apolitical/contracts
provides:
For more on the underlying technology, check out ts-rest.
The new structure would look like this:
/src
/apis
/mgmt-api
/accounts
accounts.contract.ts
connections.contract.ts
index.ts
mgmt-api.contract.ts
mgmt-api.types.ts
index.ts
// more APIs here
/ts
/i18n
i18n.constants.ts
i18n.enums.ts
i18n.types.ts
// more files here
/zod
/extensions
index.ts
index.ts
Briefly:
/src/apis
contains the contracts for each API/src/ts
contains the shared types, enums and constants/src/zod
contains the shared zod extensionsLet’s imagine you have to create a new endpoint POST /images
within the assets-api
, so then the steps to create the contract for that new endpoint are as follows:
assets-api
at /backend/v2/libs/contracts/src/apis/assets-api
Image
is a new resource within assets-api
, we create a images.contract.ts
file (as described here)images
subcontract with it’s new create
method (as described here)images
subcontract to the assets
top-contract at assets-api.contract.ts
fileassets-api.types.ts
assets-api.enums.ts
assets-api.constants.ts
Let’s imagine you have to create a new endpoint POST /learners/:id/images
within the assets-api
, so then the steps to create the contract for that new endpoint are as follows:
assets-api
at /backend/v2/libs/contracts/src/apis/assets-api
learners
folder doesn’t exist create one (note that the learners
folder is created to encapsulate the learners.contract.ts
and the images.contract.ts
as the images
contract is a subcontract of learners
).assets
→ learners
→ images
We follow the Nest.js integration guide to integrate with Nest.js endpoints. In particular, we use the @TsRestHandler
decorator to define the handler for the endpoint as we are progressing towards a fully ts-rest-fied Nest.js setup.
We follow the ts-rest client guide to consume the client on the frontend. In particular, we use the Fetch Client to interact with the APIs from the frontend. This means that 4/5xx status codes will not throw an error, so you must check for these codes explicitly.
Run nx build contracts
to build the library.
Run nx test contracts
to execute the unit tests via Jest.
From the root of contracts run
node add-locale.js --locale <localeCode> --englishName <EnglishName> --nativeName <nativeName> --flag <flag>
for example
node add-locale.js --locale sv --englishName "Swedish" --nativeName "Svenska" --flag "🇸🇪"
FAQs
An Nx library and NPM package for defining and interacting with Apolitical API endpoints, designed to streamline development with consistent contracts and robust type safety.
We found that @apolitical/contracts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.