-
Notifications
You must be signed in to change notification settings - Fork 103
feat(ack-pay): add approval model types #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EfeDurmaz16
wants to merge
5
commits into
agentcommercekit:main
Choose a base branch
from
EfeDurmaz16:feat/ack-pay-approval-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
05ddd97
feat(ack-pay): add approval model types
EfeDurmaz16 05cd68c
chore: add approval types changeset
EfeDurmaz16 5a358db
docs(ack-pay): use future approval expiry placeholder
EfeDurmaz16 77fb9d3
test(ack-pay): cover approval runtime schemas
EfeDurmaz16 44e73f0
fix(ack-pay): normalize approval timestamps
EfeDurmaz16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@agentcommercekit/ack-pay": patch | ||
| --- | ||
|
|
||
| Add approval request and decision model types. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import * as v from "valibot" | ||
| import { describe, expect, it } from "vitest" | ||
|
|
||
| import * as valibot from "./schemas/valibot" | ||
| import * as zodv3 from "./schemas/zod/v3" | ||
| import * as zodv4 from "./schemas/zod/v4" | ||
|
|
||
| const schemas = { | ||
| valibot: { | ||
| approvalRequest: (value: unknown) => | ||
| v.safeParse(valibot.paymentApprovalRequestSchema, value).success, | ||
| approvalDecision: (value: unknown) => | ||
| v.safeParse(valibot.paymentApprovalDecisionSchema, value).success, | ||
| }, | ||
| zodv3: { | ||
| approvalRequest: (value: unknown) => | ||
| zodv3.paymentApprovalRequestSchema.safeParse(value).success, | ||
| approvalDecision: (value: unknown) => | ||
| zodv3.paymentApprovalDecisionSchema.safeParse(value).success, | ||
| }, | ||
| zodv4: { | ||
| approvalRequest: (value: unknown) => | ||
| zodv4.paymentApprovalRequestSchema.safeParse(value).success, | ||
| approvalDecision: (value: unknown) => | ||
| zodv4.paymentApprovalDecisionSchema.safeParse(value).success, | ||
| }, | ||
| } | ||
|
|
||
| describe.each(Object.entries(schemas))( | ||
| "payment approval schemas (%s)", | ||
| (_name, schema) => { | ||
| it("validates approval requests", () => { | ||
| expect( | ||
| schema.approvalRequest({ | ||
| id: "approval-1", | ||
| paymentRequestId: "payment-request-1", | ||
| paymentOptionId: "usdc-base", | ||
| requesterDid: "did:web:merchant.example", | ||
| reason: "Amount exceeds automated policy limit.", | ||
| expiresAt: "2026-01-01T00:00:00.000Z", | ||
| metadata: { policyId: "spend-limit" }, | ||
| }), | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it("accepts Date timestamps in approval requests", () => { | ||
| expect( | ||
| schema.approvalRequest({ | ||
| id: "approval-1", | ||
| paymentRequestId: "payment-request-1", | ||
| expiresAt: new Date("2026-01-01T00:00:00.000Z"), | ||
| }), | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it("rejects malformed approval requests", () => { | ||
| expect( | ||
| schema.approvalRequest({ | ||
| id: "approval-1", | ||
| requesterDid: "not-a-did", | ||
| }), | ||
| ).toBe(false) | ||
| }) | ||
|
|
||
| it("validates approval decisions", () => { | ||
| expect( | ||
| schema.approvalDecision({ | ||
| requestId: "approval-1", | ||
| decision: "approved", | ||
| approverDid: "did:web:operator.example", | ||
| reason: "Reviewed by operator.", | ||
| decidedAt: "2026-01-01T00:01:00.000Z", | ||
| metadata: { ticketId: "ticket-1" }, | ||
| }), | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it("accepts Date timestamps in approval decisions", () => { | ||
| expect( | ||
| schema.approvalDecision({ | ||
| requestId: "approval-1", | ||
| decision: "approved", | ||
| decidedAt: new Date("2026-01-01T00:01:00.000Z"), | ||
| }), | ||
| ).toBe(true) | ||
| }) | ||
|
|
||
| it("rejects malformed approval decisions", () => { | ||
| expect( | ||
| schema.approvalDecision({ | ||
| requestId: "approval-1", | ||
| decision: "pending", | ||
| decidedAt: "2026-01-01T00:01:00.000Z", | ||
| }), | ||
| ).toBe(false) | ||
| }) | ||
| }, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * A request for human or policy-system approval before a payment is executed. | ||
| * | ||
| * ACK-Pay does not prescribe an approval workflow. This type gives applications | ||
| * and demos a shared object shape for approval-required paths. | ||
| */ | ||
| export interface PaymentApprovalRequest { | ||
| id: string | ||
| paymentRequestId: string | ||
| paymentOptionId?: string | ||
| requesterDid?: string | ||
| reason?: string | ||
| expiresAt?: string | ||
| metadata?: Record<string, unknown> | ||
| } | ||
|
|
||
| export type PaymentApprovalDecisionValue = "approved" | "denied" | ||
|
|
||
| /** | ||
| * The result of a human or policy-system approval request. | ||
| */ | ||
| export interface PaymentApprovalDecision { | ||
| requestId: string | ||
| decision: PaymentApprovalDecisionValue | ||
| approverDid?: string | ||
| reason?: string | ||
| decidedAt: string | ||
| metadata?: Record<string, unknown> | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this introduces new exported ACK-Pay model types, the repo’s schema contract requires matching Valibot and Zod v3/v4 schemas for new types. As written, applications receiving these approval objects over the wire can import only TypeScript interfaces, so runtime validation through
@agentcommercekit/ack-pay/schemas/*is unavailable and inconsistent with existing payment request/receipt models; please add schemas for bothPaymentApprovalRequestandPaymentApprovalDecision.Useful? React with 👍 / 👎.