@capxul/mcp 2.5.5 → 2.6.1
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 +2288 -608
- package/package.json +5 -5
package/dist/main.mjs
CHANGED
|
@@ -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.1";
|
|
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) {
|
|
@@ -2708,7 +2860,8 @@ const CAPXUL_FUNCTIONS = {
|
|
|
2708
2860
|
},
|
|
2709
2861
|
"payroll/queries": {
|
|
2710
2862
|
groups: "payroll/queries:groups",
|
|
2711
|
-
runs: "payroll/queries:runs"
|
|
2863
|
+
runs: "payroll/queries:runs",
|
|
2864
|
+
terms: "payroll/queries:terms"
|
|
2712
2865
|
},
|
|
2713
2866
|
"permission/actions": { verify: "permission/actions:verify" },
|
|
2714
2867
|
"permission/mutations": { command: "permission/mutations:command" },
|
|
@@ -3494,13 +3647,13 @@ const PaymentVerificationMismatchCodeSchema = Schema.Literals([
|
|
|
3494
3647
|
"wrong_destination",
|
|
3495
3648
|
"wrong_amount"
|
|
3496
3649
|
]);
|
|
3497
|
-
const
|
|
3650
|
+
const TransferRangeSchema = Schema.Struct({
|
|
3498
3651
|
chainId: BaseSepoliaChainIdSchema,
|
|
3499
3652
|
tokenAddress: AddressSchema$1,
|
|
3500
3653
|
fromBlock: BlockNumberSchema$1,
|
|
3501
3654
|
toBlock: BlockNumberSchema$1
|
|
3502
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" }));
|
|
3503
|
-
const
|
|
3656
|
+
const TransferEvidenceSchema = Schema.Struct({
|
|
3504
3657
|
...MovementIdentitySchema.fields,
|
|
3505
3658
|
blockNumber: BlockNumberSchema$1,
|
|
3506
3659
|
blockHash: Bytes32Schema,
|
|
@@ -3509,16 +3662,16 @@ const FinalizedTransferEvidenceSchema = Schema.Struct({
|
|
|
3509
3662
|
rawAmount: WeiAmountSchema$1,
|
|
3510
3663
|
removed: Schema.Boolean
|
|
3511
3664
|
});
|
|
3512
|
-
const
|
|
3665
|
+
const ChainBlockReferenceSchema = Schema.Struct({
|
|
3513
3666
|
chainId: BaseSepoliaChainIdSchema,
|
|
3514
3667
|
blockNumber: BlockNumberSchema$1,
|
|
3515
3668
|
blockHash: Bytes32Schema
|
|
3516
3669
|
});
|
|
3517
3670
|
Schema.Struct({
|
|
3518
|
-
range:
|
|
3519
|
-
|
|
3520
|
-
anchor:
|
|
3521
|
-
transfers: Schema.Array(
|
|
3671
|
+
range: TransferRangeSchema,
|
|
3672
|
+
chainHead: ChainBlockReferenceSchema,
|
|
3673
|
+
anchor: ChainBlockReferenceSchema,
|
|
3674
|
+
transfers: Schema.Array(TransferEvidenceSchema),
|
|
3522
3675
|
requestCount: nonNegativeInteger("requestCount")
|
|
3523
3676
|
});
|
|
3524
3677
|
const FinalizedMoneyEvidenceCommonSchema = Schema.Struct({
|
|
@@ -3588,7 +3741,7 @@ const FinalizedCommitmentCancelEvidenceSchema = Schema.Struct({
|
|
|
3588
3741
|
vestedUnclaimed: WeiAmountSchema$1,
|
|
3589
3742
|
unvestedReturned: WeiAmountSchema$1,
|
|
3590
3743
|
documentHash: NonzeroDocumentHashSchema,
|
|
3591
|
-
transfer: Schema.NullOr(
|
|
3744
|
+
transfer: Schema.NullOr(TransferEvidenceSchema)
|
|
3592
3745
|
});
|
|
3593
3746
|
const FinalizedCommitmentRedirectEvidenceSchema = Schema.Struct({
|
|
3594
3747
|
...FinalizedMoneyEvidenceCommonSchema.fields,
|
|
@@ -3612,7 +3765,7 @@ const FinalizedMoneyEvidenceSchema = Schema.Union([
|
|
|
3612
3765
|
Schema.Union([
|
|
3613
3766
|
Schema.Struct({
|
|
3614
3767
|
status: Schema.Literal("pending"),
|
|
3615
|
-
reason: Schema.
|
|
3768
|
+
reason: Schema.Literal("receipt_missing"),
|
|
3616
3769
|
receipt: Schema.optional(ReceiptRefSchema)
|
|
3617
3770
|
}),
|
|
3618
3771
|
Schema.Struct({
|
|
@@ -4059,6 +4212,21 @@ Schema.Struct({
|
|
|
4059
4212
|
tone: Schema.String,
|
|
4060
4213
|
members: Schema.Array(PayrollGroupMemberSchema)
|
|
4061
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
|
+
});
|
|
4062
4230
|
`
|
|
4063
4231
|
.capxul-doc{--ink:#1d1d1f;--muted:#6e6e73;--line:#e7e7ea;--accent:#0a7d4b;--bg:#fff;
|
|
4064
4232
|
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif;
|
|
@@ -5968,23 +6136,7 @@ function reportProvisioningTelemetryFailure(kind, smartAccount, cause) {
|
|
|
5968
6136
|
function isProvisioningTelemetryDebugEnabled() {
|
|
5969
6137
|
return globalThis.process?.env?.CAPXUL_DEBUG_TELEMETRY === "1";
|
|
5970
6138
|
}
|
|
5971
|
-
|
|
5972
|
-
//#region ../../packages/sdk/src/telemetry/get-failure-mode.ts
|
|
5973
|
-
/**
|
|
5974
|
-
* The five canonical {@link FailureMode} members, for runtime membership checks.
|
|
5975
|
-
* Single source of truth — tests assert against this exact set so the taxonomy
|
|
5976
|
-
* and its guard can never drift apart.
|
|
5977
|
-
*/
|
|
5978
|
-
const FAILURE_MODES = new Set([
|
|
5979
|
-
"auth-origin-mismatch",
|
|
5980
|
-
"stale-openfort-cache",
|
|
5981
|
-
"app-env-allowlist",
|
|
5982
|
-
"no-secure-context",
|
|
5983
|
-
"unknown"
|
|
5984
|
-
]);
|
|
5985
|
-
function isFailureMode(value) {
|
|
5986
|
-
return typeof value === "string" && FAILURE_MODES.has(value);
|
|
5987
|
-
}
|
|
6139
|
+
new Set(FAILURE_MODES$1);
|
|
5988
6140
|
/**
|
|
5989
6141
|
* Extract the structured {@link FailureMode} from a CapxulError.
|
|
5990
6142
|
*
|
|
@@ -6976,6 +7128,697 @@ function convexToJson(value) {
|
|
|
6976
7128
|
return convexToJsonInternal(value, value, "", false);
|
|
6977
7129
|
}
|
|
6978
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
|
|
6979
7822
|
//#region ../../node_modules/.pnpm/convex@1.39.1_react@19.2.7/node_modules/convex/dist/esm/values/errors.js
|
|
6980
7823
|
var __defProp$11 = Object.defineProperty;
|
|
6981
7824
|
var __defNormalProp$11 = (obj, key, value) => key in obj ? __defProp$11(obj, key, {
|
|
@@ -7697,6 +8540,344 @@ const moneyExecutionContract = {
|
|
|
7697
8540
|
submitPaymentCommandExecution: makeFunctionReference(CAPXUL_FUNCTIONS["moneyExecution/paymentCommandActions"].submitPaymentCommandExecution)
|
|
7698
8541
|
};
|
|
7699
8542
|
//#endregion
|
|
8543
|
+
//#region ../../packages/sdk/package.json
|
|
8544
|
+
var version = "2.6.1";
|
|
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
|
|
7700
8881
|
//#region ../../packages/sdk/src/domain/money/to-wei.ts
|
|
7701
8882
|
/**
|
|
7702
8883
|
* Lower consumer `Money` into an on-chain integer string for guarded writes.
|
|
@@ -7736,16 +8917,22 @@ function emitFaucetRequested(telemetry, input) {
|
|
|
7736
8917
|
}
|
|
7737
8918
|
});
|
|
7738
8919
|
}
|
|
7739
|
-
function emitFaucetFailed(telemetry,
|
|
8920
|
+
function emitFaucetFailed(telemetry, error) {
|
|
7740
8921
|
return emitMoneyTelemetry(telemetry, {
|
|
7741
8922
|
name: "faucet_failed",
|
|
7742
|
-
props: {
|
|
8923
|
+
props: {
|
|
8924
|
+
...failureDetail(error),
|
|
8925
|
+
reason: error.code
|
|
8926
|
+
}
|
|
7743
8927
|
});
|
|
7744
8928
|
}
|
|
7745
|
-
function emitAccountBalanceFailed(telemetry,
|
|
8929
|
+
function emitAccountBalanceFailed(telemetry, error) {
|
|
7746
8930
|
return emitMoneyTelemetry(telemetry, {
|
|
7747
8931
|
name: "account_balance_failed",
|
|
7748
|
-
props: {
|
|
8932
|
+
props: {
|
|
8933
|
+
...failureDetail(error),
|
|
8934
|
+
reason: error.code
|
|
8935
|
+
}
|
|
7749
8936
|
});
|
|
7750
8937
|
}
|
|
7751
8938
|
function emitDepositInitiated(telemetry) {
|
|
@@ -8929,9 +10116,6 @@ async function recoverRawDigestSigner(input) {
|
|
|
8929
10116
|
}
|
|
8930
10117
|
}
|
|
8931
10118
|
//#endregion
|
|
8932
|
-
//#region ../../packages/sdk/package.json
|
|
8933
|
-
var version = "2.5.5";
|
|
8934
|
-
//#endregion
|
|
8935
10119
|
//#region ../../packages/observability/src/engineering.ts
|
|
8936
10120
|
const ENGINEERING_CAPXUL_ENVS = [
|
|
8937
10121
|
"development",
|
|
@@ -9061,11 +10245,11 @@ function fromResult(operation, run) {
|
|
|
9061
10245
|
})
|
|
9062
10246
|
}).pipe(Effect.flatMap((result) => result.ok ? Effect.succeed(result.value) : Effect.fail(new AuthClientError({
|
|
9063
10247
|
operation,
|
|
9064
|
-
kind: errorKind
|
|
10248
|
+
kind: errorKind(result.error),
|
|
9065
10249
|
cause: result.error
|
|
9066
10250
|
}))));
|
|
9067
10251
|
}
|
|
9068
|
-
function errorKind
|
|
10252
|
+
function errorKind(error) {
|
|
9069
10253
|
if (error.code === "CANCELLED") return "cancelled";
|
|
9070
10254
|
if (error.code === "NETWORK_ERROR") return "network";
|
|
9071
10255
|
if (error.code === "INVALID_INPUT" || error.code === "OTP_EXPIRED") return "validation";
|
|
@@ -9859,7 +11043,7 @@ function isTransientBootstrapFailure(error) {
|
|
|
9859
11043
|
const status = error.details?.httpStatus;
|
|
9860
11044
|
return typeof status === "number" && isTransientHttpStatus(status);
|
|
9861
11045
|
}
|
|
9862
|
-
async function safeText(res) {
|
|
11046
|
+
async function safeText$1(res) {
|
|
9863
11047
|
try {
|
|
9864
11048
|
return await res.text();
|
|
9865
11049
|
} catch {
|
|
@@ -9934,7 +11118,7 @@ var HttpBootstrapAdapter = class {
|
|
|
9934
11118
|
return bootstrapErrorFromCapxul("malformedBody", Errors.providerError("convex", "bootstrap", cause instanceof Error ? cause : new Error(String(cause))));
|
|
9935
11119
|
}
|
|
9936
11120
|
});
|
|
9937
|
-
return Effect.promise(() => safeText(res)).pipe(Effect.flatMap((body) => {
|
|
11121
|
+
return Effect.promise(() => safeText$1(res)).pipe(Effect.flatMap((body) => {
|
|
9938
11122
|
if (res.status === 401 || body.startsWith("NOT_AUTHENTICATED")) return Effect.fail(bootstrapErrorFromCapxul("notAuthenticated", Errors.notAuthenticated()));
|
|
9939
11123
|
if (res.status === 400 || body.startsWith("INVALID_INPUT")) return Effect.fail(bootstrapErrorFromCapxul("invalidInput", Errors.invalidInput("publishableKey", "rejected by bootstrap")));
|
|
9940
11124
|
const responseBody = body.slice(0, 300);
|
|
@@ -13876,6 +15060,41 @@ const TelemetryEnvelopeProps = {
|
|
|
13876
15060
|
correlation_id: OptionalString,
|
|
13877
15061
|
sdk_version: OptionalString
|
|
13878
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
|
+
}
|
|
13879
15098
|
const AuthOtpRequestedProps = Schema.Struct({
|
|
13880
15099
|
...TelemetryEnvelopeProps,
|
|
13881
15100
|
email: Schema.optional(PII),
|
|
@@ -13899,6 +15118,7 @@ const AuthVerifiedProps = Schema.Struct({
|
|
|
13899
15118
|
});
|
|
13900
15119
|
const AuthFailedProps = Schema.Struct({
|
|
13901
15120
|
...TelemetryEnvelopeProps,
|
|
15121
|
+
...ChainCauseTelemetryProps,
|
|
13902
15122
|
email: Schema.optional(PII),
|
|
13903
15123
|
auth_type: OptionalString,
|
|
13904
15124
|
reason: OptionalString
|
|
@@ -13928,6 +15148,7 @@ const BootstrapResolvedProps = Schema.Struct({
|
|
|
13928
15148
|
});
|
|
13929
15149
|
const BootstrapFailedProps = Schema.Struct({
|
|
13930
15150
|
...TelemetryEnvelopeProps,
|
|
15151
|
+
...ChainCauseTelemetryProps,
|
|
13931
15152
|
applicationId: OptionalAppId,
|
|
13932
15153
|
durationMs: OptionalDurationMs,
|
|
13933
15154
|
origin: OptionalString,
|
|
@@ -13942,6 +15163,7 @@ const AccountBalanceReadProps = Schema.Struct({
|
|
|
13942
15163
|
});
|
|
13943
15164
|
const AccountBalanceFailedProps = Schema.Struct({
|
|
13944
15165
|
...TelemetryEnvelopeProps,
|
|
15166
|
+
...ChainCauseTelemetryProps,
|
|
13945
15167
|
reason: OptionalString
|
|
13946
15168
|
});
|
|
13947
15169
|
const FaucetRequestedProps = Schema.Struct({
|
|
@@ -13958,29 +15180,45 @@ const FaucetConfirmedProps = Schema.Struct({
|
|
|
13958
15180
|
});
|
|
13959
15181
|
const FaucetFailedProps = Schema.Struct({
|
|
13960
15182
|
...TelemetryEnvelopeProps,
|
|
15183
|
+
...ChainCauseTelemetryProps,
|
|
13961
15184
|
reason: OptionalString
|
|
13962
15185
|
});
|
|
13963
|
-
const
|
|
15186
|
+
const ChainServiceSchema = Schema.Literals(["aa-gateway", "backend"]);
|
|
15187
|
+
const ChainUpstreamFallbackProps = Schema.Struct({
|
|
13964
15188
|
...TelemetryEnvelopeProps,
|
|
15189
|
+
service: ChainServiceSchema,
|
|
13965
15190
|
method: Schema.String,
|
|
13966
|
-
from_upstream:
|
|
13967
|
-
|
|
13968
|
-
|
|
13969
|
-
|
|
13970
|
-
|
|
13971
|
-
|
|
13972
|
-
|
|
13973
|
-
|
|
13974
|
-
|
|
13975
|
-
|
|
13976
|
-
|
|
13977
|
-
|
|
13978
|
-
|
|
13979
|
-
|
|
13980
|
-
|
|
13981
|
-
|
|
13982
|
-
|
|
13983
|
-
|
|
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
|
|
13984
15222
|
});
|
|
13985
15223
|
const ORG_ID_TELEMETRY_RE = /^org_[0-9A-Za-z]+$/;
|
|
13986
15224
|
const OrgIdTelemetrySchema = Schema.String.pipe(Schema.refine((value) => ORG_ID_TELEMETRY_RE.test(value), { message: "must be org_ plus an alphanumeric id" }));
|
|
@@ -14006,6 +15244,7 @@ const MemberActivationReadyProps = Schema.Struct({
|
|
|
14006
15244
|
});
|
|
14007
15245
|
const MemberActivationFailedProps = Schema.Struct({
|
|
14008
15246
|
...TelemetryEnvelopeProps,
|
|
15247
|
+
...ChainCauseTelemetryProps,
|
|
14009
15248
|
$insert_id: Schema.String,
|
|
14010
15249
|
stage: OnboardingStageSchema,
|
|
14011
15250
|
error_code: Schema.String,
|
|
@@ -14026,6 +15265,7 @@ const OrganizationCreationReadyProps = Schema.Struct({
|
|
|
14026
15265
|
});
|
|
14027
15266
|
const OrganizationCreationFailedProps = Schema.Struct({
|
|
14028
15267
|
...TelemetryEnvelopeProps,
|
|
15268
|
+
...ChainCauseTelemetryProps,
|
|
14029
15269
|
$insert_id: Schema.String,
|
|
14030
15270
|
organization_id: OrgIdTelemetrySchema,
|
|
14031
15271
|
attempt_number: AttemptNumberSchema,
|
|
@@ -14105,6 +15345,7 @@ const OrgCreatedProps = Schema.Struct({
|
|
|
14105
15345
|
});
|
|
14106
15346
|
const OrgCreateFailedProps = Schema.Struct({
|
|
14107
15347
|
...TelemetryEnvelopeProps,
|
|
15348
|
+
...ChainCauseTelemetryProps,
|
|
14108
15349
|
org_id: OptionalOrgId,
|
|
14109
15350
|
reason: OptionalString
|
|
14110
15351
|
});
|
|
@@ -14142,10 +15383,18 @@ const PaymentSettledL2Props = Schema.Struct({
|
|
|
14142
15383
|
});
|
|
14143
15384
|
const PaymentFailedL2Props = Schema.Struct({
|
|
14144
15385
|
...TelemetryEnvelopeProps,
|
|
15386
|
+
...ChainCauseTelemetryProps,
|
|
14145
15387
|
kind: Schema.String,
|
|
14146
15388
|
payment_id: Schema.String,
|
|
14147
15389
|
reason_code: Schema.String
|
|
14148
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
|
+
});
|
|
14149
15398
|
const DepositInitiatedProps = Schema.Struct({ ...TelemetryEnvelopeProps });
|
|
14150
15399
|
const DepositSettledProps = Schema.Struct({
|
|
14151
15400
|
...TelemetryEnvelopeProps,
|
|
@@ -14184,182 +15433,200 @@ const MovementScanIncidentProps = Schema.Struct({
|
|
|
14184
15433
|
incident_kind: Schema.String,
|
|
14185
15434
|
anchor_block_number: Schema.Number
|
|
14186
15435
|
});
|
|
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
|
-
|
|
14345
|
-
|
|
14346
|
-
|
|
14347
|
-
|
|
14348
|
-
|
|
14349
|
-
|
|
14350
|
-
|
|
14351
|
-
|
|
14352
|
-
|
|
14353
|
-
|
|
14354
|
-
|
|
14355
|
-
|
|
14356
|
-
|
|
14357
|
-
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
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
|
+
};
|
|
14363
15630
|
function redactTelemetryProps(name, props, options = {}) {
|
|
14364
15631
|
if (props === void 0) return void 0;
|
|
14365
15632
|
const clone = cloneProps$1(props);
|
|
@@ -14760,7 +16027,7 @@ const isBoolean = (thing) => thing === true || thing === false;
|
|
|
14760
16027
|
*
|
|
14761
16028
|
* @returns {boolean} True if value is a plain Object, otherwise false
|
|
14762
16029
|
*/
|
|
14763
|
-
const isPlainObject
|
|
16030
|
+
const isPlainObject = (val) => {
|
|
14764
16031
|
if (kindOf(val) !== "object") return false;
|
|
14765
16032
|
const prototype = getPrototypeOf(val);
|
|
14766
16033
|
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
|
|
@@ -14975,8 +16242,8 @@ function merge(...objs) {
|
|
|
14975
16242
|
if (key === "__proto__" || key === "constructor" || key === "prototype") return;
|
|
14976
16243
|
const targetKey = caseless && typeof key === "string" && findKey(result, key) || key;
|
|
14977
16244
|
const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : void 0;
|
|
14978
|
-
if (isPlainObject
|
|
14979
|
-
else if (isPlainObject
|
|
16245
|
+
if (isPlainObject(existing) && isPlainObject(val)) result[targetKey] = merge(existing, val);
|
|
16246
|
+
else if (isPlainObject(val)) result[targetKey] = merge({}, val);
|
|
14980
16247
|
else if (isArray(val)) result[targetKey] = val.slice();
|
|
14981
16248
|
else if (!skipUndefined || !isUndefined(val)) result[targetKey] = val;
|
|
14982
16249
|
};
|
|
@@ -15322,7 +16589,7 @@ var utils_default = {
|
|
|
15322
16589
|
isNumber,
|
|
15323
16590
|
isBoolean,
|
|
15324
16591
|
isObject,
|
|
15325
|
-
isPlainObject
|
|
16592
|
+
isPlainObject,
|
|
15326
16593
|
isEmptyObject,
|
|
15327
16594
|
isReadableStream,
|
|
15328
16595
|
isRequest,
|
|
@@ -37597,7 +38864,7 @@ function normalizeConfirmationBackoff(override) {
|
|
|
37597
38864
|
}
|
|
37598
38865
|
const failureOf = (error) => {
|
|
37599
38866
|
if (error instanceof CapxulError) {
|
|
37600
|
-
const mode = error.details?.failure_mode;
|
|
38867
|
+
const mode = error.mode ?? error.details?.failure_mode;
|
|
37601
38868
|
return {
|
|
37602
38869
|
code: error.code,
|
|
37603
38870
|
message: error.message,
|
|
@@ -37720,7 +38987,7 @@ const runOrgStep = (setup, orgId, step, controls, retryDelayMs) => {
|
|
|
37720
38987
|
})];
|
|
37721
38988
|
return resultEffect(name, invoke);
|
|
37722
38989
|
};
|
|
37723
|
-
const orgLane = (setup, start, send, controls, backoff) => Effect.gen(function* () {
|
|
38990
|
+
const orgLane = (setup, start, send, controls, backoff, telemetry) => Effect.gen(function* () {
|
|
37724
38991
|
let orgId;
|
|
37725
38992
|
let lifecycle;
|
|
37726
38993
|
if (start.kind === "create") {
|
|
@@ -37803,6 +39070,15 @@ const orgLane = (setup, start, send, controls, backoff) => Effect.gen(function*
|
|
|
37803
39070
|
if (lifecycle.at === "confirmingBootstrap" && lifecycle.retryable && retries < backoff.maxRetries) {
|
|
37804
39071
|
const delayMs = Math.min(backoff.initialDelayMs * 2 ** retries, backoff.maxDelayMs);
|
|
37805
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));
|
|
37806
39082
|
yield* Effect.sleep(Duration.millis(delayMs));
|
|
37807
39083
|
const reset = yield* Effect.result(resultEffect("organization-setup.retry", (parent) => setup.retry({
|
|
37808
39084
|
orgId,
|
|
@@ -38016,7 +39292,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
|
|
|
38016
39292
|
run: (send, controls) => orgLane(input.organizationSetup, {
|
|
38017
39293
|
kind: "create",
|
|
38018
39294
|
draft: event.draft
|
|
38019
|
-
}, send, controls, backoff)
|
|
39295
|
+
}, send, controls, backoff, input.telemetry)
|
|
38020
39296
|
};
|
|
38021
39297
|
case "AttachOrganization": return input.organizationSetup === void 0 || org?.at !== "loading" ? void 0 : {
|
|
38022
39298
|
slot: IDENTITY_SLOT.org,
|
|
@@ -38024,7 +39300,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
|
|
|
38024
39300
|
run: (send, controls) => orgLane(input.organizationSetup, {
|
|
38025
39301
|
kind: "attach",
|
|
38026
39302
|
orgId: org.orgId
|
|
38027
|
-
}, send, controls, backoff)
|
|
39303
|
+
}, send, controls, backoff, input.telemetry)
|
|
38028
39304
|
};
|
|
38029
39305
|
case "RetryOrganization": return input.organizationSetup === void 0 || org?.at !== "settingUp" ? void 0 : {
|
|
38030
39306
|
slot: IDENTITY_SLOT.org,
|
|
@@ -38032,7 +39308,7 @@ const identitySpec = (input, sessionStore = { current: null }) => {
|
|
|
38032
39308
|
run: (send, controls) => orgLane(input.organizationSetup, {
|
|
38033
39309
|
kind: "retry",
|
|
38034
39310
|
orgId: org.orgId
|
|
38035
|
-
}, send, controls, backoff)
|
|
39311
|
+
}, send, controls, backoff, input.telemetry)
|
|
38036
39312
|
};
|
|
38037
39313
|
default: return;
|
|
38038
39314
|
}
|
|
@@ -38439,7 +39715,7 @@ function accountsDepsLayer(deps) {
|
|
|
38439
39715
|
}
|
|
38440
39716
|
const readAccountProgram = Effect.gen(function* () {
|
|
38441
39717
|
const deps = yield* AccountsDepsTag;
|
|
38442
|
-
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));
|
|
38443
39719
|
});
|
|
38444
39720
|
function fundFromFaucetProgram(amount) {
|
|
38445
39721
|
return Effect.gen(function* () {
|
|
@@ -38451,7 +39727,7 @@ function fundFromFaucetProgram(amount) {
|
|
|
38451
39727
|
return yield* deps.accountReadPort.fundFromFaucet({
|
|
38452
39728
|
chainId: deps.chainId,
|
|
38453
39729
|
amount
|
|
38454
|
-
}).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));
|
|
38455
39731
|
});
|
|
38456
39732
|
}
|
|
38457
39733
|
//#endregion
|
|
@@ -38839,6 +40115,7 @@ const payrollContract = {
|
|
|
38839
40115
|
authorizeRun: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/actions"].authorizeRun),
|
|
38840
40116
|
runs: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].runs),
|
|
38841
40117
|
groups: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].groups),
|
|
40118
|
+
terms: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].terms),
|
|
38842
40119
|
saveGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].saveGroup),
|
|
38843
40120
|
removeGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].removeGroup)
|
|
38844
40121
|
};
|
|
@@ -38992,6 +40269,7 @@ function makePayrollMethods(deps, orgId) {
|
|
|
38992
40269
|
};
|
|
38993
40270
|
}
|
|
38994
40271
|
},
|
|
40272
|
+
terms: (options) => runIfActive(options?.signal, "payroll.terms", () => deps.convexCall.query(payrollContract.terms, { orgId })),
|
|
38995
40273
|
groups: {
|
|
38996
40274
|
list: (options) => runIfActive(options?.signal, "payroll.groups.list", () => Effect.map(deps.convexCall.query(payrollContract.groups, { orgId }), (groups) => groups.map(toPayrollGroup))),
|
|
38997
40275
|
save: (input, options) => runIfActive(options?.signal, "payroll.groups.save", () => Effect.map(deps.convexCall.mutation(payrollContract.saveGroup, {
|
|
@@ -39017,6 +40295,7 @@ function makeUnavailablePayrollMethods() {
|
|
|
39017
40295
|
return {
|
|
39018
40296
|
runs: payrollUnavailable,
|
|
39019
40297
|
authorizeRun: payrollUnavailable,
|
|
40298
|
+
terms: payrollUnavailable,
|
|
39020
40299
|
groups: {
|
|
39021
40300
|
list: payrollUnavailable,
|
|
39022
40301
|
save: payrollUnavailable,
|
|
@@ -39090,10 +40369,13 @@ function emitOrgCreated(telemetry, input) {
|
|
|
39090
40369
|
}
|
|
39091
40370
|
});
|
|
39092
40371
|
}
|
|
39093
|
-
function emitOrgCreateFailed(telemetry,
|
|
40372
|
+
function emitOrgCreateFailed(telemetry, error) {
|
|
39094
40373
|
return emitOrgTelemetry(telemetry, {
|
|
39095
40374
|
name: "org_create_failed",
|
|
39096
|
-
props: {
|
|
40375
|
+
props: {
|
|
40376
|
+
...failureDetail(error),
|
|
40377
|
+
reason: error.code
|
|
40378
|
+
}
|
|
39097
40379
|
});
|
|
39098
40380
|
}
|
|
39099
40381
|
function emitOrgInviteSent(telemetry, input) {
|
|
@@ -39197,7 +40479,7 @@ function createOrgProgram(input) {
|
|
|
39197
40479
|
const org = hermeticOrgView(input);
|
|
39198
40480
|
yield* emitCreationFunnelTail(deps.telemetry, org, chainId);
|
|
39199
40481
|
return org;
|
|
39200
|
-
}).pipe(Effect.tapError((error) => Effect.promise(() => emitOrgCreateFailed(deps.telemetry, error
|
|
40482
|
+
}).pipe(Effect.tapError((error) => Effect.promise(() => emitOrgCreateFailed(deps.telemetry, error))));
|
|
39201
40483
|
});
|
|
39202
40484
|
}
|
|
39203
40485
|
/** Emit the remaining `org_creation` funnel steps once the org is built. */
|
|
@@ -39792,313 +41074,6 @@ function detectAuthCacheAdapter() {
|
|
|
39792
41074
|
return new InMemoryAuthCacheAdapter();
|
|
39793
41075
|
}
|
|
39794
41076
|
//#endregion
|
|
39795
|
-
//#region ../../packages/sdk/src/telemetry/capture-exception.ts
|
|
39796
|
-
/** Fixed, leak-safe message — the raw error message may carry PII and never ships. */
|
|
39797
|
-
const EXCEPTION_MESSAGE = "Capxul SDK operation failed";
|
|
39798
|
-
//#endregion
|
|
39799
|
-
//#region ../../packages/sdk/src/observation.ts
|
|
39800
|
-
const SDK_VERSION$1 = version;
|
|
39801
|
-
/** @internal Observe public result methods at the assembled Core SDK boundary. */
|
|
39802
|
-
function observeSdkClient(client, adapter, snapshot) {
|
|
39803
|
-
if (adapter === void 0) return client;
|
|
39804
|
-
const objectProxies = /* @__PURE__ */ new WeakMap();
|
|
39805
|
-
const proxyTargets = /* @__PURE__ */ new WeakMap();
|
|
39806
|
-
const functionWrappers = /* @__PURE__ */ new WeakMap();
|
|
39807
|
-
const wrapObject = (target, path, internal = false) => {
|
|
39808
|
-
const cacheKey = `${internal ? "internal" : "public"}:${path.join(".")}`;
|
|
39809
|
-
let targetProxies = objectProxies.get(target);
|
|
39810
|
-
const cached = targetProxies?.get(cacheKey);
|
|
39811
|
-
if (cached !== void 0) return cached;
|
|
39812
|
-
const proxy = new Proxy(target, { get(currentTarget, property, receiver) {
|
|
39813
|
-
const value = Reflect.get(currentTarget, property, receiver);
|
|
39814
|
-
if (typeof property !== "string") return value;
|
|
39815
|
-
if (path.length === 0 && property === "_internal" && isPlainObject(value)) return wrapObject(value, ["_internal"], true);
|
|
39816
|
-
if (internal && property !== "accounts") return value;
|
|
39817
|
-
return wrapValue(value, [...path, property], currentTarget);
|
|
39818
|
-
} });
|
|
39819
|
-
proxyTargets.set(proxy, target);
|
|
39820
|
-
if (targetProxies === void 0) {
|
|
39821
|
-
targetProxies = /* @__PURE__ */ new Map();
|
|
39822
|
-
objectProxies.set(target, targetProxies);
|
|
39823
|
-
}
|
|
39824
|
-
targetProxies.set(cacheKey, proxy);
|
|
39825
|
-
return proxy;
|
|
39826
|
-
};
|
|
39827
|
-
const wrapValue = (value, path, owner) => {
|
|
39828
|
-
if (typeof value === "function") {
|
|
39829
|
-
const callable = value;
|
|
39830
|
-
const operation = path.join(".");
|
|
39831
|
-
let ownerWrappers = functionWrappers.get(owner);
|
|
39832
|
-
if (ownerWrappers === void 0) {
|
|
39833
|
-
ownerWrappers = /* @__PURE__ */ new Map();
|
|
39834
|
-
functionWrappers.set(owner, ownerWrappers);
|
|
39835
|
-
}
|
|
39836
|
-
const cached = ownerWrappers.get(operation);
|
|
39837
|
-
if (cached !== void 0) return cached;
|
|
39838
|
-
let wrapped;
|
|
39839
|
-
wrapped = new Proxy(callable, {
|
|
39840
|
-
apply(currentTarget, thisArg, args) {
|
|
39841
|
-
const invocation = resolveInvocationSnapshot(adapter, snapshot);
|
|
39842
|
-
let output;
|
|
39843
|
-
try {
|
|
39844
|
-
output = Reflect.apply(currentTarget, unwrapReceiver(thisArg), args);
|
|
39845
|
-
} catch (cause) {
|
|
39846
|
-
report(adapter, "exception", operation, cause, invocation);
|
|
39847
|
-
throw cause;
|
|
39848
|
-
}
|
|
39849
|
-
if (isPromiseLike(output)) return Promise.resolve(output).then((result) => processOutput(result, path, invocation), (cause) => {
|
|
39850
|
-
report(adapter, "exception", operation, cause, invocation);
|
|
39851
|
-
throw cause;
|
|
39852
|
-
});
|
|
39853
|
-
return processOutput(output, path, invocation);
|
|
39854
|
-
},
|
|
39855
|
-
get(currentTarget, property) {
|
|
39856
|
-
if (property === "bind") return Function.prototype.bind.bind(wrapped);
|
|
39857
|
-
if (property === "call") return Function.prototype.call.bind(wrapped);
|
|
39858
|
-
if (property === "apply") return Function.prototype.apply.bind(wrapped);
|
|
39859
|
-
const attached = Reflect.get(currentTarget, property, currentTarget);
|
|
39860
|
-
if (typeof property !== "string") return attached;
|
|
39861
|
-
return wrapValue(attached, [...path, property], currentTarget);
|
|
39862
|
-
}
|
|
39863
|
-
});
|
|
39864
|
-
proxyTargets.set(wrapped, callable);
|
|
39865
|
-
ownerWrappers.set(operation, wrapped);
|
|
39866
|
-
return wrapped;
|
|
39867
|
-
}
|
|
39868
|
-
return isPlainObject(value) ? wrapObject(value, path) : value;
|
|
39869
|
-
};
|
|
39870
|
-
const processOutput = (output, path, invocation) => {
|
|
39871
|
-
if (isFailedResult(output)) {
|
|
39872
|
-
report(adapter, "operation", path.join("."), output.error, invocation);
|
|
39873
|
-
return output;
|
|
39874
|
-
}
|
|
39875
|
-
if (isCapxulResult(output)) return output;
|
|
39876
|
-
return isPlainObject(output) ? wrapObject(output, path) : output;
|
|
39877
|
-
};
|
|
39878
|
-
return wrapObject(client, []);
|
|
39879
|
-
function unwrapReceiver(receiver) {
|
|
39880
|
-
return (typeof receiver === "object" || typeof receiver === "function") && receiver !== null ? proxyTargets.get(receiver) ?? receiver : receiver;
|
|
39881
|
-
}
|
|
39882
|
-
}
|
|
39883
|
-
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
39884
|
-
function observeFailedResult(result, adapter, operation, origin) {
|
|
39885
|
-
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterSnapshot(adapter), origin);
|
|
39886
|
-
return result;
|
|
39887
|
-
}
|
|
39888
|
-
/**
|
|
39889
|
-
* One failure, one event. The identity machine reports a failed transition
|
|
39890
|
-
* first; when the same `CapxulError` then surfaces as a public method result
|
|
39891
|
-
* (directly or down its `cause` chain), the boundary drops that second report.
|
|
39892
|
-
* Only machine-reported errors are remembered, so a caller that reuses one
|
|
39893
|
-
* error object across unrelated public methods still sees every report.
|
|
39894
|
-
*/
|
|
39895
|
-
const machineReportedCauses = /* @__PURE__ */ new WeakSet();
|
|
39896
|
-
function reportedByMachine(cause) {
|
|
39897
|
-
let link = cause;
|
|
39898
|
-
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
39899
|
-
if (machineReportedCauses.has(link)) return true;
|
|
39900
|
-
link = link.cause;
|
|
39901
|
-
}
|
|
39902
|
-
return false;
|
|
39903
|
-
}
|
|
39904
|
-
function report(adapter, kind, operation, cause, invocation, origin) {
|
|
39905
|
-
if (origin === "machine") {
|
|
39906
|
-
let link = cause;
|
|
39907
|
-
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
39908
|
-
machineReportedCauses.add(link);
|
|
39909
|
-
link = link.cause;
|
|
39910
|
-
}
|
|
39911
|
-
} else if (reportedByMachine(cause)) return;
|
|
39912
|
-
const operationName = normalizeOperation(operation);
|
|
39913
|
-
const kindName = normalizeErrorKind(errorKind(cause));
|
|
39914
|
-
const context = sanitizeObservationContext({
|
|
39915
|
-
...invocation.context,
|
|
39916
|
-
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
39917
|
-
});
|
|
39918
|
-
const detail = failureDetail(cause);
|
|
39919
|
-
const evidence = failureEvidence(cause);
|
|
39920
|
-
const failure = markFailureInvocationSnapshot({
|
|
39921
|
-
exception: syntheticException(operationName, kindName, evidence.message, evidence.stack),
|
|
39922
|
-
sdkVersion: SDK_VERSION$1,
|
|
39923
|
-
operation: operationName,
|
|
39924
|
-
errorKind: kindName,
|
|
39925
|
-
...context === void 0 ? {} : { context },
|
|
39926
|
-
...detail === void 0 ? {} : { detail },
|
|
39927
|
-
...evidence
|
|
39928
|
-
}, {
|
|
39929
|
-
active: invocation.active,
|
|
39930
|
-
...context === void 0 ? {} : { context }
|
|
39931
|
-
});
|
|
39932
|
-
try {
|
|
39933
|
-
ignoreDeliveryFailure(kind === "operation" ? adapter.captureOperationFailure(failure) : adapter.captureException(failure));
|
|
39934
|
-
} catch {}
|
|
39935
|
-
}
|
|
39936
|
-
function resolveInvocationSnapshot(adapter, snapshot) {
|
|
39937
|
-
if (snapshot !== void 0) try {
|
|
39938
|
-
const captured = snapshot();
|
|
39939
|
-
if (captured !== void 0) return captured;
|
|
39940
|
-
} catch {}
|
|
39941
|
-
return resolveAdapterSnapshot(adapter);
|
|
39942
|
-
}
|
|
39943
|
-
function resolveAdapterSnapshot(adapter) {
|
|
39944
|
-
const context = resolveAdapterContext(adapter);
|
|
39945
|
-
return context === void 0 ? { active: false } : {
|
|
39946
|
-
active: true,
|
|
39947
|
-
context
|
|
39948
|
-
};
|
|
39949
|
-
}
|
|
39950
|
-
function resolveAdapterContext(adapter) {
|
|
39951
|
-
try {
|
|
39952
|
-
return adapter.resolveContext?.();
|
|
39953
|
-
} catch {
|
|
39954
|
-
return;
|
|
39955
|
-
}
|
|
39956
|
-
}
|
|
39957
|
-
function ignoreDeliveryFailure(delivery) {
|
|
39958
|
-
if (!isPromiseLike(delivery)) return;
|
|
39959
|
-
try {
|
|
39960
|
-
Promise.resolve(delivery).catch(() => void 0);
|
|
39961
|
-
} catch {}
|
|
39962
|
-
}
|
|
39963
|
-
const MAX_EVIDENCE_TEXT = 4e3;
|
|
39964
|
-
const MAX_CAUSE_DEPTH = 8;
|
|
39965
|
-
function evidenceText(value) {
|
|
39966
|
-
if (typeof value !== "string" || value.length === 0) return void 0;
|
|
39967
|
-
return redactSecrets(value).slice(0, MAX_EVIDENCE_TEXT);
|
|
39968
|
-
}
|
|
39969
|
-
/** A field whose NAME says credential is masked whatever its value looks like. */
|
|
39970
|
-
const CREDENTIAL_FIELD_NAME = /(?:otp|pass(?:word|wd|phrase)?|token|secret|credential|api[_-]?key|private[_-]?key|authorization|cookie|session)/iu;
|
|
39971
|
-
/** Copy a details object into a JSON-safe shape with every string masked. */
|
|
39972
|
-
function evidenceValue(value, depth = 0) {
|
|
39973
|
-
if (typeof value === "string") return evidenceText(value);
|
|
39974
|
-
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
39975
|
-
if (typeof value === "bigint") return value.toString();
|
|
39976
|
-
if (value instanceof Error) return evidenceText(value.message);
|
|
39977
|
-
if (depth >= 4 || typeof value !== "object") return void 0;
|
|
39978
|
-
if (Array.isArray(value)) return value.slice(0, 50).map((item) => evidenceValue(item, depth + 1));
|
|
39979
|
-
const copy = {};
|
|
39980
|
-
for (const [key, nested] of Object.entries(value)) {
|
|
39981
|
-
if (CREDENTIAL_FIELD_NAME.test(key)) {
|
|
39982
|
-
copy[key] = "[REDACTED]";
|
|
39983
|
-
continue;
|
|
39984
|
-
}
|
|
39985
|
-
const safe = evidenceValue(nested, depth + 1);
|
|
39986
|
-
if (safe !== void 0) copy[key] = safe;
|
|
39987
|
-
}
|
|
39988
|
-
return copy;
|
|
39989
|
-
}
|
|
39990
|
-
/**
|
|
39991
|
-
* @internal The evidence in PostHog property shape, for product events that
|
|
39992
|
-
* name a failure (`bootstrap_failed`). Same keys as the `$exception` event.
|
|
39993
|
-
*/
|
|
39994
|
-
function failureEvidenceProps(cause) {
|
|
39995
|
-
const evidence = failureEvidence(cause);
|
|
39996
|
-
return {
|
|
39997
|
-
...evidence.message === void 0 ? {} : { error_message: evidence.message },
|
|
39998
|
-
...evidence.details === void 0 ? {} : { error_details: evidence.details },
|
|
39999
|
-
...evidence.causeChain === void 0 ? {} : { error_cause: evidence.causeChain.join(" <- ") }
|
|
40000
|
-
};
|
|
40001
|
-
}
|
|
40002
|
-
/** The real failure, masked for secrets only. Never throws. */
|
|
40003
|
-
function failureEvidence(cause) {
|
|
40004
|
-
try {
|
|
40005
|
-
const message = cause instanceof Error ? evidenceText(cause.message) : evidenceText(cause);
|
|
40006
|
-
const stack = cause instanceof Error ? evidenceText(cause.stack) : void 0;
|
|
40007
|
-
const details = isCapxulError(cause) && typeof cause.details === "object" && cause.details !== null ? evidenceValue(cause.details) : void 0;
|
|
40008
|
-
const causeChain = [];
|
|
40009
|
-
let previous = message;
|
|
40010
|
-
let link = cause instanceof Error ? cause.cause : void 0;
|
|
40011
|
-
for (let depth = 0; depth < MAX_CAUSE_DEPTH && link !== void 0 && link !== null; depth++) {
|
|
40012
|
-
const text = link instanceof Error ? evidenceText(link.message) : evidenceText(link);
|
|
40013
|
-
if (text !== void 0 && text !== previous) {
|
|
40014
|
-
causeChain.push(text);
|
|
40015
|
-
previous = text;
|
|
40016
|
-
}
|
|
40017
|
-
link = link instanceof Error ? link.cause : void 0;
|
|
40018
|
-
}
|
|
40019
|
-
return {
|
|
40020
|
-
...message === void 0 ? {} : { message },
|
|
40021
|
-
...details === void 0 || Object.keys(details).length === 0 ? {} : { details },
|
|
40022
|
-
...causeChain.length === 0 ? {} : { causeChain },
|
|
40023
|
-
...stack === void 0 ? {} : { stack }
|
|
40024
|
-
};
|
|
40025
|
-
} catch {
|
|
40026
|
-
return {};
|
|
40027
|
-
}
|
|
40028
|
-
}
|
|
40029
|
-
function errorKind(cause) {
|
|
40030
|
-
try {
|
|
40031
|
-
if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
|
|
40032
|
-
if (cause instanceof Error) return normalizeErrorKind(cause.name);
|
|
40033
|
-
return "UnknownFailure";
|
|
40034
|
-
} catch {
|
|
40035
|
-
return "Error";
|
|
40036
|
-
}
|
|
40037
|
-
}
|
|
40038
|
-
/**
|
|
40039
|
-
* @internal Lift the enumerated discriminators off a `CapxulError` so a
|
|
40040
|
-
* boundary event says WHICH provider failed and HOW, not just `PROVIDER_ERROR`.
|
|
40041
|
-
* Shared by the failure boundary and the `bootstrap_failed` product event.
|
|
40042
|
-
*/
|
|
40043
|
-
function failureDetail(cause) {
|
|
40044
|
-
if (!isCapxulError(cause)) return void 0;
|
|
40045
|
-
const details = cause.details;
|
|
40046
|
-
if (typeof details !== "object" || details === null) return void 0;
|
|
40047
|
-
const source = details;
|
|
40048
|
-
return sanitizeFailureDetail({
|
|
40049
|
-
provider: source.provider,
|
|
40050
|
-
provider_operation: source.operation,
|
|
40051
|
-
failure_mode: source.failure_mode,
|
|
40052
|
-
reason: source.reason,
|
|
40053
|
-
http_status: source.httpStatus
|
|
40054
|
-
});
|
|
40055
|
-
}
|
|
40056
|
-
function sanitizeFailureDetail(input) {
|
|
40057
|
-
if (typeof input !== "object" || input === null) return void 0;
|
|
40058
|
-
const source = input;
|
|
40059
|
-
const detail = {};
|
|
40060
|
-
for (const key of [
|
|
40061
|
-
"provider",
|
|
40062
|
-
"provider_operation",
|
|
40063
|
-
"failure_mode",
|
|
40064
|
-
"reason"
|
|
40065
|
-
]) {
|
|
40066
|
-
const value = source[key];
|
|
40067
|
-
if (typeof value === "string" && ENUMERATED_DETAIL_RE.test(value)) detail[key] = value;
|
|
40068
|
-
}
|
|
40069
|
-
const status = source.http_status;
|
|
40070
|
-
if (typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599) detail.http_status = status;
|
|
40071
|
-
return Object.keys(detail).length === 0 ? void 0 : detail;
|
|
40072
|
-
}
|
|
40073
|
-
/** Enumerated codes only (`convex`, `no-secure-context`, `bootstrap-encode`); free text fails. */
|
|
40074
|
-
const ENUMERATED_DETAIL_RE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u;
|
|
40075
|
-
function normalizeOperation(value) {
|
|
40076
|
-
return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
|
|
40077
|
-
}
|
|
40078
|
-
function normalizeErrorKind(value) {
|
|
40079
|
-
return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
|
|
40080
|
-
}
|
|
40081
|
-
function syntheticException(operation, kind, message = EXCEPTION_MESSAGE, stack) {
|
|
40082
|
-
const error = new Error(message);
|
|
40083
|
-
error.name = kind;
|
|
40084
|
-
error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)` + (stack === void 0 ? "" : `\nCaused by: ${stack}`);
|
|
40085
|
-
return error;
|
|
40086
|
-
}
|
|
40087
|
-
function isPromiseLike(value) {
|
|
40088
|
-
return (typeof value === "object" || typeof value === "function") && value !== null && typeof value.then === "function";
|
|
40089
|
-
}
|
|
40090
|
-
function isPlainObject(value) {
|
|
40091
|
-
if (typeof value !== "object" || value === null) return false;
|
|
40092
|
-
const prototype = Object.getPrototypeOf(value);
|
|
40093
|
-
return prototype === Object.prototype || prototype === null;
|
|
40094
|
-
}
|
|
40095
|
-
function isCapxulResult(value) {
|
|
40096
|
-
return isPlainObject(value) && typeof value.ok === "boolean";
|
|
40097
|
-
}
|
|
40098
|
-
function isFailedResult(value) {
|
|
40099
|
-
return isCapxulResult(value) && value.ok === false && "error" in value;
|
|
40100
|
-
}
|
|
40101
|
-
//#endregion
|
|
40102
41077
|
//#region ../../packages/sdk/src/telemetry/from-posthog.ts
|
|
40103
41078
|
const PRODUCT_INVOCATION = Symbol("capxul.product-telemetry-invocation");
|
|
40104
41079
|
/** @internal Bind paired emit/identify/reset work to one call-start snapshot. */
|
|
@@ -40148,23 +41123,24 @@ const linkage = (record) => ({
|
|
|
40148
41123
|
...record.journey_id === void 0 ? {} : { journey_id: record.journey_id }
|
|
40149
41124
|
});
|
|
40150
41125
|
const emailDomain = (email) => email.split("@")[1]?.toLowerCase() ?? "unknown";
|
|
40151
|
-
const authFailure = (record, reason) => ({
|
|
41126
|
+
const authFailure = (record, reason, mode) => ({
|
|
40152
41127
|
name: "auth_failed",
|
|
40153
41128
|
props: {
|
|
40154
41129
|
auth_type: "otp",
|
|
40155
41130
|
reason,
|
|
41131
|
+
...mode === void 0 ? {} : { failure_mode: mode },
|
|
40156
41132
|
...linkage(record)
|
|
40157
41133
|
}
|
|
40158
41134
|
});
|
|
40159
41135
|
function mapIdentityProductObservation(record, state) {
|
|
40160
41136
|
if (record.machine !== "identity" || !IDENTITY_EVENT_TAG_SET.has(record.event)) return NONE;
|
|
40161
41137
|
if (record.outcome === "cancelled") return NONE;
|
|
40162
|
-
if (record.slot === "identity:auth" && record.outcome === "refused") return authFailure(record, record.refusal_code);
|
|
40163
|
-
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);
|
|
40164
41140
|
if (record.outcome !== "applied") return NONE;
|
|
40165
41141
|
switch (APPLIED_ACTION_BY_EVENT[record.event]) {
|
|
40166
41142
|
case "none": return NONE;
|
|
40167
|
-
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);
|
|
40168
41144
|
case "otp-requested": return state.phase !== "otp_pending" ? NONE : {
|
|
40169
41145
|
name: "auth_otp_requested",
|
|
40170
41146
|
props: {
|
|
@@ -40269,7 +41245,8 @@ function assembleCapxulClient(input) {
|
|
|
40269
41245
|
requirement: input.requirement,
|
|
40270
41246
|
...input.signer === void 0 ? {} : { signer: input.signer },
|
|
40271
41247
|
...input.organizationSetup === void 0 ? {} : { organizationSetup: input.organizationSetup },
|
|
40272
|
-
...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 }
|
|
40273
41250
|
}), scope)), observation.hostObservationSnapshot);
|
|
40274
41251
|
const unsubscribeProductTelemetry = actor.subscribeTransitions((record) => {
|
|
40275
41252
|
effectRunner.runPromise(executeIdentityProductObservation(input.ports.telemetry, record, actor.snapshot())).catch(() => {});
|
|
@@ -43349,6 +44326,526 @@ function optionalEnv(name) {
|
|
|
43349
44326
|
const value = process.env[name];
|
|
43350
44327
|
return value && value.length > 0 ? value : void 0;
|
|
43351
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
|
+
try {
|
|
44457
|
+
timeout = setTimeout(() => {
|
|
44458
|
+
controller.abort();
|
|
44459
|
+
reject(/* @__PURE__ */ new Error(`PostHog capture timed out after ${timeoutMs}ms`));
|
|
44460
|
+
}, timeoutMs);
|
|
44461
|
+
} catch {}
|
|
44462
|
+
});
|
|
44463
|
+
try {
|
|
44464
|
+
return await Promise.race([fetch(url, {
|
|
44465
|
+
...init,
|
|
44466
|
+
signal: controller.signal
|
|
44467
|
+
}), timeoutPromise]);
|
|
44468
|
+
} finally {
|
|
44469
|
+
if (timeout !== void 0) clearTimeout(timeout);
|
|
44470
|
+
}
|
|
44471
|
+
}
|
|
44472
|
+
function requirePostHogProjectToken() {
|
|
44473
|
+
for (const name of POSTHOG_PROJECT_TOKEN_ENV_KEYS) {
|
|
44474
|
+
const value = optionalEnv(name);
|
|
44475
|
+
if (value !== void 0) return value;
|
|
44476
|
+
}
|
|
44477
|
+
return requireEnvOrThrow("POSTHOG_PROJECT_TOKEN");
|
|
44478
|
+
}
|
|
44479
|
+
function normalizePostHogHost(host) {
|
|
44480
|
+
return host.replace(/\/+$/, "");
|
|
44481
|
+
}
|
|
44482
|
+
function rethrowPostHogCapture(error) {
|
|
44483
|
+
throw Errors.providerError("posthog", "capture", error);
|
|
44484
|
+
}
|
|
44485
|
+
//#endregion
|
|
44486
|
+
//#region ../../packages/backend/convex/_shared/init.ts
|
|
44487
|
+
var init_exports = /* @__PURE__ */ __exportAll({
|
|
44488
|
+
CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT: () => CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT,
|
|
44489
|
+
captureBackendDiagnostic: () => captureBackendDiagnostic,
|
|
44490
|
+
captureBrowserSdkFailure: () => captureBrowserSdkFailure,
|
|
44491
|
+
issueName: () => issueName,
|
|
44492
|
+
reportError: () => reportError,
|
|
44493
|
+
setReporter: () => setReporter
|
|
44494
|
+
});
|
|
44495
|
+
const POSTHOG_ERROR_TIMEOUT_MS = 5e3;
|
|
44496
|
+
let activeReporter = { captureException: captureBoundaryException };
|
|
44497
|
+
function setReporter(reporter) {
|
|
44498
|
+
const previous = activeReporter;
|
|
44499
|
+
activeReporter = reporter;
|
|
44500
|
+
return previous;
|
|
44501
|
+
}
|
|
44502
|
+
async function reportError(error, context) {
|
|
44503
|
+
try {
|
|
44504
|
+
await activeReporter.captureException(error, context);
|
|
44505
|
+
} catch {
|
|
44506
|
+
captureLocalException(error, context, "local_sanitized_fallback");
|
|
44507
|
+
}
|
|
44508
|
+
}
|
|
44509
|
+
/**
|
|
44510
|
+
* SERVER-side failures — the 5b lane (ADR-0020 §6 boundary, Part B).
|
|
44511
|
+
*
|
|
44512
|
+
* This used to post `capxul_backend_expected_outcome` and a synthetic
|
|
44513
|
+
* `$exception` into PostHog. Both are ENGINEERING diagnostics, not user
|
|
44514
|
+
* behavior: they answered no drop-off question and drowned the product error
|
|
44515
|
+
* tracker (400 `$exception`/30d, top type `NOT_IMPLEMENTED`). They now leave
|
|
44516
|
+
* PostHog entirely and exit as one wide, structured line per failure, which
|
|
44517
|
+
* Convex log streams carry to the OTLP sink (ADR-0020 B1/B2).
|
|
44518
|
+
*
|
|
44519
|
+
* `correlation_id` is deliberately on the line: it is THE shared key between a
|
|
44520
|
+
* 5a funnel drop and the 5b trace that explains it.
|
|
44521
|
+
*
|
|
44522
|
+
* Browser-origin failures are NOT affected — `captureBrowserSdkFailure` below
|
|
44523
|
+
* keeps sending `$exception`, because "what breaks in a real user's browser"
|
|
44524
|
+
* IS a product question and stays in PostHog.
|
|
44525
|
+
*/
|
|
44526
|
+
async function captureBackendDiagnostic(error, context) {
|
|
44527
|
+
const errorKind = observationErrorKind(error);
|
|
44528
|
+
const attribution = readAttribution(context?.attribution);
|
|
44529
|
+
const expected = isCapxulError(error) && EXPECTED_OPERATION_OUTCOMES.has(error.code);
|
|
44530
|
+
const properties = attributionProperties(attribution);
|
|
44531
|
+
const operation = normalizeOperation(context?.operation);
|
|
44532
|
+
emitBackendWideEvent({
|
|
44533
|
+
op: operation,
|
|
44534
|
+
outcome: expected ? "expected" : "unexpected",
|
|
44535
|
+
error_kind: errorKind,
|
|
44536
|
+
actor_kind: properties.actor_kind,
|
|
44537
|
+
actor_id: properties.actor_id,
|
|
44538
|
+
correlation_id: properties.correlation_id,
|
|
44539
|
+
journey_id: properties.journey_id,
|
|
44540
|
+
organization_id: properties.organization_id,
|
|
44541
|
+
handled: true,
|
|
44542
|
+
producer: "server"
|
|
44543
|
+
});
|
|
44544
|
+
if (isHermeticTestRun()) return;
|
|
44545
|
+
try {
|
|
44546
|
+
await (expected ? postServerExpectedOutcome(error, errorKind, operation, properties, context) : postServerException(error, errorKind, operation, properties, context));
|
|
44547
|
+
} catch {
|
|
44548
|
+
captureLocalException(error, context, "local_sanitized_fallback");
|
|
44549
|
+
}
|
|
44550
|
+
}
|
|
44551
|
+
/** The `$exception` twin for an expected product outcome: same evidence, its own stream. */
|
|
44552
|
+
const CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT = "capxul_backend_expected_outcome";
|
|
44553
|
+
async function postServerExpectedOutcome(error, errorKind, operation, properties, context) {
|
|
44554
|
+
const { attribution: _attribution, delivery: _delivery, operation: _op, ...rest } = context ?? {};
|
|
44555
|
+
await postPostHogEvent(CAPXUL_BACKEND_EXPECTED_OUTCOME_EVENT, {
|
|
44556
|
+
...properties,
|
|
44557
|
+
operation,
|
|
44558
|
+
error_kind: errorKind,
|
|
44559
|
+
...errorEvidence(error),
|
|
44560
|
+
...safeEvidence(rest),
|
|
44561
|
+
handled: true,
|
|
44562
|
+
producer: "server"
|
|
44563
|
+
}, { timeoutMs: POSTHOG_ERROR_TIMEOUT_MS });
|
|
44564
|
+
}
|
|
44565
|
+
/**
|
|
44566
|
+
* Total, cycle-safe copy of arbitrary evidence: strings masked, bigints
|
|
44567
|
+
* stringified, cycles and depth cut. `JSON.stringify` would throw on a bigint
|
|
44568
|
+
* or a cycle and drop the whole `$exception` with it.
|
|
44569
|
+
*/
|
|
44570
|
+
/** A field whose NAME says credential is masked whatever its value looks like. */
|
|
44571
|
+
const CREDENTIAL_FIELD_NAME = /(?:otp|pass(?:word|wd|phrase)?|token|secret|credential|api[_-]?key|private[_-]?key|authorization|cookie|session)/iu;
|
|
44572
|
+
/** Every string of evidence is bounded: a provider body cannot inflate a log record or an exception. */
|
|
44573
|
+
const EVIDENCE_STRING_MAX = 2e3;
|
|
44574
|
+
/** Objects and arrays keep their first entries only; the sanitizer stays total on any shape. */
|
|
44575
|
+
const EVIDENCE_ENTRY_MAX = 50;
|
|
44576
|
+
/** Property names are bounded too: fifty huge keys are still a huge record. */
|
|
44577
|
+
const EVIDENCE_KEY_MAX = 64;
|
|
44578
|
+
const UNPRINTABLE = "[unprintable]";
|
|
44579
|
+
function clipEvidence(text) {
|
|
44580
|
+
return text.length <= EVIDENCE_STRING_MAX ? text : `${text.slice(0, EVIDENCE_STRING_MAX)}…(${String(text.length)} chars)`;
|
|
44581
|
+
}
|
|
44582
|
+
/**
|
|
44583
|
+
* Total text of any value: a hostile `toString`, a throwing `message` getter,
|
|
44584
|
+
* or a Proxy yields the fixed marker instead of an exception, because this
|
|
44585
|
+
* runs inside the fallback path that must never replace the domain error.
|
|
44586
|
+
*/
|
|
44587
|
+
function safeText(value) {
|
|
44588
|
+
let text;
|
|
44589
|
+
try {
|
|
44590
|
+
text = value instanceof Error ? String(value.message) : String(value);
|
|
44591
|
+
} catch {
|
|
44592
|
+
text = UNPRINTABLE;
|
|
44593
|
+
}
|
|
44594
|
+
try {
|
|
44595
|
+
return clipEvidence(redactSecrets(text));
|
|
44596
|
+
} catch {
|
|
44597
|
+
return UNPRINTABLE;
|
|
44598
|
+
}
|
|
44599
|
+
}
|
|
44600
|
+
function safeEvidence(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
44601
|
+
if (typeof value === "string") return safeText(value);
|
|
44602
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
44603
|
+
if (typeof value === "bigint") return value.toString();
|
|
44604
|
+
if (value instanceof Error) return safeText(value);
|
|
44605
|
+
if (depth >= 4 || typeof value !== "object" || seen.has(value)) return void 0;
|
|
44606
|
+
seen.add(value);
|
|
44607
|
+
if (Array.isArray(value)) return value.slice(0, EVIDENCE_ENTRY_MAX).map((item) => safeEvidence(item, depth + 1, seen));
|
|
44608
|
+
let keys;
|
|
44609
|
+
try {
|
|
44610
|
+
keys = Object.keys(value).slice(0, EVIDENCE_ENTRY_MAX);
|
|
44611
|
+
} catch {
|
|
44612
|
+
return UNPRINTABLE;
|
|
44613
|
+
}
|
|
44614
|
+
const copy = {};
|
|
44615
|
+
for (const key of keys) {
|
|
44616
|
+
const name = key.length <= EVIDENCE_KEY_MAX ? key : `${key.slice(0, EVIDENCE_KEY_MAX)}…`;
|
|
44617
|
+
if (CREDENTIAL_FIELD_NAME.test(key)) {
|
|
44618
|
+
copy[name] = "[REDACTED]";
|
|
44619
|
+
continue;
|
|
44620
|
+
}
|
|
44621
|
+
let nested;
|
|
44622
|
+
try {
|
|
44623
|
+
nested = value[key];
|
|
44624
|
+
} catch {
|
|
44625
|
+
copy[name] = UNPRINTABLE;
|
|
44626
|
+
continue;
|
|
44627
|
+
}
|
|
44628
|
+
const safe = safeEvidence(nested, depth + 1, seen);
|
|
44629
|
+
if (safe !== void 0) copy[name] = safe;
|
|
44630
|
+
}
|
|
44631
|
+
return copy;
|
|
44632
|
+
}
|
|
44633
|
+
/** A stack is longer than a message by nature; it still ends before it can inflate a payload. */
|
|
44634
|
+
const EVIDENCE_STACK_MAX = 4e3;
|
|
44635
|
+
function safeStack(error) {
|
|
44636
|
+
try {
|
|
44637
|
+
const stack = error instanceof Error ? error.stack : void 0;
|
|
44638
|
+
if (typeof stack !== "string" || stack.length === 0) return void 0;
|
|
44639
|
+
const text = redactSecrets(stack);
|
|
44640
|
+
return text.length <= EVIDENCE_STACK_MAX ? text : `${text.slice(0, EVIDENCE_STACK_MAX)}…(${String(text.length)} chars)`;
|
|
44641
|
+
} catch {
|
|
44642
|
+
return UNPRINTABLE;
|
|
44643
|
+
}
|
|
44644
|
+
}
|
|
44645
|
+
async function postServerException(error, errorKind, operation, properties, context) {
|
|
44646
|
+
const evidence = errorEvidence(error);
|
|
44647
|
+
const message = String(evidence.error_message);
|
|
44648
|
+
const stack = safeStack(error);
|
|
44649
|
+
const mode = isCapxulError(error) ? error.mode : void 0;
|
|
44650
|
+
const chain = isCapxulError(error) ? error.chain : void 0;
|
|
44651
|
+
const { attribution: _attribution, delivery: _delivery, operation: _op, ...rest } = context ?? {};
|
|
44652
|
+
await postPostHogEvent("$exception", {
|
|
44653
|
+
...properties,
|
|
44654
|
+
operation,
|
|
44655
|
+
error_kind: errorKind,
|
|
44656
|
+
...evidence,
|
|
44657
|
+
...safeEvidence(rest),
|
|
44658
|
+
handled: true,
|
|
44659
|
+
producer: "server",
|
|
44660
|
+
$exception_type: errorKind,
|
|
44661
|
+
$exception_message: message,
|
|
44662
|
+
$exception_level: "error",
|
|
44663
|
+
$exception_fingerprint: failureFingerprint(errorKind, mode, operation),
|
|
44664
|
+
$issue_name: issueName(errorKind, mode, chain, operation),
|
|
44665
|
+
$issue_description: safeText(chain?.providerMessage ?? message),
|
|
44666
|
+
$exception_list: [{
|
|
44667
|
+
type: errorKind,
|
|
44668
|
+
value: message,
|
|
44669
|
+
mechanism: {
|
|
44670
|
+
handled: true,
|
|
44671
|
+
type: "capxul_backend_boundary"
|
|
44672
|
+
},
|
|
44673
|
+
...stack === void 0 ? {} : { stack },
|
|
44674
|
+
stacktrace: {
|
|
44675
|
+
type: "raw",
|
|
44676
|
+
frames: [{
|
|
44677
|
+
platform: "javascript",
|
|
44678
|
+
filename: "capxul-backend-observation://boundary",
|
|
44679
|
+
function: operation,
|
|
44680
|
+
lineno: 1,
|
|
44681
|
+
colno: 1,
|
|
44682
|
+
in_app: true
|
|
44683
|
+
}]
|
|
44684
|
+
}
|
|
44685
|
+
}]
|
|
44686
|
+
}, { timeoutMs: POSTHOG_ERROR_TIMEOUT_MS });
|
|
44687
|
+
}
|
|
44688
|
+
async function captureBrowserSdkFailure(input) {
|
|
44689
|
+
const { operation, errorKind, sdkVersion, attribution, correlationId } = input;
|
|
44690
|
+
const properties = {
|
|
44691
|
+
...attributionProperties(attribution),
|
|
44692
|
+
operation,
|
|
44693
|
+
error_kind: errorKind,
|
|
44694
|
+
sdk_version: sdkVersion,
|
|
44695
|
+
handled: true,
|
|
44696
|
+
producer: "browser"
|
|
44697
|
+
};
|
|
44698
|
+
if (correlationId !== void 0) properties.correlation_id = correlationId;
|
|
44699
|
+
if (EXPECTED_OPERATION_OUTCOMES.has(errorKind)) {
|
|
44700
|
+
emitBackendWideEvent({
|
|
44701
|
+
op: operation,
|
|
44702
|
+
outcome: "expected",
|
|
44703
|
+
error_kind: errorKind,
|
|
44704
|
+
sdk_version: sdkVersion,
|
|
44705
|
+
actor_kind: properties.actor_kind,
|
|
44706
|
+
actor_id: properties.actor_id,
|
|
44707
|
+
correlation_id: properties.correlation_id,
|
|
44708
|
+
journey_id: properties.journey_id,
|
|
44709
|
+
handled: true,
|
|
44710
|
+
producer: "browser"
|
|
44711
|
+
});
|
|
44712
|
+
return;
|
|
44713
|
+
}
|
|
44714
|
+
await postPostHogEvent("$exception", {
|
|
44715
|
+
...properties,
|
|
44716
|
+
$exception_type: errorKind,
|
|
44717
|
+
$exception_message: "Capxul SDK operation failed",
|
|
44718
|
+
$exception_list: [{
|
|
44719
|
+
type: errorKind,
|
|
44720
|
+
value: "Capxul SDK operation failed",
|
|
44721
|
+
mechanism: {
|
|
44722
|
+
handled: true,
|
|
44723
|
+
type: "capxul_sdk_boundary"
|
|
44724
|
+
},
|
|
44725
|
+
stacktrace: { frames: [{
|
|
44726
|
+
filename: "capxul-sdk-observation://boundary",
|
|
44727
|
+
function: operation,
|
|
44728
|
+
lineno: 1,
|
|
44729
|
+
colno: 1,
|
|
44730
|
+
in_app: true
|
|
44731
|
+
}] }
|
|
44732
|
+
}]
|
|
44733
|
+
}, { timeoutMs: POSTHOG_ERROR_TIMEOUT_MS });
|
|
44734
|
+
}
|
|
44735
|
+
async function captureBoundaryException(error, context) {
|
|
44736
|
+
const attribution = readAttribution(context?.attribution);
|
|
44737
|
+
await Promise.resolve(captureBackendDiagnostic(error, {
|
|
44738
|
+
...context,
|
|
44739
|
+
attribution
|
|
44740
|
+
}));
|
|
44741
|
+
}
|
|
44742
|
+
/**
|
|
44743
|
+
* The 5b exit for the server half: one wide, high-cardinality line per failed
|
|
44744
|
+
* operation (ADR-0020 B1). It is a `console.error` because Convex log streams
|
|
44745
|
+
* are the deployment's OTLP export path — no fetch, so it also works from
|
|
44746
|
+
* queries and mutations, where the old PostHog post could never run.
|
|
44747
|
+
*/
|
|
44748
|
+
function emitBackendWideEvent(fields) {
|
|
44749
|
+
if (isHermeticTestRun()) return;
|
|
44750
|
+
const line = {};
|
|
44751
|
+
for (const [key, value] of Object.entries(fields)) if (value !== void 0) line[key] = value;
|
|
44752
|
+
console.error("[CAPXUL_BACKEND_OPERATION]", line);
|
|
44753
|
+
}
|
|
44754
|
+
function captureLocalException(error, context, delivery = "local_sanitized") {
|
|
44755
|
+
if (isHermeticTestRun()) return;
|
|
44756
|
+
const errorKind = observationErrorKind(error);
|
|
44757
|
+
console.error("[CAPXUL_BACKEND_BOUNDARY]", {
|
|
44758
|
+
operation: normalizeOperation(context?.operation),
|
|
44759
|
+
error_kind: errorKind,
|
|
44760
|
+
delivery,
|
|
44761
|
+
...errorEvidence(error)
|
|
44762
|
+
});
|
|
44763
|
+
}
|
|
44764
|
+
/** Redacted message, cause chain (outermost first), and details of one failure. */
|
|
44765
|
+
function errorEvidence(error) {
|
|
44766
|
+
try {
|
|
44767
|
+
const message = safeText(error);
|
|
44768
|
+
const details = isCapxulError(error) ? error.details : void 0;
|
|
44769
|
+
const causeChain = [];
|
|
44770
|
+
let link = error instanceof Error ? error.cause : void 0;
|
|
44771
|
+
for (let depth = 0; depth < 8 && link !== void 0 && link !== null; depth++) {
|
|
44772
|
+
causeChain.push(safeText(link));
|
|
44773
|
+
link = link instanceof Error ? link.cause : void 0;
|
|
44774
|
+
}
|
|
44775
|
+
const mode = isCapxulError(error) ? error.mode : void 0;
|
|
44776
|
+
const chain = isCapxulError(error) ? error.chain : void 0;
|
|
44777
|
+
return {
|
|
44778
|
+
error_message: message,
|
|
44779
|
+
...details === void 0 ? {} : { error_details: safeEvidence(details) },
|
|
44780
|
+
...causeChain.length === 0 ? {} : { error_cause: clipEvidence(causeChain.join(" <- ")) },
|
|
44781
|
+
...mode === void 0 ? {} : { failure_mode: mode },
|
|
44782
|
+
...chain === void 0 ? {} : safeEvidence(chainCauseProperties(chain))
|
|
44783
|
+
};
|
|
44784
|
+
} catch {
|
|
44785
|
+
return { error_message: UNPRINTABLE };
|
|
44786
|
+
}
|
|
44787
|
+
}
|
|
44788
|
+
function readAttribution(value) {
|
|
44789
|
+
return readExplicitAttribution(value) ?? systemAttribution("unattributed_boundary");
|
|
44790
|
+
}
|
|
44791
|
+
function readExplicitAttribution(value) {
|
|
44792
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
44793
|
+
const candidate = value;
|
|
44794
|
+
if (candidate.kind === "authenticated" && typeof candidate.authUserId === "string") return candidate;
|
|
44795
|
+
if (candidate.kind === "anonymous" && typeof candidate.anonymousId === "string") return candidate;
|
|
44796
|
+
if (candidate.kind === "system" && typeof candidate.systemJob === "string") return candidate;
|
|
44797
|
+
}
|
|
44798
|
+
/** PostHog truncates `$issue_name` at 255 characters; cut on our side so the operation survives. */
|
|
44799
|
+
const ISSUE_NAME_MAX_LENGTH = 255;
|
|
44800
|
+
/** `normalizeOperation` allows 256 characters; the name keeps this much of it. */
|
|
44801
|
+
const ISSUE_NAME_OPERATION_MAX_LENGTH = 120;
|
|
44802
|
+
/** "PROVIDER_ERROR: revert on alto during eth_estimateUserOperationGas (smartAccount.claim)". */
|
|
44803
|
+
function issueName(errorKind, mode, chain, operation) {
|
|
44804
|
+
const cause = mode === void 0 ? "" : `: ${safeText(mode)}`;
|
|
44805
|
+
const where = chain?.upstream === void 0 ? "" : ` on ${safeText(chain.upstream)}${chain.method === void 0 ? "" : ` during ${safeText(chain.method)}`}`;
|
|
44806
|
+
const suffix = ` (${operation.slice(0, ISSUE_NAME_OPERATION_MAX_LENGTH)})`;
|
|
44807
|
+
const budget = Math.max(errorKind.length, ISSUE_NAME_MAX_LENGTH - suffix.length);
|
|
44808
|
+
return `${`${errorKind}${cause}${where}`.slice(0, budget)}${suffix}`;
|
|
44809
|
+
}
|
|
44810
|
+
function normalizeOperation(value) {
|
|
44811
|
+
return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.:/-]{0,255}$/u.test(value) ? value : "unknown";
|
|
44812
|
+
}
|
|
44813
|
+
//#endregion
|
|
44814
|
+
//#region ../../packages/backend/convex/_shared/telemetry.ts
|
|
44815
|
+
const AWAITED_TELEMETRY_TIMEOUT_MS = 5e3;
|
|
44816
|
+
/** Await in Convex actions — satisfies dangling-promise lint for PostHog fetch. */
|
|
44817
|
+
async function emitServerAwaited(attribution, event) {
|
|
44818
|
+
try {
|
|
44819
|
+
await emitServerPromise(attribution, event, { timeoutMs: AWAITED_TELEMETRY_TIMEOUT_MS });
|
|
44820
|
+
} catch (error) {
|
|
44821
|
+
await reportTelemetryFailure(error, {
|
|
44822
|
+
event: event.name,
|
|
44823
|
+
source: "backend.telemetry.emitServerAwaited"
|
|
44824
|
+
});
|
|
44825
|
+
}
|
|
44826
|
+
}
|
|
44827
|
+
function emitServerPromise(attribution, event, options) {
|
|
44828
|
+
const decoded = decodeTelemetryEvent(stampTelemetryEnvelope(event, {
|
|
44829
|
+
capxul_env: resolveCapxulEnv(),
|
|
44830
|
+
producer: "server"
|
|
44831
|
+
}));
|
|
44832
|
+
const redactedProps = redactTelemetryProps(decoded.name, decoded.props) ?? {};
|
|
44833
|
+
return postPostHogEvent(decoded.name, {
|
|
44834
|
+
...redactedProps,
|
|
44835
|
+
...attributionProperties(attribution)
|
|
44836
|
+
}, options);
|
|
44837
|
+
}
|
|
44838
|
+
function decodeTelemetryEvent(event) {
|
|
44839
|
+
const loose = TELEMETRY_EVENT_SCHEMAS[event.name];
|
|
44840
|
+
return Schema.decodeUnknownSync(loose)(event);
|
|
44841
|
+
}
|
|
44842
|
+
async function reportTelemetryFailure(error, context) {
|
|
44843
|
+
try {
|
|
44844
|
+
const reporterModule = init_exports;
|
|
44845
|
+
if (!Object.prototype.hasOwnProperty.call(reporterModule, "reportError")) return;
|
|
44846
|
+
await reporterModule.reportError?.(error, context);
|
|
44847
|
+
} catch {}
|
|
44848
|
+
}
|
|
43352
44849
|
//#endregion
|
|
43353
44850
|
//#region ../../packages/backend/convex/_shared/userOperationRevert.ts
|
|
43354
44851
|
/** OpenZeppelin v5 ERC-20 errors (ERC-6093). The token contracts on Base Sepolia use them. */
|
|
@@ -43497,8 +44994,11 @@ function typedSponsorshipFailure(error) {
|
|
|
43497
44994
|
available: args?.balance ?? "unknown",
|
|
43498
44995
|
required: args?.needed ?? "unknown",
|
|
43499
44996
|
sender: args?.sender ?? "unknown",
|
|
43500
|
-
revert: error.details.revert
|
|
44997
|
+
revert: error.details.revert,
|
|
44998
|
+
failure_mode: "insufficient-balance"
|
|
43501
44999
|
},
|
|
45000
|
+
mode: "insufficient-balance",
|
|
45001
|
+
...error.chain === void 0 ? {} : { chain: error.chain },
|
|
43502
45002
|
...error.correlationId === void 0 ? {} : { correlationId: error.correlationId }
|
|
43503
45003
|
});
|
|
43504
45004
|
}
|
|
@@ -43537,27 +45037,106 @@ function rpcProviderError(operation, cause, chainId) {
|
|
|
43537
45037
|
const method = operation.split(" ", 1)[0] ?? operation;
|
|
43538
45038
|
return Errors.providerError(rpcProviderRole(chainId, method), operation, cause);
|
|
43539
45039
|
}
|
|
45040
|
+
/** The modes the next upstream may not share: a throttle, a timeout, a dead upstream. */
|
|
45041
|
+
const TRANSIENT_MODES = new Set([
|
|
45042
|
+
"rate-limited",
|
|
45043
|
+
"timeout",
|
|
45044
|
+
"upstream-down"
|
|
45045
|
+
]);
|
|
45046
|
+
/** ERC-4337 validation refusals (`-3250x`) and the bundler's invalid-params answer. */
|
|
45047
|
+
const BUNDLER_REJECTION_CODES = new Set([
|
|
45048
|
+
-32500,
|
|
45049
|
+
-32501,
|
|
45050
|
+
-32502,
|
|
45051
|
+
-32503,
|
|
45052
|
+
-32504,
|
|
45053
|
+
-32505,
|
|
45054
|
+
-32506,
|
|
45055
|
+
-32507,
|
|
45056
|
+
-32508,
|
|
45057
|
+
-32602
|
|
45058
|
+
]);
|
|
43540
45059
|
/**
|
|
43541
|
-
*
|
|
43542
|
-
*
|
|
43543
|
-
*
|
|
45060
|
+
* Alto reports a malformed `eth_sendUserOperation` with `-32601` and a
|
|
45061
|
+
* "Validation error: …" message (staging, 2026-09-02). Only that shape is a
|
|
45062
|
+
* rejection; a plain method-not-found stays an upstream failure.
|
|
43544
45063
|
*/
|
|
43545
|
-
|
|
43546
|
-
|
|
45064
|
+
const METHOD_NOT_FOUND_RPC_CODE = -32601;
|
|
45065
|
+
const ALTO_VALIDATION_ERROR = /^Validation error:/u;
|
|
45066
|
+
function isBundlerRejection(method, code, message) {
|
|
45067
|
+
if (!BUNDLER_RPC_METHODS.has(method)) return false;
|
|
45068
|
+
if (BUNDLER_REJECTION_CODES.has(code)) return true;
|
|
45069
|
+
return code === METHOD_NOT_FOUND_RPC_CODE && method === "eth_sendUserOperation" && ALTO_VALIDATION_ERROR.test(message);
|
|
45070
|
+
}
|
|
45071
|
+
/**
|
|
45072
|
+
* A chain-path failure with its cause (ADR-0023 R7–R8). The cause is built
|
|
45073
|
+
* once by the layer that saw it and never rewritten; `details.failure_mode`
|
|
45074
|
+
* and `details.transient` stay for existing readers.
|
|
45075
|
+
*/
|
|
45076
|
+
function chainProviderError(method, operation, cause, chainId, chain, extraDetails = {}) {
|
|
43547
45077
|
return Errors.providerError(rpcProviderRole(chainId, method), operation, cause, {
|
|
43548
|
-
|
|
43549
|
-
details: {
|
|
45078
|
+
chain,
|
|
45079
|
+
details: {
|
|
45080
|
+
...extraDetails,
|
|
45081
|
+
transient: TRANSIENT_MODES.has(chain.mode)
|
|
45082
|
+
}
|
|
43550
45083
|
});
|
|
43551
45084
|
}
|
|
43552
45085
|
function isTransientProviderError(error) {
|
|
43553
|
-
return error instanceof CapxulError && error.
|
|
45086
|
+
return error instanceof CapxulError && error.chain !== void 0 && TRANSIENT_MODES.has(error.chain.mode);
|
|
43554
45087
|
}
|
|
43555
|
-
function
|
|
45088
|
+
function rethrowTransport(chainId, method, upstream, externalSignal) {
|
|
43556
45089
|
return (e) => {
|
|
43557
45090
|
if (externalSignal?.aborted === true) throw rpcProviderError(method, e, chainId);
|
|
43558
|
-
throw
|
|
45091
|
+
throw chainProviderError(method, method, e, chainId, {
|
|
45092
|
+
mode: e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError") ? "timeout" : "upstream-down",
|
|
45093
|
+
upstream,
|
|
45094
|
+
method,
|
|
45095
|
+
retryable: true,
|
|
45096
|
+
providerMessage: boundedEvidence(e instanceof Error ? e.message : String(e), BUNDLER_MESSAGE_MAX)
|
|
45097
|
+
});
|
|
45098
|
+
};
|
|
45099
|
+
}
|
|
45100
|
+
/** The `chain_upstream_fallback` event for one skipped upstream. Pure; the catalog test decodes it. */
|
|
45101
|
+
function upstreamFallbackEvent(input) {
|
|
45102
|
+
return {
|
|
45103
|
+
name: "chain_upstream_fallback",
|
|
45104
|
+
props: {
|
|
45105
|
+
service: "backend",
|
|
45106
|
+
method: input.method,
|
|
45107
|
+
from_upstream: input.from,
|
|
45108
|
+
...input.to === void 0 ? {} : { to_upstream: input.to },
|
|
45109
|
+
failure_mode: input.chain.mode,
|
|
45110
|
+
exhausted: input.to === void 0,
|
|
45111
|
+
...input.chain.httpStatus === void 0 ? {} : { http_status: input.chain.httpStatus },
|
|
45112
|
+
...input.chain.rpcCode === void 0 ? {} : { rpc_code: input.chain.rpcCode }
|
|
45113
|
+
}
|
|
43559
45114
|
};
|
|
43560
45115
|
}
|
|
45116
|
+
/**
|
|
45117
|
+
* Recovered fallback and exhaustion are events; the read's own outcome
|
|
45118
|
+
* stands. Awaited: a Convex action can be torn down as soon as it returns,
|
|
45119
|
+
* so a fire-and-forget capture here can be lost.
|
|
45120
|
+
*/
|
|
45121
|
+
async function reportUpstreamFallback(method, from, to, chain) {
|
|
45122
|
+
console.warn(JSON.stringify({
|
|
45123
|
+
event: "rpc_upstream_fallback",
|
|
45124
|
+
method,
|
|
45125
|
+
from,
|
|
45126
|
+
to: to ?? null,
|
|
45127
|
+
failure_mode: chain.mode,
|
|
45128
|
+
rate_limited: chain.mode === "rate-limited"
|
|
45129
|
+
}));
|
|
45130
|
+
if (isHermeticTestRun()) return;
|
|
45131
|
+
try {
|
|
45132
|
+
await emitServerAwaited(systemAttribution("chain_rpc"), upstreamFallbackEvent({
|
|
45133
|
+
method,
|
|
45134
|
+
from,
|
|
45135
|
+
to,
|
|
45136
|
+
chain
|
|
45137
|
+
}));
|
|
45138
|
+
} catch {}
|
|
45139
|
+
}
|
|
43561
45140
|
function parseRpcQuantity(value, operation, field, chainId) {
|
|
43562
45141
|
try {
|
|
43563
45142
|
return BigInt(value);
|
|
@@ -43591,7 +45170,10 @@ const BASE_MAINNET_NODE_RPC_URL = "https://mainnet.base.org";
|
|
|
43591
45170
|
*/
|
|
43592
45171
|
function nodeRpcUrl(chainId) {
|
|
43593
45172
|
switch (chainId) {
|
|
43594
|
-
case 84532:
|
|
45173
|
+
case 84532: {
|
|
45174
|
+
const override = optionalEnv("BASE_SEPOLIA_RPC_URL");
|
|
45175
|
+
return (override !== void 0 && hostedUpstreamName(override) === null ? override : BASE_SEPOLIA_NODE_RPC_URL).replace(/\/+$/, "");
|
|
45176
|
+
}
|
|
43595
45177
|
case 8453: return (optionalEnv("BASE_MAINNET_RPC_URL") ?? BASE_MAINNET_NODE_RPC_URL).replace(/\/+$/, "");
|
|
43596
45178
|
default: throw Errors.invalidInput("chainId", `unsupported chainId ${String(chainId)}`);
|
|
43597
45179
|
}
|
|
@@ -43609,6 +45191,18 @@ const BUNDLER_MESSAGE_MAX = 300;
|
|
|
43609
45191
|
function clip(value, max) {
|
|
43610
45192
|
return value.length <= max ? value : `${value.slice(0, max)}…(${String(value.length)} chars)`;
|
|
43611
45193
|
}
|
|
45194
|
+
function revertSummaryOf(revert) {
|
|
45195
|
+
return {
|
|
45196
|
+
name: revert.name,
|
|
45197
|
+
selector: revert.selector,
|
|
45198
|
+
args: revert.args
|
|
45199
|
+
};
|
|
45200
|
+
}
|
|
45201
|
+
function revertMode(revert) {
|
|
45202
|
+
if (revert.name === "ERC20InsufficientBalance") return "insufficient-balance";
|
|
45203
|
+
if (revert.name === "ERC20InsufficientAllowance") return "insufficient-allowance";
|
|
45204
|
+
return "revert";
|
|
45205
|
+
}
|
|
43612
45206
|
function boundedRevertDetails(revert, bundlerMessage) {
|
|
43613
45207
|
const args = {};
|
|
43614
45208
|
for (const [name, value] of Object.entries(revert.args).slice(0, 8)) args[clip(name, 32)] = clip(value, REVERT_ARG_MAX);
|
|
@@ -43633,16 +45227,45 @@ const WIDE_LOG_READS = new Set(["eth_getLogs"]);
|
|
|
43633
45227
|
function stripSlash(url) {
|
|
43634
45228
|
return url.replace(/\/+$/u, "");
|
|
43635
45229
|
}
|
|
45230
|
+
/**
|
|
45231
|
+
* Which hosted provider a URL points at, by host. The env name is not
|
|
45232
|
+
* trusted: staging held an Alchemy URL in `BASE_SEPOLIA_RPC_URL` and the
|
|
45233
|
+
* Infura URL in `BASE_SEPOLIA_EVIDENCE_RPC_URL`, which ran the chain
|
|
45234
|
+
* backwards (audit 2026-09-02, gap 5).
|
|
45235
|
+
*/
|
|
45236
|
+
function hostedUpstreamName(url) {
|
|
45237
|
+
let host;
|
|
45238
|
+
try {
|
|
45239
|
+
host = new URL(url).hostname;
|
|
45240
|
+
} catch {
|
|
45241
|
+
return null;
|
|
45242
|
+
}
|
|
45243
|
+
if (host === "alchemy.com" || host.endsWith(".alchemy.com")) return "alchemy";
|
|
45244
|
+
if (host === "infura.io" || host.endsWith(".infura.io")) return "infura";
|
|
45245
|
+
return null;
|
|
45246
|
+
}
|
|
45247
|
+
/** Env names in priority order; an explicit slot name wins when the host says nothing. */
|
|
45248
|
+
const BASE_SEPOLIA_UPSTREAM_ENV_NAMES = [
|
|
45249
|
+
["BASE_SEPOLIA_ALCHEMY_RPC_URL", "alchemy"],
|
|
45250
|
+
["BASE_SEPOLIA_INFURA_RPC_URL", "infura"],
|
|
45251
|
+
["BASE_SEPOLIA_EVIDENCE_RPC_URL", null],
|
|
45252
|
+
["BASE_SEPOLIA_RPC_URL", null]
|
|
45253
|
+
];
|
|
43636
45254
|
function hostedUpstreams(chainId) {
|
|
43637
45255
|
if (chainId !== 84532) return [];
|
|
43638
|
-
const
|
|
43639
|
-
const
|
|
43640
|
-
|
|
45256
|
+
const found = {};
|
|
45257
|
+
for (const [name, declared] of BASE_SEPOLIA_UPSTREAM_ENV_NAMES) {
|
|
45258
|
+
const url = optionalEnv(name);
|
|
45259
|
+
if (url === void 0) continue;
|
|
45260
|
+
const kind = hostedUpstreamName(url) ?? declared;
|
|
45261
|
+
if (kind !== null && found[kind] === void 0) found[kind] = stripSlash(url);
|
|
45262
|
+
}
|
|
45263
|
+
return [...found.alchemy === void 0 ? [] : [{
|
|
43641
45264
|
name: "alchemy",
|
|
43642
|
-
url:
|
|
43643
|
-
}], ...infura === void 0 ? [] : [{
|
|
45265
|
+
url: found.alchemy
|
|
45266
|
+
}], ...found.infura === void 0 ? [] : [{
|
|
43644
45267
|
name: "infura",
|
|
43645
|
-
url:
|
|
45268
|
+
url: found.infura
|
|
43646
45269
|
}]];
|
|
43647
45270
|
}
|
|
43648
45271
|
/** Node upstreams in the order one method tries them. Always ends on the public node. */
|
|
@@ -43663,33 +45286,87 @@ function isValidJsonRpcError(value) {
|
|
|
43663
45286
|
return isRecord(value) && typeof value.code === "number" && Number.isInteger(value.code) && typeof value.message === "string";
|
|
43664
45287
|
}
|
|
43665
45288
|
var DefinitiveBundlerJsonRpcRejection = class extends Error {
|
|
43666
|
-
constructor() {
|
|
43667
|
-
super(
|
|
45289
|
+
constructor(message) {
|
|
45290
|
+
super(message);
|
|
43668
45291
|
this.name = "DefinitiveBundlerJsonRpcRejection";
|
|
43669
45292
|
}
|
|
43670
45293
|
};
|
|
43671
45294
|
async function alchemyRpc(chainId, method, params, timeoutMs, externalSignal) {
|
|
43672
|
-
if (BUNDLER_RPC_METHODS.has(method)) return jsonRpcOnce(chainId, method, params, stripSlash(accountAbstractionUrl(chainId)), timeoutMs, externalSignal);
|
|
45295
|
+
if (BUNDLER_RPC_METHODS.has(method)) return jsonRpcOnce(chainId, method, params, stripSlash(accountAbstractionUrl(chainId)), "gateway", timeoutMs, externalSignal);
|
|
43673
45296
|
const candidates = nodeRpcCandidates(chainId, method);
|
|
43674
|
-
let lastError;
|
|
43675
45297
|
for (const [index, upstream] of candidates.entries()) try {
|
|
43676
|
-
return await jsonRpcOnce(chainId, method, params, upstream.url, timeoutMs, externalSignal);
|
|
45298
|
+
return await jsonRpcOnce(chainId, method, params, upstream.url, upstream.name, timeoutMs, externalSignal);
|
|
43677
45299
|
} catch (error) {
|
|
45300
|
+
if (!isTransientProviderError(error)) throw error;
|
|
43678
45301
|
const next = candidates[index + 1];
|
|
43679
|
-
|
|
43680
|
-
|
|
43681
|
-
console.warn(JSON.stringify({
|
|
43682
|
-
event: "rpc_upstream_fallback",
|
|
43683
|
-
method,
|
|
43684
|
-
from: upstream.name,
|
|
43685
|
-
to: next.name,
|
|
43686
|
-
operation: error.details?.operation,
|
|
43687
|
-
rate_limited: error.details?.failure_mode === "rate-limited"
|
|
43688
|
-
}));
|
|
45302
|
+
await reportUpstreamFallback(method, upstream.name, next?.name, error.chain);
|
|
45303
|
+
if (next === void 0) throw error;
|
|
43689
45304
|
}
|
|
43690
|
-
throw
|
|
45305
|
+
throw rpcProviderError(method, "no upstream configured", chainId);
|
|
43691
45306
|
}
|
|
43692
|
-
|
|
45307
|
+
/**
|
|
45308
|
+
* A JSON-RPC error answer, named. The gateway's `error.data` is the cause when
|
|
45309
|
+
* present (R8); a node's answer is classified here. Returns the error to throw.
|
|
45310
|
+
*/
|
|
45311
|
+
function jsonRpcErrorFailure(chainId, method, upstream, error) {
|
|
45312
|
+
const { code, message } = error;
|
|
45313
|
+
const providerMessage = boundedEvidence(message, BUNDLER_MESSAGE_MAX);
|
|
45314
|
+
const decoded = BUNDLER_RPC_METHODS.has(method) ? decodeUserOperationRevert(message) : null;
|
|
45315
|
+
const named = decodeChainCause(error.data);
|
|
45316
|
+
let chain;
|
|
45317
|
+
if (named !== null) chain = named.revert !== void 0 && named.revert.name === null && decoded?.name != null ? {
|
|
45318
|
+
...named,
|
|
45319
|
+
revert: {
|
|
45320
|
+
...named.revert,
|
|
45321
|
+
name: decoded.name
|
|
45322
|
+
},
|
|
45323
|
+
mode: named.mode === "revert" ? revertMode(revertSummaryOf(decoded)) : named.mode
|
|
45324
|
+
} : named;
|
|
45325
|
+
else if (code === RATE_LIMITED_RPC_CODE || RATE_LIMIT_MESSAGE.test(message)) chain = {
|
|
45326
|
+
mode: "rate-limited",
|
|
45327
|
+
upstream,
|
|
45328
|
+
method,
|
|
45329
|
+
retryable: true,
|
|
45330
|
+
rpcCode: code,
|
|
45331
|
+
providerMessage
|
|
45332
|
+
};
|
|
45333
|
+
else if (decoded !== null) {
|
|
45334
|
+
const revert = revertSummaryOf(decoded);
|
|
45335
|
+
chain = {
|
|
45336
|
+
mode: revertMode(revert),
|
|
45337
|
+
upstream,
|
|
45338
|
+
method,
|
|
45339
|
+
retryable: false,
|
|
45340
|
+
rpcCode: code,
|
|
45341
|
+
revert,
|
|
45342
|
+
providerMessage
|
|
45343
|
+
};
|
|
45344
|
+
} else if (isBundlerRejection(method, code, message)) chain = {
|
|
45345
|
+
mode: "rejected",
|
|
45346
|
+
upstream,
|
|
45347
|
+
method,
|
|
45348
|
+
retryable: false,
|
|
45349
|
+
rpcCode: code,
|
|
45350
|
+
providerMessage
|
|
45351
|
+
};
|
|
45352
|
+
else chain = {
|
|
45353
|
+
mode: "unknown",
|
|
45354
|
+
upstream,
|
|
45355
|
+
method,
|
|
45356
|
+
retryable: false,
|
|
45357
|
+
rpcCode: code,
|
|
45358
|
+
providerMessage
|
|
45359
|
+
};
|
|
45360
|
+
const cause = method === "eth_sendUserOperation" && !TRANSIENT_MODES.has(chain.mode) ? new DefinitiveBundlerJsonRpcRejection(message) : message;
|
|
45361
|
+
const revertForDetails = chain.revert === void 0 ? null : decoded ?? {
|
|
45362
|
+
data: chain.revert.selector,
|
|
45363
|
+
selector: chain.revert.selector,
|
|
45364
|
+
name: chain.revert.name,
|
|
45365
|
+
args: chain.revert.args
|
|
45366
|
+
};
|
|
45367
|
+
return chainProviderError(method, method, cause, chainId, chain, revertForDetails === null ? {} : boundedRevertDetails(revertForDetails, message));
|
|
45368
|
+
}
|
|
45369
|
+
async function jsonRpcOnce(chainId, method, params, url, upstream, timeoutMs, externalSignal) {
|
|
43693
45370
|
const timeoutSignal = timeoutMs === void 0 ? void 0 : AbortSignal.timeout(timeoutMs);
|
|
43694
45371
|
const signal = externalSignal === void 0 ? timeoutSignal : timeoutSignal === void 0 ? externalSignal : AbortSignal.any([externalSignal, timeoutSignal]);
|
|
43695
45372
|
const res = await fetch(url, {
|
|
@@ -43702,12 +45379,19 @@ async function jsonRpcOnce(chainId, method, params, url, timeoutMs, externalSign
|
|
|
43702
45379
|
params
|
|
43703
45380
|
}),
|
|
43704
45381
|
...signal === void 0 ? {} : { signal }
|
|
43705
|
-
}).catch(
|
|
45382
|
+
}).catch(rethrowTransport(chainId, method, upstream, externalSignal));
|
|
43706
45383
|
if (!res.ok) {
|
|
43707
45384
|
const body = await res.text().catch(() => "<no body>");
|
|
43708
45385
|
const operation = `${method} ${res.status}`;
|
|
43709
|
-
|
|
43710
|
-
throw
|
|
45386
|
+
const mode = res.status === 429 ? "rate-limited" : res.status >= 500 ? "upstream-down" : res.status === 401 ? "unauthorized" : "unknown";
|
|
45387
|
+
throw chainProviderError(method, operation, body, chainId, {
|
|
45388
|
+
mode,
|
|
45389
|
+
upstream,
|
|
45390
|
+
method,
|
|
45391
|
+
retryable: TRANSIENT_MODES.has(mode),
|
|
45392
|
+
httpStatus: res.status,
|
|
45393
|
+
providerMessage: boundedEvidence(body, BUNDLER_MESSAGE_MAX)
|
|
45394
|
+
});
|
|
43711
45395
|
}
|
|
43712
45396
|
let json;
|
|
43713
45397
|
try {
|
|
@@ -43718,11 +45402,7 @@ async function jsonRpcOnce(chainId, method, params, url, timeoutMs, externalSign
|
|
|
43718
45402
|
if (!isValidJsonRpcEnvelope(json)) throw rpcProviderError(method, "malformed JSON-RPC envelope", chainId);
|
|
43719
45403
|
if (json.error !== void 0) {
|
|
43720
45404
|
if (!isValidJsonRpcError(json.error)) throw rpcProviderError(method, "malformed JSON-RPC error", chainId);
|
|
43721
|
-
|
|
43722
|
-
const cause = method === "eth_sendUserOperation" ? new DefinitiveBundlerJsonRpcRejection() : json.error.message;
|
|
43723
|
-
const revert = BUNDLER_RPC_METHODS.has(method) ? decodeUserOperationRevert(json.error.message) : null;
|
|
43724
|
-
if (revert !== null) throw Errors.providerError(rpcProviderRole(chainId, method), method, cause, { details: boundedRevertDetails(revert, json.error.message) });
|
|
43725
|
-
throw rpcProviderError(method, cause, chainId);
|
|
45405
|
+
throw jsonRpcErrorFailure(chainId, method, upstream, json.error);
|
|
43726
45406
|
}
|
|
43727
45407
|
if (json.result === void 0) throw rpcProviderError(method, "missing result", chainId);
|
|
43728
45408
|
return json.result;
|