@capxul/mcp 4.1.2 → 4.1.3

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 +66 -14
  2. package/package.json +2 -2
package/dist/main.mjs CHANGED
@@ -11559,7 +11559,7 @@ const moneyExecutionContract = {
11559
11559
  };
11560
11560
  //#endregion
11561
11561
  //#region ../../packages/sdk/package.json
11562
- var version$1 = "4.1.2";
11562
+ var version$1 = "4.1.3";
11563
11563
  //#endregion
11564
11564
  //#region ../../packages/sdk/src/telemetry/exception-projection.ts
11565
11565
  /** Fixed fallback for failures that have no safe message. */
@@ -12421,8 +12421,18 @@ function parsePaymentRequestKeyState(value) {
12421
12421
  if (typeof state.key !== "string" || !Array.isArray(state.active) || state.active.some((attempt) => typeof attempt !== "string") || typeof state.resolved !== "boolean") throw new TypeError("Invalid payment request key state");
12422
12422
  return state;
12423
12423
  }
12424
- async function paymentRequestKeyLifecycle(operation, intent, provided) {
12425
- if (provided !== void 0) return {
12424
+ /** A persisted caller key cannot displace another unresolved or active intent. */
12425
+ function managedRequestKeyState(state, provided, hasActiveAttempt) {
12426
+ if (provided === void 0 || state.key === provided) return state;
12427
+ if (!state.resolved || hasActiveAttempt) throw Errors.invalidInput("requestKey", "another request key is unresolved");
12428
+ return {
12429
+ key: provided,
12430
+ active: [],
12431
+ resolved: false
12432
+ };
12433
+ }
12434
+ async function paymentRequestKeyLifecycle(operation, intent, provided, options) {
12435
+ if (provided !== void 0 && options?.manageProvidedKey !== true) return {
12426
12436
  key: provided,
12427
12437
  finish: async () => void 0
12428
12438
  };
@@ -12435,11 +12445,12 @@ async function paymentRequestKeyLifecycle(operation, intent, provided) {
12435
12445
  })}`;
12436
12446
  if (typeof window === "undefined") {
12437
12447
  const attemptId = randomPaymentRequestKey();
12438
- const state = memoryPaymentRequestKeys.get(slot) ?? {
12439
- key: randomPaymentRequestKey(),
12448
+ let state = memoryPaymentRequestKeys.get(slot) ?? {
12449
+ key: provided ?? randomPaymentRequestKey(),
12440
12450
  active: [],
12441
12451
  resolved: false
12442
12452
  };
12453
+ state = managedRequestKeyState(state, provided, state.active.length > 0);
12443
12454
  state.active.push(attemptId);
12444
12455
  memoryPaymentRequestKeys.set(slot, state);
12445
12456
  let finished = false;
@@ -12463,14 +12474,15 @@ async function paymentRequestKeyLifecycle(operation, intent, provided) {
12463
12474
  const key = await manager.request(slot, async () => {
12464
12475
  const stored = window.localStorage.getItem(slot);
12465
12476
  let state = stored === null ? {
12466
- key: randomPaymentRequestKey(),
12477
+ key: provided ?? randomPaymentRequestKey(),
12467
12478
  active: [],
12468
12479
  resolved: false
12469
12480
  } : parsePaymentRequestKeyState(stored);
12470
12481
  const registered = state.active.includes(attemptId);
12471
12482
  const active = await heldPaymentAttemptIds(manager, slot);
12483
+ state = managedRequestKeyState(state, provided, active.some((id) => id !== attemptId));
12472
12484
  if (!registered && active.every((id) => id === attemptId) && state.resolved) state = {
12473
- key: randomPaymentRequestKey(),
12485
+ key: provided ?? randomPaymentRequestKey(),
12474
12486
  active: [],
12475
12487
  resolved: false
12476
12488
  };
@@ -43907,21 +43919,54 @@ function executionDependencies(deps) {
43907
43919
  signer: deps.signer
43908
43920
  };
43909
43921
  }
43922
+ /** Read only the exact backend prepare receipt, never an arbitrary signer failure. */
43923
+ function payrollResolution(error, requestKey) {
43924
+ const details = error.details;
43925
+ if (error.code !== "WRONG_STATE" || details?.method !== AUTHORIZE_RUN || details.requestKey !== requestKey || typeof details.commandId !== "string" || typeof details.runId !== "string") return void 0;
43926
+ return details.payrollResolution === "failed" || details.payrollResolution === "settled" ? details.payrollResolution : void 0;
43927
+ }
43910
43928
  function makePayrollMethods(deps, orgId) {
43911
43929
  const requestKeyScope = deps.requestKeyScope ?? `client-${crypto.randomUUID()}`;
43912
- async function authorize(input, controls) {
43930
+ async function authorize(input, controls, onRequestKey, onResolved) {
43913
43931
  const signal = controls?.signal;
43914
43932
  const execution = executionDependencies(deps);
43915
43933
  if (execution === null) return {
43916
43934
  ok: false,
43917
43935
  error: Errors.notImplemented("payroll", "executionComposition")
43918
43936
  };
43919
- const requestKey = await paymentRequestKeyLifecycle(`${requestKeyScope}:${AUTHORIZE_RUN}`, {
43937
+ const { requestKey: provided, ...canonicalInput } = input;
43938
+ const actorId = onRequestKey === void 0 ? void 0 : execution.actor.authSession()?.authUserId;
43939
+ if (onRequestKey !== void 0 && actorId === void 0) return {
43940
+ ok: false,
43941
+ error: Errors.notAuthenticated()
43942
+ };
43943
+ const requestKey = await paymentRequestKeyLifecycle(`${requestKeyScope}:${AUTHORIZE_RUN}`, onRequestKey === void 0 ? {
43920
43944
  orgId,
43921
43945
  input
43922
- }, input.requestKey);
43946
+ } : {
43947
+ actorId,
43948
+ orgId,
43949
+ input: canonicalInput
43950
+ }, provided, onRequestKey === void 0 ? void 0 : { manageProvidedKey: true });
43951
+ try {
43952
+ await onRequestKey?.(requestKey.key);
43953
+ if (onRequestKey !== void 0 && execution.actor.authSession()?.authUserId !== actorId) {
43954
+ await requestKey.finish(false).catch(() => void 0);
43955
+ return {
43956
+ ok: false,
43957
+ error: Errors.notAuthenticated()
43958
+ };
43959
+ }
43960
+ } catch (cause) {
43961
+ await requestKey.finish(false).catch(() => void 0);
43962
+ return {
43963
+ ok: false,
43964
+ error: cause instanceof CapxulError ? cause : Errors.unknown(cause)
43965
+ };
43966
+ }
43923
43967
  let authorized;
43924
43968
  let preparedClosed = false;
43969
+ let terminalReplay;
43925
43970
  const submitted = await executePrepared(execution, async (signerAddress) => {
43926
43971
  const prepared = await runIfActive(signal, AUTHORIZE_RUN, () => withInvocationParentSpan(Effect.suspend(() => deps.convexCall.action(payrollContract.authorizeRun, copyInvocationObservation(controls, { input: {
43927
43972
  orgId,
@@ -43931,7 +43976,10 @@ function makePayrollMethods(deps, orgId) {
43931
43976
  period: input.period,
43932
43977
  items: input.items
43933
43978
  } }))), controls), deps.runPromise);
43934
- if (!prepared.ok) return prepared;
43979
+ if (!prepared.ok) {
43980
+ terminalReplay = payrollResolution(prepared.error, requestKey.key);
43981
+ return prepared;
43982
+ }
43935
43983
  authorized = prepared.value.run;
43936
43984
  return {
43937
43985
  ok: true,
@@ -43944,8 +43992,12 @@ function makePayrollMethods(deps, orgId) {
43944
43992
  runId: authorized.id,
43945
43993
  items: input.items
43946
43994
  })(request), true, () => preparedClosed = true, signal, controls);
43995
+ const resolution = preparedClosed ? "failed" : terminalReplay;
43996
+ if (resolution !== void 0) try {
43997
+ await onResolved?.(resolution);
43998
+ } catch {}
43947
43999
  try {
43948
- await requestKey.finish(submitted.ok || preparedClosed);
44000
+ await requestKey.finish(submitted.ok || resolution !== void 0);
43949
44001
  } catch {}
43950
44002
  if (!submitted.ok) return submitted;
43951
44003
  return authorized === void 0 ? {
@@ -43967,7 +44019,7 @@ function makePayrollMethods(deps, orgId) {
43967
44019
  if (controls?.signal?.aborted === true) return yield* Effect.fail(Errors.cancelled({ operation: AUTHORIZE_RUN }));
43968
44020
  const parent = yield* Effect.currentSpan.pipe(Effect.orDie);
43969
44021
  const result = yield* Effect.tryPromise({
43970
- try: () => authorize(input, carryInvocationParentSpan(controls, parent)),
44022
+ try: () => authorize(input, carryInvocationParentSpan(controls, parent), options?.onRequestKey, options?.onResolved),
43971
44023
  catch: (cause) => cause instanceof CapxulError ? cause : Errors.unknown(cause)
43972
44024
  });
43973
44025
  return yield* result.ok ? Effect.succeed(result.value) : Effect.fail(result.error);
@@ -46653,7 +46705,7 @@ function stdioIdentity(env = process.env, options = {}) {
46653
46705
  }
46654
46706
  //#endregion
46655
46707
  //#region package.json
46656
- var version = "4.1.2";
46708
+ var version = "4.1.3";
46657
46709
  //#endregion
46658
46710
  //#region src/deps.ts
46659
46711
  const NO_IDENTITY = async () => void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capxul/mcp",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
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": [
@@ -51,7 +51,7 @@
51
51
  "vite": "npm:@voidzero-dev/vite-plus-core@0.3.0",
52
52
  "vite-plus": "0.3.0",
53
53
  "@capxul/config": "0.3.0",
54
- "@capxul/sdk": "4.1.2",
54
+ "@capxul/sdk": "4.1.3",
55
55
  "@capxul/typescript-config": "0.0.0"
56
56
  },
57
57
  "scripts": {