Getting Started
Create and deploy your first external library in under 10 minutes.
Prerequisites
- Node.js 18+
- npm or pnpm
- A ReAPI account with a project
Step 1: Clone the Template
git clone https://github.com/ReAPI-com/external-lib-template my-test-lib
cd my-test-lib
npm installStep 2: Explore the Structure
my-test-lib/
├── src/
│ ├── assertions/ # Custom assertion functions
│ │ └── index.ts
│ ├── generators/ # Value generator functions
│ │ └── index.ts
│ ├── hooks/ # API hooks (before/after)
│ │ └── index.ts
│ ├── test-cases/ # External test cases
│ │ └── index.ts
│ ├── utils/ # Shared utilities
│ │ └── index.ts
│ └── index.ts # Main export file
├── dist/ # Build output
├── package.json
├── tsconfig.json
└── rollup.config.js # Builds UMD bundleStep 3: Write a Simple Assertion
Edit src/assertions/index.ts:
import type { AssertionFunction } from "../types";
export const isPositiveNumber: AssertionFunction = {
id: "is-positive-number",
name: "Is Positive Number",
description: "Checks if a value is a positive number",
enabled: true,
deprecated: false,
tested: true,
function: async (value: unknown) => {
const passed = typeof value === "number" && value > 0;
$addAssertionResult({
passed,
message: passed
? `${value} is a positive number`
: `Expected positive number, got ${value}`,
operator: "isPositiveNumber",
leftValue: value,
rightValue: "> 0",
});
},
};
// Export all assertions
export const $$AssertionFunctions = [isPositiveNumber];Step 4: Build the Library
npm run buildThis creates:
dist/build.umd.js- The library bundledist/build.d.ts- TypeScript declarations
Step 5: Deploy to ReAPI
Use the ReAPI CLI to build and sync your library directly to the platform. This is faster and more secure than publishing to npm.
# Install CLI if you haven't already
npm install -g @reapi/cli
# Login to your account
reapi login
# Sync to your project
# Replace <project-id> with your actual project ID (found in Project Settings)
reapi lib sync --project <project-id>The CLI will:
- Build your library automatically
- Upload the bundle to ReAPI’s secure CDN
- Register/Update the library in your project
Step 6: Verify in ReAPI
- Go to Project Settings → External Libraries
- You should see “My Test Library” listed and enabled
- The status should be “Synced” with the latest version
Alternative: Deploy via npm (Legacy)
If you prefer using npm:
- Run
npm publish --access public - Go to ReAPI Project Settings → External Libraries
- Manually add the unpkg.com URL (e.g.,
https://unpkg.com/my-lib/dist/build.umd.js)
Step 7: Use in Tests
Your isPositiveNumber assertion is now available:
- In Assert Node → Select “Is Positive Number” from operators
- In Script Node → Call
MyTestLib.isPositiveNumber(value)
Quick Reference
| Command | Purpose |
|---|---|
npm run build | Build the library |
npm run test | Run unit tests |
npm run lint | Check code quality |
reapi lib sync | Deploy to ReAPI (Recommended) |
npm publish | Deploy to npm (Legacy) |
Next Steps
- How It Works - Understand the system
- Writing Components - Create more components
- External Test Cases - Write code-driven tests