@capxul/mcp 2.5.4 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.mjs +2470 -611
- package/package.json +3 -3
package/dist/main.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { createHash, randomBytes } from "node:crypto";
|
|
|
7
7
|
import { createServer } from "node:http";
|
|
8
8
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
9
9
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
-
import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeFunctionData, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, isAddress, isHex, keccak256, pad, padHex, parseUnits, recoverAddress, size, slice, stringToHex, toBytes, toEventSelector, toFunctionSelector, toFunctionSignature, toHex, zeroAddress } from "viem";
|
|
10
|
+
import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeErrorResult, decodeFunctionData, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, isAddress, isHex, keccak256, pad, padHex, parseUnits, recoverAddress, size, slice, stringToHex, toBytes, toEventSelector, toFunctionSelector, toFunctionSignature, toHex, zeroAddress } from "viem";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { Cause, Context, Data, Deferred, Duration, Effect, Exit, Fiber, Layer, Queue, Ref, Result, Schedule, Schema, SchemaGetter, SchemaIssue, SchemaParser, Scope, Struct, Tracer } from "effect";
|
|
13
13
|
import { privateKeyToAccount, toAccount } from "viem/accounts";
|
|
@@ -240,7 +240,138 @@ function normalizeEmail(email) {
|
|
|
240
240
|
}
|
|
241
241
|
//#endregion
|
|
242
242
|
//#region package.json
|
|
243
|
-
var version$2 = "2.
|
|
243
|
+
var version$2 = "2.6.0";
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region ../../packages/errors/src/chain-cause.ts
|
|
246
|
+
/**
|
|
247
|
+
* Why an operation failed — the one flat vocabulary. The first four are the
|
|
248
|
+
* auth/provider diagnoses that predate this file. The rest name the chain
|
|
249
|
+
* path. `FailureMode` is derived from this list so a runtime membership check
|
|
250
|
+
* (the SDK's `$exception` projection, the observability schema) and the type
|
|
251
|
+
* can never drift apart.
|
|
252
|
+
*/
|
|
253
|
+
const FAILURE_MODES$1 = [
|
|
254
|
+
"auth-origin-mismatch",
|
|
255
|
+
"stale-openfort-cache",
|
|
256
|
+
"app-env-allowlist",
|
|
257
|
+
"no-secure-context",
|
|
258
|
+
"rate-limited",
|
|
259
|
+
"timeout",
|
|
260
|
+
"upstream-down",
|
|
261
|
+
"revert",
|
|
262
|
+
"insufficient-balance",
|
|
263
|
+
"insufficient-allowance",
|
|
264
|
+
"rejected",
|
|
265
|
+
"unauthorized",
|
|
266
|
+
"unknown"
|
|
267
|
+
];
|
|
268
|
+
function isFailureMode(value) {
|
|
269
|
+
return typeof value === "string" && FAILURE_MODES$1.includes(value);
|
|
270
|
+
}
|
|
271
|
+
/** Who answered. `alto` is the bundler; `gateway` is the AA gateway's own logic. */
|
|
272
|
+
const CHAIN_UPSTREAMS = [
|
|
273
|
+
"alchemy",
|
|
274
|
+
"infura",
|
|
275
|
+
"public",
|
|
276
|
+
"alto",
|
|
277
|
+
"gateway"
|
|
278
|
+
];
|
|
279
|
+
function isChainUpstream(value) {
|
|
280
|
+
return typeof value === "string" && CHAIN_UPSTREAMS.includes(value);
|
|
281
|
+
}
|
|
282
|
+
const PROVIDER_MESSAGE_MAX = 300;
|
|
283
|
+
const METHOD_MAX = 64;
|
|
284
|
+
const REVERT_NAME_MAX = 64;
|
|
285
|
+
const REVERT_ARG_KEY_MAX = 32;
|
|
286
|
+
const REVERT_ARG_VALUE_MAX = 128;
|
|
287
|
+
const REVERT_ARGS_MAX = 8;
|
|
288
|
+
const SELECTOR_RE = /^0x(?:[0-9a-fA-F]{8})?$/u;
|
|
289
|
+
const MASKS = [
|
|
290
|
+
[/\bBearer\s+[^\s,;]+/giu, "Bearer [REDACTED]"],
|
|
291
|
+
[/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu, "[REDACTED]"],
|
|
292
|
+
[/\b0x[a-fA-F0-9]{40,}\b/gu, "[REDACTED]"],
|
|
293
|
+
[/(^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?=$|[^a-fA-F0-9])/gu, "$1[REDACTED]"],
|
|
294
|
+
[/(?:(?:sk|pk|rk)_(?:live|test)|(?:phc|phx|ghp|gho|ghu|ghs|ghr|whsec)_|github_pat_|xox[baprs]-|AKIA[0-9A-Z]{16}|AIza)[A-Za-z0-9_-]*/giu, "[REDACTED]"],
|
|
295
|
+
[/(https?:\/\/[^\s"']+?\/v[0-9]\/)[A-Za-z0-9_-]{16,}/giu, "$1[REDACTED]"],
|
|
296
|
+
[/\b(api[ _-]?key|access[ _-]?token|token|secret|password|passphrase|private[ _-]?key|authorization|cookie|signature|credential|otp)\b\s*[:=]\s*(?:"[^"]*"|'[^']*'|[^\s,;&]+)/giu, "$1=[REDACTED]"]
|
|
297
|
+
];
|
|
298
|
+
/** Mask credential-shaped content, then cap the length. Total on any string. */
|
|
299
|
+
function boundedEvidence(value, max) {
|
|
300
|
+
let text = value;
|
|
301
|
+
for (const [pattern, replacement] of MASKS) text = text.replace(pattern, replacement);
|
|
302
|
+
return text.length <= max ? text : text.slice(0, max);
|
|
303
|
+
}
|
|
304
|
+
function isRecord$1(value) {
|
|
305
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
306
|
+
}
|
|
307
|
+
function decodeRevert(value) {
|
|
308
|
+
if (!isRecord$1(value)) return null;
|
|
309
|
+
if (value.name !== null && typeof value.name !== "string") return null;
|
|
310
|
+
if (typeof value.selector !== "string" || !SELECTOR_RE.test(value.selector)) return null;
|
|
311
|
+
if (!isRecord$1(value.args)) return null;
|
|
312
|
+
const args = {};
|
|
313
|
+
for (const [key, arg] of Object.entries(value.args).slice(0, REVERT_ARGS_MAX)) {
|
|
314
|
+
if (typeof arg !== "string") return null;
|
|
315
|
+
args[boundedEvidence(key, REVERT_ARG_KEY_MAX)] = boundedEvidence(arg, REVERT_ARG_VALUE_MAX);
|
|
316
|
+
}
|
|
317
|
+
return {
|
|
318
|
+
name: value.name === null ? null : boundedEvidence(value.name, REVERT_NAME_MAX),
|
|
319
|
+
selector: value.selector,
|
|
320
|
+
args
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Decode a `ChainCause` from untrusted wire data (gateway JSON-RPC `error.data`,
|
|
325
|
+
* a Convex error payload). Every string is masked and bounded; an unrecognized
|
|
326
|
+
* shape yields null, because a consumer must never invent a cause.
|
|
327
|
+
*/
|
|
328
|
+
function decodeChainCause(value) {
|
|
329
|
+
if (!isRecord$1(value)) return null;
|
|
330
|
+
if (!isFailureMode(value.mode) || !isChainUpstream(value.upstream)) return null;
|
|
331
|
+
if (typeof value.method !== "string" || typeof value.retryable !== "boolean") return null;
|
|
332
|
+
const cause = {
|
|
333
|
+
mode: value.mode,
|
|
334
|
+
upstream: value.upstream,
|
|
335
|
+
method: boundedEvidence(value.method, METHOD_MAX),
|
|
336
|
+
retryable: value.retryable
|
|
337
|
+
};
|
|
338
|
+
if (typeof value.httpStatus === "number" && Number.isInteger(value.httpStatus)) cause.httpStatus = value.httpStatus;
|
|
339
|
+
if (typeof value.rpcCode === "number" && Number.isInteger(value.rpcCode)) cause.rpcCode = value.rpcCode;
|
|
340
|
+
const revert = decodeRevert(value.revert);
|
|
341
|
+
if (revert !== null) cause.revert = revert;
|
|
342
|
+
if (typeof value.providerMessage === "string") cause.providerMessage = boundedEvidence(value.providerMessage, PROVIDER_MESSAGE_MAX);
|
|
343
|
+
return cause;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* The cause as flat PostHog properties. Same keys from every producer, so one
|
|
347
|
+
* filter (`failure_mode = 'rate-limited'`) finds the gateway's, the backend's,
|
|
348
|
+
* and the SDK's rows alike.
|
|
349
|
+
*/
|
|
350
|
+
function chainCauseProperties(chain) {
|
|
351
|
+
return {
|
|
352
|
+
failure_mode: chain.mode,
|
|
353
|
+
chain_upstream: chain.upstream,
|
|
354
|
+
chain_method: chain.method,
|
|
355
|
+
chain_retryable: chain.retryable,
|
|
356
|
+
...chain.httpStatus === void 0 ? {} : { chain_http_status: chain.httpStatus },
|
|
357
|
+
...chain.rpcCode === void 0 ? {} : { chain_rpc_code: chain.rpcCode },
|
|
358
|
+
...chain.revert === void 0 ? {} : {
|
|
359
|
+
chain_revert_name: chain.revert.name ?? "unknown",
|
|
360
|
+
chain_revert_selector: chain.revert.selector,
|
|
361
|
+
chain_revert_args: chain.revert.args
|
|
362
|
+
},
|
|
363
|
+
...chain.providerMessage === void 0 ? {} : { chain_provider_message: chain.providerMessage }
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* The error-tracking fingerprint for a failure: the code, the one-word cause,
|
|
368
|
+
* and the operation. PostHog groups `$exception` rows by this value, so one
|
|
369
|
+
* issue is one cause at one operation instead of every provider failure in
|
|
370
|
+
* one bucket (money-path audit 2026-09-02, row P1).
|
|
371
|
+
*/
|
|
372
|
+
function failureFingerprint(code, mode, operation) {
|
|
373
|
+
return `${code}:${mode ?? "none"}:${operation}`;
|
|
374
|
+
}
|
|
244
375
|
//#endregion
|
|
245
376
|
//#region ../../packages/errors/src/errors.ts
|
|
246
377
|
const CAPXUL_ERROR_CODES = [
|
|
@@ -303,6 +434,10 @@ var CapxulError = class extends Error {
|
|
|
303
434
|
details;
|
|
304
435
|
correlationId;
|
|
305
436
|
layer;
|
|
437
|
+
/** The one-word cause (`FailureMode`). `chain.mode` when a chain cause is set. */
|
|
438
|
+
mode;
|
|
439
|
+
/** The structured chain-path cause. Never rewritten by a later layer. */
|
|
440
|
+
chain;
|
|
306
441
|
constructor(code, message, options = {}) {
|
|
307
442
|
super(message, "cause" in options ? { cause: options.cause } : void 0);
|
|
308
443
|
this.name = "CapxulError";
|
|
@@ -310,6 +445,10 @@ var CapxulError = class extends Error {
|
|
|
310
445
|
if (options.details !== void 0) this.details = options.details;
|
|
311
446
|
if (options.correlationId !== void 0) this.correlationId = options.correlationId;
|
|
312
447
|
if (options.layer !== void 0) this.layer = options.layer;
|
|
448
|
+
const legacy = options.details?.failure_mode;
|
|
449
|
+
const mode = options.chain?.mode ?? (isFailureMode(options.mode) ? options.mode : void 0) ?? (isFailureMode(legacy) ? legacy : void 0);
|
|
450
|
+
if (mode !== void 0) this.mode = mode;
|
|
451
|
+
if (options.chain !== void 0) this.chain = options.chain;
|
|
313
452
|
}
|
|
314
453
|
};
|
|
315
454
|
function isCapxulError(value) {
|
|
@@ -319,7 +458,9 @@ function deserializeCapxulError(serialized) {
|
|
|
319
458
|
return new CapxulError(serialized.code, serialized.message, compactErrorOptions({
|
|
320
459
|
details: serialized.details,
|
|
321
460
|
correlationId: serialized.correlationId,
|
|
322
|
-
layer: serialized.layer
|
|
461
|
+
layer: serialized.layer,
|
|
462
|
+
mode: serialized.mode,
|
|
463
|
+
chain: serialized.chain === void 0 ? void 0 : decodeChainCause(serialized.chain) ?? void 0
|
|
323
464
|
}));
|
|
324
465
|
}
|
|
325
466
|
function compactErrorOptions(options) {
|
|
@@ -328,6 +469,8 @@ function compactErrorOptions(options) {
|
|
|
328
469
|
if (options.details !== void 0) result.details = options.details;
|
|
329
470
|
if (options.correlationId !== void 0) result.correlationId = options.correlationId;
|
|
330
471
|
if (options.layer !== void 0) result.layer = options.layer;
|
|
472
|
+
if (options.mode !== void 0) result.mode = options.mode;
|
|
473
|
+
if (options.chain !== void 0) result.chain = options.chain;
|
|
331
474
|
return result;
|
|
332
475
|
}
|
|
333
476
|
const Errors = {
|
|
@@ -343,11 +486,14 @@ const Errors = {
|
|
|
343
486
|
provider,
|
|
344
487
|
operation
|
|
345
488
|
};
|
|
346
|
-
|
|
489
|
+
const mode = opts?.chain?.mode ?? opts?.failure_mode;
|
|
490
|
+
if (mode !== void 0) details.failure_mode = mode;
|
|
347
491
|
if (opts?.httpStatus !== void 0) details.httpStatus = opts.httpStatus;
|
|
348
492
|
return new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation}`, {
|
|
349
493
|
cause,
|
|
350
|
-
details
|
|
494
|
+
details,
|
|
495
|
+
...mode === void 0 ? {} : { mode },
|
|
496
|
+
...opts?.chain === void 0 ? {} : { chain: opts.chain }
|
|
351
497
|
});
|
|
352
498
|
},
|
|
353
499
|
capabilityUnavailable: (provider, operation) => new CapxulError("CAPABILITY_UNAVAILABLE", "Provider capability is unavailable", { details: {
|
|
@@ -452,12 +598,18 @@ function isCapxulCode(value) {
|
|
|
452
598
|
}
|
|
453
599
|
function reconstruct(serialized) {
|
|
454
600
|
if (!isCapxulCode(serialized.code)) return null;
|
|
455
|
-
|
|
601
|
+
const payload = {
|
|
456
602
|
code: serialized.code,
|
|
457
603
|
message: typeof serialized.message === "string" ? serialized.message : String(serialized.code),
|
|
458
604
|
...typeof serialized.details === "object" && serialized.details !== null && !Array.isArray(serialized.details) ? { details: serialized.details } : {},
|
|
459
605
|
...typeof serialized.correlationId === "string" ? { correlationId: serialized.correlationId } : {},
|
|
460
|
-
...typeof serialized.layer === "string" ? { layer: serialized.layer } : {}
|
|
606
|
+
...typeof serialized.layer === "string" ? { layer: serialized.layer } : {},
|
|
607
|
+
...isFailureMode(serialized.mode) ? { mode: serialized.mode } : {}
|
|
608
|
+
};
|
|
609
|
+
const chain = decodeChainCause(serialized.chain);
|
|
610
|
+
return deserializeCapxulError(chain === null ? payload : {
|
|
611
|
+
...payload,
|
|
612
|
+
chain
|
|
461
613
|
});
|
|
462
614
|
}
|
|
463
615
|
function decodeConvexError(err) {
|
|
@@ -1491,6 +1643,24 @@ const CAPXUL_PAYMENTS_V2_ABI = [
|
|
|
1491
1643
|
internalType: "bytes32"
|
|
1492
1644
|
}]
|
|
1493
1645
|
},
|
|
1646
|
+
{
|
|
1647
|
+
type: "error",
|
|
1648
|
+
name: "TokenCallReturnedFalse",
|
|
1649
|
+
inputs: [{
|
|
1650
|
+
name: "token",
|
|
1651
|
+
type: "address",
|
|
1652
|
+
internalType: "address"
|
|
1653
|
+
}]
|
|
1654
|
+
},
|
|
1655
|
+
{
|
|
1656
|
+
type: "error",
|
|
1657
|
+
name: "TokenHasNoCode",
|
|
1658
|
+
inputs: [{
|
|
1659
|
+
name: "token",
|
|
1660
|
+
type: "address",
|
|
1661
|
+
internalType: "address"
|
|
1662
|
+
}]
|
|
1663
|
+
},
|
|
1494
1664
|
{
|
|
1495
1665
|
type: "error",
|
|
1496
1666
|
name: "ZeroAddress",
|
|
@@ -1513,7 +1683,7 @@ const CAPXUL_PAYMENTS_V2_ABI = [
|
|
|
1513
1683
|
}
|
|
1514
1684
|
];
|
|
1515
1685
|
/** Immutable CapxulPaymentsV2 deployment on Base Sepolia. */
|
|
1516
|
-
const CAPXUL_PAYMENTS_V2_ADDRESS = "
|
|
1686
|
+
const CAPXUL_PAYMENTS_V2_ADDRESS = "0x7a5c25aB7ce91d7a475B71cd1ec33E230291f8a4";
|
|
1517
1687
|
//#endregion
|
|
1518
1688
|
//#region ../../packages/config/src/route.ts
|
|
1519
1689
|
/** USDX on Base Sepolia — the only settlement token in v1. */
|
|
@@ -2690,7 +2860,8 @@ const CAPXUL_FUNCTIONS = {
|
|
|
2690
2860
|
},
|
|
2691
2861
|
"payroll/queries": {
|
|
2692
2862
|
groups: "payroll/queries:groups",
|
|
2693
|
-
runs: "payroll/queries:runs"
|
|
2863
|
+
runs: "payroll/queries:runs",
|
|
2864
|
+
terms: "payroll/queries:terms"
|
|
2694
2865
|
},
|
|
2695
2866
|
"permission/actions": { verify: "permission/actions:verify" },
|
|
2696
2867
|
"permission/mutations": { command: "permission/mutations:command" },
|
|
@@ -2774,7 +2945,7 @@ const EVM_ADDRESS_RE = /^0x[a-fA-F0-9]{40}$/;
|
|
|
2774
2945
|
* envelopes carrying it — so it MUST stay byte-identical across both. Exported
|
|
2775
2946
|
* once here to remove the drift risk of a mirrored declaration.
|
|
2776
2947
|
*/
|
|
2777
|
-
const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "
|
|
2948
|
+
const PAYMENT_DOCUMENT_VERIFYING_CONTRACT = "0x7a5c25aB7ce91d7a475B71cd1ec33E230291f8a4";
|
|
2778
2949
|
const PAYMENT_ID_RE = /^payment_[0-9A-Za-z]+$/;
|
|
2779
2950
|
const PAYEE_ID_RE = /^payee_[0-9A-Za-z]+$/;
|
|
2780
2951
|
const ORG_ID_RE = /^org_[0-9A-Za-z]+$/;
|
|
@@ -3476,13 +3647,13 @@ const PaymentVerificationMismatchCodeSchema = Schema.Literals([
|
|
|
3476
3647
|
"wrong_destination",
|
|
3477
3648
|
"wrong_amount"
|
|
3478
3649
|
]);
|
|
3479
|
-
const
|
|
3650
|
+
const TransferRangeSchema = Schema.Struct({
|
|
3480
3651
|
chainId: BaseSepoliaChainIdSchema,
|
|
3481
3652
|
tokenAddress: AddressSchema$1,
|
|
3482
3653
|
fromBlock: BlockNumberSchema$1,
|
|
3483
3654
|
toBlock: BlockNumberSchema$1
|
|
3484
3655
|
}).pipe(Schema.refine((range) => range.toBlock >= range.fromBlock && range.toBlock - range.fromBlock < 1e4, { message: "toBlock must be at or after fromBlock and the range must contain fewer than 10,000 block intervals" }));
|
|
3485
|
-
const
|
|
3656
|
+
const TransferEvidenceSchema = Schema.Struct({
|
|
3486
3657
|
...MovementIdentitySchema.fields,
|
|
3487
3658
|
blockNumber: BlockNumberSchema$1,
|
|
3488
3659
|
blockHash: Bytes32Schema,
|
|
@@ -3491,16 +3662,16 @@ const FinalizedTransferEvidenceSchema = Schema.Struct({
|
|
|
3491
3662
|
rawAmount: WeiAmountSchema$1,
|
|
3492
3663
|
removed: Schema.Boolean
|
|
3493
3664
|
});
|
|
3494
|
-
const
|
|
3665
|
+
const ChainBlockReferenceSchema = Schema.Struct({
|
|
3495
3666
|
chainId: BaseSepoliaChainIdSchema,
|
|
3496
3667
|
blockNumber: BlockNumberSchema$1,
|
|
3497
3668
|
blockHash: Bytes32Schema
|
|
3498
3669
|
});
|
|
3499
3670
|
Schema.Struct({
|
|
3500
|
-
range:
|
|
3501
|
-
|
|
3502
|
-
anchor:
|
|
3503
|
-
transfers: Schema.Array(
|
|
3671
|
+
range: TransferRangeSchema,
|
|
3672
|
+
chainHead: ChainBlockReferenceSchema,
|
|
3673
|
+
anchor: ChainBlockReferenceSchema,
|
|
3674
|
+
transfers: Schema.Array(TransferEvidenceSchema),
|
|
3504
3675
|
requestCount: nonNegativeInteger("requestCount")
|
|
3505
3676
|
});
|
|
3506
3677
|
const FinalizedMoneyEvidenceCommonSchema = Schema.Struct({
|
|
@@ -3570,7 +3741,7 @@ const FinalizedCommitmentCancelEvidenceSchema = Schema.Struct({
|
|
|
3570
3741
|
vestedUnclaimed: WeiAmountSchema$1,
|
|
3571
3742
|
unvestedReturned: WeiAmountSchema$1,
|
|
3572
3743
|
documentHash: NonzeroDocumentHashSchema,
|
|
3573
|
-
transfer: Schema.NullOr(
|
|
3744
|
+
transfer: Schema.NullOr(TransferEvidenceSchema)
|
|
3574
3745
|
});
|
|
3575
3746
|
const FinalizedCommitmentRedirectEvidenceSchema = Schema.Struct({
|
|
3576
3747
|
...FinalizedMoneyEvidenceCommonSchema.fields,
|
|
@@ -3594,7 +3765,7 @@ const FinalizedMoneyEvidenceSchema = Schema.Union([
|
|
|
3594
3765
|
Schema.Union([
|
|
3595
3766
|
Schema.Struct({
|
|
3596
3767
|
status: Schema.Literal("pending"),
|
|
3597
|
-
reason: Schema.
|
|
3768
|
+
reason: Schema.Literal("receipt_missing"),
|
|
3598
3769
|
receipt: Schema.optional(ReceiptRefSchema)
|
|
3599
3770
|
}),
|
|
3600
3771
|
Schema.Struct({
|
|
@@ -4041,6 +4212,21 @@ Schema.Struct({
|
|
|
4041
4212
|
tone: Schema.String,
|
|
4042
4213
|
members: Schema.Array(PayrollGroupMemberSchema)
|
|
4043
4214
|
});
|
|
4215
|
+
const PayrollTermsUnitSchema = Schema.Literals([
|
|
4216
|
+
"hour",
|
|
4217
|
+
"week",
|
|
4218
|
+
"month",
|
|
4219
|
+
"year",
|
|
4220
|
+
"paycheck"
|
|
4221
|
+
]);
|
|
4222
|
+
Schema.Struct({
|
|
4223
|
+
partyId: PartyIdSchema,
|
|
4224
|
+
rate: MinorUnitSchema,
|
|
4225
|
+
unit: PayrollTermsUnitSchema,
|
|
4226
|
+
currency: CurrencyCodeSchema$1,
|
|
4227
|
+
decimals: nonNegativeInteger("decimals"),
|
|
4228
|
+
effectiveFrom: nonNegativeInteger("effectiveFrom")
|
|
4229
|
+
});
|
|
4044
4230
|
`
|
|
4045
4231
|
.capxul-doc{--ink:#1d1d1f;--muted:#6e6e73;--line:#e7e7ea;--accent:#0a7d4b;--bg:#fff;
|
|
4046
4232
|
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif;
|
|
@@ -5950,23 +6136,7 @@ function reportProvisioningTelemetryFailure(kind, smartAccount, cause) {
|
|
|
5950
6136
|
function isProvisioningTelemetryDebugEnabled() {
|
|
5951
6137
|
return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
|
|
5952
6138
|
}
|
|
5953
|
-
|
|
5954
|
-
//#region ../../packages/sdk/src/telemetry/get-failure-mode.ts
|
|
5955
|
-
/**
|
|
5956
|
-
* The five canonical {@link FailureMode} members, for runtime membership checks.
|
|
5957
|
-
* Single source of truth — tests assert against this exact set so the taxonomy
|
|
5958
|
-
* and its guard can never drift apart.
|
|
5959
|
-
*/
|
|
5960
|
-
const FAILURE_MODES = new Set([
|
|
5961
|
-
"auth-origin-mismatch",
|
|
5962
|
-
"stale-openfort-cache",
|
|
5963
|
-
"app-env-allowlist",
|
|
5964
|
-
"no-secure-context",
|
|
5965
|
-
"unknown"
|
|
5966
|
-
]);
|
|
5967
|
-
function isFailureMode(value) {
|
|
5968
|
-
return typeof value === "string" && FAILURE_MODES.has(value);
|
|
5969
|
-
}
|
|
6139
|
+
new Set(FAILURE_MODES$1);
|
|
5970
6140
|
/**
|
|
5971
6141
|
* Extract the structured {@link FailureMode} from a CapxulError.
|
|
5972
6142
|
*
|
|
@@ -6958,6 +7128,697 @@ function convexToJson(value) {
|
|
|
6958
7128
|
return convexToJsonInternal(value, value, "", false);
|
|
6959
7129
|
}
|
|
6960
7130
|
//#endregion
|
|
7131
|
+
//#region ../../node_modules/.pnpm/convex@1.39.1_react@19.2.7/node_modules/convex/dist/esm/values/validators.js
|
|
7132
|
+
var __defProp$12 = Object.defineProperty;
|
|
7133
|
+
var __defNormalProp$12 = (obj, key, value) => key in obj ? __defProp$12(obj, key, {
|
|
7134
|
+
enumerable: true,
|
|
7135
|
+
configurable: true,
|
|
7136
|
+
writable: true,
|
|
7137
|
+
value
|
|
7138
|
+
}) : obj[key] = value;
|
|
7139
|
+
var __publicField$12 = (obj, key, value) => __defNormalProp$12(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7140
|
+
const UNDEFINED_VALIDATOR_ERROR_URL = "https://docs.convex.dev/error#undefined-validator";
|
|
7141
|
+
function throwUndefinedValidatorError(context, fieldName) {
|
|
7142
|
+
const fieldInfo = fieldName !== void 0 ? ` for field "${fieldName}"` : "";
|
|
7143
|
+
throw new Error(`A validator is undefined${fieldInfo} in ${context}. This is often caused by circular imports. See ${UNDEFINED_VALIDATOR_ERROR_URL} for details.`);
|
|
7144
|
+
}
|
|
7145
|
+
var BaseValidator = class {
|
|
7146
|
+
constructor({ isOptional }) {
|
|
7147
|
+
/**
|
|
7148
|
+
* Only for TypeScript, the TS type of the JS values validated
|
|
7149
|
+
* by this validator.
|
|
7150
|
+
*/
|
|
7151
|
+
__publicField$12(this, "type");
|
|
7152
|
+
/**
|
|
7153
|
+
* Only for TypeScript, if this an Object validator, then
|
|
7154
|
+
* this is the TS type of its property names.
|
|
7155
|
+
*/
|
|
7156
|
+
__publicField$12(this, "fieldPaths");
|
|
7157
|
+
/**
|
|
7158
|
+
* Whether this is an optional Object property value validator.
|
|
7159
|
+
*/
|
|
7160
|
+
__publicField$12(this, "isOptional");
|
|
7161
|
+
/**
|
|
7162
|
+
* Always `"true"`.
|
|
7163
|
+
*/
|
|
7164
|
+
__publicField$12(this, "isConvexValidator");
|
|
7165
|
+
this.isOptional = isOptional;
|
|
7166
|
+
this.isConvexValidator = true;
|
|
7167
|
+
}
|
|
7168
|
+
};
|
|
7169
|
+
var VId = class VId extends BaseValidator {
|
|
7170
|
+
/**
|
|
7171
|
+
* Usually you'd use `v.id(tableName)` instead.
|
|
7172
|
+
*/
|
|
7173
|
+
constructor({ isOptional, tableName }) {
|
|
7174
|
+
super({ isOptional });
|
|
7175
|
+
/**
|
|
7176
|
+
* The name of the table that the validated IDs must belong to.
|
|
7177
|
+
*/
|
|
7178
|
+
__publicField$12(this, "tableName");
|
|
7179
|
+
/**
|
|
7180
|
+
* The kind of validator, `"id"`.
|
|
7181
|
+
*/
|
|
7182
|
+
__publicField$12(this, "kind", "id");
|
|
7183
|
+
if (typeof tableName !== "string") throw new Error("v.id(tableName) requires a string");
|
|
7184
|
+
this.tableName = tableName;
|
|
7185
|
+
}
|
|
7186
|
+
/** @internal */
|
|
7187
|
+
get json() {
|
|
7188
|
+
return {
|
|
7189
|
+
type: "id",
|
|
7190
|
+
tableName: this.tableName
|
|
7191
|
+
};
|
|
7192
|
+
}
|
|
7193
|
+
/** @internal */
|
|
7194
|
+
asOptional() {
|
|
7195
|
+
return new VId({
|
|
7196
|
+
isOptional: "optional",
|
|
7197
|
+
tableName: this.tableName
|
|
7198
|
+
});
|
|
7199
|
+
}
|
|
7200
|
+
};
|
|
7201
|
+
var VFloat64 = class VFloat64 extends BaseValidator {
|
|
7202
|
+
constructor() {
|
|
7203
|
+
super(...arguments);
|
|
7204
|
+
/**
|
|
7205
|
+
* The kind of validator, `"float64"`.
|
|
7206
|
+
*/
|
|
7207
|
+
__publicField$12(this, "kind", "float64");
|
|
7208
|
+
}
|
|
7209
|
+
/** @internal */
|
|
7210
|
+
get json() {
|
|
7211
|
+
return { type: "number" };
|
|
7212
|
+
}
|
|
7213
|
+
/** @internal */
|
|
7214
|
+
asOptional() {
|
|
7215
|
+
return new VFloat64({ isOptional: "optional" });
|
|
7216
|
+
}
|
|
7217
|
+
};
|
|
7218
|
+
var VInt64 = class VInt64 extends BaseValidator {
|
|
7219
|
+
constructor() {
|
|
7220
|
+
super(...arguments);
|
|
7221
|
+
/**
|
|
7222
|
+
* The kind of validator, `"int64"`.
|
|
7223
|
+
*/
|
|
7224
|
+
__publicField$12(this, "kind", "int64");
|
|
7225
|
+
}
|
|
7226
|
+
/** @internal */
|
|
7227
|
+
get json() {
|
|
7228
|
+
return { type: "bigint" };
|
|
7229
|
+
}
|
|
7230
|
+
/** @internal */
|
|
7231
|
+
asOptional() {
|
|
7232
|
+
return new VInt64({ isOptional: "optional" });
|
|
7233
|
+
}
|
|
7234
|
+
};
|
|
7235
|
+
var VBoolean = class VBoolean extends BaseValidator {
|
|
7236
|
+
constructor() {
|
|
7237
|
+
super(...arguments);
|
|
7238
|
+
/**
|
|
7239
|
+
* The kind of validator, `"boolean"`.
|
|
7240
|
+
*/
|
|
7241
|
+
__publicField$12(this, "kind", "boolean");
|
|
7242
|
+
}
|
|
7243
|
+
/** @internal */
|
|
7244
|
+
get json() {
|
|
7245
|
+
return { type: this.kind };
|
|
7246
|
+
}
|
|
7247
|
+
/** @internal */
|
|
7248
|
+
asOptional() {
|
|
7249
|
+
return new VBoolean({ isOptional: "optional" });
|
|
7250
|
+
}
|
|
7251
|
+
};
|
|
7252
|
+
var VBytes = class VBytes extends BaseValidator {
|
|
7253
|
+
constructor() {
|
|
7254
|
+
super(...arguments);
|
|
7255
|
+
/**
|
|
7256
|
+
* The kind of validator, `"bytes"`.
|
|
7257
|
+
*/
|
|
7258
|
+
__publicField$12(this, "kind", "bytes");
|
|
7259
|
+
}
|
|
7260
|
+
/** @internal */
|
|
7261
|
+
get json() {
|
|
7262
|
+
return { type: this.kind };
|
|
7263
|
+
}
|
|
7264
|
+
/** @internal */
|
|
7265
|
+
asOptional() {
|
|
7266
|
+
return new VBytes({ isOptional: "optional" });
|
|
7267
|
+
}
|
|
7268
|
+
};
|
|
7269
|
+
var VString = class VString extends BaseValidator {
|
|
7270
|
+
constructor() {
|
|
7271
|
+
super(...arguments);
|
|
7272
|
+
/**
|
|
7273
|
+
* The kind of validator, `"string"`.
|
|
7274
|
+
*/
|
|
7275
|
+
__publicField$12(this, "kind", "string");
|
|
7276
|
+
}
|
|
7277
|
+
/** @internal */
|
|
7278
|
+
get json() {
|
|
7279
|
+
return { type: this.kind };
|
|
7280
|
+
}
|
|
7281
|
+
/** @internal */
|
|
7282
|
+
asOptional() {
|
|
7283
|
+
return new VString({ isOptional: "optional" });
|
|
7284
|
+
}
|
|
7285
|
+
};
|
|
7286
|
+
var VNull = class VNull extends BaseValidator {
|
|
7287
|
+
constructor() {
|
|
7288
|
+
super(...arguments);
|
|
7289
|
+
/**
|
|
7290
|
+
* The kind of validator, `"null"`.
|
|
7291
|
+
*/
|
|
7292
|
+
__publicField$12(this, "kind", "null");
|
|
7293
|
+
}
|
|
7294
|
+
/** @internal */
|
|
7295
|
+
get json() {
|
|
7296
|
+
return { type: this.kind };
|
|
7297
|
+
}
|
|
7298
|
+
/** @internal */
|
|
7299
|
+
asOptional() {
|
|
7300
|
+
return new VNull({ isOptional: "optional" });
|
|
7301
|
+
}
|
|
7302
|
+
};
|
|
7303
|
+
var VAny = class VAny extends BaseValidator {
|
|
7304
|
+
constructor() {
|
|
7305
|
+
super(...arguments);
|
|
7306
|
+
/**
|
|
7307
|
+
* The kind of validator, `"any"`.
|
|
7308
|
+
*/
|
|
7309
|
+
__publicField$12(this, "kind", "any");
|
|
7310
|
+
}
|
|
7311
|
+
/** @internal */
|
|
7312
|
+
get json() {
|
|
7313
|
+
return { type: this.kind };
|
|
7314
|
+
}
|
|
7315
|
+
/** @internal */
|
|
7316
|
+
asOptional() {
|
|
7317
|
+
return new VAny({ isOptional: "optional" });
|
|
7318
|
+
}
|
|
7319
|
+
};
|
|
7320
|
+
var VObject = class VObject extends BaseValidator {
|
|
7321
|
+
/**
|
|
7322
|
+
* Usually you'd use `v.object({ ... })` instead.
|
|
7323
|
+
*/
|
|
7324
|
+
constructor({ isOptional, fields }) {
|
|
7325
|
+
super({ isOptional });
|
|
7326
|
+
/**
|
|
7327
|
+
* An object with the validator for each property.
|
|
7328
|
+
*/
|
|
7329
|
+
__publicField$12(this, "fields");
|
|
7330
|
+
/**
|
|
7331
|
+
* The kind of validator, `"object"`.
|
|
7332
|
+
*/
|
|
7333
|
+
__publicField$12(this, "kind", "object");
|
|
7334
|
+
globalThis.Object.entries(fields).forEach(([fieldName, validator]) => {
|
|
7335
|
+
if (validator === void 0) throwUndefinedValidatorError("v.object()", fieldName);
|
|
7336
|
+
if (!validator.isConvexValidator) throw new Error("v.object() entries must be validators");
|
|
7337
|
+
});
|
|
7338
|
+
this.fields = fields;
|
|
7339
|
+
}
|
|
7340
|
+
/** @internal */
|
|
7341
|
+
get json() {
|
|
7342
|
+
return {
|
|
7343
|
+
type: this.kind,
|
|
7344
|
+
value: globalThis.Object.fromEntries(globalThis.Object.entries(this.fields).map(([k, v]) => [k, {
|
|
7345
|
+
fieldType: v.json,
|
|
7346
|
+
optional: v.isOptional === "optional" ? true : false
|
|
7347
|
+
}]))
|
|
7348
|
+
};
|
|
7349
|
+
}
|
|
7350
|
+
/** @internal */
|
|
7351
|
+
asOptional() {
|
|
7352
|
+
return new VObject({
|
|
7353
|
+
isOptional: "optional",
|
|
7354
|
+
fields: this.fields
|
|
7355
|
+
});
|
|
7356
|
+
}
|
|
7357
|
+
/**
|
|
7358
|
+
* Create a new VObject with the specified fields omitted.
|
|
7359
|
+
* @param fields The field names to omit from this VObject.
|
|
7360
|
+
*/
|
|
7361
|
+
omit(...fields) {
|
|
7362
|
+
const newFields = { ...this.fields };
|
|
7363
|
+
for (const field of fields) delete newFields[field];
|
|
7364
|
+
return new VObject({
|
|
7365
|
+
isOptional: this.isOptional,
|
|
7366
|
+
fields: newFields
|
|
7367
|
+
});
|
|
7368
|
+
}
|
|
7369
|
+
/**
|
|
7370
|
+
* Create a new VObject with only the specified fields.
|
|
7371
|
+
* @param fields The field names to pick from this VObject.
|
|
7372
|
+
*/
|
|
7373
|
+
pick(...fields) {
|
|
7374
|
+
const newFields = {};
|
|
7375
|
+
for (const field of fields) newFields[field] = this.fields[field];
|
|
7376
|
+
return new VObject({
|
|
7377
|
+
isOptional: this.isOptional,
|
|
7378
|
+
fields: newFields
|
|
7379
|
+
});
|
|
7380
|
+
}
|
|
7381
|
+
/**
|
|
7382
|
+
* Create a new VObject with all fields marked as optional.
|
|
7383
|
+
*/
|
|
7384
|
+
partial() {
|
|
7385
|
+
const newFields = {};
|
|
7386
|
+
for (const [key, validator] of globalThis.Object.entries(this.fields)) newFields[key] = validator.asOptional();
|
|
7387
|
+
return new VObject({
|
|
7388
|
+
isOptional: this.isOptional,
|
|
7389
|
+
fields: newFields
|
|
7390
|
+
});
|
|
7391
|
+
}
|
|
7392
|
+
/**
|
|
7393
|
+
* Create a new VObject with additional fields merged in.
|
|
7394
|
+
* @param fields An object with additional validators to merge into this VObject.
|
|
7395
|
+
*/
|
|
7396
|
+
extend(fields) {
|
|
7397
|
+
return new VObject({
|
|
7398
|
+
isOptional: this.isOptional,
|
|
7399
|
+
fields: {
|
|
7400
|
+
...this.fields,
|
|
7401
|
+
...fields
|
|
7402
|
+
}
|
|
7403
|
+
});
|
|
7404
|
+
}
|
|
7405
|
+
};
|
|
7406
|
+
var VLiteral = class VLiteral extends BaseValidator {
|
|
7407
|
+
/**
|
|
7408
|
+
* Usually you'd use `v.literal(value)` instead.
|
|
7409
|
+
*/
|
|
7410
|
+
constructor({ isOptional, value }) {
|
|
7411
|
+
super({ isOptional });
|
|
7412
|
+
/**
|
|
7413
|
+
* The value that the validated values must be equal to.
|
|
7414
|
+
*/
|
|
7415
|
+
__publicField$12(this, "value");
|
|
7416
|
+
/**
|
|
7417
|
+
* The kind of validator, `"literal"`.
|
|
7418
|
+
*/
|
|
7419
|
+
__publicField$12(this, "kind", "literal");
|
|
7420
|
+
if (typeof value !== "string" && typeof value !== "boolean" && typeof value !== "number" && typeof value !== "bigint") throw new Error("v.literal(value) must be a string, number, or boolean");
|
|
7421
|
+
this.value = value;
|
|
7422
|
+
}
|
|
7423
|
+
/** @internal */
|
|
7424
|
+
get json() {
|
|
7425
|
+
return {
|
|
7426
|
+
type: this.kind,
|
|
7427
|
+
value: convexToJson(this.value)
|
|
7428
|
+
};
|
|
7429
|
+
}
|
|
7430
|
+
/** @internal */
|
|
7431
|
+
asOptional() {
|
|
7432
|
+
return new VLiteral({
|
|
7433
|
+
isOptional: "optional",
|
|
7434
|
+
value: this.value
|
|
7435
|
+
});
|
|
7436
|
+
}
|
|
7437
|
+
};
|
|
7438
|
+
var VArray = class VArray extends BaseValidator {
|
|
7439
|
+
/**
|
|
7440
|
+
* Usually you'd use `v.array(element)` instead.
|
|
7441
|
+
*/
|
|
7442
|
+
constructor({ isOptional, element }) {
|
|
7443
|
+
super({ isOptional });
|
|
7444
|
+
/**
|
|
7445
|
+
* The validator for the elements of the array.
|
|
7446
|
+
*/
|
|
7447
|
+
__publicField$12(this, "element");
|
|
7448
|
+
/**
|
|
7449
|
+
* The kind of validator, `"array"`.
|
|
7450
|
+
*/
|
|
7451
|
+
__publicField$12(this, "kind", "array");
|
|
7452
|
+
if (element === void 0) throwUndefinedValidatorError("v.array()");
|
|
7453
|
+
this.element = element;
|
|
7454
|
+
}
|
|
7455
|
+
/** @internal */
|
|
7456
|
+
get json() {
|
|
7457
|
+
return {
|
|
7458
|
+
type: this.kind,
|
|
7459
|
+
value: this.element.json
|
|
7460
|
+
};
|
|
7461
|
+
}
|
|
7462
|
+
/** @internal */
|
|
7463
|
+
asOptional() {
|
|
7464
|
+
return new VArray({
|
|
7465
|
+
isOptional: "optional",
|
|
7466
|
+
element: this.element
|
|
7467
|
+
});
|
|
7468
|
+
}
|
|
7469
|
+
};
|
|
7470
|
+
var VRecord = class VRecord extends BaseValidator {
|
|
7471
|
+
/**
|
|
7472
|
+
* Usually you'd use `v.record(key, value)` instead.
|
|
7473
|
+
*/
|
|
7474
|
+
constructor({ isOptional, key, value }) {
|
|
7475
|
+
super({ isOptional });
|
|
7476
|
+
/**
|
|
7477
|
+
* The validator for the keys of the record.
|
|
7478
|
+
*/
|
|
7479
|
+
__publicField$12(this, "key");
|
|
7480
|
+
/**
|
|
7481
|
+
* The validator for the values of the record.
|
|
7482
|
+
*/
|
|
7483
|
+
__publicField$12(this, "value");
|
|
7484
|
+
/**
|
|
7485
|
+
* The kind of validator, `"record"`.
|
|
7486
|
+
*/
|
|
7487
|
+
__publicField$12(this, "kind", "record");
|
|
7488
|
+
if (key === void 0) throwUndefinedValidatorError("v.record()", "key");
|
|
7489
|
+
if (value === void 0) throwUndefinedValidatorError("v.record()", "value");
|
|
7490
|
+
if (key.isOptional === "optional") throw new Error("Record validator cannot have optional keys");
|
|
7491
|
+
if (value.isOptional === "optional") throw new Error("Record validator cannot have optional values");
|
|
7492
|
+
if (!key.isConvexValidator || !value.isConvexValidator) throw new Error("Key and value of v.record() but be validators");
|
|
7493
|
+
this.key = key;
|
|
7494
|
+
this.value = value;
|
|
7495
|
+
}
|
|
7496
|
+
/** @internal */
|
|
7497
|
+
get json() {
|
|
7498
|
+
return {
|
|
7499
|
+
type: this.kind,
|
|
7500
|
+
keys: this.key.json,
|
|
7501
|
+
values: {
|
|
7502
|
+
fieldType: this.value.json,
|
|
7503
|
+
optional: false
|
|
7504
|
+
}
|
|
7505
|
+
};
|
|
7506
|
+
}
|
|
7507
|
+
/** @internal */
|
|
7508
|
+
asOptional() {
|
|
7509
|
+
return new VRecord({
|
|
7510
|
+
isOptional: "optional",
|
|
7511
|
+
key: this.key,
|
|
7512
|
+
value: this.value
|
|
7513
|
+
});
|
|
7514
|
+
}
|
|
7515
|
+
};
|
|
7516
|
+
var VUnion = class VUnion extends BaseValidator {
|
|
7517
|
+
/**
|
|
7518
|
+
* Usually you'd use `v.union(...members)` instead.
|
|
7519
|
+
*/
|
|
7520
|
+
constructor({ isOptional, members }) {
|
|
7521
|
+
super({ isOptional });
|
|
7522
|
+
/**
|
|
7523
|
+
* The array of validators, one of which must match the value.
|
|
7524
|
+
*/
|
|
7525
|
+
__publicField$12(this, "members");
|
|
7526
|
+
/**
|
|
7527
|
+
* The kind of validator, `"union"`.
|
|
7528
|
+
*/
|
|
7529
|
+
__publicField$12(this, "kind", "union");
|
|
7530
|
+
members.forEach((member, index) => {
|
|
7531
|
+
if (member === void 0) throwUndefinedValidatorError("v.union()", `member at index ${index}`);
|
|
7532
|
+
if (!member.isConvexValidator) throw new Error("All members of v.union() must be validators");
|
|
7533
|
+
});
|
|
7534
|
+
this.members = members;
|
|
7535
|
+
}
|
|
7536
|
+
/** @internal */
|
|
7537
|
+
get json() {
|
|
7538
|
+
return {
|
|
7539
|
+
type: this.kind,
|
|
7540
|
+
value: this.members.map((v) => v.json)
|
|
7541
|
+
};
|
|
7542
|
+
}
|
|
7543
|
+
/** @internal */
|
|
7544
|
+
asOptional() {
|
|
7545
|
+
return new VUnion({
|
|
7546
|
+
isOptional: "optional",
|
|
7547
|
+
members: this.members
|
|
7548
|
+
});
|
|
7549
|
+
}
|
|
7550
|
+
};
|
|
7551
|
+
//#endregion
|
|
7552
|
+
//#region ../../node_modules/.pnpm/convex@1.39.1_react@19.2.7/node_modules/convex/dist/esm/values/validator.js
|
|
7553
|
+
const v$1 = {
|
|
7554
|
+
/**
|
|
7555
|
+
* Validates that the value is a document ID for the given table.
|
|
7556
|
+
*
|
|
7557
|
+
* IDs are strings at runtime but are typed as `Id<"tableName">` in
|
|
7558
|
+
* TypeScript for type safety.
|
|
7559
|
+
*
|
|
7560
|
+
* @example
|
|
7561
|
+
* ```typescript
|
|
7562
|
+
* args: { userId: v.id("users") }
|
|
7563
|
+
* ```
|
|
7564
|
+
*
|
|
7565
|
+
* @param tableName The name of the table.
|
|
7566
|
+
*/
|
|
7567
|
+
id: (tableName) => {
|
|
7568
|
+
return new VId({
|
|
7569
|
+
isOptional: "required",
|
|
7570
|
+
tableName
|
|
7571
|
+
});
|
|
7572
|
+
},
|
|
7573
|
+
/**
|
|
7574
|
+
* Validates that the value is `null`.
|
|
7575
|
+
*
|
|
7576
|
+
* Use `returns: v.null()` for functions that don't return a meaningful value.
|
|
7577
|
+
* JavaScript `undefined` is not a valid Convex value, it is automatically
|
|
7578
|
+
* converted to `null`.
|
|
7579
|
+
*/
|
|
7580
|
+
null: () => {
|
|
7581
|
+
return new VNull({ isOptional: "required" });
|
|
7582
|
+
},
|
|
7583
|
+
/**
|
|
7584
|
+
* Validates that the value is a JavaScript `number` (Convex Float64).
|
|
7585
|
+
*
|
|
7586
|
+
* Supports all IEEE-754 double-precision floating point numbers including
|
|
7587
|
+
* NaN and Infinity.
|
|
7588
|
+
*
|
|
7589
|
+
* Alias for `v.float64()`.
|
|
7590
|
+
*/
|
|
7591
|
+
number: () => {
|
|
7592
|
+
return new VFloat64({ isOptional: "required" });
|
|
7593
|
+
},
|
|
7594
|
+
/**
|
|
7595
|
+
* Validates that the value is a JavaScript `number` (Convex Float64).
|
|
7596
|
+
*
|
|
7597
|
+
* Supports all IEEE-754 double-precision floating point numbers.
|
|
7598
|
+
*/
|
|
7599
|
+
float64: () => {
|
|
7600
|
+
return new VFloat64({ isOptional: "required" });
|
|
7601
|
+
},
|
|
7602
|
+
/**
|
|
7603
|
+
* @deprecated Use `v.int64()` instead.
|
|
7604
|
+
*/
|
|
7605
|
+
bigint: () => {
|
|
7606
|
+
return new VInt64({ isOptional: "required" });
|
|
7607
|
+
},
|
|
7608
|
+
/**
|
|
7609
|
+
* Validates that the value is a JavaScript `bigint` (Convex Int64).
|
|
7610
|
+
*
|
|
7611
|
+
* Supports BigInts between -2^63 and 2^63-1.
|
|
7612
|
+
*
|
|
7613
|
+
* @example
|
|
7614
|
+
* ```typescript
|
|
7615
|
+
* args: { timestamp: v.int64() }
|
|
7616
|
+
* // Usage: createDoc({ timestamp: 1234567890n })
|
|
7617
|
+
* ```
|
|
7618
|
+
*/
|
|
7619
|
+
int64: () => {
|
|
7620
|
+
return new VInt64({ isOptional: "required" });
|
|
7621
|
+
},
|
|
7622
|
+
/**
|
|
7623
|
+
* Validates that the value is a `boolean`.
|
|
7624
|
+
*/
|
|
7625
|
+
boolean: () => {
|
|
7626
|
+
return new VBoolean({ isOptional: "required" });
|
|
7627
|
+
},
|
|
7628
|
+
/**
|
|
7629
|
+
* Validates that the value is a `string`.
|
|
7630
|
+
*
|
|
7631
|
+
* Strings are stored as UTF-8 and their storage size is calculated as their
|
|
7632
|
+
* UTF-8 encoded size.
|
|
7633
|
+
*/
|
|
7634
|
+
string: () => {
|
|
7635
|
+
return new VString({ isOptional: "required" });
|
|
7636
|
+
},
|
|
7637
|
+
/**
|
|
7638
|
+
* Validates that the value is an `ArrayBuffer` (Convex Bytes).
|
|
7639
|
+
*
|
|
7640
|
+
* Use for binary data.
|
|
7641
|
+
*/
|
|
7642
|
+
bytes: () => {
|
|
7643
|
+
return new VBytes({ isOptional: "required" });
|
|
7644
|
+
},
|
|
7645
|
+
/**
|
|
7646
|
+
* Validates that the value is exactly equal to the given literal.
|
|
7647
|
+
*
|
|
7648
|
+
* Useful for discriminated unions and enum-like patterns.
|
|
7649
|
+
*
|
|
7650
|
+
* @example
|
|
7651
|
+
* ```typescript
|
|
7652
|
+
* // Discriminated union pattern:
|
|
7653
|
+
* v.union(
|
|
7654
|
+
* v.object({ kind: v.literal("error"), message: v.string() }),
|
|
7655
|
+
* v.object({ kind: v.literal("success"), value: v.number() }),
|
|
7656
|
+
* )
|
|
7657
|
+
* ```
|
|
7658
|
+
*
|
|
7659
|
+
* @param literal The literal value to compare against.
|
|
7660
|
+
*/
|
|
7661
|
+
literal: (literal) => {
|
|
7662
|
+
return new VLiteral({
|
|
7663
|
+
isOptional: "required",
|
|
7664
|
+
value: literal
|
|
7665
|
+
});
|
|
7666
|
+
},
|
|
7667
|
+
/**
|
|
7668
|
+
* Validates that the value is an `Array` where every element matches the
|
|
7669
|
+
* given validator.
|
|
7670
|
+
*
|
|
7671
|
+
* Arrays can have at most 8192 elements.
|
|
7672
|
+
*
|
|
7673
|
+
* @example
|
|
7674
|
+
* ```typescript
|
|
7675
|
+
* args: { tags: v.array(v.string()) }
|
|
7676
|
+
* args: { coordinates: v.array(v.number()) }
|
|
7677
|
+
* args: { items: v.array(v.object({ name: v.string(), qty: v.number() })) }
|
|
7678
|
+
* ```
|
|
7679
|
+
*
|
|
7680
|
+
* @param element The validator for the elements of the array.
|
|
7681
|
+
*/
|
|
7682
|
+
array: (element) => {
|
|
7683
|
+
return new VArray({
|
|
7684
|
+
isOptional: "required",
|
|
7685
|
+
element
|
|
7686
|
+
});
|
|
7687
|
+
},
|
|
7688
|
+
/**
|
|
7689
|
+
* Validates that the value is an `Object` with the specified properties.
|
|
7690
|
+
*
|
|
7691
|
+
* Objects can have at most 1024 entries. Field names must be non-empty and
|
|
7692
|
+
* must not start with `"$"` or `"_"` (`_` is reserved for system fields
|
|
7693
|
+
* like `_id` and `_creationTime`; `$` is reserved for Convex internal use).
|
|
7694
|
+
*
|
|
7695
|
+
* @example
|
|
7696
|
+
* ```typescript
|
|
7697
|
+
* args: {
|
|
7698
|
+
* user: v.object({
|
|
7699
|
+
* name: v.string(),
|
|
7700
|
+
* email: v.string(),
|
|
7701
|
+
* age: v.optional(v.number()),
|
|
7702
|
+
* })
|
|
7703
|
+
* }
|
|
7704
|
+
* ```
|
|
7705
|
+
*
|
|
7706
|
+
* @param fields An object mapping property names to their validators.
|
|
7707
|
+
*/
|
|
7708
|
+
object: (fields) => {
|
|
7709
|
+
return new VObject({
|
|
7710
|
+
isOptional: "required",
|
|
7711
|
+
fields
|
|
7712
|
+
});
|
|
7713
|
+
},
|
|
7714
|
+
/**
|
|
7715
|
+
* Validates that the value is a `Record` (object with dynamic keys).
|
|
7716
|
+
*
|
|
7717
|
+
* Records are objects at runtime but allow dynamic keys, unlike `v.object()`
|
|
7718
|
+
* which requires known property names. Keys must be ASCII characters only,
|
|
7719
|
+
* non-empty, and not start with `"$"` or `"_"`.
|
|
7720
|
+
*
|
|
7721
|
+
* @example
|
|
7722
|
+
* ```typescript
|
|
7723
|
+
* // Map of user IDs to scores:
|
|
7724
|
+
* args: { scores: v.record(v.id("users"), v.number()) }
|
|
7725
|
+
*
|
|
7726
|
+
* // Map of string keys to string values:
|
|
7727
|
+
* args: { metadata: v.record(v.string(), v.string()) }
|
|
7728
|
+
* ```
|
|
7729
|
+
*
|
|
7730
|
+
* @param keys The validator for the keys of the record.
|
|
7731
|
+
* @param values The validator for the values of the record.
|
|
7732
|
+
*/
|
|
7733
|
+
record: (keys, values) => {
|
|
7734
|
+
return new VRecord({
|
|
7735
|
+
isOptional: "required",
|
|
7736
|
+
key: keys,
|
|
7737
|
+
value: values
|
|
7738
|
+
});
|
|
7739
|
+
},
|
|
7740
|
+
/**
|
|
7741
|
+
* Validates that the value matches at least one of the given validators.
|
|
7742
|
+
*
|
|
7743
|
+
* @example
|
|
7744
|
+
* ```typescript
|
|
7745
|
+
* // Allow string or number:
|
|
7746
|
+
* args: { value: v.union(v.string(), v.number()) }
|
|
7747
|
+
*
|
|
7748
|
+
* // Discriminated union (recommended pattern):
|
|
7749
|
+
* v.union(
|
|
7750
|
+
* v.object({ kind: v.literal("text"), body: v.string() }),
|
|
7751
|
+
* v.object({ kind: v.literal("image"), url: v.string() }),
|
|
7752
|
+
* )
|
|
7753
|
+
*
|
|
7754
|
+
* // Nullable value:
|
|
7755
|
+
* returns: v.union(v.object({ ... }), v.null())
|
|
7756
|
+
* ```
|
|
7757
|
+
*
|
|
7758
|
+
* @param members The validators to match against.
|
|
7759
|
+
*/
|
|
7760
|
+
union: (...members) => {
|
|
7761
|
+
return new VUnion({
|
|
7762
|
+
isOptional: "required",
|
|
7763
|
+
members
|
|
7764
|
+
});
|
|
7765
|
+
},
|
|
7766
|
+
/**
|
|
7767
|
+
* A validator that accepts any Convex value without validation.
|
|
7768
|
+
*
|
|
7769
|
+
* Prefer using specific validators when possible for better type safety
|
|
7770
|
+
* and runtime validation.
|
|
7771
|
+
*/
|
|
7772
|
+
any: () => {
|
|
7773
|
+
return new VAny({ isOptional: "required" });
|
|
7774
|
+
},
|
|
7775
|
+
/**
|
|
7776
|
+
* Makes a property optional in an object validator.
|
|
7777
|
+
*
|
|
7778
|
+
* An optional property can be omitted entirely when creating a document or
|
|
7779
|
+
* calling a function. This is different from `v.nullable()` which requires
|
|
7780
|
+
* the property to be present but allows `null`.
|
|
7781
|
+
*
|
|
7782
|
+
* @example
|
|
7783
|
+
* ```typescript
|
|
7784
|
+
* v.object({
|
|
7785
|
+
* name: v.string(), // required
|
|
7786
|
+
* nickname: v.optional(v.string()), // can be omitted
|
|
7787
|
+
* })
|
|
7788
|
+
*
|
|
7789
|
+
* // Valid: { name: "Alice" }
|
|
7790
|
+
* // Valid: { name: "Alice", nickname: "Ali" }
|
|
7791
|
+
* // Invalid: { name: "Alice", nickname: null } - use v.nullable() for this
|
|
7792
|
+
* ```
|
|
7793
|
+
*
|
|
7794
|
+
* @param value The property value validator to make optional.
|
|
7795
|
+
*/
|
|
7796
|
+
optional: (value) => {
|
|
7797
|
+
return value.asOptional();
|
|
7798
|
+
},
|
|
7799
|
+
/**
|
|
7800
|
+
* Allows a value to be either the given type or `null`.
|
|
7801
|
+
*
|
|
7802
|
+
* This is shorthand for `v.union(value, v.null())`. Unlike `v.optional()`,
|
|
7803
|
+
* the property must still be present, but may be `null`.
|
|
7804
|
+
*
|
|
7805
|
+
* @example
|
|
7806
|
+
* ```typescript
|
|
7807
|
+
* v.object({
|
|
7808
|
+
* name: v.string(),
|
|
7809
|
+
* deletedAt: v.nullable(v.number()), // must be present, can be null
|
|
7810
|
+
* })
|
|
7811
|
+
*
|
|
7812
|
+
* // Valid: { name: "Alice", deletedAt: null }
|
|
7813
|
+
* // Valid: { name: "Alice", deletedAt: 1234567890 }
|
|
7814
|
+
* // Invalid: { name: "Alice" } - deletedAt is required
|
|
7815
|
+
* ```
|
|
7816
|
+
*/
|
|
7817
|
+
nullable: (value) => {
|
|
7818
|
+
return v$1.union(value, v$1.null());
|
|
7819
|
+
}
|
|
7820
|
+
};
|
|
7821
|
+
//#endregion
|
|
6961
7822
|
//#region ../../node_modules/.pnpm/convex@1.39.1_react@19.2.7/node_modules/convex/dist/esm/values/errors.js
|
|
6962
7823
|
var __defProp$11 = Object.defineProperty;
|
|
6963
7824
|
var __defNormalProp$11 = (obj, key, value) => key in obj ? __defProp$11(obj, key, {
|
|
@@ -7679,6 +8540,344 @@ const moneyExecutionContract = {
|
|
|
7679
8540
|
submitPaymentCommandExecution: makeFunctionReference(CAPXUL_FUNCTIONS["moneyExecution/paymentCommandActions"].submitPaymentCommandExecution)
|
|
7680
8541
|
};
|
|
7681
8542
|
//#endregion
|
|
8543
|
+
//#region ../../packages/sdk/package.json
|
|
8544
|
+
var version = "2.6.0";
|
|
8545
|
+
//#endregion
|
|
8546
|
+
//#region ../../packages/sdk/src/telemetry/capture-exception.ts
|
|
8547
|
+
/** Fixed, leak-safe message — the raw error message may carry PII and never ships. */
|
|
8548
|
+
const EXCEPTION_MESSAGE = "Capxul SDK operation failed";
|
|
8549
|
+
//#endregion
|
|
8550
|
+
//#region ../../packages/sdk/src/observation.ts
|
|
8551
|
+
const SDK_VERSION$1 = version;
|
|
8552
|
+
/** @internal Observe public result methods at the assembled Core SDK boundary. */
|
|
8553
|
+
function observeSdkClient(client, adapter, snapshot) {
|
|
8554
|
+
if (adapter === void 0) return client;
|
|
8555
|
+
const objectProxies = /* @__PURE__ */ new WeakMap();
|
|
8556
|
+
const proxyTargets = /* @__PURE__ */ new WeakMap();
|
|
8557
|
+
const functionWrappers = /* @__PURE__ */ new WeakMap();
|
|
8558
|
+
const wrapObject = (target, path, internal = false) => {
|
|
8559
|
+
const cacheKey = `${internal ? "internal" : "public"}:${path.join(".")}`;
|
|
8560
|
+
let targetProxies = objectProxies.get(target);
|
|
8561
|
+
const cached = targetProxies?.get(cacheKey);
|
|
8562
|
+
if (cached !== void 0) return cached;
|
|
8563
|
+
const proxy = new Proxy(target, { get(currentTarget, property, receiver) {
|
|
8564
|
+
const value = Reflect.get(currentTarget, property, receiver);
|
|
8565
|
+
if (typeof property !== "string") return value;
|
|
8566
|
+
if (path.length === 0 && property === "_internal" && isPlainObject$1(value)) return wrapObject(value, ["_internal"], true);
|
|
8567
|
+
if (internal && property !== "accounts") return value;
|
|
8568
|
+
return wrapValue(value, [...path, property], currentTarget);
|
|
8569
|
+
} });
|
|
8570
|
+
proxyTargets.set(proxy, target);
|
|
8571
|
+
if (targetProxies === void 0) {
|
|
8572
|
+
targetProxies = /* @__PURE__ */ new Map();
|
|
8573
|
+
objectProxies.set(target, targetProxies);
|
|
8574
|
+
}
|
|
8575
|
+
targetProxies.set(cacheKey, proxy);
|
|
8576
|
+
return proxy;
|
|
8577
|
+
};
|
|
8578
|
+
const wrapValue = (value, path, owner) => {
|
|
8579
|
+
if (typeof value === "function") {
|
|
8580
|
+
const callable = value;
|
|
8581
|
+
const operation = path.join(".");
|
|
8582
|
+
let ownerWrappers = functionWrappers.get(owner);
|
|
8583
|
+
if (ownerWrappers === void 0) {
|
|
8584
|
+
ownerWrappers = /* @__PURE__ */ new Map();
|
|
8585
|
+
functionWrappers.set(owner, ownerWrappers);
|
|
8586
|
+
}
|
|
8587
|
+
const cached = ownerWrappers.get(operation);
|
|
8588
|
+
if (cached !== void 0) return cached;
|
|
8589
|
+
let wrapped;
|
|
8590
|
+
wrapped = new Proxy(callable, {
|
|
8591
|
+
apply(currentTarget, thisArg, args) {
|
|
8592
|
+
const invocation = resolveInvocationSnapshot(adapter, snapshot);
|
|
8593
|
+
let output;
|
|
8594
|
+
try {
|
|
8595
|
+
output = Reflect.apply(currentTarget, unwrapReceiver(thisArg), args);
|
|
8596
|
+
} catch (cause) {
|
|
8597
|
+
report(adapter, "exception", operation, cause, invocation);
|
|
8598
|
+
throw cause;
|
|
8599
|
+
}
|
|
8600
|
+
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path, invocation), (cause) => {
|
|
8601
|
+
report(adapter, "exception", operation, cause, invocation);
|
|
8602
|
+
throw cause;
|
|
8603
|
+
});
|
|
8604
|
+
return processOutput(output, path, invocation);
|
|
8605
|
+
},
|
|
8606
|
+
get(currentTarget, property) {
|
|
8607
|
+
if (property === "bind") return Function.prototype.bind.bind(wrapped);
|
|
8608
|
+
if (property === "call") return Function.prototype.call.bind(wrapped);
|
|
8609
|
+
if (property === "apply") return Function.prototype.apply.bind(wrapped);
|
|
8610
|
+
const attached = Reflect.get(currentTarget, property, currentTarget);
|
|
8611
|
+
if (typeof property !== "string") return attached;
|
|
8612
|
+
return wrapValue(attached, [...path, property], currentTarget);
|
|
8613
|
+
}
|
|
8614
|
+
});
|
|
8615
|
+
proxyTargets.set(wrapped, callable);
|
|
8616
|
+
ownerWrappers.set(operation, wrapped);
|
|
8617
|
+
return wrapped;
|
|
8618
|
+
}
|
|
8619
|
+
return isPlainObject$1(value) ? wrapObject(value, path) : value;
|
|
8620
|
+
};
|
|
8621
|
+
const processOutput = (output, path, invocation) => {
|
|
8622
|
+
if (isFailedResult(output)) {
|
|
8623
|
+
report(adapter, "operation", path.join("."), output.error, invocation);
|
|
8624
|
+
return output;
|
|
8625
|
+
}
|
|
8626
|
+
if (isCapxulResult(output)) return output;
|
|
8627
|
+
return isPlainObject$1(output) ? wrapObject(output, path) : output;
|
|
8628
|
+
};
|
|
8629
|
+
return wrapObject(client, []);
|
|
8630
|
+
function unwrapReceiver(receiver) {
|
|
8631
|
+
return (typeof receiver === "object" || typeof receiver === "function") && receiver !== null ? proxyTargets.get(receiver) ?? receiver : receiver;
|
|
8632
|
+
}
|
|
8633
|
+
}
|
|
8634
|
+
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
8635
|
+
function observeFailedResult(result, adapter, operation, origin) {
|
|
8636
|
+
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterSnapshot(adapter), origin);
|
|
8637
|
+
return result;
|
|
8638
|
+
}
|
|
8639
|
+
/**
|
|
8640
|
+
* One failure, one event. The identity machine reports a failed transition
|
|
8641
|
+
* first; when the same `CapxulError` then surfaces as a public method result
|
|
8642
|
+
* (directly or down its `cause` chain), the boundary drops that second report.
|
|
8643
|
+
* Only machine-reported errors are remembered, so a caller that reuses one
|
|
8644
|
+
* error object across unrelated public methods still sees every report.
|
|
8645
|
+
*/
|
|
8646
|
+
const machineReportedCauses = /* @__PURE__ */ new WeakSet();
|
|
8647
|
+
function reportedByMachine(cause) {
|
|
8648
|
+
let link = cause;
|
|
8649
|
+
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
8650
|
+
if (machineReportedCauses.has(link)) return true;
|
|
8651
|
+
link = link.cause;
|
|
8652
|
+
}
|
|
8653
|
+
return false;
|
|
8654
|
+
}
|
|
8655
|
+
function report(adapter, kind, operation, cause, invocation, origin) {
|
|
8656
|
+
if (origin === "machine") {
|
|
8657
|
+
let link = cause;
|
|
8658
|
+
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
8659
|
+
machineReportedCauses.add(link);
|
|
8660
|
+
link = link.cause;
|
|
8661
|
+
}
|
|
8662
|
+
} else if (reportedByMachine(cause)) return;
|
|
8663
|
+
const operationName = normalizeOperation$1(operation);
|
|
8664
|
+
const kindName = normalizeErrorKind(errorKind$1(cause));
|
|
8665
|
+
const context = sanitizeObservationContext({
|
|
8666
|
+
...invocation.context,
|
|
8667
|
+
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
8668
|
+
});
|
|
8669
|
+
const detail = failureDetail(cause);
|
|
8670
|
+
const evidence = failureEvidence(cause);
|
|
8671
|
+
const failure = markFailureInvocationSnapshot({
|
|
8672
|
+
exception: syntheticException(operationName, kindName, evidence.message, evidence.stack),
|
|
8673
|
+
sdkVersion: SDK_VERSION$1,
|
|
8674
|
+
operation: operationName,
|
|
8675
|
+
errorKind: kindName,
|
|
8676
|
+
...context === void 0 ? {} : { context },
|
|
8677
|
+
...detail === void 0 ? {} : { detail },
|
|
8678
|
+
...evidence
|
|
8679
|
+
}, {
|
|
8680
|
+
active: invocation.active,
|
|
8681
|
+
...context === void 0 ? {} : { context }
|
|
8682
|
+
});
|
|
8683
|
+
try {
|
|
8684
|
+
ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
|
|
8685
|
+
} catch {}
|
|
8686
|
+
}
|
|
8687
|
+
function resolveInvocationSnapshot(adapter, snapshot) {
|
|
8688
|
+
if (snapshot !== void 0) try {
|
|
8689
|
+
const captured = snapshot();
|
|
8690
|
+
if (captured !== void 0) return captured;
|
|
8691
|
+
} catch {}
|
|
8692
|
+
return resolveAdapterSnapshot(adapter);
|
|
8693
|
+
}
|
|
8694
|
+
function resolveAdapterSnapshot(adapter) {
|
|
8695
|
+
const context = resolveAdapterContext(adapter);
|
|
8696
|
+
return context === void 0 ? { active: false } : {
|
|
8697
|
+
active: true,
|
|
8698
|
+
context
|
|
8699
|
+
};
|
|
8700
|
+
}
|
|
8701
|
+
function resolveAdapterContext(adapter) {
|
|
8702
|
+
try {
|
|
8703
|
+
return adapter.resolveContext?.();
|
|
8704
|
+
} catch {
|
|
8705
|
+
return;
|
|
8706
|
+
}
|
|
8707
|
+
}
|
|
8708
|
+
function ignoreDeliveryFailure(delivery) {
|
|
8709
|
+
if (!isPromiseLike(delivery)) return;
|
|
8710
|
+
try {
|
|
8711
|
+
Promise.resolve(delivery).catch(() => void 0);
|
|
8712
|
+
} catch {}
|
|
8713
|
+
}
|
|
8714
|
+
const MAX_EVIDENCE_TEXT = 4e3;
|
|
8715
|
+
const MAX_CAUSE_DEPTH = 8;
|
|
8716
|
+
function evidenceText(value) {
|
|
8717
|
+
if (typeof value !== "string" || value.length === 0) return void 0;
|
|
8718
|
+
return redactSecrets(value).slice(0, MAX_EVIDENCE_TEXT);
|
|
8719
|
+
}
|
|
8720
|
+
/** A field whose NAME says credential is masked whatever its value looks like. */
|
|
8721
|
+
const CREDENTIAL_FIELD_NAME$1 = /(?:otp|pass(?:word|wd|phrase)?|token|secret|credential|api[_-]?key|private[_-]?key|authorization|cookie|session)/iu;
|
|
8722
|
+
/** Copy a details object into a JSON-safe shape with every string masked. */
|
|
8723
|
+
function evidenceValue(value, depth = 0) {
|
|
8724
|
+
if (typeof value === "string") return evidenceText(value);
|
|
8725
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
8726
|
+
if (typeof value === "bigint") return value.toString();
|
|
8727
|
+
if (value instanceof Error) return evidenceText(value.message);
|
|
8728
|
+
if (depth >= 4 || typeof value !== "object") return void 0;
|
|
8729
|
+
if (Array.isArray(value)) return value.slice(0, 50).map((item) => evidenceValue(item, depth + 1));
|
|
8730
|
+
const copy = {};
|
|
8731
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
8732
|
+
if (CREDENTIAL_FIELD_NAME$1.test(key)) {
|
|
8733
|
+
copy[key] = "[REDACTED]";
|
|
8734
|
+
continue;
|
|
8735
|
+
}
|
|
8736
|
+
const safe = evidenceValue(nested, depth + 1);
|
|
8737
|
+
if (safe !== void 0) copy[key] = safe;
|
|
8738
|
+
}
|
|
8739
|
+
return copy;
|
|
8740
|
+
}
|
|
8741
|
+
/**
|
|
8742
|
+
* @internal The evidence in PostHog property shape, for product events that
|
|
8743
|
+
* name a failure (`bootstrap_failed`). Same keys as the `$exception` event.
|
|
8744
|
+
*/
|
|
8745
|
+
function failureEvidenceProps(cause) {
|
|
8746
|
+
const evidence = failureEvidence(cause);
|
|
8747
|
+
return {
|
|
8748
|
+
...evidence.message === void 0 ? {} : { error_message: evidence.message },
|
|
8749
|
+
...evidence.details === void 0 ? {} : { error_details: evidence.details },
|
|
8750
|
+
...evidence.causeChain === void 0 ? {} : { error_cause: evidence.causeChain.join(" <- ") }
|
|
8751
|
+
};
|
|
8752
|
+
}
|
|
8753
|
+
/** The real failure, masked for secrets only. Never throws. */
|
|
8754
|
+
function failureEvidence(cause) {
|
|
8755
|
+
try {
|
|
8756
|
+
const message = cause instanceof Error ? evidenceText(cause.message) : evidenceText(cause);
|
|
8757
|
+
const stack = cause instanceof Error ? evidenceText(cause.stack) : void 0;
|
|
8758
|
+
const details = isCapxulError(cause) && typeof cause.details === "object" && cause.details !== null ? evidenceValue(cause.details) : void 0;
|
|
8759
|
+
const causeChain = [];
|
|
8760
|
+
let previous = message;
|
|
8761
|
+
let link = cause instanceof Error ? cause.cause : void 0;
|
|
8762
|
+
for (let depth = 0; depth < MAX_CAUSE_DEPTH && link !== void 0 && link !== null; depth++) {
|
|
8763
|
+
const text = link instanceof Error ? evidenceText(link.message) : evidenceText(link);
|
|
8764
|
+
if (text !== void 0 && text !== previous) {
|
|
8765
|
+
causeChain.push(text);
|
|
8766
|
+
previous = text;
|
|
8767
|
+
}
|
|
8768
|
+
link = link instanceof Error ? link.cause : void 0;
|
|
8769
|
+
}
|
|
8770
|
+
return {
|
|
8771
|
+
...message === void 0 ? {} : { message },
|
|
8772
|
+
...details === void 0 || Object.keys(details).length === 0 ? {} : { details },
|
|
8773
|
+
...causeChain.length === 0 ? {} : { causeChain },
|
|
8774
|
+
...stack === void 0 ? {} : { stack }
|
|
8775
|
+
};
|
|
8776
|
+
} catch {
|
|
8777
|
+
return {};
|
|
8778
|
+
}
|
|
8779
|
+
}
|
|
8780
|
+
function errorKind$1(cause) {
|
|
8781
|
+
try {
|
|
8782
|
+
if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
|
|
8783
|
+
if (cause instanceof Error) return normalizeErrorKind(cause.name);
|
|
8784
|
+
return "UnknownFailure";
|
|
8785
|
+
} catch {
|
|
8786
|
+
return "Error";
|
|
8787
|
+
}
|
|
8788
|
+
}
|
|
8789
|
+
/**
|
|
8790
|
+
* @internal Lift the enumerated discriminators off a `CapxulError` so a
|
|
8791
|
+
* boundary event says WHICH provider failed and HOW, not just `PROVIDER_ERROR`.
|
|
8792
|
+
* Shared by the failure boundary and the `bootstrap_failed` product event.
|
|
8793
|
+
*/
|
|
8794
|
+
function failureDetail(cause) {
|
|
8795
|
+
if (!isCapxulError(cause)) return void 0;
|
|
8796
|
+
const details = cause.details;
|
|
8797
|
+
const source = typeof details === "object" && details !== null ? details : {};
|
|
8798
|
+
return sanitizeFailureDetail({
|
|
8799
|
+
provider: source.provider,
|
|
8800
|
+
provider_operation: source.operation,
|
|
8801
|
+
failure_mode: cause.mode ?? source.failure_mode,
|
|
8802
|
+
reason: source.reason,
|
|
8803
|
+
http_status: source.httpStatus,
|
|
8804
|
+
...cause.chain === void 0 ? {} : chainCauseProperties(cause.chain)
|
|
8805
|
+
});
|
|
8806
|
+
}
|
|
8807
|
+
/** The chain-cause half of {@link sanitizeFailureDetail}: same bounds, same masking. */
|
|
8808
|
+
function sanitizeChainDetail(source, detail) {
|
|
8809
|
+
for (const key of [
|
|
8810
|
+
"provider",
|
|
8811
|
+
"provider_operation",
|
|
8812
|
+
"failure_mode",
|
|
8813
|
+
"reason"
|
|
8814
|
+
]) {
|
|
8815
|
+
const value = source[key];
|
|
8816
|
+
if (typeof value === "string" && ENUMERATED_DETAIL_RE.test(value)) detail[key] = value;
|
|
8817
|
+
}
|
|
8818
|
+
const status = source.http_status;
|
|
8819
|
+
if (typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599) detail.http_status = status;
|
|
8820
|
+
for (const key of [
|
|
8821
|
+
"chain_upstream",
|
|
8822
|
+
"chain_method",
|
|
8823
|
+
"chain_revert_name",
|
|
8824
|
+
"chain_revert_selector"
|
|
8825
|
+
]) {
|
|
8826
|
+
const value = source[key];
|
|
8827
|
+
if (typeof value === "string" && ENUMERATED_DETAIL_RE.test(value)) detail[key] = value;
|
|
8828
|
+
}
|
|
8829
|
+
if (typeof source.chain_retryable === "boolean") detail.chain_retryable = source.chain_retryable;
|
|
8830
|
+
const chainHttpStatus = source.chain_http_status;
|
|
8831
|
+
if (typeof chainHttpStatus === "number" && Number.isInteger(chainHttpStatus) && chainHttpStatus >= 100 && chainHttpStatus <= 599) detail.chain_http_status = chainHttpStatus;
|
|
8832
|
+
const chainRpcCode = source.chain_rpc_code;
|
|
8833
|
+
if (typeof chainRpcCode === "number" && Number.isInteger(chainRpcCode)) detail.chain_rpc_code = chainRpcCode;
|
|
8834
|
+
if (isPlainObject$1(source.chain_revert_args)) {
|
|
8835
|
+
const args = {};
|
|
8836
|
+
for (const [key, value] of Object.entries(source.chain_revert_args).slice(0, 8)) {
|
|
8837
|
+
const safeValue = evidenceText(value);
|
|
8838
|
+
if (safeValue !== void 0) args[key.slice(0, 32)] = safeValue.slice(0, 128);
|
|
8839
|
+
}
|
|
8840
|
+
if (Object.keys(args).length > 0) detail.chain_revert_args = args;
|
|
8841
|
+
}
|
|
8842
|
+
const providerMessage = evidenceText(source.chain_provider_message);
|
|
8843
|
+
if (providerMessage !== void 0) detail.chain_provider_message = providerMessage;
|
|
8844
|
+
}
|
|
8845
|
+
function sanitizeFailureDetail(input) {
|
|
8846
|
+
if (typeof input !== "object" || input === null) return void 0;
|
|
8847
|
+
const source = input;
|
|
8848
|
+
const detail = {};
|
|
8849
|
+
sanitizeChainDetail(source, detail);
|
|
8850
|
+
return Object.keys(detail).length === 0 ? void 0 : detail;
|
|
8851
|
+
}
|
|
8852
|
+
/** Enumerated codes only (`convex`, `no-secure-context`, `bootstrap-encode`); free text fails. */
|
|
8853
|
+
const ENUMERATED_DETAIL_RE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u;
|
|
8854
|
+
function normalizeOperation$1(value) {
|
|
8855
|
+
return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
|
|
8856
|
+
}
|
|
8857
|
+
function normalizeErrorKind(value) {
|
|
8858
|
+
return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
|
|
8859
|
+
}
|
|
8860
|
+
function syntheticException(operation, kind, message = EXCEPTION_MESSAGE, stack) {
|
|
8861
|
+
const error = new Error(message);
|
|
8862
|
+
error.name = kind;
|
|
8863
|
+
error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)` + (stack === void 0 ? "" : `\nCaused by: ${stack}`);
|
|
8864
|
+
return error;
|
|
8865
|
+
}
|
|
8866
|
+
function isPromiseLike(value) {
|
|
8867
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
8868
|
+
}
|
|
8869
|
+
function isPlainObject$1(value) {
|
|
8870
|
+
if (typeof value !== "object" || value === null) return false;
|
|
8871
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8872
|
+
return prototype === Object.prototype || prototype === null;
|
|
8873
|
+
}
|
|
8874
|
+
function isCapxulResult(value) {
|
|
8875
|
+
return isPlainObject$1(value) && typeof value.ok === "boolean";
|
|
8876
|
+
}
|
|
8877
|
+
function isFailedResult(value) {
|
|
8878
|
+
return isCapxulResult(value) && value.ok === false && "error" in value;
|
|
8879
|
+
}
|
|
8880
|
+
//#endregion
|
|
7682
8881
|
//#region ../../packages/sdk/src/domain/money/to-wei.ts
|
|
7683
8882
|
/**
|
|
7684
8883
|
* Lower consumer `Money` into an on-chain integer string for guarded writes.
|
|
@@ -7718,16 +8917,22 @@ function emitFaucetRequested(telemetry, input) {
|
|
|
7718
8917
|
}
|
|
7719
8918
|
});
|
|
7720
8919
|
}
|
|
7721
|
-
function emitFaucetFailed(telemetry,
|
|
8920
|
+
function emitFaucetFailed(telemetry, error) {
|
|
7722
8921
|
return emitMoneyTelemetry(telemetry, {
|
|
7723
8922
|
name: "faucet_failed",
|
|
7724
|
-
props: {
|
|
8923
|
+
props: {
|
|
8924
|
+
...failureDetail(error),
|
|
8925
|
+
reason: error.code
|
|
8926
|
+
}
|
|
7725
8927
|
});
|
|
7726
8928
|
}
|
|
7727
|
-
function emitAccountBalanceFailed(telemetry,
|
|
8929
|
+
function emitAccountBalanceFailed(telemetry, error) {
|
|
7728
8930
|
return emitMoneyTelemetry(telemetry, {
|
|
7729
8931
|
name: "account_balance_failed",
|
|
7730
|
-
props: {
|
|
8932
|
+
props: {
|
|
8933
|
+
...failureDetail(error),
|
|
8934
|
+
reason: error.code
|
|
8935
|
+
}
|
|
7731
8936
|
});
|
|
7732
8937
|
}
|
|
7733
8938
|
function emitDepositInitiated(telemetry) {
|
|
@@ -8911,9 +10116,6 @@ async function recoverRawDigestSigner(input) {
|
|
|
8911
10116
|
}
|
|
8912
10117
|
}
|
|
8913
10118
|
//#endregion
|
|
8914
|
-
//#region ../../packages/sdk/package.json
|
|
8915
|
-
var version = "2.5.4";
|
|
8916
|
-
//#endregion
|
|
8917
10119
|
//#region ../../packages/observability/src/engineering.ts
|
|
8918
10120
|
const ENGINEERING_CAPXUL_ENVS = [
|
|
8919
10121
|
"development",
|
|
@@ -9043,11 +10245,11 @@ function fromResult(operation, run) {
|
|
|
9043
10245
|
})
|
|
9044
10246
|
}).pipe(Effect.flatMap((result) => result.ok ? Effect.succeed(result.value) : Effect.fail(new AuthClientError({
|
|
9045
10247
|
operation,
|
|
9046
|
-
kind: errorKind
|
|
10248
|
+
kind: errorKind(result.error),
|
|
9047
10249
|
cause: result.error
|
|
9048
10250
|
}))));
|
|
9049
10251
|
}
|
|
9050
|
-
function errorKind
|
|
10252
|
+
function errorKind(error) {
|
|
9051
10253
|
if (error.code === "CANCELLED") return "cancelled";
|
|
9052
10254
|
if (error.code === "NETWORK_ERROR") return "network";
|
|
9053
10255
|
if (error.code === "INVALID_INPUT" || error.code === "OTP_EXPIRED") return "validation";
|
|
@@ -9841,7 +11043,7 @@ function isTransientBootstrapFailure(error) {
|
|
|
9841
11043
|
const status = error.details?.httpStatus;
|
|
9842
11044
|
return typeof status === "number" && isTransientHttpStatus(status);
|
|
9843
11045
|
}
|
|
9844
|
-
async function safeText(res) {
|
|
11046
|
+
async function safeText$1(res) {
|
|
9845
11047
|
try {
|
|
9846
11048
|
return await res.text();
|
|
9847
11049
|
} catch {
|
|
@@ -9916,7 +11118,7 @@ var HttpBootstrapAdapter = class {
|
|
|
9916
11118
|
return bootstrapErrorFromCapxul("malformedBody", Errors.providerError("convex", "bootstrap", cause instanceof Error ? cause : new Error(String(cause))));
|
|
9917
11119
|
}
|
|
9918
11120
|
});
|
|
9919
|
-
return Effect.promise(() => safeText(res)).pipe(Effect.flatMap((body) => {
|
|
11121
|
+
return Effect.promise(() => safeText$1(res)).pipe(Effect.flatMap((body) => {
|
|
9920
11122
|
if (res.status === 401 || body.startsWith("NOT_AUTHENTICATED")) return Effect.fail(bootstrapErrorFromCapxul("notAuthenticated", Errors.notAuthenticated()));
|
|
9921
11123
|
if (res.status === 400 || body.startsWith("INVALID_INPUT")) return Effect.fail(bootstrapErrorFromCapxul("invalidInput", Errors.invalidInput("publishableKey", "rejected by bootstrap")));
|
|
9922
11124
|
const responseBody = body.slice(0, 300);
|
|
@@ -13858,6 +15060,41 @@ const TelemetryEnvelopeProps = {
|
|
|
13858
15060
|
correlation_id: OptionalString,
|
|
13859
15061
|
sdk_version: OptionalString
|
|
13860
15062
|
};
|
|
15063
|
+
/**
|
|
15064
|
+
* The cause of a failure, flat (ADR-0023 R7–R8). `failure_mode` is the one
|
|
15065
|
+
* word from `@capxul/errors`; the `chain_*` keys are the `ChainCause` when the
|
|
15066
|
+
* failure came from the chain path. Spread into every failure event and posted
|
|
15067
|
+
* on `$exception`, so one PostHog filter finds a cause wherever it was seen.
|
|
15068
|
+
*/
|
|
15069
|
+
const FailureModeSchema = Schema.Literals(FAILURE_MODES$1);
|
|
15070
|
+
const ChainUpstreamSchema = Schema.Literals(CHAIN_UPSTREAMS);
|
|
15071
|
+
const ChainCauseTelemetryProps = {
|
|
15072
|
+
failure_mode: Schema.optional(FailureModeSchema),
|
|
15073
|
+
chain_upstream: Schema.optional(ChainUpstreamSchema),
|
|
15074
|
+
chain_method: OptionalString,
|
|
15075
|
+
chain_retryable: Schema.optional(Schema.Boolean),
|
|
15076
|
+
chain_http_status: Schema.optional(Schema.Number),
|
|
15077
|
+
chain_rpc_code: Schema.optional(Schema.Number),
|
|
15078
|
+
chain_revert_name: OptionalString,
|
|
15079
|
+
chain_revert_selector: OptionalString,
|
|
15080
|
+
chain_revert_args: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
15081
|
+
chain_provider_message: OptionalString
|
|
15082
|
+
};
|
|
15083
|
+
/**
|
|
15084
|
+
* Stamp the required envelope onto an event at its emit boundary. Call-site
|
|
15085
|
+
* props win on conflict: a relay that already knows the true producer (the
|
|
15086
|
+
* browser-failure relay stamps `browser` while running on the server) must not
|
|
15087
|
+
* be overwritten by the transport's own default.
|
|
15088
|
+
*/
|
|
15089
|
+
function stampTelemetryEnvelope(event, defaults) {
|
|
15090
|
+
return {
|
|
15091
|
+
name: event.name,
|
|
15092
|
+
props: {
|
|
15093
|
+
...defaults,
|
|
15094
|
+
...event.props
|
|
15095
|
+
}
|
|
15096
|
+
};
|
|
15097
|
+
}
|
|
13861
15098
|
const AuthOtpRequestedProps = Schema.Struct({
|
|
13862
15099
|
...TelemetryEnvelopeProps,
|
|
13863
15100
|
email: Schema.optional(PII),
|
|
@@ -13881,6 +15118,7 @@ const AuthVerifiedProps = Schema.Struct({
|
|
|
13881
15118
|
});
|
|
13882
15119
|
const AuthFailedProps = Schema.Struct({
|
|
13883
15120
|
...TelemetryEnvelopeProps,
|
|
15121
|
+
...ChainCauseTelemetryProps,
|
|
13884
15122
|
email: Schema.optional(PII),
|
|
13885
15123
|
auth_type: OptionalString,
|
|
13886
15124
|
reason: OptionalString
|
|
@@ -13910,6 +15148,7 @@ const BootstrapResolvedProps = Schema.Struct({
|
|
|
13910
15148
|
});
|
|
13911
15149
|
const BootstrapFailedProps = Schema.Struct({
|
|
13912
15150
|
...TelemetryEnvelopeProps,
|
|
15151
|
+
...ChainCauseTelemetryProps,
|
|
13913
15152
|
applicationId: OptionalAppId,
|
|
13914
15153
|
durationMs: OptionalDurationMs,
|
|
13915
15154
|
origin: OptionalString,
|
|
@@ -13924,6 +15163,7 @@ const AccountBalanceReadProps = Schema.Struct({
|
|
|
13924
15163
|
});
|
|
13925
15164
|
const AccountBalanceFailedProps = Schema.Struct({
|
|
13926
15165
|
...TelemetryEnvelopeProps,
|
|
15166
|
+
...ChainCauseTelemetryProps,
|
|
13927
15167
|
reason: OptionalString
|
|
13928
15168
|
});
|
|
13929
15169
|
const FaucetRequestedProps = Schema.Struct({
|
|
@@ -13940,29 +15180,45 @@ const FaucetConfirmedProps = Schema.Struct({
|
|
|
13940
15180
|
});
|
|
13941
15181
|
const FaucetFailedProps = Schema.Struct({
|
|
13942
15182
|
...TelemetryEnvelopeProps,
|
|
15183
|
+
...ChainCauseTelemetryProps,
|
|
13943
15184
|
reason: OptionalString
|
|
13944
15185
|
});
|
|
13945
|
-
const
|
|
15186
|
+
const ChainServiceSchema = Schema.Literals(["aa-gateway", "backend"]);
|
|
15187
|
+
const ChainUpstreamFallbackProps = Schema.Struct({
|
|
13946
15188
|
...TelemetryEnvelopeProps,
|
|
15189
|
+
service: ChainServiceSchema,
|
|
13947
15190
|
method: Schema.String,
|
|
13948
|
-
from_upstream:
|
|
13949
|
-
|
|
13950
|
-
|
|
13951
|
-
|
|
13952
|
-
|
|
13953
|
-
|
|
13954
|
-
|
|
13955
|
-
|
|
13956
|
-
|
|
13957
|
-
|
|
13958
|
-
|
|
13959
|
-
|
|
13960
|
-
|
|
13961
|
-
|
|
13962
|
-
|
|
13963
|
-
|
|
13964
|
-
|
|
13965
|
-
|
|
15191
|
+
from_upstream: ChainUpstreamSchema,
|
|
15192
|
+
to_upstream: Schema.optional(ChainUpstreamSchema),
|
|
15193
|
+
failure_mode: FailureModeSchema,
|
|
15194
|
+
exhausted: Schema.Boolean,
|
|
15195
|
+
http_status: Schema.optional(Schema.Number),
|
|
15196
|
+
rpc_code: Schema.optional(Schema.Number)
|
|
15197
|
+
});
|
|
15198
|
+
const BundlerErrorProps = Schema.Struct({
|
|
15199
|
+
...TelemetryEnvelopeProps,
|
|
15200
|
+
method: Schema.String,
|
|
15201
|
+
failure_mode: FailureModeSchema,
|
|
15202
|
+
chain_upstream: ChainUpstreamSchema,
|
|
15203
|
+
chain_retryable: Schema.Boolean,
|
|
15204
|
+
http_status: Schema.optional(Schema.Number),
|
|
15205
|
+
rpc_code: Schema.optional(Schema.Number),
|
|
15206
|
+
chain_revert_name: OptionalString,
|
|
15207
|
+
chain_provider_message: OptionalString
|
|
15208
|
+
});
|
|
15209
|
+
const ReceiptPendingProps = Schema.Struct({
|
|
15210
|
+
...TelemetryEnvelopeProps,
|
|
15211
|
+
service: ChainServiceSchema,
|
|
15212
|
+
method: Schema.String,
|
|
15213
|
+
chain_upstream: ChainUpstreamSchema,
|
|
15214
|
+
reason: Schema.Literals(["zero_block_hash", "no_receipt"])
|
|
15215
|
+
});
|
|
15216
|
+
const OperationRetriedProps = Schema.Struct({
|
|
15217
|
+
...TelemetryEnvelopeProps,
|
|
15218
|
+
operation: Schema.String,
|
|
15219
|
+
failure_mode: FailureModeSchema,
|
|
15220
|
+
attempt: Schema.Number,
|
|
15221
|
+
delay_ms: DurationMsSchema
|
|
13966
15222
|
});
|
|
13967
15223
|
const ORG_ID_TELEMETRY_RE = /^org_[0-9A-Za-z]+$/;
|
|
13968
15224
|
const OrgIdTelemetrySchema = Schema.String.pipe(Schema.refine((value) => ORG_ID_TELEMETRY_RE.test(value), { message: "must be org_ plus an alphanumeric id" }));
|
|
@@ -13988,6 +15244,7 @@ const MemberActivationReadyProps = Schema.Struct({
|
|
|
13988
15244
|
});
|
|
13989
15245
|
const MemberActivationFailedProps = Schema.Struct({
|
|
13990
15246
|
...TelemetryEnvelopeProps,
|
|
15247
|
+
...ChainCauseTelemetryProps,
|
|
13991
15248
|
$insert_id: Schema.String,
|
|
13992
15249
|
stage: OnboardingStageSchema,
|
|
13993
15250
|
error_code: Schema.String,
|
|
@@ -14008,6 +15265,7 @@ const OrganizationCreationReadyProps = Schema.Struct({
|
|
|
14008
15265
|
});
|
|
14009
15266
|
const OrganizationCreationFailedProps = Schema.Struct({
|
|
14010
15267
|
...TelemetryEnvelopeProps,
|
|
15268
|
+
...ChainCauseTelemetryProps,
|
|
14011
15269
|
$insert_id: Schema.String,
|
|
14012
15270
|
organization_id: OrgIdTelemetrySchema,
|
|
14013
15271
|
attempt_number: AttemptNumberSchema,
|
|
@@ -14087,6 +15345,7 @@ const OrgCreatedProps = Schema.Struct({
|
|
|
14087
15345
|
});
|
|
14088
15346
|
const OrgCreateFailedProps = Schema.Struct({
|
|
14089
15347
|
...TelemetryEnvelopeProps,
|
|
15348
|
+
...ChainCauseTelemetryProps,
|
|
14090
15349
|
org_id: OptionalOrgId,
|
|
14091
15350
|
reason: OptionalString
|
|
14092
15351
|
});
|
|
@@ -14124,10 +15383,18 @@ const PaymentSettledL2Props = Schema.Struct({
|
|
|
14124
15383
|
});
|
|
14125
15384
|
const PaymentFailedL2Props = Schema.Struct({
|
|
14126
15385
|
...TelemetryEnvelopeProps,
|
|
15386
|
+
...ChainCauseTelemetryProps,
|
|
14127
15387
|
kind: Schema.String,
|
|
14128
15388
|
payment_id: Schema.String,
|
|
14129
15389
|
reason_code: Schema.String
|
|
14130
15390
|
});
|
|
15391
|
+
const PaymentVerificationRetryProps = Schema.Struct({
|
|
15392
|
+
...TelemetryEnvelopeProps,
|
|
15393
|
+
command_id: Schema.String,
|
|
15394
|
+
attempt: Schema.Number,
|
|
15395
|
+
reason_code: Schema.String,
|
|
15396
|
+
chain_id: Schema.Number
|
|
15397
|
+
});
|
|
14131
15398
|
const DepositInitiatedProps = Schema.Struct({ ...TelemetryEnvelopeProps });
|
|
14132
15399
|
const DepositSettledProps = Schema.Struct({
|
|
14133
15400
|
...TelemetryEnvelopeProps,
|
|
@@ -14166,182 +15433,200 @@ const MovementScanIncidentProps = Schema.Struct({
|
|
|
14166
15433
|
incident_kind: Schema.String,
|
|
14167
15434
|
anchor_block_number: Schema.Number
|
|
14168
15435
|
});
|
|
14169
|
-
|
|
14170
|
-
|
|
14171
|
-
|
|
14172
|
-
|
|
14173
|
-
|
|
14174
|
-
|
|
14175
|
-
|
|
14176
|
-
|
|
14177
|
-
|
|
14178
|
-
|
|
14179
|
-
|
|
14180
|
-
|
|
14181
|
-
|
|
14182
|
-
|
|
14183
|
-
|
|
14184
|
-
|
|
14185
|
-
|
|
14186
|
-
|
|
14187
|
-
|
|
14188
|
-
|
|
14189
|
-
|
|
14190
|
-
|
|
14191
|
-
|
|
14192
|
-
|
|
14193
|
-
|
|
14194
|
-
|
|
14195
|
-
|
|
14196
|
-
|
|
14197
|
-
|
|
14198
|
-
|
|
14199
|
-
|
|
14200
|
-
|
|
14201
|
-
|
|
14202
|
-
|
|
14203
|
-
|
|
14204
|
-
|
|
14205
|
-
|
|
14206
|
-
|
|
14207
|
-
|
|
14208
|
-
|
|
14209
|
-
|
|
14210
|
-
|
|
14211
|
-
|
|
14212
|
-
|
|
14213
|
-
|
|
14214
|
-
|
|
14215
|
-
|
|
14216
|
-
|
|
14217
|
-
|
|
14218
|
-
|
|
14219
|
-
|
|
14220
|
-
|
|
14221
|
-
|
|
14222
|
-
|
|
14223
|
-
|
|
14224
|
-
|
|
14225
|
-
|
|
14226
|
-
|
|
14227
|
-
|
|
14228
|
-
|
|
14229
|
-
|
|
14230
|
-
|
|
14231
|
-
|
|
14232
|
-
|
|
14233
|
-
|
|
14234
|
-
|
|
14235
|
-
|
|
14236
|
-
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
|
|
14240
|
-
|
|
14241
|
-
|
|
14242
|
-
|
|
14243
|
-
|
|
14244
|
-
|
|
14245
|
-
|
|
14246
|
-
|
|
14247
|
-
|
|
14248
|
-
|
|
14249
|
-
|
|
14250
|
-
|
|
14251
|
-
|
|
14252
|
-
|
|
14253
|
-
|
|
14254
|
-
|
|
14255
|
-
|
|
14256
|
-
|
|
14257
|
-
|
|
14258
|
-
|
|
14259
|
-
|
|
14260
|
-
|
|
14261
|
-
|
|
14262
|
-
|
|
14263
|
-
|
|
14264
|
-
|
|
14265
|
-
|
|
14266
|
-
|
|
14267
|
-
|
|
14268
|
-
|
|
14269
|
-
|
|
14270
|
-
|
|
14271
|
-
|
|
14272
|
-
|
|
14273
|
-
|
|
14274
|
-
|
|
14275
|
-
|
|
14276
|
-
|
|
14277
|
-
|
|
14278
|
-
|
|
14279
|
-
|
|
14280
|
-
|
|
14281
|
-
|
|
14282
|
-
|
|
14283
|
-
|
|
14284
|
-
|
|
14285
|
-
|
|
14286
|
-
|
|
14287
|
-
|
|
14288
|
-
|
|
14289
|
-
|
|
14290
|
-
|
|
14291
|
-
|
|
14292
|
-
|
|
14293
|
-
|
|
14294
|
-
|
|
14295
|
-
|
|
14296
|
-
|
|
14297
|
-
|
|
14298
|
-
|
|
14299
|
-
|
|
14300
|
-
|
|
14301
|
-
|
|
14302
|
-
|
|
14303
|
-
|
|
14304
|
-
|
|
14305
|
-
|
|
14306
|
-
|
|
14307
|
-
|
|
14308
|
-
|
|
14309
|
-
|
|
14310
|
-
|
|
14311
|
-
|
|
14312
|
-
|
|
14313
|
-
|
|
14314
|
-
|
|
14315
|
-
|
|
14316
|
-
|
|
14317
|
-
|
|
14318
|
-
|
|
14319
|
-
|
|
14320
|
-
|
|
14321
|
-
|
|
14322
|
-
|
|
14323
|
-
|
|
14324
|
-
|
|
14325
|
-
|
|
14326
|
-
|
|
14327
|
-
|
|
14328
|
-
|
|
14329
|
-
|
|
14330
|
-
|
|
14331
|
-
|
|
14332
|
-
|
|
14333
|
-
|
|
14334
|
-
|
|
14335
|
-
|
|
14336
|
-
|
|
14337
|
-
|
|
14338
|
-
|
|
14339
|
-
|
|
14340
|
-
|
|
14341
|
-
|
|
14342
|
-
|
|
14343
|
-
|
|
14344
|
-
|
|
15436
|
+
const TELEMETRY_EVENT_SCHEMAS = {
|
|
15437
|
+
auth_otp_requested: Schema.Struct({
|
|
15438
|
+
name: Schema.Literal("auth_otp_requested"),
|
|
15439
|
+
props: AuthOtpRequestedProps
|
|
15440
|
+
}),
|
|
15441
|
+
auth_otp_delivered: Schema.Struct({
|
|
15442
|
+
name: Schema.Literal("auth_otp_delivered"),
|
|
15443
|
+
props: AuthOtpDeliveredProps
|
|
15444
|
+
}),
|
|
15445
|
+
auth_otp_expired: Schema.Struct({
|
|
15446
|
+
name: Schema.Literal("auth_otp_expired"),
|
|
15447
|
+
props: AuthOtpExpiredProps
|
|
15448
|
+
}),
|
|
15449
|
+
auth_verified: Schema.Struct({
|
|
15450
|
+
name: Schema.Literal("auth_verified"),
|
|
15451
|
+
props: AuthVerifiedProps
|
|
15452
|
+
}),
|
|
15453
|
+
auth_failed: Schema.Struct({
|
|
15454
|
+
name: Schema.Literal("auth_failed"),
|
|
15455
|
+
props: AuthFailedProps
|
|
15456
|
+
}),
|
|
15457
|
+
auth_signed_out: Schema.Struct({
|
|
15458
|
+
name: Schema.Literal("auth_signed_out"),
|
|
15459
|
+
props: AuthSignedOutProps
|
|
15460
|
+
}),
|
|
15461
|
+
onboarding_intent_selected: Schema.Struct({
|
|
15462
|
+
name: Schema.Literal("onboarding_intent_selected"),
|
|
15463
|
+
props: OnboardingIntentSelectedProps
|
|
15464
|
+
}),
|
|
15465
|
+
onboarding_profile_submitted: Schema.Struct({
|
|
15466
|
+
name: Schema.Literal("onboarding_profile_submitted"),
|
|
15467
|
+
props: OnboardingProfileSubmittedProps
|
|
15468
|
+
}),
|
|
15469
|
+
onboarding_organization_submitted: Schema.Struct({
|
|
15470
|
+
name: Schema.Literal("onboarding_organization_submitted"),
|
|
15471
|
+
props: OnboardingOrganizationSubmittedProps
|
|
15472
|
+
}),
|
|
15473
|
+
onboarding_dashboard_reached: Schema.Struct({
|
|
15474
|
+
name: Schema.Literal("onboarding_dashboard_reached"),
|
|
15475
|
+
props: OnboardingDashboardReachedProps
|
|
15476
|
+
}),
|
|
15477
|
+
provisioning_safe_created: Schema.Struct({
|
|
15478
|
+
name: Schema.Literal("provisioning_safe_created"),
|
|
15479
|
+
props: ProvisioningSafeCreatedProps
|
|
15480
|
+
}),
|
|
15481
|
+
provisioning_safe_confirmed: Schema.Struct({
|
|
15482
|
+
name: Schema.Literal("provisioning_safe_confirmed"),
|
|
15483
|
+
props: ProvisioningSafeConfirmedProps
|
|
15484
|
+
}),
|
|
15485
|
+
bootstrap_resolved: Schema.Struct({
|
|
15486
|
+
name: Schema.Literal("bootstrap_resolved"),
|
|
15487
|
+
props: BootstrapResolvedProps
|
|
15488
|
+
}),
|
|
15489
|
+
bootstrap_failed: Schema.Struct({
|
|
15490
|
+
name: Schema.Literal("bootstrap_failed"),
|
|
15491
|
+
props: BootstrapFailedProps
|
|
15492
|
+
}),
|
|
15493
|
+
member_activation_started: Schema.Struct({
|
|
15494
|
+
name: Schema.Literal("member_activation_started"),
|
|
15495
|
+
props: MemberActivationStartedProps
|
|
15496
|
+
}),
|
|
15497
|
+
member_activation_ready: Schema.Struct({
|
|
15498
|
+
name: Schema.Literal("member_activation_ready"),
|
|
15499
|
+
props: MemberActivationReadyProps
|
|
15500
|
+
}),
|
|
15501
|
+
member_activation_failed: Schema.Struct({
|
|
15502
|
+
name: Schema.Literal("member_activation_failed"),
|
|
15503
|
+
props: MemberActivationFailedProps
|
|
15504
|
+
}),
|
|
15505
|
+
organization_creation_started: Schema.Struct({
|
|
15506
|
+
name: Schema.Literal("organization_creation_started"),
|
|
15507
|
+
props: OrganizationCreationStartedProps
|
|
15508
|
+
}),
|
|
15509
|
+
organization_creation_ready: Schema.Struct({
|
|
15510
|
+
name: Schema.Literal("organization_creation_ready"),
|
|
15511
|
+
props: OrganizationCreationReadyProps
|
|
15512
|
+
}),
|
|
15513
|
+
organization_creation_failed: Schema.Struct({
|
|
15514
|
+
name: Schema.Literal("organization_creation_failed"),
|
|
15515
|
+
props: OrganizationCreationFailedProps
|
|
15516
|
+
}),
|
|
15517
|
+
account_balance_read: Schema.Struct({
|
|
15518
|
+
name: Schema.Literal("account_balance_read"),
|
|
15519
|
+
props: AccountBalanceReadProps
|
|
15520
|
+
}),
|
|
15521
|
+
account_balance_failed: Schema.Struct({
|
|
15522
|
+
name: Schema.Literal("account_balance_failed"),
|
|
15523
|
+
props: AccountBalanceFailedProps
|
|
15524
|
+
}),
|
|
15525
|
+
faucet_requested: Schema.Struct({
|
|
15526
|
+
name: Schema.Literal("faucet_requested"),
|
|
15527
|
+
props: FaucetRequestedProps
|
|
15528
|
+
}),
|
|
15529
|
+
faucet_confirmed: Schema.Struct({
|
|
15530
|
+
name: Schema.Literal("faucet_confirmed"),
|
|
15531
|
+
props: FaucetConfirmedProps
|
|
15532
|
+
}),
|
|
15533
|
+
faucet_failed: Schema.Struct({
|
|
15534
|
+
name: Schema.Literal("faucet_failed"),
|
|
15535
|
+
props: FaucetFailedProps
|
|
15536
|
+
}),
|
|
15537
|
+
chain_upstream_fallback: Schema.Struct({
|
|
15538
|
+
name: Schema.Literal("chain_upstream_fallback"),
|
|
15539
|
+
props: ChainUpstreamFallbackProps
|
|
15540
|
+
}),
|
|
15541
|
+
bundler_error: Schema.Struct({
|
|
15542
|
+
name: Schema.Literal("bundler_error"),
|
|
15543
|
+
props: BundlerErrorProps
|
|
15544
|
+
}),
|
|
15545
|
+
receipt_pending: Schema.Struct({
|
|
15546
|
+
name: Schema.Literal("receipt_pending"),
|
|
15547
|
+
props: ReceiptPendingProps
|
|
15548
|
+
}),
|
|
15549
|
+
operation_retried: Schema.Struct({
|
|
15550
|
+
name: Schema.Literal("operation_retried"),
|
|
15551
|
+
props: OperationRetriedProps
|
|
15552
|
+
}),
|
|
15553
|
+
org_create_started: Schema.Struct({
|
|
15554
|
+
name: Schema.Literal("org_create_started"),
|
|
15555
|
+
props: OrgCreateStartedProps
|
|
15556
|
+
}),
|
|
15557
|
+
org_safe_created: Schema.Struct({
|
|
15558
|
+
name: Schema.Literal("org_safe_created"),
|
|
15559
|
+
props: OrgSafeCreatedProps
|
|
15560
|
+
}),
|
|
15561
|
+
org_safe_confirmed: Schema.Struct({
|
|
15562
|
+
name: Schema.Literal("org_safe_confirmed"),
|
|
15563
|
+
props: OrgSafeConfirmedProps
|
|
15564
|
+
}),
|
|
15565
|
+
org_roles_seeded: Schema.Struct({
|
|
15566
|
+
name: Schema.Literal("org_roles_seeded"),
|
|
15567
|
+
props: OrgRolesSeededProps
|
|
15568
|
+
}),
|
|
15569
|
+
org_created: Schema.Struct({
|
|
15570
|
+
name: Schema.Literal("org_created"),
|
|
15571
|
+
props: OrgCreatedProps
|
|
15572
|
+
}),
|
|
15573
|
+
org_create_failed: Schema.Struct({
|
|
15574
|
+
name: Schema.Literal("org_create_failed"),
|
|
15575
|
+
props: OrgCreateFailedProps
|
|
15576
|
+
}),
|
|
15577
|
+
org_invite_sent: Schema.Struct({
|
|
15578
|
+
name: Schema.Literal("org_invite_sent"),
|
|
15579
|
+
props: OrgInviteSentProps
|
|
15580
|
+
}),
|
|
15581
|
+
org_invite_accepted: Schema.Struct({
|
|
15582
|
+
name: Schema.Literal("org_invite_accepted"),
|
|
15583
|
+
props: OrgInviteAcceptedProps
|
|
15584
|
+
}),
|
|
15585
|
+
org_invite_expired: Schema.Struct({
|
|
15586
|
+
name: Schema.Literal("org_invite_expired"),
|
|
15587
|
+
props: OrgInviteExpiredProps
|
|
15588
|
+
}),
|
|
15589
|
+
payment_initiated: Schema.Struct({
|
|
15590
|
+
name: Schema.Literal("payment_initiated"),
|
|
15591
|
+
props: PaymentInitiatedProps
|
|
15592
|
+
}),
|
|
15593
|
+
payment_settled: Schema.Struct({
|
|
15594
|
+
name: Schema.Literal("payment_settled"),
|
|
15595
|
+
props: PaymentSettledL2Props
|
|
15596
|
+
}),
|
|
15597
|
+
payment_failed: Schema.Struct({
|
|
15598
|
+
name: Schema.Literal("payment_failed"),
|
|
15599
|
+
props: PaymentFailedL2Props
|
|
15600
|
+
}),
|
|
15601
|
+
payment_verification_retry: Schema.Struct({
|
|
15602
|
+
name: Schema.Literal("payment_verification_retry"),
|
|
15603
|
+
props: PaymentVerificationRetryProps
|
|
15604
|
+
}),
|
|
15605
|
+
deposit_initiated: Schema.Struct({
|
|
15606
|
+
name: Schema.Literal("deposit_initiated"),
|
|
15607
|
+
props: DepositInitiatedProps
|
|
15608
|
+
}),
|
|
15609
|
+
deposit_settled: Schema.Struct({
|
|
15610
|
+
name: Schema.Literal("deposit_settled"),
|
|
15611
|
+
props: DepositSettledProps
|
|
15612
|
+
}),
|
|
15613
|
+
permission_mirror_verification: Schema.Struct({
|
|
15614
|
+
name: Schema.Literal("permission_mirror_verification"),
|
|
15615
|
+
props: PermissionMirrorVerificationProps
|
|
15616
|
+
}),
|
|
15617
|
+
movement_scan_window: Schema.Struct({
|
|
15618
|
+
name: Schema.Literal("movement_scan_window"),
|
|
15619
|
+
props: MovementScanWindowProps
|
|
15620
|
+
}),
|
|
15621
|
+
movement_scan_checkpoint: Schema.Struct({
|
|
15622
|
+
name: Schema.Literal("movement_scan_checkpoint"),
|
|
15623
|
+
props: MovementScanCheckpointProps
|
|
15624
|
+
}),
|
|
15625
|
+
movement_scan_incident: Schema.Struct({
|
|
15626
|
+
name: Schema.Literal("movement_scan_incident"),
|
|
15627
|
+
props: MovementScanIncidentProps
|
|
15628
|
+
})
|
|
15629
|
+
};
|
|
14345
15630
|
function redactTelemetryProps(name, props, options = {}) {
|
|
14346
15631
|
if (props === void 0) return void 0;
|
|
14347
15632
|
const clone = cloneProps$1(props);
|
|
@@ -14742,7 +16027,7 @@ const isBoolean = (thing) => thing === true || thing === false;
|
|
|
14742
16027
|
*
|
|
14743
16028
|
* @returns {boolean} True if value is a plain Object, otherwise false
|
|
14744
16029
|
*/
|
|
14745
|
-
const isPlainObject
|
|
16030
|
+
const isPlainObject = (val) => {
|
|
14746
16031
|
if (kindOf(val) !== "object") return false;
|
|
14747
16032
|
const prototype = getPrototypeOf(val);
|
|
14748
16033
|
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
|
|
@@ -14957,8 +16242,8 @@ function merge(...objs) {
|
|
|
14957
16242
|
if (key === "__proto__" || key === "constructor" || key === "prototype") return;
|
|
14958
16243
|
const targetKey = caseless && typeof key === "string" && findKey(result, key) || key;
|
|
14959
16244
|
const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : void 0;
|
|
14960
|
-
if (isPlainObject
|
|
14961
|
-
else if (isPlainObject
|
|
16245
|
+
if (isPlainObject(existing) && isPlainObject(val)) result[targetKey] = merge(existing, val);
|
|
16246
|
+
else if (isPlainObject(val)) result[targetKey] = merge({}, val);
|
|
14962
16247
|
else if (isArray(val)) result[targetKey] = val.slice();
|
|
14963
16248
|
else if (!skipUndefined || !isUndefined(val)) result[targetKey] = val;
|
|
14964
16249
|
};
|
|
@@ -15304,7 +16589,7 @@ var utils_default = {
|
|
|
15304
16589
|
isNumber,
|
|
15305
16590
|
isBoolean,
|
|
15306
16591
|
isObject,
|
|
15307
|
-
isPlainObject
|
|
16592
|
+
isPlainObject,
|
|
15308
16593
|
isEmptyObject,
|
|
15309
16594
|
isReadableStream,
|
|
15310
16595
|
isRequest,
|
|
@@ -37579,7 +38864,7 @@ function normalizeConfirmationBackoff(override) {
|
|
|
37579
38864
|
}
|
|
37580
38865
|
const failureOf = (error) => {
|
|
37581
38866
|
if (error instanceof CapxulError) {
|
|
37582
|
-
const mode = error.details?.failure_mode;
|
|
38867
|
+
const mode = error.mode ?? error.details?.failure_mode;
|
|
37583
38868
|
return {
|
|
37584
38869
|
code: error.code,
|
|
37585
38870
|
message: error.message,
|
|
@@ -37702,7 +38987,7 @@ const runOrgStep = (setup, orgId, step, controls, retryDelayMs) => {
|
|
|
37702
38987
|
})];
|
|
37703
38988
|
return resultEffect(name, invoke);
|
|
37704
38989
|
};
|
|
37705
|
-
const orgLane = (setup, start, send, controls, backoff) => Effect.gen(function* () {
|
|
38990
|
+
const orgLane = (setup, start, send, controls, backoff, telemetry) => Effect.gen(function* () {
|
|
37706
38991
|
let orgId;
|
|
37707
38992
|
let lifecycle;
|
|
37708
38993
|
if (start.kind === "create") {
|
|
@@ -37785,6 +39070,15 @@ const orgLane = (setup, start, send, controls, backoff) => Effect.gen(function*
|
|
|
37785
39070
|
if (lifecycle.at === "confirmingBootstrap" && lifecycle.retryable && retries < backoff.maxRetries) {
|
|
37786
39071
|
const delayMs = Math.min(backoff.initialDelayMs * 2 ** retries, backoff.maxDelayMs);
|
|
37787
39072
|
retries += 1;
|
|
39073
|
+
if (telemetry !== void 0) yield* telemetry.emit({
|
|
39074
|
+
name: "operation_retried",
|
|
39075
|
+
props: {
|
|
39076
|
+
operation: "org.confirmBootstrap",
|
|
39077
|
+
failure_mode: failureOf(lifecycle.error).mode ?? "unknown",
|
|
39078
|
+
attempt: retries,
|
|
39079
|
+
delay_ms: delayMs
|
|
39080
|
+
}
|
|
39081
|
+
}).pipe(Effect.catchDefect(() => Effect.void));
|
|
37788
39082
|
yield* Effect.sleep(Duration.millis(delayMs));
|
|
37789
39083
|
const reset = yield* Effect.result(resultEffect("organization-setup.retry", (parent) => setup.retry({
|
|
37790
39084
|
orgId,
|
|
@@ -37998,7 +39292,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
|
|
|
37998
39292
|
run: (send, controls) => orgLane(input.organizationSetup, {
|
|
37999
39293
|
kind: "create",
|
|
38000
39294
|
draft: event.draft
|
|
38001
|
-
}, send, controls, backoff)
|
|
39295
|
+
}, send, controls, backoff, input.telemetry)
|
|
38002
39296
|
};
|
|
38003
39297
|
case "AttachOrganization": return input.organizationSetup === void 0 || org?.at !== "loading" ? void 0 : {
|
|
38004
39298
|
slot: IDENTITY_SLOT.org,
|
|
@@ -38006,7 +39300,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
|
|
|
38006
39300
|
run: (send, controls) => orgLane(input.organizationSetup, {
|
|
38007
39301
|
kind: "attach",
|
|
38008
39302
|
orgId: org.orgId
|
|
38009
|
-
}, send, controls, backoff)
|
|
39303
|
+
}, send, controls, backoff, input.telemetry)
|
|
38010
39304
|
};
|
|
38011
39305
|
case "RetryOrganization": return input.organizationSetup === void 0 || org?.at !== "settingUp" ? void 0 : {
|
|
38012
39306
|
slot: IDENTITY_SLOT.org,
|
|
@@ -38014,7 +39308,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
|
|
|
38014
39308
|
run: (send, controls) => orgLane(input.organizationSetup, {
|
|
38015
39309
|
kind: "retry",
|
|
38016
39310
|
orgId: org.orgId
|
|
38017
|
-
}, send, controls, backoff)
|
|
39311
|
+
}, send, controls, backoff, input.telemetry)
|
|
38018
39312
|
};
|
|
38019
39313
|
default: return;
|
|
38020
39314
|
}
|
|
@@ -38421,7 +39715,7 @@ function accountsDepsLayer(deps) {
|
|
|
38421
39715
|
}
|
|
38422
39716
|
const readAccountProgram = Effect.gen(function* () {
|
|
38423
39717
|
const deps = yield* AccountsDepsTag;
|
|
38424
|
-
return yield* deps.accountReadPort.readBalance({ chainId: deps.chainId }).pipe(Effect.tapError((error) => Effect.promise(() => emitAccountBalanceFailed(deps.telemetry, error.
|
|
39718
|
+
return yield* deps.accountReadPort.readBalance({ chainId: deps.chainId }).pipe(Effect.tapError((error) => Effect.promise(() => emitAccountBalanceFailed(deps.telemetry, error.publicError))), Effect.mapError((error) => error.publicError));
|
|
38425
39719
|
});
|
|
38426
39720
|
function fundFromFaucetProgram(amount) {
|
|
38427
39721
|
return Effect.gen(function* () {
|
|
@@ -38433,7 +39727,7 @@ function fundFromFaucetProgram(amount) {
|
|
|
38433
39727
|
return yield* deps.accountReadPort.fundFromFaucet({
|
|
38434
39728
|
chainId: deps.chainId,
|
|
38435
39729
|
amount
|
|
38436
|
-
}).pipe(Effect.tapError((error) => Effect.promise(() => emitFaucetFailed(deps.telemetry, error.
|
|
39730
|
+
}).pipe(Effect.tapError((error) => Effect.promise(() => emitFaucetFailed(deps.telemetry, error.publicError))), Effect.mapError((error) => error.publicError));
|
|
38437
39731
|
});
|
|
38438
39732
|
}
|
|
38439
39733
|
//#endregion
|
|
@@ -38821,6 +40115,7 @@ const payrollContract = {
|
|
|
38821
40115
|
authorizeRun: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/actions"].authorizeRun),
|
|
38822
40116
|
runs: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].runs),
|
|
38823
40117
|
groups: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].groups),
|
|
40118
|
+
terms: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].terms),
|
|
38824
40119
|
saveGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].saveGroup),
|
|
38825
40120
|
removeGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].removeGroup)
|
|
38826
40121
|
};
|
|
@@ -38974,6 +40269,7 @@ function makePayrollMethods(deps, orgId) {
|
|
|
38974
40269
|
};
|
|
38975
40270
|
}
|
|
38976
40271
|
},
|
|
40272
|
+
terms: (options) => runIfActive(options?.signal, "payroll.terms", () => deps.convexCall.query(payrollContract.terms, { orgId })),
|
|
38977
40273
|
groups: {
|
|
38978
40274
|
list: (options) => runIfActive(options?.signal, "payroll.groups.list", () => Effect.map(deps.convexCall.query(payrollContract.groups, { orgId }), (groups) => groups.map(toPayrollGroup))),
|
|
38979
40275
|
save: (input, options) => runIfActive(options?.signal, "payroll.groups.save", () => Effect.map(deps.convexCall.mutation(payrollContract.saveGroup, {
|
|
@@ -38999,6 +40295,7 @@ function makeUnavailablePayrollMethods() {
|
|
|
38999
40295
|
return {
|
|
39000
40296
|
runs: payrollUnavailable,
|
|
39001
40297
|
authorizeRun: payrollUnavailable,
|
|
40298
|
+
terms: payrollUnavailable,
|
|
39002
40299
|
groups: {
|
|
39003
40300
|
list: payrollUnavailable,
|
|
39004
40301
|
save: payrollUnavailable,
|
|
@@ -39072,10 +40369,13 @@ function emitOrgCreated(telemetry, input) {
|
|
|
39072
40369
|
}
|
|
39073
40370
|
});
|
|
39074
40371
|
}
|
|
39075
|
-
function emitOrgCreateFailed(telemetry,
|
|
40372
|
+
function emitOrgCreateFailed(telemetry, error) {
|
|
39076
40373
|
return emitOrgTelemetry(telemetry, {
|
|
39077
40374
|
name: "org_create_failed",
|
|
39078
|
-
props: {
|
|
40375
|
+
props: {
|
|
40376
|
+
...failureDetail(error),
|
|
40377
|
+
reason: error.code
|
|
40378
|
+
}
|
|
39079
40379
|
});
|
|
39080
40380
|
}
|
|
39081
40381
|
function emitOrgInviteSent(telemetry, input) {
|
|
@@ -39179,7 +40479,7 @@ function createOrgProgram(input) {
|
|
|
39179
40479
|
const org = hermeticOrgView(input);
|
|
39180
40480
|
yield* emitCreationFunnelTail(deps.telemetry, org, chainId);
|
|
39181
40481
|
return org;
|
|
39182
|
-
}).pipe(Effect.tapError((error) => Effect.promise(() => emitOrgCreateFailed(deps.telemetry, error
|
|
40482
|
+
}).pipe(Effect.tapError((error) => Effect.promise(() => emitOrgCreateFailed(deps.telemetry, error))));
|
|
39183
40483
|
});
|
|
39184
40484
|
}
|
|
39185
40485
|
/** Emit the remaining `org_creation` funnel steps once the org is built. */
|
|
@@ -39774,313 +41074,6 @@ function detectAuthCacheAdapter() {
|
|
|
39774
41074
|
return new InMemoryAuthCacheAdapter();
|
|
39775
41075
|
}
|
|
39776
41076
|
//#endregion
|
|
39777
|
-
//#region ../../packages/sdk/src/telemetry/capture-exception.ts
|
|
39778
|
-
/** Fixed, leak-safe message — the raw error message may carry PII and never ships. */
|
|
39779
|
-
const EXCEPTION_MESSAGE = "Capxul SDK operation failed";
|
|
39780
|
-
//#endregion
|
|
39781
|
-
//#region ../../packages/sdk/src/observation.ts
|
|
39782
|
-
const SDK_VERSION$1 = version;
|
|
39783
|
-
/** @internal Observe public result methods at the assembled Core SDK boundary. */
|
|
39784
|
-
function observeSdkClient(client, adapter, snapshot) {
|
|
39785
|
-
if (adapter === void 0) return client;
|
|
39786
|
-
const objectProxies = /* @__PURE__ */ new WeakMap();
|
|
39787
|
-
const proxyTargets = /* @__PURE__ */ new WeakMap();
|
|
39788
|
-
const functionWrappers = /* @__PURE__ */ new WeakMap();
|
|
39789
|
-
const wrapObject = (target, path, internal = false) => {
|
|
39790
|
-
const cacheKey = `${internal ? "internal" : "public"}:${path.join(".")}`;
|
|
39791
|
-
let targetProxies = objectProxies.get(target);
|
|
39792
|
-
const cached = targetProxies?.get(cacheKey);
|
|
39793
|
-
if (cached !== void 0) return cached;
|
|
39794
|
-
const proxy = new Proxy(target, { get(currentTarget, property, receiver) {
|
|
39795
|
-
const value = Reflect.get(currentTarget, property, receiver);
|
|
39796
|
-
if (typeof property !== "string") return value;
|
|
39797
|
-
if (path.length === 0 && property === "_internal" && isPlainObject(value)) return wrapObject(value, ["_internal"], true);
|
|
39798
|
-
if (internal && property !== "accounts") return value;
|
|
39799
|
-
return wrapValue(value, [...path, property], currentTarget);
|
|
39800
|
-
} });
|
|
39801
|
-
proxyTargets.set(proxy, target);
|
|
39802
|
-
if (targetProxies === void 0) {
|
|
39803
|
-
targetProxies = /* @__PURE__ */ new Map();
|
|
39804
|
-
objectProxies.set(target, targetProxies);
|
|
39805
|
-
}
|
|
39806
|
-
targetProxies.set(cacheKey, proxy);
|
|
39807
|
-
return proxy;
|
|
39808
|
-
};
|
|
39809
|
-
const wrapValue = (value, path, owner) => {
|
|
39810
|
-
if (typeof value === "function") {
|
|
39811
|
-
const callable = value;
|
|
39812
|
-
const operation = path.join(".");
|
|
39813
|
-
let ownerWrappers = functionWrappers.get(owner);
|
|
39814
|
-
if (ownerWrappers === void 0) {
|
|
39815
|
-
ownerWrappers = /* @__PURE__ */ new Map();
|
|
39816
|
-
functionWrappers.set(owner, ownerWrappers);
|
|
39817
|
-
}
|
|
39818
|
-
const cached = ownerWrappers.get(operation);
|
|
39819
|
-
if (cached !== void 0) return cached;
|
|
39820
|
-
let wrapped;
|
|
39821
|
-
wrapped = new Proxy(callable, {
|
|
39822
|
-
apply(currentTarget, thisArg, args) {
|
|
39823
|
-
const invocation = resolveInvocationSnapshot(adapter, snapshot);
|
|
39824
|
-
let output;
|
|
39825
|
-
try {
|
|
39826
|
-
output = Reflect.apply(currentTarget, unwrapReceiver(thisArg), args);
|
|
39827
|
-
} catch (cause) {
|
|
39828
|
-
report(adapter, "exception", operation, cause, invocation);
|
|
39829
|
-
throw cause;
|
|
39830
|
-
}
|
|
39831
|
-
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path, invocation), (cause) => {
|
|
39832
|
-
report(adapter, "exception", operation, cause, invocation);
|
|
39833
|
-
throw cause;
|
|
39834
|
-
});
|
|
39835
|
-
return processOutput(output, path, invocation);
|
|
39836
|
-
},
|
|
39837
|
-
get(currentTarget, property) {
|
|
39838
|
-
if (property === "bind") return Function.prototype.bind.bind(wrapped);
|
|
39839
|
-
if (property === "call") return Function.prototype.call.bind(wrapped);
|
|
39840
|
-
if (property === "apply") return Function.prototype.apply.bind(wrapped);
|
|
39841
|
-
const attached = Reflect.get(currentTarget, property, currentTarget);
|
|
39842
|
-
if (typeof property !== "string") return attached;
|
|
39843
|
-
return wrapValue(attached, [...path, property], currentTarget);
|
|
39844
|
-
}
|
|
39845
|
-
});
|
|
39846
|
-
proxyTargets.set(wrapped, callable);
|
|
39847
|
-
ownerWrappers.set(operation, wrapped);
|
|
39848
|
-
return wrapped;
|
|
39849
|
-
}
|
|
39850
|
-
return isPlainObject(value) ? wrapObject(value, path) : value;
|
|
39851
|
-
};
|
|
39852
|
-
const processOutput = (output, path, invocation) => {
|
|
39853
|
-
if (isFailedResult(output)) {
|
|
39854
|
-
report(adapter, "operation", path.join("."), output.error, invocation);
|
|
39855
|
-
return output;
|
|
39856
|
-
}
|
|
39857
|
-
if (isCapxulResult(output)) return output;
|
|
39858
|
-
return isPlainObject(output) ? wrapObject(output, path) : output;
|
|
39859
|
-
};
|
|
39860
|
-
return wrapObject(client, []);
|
|
39861
|
-
function unwrapReceiver(receiver) {
|
|
39862
|
-
return (typeof receiver === "object" || typeof receiver === "function") && receiver !== null ? proxyTargets.get(receiver) ?? receiver : receiver;
|
|
39863
|
-
}
|
|
39864
|
-
}
|
|
39865
|
-
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
39866
|
-
function observeFailedResult(result, adapter, operation, origin) {
|
|
39867
|
-
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterSnapshot(adapter), origin);
|
|
39868
|
-
return result;
|
|
39869
|
-
}
|
|
39870
|
-
/**
|
|
39871
|
-
* One failure, one event. The identity machine reports a failed transition
|
|
39872
|
-
* first; when the same `CapxulError` then surfaces as a public method result
|
|
39873
|
-
* (directly or down its `cause` chain), the boundary drops that second report.
|
|
39874
|
-
* Only machine-reported errors are remembered, so a caller that reuses one
|
|
39875
|
-
* error object across unrelated public methods still sees every report.
|
|
39876
|
-
*/
|
|
39877
|
-
const machineReportedCauses = /* @__PURE__ */ new WeakSet();
|
|
39878
|
-
function reportedByMachine(cause) {
|
|
39879
|
-
let link = cause;
|
|
39880
|
-
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
39881
|
-
if (machineReportedCauses.has(link)) return true;
|
|
39882
|
-
link = link.cause;
|
|
39883
|
-
}
|
|
39884
|
-
return false;
|
|
39885
|
-
}
|
|
39886
|
-
function report(adapter, kind, operation, cause, invocation, origin) {
|
|
39887
|
-
if (origin === "machine") {
|
|
39888
|
-
let link = cause;
|
|
39889
|
-
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
39890
|
-
machineReportedCauses.add(link);
|
|
39891
|
-
link = link.cause;
|
|
39892
|
-
}
|
|
39893
|
-
} else if (reportedByMachine(cause)) return;
|
|
39894
|
-
const operationName = normalizeOperation(operation);
|
|
39895
|
-
const kindName = normalizeErrorKind(errorKind(cause));
|
|
39896
|
-
const context = sanitizeObservationContext({
|
|
39897
|
-
...invocation.context,
|
|
39898
|
-
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
39899
|
-
});
|
|
39900
|
-
const detail = failureDetail(cause);
|
|
39901
|
-
const evidence = failureEvidence(cause);
|
|
39902
|
-
const failure = markFailureInvocationSnapshot({
|
|
39903
|
-
exception: syntheticException(operationName, kindName, evidence.message, evidence.stack),
|
|
39904
|
-
sdkVersion: SDK_VERSION$1,
|
|
39905
|
-
operation: operationName,
|
|
39906
|
-
errorKind: kindName,
|
|
39907
|
-
...context === void 0 ? {} : { context },
|
|
39908
|
-
...detail === void 0 ? {} : { detail },
|
|
39909
|
-
...evidence
|
|
39910
|
-
}, {
|
|
39911
|
-
active: invocation.active,
|
|
39912
|
-
...context === void 0 ? {} : { context }
|
|
39913
|
-
});
|
|
39914
|
-
try {
|
|
39915
|
-
ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
|
|
39916
|
-
} catch {}
|
|
39917
|
-
}
|
|
39918
|
-
function resolveInvocationSnapshot(adapter, snapshot) {
|
|
39919
|
-
if (snapshot !== void 0) try {
|
|
39920
|
-
const captured = snapshot();
|
|
39921
|
-
if (captured !== void 0) return captured;
|
|
39922
|
-
} catch {}
|
|
39923
|
-
return resolveAdapterSnapshot(adapter);
|
|
39924
|
-
}
|
|
39925
|
-
function resolveAdapterSnapshot(adapter) {
|
|
39926
|
-
const context = resolveAdapterContext(adapter);
|
|
39927
|
-
return context === void 0 ? { active: false } : {
|
|
39928
|
-
active: true,
|
|
39929
|
-
context
|
|
39930
|
-
};
|
|
39931
|
-
}
|
|
39932
|
-
function resolveAdapterContext(adapter) {
|
|
39933
|
-
try {
|
|
39934
|
-
return adapter.resolveContext?.();
|
|
39935
|
-
} catch {
|
|
39936
|
-
return;
|
|
39937
|
-
}
|
|
39938
|
-
}
|
|
39939
|
-
function ignoreDeliveryFailure(delivery) {
|
|
39940
|
-
if (!isPromiseLike(delivery)) return;
|
|
39941
|
-
try {
|
|
39942
|
-
Promise.resolve(delivery).catch(() => void 0);
|
|
39943
|
-
} catch {}
|
|
39944
|
-
}
|
|
39945
|
-
const MAX_EVIDENCE_TEXT = 4e3;
|
|
39946
|
-
const MAX_CAUSE_DEPTH = 8;
|
|
39947
|
-
function evidenceText(value) {
|
|
39948
|
-
if (typeof value !== "string" || value.length === 0) return void 0;
|
|
39949
|
-
return redactSecrets(value).slice(0, MAX_EVIDENCE_TEXT);
|
|
39950
|
-
}
|
|
39951
|
-
/** A field whose NAME says credential is masked whatever its value looks like. */
|
|
39952
|
-
const CREDENTIAL_FIELD_NAME = /(?:otp|pass(?:word|wd|phrase)?|token|secret|credential|api[_-]?key|private[_-]?key|authorization|cookie|session)/iu;
|
|
39953
|
-
/** Copy a details object into a JSON-safe shape with every string masked. */
|
|
39954
|
-
function evidenceValue(value, depth = 0) {
|
|
39955
|
-
if (typeof value === "string") return evidenceText(value);
|
|
39956
|
-
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
39957
|
-
if (typeof value === "bigint") return value.toString();
|
|
39958
|
-
if (value instanceof Error) return evidenceText(value.message);
|
|
39959
|
-
if (depth >= 4 || typeof value !== "object") return void 0;
|
|
39960
|
-
if (Array.isArray(value)) return value.slice(0, 50).map((item) => evidenceValue(item, depth + 1));
|
|
39961
|
-
const copy = {};
|
|
39962
|
-
for (const [key, nested] of Object.entries(value)) {
|
|
39963
|
-
if (CREDENTIAL_FIELD_NAME.test(key)) {
|
|
39964
|
-
copy[key] = "[REDACTED]";
|
|
39965
|
-
continue;
|
|
39966
|
-
}
|
|
39967
|
-
const safe = evidenceValue(nested, depth + 1);
|
|
39968
|
-
if (safe !== void 0) copy[key] = safe;
|
|
39969
|
-
}
|
|
39970
|
-
return copy;
|
|
39971
|
-
}
|
|
39972
|
-
/**
|
|
39973
|
-
* @internal The evidence in PostHog property shape, for product events that
|
|
39974
|
-
* name a failure (`bootstrap_failed`). Same keys as the `$exception` event.
|
|
39975
|
-
*/
|
|
39976
|
-
function failureEvidenceProps(cause) {
|
|
39977
|
-
const evidence = failureEvidence(cause);
|
|
39978
|
-
return {
|
|
39979
|
-
...evidence.message === void 0 ? {} : { error_message: evidence.message },
|
|
39980
|
-
...evidence.details === void 0 ? {} : { error_details: evidence.details },
|
|
39981
|
-
...evidence.causeChain === void 0 ? {} : { error_cause: evidence.causeChain.join(" <- ") }
|
|
39982
|
-
};
|
|
39983
|
-
}
|
|
39984
|
-
/** The real failure, masked for secrets only. Never throws. */
|
|
39985
|
-
function failureEvidence(cause) {
|
|
39986
|
-
try {
|
|
39987
|
-
const message = cause instanceof Error ? evidenceText(cause.message) : evidenceText(cause);
|
|
39988
|
-
const stack = cause instanceof Error ? evidenceText(cause.stack) : void 0;
|
|
39989
|
-
const details = isCapxulError(cause) && typeof cause.details === "object" && cause.details !== null ? evidenceValue(cause.details) : void 0;
|
|
39990
|
-
const causeChain = [];
|
|
39991
|
-
let previous = message;
|
|
39992
|
-
let link = cause instanceof Error ? cause.cause : void 0;
|
|
39993
|
-
for (let depth = 0; depth < MAX_CAUSE_DEPTH && link !== void 0 && link !== null; depth++) {
|
|
39994
|
-
const text = link instanceof Error ? evidenceText(link.message) : evidenceText(link);
|
|
39995
|
-
if (text !== void 0 && text !== previous) {
|
|
39996
|
-
causeChain.push(text);
|
|
39997
|
-
previous = text;
|
|
39998
|
-
}
|
|
39999
|
-
link = link instanceof Error ? link.cause : void 0;
|
|
40000
|
-
}
|
|
40001
|
-
return {
|
|
40002
|
-
...message === void 0 ? {} : { message },
|
|
40003
|
-
...details === void 0 || Object.keys(details).length === 0 ? {} : { details },
|
|
40004
|
-
...causeChain.length === 0 ? {} : { causeChain },
|
|
40005
|
-
...stack === void 0 ? {} : { stack }
|
|
40006
|
-
};
|
|
40007
|
-
} catch {
|
|
40008
|
-
return {};
|
|
40009
|
-
}
|
|
40010
|
-
}
|
|
40011
|
-
function errorKind(cause) {
|
|
40012
|
-
try {
|
|
40013
|
-
if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
|
|
40014
|
-
if (cause instanceof Error) return normalizeErrorKind(cause.name);
|
|
40015
|
-
return "UnknownFailure";
|
|
40016
|
-
} catch {
|
|
40017
|
-
return "Error";
|
|
40018
|
-
}
|
|
40019
|
-
}
|
|
40020
|
-
/**
|
|
40021
|
-
* @internal Lift the enumerated discriminators off a `CapxulError` so a
|
|
40022
|
-
* boundary event says WHICH provider failed and HOW, not just `PROVIDER_ERROR`.
|
|
40023
|
-
* Shared by the failure boundary and the `bootstrap_failed` product event.
|
|
40024
|
-
*/
|
|
40025
|
-
function failureDetail(cause) {
|
|
40026
|
-
if (!isCapxulError(cause)) return void 0;
|
|
40027
|
-
const details = cause.details;
|
|
40028
|
-
if (typeof details !== "object" || details === null) return void 0;
|
|
40029
|
-
const source = details;
|
|
40030
|
-
return sanitizeFailureDetail({
|
|
40031
|
-
provider: source.provider,
|
|
40032
|
-
provider_operation: source.operation,
|
|
40033
|
-
failure_mode: source.failure_mode,
|
|
40034
|
-
reason: source.reason,
|
|
40035
|
-
http_status: source.httpStatus
|
|
40036
|
-
});
|
|
40037
|
-
}
|
|
40038
|
-
function sanitizeFailureDetail(input) {
|
|
40039
|
-
if (typeof input !== "object" || input === null) return void 0;
|
|
40040
|
-
const source = input;
|
|
40041
|
-
const detail = {};
|
|
40042
|
-
for (const key of [
|
|
40043
|
-
"provider",
|
|
40044
|
-
"provider_operation",
|
|
40045
|
-
"failure_mode",
|
|
40046
|
-
"reason"
|
|
40047
|
-
]) {
|
|
40048
|
-
const value = source[key];
|
|
40049
|
-
if (typeof value === "string" && ENUMERATED_DETAIL_RE.test(value)) detail[key] = value;
|
|
40050
|
-
}
|
|
40051
|
-
const status = source.http_status;
|
|
40052
|
-
if (typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599) detail.http_status = status;
|
|
40053
|
-
return Object.keys(detail).length === 0 ? void 0 : detail;
|
|
40054
|
-
}
|
|
40055
|
-
/** Enumerated codes only (`convex`, `no-secure-context`, `bootstrap-encode`); free text fails. */
|
|
40056
|
-
const ENUMERATED_DETAIL_RE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u;
|
|
40057
|
-
function normalizeOperation(value) {
|
|
40058
|
-
return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
|
|
40059
|
-
}
|
|
40060
|
-
function normalizeErrorKind(value) {
|
|
40061
|
-
return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
|
|
40062
|
-
}
|
|
40063
|
-
function syntheticException(operation, kind, message = EXCEPTION_MESSAGE, stack) {
|
|
40064
|
-
const error = new Error(message);
|
|
40065
|
-
error.name = kind;
|
|
40066
|
-
error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)` + (stack === void 0 ? "" : `\nCaused by: ${stack}`);
|
|
40067
|
-
return error;
|
|
40068
|
-
}
|
|
40069
|
-
function isPromiseLike(value) {
|
|
40070
|
-
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
40071
|
-
}
|
|
40072
|
-
function isPlainObject(value) {
|
|
40073
|
-
if (typeof value !== "object" || value === null) return false;
|
|
40074
|
-
const prototype = Object.getPrototypeOf(value);
|
|
40075
|
-
return prototype === Object.prototype || prototype === null;
|
|
40076
|
-
}
|
|
40077
|
-
function isCapxulResult(value) {
|
|
40078
|
-
return isPlainObject(value) && typeof value.ok === "boolean";
|
|
40079
|
-
}
|
|
40080
|
-
function isFailedResult(value) {
|
|
40081
|
-
return isCapxulResult(value) && value.ok === false && "error" in value;
|
|
40082
|
-
}
|
|
40083
|
-
//#endregion
|
|
40084
41077
|
//#region ../../packages/sdk/src/telemetry/from-posthog.ts
|
|
40085
41078
|
const PRODUCT_INVOCATION = Symbol("capxul.product-telemetry-invocation");
|
|
40086
41079
|
/** @internal Bind paired emit/identify/reset work to one call-start snapshot. */
|
|
@@ -40130,23 +41123,24 @@ const linkage = (record) => ({
|
|
|
40130
41123
|
...record.journey_id === void 0 ? {} : { journey_id: record.journey_id }
|
|
40131
41124
|
});
|
|
40132
41125
|
const emailDomain = (email) => email.split("@")[1]?.toLowerCase() ?? "unknown";
|
|
40133
|
-
const authFailure = (record, reason) => ({
|
|
41126
|
+
const authFailure = (record, reason, mode) => ({
|
|
40134
41127
|
name: "auth_failed",
|
|
40135
41128
|
props: {
|
|
40136
41129
|
auth_type: "otp",
|
|
40137
41130
|
reason,
|
|
41131
|
+
...mode === void 0 ? {} : { failure_mode: mode },
|
|
40138
41132
|
...linkage(record)
|
|
40139
41133
|
}
|
|
40140
41134
|
});
|
|
40141
41135
|
function mapIdentityProductObservation(record, state) {
|
|
40142
41136
|
if (record.machine !== "identity" || !IDENTITY_EVENT_TAG_SET.has(record.event)) return NONE;
|
|
40143
41137
|
if (record.outcome === "cancelled") return NONE;
|
|
40144
|
-
if (record.slot === "identity:auth" && record.outcome === "refused") return authFailure(record, record.refusal_code);
|
|
40145
|
-
if (record.slot === "identity:auth" && record.outcome === "failed") return authFailure(record, record.error_code);
|
|
41138
|
+
if (record.slot === "identity:auth" && record.outcome === "refused") return authFailure(record, record.refusal_code, void 0);
|
|
41139
|
+
if (record.slot === "identity:auth" && record.outcome === "failed") return authFailure(record, record.error_code, record.failure?.mode);
|
|
40146
41140
|
if (record.outcome !== "applied") return NONE;
|
|
40147
41141
|
switch (APPLIED_ACTION_BY_EVENT[record.event]) {
|
|
40148
41142
|
case "none": return NONE;
|
|
40149
|
-
case "failed": return state.phase !== "faulted" || state.failure.code === "CANCELLED" ? NONE : authFailure(record, state.failure.code);
|
|
41143
|
+
case "failed": return state.phase !== "faulted" || state.failure.code === "CANCELLED" ? NONE : authFailure(record, state.failure.code, state.failure.mode);
|
|
40150
41144
|
case "otp-requested": return state.phase !== "otp_pending" ? NONE : {
|
|
40151
41145
|
name: "auth_otp_requested",
|
|
40152
41146
|
props: {
|
|
@@ -40251,7 +41245,8 @@ function assembleCapxulClient(input) {
|
|
|
40251
41245
|
requirement: input.requirement,
|
|
40252
41246
|
...input.signer === void 0 ? {} : { signer: input.signer },
|
|
40253
41247
|
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup },
|
|
40254
|
-
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs }
|
|
41248
|
+
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
|
41249
|
+
...input.ports.telemetry === void 0 ? {} : { telemetry: input.ports.telemetry }
|
|
40255
41250
|
}), scope)), observation.hostObservationSnapshot);
|
|
40256
41251
|
const unsubscribeProductTelemetry = actor.subscribeTransitions((record) => {
|
|
40257
41252
|
effectRunner.runPromise(executeIdentityProductObservation(input.ports.telemetry, record, actor.snapshot())).catch(() => {});
|
|
@@ -43331,6 +44326,658 @@ function optionalEnv(name) {
|
|
|
43331
44326
|
const value = process.env[name];
|
|
43332
44327
|
return value && value.length > 0 ? value : void 0;
|
|
43333
44328
|
}
|
|
44329
|
+
/** Return true only when an absolute URL names the local loopback host. */
|
|
44330
|
+
function isLoopbackOrigin(url) {
|
|
44331
|
+
try {
|
|
44332
|
+
const { hostname } = new URL(url);
|
|
44333
|
+
return hostname === "127.0.0.1" || hostname === "localhost" || hostname === "[::1]";
|
|
44334
|
+
} catch {
|
|
44335
|
+
return false;
|
|
44336
|
+
}
|
|
44337
|
+
}
|
|
44338
|
+
function isHermeticTestRun() {
|
|
44339
|
+
return optionalEnv("VITEST") !== void 0;
|
|
44340
|
+
}
|
|
44341
|
+
v$1.object({
|
|
44342
|
+
application: v$1.optional(v$1.string()),
|
|
44343
|
+
applicationId: v$1.optional(v$1.string()),
|
|
44344
|
+
release: v$1.optional(v$1.string()),
|
|
44345
|
+
sessionId: v$1.optional(v$1.string()),
|
|
44346
|
+
organizationId: v$1.optional(v$1.string()),
|
|
44347
|
+
journeyId: v$1.optional(v$1.string()),
|
|
44348
|
+
correlationId: v$1.optional(v$1.string()),
|
|
44349
|
+
anonymousId: v$1.optional(v$1.string()),
|
|
44350
|
+
traceparent: v$1.optional(v$1.string())
|
|
44351
|
+
});
|
|
44352
|
+
v$1.optional(v$1.string()), v$1.optional(v$1.string());
|
|
44353
|
+
function systemAttribution(systemJob) {
|
|
44354
|
+
return {
|
|
44355
|
+
kind: "system",
|
|
44356
|
+
systemJob
|
|
44357
|
+
};
|
|
44358
|
+
}
|
|
44359
|
+
function attributionProperties(attribution) {
|
|
44360
|
+
const observation = "observation" in attribution ? attribution.observation : void 0;
|
|
44361
|
+
const properties = {
|
|
44362
|
+
actor_kind: attribution.kind,
|
|
44363
|
+
actor_id: distinctId(attribution),
|
|
44364
|
+
distinct_id: distinctId(attribution)
|
|
44365
|
+
};
|
|
44366
|
+
if (attribution.kind === "system") properties.system_job = attribution.systemJob;
|
|
44367
|
+
if (observation?.application !== void 0) properties.application = observation.application;
|
|
44368
|
+
if (observation?.verifiedApplicationId !== void 0) properties.application_id = observation.verifiedApplicationId;
|
|
44369
|
+
if (observation?.release !== void 0) properties.release = observation.release;
|
|
44370
|
+
if (observation?.sessionId !== void 0) properties.session_id = observation.sessionId;
|
|
44371
|
+
if (observation?.journeyId !== void 0) properties.journey_id = observation.journeyId;
|
|
44372
|
+
if (observation?.correlationId !== void 0) properties.correlation_id = observation.correlationId;
|
|
44373
|
+
if (observation?.anonymousId !== void 0) properties.anonymous_id = observation.anonymousId;
|
|
44374
|
+
if (observation?.verifiedOrganizationId !== void 0) {
|
|
44375
|
+
properties.organization_id = observation.verifiedOrganizationId;
|
|
44376
|
+
properties.$groups = { organization: observation.verifiedOrganizationId };
|
|
44377
|
+
}
|
|
44378
|
+
return properties;
|
|
44379
|
+
}
|
|
44380
|
+
/** Closed projection for person-linked telemetry; raw failure text never leaves the boundary. */
|
|
44381
|
+
function observationErrorKind(error) {
|
|
44382
|
+
if (isCapxulError(error)) return error.code;
|
|
44383
|
+
if (error instanceof Error) return "Error";
|
|
44384
|
+
return "UnknownFailure";
|
|
44385
|
+
}
|
|
44386
|
+
function distinctId(attribution) {
|
|
44387
|
+
if (attribution.kind === "authenticated") return attribution.authUserId;
|
|
44388
|
+
if (attribution.kind === "anonymous") return attribution.anonymousId;
|
|
44389
|
+
return `system:${attribution.systemJob}`;
|
|
44390
|
+
}
|
|
44391
|
+
//#endregion
|
|
44392
|
+
//#region ../../packages/backend/convex/_shared/posthog.ts
|
|
44393
|
+
const DEFAULT_POSTHOG_HOST = "https://app.posthog.com";
|
|
44394
|
+
/**
|
|
44395
|
+
* Which environment a Convex deployment IS (ADR-0020 A1 amendment). One
|
|
44396
|
+
* PostHog project holds every environment, so this map is what keeps a
|
|
44397
|
+
* production surface from reading dev traffic — it is the mechanical
|
|
44398
|
+
* substitute for project isolation on the server half.
|
|
44399
|
+
*
|
|
44400
|
+
* Derived from the deployment's own `CONVEX_CLOUD_URL` rather than a
|
|
44401
|
+
* deployment env var on purpose. Kept byte-
|
|
44402
|
+
* equal to `config/deployment-topology.json` by
|
|
44403
|
+
* `scripts/__tests__/deployment-topology.test.mjs`; production joins both
|
|
44404
|
+
* files together when it exists.
|
|
44405
|
+
*/
|
|
44406
|
+
const CLOUD_URL_CAPXUL_ENVS = {
|
|
44407
|
+
"https://incredible-possum-990.convex.cloud": "development",
|
|
44408
|
+
"https://convex-backend-production-f220.up.railway.app": "staging"
|
|
44409
|
+
};
|
|
44410
|
+
/**
|
|
44411
|
+
* `unknown` is deliberate, not a fallback to hide behind: an undeclared
|
|
44412
|
+
* deployment gets a LOUD value that every synced artifact filters out, rather
|
|
44413
|
+
* than an absent property that silently passes every filter.
|
|
44414
|
+
*/
|
|
44415
|
+
function resolveCapxulEnvFromCloudUrl(cloudUrl) {
|
|
44416
|
+
if (cloudUrl === void 0 || cloudUrl.length === 0) return "unknown";
|
|
44417
|
+
if (isLoopbackOrigin(cloudUrl)) return "local";
|
|
44418
|
+
try {
|
|
44419
|
+
return CLOUD_URL_CAPXUL_ENVS[new URL(cloudUrl).origin] ?? "unknown";
|
|
44420
|
+
} catch {
|
|
44421
|
+
return "unknown";
|
|
44422
|
+
}
|
|
44423
|
+
}
|
|
44424
|
+
function resolveCapxulEnv() {
|
|
44425
|
+
return resolveCapxulEnvFromCloudUrl(optionalEnv("CONVEX_CLOUD_URL"));
|
|
44426
|
+
}
|
|
44427
|
+
const POSTHOG_PROJECT_TOKEN_ENV_KEYS = [
|
|
44428
|
+
"POSTHOG_PROJECT_TOKEN",
|
|
44429
|
+
"POSTHOG_PROECT_TOKEN",
|
|
44430
|
+
"POSTHOG_INGEST_KEY"
|
|
44431
|
+
];
|
|
44432
|
+
async function postPostHogEvent(event, properties, options) {
|
|
44433
|
+
const deploymentEnv = resolveCapxulEnv();
|
|
44434
|
+
const stamped = {
|
|
44435
|
+
capxul_env: deploymentEnv,
|
|
44436
|
+
...properties
|
|
44437
|
+
};
|
|
44438
|
+
if (deploymentEnv === "local" || stamped.capxul_env === "local") return;
|
|
44439
|
+
const apiKey = requirePostHogProjectToken();
|
|
44440
|
+
const response = await fetchWithTimeout(`${normalizePostHogHost(optionalEnv("POSTHOG_HOST") ?? DEFAULT_POSTHOG_HOST)}/capture/`, {
|
|
44441
|
+
body: JSON.stringify({
|
|
44442
|
+
api_key: apiKey,
|
|
44443
|
+
event,
|
|
44444
|
+
properties: stamped
|
|
44445
|
+
}),
|
|
44446
|
+
headers: { "content-type": "application/json" },
|
|
44447
|
+
method: "POST"
|
|
44448
|
+
}, options?.timeoutMs).catch(rethrowPostHogCapture);
|
|
44449
|
+
if (!response.ok) throw Errors.providerError("posthog", "capture", /* @__PURE__ */ new Error(`PostHog capture failed with HTTP ${response.status}`));
|
|
44450
|
+
}
|
|
44451
|
+
async function fetchWithTimeout(url, init, timeoutMs) {
|
|
44452
|
+
if (timeoutMs === void 0) return fetch(url, init);
|
|
44453
|
+
const controller = new AbortController();
|
|
44454
|
+
let timeout;
|
|
44455
|
+
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
44456
|
+
timeout = setTimeout(() => {
|
|
44457
|
+
controller.abort();
|
|
44458
|
+
reject(/* @__PURE__ */ new Error(`PostHog capture timed out after ${timeoutMs}ms`));
|
|
44459
|
+
}, timeoutMs);
|
|
44460
|
+
});
|
|
44461
|
+
try {
|
|
44462
|
+
return await Promise.race([fetch(url, {
|
|
44463
|
+
...init,
|
|
44464
|
+
signal: controller.signal
|
|
44465
|
+
}), timeoutPromise]);
|
|
44466
|
+
} finally {
|
|
44467
|
+
if (timeout !== void 0) clearTimeout(timeout);
|
|
44468
|
+
}
|
|
44469
|
+
}
|
|
44470
|
+
function requirePostHogProjectToken() {
|
|
44471
|
+
for (const name of POSTHOG_PROJECT_TOKEN_ENV_KEYS) {
|
|
44472
|
+
const value = optionalEnv(name);
|
|
44473
|
+
if (value !== void 0) return value;
|
|
44474
|
+
}
|
|
44475
|
+
return requireEnvOrThrow("POSTHOG_PROJECT_TOKEN");
|
|
44476
|
+
}
|
|
44477
|
+
function normalizePostHogHost(host) {
|
|
44478
|
+
return host.replace(/\/+$/, "");
|
|
44479
|
+
}
|
|
44480
|
+
function rethrowPostHogCapture(error) {
|
|
44481
|
+
throw Errors.providerError("posthog", "capture", error);
|
|
44482
|
+
}
|
|
44483
|
+
//#endregion
|
|
44484
|
+
//#region ../../packages/backend/convex/_shared/init.ts
|
|
44485
|
+
var init_exports = /* @__PURE__ */ __exportAll({
|
|
44486
|
+
CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT: () => CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT,
|
|
44487
|
+
captureBackendDiagnostic: () => captureBackendDiagnostic,
|
|
44488
|
+
captureBrowserSdkFailure: () => captureBrowserSdkFailure,
|
|
44489
|
+
reportError: () => reportError,
|
|
44490
|
+
setReporter: () => setReporter
|
|
44491
|
+
});
|
|
44492
|
+
const POSTHOG_ERROR_TIMEOUT_MS = 5e3;
|
|
44493
|
+
let activeReporter = { captureException: captureBoundaryException };
|
|
44494
|
+
function setReporter(reporter) {
|
|
44495
|
+
const previous = activeReporter;
|
|
44496
|
+
activeReporter = reporter;
|
|
44497
|
+
return previous;
|
|
44498
|
+
}
|
|
44499
|
+
async function reportError(error, context) {
|
|
44500
|
+
try {
|
|
44501
|
+
await activeReporter.captureException(error, context);
|
|
44502
|
+
} catch {
|
|
44503
|
+
captureLocalException(error, context, "local_sanitized_fallback");
|
|
44504
|
+
}
|
|
44505
|
+
}
|
|
44506
|
+
/**
|
|
44507
|
+
* SERVER-side failures — the 5b lane (ADR-0020 §6 boundary, Part B).
|
|
44508
|
+
*
|
|
44509
|
+
* This used to post `capxul_backend_expected_outcome` and a synthetic
|
|
44510
|
+
* `$exception` into PostHog. Both are ENGINEERING diagnostics, not user
|
|
44511
|
+
* behavior: they answered no drop-off question and drowned the product error
|
|
44512
|
+
* tracker (400 `$exception`/30d, top type `NOT_IMPLEMENTED`). They now leave
|
|
44513
|
+
* PostHog entirely and exit as one wide, structured line per failure, which
|
|
44514
|
+
* Convex log streams carry to the OTLP sink (ADR-0020 B1/B2).
|
|
44515
|
+
*
|
|
44516
|
+
* `correlation_id` is deliberately on the line: it is THE shared key between a
|
|
44517
|
+
* 5a funnel drop and the 5b trace that explains it.
|
|
44518
|
+
*
|
|
44519
|
+
* Browser-origin failures are NOT affected — `captureBrowserSdkFailure` below
|
|
44520
|
+
* keeps sending `$exception`, because "what breaks in a real user's browser"
|
|
44521
|
+
* IS a product question and stays in PostHog.
|
|
44522
|
+
*/
|
|
44523
|
+
async function captureBackendDiagnostic(error, context) {
|
|
44524
|
+
const errorKind = observationErrorKind(error);
|
|
44525
|
+
const attribution = readAttribution(context?.attribution);
|
|
44526
|
+
const expected = isCapxulError(error) && EXPECTED_OPERATION_OUTCOMES.has(error.code);
|
|
44527
|
+
const properties = attributionProperties(attribution);
|
|
44528
|
+
const operation = normalizeOperation(context?.operation);
|
|
44529
|
+
emitBackendWideEvent({
|
|
44530
|
+
op: operation,
|
|
44531
|
+
outcome: expected ? "expected" : "unexpected",
|
|
44532
|
+
error_kind: errorKind,
|
|
44533
|
+
actor_kind: properties.actor_kind,
|
|
44534
|
+
actor_id: properties.actor_id,
|
|
44535
|
+
correlation_id: properties.correlation_id,
|
|
44536
|
+
journey_id: properties.journey_id,
|
|
44537
|
+
organization_id: properties.organization_id,
|
|
44538
|
+
handled: true,
|
|
44539
|
+
producer: "server"
|
|
44540
|
+
});
|
|
44541
|
+
if (isHermeticTestRun()) return;
|
|
44542
|
+
try {
|
|
44543
|
+
await (expected ? postServerExpectedOutcome(error, errorKind, operation, properties, context) : postServerException(error, errorKind, operation, properties, context));
|
|
44544
|
+
} catch {
|
|
44545
|
+
captureLocalException(error, context, "local_sanitized_fallback");
|
|
44546
|
+
}
|
|
44547
|
+
}
|
|
44548
|
+
/** The `$exception` twin for an expected product outcome: same evidence, its own stream. */
|
|
44549
|
+
const CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT = "capxul_backend_expected_outcome";
|
|
44550
|
+
async function postServerExpectedOutcome(error, errorKind, operation, properties, context) {
|
|
44551
|
+
const { attribution: _attribution, delivery: _delivery, operation: _op, ...rest } = context ?? {};
|
|
44552
|
+
await postPostHogEvent(CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT, {
|
|
44553
|
+
...properties,
|
|
44554
|
+
operation,
|
|
44555
|
+
error_kind: errorKind,
|
|
44556
|
+
...errorEvidence(error),
|
|
44557
|
+
...safeEvidence(rest),
|
|
44558
|
+
handled: true,
|
|
44559
|
+
producer: "server"
|
|
44560
|
+
}, { timeoutMs: POSTHOG_ERROR_TIMEOUT_MS });
|
|
44561
|
+
}
|
|
44562
|
+
/**
|
|
44563
|
+
* Total, cycle-safe copy of arbitrary evidence: strings masked, bigints
|
|
44564
|
+
* stringified, cycles and depth cut. `JSON.stringify` would throw on a bigint
|
|
44565
|
+
* or a cycle and drop the whole `$exception` with it.
|
|
44566
|
+
*/
|
|
44567
|
+
/** A field whose NAME says credential is masked whatever its value looks like. */
|
|
44568
|
+
const CREDENTIAL_FIELD_NAME = /(?:otp|pass(?:word|wd|phrase)?|token|secret|credential|api[_-]?key|private[_-]?key|authorization|cookie|session)/iu;
|
|
44569
|
+
/** Every string of evidence is bounded: a provider body cannot inflate a log record or an exception. */
|
|
44570
|
+
const EVIDENCE_STRING_MAX = 2e3;
|
|
44571
|
+
/** Objects and arrays keep their first entries only; the sanitizer stays total on any shape. */
|
|
44572
|
+
const EVIDENCE_ENTRY_MAX = 50;
|
|
44573
|
+
/** Property names are bounded too: fifty huge keys are still a huge record. */
|
|
44574
|
+
const EVIDENCE_KEY_MAX = 64;
|
|
44575
|
+
const UNPRINTABLE = "[unprintable]";
|
|
44576
|
+
function clipEvidence(text) {
|
|
44577
|
+
return text.length <= EVIDENCE_STRING_MAX ? text : `${text.slice(0, EVIDENCE_STRING_MAX)}…(${String(text.length)} chars)`;
|
|
44578
|
+
}
|
|
44579
|
+
/**
|
|
44580
|
+
* Total text of any value: a hostile `toString`, a throwing `message` getter,
|
|
44581
|
+
* or a Proxy yields the fixed marker instead of an exception, because this
|
|
44582
|
+
* runs inside the fallback path that must never replace the domain error.
|
|
44583
|
+
*/
|
|
44584
|
+
function safeText(value) {
|
|
44585
|
+
let text;
|
|
44586
|
+
try {
|
|
44587
|
+
text = value instanceof Error ? String(value.message) : String(value);
|
|
44588
|
+
} catch {
|
|
44589
|
+
text = UNPRINTABLE;
|
|
44590
|
+
}
|
|
44591
|
+
try {
|
|
44592
|
+
return clipEvidence(redactSecrets(text));
|
|
44593
|
+
} catch {
|
|
44594
|
+
return UNPRINTABLE;
|
|
44595
|
+
}
|
|
44596
|
+
}
|
|
44597
|
+
function safeEvidence(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
44598
|
+
if (typeof value === "string") return safeText(value);
|
|
44599
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
44600
|
+
if (typeof value === "bigint") return value.toString();
|
|
44601
|
+
if (value instanceof Error) return safeText(value);
|
|
44602
|
+
if (depth >= 4 || typeof value !== "object" || seen.has(value)) return void 0;
|
|
44603
|
+
seen.add(value);
|
|
44604
|
+
if (Array.isArray(value)) return value.slice(0, EVIDENCE_ENTRY_MAX).map((item) => safeEvidence(item, depth + 1, seen));
|
|
44605
|
+
let keys;
|
|
44606
|
+
try {
|
|
44607
|
+
keys = Object.keys(value).slice(0, EVIDENCE_ENTRY_MAX);
|
|
44608
|
+
} catch {
|
|
44609
|
+
return UNPRINTABLE;
|
|
44610
|
+
}
|
|
44611
|
+
const copy = {};
|
|
44612
|
+
for (const key of keys) {
|
|
44613
|
+
const name = key.length <= EVIDENCE_KEY_MAX ? key : `${key.slice(0, EVIDENCE_KEY_MAX)}…`;
|
|
44614
|
+
if (CREDENTIAL_FIELD_NAME.test(key)) {
|
|
44615
|
+
copy[name] = "[REDACTED]";
|
|
44616
|
+
continue;
|
|
44617
|
+
}
|
|
44618
|
+
let nested;
|
|
44619
|
+
try {
|
|
44620
|
+
nested = value[key];
|
|
44621
|
+
} catch {
|
|
44622
|
+
copy[name] = UNPRINTABLE;
|
|
44623
|
+
continue;
|
|
44624
|
+
}
|
|
44625
|
+
const safe = safeEvidence(nested, depth + 1, seen);
|
|
44626
|
+
if (safe !== void 0) copy[name] = safe;
|
|
44627
|
+
}
|
|
44628
|
+
return copy;
|
|
44629
|
+
}
|
|
44630
|
+
/** A stack is longer than a message by nature; it still ends before it can inflate a payload. */
|
|
44631
|
+
const EVIDENCE_STACK_MAX = 4e3;
|
|
44632
|
+
function safeStack(error) {
|
|
44633
|
+
try {
|
|
44634
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
44635
|
+
if (typeof stack !== "string" || stack.length === 0) return void 0;
|
|
44636
|
+
const text = redactSecrets(stack);
|
|
44637
|
+
return text.length <= EVIDENCE_STACK_MAX ? text : `${text.slice(0, EVIDENCE_STACK_MAX)}…(${String(text.length)} chars)`;
|
|
44638
|
+
} catch {
|
|
44639
|
+
return UNPRINTABLE;
|
|
44640
|
+
}
|
|
44641
|
+
}
|
|
44642
|
+
async function postServerException(error, errorKind, operation, properties, context) {
|
|
44643
|
+
const evidence = errorEvidence(error);
|
|
44644
|
+
const message = String(evidence.error_message);
|
|
44645
|
+
const stack = safeStack(error);
|
|
44646
|
+
const { attribution: _attribution, delivery: _delivery, operation: _op, ...rest } = context ?? {};
|
|
44647
|
+
await postPostHogEvent("$exception", {
|
|
44648
|
+
...properties,
|
|
44649
|
+
operation,
|
|
44650
|
+
error_kind: errorKind,
|
|
44651
|
+
...evidence,
|
|
44652
|
+
...safeEvidence(rest),
|
|
44653
|
+
handled: true,
|
|
44654
|
+
producer: "server",
|
|
44655
|
+
$exception_type: errorKind,
|
|
44656
|
+
$exception_message: message,
|
|
44657
|
+
$exception_fingerprint: failureFingerprint(errorKind, isCapxulError(error) ? error.mode : void 0, operation),
|
|
44658
|
+
$exception_list: [{
|
|
44659
|
+
type: errorKind,
|
|
44660
|
+
value: message,
|
|
44661
|
+
mechanism: {
|
|
44662
|
+
handled: true,
|
|
44663
|
+
type: "capxul_backend_boundary"
|
|
44664
|
+
},
|
|
44665
|
+
...stack === void 0 ? {} : { stack },
|
|
44666
|
+
stacktrace: { frames: [{
|
|
44667
|
+
filename: "capxul-backend-observation://boundary",
|
|
44668
|
+
function: operation,
|
|
44669
|
+
lineno: 1,
|
|
44670
|
+
colno: 1,
|
|
44671
|
+
in_app: true
|
|
44672
|
+
}] }
|
|
44673
|
+
}]
|
|
44674
|
+
}, { timeoutMs: POSTHOG_ERROR_TIMEOUT_MS });
|
|
44675
|
+
}
|
|
44676
|
+
async function captureBrowserSdkFailure(input) {
|
|
44677
|
+
const { operation, errorKind, sdkVersion, attribution, correlationId } = input;
|
|
44678
|
+
const properties = {
|
|
44679
|
+
...attributionProperties(attribution),
|
|
44680
|
+
operation,
|
|
44681
|
+
error_kind: errorKind,
|
|
44682
|
+
sdk_version: sdkVersion,
|
|
44683
|
+
handled: true,
|
|
44684
|
+
producer: "browser"
|
|
44685
|
+
};
|
|
44686
|
+
if (correlationId !== void 0) properties.correlation_id = correlationId;
|
|
44687
|
+
if (EXPECTED_OPERATION_OUTCOMES.has(errorKind)) {
|
|
44688
|
+
emitBackendWideEvent({
|
|
44689
|
+
op: operation,
|
|
44690
|
+
outcome: "expected",
|
|
44691
|
+
error_kind: errorKind,
|
|
44692
|
+
sdk_version: sdkVersion,
|
|
44693
|
+
actor_kind: properties.actor_kind,
|
|
44694
|
+
actor_id: properties.actor_id,
|
|
44695
|
+
correlation_id: properties.correlation_id,
|
|
44696
|
+
journey_id: properties.journey_id,
|
|
44697
|
+
handled: true,
|
|
44698
|
+
producer: "browser"
|
|
44699
|
+
});
|
|
44700
|
+
return;
|
|
44701
|
+
}
|
|
44702
|
+
await postPostHogEvent("$exception", {
|
|
44703
|
+
...properties,
|
|
44704
|
+
$exception_type: errorKind,
|
|
44705
|
+
$exception_message: "Capxul SDK operation failed",
|
|
44706
|
+
$exception_list: [{
|
|
44707
|
+
type: errorKind,
|
|
44708
|
+
value: "Capxul SDK operation failed",
|
|
44709
|
+
mechanism: {
|
|
44710
|
+
handled: true,
|
|
44711
|
+
type: "capxul_sdk_boundary"
|
|
44712
|
+
},
|
|
44713
|
+
stacktrace: { frames: [{
|
|
44714
|
+
filename: "capxul-sdk-observation://boundary",
|
|
44715
|
+
function: operation,
|
|
44716
|
+
lineno: 1,
|
|
44717
|
+
colno: 1,
|
|
44718
|
+
in_app: true
|
|
44719
|
+
}] }
|
|
44720
|
+
}]
|
|
44721
|
+
}, { timeoutMs: POSTHOG_ERROR_TIMEOUT_MS });
|
|
44722
|
+
}
|
|
44723
|
+
async function captureBoundaryException(error, context) {
|
|
44724
|
+
const attribution = readAttribution(context?.attribution);
|
|
44725
|
+
await Promise.resolve(captureBackendDiagnostic(error, {
|
|
44726
|
+
...context,
|
|
44727
|
+
attribution
|
|
44728
|
+
}));
|
|
44729
|
+
}
|
|
44730
|
+
/**
|
|
44731
|
+
* The 5b exit for the server half: one wide, high-cardinality line per failed
|
|
44732
|
+
* operation (ADR-0020 B1). It is a `console.error` because Convex log streams
|
|
44733
|
+
* are the deployment's OTLP export path — no fetch, so it also works from
|
|
44734
|
+
* queries and mutations, where the old PostHog post could never run.
|
|
44735
|
+
*/
|
|
44736
|
+
function emitBackendWideEvent(fields) {
|
|
44737
|
+
if (isHermeticTestRun()) return;
|
|
44738
|
+
const line = {};
|
|
44739
|
+
for (const [key, value] of Object.entries(fields)) if (value !== void 0) line[key] = value;
|
|
44740
|
+
console.error("[CAPXUL_BACKEND_OPERATION]", line);
|
|
44741
|
+
}
|
|
44742
|
+
function captureLocalException(error, context, delivery = "local_sanitized") {
|
|
44743
|
+
if (isHermeticTestRun()) return;
|
|
44744
|
+
const errorKind = observationErrorKind(error);
|
|
44745
|
+
console.error("[CAPXUL_BACKEND_BOUNDARY]", {
|
|
44746
|
+
operation: normalizeOperation(context?.operation),
|
|
44747
|
+
error_kind: errorKind,
|
|
44748
|
+
delivery,
|
|
44749
|
+
...errorEvidence(error)
|
|
44750
|
+
});
|
|
44751
|
+
}
|
|
44752
|
+
/** Redacted message, cause chain (outermost first), and details of one failure. */
|
|
44753
|
+
function errorEvidence(error) {
|
|
44754
|
+
try {
|
|
44755
|
+
const message = safeText(error);
|
|
44756
|
+
const details = isCapxulError(error) ? error.details : void 0;
|
|
44757
|
+
const causeChain = [];
|
|
44758
|
+
let link = error instanceof Error ? error.cause : void 0;
|
|
44759
|
+
for (let depth = 0; depth < 8 && link !== void 0 && link !== null; depth++) {
|
|
44760
|
+
causeChain.push(safeText(link));
|
|
44761
|
+
link = link instanceof Error ? link.cause : void 0;
|
|
44762
|
+
}
|
|
44763
|
+
const mode = isCapxulError(error) ? error.mode : void 0;
|
|
44764
|
+
const chain = isCapxulError(error) ? error.chain : void 0;
|
|
44765
|
+
return {
|
|
44766
|
+
error_message: message,
|
|
44767
|
+
...details === void 0 ? {} : { error_details: safeEvidence(details) },
|
|
44768
|
+
...causeChain.length === 0 ? {} : { error_cause: clipEvidence(causeChain.join(" <- ")) },
|
|
44769
|
+
...mode === void 0 ? {} : { failure_mode: mode },
|
|
44770
|
+
...chain === void 0 ? {} : safeEvidence(chainCauseProperties(chain))
|
|
44771
|
+
};
|
|
44772
|
+
} catch {
|
|
44773
|
+
return { error_message: UNPRINTABLE };
|
|
44774
|
+
}
|
|
44775
|
+
}
|
|
44776
|
+
function readAttribution(value) {
|
|
44777
|
+
return readExplicitAttribution(value) ?? systemAttribution("unattributed_boundary");
|
|
44778
|
+
}
|
|
44779
|
+
function readExplicitAttribution(value) {
|
|
44780
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
44781
|
+
const candidate = value;
|
|
44782
|
+
if (candidate.kind === "authenticated" && typeof candidate.authUserId === "string") return candidate;
|
|
44783
|
+
if (candidate.kind === "anonymous" && typeof candidate.anonymousId === "string") return candidate;
|
|
44784
|
+
if (candidate.kind === "system" && typeof candidate.systemJob === "string") return candidate;
|
|
44785
|
+
}
|
|
44786
|
+
function normalizeOperation(value) {
|
|
44787
|
+
return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.:/-]{0,255}$/u.test(value) ? value : "unknown";
|
|
44788
|
+
}
|
|
44789
|
+
//#endregion
|
|
44790
|
+
//#region ../../packages/backend/convex/_shared/telemetry.ts
|
|
44791
|
+
const AWAITED_TELEMETRY_TIMEOUT_MS = 5e3;
|
|
44792
|
+
/** Await in Convex actions — satisfies dangling-promise lint for PostHog fetch. */
|
|
44793
|
+
async function emitServerAwaited(attribution, event) {
|
|
44794
|
+
try {
|
|
44795
|
+
await emitServerPromise(attribution, event, { timeoutMs: AWAITED_TELEMETRY_TIMEOUT_MS });
|
|
44796
|
+
} catch (error) {
|
|
44797
|
+
await reportTelemetryFailure(error, {
|
|
44798
|
+
event: event.name,
|
|
44799
|
+
source: "backend.telemetry.emitServerAwaited"
|
|
44800
|
+
});
|
|
44801
|
+
}
|
|
44802
|
+
}
|
|
44803
|
+
function emitServerPromise(attribution, event, options) {
|
|
44804
|
+
const decoded = decodeTelemetryEvent(stampTelemetryEnvelope(event, {
|
|
44805
|
+
capxul_env: resolveCapxulEnv(),
|
|
44806
|
+
producer: "server"
|
|
44807
|
+
}));
|
|
44808
|
+
const redactedProps = redactTelemetryProps(decoded.name, decoded.props) ?? {};
|
|
44809
|
+
return postPostHogEvent(decoded.name, {
|
|
44810
|
+
...redactedProps,
|
|
44811
|
+
...attributionProperties(attribution)
|
|
44812
|
+
}, options);
|
|
44813
|
+
}
|
|
44814
|
+
function decodeTelemetryEvent(event) {
|
|
44815
|
+
const loose = TELEMETRY_EVENT_SCHEMAS[event.name];
|
|
44816
|
+
return Schema.decodeUnknownSync(loose)(event);
|
|
44817
|
+
}
|
|
44818
|
+
async function reportTelemetryFailure(error, context) {
|
|
44819
|
+
try {
|
|
44820
|
+
const reporterModule = init_exports;
|
|
44821
|
+
if (!Object.prototype.hasOwnProperty.call(reporterModule, "reportError")) return;
|
|
44822
|
+
await reporterModule.reportError?.(error, context);
|
|
44823
|
+
} catch {}
|
|
44824
|
+
}
|
|
44825
|
+
//#endregion
|
|
44826
|
+
//#region ../../packages/backend/convex/_shared/userOperationRevert.ts
|
|
44827
|
+
/** OpenZeppelin v5 ERC-20 errors (ERC-6093). The token contracts on Base Sepolia use them. */
|
|
44828
|
+
const ERC20_ERRORS_ABI = [
|
|
44829
|
+
{
|
|
44830
|
+
type: "error",
|
|
44831
|
+
name: "ERC20InsufficientBalance",
|
|
44832
|
+
inputs: [
|
|
44833
|
+
{
|
|
44834
|
+
name: "sender",
|
|
44835
|
+
type: "address"
|
|
44836
|
+
},
|
|
44837
|
+
{
|
|
44838
|
+
name: "balance",
|
|
44839
|
+
type: "uint256"
|
|
44840
|
+
},
|
|
44841
|
+
{
|
|
44842
|
+
name: "needed",
|
|
44843
|
+
type: "uint256"
|
|
44844
|
+
}
|
|
44845
|
+
]
|
|
44846
|
+
},
|
|
44847
|
+
{
|
|
44848
|
+
type: "error",
|
|
44849
|
+
name: "ERC20InsufficientAllowance",
|
|
44850
|
+
inputs: [
|
|
44851
|
+
{
|
|
44852
|
+
name: "spender",
|
|
44853
|
+
type: "address"
|
|
44854
|
+
},
|
|
44855
|
+
{
|
|
44856
|
+
name: "allowance",
|
|
44857
|
+
type: "uint256"
|
|
44858
|
+
},
|
|
44859
|
+
{
|
|
44860
|
+
name: "needed",
|
|
44861
|
+
type: "uint256"
|
|
44862
|
+
}
|
|
44863
|
+
]
|
|
44864
|
+
},
|
|
44865
|
+
{
|
|
44866
|
+
type: "error",
|
|
44867
|
+
name: "ERC20InvalidSender",
|
|
44868
|
+
inputs: [{
|
|
44869
|
+
name: "sender",
|
|
44870
|
+
type: "address"
|
|
44871
|
+
}]
|
|
44872
|
+
},
|
|
44873
|
+
{
|
|
44874
|
+
type: "error",
|
|
44875
|
+
name: "ERC20InvalidReceiver",
|
|
44876
|
+
inputs: [{
|
|
44877
|
+
name: "receiver",
|
|
44878
|
+
type: "address"
|
|
44879
|
+
}]
|
|
44880
|
+
},
|
|
44881
|
+
{
|
|
44882
|
+
type: "error",
|
|
44883
|
+
name: "ERC20InvalidApprover",
|
|
44884
|
+
inputs: [{
|
|
44885
|
+
name: "approver",
|
|
44886
|
+
type: "address"
|
|
44887
|
+
}]
|
|
44888
|
+
},
|
|
44889
|
+
{
|
|
44890
|
+
type: "error",
|
|
44891
|
+
name: "ERC20InvalidSpender",
|
|
44892
|
+
inputs: [{
|
|
44893
|
+
name: "spender",
|
|
44894
|
+
type: "address"
|
|
44895
|
+
}]
|
|
44896
|
+
}
|
|
44897
|
+
];
|
|
44898
|
+
const REVERT_ABI = [...CAPXUL_PAYMENTS_V2_ABI, ...ERC20_ERRORS_ABI];
|
|
44899
|
+
const REASON_RE = /reason:\s*(0x[0-9a-fA-F]*)/u;
|
|
44900
|
+
const SELECTOR_LENGTH = 10;
|
|
44901
|
+
function stringifyArg(value) {
|
|
44902
|
+
if (typeof value === "bigint") return value.toString(10);
|
|
44903
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return String(value);
|
|
44904
|
+
return JSON.stringify(value);
|
|
44905
|
+
}
|
|
44906
|
+
/** Decode revert data. Never throws: an unknown selector yields `name: null`. */
|
|
44907
|
+
function decodeRevertData(data) {
|
|
44908
|
+
const selector = data.length >= SELECTOR_LENGTH ? data.slice(0, SELECTOR_LENGTH) : "0x";
|
|
44909
|
+
if (selector === "0x") return {
|
|
44910
|
+
data,
|
|
44911
|
+
selector,
|
|
44912
|
+
name: null,
|
|
44913
|
+
args: {}
|
|
44914
|
+
};
|
|
44915
|
+
try {
|
|
44916
|
+
const decoded = decodeErrorResult({
|
|
44917
|
+
abi: REVERT_ABI,
|
|
44918
|
+
data
|
|
44919
|
+
});
|
|
44920
|
+
const inputs = decoded.abiItem.type === "error" ? decoded.abiItem.inputs.map((input) => input.name) : [];
|
|
44921
|
+
const args = {};
|
|
44922
|
+
(decoded.args ?? []).forEach((value, index) => {
|
|
44923
|
+
args[inputs[index] ?? String(index)] = stringifyArg(value);
|
|
44924
|
+
});
|
|
44925
|
+
return {
|
|
44926
|
+
data,
|
|
44927
|
+
selector,
|
|
44928
|
+
name: decoded.errorName,
|
|
44929
|
+
args
|
|
44930
|
+
};
|
|
44931
|
+
} catch {
|
|
44932
|
+
return {
|
|
44933
|
+
data,
|
|
44934
|
+
selector,
|
|
44935
|
+
name: null,
|
|
44936
|
+
args: {}
|
|
44937
|
+
};
|
|
44938
|
+
}
|
|
44939
|
+
}
|
|
44940
|
+
/** The revert data a bundler message carries, or null when the message names none. */
|
|
44941
|
+
function revertDataInMessage(message) {
|
|
44942
|
+
const match = REASON_RE.exec(message);
|
|
44943
|
+
return match?.[1] === void 0 ? null : match[1];
|
|
44944
|
+
}
|
|
44945
|
+
/** `ERC20InsufficientBalance(sender=0x…, balance=1000000000, needed=50000000000000)`. */
|
|
44946
|
+
function describeRevert(revert) {
|
|
44947
|
+
if (revert.name === null) return revert.selector === "0x" ? "empty revert" : `unknown selector ${revert.selector}`;
|
|
44948
|
+
const args = Object.entries(revert.args).map(([name, value]) => `${name}=${value}`).join(", ");
|
|
44949
|
+
return `${revert.name}(${args})`;
|
|
44950
|
+
}
|
|
44951
|
+
/** Decode the revert in a bundler error message, or null when there is none. */
|
|
44952
|
+
function decodeUserOperationRevert(message) {
|
|
44953
|
+
const data = revertDataInMessage(message);
|
|
44954
|
+
return data === null ? null : decodeRevertData(data);
|
|
44955
|
+
}
|
|
44956
|
+
/**
|
|
44957
|
+
* A sponsorship failure whose decoded revert is the token's insufficient
|
|
44958
|
+
* balance is a product outcome, not a provider defect: return it as
|
|
44959
|
+
* `INSUFFICIENT_BALANCE` with the token's own numbers. Every other failure
|
|
44960
|
+
* passes through unchanged (an allowance failure is a route bug and stays a
|
|
44961
|
+
* provider error for error tracking).
|
|
44962
|
+
*/
|
|
44963
|
+
function typedSponsorshipFailure(error) {
|
|
44964
|
+
if (!(error instanceof CapxulError) || error.details?.revert_name !== "ERC20InsufficientBalance") return error;
|
|
44965
|
+
const args = error.details.revert_args;
|
|
44966
|
+
return new CapxulError("INSUFFICIENT_BALANCE", "Insufficient token balance", {
|
|
44967
|
+
cause: error,
|
|
44968
|
+
details: {
|
|
44969
|
+
asset: "token",
|
|
44970
|
+
available: args?.balance ?? "unknown",
|
|
44971
|
+
required: args?.needed ?? "unknown",
|
|
44972
|
+
sender: args?.sender ?? "unknown",
|
|
44973
|
+
revert: error.details.revert,
|
|
44974
|
+
failure_mode: "insufficient-balance"
|
|
44975
|
+
},
|
|
44976
|
+
mode: "insufficient-balance",
|
|
44977
|
+
...error.chain === void 0 ? {} : { chain: error.chain },
|
|
44978
|
+
...error.correlationId === void 0 ? {} : { correlationId: error.correlationId }
|
|
44979
|
+
});
|
|
44980
|
+
}
|
|
43334
44981
|
//#endregion
|
|
43335
44982
|
//#region ../../packages/backend/convex/_shared/alchemyRpc.ts
|
|
43336
44983
|
const TX_HASH_HEX = /^0x[0-9a-fA-F]{64}$/;
|
|
@@ -43366,27 +45013,106 @@ function rpcProviderError(operation, cause, chainId) {
|
|
|
43366
45013
|
const method = operation.split(" ", 1)[0] ?? operation;
|
|
43367
45014
|
return Errors.providerError(rpcProviderRole(chainId, method), operation, cause);
|
|
43368
45015
|
}
|
|
45016
|
+
/** The modes the next upstream may not share: a throttle, a timeout, a dead upstream. */
|
|
45017
|
+
const TRANSIENT_MODES = new Set([
|
|
45018
|
+
"rate-limited",
|
|
45019
|
+
"timeout",
|
|
45020
|
+
"upstream-down"
|
|
45021
|
+
]);
|
|
45022
|
+
/** ERC-4337 validation refusals (`-3250x`) and the bundler's invalid-params answer. */
|
|
45023
|
+
const BUNDLER_REJECTION_CODES = new Set([
|
|
45024
|
+
-32500,
|
|
45025
|
+
-32501,
|
|
45026
|
+
-32502,
|
|
45027
|
+
-32503,
|
|
45028
|
+
-32504,
|
|
45029
|
+
-32505,
|
|
45030
|
+
-32506,
|
|
45031
|
+
-32507,
|
|
45032
|
+
-32508,
|
|
45033
|
+
-32602
|
|
45034
|
+
]);
|
|
43369
45035
|
/**
|
|
43370
|
-
*
|
|
43371
|
-
*
|
|
43372
|
-
*
|
|
45036
|
+
* Alto reports a malformed `eth_sendUserOperation` with `-32601` and a
|
|
45037
|
+
* "Validation error: …" message (staging, 2026-09-02). Only that shape is a
|
|
45038
|
+
* rejection; a plain method-not-found stays an upstream failure.
|
|
43373
45039
|
*/
|
|
43374
|
-
|
|
43375
|
-
|
|
45040
|
+
const METHOD_NOT_FOUND_RPC_CODE = -32601;
|
|
45041
|
+
const ALTO_VALIDATION_ERROR = /^Validation error:/u;
|
|
45042
|
+
function isBundlerRejection(method, code, message) {
|
|
45043
|
+
if (!BUNDLER_RPC_METHODS.has(method)) return false;
|
|
45044
|
+
if (BUNDLER_REJECTION_CODES.has(code)) return true;
|
|
45045
|
+
return code === METHOD_NOT_FOUND_RPC_CODE && method === "eth_sendUserOperation" && ALTO_VALIDATION_ERROR.test(message);
|
|
45046
|
+
}
|
|
45047
|
+
/**
|
|
45048
|
+
* A chain-path failure with its cause (ADR-0023 R7–R8). The cause is built
|
|
45049
|
+
* once by the layer that saw it and never rewritten; `details.failure_mode`
|
|
45050
|
+
* and `details.transient` stay for existing readers.
|
|
45051
|
+
*/
|
|
45052
|
+
function chainProviderError(method, operation, cause, chainId, chain, extraDetails = {}) {
|
|
43376
45053
|
return Errors.providerError(rpcProviderRole(chainId, method), operation, cause, {
|
|
43377
|
-
|
|
43378
|
-
details: {
|
|
45054
|
+
chain,
|
|
45055
|
+
details: {
|
|
45056
|
+
...extraDetails,
|
|
45057
|
+
transient: TRANSIENT_MODES.has(chain.mode)
|
|
45058
|
+
}
|
|
43379
45059
|
});
|
|
43380
45060
|
}
|
|
43381
45061
|
function isTransientProviderError(error) {
|
|
43382
|
-
return error instanceof CapxulError && error.
|
|
45062
|
+
return error instanceof CapxulError && error.chain !== void 0 && TRANSIENT_MODES.has(error.chain.mode);
|
|
43383
45063
|
}
|
|
43384
|
-
function
|
|
45064
|
+
function rethrowTransport(chainId, method, upstream, externalSignal) {
|
|
43385
45065
|
return (e) => {
|
|
43386
45066
|
if (externalSignal?.aborted === true) throw rpcProviderError(method, e, chainId);
|
|
43387
|
-
throw
|
|
45067
|
+
throw chainProviderError(method, method, e, chainId, {
|
|
45068
|
+
mode: e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError") ? "timeout" : "upstream-down",
|
|
45069
|
+
upstream,
|
|
45070
|
+
method,
|
|
45071
|
+
retryable: true,
|
|
45072
|
+
providerMessage: boundedEvidence(e instanceof Error ? e.message : String(e), BUNDLER_MESSAGE_MAX)
|
|
45073
|
+
});
|
|
43388
45074
|
};
|
|
43389
45075
|
}
|
|
45076
|
+
/** The `chain_upstream_fallback` event for one skipped upstream. Pure; the catalog test decodes it. */
|
|
45077
|
+
function upstreamFallbackEvent(input) {
|
|
45078
|
+
return {
|
|
45079
|
+
name: "chain_upstream_fallback",
|
|
45080
|
+
props: {
|
|
45081
|
+
service: "backend",
|
|
45082
|
+
method: input.method,
|
|
45083
|
+
from_upstream: input.from,
|
|
45084
|
+
...input.to === void 0 ? {} : { to_upstream: input.to },
|
|
45085
|
+
failure_mode: input.chain.mode,
|
|
45086
|
+
exhausted: input.to === void 0,
|
|
45087
|
+
...input.chain.httpStatus === void 0 ? {} : { http_status: input.chain.httpStatus },
|
|
45088
|
+
...input.chain.rpcCode === void 0 ? {} : { rpc_code: input.chain.rpcCode }
|
|
45089
|
+
}
|
|
45090
|
+
};
|
|
45091
|
+
}
|
|
45092
|
+
/**
|
|
45093
|
+
* Recovered fallback and exhaustion are events; the read's own outcome
|
|
45094
|
+
* stands. Awaited: a Convex action can be torn down as soon as it returns,
|
|
45095
|
+
* so a fire-and-forget capture here can be lost.
|
|
45096
|
+
*/
|
|
45097
|
+
async function reportUpstreamFallback(method, from, to, chain) {
|
|
45098
|
+
console.warn(JSON.stringify({
|
|
45099
|
+
event: "rpc_upstream_fallback",
|
|
45100
|
+
method,
|
|
45101
|
+
from,
|
|
45102
|
+
to: to ?? null,
|
|
45103
|
+
failure_mode: chain.mode,
|
|
45104
|
+
rate_limited: chain.mode === "rate-limited"
|
|
45105
|
+
}));
|
|
45106
|
+
if (isHermeticTestRun()) return;
|
|
45107
|
+
try {
|
|
45108
|
+
await emitServerAwaited(systemAttribution("chain_rpc"), upstreamFallbackEvent({
|
|
45109
|
+
method,
|
|
45110
|
+
from,
|
|
45111
|
+
to,
|
|
45112
|
+
chain
|
|
45113
|
+
}));
|
|
45114
|
+
} catch {}
|
|
45115
|
+
}
|
|
43390
45116
|
function parseRpcQuantity(value, operation, field, chainId) {
|
|
43391
45117
|
try {
|
|
43392
45118
|
return BigInt(value);
|
|
@@ -43420,12 +45146,52 @@ const BASE_MAINNET_NODE_RPC_URL = "https://mainnet.base.org";
|
|
|
43420
45146
|
*/
|
|
43421
45147
|
function nodeRpcUrl(chainId) {
|
|
43422
45148
|
switch (chainId) {
|
|
43423
|
-
case 84532:
|
|
45149
|
+
case 84532: {
|
|
45150
|
+
const override = optionalEnv("BASE_SEPOLIA_RPC_URL");
|
|
45151
|
+
return (override !== void 0 && hostedUpstreamName(override) === null ? override : BASE_SEPOLIA_NODE_RPC_URL).replace(/\/+$/, "");
|
|
45152
|
+
}
|
|
43424
45153
|
case 8453: return (optionalEnv("BASE_MAINNET_RPC_URL") ?? BASE_MAINNET_NODE_RPC_URL).replace(/\/+$/, "");
|
|
43425
45154
|
default: throw Errors.invalidInput("chainId", `unsupported chainId ${String(chainId)}`);
|
|
43426
45155
|
}
|
|
43427
45156
|
}
|
|
43428
45157
|
/**
|
|
45158
|
+
* Evidence sizes for a decoded simulation revert (#1685). The bundler message
|
|
45159
|
+
* is provider-controlled: keep the decoded name and selector whole, and cap
|
|
45160
|
+
* every free-form string so one oversized answer cannot inflate an exception
|
|
45161
|
+
* payload. The reporter masks credential-shaped values on top of this.
|
|
45162
|
+
*/
|
|
45163
|
+
const REVERT_LINE_MAX = 400;
|
|
45164
|
+
const REVERT_ARG_MAX = 128;
|
|
45165
|
+
const REVERT_DATA_MAX = 522;
|
|
45166
|
+
const BUNDLER_MESSAGE_MAX = 300;
|
|
45167
|
+
function clip(value, max) {
|
|
45168
|
+
return value.length <= max ? value : `${value.slice(0, max)}…(${String(value.length)} chars)`;
|
|
45169
|
+
}
|
|
45170
|
+
function revertSummaryOf(revert) {
|
|
45171
|
+
return {
|
|
45172
|
+
name: revert.name,
|
|
45173
|
+
selector: revert.selector,
|
|
45174
|
+
args: revert.args
|
|
45175
|
+
};
|
|
45176
|
+
}
|
|
45177
|
+
function revertMode(revert) {
|
|
45178
|
+
if (revert.name === "ERC20InsufficientBalance") return "insufficient-balance";
|
|
45179
|
+
if (revert.name === "ERC20InsufficientAllowance") return "insufficient-allowance";
|
|
45180
|
+
return "revert";
|
|
45181
|
+
}
|
|
45182
|
+
function boundedRevertDetails(revert, bundlerMessage) {
|
|
45183
|
+
const args = {};
|
|
45184
|
+
for (const [name, value] of Object.entries(revert.args).slice(0, 8)) args[clip(name, 32)] = clip(value, REVERT_ARG_MAX);
|
|
45185
|
+
return {
|
|
45186
|
+
revert: clip(describeRevert(revert), REVERT_LINE_MAX),
|
|
45187
|
+
revert_name: revert.name,
|
|
45188
|
+
revert_selector: revert.selector,
|
|
45189
|
+
revert_args: args,
|
|
45190
|
+
revert_data: clip(revert.data, REVERT_DATA_MAX),
|
|
45191
|
+
bundler_message: clip(bundlerMessage, BUNDLER_MESSAGE_MAX)
|
|
45192
|
+
};
|
|
45193
|
+
}
|
|
45194
|
+
/**
|
|
43429
45195
|
* JSON-RPC "limit exceeded". Providers use it for rate limits and the AA
|
|
43430
45196
|
* Gateway returns it when alto failed while its upstream chain was exhausted
|
|
43431
45197
|
* (`packages/aa-gateway/src/modules/upstream/types.ts`).
|
|
@@ -43437,16 +45203,45 @@ const WIDE_LOG_READS = new Set(["eth_getLogs"]);
|
|
|
43437
45203
|
function stripSlash(url) {
|
|
43438
45204
|
return url.replace(/\/+$/u, "");
|
|
43439
45205
|
}
|
|
45206
|
+
/**
|
|
45207
|
+
* Which hosted provider a URL points at, by host. The env name is not
|
|
45208
|
+
* trusted: staging held an Alchemy URL in `BASE_SEPOLIA_RPC_URL` and the
|
|
45209
|
+
* Infura URL in `BASE_SEPOLIA_EVIDENCE_RPC_URL`, which ran the chain
|
|
45210
|
+
* backwards (audit 2026-09-02, gap 5).
|
|
45211
|
+
*/
|
|
45212
|
+
function hostedUpstreamName(url) {
|
|
45213
|
+
let host;
|
|
45214
|
+
try {
|
|
45215
|
+
host = new URL(url).hostname;
|
|
45216
|
+
} catch {
|
|
45217
|
+
return null;
|
|
45218
|
+
}
|
|
45219
|
+
if (host === "alchemy.com" || host.endsWith(".alchemy.com")) return "alchemy";
|
|
45220
|
+
if (host === "infura.io" || host.endsWith(".infura.io")) return "infura";
|
|
45221
|
+
return null;
|
|
45222
|
+
}
|
|
45223
|
+
/** Env names in priority order; an explicit slot name wins when the host says nothing. */
|
|
45224
|
+
const BASE_SEPOLIA_UPSTREAM_ENV_NAMES = [
|
|
45225
|
+
["BASE_SEPOLIA_ALCHEMY_RPC_URL", "alchemy"],
|
|
45226
|
+
["BASE_SEPOLIA_INFURA_RPC_URL", "infura"],
|
|
45227
|
+
["BASE_SEPOLIA_EVIDENCE_RPC_URL", null],
|
|
45228
|
+
["BASE_SEPOLIA_RPC_URL", null]
|
|
45229
|
+
];
|
|
43440
45230
|
function hostedUpstreams(chainId) {
|
|
43441
45231
|
if (chainId !== 84532) return [];
|
|
43442
|
-
const
|
|
43443
|
-
const
|
|
43444
|
-
|
|
45232
|
+
const found = {};
|
|
45233
|
+
for (const [name, declared] of BASE_SEPOLIA_UPSTREAM_ENV_NAMES) {
|
|
45234
|
+
const url = optionalEnv(name);
|
|
45235
|
+
if (url === void 0) continue;
|
|
45236
|
+
const kind = hostedUpstreamName(url) ?? declared;
|
|
45237
|
+
if (kind !== null && found[kind] === void 0) found[kind] = stripSlash(url);
|
|
45238
|
+
}
|
|
45239
|
+
return [...found.alchemy === void 0 ? [] : [{
|
|
43445
45240
|
name: "alchemy",
|
|
43446
|
-
url:
|
|
43447
|
-
}], ...infura === void 0 ? [] : [{
|
|
45241
|
+
url: found.alchemy
|
|
45242
|
+
}], ...found.infura === void 0 ? [] : [{
|
|
43448
45243
|
name: "infura",
|
|
43449
|
-
url:
|
|
45244
|
+
url: found.infura
|
|
43450
45245
|
}]];
|
|
43451
45246
|
}
|
|
43452
45247
|
/** Node upstreams in the order one method tries them. Always ends on the public node. */
|
|
@@ -43467,33 +45262,87 @@ function isValidJsonRpcError(value) {
|
|
|
43467
45262
|
return isRecord(value) && typeof value.code === "number" && Number.isInteger(value.code) && typeof value.message === "string";
|
|
43468
45263
|
}
|
|
43469
45264
|
var DefinitiveBundlerJsonRpcRejection = class extends Error {
|
|
43470
|
-
constructor() {
|
|
43471
|
-
super(
|
|
45265
|
+
constructor(message) {
|
|
45266
|
+
super(message);
|
|
43472
45267
|
this.name = "DefinitiveBundlerJsonRpcRejection";
|
|
43473
45268
|
}
|
|
43474
45269
|
};
|
|
43475
45270
|
async function alchemyRpc(chainId, method, params, timeoutMs, externalSignal) {
|
|
43476
|
-
if (BUNDLER_RPC_METHODS.has(method)) return jsonRpcOnce(chainId, method, params, stripSlash(accountAbstractionUrl(chainId)), timeoutMs, externalSignal);
|
|
45271
|
+
if (BUNDLER_RPC_METHODS.has(method)) return jsonRpcOnce(chainId, method, params, stripSlash(accountAbstractionUrl(chainId)), "gateway", timeoutMs, externalSignal);
|
|
43477
45272
|
const candidates = nodeRpcCandidates(chainId, method);
|
|
43478
|
-
let lastError;
|
|
43479
45273
|
for (const [index, upstream] of candidates.entries()) try {
|
|
43480
|
-
return await jsonRpcOnce(chainId, method, params, upstream.url, timeoutMs, externalSignal);
|
|
45274
|
+
return await jsonRpcOnce(chainId, method, params, upstream.url, upstream.name, timeoutMs, externalSignal);
|
|
43481
45275
|
} catch (error) {
|
|
45276
|
+
if (!isTransientProviderError(error)) throw error;
|
|
43482
45277
|
const next = candidates[index + 1];
|
|
43483
|
-
|
|
43484
|
-
|
|
43485
|
-
console.warn(JSON.stringify({
|
|
43486
|
-
event: "rpc_upstream_fallback",
|
|
43487
|
-
method,
|
|
43488
|
-
from: upstream.name,
|
|
43489
|
-
to: next.name,
|
|
43490
|
-
operation: error.details?.operation,
|
|
43491
|
-
rate_limited: error.details?.failure_mode === "rate-limited"
|
|
43492
|
-
}));
|
|
45278
|
+
await reportUpstreamFallback(method, upstream.name, next?.name, error.chain);
|
|
45279
|
+
if (next === void 0) throw error;
|
|
43493
45280
|
}
|
|
43494
|
-
throw
|
|
45281
|
+
throw rpcProviderError(method, "no upstream configured", chainId);
|
|
43495
45282
|
}
|
|
43496
|
-
|
|
45283
|
+
/**
|
|
45284
|
+
* A JSON-RPC error answer, named. The gateway's `error.data` is the cause when
|
|
45285
|
+
* present (R8); a node's answer is classified here. Returns the error to throw.
|
|
45286
|
+
*/
|
|
45287
|
+
function jsonRpcErrorFailure(chainId, method, upstream, error) {
|
|
45288
|
+
const { code, message } = error;
|
|
45289
|
+
const providerMessage = boundedEvidence(message, BUNDLER_MESSAGE_MAX);
|
|
45290
|
+
const decoded = BUNDLER_RPC_METHODS.has(method) ? decodeUserOperationRevert(message) : null;
|
|
45291
|
+
const named = decodeChainCause(error.data);
|
|
45292
|
+
let chain;
|
|
45293
|
+
if (named !== null) chain = named.revert !== void 0 && named.revert.name === null && decoded?.name != null ? {
|
|
45294
|
+
...named,
|
|
45295
|
+
revert: {
|
|
45296
|
+
...named.revert,
|
|
45297
|
+
name: decoded.name
|
|
45298
|
+
},
|
|
45299
|
+
mode: named.mode === "revert" ? revertMode(revertSummaryOf(decoded)) : named.mode
|
|
45300
|
+
} : named;
|
|
45301
|
+
else if (code === RATE_LIMITED_RPC_CODE || RATE_LIMIT_MESSAGE.test(message)) chain = {
|
|
45302
|
+
mode: "rate-limited",
|
|
45303
|
+
upstream,
|
|
45304
|
+
method,
|
|
45305
|
+
retryable: true,
|
|
45306
|
+
rpcCode: code,
|
|
45307
|
+
providerMessage
|
|
45308
|
+
};
|
|
45309
|
+
else if (decoded !== null) {
|
|
45310
|
+
const revert = revertSummaryOf(decoded);
|
|
45311
|
+
chain = {
|
|
45312
|
+
mode: revertMode(revert),
|
|
45313
|
+
upstream,
|
|
45314
|
+
method,
|
|
45315
|
+
retryable: false,
|
|
45316
|
+
rpcCode: code,
|
|
45317
|
+
revert,
|
|
45318
|
+
providerMessage
|
|
45319
|
+
};
|
|
45320
|
+
} else if (isBundlerRejection(method, code, message)) chain = {
|
|
45321
|
+
mode: "rejected",
|
|
45322
|
+
upstream,
|
|
45323
|
+
method,
|
|
45324
|
+
retryable: false,
|
|
45325
|
+
rpcCode: code,
|
|
45326
|
+
providerMessage
|
|
45327
|
+
};
|
|
45328
|
+
else chain = {
|
|
45329
|
+
mode: "unknown",
|
|
45330
|
+
upstream,
|
|
45331
|
+
method,
|
|
45332
|
+
retryable: false,
|
|
45333
|
+
rpcCode: code,
|
|
45334
|
+
providerMessage
|
|
45335
|
+
};
|
|
45336
|
+
const cause = method === "eth_sendUserOperation" && !TRANSIENT_MODES.has(chain.mode) ? new DefinitiveBundlerJsonRpcRejection(message) : message;
|
|
45337
|
+
const revertForDetails = chain.revert === void 0 ? null : decoded ?? {
|
|
45338
|
+
data: chain.revert.selector,
|
|
45339
|
+
selector: chain.revert.selector,
|
|
45340
|
+
name: chain.revert.name,
|
|
45341
|
+
args: chain.revert.args
|
|
45342
|
+
};
|
|
45343
|
+
return chainProviderError(method, method, cause, chainId, chain, revertForDetails === null ? {} : boundedRevertDetails(revertForDetails, message));
|
|
45344
|
+
}
|
|
45345
|
+
async function jsonRpcOnce(chainId, method, params, url, upstream, timeoutMs, externalSignal) {
|
|
43497
45346
|
const timeoutSignal = timeoutMs === void 0 ? void 0 : AbortSignal.timeout(timeoutMs);
|
|
43498
45347
|
const signal = externalSignal === void 0 ? timeoutSignal : timeoutSignal === void 0 ? externalSignal : AbortSignal.any([externalSignal, timeoutSignal]);
|
|
43499
45348
|
const res = await fetch(url, {
|
|
@@ -43506,12 +45355,19 @@ async function jsonRpcOnce(chainId, method, params, url, timeoutMs, externalSign
|
|
|
43506
45355
|
params
|
|
43507
45356
|
}),
|
|
43508
45357
|
...signal === void 0 ? {} : { signal }
|
|
43509
|
-
}).catch(
|
|
45358
|
+
}).catch(rethrowTransport(chainId, method, upstream, externalSignal));
|
|
43510
45359
|
if (!res.ok) {
|
|
43511
45360
|
const body = await res.text().catch(() => "<no body>");
|
|
43512
45361
|
const operation = `${method} ${res.status}`;
|
|
43513
|
-
|
|
43514
|
-
throw
|
|
45362
|
+
const mode = res.status === 429 ? "rate-limited" : res.status >= 500 ? "upstream-down" : res.status === 401 ? "unauthorized" : "unknown";
|
|
45363
|
+
throw chainProviderError(method, operation, body, chainId, {
|
|
45364
|
+
mode,
|
|
45365
|
+
upstream,
|
|
45366
|
+
method,
|
|
45367
|
+
retryable: TRANSIENT_MODES.has(mode),
|
|
45368
|
+
httpStatus: res.status,
|
|
45369
|
+
providerMessage: boundedEvidence(body, BUNDLER_MESSAGE_MAX)
|
|
45370
|
+
});
|
|
43515
45371
|
}
|
|
43516
45372
|
let json;
|
|
43517
45373
|
try {
|
|
@@ -43522,8 +45378,7 @@ async function jsonRpcOnce(chainId, method, params, url, timeoutMs, externalSign
|
|
|
43522
45378
|
if (!isValidJsonRpcEnvelope(json)) throw rpcProviderError(method, "malformed JSON-RPC envelope", chainId);
|
|
43523
45379
|
if (json.error !== void 0) {
|
|
43524
45380
|
if (!isValidJsonRpcError(json.error)) throw rpcProviderError(method, "malformed JSON-RPC error", chainId);
|
|
43525
|
-
|
|
43526
|
-
throw rpcProviderError(method, method === "eth_sendUserOperation" ? new DefinitiveBundlerJsonRpcRejection() : json.error.message, chainId);
|
|
45381
|
+
throw jsonRpcErrorFailure(chainId, method, upstream, json.error);
|
|
43527
45382
|
}
|
|
43528
45383
|
if (json.result === void 0) throw rpcProviderError(method, "missing result", chainId);
|
|
43529
45384
|
return json.result;
|
|
@@ -43827,10 +45682,14 @@ async function buildSponsoredSafeUserOp(input) {
|
|
|
43827
45682
|
maxPriorityFeePerGas: toHex(fees.maxPriorityFeePerGas),
|
|
43828
45683
|
signature: safe4337StubSignature()
|
|
43829
45684
|
};
|
|
43830
|
-
|
|
43831
|
-
|
|
43832
|
-
|
|
43833
|
-
|
|
45685
|
+
try {
|
|
45686
|
+
request = await sponsorUserOperation({
|
|
45687
|
+
chainId,
|
|
45688
|
+
userOp: request
|
|
45689
|
+
});
|
|
45690
|
+
} catch (error) {
|
|
45691
|
+
throw typedSponsorshipFailure(error);
|
|
45692
|
+
}
|
|
43834
45693
|
if (request.paymaster === void 0 || request.paymasterData === void 0) throw Errors.providerError("account-abstraction", "sponsorUserOperation", "missing paymaster sponsorship");
|
|
43835
45694
|
const userOp = {
|
|
43836
45695
|
sender,
|