@capxul/mcp 2.4.0 → 2.5.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 +537 -32
- package/package.json +6 -6
package/dist/main.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
|
|
|
9
9
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
10
|
import { concat, concatHex, createPublicClient, createWalletClient, custom, decodeAbiParameters, decodeFunctionData, decodeFunctionResult, encodeAbiParameters, encodeFunctionData, encodePacked, formatUnits, getAddress, getContractAddress, hashMessage, hashTypedData, hexToBigInt, http, isAddress, isHex, keccak256, pad, padHex, parseUnits, recoverAddress, size, slice, stringToHex, toBytes, toEventSelector, toFunctionSelector, toFunctionSignature, toHex, zeroAddress } from "viem";
|
|
11
11
|
import { z } from "zod";
|
|
12
|
-
import { Cause, Context, Data, Deferred, Effect, Exit, Fiber, Layer, Queue, Ref, Result, Schema, SchemaGetter, SchemaIssue, SchemaParser, Scope, Struct, Tracer } from "effect";
|
|
12
|
+
import { Cause, Context, Data, Deferred, Duration, Effect, Exit, Fiber, Layer, Queue, Ref, Result, Schedule, Schema, SchemaGetter, SchemaIssue, SchemaParser, Scope, Struct, Tracer } from "effect";
|
|
13
13
|
import { privateKeyToAccount, toAccount } from "viem/accounts";
|
|
14
14
|
import { FetchHttpClient, Headers, HttpClient } from "effect/unstable/http";
|
|
15
15
|
import { OtlpExporter, OtlpLogger, OtlpSerialization, OtlpTracer } from "effect/unstable/observability";
|
|
@@ -240,7 +240,7 @@ function normalizeEmail(email) {
|
|
|
240
240
|
}
|
|
241
241
|
//#endregion
|
|
242
242
|
//#region package.json
|
|
243
|
-
var version$2 = "2.
|
|
243
|
+
var version$2 = "2.5.1";
|
|
244
244
|
//#endregion
|
|
245
245
|
//#region ../../packages/errors/src/errors.ts
|
|
246
246
|
const CAPXUL_ERROR_CODES = [
|
|
@@ -339,10 +339,12 @@ const Errors = {
|
|
|
339
339
|
accountNotFound: (accountId) => new CapxulError("ACCOUNT_NOT_FOUND", accountId ? `Openfort account ${accountId} not found` : "Openfort account not found", accountId === void 0 ? void 0 : { details: { accountId } }),
|
|
340
340
|
providerError: (provider, operation, cause, opts) => {
|
|
341
341
|
const details = {
|
|
342
|
+
...opts?.details,
|
|
342
343
|
provider,
|
|
343
344
|
operation
|
|
344
345
|
};
|
|
345
346
|
if (opts?.failure_mode) details.failure_mode = opts.failure_mode;
|
|
347
|
+
if (opts?.httpStatus !== void 0) details.httpStatus = opts.httpStatus;
|
|
346
348
|
return new CapxulError("PROVIDER_ERROR", `Provider error: ${provider} ${operation}`, {
|
|
347
349
|
cause,
|
|
348
350
|
details
|
|
@@ -2398,6 +2400,12 @@ function toPartyId(raw) {
|
|
|
2398
2400
|
function toBudgetId(raw) {
|
|
2399
2401
|
return toNonEmptyStringBrand(raw, "budgetId");
|
|
2400
2402
|
}
|
|
2403
|
+
function toPayrollRunId(raw) {
|
|
2404
|
+
return toNonEmptyStringBrand(raw, "payrollRunId");
|
|
2405
|
+
}
|
|
2406
|
+
function toPayrollGroupId(raw) {
|
|
2407
|
+
return toNonEmptyStringBrand(raw, "payrollGroupId");
|
|
2408
|
+
}
|
|
2401
2409
|
function toOrgId(raw) {
|
|
2402
2410
|
return toNonEmptyStringBrand(raw, "orgId");
|
|
2403
2411
|
}
|
|
@@ -2675,6 +2683,15 @@ const CAPXUL_FUNCTIONS = {
|
|
|
2675
2683
|
resumeBootstrapSubmission: "org/actions:resumeBootstrapSubmission",
|
|
2676
2684
|
submitBootstrap: "org/actions:submitBootstrap"
|
|
2677
2685
|
},
|
|
2686
|
+
"payroll/actions": { authorizeRun: "payroll/actions:authorizeRun" },
|
|
2687
|
+
"payroll/mutations": {
|
|
2688
|
+
removeGroup: "payroll/mutations:removeGroup",
|
|
2689
|
+
saveGroup: "payroll/mutations:saveGroup"
|
|
2690
|
+
},
|
|
2691
|
+
"payroll/queries": {
|
|
2692
|
+
groups: "payroll/queries:groups",
|
|
2693
|
+
runs: "payroll/queries:runs"
|
|
2694
|
+
},
|
|
2678
2695
|
"permission/actions": { verify: "permission/actions:verify" },
|
|
2679
2696
|
"permission/mutations": { command: "permission/mutations:command" },
|
|
2680
2697
|
"permission/queries": {
|
|
@@ -3868,7 +3885,7 @@ Schema.Struct({
|
|
|
3868
3885
|
items: Schema.Array(OrganizationPaymentExecutionItemSchema),
|
|
3869
3886
|
lineage: Schema.optional(PaymentCommandLineageSchema)
|
|
3870
3887
|
});
|
|
3871
|
-
Schema.Struct({
|
|
3888
|
+
const PreparedPaymentCommandExecutionSchema = Schema.Struct({
|
|
3872
3889
|
executionId: MoneyExecutionIdSchema,
|
|
3873
3890
|
commandId: PaymentCommandIdSchema,
|
|
3874
3891
|
paymentIds: Schema.Array(PaymentIdSchema),
|
|
@@ -3961,6 +3978,69 @@ Schema.Struct({
|
|
|
3961
3978
|
userOpHash: Bytes32Schema,
|
|
3962
3979
|
value: PermissionResourceSchema
|
|
3963
3980
|
});
|
|
3981
|
+
const PayrollRunStatusSchema = Schema.Literals([
|
|
3982
|
+
"draft",
|
|
3983
|
+
"authorized",
|
|
3984
|
+
"settled"
|
|
3985
|
+
]);
|
|
3986
|
+
const PayrollRunIdSchema = Schema.String.pipe(Schema.refine((value) => /^payroll_run_[0-9a-f]{64}$/u.test(value), { message: "payrollRunId must be a payroll_run_ digest identifier" }));
|
|
3987
|
+
const SignedMinorUnitSchema = Schema.String.pipe(Schema.refine((value) => /^-?(0|[1-9][0-9]*)$/u.test(value), { message: "must be an integer minor-unit string" }));
|
|
3988
|
+
const MinorUnitSchema = Schema.String.pipe(Schema.refine((value) => /^(0|[1-9][0-9]*)$/u.test(value), { message: "must be a non-negative integer minor-unit string" }));
|
|
3989
|
+
const PayrollRunItemInputSchema = Schema.Struct({
|
|
3990
|
+
to: PaymentRef,
|
|
3991
|
+
partyId: nonEmpty("partyId"),
|
|
3992
|
+
gross: MinorUnitSchema,
|
|
3993
|
+
net: MinorUnitSchema,
|
|
3994
|
+
adjustments: Schema.Array(Schema.Struct({
|
|
3995
|
+
label: Schema.String,
|
|
3996
|
+
amount: SignedMinorUnitSchema
|
|
3997
|
+
}))
|
|
3998
|
+
});
|
|
3999
|
+
Schema.Struct({
|
|
4000
|
+
orgId: nonEmpty("orgId"),
|
|
4001
|
+
permissionId: PermissionIdSchema,
|
|
4002
|
+
requestKey: nonEmpty("requestKey"),
|
|
4003
|
+
signerAddress: AddressSchema$1,
|
|
4004
|
+
period: Schema.Struct({
|
|
4005
|
+
start: nonNegativeInteger("period.start"),
|
|
4006
|
+
end: nonNegativeInteger("period.end")
|
|
4007
|
+
}),
|
|
4008
|
+
items: Schema.Array(PayrollRunItemInputSchema)
|
|
4009
|
+
});
|
|
4010
|
+
const PayrollRunSchema = Schema.Struct({
|
|
4011
|
+
id: PayrollRunIdSchema,
|
|
4012
|
+
status: PayrollRunStatusSchema,
|
|
4013
|
+
periodStart: nonNegativeInteger("periodStart"),
|
|
4014
|
+
periodEnd: nonNegativeInteger("periodEnd"),
|
|
4015
|
+
total: FinancialOpsMoney,
|
|
4016
|
+
recipientCount: nonNegativeInteger("recipientCount")
|
|
4017
|
+
});
|
|
4018
|
+
Schema.Struct({
|
|
4019
|
+
runs: Schema.Array(PayrollRunSchema),
|
|
4020
|
+
settledThisMonth: FinancialOpsMoney
|
|
4021
|
+
});
|
|
4022
|
+
Schema.Struct({
|
|
4023
|
+
run: PayrollRunSchema,
|
|
4024
|
+
execution: PreparedPaymentCommandExecutionSchema
|
|
4025
|
+
});
|
|
4026
|
+
const PayrollGroupIdSchema = Schema.String.pipe(Schema.refine((value) => /^payroll_group_[0-9A-Z]{26}$/u.test(value), { message: "payrollGroupId must be a payroll_group_ ULID identifier" }));
|
|
4027
|
+
const PayrollGroupMemberSchema = Schema.Struct({
|
|
4028
|
+
partyId: PartyIdSchema,
|
|
4029
|
+
amount: Schema.String,
|
|
4030
|
+
currency: CurrencyCodeSchema$1
|
|
4031
|
+
});
|
|
4032
|
+
Schema.Struct({
|
|
4033
|
+
id: PayrollGroupIdSchema,
|
|
4034
|
+
name: nonEmpty("name"),
|
|
4035
|
+
tone: Schema.String,
|
|
4036
|
+
members: Schema.Array(PayrollGroupMemberSchema)
|
|
4037
|
+
});
|
|
4038
|
+
Schema.Struct({
|
|
4039
|
+
id: Schema.optional(PayrollGroupIdSchema),
|
|
4040
|
+
name: Schema.String,
|
|
4041
|
+
tone: Schema.String,
|
|
4042
|
+
members: Schema.Array(PayrollGroupMemberSchema)
|
|
4043
|
+
});
|
|
3964
4044
|
`
|
|
3965
4045
|
.capxul-doc{--ink:#1d1d1f;--muted:#6e6e73;--line:#e7e7ea;--accent:#0a7d4b;--bg:#fff;
|
|
3966
4046
|
font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif;
|
|
@@ -4159,6 +4239,9 @@ const SENSITIVE_MATERIAL_PATTERNS = [
|
|
|
4159
4239
|
/eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/u,
|
|
4160
4240
|
/(?:(?: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_-]*/iu
|
|
4161
4241
|
];
|
|
4242
|
+
const RAW_PRIVATE_KEY_MASK = /(^|[^a-fA-F0-9])[a-fA-F0-9]{64}(?=$|[^a-fA-F0-9])/gu;
|
|
4243
|
+
const KNOWN_CREDENTIAL_MASK = /(?:(?: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;
|
|
4244
|
+
const LABELLED_SECRET_MASK = /\b(api[ _-]?key|access[ _-]?token|token|secret|password|passphrase|private[ _-]?key|authorization|cookie|signature|request[ _-]?body|credential|otp|one[ _-]?time[ _-]?(?:password|code)|verification[ _-]?code)\b\s*[:=]\s*(?:"[^"]*"|'[^']*'|[^\s,;]+)/giu;
|
|
4162
4245
|
/**
|
|
4163
4246
|
* Reject: does the value carry any known secret material? Best effort — callers
|
|
4164
4247
|
* drop the whole value on a match; a false negative is a leak, a false positive
|
|
@@ -4167,6 +4250,14 @@ const SENSITIVE_MATERIAL_PATTERNS = [
|
|
|
4167
4250
|
function containsSensitiveMaterial(value) {
|
|
4168
4251
|
return SENSITIVE_MATERIAL_PATTERNS.some((pattern) => pattern.test(value));
|
|
4169
4252
|
}
|
|
4253
|
+
/**
|
|
4254
|
+
* Mask: return the value with every known secret rewritten to `[REDACTED]`,
|
|
4255
|
+
* preserving surrounding text. Used where a value must still be shown (log
|
|
4256
|
+
* lines, issue bodies) but must not carry live credentials.
|
|
4257
|
+
*/
|
|
4258
|
+
function redactSecrets(value) {
|
|
4259
|
+
return value.replace(/\bBearer\s+[^\s,;]+/giu, "Bearer [REDACTED]").replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/gu, "[REDACTED]").replace(/\b0x[a-fA-F0-9]{40,}\b/gu, "[REDACTED]").replace(RAW_PRIVATE_KEY_MASK, "$1[REDACTED]").replace(KNOWN_CREDENTIAL_MASK, "[REDACTED]").replace(LABELLED_SECRET_MASK, (_match, label) => `${label}=[REDACTED]`);
|
|
4260
|
+
}
|
|
4170
4261
|
//#endregion
|
|
4171
4262
|
//#region ../../packages/wire/src/observation-context.ts
|
|
4172
4263
|
/** Single bounded HTTP carrier used before a Convex action envelope exists. */
|
|
@@ -6030,8 +6121,8 @@ var ActorFailure = class extends Error {
|
|
|
6030
6121
|
event;
|
|
6031
6122
|
details;
|
|
6032
6123
|
_tag = "ActorFailure";
|
|
6033
|
-
constructor(reason, machine, state, event, details) {
|
|
6034
|
-
super(`${machine}:${state}:${event} ${reason}
|
|
6124
|
+
constructor(reason, machine, state, event, details, cause) {
|
|
6125
|
+
super(`${machine}:${state}:${event} ${reason}`, cause === void 0 ? void 0 : { cause });
|
|
6035
6126
|
this.reason = reason;
|
|
6036
6127
|
this.machine = machine;
|
|
6037
6128
|
this.state = state;
|
|
@@ -6106,8 +6197,8 @@ const boot = (spec, options = {}) => Effect.gen(function* () {
|
|
|
6106
6197
|
defect(cause);
|
|
6107
6198
|
}
|
|
6108
6199
|
};
|
|
6109
|
-
const makeFailure = (state, event, reason, details) => new ActorFailure(reason, spec.machine, spec.label(state), event._tag, details);
|
|
6110
|
-
const nonApplied = (state, event, reason, outcome, env) => {
|
|
6200
|
+
const makeFailure = (state, event, reason, details, cause) => new ActorFailure(reason, spec.machine, spec.label(state), event._tag, details, cause);
|
|
6201
|
+
const nonApplied = (state, event, reason, outcome, env, failure) => {
|
|
6111
6202
|
const slot = env.origin?.slot ?? spec.slot(event);
|
|
6112
6203
|
return copyInvocationObservation(env.invocation, {
|
|
6113
6204
|
machine: spec.machine,
|
|
@@ -6118,7 +6209,8 @@ const boot = (spec, options = {}) => Effect.gen(function* () {
|
|
|
6118
6209
|
outcome,
|
|
6119
6210
|
duration_ms: duration(env.startedAt),
|
|
6120
6211
|
...withCarriage(env.invocation),
|
|
6121
|
-
...outcome === "refused" ? { refusal_code: reason } : { error_code: reason }
|
|
6212
|
+
...outcome === "refused" ? { refusal_code: reason } : { error_code: reason },
|
|
6213
|
+
...failure === void 0 ? {} : { failure }
|
|
6122
6214
|
});
|
|
6123
6215
|
};
|
|
6124
6216
|
const applied = (from, to, event, slot, epoch, env) => copyInvocationObservation(env.invocation, {
|
|
@@ -6171,12 +6263,13 @@ const boot = (spec, options = {}) => Effect.gen(function* () {
|
|
|
6171
6263
|
slots.delete(env.origin.slot);
|
|
6172
6264
|
defect(exit.defect);
|
|
6173
6265
|
const event = { _tag: env.origin.event };
|
|
6174
|
-
const
|
|
6266
|
+
const died = {
|
|
6175
6267
|
code: "WORK_DIED",
|
|
6176
|
-
message: "Identity work died"
|
|
6177
|
-
}
|
|
6178
|
-
yield*
|
|
6179
|
-
yield*
|
|
6268
|
+
message: exit.defect instanceof Error ? exit.defect.message : "Identity work died"
|
|
6269
|
+
};
|
|
6270
|
+
const failedState = yield* recoverFailure(state, env.origin, died);
|
|
6271
|
+
yield* emit(nonApplied(failedState, event, "WORK_DIED", "failed", env, died));
|
|
6272
|
+
yield* failReply(held.reply, makeFailure(failedState, event, "WORK_DIED", void 0, died));
|
|
6180
6273
|
return;
|
|
6181
6274
|
}
|
|
6182
6275
|
if (exit.failure !== void 0) {
|
|
@@ -6184,9 +6277,9 @@ const boot = (spec, options = {}) => Effect.gen(function* () {
|
|
|
6184
6277
|
const outcome = exit.failure.code === "CANCELLED" ? "cancelled" : "failed";
|
|
6185
6278
|
const event = { _tag: env.origin.event };
|
|
6186
6279
|
const failedState = exit.failure === timeoutFailure || exit.failure === cancelledFailure ? yield* recoverFailure(state, env.origin, exit.failure) : state;
|
|
6187
|
-
yield* emit(nonApplied(failedState, event, exit.failure.code, outcome, env));
|
|
6280
|
+
yield* emit(nonApplied(failedState, event, exit.failure.code, outcome, env, exit.failure));
|
|
6188
6281
|
const details = exit.failure === timeoutFailure ? { reason: "timeout" } : void 0;
|
|
6189
|
-
yield* failReply(held.reply, makeFailure(failedState, event, exit.failure.code, details));
|
|
6282
|
+
yield* failReply(held.reply, makeFailure(failedState, event, exit.failure.code, details, exit.failure.error ?? exit.failure));
|
|
6190
6283
|
return;
|
|
6191
6284
|
}
|
|
6192
6285
|
yield* finish(env.origin, state);
|
|
@@ -7742,7 +7835,10 @@ function canonicalJson(value) {
|
|
|
7742
7835
|
async function fingerprintPaymentIntent(intent) {
|
|
7743
7836
|
return keccak256(toBytes(canonicalJson(intent)));
|
|
7744
7837
|
}
|
|
7745
|
-
|
|
7838
|
+
function matchesIntent(expected) {
|
|
7839
|
+
return async (request) => await fingerprintPaymentIntent(request) === await fingerprintPaymentIntent(expected);
|
|
7840
|
+
}
|
|
7841
|
+
async function executePrepared(deps, prepare, isExpectedRequest, signal) {
|
|
7746
7842
|
if (isAborted$1(signal)) return {
|
|
7747
7843
|
ok: false,
|
|
7748
7844
|
error: Errors.cancelled({ operation: "payments" })
|
|
@@ -7763,7 +7859,7 @@ async function executePrepared(deps, prepare, expectedRequest, signal) {
|
|
|
7763
7859
|
}
|
|
7764
7860
|
const prepared = await prepare(signerAddress);
|
|
7765
7861
|
if (!prepared.ok) return prepared;
|
|
7766
|
-
if (await
|
|
7862
|
+
if (!await isExpectedRequest(prepared.value.request)) return {
|
|
7767
7863
|
ok: false,
|
|
7768
7864
|
error: Errors.invalidInput("payment", "prepared command mismatch")
|
|
7769
7865
|
};
|
|
@@ -7798,13 +7894,13 @@ function executePaymentLifecycle(deps, intent, signal) {
|
|
|
7798
7894
|
return executePrepared(deps, (signerAddress) => runIfActive(signal, "payments.prepareLifecycleExecution", () => deps.convexCall.action(deps.functions.preparePaymentLifecycleExecution, { input: {
|
|
7799
7895
|
signerAddress,
|
|
7800
7896
|
intent
|
|
7801
|
-
} })), intent, signal);
|
|
7897
|
+
} })), matchesIntent(intent), signal);
|
|
7802
7898
|
}
|
|
7803
7899
|
function executeOrganizationPayment(deps, input, signal) {
|
|
7804
7900
|
return executePrepared(deps, (signerAddress) => runIfActive(signal, "organizationPayments.prepareExecution", () => deps.convexCall.action(deps.functions.prepareOrganizationPaymentExecution, { input: {
|
|
7805
7901
|
...input,
|
|
7806
7902
|
signerAddress
|
|
7807
|
-
} })), input, signal);
|
|
7903
|
+
} })), matchesIntent(input), signal);
|
|
7808
7904
|
}
|
|
7809
7905
|
//#endregion
|
|
7810
7906
|
//#region ../../packages/sdk/src/surface/money.ts
|
|
@@ -8816,7 +8912,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
8816
8912
|
}
|
|
8817
8913
|
//#endregion
|
|
8818
8914
|
//#region ../../packages/sdk/package.json
|
|
8819
|
-
var version = "2.
|
|
8915
|
+
var version = "2.5.1";
|
|
8820
8916
|
//#endregion
|
|
8821
8917
|
//#region ../../packages/observability/src/engineering.ts
|
|
8822
8918
|
const ENGINEERING_CAPXUL_ENVS = [
|
|
@@ -9718,6 +9814,33 @@ function bootstrapErrorFromCapxul(kind, error) {
|
|
|
9718
9814
|
var BootstrapPortTag = class extends Context.Service()("@capxul/sdk/ports/BootstrapPort") {};
|
|
9719
9815
|
//#endregion
|
|
9720
9816
|
//#region ../../packages/sdk/src/adapters/bootstrap/HttpBootstrapAdapter.ts
|
|
9817
|
+
const DEFAULT_RETRY = {
|
|
9818
|
+
attempts: 2,
|
|
9819
|
+
baseDelayMs: 400
|
|
9820
|
+
};
|
|
9821
|
+
/** Request-side statuses a proxy or backend returns while momentarily unable to serve. */
|
|
9822
|
+
const TRANSIENT_HTTP_STATUSES = new Set([
|
|
9823
|
+
408,
|
|
9824
|
+
425,
|
|
9825
|
+
429
|
|
9826
|
+
]);
|
|
9827
|
+
/** Every 5xx is a server-side condition worth one more try; the client sent nothing wrong. */
|
|
9828
|
+
function isTransientHttpStatus(status) {
|
|
9829
|
+
return status >= 500 || TRANSIENT_HTTP_STATUSES.has(status);
|
|
9830
|
+
}
|
|
9831
|
+
/**
|
|
9832
|
+
* A transient HTTP status is worth one more try. The bootstrap call crosses
|
|
9833
|
+
* the host's own proxy before it reaches Convex, and every observed failure
|
|
9834
|
+
* of that hop cleared on a retry seconds later. A network rejection (offline,
|
|
9835
|
+
* DNS, CORS) is not retried: it does not clear in a second, and the caller
|
|
9836
|
+
* surfaces it as `NETWORK_ERROR` at once. Auth and input rejections are
|
|
9837
|
+
* deterministic and never retried.
|
|
9838
|
+
*/
|
|
9839
|
+
function isTransientBootstrapFailure(error) {
|
|
9840
|
+
if (error.kind !== "provider") return false;
|
|
9841
|
+
const status = error.details?.httpStatus;
|
|
9842
|
+
return typeof status === "number" && isTransientHttpStatus(status);
|
|
9843
|
+
}
|
|
9721
9844
|
async function safeText(res) {
|
|
9722
9845
|
try {
|
|
9723
9846
|
return await res.text();
|
|
@@ -9729,12 +9852,21 @@ var HttpBootstrapAdapter = class {
|
|
|
9729
9852
|
bootstrapBaseUrl;
|
|
9730
9853
|
fetchImpl;
|
|
9731
9854
|
observation;
|
|
9855
|
+
retry;
|
|
9732
9856
|
constructor(deps) {
|
|
9733
9857
|
this.bootstrapBaseUrl = deps.bootstrapBaseUrl.replace(/\/$/, "");
|
|
9734
9858
|
this.observation = deps.observation;
|
|
9859
|
+
this.retry = deps.retry ?? DEFAULT_RETRY;
|
|
9735
9860
|
this.fetchImpl = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
9736
9861
|
}
|
|
9737
9862
|
resolve(input) {
|
|
9863
|
+
return this.attempt(input).pipe(Effect.retry({
|
|
9864
|
+
times: this.retry.attempts,
|
|
9865
|
+
while: isTransientBootstrapFailure,
|
|
9866
|
+
schedule: Schedule.exponential(Duration.millis(this.retry.baseDelayMs))
|
|
9867
|
+
}));
|
|
9868
|
+
}
|
|
9869
|
+
attempt(input) {
|
|
9738
9870
|
return Effect.tryPromise({
|
|
9739
9871
|
try: () => {
|
|
9740
9872
|
const headers = {
|
|
@@ -9787,7 +9919,17 @@ var HttpBootstrapAdapter = class {
|
|
|
9787
9919
|
return Effect.promise(() => safeText(res)).pipe(Effect.flatMap((body) => {
|
|
9788
9920
|
if (res.status === 401 || body.startsWith("NOT_AUTHENTICATED")) return Effect.fail(bootstrapErrorFromCapxul("notAuthenticated", Errors.notAuthenticated()));
|
|
9789
9921
|
if (res.status === 400 || body.startsWith("INVALID_INPUT")) return Effect.fail(bootstrapErrorFromCapxul("invalidInput", Errors.invalidInput("publishableKey", "rejected by bootstrap")));
|
|
9790
|
-
|
|
9922
|
+
const responseBody = body.slice(0, 300);
|
|
9923
|
+
const edgeError = res.headers?.get?.("x-vercel-error") ?? void 0;
|
|
9924
|
+
const edgeRequestId = res.headers?.get?.("x-vercel-id") ?? void 0;
|
|
9925
|
+
return Effect.fail(bootstrapErrorFromCapxul("provider", Errors.providerError("convex", "bootstrap", /* @__PURE__ */ new Error(`HTTP ${res.status}${edgeError === void 0 ? "" : ` ${edgeError}`}`), {
|
|
9926
|
+
httpStatus: res.status,
|
|
9927
|
+
details: {
|
|
9928
|
+
...responseBody.length === 0 ? {} : { responseBody },
|
|
9929
|
+
...edgeError === void 0 ? {} : { edgeError },
|
|
9930
|
+
...edgeRequestId === void 0 ? {} : { edgeRequestId }
|
|
9931
|
+
}
|
|
9932
|
+
})));
|
|
9791
9933
|
}));
|
|
9792
9934
|
}
|
|
9793
9935
|
};
|
|
@@ -38472,7 +38614,7 @@ function makePermissionMethods(deps, orgId) {
|
|
|
38472
38614
|
}
|
|
38473
38615
|
//#endregion
|
|
38474
38616
|
//#region ../../packages/sdk/src/surface/organization-payments.ts
|
|
38475
|
-
function executionDependencies(input) {
|
|
38617
|
+
function executionDependencies$1(input) {
|
|
38476
38618
|
return input.actor === void 0 || input.chainId === void 0 || input.signer === void 0 ? null : {
|
|
38477
38619
|
actor: input.actor,
|
|
38478
38620
|
chainId: input.chainId,
|
|
@@ -38489,7 +38631,7 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
|
|
|
38489
38631
|
ok: false,
|
|
38490
38632
|
error: Errors.cancelled({ operation })
|
|
38491
38633
|
};
|
|
38492
|
-
const execution = executionDependencies(deps);
|
|
38634
|
+
const execution = executionDependencies$1(deps);
|
|
38493
38635
|
if (execution === null) return {
|
|
38494
38636
|
ok: false,
|
|
38495
38637
|
error: Errors.notImplemented("organizationPayments", "executionComposition")
|
|
@@ -38584,6 +38726,197 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
|
|
|
38584
38726
|
};
|
|
38585
38727
|
}
|
|
38586
38728
|
//#endregion
|
|
38729
|
+
//#region ../../packages/sdk/src/contract/payroll.ts
|
|
38730
|
+
const payrollContract = {
|
|
38731
|
+
authorizeRun: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/actions"].authorizeRun),
|
|
38732
|
+
runs: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].runs),
|
|
38733
|
+
groups: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].groups),
|
|
38734
|
+
saveGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].saveGroup),
|
|
38735
|
+
removeGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].removeGroup)
|
|
38736
|
+
};
|
|
38737
|
+
//#endregion
|
|
38738
|
+
//#region ../../packages/sdk/src/surface/payroll.ts
|
|
38739
|
+
const AUTHORIZE_RUN = "payroll.authorizeRun";
|
|
38740
|
+
function toPayrollRun(wire) {
|
|
38741
|
+
return {
|
|
38742
|
+
id: toPayrollRunId(wire.id),
|
|
38743
|
+
status: wire.status,
|
|
38744
|
+
periodStart: wire.periodStart,
|
|
38745
|
+
periodEnd: wire.periodEnd,
|
|
38746
|
+
total: wire.total,
|
|
38747
|
+
recipientCount: wire.recipientCount
|
|
38748
|
+
};
|
|
38749
|
+
}
|
|
38750
|
+
function toPayrollRuns(wire) {
|
|
38751
|
+
return {
|
|
38752
|
+
runs: wire.runs.map(toPayrollRun),
|
|
38753
|
+
settledThisMonth: wire.settledThisMonth
|
|
38754
|
+
};
|
|
38755
|
+
}
|
|
38756
|
+
function toPayrollGroup(wire) {
|
|
38757
|
+
return {
|
|
38758
|
+
id: toPayrollGroupId(wire.id),
|
|
38759
|
+
name: wire.name,
|
|
38760
|
+
tone: wire.tone,
|
|
38761
|
+
members: wire.members.map((member) => ({
|
|
38762
|
+
partyId: member.partyId,
|
|
38763
|
+
amount: member.amount,
|
|
38764
|
+
currency: member.currency
|
|
38765
|
+
}))
|
|
38766
|
+
};
|
|
38767
|
+
}
|
|
38768
|
+
const MINOR_UNIT_INTEGER = /^-?\d+$/u;
|
|
38769
|
+
/**
|
|
38770
|
+
* One prepared `Money` counted in the minor units `net` is written in, or
|
|
38771
|
+
* `null` when the value is not a decimal number. `amount.value` is a DECIMAL
|
|
38772
|
+
* string (`"200"` at 6 decimals is 200000000 minor units), so comparing it to
|
|
38773
|
+
* `net` directly would compare two different units and pass nothing.
|
|
38774
|
+
*/
|
|
38775
|
+
function minorUnits(amount) {
|
|
38776
|
+
const [whole = "", fraction = ""] = amount.value.split(".");
|
|
38777
|
+
if (!/^\d+$/u.test(whole) || !/^\d*$/u.test(fraction) || fraction.length > amount.decimals) return null;
|
|
38778
|
+
return BigInt(whole + fraction.padEnd(amount.decimals, "0"));
|
|
38779
|
+
}
|
|
38780
|
+
/**
|
|
38781
|
+
* One prepared item must pay the person this caller named, the amount this
|
|
38782
|
+
* caller set, under a payslip that attests to the same figures.
|
|
38783
|
+
*
|
|
38784
|
+
* `issuedAt` and `employerRef` are server facts the caller cannot contradict,
|
|
38785
|
+
* so they are not compared. Everything the caller DID supply is: the recipient
|
|
38786
|
+
* `Ref`, the transfer amount against `net`, and the payslip's employee, gross
|
|
38787
|
+
* and net. Adjustments are not in the signed command at all — the backend
|
|
38788
|
+
* enforces `gross + Σ adjustments === net` (ADR-0022 R8), and gross and net
|
|
38789
|
+
* being right is what the signer can prove here.
|
|
38790
|
+
*/
|
|
38791
|
+
function isRunItem(prepared, item) {
|
|
38792
|
+
if (prepared === void 0) return false;
|
|
38793
|
+
const payslip = prepared.document;
|
|
38794
|
+
return canonicalJson(prepared.to) === canonicalJson(item.to) && prepared.paymentType === "payroll" && MINOR_UNIT_INTEGER.test(item.net) && minorUnits(prepared.amount) === BigInt(item.net) && payslip?.primaryType === "Payslip" && payslip.message.employeeRef === item.partyId && payslip.message.gross === item.gross && payslip.message.net === item.net;
|
|
38795
|
+
}
|
|
38796
|
+
/**
|
|
38797
|
+
* The batch the backend derived from a payroll intent must be the batch this
|
|
38798
|
+
* caller asked for, checked before the digest is signed.
|
|
38799
|
+
*
|
|
38800
|
+
* The payslip envelope on each item is server-built and carries the run row's
|
|
38801
|
+
* own `issuedAt`, so the batch cannot be fingerprinted against a local copy
|
|
38802
|
+
* (`matchesIntent` is unavailable here). What CAN be verified is every field
|
|
38803
|
+
* the caller supplied — the org, the Budget, the request key, and per item the
|
|
38804
|
+
* recipient, the amount and the payslip figures — plus the lineage binding the
|
|
38805
|
+
* batch to the run just written. A prepared command that pays a different
|
|
38806
|
+
* person, a different amount, from a different Budget, or under a different
|
|
38807
|
+
* run never reaches the signer.
|
|
38808
|
+
*/
|
|
38809
|
+
function isRunBatch(input) {
|
|
38810
|
+
return (request) => {
|
|
38811
|
+
const batch = request;
|
|
38812
|
+
return Promise.resolve(batch.orgId === input.orgId && batch.permissionId === input.permissionId && batch.requestKey === input.requestKey && batch.lineage?.kind === "payroll" && batch.lineage.runId === input.runId && batch.items?.length === input.items.length && input.items.every((item, index) => isRunItem(batch.items?.[index], item)));
|
|
38813
|
+
};
|
|
38814
|
+
}
|
|
38815
|
+
function executionDependencies(deps) {
|
|
38816
|
+
return deps.actor === void 0 || deps.chainId === void 0 || deps.signer === void 0 ? null : {
|
|
38817
|
+
actor: deps.actor,
|
|
38818
|
+
chainId: deps.chainId,
|
|
38819
|
+
convexCall: deps.convexCall,
|
|
38820
|
+
functions: moneyExecutionContract,
|
|
38821
|
+
signer: deps.signer
|
|
38822
|
+
};
|
|
38823
|
+
}
|
|
38824
|
+
function makePayrollMethods(deps, orgId) {
|
|
38825
|
+
const requestKeyScope = deps.requestKeyScope ?? `client-${crypto.randomUUID()}`;
|
|
38826
|
+
async function authorize(input, signal) {
|
|
38827
|
+
const execution = executionDependencies(deps);
|
|
38828
|
+
if (execution === null) return {
|
|
38829
|
+
ok: false,
|
|
38830
|
+
error: Errors.notImplemented("payroll", "executionComposition")
|
|
38831
|
+
};
|
|
38832
|
+
const requestKey = await paymentRequestKeyLifecycle(`${requestKeyScope}:${AUTHORIZE_RUN}`, {
|
|
38833
|
+
orgId,
|
|
38834
|
+
input
|
|
38835
|
+
}, input.requestKey);
|
|
38836
|
+
let authorized;
|
|
38837
|
+
const submitted = await executePrepared(execution, async (signerAddress) => {
|
|
38838
|
+
const prepared = await runIfActive(signal, AUTHORIZE_RUN, () => deps.convexCall.action(payrollContract.authorizeRun, { input: {
|
|
38839
|
+
orgId,
|
|
38840
|
+
permissionId: input.permissionId,
|
|
38841
|
+
requestKey: requestKey.key,
|
|
38842
|
+
signerAddress,
|
|
38843
|
+
period: input.period,
|
|
38844
|
+
items: input.items
|
|
38845
|
+
} }));
|
|
38846
|
+
if (!prepared.ok) return prepared;
|
|
38847
|
+
authorized = prepared.value.run;
|
|
38848
|
+
return {
|
|
38849
|
+
ok: true,
|
|
38850
|
+
value: prepared.value.execution
|
|
38851
|
+
};
|
|
38852
|
+
}, (request) => authorized === void 0 || authorized.periodStart !== input.period.start || authorized.periodEnd !== input.period.end ? Promise.resolve(false) : isRunBatch({
|
|
38853
|
+
orgId,
|
|
38854
|
+
permissionId: input.permissionId,
|
|
38855
|
+
requestKey: requestKey.key,
|
|
38856
|
+
runId: authorized.id,
|
|
38857
|
+
items: input.items
|
|
38858
|
+
})(request), signal);
|
|
38859
|
+
try {
|
|
38860
|
+
await requestKey.finish(submitted.ok);
|
|
38861
|
+
} catch {}
|
|
38862
|
+
if (!submitted.ok) return submitted;
|
|
38863
|
+
return authorized === void 0 ? {
|
|
38864
|
+
ok: false,
|
|
38865
|
+
error: Errors.unknown()
|
|
38866
|
+
} : {
|
|
38867
|
+
ok: true,
|
|
38868
|
+
value: toPayrollRun(authorized)
|
|
38869
|
+
};
|
|
38870
|
+
}
|
|
38871
|
+
return {
|
|
38872
|
+
runs: (options) => runIfActive(options?.signal, "payroll.runs", () => Effect.map(deps.convexCall.query(payrollContract.runs, { orgId }), toPayrollRuns)),
|
|
38873
|
+
authorizeRun: async (input, options) => {
|
|
38874
|
+
if (options?.signal?.aborted === true) return {
|
|
38875
|
+
ok: false,
|
|
38876
|
+
error: Errors.cancelled({ operation: AUTHORIZE_RUN })
|
|
38877
|
+
};
|
|
38878
|
+
try {
|
|
38879
|
+
return await authorize(input, options?.signal);
|
|
38880
|
+
} catch (cause) {
|
|
38881
|
+
return {
|
|
38882
|
+
ok: false,
|
|
38883
|
+
error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
|
|
38884
|
+
};
|
|
38885
|
+
}
|
|
38886
|
+
},
|
|
38887
|
+
groups: {
|
|
38888
|
+
list: (options) => runIfActive(options?.signal, "payroll.groups.list", () => Effect.map(deps.convexCall.query(payrollContract.groups, { orgId }), (groups) => groups.map(toPayrollGroup))),
|
|
38889
|
+
save: (input, options) => runIfActive(options?.signal, "payroll.groups.save", () => Effect.map(deps.convexCall.mutation(payrollContract.saveGroup, {
|
|
38890
|
+
orgId,
|
|
38891
|
+
...input.id === void 0 ? {} : { id: String(input.id) },
|
|
38892
|
+
name: input.name,
|
|
38893
|
+
tone: input.tone,
|
|
38894
|
+
members: input.members
|
|
38895
|
+
}), toPayrollGroup)),
|
|
38896
|
+
remove: (id, options) => runIfActive(options?.signal, "payroll.groups.remove", () => Effect.map(deps.convexCall.mutation(payrollContract.removeGroup, {
|
|
38897
|
+
orgId,
|
|
38898
|
+
id
|
|
38899
|
+
}), () => void 0))
|
|
38900
|
+
}
|
|
38901
|
+
};
|
|
38902
|
+
}
|
|
38903
|
+
const payrollUnavailable = () => Promise.resolve({
|
|
38904
|
+
ok: false,
|
|
38905
|
+
error: Errors.notImplemented("payroll", "executionComposition")
|
|
38906
|
+
});
|
|
38907
|
+
/** The bundle an unconfigured client exposes — every verb refuses, none throws. */
|
|
38908
|
+
function makeUnavailablePayrollMethods() {
|
|
38909
|
+
return {
|
|
38910
|
+
runs: payrollUnavailable,
|
|
38911
|
+
authorizeRun: payrollUnavailable,
|
|
38912
|
+
groups: {
|
|
38913
|
+
list: payrollUnavailable,
|
|
38914
|
+
save: payrollUnavailable,
|
|
38915
|
+
remove: payrollUnavailable
|
|
38916
|
+
}
|
|
38917
|
+
};
|
|
38918
|
+
}
|
|
38919
|
+
//#endregion
|
|
38587
38920
|
//#region ../../packages/sdk/src/surface/_shared/org-telemetry.ts
|
|
38588
38921
|
/** Extract the domain from an email for telemetry (never the local part / PII). */
|
|
38589
38922
|
function emailDomain$1(email) {
|
|
@@ -39121,6 +39454,13 @@ function makeOrgMethods(deps) {
|
|
|
39121
39454
|
...deps.actor === void 0 ? {} : { actor: deps.actor },
|
|
39122
39455
|
...deps.chainId === void 0 ? {} : { chainId: Number(deps.chainId) },
|
|
39123
39456
|
...deps.signer === void 0 ? {} : { signer: deps.signer }
|
|
39457
|
+
}, String(orgId)),
|
|
39458
|
+
payroll: convexCall === void 0 ? makeUnavailablePayrollMethods() : makePayrollMethods({
|
|
39459
|
+
convexCall,
|
|
39460
|
+
...deps.requestKeyScope === void 0 ? {} : { requestKeyScope: deps.requestKeyScope },
|
|
39461
|
+
...deps.actor === void 0 ? {} : { actor: deps.actor },
|
|
39462
|
+
...deps.chainId === void 0 ? {} : { chainId: Number(deps.chainId) },
|
|
39463
|
+
...deps.signer === void 0 ? {} : { signer: deps.signer }
|
|
39124
39464
|
}, String(orgId))
|
|
39125
39465
|
};
|
|
39126
39466
|
}
|
|
@@ -39433,23 +39773,50 @@ function observeSdkClient(client, adapter, snapshot) {
|
|
|
39433
39773
|
}
|
|
39434
39774
|
}
|
|
39435
39775
|
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
39436
|
-
function observeFailedResult(result, adapter, operation) {
|
|
39437
|
-
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterSnapshot(adapter));
|
|
39776
|
+
function observeFailedResult(result, adapter, operation, origin) {
|
|
39777
|
+
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterSnapshot(adapter), origin);
|
|
39438
39778
|
return result;
|
|
39439
39779
|
}
|
|
39440
|
-
|
|
39780
|
+
/**
|
|
39781
|
+
* One failure, one event. The identity machine reports a failed transition
|
|
39782
|
+
* first; when the same `CapxulError` then surfaces as a public method result
|
|
39783
|
+
* (directly or down its `cause` chain), the boundary drops that second report.
|
|
39784
|
+
* Only machine-reported errors are remembered, so a caller that reuses one
|
|
39785
|
+
* error object across unrelated public methods still sees every report.
|
|
39786
|
+
*/
|
|
39787
|
+
const machineReportedCauses = /* @__PURE__ */ new WeakSet();
|
|
39788
|
+
function reportedByMachine(cause) {
|
|
39789
|
+
let link = cause;
|
|
39790
|
+
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
39791
|
+
if (machineReportedCauses.has(link)) return true;
|
|
39792
|
+
link = link.cause;
|
|
39793
|
+
}
|
|
39794
|
+
return false;
|
|
39795
|
+
}
|
|
39796
|
+
function report(adapter, kind, operation, cause, invocation, origin) {
|
|
39797
|
+
if (origin === "machine") {
|
|
39798
|
+
let link = cause;
|
|
39799
|
+
for (let depth = 0; depth < 8 && typeof link === "object" && link !== null; depth++) {
|
|
39800
|
+
machineReportedCauses.add(link);
|
|
39801
|
+
link = link.cause;
|
|
39802
|
+
}
|
|
39803
|
+
} else if (reportedByMachine(cause)) return;
|
|
39441
39804
|
const operationName = normalizeOperation(operation);
|
|
39442
39805
|
const kindName = normalizeErrorKind(errorKind(cause));
|
|
39443
39806
|
const context = sanitizeObservationContext({
|
|
39444
39807
|
...invocation.context,
|
|
39445
39808
|
...isCapxulError(cause) && cause.correlationId !== void 0 ? { correlationId: cause.correlationId } : {}
|
|
39446
39809
|
});
|
|
39810
|
+
const detail = failureDetail(cause);
|
|
39811
|
+
const evidence = failureEvidence(cause);
|
|
39447
39812
|
const failure = markFailureInvocationSnapshot({
|
|
39448
|
-
exception: syntheticException(operationName, kindName),
|
|
39813
|
+
exception: syntheticException(operationName, kindName, evidence.message, evidence.stack),
|
|
39449
39814
|
sdkVersion: SDK_VERSION$1,
|
|
39450
39815
|
operation: operationName,
|
|
39451
39816
|
errorKind: kindName,
|
|
39452
|
-
...context === void 0 ? {} : { context }
|
|
39817
|
+
...context === void 0 ? {} : { context },
|
|
39818
|
+
...detail === void 0 ? {} : { detail },
|
|
39819
|
+
...evidence
|
|
39453
39820
|
}, {
|
|
39454
39821
|
active: invocation.active,
|
|
39455
39822
|
...context === void 0 ? {} : { context }
|
|
@@ -39485,6 +39852,72 @@ function ignoreDeliveryFailure(delivery) {
|
|
|
39485
39852
|
Promise.resolve(delivery).catch(() => void 0);
|
|
39486
39853
|
} catch {}
|
|
39487
39854
|
}
|
|
39855
|
+
const MAX_EVIDENCE_TEXT = 4e3;
|
|
39856
|
+
const MAX_CAUSE_DEPTH = 8;
|
|
39857
|
+
function evidenceText(value) {
|
|
39858
|
+
if (typeof value !== "string" || value.length === 0) return void 0;
|
|
39859
|
+
return redactSecrets(value).slice(0, MAX_EVIDENCE_TEXT);
|
|
39860
|
+
}
|
|
39861
|
+
/** A field whose NAME says credential is masked whatever its value looks like. */
|
|
39862
|
+
const CREDENTIAL_FIELD_NAME = /(?:otp|pass(?:word|wd|phrase)?|token|secret|credential|api[_-]?key|private[_-]?key|authorization|cookie|session)/iu;
|
|
39863
|
+
/** Copy a details object into a JSON-safe shape with every string masked. */
|
|
39864
|
+
function evidenceValue(value, depth = 0) {
|
|
39865
|
+
if (typeof value === "string") return evidenceText(value);
|
|
39866
|
+
if (typeof value === "number" || typeof value === "boolean" || value === null) return value;
|
|
39867
|
+
if (typeof value === "bigint") return value.toString();
|
|
39868
|
+
if (value instanceof Error) return evidenceText(value.message);
|
|
39869
|
+
if (depth >= 4 || typeof value !== "object") return void 0;
|
|
39870
|
+
if (Array.isArray(value)) return value.slice(0, 50).map((item) => evidenceValue(item, depth + 1));
|
|
39871
|
+
const copy = {};
|
|
39872
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
39873
|
+
if (CREDENTIAL_FIELD_NAME.test(key)) {
|
|
39874
|
+
copy[key] = "[REDACTED]";
|
|
39875
|
+
continue;
|
|
39876
|
+
}
|
|
39877
|
+
const safe = evidenceValue(nested, depth + 1);
|
|
39878
|
+
if (safe !== void 0) copy[key] = safe;
|
|
39879
|
+
}
|
|
39880
|
+
return copy;
|
|
39881
|
+
}
|
|
39882
|
+
/**
|
|
39883
|
+
* @internal The evidence in PostHog property shape, for product events that
|
|
39884
|
+
* name a failure (`bootstrap_failed`). Same keys as the `$exception` event.
|
|
39885
|
+
*/
|
|
39886
|
+
function failureEvidenceProps(cause) {
|
|
39887
|
+
const evidence = failureEvidence(cause);
|
|
39888
|
+
return {
|
|
39889
|
+
...evidence.message === void 0 ? {} : { error_message: evidence.message },
|
|
39890
|
+
...evidence.details === void 0 ? {} : { error_details: evidence.details },
|
|
39891
|
+
...evidence.causeChain === void 0 ? {} : { error_cause: evidence.causeChain.join(" <- ") }
|
|
39892
|
+
};
|
|
39893
|
+
}
|
|
39894
|
+
/** The real failure, masked for secrets only. Never throws. */
|
|
39895
|
+
function failureEvidence(cause) {
|
|
39896
|
+
try {
|
|
39897
|
+
const message = cause instanceof Error ? evidenceText(cause.message) : evidenceText(cause);
|
|
39898
|
+
const stack = cause instanceof Error ? evidenceText(cause.stack) : void 0;
|
|
39899
|
+
const details = isCapxulError(cause) && typeof cause.details === "object" && cause.details !== null ? evidenceValue(cause.details) : void 0;
|
|
39900
|
+
const causeChain = [];
|
|
39901
|
+
let previous = message;
|
|
39902
|
+
let link = cause instanceof Error ? cause.cause : void 0;
|
|
39903
|
+
for (let depth = 0; depth < MAX_CAUSE_DEPTH && link !== void 0 && link !== null; depth++) {
|
|
39904
|
+
const text = link instanceof Error ? evidenceText(link.message) : evidenceText(link);
|
|
39905
|
+
if (text !== void 0 && text !== previous) {
|
|
39906
|
+
causeChain.push(text);
|
|
39907
|
+
previous = text;
|
|
39908
|
+
}
|
|
39909
|
+
link = link instanceof Error ? link.cause : void 0;
|
|
39910
|
+
}
|
|
39911
|
+
return {
|
|
39912
|
+
...message === void 0 ? {} : { message },
|
|
39913
|
+
...details === void 0 || Object.keys(details).length === 0 ? {} : { details },
|
|
39914
|
+
...causeChain.length === 0 ? {} : { causeChain },
|
|
39915
|
+
...stack === void 0 ? {} : { stack }
|
|
39916
|
+
};
|
|
39917
|
+
} catch {
|
|
39918
|
+
return {};
|
|
39919
|
+
}
|
|
39920
|
+
}
|
|
39488
39921
|
function errorKind(cause) {
|
|
39489
39922
|
try {
|
|
39490
39923
|
if (isCapxulError(cause)) return normalizeErrorKind(cause.code);
|
|
@@ -39494,16 +39927,53 @@ function errorKind(cause) {
|
|
|
39494
39927
|
return "Error";
|
|
39495
39928
|
}
|
|
39496
39929
|
}
|
|
39930
|
+
/**
|
|
39931
|
+
* @internal Lift the enumerated discriminators off a `CapxulError` so a
|
|
39932
|
+
* boundary event says WHICH provider failed and HOW, not just `PROVIDER_ERROR`.
|
|
39933
|
+
* Shared by the failure boundary and the `bootstrap_failed` product event.
|
|
39934
|
+
*/
|
|
39935
|
+
function failureDetail(cause) {
|
|
39936
|
+
if (!isCapxulError(cause)) return void 0;
|
|
39937
|
+
const details = cause.details;
|
|
39938
|
+
if (typeof details !== "object" || details === null) return void 0;
|
|
39939
|
+
const source = details;
|
|
39940
|
+
return sanitizeFailureDetail({
|
|
39941
|
+
provider: source.provider,
|
|
39942
|
+
provider_operation: source.operation,
|
|
39943
|
+
failure_mode: source.failure_mode,
|
|
39944
|
+
reason: source.reason,
|
|
39945
|
+
http_status: source.httpStatus
|
|
39946
|
+
});
|
|
39947
|
+
}
|
|
39948
|
+
function sanitizeFailureDetail(input) {
|
|
39949
|
+
if (typeof input !== "object" || input === null) return void 0;
|
|
39950
|
+
const source = input;
|
|
39951
|
+
const detail = {};
|
|
39952
|
+
for (const key of [
|
|
39953
|
+
"provider",
|
|
39954
|
+
"provider_operation",
|
|
39955
|
+
"failure_mode",
|
|
39956
|
+
"reason"
|
|
39957
|
+
]) {
|
|
39958
|
+
const value = source[key];
|
|
39959
|
+
if (typeof value === "string" && ENUMERATED_DETAIL_RE.test(value)) detail[key] = value;
|
|
39960
|
+
}
|
|
39961
|
+
const status = source.http_status;
|
|
39962
|
+
if (typeof status === "number" && Number.isInteger(status) && status >= 100 && status <= 599) detail.http_status = status;
|
|
39963
|
+
return Object.keys(detail).length === 0 ? void 0 : detail;
|
|
39964
|
+
}
|
|
39965
|
+
/** Enumerated codes only (`convex`, `no-secure-context`, `bootstrap-encode`); free text fails. */
|
|
39966
|
+
const ENUMERATED_DETAIL_RE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u;
|
|
39497
39967
|
function normalizeOperation(value) {
|
|
39498
39968
|
return typeof value === "string" && /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,255}$/u.test(value) ? value : "unknown";
|
|
39499
39969
|
}
|
|
39500
39970
|
function normalizeErrorKind(value) {
|
|
39501
39971
|
return typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/u.test(value) ? value : "Error";
|
|
39502
39972
|
}
|
|
39503
|
-
function syntheticException(operation, kind) {
|
|
39504
|
-
const error =
|
|
39973
|
+
function syntheticException(operation, kind, message = EXCEPTION_MESSAGE, stack) {
|
|
39974
|
+
const error = new Error(message);
|
|
39505
39975
|
error.name = kind;
|
|
39506
|
-
error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)
|
|
39976
|
+
error.stack = `${kind}: ${error.message}\n at CapxulSdkBoundary.${operation} (capxul-sdk-observation://boundary/${operation}:1:1)` + (stack === void 0 ? "" : `\nCaused by: ${stack}`);
|
|
39507
39977
|
return error;
|
|
39508
39978
|
}
|
|
39509
39979
|
function isPromiseLike(value) {
|
|
@@ -39659,10 +40129,19 @@ function assembleCapxulClient(input) {
|
|
|
39659
40129
|
const unsubscribeProductTelemetry = actor.subscribeTransitions((record) => {
|
|
39660
40130
|
effectRunner.runPromise(executeIdentityProductObservation(input.ports.telemetry, record, actor.snapshot())).catch(() => {});
|
|
39661
40131
|
});
|
|
40132
|
+
const failureObservation = observation.failureObservation;
|
|
40133
|
+
const unsubscribeFailureObservation = failureObservation === void 0 ? () => {} : actor.subscribeTransitions((record) => {
|
|
40134
|
+
if (record.outcome !== "failed") return;
|
|
40135
|
+
observeFailedResult({
|
|
40136
|
+
ok: false,
|
|
40137
|
+
error: transitionError(record)
|
|
40138
|
+
}, failureObservation, `identity.${record.event}`, "machine");
|
|
40139
|
+
});
|
|
39662
40140
|
let stopPromise = null;
|
|
39663
40141
|
const stopActor = () => {
|
|
39664
40142
|
if (stopPromise === null) {
|
|
39665
40143
|
unsubscribeProductTelemetry();
|
|
40144
|
+
unsubscribeFailureObservation();
|
|
39666
40145
|
stopPromise = effectRunner.runPromise(Scope.close(scope, Exit.void));
|
|
39667
40146
|
}
|
|
39668
40147
|
return stopPromise;
|
|
@@ -39847,6 +40326,30 @@ function assembleCapxulClient(input) {
|
|
|
39847
40326
|
}
|
|
39848
40327
|
}, observation.failureObservation, observation.hostObservationSnapshot);
|
|
39849
40328
|
}
|
|
40329
|
+
function transitionError(record) {
|
|
40330
|
+
const failure = record.failure;
|
|
40331
|
+
if (failure?.error !== void 0) {
|
|
40332
|
+
const error = failure.error;
|
|
40333
|
+
if (record.correlation_id === void 0 || error.correlationId !== void 0) return error;
|
|
40334
|
+
return new CapxulError(error.code, error.message, {
|
|
40335
|
+
cause: error,
|
|
40336
|
+
correlationId: record.correlation_id,
|
|
40337
|
+
...error.details === void 0 ? {} : { details: error.details },
|
|
40338
|
+
...error.layer === void 0 ? {} : { layer: error.layer }
|
|
40339
|
+
});
|
|
40340
|
+
}
|
|
40341
|
+
return new CapxulError(record.error_code, failure?.message ?? "Identity work failed", {
|
|
40342
|
+
...failure === void 0 ? {} : { cause: failure },
|
|
40343
|
+
details: {
|
|
40344
|
+
machine: record.machine,
|
|
40345
|
+
state: record.state,
|
|
40346
|
+
event: record.event,
|
|
40347
|
+
slot: record.slot,
|
|
40348
|
+
...failure?.mode === void 0 ? {} : { failure_mode: failure.mode }
|
|
40349
|
+
},
|
|
40350
|
+
...record.correlation_id === void 0 ? {} : { correlationId: record.correlation_id }
|
|
40351
|
+
});
|
|
40352
|
+
}
|
|
39850
40353
|
function withHostObservation(actor, snapshot) {
|
|
39851
40354
|
if (snapshot === void 0) return actor;
|
|
39852
40355
|
const controls = (input) => {
|
|
@@ -40056,7 +40559,9 @@ async function createProductionAdapters(input) {
|
|
|
40056
40559
|
name: "bootstrap_failed",
|
|
40057
40560
|
props: {
|
|
40058
40561
|
...bootstrapTelemetryEnvelope(input, resolvedInput.value),
|
|
40059
|
-
reason: bootstrapResult.error.code
|
|
40562
|
+
reason: bootstrapResult.error.code,
|
|
40563
|
+
...failureDetail(bootstrapResult.error),
|
|
40564
|
+
...failureEvidenceProps(bootstrapResult.error)
|
|
40060
40565
|
}
|
|
40061
40566
|
});
|
|
40062
40567
|
await closeScope().catch(() => void 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capxul/mcp",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Capxul MCP server for auth, Account readiness, identity, Organizations, relationships, requests, destinations, and testnet funding over Streamable HTTP.",
|
|
6
6
|
"keywords": [
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
48
48
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.23",
|
|
49
49
|
"vite-plus": "0.1.23",
|
|
50
|
-
"@capxul/backend": "0.2.
|
|
51
|
-
"@capxul/config": "0.2.
|
|
52
|
-
"@capxul/sdk": "2.
|
|
53
|
-
"@capxul/types": "0.2.
|
|
50
|
+
"@capxul/backend": "0.2.8",
|
|
51
|
+
"@capxul/config": "0.2.1",
|
|
52
|
+
"@capxul/sdk": "2.5.1",
|
|
53
|
+
"@capxul/types": "0.2.1",
|
|
54
54
|
"@capxul/typescript-config": "0.0.0",
|
|
55
|
-
"@capxul/wire": "0.5.
|
|
55
|
+
"@capxul/wire": "0.5.1"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"dev": "vp exec tsx src/main.ts serve",
|