@valiron/sdk 2.0.0 → 2.1.1
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.
- package/README.md +12 -0
- package/bin/valiron-card.mjs +211 -0
- package/dist/card.d.ts +565 -0
- package/dist/card.js +722 -0
- package/dist/clients.js +2 -2
- package/dist/edge.d.ts +87 -0
- package/dist/edge.js +164 -0
- package/dist/edgeGate.d.ts +146 -0
- package/dist/edgeGate.js +230 -0
- package/dist/edgeGateVerify.d.ts +146 -0
- package/dist/edgeGateVerify.js +243 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/middleware.d.ts +2 -0
- package/dist/middleware.js +6 -3
- package/dist/operatorSdk.d.ts +8 -0
- package/dist/operatorSdk.js +8 -0
- package/docs/API-REFERENCE.md +59 -80
- package/docs/CLOUDFLARE-GATE-MIDDLEWARE.md +196 -0
- package/docs/CRAWLER-PROTECTION.md +509 -25
- package/docs/DASHBOARD.md +72 -214
- package/docs/E2E-MIDDLEWARE-INTEGRATION.md +9 -46
- package/docs/ERRORS.md +3 -11
- package/docs/PROVIDER-IDENTITY.md +1 -1
- package/docs/QUICKSTART.md +7 -22
- package/docs/README.md +10 -9
- package/docs/SDK-REFERENCE.md +51 -7
- package/docs/SECURITY-UPGRADE-2026-10-31.md +3 -3
- package/docs/llms.txt +19 -14
- package/examples/cloudflare-gate-worker/README.md +198 -0
- package/examples/cloudflare-gate-worker/package.json +20 -0
- package/examples/cloudflare-gate-worker/worker.ts +309 -0
- package/examples/cloudflare-gate-worker/wrangler.toml +46 -0
- package/examples/cloudflare-worker/package.json +8 -0
- package/examples/cloudflare-worker/worker.ts +495 -0
- package/examples/cloudflare-worker/wrangler.toml +57 -0
- package/package.json +34 -4
- package/docs/AGENT-READY-APIS.md +0 -294
package/README.md
CHANGED
|
@@ -6,3 +6,15 @@ Valiron verifies AI agent identity and enforces access policies at your API.
|
|
|
6
6
|
- [Agent docs](https://www.valiron.co/llms-full.txt)
|
|
7
7
|
- [Website](https://www.valiron.co)
|
|
8
8
|
- [founders@valiron.co](mailto:founders@valiron.co)
|
|
9
|
+
|
|
10
|
+
## Hosted request billing
|
|
11
|
+
|
|
12
|
+
Free includes 10,000 Agent Access requests per UTC month; Pro includes 100,000. Active paid Pro customers can separately opt in to additional Agent Access calls at $0.001 each. Crawler Protection has its own allowance and opt-in. This counts hosted admission calls, not every local SDK method. View current counts and request-overage estimates in [Dashboard → Usage](https://www.valiron.co/dashboard/usage). See the [metered routes and billing contract](https://www.valiron.co/docs/agents/API-REFERENCE.md#monthly-request-allowance).
|
|
13
|
+
|
|
14
|
+
## Website crawler protection
|
|
15
|
+
|
|
16
|
+
Website crawler verification and rendering/database admission use the separate `@valiron/crawler-protection` package, not this agent middleware SDK. Install `npm install @valiron/crawler-protection@^0.6.0` for the current AI provider checks and explicit allow/block defaults. Sign up for a server-side operator key and follow the [Crawler Protection quickstart](https://www.valiron.co/docs/crawler-protection/quickstart) and [selected AI service policy](https://www.valiron.co/docs/crawler-protection/policies#allow-selected-ai-services). Their allowances and optional overage consent are independent.
|
|
17
|
+
|
|
18
|
+
## Cloudflare Workers gate
|
|
19
|
+
|
|
20
|
+
Import `ValironClient`, `runValironEdgeGate`, `stripEdgeGateHeaders`, and `createEdgeIdentityVerifier` from `@valiron/sdk/edge-gate`. This node-free entry point runs the same general trust-gate contract (fresh request-bound proof checked before every decision including profile-cache hits, a 30-second per-isolate profile cache, and fail-closed 503s) in Cloudflare Workers and other fetch-based edge runtimes. A deployable template lives in `examples/cloudflare-gate-worker`; setup and end-to-end verification are in the [Cloudflare gate middleware guide](https://www.valiron.co/docs/agents/CLOUDFLARE-GATE-MIDDLEWARE.md).
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile, open, unlink } from "node:fs/promises";
|
|
3
|
+
import {
|
|
4
|
+
CardClient,
|
|
5
|
+
CardSellerClient,
|
|
6
|
+
CardAPIError,
|
|
7
|
+
createCardKey,
|
|
8
|
+
} from "../dist/card.js";
|
|
9
|
+
|
|
10
|
+
const [role, action, ...args] = process.argv.slice(2);
|
|
11
|
+
const option = (name) => {
|
|
12
|
+
const i = args.indexOf(`--${name}`);
|
|
13
|
+
if (i < 0 || !args[i + 1] || args[i + 1].startsWith("--"))
|
|
14
|
+
throw new Error(`--${name} is required`);
|
|
15
|
+
return args[i + 1];
|
|
16
|
+
};
|
|
17
|
+
const env = (name) => {
|
|
18
|
+
if (!process.env[name]) throw new Error(`${name} is required`);
|
|
19
|
+
return process.env[name];
|
|
20
|
+
};
|
|
21
|
+
const jsonInput = async () =>
|
|
22
|
+
JSON.parse(await readFile(option("input"), "utf8"));
|
|
23
|
+
// Exclusive creation prevents replacing another agent's keys or following a symlink.
|
|
24
|
+
async function saveSecret(path, produce) {
|
|
25
|
+
const file = await open(path, "wx", 0o600);
|
|
26
|
+
try {
|
|
27
|
+
const result = await produce();
|
|
28
|
+
await file.writeFile(JSON.stringify(result, null, 2));
|
|
29
|
+
return result;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
await file.close();
|
|
32
|
+
await unlink(path);
|
|
33
|
+
throw error;
|
|
34
|
+
} finally {
|
|
35
|
+
await file.close();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function main() {
|
|
39
|
+
if (!role || role === "--help")
|
|
40
|
+
return {
|
|
41
|
+
commands: [
|
|
42
|
+
"agent apply --name NAME --key-file NEW_FILE",
|
|
43
|
+
"agent link --code CODE --name NAME --key-file NEW_FILE",
|
|
44
|
+
"agent poll --key-file FILE",
|
|
45
|
+
"seller status",
|
|
46
|
+
"seller register --input FILE",
|
|
47
|
+
"seller key --input FILE --output NEW_SECRET_FILE",
|
|
48
|
+
"seller offers",
|
|
49
|
+
"seller offer-create --input FILE",
|
|
50
|
+
"seller test-enable --id ID",
|
|
51
|
+
"seller publish --id ID",
|
|
52
|
+
"seller disable --id ID",
|
|
53
|
+
"seller revoke --id ID",
|
|
54
|
+
],
|
|
55
|
+
authentication: {
|
|
56
|
+
baseUrl:
|
|
57
|
+
"VALIRON_PASS_API_URL; set VALIRON_PASS_TRANSPORT=website for the Valiron website, otherwise use the explicitly enabled local Pass service API",
|
|
58
|
+
bootstrap: "VALIRON_OPERATOR_TOKEN (authorized seller session)",
|
|
59
|
+
operations: "VALIRON_PASS_MERCHANT_KEY (scoped Test or Live key)",
|
|
60
|
+
},
|
|
61
|
+
workspace: "https://www.valiron.co/pass",
|
|
62
|
+
};
|
|
63
|
+
const baseUrl = process.env.VALIRON_PASS_API_URL ?? env("VALIRON_CARD_API_URL");
|
|
64
|
+
const transport =
|
|
65
|
+
(process.env.VALIRON_PASS_TRANSPORT ?? process.env.VALIRON_CARD_TRANSPORT) === "website" ? "website" : "service";
|
|
66
|
+
if (role === "agent") {
|
|
67
|
+
const client = new CardClient({ baseUrl, transport });
|
|
68
|
+
if (action === "apply") {
|
|
69
|
+
const name = option("name");
|
|
70
|
+
const stored = await saveSecret(option("key-file"), async () => {
|
|
71
|
+
const keys = createCardKey();
|
|
72
|
+
const application = await client.startApplication({
|
|
73
|
+
name,
|
|
74
|
+
privateKey: keys.privateKey,
|
|
75
|
+
});
|
|
76
|
+
return { ...keys, application };
|
|
77
|
+
});
|
|
78
|
+
const { approvalUrl, comparisonCode, expiresAt, pollIntervalSeconds } =
|
|
79
|
+
stored.application;
|
|
80
|
+
return {
|
|
81
|
+
status: "owner_approval_required",
|
|
82
|
+
approvalUrl,
|
|
83
|
+
comparisonCode,
|
|
84
|
+
expiresAt,
|
|
85
|
+
pollIntervalSeconds,
|
|
86
|
+
nextAction:
|
|
87
|
+
"Ask the owner to open the URL, sign in or apply with an invite, compare the code, and approve. Then poll with the same key file. Never approve on their behalf.",
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (action === "link") {
|
|
91
|
+
const code = option("code");
|
|
92
|
+
const name = option("name");
|
|
93
|
+
const stored = await saveSecret(option("key-file"), async () => {
|
|
94
|
+
const keys = createCardKey();
|
|
95
|
+
const application = await client.linkWithInvite({
|
|
96
|
+
code, name, privateKey: keys.privateKey,
|
|
97
|
+
});
|
|
98
|
+
return { ...keys, application };
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
status: "owner_approval_required",
|
|
102
|
+
approvalUrl: stored.application.approvalUrl,
|
|
103
|
+
comparisonCode: stored.application.comparisonCode,
|
|
104
|
+
expiresAt: stored.application.expiresAt,
|
|
105
|
+
pollIntervalSeconds: stored.application.pollIntervalSeconds,
|
|
106
|
+
nextAction: "Show the owner the approval URL and comparison code, wait for their explicit approval, then poll with the same private key file.",
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (action === "poll") {
|
|
110
|
+
const stored = JSON.parse(await readFile(option("key-file"), "utf8"));
|
|
111
|
+
return client.pollApplication({
|
|
112
|
+
id: stored.application.id,
|
|
113
|
+
pollSecret: stored.application.pollSecret,
|
|
114
|
+
privateKey: stored.privateKey,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (role === "seller") {
|
|
119
|
+
if (["status", "register", "key", "revoke"].includes(action)) {
|
|
120
|
+
if (!process.env.VALIRON_OPERATOR_TOKEN) {
|
|
121
|
+
process.exitCode = 2;
|
|
122
|
+
return {
|
|
123
|
+
status: "authorization_required",
|
|
124
|
+
code: "operator_access_required",
|
|
125
|
+
signInUrl:
|
|
126
|
+
transport === "website"
|
|
127
|
+
? new URL("/dashboard/login?next=%2Fdashboard%2Fpass", baseUrl)
|
|
128
|
+
.href
|
|
129
|
+
: null,
|
|
130
|
+
nextAction:
|
|
131
|
+
"Ask the business operator to sign in and authorize bootstrap through the runtime secret store. Never request their password or an administrator key.",
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const seller = new CardSellerClient({
|
|
135
|
+
baseUrl,
|
|
136
|
+
transport,
|
|
137
|
+
operatorToken: env("VALIRON_OPERATOR_TOKEN"),
|
|
138
|
+
});
|
|
139
|
+
if (action === "status") {
|
|
140
|
+
const setup = await seller.getSetup();
|
|
141
|
+
return {
|
|
142
|
+
...setup,
|
|
143
|
+
nextAction: !setup.merchant
|
|
144
|
+
? "register_business"
|
|
145
|
+
: setup.merchant.status === "pending"
|
|
146
|
+
? "wait_for_pilot_approval"
|
|
147
|
+
: setup.merchant.status !== "active"
|
|
148
|
+
? "contact_support"
|
|
149
|
+
: !setup.credentials.some(
|
|
150
|
+
(k) =>
|
|
151
|
+
!k.revoked_at && Date.parse(k.expires_at) > Date.now(),
|
|
152
|
+
)
|
|
153
|
+
? "create_scoped_test_credentials"
|
|
154
|
+
: "configure_offer_and_test_real_enforcement",
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (action === "register")
|
|
158
|
+
return seller.registerBusiness(await jsonInput());
|
|
159
|
+
if (action === "revoke") return seller.revokeCredential(option("id"));
|
|
160
|
+
if (action === "key") {
|
|
161
|
+
const input = await jsonInput();
|
|
162
|
+
const path = option("output");
|
|
163
|
+
const result = await saveSecret(path, () =>
|
|
164
|
+
seller.createCredential(input),
|
|
165
|
+
);
|
|
166
|
+
return {
|
|
167
|
+
id: result.id,
|
|
168
|
+
expiresAt: result.expires_at,
|
|
169
|
+
credentialFile: path,
|
|
170
|
+
status: "created",
|
|
171
|
+
nextAction:
|
|
172
|
+
"Load the key from this private file into the authorized service secret store. It is not printed.",
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const client = new CardClient({
|
|
177
|
+
baseUrl,
|
|
178
|
+
transport,
|
|
179
|
+
merchantKey: process.env.VALIRON_PASS_MERCHANT_KEY ?? env("VALIRON_CARD_MERCHANT_KEY"),
|
|
180
|
+
});
|
|
181
|
+
if (action === "offers") return client.listOffers();
|
|
182
|
+
if (action === "offer-create") return client.createOffer(await jsonInput());
|
|
183
|
+
if (action === "test-enable") return client.enableTestOffer(option("id"));
|
|
184
|
+
if (action === "publish") return client.publishOffer(option("id"));
|
|
185
|
+
if (action === "disable") return client.disableOffer(option("id"));
|
|
186
|
+
}
|
|
187
|
+
throw new Error("Unknown command. Run valiron-pass --help.");
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
console.log(JSON.stringify(await main(), null, 2));
|
|
191
|
+
} catch (error) {
|
|
192
|
+
// Never echo transport errors, response bodies, input, or credentials.
|
|
193
|
+
console.error(
|
|
194
|
+
JSON.stringify(
|
|
195
|
+
error instanceof CardAPIError
|
|
196
|
+
? {
|
|
197
|
+
status: "error",
|
|
198
|
+
httpStatus: error.status,
|
|
199
|
+
code: error.code,
|
|
200
|
+
retryable: error.status === 429 || error.status >= 500,
|
|
201
|
+
}
|
|
202
|
+
: {
|
|
203
|
+
status: "error",
|
|
204
|
+
code: "command_failed",
|
|
205
|
+
nextAction:
|
|
206
|
+
"Check command syntax, required environment, private file paths, and network access. Run valiron-pass --help.",
|
|
207
|
+
},
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
process.exitCode = 1;
|
|
211
|
+
}
|