@capxul/mcp 1.0.0-alpha.20 → 1.0.0-alpha.22
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 +387 -144
- package/package.json +6 -6
package/dist/main.mjs
CHANGED
|
@@ -232,7 +232,7 @@ function normalizeEmail(email) {
|
|
|
232
232
|
}
|
|
233
233
|
//#endregion
|
|
234
234
|
//#region package.json
|
|
235
|
-
var version$1 = "1.0.0-alpha.
|
|
235
|
+
var version$1 = "1.0.0-alpha.22";
|
|
236
236
|
//#endregion
|
|
237
237
|
//#region src/tool-result.ts
|
|
238
238
|
function okResult(structured) {
|
|
@@ -1649,6 +1649,10 @@ const FIELD_RULES = {
|
|
|
1649
1649
|
maxLength: 128,
|
|
1650
1650
|
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1651
1651
|
},
|
|
1652
|
+
journeyId: {
|
|
1653
|
+
maxLength: 128,
|
|
1654
|
+
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
1655
|
+
},
|
|
1652
1656
|
correlationId: {
|
|
1653
1657
|
maxLength: 128,
|
|
1654
1658
|
pattern: /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u
|
|
@@ -4162,6 +4166,41 @@ function captureExceptionSync(telemetry, error, context) {
|
|
|
4162
4166
|
} catch {}
|
|
4163
4167
|
}
|
|
4164
4168
|
//#endregion
|
|
4169
|
+
//#region ../../packages/sdk/src/internal/invocation-observation.ts
|
|
4170
|
+
const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
|
|
4171
|
+
const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
|
|
4172
|
+
/** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
|
|
4173
|
+
function attachInvocationObservation(target, context) {
|
|
4174
|
+
const snapshot = Object.freeze(context === void 0 ? {} : { context: Object.freeze({ ...context }) });
|
|
4175
|
+
Object.defineProperty(target, INVOCATION_OBSERVATION, {
|
|
4176
|
+
configurable: false,
|
|
4177
|
+
enumerable: false,
|
|
4178
|
+
value: snapshot,
|
|
4179
|
+
writable: false
|
|
4180
|
+
});
|
|
4181
|
+
return target;
|
|
4182
|
+
}
|
|
4183
|
+
/** @internal Read the snapshot without exposing its symbol or adding a wire field. */
|
|
4184
|
+
function readInvocationObservation(source) {
|
|
4185
|
+
if (typeof source !== "object" || source === null) return void 0;
|
|
4186
|
+
return source[INVOCATION_OBSERVATION];
|
|
4187
|
+
}
|
|
4188
|
+
/** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
|
|
4189
|
+
function copyInvocationObservation(source, target) {
|
|
4190
|
+
const snapshot = readInvocationObservation(source);
|
|
4191
|
+
return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot.context);
|
|
4192
|
+
}
|
|
4193
|
+
/** @internal Mark a failure envelope as already resolved at the public invocation boundary. */
|
|
4194
|
+
function markFailureInvocationSnapshot(failure) {
|
|
4195
|
+
Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
|
|
4196
|
+
configurable: false,
|
|
4197
|
+
enumerable: false,
|
|
4198
|
+
value: true,
|
|
4199
|
+
writable: false
|
|
4200
|
+
});
|
|
4201
|
+
return failure;
|
|
4202
|
+
}
|
|
4203
|
+
//#endregion
|
|
4165
4204
|
//#region ../../packages/sdk/src/client/_shared/effect-actor-bridge.ts
|
|
4166
4205
|
/**
|
|
4167
4206
|
* Bridge an Effect whose typed failure carries `{ publicError: CapxulError }`
|
|
@@ -5004,7 +5043,7 @@ function makeAccountMethods(deps) {
|
|
|
5004
5043
|
};
|
|
5005
5044
|
};
|
|
5006
5045
|
const deployMutex = /* @__PURE__ */ new Map();
|
|
5007
|
-
const deploySafeImpl = async () => {
|
|
5046
|
+
const deploySafeImpl = async (observationSource) => {
|
|
5008
5047
|
const session = await currentSession(deps.actor, deps.authCache);
|
|
5009
5048
|
if (session === null) return {
|
|
5010
5049
|
ok: false,
|
|
@@ -5032,7 +5071,8 @@ function makeAccountMethods(deps) {
|
|
|
5032
5071
|
authUserId: session.authUserId,
|
|
5033
5072
|
chainId: deps.chainId,
|
|
5034
5073
|
signer,
|
|
5035
|
-
smartAccountPort: deps.smartAccountPort
|
|
5074
|
+
smartAccountPort: deps.smartAccountPort,
|
|
5075
|
+
observationSource
|
|
5036
5076
|
}).finally(() => {
|
|
5037
5077
|
deployMutex.delete(mutexKey);
|
|
5038
5078
|
});
|
|
@@ -5156,11 +5196,11 @@ async function runBackendClaim(input) {
|
|
|
5156
5196
|
error: Errors.providerError("signer", "getAddress", cause)
|
|
5157
5197
|
};
|
|
5158
5198
|
}
|
|
5159
|
-
const claimed = await runPortEffect(input.smartAccountPort.claim({
|
|
5199
|
+
const claimed = await runPortEffect(input.smartAccountPort.claim(copyInvocationObservation(input.observationSource, {
|
|
5160
5200
|
authUserId: input.authUserId,
|
|
5161
5201
|
chainId,
|
|
5162
5202
|
signerAddress
|
|
5163
|
-
}));
|
|
5203
|
+
})));
|
|
5164
5204
|
if (!claimed.ok) return claimed;
|
|
5165
5205
|
return {
|
|
5166
5206
|
ok: true,
|
|
@@ -5302,7 +5342,7 @@ async function recoverRawDigestSigner(input) {
|
|
|
5302
5342
|
}
|
|
5303
5343
|
//#endregion
|
|
5304
5344
|
//#region ../../packages/sdk/package.json
|
|
5305
|
-
var version = "1.0.0-alpha.
|
|
5345
|
+
var version = "1.0.0-alpha.22";
|
|
5306
5346
|
//#endregion
|
|
5307
5347
|
//#region ../../packages/sdk/src/ports/auth-client.ts
|
|
5308
5348
|
var AuthClientError = class extends Data.TaggedError("AuthClientError") {};
|
|
@@ -6214,44 +6254,10 @@ function convexCallErrorFromCapxul(operation, error) {
|
|
|
6214
6254
|
}
|
|
6215
6255
|
var ConvexCallPortTag = class extends Context.Tag("@capxul/sdk/ports/ConvexCallPort")() {};
|
|
6216
6256
|
//#endregion
|
|
6217
|
-
//#region ../../packages/sdk/src/internal/invocation-observation.ts
|
|
6218
|
-
const INVOCATION_OBSERVATION = Symbol("capxul.invocation-observation");
|
|
6219
|
-
const FAILURE_INVOCATION_SNAPSHOT = Symbol("capxul.failure-invocation-snapshot");
|
|
6220
|
-
/** @internal Attach one immutable, non-wire invocation snapshot to an SDK-owned object. */
|
|
6221
|
-
function attachInvocationObservation(target, context) {
|
|
6222
|
-
const snapshot = Object.freeze(context === void 0 ? {} : { context: Object.freeze({ ...context }) });
|
|
6223
|
-
Object.defineProperty(target, INVOCATION_OBSERVATION, {
|
|
6224
|
-
configurable: false,
|
|
6225
|
-
enumerable: false,
|
|
6226
|
-
value: snapshot,
|
|
6227
|
-
writable: false
|
|
6228
|
-
});
|
|
6229
|
-
return target;
|
|
6230
|
-
}
|
|
6231
|
-
/** @internal Read the snapshot without exposing its symbol or adding a wire field. */
|
|
6232
|
-
function readInvocationObservation(source) {
|
|
6233
|
-
if (typeof source !== "object" || source === null) return void 0;
|
|
6234
|
-
return source[INVOCATION_OBSERVATION];
|
|
6235
|
-
}
|
|
6236
|
-
/** @internal Carry a snapshot across an SDK adapter projection without resolving again. */
|
|
6237
|
-
function copyInvocationObservation(source, target) {
|
|
6238
|
-
const snapshot = readInvocationObservation(source);
|
|
6239
|
-
return snapshot === void 0 ? target : attachInvocationObservation(target, snapshot.context);
|
|
6240
|
-
}
|
|
6241
|
-
/** @internal Mark a failure envelope as already resolved at the public invocation boundary. */
|
|
6242
|
-
function markFailureInvocationSnapshot(failure) {
|
|
6243
|
-
Object.defineProperty(failure, FAILURE_INVOCATION_SNAPSHOT, {
|
|
6244
|
-
configurable: false,
|
|
6245
|
-
enumerable: false,
|
|
6246
|
-
value: true,
|
|
6247
|
-
writable: false
|
|
6248
|
-
});
|
|
6249
|
-
return failure;
|
|
6250
|
-
}
|
|
6251
|
-
//#endregion
|
|
6252
6257
|
//#region ../../packages/sdk/src/adapters/convex-call/ConvexCallAdapter.ts
|
|
6253
6258
|
/** Exact floor-first allowlist; every additional handler must migrate its validator first. */
|
|
6254
|
-
const OBSERVED_CONVEX_ACTIONS = new Set(["subAccount/actions:transfer"]);
|
|
6259
|
+
const OBSERVED_CONVEX_ACTIONS = new Set(["subAccount/actions:transfer", "smartAccount/actions:claim"]);
|
|
6260
|
+
const OBSERVED_CONVEX_MUTATIONS = new Set(["org/lifecycle:startOrResume", "org/lifecycle:retry"]);
|
|
6255
6261
|
var ConvexCallAdapter = class {
|
|
6256
6262
|
#client;
|
|
6257
6263
|
#tokenProvider;
|
|
@@ -6274,20 +6280,21 @@ var ConvexCallAdapter = class {
|
|
|
6274
6280
|
});
|
|
6275
6281
|
}
|
|
6276
6282
|
mutation(fn, args) {
|
|
6283
|
+
const path = getFunctionName(fn);
|
|
6277
6284
|
return Effect.tryPromise({
|
|
6278
|
-
try: () => this.#client.mutation(fn, args),
|
|
6279
|
-
catch: (cause) => mapToConvexCallError(
|
|
6285
|
+
try: () => this.#client.mutation(fn, this.#observedArgs(OBSERVED_CONVEX_MUTATIONS, path, args)),
|
|
6286
|
+
catch: (cause) => mapToConvexCallError(path, cause)
|
|
6280
6287
|
});
|
|
6281
6288
|
}
|
|
6282
6289
|
action(fn, args) {
|
|
6283
6290
|
const path = getFunctionName(fn);
|
|
6284
6291
|
return Effect.tryPromise({
|
|
6285
|
-
try: () => this.#client.action(fn, this.#
|
|
6292
|
+
try: () => this.#client.action(fn, this.#observedArgs(OBSERVED_CONVEX_ACTIONS, path, args)),
|
|
6286
6293
|
catch: (cause) => mapToConvexCallError(path, cause)
|
|
6287
6294
|
});
|
|
6288
6295
|
}
|
|
6289
|
-
#
|
|
6290
|
-
if (!
|
|
6296
|
+
#observedArgs(allowlist, path, args) {
|
|
6297
|
+
if (!allowlist.has(path)) return args;
|
|
6291
6298
|
let hostContext;
|
|
6292
6299
|
const invocationSnapshot = readInvocationObservation(args);
|
|
6293
6300
|
if (invocationSnapshot !== void 0) hostContext = invocationSnapshot.context;
|
|
@@ -6877,6 +6884,10 @@ function brandProfile(raw) {
|
|
|
6877
6884
|
email: toEmail(raw.email),
|
|
6878
6885
|
displayName: raw.displayName,
|
|
6879
6886
|
country: raw.country === null ? null : toCountryCode(raw.country),
|
|
6887
|
+
onboarded: raw.onboarded ?? false,
|
|
6888
|
+
withdrawalAddress: raw.withdrawalAddress === null || raw.withdrawalAddress === void 0 ? null : toAddress(raw.withdrawalAddress),
|
|
6889
|
+
username: raw.username ?? null,
|
|
6890
|
+
imageUrl: raw.imageUrl ?? null,
|
|
6880
6891
|
kycTier: toKycTier(raw.kycTier),
|
|
6881
6892
|
createdAt: toEpochMs(raw.createdAt),
|
|
6882
6893
|
updatedAt: toEpochMs(raw.updatedAt)
|
|
@@ -7136,11 +7147,11 @@ var ConvexSmartAccountAdapter = class {
|
|
|
7136
7147
|
})), Effect.catchAllDefect((cause) => Effect.fail(smartAccountErrorFromUnknown("confirmDeployment", cause))));
|
|
7137
7148
|
}
|
|
7138
7149
|
claim(input) {
|
|
7139
|
-
return this.#convex.action(this.#fns.claim, {
|
|
7150
|
+
return this.#convex.action(this.#fns.claim, copyInvocationObservation(input, {
|
|
7140
7151
|
chainId: wireChainId(input.chainId),
|
|
7141
7152
|
signerAddress: input.signerAddress,
|
|
7142
7153
|
...input.telemetryRunId === void 0 ? {} : { telemetryRunId: input.telemetryRunId }
|
|
7143
|
-
}).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("claim", error.publicError, error)), Effect.flatMap((row) => Effect.try({
|
|
7154
|
+
})).pipe(Effect.mapError((error) => smartAccountErrorFromCapxul("claim", error.publicError, error)), Effect.flatMap((row) => Effect.try({
|
|
7144
7155
|
try: () => brandProvisionedSmartAccount(input.authUserId, row),
|
|
7145
7156
|
catch: (cause) => smartAccountErrorFromUnknown("claim", cause)
|
|
7146
7157
|
})), Effect.catchAllDefect((cause) => Effect.fail(smartAccountErrorFromUnknown("claim", cause))));
|
|
@@ -7206,7 +7217,10 @@ function brandOrgView(wire, treasury, viewerRole) {
|
|
|
7206
7217
|
handle: wire.slug,
|
|
7207
7218
|
safeAddress: toAddress(wire.safeAddress.toLowerCase()),
|
|
7208
7219
|
role: viewerRole,
|
|
7209
|
-
treasury
|
|
7220
|
+
treasury,
|
|
7221
|
+
bio: wire.bio ?? null,
|
|
7222
|
+
size: wire.size ?? null,
|
|
7223
|
+
logoUrl: wire.logoUrl ?? null
|
|
7210
7224
|
};
|
|
7211
7225
|
}
|
|
7212
7226
|
/**
|
|
@@ -7402,14 +7416,19 @@ const DEFAULT_FUNCTIONS$1 = {
|
|
|
7402
7416
|
var ConvexOrganizationSetupAdapter = class {
|
|
7403
7417
|
#convex;
|
|
7404
7418
|
#signer;
|
|
7419
|
+
#chainId;
|
|
7405
7420
|
#fns;
|
|
7406
7421
|
constructor(input) {
|
|
7407
7422
|
this.#convex = input.convex;
|
|
7408
7423
|
this.#signer = input.signer;
|
|
7424
|
+
this.#chainId = input.chainId;
|
|
7409
7425
|
this.#fns = input.functions ?? DEFAULT_FUNCTIONS$1;
|
|
7410
7426
|
}
|
|
7411
7427
|
async startOrResume(input) {
|
|
7412
|
-
const result = await runCall("startOrResume", this.#convex.mutation(this.#fns.startOrResume, input
|
|
7428
|
+
const result = await runCall("startOrResume", this.#convex.mutation(this.#fns.startOrResume, copyInvocationObservation(input, {
|
|
7429
|
+
...input,
|
|
7430
|
+
chainId: this.#chainId
|
|
7431
|
+
})));
|
|
7413
7432
|
if (!result.ok) return result;
|
|
7414
7433
|
const lifecycle = parseLifecycle("startOrResume", result.value.lifecycle);
|
|
7415
7434
|
if (!lifecycle.ok) return lifecycle;
|
|
@@ -7425,17 +7444,17 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
7425
7444
|
};
|
|
7426
7445
|
}
|
|
7427
7446
|
prepareFounderAccount(input) {
|
|
7428
|
-
return this.#lifecycleAction("prepareFounderAccount", input, () => this.#convex.action(this.#fns.prepareFounderAccount, { orgId: input.orgId }));
|
|
7447
|
+
return this.#lifecycleAction("prepareFounderAccount", input, () => this.#convex.action(this.#fns.prepareFounderAccount, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
7429
7448
|
}
|
|
7430
7449
|
async authorizeAndSubmitBootstrap(input) {
|
|
7431
7450
|
const cancelled = cancellation(input.signal);
|
|
7432
7451
|
if (cancelled !== void 0) return cancelled;
|
|
7433
7452
|
const signerAddress = await signerResult("getAddress", () => this.#signer.getAddress());
|
|
7434
7453
|
if (!signerAddress.ok) return signerAddress;
|
|
7435
|
-
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, {
|
|
7454
|
+
const prepared = await runCall("prepareBootstrap", this.#convex.action(this.#fns.prepareBootstrap, copyInvocationObservation(input, {
|
|
7436
7455
|
orgId: input.orgId,
|
|
7437
7456
|
signerAddress: signerAddress.value
|
|
7438
|
-
}));
|
|
7457
|
+
})));
|
|
7439
7458
|
if (!prepared.ok) return prepared;
|
|
7440
7459
|
const authority = validatePreparedAuthorities(prepared.value, signerAddress.value);
|
|
7441
7460
|
if (!authority.ok) return authority;
|
|
@@ -7445,25 +7464,25 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
7445
7464
|
if (!signature.ok) return signature;
|
|
7446
7465
|
const cancelledAfterSign = cancellation(input.signal);
|
|
7447
7466
|
if (cancelledAfterSign !== void 0) return cancelledAfterSign;
|
|
7448
|
-
const submitted = await runCall("submitBootstrap", this.#convex.action(this.#fns.submitBootstrap, {
|
|
7467
|
+
const submitted = await runCall("submitBootstrap", this.#convex.action(this.#fns.submitBootstrap, copyInvocationObservation(input, {
|
|
7449
7468
|
orgId: input.orgId,
|
|
7450
7469
|
signerAddress: signerAddress.value,
|
|
7451
7470
|
signature: signature.value,
|
|
7452
7471
|
userOp: prepared.value.userOp
|
|
7453
|
-
}));
|
|
7472
|
+
})));
|
|
7454
7473
|
if (!submitted.ok) return submitted;
|
|
7455
7474
|
return parseLifecycle("submitBootstrap", submitted.value);
|
|
7456
7475
|
}
|
|
7457
7476
|
resumeSubmittedBootstrap(input) {
|
|
7458
|
-
return this.#lifecycleAction("resumeBootstrapSubmission", input, () => this.#convex.action(this.#fns.resumeBootstrapSubmission, { orgId: input.orgId }));
|
|
7477
|
+
return this.#lifecycleAction("resumeBootstrapSubmission", input, () => this.#convex.action(this.#fns.resumeBootstrapSubmission, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
7459
7478
|
}
|
|
7460
7479
|
confirmSubmittedBootstrap(input) {
|
|
7461
|
-
return this.#lifecycleAction("confirmBootstrap", input, () => this.#convex.action(this.#fns.confirmBootstrap, { orgId: input.orgId }));
|
|
7480
|
+
return this.#lifecycleAction("confirmBootstrap", input, () => this.#convex.action(this.#fns.confirmBootstrap, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
7462
7481
|
}
|
|
7463
7482
|
async recordFailure(input) {
|
|
7464
7483
|
const errorProvider = input.error.details?.provider;
|
|
7465
7484
|
const errorOperation = input.error.details?.operation;
|
|
7466
|
-
const result = await runCall("recordFailure", this.#convex.mutation(this.#fns.recordFailure, {
|
|
7485
|
+
const result = await runCall("recordFailure", this.#convex.mutation(this.#fns.recordFailure, copyInvocationObservation(input, {
|
|
7467
7486
|
orgId: input.orgId,
|
|
7468
7487
|
errorCode: input.error.code,
|
|
7469
7488
|
...typeof errorProvider === "string" && typeof errorOperation === "string" ? {
|
|
@@ -7471,7 +7490,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
7471
7490
|
errorOperation
|
|
7472
7491
|
} : {},
|
|
7473
7492
|
retryable: input.retryable
|
|
7474
|
-
}));
|
|
7493
|
+
})));
|
|
7475
7494
|
return result.ok ? parseLifecycle("recordFailure", result.value) : result;
|
|
7476
7495
|
}
|
|
7477
7496
|
async loadLifecycle(input) {
|
|
@@ -7489,7 +7508,7 @@ var ConvexOrganizationSetupAdapter = class {
|
|
|
7489
7508
|
const reset = resetSignerSession(this.#signer);
|
|
7490
7509
|
if (!reset.ok) return reset;
|
|
7491
7510
|
}
|
|
7492
|
-
const result = await runCall("retry", this.#convex.mutation(this.#fns.retry, { orgId: input.orgId }));
|
|
7511
|
+
const result = await runCall("retry", this.#convex.mutation(this.#fns.retry, copyInvocationObservation(input, { orgId: input.orgId })));
|
|
7493
7512
|
if (!result.ok) return result;
|
|
7494
7513
|
return parseLifecycle("retry", result.value);
|
|
7495
7514
|
}
|
|
@@ -7674,6 +7693,7 @@ const PayeeIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => PAYEE
|
|
|
7674
7693
|
const DocumentHashSchema = Schema.String.pipe(Schema.filter((value) => BYTES32_RE$2.test(value), { message: () => "must be 0x + 64 hex chars" }));
|
|
7675
7694
|
const TelemetryEnvelopeProps = {
|
|
7676
7695
|
capxul_e2e_run_id: OptionalString,
|
|
7696
|
+
journeyId: OptionalString,
|
|
7677
7697
|
correlationId: OptionalString,
|
|
7678
7698
|
capxulEnv: OptionalString,
|
|
7679
7699
|
sdkVersion: OptionalString,
|
|
@@ -7805,6 +7825,46 @@ const TransferFailedProps = Schema.Struct({
|
|
|
7805
7825
|
const ORG_ID_TELEMETRY_RE = /^org_[0-9A-Za-z]+$/;
|
|
7806
7826
|
const OrgIdTelemetrySchema = Schema.String.pipe(Schema.filter((value) => ORG_ID_TELEMETRY_RE.test(value), { message: () => "must be org_ plus an alphanumeric id" }));
|
|
7807
7827
|
const OptionalOrgId = Schema.optional(OrgIdTelemetrySchema);
|
|
7828
|
+
const AttemptNumberSchema = Schema.Number.pipe(Schema.filter((value) => Number.isSafeInteger(value) && value > 0, { message: () => "must be a positive safe integer" }));
|
|
7829
|
+
const OnboardingStageSchema = Schema.Literal("profile", "accountProvisioning", "accountClaim", "preparingFounderAccount", "awaitingFounderAuthorization", "submittingBootstrap", "confirmingBootstrap");
|
|
7830
|
+
const MemberActivationStartedProps = Schema.Struct({
|
|
7831
|
+
$insert_id: Schema.String,
|
|
7832
|
+
producer: Schema.Literal("server")
|
|
7833
|
+
});
|
|
7834
|
+
const MemberActivationReadyProps = Schema.Struct({
|
|
7835
|
+
$insert_id: Schema.String,
|
|
7836
|
+
duration_ms: DurationMsSchema,
|
|
7837
|
+
producer: Schema.Literal("server")
|
|
7838
|
+
});
|
|
7839
|
+
const MemberActivationFailedProps = Schema.Struct({
|
|
7840
|
+
$insert_id: Schema.String,
|
|
7841
|
+
stage: OnboardingStageSchema,
|
|
7842
|
+
error_code: Schema.String,
|
|
7843
|
+
retryable: Schema.Boolean,
|
|
7844
|
+
producer: Schema.Literal("server")
|
|
7845
|
+
});
|
|
7846
|
+
const OrganizationCreationStartedProps = Schema.Struct({
|
|
7847
|
+
$insert_id: Schema.String,
|
|
7848
|
+
organization_id: OrgIdTelemetrySchema,
|
|
7849
|
+
attempt_number: AttemptNumberSchema,
|
|
7850
|
+
producer: Schema.Literal("server")
|
|
7851
|
+
});
|
|
7852
|
+
const OrganizationCreationReadyProps = Schema.Struct({
|
|
7853
|
+
$insert_id: Schema.String,
|
|
7854
|
+
organization_id: OrgIdTelemetrySchema,
|
|
7855
|
+
attempt_number: AttemptNumberSchema,
|
|
7856
|
+
duration_ms: DurationMsSchema,
|
|
7857
|
+
producer: Schema.Literal("server")
|
|
7858
|
+
});
|
|
7859
|
+
const OrganizationCreationFailedProps = Schema.Struct({
|
|
7860
|
+
$insert_id: Schema.String,
|
|
7861
|
+
organization_id: OrgIdTelemetrySchema,
|
|
7862
|
+
attempt_number: AttemptNumberSchema,
|
|
7863
|
+
stage: OnboardingStageSchema,
|
|
7864
|
+
error_code: Schema.String,
|
|
7865
|
+
retryable: Schema.Boolean,
|
|
7866
|
+
producer: Schema.Literal("server")
|
|
7867
|
+
});
|
|
7808
7868
|
const OrgCreateStartedProps = Schema.Struct({
|
|
7809
7869
|
...TelemetryEnvelopeProps,
|
|
7810
7870
|
org_id: OptionalOrgId,
|
|
@@ -7966,6 +8026,30 @@ Schema.Struct({
|
|
|
7966
8026
|
name: Schema.Literal("bootstrap_failed"),
|
|
7967
8027
|
props: Schema.optional(BootstrapFailedProps)
|
|
7968
8028
|
});
|
|
8029
|
+
Schema.Struct({
|
|
8030
|
+
name: Schema.Literal("member_activation_started"),
|
|
8031
|
+
props: MemberActivationStartedProps
|
|
8032
|
+
});
|
|
8033
|
+
Schema.Struct({
|
|
8034
|
+
name: Schema.Literal("member_activation_ready"),
|
|
8035
|
+
props: MemberActivationReadyProps
|
|
8036
|
+
});
|
|
8037
|
+
Schema.Struct({
|
|
8038
|
+
name: Schema.Literal("member_activation_failed"),
|
|
8039
|
+
props: MemberActivationFailedProps
|
|
8040
|
+
});
|
|
8041
|
+
Schema.Struct({
|
|
8042
|
+
name: Schema.Literal("organization_creation_started"),
|
|
8043
|
+
props: OrganizationCreationStartedProps
|
|
8044
|
+
});
|
|
8045
|
+
Schema.Struct({
|
|
8046
|
+
name: Schema.Literal("organization_creation_ready"),
|
|
8047
|
+
props: OrganizationCreationReadyProps
|
|
8048
|
+
});
|
|
8049
|
+
Schema.Struct({
|
|
8050
|
+
name: Schema.Literal("organization_creation_failed"),
|
|
8051
|
+
props: OrganizationCreationFailedProps
|
|
8052
|
+
});
|
|
7969
8053
|
Schema.Struct({
|
|
7970
8054
|
name: Schema.Literal("account_balance_read"),
|
|
7971
8055
|
props: Schema.optional(AccountBalanceReadProps)
|
|
@@ -9654,14 +9738,29 @@ const loadIdentityProgram = Effect.gen(function* () {
|
|
|
9654
9738
|
});
|
|
9655
9739
|
//#endregion
|
|
9656
9740
|
//#region ../../packages/sdk/src/client/identity.ts
|
|
9741
|
+
const usernameAvailableQuery = makeFunctionReference("identity/queries:usernameAvailable");
|
|
9657
9742
|
function makeIdentityMethods(deps) {
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9743
|
+
const convexCall = deps.convexCall;
|
|
9744
|
+
return {
|
|
9745
|
+
async loadCurrent(options) {
|
|
9746
|
+
if (options?.signal?.aborted) return {
|
|
9747
|
+
ok: false,
|
|
9748
|
+
error: Errors.cancelled({ operation: "identity.loadCurrent" })
|
|
9749
|
+
};
|
|
9750
|
+
return toCapxulResult(loadIdentityProgram, identityDepsLayer(deps));
|
|
9751
|
+
},
|
|
9752
|
+
async usernameAvailable(username, options) {
|
|
9753
|
+
if (options?.signal?.aborted) return {
|
|
9754
|
+
ok: false,
|
|
9755
|
+
error: Errors.cancelled({ operation: "identity.usernameAvailable" })
|
|
9756
|
+
};
|
|
9757
|
+
if (convexCall === void 0) return {
|
|
9758
|
+
ok: false,
|
|
9759
|
+
error: Errors.notImplemented("identity", "usernameAvailable")
|
|
9760
|
+
};
|
|
9761
|
+
return runPortEffect(convexCall.query(usernameAvailableQuery, { username }));
|
|
9762
|
+
}
|
|
9763
|
+
};
|
|
9665
9764
|
}
|
|
9666
9765
|
//#endregion
|
|
9667
9766
|
//#region ../../packages/sdk/src/client/_shared/money-telemetry.ts
|
|
@@ -9993,32 +10092,36 @@ function makeFinancialOpsMethods(deps) {
|
|
|
9993
10092
|
} },
|
|
9994
10093
|
destinations: {
|
|
9995
10094
|
add: async (input, options) => {
|
|
9996
|
-
const
|
|
9997
|
-
if (!
|
|
10095
|
+
const scope = normalizeDestinationInputScope(input, "target");
|
|
10096
|
+
if (!scope.ok) return {
|
|
9998
10097
|
ok: false,
|
|
9999
|
-
error:
|
|
10098
|
+
error: scope.error
|
|
10000
10099
|
};
|
|
10001
|
-
|
|
10100
|
+
const scopeValue = scope.value;
|
|
10101
|
+
if (scopeValue === void 0) return {
|
|
10002
10102
|
ok: false,
|
|
10003
|
-
error: Errors.invalidInput("target",
|
|
10103
|
+
error: Errors.invalidInput("target", DESTINATION_SCOPE_MESSAGE)
|
|
10004
10104
|
};
|
|
10105
|
+
const backendActor = actorReferenceToBackend(input.actor);
|
|
10005
10106
|
return mapOk$1(await runIfActive(options?.signal, "destinations.add", () => deps.convexCall.mutation(fns.addDestination, {
|
|
10006
|
-
...
|
|
10007
|
-
ref:
|
|
10107
|
+
...backendActor === void 0 ? {} : { actor: backendActor },
|
|
10108
|
+
...isSelfTarget(scopeValue) ? { self: true } : { ref: scopeValue },
|
|
10008
10109
|
kind: destinationKindToBackend(input.kind),
|
|
10009
10110
|
...input.label === void 0 ? {} : { label: input.label },
|
|
10010
10111
|
payload: input.payload
|
|
10011
10112
|
})), destinationFromBackend);
|
|
10012
10113
|
},
|
|
10013
10114
|
list: async (input, options) => {
|
|
10014
|
-
const
|
|
10015
|
-
if (!
|
|
10115
|
+
const scope = normalizeDestinationInputScope(input, "target");
|
|
10116
|
+
if (!scope.ok) return {
|
|
10016
10117
|
ok: false,
|
|
10017
|
-
error:
|
|
10118
|
+
error: scope.error
|
|
10018
10119
|
};
|
|
10120
|
+
const scopeValue = scope.value;
|
|
10019
10121
|
return mapOk$1(await runIfActive(options?.signal, "destinations.list", () => deps.convexCall.query(fns.listDestinations, {
|
|
10020
10122
|
...input.actor === void 0 ? {} : { actor: actorReferenceToBackend(input.actor) },
|
|
10021
|
-
...
|
|
10123
|
+
...scopeValue !== void 0 && isSelfTarget(scopeValue) ? { self: true } : {},
|
|
10124
|
+
...scopeValue !== void 0 && !isSelfTarget(scopeValue) ? { ref: scopeValue } : {}
|
|
10022
10125
|
})), (destinations) => destinations.map(destinationFromBackend).filter((destination) => input.kind === void 0 || destination.kind === input.kind));
|
|
10023
10126
|
},
|
|
10024
10127
|
remove: (input, options) => runIfActive(options?.signal, "destinations.remove", () => deps.convexCall.mutation(fns.removeDestination, {
|
|
@@ -10293,8 +10396,28 @@ function normalizeTargetForBackend(reference, field) {
|
|
|
10293
10396
|
const ref = refFromTargetReference(reference, field);
|
|
10294
10397
|
return ref.ok ? normalizeRefForBackend(ref.value, field) : ref;
|
|
10295
10398
|
}
|
|
10296
|
-
|
|
10297
|
-
|
|
10399
|
+
const DESTINATION_SCOPE_MESSAGE = "provide exactly one of target or ref; use target: { self: true } for your own destination";
|
|
10400
|
+
/** #1063: detect the `{ self: true }` variant of a destination target. */
|
|
10401
|
+
function isSelfTarget(value) {
|
|
10402
|
+
return "self" in value;
|
|
10403
|
+
}
|
|
10404
|
+
/**
|
|
10405
|
+
* #1063: resolve the public `target`/`ref` pair — `SelfTarget` for the actor's
|
|
10406
|
+
* own destination, a `BackendRef` for a counterparty, `undefined` when unscoped.
|
|
10407
|
+
*/
|
|
10408
|
+
function normalizeDestinationInputScope(input, field) {
|
|
10409
|
+
const target = input.target;
|
|
10410
|
+
if (target !== void 0 && isSelfTarget(target)) {
|
|
10411
|
+
if (input.ref !== void 0) return {
|
|
10412
|
+
ok: false,
|
|
10413
|
+
error: Errors.invalidInput(field, DESTINATION_SCOPE_MESSAGE)
|
|
10414
|
+
};
|
|
10415
|
+
return {
|
|
10416
|
+
ok: true,
|
|
10417
|
+
value: target
|
|
10418
|
+
};
|
|
10419
|
+
}
|
|
10420
|
+
if (target !== void 0) return normalizeTargetForBackend(target, field);
|
|
10298
10421
|
if (input.ref !== void 0) return normalizeDestinationRefForBackend(input.ref, "ref");
|
|
10299
10422
|
return {
|
|
10300
10423
|
ok: true,
|
|
@@ -10390,7 +10513,8 @@ function destinationRailFromBackend(destination) {
|
|
|
10390
10513
|
function destinationFromBackend(destination) {
|
|
10391
10514
|
return {
|
|
10392
10515
|
...destination,
|
|
10393
|
-
target: targetReferenceFromBackendRef(destination.ref),
|
|
10516
|
+
target: destination.ref === null ? null : targetReferenceFromBackendRef(destination.ref),
|
|
10517
|
+
ownerScope: destination.ownerScope ?? "counterparty",
|
|
10394
10518
|
kind: destinationKindFromBackend(destination.kind),
|
|
10395
10519
|
rail: destinationRailFromBackend(destination)
|
|
10396
10520
|
};
|
|
@@ -10477,6 +10601,7 @@ function mapOk$1(result, f) {
|
|
|
10477
10601
|
throw cause;
|
|
10478
10602
|
}
|
|
10479
10603
|
}
|
|
10604
|
+
/** Internal signal-aware Effect→CapxulResult bridge, shared with `media.ts`. */
|
|
10480
10605
|
async function runIfActive(signal, operation, effect) {
|
|
10481
10606
|
if (signal?.aborted === true) return {
|
|
10482
10607
|
ok: false,
|
|
@@ -10493,6 +10618,51 @@ async function runIfActive(signal, operation, effect) {
|
|
|
10493
10618
|
};
|
|
10494
10619
|
}
|
|
10495
10620
|
//#endregion
|
|
10621
|
+
//#region ../../packages/sdk/src/client/media.ts
|
|
10622
|
+
const generateUploadUrlFn = makeFunctionReference("media:generateUploadUrl");
|
|
10623
|
+
const setProfileImageFn = makeFunctionReference("media:setProfileImage");
|
|
10624
|
+
const setOrgLogoFn = makeFunctionReference("media:setOrgLogo");
|
|
10625
|
+
function makeMediaMethods(deps) {
|
|
10626
|
+
const fetchImpl = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
10627
|
+
return {
|
|
10628
|
+
async uploadImage(blob, options) {
|
|
10629
|
+
const url = await runIfActive(options?.signal, "media.uploadImage", () => deps.convexCall.mutation(generateUploadUrlFn, {}));
|
|
10630
|
+
if (!url.ok) return url;
|
|
10631
|
+
try {
|
|
10632
|
+
const response = await fetchImpl(url.value.uploadUrl, {
|
|
10633
|
+
method: "POST",
|
|
10634
|
+
headers: { "Content-Type": blob.type },
|
|
10635
|
+
body: blob,
|
|
10636
|
+
...options?.signal === void 0 ? {} : { signal: options.signal }
|
|
10637
|
+
});
|
|
10638
|
+
if (!response.ok) return {
|
|
10639
|
+
ok: false,
|
|
10640
|
+
error: Errors.providerError("convex-storage", "uploadImage", `upload failed with status ${response.status}`)
|
|
10641
|
+
};
|
|
10642
|
+
const parsed = await response.json();
|
|
10643
|
+
if (typeof parsed.storageId !== "string" || parsed.storageId.length === 0) return {
|
|
10644
|
+
ok: false,
|
|
10645
|
+
error: Errors.providerError("convex-storage", "uploadImage", "upload response carried no storageId")
|
|
10646
|
+
};
|
|
10647
|
+
return {
|
|
10648
|
+
ok: true,
|
|
10649
|
+
value: { storageId: parsed.storageId }
|
|
10650
|
+
};
|
|
10651
|
+
} catch (cause) {
|
|
10652
|
+
return {
|
|
10653
|
+
ok: false,
|
|
10654
|
+
error: Errors.providerError("convex-storage", "uploadImage", cause)
|
|
10655
|
+
};
|
|
10656
|
+
}
|
|
10657
|
+
},
|
|
10658
|
+
setProfileImage: (input, options) => runIfActive(options?.signal, "media.setProfileImage", () => deps.convexCall.mutation(setProfileImageFn, { storageId: input.storageId })),
|
|
10659
|
+
setOrgLogo: (input, options) => runIfActive(options?.signal, "media.setOrgLogo", () => deps.convexCall.mutation(setOrgLogoFn, {
|
|
10660
|
+
orgId: input.orgId,
|
|
10661
|
+
storageId: input.storageId
|
|
10662
|
+
}))
|
|
10663
|
+
};
|
|
10664
|
+
}
|
|
10665
|
+
//#endregion
|
|
10496
10666
|
//#region ../../packages/sdk/src/client/sub-accounts-deps.ts
|
|
10497
10667
|
var SubAccountsDepsTag = class extends Context.Tag("@capxul/sdk/SubAccountsDeps")() {};
|
|
10498
10668
|
function subAccountsDepsLayer(deps) {
|
|
@@ -10785,7 +10955,10 @@ function hermeticOrgView(input) {
|
|
|
10785
10955
|
handle: input.handle,
|
|
10786
10956
|
safeAddress: toAddress(placeholder),
|
|
10787
10957
|
role: "Owner",
|
|
10788
|
-
treasury: zeroTreasury(orgId)
|
|
10958
|
+
treasury: zeroTreasury(orgId),
|
|
10959
|
+
bio: null,
|
|
10960
|
+
size: null,
|
|
10961
|
+
logoUrl: null
|
|
10789
10962
|
};
|
|
10790
10963
|
}
|
|
10791
10964
|
function moneyFromConfig(input) {
|
|
@@ -11209,7 +11382,8 @@ function validateOrganizationLifecycleScope(orgId, lifecycle) {
|
|
|
11209
11382
|
};
|
|
11210
11383
|
}
|
|
11211
11384
|
/** Advance only the steps still required by one durable Organization lane. */
|
|
11212
|
-
async function advanceOrganizationSetup(setup, orgId, initial,
|
|
11385
|
+
async function advanceOrganizationSetup(setup, orgId, initial, context) {
|
|
11386
|
+
const { signal, observationSource } = context ?? {};
|
|
11213
11387
|
const scopedInitial = validateOrganizationLifecycleScope(orgId, initial);
|
|
11214
11388
|
if (!scopedInitial.ok) return scopedInitial;
|
|
11215
11389
|
let lifecycle = scopedInitial.value;
|
|
@@ -11219,19 +11393,15 @@ async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
|
11219
11393
|
value: lifecycle
|
|
11220
11394
|
};
|
|
11221
11395
|
const currentStep = lifecycle.step;
|
|
11222
|
-
if (signal?.aborted) return recordSetupFailure(setup, orgId, Errors.cancelled({ operation: "organization.setup" }), true);
|
|
11223
|
-
const stepInput = {
|
|
11396
|
+
if (signal?.aborted) return recordSetupFailure(setup, orgId, Errors.cancelled({ operation: "organization.setup" }), true, observationSource);
|
|
11397
|
+
const stepInput = copyInvocationObservation(observationSource, {
|
|
11224
11398
|
orgId,
|
|
11225
11399
|
...signal === void 0 ? {} : { signal }
|
|
11226
|
-
};
|
|
11400
|
+
});
|
|
11227
11401
|
const next = lifecycle.step === "preparingFounderAccount" ? await setup.prepareFounderAccount(stepInput) : lifecycle.step === "awaitingFounderAuthorization" ? await setup.authorizeAndSubmitBootstrap(stepInput) : lifecycle.step === "submittingBootstrap" ? await setup.resumeSubmittedBootstrap(stepInput) : await setup.confirmSubmittedBootstrap(stepInput);
|
|
11228
|
-
if (!next.ok)
|
|
11229
|
-
if (next.error.code === "CANCELLED") return recordSetupFailure(setup, orgId, next.error, true);
|
|
11230
|
-
if (next.error.code === "PROVIDER_ERROR") return recordSetupFailure(setup, orgId, next.error, isRetryableProviderFailure(next.error));
|
|
11231
|
-
return next;
|
|
11232
|
-
}
|
|
11402
|
+
if (!next.ok) return recordSetupFailure(setup, orgId, next.error, isRetryableOrganizationSetupFailure(next.error), observationSource);
|
|
11233
11403
|
const scopedNext = validateOrganizationLifecycleScope(orgId, next.value);
|
|
11234
|
-
if (!scopedNext.ok) return scopedNext;
|
|
11404
|
+
if (!scopedNext.ok) return recordSetupFailure(setup, orgId, scopedNext.error, false, observationSource);
|
|
11235
11405
|
lifecycle = scopedNext.value;
|
|
11236
11406
|
if (currentStep === "confirmingBootstrap") return {
|
|
11237
11407
|
ok: true,
|
|
@@ -11242,7 +11412,7 @@ async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
|
11242
11412
|
ok: true,
|
|
11243
11413
|
value: lifecycle
|
|
11244
11414
|
};
|
|
11245
|
-
return
|
|
11415
|
+
return recordSetupFailure(setup, orgId, Errors.wrongState({
|
|
11246
11416
|
method: "organization.setup",
|
|
11247
11417
|
currentState: lifecycle.step,
|
|
11248
11418
|
validStates: [
|
|
@@ -11250,23 +11420,28 @@ async function advanceOrganizationSetup(setup, orgId, initial, signal) {
|
|
|
11250
11420
|
"ready",
|
|
11251
11421
|
"failed"
|
|
11252
11422
|
]
|
|
11253
|
-
}));
|
|
11423
|
+
}), false, observationSource);
|
|
11254
11424
|
}
|
|
11255
|
-
async function recordSetupFailure(setup, orgId, error, retryable) {
|
|
11256
|
-
const recorded = await setup.recordFailure({
|
|
11425
|
+
async function recordSetupFailure(setup, orgId, error, retryable, observationSource) {
|
|
11426
|
+
const recorded = await setup.recordFailure(copyInvocationObservation(observationSource, {
|
|
11257
11427
|
orgId,
|
|
11258
11428
|
error,
|
|
11259
11429
|
retryable
|
|
11260
|
-
});
|
|
11430
|
+
}));
|
|
11261
11431
|
if (!recorded.ok) return recorded;
|
|
11262
11432
|
const scopedRecorded = validateOrganizationLifecycleScope(orgId, recorded.value);
|
|
11263
11433
|
if (!scopedRecorded.ok) return scopedRecorded;
|
|
11264
|
-
return
|
|
11434
|
+
return scopedRecorded;
|
|
11265
11435
|
}
|
|
11266
11436
|
function isRetryableProviderFailure(error) {
|
|
11267
11437
|
const mode = error.details?.failure_mode;
|
|
11268
11438
|
return mode !== "auth-origin-mismatch" && mode !== "app-env-allowlist" && mode !== "no-secure-context";
|
|
11269
11439
|
}
|
|
11440
|
+
function isRetryableOrganizationSetupFailure(error) {
|
|
11441
|
+
if (error.code === "CANCELLED" || error.code === "SIGNER_REJECTED") return true;
|
|
11442
|
+
if (error.code === "PROVIDER_ERROR") return isRetryableProviderFailure(error);
|
|
11443
|
+
return error.code === "NETWORK_ERROR" || error.code === "UNKNOWN";
|
|
11444
|
+
}
|
|
11270
11445
|
//#endregion
|
|
11271
11446
|
//#region ../../packages/sdk/src/client/org.ts
|
|
11272
11447
|
/**
|
|
@@ -11339,12 +11514,15 @@ function makeOrgMethods(deps) {
|
|
|
11339
11514
|
ok: false,
|
|
11340
11515
|
error: Errors.notImplemented("organizationSetup", "retrySetup")
|
|
11341
11516
|
};
|
|
11342
|
-
const retried = await setup.retry({
|
|
11517
|
+
const retried = await setup.retry(copyInvocationObservation(options, {
|
|
11343
11518
|
orgId,
|
|
11344
11519
|
...options?.signal === void 0 ? {} : { signal: options.signal }
|
|
11345
|
-
});
|
|
11520
|
+
}));
|
|
11346
11521
|
if (!retried.ok) return retried;
|
|
11347
|
-
return advanceOrganizationSetup(setup, orgId, retried.value,
|
|
11522
|
+
return advanceOrganizationSetup(setup, orgId, retried.value, {
|
|
11523
|
+
signal: options?.signal,
|
|
11524
|
+
observationSource: options
|
|
11525
|
+
});
|
|
11348
11526
|
},
|
|
11349
11527
|
profile: {
|
|
11350
11528
|
get(_options) {
|
|
@@ -11582,7 +11760,8 @@ async function runCompletePersonalOnboarding(ops, input) {
|
|
|
11582
11760
|
email: session.email,
|
|
11583
11761
|
displayName: validated.value.displayName,
|
|
11584
11762
|
country: validated.value.country,
|
|
11585
|
-
...validated.value.withdrawalAddress === void 0 ? {} : { withdrawalAddress: validated.value.withdrawalAddress }
|
|
11763
|
+
...validated.value.withdrawalAddress === void 0 ? {} : { withdrawalAddress: validated.value.withdrawalAddress },
|
|
11764
|
+
...validated.value.username === void 0 ? {} : { username: validated.value.username }
|
|
11586
11765
|
});
|
|
11587
11766
|
if (!written.ok) return fail(written.error);
|
|
11588
11767
|
const provisioned = await ops.triggerProvisioning();
|
|
@@ -11605,17 +11784,27 @@ async function runCompleteOrganizationOnboarding(ops, input, options) {
|
|
|
11605
11784
|
const written = await ops.completeIdentityOnboarding({
|
|
11606
11785
|
authUserId: session.authUserId,
|
|
11607
11786
|
email: session.email,
|
|
11608
|
-
displayName: validated.value.
|
|
11609
|
-
country: validated.value.country
|
|
11787
|
+
displayName: validated.value.profile.displayName,
|
|
11788
|
+
country: validated.value.profile.country,
|
|
11789
|
+
...validated.value.profile.withdrawalAddress === void 0 ? {} : { withdrawalAddress: validated.value.profile.withdrawalAddress },
|
|
11790
|
+
...validated.value.profile.username === void 0 ? {} : { username: validated.value.profile.username }
|
|
11610
11791
|
});
|
|
11611
11792
|
if (!written.ok) return fail(written.error);
|
|
11612
|
-
const
|
|
11613
|
-
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11793
|
+
const founderAccount = await ops.ensureFounderAccountReady(input);
|
|
11794
|
+
if (!founderAccount.ok) return fail(founderAccount.error);
|
|
11795
|
+
if (options?.signal?.aborted === true) return fail(Errors.cancelled({ operation: "onboarding.completeOrganization" }));
|
|
11796
|
+
const started = await setup.startOrResume(copyInvocationObservation(input, {
|
|
11797
|
+
name: validated.value.organization.name,
|
|
11798
|
+
handle: validated.value.organization.handle,
|
|
11799
|
+
country: validated.value.organization.country,
|
|
11800
|
+
...validated.value.organization.bio === void 0 ? {} : { bio: validated.value.organization.bio },
|
|
11801
|
+
...validated.value.organization.size === void 0 ? {} : { size: validated.value.organization.size }
|
|
11802
|
+
}));
|
|
11617
11803
|
if (!started.ok) return fail(started.error);
|
|
11618
|
-
const lifecycle = await advanceOrganizationSetup(setup, started.value.orgId, started.value.lifecycle,
|
|
11804
|
+
const lifecycle = await advanceOrganizationSetup(setup, started.value.orgId, started.value.lifecycle, {
|
|
11805
|
+
signal: options?.signal,
|
|
11806
|
+
observationSource: input
|
|
11807
|
+
});
|
|
11619
11808
|
if (!lifecycle.ok) {
|
|
11620
11809
|
const error = lifecycle.error;
|
|
11621
11810
|
return fail(new CapxulError(error.code, error.message, {
|
|
@@ -11637,44 +11826,61 @@ async function runCompleteOrganizationOnboarding(ops, input, options) {
|
|
|
11637
11826
|
};
|
|
11638
11827
|
}
|
|
11639
11828
|
function validatePersonalInput(input) {
|
|
11640
|
-
|
|
11641
|
-
|
|
11642
|
-
|
|
11829
|
+
if (!isRecord(input) || !isRecord(input.profile)) return fail(Errors.invalidInput("profile", "must be an object"));
|
|
11830
|
+
return validateProfileInput(input.profile);
|
|
11831
|
+
}
|
|
11832
|
+
function validateOrganizationInput(input) {
|
|
11833
|
+
if (!isRecord(input) || !isRecord(input.profile)) return fail(Errors.invalidInput("profile", "must be an object"));
|
|
11834
|
+
if (!isRecord(input.organization)) return fail(Errors.invalidInput("organization", "must be an object"));
|
|
11835
|
+
const profile = validateProfileInput(input.profile);
|
|
11836
|
+
if (!profile.ok) return profile;
|
|
11837
|
+
const name = requireNonEmpty(input.organization.name, "organization.name");
|
|
11838
|
+
if (!name.ok) return name;
|
|
11839
|
+
const handle = requireNonEmpty(input.organization.handle, "organization.handle");
|
|
11840
|
+
if (!handle.ok) return handle;
|
|
11841
|
+
const country = parseCountry(input.organization.country, "organization.country");
|
|
11643
11842
|
if (!country.ok) return country;
|
|
11644
|
-
if (input.withdrawalAddress === void 0) return {
|
|
11645
|
-
ok: true,
|
|
11646
|
-
value: {
|
|
11647
|
-
displayName: displayName.value,
|
|
11648
|
-
country: country.value
|
|
11649
|
-
}
|
|
11650
|
-
};
|
|
11651
|
-
const withdrawalAddress = parseAddress(input.withdrawalAddress, "withdrawalAddress");
|
|
11652
|
-
if (!withdrawalAddress.ok) return withdrawalAddress;
|
|
11653
11843
|
return {
|
|
11654
11844
|
ok: true,
|
|
11655
11845
|
value: {
|
|
11656
|
-
|
|
11657
|
-
|
|
11658
|
-
|
|
11846
|
+
profile: profile.value,
|
|
11847
|
+
organization: {
|
|
11848
|
+
name: name.value,
|
|
11849
|
+
handle: handle.value,
|
|
11850
|
+
country: country.value,
|
|
11851
|
+
...input.organization.bio === void 0 ? {} : { bio: input.organization.bio },
|
|
11852
|
+
...input.organization.size === void 0 ? {} : { size: input.organization.size }
|
|
11853
|
+
}
|
|
11659
11854
|
}
|
|
11660
11855
|
};
|
|
11661
11856
|
}
|
|
11662
|
-
function
|
|
11663
|
-
const
|
|
11664
|
-
if (!
|
|
11665
|
-
const
|
|
11666
|
-
if (!handle.ok) return handle;
|
|
11667
|
-
const ownerDisplayName = requireNonEmpty(input.ownerDisplayName, "ownerDisplayName");
|
|
11668
|
-
if (!ownerDisplayName.ok) return ownerDisplayName;
|
|
11669
|
-
const country = parseCountry(input.country);
|
|
11857
|
+
function validateProfileInput(input) {
|
|
11858
|
+
const displayName = requireNonEmpty(input.displayName, "profile.displayName");
|
|
11859
|
+
if (!displayName.ok) return displayName;
|
|
11860
|
+
const country = parseCountry(input.country, "profile.country");
|
|
11670
11861
|
if (!country.ok) return country;
|
|
11862
|
+
let username;
|
|
11863
|
+
if (input.username !== void 0) {
|
|
11864
|
+
const parsed = requireNonEmpty(input.username, "profile.username");
|
|
11865
|
+
if (!parsed.ok) return parsed;
|
|
11866
|
+
username = parsed.value;
|
|
11867
|
+
}
|
|
11868
|
+
const base = {
|
|
11869
|
+
displayName: displayName.value,
|
|
11870
|
+
country: country.value,
|
|
11871
|
+
...username === void 0 ? {} : { username }
|
|
11872
|
+
};
|
|
11873
|
+
if (input.withdrawalAddress === void 0) return {
|
|
11874
|
+
ok: true,
|
|
11875
|
+
value: base
|
|
11876
|
+
};
|
|
11877
|
+
const withdrawalAddress = parseAddress(input.withdrawalAddress, "profile.withdrawalAddress");
|
|
11878
|
+
if (!withdrawalAddress.ok) return withdrawalAddress;
|
|
11671
11879
|
return {
|
|
11672
11880
|
ok: true,
|
|
11673
11881
|
value: {
|
|
11674
|
-
|
|
11675
|
-
|
|
11676
|
-
country: country.value,
|
|
11677
|
-
ownerDisplayName: ownerDisplayName.value
|
|
11882
|
+
...base,
|
|
11883
|
+
withdrawalAddress: withdrawalAddress.value
|
|
11678
11884
|
}
|
|
11679
11885
|
};
|
|
11680
11886
|
}
|
|
@@ -11686,14 +11892,14 @@ function requireNonEmpty(value, field) {
|
|
|
11686
11892
|
value: trimmed
|
|
11687
11893
|
};
|
|
11688
11894
|
}
|
|
11689
|
-
function parseCountry(value) {
|
|
11895
|
+
function parseCountry(value, field = "country") {
|
|
11690
11896
|
try {
|
|
11691
11897
|
return {
|
|
11692
11898
|
ok: true,
|
|
11693
11899
|
value: toCountryCode(value)
|
|
11694
11900
|
};
|
|
11695
11901
|
} catch (cause) {
|
|
11696
|
-
return fail(invalidFrom(
|
|
11902
|
+
return fail(invalidFrom(field, cause, "must be an ISO-3166 alpha-2 code"));
|
|
11697
11903
|
}
|
|
11698
11904
|
}
|
|
11699
11905
|
function parseAddress(value, field) {
|
|
@@ -11710,6 +11916,9 @@ function invalidFrom(field, cause, fallback) {
|
|
|
11710
11916
|
const message = cause instanceof Error && cause.message.length > 0 ? cause.message : fallback;
|
|
11711
11917
|
return Errors.invalidInput(field, message);
|
|
11712
11918
|
}
|
|
11919
|
+
function isRecord(value) {
|
|
11920
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11921
|
+
}
|
|
11713
11922
|
function fail(error) {
|
|
11714
11923
|
return {
|
|
11715
11924
|
ok: false,
|
|
@@ -11909,8 +12118,10 @@ function assembleCapxulClient(input) {
|
|
|
11909
12118
|
});
|
|
11910
12119
|
const identity = makeIdentityMethods({
|
|
11911
12120
|
identityPort: input.ports.identity,
|
|
11912
|
-
actor
|
|
12121
|
+
actor,
|
|
12122
|
+
convexCall: input.ports.convexCall
|
|
11913
12123
|
});
|
|
12124
|
+
const media = makeMediaMethods({ convexCall: input.ports.convexCall });
|
|
11914
12125
|
const accounts = makeAccountsMethods({
|
|
11915
12126
|
accountReadPort: input.ports.accountRead,
|
|
11916
12127
|
chainId: input.bootstrap.chainId,
|
|
@@ -11947,6 +12158,22 @@ function assembleCapxulClient(input) {
|
|
|
11947
12158
|
};
|
|
11948
12159
|
},
|
|
11949
12160
|
completeIdentityOnboarding: (write) => runPortEffect(input.ports.identity.completeOnboarding(write)),
|
|
12161
|
+
ensureFounderAccountReady: async (observationSource) => {
|
|
12162
|
+
const deployed = await account._internal.deploySafe(observationSource);
|
|
12163
|
+
if (!deployed.ok) return deployed;
|
|
12164
|
+
if (deployed.value.deployedAt === null || deployed.value.claimedAt === null) return {
|
|
12165
|
+
ok: false,
|
|
12166
|
+
error: Errors.wrongState({
|
|
12167
|
+
method: "onboarding.completeOrganization",
|
|
12168
|
+
currentState: "founderAccountClaimPending",
|
|
12169
|
+
validStates: ["founderAccountDeployedAndClaimed"]
|
|
12170
|
+
})
|
|
12171
|
+
};
|
|
12172
|
+
return {
|
|
12173
|
+
ok: true,
|
|
12174
|
+
value: void 0
|
|
12175
|
+
};
|
|
12176
|
+
},
|
|
11950
12177
|
triggerProvisioning: () => account._internal.provision(),
|
|
11951
12178
|
kickProvisioning: () => kickProvisioning?.(),
|
|
11952
12179
|
readLifecycle: () => account.getLifecycle(),
|
|
@@ -11970,6 +12197,7 @@ function assembleCapxulClient(input) {
|
|
|
11970
12197
|
paymentDocuments: financialOps.paymentDocuments,
|
|
11971
12198
|
paymentRequests: financialOps.paymentRequests,
|
|
11972
12199
|
workbench: financialOps.workbench,
|
|
12200
|
+
media,
|
|
11973
12201
|
subAccounts,
|
|
11974
12202
|
createOrg: orgMethods.createOrg,
|
|
11975
12203
|
orgs: orgMethods.orgs,
|
|
@@ -12057,7 +12285,7 @@ function observeSdkClient(client, adapter) {
|
|
|
12057
12285
|
if (cached !== void 0) return cached;
|
|
12058
12286
|
const wrapped = new Proxy(callable, {
|
|
12059
12287
|
apply(currentTarget, _thisArg, args) {
|
|
12060
|
-
const invocationContext = resolveAdapterContext(adapter);
|
|
12288
|
+
const invocationContext = invocationObservationContext(resolveAdapterContext(adapter));
|
|
12061
12289
|
const invocationArgs = carryInvocationContext(operation, args, invocationContext);
|
|
12062
12290
|
let output;
|
|
12063
12291
|
try {
|
|
@@ -12094,9 +12322,23 @@ function observeSdkClient(client, adapter) {
|
|
|
12094
12322
|
return wrapObject(client, []);
|
|
12095
12323
|
}
|
|
12096
12324
|
function carryInvocationContext(operation, args, context) {
|
|
12097
|
-
if (
|
|
12325
|
+
if (!isPlainObject(args[0])) return args.length === 0 && operation === "org.retrySetup" ? [attachInvocationObservation({}, context)] : args;
|
|
12098
12326
|
return [attachInvocationObservation({ ...args[0] }, context), ...args.slice(1)];
|
|
12099
12327
|
}
|
|
12328
|
+
/** One stable correlation id per public call; the next call is an explicit retry. */
|
|
12329
|
+
function invocationObservationContext(context) {
|
|
12330
|
+
return {
|
|
12331
|
+
...context,
|
|
12332
|
+
correlationId: createInvocationCorrelationId()
|
|
12333
|
+
};
|
|
12334
|
+
}
|
|
12335
|
+
function createInvocationCorrelationId() {
|
|
12336
|
+
if (typeof globalThis.crypto?.randomUUID === "function") return `sdk_${globalThis.crypto.randomUUID()}`;
|
|
12337
|
+
const bytes = new Uint8Array(16);
|
|
12338
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") globalThis.crypto.getRandomValues(bytes);
|
|
12339
|
+
else for (let index = 0; index < bytes.length; index += 1) bytes[index] = Math.floor(Math.random() * 256);
|
|
12340
|
+
return `sdk_${Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("")}`;
|
|
12341
|
+
}
|
|
12100
12342
|
/** @internal Reports a factory-level typed failure without changing its identity. */
|
|
12101
12343
|
function observeFailedResult(result, adapter, operation) {
|
|
12102
12344
|
if (adapter !== void 0 && isFailedResult(result)) report(adapter, "operation", operation, result.error, resolveAdapterContext(adapter));
|
|
@@ -12508,7 +12750,8 @@ async function createCapxulClient(input) {
|
|
|
12508
12750
|
orgPort: new ConvexOrganizationAdapter({ convex: adapters.value.ports.convexCall }),
|
|
12509
12751
|
...signer === void 0 ? {} : { organizationSetup: new ConvexOrganizationSetupAdapter({
|
|
12510
12752
|
convex: adapters.value.ports.convexCall,
|
|
12511
|
-
signer
|
|
12753
|
+
signer,
|
|
12754
|
+
chainId: adapters.value.bootstrap.chainId
|
|
12512
12755
|
}) },
|
|
12513
12756
|
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
12514
12757
|
...input.otpTtlMs === void 0 ? {} : { otpTtlMs: input.otpTtlMs },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capxul/mcp",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Capxul MCP server — agent-facing financial-ops tools (auth, account readiness, balances, testnet faucet, payments) exposed over Streamable HTTP with OAuth bearer auth and a dev-mode custody gate.",
|
|
6
6
|
"keywords": [
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"typescript": "5.9.2",
|
|
53
53
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.23",
|
|
54
54
|
"vite-plus": "0.1.23",
|
|
55
|
-
"@capxul/backend": "0.1.0-alpha.
|
|
55
|
+
"@capxul/backend": "0.1.0-alpha.6",
|
|
56
56
|
"@capxul/config": "0.1.0-alpha.3",
|
|
57
57
|
"@capxul/errors": "0.0.1-alpha.0",
|
|
58
|
-
"@capxul/observability": "0.1.0-alpha.
|
|
59
|
-
"@capxul/sdk": "1.0.0-alpha.
|
|
60
|
-
"@capxul/types": "0.1.0-alpha.
|
|
61
|
-
"@capxul/wire": "0.1.0-alpha.
|
|
58
|
+
"@capxul/observability": "0.1.0-alpha.2",
|
|
59
|
+
"@capxul/sdk": "1.0.0-alpha.22",
|
|
60
|
+
"@capxul/types": "0.1.0-alpha.2",
|
|
61
|
+
"@capxul/wire": "0.1.0-alpha.4"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"dev": "vp exec tsx src/main.ts serve",
|