@zerocore1/sdk 0.1.0
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/dist/index.cjs +229 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +158 -0
- package/dist/index.d.ts +158 -0
- package/dist/index.js +197 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Client: () => Client,
|
|
24
|
+
ZerocoreAuthError: () => ZerocoreAuthError,
|
|
25
|
+
ZerocoreError: () => ZerocoreError,
|
|
26
|
+
ZerocoreNetworkError: () => ZerocoreNetworkError,
|
|
27
|
+
ZerocorePaymentError: () => ZerocorePaymentError,
|
|
28
|
+
ZerocoreRateLimitError: () => ZerocoreRateLimitError
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/errors.ts
|
|
33
|
+
var ZerocoreError = class extends Error {
|
|
34
|
+
/** HTTP status code from the API, if applicable. */
|
|
35
|
+
statusCode;
|
|
36
|
+
constructor(message, statusCode) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.name = "ZerocoreError";
|
|
39
|
+
this.statusCode = statusCode;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var ZerocoreAuthError = class extends ZerocoreError {
|
|
43
|
+
constructor(message = "Invalid API key") {
|
|
44
|
+
super(message, 401);
|
|
45
|
+
this.name = "ZerocoreAuthError";
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var ZerocorePaymentError = class extends ZerocoreError {
|
|
49
|
+
/** Machine-readable denial reason from the control plane. */
|
|
50
|
+
reason;
|
|
51
|
+
constructor(message, reason, statusCode = 403) {
|
|
52
|
+
super(message, statusCode);
|
|
53
|
+
this.name = "ZerocorePaymentError";
|
|
54
|
+
this.reason = reason;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var ZerocoreRateLimitError = class extends ZerocoreError {
|
|
58
|
+
/** Seconds to wait before retrying, if provided by the API. */
|
|
59
|
+
retryAfter;
|
|
60
|
+
constructor(retryAfter) {
|
|
61
|
+
const msg = retryAfter ? `Rate limited. Retry after ${retryAfter}s.` : "Rate limited.";
|
|
62
|
+
super(msg, 429);
|
|
63
|
+
this.name = "ZerocoreRateLimitError";
|
|
64
|
+
this.retryAfter = retryAfter;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var ZerocoreNetworkError = class extends ZerocoreError {
|
|
68
|
+
constructor(message = "Cannot connect to ZERO.CORE API.") {
|
|
69
|
+
super(message);
|
|
70
|
+
this.name = "ZerocoreNetworkError";
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/client.ts
|
|
75
|
+
var DEFAULT_BASE_URL = "https://augvmbhpuchkqqowxmrk.supabase.co/functions/v1";
|
|
76
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
77
|
+
var USER_AGENT = "zerocore-sdk-ts/0.1.0";
|
|
78
|
+
var Client = class {
|
|
79
|
+
apiKey;
|
|
80
|
+
baseUrl;
|
|
81
|
+
timeout;
|
|
82
|
+
constructor(options) {
|
|
83
|
+
const { apiKey, baseUrl, timeout } = options;
|
|
84
|
+
if (!apiKey || !apiKey.startsWith("zc_")) {
|
|
85
|
+
throw new ZerocoreAuthError(
|
|
86
|
+
"API key must start with 'zc_live_' or 'zc_test_'. Generate one at your ZERO.CORE dashboard \u2192 API Keys."
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
this.apiKey = apiKey;
|
|
90
|
+
this.baseUrl = (baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
91
|
+
this.timeout = timeout ?? DEFAULT_TIMEOUT;
|
|
92
|
+
}
|
|
93
|
+
// ── Public API ──────────────────────────────────────────────────────────
|
|
94
|
+
/**
|
|
95
|
+
* Request authorization for an agent payment.
|
|
96
|
+
*
|
|
97
|
+
* Call this **before** your agent executes any paid API call.
|
|
98
|
+
* The control plane checks:
|
|
99
|
+
* - Is the agent active? (kill switch)
|
|
100
|
+
* - Does this exceed the per-transaction limit?
|
|
101
|
+
* - Does this exceed the daily spending limit?
|
|
102
|
+
*
|
|
103
|
+
* If approved and `executeOnChain` is `true`, the Edge Function executes
|
|
104
|
+
* a real on-chain transfer (SOL or USDC SPL token).
|
|
105
|
+
*
|
|
106
|
+
* @throws {ZerocorePaymentError} Transaction was denied.
|
|
107
|
+
* @throws {ZerocoreAuthError} API key is invalid.
|
|
108
|
+
* @throws {ZerocoreRateLimitError} Too many requests.
|
|
109
|
+
* @throws {ZerocoreNetworkError} API is unreachable.
|
|
110
|
+
*/
|
|
111
|
+
async authorizeSpend(params) {
|
|
112
|
+
const { amountUsd, merchant, currency = "SOL", memo, executeOnChain = false } = params;
|
|
113
|
+
if (amountUsd <= 0) {
|
|
114
|
+
throw new Error("amountUsd must be positive");
|
|
115
|
+
}
|
|
116
|
+
if (!merchant) {
|
|
117
|
+
throw new Error("merchant is required");
|
|
118
|
+
}
|
|
119
|
+
if (currency !== "SOL" && currency !== "USDC") {
|
|
120
|
+
throw new Error("currency must be 'SOL' or 'USDC'");
|
|
121
|
+
}
|
|
122
|
+
const payload = {
|
|
123
|
+
amount_usd: amountUsd,
|
|
124
|
+
merchant,
|
|
125
|
+
execute_on_chain: executeOnChain,
|
|
126
|
+
currency
|
|
127
|
+
};
|
|
128
|
+
if (memo) {
|
|
129
|
+
payload.memo = memo;
|
|
130
|
+
}
|
|
131
|
+
const raw = await this.post("/authorize", payload);
|
|
132
|
+
return toApprovalResult(raw);
|
|
133
|
+
}
|
|
134
|
+
// ── Internal ────────────────────────────────────────────────────────────
|
|
135
|
+
async post(path, body) {
|
|
136
|
+
const url = `${this.baseUrl}${path}`;
|
|
137
|
+
let response;
|
|
138
|
+
try {
|
|
139
|
+
response = await fetch(url, {
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: {
|
|
142
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
143
|
+
"Content-Type": "application/json",
|
|
144
|
+
"User-Agent": USER_AGENT
|
|
145
|
+
},
|
|
146
|
+
body: JSON.stringify(body),
|
|
147
|
+
signal: AbortSignal.timeout(this.timeout)
|
|
148
|
+
});
|
|
149
|
+
} catch (err) {
|
|
150
|
+
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
151
|
+
throw new ZerocoreNetworkError("Request timed out.");
|
|
152
|
+
}
|
|
153
|
+
throw new ZerocoreNetworkError(
|
|
154
|
+
`Cannot connect to ${this.baseUrl}. Check your network or baseUrl setting.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
return this.handleResponse(response);
|
|
158
|
+
}
|
|
159
|
+
async handleResponse(response) {
|
|
160
|
+
if (response.ok) {
|
|
161
|
+
return await response.json();
|
|
162
|
+
}
|
|
163
|
+
if (response.status === 401) {
|
|
164
|
+
const data2 = await safeJson(response);
|
|
165
|
+
const msg = data2?.detail ?? "Invalid API key";
|
|
166
|
+
throw new ZerocoreAuthError(typeof msg === "string" ? msg : "Invalid API key");
|
|
167
|
+
}
|
|
168
|
+
if (response.status === 429) {
|
|
169
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
170
|
+
throw new ZerocoreRateLimitError(
|
|
171
|
+
retryAfter ? parseFloat(retryAfter) : void 0
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
if (response.status === 402 || response.status === 403) {
|
|
175
|
+
const data2 = await safeJson(response);
|
|
176
|
+
const detail = data2?.detail ?? data2;
|
|
177
|
+
if (detail && typeof detail === "object") {
|
|
178
|
+
throw new ZerocorePaymentError(
|
|
179
|
+
detail.message ?? "Payment denied",
|
|
180
|
+
detail.denial_reason ?? "UNKNOWN",
|
|
181
|
+
response.status
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
throw new ZerocorePaymentError(
|
|
185
|
+
typeof detail === "string" ? detail : "Payment denied",
|
|
186
|
+
"UNKNOWN",
|
|
187
|
+
response.status
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const data = await safeJson(response);
|
|
191
|
+
const message = data?.detail ?? data?.message ?? `API error ${response.status}`;
|
|
192
|
+
throw new ZerocoreError(
|
|
193
|
+
typeof message === "string" ? message : `API error ${response.status}`,
|
|
194
|
+
response.status
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
async function safeJson(response) {
|
|
199
|
+
try {
|
|
200
|
+
return await response.json();
|
|
201
|
+
} catch {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function toApprovalResult(raw) {
|
|
206
|
+
return {
|
|
207
|
+
approved: raw.approval_status === "approved",
|
|
208
|
+
transactionId: raw.transaction_id,
|
|
209
|
+
amountUsd: raw.amount_usd,
|
|
210
|
+
amountSol: raw.amount_sol,
|
|
211
|
+
amountUsdc: raw.amount_usdc,
|
|
212
|
+
currency: raw.currency,
|
|
213
|
+
merchant: raw.merchant,
|
|
214
|
+
remainingDailyLimit: raw.remaining_daily_limit,
|
|
215
|
+
solanaSignature: raw.solana_signature,
|
|
216
|
+
denialReason: raw.denial_reason,
|
|
217
|
+
message: raw.message
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
+
0 && (module.exports = {
|
|
222
|
+
Client,
|
|
223
|
+
ZerocoreAuthError,
|
|
224
|
+
ZerocoreError,
|
|
225
|
+
ZerocoreNetworkError,
|
|
226
|
+
ZerocorePaymentError,
|
|
227
|
+
ZerocoreRateLimitError
|
|
228
|
+
});
|
|
229
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/client.ts"],"sourcesContent":["/**\n * @zerocore1/sdk — Fiduciary Control Plane for AI Agents\n *\n * @example\n * ```ts\n * import { Client, ZerocorePaymentError } from \"@zerocore1/sdk\";\n *\n * const zc = new Client({ apiKey: \"zc_live_abc123...\" });\n *\n * try {\n * const result = await zc.authorizeSpend({\n * amountUsd: 0.03,\n * merchant: \"OpenAI\",\n * currency: \"USDC\",\n * });\n * console.log(`Approved! tx=${result.transactionId}`);\n * } catch (err) {\n * if (err instanceof ZerocorePaymentError) {\n * console.log(`Denied: ${err.reason}`);\n * }\n * }\n * ```\n *\n * @packageDocumentation\n */\n\n// Client\nexport { Client } from \"./client.js\";\n\n// Errors\nexport {\n ZerocoreError,\n ZerocoreAuthError,\n ZerocorePaymentError,\n ZerocoreRateLimitError,\n ZerocoreNetworkError,\n} from \"./errors.js\";\n\n// Types\nexport type {\n Currency,\n AuthorizeSpendParams,\n ApprovalResult,\n ClientOptions,\n DenialReason,\n} from \"./types.js\";\n","/**\n * ZERO.CORE SDK — Error Classes\n *\n * Typed exceptions for every failure mode the control plane can produce.\n */\n\nimport type { DenialReason } from \"./types.js\";\n\n// ---------------------------------------------------------------------------\n// Base\n// ---------------------------------------------------------------------------\n\n/** Base error for all ZERO.CORE SDK errors. */\nexport class ZerocoreError extends Error {\n /** HTTP status code from the API, if applicable. */\n readonly statusCode?: number;\n\n constructor(message: string, statusCode?: number) {\n super(message);\n this.name = \"ZerocoreError\";\n this.statusCode = statusCode;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Auth\n// ---------------------------------------------------------------------------\n\n/** Thrown when the API key is invalid or revoked (HTTP 401). */\nexport class ZerocoreAuthError extends ZerocoreError {\n constructor(message = \"Invalid API key\") {\n super(message, 401);\n this.name = \"ZerocoreAuthError\";\n }\n}\n\n// ---------------------------------------------------------------------------\n// Payment denied\n// ---------------------------------------------------------------------------\n\n/**\n * Thrown when the fiduciary control plane denies a transaction (HTTP 402/403).\n *\n * Inspect {@link reason} for the specific denial cause:\n * - `AGENT_INACTIVE` — Kill switch is off\n * - `EXCEEDS_PER_TX_LIMIT` — Single transaction too large\n * - `EXCEEDS_DAILY_LIMIT` — Daily budget exhausted\n * - `SETTLEMENT_FAILED: ...` — On-chain transfer failed\n */\nexport class ZerocorePaymentError extends ZerocoreError {\n /** Machine-readable denial reason from the control plane. */\n readonly reason: DenialReason;\n\n constructor(message: string, reason: DenialReason, statusCode = 403) {\n super(message, statusCode);\n this.name = \"ZerocorePaymentError\";\n this.reason = reason;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Rate limit\n// ---------------------------------------------------------------------------\n\n/** Thrown when the API rate limit is exceeded (HTTP 429). */\nexport class ZerocoreRateLimitError extends ZerocoreError {\n /** Seconds to wait before retrying, if provided by the API. */\n readonly retryAfter?: number;\n\n constructor(retryAfter?: number) {\n const msg = retryAfter\n ? `Rate limited. Retry after ${retryAfter}s.`\n : \"Rate limited.\";\n super(msg, 429);\n this.name = \"ZerocoreRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Network\n// ---------------------------------------------------------------------------\n\n/** Thrown when the Edge Function is unreachable. */\nexport class ZerocoreNetworkError extends ZerocoreError {\n constructor(message = \"Cannot connect to ZERO.CORE API.\") {\n super(message);\n this.name = \"ZerocoreNetworkError\";\n }\n}\n","/**\n * ZERO.CORE SDK — Client\n *\n * The fiduciary gatekeeper for AI agents. Every paid API call your agent\n * makes should pass through {@link Client.authorizeSpend} first. If the\n * control plane says no, the call never happens.\n *\n * @example\n * ```ts\n * import { Client } from \"@zerocore1/sdk\";\n *\n * const zc = new Client({ apiKey: \"zc_live_abc123...\" });\n *\n * const result = await zc.authorizeSpend({\n * amountUsd: 0.03,\n * merchant: \"OpenAI\",\n * currency: \"USDC\",\n * });\n *\n * if (result.approved) {\n * // safe to call OpenAI\n * }\n * ```\n */\n\nimport type {\n ApprovalResult,\n AuthorizeSpendParams,\n ClientOptions,\n RawApiResponse,\n} from \"./types.js\";\n\nimport {\n ZerocoreAuthError,\n ZerocoreError,\n ZerocoreNetworkError,\n ZerocorePaymentError,\n ZerocoreRateLimitError,\n} from \"./errors.js\";\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_BASE_URL =\n \"https://augvmbhpuchkqqowxmrk.supabase.co/functions/v1\";\n\nconst DEFAULT_TIMEOUT = 30_000;\n\nconst USER_AGENT = \"zerocore-sdk-ts/0.1.0\";\n\n// ---------------------------------------------------------------------------\n// Client\n// ---------------------------------------------------------------------------\n\nexport class Client {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n\n constructor(options: ClientOptions) {\n const { apiKey, baseUrl, timeout } = options;\n\n if (!apiKey || !apiKey.startsWith(\"zc_\")) {\n throw new ZerocoreAuthError(\n \"API key must start with 'zc_live_' or 'zc_test_'. \" +\n \"Generate one at your ZERO.CORE dashboard → API Keys.\",\n );\n }\n\n this.apiKey = apiKey;\n this.baseUrl = (baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = timeout ?? DEFAULT_TIMEOUT;\n }\n\n // ── Public API ──────────────────────────────────────────────────────────\n\n /**\n * Request authorization for an agent payment.\n *\n * Call this **before** your agent executes any paid API call.\n * The control plane checks:\n * - Is the agent active? (kill switch)\n * - Does this exceed the per-transaction limit?\n * - Does this exceed the daily spending limit?\n *\n * If approved and `executeOnChain` is `true`, the Edge Function executes\n * a real on-chain transfer (SOL or USDC SPL token).\n *\n * @throws {ZerocorePaymentError} Transaction was denied.\n * @throws {ZerocoreAuthError} API key is invalid.\n * @throws {ZerocoreRateLimitError} Too many requests.\n * @throws {ZerocoreNetworkError} API is unreachable.\n */\n async authorizeSpend(\n params: AuthorizeSpendParams,\n ): Promise<ApprovalResult> {\n const { amountUsd, merchant, currency = \"SOL\", memo, executeOnChain = false } = params;\n\n if (amountUsd <= 0) {\n throw new Error(\"amountUsd must be positive\");\n }\n if (!merchant) {\n throw new Error(\"merchant is required\");\n }\n if (currency !== \"SOL\" && currency !== \"USDC\") {\n throw new Error(\"currency must be 'SOL' or 'USDC'\");\n }\n\n const payload: Record<string, unknown> = {\n amount_usd: amountUsd,\n merchant,\n execute_on_chain: executeOnChain,\n currency,\n };\n\n if (memo) {\n payload.memo = memo;\n }\n\n const raw = await this.post<RawApiResponse>(\"/authorize\", payload);\n\n return toApprovalResult(raw);\n }\n\n // ── Internal ────────────────────────────────────────────────────────────\n\n private async post<T>(path: string, body: Record<string, unknown>): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": USER_AGENT,\n },\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(this.timeout),\n });\n } catch (err) {\n if (err instanceof DOMException && err.name === \"TimeoutError\") {\n throw new ZerocoreNetworkError(\"Request timed out.\");\n }\n throw new ZerocoreNetworkError(\n `Cannot connect to ${this.baseUrl}. Check your network or baseUrl setting.`,\n );\n }\n\n return this.handleResponse<T>(response);\n }\n\n private async handleResponse<T>(response: Response): Promise<T> {\n // 200 — success\n if (response.ok) {\n return (await response.json()) as T;\n }\n\n // 401 — auth error\n if (response.status === 401) {\n const data = await safeJson(response);\n const msg = data?.detail ?? \"Invalid API key\";\n throw new ZerocoreAuthError(typeof msg === \"string\" ? msg : \"Invalid API key\");\n }\n\n // 429 — rate limit\n if (response.status === 429) {\n const retryAfter = response.headers.get(\"Retry-After\");\n throw new ZerocoreRateLimitError(\n retryAfter ? parseFloat(retryAfter) : undefined,\n );\n }\n\n // 402 / 403 — payment denied\n if (response.status === 402 || response.status === 403) {\n const data = await safeJson(response);\n const detail = data?.detail ?? data;\n\n if (detail && typeof detail === \"object\") {\n throw new ZerocorePaymentError(\n detail.message ?? \"Payment denied\",\n detail.denial_reason ?? \"UNKNOWN\",\n response.status,\n );\n }\n\n throw new ZerocorePaymentError(\n typeof detail === \"string\" ? detail : \"Payment denied\",\n \"UNKNOWN\",\n response.status,\n );\n }\n\n // Anything else\n const data = await safeJson(response);\n const message = data?.detail ?? data?.message ?? `API error ${response.status}`;\n throw new ZerocoreError(\n typeof message === \"string\" ? message : `API error ${response.status}`,\n response.status,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Parse JSON from a response without throwing on invalid JSON. */\n// deno-lint-ignore no-explicit-any\nasync function safeJson(response: Response): Promise<any> {\n try {\n return await response.json();\n } catch {\n return null;\n }\n}\n\n/** Map a raw snake_case API response to a camelCase {@link ApprovalResult}. */\nfunction toApprovalResult(raw: RawApiResponse): ApprovalResult {\n return {\n approved: raw.approval_status === \"approved\",\n transactionId: raw.transaction_id,\n amountUsd: raw.amount_usd,\n amountSol: raw.amount_sol,\n amountUsdc: raw.amount_usdc,\n currency: raw.currency,\n merchant: raw.merchant,\n remainingDailyLimit: raw.remaining_daily_limit,\n solanaSignature: raw.solana_signature,\n denialReason: raw.denial_reason,\n message: raw.message,\n };\n}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U,IAAI,oBAAoB;AAAA,IAClC,eAAe,IAAI;AAAA,IACnB,WAAW,IAAI;AAAA,IACf,WAAW,IAAI;AAAA,IACf,YAAY,IAAI;AAAA,IAChB,UAAU,IAAI;AAAA,IACd,UAAU,IAAI;AAAA,IACd,qBAAqB,IAAI;AAAA,IACzB,iBAAiB,IAAI;AAAA,IACrB,cAAc,IAAI;AAAA,IAClB,SAAS,IAAI;AAAA,EACf;AACF;","names":["data"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZERO.CORE SDK — Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Python SDK types and the Edge Function API contract.
|
|
5
|
+
*/
|
|
6
|
+
/** Settlement currency for the transaction. */
|
|
7
|
+
type Currency = "SOL" | "USDC";
|
|
8
|
+
/** Parameters for {@link Client.authorizeSpend}. */
|
|
9
|
+
interface AuthorizeSpendParams {
|
|
10
|
+
/** Amount in USD to authorize. */
|
|
11
|
+
amountUsd: number;
|
|
12
|
+
/** Vendor/merchant name (e.g. "OpenAI", "X.com", "Helius"). */
|
|
13
|
+
merchant: string;
|
|
14
|
+
/** Settlement currency. Defaults to `"SOL"`. */
|
|
15
|
+
currency?: Currency;
|
|
16
|
+
/** Optional memo attached to the transaction for the audit trail. */
|
|
17
|
+
memo?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to execute a real on-chain transfer.
|
|
20
|
+
* When `false`, the Edge Function generates a mock signature (dev/test mode).
|
|
21
|
+
* Defaults to `false`.
|
|
22
|
+
*/
|
|
23
|
+
executeOnChain?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Why the fiduciary control plane denied a transaction. */
|
|
26
|
+
type DenialReason = "AGENT_INACTIVE" | "AGENT_PAUSED" | "AGENT_SUSPENDED" | "AGENT_REVOKED" | "EXCEEDS_PER_TX_LIMIT" | "EXCEEDS_DAILY_LIMIT" | "INSUFFICIENT_TREASURY" | "MERCHANT_NOT_AUTHORIZED" | `SETTLEMENT_FAILED: ${string}` | string;
|
|
27
|
+
/** Result of an {@link Client.authorizeSpend} call. */
|
|
28
|
+
interface ApprovalResult {
|
|
29
|
+
/** Whether the transaction was approved. */
|
|
30
|
+
approved: boolean;
|
|
31
|
+
/** Unique ID for the transaction record. */
|
|
32
|
+
transactionId: string;
|
|
33
|
+
/** The amount in USD that was authorized. */
|
|
34
|
+
amountUsd: number;
|
|
35
|
+
/** The equivalent amount in SOL (when currency is SOL). */
|
|
36
|
+
amountSol: number;
|
|
37
|
+
/** The equivalent amount in USDC (when currency is USDC). */
|
|
38
|
+
amountUsdc?: number;
|
|
39
|
+
/** Settlement currency — `"SOL"` or `"USDC"`. */
|
|
40
|
+
currency: Currency;
|
|
41
|
+
/** The merchant/vendor name. */
|
|
42
|
+
merchant: string;
|
|
43
|
+
/** How much daily budget remains after this transaction. */
|
|
44
|
+
remainingDailyLimit: number;
|
|
45
|
+
/** On-chain Solana transaction signature, if settled. */
|
|
46
|
+
solanaSignature: string | null;
|
|
47
|
+
/** Why the transaction was denied, if denied. */
|
|
48
|
+
denialReason: DenialReason | null;
|
|
49
|
+
/** Human-readable status message. */
|
|
50
|
+
message: string;
|
|
51
|
+
}
|
|
52
|
+
/** Options for initializing the {@link Client}. */
|
|
53
|
+
interface ClientOptions {
|
|
54
|
+
/** Your `zc_live_...` API key from the dashboard. */
|
|
55
|
+
apiKey: string;
|
|
56
|
+
/**
|
|
57
|
+
* Override the API base URL.
|
|
58
|
+
* Defaults to the ZERO.CORE Supabase Edge Function endpoint.
|
|
59
|
+
*/
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
/** Request timeout in milliseconds. Defaults to `30_000` (30s). */
|
|
62
|
+
timeout?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* ZERO.CORE SDK — Client
|
|
67
|
+
*
|
|
68
|
+
* The fiduciary gatekeeper for AI agents. Every paid API call your agent
|
|
69
|
+
* makes should pass through {@link Client.authorizeSpend} first. If the
|
|
70
|
+
* control plane says no, the call never happens.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { Client } from "@zerocore1/sdk";
|
|
75
|
+
*
|
|
76
|
+
* const zc = new Client({ apiKey: "zc_live_abc123..." });
|
|
77
|
+
*
|
|
78
|
+
* const result = await zc.authorizeSpend({
|
|
79
|
+
* amountUsd: 0.03,
|
|
80
|
+
* merchant: "OpenAI",
|
|
81
|
+
* currency: "USDC",
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* if (result.approved) {
|
|
85
|
+
* // safe to call OpenAI
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
declare class Client {
|
|
91
|
+
private readonly apiKey;
|
|
92
|
+
private readonly baseUrl;
|
|
93
|
+
private readonly timeout;
|
|
94
|
+
constructor(options: ClientOptions);
|
|
95
|
+
/**
|
|
96
|
+
* Request authorization for an agent payment.
|
|
97
|
+
*
|
|
98
|
+
* Call this **before** your agent executes any paid API call.
|
|
99
|
+
* The control plane checks:
|
|
100
|
+
* - Is the agent active? (kill switch)
|
|
101
|
+
* - Does this exceed the per-transaction limit?
|
|
102
|
+
* - Does this exceed the daily spending limit?
|
|
103
|
+
*
|
|
104
|
+
* If approved and `executeOnChain` is `true`, the Edge Function executes
|
|
105
|
+
* a real on-chain transfer (SOL or USDC SPL token).
|
|
106
|
+
*
|
|
107
|
+
* @throws {ZerocorePaymentError} Transaction was denied.
|
|
108
|
+
* @throws {ZerocoreAuthError} API key is invalid.
|
|
109
|
+
* @throws {ZerocoreRateLimitError} Too many requests.
|
|
110
|
+
* @throws {ZerocoreNetworkError} API is unreachable.
|
|
111
|
+
*/
|
|
112
|
+
authorizeSpend(params: AuthorizeSpendParams): Promise<ApprovalResult>;
|
|
113
|
+
private post;
|
|
114
|
+
private handleResponse;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* ZERO.CORE SDK — Error Classes
|
|
119
|
+
*
|
|
120
|
+
* Typed exceptions for every failure mode the control plane can produce.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/** Base error for all ZERO.CORE SDK errors. */
|
|
124
|
+
declare class ZerocoreError extends Error {
|
|
125
|
+
/** HTTP status code from the API, if applicable. */
|
|
126
|
+
readonly statusCode?: number;
|
|
127
|
+
constructor(message: string, statusCode?: number);
|
|
128
|
+
}
|
|
129
|
+
/** Thrown when the API key is invalid or revoked (HTTP 401). */
|
|
130
|
+
declare class ZerocoreAuthError extends ZerocoreError {
|
|
131
|
+
constructor(message?: string);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Thrown when the fiduciary control plane denies a transaction (HTTP 402/403).
|
|
135
|
+
*
|
|
136
|
+
* Inspect {@link reason} for the specific denial cause:
|
|
137
|
+
* - `AGENT_INACTIVE` — Kill switch is off
|
|
138
|
+
* - `EXCEEDS_PER_TX_LIMIT` — Single transaction too large
|
|
139
|
+
* - `EXCEEDS_DAILY_LIMIT` — Daily budget exhausted
|
|
140
|
+
* - `SETTLEMENT_FAILED: ...` — On-chain transfer failed
|
|
141
|
+
*/
|
|
142
|
+
declare class ZerocorePaymentError extends ZerocoreError {
|
|
143
|
+
/** Machine-readable denial reason from the control plane. */
|
|
144
|
+
readonly reason: DenialReason;
|
|
145
|
+
constructor(message: string, reason: DenialReason, statusCode?: number);
|
|
146
|
+
}
|
|
147
|
+
/** Thrown when the API rate limit is exceeded (HTTP 429). */
|
|
148
|
+
declare class ZerocoreRateLimitError extends ZerocoreError {
|
|
149
|
+
/** Seconds to wait before retrying, if provided by the API. */
|
|
150
|
+
readonly retryAfter?: number;
|
|
151
|
+
constructor(retryAfter?: number);
|
|
152
|
+
}
|
|
153
|
+
/** Thrown when the Edge Function is unreachable. */
|
|
154
|
+
declare class ZerocoreNetworkError extends ZerocoreError {
|
|
155
|
+
constructor(message?: string);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { type ApprovalResult, type AuthorizeSpendParams, Client, type ClientOptions, type Currency, type DenialReason, ZerocoreAuthError, ZerocoreError, ZerocoreNetworkError, ZerocorePaymentError, ZerocoreRateLimitError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZERO.CORE SDK — Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Python SDK types and the Edge Function API contract.
|
|
5
|
+
*/
|
|
6
|
+
/** Settlement currency for the transaction. */
|
|
7
|
+
type Currency = "SOL" | "USDC";
|
|
8
|
+
/** Parameters for {@link Client.authorizeSpend}. */
|
|
9
|
+
interface AuthorizeSpendParams {
|
|
10
|
+
/** Amount in USD to authorize. */
|
|
11
|
+
amountUsd: number;
|
|
12
|
+
/** Vendor/merchant name (e.g. "OpenAI", "X.com", "Helius"). */
|
|
13
|
+
merchant: string;
|
|
14
|
+
/** Settlement currency. Defaults to `"SOL"`. */
|
|
15
|
+
currency?: Currency;
|
|
16
|
+
/** Optional memo attached to the transaction for the audit trail. */
|
|
17
|
+
memo?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to execute a real on-chain transfer.
|
|
20
|
+
* When `false`, the Edge Function generates a mock signature (dev/test mode).
|
|
21
|
+
* Defaults to `false`.
|
|
22
|
+
*/
|
|
23
|
+
executeOnChain?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** Why the fiduciary control plane denied a transaction. */
|
|
26
|
+
type DenialReason = "AGENT_INACTIVE" | "AGENT_PAUSED" | "AGENT_SUSPENDED" | "AGENT_REVOKED" | "EXCEEDS_PER_TX_LIMIT" | "EXCEEDS_DAILY_LIMIT" | "INSUFFICIENT_TREASURY" | "MERCHANT_NOT_AUTHORIZED" | `SETTLEMENT_FAILED: ${string}` | string;
|
|
27
|
+
/** Result of an {@link Client.authorizeSpend} call. */
|
|
28
|
+
interface ApprovalResult {
|
|
29
|
+
/** Whether the transaction was approved. */
|
|
30
|
+
approved: boolean;
|
|
31
|
+
/** Unique ID for the transaction record. */
|
|
32
|
+
transactionId: string;
|
|
33
|
+
/** The amount in USD that was authorized. */
|
|
34
|
+
amountUsd: number;
|
|
35
|
+
/** The equivalent amount in SOL (when currency is SOL). */
|
|
36
|
+
amountSol: number;
|
|
37
|
+
/** The equivalent amount in USDC (when currency is USDC). */
|
|
38
|
+
amountUsdc?: number;
|
|
39
|
+
/** Settlement currency — `"SOL"` or `"USDC"`. */
|
|
40
|
+
currency: Currency;
|
|
41
|
+
/** The merchant/vendor name. */
|
|
42
|
+
merchant: string;
|
|
43
|
+
/** How much daily budget remains after this transaction. */
|
|
44
|
+
remainingDailyLimit: number;
|
|
45
|
+
/** On-chain Solana transaction signature, if settled. */
|
|
46
|
+
solanaSignature: string | null;
|
|
47
|
+
/** Why the transaction was denied, if denied. */
|
|
48
|
+
denialReason: DenialReason | null;
|
|
49
|
+
/** Human-readable status message. */
|
|
50
|
+
message: string;
|
|
51
|
+
}
|
|
52
|
+
/** Options for initializing the {@link Client}. */
|
|
53
|
+
interface ClientOptions {
|
|
54
|
+
/** Your `zc_live_...` API key from the dashboard. */
|
|
55
|
+
apiKey: string;
|
|
56
|
+
/**
|
|
57
|
+
* Override the API base URL.
|
|
58
|
+
* Defaults to the ZERO.CORE Supabase Edge Function endpoint.
|
|
59
|
+
*/
|
|
60
|
+
baseUrl?: string;
|
|
61
|
+
/** Request timeout in milliseconds. Defaults to `30_000` (30s). */
|
|
62
|
+
timeout?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* ZERO.CORE SDK — Client
|
|
67
|
+
*
|
|
68
|
+
* The fiduciary gatekeeper for AI agents. Every paid API call your agent
|
|
69
|
+
* makes should pass through {@link Client.authorizeSpend} first. If the
|
|
70
|
+
* control plane says no, the call never happens.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { Client } from "@zerocore1/sdk";
|
|
75
|
+
*
|
|
76
|
+
* const zc = new Client({ apiKey: "zc_live_abc123..." });
|
|
77
|
+
*
|
|
78
|
+
* const result = await zc.authorizeSpend({
|
|
79
|
+
* amountUsd: 0.03,
|
|
80
|
+
* merchant: "OpenAI",
|
|
81
|
+
* currency: "USDC",
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* if (result.approved) {
|
|
85
|
+
* // safe to call OpenAI
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
declare class Client {
|
|
91
|
+
private readonly apiKey;
|
|
92
|
+
private readonly baseUrl;
|
|
93
|
+
private readonly timeout;
|
|
94
|
+
constructor(options: ClientOptions);
|
|
95
|
+
/**
|
|
96
|
+
* Request authorization for an agent payment.
|
|
97
|
+
*
|
|
98
|
+
* Call this **before** your agent executes any paid API call.
|
|
99
|
+
* The control plane checks:
|
|
100
|
+
* - Is the agent active? (kill switch)
|
|
101
|
+
* - Does this exceed the per-transaction limit?
|
|
102
|
+
* - Does this exceed the daily spending limit?
|
|
103
|
+
*
|
|
104
|
+
* If approved and `executeOnChain` is `true`, the Edge Function executes
|
|
105
|
+
* a real on-chain transfer (SOL or USDC SPL token).
|
|
106
|
+
*
|
|
107
|
+
* @throws {ZerocorePaymentError} Transaction was denied.
|
|
108
|
+
* @throws {ZerocoreAuthError} API key is invalid.
|
|
109
|
+
* @throws {ZerocoreRateLimitError} Too many requests.
|
|
110
|
+
* @throws {ZerocoreNetworkError} API is unreachable.
|
|
111
|
+
*/
|
|
112
|
+
authorizeSpend(params: AuthorizeSpendParams): Promise<ApprovalResult>;
|
|
113
|
+
private post;
|
|
114
|
+
private handleResponse;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* ZERO.CORE SDK — Error Classes
|
|
119
|
+
*
|
|
120
|
+
* Typed exceptions for every failure mode the control plane can produce.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/** Base error for all ZERO.CORE SDK errors. */
|
|
124
|
+
declare class ZerocoreError extends Error {
|
|
125
|
+
/** HTTP status code from the API, if applicable. */
|
|
126
|
+
readonly statusCode?: number;
|
|
127
|
+
constructor(message: string, statusCode?: number);
|
|
128
|
+
}
|
|
129
|
+
/** Thrown when the API key is invalid or revoked (HTTP 401). */
|
|
130
|
+
declare class ZerocoreAuthError extends ZerocoreError {
|
|
131
|
+
constructor(message?: string);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Thrown when the fiduciary control plane denies a transaction (HTTP 402/403).
|
|
135
|
+
*
|
|
136
|
+
* Inspect {@link reason} for the specific denial cause:
|
|
137
|
+
* - `AGENT_INACTIVE` — Kill switch is off
|
|
138
|
+
* - `EXCEEDS_PER_TX_LIMIT` — Single transaction too large
|
|
139
|
+
* - `EXCEEDS_DAILY_LIMIT` — Daily budget exhausted
|
|
140
|
+
* - `SETTLEMENT_FAILED: ...` — On-chain transfer failed
|
|
141
|
+
*/
|
|
142
|
+
declare class ZerocorePaymentError extends ZerocoreError {
|
|
143
|
+
/** Machine-readable denial reason from the control plane. */
|
|
144
|
+
readonly reason: DenialReason;
|
|
145
|
+
constructor(message: string, reason: DenialReason, statusCode?: number);
|
|
146
|
+
}
|
|
147
|
+
/** Thrown when the API rate limit is exceeded (HTTP 429). */
|
|
148
|
+
declare class ZerocoreRateLimitError extends ZerocoreError {
|
|
149
|
+
/** Seconds to wait before retrying, if provided by the API. */
|
|
150
|
+
readonly retryAfter?: number;
|
|
151
|
+
constructor(retryAfter?: number);
|
|
152
|
+
}
|
|
153
|
+
/** Thrown when the Edge Function is unreachable. */
|
|
154
|
+
declare class ZerocoreNetworkError extends ZerocoreError {
|
|
155
|
+
constructor(message?: string);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { type ApprovalResult, type AuthorizeSpendParams, Client, type ClientOptions, type Currency, type DenialReason, ZerocoreAuthError, ZerocoreError, ZerocoreNetworkError, ZerocorePaymentError, ZerocoreRateLimitError };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var ZerocoreError = class extends Error {
|
|
3
|
+
/** HTTP status code from the API, if applicable. */
|
|
4
|
+
statusCode;
|
|
5
|
+
constructor(message, statusCode) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "ZerocoreError";
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
var ZerocoreAuthError = class extends ZerocoreError {
|
|
12
|
+
constructor(message = "Invalid API key") {
|
|
13
|
+
super(message, 401);
|
|
14
|
+
this.name = "ZerocoreAuthError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var ZerocorePaymentError = class extends ZerocoreError {
|
|
18
|
+
/** Machine-readable denial reason from the control plane. */
|
|
19
|
+
reason;
|
|
20
|
+
constructor(message, reason, statusCode = 403) {
|
|
21
|
+
super(message, statusCode);
|
|
22
|
+
this.name = "ZerocorePaymentError";
|
|
23
|
+
this.reason = reason;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var ZerocoreRateLimitError = class extends ZerocoreError {
|
|
27
|
+
/** Seconds to wait before retrying, if provided by the API. */
|
|
28
|
+
retryAfter;
|
|
29
|
+
constructor(retryAfter) {
|
|
30
|
+
const msg = retryAfter ? `Rate limited. Retry after ${retryAfter}s.` : "Rate limited.";
|
|
31
|
+
super(msg, 429);
|
|
32
|
+
this.name = "ZerocoreRateLimitError";
|
|
33
|
+
this.retryAfter = retryAfter;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var ZerocoreNetworkError = class extends ZerocoreError {
|
|
37
|
+
constructor(message = "Cannot connect to ZERO.CORE API.") {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = "ZerocoreNetworkError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/client.ts
|
|
44
|
+
var DEFAULT_BASE_URL = "https://augvmbhpuchkqqowxmrk.supabase.co/functions/v1";
|
|
45
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
46
|
+
var USER_AGENT = "zerocore-sdk-ts/0.1.0";
|
|
47
|
+
var Client = class {
|
|
48
|
+
apiKey;
|
|
49
|
+
baseUrl;
|
|
50
|
+
timeout;
|
|
51
|
+
constructor(options) {
|
|
52
|
+
const { apiKey, baseUrl, timeout } = options;
|
|
53
|
+
if (!apiKey || !apiKey.startsWith("zc_")) {
|
|
54
|
+
throw new ZerocoreAuthError(
|
|
55
|
+
"API key must start with 'zc_live_' or 'zc_test_'. Generate one at your ZERO.CORE dashboard \u2192 API Keys."
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
this.apiKey = apiKey;
|
|
59
|
+
this.baseUrl = (baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
60
|
+
this.timeout = timeout ?? DEFAULT_TIMEOUT;
|
|
61
|
+
}
|
|
62
|
+
// ── Public API ──────────────────────────────────────────────────────────
|
|
63
|
+
/**
|
|
64
|
+
* Request authorization for an agent payment.
|
|
65
|
+
*
|
|
66
|
+
* Call this **before** your agent executes any paid API call.
|
|
67
|
+
* The control plane checks:
|
|
68
|
+
* - Is the agent active? (kill switch)
|
|
69
|
+
* - Does this exceed the per-transaction limit?
|
|
70
|
+
* - Does this exceed the daily spending limit?
|
|
71
|
+
*
|
|
72
|
+
* If approved and `executeOnChain` is `true`, the Edge Function executes
|
|
73
|
+
* a real on-chain transfer (SOL or USDC SPL token).
|
|
74
|
+
*
|
|
75
|
+
* @throws {ZerocorePaymentError} Transaction was denied.
|
|
76
|
+
* @throws {ZerocoreAuthError} API key is invalid.
|
|
77
|
+
* @throws {ZerocoreRateLimitError} Too many requests.
|
|
78
|
+
* @throws {ZerocoreNetworkError} API is unreachable.
|
|
79
|
+
*/
|
|
80
|
+
async authorizeSpend(params) {
|
|
81
|
+
const { amountUsd, merchant, currency = "SOL", memo, executeOnChain = false } = params;
|
|
82
|
+
if (amountUsd <= 0) {
|
|
83
|
+
throw new Error("amountUsd must be positive");
|
|
84
|
+
}
|
|
85
|
+
if (!merchant) {
|
|
86
|
+
throw new Error("merchant is required");
|
|
87
|
+
}
|
|
88
|
+
if (currency !== "SOL" && currency !== "USDC") {
|
|
89
|
+
throw new Error("currency must be 'SOL' or 'USDC'");
|
|
90
|
+
}
|
|
91
|
+
const payload = {
|
|
92
|
+
amount_usd: amountUsd,
|
|
93
|
+
merchant,
|
|
94
|
+
execute_on_chain: executeOnChain,
|
|
95
|
+
currency
|
|
96
|
+
};
|
|
97
|
+
if (memo) {
|
|
98
|
+
payload.memo = memo;
|
|
99
|
+
}
|
|
100
|
+
const raw = await this.post("/authorize", payload);
|
|
101
|
+
return toApprovalResult(raw);
|
|
102
|
+
}
|
|
103
|
+
// ── Internal ────────────────────────────────────────────────────────────
|
|
104
|
+
async post(path, body) {
|
|
105
|
+
const url = `${this.baseUrl}${path}`;
|
|
106
|
+
let response;
|
|
107
|
+
try {
|
|
108
|
+
response = await fetch(url, {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: {
|
|
111
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
112
|
+
"Content-Type": "application/json",
|
|
113
|
+
"User-Agent": USER_AGENT
|
|
114
|
+
},
|
|
115
|
+
body: JSON.stringify(body),
|
|
116
|
+
signal: AbortSignal.timeout(this.timeout)
|
|
117
|
+
});
|
|
118
|
+
} catch (err) {
|
|
119
|
+
if (err instanceof DOMException && err.name === "TimeoutError") {
|
|
120
|
+
throw new ZerocoreNetworkError("Request timed out.");
|
|
121
|
+
}
|
|
122
|
+
throw new ZerocoreNetworkError(
|
|
123
|
+
`Cannot connect to ${this.baseUrl}. Check your network or baseUrl setting.`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return this.handleResponse(response);
|
|
127
|
+
}
|
|
128
|
+
async handleResponse(response) {
|
|
129
|
+
if (response.ok) {
|
|
130
|
+
return await response.json();
|
|
131
|
+
}
|
|
132
|
+
if (response.status === 401) {
|
|
133
|
+
const data2 = await safeJson(response);
|
|
134
|
+
const msg = data2?.detail ?? "Invalid API key";
|
|
135
|
+
throw new ZerocoreAuthError(typeof msg === "string" ? msg : "Invalid API key");
|
|
136
|
+
}
|
|
137
|
+
if (response.status === 429) {
|
|
138
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
139
|
+
throw new ZerocoreRateLimitError(
|
|
140
|
+
retryAfter ? parseFloat(retryAfter) : void 0
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (response.status === 402 || response.status === 403) {
|
|
144
|
+
const data2 = await safeJson(response);
|
|
145
|
+
const detail = data2?.detail ?? data2;
|
|
146
|
+
if (detail && typeof detail === "object") {
|
|
147
|
+
throw new ZerocorePaymentError(
|
|
148
|
+
detail.message ?? "Payment denied",
|
|
149
|
+
detail.denial_reason ?? "UNKNOWN",
|
|
150
|
+
response.status
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
throw new ZerocorePaymentError(
|
|
154
|
+
typeof detail === "string" ? detail : "Payment denied",
|
|
155
|
+
"UNKNOWN",
|
|
156
|
+
response.status
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const data = await safeJson(response);
|
|
160
|
+
const message = data?.detail ?? data?.message ?? `API error ${response.status}`;
|
|
161
|
+
throw new ZerocoreError(
|
|
162
|
+
typeof message === "string" ? message : `API error ${response.status}`,
|
|
163
|
+
response.status
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
async function safeJson(response) {
|
|
168
|
+
try {
|
|
169
|
+
return await response.json();
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function toApprovalResult(raw) {
|
|
175
|
+
return {
|
|
176
|
+
approved: raw.approval_status === "approved",
|
|
177
|
+
transactionId: raw.transaction_id,
|
|
178
|
+
amountUsd: raw.amount_usd,
|
|
179
|
+
amountSol: raw.amount_sol,
|
|
180
|
+
amountUsdc: raw.amount_usdc,
|
|
181
|
+
currency: raw.currency,
|
|
182
|
+
merchant: raw.merchant,
|
|
183
|
+
remainingDailyLimit: raw.remaining_daily_limit,
|
|
184
|
+
solanaSignature: raw.solana_signature,
|
|
185
|
+
denialReason: raw.denial_reason,
|
|
186
|
+
message: raw.message
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
export {
|
|
190
|
+
Client,
|
|
191
|
+
ZerocoreAuthError,
|
|
192
|
+
ZerocoreError,
|
|
193
|
+
ZerocoreNetworkError,
|
|
194
|
+
ZerocorePaymentError,
|
|
195
|
+
ZerocoreRateLimitError
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/client.ts"],"sourcesContent":["/**\n * ZERO.CORE SDK — Error Classes\n *\n * Typed exceptions for every failure mode the control plane can produce.\n */\n\nimport type { DenialReason } from \"./types.js\";\n\n// ---------------------------------------------------------------------------\n// Base\n// ---------------------------------------------------------------------------\n\n/** Base error for all ZERO.CORE SDK errors. */\nexport class ZerocoreError extends Error {\n /** HTTP status code from the API, if applicable. */\n readonly statusCode?: number;\n\n constructor(message: string, statusCode?: number) {\n super(message);\n this.name = \"ZerocoreError\";\n this.statusCode = statusCode;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Auth\n// ---------------------------------------------------------------------------\n\n/** Thrown when the API key is invalid or revoked (HTTP 401). */\nexport class ZerocoreAuthError extends ZerocoreError {\n constructor(message = \"Invalid API key\") {\n super(message, 401);\n this.name = \"ZerocoreAuthError\";\n }\n}\n\n// ---------------------------------------------------------------------------\n// Payment denied\n// ---------------------------------------------------------------------------\n\n/**\n * Thrown when the fiduciary control plane denies a transaction (HTTP 402/403).\n *\n * Inspect {@link reason} for the specific denial cause:\n * - `AGENT_INACTIVE` — Kill switch is off\n * - `EXCEEDS_PER_TX_LIMIT` — Single transaction too large\n * - `EXCEEDS_DAILY_LIMIT` — Daily budget exhausted\n * - `SETTLEMENT_FAILED: ...` — On-chain transfer failed\n */\nexport class ZerocorePaymentError extends ZerocoreError {\n /** Machine-readable denial reason from the control plane. */\n readonly reason: DenialReason;\n\n constructor(message: string, reason: DenialReason, statusCode = 403) {\n super(message, statusCode);\n this.name = \"ZerocorePaymentError\";\n this.reason = reason;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Rate limit\n// ---------------------------------------------------------------------------\n\n/** Thrown when the API rate limit is exceeded (HTTP 429). */\nexport class ZerocoreRateLimitError extends ZerocoreError {\n /** Seconds to wait before retrying, if provided by the API. */\n readonly retryAfter?: number;\n\n constructor(retryAfter?: number) {\n const msg = retryAfter\n ? `Rate limited. Retry after ${retryAfter}s.`\n : \"Rate limited.\";\n super(msg, 429);\n this.name = \"ZerocoreRateLimitError\";\n this.retryAfter = retryAfter;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Network\n// ---------------------------------------------------------------------------\n\n/** Thrown when the Edge Function is unreachable. */\nexport class ZerocoreNetworkError extends ZerocoreError {\n constructor(message = \"Cannot connect to ZERO.CORE API.\") {\n super(message);\n this.name = \"ZerocoreNetworkError\";\n }\n}\n","/**\n * ZERO.CORE SDK — Client\n *\n * The fiduciary gatekeeper for AI agents. Every paid API call your agent\n * makes should pass through {@link Client.authorizeSpend} first. If the\n * control plane says no, the call never happens.\n *\n * @example\n * ```ts\n * import { Client } from \"@zerocore1/sdk\";\n *\n * const zc = new Client({ apiKey: \"zc_live_abc123...\" });\n *\n * const result = await zc.authorizeSpend({\n * amountUsd: 0.03,\n * merchant: \"OpenAI\",\n * currency: \"USDC\",\n * });\n *\n * if (result.approved) {\n * // safe to call OpenAI\n * }\n * ```\n */\n\nimport type {\n ApprovalResult,\n AuthorizeSpendParams,\n ClientOptions,\n RawApiResponse,\n} from \"./types.js\";\n\nimport {\n ZerocoreAuthError,\n ZerocoreError,\n ZerocoreNetworkError,\n ZerocorePaymentError,\n ZerocoreRateLimitError,\n} from \"./errors.js\";\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_BASE_URL =\n \"https://augvmbhpuchkqqowxmrk.supabase.co/functions/v1\";\n\nconst DEFAULT_TIMEOUT = 30_000;\n\nconst USER_AGENT = \"zerocore-sdk-ts/0.1.0\";\n\n// ---------------------------------------------------------------------------\n// Client\n// ---------------------------------------------------------------------------\n\nexport class Client {\n private readonly apiKey: string;\n private readonly baseUrl: string;\n private readonly timeout: number;\n\n constructor(options: ClientOptions) {\n const { apiKey, baseUrl, timeout } = options;\n\n if (!apiKey || !apiKey.startsWith(\"zc_\")) {\n throw new ZerocoreAuthError(\n \"API key must start with 'zc_live_' or 'zc_test_'. \" +\n \"Generate one at your ZERO.CORE dashboard → API Keys.\",\n );\n }\n\n this.apiKey = apiKey;\n this.baseUrl = (baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = timeout ?? DEFAULT_TIMEOUT;\n }\n\n // ── Public API ──────────────────────────────────────────────────────────\n\n /**\n * Request authorization for an agent payment.\n *\n * Call this **before** your agent executes any paid API call.\n * The control plane checks:\n * - Is the agent active? (kill switch)\n * - Does this exceed the per-transaction limit?\n * - Does this exceed the daily spending limit?\n *\n * If approved and `executeOnChain` is `true`, the Edge Function executes\n * a real on-chain transfer (SOL or USDC SPL token).\n *\n * @throws {ZerocorePaymentError} Transaction was denied.\n * @throws {ZerocoreAuthError} API key is invalid.\n * @throws {ZerocoreRateLimitError} Too many requests.\n * @throws {ZerocoreNetworkError} API is unreachable.\n */\n async authorizeSpend(\n params: AuthorizeSpendParams,\n ): Promise<ApprovalResult> {\n const { amountUsd, merchant, currency = \"SOL\", memo, executeOnChain = false } = params;\n\n if (amountUsd <= 0) {\n throw new Error(\"amountUsd must be positive\");\n }\n if (!merchant) {\n throw new Error(\"merchant is required\");\n }\n if (currency !== \"SOL\" && currency !== \"USDC\") {\n throw new Error(\"currency must be 'SOL' or 'USDC'\");\n }\n\n const payload: Record<string, unknown> = {\n amount_usd: amountUsd,\n merchant,\n execute_on_chain: executeOnChain,\n currency,\n };\n\n if (memo) {\n payload.memo = memo;\n }\n\n const raw = await this.post<RawApiResponse>(\"/authorize\", payload);\n\n return toApprovalResult(raw);\n }\n\n // ── Internal ────────────────────────────────────────────────────────────\n\n private async post<T>(path: string, body: Record<string, unknown>): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n\n let response: Response;\n try {\n response = await fetch(url, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": USER_AGENT,\n },\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(this.timeout),\n });\n } catch (err) {\n if (err instanceof DOMException && err.name === \"TimeoutError\") {\n throw new ZerocoreNetworkError(\"Request timed out.\");\n }\n throw new ZerocoreNetworkError(\n `Cannot connect to ${this.baseUrl}. Check your network or baseUrl setting.`,\n );\n }\n\n return this.handleResponse<T>(response);\n }\n\n private async handleResponse<T>(response: Response): Promise<T> {\n // 200 — success\n if (response.ok) {\n return (await response.json()) as T;\n }\n\n // 401 — auth error\n if (response.status === 401) {\n const data = await safeJson(response);\n const msg = data?.detail ?? \"Invalid API key\";\n throw new ZerocoreAuthError(typeof msg === \"string\" ? msg : \"Invalid API key\");\n }\n\n // 429 — rate limit\n if (response.status === 429) {\n const retryAfter = response.headers.get(\"Retry-After\");\n throw new ZerocoreRateLimitError(\n retryAfter ? parseFloat(retryAfter) : undefined,\n );\n }\n\n // 402 / 403 — payment denied\n if (response.status === 402 || response.status === 403) {\n const data = await safeJson(response);\n const detail = data?.detail ?? data;\n\n if (detail && typeof detail === \"object\") {\n throw new ZerocorePaymentError(\n detail.message ?? \"Payment denied\",\n detail.denial_reason ?? \"UNKNOWN\",\n response.status,\n );\n }\n\n throw new ZerocorePaymentError(\n typeof detail === \"string\" ? detail : \"Payment denied\",\n \"UNKNOWN\",\n response.status,\n );\n }\n\n // Anything else\n const data = await safeJson(response);\n const message = data?.detail ?? data?.message ?? `API error ${response.status}`;\n throw new ZerocoreError(\n typeof message === \"string\" ? message : `API error ${response.status}`,\n response.status,\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\n/** Parse JSON from a response without throwing on invalid JSON. */\n// deno-lint-ignore no-explicit-any\nasync function safeJson(response: Response): Promise<any> {\n try {\n return await response.json();\n } catch {\n return null;\n }\n}\n\n/** Map a raw snake_case API response to a camelCase {@link ApprovalResult}. */\nfunction toApprovalResult(raw: RawApiResponse): ApprovalResult {\n return {\n approved: raw.approval_status === \"approved\",\n transactionId: raw.transaction_id,\n amountUsd: raw.amount_usd,\n amountSol: raw.amount_sol,\n amountUsdc: raw.amount_usdc,\n currency: raw.currency,\n merchant: raw.merchant,\n remainingDailyLimit: raw.remaining_daily_limit,\n solanaSignature: raw.solana_signature,\n denialReason: raw.denial_reason,\n message: raw.message,\n };\n}\n"],"mappings":";AAaO,IAAM,gBAAN,cAA4B,MAAM;AAAA;AAAA,EAE9B;AAAA,EAET,YAAY,SAAiB,YAAqB;AAChD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAOO,IAAM,oBAAN,cAAgC,cAAc;AAAA,EACnD,YAAY,UAAU,mBAAmB;AACvC,UAAM,SAAS,GAAG;AAClB,SAAK,OAAO;AAAA,EACd;AACF;AAeO,IAAM,uBAAN,cAAmC,cAAc;AAAA;AAAA,EAE7C;AAAA,EAET,YAAY,SAAiB,QAAsB,aAAa,KAAK;AACnE,UAAM,SAAS,UAAU;AACzB,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAOO,IAAM,yBAAN,cAAqC,cAAc;AAAA;AAAA,EAE/C;AAAA,EAET,YAAY,YAAqB;AAC/B,UAAM,MAAM,aACR,6BAA6B,UAAU,OACvC;AACJ,UAAM,KAAK,GAAG;AACd,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;A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ACF;AAEA,YAAM,IAAI;AAAA,QACR,OAAO,WAAW,WAAW,SAAS;AAAA,QACtC;AAAA,QACA,SAAS;AAAA,MACX;AAAA,IACF;AAGA,UAAM,OAAO,MAAM,SAAS,QAAQ;AACpC,UAAM,UAAU,MAAM,UAAU,MAAM,WAAW,aAAa,SAAS,MAAM;AAC7E,UAAM,IAAI;AAAA,MACR,OAAO,YAAY,WAAW,UAAU,aAAa,SAAS,MAAM;AAAA,MACpE,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAQA,eAAe,SAAS,UAAkC;AACxD,MAAI;AACF,WAAO,MAAM,SAAS,KAAK;AAAA,EAC7B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,SAAS,iBAAiB,KAAqC;AAC7D,SAAO;AAAA,IACL,UAAU,IAAI,oBAAoB;AAAA,IAClC,eAAe,IAAI;AAAA,IACnB,WAAW,IAAI;AAAA,IACf,WAAW,IAAI;AAAA,IACf,YAAY,IAAI;AAAA,IAChB,UAAU,IAAI;AAAA,IACd,UAAU,IAAI;AAAA,IACd,qBAAqB,IAAI;AAAA,IACzB,iBAAiB,IAAI;AAAA,IACrB,cAAc,IAAI;AAAA,IAClB,SAAS,IAAI;AAAA,EACf;AACF;","names":["data"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zerocore1/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript SDK for ZERO.CORE — the Fiduciary Control Plane for AI Agents",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "ZERO.CORE <dev@zerocore.io>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/josephthompson101/zerocore",
|
|
10
|
+
"directory": "sdk-ts"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ai",
|
|
14
|
+
"agents",
|
|
15
|
+
"payments",
|
|
16
|
+
"fiduciary",
|
|
17
|
+
"solana",
|
|
18
|
+
"fintech",
|
|
19
|
+
"usdc",
|
|
20
|
+
"settlement"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
34
|
+
"default": "./dist/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"dev": "tsup --watch",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"clean": "rm -rf dist"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"tsup": "^8.0.0",
|
|
50
|
+
"typescript": "^5.4.0"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=18.0.0"
|
|
54
|
+
}
|
|
55
|
+
}
|