Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,19 @@ describe('APortIntegration', () => {
});

// Act
const result = await integration.verify('payments.refund.v1', 'agt_123');
const result = await integration.verify('finance.payment.refund.v1', 'agt_123');

// Assert
expect(result.verified).toBe(true);
expect(mockAPortAPI.verify).toHaveBeenCalledWith('payments.refund.v1', 'agt_123');
expect(mockAPortAPI.verify).toHaveBeenCalledWith('finance.payment.refund.v1', 'agt_123');
});

it('should handle verification failure', async () => {
// Arrange
mockAPortAPI.verify.mockRejectedValue(new Error('Verification failed'));

// Act & Assert
await expect(integration.verify('payments.refund.v1', 'agt_123'))
await expect(integration.verify('finance.payment.refund.v1', 'agt_123'))
.rejects.toThrow('Verification failed');
});
});
Expand All @@ -461,15 +461,15 @@ describe('APortIntegration', () => {
```javascript
/**
* Verifies an agent against a policy pack
* @param {string} policy - Policy pack identifier (e.g., 'payments.refund.v1')
* @param {string} policy - Policy pack identifier (e.g., 'finance.payment.refund.v1')
* @param {string} agentId - Agent identifier (e.g., 'agt_inst_xyz789')
* @param {Object} context - Additional context for verification
* @param {string} context.userId - User ID for user-specific policies
* @param {Object} context.metadata - Additional metadata
* @returns {Promise<VerificationResult>} Verification result
* @throws {APortError} If verification fails
* @example
* const result = await integration.verify('payments.refund.v1', 'agt_123', {
* const result = await integration.verify('finance.payment.refund.v1', 'agt_123', {
* userId: 'user_456',
* metadata: { amount: 100 }
* });
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const aportMiddleware = createAPortMiddleware({
});

app.post("/api/refunds",
aportMiddleware("payments.refund.v1"),
aportMiddleware("finance.payment.refund.v1"),
async (req, res) => {
// Policy already verified! Check specific limits
const passport = req.aport.passport;
Expand Down Expand Up @@ -326,7 +326,7 @@ protected_refund_tool = APortToolGuard(
description="Process customer refunds",
func=refund_tool
),
policy_pack="payments.refund.v1",
policy_pack="finance.payment.refund.v1",
agent_id="agt_inst_xyz789"
)

Expand All @@ -349,7 +349,7 @@ jobs:
- uses: aporthq/policy-verify-action@v1
with:
agent-id: ${{ secrets.APORT_AGENT_ID }}
policy-pack: 'repo.v1'
policy-pack: 'code.repository.merge.v1'
context: |
{
"repo": "${{ github.repository }}",
Expand Down
6 changes: 3 additions & 3 deletions docs/INTEGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,19 @@ describe('APortIntegration', () => {
});

// Act
const result = await integration.verify('payments.refund.v1', 'agt_123');
const result = await integration.verify('finance.payment.refund.v1', 'agt_123');

// Assert
expect(result.verified).toBe(true);
expect(mockAPortAPI.verify).toHaveBeenCalledWith('payments.refund.v1', 'agt_123');
expect(mockAPortAPI.verify).toHaveBeenCalledWith('finance.payment.refund.v1', 'agt_123');
});

it('should handle verification failure', async () => {
// Arrange
mockAPortAPI.verify.mockRejectedValue(new Error('Verification failed'));

// Act & Assert
await expect(integration.verify('payments.refund.v1', 'agt_123'))
await expect(integration.verify('finance.payment.refund.v1', 'agt_123'))
.rejects.toThrow('Verification failed');
});
});
Expand Down
14 changes: 7 additions & 7 deletions examples/developer-tools/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ npm start demo
npm start verify -- --interactive

# Direct verification with real agent IDs - NO API KEY NEEDED!
npm start verify ap_a2d10232c6534523812423eec8a1425c payments.refund.v1 '{"amount":50}'
npm start verify ap_a2d10232c6534523812423eec8a1425c finance.payment.refund.v1 '{"amount":50}'

# Or using options
npm start verify -a ap_a2d10232c6534523812423eec8a1425c -p payments.refund.v1 -c '{"amount":50}'
npm start verify -a ap_a2d10232c6534523812423eec8a1425c -p finance.payment.refund.v1 -c '{"amount":50}'

# Get passport information - NO API KEY NEEDED!
npm start get-passport -- --interactive
Expand All @@ -55,10 +55,10 @@ npm start create-passport -- --interactive
aport verify --interactive

# Direct mode (positional arguments)
aport verify agt_inst_refund_bot_123 payments.refund.v1 '{"amount":50}'
aport verify agt_inst_refund_bot_123 finance.payment.refund.v1 '{"amount":50}'

# Direct mode (options)
aport verify -a agt_inst_refund_bot_123 -p payments.refund.v1 -c '{"amount":50}'
aport verify -a agt_inst_refund_bot_123 -p finance.payment.refund.v1 -c '{"amount":50}'
```

### `policy` - Verify against specific policy pack
Expand Down Expand Up @@ -113,9 +113,9 @@ The CLI includes pre-configured sample agent IDs for testing:

Test against these policy packs:

- `payments.refund.v1` - Refund processing policies
- `finance.payment.refund.v1` - Refund processing policies
- `data.export.v1` - Data export policies
- `repo.v1` - Repository operation policies
- `code.repository.merge.v1` - Repository operation policies
- `admin.access.v1` - Admin access policies

## 🔧 Configuration
Expand Down Expand Up @@ -158,7 +158,7 @@ npm start demo
### Example 1: Verify Refund Bot

```bash
aport verify -a agt_inst_refund_bot_123 -p payments.refund.v1 -c '{"amount":50,"currency":"USD"}'
aport verify -a agt_inst_refund_bot_123 -p finance.payment.refund.v1 -c '{"amount":50,"currency":"USD"}'
```

### Example 2: Create Test Passport
Expand Down
18 changes: 11 additions & 7 deletions examples/developer-tools/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ program
name: "policy",
message: "Select a policy pack:",
choices: [
"payments.refund.v1",
"finance.payment.refund.v1",
"data.export.v1",
"repo.v1",
"code.repository.merge.v1",
"admin.access.v1",
],
},
Expand Down Expand Up @@ -372,11 +372,13 @@ program

// Demo 1: Verify refund bot
console.log(
chalk.yellow("1. Verifying refund bot against payments.refund.v1 policy")
chalk.yellow(
"1. Verifying refund bot against finance.payment.refund.v1 policy"
)
);
try {
const result1 = await client.verify(
"payments.refund.v1",
"finance.payment.refund.v1",
SAMPLE_AGENTS["refund-bot"],
{
amount: 50,
Expand Down Expand Up @@ -449,14 +451,16 @@ program
});

console.log(chalk.yellow("\nPolicy Packs:"));
console.log(" payments.refund.v1 # Refund processing");
console.log(" finance.payment.refund.v1 # Refund processing");
console.log(" data.export.v1 # Data export");
console.log(" repo.v1 # Repository operations");
console.log(
" code.repository.merge.v1 # Repository operations"
);
console.log(" admin.access.v1 # Admin access\n");

console.log(chalk.yellow("Examples (No API Key Needed!):"));
console.log(
" aport verify -a ap_a2d10232c6534523812423eec8a1425c -p payments.refund.v1 -c '{\"amount\":50}'"
" aport verify -a ap_a2d10232c6534523812423eec8a1425c -p finance.payment.refund.v1 -c '{\"amount\":50}'"
);
console.log(
" aport policy -a ap_b804b365003247888c06c94347cf54fe -p data.export.v1 -c '{\"rows\":1000}'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/create-hacktoberfest-issues-complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ create_issue_interactive \
"Complete production-ready Shopify app using APort to verify refund requests via webhooks.

## Success Criteria
- Deployable app in /examples/shopify-guardrail using payments.refund.v1 policy
- Deployable app in /examples/shopify-guardrail using finance.payment.refund.v1 policy
- Complete Shopify app with APort verification
- Refund processing with policy checks
- Comprehensive tests and documentation
Expand Down
4 changes: 2 additions & 2 deletions templates/javascript-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const aportMiddleware = createAPortMiddleware({

// Protect a route
app.post('/refund',
aportMiddleware('payments.refund.v1'),
aportMiddleware('finance.payment.refund.v1'),
(req, res) => {
// Agent is verified, access passport data
const { passport, agentId } = req.aport;
Expand Down Expand Up @@ -103,7 +103,7 @@ The middleware looks for agent IDs in the following order:

```javascript
app.post('/refund',
aportMiddleware('payments.refund.v1'),
aportMiddleware('finance.payment.refund.v1'),
(req, res) => {
const { passport } = req.aport;

Expand Down
5 changes: 3 additions & 2 deletions templates/javascript-middleware/examples/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ app.get("/", (req, res) => {
version: "1.0.0",
endpoints: {
"GET /public": "Public endpoint (no verification)",
"POST /refund": "Refund endpoint (requires payments.refund.v1 policy)",
"POST /refund":
"Refund endpoint (requires finance.payment.refund.v1 policy)",
"GET /admin": "Admin endpoint (requires admin.access policy)",
},
});
Expand All @@ -37,7 +38,7 @@ app.get("/public", (req, res) => {
// Refund endpoint (requires verification)
app.post(
"/refund",
aportMiddleware("payments.refund.v1", {
aportMiddleware("finance.payment.refund.v1", {
context: {
endpoint: "refund",
action: "process_refund",
Expand Down
24 changes: 14 additions & 10 deletions templates/javascript-middleware/tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ describe("APort Express Middleware", () => {
res.json({ message: "public" });
});

app.post("/refund", aportMiddleware("payments.refund.v1"), (req, res) => {
res.json({
success: true,
agentId: req.aport.agentId,
});
});
app.post(
"/refund",
aportMiddleware("finance.payment.refund.v1"),
(req, res) => {
res.json({
success: true,
agentId: req.aport.agentId,
});
}
);
});

afterEach(() => {
Expand Down Expand Up @@ -74,7 +78,7 @@ describe("APort Express Middleware", () => {
expect(response.body.success).toBe(true);
expect(response.body.agentId).toBe("agt_test123");
expect(mockClient.verify).toHaveBeenCalledWith(
"payments.refund.v1",
"finance.payment.refund.v1",
"agt_test123",
expect.any(Object)
);
Expand Down Expand Up @@ -132,7 +136,7 @@ describe("APort Express Middleware", () => {
.expect(200);

expect(mockClient.verify).toHaveBeenCalledWith(
"payments.refund.v1",
"finance.payment.refund.v1",
"agt_header123",
expect.any(Object)
);
Expand All @@ -150,7 +154,7 @@ describe("APort Express Middleware", () => {
.expect(200);

expect(mockClient.verify).toHaveBeenCalledWith(
"payments.refund.v1",
"finance.payment.refund.v1",
"agt_query123",
expect.any(Object)
);
Expand All @@ -171,7 +175,7 @@ describe("APort Express Middleware", () => {
.expect(200);

expect(mockClient.verify).toHaveBeenCalledWith(
"payments.refund.v1",
"finance.payment.refund.v1",
"agt_body123",
expect.any(Object)
);
Expand Down
4 changes: 2 additions & 2 deletions templates/python-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ aport_middleware = APortMiddleware(
async def process_refund(
request: Request,
aport_data: dict = Depends(
aport_middleware.require_policy("payments.refund.v1")
aport_middleware.require_policy("finance.payment.refund.v1")
)
):
# Agent is verified, access passport data
Expand Down Expand Up @@ -120,7 +120,7 @@ The middleware looks for agent IDs in the following order:
async def process_refund(
request: Request,
aport_data: dict = Depends(
aport_middleware.require_policy("payments.refund.v1")
aport_middleware.require_policy("finance.payment.refund.v1")
)
):
passport = aport_data["passport"]
Expand Down
4 changes: 2 additions & 2 deletions templates/python-middleware/examples/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def root():
"version": "1.0.0",
"endpoints": {
"GET /public": "Public endpoint (no verification)",
"POST /refund": "Refund endpoint (requires payments.refund.v1 policy)",
"POST /refund": "Refund endpoint (requires finance.payment.refund.v1 policy)",
"GET /admin": "Admin endpoint (requires admin.access policy)"
}
}
Expand All @@ -59,7 +59,7 @@ async def process_refund(
request: RefundRequest,
aport_data: Dict[str, Any] = Depends(
aport_middleware.require_policy(
"payments.refund.v1",
"finance.payment.refund.v1",
context={"endpoint": "refund", "action": "process_refund"}
)
)
Expand Down
2 changes: 1 addition & 1 deletion templates/python-middleware/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def public():
@app.post("/refund")
async def refund(
request: Request,
aport_data: dict = middleware.require_policy("payments.refund.v1")
aport_data: dict = middleware.require_policy("finance.payment.refund.v1")
):
return {"success": True, "agent_id": aport_data["agent_id"]}

Expand Down
14 changes: 7 additions & 7 deletions tools/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ npm start demo
npm start verify -- --interactive

# Direct verification with real agent IDs - NO API KEY NEEDED!
npm start verify ap_a2d10232c6534523812423eec8a1425c payments.refund.v1 '{"amount":50}'
npm start verify ap_a2d10232c6534523812423eec8a1425c finance.payment.refund.v1 '{"amount":50}'

# Or using options
npm start verify -a ap_a2d10232c6534523812423eec8a1425c -p payments.refund.v1 -c '{"amount":50}'
npm start verify -a ap_a2d10232c6534523812423eec8a1425c -p finance.payment.refund.v1 -c '{"amount":50}'

# Get passport information - NO API KEY NEEDED!
npm start get-passport -- --interactive
Expand All @@ -55,10 +55,10 @@ npm start create-passport -- --interactive
aport verify --interactive

# Direct mode (positional arguments)
aport verify agt_inst_refund_bot_123 payments.refund.v1 '{"amount":50}'
aport verify agt_inst_refund_bot_123 finance.payment.refund.v1 '{"amount":50}'

# Direct mode (options)
aport verify -a agt_inst_refund_bot_123 -p payments.refund.v1 -c '{"amount":50}'
aport verify -a agt_inst_refund_bot_123 -p finance.payment.refund.v1 -c '{"amount":50}'
```

### `policy` - Verify against specific policy pack
Expand Down Expand Up @@ -113,9 +113,9 @@ The CLI includes pre-configured sample agent IDs for testing:

Test against these policy packs:

- `payments.refund.v1` - Refund processing policies
- `finance.payment.refund.v1` - Refund processing policies
- `data.export.v1` - Data export policies
- `repo.v1` - Repository operation policies
- `code.repository.merge.v1` - Repository operation policies
- `admin.access.v1` - Admin access policies

## 🔧 Configuration
Expand Down Expand Up @@ -158,7 +158,7 @@ npm start demo
### Example 1: Verify Refund Bot

```bash
aport verify -a agt_inst_refund_bot_123 -p payments.refund.v1 -c '{"amount":50,"currency":"USD"}'
aport verify -a agt_inst_refund_bot_123 -p finance.payment.refund.v1 -c '{"amount":50,"currency":"USD"}'
```

### Example 2: Create Test Passport
Expand Down
Loading
Loading