@capxul/sdk 1.0.0-alpha.12 → 1.0.0-alpha.13
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/InMemoryAuthCacheAdapter-v5W-XB5M.mjs +457 -0
- package/dist/InMemoryAuthCacheAdapter-v5W-XB5M.mjs.map +1 -0
- package/dist/index-D0SflScT.d.mts +157 -0
- package/dist/index-D0SflScT.d.mts.map +1 -0
- package/dist/index.d.mts +407 -130
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1411 -187
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.d.mts +3 -3
- package/dist/node/index.mjs +1 -2
- package/dist/node/index.mjs.map +1 -1
- package/dist/ports/safe-deployment.d.mts +1 -1
- package/dist/{safe-deployment-DMGB1kEL.d.mts → safe-deployment-ToMPzqwk.d.mts} +4 -5
- package/dist/safe-deployment-ToMPzqwk.d.mts.map +1 -0
- package/dist/{signer-DEMJbpJ2.d.mts → signer-Cp2G98ZK.d.mts} +7 -8
- package/dist/signer-Cp2G98ZK.d.mts.map +1 -0
- package/package.json +8 -8
- package/dist/InMemoryAuthCacheAdapter-EBzKEJmQ.mjs +0 -113
- package/dist/InMemoryAuthCacheAdapter-EBzKEJmQ.mjs.map +0 -1
- package/dist/safe-deployment-DMGB1kEL.d.mts.map +0 -1
- package/dist/signer-DEMJbpJ2.d.mts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,181 @@
|
|
|
1
|
-
import { n as BrowserAuthCacheAdapter, o as AuthCachePortTag, t as InMemoryAuthCacheAdapter } from "./InMemoryAuthCacheAdapter-
|
|
2
|
-
import {
|
|
3
|
-
import { CapxulError as CapxulError$2, Errors as Errors$1, USDX_CURRENCY, USDX_DECIMALS, compileOrgRoleDefinitions, decodeConvexError, isCapxulError as isCapxulError$2, normalizeBindingEmail, orgRoleKeyForLabel, orgRoleTemplateDefinitions } from "@capxul/config";
|
|
4
|
-
import { toAccountId, toAddress, toAllowedOrigin, toAnonymousDistinctId, toAppId, toAuthUserId, toChainId, toCountryCode, toCurrencyCode, toDurationMs, toEmail, toEpochMs, toEpochSeconds, toJwtToken, toKycTier, toOrgId, toPublishableKey, toPublishableKeyId, toRoleKey, toSessionToken, toSubAccountId } from "@capxul/types";
|
|
1
|
+
import { A as toSessionToken, C as toEpochSeconds, D as toPublishableKey, E as toOrgId, F as isCapxulError, M as decodeConvexError, N as CapxulError, O as toPublishableKeyId, P as Errors, S as toEpochMs, T as toKycTier, _ as toChainId, b as toDurationMs, c as BYTES32_RE, d as toAccountId, f as toAddress, g as toAuthUserId, h as toAppId, j as toSubAccountId, k as toRoleKey, l as EVM_ADDRESS_RE$1, m as toAnonymousDistinctId, n as BrowserAuthCacheAdapter, o as AuthCachePortTag, p as toAllowedOrigin, s as APP_ID_RE, t as InMemoryAuthCacheAdapter, u as SUPPORTED_CURRENCY_CODES, v as toCountryCode, w as toJwtToken, x as toEmail, y as toCurrencyCode } from "./InMemoryAuthCacheAdapter-v5W-XB5M.mjs";
|
|
2
|
+
import { formatUnits, keccak256, padHex, parseUnits, recoverAddress, stringToHex, toBytes } from "viem";
|
|
5
3
|
import { Context, Data, Deferred, Duration, Effect, Either, Exit, Layer, Ref, Request, Scope } from "effect";
|
|
6
4
|
import { getFunctionName, makeFunctionReference } from "convex/server";
|
|
7
5
|
import { privateKeyToAccount } from "viem/accounts";
|
|
8
|
-
import { formatUnits, keccak256, parseUnits, recoverAddress, stringToHex } from "viem";
|
|
9
6
|
import { Schema, TreeFormatter } from "@effect/schema";
|
|
10
|
-
import { BootstrapEnvelope } from "@capxul/wire";
|
|
11
7
|
import { ConvexClient } from "convex/browser";
|
|
12
|
-
import { redactTelemetryProps } from "@capxul/observability";
|
|
13
8
|
import { AccountTypeEnum, ChainTypeEnum, EmbeddedState, Openfort, RecoveryMethod, ThirdPartyOAuthProvider } from "@openfort/openfort-js";
|
|
14
9
|
import { Machine } from "@effect/experimental";
|
|
10
|
+
//#region ../config/src/tokens.ts
|
|
11
|
+
/** `TestUSDC` ("USDX") — Base Sepolia, 6 decimals, open `mint`. (Canon §1.) */
|
|
12
|
+
const USDX_ADDRESS_BASE_SEPOLIA = "0xf09fcbb6df9f8f918e58f9c8ab15a76ade862b77";
|
|
13
|
+
USDX_ADDRESS_BASE_SEPOLIA.toLowerCase();
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region ../config/src/safe.ts
|
|
16
|
+
const BASE_SEPOLIA_CHAIN_ID = 84532;
|
|
17
|
+
/**
|
|
18
|
+
* Normalize an email for use as a Capxul Safe salt input.
|
|
19
|
+
*
|
|
20
|
+
* Trims surrounding whitespace and lowercases the address so that
|
|
21
|
+
* `" User+Demo@Example.COM "` and `"user+demo@example.com"` derive
|
|
22
|
+
* the same `safeAddress`. This is the canonical normalization rule —
|
|
23
|
+
* any future change here would shift every existing user's Safe
|
|
24
|
+
* address, so the rule is pinned by the fixture matrix in
|
|
25
|
+
* `packages/config/tests/safe-address-conformance.test.ts`.
|
|
26
|
+
*
|
|
27
|
+
* @param email - The raw email address to normalize
|
|
28
|
+
* @returns The trimmed, lowercased email
|
|
29
|
+
*/
|
|
30
|
+
function normalizeSafeSaltEmail(email) {
|
|
31
|
+
return email.trim().toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Normalize a raw email for binding id + Safe salt derivation.
|
|
35
|
+
* Delegates to {@link normalizeSafeSaltEmail} so binding resolution and
|
|
36
|
+
* `deriveCapxulSafeAddress` never drift apart.
|
|
37
|
+
*/
|
|
38
|
+
function normalizeBindingEmail(email) {
|
|
39
|
+
return normalizeSafeSaltEmail(email);
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region ../config/src/route.ts
|
|
43
|
+
/** USDX on Base Sepolia — the only settlement token in v1. */
|
|
44
|
+
const USDX_BASE_SEPOLIA_TOKEN = {
|
|
45
|
+
chainId: BASE_SEPOLIA_CHAIN_ID,
|
|
46
|
+
address: USDX_ADDRESS_BASE_SEPOLIA,
|
|
47
|
+
decimals: 6
|
|
48
|
+
};
|
|
49
|
+
USDX_BASE_SEPOLIA_TOKEN.chainId;
|
|
50
|
+
USDX_BASE_SEPOLIA_TOKEN.chainId;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region ../config/src/role-dsl.ts
|
|
53
|
+
const USD_DECIMALS = 6;
|
|
54
|
+
const USD_SCALE = 10n ** BigInt(USD_DECIMALS);
|
|
55
|
+
const USD_DISPLAY_RE = /^\d+(?:\.\d{1,6})?$/;
|
|
56
|
+
const USD_BASE_UNIT_RE = /^\d+$/;
|
|
57
|
+
const EXEC_TRANSACTION_WITH_ROLE = "zodiac.roles.execTransactionWithRole";
|
|
58
|
+
const ASSIGN_ROLES = "zodiac.roles.assignRoles";
|
|
59
|
+
const SCOPE_TARGET = "zodiac.roles.scopeTarget";
|
|
60
|
+
const OWNER_ROLE_LABEL = "Owner";
|
|
61
|
+
const MARKETING_SUB_ACCOUNT_ID = "subaccount_marketing";
|
|
62
|
+
const PAYROLL_SUB_ACCOUNT_ID = "subaccount_payroll";
|
|
63
|
+
function usd(value) {
|
|
64
|
+
return {
|
|
65
|
+
currency: "USD",
|
|
66
|
+
value: usdDisplayToBaseUnits(value),
|
|
67
|
+
decimals: USD_DECIMALS
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function usdDisplayToBaseUnits(value) {
|
|
71
|
+
if (value.trim() !== value || !USD_DISPLAY_RE.test(value)) throw Errors.invalidInput("role.spend", "USD caps must be unsigned decimal strings with at most 6 fractional digits");
|
|
72
|
+
const parts = value.split(".");
|
|
73
|
+
const whole = parts[0] ?? "0";
|
|
74
|
+
const fraction = parts[1] ?? "";
|
|
75
|
+
return (BigInt(whole) * USD_SCALE + BigInt(fraction.padEnd(USD_DECIMALS, "0"))).toString();
|
|
76
|
+
}
|
|
77
|
+
function normalizeOrgRoleMoney(money, field) {
|
|
78
|
+
if (money.currency !== "USD" || money.decimals !== USD_DECIMALS || !USD_BASE_UNIT_RE.test(money.value)) throw Errors.invalidInput(field, `must be USD base units with ${USD_DECIMALS} decimals`);
|
|
79
|
+
return money;
|
|
80
|
+
}
|
|
81
|
+
function normalizeOrgRoleSpendCap(spend) {
|
|
82
|
+
if (spend === void 0) return void 0;
|
|
83
|
+
return {
|
|
84
|
+
...spend.perTx === void 0 ? {} : { perTx: normalizeOrgRoleMoney(spend.perTx, "roles.spend.perTx") },
|
|
85
|
+
...spend.perDay === void 0 ? {} : { perDay: normalizeOrgRoleMoney(spend.perDay, "roles.spend.perDay") },
|
|
86
|
+
...spend.toRecipients === void 0 ? {} : { toRecipients: spend.toRecipients }
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function normalizeOrgRoleLabel(label) {
|
|
90
|
+
const normalized = label.trim().replace(/\s+/g, " ");
|
|
91
|
+
if (normalized.length === 0) throw Errors.invalidInput("role.label", "must be a non-empty role label");
|
|
92
|
+
return normalized;
|
|
93
|
+
}
|
|
94
|
+
function orgRoleKeyForLabel(label) {
|
|
95
|
+
return keccak256(toBytes(normalizeOrgRoleLabel(label).toLowerCase()));
|
|
96
|
+
}
|
|
97
|
+
function soloOrgRoleTemplate() {
|
|
98
|
+
return [{
|
|
99
|
+
label: "Owner",
|
|
100
|
+
subAccounts: { scope: "all" },
|
|
101
|
+
canManageMembers: true,
|
|
102
|
+
canManageRoles: true
|
|
103
|
+
}];
|
|
104
|
+
}
|
|
105
|
+
function startupOrgRoleTemplate() {
|
|
106
|
+
return [
|
|
107
|
+
...soloOrgRoleTemplate(),
|
|
108
|
+
{
|
|
109
|
+
label: "Finance Manager",
|
|
110
|
+
spend: {
|
|
111
|
+
perTx: usd("25000"),
|
|
112
|
+
perDay: usd("100000"),
|
|
113
|
+
toRecipients: "anyone"
|
|
114
|
+
},
|
|
115
|
+
subAccounts: { scope: [MARKETING_SUB_ACCOUNT_ID] }
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
label: "Team Lead",
|
|
119
|
+
spend: {
|
|
120
|
+
perTx: usd("5000"),
|
|
121
|
+
perDay: usd("15000"),
|
|
122
|
+
toRecipients: "anyone"
|
|
123
|
+
},
|
|
124
|
+
subAccounts: { scope: [PAYROLL_SUB_ACCOUNT_ID] }
|
|
125
|
+
}
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
function orgRoleTemplateDefinitions(template, customRoles = []) {
|
|
129
|
+
switch (template) {
|
|
130
|
+
case "Solo": return soloOrgRoleTemplate();
|
|
131
|
+
case "Startup": return startupOrgRoleTemplate();
|
|
132
|
+
case "Custom": return customRoles.length === 0 ? soloOrgRoleTemplate() : customRoles;
|
|
133
|
+
default: return template;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function compileOrgRoleDefinitions(definitions) {
|
|
137
|
+
if (definitions.length === 0) throw Errors.invalidInput("roles", "must include at least one role");
|
|
138
|
+
const seen = /* @__PURE__ */ new Set();
|
|
139
|
+
const roles = definitions.map((definition) => {
|
|
140
|
+
const label = normalizeOrgRoleLabel(definition.label);
|
|
141
|
+
const roleKey = orgRoleKeyForLabel(label);
|
|
142
|
+
if (seen.has(roleKey)) throw Errors.invalidInput("roles", `duplicate role label: ${label}`);
|
|
143
|
+
seen.add(roleKey);
|
|
144
|
+
const spend = normalizeOrgRoleSpendCap(definition.spend);
|
|
145
|
+
const permissions = [];
|
|
146
|
+
if (spend !== void 0 || label === OWNER_ROLE_LABEL) permissions.push(EXEC_TRANSACTION_WITH_ROLE);
|
|
147
|
+
if (definition.canManageMembers === true) permissions.push(ASSIGN_ROLES);
|
|
148
|
+
if (definition.canManageRoles === true) permissions.push(SCOPE_TARGET);
|
|
149
|
+
return {
|
|
150
|
+
label,
|
|
151
|
+
roleKey,
|
|
152
|
+
definition: {
|
|
153
|
+
...definition,
|
|
154
|
+
label,
|
|
155
|
+
...spend === void 0 ? {} : { spend }
|
|
156
|
+
},
|
|
157
|
+
permissions,
|
|
158
|
+
allowance: spend ?? null
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
const manager = roles.find((role) => role.definition.canManageMembers === true);
|
|
162
|
+
if (manager === void 0) throw Errors.invalidInput("roles.canManageMembers", "at least one role must compile to the on-chain member-management permission");
|
|
163
|
+
return {
|
|
164
|
+
roles,
|
|
165
|
+
memberManagementRole: {
|
|
166
|
+
roleKey: manager.roleKey,
|
|
167
|
+
permission: ASSIGN_ROLES
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
padHex(stringToHex("FM_DAILY"), {
|
|
172
|
+
size: 32,
|
|
173
|
+
dir: "right"
|
|
174
|
+
}), padHex(stringToHex("TL_DAILY"), {
|
|
175
|
+
size: 32,
|
|
176
|
+
dir: "right"
|
|
177
|
+
});
|
|
178
|
+
//#endregion
|
|
15
179
|
//#region src/telemetry/stack-frame-parser.ts
|
|
16
180
|
/**
|
|
17
181
|
* Regex for V8/Chrome stack trace frame lines.
|
|
@@ -101,7 +265,7 @@ function isFailureMode(value) {
|
|
|
101
265
|
* unrecognised cause.
|
|
102
266
|
*/
|
|
103
267
|
function getFailureMode(error) {
|
|
104
|
-
if (!isCapxulError
|
|
268
|
+
if (!isCapxulError(error)) return void 0;
|
|
105
269
|
const details = error.details;
|
|
106
270
|
if (details === void 0) return void 0;
|
|
107
271
|
return isFailureMode(details.failure_mode) ? details.failure_mode : void 0;
|
|
@@ -138,7 +302,7 @@ function resolveFailureMode(error, contextFailureMode) {
|
|
|
138
302
|
function captureException(telemetry, error, context) {
|
|
139
303
|
return Effect.catchAllDefect(Effect.sync(() => {
|
|
140
304
|
const exceptionList = buildExceptionList(error instanceof Error ? parseV8StackFrames(error) : []);
|
|
141
|
-
const capxulError = isCapxulError
|
|
305
|
+
const capxulError = isCapxulError(error) ? error : null;
|
|
142
306
|
const props = {
|
|
143
307
|
capxul_error_code: capxulError?.code ?? context?.capxul_error_code ?? "UNKNOWN",
|
|
144
308
|
layer: capxulError?.layer ?? context?.layer,
|
|
@@ -245,7 +409,7 @@ const accountStatusProgram = Effect.gen(function* () {
|
|
|
245
409
|
};
|
|
246
410
|
const signerAddress = yield* Effect.tryPromise({
|
|
247
411
|
try: () => signer.getAddress(),
|
|
248
|
-
catch: (cause) => isCapxulError
|
|
412
|
+
catch: (cause) => isCapxulError(cause) ? cause : Errors.providerError("signer", "getAddress", cause)
|
|
249
413
|
});
|
|
250
414
|
return {
|
|
251
415
|
status: "accountProviderReady",
|
|
@@ -926,7 +1090,7 @@ function refLabel(ref) {
|
|
|
926
1090
|
//#endregion
|
|
927
1091
|
//#region src/client/to-capxul-result.ts
|
|
928
1092
|
async function toCapxulResult(program, layer) {
|
|
929
|
-
const result = await Effect.runPromise(program.pipe(Effect.provide(layer), Effect.catchAllDefect((defect) => Effect.fail(Errors
|
|
1093
|
+
const result = await Effect.runPromise(program.pipe(Effect.provide(layer), Effect.catchAllDefect((defect) => Effect.fail(Errors.unknown(defect))), Effect.either));
|
|
930
1094
|
if (Either.isLeft(result)) return {
|
|
931
1095
|
ok: false,
|
|
932
1096
|
error: result.left
|
|
@@ -955,13 +1119,13 @@ function makeAccountMethods(deps) {
|
|
|
955
1119
|
value: void 0
|
|
956
1120
|
};
|
|
957
1121
|
} catch (cause) {
|
|
958
|
-
if (cause instanceof CapxulError
|
|
1122
|
+
if (cause instanceof CapxulError) return {
|
|
959
1123
|
ok: false,
|
|
960
1124
|
error: cause
|
|
961
1125
|
};
|
|
962
1126
|
return {
|
|
963
1127
|
ok: false,
|
|
964
|
-
error: Errors
|
|
1128
|
+
error: Errors.providerError("signer", "getAddress", cause)
|
|
965
1129
|
};
|
|
966
1130
|
}
|
|
967
1131
|
};
|
|
@@ -992,7 +1156,7 @@ function makeAccountMethods(deps) {
|
|
|
992
1156
|
const session = await currentSession(deps.actor, deps.authCache);
|
|
993
1157
|
if (session === null) return {
|
|
994
1158
|
ok: false,
|
|
995
|
-
error: Errors
|
|
1159
|
+
error: Errors.notAuthenticated()
|
|
996
1160
|
};
|
|
997
1161
|
const profileReady = await ensureIdentityProfile(session);
|
|
998
1162
|
if (!profileReady.ok) return {
|
|
@@ -1015,12 +1179,12 @@ function makeAccountMethods(deps) {
|
|
|
1015
1179
|
const session = await currentSession(deps.actor, deps.authCache);
|
|
1016
1180
|
if (session === null) return {
|
|
1017
1181
|
ok: false,
|
|
1018
|
-
error: Errors
|
|
1182
|
+
error: Errors.notAuthenticated()
|
|
1019
1183
|
};
|
|
1020
1184
|
const signer = deps.signer;
|
|
1021
1185
|
if (signer === void 0) return {
|
|
1022
1186
|
ok: false,
|
|
1023
|
-
error: Errors
|
|
1187
|
+
error: Errors.smartAccountMissing("deploySafe")
|
|
1024
1188
|
};
|
|
1025
1189
|
const existing = await runPortEffect(deps.smartAccountPort.loadByAuthUserId(session.authUserId));
|
|
1026
1190
|
if (!existing.ok) return existing;
|
|
@@ -1093,7 +1257,7 @@ function makeAccountMethods(deps) {
|
|
|
1093
1257
|
let accountId;
|
|
1094
1258
|
if (status.value.status !== "notAuthenticated" && (phase.status === "ready" || isRequirementMet(status.value, requirement))) {
|
|
1095
1259
|
const accountReadPort = deps.accountReadPort;
|
|
1096
|
-
if (accountReadPort === void 0) return reportAndReturn(Errors
|
|
1260
|
+
if (accountReadPort === void 0) return reportAndReturn(Errors.invalidInput("account", "accountReadPort is required to resolve ready lifecycle"));
|
|
1097
1261
|
const account = await runPortEffect(accountReadPort.readBalance({ chainId: toChainId(deps.chainId) }));
|
|
1098
1262
|
if (!account.ok) return reportAndReturn(account.error);
|
|
1099
1263
|
accountId = String(account.value.id);
|
|
@@ -1154,7 +1318,7 @@ async function runBackendClaim(input) {
|
|
|
1154
1318
|
} catch (cause) {
|
|
1155
1319
|
return {
|
|
1156
1320
|
ok: false,
|
|
1157
|
-
error: Errors
|
|
1321
|
+
error: Errors.providerError("signer", "getAddress", cause)
|
|
1158
1322
|
};
|
|
1159
1323
|
}
|
|
1160
1324
|
const claimed = await runPortEffect(input.smartAccountPort.claim({
|
|
@@ -1203,7 +1367,7 @@ function eip1193AccountProvider(input) {
|
|
|
1203
1367
|
const first = firstAccount(await input.provider.request({ method: "eth_accounts" }));
|
|
1204
1368
|
if (first === null) return {
|
|
1205
1369
|
ok: false,
|
|
1206
|
-
error: Errors
|
|
1370
|
+
error: Errors.smartAccountMissing("eip1193-account")
|
|
1207
1371
|
};
|
|
1208
1372
|
const address = toAddress(first);
|
|
1209
1373
|
cachedAddress = address;
|
|
@@ -1214,7 +1378,7 @@ function eip1193AccountProvider(input) {
|
|
|
1214
1378
|
} catch (err) {
|
|
1215
1379
|
return {
|
|
1216
1380
|
ok: false,
|
|
1217
|
-
error: Errors
|
|
1381
|
+
error: Errors.providerError("eip1193", "eth_accounts", err)
|
|
1218
1382
|
};
|
|
1219
1383
|
} finally {
|
|
1220
1384
|
inFlight = null;
|
|
@@ -1228,7 +1392,7 @@ function eip1193AccountProvider(input) {
|
|
|
1228
1392
|
async getDeployAccount() {
|
|
1229
1393
|
return {
|
|
1230
1394
|
ok: false,
|
|
1231
|
-
error: Errors
|
|
1395
|
+
error: Errors.notImplemented("Eip1193AccountProvider", "getDeployAccount")
|
|
1232
1396
|
};
|
|
1233
1397
|
}
|
|
1234
1398
|
};
|
|
@@ -1436,7 +1600,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
1436
1600
|
}
|
|
1437
1601
|
//#endregion
|
|
1438
1602
|
//#region package.json
|
|
1439
|
-
var version = "1.0.0-alpha.
|
|
1603
|
+
var version = "1.0.0-alpha.13";
|
|
1440
1604
|
//#endregion
|
|
1441
1605
|
//#region src/ports/auth-client.ts
|
|
1442
1606
|
var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
|
|
@@ -1523,18 +1687,18 @@ function mapBetterAuthError(operation, body) {
|
|
|
1523
1687
|
if (typeof body === "object" && body !== null) {
|
|
1524
1688
|
const errBody = body;
|
|
1525
1689
|
const code = typeof errBody.code === "string" ? errBody.code : "";
|
|
1526
|
-
if (code === "OTP_EXPIRED") return Errors
|
|
1527
|
-
if (code === "INVALID_OTP") return Errors
|
|
1528
|
-
if (code === "VALIDATION_ERROR" || code === "INVALID_EMAIL") return Errors
|
|
1690
|
+
if (code === "OTP_EXPIRED") return Errors.otpExpired();
|
|
1691
|
+
if (code === "INVALID_OTP") return Errors.invalidInput("otp", errBody.message ?? "invalid OTP");
|
|
1692
|
+
if (code === "VALIDATION_ERROR" || code === "INVALID_EMAIL") return Errors.invalidInput("email", errBody.message ?? "invalid email");
|
|
1529
1693
|
}
|
|
1530
|
-
return Errors
|
|
1694
|
+
return Errors.providerError("better-auth", operation, new Error(String(body)));
|
|
1531
1695
|
}
|
|
1532
1696
|
function isAbortError$1(err, signal) {
|
|
1533
1697
|
return signal?.aborted === true || err instanceof Error && err.name === "AbortError" || typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError";
|
|
1534
1698
|
}
|
|
1535
1699
|
function mapFetchError$1(operation, err, signal) {
|
|
1536
|
-
if (isAbortError$1(err, signal)) return Errors
|
|
1537
|
-
return Errors
|
|
1700
|
+
if (isAbortError$1(err, signal)) return Errors.cancelled({ operation });
|
|
1701
|
+
return Errors.networkError(operation, err instanceof Error ? err : new Error(String(err)));
|
|
1538
1702
|
}
|
|
1539
1703
|
var BetterAuthBrowserAdapter = class {
|
|
1540
1704
|
authBaseUrl;
|
|
@@ -1549,7 +1713,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1549
1713
|
async canSendOtp(_input, options) {
|
|
1550
1714
|
if (options?.signal?.aborted) return {
|
|
1551
1715
|
ok: false,
|
|
1552
|
-
error: Errors
|
|
1716
|
+
error: Errors.cancelled({ operation: "canSendOtp" })
|
|
1553
1717
|
};
|
|
1554
1718
|
return {
|
|
1555
1719
|
ok: true,
|
|
@@ -1562,7 +1726,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1562
1726
|
async sendOtp(input, options) {
|
|
1563
1727
|
if (options?.signal?.aborted) return {
|
|
1564
1728
|
ok: false,
|
|
1565
|
-
error: Errors
|
|
1729
|
+
error: Errors.cancelled({ operation: "sendOtp" })
|
|
1566
1730
|
};
|
|
1567
1731
|
try {
|
|
1568
1732
|
const res = await this.fetchImpl(this.url("/api/auth/email-otp/send-verification-otp"), withSignal$1({
|
|
@@ -1576,7 +1740,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1576
1740
|
}, options?.signal));
|
|
1577
1741
|
if (options?.signal?.aborted) return {
|
|
1578
1742
|
ok: false,
|
|
1579
|
-
error: Errors
|
|
1743
|
+
error: Errors.cancelled({ operation: "sendOtp" })
|
|
1580
1744
|
};
|
|
1581
1745
|
if (res.ok) return {
|
|
1582
1746
|
ok: true,
|
|
@@ -1584,19 +1748,19 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1584
1748
|
};
|
|
1585
1749
|
if (res.status === 429) return {
|
|
1586
1750
|
ok: false,
|
|
1587
|
-
error: Errors
|
|
1751
|
+
error: Errors.rateLimited({ resource: "better-auth/sendOtp" })
|
|
1588
1752
|
};
|
|
1589
1753
|
const body = await safeJson$1(res);
|
|
1590
1754
|
if (typeof body === "object" && body !== null) {
|
|
1591
1755
|
const errBody = body;
|
|
1592
1756
|
if (errBody.code === "INVALID_EMAIL" || errBody.code === "VALIDATION_ERROR") return {
|
|
1593
1757
|
ok: false,
|
|
1594
|
-
error: Errors
|
|
1758
|
+
error: Errors.invalidInput("email", errBody.message ?? "invalid email")
|
|
1595
1759
|
};
|
|
1596
1760
|
}
|
|
1597
1761
|
return {
|
|
1598
1762
|
ok: false,
|
|
1599
|
-
error: Errors
|
|
1763
|
+
error: Errors.providerError("better-auth", "sendOtp", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
1600
1764
|
};
|
|
1601
1765
|
} catch (err) {
|
|
1602
1766
|
return {
|
|
@@ -1608,7 +1772,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1608
1772
|
async verifyOtp(input, options) {
|
|
1609
1773
|
if (options?.signal?.aborted) return {
|
|
1610
1774
|
ok: false,
|
|
1611
|
-
error: Errors
|
|
1775
|
+
error: Errors.cancelled({ operation: "verifyOtp" })
|
|
1612
1776
|
};
|
|
1613
1777
|
try {
|
|
1614
1778
|
const res = await this.fetchImpl(this.url("/api/auth/sign-in/email-otp"), withSignal$1({
|
|
@@ -1622,7 +1786,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1622
1786
|
}, options?.signal));
|
|
1623
1787
|
if (options?.signal?.aborted) return {
|
|
1624
1788
|
ok: false,
|
|
1625
|
-
error: Errors
|
|
1789
|
+
error: Errors.cancelled({ operation: "verifyOtp" })
|
|
1626
1790
|
};
|
|
1627
1791
|
const body = await safeJson$1(res);
|
|
1628
1792
|
if (res.ok) {
|
|
@@ -1635,7 +1799,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1635
1799
|
}
|
|
1636
1800
|
return {
|
|
1637
1801
|
ok: false,
|
|
1638
|
-
error: Errors
|
|
1802
|
+
error: Errors.providerError("better-auth", "verifyOtp", /* @__PURE__ */ new Error("unexpected 200 body"))
|
|
1639
1803
|
};
|
|
1640
1804
|
}
|
|
1641
1805
|
return {
|
|
@@ -1652,7 +1816,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1652
1816
|
async getSession(options) {
|
|
1653
1817
|
if (options?.signal?.aborted) return {
|
|
1654
1818
|
ok: false,
|
|
1655
|
-
error: Errors
|
|
1819
|
+
error: Errors.cancelled({ operation: "getSession" })
|
|
1656
1820
|
};
|
|
1657
1821
|
try {
|
|
1658
1822
|
const res = await this.fetchImpl(this.url("/api/auth/get-session"), withSignal$1({
|
|
@@ -1661,11 +1825,11 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1661
1825
|
}, options?.signal));
|
|
1662
1826
|
if (options?.signal?.aborted) return {
|
|
1663
1827
|
ok: false,
|
|
1664
|
-
error: Errors
|
|
1828
|
+
error: Errors.cancelled({ operation: "getSession" })
|
|
1665
1829
|
};
|
|
1666
1830
|
if (!res.ok) return {
|
|
1667
1831
|
ok: false,
|
|
1668
|
-
error: Errors
|
|
1832
|
+
error: Errors.providerError("better-auth", "getSession", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
1669
1833
|
};
|
|
1670
1834
|
const body = await safeJson$1(res);
|
|
1671
1835
|
if (body === null) return {
|
|
@@ -1693,7 +1857,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1693
1857
|
async signOut(options) {
|
|
1694
1858
|
if (options?.signal?.aborted) return {
|
|
1695
1859
|
ok: false,
|
|
1696
|
-
error: Errors
|
|
1860
|
+
error: Errors.cancelled({ operation: "signOut" })
|
|
1697
1861
|
};
|
|
1698
1862
|
try {
|
|
1699
1863
|
const res = await this.fetchImpl(this.url("/api/auth/sign-out"), withSignal$1({
|
|
@@ -1704,7 +1868,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1704
1868
|
}, options?.signal));
|
|
1705
1869
|
if (options?.signal?.aborted) return {
|
|
1706
1870
|
ok: false,
|
|
1707
|
-
error: Errors
|
|
1871
|
+
error: Errors.cancelled({ operation: "signOut" })
|
|
1708
1872
|
};
|
|
1709
1873
|
if (res.ok) return {
|
|
1710
1874
|
ok: true,
|
|
@@ -1712,7 +1876,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1712
1876
|
};
|
|
1713
1877
|
return {
|
|
1714
1878
|
ok: false,
|
|
1715
|
-
error: Errors
|
|
1879
|
+
error: Errors.providerError("better-auth", "signOut", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
1716
1880
|
};
|
|
1717
1881
|
} catch (err) {
|
|
1718
1882
|
return {
|
|
@@ -1724,7 +1888,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1724
1888
|
async getConvexJwt(options) {
|
|
1725
1889
|
if (options?.signal?.aborted) return {
|
|
1726
1890
|
ok: false,
|
|
1727
|
-
error: Errors
|
|
1891
|
+
error: Errors.cancelled({ operation: "getConvexJwt" })
|
|
1728
1892
|
};
|
|
1729
1893
|
try {
|
|
1730
1894
|
const res = await this.fetchImpl(this.url("/api/auth/convex/token"), withSignal$1({
|
|
@@ -1733,15 +1897,15 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1733
1897
|
}, options?.signal));
|
|
1734
1898
|
if (options?.signal?.aborted) return {
|
|
1735
1899
|
ok: false,
|
|
1736
|
-
error: Errors
|
|
1900
|
+
error: Errors.cancelled({ operation: "getConvexJwt" })
|
|
1737
1901
|
};
|
|
1738
1902
|
if (res.status === 401) return {
|
|
1739
1903
|
ok: false,
|
|
1740
|
-
error: Errors
|
|
1904
|
+
error: Errors.notAuthenticated()
|
|
1741
1905
|
};
|
|
1742
1906
|
if (!res.ok) return {
|
|
1743
1907
|
ok: false,
|
|
1744
|
-
error: Errors
|
|
1908
|
+
error: Errors.providerError("better-auth", "getConvexJwt", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
1745
1909
|
};
|
|
1746
1910
|
const body = await safeJson$1(res);
|
|
1747
1911
|
if (typeof body === "object" && body !== null) {
|
|
@@ -1756,7 +1920,7 @@ var BetterAuthBrowserAdapter = class {
|
|
|
1756
1920
|
}
|
|
1757
1921
|
return {
|
|
1758
1922
|
ok: false,
|
|
1759
|
-
error: Errors
|
|
1923
|
+
error: Errors.providerError("better-auth", "getConvexJwt", /* @__PURE__ */ new Error("unexpected body"))
|
|
1760
1924
|
};
|
|
1761
1925
|
} catch (err) {
|
|
1762
1926
|
return {
|
|
@@ -1932,8 +2096,8 @@ function isAbortError(err, signal) {
|
|
|
1932
2096
|
return signal?.aborted === true || err instanceof Error && err.name === "AbortError" || typeof DOMException !== "undefined" && err instanceof DOMException && err.name === "AbortError";
|
|
1933
2097
|
}
|
|
1934
2098
|
function mapFetchError(operation, err, signal) {
|
|
1935
|
-
if (isAbortError(err, signal)) return Errors
|
|
1936
|
-
return Errors
|
|
2099
|
+
if (isAbortError(err, signal)) return Errors.cancelled({ operation });
|
|
2100
|
+
return Errors.networkError(operation, err instanceof Error ? err : new Error(String(err)));
|
|
1937
2101
|
}
|
|
1938
2102
|
var BetterAuthNodeAdapter = class {
|
|
1939
2103
|
authBaseUrl;
|
|
@@ -1961,7 +2125,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
1961
2125
|
async canSendOtp(_input, options) {
|
|
1962
2126
|
if (options?.signal?.aborted) return {
|
|
1963
2127
|
ok: false,
|
|
1964
|
-
error: Errors
|
|
2128
|
+
error: Errors.cancelled({ operation: "canSendOtp" })
|
|
1965
2129
|
};
|
|
1966
2130
|
return {
|
|
1967
2131
|
ok: true,
|
|
@@ -1974,7 +2138,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
1974
2138
|
async sendOtp(input, options) {
|
|
1975
2139
|
if (options?.signal?.aborted) return {
|
|
1976
2140
|
ok: false,
|
|
1977
|
-
error: Errors
|
|
2141
|
+
error: Errors.cancelled({ operation: "sendOtp" })
|
|
1978
2142
|
};
|
|
1979
2143
|
try {
|
|
1980
2144
|
const res = await this.fetchImpl(this.url("/api/auth/email-otp/send-verification-otp"), withSignal({
|
|
@@ -1990,7 +2154,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
1990
2154
|
}, options?.signal));
|
|
1991
2155
|
if (options?.signal?.aborted) return {
|
|
1992
2156
|
ok: false,
|
|
1993
|
-
error: Errors
|
|
2157
|
+
error: Errors.cancelled({ operation: "sendOtp" })
|
|
1994
2158
|
};
|
|
1995
2159
|
if (res.ok) return {
|
|
1996
2160
|
ok: true,
|
|
@@ -1998,19 +2162,19 @@ var BetterAuthNodeAdapter = class {
|
|
|
1998
2162
|
};
|
|
1999
2163
|
if (res.status === 429) return {
|
|
2000
2164
|
ok: false,
|
|
2001
|
-
error: Errors
|
|
2165
|
+
error: Errors.rateLimited({ resource: "better-auth/sendOtp" })
|
|
2002
2166
|
};
|
|
2003
2167
|
const body = await safeJson(res);
|
|
2004
2168
|
if (typeof body === "object" && body !== null) {
|
|
2005
2169
|
const errBody = body;
|
|
2006
2170
|
if (errBody.code === "INVALID_EMAIL" || errBody.code === "VALIDATION_ERROR") return {
|
|
2007
2171
|
ok: false,
|
|
2008
|
-
error: Errors
|
|
2172
|
+
error: Errors.invalidInput("email", errBody.message ?? "invalid email")
|
|
2009
2173
|
};
|
|
2010
2174
|
}
|
|
2011
2175
|
return {
|
|
2012
2176
|
ok: false,
|
|
2013
|
-
error: Errors
|
|
2177
|
+
error: Errors.providerError("better-auth", "sendOtp", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
2014
2178
|
};
|
|
2015
2179
|
} catch (err) {
|
|
2016
2180
|
return {
|
|
@@ -2022,7 +2186,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2022
2186
|
async verifyOtp(input, options) {
|
|
2023
2187
|
if (options?.signal?.aborted) return {
|
|
2024
2188
|
ok: false,
|
|
2025
|
-
error: Errors
|
|
2189
|
+
error: Errors.cancelled({ operation: "verifyOtp" })
|
|
2026
2190
|
};
|
|
2027
2191
|
try {
|
|
2028
2192
|
const res = await this.fetchImpl(this.url("/api/auth/sign-in/email-otp"), withSignal({
|
|
@@ -2038,7 +2202,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2038
2202
|
}, options?.signal));
|
|
2039
2203
|
if (options?.signal?.aborted) return {
|
|
2040
2204
|
ok: false,
|
|
2041
|
-
error: Errors
|
|
2205
|
+
error: Errors.cancelled({ operation: "verifyOtp" })
|
|
2042
2206
|
};
|
|
2043
2207
|
setCookiesFromResponse(this.cookieJar, this.host, res);
|
|
2044
2208
|
const body = await safeJson(res);
|
|
@@ -2054,17 +2218,17 @@ var BetterAuthNodeAdapter = class {
|
|
|
2054
2218
|
const errBody = body;
|
|
2055
2219
|
if (errBody.code === "OTP_EXPIRED") return {
|
|
2056
2220
|
ok: false,
|
|
2057
|
-
error: Errors
|
|
2221
|
+
error: Errors.otpExpired()
|
|
2058
2222
|
};
|
|
2059
2223
|
if (errBody.code === "INVALID_OTP") return {
|
|
2060
2224
|
ok: false,
|
|
2061
|
-
error: Errors
|
|
2225
|
+
error: Errors.invalidInput("otp", errBody.message ?? "invalid OTP")
|
|
2062
2226
|
};
|
|
2063
2227
|
}
|
|
2064
2228
|
}
|
|
2065
2229
|
return {
|
|
2066
2230
|
ok: false,
|
|
2067
|
-
error: Errors
|
|
2231
|
+
error: Errors.providerError("better-auth", "verifyOtp", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
2068
2232
|
};
|
|
2069
2233
|
} catch (err) {
|
|
2070
2234
|
return {
|
|
@@ -2076,7 +2240,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2076
2240
|
async getSession(options) {
|
|
2077
2241
|
if (options?.signal?.aborted) return {
|
|
2078
2242
|
ok: false,
|
|
2079
|
-
error: Errors
|
|
2243
|
+
error: Errors.cancelled({ operation: "getSession" })
|
|
2080
2244
|
};
|
|
2081
2245
|
try {
|
|
2082
2246
|
const res = await this.fetchImpl(this.url("/api/auth/get-session"), withSignal({
|
|
@@ -2085,11 +2249,11 @@ var BetterAuthNodeAdapter = class {
|
|
|
2085
2249
|
}, options?.signal));
|
|
2086
2250
|
if (options?.signal?.aborted) return {
|
|
2087
2251
|
ok: false,
|
|
2088
|
-
error: Errors
|
|
2252
|
+
error: Errors.cancelled({ operation: "getSession" })
|
|
2089
2253
|
};
|
|
2090
2254
|
if (!res.ok) return {
|
|
2091
2255
|
ok: false,
|
|
2092
|
-
error: Errors
|
|
2256
|
+
error: Errors.providerError("better-auth", "getSession", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
2093
2257
|
};
|
|
2094
2258
|
const body = await safeJson(res);
|
|
2095
2259
|
if (body === null) return {
|
|
@@ -2117,7 +2281,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2117
2281
|
async signOut(options) {
|
|
2118
2282
|
if (options?.signal?.aborted) return {
|
|
2119
2283
|
ok: false,
|
|
2120
|
-
error: Errors
|
|
2284
|
+
error: Errors.cancelled({ operation: "signOut" })
|
|
2121
2285
|
};
|
|
2122
2286
|
try {
|
|
2123
2287
|
const signOutOrigin = originFromBaseUrl(this.authBaseUrl) ?? this.origin;
|
|
@@ -2131,7 +2295,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2131
2295
|
}, options?.signal));
|
|
2132
2296
|
if (options?.signal?.aborted) return {
|
|
2133
2297
|
ok: false,
|
|
2134
|
-
error: Errors
|
|
2298
|
+
error: Errors.cancelled({ operation: "signOut" })
|
|
2135
2299
|
};
|
|
2136
2300
|
setCookiesFromResponse(this.cookieJar, this.host, res);
|
|
2137
2301
|
if (res.ok) return {
|
|
@@ -2140,7 +2304,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2140
2304
|
};
|
|
2141
2305
|
return {
|
|
2142
2306
|
ok: false,
|
|
2143
|
-
error: Errors
|
|
2307
|
+
error: Errors.providerError("better-auth", "signOut", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
2144
2308
|
};
|
|
2145
2309
|
} catch (err) {
|
|
2146
2310
|
return {
|
|
@@ -2152,7 +2316,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2152
2316
|
async getConvexJwt(options) {
|
|
2153
2317
|
if (options?.signal?.aborted) return {
|
|
2154
2318
|
ok: false,
|
|
2155
|
-
error: Errors
|
|
2319
|
+
error: Errors.cancelled({ operation: "getConvexJwt" })
|
|
2156
2320
|
};
|
|
2157
2321
|
try {
|
|
2158
2322
|
const res = await this.fetchImpl(this.url("/api/auth/convex/token"), withSignal({
|
|
@@ -2161,15 +2325,15 @@ var BetterAuthNodeAdapter = class {
|
|
|
2161
2325
|
}, options?.signal));
|
|
2162
2326
|
if (options?.signal?.aborted) return {
|
|
2163
2327
|
ok: false,
|
|
2164
|
-
error: Errors
|
|
2328
|
+
error: Errors.cancelled({ operation: "getConvexJwt" })
|
|
2165
2329
|
};
|
|
2166
2330
|
if (res.status === 401) return {
|
|
2167
2331
|
ok: false,
|
|
2168
|
-
error: Errors
|
|
2332
|
+
error: Errors.notAuthenticated()
|
|
2169
2333
|
};
|
|
2170
2334
|
if (!res.ok) return {
|
|
2171
2335
|
ok: false,
|
|
2172
|
-
error: Errors
|
|
2336
|
+
error: Errors.providerError("better-auth", "getConvexJwt", /* @__PURE__ */ new Error(`HTTP ${res.status}`))
|
|
2173
2337
|
};
|
|
2174
2338
|
const body = await safeJson(res);
|
|
2175
2339
|
if (typeof body === "object" && body !== null) {
|
|
@@ -2184,7 +2348,7 @@ var BetterAuthNodeAdapter = class {
|
|
|
2184
2348
|
}
|
|
2185
2349
|
return {
|
|
2186
2350
|
ok: false,
|
|
2187
|
-
error: Errors
|
|
2351
|
+
error: Errors.providerError("better-auth", "getConvexJwt", /* @__PURE__ */ new Error("unexpected body"))
|
|
2188
2352
|
};
|
|
2189
2353
|
} catch (err) {
|
|
2190
2354
|
return {
|
|
@@ -2198,6 +2362,377 @@ function BetterAuthNodeLayer(deps) {
|
|
|
2198
2362
|
return Layer.succeed(AuthClientPortTag, authClientPortFromPromiseAdapter(new BetterAuthNodeAdapter(deps)));
|
|
2199
2363
|
}
|
|
2200
2364
|
//#endregion
|
|
2365
|
+
//#region ../wire/src/brands.ts
|
|
2366
|
+
/**
|
|
2367
|
+
* `AppId` schema. Mirrors `toAppId` from `@capxul/types`:
|
|
2368
|
+
* `app_` + Crockford-base32 ULID (26 chars, first char in `[0-7]`).
|
|
2369
|
+
*/
|
|
2370
|
+
const AppIdSchema$1 = Schema.String.pipe(Schema.filter((s) => APP_ID_RE.test(s), { message: () => "must be app_ plus a ULID" }));
|
|
2371
|
+
/**
|
|
2372
|
+
* `ChainId` schema. Mirrors `toChainId`: positive safe integer.
|
|
2373
|
+
*/
|
|
2374
|
+
const ChainIdSchema$1 = Schema.Number.pipe(Schema.filter((n) => Number.isSafeInteger(n) && n > 0, { message: () => "must be a positive safe integer" }));
|
|
2375
|
+
/**
|
|
2376
|
+
* `CurrencyCode` schema. Mirrors `toCurrencyCode`: currently supported
|
|
2377
|
+
* consumer-facing ISO-ish currency code set.
|
|
2378
|
+
*/
|
|
2379
|
+
const CurrencyCodeSchema$1 = Schema.String.pipe(Schema.filter((s) => SUPPORTED_CURRENCY_CODES.includes(s), { message: () => "must be a supported currency code" }));
|
|
2380
|
+
const DOCUMENT_HASH_HEX_RE = /^[0-9a-fA-F]{64}$/;
|
|
2381
|
+
/**
|
|
2382
|
+
* `DocumentHash` schema. Mirrors `toDocumentHash`: bare or 0x-prefixed bytes32,
|
|
2383
|
+
* normalized to lowercase 0x-prefixed form.
|
|
2384
|
+
*/
|
|
2385
|
+
const DocumentHashSchema$1 = Schema.String.pipe(Schema.transform(Schema.String, {
|
|
2386
|
+
decode: (s) => {
|
|
2387
|
+
const stripped = s.startsWith("0x") || s.startsWith("0X") ? s.slice(2) : s;
|
|
2388
|
+
return DOCUMENT_HASH_HEX_RE.test(stripped) ? `0x${stripped.toLowerCase()}` : s;
|
|
2389
|
+
},
|
|
2390
|
+
encode: (s) => s
|
|
2391
|
+
}), Schema.filter((s) => BYTES32_RE.test(s), { message: () => "must be 32 bytes of hex" }));
|
|
2392
|
+
/**
|
|
2393
|
+
* `SessionToken` schema. Mirrors `toSessionToken`: non-empty string.
|
|
2394
|
+
* Issuance source distinguishes SDK-handshake tokens from auth-session
|
|
2395
|
+
* tokens; the brand itself is opaque.
|
|
2396
|
+
*/
|
|
2397
|
+
const SessionTokenSchema = Schema.String.pipe(Schema.filter((s) => s.length > 0, { message: () => "must be a non-empty string" }));
|
|
2398
|
+
/**
|
|
2399
|
+
* `EpochMs` schema. Mirrors `toEpochMs`: non-negative safe integer.
|
|
2400
|
+
*/
|
|
2401
|
+
const EpochMsSchema$1 = Schema.Number.pipe(Schema.filter((n) => Number.isSafeInteger(n) && n >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
2402
|
+
/**
|
|
2403
|
+
* `DurationMs` schema. Mirrors `toDurationMs`: non-negative safe integer.
|
|
2404
|
+
*/
|
|
2405
|
+
const DurationMsSchema$1 = Schema.Number.pipe(Schema.filter((n) => Number.isSafeInteger(n) && n >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
2406
|
+
//#endregion
|
|
2407
|
+
//#region ../wire/src/bootstrap.ts
|
|
2408
|
+
/**
|
|
2409
|
+
* `BootstrapEnvelope` v1.
|
|
2410
|
+
*
|
|
2411
|
+
* - `protocol`: discriminator that lets future protocols coexist on the
|
|
2412
|
+
* same endpoint without a wire-shape conflict.
|
|
2413
|
+
* - `version`: numeric version inside the protocol. Unknown versions MUST
|
|
2414
|
+
* fail decode with an INVALID_INPUT-class `CapxulError` at the SDK seam.
|
|
2415
|
+
* - `state`: the resolved bootstrap payload. Field shape matches the
|
|
2416
|
+
* `BootstrapResolution` port; the SDK consumer can pass `state`
|
|
2417
|
+
* directly (after `normalizeRuntimeUrl` on the two URL fields) into
|
|
2418
|
+
* the port without re-branding.
|
|
2419
|
+
*/
|
|
2420
|
+
const BootstrapEnvelope = Schema.Struct({
|
|
2421
|
+
protocol: Schema.Literal("capxul.bootstrap"),
|
|
2422
|
+
version: Schema.Literal(1),
|
|
2423
|
+
state: Schema.Struct({
|
|
2424
|
+
applicationId: AppIdSchema$1,
|
|
2425
|
+
chainId: ChainIdSchema$1,
|
|
2426
|
+
sessionToken: SessionTokenSchema,
|
|
2427
|
+
issuedAt: EpochMsSchema$1,
|
|
2428
|
+
expiresIn: DurationMsSchema$1,
|
|
2429
|
+
authBaseUrl: Schema.String,
|
|
2430
|
+
convexUrl: Schema.String,
|
|
2431
|
+
siteBaseUrl: Schema.String,
|
|
2432
|
+
openfortPublishableKey: Schema.String,
|
|
2433
|
+
shieldPublishableKey: Schema.String
|
|
2434
|
+
})
|
|
2435
|
+
});
|
|
2436
|
+
//#endregion
|
|
2437
|
+
//#region ../wire/src/financial-ops.ts
|
|
2438
|
+
const MINOR_UNIT_STRING_RE = /^[0-9]+$/;
|
|
2439
|
+
const DECIMAL_STRING_RE = /^[0-9]+(?:\.[0-9]+)?$/;
|
|
2440
|
+
const EVM_ADDRESS_RE = /^0x[a-fA-F0-9]{40}$/;
|
|
2441
|
+
/**
|
|
2442
|
+
* The canonical on-chain domain anchor for the v1 payment-document EIP-712
|
|
2443
|
+
* `domain` (payment-document-spec.md v1). The `PaymentDocumentDomain` schema
|
|
2444
|
+
* validates against this exact literal, and the backend's receipt builder mints
|
|
2445
|
+
* envelopes carrying it — so it MUST stay byte-identical across both. Exported
|
|
2446
|
+
* once here to remove the drift risk of a mirrored declaration.
|
|
2447
|
+
*/
|
|
2448
|
+
const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "0xe740ea65521edc9bef0ea75d30b5334711db99f4";
|
|
2449
|
+
const PAYMENT_ID_RE = /^payment_[0-9A-Za-z]+$/;
|
|
2450
|
+
const PAYEE_ID_RE = /^payee_[0-9A-Za-z]+$/;
|
|
2451
|
+
const ORG_ID_RE = /^org_[0-9A-Za-z]+$/;
|
|
2452
|
+
const USER_ID_RE = /^user_[0-9A-Za-z]+$/;
|
|
2453
|
+
const HANDLE_RE = /^@?[a-z0-9][a-z0-9-]{2,31}$/;
|
|
2454
|
+
const ORG_HANDLE_RE = /^[a-z0-9][a-z0-9-]{2,31}$/;
|
|
2455
|
+
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
2456
|
+
const MinorUnitStringSchema = Schema.String.pipe(Schema.filter((value) => MINOR_UNIT_STRING_RE.test(value), { message: () => "must be a non-negative integer minor-unit string" }));
|
|
2457
|
+
const PaymentIdSchema = Schema.String.pipe(Schema.filter((value) => PAYMENT_ID_RE.test(value), { message: () => "must be payment_ plus an alphanumeric id" }));
|
|
2458
|
+
const PayeeIdSchema = Schema.String.pipe(Schema.filter((value) => PAYEE_ID_RE.test(value), { message: () => "must be payee_ plus an alphanumeric id" }));
|
|
2459
|
+
const OrgIdSchema = Schema.String.pipe(Schema.filter((value) => ORG_ID_RE.test(value), { message: () => "must be org_ plus an alphanumeric id" }));
|
|
2460
|
+
const UserIdSchema = Schema.String.pipe(Schema.filter((value) => USER_ID_RE.test(value), { message: () => "must be user_ plus an alphanumeric id" }));
|
|
2461
|
+
const DecimalStringSchema = Schema.String.pipe(Schema.filter((value) => DECIMAL_STRING_RE.test(value), { message: () => "must be a non-negative decimal string" }));
|
|
2462
|
+
const HandleValueSchema = Schema.String.pipe(Schema.filter((value) => !EVM_ADDRESS_RE.test(value) && HANDLE_RE.test(value), { message: () => "must be a handle; raw addresses are not accepted" }));
|
|
2463
|
+
const OrgHandleValueSchema = Schema.String.pipe(Schema.filter((value) => !EVM_ADDRESS_RE.test(value) && ORG_HANDLE_RE.test(value), { message: () => "must be an org handle; raw addresses are not accepted" }));
|
|
2464
|
+
const EmailValueSchema = Schema.String.pipe(Schema.filter((value) => !EVM_ADDRESS_RE.test(value) && EMAIL_RE.test(value), { message: () => "must be an email; raw addresses are not accepted" }));
|
|
2465
|
+
const Uint8Schema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0 && value <= 255, { message: () => "must be a uint8" }));
|
|
2466
|
+
const Uint64Schema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
2467
|
+
const PaymentDocumentDomain = Schema.Struct({
|
|
2468
|
+
name: Schema.Literal("CapxulPayments"),
|
|
2469
|
+
version: Schema.Literal("1"),
|
|
2470
|
+
chainId: ChainIdSchema$1,
|
|
2471
|
+
verifyingContract: Schema.Literal(PAYMENT_DOCUMENT_VERIFYING_CONTRACT)
|
|
2472
|
+
});
|
|
2473
|
+
const MemoDocument = Schema.Struct({
|
|
2474
|
+
kind: Schema.Literal(0),
|
|
2475
|
+
reference: Schema.String,
|
|
2476
|
+
note: Schema.String,
|
|
2477
|
+
issuedAt: Uint64Schema
|
|
2478
|
+
});
|
|
2479
|
+
const InvoiceDocument = Schema.Struct({
|
|
2480
|
+
kind: Schema.Literal(1),
|
|
2481
|
+
invoiceNumber: Schema.String,
|
|
2482
|
+
payerRef: Schema.String,
|
|
2483
|
+
payeeRef: Schema.String,
|
|
2484
|
+
amount: MinorUnitStringSchema,
|
|
2485
|
+
currency: CurrencyCodeSchema$1,
|
|
2486
|
+
decimals: Uint8Schema,
|
|
2487
|
+
issuedAt: Uint64Schema,
|
|
2488
|
+
dueAt: Uint64Schema,
|
|
2489
|
+
lineItemsHash: DocumentHashSchema$1
|
|
2490
|
+
});
|
|
2491
|
+
const PayslipDocument = Schema.Struct({
|
|
2492
|
+
kind: Schema.Literal(2),
|
|
2493
|
+
employerRef: Schema.String,
|
|
2494
|
+
employeeRef: Schema.String,
|
|
2495
|
+
period: Schema.String,
|
|
2496
|
+
gross: MinorUnitStringSchema,
|
|
2497
|
+
net: MinorUnitStringSchema,
|
|
2498
|
+
currency: CurrencyCodeSchema$1,
|
|
2499
|
+
decimals: Uint8Schema,
|
|
2500
|
+
issuedAt: Uint64Schema
|
|
2501
|
+
});
|
|
2502
|
+
const ReceiptDocument = Schema.Struct({
|
|
2503
|
+
kind: Schema.Literal(3),
|
|
2504
|
+
reference: Schema.String,
|
|
2505
|
+
amount: MinorUnitStringSchema,
|
|
2506
|
+
currency: CurrencyCodeSchema$1,
|
|
2507
|
+
decimals: Uint8Schema,
|
|
2508
|
+
paidAt: Uint64Schema,
|
|
2509
|
+
note: Schema.String
|
|
2510
|
+
});
|
|
2511
|
+
const WithdrawalDestAddressSchema = Schema.String.pipe(Schema.filter((value) => EVM_ADDRESS_RE.test(value), { message: () => "must be a 0x EVM address" }));
|
|
2512
|
+
const WithdrawalDocument = Schema.Struct({
|
|
2513
|
+
kind: Schema.Literal(4),
|
|
2514
|
+
reference: Schema.String,
|
|
2515
|
+
amount: MinorUnitStringSchema,
|
|
2516
|
+
currency: CurrencyCodeSchema$1,
|
|
2517
|
+
decimals: Uint8Schema,
|
|
2518
|
+
destChain: ChainIdSchema$1,
|
|
2519
|
+
destAddress: WithdrawalDestAddressSchema,
|
|
2520
|
+
settledAt: Uint64Schema,
|
|
2521
|
+
provider: Schema.String,
|
|
2522
|
+
note: Schema.String
|
|
2523
|
+
});
|
|
2524
|
+
const FinancialOpsMoney = Schema.Struct({
|
|
2525
|
+
currency: CurrencyCodeSchema$1,
|
|
2526
|
+
value: DecimalStringSchema,
|
|
2527
|
+
decimals: Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }))
|
|
2528
|
+
});
|
|
2529
|
+
const PaymentDocument = Schema.Struct({
|
|
2530
|
+
documentHash: DocumentHashSchema$1,
|
|
2531
|
+
kind: Schema.Literal("invoice", "receipt", "payslip", "memo", "withdrawal"),
|
|
2532
|
+
title: Schema.optional(Schema.String),
|
|
2533
|
+
uri: Schema.optional(Schema.String),
|
|
2534
|
+
issuedAt: Schema.optional(EpochMsSchema$1)
|
|
2535
|
+
});
|
|
2536
|
+
const PaymentType = Schema.Literal("unspecified", "invoice", "payroll", "reimbursement");
|
|
2537
|
+
function paymentTypeForDocumentKind(kind) {
|
|
2538
|
+
switch (kind) {
|
|
2539
|
+
case "memo": return "unspecified";
|
|
2540
|
+
case "invoice": return "invoice";
|
|
2541
|
+
case "payslip": return "payroll";
|
|
2542
|
+
case "receipt": return "reimbursement";
|
|
2543
|
+
case "withdrawal": return "unspecified";
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
const AttachablePaymentDocumentEnvelope = Schema.Union(Schema.Struct({
|
|
2547
|
+
protocol: Schema.Literal("capxul.payment-document"),
|
|
2548
|
+
version: Schema.Literal(1),
|
|
2549
|
+
domain: PaymentDocumentDomain,
|
|
2550
|
+
primaryType: Schema.Literal("Memo"),
|
|
2551
|
+
message: MemoDocument
|
|
2552
|
+
}), Schema.Struct({
|
|
2553
|
+
protocol: Schema.Literal("capxul.payment-document"),
|
|
2554
|
+
version: Schema.Literal(1),
|
|
2555
|
+
domain: PaymentDocumentDomain,
|
|
2556
|
+
primaryType: Schema.Literal("Invoice"),
|
|
2557
|
+
message: InvoiceDocument
|
|
2558
|
+
}), Schema.Struct({
|
|
2559
|
+
protocol: Schema.Literal("capxul.payment-document"),
|
|
2560
|
+
version: Schema.Literal(1),
|
|
2561
|
+
domain: PaymentDocumentDomain,
|
|
2562
|
+
primaryType: Schema.Literal("Payslip"),
|
|
2563
|
+
message: PayslipDocument
|
|
2564
|
+
}), Schema.Struct({
|
|
2565
|
+
protocol: Schema.Literal("capxul.payment-document"),
|
|
2566
|
+
version: Schema.Literal(1),
|
|
2567
|
+
domain: PaymentDocumentDomain,
|
|
2568
|
+
primaryType: Schema.Literal("Receipt"),
|
|
2569
|
+
message: ReceiptDocument
|
|
2570
|
+
}));
|
|
2571
|
+
const WithdrawalDocumentEnvelope = Schema.Struct({
|
|
2572
|
+
protocol: Schema.Literal("capxul.payment-document"),
|
|
2573
|
+
version: Schema.Literal(1),
|
|
2574
|
+
domain: PaymentDocumentDomain,
|
|
2575
|
+
primaryType: Schema.Literal("Withdrawal"),
|
|
2576
|
+
message: WithdrawalDocument
|
|
2577
|
+
});
|
|
2578
|
+
Schema.Union(AttachablePaymentDocumentEnvelope, WithdrawalDocumentEnvelope);
|
|
2579
|
+
Schema.Struct({
|
|
2580
|
+
payeeId: PayeeIdSchema,
|
|
2581
|
+
label: Schema.String,
|
|
2582
|
+
trustState: Schema.Literal("unverified", "trusted", "blocked"),
|
|
2583
|
+
destinationKind: Schema.Literal("handle", "email", "saved-payee", "org")
|
|
2584
|
+
});
|
|
2585
|
+
const PaymentRecipient = Schema.Struct({
|
|
2586
|
+
kind: Schema.Literal("handle", "email", "payee", "capxulUserId", "me", "org", "external_address"),
|
|
2587
|
+
label: Schema.String,
|
|
2588
|
+
payeeId: Schema.optional(PayeeIdSchema)
|
|
2589
|
+
});
|
|
2590
|
+
/**
|
|
2591
|
+
* A raw external EVM address for the B3 withdraw lane — the cash-out
|
|
2592
|
+
* destination. This is the ONE schema that ACCEPTS a bare 0x (the withdraw
|
|
2593
|
+
* mutation args use it), as opposed to `PaymentRecipientRefSchema` which
|
|
2594
|
+
* REJECTS bare addresses to protect the pay lane. The full address never
|
|
2595
|
+
* crosses the model wire; it lives on the kind:4 Withdrawal document only.
|
|
2596
|
+
*/
|
|
2597
|
+
const ExternalAddressSchema = Schema.String.pipe(Schema.filter((value) => EVM_ADDRESS_RE.test(value), { message: () => "must be a 0x EVM address (40 hex chars)" }));
|
|
2598
|
+
const PaymentTiming = Schema.Union(Schema.Struct({ kind: Schema.Literal("instant") }), Schema.Struct({
|
|
2599
|
+
kind: Schema.Literal("scheduled"),
|
|
2600
|
+
at: EpochMsSchema$1
|
|
2601
|
+
}), Schema.Struct({
|
|
2602
|
+
kind: Schema.Literal("stream"),
|
|
2603
|
+
startsAt: EpochMsSchema$1,
|
|
2604
|
+
endsAt: EpochMsSchema$1,
|
|
2605
|
+
cliffAt: Schema.optional(EpochMsSchema$1)
|
|
2606
|
+
}));
|
|
2607
|
+
const PaymentRef = Schema.Union(Schema.Struct({
|
|
2608
|
+
kind: Schema.Literal("handle"),
|
|
2609
|
+
handle: HandleValueSchema
|
|
2610
|
+
}), Schema.Struct({
|
|
2611
|
+
kind: Schema.Literal("email"),
|
|
2612
|
+
email: EmailValueSchema
|
|
2613
|
+
}), Schema.Struct({
|
|
2614
|
+
kind: Schema.Literal("orgHandle"),
|
|
2615
|
+
orgHandle: OrgHandleValueSchema
|
|
2616
|
+
}), Schema.Struct({
|
|
2617
|
+
kind: Schema.Literal("capxulUserId"),
|
|
2618
|
+
capxulUserId: UserIdSchema
|
|
2619
|
+
}), Schema.Struct({
|
|
2620
|
+
kind: Schema.Literal("payeeId"),
|
|
2621
|
+
payeeId: PayeeIdSchema
|
|
2622
|
+
}));
|
|
2623
|
+
const Payment = Schema.Struct({
|
|
2624
|
+
id: PaymentIdSchema,
|
|
2625
|
+
status: Schema.Literal("pending", "submitted", "pending_claim", "scheduled", "streaming", "settled", "cancelled", "redirected", "expired", "failed"),
|
|
2626
|
+
amount: FinancialOpsMoney,
|
|
2627
|
+
paymentType: PaymentType,
|
|
2628
|
+
recipient: PaymentRecipient,
|
|
2629
|
+
documents: Schema.Array(PaymentDocument),
|
|
2630
|
+
timing: PaymentTiming,
|
|
2631
|
+
released: FinancialOpsMoney,
|
|
2632
|
+
availableToClaim: FinancialOpsMoney,
|
|
2633
|
+
createdAt: EpochMsSchema$1,
|
|
2634
|
+
updatedAt: EpochMsSchema$1
|
|
2635
|
+
}).pipe(Schema.filter((payment) => payment.documents.every((document) => paymentTypeForDocumentKind(document.kind) === payment.paymentType), { message: () => "document kind must map to paymentType" }));
|
|
2636
|
+
const PaymentSource = Schema.Union(Schema.Struct({
|
|
2637
|
+
kind: Schema.Literal("me"),
|
|
2638
|
+
orgId: Schema.optional(Schema.Undefined)
|
|
2639
|
+
}), Schema.Struct({
|
|
2640
|
+
kind: Schema.Literal("org"),
|
|
2641
|
+
orgId: OrgIdSchema
|
|
2642
|
+
}));
|
|
2643
|
+
/**
|
|
2644
|
+
* #592 invoice line item. `quantity` is a positive integer; `unitMinor` is the
|
|
2645
|
+
* per-unit price in integer minor units. The list is canonically hashed by
|
|
2646
|
+
* `hashLineItems` (payment-document-hash.ts) into the Invoice `lineItemsHash`,
|
|
2647
|
+
* and Σ(quantity × unitMinor) MUST equal the invoice `amount`. The hash binds
|
|
2648
|
+
* the documentHash to the exact items; the sum-check makes the items add up to
|
|
2649
|
+
* the amount due. See the payment-document spec (canon/mcp/financial-ops.md).
|
|
2650
|
+
*/
|
|
2651
|
+
const LineItem = Schema.Struct({
|
|
2652
|
+
description: Schema.String,
|
|
2653
|
+
quantity: Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value > 0, { message: () => "quantity must be a positive integer" })),
|
|
2654
|
+
unitMinor: MinorUnitStringSchema
|
|
2655
|
+
});
|
|
2656
|
+
Schema.Struct({
|
|
2657
|
+
from: Schema.optional(PaymentSource),
|
|
2658
|
+
to: PaymentRef,
|
|
2659
|
+
amount: FinancialOpsMoney,
|
|
2660
|
+
timing: Schema.optional(PaymentTiming),
|
|
2661
|
+
document: Schema.optional(AttachablePaymentDocumentEnvelope),
|
|
2662
|
+
lineItems: Schema.optional(Schema.Array(LineItem))
|
|
2663
|
+
});
|
|
2664
|
+
Schema.Struct({
|
|
2665
|
+
to: ExternalAddressSchema,
|
|
2666
|
+
amount: FinancialOpsMoney,
|
|
2667
|
+
document: WithdrawalDocumentEnvelope
|
|
2668
|
+
});
|
|
2669
|
+
Schema.Struct({
|
|
2670
|
+
protocol: Schema.Literal("capxul.me"),
|
|
2671
|
+
version: Schema.Literal(1),
|
|
2672
|
+
me: Schema.Struct({
|
|
2673
|
+
displayName: Schema.NullOr(Schema.String),
|
|
2674
|
+
handle: Schema.NullOr(Schema.String),
|
|
2675
|
+
defaultCurrency: CurrencyCodeSchema$1,
|
|
2676
|
+
depositInstructions: Schema.Array(Schema.Struct({
|
|
2677
|
+
network: Schema.String,
|
|
2678
|
+
asset: CurrencyCodeSchema$1,
|
|
2679
|
+
depositTarget: Schema.String,
|
|
2680
|
+
memo: Schema.optional(Schema.String)
|
|
2681
|
+
}))
|
|
2682
|
+
})
|
|
2683
|
+
});
|
|
2684
|
+
Schema.Struct({
|
|
2685
|
+
protocol: Schema.Literal("capxul.payments"),
|
|
2686
|
+
version: Schema.Literal(1),
|
|
2687
|
+
payments: Schema.Array(Payment)
|
|
2688
|
+
});
|
|
2689
|
+
`
|
|
2690
|
+
.capxul-doc{--ink:#1d1d1f;--muted:#6e6e73;--line:#e7e7ea;--accent:#0a7d4b;--bg:#fff;
|
|
2691
|
+
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif;
|
|
2692
|
+
color:var(--ink);background:var(--bg);max-width:44rem;margin:0 auto;padding:2.75rem 3rem;
|
|
2693
|
+
border:1px solid var(--line);border-radius:16px;box-shadow:0 1px 2px rgba(0,0,0,.04),0 12px 32px rgba(0,0,0,.06);
|
|
2694
|
+
line-height:1.5;font-size:15px;overflow-wrap:anywhere;word-break:break-word}
|
|
2695
|
+
.capxul-doc *{box-sizing:border-box;min-width:0}
|
|
2696
|
+
.capxul-doc .doc-header{display:flex;flex-direction:column;gap:1.25rem;padding-bottom:1.5rem;border-bottom:1px solid var(--line);margin-bottom:1.75rem}
|
|
2697
|
+
.capxul-doc .doc-brand{display:flex;align-items:center;gap:.5rem;color:var(--accent);font-weight:600}
|
|
2698
|
+
.capxul-doc .doc-brand-mark{font-size:1.1rem}
|
|
2699
|
+
.capxul-doc .doc-brand-name{letter-spacing:.02em}
|
|
2700
|
+
.capxul-doc .doc-headline{display:flex;align-items:baseline;justify-content:space-between;gap:1rem;flex-wrap:wrap}
|
|
2701
|
+
.capxul-doc .doc-title{font-size:1.9rem;font-weight:700;letter-spacing:-.02em;margin:0}
|
|
2702
|
+
.capxul-doc .doc-badge{font-size:.7rem;font-weight:700;text-transform:uppercase;letter-spacing:.08em;
|
|
2703
|
+
color:var(--accent);background:rgba(10,125,75,.1);padding:.3rem .6rem;border-radius:999px;max-width:100%;text-align:right}
|
|
2704
|
+
.capxul-doc .doc-parties{display:grid;grid-template-columns:1fr 1fr;gap:1.25rem;margin-bottom:1.75rem}
|
|
2705
|
+
.capxul-doc .doc-party{display:flex;flex-direction:column;gap:.15rem}
|
|
2706
|
+
.capxul-doc .doc-party-label{font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;color:var(--muted)}
|
|
2707
|
+
.capxul-doc .doc-party-name{font-weight:600}
|
|
2708
|
+
.capxul-doc .doc-meta{display:flex;flex-direction:column;gap:.4rem;margin-bottom:1.75rem}
|
|
2709
|
+
.capxul-doc .doc-meta-row{display:flex;justify-content:space-between;gap:1rem;font-size:.92rem}
|
|
2710
|
+
.capxul-doc .doc-meta-label{color:var(--muted);flex-shrink:0}
|
|
2711
|
+
.capxul-doc .doc-meta-value{font-weight:500;text-align:right}
|
|
2712
|
+
.capxul-doc time{color:var(--ink);font-variant-numeric:tabular-nums}
|
|
2713
|
+
.capxul-doc .doc-line-items{width:100%;border-collapse:collapse;margin:.5rem 0 1.5rem;font-size:.92rem}
|
|
2714
|
+
.capxul-doc .doc-line-items th{text-align:left;font-size:.7rem;text-transform:uppercase;letter-spacing:.05em;
|
|
2715
|
+
color:var(--muted);font-weight:600;padding:.5rem .25rem;border-bottom:1px solid var(--line)}
|
|
2716
|
+
.capxul-doc .doc-line-items td{padding:.7rem .25rem;border-bottom:1px solid var(--line)}
|
|
2717
|
+
.capxul-doc .doc-li-qty,.capxul-doc .doc-li-unit,.capxul-doc .doc-li-total{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
|
|
2718
|
+
.capxul-doc .doc-li-desc{width:100%}
|
|
2719
|
+
.capxul-doc .doc-totals{display:flex;flex-direction:column;gap:.5rem;margin-top:.5rem}
|
|
2720
|
+
.capxul-doc .doc-total-line{display:flex;justify-content:space-between;align-items:baseline;gap:1rem}
|
|
2721
|
+
.capxul-doc .doc-total-label{color:var(--muted)}
|
|
2722
|
+
.capxul-doc .doc-total-deduction .doc-amount-value{color:var(--muted)}
|
|
2723
|
+
.capxul-doc .doc-total-grand{border-top:2px solid var(--ink);margin-top:.5rem;padding-top:.75rem;font-size:1.15rem}
|
|
2724
|
+
.capxul-doc .doc-total-grand .doc-amount-value{font-weight:700}
|
|
2725
|
+
.capxul-doc .doc-amount-value{font-variant-numeric:tabular-nums;font-weight:600}
|
|
2726
|
+
.capxul-doc .doc-hero{text-align:center;padding:1.5rem 0 2rem}
|
|
2727
|
+
.capxul-doc .doc-hero-label{font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;color:var(--muted)}
|
|
2728
|
+
.capxul-doc .doc-hero-amount{font-size:2.6rem;font-weight:700;letter-spacing:-.02em;margin-top:.35rem}
|
|
2729
|
+
.capxul-doc .doc-note{color:var(--ink);background:#f7f7f8;border-radius:10px;padding:.9rem 1.1rem;margin:0}
|
|
2730
|
+
.capxul-doc .doc-dest-address{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9rem}
|
|
2731
|
+
.capxul-doc .doc-footer{margin-top:1.75rem;padding-top:1.25rem;border-top:1px solid var(--line);color:var(--muted);font-size:.9rem}
|
|
2732
|
+
.capxul-doc code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.82rem;color:var(--muted);word-break:break-all}
|
|
2733
|
+
@media (max-width:540px){.capxul-doc{padding:1.75rem 1.25rem}.capxul-doc .doc-parties{grid-template-columns:1fr}}
|
|
2734
|
+
`.trim();
|
|
2735
|
+
//#endregion
|
|
2201
2736
|
//#region src/ports/bootstrap.ts
|
|
2202
2737
|
var BootstrapError = class extends Data.TaggedError("BootstrapError") {};
|
|
2203
2738
|
function bootstrapErrorFromCapxul(kind, error) {
|
|
@@ -2239,7 +2774,7 @@ var HttpBootstrapAdapter = class {
|
|
|
2239
2774
|
body: JSON.stringify({ publishableKey: input.publishableKey })
|
|
2240
2775
|
});
|
|
2241
2776
|
},
|
|
2242
|
-
catch: (cause) => bootstrapErrorFromCapxul("network", Errors
|
|
2777
|
+
catch: (cause) => bootstrapErrorFromCapxul("network", Errors.networkError("bootstrap", cause))
|
|
2243
2778
|
}).pipe(Effect.flatMap((res) => this.mapResponse(res)));
|
|
2244
2779
|
}
|
|
2245
2780
|
mapResponse(res) {
|
|
@@ -2247,7 +2782,7 @@ var HttpBootstrapAdapter = class {
|
|
|
2247
2782
|
try: async () => {
|
|
2248
2783
|
const body = await res.json();
|
|
2249
2784
|
const decoded = Schema.decodeUnknownEither(BootstrapEnvelope)(body);
|
|
2250
|
-
if (Either.isLeft(decoded)) throw Errors
|
|
2785
|
+
if (Either.isLeft(decoded)) throw Errors.invalidInput("bootstrapEnvelope", decoded.left.message);
|
|
2251
2786
|
const { state } = decoded.right;
|
|
2252
2787
|
return {
|
|
2253
2788
|
applicationId: state.applicationId,
|
|
@@ -2263,14 +2798,14 @@ var HttpBootstrapAdapter = class {
|
|
|
2263
2798
|
};
|
|
2264
2799
|
},
|
|
2265
2800
|
catch: (cause) => {
|
|
2266
|
-
if (cause instanceof CapxulError
|
|
2267
|
-
return bootstrapErrorFromCapxul("malformedBody", Errors
|
|
2801
|
+
if (cause instanceof CapxulError && cause.code === "INVALID_INPUT") return bootstrapErrorFromCapxul("invalidInput", cause);
|
|
2802
|
+
return bootstrapErrorFromCapxul("malformedBody", Errors.providerError("convex", "bootstrap", cause instanceof Error ? cause : new Error(String(cause))));
|
|
2268
2803
|
}
|
|
2269
2804
|
});
|
|
2270
2805
|
return Effect.promise(() => safeText(res)).pipe(Effect.flatMap((body) => {
|
|
2271
|
-
if (res.status === 401 || body.startsWith("NOT_AUTHENTICATED")) return Effect.fail(bootstrapErrorFromCapxul("notAuthenticated", Errors
|
|
2272
|
-
if (res.status === 400 || body.startsWith("INVALID_INPUT")) return Effect.fail(bootstrapErrorFromCapxul("invalidInput", Errors
|
|
2273
|
-
return Effect.fail(bootstrapErrorFromCapxul("provider", Errors
|
|
2806
|
+
if (res.status === 401 || body.startsWith("NOT_AUTHENTICATED")) return Effect.fail(bootstrapErrorFromCapxul("notAuthenticated", Errors.notAuthenticated()));
|
|
2807
|
+
if (res.status === 400 || body.startsWith("INVALID_INPUT")) return Effect.fail(bootstrapErrorFromCapxul("invalidInput", Errors.invalidInput("publishableKey", "rejected by bootstrap")));
|
|
2808
|
+
return Effect.fail(bootstrapErrorFromCapxul("provider", Errors.providerError("convex", "bootstrap", /* @__PURE__ */ new Error(`HTTP ${res.status}`))));
|
|
2274
2809
|
}));
|
|
2275
2810
|
}
|
|
2276
2811
|
};
|
|
@@ -2282,9 +2817,9 @@ function normalizeRuntimeUrl(field, raw) {
|
|
|
2282
2817
|
try {
|
|
2283
2818
|
parsed = new URL(raw);
|
|
2284
2819
|
} catch {
|
|
2285
|
-
throw Errors
|
|
2820
|
+
throw Errors.invalidInput(field, "must be an http or https URL");
|
|
2286
2821
|
}
|
|
2287
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw Errors
|
|
2822
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw Errors.invalidInput(field, "must be an http or https URL");
|
|
2288
2823
|
return parsed.toString().replace(/\/$/, "");
|
|
2289
2824
|
}
|
|
2290
2825
|
//#endregion
|
|
@@ -2388,12 +2923,12 @@ function ConvexCallLayer(deps) {
|
|
|
2388
2923
|
function mapToCapxulError(operation, err) {
|
|
2389
2924
|
const decoded = decodeConvexError(err);
|
|
2390
2925
|
if (decoded !== null) return decoded;
|
|
2391
|
-
if (err instanceof CapxulError
|
|
2926
|
+
if (err instanceof CapxulError) return err;
|
|
2392
2927
|
if (err instanceof Error) {
|
|
2393
|
-
if (isTransportError(err)) return Errors
|
|
2394
|
-
return Errors
|
|
2928
|
+
if (isTransportError(err)) return Errors.networkError(operation, err);
|
|
2929
|
+
return Errors.providerError("convex", operation, err);
|
|
2395
2930
|
}
|
|
2396
|
-
return Errors
|
|
2931
|
+
return Errors.providerError("convex", operation, new Error(String(err)));
|
|
2397
2932
|
}
|
|
2398
2933
|
function mapToConvexCallError(operation, err) {
|
|
2399
2934
|
return convexCallErrorFromCapxul(operation, mapToCapxulError(operation, err));
|
|
@@ -2530,8 +3065,8 @@ function brandPublishableKeyRecord(row) {
|
|
|
2530
3065
|
};
|
|
2531
3066
|
}
|
|
2532
3067
|
function credentialsErrorFromUnknown(operation, cause) {
|
|
2533
|
-
if (cause instanceof CapxulError
|
|
2534
|
-
return credentialsErrorFromCapxul(operation, Errors
|
|
3068
|
+
if (cause instanceof CapxulError) return credentialsErrorFromCapxul(operation, cause);
|
|
3069
|
+
return credentialsErrorFromCapxul(operation, Errors.providerError("credentials", operation, cause instanceof Error ? cause : new Error(String(cause))), cause);
|
|
2535
3070
|
}
|
|
2536
3071
|
//#endregion
|
|
2537
3072
|
//#region src/ports/env.ts
|
|
@@ -2847,7 +3382,7 @@ function schemaFor(kind) {
|
|
|
2847
3382
|
}, { message: () => "Invalid url" }));
|
|
2848
3383
|
default: {
|
|
2849
3384
|
const unsupported = kind;
|
|
2850
|
-
throw Errors
|
|
3385
|
+
throw Errors.invalidInput(String(unsupported), "unsupported environment field kind");
|
|
2851
3386
|
}
|
|
2852
3387
|
}
|
|
2853
3388
|
}
|
|
@@ -2856,14 +3391,14 @@ const envShapeSchema = Schema.Struct(envShapeFields);
|
|
|
2856
3391
|
Schema.partial(envShapeSchema);
|
|
2857
3392
|
function parseEnvValue$1(key, raw, required) {
|
|
2858
3393
|
const field = envFields[key];
|
|
2859
|
-
if (field === void 0) throw Errors
|
|
3394
|
+
if (field === void 0) throw Errors.invalidInput(key, "unknown environment key");
|
|
2860
3395
|
const normalized = normalizeEnvRaw(raw);
|
|
2861
3396
|
if (normalized === void 0) {
|
|
2862
|
-
if (required) throw Errors
|
|
3397
|
+
if (required) throw Errors.envMissing(key);
|
|
2863
3398
|
return;
|
|
2864
3399
|
}
|
|
2865
3400
|
const result = Schema.decodeUnknownEither(schemaFor(field.kind))(normalized);
|
|
2866
|
-
if (Either.isLeft(result)) throw Errors
|
|
3401
|
+
if (Either.isLeft(result)) throw Errors.invalidInput(key, TreeFormatter.formatErrorSync(result.left));
|
|
2867
3402
|
return result.right;
|
|
2868
3403
|
}
|
|
2869
3404
|
function normalizeEnvRaw(raw) {
|
|
@@ -2879,14 +3414,14 @@ function parseEnvValue(key, raw, required) {
|
|
|
2879
3414
|
return parseEnvValue$1(key, raw, required);
|
|
2880
3415
|
}
|
|
2881
3416
|
function hasEnvValue(key, raw) {
|
|
2882
|
-
if (envFields[key] === void 0) throw envErrorFromCapxul(key, Errors
|
|
3417
|
+
if (envFields[key] === void 0) throw envErrorFromCapxul(key, Errors.invalidInput(key, "unknown environment key"));
|
|
2883
3418
|
return normalizeEnvRaw(raw) !== void 0;
|
|
2884
3419
|
}
|
|
2885
3420
|
function catchEnvError(key, cause) {
|
|
2886
3421
|
if (cause instanceof EnvError) return cause;
|
|
2887
|
-
if (isCapxulError
|
|
3422
|
+
if (isCapxulError(cause)) return envErrorFromCapxul(key, cause, cause);
|
|
2888
3423
|
const redactedCause = /* @__PURE__ */ new Error(`env ${key} read failed`);
|
|
2889
|
-
return envErrorFromCapxul(key, Errors
|
|
3424
|
+
return envErrorFromCapxul(key, Errors.providerError("env", key, redactedCause), redactedCause);
|
|
2890
3425
|
}
|
|
2891
3426
|
//#endregion
|
|
2892
3427
|
//#region src/adapters/env/SystemEnvAdapter.ts
|
|
@@ -2975,8 +3510,8 @@ function brandProfile(raw) {
|
|
|
2975
3510
|
};
|
|
2976
3511
|
}
|
|
2977
3512
|
function identityErrorFromUnknown(operation, cause) {
|
|
2978
|
-
if (cause instanceof CapxulError
|
|
2979
|
-
return identityErrorFromCapxul(operation, Errors
|
|
3513
|
+
if (cause instanceof CapxulError) return identityErrorFromCapxul(operation, cause);
|
|
3514
|
+
return identityErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
|
|
2980
3515
|
}
|
|
2981
3516
|
//#endregion
|
|
2982
3517
|
//#region src/money/to-wei.ts
|
|
@@ -3065,8 +3600,8 @@ function brandAccount(wire) {
|
|
|
3065
3600
|
};
|
|
3066
3601
|
}
|
|
3067
3602
|
function accountReadErrorFromUnknown(operation, cause) {
|
|
3068
|
-
if (cause instanceof CapxulError
|
|
3069
|
-
return accountReadErrorFromCapxul(operation, Errors
|
|
3603
|
+
if (cause instanceof CapxulError) return accountReadErrorFromCapxul(operation, cause);
|
|
3604
|
+
return accountReadErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
|
|
3070
3605
|
}
|
|
3071
3606
|
//#endregion
|
|
3072
3607
|
//#region src/ports/sub-account.ts
|
|
@@ -3164,8 +3699,8 @@ function brandSubAccount(wire) {
|
|
|
3164
3699
|
};
|
|
3165
3700
|
}
|
|
3166
3701
|
function subAccountErrorFromUnknown(operation, cause) {
|
|
3167
|
-
if (cause instanceof CapxulError
|
|
3168
|
-
return subAccountErrorFromCapxul(operation, Errors
|
|
3702
|
+
if (cause instanceof CapxulError) return subAccountErrorFromCapxul(operation, cause);
|
|
3703
|
+
return subAccountErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
|
|
3169
3704
|
}
|
|
3170
3705
|
//#endregion
|
|
3171
3706
|
//#region src/ports/smart-account.ts
|
|
@@ -3259,16 +3794,705 @@ function brandNonNullSmartAccount(wire) {
|
|
|
3259
3794
|
};
|
|
3260
3795
|
}
|
|
3261
3796
|
function brandProvisionedSmartAccount(requestedAuthUserId, wire) {
|
|
3262
|
-
if (wire.authUserId !== String(requestedAuthUserId)) throw Errors
|
|
3797
|
+
if (wire.authUserId !== String(requestedAuthUserId)) throw Errors.notAuthenticated();
|
|
3263
3798
|
return brandNonNullSmartAccount(wire);
|
|
3264
3799
|
}
|
|
3265
3800
|
function smartAccountErrorFromUnknown(operation, cause) {
|
|
3266
|
-
if (cause instanceof CapxulError
|
|
3267
|
-
return smartAccountErrorFromCapxul(operation, Errors
|
|
3801
|
+
if (cause instanceof CapxulError) return smartAccountErrorFromCapxul(operation, cause);
|
|
3802
|
+
return smartAccountErrorFromCapxul(operation, Errors.providerError("convex", operation, cause), cause);
|
|
3268
3803
|
}
|
|
3269
3804
|
toAddress("0xa6b71e26c5e0845f74c812102ca7114b6a896ab2");
|
|
3270
3805
|
keccak256("0x");
|
|
3271
3806
|
//#endregion
|
|
3807
|
+
//#region ../observability/src/index.ts
|
|
3808
|
+
const PII = Schema.String.pipe(Schema.brand("PII"));
|
|
3809
|
+
const OptionalString = Schema.optional(Schema.String);
|
|
3810
|
+
const AddressSchema = Schema.String.pipe(Schema.transform(Schema.String, {
|
|
3811
|
+
decode: (value) => value.toLowerCase(),
|
|
3812
|
+
encode: (value) => value
|
|
3813
|
+
}), Schema.filter((value) => EVM_ADDRESS_RE$1.test(value), { message: () => "must be 0x + 40 hex chars" }));
|
|
3814
|
+
const AppIdSchema = Schema.String.pipe(Schema.filter((value) => APP_ID_RE.test(value), { message: () => "must be app_ plus a ULID" }));
|
|
3815
|
+
const BlockNumberSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
3816
|
+
const ChainIdSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value > 0, { message: () => "must be a positive safe integer" }));
|
|
3817
|
+
const DurationMsSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
3818
|
+
const EpochMsSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value >= 0, { message: () => "must be a non-negative safe integer" }));
|
|
3819
|
+
const PublishableKeyIdSchema = Schema.String.pipe(Schema.filter((value) => value.length > 0, { message: () => "must be a non-empty string" }));
|
|
3820
|
+
const TxHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
3821
|
+
const ACCOUNT_ID_TELEMETRY_RE = /^account_[0-9A-Za-z]+$/;
|
|
3822
|
+
const SUBACCOUNT_ID_TELEMETRY_RE = /^subaccount_[0-9A-Za-z]+$/;
|
|
3823
|
+
const WEI_AMOUNT_TELEMETRY_RE = /^[0-9]+$/;
|
|
3824
|
+
const AccountIdSchema = Schema.String.pipe(Schema.filter((value) => ACCOUNT_ID_TELEMETRY_RE.test(value), { message: () => "must be account_ plus an alphanumeric id" }));
|
|
3825
|
+
const SubAccountIdSchema = Schema.String.pipe(Schema.filter((value) => SUBACCOUNT_ID_TELEMETRY_RE.test(value), { message: () => "must be subaccount_ plus an alphanumeric id" }));
|
|
3826
|
+
const WeiAmountSchema = Schema.String.pipe(Schema.filter((value) => WEI_AMOUNT_TELEMETRY_RE.test(value), { message: () => "must be a non-negative integer string" }));
|
|
3827
|
+
const CurrencyCodeSchema = Schema.String.pipe(Schema.filter((value) => value.length > 0, { message: () => "must be a non-empty currency code" }));
|
|
3828
|
+
const BalanceBucketSchema = Schema.Literal("zero", "nonzero");
|
|
3829
|
+
const TransferDirectionSchema = Schema.Literal("add", "out", "between");
|
|
3830
|
+
const SubAccountOpSchema = Schema.Literal("create", "rename", "delete");
|
|
3831
|
+
const OptionalAccountId = Schema.optional(AccountIdSchema);
|
|
3832
|
+
const OptionalSubAccountId = Schema.optional(SubAccountIdSchema);
|
|
3833
|
+
const OptionalWeiAmount = Schema.optional(WeiAmountSchema);
|
|
3834
|
+
const OptionalCurrencyCode = Schema.optional(CurrencyCodeSchema);
|
|
3835
|
+
const OptionalBalanceBucket = Schema.optional(BalanceBucketSchema);
|
|
3836
|
+
const OptionalTransferDirection = Schema.optional(TransferDirectionSchema);
|
|
3837
|
+
const OptionalSubAccountOp = Schema.optional(SubAccountOpSchema);
|
|
3838
|
+
const OptionalTrue = Schema.optional(Schema.Literal(true));
|
|
3839
|
+
const OptionalAddress = Schema.optional(AddressSchema);
|
|
3840
|
+
const OptionalAppId = Schema.optional(AppIdSchema);
|
|
3841
|
+
const OptionalBlockNumber = Schema.optional(BlockNumberSchema);
|
|
3842
|
+
const OptionalChainId = Schema.optional(ChainIdSchema);
|
|
3843
|
+
const OptionalDurationMs = Schema.optional(DurationMsSchema);
|
|
3844
|
+
const OptionalEpochMs = Schema.optional(EpochMsSchema);
|
|
3845
|
+
const OptionalPublishableKeyId = Schema.optional(PublishableKeyIdSchema);
|
|
3846
|
+
const OptionalTxHash = Schema.optional(TxHashSchema);
|
|
3847
|
+
const PAYMENT_ID_TELEMETRY_RE = /^payment_[0-9A-Za-z]+$/;
|
|
3848
|
+
const PAYEE_ID_TELEMETRY_RE = /^payee_[0-9A-Za-z]+$/;
|
|
3849
|
+
const PaymentIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYMENT_ID_TELEMETRY_RE.test(value), { message: () => "must be payment_ plus an alphanumeric id" }));
|
|
3850
|
+
const PayeeIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYEE_ID_TELEMETRY_RE.test(value), { message: () => "must be payee_ plus an alphanumeric id" }));
|
|
3851
|
+
const DocumentHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
3852
|
+
const TelemetryEnvelopeProps = {
|
|
3853
|
+
capxul_e2e_run_id: OptionalString,
|
|
3854
|
+
correlationId: OptionalString,
|
|
3855
|
+
capxulEnv: OptionalString,
|
|
3856
|
+
sdkVersion: OptionalString,
|
|
3857
|
+
producer: OptionalString
|
|
3858
|
+
};
|
|
3859
|
+
const AuthOtpRequestedProps = Schema.Struct({
|
|
3860
|
+
...TelemetryEnvelopeProps,
|
|
3861
|
+
email: Schema.optional(PII),
|
|
3862
|
+
email_domain: OptionalString
|
|
3863
|
+
});
|
|
3864
|
+
const AuthOtpDeliveredProps = Schema.Struct({
|
|
3865
|
+
...TelemetryEnvelopeProps,
|
|
3866
|
+
durationMs: OptionalDurationMs,
|
|
3867
|
+
email: Schema.optional(PII),
|
|
3868
|
+
email_domain: OptionalString,
|
|
3869
|
+
resendMessageId: OptionalString
|
|
3870
|
+
});
|
|
3871
|
+
const AuthOtpExpiredProps = Schema.Struct({
|
|
3872
|
+
...TelemetryEnvelopeProps,
|
|
3873
|
+
email: Schema.optional(PII),
|
|
3874
|
+
email_domain: OptionalString
|
|
3875
|
+
});
|
|
3876
|
+
const AuthVerifiedProps = Schema.Struct({
|
|
3877
|
+
...TelemetryEnvelopeProps,
|
|
3878
|
+
auth_type: OptionalString
|
|
3879
|
+
});
|
|
3880
|
+
const AuthFailedProps = Schema.Struct({
|
|
3881
|
+
...TelemetryEnvelopeProps,
|
|
3882
|
+
email: Schema.optional(PII),
|
|
3883
|
+
auth_type: OptionalString,
|
|
3884
|
+
reason: OptionalString
|
|
3885
|
+
});
|
|
3886
|
+
const AuthSignedOutProps = Schema.Struct(TelemetryEnvelopeProps);
|
|
3887
|
+
const ProvisioningSafeCreatedProps = Schema.Struct({
|
|
3888
|
+
...TelemetryEnvelopeProps,
|
|
3889
|
+
safe_address: OptionalAddress
|
|
3890
|
+
});
|
|
3891
|
+
const ProvisioningSafeConfirmedProps = Schema.Struct({
|
|
3892
|
+
...TelemetryEnvelopeProps,
|
|
3893
|
+
chainId: OptionalChainId,
|
|
3894
|
+
deployedAt: OptionalEpochMs,
|
|
3895
|
+
deployedAtBlock: OptionalBlockNumber,
|
|
3896
|
+
deployTxHash: OptionalTxHash,
|
|
3897
|
+
durationMs: OptionalDurationMs,
|
|
3898
|
+
safe_address: OptionalAddress,
|
|
3899
|
+
userOpHash: OptionalTxHash
|
|
3900
|
+
});
|
|
3901
|
+
const BootstrapResolvedProps = Schema.Struct({
|
|
3902
|
+
...TelemetryEnvelopeProps,
|
|
3903
|
+
applicationId: OptionalAppId,
|
|
3904
|
+
durationMs: OptionalDurationMs,
|
|
3905
|
+
env: OptionalString,
|
|
3906
|
+
keyId: OptionalPublishableKeyId,
|
|
3907
|
+
origin: OptionalString
|
|
3908
|
+
});
|
|
3909
|
+
const BootstrapFailedProps = Schema.Struct({
|
|
3910
|
+
...TelemetryEnvelopeProps,
|
|
3911
|
+
applicationId: OptionalAppId,
|
|
3912
|
+
durationMs: OptionalDurationMs,
|
|
3913
|
+
origin: OptionalString,
|
|
3914
|
+
reason: OptionalString
|
|
3915
|
+
});
|
|
3916
|
+
const AccountBalanceReadProps = Schema.Struct({
|
|
3917
|
+
...TelemetryEnvelopeProps,
|
|
3918
|
+
account_id: OptionalAccountId,
|
|
3919
|
+
currency: OptionalCurrencyCode,
|
|
3920
|
+
balance_bucket: OptionalBalanceBucket,
|
|
3921
|
+
durationMs: OptionalDurationMs
|
|
3922
|
+
});
|
|
3923
|
+
const AccountBalanceFailedProps = Schema.Struct({
|
|
3924
|
+
...TelemetryEnvelopeProps,
|
|
3925
|
+
reason: OptionalString
|
|
3926
|
+
});
|
|
3927
|
+
const FaucetRequestedProps = Schema.Struct({
|
|
3928
|
+
...TelemetryEnvelopeProps,
|
|
3929
|
+
amount: OptionalWeiAmount,
|
|
3930
|
+
chainId: OptionalChainId
|
|
3931
|
+
});
|
|
3932
|
+
const FaucetConfirmedProps = Schema.Struct({
|
|
3933
|
+
...TelemetryEnvelopeProps,
|
|
3934
|
+
amount: OptionalWeiAmount,
|
|
3935
|
+
chainId: OptionalChainId,
|
|
3936
|
+
txHash: OptionalTxHash,
|
|
3937
|
+
durationMs: OptionalDurationMs
|
|
3938
|
+
});
|
|
3939
|
+
const FaucetFailedProps = Schema.Struct({
|
|
3940
|
+
...TelemetryEnvelopeProps,
|
|
3941
|
+
reason: OptionalString
|
|
3942
|
+
});
|
|
3943
|
+
const SubaccountCreatedProps = Schema.Struct({
|
|
3944
|
+
...TelemetryEnvelopeProps,
|
|
3945
|
+
sub_account_id: OptionalSubAccountId,
|
|
3946
|
+
durationMs: OptionalDurationMs
|
|
3947
|
+
});
|
|
3948
|
+
const SubaccountRenamedProps = Schema.Struct({
|
|
3949
|
+
...TelemetryEnvelopeProps,
|
|
3950
|
+
sub_account_id: OptionalSubAccountId
|
|
3951
|
+
});
|
|
3952
|
+
const SubaccountDeletedProps = Schema.Struct({
|
|
3953
|
+
...TelemetryEnvelopeProps,
|
|
3954
|
+
sub_account_id: OptionalSubAccountId
|
|
3955
|
+
});
|
|
3956
|
+
const SubaccountOpFailedProps = Schema.Struct({
|
|
3957
|
+
...TelemetryEnvelopeProps,
|
|
3958
|
+
op: OptionalSubAccountOp,
|
|
3959
|
+
reason: OptionalString
|
|
3960
|
+
});
|
|
3961
|
+
const TransferRequestedProps = Schema.Struct({
|
|
3962
|
+
...TelemetryEnvelopeProps,
|
|
3963
|
+
amount: OptionalWeiAmount,
|
|
3964
|
+
direction: OptionalTransferDirection
|
|
3965
|
+
});
|
|
3966
|
+
const TransferConfirmedProps = Schema.Struct({
|
|
3967
|
+
...TelemetryEnvelopeProps,
|
|
3968
|
+
amount: OptionalWeiAmount,
|
|
3969
|
+
direction: OptionalTransferDirection,
|
|
3970
|
+
available_bucket: OptionalBalanceBucket,
|
|
3971
|
+
txless: OptionalTrue,
|
|
3972
|
+
durationMs: OptionalDurationMs
|
|
3973
|
+
});
|
|
3974
|
+
const TransferFailedProps = Schema.Struct({
|
|
3975
|
+
...TelemetryEnvelopeProps,
|
|
3976
|
+
reason: OptionalString
|
|
3977
|
+
});
|
|
3978
|
+
const ORG_ID_TELEMETRY_RE = /^org_[0-9A-Za-z]+$/;
|
|
3979
|
+
const OrgIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => ORG_ID_TELEMETRY_RE.test(value), { message: () => "must be org_ plus an alphanumeric id" }));
|
|
3980
|
+
const OptionalOrgId = Schema.optional(OrgIdTelemetrySchema);
|
|
3981
|
+
const OrgCreateStartedProps = Schema.Struct({
|
|
3982
|
+
...TelemetryEnvelopeProps,
|
|
3983
|
+
org_id: OptionalOrgId,
|
|
3984
|
+
email_domain: OptionalString,
|
|
3985
|
+
template: OptionalString
|
|
3986
|
+
});
|
|
3987
|
+
const OrgSafeCreatedProps = Schema.Struct({
|
|
3988
|
+
...TelemetryEnvelopeProps,
|
|
3989
|
+
org_id: OptionalOrgId,
|
|
3990
|
+
chainId: OptionalChainId,
|
|
3991
|
+
safe_address: OptionalAddress
|
|
3992
|
+
});
|
|
3993
|
+
const OrgSafeConfirmedProps = Schema.Struct({
|
|
3994
|
+
...TelemetryEnvelopeProps,
|
|
3995
|
+
org_id: OptionalOrgId,
|
|
3996
|
+
chainId: OptionalChainId,
|
|
3997
|
+
safe_address: OptionalAddress,
|
|
3998
|
+
durationMs: OptionalDurationMs
|
|
3999
|
+
});
|
|
4000
|
+
const OrgRolesSeededProps = Schema.Struct({
|
|
4001
|
+
...TelemetryEnvelopeProps,
|
|
4002
|
+
org_id: OptionalOrgId,
|
|
4003
|
+
chainId: OptionalChainId,
|
|
4004
|
+
role: OptionalString,
|
|
4005
|
+
txHash: OptionalTxHash
|
|
4006
|
+
});
|
|
4007
|
+
const OrgCreatedProps = Schema.Struct({
|
|
4008
|
+
...TelemetryEnvelopeProps,
|
|
4009
|
+
org_id: OptionalOrgId,
|
|
4010
|
+
chainId: OptionalChainId,
|
|
4011
|
+
safe_address: OptionalAddress,
|
|
4012
|
+
durationMs: OptionalDurationMs
|
|
4013
|
+
});
|
|
4014
|
+
const OrgCreateFailedProps = Schema.Struct({
|
|
4015
|
+
...TelemetryEnvelopeProps,
|
|
4016
|
+
org_id: OptionalOrgId,
|
|
4017
|
+
reason: OptionalString
|
|
4018
|
+
});
|
|
4019
|
+
const OrgInviteSentProps = Schema.Struct({
|
|
4020
|
+
...TelemetryEnvelopeProps,
|
|
4021
|
+
org_id: OptionalOrgId,
|
|
4022
|
+
email_domain: OptionalString,
|
|
4023
|
+
role: OptionalString,
|
|
4024
|
+
status: OptionalString
|
|
4025
|
+
});
|
|
4026
|
+
const OrgInviteAcceptedProps = Schema.Struct({
|
|
4027
|
+
...TelemetryEnvelopeProps,
|
|
4028
|
+
org_id: OptionalOrgId,
|
|
4029
|
+
role: OptionalString,
|
|
4030
|
+
status: OptionalString
|
|
4031
|
+
});
|
|
4032
|
+
const OrgRoleGrantedProps = Schema.Struct({
|
|
4033
|
+
...TelemetryEnvelopeProps,
|
|
4034
|
+
org_id: OptionalOrgId,
|
|
4035
|
+
role: OptionalString,
|
|
4036
|
+
status: OptionalString,
|
|
4037
|
+
txHash: OptionalTxHash
|
|
4038
|
+
});
|
|
4039
|
+
const OrgMemberActiveProps = Schema.Struct({
|
|
4040
|
+
...TelemetryEnvelopeProps,
|
|
4041
|
+
org_id: OptionalOrgId,
|
|
4042
|
+
role: OptionalString,
|
|
4043
|
+
status: OptionalString,
|
|
4044
|
+
durationMs: OptionalDurationMs
|
|
4045
|
+
});
|
|
4046
|
+
const OrgMemberRemovedProps = Schema.Struct({
|
|
4047
|
+
...TelemetryEnvelopeProps,
|
|
4048
|
+
org_id: OptionalOrgId,
|
|
4049
|
+
role: OptionalString,
|
|
4050
|
+
status: OptionalString,
|
|
4051
|
+
txHash: OptionalTxHash
|
|
4052
|
+
});
|
|
4053
|
+
const OrgInviteExpiredProps = Schema.Struct({
|
|
4054
|
+
...TelemetryEnvelopeProps,
|
|
4055
|
+
org_id: OptionalOrgId,
|
|
4056
|
+
email_domain: OptionalString,
|
|
4057
|
+
reason: OptionalString,
|
|
4058
|
+
role: OptionalString,
|
|
4059
|
+
status: OptionalString
|
|
4060
|
+
});
|
|
4061
|
+
const OrgRoleGrantFailedProps = Schema.Struct({
|
|
4062
|
+
...TelemetryEnvelopeProps,
|
|
4063
|
+
org_id: OptionalOrgId,
|
|
4064
|
+
reason: OptionalString,
|
|
4065
|
+
role: OptionalString
|
|
4066
|
+
});
|
|
4067
|
+
const OptionalPaymentId = Schema.optional(PaymentIdTelemetrySchema);
|
|
4068
|
+
const OptionalPayeeId = Schema.optional(PayeeIdTelemetrySchema);
|
|
4069
|
+
const OptionalDocumentHash = Schema.optional(DocumentHashSchema);
|
|
4070
|
+
const PaymentTargetTelemetryProps = Schema.Struct({
|
|
4071
|
+
...TelemetryEnvelopeProps,
|
|
4072
|
+
payment_id: OptionalPaymentId,
|
|
4073
|
+
payee_id: OptionalPayeeId,
|
|
4074
|
+
document_hash: OptionalDocumentHash,
|
|
4075
|
+
amount: OptionalWeiAmount,
|
|
4076
|
+
currency: OptionalCurrencyCode,
|
|
4077
|
+
status: OptionalString,
|
|
4078
|
+
reason: OptionalString,
|
|
4079
|
+
durationMs: OptionalDurationMs
|
|
4080
|
+
});
|
|
4081
|
+
const StreamTargetTelemetryProps = Schema.Struct({
|
|
4082
|
+
...TelemetryEnvelopeProps,
|
|
4083
|
+
payment_id: OptionalPaymentId,
|
|
4084
|
+
document_hash: OptionalDocumentHash,
|
|
4085
|
+
amount: OptionalWeiAmount,
|
|
4086
|
+
currency: OptionalCurrencyCode,
|
|
4087
|
+
status: OptionalString,
|
|
4088
|
+
available_bucket: OptionalBalanceBucket,
|
|
4089
|
+
reason: OptionalString,
|
|
4090
|
+
durationMs: OptionalDurationMs
|
|
4091
|
+
});
|
|
4092
|
+
const WithdrawalTargetTelemetryProps = Schema.Struct({
|
|
4093
|
+
...TelemetryEnvelopeProps,
|
|
4094
|
+
payment_id: OptionalPaymentId,
|
|
4095
|
+
document_hash: OptionalDocumentHash,
|
|
4096
|
+
amount: OptionalWeiAmount,
|
|
4097
|
+
currency: OptionalCurrencyCode,
|
|
4098
|
+
status: OptionalString,
|
|
4099
|
+
reason: OptionalString,
|
|
4100
|
+
durationMs: OptionalDurationMs
|
|
4101
|
+
});
|
|
4102
|
+
Schema.Struct({
|
|
4103
|
+
name: Schema.Literal("auth_otp_requested"),
|
|
4104
|
+
props: Schema.optional(AuthOtpRequestedProps)
|
|
4105
|
+
});
|
|
4106
|
+
Schema.Struct({
|
|
4107
|
+
name: Schema.Literal("auth_otp_delivered"),
|
|
4108
|
+
props: Schema.optional(AuthOtpDeliveredProps)
|
|
4109
|
+
});
|
|
4110
|
+
Schema.Struct({
|
|
4111
|
+
name: Schema.Literal("auth_otp_expired"),
|
|
4112
|
+
props: Schema.optional(AuthOtpExpiredProps)
|
|
4113
|
+
});
|
|
4114
|
+
Schema.Struct({
|
|
4115
|
+
name: Schema.Literal("auth_verified"),
|
|
4116
|
+
props: Schema.optional(AuthVerifiedProps)
|
|
4117
|
+
});
|
|
4118
|
+
Schema.Struct({
|
|
4119
|
+
name: Schema.Literal("auth_failed"),
|
|
4120
|
+
props: Schema.optional(AuthFailedProps)
|
|
4121
|
+
});
|
|
4122
|
+
Schema.Struct({
|
|
4123
|
+
name: Schema.Literal("auth_signed_out"),
|
|
4124
|
+
props: Schema.optional(AuthSignedOutProps)
|
|
4125
|
+
});
|
|
4126
|
+
Schema.Struct({
|
|
4127
|
+
name: Schema.Literal("provisioning_safe_created"),
|
|
4128
|
+
props: Schema.optional(ProvisioningSafeCreatedProps)
|
|
4129
|
+
});
|
|
4130
|
+
Schema.Struct({
|
|
4131
|
+
name: Schema.Literal("provisioning_safe_confirmed"),
|
|
4132
|
+
props: Schema.optional(ProvisioningSafeConfirmedProps)
|
|
4133
|
+
});
|
|
4134
|
+
Schema.Struct({
|
|
4135
|
+
name: Schema.Literal("bootstrap_resolved"),
|
|
4136
|
+
props: Schema.optional(BootstrapResolvedProps)
|
|
4137
|
+
});
|
|
4138
|
+
Schema.Struct({
|
|
4139
|
+
name: Schema.Literal("bootstrap_failed"),
|
|
4140
|
+
props: Schema.optional(BootstrapFailedProps)
|
|
4141
|
+
});
|
|
4142
|
+
Schema.Struct({
|
|
4143
|
+
name: Schema.Literal("account_balance_read"),
|
|
4144
|
+
props: Schema.optional(AccountBalanceReadProps)
|
|
4145
|
+
});
|
|
4146
|
+
Schema.Struct({
|
|
4147
|
+
name: Schema.Literal("account_balance_failed"),
|
|
4148
|
+
props: Schema.optional(AccountBalanceFailedProps)
|
|
4149
|
+
});
|
|
4150
|
+
Schema.Struct({
|
|
4151
|
+
name: Schema.Literal("faucet_requested"),
|
|
4152
|
+
props: Schema.optional(FaucetRequestedProps)
|
|
4153
|
+
});
|
|
4154
|
+
Schema.Struct({
|
|
4155
|
+
name: Schema.Literal("faucet_confirmed"),
|
|
4156
|
+
props: Schema.optional(FaucetConfirmedProps)
|
|
4157
|
+
});
|
|
4158
|
+
Schema.Struct({
|
|
4159
|
+
name: Schema.Literal("faucet_failed"),
|
|
4160
|
+
props: Schema.optional(FaucetFailedProps)
|
|
4161
|
+
});
|
|
4162
|
+
Schema.Struct({
|
|
4163
|
+
name: Schema.Literal("subaccount_created"),
|
|
4164
|
+
props: Schema.optional(SubaccountCreatedProps)
|
|
4165
|
+
});
|
|
4166
|
+
Schema.Struct({
|
|
4167
|
+
name: Schema.Literal("subaccount_renamed"),
|
|
4168
|
+
props: Schema.optional(SubaccountRenamedProps)
|
|
4169
|
+
});
|
|
4170
|
+
Schema.Struct({
|
|
4171
|
+
name: Schema.Literal("subaccount_deleted"),
|
|
4172
|
+
props: Schema.optional(SubaccountDeletedProps)
|
|
4173
|
+
});
|
|
4174
|
+
Schema.Struct({
|
|
4175
|
+
name: Schema.Literal("subaccount_op_failed"),
|
|
4176
|
+
props: Schema.optional(SubaccountOpFailedProps)
|
|
4177
|
+
});
|
|
4178
|
+
Schema.Struct({
|
|
4179
|
+
name: Schema.Literal("transfer_requested"),
|
|
4180
|
+
props: Schema.optional(TransferRequestedProps)
|
|
4181
|
+
});
|
|
4182
|
+
Schema.Struct({
|
|
4183
|
+
name: Schema.Literal("transfer_confirmed"),
|
|
4184
|
+
props: Schema.optional(TransferConfirmedProps)
|
|
4185
|
+
});
|
|
4186
|
+
Schema.Struct({
|
|
4187
|
+
name: Schema.Literal("transfer_failed"),
|
|
4188
|
+
props: Schema.optional(TransferFailedProps)
|
|
4189
|
+
});
|
|
4190
|
+
Schema.Struct({
|
|
4191
|
+
name: Schema.Literal("org_create_started"),
|
|
4192
|
+
props: Schema.optional(OrgCreateStartedProps)
|
|
4193
|
+
});
|
|
4194
|
+
Schema.Struct({
|
|
4195
|
+
name: Schema.Literal("org_safe_created"),
|
|
4196
|
+
props: Schema.optional(OrgSafeCreatedProps)
|
|
4197
|
+
});
|
|
4198
|
+
Schema.Struct({
|
|
4199
|
+
name: Schema.Literal("org_safe_confirmed"),
|
|
4200
|
+
props: Schema.optional(OrgSafeConfirmedProps)
|
|
4201
|
+
});
|
|
4202
|
+
Schema.Struct({
|
|
4203
|
+
name: Schema.Literal("org_roles_seeded"),
|
|
4204
|
+
props: Schema.optional(OrgRolesSeededProps)
|
|
4205
|
+
});
|
|
4206
|
+
Schema.Struct({
|
|
4207
|
+
name: Schema.Literal("org_created"),
|
|
4208
|
+
props: Schema.optional(OrgCreatedProps)
|
|
4209
|
+
});
|
|
4210
|
+
Schema.Struct({
|
|
4211
|
+
name: Schema.Literal("org_create_failed"),
|
|
4212
|
+
props: Schema.optional(OrgCreateFailedProps)
|
|
4213
|
+
});
|
|
4214
|
+
Schema.Struct({
|
|
4215
|
+
name: Schema.Literal("org_invite_sent"),
|
|
4216
|
+
props: Schema.optional(OrgInviteSentProps)
|
|
4217
|
+
});
|
|
4218
|
+
Schema.Struct({
|
|
4219
|
+
name: Schema.Literal("org_invite_accepted"),
|
|
4220
|
+
props: Schema.optional(OrgInviteAcceptedProps)
|
|
4221
|
+
});
|
|
4222
|
+
Schema.Struct({
|
|
4223
|
+
name: Schema.Literal("org_role_granted"),
|
|
4224
|
+
props: Schema.optional(OrgRoleGrantedProps)
|
|
4225
|
+
});
|
|
4226
|
+
Schema.Struct({
|
|
4227
|
+
name: Schema.Literal("org_member_active"),
|
|
4228
|
+
props: Schema.optional(OrgMemberActiveProps)
|
|
4229
|
+
});
|
|
4230
|
+
Schema.Struct({
|
|
4231
|
+
name: Schema.Literal("org_member_removed"),
|
|
4232
|
+
props: Schema.optional(OrgMemberRemovedProps)
|
|
4233
|
+
});
|
|
4234
|
+
Schema.Struct({
|
|
4235
|
+
name: Schema.Literal("org_invite_expired"),
|
|
4236
|
+
props: Schema.optional(OrgInviteExpiredProps)
|
|
4237
|
+
});
|
|
4238
|
+
Schema.Struct({
|
|
4239
|
+
name: Schema.Literal("org_role_grant_failed"),
|
|
4240
|
+
props: Schema.optional(OrgRoleGrantFailedProps)
|
|
4241
|
+
});
|
|
4242
|
+
Schema.Struct({
|
|
4243
|
+
name: Schema.Literal("payment_requested"),
|
|
4244
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4245
|
+
});
|
|
4246
|
+
Schema.Struct({
|
|
4247
|
+
name: Schema.Literal("payment_resolved"),
|
|
4248
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4249
|
+
});
|
|
4250
|
+
Schema.Struct({
|
|
4251
|
+
name: Schema.Literal("payment_document_attached"),
|
|
4252
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4253
|
+
});
|
|
4254
|
+
Schema.Struct({
|
|
4255
|
+
name: Schema.Literal("payment_submitted"),
|
|
4256
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4257
|
+
});
|
|
4258
|
+
Schema.Struct({
|
|
4259
|
+
name: Schema.Literal("payment_settled"),
|
|
4260
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4261
|
+
});
|
|
4262
|
+
Schema.Struct({
|
|
4263
|
+
name: Schema.Literal("payment_claimed"),
|
|
4264
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4265
|
+
});
|
|
4266
|
+
Schema.Struct({
|
|
4267
|
+
name: Schema.Literal("payment_cancelled"),
|
|
4268
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4269
|
+
});
|
|
4270
|
+
Schema.Struct({
|
|
4271
|
+
name: Schema.Literal("payment_redirected"),
|
|
4272
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4273
|
+
});
|
|
4274
|
+
Schema.Struct({
|
|
4275
|
+
name: Schema.Literal("payment_failed"),
|
|
4276
|
+
props: Schema.optional(PaymentTargetTelemetryProps)
|
|
4277
|
+
});
|
|
4278
|
+
Schema.Struct({
|
|
4279
|
+
name: Schema.Literal("stream_created"),
|
|
4280
|
+
props: Schema.optional(StreamTargetTelemetryProps)
|
|
4281
|
+
});
|
|
4282
|
+
Schema.Struct({
|
|
4283
|
+
name: Schema.Literal("stream_claimed"),
|
|
4284
|
+
props: Schema.optional(StreamTargetTelemetryProps)
|
|
4285
|
+
});
|
|
4286
|
+
Schema.Struct({
|
|
4287
|
+
name: Schema.Literal("stream_cancelled"),
|
|
4288
|
+
props: Schema.optional(StreamTargetTelemetryProps)
|
|
4289
|
+
});
|
|
4290
|
+
Schema.Struct({
|
|
4291
|
+
name: Schema.Literal("stream_completed"),
|
|
4292
|
+
props: Schema.optional(StreamTargetTelemetryProps)
|
|
4293
|
+
});
|
|
4294
|
+
Schema.Struct({
|
|
4295
|
+
name: Schema.Literal("stream_failed"),
|
|
4296
|
+
props: Schema.optional(StreamTargetTelemetryProps)
|
|
4297
|
+
});
|
|
4298
|
+
Schema.Struct({
|
|
4299
|
+
name: Schema.Literal("withdrawal_requested"),
|
|
4300
|
+
props: Schema.optional(WithdrawalTargetTelemetryProps)
|
|
4301
|
+
});
|
|
4302
|
+
Schema.Struct({
|
|
4303
|
+
name: Schema.Literal("withdrawal_submitted"),
|
|
4304
|
+
props: Schema.optional(WithdrawalTargetTelemetryProps)
|
|
4305
|
+
});
|
|
4306
|
+
Schema.Struct({
|
|
4307
|
+
name: Schema.Literal("withdrawal_settled"),
|
|
4308
|
+
props: Schema.optional(WithdrawalTargetTelemetryProps)
|
|
4309
|
+
});
|
|
4310
|
+
Schema.Struct({
|
|
4311
|
+
name: Schema.Literal("withdrawal_failed"),
|
|
4312
|
+
props: Schema.optional(WithdrawalTargetTelemetryProps)
|
|
4313
|
+
});
|
|
4314
|
+
function redactTelemetryProps(name, props, options = {}) {
|
|
4315
|
+
if (props === void 0) return void 0;
|
|
4316
|
+
const clone = cloneProps$1(props);
|
|
4317
|
+
if (options.rawMode === true) return clone;
|
|
4318
|
+
for (const key of PII_PROP_KEYS_BY_EVENT[name] ?? []) redactProperty(clone, key);
|
|
4319
|
+
return clone;
|
|
4320
|
+
}
|
|
4321
|
+
const PII_PROP_KEYS_BY_EVENT = {
|
|
4322
|
+
auth_otp_requested: ["email"],
|
|
4323
|
+
auth_otp_delivered: ["email"],
|
|
4324
|
+
auth_otp_expired: ["email"],
|
|
4325
|
+
auth_failed: ["email"]
|
|
4326
|
+
};
|
|
4327
|
+
function redactProperty(props, key) {
|
|
4328
|
+
const value = props[key];
|
|
4329
|
+
if (typeof value === "string") props[key] = sha256Hex(value).slice(0, 12);
|
|
4330
|
+
}
|
|
4331
|
+
function cloneProps$1(props) {
|
|
4332
|
+
const cloned = {};
|
|
4333
|
+
for (const [key, value] of Object.entries(props)) cloned[key] = cloneTelemetryValue$1(value);
|
|
4334
|
+
return cloned;
|
|
4335
|
+
}
|
|
4336
|
+
function cloneTelemetryValue$1(value) {
|
|
4337
|
+
if (Array.isArray(value)) return value.map(cloneTelemetryValue$1);
|
|
4338
|
+
if (value === null || typeof value !== "object") return value;
|
|
4339
|
+
if (Object.getPrototypeOf(value) !== Object.prototype) return value;
|
|
4340
|
+
const cloned = {};
|
|
4341
|
+
for (const [key, nested] of Object.entries(value)) cloned[key] = cloneTelemetryValue$1(nested);
|
|
4342
|
+
return cloned;
|
|
4343
|
+
}
|
|
4344
|
+
const SHA256_INITIAL_HASH = [
|
|
4345
|
+
1779033703,
|
|
4346
|
+
3144134277,
|
|
4347
|
+
1013904242,
|
|
4348
|
+
2773480762,
|
|
4349
|
+
1359893119,
|
|
4350
|
+
2600822924,
|
|
4351
|
+
528734635,
|
|
4352
|
+
1541459225
|
|
4353
|
+
];
|
|
4354
|
+
const SHA256_K = [
|
|
4355
|
+
1116352408,
|
|
4356
|
+
1899447441,
|
|
4357
|
+
3049323471,
|
|
4358
|
+
3921009573,
|
|
4359
|
+
961987163,
|
|
4360
|
+
1508970993,
|
|
4361
|
+
2453635748,
|
|
4362
|
+
2870763221,
|
|
4363
|
+
3624381080,
|
|
4364
|
+
310598401,
|
|
4365
|
+
607225278,
|
|
4366
|
+
1426881987,
|
|
4367
|
+
1925078388,
|
|
4368
|
+
2162078206,
|
|
4369
|
+
2614888103,
|
|
4370
|
+
3248222580,
|
|
4371
|
+
3835390401,
|
|
4372
|
+
4022224774,
|
|
4373
|
+
264347078,
|
|
4374
|
+
604807628,
|
|
4375
|
+
770255983,
|
|
4376
|
+
1249150122,
|
|
4377
|
+
1555081692,
|
|
4378
|
+
1996064986,
|
|
4379
|
+
2554220882,
|
|
4380
|
+
2821834349,
|
|
4381
|
+
2952996808,
|
|
4382
|
+
3210313671,
|
|
4383
|
+
3336571891,
|
|
4384
|
+
3584528711,
|
|
4385
|
+
113926993,
|
|
4386
|
+
338241895,
|
|
4387
|
+
666307205,
|
|
4388
|
+
773529912,
|
|
4389
|
+
1294757372,
|
|
4390
|
+
1396182291,
|
|
4391
|
+
1695183700,
|
|
4392
|
+
1986661051,
|
|
4393
|
+
2177026350,
|
|
4394
|
+
2456956037,
|
|
4395
|
+
2730485921,
|
|
4396
|
+
2820302411,
|
|
4397
|
+
3259730800,
|
|
4398
|
+
3345764771,
|
|
4399
|
+
3516065817,
|
|
4400
|
+
3600352804,
|
|
4401
|
+
4094571909,
|
|
4402
|
+
275423344,
|
|
4403
|
+
430227734,
|
|
4404
|
+
506948616,
|
|
4405
|
+
659060556,
|
|
4406
|
+
883997877,
|
|
4407
|
+
958139571,
|
|
4408
|
+
1322822218,
|
|
4409
|
+
1537002063,
|
|
4410
|
+
1747873779,
|
|
4411
|
+
1955562222,
|
|
4412
|
+
2024104815,
|
|
4413
|
+
2227730452,
|
|
4414
|
+
2361852424,
|
|
4415
|
+
2428436474,
|
|
4416
|
+
2756734187,
|
|
4417
|
+
3204031479,
|
|
4418
|
+
3329325298
|
|
4419
|
+
];
|
|
4420
|
+
function sha256Hex(input) {
|
|
4421
|
+
const padded = padSha256Message(new TextEncoder().encode(input));
|
|
4422
|
+
const view = new DataView(padded.buffer, padded.byteOffset, padded.byteLength);
|
|
4423
|
+
const words = new Uint32Array(64);
|
|
4424
|
+
let h0 = SHA256_INITIAL_HASH[0];
|
|
4425
|
+
let h1 = SHA256_INITIAL_HASH[1];
|
|
4426
|
+
let h2 = SHA256_INITIAL_HASH[2];
|
|
4427
|
+
let h3 = SHA256_INITIAL_HASH[3];
|
|
4428
|
+
let h4 = SHA256_INITIAL_HASH[4];
|
|
4429
|
+
let h5 = SHA256_INITIAL_HASH[5];
|
|
4430
|
+
let h6 = SHA256_INITIAL_HASH[6];
|
|
4431
|
+
let h7 = SHA256_INITIAL_HASH[7];
|
|
4432
|
+
for (let offset = 0; offset < padded.byteLength; offset += 64) {
|
|
4433
|
+
for (let i = 0; i < 16; i++) words[i] = view.getUint32(offset + i * 4);
|
|
4434
|
+
for (let i = 16; i < 64; i++) {
|
|
4435
|
+
const s0 = rotr(words[i - 15], 7) ^ rotr(words[i - 15], 18) ^ words[i - 15] >>> 3;
|
|
4436
|
+
const s1 = rotr(words[i - 2], 17) ^ rotr(words[i - 2], 19) ^ words[i - 2] >>> 10;
|
|
4437
|
+
words[i] = words[i - 16] + s0 + words[i - 7] + s1 >>> 0;
|
|
4438
|
+
}
|
|
4439
|
+
let a = h0;
|
|
4440
|
+
let b = h1;
|
|
4441
|
+
let c = h2;
|
|
4442
|
+
let d = h3;
|
|
4443
|
+
let e = h4;
|
|
4444
|
+
let f = h5;
|
|
4445
|
+
let g = h6;
|
|
4446
|
+
let h = h7;
|
|
4447
|
+
for (let i = 0; i < 64; i++) {
|
|
4448
|
+
const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
4449
|
+
const ch = e & f ^ ~e & g;
|
|
4450
|
+
const temp1 = h + s1 + ch + SHA256_K[i] + words[i] >>> 0;
|
|
4451
|
+
const temp2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
|
|
4452
|
+
h = g;
|
|
4453
|
+
g = f;
|
|
4454
|
+
f = e;
|
|
4455
|
+
e = d + temp1 >>> 0;
|
|
4456
|
+
d = c;
|
|
4457
|
+
c = b;
|
|
4458
|
+
b = a;
|
|
4459
|
+
a = temp1 + temp2 >>> 0;
|
|
4460
|
+
}
|
|
4461
|
+
h0 = h0 + a >>> 0;
|
|
4462
|
+
h1 = h1 + b >>> 0;
|
|
4463
|
+
h2 = h2 + c >>> 0;
|
|
4464
|
+
h3 = h3 + d >>> 0;
|
|
4465
|
+
h4 = h4 + e >>> 0;
|
|
4466
|
+
h5 = h5 + f >>> 0;
|
|
4467
|
+
h6 = h6 + g >>> 0;
|
|
4468
|
+
h7 = h7 + h >>> 0;
|
|
4469
|
+
}
|
|
4470
|
+
return [
|
|
4471
|
+
h0,
|
|
4472
|
+
h1,
|
|
4473
|
+
h2,
|
|
4474
|
+
h3,
|
|
4475
|
+
h4,
|
|
4476
|
+
h5,
|
|
4477
|
+
h6,
|
|
4478
|
+
h7
|
|
4479
|
+
].map((word) => word.toString(16).padStart(8, "0")).join("");
|
|
4480
|
+
}
|
|
4481
|
+
function padSha256Message(bytes) {
|
|
4482
|
+
const bitLength = bytes.byteLength * 8;
|
|
4483
|
+
const zeroPadLength = (64 - (bytes.byteLength + 1 + 8) % 64) % 64;
|
|
4484
|
+
const output = new Uint8Array(bytes.byteLength + 1 + zeroPadLength + 8);
|
|
4485
|
+
output.set(bytes);
|
|
4486
|
+
output[bytes.byteLength] = 128;
|
|
4487
|
+
const view = new DataView(output.buffer);
|
|
4488
|
+
view.setUint32(output.byteLength - 8, Math.floor(bitLength / 4294967296));
|
|
4489
|
+
view.setUint32(output.byteLength - 4, bitLength >>> 0);
|
|
4490
|
+
return output;
|
|
4491
|
+
}
|
|
4492
|
+
function rotr(value, bits) {
|
|
4493
|
+
return value >>> bits | value << 32 - bits;
|
|
4494
|
+
}
|
|
4495
|
+
//#endregion
|
|
3272
4496
|
//#region src/ports/telemetry.ts
|
|
3273
4497
|
var TelemetryPortTag = class extends Context.Tag("@capxul/sdk/ports/TelemetryPort")() {};
|
|
3274
4498
|
//#endregion
|
|
@@ -3408,7 +4632,7 @@ function asRecordArgs(args) {
|
|
|
3408
4632
|
return { value: args };
|
|
3409
4633
|
}
|
|
3410
4634
|
function transportErrorFromThrown(operation, request, cause) {
|
|
3411
|
-
return transportErrorFromCapxul(operation, request, cause instanceof Error ? Errors
|
|
4635
|
+
return transportErrorFromCapxul(operation, request, cause instanceof Error ? Errors.providerError("transport", request.name, cause) : Errors.providerError("transport", request.name, new Error(String(cause))), cause);
|
|
3412
4636
|
}
|
|
3413
4637
|
//#endregion
|
|
3414
4638
|
//#region src/openfort/create-openfort-browser-signer.ts
|
|
@@ -3464,7 +4688,7 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
3464
4688
|
ok: false,
|
|
3465
4689
|
failure_mode: "no-secure-context"
|
|
3466
4690
|
});
|
|
3467
|
-
const error = Errors
|
|
4691
|
+
const error = Errors.providerError("openfort", "configure", /* @__PURE__ */ new Error("Web Crypto unavailable: browser is not a secure context"), { failure_mode: "no-secure-context" });
|
|
3468
4692
|
if (telemetry) captureExceptionSync(telemetry, error, {
|
|
3469
4693
|
layer: "openfort",
|
|
3470
4694
|
operation: "configure",
|
|
@@ -3510,7 +4734,7 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
3510
4734
|
if (isInsecureBrowserContext()) failNoSecureContext();
|
|
3511
4735
|
await openfort.waitForInitialization();
|
|
3512
4736
|
const accessToken = await fetchBetterAuthAccessToken();
|
|
3513
|
-
if (accessToken === null) throw Errors
|
|
4737
|
+
if (accessToken === null) throw Errors.notAuthenticated();
|
|
3514
4738
|
const encryptionResponse = await fetch(encryptionSessionUrl(), {
|
|
3515
4739
|
method: "POST",
|
|
3516
4740
|
credentials: "include",
|
|
@@ -3523,10 +4747,10 @@ function createOpenfortBrowserSignerFromBootstrap(bootstrap, options = {}) {
|
|
|
3523
4747
|
diagnostic?.trace("openfort.encryptionSession", { httpStatus: encryptionResponse.status });
|
|
3524
4748
|
if (!encryptionResponse.ok) {
|
|
3525
4749
|
const detail = await encryptionResponse.text();
|
|
3526
|
-
throw Errors
|
|
4750
|
+
throw Errors.providerError("openfort", "encryptionSession", /* @__PURE__ */ new Error(`Openfort encryption session failed (${encryptionResponse.status}): ${detail.slice(0, 200)}`));
|
|
3527
4751
|
}
|
|
3528
4752
|
const encryptionBody = await encryptionResponse.json();
|
|
3529
|
-
if (typeof encryptionBody.sessionId !== "string" || encryptionBody.sessionId.length === 0) throw Errors
|
|
4753
|
+
if (typeof encryptionBody.sessionId !== "string" || encryptionBody.sessionId.length === 0) throw Errors.providerError("openfort", "encryptionSession", /* @__PURE__ */ new Error("Openfort encryption session response missing sessionId"));
|
|
3530
4754
|
const embeddedState = await openfort.embeddedWallet.getEmbeddedState();
|
|
3531
4755
|
diagnostic?.trace("openfort.embeddedState", { state: embeddedState });
|
|
3532
4756
|
if (embeddedState !== EmbeddedState.READY) {
|
|
@@ -3715,7 +4939,7 @@ function createAuthFlowMachine() {
|
|
|
3715
4939
|
if (!/^\d{6}$/.test(context.request.otp)) return yield* Effect.fail(new AuthFlowError({
|
|
3716
4940
|
operation: "verifyOtp",
|
|
3717
4941
|
state: context.state.state,
|
|
3718
|
-
publicError: Errors
|
|
4942
|
+
publicError: Errors.invalidInput("otp", "must be a six digit code"),
|
|
3719
4943
|
publicCode: "INVALID_INPUT"
|
|
3720
4944
|
}));
|
|
3721
4945
|
if (!canTransition(context.state.state, "VerifyOtp")) return yield* Effect.fail(wrongState("VerifyOtp", context.state.state));
|
|
@@ -3724,7 +4948,7 @@ function createAuthFlowMachine() {
|
|
|
3724
4948
|
const now = yield* (yield* ClockPortTag).now.pipe(Effect.mapError((cause) => new AuthFlowError({
|
|
3725
4949
|
operation: "verifyOtp",
|
|
3726
4950
|
state: current.state,
|
|
3727
|
-
publicError: Errors
|
|
4951
|
+
publicError: Errors.providerError("clock", "now", cause),
|
|
3728
4952
|
publicCode: "PROVIDER_ERROR",
|
|
3729
4953
|
cause
|
|
3730
4954
|
})));
|
|
@@ -3732,7 +4956,7 @@ function createAuthFlowMachine() {
|
|
|
3732
4956
|
const failure = new AuthFlowError({
|
|
3733
4957
|
operation: "verifyOtp",
|
|
3734
4958
|
state: "otp_requested",
|
|
3735
|
-
publicError: Errors
|
|
4959
|
+
publicError: Errors.otpExpired({ expiredAt: Number(current.otpRequestedAt) + normalized.otpTtlMs }),
|
|
3736
4960
|
publicCode: "OTP_EXPIRED"
|
|
3737
4961
|
});
|
|
3738
4962
|
yield* emitTelemetry({
|
|
@@ -3793,7 +5017,7 @@ function createAuthFlowMachine() {
|
|
|
3793
5017
|
const now = yield* (yield* ClockPortTag).now.pipe(Effect.mapError((cause) => new AuthFlowError({
|
|
3794
5018
|
operation: "verifyOtp",
|
|
3795
5019
|
state: current.state,
|
|
3796
|
-
publicError: Errors
|
|
5020
|
+
publicError: Errors.providerError("clock", "now", cause),
|
|
3797
5021
|
publicCode: "PROVIDER_ERROR",
|
|
3798
5022
|
cause
|
|
3799
5023
|
})));
|
|
@@ -3801,7 +5025,7 @@ function createAuthFlowMachine() {
|
|
|
3801
5025
|
const failure = new AuthFlowError({
|
|
3802
5026
|
operation: "verifyOtp",
|
|
3803
5027
|
state: "error",
|
|
3804
|
-
publicError: Errors
|
|
5028
|
+
publicError: Errors.otpExpired({ expiredAt: Number(current.otpRequestedAt) + normalized.otpTtlMs }),
|
|
3805
5029
|
publicCode: "OTP_EXPIRED"
|
|
3806
5030
|
});
|
|
3807
5031
|
yield* emitTelemetry({
|
|
@@ -3854,12 +5078,12 @@ function bootAuthFlow(machine, input) {
|
|
|
3854
5078
|
return Ref.get(statusRef).pipe(Effect.flatMap((status) => status === "active" ? actor.send(toMachineRequest(request)).pipe(Effect.raceFirst(Deferred.await(stopDeferred).pipe(Effect.flatMap(() => Effect.fail(new AuthFlowError({
|
|
3855
5079
|
operation: "transition",
|
|
3856
5080
|
state: Effect.runSync(actor.get).state,
|
|
3857
|
-
publicError: Errors
|
|
5081
|
+
publicError: Errors.cancelled({ operation: "authFlow.send" }),
|
|
3858
5082
|
publicCode: "CANCELLED"
|
|
3859
5083
|
})))))) : Effect.fail(new AuthFlowError({
|
|
3860
5084
|
operation: "transition",
|
|
3861
5085
|
state: Effect.runSync(actor.get).state,
|
|
3862
|
-
publicError: Errors
|
|
5086
|
+
publicError: Errors.cancelled({ operation: "authFlow.send" }),
|
|
3863
5087
|
publicCode: "CANCELLED"
|
|
3864
5088
|
}))), Effect.tapError((failure) => failure.publicCode === "OTP_EXPIRED" ? Effect.void : emitTelemetry({
|
|
3865
5089
|
name: "auth_failed",
|
|
@@ -3906,7 +5130,7 @@ function requestOtpCompletion(email, anonDistinctId, options) {
|
|
|
3906
5130
|
const now = yield* (yield* ClockPortTag).now.pipe(Effect.mapError((cause) => new AuthFlowError({
|
|
3907
5131
|
operation: "requestOtp",
|
|
3908
5132
|
state: "sending_otp",
|
|
3909
|
-
publicError: Errors
|
|
5133
|
+
publicError: Errors.providerError("clock", "now", cause),
|
|
3910
5134
|
publicCode: "PROVIDER_ERROR",
|
|
3911
5135
|
cause
|
|
3912
5136
|
})));
|
|
@@ -3983,7 +5207,7 @@ function withAuthFlowTimeout(effect, operation, state, options) {
|
|
|
3983
5207
|
onTimeout: () => new AuthFlowError({
|
|
3984
5208
|
operation,
|
|
3985
5209
|
state,
|
|
3986
|
-
publicError: Errors
|
|
5210
|
+
publicError: Errors.providerTimeout("auth-flow", operation, timeoutMs),
|
|
3987
5211
|
publicCode: "PROVIDER_ERROR"
|
|
3988
5212
|
})
|
|
3989
5213
|
}));
|
|
@@ -4005,7 +5229,7 @@ function completeRequest(commit, deferred, input, control, effect, toFailureCont
|
|
|
4005
5229
|
const failure = new AuthFlowError({
|
|
4006
5230
|
operation: "transition",
|
|
4007
5231
|
state: "error",
|
|
4008
|
-
publicError: Errors
|
|
5232
|
+
publicError: Errors.unknown(cause),
|
|
4009
5233
|
publicCode: "UNKNOWN",
|
|
4010
5234
|
cause
|
|
4011
5235
|
});
|
|
@@ -4049,7 +5273,7 @@ function stoppedFailure() {
|
|
|
4049
5273
|
return new AuthFlowError({
|
|
4050
5274
|
operation: "transition",
|
|
4051
5275
|
state: "error",
|
|
4052
|
-
publicError: Errors
|
|
5276
|
+
publicError: Errors.cancelled({ operation: "authFlow.request" }),
|
|
4053
5277
|
publicCode: "CANCELLED"
|
|
4054
5278
|
});
|
|
4055
5279
|
}
|
|
@@ -4078,7 +5302,7 @@ function wrongState(request, state) {
|
|
|
4078
5302
|
return new AuthFlowError({
|
|
4079
5303
|
operation: "transition",
|
|
4080
5304
|
state,
|
|
4081
|
-
publicError: Errors
|
|
5305
|
+
publicError: Errors.wrongState({
|
|
4082
5306
|
method: request,
|
|
4083
5307
|
currentState: state,
|
|
4084
5308
|
validStates: AUTH_FLOW_TRANSITION_TABLE[state].valid
|
|
@@ -4097,9 +5321,9 @@ function toAuthFlowError(operation, state, error) {
|
|
|
4097
5321
|
});
|
|
4098
5322
|
}
|
|
4099
5323
|
function toCapxulError(operation, error) {
|
|
4100
|
-
if (error.cause instanceof CapxulError
|
|
4101
|
-
if (operation === "requestOtp" && error.kind === "provider") return Errors
|
|
4102
|
-
return Errors
|
|
5324
|
+
if (error.cause instanceof CapxulError) return error.cause;
|
|
5325
|
+
if (operation === "requestOtp" && error.kind === "provider") return Errors.emailDeliveryFailed("provider rejected OTP request");
|
|
5326
|
+
return Errors.providerError("auth-client", operation, /* @__PURE__ */ new Error("auth-client provider failure"));
|
|
4103
5327
|
}
|
|
4104
5328
|
function emitTelemetry(event) {
|
|
4105
5329
|
return Effect.gen(function* () {
|
|
@@ -4165,7 +5389,7 @@ function hasMachineActor(actor) {
|
|
|
4165
5389
|
*/
|
|
4166
5390
|
const getSessionProgramWithOptions = (options) => Effect.gen(function* () {
|
|
4167
5391
|
const deps = yield* CapxulDepsTag;
|
|
4168
|
-
const cached = yield* deps.authCache.getSession.pipe(Effect.mapError((e) => Errors
|
|
5392
|
+
const cached = yield* deps.authCache.getSession.pipe(Effect.mapError((e) => Errors.providerError("auth-cache", "getSession", e)));
|
|
4169
5393
|
const actorState = String(deps.actor.getSnapshot().value);
|
|
4170
5394
|
if (cached === null && (actorState === "otp_requested" || actorState === "sending_otp" || actorState === "verifying")) return null;
|
|
4171
5395
|
if (cached !== null && actorState !== "idle") return cached;
|
|
@@ -4205,25 +5429,25 @@ getSessionProgramWithOptions();
|
|
|
4205
5429
|
function verifyOtpProgram(input, options) {
|
|
4206
5430
|
return Effect.gen(function* () {
|
|
4207
5431
|
const deps = yield* CapxulDepsTag;
|
|
4208
|
-
if (!/^\d{6}$/.test(input.code)) return yield* Effect.fail(Errors
|
|
5432
|
+
if (!/^\d{6}$/.test(input.code)) return yield* Effect.fail(Errors.invalidInput("otp", "must be 6 digits"));
|
|
4209
5433
|
let email;
|
|
4210
5434
|
try {
|
|
4211
5435
|
email = toEmail(input.email);
|
|
4212
5436
|
} catch (err) {
|
|
4213
|
-
return yield* Effect.fail(err instanceof CapxulError
|
|
5437
|
+
return yield* Effect.fail(err instanceof CapxulError ? err : Errors.invalidInput("email", "invalid email"));
|
|
4214
5438
|
}
|
|
4215
5439
|
let value = String(deps.actor.getSnapshot().value);
|
|
4216
5440
|
if (value === "error") {
|
|
4217
5441
|
yield* sendAuthFlowRequest(deps.actor, { _tag: "ResumeOtpEntry" }).pipe(Effect.provide(authFlowLayer(deps)), Effect.mapError((failure) => failure.publicError));
|
|
4218
5442
|
value = "otp_requested";
|
|
4219
|
-
} else if (value !== "otp_requested") return yield* Effect.fail(Errors
|
|
5443
|
+
} else if (value !== "otp_requested") return yield* Effect.fail(Errors.wrongState({
|
|
4220
5444
|
method: "verifyOtp",
|
|
4221
5445
|
currentState: value,
|
|
4222
5446
|
validStates: ["otp_requested"]
|
|
4223
5447
|
}));
|
|
4224
5448
|
if (!hasMachineActor(deps.actor)) {
|
|
4225
5449
|
const next = deps.actor.getSnapshot();
|
|
4226
|
-
if (String(next.value) === "error") return yield* Effect.fail(next.context.error ?? Errors
|
|
5450
|
+
if (String(next.value) === "error") return yield* Effect.fail(next.context.error ?? Errors.unknown({ method: "verifyOtp" }));
|
|
4227
5451
|
}
|
|
4228
5452
|
const session = yield* sendAuthFlowRequest(deps.actor, {
|
|
4229
5453
|
_tag: "VerifyOtp",
|
|
@@ -4231,8 +5455,8 @@ function verifyOtpProgram(input, options) {
|
|
|
4231
5455
|
otp: input.code,
|
|
4232
5456
|
...depsRequestOptions(deps, options?.signal)
|
|
4233
5457
|
}).pipe(Effect.provide(authFlowLayer(deps)), Effect.map((snapshot) => snapshot[1].session), Effect.mapError((failure) => failure.publicError));
|
|
4234
|
-
if (session === null) return yield* Effect.fail(Errors
|
|
4235
|
-
yield* deps.authCache.setSession(session).pipe(Effect.mapError((e) => Errors
|
|
5458
|
+
if (session === null) return yield* Effect.fail(Errors.notAuthenticated());
|
|
5459
|
+
yield* deps.authCache.setSession(session).pipe(Effect.mapError((e) => Errors.providerError("auth-cache", "setSession", e)));
|
|
4236
5460
|
return session;
|
|
4237
5461
|
});
|
|
4238
5462
|
}
|
|
@@ -4256,7 +5480,7 @@ function depsRequestOptions(deps, signal) {
|
|
|
4256
5480
|
* JWT clear on failure, matching the original's sequential `if (!ok) return`.
|
|
4257
5481
|
*/
|
|
4258
5482
|
function clearAuthCacheEffect(authCache) {
|
|
4259
|
-
return authCache.clearSession.pipe(Effect.mapError((cause) => Errors
|
|
5483
|
+
return authCache.clearSession.pipe(Effect.mapError((cause) => Errors.providerError("auth-cache", "clearSession", cause)), Effect.zipRight(authCache.clearJwt.pipe(Effect.mapError((cause) => Errors.providerError("auth-cache", "clearJwt", cause)))));
|
|
4260
5484
|
}
|
|
4261
5485
|
function cryptoRandomId() {
|
|
4262
5486
|
const bytes = new Uint8Array(8);
|
|
@@ -4268,9 +5492,9 @@ const canSendOtpProgram = (input, options) => Effect.gen(function* () {
|
|
|
4268
5492
|
const deps = yield* CapxulDepsTag;
|
|
4269
5493
|
const email = yield* Effect.try({
|
|
4270
5494
|
try: () => toEmail(input.email),
|
|
4271
|
-
catch: (err) => err instanceof CapxulError
|
|
5495
|
+
catch: (err) => err instanceof CapxulError ? err : Errors.invalidInput("email", "invalid email")
|
|
4272
5496
|
});
|
|
4273
|
-
return yield* deps.authClient.canSendOtp({ email }, options?.signal === void 0 ? void 0 : { signal: options.signal }).pipe(Effect.mapError((failure) => failure.cause instanceof CapxulError
|
|
5497
|
+
return yield* deps.authClient.canSendOtp({ email }, options?.signal === void 0 ? void 0 : { signal: options.signal }).pipe(Effect.mapError((failure) => failure.cause instanceof CapxulError ? failure.cause : Errors.providerError("auth-client", "canSendOtp", failure.cause)));
|
|
4274
5498
|
});
|
|
4275
5499
|
/**
|
|
4276
5500
|
* `signIn` as a single Effect requiring ONLY `CapxulDepsTag`. Faithful
|
|
@@ -4283,10 +5507,10 @@ const signInProgram = (input, options) => Effect.gen(function* () {
|
|
|
4283
5507
|
const deps = yield* CapxulDepsTag;
|
|
4284
5508
|
const email = yield* Effect.try({
|
|
4285
5509
|
try: () => toEmail(input.email),
|
|
4286
|
-
catch: (err) => err instanceof CapxulError
|
|
5510
|
+
catch: (err) => err instanceof CapxulError ? err : Errors.invalidInput("email", "invalid email")
|
|
4287
5511
|
});
|
|
4288
5512
|
const value = String(deps.actor.getSnapshot().value);
|
|
4289
|
-
if (value !== "idle" && value !== "otp_requested" && value !== "error") return yield* Effect.fail(Errors
|
|
5513
|
+
if (value !== "idle" && value !== "otp_requested" && value !== "error") return yield* Effect.fail(Errors.wrongState({
|
|
4290
5514
|
method: "signIn",
|
|
4291
5515
|
currentState: value,
|
|
4292
5516
|
validStates: [
|
|
@@ -4304,7 +5528,7 @@ const signInProgram = (input, options) => Effect.gen(function* () {
|
|
|
4304
5528
|
email,
|
|
4305
5529
|
...depsRequestOptions(deps, options?.signal)
|
|
4306
5530
|
}).pipe(Effect.provide(authFlowLayer(deps)), Effect.mapError((failure) => failure.publicError));
|
|
4307
|
-
const now = yield* deps.clock.now.pipe(Effect.mapError((cause) => Errors
|
|
5531
|
+
const now = yield* deps.clock.now.pipe(Effect.mapError((cause) => Errors.providerError("clock", "now", cause)));
|
|
4308
5532
|
return {
|
|
4309
5533
|
sessionId: cryptoRandomId(),
|
|
4310
5534
|
expiresAt: now + (deps.otpTtlMs ?? 3e5)
|
|
@@ -4323,7 +5547,7 @@ const signOutProgramWithOptions = (options) => Effect.gen(function* () {
|
|
|
4323
5547
|
const deps = yield* CapxulDepsTag;
|
|
4324
5548
|
let value = String(deps.actor.getSnapshot().value);
|
|
4325
5549
|
if (value === "idle") {
|
|
4326
|
-
const cached = yield* deps.authCache.getSession.pipe(Effect.mapError((e) => Errors
|
|
5550
|
+
const cached = yield* deps.authCache.getSession.pipe(Effect.mapError((e) => Errors.providerError("auth-cache", "getSession", e)));
|
|
4327
5551
|
if (cached !== null) {
|
|
4328
5552
|
yield* sendAuthFlowRequest(deps.actor, {
|
|
4329
5553
|
_tag: "RestoreCachedSession",
|
|
@@ -4331,7 +5555,7 @@ const signOutProgramWithOptions = (options) => Effect.gen(function* () {
|
|
|
4331
5555
|
}).pipe(Effect.provide(authFlowLayer(deps)), Effect.mapError((failure) => failure.publicError));
|
|
4332
5556
|
value = String(deps.actor.getSnapshot().value);
|
|
4333
5557
|
}
|
|
4334
|
-
if (value === "idle") return yield* Effect.fail(Errors
|
|
5558
|
+
if (value === "idle") return yield* Effect.fail(Errors.wrongState({
|
|
4335
5559
|
method: "signOut",
|
|
4336
5560
|
currentState: value,
|
|
4337
5561
|
validStates: [
|
|
@@ -4366,21 +5590,21 @@ function makeAuthMethods(deps) {
|
|
|
4366
5590
|
async canSendOtp(input, options) {
|
|
4367
5591
|
if (options?.signal?.aborted) return {
|
|
4368
5592
|
ok: false,
|
|
4369
|
-
error: Errors
|
|
5593
|
+
error: Errors.cancelled({ operation: "canSendOtp" })
|
|
4370
5594
|
};
|
|
4371
5595
|
return toCapxulResult(canSendOtpProgram(input, options), capxulDepsLayer(deps));
|
|
4372
5596
|
},
|
|
4373
5597
|
async signIn(input, options) {
|
|
4374
5598
|
if (options?.signal?.aborted) return {
|
|
4375
5599
|
ok: false,
|
|
4376
|
-
error: Errors
|
|
5600
|
+
error: Errors.cancelled({ operation: "signIn" })
|
|
4377
5601
|
};
|
|
4378
5602
|
return toCapxulResult(signInProgram(input, options), capxulDepsLayer(deps));
|
|
4379
5603
|
},
|
|
4380
5604
|
async verifyOtp(input, options) {
|
|
4381
5605
|
if (options?.signal?.aborted) return {
|
|
4382
5606
|
ok: false,
|
|
4383
|
-
error: Errors
|
|
5607
|
+
error: Errors.cancelled({ operation: "verifyOtp" })
|
|
4384
5608
|
};
|
|
4385
5609
|
const result = await toCapxulResult(verifyOtpProgram(input, options), capxulDepsLayer(deps));
|
|
4386
5610
|
if (!result.ok) return result;
|
|
@@ -4389,13 +5613,13 @@ function makeAuthMethods(deps) {
|
|
|
4389
5613
|
try {
|
|
4390
5614
|
await afterVerifyOtp();
|
|
4391
5615
|
} catch (cause) {
|
|
4392
|
-
if (cause instanceof CapxulError
|
|
5616
|
+
if (cause instanceof CapxulError) return {
|
|
4393
5617
|
ok: false,
|
|
4394
5618
|
error: cause
|
|
4395
5619
|
};
|
|
4396
5620
|
return {
|
|
4397
5621
|
ok: false,
|
|
4398
|
-
error: Errors
|
|
5622
|
+
error: Errors.providerError("sdk", "afterVerifyOtp", cause)
|
|
4399
5623
|
};
|
|
4400
5624
|
}
|
|
4401
5625
|
return result;
|
|
@@ -4403,14 +5627,14 @@ function makeAuthMethods(deps) {
|
|
|
4403
5627
|
async signOut(options) {
|
|
4404
5628
|
if (options?.signal?.aborted) return {
|
|
4405
5629
|
ok: false,
|
|
4406
|
-
error: Errors
|
|
5630
|
+
error: Errors.cancelled({ operation: "signOut" })
|
|
4407
5631
|
};
|
|
4408
5632
|
return toCapxulResult(signOutProgramWithOptions(options), capxulDepsLayer(deps));
|
|
4409
5633
|
},
|
|
4410
5634
|
async getSession(options) {
|
|
4411
5635
|
if (options?.signal?.aborted) return {
|
|
4412
5636
|
ok: false,
|
|
4413
|
-
error: Errors
|
|
5637
|
+
error: Errors.cancelled({ operation: "getSession" })
|
|
4414
5638
|
};
|
|
4415
5639
|
return toCapxulResult(getSessionProgramWithOptions(options), capxulDepsLayer(deps));
|
|
4416
5640
|
}
|
|
@@ -4458,13 +5682,13 @@ function provisionSmartAccountProgram() {
|
|
|
4458
5682
|
const deps = yield* SmartAccountDepsTag;
|
|
4459
5683
|
const snap = deps.actor.getSnapshot();
|
|
4460
5684
|
const value = snap.value;
|
|
4461
|
-
if (value !== "authenticated") return yield* Effect.fail(Errors
|
|
5685
|
+
if (value !== "authenticated") return yield* Effect.fail(Errors.wrongState({
|
|
4462
5686
|
method: "smartAccount.provision",
|
|
4463
5687
|
currentState: value,
|
|
4464
5688
|
validStates: ["authenticated"]
|
|
4465
5689
|
}));
|
|
4466
5690
|
const session = snap.context.session;
|
|
4467
|
-
if (session === null) return yield* Effect.fail(Errors
|
|
5691
|
+
if (session === null) return yield* Effect.fail(Errors.notAuthenticated());
|
|
4468
5692
|
const provisioned = yield* deps.smartAccountPort.provision({
|
|
4469
5693
|
authUserId: session.authUserId,
|
|
4470
5694
|
chainId: deps.chainId
|
|
@@ -4480,7 +5704,7 @@ function makeSmartAccountMethods(deps) {
|
|
|
4480
5704
|
async loadCurrent(options) {
|
|
4481
5705
|
if (options?.signal?.aborted) return {
|
|
4482
5706
|
ok: false,
|
|
4483
|
-
error: Errors
|
|
5707
|
+
error: Errors.cancelled({ operation: "smartAccount.loadCurrent" })
|
|
4484
5708
|
};
|
|
4485
5709
|
return toCapxulResult(loadSmartAccountProgram, smartAccountDepsLayer(deps));
|
|
4486
5710
|
},
|
|
@@ -4508,13 +5732,13 @@ function identityDepsLayer(deps) {
|
|
|
4508
5732
|
*/
|
|
4509
5733
|
const loadIdentityProgram = Effect.gen(function* () {
|
|
4510
5734
|
const deps = yield* IdentityDepsTag;
|
|
4511
|
-
if (deps.actor === void 0) return yield* Effect.fail(Errors
|
|
5735
|
+
if (deps.actor === void 0) return yield* Effect.fail(Errors.notAuthenticated());
|
|
4512
5736
|
const snapshot = deps.actor.getSnapshot();
|
|
4513
5737
|
const existingError = snapshot.context.error;
|
|
4514
|
-
if (existingError instanceof CapxulError
|
|
5738
|
+
if (existingError instanceof CapxulError) return yield* Effect.fail(existingError);
|
|
4515
5739
|
const authUserId = snapshot.context.session?.authUserId;
|
|
4516
5740
|
if (authUserId === void 0) return null;
|
|
4517
|
-
return yield* deps.identityPort.loadByAuthUserId(authUserId).pipe(Effect.catchAllDefect((cause) => Effect.fail(identityErrorFromCapxul("loadByAuthUserId", cause instanceof CapxulError
|
|
5741
|
+
return yield* deps.identityPort.loadByAuthUserId(authUserId).pipe(Effect.catchAllDefect((cause) => Effect.fail(identityErrorFromCapxul("loadByAuthUserId", cause instanceof CapxulError ? cause : Errors.unknown(cause), cause))), Effect.mapError((failure) => failure.publicError));
|
|
4518
5742
|
});
|
|
4519
5743
|
//#endregion
|
|
4520
5744
|
//#region src/client/identity.ts
|
|
@@ -4522,7 +5746,7 @@ function makeIdentityMethods(deps) {
|
|
|
4522
5746
|
return { async loadCurrent(options) {
|
|
4523
5747
|
if (options?.signal?.aborted) return {
|
|
4524
5748
|
ok: false,
|
|
4525
|
-
error: Errors
|
|
5749
|
+
error: Errors.cancelled({ operation: "identity.loadCurrent" })
|
|
4526
5750
|
};
|
|
4527
5751
|
return toCapxulResult(loadIdentityProgram, identityDepsLayer(deps));
|
|
4528
5752
|
} };
|
|
@@ -4671,14 +5895,14 @@ function makeAccountsMethods(deps) {
|
|
|
4671
5895
|
async read(options) {
|
|
4672
5896
|
if (options?.signal?.aborted) return {
|
|
4673
5897
|
ok: false,
|
|
4674
|
-
error: Errors
|
|
5898
|
+
error: Errors.cancelled({ operation: "accounts.read" })
|
|
4675
5899
|
};
|
|
4676
5900
|
return toCapxulResult(readAccountProgram, accountsDepsLayer(deps));
|
|
4677
5901
|
},
|
|
4678
5902
|
async fund(amount, options) {
|
|
4679
5903
|
if (options?.signal?.aborted) return {
|
|
4680
5904
|
ok: false,
|
|
4681
|
-
error: Errors
|
|
5905
|
+
error: Errors.cancelled({ operation: "accounts.fund" })
|
|
4682
5906
|
};
|
|
4683
5907
|
return toCapxulResult(fundFromFaucetProgram(amount), accountsDepsLayer(deps));
|
|
4684
5908
|
}
|
|
@@ -5420,42 +6644,42 @@ function makeSubAccountsMethods(deps) {
|
|
|
5420
6644
|
async create(accountId, input, options) {
|
|
5421
6645
|
if (options?.signal?.aborted) return {
|
|
5422
6646
|
ok: false,
|
|
5423
|
-
error: Errors
|
|
6647
|
+
error: Errors.cancelled({ operation: "subAccounts.create" })
|
|
5424
6648
|
};
|
|
5425
6649
|
return toCapxulResult(createSubAccountProgram(accountId, input.name), layer);
|
|
5426
6650
|
},
|
|
5427
6651
|
async get(subAccountId, options) {
|
|
5428
6652
|
if (options?.signal?.aborted) return {
|
|
5429
6653
|
ok: false,
|
|
5430
|
-
error: Errors
|
|
6654
|
+
error: Errors.cancelled({ operation: "subAccounts.get" })
|
|
5431
6655
|
};
|
|
5432
6656
|
return toCapxulResult(getSubAccountProgram(subAccountId), layer);
|
|
5433
6657
|
},
|
|
5434
6658
|
async list(accountId, options) {
|
|
5435
6659
|
if (options?.signal?.aborted) return {
|
|
5436
6660
|
ok: false,
|
|
5437
|
-
error: Errors
|
|
6661
|
+
error: Errors.cancelled({ operation: "subAccounts.list" })
|
|
5438
6662
|
};
|
|
5439
6663
|
return toCapxulResult(listSubAccountsProgram(accountId), layer);
|
|
5440
6664
|
},
|
|
5441
6665
|
async rename(subAccountId, name, options) {
|
|
5442
6666
|
if (options?.signal?.aborted) return {
|
|
5443
6667
|
ok: false,
|
|
5444
|
-
error: Errors
|
|
6668
|
+
error: Errors.cancelled({ operation: "subAccounts.rename" })
|
|
5445
6669
|
};
|
|
5446
6670
|
return toCapxulResult(renameSubAccountProgram(subAccountId, name), layer);
|
|
5447
6671
|
},
|
|
5448
6672
|
async delete(subAccountId, options) {
|
|
5449
6673
|
if (options?.signal?.aborted) return {
|
|
5450
6674
|
ok: false,
|
|
5451
|
-
error: Errors
|
|
6675
|
+
error: Errors.cancelled({ operation: "subAccounts.delete" })
|
|
5452
6676
|
};
|
|
5453
6677
|
return toCapxulResult(deleteSubAccountProgram(subAccountId), layer);
|
|
5454
6678
|
},
|
|
5455
6679
|
async transfer(input, options) {
|
|
5456
6680
|
if (options?.signal?.aborted) return {
|
|
5457
6681
|
ok: false,
|
|
5458
|
-
error: Errors
|
|
6682
|
+
error: Errors.cancelled({ operation: "subAccounts.transfer" })
|
|
5459
6683
|
};
|
|
5460
6684
|
return toCapxulResult(transferSubAccountProgram(input), layer);
|
|
5461
6685
|
}
|
|
@@ -5559,18 +6783,18 @@ function isOrgTelemetryDebugEnabled() {
|
|
|
5559
6783
|
//#endregion
|
|
5560
6784
|
//#region src/client/org-spend-gate.ts
|
|
5561
6785
|
function evaluateSpendGate(input) {
|
|
5562
|
-
if (!input.activeMember) return reject("not_member", Errors
|
|
5563
|
-
if (!recipientAllowed(input.recipients, input.recipient)) return reject("invalid_recipient", Errors
|
|
5564
|
-
if (!subAccountAllowed(input.subAccounts, input.subAccountId)) return reject("wrong_envelope", Errors
|
|
6786
|
+
if (!input.activeMember) return reject("not_member", Errors.invalidInput("member", "you are not an active member"));
|
|
6787
|
+
if (!recipientAllowed(input.recipients, input.recipient)) return reject("invalid_recipient", Errors.invalidRecipient("recipient is not allowed by this role"));
|
|
6788
|
+
if (!subAccountAllowed(input.subAccounts, input.subAccountId)) return reject("wrong_envelope", Errors.invalidInput("subAccountId", "sub-account not in scope for this role"));
|
|
5565
6789
|
const amount = parseRaw(input.amountRaw, "amountRaw");
|
|
5566
6790
|
const balance = parseRaw(input.subAccountBalanceRaw, "subAccountBalanceRaw");
|
|
5567
|
-
if (amount > balance) return reject("insufficient_subaccount_balance", Errors
|
|
6791
|
+
if (amount > balance) return reject("insufficient_subaccount_balance", Errors.insufficientBalance(input.currency, balance.toString(10), amount.toString(10)));
|
|
5568
6792
|
const perTxCap = parseOptionalRaw(input.perTxCapRaw, "perTxCapRaw");
|
|
5569
|
-
if (perTxCap !== null && amount > perTxCap) return reject("over_cap", Errors
|
|
6793
|
+
if (perTxCap !== null && amount > perTxCap) return reject("over_cap", Errors.insufficientBalance("role per-transaction cap", perTxCap.toString(10), amount.toString(10)));
|
|
5570
6794
|
const perDayCap = parseOptionalRaw(input.perDayCapRaw, "perDayCapRaw");
|
|
5571
6795
|
if (perDayCap !== null) {
|
|
5572
6796
|
const remaining = perDayCap - (parseOptionalRaw(input.spentTodayRaw, "spentTodayRaw") ?? 0n);
|
|
5573
|
-
if (remaining < amount) return reject("daily_cap_exhausted", Errors
|
|
6797
|
+
if (remaining < amount) return reject("daily_cap_exhausted", Errors.insufficientBalance("role daily cap", remaining.toString(10), amount.toString(10)));
|
|
5574
6798
|
}
|
|
5575
6799
|
return { ok: true };
|
|
5576
6800
|
}
|
|
@@ -5595,7 +6819,7 @@ function parseOptionalRaw(value, field) {
|
|
|
5595
6819
|
return parseRaw(value, field);
|
|
5596
6820
|
}
|
|
5597
6821
|
function parseRaw(value, field) {
|
|
5598
|
-
if (!/^[0-9]+$/.test(value)) throw Errors
|
|
6822
|
+
if (!/^[0-9]+$/.test(value)) throw Errors.invalidInput(field, "must be a non-negative integer string");
|
|
5599
6823
|
return BigInt(value);
|
|
5600
6824
|
}
|
|
5601
6825
|
//#endregion
|
|
@@ -5612,7 +6836,7 @@ function missingLiveOrgDep(portName) {
|
|
|
5612
6836
|
}
|
|
5613
6837
|
/** Zero `Money` in the USDX-backed display currency (a fresh Org's treasury). */
|
|
5614
6838
|
function zeroMoney() {
|
|
5615
|
-
return fromWei("0",
|
|
6839
|
+
return fromWei("0", 6, "USD");
|
|
5616
6840
|
}
|
|
5617
6841
|
/** A fresh Org's treasury Account: `$0` balance, `available === balance`. */
|
|
5618
6842
|
function zeroTreasury(orgId) {
|
|
@@ -5964,7 +7188,7 @@ function gateOneRun(input) {
|
|
|
5964
7188
|
subAccountBalanceRaw: subtractNonNegative(baseGateInput.subAccountBalanceRaw, accumulated),
|
|
5965
7189
|
spentTodayRaw: (BigInt(authority.spentTodayRaw ?? "0") + accumulated).toString(10)
|
|
5966
7190
|
}),
|
|
5967
|
-
catch: (cause) => isCapxulError
|
|
7191
|
+
catch: (cause) => isCapxulError(cause) ? cause : Errors.unknown(cause)
|
|
5968
7192
|
});
|
|
5969
7193
|
if (!decision.ok) return yield* Effect.fail(decision.error);
|
|
5970
7194
|
return {
|
|
@@ -5984,7 +7208,7 @@ function spendViaPaymentsProgram(orgId, input) {
|
|
|
5984
7208
|
if (deps.orgSpendPort === void 0 && !isHermeticOrgDeps(deps)) return yield* Effect.fail(missingLiveOrgDep("orgSpendPort"));
|
|
5985
7209
|
const to = yield* Effect.try({
|
|
5986
7210
|
try: () => refToRecipientString(input.to),
|
|
5987
|
-
catch: (cause) => isCapxulError
|
|
7211
|
+
catch: (cause) => isCapxulError(cause) ? cause : Errors.invalidInput("to", "invalid Ref")
|
|
5988
7212
|
});
|
|
5989
7213
|
const gated = yield* gateOneRun({
|
|
5990
7214
|
deps,
|
|
@@ -6017,7 +7241,7 @@ function batchPayrollProgram(orgId, input) {
|
|
|
6017
7241
|
const gated = [];
|
|
6018
7242
|
const recipients = yield* Effect.try({
|
|
6019
7243
|
try: () => input.runs.map((run) => refToRecipientString(run.to)),
|
|
6020
|
-
catch: (cause) => isCapxulError
|
|
7244
|
+
catch: (cause) => isCapxulError(cause) ? cause : Errors.invalidInput("to", "invalid Ref")
|
|
6021
7245
|
});
|
|
6022
7246
|
let accumulatedRaw = 0n;
|
|
6023
7247
|
for (const [index, run] of input.runs.entries()) {
|
|
@@ -6337,7 +7561,7 @@ async function runCompletePersonalOnboarding(ops, input) {
|
|
|
6337
7561
|
const validated = validatePersonalInput(input);
|
|
6338
7562
|
if (!validated.ok) return validated;
|
|
6339
7563
|
const session = await ops.currentSession();
|
|
6340
|
-
if (session === null) return fail(Errors
|
|
7564
|
+
if (session === null) return fail(Errors.notAuthenticated());
|
|
6341
7565
|
const written = await ops.completeIdentityOnboarding({
|
|
6342
7566
|
authUserId: session.authUserId,
|
|
6343
7567
|
email: session.email,
|
|
@@ -6360,7 +7584,7 @@ async function runCompleteOrganizationOnboarding(ops, input) {
|
|
|
6360
7584
|
const validated = validateOrganizationInput(input);
|
|
6361
7585
|
if (!validated.ok) return validated;
|
|
6362
7586
|
const session = await ops.currentSession();
|
|
6363
|
-
if (session === null) return fail(Errors
|
|
7587
|
+
if (session === null) return fail(Errors.notAuthenticated());
|
|
6364
7588
|
const written = await ops.completeIdentityOnboarding({
|
|
6365
7589
|
authUserId: session.authUserId,
|
|
6366
7590
|
email: session.email,
|
|
@@ -6432,7 +7656,7 @@ function validateOrganizationInput(input) {
|
|
|
6432
7656
|
}
|
|
6433
7657
|
function requireNonEmpty(value, field) {
|
|
6434
7658
|
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
6435
|
-
if (trimmed.length === 0) return fail(Errors
|
|
7659
|
+
if (trimmed.length === 0) return fail(Errors.invalidInput(field, "must be a non-empty string"));
|
|
6436
7660
|
return {
|
|
6437
7661
|
ok: true,
|
|
6438
7662
|
value: trimmed
|
|
@@ -6460,12 +7684,12 @@ function parseAddress(value, field) {
|
|
|
6460
7684
|
}
|
|
6461
7685
|
function invalidFrom(field, cause, fallback) {
|
|
6462
7686
|
const message = cause instanceof Error && cause.message.length > 0 ? cause.message : fallback;
|
|
6463
|
-
return Errors
|
|
7687
|
+
return Errors.invalidInput(field, message);
|
|
6464
7688
|
}
|
|
6465
7689
|
function fail(error) {
|
|
6466
7690
|
return {
|
|
6467
7691
|
ok: false,
|
|
6468
|
-
error: error instanceof CapxulError
|
|
7692
|
+
error: error instanceof CapxulError ? error : Errors.unknown(error)
|
|
6469
7693
|
};
|
|
6470
7694
|
}
|
|
6471
7695
|
//#endregion
|
|
@@ -6482,14 +7706,14 @@ function makeOnboardingMethods(ops) {
|
|
|
6482
7706
|
completePersonal(input, options) {
|
|
6483
7707
|
if (options?.signal?.aborted) return Promise.resolve({
|
|
6484
7708
|
ok: false,
|
|
6485
|
-
error: Errors
|
|
7709
|
+
error: Errors.cancelled({ operation: "onboarding.completePersonal" })
|
|
6486
7710
|
});
|
|
6487
7711
|
return runCompletePersonalOnboarding(ops, input);
|
|
6488
7712
|
},
|
|
6489
7713
|
completeOrganization(input, options) {
|
|
6490
7714
|
if (options?.signal?.aborted) return Promise.resolve({
|
|
6491
7715
|
ok: false,
|
|
6492
|
-
error: Errors
|
|
7716
|
+
error: Errors.cancelled({ operation: "onboarding.completeOrganization" })
|
|
6493
7717
|
});
|
|
6494
7718
|
return runCompleteOrganizationOnboarding(ops, input);
|
|
6495
7719
|
}
|
|
@@ -6950,7 +8174,7 @@ function validateCreateCapxulClientInput(input) {
|
|
|
6950
8174
|
const runtime = input.runtime ?? detectRuntime();
|
|
6951
8175
|
if ((input.requirement ?? "none") === "deployed" && input.signer === void 0 && runtime !== "browser") return {
|
|
6952
8176
|
ok: false,
|
|
6953
|
-
error: Errors
|
|
8177
|
+
error: Errors.invalidInput("signer", "required when requirement is \"deployed\"")
|
|
6954
8178
|
};
|
|
6955
8179
|
return {
|
|
6956
8180
|
ok: true,
|
|
@@ -6983,10 +8207,10 @@ function detectRuntime() {
|
|
|
6983
8207
|
return globalAny.window !== void 0 || globalAny.document !== void 0 ? "browser" : "node";
|
|
6984
8208
|
}
|
|
6985
8209
|
function derivedBrowserOrigin(runtime) {
|
|
6986
|
-
if (runtime !== "browser") throw Errors
|
|
8210
|
+
if (runtime !== "browser") throw Errors.invalidInput("origin", "required outside browser runtime");
|
|
6987
8211
|
const globalAny = globalThis;
|
|
6988
8212
|
if (typeof globalAny.location?.origin === "string" && globalAny.location.origin.length > 0) return globalAny.location.origin;
|
|
6989
|
-
throw Errors
|
|
8213
|
+
throw Errors.invalidInput("origin", "required when browser location is unavailable");
|
|
6990
8214
|
}
|
|
6991
8215
|
/**
|
|
6992
8216
|
* Browser local dev serves `/api/auth` via the Vite proxy on `window.location.origin`
|
|
@@ -7055,20 +8279,20 @@ function normalizeHttpUrl(field, raw) {
|
|
|
7055
8279
|
try {
|
|
7056
8280
|
parsed = new URL(raw);
|
|
7057
8281
|
} catch {
|
|
7058
|
-
throw Errors
|
|
8282
|
+
throw Errors.invalidInput(field, "must be an http or https URL");
|
|
7059
8283
|
}
|
|
7060
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw Errors
|
|
8284
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw Errors.invalidInput(field, "must be an http or https URL");
|
|
7061
8285
|
return parsed.toString().replace(/\/$/, "");
|
|
7062
8286
|
}
|
|
7063
8287
|
function toPublicError(cause, operation) {
|
|
7064
|
-
if (cause instanceof CapxulError
|
|
8288
|
+
if (cause instanceof CapxulError) return cause;
|
|
7065
8289
|
if (typeof cause === "object" && cause !== null) {
|
|
7066
8290
|
const publicError = cause.publicError;
|
|
7067
|
-
if (publicError instanceof CapxulError
|
|
8291
|
+
if (publicError instanceof CapxulError) return publicError;
|
|
7068
8292
|
const nestedCause = cause.cause;
|
|
7069
|
-
if (nestedCause instanceof CapxulError
|
|
8293
|
+
if (nestedCause instanceof CapxulError) return nestedCause;
|
|
7070
8294
|
}
|
|
7071
|
-
return Errors
|
|
8295
|
+
return Errors.providerError("sdk-production-adapters", operation, cause);
|
|
7072
8296
|
}
|
|
7073
8297
|
function idempotentClose(close) {
|
|
7074
8298
|
let closed = false;
|