@capxul/mcp 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/main.mjs +288 -9
  2. package/package.json +3 -3
package/dist/main.mjs CHANGED
@@ -240,7 +240,7 @@ function normalizeEmail(email) {
240
240
  }
241
241
  //#endregion
242
242
  //#region package.json
243
- var version$2 = "2.4.0";
243
+ var version$2 = "2.5.0";
244
244
  //#endregion
245
245
  //#region ../../packages/errors/src/errors.ts
246
246
  const CAPXUL_ERROR_CODES = [
@@ -2398,6 +2398,12 @@ function toPartyId(raw) {
2398
2398
  function toBudgetId(raw) {
2399
2399
  return toNonEmptyStringBrand(raw, "budgetId");
2400
2400
  }
2401
+ function toPayrollRunId(raw) {
2402
+ return toNonEmptyStringBrand(raw, "payrollRunId");
2403
+ }
2404
+ function toPayrollGroupId(raw) {
2405
+ return toNonEmptyStringBrand(raw, "payrollGroupId");
2406
+ }
2401
2407
  function toOrgId(raw) {
2402
2408
  return toNonEmptyStringBrand(raw, "orgId");
2403
2409
  }
@@ -2675,6 +2681,15 @@ const CAPXUL_FUNCTIONS = {
2675
2681
  resumeBootstrapSubmission: "org/actions:resumeBootstrapSubmission",
2676
2682
  submitBootstrap: "org/actions:submitBootstrap"
2677
2683
  },
2684
+ "payroll/actions": { authorizeRun: "payroll/actions:authorizeRun" },
2685
+ "payroll/mutations": {
2686
+ removeGroup: "payroll/mutations:removeGroup",
2687
+ saveGroup: "payroll/mutations:saveGroup"
2688
+ },
2689
+ "payroll/queries": {
2690
+ groups: "payroll/queries:groups",
2691
+ runs: "payroll/queries:runs"
2692
+ },
2678
2693
  "permission/actions": { verify: "permission/actions:verify" },
2679
2694
  "permission/mutations": { command: "permission/mutations:command" },
2680
2695
  "permission/queries": {
@@ -3868,7 +3883,7 @@ Schema.Struct({
3868
3883
  items: Schema.Array(OrganizationPaymentExecutionItemSchema),
3869
3884
  lineage: Schema.optional(PaymentCommandLineageSchema)
3870
3885
  });
3871
- Schema.Struct({
3886
+ const PreparedPaymentCommandExecutionSchema = Schema.Struct({
3872
3887
  executionId: MoneyExecutionIdSchema,
3873
3888
  commandId: PaymentCommandIdSchema,
3874
3889
  paymentIds: Schema.Array(PaymentIdSchema),
@@ -3961,6 +3976,69 @@ Schema.Struct({
3961
3976
  userOpHash: Bytes32Schema,
3962
3977
  value: PermissionResourceSchema
3963
3978
  });
3979
+ const PayrollRunStatusSchema = Schema.Literals([
3980
+ "draft",
3981
+ "authorized",
3982
+ "settled"
3983
+ ]);
3984
+ 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" }));
3985
+ const SignedMinorUnitSchema = Schema.String.pipe(Schema.refine((value) => /^-?(0|[1-9][0-9]*)$/u.test(value), { message: "must be an integer minor-unit string" }));
3986
+ 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" }));
3987
+ const PayrollRunItemInputSchema = Schema.Struct({
3988
+ to: PaymentRef,
3989
+ partyId: nonEmpty("partyId"),
3990
+ gross: MinorUnitSchema,
3991
+ net: MinorUnitSchema,
3992
+ adjustments: Schema.Array(Schema.Struct({
3993
+ label: Schema.String,
3994
+ amount: SignedMinorUnitSchema
3995
+ }))
3996
+ });
3997
+ Schema.Struct({
3998
+ orgId: nonEmpty("orgId"),
3999
+ permissionId: PermissionIdSchema,
4000
+ requestKey: nonEmpty("requestKey"),
4001
+ signerAddress: AddressSchema$1,
4002
+ period: Schema.Struct({
4003
+ start: nonNegativeInteger("period.start"),
4004
+ end: nonNegativeInteger("period.end")
4005
+ }),
4006
+ items: Schema.Array(PayrollRunItemInputSchema)
4007
+ });
4008
+ const PayrollRunSchema = Schema.Struct({
4009
+ id: PayrollRunIdSchema,
4010
+ status: PayrollRunStatusSchema,
4011
+ periodStart: nonNegativeInteger("periodStart"),
4012
+ periodEnd: nonNegativeInteger("periodEnd"),
4013
+ total: FinancialOpsMoney,
4014
+ recipientCount: nonNegativeInteger("recipientCount")
4015
+ });
4016
+ Schema.Struct({
4017
+ runs: Schema.Array(PayrollRunSchema),
4018
+ settledThisMonth: FinancialOpsMoney
4019
+ });
4020
+ Schema.Struct({
4021
+ run: PayrollRunSchema,
4022
+ execution: PreparedPaymentCommandExecutionSchema
4023
+ });
4024
+ 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" }));
4025
+ const PayrollGroupMemberSchema = Schema.Struct({
4026
+ partyId: PartyIdSchema,
4027
+ amount: Schema.String,
4028
+ currency: CurrencyCodeSchema$1
4029
+ });
4030
+ Schema.Struct({
4031
+ id: PayrollGroupIdSchema,
4032
+ name: nonEmpty("name"),
4033
+ tone: Schema.String,
4034
+ members: Schema.Array(PayrollGroupMemberSchema)
4035
+ });
4036
+ Schema.Struct({
4037
+ id: Schema.optional(PayrollGroupIdSchema),
4038
+ name: Schema.String,
4039
+ tone: Schema.String,
4040
+ members: Schema.Array(PayrollGroupMemberSchema)
4041
+ });
3964
4042
  `
3965
4043
  .capxul-doc{--ink:#1d1d1f;--muted:#6e6e73;--line:#e7e7ea;--accent:#0a7d4b;--bg:#fff;
3966
4044
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Inter,system-ui,sans-serif;
@@ -7742,7 +7820,10 @@ function canonicalJson(value) {
7742
7820
  async function fingerprintPaymentIntent(intent) {
7743
7821
  return keccak256(toBytes(canonicalJson(intent)));
7744
7822
  }
7745
- async function executePrepared(deps, prepare, expectedRequest, signal) {
7823
+ function matchesIntent(expected) {
7824
+ return async (request) => await fingerprintPaymentIntent(request) === await fingerprintPaymentIntent(expected);
7825
+ }
7826
+ async function executePrepared(deps, prepare, isExpectedRequest, signal) {
7746
7827
  if (isAborted$1(signal)) return {
7747
7828
  ok: false,
7748
7829
  error: Errors.cancelled({ operation: "payments" })
@@ -7763,7 +7844,7 @@ async function executePrepared(deps, prepare, expectedRequest, signal) {
7763
7844
  }
7764
7845
  const prepared = await prepare(signerAddress);
7765
7846
  if (!prepared.ok) return prepared;
7766
- if (await fingerprintPaymentIntent(prepared.value.request) !== await fingerprintPaymentIntent(expectedRequest)) return {
7847
+ if (!await isExpectedRequest(prepared.value.request)) return {
7767
7848
  ok: false,
7768
7849
  error: Errors.invalidInput("payment", "prepared command mismatch")
7769
7850
  };
@@ -7798,13 +7879,13 @@ function executePaymentLifecycle(deps, intent, signal) {
7798
7879
  return executePrepared(deps, (signerAddress) => runIfActive(signal, "payments.prepareLifecycleExecution", () => deps.convexCall.action(deps.functions.preparePaymentLifecycleExecution, { input: {
7799
7880
  signerAddress,
7800
7881
  intent
7801
- } })), intent, signal);
7882
+ } })), matchesIntent(intent), signal);
7802
7883
  }
7803
7884
  function executeOrganizationPayment(deps, input, signal) {
7804
7885
  return executePrepared(deps, (signerAddress) => runIfActive(signal, "organizationPayments.prepareExecution", () => deps.convexCall.action(deps.functions.prepareOrganizationPaymentExecution, { input: {
7805
7886
  ...input,
7806
7887
  signerAddress
7807
- } })), input, signal);
7888
+ } })), matchesIntent(input), signal);
7808
7889
  }
7809
7890
  //#endregion
7810
7891
  //#region ../../packages/sdk/src/surface/money.ts
@@ -8816,7 +8897,7 @@ async function recoverRawDigestSigner(input) {
8816
8897
  }
8817
8898
  //#endregion
8818
8899
  //#region ../../packages/sdk/package.json
8819
- var version = "2.4.0";
8900
+ var version = "2.5.0";
8820
8901
  //#endregion
8821
8902
  //#region ../../packages/observability/src/engineering.ts
8822
8903
  const ENGINEERING_CAPXUL_ENVS = [
@@ -38472,7 +38553,7 @@ function makePermissionMethods(deps, orgId) {
38472
38553
  }
38473
38554
  //#endregion
38474
38555
  //#region ../../packages/sdk/src/surface/organization-payments.ts
38475
- function executionDependencies(input) {
38556
+ function executionDependencies$1(input) {
38476
38557
  return input.actor === void 0 || input.chainId === void 0 || input.signer === void 0 ? null : {
38477
38558
  actor: input.actor,
38478
38559
  chainId: input.chainId,
@@ -38489,7 +38570,7 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
38489
38570
  ok: false,
38490
38571
  error: Errors.cancelled({ operation })
38491
38572
  };
38492
- const execution = executionDependencies(deps);
38573
+ const execution = executionDependencies$1(deps);
38493
38574
  if (execution === null) return {
38494
38575
  ok: false,
38495
38576
  error: Errors.notImplemented("organizationPayments", "executionComposition")
@@ -38584,6 +38665,197 @@ function makeOrganizationPaymentsMethods(deps, orgId) {
38584
38665
  };
38585
38666
  }
38586
38667
  //#endregion
38668
+ //#region ../../packages/sdk/src/contract/payroll.ts
38669
+ const payrollContract = {
38670
+ authorizeRun: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/actions"].authorizeRun),
38671
+ runs: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].runs),
38672
+ groups: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/queries"].groups),
38673
+ saveGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].saveGroup),
38674
+ removeGroup: makeFunctionReference(CAPXUL_FUNCTIONS["payroll/mutations"].removeGroup)
38675
+ };
38676
+ //#endregion
38677
+ //#region ../../packages/sdk/src/surface/payroll.ts
38678
+ const AUTHORIZE_RUN = "payroll.authorizeRun";
38679
+ function toPayrollRun(wire) {
38680
+ return {
38681
+ id: toPayrollRunId(wire.id),
38682
+ status: wire.status,
38683
+ periodStart: wire.periodStart,
38684
+ periodEnd: wire.periodEnd,
38685
+ total: wire.total,
38686
+ recipientCount: wire.recipientCount
38687
+ };
38688
+ }
38689
+ function toPayrollRuns(wire) {
38690
+ return {
38691
+ runs: wire.runs.map(toPayrollRun),
38692
+ settledThisMonth: wire.settledThisMonth
38693
+ };
38694
+ }
38695
+ function toPayrollGroup(wire) {
38696
+ return {
38697
+ id: toPayrollGroupId(wire.id),
38698
+ name: wire.name,
38699
+ tone: wire.tone,
38700
+ members: wire.members.map((member) => ({
38701
+ partyId: member.partyId,
38702
+ amount: member.amount,
38703
+ currency: member.currency
38704
+ }))
38705
+ };
38706
+ }
38707
+ const MINOR_UNIT_INTEGER = /^-?\d+$/u;
38708
+ /**
38709
+ * One prepared `Money` counted in the minor units `net` is written in, or
38710
+ * `null` when the value is not a decimal number. `amount.value` is a DECIMAL
38711
+ * string (`"200"` at 6 decimals is 200000000 minor units), so comparing it to
38712
+ * `net` directly would compare two different units and pass nothing.
38713
+ */
38714
+ function minorUnits(amount) {
38715
+ const [whole = "", fraction = ""] = amount.value.split(".");
38716
+ if (!/^\d+$/u.test(whole) || !/^\d*$/u.test(fraction) || fraction.length > amount.decimals) return null;
38717
+ return BigInt(whole + fraction.padEnd(amount.decimals, "0"));
38718
+ }
38719
+ /**
38720
+ * One prepared item must pay the person this caller named, the amount this
38721
+ * caller set, under a payslip that attests to the same figures.
38722
+ *
38723
+ * `issuedAt` and `employerRef` are server facts the caller cannot contradict,
38724
+ * so they are not compared. Everything the caller DID supply is: the recipient
38725
+ * `Ref`, the transfer amount against `net`, and the payslip's employee, gross
38726
+ * and net. Adjustments are not in the signed command at all — the backend
38727
+ * enforces `gross + Σ adjustments === net` (ADR-0022 R8), and gross and net
38728
+ * being right is what the signer can prove here.
38729
+ */
38730
+ function isRunItem(prepared, item) {
38731
+ if (prepared === void 0) return false;
38732
+ const payslip = prepared.document;
38733
+ 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;
38734
+ }
38735
+ /**
38736
+ * The batch the backend derived from a payroll intent must be the batch this
38737
+ * caller asked for, checked before the digest is signed.
38738
+ *
38739
+ * The payslip envelope on each item is server-built and carries the run row's
38740
+ * own `issuedAt`, so the batch cannot be fingerprinted against a local copy
38741
+ * (`matchesIntent` is unavailable here). What CAN be verified is every field
38742
+ * the caller supplied — the org, the Budget, the request key, and per item the
38743
+ * recipient, the amount and the payslip figures — plus the lineage binding the
38744
+ * batch to the run just written. A prepared command that pays a different
38745
+ * person, a different amount, from a different Budget, or under a different
38746
+ * run never reaches the signer.
38747
+ */
38748
+ function isRunBatch(input) {
38749
+ return (request) => {
38750
+ const batch = request;
38751
+ 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)));
38752
+ };
38753
+ }
38754
+ function executionDependencies(deps) {
38755
+ return deps.actor === void 0 || deps.chainId === void 0 || deps.signer === void 0 ? null : {
38756
+ actor: deps.actor,
38757
+ chainId: deps.chainId,
38758
+ convexCall: deps.convexCall,
38759
+ functions: moneyExecutionContract,
38760
+ signer: deps.signer
38761
+ };
38762
+ }
38763
+ function makePayrollMethods(deps, orgId) {
38764
+ const requestKeyScope = deps.requestKeyScope ?? `client-${crypto.randomUUID()}`;
38765
+ async function authorize(input, signal) {
38766
+ const execution = executionDependencies(deps);
38767
+ if (execution === null) return {
38768
+ ok: false,
38769
+ error: Errors.notImplemented("payroll", "executionComposition")
38770
+ };
38771
+ const requestKey = await paymentRequestKeyLifecycle(`${requestKeyScope}:${AUTHORIZE_RUN}`, {
38772
+ orgId,
38773
+ input
38774
+ }, input.requestKey);
38775
+ let authorized;
38776
+ const submitted = await executePrepared(execution, async (signerAddress) => {
38777
+ const prepared = await runIfActive(signal, AUTHORIZE_RUN, () => deps.convexCall.action(payrollContract.authorizeRun, { input: {
38778
+ orgId,
38779
+ permissionId: input.permissionId,
38780
+ requestKey: requestKey.key,
38781
+ signerAddress,
38782
+ period: input.period,
38783
+ items: input.items
38784
+ } }));
38785
+ if (!prepared.ok) return prepared;
38786
+ authorized = prepared.value.run;
38787
+ return {
38788
+ ok: true,
38789
+ value: prepared.value.execution
38790
+ };
38791
+ }, (request) => authorized === void 0 || authorized.periodStart !== input.period.start || authorized.periodEnd !== input.period.end ? Promise.resolve(false) : isRunBatch({
38792
+ orgId,
38793
+ permissionId: input.permissionId,
38794
+ requestKey: requestKey.key,
38795
+ runId: authorized.id,
38796
+ items: input.items
38797
+ })(request), signal);
38798
+ try {
38799
+ await requestKey.finish(submitted.ok);
38800
+ } catch {}
38801
+ if (!submitted.ok) return submitted;
38802
+ return authorized === void 0 ? {
38803
+ ok: false,
38804
+ error: Errors.unknown()
38805
+ } : {
38806
+ ok: true,
38807
+ value: toPayrollRun(authorized)
38808
+ };
38809
+ }
38810
+ return {
38811
+ runs: (options) => runIfActive(options?.signal, "payroll.runs", () => Effect.map(deps.convexCall.query(payrollContract.runs, { orgId }), toPayrollRuns)),
38812
+ authorizeRun: async (input, options) => {
38813
+ if (options?.signal?.aborted === true) return {
38814
+ ok: false,
38815
+ error: Errors.cancelled({ operation: AUTHORIZE_RUN })
38816
+ };
38817
+ try {
38818
+ return await authorize(input, options?.signal);
38819
+ } catch (cause) {
38820
+ return {
38821
+ ok: false,
38822
+ error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
38823
+ };
38824
+ }
38825
+ },
38826
+ groups: {
38827
+ list: (options) => runIfActive(options?.signal, "payroll.groups.list", () => Effect.map(deps.convexCall.query(payrollContract.groups, { orgId }), (groups) => groups.map(toPayrollGroup))),
38828
+ save: (input, options) => runIfActive(options?.signal, "payroll.groups.save", () => Effect.map(deps.convexCall.mutation(payrollContract.saveGroup, {
38829
+ orgId,
38830
+ ...input.id === void 0 ? {} : { id: String(input.id) },
38831
+ name: input.name,
38832
+ tone: input.tone,
38833
+ members: input.members
38834
+ }), toPayrollGroup)),
38835
+ remove: (id, options) => runIfActive(options?.signal, "payroll.groups.remove", () => Effect.map(deps.convexCall.mutation(payrollContract.removeGroup, {
38836
+ orgId,
38837
+ id
38838
+ }), () => void 0))
38839
+ }
38840
+ };
38841
+ }
38842
+ const payrollUnavailable = () => Promise.resolve({
38843
+ ok: false,
38844
+ error: Errors.notImplemented("payroll", "executionComposition")
38845
+ });
38846
+ /** The bundle an unconfigured client exposes — every verb refuses, none throws. */
38847
+ function makeUnavailablePayrollMethods() {
38848
+ return {
38849
+ runs: payrollUnavailable,
38850
+ authorizeRun: payrollUnavailable,
38851
+ groups: {
38852
+ list: payrollUnavailable,
38853
+ save: payrollUnavailable,
38854
+ remove: payrollUnavailable
38855
+ }
38856
+ };
38857
+ }
38858
+ //#endregion
38587
38859
  //#region ../../packages/sdk/src/surface/_shared/org-telemetry.ts
38588
38860
  /** Extract the domain from an email for telemetry (never the local part / PII). */
38589
38861
  function emailDomain$1(email) {
@@ -39121,6 +39393,13 @@ function makeOrgMethods(deps) {
39121
39393
  ...deps.actor === void 0 ? {} : { actor: deps.actor },
39122
39394
  ...deps.chainId === void 0 ? {} : { chainId: Number(deps.chainId) },
39123
39395
  ...deps.signer === void 0 ? {} : { signer: deps.signer }
39396
+ }, String(orgId)),
39397
+ payroll: convexCall === void 0 ? makeUnavailablePayrollMethods() : makePayrollMethods({
39398
+ convexCall,
39399
+ ...deps.requestKeyScope === void 0 ? {} : { requestKeyScope: deps.requestKeyScope },
39400
+ ...deps.actor === void 0 ? {} : { actor: deps.actor },
39401
+ ...deps.chainId === void 0 ? {} : { chainId: Number(deps.chainId) },
39402
+ ...deps.signer === void 0 ? {} : { signer: deps.signer }
39124
39403
  }, String(orgId))
39125
39404
  };
39126
39405
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
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,9 +47,9 @@
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.6",
50
+ "@capxul/backend": "0.2.7",
51
51
  "@capxul/config": "0.2.0",
52
- "@capxul/sdk": "2.4.0",
52
+ "@capxul/sdk": "2.5.0",
53
53
  "@capxul/types": "0.2.0",
54
54
  "@capxul/typescript-config": "0.0.0",
55
55
  "@capxul/wire": "0.5.0"