@zeroxyz/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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +281 -0
- package/dist/chunk-7STN754W.cjs +3048 -0
- package/dist/chunk-7STN754W.cjs.map +1 -0
- package/dist/chunk-XQEHJX2X.js +3017 -0
- package/dist/chunk-XQEHJX2X.js.map +1 -0
- package/dist/client-B50UYxPr.d.cts +836 -0
- package/dist/client-B50UYxPr.d.ts +836 -0
- package/dist/index.cjs +150 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +148 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/testing.cjs +51 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.cts +14 -0
- package/dist/testing.d.ts +14 -0
- package/dist/testing.js +47 -0
- package/dist/testing.js.map +1 -0
- package/package.json +95 -0
- package/testing/package.json +5 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk7STN754W_cjs = require('./chunk-7STN754W.cjs');
|
|
4
|
+
|
|
5
|
+
// src/status.ts
|
|
6
|
+
var AVAILABILITY_BADGES = {
|
|
7
|
+
healthy: { symbol: "\u2713", color: "green", label: "Healthy" },
|
|
8
|
+
unknown: { symbol: "?", color: "yellow", label: "Unknown" },
|
|
9
|
+
down: { symbol: "\u2717", color: "red", label: "Down" }
|
|
10
|
+
};
|
|
11
|
+
var STATUS_RANK = {
|
|
12
|
+
healthy: 0,
|
|
13
|
+
unknown: 1,
|
|
14
|
+
down: 2
|
|
15
|
+
};
|
|
16
|
+
var rankOf = (status) => (
|
|
17
|
+
// Missing/null status is treated as `unknown` — "we don't know" ranks
|
|
18
|
+
// above a confirmed `down` but below a proven `healthy`.
|
|
19
|
+
status == null ? STATUS_RANK.unknown : STATUS_RANK[status]
|
|
20
|
+
);
|
|
21
|
+
var sortByHealth = (items) => [...items].sort(
|
|
22
|
+
(a, b) => rankOf(a.availabilityStatus) - rankOf(b.availabilityStatus)
|
|
23
|
+
);
|
|
24
|
+
var preferHealthy = sortByHealth;
|
|
25
|
+
|
|
26
|
+
Object.defineProperty(exports, "Auth", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return chunk7STN754W_cjs.Auth; }
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "AuthDevice", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return chunk7STN754W_cjs.AuthDevice; }
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "BUG_REPORT_CATEGORIES", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () { return chunk7STN754W_cjs.BUG_REPORT_CATEGORIES; }
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(exports, "BugReports", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () { return chunk7STN754W_cjs.BugReports; }
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "Capabilities", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () { return chunk7STN754W_cjs.Capabilities; }
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () { return chunk7STN754W_cjs.DEFAULT_BASE_URL; }
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(exports, "DEFAULT_MAX_RETRIES", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function () { return chunk7STN754W_cjs.DEFAULT_MAX_RETRIES; }
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "DEFAULT_TIMEOUT_MS", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () { return chunk7STN754W_cjs.DEFAULT_TIMEOUT_MS; }
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(exports, "FETCH_SKIP_REASONS", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () { return chunk7STN754W_cjs.FETCH_SKIP_REASONS; }
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(exports, "FETCH_WARNINGS", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function () { return chunk7STN754W_cjs.FETCH_WARNINGS; }
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "Payments", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () { return chunk7STN754W_cjs.Payments; }
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(exports, "Runs", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () { return chunk7STN754W_cjs.Runs; }
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(exports, "SDK_VERSION", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function () { return chunk7STN754W_cjs.SDK_VERSION; }
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(exports, "TEMPO_CHAIN_ID", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () { return chunk7STN754W_cjs.TEMPO_CHAIN_ID; }
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(exports, "TEMPO_TESTNET_CHAIN_ID", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () { return chunk7STN754W_cjs.TEMPO_TESTNET_CHAIN_ID; }
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, "Wallet", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function () { return chunk7STN754W_cjs.Wallet; }
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(exports, "ZeroApiError", {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () { return chunk7STN754W_cjs.ZeroApiError; }
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(exports, "ZeroAuthError", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function () { return chunk7STN754W_cjs.ZeroAuthError; }
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, "ZeroClient", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () { return chunk7STN754W_cjs.ZeroClient; }
|
|
101
|
+
});
|
|
102
|
+
Object.defineProperty(exports, "ZeroConfigurationError", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function () { return chunk7STN754W_cjs.ZeroConfigurationError; }
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(exports, "ZeroError", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function () { return chunk7STN754W_cjs.ZeroError; }
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, "ZeroPaymentError", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function () { return chunk7STN754W_cjs.ZeroPaymentError; }
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(exports, "ZeroSessionCloseFailedError", {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function () { return chunk7STN754W_cjs.ZeroSessionCloseFailedError; }
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(exports, "ZeroTimeoutError", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function () { return chunk7STN754W_cjs.ZeroTimeoutError; }
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, "ZeroValidationError", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function () { return chunk7STN754W_cjs.ZeroValidationError; }
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(exports, "ZeroWalletError", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
get: function () { return chunk7STN754W_cjs.ZeroWalletError; }
|
|
129
|
+
});
|
|
130
|
+
Object.defineProperty(exports, "coerceTempoChainId", {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function () { return chunk7STN754W_cjs.coerceTempoChainId; }
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(exports, "createManagedAccount", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function () { return chunk7STN754W_cjs.createManagedAccount; }
|
|
137
|
+
});
|
|
138
|
+
Object.defineProperty(exports, "paymentHasAnchor", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function () { return chunk7STN754W_cjs.paymentHasAnchor; }
|
|
141
|
+
});
|
|
142
|
+
Object.defineProperty(exports, "tempoChainLabelFromId", {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () { return chunk7STN754W_cjs.tempoChainLabelFromId; }
|
|
145
|
+
});
|
|
146
|
+
exports.AVAILABILITY_BADGES = AVAILABILITY_BADGES;
|
|
147
|
+
exports.preferHealthy = preferHealthy;
|
|
148
|
+
exports.sortByHealth = sortByHealth;
|
|
149
|
+
//# sourceMappingURL=index.cjs.map
|
|
150
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/status.ts"],"names":[],"mappings":";;;;;AAoCO,IAAM,mBAAA,GAAsB;AAAA,EAClC,SAAS,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,OAAA,EAAS,OAAO,SAAA,EAAU;AAAA,EACzD,SAAS,EAAE,MAAA,EAAQ,KAAK,KAAA,EAAO,QAAA,EAAU,OAAO,SAAA,EAAU;AAAA,EAC1D,MAAM,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,KAAA,EAAO,OAAO,MAAA;AAC3C;AAGA,IAAM,WAAA,GAAkD;AAAA,EACvD,OAAA,EAAS,CAAA;AAAA,EACT,OAAA,EAAS,CAAA;AAAA,EACT,IAAA,EAAM;AACP,CAAA;AAEA,IAAM,SAAS,CAAC,MAAA;AAAA;AAAA;AAAA,EAGf,MAAA,IAAU,IAAA,GAAO,WAAA,CAAY,OAAA,GAAU,YAAY,MAAM;AAAA,CAAA;AAUnD,IAAM,eAAe,CAG3B,KAAA,KAEA,CAAC,GAAG,KAAK,CAAA,CAAE,IAAA;AAAA,EACV,CAAC,GAAG,CAAA,KAAM,MAAA,CAAO,EAAE,kBAAkB,CAAA,GAAI,MAAA,CAAO,CAAA,CAAE,kBAAkB;AACrE;AAMM,IAAM,aAAA,GAAgB","file":"index.cjs","sourcesContent":["/**\n * Capability availability status — the single, consolidated health signal\n * Zero surfaces to clients (ZERO-89 / ZERO-92).\n *\n * - `healthy` — proven live and executable; safe to call.\n * - `unknown` — insufficient evidence either way; usable as a fallback.\n * - `down` — confirmed dead / failing; avoid.\n *\n * Preference rule for agents: PREFER `healthy`. Fall back to `unknown` only\n * when nothing `healthy` fits the task. Avoid `down`. This is the same rule the\n * server-side visibility filter enforces, surfaced here so agents and UIs can\n * rank consistently.\n */\nexport type AvailabilityStatus = \"healthy\" | \"unknown\" | \"down\";\n\n/** A renderable badge for an {@link AvailabilityStatus}. */\nexport type AvailabilityBadge = {\n\t/** A short glyph suitable for terminals/UI (✓ / ? / ✗). */\n\tsymbol: string;\n\t/**\n\t * A color *name* (not ANSI/hex) — this SDK is environment-agnostic, so\n\t * consumers map the name to whatever their renderer needs.\n\t */\n\tcolor: \"green\" | \"yellow\" | \"red\";\n\t/** Human-readable label. */\n\tlabel: string;\n};\n\n/**\n * Badge metadata for each {@link AvailabilityStatus}. Exhaustively keyed via\n * `satisfies` so adding/removing a status value is a compile error here.\n *\n * - healthy → green check\n * - unknown → yellow question\n * - down → red cross\n */\nexport const AVAILABILITY_BADGES = {\n\thealthy: { symbol: \"✓\", color: \"green\", label: \"Healthy\" },\n\tunknown: { symbol: \"?\", color: \"yellow\", label: \"Unknown\" },\n\tdown: { symbol: \"✗\", color: \"red\", label: \"Down\" },\n} as const satisfies Record<AvailabilityStatus, AvailabilityBadge>;\n\n// Lower rank sorts first: healthy ahead of unknown ahead of down.\nconst STATUS_RANK: Record<AvailabilityStatus, number> = {\n\thealthy: 0,\n\tunknown: 1,\n\tdown: 2,\n};\n\nconst rankOf = (status: AvailabilityStatus | null | undefined): number =>\n\t// Missing/null status is treated as `unknown` — \"we don't know\" ranks\n\t// above a confirmed `down` but below a proven `healthy`.\n\tstatus == null ? STATUS_RANK.unknown : STATUS_RANK[status];\n\n/**\n * Stable-sort capabilities by health: `healthy` > `unknown` > `down`.\n *\n * Agents should PREFER `healthy` and fall back to `unknown` only when nothing\n * `healthy` fits; `down` is last. A missing/null status is ranked as\n * `unknown`. Returns a NEW array — the input is not mutated. Items of equal\n * rank keep their original relative order (stable).\n */\nexport const sortByHealth = <\n\tT extends { availabilityStatus?: AvailabilityStatus | null },\n>(\n\titems: readonly T[],\n): T[] =>\n\t[...items].sort(\n\t\t(a, b) => rankOf(a.availabilityStatus) - rankOf(b.availabilityStatus),\n\t);\n\n/**\n * Alias for {@link sortByHealth}. The preference rule is \"prefer healthy, fall\n * back to unknown\" — applying it to a list means sorting healthy-first.\n */\nexport const preferHealthy = sortByHealth;\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Z as ZeroClient, P as PaymentSessionMeta } from './client-B50UYxPr.cjs';
|
|
2
|
+
export { A as AccountCredentials, g as Auth, h as AuthDevice, _ as BUG_REPORT_CATEGORIES, w as BalanceOptions, x as BalanceReadError, a7 as BatchReviewResponse, $ as BugReportCategory, B as BugReports, i as Capabilities, a2 as CapabilityResponse, E as ClientOptions, a0 as CreateBugReportInput, a1 as CreateBugReportResponse, a8 as CreateReviewInput, a9 as CreateReviewResponse, aa as CreateRunInput, ab as CreateRunResponse, C as Credentials, G as DEFAULT_BASE_URL, H as DEFAULT_MAX_RETRIES, I as DEFAULT_TIMEOUT_MS, a4 as DevicePollResult, a5 as DeviceStartResponse, q as FETCH_SKIP_REASONS, r as FETCH_WARNINGS, F as FetchOptions, b as FetchOutcome, c as FetchResult, y as FundingUrlOptions, a3 as GetCapabilityOptions, Q as InternalUserDto, ac as ListRunsParams, ad as ListRunsResponse, L as LogEvent, K as LogLevel, J as Logger, M as MigrateAuthorization, z as MigrateAuthorizationResponse, N as NoCredentials, O as OnSessionRefreshed, j as PayInput, n as PayResult, k as PaymentChain, l as PaymentProtocol, m as PaymentResult, s as Payments, V as PublicUserDto, ae as RunListItem, R as Runs, af as SearchOptions, ag as SearchResponse, ah as SearchResult, S as SessionCredentials, a as SessionCredentialsInput, a6 as SessionExchangeResponse, o as SessionReceiptPayload, d as SignMessageInput, e as SignTransactionInput, f as SignTypedDataInput, T as TEMPO_CHAIN_ID, u as TEMPO_TESTNET_CHAIN_ID, U as UpstreamError, X as UserWalletDto, D as Wallet, W as WalletBalance, Y as WelcomeBonusSummary, p as coerceTempoChainId, t as paymentHasAnchor, v as tempoChainLabelFromId } from './client-B50UYxPr.cjs';
|
|
3
|
+
import { Address, LocalAccount } from 'viem';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
declare const createManagedAccount: (client: ZeroClient, address: Address) => LocalAccount;
|
|
7
|
+
|
|
8
|
+
type ZeroErrorCode = "api_error" | "auth_error" | "auth_session_expired" | "auth_no_credentials" | "payment_error" | "payment_session_close_failed" | "wallet_error" | "validation_error" | "timeout_error" | "configuration_error";
|
|
9
|
+
type ZeroErrorOptions = {
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
};
|
|
12
|
+
declare class ZeroError extends Error {
|
|
13
|
+
readonly code: ZeroErrorCode;
|
|
14
|
+
constructor(code: ZeroErrorCode, message: string, options?: ZeroErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
type ApiErrorInit = {
|
|
17
|
+
status: number;
|
|
18
|
+
requestId?: string | undefined;
|
|
19
|
+
body?: unknown;
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
};
|
|
22
|
+
declare class ZeroApiError extends ZeroError {
|
|
23
|
+
readonly status: number;
|
|
24
|
+
readonly requestId: string | undefined;
|
|
25
|
+
readonly body: unknown;
|
|
26
|
+
constructor(message: string, init: ApiErrorInit);
|
|
27
|
+
}
|
|
28
|
+
type AuthErrorCode = Extract<ZeroErrorCode, "auth_error" | "auth_session_expired" | "auth_no_credentials">;
|
|
29
|
+
declare class ZeroAuthError extends ZeroError {
|
|
30
|
+
constructor(code: AuthErrorCode, message: string, options?: ZeroErrorOptions);
|
|
31
|
+
}
|
|
32
|
+
declare class ZeroPaymentError extends ZeroError {
|
|
33
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
34
|
+
}
|
|
35
|
+
type SessionCloseFailedInit = {
|
|
36
|
+
session: PaymentSessionMeta;
|
|
37
|
+
response: Response;
|
|
38
|
+
capturedAmount: string;
|
|
39
|
+
cause?: unknown;
|
|
40
|
+
};
|
|
41
|
+
declare class ZeroSessionCloseFailedError extends ZeroError {
|
|
42
|
+
readonly session: PaymentSessionMeta;
|
|
43
|
+
readonly response: Response;
|
|
44
|
+
readonly capturedAmount: string;
|
|
45
|
+
constructor(message: string, init: SessionCloseFailedInit);
|
|
46
|
+
}
|
|
47
|
+
declare class ZeroWalletError extends ZeroError {
|
|
48
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
49
|
+
}
|
|
50
|
+
type ValidationErrorOptions = ZeroErrorOptions & {
|
|
51
|
+
body?: string;
|
|
52
|
+
};
|
|
53
|
+
declare class ZeroValidationError extends ZeroError {
|
|
54
|
+
readonly body: string | undefined;
|
|
55
|
+
constructor(message: string, options?: ValidationErrorOptions);
|
|
56
|
+
}
|
|
57
|
+
declare class ZeroTimeoutError extends ZeroError {
|
|
58
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
59
|
+
}
|
|
60
|
+
declare class ZeroConfigurationError extends ZeroError {
|
|
61
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare const ratingSchema: z.ZodObject<{
|
|
65
|
+
score: z.ZodString;
|
|
66
|
+
successRate: z.ZodString;
|
|
67
|
+
reviews: z.ZodNumber;
|
|
68
|
+
stars: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
unrated: "unrated";
|
|
71
|
+
rated: "rated";
|
|
72
|
+
}>>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
type Rating = z.infer<typeof ratingSchema>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Capability availability status — the single, consolidated health signal
|
|
78
|
+
* Zero surfaces to clients (ZERO-89 / ZERO-92).
|
|
79
|
+
*
|
|
80
|
+
* - `healthy` — proven live and executable; safe to call.
|
|
81
|
+
* - `unknown` — insufficient evidence either way; usable as a fallback.
|
|
82
|
+
* - `down` — confirmed dead / failing; avoid.
|
|
83
|
+
*
|
|
84
|
+
* Preference rule for agents: PREFER `healthy`. Fall back to `unknown` only
|
|
85
|
+
* when nothing `healthy` fits the task. Avoid `down`. This is the same rule the
|
|
86
|
+
* server-side visibility filter enforces, surfaced here so agents and UIs can
|
|
87
|
+
* rank consistently.
|
|
88
|
+
*/
|
|
89
|
+
type AvailabilityStatus = "healthy" | "unknown" | "down";
|
|
90
|
+
/** A renderable badge for an {@link AvailabilityStatus}. */
|
|
91
|
+
type AvailabilityBadge = {
|
|
92
|
+
/** A short glyph suitable for terminals/UI (✓ / ? / ✗). */
|
|
93
|
+
symbol: string;
|
|
94
|
+
/**
|
|
95
|
+
* A color *name* (not ANSI/hex) — this SDK is environment-agnostic, so
|
|
96
|
+
* consumers map the name to whatever their renderer needs.
|
|
97
|
+
*/
|
|
98
|
+
color: "green" | "yellow" | "red";
|
|
99
|
+
/** Human-readable label. */
|
|
100
|
+
label: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Badge metadata for each {@link AvailabilityStatus}. Exhaustively keyed via
|
|
104
|
+
* `satisfies` so adding/removing a status value is a compile error here.
|
|
105
|
+
*
|
|
106
|
+
* - healthy → green check
|
|
107
|
+
* - unknown → yellow question
|
|
108
|
+
* - down → red cross
|
|
109
|
+
*/
|
|
110
|
+
declare const AVAILABILITY_BADGES: {
|
|
111
|
+
readonly healthy: {
|
|
112
|
+
readonly symbol: "✓";
|
|
113
|
+
readonly color: "green";
|
|
114
|
+
readonly label: "Healthy";
|
|
115
|
+
};
|
|
116
|
+
readonly unknown: {
|
|
117
|
+
readonly symbol: "?";
|
|
118
|
+
readonly color: "yellow";
|
|
119
|
+
readonly label: "Unknown";
|
|
120
|
+
};
|
|
121
|
+
readonly down: {
|
|
122
|
+
readonly symbol: "✗";
|
|
123
|
+
readonly color: "red";
|
|
124
|
+
readonly label: "Down";
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Stable-sort capabilities by health: `healthy` > `unknown` > `down`.
|
|
129
|
+
*
|
|
130
|
+
* Agents should PREFER `healthy` and fall back to `unknown` only when nothing
|
|
131
|
+
* `healthy` fits; `down` is last. A missing/null status is ranked as
|
|
132
|
+
* `unknown`. Returns a NEW array — the input is not mutated. Items of equal
|
|
133
|
+
* rank keep their original relative order (stable).
|
|
134
|
+
*/
|
|
135
|
+
declare const sortByHealth: <T extends {
|
|
136
|
+
availabilityStatus?: AvailabilityStatus | null;
|
|
137
|
+
}>(items: readonly T[]) => T[];
|
|
138
|
+
/**
|
|
139
|
+
* Alias for {@link sortByHealth}. The preference rule is "prefer healthy, fall
|
|
140
|
+
* back to unknown" — applying it to a list means sorting healthy-first.
|
|
141
|
+
*/
|
|
142
|
+
declare const preferHealthy: <T extends {
|
|
143
|
+
availabilityStatus?: AvailabilityStatus | null;
|
|
144
|
+
}>(items: readonly T[]) => T[];
|
|
145
|
+
|
|
146
|
+
declare const SDK_VERSION: string;
|
|
147
|
+
|
|
148
|
+
export { AVAILABILITY_BADGES, type AvailabilityBadge, type AvailabilityStatus, PaymentSessionMeta, type Rating, SDK_VERSION, ZeroApiError, ZeroAuthError, ZeroClient, ZeroConfigurationError, ZeroError, type ZeroErrorCode, ZeroPaymentError, ZeroSessionCloseFailedError, ZeroTimeoutError, ZeroValidationError, ZeroWalletError, createManagedAccount, preferHealthy, sortByHealth };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Z as ZeroClient, P as PaymentSessionMeta } from './client-B50UYxPr.js';
|
|
2
|
+
export { A as AccountCredentials, g as Auth, h as AuthDevice, _ as BUG_REPORT_CATEGORIES, w as BalanceOptions, x as BalanceReadError, a7 as BatchReviewResponse, $ as BugReportCategory, B as BugReports, i as Capabilities, a2 as CapabilityResponse, E as ClientOptions, a0 as CreateBugReportInput, a1 as CreateBugReportResponse, a8 as CreateReviewInput, a9 as CreateReviewResponse, aa as CreateRunInput, ab as CreateRunResponse, C as Credentials, G as DEFAULT_BASE_URL, H as DEFAULT_MAX_RETRIES, I as DEFAULT_TIMEOUT_MS, a4 as DevicePollResult, a5 as DeviceStartResponse, q as FETCH_SKIP_REASONS, r as FETCH_WARNINGS, F as FetchOptions, b as FetchOutcome, c as FetchResult, y as FundingUrlOptions, a3 as GetCapabilityOptions, Q as InternalUserDto, ac as ListRunsParams, ad as ListRunsResponse, L as LogEvent, K as LogLevel, J as Logger, M as MigrateAuthorization, z as MigrateAuthorizationResponse, N as NoCredentials, O as OnSessionRefreshed, j as PayInput, n as PayResult, k as PaymentChain, l as PaymentProtocol, m as PaymentResult, s as Payments, V as PublicUserDto, ae as RunListItem, R as Runs, af as SearchOptions, ag as SearchResponse, ah as SearchResult, S as SessionCredentials, a as SessionCredentialsInput, a6 as SessionExchangeResponse, o as SessionReceiptPayload, d as SignMessageInput, e as SignTransactionInput, f as SignTypedDataInput, T as TEMPO_CHAIN_ID, u as TEMPO_TESTNET_CHAIN_ID, U as UpstreamError, X as UserWalletDto, D as Wallet, W as WalletBalance, Y as WelcomeBonusSummary, p as coerceTempoChainId, t as paymentHasAnchor, v as tempoChainLabelFromId } from './client-B50UYxPr.js';
|
|
3
|
+
import { Address, LocalAccount } from 'viem';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
|
|
6
|
+
declare const createManagedAccount: (client: ZeroClient, address: Address) => LocalAccount;
|
|
7
|
+
|
|
8
|
+
type ZeroErrorCode = "api_error" | "auth_error" | "auth_session_expired" | "auth_no_credentials" | "payment_error" | "payment_session_close_failed" | "wallet_error" | "validation_error" | "timeout_error" | "configuration_error";
|
|
9
|
+
type ZeroErrorOptions = {
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
};
|
|
12
|
+
declare class ZeroError extends Error {
|
|
13
|
+
readonly code: ZeroErrorCode;
|
|
14
|
+
constructor(code: ZeroErrorCode, message: string, options?: ZeroErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
type ApiErrorInit = {
|
|
17
|
+
status: number;
|
|
18
|
+
requestId?: string | undefined;
|
|
19
|
+
body?: unknown;
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
};
|
|
22
|
+
declare class ZeroApiError extends ZeroError {
|
|
23
|
+
readonly status: number;
|
|
24
|
+
readonly requestId: string | undefined;
|
|
25
|
+
readonly body: unknown;
|
|
26
|
+
constructor(message: string, init: ApiErrorInit);
|
|
27
|
+
}
|
|
28
|
+
type AuthErrorCode = Extract<ZeroErrorCode, "auth_error" | "auth_session_expired" | "auth_no_credentials">;
|
|
29
|
+
declare class ZeroAuthError extends ZeroError {
|
|
30
|
+
constructor(code: AuthErrorCode, message: string, options?: ZeroErrorOptions);
|
|
31
|
+
}
|
|
32
|
+
declare class ZeroPaymentError extends ZeroError {
|
|
33
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
34
|
+
}
|
|
35
|
+
type SessionCloseFailedInit = {
|
|
36
|
+
session: PaymentSessionMeta;
|
|
37
|
+
response: Response;
|
|
38
|
+
capturedAmount: string;
|
|
39
|
+
cause?: unknown;
|
|
40
|
+
};
|
|
41
|
+
declare class ZeroSessionCloseFailedError extends ZeroError {
|
|
42
|
+
readonly session: PaymentSessionMeta;
|
|
43
|
+
readonly response: Response;
|
|
44
|
+
readonly capturedAmount: string;
|
|
45
|
+
constructor(message: string, init: SessionCloseFailedInit);
|
|
46
|
+
}
|
|
47
|
+
declare class ZeroWalletError extends ZeroError {
|
|
48
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
49
|
+
}
|
|
50
|
+
type ValidationErrorOptions = ZeroErrorOptions & {
|
|
51
|
+
body?: string;
|
|
52
|
+
};
|
|
53
|
+
declare class ZeroValidationError extends ZeroError {
|
|
54
|
+
readonly body: string | undefined;
|
|
55
|
+
constructor(message: string, options?: ValidationErrorOptions);
|
|
56
|
+
}
|
|
57
|
+
declare class ZeroTimeoutError extends ZeroError {
|
|
58
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
59
|
+
}
|
|
60
|
+
declare class ZeroConfigurationError extends ZeroError {
|
|
61
|
+
constructor(message: string, options?: ZeroErrorOptions);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare const ratingSchema: z.ZodObject<{
|
|
65
|
+
score: z.ZodString;
|
|
66
|
+
successRate: z.ZodString;
|
|
67
|
+
reviews: z.ZodNumber;
|
|
68
|
+
stars: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
+
state: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
unrated: "unrated";
|
|
71
|
+
rated: "rated";
|
|
72
|
+
}>>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
type Rating = z.infer<typeof ratingSchema>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Capability availability status — the single, consolidated health signal
|
|
78
|
+
* Zero surfaces to clients (ZERO-89 / ZERO-92).
|
|
79
|
+
*
|
|
80
|
+
* - `healthy` — proven live and executable; safe to call.
|
|
81
|
+
* - `unknown` — insufficient evidence either way; usable as a fallback.
|
|
82
|
+
* - `down` — confirmed dead / failing; avoid.
|
|
83
|
+
*
|
|
84
|
+
* Preference rule for agents: PREFER `healthy`. Fall back to `unknown` only
|
|
85
|
+
* when nothing `healthy` fits the task. Avoid `down`. This is the same rule the
|
|
86
|
+
* server-side visibility filter enforces, surfaced here so agents and UIs can
|
|
87
|
+
* rank consistently.
|
|
88
|
+
*/
|
|
89
|
+
type AvailabilityStatus = "healthy" | "unknown" | "down";
|
|
90
|
+
/** A renderable badge for an {@link AvailabilityStatus}. */
|
|
91
|
+
type AvailabilityBadge = {
|
|
92
|
+
/** A short glyph suitable for terminals/UI (✓ / ? / ✗). */
|
|
93
|
+
symbol: string;
|
|
94
|
+
/**
|
|
95
|
+
* A color *name* (not ANSI/hex) — this SDK is environment-agnostic, so
|
|
96
|
+
* consumers map the name to whatever their renderer needs.
|
|
97
|
+
*/
|
|
98
|
+
color: "green" | "yellow" | "red";
|
|
99
|
+
/** Human-readable label. */
|
|
100
|
+
label: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Badge metadata for each {@link AvailabilityStatus}. Exhaustively keyed via
|
|
104
|
+
* `satisfies` so adding/removing a status value is a compile error here.
|
|
105
|
+
*
|
|
106
|
+
* - healthy → green check
|
|
107
|
+
* - unknown → yellow question
|
|
108
|
+
* - down → red cross
|
|
109
|
+
*/
|
|
110
|
+
declare const AVAILABILITY_BADGES: {
|
|
111
|
+
readonly healthy: {
|
|
112
|
+
readonly symbol: "✓";
|
|
113
|
+
readonly color: "green";
|
|
114
|
+
readonly label: "Healthy";
|
|
115
|
+
};
|
|
116
|
+
readonly unknown: {
|
|
117
|
+
readonly symbol: "?";
|
|
118
|
+
readonly color: "yellow";
|
|
119
|
+
readonly label: "Unknown";
|
|
120
|
+
};
|
|
121
|
+
readonly down: {
|
|
122
|
+
readonly symbol: "✗";
|
|
123
|
+
readonly color: "red";
|
|
124
|
+
readonly label: "Down";
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Stable-sort capabilities by health: `healthy` > `unknown` > `down`.
|
|
129
|
+
*
|
|
130
|
+
* Agents should PREFER `healthy` and fall back to `unknown` only when nothing
|
|
131
|
+
* `healthy` fits; `down` is last. A missing/null status is ranked as
|
|
132
|
+
* `unknown`. Returns a NEW array — the input is not mutated. Items of equal
|
|
133
|
+
* rank keep their original relative order (stable).
|
|
134
|
+
*/
|
|
135
|
+
declare const sortByHealth: <T extends {
|
|
136
|
+
availabilityStatus?: AvailabilityStatus | null;
|
|
137
|
+
}>(items: readonly T[]) => T[];
|
|
138
|
+
/**
|
|
139
|
+
* Alias for {@link sortByHealth}. The preference rule is "prefer healthy, fall
|
|
140
|
+
* back to unknown" — applying it to a list means sorting healthy-first.
|
|
141
|
+
*/
|
|
142
|
+
declare const preferHealthy: <T extends {
|
|
143
|
+
availabilityStatus?: AvailabilityStatus | null;
|
|
144
|
+
}>(items: readonly T[]) => T[];
|
|
145
|
+
|
|
146
|
+
declare const SDK_VERSION: string;
|
|
147
|
+
|
|
148
|
+
export { AVAILABILITY_BADGES, type AvailabilityBadge, type AvailabilityStatus, PaymentSessionMeta, type Rating, SDK_VERSION, ZeroApiError, ZeroAuthError, ZeroClient, ZeroConfigurationError, ZeroError, type ZeroErrorCode, ZeroPaymentError, ZeroSessionCloseFailedError, ZeroTimeoutError, ZeroValidationError, ZeroWalletError, createManagedAccount, preferHealthy, sortByHealth };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export { Auth, AuthDevice, BUG_REPORT_CATEGORIES, BugReports, Capabilities, DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, FETCH_SKIP_REASONS, FETCH_WARNINGS, Payments, Runs, SDK_VERSION, TEMPO_CHAIN_ID, TEMPO_TESTNET_CHAIN_ID, Wallet, ZeroApiError, ZeroAuthError, ZeroClient, ZeroConfigurationError, ZeroError, ZeroPaymentError, ZeroSessionCloseFailedError, ZeroTimeoutError, ZeroValidationError, ZeroWalletError, coerceTempoChainId, createManagedAccount, paymentHasAnchor, tempoChainLabelFromId } from './chunk-XQEHJX2X.js';
|
|
2
|
+
|
|
3
|
+
// src/status.ts
|
|
4
|
+
var AVAILABILITY_BADGES = {
|
|
5
|
+
healthy: { symbol: "\u2713", color: "green", label: "Healthy" },
|
|
6
|
+
unknown: { symbol: "?", color: "yellow", label: "Unknown" },
|
|
7
|
+
down: { symbol: "\u2717", color: "red", label: "Down" }
|
|
8
|
+
};
|
|
9
|
+
var STATUS_RANK = {
|
|
10
|
+
healthy: 0,
|
|
11
|
+
unknown: 1,
|
|
12
|
+
down: 2
|
|
13
|
+
};
|
|
14
|
+
var rankOf = (status) => (
|
|
15
|
+
// Missing/null status is treated as `unknown` — "we don't know" ranks
|
|
16
|
+
// above a confirmed `down` but below a proven `healthy`.
|
|
17
|
+
status == null ? STATUS_RANK.unknown : STATUS_RANK[status]
|
|
18
|
+
);
|
|
19
|
+
var sortByHealth = (items) => [...items].sort(
|
|
20
|
+
(a, b) => rankOf(a.availabilityStatus) - rankOf(b.availabilityStatus)
|
|
21
|
+
);
|
|
22
|
+
var preferHealthy = sortByHealth;
|
|
23
|
+
|
|
24
|
+
export { AVAILABILITY_BADGES, preferHealthy, sortByHealth };
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/status.ts"],"names":[],"mappings":";;;AAoCO,IAAM,mBAAA,GAAsB;AAAA,EAClC,SAAS,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,OAAA,EAAS,OAAO,SAAA,EAAU;AAAA,EACzD,SAAS,EAAE,MAAA,EAAQ,KAAK,KAAA,EAAO,QAAA,EAAU,OAAO,SAAA,EAAU;AAAA,EAC1D,MAAM,EAAE,MAAA,EAAQ,UAAK,KAAA,EAAO,KAAA,EAAO,OAAO,MAAA;AAC3C;AAGA,IAAM,WAAA,GAAkD;AAAA,EACvD,OAAA,EAAS,CAAA;AAAA,EACT,OAAA,EAAS,CAAA;AAAA,EACT,IAAA,EAAM;AACP,CAAA;AAEA,IAAM,SAAS,CAAC,MAAA;AAAA;AAAA;AAAA,EAGf,MAAA,IAAU,IAAA,GAAO,WAAA,CAAY,OAAA,GAAU,YAAY,MAAM;AAAA,CAAA;AAUnD,IAAM,eAAe,CAG3B,KAAA,KAEA,CAAC,GAAG,KAAK,CAAA,CAAE,IAAA;AAAA,EACV,CAAC,GAAG,CAAA,KAAM,MAAA,CAAO,EAAE,kBAAkB,CAAA,GAAI,MAAA,CAAO,CAAA,CAAE,kBAAkB;AACrE;AAMM,IAAM,aAAA,GAAgB","file":"index.js","sourcesContent":["/**\n * Capability availability status — the single, consolidated health signal\n * Zero surfaces to clients (ZERO-89 / ZERO-92).\n *\n * - `healthy` — proven live and executable; safe to call.\n * - `unknown` — insufficient evidence either way; usable as a fallback.\n * - `down` — confirmed dead / failing; avoid.\n *\n * Preference rule for agents: PREFER `healthy`. Fall back to `unknown` only\n * when nothing `healthy` fits the task. Avoid `down`. This is the same rule the\n * server-side visibility filter enforces, surfaced here so agents and UIs can\n * rank consistently.\n */\nexport type AvailabilityStatus = \"healthy\" | \"unknown\" | \"down\";\n\n/** A renderable badge for an {@link AvailabilityStatus}. */\nexport type AvailabilityBadge = {\n\t/** A short glyph suitable for terminals/UI (✓ / ? / ✗). */\n\tsymbol: string;\n\t/**\n\t * A color *name* (not ANSI/hex) — this SDK is environment-agnostic, so\n\t * consumers map the name to whatever their renderer needs.\n\t */\n\tcolor: \"green\" | \"yellow\" | \"red\";\n\t/** Human-readable label. */\n\tlabel: string;\n};\n\n/**\n * Badge metadata for each {@link AvailabilityStatus}. Exhaustively keyed via\n * `satisfies` so adding/removing a status value is a compile error here.\n *\n * - healthy → green check\n * - unknown → yellow question\n * - down → red cross\n */\nexport const AVAILABILITY_BADGES = {\n\thealthy: { symbol: \"✓\", color: \"green\", label: \"Healthy\" },\n\tunknown: { symbol: \"?\", color: \"yellow\", label: \"Unknown\" },\n\tdown: { symbol: \"✗\", color: \"red\", label: \"Down\" },\n} as const satisfies Record<AvailabilityStatus, AvailabilityBadge>;\n\n// Lower rank sorts first: healthy ahead of unknown ahead of down.\nconst STATUS_RANK: Record<AvailabilityStatus, number> = {\n\thealthy: 0,\n\tunknown: 1,\n\tdown: 2,\n};\n\nconst rankOf = (status: AvailabilityStatus | null | undefined): number =>\n\t// Missing/null status is treated as `unknown` — \"we don't know\" ranks\n\t// above a confirmed `down` but below a proven `healthy`.\n\tstatus == null ? STATUS_RANK.unknown : STATUS_RANK[status];\n\n/**\n * Stable-sort capabilities by health: `healthy` > `unknown` > `down`.\n *\n * Agents should PREFER `healthy` and fall back to `unknown` only when nothing\n * `healthy` fits; `down` is last. A missing/null status is ranked as\n * `unknown`. Returns a NEW array — the input is not mutated. Items of equal\n * rank keep their original relative order (stable).\n */\nexport const sortByHealth = <\n\tT extends { availabilityStatus?: AvailabilityStatus | null },\n>(\n\titems: readonly T[],\n): T[] =>\n\t[...items].sort(\n\t\t(a, b) => rankOf(a.availabilityStatus) - rankOf(b.availabilityStatus),\n\t);\n\n/**\n * Alias for {@link sortByHealth}. The preference rule is \"prefer healthy, fall\n * back to unknown\" — applying it to a list means sorting healthy-first.\n */\nexport const preferHealthy = sortByHealth;\n"]}
|
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk7STN754W_cjs = require('./chunk-7STN754W.cjs');
|
|
4
|
+
|
|
5
|
+
// src/testing/index.ts
|
|
6
|
+
var FALLBACK_HANDLER = (request) => {
|
|
7
|
+
const url = new URL(request.url);
|
|
8
|
+
return new Response(
|
|
9
|
+
JSON.stringify({
|
|
10
|
+
error: `No mock handler registered for ${request.method} ${url.pathname}`
|
|
11
|
+
}),
|
|
12
|
+
{
|
|
13
|
+
status: 404,
|
|
14
|
+
headers: { "content-type": "application/json" }
|
|
15
|
+
}
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
var createMockFetch = (routes) => {
|
|
19
|
+
const impl = async (input, init) => {
|
|
20
|
+
const request = new Request(input, init);
|
|
21
|
+
const url = new URL(request.url);
|
|
22
|
+
const key = `${request.method} ${url.pathname}`;
|
|
23
|
+
const handler = routes[key] ?? FALLBACK_HANDLER;
|
|
24
|
+
return await handler(request);
|
|
25
|
+
};
|
|
26
|
+
return impl;
|
|
27
|
+
};
|
|
28
|
+
var respondJson = (body, init) => new Response(JSON.stringify(body), {
|
|
29
|
+
status: init?.status ?? 200,
|
|
30
|
+
headers: {
|
|
31
|
+
"content-type": "application/json",
|
|
32
|
+
...init?.headers
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
var createTestClient = (opts = {}) => {
|
|
36
|
+
const { routes, ...rest } = opts;
|
|
37
|
+
return new chunk7STN754W_cjs.ZeroClient({
|
|
38
|
+
...rest,
|
|
39
|
+
baseUrl: rest.baseUrl ?? "http://test.zero.local",
|
|
40
|
+
// Tests should fail fast, not retry-and-mask flakiness.
|
|
41
|
+
maxRetries: rest.maxRetries ?? 0,
|
|
42
|
+
timeout: rest.timeout ?? 2e3,
|
|
43
|
+
fetch: rest.fetch ?? (routes ? createMockFetch(routes) : void 0)
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.createMockFetch = createMockFetch;
|
|
48
|
+
exports.createTestClient = createTestClient;
|
|
49
|
+
exports.respondJson = respondJson;
|
|
50
|
+
//# sourceMappingURL=testing.cjs.map
|
|
51
|
+
//# sourceMappingURL=testing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing/index.ts"],"names":["ZeroClient"],"mappings":";;;;;AAeA,IAAM,gBAAA,GAAiC,CAAC,OAAA,KAAY;AACnD,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,OAAA,CAAQ,GAAG,CAAA;AAC/B,EAAA,OAAO,IAAI,QAAA;AAAA,IACV,KAAK,SAAA,CAAU;AAAA,MACd,OAAO,CAAA,+BAAA,EAAkC,OAAA,CAAQ,MAAM,CAAA,CAAA,EAAI,IAAI,QAAQ,CAAA;AAAA,KACvE,CAAA;AAAA,IACD;AAAA,MACC,MAAA,EAAQ,GAAA;AAAA,MACR,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA;AAAmB;AAC/C,GACD;AACD,CAAA;AAKO,IAAM,eAAA,GAAkB,CAAC,MAAA,KAAmC;AAClE,EAAA,MAAM,IAAA,GAAO,OACZ,KAAA,EACA,IAAA,KACuB;AACvB,IAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAAQ,KAAA,EAA4B,IAAI,CAAA;AAC5D,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,OAAA,CAAQ,GAAG,CAAA;AAC/B,IAAA,MAAM,MAAM,CAAA,EAAG,OAAA,CAAQ,MAAM,CAAA,CAAA,EAAI,IAAI,QAAQ,CAAA,CAAA;AAC7C,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,GAAG,CAAA,IAAK,gBAAA;AAC/B,IAAA,OAAO,MAAM,QAAQ,OAAO,CAAA;AAAA,EAC7B,CAAA;AACA,EAAA,OAAO,IAAA;AACR;AAEO,IAAM,WAAA,GAAc,CAAC,IAAA,EAAe,IAAA,KAC1C,IAAI,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA,EAAG;AAAA,EAClC,MAAA,EAAQ,MAAM,MAAA,IAAU,GAAA;AAAA,EACxB,OAAA,EAAS;AAAA,IACR,cAAA,EAAgB,kBAAA;AAAA,IAChB,GAAI,IAAA,EAAM;AAAA;AAEZ,CAAC;AAQK,IAAM,gBAAA,GAAmB,CAAC,IAAA,GAA0B,EAAC,KAAkB;AAC7E,EAAA,MAAM,EAAE,MAAA,EAAQ,GAAG,IAAA,EAAK,GAAI,IAAA;AAK5B,EAAA,OAAO,IAAIA,4BAAA,CAAW;AAAA,IACrB,GAAG,IAAA;AAAA,IACH,OAAA,EAAS,KAAK,OAAA,IAAW,wBAAA;AAAA;AAAA,IAEzB,UAAA,EAAY,KAAK,UAAA,IAAc,CAAA;AAAA,IAC/B,OAAA,EAAS,KAAK,OAAA,IAAW,GAAA;AAAA,IACzB,OAAO,IAAA,CAAK,KAAA,KAAU,MAAA,GAAS,eAAA,CAAgB,MAAM,CAAA,GAAI,MAAA;AAAA,GACzD,CAAA;AACF","file":"testing.cjs","sourcesContent":["import { ZeroClient } from \"../client\";\nimport type { ClientOptions } from \"../options\";\n\n// Local x402 / MPP test servers live in the workspace-internal\n// `@zero/test-fixtures` package (private, never published). Keeping them out\n// of the SDK keeps the published surface small and avoids pulling hono /\n// @hono/node-server / @x402/hono into partner installs.\n\nexport type RouteHandler = (request: Request) => Response | Promise<Response>;\n\n// Keyed by `\"METHOD pathname\"` (e.g. `\"POST /v1/search\"`). Path is the URL\n// pathname only — query string is ignored for matching, but the handler gets\n// the full Request and can inspect query params via `new URL(req.url)`.\nexport type RouteMap = Record<string, RouteHandler>;\n\nconst FALLBACK_HANDLER: RouteHandler = (request) => {\n\tconst url = new URL(request.url);\n\treturn new Response(\n\t\tJSON.stringify({\n\t\t\terror: `No mock handler registered for ${request.method} ${url.pathname}`,\n\t\t}),\n\t\t{\n\t\t\tstatus: 404,\n\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t},\n\t);\n};\n\n// Minimal fetch substitute for unit tests. For richer mocking (request\n// matching, body assertions, scenario reuse across packages), reach for MSW\n// — this helper is the dependency-free escape hatch.\nexport const createMockFetch = (routes: RouteMap): typeof fetch => {\n\tconst impl = async (\n\t\tinput: Parameters<typeof fetch>[0],\n\t\tinit?: RequestInit,\n\t): Promise<Response> => {\n\t\tconst request = new Request(input as unknown as string, init);\n\t\tconst url = new URL(request.url);\n\t\tconst key = `${request.method} ${url.pathname}`;\n\t\tconst handler = routes[key] ?? FALLBACK_HANDLER;\n\t\treturn await handler(request);\n\t};\n\treturn impl as typeof fetch;\n};\n\nexport const respondJson = (body: unknown, init?: ResponseInit): Response =>\n\tnew Response(JSON.stringify(body), {\n\t\tstatus: init?.status ?? 200,\n\t\theaders: {\n\t\t\t\"content-type\": \"application/json\",\n\t\t\t...(init?.headers as Record<string, string> | undefined),\n\t\t},\n\t});\n\nexport type TestClientOptions = ClientOptions & {\n\t// Convenience: if supplied, builds a mock fetch from the routes and\n\t// installs it on the client. Useful for `createTestClient({ routes: { ... } })`.\n\troutes?: RouteMap;\n};\n\nexport const createTestClient = (opts: TestClientOptions = {}): ZeroClient => {\n\tconst { routes, ...rest } = opts;\n\t// Spread `rest` FIRST, then apply defaults — that way a caller that\n\t// passes `baseUrl: undefined` (common from `{ ...userOpts }` shapes)\n\t// gets the test default rather than falling through to the\n\t// production-pointing ClientOptions default.\n\treturn new ZeroClient({\n\t\t...rest,\n\t\tbaseUrl: rest.baseUrl ?? \"http://test.zero.local\",\n\t\t// Tests should fail fast, not retry-and-mask flakiness.\n\t\tmaxRetries: rest.maxRetries ?? 0,\n\t\ttimeout: rest.timeout ?? 2_000,\n\t\tfetch: rest.fetch ?? (routes ? createMockFetch(routes) : undefined),\n\t});\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { E as ClientOptions, Z as ZeroClient } from './client-B50UYxPr.cjs';
|
|
2
|
+
import 'viem';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
type RouteHandler = (request: Request) => Response | Promise<Response>;
|
|
6
|
+
type RouteMap = Record<string, RouteHandler>;
|
|
7
|
+
declare const createMockFetch: (routes: RouteMap) => typeof fetch;
|
|
8
|
+
declare const respondJson: (body: unknown, init?: ResponseInit) => Response;
|
|
9
|
+
type TestClientOptions = ClientOptions & {
|
|
10
|
+
routes?: RouteMap;
|
|
11
|
+
};
|
|
12
|
+
declare const createTestClient: (opts?: TestClientOptions) => ZeroClient;
|
|
13
|
+
|
|
14
|
+
export { type RouteHandler, type RouteMap, type TestClientOptions, createMockFetch, createTestClient, respondJson };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { E as ClientOptions, Z as ZeroClient } from './client-B50UYxPr.js';
|
|
2
|
+
import 'viem';
|
|
3
|
+
import 'zod';
|
|
4
|
+
|
|
5
|
+
type RouteHandler = (request: Request) => Response | Promise<Response>;
|
|
6
|
+
type RouteMap = Record<string, RouteHandler>;
|
|
7
|
+
declare const createMockFetch: (routes: RouteMap) => typeof fetch;
|
|
8
|
+
declare const respondJson: (body: unknown, init?: ResponseInit) => Response;
|
|
9
|
+
type TestClientOptions = ClientOptions & {
|
|
10
|
+
routes?: RouteMap;
|
|
11
|
+
};
|
|
12
|
+
declare const createTestClient: (opts?: TestClientOptions) => ZeroClient;
|
|
13
|
+
|
|
14
|
+
export { type RouteHandler, type RouteMap, type TestClientOptions, createMockFetch, createTestClient, respondJson };
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ZeroClient } from './chunk-XQEHJX2X.js';
|
|
2
|
+
|
|
3
|
+
// src/testing/index.ts
|
|
4
|
+
var FALLBACK_HANDLER = (request) => {
|
|
5
|
+
const url = new URL(request.url);
|
|
6
|
+
return new Response(
|
|
7
|
+
JSON.stringify({
|
|
8
|
+
error: `No mock handler registered for ${request.method} ${url.pathname}`
|
|
9
|
+
}),
|
|
10
|
+
{
|
|
11
|
+
status: 404,
|
|
12
|
+
headers: { "content-type": "application/json" }
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
var createMockFetch = (routes) => {
|
|
17
|
+
const impl = async (input, init) => {
|
|
18
|
+
const request = new Request(input, init);
|
|
19
|
+
const url = new URL(request.url);
|
|
20
|
+
const key = `${request.method} ${url.pathname}`;
|
|
21
|
+
const handler = routes[key] ?? FALLBACK_HANDLER;
|
|
22
|
+
return await handler(request);
|
|
23
|
+
};
|
|
24
|
+
return impl;
|
|
25
|
+
};
|
|
26
|
+
var respondJson = (body, init) => new Response(JSON.stringify(body), {
|
|
27
|
+
status: init?.status ?? 200,
|
|
28
|
+
headers: {
|
|
29
|
+
"content-type": "application/json",
|
|
30
|
+
...init?.headers
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
var createTestClient = (opts = {}) => {
|
|
34
|
+
const { routes, ...rest } = opts;
|
|
35
|
+
return new ZeroClient({
|
|
36
|
+
...rest,
|
|
37
|
+
baseUrl: rest.baseUrl ?? "http://test.zero.local",
|
|
38
|
+
// Tests should fail fast, not retry-and-mask flakiness.
|
|
39
|
+
maxRetries: rest.maxRetries ?? 0,
|
|
40
|
+
timeout: rest.timeout ?? 2e3,
|
|
41
|
+
fetch: rest.fetch ?? (routes ? createMockFetch(routes) : void 0)
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { createMockFetch, createTestClient, respondJson };
|
|
46
|
+
//# sourceMappingURL=testing.js.map
|
|
47
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/testing/index.ts"],"names":[],"mappings":";;;AAeA,IAAM,gBAAA,GAAiC,CAAC,OAAA,KAAY;AACnD,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,OAAA,CAAQ,GAAG,CAAA;AAC/B,EAAA,OAAO,IAAI,QAAA;AAAA,IACV,KAAK,SAAA,CAAU;AAAA,MACd,OAAO,CAAA,+BAAA,EAAkC,OAAA,CAAQ,MAAM,CAAA,CAAA,EAAI,IAAI,QAAQ,CAAA;AAAA,KACvE,CAAA;AAAA,IACD;AAAA,MACC,MAAA,EAAQ,GAAA;AAAA,MACR,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA;AAAmB;AAC/C,GACD;AACD,CAAA;AAKO,IAAM,eAAA,GAAkB,CAAC,MAAA,KAAmC;AAClE,EAAA,MAAM,IAAA,GAAO,OACZ,KAAA,EACA,IAAA,KACuB;AACvB,IAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAAQ,KAAA,EAA4B,IAAI,CAAA;AAC5D,IAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,OAAA,CAAQ,GAAG,CAAA;AAC/B,IAAA,MAAM,MAAM,CAAA,EAAG,OAAA,CAAQ,MAAM,CAAA,CAAA,EAAI,IAAI,QAAQ,CAAA,CAAA;AAC7C,IAAA,MAAM,OAAA,GAAU,MAAA,CAAO,GAAG,CAAA,IAAK,gBAAA;AAC/B,IAAA,OAAO,MAAM,QAAQ,OAAO,CAAA;AAAA,EAC7B,CAAA;AACA,EAAA,OAAO,IAAA;AACR;AAEO,IAAM,WAAA,GAAc,CAAC,IAAA,EAAe,IAAA,KAC1C,IAAI,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA,EAAG;AAAA,EAClC,MAAA,EAAQ,MAAM,MAAA,IAAU,GAAA;AAAA,EACxB,OAAA,EAAS;AAAA,IACR,cAAA,EAAgB,kBAAA;AAAA,IAChB,GAAI,IAAA,EAAM;AAAA;AAEZ,CAAC;AAQK,IAAM,gBAAA,GAAmB,CAAC,IAAA,GAA0B,EAAC,KAAkB;AAC7E,EAAA,MAAM,EAAE,MAAA,EAAQ,GAAG,IAAA,EAAK,GAAI,IAAA;AAK5B,EAAA,OAAO,IAAI,UAAA,CAAW;AAAA,IACrB,GAAG,IAAA;AAAA,IACH,OAAA,EAAS,KAAK,OAAA,IAAW,wBAAA;AAAA;AAAA,IAEzB,UAAA,EAAY,KAAK,UAAA,IAAc,CAAA;AAAA,IAC/B,OAAA,EAAS,KAAK,OAAA,IAAW,GAAA;AAAA,IACzB,OAAO,IAAA,CAAK,KAAA,KAAU,MAAA,GAAS,eAAA,CAAgB,MAAM,CAAA,GAAI,MAAA;AAAA,GACzD,CAAA;AACF","file":"testing.js","sourcesContent":["import { ZeroClient } from \"../client\";\nimport type { ClientOptions } from \"../options\";\n\n// Local x402 / MPP test servers live in the workspace-internal\n// `@zero/test-fixtures` package (private, never published). Keeping them out\n// of the SDK keeps the published surface small and avoids pulling hono /\n// @hono/node-server / @x402/hono into partner installs.\n\nexport type RouteHandler = (request: Request) => Response | Promise<Response>;\n\n// Keyed by `\"METHOD pathname\"` (e.g. `\"POST /v1/search\"`). Path is the URL\n// pathname only — query string is ignored for matching, but the handler gets\n// the full Request and can inspect query params via `new URL(req.url)`.\nexport type RouteMap = Record<string, RouteHandler>;\n\nconst FALLBACK_HANDLER: RouteHandler = (request) => {\n\tconst url = new URL(request.url);\n\treturn new Response(\n\t\tJSON.stringify({\n\t\t\terror: `No mock handler registered for ${request.method} ${url.pathname}`,\n\t\t}),\n\t\t{\n\t\t\tstatus: 404,\n\t\t\theaders: { \"content-type\": \"application/json\" },\n\t\t},\n\t);\n};\n\n// Minimal fetch substitute for unit tests. For richer mocking (request\n// matching, body assertions, scenario reuse across packages), reach for MSW\n// — this helper is the dependency-free escape hatch.\nexport const createMockFetch = (routes: RouteMap): typeof fetch => {\n\tconst impl = async (\n\t\tinput: Parameters<typeof fetch>[0],\n\t\tinit?: RequestInit,\n\t): Promise<Response> => {\n\t\tconst request = new Request(input as unknown as string, init);\n\t\tconst url = new URL(request.url);\n\t\tconst key = `${request.method} ${url.pathname}`;\n\t\tconst handler = routes[key] ?? FALLBACK_HANDLER;\n\t\treturn await handler(request);\n\t};\n\treturn impl as typeof fetch;\n};\n\nexport const respondJson = (body: unknown, init?: ResponseInit): Response =>\n\tnew Response(JSON.stringify(body), {\n\t\tstatus: init?.status ?? 200,\n\t\theaders: {\n\t\t\t\"content-type\": \"application/json\",\n\t\t\t...(init?.headers as Record<string, string> | undefined),\n\t\t},\n\t});\n\nexport type TestClientOptions = ClientOptions & {\n\t// Convenience: if supplied, builds a mock fetch from the routes and\n\t// installs it on the client. Useful for `createTestClient({ routes: { ... } })`.\n\troutes?: RouteMap;\n};\n\nexport const createTestClient = (opts: TestClientOptions = {}): ZeroClient => {\n\tconst { routes, ...rest } = opts;\n\t// Spread `rest` FIRST, then apply defaults — that way a caller that\n\t// passes `baseUrl: undefined` (common from `{ ...userOpts }` shapes)\n\t// gets the test default rather than falling through to the\n\t// production-pointing ClientOptions default.\n\treturn new ZeroClient({\n\t\t...rest,\n\t\tbaseUrl: rest.baseUrl ?? \"http://test.zero.local\",\n\t\t// Tests should fail fast, not retry-and-mask flakiness.\n\t\tmaxRetries: rest.maxRetries ?? 0,\n\t\ttimeout: rest.timeout ?? 2_000,\n\t\tfetch: rest.fetch ?? (routes ? createMockFetch(routes) : undefined),\n\t});\n};\n"]}
|