@xenosystem/agent-cli 0.5.107 → 0.5.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index.js +2 -2
  3. package/dist/metafile-esm.json +1 -1
  4. package/dist/sdk-build-identity.json +4 -4
  5. package/native/xeno-pty/prebuilds/win32-x64/manifest.json +18 -18
  6. package/node_modules/@xeno-corporation/account/LICENSE +39 -0
  7. package/node_modules/@xeno-corporation/account/README.md +211 -0
  8. package/node_modules/@xeno-corporation/account/dist/chunk-FELZILY4.mjs +60 -0
  9. package/node_modules/@xeno-corporation/account/dist/chunk-FELZILY4.mjs.map +1 -0
  10. package/node_modules/@xeno-corporation/account/dist/index.d.mts +883 -0
  11. package/node_modules/@xeno-corporation/account/dist/index.d.ts +883 -0
  12. package/node_modules/@xeno-corporation/account/dist/index.js +2301 -0
  13. package/node_modules/@xeno-corporation/account/dist/index.js.map +1 -0
  14. package/node_modules/@xeno-corporation/account/dist/index.mjs +2191 -0
  15. package/node_modules/@xeno-corporation/account/dist/index.mjs.map +1 -0
  16. package/node_modules/@xeno-corporation/account/dist/node.d.mts +35 -0
  17. package/node_modules/@xeno-corporation/account/dist/node.d.ts +35 -0
  18. package/node_modules/@xeno-corporation/account/dist/node.js +715 -0
  19. package/node_modules/@xeno-corporation/account/dist/node.js.map +1 -0
  20. package/node_modules/@xeno-corporation/account/dist/node.mjs +645 -0
  21. package/node_modules/@xeno-corporation/account/dist/node.mjs.map +1 -0
  22. package/node_modules/@xeno-corporation/account/dist/tokenStore-CnIo2ILq.d.mts +47 -0
  23. package/node_modules/@xeno-corporation/account/dist/tokenStore-CnIo2ILq.d.ts +47 -0
  24. package/node_modules/@xeno-corporation/account/package.json +60 -0
  25. package/node_modules/zod/LICENSE +21 -0
  26. package/node_modules/zod/README.md +3028 -0
  27. package/node_modules/zod/index.d.ts +2 -0
  28. package/node_modules/zod/lib/ZodError.d.ts +164 -0
  29. package/node_modules/zod/lib/ZodError.js +137 -0
  30. package/node_modules/zod/lib/__tests__/Mocker.d.ts +17 -0
  31. package/node_modules/zod/lib/__tests__/Mocker.js +57 -0
  32. package/node_modules/zod/lib/benchmarks/datetime.d.ts +5 -0
  33. package/node_modules/zod/lib/benchmarks/datetime.js +54 -0
  34. package/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts +5 -0
  35. package/node_modules/zod/lib/benchmarks/discriminatedUnion.js +79 -0
  36. package/node_modules/zod/lib/benchmarks/index.d.ts +1 -0
  37. package/node_modules/zod/lib/benchmarks/index.js +59 -0
  38. package/node_modules/zod/lib/benchmarks/ipv4.d.ts +5 -0
  39. package/node_modules/zod/lib/benchmarks/ipv4.js +54 -0
  40. package/node_modules/zod/lib/benchmarks/object.d.ts +5 -0
  41. package/node_modules/zod/lib/benchmarks/object.js +70 -0
  42. package/node_modules/zod/lib/benchmarks/primitives.d.ts +5 -0
  43. package/node_modules/zod/lib/benchmarks/primitives.js +170 -0
  44. package/node_modules/zod/lib/benchmarks/realworld.d.ts +5 -0
  45. package/node_modules/zod/lib/benchmarks/realworld.js +56 -0
  46. package/node_modules/zod/lib/benchmarks/string.d.ts +5 -0
  47. package/node_modules/zod/lib/benchmarks/string.js +55 -0
  48. package/node_modules/zod/lib/benchmarks/union.d.ts +5 -0
  49. package/node_modules/zod/lib/benchmarks/union.js +79 -0
  50. package/node_modules/zod/lib/errors.d.ts +5 -0
  51. package/node_modules/zod/lib/errors.js +17 -0
  52. package/node_modules/zod/lib/external.d.ts +6 -0
  53. package/node_modules/zod/lib/external.js +22 -0
  54. package/node_modules/zod/lib/helpers/enumUtil.d.ts +8 -0
  55. package/node_modules/zod/lib/helpers/enumUtil.js +2 -0
  56. package/node_modules/zod/lib/helpers/errorUtil.d.ts +9 -0
  57. package/node_modules/zod/lib/helpers/errorUtil.js +8 -0
  58. package/node_modules/zod/lib/helpers/parseUtil.d.ts +78 -0
  59. package/node_modules/zod/lib/helpers/parseUtil.js +125 -0
  60. package/node_modules/zod/lib/helpers/partialUtil.d.ts +8 -0
  61. package/node_modules/zod/lib/helpers/partialUtil.js +2 -0
  62. package/node_modules/zod/lib/helpers/typeAliases.d.ts +2 -0
  63. package/node_modules/zod/lib/helpers/typeAliases.js +2 -0
  64. package/node_modules/zod/lib/helpers/util.d.ts +82 -0
  65. package/node_modules/zod/lib/helpers/util.js +142 -0
  66. package/node_modules/zod/lib/index.d.ts +4 -0
  67. package/node_modules/zod/lib/index.js +33 -0
  68. package/node_modules/zod/lib/index.mjs +4382 -0
  69. package/node_modules/zod/lib/index.umd.js +4497 -0
  70. package/node_modules/zod/lib/locales/en.d.ts +3 -0
  71. package/node_modules/zod/lib/locales/en.js +129 -0
  72. package/node_modules/zod/lib/standard-schema.d.ts +102 -0
  73. package/node_modules/zod/lib/standard-schema.js +2 -0
  74. package/node_modules/zod/lib/types.d.ts +1062 -0
  75. package/node_modules/zod/lib/types.js +3823 -0
  76. package/node_modules/zod/package.json +122 -0
  77. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "packageName": "@xenosystem/agent-sdk",
4
4
  "version": "0.10.59",
5
- "cliBundleSha256": "cb1f79b4a55dfb484cf65520842681d731dda125830e061a1aa8b34be9dceed0",
5
+ "cliBundleSha256": "84ce2b2a979b9368376ceb669da9f10af61ec61abfaa050f79b52ff97ef26ee1",
6
6
  "inputs": [
7
7
  {
8
8
  "path": "dist/agents/index.js",
@@ -157,15 +157,15 @@
157
157
  "emitted": [
158
158
  {
159
159
  "path": "cli.js",
160
- "sha256": "8036feb360c5f4d4b8414ff12034dd5c0e58254f8cb643ba19902ec3472e9e36"
160
+ "sha256": "25464ebf7863e0a64dc17565642107675ab59062d13f77a44a2be98a6980a7e3"
161
161
  },
162
162
  {
163
163
  "path": "index.js",
164
- "sha256": "cb1f79b4a55dfb484cf65520842681d731dda125830e061a1aa8b34be9dceed0"
164
+ "sha256": "84ce2b2a979b9368376ceb669da9f10af61ec61abfaa050f79b52ff97ef26ee1"
165
165
  },
166
166
  {
167
167
  "path": "metafile-esm.json",
168
- "sha256": "8f1cf7d50da12396ec1b5a3862f18677d3231355f1c6f5040f2a1371a82f8f17"
168
+ "sha256": "5cc3e2e2dddae274e55eff2b9f7798d7eea4ed455cbf335bce48c4325988f740"
169
169
  }
170
170
  ]
171
171
  }
@@ -1,18 +1,18 @@
1
- {
2
- "schemaVersion": 2,
3
- "component": "xeno-pty",
4
- "binary": "xeno_pty.node",
5
- "apiVersion": 1,
6
- "platform": "win32",
7
- "architecture": "x64",
8
- "abi": "napi-v8",
9
- "napi": 8,
10
- "minimumNode": "20.0.0",
11
- "nodeHeaders": "24.13.1",
12
- "compiler": "Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36260 for x64",
13
- "sourceSha256": "3da3e5b6c553f76d9adb3078507c9d615e5dcae9fe5f8b86094e219c7ad768fa",
14
- "sha256": "557d7c100735e72506e3eb302d33cec302b2e6fcc6d3bcbf66730844eac8f3df",
15
- "signature": {
16
- "status": "unsigned-development"
17
- }
18
- }
1
+ {
2
+ "schemaVersion": 2,
3
+ "component": "xeno-pty",
4
+ "binary": "xeno_pty.node",
5
+ "apiVersion": 1,
6
+ "platform": "win32",
7
+ "architecture": "x64",
8
+ "abi": "napi-v8",
9
+ "napi": 8,
10
+ "minimumNode": "20.0.0",
11
+ "nodeHeaders": "24.13.1",
12
+ "compiler": "Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36260 for x64",
13
+ "sourceSha256": "3da3e5b6c553f76d9adb3078507c9d615e5dcae9fe5f8b86094e219c7ad768fa",
14
+ "sha256": "557d7c100735e72506e3eb302d33cec302b2e6fcc6d3bcbf66730844eac8f3df",
15
+ "signature": {
16
+ "status": "unsigned-development"
17
+ }
18
+ }
@@ -0,0 +1,39 @@
1
+ @xeno-corporation/account — PROPRIETARY SOFTWARE LICENSE
2
+
3
+ Copyright (c) 2026 XENO Corporation. All rights reserved.
4
+
5
+ This package is the confidential and proprietary property of XENO Corporation.
6
+ No license, right, or interest is granted by possession of this package or by
7
+ its availability on any package registry.
8
+
9
+ You may NOT, without the prior written permission of XENO Corporation: use,
10
+ execute, copy, publish, distribute, modify, create derivative works from,
11
+ reverse engineer, sublicense, sell, rent, lease, or otherwise transfer this
12
+ package, in whole or in part.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED. IN NO EVENT SHALL XENO CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, OR
16
+ OTHER LIABILITY ARISING FROM OR IN CONNECTION WITH THE SOFTWARE.
17
+
18
+ ---
19
+
20
+ WHY THIS PACKAGE CARRIES ITS OWN LICENCE
21
+
22
+ This is the canonical XENO ecosystem account + credits-ledger client. Every XENO
23
+ product federates to the platform through it — and most of those products are
24
+ proprietary.
25
+
26
+ It lives inside the `xeno-post` repository for historical reasons
27
+ (`XENO AUTH - SPEC.md` line 7 designates `xeno-post/packages/account-kit` as its
28
+ canonical home). It therefore used to inherit that repository's licence. When
29
+ `xeno-post` was AGPL-3.0, this SDK was implicitly AGPL-3.0 too — meaning every
30
+ proprietary XENO app that embedded it was linking copyleft code.
31
+
32
+ This file exists so that never happens again by accident. **A package's licence
33
+ must be stated on the package, not inherited from whatever repository it happens
34
+ to sit in.** If `xeno-post` is ever relicensed — in either direction — this file
35
+ governs this package and must be changed deliberately, on its own merits.
36
+
37
+ Publishing note: this package is published to a PRIVATE registry (GitHub
38
+ Packages, `@xeno-corporation` scope). It must never be published to the public
39
+ npm registry.
@@ -0,0 +1,211 @@
1
+ # @xeno-corporation/account
2
+
3
+ The canonical XENO ecosystem **account + credits-ledger client**. Every XENO app
4
+ (a "branch") federates to the platform ("origin") through this one SDK — uniform
5
+ integration, not bespoke per-app hacks. See `XENO ACCOUNT - ARCHITECTURE.md`.
6
+
7
+ Framework-agnostic (no NestJS/React/etc.), `fetch`-based, Zod-validated. Node + edge.
8
+
9
+ ## What it does
10
+ - **Identity (OIDC relying-party):** Authorization Code + PKCE (S256) for web/native
11
+ (RFC 8252), Device Authorization Grant (RFC 8628) for CLI. No implicit, no ROPC.
12
+ - **Ledger (idempotent metering):** double-entry spend via usage events + two-phase
13
+ holds (reserve → settle/void). Every mutation carries an `Idempotency-Key`; a retry
14
+ can never double-charge. Money is integer **micro-credits** (1 credit = 1e6 µcr).
15
+ - **Authorization (ReBAC):** central authz checks (OpenFGA-backed) so cross-app
16
+ permission inheritance works without per-app role sync.
17
+
18
+ ## Quick start (a branch)
19
+ ```ts
20
+ import { XenoAccountClient, keychainStore } from '@xeno-corporation/account';
21
+ import { createNodeDpopSigner } from '@xeno-corporation/account/node';
22
+
23
+ // Load this stable P-256 private JWK from the host keychain/secret manager.
24
+ // Never generate a new key for each process start and never log the JWK.
25
+ const dpopSigner = createNodeDpopSigner(process.env.XENO_OIDC_DPOP_PRIVATE_JWK!);
26
+
27
+ const xeno = new XenoAccountClient({
28
+ issuer: process.env.XENO_PLATFORM_URL!, // https://xenostudio.ai
29
+ apiBase: process.env.XENO_PLATFORM_API_URL!, // https://api.xenostudio.ai
30
+ surface: 'xeno_post', // this app's attribution tag
31
+ oidc: {
32
+ clientId: 'xeno-post',
33
+ redirectUri: 'https://post.xenostudio.ai/auth/callback',
34
+ dpopSigner,
35
+ },
36
+ store: keychainStore(hostKeychain),
37
+ });
38
+
39
+ // 1. Begin "Continue with XENO" — persist { state, pkce.verifier } (encrypted).
40
+ const { url, state, nonce, pkce } = await xeno.beginSignIn();
41
+
42
+ // 2. On callback — exchange the code (verify state first).
43
+ const tokens = await xeno.completeSignIn({
44
+ code,
45
+ codeVerifier: pkce.verifier,
46
+ expectedNonce: nonce,
47
+ });
48
+
49
+ // 3. Sender-constrain every resource call to its exact method and URL.
50
+ const usageUrl = `${process.env.XENO_PLATFORM_API_URL!}/api/v2/ledger/usage`;
51
+ const usageAuth = await xeno.authorization('POST', usageUrl, { scopes: ['ledger'] });
52
+ if (!usageAuth) throw new Error('XENO sign-in required');
53
+
54
+ // 4. Meter a spend (idempotent on a deterministic transactionId).
55
+ await xeno.ledger.recordUsage(usageAuth, {
56
+ surface: 'xeno_post',
57
+ transactionId: `post:${postId}:ai-caption`, // deterministic → exactly-once
58
+ operation: 'ai.caption',
59
+ model: 'claude-opus-4-8',
60
+ costMicro: 5_000,
61
+ });
62
+
63
+ // 5. Obtain a new proof for every distinct method/URL. Never reuse one.
64
+ const holdUrl = `${process.env.XENO_PLATFORM_API_URL!}/api/v2/ledger/holds`;
65
+ const holdAuth = await xeno.authorization('POST', holdUrl, { scopes: ['ledger'] });
66
+ if (!holdAuth) throw new Error('XENO sign-in required');
67
+ const hold = await xeno.ledger.hold(holdAuth, {
68
+ surface: 'xeno_post', holdId: `job:${jobId}`, amountMicro: 50_000, operation: 'ai.image',
69
+ });
70
+ // … do the work …
71
+ const settleUrl = `${holdUrl}/${encodeURIComponent(hold.holdId)}/settle`;
72
+ const settleAuth = await xeno.authorization('POST', settleUrl, { scopes: ['ledger'] });
73
+ if (!settleAuth) throw new Error('XENO sign-in required');
74
+ await xeno.ledger.settle(settleAuth, hold.holdId, /* actual */ 42_000);
75
+ ```
76
+
77
+ ## Standalone-first
78
+ A branch only constructs this in **cloud mode** (when a platform URL is configured).
79
+ With it absent the app runs entirely on its own auth — self-host stays free.
80
+
81
+ ## Resource Request Verification
82
+
83
+ `createResourceRequestAuthorizer` is the shared resource-server verifier for
84
+ DPoP-bound account access tokens. Configure the canonical issuer, eligible
85
+ client IDs, existing `Transport`, an atomic durable `DpopReplayStore`, and a
86
+ trusted current-session/epoch callback. Pass the exact method, operator-known
87
+ HTTPS URL, Authorization and DPoP headers. Never derive the trusted origin from
88
+ caller Host/Forwarded headers or accept identity as a product capability grant.
89
+
90
+ The returned receipt revalidates original identity before effect/evidence release
91
+ without replaying its single-use proof. Token/proof/key/method/URL/hash/time/nonce,
92
+ client/scope and ambiguous JSON failures refuse. Revocation/replay dependency
93
+ outages remain unavailable. The callback and replay store need production
94
+ provisioning; this candidate is not a new login issuer, live auth qualification
95
+ or permission to publish. The live origin currently lacks a verified MFA-strength
96
+ claim in the inspected contract, so fresh timing alone must not authorize MFA gates.
97
+
98
+ `createOidcIntrospectionSessionAuthority` provides the current origin-session
99
+ callback. It posts the exact verified token to the canonical introspection
100
+ endpoint without forwarding a resource-specific proof, validates matching
101
+ subject/session/client/scope/expiry/resource and bounds both headers and body
102
+ by one deadline. It has no positive revocation cache or local session issuer.
103
+
104
+ ## HTTP Response And Retry Contract
105
+
106
+ `Transport` keeps one per-attempt deadline across host authorization, headers and
107
+ streamed response body. Default timeout is 8 seconds; default decoded-response
108
+ limit is 1 MiB. Invalid limits, malformed UTF-8 and oversized responses refuse;
109
+ successful JSON is never truncated. Redirects and ambient cookies are disabled.
110
+ Unread/late bodies are cancelled without awaiting an unbounded cancel callback.
111
+ Public errors omit request paths, queries, credentials and provider error text.
112
+
113
+ Automatic retry requires an idempotent GET or a mutation idempotency key. A static
114
+ DPoP proof is never replayed. Pass a `RequestAuthorizationProvider(method, url)`
115
+ to the transport or account/ledger/authz client when retries need fresh host-owned
116
+ authorization. Each attempt obtains a new proof for that exact method/URL.
117
+ Original method/URL/body/headers/idempotency identity is snapshotted before any
118
+ await. Invalid authorization replies refuse rather than falling back to old tokens.
119
+ OAuth grant endpoints explicitly opt into bounded allowlisted error codes;
120
+ unreadable/ambiguous bodies never become `invalid_grant` or successful polling.
121
+
122
+ These changes are unpublished candidate behavior, not a live sign-in/keystore
123
+ or release qualification. See `docs/ACCOUNT_HTTP_QUALIFICATION.md` in the owning
124
+ repository for benchmark, verification scope and remaining release gates.
125
+
126
+ ## Errors
127
+ Every failure is an `AccountError` with a `code` you branch on:
128
+ `DISABLED · UNREACHABLE · INVALID_TOKEN · INSUFFICIENT_CREDITS · CONFLICT ·
129
+ INVALID_RESPONSE · BAD_REQUEST · NOT_FOUND · RATE_LIMITED · PLATFORM_ERROR`.
130
+
131
+ ## Owning Session Lifecycle
132
+
133
+ `TokenStore.withExclusive(key, work)` is required for canonical session writes.
134
+ The host must exclude all other writers of that product/client entry, including
135
+ other processes sharing its keystore. `memoryStore` supplies in-realm exclusion;
136
+ `keychainStore` forwards the owning host primitive. Missing exclusion refuses
137
+ before refresh dispatch. A promise queue in one CLI process is not OS exclusion.
138
+
139
+ Refresh reserves a unique transition marker in the same protected store before
140
+ the single-use request. Success persists the successor before publishing cached
141
+ access. Unknown reply, invalid response or failed commit retains an explicit
142
+ nonretryable pending state; cold clients cannot blindly replay the old rotating
143
+ token. Explicit interactive sign-in replaces that state. Only confirmed typed
144
+ `invalid_grant` removes the original credential, and only while it still owns
145
+ the exact transition. Outages never silently delete the credential or prompt.
146
+
147
+ Logout immediately withdraws local cached authority and advances a generation;
148
+ late refresh/code/device/proof responses cannot restore it. A durable signed-out
149
+ marker precedes deletion, so failed deletion refuses cold reuse. Global logout
150
+ failure preserves the original local session for explicit step-up recovery;
151
+ successful cleanup may delete only its original committed store transition,
152
+ never a newer sign-in. Request release checks both generation and store state.
153
+
154
+ Cached scope/expiry/session derive from signed access claims, with response
155
+ expiry allowed only to shorten authority. User display derives from verified ID
156
+ claims matching the access subject/session. Auth observers cannot break a
157
+ committed state, signer/store failures are categorical, and broker tokens never
158
+ transfer refresh credentials. Fresh standalone sign-in without a successor
159
+ retires any prior standalone refresh token. Raw `refresh(token)` remains the
160
+ server-owned low-level API; its caller owns serialization/durable reconciliation.
161
+
162
+ These are candidate protocol/client guarantees, not an OS-keystore implementation,
163
+ hardware-key claim, production origin/Hub/CLI migration or release clearance.
164
+ See `docs/ACCOUNT_SESSION_LIFECYCLE.md` in the owning repository.
165
+
166
+ ## Windows Privileged Host
167
+
168
+ `createWindowsAccountHost` is exported only from `@xeno-corporation/account/node`.
169
+ It supplies a `TokenStore` backed by current-user Windows Credential Manager,
170
+ native SID/product-namespaced mutex exclusion and a non-exportable P-256 signer
171
+ from Microsoft Platform Crypto Provider. The provider's hardware implementation
172
+ flag, actual key provider/algorithm/usage/export policy and returned signatures
173
+ are verified. Missing TPM, key, secure vault or private mutex custody fails;
174
+ there is no software-key, plaintext file or bearer fallback.
175
+
176
+ ```ts
177
+ import { XenoAccountClient } from '@xeno-corporation/account';
178
+ import { createWindowsAccountHost } from '@xeno-corporation/account/node';
179
+
180
+ const host = await createWindowsAccountHost({ clientId: 'xeno-agent-cli' });
181
+ const account = new XenoAccountClient({
182
+ issuer: 'https://xenostudio.ai',
183
+ apiBase: 'https://api.xenostudio.ai',
184
+ surface: 'xeno_agent_cli',
185
+ apiKey: '',
186
+ store: host.store,
187
+ oidc: { clientId: 'xeno-agent-cli', dpopSigner: host.dpopSigner },
188
+ });
189
+ // Own explicit system-browser/device sign-in and typed display state in the host.
190
+ // On shutdown, finish active account work, then await host.close().
191
+ ```
192
+
193
+ Default opens an existing key. Explicit initial `createKey: true` provisions one
194
+ only when no key or vault refresh/pending authority exists in that namespace.
195
+ It never silently replaces a missing key under an existing credential. A key
196
+ rotation or account migration requires its own reviewed lifecycle.
197
+
198
+ Refresh and transition values are limited to Credential Manager's 2560-byte
199
+ generic-credential bound. Only the configured client refresh/pending names are
200
+ accessible. Secrets use inherited private stdin/stdout, not command arguments,
201
+ environment or logs. A hidden helper owns the thread-affine mutex and monitors
202
+ the exact Node parent's kernel process handle; parent loss interrupts native
203
+ waits. Abandoned mutex acquisition refuses, never pretending clean completion.
204
+ Late callback access after transaction release refuses. Queues, RPC bytes,
205
+ native lock waits and whole transaction/helper calls are bounded; timeout kills
206
+ the exact helper and leaves account state unknown. Close refuses active work.
207
+
208
+ Hardware/non-exportability is not remote attestation or containment against
209
+ malicious same-user code. This candidate does not integrate real CLI login,
210
+ verify Hub executable trust, provision Use policy/product grants, establish MFA,
211
+ or qualify macOS/Linux keystores. See `docs/ACCOUNT_WINDOWS_HOST.md` in the owner.
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/errors.ts
5
+ var AccountError = class extends Error {
6
+ static {
7
+ __name(this, "AccountError");
8
+ }
9
+ code;
10
+ httpStatus;
11
+ retryable;
12
+ retryAfterMs;
13
+ oauthError;
14
+ constructor(args) {
15
+ super(args.message);
16
+ this.name = "AccountError";
17
+ this.code = args.code;
18
+ this.httpStatus = args.httpStatus ?? null;
19
+ this.retryable = args.retryable ?? defaultRetryable(args.code);
20
+ this.retryAfterMs = args.retryAfterMs ?? null;
21
+ this.oauthError = args.oauthError ?? null;
22
+ }
23
+ };
24
+ function defaultRetryable(code) {
25
+ return code === "UNREACHABLE" || code === "RATE_LIMITED" || code === "PLATFORM_ERROR";
26
+ }
27
+ __name(defaultRetryable, "defaultRetryable");
28
+ function codeForStatus(status) {
29
+ if (status === 401 || status === 403) return "INVALID_TOKEN";
30
+ if (status === 402) return "INSUFFICIENT_CREDITS";
31
+ if (status === 409) return "CONFLICT";
32
+ if (status === 400 || status === 422) return "BAD_REQUEST";
33
+ if (status === 404) return "NOT_FOUND";
34
+ if (status === 429) return "RATE_LIMITED";
35
+ if (status >= 500) return "UNREACHABLE";
36
+ return "PLATFORM_ERROR";
37
+ }
38
+ __name(codeForStatus, "codeForStatus");
39
+
40
+ // src/dpop.ts
41
+ function normalizeDpopHtu(value) {
42
+ const url = new URL(value);
43
+ if (url.protocol !== "https:") throw new Error("DPoP htu must use HTTPS");
44
+ url.hash = "";
45
+ url.search = "";
46
+ url.username = "";
47
+ url.password = "";
48
+ url.hostname = url.hostname.toLowerCase();
49
+ if (url.port === "443") url.port = "";
50
+ return url.toString();
51
+ }
52
+ __name(normalizeDpopHtu, "normalizeDpopHtu");
53
+
54
+ export {
55
+ __name,
56
+ AccountError,
57
+ codeForStatus,
58
+ normalizeDpopHtu
59
+ };
60
+ //# sourceMappingURL=chunk-FELZILY4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/dpop.ts"],"mappings":";;;;AAgBO,IAAMA,eAAN,cAA2BC,MAAAA;EAhBlC,OAgBkCA;;;EACvBC;EACAC;EACAC;EACAC;EACAC;EAET,YAAYC,MAOT;AACD,UAAMA,KAAKC,OAAO;AAClB,SAAKC,OAAO;AACZ,SAAKP,OAAOK,KAAKL;AACjB,SAAKC,aAAaI,KAAKJ,cAAc;AACrC,SAAKC,YAAYG,KAAKH,aAAaM,iBAAiBH,KAAKL,IAAI;AAC7D,SAAKG,eAAeE,KAAKF,gBAAgB;AACzC,SAAKC,aAAaC,KAAKD,cAAc;EACvC;AACF;AAEA,SAASI,iBAAiBR,MAAsB;AAC9C,SAAOA,SAAS,iBAAiBA,SAAS,kBAAkBA,SAAS;AACvE;AAFSQ;AAKF,SAASC,cAAcC,QAAc;AAC1C,MAAIA,WAAW,OAAOA,WAAW,IAAK,QAAO;AAC7C,MAAIA,WAAW,IAAK,QAAO;AAC3B,MAAIA,WAAW,IAAK,QAAO;AAC3B,MAAIA,WAAW,OAAOA,WAAW,IAAK,QAAO;AAC7C,MAAIA,WAAW,IAAK,QAAO;AAC3B,MAAIA,WAAW,IAAK,QAAO;AAC3B,MAAIA,UAAU,IAAK,QAAO;AAC1B,SAAO;AACT;AATgBD;;;AC7BT,SAASE,iBAAiBC,OAAa;AAC5C,QAAMC,MAAM,IAAIC,IAAIF,KAAAA;AACpB,MAAIC,IAAIE,aAAa,SAAU,OAAM,IAAIC,MAAM,yBAAA;AAC/CH,MAAII,OAAO;AACXJ,MAAIK,SAAS;AACbL,MAAIM,WAAW;AACfN,MAAIO,WAAW;AACfP,MAAIQ,WAAWR,IAAIQ,SAASC,YAAW;AACvC,MAAIT,IAAIU,SAAS,MAAOV,KAAIU,OAAO;AACnC,SAAOV,IAAIW,SAAQ;AACrB;AAVgBb;","names":["AccountError","Error","code","httpStatus","retryable","retryAfterMs","oauthError","args","message","name","defaultRetryable","codeForStatus","status","normalizeDpopHtu","value","url","URL","protocol","Error","hash","search","username","password","hostname","toLowerCase","port","toString"]}