@peac/adapter-core 0.12.5 → 0.12.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +30 -33
  2. package/package.json +20 -4
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @peac/adapter-core
2
2
 
3
- Shared utilities for PEAC payment rail adapters.
3
+ Shared Result types, validators, and payment proof interfaces for PEAC adapters.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,34 +8,33 @@ Shared utilities for PEAC payment rail adapters.
8
8
  pnpm add @peac/adapter-core
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## What It Does
12
12
 
13
- ### Result Type
13
+ `@peac/adapter-core` provides the foundational utilities that all PEAC adapters build on. It enforces a "never throws" convention where all adapter functions return explicit `Result<T>` values instead of throwing exceptions. It also provides input validators for common fields (amounts, currencies, networks, timestamps) and defines the `PaymentProofAdapter` interface that payment-focused adapters implement.
14
14
 
15
- All adapter functions use the Result type for explicit error handling:
15
+ ## How Do I Use It?
16
+
17
+ ### Use the Result type for explicit error handling
16
18
 
17
19
  ```typescript
18
- import { ok, err, isOk, type Result } from '@peac/adapter-core';
20
+ import { ok, adapterErr, isOk, type Result, type AdapterError } from '@peac/adapter-core';
19
21
 
20
- function parseEvent(input: unknown): Result<Event, AdapterError> {
22
+ function parseEvent(input: unknown): Result<{ id: string }, AdapterError> {
21
23
  if (!input) {
22
24
  return adapterErr('input is required', 'missing_required_field');
23
25
  }
24
- return ok({ ...parsed });
26
+ return ok({ id: 'parsed-event' });
25
27
  }
26
28
 
27
- // Handle result
28
29
  const result = parseEvent(data);
29
30
  if (isOk(result)) {
30
- console.log(result.value);
31
+ console.log(result.value.id);
31
32
  } else {
32
- console.error(result.error.message);
33
+ console.error(result.error.code, result.error.message);
33
34
  }
34
35
  ```
35
36
 
36
- ### Validators
37
-
38
- Common validation functions for adapter inputs:
37
+ ### Validate adapter inputs
39
38
 
40
39
  ```typescript
41
40
  import { requireString, requireAmount, requireCurrency, requireObject } from '@peac/adapter-core';
@@ -54,35 +53,33 @@ function parseWebhook(event: unknown) {
54
53
  }
55
54
  ```
56
55
 
57
- ### Available Validators
58
-
59
- | Validator | Description |
60
- | ------------------------------------- | --------------------------- |
61
- | `requireString(value, field)` | Non-empty string required |
62
- | `optionalString(value, field)` | String or undefined |
63
- | `requireNumber(value, field)` | Finite number required |
64
- | `requireAmount(value)` | Non-negative safe integer |
65
- | `requireCurrency(value)` | ISO 4217 currency code |
66
- | `optionalNetwork(value)` | Network identifier (CAIP-2) |
67
- | `requireObject(value, field)` | Non-null object |
68
- | `optionalTimestamp(value)` | ISO 8601 or Unix seconds |
69
- | `optionalBoolean(value, field)` | Boolean or undefined |
70
- | `requireEnum(value, allowed, field)` | Value from allowed list |
71
- | `optionalEnum(value, allowed, field)` | Enum or undefined |
72
-
73
- ### JSON Types
74
-
75
- Re-exported from `@peac/kernel` for convenience:
56
+ ### Use JSON types for evidence structures
76
57
 
77
58
  ```typescript
78
59
  import type { JsonObject, JsonValue } from '@peac/adapter-core';
79
60
 
80
61
  interface PaymentEvidence {
81
62
  rail: string;
82
- evidence: JsonObject; // JSON-safe, no unknown
63
+ evidence: JsonObject;
83
64
  }
84
65
  ```
85
66
 
67
+ ## Integrates With
68
+
69
+ - `@peac/kernel` (Layer 0): JSON types re-exported for convenience
70
+ - `@peac/adapter-x402` (Layer 4): Uses Result types and validators
71
+ - `@peac/adapter-openclaw` (Layer 4): Uses Result types
72
+ - All `@peac/adapter-*` and `@peac/mappings-*` packages
73
+
74
+ ## For Agent Developers
75
+
76
+ If you are building a custom PEAC adapter for a new payment rail or protocol:
77
+
78
+ - Import `Result`, `ok`, `err`, and `adapterErr` to follow the "never throws" convention
79
+ - Use the provided validators (`requireAmount`, `requireCurrency`, `requireString`) for input parsing
80
+ - Implement the `PaymentProofAdapter` interface for payment-focused adapters
81
+ - See the [llms.txt](https://github.com/peacprotocol/peac/blob/main/llms.txt) for a concise protocol overview
82
+
86
83
  ## License
87
84
 
88
85
  Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peac/adapter-core",
3
- "version": "0.12.5",
3
+ "version": "0.12.7",
4
4
  "description": "Shared utilities for PEAC payment rail adapters",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.ts",
@@ -15,10 +15,10 @@
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/peacprotocol/peac.git",
18
+ "url": "git+https://github.com/peacprotocol/peac.git",
19
19
  "directory": "packages/adapters/core"
20
20
  },
21
- "author": "jithinraj <7850727+jithinraj@users.noreply.github.com>",
21
+ "author": "PEAC Protocol Contributors",
22
22
  "license": "Apache-2.0",
23
23
  "files": [
24
24
  "dist",
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@peac/kernel": "0.12.5"
31
+ "@peac/kernel": "0.12.7"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^22.19.11",
@@ -36,6 +36,22 @@
36
36
  "vitest": "^4.0.0",
37
37
  "tsup": "^8.0.0"
38
38
  },
39
+ "bugs": {
40
+ "url": "https://github.com/peacprotocol/peac/issues"
41
+ },
42
+ "homepage": "https://github.com/peacprotocol/peac#readme",
43
+ "keywords": [
44
+ "peac",
45
+ "peacprotocol",
46
+ "interaction-records",
47
+ "signed-records",
48
+ "receipts",
49
+ "originary",
50
+ "adapter",
51
+ "carrier",
52
+ "transport",
53
+ "evidence"
54
+ ],
39
55
  "scripts": {
40
56
  "prebuild": "rm -rf dist",
41
57
  "build": "pnpm run build:js && pnpm run build:types",